filename
stringlengths
5
42
content
stringlengths
15
319k
Limits.lean
/- Copyright (c) 2023 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.Topology.Category.CompHausLike.Limits import Mathlib.Topology.Category.Stonean.Basic /-! # Explicit limits and colimits This file applies the general API for explicit limits and colimits in `CompHausLike P` (see the file `Mathlib/Topology/Category/CompHausLike/Limits.lean`) to the special case of `Stonean`. -/ universe w u open CategoryTheory Limits CompHausLike Topology namespace Stonean instance : HasExplicitFiniteCoproducts.{w, u} (fun Y ↦ ExtremallyDisconnected Y) where hasProp _ := { hasProp := show ExtremallyDisconnected (Σ (_a : _), _) from inferInstance} variable {X Y Z : Stonean} {f : X ⟶ Z} (i : Y ⟶ Z) (hi : IsOpenEmbedding f) include hi lemma extremallyDisconnected_preimage : ExtremallyDisconnected (i ⁻¹' (Set.range f)) where open_closure U hU := by have h : IsClopen (i ⁻¹' (Set.range f)) := ⟨IsClosed.preimage i.hom.continuous (isCompact_range f.hom.continuous).isClosed, IsOpen.preimage i.hom.continuous hi.isOpen_range⟩ rw [← (closure U).preimage_image_eq Subtype.coe_injective, ← h.1.isClosedEmbedding_subtypeVal.closure_image_eq U] exact isOpen_induced (ExtremallyDisconnected.open_closure _ (h.2.isOpenEmbedding_subtypeVal.isOpenMap U hU)) lemma extremallyDisconnected_pullback : ExtremallyDisconnected {xy : X × Y | f xy.1 = i xy.2} := have := extremallyDisconnected_preimage i hi let e := (TopCat.pullbackHomeoPreimage i i.hom.2 f hi.isEmbedding).symm let e' : {xy : X × Y | f xy.1 = i xy.2} ≃ₜ {xy : Y × X | i xy.1 = f xy.2} := by exact TopCat.homeoOfIso ((TopCat.pullbackIsoProdSubtype f i).symm ≪≫ pullbackSymmetry _ _ ≪≫ (TopCat.pullbackIsoProdSubtype i f)) extremallyDisconnected_of_homeo (e.trans e'.symm) instance : HasExplicitPullbacksOfInclusions (fun (Y : TopCat.{u}) ↦ ExtremallyDisconnected Y) := by apply CompHausLike.hasPullbacksOfInclusions intro _ _ _ _ _ hi exact ⟨extremallyDisconnected_pullback _ hi⟩ example : FinitaryExtensive Stonean.{u} := inferInstance noncomputable example : PreservesFiniteCoproducts Stonean.toCompHaus := inferInstance noncomputable example : PreservesFiniteCoproducts Stonean.toProfinite := inferInstance end Stonean
Basic.lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Jujian Zhang -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Module.TransferInstance import Mathlib.RingTheory.Localization.Defs /-! # Localized Module Given a commutative semiring `R`, a multiplicative subset `S ⊆ R` and an `R`-module `M`, we can localize `M` by `S`. This gives us a `Localization S`-module. ## Main definitions * `LocalizedModule.r`: the equivalence relation defining this localization, namely `(m, s) ≈ (m', s')` if and only if there is some `u : S` such that `u • s' • m = u • s • m'`. * `LocalizedModule M S`: the localized module by `S`. * `LocalizedModule.mk`: the canonical map sending `(m, s) : M × S ↦ m/s : LocalizedModule M S` * `LocalizedModule.liftOn`: any well defined function `f : M × S → α` respecting `r` descents to a function `LocalizedModule M S → α` * `LocalizedModule.liftOn₂`: any well defined function `f : M × S → M × S → α` respecting `r` descents to a function `LocalizedModule M S → LocalizedModule M S` * `LocalizedModule.mk_add_mk`: in the localized module `mk m s + mk m' s' = mk (s' • m + s • m') (s * s')` * `LocalizedModule.mk_smul_mk` : in the localized module, for any `r : R`, `s t : S`, `m : M`, we have `mk r s • mk m t = mk (r • m) (s * t)` where `mk r s : Localization S` is localized ring by `S`. * `LocalizedModule.isModule` : `LocalizedModule M S` is a `Localization S`-module. ## Future work * Redefine `Localization` for monoids and rings to coincide with `LocalizedModule`. -/ namespace LocalizedModule universe u v variable {R : Type u} [CommSemiring R] (S : Submonoid R) variable (M : Type v) [AddCommMonoid M] [Module R M] variable (T : Type*) [CommSemiring T] [Algebra R T] [IsLocalization S T] /-- The equivalence relation on `M × S` where `(m1, s1) ≈ (m2, s2)` if and only if for some (u : S), u * (s2 • m1 - s1 • m2) = 0 -/ def r (a b : M × S) : Prop := ∃ u : S, u • b.2 • a.1 = u • a.2 • b.1 theorem r.isEquiv : IsEquiv _ (r S M) := { refl := fun ⟨m, s⟩ => ⟨1, by rw [one_smul]⟩ trans := fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m3, s3⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => by use u1 * u2 * s2 -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s3) • ·) hu1.symm have hu2' := congr_arg ((u1 * s1) • ·) hu2.symm simp only [← mul_smul, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu2', hu1'] symm := fun ⟨_, _⟩ ⟨_, _⟩ ⟨u, hu⟩ => ⟨u, hu.symm⟩ } instance r.setoid : Setoid (M × S) where r := r S M iseqv := ⟨(r.isEquiv S M).refl, (r.isEquiv S M).symm _ _, (r.isEquiv S M).trans _ _ _⟩ -- TODO: change `Localization` to use `r'` instead of `r` so that the two types are also defeq, -- `Localization S = LocalizedModule S R`. example {R} [CommSemiring R] (S : Submonoid R) : ⇑(Localization.r' S) = LocalizedModule.r S R := rfl /-- If `S` is a multiplicative subset of a ring `R` and `M` an `R`-module, then we can localize `M` by `S`. -/ def _root_.LocalizedModule : Type max u v := Quotient (r.setoid S M) section variable {M S} /-- The canonical map sending `(m, s) ↦ m/s` -/ def mk (m : M) (s : S) : LocalizedModule S M := Quotient.mk' ⟨m, s⟩ theorem mk_eq {m m' : M} {s s' : S} : mk m s = mk m' s' ↔ ∃ u : S, u • s' • m = u • s • m' := Quotient.eq' @[elab_as_elim, induction_eliminator, cases_eliminator] theorem induction_on {β : LocalizedModule S M → Prop} (h : ∀ (m : M) (s : S), β (mk m s)) : ∀ x : LocalizedModule S M, β x := by rintro ⟨⟨m, s⟩⟩ exact h m s @[elab_as_elim] theorem induction_on₂ {β : LocalizedModule S M → LocalizedModule S M → Prop} (h : ∀ (m m' : M) (s s' : S), β (mk m s) (mk m' s')) : ∀ x y, β x y := by rintro ⟨⟨m, s⟩⟩ ⟨⟨m', s'⟩⟩ exact h m m' s s' /-- If `f : M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → α`. -/ def liftOn {α : Type*} (x : LocalizedModule S M) (f : M × S → α) (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') : α := Quotient.liftOn x f wd theorem liftOn_mk {α : Type*} {f : M × S → α} (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') (m : M) (s : S) : liftOn (mk m s) f wd = f ⟨m, s⟩ := by convert Quotient.liftOn_mk f wd ⟨m, s⟩ /-- If `f : M × S → M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → LocalizedModule M S → α`. -/ def liftOn₂ {α : Type*} (x y : LocalizedModule S M) (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') : α := Quotient.liftOn₂ x y f wd theorem liftOn₂_mk {α : Type*} (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') (m m' : M) (s s' : S) : liftOn₂ (mk m s) (mk m' s') f wd = f ⟨m, s⟩ ⟨m', s'⟩ := by convert Quotient.liftOn₂_mk f wd _ _ instance : Zero (LocalizedModule S M) := ⟨mk 0 1⟩ /-- If `S` contains `0` then the localization at `S` is trivial. -/ theorem subsingleton (h : 0 ∈ S) : Subsingleton (LocalizedModule S M) := by refine ⟨fun a b ↦ ?_⟩ induction a,b using LocalizedModule.induction_on₂ exact mk_eq.mpr ⟨⟨0, h⟩, by simp only [Submonoid.mk_smul, zero_smul]⟩ @[simp] theorem zero_mk (s : S) : mk (0 : M) s = 0 := mk_eq.mpr ⟨1, by rw [one_smul, smul_zero, smul_zero, one_smul]⟩ instance : Add (LocalizedModule S M) where add p1 p2 := liftOn₂ p1 p2 (fun x y => mk (y.2 • x.1 + x.2 • y.1) (x.2 * y.2)) <| fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m1', s1'⟩ ⟨m2', s2'⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => mk_eq.mpr ⟨u1 * u2, by -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s2 * s2') • ·) hu1 have hu2' := congr_arg ((u1 * s1 * s1') • ·) hu2 simp only [smul_add, ← mul_smul, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu1', hu2']⟩ theorem mk_add_mk {m1 m2 : M} {s1 s2 : S} : mk m1 s1 + mk m2 s2 = mk (s2 • m1 + s1 • m2) (s1 * s2) := mk_eq.mpr <| ⟨1, rfl⟩ private theorem add_assoc' (x y z : LocalizedModule S M) : x + y + z = x + (y + z) := by induction' x with mx sx induction' y with my sy induction' z with mz sz simp only [mk_add_mk, smul_add] refine mk_eq.mpr ⟨1, ?_⟩ rw [one_smul, one_smul] congr 1 · rw [mul_assoc] · rw [eq_comm, mul_comm, add_assoc, mul_smul, mul_smul, ← mul_smul sx sz, mul_comm, mul_smul] private theorem add_comm' (x y : LocalizedModule S M) : x + y = y + x := LocalizedModule.induction_on₂ (fun m m' s s' => by rw [mk_add_mk, mk_add_mk, add_comm, mul_comm]) x y private theorem zero_add' (x : LocalizedModule S M) : 0 + x = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, zero_add, mk_eq] exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x private theorem add_zero' (x : LocalizedModule S M) : x + 0 = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, add_zero, mk_eq] exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x instance hasNatSMul : SMul ℕ (LocalizedModule S M) where smul n := nsmulRec n private theorem nsmul_zero' (x : LocalizedModule S M) : (0 : ℕ) • x = 0 := LocalizedModule.induction_on (fun _ _ => rfl) x private theorem nsmul_succ' (n : ℕ) (x : LocalizedModule S M) : n.succ • x = n • x + x := LocalizedModule.induction_on (fun _ _ => rfl) x instance : AddCommMonoid (LocalizedModule S M) where add := (· + ·) add_assoc := add_assoc' zero := 0 zero_add := zero_add' add_zero := add_zero' nsmul := (· • ·) nsmul_zero := nsmul_zero' nsmul_succ := nsmul_succ' add_comm := add_comm' instance {M : Type*} [AddCommGroup M] [Module R M] : Neg (LocalizedModule S M) where neg p := liftOn p (fun x => LocalizedModule.mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩ instance {M : Type*} [AddCommGroup M] [Module R M] : AddCommGroup (LocalizedModule S M) := { show AddCommMonoid (LocalizedModule S M) by infer_instance with neg_add_cancel := by rintro ⟨m, s⟩ change (liftOn (mk m s) (fun x => mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩) + mk m s = 0 rw [liftOn_mk, mk_add_mk] simp -- TODO: fix the diamond zsmul := zsmulRec } theorem mk_neg {M : Type*} [AddCommGroup M] [Module R M] {m : M} {s : S} : mk (-m) s = -mk m s := rfl instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Monoid (LocalizedModule S A) := { mul := fun m₁ m₂ => liftOn₂ m₁ m₂ (fun x₁ x₂ => LocalizedModule.mk (x₁.1 * x₂.1) (x₁.2 * x₂.2)) (by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨b₁, t₁⟩ ⟨b₂, t₂⟩ ⟨u₁, e₁⟩ ⟨u₂, e₂⟩ rw [mk_eq] use u₁ * u₂ dsimp only at e₁ e₂ ⊢ rw [eq_comm] trans (u₁ • t₁ • a₁) • u₂ • t₂ • a₂ on_goal 1 => rw [e₁, e₂] on_goal 2 => rw [eq_comm] all_goals rw [smul_smul, mul_mul_mul_comm, ← smul_eq_mul, ← smul_eq_mul (α := A), smul_smul_smul_comm, mul_smul, mul_smul]) one := mk 1 (1 : S) one_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [one_mul, one_smul]⟩ mul_one := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_one, one_smul]⟩ mul_assoc := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_smul, ← mul_assoc] } instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Semiring (LocalizedModule S A) := { show (AddCommMonoid (LocalizedModule S A)) by infer_instance, show (Monoid (LocalizedModule S A)) by infer_instance with left_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, mul_add, mul_smul_comm, smul_smul, ← mul_assoc, mul_right_comm] right_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, add_mul, smul_smul, ← mul_assoc, smul_mul_assoc, mul_right_comm] zero_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [zero_mul, smul_zero]⟩ mul_zero := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_zero, smul_zero]⟩ } instance {A : Type*} [CommSemiring A] [Algebra R A] {S : Submonoid R} : CommSemiring (LocalizedModule S A) := { show Semiring (LocalizedModule S A) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } instance {A : Type*} [Ring A] [Algebra R A] {S : Submonoid R} : Ring (LocalizedModule S A) := { inferInstanceAs (AddCommGroup (LocalizedModule S A)), inferInstanceAs (Semiring (LocalizedModule S A)) with } instance {A : Type*} [CommRing A] [Algebra R A] {S : Submonoid R} : CommRing (LocalizedModule S A) := { show (Ring (LocalizedModule S A)) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } theorem mk_mul_mk {A : Type*} [Semiring A] [Algebra R A] {a₁ a₂ : A} {s₁ s₂ : S} : mk a₁ s₁ * mk a₂ s₂ = mk (a₁ * a₂) (s₁ * s₂) := rfl noncomputable instance : SMul T (LocalizedModule S M) where smul x p := let a := IsLocalization.sec S x liftOn p (fun p ↦ mk (a.1 • p.1) (a.2 * p.2)) (by rintro p p' ⟨s, h⟩ refine mk_eq.mpr ⟨s, ?_⟩ calc _ = a.2 • a.1 • s • p'.2 • p.1 := by simp_rw [Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul]; ring_nf _ = a.2 • a.1 • s • p.2 • p'.1 := by rw [h] _ = s • (a.2 * p.2) • a.1 • p'.1 := by simp_rw [Submonoid.smul_def, ← mul_smul, Submonoid.coe_mul]; ring_nf ) theorem smul_def (x : T) (m : M) (s : S) : x • mk m s = mk ((IsLocalization.sec S x).1 • m) ((IsLocalization.sec S x).2 * s) := rfl theorem mk'_smul_mk (r : R) (m : M) (s s' : S) : IsLocalization.mk' T r s • mk m s' = mk (r • m) (s * s') := by rw [smul_def, mk_eq] obtain ⟨c, hc⟩ := IsLocalization.eq.mp <| IsLocalization.mk'_sec T (IsLocalization.mk' T r s) use c simp_rw [← mul_smul, Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul, ← mul_assoc, mul_comm _ (s' : R), mul_assoc, hc] theorem mk_smul_mk (r : R) (m : M) (s t : S) : Localization.mk r s • mk m t = mk (r • m) (s * t) := by rw [Localization.mk_eq_mk'] exact mk'_smul_mk .. variable {T} private theorem one_smul_aux (p : LocalizedModule S M) : (1 : T) • p = p := by induction' p with m s rw [show (1 : T) = IsLocalization.mk' T (1 : R) (1 : S) by rw [IsLocalization.mk'_one, map_one]] rw [mk'_smul_mk, one_smul, one_mul] private theorem mul_smul_aux (x y : T) (p : LocalizedModule S M) : (x * y) • p = x • y • p := by induction' p with m s rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y] simp_rw [← IsLocalization.mk'_mul, mk'_smul_mk, ← mul_smul, mul_assoc] private theorem smul_add_aux (x : T) (p q : LocalizedModule S M) : x • (p + q) = x • p + x • q := by induction' p with m s induction' q with n t rw [smul_def, smul_def, mk_add_mk, mk_add_mk] rw [show x • _ = IsLocalization.mk' T _ _ • _ by rw [IsLocalization.mk'_sec (M := S) T]] rw [← IsLocalization.mk'_cancel _ _ (IsLocalization.sec S x).2, mk'_smul_mk] congr 1 · simp only [Submonoid.smul_def, smul_add, ← mul_smul, Submonoid.coe_mul]; ring_nf · rw [mul_mul_mul_comm] -- ring does not work here private theorem smul_zero_aux (x : T) : x • (0 : LocalizedModule S M) = 0 := by conv => lhs; rw [← zero_mk 1, smul_def, smul_zero, zero_mk] private theorem add_smul_aux (x y : T) (p : LocalizedModule S M) : (x + y) • p = x • p + y • p := by induction' p with m s rw [smul_def T x, smul_def T y, mk_add_mk, show (x + y) • _ = IsLocalization.mk' T _ _ • _ by rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y, ← IsLocalization.mk'_add, IsLocalization.mk'_cancel _ _ s], mk'_smul_mk, ← smul_assoc, ← smul_assoc, ← add_smul] congr 1 · simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_eq_mul]; ring_nf · rw [mul_mul_mul_comm, mul_assoc] -- ring does not work here private theorem zero_smul_aux (p : LocalizedModule S M) : (0 : T) • p = 0 := by induction' p with m s rw [show (0 : T) = IsLocalization.mk' T (0 : R) (1 : S) by rw [IsLocalization.mk'_zero], mk'_smul_mk, zero_smul, zero_mk] noncomputable instance isModule : Module T (LocalizedModule S M) where smul := (· • ·) one_smul := one_smul_aux mul_smul := mul_smul_aux smul_add := smul_add_aux smul_zero := smul_zero_aux add_smul := add_smul_aux zero_smul := zero_smul_aux @[simp] theorem mk_cancel_common_left (s' s : S) (m : M) : mk (s' • m) (s' * s) = mk m s := mk_eq.mpr ⟨1, by simp only [mul_smul, one_smul] rw [smul_comm]⟩ @[simp] theorem mk_cancel (s : S) (m : M) : mk (s • m) s = mk m 1 := mk_eq.mpr ⟨1, by simp⟩ @[simp] theorem mk_cancel_common_right (s s' : S) (m : M) : mk (s' • m) (s * s') = mk m s := mk_eq.mpr ⟨1, by simp [mul_smul]⟩ noncomputable instance isModule' : Module R (LocalizedModule S M) := { Module.compHom (LocalizedModule S M) <| algebraMap R (Localization S) with } theorem smul'_mk (r : R) (s : S) (m : M) : r • mk m s = mk (r • m) s := by simpa only [one_mul] using mk_smul_mk r m 1 s lemma smul_eq_iff_of_mem (r : R) (hr : r ∈ S) (x y : LocalizedModule S M) : r • x = y ↔ x = Localization.mk 1 ⟨r, hr⟩ • y := by induction x using induction_on with | h m s => induction y using induction_on with | h n t => rw [smul'_mk, mk_smul_mk, one_smul, mk_eq, mk_eq] simp only [Subtype.exists, Submonoid.mk_smul, exists_prop] fconstructor · rintro ⟨a, ha, eq1⟩ refine ⟨a, ha, ?_⟩ rw [mul_smul, ← eq1, Submonoid.mk_smul, smul_comm r t] · rintro ⟨a, ha, eq1⟩ refine ⟨a, ha, ?_⟩ rw [← eq1, mul_comm, mul_smul, Submonoid.mk_smul, Submonoid.smul_def, Submonoid.mk_smul] lemma eq_zero_of_smul_eq_zero (r : R) (hr : r ∈ S) (x : LocalizedModule S M) (hx : r • x = 0) : x = 0 := by rw [smul_eq_iff_of_mem (hr := hr)] at hx rw [hx, smul_zero] theorem smul'_mul {A : Type*} [Semiring A] [Algebra R A] (x : T) (p₁ p₂ : LocalizedModule S A) : x • p₁ * p₂ = x • (p₁ * p₂) := by induction p₁, p₂ using induction_on₂ with | _ a₁ s₁ a₂ s₂ => _ rw [mk_mul_mk, smul_def, smul_def, mk_mul_mk, mul_assoc, smul_mul_assoc] theorem mul_smul' {A : Type*} [Semiring A] [Algebra R A] (x : T) (p₁ p₂ : LocalizedModule S A) : p₁ * x • p₂ = x • (p₁ * p₂) := by induction p₁, p₂ using induction_on₂ with | _ a₁ s₁ a₂ s₂ => _ rw [smul_def, mk_mul_mk, mk_mul_mk, smul_def, mul_left_comm, mul_smul_comm] variable (T) noncomputable instance {A : Type*} [Semiring A] [Algebra R A] : Algebra T (LocalizedModule S A) := Algebra.ofModule smul'_mul mul_smul' theorem algebraMap_mk' {A : Type*} [Semiring A] [Algebra R A] (a : R) (s : S) : algebraMap _ _ (IsLocalization.mk' T a s) = mk (algebraMap R A a) s := by rw [Algebra.algebraMap_eq_smul_one] change _ • mk _ _ = _ rw [mk'_smul_mk, Algebra.algebraMap_eq_smul_one, mul_one] theorem algebraMap_mk {A : Type*} [Semiring A] [Algebra R A] (a : R) (s : S) : algebraMap _ _ (Localization.mk a s) = mk (algebraMap R A a) s := by rw [Localization.mk_eq_mk'] exact algebraMap_mk' .. instance : IsScalarTower R T (LocalizedModule S M) where smul_assoc r x p := by induction' p with m s rw [← IsLocalization.mk'_sec (M := S) T x, IsLocalization.smul_mk', mk'_smul_mk, mk'_smul_mk, smul'_mk, mul_smul] noncomputable instance algebra' {A : Type*} [Semiring A] [Algebra R A] : Algebra R (LocalizedModule S A) where algebraMap := (algebraMap (Localization S) (LocalizedModule S A)).comp (algebraMap R <| Localization S) commutes' := by intro r x induction x using induction_on with | _ a s => _ dsimp rw [← Localization.mk_one_eq_algebraMap, algebraMap_mk, mk_mul_mk, mk_mul_mk, mul_comm, Algebra.commutes] smul_def' := by intro r x induction x using induction_on with | _ a s => _ dsimp rw [← Localization.mk_one_eq_algebraMap, algebraMap_mk, mk_mul_mk, smul'_mk, Algebra.smul_def, one_mul] section variable (S M) /-- The function `m ↦ m / 1` as an `R`-linear map. -/ @[simps] noncomputable def mkLinearMap : M →ₗ[R] LocalizedModule S M where toFun m := mk m 1 map_add' x y := by simp [mk_add_mk] map_smul' _ _ := (smul'_mk _ _ _).symm end /-- For any `s : S`, there is an `R`-linear map given by `a/b ↦ a/(b*s)`. -/ @[simps] noncomputable def divBy (s : S) : LocalizedModule S M →ₗ[R] LocalizedModule S M where toFun p := p.liftOn (fun p => mk p.1 (p.2 * s)) fun ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩ => mk_eq.mpr ⟨c, by rw [mul_smul, mul_smul, smul_comm _ s, smul_comm _ s, eq1, smul_comm _ s, smul_comm _ s]⟩ map_add' x y := by refine x.induction_on₂ ?_ y intro m₁ m₂ t₁ t₂ simp_rw [mk_add_mk, LocalizedModule.liftOn_mk, mk_add_mk, mul_smul, mul_comm _ s, mul_assoc, smul_comm _ s, ← smul_add, mul_left_comm s t₁ t₂, mk_cancel_common_left s] map_smul' r x := by refine x.induction_on (fun _ _ ↦ ?_) change liftOn (mk _ _) _ _ = r • (liftOn (mk _ _) _ _) simp_rw [liftOn_mk, mul_assoc, ← smul_def] congr! theorem divBy_mul_by (s : S) (p : LocalizedModule S M) : divBy s (algebraMap R (Module.End R (LocalizedModule S M)) s p) = p := p.induction_on fun m t => by rw [Module.algebraMap_end_apply, divBy_apply, ← algebraMap_smul (Localization S) (s : R), smul_def, LocalizedModule.liftOn_mk, mul_assoc, ← smul_def, algebraMap_smul, smul'_mk, ← Submonoid.smul_def, mk_cancel_common_right _ s] theorem mul_by_divBy (s : S) (p : LocalizedModule S M) : algebraMap R (Module.End R (LocalizedModule S M)) s (divBy s p) = p := p.induction_on fun m t => by rw [divBy_apply, Module.algebraMap_end_apply, LocalizedModule.liftOn_mk, smul'_mk, ← Submonoid.smul_def, mk_cancel_common_right _ s] end end LocalizedModule section IsLocalizedModule universe u v variable {R : Type*} [CommSemiring R] (S : Submonoid R) variable {M M' M'' : Type*} [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable {A : Type*} [CommSemiring A] [Algebra R A] [Module A M'] [IsLocalization S A] variable [Module R M] [Module R M'] [Module R M''] [IsScalarTower R A M'] variable (f : M →ₗ[R] M') (g : M →ₗ[R] M'') /-- The characteristic predicate for localized module. `IsLocalizedModule S f` describes that `f : M ⟶ M'` is the localization map identifying `M'` as `LocalizedModule S M`. -/ @[mk_iff] class IsLocalizedModule : Prop where map_units : ∀ x : S, IsUnit (algebraMap R (Module.End R M') x) surj' : ∀ y : M', ∃ x : M × S, x.2 • y = f x.1 exists_of_eq : ∀ {x₁ x₂}, f x₁ = f x₂ → ∃ c : S, c • x₁ = c • x₂ attribute [nolint docBlame] IsLocalizedModule.map_units IsLocalizedModule.surj' IsLocalizedModule.exists_of_eq lemma IsLocalizedModule.surj [IsLocalizedModule S f] (y : M') : ∃ x : M × S, x.2 • y = f x.1 := surj' y lemma IsLocalizedModule.eq_iff_exists [IsLocalizedModule S f] {x₁ x₂} : f x₁ = f x₂ ↔ ∃ c : S, c • x₁ = c • x₂ := Iff.intro exists_of_eq fun ⟨c, h⟩ ↦ by apply_fun f at h simp_rw [f.map_smul_of_tower, Submonoid.smul_def, ← Module.algebraMap_end_apply R R] at h exact ((Module.End.isUnit_iff _).mp <| map_units f c).1 h lemma IsLocalizedModule.injective_iff_isRegular [IsLocalizedModule S f] : Function.Injective f ↔ ∀ c : S, IsSMulRegular M c := by simp_rw [IsSMulRegular, Function.Injective, eq_iff_exists S, exists_imp, forall_comm (α := S)] instance IsLocalizedModule.of_linearEquiv (e : M' ≃ₗ[R] M'') [hf : IsLocalizedModule S f] : IsLocalizedModule S (e ∘ₗ f : M →ₗ[R] M'') where map_units s := by rw [show algebraMap R (Module.End R M'') s = e ∘ₗ (algebraMap R (Module.End R M') s) ∘ₗ e.symm by ext; simp, Module.End.isUnit_iff, LinearMap.coe_comp, LinearMap.coe_comp, LinearEquiv.coe_coe, LinearEquiv.coe_coe, EquivLike.comp_bijective, EquivLike.bijective_comp] exact (Module.End.isUnit_iff _).mp <| hf.map_units s surj' x := by obtain ⟨p, h⟩ := hf.surj' (e.symm x) exact ⟨p, by rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, ← e.congr_arg h, Submonoid.smul_def, Submonoid.smul_def, LinearEquiv.map_smul, LinearEquiv.apply_symm_apply]⟩ exists_of_eq h := by simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, EmbeddingLike.apply_eq_iff_eq] at h exact hf.exists_of_eq h instance IsLocalizedModule.of_linearEquiv_right (e : M'' ≃ₗ[R] M) [hf : IsLocalizedModule S f] : IsLocalizedModule S (f ∘ₗ e : M'' →ₗ[R] M') where map_units s := hf.map_units s surj' x := by obtain ⟨⟨p, s⟩, h⟩ := hf.surj' x exact ⟨⟨e.symm p, s⟩, by simpa using h⟩ exists_of_eq h := by simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply] at h obtain ⟨c, hc⟩ := hf.exists_of_eq h exact ⟨c, by simpa only [Submonoid.smul_def, map_smul, e.symm_apply_apply] using congr(e.symm $hc)⟩ variable (M) in lemma isLocalizedModule_id (R') [CommSemiring R'] [Algebra R R'] [IsLocalization S R'] [Module R' M] [IsScalarTower R R' M] : IsLocalizedModule S (.id : M →ₗ[R] M) where map_units s := by rw [← (Algebra.lsmul R (A := R') R M).commutes]; exact (IsLocalization.map_units R' s).map _ surj' m := ⟨(m, 1), one_smul _ _⟩ exists_of_eq h := ⟨1, congr_arg _ h⟩ namespace LocalizedModule /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `LocalizedModule S M → M''`. -/ noncomputable def lift' (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit (algebraMap R (Module.End R M'') x)) : LocalizedModule S M → M'' := fun m => m.liftOn (fun p => (h p.2).unit⁻¹.val <| g p.1) fun ⟨m, s⟩ ⟨m', s'⟩ ⟨c, eq1⟩ => by dsimp only simp only [Submonoid.smul_def] at eq1 rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← map_smul, eq_comm, Module.End.algebraMap_isUnit_inv_apply_eq_iff] have : c • s • g m' = c • s' • g m := by simp only [Submonoid.smul_def, ← g.map_smul, eq1] have : Function.Injective (h c).unit.inv := ((Module.End.isUnit_iff _).1 (by simp)).1 apply_fun (h c).unit.inv rw [Units.inv_eq_val_inv, Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← (h c).unit⁻¹.val.map_smul] symm rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← g.map_smul, ← g.map_smul, ← g.map_smul, ← g.map_smul, eq1] theorem lift'_mk (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (m : M) (s : S) : LocalizedModule.lift' S g h (LocalizedModule.mk m s) = (h s).unit⁻¹.val (g m) := rfl theorem lift'_add (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (x y) : LocalizedModule.lift' S g h (x + y) = LocalizedModule.lift' S g h x + LocalizedModule.lift' S g h y := LocalizedModule.induction_on₂ (by intro a a' b b' rw [mk_add_mk, LocalizedModule.lift'_mk, LocalizedModule.lift'_mk, LocalizedModule.lift'_mk] rw [map_add, Module.End.algebraMap_isUnit_inv_apply_eq_iff, smul_add, ← map_smul, ← map_smul, ← map_smul] congr 1 <;> symm · rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff] simp only [Submonoid.coe_mul, LinearMap.map_smul_of_tower] rw [mul_smul, Submonoid.smul_def] · dsimp rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, mul_comm, mul_smul, ← map_smul] rfl) x y theorem lift'_smul (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (r : R) (m) : r • LocalizedModule.lift' S g h m = LocalizedModule.lift' S g h (r • m) := m.induction_on fun a b => by rw [LocalizedModule.lift'_mk, LocalizedModule.smul'_mk, LocalizedModule.lift'_mk, ← map_smul, ← g.map_smul] /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `LocalizedModule S M → M''`. -/ noncomputable def lift (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : LocalizedModule S M →ₗ[R] M'' where toFun := LocalizedModule.lift' S g h map_add' := LocalizedModule.lift'_add S g h map_smul' r x := by rw [LocalizedModule.lift'_smul, RingHom.id_apply] /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then `lift g m s = s⁻¹ • g m`. -/ theorem lift_mk (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit (algebraMap R (Module.End R M'') x)) (m : M) (s : S) : LocalizedModule.lift S g h (LocalizedModule.mk m s) = (h s).unit⁻¹.val (g m) := rfl @[simp] lemma lift_mk_one (h : ∀ (x : S), IsUnit ((algebraMap R (Module.End R M'')) x)) (m : M) : (LocalizedModule.lift S g h) (LocalizedModule.mk m 1) = g m := by simp [lift_mk] /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `lift g ∘ mkLinearMap = g`. -/ theorem lift_comp (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : (lift S g h).comp (mkLinearMap S M) = g := by ext x simp [LocalizedModule.lift_mk] /-- If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible and `l` is another linear map `LocalizedModule S M ⟶ M''` such that `l ∘ mkLinearMap = g` then `l = lift g` -/ theorem lift_unique (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (l : LocalizedModule S M →ₗ[R] M'') (hl : l.comp (LocalizedModule.mkLinearMap S M) = g) : LocalizedModule.lift S g h = l := by ext x; induction' x with m s rw [LocalizedModule.lift_mk] rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← hl, LinearMap.coe_comp, Function.comp_apply, LocalizedModule.mkLinearMap_apply, ← l.map_smul, LocalizedModule.smul'_mk] congr 1; rw [LocalizedModule.mk_eq] refine ⟨1, ?_⟩; simp only [one_smul, Submonoid.smul_def] end LocalizedModule instance localizedModuleIsLocalizedModule : IsLocalizedModule S (LocalizedModule.mkLinearMap S M) where map_units s := ⟨⟨algebraMap R (Module.End R (LocalizedModule S M)) s, LocalizedModule.divBy s, DFunLike.ext _ _ <| LocalizedModule.mul_by_divBy s, DFunLike.ext _ _ <| LocalizedModule.divBy_mul_by s⟩, DFunLike.ext _ _ fun p => p.induction_on <| by intros rfl⟩ surj' p := p.induction_on fun m t => by refine ⟨⟨m, t⟩, ?_⟩ rw [Submonoid.smul_def, LocalizedModule.smul'_mk, LocalizedModule.mkLinearMap_apply, ← Submonoid.smul_def, LocalizedModule.mk_cancel t] exists_of_eq eq1 := by simpa only [eq_comm, one_smul] using LocalizedModule.mk_eq.mp eq1 lemma IsLocalizedModule.of_restrictScalars (S : Submonoid R) {N : Type*} [AddCommMonoid N] [Module R N] [Module A M] [Module A N] [IsScalarTower R A M] [IsScalarTower R A N] (f : M →ₗ[A] N) [IsLocalizedModule S (f.restrictScalars R)] : IsLocalizedModule (Algebra.algebraMapSubmonoid A S) f where map_units x := by obtain ⟨_, x, hx, rfl⟩ := x have := IsLocalizedModule.map_units (f.restrictScalars R) ⟨x, hx⟩ simp only [← IsScalarTower.algebraMap_apply, Module.End.isUnit_iff] at this ⊢ exact this surj' y := by obtain ⟨⟨x, t⟩, e⟩ := IsLocalizedModule.surj S (f.restrictScalars R) y exact ⟨⟨x, ⟨_, t, t.2, rfl⟩⟩, by simpa [Submonoid.smul_def] using e⟩ exists_of_eq {x₁ x₂} e := by obtain ⟨c, hc⟩ := IsLocalizedModule.exists_of_eq (S := S) (f := f.restrictScalars R) e refine ⟨⟨_, c, c.2, rfl⟩, by simpa [Submonoid.smul_def]⟩ lemma IsLocalizedModule.of_exists_mul_mem {N : Type*} [AddCommMonoid N] [Module R N] (S T : Submonoid R) (h : S ≤ T) (h' : ∀ x : T, ∃ m : R, m * x ∈ S) (f : M →ₗ[R] N) [IsLocalizedModule S f] : IsLocalizedModule T f where map_units x := by obtain ⟨m, mx⟩ := h' x have := IsLocalizedModule.map_units f ⟨_, mx⟩ rw [map_mul, (Algebra.commute_algebraMap_left _ _).isUnit_mul_iff] at this exact this.2 surj' y := by obtain ⟨⟨x, t⟩, e⟩ := IsLocalizedModule.surj S f y exact ⟨⟨x, ⟨t, h t.2⟩⟩, e⟩ exists_of_eq {x₁ x₂} e := by obtain ⟨c, hc⟩ := IsLocalizedModule.exists_of_eq (S := S) (f := f) e exact ⟨⟨c, h c.2⟩, hc⟩ namespace IsLocalizedModule variable [IsLocalizedModule S f] /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, there is a canonical map `LocalizedModule S M ⟶ M'`. -/ noncomputable def fromLocalizedModule' : LocalizedModule S M → M' := fun p => p.liftOn (fun x => (IsLocalizedModule.map_units f x.2).unit⁻¹.val (f x.1)) (by rintro ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩ dsimp rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← map_smul, ← map_smul, Module.End.algebraMap_isUnit_inv_apply_eq_iff', ← map_smul] exact (IsLocalizedModule.eq_iff_exists S f).mpr ⟨c, eq1.symm⟩) @[simp] theorem fromLocalizedModule'_mk (m : M) (s : S) : fromLocalizedModule' S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl theorem fromLocalizedModule'_add (x y : LocalizedModule S M) : fromLocalizedModule' S f (x + y) = fromLocalizedModule' S f x + fromLocalizedModule' S f y := LocalizedModule.induction_on₂ (by intro a a' b b' simp only [LocalizedModule.mk_add_mk, fromLocalizedModule'_mk] rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, smul_add, ← map_smul, ← map_smul, ← map_smul, map_add] congr 1 all_goals rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff'] · simp [mul_smul, Submonoid.smul_def] · rw [Submonoid.coe_mul, LinearMap.map_smul_of_tower, mul_comm, mul_smul, Submonoid.smul_def]) x y theorem fromLocalizedModule'_smul (r : R) (x : LocalizedModule S M) : r • fromLocalizedModule' S f x = fromLocalizedModule' S f (r • x) := LocalizedModule.induction_on (by intro a b rw [fromLocalizedModule'_mk, LocalizedModule.smul'_mk, fromLocalizedModule'_mk, f.map_smul, map_smul]) x /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, there is a canonical map `LocalizedModule S M ⟶ M'`. -/ noncomputable def fromLocalizedModule : LocalizedModule S M →ₗ[R] M' where toFun := fromLocalizedModule' S f map_add' := fromLocalizedModule'_add S f map_smul' r x := by rw [fromLocalizedModule'_smul, RingHom.id_apply] theorem fromLocalizedModule_mk (m : M) (s : S) : fromLocalizedModule S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl theorem fromLocalizedModule.inj : Function.Injective <| fromLocalizedModule S f := fun x y eq1 => by induction' x with a b induction' y with a' b' simp only [fromLocalizedModule_mk] at eq1 rw [Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← LinearMap.map_smul, Module.End.algebraMap_isUnit_inv_apply_eq_iff'] at eq1 rw [LocalizedModule.mk_eq, ← IsLocalizedModule.eq_iff_exists S f, Submonoid.smul_def, Submonoid.smul_def, f.map_smul, f.map_smul, eq1] theorem fromLocalizedModule.surj : Function.Surjective <| fromLocalizedModule S f := fun x => let ⟨⟨m, s⟩, eq1⟩ := IsLocalizedModule.surj S f x ⟨LocalizedModule.mk m s, by rw [fromLocalizedModule_mk, Module.End.algebraMap_isUnit_inv_apply_eq_iff, ← eq1, Submonoid.smul_def]⟩ theorem fromLocalizedModule.bij : Function.Bijective <| fromLocalizedModule S f := ⟨fromLocalizedModule.inj _ _, fromLocalizedModule.surj _ _⟩ /-- If `(M', f : M ⟶ M')` satisfies universal property of localized module, then `M'` is isomorphic to `LocalizedModule S M` as an `R`-module. -/ noncomputable def iso : LocalizedModule S M ≃ₗ[R] M' := { fromLocalizedModule S f, Equiv.ofBijective (fromLocalizedModule S f) <| fromLocalizedModule.bij _ _ with } theorem iso_apply_mk (m : M) (s : S) : iso S f (LocalizedModule.mk m s) = (IsLocalizedModule.map_units f s).unit⁻¹.val (f m) := rfl @[simp] lemma iso_mk_one (x : M) : (iso S f) (LocalizedModule.mk x 1) = f x := by simp [iso_apply_mk] theorem iso_symm_apply_aux (m : M') : (iso S f).symm m = LocalizedModule.mk (IsLocalizedModule.surj S f m).choose.1 (IsLocalizedModule.surj S f m).choose.2 := by apply_fun iso S f using LinearEquiv.injective (iso S f) rw [LinearEquiv.apply_symm_apply] simp [iso, fromLocalizedModule, Module.End.algebraMap_isUnit_inv_apply_eq_iff', ← Submonoid.smul_def, (surj' _).choose_spec] theorem iso_symm_apply' (m : M') (a : M) (b : S) (eq1 : b • m = f a) : (iso S f).symm m = LocalizedModule.mk a b := (iso_symm_apply_aux S f m).trans <| LocalizedModule.mk_eq.mpr <| by rw [← IsLocalizedModule.eq_iff_exists S f, Submonoid.smul_def, Submonoid.smul_def, f.map_smul, f.map_smul, ← (surj' _).choose_spec, ← Submonoid.smul_def, ← Submonoid.smul_def, ← mul_smul, mul_comm, mul_smul, eq1] theorem iso_symm_comp : (iso S f).symm.toLinearMap.comp f = LocalizedModule.mkLinearMap S M := by ext m rw [LinearMap.comp_apply, LocalizedModule.mkLinearMap_apply, LinearEquiv.coe_coe, iso_symm_apply'] exact one_smul _ _ @[simp] lemma iso_symm_apply (x) : (iso S f).symm (f x) = LocalizedModule.mk x 1 := DFunLike.congr_fun (iso_symm_comp S f) x /-- If `M'` is a localized module and `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then there is a linear map `M' → M''`. -/ noncomputable def lift (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : M' →ₗ[R] M'' := (LocalizedModule.lift S g h).comp (iso S f).symm.toLinearMap theorem lift_comp (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) : (lift S f g h).comp f = g := by dsimp only [IsLocalizedModule.lift] rw [LinearMap.comp_assoc, iso_symm_comp, LocalizedModule.lift_comp S g h] @[simp] lemma lift_iso (h : ∀ (x : S), IsUnit ((algebraMap R (Module.End R M'')) x)) (x : LocalizedModule S M) : IsLocalizedModule.lift S f g h ((iso S f) x) = LocalizedModule.lift S g h x := by simp [lift] @[simp] lemma lift_comp_iso (h : ∀ (x : S), IsUnit ((algebraMap R (Module.End R M'')) x)) : IsLocalizedModule.lift S f g h ∘ₗ iso S f = LocalizedModule.lift S g h := LinearMap.ext fun x ↦ lift_iso S f g h x @[simp] theorem lift_apply (g : M →ₗ[R] M'') (h) (x) : lift S f g h (f x) = g x := LinearMap.congr_fun (lift_comp S f g h) x theorem lift_unique (g : M →ₗ[R] M'') (h : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) (l : M' →ₗ[R] M'') (hl : l.comp f = g) : lift S f g h = l := by dsimp only [IsLocalizedModule.lift] rw [LocalizedModule.lift_unique S g h (l.comp (iso S f).toLinearMap), LinearMap.comp_assoc, LinearEquiv.comp_coe, LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, LinearMap.comp_id] rw [LinearMap.comp_assoc, ← hl] congr 1 ext x simp /-- Universal property from localized module: If `(M', f : M ⟶ M')` is a localized module then it satisfies the following universal property: For every `R`-module `M''` which every `s : S`-scalar multiplication is invertible and for every `R`-linear map `g : M ⟶ M''`, there is a unique `R`-linear map `l : M' ⟶ M''` such that `l ∘ f = g`. ``` M -----f----> M' | / |g / | / l v / M'' ``` -/ theorem is_universal : ∀ (g : M →ₗ[R] M'') (_ : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)), ∃! l : M' →ₗ[R] M'', l.comp f = g := fun g h => ⟨lift S f g h, lift_comp S f g h, fun l hl => (lift_unique S f g h l hl).symm⟩ theorem linearMap_ext {N N'} [AddCommMonoid N] [Module R N] [AddCommMonoid N'] [Module R N'] (f' : N →ₗ[R] N') [IsLocalizedModule S f'] ⦃g g' : M' →ₗ[R] N'⦄ (h : g ∘ₗ f = g' ∘ₗ f) : g = g' := (is_universal S f _ <| map_units f').unique h rfl theorem ext (map_unit : ∀ x : S, IsUnit ((algebraMap R (Module.End R M'')) x)) ⦃j k : M' →ₗ[R] M''⦄ (h : j.comp f = k.comp f) : j = k := by rw [← lift_unique S f (k.comp f) map_unit j h, lift_unique] rfl /-- If `(M', f)` and `(M'', g)` both satisfy universal property of localized module, then `M', M''` are isomorphic as `R`-module -/ noncomputable def linearEquiv [IsLocalizedModule S g] : M' ≃ₗ[R] M'' := (iso S f).symm.trans (iso S g) @[simp] lemma linearEquiv_apply [IsLocalizedModule S g] (x : M) : (linearEquiv S f g) (f x) = g x := by simp [linearEquiv] @[simp] lemma linearEquiv_symm_apply [IsLocalizedModule S g] (x : M) : (linearEquiv S f g).symm (g x) = f x := by simp [linearEquiv] variable {S} include f in theorem smul_injective (s : S) : Function.Injective fun m : M' => s • m := ((Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units f s)).injective include f in theorem smul_inj (s : S) (m₁ m₂ : M') : s • m₁ = s • m₂ ↔ m₁ = m₂ := (smul_injective f s).eq_iff include f in lemma isRegular_of_smul_left_injective {m : M'} (inj : Function.Injective fun r : R ↦ r • m) (s : S) : IsRegular (s : R) := (Commute.isRegular_iff (Commute.all _)).mpr fun r r' eq ↦ by have := congr_arg (· • m) eq simp_rw [mul_smul, ← Submonoid.smul_def, smul_inj f] at this exact inj this /-- `mk' f m s` is the fraction `m/s` with respect to the localization map `f`. -/ noncomputable def mk' (m : M) (s : S) : M' := fromLocalizedModule S f (LocalizedModule.mk m s) theorem mk'_smul (r : R) (m : M) (s : S) : mk' f (r • m) s = r • mk' f m s := by delta mk' rw [← LocalizedModule.smul'_mk, LinearMap.map_smul] theorem mk'_add_mk' (m₁ m₂ : M) (s₁ s₂ : S) : mk' f m₁ s₁ + mk' f m₂ s₂ = mk' f (s₂ • m₁ + s₁ • m₂) (s₁ * s₂) := by delta mk' rw [← map_add, LocalizedModule.mk_add_mk] @[simp] theorem mk'_zero (s : S) : mk' f 0 s = 0 := by rw [← zero_smul R (0 : M), mk'_smul, zero_smul] variable (S) in @[simp] theorem mk'_one (m : M) : mk' f m (1 : S) = f m := by delta mk' rw [fromLocalizedModule_mk, Module.End.algebraMap_isUnit_inv_apply_eq_iff, Submonoid.coe_one, one_smul] @[simp] theorem mk'_cancel (m : M) (s : S) : mk' f (s • m) s = f m := by delta mk' rw [LocalizedModule.mk_cancel, ← mk'_one S f, fromLocalizedModule_mk, Module.End.algebraMap_isUnit_inv_apply_eq_iff, OneMemClass.coe_one, mk'_one, one_smul] @[simp] theorem mk'_cancel' (m : M) (s : S) : s • mk' f m s = f m := by rw [Submonoid.smul_def, ← mk'_smul, ← Submonoid.smul_def, mk'_cancel] @[simp] theorem mk'_cancel_left (m : M) (s₁ s₂ : S) : mk' f (s₁ • m) (s₁ * s₂) = mk' f m s₂ := by delta mk' rw [LocalizedModule.mk_cancel_common_left] @[simp] theorem mk'_cancel_right (m : M) (s₁ s₂ : S) : mk' f (s₂ • m) (s₁ * s₂) = mk' f m s₁ := by delta mk' rw [LocalizedModule.mk_cancel_common_right] theorem mk'_add (m₁ m₂ : M) (s : S) : mk' f (m₁ + m₂) s = mk' f m₁ s + mk' f m₂ s := by rw [mk'_add_mk', ← smul_add, mk'_cancel_left] theorem mk'_eq_mk'_iff (m₁ m₂ : M) (s₁ s₂ : S) : mk' f m₁ s₁ = mk' f m₂ s₂ ↔ ∃ s : S, s • s₁ • m₂ = s • s₂ • m₁ := by delta mk' rw [(fromLocalizedModule.inj S f).eq_iff, LocalizedModule.mk_eq] simp_rw [eq_comm] theorem mk'_neg {M M' : Type*} [AddCommGroup M] [SubtractionCommMonoid M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] (m : M) (s : S) : mk' f (-m) s = -mk' f m s := by delta mk' rw [LocalizedModule.mk_neg, map_neg] theorem mk'_sub {M M' : Type*} [AddCommGroup M] [SubtractionCommMonoid M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] (m₁ m₂ : M) (s : S) : mk' f (m₁ - m₂) s = mk' f m₁ s - mk' f m₂ s := by rw [sub_eq_add_neg, sub_eq_add_neg, mk'_add, mk'_neg] theorem mk'_sub_mk' {M M' : Type*} [AddCommGroup M] [SubtractionCommMonoid M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] (m₁ m₂ : M) (s₁ s₂ : S) : mk' f m₁ s₁ - mk' f m₂ s₂ = mk' f (s₂ • m₁ - s₁ • m₂) (s₁ * s₂) := by rw [sub_eq_add_neg, ← mk'_neg, mk'_add_mk', smul_neg, ← sub_eq_add_neg] theorem mk'_mul_mk'_of_map_mul {M M' : Type*} [NonUnitalNonAssocSemiring M] [Semiring M'] [Module R M] [Algebra R M'] (f : M →ₗ[R] M') (hf : ∀ m₁ m₂, f (m₁ * m₂) = f m₁ * f m₂) [IsLocalizedModule S f] (m₁ m₂ : M) (s₁ s₂ : S) : mk' f m₁ s₁ * mk' f m₂ s₂ = mk' f (m₁ * m₂) (s₁ * s₂) := by symm apply (Module.End.algebraMap_isUnit_inv_apply_eq_iff _ _ _ _).mpr simp_rw [Submonoid.coe_mul, ← smul_eq_mul] rw [smul_smul_smul_comm, ← mk'_smul, ← mk'_smul] simp_rw [← Submonoid.smul_def, mk'_cancel, smul_eq_mul, hf] theorem mk'_mul_mk' {M M' : Type*} [Semiring M] [Semiring M'] [Algebra R M] [Algebra R M'] (f : M →ₐ[R] M') [IsLocalizedModule S f.toLinearMap] (m₁ m₂ : M) (s₁ s₂ : S) : mk' f.toLinearMap m₁ s₁ * mk' f.toLinearMap m₂ s₂ = mk' f.toLinearMap (m₁ * m₂) (s₁ * s₂) := mk'_mul_mk'_of_map_mul f.toLinearMap (map_mul f) m₁ m₂ s₁ s₂ variable {f} theorem mk'_eq_iff {m : M} {s : S} {m' : M'} : mk' f m s = m' ↔ f m = s • m' := by rw [← smul_inj f s, Submonoid.smul_def, ← mk'_smul, ← Submonoid.smul_def, mk'_cancel] @[simp] theorem mk'_eq_zero {m : M} (s : S) : mk' f m s = 0 ↔ f m = 0 := by rw [mk'_eq_iff, smul_zero] variable (f) theorem mk'_eq_zero' {m : M} (s : S) : mk' f m s = 0 ↔ ∃ s' : S, s' • m = 0 := by simp_rw [← mk'_zero f (1 : S), mk'_eq_mk'_iff, smul_zero, one_smul, eq_comm] theorem mk_eq_mk' (s : S) (m : M) : LocalizedModule.mk m s = mk' (LocalizedModule.mkLinearMap S M) m s := by rw [eq_comm, mk'_eq_iff, Submonoid.smul_def, LocalizedModule.smul'_mk, ← Submonoid.smul_def, LocalizedModule.mk_cancel, LocalizedModule.mkLinearMap_apply] variable (A) in lemma mk'_smul_mk' (x : R) (m : M) (s t : S) : IsLocalization.mk' A x s • mk' f m t = mk' f (x • m) (s * t) := by apply smul_injective f (s * t) conv_lhs => simp only [smul_assoc, mul_smul, smul_comm t] simp only [mk'_cancel', map_smul, Submonoid.smul_def s] rw [← smul_assoc, IsLocalization.smul_mk'_self, algebraMap_smul] variable (S) theorem eq_zero_iff {m : M} : f m = 0 ↔ ∃ s' : S, s' • m = 0 := (mk'_eq_zero (1 : S)).symm.trans (mk'_eq_zero' f _) theorem mk'_surjective : Function.Surjective (Function.uncurry <| mk' f : M × S → M') := by intro x obtain ⟨⟨m, s⟩, e : s • x = f m⟩ := IsLocalizedModule.surj S f x exact ⟨⟨m, s⟩, mk'_eq_iff.mpr e.symm⟩ section liftOfLE variable {M₁ M₂} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (S₁ S₂ : Submonoid R) (h : S₁ ≤ S₂) (f₁ : M →ₗ[R] M₁) (f₂ : M →ₗ[R] M₂) variable [IsLocalizedModule S₁ f₁] [IsLocalizedModule S₂ f₂] /-- The natural map `Mₛ →ₗ[R] Mₜ` if `s ≤ t` (in `Submonoid R`). -/ noncomputable def liftOfLE : M₁ →ₗ[R] M₂ := lift S₁ f₁ f₂ fun x ↦ map_units f₂ ⟨x.1, h x.2⟩ /-- The natural map `Mₛ →ₗ[R] Mₜ` if `s ≤ t` (in `Submonoid R`). -/ noncomputable abbrev _root_.LocalizedModule.liftOfLE : LocalizedModule S₁ M →ₗ[R] LocalizedModule S₂ M := IsLocalizedModule.liftOfLE S₁ S₂ h (LocalizedModule.mkLinearMap S₁ M) (LocalizedModule.mkLinearMap S₂ M) lemma liftOfLE_comp : (liftOfLE S₁ S₂ h f₁ f₂).comp f₁ = f₂ := lift_comp .. @[simp] lemma liftOfLE_apply (x) : liftOfLE S₁ S₂ h f₁ f₂ (f₁ x) = f₂ x := lift_apply .. /-- The image of `m/s` under `liftOfLE` is `m/s`. -/ @[simp] lemma liftOfLE_mk' (m : M) (s : S₁) : liftOfLE S₁ S₂ h f₁ f₂ (mk' f₁ m s) = mk' f₂ m ⟨s.1, h s.2⟩ := by apply ((Module.End.isUnit_iff _).mp (map_units f₂ ⟨s, h s.2⟩)).1 simp only [Module.algebraMap_end_apply, ← map_smul, ← Submonoid.smul_def, mk'_cancel'] rw [liftOfLE, lift_apply] exact (mk'_cancel' (S := S₂) f₂ m ⟨s.1, h s.2⟩).symm instance : IsLocalizedModule S₂ (liftOfLE S₁ S₂ h f₁ f₂) where map_units := map_units f₂ surj' y := by obtain ⟨⟨y', s⟩, e⟩ := IsLocalizedModule.surj S₂ f₂ y exact ⟨⟨f₁ y', s⟩, by simpa⟩ exists_of_eq := by intros x₁ x₂ e obtain ⟨x₁, s₁, rfl⟩ := mk'_surjective S₁ f₁ x₁ obtain ⟨x₂, s₂, rfl⟩ := mk'_surjective S₁ f₁ x₂ simp only [Function.uncurry, liftOfLE_mk', mk'_eq_mk'_iff, Submonoid.smul_def, ← mk'_smul] at e ⊢ obtain ⟨c, e⟩ := e exact ⟨c, 1, by simpa [← smul_comm c.1]⟩ end liftOfLE include S in lemma injective_of_map_eq {N : Type*} [AddCommMonoid N] [Module R N] {g : M' →ₗ[R] N} (H : ∀ {x y}, g (f x) = g (f y) → f x = f y) : Function.Injective g := by intro a b hab obtain ⟨⟨x, m⟩, (hxm : m • a = f x)⟩ := IsLocalizedModule.surj S f a obtain ⟨⟨y, n⟩, (hym : n • b = f y)⟩ := IsLocalizedModule.surj S f b suffices h : g (f (n.val • x)) = g (f (m.val • y)) by apply H at h rw [map_smul, map_smul] at h rwa [← IsLocalizedModule.smul_inj f (n * m), mul_smul, mul_comm, mul_smul, hxm, hym] simp [← hxm, ← hym, hab, ← S.smul_def, ← mul_smul, mul_comm, ← mul_smul] lemma injective_of_map_zero {M M' N : Type*} [AddCommGroup M] [AddCommGroup M'] [Module R M] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] [AddCommGroup N] [Module R N] {g : M' →ₗ[R] N} (H : ∀ m, g (f m) = 0 → f m = 0) : Function.Injective g := by refine IsLocalizedModule.injective_of_map_eq S f (fun hxy ↦ ?_) rw [← sub_eq_zero, ← map_sub] apply H simpa [sub_eq_zero] variable {N N'} [AddCommMonoid N] [AddCommMonoid N'] [Module R N] [Module R N'] variable (g : N →ₗ[R] N') [IsLocalizedModule S g] /-- A linear map `M →ₗ[R] N` gives a map between localized modules `Mₛ →ₗ[R] Nₛ`. -/ noncomputable def map : (M →ₗ[R] N) →ₗ[R] (M' →ₗ[R] N') where toFun h := lift S f (g ∘ₗ h) (IsLocalizedModule.map_units g) map_add' h₁ h₂ := by apply IsLocalizedModule.ext S f (IsLocalizedModule.map_units g) simp only [lift_comp, LinearMap.add_comp, LinearMap.comp_add] map_smul' r h := by apply IsLocalizedModule.ext S f (IsLocalizedModule.map_units g) simp only [lift_comp, LinearMap.smul_comp, LinearMap.comp_smul, RingHom.id_apply] lemma map_comp (h : M →ₗ[R] N) : (map S f g h) ∘ₗ f = g ∘ₗ h := lift_comp S f (g ∘ₗ h) (IsLocalizedModule.map_units g) @[simp] lemma map_apply (h : M →ₗ[R] N) (x) : map S f g h (f x) = g (h x) := lift_apply S f (g ∘ₗ h) (IsLocalizedModule.map_units g) x @[simp] lemma map_mk' (h : M →ₗ[R] N) (x) (s : S) : map S f g h (IsLocalizedModule.mk' f x s) = (IsLocalizedModule.mk' g (h x) s) := by simp only [map, lift, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply] rw [iso_symm_apply' S f (mk' f x s) x s (mk'_cancel' f x s), LocalizedModule.lift_mk] rfl @[simp] lemma map_id : map S f f (.id ) = .id := by ext x obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f x simp @[simp] theorem map_injective (h : M →ₗ[R] N) (h_inj : Function.Injective h) : Function.Injective (map S f g h) := by intros x y obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f x obtain ⟨⟨y, t⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f y simp only [Function.uncurry_apply_pair, map_mk', mk'_eq_mk'_iff, Subtype.exists, Submonoid.mk_smul, exists_prop, forall_exists_index, and_imp] intros c hc e exact ⟨c, hc, h_inj (by simpa)⟩ @[simp] theorem map_surjective (h : M →ₗ[R] N) (h_surj : Function.Surjective h) : Function.Surjective (map S f g h) := by intros x obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S g x obtain ⟨x, rfl⟩ := h_surj x exact ⟨mk' f x s, by simp⟩ open LocalizedModule LinearEquiv LinearMap Submonoid variable (M) /-- The linear map `(LocalizedModule S M) → (LocalizedModule S M)` from `iso` is the identity. -/ lemma iso_localizedModule_eq_refl : iso S (mkLinearMap S M) = refl R (LocalizedModule S M) := by let f := mkLinearMap S M obtain ⟨e, _, univ⟩ := is_universal S f f (map_units f) rw [← toLinearMap_inj, univ (iso S f) ((eq_toLinearMap_symm_comp f f).1 (iso_symm_comp S f).symm)] exact Eq.symm <| univ (refl R (LocalizedModule S M)) (by simp) variable {M₀ M₀'} [AddCommMonoid M₀] [AddCommMonoid M₀'] [Module R M₀] [Module R M₀'] variable (f₀ : M₀ →ₗ[R] M₀') [IsLocalizedModule S f₀] variable {M₁ M₁'} [AddCommMonoid M₁] [AddCommMonoid M₁'] [Module R M₁] [Module R M₁'] variable (f₁ : M₁ →ₗ[R] M₁') [IsLocalizedModule S f₁] /-- Formula for `IsLocalizedModule.map` when each localized module is a `LocalizedModule`. -/ lemma map_LocalizedModules (g : M₀ →ₗ[R] M₁) (m : M₀) (s : S) : ((map S (mkLinearMap S M₀) (mkLinearMap S M₁)) g) (LocalizedModule.mk m s) = LocalizedModule.mk (g m) s := by have := (iso_apply_mk S (mkLinearMap S M₁) (g m) s).symm rw [iso_localizedModule_eq_refl, refl_apply] at this simpa [map, lift, iso_localizedModule_eq_refl S M₀] lemma map_iso_commute (g : M₀ →ₗ[R] M₁) : (map S f₀ f₁) g ∘ₗ (iso S f₀) = (iso S f₁) ∘ₗ (map S (mkLinearMap S M₀) (mkLinearMap S M₁)) g := by ext x refine induction_on (fun m s ↦ ((Module.End.isUnit_iff _).1 (map_units f₁ s)).1 ?_) x repeat rw [Module.algebraMap_end_apply, ← CompatibleSMul.map_smul, smul'_mk, ← mk_smul, mk_cancel] simp -- Can't be combined with next simp. This uses map_apply, which would be preempted by map. simp [map, lift, iso_localizedModule_eq_refl, lift_mk] end IsLocalizedModule namespace IsLocalizedModule variable {M₀ M₀'} [AddCommMonoid M₀] [AddCommMonoid M₀'] [Module R M₀] [Module R M₀'] variable (f₀ : M₀ →ₗ[R] M₀') [IsLocalizedModule S f₀] variable {M₁ M₁'} [AddCommMonoid M₁] [AddCommMonoid M₁'] [Module R M₁] [Module R M₁'] variable (f₁ : M₁ →ₗ[R] M₁') [IsLocalizedModule S f₁] variable {M₂ M₂'} [AddCommMonoid M₂] [AddCommMonoid M₂'] [Module R M₂] [Module R M₂'] variable (f₂ : M₂ →ₗ[R] M₂') [IsLocalizedModule S f₂] /-- Localization of composition is the composition of localization -/ theorem map_comp' (g : M₀ →ₗ[R] M₁) (h : M₁ →ₗ[R] M₂) : map S f₀ f₂ (h ∘ₗ g) = map S f₁ f₂ h ∘ₗ map S f₀ f₁ g := by ext x obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S f₀ x simp section Algebra theorem mkOfAlgebra {R S S' : Type*} [CommSemiring R] [Ring S] [Ring S'] [Algebra R S] [Algebra R S'] (M : Submonoid R) (f : S →ₐ[R] S') (h₁ : ∀ x ∈ M, IsUnit (algebraMap R S' x)) (h₂ : ∀ y, ∃ x : S × M, x.2 • y = f x.1) (h₃ : ∀ x, f x = 0 → ∃ m : M, m • x = 0) : IsLocalizedModule M f.toLinearMap := by replace h₃ := fun x => Iff.intro (h₃ x) fun ⟨⟨m, hm⟩, e⟩ => (h₁ m hm).mul_left_cancel <| by rw [← Algebra.smul_def] simpa [Submonoid.smul_def] using f.congr_arg e constructor · intro x rw [Module.End.isUnit_iff] constructor · rintro a b (e : x • a = x • b) simp_rw [Submonoid.smul_def, Algebra.smul_def] at e exact (h₁ x x.2).mul_left_cancel e · intro a refine ⟨((h₁ x x.2).unit⁻¹ :) * a, ?_⟩ rw [Module.algebraMap_end_apply, Algebra.smul_def, ← mul_assoc, IsUnit.mul_val_inv, one_mul] · exact h₂ · intros x y dsimp only [AlgHom.toLinearMap_apply] rw [← sub_eq_zero, ← map_sub, h₃] simp_rw [smul_sub, sub_eq_zero] exact id end Algebra variable {R A M M' : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Submonoid R) [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] [IsLocalization S A] /-- If `M'` is the localization of `M` at `S` and `A = S⁻¹R`, then `M' is an `A`-module. -/ @[reducible] noncomputable def module (f : M →ₗ[R] M') [IsLocalizedModule S f] : Module A M' := (IsLocalizedModule.iso S f).symm.toAddEquiv.module A lemma isScalarTower_module (f : M →ₗ[R] M') [IsLocalizedModule S f] : letI : Module A M' := IsLocalizedModule.module S f IsScalarTower R A M' := (IsLocalizedModule.iso S f).symm.isScalarTower A section Subsingleton lemma mem_ker_iff (S : Submonoid R) {g : M →ₗ[R] M'} [IsLocalizedModule S g] {m : M} : m ∈ LinearMap.ker g ↔ ∃ r ∈ S, r • m = 0 := by simpa using IsLocalizedModule.eq_zero_iff S g lemma subsingleton_iff_ker_eq_top (S : Submonoid R) (g : M →ₗ[R] M') [IsLocalizedModule S g] : Subsingleton M' ↔ LinearMap.ker g = ⊤ := by rw [← top_le_iff] refine ⟨fun H m _ ↦ Subsingleton.elim _ _, fun H ↦ (subsingleton_iff_forall_eq 0).mpr fun x ↦ ?_⟩ obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective S g x simpa using @H x Submodule.mem_top lemma subsingleton_iff (S : Submonoid R) (g : M →ₗ[R] M') [IsLocalizedModule S g] : Subsingleton M' ↔ ∀ m : M, ∃ r ∈ S, r • m = 0 := by simp_rw [subsingleton_iff_ker_eq_top S g, ← top_le_iff, SetLike.le_def, mem_ker_iff S, Submodule.mem_top, true_implies] end Subsingleton end IsLocalizedModule end IsLocalizedModule namespace LocalizedModule variable {R M : Type*} [CommRing R] [AddCommMonoid M] [Module R M] lemma mem_ker_mkLinearMap_iff {S : Submonoid R} {m : M} : m ∈ LinearMap.ker (mkLinearMap S M) ↔ ∃ r ∈ S, r • m = 0 := IsLocalizedModule.mem_ker_iff S lemma subsingleton_iff_ker_eq_top {S : Submonoid R} : Subsingleton (LocalizedModule S M) ↔ LinearMap.ker (LocalizedModule.mkLinearMap S M) = ⊤ := IsLocalizedModule.subsingleton_iff_ker_eq_top S _ lemma subsingleton_iff {S : Submonoid R} : Subsingleton (LocalizedModule S M) ↔ ∀ m : M, ∃ r ∈ S, r • m = 0 := IsLocalizedModule.subsingleton_iff S (LocalizedModule.mkLinearMap S M) instance [Subsingleton M] (S : Submonoid R) : Subsingleton (LocalizedModule S M) := by rw [IsLocalizedModule.subsingleton_iff S (LocalizedModule.mkLinearMap S M)] intro use 1, S.one_mem, Subsingleton.elim _ _ end LocalizedModule
Functor.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Closed.Cartesian import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Adjunction.FullyFaithful /-! # Cartesian closed functors Define the exponential comparison morphisms for a functor which preserves binary products, and use them to define a cartesian closed functor: one which (naturally) preserves exponentials. Define the Frobenius morphism, and show it is an isomorphism iff the exponential comparison is an isomorphism. ## TODO Some of the results here are true more generally for closed objects and for closed monoidal categories, and these could be generalised. ## References https://ncatlab.org/nlab/show/cartesian+closed+functor https://ncatlab.org/nlab/show/Frobenius+reciprocity ## Tags Frobenius reciprocity, cartesian closed functor -/ noncomputable section namespace CategoryTheory open Category CartesianClosed MonoidalCategory CartesianMonoidalCategory TwoSquare universe v u u' variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v} D] variable [CartesianMonoidalCategory C] [CartesianMonoidalCategory D] variable (F : C ⥤ D) {L : D ⥤ C} /-- The Frobenius morphism for an adjunction `L ⊣ F` at `A` is given by the morphism L(FA ⨯ B) ⟶ LFA ⨯ LB ⟶ A ⨯ LB natural in `B`, where the first morphism is the product comparison and the latter uses the counit of the adjunction. We will show that if `C` and `D` are cartesian closed, then this morphism is an isomorphism for all `A` iff `F` is a cartesian closed functor, i.e. it preserves exponentials. -/ def frobeniusMorphism (h : L ⊣ F) (A : C) : TwoSquare (tensorLeft (F.obj A)) L L (tensorLeft A) := prodComparisonNatTrans L (F.obj A) ≫ Functor.whiskerLeft _ ((curriedTensor C).map (h.counit.app _)) /-- If `F` is full and faithful and has a left adjoint `L` which preserves binary products, then the Frobenius morphism is an isomorphism. -/ instance frobeniusMorphism_iso_of_preserves_binary_products (h : L ⊣ F) (A : C) [Limits.PreservesLimitsOfShape (Discrete Limits.WalkingPair) L] [F.Full] [F.Faithful] : IsIso (frobeniusMorphism F h A).natTrans := suffices ∀ (X : D), IsIso ((frobeniusMorphism F h A).natTrans.app X) from NatIso.isIso_of_isIso_app _ fun B ↦ by dsimp [frobeniusMorphism]; infer_instance variable [CartesianClosed C] [CartesianClosed D] variable [Limits.PreservesLimitsOfShape (Discrete Limits.WalkingPair) F] /-- The exponential comparison map. `F` is a cartesian closed functor if this is an iso for all `A`. -/ def expComparison (A : C) : TwoSquare (exp A) F F (exp (F.obj A)) := mateEquiv (exp.adjunction A) (exp.adjunction (F.obj A)) (prodComparisonNatIso F A).inv theorem expComparison_ev (A B : C) : F.obj A ◁ ((expComparison F A).natTrans.app B) ≫ (exp.ev (F.obj A)).app (F.obj B) = inv (prodComparison F _ _) ≫ F.map ((exp.ev _).app _) := by convert mateEquiv_counit _ _ (prodComparisonNatIso F A).inv B using 2 apply IsIso.inv_eq_of_hom_inv_id -- Porting note: was `ext` simp only [prodComparisonNatTrans_app, prodComparisonNatIso_inv, NatIso.isIso_inv_app, IsIso.hom_inv_id] theorem coev_expComparison (A B : C) : F.map ((exp.coev A).app B) ≫ (expComparison F A).natTrans.app (A ⊗ B) = (exp.coev _).app (F.obj B) ≫ (exp (F.obj A)).map (inv (prodComparison F A B)) := by convert unit_mateEquiv _ _ (prodComparisonNatIso F A).inv B using 3 apply IsIso.inv_eq_of_hom_inv_id -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): was `ext` simp theorem uncurry_expComparison (A B : C) : CartesianClosed.uncurry ((expComparison F A).natTrans.app B) = inv (prodComparison F _ _) ≫ F.map ((exp.ev _).app _) := by rw [uncurry_eq, expComparison_ev] /-- The exponential comparison map is natural in `A`. -/ theorem expComparison_whiskerLeft {A A' : C} (f : A' ⟶ A) : (expComparison F A).whiskerBottom (pre (F.map f)) = (expComparison F A').whiskerTop (pre f) := by unfold expComparison pre have vcomp1 := mateEquiv_conjugateEquiv_vcomp (exp.adjunction A) (exp.adjunction (F.obj A)) (exp.adjunction (F.obj A')) ((prodComparisonNatIso F A).inv) (((curriedTensor D).map (F.map f))) have vcomp2 := conjugateEquiv_mateEquiv_vcomp (exp.adjunction A) (exp.adjunction A') (exp.adjunction (F.obj A')) (((curriedTensor C).map f)) ((prodComparisonNatIso F A').inv) rw [← vcomp1, ← vcomp2] unfold TwoSquare.whiskerLeft TwoSquare.whiskerRight congr 1 apply congr_arg ext B simp only [Functor.comp_obj, curriedTensor_obj_obj, prodComparisonNatIso_inv, NatTrans.comp_app, Functor.whiskerLeft_app, curriedTensor_map_app, NatIso.isIso_inv_app, Functor.whiskerRight_app, IsIso.eq_inv_comp, prodComparisonNatTrans_app] rw [← prodComparison_inv_natural_whiskerRight F f] simp /-- The functor `F` is cartesian closed (ie preserves exponentials) if each natural transformation `exp_comparison F A` is an isomorphism -/ class CartesianClosedFunctor : Prop where comparison_iso : ∀ A, IsIso (expComparison F A).natTrans attribute [instance] CartesianClosedFunctor.comparison_iso theorem frobeniusMorphism_mate (h : L ⊣ F) (A : C) : conjugateEquiv (h.comp (exp.adjunction A)) ((exp.adjunction (F.obj A)).comp h) (frobeniusMorphism F h A).natTrans = (expComparison F A).natTrans := by unfold expComparison frobeniusMorphism have conjeq := iterated_mateEquiv_conjugateEquiv h h (exp.adjunction (F.obj A)) (exp.adjunction A) (prodComparisonNatTrans L (F.obj A) ≫ Functor.whiskerLeft L ((curriedTensor C).map (h.counit.app A))) rw [← conjeq] congr 1 apply congr_arg ext B unfold mateEquiv simp only [Functor.comp_obj, curriedTensor_obj_obj, Equiv.coe_fn_mk, Functor.whiskerRight_comp, Functor.whiskerLeft_comp, assoc, NatTrans.comp_app, Functor.id_obj, Functor.rightUnitor_inv_app, Functor.whiskerLeft_app, Functor.associator_hom_app, Functor.associator_inv_app, Functor.whiskerRight_app, prodComparisonNatTrans_app, curriedTensor_map_app, Functor.comp_map, curriedTensor_obj_map, Functor.leftUnitor_hom_app, comp_id, id_comp, prodComparisonNatIso_inv, NatIso.isIso_inv_app] rw [← F.map_comp, ← F.map_comp] simp only [Functor.map_comp] apply IsIso.eq_inv_of_inv_hom_id simp only [assoc] rw [prodComparison_natural_whiskerLeft, prodComparison_natural_whiskerRight_assoc] slice_lhs 2 3 => rw [← prodComparison_comp] simp only [assoc] unfold prodComparison simp /-- If the exponential comparison transformation (at `A`) is an isomorphism, then the Frobenius morphism at `A` is an isomorphism. -/ theorem frobeniusMorphism_iso_of_expComparison_iso (h : L ⊣ F) (A : C) [i : IsIso (expComparison F A).natTrans] : IsIso (frobeniusMorphism F h A).natTrans := by rw [← frobeniusMorphism_mate F h] at i exact @conjugateEquiv_of_iso _ _ _ _ _ _ _ _ _ _ _ i /-- If the Frobenius morphism at `A` is an isomorphism, then the exponential comparison transformation (at `A`) is an isomorphism. -/ theorem expComparison_iso_of_frobeniusMorphism_iso (h : L ⊣ F) (A : C) [i : IsIso (frobeniusMorphism F h A)] : IsIso (expComparison F A).natTrans := by rw [← frobeniusMorphism_mate F h]; infer_instance open Limits in /-- If `F` is full and faithful, and has a left adjoint which preserves binary products, then it is cartesian closed. TODO: Show the converse, that if `F` is cartesian closed and its left adjoint preserves binary products, then it is full and faithful. -/ theorem cartesianClosedFunctorOfLeftAdjointPreservesBinaryProducts (h : L ⊣ F) [F.Full] [F.Faithful] [PreservesLimitsOfShape (Discrete WalkingPair) L] : CartesianClosedFunctor F where comparison_iso _ := expComparison_iso_of_frobeniusMorphism_iso F h _ end CategoryTheory
RegularSheaves.lean
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Filippo A. E. Nuccio, Riccardo Brasca -/ import Mathlib.CategoryTheory.EffectiveEpi.Preserves import Mathlib.CategoryTheory.Limits.Final.ParallelPair import Mathlib.CategoryTheory.Preadditive.Projective.Basic import Mathlib.CategoryTheory.Sites.Canonical import Mathlib.CategoryTheory.Sites.Coherent.Basic import Mathlib.CategoryTheory.Sites.EffectiveEpimorphic /-! # Sheaves for the regular topology This file characterises sheaves for the regular topology. ## Main results * `equalizerCondition_iff_isSheaf`: In a preregular category with pullbacks, the sheaves for the regular topology are precisely the presheaves satisfying an equaliser condition with respect to effective epimorphisms. * `isSheaf_of_projective`: In a preregular category in which every object is projective, every presheaf is a sheaf for the regular topology. -/ namespace CategoryTheory open Limits variable {C D E : Type*} [Category C] [Category D] [Category E] open Opposite Presieve Functor /-- A presieve is *regular* if it consists of a single effective epimorphism. -/ class Presieve.regular {X : C} (R : Presieve X) : Prop where /-- `R` consists of a single epimorphism. -/ single_epi : ∃ (Y : C) (f : Y ⟶ X), R = Presieve.ofArrows (fun (_ : Unit) ↦ Y) (fun (_ : Unit) ↦ f) ∧ EffectiveEpi f namespace regularTopology lemma equalizerCondition_w (P : Cᵒᵖ ⥤ D) {X B : C} {π : X ⟶ B} (c : PullbackCone π π) : P.map π.op ≫ P.map c.fst.op = P.map π.op ≫ P.map c.snd.op := by simp only [← Functor.map_comp, ← op_comp, c.condition] /-- A contravariant functor on `C` satisfies `SingleEqualizerCondition` with respect to a morphism `π` if it takes its kernel pair to an equalizer diagram. -/ def SingleEqualizerCondition (P : Cᵒᵖ ⥤ D) ⦃X B : C⦄ (π : X ⟶ B) : Prop := ∀ (c : PullbackCone π π) (_ : IsLimit c), Nonempty (IsLimit (Fork.ofι (P.map π.op) (equalizerCondition_w P c))) /-- A contravariant functor on `C` satisfies `EqualizerCondition` if it takes kernel pairs of effective epimorphisms to equalizer diagrams. -/ def EqualizerCondition (P : Cᵒᵖ ⥤ D) : Prop := ∀ ⦃X B : C⦄ (π : X ⟶ B) [EffectiveEpi π], SingleEqualizerCondition P π /-- The equalizer condition is preserved by natural isomorphism. -/ theorem equalizerCondition_of_natIso {P P' : Cᵒᵖ ⥤ D} (i : P ≅ P') (hP : EqualizerCondition P) : EqualizerCondition P' := fun X B π _ c hc ↦ ⟨Fork.isLimitOfIsos _ (hP π c hc).some _ (i.app _) (i.app _) (i.app _)⟩ /-- Precomposing with a pullback-preserving functor preserves the equalizer condition. -/ theorem equalizerCondition_precomp_of_preservesPullback (P : Cᵒᵖ ⥤ D) (F : E ⥤ C) [∀ {X B} (π : X ⟶ B) [EffectiveEpi π], PreservesLimit (cospan π π) F] [F.PreservesEffectiveEpis] (hP : EqualizerCondition P) : EqualizerCondition (F.op ⋙ P) := by intro X B π _ c hc have h : P.map (F.map π).op = (F.op ⋙ P).map π.op := by simp refine ⟨(IsLimit.equivIsoLimit (ForkOfι.ext ?_ _ h)) ?_⟩ · simp only [Functor.comp_map, op_map, Quiver.Hom.unop_op, ← map_comp, ← op_comp, c.condition] · refine (hP (F.map π) (PullbackCone.mk (F.map c.fst) (F.map c.snd) ?_) ?_).some · simp only [← map_comp, c.condition] · exact (isLimitMapConePullbackConeEquiv F c.condition) (isLimitOfPreserves F (hc.ofIsoLimit (PullbackCone.ext (Iso.refl _) (by simp) (by simp)))) /-- The canonical map to the explicit equalizer. -/ def MapToEqualizer (P : Cᵒᵖ ⥤ Type*) {W X B : C} (f : X ⟶ B) (g₁ g₂ : W ⟶ X) (w : g₁ ≫ f = g₂ ≫ f) : P.obj (op B) → { x : P.obj (op X) | P.map g₁.op x = P.map g₂.op x } := fun t ↦ ⟨P.map f.op t, by simp only [Set.mem_setOf_eq, ← FunctorToTypes.map_comp_apply, ← op_comp, w]⟩ theorem EqualizerCondition.bijective_mapToEqualizer_pullback (P : Cᵒᵖ ⥤ Type*) (hP : EqualizerCondition P) : ∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π], Function.Bijective (MapToEqualizer P π (pullback.fst π π) (pullback.snd π π) pullback.condition) := by intro X B π _ _ specialize hP π _ (pullbackIsPullback π π) rw [Types.type_equalizer_iff_unique] at hP rw [Function.bijective_iff_existsUnique] intro ⟨b, hb⟩ obtain ⟨a, ha₁, ha₂⟩ := hP b hb refine ⟨a, ?_, ?_⟩ · simpa [MapToEqualizer] using ha₁ · simpa [MapToEqualizer] using ha₂ theorem EqualizerCondition.mk (P : Cᵒᵖ ⥤ Type*) (hP : ∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π], Function.Bijective (MapToEqualizer P π (pullback.fst π π) (pullback.snd π π) pullback.condition)) : EqualizerCondition P := by intro X B π _ c hc have : HasPullback π π := ⟨c, hc⟩ specialize hP X B π rw [Types.type_equalizer_iff_unique] rw [Function.bijective_iff_existsUnique] at hP intro b hb have h₁ : ((pullbackIsPullback π π).conePointUniqueUpToIso hc).hom ≫ c.fst = pullback.fst π π := by simp have hb' : P.map (pullback.fst π π).op b = P.map (pullback.snd _ _).op b := by rw [← h₁, op_comp, FunctorToTypes.map_comp_apply, hb] simp [← FunctorToTypes.map_comp_apply, ← op_comp] obtain ⟨a, ha₁, ha₂⟩ := hP ⟨b, hb'⟩ refine ⟨a, ?_, ?_⟩ · simpa [MapToEqualizer] using ha₁ · simpa [MapToEqualizer] using ha₂ lemma equalizerCondition_w' (P : Cᵒᵖ ⥤ Type*) {X B : C} (π : X ⟶ B) [HasPullback π π] : P.map π.op ≫ P.map (pullback.fst π π).op = P.map π.op ≫ P.map (pullback.snd π π).op := by simp only [← Functor.map_comp, ← op_comp, pullback.condition] lemma mapToEqualizer_eq_comp (P : Cᵒᵖ ⥤ Type*) {X B : C} (π : X ⟶ B) [HasPullback π π] : MapToEqualizer P π (pullback.fst π π) (pullback.snd π π) pullback.condition = equalizer.lift (P.map π.op) (equalizerCondition_w' P π) ≫ (Types.equalizerIso _ _).hom := by rw [← Iso.comp_inv_eq (α := Types.equalizerIso _ _)] apply equalizer.hom_ext aesop /-- An alternative phrasing of the explicit equalizer condition, using more categorical language. -/ theorem equalizerCondition_iff_isIso_lift (P : Cᵒᵖ ⥤ Type*) : EqualizerCondition P ↔ ∀ (X B : C) (π : X ⟶ B) [EffectiveEpi π] [HasPullback π π], IsIso (equalizer.lift (P.map π.op) (equalizerCondition_w' P π)) := by constructor · intro hP X B π _ _ have h := hP.bijective_mapToEqualizer_pullback _ X B π rw [← isIso_iff_bijective, mapToEqualizer_eq_comp] at h exact IsIso.of_isIso_comp_right (equalizer.lift (P.map π.op) (equalizerCondition_w' P π)) (Types.equalizerIso _ _).hom · intro hP apply EqualizerCondition.mk intro X B π _ _ rw [mapToEqualizer_eq_comp, ← isIso_iff_bijective] infer_instance /-- `P` satisfies the equalizer condition iff its precomposition by an equivalence does. -/ theorem equalizerCondition_iff_of_equivalence (P : Cᵒᵖ ⥤ D) (e : C ≌ E) : EqualizerCondition P ↔ EqualizerCondition (e.op.inverse ⋙ P) := ⟨fun h ↦ equalizerCondition_precomp_of_preservesPullback P e.inverse h, fun h ↦ equalizerCondition_of_natIso (e.op.funInvIdAssoc P) (equalizerCondition_precomp_of_preservesPullback (e.op.inverse ⋙ P) e.functor h)⟩ open WalkingParallelPair WalkingParallelPairHom in theorem parallelPair_pullback_initial {X B : C} (π : X ⟶ B) (c : PullbackCone π π) (hc : IsLimit c) : (parallelPair (C := (Sieve.ofArrows (fun (_ : Unit) => X) (fun _ => π)).arrows.categoryᵒᵖ) (Y := op ((Presieve.categoryMk _ (c.fst ≫ π) ⟨_, c.fst, π, ofArrows.mk (), rfl⟩))) (X := op ((Presieve.categoryMk _ π (Sieve.ofArrows_mk _ _ Unit.unit)))) (Quiver.Hom.op (Over.homMk c.fst)) (Quiver.Hom.op (Over.homMk c.snd c.condition.symm))).Initial := by apply Limits.parallelPair_initial_mk · intro ⟨Z⟩ obtain ⟨_, f, g, ⟨⟩, hh⟩ := Z.property let X' : (Presieve.ofArrows (fun () ↦ X) (fun () ↦ π)).category := Presieve.categoryMk _ π (ofArrows.mk ()) let f' : Z.obj.left ⟶ X'.obj.left := f exact ⟨(Over.homMk f').op⟩ · intro ⟨Z⟩ ⟨i⟩ ⟨j⟩ let ij := PullbackCone.IsLimit.lift hc i.left j.left (by erw [i.w, j.w]; rfl) refine ⟨Quiver.Hom.op (Over.homMk ij (by simpa [ij] using i.w)), ?_, ?_⟩ all_goals congr all_goals exact Comma.hom_ext _ _ (by erw [Over.comp_left]; simp [ij]) rfl /-- Given a limiting pullback cone, the fork in `SingleEqualizerCondition` is limiting iff the diagram in `Presheaf.isSheaf_iff_isLimit_coverage` is limiting. -/ noncomputable def isLimit_forkOfι_equiv (P : Cᵒᵖ ⥤ D) {X B : C} (π : X ⟶ B) (c : PullbackCone π π) (hc : IsLimit c) : IsLimit (Fork.ofι (P.map π.op) (equalizerCondition_w P c)) ≃ IsLimit (P.mapCone (Sieve.ofArrows (fun (_ : Unit) ↦ X) fun _ ↦ π).arrows.cocone.op) := by let S := (Sieve.ofArrows (fun (_ : Unit) => X) (fun _ => π)).arrows let X' := S.categoryMk π ⟨_, 𝟙 _, π, ofArrows.mk (), Category.id_comp _⟩ let P' := S.categoryMk (c.fst ≫ π) ⟨_, c.fst, π, ofArrows.mk (), rfl⟩ let fst : P' ⟶ X' := Over.homMk c.fst let snd : P' ⟶ X' := Over.homMk c.snd c.condition.symm let F : S.categoryᵒᵖ ⥤ D := S.diagram.op ⋙ P let G := parallelPair (P.map c.fst.op) (P.map c.snd.op) let H := parallelPair fst.op snd.op have : H.Initial := parallelPair_pullback_initial π c hc let i : H ⋙ F ≅ G := parallelPair.ext (Iso.refl _) (Iso.refl _) (by aesop) (by aesop) refine (IsLimit.equivOfNatIsoOfIso i.symm _ _ ?_).trans (Functor.Initial.isLimitWhiskerEquiv H _) refine Cones.ext (Iso.refl _) ?_ rintro ⟨_ | _⟩ all_goals aesop lemma equalizerConditionMap_iff_nonempty_isLimit (P : Cᵒᵖ ⥤ D) ⦃X B : C⦄ (π : X ⟶ B) [HasPullback π π] : SingleEqualizerCondition P π ↔ Nonempty (IsLimit (P.mapCone (Sieve.ofArrows (fun (_ : Unit) => X) (fun _ => π)).arrows.cocone.op)) := by constructor · intro h exact ⟨isLimit_forkOfι_equiv _ _ _ (pullbackIsPullback π π) (h _ (pullbackIsPullback π π)).some⟩ · intro ⟨h⟩ exact fun c hc ↦ ⟨(isLimit_forkOfι_equiv _ _ _ hc).symm h⟩ lemma equalizerCondition_iff_isSheaf (F : Cᵒᵖ ⥤ D) [Preregular C] [∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f] : EqualizerCondition F ↔ Presheaf.IsSheaf (regularTopology C) F := by dsimp [regularTopology] rw [Presheaf.isSheaf_iff_isLimit_coverage] constructor · rintro hF X _ ⟨Y, f, rfl, _⟩ exact (equalizerConditionMap_iff_nonempty_isLimit F f).1 (hF f) · intro hF Y X f _ exact (equalizerConditionMap_iff_nonempty_isLimit F f).2 (hF _ ⟨_, f, rfl, inferInstance⟩) lemma isSheafFor_regular_of_projective {X : C} (S : Presieve X) [S.regular] [Projective X] (F : Cᵒᵖ ⥤ Type*) : S.IsSheafFor F := by obtain ⟨Y, f, rfl, hf⟩ := Presieve.regular.single_epi (R := S) rw [isSheafFor_arrows_iff] refine fun x hx ↦ ⟨F.map (Projective.factorThru (𝟙 _) f).op <| x (), fun _ ↦ ?_, fun y h ↦ ?_⟩ · simpa using (hx () () Y (𝟙 Y) (f ≫ (Projective.factorThru (𝟙 _) f)) (by simp)).symm · simp only [← h (), ← FunctorToTypes.map_comp_apply, ← op_comp, Projective.factorThru_comp, op_id, FunctorToTypes.map_id_apply] /-- Every presheaf is a sheaf for the regular topology if every object of `C` is projective. -/ theorem isSheaf_of_projective (F : Cᵒᵖ ⥤ D) [Preregular C] [∀ (X : C), Projective X] : Presheaf.IsSheaf (regularTopology C) F := fun _ ↦ (isSheaf_coverage _ _).mpr fun S ⟨_, h⟩ ↦ have : S.regular := ⟨_, h⟩ isSheafFor_regular_of_projective _ _ /-- Every Yoneda-presheaf is a sheaf for the regular topology. -/ lemma isSheaf_yoneda_obj [Preregular C] (W : C) : Presieve.IsSheaf (regularTopology C) (yoneda.obj W) := by rw [regularTopology, isSheaf_coverage] intro X S ⟨_, hS⟩ have : S.regular := ⟨_, hS⟩ obtain ⟨Y, f, rfl, hf⟩ := Presieve.regular.single_epi (R := S) have h_colim := isColimitOfEffectiveEpiStruct f hf.effectiveEpi.some rw [← Sieve.generateSingleton_eq, ← Presieve.ofArrows_pUnit] at h_colim intro x hx let x_ext := Presieve.FamilyOfElements.sieveExtend x have hx_ext := Presieve.FamilyOfElements.Compatible.sieveExtend hx let S := Sieve.generate (Presieve.ofArrows (fun () ↦ Y) (fun () ↦ f)) obtain ⟨t, t_amalg, t_uniq⟩ := (Sieve.forallYonedaIsSheaf_iff_colimit S).mpr ⟨h_colim⟩ W x_ext hx_ext refine ⟨t, ?_, ?_⟩ · convert Presieve.isAmalgamation_restrict (Sieve.le_generate (Presieve.ofArrows (fun () ↦ Y) (fun () ↦ f))) _ _ t_amalg exact (Presieve.restrict_extend hx).symm · exact fun y hy ↦ t_uniq y <| Presieve.isAmalgamation_sieveExtend x y hy /-- The regular topology on any preregular category is subcanonical. -/ instance subcanonical [Preregular C] : (regularTopology C).Subcanonical := GrothendieckTopology.Subcanonical.of_isSheaf_yoneda_obj _ isSheaf_yoneda_obj end regularTopology end CategoryTheory
MulOpposite.lean
/- Copyright (c) 2025 Monica Omar. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Monica Omar -/ import Mathlib.LinearAlgebra.FiniteDimensional.Defs /-! # Basis of an opposite space This file defines the basis of an opposite space and shows that the opposite space is finite-dimensional and free when the original space is. -/ open Module MulOpposite variable {R H : Type*} namespace Module.Basis variable {ι : Type*} [Semiring R] [AddCommMonoid H] [Module R H] /-- The multiplicative opposite of a basis: `b.mulOpposite i ↦ op (b i)`. -/ noncomputable def mulOpposite (b : Basis ι R H) : Basis ι R Hᵐᵒᵖ := b.map (opLinearEquiv R) @[simp] theorem mulOpposite_apply (b : Basis ι R H) (i : ι) : b.mulOpposite i = op (b i) := rfl theorem mulOpposite_repr_eq (b : Basis ι R H) : b.mulOpposite.repr = (opLinearEquiv R).symm.trans b.repr := rfl @[simp] theorem repr_unop_eq_mulOpposite_repr (b : Basis ι R H) (x : Hᵐᵒᵖ) : b.repr (unop x) = b.mulOpposite.repr x := rfl @[simp] theorem mulOpposite_repr_op (b : Basis ι R H) (x : H) : b.mulOpposite.repr (op x) = b.repr x := rfl end Module.Basis namespace MulOpposite instance [DivisionRing R] [AddCommGroup H] [Module R H] [FiniteDimensional R H] : FiniteDimensional R Hᵐᵒᵖ := FiniteDimensional.of_finite_basis (Basis.ofVectorSpace R H).mulOpposite (Basis.ofVectorSpaceIndex R H).toFinite instance [Semiring R] [AddCommMonoid H] [Module R H] [Module.Free R H] : Module.Free R Hᵐᵒᵖ := let ⟨b⟩ := Module.Free.exists_basis (R := R) (M := H) Module.Free.of_basis b.2.mulOpposite theorem rank [Semiring R] [StrongRankCondition R] [AddCommMonoid H] [Module R H] [Module.Free R H] : Module.rank R Hᵐᵒᵖ = Module.rank R H := LinearEquiv.nonempty_equiv_iff_rank_eq.mp ⟨(opLinearEquiv R).symm⟩ theorem finrank [DivisionRing R] [AddCommGroup H] [Module R H] : Module.finrank R Hᵐᵒᵖ = Module.finrank R H := by let b := Basis.ofVectorSpace R H rw [Module.finrank_eq_nat_card_basis b, Module.finrank_eq_nat_card_basis b.mulOpposite] end MulOpposite
Prod.lean
/- Copyright (c) 2022 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Yury Kudryashov, Kevin H. Wilson, Heather Macbeth -/ import Mathlib.Order.Filter.Tendsto /-! # Product and coproduct filters In this file we define `Filter.prod f g` (notation: `f ×ˢ g`) and `Filter.coprod f g`. The product of two filters is the largest filter `l` such that `Filter.Tendsto Prod.fst l f` and `Filter.Tendsto Prod.snd l g`. ## Implementation details The product filter cannot be defined using the monad structure on filters. For example: ```lean F := do {x ← seq, y ← top, return (x, y)} G := do {y ← top, x ← seq, return (x, y)} ``` hence: ```lean s ∈ F ↔ ∃ n, [n..∞] × univ ⊆ s s ∈ G ↔ ∀ i:ℕ, ∃ n, [n..∞] × {i} ⊆ s ``` Now `⋃ i, [i..∞] × {i}` is in `G` but not in `F`. As product filter we want to have `F` as result. ## Notations * `f ×ˢ g` : `Filter.prod f g`, localized in `Filter`. -/ open Set open Filter namespace Filter variable {α β γ δ : Type*} {ι : Sort*} section Prod variable {s : Set α} {t : Set β} {f : Filter α} {g : Filter β} theorem prod_mem_prod (hs : s ∈ f) (ht : t ∈ g) : s ×ˢ t ∈ f ×ˢ g := inter_mem_inf (preimage_mem_comap hs) (preimage_mem_comap ht) theorem mem_prod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} : s ∈ f ×ˢ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ×ˢ t₂ ⊆ s := by constructor · rintro ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, rfl⟩ exact ⟨s₁, hs₁, s₂, hs₂, fun p ⟨h, h'⟩ => ⟨hts₁ h, hts₂ h'⟩⟩ · rintro ⟨t₁, ht₁, t₂, ht₂, h⟩ exact mem_inf_of_inter (preimage_mem_comap ht₁) (preimage_mem_comap ht₂) h @[simp] theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint] @[simp] theorem prod_mem_prod_iff [f.NeBot] [g.NeBot] : s ×ˢ t ∈ f ×ˢ g ↔ s ∈ f ∧ t ∈ g := ⟨fun h => let ⟨_s', hs', _t', ht', H⟩ := mem_prod_iff.1 h (prod_subset_prod_iff.1 H).elim (fun ⟨hs's, ht't⟩ => ⟨mem_of_superset hs' hs's, mem_of_superset ht' ht't⟩) fun h => h.elim (fun hs'e => absurd hs'e (nonempty_of_mem hs').ne_empty) fun ht'e => absurd ht'e (nonempty_of_mem ht').ne_empty, fun h => prod_mem_prod h.1 h.2⟩ theorem mem_prod_principal {s : Set (α × β)} : s ∈ f ×ˢ 𝓟 t ↔ { a | ∀ b ∈ t, (a, b) ∈ s } ∈ f := by rw [← @exists_mem_subset_iff _ f, mem_prod_iff] refine exists_congr fun u => Iff.rfl.and ⟨?_, fun h => ⟨t, mem_principal_self t, ?_⟩⟩ · rintro ⟨v, v_in, hv⟩ a a_in b b_in exact hv (mk_mem_prod a_in <| v_in b_in) · rintro ⟨x, y⟩ ⟨hx, hy⟩ exact h hx y hy theorem mem_prod_top {s : Set (α × β)} : s ∈ f ×ˢ (⊤ : Filter β) ↔ { a | ∀ b, (a, b) ∈ s } ∈ f := by rw [← principal_univ, mem_prod_principal] simp only [mem_univ, forall_true_left] theorem eventually_prod_principal_iff {p : α × β → Prop} {s : Set β} : (∀ᶠ x : α × β in f ×ˢ 𝓟 s, p x) ↔ ∀ᶠ x : α in f, ∀ y : β, y ∈ s → p (x, y) := by rw [eventually_iff, eventually_iff, mem_prod_principal] simp only [mem_setOf_eq] theorem comap_prod (f : α → β × γ) (b : Filter β) (c : Filter γ) : comap f (b ×ˢ c) = comap (Prod.fst ∘ f) b ⊓ comap (Prod.snd ∘ f) c := by rw [prod_eq_inf, comap_inf, Filter.comap_comap, Filter.comap_comap] theorem comap_prodMap_prod (f : α → β) (g : γ → δ) (lb : Filter β) (ld : Filter δ) : comap (Prod.map f g) (lb ×ˢ ld) = comap f lb ×ˢ comap g ld := by simp [prod_eq_inf, comap_comap, Function.comp_def] theorem prod_top : f ×ˢ (⊤ : Filter β) = f.comap Prod.fst := by rw [prod_eq_inf, comap_top, inf_top_eq] theorem top_prod : (⊤ : Filter α) ×ˢ g = g.comap Prod.snd := by rw [prod_eq_inf, comap_top, top_inf_eq] theorem sup_prod (f₁ f₂ : Filter α) (g : Filter β) : (f₁ ⊔ f₂) ×ˢ g = (f₁ ×ˢ g) ⊔ (f₂ ×ˢ g) := by simp only [prod_eq_inf, comap_sup, inf_sup_right] theorem prod_sup (f : Filter α) (g₁ g₂ : Filter β) : f ×ˢ (g₁ ⊔ g₂) = (f ×ˢ g₁) ⊔ (f ×ˢ g₂) := by simp only [prod_eq_inf, comap_sup, inf_sup_left] theorem eventually_prod_iff {p : α × β → Prop} : (∀ᶠ x in f ×ˢ g, p x) ↔ ∃ pa : α → Prop, (∀ᶠ x in f, pa x) ∧ ∃ pb : β → Prop, (∀ᶠ y in g, pb y) ∧ ∀ {x}, pa x → ∀ {y}, pb y → p (x, y) := by simpa only [Set.prod_subset_iff] using @mem_prod_iff α β p f g theorem tendsto_fst : Tendsto Prod.fst (f ×ˢ g) f := tendsto_inf_left tendsto_comap theorem tendsto_snd : Tendsto Prod.snd (f ×ˢ g) g := tendsto_inf_right tendsto_comap /-- If a function tends to a product `g ×ˢ h` of filters, then its first component tends to `g`. See also `Filter.Tendsto.fst_nhds` for the special case of converging to a point in a product of two topological spaces. -/ theorem Tendsto.fst {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) : Tendsto (fun a ↦ (m a).1) f g := tendsto_fst.comp H /-- If a function tends to a product `g ×ˢ h` of filters, then its second component tends to `h`. See also `Filter.Tendsto.snd_nhds` for the special case of converging to a point in a product of two topological spaces. -/ theorem Tendsto.snd {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) : Tendsto (fun a ↦ (m a).2) f h := tendsto_snd.comp H theorem Tendsto.prodMk {h : Filter γ} {m₁ : α → β} {m₂ : α → γ} (h₁ : Tendsto m₁ f g) (h₂ : Tendsto m₂ f h) : Tendsto (fun x => (m₁ x, m₂ x)) f (g ×ˢ h) := tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ @[deprecated (since := "2025-03-10")] alias Tendsto.prod_mk := Tendsto.prodMk theorem tendsto_prod_swap : Tendsto (Prod.swap : α × β → β × α) (f ×ˢ g) (g ×ˢ f) := tendsto_snd.prodMk tendsto_fst theorem Eventually.prod_inl {la : Filter α} {p : α → Prop} (h : ∀ᶠ x in la, p x) (lb : Filter β) : ∀ᶠ x in la ×ˢ lb, p (x : α × β).1 := tendsto_fst.eventually h theorem Eventually.prod_inr {lb : Filter β} {p : β → Prop} (h : ∀ᶠ x in lb, p x) (la : Filter α) : ∀ᶠ x in la ×ˢ lb, p (x : α × β).2 := tendsto_snd.eventually h theorem Eventually.prod_mk {la : Filter α} {pa : α → Prop} (ha : ∀ᶠ x in la, pa x) {lb : Filter β} {pb : β → Prop} (hb : ∀ᶠ y in lb, pb y) : ∀ᶠ p in la ×ˢ lb, pa (p : α × β).1 ∧ pb p.2 := (ha.prod_inl lb).and (hb.prod_inr la) theorem EventuallyEq.prodMap {δ} {la : Filter α} {fa ga : α → γ} (ha : fa =ᶠ[la] ga) {lb : Filter β} {fb gb : β → δ} (hb : fb =ᶠ[lb] gb) : Prod.map fa fb =ᶠ[la ×ˢ lb] Prod.map ga gb := (Eventually.prod_mk ha hb).mono fun _ h => Prod.ext h.1 h.2 @[deprecated (since := "2025-03-10")] alias EventuallyEq.prod_map := EventuallyEq.prodMap theorem EventuallyLE.prodMap {δ} [LE γ] [LE δ] {la : Filter α} {fa ga : α → γ} (ha : fa ≤ᶠ[la] ga) {lb : Filter β} {fb gb : β → δ} (hb : fb ≤ᶠ[lb] gb) : Prod.map fa fb ≤ᶠ[la ×ˢ lb] Prod.map ga gb := Eventually.prod_mk ha hb @[deprecated (since := "2025-03-10")] alias EventuallyLE.prod_map := EventuallyLE.prodMap theorem Eventually.curry {la : Filter α} {lb : Filter β} {p : α × β → Prop} (h : ∀ᶠ x in la ×ˢ lb, p x) : ∀ᶠ x in la, ∀ᶠ y in lb, p (x, y) := by rcases eventually_prod_iff.1 h with ⟨pa, ha, pb, hb, h⟩ exact ha.mono fun a ha => hb.mono fun b hb => h ha hb protected lemma Frequently.uncurry {la : Filter α} {lb : Filter β} {p : α → β → Prop} (h : ∃ᶠ x in la, ∃ᶠ y in lb, p x y) : ∃ᶠ xy in la ×ˢ lb, p xy.1 xy.2 := mt (fun h ↦ by simpa only [not_frequently] using h.curry) h lemma Frequently.of_curry {la : Filter α} {lb : Filter β} {p : α × β → Prop} (h : ∃ᶠ x in la, ∃ᶠ y in lb, p (x, y)) : ∃ᶠ xy in la ×ˢ lb, p xy := h.uncurry /-- A fact that is eventually true about all pairs `l ×ˢ l` is eventually true about all diagonal pairs `(i, i)` -/ theorem Eventually.diag_of_prod {p : α × α → Prop} (h : ∀ᶠ i in f ×ˢ f, p i) : ∀ᶠ i in f, p (i, i) := by obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h apply (ht.and hs).mono fun x hx => hst hx.1 hx.2 theorem Eventually.diag_of_prod_left {f : Filter α} {g : Filter γ} {p : (α × α) × γ → Prop} : (∀ᶠ x in (f ×ˢ f) ×ˢ g, p x) → ∀ᶠ x : α × γ in f ×ˢ g, p ((x.1, x.1), x.2) := by intro h obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h exact (ht.diag_of_prod.prod_mk hs).mono fun x hx => by simp only [hst hx.1 hx.2] theorem Eventually.diag_of_prod_right {f : Filter α} {g : Filter γ} {p : α × γ × γ → Prop} : (∀ᶠ x in f ×ˢ (g ×ˢ g), p x) → ∀ᶠ x : α × γ in f ×ˢ g, p (x.1, x.2, x.2) := by intro h obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h exact (ht.prod_mk hs.diag_of_prod).mono fun x hx => by simp only [hst hx.1 hx.2] theorem tendsto_diag : Tendsto (fun i => (i, i)) f (f ×ˢ f) := tendsto_iff_eventually.mpr fun _ hpr => hpr.diag_of_prod theorem prod_iInf_left [Nonempty ι] {f : ι → Filter α} {g : Filter β} : (⨅ i, f i) ×ˢ g = ⨅ i, f i ×ˢ g := by simp only [prod_eq_inf, comap_iInf, iInf_inf] theorem prod_iInf_right [Nonempty ι] {f : Filter α} {g : ι → Filter β} : (f ×ˢ ⨅ i, g i) = ⨅ i, f ×ˢ g i := by simp only [prod_eq_inf, comap_iInf, inf_iInf] @[mono, gcongr] theorem prod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ := inf_le_inf (comap_mono hf) (comap_mono hg) theorem prod_mono_left (g : Filter β) {f₁ f₂ : Filter α} (hf : f₁ ≤ f₂) : f₁ ×ˢ g ≤ f₂ ×ˢ g := Filter.prod_mono hf rfl.le theorem prod_mono_right (f : Filter α) {g₁ g₂ : Filter β} (hf : g₁ ≤ g₂) : f ×ˢ g₁ ≤ f ×ˢ g₂ := Filter.prod_mono rfl.le hf theorem prod_comap_comap_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} : comap m₁ f₁ ×ˢ comap m₂ f₂ = comap (fun p : β₁ × β₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := by simp only [prod_eq_inf, comap_comap, comap_inf, Function.comp_def] theorem prod_comm' : f ×ˢ g = comap Prod.swap (g ×ˢ f) := by simp only [prod_eq_inf, comap_comap, Function.comp_def, inf_comm, Prod.swap, comap_inf] theorem prod_comm : f ×ˢ g = map (fun p : β × α => (p.2, p.1)) (g ×ˢ f) := by rw [prod_comm', ← map_swap_eq_comap_swap] rfl theorem mem_prod_iff_left {s : Set (α × β)} : s ∈ f ×ˢ g ↔ ∃ t ∈ f, ∀ᶠ y in g, ∀ x ∈ t, (x, y) ∈ s := by simp only [mem_prod_iff, prod_subset_iff] refine exists_congr fun _ => Iff.rfl.and <| Iff.trans ?_ exists_mem_subset_iff exact exists_congr fun _ => Iff.rfl.and forall₂_swap theorem mem_prod_iff_right {s : Set (α × β)} : s ∈ f ×ˢ g ↔ ∃ t ∈ g, ∀ᶠ x in f, ∀ y ∈ t, (x, y) ∈ s := by rw [prod_comm, mem_map, mem_prod_iff_left]; rfl @[simp] theorem map_fst_prod (f : Filter α) (g : Filter β) [NeBot g] : map Prod.fst (f ×ˢ g) = f := by ext s simp only [mem_map, mem_prod_iff_left, mem_preimage, eventually_const, ← subset_def, exists_mem_subset_iff] @[simp] theorem map_snd_prod (f : Filter α) (g : Filter β) [NeBot f] : map Prod.snd (f ×ˢ g) = g := by rw [prod_comm, map_map]; apply map_fst_prod @[simp] theorem prod_le_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] : f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ ↔ f₁ ≤ f₂ ∧ g₁ ≤ g₂ := ⟨fun h => ⟨map_fst_prod f₁ g₁ ▸ tendsto_fst.mono_left h, map_snd_prod f₁ g₁ ▸ tendsto_snd.mono_left h⟩, fun h => prod_mono h.1 h.2⟩ @[simp] theorem prod_inj {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] : f₁ ×ˢ g₁ = f₂ ×ˢ g₂ ↔ f₁ = f₂ ∧ g₁ = g₂ := by refine ⟨fun h => ?_, fun h => h.1 ▸ h.2 ▸ rfl⟩ have hle : f₁ ≤ f₂ ∧ g₁ ≤ g₂ := prod_le_prod.1 h.le haveI := neBot_of_le hle.1; haveI := neBot_of_le hle.2 exact ⟨hle.1.antisymm <| (prod_le_prod.1 h.ge).1, hle.2.antisymm <| (prod_le_prod.1 h.ge).2⟩ theorem eventually_swap_iff {p : α × β → Prop} : (∀ᶠ x : α × β in f ×ˢ g, p x) ↔ ∀ᶠ y : β × α in g ×ˢ f, p y.swap := by rw [prod_comm]; rfl theorem prod_assoc (f : Filter α) (g : Filter β) (h : Filter γ) : map (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) = f ×ˢ (g ×ˢ h) := by simp_rw [← comap_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc, Function.comp_def, Equiv.prodAssoc_symm_apply] theorem prod_assoc_symm (f : Filter α) (g : Filter β) (h : Filter γ) : map (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) = (f ×ˢ g) ×ˢ h := by simp_rw [map_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc, Function.comp_def, Equiv.prodAssoc_apply] theorem tendsto_prodAssoc {h : Filter γ} : Tendsto (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) (f ×ˢ (g ×ˢ h)) := (prod_assoc f g h).le theorem tendsto_prodAssoc_symm {h : Filter γ} : Tendsto (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) ((f ×ˢ g) ×ˢ h) := (prod_assoc_symm f g h).le /-- A useful lemma when dealing with uniformities. -/ theorem map_swap4_prod {h : Filter γ} {k : Filter δ} : map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) = (f ×ˢ h) ×ˢ (g ×ˢ k) := by simp_rw [map_swap4_eq_comap, prod_eq_inf, comap_inf, comap_comap]; ac_rfl theorem tendsto_swap4_prod {h : Filter γ} {k : Filter δ} : Tendsto (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) ((f ×ˢ h) ×ˢ (g ×ˢ k)) := map_swap4_prod.le theorem prod_map_map_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} : map m₁ f₁ ×ˢ map m₂ f₂ = map (fun p : α₁ × α₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := le_antisymm (fun s hs => let ⟨s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs mem_of_superset (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) <| by rwa [prod_image_image_eq, image_subset_iff]) ((tendsto_map.comp tendsto_fst).prodMk (tendsto_map.comp tendsto_snd)) theorem prod_map_map_eq' {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*} (f : α₁ → α₂) (g : β₁ → β₂) (F : Filter α₁) (G : Filter β₁) : map f F ×ˢ map g G = map (Prod.map f g) (F ×ˢ G) := prod_map_map_eq theorem prod_map_left (f : α → β) (F : Filter α) (G : Filter γ) : map f F ×ˢ G = map (Prod.map f id) (F ×ˢ G) := by rw [← prod_map_map_eq', map_id] theorem prod_map_right (f : β → γ) (F : Filter α) (G : Filter β) : F ×ˢ map f G = map (Prod.map id f) (F ×ˢ G) := by rw [← prod_map_map_eq', map_id] theorem le_prod_map_fst_snd {f : Filter (α × β)} : f ≤ map Prod.fst f ×ˢ map Prod.snd f := le_inf le_comap_map le_comap_map theorem Tendsto.prodMap {δ : Type*} {f : α → γ} {g : β → δ} {a : Filter α} {b : Filter β} {c : Filter γ} {d : Filter δ} (hf : Tendsto f a c) (hg : Tendsto g b d) : Tendsto (Prod.map f g) (a ×ˢ b) (c ×ˢ d) := by rw [Tendsto, Prod.map_def, ← prod_map_map_eq] exact Filter.prod_mono hf hg @[deprecated (since := "2025-03-10")] alias Tendsto.prod_map := Tendsto.prodMap protected theorem map_prod (m : α × β → γ) (f : Filter α) (g : Filter β) : map m (f ×ˢ g) = (f.map fun a b => m (a, b)).seq g := by simp only [Filter.ext_iff, mem_map, mem_prod_iff, mem_map_seq_iff, exists_and_left] intro s constructor · exact fun ⟨t, ht, s, hs, h⟩ => ⟨s, hs, t, ht, fun x hx y hy => @h ⟨x, y⟩ ⟨hx, hy⟩⟩ · exact fun ⟨s, hs, t, ht, h⟩ => ⟨t, ht, s, hs, fun ⟨x, y⟩ ⟨hx, hy⟩ => h x hx y hy⟩ theorem prod_eq : f ×ˢ g = (f.map Prod.mk).seq g := f.map_prod id g theorem prod_inf_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} : (f₁ ×ˢ g₁) ⊓ (f₂ ×ˢ g₂) = (f₁ ⊓ f₂) ×ˢ (g₁ ⊓ g₂) := by simp only [prod_eq_inf, comap_inf, inf_comm, inf_assoc, inf_left_comm] theorem inf_prod {f₁ f₂ : Filter α} : (f₁ ⊓ f₂) ×ˢ g = (f₁ ×ˢ g) ⊓ (f₂ ×ˢ g) := by rw [prod_inf_prod, inf_idem] theorem prod_inf {g₁ g₂ : Filter β} : f ×ˢ (g₁ ⊓ g₂) = (f ×ˢ g₁) ⊓ (f ×ˢ g₂) := by rw [prod_inf_prod, inf_idem] @[simp] theorem prod_principal_principal {s : Set α} {t : Set β} : 𝓟 s ×ˢ 𝓟 t = 𝓟 (s ×ˢ t) := by simp only [prod_eq_inf, comap_principal, principal_eq_iff_eq, comap_principal, inf_principal]; rfl @[simp] theorem pure_prod {a : α} {f : Filter β} : pure a ×ˢ f = map (Prod.mk a) f := by rw [prod_eq, map_pure, pure_seq_eq_map] theorem map_pure_prod (f : α → β → γ) (a : α) (B : Filter β) : map (Function.uncurry f) (pure a ×ˢ B) = map (f a) B := by rw [Filter.pure_prod]; rfl @[simp] theorem prod_pure {b : β} : f ×ˢ pure b = map (fun a => (a, b)) f := by rw [prod_eq, seq_pure, map_map]; rfl theorem prod_pure_pure {a : α} {b : β} : (pure a : Filter α) ×ˢ (pure b : Filter β) = pure (a, b) := by simp @[simp] theorem prod_eq_bot : f ×ˢ g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := by simp_rw [← empty_mem_iff_bot, mem_prod_iff, subset_empty_iff, prod_eq_empty_iff, ← exists_prop, Subtype.exists', exists_or, exists_const, Subtype.exists, exists_prop, exists_eq_right] @[simp] theorem prod_bot : f ×ˢ (⊥ : Filter β) = ⊥ := prod_eq_bot.2 <| Or.inr rfl @[simp] theorem bot_prod : (⊥ : Filter α) ×ˢ g = ⊥ := prod_eq_bot.2 <| Or.inl rfl theorem prod_neBot : NeBot (f ×ˢ g) ↔ NeBot f ∧ NeBot g := by simp only [neBot_iff, Ne, prod_eq_bot, not_or] protected theorem NeBot.prod (hf : NeBot f) (hg : NeBot g) : NeBot (f ×ˢ g) := prod_neBot.2 ⟨hf, hg⟩ instance prod.instNeBot [hf : NeBot f] [hg : NeBot g] : NeBot (f ×ˢ g) := hf.prod hg @[simp] lemma disjoint_prod {f' : Filter α} {g' : Filter β} : Disjoint (f ×ˢ g) (f' ×ˢ g') ↔ Disjoint f f' ∨ Disjoint g g' := by simp only [disjoint_iff, prod_inf_prod, prod_eq_bot] /-- `p ∧ q` occurs frequently along the product of two filters iff both `p` and `q` occur frequently along the corresponding filters. -/ theorem frequently_prod_and {p : α → Prop} {q : β → Prop} : (∃ᶠ x in f ×ˢ g, p x.1 ∧ q x.2) ↔ (∃ᶠ a in f, p a) ∧ ∃ᶠ b in g, q b := by simp only [frequently_iff_neBot, ← prod_neBot, ← prod_inf_prod, prod_principal_principal] rfl theorem tendsto_prod_iff {f : α × β → γ} {x : Filter α} {y : Filter β} {z : Filter γ} : Tendsto f (x ×ˢ y) z ↔ ∀ W ∈ z, ∃ U ∈ x, ∃ V ∈ y, ∀ x y, x ∈ U → y ∈ V → f (x, y) ∈ W := by simp only [tendsto_def, mem_prod_iff, prod_sub_preimage_iff] theorem tendsto_prod_iff' {g' : Filter γ} {s : α → β × γ} : Tendsto s f (g ×ˢ g') ↔ Tendsto (fun n => (s n).1) f g ∧ Tendsto (fun n => (s n).2) f g' := by simp only [prod_eq_inf, tendsto_inf, tendsto_comap_iff, Function.comp_def] theorem le_prod {f : Filter (α × β)} {g : Filter α} {g' : Filter β} : (f ≤ g ×ˢ g') ↔ Tendsto Prod.fst f g ∧ Tendsto Prod.snd f g' := tendsto_prod_iff' end Prod /-! ### Coproducts of filters -/ section Coprod variable {f : Filter α} {g : Filter β} theorem coprod_eq_prod_top_sup_top_prod (f : Filter α) (g : Filter β) : Filter.coprod f g = f ×ˢ ⊤ ⊔ ⊤ ×ˢ g := by rw [prod_top, top_prod] rfl theorem mem_coprod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} : s ∈ f.coprod g ↔ (∃ t₁ ∈ f, Prod.fst ⁻¹' t₁ ⊆ s) ∧ ∃ t₂ ∈ g, Prod.snd ⁻¹' t₂ ⊆ s := by simp [Filter.coprod] @[simp] theorem bot_coprod (l : Filter β) : (⊥ : Filter α).coprod l = comap Prod.snd l := by simp [Filter.coprod] @[simp] theorem coprod_bot (l : Filter α) : l.coprod (⊥ : Filter β) = comap Prod.fst l := by simp [Filter.coprod] theorem bot_coprod_bot : (⊥ : Filter α).coprod (⊥ : Filter β) = ⊥ := by simp theorem compl_mem_coprod {s : Set (α × β)} {la : Filter α} {lb : Filter β} : sᶜ ∈ la.coprod lb ↔ (Prod.fst '' s)ᶜ ∈ la ∧ (Prod.snd '' s)ᶜ ∈ lb := by simp only [Filter.coprod, mem_sup, compl_mem_comap] @[mono] theorem coprod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.coprod g₁ ≤ f₂.coprod g₂ := sup_le_sup (comap_mono hf) (comap_mono hg) theorem coprod_neBot_iff : (f.coprod g).NeBot ↔ f.NeBot ∧ Nonempty β ∨ Nonempty α ∧ g.NeBot := by simp [Filter.coprod] @[instance] theorem coprod_neBot_left [NeBot f] [Nonempty β] : (f.coprod g).NeBot := coprod_neBot_iff.2 (Or.inl ⟨‹_›, ‹_›⟩) @[instance] theorem coprod_neBot_right [NeBot g] [Nonempty α] : (f.coprod g).NeBot := coprod_neBot_iff.2 (Or.inr ⟨‹_›, ‹_›⟩) theorem coprod_inf_prod_le (f₁ f₂ : Filter α) (g₁ g₂ : Filter β) : f₁.coprod g₁ ⊓ f₂ ×ˢ g₂ ≤ f₁ ×ˢ g₂ ⊔ f₂ ×ˢ g₁ := calc f₁.coprod g₁ ⊓ f₂ ×ˢ g₂ _ = (f₁ ×ˢ ⊤ ⊔ ⊤ ×ˢ g₁) ⊓ f₂ ×ˢ g₂ := by rw [coprod_eq_prod_top_sup_top_prod] _ = f₁ ×ˢ ⊤ ⊓ f₂ ×ˢ g₂ ⊔ ⊤ ×ˢ g₁ ⊓ f₂ ×ˢ g₂ := inf_sup_right _ _ _ _ = (f₁ ⊓ f₂) ×ˢ g₂ ⊔ f₂ ×ˢ (g₁ ⊓ g₂) := by simp [prod_inf_prod] _ ≤ f₁ ×ˢ g₂ ⊔ f₂ ×ˢ g₁ := sup_le_sup (prod_mono inf_le_left le_rfl) (prod_mono le_rfl inf_le_left) theorem principal_coprod_principal (s : Set α) (t : Set β) : (𝓟 s).coprod (𝓟 t) = 𝓟 (sᶜ ×ˢ tᶜ)ᶜ := by rw [Filter.coprod, comap_principal, comap_principal, sup_principal, Set.prod_eq, compl_inter, preimage_compl, preimage_compl, compl_compl, compl_compl] -- this inequality can be strict; see `map_const_principal_coprod_map_id_principal` and -- `map_prodMap_const_id_principal_coprod_principal` below. theorem map_prodMap_coprod_le.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} : map (Prod.map m₁ m₂) (f₁.coprod f₂) ≤ (map m₁ f₁).coprod (map m₂ f₂) := by intro s simp only [mem_map, mem_coprod_iff] rintro ⟨⟨u₁, hu₁, h₁⟩, u₂, hu₂, h₂⟩ refine ⟨⟨m₁ ⁻¹' u₁, hu₁, fun _ hx => h₁ ?_⟩, ⟨m₂ ⁻¹' u₂, hu₂, fun _ hx => h₂ ?_⟩⟩ <;> convert hx @[deprecated (since := "2025-03-10")] alias map_prod_map_coprod_le := map_prodMap_coprod_le /-- Characterization of the coproduct of the `Filter.map`s of two principal filters `𝓟 {a}` and `𝓟 {i}`, the first under the constant function `fun a => b` and the second under the identity function. Together with the next lemma, `map_prodMap_const_id_principal_coprod_principal`, this provides an example showing that the inequality in the lemma `map_prodMap_coprod_le` can be strict. -/ theorem map_const_principal_coprod_map_id_principal {α β ι : Type*} (a : α) (b : β) (i : ι) : (map (fun _ => b) (𝓟 {a})).coprod (map id (𝓟 {i})) = 𝓟 ((({b} : Set β) ×ˢ univ) ∪ (univ ×ˢ ({i} : Set ι))) := by simp only [map_principal, Filter.coprod, comap_principal, sup_principal, image_singleton, prod_univ, univ_prod, id] /-- Characterization of the `Filter.map` of the coproduct of two principal filters `𝓟 {a}` and `𝓟 {i}`, under the `Prod.map` of two functions, respectively the constant function `fun a => b` and the identity function. Together with the previous lemma, `map_const_principal_coprod_map_id_principal`, this provides an example showing that the inequality in the lemma `map_prodMap_coprod_le` can be strict. -/ theorem map_prodMap_const_id_principal_coprod_principal {α β ι : Type*} (a : α) (b : β) (i : ι) : map (Prod.map (fun _ : α => b) id) ((𝓟 {a}).coprod (𝓟 {i})) = 𝓟 (({b} : Set β) ×ˢ (univ : Set ι)) := by rw [principal_coprod_principal, map_principal] congr ext ⟨b', i'⟩ constructor · rintro ⟨⟨a'', i''⟩, _, h₂, h₃⟩ simp · rintro ⟨h₁, _⟩ use (a, i') simpa using h₁.symm @[deprecated (since := "2025-03-10")] alias map_prod_map_const_id_principal_coprod_principal := map_prodMap_const_id_principal_coprod_principal theorem Tendsto.prodMap_coprod {δ : Type*} {f : α → γ} {g : β → δ} {a : Filter α} {b : Filter β} {c : Filter γ} {d : Filter δ} (hf : Tendsto f a c) (hg : Tendsto g b d) : Tendsto (Prod.map f g) (a.coprod b) (c.coprod d) := map_prodMap_coprod_le.trans (coprod_mono hf hg) @[deprecated (since := "2025-03-10")] alias Tendsto.prod_map_coprod := Tendsto.prodMap_coprod end Coprod end Filter
ssrnotations.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) (******************************************************************************) (* - Reserved notation for various arithmetic and algebraic operations: *) (* e.[a1, ..., a_n] evaluation (e.g., polynomials). *) (* e`_i indexing (number list, integer pi-part). *) (* x^-1 inverse (group, field). *) (* x *+ n, x *- n integer multiplier (modules and rings). *) (* x ^+ n, x ^- n integer exponent (groups and rings). *) (* x *: A, A :* x external product (scaling/module product in rings, *) (* left/right cosets in groups). *) (* A :&: B intersection (of sets, groups, subspaces, ...). *) (* A :|: B, a |: B union, union with a singleton (of sets). *) (* A :\: B, A :\ b relative complement (of sets, subspaces, ...). *) (* <<A>>, <[a]> generated group/subspace, generated cycle/line. *) (* 'C[x], 'C_A[x] point centralisers (in groups and F-algebras). *) (* 'C(A), 'C_B(A) centralisers (in groups and matrix and F_algebras). *) (* 'Z(A) centers (in groups and matrix and F-algebras). *) (* m %/ d, m %% d Euclidean division and remainder (nat, polynomials). *) (* d %| m Euclidean divisibility (nat, polynomial). *) (* m = n %[mod d] equality mod d (also defined for <>, ==, and !=). *) (* e^`(n) nth formal derivative (groups, polynomials). *) (* e^`() simple formal derivative (polynomials only). *) (* `|x| norm, absolute value, distance (rings, int, nat). *) (* x <= y ?= iff C x is less than y, and equal iff C holds (nat, rings). *) (* x <= y :> T, etc cast comparison (rings, all comparison operators). *) (* [rec a1, ..., an] standard shorthand for hidden recursor (see prime.v). *) (* The interpretation of these notations is not defined here, but the *) (* declarations help maintain consistency across the library. *) (******************************************************************************) (* Reserved notation for evaluation *) Reserved Notation "e .[ x ]" (left associativity, format "e .[ x ]"). Reserved Notation "e .[ x1 , x2 , .. , xn ]" (left associativity, format "e '[ ' .[ x1 , '/' x2 , '/' .. , '/' xn ] ']'"). (* Reserved notation for subscripting and superscripting *) Reserved Notation "s `_ i" (at level 3, i at level 2, left associativity, format "s `_ i"). Reserved Notation "x ^-1" (left associativity, format "x ^-1"). (* Reserved notation for integer multipliers and exponents *) Reserved Notation "x *+ n" (at level 40, left associativity). Reserved Notation "x *- n" (at level 40, left associativity). Reserved Notation "x ^+ n" (at level 29, left associativity). Reserved Notation "x ^- n" (at level 29, left associativity). (* Reserved notation for external multiplication. *) Reserved Notation "x *: A" (at level 40). Reserved Notation "A :* x" (at level 40). (* Reserved notation for conjugation and lifting of actions to sets. *) Reserved Notation "x ^*" (format "x ^*", left associativity). (* Reserved notation for set-theoretic operations. *) Reserved Notation "A :&: B" (at level 48, left associativity). Reserved Notation "A :|: B" (at level 52, left associativity). Reserved Notation "a |: A" (at level 52, left associativity). Reserved Notation "A :\: B" (at level 50, left associativity). Reserved Notation "A :\ b" (at level 50, left associativity). (* Reserved notation for generated structures *) Reserved Notation "<< A >>" (format "<< A >>"). Reserved Notation "<[ a ] >" (format "<[ a ] >"). (* Reserved notation for the order of an element (group, polynomial, etc) *) Reserved Notation "#[ x ]" (format "#[ x ]"). (* Reserved notation for centralisers and centers. *) Reserved Notation "''C' [ x ]" (format "''C' [ x ]"). Reserved Notation "''C_' A [ x ]" (A at level 2, format "''C_' A [ x ]"). Reserved Notation "''C' ( A )" (format "''C' ( A )"). Reserved Notation "''C_' B ( A )" (B at level 2, format "''C_' B ( A )"). Reserved Notation "''Z' ( A )" (format "''Z' ( A )"). (* Compatibility with group action centraliser notation. *) Reserved Notation "''C_' ( A ) [ x ]". Reserved Notation "''C_' ( B ) ( A )". Reserved Notation "''C' [ x | to ]" (format "''C' [ x | to ]"). Reserved Notation "''C' ( S | to )" (format "''C' ( S | to )"). Reserved Notation "''C_' A [ x | to ]" (A at level 2, format "''C_' A [ x | to ]"). Reserved Notation "''C_' A ( S | to )" (A at level 2, format "''C_' A ( S | to )"). Reserved Notation "''C_' ( A ) [ x | to ]". Reserved Notation "''C_' ( A ) ( S | to )". Reserved Notation "''C_' ( | to ) [ a ]" (format "''C_' ( | to ) [ a ]"). Reserved Notation "''C_' ( G | to ) [ a ]" (format "''C_' ( G | to ) [ a ]"). Reserved Notation "''C_' ( | to ) ( A )" (format "''C_' ( | to ) ( A )"). Reserved Notation "''C_' ( G | to ) ( A )" (format "''C_' ( G | to ) ( A )"). (* Bionomial coefficient *) Reserved Notation "''C' ( n , m )" (format "''C' ( n , m )"). (* Reserved notation for Euclidean division and divisibility. *) Reserved Notation "m %/ d" (at level 40, no associativity). Reserved Notation "m %% d" (at level 40, no associativity). Reserved Notation "m %| d" (at level 70, no associativity). #[warning="-postfix-notation-not-level-1"] Reserved Notation "m = n %[mod d ]" (format "'[hv ' m '/' = n '/' %[mod d ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "m == n %[mod d ]" (at level 70, n at next level, format "'[hv ' m '/' == n '/' %[mod d ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "m <> n %[mod d ]" (format "'[hv ' m '/' <> n '/' %[mod d ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "m != n %[mod d ]" (at level 70, n at next level, format "'[hv ' m '/' != n '/' %[mod d ] ']'"). (* Reserved notation for derivatives. *) Reserved Notation "a ^` ()" (format "a ^` ()"). Reserved Notation "a ^` ( n )" (format "a ^` ( n )"). (* Reserved notation for absolute value. *) Reserved Notation "`| x |" (format "`| x |"). (* Reserved notation for conditional comparison *) Reserved Notation "x <= y ?= 'iff' c" (c at next level, format "x '[hv' <= y '/' ?= 'iff' c ']'"). (* Reserved notation for cast comparison. *) Reserved Notation "x <= y :> T". Reserved Notation "x >= y :> T". Reserved Notation "x < y :> T". Reserved Notation "x > y :> T". Reserved Notation "x <= y ?= 'iff' c :> T" (c at next level, format "x '[hv' <= y '/' ?= 'iff' c :> T ']'"). (* Reserved notation for dot product. *) Reserved Notation "'[ u , v ]" (format "'[hv' ''[' u , '/ ' v ] ']'"). Reserved Notation "'[ u ]" (format "''[' u ]").
Hermitian.lean
/- Copyright (c) 2022 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.LinearAlgebra.Matrix.ZPow import Mathlib.Data.Matrix.ConjTranspose /-! # Hermitian matrices This file defines hermitian matrices and some basic results about them. See also `IsSelfAdjoint`, which generalizes this definition to other star rings. ## Main definition * `Matrix.IsHermitian` : a matrix `A : Matrix n n α` is hermitian if `Aᴴ = A`. ## Tags self-adjoint matrix, hermitian matrix -/ namespace Matrix variable {α β : Type*} {m n : Type*} {A : Matrix n n α} open scoped Matrix local notation "⟪" x ", " y "⟫" => inner α x y section Star variable [Star α] [Star β] /-- A matrix is hermitian if it is equal to its conjugate transpose. On the reals, this definition captures symmetric matrices. -/ def IsHermitian (A : Matrix n n α) : Prop := Aᴴ = A instance (A : Matrix n n α) [Decidable (Aᴴ = A)] : Decidable (IsHermitian A) := inferInstanceAs <| Decidable (_ = _) theorem IsHermitian.eq {A : Matrix n n α} (h : A.IsHermitian) : Aᴴ = A := h protected theorem IsHermitian.isSelfAdjoint {A : Matrix n n α} (h : A.IsHermitian) : IsSelfAdjoint A := h theorem IsHermitian.ext {A : Matrix n n α} : (∀ i j, star (A j i) = A i j) → A.IsHermitian := by intro h; ext i j; exact h i j theorem IsHermitian.apply {A : Matrix n n α} (h : A.IsHermitian) (i j : n) : star (A j i) = A i j := congr_fun (congr_fun h _) _ theorem IsHermitian.ext_iff {A : Matrix n n α} : A.IsHermitian ↔ ∀ i j, star (A j i) = A i j := ⟨IsHermitian.apply, IsHermitian.ext⟩ @[simp] theorem IsHermitian.map {A : Matrix n n α} (h : A.IsHermitian) (f : α → β) (hf : Function.Semiconj f star star) : (A.map f).IsHermitian := (conjTranspose_map f hf).symm.trans <| h.eq.symm ▸ rfl theorem IsHermitian.transpose {A : Matrix n n α} (h : A.IsHermitian) : Aᵀ.IsHermitian := by rw [IsHermitian, conjTranspose, transpose_map] exact congr_arg Matrix.transpose h @[simp] theorem isHermitian_transpose_iff (A : Matrix n n α) : Aᵀ.IsHermitian ↔ A.IsHermitian := ⟨by intro h; rw [← transpose_transpose A]; exact IsHermitian.transpose h, IsHermitian.transpose⟩ theorem IsHermitian.conjTranspose {A : Matrix n n α} (h : A.IsHermitian) : Aᴴ.IsHermitian := h.transpose.map _ fun _ => rfl @[simp] theorem IsHermitian.submatrix {A : Matrix n n α} (h : A.IsHermitian) (f : m → n) : (A.submatrix f f).IsHermitian := (conjTranspose_submatrix _ _ _).trans (h.symm ▸ rfl) @[simp] theorem isHermitian_submatrix_equiv {A : Matrix n n α} (e : m ≃ n) : (A.submatrix e e).IsHermitian ↔ A.IsHermitian := ⟨fun h => by simpa using h.submatrix e.symm, fun h => h.submatrix _⟩ end Star section InvolutiveStar variable [InvolutiveStar α] @[simp] theorem isHermitian_conjTranspose_iff (A : Matrix n n α) : Aᴴ.IsHermitian ↔ A.IsHermitian := IsSelfAdjoint.star_iff /-- A block matrix `A.from_blocks B C D` is hermitian, if `A` and `D` are hermitian and `Bᴴ = C`. -/ theorem IsHermitian.fromBlocks {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α} {D : Matrix n n α} (hA : A.IsHermitian) (hBC : Bᴴ = C) (hD : D.IsHermitian) : (A.fromBlocks B C D).IsHermitian := by have hCB : Cᴴ = B := by rw [← hBC, conjTranspose_conjTranspose] unfold Matrix.IsHermitian rw [fromBlocks_conjTranspose, hBC, hCB, hA, hD] /-- This is the `iff` version of `Matrix.IsHermitian.fromBlocks`. -/ theorem isHermitian_fromBlocks_iff {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α} {D : Matrix n n α} : (A.fromBlocks B C D).IsHermitian ↔ A.IsHermitian ∧ Bᴴ = C ∧ Cᴴ = B ∧ D.IsHermitian := ⟨fun h => ⟨congr_arg toBlocks₁₁ h, congr_arg toBlocks₂₁ h, congr_arg toBlocks₁₂ h, congr_arg toBlocks₂₂ h⟩, fun ⟨hA, hBC, _hCB, hD⟩ => IsHermitian.fromBlocks hA hBC hD⟩ end InvolutiveStar section AddMonoid variable [AddMonoid α] [StarAddMonoid α] /-- A diagonal matrix is hermitian if the entries are self-adjoint (as a vector) -/ theorem isHermitian_diagonal_of_self_adjoint [DecidableEq n] (v : n → α) (h : IsSelfAdjoint v) : (diagonal v).IsHermitian := (-- TODO: add a `pi.has_trivial_star` instance and remove the `funext` diagonal_conjTranspose v).trans <| congr_arg _ h /-- A diagonal matrix is hermitian if each diagonal entry is self-adjoint -/ lemma isHermitian_diagonal_iff [DecidableEq n] {d : n → α} : IsHermitian (diagonal d) ↔ (∀ i : n, IsSelfAdjoint (d i)) := by simp [isSelfAdjoint_iff, IsHermitian, conjTranspose, diagonal_transpose, diagonal_map] /-- A diagonal matrix is hermitian if the entries have the trivial `star` operation (such as on the reals). -/ @[simp] theorem isHermitian_diagonal [TrivialStar α] [DecidableEq n] (v : n → α) : (diagonal v).IsHermitian := isHermitian_diagonal_of_self_adjoint _ (IsSelfAdjoint.all _) @[simp] theorem isHermitian_zero : (0 : Matrix n n α).IsHermitian := IsSelfAdjoint.zero _ @[simp] theorem IsHermitian.add {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : (A + B).IsHermitian := IsSelfAdjoint.add hA hB end AddMonoid section AddCommMonoid variable [AddCommMonoid α] [StarAddMonoid α] theorem isHermitian_add_transpose_self (A : Matrix n n α) : (A + Aᴴ).IsHermitian := IsSelfAdjoint.add_star_self A theorem isHermitian_transpose_add_self (A : Matrix n n α) : (Aᴴ + A).IsHermitian := IsSelfAdjoint.star_add_self A end AddCommMonoid section AddGroup variable [AddGroup α] [StarAddMonoid α] @[simp] theorem IsHermitian.neg {A : Matrix n n α} (h : A.IsHermitian) : (-A).IsHermitian := IsSelfAdjoint.neg h @[simp] theorem IsHermitian.sub {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : (A - B).IsHermitian := IsSelfAdjoint.sub hA hB end AddGroup section NonUnitalSemiring variable [NonUnitalSemiring α] [StarRing α] /-- Note this is more general than `IsSelfAdjoint.mul_star_self` as `B` can be rectangular. -/ theorem isHermitian_mul_conjTranspose_self [Fintype n] (A : Matrix m n α) : (A * Aᴴ).IsHermitian := by rw [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose] /-- Note this is more general than `IsSelfAdjoint.star_mul_self` as `B` can be rectangular. -/ theorem isHermitian_transpose_mul_self [Fintype m] (A : Matrix m n α) : (Aᴴ * A).IsHermitian := by rw [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose] /-- Note this is more general than `IsSelfAdjoint.conjugate'` as `B` can be rectangular. -/ theorem isHermitian_conjTranspose_mul_mul [Fintype m] {A : Matrix m m α} (B : Matrix m n α) (hA : A.IsHermitian) : (Bᴴ * A * B).IsHermitian := by simp only [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose, hA.eq, Matrix.mul_assoc] /-- Note this is more general than `IsSelfAdjoint.conjugate` as `B` can be rectangular. -/ theorem isHermitian_mul_mul_conjTranspose [Fintype m] {A : Matrix m m α} (B : Matrix n m α) (hA : A.IsHermitian) : (B * A * Bᴴ).IsHermitian := by simp only [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose, hA.eq, Matrix.mul_assoc] lemma IsHermitian.commute_iff [Fintype n] {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : Commute A B ↔ (A * B).IsHermitian := hA.isSelfAdjoint.commute_iff hB.isSelfAdjoint @[deprecated (since := "13-08-2025")] alias commute_iff := IsHermitian.commute_iff end NonUnitalSemiring section Semiring variable [Semiring α] [StarRing α] /-- Note this is more general for matrices than `isSelfAdjoint_one` as it does not require `Fintype n`, which is necessary for `Monoid (Matrix n n R)`. -/ @[simp] theorem isHermitian_one [DecidableEq n] : (1 : Matrix n n α).IsHermitian := conjTranspose_one @[simp] theorem isHermitian_natCast [DecidableEq n] (d : ℕ) : (d : Matrix n n α).IsHermitian := conjTranspose_natCast _ theorem IsHermitian.pow [Fintype n] [DecidableEq n] {A : Matrix n n α} (h : A.IsHermitian) (k : ℕ) : (A ^ k).IsHermitian := IsSelfAdjoint.pow h _ end Semiring section Ring variable [Ring α] [StarRing α] @[simp] theorem isHermitian_intCast [DecidableEq n] (d : ℤ) : (d : Matrix n n α).IsHermitian := conjTranspose_intCast _ end Ring section CommRing variable [CommRing α] [StarRing α] theorem IsHermitian.inv [Fintype m] [DecidableEq m] {A : Matrix m m α} (hA : A.IsHermitian) : A⁻¹.IsHermitian := by simp [IsHermitian, conjTranspose_nonsing_inv, hA.eq] @[simp] theorem isHermitian_inv [Fintype m] [DecidableEq m] (A : Matrix m m α) [Invertible A] : A⁻¹.IsHermitian ↔ A.IsHermitian := ⟨fun h => by rw [← inv_inv_of_invertible A]; exact IsHermitian.inv h, IsHermitian.inv⟩ theorem IsHermitian.adjugate [Fintype m] [DecidableEq m] {A : Matrix m m α} (hA : A.IsHermitian) : A.adjugate.IsHermitian := by simp [IsHermitian, adjugate_conjTranspose, hA.eq] /-- Note that `IsSelfAdjoint.zpow` does not apply to matrices as they are not a division ring. -/ theorem IsHermitian.zpow [Fintype m] [DecidableEq m] {A : Matrix m m α} (h : A.IsHermitian) (k : ℤ) : (A ^ k).IsHermitian := by rw [IsHermitian, conjTranspose_zpow, h] end CommRing section RCLike open RCLike variable [RCLike α] /-- The diagonal elements of a complex hermitian matrix are real. -/ theorem IsHermitian.coe_re_apply_self {A : Matrix n n α} (h : A.IsHermitian) (i : n) : (re (A i i) : α) = A i i := by rw [← conj_eq_iff_re, ← star_def, ← conjTranspose_apply, h.eq] /-- The diagonal elements of a complex hermitian matrix are real. -/ theorem IsHermitian.coe_re_diag {A : Matrix n n α} (h : A.IsHermitian) : (fun i => (re (A.diag i) : α)) = A.diag := funext h.coe_re_apply_self /-- A matrix is hermitian iff the corresponding linear map is self adjoint. -/ theorem isHermitian_iff_isSymmetric [Fintype n] [DecidableEq n] {A : Matrix n n α} : IsHermitian A ↔ A.toEuclideanLin.IsSymmetric := by rw [LinearMap.IsSymmetric, (WithLp.toLp_surjective _).forall₂] simp only [toEuclideanLin_toLp, Matrix.toLin'_apply, EuclideanSpace.inner_eq_star_dotProduct, WithLp.ofLp_toLp, star_mulVec] constructor · rintro (h : Aᴴ = A) x y rw [dotProduct_comm, ← dotProduct_mulVec, h, dotProduct_comm] · intro h ext i j simpa [(Pi.single_star i 1).symm] using h (Pi.single i 1) (Pi.single j 1) end RCLike end Matrix
FactorThru.lean
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Kim Morrison -/ import Mathlib.CategoryTheory.Subobject.Basic import Mathlib.CategoryTheory.Preadditive.Basic /-! # Factoring through subobjects The predicate `h : P.Factors f`, for `P : Subobject Y` and `f : X ⟶ Y` asserts the existence of some `P.factorThru f : X ⟶ (P : C)` making the obvious diagram commute. -/ universe v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] {X Y Z : C} variable {D : Type u₂} [Category.{v₂} D] namespace CategoryTheory namespace MonoOver /-- When `f : X ⟶ Y` and `P : MonoOver Y`, `P.Factors f` expresses that there exists a factorisation of `f` through `P`. Given `h : P.Factors f`, you can recover the morphism as `P.factorThru f h`. -/ def Factors {X Y : C} (P : MonoOver Y) (f : X ⟶ Y) : Prop := ∃ g : X ⟶ (P : C), g ≫ P.arrow = f theorem factors_congr {X : C} {f g : MonoOver X} {Y : C} (h : Y ⟶ X) (e : f ≅ g) : f.Factors h ↔ g.Factors h := ⟨fun ⟨u, hu⟩ => ⟨u ≫ ((MonoOver.forget _).map e.hom).left, by simp [hu]⟩, fun ⟨u, hu⟩ => ⟨u ≫ ((MonoOver.forget _).map e.inv).left, by simp [hu]⟩⟩ /-- `P.factorThru f h` provides a factorisation of `f : X ⟶ Y` through some `P : MonoOver Y`, given the evidence `h : P.Factors f` that such a factorisation exists. -/ def factorThru {X Y : C} (P : MonoOver Y) (f : X ⟶ Y) (h : Factors P f) : X ⟶ (P : C) := Classical.choose h end MonoOver namespace Subobject /-- When `f : X ⟶ Y` and `P : Subobject Y`, `P.Factors f` expresses that there exists a factorisation of `f` through `P`. Given `h : P.Factors f`, you can recover the morphism as `P.factorThru f h`. -/ def Factors {X Y : C} (P : Subobject Y) (f : X ⟶ Y) : Prop := Quotient.liftOn' P (fun P => P.Factors f) (by rintro P Q ⟨h⟩ apply propext constructor · rintro ⟨i, w⟩ exact ⟨i ≫ h.hom.left, by erw [Category.assoc, Over.w h.hom, w]⟩ · rintro ⟨i, w⟩ exact ⟨i ≫ h.inv.left, by erw [Category.assoc, Over.w h.inv, w]⟩) @[simp] theorem mk_factors_iff {X Y Z : C} (f : Y ⟶ X) [Mono f] (g : Z ⟶ X) : (Subobject.mk f).Factors g ↔ (MonoOver.mk' f).Factors g := Iff.rfl theorem mk_factors_self (f : X ⟶ Y) [Mono f] : (mk f).Factors f := ⟨𝟙 _, by simp⟩ theorem factors_iff {X Y : C} (P : Subobject Y) (f : X ⟶ Y) : P.Factors f ↔ (representative.obj P).Factors f := Quot.inductionOn P fun _ => MonoOver.factors_congr _ (representativeIso _).symm theorem factors_self {X : C} (P : Subobject X) : P.Factors P.arrow := (factors_iff _ _).mpr ⟨𝟙 (P : C), by simp⟩ theorem factors_comp_arrow {X Y : C} {P : Subobject Y} (f : X ⟶ P) : P.Factors (f ≫ P.arrow) := (factors_iff _ _).mpr ⟨f, rfl⟩ theorem factors_of_factors_right {X Y Z : C} {P : Subobject Z} (f : X ⟶ Y) {g : Y ⟶ Z} (h : P.Factors g) : P.Factors (f ≫ g) := by induction' P using Quotient.ind' with P obtain ⟨g, rfl⟩ := h exact ⟨f ≫ g, by simp⟩ theorem factors_zero [HasZeroMorphisms C] {X Y : C} {P : Subobject Y} : P.Factors (0 : X ⟶ Y) := (factors_iff _ _).mpr ⟨0, by simp⟩ theorem factors_of_le {Y Z : C} {P Q : Subobject Y} (f : Z ⟶ Y) (h : P ≤ Q) : P.Factors f → Q.Factors f := by simp only [factors_iff] exact fun ⟨u, hu⟩ => ⟨u ≫ ofLE _ _ h, by simp [← hu]⟩ /-- `P.factorThru f h` provides a factorisation of `f : X ⟶ Y` through some `P : Subobject Y`, given the evidence `h : P.Factors f` that such a factorisation exists. -/ def factorThru {X Y : C} (P : Subobject Y) (f : X ⟶ Y) (h : Factors P f) : X ⟶ P := Classical.choose ((factors_iff _ _).mp h) @[reassoc (attr := simp)] theorem factorThru_arrow {X Y : C} (P : Subobject Y) (f : X ⟶ Y) (h : Factors P f) : P.factorThru f h ≫ P.arrow = f := Classical.choose_spec ((factors_iff _ _).mp h) @[simp] theorem factorThru_self {X : C} (P : Subobject X) (h) : P.factorThru P.arrow h = 𝟙 (P : C) := by ext simp @[simp] theorem factorThru_mk_self (f : X ⟶ Y) [Mono f] : (mk f).factorThru f (mk_factors_self f) = (underlyingIso f).inv := by ext simp @[simp] theorem factorThru_comp_arrow {X Y : C} {P : Subobject Y} (f : X ⟶ P) (h) : P.factorThru (f ≫ P.arrow) h = f := by ext simp @[simp] theorem factorThru_eq_zero [HasZeroMorphisms C] {X Y : C} {P : Subobject Y} {f : X ⟶ Y} {h : Factors P f} : P.factorThru f h = 0 ↔ f = 0 := by fconstructor · intro w replace w := w =≫ P.arrow simpa using w · rintro rfl ext simp theorem factorThru_right {X Y Z : C} {P : Subobject Z} (f : X ⟶ Y) (g : Y ⟶ Z) (h : P.Factors g) : f ≫ P.factorThru g h = P.factorThru (f ≫ g) (factors_of_factors_right f h) := by apply (cancel_mono P.arrow).mp simp @[simp] theorem factorThru_zero [HasZeroMorphisms C] {X Y : C} {P : Subobject Y} (h : P.Factors (0 : X ⟶ Y)) : P.factorThru 0 h = 0 := by simp -- `h` is an explicit argument here so we can use -- `rw factorThru_ofLE h`, obtaining a subgoal `P.Factors f`. -- (While the reverse direction looks plausible as a simp lemma, it seems to be unproductive.) theorem factorThru_ofLE {Y Z : C} {P Q : Subobject Y} {f : Z ⟶ Y} (h : P ≤ Q) (w : P.Factors f) : Q.factorThru f (factors_of_le f h w) = P.factorThru f w ≫ ofLE P Q h := by ext simp section Preadditive variable [Preadditive C] theorem factors_add {X Y : C} {P : Subobject Y} (f g : X ⟶ Y) (wf : P.Factors f) (wg : P.Factors g) : P.Factors (f + g) := (factors_iff _ _).mpr ⟨P.factorThru f wf + P.factorThru g wg, by simp⟩ -- This can't be a `simp` lemma as `wf` and `wg` may not exist. -- However you can `rw` by it to assert that `f` and `g` factor through `P` separately. theorem factorThru_add {X Y : C} {P : Subobject Y} (f g : X ⟶ Y) (w : P.Factors (f + g)) (wf : P.Factors f) (wg : P.Factors g) : P.factorThru (f + g) w = P.factorThru f wf + P.factorThru g wg := by ext simp theorem factors_left_of_factors_add {X Y : C} {P : Subobject Y} (f g : X ⟶ Y) (w : P.Factors (f + g)) (wg : P.Factors g) : P.Factors f := (factors_iff _ _).mpr ⟨P.factorThru (f + g) w - P.factorThru g wg, by simp⟩ @[simp] theorem factorThru_add_sub_factorThru_right {X Y : C} {P : Subobject Y} (f g : X ⟶ Y) (w : P.Factors (f + g)) (wg : P.Factors g) : P.factorThru (f + g) w - P.factorThru g wg = P.factorThru f (factors_left_of_factors_add f g w wg) := by ext simp theorem factors_right_of_factors_add {X Y : C} {P : Subobject Y} (f g : X ⟶ Y) (w : P.Factors (f + g)) (wf : P.Factors f) : P.Factors g := (factors_iff _ _).mpr ⟨P.factorThru (f + g) w - P.factorThru f wf, by simp⟩ @[simp] theorem factorThru_add_sub_factorThru_left {X Y : C} {P : Subobject Y} (f g : X ⟶ Y) (w : P.Factors (f + g)) (wf : P.Factors f) : P.factorThru (f + g) w - P.factorThru f wf = P.factorThru g (factors_right_of_factors_add f g w wf) := by ext simp end Preadditive end Subobject end CategoryTheory
Center.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Jireh Loreaux -/ import Mathlib.Algebra.Group.Center import Mathlib.Data.Int.Cast.Lemmas /-! # Centers of rings -/ assert_not_exists RelIso Finset Subsemigroup Field variable {M : Type*} namespace Set variable (M) @[simp] theorem natCast_mem_center [NonAssocSemiring M] (n : ℕ) : (n : M) ∈ Set.center M where comm _ := by rw [commute_iff_eq, Nat.commute_cast] left_assoc _ _ := by induction n with | zero => rw [Nat.cast_zero, zero_mul, zero_mul, zero_mul] | succ n ihn => rw [Nat.cast_succ, add_mul, one_mul, ihn, add_mul, add_mul, one_mul] right_assoc _ _ := by induction n with | zero => rw [Nat.cast_zero, mul_zero, mul_zero, mul_zero] | succ n ihn => rw [Nat.cast_succ, mul_add, ihn, mul_add, mul_add, mul_one, mul_one] @[simp] theorem ofNat_mem_center [NonAssocSemiring M] (n : ℕ) [n.AtLeastTwo] : ofNat(n) ∈ Set.center M := natCast_mem_center M n @[simp] theorem intCast_mem_center [NonAssocRing M] (n : ℤ) : (n : M) ∈ Set.center M where comm _ := by rw [commute_iff_eq, Int.commute_cast] left_assoc _ _ := match n with | (n : ℕ) => by rw [Int.cast_natCast, (natCast_mem_center _ n).left_assoc _ _] | Int.negSucc n => by rw [Int.cast_negSucc, Nat.cast_add, Nat.cast_one, neg_add_rev, add_mul, add_mul, add_mul, neg_mul, one_mul, neg_mul 1, one_mul, ← neg_mul, add_right_inj, neg_mul, (natCast_mem_center _ n).left_assoc _ _, neg_mul, neg_mul] right_assoc _ _ := match n with | (n : ℕ) => by rw [Int.cast_natCast, (natCast_mem_center _ n).right_assoc _ _] | Int.negSucc n => by simp only [Int.cast_negSucc, Nat.cast_add, Nat.cast_one, neg_add_rev] rw [mul_add, mul_add, mul_add, mul_neg, mul_one, mul_neg, mul_neg, mul_one, mul_neg, add_right_inj, (natCast_mem_center _ n).right_assoc _ _, mul_neg, mul_neg] variable {M} @[simp] theorem add_mem_center [Distrib M] {a b : M} (ha : a ∈ Set.center M) (hb : b ∈ Set.center M) : a + b ∈ Set.center M where comm _ := by rw [commute_iff_eq, add_mul, mul_add, ha.comm, hb.comm] left_assoc _ _ := by rw [add_mul, ha.left_assoc, hb.left_assoc, ← add_mul, ← add_mul] right_assoc _ _ := by rw [mul_add, ha.right_assoc, hb.right_assoc, ← mul_add, ← mul_add] @[simp] theorem neg_mem_center [NonUnitalNonAssocRing M] {a : M} (ha : a ∈ Set.center M) : -a ∈ Set.center M where comm _ := by rw [commute_iff_eq, ← neg_mul_comm, ← ha.comm, neg_mul_comm] left_assoc _ _ := by rw [neg_mul, ha.left_assoc, neg_mul, neg_mul] right_assoc _ _ := by rw [mul_neg, ha.right_assoc, mul_neg, mul_neg] end Set
LebesgueNormedSpace.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.MeasureTheory.Measure.WithDensity import Mathlib.Analysis.Normed.Module.Basic /-! # A lemma about measurability with density under scalar multiplication in normed spaces -/ open MeasureTheory Filter ENNReal Set open NNReal ENNReal variable {α : Type*} {m : MeasurableSpace α} {μ : MeasureTheory.Measure α} theorem aemeasurable_withDensity_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] {f : α → ℝ≥0} (hf : Measurable f) {g : α → E} : AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔ AEMeasurable (fun x => (f x : ℝ) • g x) μ := by constructor · rintro ⟨g', g'meas, hg'⟩ have A : MeasurableSet { x : α | f x ≠ 0 } := (hf (measurableSet_singleton 0)).compl refine ⟨fun x => (f x : ℝ) • g' x, hf.coe_nnreal_real.smul g'meas, ?_⟩ apply @ae_of_ae_restrict_of_ae_restrict_compl _ _ _ { x | f x ≠ 0 } · rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal] at hg' rw [ae_restrict_iff' A] filter_upwards [hg'] intro a ha h'a have : (f a : ℝ≥0∞) ≠ 0 := by simpa only [Ne, ENNReal.coe_eq_zero] using h'a rw [ha this] · filter_upwards [ae_restrict_mem A.compl] intro x hx simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx simp [hx] · rintro ⟨g', g'meas, hg'⟩ refine ⟨fun x => (f x : ℝ)⁻¹ • g' x, hf.coe_nnreal_real.inv.smul g'meas, ?_⟩ rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal] filter_upwards [hg'] intro x hx h'x rw [← hx, smul_smul, inv_mul_cancel₀, one_smul] simp only [Ne, ENNReal.coe_eq_zero] at h'x simpa only [NNReal.coe_eq_zero, Ne] using h'x
countalg.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype bigop ssralg. (*****************************************************************************) (* The algebraic part of the algebraic hierarchy for countable types *) (* *) (* This file clones part of ssralg hierarchy for countable types; it does *) (* not cover the left module / algebra interfaces, providing only *) (* countNmodType == countable nmodType interface *) (* countZmodType == countable zmodType interface *) (* countPzSemiRingType == countable pzSemiRingType interface *) (* countNzSemiRingType == countable nzSemiRingType interface *) (* countPzRingType == countable pzRingType interface *) (* countNzRingType == countable nzRingType interface *) (* countComPzSemiRingType == countable comPzSemiRingType interface *) (* countComNzSemiRingType == countable comNzSemiRingType interface *) (* countComPzRingType == countable comPzRingType interface *) (* countComNzRingType == countable comNzRingType interface *) (* countUnitRingType == countable unitRingType interface *) (* countComUnitRingType == countable comUnitRingType interface *) (* countIdomainType == countable idomainType interface *) (* countFieldType == countable fieldType interface *) (* countDecFieldType == countable decFieldType interface *) (* countClosedFieldType == countable closedFieldType interface *) (* *) (* This file provides constructions for both simple extension and algebraic *) (* closure of countable fields. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory CodeSeq. Module CountRing. Import GRing.Theory. #[short(type="countNmodType")] HB.structure Definition Nmodule := {M of GRing.Nmodule M & Countable M}. #[short(type="countZmodType")] HB.structure Definition Zmodule := {M of GRing.Zmodule M & Countable M}. #[short(type="countPzSemiRingType")] HB.structure Definition PzSemiRing := {R of GRing.PzSemiRing R & Countable R}. #[short(type="countNzSemiRingType")] HB.structure Definition NzSemiRing := {R of GRing.NzSemiRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing instead.")] Notation SemiRing R := (NzSemiRing R) (only parsing). Module SemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.sort instead.")] Notation sort := (NzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.on instead.")] Notation on R := (NzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.copy instead.")] Notation copy T U := (NzSemiRing.copy T U) (only parsing). End SemiRing. #[short(type="countPzRingType")] HB.structure Definition PzRing := {R of GRing.PzRing R & Countable R}. #[short(type="countNzRingType")] HB.structure Definition NzRing := {R of GRing.NzRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing instead.")] Notation Ring R := (NzRing R) (only parsing). Module Ring. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.sort instead.")] Notation sort := (NzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.on instead.")] Notation on R := (NzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.copy instead.")] Notation copy T U := (NzRing.copy T U) (only parsing). End Ring. #[short(type="countComPzSemiRingType")] HB.structure Definition ComPzSemiRing := {R of GRing.ComPzSemiRing R & Countable R}. #[short(type="countComNzSemiRingType")] HB.structure Definition ComNzSemiRing := {R of GRing.ComNzSemiRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing instead.")] Notation ComSemiRing R := (ComNzSemiRing R) (only parsing). Module ComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.sort instead.")] Notation sort := (ComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.on instead.")] Notation on R := (ComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.copy instead.")] Notation copy T U := (ComNzSemiRing.copy T U) (only parsing). End ComSemiRing. #[short(type="countComPzRingType")] HB.structure Definition ComPzRing := {R of GRing.ComPzRing R & Countable R}. #[short(type="countComNzRingType")] HB.structure Definition ComNzRing := {R of GRing.ComNzRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing instead.")] Notation ComRing R := (ComNzRing R) (only parsing). Module ComRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.sort instead.")] Notation sort := (ComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.on instead.")] Notation on R := (ComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.copy instead.")] Notation copy T U := (ComNzRing.copy T U) (only parsing). End ComRing. #[short(type="countUnitRingType")] HB.structure Definition UnitRing := {R of GRing.UnitRing R & Countable R}. #[short(type="countComUnitRingType")] HB.structure Definition ComUnitRing := {R of GRing.ComUnitRing R & Countable R}. #[short(type="countIdomainType")] HB.structure Definition IntegralDomain := {R of GRing.IntegralDomain R & Countable R}. #[short(type="countFieldType")] HB.structure Definition Field := {R of GRing.Field R & Countable R}. #[short(type="countDecFieldType")] HB.structure Definition DecidableField := {R of GRing.DecidableField R & Countable R}. #[short(type="countClosedFieldType")] HB.structure Definition ClosedField := {R of GRing.ClosedField R & Countable R}. Module ReguralExports. HB.instance Definition _ (R : countType) := Countable.on R^o. HB.instance Definition _ (R : countNmodType) := Nmodule.on R^o. HB.instance Definition _ (R : countZmodType) := Zmodule.on R^o. HB.instance Definition _ (R : countPzSemiRingType) := PzSemiRing.on R^o. HB.instance Definition _ (R : countNzSemiRingType) := NzSemiRing.on R^o. HB.instance Definition _ (R : countPzRingType) := PzRing.on R^o. HB.instance Definition _ (R : countNzRingType) := NzRing.on R^o. HB.instance Definition _ (R : countComPzSemiRingType) := ComPzSemiRing.on R^o. HB.instance Definition _ (R : countComNzSemiRingType) := ComNzSemiRing.on R^o. HB.instance Definition _ (R : countComPzRingType) := ComPzRing.on R^o. HB.instance Definition _ (R : countComNzRingType) := ComNzRing.on R^o. HB.instance Definition _ (R : countUnitRingType) := UnitRing.on R^o. HB.instance Definition _ (R : countComUnitRingType) := ComUnitRing.on R^o. HB.instance Definition _ (R : countIdomainType) := IntegralDomain.on R^o. HB.instance Definition _ (R : countFieldType) := Field.on R^o. HB.instance Definition _ (R : countDecFieldType) := DecidableField.on R^o. HB.instance Definition _ (R : countClosedFieldType) := ClosedField.on R^o. End ReguralExports. HB.export ReguralExports. End CountRing. Import CountRing. HB.reexport. #[deprecated(since="mathcomp 2.4.0", note="Use countNzSemiRingType instead.")] Notation countSemiRingType := (countNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countNzRingType instead.")] Notation countRingType := (countNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countComNzSemiRingType instead.")] Notation countComSemiRingType := (countComNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countComNzRingType instead.")] Notation countComRingType := (countComNzRingType) (only parsing).
all_boot.v
Require Export ssreflect. Require Export ssrbool. Require Export ssrfun. Require Export eqtype. Require Export ssrnat. Require Export seq. Require Export choice. Require Export monoid. Require Export nmodule. Require Export path. Require Export div. Require Export fintype. Require Export fingraph. Require Export tuple. Require Export finfun. Require Export bigop. Require Export prime. Require Export finset. Require Export binomial. Require Export generic_quotient. Require Export ssrAC.
perm.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 tuple finfun bigop finset binomial. From mathcomp Require Import fingroup morphism. (******************************************************************************) (* This file contains the definition and properties associated to the group *) (* of permutations of an arbitrary finite type. *) (* {perm T} == the type of permutations of a finite type T, i.e., *) (* injective (finite) functions from T to T. Permutations *) (* coerce to CiC functions. *) (* 'S_n == the set of all permutations of 'I_n, i.e., of *) (* {0,.., n-1} *) (* perm_on A u == u is a permutation with support A, i.e., u only *) (* displaces elements of A (u x != x implies x \in A). *) (* tperm x y == the transposition of x, y. *) (* aperm x s == the image of x under the action of the permutation s. *) (* := s x *) (* cast_perm Emn s == the 'S_m permutation cast as a 'S_n permutation using *) (* Emn : m = n *) (* porbit s x == the set of all elements that are in the same cycle of *) (* the permutation s as x, i.e., {x, s x, (s ^+ 2) x, ...}.*) (* porbits s == the set of all the cycles of the permutation s. *) (* (s : bool) == s is an odd permutation (the coercion is called *) (* odd_perm). *) (* dpair u == u is a pair (x, y) of distinct objects (i.e., x != y). *) (* Sym S == the set of permutations with support S *) (* lift_perm i j s == the permutation obtained by lifting s : 'S_n.-1 over *) (* (i |-> j), that maps i to j and lift i k to *) (* lift j (s k). *) (* Canonical structures are defined allowing permutations to be an eqType, *) (* choiceType, countType, finType, subType, finGroupType; permutations with *) (* composition form a group, therefore inherit all generic group notations: *) (* 1 == identity permutation, * == composition, ^-1 == inverse permutation. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section PermDefSection. Variable T : finType. Inductive perm_type : predArgType := Perm (pval : {ffun T -> T}) & injectiveb pval. Definition pval p := let: Perm f _ := p in f. Definition perm_of := perm_type. Identity Coercion type_of_perm : perm_of >-> perm_type. HB.instance Definition _ := [isSub for pval]. HB.instance Definition _ := [Finite of perm_type by <:]. Lemma perm_proof (f : T -> T) : injective f -> injectiveb (finfun f). Proof. by move=> f_inj; apply/injectiveP; apply: eq_inj f_inj _ => x; rewrite ffunE. Qed. End PermDefSection. Arguments perm_of T%_type. Notation "{ 'perm' T }" := (perm_of T) (format "{ 'perm' T }") : type_scope. Arguments pval _ _%_g. Bind Scope group_scope with perm_type. Bind Scope group_scope with perm_of. Notation "''S_' n" := {perm 'I_n} (at level 8, n at level 2, format "''S_' n"). HB.lock Definition perm T f injf := Perm (@perm_proof T f injf). Canonical perm_unlock := Unlockable perm.unlock. HB.lock Definition fun_of_perm T (u : perm_type T) : T -> T := val u. Canonical fun_of_perm_unlock := Unlockable fun_of_perm.unlock. Coercion fun_of_perm : perm_type >-> Funclass. Section Theory. Variable T : finType. Implicit Types (x y : T) (s t : {perm T}) (S : {set T}). Lemma permP s t : s =1 t <-> s = t. Proof. by split=> [| -> //]; rewrite unlock => eq_sv; apply/val_inj/ffunP. Qed. Lemma pvalE s : pval s = s :> (T -> T). Proof. by rewrite [@fun_of_perm]unlock. Qed. Lemma permE f f_inj : @perm T f f_inj =1 f. Proof. by move=> x; rewrite -pvalE [@perm]unlock ffunE. Qed. Lemma perm_inj {s} : injective s. Proof. by rewrite -!pvalE; apply: (injectiveP _ (valP s)). Qed. Hint Resolve perm_inj : core. Lemma perm_onto s : codom s =i predT. Proof. by apply/subset_cardP; rewrite ?card_codom ?subset_predT. Qed. Definition perm_one := perm (@inj_id T). Lemma perm_invK s : cancel (fun x => iinv (perm_onto s x)) s. Proof. by move=> x /=; rewrite f_iinv. Qed. Definition perm_inv s := perm (can_inj (perm_invK s)). Definition perm_mul s t := perm (inj_comp (@perm_inj t) (@perm_inj s)). Lemma perm_oneP : left_id perm_one perm_mul. Proof. by move=> s; apply/permP => x; rewrite permE /= permE. Qed. Lemma perm_invP : left_inverse perm_one perm_inv perm_mul. Proof. by move=> s; apply/permP=> x; rewrite !permE /= permE f_iinv. Qed. Lemma perm_mulP : associative perm_mul. Proof. by move=> s t u; apply/permP=> x; do !rewrite permE /=. Qed. HB.instance Definition _ := isMulGroup.Build (perm_type T) perm_mulP perm_oneP perm_invP. Lemma perm1 x : (1 : {perm T}) x = x. Proof. by rewrite permE. Qed. Lemma permM s t x : (s * t) x = t (s x). Proof. by rewrite permE. Qed. Lemma permK s : cancel s s^-1. Proof. by move=> x; rewrite -permM mulgV perm1. Qed. Lemma permKV s : cancel s^-1 s. Proof. by have:= permK s^-1; rewrite invgK. Qed. Lemma permJ s t x : (s ^ t) (t x) = t (s x). Proof. by rewrite !permM permK. Qed. Lemma permX s x n : (s ^+ n) x = iter n s x. Proof. by elim: n => [|n /= <-]; rewrite ?perm1 // -permM expgSr. Qed. Lemma permX_fix s x n : s x = x -> (s ^+ n) x = x. Proof. move=> Hs; elim: n => [|n IHn]; first by rewrite expg0 perm1. by rewrite expgS permM Hs. Qed. Lemma im_permV s S : s^-1 @: S = s @^-1: S. Proof. exact: can2_imset_pre (permKV s) (permK s). Qed. Lemma preim_permV s S : s^-1 @^-1: S = s @: S. Proof. by rewrite -im_permV invgK. Qed. Definition perm_on S : pred {perm T} := fun s => [pred x | s x != x] \subset S. Lemma perm_closed S s x : perm_on S s -> (s x \in S) = (x \in S). Proof. move/subsetP=> s_on_S; have [-> // | nfix_s_x] := eqVneq (s x) x. by rewrite !s_on_S // inE /= ?(inj_eq perm_inj). Qed. Lemma perm_on1 H : perm_on H 1. Proof. by apply/subsetP=> x; rewrite inE /= perm1 eqxx. Qed. Lemma perm_onM H s t : perm_on H s -> perm_on H t -> perm_on H (s * t). Proof. move/subsetP=> sH /subsetP tH; apply/subsetP => x; rewrite inE /= permM. by have [-> /tH | /sH] := eqVneq (s x) x. Qed. Lemma perm_onV H s : perm_on H s -> perm_on H s^-1. Proof. move=> /subsetP sH; apply/subsetP => i /[!inE] sVi; apply: sH; rewrite inE. by apply: contra_neq sVi => si_id; rewrite -[in LHS]si_id permK. Qed. Lemma out_perm S u x : perm_on S u -> x \notin S -> u x = x. Proof. by move=> uS; apply: contraNeq (subsetP uS x). Qed. Lemma im_perm_on u S : perm_on S u -> u @: S = S. Proof. move=> Su; rewrite -preim_permV; apply/setP=> x. by rewrite !inE -(perm_closed _ Su) permKV. Qed. Lemma perm_on_id u S : perm_on S u -> #|S| <= 1 -> u = 1%g. Proof. rewrite leq_eqVlt ltnS leqn0 => pSu S10; apply/permP => t; rewrite perm1. case/orP : S10; last first. by move/eqP/cards0_eq => S0; apply: (out_perm pSu); rewrite S0 inE. move=> /cards1P[x Sx]. have [-> | ntx] := eqVneq t x; last by apply: (out_perm pSu); rewrite Sx inE. by apply/eqP; have := perm_closed x pSu; rewrite Sx !inE => ->. Qed. Lemma perm_onC (S1 S2 : {set T}) (u1 u2 : {perm T}) : perm_on S1 u1 -> perm_on S2 u2 -> [disjoint S1 & S2] -> commute u1 u2. Proof. move=> pS1 pS2 S12; apply/permP => t; rewrite !permM. case/boolP : (t \in S1) => tS1. have /[!disjoint_subset] /subsetP {}S12 := S12. by rewrite !(out_perm pS2) //; apply: S12; rewrite // perm_closed. case/boolP : (t \in S2) => tS2. have /[1!disjoint_sym] /[!disjoint_subset] /subsetP {}S12 := S12. by rewrite !(out_perm pS1) //; apply: S12; rewrite // perm_closed. by rewrite (out_perm pS1) // (out_perm pS2) // (out_perm pS1). Qed. Lemma imset_perm1 (S : {set T}) : [set (1 : {perm T}) x | x in S] = S. Proof. apply: im_perm_on; exact: perm_on1. Qed. Lemma tperm_proof x y : involutive [fun z => z with x |-> y, y |-> x]. Proof. move=> z /=; case: (z =P x) => [-> | ne_zx]; first by rewrite eqxx; case: eqP. by case: (z =P y) => [->| ne_zy]; [rewrite eqxx | do 2?case: eqP]. Qed. Definition tperm x y := perm (can_inj (tperm_proof x y)). Variant tperm_spec x y z : T -> Type := | TpermFirst of z = x : tperm_spec x y z y | TpermSecond of z = y : tperm_spec x y z x | TpermNone of z <> x & z <> y : tperm_spec x y z z. Lemma tpermP x y z : tperm_spec x y z (tperm x y z). Proof. by rewrite permE /=; do 2?[case: eqP => /=]; constructor; auto. Qed. Lemma tpermL x y : tperm x y x = y. Proof. by case: tpermP. Qed. Lemma tpermR x y : tperm x y y = x. Proof. by case: tpermP. Qed. Lemma tpermD x y z : x != z -> y != z -> tperm x y z = z. Proof. by case: tpermP => // ->; rewrite eqxx. Qed. Lemma tpermC x y : tperm x y = tperm y x. Proof. by apply/permP => z; do 2![case: tpermP => //] => ->. Qed. Lemma tperm1 x : tperm x x = 1. Proof. by apply/permP => z; rewrite perm1; case: tpermP. Qed. Lemma tpermK x y : involutive (tperm x y). Proof. by move=> z; rewrite !permE tperm_proof. Qed. Lemma tpermKg x y : involutive (mulg (tperm x y)). Proof. by move=> s; apply/permP=> z; rewrite !permM tpermK. Qed. Lemma tpermV x y : (tperm x y)^-1 = tperm x y. Proof. by set t := tperm x y; rewrite -{2}(mulgK t t) -mulgA tpermKg. Qed. Lemma tperm2 x y : tperm x y * tperm x y = 1. Proof. by rewrite -{1}tpermV mulVg. Qed. Lemma tperm_on x y : perm_on [set x; y] (tperm x y). Proof. by apply/subsetP => z /[!inE]; case: tpermP => [->|->|]; rewrite eqxx // orbT. Qed. Lemma card_perm A : #|perm_on A| = (#|A|)`!. Proof. pose ffA := {ffun {x | x \in A} -> T}. rewrite -ffactnn -{2}(card_sig [in A]) /= -card_inj_ffuns_on. pose fT (f : ffA) := [ffun x => oapp f x (insub x)]. pose pfT f := insubd (1 : {perm T}) (fT f). pose fA s : ffA := [ffun u => s (val u)]. rewrite -!sum1dep_card -sum1_card (reindex_onto fA pfT) => [|f]. apply: eq_bigl => p; rewrite andbC; apply/idP/and3P=> [onA | []]; first split. - apply/eqP; suffices fTAp: fT (fA p) = pval p. by apply/permP=> x; rewrite -!pvalE insubdK fTAp //; apply: (valP p). apply/ffunP=> x; rewrite ffunE pvalE. by case: insubP => [u _ <- | /out_perm->] //=; rewrite ffunE. - by apply/forallP=> [[x Ax]]; rewrite ffunE /= perm_closed. - by apply/injectiveP=> u v; rewrite !ffunE => /perm_inj; apply: val_inj. move/eqP=> <- _ _; apply/subsetP=> x; rewrite !inE -pvalE val_insubd fun_if. by rewrite if_arg ffunE; case: insubP; rewrite // pvalE perm1 if_same eqxx. case/andP=> /forallP-onA /injectiveP-f_inj. apply/ffunP=> u; rewrite ffunE -pvalE insubdK; first by rewrite ffunE valK. apply/injectiveP=> {u} x y; rewrite !ffunE. case: insubP => [u _ <-|]; case: insubP => [v _ <-|] //=; first by move/f_inj->. by move=> Ay' def_y; rewrite -def_y [_ \in A]onA in Ay'. by move=> Ax' def_x; rewrite def_x [_ \in A]onA in Ax'. Qed. End Theory. Prenex Implicits tperm permK permKV tpermK. Arguments perm_inj {T s} [x1 x2] eq_sx12. (* Shorthand for using a permutation to reindex a bigop. *) Notation reindex_perm s := (reindex_inj (@perm_inj _ s)). Lemma inj_tperm (T T' : finType) (f : T -> T') x y z : injective f -> f (tperm x y z) = tperm (f x) (f y) (f z). Proof. by move=> injf; rewrite !permE /= !(inj_eq injf) !(fun_if f). Qed. Section tpermJ. Variables (T : finType). Implicit Types (x y z : T) (s : {perm T}). Lemma tpermJ x y s : (tperm x y) ^ s = tperm (s x) (s y). Proof. by apply/permP => z; rewrite -(permKV s z) permJ; apply/inj_tperm/perm_inj. Qed. Lemma tpermJ_tperm x y z : x != z -> y != z -> tperm x z ^ tperm x y = tperm y z. Proof. by move=> nxz nyz; rewrite tpermJ tpermL [tperm _ _ z]tpermD. Qed. End tpermJ. Lemma tuple_permP {T : eqType} {n} {s : seq T} {t : n.-tuple T} : reflect (exists p : 'S_n, s = [tuple tnth t (p i) | i < n]) (perm_eq s t). Proof. apply: (iffP idP) => [|[p ->]]; last first. rewrite /= (map_comp (tnth t)) -{1}(map_tnth_enum t) perm_map //. apply: uniq_perm => [||i]; rewrite ?enum_uniq //. by apply/injectiveP; apply: perm_inj. by rewrite mem_enum -[i](permKV p) image_f. case: n => [|n] in t *; last have x0 := tnth t ord0. rewrite tuple0 => /perm_small_eq-> //. by exists 1; rewrite [mktuple _]tuple0. case/(perm_iotaP x0); rewrite size_tuple => Is eqIst ->{s}. have uniqIs: uniq Is by rewrite (perm_uniq eqIst) iota_uniq. have szIs: size Is == n.+1 by rewrite (perm_size eqIst) !size_tuple. have pP i : tnth (Tuple szIs) i < n.+1. by rewrite -[_ < _](mem_iota 0) -(perm_mem eqIst) mem_tnth. have inj_p: injective (fun i => Ordinal (pP i)). by apply/injectiveP/(@map_uniq _ _ val); rewrite -map_comp map_tnth_enum. exists (perm inj_p); rewrite -[Is]/(tval (Tuple szIs)); congr (tval _). by apply: eq_from_tnth => i; rewrite tnth_map tnth_mktuple permE (tnth_nth x0). Qed. (* Note that porbit s x is the orbit of x by <[s]> under the action aperm. *) (* Hence, the porbit lemmas below are special cases of more general lemmas *) (* on orbits that will be stated in action.v. *) (* Defining porbit directly here avoids a dependency of matrix.v on *) (* action.v and hence morphism.v. *) Definition aperm (T : finType) x (s : {perm T}) := s x. HB.lock Definition porbit (T : finType) (s : {perm T}) x := aperm x @: <[s]>. Canonical porbit_unlockable := Unlockable porbit.unlock. Definition porbits (T : finType) (s : {perm T}) := porbit s @: T. Section PermutationParity. Variable T : finType. Implicit Types (s t u v : {perm T}) (x y z a b : T). Definition odd_perm (s : perm_type T) := odd #|T| (+) odd #|porbits s|. Lemma apermE x s : aperm x s = s x. Proof. by []. Qed. Lemma mem_porbit s i x : (s ^+ i) x \in porbit s x. Proof. by rewrite [@porbit]unlock (imset_f (aperm x)) ?mem_cycle. Qed. Lemma porbit_id s x : x \in porbit s x. Proof. by rewrite -{1}[x]perm1 (mem_porbit s 0). Qed. Lemma card_porbit_neq0 s x : #|porbit s x| != 0. Proof. by rewrite -lt0n card_gt0; apply/set0Pn; exists x; exact: porbit_id. Qed. Lemma uniq_traject_porbit s x : uniq (traject s x #|porbit s x|). Proof. case def_n: #|_| => // [n]; rewrite looping_uniq. apply: contraL (card_size (traject s x n)) => /loopingP t_sx. rewrite -ltnNge size_traject -def_n ?subset_leq_card // porbit.unlock. by apply/subsetP=> _ /imsetP[_ /cycleP[i ->] ->]; rewrite /aperm permX t_sx. Qed. Lemma porbit_traject s x : porbit s x =i traject s x #|porbit s x|. Proof. apply: fsym; apply/subset_cardP. by rewrite (card_uniqP _) ?size_traject ?uniq_traject_porbit. by apply/subsetP=> _ /trajectP[i _ ->]; rewrite -permX mem_porbit. Qed. Lemma iter_porbit s x : iter #|porbit s x| s x = x. Proof. case def_n: #|_| (uniq_traject_porbit s x) => [//|n] Ut. have: looping s x n.+1. by rewrite -def_n -[looping _ _ _]porbit_traject -permX mem_porbit. rewrite /looping => /trajectP[[|i] //= lt_i_n /perm_inj eq_i_n_sx]. move: lt_i_n; rewrite ltnS ltn_neqAle andbC => /andP[le_i_n /negP[]]. by rewrite -(nth_uniq x _ _ Ut) ?size_traject ?nth_traject // eq_i_n_sx. Qed. Lemma eq_porbit_mem s x y : (porbit s x == porbit s y) = (x \in porbit s y). Proof. apply/eqP/idP; first by move<-; exact: porbit_id. rewrite porbit.unlock => /imsetP[si s_si ->]. apply/setP => z; apply/imsetP/imsetP=> [] [sj s_sj ->]. by exists (si * sj); rewrite ?groupM /aperm ?permM. exists (si^-1 * sj); first by rewrite groupM ?groupV. by rewrite /aperm permM permK. Qed. Lemma porbit_sym s x y : (x \in porbit s y) = (y \in porbit s x). Proof. by rewrite -!eq_porbit_mem eq_sym. Qed. Lemma porbit_perm s i x : porbit s ((s ^+ i) x) = porbit s x. Proof. by apply/eqP; rewrite eq_porbit_mem mem_porbit. Qed. Lemma porbitPmin s x y : y \in porbit s x -> exists2 i, i < #[s] & y = (s ^+ i) x. Proof. by rewrite porbit.unlock=> /imsetP [z /cyclePmin[ i Hi ->{z}] ->{y}]; exists i. Qed. Lemma porbitP s x y : reflect (exists i, y = (s ^+ i) x) (y \in porbit s x). Proof. apply (iffP idP) => [/porbitPmin [i _ ->]| [i ->]]; last exact: mem_porbit. by exists i. Qed. Lemma porbitV s : porbit s^-1 =1 porbit s. Proof. move=> x; apply/setP => y; rewrite porbit_sym. by apply/porbitP/porbitP => -[i ->]; exists i; rewrite expgVn ?permK ?permKV. Qed. Lemma porbitsV s : porbits s^-1 = porbits s. Proof. rewrite /porbits; apply/setP => y. by apply/imsetP/imsetP => -[x _ ->{y}]; exists x; rewrite // porbitV. Qed. Lemma porbit_setP s t x : porbit s x =i porbit t x <-> porbit s x = porbit t x. Proof. by rewrite porbit.unlock; exact: setP. Qed. Lemma porbits_mul_tperm s x y : let t := tperm x y in #|porbits (t * s)| + (x \notin porbit s y).*2 = #|porbits s| + (x != y). Proof. pose xf a b u := seq.find (pred2 a b) (traject u (u a) #|porbit u a|). have xf_size a b u: xf a b u <= #|porbit u a|. by rewrite (leq_trans (find_size _ _)) ?size_traject. have lt_xf a b u n : n < xf a b u -> ~~ pred2 a b ((u ^+ n.+1) a). move=> lt_n; apply: contraFN (before_find (u a) lt_n). by rewrite permX iterSr nth_traject // (leq_trans lt_n). pose t a b u := tperm a b * u. have tC a b u : t a b u = t b a u by rewrite /t tpermC. have tK a b: involutive (t a b) by move=> u; apply: tpermKg. have tXC a b u n: n <= xf a b u -> (t a b u ^+ n.+1) b = (u ^+ n.+1) a. elim: n => [|n IHn] lt_n_f; first by rewrite permM tpermR. rewrite !(expgSr _ n.+1) !permM {}IHn 1?ltnW //; congr (u _). by case/lt_xf/norP: lt_n_f => ne_a ne_b; rewrite tpermD // eq_sym. have eq_xf a b u: pred2 a b ((u ^+ (xf a b u).+1) a). have ua_a: a \in porbit u (u a) by rewrite porbit_sym (mem_porbit _ 1). have has_f: has (pred2 a b) (traject u (u a) #|porbit u (u a)|). by apply/hasP; exists a; rewrite /= ?eqxx -?porbit_traject. have:= nth_find (u a) has_f; rewrite has_find size_traject in has_f. rewrite -eq_porbit_mem in ua_a. by rewrite nth_traject // -iterSr -permX -(eqP ua_a). have xfC a b u: xf b a (t a b u) = xf a b u. without loss lt_a: a b u / xf b a (t a b u) < xf a b u. move=> IHab; set m := xf b a _; set n := xf a b u. by case: (ltngtP m n) => // ltx; [apply: IHab | rewrite -[m]IHab tC tK]. by move/lt_xf: (lt_a); rewrite -(tXC a b) 1?ltnW //= orbC [_ || _]eq_xf. pose ts := t x y s; rewrite /= -[_ * s]/ts. pose dp u := #|porbits u :\ porbit u y :\ porbit u x|. rewrite !(addnC #|_|) (cardsD1 (porbit ts y)) imset_f ?inE //. rewrite (cardsD1 (porbit ts x)) inE imset_f ?inE //= -/(dp ts) {}/ts. rewrite (cardsD1 (porbit s y)) (cardsD1 (porbit s x)) !(imset_f, inE) //. rewrite -/(dp s) !addnA !eq_porbit_mem andbT; congr (_ + _); last first. wlog suffices: s / dp s <= dp (t x y s). by move=> IHs; apply/eqP; rewrite eqn_leq -{2}(tK x y s) !IHs. apply/subset_leq_card/subsetP=> {dp} C. rewrite !inE andbA andbC !(eq_sym C) => /and3P[/imsetP[z _ ->{C}]]. rewrite 2!eq_porbit_mem => sxz syz. suffices ts_z: porbit (t x y s) z = porbit s z. by rewrite -ts_z !eq_porbit_mem {1 2}ts_z sxz syz imset_f ?inE. suffices exp_id n: ((t x y s) ^+ n) z = (s ^+ n) z. apply/porbit_setP => u; apply/idP/idP=> /porbitP[i ->]. by rewrite /aperm exp_id mem_porbit. by rewrite /aperm -exp_id mem_porbit. elim: n => // n IHn; rewrite !expgSr !permM {}IHn tpermD //. by apply: contraNneq sxz => ->; apply: mem_porbit. by apply: contraNneq syz => ->; apply: mem_porbit. case: eqP {dp} => [<- | ne_xy]; first by rewrite /t tperm1 mul1g porbit_id. suff ->: (x \in porbit (t x y s) y) = (x \notin porbit s y) by case: (x \in _). without loss xf_x: s x y ne_xy / (s ^+ (xf x y s).+1) x = x. move=> IHs; have ne_yx := nesym ne_xy; have:= eq_xf x y s; set n := xf x y s. case/pred2P=> [|snx]; first exact: IHs. by rewrite -[x \in _]negbK ![x \in _]porbit_sym -{}IHs ?xfC ?tXC // tC tK. rewrite -{1}xf_x -(tXC _ _ _ _ (leqnn _)) mem_porbit; symmetry. rewrite -eq_porbit_mem eq_sym eq_porbit_mem porbit_traject. apply/trajectP=> [[n _ snx]]. have: looping s x (xf x y s).+1 by rewrite /looping -permX xf_x inE eqxx. move/loopingP/(_ n); rewrite -{n}snx. case/trajectP=> [[_|i]]; first exact: nesym; rewrite ltnS -permX => lt_i def_y. by move/lt_xf: lt_i; rewrite def_y /= eqxx orbT. Qed. Lemma odd_perm1 : odd_perm 1 = false. Proof. rewrite /odd_perm card_imset ?addbb // => x y; move/eqP; rewrite eq_porbit_mem. by rewrite porbit.unlock cycle1 imset_set1 /aperm perm1 inE=> /eqP. Qed. Lemma odd_mul_tperm x y s : odd_perm (tperm x y * s) = (x != y) (+) odd_perm s. Proof. rewrite addbC -addbA -[~~ _]oddb -oddD -porbits_mul_tperm. by rewrite oddD odd_double addbF. Qed. Lemma odd_tperm x y : odd_perm (tperm x y) = (x != y). Proof. by rewrite -[_ y]mulg1 odd_mul_tperm odd_perm1 addbF. Qed. Definition dpair (eT : eqType) := [pred t | t.1 != t.2 :> eT]. Arguments dpair {eT}. Lemma prod_tpermP s : {ts : seq (T * T) | s = \prod_(t <- ts) tperm t.1 t.2 & all dpair ts}. Proof. have [n] := ubnP #|[pred x | s x != x]|; elim: n s => // n IHn s /ltnSE-le_s_n. case: (pickP (fun x => s x != x)) => [x s_x | s_id]; last first. exists nil; rewrite // big_nil; apply/permP=> x. by apply/eqP/idPn; rewrite perm1 s_id. have [|ts def_s ne_ts] := IHn (tperm x (s^-1 x) * s); last first. exists ((x, s^-1 x) :: ts); last by rewrite /= -(canF_eq (permK _)) s_x. by rewrite big_cons -def_s mulgA tperm2 mul1g. rewrite (cardD1 x) !inE s_x in le_s_n; apply: leq_ltn_trans le_s_n. apply: subset_leq_card; apply/subsetP=> y. rewrite !inE permM permE /= -(canF_eq (permK _)). have [-> | ne_yx] := eqVneq y x; first by rewrite permKV eqxx. by case: (s y =P x) => // -> _; rewrite eq_sym. Qed. Lemma odd_perm_prod ts : all dpair ts -> odd_perm (\prod_(t <- ts) tperm t.1 t.2) = odd (size ts). Proof. elim: ts => [_|t ts IHts] /=; first by rewrite big_nil odd_perm1. by case/andP=> dt12 dts; rewrite big_cons odd_mul_tperm dt12 IHts. Qed. Lemma odd_permM : {morph odd_perm : s1 s2 / s1 * s2 >-> s1 (+) s2}. Proof. move=> s1 s2; case: (prod_tpermP s1) => ts1 ->{s1} dts1. case: (prod_tpermP s2) => ts2 ->{s2} dts2. by rewrite -big_cat !odd_perm_prod ?all_cat ?dts1 // size_cat oddD. Qed. Lemma odd_permV s : odd_perm s^-1 = odd_perm s. Proof. by rewrite -{2}(mulgK s s) !odd_permM -addbA addKb. Qed. Lemma odd_permJ s1 s2 : odd_perm (s1 ^ s2) = odd_perm s1. Proof. by rewrite !odd_permM odd_permV addbC addbK. Qed. Lemma gen_tperm x : <<[set tperm x y | y in T]>>%g = [set: {perm T}]. Proof. apply/eqP; rewrite eqEsubset subsetT/=; apply/subsetP => s _. have [ts -> _] := prod_tpermP s; rewrite group_prod// => -[/= y z] _. have [<-|Nyz] := eqVneq y z; first by rewrite tperm1 group1. have [<-|Nxz] := eqVneq x z; first by rewrite tpermC mem_gen ?imset_f. by rewrite -(tpermJ_tperm Nxz Nyz) groupJ ?mem_gen ?imset_f. Qed. End PermutationParity. Coercion odd_perm : perm_type >-> bool. Arguments dpair {eT}. Prenex Implicits porbit dpair porbits aperm. Section Symmetry. Variables (T : finType) (S : {set T}). Definition Sym : {set {perm T}} := [set s | perm_on S s]. Lemma Sym_group_set : group_set Sym. Proof. apply/group_setP; split => [|s t] /[!inE]; [exact: perm_on1 | exact: perm_onM]. Qed. Canonical Sym_group : {group {perm T}} := Group Sym_group_set. Lemma card_Sym : #|Sym| = #|S|`!. Proof. by rewrite cardsE /= card_perm. Qed. End Symmetry. Section LiftPerm. (* Somewhat more specialised constructs for permutations on ordinals. *) Variable n : nat. Implicit Types i j : 'I_n.+1. Implicit Types s t : 'S_n. Lemma card_Sn : #|'S_(n)| = n`!. Proof. rewrite (eq_card (B := perm_on [set : 'I_n])). by rewrite card_perm /= cardsE /= card_ord. move=> p; rewrite inE unfold_in /perm_on /=. by apply/esym/subsetP => i _; rewrite in_set. Qed. Definition lift_perm_fun i j s k := if unlift i k is Some k' then lift j (s k') else j. Lemma lift_permK i j s : cancel (lift_perm_fun i j s) (lift_perm_fun j i s^-1). Proof. rewrite /lift_perm_fun => k. by case: (unliftP i k) => [j'|] ->; rewrite (liftK, unlift_none) ?permK. Qed. Definition lift_perm i j s := perm (can_inj (lift_permK i j s)). Lemma lift_perm_id i j s : lift_perm i j s i = j. Proof. by rewrite permE /lift_perm_fun unlift_none. Qed. Lemma lift_perm_lift i j s k' : lift_perm i j s (lift i k') = lift j (s k') :> 'I_n.+1. Proof. by rewrite permE /lift_perm_fun liftK. Qed. Lemma lift_permM i j k s t : lift_perm i j s * lift_perm j k t = lift_perm i k (s * t). Proof. apply/permP=> i1; case: (unliftP i i1) => [i2|] ->{i1}. by rewrite !(permM, lift_perm_lift). by rewrite permM !lift_perm_id. Qed. Lemma lift_perm1 i : lift_perm i i 1 = 1. Proof. by apply: (mulgI (lift_perm i i 1)); rewrite lift_permM !mulg1. Qed. Lemma lift_permV i j s : (lift_perm i j s)^-1 = lift_perm j i s^-1. Proof. by apply/eqP; rewrite eq_invg_mul lift_permM mulgV lift_perm1. Qed. Lemma odd_lift_perm i j s : lift_perm i j s = odd i (+) odd j (+) s :> bool. Proof. rewrite -{1}(mul1g s) -(lift_permM _ j) odd_permM. congr (_ (+) _); last first. case: (prod_tpermP s) => ts ->{s} _. elim: ts => [|t ts IHts] /=; first by rewrite big_nil lift_perm1 !odd_perm1. rewrite big_cons odd_mul_tperm -(lift_permM _ j) odd_permM {}IHts //. congr (_ (+) _); transitivity (tperm (lift j t.1) (lift j t.2)); last first. by rewrite odd_tperm (inj_eq (pcan_inj (liftK j))). congr odd_perm; apply/permP=> k; case: (unliftP j k) => [k'|] ->. by rewrite lift_perm_lift inj_tperm //; apply: lift_inj. by rewrite lift_perm_id tpermD // eq_sym neq_lift. suff{i j s} odd_lift0 (k : 'I_n.+1): lift_perm ord0 k 1 = odd k :> bool. rewrite -!odd_lift0 -{2}invg1 -lift_permV odd_permV -odd_permM. by rewrite lift_permM mulg1. elim: {k}(k : nat) {1 3}k (erefl (k : nat)) => [|m IHm] k def_k. by rewrite (_ : k = ord0) ?lift_perm1 ?odd_perm1 //; apply: val_inj. have le_mn: m < n.+1 by [rewrite -def_k ltnW]; pose j := Ordinal le_mn. rewrite -(mulg1 1)%g -(lift_permM _ j) odd_permM {}IHm // addbC. rewrite (_ : _ 1 = tperm j k); first by rewrite odd_tperm neq_ltn/= def_k leqnn. apply/permP=> i; case: (unliftP j i) => [i'|] ->; last first. by rewrite lift_perm_id tpermL. apply: ord_inj; rewrite lift_perm_lift !permE /= eq_sym -if_neg neq_lift. rewrite fun_if -val_eqE /= def_k /bump ltn_neqAle andbC. case: leqP => [_ | lt_i'm] /=; last by rewrite -if_neg neq_ltn leqW. by rewrite add1n eqSS; case: eqVneq. Qed. End LiftPerm. Prenex Implicits lift_perm lift_permK. Lemma permS0 : all_equal_to (1 : 'S_0). Proof. by move=> g; apply/permP; case. Qed. Lemma permS1 : all_equal_to (1 : 'S_1). Proof. by move=> g; apply/permP => i; rewrite !ord1. Qed. Lemma permS01 n : n <= 1 -> all_equal_to (1 : 'S_n). Proof. by case: n => [|[|]//=] _ g; rewrite (permS0, permS1). Qed. Section CastSn. Definition cast_perm m n (eq_mn : m = n) (s : 'S_m) := let: erefl in _ = n := eq_mn return 'S_n in s. Lemma cast_perm_id n eq_n s : cast_perm eq_n s = s :> 'S_n. Proof. by apply/permP => i; rewrite /cast_perm /= eq_axiomK. Qed. Lemma cast_ord_permE m n eq_m_n (s : 'S_m) i : @cast_ord m n eq_m_n (s i) = (cast_perm eq_m_n s) (cast_ord eq_m_n i). Proof. by subst m; rewrite cast_perm_id !cast_ord_id. Qed. Lemma cast_permE m n (eq_m_n : m = n) (s : 'S_m) (i : 'I_n) : cast_perm eq_m_n s i = cast_ord eq_m_n (s (cast_ord (esym eq_m_n) i)). Proof. by rewrite cast_ord_permE cast_ordKV. Qed. Lemma cast_perm_comp m n p (eq_m_n : m = n) (eq_n_p : n = p) s : cast_perm eq_n_p (cast_perm eq_m_n s) = cast_perm (etrans eq_m_n eq_n_p) s. Proof. by case: _ / eq_n_p. Qed. Lemma cast_permK m n eq_m_n : cancel (@cast_perm m n eq_m_n) (cast_perm (esym eq_m_n)). Proof. by subst m. Qed. Lemma cast_permKV m n eq_m_n : cancel (cast_perm (esym eq_m_n)) (@cast_perm m n eq_m_n). Proof. by subst m. Qed. Lemma cast_perm_sym m n (eq_m_n : m = n) s t : s = cast_perm eq_m_n t -> t = cast_perm (esym eq_m_n) s. Proof. by move/(canLR (cast_permK _)). Qed. Lemma cast_perm_inj m n eq_m_n : injective (@cast_perm m n eq_m_n). Proof. exact: can_inj (cast_permK eq_m_n). Qed. Lemma cast_perm_morphM m n eq_m_n : {morph @cast_perm m n eq_m_n : x y / x * y >-> x * y}. Proof. by subst m. Qed. Canonical morph_of_cast_perm m n eq_m_n := @Morphism _ _ setT (cast_perm eq_m_n) (in2W (@cast_perm_morphM m n eq_m_n)). Lemma isom_cast_perm m n eq_m_n : isom setT setT (@cast_perm m n eq_m_n). Proof. case: {n} _ / eq_m_n; apply/isomP; split. exact/injmP/(in2W (@cast_perm_inj _ _ _)). by apply/setP => /= s /[!inE]; apply/imsetP; exists s; rewrite ?inE. Qed. End CastSn.
MeanInequalities.lean
/- Copyright (c) 2020 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.MeanInequalities import Mathlib.Analysis.MeanInequalitiesPow import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Add /-! # Mean value inequalities for integrals In this file we prove several inequalities on integrals, notably the Hölder inequality and the Minkowski inequality. The versions for finite sums are in `Analysis.MeanInequalities`. ## Main results Hölder's inequality for the Lebesgue integral of `ℝ≥0∞` and `ℝ≥0` functions: we prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents and `α → (E)NNReal` functions in two cases, * `ENNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions, * `NNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0 functions. `ENNReal.lintegral_mul_norm_pow_le` is a variant where the exponents are not reciprocals: `∫ (f ^ p * g ^ q) ∂μ ≤ (∫ f ∂μ) ^ p * (∫ g ∂μ) ^ q` where `p, q ≥ 0` and `p + q = 1`. `ENNReal.lintegral_prod_norm_pow_le` generalizes this to a finite family of functions: `∫ (∏ i, f i ^ p i) ∂μ ≤ ∏ i, (∫ f i ∂μ) ^ p i` when the `p` is a collection of nonnegative weights with sum 1. Minkowski's inequality for the Lebesgue integral of measurable functions with `ℝ≥0∞` values: we prove `(∫ (f + g)^p ∂μ) ^ (1/p) ≤ (∫ f^p ∂μ) ^ (1/p) + (∫ g^p ∂μ) ^ (1/p)` for `1 ≤ p`. -/ section LIntegral /-! ### Hölder's inequality for the Lebesgue integral of ℝ≥0∞ and ℝ≥0 functions We prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents and `α → (E)NNReal` functions in several cases, the first two being useful only to prove the more general results: * `ENNReal.lintegral_mul_le_one_of_lintegral_rpow_eq_one` : ℝ≥0∞ functions for which the integrals on the right are equal to 1, * `ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top` : ℝ≥0∞ functions for which the integrals on the right are neither ⊤ nor 0, * `ENNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions, * `NNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0 functions. -/ noncomputable section open NNReal ENNReal MeasureTheory Finset variable {α : Type*} [MeasurableSpace α] {μ : Measure α} namespace ENNReal theorem lintegral_mul_le_one_of_lintegral_rpow_eq_one {p q : ℝ} (hpq : p.HolderConjugate q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_norm : ∫⁻ a, f a ^ p ∂μ = 1) (hg_norm : ∫⁻ a, g a ^ q ∂μ = 1) : (∫⁻ a, (f * g) a ∂μ) ≤ 1 := by calc (∫⁻ a : α, (f * g) a ∂μ) ≤ ∫⁻ a : α, f a ^ p / ENNReal.ofReal p + g a ^ q / ENNReal.ofReal q ∂μ := lintegral_mono fun a => young_inequality (f a) (g a) hpq _ = 1 := by simp only [div_eq_mul_inv] rw [lintegral_add_left'] · rw [lintegral_mul_const'' _ (hf.pow_const p), lintegral_mul_const', hf_norm, hg_norm, one_mul, one_mul, hpq.inv_add_inv_ennreal] simp [hpq.symm.pos] · exact (hf.pow_const _).mul_const _ /-- Function multiplied by the inverse of its p-seminorm `(∫⁻ f^p ∂μ) ^ 1/p` -/ def funMulInvSnorm (f : α → ℝ≥0∞) (p : ℝ) (μ : Measure α) : α → ℝ≥0∞ := fun a => f a * ((∫⁻ c, f c ^ p ∂μ) ^ (1 / p))⁻¹ theorem fun_eq_funMulInvSnorm_mul_eLpNorm {p : ℝ} (f : α → ℝ≥0∞) (hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) {a : α} : f a = funMulInvSnorm f p μ a * (∫⁻ c, f c ^ p ∂μ) ^ (1 / p) := by simp [funMulInvSnorm, mul_assoc, ENNReal.inv_mul_cancel, hf_nonzero, hf_top] theorem funMulInvSnorm_rpow {p : ℝ} (hp0 : 0 < p) {f : α → ℝ≥0∞} {a : α} : funMulInvSnorm f p μ a ^ p = f a ^ p * (∫⁻ c, f c ^ p ∂μ)⁻¹ := by rw [funMulInvSnorm, mul_rpow_of_nonneg _ _ (le_of_lt hp0)] suffices h_inv_rpow : ((∫⁻ c : α, f c ^ p ∂μ) ^ (1 / p))⁻¹ ^ p = (∫⁻ c : α, f c ^ p ∂μ)⁻¹ by rw [h_inv_rpow] rw [inv_rpow, ← rpow_mul, one_div_mul_cancel hp0.ne', rpow_one] theorem lintegral_rpow_funMulInvSnorm_eq_one {p : ℝ} (hp0_lt : 0 < p) {f : α → ℝ≥0∞} (hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) : ∫⁻ c, funMulInvSnorm f p μ c ^ p ∂μ = 1 := by simp_rw [funMulInvSnorm_rpow hp0_lt] rw [lintegral_mul_const', ENNReal.mul_inv_cancel hf_nonzero hf_top] rwa [inv_ne_top] /-- Hölder's inequality in case of finite non-zero integrals -/ theorem lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top {p q : ℝ} (hpq : p.HolderConjugate q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_nontop : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) (hg_nontop : (∫⁻ a, g a ^ q ∂μ) ≠ ⊤) (hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0) (hg_nonzero : (∫⁻ a, g a ^ q ∂μ) ≠ 0) : (∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by let npf := (∫⁻ c : α, f c ^ p ∂μ) ^ (1 / p) let nqg := (∫⁻ c : α, g c ^ q ∂μ) ^ (1 / q) calc (∫⁻ a : α, (f * g) a ∂μ) = ∫⁻ a : α, (funMulInvSnorm f p μ * funMulInvSnorm g q μ) a * (npf * nqg) ∂μ := by refine lintegral_congr fun a => ?_ rw [Pi.mul_apply, fun_eq_funMulInvSnorm_mul_eLpNorm f hf_nonzero hf_nontop, fun_eq_funMulInvSnorm_mul_eLpNorm g hg_nonzero hg_nontop, Pi.mul_apply] ring _ ≤ npf * nqg := by rw [lintegral_mul_const' (npf * nqg) _ (by simp [npf, nqg, hf_nontop, hg_nontop, hf_nonzero, hg_nonzero, ENNReal.mul_eq_top])] refine mul_le_of_le_one_left' ?_ have hf1 := lintegral_rpow_funMulInvSnorm_eq_one hpq.pos hf_nonzero hf_nontop have hg1 := lintegral_rpow_funMulInvSnorm_eq_one hpq.symm.pos hg_nonzero hg_nontop exact lintegral_mul_le_one_of_lintegral_rpow_eq_one hpq (hf.mul_const _) hf1 hg1 theorem ae_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_zero : ∫⁻ a, f a ^ p ∂μ = 0) : f =ᵐ[μ] 0 := by rw [lintegral_eq_zero_iff' (hf.pow_const p)] at hf_zero filter_upwards [hf_zero] with x rw [Pi.zero_apply, ← not_imp_not] exact fun hx => (rpow_pos_of_nonneg (pos_iff_ne_zero.2 hx) hp0).ne' theorem lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_zero : ∫⁻ a, f a ^ p ∂μ = 0) : (∫⁻ a, (f * g) a ∂μ) = 0 := by rw [← @lintegral_zero_fun α _ μ] refine lintegral_congr_ae ?_ suffices h_mul_zero : f * g =ᵐ[μ] 0 * g by rwa [zero_mul] at h_mul_zero have hf_eq_zero : f =ᵐ[μ] 0 := ae_eq_zero_of_lintegral_rpow_eq_zero hp0 hf hf_zero exact hf_eq_zero.mul (ae_eq_refl g) theorem lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top {p q : ℝ} (hp0_lt : 0 < p) (hq0 : 0 ≤ q) {f g : α → ℝ≥0∞} (hf_top : ∫⁻ a, f a ^ p ∂μ = ⊤) (hg_nonzero : (∫⁻ a, g a ^ q ∂μ) ≠ 0) : (∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by simp [*] /-- Hölder's inequality for functions `α → ℝ≥0∞`. The integral of the product of two functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate exponents. -/ theorem lintegral_mul_le_Lp_mul_Lq (μ : Measure α) {p q : ℝ} (hpq : p.HolderConjugate q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : (∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by by_cases hf_zero : ∫⁻ a, f a ^ p ∂μ = 0 · refine Eq.trans_le ?_ (zero_le _) exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.nonneg hf hf_zero by_cases hg_zero : ∫⁻ a, g a ^ q ∂μ = 0 · refine Eq.trans_le ?_ (zero_le _) rw [mul_comm] exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.symm.nonneg hg hg_zero by_cases hf_top : ∫⁻ a, f a ^ p ∂μ = ⊤ · exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.pos hpq.symm.nonneg hf_top hg_zero by_cases hg_top : ∫⁻ a, g a ^ q ∂μ = ⊤ · rw [mul_comm, mul_comm ((∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p))] exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.symm.pos hpq.nonneg hg_top hf_zero -- non-⊤ non-zero case exact ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top hpq hf hf_top hg_top hf_zero hg_zero /-- A different formulation of Hölder's inequality for two functions, with two exponents that sum to 1, instead of reciprocals of -/ theorem lintegral_mul_norm_pow_le {α} [MeasurableSpace α] {μ : Measure α} {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) (hpq : p + q = 1) : ∫⁻ a, f a ^ p * g a ^ q ∂μ ≤ (∫⁻ a, f a ∂μ) ^ p * (∫⁻ a, g a ∂μ) ^ q := by rcases hp.eq_or_lt with rfl | hp · rw [zero_add] at hpq simp [hpq] rcases hq.eq_or_lt with rfl | hq · rw [add_zero] at hpq simp [hpq] have h2p : 1 < 1 / p := by rw [one_div, one_lt_inv₀ hp] linarith have h2pq : (1 / p)⁻¹ + (1 / q)⁻¹ = 1 := by simp [hpq] have := ENNReal.lintegral_mul_le_Lp_mul_Lq μ (Real.holderConjugate_iff.mpr ⟨h2p, h2pq⟩) (hf.pow_const p) (hg.pow_const q) simpa [← ENNReal.rpow_mul, hp.ne', hq.ne'] using this /-- A version of Hölder with multiple arguments -/ theorem lintegral_prod_norm_pow_le {α ι : Type*} [MeasurableSpace α] {μ : Measure α} (s : Finset ι) {f : ι → α → ℝ≥0∞} (hf : ∀ i ∈ s, AEMeasurable (f i) μ) {p : ι → ℝ} (hp : ∑ i ∈ s, p i = 1) (h2p : ∀ i ∈ s, 0 ≤ p i) : ∫⁻ a, ∏ i ∈ s, f i a ^ p i ∂μ ≤ ∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ p i := by classical induction s using Finset.induction generalizing p with | empty => simp at hp | insert i₀ s hi₀ ih => rcases eq_or_ne (p i₀) 1 with h2i₀|h2i₀ · simp only [hi₀, not_false_eq_true, prod_insert] have h2p : ∀ i ∈ s, p i = 0 := by simpa [hi₀, h2i₀, sum_eq_zero_iff_of_nonneg (fun i hi ↦ h2p i <| mem_insert_of_mem hi)] using hp calc ∫⁻ a, f i₀ a ^ p i₀ * ∏ i ∈ s, f i a ^ p i ∂μ = ∫⁻ a, f i₀ a ^ p i₀ * ∏ i ∈ s, 1 ∂μ := by congr! 3 with x apply prod_congr rfl fun i hi ↦ by rw [h2p i hi, ENNReal.rpow_zero] _ ≤ (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * ∏ i ∈ s, 1 := by simp [h2i₀] _ = (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * ∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ p i := by congr 1 apply prod_congr rfl fun i hi ↦ by rw [h2p i hi, ENNReal.rpow_zero] · have hpi₀ : 0 ≤ 1 - p i₀ := by simp_rw [sub_nonneg, ← hp, single_le_sum h2p (mem_insert_self ..)] have h2pi₀ : 1 - p i₀ ≠ 0 := by rwa [sub_ne_zero, ne_comm] let q := fun i ↦ p i / (1 - p i₀) have hq : ∑ i ∈ s, q i = 1 := by rw [← Finset.sum_div, ← sum_insert_sub hi₀, hp, div_self h2pi₀] have h2q : ∀ i ∈ s, 0 ≤ q i := fun i hi ↦ div_nonneg (h2p i <| mem_insert_of_mem hi) hpi₀ calc ∫⁻ a, ∏ i ∈ insert i₀ s, f i a ^ p i ∂μ = ∫⁻ a, f i₀ a ^ p i₀ * ∏ i ∈ s, f i a ^ p i ∂μ := by simp [hi₀] _ = ∫⁻ a, f i₀ a ^ p i₀ * (∏ i ∈ s, f i a ^ q i) ^ (1 - p i₀) ∂μ := by simp [q, ← ENNReal.prod_rpow_of_nonneg hpi₀, ← ENNReal.rpow_mul, div_mul_cancel₀ (h := h2pi₀)] _ ≤ (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * (∫⁻ a, ∏ i ∈ s, f i a ^ q i ∂μ) ^ (1 - p i₀) := by apply ENNReal.lintegral_mul_norm_pow_le · exact hf i₀ <| mem_insert_self .. · exact s.aemeasurable_fun_prod fun i hi ↦ (hf i <| mem_insert_of_mem hi).pow_const _ · exact h2p i₀ <| mem_insert_self .. · exact hpi₀ · apply add_sub_cancel _ ≤ (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * (∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ q i) ^ (1 - p i₀) := by gcongr -- behavior of gcongr is heartbeat-dependent, which makes code really fragile... exact ih (fun i hi ↦ hf i <| mem_insert_of_mem hi) hq h2q _ = (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * ∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ p i := by simp [q, ← ENNReal.prod_rpow_of_nonneg hpi₀, ← ENNReal.rpow_mul, div_mul_cancel₀ (h := h2pi₀)] _ = ∏ i ∈ insert i₀ s, (∫⁻ a, f i a ∂μ) ^ p i := by simp [hi₀] /-- A version of Hölder with multiple arguments, one of which plays a distinguished role. -/ theorem lintegral_mul_prod_norm_pow_le {α ι : Type*} [MeasurableSpace α] {μ : Measure α} (s : Finset ι) {g : α → ℝ≥0∞} {f : ι → α → ℝ≥0∞} (hg : AEMeasurable g μ) (hf : ∀ i ∈ s, AEMeasurable (f i) μ) (q : ℝ) {p : ι → ℝ} (hpq : q + ∑ i ∈ s, p i = 1) (hq : 0 ≤ q) (hp : ∀ i ∈ s, 0 ≤ p i) : ∫⁻ a, g a ^ q * ∏ i ∈ s, f i a ^ p i ∂μ ≤ (∫⁻ a, g a ∂μ) ^ q * ∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ p i := by suffices ∫⁻ t, ∏ j ∈ insertNone s, Option.elim j (g t) (fun j ↦ f j t) ^ Option.elim j q p ∂μ ≤ ∏ j ∈ insertNone s, (∫⁻ t, Option.elim j (g t) (fun j ↦ f j t) ∂μ) ^ Option.elim j q p by simpa using this refine ENNReal.lintegral_prod_norm_pow_le _ ?_ ?_ ?_ · rintro (_ | i) hi · exact hg · refine hf i ?_ simpa using hi · simp_rw [sum_insertNone, Option.elim] exact hpq · rintro (_ | i) hi · exact hq · refine hp i ?_ simpa using hi theorem lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top {p : ℝ} {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_top : (∫⁻ a, f a ^ p ∂μ) < ⊤) (hg_top : (∫⁻ a, g a ^ p ∂μ) < ⊤) (hp1 : 1 ≤ p) : (∫⁻ a, (f + g) a ^ p ∂μ) < ⊤ := by have hp0_lt : 0 < p := lt_of_lt_of_le zero_lt_one hp1 have hp0 : 0 ≤ p := le_of_lt hp0_lt calc (∫⁻ a : α, (f a + g a) ^ p ∂μ) ≤ ∫⁻ a, (2 : ℝ≥0∞) ^ (p - 1) * f a ^ p + (2 : ℝ≥0∞) ^ (p - 1) * g a ^ p ∂μ := by refine lintegral_mono fun a => ?_ dsimp only have h_zero_lt_half_rpow : (0 : ℝ≥0∞) < (1 / 2 : ℝ≥0∞) ^ p := by rw [← ENNReal.zero_rpow_of_pos hp0_lt] exact ENNReal.rpow_lt_rpow (by simp) hp0_lt have h_rw : (1 / 2 : ℝ≥0∞) ^ p * (2 : ℝ≥0∞) ^ (p - 1) = 1 / 2 := by rw [sub_eq_add_neg, ENNReal.rpow_add _ _ two_ne_zero ENNReal.coe_ne_top, ← mul_assoc, ← ENNReal.mul_rpow_of_nonneg _ _ hp0, one_div, ENNReal.inv_mul_cancel two_ne_zero ENNReal.coe_ne_top, ENNReal.one_rpow, one_mul, ENNReal.rpow_neg_one] rw [← ENNReal.mul_le_mul_left (ne_of_lt h_zero_lt_half_rpow).symm _] · rw [mul_add, ← mul_assoc, ← mul_assoc, h_rw, ← ENNReal.mul_rpow_of_nonneg _ _ hp0, mul_add] refine ENNReal.rpow_arith_mean_le_arith_mean2_rpow (1 / 2 : ℝ≥0∞) (1 / 2 : ℝ≥0∞) (f a) (g a) ?_ hp1 rw [ENNReal.div_add_div_same, one_add_one_eq_two, ENNReal.div_self two_ne_zero ENNReal.coe_ne_top] · finiteness _ < ⊤ := by rw [lintegral_add_left', lintegral_const_mul'' _ (hf.pow_const p), lintegral_const_mul' _ _ (by finiteness), ENNReal.add_lt_top] · constructor <;> finiteness · fun_prop theorem lintegral_Lp_mul_le_Lq_mul_Lr {α} [MeasurableSpace α] {p q r : ℝ} (hp0_lt : 0 < p) (hpq : p < q) (hpqr : 1 / p = 1 / q + 1 / r) (μ : Measure α) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : (∫⁻ a, (f * g) a ^ p ∂μ) ^ (1 / p) ≤ (∫⁻ a, f a ^ q ∂μ) ^ (1 / q) * (∫⁻ a, g a ^ r ∂μ) ^ (1 / r) := by have hp0_ne : p ≠ 0 := (ne_of_lt hp0_lt).symm have hp0 : 0 ≤ p := le_of_lt hp0_lt have hq0_lt : 0 < q := lt_of_le_of_lt hp0 hpq have hq0_ne : q ≠ 0 := (ne_of_lt hq0_lt).symm have h_one_div_r : 1 / r = 1 / p - 1 / q := by rw [hpqr]; simp let p2 := q / p let q2 := p2.conjExponent have hp2q2 : p2.HolderConjugate q2 := .conjExponent (by simp [p2, _root_.lt_div_iff₀, hpq, hp0_lt]) calc (∫⁻ a : α, (f * g) a ^ p ∂μ) ^ (1 / p) = (∫⁻ a : α, f a ^ p * g a ^ p ∂μ) ^ (1 / p) := by simp_rw [Pi.mul_apply, ENNReal.mul_rpow_of_nonneg _ _ hp0] _ ≤ ((∫⁻ a, f a ^ (p * p2) ∂μ) ^ (1 / p2) * (∫⁻ a, g a ^ (p * q2) ∂μ) ^ (1 / q2)) ^ (1 / p) := by gcongr simp_rw [ENNReal.rpow_mul] exact ENNReal.lintegral_mul_le_Lp_mul_Lq μ hp2q2 (hf.pow_const _) (hg.pow_const _) _ = (∫⁻ a : α, f a ^ q ∂μ) ^ (1 / q) * (∫⁻ a : α, g a ^ r ∂μ) ^ (1 / r) := by rw [@ENNReal.mul_rpow_of_nonneg _ _ (1 / p) (by simp [hp0]), ← ENNReal.rpow_mul, ← ENNReal.rpow_mul] have hpp2 : p * p2 = q := by symm rw [mul_comm, ← div_eq_iff hp0_ne] have hpq2 : p * q2 = r := by rw [← inv_inv r, ← one_div, ← one_div, h_one_div_r] field_simp [p2, q2, Real.conjExponent, hp0_ne, hq0_ne] simp_rw [div_mul_div_comm, mul_one, mul_comm p2, mul_comm q2, hpp2, hpq2] theorem lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow {p q : ℝ} (hpq : p.HolderConjugate q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) : (∫⁻ a, f a * g a ^ (p - 1) ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ p ∂μ) ^ (1 / q) := by refine le_trans (ENNReal.lintegral_mul_le_Lp_mul_Lq μ hpq hf (hg.pow_const _)) ?_ by_cases hf_zero_rpow : (∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p) = 0 · rw [hf_zero_rpow, zero_mul] exact zero_le _ have hf_top_rpow : (∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p) ≠ ⊤ := by by_contra h refine hf_top ?_ have hp_not_neg : ¬p < 0 := by simp [hpq.nonneg] simpa [hpq.pos, hp_not_neg] using h refine (ENNReal.mul_le_mul_left hf_zero_rpow hf_top_rpow).mpr (le_of_eq ?_) congr ext1 a rw [← ENNReal.rpow_mul, hpq.sub_one_mul_conj] theorem lintegral_rpow_add_le_add_eLpNorm_mul_lintegral_rpow_add {p q : ℝ} (hpq : p.HolderConjugate q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) (hg : AEMeasurable g μ) (hg_top : (∫⁻ a, g a ^ p ∂μ) ≠ ⊤) : (∫⁻ a, (f + g) a ^ p ∂μ) ≤ ((∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p)) * (∫⁻ a, (f a + g a) ^ p ∂μ) ^ (1 / q) := by calc (∫⁻ a, (f + g) a ^ p ∂μ) ≤ ∫⁻ a, (f + g) a * (f + g) a ^ (p - 1) ∂μ := by gcongr with a by_cases h_zero : (f + g) a = 0 · rw [h_zero, ENNReal.zero_rpow_of_pos hpq.pos] exact zero_le _ by_cases h_top : (f + g) a = ⊤ · rw [h_top, ENNReal.top_rpow_of_pos hpq.sub_one_pos, ENNReal.top_mul_top] exact le_top refine le_of_eq ?_ nth_rw 2 [← ENNReal.rpow_one ((f + g) a)] rw [← ENNReal.rpow_add _ _ h_zero h_top, add_sub_cancel] _ = (∫⁻ a : α, f a * (f + g) a ^ (p - 1) ∂μ) + ∫⁻ a : α, g a * (f + g) a ^ (p - 1) ∂μ := by have h_add_m : AEMeasurable (fun a : α => (f + g) a ^ (p - 1 : ℝ)) μ := (hf.add hg).pow_const _ have h_add_apply : (∫⁻ a : α, (f + g) a * (f + g) a ^ (p - 1) ∂μ) = ∫⁻ a : α, (f a + g a) * (f + g) a ^ (p - 1) ∂μ := rfl simp_rw [h_add_apply, add_mul] rw [lintegral_add_left' (hf.mul h_add_m)] _ ≤ ((∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p)) * (∫⁻ a, (f a + g a) ^ p ∂μ) ^ (1 / q) := by rw [add_mul] gcongr · exact lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hf (hf.add hg) hf_top · exact lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hg (hf.add hg) hg_top private theorem lintegral_Lp_add_le_aux {p q : ℝ} (hpq : p.HolderConjugate q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) (hg : AEMeasurable g μ) (hg_top : (∫⁻ a, g a ^ p ∂μ) ≠ ⊤) (h_add_zero : (∫⁻ a, (f + g) a ^ p ∂μ) ≠ 0) (h_add_top : (∫⁻ a, (f + g) a ^ p ∂μ) ≠ ⊤) : (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p) := by have hp_not_nonpos : ¬p ≤ 0 := by simp [hpq.pos] have h0_rpow : (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≠ 0 := by simp [h_add_zero, h_add_top, -Pi.add_apply] suffices h : 1 ≤ (∫⁻ a : α, (f + g) a ^ p ∂μ) ^ (-(1 / p)) * ((∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a : α, g a ^ p ∂μ) ^ (1 / p)) by rwa [← mul_le_mul_left h0_rpow (by finiteness), ← mul_assoc, ← rpow_add _ _ h_add_zero h_add_top, ← sub_eq_add_neg, _root_.sub_self, rpow_zero, one_mul, mul_one] at h have h : (∫⁻ a : α, (f + g) a ^ p ∂μ) ≤ ((∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a : α, g a ^ p ∂μ) ^ (1 / p)) * (∫⁻ a : α, (f + g) a ^ p ∂μ) ^ (1 / q) := lintegral_rpow_add_le_add_eLpNorm_mul_lintegral_rpow_add hpq hf hf_top hg hg_top have h_one_div_q : 1 / q = 1 - 1 / p := by nth_rw 2 [← hpq.inv_add_inv_eq_one] ring simp_rw [h_one_div_q, sub_eq_add_neg 1 (1 / p), ENNReal.rpow_add _ _ h_add_zero h_add_top, rpow_one] at h conv_rhs at h => enter [2]; rw [mul_comm] conv_lhs at h => rw [← one_mul (∫⁻ a : α, (f + g) a ^ p ∂μ)] rwa [← mul_assoc, ENNReal.mul_le_mul_right h_add_zero h_add_top, mul_comm] at h /-- **Minkowski's inequality for functions** `α → ℝ≥0∞`: the `ℒp` seminorm of the sum of two functions is bounded by the sum of their `ℒp` seminorms. -/ theorem lintegral_Lp_add_le {p : ℝ} {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) (hp1 : 1 ≤ p) : (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p) := by have hp_pos : 0 < p := lt_of_lt_of_le zero_lt_one hp1 by_cases hf_top : ∫⁻ a, f a ^ p ∂μ = ⊤ · simp [hf_top, hp_pos] by_cases hg_top : ∫⁻ a, g a ^ p ∂μ = ⊤ · simp [hg_top, hp_pos] by_cases h1 : p = 1 · refine le_of_eq ?_ simp_rw [h1, one_div_one, ENNReal.rpow_one] exact lintegral_add_left' hf _ have hp1_lt : 1 < p := by refine lt_of_le_of_ne hp1 ?_ symm exact h1 have hpq := Real.HolderConjugate.conjExponent hp1_lt by_cases h0 : (∫⁻ a, (f + g) a ^ p ∂μ) = 0 · rw [h0, @ENNReal.zero_rpow_of_pos (1 / p) (by simp [lt_of_lt_of_le zero_lt_one hp1])] exact zero_le _ have htop : (∫⁻ a, (f + g) a ^ p ∂μ) ≠ ⊤ := by rw [← Ne] at hf_top hg_top rw [← lt_top_iff_ne_top] at hf_top hg_top ⊢ exact lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top hf hf_top hg_top hp1 exact lintegral_Lp_add_le_aux hpq hf hf_top hg hg_top h0 htop /-- Variant of Minkowski's inequality for functions `α → ℝ≥0∞` in `ℒp` with `p ≤ 1`: the `ℒp` seminorm of the sum of two functions is bounded by a constant multiple of the sum of their `ℒp` seminorms. -/ theorem lintegral_Lp_add_le_of_le_one {p : ℝ} {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hp0 : 0 ≤ p) (hp1 : p ≤ 1) : (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≤ (2 : ℝ≥0∞) ^ (1 / p - 1) * ((∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p)) := by rcases eq_or_lt_of_le hp0 with (rfl | hp) · simp only [Pi.add_apply, rpow_zero, lintegral_one, _root_.div_zero, zero_sub] norm_num rw [rpow_neg, rpow_one, ENNReal.inv_mul_cancel two_ne_zero ofNat_ne_top] calc (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≤ ((∫⁻ a, f a ^ p ∂μ) + ∫⁻ a, g a ^ p ∂μ) ^ (1 / p) := by rw [← lintegral_add_left' (hf.pow_const p)] gcongr with a exact rpow_add_le_add_rpow _ _ hp0 hp1 _ ≤ (2 : ℝ≥0∞) ^ (1 / p - 1) * ((∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p)) := rpow_add_le_mul_rpow_add_rpow _ _ ((one_le_div hp).2 hp1) end ENNReal /-- Hölder's inequality for functions `α → ℝ≥0`. The integral of the product of two functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate exponents. -/ theorem NNReal.lintegral_mul_le_Lp_mul_Lq {p q : ℝ} (hpq : p.HolderConjugate q) {f g : α → ℝ≥0} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : (∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, (f a : ℝ≥0∞) ^ p ∂μ) ^ (1 / p) * (∫⁻ a, (g a : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) := by simp_rw [Pi.mul_apply, ENNReal.coe_mul] exact ENNReal.lintegral_mul_le_Lp_mul_Lq μ hpq hf.coe_nnreal_ennreal hg.coe_nnreal_ennreal end end LIntegral
ADEInequality.lean
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Order.Ring.Rat import Mathlib.Data.Multiset.Sort import Mathlib.Data.PNat.Basic import Mathlib.Data.PNat.Interval import Mathlib.Tactic.NormNum import Mathlib.Tactic.IntervalCases /-! # The inequality `p⁻¹ + q⁻¹ + r⁻¹ > 1` In this file we classify solutions to the inequality `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`, for positive natural numbers `p`, `q`, and `r`. The solutions are exactly of the form. * `A' q r := {1,q,r}` * `D' r := {2,2,r}` * `E6 := {2,3,3}`, or `E7 := {2,3,4}`, or `E8 := {2,3,5}` This inequality shows up in Lie theory, in the classification of Dynkin diagrams, root systems, and semisimple Lie algebras. ## Main declarations * `pqr.A' q r`, the multiset `{1,q,r}` * `pqr.D' r`, the multiset `{2,2,r}` * `pqr.E6`, the multiset `{2,3,3}` * `pqr.E7`, the multiset `{2,3,4}` * `pqr.E8`, the multiset `{2,3,5}` * `pqr.classification`, the classification of solutions to `p⁻¹ + q⁻¹ + r⁻¹ > 1` -/ namespace ADEInequality open Multiset /-- `A' q r := {1,q,r}` is a `Multiset ℕ+` that is a solution to the inequality `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`. -/ def A' (q r : ℕ+) : Multiset ℕ+ := {1, q, r} /-- `A r := {1,1,r}` is a `Multiset ℕ+` that is a solution to the inequality `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`. These solutions are related to the Dynkin diagrams $A_r$. -/ def A (r : ℕ+) : Multiset ℕ+ := A' 1 r /-- `D' r := {2,2,r}` is a `Multiset ℕ+` that is a solution to the inequality `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`. These solutions are related to the Dynkin diagrams $D_{r+2}$. -/ def D' (r : ℕ+) : Multiset ℕ+ := {2, 2, r} /-- `E' r := {2,3,r}` is a `Multiset ℕ+`. For `r ∈ {3,4,5}` is a solution to the inequality `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`. These solutions are related to the Dynkin diagrams $E_{r+3}$. -/ def E' (r : ℕ+) : Multiset ℕ+ := {2, 3, r} /-- `E6 := {2,3,3}` is a `Multiset ℕ+` that is a solution to the inequality `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`. This solution is related to the Dynkin diagrams $E_6$. -/ def E6 : Multiset ℕ+ := E' 3 /-- `E7 := {2,3,4}` is a `Multiset ℕ+` that is a solution to the inequality `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`. This solution is related to the Dynkin diagrams $E_7$. -/ def E7 : Multiset ℕ+ := E' 4 /-- `E8 := {2,3,5}` is a `Multiset ℕ+` that is a solution to the inequality `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1`. This solution is related to the Dynkin diagrams $E_8$. -/ def E8 : Multiset ℕ+ := E' 5 /-- `sum_inv pqr` for a `pqr : Multiset ℕ+` is the sum of the inverses of the elements of `pqr`, as rational number. The intended argument is a multiset `{p,q,r}` of cardinality `3`. -/ def sumInv (pqr : Multiset ℕ+) : ℚ := Multiset.sum (pqr.map fun (x : ℕ+) => x⁻¹) theorem sumInv_pqr (p q r : ℕ+) : sumInv {p, q, r} = (p : ℚ)⁻¹ + (q : ℚ)⁻¹ + (r : ℚ)⁻¹ := by simp only [sumInv, insert_eq_cons, add_assoc, map_cons, sum_cons, map_singleton, sum_singleton] /-- A multiset `pqr` of positive natural numbers is `admissible` if it is equal to `A' q r`, or `D' r`, or one of `E6`, `E7`, or `E8`. -/ def Admissible (pqr : Multiset ℕ+) : Prop := (∃ q r, A' q r = pqr) ∨ (∃ r, D' r = pqr) ∨ E' 3 = pqr ∨ E' 4 = pqr ∨ E' 5 = pqr theorem admissible_A' (q r : ℕ+) : Admissible (A' q r) := Or.inl ⟨q, r, rfl⟩ theorem admissible_D' (n : ℕ+) : Admissible (D' n) := Or.inr <| Or.inl ⟨n, rfl⟩ theorem admissible_E'3 : Admissible (E' 3) := Or.inr <| Or.inr <| Or.inl rfl theorem admissible_E'4 : Admissible (E' 4) := Or.inr <| Or.inr <| Or.inr <| Or.inl rfl theorem admissible_E'5 : Admissible (E' 5) := Or.inr <| Or.inr <| Or.inr <| Or.inr rfl theorem admissible_E6 : Admissible E6 := admissible_E'3 theorem admissible_E7 : Admissible E7 := admissible_E'4 theorem admissible_E8 : Admissible E8 := admissible_E'5 theorem Admissible.one_lt_sumInv {pqr : Multiset ℕ+} : Admissible pqr → 1 < sumInv pqr := by rw [Admissible] rintro (⟨p', q', H⟩ | ⟨n, H⟩ | H | H | H) · rw [← H, A', sumInv_pqr, add_assoc] simp only [lt_add_iff_pos_right, PNat.one_coe, inv_one, Nat.cast_one] apply add_pos <;> simp only [PNat.pos, Nat.cast_pos, inv_pos] · rw [← H, D', sumInv_pqr] norm_num all_goals rw [← H, E', sumInv_pqr] norm_num theorem lt_three {p q r : ℕ+} (hpq : p ≤ q) (hqr : q ≤ r) (H : 1 < sumInv {p, q, r}) : p < 3 := by have h3 : (0 : ℚ) < 3 := by simp contrapose! H rw [sumInv_pqr] have h3q := H.trans hpq have h3r := h3q.trans hqr have hp : (p : ℚ)⁻¹ ≤ 3⁻¹ := by rw [inv_le_inv₀ _ h3] · assumption_mod_cast · norm_num have hq : (q : ℚ)⁻¹ ≤ 3⁻¹ := by rw [inv_le_inv₀ _ h3] · assumption_mod_cast · norm_num have hr : (r : ℚ)⁻¹ ≤ 3⁻¹ := by rw [inv_le_inv₀ _ h3] · assumption_mod_cast · norm_num calc (p : ℚ)⁻¹ + (q : ℚ)⁻¹ + (r : ℚ)⁻¹ ≤ 3⁻¹ + 3⁻¹ + 3⁻¹ := add_le_add (add_le_add hp hq) hr _ = 1 := by norm_num theorem lt_four {q r : ℕ+} (hqr : q ≤ r) (H : 1 < sumInv {2, q, r}) : q < 4 := by have h4 : (0 : ℚ) < 4 := by simp contrapose! H rw [sumInv_pqr] have h4r := H.trans hqr have hq : (q : ℚ)⁻¹ ≤ 4⁻¹ := by rw [inv_le_inv₀ _ h4] · assumption_mod_cast · norm_num have hr : (r : ℚ)⁻¹ ≤ 4⁻¹ := by rw [inv_le_inv₀ _ h4] · assumption_mod_cast · norm_num calc (2⁻¹ + (q : ℚ)⁻¹ + (r : ℚ)⁻¹) ≤ 2⁻¹ + 4⁻¹ + 4⁻¹ := add_le_add (add_le_add le_rfl hq) hr _ = 1 := by norm_num theorem lt_six {r : ℕ+} (H : 1 < sumInv {2, 3, r}) : r < 6 := by have h6 : (0 : ℚ) < 6 := by simp contrapose! H rw [sumInv_pqr] have hr : (r : ℚ)⁻¹ ≤ 6⁻¹ := by rw [inv_le_inv₀ _ h6] · assumption_mod_cast · norm_num calc (2⁻¹ + 3⁻¹ + (r : ℚ)⁻¹ : ℚ) ≤ 2⁻¹ + 3⁻¹ + 6⁻¹ := add_le_add (add_le_add le_rfl le_rfl) hr _ = 1 := by norm_num theorem admissible_of_one_lt_sumInv_aux' {p q r : ℕ+} (hpq : p ≤ q) (hqr : q ≤ r) (H : 1 < sumInv {p, q, r}) : Admissible {p, q, r} := by have hp3 : p < 3 := lt_three hpq hqr H -- Porting note: `interval_cases` doesn't support `ℕ+` yet. replace hp3 := Finset.mem_Iio.mpr hp3 conv at hp3 => change p ∈ ({1, 2} : Multiset ℕ+) fin_cases hp3 · exact admissible_A' q r have hq4 : q < 4 := lt_four hqr H replace hq4 := Finset.mem_Ico.mpr ⟨hpq, hq4⟩; clear hpq conv at hq4 => change q ∈ ({2, 3} : Multiset ℕ+) fin_cases hq4 · exact admissible_D' r have hr6 : r < 6 := lt_six H replace hr6 := Finset.mem_Ico.mpr ⟨hqr, hr6⟩; clear hqr conv at hr6 => change r ∈ ({3, 4, 5} : Multiset ℕ+) fin_cases hr6 · exact admissible_E6 · exact admissible_E7 · exact admissible_E8 theorem admissible_of_one_lt_sumInv_aux : ∀ {pqr : List ℕ+} (_ : pqr.Sorted (· ≤ ·)) (_ : pqr.length = 3) (_ : 1 < sumInv pqr), Admissible pqr | [p, q, r], hs, _, H => by obtain ⟨⟨hpq, -⟩, hqr⟩ : (p ≤ q ∧ p ≤ r) ∧ q ≤ r := by simpa using hs exact admissible_of_one_lt_sumInv_aux' hpq hqr H theorem admissible_of_one_lt_sumInv {p q r : ℕ+} (H : 1 < sumInv {p, q, r}) : Admissible {p, q, r} := by simp only [Admissible] let S := sort ((· ≤ ·) : ℕ+ → ℕ+ → Prop) {p, q, r} have hS : S.Sorted (· ≤ ·) := sort_sorted _ _ have hpqr : ({p, q, r} : Multiset ℕ+) = S := (sort_eq LE.le {p, q, r}).symm rw [hpqr] rw [hpqr] at H apply admissible_of_one_lt_sumInv_aux hS _ H simp only [S, insert_eq_cons, length_sort, card_cons, card_singleton] /-- A multiset `{p,q,r}` of positive natural numbers is a solution to `(p⁻¹ + q⁻¹ + r⁻¹ : ℚ) > 1` if and only if it is `admissible` which means it is one of: * `A' q r := {1,q,r}` * `D' r := {2,2,r}` * `E6 := {2,3,3}`, or `E7 := {2,3,4}`, or `E8 := {2,3,5}` -/ theorem classification (p q r : ℕ+) : 1 < sumInv {p, q, r} ↔ Admissible {p, q, r} := ⟨admissible_of_one_lt_sumInv, Admissible.one_lt_sumInv⟩ end ADEInequality
TotallyDisconnected.lean
/- Copyright (c) 2024 Jou Glasheen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jou Glasheen, Kevin Buzzard, David Loeffler, Yongle Hu, Johan Commelin -/ import Mathlib.Topology.Algebra.Nonarchimedean.Basic /-! # Total separatedness of nonarchimedean groups In this file, we prove that a nonarchimedean group is a totally separated topological space. The fact that a nonarchimedean group is a totally disconnected topological space is implied by the fact that a nonarchimedean group is totally separated. ## Main results - `NonarchimedeanGroup.instTotallySeparated`: A nonarchimedean group is a totally separated topological space. ## Notation - `G` : Is a nonarchimedean group. - `V` : Is an open subgroup which is a neighbourhood of the identity in `G`. ## References See Proposition 2.3.9 and Problem 63 in [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]. -/ open Pointwise TopologicalSpace variable {G : Type*} [TopologicalSpace G] [Group G] [NonarchimedeanGroup G] [T2Space G] namespace NonarchimedeanGroup @[to_additive] lemma exists_openSubgroup_separating {a b : G} (h : a ≠ b) : ∃ V : OpenSubgroup G, Disjoint (a • (V : Set G)) (b • V) := by obtain ⟨u, v, _, open_v, mem_u, mem_v, dis⟩ := t2_separation (h ∘ inv_mul_eq_one.mp) obtain ⟨V, hV⟩ := is_nonarchimedean v (open_v.mem_nhds mem_v) use V simp only [Disjoint, Set.le_eq_subset, Set.bot_eq_empty, Set.subset_empty_iff] intros x mem_aV mem_bV by_contra! con obtain ⟨s, hs⟩ := con have hsa : s ∈ a • (V : Set G) := mem_aV hs have hsb : s ∈ b • (V : Set G) := mem_bV hs rw [mem_leftCoset_iff] at hsa hsb refine dis.subset_compl_right mem_u (hV ?_) simpa [mul_assoc] using mul_mem hsa (inv_mem hsb) @[to_additive] instance (priority := 100) instTotallySeparated : TotallySeparatedSpace G where isTotallySeparated_univ x _ y _ hxy := by obtain ⟨V, dxy⟩ := exists_openSubgroup_separating hxy exact ⟨_, _, V.isOpen.smul x, (V.isClosed.smul x).isOpen_compl, mem_own_leftCoset .., dxy.subset_compl_left <| mem_own_leftCoset .., by simp, disjoint_compl_right⟩ end NonarchimedeanGroup
Basic.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Isometric import Mathlib.Analysis.CStarAlgebra.GelfandDuality import Mathlib.Analysis.CStarAlgebra.Unitization import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.PosPart.Basic /-! # Continuous functional calculus In this file we construct the `continuousFunctionalCalculus` for a normal element `a` of a (unital) C⋆-algebra over `ℂ`. This is a star algebra equivalence `C(spectrum ℂ a, ℂ) ≃⋆ₐ[ℂ] elemental ℂ a` which sends the (restriction of) the identity map `ContinuousMap.id ℂ` to the (unique) preimage of `a` under the coercion of `elemental ℂ a` to `A`. Being a star algebra equivalence between C⋆-algebras, this map is continuous (even an isometry), and by the Stone-Weierstrass theorem it is the unique star algebra equivalence which extends the polynomial functional calculus (i.e., `Polynomial.aeval`). For any continuous function `f : spectrum ℂ a → ℂ`, this makes it possible to define an element `f a` (not valid notation) in the original algebra, which heuristically has the same eigenspaces as `a` and acts on eigenvector of `a` for an eigenvalue `λ` as multiplication by `f λ`. This description is perfectly accurate in finite dimension, but only heuristic in infinite dimension as there might be no genuine eigenvector. In particular, when `f` is a polynomial `∑ cᵢ Xⁱ`, then `f a` is `∑ cᵢ aⁱ`. Also, `id a = a`. The result we have established here is the strongest possible, but it is not the version which is most useful in practice. The generic API for the continuous functional calculus can be found in `Analysis.CStarAlgebra.ContinuousFunctionalCalculus` in the `Unital` and `NonUnital` files. The relevant instances on C⋆-algebra can be found in the `Instances` file. ## Main definitions * `continuousFunctionalCalculus : C(spectrum ℂ a, ℂ) ≃⋆ₐ[ℂ] elemental ℂ a`: this is the composition of the inverse of the `gelfandStarTransform` with the natural isomorphism induced by the homeomorphism `elemental.characterSpaceHomeo`. * `elemental.characterSpaceHomeo` : `characterSpace ℂ (elemental ℂ a) ≃ₜ spectrum ℂ a`: this homeomorphism is defined by evaluating a character `φ` at `a`, and noting that `φ a ∈ spectrum ℂ a` since `φ` is an algebra homomorphism. Moreover, this map is continuous and bijective and since the spaces involved are compact Hausdorff, it is a homeomorphism. * `IsStarNormal.instContinuousFunctionalCalculus`: the continuous functional calculus for normal elements in a unital C⋆-algebra over `ℂ`. * `CStarAlgebra.instNonnegSpectrumClass`: In a unital C⋆-algebra over `ℂ` which is also a `StarOrderedRing`, the spectrum of a nonnegative element is nonnegative. -/ open scoped Pointwise ENNReal NNReal ComplexOrder open WeakDual WeakDual.CharacterSpace variable {A : Type*} [CStarAlgebra A] namespace StarAlgebra.elemental instance {R A : Type*} [CommRing R] [StarRing R] [NormedRing A] [Algebra R A] [StarRing A] [ContinuousStar A] [StarModule R A] (a : A) [IsStarNormal a] : NormedCommRing (elemental R a) := { SubringClass.toNormedRing (elemental R a) with mul_comm := mul_comm } noncomputable instance (a : A) [IsStarNormal a] : CommCStarAlgebra (elemental ℂ a) where variable (a : A) [IsStarNormal a] /-- The natural map from `characterSpace ℂ (elemental ℂ x)` to `spectrum ℂ x` given by evaluating `φ` at `x`. This is essentially just evaluation of the `gelfandTransform` of `x`, but because we want something in `spectrum ℂ x`, as opposed to `spectrum ℂ ⟨x, elemental.self_mem ℂ x⟩` there is slightly more work to do. -/ @[simps] noncomputable def characterSpaceToSpectrum (x : A) (φ : characterSpace ℂ (elemental ℂ x)) : spectrum ℂ x where val := φ ⟨x, self_mem ℂ x⟩ property := by simpa only [StarSubalgebra.spectrum_eq (hS := isClosed ℂ x) (a := ⟨x, self_mem ℂ x⟩)] using AlgHom.apply_mem_spectrum φ ⟨x, self_mem ℂ x⟩ theorem continuous_characterSpaceToSpectrum (x : A) : Continuous (characterSpaceToSpectrum x) := continuous_induced_rng.2 (map_continuous <| gelfandTransform ℂ (elemental ℂ x) ⟨x, self_mem ℂ x⟩) theorem bijective_characterSpaceToSpectrum : Function.Bijective (characterSpaceToSpectrum a) := by refine ⟨fun φ ψ h => starAlgHomClass_ext ℂ ?_ ?_ ?_, ?_⟩ · exact (map_continuous φ) · exact (map_continuous ψ) · simpa only [characterSpaceToSpectrum, Subtype.mk_eq_mk, ContinuousMap.coe_mk] using h · rintro ⟨z, hz⟩ have hz' := (StarSubalgebra.spectrum_eq (hS := isClosed ℂ a) (a := ⟨a, self_mem ℂ a⟩) ▸ hz) rw [CharacterSpace.mem_spectrum_iff_exists] at hz' obtain ⟨φ, rfl⟩ := hz' exact ⟨φ, rfl⟩ /-- The homeomorphism between the character space of the unital C⋆-subalgebra generated by a single normal element `a : A` and `spectrum ℂ a`. -/ noncomputable def characterSpaceHomeo : characterSpace ℂ (elemental ℂ a) ≃ₜ spectrum ℂ a := @Continuous.homeoOfEquivCompactToT2 _ _ _ _ _ _ (Equiv.ofBijective (characterSpaceToSpectrum a) (bijective_characterSpaceToSpectrum a)) (continuous_characterSpaceToSpectrum a) end StarAlgebra.elemental open StarAlgebra elemental variable (a : A) [IsStarNormal a] /-- **Continuous functional calculus.** Given a normal element `a : A` of a unital C⋆-algebra, the continuous functional calculus is a `StarAlgEquiv` from the complex-valued continuous functions on the spectrum of `a` to the unital C⋆-subalgebra generated by `a`. Moreover, this equivalence identifies `(ContinuousMap.id ℂ).restrict (spectrum ℂ a))` with `a`; see `continuousFunctionalCalculus_map_id`. As such it extends the polynomial functional calculus. -/ noncomputable def continuousFunctionalCalculus : C(spectrum ℂ a, ℂ) ≃⋆ₐ[ℂ] elemental ℂ a := ((characterSpaceHomeo a).compStarAlgEquiv' ℂ ℂ).trans (gelfandStarTransform (elemental ℂ a)).symm theorem continuousFunctionalCalculus_map_id : continuousFunctionalCalculus a ((ContinuousMap.id ℂ).restrict (spectrum ℂ a)) = ⟨a, self_mem ℂ a⟩ := (gelfandStarTransform (elemental ℂ a)).symm_apply_apply _ /-! ### Continuous functional calculus for normal elements -/ local notation "σₙ" => quasispectrum section Normal instance IsStarNormal.instContinuousFunctionalCalculus {A : Type*} [CStarAlgebra A] : ContinuousFunctionalCalculus ℂ A IsStarNormal where predicate_zero := .zero spectrum_nonempty a _ := spectrum.nonempty a exists_cfc_of_predicate a ha := by refine ⟨(StarAlgebra.elemental ℂ a).subtype.comp <| continuousFunctionalCalculus a, ?hom_isClosedEmbedding, ?hom_id, ?hom_map_spectrum, ?predicate_hom⟩ case hom_isClosedEmbedding => exact Isometry.isClosedEmbedding <| isometry_subtype_coe.comp <| StarAlgEquiv.isometry (continuousFunctionalCalculus a) case hom_id => exact congr_arg Subtype.val <| continuousFunctionalCalculus_map_id a case hom_map_spectrum => intro f simp only [StarAlgHom.comp_apply, StarAlgHom.coe_coe, StarSubalgebra.coe_subtype] rw [← StarSubalgebra.spectrum_eq (hS := StarAlgebra.elemental.isClosed ℂ a), AlgEquiv.spectrum_eq (continuousFunctionalCalculus a), ContinuousMap.spectrum_eq_range] case predicate_hom => exact fun f ↦ ⟨by rw [← map_star]; exact Commute.all (star f) f |>.map _⟩ lemma cfcHom_eq_of_isStarNormal {A : Type*} [CStarAlgebra A] (a : A) [ha : IsStarNormal a] : cfcHom ha = (StarAlgebra.elemental ℂ a).subtype.comp (continuousFunctionalCalculus a) := by refine cfcHom_eq_of_continuous_of_map_id ha _ ?_ ?_ · exact continuous_subtype_val.comp <| (StarAlgEquiv.isometry (continuousFunctionalCalculus a)).continuous · simp [continuousFunctionalCalculus_map_id a] instance IsStarNormal.instNonUnitalContinuousFunctionalCalculus {A : Type*} [NonUnitalCStarAlgebra A] : NonUnitalContinuousFunctionalCalculus ℂ A IsStarNormal := RCLike.nonUnitalContinuousFunctionalCalculus Unitization.isStarNormal_inr open Unitization CStarAlgebra in lemma inr_comp_cfcₙHom_eq_cfcₙAux {A : Type*} [NonUnitalCStarAlgebra A] (a : A) [ha : IsStarNormal a] : (inrNonUnitalStarAlgHom ℂ A).comp (cfcₙHom ha) = cfcₙAux (isStarNormal_inr (R := ℂ) (A := A)) a ha := by have h (a : A) := isStarNormal_inr (R := ℂ) (A := A) (a := a) refine @ContinuousMapZero.UniqueHom.eq_of_continuous_of_map_id _ _ _ _ _ _ _ _ _ _ _ inferInstance inferInstance _ (σₙ ℂ a) _ _ rfl _ _ ?_ ?_ ?_ · change Continuous (fun f ↦ (cfcₙHom ha f : A⁺¹)); fun_prop · exact isClosedEmbedding_cfcₙAux @(h) a ha |>.continuous · trans (a : A⁺¹) · congrm(inr $(cfcₙHom_id ha)) · exact cfcₙAux_id @(h) a ha |>.symm end Normal /-! ### The spectrum of a nonnegative element is nonnegative -/ section SpectrumRestricts open NNReal ENNReal variable {A : Type*} [CStarAlgebra A] lemma SpectrumRestricts.nnreal_iff_nnnorm {a : A} {t : ℝ≥0} (ha : IsSelfAdjoint a) (ht : ‖a‖₊ ≤ t) : SpectrumRestricts a ContinuousMap.realToNNReal ↔ ‖algebraMap ℝ A t - a‖₊ ≤ t := by have : IsSelfAdjoint (algebraMap ℝ A t - a) := IsSelfAdjoint.algebraMap A (.all (t : ℝ)) |>.sub ha rw [← ENNReal.coe_le_coe, ← IsSelfAdjoint.spectralRadius_eq_nnnorm, ← SpectrumRestricts.spectralRadius_eq (f := Complex.reCLM)] at ht ⊢ · exact SpectrumRestricts.nnreal_iff_spectralRadius_le ht all_goals try apply IsSelfAdjoint.spectrumRestricts assumption lemma SpectrumRestricts.nnreal_add {a b : A} (ha₁ : IsSelfAdjoint a) (hb₁ : IsSelfAdjoint b) (ha₂ : SpectrumRestricts a ContinuousMap.realToNNReal) (hb₂ : SpectrumRestricts b ContinuousMap.realToNNReal) : SpectrumRestricts (a + b) ContinuousMap.realToNNReal := by rw [SpectrumRestricts.nnreal_iff_nnnorm (ha₁.add hb₁) (nnnorm_add_le a b), NNReal.coe_add, map_add, add_sub_add_comm] refine nnnorm_add_le _ _ |>.trans ?_ gcongr all_goals rw [← SpectrumRestricts.nnreal_iff_nnnorm] <;> first | rfl | assumption lemma IsSelfAdjoint.sq_spectrumRestricts {a : A} (ha : IsSelfAdjoint a) : SpectrumRestricts (a ^ 2) ContinuousMap.realToNNReal := by rw [SpectrumRestricts.nnreal_iff, ← cfc_id (R := ℝ) a, ← cfc_pow .., cfc_map_spectrum ..] rintro - ⟨x, -, rfl⟩ exact sq_nonneg x open ComplexStarModule lemma SpectrumRestricts.eq_zero_of_neg {a : A} (ha : IsSelfAdjoint a) (ha₁ : SpectrumRestricts a ContinuousMap.realToNNReal) (ha₂ : SpectrumRestricts (-a) ContinuousMap.realToNNReal) : a = 0 := by nontriviality A rw [SpectrumRestricts.nnreal_iff] at ha₁ ha₂ apply CFC.eq_zero_of_spectrum_subset_zero (R := ℝ) a rw [Set.subset_singleton_iff] simp only [← spectrum.neg_eq, Set.mem_neg] at ha₂ peel ha₁ with x hx _ linarith [ha₂ (-x) ((neg_neg x).symm ▸ hx)] lemma SpectrumRestricts.smul_of_nonneg {A : Type*} [Ring A] [Algebra ℝ A] {a : A} (ha : SpectrumRestricts a ContinuousMap.realToNNReal) {r : ℝ} (hr : 0 ≤ r) : SpectrumRestricts (r • a) ContinuousMap.realToNNReal := by rw [SpectrumRestricts.nnreal_iff] at ha ⊢ nontriviality A intro x hx by_cases hr' : r = 0 · simp [hr'] at hx ⊢ exact hx.symm.le · lift r to ℝˣ using IsUnit.mk0 r hr' rw [← Units.smul_def, spectrum.unit_smul_eq_smul, Set.mem_smul_set_iff_inv_smul_mem] at hx refine le_of_smul_le_smul_left ?_ (inv_pos.mpr <| lt_of_le_of_ne hr <| ne_comm.mpr hr') simpa [Units.smul_def] using ha _ hx /-- The `ℝ`-spectrum of an element of the form `star b * b` in a C⋆-algebra is nonnegative. This is the key result used to establish `CStarAlgebra.instNonnegSpectrumClass`. -/ lemma spectrum_star_mul_self_nonneg {b : A} : ∀ x ∈ spectrum ℝ (star b * b), 0 ≤ x := by -- for convenience we'll work with `a := star b * b`, which is selfadjoint. set a := star b * b with a_def have ha : IsSelfAdjoint a := by simp [a_def] -- the key element to consider is `c := b * a⁻`, which satisfies `- (star c * c) = a⁻ ^ 3`. set c := b * a⁻ have h_eq_negPart_a : - (star c * c) = a⁻ ^ 3 := calc -(star c * c) = - a⁻ * a * a⁻ := by simp only [star_mul, c, mul_assoc, ← mul_assoc (star b), ← a_def, CFC.negPart_def, neg_mul, IsSelfAdjoint.cfcₙ (f := (·⁻)).star_eq] _ = - a⁻ * (a⁺ - a⁻) * a⁻ := congr(- a⁻ * $(CFC.posPart_sub_negPart a ha) * a⁻).symm _ = a⁻ ^ 3 := by simp [mul_sub, pow_succ] -- the spectrum of `- (star c * c) = a⁻ ^ 3` is nonnegative, since the function on the right -- is nonnegative on the spectrum of `a`. have h_c_spec₀ : SpectrumRestricts (- (star c * c)) (ContinuousMap.realToNNReal ·) := by simp only [SpectrumRestricts.nnreal_iff, h_eq_negPart_a, CFC.negPart_def] rw [cfcₙ_eq_cfc (hf0 := by simp), ← cfc_pow (ha := ha) .., cfc_map_spectrum (ha := ha) ..] rintro - ⟨x, -, rfl⟩ positivity -- the spectrum of `c * star c` is nonnegative, since squares of selfadjoint elements have -- nonnegative spectrum, and `c * star c = 2 • (ℜ c ^ 2 + ℑ c ^ 2) + (- (star c * c))`, -- and selfadjoint elements with nonnegative spectrum are closed under addition. have h_c_spec₁ : SpectrumRestricts (c * star c) ContinuousMap.realToNNReal := by rw [eq_sub_iff_add_eq'.mpr <| star_mul_self_add_self_mul_star c, sub_eq_add_neg, ← sq, ← sq] refine SpectrumRestricts.nnreal_add ?_ ?_ ?_ h_c_spec₀ · exact .smul (star_trivial _) <| ((ℜ c).prop.pow 2).add ((ℑ c).prop.pow 2) · exact .neg <| .star_mul_self c · rw [← Nat.cast_smul_eq_nsmul ℝ] refine (ℜ c).2.sq_spectrumRestricts.nnreal_add ((ℜ c).2.pow 2) ((ℑ c).2.pow 2) (ℑ c).2.sq_spectrumRestricts |>.smul_of_nonneg <| by simp -- therefore `- (star c * c) = 0` and so `a⁻ ^ 3 = 0`. By properties of the continuous functional -- calculus, `fun x ↦ x⁻ ^ 3` is zero on the spectrum of `a`, `0 ≤ x` for `x ∈ spectrum ℝ a`. rw [h_c_spec₁.mul_comm.eq_zero_of_neg (.star_mul_self c) h_c_spec₀, neg_zero, CFC.negPart_def, cfcₙ_eq_cfc (hf0 := by simp), ← cfc_pow _ _ (ha := ha), ← cfc_zero a (R := ℝ)] at h_eq_negPart_a have h_eqOn := eqOn_of_cfc_eq_cfc (ha := ha) h_eq_negPart_a exact fun x hx ↦ negPart_eq_zero.mp <| pow_eq_zero (h_eqOn hx).symm lemma IsSelfAdjoint.coe_mem_spectrum_complex {A : Type*} [TopologicalSpace A] [Ring A] [StarRing A] [Algebra ℂ A] [ContinuousFunctionalCalculus ℂ A IsStarNormal] {a : A} {x : ℝ} (ha : IsSelfAdjoint a := by cfc_tac) : (x : ℂ) ∈ spectrum ℂ a ↔ x ∈ spectrum ℝ a := by simp [← ha.spectrumRestricts.algebraMap_image] end SpectrumRestricts section NonnegSpectrumClass variable {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] instance CStarAlgebra.instNonnegSpectrumClass : NonnegSpectrumClass ℝ A := .of_spectrum_nonneg fun a ha ↦ by rw [StarOrderedRing.nonneg_iff] at ha induction ha using AddSubmonoid.closure_induction with | mem x hx => obtain ⟨b, rfl⟩ := hx exact spectrum_star_mul_self_nonneg | one => nontriviality A simp | mul x y x_mem y_mem hx hy => rw [← SpectrumRestricts.nnreal_iff] at hx hy ⊢ rw [← StarOrderedRing.nonneg_iff] at x_mem y_mem exact hx.nnreal_add (.of_nonneg x_mem) (.of_nonneg y_mem) hy open ComplexOrder in instance CStarAlgebra.instNonnegSpectrumClassComplexUnital : NonnegSpectrumClass ℂ A where quasispectrum_nonneg_of_nonneg a ha x := by rw [mem_quasispectrum_iff] refine (Or.elim · ge_of_eq fun hx ↦ ?_) obtain ⟨y, hy, rfl⟩ := (IsSelfAdjoint.of_nonneg ha).spectrumRestricts.algebraMap_image ▸ hx simpa using spectrum_nonneg_of_nonneg ha hy end NonnegSpectrumClass section SpectralOrder variable (A : Type*) [NonUnitalCStarAlgebra A] open scoped CStarAlgebra /-- The partial order on a C⋆-algebra defined by `x ≤ y` if and only if `y - x` is selfadjoint and has nonnegative spectrum. This is not declared as an instance because one may already have a partial order with better definitional properties. However, it can be useful to invoke this as an instance in proofs. -/ @[reducible] def CStarAlgebra.spectralOrder : PartialOrder A where le x y := IsSelfAdjoint (y - x) ∧ QuasispectrumRestricts (y - x) ContinuousMap.realToNNReal le_refl := by simp only [sub_self, IsSelfAdjoint.zero, true_and, forall_const] rw [quasispectrumRestricts_iff_spectrumRestricts_inr' ℂ, SpectrumRestricts.nnreal_iff] nontriviality A simp le_antisymm x y hxy hyx := by rw [← Unitization.isSelfAdjoint_inr (R := ℂ), quasispectrumRestricts_iff_spectrumRestricts_inr' ℂ, Unitization.inr_sub ℂ] at hxy hyx rw [← sub_eq_zero] apply Unitization.inr_injective (R := ℂ) rw [Unitization.inr_zero, Unitization.inr_sub] exact hyx.2.eq_zero_of_neg hyx.1 (neg_sub (x : A⁺¹) (y : A⁺¹) ▸ hxy.2) le_trans x y z hxy hyz := by simp +singlePass only [← Unitization.isSelfAdjoint_inr (R := ℂ), quasispectrumRestricts_iff_spectrumRestricts_inr' ℂ] at hxy hyz ⊢ exact ⟨by simpa using hyz.1.add hxy.1, by simpa using hyz.2.nnreal_add hyz.1 hxy.1 hxy.2⟩ /-- The `CStarAlgebra.spectralOrder` on a C⋆-algebra is a `StarOrderedRing`. -/ lemma CStarAlgebra.spectralOrderedRing : @StarOrderedRing A _ (CStarAlgebra.spectralOrder A) _ := let _ := CStarAlgebra.spectralOrder A { le_iff := by intro x y constructor · intro h obtain ⟨s, hs₁, _, hs₂⟩ := CFC.exists_sqrt_of_isSelfAdjoint_of_quasispectrumRestricts h.1 h.2 refine ⟨s * s, ?_, by rwa [eq_sub_iff_add_eq', eq_comm] at hs₂⟩ exact AddSubmonoid.subset_closure ⟨s, by simp [hs₁.star_eq]⟩ · rintro ⟨p, hp, rfl⟩ simp only [spectralOrder, add_sub_cancel_left] induction hp using AddSubmonoid.closure_induction with | mem x hx => obtain ⟨s, rfl⟩ := hx refine ⟨IsSelfAdjoint.star_mul_self s, ?_⟩ rw [quasispectrumRestricts_iff_spectrumRestricts_inr' ℂ, SpectrumRestricts.nnreal_iff, Unitization.inr_mul, Unitization.inr_star] exact spectrum_star_mul_self_nonneg | one => rw [quasispectrumRestricts_iff_spectrumRestricts_inr' ℂ, SpectrumRestricts.nnreal_iff] nontriviality A simp | mul x y _ _ hx hy => simp +singlePass only [← Unitization.isSelfAdjoint_inr (R := ℂ), quasispectrumRestricts_iff_spectrumRestricts_inr' ℂ] at hx hy ⊢ rw [Unitization.inr_add] exact ⟨hx.1.add hy.1, hx.2.nnreal_add hx.1 hy.1 hy.2⟩ } end SpectralOrder section NonnegSpectrumClass variable {A : Type*} [NonUnitalCStarAlgebra A] [PartialOrder A] [StarOrderedRing A] open scoped CStarAlgebra in instance CStarAlgebra.instNonnegSpectrumClass' : NonnegSpectrumClass ℝ A where quasispectrum_nonneg_of_nonneg a ha := by rw [Unitization.quasispectrum_eq_spectrum_inr' _ ℂ] -- should this actually be an instance on the `Unitization`? (probably scoped) let _ := CStarAlgebra.spectralOrder A⁺¹ have := CStarAlgebra.spectralOrderedRing A⁺¹ apply spectrum_nonneg_of_nonneg rw [StarOrderedRing.nonneg_iff] at ha ⊢ have := AddSubmonoid.mem_map_of_mem (Unitization.inrNonUnitalStarAlgHom ℂ A) ha rw [AddMonoidHom.map_mclosure, ← Set.range_comp] at this apply AddSubmonoid.closure_mono ?_ this rintro _ ⟨s, rfl⟩ exact ⟨s, by simp⟩ end NonnegSpectrumClass section cfc_inr open CStarAlgebra variable {A : Type*} [NonUnitalCStarAlgebra A] open scoped NonUnitalContinuousFunctionalCalculus in /-- This lemma requires a lot from type class synthesis, and so one should instead favor the bespoke versions for `ℝ≥0`, `ℝ`, and `ℂ`. -/ lemma Unitization.cfcₙ_eq_cfc_inr {R : Type*} [Semifield R] [StarRing R] [MetricSpace R] [IsTopologicalSemiring R] [ContinuousStar R] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [CompleteSpace R] [Algebra R ℂ] [IsScalarTower R ℂ A] {p : A → Prop} {p' : A⁺¹ → Prop} [NonUnitalContinuousFunctionalCalculus R A p] [ContinuousFunctionalCalculus R A⁺¹ p'] [ContinuousMapZero.UniqueHom R (Unitization ℂ A)] (hp : ∀ {a : A}, p' (a : A⁺¹) ↔ p a) (a : A) (f : R → R) (hf₀ : f 0 = 0 := by cfc_zero_tac) : cfcₙ f a = cfc f (a : A⁺¹) := by by_cases h : ContinuousOn f (σₙ R a) ∧ p a · obtain ⟨hf, ha⟩ := h rw [← cfcₙ_eq_cfc (quasispectrum_inr_eq R ℂ a ▸ hf)] exact (inrNonUnitalStarAlgHom ℂ A).map_cfcₙ f a · obtain (hf | ha) := not_and_or.mp h · rw [cfcₙ_apply_of_not_continuousOn a hf, inr_zero, cfc_apply_of_not_continuousOn _ (quasispectrum_eq_spectrum_inr' R ℂ a ▸ hf)] · rw [cfcₙ_apply_of_not_predicate a ha, inr_zero, cfc_apply_of_not_predicate _ (not_iff_not.mpr hp |>.mpr ha)] lemma Unitization.complex_cfcₙ_eq_cfc_inr (a : A) (f : ℂ → ℂ) (hf₀ : f 0 = 0 := by cfc_zero_tac) : cfcₙ f a = cfc f (a : A⁺¹) := Unitization.cfcₙ_eq_cfc_inr isStarNormal_inr .. /-- note: the version for `ℝ≥0`, `Unitization.nnreal_cfcₙ_eq_cfc_inr`, can be found in `Analysis/CStarAlgebra/ContinuousFunctionalCalculus/Order.lean` -/ lemma Unitization.real_cfcₙ_eq_cfc_inr (a : A) (f : ℝ → ℝ) (hf₀ : f 0 = 0 := by cfc_zero_tac) : cfcₙ f a = cfc f (a : A⁺¹) := Unitization.cfcₙ_eq_cfc_inr isSelfAdjoint_inr .. end cfc_inr /-! ### Instances of isometric continuous functional calculi -/ section Unital variable {A : Type*} [CStarAlgebra A] instance IsStarNormal.instIsometricContinuousFunctionalCalculus : IsometricContinuousFunctionalCalculus ℂ A IsStarNormal where isometric a ha := by rw [cfcHom_eq_of_isStarNormal] exact isometry_subtype_coe.comp <| StarAlgEquiv.isometry (continuousFunctionalCalculus a) instance IsSelfAdjoint.instIsometricContinuousFunctionalCalculus : IsometricContinuousFunctionalCalculus ℝ A IsSelfAdjoint := SpectrumRestricts.isometric_cfc Complex.reCLM Complex.isometry_ofReal (.zero _) fun _ ↦ isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts end Unital section NonUnital variable {A : Type*} [NonUnitalCStarAlgebra A] open Unitization open ContinuousMapZero in instance IsStarNormal.instNonUnitalIsometricContinuousFunctionalCalculus : NonUnitalIsometricContinuousFunctionalCalculus ℂ A IsStarNormal where isometric a ha := by refine AddMonoidHomClass.isometry_of_norm _ fun f ↦ ?_ rw [← norm_inr (𝕜 := ℂ), ← inrNonUnitalStarAlgHom_apply, ← NonUnitalStarAlgHom.comp_apply, inr_comp_cfcₙHom_eq_cfcₙAux a, cfcₙAux] simp only [NonUnitalStarAlgHom.comp_assoc, NonUnitalStarAlgHom.comp_apply, toContinuousMapHom_apply, NonUnitalStarAlgHom.coe_coe] rw [norm_cfcHom (a : Unitization ℂ A), StarAlgEquiv.norm_map] rfl instance IsSelfAdjoint.instNonUnitalIsometricContinuousFunctionalCalculus : NonUnitalIsometricContinuousFunctionalCalculus ℝ A IsSelfAdjoint := QuasispectrumRestricts.isometric_cfc Complex.reCLM Complex.isometry_ofReal (.zero _) fun _ ↦ isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts end NonUnital
Bilinear.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov -/ import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # Facts about algebras involving bilinear maps and tensor products We move a few basic statements about algebras out of `Algebra.Algebra.Basic`, in order to avoid importing `LinearAlgebra.BilinearMap` and `LinearAlgebra.TensorProduct` unnecessarily. -/ open TensorProduct Module namespace LinearMap section NonUnitalNonAssoc variable (R A : Type*) section one_side variable [Semiring R] [NonUnitalNonAssocSemiring A] [Module R A] section left variable {A} [SMulCommClass R A A] /-- The multiplication on the left in an algebra is a linear map. Note that this only assumes `SMulCommClass R A A`, so that it also works for `R := Aᵐᵒᵖ`. When `A` is unital and associative, this is the same as `DistribMulAction.toLinearMap R A a` -/ def mulLeft (a : A) : A →ₗ[R] A where toFun := (a * ·) map_add' := mul_add _ map_smul' _ := mul_smul_comm _ _ @[simp] theorem mulLeft_apply (a b : A) : mulLeft R a b = a * b := rfl @[simp] theorem mulLeft_toAddMonoidHom (a : A) : (mulLeft R a : A →+ A) = AddMonoidHom.mulLeft a := rfl variable (A) in @[simp] theorem mulLeft_zero_eq_zero : mulLeft R (0 : A) = 0 := ext fun _ => zero_mul _ end left section right variable {A} [IsScalarTower R A A] /-- The multiplication on the right in an algebra is a linear map. Note that this only assumes `IsScalarTower R A A`, so that it also works for `R := A`. When `A` is unital and associative, this is the same as `DistribMulAction.toLinearMap R A (MulOpposite.op b)`. -/ def mulRight (b : A) : A →ₗ[R] A where toFun := (· * b) map_add' _ _ := add_mul _ _ _ map_smul' _ _ := smul_mul_assoc _ _ _ @[simp] theorem mulRight_apply (a b : A) : mulRight R a b = b * a := rfl @[simp] theorem mulRight_toAddMonoidHom (a : A) : (mulRight R a : A →+ A) = AddMonoidHom.mulRight a := rfl variable (A) in @[simp] theorem mulRight_zero_eq_zero : mulRight R (0 : A) = 0 := ext fun _ => mul_zero _ end right end one_side variable [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] variable [SMulCommClass R A A] [IsScalarTower R A A] /-- The multiplication in a non-unital non-associative algebra is a bilinear map. A weaker version of this for semirings exists as `AddMonoidHom.mul`. -/ @[simps!] def mul : A →ₗ[R] A →ₗ[R] A := LinearMap.mk₂ R (· * ·) add_mul smul_mul_assoc mul_add mul_smul_comm /-- The multiplication map on a non-unital algebra, as an `R`-linear map from `A ⊗[R] A` to `A`. -/ -- TODO: upgrade to A-linear map if A is a semiring. def mul' : A ⊗[R] A →ₗ[R] A := TensorProduct.lift (mul R A) variable {A} /-- Simultaneous multiplication on the left and right is a linear map. -/ def mulLeftRight (ab : A × A) : A →ₗ[R] A := (mulRight R ab.snd).comp (mulLeft R ab.fst) variable {R} @[simp] theorem mul_apply' (a b : A) : mul R A a b = a * b := rfl @[simp] theorem mulLeftRight_apply (a b x : A) : mulLeftRight R (a, b) x = a * x * b := rfl @[simp] theorem mul'_apply {a b : A} : mul' R A (a ⊗ₜ b) = a * b := rfl end NonUnitalNonAssoc section NonUnital variable (R A B : Type*) section one_side variable [Semiring R] [NonUnitalSemiring A] [NonUnitalSemiring B] [Module R B] [Module R A] @[simp] theorem mulLeft_mul [SMulCommClass R A A] (a b : A) : mulLeft R (a * b) = (mulLeft R a).comp (mulLeft R b) := by ext simp only [mulLeft_apply, comp_apply, mul_assoc] @[simp] theorem mulRight_mul [IsScalarTower R A A] (a b : A) : mulRight R (a * b) = (mulRight R b).comp (mulRight R a) := by ext simp only [mulRight_apply, comp_apply, mul_assoc] end one_side variable [CommSemiring R] [NonUnitalSemiring A] [NonUnitalSemiring B] [Module R B] [Module R A] variable [SMulCommClass R A A] [IsScalarTower R A A] variable [SMulCommClass R B B] [IsScalarTower R B B] /-- The multiplication in a non-unital algebra is a bilinear map. A weaker version of this for non-unital non-associative algebras exists as `LinearMap.mul`. -/ def _root_.NonUnitalAlgHom.lmul : A →ₙₐ[R] End R A where __ := mul R A map_mul' := mulLeft_mul _ _ map_zero' := mulLeft_zero_eq_zero _ _ variable {R A B} @[simp] theorem _root_.NonUnitalAlgHom.coe_lmul_eq_mul : ⇑(NonUnitalAlgHom.lmul R A) = mul R A := rfl theorem commute_mulLeft_right (a b : A) : Commute (mulLeft R a) (mulRight R b) := by ext c exact (mul_assoc a c b).symm /-- A `LinearMap` preserves multiplication if pre- and post- composition with `LinearMap.mul` are equivalent. By converting the statement into an equality of `LinearMap`s, this lemma allows various specialized `ext` lemmas about `→ₗ[R]` to then be applied. This is the `LinearMap` version of `AddMonoidHom.map_mul_iff`. -/ theorem map_mul_iff (f : A →ₗ[R] B) : (∀ x y, f (x * y) = f x * f y) ↔ (LinearMap.mul R A).compr₂ f = (LinearMap.mul R B ∘ₗ f).compl₂ f := Iff.symm LinearMap.ext_iff₂ end NonUnital section Injective variable {R A : Type*} [Semiring R] [NonAssocSemiring A] [Module R A] @[simp] lemma mulLeft_inj [SMulCommClass R A A] {a b : A} : mulLeft R a = mulLeft R b ↔ a = b := ⟨fun h => by simpa using LinearMap.ext_iff.mp h 1, fun h => h ▸ rfl⟩ @[simp] lemma mulRight_inj [IsScalarTower R A A] {a b : A} : mulRight R a = mulRight R b ↔ a = b := ⟨fun h => by simpa using LinearMap.ext_iff.mp h 1, fun h => h ▸ rfl⟩ end Injective section Semiring variable (R A : Type*) section one_side variable [Semiring R] [Semiring A] section left variable [Module R A] [SMulCommClass R A A] @[simp] theorem mulLeft_one : mulLeft R (1 : A) = LinearMap.id := ext fun _ => one_mul _ @[simp] theorem mulLeft_eq_zero_iff (a : A) : mulLeft R a = 0 ↔ a = 0 := mulLeft_zero_eq_zero R A ▸ mulLeft_inj @[simp] theorem pow_mulLeft (a : A) (n : ℕ) : mulLeft R a ^ n = mulLeft R (a ^ n) := match n with | 0 => by rw [pow_zero, pow_zero, mulLeft_one, Module.End.one_eq_id] | (n + 1) => by rw [pow_succ, pow_succ, mulLeft_mul, Module.End.mul_eq_comp, pow_mulLeft] end left section right variable [Module R A] [IsScalarTower R A A] @[simp] theorem mulRight_one : mulRight R (1 : A) = LinearMap.id := ext fun _ => mul_one _ @[simp] theorem mulRight_eq_zero_iff (a : A) : mulRight R a = 0 ↔ a = 0 := mulRight_zero_eq_zero R A ▸ mulRight_inj @[simp] theorem pow_mulRight (a : A) (n : ℕ) : mulRight R a ^ n = mulRight R (a ^ n) := match n with | 0 => by rw [pow_zero, pow_zero, mulRight_one, Module.End.one_eq_id] | (n + 1) => by rw [pow_succ, pow_succ', mulRight_mul, Module.End.mul_eq_comp, pow_mulRight] end right end one_side variable [CommSemiring R] [Semiring A] [Algebra R A] /-- The multiplication in an algebra is an algebra homomorphism into the endomorphisms on the algebra. A weaker version of this for non-unital algebras exists as `NonUnitalAlgHom.lmul`. -/ def _root_.Algebra.lmul : A →ₐ[R] End R A where __ := NonUnitalAlgHom.lmul R A map_one' := mulLeft_one _ _ commutes' r := ext fun a => (Algebra.smul_def r a).symm variable {R A} @[simp] theorem _root_.Algebra.coe_lmul_eq_mul : ⇑(Algebra.lmul R A) = mul R A := rfl theorem _root_.Algebra.lmul_injective : Function.Injective (Algebra.lmul R A) := fun a₁ a₂ h ↦ by simpa using DFunLike.congr_fun h 1 theorem _root_.Algebra.lmul_isUnit_iff {x : A} : IsUnit (Algebra.lmul R A x) ↔ IsUnit x := by rw [Module.End.isUnit_iff, Iff.comm] exact IsUnit.isUnit_iff_mulLeft_bijective theorem toSpanSingleton_eq_algebra_linearMap : toSpanSingleton R A 1 = Algebra.linearMap R A := by ext; simp end Semiring end LinearMap
Triangulated.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.HomotopyCategory.Pretriangulated import Mathlib.CategoryTheory.Triangulated.Triangulated import Mathlib.CategoryTheory.ComposableArrows /-! The triangulated structure on the homotopy category of complexes In this file, we show that for any additive category `C`, the pretriangulated category `HomotopyCategory C (ComplexShape.up ℤ)` is triangulated. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits Pretriangulated ComposableArrows -- Explicit universe annotations were used in this file to improve perfomance #12737 universe v variable {C : Type*} [Category.{v} C] [Preadditive C] [HasBinaryBiproducts C] {X₁ X₂ X₃ : CochainComplex C ℤ} (f : X₁ ⟶ X₂) (g : X₂ ⟶ X₃) namespace CochainComplex open HomComplex mappingCone /-- Given two composable morphisms `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` in the category of cochain complexes, this is the canonical triangle `mappingCone f ⟶ mappingCone (f ≫ g) ⟶ mappingCone g ⟶ (mappingCone f)⟦1⟧`. -/ @[simps! mor₁ mor₂ mor₃ obj₁ obj₂ obj₃] noncomputable def mappingConeCompTriangle : Triangle (CochainComplex C ℤ) := Triangle.mk (map f (f ≫ g) (𝟙 X₁) g (by rw [id_comp])) (map (f ≫ g) g f (𝟙 X₃) (by rw [comp_id])) ((triangle g).mor₃ ≫ (inr f)⟦1⟧') /-- Given two composable morphisms `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` in the category of cochain complexes, this is the canonical triangle `mappingCone f ⟶ mappingCone (f ≫ g) ⟶ mappingCone g ⟶ (mappingCone f)⟦1⟧` in the homotopy category. It is a distinguished triangle, see `HomotopyCategory.mappingConeCompTriangleh_distinguished`. -/ noncomputable def mappingConeCompTriangleh : Triangle (HomotopyCategory C (ComplexShape.up ℤ)) := (HomotopyCategory.quotient _ _).mapTriangle.obj (mappingConeCompTriangle f g) @[reassoc] lemma mappingConeCompTriangle_mor₃_naturality {Y₁ Y₂ Y₃ : CochainComplex C ℤ} (f' : Y₁ ⟶ Y₂) (g' : Y₂ ⟶ Y₃) (φ : mk₂ f g ⟶ mk₂ f' g') : map g g' (φ.app 1) (φ.app 2) (naturality' φ 1 2) ≫ (mappingConeCompTriangle f' g').mor₃ = (mappingConeCompTriangle f g).mor₃ ≫ (map f f' (φ.app 0) (φ.app 1) (naturality' φ 0 1))⟦1⟧' := by ext n dsimp [map] -- the following list of lemmas was obtained by doing simp? [ext_from_iff _ (n + 1) _ rfl] simp only [Int.reduceNeg, Fin.isValue, assoc, inr_f_desc_f, HomologicalComplex.comp_f, ext_from_iff _ (n + 1) _ rfl, inl_v_desc_f_assoc, Cochain.zero_cochain_comp_v, Cochain.ofHom_v, inl_v_triangle_mor₃_f_assoc, triangle_obj₁, shiftFunctor_obj_X', shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, Preadditive.neg_comp, id_comp, Preadditive.comp_neg, inr_f_desc_f_assoc, inr_f_triangle_mor₃_f_assoc, zero_comp, comp_zero, and_self] namespace MappingConeCompHomotopyEquiv /-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this is the canonical morphism (which is an homotopy equivalence) from `mappingCone g` to the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)`. -/ noncomputable def hom : mappingCone g ⟶ mappingCone (mappingConeCompTriangle f g).mor₁ := lift _ (descCocycle g (Cochain.ofHom (inr f)) 0 (zero_add 1) (by simp)) (descCochain _ 0 (Cochain.ofHom (inr (f ≫ g))) (neg_add_cancel 1)) (by ext p _ rfl dsimp [mappingConeCompTriangle, map] simp [ext_from_iff _ _ _ rfl, inl_v_d_assoc _ (p+1) p (p+2) (by omega) (by omega)]) /-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this is the canonical morphism (which is an homotopy equivalence) from the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)` to `mappingCone g`. -/ noncomputable def inv : mappingCone (mappingConeCompTriangle f g).mor₁ ⟶ mappingCone g := desc _ ((snd f).comp (inl g) (zero_add (-1))) (desc _ ((Cochain.ofHom f).comp (inl g) (zero_add (-1))) (inr g) (by simp)) (by ext p rw [ext_from_iff _ (p + 1) _ rfl, ext_to_iff _ _ (p + 1) rfl] simp [map, δ_zero_cochain_comp, Cochain.comp_v _ _ (add_neg_cancel 1) p (p+1) p (by omega) (by omega)]) @[reassoc (attr := simp)] lemma hom_inv_id : hom f g ≫ inv f g = 𝟙 _ := by ext n simp [hom, inv, lift_desc_f _ _ _ _ _ _ _ n (n + 1) rfl, ext_from_iff _ (n + 1) _ rfl] /-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this is the `homotopyInvHomId` field of the homotopy equivalence `mappingConeCompHomotopyEquiv f g` between `mappingCone g` and the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)`. -/ noncomputable def homotopyInvHomId : Homotopy (inv f g ≫ hom f g) (𝟙 _) := (Cochain.equivHomotopy _ _).symm ⟨-((snd _).comp ((fst (f ≫ g)).1.comp ((inl f).comp (inl _) (by decide)) (show 1 + (-2) = -1 by decide)) (zero_add (-1))), by rw [δ_neg, δ_zero_cochain_comp _ _ _ (neg_add_cancel 1), Int.negOnePow_neg, Int.negOnePow_one, Units.neg_smul, one_smul, δ_comp _ _ (show 1 + (-2) = -1 by decide) 2 (-1) 0 (by decide) (by decide) (by decide), δ_comp _ _ (show (-1) + (-1) = -2 by decide) 0 0 (-1) (by decide) (by decide) (by decide), Int.negOnePow_neg, Int.negOnePow_neg, Int.negOnePow_even 2 ⟨1, by decide⟩, Int.negOnePow_one, Units.neg_smul, one_smul, one_smul, δ_inl, δ_inl, δ_snd, Cocycle.δ_eq_zero, Cochain.zero_comp, add_zero, Cochain.neg_comp, neg_neg] ext n rw [ext_from_iff _ (n + 1) n rfl, ext_from_iff _ (n + 1) n rfl, ext_from_iff _ (n + 2) (n + 1) (by omega)] dsimp [hom, inv] simp [ext_to_iff _ n (n + 1) rfl, map, Cochain.comp_v _ _ (add_neg_cancel 1) n (n + 1) n (by omega) (by omega), Cochain.comp_v _ _ (show 1 + -2 = -1 by decide) (n + 1) (n + 2) n (by omega) (by omega), Cochain.comp_v _ _ (show (-1) + -1 = -2 by decide) (n + 2) (n + 1) n (by omega) (by omega)]⟩ end MappingConeCompHomotopyEquiv /-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this is the homotopy equivalence `mappingConeCompHomotopyEquiv f g` between `mappingCone g` and the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)`. -/ noncomputable def mappingConeCompHomotopyEquiv : HomotopyEquiv (mappingCone g) (mappingCone (mappingConeCompTriangle f g).mor₁) where hom := MappingConeCompHomotopyEquiv.hom f g inv := MappingConeCompHomotopyEquiv.inv f g homotopyHomInvId := Homotopy.ofEq (by simp) homotopyInvHomId := MappingConeCompHomotopyEquiv.homotopyInvHomId f g @[reassoc (attr := simp)] lemma mappingConeCompHomotopyEquiv_hom_inv_id : (mappingConeCompHomotopyEquiv f g).hom ≫ (mappingConeCompHomotopyEquiv f g).inv = 𝟙 _ := by simp [mappingConeCompHomotopyEquiv] @[reassoc] lemma mappingConeCompHomotopyEquiv_comm₁ : inr (map f (f ≫ g) (𝟙 X₁) g (by rw [id_comp])) ≫ (mappingConeCompHomotopyEquiv f g).inv = (mappingConeCompTriangle f g).mor₂ := by simp [map, mappingConeCompHomotopyEquiv, MappingConeCompHomotopyEquiv.inv] @[reassoc] lemma mappingConeCompHomotopyEquiv_comm₂ : (mappingConeCompHomotopyEquiv f g).hom ≫ (triangle (mappingConeCompTriangle f g).mor₁).mor₃ = (mappingConeCompTriangle f g).mor₃ := by ext n simp [map, mappingConeCompHomotopyEquiv, MappingConeCompHomotopyEquiv.hom, lift_f _ _ _ _ _ (n + 1) rfl, ext_from_iff _ (n + 1) _ rfl] @[reassoc (attr := simp)] lemma mappingConeCompTriangleh_comm₁ : (mappingConeCompTriangleh f g).mor₂ ≫ (HomotopyCategory.quotient _ _).map (mappingConeCompHomotopyEquiv f g).hom = (HomotopyCategory.quotient _ _).map (mappingCone.inr _) := by rw [← cancel_mono (HomotopyCategory.isoOfHomotopyEquiv (mappingConeCompHomotopyEquiv f g)).inv, assoc] dsimp [mappingConeCompTriangleh] rw [← Functor.map_comp, ← Functor.map_comp, ← Functor.map_comp, mappingConeCompHomotopyEquiv_hom_inv_id, comp_id, mappingConeCompHomotopyEquiv_comm₁ f g, mappingConeCompTriangle_mor₂] end CochainComplex namespace HomotopyCategory open CochainComplex variable [HasZeroObject C] lemma mappingConeCompTriangleh_distinguished : (mappingConeCompTriangleh f g) ∈ distTriang (HomotopyCategory C (ComplexShape.up ℤ)) := by refine ⟨_, _, (mappingConeCompTriangle f g).mor₁, ⟨?_⟩⟩ refine Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (isoOfHomotopyEquiv (mappingConeCompHomotopyEquiv f g)) (by cat_disch) (by simp) ?_ dsimp [mappingConeCompTriangleh] rw [CategoryTheory.Functor.map_id, comp_id, ← Functor.map_comp_assoc] congr 2 exact (mappingConeCompHomotopyEquiv_comm₂ f g).symm noncomputable instance : IsTriangulated (HomotopyCategory C (ComplexShape.up ℤ)) := IsTriangulated.mk' (by rintro ⟨X₁ : CochainComplex C ℤ⟩ ⟨X₂ : CochainComplex C ℤ⟩ ⟨X₃ : CochainComplex C ℤ⟩ u₁₂' u₂₃' obtain ⟨u₁₂, rfl⟩ := (HomotopyCategory.quotient C (ComplexShape.up ℤ)).map_surjective u₁₂' obtain ⟨u₂₃, rfl⟩ := (HomotopyCategory.quotient C (ComplexShape.up ℤ)).map_surjective u₂₃' refine ⟨_, _, _, _, _, _, _, _, Iso.refl _, Iso.refl _, Iso.refl _, by simp, by simp, _, _, mappingCone_triangleh_distinguished u₁₂, _, _, mappingCone_triangleh_distinguished u₂₃, _, _, mappingCone_triangleh_distinguished (u₁₂ ≫ u₂₃), ⟨?_⟩⟩ let α := mappingCone.triangleMap u₁₂ (u₁₂ ≫ u₂₃) (𝟙 X₁) u₂₃ (by rw [id_comp]) let β := mappingCone.triangleMap (u₁₂ ≫ u₂₃) u₂₃ u₁₂ (𝟙 X₃) (by rw [comp_id]) refine Triangulated.Octahedron.mk ((HomotopyCategory.quotient _ _).map α.hom₃) ((HomotopyCategory.quotient _ _).map β.hom₃) ?_ ?_ ?_ ?_ ?_ · exact ((quotient _ _).mapTriangle.map α).comm₂ · exact ((quotient _ _).mapTriangle.map α).comm₃.symm.trans (by dsimp [α]; simp) · exact ((quotient _ _).mapTriangle.map β).comm₂.trans (by dsimp [β]; simp) · exact ((quotient _ _).mapTriangle.map β).comm₃ · refine isomorphic_distinguished _ (mappingConeCompTriangleh_distinguished u₁₂ u₂₃) _ ?_ exact Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (Iso.refl _) (by dsimp [α, mappingConeCompTriangleh]; simp) (by dsimp [β, mappingConeCompTriangleh]; simp) (by dsimp [mappingConeCompTriangleh]; simp)) end HomotopyCategory
Inductions.lean
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Damiano Testa, Jens Wagemaker -/ import Mathlib.Algebra.MonoidAlgebra.Division import Mathlib.Algebra.Polynomial.Degree.Operations import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Order.Interval.Finset.Nat /-! # Induction on polynomials This file contains lemmas dealing with different flavours of induction on polynomials. -/ noncomputable section open Polynomial open Finset namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} /-- `divX p` returns a polynomial `q` such that `q * X + C (p.coeff 0) = p`. It can be used in a semiring where the usual division algorithm is not possible -/ def divX (p : R[X]) : R[X] := ⟨AddMonoidAlgebra.divOf p.toFinsupp 1⟩ @[simp] theorem coeff_divX : (divX p).coeff n = p.coeff (n + 1) := by rw [add_comm]; cases p; rfl theorem divX_mul_X_add (p : R[X]) : divX p * X + C (p.coeff 0) = p := ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C, coeff_mul_X] @[simp] theorem X_mul_divX_add (p : R[X]) : X * divX p + C (p.coeff 0) = p := ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C] @[simp] theorem divX_C (a : R) : divX (C a) = 0 := ext fun n => by simp [coeff_divX] theorem divX_eq_zero_iff : divX p = 0 ↔ p = C (p.coeff 0) := ⟨fun h => by simpa [eq_comm, h] using divX_mul_X_add p, fun h => by rw [h, divX_C]⟩ theorem divX_add : divX (p + q) = divX p + divX q := ext <| by simp @[simp] theorem divX_zero : divX (0 : R[X]) = 0 := leadingCoeff_eq_zero.mp rfl @[simp] theorem divX_one : divX (1 : R[X]) = 0 := by ext simpa only [coeff_divX, coeff_zero] using coeff_one @[simp] theorem divX_C_mul : divX (C a * p) = C a * divX p := by ext simp theorem divX_X_pow : divX (X ^ n : R[X]) = if (n = 0) then 0 else X ^ (n - 1) := by cases n · simp · ext n simp [coeff_X_pow] /-- `divX` as an additive homomorphism. -/ noncomputable def divX_hom : R[X] →+ R[X] := { toFun := divX map_zero' := divX_zero map_add' := fun _ _ => divX_add } @[simp] theorem divX_hom_toFun : divX_hom p = divX p := rfl theorem natDegree_divX_eq_natDegree_tsub_one : p.divX.natDegree = p.natDegree - 1 := by apply map_natDegree_eq_sub (φ := divX_hom) · intro f simpa [divX_hom, divX_eq_zero_iff] using eq_C_of_natDegree_eq_zero · intros n c c0 rw [← C_mul_X_pow_eq_monomial, divX_hom_toFun, divX_C_mul, divX_X_pow] split_ifs with n0 · simp [n0] · exact natDegree_C_mul_X_pow (n - 1) c c0 theorem natDegree_divX_le : p.divX.natDegree ≤ p.natDegree := natDegree_divX_eq_natDegree_tsub_one.trans_le (Nat.pred_le _) theorem divX_C_mul_X_pow : divX (C a * X ^ n) = if n = 0 then 0 else C a * X ^ (n - 1) := by simp only [divX_C_mul, divX_X_pow, mul_ite, mul_zero] theorem degree_divX_lt (hp0 : p ≠ 0) : (divX p).degree < p.degree := by haveI := Nontrivial.of_polynomial_ne hp0 calc degree (divX p) < (divX p * X + C (p.coeff 0)).degree := if h : degree p ≤ 0 then by have h' : C (p.coeff 0) ≠ 0 := by rwa [← eq_C_of_degree_le_zero h] rw [eq_C_of_degree_le_zero h, divX_C, degree_zero, zero_mul, zero_add] exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 <| by simpa using h')) else by have hXp0 : divX p ≠ 0 := by simpa [divX_eq_zero_iff, -not_le, degree_le_zero_iff] using h have : leadingCoeff (divX p) * leadingCoeff X ≠ 0 := by simpa have : degree (C (p.coeff 0)) < degree (divX p * X) := calc degree (C (p.coeff 0)) ≤ 0 := degree_C_le _ < 1 := by decide _ = degree (X : R[X]) := degree_X.symm _ ≤ degree (divX p * X) := by rw [← zero_add (degree X), degree_mul' this] exact add_le_add (by rw [zero_le_degree_iff, Ne, divX_eq_zero_iff] exact fun h0 => h (h0.symm ▸ degree_C_le)) le_rfl rw [degree_add_eq_left_of_degree_lt this]; exact degree_lt_degree_mul_X hXp0 _ = degree p := congr_arg _ (divX_mul_X_add _) /-- An induction principle for polynomials, valued in Sort* instead of Prop. -/ @[elab_as_elim] noncomputable def recOnHorner {M : R[X] → Sort*} (p : R[X]) (M0 : M 0) (MC : ∀ p a, coeff p 0 = 0 → a ≠ 0 → M p → M (p + C a)) (MX : ∀ p, p ≠ 0 → M p → M (p * X)) : M p := letI := Classical.decEq R if hp : p = 0 then hp ▸ M0 else by have wf : degree (divX p) < degree p := degree_divX_lt hp rw [← divX_mul_X_add p] at * exact if hcp0 : coeff p 0 = 0 then by rw [hcp0, C_0, add_zero] exact MX _ (fun h : divX p = 0 => by simp [h, hcp0] at hp) (recOnHorner (divX p) M0 MC MX) else MC _ _ (coeff_mul_X_zero _) hcp0 (if hpX0 : divX p = 0 then show M (divX p * X) by rw [hpX0, zero_mul]; exact M0 else MX (divX p) hpX0 (recOnHorner _ M0 MC MX)) termination_by p.degree /-- A property holds for all polynomials of positive `degree` with coefficients in a semiring `R` if it holds for * `a * X`, with `a ∈ R`, * `p * X`, with `p ∈ R[X]`, * `p + a`, with `a ∈ R`, `p ∈ R[X]`, with appropriate restrictions on each term. See `natDegree_ne_zero_induction_on` for a similar statement involving no explicit multiplication. -/ @[elab_as_elim] theorem degree_pos_induction_on {P : R[X] → Prop} (p : R[X]) (h0 : 0 < degree p) (hC : ∀ {a}, a ≠ 0 → P (C a * X)) (hX : ∀ {p}, 0 < degree p → P p → P (p * X)) (hadd : ∀ {p} {a}, 0 < degree p → P p → P (p + C a)) : P p := recOnHorner p (fun h => by rw [degree_zero] at h; exact absurd h (by decide)) (fun p a heq0 _ ih h0 => (have : 0 < degree p := (lt_of_not_ge fun h => not_lt_of_ge (degree_C_le (a := a)) <| by rwa [eq_C_of_degree_le_zero h, ← C_add,heq0,zero_add] at h0) hadd this (ih this))) (fun p _ ih h0' => if h0 : 0 < degree p then hX h0 (ih h0) else by rw [eq_C_of_degree_le_zero (le_of_not_gt h0)] at h0' ⊢ exact hC fun h : coeff p 0 = 0 => by simp [h] at h0') h0 /-- A property holds for all polynomials of non-zero `natDegree` with coefficients in a semiring `R` if it holds for * `p + a`, with `a ∈ R`, `p ∈ R[X]`, * `p + q`, with `p, q ∈ R[X]`, * monomials with nonzero coefficient and non-zero exponent, with appropriate restrictions on each term. Note that multiplication is "hidden" in the assumption on monomials, so there is no explicit multiplication in the statement. See `degree_pos_induction_on` for a similar statement involving more explicit multiplications. -/ @[elab_as_elim] theorem natDegree_ne_zero_induction_on {M : R[X] → Prop} {f : R[X]} (f0 : f.natDegree ≠ 0) (h_C_add : ∀ {a p}, M p → M (C a + p)) (h_add : ∀ {p q}, M p → M q → M (p + q)) (h_monomial : ∀ {n : ℕ} {a : R}, a ≠ 0 → n ≠ 0 → M (monomial n a)) : M f := by suffices f.natDegree = 0 ∨ M f from Or.recOn this (fun h => (f0 h).elim) id refine Polynomial.induction_on f ?_ ?_ ?_ · exact fun a => Or.inl (natDegree_C _) · rintro p q (hp | hp) (hq | hq) · refine Or.inl ?_ rw [eq_C_of_natDegree_eq_zero hp, eq_C_of_natDegree_eq_zero hq, ← C_add, natDegree_C] · refine Or.inr ?_ rw [eq_C_of_natDegree_eq_zero hp] exact h_C_add hq · refine Or.inr ?_ rw [eq_C_of_natDegree_eq_zero hq, add_comm] exact h_C_add hp · exact Or.inr (h_add hp hq) · intro n a _ by_cases a0 : a = 0 · exact Or.inl (by rw [a0, C_0, zero_mul, natDegree_zero]) · refine Or.inr ?_ rw [C_mul_X_pow_eq_monomial] exact h_monomial a0 n.succ_ne_zero end Semiring end Polynomial
Canonical.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin, Patrick Massot -/ import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.GroupWithZero.WithZero import Mathlib.Algebra.Order.AddGroupWithTop import Mathlib.Algebra.Order.Group.Int import Mathlib.Algebra.Order.Monoid.Units import Mathlib.Algebra.Order.Monoid.Basic import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Algebra.Order.Monoid.TypeTags import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic /-! # Linearly ordered commutative groups and monoids with a zero element adjoined This file sets up a special class of linearly ordered commutative monoids that show up as the target of so-called “valuations” in algebraic number theory. Usually, in the informal literature, these objects are constructed by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}. The disadvantage is that a type such as `NNReal` is not of that form, whereas it is a very common target for valuations. The solutions is to use a typeclass, and that is exactly what we do in this file. -/ variable {α β : Type*} /-- A linearly ordered commutative monoid with a zero element. -/ class LinearOrderedCommMonoidWithZero (α : Type*) extends CommMonoidWithZero α, LinearOrder α, IsOrderedMonoid α, OrderBot α where /-- `0 ≤ 1` in any linearly ordered commutative monoid. -/ zero_le_one : (0 : α) ≤ 1 /-- A linearly ordered commutative group with a zero element. -/ class LinearOrderedCommGroupWithZero (α : Type*) extends LinearOrderedCommMonoidWithZero α, CommGroupWithZero α instance (priority := 100) LinearOrderedCommMonoidWithZero.toZeroLeOneClass [LinearOrderedCommMonoidWithZero α] : ZeroLEOneClass α := { ‹LinearOrderedCommMonoidWithZero α› with } instance (priority := 100) CanonicallyOrderedAdd.toZeroLeOneClass [AddZeroClass α] [LE α] [CanonicallyOrderedAdd α] [One α] : ZeroLEOneClass α := ⟨zero_le 1⟩ section LinearOrderedCommMonoidWithZero variable [LinearOrderedCommMonoidWithZero α] {a b : α} {n : ℕ} /- The following facts are true more generally in a (linearly) ordered commutative monoid. -/ /-- Pullback a `LinearOrderedCommMonoidWithZero` under an injective map. See note [reducible non-instances]. -/ abbrev Function.Injective.linearOrderedCommMonoidWithZero {β : Type*} [Zero β] [Bot β] [One β] [Mul β] [Pow β ℕ] [Max β] [Min β] (f : β → α) (hf : Function.Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) (bot : f ⊥ = ⊥) : LinearOrderedCommMonoidWithZero β where __ := LinearOrder.lift f hf hsup hinf __ := hf.isOrderedMonoid f one mul npow __ := hf.commMonoidWithZero f zero one mul npow zero_le_one := show f 0 ≤ f 1 by simp only [zero, one, LinearOrderedCommMonoidWithZero.zero_le_one] bot_le a := show f ⊥ ≤ f a from bot ▸ bot_le @[simp] lemma zero_le' : 0 ≤ a := by simpa only [mul_zero, mul_one] using mul_le_mul_left' (zero_le_one' α) a @[simp] theorem not_lt_zero' : ¬a < 0 := not_lt_of_ge zero_le' @[simp] theorem le_zero_iff : a ≤ 0 ↔ a = 0 := ⟨fun h ↦ le_antisymm h zero_le', fun h ↦ h ▸ le_rfl⟩ theorem zero_lt_iff : 0 < a ↔ a ≠ 0 := ⟨ne_of_gt, fun h ↦ lt_of_le_of_ne zero_le' h.symm⟩ theorem ne_zero_of_lt (h : b < a) : a ≠ 0 := fun h1 ↦ not_lt_zero' <| show b < 0 from h1 ▸ h /-- See also `bot_eq_zero` and `bot_eq_zero'` for canonically ordered monoids. -/ lemma bot_eq_zero'' : (⊥ : α) = 0 := eq_of_forall_ge_iff fun _ ↦ by simp instance instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual : LinearOrderedAddCommMonoidWithTop (Additive αᵒᵈ) where top := .ofMul <| .toDual 0 top_add' a := zero_mul a.toMul.ofDual le_top _ := zero_le' instance instLinearOrderedAddCommMonoidWithTopOrderDualAdditive : LinearOrderedAddCommMonoidWithTop (Additive α)ᵒᵈ where top := .toDual <| .ofMul _ top_add' := fun a ↦ zero_mul (Additive.toMul (OrderDual.ofDual a)) le_top := fun a ↦ @zero_le' _ _ (Additive.toMul (OrderDual.ofDual a)) variable [NoZeroDivisors α] lemma pow_pos_iff (hn : n ≠ 0) : 0 < a ^ n ↔ 0 < a := by simp_rw [zero_lt_iff, pow_ne_zero_iff hn] end LinearOrderedCommMonoidWithZero section LinearOrderedCommGroupWithZero variable [LinearOrderedCommGroupWithZero α] {a b c d : α} {m n : ℕ} -- See note [lower instance priority] instance (priority := 100) LinearOrderedCommGroupWithZero.toMulPosMono : MulPosMono α where elim _a _b _c hbc := mul_le_mul_right' hbc _ -- See note [lower instance priority] instance (priority := 100) LinearOrderedCommGroupWithZero.toPosMulMono : PosMulMono α where elim _a _b _c hbc := mul_le_mul_left' hbc _ -- See note [lower instance priority] instance (priority := 100) LinearOrderedCommGroupWithZero.toPosMulReflectLE : PosMulReflectLE α where elim a b c hbc := by simpa [a.2.ne'] using mul_le_mul_left' hbc a⁻¹ -- See note [lower instance priority] instance (priority := 100) LinearOrderedCommGroupWithZero.toMulPosReflectLE : MulPosReflectLE α where elim a b c hbc := by simpa [a.2.ne'] using mul_le_mul_right' hbc a⁻¹ -- See note [lower instance priority] instance (priority := 100) LinearOrderedCommGroupWithZero.toPosMulReflectLT : PosMulReflectLT α where elim _a _b _c := lt_of_mul_lt_mul_left' #adaptation_note /-- 2025-03-29 lean4#7717 Needed to add `dsimp only` -/ -- See note [lower instance priority] instance (priority := 100) LinearOrderedCommGroupWithZero.toPosMulStrictMono : PosMulStrictMono α where elim a b c hbc := by dsimp only; by_contra! h; exact hbc.not_ge <| (mul_le_mul_left a.2).1 h #adaptation_note /-- 2025-03-29 lean4#7717 Needed to add `dsimp only` -/ -- See note [lower instance priority] instance (priority := 100) LinearOrderedCommGroupWithZero.toMulPosStrictMono : MulPosStrictMono α where elim a b c hbc := by dsimp only; by_contra! h; exact hbc.not_ge <| (mul_le_mul_right a.2).1 h @[simp] theorem Units.zero_lt (u : αˣ) : (0 : α) < u := zero_lt_iff.2 u.ne_zero theorem mul_inv_lt_of_lt_mul₀ (h : a < b * c) : a * c⁻¹ < b := by contrapose! h simpa only [inv_inv] using mul_inv_le_of_le_mul₀ zero_le' zero_le' h theorem inv_mul_lt_of_lt_mul₀ (h : a < b * c) : b⁻¹ * a < c := by rw [mul_comm] at * exact mul_inv_lt_of_lt_mul₀ h theorem lt_of_mul_lt_mul_of_le₀ (h : a * b < c * d) (hc : 0 < c) (hh : c ≤ a) : b < d := by have ha : a ≠ 0 := ne_of_gt (lt_of_lt_of_le hc hh) rw [← inv_le_inv₀ (zero_lt_iff.2 ha) hc] at hh simpa [inv_mul_cancel_left₀ ha, inv_mul_cancel_left₀ hc.ne'] using mul_lt_mul_of_le_of_lt_of_nonneg_of_pos hh h zero_le' (inv_pos.2 hc) instance : LinearOrderedAddCommGroupWithTop (Additive αᵒᵈ) where neg_top := inv_zero (G₀ := α) add_neg_cancel := fun a ha ↦ mul_inv_cancel₀ (G₀ := α) (id ha : a.toMul ≠ 0) instance : LinearOrderedAddCommGroupWithTop (Additive α)ᵒᵈ where neg_top := inv_zero (G₀ := α) add_neg_cancel := fun a ha ↦ mul_inv_cancel₀ (G₀ := α) (id ha : a.toMul ≠ 0) end LinearOrderedCommGroupWithZero instance instLinearOrderedCommMonoidWithZeroMultiplicativeOrderDual [LinearOrderedAddCommMonoidWithTop α] : LinearOrderedCommMonoidWithZero (Multiplicative αᵒᵈ) where zero := Multiplicative.ofAdd (OrderDual.toDual ⊤) zero_mul := @top_add _ (_) -- Porting note: Here and elsewhere in the file, just `zero_mul` worked in Lean 3. See -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Type.20synonyms mul_zero := @add_top _ (_) zero_le_one := (le_top : (0 : α) ≤ ⊤) @[simp] theorem ofAdd_toDual_eq_zero_iff [LinearOrderedAddCommMonoidWithTop α] (x : α) : Multiplicative.ofAdd (OrderDual.toDual x) = 0 ↔ x = ⊤ := Iff.rfl @[simp] theorem ofDual_toAdd_eq_top_iff [LinearOrderedAddCommMonoidWithTop α] (x : Multiplicative αᵒᵈ) : OrderDual.ofDual x.toAdd = ⊤ ↔ x = 0 := Iff.rfl @[simp] theorem ofAdd_bot [LinearOrderedAddCommMonoidWithTop α] : Multiplicative.ofAdd ⊥ = (0 : Multiplicative αᵒᵈ) := rfl @[simp] theorem ofDual_toAdd_zero [LinearOrderedAddCommMonoidWithTop α] : OrderDual.ofDual (0 : Multiplicative αᵒᵈ).toAdd = ⊤ := rfl instance [LinearOrderedAddCommGroupWithTop α] : LinearOrderedCommGroupWithZero (Multiplicative αᵒᵈ) := { Multiplicative.divInvMonoid, instLinearOrderedCommMonoidWithZeroMultiplicativeOrderDual, Multiplicative.instNontrivial with inv_zero := @LinearOrderedAddCommGroupWithTop.neg_top _ (_) mul_inv_cancel := @LinearOrderedAddCommGroupWithTop.add_neg_cancel _ (_) } namespace WithZero section Preorder variable [Preorder α] [Preorder β] {x : WithZero α} {a b : α} instance instPreorder : Preorder (WithZero α) := WithBot.preorder instance instOrderBot : OrderBot (WithZero α) := WithBot.orderBot @[simp] lemma zero_le (a : WithZero α) : 0 ≤ a := bot_le @[simp] lemma zero_lt_coe (a : α) : (0 : WithZero α) < a := WithBot.bot_lt_coe a @[simp] lemma not_coe_le_zero : ¬ a ≤ (0 : WithZero α) := WithBot.not_coe_le_bot a @[simp] lemma not_lt_zero : ¬ x < (0 : WithZero α) := WithBot.not_lt_bot _ lemma zero_eq_bot : (0 : WithZero α) = ⊥ := rfl @[simp, norm_cast] lemma coe_lt_coe : (a : WithZero α) < b ↔ a < b := WithBot.coe_lt_coe @[simp, norm_cast] lemma coe_le_coe : (a : WithZero α) ≤ b ↔ a ≤ b := WithBot.coe_le_coe @[simp, norm_cast] lemma one_lt_coe [One α] : 1 < (a : WithZero α) ↔ 1 < a := coe_lt_coe @[simp, norm_cast] lemma one_le_coe [One α] : 1 ≤ (a : WithZero α) ↔ 1 ≤ a := coe_le_coe @[simp, norm_cast] lemma coe_lt_one [One α] : (a : WithZero α) < 1 ↔ a < 1 := coe_lt_coe @[simp, norm_cast] lemma coe_le_one [One α] : (a : WithZero α) ≤ 1 ↔ a ≤ 1 := coe_le_coe theorem coe_le_iff {x : WithZero α} : (a : WithZero α) ≤ x ↔ ∃ b : α, x = b ∧ a ≤ b := WithBot.coe_le_iff @[simp] lemma unzero_le_unzero {a b : WithZero α} (ha hb) : unzero (x := a) ha ≤ unzero (x := b) hb ↔ a ≤ b := by -- TODO: Fix `lift` so that it doesn't try to clear the hypotheses I give it when it is -- impossible to do so. See https://github.com/leanprover-community/mathlib4/issues/19160 lift a to α using id ha lift b to α using id hb simp instance instMulLeftMono [Mul α] [MulLeftMono α] : MulLeftMono (WithZero α) := by refine ⟨fun a b c hbc => ?_⟩ induction a; · exact zero_le _ induction b; · exact zero_le _ rcases WithZero.coe_le_iff.1 hbc with ⟨c, rfl, hbc'⟩ rw [← coe_mul _ c, ← coe_mul, coe_le_coe] exact mul_le_mul_left' hbc' _ protected lemma addLeftMono [AddZeroClass α] [AddLeftMono α] (h : ∀ a : α, 0 ≤ a) : AddLeftMono (WithZero α) := by refine ⟨fun a b c hbc => ?_⟩ induction a · rwa [zero_add, zero_add] induction b · rw [add_zero] induction c · rw [add_zero] · rw [← coe_add, coe_le_coe] exact le_add_of_nonneg_right (h _) · rcases WithZero.coe_le_iff.1 hbc with ⟨c, rfl, hbc'⟩ rw [← coe_add, ← coe_add _ c, coe_le_coe] exact add_le_add_left hbc' _ instance instExistsAddOfLE [Add α] [ExistsAddOfLE α] : ExistsAddOfLE (WithZero α) := ⟨fun {a b} => by induction a · exact fun _ => ⟨b, (zero_add b).symm⟩ induction b · exact fun h => (WithBot.not_coe_le_bot _ h).elim intro h obtain ⟨c, rfl⟩ := exists_add_of_le (WithZero.coe_le_coe.1 h) exact ⟨c, rfl⟩⟩ lemma map'_mono [MulOneClass α] [MulOneClass β] {f : α →* β} (hf : Monotone f) : Monotone (map' f) := by simpa [Monotone, WithZero.forall] lemma map'_strictMono [MulOneClass α] [MulOneClass β] {f : α →* β} (hf : StrictMono f) : StrictMono (map' f) := by simpa [StrictMono, WithZero.forall] theorem exists_ne_zero_and_lt [NoMinOrder α] (hx : x ≠ 0) : ∃ y, y ≠ 0 ∧ y < x := by obtain ⟨z, hlt⟩ := exists_lt (WithZero.unzero hx) rw [← WithZero.coe_lt_coe, WithZero.coe_unzero hx] at hlt exact ⟨z, WithZero.coe_ne_zero, hlt⟩ section Multiplicative open Multiplicative theorem toAdd_unzero_lt_of_lt_ofAdd {a : WithZero (Multiplicative α)} {b : α} (ha : a ≠ 0) (h : a < ofAdd b) : toAdd (unzero ha) < b := by rwa [← coe_unzero ha, coe_lt_coe, ← toAdd_lt, toAdd_ofAdd] at h theorem lt_ofAdd_of_toAdd_unzero_lt {a : WithZero (Multiplicative α)} {b : α} (ha : a ≠ 0) (h : toAdd (unzero ha) < b) : a < ofAdd b := by rwa [← coe_unzero ha, coe_lt_coe, ← ofAdd_toAdd (unzero ha), ofAdd_lt] theorem lt_ofAdd_iff {a : WithZero (Multiplicative α)} {b : α} (ha : a ≠ 0) : a < ofAdd b ↔ toAdd (unzero ha) < b := ⟨toAdd_unzero_lt_of_lt_ofAdd ha, lt_ofAdd_of_toAdd_unzero_lt ha⟩ theorem toAdd_unzero_le_of_lt_ofAdd {a : WithZero (Multiplicative α)} {b : α} (ha : a ≠ 0) (h : a ≤ ofAdd b) : toAdd (unzero ha) ≤ b := by rwa [← coe_unzero ha, coe_le_coe, ← toAdd_le, toAdd_ofAdd] at h theorem le_ofAdd_of_toAdd_unzero_le {a : WithZero (Multiplicative α)} {b : α} (ha : a ≠ 0) (h : toAdd (unzero ha) ≤ b) : a ≤ ofAdd b := by rwa [← coe_unzero ha, coe_le_coe, ← ofAdd_toAdd (unzero ha), ofAdd_le] theorem le_ofAdd_iff {a : WithZero (Multiplicative α)} {b : α} (ha : a ≠ 0) : a ≤ ofAdd b ↔ toAdd (unzero ha) ≤ b := ⟨toAdd_unzero_le_of_lt_ofAdd ha, le_ofAdd_of_toAdd_unzero_le ha⟩ end Multiplicative end Preorder section PartialOrder variable [PartialOrder α] instance instPartialOrder : PartialOrder (WithZero α) := WithBot.partialOrder instance instMulLeftReflectLT [Mul α] [MulLeftReflectLT α] : MulLeftReflectLT (WithZero α) := by refine ⟨fun a b c h => ?_⟩ have := ((zero_le _).trans_lt h).ne' induction a · simp at this induction c · simp at this induction b exacts [zero_lt_coe _, coe_lt_coe.mpr (lt_of_mul_lt_mul_left' <| coe_lt_coe.mp h)] end PartialOrder instance instLattice [Lattice α] : Lattice (WithZero α) := WithBot.lattice section LinearOrder variable [LinearOrder α] {a b c : α} {x y : WithZero α} instance instLinearOrder : LinearOrder (WithZero α) := WithBot.linearOrder protected lemma le_max_iff : (a : WithZero α) ≤ max (b : WithZero α) c ↔ a ≤ max b c := by simp only [WithZero.coe_le_coe, le_max_iff] protected lemma min_le_iff : min (a : WithZero α) b ≤ c ↔ min a b ≤ c := by simp only [WithZero.coe_le_coe, min_le_iff] theorem exists_ne_zero_and_le_and_le (hx : x ≠ 0) (hy : y ≠ 0) : ∃ z, z ≠ 0 ∧ z ≤ x ∧ z ≤ y := ⟨x ⊓ y, by simp [min_eq_iff, hx, hy], by simp, by simp⟩ theorem exists_ne_zero_and_lt_and_lt [NoMinOrder α] (hx : x ≠ 0) (hy : y ≠ 0) : ∃ z, z ≠ 0 ∧ z < x ∧ z < y := by obtain ⟨z', hnz', hzx, hzy⟩ := exists_ne_zero_and_le_and_le hx hy obtain ⟨z, hnz, hlt⟩ := exists_ne_zero_and_lt hnz' use z, hnz constructor <;> exact lt_of_lt_of_le hlt ‹z' ≤ _› end LinearOrder instance isOrderedMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] : IsOrderedMonoid (WithZero α) where mul_le_mul_left := fun _ _ => mul_le_mul_left' /- Note 1 : the below is not an instance because it requires `zero_le`. It seems like a rather pathological definition because α already has a zero. Note 2 : there is no multiplicative analogue because it does not seem necessary. Mathematicians might be more likely to use the order-dual version, where all elements are ≤ 1 and then 1 is the top element. -/ /-- If `0` is the least element in `α`, then `WithZero α` is an ordered `AddMonoid`. -/ -- See note [reducible non-instances] protected lemma isOrderedAddMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] (zero_le : ∀ a : α, 0 ≤ a) : IsOrderedAddMonoid (WithZero α) where add_le_add_left := @add_le_add_left _ _ _ (WithZero.addLeftMono zero_le) /-- Adding a new zero to a canonically ordered additive monoid produces another one. -/ instance instCanonicallyOrderedAdd [AddZeroClass α] [Preorder α] [CanonicallyOrderedAdd α] : CanonicallyOrderedAdd (WithZero α) := { WithZero.instExistsAddOfLE with le_self_add := fun a b => by induction a · exact bot_le induction b · exact le_rfl · exact WithZero.coe_le_coe.2 le_self_add } instance instLinearOrderedCommMonoidWithZero [CommMonoid α] [LinearOrder α] [IsOrderedMonoid α] : LinearOrderedCommMonoidWithZero (WithZero α) where zero_le_one := WithZero.zero_le _ instance instLinearOrderedCommGroupWithZero [CommGroup α] [LinearOrder α] [IsOrderedMonoid α] : LinearOrderedCommGroupWithZero (WithZero α) where /-! ### Exponential and logarithm -/ variable {G : Type*} [Preorder G] {a b : G} @[simp] lemma exp_le_exp : exp a ≤ exp b ↔ a ≤ b := by simp [exp] @[simp] lemma exp_lt_exp : exp a < exp b ↔ a < b := by simp [exp] @[simp] lemma exp_pos : 0 < exp a := by simp [exp] variable [AddGroup G] {x y : Gᵐ⁰} @[simp] lemma log_le_log (hx : x ≠ 0) (hy : y ≠ 0) : log x ≤ log y ↔ x ≤ y := by lift x to Multiplicative G using hx; lift y to Multiplicative G using hy; simp [log] @[simp] lemma log_lt_log (hx : x ≠ 0) (hy : y ≠ 0) : log x < log y ↔ x < y := by lift x to Multiplicative G using hx; lift y to Multiplicative G using hy; simp [log] lemma log_le_iff_le_exp (hx : x ≠ 0) : log x ≤ a ↔ x ≤ exp a := by lift x to Multiplicative G using hx; simpa [log, exp] using .rfl lemma log_lt_iff_lt_exp (hx : x ≠ 0) : log x < a ↔ x < exp a := by lift x to Multiplicative G using hx; simpa [log, exp] using .rfl lemma le_log_iff_exp_le (hx : x ≠ 0) : a ≤ log x ↔ exp a ≤ x := by lift x to Multiplicative G using hx; simpa [log, exp] using .rfl lemma lt_log_iff_exp_lt (hx : x ≠ 0) : a < log x ↔ exp a < x := by lift x to Multiplicative G using hx; simpa [log, exp] using .rfl lemma le_exp_of_log_le (hxa : log x ≤ a) : x ≤ exp a := by obtain rfl | hx := eq_or_ne x 0 <;> simp [← log_le_iff_le_exp, *] lemma lt_exp_of_log_lt (hxa : log x < a) : x < exp a := by obtain rfl | hx := eq_or_ne x 0 <;> simp [← log_lt_iff_lt_exp, *] lemma le_log_of_exp_le (hax : exp a ≤ x) : a ≤ log x := (le_log_iff_exp_le (exp_pos.trans_le hax).ne').2 hax lemma lt_log_of_exp_lt (hax : exp a < x) : a < log x := (lt_log_iff_exp_lt (exp_pos.trans hax).ne').2 hax /-- The exponential map as an order isomorphism between `G` and `Gᵐ⁰ˣ`. -/ @[simps!] def expOrderIso : G ≃o Gᵐ⁰ˣ where __ := expEquiv map_rel_iff' := by simp [← Units.val_le_val] /-- The logarithm as an order isomorphism between `Gᵐ⁰ˣ` and `G`. -/ @[simps!] def logOrderIso : Gᵐ⁰ˣ ≃o G where __ := logEquiv map_rel_iff' := by simp lemma lt_mul_exp_iff_le {x y : ℤᵐ⁰} (hy : y ≠ 0) : x < y * exp 1 ↔ x ≤ y := by lift y to Multiplicative ℤ using hy obtain rfl | hx := eq_or_ne x 0 · simp lift x to Multiplicative ℤ using hx rw [← log_le_log, ← log_lt_log] <;> simp [log_mul, Int.lt_add_one_iff] end WithZero
Partial.lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Order.Filter.Tendsto import Mathlib.Data.PFun /-! # `Tendsto` for relations and partial functions This file generalizes `Filter` definitions from functions to partial functions and relations. ## Considering functions and partial functions as relations A function `f : α → β` can be considered as the relation `Rel α β` which relates `x` and `f x` for all `x`, and nothing else. This relation is called `Function.Graph f`. A partial function `f : α →. β` can be considered as the relation `Rel α β` which relates `x` and `f x` for all `x` for which `f x` exists, and nothing else. This relation is called `PFun.Graph' f`. In this regard, a function is a relation for which every element in `α` is related to exactly one element in `β` and a partial function is a relation for which every element in `α` is related to at most one element in `β`. This file leverages this analogy to generalize `Filter` definitions from functions to partial functions and relations. ## Notes `Set.preimage` can be generalized to relations in two ways: * `Rel.preimage` returns the image of the set under the inverse relation. * `Rel.core` returns the set of elements that are only related to those in the set. Both generalizations are sensible in the context of filters, so `Filter.comap` and `Filter.Tendsto` get two generalizations each. We first take care of relations. Then the definitions for partial functions are taken as special cases of the definitions for relations. -/ universe u v w namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} open Filter /-! ### Relations -/ /-- The forward map of a filter under a relation. Generalization of `Filter.map` to relations. Note that `Rel.core` generalizes `Set.preimage`. -/ def rmap (r : SetRel α β) (l : Filter α) : Filter β where sets := { s | r.core s ∈ l } univ_sets := by simp sets_of_superset hs st := mem_of_superset hs (SetRel.core_mono st) inter_sets hs ht := by simp only [Set.mem_setOf_eq] convert inter_mem hs ht rw [← SetRel.core_inter] theorem rmap_sets (r : SetRel α β) (l : Filter α) : (l.rmap r).sets = r.core ⁻¹' l.sets := rfl @[simp] theorem mem_rmap (r : SetRel α β) (l : Filter α) (s : Set β) : s ∈ l.rmap r ↔ r.core s ∈ l := Iff.rfl @[simp] theorem rmap_rmap (r : SetRel α β) (s : SetRel β γ) (l : Filter α) : rmap s (rmap r l) = rmap (r.comp s) l := filter_eq <| by simp [rmap_sets, Set.preimage, SetRel.core_comp] @[simp] theorem rmap_compose (r : SetRel α β) (s : SetRel β γ) : rmap s ∘ rmap r = rmap (r.comp s) := funext <| rmap_rmap _ _ /-- Generic "limit of a relation" predicate. `RTendsto r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `r`-core of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to relations. -/ def RTendsto (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) := l₁.rmap r ≤ l₂ theorem rtendsto_def (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) : RTendsto r l₁ l₂ ↔ ∀ s ∈ l₂, r.core s ∈ l₁ := Iff.rfl /-- One way of taking the inverse map of a filter under a relation. One generalization of `Filter.comap` to relations. Note that `Rel.core` generalizes `Set.preimage`. -/ def rcomap (r : SetRel α β) (f : Filter β) : Filter α where sets := SetRel.image {(s, t) : _ × _ | r.core s ⊆ t} f.sets univ_sets := ⟨Set.univ, univ_mem, Set.subset_univ _⟩ sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩ inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ => ⟨a' ∩ b', inter_mem ha₁ hb₁, (r.core_inter a' b').subset.trans (Set.inter_subset_inter ha₂ hb₂)⟩ theorem rcomap_sets (r : SetRel α β) (f : Filter β) : (rcomap r f).sets = SetRel.image {(s, t) : _ × _ | r.core s ⊆ t} f.sets := rfl theorem rcomap_rcomap (r : SetRel α β) (s : SetRel β γ) (l : Filter γ) : rcomap r (rcomap s l) = rcomap (r.comp s) l := filter_eq <| by ext t simp only [rcomap_sets, SetRel.image, Filter.mem_sets, Set.mem_setOf_eq,SetRel.core_comp] constructor · rintro ⟨u, ⟨v, vsets, hv⟩, h⟩ exact ⟨v, vsets, Set.Subset.trans (SetRel.core_mono hv) h⟩ rintro ⟨t, tsets, ht⟩ exact ⟨SetRel.core s t, ⟨t, tsets, Set.Subset.rfl⟩, ht⟩ @[simp] theorem rcomap_compose (r : SetRel α β) (s : SetRel β γ) : rcomap r ∘ rcomap s = rcomap (r.comp s) := funext <| rcomap_rcomap _ _ theorem rtendsto_iff_le_rcomap (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) : RTendsto r l₁ l₂ ↔ l₁ ≤ l₂.rcomap r := by rw [rtendsto_def] simp_rw [← l₂.mem_sets] constructor · simpa [Filter.le_def, rcomap, SetRel.mem_image] using fun h s t tl₂ => mem_of_superset (h t tl₂) · simpa [Filter.le_def, rcomap, SetRel.mem_image] using fun h t tl₂ => h _ t tl₂ Set.Subset.rfl -- Interestingly, there does not seem to be a way to express this relation using a forward map. -- Given a filter `f` on `α`, we want a filter `f'` on `β` such that `r.preimage s ∈ f` if -- and only if `s ∈ f'`. But the intersection of two sets satisfying the lhs may be empty. /-- One way of taking the inverse map of a filter under a relation. Generalization of `Filter.comap` to relations. -/ def rcomap' (r : SetRel α β) (f : Filter β) : Filter α where sets := SetRel.image {(s, t) : _ × _ | r.preimage s ⊆ t} f.sets univ_sets := ⟨Set.univ, univ_mem, Set.subset_univ _⟩ sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩ inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ => ⟨a' ∩ b', inter_mem ha₁ hb₁, r.preimage_inter_subset.trans (Set.inter_subset_inter ha₂ hb₂)⟩ @[simp] theorem mem_rcomap' (r : SetRel α β) (l : Filter β) (s : Set α) : s ∈ l.rcomap' r ↔ ∃ t ∈ l, r.preimage t ⊆ s := Iff.rfl theorem rcomap'_sets (r : SetRel α β) (f : Filter β) : (rcomap' r f).sets = SetRel.image {(s, t) | r.preimage s ⊆ t} f.sets := rfl @[simp] theorem rcomap'_rcomap' (r : SetRel α β) (s : SetRel β γ) (l : Filter γ) : rcomap' r (rcomap' s l) = rcomap' (r.comp s) l := Filter.ext fun t => by simp only [mem_rcomap', SetRel.preimage_comp] constructor · rintro ⟨u, ⟨v, vsets, hv⟩, h⟩ exact ⟨v, vsets, (SetRel.preimage_mono hv).trans h⟩ rintro ⟨t, tsets, ht⟩ exact ⟨s.preimage t, ⟨t, tsets, Set.Subset.rfl⟩, ht⟩ @[simp] theorem rcomap'_compose (r : SetRel α β) (s : SetRel β γ) : rcomap' r ∘ rcomap' s = rcomap' (r.comp s) := funext <| rcomap'_rcomap' _ _ /-- Generic "limit of a relation" predicate. `RTendsto' r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `r`-preimage of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to relations. -/ def RTendsto' (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) := l₁ ≤ l₂.rcomap' r theorem rtendsto'_def (r : SetRel α β) (l₁ : Filter α) (l₂ : Filter β) : RTendsto' r l₁ l₂ ↔ ∀ s ∈ l₂, r.preimage s ∈ l₁ := by unfold RTendsto' rcomap'; constructor · simpa [le_def, SetRel.mem_image] using fun h s hs => h _ _ hs Set.Subset.rfl · simpa [le_def, SetRel.mem_image] using fun h s t ht => mem_of_superset (h t ht) theorem tendsto_iff_rtendsto (l₁ : Filter α) (l₂ : Filter β) (f : α → β) : Tendsto f l₁ l₂ ↔ RTendsto (Function.graph f) l₁ l₂ := by simp [tendsto_def, Function.graph, rtendsto_def, SetRel.core, Set.preimage] theorem tendsto_iff_rtendsto' (l₁ : Filter α) (l₂ : Filter β) (f : α → β) : Tendsto f l₁ l₂ ↔ RTendsto' (Function.graph f) l₁ l₂ := by simp [tendsto_def, Function.graph, rtendsto'_def, SetRel.preimage, Set.preimage] /-! ### Partial functions -/ /-- The forward map of a filter under a partial function. Generalization of `Filter.map` to partial functions. -/ def pmap (f : α →. β) (l : Filter α) : Filter β := Filter.rmap f.graph' l @[simp] theorem mem_pmap (f : α →. β) (l : Filter α) (s : Set β) : s ∈ l.pmap f ↔ f.core s ∈ l := Iff.rfl /-- Generic "limit of a partial function" predicate. `PTendsto r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `p`-core of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to partial function. -/ def PTendsto (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) := l₁.pmap f ≤ l₂ theorem ptendsto_def (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) : PTendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f.core s ∈ l₁ := Iff.rfl theorem ptendsto_iff_rtendsto (l₁ : Filter α) (l₂ : Filter β) (f : α →. β) : PTendsto f l₁ l₂ ↔ RTendsto f.graph' l₁ l₂ := Iff.rfl theorem pmap_res (l : Filter α) (s : Set α) (f : α → β) : pmap (PFun.res f s) l = map f (l ⊓ 𝓟 s) := by ext t simp only [PFun.core_res, mem_pmap, mem_map, mem_inf_principal, imp_iff_not_or] rfl theorem tendsto_iff_ptendsto (l₁ : Filter α) (l₂ : Filter β) (s : Set α) (f : α → β) : Tendsto f (l₁ ⊓ 𝓟 s) l₂ ↔ PTendsto (PFun.res f s) l₁ l₂ := by simp only [Tendsto, PTendsto, pmap_res] theorem tendsto_iff_ptendsto_univ (l₁ : Filter α) (l₂ : Filter β) (f : α → β) : Tendsto f l₁ l₂ ↔ PTendsto (PFun.res f Set.univ) l₁ l₂ := by rw [← tendsto_iff_ptendsto] simp [principal_univ] /-- Inverse map of a filter under a partial function. One generalization of `Filter.comap` to partial functions. -/ def pcomap' (f : α →. β) (l : Filter β) : Filter α := Filter.rcomap' f.graph' l /-- Generic "limit of a partial function" predicate. `PTendsto' r l₁ l₂` asserts that for every `l₂`-neighborhood `a`, the `p`-preimage of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to partial functions. -/ def PTendsto' (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) := l₁ ≤ l₂.rcomap' f.graph' theorem ptendsto'_def (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) : PTendsto' f l₁ l₂ ↔ ∀ s ∈ l₂, f.preimage s ∈ l₁ := rtendsto'_def _ _ _ theorem ptendsto_of_ptendsto' {f : α →. β} {l₁ : Filter α} {l₂ : Filter β} : PTendsto' f l₁ l₂ → PTendsto f l₁ l₂ := by rw [ptendsto_def, ptendsto'_def] exact fun h s sl₂ => mem_of_superset (h s sl₂) (PFun.preimage_subset_core _ _) theorem ptendsto'_of_ptendsto {f : α →. β} {l₁ : Filter α} {l₂ : Filter β} (h : f.Dom ∈ l₁) : PTendsto f l₁ l₂ → PTendsto' f l₁ l₂ := by rw [ptendsto_def, ptendsto'_def] intro h' s sl₂ rw [PFun.preimage_eq] exact inter_mem (h' s sl₂) h end Filter
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.
PPWithUniv.lean
/- Copyright (c) 2023 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner -/ import Mathlib.Init /-! # Attribute to pretty-print universe level parameters by default This module contains the `pp_with_univ` attribute, which enables pretty-printing of universe parameters for the associated declaration. This is helpful for definitions like `Ordinal`, where the universe levels are both relevant and not deducible from the arguments. -/ namespace Mathlib.PPWithUniv open Lean Parser PrettyPrinter Delaborator SubExpr Elab Command /-- Delaborator that prints the current application with universe parameters on the head symbol, unless `pp.universes` is explicitly set to `false`. -/ def delabWithUniv : Delab := whenPPOption (·.get pp.universes.name true) <| let enablePPUnivOnHead subExpr := let expr := subExpr.expr let expr := mkAppN (expr.getAppFn.setOption pp.universes.name true) expr.getAppArgs { subExpr with expr } withTheReader SubExpr enablePPUnivOnHead delabApp /-- `attribute [pp_with_univ] Ordinal` instructs the pretty-printer to print `Ordinal.{u}` with universe parameters by default (unless `pp.universes` is explicitly set to `false`). -/ syntax (name := ppWithUnivAttr) "pp_with_univ" : attr initialize registerBuiltinAttribute { name := `ppWithUnivAttr descr := "" applicationTime := .afterCompilation add := fun src ref kind => match ref with | `(attr| pp_with_univ) => do liftCommandElabM <| withRef ref do let attr ← Elab.elabAttr <| ← `(Term.attrInstance| delab $(mkIdent <| `app ++ src)) liftTermElabM <| Term.applyAttributes ``delabWithUniv #[{attr with kind}] | _ => throwUnsupportedSyntax } end PPWithUniv end Mathlib
StructuredArrow.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.Localization.HomEquiv import Mathlib.CategoryTheory.Localization.Opposite import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic /-! # Induction principles for structured and costructured arrows Assume that `L : C ⥤ D` is a localization functor for `W : MorphismProperty C`. Given `X : C` and a predicate `P` on `StructuredArrow (L.obj X) L`, we obtain the lemma `Localization.induction_structuredArrow` which shows that `P` holds for all structured arrows if `P` holds for the identity map `𝟙 (L.obj X)`, if `P` is stable by post-composition with `L.map f` for any `f` and if `P` is stable by post-composition with the inverse of `L.map w` when `W w`. We obtain a similar lemma `Localization.induction_costructuredArrow` for costructured arrows. -/ namespace CategoryTheory open Opposite variable {C D D' : Type*} [Category C] [Category D] [Category D'] namespace Localization section variable (W : MorphismProperty C) (L : C ⥤ D) (L' : C ⥤ D') [L.IsLocalization W] [L'.IsLocalization W] {X : C} /-- The bijection `StructuredArrow (L.obj X) L ≃ StructuredArrow (L'.obj X) L'` when `L` and `L'` are two localization functors for the same class of morphisms. -/ @[simps] noncomputable def structuredArrowEquiv : StructuredArrow (L.obj X) L ≃ StructuredArrow (L'.obj X) L' where toFun f := StructuredArrow.mk (homEquiv W L L' f.hom) invFun f := StructuredArrow.mk (homEquiv W L' L f.hom) left_inv f := by obtain ⟨Y, f, rfl⟩ := f.mk_surjective dsimp rw [← homEquiv_symm_apply, Equiv.symm_apply_apply] right_inv f := by obtain ⟨Y, f, rfl⟩ := f.mk_surjective dsimp rw [← homEquiv_symm_apply, Equiv.symm_apply_apply] end section variable (W : MorphismProperty C) {X : C} (P : StructuredArrow (W.Q.obj X) W.Q → Prop) open Construction in private lemma induction_structuredArrow' (hP₀ : P (StructuredArrow.mk (𝟙 (W.Q.obj X)))) (hP₁ : ∀ ⦃Y₁ Y₂ : C⦄ (f : Y₁ ⟶ Y₂) (φ : W.Q.obj X ⟶ W.Q.obj Y₁), P (StructuredArrow.mk φ) → P (StructuredArrow.mk (φ ≫ W.Q.map f))) (hP₂ : ∀ ⦃Y₁ Y₂ : C⦄ (w : Y₁ ⟶ Y₂) (hw : W w) (φ : W.Q.obj X ⟶ W.Q.obj Y₂), P (StructuredArrow.mk φ) → P (StructuredArrow.mk (φ ≫ (isoOfHom W.Q W w hw).inv))) (g : StructuredArrow (W.Q.obj X) W.Q) : P g := by let X₀ : Paths (LocQuiver W) := ⟨X⟩ suffices ∀ ⦃Y₀ : Paths (LocQuiver W)⦄ (f : X₀ ⟶ Y₀), P (StructuredArrow.mk ((Quotient.functor (relations W)).map f)) by obtain ⟨Y, g, rfl⟩ := g.mk_surjective obtain ⟨g, rfl⟩ := (Quotient.functor (relations W)).map_surjective g exact this g intro Y₀ f induction f with | nil => exact hP₀ | cons f g hf => obtain (g|⟨w, hw⟩) := g · exact hP₁ g _ hf · simpa only [← Construction.wInv_eq_isoOfHom_inv w hw] using hP₂ w hw _ hf end section variable (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] {X : C} (P : StructuredArrow (L.obj X) L → Prop) @[elab_as_elim] lemma induction_structuredArrow (hP₀ : P (StructuredArrow.mk (𝟙 (L.obj X)))) (hP₁ : ∀ ⦃Y₁ Y₂ : C⦄ (f : Y₁ ⟶ Y₂) (φ : L.obj X ⟶ L.obj Y₁), P (StructuredArrow.mk φ) → P (StructuredArrow.mk (φ ≫ L.map f))) (hP₂ : ∀ ⦃Y₁ Y₂ : C⦄ (w : Y₁ ⟶ Y₂) (hw : W w) (φ : L.obj X ⟶ L.obj Y₂), P (StructuredArrow.mk φ) → P (StructuredArrow.mk (φ ≫ (isoOfHom L W w hw).inv))) (g : StructuredArrow (L.obj X) L) : P g := by let P' : StructuredArrow (W.Q.obj X) W.Q → Prop := fun g ↦ P (structuredArrowEquiv W W.Q L g) rw [← (structuredArrowEquiv W W.Q L).apply_symm_apply g] apply induction_structuredArrow' W P' · convert hP₀ simp · intros Y₁ Y₂ f φ hφ convert hP₁ f (homEquiv W W.Q L φ) hφ simp [homEquiv_comp] · intros Y₁ Y₂ w hw φ hφ convert hP₂ w hw (homEquiv W W.Q L φ) hφ simp [homEquiv_comp, homEquiv_isoOfHom_inv] end section variable (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] {Y : C} (P : CostructuredArrow L (L.obj Y) → Prop) @[elab_as_elim] lemma induction_costructuredArrow (hP₀ : P (CostructuredArrow.mk (𝟙 (L.obj Y)))) (hP₁ : ∀ ⦃X₁ X₂ : C⦄ (f : X₁ ⟶ X₂) (φ : L.obj X₂ ⟶ L.obj Y), P (CostructuredArrow.mk φ) → P (CostructuredArrow.mk (L.map f ≫ φ))) (hP₂ : ∀ ⦃X₁ X₂ : C⦄ (w : X₁ ⟶ X₂) (hw : W w) (φ : L.obj X₁ ⟶ L.obj Y), P (CostructuredArrow.mk φ) → P (CostructuredArrow.mk ((isoOfHom L W w hw).inv ≫ φ))) (g : CostructuredArrow L (L.obj Y)) : P g := by let g' := StructuredArrow.mk (T := L.op) (Y := op g.left) g.hom.op change P (CostructuredArrow.mk g'.hom.unop) induction g' using induction_structuredArrow L.op W.op with | hP₀ => exact hP₀ | hP₁ f φ hφ => exact hP₁ f.unop φ.unop hφ | hP₂ w hw φ hφ => simpa [isoOfHom_op_inv L W w hw] using hP₂ w.unop hw φ.unop hφ end end Localization end CategoryTheory
MapDomain.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, Yury Kudryashov, Kim Morrison -/ import Mathlib.Algebra.MonoidAlgebra.Defs import Mathlib.Data.Finsupp.SMul /-! # MonoidAlgebra.mapDomain -/ assert_not_exists NonUnitalAlgHom AlgEquiv open Function open Finsupp hiding single mapDomain noncomputable section variable {k R S G H M N : Type*} /-! ### Multiplicative monoids -/ namespace MonoidAlgebra section Semiring variable [Semiring R] [Semiring S] {f : M → N} {a : M} {r : R} /-- Given a function `f : M → N` between magmas, return the corresponding map `R[M] → R[N]` obtained by summing the coefficients along each fiber of `f`. -/ abbrev mapDomain (f : M → N) (v : MonoidAlgebra R M) : MonoidAlgebra R N := Finsupp.mapDomain f v lemma mapDomain_sum (f : M → N) (s : MonoidAlgebra S M) (v : M → S → MonoidAlgebra R M) : mapDomain f (s.sum v) = s.sum fun a b ↦ mapDomain f (v a b) := Finsupp.mapDomain_sum lemma mapDomain_single : mapDomain f (single a r) = single (f a) r := Finsupp.mapDomain_single lemma mapDomain_injective (hf : Injective f) : Injective (mapDomain (R := R) f) := Finsupp.mapDomain_injective hf end Semiring section MiscTheorems variable [Semiring k] section /-- Like `Finsupp.mapDomain_zero`, but for the `1` we define in this file -/ @[simp] theorem mapDomain_one {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [One α] [One α₂] {F : Type*} [FunLike F α α₂] [OneHomClass F α α₂] (f : F) : (mapDomain f (1 : MonoidAlgebra β α) : MonoidAlgebra β α₂) = (1 : MonoidAlgebra β α₂) := by simp_rw [one_def, mapDomain_single, map_one] /-- Like `Finsupp.mapDomain_add`, but for the convolutive multiplication we define in this file -/ theorem mapDomain_mul {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [Mul α] [Mul α₂] {F : Type*} [FunLike F α α₂] [MulHomClass F α α₂] (f : F) (x y : MonoidAlgebra β α) : mapDomain f (x * y) = mapDomain f x * mapDomain f y := by simp_rw [mul_def, mapDomain_sum, mapDomain_single, map_mul] rw [Finsupp.sum_mapDomain_index] · congr ext a b rw [Finsupp.sum_mapDomain_index] · simp · simp [mul_add] · simp · simp [add_mul] end end MiscTheorems /-- If `f : G → H` is a multiplicative homomorphism between two monoids, then `Finsupp.mapDomain f` is a ring homomorphism between their monoid algebras. -/ @[simps] def mapDomainRingHom (k : Type*) {H F : Type*} [Semiring k] [Monoid G] [Monoid H] [FunLike F G H] [MonoidHomClass F G H] (f : F) : MonoidAlgebra k G →+* MonoidAlgebra k H := { (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra k G →+ MonoidAlgebra k H) with map_one' := mapDomain_one f map_mul' := fun x y => mapDomain_mul f x y } end MonoidAlgebra /-! ### Additive monoids -/ namespace AddMonoidAlgebra section Semiring variable [Semiring R] [Semiring S] {f : M → N} {a : M} {r : R} /-- Given a function `f : M → N` between magmas, return the corresponding map `R[M] → R[N]` obtained by summing the coefficients along each fiber of `f`. -/ abbrev mapDomain (f : M → N) (v : R[M]) : R[N] := Finsupp.mapDomain f v lemma mapDomain_sum (f : M → N) (s : S[M]) (v : M → S → R[M]) : mapDomain f (s.sum v) = s.sum fun a b ↦ mapDomain f (v a b) := Finsupp.mapDomain_sum lemma mapDomain_single : mapDomain f (single a r) = single (f a) r := Finsupp.mapDomain_single lemma mapDomain_injective (hf : Injective f) : Injective (mapDomain (R := R) f) := Finsupp.mapDomain_injective hf end Semiring section MiscTheorems variable [Semiring k] /-- Like `Finsupp.mapDomain_zero`, but for the `1` we define in this file -/ @[simp] theorem mapDomain_one {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [Zero α] [Zero α₂] {F : Type*} [FunLike F α α₂] [ZeroHomClass F α α₂] (f : F) : (mapDomain f (1 : AddMonoidAlgebra β α) : AddMonoidAlgebra β α₂) = (1 : AddMonoidAlgebra β α₂) := by simp_rw [one_def, mapDomain_single, map_zero] /-- Like `Finsupp.mapDomain_add`, but for the convolutive multiplication we define in this file -/ theorem mapDomain_mul {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [Add α] [Add α₂] {F : Type*} [FunLike F α α₂] [AddHomClass F α α₂] (f : F) (x y : AddMonoidAlgebra β α) : mapDomain f (x * y) = mapDomain f x * mapDomain f y := by simp_rw [mul_def, mapDomain_sum, mapDomain_single, map_add] rw [Finsupp.sum_mapDomain_index] · congr ext a b rw [Finsupp.sum_mapDomain_index] · simp · simp [mul_add] · simp · simp [add_mul] /-- If `f : G → H` is an additive homomorphism between two additive monoids, then `Finsupp.mapDomain f` is a ring homomorphism between their add monoid algebras. -/ @[simps] def mapDomainRingHom (k : Type*) [Semiring k] {H F : Type*} [AddMonoid G] [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H] (f : F) : k[G] →+* k[H] := { (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra k G →+ MonoidAlgebra k H) with map_one' := mapDomain_one f map_mul' := fun x y => mapDomain_mul f x y } end MiscTheorems end AddMonoidAlgebra /-! #### Conversions between `AddMonoidAlgebra` and `MonoidAlgebra` We have not defined `k[G] = MonoidAlgebra k (Multiplicative G)` because historically this caused problems; since the changes that have made `nsmul` definitional, this would be possible, but for now we just construct the ring isomorphisms using `RingEquiv.refl _`. -/ variable (k G) in /-- The equivalence between `AddMonoidAlgebra` and `MonoidAlgebra` in terms of `Multiplicative` -/ protected def AddMonoidAlgebra.toMultiplicative [Semiring k] [Add G] : AddMonoidAlgebra k G ≃+* MonoidAlgebra k (Multiplicative G) := { Finsupp.domCongr Multiplicative.ofAdd with toFun := equivMapDomain Multiplicative.ofAdd map_mul' := fun x y => by repeat' rw [equivMapDomain_eq_mapDomain (M := k)] dsimp [Multiplicative.ofAdd] exact MonoidAlgebra.mapDomain_mul (α := Multiplicative G) (β := k) (MulHom.id (Multiplicative G)) x y } variable (k G) in /-- The equivalence between `MonoidAlgebra` and `AddMonoidAlgebra` in terms of `Additive` -/ protected def MonoidAlgebra.toAdditive [Semiring k] [Mul G] : MonoidAlgebra k G ≃+* AddMonoidAlgebra k (Additive G) := { Finsupp.domCongr Additive.ofMul with toFun := equivMapDomain Additive.ofMul map_mul' := fun x y => by repeat' rw [equivMapDomain_eq_mapDomain (M := k)] dsimp [Additive.ofMul] convert MonoidAlgebra.mapDomain_mul (β := k) (MulHom.id G) x y }
Arithmetic.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Data.Nat.SuccPred import Mathlib.Order.IsNormal import Mathlib.Order.SuccPred.InitialSeg import Mathlib.SetTheory.Ordinal.Basic /-! # Ordinal arithmetic Ordinals have an addition (corresponding to disjoint union) that turns them into an additive monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns them into a monoid. One can also define correspondingly a subtraction, a division, a successor function, a power function and a logarithm function. We also define limit ordinals and prove the basic induction principle on ordinals separating successor ordinals and limit ordinals, in `limitRecOn`. ## Main definitions and results * `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that every element of `o₁` is smaller than every element of `o₂`. * `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`. * `o₁ * o₂` is the lexicographic order on `o₂ × o₁`. * `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the divisibility predicate, and a modulo operation. * `Order.succ o = o + 1` is the successor of `o`. * `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`. We discuss the properties of casts of natural numbers of and of `ω` with respect to these operations. Some properties of the operations are also used to discuss general tools on ordinals: * `Order.IsSuccLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor. * `limitRecOn` is the main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. * `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. Various other basic arithmetic results are given in `Principal.lean` instead. -/ assert_not_exists Field Module noncomputable section open Function Cardinal Set Equiv Order open scoped Ordinal universe u v w namespace Ordinal variable {α β γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} /-! ### Further properties of addition on ordinals -/ @[simp] theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ @[simp] theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by rw [← add_one_eq_succ, lift_add, lift_one] rfl instance instAddLeftReflectLE : AddLeftReflectLE Ordinal.{u} where elim c a b := by refine inductionOn₃ a b c fun α r _ β s _ γ t _ ⟨f⟩ ↦ ?_ have H₁ a : f (Sum.inl a) = Sum.inl a := by simpa using ((InitialSeg.leAdd t r).trans f).eq (InitialSeg.leAdd t s) a have H₂ a : ∃ b, f (Sum.inr a) = Sum.inr b := by generalize hx : f (Sum.inr a) = x obtain x | x := x · rw [← H₁, f.inj] at hx contradiction · exact ⟨x, rfl⟩ choose g hg using H₂ refine (RelEmbedding.ofMonotone g fun _ _ h ↦ ?_).ordinal_type_le rwa [← @Sum.lex_inr_inr _ t _ s, ← hg, ← hg, f.map_rel_iff, Sum.lex_inr_inr] instance : IsLeftCancelAdd Ordinal where add_left_cancel a b c h := by simpa only [le_antisymm_iff, add_le_add_iff_left] using h private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by rw [← not_le, ← not_le, add_le_add_iff_left] instance instAddLeftStrictMono : AddLeftStrictMono Ordinal.{u} := ⟨fun a _b _c ↦ (add_lt_add_iff_left' a).2⟩ instance instAddLeftReflectLT : AddLeftReflectLT Ordinal.{u} := ⟨fun a _b _c ↦ (add_lt_add_iff_left' a).1⟩ instance instAddRightReflectLT : AddRightReflectLT Ordinal.{u} := ⟨fun _a _b _c ↦ lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩ theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b | 0 => by simp | n + 1 => by simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right] theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by simp only [le_antisymm_iff, add_le_add_iff_right] theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 := inductionOn₂ a b fun α r _ β s _ => by simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty] exact isEmpty_sum theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 := (add_eq_zero_iff.1 h).1 theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 := (add_eq_zero_iff.1 h).2 /-! ### Limit ordinals -/ /-- A limit ordinal is an ordinal which is not zero and not a successor. Deprecated: use `Order.IsSuccLimit` instead. -/ @[deprecated IsSuccLimit (since := "2025-02-09")] def IsLimit (o : Ordinal) : Prop := IsSuccLimit o theorem isSuccLimit_iff {o : Ordinal} : IsSuccLimit o ↔ o ≠ 0 ∧ IsSuccPrelimit o := by simp [IsSuccLimit] @[deprecated (since := "2025-07-09")] alias isLimit_iff := isSuccLimit_iff @[deprecated (since := "2025-07-09")] alias IsLimit.isSuccPrelimit := IsSuccLimit.isSuccPrelimit @[deprecated (since := "2025-07-09")] alias IsLimit.succ_lt := IsSuccLimit.succ_lt @[simp] theorem isSuccPrelimit_zero : IsSuccPrelimit (0 : Ordinal) := isSuccPrelimit_bot @[simp] theorem not_isSuccLimit_zero : ¬ IsSuccLimit (0 : Ordinal) := not_isSuccLimit_bot @[deprecated (since := "2025-07-09")] alias not_zero_isLimit := not_isSuccLimit_zero @[deprecated (since := "2025-07-09")] alias not_succ_isLimit := not_isSuccLimit_succ set_option linter.deprecated false in @[deprecated not_isSuccLimit_succ (since := "2025-07-09")] theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a | ⟨a, e⟩ => not_succ_isLimit a (e ▸ h) @[deprecated (since := "2025-07-09")] alias succ_lt_of_isLimit := IsSuccLimit.succ_lt_iff @[deprecated (since := "2025-07-09")] alias le_succ_of_isLimit := IsSuccLimit.le_succ_iff @[deprecated (since := "2025-07-09")] alias limit_le := IsSuccLimit.le_iff_forall_le @[deprecated (since := "2025-07-09")] alias lt_limit := IsSuccLimit.lt_iff_exists_lt @[simp] theorem isSuccPrelimit_lift {o : Ordinal} : IsSuccPrelimit (lift.{u, v} o) ↔ IsSuccPrelimit o := liftInitialSeg.isSuccPrelimit_apply_iff @[simp] theorem isSuccLimit_lift {o : Ordinal} : IsSuccLimit (lift.{u, v} o) ↔ IsSuccLimit o := liftInitialSeg.isSuccLimit_apply_iff @[deprecated (since := "2025-07-09")] alias lift_isLimit := isSuccLimit_lift set_option linter.deprecated false in @[deprecated IsSuccLimit.bot_lt (since := "2025-07-09")] theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o := IsSuccLimit.bot_lt h set_option linter.deprecated false in @[deprecated IsSuccLimit.ne_bot (since := "2025-07-09")] theorem IsLimit.ne_zero {o : Ordinal} (h : IsLimit o) : o ≠ 0 := h.pos.ne' theorem natCast_lt_of_isSuccLimit {o : Ordinal} (h : IsSuccLimit o) (n : ℕ) : n < o := by simpa using h.add_natCast_lt h.bot_lt n @[deprecated (since := "2025-07-09")] alias IsLimit.nat_lt := natCast_lt_of_isSuccLimit theorem one_lt_of_isSuccLimit {o : Ordinal} (h : IsSuccLimit o) : 1 < o := mod_cast natCast_lt_of_isSuccLimit h 1 @[deprecated (since := "2025-07-09")] alias IsLimit.one_lt := one_lt_of_isSuccLimit theorem zero_or_succ_or_isSuccLimit (o : Ordinal) : o = 0 ∨ o ∈ range succ ∨ IsSuccLimit o := by simpa using isMin_or_mem_range_succ_or_isSuccLimit o set_option linter.deprecated false in @[deprecated zero_or_succ_or_isSuccLimit (since := "2025-07-09")] theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := by simpa [eq_comm] using isMin_or_mem_range_succ_or_isSuccLimit o set_option linter.deprecated false in @[deprecated zero_or_succ_or_isSuccLimit (since := "2025-07-09")] theorem isLimit_of_not_succ_of_ne_zero {o : Ordinal} (h : ¬∃ a, o = succ a) (h' : o ≠ 0) : IsLimit o := ((zero_or_succ_or_limit o).resolve_left h').resolve_left h @[deprecated (since := "2025-07-09")] alias IsLimit.sSup_Iio := IsSuccLimit.sSup_Iio @[deprecated (since := "2025-07-09")] alias IsLimit.iSup_Iio := IsSuccLimit.iSup_Iio /-- Main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/ @[elab_as_elim] def limitRecOn {motive : Ordinal → Sort*} (o : Ordinal) (zero : motive 0) (succ : ∀ o, motive o → motive (succ o)) (limit : ∀ o, IsSuccLimit o → (∀ o' < o, motive o') → motive o) : motive o := SuccOrder.limitRecOn o (fun _a ha ↦ ha.eq_bot ▸ zero) (fun a _ ↦ succ a) limit @[simp] theorem limitRecOn_zero {motive} (H₁ H₂ H₃) : @limitRecOn motive 0 H₁ H₂ H₃ = H₁ := SuccOrder.limitRecOn_isMin _ _ _ isMin_bot @[simp] theorem limitRecOn_succ {motive} (o H₁ H₂ H₃) : @limitRecOn motive (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn motive o H₁ H₂ H₃) := SuccOrder.limitRecOn_succ .. @[simp] theorem limitRecOn_limit {motive} (o H₁ H₂ H₃ h) : @limitRecOn motive o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn motive x H₁ H₂ H₃ := SuccOrder.limitRecOn_of_isSuccLimit .. /-- Bounded recursion on ordinals. Similar to `limitRecOn`, with the assumption `o < l` added to all cases. The final term's domain is the ordinals below `l`. -/ @[elab_as_elim] def boundedLimitRecOn {l : Ordinal} (lLim : IsSuccLimit l) {motive : Iio l → Sort*} (o : Iio l) (zero : motive ⟨0, lLim.bot_lt⟩) (succ : (o : Iio l) → motive o → motive ⟨succ o, lLim.succ_lt o.2⟩) (limit : (o : Iio l) → IsSuccLimit o.1 → (Π o' < o, motive o') → motive o) : motive o := limitRecOn (motive := fun p ↦ (h : p < l) → motive ⟨p, h⟩) o.1 (fun _ ↦ zero) (fun o ih h ↦ succ ⟨o, _⟩ <| ih <| (lt_succ o).trans h) (fun _o ho ih _ ↦ limit _ ho fun _o' h ↦ ih _ h _) o.2 @[simp] theorem boundedLimitRec_zero {l} (lLim : IsSuccLimit l) {motive} (H₁ H₂ H₃) : @boundedLimitRecOn l lLim motive ⟨0, lLim.bot_lt⟩ H₁ H₂ H₃ = H₁ := by rw [boundedLimitRecOn, limitRecOn_zero] @[simp] theorem boundedLimitRec_succ {l} (lLim : IsSuccLimit l) {motive} (o H₁ H₂ H₃) : @boundedLimitRecOn l lLim motive ⟨succ o.1, lLim.succ_lt o.2⟩ H₁ H₂ H₃ = H₂ o (@boundedLimitRecOn l lLim motive o H₁ H₂ H₃) := by rw [boundedLimitRecOn, limitRecOn_succ] rfl theorem boundedLimitRec_limit {l} (lLim : IsSuccLimit l) {motive} (o H₁ H₂ H₃ oLim) : @boundedLimitRecOn l lLim motive o H₁ H₂ H₃ = H₃ o oLim (fun x _ ↦ @boundedLimitRecOn l lLim motive x H₁ H₂ H₃) := by rw [boundedLimitRecOn, limitRecOn_limit] rfl instance orderTopToTypeSucc (o : Ordinal) : OrderTop (succ o).toType := @OrderTop.mk _ _ (Top.mk _) le_enum_succ theorem enum_succ_eq_top {o : Ordinal} : enum (α := (succ o).toType) (· < ·) ⟨o, type_toType _ ▸ lt_succ o⟩ = ⊤ := rfl theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r] (h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by use enum r ⟨succ (typein r x), h _ (typein_lt_type r x)⟩ convert enum_lt_enum.mpr _ · rw [enum_typein] · rw [Subtype.mk_lt_mk, lt_succ_iff] theorem toType_noMax_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.toType := ⟨has_succ_of_type_succ_lt (type_toType _ ▸ ho)⟩ theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : IsSuccLimit (type r)) (x) : Bounded r {x} := by refine ⟨enum r ⟨succ (typein r x), hr.succ_lt (typein_lt_type r x)⟩, ?_⟩ intro b hb rw [mem_singleton_iff.1 hb] nth_rw 1 [← enum_typein r x] rw [@enum_lt_enum _ r, Subtype.mk_lt_mk] apply lt_succ @[simp] theorem typein_ordinal (o : Ordinal.{u}) : @typein Ordinal (· < ·) _ o = Ordinal.lift.{u + 1} o := by refine Quotient.inductionOn o ?_ rintro ⟨α, r, wo⟩; apply Quotient.sound constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enum r).symm).symm theorem mk_Iio_ordinal (o : Ordinal.{u}) : #(Iio o) = Cardinal.lift.{u + 1} o.card := by rw [lift_card, ← typein_ordinal] rfl /-! ### The predecessor of an ordinal -/ /-- The ordinal predecessor of `o` is `o'` if `o = succ o'`, and `o` otherwise. -/ def pred (o : Ordinal) : Ordinal := isSuccPrelimitRecOn o (fun a _ ↦ a) (fun a _ ↦ a) @[simp] theorem pred_succ (o) : pred (succ o) = o := isSuccPrelimitRecOn_succ .. theorem pred_eq_of_isSuccPrelimit {o} : IsSuccPrelimit o → pred o = o := isSuccPrelimitRecOn_of_isSuccPrelimit _ _ alias _root_.Order.IsSuccPrelimit.ordinalPred_eq := pred_eq_of_isSuccPrelimit theorem _root_.Order.IsSuccLimit.ordinalPred_eq {o} (ho : IsSuccLimit o) : pred o = o := ho.isSuccPrelimit.ordinalPred_eq @[simp] theorem pred_zero : pred 0 = 0 := isSuccPrelimit_zero.ordinalPred_eq @[simp] theorem pred_le_iff_le_succ {a b} : pred a ≤ b ↔ a ≤ succ b := by obtain ⟨a, rfl⟩ | ha := mem_range_succ_or_isSuccPrelimit a · simp · rw [ha.ordinalPred_eq, ha.le_succ_iff] @[deprecated pred_le_iff_le_succ (since := "2025-02-11")] alias pred_le := pred_le_iff_le_succ @[simp] theorem lt_pred_iff_succ_lt {a b} : a < pred b ↔ succ a < b := le_iff_le_iff_lt_iff_lt.1 pred_le_iff_le_succ @[deprecated lt_pred_iff_succ_lt (since := "2025-02-11")] alias lt_pred := lt_pred_iff_succ_lt theorem pred_le_self (o) : pred o ≤ o := by simpa using le_succ o /-- `Ordinal.pred` and `Order.succ` form a Galois insertion. -/ def pred_succ_gi : GaloisInsertion pred succ := GaloisConnection.toGaloisInsertion @pred_le_iff_le_succ (by simp) theorem pred_surjective : Function.Surjective pred := pred_succ_gi.l_surjective theorem self_le_succ_pred (o) : o ≤ succ (pred o) := pred_succ_gi.gc.le_u_l o theorem pred_eq_iff_isSuccPrelimit {o} : pred o = o ↔ IsSuccPrelimit o := by obtain ⟨a, rfl⟩ | ho := mem_range_succ_or_isSuccPrelimit o · simpa using (lt_succ a).ne · simp_rw [ho.ordinalPred_eq, ho] @[deprecated pred_eq_iff_isSuccPrelimit (since := "2025-02-11")] theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a := by simpa [eq_comm, isSuccPrelimit_iff_succ_ne] using pred_eq_iff_isSuccPrelimit @[deprecated pred_eq_iff_isSuccPrelimit (since := "2025-02-11")] theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by simpa [eq_comm, isSuccPrelimit_iff_succ_ne] using pred_eq_iff_isSuccPrelimit theorem pred_lt_iff_not_isSuccPrelimit {o} : pred o < o ↔ ¬ IsSuccPrelimit o := by rw [(pred_le_self o).lt_iff_ne] exact pred_eq_iff_isSuccPrelimit.not @[deprecated pred_lt_iff_not_isSuccPrelimit (since := "2025-02-11")] theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a := by simpa [eq_comm, isSuccPrelimit_iff_succ_ne] using pred_lt_iff_not_isSuccPrelimit theorem succ_pred_eq_iff_not_isSuccPrelimit {o} : succ (pred o) = o ↔ ¬ IsSuccPrelimit o := by rw [← (self_le_succ_pred o).ge_iff_eq', succ_le_iff, pred_lt_iff_not_isSuccPrelimit] @[deprecated succ_pred_iff_is_succ (since := "2025-02-11")] theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a := by simpa [eq_comm, isSuccPrelimit_iff_succ_ne] using succ_pred_eq_iff_not_isSuccPrelimit @[deprecated IsSuccPrelimit.succ_lt_iff (since := "2025-02-11")] theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o := by apply (isSuccPrelimit_of_succ_ne _).succ_lt_iff simpa [eq_comm] using h @[deprecated isSuccPrelimit_lift (since := "2025-02-11")] theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a := by simpa [eq_comm, not_isSuccPrelimit_iff', - isSuccPrelimit_lift] using isSuccPrelimit_lift.not @[simp] theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := by obtain ⟨a, rfl⟩ | ho := mem_range_succ_or_isSuccPrelimit o · simp · rwa [ho.ordinalPred_eq, eq_comm, pred_eq_iff_isSuccPrelimit, isSuccPrelimit_lift] /-! ### Normal ordinal functions -/ /-- A normal ordinal function is a strictly increasing function which is order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. Todo: deprecate this in favor of `Order.IsNormal`. -/ def IsNormal (f : Ordinal → Ordinal) : Prop := Order.IsNormal f theorem IsNormal.limit_le {f} (H : IsNormal f) : ∀ {o}, IsSuccLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a := H.le_iff_forall_le theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsSuccLimit o) {a} : a < f o ↔ ∃ b < o, a < f b := H.lt_iff_exists_lt h theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := Order.IsNormal.strictMono H theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f := H.strictMono.monotone theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) : IsNormal f ↔ StrictMono f ∧ ∀ o, IsSuccLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a := isNormal_iff theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b := StrictMono.lt_iff_lt <| H.strictMono theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b := le_iff_le_iff_lt_iff_lt.2 H.lt_iff theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by simp only [le_antisymm_iff, H.le_iff] theorem IsNormal.id_le {f} (H : IsNormal f) : id ≤ f := H.strictMono.id_le theorem IsNormal.le_apply {f} (H : IsNormal f) {a} : a ≤ f a := H.strictMono.le_apply theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a := H.le_apply.ge_iff_eq' theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o := ⟨fun h _ pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by induction b using limitRecOn with | zero => obtain ⟨x, px⟩ := p0 have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px) rw [this] at px exact h _ px | succ S _ => rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_ge) with ⟨a, h₁, h₂⟩ exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁) | limit S L _ => refine (H.le_iff_forall_le L).2 fun a h' => ?_ rcases not_forall₂.1 (mt (H₂ a).2 h'.not_ge) with ⟨b, h₁, h₂⟩ exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩ theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by simpa [H₂] using H.le_set (g '' p) (p0.image g) b theorem IsNormal.refl : IsNormal id := .id theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) := H₁.comp H₂ theorem IsNormal.isSuccLimit {f} (H : IsNormal f) {o} (ho : IsSuccLimit o) : IsSuccLimit (f o) := H.map_isSuccLimit ho /-! ### Subtraction on ordinals -/ instance existsAddOfLE : ExistsAddOfLE Ordinal where exists_add_of_le {a b} := by refine inductionOn₂ a b fun α r _ β s _ ⟨f⟩ ↦ ?_ obtain ⟨γ, t, _, ⟨g⟩⟩ := f.exists_sum_relIso exact ⟨type t, g.ordinal_type_eq.symm⟩ -- TODO: This gives us `zero_le` as an immediate consequence. -- Private/protect the old theorem, golf proofs. instance canonicallyOrderedAdd : CanonicallyOrderedAdd Ordinal where le_self_add := le_add_right /-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/ instance sub : Sub Ordinal where sub a b := if h : b ≤ a then Classical.choose (exists_add_of_le h) else 0 private theorem sub_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a - b = 0 := dif_neg h.not_ge protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a := by change b + dite _ _ _ = a rw [dif_pos h] exact (Classical.choose_spec (exists_add_of_le h)).symm @[simp] theorem add_sub_cancel (a b : Ordinal) : a + b - a = b := by simpa using Ordinal.add_sub_cancel_of_le (le_add_right a b) theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) := by obtain h | h := le_or_gt b a · exact (Ordinal.add_sub_cancel_of_le h).ge · simpa [sub_eq_zero_of_lt h] using h.le theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c := by refine ⟨fun h ↦ (le_add_sub a b).trans (add_le_add_left h _), fun h ↦ ?_⟩ obtain h' | h' := le_or_gt b a · rwa [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h'] · simp [sub_eq_zero_of_lt h'] theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b := lt_iff_lt_of_le_iff_le sub_le theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b := h ▸ add_sub_cancel _ _ theorem sub_le_self (a b : Ordinal) : a - b ≤ a := sub_le.2 <| le_add_left _ _ theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h] theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c := lt_iff_lt_of_le_iff_le (le_sub_of_le h) @[simp] theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a @[simp] theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self @[simp] theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0 protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b := ⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by rwa [← Ordinal.le_zero, sub_le, add_zero]⟩ protected theorem sub_ne_zero_iff_lt {a b : Ordinal} : a - b ≠ 0 ↔ b < a := by simpa using Ordinal.sub_eq_zero_iff_le.not theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) := eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc] @[simp] theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by rw [← sub_sub, add_sub_cancel] theorem le_sub_of_add_le {a b c : Ordinal} (h : b + c ≤ a) : c ≤ a - b := by rw [← add_le_add_iff_left b] exact h.trans (le_add_sub a b) theorem sub_lt_of_lt_add {a b c : Ordinal} (h : a < b + c) (hc : 0 < c) : a - b < c := by obtain hab | hba := lt_or_ge a b · rwa [Ordinal.sub_eq_zero_iff_le.2 hab.le] · rwa [sub_lt_of_le hba] theorem lt_add_iff {a b c : Ordinal} (hc : c ≠ 0) : a < b + c ↔ ∃ d < c, a ≤ b + d := by use fun h ↦ ⟨_, sub_lt_of_lt_add h hc.bot_lt, le_add_sub a b⟩ rintro ⟨d, hd, ha⟩ exact ha.trans_lt (add_lt_add_left hd b) theorem add_le_iff {a b c : Ordinal} (hb : b ≠ 0) : a + b ≤ c ↔ ∀ d < b, a + d < c := by simpa using (lt_add_iff hb).not theorem lt_add_iff_of_isSuccLimit {a b c : Ordinal} (hc : IsSuccLimit c) : a < b + c ↔ ∃ d < c, a < b + d := by rw [lt_add_iff hc.ne_bot] constructor <;> rintro ⟨d, hd, ha⟩ · refine ⟨_, hc.succ_lt hd, ?_⟩ rwa [add_succ, lt_succ_iff] · exact ⟨d, hd, ha.le⟩ @[deprecated (since := "2025-07-08")] alias lt_add_of_limit := lt_add_iff_of_isSuccLimit theorem add_le_iff_of_isSuccLimit {a b c : Ordinal} (hb : IsSuccLimit b) : a + b ≤ c ↔ ∀ d < b, a + d ≤ c := by simpa using (lt_add_iff_of_isSuccLimit hb).not @[deprecated (since := "2025-07-08")] alias add_le_of_limit := add_le_iff_of_isSuccLimit theorem isNormal_add_right (a : Ordinal) : IsNormal (a + ·) := by rw [isNormal_iff_strictMono_limit] exact ⟨add_left_strictMono, fun _ l _ ↦ (add_le_iff_of_isSuccLimit l).2⟩ theorem isSuccLimit_add (a : Ordinal) {b : Ordinal} : IsSuccLimit b → IsSuccLimit (a + b) := (isNormal_add_right a).isSuccLimit @[deprecated (since := "2025-07-09")] alias isLimit_add := isSuccLimit_add @[deprecated (since := "2025-07-09")] alias IsLimit.add := isSuccLimit_add theorem isSuccLimit_sub {a b : Ordinal} (ha : IsSuccLimit a) (h : b < a) : IsSuccLimit (a - b) := by rw [isSuccLimit_iff, Ordinal.sub_ne_zero_iff_lt, isSuccPrelimit_iff_succ_lt] refine ⟨h, fun c hc ↦ ?_⟩ rw [lt_sub] at hc ⊢ rw [add_succ] exact ha.succ_lt hc @[deprecated (since := "2025-07-09")] alias isLimit_sub := isSuccLimit_sub /-! ### Multiplication of ordinals -/ /-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on `o₂ × o₁`. -/ instance monoid : Monoid Ordinal.{u} where mul a b := Quotient.liftOn₂ a b (fun ⟨α, r, _⟩ ⟨β, s, _⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ : WellOrder → WellOrder → Ordinal) fun ⟨_, _, _⟩ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.prodLexCongr g f⟩ one := 1 mul_assoc a b c := Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Eq.symm <| Quotient.sound ⟨⟨prodAssoc _ _ _, @fun a b => by rcases a with ⟨⟨a₁, a₂⟩, a₃⟩ rcases b with ⟨⟨b₁, b₂⟩, b₃⟩ simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩ mul_one a := inductionOn a fun α r _ => Quotient.sound ⟨⟨punitProd _, @fun a b => by rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩ simp only [Prod.lex_def, EmptyRelation, false_or] simp only [true_and] rfl⟩⟩ one_mul a := inductionOn a fun α r _ => Quotient.sound ⟨⟨prodPUnit _, @fun a b => by rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩ simp only [Prod.lex_def, EmptyRelation, and_false, or_false] rfl⟩⟩ @[simp] theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r] [IsWellOrder β s] : type (Prod.Lex s r) = type r * type s := rfl private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 := inductionOn a fun α _ _ => inductionOn b fun β _ _ => by simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty] rw [or_comm] exact isEmpty_prod instance monoidWithZero : MonoidWithZero Ordinal := { Ordinal.monoid with zero := 0 mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl } instance noZeroDivisors : NoZeroDivisors Ordinal := ⟨fun {_ _} => mul_eq_zero'.1⟩ @[simp] theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ @[simp] theorem card_mul (a b) : card (a * b) = card a * card b := Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α instance leftDistribClass : LeftDistribClass Ordinal.{u} := ⟨fun a b c => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Quotient.sound ⟨⟨sumProdDistrib _ _ _, by rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;> simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl, Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right, reduceCtorEq] <;> -- Porting note: `Sum.inr.inj_iff` is required. simp only [Sum.inl.inj_iff, Sum.inr.inj_iff, true_or, false_and, false_or]⟩⟩⟩ theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a := mul_add_one a b instance mulLeftMono : MulLeftMono Ordinal.{u} := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le obtain ⟨-, -, h'⟩ | ⟨-, h'⟩ := h · exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h') · exact Prod.Lex.right _ h'⟩ instance mulRightMono : MulRightMono Ordinal.{u} := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le obtain ⟨-, -, h'⟩ | ⟨-, h'⟩ := h · exact Prod.Lex.left _ _ h' · exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩ theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by convert mul_le_mul_left' (one_le_iff_pos.2 hb) a rw [mul_one a] theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by convert mul_le_mul_right' (one_le_iff_pos.2 hb) a rw [one_mul a] private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c} (h : IsSuccLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) : False := by suffices ∀ a b, Prod.Lex s r (b, a) (enum _ ⟨_, l⟩) by obtain ⟨b, a⟩ := enum _ ⟨_, l⟩ exact irrefl _ (this _ _) intro a b rw [← typein_lt_typein (Prod.Lex s r), typein_enum] have := H _ (h.succ_lt (typein_lt_type s b)) rw [mul_succ] at this have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨⟨b', a'⟩, h⟩ by_cases e : b = b' · refine Sum.inr ⟨a', ?_⟩ subst e obtain ⟨-, -, h⟩ | ⟨-, h⟩ := h · exact (irrefl _ h).elim · exact h · refine Sum.inl (⟨b', ?_⟩, a') obtain ⟨-, -, h⟩ | ⟨e, h⟩ := h · exact h · exact (e rfl).elim · rcases a with ⟨⟨b₁, a₁⟩, h₁⟩ rcases b with ⟨⟨b₂, a₂⟩, h₂⟩ intro h by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂ · substs b₁ b₂ simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and, false_or, eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h · subst b₁ simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, or_false, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and] at h ⊢ obtain ⟨-, -, h₂_h⟩ | e₂ := h₂ <;> [exact asymm h h₂_h; exact e₂ rfl] · simp [e₂, show b₂ ≠ b₁ from e₂ ▸ e₁] · simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk, Sum.lex_inl_inl] using h theorem mul_le_iff_of_isSuccLimit {a b c : Ordinal} (h : IsSuccLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c := ⟨fun h _ l => (mul_le_mul_left' l.le _).trans h, fun H => -- Porting note: `induction` tactics are required because of the parser bug. le_of_not_gt <| by induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => exact mul_le_of_limit_aux h H⟩ @[deprecated (since := "2025-07-09")] alias mul_le_of_limit := mul_le_iff_of_isSuccLimit theorem isNormal_mul_right {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) := by refine IsNormal.of_succ_lt (fun b ↦ ?_) fun hb ↦ ?_ · simpa [mul_succ] using (add_lt_add_iff_left (a * b)).2 h · simpa [IsLUB, IsLeast, upperBounds, lowerBounds, mul_le_iff_of_isSuccLimit hb] using fun c hc ↦ mul_le_mul_left' hc.le a theorem lt_mul_iff_of_isSuccLimit {a b c : Ordinal} (h : IsSuccLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by simpa using (mul_le_iff_of_isSuccLimit h).not @[deprecated (since := "2025-07-09")] alias lt_mul_of_limit := lt_mul_iff_of_isSuccLimit theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c := (isNormal_mul_right a0).lt_iff theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c := (isNormal_mul_right a0).le_iff theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b := (mul_lt_mul_iff_left c0).2 h theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁ theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by simpa only [Ordinal.pos_iff_ne_zero] using mul_pos theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b := le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c := (isNormal_mul_right a0).inj theorem isSuccLimit_mul {a b : Ordinal} (a0 : 0 < a) : IsSuccLimit b → IsSuccLimit (a * b) := (isNormal_mul_right a0).isSuccLimit @[deprecated (since := "2025-07-09")] alias isLimit_mul := isSuccLimit_mul theorem isSuccLimit_mul_left {a b : Ordinal} (l : IsSuccLimit a) (b0 : 0 < b) : IsSuccLimit (a * b) := by rcases zero_or_succ_or_isSuccLimit b with (rfl | ⟨b, rfl⟩ | lb) · exact b0.false.elim · rw [mul_succ] exact isSuccLimit_add _ l · exact isSuccLimit_mul l.bot_lt lb @[deprecated (since := "2025-07-09")] alias isLimit_mul_left := isSuccLimit_mul_left theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n | 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero] | n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n] private theorem add_mul_limit_aux {a b c : Ordinal} (ba : b + a = a) (l : IsSuccLimit c) (IH : ∀ c' < c, (a + b) * succ c' = a * succ c' + b) : (a + b) * c = a * c := le_antisymm ((mul_le_iff_of_isSuccLimit l).2 fun c' h => by apply (mul_le_mul_left' (le_succ c') _).trans rw [IH _ h] apply (add_le_add_left _ _).trans · rw [← mul_succ] exact mul_le_mul_left' (succ_le_of_lt <| l.succ_lt h) _ · rw [← ba] exact le_add_right _ _) (mul_le_mul_right' (le_add_right _ _) _) theorem add_mul_succ {a b : Ordinal} (c) (ba : b + a = a) : (a + b) * succ c = a * succ c + b := by induction c using limitRecOn with | zero => simp only [succ_zero, mul_one] | succ c IH => rw [mul_succ, IH, ← add_assoc, add_assoc _ b, ba, ← mul_succ] | limit c l IH => rw [mul_succ, add_mul_limit_aux ba l IH, mul_succ, add_assoc] theorem add_mul_of_isSuccLimit {a b c : Ordinal} (ba : b + a = a) (l : IsSuccLimit c) : (a + b) * c = a * c := add_mul_limit_aux ba l fun c' _ => add_mul_succ c' ba @[deprecated (since := "2025-07-09")] alias add_mul_limit := add_mul_of_isSuccLimit /-! ### Division on ordinals -/ /-- The set in the definition of division is nonempty. -/ private theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty := ⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by simpa only [succ_zero, one_mul] using mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩ /-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/ instance div : Div Ordinal := ⟨fun a b => if b = 0 then 0 else sInf { o | a < b * succ o }⟩ @[simp] theorem div_zero (a : Ordinal) : a / 0 = 0 := dif_pos rfl private theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } := dif_neg h theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by rw [div_def a h]; exact csInf_mem (div_nonempty h) theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by simpa only [mul_succ] using lt_mul_succ_div a h theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c := ⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by rw [div_def a b0]; exact csInf_le' h⟩ theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by rw [← not_le, div_le h, not_lt] theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h] theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by induction a using limitRecOn with | zero => simp only [mul_zero, Ordinal.zero_le] | succ _ _ => rw [succ_le_iff, lt_div c0] | limit _ h₁ h₂ => revert h₁ h₂ simp +contextual only [mul_le_iff_of_isSuccLimit, IsSuccLimit.le_iff_forall_le, forall_true_iff] theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c := lt_iff_lt_of_le_iff_le <| le_div b0 theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c := if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le] else (div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0) theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b := lt_imp_lt_of_le_imp_le div_le_of_le_mul @[simp] theorem zero_div (a : Ordinal) : 0 / a = 0 := Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _ theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a := if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl theorem div_le_left {a b : Ordinal} (h : a ≤ b) (c : Ordinal) : a / c ≤ b / c := by obtain rfl | hc := eq_or_ne c 0 · rw [div_zero, div_zero] · rw [le_div hc] exact (mul_div_le a c).trans h theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by apply le_antisymm · apply (div_le b0).2 rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left] apply lt_mul_div_add _ b0 · rw [le_div b0, mul_add, add_le_add_iff_left] apply mul_div_le theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h] simpa only [succ_zero, mul_one] using h @[simp] theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by simpa only [add_zero, zero_div] using mul_add_div a b0 0 theorem mul_add_div_mul {a c : Ordinal} (hc : c < a) (b d : Ordinal) : (a * b + c) / (a * d) = b / d := by have ha : a ≠ 0 := ((Ordinal.zero_le c).trans_lt hc).ne' obtain rfl | hd := eq_or_ne d 0 · rw [mul_zero, div_zero, div_zero] · have H := mul_ne_zero ha hd apply le_antisymm · rw [← lt_succ_iff, div_lt H, mul_assoc] · apply (add_lt_add_left hc _).trans_le rw [← mul_succ] apply mul_le_mul_left' rw [succ_le_iff] exact lt_mul_succ_div b hd · rw [le_div H, mul_assoc] exact (mul_le_mul_left' (mul_div_le b d) a).trans (le_add_right _ c) theorem mul_div_mul_cancel {a : Ordinal} (ha : a ≠ 0) (b c) : a * b / (a * c) = b / c := by convert mul_add_div_mul (Ordinal.pos_iff_ne_zero.2 ha) b c using 1 rw [add_zero] @[simp] theorem div_one (a : Ordinal) : a / 1 = a := by simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero @[simp] theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by simpa only [mul_one] using mul_div_cancel 1 h theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c := if a0 : a = 0 then by simp only [a0, zero_mul, sub_self] else eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0] theorem isSuccLimit_add_iff {a b : Ordinal} : IsSuccLimit (a + b) ↔ IsSuccLimit b ∨ b = 0 ∧ IsSuccLimit a := by constructor <;> intro h · by_cases h' : b = 0 · rw [h', add_zero] at h right exact ⟨h', h⟩ left rw [← add_sub_cancel a b] apply isSuccLimit_sub h suffices a + 0 < a + b by simpa only [add_zero] using this rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero] rcases h with (h | ⟨rfl, h⟩) · exact isSuccLimit_add a h · simpa only [add_zero] @[deprecated (since := "2025-07-09")] alias isLimit_add_iff := isSuccLimit_add_iff theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c) | a, _, c, ⟨b, rfl⟩ => ⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by rw [e, ← mul_add] apply dvd_mul_right⟩ theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b | a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0] theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b -- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e` | a, _, b0, ⟨b, e⟩ => by subst e -- Porting note: `Ne` is required. simpa only [mul_one] using mul_le_mul_left' (one_le_iff_ne_zero.2 fun h : b = 0 => by simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b := if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm else if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂ else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂) instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) := ⟨@dvd_antisymm⟩ /-- `a % b` is the unique ordinal `o'` satisfying `a = b * o + o'` with `o' < b`. -/ instance mod : Mod Ordinal := ⟨fun a b => a - b * (a / b)⟩ theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) := rfl theorem mod_le (a b : Ordinal) : a % b ≤ a := sub_le_self a _ @[simp] theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero] theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero] @[simp] theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self] theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a := Ordinal.add_sub_cancel_of_le <| mul_div_le _ _ theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b := (add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h @[simp] theorem mod_self (a : Ordinal) : a % a = 0 := if a0 : a = 0 then by simp only [a0, zero_mod] else by simp only [mod_def, div_self a0, mul_one, sub_self] @[simp] theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self] theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a := ⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩ theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by rcases H with ⟨c, rfl⟩ rcases eq_or_ne b 0 with (rfl | hb) · simp · simp [mod_def, hb] theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 := ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩ @[simp] theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by rcases eq_or_ne x 0 with rfl | hx · simp · rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def] @[simp] theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by simpa using mul_add_mod_self x y 0 theorem mul_add_mod_mul {w x : Ordinal} (hw : w < x) (y z : Ordinal) : (x * y + w) % (x * z) = x * (y % z) + w := by rw [mod_def, mul_add_div_mul hw] apply sub_eq_of_add_eq rw [← add_assoc, mul_assoc, ← mul_add, div_add_mod] theorem mul_mod_mul (x y z : Ordinal) : (x * y) % (x * z) = x * (y % z) := by obtain rfl | hx := Ordinal.eq_zero_or_pos x · simp · convert mul_add_mod_mul hx y z using 1 <;> rw [add_zero] theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by nth_rw 2 [← div_add_mod a b] rcases h with ⟨d, rfl⟩ rw [mul_assoc, mul_add_mod_self] @[simp] theorem mod_mod (a b : Ordinal) : a % b % b = a % b := mod_mod_of_dvd a dvd_rfl /-! ### Casting naturals into ordinals, compatibility with operations -/ instance instCharZero : CharZero Ordinal := by refine ⟨fun a b h ↦ ?_⟩ rwa [← Cardinal.ord_nat, ← Cardinal.ord_nat, Cardinal.ord_inj, Nat.cast_inj] at h @[simp] theorem one_add_natCast (m : ℕ) : 1 + (m : Ordinal) = succ m := by rw [← Nat.cast_one, ← Nat.cast_add, add_comm] rfl @[simp] theorem one_add_ofNat (m : ℕ) [m.AtLeastTwo] : 1 + (ofNat(m) : Ordinal) = Order.succ (OfNat.ofNat m : Ordinal) := one_add_natCast m @[simp, norm_cast] theorem natCast_mul (m : ℕ) : ∀ n : ℕ, ((m * n : ℕ) : Ordinal) = m * n | 0 => by simp | n + 1 => by rw [Nat.mul_succ, Nat.cast_add, natCast_mul m n, Nat.cast_succ, mul_add_one] @[simp, norm_cast] theorem natCast_sub (m n : ℕ) : ((m - n : ℕ) : Ordinal) = m - n := by rcases le_total m n with h | h · rw [tsub_eq_zero_iff_le.2 h, Ordinal.sub_eq_zero_iff_le.2 (Nat.cast_le.2 h), Nat.cast_zero] · rw [← add_left_cancel_iff (a := ↑n), ← Nat.cast_add, add_tsub_cancel_of_le h, Ordinal.add_sub_cancel_of_le (Nat.cast_le.2 h)] @[simp, norm_cast] theorem natCast_div (m n : ℕ) : ((m / n : ℕ) : Ordinal) = m / n := by rcases eq_or_ne n 0 with (rfl | hn) · simp · have hn' : (n : Ordinal) ≠ 0 := Nat.cast_ne_zero.2 hn apply le_antisymm · rw [le_div hn', ← natCast_mul, Nat.cast_le, mul_comm] apply Nat.div_mul_le_self · rw [div_le hn', ← add_one_eq_succ, ← Nat.cast_succ, ← natCast_mul, Nat.cast_lt, mul_comm, ← Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero hn)] apply Nat.lt_succ_self @[simp, norm_cast] theorem natCast_mod (m n : ℕ) : ((m % n : ℕ) : Ordinal) = m % n := by rw [← add_left_cancel_iff, div_add_mod, ← natCast_div, ← natCast_mul, ← Nat.cast_add, Nat.div_add_mod] @[simp] theorem lift_natCast : ∀ n : ℕ, lift.{u, v} n = n | 0 => by simp | n + 1 => by simp [lift_natCast n] @[simp] theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] : lift.{u, v} ofNat(n) = OfNat.ofNat n := lift_natCast n /-! ### Properties of `ω` -/ theorem lt_omega0 {o : Ordinal} : o < ω ↔ ∃ n : ℕ, o = n := by simp_rw [← Cardinal.ord_aleph0, Cardinal.lt_ord, lt_aleph0, card_eq_nat] theorem nat_lt_omega0 (n : ℕ) : ↑n < ω := lt_omega0.2 ⟨_, rfl⟩ theorem eq_nat_or_omega0_le (o : Ordinal) : (∃ n : ℕ, o = n) ∨ ω ≤ o := by obtain ho | ho := lt_or_ge o ω · exact Or.inl <| lt_omega0.1 ho · exact Or.inr ho theorem omega0_pos : 0 < ω := nat_lt_omega0 0 theorem omega0_ne_zero : ω ≠ 0 := omega0_pos.ne' theorem one_lt_omega0 : 1 < ω := by simpa only [Nat.cast_one] using nat_lt_omega0 1 theorem isSuccLimit_omega0 : IsSuccLimit ω := by rw [isSuccLimit_iff, isSuccPrelimit_iff_succ_lt] refine ⟨omega0_ne_zero, fun o h => ?_⟩ obtain ⟨n, rfl⟩ := lt_omega0.1 h exact nat_lt_omega0 (n + 1) @[deprecated (since := "2025-07-09")] alias isLimit_omega0 := isSuccLimit_omega0 @[deprecated (since := "2025-07-09")] alias nat_lt_limit := natCast_lt_of_isSuccLimit theorem omega0_le {o : Ordinal} : ω ≤ o ↔ ∀ n : ℕ, ↑n ≤ o := ⟨fun h n => (nat_lt_omega0 _).le.trans h, fun H => le_of_forall_lt fun a h => by let ⟨n, e⟩ := lt_omega0.1 h rw [e, ← succ_le_iff]; exact H (n + 1)⟩ theorem omega0_le_of_isSuccLimit {o} (h : IsSuccLimit o) : ω ≤ o := omega0_le.2 fun n => le_of_lt <| natCast_lt_of_isSuccLimit h n @[deprecated (since := "2025-07-09")] alias omega0_le_of_isLimit := omega0_le_of_isSuccLimit theorem natCast_add_omega0 (n : ℕ) : n + ω = ω := by refine le_antisymm (le_of_forall_lt fun a ha ↦ ?_) (le_add_left _ _) obtain ⟨b, hb', hb⟩ := (lt_add_iff omega0_ne_zero).1 ha obtain ⟨m, rfl⟩ := lt_omega0.1 hb' apply hb.trans_lt exact_mod_cast nat_lt_omega0 (n + m) theorem one_add_omega0 : 1 + ω = ω := mod_cast natCast_add_omega0 1 theorem add_omega0 {a : Ordinal} (h : a < ω) : a + ω = ω := by obtain ⟨n, rfl⟩ := lt_omega0.1 h exact natCast_add_omega0 n @[simp] theorem natCast_add_of_omega0_le {o} (h : ω ≤ o) (n : ℕ) : n + o = o := by rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, natCast_add_omega0] @[simp] theorem one_add_of_omega0_le {o} (h : ω ≤ o) : 1 + o = o := mod_cast natCast_add_of_omega0_le h 1 open Ordinal -- TODO: prove `IsSuccPrelimit a ↔ ω ∣ a`. theorem isSuccLimit_iff_omega0_dvd {a : Ordinal} : IsSuccLimit a ↔ a ≠ 0 ∧ ω ∣ a := by refine ⟨fun l => ⟨l.ne_bot, ⟨a / ω, le_antisymm ?_ (mul_div_le _ _)⟩⟩, fun h => ?_⟩ · refine l.le_iff_forall_le.2 fun x hx => le_of_lt ?_ rw [← div_lt omega0_ne_zero, ← succ_le_iff, le_div omega0_ne_zero, mul_succ, add_le_iff_of_isSuccLimit isSuccLimit_omega0] intro b hb rcases lt_omega0.1 hb with ⟨n, rfl⟩ exact (add_le_add_right (mul_div_le _ _) _).trans (lt_sub.1 <| natCast_lt_of_isSuccLimit (isSuccLimit_sub l hx) _).le · rcases h with ⟨a0, b, rfl⟩ refine isSuccLimit_mul_left isSuccLimit_omega0 (Ordinal.pos_iff_ne_zero.2 <| mt ?_ a0) intro e simp only [e, mul_zero] @[deprecated (since := "2025-07-09")] alias isLimit_iff_omega0_dvd := isSuccLimit_iff_omega0_dvd @[simp] theorem natCast_mod_omega0 (n : ℕ) : n % ω = n := mod_eq_of_lt (nat_lt_omega0 n) end Ordinal namespace Cardinal open Ordinal @[simp] theorem add_one_of_aleph0_le {c} (h : ℵ₀ ≤ c) : c + 1 = c := by rw [add_comm, ← card_ord c, ← card_one, ← card_add, one_add_of_omega0_le] rwa [← ord_aleph0, ord_le_ord] theorem isSuccLimit_ord {c} (co : ℵ₀ ≤ c) : IsSuccLimit (ord c) := by rw [isSuccLimit_iff, isSuccPrelimit_iff_succ_lt] refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩ · rw [← Ordinal.le_zero, ord_le] at h simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h · rw [ord_le] at h ⊢ rwa [← @add_one_of_aleph0_le (card a), ← card_succ] rw [← ord_le, ← IsSuccLimit.le_succ_iff, ord_le] · exact co.trans h · rw [ord_aleph0] exact Ordinal.isSuccLimit_omega0 @[deprecated (since := "2025-07-09")] alias isLimit_ord := isSuccLimit_ord theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.toType := toType_noMax_of_succ_lt fun _ ↦ (isSuccLimit_ord h).succ_lt end Cardinal
DirectedInverseSystem.lean
/- Copyright (c) 2024 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Order.SuccPred.Limit import Mathlib.Order.UpperLower.Basic /-! # Definition of direct systems, inverse systems, and cardinalities in specific inverse systems The first part of this file concerns directed systems: `DirectLimit` is defined as the quotient of the disjoint union (`Sigma` type) by an equivalence relation (`Setoid`): compare `CategoryTheory.Limits.Types.Quot`, which is a quotient by a plain relation. Recursion and induction principles for constructing functions from and to `DirectLimit` and proving things about elements in `DirectLimit`. In the second part we compute the cardinality of each node in an inverse system `F i` indexed by a well-order in which every map between successive nodes has constant fiber `X i`, and every limit node is the `limit` of the inverse subsystem formed by all previous nodes. (To avoid importing `Cardinal`, we in fact construct a bijection rather than stating the result in terms of `Cardinal.mk`.) The most tricky part of the whole argument happens at limit nodes: if `i : ι` is a limit, what we have in hand is a family of bijections `F j ≃ ∀ l : Iio j, X l` for every `j < i`, which we would like to "glue" up to a bijection `F i ≃ ∀ l : Iio i, X l`. We denote `∀ l : Iio i, X l` by `PiLT X i`, and they form an inverse system just like the `F i`. Observe that at a limit node `i`, `PiLT X i` is actually the inverse limit of `PiLT X j` over all `j < i` (`piLTLim`). If the family of bijections `F j ≃ PiLT X j` is natural (`IsNatEquiv`), we immediately obtain a bijection between the limits `limit F i ≃ PiLT X i` (`invLimEquiv`), and we just need an additional bijection `F i ≃ limit F i` to obtain the desired extension `F i ≃ PiLT X i` to the limit node `i`. (We do have such a bijection, for example, when we consider a directed system of algebraic structures (say fields) `K i`, and `F` is the inverse system of homomorphisms `K i ⟶ K` into a specific field `K`.) Now our task reduces to the recursive construction of a *natural* family of bijections for each `i`. We can prove that a natural family over all `l ≤ i` (`Iic i`) extends to a natural family over `Iic i⁺` (where `i⁺ = succ i`), but at a limit node, recursion stops working: we have natural families over all `Iic j` for each `j < i`, but we need to know that they glue together to form a natural family over all `l < i` (`Iio i`). This intricacy did not occur to the author when he thought he had a proof and set out to formalize it. Fortunately he was able to figure out an additional `compat` condition (compatibility with the bijections `F i⁺ ≃ F i × X i` in the `X` component) that guarantees uniqueness (`unique_pEquivOn`) and hence gluability (well-definedness): see `pEquivOnGlue`. Instead of just a family of natural families, we actually construct a family of the stronger `PEquivOn`s that bundles the `compat` condition, in order for the inductive argument to work. It is possible to circumvent the introduction of the `compat` condition using Zorn's lemma; if there is a chain of natural families (i.e. for any two families in the chain, one is an extension of the other) over lowersets (which are all of the form `Iic`, `Iio`, or `univ`), we can clearly take the union to get a natural family that extends them all. If a maximal natural family has domain `Iic i` or `Iio i` (`i` a limit), we already know how to extend it one step further to `Iic i⁺` or `Iic i` respectively, so it must be the case that the domain is everything. However, the author chose the `compat` approach in the end because it constructs the distinguished bijection that is compatible with the projections to all `X i`. -/ open Order Set variable {ι : Type*} [Preorder ι] {F₁ F₂ F X : ι → Type*} variable (F) in /-- A directed system is a functor from a category (directed poset) to another category. -/ class DirectedSystem (f : ∀ ⦃i j⦄, i ≤ j → F i → F j) : Prop where map_self ⦃i⦄ (x : F i) : f le_rfl x = x map_map ⦃k j i⦄ (hij : i ≤ j) (hjk : j ≤ k) (x : F i) : f hjk (f hij x) = f (hij.trans hjk) x section DirectedSystem variable {T₁ : ∀ ⦃i j : ι⦄, i ≤ j → Sort*} (f₁ : ∀ i j (h : i ≤ j), T₁ h) variable [∀ ⦃i j⦄ (h : i ≤ j), FunLike (T₁ h) (F₁ i) (F₁ j)] [DirectedSystem F₁ (f₁ · · ·)] variable {T₂ : ∀ ⦃i j : ι⦄, i ≤ j → Sort*} (f₂ : ∀ i j (h : i ≤ j), T₂ h) variable [∀ ⦃i j⦄ (h : i ≤ j), FunLike (T₂ h) (F₂ i) (F₂ j)] [DirectedSystem F₂ (f₂ · · ·)] variable {T : ∀ ⦃i j : ι⦄, i ≤ j → Sort*} (f : ∀ i j (h : i ≤ j), T h) variable [∀ ⦃i j⦄ (h : i ≤ j), FunLike (T h) (F i) (F j)] [DirectedSystem F (f · · ·)] /-- A copy of `DirectedSystem.map_self` specialized to FunLike, as otherwise the `fun i j h ↦ f i j h` can confuse the simplifier. -/ theorem DirectedSystem.map_self' ⦃i⦄ (x) : f i i le_rfl x = x := DirectedSystem.map_self (f := (f · · ·)) x /-- A copy of `DirectedSystem.map_map` specialized to FunLike, as otherwise the `fun i j h ↦ f i j h` can confuse the simplifier. -/ theorem DirectedSystem.map_map' ⦃i j k⦄ (hij hjk x) : f j k hjk (f i j hij x) = f i k (hij.trans hjk) x := DirectedSystem.map_map (f := (f · · ·)) hij hjk x namespace DirectLimit open DirectedSystem variable [IsDirected ι (· ≤ ·)] /-- The setoid on the sigma type defining the direct limit. -/ def setoid : Setoid (Σ i, F i) where r x y := ∃ᵉ (i) (hx : x.1 ≤ i) (hy : y.1 ≤ i), f _ _ hx x.2 = f _ _ hy y.2 iseqv := ⟨fun x ↦ ⟨x.1, le_rfl, le_rfl, rfl⟩, fun ⟨i, hx, hy, eq⟩ ↦ ⟨i, hy, hx, eq.symm⟩, fun ⟨j, hx, _, jeq⟩ ⟨k, _, hz, keq⟩ ↦ have ⟨i, hji, hki⟩ := exists_ge_ge j k ⟨i, hx.trans hji, hz.trans hki, by rw [← map_map' _ hx hji, ← map_map' _ hz hki, jeq, ← keq, map_map', map_map']⟩⟩ theorem r_of_le (x : Σ i, F i) (i : ι) (h : x.1 ≤ i) : (setoid f).r x ⟨i, f _ _ h x.2⟩ := ⟨i, h, le_rfl, (map_map' _ _ _ _).symm⟩ variable (F) in /-- The direct limit of a directed system. -/ abbrev _root_.DirectLimit : Type _ := Quotient (setoid f) variable {f} in theorem eq_of_le (x : Σ i, F i) (i : ι) (h : x.1 ≤ i) : (⟦x⟧ : DirectLimit F f) = ⟦⟨i, f _ _ h x.2⟩⟧ := Quotient.sound (r_of_le _ x i h) @[elab_as_elim] protected theorem induction {C : DirectLimit F f → Prop} (ih : ∀ i x, C ⟦⟨i, x⟩⟧) (x : DirectLimit F f) : C x := Quotient.ind (fun _ ↦ ih _ _) x theorem exists_eq_mk (z : DirectLimit F f) : ∃ i x, z = ⟦⟨i, x⟩⟧ := by rcases z; exact ⟨_, _, rfl⟩ theorem exists_eq_mk₂ (z w : DirectLimit F f) : ∃ i x y, z = ⟦⟨i, x⟩⟧ ∧ w = ⟦⟨i, y⟩⟧ := z.inductionOn₂ w fun x y ↦ have ⟨i, hxi, hyi⟩ := exists_ge_ge x.1 y.1 ⟨i, _, _, eq_of_le x i hxi, eq_of_le y i hyi⟩ theorem exists_eq_mk₃ (w u v : DirectLimit F f) : ∃ i x y z, w = ⟦⟨i, x⟩⟧ ∧ u = ⟦⟨i, y⟩⟧ ∧ v = ⟦⟨i, z⟩⟧ := w.inductionOn₃ u v fun x y z ↦ have ⟨i, hxi, hyi, hzi⟩ := directed_of₃ (· ≤ ·) x.1 y.1 z.1 ⟨i, _, _, _, eq_of_le x i hxi, eq_of_le y i hyi, eq_of_le z i hzi⟩ @[elab_as_elim] protected theorem induction₂ {C : DirectLimit F f → DirectLimit F f → Prop} (ih : ∀ i x y, C ⟦⟨i, x⟩⟧ ⟦⟨i, y⟩⟧) (x y : DirectLimit F f) : C x y := by obtain ⟨_, _, _, rfl, rfl⟩ := exists_eq_mk₂ f x y; apply ih @[elab_as_elim] protected theorem induction₃ {C : DirectLimit F f → DirectLimit F f → DirectLimit F f → Prop} (ih : ∀ i x y z, C ⟦⟨i, x⟩⟧ ⟦⟨i, y⟩⟧ ⟦⟨i, z⟩⟧) (x y z : DirectLimit F f) : C x y z := by obtain ⟨_, _, _, _, rfl, rfl, rfl⟩ := exists_eq_mk₃ f x y z; apply ih theorem mk_injective (h : ∀ i j hij, Function.Injective (f i j hij)) (i) : Function.Injective fun x ↦ (⟦⟨i, x⟩⟧ : DirectLimit F f) := fun _ _ eq ↦ have ⟨_, _, _, eq⟩ := Quotient.eq.mp eq; h _ _ _ eq section map₀ variable [Nonempty ι] (ih : ∀ i, F i) /-- "Nullary map" to construct an element in the direct limit. -/ noncomputable def map₀ : DirectLimit F f := ⟦⟨Classical.arbitrary ι, ih _⟩⟧ theorem map₀_def (compat : ∀ i j h, f i j h (ih i) = ih j) (i) : map₀ f ih = ⟦⟨i, ih i⟩⟧ := have ⟨j, hcj, hij⟩ := exists_ge_ge (Classical.arbitrary ι) i Quotient.sound ⟨j, hcj, hij, (compat ..).trans (compat ..).symm⟩ end map₀ section lift variable {C : Sort*} (ih : ∀ i, F i → C) (compat : ∀ i j h x, ih i x = ih j (f i j h x)) /-- To define a function from the direct limit, it suffices to provide one function from each component subject to a compatibility condition. -/ protected def lift (z : DirectLimit F f) : C := z.recOn (fun x ↦ ih x.1 x.2) fun x y ⟨k, hxk, hyk, eq⟩ ↦ by simp_rw [eq_rec_constant, compat _ _ hxk, compat _ _ hyk, eq] theorem lift_def (x) : DirectLimit.lift f ih compat ⟦x⟧ = ih x.1 x.2 := rfl theorem lift_injective (h : ∀ i, Function.Injective (ih i)) : Function.Injective (DirectLimit.lift f ih compat) := DirectLimit.induction₂ _ fun i x y eq ↦ by simp_rw [lift_def] at eq; rw [h i eq] end lift section map variable (ih : ∀ i, F₁ i → F₂ i) (compat : ∀ i j h x, f₂ i j h (ih i x) = ih j (f₁ i j h x)) /-- To define a function from the direct limit, it suffices to provide one function from each component subject to a compatibility condition. -/ def map (z : DirectLimit F₁ f₁) : DirectLimit F₂ f₂ := z.lift _ (fun i x ↦ ⟦⟨i, ih i x⟩⟧) fun j k h x ↦ Quotient.sound <| have ⟨i, hji, hki⟩ := exists_ge_ge j k ⟨i, hji, hki, by simp_rw [compat, map_map']⟩ theorem map_def (x) : map f₁ f₂ ih compat ⟦x⟧ = ⟦⟨x.1, ih x.1 x.2⟩⟧ := rfl end map section lift₂ variable {C : Sort*} (ih : ∀ i, F₁ i → F₂ i → C) (compat : ∀ i j h x y, ih i x y = ih j (f₁ i j h x) (f₂ i j h y)) private noncomputable def lift₂Aux (z : Σ i, F₁ i) (w : Σ i, F₂ i) : {x : C // ∀ i (hzi : z.1 ≤ i) (hwi : w.1 ≤ i), x = ih i (f₁ _ _ hzi z.2) (f₂ _ _ hwi w.2)} := by choose j hzj hwj using exists_ge_ge z.1 w.1 refine ⟨ih j (f₁ _ _ hzj z.2) (f₂ _ _ hwj w.2), fun k hzk hwk ↦ ?_⟩ have ⟨i, hji, hki⟩ := exists_ge_ge j k simp_rw [compat _ _ hji, compat _ _ hki, map_map'] /-- To define a binary function from the direct limit, it suffices to provide one binary function from each component subject to a compatibility condition. -/ protected noncomputable def lift₂ (z : DirectLimit F₁ f₁) (w : DirectLimit F₂ f₂) : C := z.hrecOn₂ w (φ := fun _ _ ↦ C) (lift₂Aux f₁ f₂ ih compat · ·) fun _ _ _ _ ⟨j, hx, hyj, jeq⟩ ⟨k, hyk, hz, keq⟩ ↦ heq_of_eq <| by have ⟨i, hji, hki⟩ := exists_ge_ge j k simp_rw [(lift₂Aux ..).2 _ (hx.trans hji) (hyk.trans hki), (lift₂Aux ..).2 _ (hyj.trans hji) (hz.trans hki), ← map_map' _ hx hji, jeq, ← map_map' _ hz hki, ← keq, map_map'] theorem lift₂_def₂ (x : Σ i, F₁ i) (y : Σ i, F₂ i) (i) (hxi : x.1 ≤ i) (hyi : y.1 ≤ i) : DirectLimit.lift₂ f₁ f₂ ih compat ⟦x⟧ ⟦y⟧ = ih i (f₁ _ _ hxi x.2) (f₂ _ _ hyi y.2) := (lift₂Aux _ _ _ compat _ _).2 .. theorem lift₂_def (i x y) : DirectLimit.lift₂ f₁ f₂ ih compat ⟦⟨i, x⟩⟧ ⟦⟨i, y⟩⟧ = ih i x y := by rw [lift₂_def₂ _ _ _ _ _ _ i le_rfl le_rfl, map_self', map_self'] end lift₂ section map₂ variable (ih : ∀ i, F₁ i → F₂ i → F i) (compat : ∀ i j h x y, f i j h (ih i x y) = ih j (f₁ i j h x) (f₂ i j h y)) /-- To define a function from the direct limit, it suffices to provide one function from each component subject to a compatibility condition. -/ noncomputable def map₂ : DirectLimit F₁ f₁ → DirectLimit F₂ f₂ → DirectLimit F f := DirectLimit.lift₂ f₁ f₂ (fun i x y ↦ ⟦⟨i, ih i x y⟩⟧) fun j k h x y ↦ Quotient.sound <| have ⟨i, hji, hki⟩ := exists_ge_ge j k ⟨i, hji, hki, by simp_rw [compat, map_map']⟩ theorem map₂_def₂ (x y) (i) (hxi : x.1 ≤ i) (hyi : y.1 ≤ i) : map₂ f₁ f₂ f ih compat ⟦x⟧ ⟦y⟧ = ⟦⟨i, ih i (f₁ _ _ hxi x.2) (f₂ _ _ hyi y.2)⟩⟧ := lift₂_def₂ .. theorem map₂_def (i x y) : map₂ f₁ f₂ f ih compat ⟦⟨i, x⟩⟧ ⟦⟨i, y⟩⟧ = ⟦⟨i, ih i x y⟩⟧ := lift₂_def .. end map₂ end DirectLimit end DirectedSystem variable (f : ∀ ⦃i j : ι⦄, i ≤ j → F j → F i) ⦃i j : ι⦄ (h : i ≤ j) /-- A inverse system indexed by a preorder is a contravariant functor from the preorder to another category. It is dual to `DirectedSystem`. -/ class InverseSystem : Prop where map_self ⦃i : ι⦄ (x : F i) : f le_rfl x = x map_map ⦃k j i : ι⦄ (hkj : k ≤ j) (hji : j ≤ i) (x : F i) : f hkj (f hji x) = f (hkj.trans hji) x namespace InverseSystem section proj /-- The inverse limit of an inverse system of types. -/ def limit (i : ι) : Set (∀ l : Iio i, F l) := {F | ∀ ⦃j k⦄ (h : j.1 ≤ k.1), f h (F k) = F j} /-- For a family of types `X` indexed by an preorder `ι` and an element `i : ι`, `piLT X i` is the product of all the types indexed by elements below `i`. -/ abbrev piLT (X : ι → Type*) (i : ι) := ∀ l : Iio i, X l /-- The projection from a Pi type to the Pi type over an initial segment of its indexing type. -/ abbrev piLTProj (f : piLT X j) : piLT X i := fun l ↦ f ⟨l, l.2.trans_le h⟩ theorem piLTProj_intro {l : Iio j} {f : piLT X j} (hl : l < i) : f l = piLTProj h f ⟨l, hl⟩ := rfl /-- The predicate that says a family of equivalences between `F j` and `piLT X j` is a natural transformation. -/ def IsNatEquiv {s : Set ι} (equiv : ∀ j : s, F j ≃ piLT X j) : Prop := ∀ ⦃j k⦄ (hj : j ∈ s) (hk : k ∈ s) (h : k ≤ j) (x : F j), equiv ⟨k, hk⟩ (f h x) = piLTProj h (equiv ⟨j, hj⟩ x) variable {ι : Type*} [LinearOrder ι] {X : ι → Type*} {i : ι} (hi : IsSuccPrelimit i) /-- If `i` is a limit in a well-ordered type indexing a family of types, then `piLT X i` is the limit of all `piLT X j` for `j < i`. -/ @[simps apply] noncomputable def piLTLim : piLT X i ≃ limit (piLTProj (X := X)) i where toFun f := ⟨fun j ↦ piLTProj j.2.le f, fun _ _ _ ↦ rfl⟩ invFun f l := let k := hi.mid l.2; f.1 ⟨k, k.2.2⟩ ⟨l, k.2.1⟩ right_inv f := by ext j l set k := hi.mid (l.2.trans j.2) obtain le | le := le_total j ⟨k, k.2.2⟩ exacts [congr_fun (f.2 le) l, (congr_fun (f.2 le) ⟨l, _⟩).symm] theorem piLTLim_symm_apply {f} (k : Iio i) {l : Iio i} (hl : l.1 < k.1) : (piLTLim (X := X) hi).symm f l = f.1 k ⟨l, hl⟩ := by conv_rhs => rw [← (piLTLim hi).right_inv f] rfl end proj variable {ι : Type*} {F X : ι → Type*} {i : ι} section variable [PartialOrder ι] [DecidableEq ι] /-- Splitting off the `X i` factor from the Pi type over `{j | j ≤ i}`. -/ def piSplitLE : piLT X i × X i ≃ ∀ j : Iic i, X j where toFun f j := if h : j = i then h.symm ▸ f.2 else f.1 ⟨j, j.2.lt_of_ne h⟩ invFun f := (fun j ↦ f ⟨j, j.2.le⟩, f ⟨i, le_rfl⟩) left_inv f := by ext j; exacts [dif_neg j.2.ne, dif_pos rfl] right_inv f := by grind @[simp] theorem piSplitLE_eq {f : piLT X i × X i} : piSplitLE f ⟨i, le_rfl⟩ = f.2 := by simp [piSplitLE] theorem piSplitLE_lt {f : piLT X i × X i} {j} (hj : j < i) : piSplitLE f ⟨j, hj.le⟩ = f.1 ⟨j, hj⟩ := dif_neg hj.ne end variable [LinearOrder ι] {f : ∀ ⦃i j : ι⦄, i ≤ j → F j → F i} local postfix:max "⁺" => succ -- Note: conflicts with `PosPart` notation section Succ variable [SuccOrder ι] variable (equiv : ∀ j : Iic i, F j ≃ piLT X j) (e : F i⁺ ≃ F i × X i) (hi : ¬ IsMax i) /-- Extend a family of bijections to `piLT` by one step. -/ def piEquivSucc : ∀ j : Iic i⁺, F j ≃ piLT X j := piSplitLE (X := fun i ↦ F i ≃ piLT X i) (fun j ↦ equiv ⟨j, (lt_succ_iff_of_not_isMax hi).mp j.2⟩, e.trans <| ((equiv ⟨i, le_rfl⟩).prodCongr <| Equiv.refl _).trans <| piSplitLE.trans <| Equiv.piCongrSet <| Set.ext fun _ ↦ (lt_succ_iff_of_not_isMax hi).symm) theorem piEquivSucc_self {x} : piEquivSucc equiv e hi ⟨_, le_rfl⟩ x ⟨i, lt_succ_of_not_isMax hi⟩ = (e x).2 := by simp [piEquivSucc] variable {equiv e} theorem isNatEquiv_piEquivSucc [InverseSystem f] (H : ∀ x, (e x).1 = f (le_succ i) x) (nat : IsNatEquiv f equiv) : IsNatEquiv f (piEquivSucc equiv e hi) := fun j k hj hk h x ↦ by have lt_succ {j} := (lt_succ_iff_of_not_isMax (b := j) hi).mpr obtain rfl | hj := le_succ_iff_eq_or_le.mp hj · obtain rfl | hk := le_succ_iff_eq_or_le.mp hk · simp [InverseSystem.map_self] · funext l rw [piEquivSucc, piSplitLE_lt (lt_succ hk), ← InverseSystem.map_map (f := f) hk (le_succ i), ← H, piLTProj, nat le_rfl] simp [piSplitLE_lt (l.2.trans_le hk)] · rw [piEquivSucc, piSplitLE_lt (h.trans_lt <| lt_succ hj), nat hj, piSplitLE_lt (lt_succ hj)] end Succ section Lim variable {equiv : ∀ j : Iio i, F j ≃ piLT X j} (nat : IsNatEquiv f equiv) /-- A natural family of bijections below a limit ordinal induces a bijection at the limit ordinal. -/ @[simps] def invLimEquiv : limit f i ≃ limit (piLTProj (X := X)) i where toFun t := ⟨fun l ↦ equiv l (t.1 l), fun _ _ h ↦ Eq.symm <| by simp_rw [← t.2 h]; apply nat⟩ invFun t := ⟨fun l ↦ (equiv l).symm (t.1 l), fun _ _ h ↦ (Equiv.eq_symm_apply _).mpr <| by rw [nat, ← t.2 h]; simp⟩ left_inv t := by ext; apply Equiv.left_inv right_inv t := by ext1; ext1; apply Equiv.right_inv variable (equivLim : F i ≃ limit f i) (hi : IsSuccPrelimit i) /-- Extend a natural family of bijections to a limit ordinal. -/ noncomputable def piEquivLim : ∀ j : Iic i, F j ≃ piLT X j := piSplitLE (X := fun j ↦ F j ≃ piLT X j) (equiv, equivLim.trans <| (invLimEquiv nat).trans (piLTLim hi).symm) variable {equivLim} theorem isNatEquiv_piEquivLim [InverseSystem f] (H : ∀ x l, (equivLim x).1 l = f l.2.le x) : IsNatEquiv f (piEquivLim nat equivLim hi) := fun j k hj hk h t ↦ by obtain rfl | hj := hj.eq_or_lt · obtain rfl | hk := hk.eq_or_lt · simp [InverseSystem.map_self] · funext l simp_rw [piEquivLim, piSplitLE_lt hk, piSplitLE_eq, Equiv.trans_apply] rw [piLTProj, piLTLim_symm_apply hi ⟨k, hk⟩ (by exact l.2), invLimEquiv_apply_coe, H] · rw [piEquivLim, piSplitLE_lt (h.trans_lt hj), piSplitLE_lt hj]; apply nat end Lim section Unique variable [SuccOrder ι] (f) (equivSucc : ∀ ⦃i⦄, ¬IsMax i → F i⁺ ≃ F i × X i) /-- A natural partial family of bijections to `piLT` satisfying a compatibility condition. -/ @[ext] structure PEquivOn (s : Set ι) where /-- A partial family of bijections between `F` and `piLT X` defined on some set in `ι`. -/ equiv (i : s) : F i ≃ piLT X i /-- It is a natural family of bijections. -/ nat : IsNatEquiv f equiv /-- It is compatible with a family of bijections relating `F i⁺` to `F i`. -/ compat {i : ι} (hsi : (i⁺ : ι) ∈ s) (hi : ¬IsMax i) (x) : equiv ⟨i⁺, hsi⟩ x ⟨i, lt_succ_of_not_isMax hi⟩ = (equivSucc hi x).2 variable {s t : Set ι} {f equivSucc} [WellFoundedLT ι] /-- Restrict a partial family of bijections to a smaller set. -/ @[simps] def PEquivOn.restrict (e : PEquivOn f equivSucc t) (h : s ⊆ t) : PEquivOn f equivSucc s where equiv i := e.equiv ⟨i, h i.2⟩ nat _ _ _ _ := e.nat _ _ compat _ := e.compat _ theorem unique_pEquivOn (hs : IsLowerSet s) {e₁ e₂ : PEquivOn f equivSucc s} : e₁ = e₂ := by obtain ⟨e₁, nat₁, compat₁⟩ := e₁ obtain ⟨e₂, nat₂, compat₂⟩ := e₂ ext1; ext1 i; dsimp only refine SuccOrder.prelimitRecOn i.1 (motive := fun i ↦ ∀ h : i ∈ s, e₁ ⟨i, h⟩ = e₂ ⟨i, h⟩) (fun i nmax ih hi ↦ ?_) (fun i lim ih hi ↦ ?_) i.2 · ext x ⟨j, hj⟩ obtain rfl | hj := ((lt_succ_iff_of_not_isMax nmax).mp hj).eq_or_lt · exact (compat₁ _ nmax x).trans (compat₂ _ nmax x).symm have hi : i ∈ s := hs (le_succ i) hi rw [piLTProj_intro (f := e₁ _ x) (le_succ i) (by exact hj), ← nat₁ _ hi (by exact le_succ i), ih, nat₂ _ hi (by exact le_succ i)] · ext x j have ⟨k, hjk, hki⟩ := lim.mid j.2 have hk : k ∈ s := hs hki.le hi rw [piLTProj_intro (f := e₁ _ x) hki.le hjk, piLTProj_intro (f := e₂ _ x) hki.le hjk, ← nat₁ _ hk, ← nat₂ _ hk, ih _ hki] theorem pEquivOn_apply_eq (h : IsLowerSet (s ∩ t)) {e₁ : PEquivOn f equivSucc s} {e₂ : PEquivOn f equivSucc t} {i} {his : i ∈ s} {hit : i ∈ t} : e₁.equiv ⟨i, his⟩ = e₂.equiv ⟨i, hit⟩ := show (e₁.restrict inter_subset_left).equiv ⟨i, his, hit⟩ = (e₂.restrict inter_subset_right).equiv ⟨i, his, hit⟩ from congr_fun (congr_arg _ <| unique_pEquivOn h) _ /-- Extend a partial family of bijections by one step. -/ def pEquivOnSucc [InverseSystem f] (hi : ¬IsMax i) (e : PEquivOn f equivSucc (Iic i)) (H : ∀ ⦃i⦄ (hi : ¬ IsMax i) x, (equivSucc hi x).1 = f (le_succ i) x) : PEquivOn f equivSucc (Iic i⁺) where equiv := piEquivSucc e.equiv (equivSucc hi) hi nat := isNatEquiv_piEquivSucc hi (H hi) e.nat compat hsj hj x := by obtain eq | lt := hsj.eq_or_lt · cases (succ_eq_succ_iff_of_not_isMax hj hi).mp eq; simp [piEquivSucc] · rwa [piEquivSucc, piSplitLE_lt, e.compat] variable (hi : IsSuccPrelimit i) (e : ∀ j : Iio i, PEquivOn f equivSucc (Iic j)) /-- Glue partial families of bijections at a limit ordinal, obtaining a partial family over a right-open interval. -/ noncomputable def pEquivOnGlue : PEquivOn f equivSucc (Iio i) where equiv := (piLTLim (X := fun j ↦ F j ≃ piLT X j) hi).symm ⟨fun j ↦ ((e j).restrict fun _ h ↦ h.le).equiv, fun _ _ h ↦ funext fun _ ↦ pEquivOn_apply_eq ((isLowerSet_Iio _).inter <| isLowerSet_Iio _)⟩ nat j k hj hk h := by rw [piLTLim_symm_apply]; exacts [(e _).nat _ _ _, h.trans_lt (hi.mid _).2.1] compat hj := have k := hi.mid hj by rw [piLTLim_symm_apply hi ⟨_, k.2.2⟩ (by exact k.2.1)]; apply (e _).compat /-- Extend `pEquivOnGlue` by one step, obtaining a partial family over a right-closed interval. -/ noncomputable def pEquivOnLim [InverseSystem f] (equivLim : F i ≃ limit f i) (H : ∀ x l, (equivLim x).1 l = f l.2.le x) : PEquivOn f equivSucc (Iic i) where equiv := piEquivLim (pEquivOnGlue hi e).nat equivLim hi nat := isNatEquiv_piEquivLim (pEquivOnGlue hi e).nat hi H compat hsj hj x := by rw [piEquivLim, piSplitLE_lt (hi.succ_lt <| (succ_le_iff_of_not_isMax hj).mp hsj)] apply (pEquivOnGlue hi e).compat end Unique variable [WellFoundedLT ι] [SuccOrder ι] [InverseSystem f] (equivSucc : ∀ i, ¬IsMax i → {e : F i⁺ ≃ F i × X i // ∀ x, (e x).1 = f (le_succ i) x}) (equivLim : ∀ i, IsSuccPrelimit i → {e : F i ≃ limit f i // ∀ x l, (e x).1 l = f l.2.le x}) private noncomputable def globalEquivAux (i : ι) : PEquivOn f (fun i hi ↦ (equivSucc i hi).1) (Iic i) := SuccOrder.prelimitRecOn i (fun _ hi e ↦ pEquivOnSucc hi e fun i hi ↦ (equivSucc i hi).2) fun i hi e ↦ pEquivOnLim hi (fun j ↦ e j j.2) (equivLim i hi).1 (equivLim i hi).2 /-- Over a well-ordered type, construct a family of bijections by transfinite recursion. -/ noncomputable def globalEquiv (i : ι) : F i ≃ piLT X i := (globalEquivAux equivSucc equivLim i).equiv ⟨i, le_rfl⟩ theorem globalEquiv_naturality ⦃i j⦄ (h : i ≤ j) (x : F j) : letI e := globalEquiv equivSucc equivLim e i (f h x) = piLTProj h (e j x) := by refine (DFunLike.congr_fun ?_ _).trans ((globalEquivAux equivSucc equivLim j).nat le_rfl h h x) exact pEquivOn_apply_eq ((isLowerSet_Iic _).inter <| isLowerSet_Iic _) theorem globalEquiv_compatibility ⦃i⦄ (hi : ¬IsMax i) (x) : globalEquiv equivSucc equivLim i⁺ x ⟨i, lt_succ_of_not_isMax hi⟩ = ((equivSucc i hi).1 x).2 := (globalEquivAux equivSucc equivLim i⁺).compat le_rfl hi x end InverseSystem
galois.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 ssralg poly. From mathcomp Require Import polydiv finset fingroup morphism quotient perm. From mathcomp Require Import action zmodp cyclic matrix mxalgebra vector. From mathcomp Require Import falgebra fieldext separable. (******************************************************************************) (* Basic Galois field theory *) (* *) (* This file defines: *) (* splittingFieldFor K p E <-> E is the smallest field over K that splits p *) (* into linear factors *) (* kHom K E f <=> f : 'End(L) is a ring morphism on E and fixes K *) (* kAut K E f <=> f : 'End(L) is a kHom K E and f @: E == E *) (* kHomExtend E f x y == a kHom K <<E; x>> that extends f and maps x to y, *) (* when f \is a kHom K E and root (minPoly E x) y *) (* splittingFieldType F == the interface type of splitting field extensions *) (* of F, that is, extensions generated by all the *) (* algebraic roots of some polynomial, or, *) (* equivalently, normal field extensions of F *) (* The HB class is called SplittingField. *) (* splitting_field_axiom F L == the axiom stating that L is a splitting field *) (* gal_of E == the group_type of automorphisms of E over the *) (* base field F *) (* 'Gal(E / K) == the group of automorphisms of E that fix K *) (* fixedField s == the field fixed by the set of automorphisms s *) (* fixedField set0 = E when set0 : {set: gal_of E} *) (* normalField K E <=> E is invariant for every 'Gal(L / K) for every L *) (* galois K E <=> E is a normal and separable field extension of K *) (* galTrace K E a == \sum_(f in 'Gal(E / K)) (f a) *) (* galNorm K E a == \prod_(f in 'Gal(E / K)) (f a) *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "''Gal' ( A / B )" (A at level 35, format "''Gal' ( A / B )"). Import GroupScope GRing.Theory. Local Open Scope ring_scope. Section SplittingFieldFor. Variables (F : fieldType) (L : fieldExtType F). Definition splittingFieldFor (U : {vspace L}) (p : {poly L}) (V : {vspace L}) := exists2 rs, p %= \prod_(z <- rs) ('X - z%:P) & <<U & rs>>%VS = V. Lemma splittingFieldForS (K M E : {subfield L}) p : (K <= M)%VS -> (M <= E)%VS -> splittingFieldFor K p E -> splittingFieldFor M p E. Proof. move=> sKM sKE [rs Dp genL]; exists rs => //; apply/eqP. rewrite eqEsubv -[in X in _ && (X <= _)%VS]genL adjoin_seqSl // andbT. by apply/Fadjoin_seqP; split; rewrite // -genL; apply: seqv_sub_adjoin. Qed. End SplittingFieldFor. Section kHom. Variables (F : fieldType) (L : fieldExtType F). Implicit Types (U V : {vspace L}) (K E : {subfield L}) (f g : 'End(L)). Definition kHom U V f := ahom_in V f && (U <= fixedSpace f)%VS. Lemma kHomP_tmp {K V f} : reflect [/\ {in K, forall x, f x = x} & {in V &, forall x y, f (x * y) = f x * f y}] (kHom K V f). Proof. apply: (iffP andP) => [[/ahom_inP[fM _] /subvP idKf] | [idKf fM]]. by split=> // x /idKf/fixedSpaceP. split; last by apply/subvP=> x /idKf/fixedSpaceP. by apply/ahom_inP; split=> //; rewrite idKf ?mem1v. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `kHomP_tmp` instead")] Lemma kHomP {K V f} : reflect [/\ {in V &, forall x y, f (x * y) = f x * f y} & {in K, forall x, f x = x}] (kHom K V f). Proof. by apply: (iffP kHomP_tmp) => [][]. Qed. Lemma kAHomP {U V} {f : 'AEnd(L)} : reflect {in U, forall x, f x = x} (kHom U V f). Proof. by rewrite /kHom ahomWin; apply: fixedSpacesP. Qed. Lemma kHom1 U V : kHom U V \1. Proof. by apply/kAHomP => u _; rewrite lfunE. Qed. Lemma k1HomE V f : kHom 1 V f = ahom_in V f. Proof. by apply: andb_idr => /ahom_inP[_ f1]; apply/fixedSpaceP. Qed. Lemma kHom_monoid_morphism (f : 'End(L)) : reflect (monoid_morphism f) (kHom 1 {:L} f). Proof. by rewrite k1HomE; apply: ahomP_tmp. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `kHom_monoid_morphism` instead")] Lemma kHom_lrmorphism (f : 'End(L)) : reflect (multiplicative f) (kHom 1 {:L} f). Proof. #[warning="-deprecated-since-mathcomp-2.5.0"] by rewrite k1HomE; apply: ahomP. Qed. (* Lemma kHom_lrmorphism (f : 'End(L)) : reflect (lrmorphism f) (kHom 1 {:L} f). *) (* Proof. by rewrite k1HomE; apply: ahomP. Qed. *) Lemma k1AHom V (f : 'AEnd(L)) : kHom 1 V f. Proof. by rewrite k1HomE ahomWin. Qed. Lemma kHom_poly_id K E f p : kHom K E f -> p \is a polyOver K -> map_poly f p = p. Proof. by case/kHomP_tmp=> idKf _ /polyOverP Kp; apply/polyP=> i; rewrite coef_map /= idKf. Qed. Lemma kHomSl U1 U2 V f : (U1 <= U2)%VS -> kHom U2 V f -> kHom U1 V f. Proof. by rewrite /kHom => sU12 /andP[-> /(subv_trans sU12)]. Qed. Lemma kHomSr K V1 V2 f : (V1 <= V2)%VS -> kHom K V2 f -> kHom K V1 f. Proof. by move/subvP=> sV12 /kHomP_tmp[idKf /(sub_in2 sV12)fM]; apply/kHomP_tmp. Qed. Lemma kHomS K1 K2 V1 V2 f : (K1 <= K2)%VS -> (V1 <= V2)%VS -> kHom K2 V2 f -> kHom K1 V1 f. Proof. by move=> sK12 sV12 /(kHomSl sK12)/(kHomSr sV12). Qed. Lemma kHom_eq K E f g : (K <= E)%VS -> {in E, f =1 g} -> kHom K E f = kHom K E g. Proof. move/subvP=> sKE eq_fg; wlog suffices: f g eq_fg / kHom K E f -> kHom K E g. by move=> IH; apply/idP/idP; apply: IH => x /eq_fg. case/kHomP_tmp=> idKf fM; apply/kHomP_tmp. by split=> [x Kx | x y Ex Ey]; rewrite -!eq_fg ?fM ?rpredM // ?idKf ?sKE. Qed. Lemma kHom_inv K E f : kHom K E f -> {in E, {morph f : x / x^-1}}. Proof. case/kHomP_tmp=> idKf fM x Ex. have [-> | nz_x] := eqVneq x 0; first by rewrite linear0 invr0 linear0. have fxV: f x * f x^-1 = 1 by rewrite -fM ?rpredV ?divff // idKf ?mem1v. have Ufx: f x \is a GRing.unit by apply/unitrPr; exists (f x^-1). by apply: (mulrI Ufx); rewrite divrr. Qed. Lemma kHom_dim K E f : kHom K E f -> \dim (f @: E) = \dim E. Proof. move=> homKf; have [idKf fM] := kHomP_tmp homKf. apply/limg_dim_eq/eqP; rewrite -subv0; apply/subvP=> v. rewrite memv_cap memv0 memv_ker => /andP[Ev]; apply: contraLR => nz_v. by rewrite -unitfE unitrE -(kHom_inv homKf) // -fM ?rpredV ?divff ?idKf ?mem1v. Qed. Section kHomMorphism. Variables (K E : {subfield L}) (f : 'End(L)). Let kHomf : subvs_of E -> L := f \o vsval. Lemma kHom_is_zmod_morphism : kHom K E f -> zmod_morphism kHomf. Proof. by case/kHomP_tmp => idKf fM; apply: raddfB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `kHom_is_zmod_morphism` instead")] Definition kHom_is_additive := kHom_is_zmod_morphism. Lemma kHom_is_monoid_morphism : kHom K E f -> monoid_morphism kHomf. Proof. case/kHomP_tmp=> idKf fM; rewrite /kHomf. by split=> [|a b] /=; [rewrite algid1 idKf // mem1v | rewrite /= fM ?subvsP]. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `kHom_is_monoid_morphism` instead")] Definition kHom_is_multiplicative := (fun p => (p.1, p.2)) \o kHom_is_monoid_morphism. Variable (homKEf : kHom K E f). HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ kHomf (kHom_is_zmod_morphism homKEf). HB.instance Definition _ := @GRing.isMonoidMorphism.Build _ _ kHomf (kHom_is_monoid_morphism homKEf). Definition kHom_rmorphism := Eval hnf in (kHomf : {rmorphism _ -> _}). End kHomMorphism. Lemma kHom_horner K E f p x : kHom K E f -> p \is a polyOver E -> x \in E -> f p.[x] = (map_poly f p).[f x]. Proof. move=> homKf /polyOver_subvs[{}p -> Ex]; pose fRM := kHom_rmorphism homKf. by rewrite (horner_map _ _ (Subvs Ex)) -[f _](horner_map fRM) map_poly_comp. Qed. Lemma kHom_root K E f p x : kHom K E f -> p \is a polyOver E -> x \in E -> root p x -> root (map_poly f p) (f x). Proof. by move/kHom_horner=> homKf Ep Ex /rootP px0; rewrite /root -homKf ?px0 ?raddf0. Qed. Lemma kHom_root_id K E f p x : (K <= E)%VS -> kHom K E f -> p \is a polyOver K -> x \in E -> root p x -> root p (f x). Proof. move=> sKE homKf Kp Ex /(kHom_root homKf (polyOverSv sKE Kp) Ex). by rewrite (kHom_poly_id homKf). Qed. Section kHomExtend. Variables (K E : {subfield L}) (f : 'End(L)) (x y : L). Let kHomf z := (map_poly f (Fadjoin_poly E x z)).[y]. Fact kHomExtend_zmod_morphism_subproof : zmod_morphism kHomf. Proof. by move=> a b; rewrite /kHomf 2!raddfB hornerD hornerN. Qed. Fact kHomExtend_scalable_subproof : scalable kHomf. Proof. move=> k a; rewrite /kHomf linearZ /= -[RHS]mulr_algl -hornerZ; congr _.[_]. by apply/polyP => i; rewrite !(coefZ, coef_map) /= !mulr_algl linearZ. Qed. HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ kHomf kHomExtend_zmod_morphism_subproof. HB.instance Definition _ := @GRing.isScalable.Build _ _ _ _ kHomf kHomExtend_scalable_subproof. Let kHomExtendLinear := Eval hnf in (kHomf : {linear _ -> _}). Definition kHomExtend := linfun kHomExtendLinear. Lemma kHomExtendE z : kHomExtend z = (map_poly f (Fadjoin_poly E x z)).[y]. Proof. by rewrite lfunE. Qed. Hypotheses (sKE : (K <= E)%VS) (homKf : kHom K E f). Local Notation Px := (minPoly E x). Hypothesis fPx_y_0 : root (map_poly f Px) y. Lemma kHomExtend_id z : z \in E -> kHomExtend z = f z. Proof. by move=> Ez; rewrite kHomExtendE Fadjoin_polyC ?map_polyC ?hornerC. Qed. Lemma kHomExtend_val : kHomExtend x = y. Proof. have fX: map_poly f 'X = 'X by rewrite (kHom_poly_id homKf) ?polyOverX. have [Ex | E'x] := boolP (x \in E); last first. by rewrite kHomExtendE Fadjoin_polyX // fX hornerX. have:= fPx_y_0; rewrite (minPoly_XsubC Ex) raddfB /= map_polyC fX root_XsubC /=. by rewrite (kHomExtend_id Ex) => /eqP->. Qed. Lemma kHomExtend_poly p : p \in polyOver E -> kHomExtend p.[x] = (map_poly f p).[y]. Proof. move=> Ep; rewrite kHomExtendE (Fadjoin_poly_mod x) //. rewrite (divp_eq (map_poly f p) (map_poly f Px)). rewrite !hornerE (rootP fPx_y_0) mulr0 add0r. have [p1 ->] := polyOver_subvs Ep. have [Px1 ->] := polyOver_subvs (minPolyOver E x). by rewrite -map_modp -!map_poly_comp (map_modp (kHom_rmorphism homKf)). Qed. Lemma kHomExtendP : kHom K <<E; x>> kHomExtend. Proof. have [idKf fM] := kHomP_tmp homKf. apply/kHomP_tmp; split=> [z Kz|]; first by rewrite kHomExtend_id ?(subvP sKE) ?idKf. move=> _ _ /Fadjoin_polyP[p Ep ->] /Fadjoin_polyP[q Eq ->]. rewrite -hornerM !kHomExtend_poly ?rpredM // -hornerM; congr _.[_]. apply/polyP=> i; rewrite coef_map !coefM /= linear_sum /=. by apply: eq_bigr => j _; rewrite !coef_map /= fM ?(polyOverP _). Qed. End kHomExtend. Definition kAut U V f := kHom U V f && (f @: V == V)%VS. Lemma kAutE K E f : kAut K E f = kHom K E f && (f @: E <= E)%VS. Proof. apply/andP/andP=> [[-> /eqP->] // | [homKf EfE]]. by rewrite eqEdim EfE /= (kHom_dim homKf). Qed. Lemma kAutS U1 U2 V f : (U1 <= U2)%VS -> kAut U2 V f -> kAut U1 V f. Proof. by move=> sU12 /andP[/(kHomSl sU12)homU1f EfE]; apply/andP. Qed. Lemma kHom_kAut_sub K E f : kAut K E f -> kHom K E f. Proof. by case/andP. Qed. Lemma kAut_eq K E (f g : 'End(L)) : (K <= E)%VS -> {in E, f =1 g} -> kAut K E f = kAut K E g. Proof. by move=> sKE eq_fg; rewrite !kAutE (kHom_eq sKE eq_fg) (eq_in_limg eq_fg). Qed. Lemma kAutfE K f : kAut K {:L} f = kHom K {:L} f. Proof. by rewrite kAutE subvf andbT. Qed. Lemma kAut1E E (f : 'AEnd(L)) : kAut 1 E f = (f @: E <= E)%VS. Proof. by rewrite kAutE k1AHom. Qed. Lemma kAutf_lker0 K f : kHom K {:L} f -> lker f == 0%VS. Proof. move/(kHomSl (sub1v _))/kHom_monoid_morphism => fM. pose fmM := GRing.isMonoidMorphism.Build _ _ _ fM. pose fRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun f) fmM. by apply/lker0P; apply: (fmorph_inj fRM). Qed. Lemma inv_kHomf K f : kHom K {:L} f -> kHom K {:L} f^-1. Proof. move=> homKf; have [[idKf fM] kerf0] := (kHomP_tmp homKf, kAutf_lker0 homKf). have f1K: cancel f^-1%VF f by apply: lker0_lfunVK. apply/kHomP_tmp; split=> [x Kx | x y _ _]; apply: (lker0P kerf0). by rewrite f1K idKf. by rewrite fM ?memvf ?{1}f1K. Qed. Lemma inv_is_ahom (f : 'AEnd(L)) : ahom_in {:L} f^-1. Proof. have /ahomP_tmp/kHom_monoid_morphism hom1f := valP f. exact/ahomP_tmp/kHom_monoid_morphism/inv_kHomf. Qed. Canonical inv_ahom (f : 'AEnd(L)) : 'AEnd(L) := AHom (inv_is_ahom f). Notation "f ^-1" := (inv_ahom f) : lrfun_scope. Lemma comp_kHom_img K E f g : kHom K (g @: E) f -> kHom K E g -> kHom K E (f \o g). Proof. move=> /kHomP_tmp[idKf fM] /kHomP_tmp[idKg gM]; apply/kHomP_tmp; split=> [x Kx | x y Ex Ey]. by rewrite lfunE /= idKg ?idKf. by rewrite !lfunE /= gM // fM ?memv_img. Qed. Lemma comp_kHom K E f g : kHom K {:L} f -> kHom K E g -> kHom K E (f \o g). Proof. by move/(kHomSr (subvf (g @: E))); apply: comp_kHom_img. Qed. Lemma kHom_extends K E f p U : (K <= E)%VS -> kHom K E f -> p \is a polyOver K -> splittingFieldFor E p U -> {g | kHom K U g & {in E, f =1 g}}. Proof. move=> sKE homEf Kp /sig2_eqW[rs Dp <-{U}]. set r := rs; have rs_r: all [in rs] r by apply/allP. elim: r rs_r => [_|z r IHr /=/andP[rs_z rs_r]] /= in E f sKE homEf *. by exists f; rewrite ?Fadjoin_nil. set Ez := <<E; z>>%AS; pose fpEz := map_poly f (minPoly E z). suffices{IHr} /sigW[y fpEz_y]: exists y, root fpEz y. have homEz_fz: kHom K Ez (kHomExtend E f z y) by apply: kHomExtendP. have sKEz: (K <= Ez)%VS := subv_trans sKE (subv_adjoin E z). have [g homGg Dg] := IHr rs_r _ _ sKEz homEz_fz. exists g => [|x Ex]; first by rewrite adjoin_cons. by rewrite -Dg ?subvP_adjoin // kHomExtend_id. have [m DfpEz]: {m | fpEz %= \prod_(w <- mask m rs) ('X - w%:P)}. apply: dvdp_prod_XsubC; rewrite -(eqp_dvdr _ Dp) -(kHom_poly_id homEf Kp). have /polyOver_subvs[q Dq] := polyOverSv sKE Kp. have /polyOver_subvs[qz Dqz] := minPolyOver E z. rewrite /fpEz Dq Dqz -2?{1}map_poly_comp (dvdp_map (kHom_rmorphism homEf)). rewrite -(dvdp_map (@vsval _ _ E)) -Dqz -Dq. by rewrite minPoly_dvdp ?(polyOverSv sKE) // (eqp_root Dp) root_prod_XsubC. exists (mask m rs)`_0; rewrite (eqp_root DfpEz) root_prod_XsubC mem_nth //. rewrite -ltnS -(size_prod_XsubC _ id) -(eqp_size DfpEz). rewrite size_poly_eq -?lead_coefE ?size_minPoly // (monicP (monic_minPoly E z)). by have [idKf _] := kHomP_tmp homEf; rewrite idKf ?mem1v ?oner_eq0. Qed. End kHom. Notation "f ^-1" := (inv_ahom f) : lrfun_scope. #[warning="-deprecated-since-mathcomp-2.5.0"] Arguments kHomP {F L K V f}. Arguments kHomP_tmp {F L K V f}. Arguments kAHomP {F L U V f}. #[warning="-deprecated-since-mathcomp-2.5.0"] Arguments kHom_lrmorphism {F L f}. Arguments kHom_monoid_morphism {F L f}. Definition splitting_field_axiom (F : fieldType) (L : fieldExtType F) := exists2 p : {poly L}, p \is a polyOver 1%VS & splittingFieldFor 1 p {:L}. HB.mixin Record FieldExt_isSplittingField (F : fieldType) L of FieldExt F L := { splittingFieldP_subproof : splitting_field_axiom L }. #[mathcomp(axiom="splitting_field_axiom"), short(type="splittingFieldType")] HB.structure Definition SplittingField F := { T of FieldExt_isSplittingField F T & FieldExt F T }. Module SplittingFieldExports. Bind Scope ring_scope with SplittingField.sort. End SplittingFieldExports. HB.export SplittingFieldExports. Lemma normal_field_splitting (F : fieldType) (L : fieldExtType F) : (forall (K : {subfield L}) x, exists r, minPoly K x == \prod_(y <- r) ('X - y%:P)) -> SplittingField.axiom L. Proof. move=> normalL; pose r i := sval (sigW (normalL 1%AS (tnth (vbasis {:L}) i))). have sz_r i: size (r i) <= \dim {:L}. rewrite -ltnS -(size_prod_XsubC _ id) /r; case: sigW => _ /= /eqP <-. rewrite size_minPoly ltnS; move: (tnth _ _) => x. by rewrite adjoin_degreeE dimv1 divn1 dimvS // subvf. pose mkf (z : L) := 'X - z%:P. exists (\prod_i \prod_(j < \dim {:L} | j < size (r i)) mkf (r i)`_j). apply: rpred_prod => i _; rewrite big_ord_narrow /= /r; case: sigW => rs /=. by rewrite (big_nth 0) big_mkord => /eqP <- {rs}; apply: minPolyOver. rewrite pair_big_dep /= -big_filter -(big_map _ xpredT mkf). set rF := map _ _; exists rF; first exact: eqpxx. apply/eqP; rewrite eqEsubv subvf -(span_basis (vbasisP {:L})). apply/span_subvP=> _ /tnthP[i ->]; set x := tnth _ i. have /tnthP[j ->]: x \in in_tuple (r i). by rewrite -root_prod_XsubC /r; case: sigW => _ /=/eqP<-; apply: root_minPoly. apply/seqv_sub_adjoin/mapP; rewrite (tnth_nth 0). exists (i, widen_ord (sz_r i) j) => //. by rewrite mem_filter /= ltn_ord mem_index_enum. Qed. HB.factory Record FieldExt_isNormalSplittingField (F : fieldType) L of FieldExt F L := { normal_field_splitting_axiom : forall (K : {subfield L}) x, exists r, minPoly K x == \prod_(y <- r) ('X - y%:P) }. HB.builders Context F L of FieldExt_isNormalSplittingField F L. HB.instance Definition _ := FieldExt_isSplittingField.Build F L (normal_field_splitting normal_field_splitting_axiom). HB.end. Fact regular_splittingAxiom (F : fieldType) : SplittingField.axiom F^o. Proof. exists 1; first exact: rpred1. by exists [::]; [rewrite big_nil eqpxx | rewrite Fadjoin_nil regular_fullv]. Qed. HB.instance Definition _ (F : fieldType) := FieldExt_isSplittingField.Build F F^o (regular_splittingAxiom F). Section SplittingFieldTheory. Variables (F : fieldType) (L : splittingFieldType F). Implicit Types (U V W : {vspace L}). Implicit Types (K M E : {subfield L}). Lemma splittingFieldP : SplittingField.axiom L. Proof. exact: splittingFieldP_subproof. Qed. Lemma splittingPoly : {p : {poly L} | p \is a polyOver 1%VS & splittingFieldFor 1 p {:L}}. Proof. pose factF p s := (p \is a polyOver 1%VS) && (p %= \prod_(z <- s) ('X - z%:P)). suffices [[p rs] /andP[]]: {ps | factF F L ps.1 ps.2 & <<1 & ps.2>> = {:L}}%VS. by exists p; last exists rs. apply: sig2_eqW; have [p F0p [rs splitLp genLrs]] := splittingFieldP. by exists (p, rs); rewrite // /factF F0p splitLp. Qed. Fact fieldOver_splitting E : SplittingField.axiom (fieldOver E). Proof. have [p Fp [r Dp defL]] := splittingFieldP; exists p. apply/polyOverP=> j; rewrite trivial_fieldOver. by rewrite (subvP (sub1v E)) ?(polyOverP Fp). exists r => //; apply/vspaceP=> x; rewrite memvf. have [L0 [_ _ defL0]] := @aspaceOverP _ _ E <<1 & r : seq (fieldOver E)>>. rewrite defL0; have: x \in <<1 & r>>%VS by rewrite defL (@memvf _ L). apply: subvP; apply/Fadjoin_seqP; rewrite -memvE -defL0 mem1v. by split=> // y r_y; rewrite -defL0 seqv_sub_adjoin. Qed. HB.instance Definition _ E := FieldExt_isSplittingField.Build (subvs_of E) (fieldOver E) (fieldOver_splitting E). Lemma enum_AEnd : {kAutL : seq 'AEnd(L) | forall f, f \in kAutL}. Proof. pose isAutL (s : seq 'AEnd(L)) (f : 'AEnd(L)) := kHom 1 {:L} f = (f \in s). suffices [kAutL in_kAutL] : {kAutL : seq 'AEnd(L) | forall f, isAutL kAutL f}. by exists kAutL => f; rewrite -in_kAutL k1AHom. have [p Kp /sig2_eqW[rs Dp defL]] := splittingPoly. do [rewrite {}/isAutL -(erefl (asval 1)); set r := rs; set E := 1%AS] in defL *. have [sKE rs_r]: (1 <= E)%VS /\ all [in rs] r by split; last apply/allP. elim: r rs_r => [_|z r IHr /=/andP[rs_z rs_r]] /= in (E) sKE defL *. rewrite Fadjoin_nil in defL; exists [tuple \1%AF] => f; rewrite defL inE. apply/idP/eqP=> [/kAHomP f1 | ->]; last exact: kHom1. by apply/val_inj/lfunP=> x; rewrite id_lfunE f1 ?memvf. do [set Ez := <<E; z>>%VS; rewrite adjoin_cons] in defL. have sEEz: (E <= Ez)%VS := subv_adjoin E z; have sKEz := subv_trans sKE sEEz. have{IHr} [homEz DhomEz] := IHr rs_r _ sKEz defL. have Ep: p \in polyOver E := polyOverSv sKE Kp. have{rs_z} pz0: root p z by rewrite (eqp_root Dp) root_prod_XsubC. pose pEz := minPoly E z; pose n := \dim_E Ez. have{pz0} [rz DpEz]: {rz : n.-tuple L | pEz %= \prod_(w <- rz) ('X - w%:P)}. have /dvdp_prod_XsubC[m DpEz]: pEz %| \prod_(w <- rs) ('X - w%:P). by rewrite -(eqp_dvdr _ Dp) minPoly_dvdp ?(polyOverSv sKE). suffices sz_rz: size (mask m rs) == n by exists (Tuple sz_rz). rewrite -[n]adjoin_degreeE -eqSS -size_minPoly. by rewrite (eqp_size DpEz) size_prod_XsubC. have fEz i (y := tnth rz i): {f : 'AEnd(L) | kHom E {:L} f & f z = y}. have homEfz: kHom E Ez (kHomExtend E \1 z y). rewrite kHomExtendP ?kHom1 // lfun1_poly. by rewrite (eqp_root DpEz) -/rz root_prod_XsubC mem_tnth. have splitFp: splittingFieldFor Ez p {:L}. exists rs => //; apply/eqP; rewrite eqEsubv subvf -defL adjoin_seqSr //. exact/allP. have [f homLf Df] := kHom_extends sEEz homEfz Ep splitFp. have [ahomf _] := andP homLf; exists (AHom ahomf) => //. rewrite -Df ?memv_adjoin ?(kHomExtend_val (kHom1 E E)) // lfun1_poly. by rewrite (eqp_root DpEz) root_prod_XsubC mem_tnth. exists [seq (s2val (fEz i) \o f)%AF| i <- enum 'I_n, f <- homEz] => f. apply/idP/allpairsP => [homLf | [[i g] [_ Hg ->]] /=]; last first. by case: (fEz i) => fi /= /comp_kHom->; rewrite ?(kHomSl sEEz) ?DhomEz. have /tnthP[i Dfz]: f z \in rz. rewrite memtE /= -root_prod_XsubC -(eqp_root DpEz). by rewrite (kHom_root_id _ homLf) ?memvf ?subvf ?minPolyOver ?root_minPoly. case Dfi: (fEz i) => [fi homLfi fi_z]; have kerfi0 := kAutf_lker0 homLfi. set fj := (fi ^-1 \o f)%AF; suffices Hfj : fj \in homEz. exists (i, fj) => //=; rewrite mem_enum inE Hfj; split => //. by apply/val_inj; rewrite {}Dfi /= (lker0_compVKf kerfi0). rewrite -DhomEz; apply/kAHomP => _ /Fadjoin_polyP[q Eq ->]. have homLfj: kHom E {:L} fj := comp_kHom (inv_kHomf homLfi) homLf. have /kHom_monoid_morphism fjM := kHomSl (sub1v _) homLfj. pose fjmM := GRing.isMonoidMorphism.Build _ _ _ fjM. pose fjRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun fj) fjmM. rewrite -[fj _](horner_map fjRM) (kHom_poly_id homLfj) //=. by rewrite (@lfunE _ _ L) /= Dfz -fi_z lker0_lfunK. Qed. Lemma splitting_field_normal K x : exists r, minPoly K x == \prod_(y <- r) ('X - y%:P). Proof. pose q1 := minPoly 1 x; pose fx_root q (f : 'AEnd(L)) := root q (f x). have [[p F0p splitLp] [autL DautL]] := (splittingFieldP, enum_AEnd). suffices{K} autL_px q: q != 0 -> q %| q1 -> size q > 1 -> has (fx_root q) autL. set q := minPoly K x; have: q \is monic := monic_minPoly K x. have: q %| q1 by rewrite minPolyS // sub1v. have [d] := ubnP (size q); elim: d q => // d IHd q leqd q_dv_q1 mon_q. have nz_q: q != 0 := monic_neq0 mon_q. have [|q_gt1|q_1] := ltngtP (size q) 1; last first; last by rewrite polySpred. by exists nil; rewrite big_nil -eqp_monic ?monic1 // -size_poly_eq1 q_1. have /hasP[f autLf /factor_theorem[q2 Dq]] := autL_px q nz_q q_dv_q1 q_gt1. have mon_q2: q2 \is monic by rewrite -(monicMr _ (monicXsubC (f x))) -Dq. rewrite Dq size_monicM -?size_poly_eq0 ?size_XsubC ?addn2 //= ltnS in leqd. have q2_dv_q1: q2 %| q1 by rewrite (dvdp_trans _ q_dv_q1) // Dq dvdp_mulr. rewrite Dq; have [r /eqP->] := IHd q2 leqd q2_dv_q1 mon_q2. by exists (f x :: r); rewrite big_cons mulrC. have [d] := ubnP (size q); elim: d q => // d IHd q leqd nz_q q_dv_q1 q_gt1. without loss{d leqd IHd nz_q q_gt1} irr_q: q q_dv_q1 / irreducible_poly q. move=> IHq; apply: wlog_neg => not_autLx_q; apply: IHq => //. split=> // q2 q2_neq1 q2_dv_q; rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //=. rewrite leqNgt; apply: contra not_autLx_q => ltq2q. have nz_q2: q2 != 0 by apply: contraTneq q2_dv_q => ->; rewrite dvd0p. have{q2_neq1} q2_gt1: size q2 > 1 by rewrite neq_ltn polySpred in q2_neq1 *. have{leqd ltq2q} ltq2d: size q2 < d by apply: leq_trans ltq2q _. apply: sub_has (IHd _ ltq2d nz_q2 (dvdp_trans q2_dv_q q_dv_q1) q2_gt1) => f. by rewrite /fx_root !root_factor_theorem => /dvdp_trans->. have{irr_q} [Lz [inLz [z qz0]]]: {Lz : fieldExtType F & {inLz : 'AHom(L, Lz) & {z : Lz | root (map_poly inLz q) z}}}. - have [Lz0 _ [z qz0 defLz]] := irredp_FAdjoin irr_q. pose Lz : fieldExtType _ := baseFieldType Lz0. pose inLz : {rmorphism L -> Lz} := in_alg Lz0. have inLzL_linear: linear (locked inLz). by move=> a u v; rewrite -[in LHS]mulr_algl rmorphD rmorphM -lock mulr_algl. pose inLzLlM := GRing.isLinear.Build _ _ _ _ _ inLzL_linear. pose inLzLL : {linear _ -> _} := HB.pack (locked inLz : _ -> _) inLzLlM. have ihLzZ: ahom_in {:L} (linfun inLzLL). by apply/ahom_inP; split=> [u v|]; rewrite !lfunE (rmorphM, rmorph1). exists Lz, (AHom ihLzZ), z; congr (root _ z): qz0. by apply: eq_map_poly => y; rewrite lfunE /= -lock. pose imL := [aspace of limg inLz]; pose pz := map_poly inLz p. have in_imL u: inLz u \in imL by rewrite memv_img ?memvf. have F0pz: pz \is a polyOver 1%VS. apply/polyOverP=> i; rewrite -(aimg1 inLz) coef_map /= memv_img //. exact: (polyOverP F0p). have{splitLp} splitLpz: splittingFieldFor 1 pz imL. have [r def_p defL] := splitLp; exists (map inLz r) => [|{def_p}]. move: def_p; rewrite -(eqp_map inLz) rmorph_prod. rewrite big_map; congr (_ %= _); apply: eq_big => //= y _. by rewrite rmorphB /= map_polyX map_polyC. apply/eqP; rewrite eqEsubv /= -{2}defL {defL}; apply/andP; split. by apply/Fadjoin_seqP; rewrite sub1v; split=> // _ /mapP[y r_y ->]. elim/last_ind: r => [|r y IHr] /=; first by rewrite !Fadjoin_nil aimg1. rewrite map_rcons !adjoin_rcons /=. apply/subvP=> _ /memv_imgP[_ /Fadjoin_polyP[p1 r_p1 ->] ->]. rewrite -horner_map /= mempx_Fadjoin //=; apply/polyOverP=> i. by rewrite coef_map (subvP IHr) //= memv_img ?(polyOverP r_p1). have [f homLf fxz]: exists2 f : 'End(Lz), kHom 1 imL f & f (inLz x) = z. pose q1z := minPoly 1 (inLz x). have Dq1z: map_poly inLz q1 %| q1z. have F0q1z i: exists a, q1z`_i = a%:A by apply/vlineP/polyOverP/minPolyOver. have [q2 Dq2]: exists q2, q1z = map_poly inLz q2. exists (\poly_(i < size q1z) (sval (sig_eqW (F0q1z i)))%:A). rewrite -{1}[q1z]coefK; apply/polyP=> i; rewrite coef_map !{1}coef_poly. by case: sig_eqW => a; case: ifP; rewrite /= ?rmorph0 ?rmorph_alg. rewrite Dq2 dvdp_map minPoly_dvdp //. apply/polyOverP=> i; have[a] := F0q1z i. rewrite -(rmorph_alg inLz) Dq2 coef_map /= => /fmorph_inj->. exact/rpredZ/mem1v. by rewrite -(fmorph_root inLz) -Dq2 root_minPoly. have q1z_z: root q1z z. rewrite !root_factor_theorem in qz0 *. by apply: dvdp_trans qz0 (dvdp_trans _ Dq1z); rewrite dvdp_map. have map1q1z_z: root (map_poly \1%VF q1z) z. by rewrite map_poly_id => // ? _; rewrite lfunE. pose f0 := kHomExtend 1 \1 (inLz x) z. have{map1q1z_z} hom_f0 : kHom 1 <<1; inLz x>> f0. by apply: kHomExtendP map1q1z_z => //; apply: kHom1. have{} splitLpz: splittingFieldFor <<1; inLz x>> pz imL. have [r def_pz defLz] := splitLpz; exists r => //. apply/eqP; rewrite eqEsubv -{2}defLz adjoin_seqSl ?sub1v // andbT. apply/Fadjoin_seqP; split; last first. by rewrite /= -[limg _]defLz; apply: seqv_sub_adjoin. by apply/FadjoinP/andP; rewrite sub1v memv_img ?memvf. have [f homLzf Df] := kHom_extends (sub1v _) hom_f0 F0pz splitLpz. have [-> | x'z] := eqVneq (inLz x) z. by exists \1%VF; rewrite ?lfunE ?kHom1. exists f => //; rewrite -Df ?memv_adjoin ?(kHomExtend_val (kHom1 1 1)) //. by rewrite lfun1_poly. pose f1 := (inLz^-1 \o f \o inLz)%VF; have /kHomP_tmp[fFid fM] := homLf. have Df1 u: inLz (f1 u) = f (inLz u). rewrite !comp_lfunE limg_lfunVK //= -[limg _]/(asval imL). have [r def_pz defLz] := splitLpz; set r1 := r. have: inLz u \in <<1 & r1>>%VS by rewrite defLz. have: all [in r] r1 by apply/allP. elim/last_ind: r1 {u}(inLz u) => [|r1 y IHr1] u. by rewrite Fadjoin_nil => _ Fu; rewrite fFid // (subvP (sub1v _)). rewrite all_rcons adjoin_rcons => /andP[rr1 ry] /Fadjoin_polyP[pu r1pu ->]. rewrite (kHom_horner homLf) -defLz; last exact: seqv_sub_adjoin; last first. by apply: polyOverS r1pu; apply/subvP/adjoin_seqSr/allP. apply: rpred_horner. by apply/polyOverP=> i; rewrite coef_map /= defLz IHr1 ?(polyOverP r1pu). rewrite seqv_sub_adjoin // -root_prod_XsubC -(eqp_root def_pz). rewrite (kHom_root_id _ homLf) ?sub1v //. by rewrite -defLz seqv_sub_adjoin. by rewrite (eqp_root def_pz) root_prod_XsubC. suffices f1_is_ahom : ahom_in {:L} f1. apply/hasP; exists (AHom f1_is_ahom); first exact: DautL. by rewrite /fx_root -(fmorph_root inLz) /= Df1 fxz. apply/ahom_inP; split=> [a b _ _|]; apply: (fmorph_inj inLz). by rewrite rmorphM /= !Df1 rmorphM fM ?in_imL. by rewrite /= Df1 /= fFid ?rmorph1 ?mem1v. Qed. Lemma kHom_to_AEnd K E f : kHom K E f -> {g : 'AEnd(L) | {in E, f =1 val g}}. Proof. move=> homKf; have{homKf} [homFf sFE] := (kHomSl (sub1v K) homKf, sub1v E). have [p Fp /(splittingFieldForS sFE (subvf E))splitLp] := splittingPoly. have [g0 homLg0 eq_fg] := kHom_extends sFE homFf Fp splitLp. by apply: exist (Sub g0 _) _ => //; apply/ahomP_tmp/kHom_monoid_morphism. Qed. End SplittingFieldTheory. (* Hide the finGroup structure on 'AEnd(L) in a module so that we can control *) (* when it is exported. Most people will want to use the finGroup structure *) (* on 'Gal(E / K) and will not need this module. *) Module Import AEnd_FinGroup. Section AEnd_FinGroup. Variables (F : fieldType) (L : splittingFieldType F). Implicit Types (U V W : {vspace L}) (K M E : {subfield L}). Definition inAEnd f := SeqSub (svalP (enum_AEnd L) f). Fact inAEndK : cancel inAEnd val. Proof. by []. Qed. HB.instance Definition _ := Countable.copy 'AEnd(L) (can_type inAEndK). HB.instance Definition _ := isFinite.Build 'AEnd(L) (pcan_enumP (can_pcan inAEndK)). (* the group operation is the categorical composition operation *) Definition comp_AEnd (f g : 'AEnd(L)) : 'AEnd(L) := (g \o f)%AF. Fact comp_AEndA : associative comp_AEnd. Proof. by move=> f g h; apply: val_inj; symmetry; apply: comp_lfunA. Qed. Fact comp_AEnd1l : left_id \1%AF comp_AEnd. Proof. by move=> f; apply/val_inj/comp_lfun1r. Qed. Fact comp_AEndK : left_inverse \1%AF (@inv_ahom _ L) comp_AEnd. Proof. by move=> f; apply/val_inj; rewrite /= lker0_compfV ?AEnd_lker0. Qed. HB.instance Definition _:= isMulGroup.Build 'AEnd(L) comp_AEndA comp_AEnd1l comp_AEndK. Definition kAEnd U V := [set f : 'AEnd(L) | kAut U V f]. Definition kAEndf U := kAEnd U {:L}. Lemma kAEnd_group_set K E : group_set (kAEnd K E). Proof. apply/group_setP; split=> [|f g]; first by rewrite inE /kAut kHom1 lim1g eqxx. rewrite !inE !kAutE => /andP[homKf EfE] /andP[/(kHomSr EfE)homKg EgE]. by rewrite (comp_kHom_img homKg homKf) limg_comp (subv_trans _ EgE) ?limgS. Qed. Canonical kAEnd_group K E := group (kAEnd_group_set K E). Canonical kAEndf_group K := [group of kAEndf K]. Lemma kAEnd_norm K E : kAEnd K E \subset 'N(kAEndf E)%g. Proof. apply/subsetP=> x; rewrite -groupV 2!in_set => /andP[_ /eqP ExE]. apply/subsetP=> _ /imsetP[y homEy ->]; rewrite !in_set !kAutfE in homEy *. apply/kAHomP=> u Eu; have idEy := kAHomP homEy; rewrite -ExE in idEy. rewrite !(@lfunE _ _ L) /= (@lfunE _ _ L) /= idEy ?memv_img //. by rewrite lker0_lfunVK ?AEnd_lker0. Qed. Lemma mem_kAut_coset K E (g : 'AEnd(L)) : kAut K E g -> g \in coset (kAEndf E) g. Proof. move=> autEg; rewrite val_coset ?rcoset_refl //. by rewrite (subsetP (kAEnd_norm K E)) // inE. Qed. Lemma aut_mem_eqP E (x y : coset_of (kAEndf E)) f g : f \in x -> g \in y -> reflect {in E, f =1 g} (x == y). Proof. move=> x_f y_g; rewrite -(coset_mem x_f) -(coset_mem y_g). have [Nf Ng] := (subsetP (coset_norm x) f x_f, subsetP (coset_norm y) g y_g). rewrite (sameP eqP (rcoset_kercosetP Nf Ng)) mem_rcoset inE kAutfE. apply: (iffP kAHomP) => idEfg u Eu. by rewrite -(mulgKV g f) lfunE /= idEfg. by rewrite (@lfunE _ _ L) /= idEfg // lker0_lfunK ?AEnd_lker0. Qed. End AEnd_FinGroup. End AEnd_FinGroup. Section GaloisTheory. Variables (F : fieldType) (L : splittingFieldType F). Implicit Types (U V W : {vspace L}). Implicit Types (K M E : {subfield L}). (* We take Galois automorphisms for a subfield E to be automorphisms of the *) (* full field {:L} that operate in E taken modulo those that fix E pointwise. *) (* The type of Galois automorphisms of E is then the subtype of elements of *) (* the quotient kAEnd 1 E / kAEndf E, which we encapsulate in a specific *) (* wrapper to ensure stability of the gal_repr coercion insertion. *) Section gal_of_Definition. Variable V : {vspace L}. (* The <<_>>, which becomes redundant when V is a {subfield L}, ensures that *) (* the argument of [subg _] is syntactically a group. *) Inductive gal_of := Gal of [subg kAEnd_group 1 <<V>> / kAEndf (agenv V)]. Definition gal (f : 'AEnd(L)) := Gal (subg _ (coset _ f)). Definition gal_sgval x := let: Gal u := x in u. Fact gal_sgvalK : cancel gal_sgval Gal. Proof. by case. Qed. Let gal_sgval_inj := can_inj gal_sgvalK. HB.instance Definition _ := Countable.copy gal_of (can_type gal_sgvalK). HB.instance Definition _ := isFinite.Build gal_of (pcan_enumP (can_pcan gal_sgvalK)). Definition gal_one := Gal 1%g. Definition gal_inv x := Gal (gal_sgval x)^-1. Definition gal_mul x y := Gal (gal_sgval x * gal_sgval y). Fact gal_oneP : left_id gal_one gal_mul. Proof. by move=> x; apply/gal_sgval_inj/mul1g. Qed. Fact gal_invP : left_inverse gal_one gal_inv gal_mul. Proof. by move=> x; apply/gal_sgval_inj/mulVg. Qed. Fact gal_mulP : associative gal_mul. Proof. by move=> x y z; apply/gal_sgval_inj/mulgA. Qed. HB.instance Definition _ := isMulGroup.Build gal_of gal_mulP gal_oneP gal_invP. Coercion gal_repr u : 'AEnd(L) := repr (sgval (gal_sgval u)). Fact gal_is_morphism : {in kAEnd 1 (agenv V) &, {morph gal : x y / x * y}%g}. Proof. move=> f g /= autEa autEb; congr (Gal _). by rewrite !morphM ?mem_morphim // (subsetP (kAEnd_norm 1 _)). Qed. Canonical gal_morphism := Morphism gal_is_morphism. Lemma gal_reprK : cancel gal_repr gal. Proof. by case=> x; rewrite /gal coset_reprK sgvalK. Qed. Lemma gal_repr_inj : injective gal_repr. Proof. exact: can_inj gal_reprK. Qed. Lemma gal_AEnd x : gal_repr x \in kAEnd 1 (agenv V). Proof. rewrite /gal_repr; case/gal_sgval: x => _ /=/morphimP[g Ng autEg ->]. rewrite val_coset //=; case: repr_rcosetP => f; rewrite groupMr // !inE kAut1E. by rewrite kAutE -andbA => /and3P[_ /fixedSpace_limg-> _]. Qed. End gal_of_Definition. Prenex Implicits gal_repr. Lemma gal_eqP E {x y : gal_of E} : reflect {in E, x =1 y} (x == y). Proof. by rewrite -{1}(subfield_closed E); apply: aut_mem_eqP; apply: mem_repr_coset. Qed. Lemma galK E (f : 'AEnd(L)) : (f @: E <= E)%VS -> {in E, gal E f =1 f}. Proof. rewrite -kAut1E -{1 2}(subfield_closed E) => autEf. apply: (aut_mem_eqP (mem_repr_coset _) _ (eqxx _)). by rewrite subgK /= ?(mem_kAut_coset autEf) // ?mem_quotient ?inE. Qed. Lemma eq_galP E (f g : 'AEnd(L)) : (f @: E <= E)%VS -> (g @: E <= E)%VS -> reflect {in E, f =1 g} (gal E f == gal E g). Proof. move=> EfE EgE. by apply: (iffP gal_eqP) => Dfg a Ea; have:= Dfg a Ea; rewrite !{1}galK. Qed. Lemma limg_gal E (x : gal_of E) : (x @: E)%VS = E. Proof. by have:= gal_AEnd x; rewrite inE subfield_closed => /andP[_ /eqP]. Qed. Lemma memv_gal E (x : gal_of E) a : a \in E -> x a \in E. Proof. by move/(memv_img x); rewrite limg_gal. Qed. Lemma gal_id E a : (1 : gal_of E)%g a = a. Proof. by rewrite /gal_repr repr_coset1 id_lfunE. Qed. Lemma galM E (x y : gal_of E) a : a \in E -> (x * y)%g a = y (x a). Proof. rewrite /= -comp_lfunE; apply/eq_galP; rewrite ?limg_comp ?limg_gal //. by rewrite morphM /= ?gal_reprK ?gal_AEnd. Qed. Lemma galV E (x : gal_of E) : {in E, (x^-1)%g =1 x^-1%VF}. Proof. move=> a Ea; apply: canRL (lker0_lfunK (AEnd_lker0 _)) _. by rewrite -galM // mulVg gal_id. Qed. (* Standard mathematical notation for 'Gal(E / K) puts the larger field first.*) Definition galoisG V U := gal V @* <<kAEnd (U :&: V) V>>. Local Notation "''Gal' ( V / U )" := (galoisG V U) : group_scope. Canonical galoisG_group E U := Eval hnf in [group of (galoisG E U)]. Local Notation "''Gal' ( V / U )" := (galoisG_group V U) : Group_scope. Section Automorphism. Lemma gal_cap U V : 'Gal(V / U) = 'Gal(V / U :&: V). Proof. by rewrite /galoisG -capvA capvv. Qed. Lemma gal_kAut K E x : (K <= E)%VS -> (x \in 'Gal(E / K)) = kAut K E x. Proof. move=> sKE; apply/morphimP/idP=> /= [[g EgE KautEg ->{x}] | KautEx]. rewrite genGid !inE kAut1E /= subfield_closed (capv_idPl sKE) in KautEg EgE. by apply: etrans KautEg; apply/(kAut_eq sKE); apply: galK. exists (x : 'AEnd(L)); rewrite ?gal_reprK ?gal_AEnd //. by rewrite (capv_idPl sKE) mem_gen ?inE. Qed. Lemma gal_kHom K E x : (K <= E)%VS -> (x \in 'Gal(E / K)) = kHom K E x. Proof. by move/gal_kAut->; rewrite /kAut limg_gal eqxx andbT. Qed. Lemma kAut_to_gal K E f : kAut K E f -> {x : gal_of E | x \in 'Gal(E / K) & {in E, f =1 x}}. Proof. case/andP=> homKf EfE; have [g Df] := kHom_to_AEnd homKf. have{homKf EfE} autEg: kAut (K :&: E) E g. rewrite /kAut -(kHom_eq (capvSr _ _) Df) (kHomSl (capvSl _ _) homKf) /=. by rewrite -(eq_in_limg Df). have FautEg := kAutS (sub1v _) autEg. exists (gal E g) => [|a Ea]; last by rewrite {f}Df // galK // -kAut1E. by rewrite mem_morphim /= ?subfield_closed ?genGid ?inE. Qed. Lemma fixed_gal K E x a : (K <= E)%VS -> x \in 'Gal(E / K) -> a \in K -> x a = a. Proof. by move/gal_kHom=> -> /kAHomP idKx /idKx. Qed. Lemma fixedPoly_gal K E x p : (K <= E)%VS -> x \in 'Gal(E / K) -> p \is a polyOver K -> map_poly x p = p. Proof. move=> sKE galEKx /polyOverP Kp; apply/polyP => i. by rewrite coef_map /= (fixed_gal sKE). Qed. Lemma root_minPoly_gal K E x a : (K <= E)%VS -> x \in 'Gal(E / K) -> a \in E -> root (minPoly K a) (x a). Proof. move=> sKE galEKx Ea; have homKx: kHom K E x by rewrite -gal_kHom. have K_Pa := minPolyOver K a; rewrite -[minPoly K a](fixedPoly_gal _ galEKx) //. by rewrite (kHom_root homKx) ?root_minPoly // (polyOverS (subvP sKE)). Qed. End Automorphism. Lemma gal_adjoin_eq K a x y : x \in 'Gal(<<K; a>> / K) -> y \in 'Gal(<<K; a>> / K) -> (x == y) = (x a == y a). Proof. move=> galKa_x galKa_y; apply/idP/eqP=> [/eqP-> // | eq_xy_a]. apply/gal_eqP => _ /Fadjoin_polyP[p Kp ->]. by rewrite -!horner_map !(fixedPoly_gal (subv_adjoin K a)) //= eq_xy_a. Qed. Lemma galS K M E : (K <= M)%VS -> 'Gal(E / M) \subset 'Gal(E / K). Proof. rewrite gal_cap (gal_cap K E) => sKM; apply/subsetP=> x. by rewrite !gal_kAut ?capvSr //; apply: kAutS; apply: capvS. Qed. Lemma gal_conjg K E x : 'Gal(E / K) :^ x = 'Gal(E / x @: K). Proof. without loss sKE: K / (K <= E)%VS. move=> IH_K; rewrite gal_cap {}IH_K ?capvSr //. transitivity 'Gal(E / x @: K :&: x @: E); last by rewrite limg_gal -gal_cap. congr 'Gal(E / _); apply/eqP; rewrite eqEsubv limg_cap; apply/subvP=> a. rewrite memv_cap => /andP[/memv_imgP[b Kb ->] /memv_imgP[c Ec] eq_bc]. by rewrite memv_img // memv_cap Kb (lker0P (AEnd_lker0 _) _ _ eq_bc). wlog suffices IHx: x K sKE / 'Gal(E / K) :^ x \subset 'Gal(E / x @: K). apply/eqP; rewrite eqEsubset IHx // -sub_conjgV (subset_trans (IHx _ _ _)) //. by apply/subvP=> _ /memv_imgP[a Ka ->]; rewrite memv_gal ?(subvP sKE). rewrite -limg_comp (etrans (eq_in_limg _) (lim1g _)) // => a /(subvP sKE)Ka. by rewrite !(@lfunE _ _ L) /= -galM // mulgV gal_id. apply/subsetP=> _ /imsetP[y galEy ->]; rewrite gal_cap gal_kHom ?capvSr //=. apply/kAHomP=> _ /memv_capP[/memv_imgP[a Ka ->] _]; have Ea := subvP sKE a Ka. by rewrite -galM // -conjgC galM // (fixed_gal sKE galEy). Qed. Definition fixedField V (A : {set gal_of V}) := (V :&: \bigcap_(x in A) fixedSpace x)%VS. Lemma fixedFieldP E {A : {set gal_of E}} a : a \in E -> reflect (forall x, x \in A -> x a = a) (a \in fixedField A). Proof. by rewrite memv_cap => ->; apply: (iffP subv_bigcapP) => cAa x /cAa/fixedSpaceP. Qed. Lemma mem_fixedFieldP E (A : {set gal_of E}) a : a \in fixedField A -> a \in E /\ (forall x, x \in A -> x a = a). Proof. by move=> fixAa; have [Ea _] := memv_capP fixAa; have:= fixedFieldP Ea fixAa. Qed. Fact fixedField_is_aspace E (A : {set gal_of E}) : is_aspace (fixedField A). Proof. rewrite /fixedField; elim/big_rec: _ {1}E => [|x K _ IH_K] M. exact: (valP (M :&: _)%AS). by rewrite capvA IH_K. Qed. Canonical fixedField_aspace E A : {subfield L} := ASpace (@fixedField_is_aspace E A). Lemma fixedField_bound E (A : {set gal_of E}) : (fixedField A <= E)%VS. Proof. exact: capvSl. Qed. Lemma fixedFieldS E (A B : {set gal_of E}) : A \subset B -> (fixedField B <= fixedField A)%VS. Proof. move/subsetP=> sAB; apply/subvP => a /mem_fixedFieldP[Ea cBa]. by apply/fixedFieldP; last apply: sub_in1 cBa. Qed. Lemma galois_connection_subv K E : (K <= E)%VS -> (K <= fixedField ('Gal(E / K)))%VS. Proof. move=> sKE; apply/subvP => a Ka; have Ea := subvP sKE a Ka. by apply/fixedFieldP=> // x galEx; apply: (fixed_gal sKE). Qed. Lemma galois_connection_subset E (A : {set gal_of E}): A \subset 'Gal(E / fixedField A). Proof. apply/subsetP => x Ax; rewrite gal_kAut ?capvSl // kAutE limg_gal subvv andbT. by apply/kAHomP=> a /mem_fixedFieldP[_ ->]. Qed. Lemma galois_connection K E (A : {set gal_of E}): (K <= E)%VS -> (A \subset 'Gal(E / K)) = (K <= fixedField A)%VS. Proof. move=> sKE; apply/idP/idP => [/fixedFieldS | /(galS E)]. exact/subv_trans/galois_connection_subv. exact/subset_trans/galois_connection_subset. Qed. Definition galTrace U V a := \sum_(x in 'Gal(V / U)) (x a). Definition galNorm U V a := \prod_(x in 'Gal(V / U)) (x a). Section TraceAndNormMorphism. Variables U V : {vspace L}. Fact galTrace_is_zmod_morphism : zmod_morphism (galTrace U V). Proof. by move=> a b /=; rewrite -sumrB; apply: eq_bigr => x _; rewrite rmorphB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `galTrace_is_zmod_morphism` instead")] Definition galTrace_is_additive := galTrace_is_zmod_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build L L (galTrace U V) galTrace_is_zmod_morphism. Lemma galNorm1 : galNorm U V 1 = 1. Proof. by apply: big1 => x _; rewrite rmorph1. Qed. Lemma galNormM : {morph galNorm U V : a b / a * b}. Proof. by move=> a b /=; rewrite -big_split; apply: eq_bigr => x _; rewrite rmorphM. Qed. Lemma galNormV : {morph galNorm U V : a / a^-1}. Proof. by move=> a /=; rewrite -prodfV; apply: eq_bigr => x _; rewrite fmorphV. Qed. Lemma galNormX n : {morph galNorm U V : a / a ^+ n}. Proof. move=> a; elim: n => [|n IHn]; first exact: galNorm1. by rewrite !exprS galNormM IHn. Qed. Lemma galNorm_prod (I : Type) (r : seq I) (P : pred I) (B : I -> L) : galNorm U V (\prod_(i <- r | P i) B i) = \prod_(i <- r | P i) galNorm U V (B i). Proof. exact: (big_morph _ galNormM galNorm1). Qed. Lemma galNorm0 : galNorm U V 0 = 0. Proof. by rewrite /galNorm (bigD1 1%g) ?group1 // rmorph0 /= mul0r. Qed. Lemma galNorm_eq0 a : (galNorm U V a == 0) = (a == 0). Proof. apply/idP/eqP=> [/prodf_eq0[x _] | ->]; last by rewrite galNorm0. by rewrite fmorph_eq0 => /eqP. Qed. End TraceAndNormMorphism. Section TraceAndNormField. Variables K E : {subfield L}. Lemma galTrace_fixedField a : a \in E -> galTrace K E a \in fixedField 'Gal(E / K). Proof. move=> Ea; apply/fixedFieldP=> [|x galEx]. by apply: rpred_sum => x _; apply: memv_gal. rewrite {2}/galTrace (reindex_acts 'R _ galEx) ?astabsR //=. by rewrite rmorph_sum; apply: eq_bigr => y _; rewrite galM ?lfunE. Qed. Lemma galTrace_gal a x : a \in E -> x \in 'Gal(E / K) -> galTrace K E (x a) = galTrace K E a. Proof. move=> Ea galEx; rewrite {2}/galTrace (reindex_inj (mulgI x)). by apply: eq_big => [b | b _]; rewrite ?groupMl // galM ?lfunE. Qed. Lemma galNorm_fixedField a : a \in E -> galNorm K E a \in fixedField 'Gal(E / K). Proof. move=> Ea; apply/fixedFieldP=> [|x galEx]. by apply: rpred_prod => x _; apply: memv_gal. rewrite {2}/galNorm (reindex_acts 'R _ galEx) ?astabsR //=. by rewrite rmorph_prod; apply: eq_bigr => y _; rewrite galM ?lfunE. Qed. Lemma galNorm_gal a x : a \in E -> x \in 'Gal(E / K) -> galNorm K E (x a) = galNorm K E a. Proof. move=> Ea galEx; rewrite {2}/galNorm (reindex_inj (mulgI x)). by apply: eq_big => [b | b _]; rewrite ?groupMl // galM ?lfunE. Qed. End TraceAndNormField. Definition normalField U V := [forall x in kAEndf U, x @: V == V]%VS. Lemma normalField_kAut K M E f : (K <= M <= E)%VS -> normalField K M -> kAut K E f -> kAut K M f. Proof. case/andP=> sKM sME nKM /kAut_to_gal[x galEx /(sub_in1 (subvP sME))Df]. have sKE := subv_trans sKM sME; rewrite gal_kHom // in galEx. rewrite (kAut_eq sKM Df) /kAut (kHomSr sME) //= (forall_inP nKM) // inE. by rewrite kAutfE; apply/kAHomP; apply: (kAHomP galEx). Qed. Lemma normalFieldP K E : reflect {in E, forall a, exists2 r, all [in E] r & minPoly K a = \prod_(b <- r) ('X - b%:P)} (normalField K E). Proof. apply: (iffP eqfun_inP) => [nKE a Ea | nKE x]; last first. rewrite inE kAutfE => homKx; suffices: kAut K E x by case/andP=> _ /eqP. rewrite kAutE (kHomSr (subvf E)) //=; apply/subvP=> _ /memv_imgP[a Ea ->]. have [r /allP/=srE splitEa] := nKE a Ea. rewrite srE // -root_prod_XsubC -splitEa. by rewrite -(kHom_poly_id homKx (minPolyOver K a)) fmorph_root root_minPoly. have [r /eqP splitKa] := splitting_field_normal K a. exists r => //; apply/allP => b; rewrite -root_prod_XsubC -splitKa => pKa_b_0. pose y := kHomExtend K \1 a b; have [hom1K lf1p] := (kHom1 K K, lfun1_poly). have homKy: kHom K <<K; a>> y by apply/kHomExtendP; rewrite ?lf1p. have [[g Dy] [idKy _]] := (kHom_to_AEnd homKy, kHomP_tmp homKy). have <-: g a = b by rewrite -Dy ?memv_adjoin // (kHomExtend_val hom1K) ?lf1p. suffices /nKE <-: g \in kAEndf K by apply: memv_img. by rewrite inE kAutfE; apply/kAHomP=> c Kc; rewrite -Dy ?subvP_adjoin ?idKy. Qed. Lemma normalFieldf K : normalField K {:L}. Proof. apply/normalFieldP=> a _; have [r /eqP->] := splitting_field_normal K a. by exists r => //; apply/allP=> b; rewrite /= memvf. Qed. Lemma normalFieldS K M E : (K <= M)%VS -> normalField K E -> normalField M E. Proof. move=> sKM /normalFieldP nKE; apply/normalFieldP=> a Ea. have [r /allP Er splitKa] := nKE a Ea. have /dvdp_prod_XsubC[m splitMa]: minPoly M a %| \prod_(b <- r) ('X - b%:P). by rewrite -splitKa minPolyS. exists (mask m r); first by apply/allP=> b /mem_mask/Er. by apply/eqP; rewrite -eqp_monic ?monic_prod_XsubC ?monic_minPoly. Qed. Lemma splitting_normalField E K : (K <= E)%VS -> reflect (exists2 p, p \is a polyOver K & splittingFieldFor K p E) (normalField K E). Proof. move=> sKE; apply: (iffP idP) => [nKE| [p Kp [rs Dp defE]]]; last first. apply/forall_inP=> g /[!(inE, kAutE)] /andP[homKg _]. rewrite -dimv_leqif_eq ?limg_dim_eq ?(eqP (AEnd_lker0 g)) ?capv0 //. rewrite -defE aimg_adjoin_seq; have [_ /fixedSpace_limg->] := andP homKg. apply/adjoin_seqSr=> _ /mapP[a rs_a ->]. rewrite -!root_prod_XsubC -!(eqp_root Dp) in rs_a *. by apply: kHom_root_id homKg Kp _ rs_a; rewrite ?subvf ?memvf. pose splitK a r := minPoly K a = \prod_(b <- r) ('X - b%:P). have{nKE} rK_ a: {r | a \in E -> all [in E] r /\ splitK a r}. case Ea: (a \in E); last by exists [::]. by have /sig2_eqW[r] := normalFieldP _ _ nKE a Ea; exists r. have sXE := basis_mem (vbasisP E); set X : seq L := vbasis E in sXE. exists (\prod_(a <- X) minPoly K a). by apply: rpred_prod => a _; apply: minPolyOver. exists (flatten [seq (sval (rK_ a)) | a <- X]). move/allP: sXE; elim: X => [|a X IHX]; first by rewrite !big_nil eqpxx. rewrite big_cons /= big_cat /= => /andP[Ea sXE]. by case: (rK_ a) => /= r [] // _ <-; apply/eqp_mull/IHX. apply/eqP; rewrite eqEsubv; apply/andP; split. apply/Fadjoin_seqP; split=> // b /flatten_mapP[a /sXE Ea]. by apply/allP; case: rK_ => r /= []. rewrite -{1}(span_basis (vbasisP E)); apply/span_subvP=> a Xa. apply/seqv_sub_adjoin/flatten_mapP; exists a => //; rewrite -root_prod_XsubC. by case: rK_ => /= r [| _ <-]; rewrite ?sXE ?root_minPoly. Qed. Lemma kHom_to_gal K M E f : (K <= M <= E)%VS -> normalField K E -> kHom K M f -> {x | x \in 'Gal(E / K) & {in M, f =1 x}}. Proof. case/andP=> /subvP sKM /subvP sME nKE KhomMf. have [[g Df] [idKf _]] := (kHom_to_AEnd KhomMf, kHomP_tmp KhomMf). suffices /kAut_to_gal[x galEx Dg]: kAut K E g. by exists x => //= a Ma; rewrite Df // Dg ?sME. have homKg: kHom K {:L} g by apply/kAHomP=> a Ka; rewrite -Df ?sKM ?idKf. by rewrite /kAut (kHomSr (subvf _)) // (forall_inP nKE) // inE kAutfE. Qed. Lemma normalField_root_minPoly K E a b : (K <= E)%VS -> normalField K E -> a \in E -> root (minPoly K a) b -> exists2 x, x \in 'Gal(E / K) & x a = b. Proof. move=> sKE nKE Ea pKa_b_0; pose f := kHomExtend K \1 a b. have homKa_f: kHom K <<K; a>> f. by apply: kHomExtendP; rewrite ?kHom1 ?lfun1_poly. have sK_Ka_E: (K <= <<K; a>> <= E)%VS. by rewrite subv_adjoin; apply/FadjoinP; rewrite sKE Ea. have [x galEx Df] := kHom_to_gal sK_Ka_E nKE homKa_f; exists x => //. by rewrite -Df ?memv_adjoin // (kHomExtend_val (kHom1 K K)) ?lfun1_poly. Qed. Arguments normalFieldP {K E}. Lemma normalField_factors K E : (K <= E)%VS -> reflect {in E, forall a, exists2 r : seq (gal_of E), r \subset 'Gal(E / K) & minPoly K a = \prod_(x <- r) ('X - (x a)%:P)} (normalField K E). Proof. move=> sKE; apply: (iffP idP) => [nKE a Ea | nKE]; last first. apply/normalFieldP=> a Ea; have [r _ ->] := nKE a Ea. exists [seq x a | x : gal_of E <- r]; last by rewrite big_map. by rewrite all_map; apply/allP=> b _; apply: memv_gal. have [r Er splitKa] := normalFieldP nKE a Ea. pose f b := [pick x in 'Gal(E / K) | x a == b]. exists (pmap f r). apply/subsetP=> x; rewrite mem_pmap /f => /mapP[b _]. by case: (pickP _) => // c /andP[galEc _] [->]. rewrite splitKa; have{splitKa}: all (root (minPoly K a)) r. by apply/allP => b; rewrite splitKa root_prod_XsubC. elim: r Er => /= [|b r IHr]; first by rewrite !big_nil. case/andP=> Eb Er /andP[pKa_b_0 /(IHr Er){Er}IHr]. have [x galE /eqP xa_b] := normalField_root_minPoly sKE nKE Ea pKa_b_0. rewrite /(f b); case: (pickP _) => [y /andP[_ /eqP<-]|/(_ x)/andP[]//]. by rewrite !big_cons IHr. Qed. Definition galois U V := [&& (U <= V)%VS, separable U V & normalField U V]. Lemma galoisS K M E : (K <= M <= E)%VS -> galois K E -> galois M E. Proof. case/andP=> sKM sME /and3P[_ sepUV nUV]. by rewrite /galois sME (separableSl sKM) ?(normalFieldS sKM). Qed. Lemma galois_dim K E : galois K E -> \dim_K E = #|'Gal(E / K)|. Proof. case/and3P=> sKE /eq_adjoin_separable_generator-> // nKE. set a := separable_generator K E in nKE *. have [r /allP/=Er splitKa] := normalFieldP nKE a (memv_adjoin K a). rewrite (dim_sup_field (subv_adjoin K a)) mulnK ?adim_gt0 //. apply/eqP; rewrite -eqSS -adjoin_degreeE -size_minPoly splitKa size_prod_XsubC. set n := size r; rewrite eqSS -[n]card_ord. have x_ (i : 'I_n): {x | x \in 'Gal(<<K; a>> / K) & x a = r`_i}. apply/sig2_eqW/normalField_root_minPoly; rewrite ?subv_adjoin ?memv_adjoin //. by rewrite splitKa root_prod_XsubC mem_nth. have /card_image <-: injective (fun i => s2val (x_ i)). move=> i j /eqP; case: (x_ i) (x_ j) => y /= galEy Dya [z /= galEx Dza]. rewrite gal_adjoin_eq // Dya Dza nth_uniq // => [/(i =P j)//|]. by rewrite -separable_prod_XsubC -splitKa; apply: separable_generatorP. apply/eqP/eq_card=> x; apply/codomP/idP=> [[i ->] | galEx]; first by case: x_. have /(nthP 0) [i ltin Dxa]: x a \in r. rewrite -root_prod_XsubC -splitKa. by rewrite root_minPoly_gal ?memv_adjoin ?subv_adjoin. exists (Ordinal ltin); apply/esym/eqP. by case: x_ => y /= galEy /eqP; rewrite Dxa gal_adjoin_eq. Qed. Lemma galois_factors K E : (K <= E)%VS -> reflect {in E, forall a, exists r, let r_a := [seq x a | x : gal_of E <- r] in [/\ r \subset 'Gal(E / K), uniq r_a & minPoly K a = \prod_(b <- r_a) ('X - b%:P)]} (galois K E). Proof. move=> sKE; apply: (iffP and3P) => [[_ sepKE nKE] a Ea | galKE]. have [r galEr splitEa] := normalField_factors sKE nKE a Ea. exists r; rewrite /= -separable_prod_XsubC !big_map -splitEa. by split=> //; apply: separableP Ea. split=> //. apply/separableP => a /galKE[r [_ Ur_a splitKa]]. by rewrite /separable_element splitKa separable_prod_XsubC. apply/(normalField_factors sKE)=> a /galKE[r [galEr _ ->]]. by rewrite big_map; exists r. Qed. Lemma splitting_galoisField K E : reflect (exists p, [/\ p \is a polyOver K, separable_poly p & splittingFieldFor K p E]) (galois K E). Proof. apply: (iffP and3P) => [[sKE sepKE nKE]|[p [Kp sep_p [r Dp defE]]]]. rewrite (eq_adjoin_separable_generator sepKE) // in nKE *. set a := separable_generator K E in nKE *; exists (minPoly K a). split; first 1 [exact: minPolyOver | exact/separable_generatorP]. have [r /= /allP Er splitKa] := normalFieldP nKE a (memv_adjoin _ _). exists r; first by rewrite splitKa eqpxx. apply/eqP; rewrite eqEsubv; apply/andP; split. by apply/Fadjoin_seqP; split => //; apply: subv_adjoin. apply/FadjoinP; split; first exact: subv_adjoin_seq. by rewrite seqv_sub_adjoin // -root_prod_XsubC -splitKa root_minPoly. have sKE: (K <= E)%VS by rewrite -defE subv_adjoin_seq. split=> //; last by apply/splitting_normalField=> //; exists p; last exists r. rewrite -defE; apply/separable_Fadjoin_seq/allP=> a r_a. by apply/separable_elementP; exists p; rewrite (eqp_root Dp) root_prod_XsubC. Qed. Lemma galois_fixedField K E : reflect (fixedField 'Gal(E / K) = K) (galois K E). Proof. apply: (iffP idP) => [/and3P[sKE /separableP sepKE nKE] | fixedKE]. apply/eqP; rewrite eqEsubv galois_connection_subv ?andbT //. apply/subvP=> a /mem_fixedFieldP[Ea fixEa]; rewrite -adjoin_deg_eq1. have [r /allP Er splitKa] := normalFieldP nKE a Ea. rewrite -eqSS -size_minPoly splitKa size_prod_XsubC eqSS -[1]/(size [:: a]). have Ur: uniq r by rewrite -separable_prod_XsubC -splitKa; apply: sepKE. rewrite -uniq_size_uniq {Ur}// => b; rewrite inE -root_prod_XsubC -splitKa. apply/eqP/idP=> [-> | pKa_b_0]; first exact: root_minPoly. by have [x /fixEa-> ->] := normalField_root_minPoly sKE nKE Ea pKa_b_0. have sKE: (K <= E)%VS by rewrite -fixedKE capvSl. apply/galois_factors=> // a Ea. pose r_pKa := [seq x a | x : gal_of E in 'Gal(E / K)]. have /fin_all_exists2[x_ galEx_ Dx_a] (b : seq_sub r_pKa) := imageP (valP b). exists (codom x_); rewrite -map_comp; set r := map _ _. have r_xa x: x \in 'Gal(E / K) -> x a \in r. move=> galEx; have r_pKa_xa: x a \in r_pKa by apply/imageP; exists x. by rewrite [x a](Dx_a (SeqSub r_pKa_xa)); apply: codom_f. have Ur: uniq r by apply/injectiveP=> b c /=; rewrite -!Dx_a => /val_inj. split=> //; first by apply/subsetP=> _ /codomP[b ->]. apply/eqP; rewrite -eqp_monic ?monic_minPoly ?monic_prod_XsubC //. apply/andP; split; last first. rewrite uniq_roots_dvdp ?uniq_rootsE // all_map. by apply/allP=> b _ /=; rewrite root_minPoly_gal. apply: minPoly_dvdp; last by rewrite root_prod_XsubC -(gal_id E a) r_xa ?group1. rewrite -fixedKE; apply/polyOverP => i; apply/fixedFieldP=> [|x galEx]. rewrite (polyOverP _) // big_map rpred_prod // => b _. by rewrite polyOverXsubC memv_gal. rewrite -coef_map rmorph_prod; congr (_ : {poly _})`_i. symmetry; rewrite (perm_big (map x r)) /= ?(big_map x). by apply: eq_bigr => b _; rewrite rmorphB /= map_polyX map_polyC. have Uxr: uniq (map x r) by rewrite map_inj_uniq //; apply: fmorph_inj. have /uniq_min_size: {subset map x r <= r}. by rewrite -map_comp => _ /codomP[b ->] /=; rewrite -galM // r_xa ?groupM. by rewrite (size_map x) perm_sym; case=> // _ /uniq_perm->. Qed. Lemma mem_galTrace K E a : galois K E -> a \in E -> galTrace K E a \in K. Proof. by move/galois_fixedField => {2}<- /galTrace_fixedField. Qed. Lemma mem_galNorm K E a : galois K E -> a \in E -> galNorm K E a \in K. Proof. by move/galois_fixedField=> {2}<- /galNorm_fixedField. Qed. Lemma gal_independent_contra E (P : pred (gal_of E)) (c_ : gal_of E -> L) x : P x -> c_ x != 0 -> exists2 a, a \in E & \sum_(y | P y) c_ y * y a != 0. Proof. have [n] := ubnP #|P|; elim: n c_ x P => // n IHn c_ x P lePn Px nz_cx. rewrite ltnS (cardD1x Px) in lePn; move/IHn: lePn => {n IHn}/=IH_P. have [/eqfun_inP c_Px'_0 | ] := boolP [forall (y | P y && (y != x)), c_ y == 0]. exists 1; rewrite ?mem1v // (bigD1 x Px) /= rmorph1 mulr1. by rewrite big1 ?addr0 // => y /c_Px'_0->; rewrite mul0r. case/forall_inPn => y Px'y nz_cy. have [Py /gal_eqP/eqlfun_inP/subvPn[a Ea]] := andP Px'y. rewrite memv_ker !lfun_simp => nz_yxa; pose d_ y := c_ y * (y a - x a). have /IH_P[//|b Eb nz_sumb]: d_ y != 0 by rewrite mulf_neq0. have [sumb_0|] := eqVneq (\sum_(z | P z) c_ z * z b) 0; last by exists b. exists (a * b); first exact: rpredM. rewrite -subr_eq0 -[z in _ - z](mulr0 (x a)) -[in z in _ - z]sumb_0. rewrite mulr_sumr -sumrB (bigD1 x Px) rmorphM /= mulrCA subrr add0r. congr (_ != 0): nz_sumb; apply: eq_bigr => z _. by rewrite mulrCA rmorphM -mulrBr -mulrBl mulrA. Qed. Lemma gal_independent E (P : pred (gal_of E)) (c_ : gal_of E -> L) : (forall a, a \in E -> \sum_(x | P x) c_ x * x a = 0) -> (forall x, P x -> c_ x = 0). Proof. move=> sum_cP_0 x Px; apply/eqP/idPn=> /(gal_independent_contra Px)[a Ea]. by rewrite sum_cP_0 ?eqxx. Qed. Lemma Hilbert's_theorem_90 K E x a : generator 'Gal(E / K) x -> a \in E -> reflect (exists2 b, b \in E /\ b != 0 & a = b / x b) (galNorm K E a == 1). Proof. move/(_ =P <[x]>)=> DgalE Ea. have galEx: x \in 'Gal(E / K) by rewrite DgalE cycle_id. apply: (iffP eqP) => [normEa1 | [b [Eb nzb] ->]]; last first. by rewrite galNormM galNormV galNorm_gal // mulfV // galNorm_eq0. have [x1 | ntx] := eqVneq x 1%g. exists 1; first by rewrite mem1v oner_neq0. by rewrite -{1}normEa1 /galNorm DgalE x1 cycle1 big_set1 !gal_id divr1. pose c_ y := \prod_(i < invm (injm_Zpm x) y) (x ^+ i)%g a. have nz_c1: c_ 1%g != 0 by rewrite /c_ morph1 big_ord0 oner_neq0. have [d] := @gal_independent_contra _ [in 'Gal(E / K)] _ _ (group1 _) nz_c1. set b := \sum_(y in _) _ => Ed nz_b; exists b. split=> //; apply: rpred_sum => y galEy. by apply: rpredM; first apply: rpred_prod => i _; apply: memv_gal. apply: canRL (mulfK _) _; first by rewrite fmorph_eq0. rewrite rmorph_sum mulr_sumr [b](reindex_acts 'R _ galEx) ?astabsR //=. apply: eq_bigr => y galEy; rewrite galM // rmorphM mulrA; congr (_ * _). have /morphimP[/= i _ _ ->] /=: y \in Zpm @* Zp #[x] by rewrite im_Zpm -DgalE. have <-: Zpm (i + 1) = (Zpm i * x)%g by rewrite morphM ?mem_Zp ?order_gt1. rewrite /c_ !invmE ?mem_Zp ?order_gt1 //= addn1; set n := _.+2. transitivity (\prod_(j < i.+1) (x ^+ j)%g a). rewrite big_ord_recl gal_id rmorph_prod; congr (_ * _). by apply: eq_bigr => j _; rewrite expgSr galM ?lfunE. have [/modn_small->//||->] := ltngtP i.+1 n; first by rewrite ltnNge ltn_ord. rewrite modnn big_ord0; apply: etrans normEa1; rewrite /galNorm DgalE -im_Zpm. rewrite morphimEdom big_imset /=; last exact/injmP/injm_Zpm. by apply: eq_bigl => j /=; rewrite mem_Zp ?order_gt1. Qed. Section Matrix. Variable (E : {subfield L}) (A : {set gal_of E}). Let K := fixedField A. Lemma gal_matrix : {w : #|A|.-tuple L | {subset w <= E} /\ 0 \notin w & [/\ \matrix_(i, j < #|A|) enum_val i (tnth w j) \in unitmx, directv (\sum_i K * <[tnth w i]>) & group_set A -> (\sum_i K * <[tnth w i]>)%VS = E] }. Proof. pose nzE (w : #|A|.-tuple L) := {subset w <= E} /\ 0 \notin w. pose M w := \matrix_(i, j < #|A|) nth 1%g (enum A) i (tnth w j). have [w [Ew nzw] uM]: {w : #|A|.-tuple L | nzE w & M w \in unitmx}. rewrite {}/nzE {}/M cardE; have: uniq (enum A) := enum_uniq _. elim: (enum A) => [|x s IHs] Uxs. by exists [tuple]; rewrite // flatmx0 -(flatmx0 1%:M) unitmx1. have [s'x Us]: x \notin s /\ uniq s by apply/andP. have{IHs} [w [Ew nzw] uM] := IHs Us; set M := \matrix_(i, j) _ in uM. pose a := \row_i x (tnth w i) *m invmx M. pose c_ y := oapp (a 0) (-1) (insub (index y s)). have cx_n1 : c_ x = -1 by rewrite /c_ insubN ?index_mem. have nz_cx : c_ x != 0 by rewrite cx_n1 oppr_eq0 oner_neq0. have Px: [pred y in x :: s] x := mem_head x s. have{Px nz_cx} /sig2W[w0 Ew0 nzS] := gal_independent_contra Px nz_cx. exists [tuple of cons w0 w]. split; first by apply/allP; rewrite /= Ew0; apply/allP. rewrite inE negb_or (contraNneq _ nzS) // => <-. by rewrite big1 // => y _; rewrite rmorph0 mulr0. rewrite unitmxE -[\det _]mul1r; set M1 := \matrix_(i, j < 1 + size s) _. have <-: \det (block_mx 1 (- a) 0 1%:M) = 1 by rewrite det_ublock !det1 mulr1. rewrite -det_mulmx -[M1]submxK mulmx_block !mul0mx !mul1mx !add0r !mulNmx. have ->: drsubmx M1 = M by apply/matrixP => i j; rewrite !mxE !(tnth_nth 0). have ->: ursubmx M1 - a *m M = 0. by apply/rowP=> i; rewrite mulmxKV // !mxE !(tnth_nth 0) subrr. rewrite det_lblock unitrM andbC -(unitmxE M) uM unitfE -oppr_eq0. congr (_ != 0): nzS; rewrite [_ - _]mx11_scalar det_scalar !mxE opprB /=. rewrite -big_uniq // big_cons /= cx_n1 mulN1r addrC; congr (_ + _). rewrite (big_nth 1%g) big_mkord; apply: eq_bigr => j _. by rewrite /c_ index_uniq // valK; congr (_ * _); rewrite !mxE. exists w => [//|]; split=> [||gA]. - by congr (_ \in unitmx): uM; apply/matrixP=> i j; rewrite !mxE -enum_val_nth. - apply/directv_sum_independent=> kw_ Kw_kw sum_kw_0 j _. have /fin_all_exists2[k_ Kk_ Dk_] i := memv_cosetP (Kw_kw i isT). pose kv := \col_i k_ i. transitivity (kv j 0 * tnth w j); first by rewrite !mxE. suffices{j}/(canRL (mulKmx uM))->: M w *m kv = 0 by rewrite mulmx0 mxE mul0r. apply/colP=> i /[!mxE]; pose Ai := nth 1%g (enum A) i. transitivity (Ai (\sum_j kw_ j)); last by rewrite sum_kw_0 rmorph0. rewrite rmorph_sum; apply: eq_bigr => j _; rewrite !mxE /= -/Ai. rewrite Dk_ mulrC rmorphM /=; congr (_ * _). by have /mem_fixedFieldP[_ -> //] := Kk_ j; rewrite -mem_enum mem_nth -?cardE. pose G := group gA; have G_1 := group1 G; pose iG := enum_rank_in G_1. apply/eqP; rewrite eqEsubv; apply/andP; split. apply/subv_sumP=> i _; apply: subv_trans (asubv _). by rewrite prodvS ?capvSl // -memvE Ew ?mem_tnth. apply/subvP=> w0 Ew0; apply/memv_sumP. pose wv := \col_(i < #|A|) enum_val i w0; pose v := invmx (M w) *m wv. exists (fun i => tnth w i * v i 0) => [i _|]; last first. transitivity (wv (iG 1%g) 0); first by rewrite mxE enum_rankK_in ?gal_id. rewrite -[wv](mulKVmx uM) -/v mxE; apply: eq_bigr => i _. by congr (_ * _); rewrite !mxE -enum_val_nth enum_rankK_in ?gal_id. rewrite mulrC memv_mul ?memv_line //; apply/fixedFieldP=> [|x Gx]. rewrite mxE rpred_sum // => j _; rewrite !mxE rpredM //; last exact: memv_gal. have E_M k l: M w k l \in E by rewrite mxE memv_gal // Ew ?mem_tnth. have Edet n (N : 'M_n) (E_N : forall i j, N i j \in E): \det N \in E. by apply: rpred_sum => sigma _; rewrite rpredMsign rpred_prod. rewrite /invmx uM 2!mxE mulrC rpred_div ?Edet //. by rewrite rpredMsign Edet // => k l; rewrite 2!mxE. suffices{i} {2}<-: map_mx x v = v by rewrite [map_mx x v i 0]mxE. have uMx: map_mx x (M w) \in unitmx by rewrite map_unitmx. rewrite map_mxM map_invmx /=; apply: canLR {uMx}(mulKmx uMx) _. apply/colP=> i /[!mxE]; pose ix := iG (enum_val i * x)%g. have Dix b: b \in E -> enum_val ix b = x (enum_val i b). by move=> Eb; rewrite enum_rankK_in ?groupM ?enum_valP // galM ?lfunE. transitivity ((M w *m v) ix 0); first by rewrite mulKVmx // mxE Dix. rewrite mxE; apply: eq_bigr => j _; congr (_ * _). by rewrite !mxE -!enum_val_nth Dix // ?Ew ?mem_tnth. Qed. End Matrix. Lemma dim_fixedField E (G : {group gal_of E}) : #|G| = \dim_(fixedField G) E. Proof. have [w [_ nzw] [_ Edirect /(_ (groupP G))defE]] := gal_matrix G. set n := #|G|; set m := \dim (fixedField G); rewrite -defE (directvP Edirect). rewrite -[n]card_ord -(@mulnK #|'I_n| m) ?adim_gt0 //= -sum_nat_const. congr (_ %/ _)%N; apply: eq_bigr => i _. by rewrite dim_cosetv ?(memPn nzw) ?mem_tnth. Qed. Lemma dim_fixed_galois K E (G : {group gal_of E}) : galois K E -> G \subset 'Gal(E / K) -> \dim_K (fixedField G) = #|'Gal(E / K) : G|. Proof. move=> galE sGgal; have [sFE _ _] := and3P galE; apply/eqP. rewrite -divgS // eqn_div ?cardSg // dim_fixedField -galois_dim //. by rewrite mulnC muln_divA ?divnK ?field_dimS ?capvSl -?galois_connection. Qed. Lemma gal_fixedField E (G : {group gal_of E}): 'Gal(E / fixedField G) = G. Proof. apply/esym/eqP; rewrite eqEcard galois_connection_subset /= (dim_fixedField G). rewrite galois_dim //; apply/galois_fixedField/eqP. rewrite eqEsubv galois_connection_subv ?capvSl //. by rewrite fixedFieldS ?galois_connection_subset. Qed. Lemma gal_generated E (A : {set gal_of E}) : 'Gal(E / fixedField A) = <<A>>. Proof. apply/eqP; rewrite eqEsubset gen_subG galois_connection_subset. by rewrite -[<<A>>]gal_fixedField galS // fixedFieldS // subset_gen. Qed. Lemma fixedField_galois E (A : {set gal_of E}): galois (fixedField A) E. Proof. have: galois (fixedField <<A>>) E. by apply/galois_fixedField; rewrite gal_fixedField. by apply: galoisS; rewrite capvSl fixedFieldS // subset_gen. Qed. Section FundamentalTheoremOfGaloisTheory. Variables E K : {subfield L}. Hypothesis galKE : galois K E. Section IntermediateField. Variable M : {subfield L}. Hypothesis (sKME : (K <= M <= E)%VS) (nKM : normalField K M). Lemma normalField_galois : galois K M. Proof. have [[sKM sME] [_ sepKE nKE]] := (andP sKME, and3P galKE). by rewrite /galois sKM (separableSr sME). Qed. Definition normalField_cast (x : gal_of E) : gal_of M := gal M x. Lemma normalField_cast_eq x : x \in 'Gal(E / K) -> {in M, normalField_cast x =1 x}. Proof. have [sKM sME] := andP sKME; have sKE := subv_trans sKM sME. rewrite gal_kAut // => /(normalField_kAut sKME nKM). by rewrite kAutE => /andP[_ /galK]. Qed. Lemma normalField_castM : {in 'Gal(E / K) &, {morph normalField_cast : x y / (x * y)%g}}. Proof. move=> x y galEx galEy /=; apply/eqP/gal_eqP => a Ma. have Ea: a \in E by have [_ /subvP->] := andP sKME. rewrite normalField_cast_eq ?groupM ?galM //=. by rewrite normalField_cast_eq ?memv_gal // normalField_cast_eq. Qed. Canonical normalField_cast_morphism := Morphism normalField_castM. Lemma normalField_ker : 'ker normalField_cast = 'Gal(E / M). Proof. have [sKM sME] := andP sKME. apply/setP=> x; apply/idP/idP=> [kerMx | galEMx]. rewrite gal_kHom //; apply/kAHomP=> a Ma. by rewrite -normalField_cast_eq ?(dom_ker kerMx) // (mker kerMx) gal_id. have galEM: x \in 'Gal(E / K) := subsetP (galS E sKM) x galEMx. apply/kerP=> //; apply/eqP/gal_eqP=> a Ma. by rewrite normalField_cast_eq // gal_id (fixed_gal sME). Qed. Lemma normalField_normal : 'Gal(E / M) <| 'Gal(E / K). Proof. by rewrite -normalField_ker ker_normal. Qed. Lemma normalField_img : normalField_cast @* 'Gal(E / K) = 'Gal(M / K). Proof. have [[sKM sME] [sKE _ nKE]] := (andP sKME, and3P galKE). apply/setP=> x; apply/idP/idP=> [/morphimP[{}x galEx _ ->] | galMx]. rewrite gal_kHom //; apply/kAHomP=> a Ka; have Ma := subvP sKM a Ka. by rewrite normalField_cast_eq // (fixed_gal sKE). have /(kHom_to_gal sKME nKE)[y galEy eq_xy]: kHom K M x by rewrite -gal_kHom. apply/morphimP; exists y => //; apply/eqP/gal_eqP => a Ha. by rewrite normalField_cast_eq // eq_xy. Qed. Lemma normalField_isom : {f : {morphism ('Gal(E / K) / 'Gal(E / M)) >-> gal_of M} | isom ('Gal(E / K) / 'Gal (E / M)) 'Gal(M / K) f & (forall A, f @* (A / 'Gal(E / M)) = normalField_cast @* A) /\ {in 'Gal(E / K) & M, forall x, f (coset 'Gal (E / M) x) =1 x} }%g. Proof. have:= first_isom normalField_cast_morphism; rewrite normalField_ker. case=> f injf Df; exists f; first by apply/isomP; rewrite Df normalField_img. split=> [//|x a galEx /normalField_cast_eq<- //]; congr ((_ : gal_of M) a). apply: set1_inj; rewrite -!morphim_set1 ?mem_quotient ?Df //. by rewrite (subsetP (normal_norm normalField_normal)). Qed. Lemma normalField_isog : 'Gal(E / K) / 'Gal(E / M) \isog 'Gal(M / K). Proof. by rewrite -normalField_ker -normalField_img first_isog. Qed. End IntermediateField. Section IntermediateGroup. Variable G : {group gal_of E}. Hypothesis nsGgalE : G <| 'Gal(E / K). Lemma normal_fixedField_galois : galois K (fixedField G). Proof. have [[sKE sepKE nKE] [sGgal nGgal]] := (and3P galKE, andP nsGgalE). rewrite /galois -(galois_connection _ sKE) sGgal. rewrite (separableSr _ sepKE) ?capvSl //; apply/forall_inP=> f autKf. rewrite eqEdim limg_dim_eq ?(eqP (AEnd_lker0 _)) ?capv0 // leqnn andbT. apply/subvP => _ /memv_imgP[a /mem_fixedFieldP[Ea cGa] ->]. have /kAut_to_gal[x galEx -> //]: kAut K E f. rewrite /kAut (forall_inP nKE) // andbT; apply/kAHomP. by move: autKf; rewrite inE kAutfE => /kHomP_tmp[]. apply/fixedFieldP=> [|y Gy]; first exact: memv_gal. by rewrite -galM // conjgCV galM //= cGa // memJ_norm ?groupV ?(subsetP nGgal). Qed. End IntermediateGroup. End FundamentalTheoremOfGaloisTheory. End GaloisTheory. Prenex Implicits gal_repr gal gal_reprK. Arguments gal_repr_inj {F L V} [x1 x2]. Notation "''Gal' ( V / U )" := (galoisG V U) : group_scope. Notation "''Gal' ( V / U )" := (galoisG_group V U) : Group_scope. Arguments fixedFieldP {F L E A a}. Arguments normalFieldP {F L K E}. Arguments splitting_galoisField {F L K E}. Arguments galois_fixedField {F L K E}.
Orthogonal.lean
/- Copyright (c) 2021 Lu-Ming Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lu-Ming Zhang -/ import Mathlib.Data.Matrix.Mul /-! # Orthogonal This file contains definitions and properties concerning orthogonality of rows and columns. ## Main results - `matrix.HasOrthogonalRows`: `A.HasOrthogonalRows` means `A` has orthogonal (with respect to `dotProduct`) rows. - `matrix.HasOrthogonalCols`: `A.HasOrthogonalCols` means `A` has orthogonal (with respect to `dotProduct`) columns. ## Tags orthogonal -/ assert_not_exists Field namespace Matrix variable {α n m : Type*} variable [Mul α] [AddCommMonoid α] variable (A : Matrix m n α) open Matrix /-- `A.HasOrthogonalRows` means matrix `A` has orthogonal rows (with respect to `dotProduct`). -/ def HasOrthogonalRows [Fintype n] : Prop := ∀ ⦃i₁ i₂⦄, i₁ ≠ i₂ → A i₁ ⬝ᵥ A i₂ = 0 /-- `A.HasOrthogonalCols` means matrix `A` has orthogonal columns (with respect to `dotProduct`). -/ def HasOrthogonalCols [Fintype m] : Prop := HasOrthogonalRows Aᵀ /-- `Aᵀ` has orthogonal rows iff `A` has orthogonal columns. -/ @[simp] theorem transpose_hasOrthogonalRows_iff_hasOrthogonalCols [Fintype m] : Aᵀ.HasOrthogonalRows ↔ A.HasOrthogonalCols := Iff.rfl /-- `Aᵀ` has orthogonal columns iff `A` has orthogonal rows. -/ @[simp] theorem transpose_hasOrthogonalCols_iff_hasOrthogonalRows [Fintype n] : Aᵀ.HasOrthogonalCols ↔ A.HasOrthogonalRows := Iff.rfl variable {A} theorem HasOrthogonalRows.hasOrthogonalCols [Fintype m] (h : Aᵀ.HasOrthogonalRows) : A.HasOrthogonalCols := h theorem HasOrthogonalCols.transpose_hasOrthogonalRows [Fintype m] (h : A.HasOrthogonalCols) : Aᵀ.HasOrthogonalRows := h theorem HasOrthogonalCols.hasOrthogonalRows [Fintype n] (h : Aᵀ.HasOrthogonalCols) : A.HasOrthogonalRows := h theorem HasOrthogonalRows.transpose_hasOrthogonalCols [Fintype n] (h : A.HasOrthogonalRows) : Aᵀ.HasOrthogonalCols := h end Matrix
inertia.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 prime order. From mathcomp Require Import ssralg ssrnum finset fingroup morphism perm. From mathcomp Require Import automorphism quotient action zmodp cyclic center. From mathcomp Require Import gproduct commutator gseries nilpotent pgroup. From mathcomp Require Import sylow maximal frobenius matrix mxalgebra. From mathcomp Require Import mxrepresentation vector algC classfun character. From mathcomp Require Import archimedean. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import Order.TTheory GroupScope GRing.Theory Num.Theory. Local Open Scope ring_scope. (******************************************************************************) (* This file contains the definitions and properties of inertia groups: *) (* (phi ^ y)%CF == the y-conjugate of phi : 'CF(G), i.e., the class *) (* function mapping x ^ y to phi x provided y normalises G. *) (* We take (phi ^ y)%CF = phi when y \notin 'N(G). *) (* (phi ^: G)%CF == the sequence of all distinct conjugates of phi : 'CF(H) *) (* by all y in G. *) (* 'I[phi] == the inertia group of phi : CF(H), i.e., the set of y *) (* such that (phi ^ y)%CF = phi AND H :^ y = y. *) (* 'I_G[phi] == the inertia group of phi in G, i.e., G :&: 'I[phi]. *) (* conjg_Iirr i y == the index j : Iirr G such that ('chi_i ^ y)%CF = 'chi_j. *) (* cfclass_Iirr G i == the image of G under conjg_Iirr i, i.e., the set of j *) (* such that 'chi_j \in ('chi_i ^: G)%CF. *) (* mul_Iirr i j == the index k such that 'chi_j * 'chi_i = 'chi[G]_k, *) (* or 0 if 'chi_j * 'chi_i is reducible. *) (* mul_mod_Iirr i j := mul_Iirr i (mod_Iirr j), for j : Iirr (G / H). *) (******************************************************************************) Reserved Notation "''I[' phi ]" (format "''I[' phi ]"). Reserved Notation "''I_' G [ phi ]" (G at level 2, format "''I_' G [ phi ]"). Section ConjDef. Variables (gT : finGroupType) (B : {set gT}) (y : gT) (phi : 'CF(B)). Local Notation G := <<B>>. Fact cfConjg_subproof : is_class_fun G [ffun x => phi (if y \in 'N(G) then x ^ y^-1 else x)]. Proof. apply: intro_class_fun => [x z _ Gz | x notGx]. have [nGy | _] := ifP; last by rewrite cfunJgen. by rewrite -conjgM conjgC conjgM cfunJgen // memJ_norm ?groupV. by rewrite cfun0gen //; case: ifP => // nGy; rewrite memJ_norm ?groupV. Qed. Definition cfConjg := Cfun 1 cfConjg_subproof. End ConjDef. Prenex Implicits cfConjg. Notation "f ^ y" := (cfConjg y f) : cfun_scope. Section Conj. Variables (gT : finGroupType) (G : {group gT}). Implicit Type phi : 'CF(G). Lemma cfConjgE phi y x : y \in 'N(G) -> (phi ^ y)%CF x = phi (x ^ y^-1)%g. Proof. by rewrite cfunElock genGid => ->. Qed. Lemma cfConjgEJ phi y x : y \in 'N(G) -> (phi ^ y)%CF (x ^ y) = phi x. Proof. by move/cfConjgE->; rewrite conjgK. Qed. Lemma cfConjgEout phi y : y \notin 'N(G) -> (phi ^ y = phi)%CF. Proof. by move/negbTE=> notNy; apply/cfunP=> x; rewrite !cfunElock genGid notNy. Qed. Lemma cfConjgEin phi y (nGy : y \in 'N(G)) : (phi ^ y)%CF = cfIsom (norm_conj_isom nGy) phi. Proof. apply/cfun_inP=> x Gx. by rewrite cfConjgE // -{2}[x](conjgKV y) cfIsomE ?memJ_norm ?groupV. Qed. Lemma cfConjgMnorm phi : {in 'N(G) &, forall y z, phi ^ (y * z) = (phi ^ y) ^ z}%CF. Proof. move=> y z nGy nGz. by apply/cfunP=> x; rewrite !cfConjgE ?groupM // invMg conjgM. Qed. Lemma cfConjg_id phi y : y \in G -> (phi ^ y)%CF = phi. Proof. move=> Gy; apply/cfunP=> x; have nGy := subsetP (normG G) y Gy. by rewrite -(cfunJ _ _ Gy) cfConjgEJ. Qed. (* Isaacs' 6.1.b *) Lemma cfConjgM L phi : G <| L -> {in L &, forall y z, phi ^ (y * z) = (phi ^ y) ^ z}%CF. Proof. by case/andP=> _ /subsetP nGL; apply: sub_in2 (cfConjgMnorm phi). Qed. Lemma cfConjgJ1 phi : (phi ^ 1)%CF = phi. Proof. by apply/cfunP=> x; rewrite cfConjgE ?group1 // invg1 conjg1. Qed. Lemma cfConjgK y : cancel (cfConjg y) (cfConjg y^-1 : 'CF(G) -> 'CF(G)). Proof. move=> phi; apply/cfunP=> x; rewrite !cfunElock groupV /=. by case: ifP => -> //; rewrite conjgKV. Qed. Lemma cfConjgKV y : cancel (cfConjg y^-1) (cfConjg y : 'CF(G) -> 'CF(G)). Proof. by move=> phi /=; rewrite -{1}[y]invgK cfConjgK. Qed. Lemma cfConjg1 phi y : (phi ^ y)%CF 1%g = phi 1%g. Proof. by rewrite cfunElock conj1g if_same. Qed. Fact cfConjg_is_linear y : linear (cfConjg y : 'CF(G) -> 'CF(G)). Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock. Qed. HB.instance Definition _ y := GRing.isSemilinear.Build _ _ _ _ (cfConjg y) (GRing.semilinear_linear (cfConjg_is_linear y)). Lemma cfConjg_cfuniJ A y : y \in 'N(G) -> ('1_A ^ y)%CF = '1_(A :^ y) :> 'CF(G). Proof. move=> nGy; apply/cfunP=> x; rewrite !cfunElock genGid nGy -sub_conjgV. by rewrite -class_lcoset -class_rcoset norm_rlcoset ?memJ_norm ?groupV. Qed. Lemma cfConjg_cfuni A y : y \in 'N(A) -> ('1_A ^ y)%CF = '1_A :> 'CF(G). Proof. by have [/cfConjg_cfuniJ-> /normP-> | /cfConjgEout] := boolP (y \in 'N(G)). Qed. Lemma cfConjg_cfun1 y : (1 ^ y)%CF = 1 :> 'CF(G). Proof. by rewrite -cfuniG; have [/cfConjg_cfuni|/cfConjgEout] := boolP (y \in 'N(G)). Qed. Fact cfConjg_is_monoid_morphism y : monoid_morphism (cfConjg y : _ -> 'CF(G)). Proof. split=> [|phi psi]; first exact: cfConjg_cfun1. by apply/cfunP=> x; rewrite !cfunElock. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `cfConjg_is_monoid_morphism` instead")] Definition cfConjg_is_multiplicative y := (fun g => (g.2,g.1)) (cfConjg_is_monoid_morphism y). HB.instance Definition _ y := GRing.isMonoidMorphism.Build _ _ (cfConjg y) (cfConjg_is_monoid_morphism y). Lemma cfConjg_eq1 phi y : ((phi ^ y)%CF == 1) = (phi == 1). Proof. by apply: rmorph_eq1; apply: can_inj (cfConjgK y). Qed. Lemma cfAutConjg phi u y : cfAut u (phi ^ y) = (cfAut u phi ^ y)%CF. Proof. by apply/cfunP=> x; rewrite !cfunElock. Qed. Lemma conj_cfConjg phi y : (phi ^ y)^*%CF = (phi^* ^ y)%CF. Proof. exact: cfAutConjg. Qed. Lemma cfker_conjg phi y : y \in 'N(G) -> cfker (phi ^ y) = cfker phi :^ y. Proof. move=> nGy; rewrite cfConjgEin // cfker_isom. by rewrite morphim_conj (setIidPr (cfker_sub _)). Qed. Lemma cfDetConjg phi y : cfDet (phi ^ y) = (cfDet phi ^ y)%CF. Proof. have [nGy | not_nGy] := boolP (y \in 'N(G)); last by rewrite !cfConjgEout. by rewrite !cfConjgEin cfDetIsom. Qed. End Conj. Section Inertia. Variable gT : finGroupType. Definition inertia (B : {set gT}) (phi : 'CF(B)) := [set y in 'N(B) | (phi ^ y)%CF == phi]. Local Notation "''I[' phi ]" := (inertia phi) : group_scope. Local Notation "''I_' G [ phi ]" := (G%g :&: 'I[phi]) : group_scope. Fact group_set_inertia (H : {group gT}) phi : group_set 'I[phi : 'CF(H)]. Proof. apply/group_setP; split; first by rewrite inE group1 /= cfConjgJ1. move=> y z /setIdP[nHy /eqP n_phi_y] /setIdP[nHz n_phi_z]. by rewrite inE groupM //= cfConjgMnorm ?n_phi_y. Qed. Canonical inertia_group H phi := Group (@group_set_inertia H phi). Local Notation "''I[' phi ]" := (inertia_group phi) : Group_scope. Local Notation "''I_' G [ phi ]" := (G :&: 'I[phi])%G : Group_scope. Variables G H : {group gT}. Implicit Type phi : 'CF(H). Lemma inertiaJ phi y : y \in 'I[phi] -> (phi ^ y)%CF = phi. Proof. by case/setIdP=> _ /eqP->. Qed. Lemma inertia_valJ phi x y : y \in 'I[phi] -> phi (x ^ y)%g = phi x. Proof. by case/setIdP=> nHy /eqP {1}<-; rewrite cfConjgEJ. Qed. (* To disambiguate basic inclucion lemma names we capitalize Inertia for *) (* lemmas concerning the localized inertia group 'I_G[phi]. *) Lemma Inertia_sub phi : 'I_G[phi] \subset G. Proof. exact: subsetIl. Qed. Lemma norm_inertia phi : 'I[phi] \subset 'N(H). Proof. by rewrite ['I[_]]setIdE subsetIl. Qed. Lemma sub_inertia phi : H \subset 'I[phi]. Proof. by apply/subsetP=> y Hy; rewrite inE cfConjg_id ?(subsetP (normG H)) /=. Qed. Lemma normal_inertia phi : H <| 'I[phi]. Proof. by rewrite /normal sub_inertia norm_inertia. Qed. Lemma sub_Inertia phi : H \subset G -> H \subset 'I_G[phi]. Proof. by rewrite subsetI sub_inertia andbT. Qed. Lemma norm_Inertia phi : 'I_G[phi] \subset 'N(H). Proof. by rewrite setIC subIset ?norm_inertia. Qed. Lemma normal_Inertia phi : H \subset G -> H <| 'I_G[phi]. Proof. by rewrite /normal norm_Inertia andbT; apply: sub_Inertia. Qed. Lemma cfConjg_eqE phi : H <| G -> {in G &, forall y z, (phi ^ y == phi ^ z)%CF = (z \in 'I_G[phi] :* y)}. Proof. case/andP=> _ nHG y z Gy; rewrite -{1 2}[z](mulgKV y) groupMr // mem_rcoset. move: {z}(z * _)%g => z Gz; rewrite 2!inE Gz cfConjgMnorm ?(subsetP nHG) //=. by rewrite eq_sym (can_eq (cfConjgK y)). Qed. Lemma cent_sub_inertia phi : 'C(H) \subset 'I[phi]. Proof. apply/subsetP=> y cHy; have nHy := subsetP (cent_sub H) y cHy. rewrite inE nHy; apply/eqP/cfun_inP=> x Hx; rewrite cfConjgE //. by rewrite /conjg invgK mulgA (centP cHy) ?mulgK. Qed. Lemma cent_sub_Inertia phi : 'C_G(H) \subset 'I_G[phi]. Proof. exact: setIS (cent_sub_inertia phi). Qed. Lemma center_sub_Inertia phi : H \subset G -> 'Z(G) \subset 'I_G[phi]. Proof. by move/centS=> sHG; rewrite setIS // (subset_trans sHG) // cent_sub_inertia. Qed. Lemma conjg_inertia phi y : y \in 'N(H) -> 'I[phi] :^ y = 'I[phi ^ y]. Proof. move=> nHy; apply/setP=> z; rewrite !['I[_]]setIdE conjIg conjGid // !in_setI. apply/andb_id2l=> nHz; rewrite mem_conjg !inE. by rewrite !cfConjgMnorm ?in_group ?(can2_eq (cfConjgKV y) (cfConjgK y)) ?invgK. Qed. Lemma inertia0 : 'I[0 : 'CF(H)] = 'N(H). Proof. by apply/setP=> x; rewrite !inE linear0 eqxx andbT. Qed. Lemma inertia_add phi psi : 'I[phi] :&: 'I[psi] \subset 'I[phi + psi]. Proof. rewrite !['I[_]]setIdE -setIIr setIS //. by apply/subsetP=> x /[!(inE, linearD)]/= /andP[/eqP-> /eqP->]. Qed. Lemma inertia_sum I r (P : pred I) (Phi : I -> 'CF(H)) : 'N(H) :&: \bigcap_(i <- r | P i) 'I[Phi i] \subset 'I[\sum_(i <- r | P i) Phi i]. Proof. elim/big_rec2: _ => [|i K psi Pi sK_Ipsi]; first by rewrite setIT inertia0. by rewrite setICA; apply: subset_trans (setIS _ sK_Ipsi) (inertia_add _ _). Qed. Lemma inertia_scale a phi : 'I[phi] \subset 'I[a *: phi]. Proof. apply/subsetP=> x /setIdP[nHx /eqP Iphi_x]. by rewrite inE nHx linearZ /= Iphi_x. Qed. Lemma inertia_scale_nz a phi : a != 0 -> 'I[a *: phi] = 'I[phi]. Proof. move=> nz_a; apply/eqP. by rewrite eqEsubset -{2}(scalerK nz_a phi) !inertia_scale. Qed. Lemma inertia_opp phi : 'I[- phi] = 'I[phi]. Proof. by rewrite -scaleN1r inertia_scale_nz // oppr_eq0 oner_eq0. Qed. Lemma inertia1 : 'I[1 : 'CF(H)] = 'N(H). Proof. by apply/setP=> x; rewrite inE rmorph1 eqxx andbT. Qed. Lemma Inertia1 : H <| G -> 'I_G[1 : 'CF(H)] = G. Proof. by rewrite inertia1 => /normal_norm/setIidPl. Qed. Lemma inertia_mul phi psi : 'I[phi] :&: 'I[psi] \subset 'I[phi * psi]. Proof. rewrite !['I[_]]setIdE -setIIr setIS //. by apply/subsetP=> x /[!(inE, rmorphM)]/= /andP[/eqP-> /eqP->]. Qed. Lemma inertia_prod I r (P : pred I) (Phi : I -> 'CF(H)) : 'N(H) :&: \bigcap_(i <- r | P i) 'I[Phi i] \subset 'I[\prod_(i <- r | P i) Phi i]. Proof. elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite inertia1 setIT. by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (inertia_mul _ _). Qed. Lemma inertia_injective (chi : 'CF(H)) : {in H &, injective chi} -> 'I[chi] = 'C(H). Proof. move=> inj_chi; apply/eqP; rewrite eqEsubset cent_sub_inertia andbT. apply/subsetP=> y Ichi_y; have /setIdP[nHy _] := Ichi_y. apply/centP=> x Hx; apply/esym/commgP/conjg_fixP. by apply/inj_chi; rewrite ?memJ_norm ?(inertia_valJ _ Ichi_y). Qed. Lemma inertia_irr_prime p i : #|H| = p -> prime p -> i != 0 -> 'I['chi[H]_i] = 'C(H). Proof. by move=> <- pr_H /(irr_prime_injP pr_H); apply: inertia_injective. Qed. Lemma inertia_irr0 : 'I['chi[H]_0] = 'N(H). Proof. by rewrite irr0 inertia1. Qed. (* Isaacs' 6.1.c *) Lemma cfConjg_iso y : isometry (cfConjg y : 'CF(H) -> 'CF(H)). Proof. move=> phi psi; congr (_ * _). have [nHy | not_nHy] := boolP (y \in 'N(H)); last by rewrite !cfConjgEout. rewrite (reindex_astabs 'J y) ?astabsJ //=. by apply: eq_bigr=> x _; rewrite !cfConjgEJ. Qed. (* Isaacs' 6.1.d *) Lemma cfdot_Res_conjg psi phi y : y \in G -> '['Res[H, G] psi, phi ^ y] = '['Res[H] psi, phi]. Proof. move=> Gy; rewrite -(cfConjg_iso y _ phi); congr '[_, _]; apply/cfunP=> x. rewrite !cfunElock !genGid; case nHy: (y \in 'N(H)) => //. by rewrite !(fun_if psi) cfunJ ?memJ_norm ?groupV. Qed. (* Isaac's 6.1.e *) Lemma cfConjg_char (chi : 'CF(H)) y : chi \is a character -> (chi ^ y)%CF \is a character. Proof. have [nHy Nchi | /cfConjgEout-> //] := boolP (y \in 'N(H)). by rewrite cfConjgEin cfIsom_char. Qed. Lemma cfConjg_lin_char (chi : 'CF(H)) y : chi \is a linear_char -> (chi ^ y)%CF \is a linear_char. Proof. by case/andP=> Nchi chi1; rewrite qualifE/= cfConjg1 cfConjg_char. Qed. Lemma cfConjg_irr y chi : chi \in irr H -> (chi ^ y)%CF \in irr H. Proof. by rewrite !irrEchar cfConjg_iso => /andP[/cfConjg_char->]. Qed. Definition conjg_Iirr i y := cfIirr ('chi[H]_i ^ y)%CF. Lemma conjg_IirrE i y : 'chi_(conjg_Iirr i y) = ('chi_i ^ y)%CF. Proof. by rewrite cfIirrE ?cfConjg_irr ?mem_irr. Qed. Lemma conjg_IirrK y : cancel (conjg_Iirr^~ y) (conjg_Iirr^~ y^-1%g). Proof. by move=> i; apply/irr_inj; rewrite !conjg_IirrE cfConjgK. Qed. Lemma conjg_IirrKV y : cancel (conjg_Iirr^~ y^-1%g) (conjg_Iirr^~ y). Proof. by rewrite -{2}[y]invgK; apply: conjg_IirrK. Qed. Lemma conjg_Iirr_inj y : injective (conjg_Iirr^~ y). Proof. exact: can_inj (conjg_IirrK y). Qed. Lemma conjg_Iirr_eq0 i y : (conjg_Iirr i y == 0) = (i == 0). Proof. by rewrite -!irr_eq1 conjg_IirrE cfConjg_eq1. Qed. Lemma conjg_Iirr0 x : conjg_Iirr 0 x = 0. Proof. by apply/eqP; rewrite conjg_Iirr_eq0. Qed. Lemma cfdot_irr_conjg i y : H <| G -> y \in G -> '['chi_i, 'chi_i ^ y]_H = (y \in 'I_G['chi_i])%:R. Proof. move=> nsHG Gy; rewrite -conjg_IirrE cfdot_irr -(inj_eq irr_inj) conjg_IirrE. by rewrite -{1}['chi_i]cfConjgJ1 cfConjg_eqE ?mulg1. Qed. Definition cfclass (A : {set gT}) (phi : 'CF(A)) (B : {set gT}) := [seq (phi ^ repr Tx)%CF | Tx in rcosets 'I_B[phi] B]. Local Notation "phi ^: G" := (cfclass phi G) : cfun_scope. Lemma size_cfclass i : size ('chi[H]_i ^: G)%CF = #|G : 'I_G['chi_i]|. Proof. by rewrite size_map -cardE. Qed. Lemma cfclassP (A : {group gT}) phi psi : reflect (exists2 y, y \in A & psi = phi ^ y)%CF (psi \in phi ^: A)%CF. Proof. apply: (iffP imageP) => [[_ /rcosetsP[y Ay ->] ->] | [y Ay ->]]. by case: repr_rcosetP => z /setIdP[Az _]; exists (z * y)%g; rewrite ?groupM. without loss nHy: y Ay / y \in 'N(H). have [nHy | /cfConjgEout->] := boolP (y \in 'N(H)); first exact. by move/(_ 1%g); rewrite !group1 !cfConjgJ1; apply. exists ('I_A[phi] :* y); first by rewrite -rcosetE imset_f. case: repr_rcosetP => z /setIP[_ /setIdP[nHz /eqP Tz]]. by rewrite cfConjgMnorm ?Tz. Qed. Lemma cfclassInorm phi : (phi ^: 'N_G(H) =i phi ^: G)%CF. Proof. move=> xi; apply/cfclassP/cfclassP=> [[x /setIP[Gx _] ->] | [x Gx ->]]. by exists x. have [Nx | /cfConjgEout-> //] := boolP (x \in 'N(H)). by exists x; first apply/setIP. by exists 1%g; rewrite ?group1 ?cfConjgJ1. Qed. Lemma cfclass_refl phi : phi \in (phi ^: G)%CF. Proof. by apply/cfclassP; exists 1%g => //; rewrite cfConjgJ1. Qed. Lemma cfclass_transr phi psi : (psi \in phi ^: G)%CF -> (phi ^: G =i psi ^: G)%CF. Proof. rewrite -cfclassInorm; case/cfclassP=> x Gx -> xi; rewrite -!cfclassInorm. have nHN: {subset 'N_G(H) <= 'N(H)} by apply/subsetP; apply: subsetIr. apply/cfclassP/cfclassP=> [[y Gy ->] | [y Gy ->]]. by exists (x^-1 * y)%g; rewrite -?cfConjgMnorm ?groupM ?groupV ?nHN // mulKVg. by exists (x * y)%g; rewrite -?cfConjgMnorm ?groupM ?nHN. Qed. Lemma cfclass_sym phi psi : (psi \in phi ^: G)%CF = (phi \in psi ^: G)%CF. Proof. by apply/idP/idP=> /cfclass_transr <-; apply: cfclass_refl. Qed. Lemma cfclass_uniq phi : H <| G -> uniq (phi ^: G)%CF. Proof. move=> nsHG; rewrite map_inj_in_uniq ?enum_uniq // => Ty Tz; rewrite !mem_enum. move=> {Ty}/rcosetsP[y Gy ->] {Tz}/rcosetsP[z Gz ->] /eqP. case: repr_rcosetP => u Iphi_u; case: repr_rcosetP => v Iphi_v. have [[Gu _] [Gv _]] := (setIdP Iphi_u, setIdP Iphi_v). rewrite cfConjg_eqE ?groupM // => /rcoset_eqP. by rewrite !rcosetM (rcoset_id Iphi_v) (rcoset_id Iphi_u). Qed. Lemma cfclass_invariant phi : G \subset 'I[phi] -> (phi ^: G)%CF = phi. Proof. move/setIidPl=> IGphi; rewrite /cfclass IGphi // rcosets_id. by rewrite /(image _ _) enum_set1 /= repr_group cfConjgJ1. Qed. Lemma cfclass1 : H <| G -> (1 ^: G)%CF = [:: 1 : 'CF(H)]. Proof. by move/normal_norm=> nHG; rewrite cfclass_invariant ?inertia1. Qed. Definition cfclass_Iirr (A : {set gT}) i := conjg_Iirr i @: A. Lemma cfclass_IirrE i j : (j \in cfclass_Iirr G i) = ('chi_j \in 'chi_i ^: G)%CF. Proof. apply/imsetP/cfclassP=> [[y Gy ->] | [y]]; exists y; rewrite ?conjg_IirrE //. by apply: irr_inj; rewrite conjg_IirrE. Qed. Lemma eq_cfclass_IirrE i j : (cfclass_Iirr G j == cfclass_Iirr G i) = (j \in cfclass_Iirr G i). Proof. apply/eqP/idP=> [<- | iGj]; first by rewrite cfclass_IirrE cfclass_refl. by apply/setP=> k; rewrite !cfclass_IirrE in iGj *; apply/esym/cfclass_transr. Qed. Lemma im_cfclass_Iirr i : H <| G -> perm_eq [seq 'chi_j | j in cfclass_Iirr G i] ('chi_i ^: G)%CF. Proof. move=> nsHG; have UchiG := cfclass_uniq 'chi_i nsHG. apply: uniq_perm; rewrite ?(map_inj_uniq irr_inj) ?enum_uniq // => phi. apply/imageP/idP=> [[j iGj ->] | /cfclassP[y]]; first by rewrite -cfclass_IirrE. by exists (conjg_Iirr i y); rewrite ?imset_f ?conjg_IirrE. Qed. Lemma card_cfclass_Iirr i : H <| G -> #|cfclass_Iirr G i| = #|G : 'I_G['chi_i]|. Proof. move=> nsHG; rewrite -size_cfclass -(perm_size (im_cfclass_Iirr i nsHG)). by rewrite size_map -cardE. Qed. Lemma reindex_cfclass R idx (op : Monoid.com_law idx) (F : 'CF(H) -> R) i : H <| G -> \big[op/idx]_(chi <- ('chi_i ^: G)%CF) F chi = \big[op/idx]_(j | 'chi_j \in ('chi_i ^: G)%CF) F 'chi_j. Proof. move/im_cfclass_Iirr/(perm_big _) <-; rewrite big_image /=. by apply: eq_bigl => j; rewrite cfclass_IirrE. Qed. Lemma cfResInd j: H <| G -> 'Res[H] ('Ind[G] 'chi_j) = #|H|%:R^-1 *: (\sum_(y in G) 'chi_j ^ y)%CF. Proof. case/andP=> [sHG /subsetP nHG]. rewrite (reindex_inj invg_inj); apply/cfun_inP=> x Hx. rewrite cfResE // cfIndE // ?cfunE ?sum_cfunE; congr (_ * _). by apply: eq_big => [y | y Gy]; rewrite ?cfConjgE ?groupV ?invgK ?nHG. Qed. (* This is Isaacs, Theorem (6.2) *) Lemma Clifford_Res_sum_cfclass i j : H <| G -> j \in irr_constt ('Res[H, G] 'chi_i) -> 'Res[H] 'chi_i = '['Res[H] 'chi_i, 'chi_j] *: (\sum_(chi <- ('chi_j ^: G)%CF) chi). Proof. move=> nsHG chiHj; have [sHG /subsetP nHG] := andP nsHG. rewrite reindex_cfclass //= big_mkcond. rewrite {1}['Res _]cfun_sum_cfdot linear_sum /=; apply: eq_bigr => k _. have [[y Gy ->] | ] := altP (cfclassP _ _ _); first by rewrite cfdot_Res_conjg. apply: contraNeq; rewrite scaler0 scaler_eq0 orbC => /norP[_ chiHk]. have{chiHk chiHj}: '['Res[H] ('Ind[G] 'chi_j), 'chi_k] != 0. rewrite !inE !cfdot_Res_l in chiHj chiHk *. apply: contraNneq chiHk; rewrite cfdot_sum_irr => /psumr_eq0P/(_ i isT)/eqP. rewrite -cfdotC cfdotC mulf_eq0 conjC_eq0 (negbTE chiHj) /= => -> // i1. by rewrite -cfdotC natr_ge0 // rpredM ?Cnat_cfdot_char ?cfInd_char ?irr_char. rewrite cfResInd // cfdotZl mulf_eq0 cfdot_suml => /norP[_]. apply: contraR => chiGk'j; rewrite big1 // => x Gx; apply: contraNeq chiGk'j. rewrite -conjg_IirrE cfdot_irr pnatr_eq0; case: (_ =P k) => // <- _. by rewrite conjg_IirrE; apply/cfclassP; exists x. Qed. Lemma cfRes_Ind_invariant psi : H <| G -> G \subset 'I[psi] -> 'Res ('Ind[G, H] psi) = #|G : H|%:R *: psi. Proof. case/andP=> sHG _ /subsetP IGpsi; apply/cfun_inP=> x Hx. rewrite cfResE ?cfIndE ?natf_indexg // cfunE -mulrA mulrCA; congr (_ * _). by rewrite mulr_natl -sumr_const; apply: eq_bigr => y /IGpsi/inertia_valJ->. Qed. (* This is Isaacs, Corollary (6.7). *) Corollary constt0_Res_cfker i : H <| G -> 0 \in irr_constt ('Res[H] 'chi[G]_i) -> H \subset cfker 'chi[G]_i. Proof. move=> nsHG /(Clifford_Res_sum_cfclass nsHG); have [sHG nHG] := andP nsHG. rewrite irr0 cfdot_Res_l cfclass1 // big_seq1 cfInd_cfun1 //. rewrite cfdotZr conjC_nat => def_chiH. apply/subsetP=> x Hx; rewrite cfkerEirr inE -!(cfResE _ sHG) //. by rewrite def_chiH !cfunE cfun11 cfun1E Hx. Qed. (* This is Isaacs, Lemma (6.8). *) Lemma dvdn_constt_Res1_irr1 i j : H <| G -> j \in irr_constt ('Res[H, G] 'chi_i) -> exists n, 'chi_i 1%g = n%:R * 'chi_j 1%g. Proof. move=> nsHG chiHj; have [sHG nHG] := andP nsHG; rewrite -(cfResE _ sHG) //. rewrite {1}(Clifford_Res_sum_cfclass nsHG chiHj) cfunE sum_cfunE. have /natrP[n ->]: '['Res[H] 'chi_i, 'chi_j] \in Num.nat. by rewrite Cnat_cfdot_char ?cfRes_char ?irr_char. exists (n * size ('chi_j ^: G)%CF)%N; rewrite natrM -mulrA; congr (_ * _). rewrite mulr_natl -[size _]card_ord big_tnth -sumr_const; apply: eq_bigr => k _. by have /cfclassP[y Gy ->]:= mem_tnth k (in_tuple _); rewrite cfConjg1. Qed. Lemma cfclass_Ind phi psi : H <| G -> psi \in (phi ^: G)%CF -> 'Ind[G] phi = 'Ind[G] psi. Proof. move=> nsHG /cfclassP[y Gy ->]; have [sHG /subsetP nHG] := andP nsHG. apply/cfun_inP=> x Hx; rewrite !cfIndE //; congr (_ * _). rewrite (reindex_acts 'R _ (groupVr Gy)) ?astabsR //=. by apply: eq_bigr => z Gz; rewrite conjgM cfConjgE ?nHG. Qed. End Inertia. Arguments inertia {gT B%_g} phi%_CF. Arguments cfclass {gT A%_g} phi%_CF B%_g. Arguments conjg_Iirr_inj {gT H} y [i1 i2] : rename. Notation "''I[' phi ] " := (inertia phi) : group_scope. Notation "''I[' phi ] " := (inertia_group phi) : Group_scope. Notation "''I_' G [ phi ] " := (G%g :&: 'I[phi]) : group_scope. Notation "''I_' G [ phi ] " := (G :&: 'I[phi])%G : Group_scope. Notation "phi ^: G" := (cfclass phi G) : cfun_scope. Section ConjRestrict. Variables (gT : finGroupType) (G H K : {group gT}). Lemma cfConjgRes_norm phi y : y \in 'N(K) -> y \in 'N(H) -> ('Res[K, H] phi ^ y)%CF = 'Res (phi ^ y)%CF. Proof. move=> nKy nHy; have [sKH | not_sKH] := boolP (K \subset H); last first. by rewrite !cfResEout // rmorph_alg cfConjg1. by apply/cfun_inP=> x Kx; rewrite !(cfConjgE, cfResE) ?memJ_norm ?groupV. Qed. Lemma cfConjgRes phi y : H <| G -> K <| G -> y \in G -> ('Res[K, H] phi ^ y)%CF = 'Res (phi ^ y)%CF. Proof. move=> /andP[_ nHG] /andP[_ nKG] Gy. by rewrite cfConjgRes_norm ?(subsetP nHG) ?(subsetP nKG). Qed. Lemma sub_inertia_Res phi : G \subset 'N(K) -> 'I_G[phi] \subset 'I_G['Res[K, H] phi]. Proof. move=> nKG; apply/subsetP=> y /setIP[Gy /setIdP[nHy /eqP Iphi_y]]. by rewrite 2!inE Gy cfConjgRes_norm ?(subsetP nKG) ?Iphi_y /=. Qed. Lemma cfConjgInd_norm phi y : y \in 'N(K) -> y \in 'N(H) -> ('Ind[H, K] phi ^ y)%CF = 'Ind (phi ^ y)%CF. Proof. move=> nKy nHy; have [sKH | not_sKH] := boolP (K \subset H). by rewrite !cfConjgEin (cfIndIsom (norm_conj_isom nHy)). rewrite !cfIndEout // linearZ -(cfConjg_iso y) rmorph1 /=; congr (_ *: _). by rewrite cfConjg_cfuni ?norm1 ?inE. Qed. Lemma cfConjgInd phi y : H <| G -> K <| G -> y \in G -> ('Ind[H, K] phi ^ y)%CF = 'Ind (phi ^ y)%CF. Proof. move=> /andP[_ nHG] /andP[_ nKG] Gy. by rewrite cfConjgInd_norm ?(subsetP nHG) ?(subsetP nKG). Qed. Lemma sub_inertia_Ind phi : G \subset 'N(H) -> 'I_G[phi] \subset 'I_G['Ind[H, K] phi]. Proof. move=> nHG; apply/subsetP=> y /setIP[Gy /setIdP[nKy /eqP Iphi_y]]. by rewrite 2!inE Gy cfConjgInd_norm ?(subsetP nHG) ?Iphi_y /=. Qed. End ConjRestrict. Section MoreInertia. Variables (gT : finGroupType) (G H : {group gT}) (i : Iirr H). Let T := 'I_G['chi_i]. Lemma inertia_id : 'I_T['chi_i] = T. Proof. by rewrite -setIA setIid. Qed. Lemma cfclass_inertia : ('chi[H]_i ^: T)%CF = [:: 'chi_i]. Proof. rewrite /cfclass inertia_id rcosets_id /(image _ _) enum_set1 /=. by rewrite repr_group cfConjgJ1. Qed. End MoreInertia. Section ConjMorph. Variables (aT rT : finGroupType) (D G H : {group aT}) (f : {morphism D >-> rT}). Lemma cfConjgMorph (phi : 'CF(f @* H)) y : y \in D -> y \in 'N(H) -> (cfMorph phi ^ y)%CF = cfMorph (phi ^ f y). Proof. move=> Dy nHy; have [sHD | not_sHD] := boolP (H \subset D); last first. by rewrite !cfMorphEout // rmorph_alg cfConjg1. apply/cfun_inP=> x Gx; rewrite !(cfConjgE, cfMorphE) ?memJ_norm ?groupV //. by rewrite morphJ ?morphV ?groupV // (subsetP sHD). by rewrite (subsetP (morphim_norm _ _)) ?mem_morphim. Qed. Lemma inertia_morph_pre (phi : 'CF(f @* H)) : H <| G -> G \subset D -> 'I_G[cfMorph phi] = G :&: f @*^-1 'I_(f @* G)[phi]. Proof. case/andP=> sHG nHG sGD; have sHD := subset_trans sHG sGD. apply/setP=> y; rewrite !in_setI; apply: andb_id2l => Gy. have [Dy nHy] := (subsetP sGD y Gy, subsetP nHG y Gy). rewrite Dy inE nHy 4!inE mem_morphim // -morphimJ ?(normP nHy) // subxx /=. rewrite cfConjgMorph //; apply/eqP/eqP=> [Iphi_y | -> //]. by apply/cfun_inP=> _ /morphimP[x Dx Hx ->]; rewrite -!cfMorphE ?Iphi_y. Qed. Lemma inertia_morph_im (phi : 'CF(f @* H)) : H <| G -> G \subset D -> f @* 'I_G[cfMorph phi] = 'I_(f @* G)[phi]. Proof. move=> nsHG sGD; rewrite inertia_morph_pre // morphim_setIpre. by rewrite (setIidPr _) ?Inertia_sub. Qed. Variables (R S : {group rT}). Variables (g : {morphism G >-> rT}) (h : {morphism H >-> rT}). Hypotheses (isoG : isom G R g) (isoH : isom H S h). Hypotheses (eq_hg : {in H, h =1 g}) (sHG : H \subset G). (* This does not depend on the (isoG : isom G R g) assumption. *) Lemma cfConjgIsom phi y : y \in G -> y \in 'N(H) -> (cfIsom isoH phi ^ g y)%CF = cfIsom isoH (phi ^ y). Proof. move=> Gy nHy; have [_ defS] := isomP isoH. rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS. apply/cfun_inP=> gx; rewrite -{1}defS => /morphimP[x Gx Hx ->] {gx}. rewrite cfConjgE; last by rewrite -defS inE -morphimJ ?(normP nHy). by rewrite -morphV -?morphJ -?eq_hg ?cfIsomE ?cfConjgE ?memJ_norm ?groupV. Qed. Lemma inertia_isom phi : 'I_R[cfIsom isoH phi] = g @* 'I_G[phi]. Proof. have [[_ defS] [injg <-]] := (isomP isoH, isomP isoG). rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS. rewrite /inertia !setIdE morphimIdom setIA -{1}defS -injm_norm ?injmI //. apply/setP=> gy /[!inE]; apply: andb_id2l => /morphimP[y Gy nHy ->] {gy}. rewrite cfConjgIsom // -sub1set -morphim_set1 // injmSK ?sub1set //= inE. apply/eqP/eqP=> [Iphi_y | -> //]. by apply/cfun_inP=> x Hx; rewrite -!(cfIsomE isoH) ?Iphi_y. Qed. End ConjMorph. Section ConjQuotient. Variables gT : finGroupType. Implicit Types G H K : {group gT}. Lemma cfConjgMod_norm H K (phi : 'CF(H / K)) y : y \in 'N(K) -> y \in 'N(H) -> ((phi %% K) ^ y)%CF = (phi ^ coset K y %% K)%CF. Proof. exact: cfConjgMorph. Qed. Lemma cfConjgMod G H K (phi : 'CF(H / K)) y : H <| G -> K <| G -> y \in G -> ((phi %% K) ^ y)%CF = (phi ^ coset K y %% K)%CF. Proof. move=> /andP[_ nHG] /andP[_ nKG] Gy. by rewrite cfConjgMod_norm ?(subsetP nHG) ?(subsetP nKG). Qed. Lemma cfConjgQuo_norm H K (phi : 'CF(H)) y : y \in 'N(K) -> y \in 'N(H) -> ((phi / K) ^ coset K y)%CF = (phi ^ y / K)%CF. Proof. move=> nKy nHy; have keryK: (K \subset cfker (phi ^ y)) = (K \subset cfker phi). by rewrite cfker_conjg // -{1}(normP nKy) conjSg. have [kerK | not_kerK] := boolP (K \subset cfker phi); last first. by rewrite !cfQuoEout ?rmorph_alg ?cfConjg1 ?keryK. apply/cfun_inP=> _ /morphimP[x nKx Hx ->]. have nHyb: coset K y \in 'N(H / K) by rewrite inE -morphimJ ?(normP nHy). rewrite !(cfConjgE, cfQuoEnorm) ?keryK // ?in_setI ?Hx //. rewrite -morphV -?morphJ ?groupV // cfQuoEnorm //. by rewrite inE memJ_norm ?Hx ?groupJ ?groupV. Qed. Lemma cfConjgQuo G H K (phi : 'CF(H)) y : H <| G -> K <| G -> y \in G -> ((phi / K) ^ coset K y)%CF = (phi ^ y / K)%CF. Proof. move=> /andP[_ nHG] /andP[_ nKG] Gy. by rewrite cfConjgQuo_norm ?(subsetP nHG) ?(subsetP nKG). Qed. Lemma inertia_mod_pre G H K (phi : 'CF(H / K)) : H <| G -> K <| G -> 'I_G[phi %% K] = G :&: coset K @*^-1 'I_(G / K)[phi]. Proof. by move=> nsHG /andP[_]; apply: inertia_morph_pre. Qed. Lemma inertia_mod_quo G H K (phi : 'CF(H / K)) : H <| G -> K <| G -> ('I_G[phi %% K] / K)%g = 'I_(G / K)[phi]. Proof. by move=> nsHG /andP[_]; apply: inertia_morph_im. Qed. Lemma inertia_quo G H K (phi : 'CF(H)) : H <| G -> K <| G -> K \subset cfker phi -> 'I_(G / K)[phi / K] = ('I_G[phi] / K)%g. Proof. move=> nsHG nsKG kerK; rewrite -inertia_mod_quo ?cfQuoK //. by rewrite (normalS _ (normal_sub nsHG)) // (subset_trans _ (cfker_sub phi)). Qed. End ConjQuotient. Section InertiaSdprod. Variables (gT : finGroupType) (K H G : {group gT}). Hypothesis defG : K ><| H = G. Lemma cfConjgSdprod phi y : y \in 'N(K) -> y \in 'N(H) -> (cfSdprod defG phi ^ y = cfSdprod defG (phi ^ y))%CF. Proof. move=> nKy nHy. have nGy: y \in 'N(G) by rewrite -sub1set -(sdprodW defG) normsM ?sub1set. rewrite -{2}[phi](cfSdprodK defG) cfConjgRes_norm // cfRes_sdprodK //. by rewrite cfker_conjg // -{1}(normP nKy) conjSg cfker_sdprod. Qed. Lemma inertia_sdprod (L : {group gT}) phi : L \subset 'N(K) -> L \subset 'N(H) -> 'I_L[cfSdprod defG phi] = 'I_L[phi]. Proof. move=> nKL nHL; have nGL: L \subset 'N(G) by rewrite -(sdprodW defG) normsM. apply/setP=> z; rewrite !in_setI ![z \in 'I[_]]inE; apply: andb_id2l => Lz. rewrite cfConjgSdprod ?(subsetP nKL) ?(subsetP nHL) ?(subsetP nGL) //=. by rewrite (can_eq (cfSdprodK defG)). Qed. End InertiaSdprod. Section InertiaDprod. Variables (gT : finGroupType) (G K H : {group gT}). Implicit Type L : {group gT}. Hypothesis KxH : K \x H = G. Lemma cfConjgDprodl phi y : y \in 'N(K) -> y \in 'N(H) -> (cfDprodl KxH phi ^ y = cfDprodl KxH (phi ^ y))%CF. Proof. by move=> nKy nHy; apply: cfConjgSdprod. Qed. Lemma cfConjgDprodr psi y : y \in 'N(K) -> y \in 'N(H) -> (cfDprodr KxH psi ^ y = cfDprodr KxH (psi ^ y))%CF. Proof. by move=> nKy nHy; apply: cfConjgSdprod. Qed. Lemma cfConjgDprod phi psi y : y \in 'N(K) -> y \in 'N(H) -> (cfDprod KxH phi psi ^ y = cfDprod KxH (phi ^ y) (psi ^ y))%CF. Proof. by move=> nKy nHy; rewrite rmorphM /= cfConjgDprodl ?cfConjgDprodr. Qed. Lemma inertia_dprodl L phi : L \subset 'N(K) -> L \subset 'N(H) -> 'I_L[cfDprodl KxH phi] = 'I_L[phi]. Proof. by move=> nKL nHL; apply: inertia_sdprod. Qed. Lemma inertia_dprodr L psi : L \subset 'N(K) -> L \subset 'N(H) -> 'I_L[cfDprodr KxH psi] = 'I_L[psi]. Proof. by move=> nKL nHL; apply: inertia_sdprod. Qed. Lemma inertia_dprod L (phi : 'CF(K)) (psi : 'CF(H)) : L \subset 'N(K) -> L \subset 'N(H) -> phi 1%g != 0 -> psi 1%g != 0 -> 'I_L[cfDprod KxH phi psi] = 'I_L[phi] :&: 'I_L[psi]. Proof. move=> nKL nHL nz_phi nz_psi; apply/eqP; rewrite eqEsubset subsetI. rewrite -{1}(inertia_scale_nz psi nz_phi) -{1}(inertia_scale_nz phi nz_psi). rewrite -(cfDprod_Resl KxH) -(cfDprod_Resr KxH) !sub_inertia_Res //=. by rewrite -inertia_dprodl -?inertia_dprodr // -setIIr setIS ?inertia_mul. Qed. Lemma inertia_dprod_irr L i j : L \subset 'N(K) -> L \subset 'N(H) -> 'I_L[cfDprod KxH 'chi_i 'chi_j] = 'I_L['chi_i] :&: 'I_L['chi_j]. Proof. by move=> nKL nHL; rewrite inertia_dprod ?irr1_neq0. Qed. End InertiaDprod. Section InertiaBigdprod. Variables (gT : finGroupType) (I : finType) (P : pred I). Variables (A : I -> {group gT}) (G : {group gT}). Implicit Type L : {group gT}. Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G. Section ConjBig. Variable y : gT. Hypothesis nAy: forall i, P i -> y \in 'N(A i). Lemma cfConjgBigdprodi i (phi : 'CF(A i)) : (cfBigdprodi defG phi ^ y = cfBigdprodi defG (phi ^ y))%CF. Proof. rewrite cfConjgDprodl; try by case: ifP => [/nAy// | _]; rewrite norm1 inE. congr (cfDprodl _ _); case: ifP => [Pi | _]. by rewrite cfConjgRes_norm ?nAy. by apply/cfun_inP=> _ /set1P->; rewrite !(cfRes1, cfConjg1). rewrite -sub1set norms_gen ?norms_bigcup // sub1set. by apply/bigcapP=> j /andP[/nAy]. Qed. Lemma cfConjgBigdprod phi : (cfBigdprod defG phi ^ y = cfBigdprod defG (fun i => phi i ^ y))%CF. Proof. by rewrite rmorph_prod /=; apply: eq_bigr => i _; apply: cfConjgBigdprodi. Qed. End ConjBig. Section InertiaBig. Variable L : {group gT}. Hypothesis nAL : forall i, P i -> L \subset 'N(A i). Lemma inertia_bigdprodi i (phi : 'CF(A i)) : P i -> 'I_L[cfBigdprodi defG phi] = 'I_L[phi]. Proof. move=> Pi; rewrite inertia_dprodl ?Pi ?cfRes_id ?nAL //. by apply/norms_gen/norms_bigcup/bigcapsP=> j /andP[/nAL]. Qed. Lemma inertia_bigdprod phi (Phi := cfBigdprod defG phi) : Phi 1%g != 0 -> 'I_L[Phi] = L :&: \bigcap_(i | P i) 'I_L[phi i]. Proof. move=> nz_Phi; apply/eqP; rewrite eqEsubset; apply/andP; split. rewrite subsetI Inertia_sub; apply/bigcapsP=> i Pi. have [] := cfBigdprodK nz_Phi Pi; move: (_ / _) => a nz_a <-. by rewrite inertia_scale_nz ?sub_inertia_Res //= ?nAL. rewrite subsetI subsetIl; apply: subset_trans (inertia_prod _ _ _). apply: setISS. by rewrite -(bigdprodWY defG) norms_gen ?norms_bigcup //; apply/bigcapsP. apply/bigcapsP=> i Pi; rewrite (bigcap_min i) //. by rewrite -inertia_bigdprodi ?subsetIr. Qed. Lemma inertia_bigdprod_irr Iphi (phi := fun i => 'chi_(Iphi i)) : 'I_L[cfBigdprod defG phi] = L :&: \bigcap_(i | P i) 'I_L[phi i]. Proof. rewrite inertia_bigdprod // -[cfBigdprod _ _]cfIirrE ?irr1_neq0 //. by apply: cfBigdprod_irr => i _; apply: mem_irr. Qed. End InertiaBig. End InertiaBigdprod. Section ConsttInertiaBijection. Variables (gT : finGroupType) (H G : {group gT}) (t : Iirr H). Hypothesis nsHG : H <| G. Local Notation theta := 'chi_t. Local Notation T := 'I_G[theta]%G. Local Notation "` 'T'" := 'I_(gval G)[theta] (format "` 'T'") : group_scope. Let calA := irr_constt ('Ind[T] theta). Let calB := irr_constt ('Ind[G] theta). Local Notation AtoB := (Ind_Iirr G). (* This is Isaacs, Theorem (6.11). *) Theorem constt_Inertia_bijection : [/\ (*a*) {in calA, forall s, 'Ind[G] 'chi_s \in irr G}, (*b*) {in calA &, injective (Ind_Iirr G)}, Ind_Iirr G @: calA =i calB, (*c*) {in calA, forall s (psi := 'chi_s) (chi := 'Ind[G] psi), [predI irr_constt ('Res chi) & calA] =i pred1 s} & (*d*) {in calA, forall s (psi := 'chi_s) (chi := 'Ind[G] psi), '['Res psi, theta] = '['Res chi, theta]}]. Proof. have [sHG sTG]: H \subset G /\ T \subset G by rewrite subsetIl normal_sub. have nsHT : H <| T := normal_Inertia theta sHG; have sHT := normal_sub nsHT. have AtoB_P s (psi := 'chi_s) (chi := 'Ind[G] psi): s \in calA -> [/\ chi \in irr G, AtoB s \in calB & '['Res psi, theta] = '['Res chi, theta]]. - rewrite constt_Ind_Res => sHt; have [r sGr] := constt_cfInd_irr s sTG. rewrite constt_Ind_Res. have rTs: s \in irr_constt ('Res[T] 'chi_r) by rewrite -constt_Ind_Res. have NrT: 'Res[T] 'chi_r \is a character by rewrite cfRes_char ?irr_char. have rHt: t \in irr_constt ('Res[H] 'chi_r). by have:= constt_Res_trans NrT rTs sHt; rewrite cfResRes. pose e := '['Res[H] 'chi_r, theta]; set f := '['Res[H] psi, theta]. have DrH: 'Res[H] 'chi_r = e *: \sum_(xi <- (theta ^: G)%CF) xi. exact: Clifford_Res_sum_cfclass. have DpsiH: 'Res[H] psi = f *: theta. rewrite (Clifford_Res_sum_cfclass nsHT sHt). by rewrite cfclass_invariant ?subsetIr ?big_seq1. have ub_chi_r: 'chi_r 1%g <= chi 1%g ?= iff ('chi_r == chi). have Nchi: chi \is a character by rewrite cfInd_char ?irr_char. have [chi1 Nchi1->] := constt_charP _ Nchi sGr. rewrite addrC cfunE -leifBLR subrr eq_sym -subr_eq0 addrK. by split; rewrite ?char1_ge0 // eq_sym char1_eq0. have lb_chi_r: chi 1%g <= 'chi_r 1%g ?= iff (f == e). rewrite cfInd1 // -(cfRes1 H) DpsiH -(cfRes1 H 'chi_r) DrH !cfunE sum_cfunE. rewrite (eq_big_seq (fun _ => theta 1%g)) => [|i]; last first. by case/cfclassP=> y _ ->; rewrite cfConjg1. rewrite reindex_cfclass //= sumr_const -(eq_card (cfclass_IirrE _ _)). rewrite mulr_natl mulrnAr card_cfclass_Iirr //. rewrite (mono_leif (ler_pMn2r (indexg_gt0 G T))). rewrite (mono_leif (ler_pM2r (irr1_gt0 t))); apply: leif_eq. by rewrite /e -(cfResRes _ sHT) ?cfdot_Res_ge_constt. have [_ /esym] := leif_trans ub_chi_r lb_chi_r; rewrite eqxx. by case/andP=> /eqP Dchi /eqP->; rewrite cfIirrE -/chi -?Dchi ?mem_irr. have part_c: {in calA, forall s (chi := 'Ind[G] 'chi_s), [predI irr_constt ('Res[T] chi) & calA] =i pred1 s}. - move=> s As chi s1; have [irr_chi _ /eqP Dchi_theta] := AtoB_P s As. have chiTs: s \in irr_constt ('Res[T] chi). by rewrite irr_consttE cfdot_Res_l irrWnorm ?oner_eq0. apply/andP/eqP=> [[/= chiTs1 As1] | -> //]. apply: contraTeq Dchi_theta => s's1; rewrite lt_eqF // -/chi. have [|phi Nphi DchiT] := constt_charP _ _ chiTs. by rewrite cfRes_char ?cfInd_char ?irr_char. have [|phi1 Nphi1 Dphi] := constt_charP s1 Nphi _. rewrite irr_consttE -(canLR (addKr _) DchiT) addrC cfdotBl cfdot_irr. by rewrite mulrb ifN_eqC ?subr0. rewrite -(cfResRes chi sHT sTG) DchiT Dphi !rmorphD !cfdotDl /=. rewrite -ltrBDl subrr ltr_wpDr ?lt_def //; rewrite natr_ge0 ?Cnat_cfdot_char ?cfRes_char ?irr_char //. by rewrite andbT -irr_consttE -constt_Ind_Res. do [split=> //; try by move=> s /AtoB_P[]] => [s1 s2 As1 As2 | r]. have [[irr_s1G _ _] [irr_s2G _ _]] := (AtoB_P _ As1, AtoB_P _ As2). move/(congr1 (tnth (irr G))); rewrite !cfIirrE // => eq_s12_G. apply/eqP; rewrite -[_ == _]part_c // inE /= As1 -eq_s12_G. by rewrite -As1 [_ && _]part_c // inE /=. apply/imsetP/idP=> [[s /AtoB_P[_ BsG _] -> //] | Br]. have /exists_inP[s rTs As]: [exists s in irr_constt ('Res 'chi_r), s \in calA]. rewrite -negb_forall_in; apply: contra Br => /eqfun_inP => o_tT_rT. rewrite -(cfIndInd _ sTG sHT) -cfdot_Res_r ['Res _]cfun_sum_constt. by rewrite cfdot_sumr big1 // => i rTi; rewrite cfdotZr o_tT_rT ?mulr0. exists s => //; have [/irrP[r1 DsG] _ _] := AtoB_P s As. by apply/eqP; rewrite /AtoB -constt_Ind_Res DsG irrK constt_irr in rTs *. Qed. End ConsttInertiaBijection. Section ExtendInvariantIrr. Variable gT : finGroupType. Implicit Types G H K L M N : {group gT}. Section ConsttIndExtendible. Variables (G N : {group gT}) (t : Iirr N) (c : Iirr G). Let theta := 'chi_t. Let chi := 'chi_c. Definition mul_Iirr b := cfIirr ('chi_b * chi). Definition mul_mod_Iirr (b : Iirr (G / N)) := mul_Iirr (mod_Iirr b). Hypotheses (nsNG : N <| G) (cNt : 'Res[N] chi = theta). Let sNG : N \subset G. Proof. exact: normal_sub. Qed. Let nNG : G \subset 'N(N). Proof. exact: normal_norm. Qed. Lemma extendible_irr_invariant : G \subset 'I[theta]. Proof. apply/subsetP=> y Gy; have nNy := subsetP nNG y Gy. rewrite inE nNy; apply/eqP/cfun_inP=> x Nx; rewrite cfConjgE // -cNt. by rewrite !cfResE ?memJ_norm ?cfunJ ?groupV. Qed. Let IGtheta := extendible_irr_invariant. (* This is Isaacs, Theorem (6.16) *) Theorem constt_Ind_mul_ext f (phi := 'chi_f) (psi := phi * theta) : G \subset 'I[phi] -> psi \in irr N -> let calS := irr_constt ('Ind phi) in [/\ {in calS, forall b, 'chi_b * chi \in irr G}, {in calS &, injective mul_Iirr}, irr_constt ('Ind psi) =i [seq mul_Iirr b | b in calS] & 'Ind psi = \sum_(b in calS) '['Ind phi, 'chi_b] *: 'chi_(mul_Iirr b)]. Proof. move=> IGphi irr_psi calS. have IGpsi: G \subset 'I[psi]. by rewrite (subset_trans _ (inertia_mul _ _)) // subsetI IGphi. pose e b := '['Ind[G] phi, 'chi_b]; pose d b g := '['chi_b * chi, 'chi_g * chi]. have Ne b: e b \in Num.nat by rewrite Cnat_cfdot_char ?cfInd_char ?irr_char. have egt0 b: b \in calS -> e b > 0 by rewrite natr_gt0. have DphiG: 'Ind phi = \sum_(b in calS) e b *: 'chi_b := cfun_sum_constt _. have DpsiG: 'Ind psi = \sum_(b in calS) e b *: 'chi_b * chi. by rewrite /psi -cNt cfIndM // DphiG mulr_suml. pose d_delta := [forall b in calS, forall g in calS, d b g == (b == g)%:R]. have charMchi b: 'chi_b * chi \is a character by rewrite rpredM ?irr_char. have [_]: '['Ind[G] phi] <= '['Ind[G] psi] ?= iff d_delta. pose sum_delta := \sum_(b in calS) e b * \sum_(g in calS) e g * (b == g)%:R. pose sum_d := \sum_(b in calS) e b * \sum_(g in calS) e g * d b g. have ->: '['Ind[G] phi] = sum_delta. rewrite DphiG cfdot_suml; apply: eq_bigr => b _; rewrite cfdotZl cfdot_sumr. by congr (_ * _); apply: eq_bigr => g; rewrite cfdotZr cfdot_irr conj_natr. have ->: '['Ind[G] psi] = sum_d. rewrite DpsiG cfdot_suml; apply: eq_bigr => b _. rewrite -scalerAl cfdotZl cfdot_sumr; congr (_ * _). by apply: eq_bigr => g _; rewrite -scalerAl cfdotZr conj_natr. have eMmono := mono_leif (ler_pM2l (egt0 _ _)). apply: leif_sum => b /eMmono->; apply: leif_sum => g /eMmono->. split; last exact: eq_sym. have /natrP[n Dd]: d b g \in Num.nat by rewrite Cnat_cfdot_char. have [Db | _] := eqP; rewrite Dd leC_nat // -ltC_nat -Dd Db cfnorm_gt0. by rewrite -char1_eq0 // cfunE mulf_neq0 ?irr1_neq0. rewrite -!cfdot_Res_l ?cfRes_Ind_invariant // !cfdotZl cfnorm_irr irrWnorm //. rewrite eqxx => /esym/forall_inP/(_ _ _)/eqfun_inP; rewrite /d /= => Dd. have irrMchi: {in calS, forall b, 'chi_b * chi \in irr G}. by move=> b Sb; rewrite /= irrEchar charMchi Dd ?eqxx. have injMchi: {in calS &, injective mul_Iirr}. move=> b g Sb Sg /(congr1 (fun s => '['chi_s, 'chi_(mul_Iirr g)]))/eqP. by rewrite cfnorm_irr !cfIirrE ?irrMchi ?Dd // pnatr_eq1; case: (b =P g). have{DpsiG} ->: 'Ind psi = \sum_(b in calS) e b *: 'chi_(mul_Iirr b). by rewrite DpsiG; apply: eq_bigr => b Sb; rewrite -scalerAl cfIirrE ?irrMchi. split=> // i; rewrite irr_consttE cfdot_suml; apply/idP/idP=> [|/imageP[b Sb ->]]. apply: contraR => N'i; rewrite big1 // => b Sb. rewrite cfdotZl cfdot_irr mulrb ifN_eqC ?mulr0 //. by apply: contraNneq N'i => ->; apply: image_f. rewrite gt_eqF // (bigD1 b) //= cfdotZl cfnorm_irr mulr1 ltr_wpDr ?egt0 //. apply: sumr_ge0 => g /andP[Sg _]; rewrite cfdotZl cfdot_irr. by rewrite mulr_ge0 ?ler0n ?natr_ge0. Qed. (* This is Isaacs, Corollary (6.17) (due to Gallagher). *) Corollary constt_Ind_ext : [/\ forall b : Iirr (G / N), 'chi_(mod_Iirr b) * chi \in irr G, injective mul_mod_Iirr, irr_constt ('Ind theta) =i codom mul_mod_Iirr & 'Ind theta = \sum_b 'chi_b 1%g *: 'chi_(mul_mod_Iirr b)]. Proof. have IHchi0: G \subset 'I['chi[N]_0] by rewrite inertia_irr0. have [] := constt_Ind_mul_ext IHchi0; rewrite irr0 ?mul1r ?mem_irr //. set psiG := 'Ind 1 => irrMchi injMchi constt_theta {2}->. have dot_psiG b: '[psiG, 'chi_(mod_Iirr b)] = 'chi[G / N]_b 1%g. rewrite mod_IirrE // -cfdot_Res_r cfRes_sub_ker ?cfker_mod //. by rewrite cfdotZr cfnorm1 mulr1 conj_natr ?cfMod1 ?Cnat_irr1. have mem_psiG (b : Iirr (G / N)): mod_Iirr b \in irr_constt psiG. by rewrite irr_consttE dot_psiG irr1_neq0. have constt_psiG b: (b \in irr_constt psiG) = (N \subset cfker 'chi_b). apply/idP/idP=> [psiGb | /quo_IirrK <- //]. by rewrite constt0_Res_cfker // -constt_Ind_Res irr0. split=> [b | b g /injMchi/(can_inj (mod_IirrK nsNG))-> // | b0 | ]. - exact: irrMchi. - rewrite constt_theta. apply/imageP/imageP=> [][b psiGb ->]; last by exists (mod_Iirr b). by exists (quo_Iirr N b) => //; rewrite /mul_mod_Iirr quo_IirrK -?constt_psiG. rewrite (reindex_onto _ _ (in1W (mod_IirrK nsNG))) /=. apply/esym/eq_big => b; first by rewrite constt_psiG quo_IirrKeq. by rewrite -dot_psiG /mul_mod_Iirr => /eqP->. Qed. End ConsttIndExtendible. (* This is Isaacs, Theorem (6.19). *) Theorem invariant_chief_irr_cases G K L s (theta := 'chi[K]_s) : chief_factor G L K -> abelian (K / L) -> G \subset 'I[theta] -> let t := #|K : L| in [\/ 'Res[L] theta \in irr L, exists2 e, exists p, 'Res[L] theta = e%:R *: 'chi_p & (e ^ 2)%N = t | exists2 p, injective p & 'Res[L] theta = \sum_(i < t) 'chi_(p i)]. Proof. case/andP=> /maxgroupP[/andP[ltLK nLG] maxL] nsKG abKbar IGtheta t. have [sKG nKG] := andP nsKG; have sLG := subset_trans (proper_sub ltLK) sKG. have nsLG: L <| G by apply/andP. have nsLK := normalS (proper_sub ltLK) sKG nsLG; have [sLK nLK] := andP nsLK. have [p0 sLp0] := constt_cfRes_irr L s; rewrite -/theta in sLp0. pose phi := 'chi_p0; pose T := 'I_G[phi]. have sTG: T \subset G := subsetIl G _. have /eqP mulKT: (K * T)%g == G. rewrite eqEcard mulG_subG sKG sTG -LagrangeMr -indexgI -(Lagrange sTG) /= -/T. rewrite mulnC leq_mul // setIA (setIidPl sKG) -!size_cfclass // -/phi. rewrite uniq_leq_size ?cfclass_uniq // => _ /cfclassP[x Gx ->]. have: conjg_Iirr p0 x \in irr_constt ('Res theta). have /inertiaJ <-: x \in 'I[theta] := subsetP IGtheta x Gx. by rewrite -(cfConjgRes _ nsKG) // irr_consttE conjg_IirrE // cfConjg_iso. apply: contraR; rewrite -conjg_IirrE // => not_sLp0x. rewrite (Clifford_Res_sum_cfclass nsLK sLp0) cfdotZl cfdot_suml. rewrite big1_seq ?mulr0 // => _ /cfclassP[y Ky ->]; rewrite -conjg_IirrE //. rewrite cfdot_irr mulrb ifN_eq ?(contraNneq _ not_sLp0x) // => <-. by rewrite conjg_IirrE //; apply/cfclassP; exists y. have nsKT_G: K :&: T <| G. rewrite /normal subIset ?sKG // -mulKT setIA (setIidPl sKG) mulG_subG. rewrite normsIG // sub_der1_norm ?subsetIl //. exact: subset_trans (der1_min nLK abKbar) (sub_Inertia _ sLK). have [e DthL]: exists e, 'Res theta = e%:R *: \sum_(xi <- (phi ^: K)%CF) xi. rewrite (Clifford_Res_sum_cfclass nsLK sLp0) -/phi; set e := '[_, _]. exists (Num.truncn e). by rewrite truncnK ?Cnat_cfdot_char ?cfRes_char ?irr_char. have [defKT | ltKT_K] := eqVneq (K :&: T) K; last first. have defKT: K :&: T = L. apply: maxL; last by rewrite subsetI sLK sub_Inertia. by rewrite normal_norm // properEneq ltKT_K subsetIl. have t_cast: size (phi ^: K)%CF = t. by rewrite size_cfclass //= -{2}(setIidPl sKG) -setIA defKT. pose phiKt := Tuple (introT eqP t_cast); pose p i := cfIirr (tnth phiKt i). have pK i: 'chi_(p i) = (phi ^: K)%CF`_i. rewrite cfIirrE; first by rewrite (tnth_nth 0). by have /cfclassP[y _ ->] := mem_tnth i phiKt; rewrite cfConjg_irr ?mem_irr. constructor 3; exists p => [i j /(congr1 (tnth (irr L)))/eqP| ]. by apply: contraTeq; rewrite !pK !nth_uniq ?t_cast ?cfclass_uniq. have{} DthL: 'Res theta = e%:R *: \sum_(i < t) (phi ^: K)%CF`_i. by rewrite DthL (big_nth 0) big_mkord t_cast. suffices /eqP e1: e == 1 by rewrite DthL e1 scale1r; apply: eq_bigr. have Dth1: theta 1%g = e%:R * t%:R * phi 1%g. rewrite -[t]card_ord -mulrA -(cfRes1 L) DthL cfunE; congr (_ * _). rewrite mulr_natl -sumr_const sum_cfunE -t_cast; apply: eq_bigr => i _. by have /cfclassP[y _ ->] := mem_nth 0 (valP i); rewrite cfConjg1. rewrite eqn_leq lt0n (contraNneq _ (irr1_neq0 s)); last first. by rewrite Dth1 => ->; rewrite !mul0r. rewrite -leC_nat -(ler_pM2r (gt0CiG K L)) -/t -(ler_pM2r (irr1_gt0 p0)). rewrite mul1r -Dth1 -cfInd1 //. by rewrite char1_ge_constt ?cfInd_char ?irr_char ?constt_Ind_Res. have IKphi: 'I_K[phi] = K by rewrite -{1}(setIidPl sKG) -setIA. have{} DthL: 'Res[L] theta = e%:R *: phi. by rewrite DthL -[rhs in (_ ^: rhs)%CF]IKphi cfclass_inertia big_seq1. pose mmLth := @mul_mod_Iirr K L s. have linKbar := char_abelianP _ abKbar. have LmodL i: ('chi_i %% L)%CF \is a linear_char := cfMod_lin_char (linKbar i). have mmLthE i: 'chi_(mmLth i) = ('chi_i %% L)%CF * theta. by rewrite cfIirrE ?mod_IirrE // mul_lin_irr ?mem_irr. have mmLthL i: 'Res[L] 'chi_(mmLth i) = 'Res[L] theta. rewrite mmLthE rmorphM /= cfRes_sub_ker ?cfker_mod ?lin_char1 //. by rewrite scale1r mul1r. have [inj_Mphi | /injectivePn[i [j i'j eq_mm_ij]]] := boolP (injectiveb mmLth). suffices /eqP e1: e == 1 by constructor 1; rewrite DthL e1 scale1r mem_irr. rewrite eqn_leq lt0n (contraNneq _ (irr1_neq0 s)); last first. by rewrite -(cfRes1 L) DthL cfunE => ->; rewrite !mul0r. rewrite -leq_sqr -leC_nat natrX -(ler_pM2r (irr1_gt0 p0)) -mulrA mul1r. have ->: e%:R * 'chi_p0 1%g = 'Res[L] theta 1%g by rewrite DthL cfunE. rewrite cfRes1 -(ler_pM2l (gt0CiG K L)) -cfInd1 // -/phi. rewrite -card_quotient // -card_Iirr_abelian // mulr_natl. rewrite ['Ind phi]cfun_sum_cfdot sum_cfunE (bigID [in codom mmLth]) /=. rewrite ler_wpDr ?sumr_ge0 // => [i _|]. by rewrite char1_ge0 ?rpredZ_nat ?Cnat_cfdot_char ?cfInd_char ?irr_char. rewrite -big_uniq //= big_image -sumr_const ler_sum // => i _. rewrite cfunE -[in leRHS](cfRes1 L) -cfdot_Res_r mmLthL cfRes1. by rewrite DthL cfdotZr rmorph_nat cfnorm_irr mulr1. constructor 2; exists e; first by exists p0. pose mu := (('chi_i / 'chi_j)%R %% L)%CF; pose U := cfker mu. have lin_mu: mu \is a linear_char by rewrite cfMod_lin_char ?rpred_div. have Uj := lin_char_unitr (linKbar j). have ltUK: U \proper K. rewrite /proper cfker_sub /U; have /irrP[k Dmu] := lin_char_irr lin_mu. rewrite Dmu subGcfker -irr_eq1 -Dmu cfMod_eq1 //. by rewrite (can2_eq (divrK Uj) (mulrK Uj)) mul1r (inj_eq irr_inj). suffices: theta \in 'CF(K, L). rewrite -cfnorm_Res_leif // DthL cfnormZ !cfnorm_irr !mulr1 normr_nat. by rewrite -natrX eqC_nat => /eqP. have <-: gcore U G = L. apply: maxL; last by rewrite sub_gcore ?cfker_mod. by rewrite gcore_norm (sub_proper_trans (gcore_sub _ _)). apply/cfun_onP=> x; apply: contraNeq => nz_th_x. apply/bigcapP=> y /(subsetP IGtheta)/setIdP[nKy /eqP th_y]. apply: contraR nz_th_x; rewrite mem_conjg -{}th_y cfConjgE {nKy}//. move: {x y}(x ^ _) => x U'x; have [Kx | /cfun0-> //] := boolP (x \in K). have /eqP := congr1 (fun k => (('chi_j %% L)%CF^-1 * 'chi_k) x) eq_mm_ij. rewrite -rmorphV // !mmLthE !mulrA -!rmorphM mulVr // rmorph1 !cfunE. rewrite (mulrC _^-1) -/mu -subr_eq0 -mulrBl cfun1E Kx mulf_eq0 => /orP[]//. rewrite mulrb subr_eq0 -(lin_char1 lin_mu) [_ == _](contraNF _ U'x) //. by rewrite /U cfkerEchar ?lin_charW // inE Kx. Qed. (* This is Isaacs, Corollary (6.19). *) Corollary cfRes_prime_irr_cases G N s p (chi := 'chi[G]_s) : N <| G -> #|G : N| = p -> prime p -> [\/ 'Res[N] chi \in irr N | exists2 c, injective c & 'Res[N] chi = \sum_(i < p) 'chi_(c i)]. Proof. move=> /andP[sNG nNG] iGN pr_p. have chiefGN: chief_factor G N G. apply/andP; split=> //; apply/maxgroupP. split=> [|M /andP[/andP[sMG ltMG] _] sNM]. by rewrite /proper sNG -indexg_gt1 iGN prime_gt1. apply/esym/eqP; rewrite eqEsubset sNM -indexg_eq1 /= eq_sym. rewrite -(eqn_pmul2l (indexg_gt0 G M)) muln1 Lagrange_index // iGN. by apply/eqP/prime_nt_dvdP; rewrite ?indexg_eq1 // -iGN indexgS. have abGbar: abelian (G / N). by rewrite cyclic_abelian ?prime_cyclic ?card_quotient ?iGN. have IGchi: G \subset 'I[chi] by apply: sub_inertia. have [] := invariant_chief_irr_cases chiefGN abGbar IGchi; first by left. case=> e _ /(congr1 (fun m => odd (logn p m)))/eqP/idPn[]. by rewrite lognX mul2n odd_double iGN logn_prime // eqxx. by rewrite iGN; right. Qed. (* This is Isaacs, Corollary (6.20). *) Corollary prime_invariant_irr_extendible G N s p : N <| G -> #|G : N| = p -> prime p -> G \subset 'I['chi_s] -> {t | 'Res[N, G] 'chi_t = 'chi_s}. Proof. move=> nsNG iGN pr_p IGchi. have [t sGt] := constt_cfInd_irr s (normal_sub nsNG); exists t. have [e DtN]: exists e, 'Res 'chi_t = e%:R *: 'chi_s. rewrite constt_Ind_Res in sGt. rewrite (Clifford_Res_sum_cfclass nsNG sGt) cfclass_invariant // big_seq1. set e := '[_, _]; exists (Num.truncn e). by rewrite truncnK ?Cnat_cfdot_char ?cfRes_char ?irr_char. have [/irrWnorm/eqP | [c injc DtNc]] := cfRes_prime_irr_cases t nsNG iGN pr_p. rewrite DtN cfnormZ cfnorm_irr normr_nat mulr1 -natrX pnatr_eq1. by rewrite muln_eq1 andbb => /eqP->; rewrite scale1r. have nz_e: e != 0. have: 'Res[N] 'chi_t != 0 by rewrite cfRes_eq0 // ?irr_char ?irr_neq0. by rewrite DtN; apply: contraNneq => ->; rewrite scale0r. have [i s'ci]: exists i, c i != s. pose i0 := Ordinal (prime_gt0 pr_p); pose i1 := Ordinal (prime_gt1 pr_p). have [<- | ] := eqVneq (c i0) s; last by exists i0. by exists i1; rewrite (inj_eq injc). have /esym/eqP/idPn[] := congr1 (cfdotr 'chi_(c i)) DtNc; rewrite {1}DtN /=. rewrite cfdot_suml cfdotZl cfdot_irr mulrb ifN_eqC // mulr0. rewrite (bigD1 i) //= cfnorm_irr big1 ?addr0 ?oner_eq0 // => j i'j. by rewrite cfdot_irr mulrb ifN_eq ?(inj_eq injc). Qed. (* This is Isaacs, Lemma (6.24). *) Lemma extend_to_cfdet G N s c0 u : let theta := 'chi_s in let lambda := cfDet theta in let mu := 'chi_u in N <| G -> coprime #|G : N| (Num.truncn (theta 1%g)) -> 'Res[N, G] 'chi_c0 = theta -> 'Res[N, G] mu = lambda -> exists2 c, 'Res 'chi_c = theta /\ cfDet 'chi_c = mu & forall c1, 'Res 'chi_c1 = theta -> cfDet 'chi_c1 = mu -> c1 = c. Proof. move=> theta lambda mu nsNG; set e := #|G : N|; set f := Num.truncn _. set eta := 'chi_c0 => co_e_f etaNth muNlam; have [sNG nNG] := andP nsNG. have fE: f%:R = theta 1%g by rewrite truncnK ?Cnat_irr1. pose nu := cfDet eta; have lin_nu: nu \is a linear_char := cfDet_lin_char _. have nuNlam: 'Res nu = lambda by rewrite -cfDetRes ?irr_char ?etaNth. have lin_lam: lambda \is a linear_char := cfDet_lin_char _. have lin_mu: mu \is a linear_char. by have:= lin_lam; rewrite -muNlam; apply: cfRes_lin_lin; apply: irr_char. have [Unu Ulam] := (lin_char_unitr lin_nu, lin_char_unitr lin_lam). pose alpha := mu / nu. have alphaN_1: 'Res[N] alpha = 1 by rewrite rmorph_div //= muNlam nuNlam divrr. have lin_alpha: alpha \is a linear_char by apply: rpred_div. have alpha_e: alpha ^+ e = 1. have kerNalpha: N \subset cfker alpha. by rewrite -subsetIidl -cfker_Res ?lin_charW // alphaN_1 cfker_cfun1. apply/eqP; rewrite -(cfQuoK nsNG kerNalpha) -rmorphXn cfMod_eq1 //. rewrite -dvdn_cforder /e -card_quotient //. by rewrite cforder_lin_char_dvdG ?cfQuo_lin_char. have det_alphaXeta b: cfDet (alpha ^+ b * eta) = alpha ^+ (b * f) * nu. by rewrite cfDet_mul_lin ?rpredX ?irr_char // -exprM -(cfRes1 N) etaNth. have [b bf_mod_e]: exists b, b * f = 1 %[mod e]. rewrite -(chinese_modl co_e_f 1 0) /chinese !mul0n addn0 !mul1n mulnC. by exists (egcdn f e).1. have alpha_bf: alpha ^+ (b * f) = alpha. by rewrite -(expr_mod _ alpha_e) bf_mod_e expr_mod. have /irrP[c Dc]: alpha ^+ b * eta \in irr G. by rewrite mul_lin_irr ?rpredX ?mem_irr. have chiN: 'Res 'chi_c = theta. by rewrite -Dc rmorphM rmorphXn /= alphaN_1 expr1n mul1r. have det_chi: cfDet 'chi_c = mu by rewrite -Dc det_alphaXeta alpha_bf divrK. exists c => // c2 c2Nth det_c2_mu; apply: irr_inj. have [irrMc _ imMc _] := constt_Ind_ext nsNG chiN. have /codomP[s2 Dc2]: c2 \in codom (@mul_mod_Iirr G N c). by rewrite -imMc constt_Ind_Res c2Nth constt_irr ?inE. have{} Dc2: 'chi_c2 = ('chi_s2 %% N)%CF * 'chi_c. by rewrite Dc2 cfIirrE // mod_IirrE. have s2_lin: 'chi_s2 \is a linear_char. rewrite qualifE/= irr_char; apply/eqP/(mulIf (irr1_neq0 c)). rewrite mul1r -[in RHS](cfRes1 N) chiN -c2Nth cfRes1. by rewrite Dc2 cfunE cfMod1. have s2Xf_1: 'chi_s2 ^+ f = 1. apply/(can_inj (cfModK nsNG))/(mulIr (lin_char_unitr lin_mu))/esym. rewrite rmorph1 rmorphXn /= mul1r -{1}det_c2_mu Dc2 -det_chi. by rewrite cfDet_mul_lin ?cfMod_lin_char ?irr_char // -(cfRes1 N) chiN. suffices /eqP s2_1: 'chi_s2 == 1 by rewrite Dc2 s2_1 rmorph1 mul1r. rewrite -['chi_s2]expr1 -dvdn_cforder -(eqnP co_e_f) dvdn_gcd. by rewrite /e -card_quotient ?cforder_lin_char_dvdG //= dvdn_cforder s2Xf_1. Qed. (* This is Isaacs, Theorem (6.25). *) Theorem solvable_irr_extendible_from_det G N s (theta := 'chi[N]_s) : N <| G -> solvable (G / N) -> G \subset 'I[theta] -> coprime #|G : N| (Num.truncn (theta 1%g)) -> [exists c, 'Res 'chi[G]_c == theta] = [exists u, 'Res 'chi[G]_u == cfDet theta]. Proof. set e := #|G : N|; set f := Num.truncn _ => nsNG solG IGtheta co_e_f. apply/exists_eqP/exists_eqP=> [[c cNth] | [u uNdth]]. have /lin_char_irr/irrP[u Du] := cfDet_lin_char 'chi_c. by exists u; rewrite -Du -cfDetRes ?irr_char ?cNth. move: {2}e.+1 (ltnSn e) => m. elim: m => // m IHm in G u e nsNG solG IGtheta co_e_f uNdth *. rewrite ltnS => le_e; have [sNG nNG] := andP nsNG. have [<- | ltNG] := eqsVneq N G; first by exists s; rewrite cfRes_id. have [G0 maxG0 sNG0]: {G0 | maxnormal (gval G0) G G & N \subset G0}. by apply: maxgroup_exists; rewrite properEneq ltNG sNG. have [/andP[ltG0G nG0G] maxG0_P] := maxgroupP maxG0. set mu := 'chi_u in uNdth; have lin_mu: mu \is a linear_char. by rewrite qualifE/= irr_char -(cfRes1 N) uNdth /= lin_char1 ?cfDet_lin_char. have sG0G := proper_sub ltG0G; have nsNG0 := normalS sNG0 sG0G nsNG. have nsG0G: G0 <| G by apply/andP. have /lin_char_irr/irrP[u0 Du0] := cfRes_lin_char G0 lin_mu. have u0Ndth: 'Res 'chi_u0 = cfDet theta by rewrite -Du0 cfResRes. have IG0theta: G0 \subset 'I[theta]. by rewrite (subset_trans sG0G) // -IGtheta subsetIr. have coG0f: coprime #|G0 : N| f by rewrite (coprime_dvdl _ co_e_f) ?indexSg. have{m IHm le_e} [c0 c0Ns]: exists c0, 'Res 'chi[G0]_c0 = theta. have solG0: solvable (G0 / N) := solvableS (quotientS N sG0G) solG. apply: IHm nsNG0 solG0 IG0theta coG0f u0Ndth (leq_trans _ le_e). by rewrite -(ltn_pmul2l (cardG_gt0 N)) !Lagrange ?proper_card. have{c0 c0Ns} [c0 [c0Ns dc0_u0] Uc0] := extend_to_cfdet nsNG0 coG0f c0Ns u0Ndth. have IGc0: G \subset 'I['chi_c0]. apply/subsetP=> x Gx; rewrite inE (subsetP nG0G) //= -conjg_IirrE. apply/eqP; congr 'chi__; apply: Uc0; rewrite conjg_IirrE. by rewrite -(cfConjgRes _ nsG0G nsNG) // c0Ns inertiaJ ?(subsetP IGtheta). by rewrite cfDetConjg dc0_u0 -Du0 (cfConjgRes _ _ nsG0G) // cfConjg_id. have prG0G: prime #|G : G0|. have [h injh im_h] := third_isom sNG0 nsNG nsG0G. rewrite -card_quotient // -im_h // card_injm //. rewrite simple_sol_prime 1?quotient_sol //. by rewrite /simple -(injm_minnormal injh) // im_h // maxnormal_minnormal. have [t tG0c0] := prime_invariant_irr_extendible nsG0G (erefl _) prG0G IGc0. by exists t; rewrite /theta -c0Ns -tG0c0 cfResRes. Qed. (* This is Isaacs, Theorem (6.26). *) Theorem extend_linear_char_from_Sylow G N (lambda : 'CF(N)) : N <| G -> lambda \is a linear_char -> G \subset 'I[lambda] -> (forall p, p \in \pi('o(lambda)%CF) -> exists2 Hp : {group gT}, [/\ N \subset Hp, Hp \subset G & p.-Sylow(G / N) (Hp / N)%g] & exists u, 'Res 'chi[Hp]_u = lambda) -> exists u, 'Res[N, G] 'chi_u = lambda. Proof. set m := 'o(lambda)%CF => nsNG lam_lin IGlam p_ext_lam. have [sNG nNG] := andP nsNG; have linN := @cfRes_lin_lin _ _ N. wlog [p p_lam]: lambda @m lam_lin IGlam p_ext_lam / exists p : nat, \pi(m) =i (p : nat_pred). - move=> IHp; have [linG [cf [inj_cf _ lin_cf onto_cf]]] := lin_char_group N. case=> cf1 cfM cfX _ cf_order; have [lam cf_lam] := onto_cf _ lam_lin. pose mu p := cf lam.`_p; pose pi_m p := p \in \pi(m). have Dm: m = #[lam] by rewrite /m cfDet_order_lin // cf_lam cf_order. have Dlambda: lambda = \prod_(p < m.+1 | pi_m p) mu p. rewrite -(big_morph cf cfM cf1) big_mkcond cf_lam /pi_m Dm; congr (cf _). rewrite -{1}[lam]prod_constt big_mkord; apply: eq_bigr => p _. by case: ifPn => // p'lam; apply/constt1P; rewrite /p_elt p'natEpi. have lin_mu p: mu p \is a linear_char by rewrite /mu cfX -cf_lam rpredX. suffices /fin_all_exists [u uNlam] (p : 'I_m.+1): exists u, pi_m p -> 'Res[N, G] 'chi_u = mu p. - pose nu := \prod_(p < m.+1 | pi_m p) 'chi_(u p). have lin_nu: nu \is a linear_char. by apply: rpred_prod => p m_p; rewrite linN ?irr_char ?uNlam. have /irrP[u1 Dnu] := lin_char_irr lin_nu. by exists u1; rewrite Dlambda -Dnu rmorph_prod; apply: eq_bigr. have [m_p | _] := boolP (pi_m p); last by exists 0. have o_mu: \pi('o(mu p)%CF) =i (p : nat_pred). rewrite cfDet_order_lin // cf_order orderE /=. have [|pr_p _ [k ->]] := pgroup_pdiv (p_elt_constt p lam). by rewrite cycle_eq1 (sameP eqP constt1P) /p_elt p'natEpi // negbK -Dm. by move=> q; rewrite pi_of_exp // pi_of_prime. have IGmu: G \subset 'I[mu p]. rewrite (subset_trans IGlam) // /mu cfX -cf_lam. elim: (chinese _ _ _ _) => [|k IHk]; first by rewrite inertia1 norm_inertia. by rewrite exprS (subset_trans _ (inertia_mul _ _)) // subsetIidl. have [q||u] := IHp _ (lin_mu p) IGmu; [ | by exists p | by exists u]. rewrite o_mu => /eqnP-> {q}. have [Hp sylHp [u uNlam]] := p_ext_lam p m_p; exists Hp => //. rewrite /mu cfX -cf_lam -uNlam -rmorphXn /=; set nu := _ ^+ _. have /lin_char_irr/irrP[v ->]: nu \is a linear_char; last by exists v. by rewrite rpredX // linN ?irr_char ?uNlam. have pi_m_p: p \in \pi(m) by rewrite p_lam !inE. have [pr_p mgt0]: prime p /\ (m > 0)%N. by have:= pi_m_p; rewrite mem_primes => /and3P[]. have p_m: p.-nat m by rewrite -(eq_pnat _ p_lam) pnat_pi. have{p_ext_lam} [H [sNH sHG sylHbar] [v vNlam]] := p_ext_lam p pi_m_p. have co_p_GH: coprime p #|G : H|. rewrite -(index_quotient_eq _ sHG nNG) ?subIset ?sNH ?orbT //. by rewrite (pnat_coprime (pnat_id pr_p)) //; have [] := and3P sylHbar. have lin_v: 'chi_v \is a linear_char by rewrite linN ?irr_char ?vNlam. pose nuG := 'Ind[G] 'chi_v. have [c vGc co_p_f]: exists2 c, c \in irr_constt nuG & ~~ (p %| 'chi_c 1%g)%C. apply/exists_inP; rewrite -negb_forall_in. apply: contraL co_p_GH => /forall_inP p_dv_v1. rewrite prime_coprime // negbK -dvdC_nat -[rhs in (_ %| rhs)%C]mulr1. rewrite -(lin_char1 lin_v) -cfInd1 // ['Ind _]cfun_sum_constt /=. rewrite sum_cfunE rpred_sum // => i /p_dv_v1 p_dv_chi1i. rewrite cfunE dvdC_mull // intr_nat //. by rewrite Cnat_cfdot_char ?cfInd_char ?irr_char. pose f := Num.truncn ('chi_c 1%g); pose b := (egcdn f m).1. have fK: f%:R = 'chi_c 1%g by rewrite truncnK ?Cnat_irr1. have fb_mod_m: f * b = 1 %[mod m]. have co_m_f: coprime m f. by rewrite (pnat_coprime p_m) ?p'natE // -dvdC_nat CdivE fK. by rewrite -(chinese_modl co_m_f 1 0) /chinese !mul0n addn0 mul1n. have /irrP[s Dlam] := lin_char_irr lam_lin. have cHv: v \in irr_constt ('Res[H] 'chi_c) by rewrite -constt_Ind_Res. have{cHv} cNs: s \in irr_constt ('Res[N] 'chi_c). rewrite -(cfResRes _ sNH) ?(constt_Res_trans _ cHv) ?cfRes_char ?irr_char //. by rewrite vNlam Dlam constt_irr !inE. have DcN: 'Res[N] 'chi_c = lambda *+ f. have:= Clifford_Res_sum_cfclass nsNG cNs. rewrite cfclass_invariant -Dlam // big_seq1 Dlam => DcN. have:= cfRes1 N 'chi_c; rewrite DcN cfunE -Dlam lin_char1 // mulr1 => ->. by rewrite -scaler_nat fK. have /lin_char_irr/irrP[d Dd]: cfDet 'chi_c ^+ b \is a linear_char. by rewrite rpredX // cfDet_lin_char. exists d; rewrite -{}Dd rmorphXn /= -cfDetRes ?irr_char // DcN. rewrite cfDetMn ?lin_charW // -exprM cfDet_id //. rewrite -(expr_mod _ (exp_cforder _)) -cfDet_order_lin // -/m. by rewrite fb_mod_m /m cfDet_order_lin // expr_mod ?exp_cforder. Qed. (* This is Isaacs, Corollary (6.27). *) Corollary extend_coprime_linear_char G N (lambda : 'CF(N)) : N <| G -> lambda \is a linear_char -> G \subset 'I[lambda] -> coprime #|G : N| 'o(lambda)%CF -> exists u, [/\ 'Res 'chi[G]_u = lambda, 'o('chi_u)%CF = 'o(lambda)%CF & forall v, 'Res 'chi_v = lambda -> coprime #|G : N| 'o('chi_v)%CF -> v = u]. Proof. set e := #|G : N| => nsNG lam_lin IGlam co_e_lam; have [sNG nNG] := andP nsNG. have [p lam_p | v vNlam] := extend_linear_char_from_Sylow nsNG lam_lin IGlam. exists N; last first. by have /irrP[u ->] := lin_char_irr lam_lin; exists u; rewrite cfRes_id. split=> //; rewrite trivg_quotient /pHall sub1G pgroup1 indexg1. rewrite card_quotient //= -/e (pi'_p'nat _ lam_p) //. rewrite -coprime_pi' ?indexg_gt0 1?coprime_sym //. by have:= lam_p; rewrite mem_primes => /and3P[]. set nu := 'chi_v in vNlam. have lin_nu: nu \is a linear_char. by rewrite (@cfRes_lin_lin _ _ N) ?vNlam ?irr_char. have [b be_mod_lam]: exists b, b * e = 1 %[mod 'o(lambda)%CF]. rewrite -(chinese_modr co_e_lam 0 1) /chinese !mul0n !mul1n mulnC. by set b := _.1; exists b. have /irrP[u Du]: nu ^+ (b * e) \in irr G by rewrite lin_char_irr ?rpredX. exists u; set mu := 'chi_u in Du *. have uNlam: 'Res mu = lambda. rewrite cfDet_order_lin // in be_mod_lam. rewrite -Du rmorphXn /= vNlam -(expr_mod _ (exp_cforder _)) //. by rewrite be_mod_lam expr_mod ?exp_cforder. have lin_mu: mu \is a linear_char by rewrite -Du rpredX. have o_mu: ('o(mu) = 'o(lambda))%CF. have dv_o_lam_mu: 'o(lambda)%CF %| 'o(mu)%CF. by rewrite !cfDet_order_lin // -uNlam cforder_Res. have kerNnu_olam: N \subset cfker (nu ^+ 'o(lambda)%CF). rewrite -subsetIidl -cfker_Res ?rpredX ?irr_char //. by rewrite rmorphXn /= vNlam cfDet_order_lin // exp_cforder cfker_cfun1. apply/eqP; rewrite eqn_dvd dv_o_lam_mu andbT cfDet_order_lin //. rewrite dvdn_cforder -Du exprAC -dvdn_cforder dvdn_mull //. rewrite -(cfQuoK nsNG kerNnu_olam) cforder_mod // /e -card_quotient //. by rewrite cforder_lin_char_dvdG ?cfQuo_lin_char ?rpredX. split=> // t tNlam co_e_t. have lin_t: 'chi_t \is a linear_char. by rewrite (@cfRes_lin_lin _ _ N) ?tNlam ?irr_char. have Ut := lin_char_unitr lin_t. have kerN_mu_t: N \subset cfker (mu / 'chi_t)%R. rewrite -subsetIidl -cfker_Res ?lin_charW ?rpred_div ?rmorph_div //. by rewrite /= uNlam tNlam divrr ?lin_char_unitr ?cfker_cfun1. have co_e_mu_t: coprime e #[(mu / 'chi_t)%R]%CF. suffices dv_o_mu_t: #[(mu / 'chi_t)%R]%CF %| 'o(mu)%CF * 'o('chi_t)%CF. by rewrite (coprime_dvdr dv_o_mu_t) // coprimeMr o_mu co_e_lam. rewrite !cfDet_order_lin //; apply/dvdn_cforderP=> x Gx. rewrite invr_lin_char // !cfunE exprMn -rmorphXn {2}mulnC /=. by rewrite !(dvdn_cforderP _) ?conjC1 ?mulr1 // dvdn_mulr. have /eqP mu_t_1: mu / 'chi_t == 1. rewrite -(dvdn_cforder (_ / _)%R 1) -(eqnP co_e_mu_t) dvdn_gcd dvdnn andbT. rewrite -(cfQuoK nsNG kerN_mu_t) cforder_mod // /e -card_quotient //. by rewrite cforder_lin_char_dvdG ?cfQuo_lin_char ?rpred_div. by apply: irr_inj; rewrite -['chi_t]mul1r -mu_t_1 divrK. Qed. (* This is Isaacs, Corollary (6.28). *) Corollary extend_solvable_coprime_irr G N t (theta := 'chi[N]_t) : N <| G -> solvable (G / N) -> G \subset 'I[theta] -> coprime #|G : N| ('o(theta)%CF * Num.truncn (theta 1%g)) -> exists c, [/\ 'Res 'chi[G]_c = theta, 'o('chi_c)%CF = 'o(theta)%CF & forall d, 'Res 'chi_d = theta -> coprime #|G : N| 'o('chi_d)%CF -> d = c]. Proof. set e := #|G : N|; set f := Num.truncn _ => nsNG solG IGtheta. rewrite coprimeMr => /andP[co_e_th co_e_f]. have [sNG nNG] := andP nsNG; pose lambda := cfDet theta. have lin_lam: lambda \is a linear_char := cfDet_lin_char theta. have IGlam: G \subset 'I[lambda]. apply/subsetP=> y /(subsetP IGtheta)/setIdP[nNy /eqP th_y]. by rewrite inE nNy /= -cfDetConjg th_y. have co_e_lam: coprime e 'o(lambda)%CF by rewrite cfDet_order_lin. have [//|u [uNlam o_u Uu]] := extend_coprime_linear_char nsNG lin_lam IGlam. have /exists_eqP[c cNth]: [exists c, 'Res 'chi[G]_c == theta]. rewrite solvable_irr_extendible_from_det //. by apply/exists_eqP; exists u. have{c cNth} [c [cNth det_c] Uc] := extend_to_cfdet nsNG co_e_f cNth uNlam. have lin_u: 'chi_u \is a linear_char by rewrite -det_c cfDet_lin_char. exists c; split=> // [|c0 c0Nth co_e_c0]. by rewrite !cfDet_order_lin // -det_c in o_u. have lin_u0: cfDet 'chi_c0 \is a linear_char := cfDet_lin_char 'chi_c0. have /irrP[u0 Du0] := lin_char_irr lin_u0. have co_e_u0: coprime e 'o('chi_u0)%CF by rewrite -Du0 cfDet_order_lin. have eq_u0u: u0 = u by apply: Uu; rewrite // -Du0 -cfDetRes ?irr_char ?c0Nth. by apply: Uc; rewrite // Du0 eq_u0u. Qed. End ExtendInvariantIrr. Section Frobenius. Variables (gT : finGroupType) (G K : {group gT}). (* Because he only defines Frobenius groups in chapter 7, Isaacs does not *) (* state these theorems using the Frobenius property. *) Hypothesis frobGK : [Frobenius G with kernel K]. (* This is Isaacs, Theorem 6.34(a1). *) Theorem inertia_Frobenius_ker i : i != 0 -> 'I_G['chi[K]_i] = K. Proof. have [_ _ nsKG regK] := Frobenius_kerP frobGK; have [sKG nKG] := andP nsKG. move=> nzi; apply/eqP; rewrite eqEsubset sub_Inertia // andbT. apply/subsetP=> x /setIP[Gx /setIdP[nKx /eqP x_stab_i]]. have actIirrK: is_action G (@conjg_Iirr _ K). split=> [y j k eq_jk | j y z Gy Gz]. by apply/irr_inj/(can_inj (cfConjgK y)); rewrite -!conjg_IirrE eq_jk. by apply: irr_inj; rewrite !conjg_IirrE (cfConjgM _ nsKG). pose ito := Action actIirrK; pose cto := ('Js \ (subsetT G))%act. have acts_Js : [acts G, on classes K | 'Js]. apply/subsetP=> y Gy; have nKy := subsetP nKG y Gy. rewrite !inE; apply/subsetP=> _ /imsetP[z Gz ->] /[!inE]/=. rewrite -class_rcoset norm_rlcoset // class_lcoset. by apply: imset_f; rewrite memJ_norm. have acts_cto : [acts G, on classes K | cto] by rewrite astabs_ract subsetIidl. pose m := #|'Fix_(classes K | cto)[x]|. have def_m: #|'Fix_ito[x]| = m. apply: card_afix_irr_classes => // j y _ Ky /imsetP[_ /imsetP[z Kz ->] ->]. by rewrite conjg_IirrE cfConjgEJ // cfunJ. have: (m != 1)%N. rewrite -def_m (cardD1 (0 : Iirr K)) (cardD1 i) !(inE, sub1set) /=. by rewrite conjg_Iirr0 nzi eqxx -(inj_eq irr_inj) conjg_IirrE x_stab_i eqxx. apply: contraR => notKx; apply/cards1P; exists 1%g; apply/esym/eqP. rewrite eqEsubset !(sub1set, inE) classes1 /= conjs1g eqxx /=. apply/subsetP=> _ /setIP[/imsetP[y Ky ->] /afix1P /= cyKx]. have /imsetP[z Kz def_yx]: y ^ x \in y ^: K. by rewrite -cyKx; apply: imset_f; apply: class_refl. rewrite inE classG_eq1; apply: contraR notKx => nty. rewrite -(groupMr x (groupVr Kz)). apply: (subsetP (regK y _)); first exact/setD1P. rewrite !inE groupMl // groupV (subsetP sKG) //=. by rewrite conjg_set1 conjgM def_yx conjgK. Qed. (* This is Isaacs, Theorem 6.34(a2) *) Theorem irr_induced_Frobenius_ker i : i != 0 -> 'Ind[G, K] 'chi_i \in irr G. Proof. move/inertia_Frobenius_ker/group_inj=> defK. have [_ _ nsKG _] := Frobenius_kerP frobGK. have [] := constt_Inertia_bijection i nsKG; rewrite defK cfInd_id => -> //. by rewrite constt_irr !inE. Qed. (* This is Isaacs, Theorem 6.34(b) *) Theorem Frobenius_Ind_irrP j : reflect (exists2 i, i != 0 & 'chi_j = 'Ind[G, K] 'chi_i) (~~ (K \subset cfker 'chi_j)). Proof. have [_ _ nsKG _] := Frobenius_kerP frobGK; have [sKG nKG] := andP nsKG. apply: (iffP idP) => [not_chijK1 | [i nzi ->]]; last first. by rewrite cfker_Ind_irr ?sub_gcore // subGcfker. have /neq0_has_constt[i chijKi]: 'Res[K] 'chi_j != 0 by apply: Res_irr_neq0. have nz_i: i != 0. by apply: contraNneq not_chijK1 => i0; rewrite constt0_Res_cfker // -i0. have /irrP[k def_chik] := irr_induced_Frobenius_ker nz_i. have: '['chi_j, 'chi_k] != 0 by rewrite -def_chik -cfdot_Res_l. by rewrite cfdot_irr pnatr_eq0; case: (j =P k) => // ->; exists i. Qed. End Frobenius.
LexOrder.lean
/- Copyright (c) 2024 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.Data.Finsupp.WellFounded /-! LexOrder of multivariate power series Given an ordering of `σ` such that `WellOrderGT σ`, the lexicographic order on `σ →₀ ℕ` is a well ordering, which can be used to define a natural valuation `lexOrder` on the ring `MvPowerSeries σ R`: the smallest exponent in the support. -/ namespace MvPowerSeries variable {σ R : Type*} variable [Semiring R] section LexOrder open Finsupp variable [LinearOrder σ] [WellFoundedGT σ] /-- The lex order on multivariate power series. -/ noncomputable def lexOrder (φ : MvPowerSeries σ R) : (WithTop (Lex (σ →₀ ℕ))) := by classical exact if h : φ = 0 then ⊤ else by have ne : Set.Nonempty (toLex '' φ.support) := by simp only [Set.image_nonempty, Function.support_nonempty_iff, ne_eq, h, not_false_eq_true] apply WithTop.some apply WellFounded.min _ (toLex '' φ.support) ne · exact Finsupp.instLTLex.lt · exact wellFounded_lt theorem lexOrder_def_of_ne_zero {φ : MvPowerSeries σ R} (hφ : φ ≠ 0) : ∃ (ne : Set.Nonempty (toLex '' φ.support)), lexOrder φ = WithTop.some ((@wellFounded_lt (Lex (σ →₀ ℕ)) (instLTLex) (Lex.wellFoundedLT)).min (toLex '' φ.support) ne) := by suffices ne : Set.Nonempty (toLex '' φ.support) by use ne unfold lexOrder simp only [dif_neg hφ] simp only [Set.image_nonempty, Function.support_nonempty_iff, ne_eq, hφ, not_false_eq_true] @[simp] theorem lexOrder_eq_top_iff_eq_zero (φ : MvPowerSeries σ R) : lexOrder φ = ⊤ ↔ φ = 0 := by unfold lexOrder split_ifs with h · simp only [h] · simp only [h, WithTop.coe_ne_top] theorem lexOrder_zero : lexOrder (0 : MvPowerSeries σ R) = ⊤ := by unfold lexOrder rw [dif_pos rfl] theorem exists_finsupp_eq_lexOrder_of_ne_zero {φ : MvPowerSeries σ R} (hφ : φ ≠ 0) : ∃ (d : σ →₀ ℕ), lexOrder φ = toLex d := by simp only [ne_eq, ← lexOrder_eq_top_iff_eq_zero, WithTop.ne_top_iff_exists] at hφ obtain ⟨p, hp⟩ := hφ exact ⟨ofLex p, by simp only [toLex_ofLex, hp]⟩ theorem coeff_ne_zero_of_lexOrder {φ : MvPowerSeries σ R} {d : σ →₀ ℕ} (h : toLex d = lexOrder φ) : coeff R d φ ≠ 0 := by have hφ : φ ≠ 0 := by simp only [ne_eq, ← lexOrder_eq_top_iff_eq_zero, ← h, WithTop.coe_ne_top, not_false_eq_true] have hφ' := lexOrder_def_of_ne_zero hφ rcases hφ' with ⟨ne, hφ'⟩ simp only [← h, WithTop.coe_eq_coe] at hφ' suffices toLex d ∈ toLex '' φ.support by simp only [Set.mem_image_equiv, toLex_symm_eq, ofLex_toLex, Function.mem_support, ne_eq] at this apply this rw [hφ'] apply WellFounded.min_mem theorem coeff_eq_zero_of_lt_lexOrder {φ : MvPowerSeries σ R} {d : σ →₀ ℕ} (h : toLex d < lexOrder φ) : coeff R d φ = 0 := by by_cases hφ : φ = 0 · simp only [hφ, map_zero] · rcases lexOrder_def_of_ne_zero hφ with ⟨ne, hφ'⟩ rw [hφ', WithTop.coe_lt_coe] at h by_contra h' exact WellFounded.not_lt_min _ (toLex '' φ.support) ne (Set.mem_image_equiv.mpr h') h theorem lexOrder_le_of_coeff_ne_zero {φ : MvPowerSeries σ R} {d : σ →₀ ℕ} (h : coeff R d φ ≠ 0) : lexOrder φ ≤ toLex d := by rw [← not_lt] intro h' exact h (coeff_eq_zero_of_lt_lexOrder h') theorem le_lexOrder_iff {φ : MvPowerSeries σ R} {w : WithTop (Lex (σ →₀ ℕ))} : w ≤ lexOrder φ ↔ (∀ (d : σ →₀ ℕ) (_ : toLex d < w), coeff R d φ = 0) := by constructor · intro h d hd apply coeff_eq_zero_of_lt_lexOrder exact lt_of_lt_of_le hd h · intro h rw [← not_lt] intro h' have hφ : φ ≠ 0 := by rw [ne_eq, ← lexOrder_eq_top_iff_eq_zero] exact ne_top_of_lt h' obtain ⟨d, hd⟩ := exists_finsupp_eq_lexOrder_of_ne_zero hφ refine coeff_ne_zero_of_lexOrder hd.symm (h d ?_) rwa [← hd] theorem min_lexOrder_le {φ ψ : MvPowerSeries σ R} : min (lexOrder φ) (lexOrder ψ) ≤ lexOrder (φ + ψ) := by rw [le_lexOrder_iff] intro d hd simp only [lt_min_iff] at hd rw [map_add, coeff_eq_zero_of_lt_lexOrder hd.1, coeff_eq_zero_of_lt_lexOrder hd.2, add_zero] theorem coeff_mul_of_add_lexOrder {φ ψ : MvPowerSeries σ R} {p q : σ →₀ ℕ} (hp : lexOrder φ = toLex p) (hq : lexOrder ψ = toLex q) : coeff R (p + q) (φ * ψ) = coeff R p φ * coeff R q ψ := by rw [coeff_mul, Finset.sum_eq_single_of_mem ⟨p, q⟩ (by simp)] rintro ⟨u, v⟩ h h' simp only [Finset.mem_antidiagonal] at h rcases trichotomy_of_add_eq_add (congrArg toLex h) with h'' | h'' | h'' · exact False.elim (h' (by simp [h''.1, h''.2])) · rw [coeff_eq_zero_of_lt_lexOrder (d := u), zero_mul] rw [hp] norm_cast · rw [coeff_eq_zero_of_lt_lexOrder (d := v), mul_zero] rw [hq] norm_cast theorem le_lexOrder_mul (φ ψ : MvPowerSeries σ R) : lexOrder φ + lexOrder ψ ≤ lexOrder (φ * ψ) := by rw [le_lexOrder_iff] intro d hd rw [coeff_mul] apply Finset.sum_eq_zero rintro ⟨u, v⟩ h simp only [Finset.mem_antidiagonal] at h simp only suffices toLex u < lexOrder φ ∨ toLex v < lexOrder ψ by rcases this with (hu | hv) · rw [coeff_eq_zero_of_lt_lexOrder hu, zero_mul] · rw [coeff_eq_zero_of_lt_lexOrder hv, mul_zero] rw [or_iff_not_imp_left, not_lt, ← not_le] intro hu hv rw [← not_le] at hd apply hd simp only [← h, toLex_add, WithTop.coe_add, add_le_add hu hv] alias lexOrder_mul_ge := le_lexOrder_mul theorem lexOrder_mul [NoZeroDivisors R] (φ ψ : MvPowerSeries σ R) : lexOrder (φ * ψ) = lexOrder φ + lexOrder ψ := by by_cases hφ : φ = 0 · simp only [hφ, zero_mul, lexOrder_zero, top_add] by_cases hψ : ψ = 0 · simp only [hψ, mul_zero, lexOrder_zero, add_top] rcases exists_finsupp_eq_lexOrder_of_ne_zero hφ with ⟨p, hp⟩ rcases exists_finsupp_eq_lexOrder_of_ne_zero hψ with ⟨q, hq⟩ apply le_antisymm _ (lexOrder_mul_ge φ ψ) rw [hp, hq] apply lexOrder_le_of_coeff_ne_zero (d := p + q) rw [coeff_mul_of_add_lexOrder hp hq, mul_ne_zero_iff] exact ⟨coeff_ne_zero_of_lexOrder hp.symm, coeff_ne_zero_of_lexOrder hq.symm⟩ end LexOrder end MvPowerSeries
measurability.lean
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic import Mathlib.MeasureTheory.Function.SpecialFunctions.Inner import Mathlib.MeasureTheory.Function.StronglyMeasurable.Lemmas open MeasureTheory TopologicalSpace variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] {f g : α → β} {s₁ s₂ : Set α} {t₁ t₂ : Set β} {μ ν : MeasureTheory.Measure α} set_option linter.unusedVariables false -- Test the use of assumption example (hf : Measurable f) : Measurable f := by measurability -- Test that intro does not unfold `Measurable` example : Measurable f → Measurable f := by measurability -- Test the use of apply_assumption to get (h i) from a hypothesis (h : ∀ i, ...). example {F : ℕ → α → β} (hF : ∀ i, Measurable (F i)) : Measurable (F 0) := by measurability example {ι} [Encodable ι] {S₁ S₂ : ι → Set α} (hS₁ : ∀ i, MeasurableSet (S₁ i)) (hS₂ : ∀ i, MeasurableSet (S₂ i)) : MeasurableSet (⋃ i, (S₁ i) ∪ (S₂ i)) := by measurability -- Tests on sets example (hs₁ : MeasurableSet s₁) (hs₂ : MeasurableSet s₂) : MeasurableSet (s₁ ∪ s₁) := by measurability example {ι} [Encodable ι] {S : ι → Set α} (hs : ∀ i, MeasurableSet (S i)) : MeasurableSet (⋃ i, S i) := by measurability example (hf : Measurable f) (hs₁ : MeasurableSet s₁) (ht₂ : MeasurableSet t₂) : MeasurableSet ((f ⁻¹' t₂) ∩ s₁) := by measurability -- Strong measurability section strong_measurability variable [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] -- Test the use of apply_assumption to get (h i) from a hypothesis (h : ∀ i, ...). example {F : ℕ → α → β} (hF : ∀ i, StronglyMeasurable (F i)) : Measurable (F 0) := by measurability example [Zero β] {F : ℕ → α → β} (hF : ∀ i, AEFinStronglyMeasurable (F i) μ) : AEMeasurable (F 0) μ := by measurability example {ι} [Encodable ι] {S₁ S₂ : ι → Set α} (hS₁ : ∀ i, MeasurableSet (S₁ i)) (hS₂ : ∀ i, MeasurableSet (S₂ i)) : MeasurableSet (⋃ i, (S₁ i) ∪ (S₂ i)) := by measurability end strong_measurability /-- `ℝ` is a good test case because it verifies many assumptions, hence many lemmas apply and we are more likely to detect a bad lemma. In a previous version of the tactic, `measurability` got stuck trying to apply `Set.Finite.MeasurableSet` here. -/ example {a b : ℝ} : MeasurableSet (Set.Icc a b) := by measurability -- Tests on functions example [Mul β] [MeasurableMul₂ β] (hf : Measurable f) (c : β) : Measurable (fun x => c * f x) := by measurability -- uses const_mul, not mul example [Add β] [MeasurableAdd₂ β] (hf : Measurable f) (hg : Measurable g) : Measurable (fun x => f x + g x) := by measurability example [Add β] [MeasurableAdd₂ β] (hf : Measurable f) (hg : AEMeasurable g μ) : AEMeasurable (fun x => f x + g x) μ := by measurability example [Div β] [MeasurableDiv₂ β] (hf : Measurable f) (hg : Measurable g) (ht : MeasurableSet t₂) : MeasurableSet ((fun x => f x / g x) ⁻¹' t₂) := by measurability example [AddCommMonoid β] [MeasurableAdd₂ β] {s : Finset ℕ} {F : ℕ → α → β} (hF : ∀ i, Measurable (F i)) : Measurable (∑ i ∈ s, (fun x => F (i+1) x + F i x)) := by fun_prop example [AddCommMonoid β] [MeasurableAdd₂ β] {s : Finset ℕ} {F : ℕ → α → β} (hF : ∀ i, AEMeasurable (F i) μ) : AEMeasurable (∑ i ∈ s, (fun x => F (i+1) x + F i x)) μ := by measurability -- even with many assumptions, the tactic is not trapped by a bad lemma example [TopologicalSpace α] [BorelSpace α] [NormedAddCommGroup β] [BorelSpace β] [MeasurableAdd₂ β] [MeasurableSub₂ β] {s : Finset ℕ} {F : ℕ → α → β} (hF : ∀ i, Measurable (F i)) : AEMeasurable (∑ i ∈ s, (fun x => F (i+1) x - F i x)) μ := by measurability open scoped RealInnerProductSpace example : Measurable (fun x : ℝ => Real.exp (2 * ⟪3, x⟫)) := by measurability example : StronglyMeasurable (fun x : ℝ => Real.exp (2 * ⟪3, x⟫)) := by measurability example {γ : MeasureTheory.Measure ℝ} : AEMeasurable (fun x : ℝ => Real.exp (2 * ⟪3, x⟫)) γ := by measurability example {γ : MeasureTheory.Measure ℝ} : AEStronglyMeasurable (fun x : ℝ => Real.exp (2 * ⟪3, x⟫)) γ := by measurability example {γ : MeasureTheory.Measure ℝ} [SigmaFinite γ] : FinStronglyMeasurable (fun x : ℝ => Real.exp (2 * ⟪3, x⟫)) γ := by measurability example {γ : MeasureTheory.Measure ℝ} [SigmaFinite γ] : AEFinStronglyMeasurable (fun x : ℝ => Real.exp (2 * ⟪3, x⟫)) γ := by measurability /-- An older version of the tactic failed in the presence of a negated hypothesis due to an internal call to `apply_assumption`. -/ example {ι : Type _} (i k : ι) (hik : i ≠ k) : Measurable (id : α → α) := by measurability --This search problem loops (StronglyMeasurable -> Measurable -> StronglyMeasurable) but fails --quickly nevertheless. --example (f : ℝ → ℝ) : StronglyMeasurable f := by measurability
Bounds.lean
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler, Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.SpecificFunctions.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv /-! # Polynomial bounds for trigonometric functions ## Main statements This file contains upper and lower bounds for real trigonometric functions in terms of polynomials. See `Trigonometric.Basic` for more elementary inequalities, establishing the ranges of these functions, and their monotonicity in suitable intervals. Here we prove the following: * `sin_lt`: for `x > 0` we have `sin x < x`. * `sin_gt_sub_cube`: For `0 < x ≤ 1` we have `x - x ^ 3 / 4 < sin x`. * `lt_tan`: for `0 < x < π/2` we have `x < tan x`. * `cos_le_one_div_sqrt_sq_add_one` and `cos_lt_one_div_sqrt_sq_add_one`: for `-3 * π / 2 ≤ x ≤ 3 * π / 2`, we have `cos x ≤ 1 / sqrt (x ^ 2 + 1)`, with strict inequality if `x ≠ 0`. (This bound is not quite optimal, but not far off) ## Tags sin, cos, tan, angle -/ open Set namespace Real variable {x : ℝ} /-- For 0 < x, we have sin x < x. -/ theorem sin_lt (h : 0 < x) : sin x < x := by rcases lt_or_ge 1 x with h' | h' · exact (sin_le_one x).trans_lt h' have hx : |x| = x := abs_of_nonneg h.le have := le_of_abs_le (sin_bound <| show |x| ≤ 1 by rwa [hx]) rw [sub_le_iff_le_add', hx] at this apply this.trans_lt rw [sub_add, sub_lt_self_iff, sub_pos, div_eq_mul_inv (x ^ 3)] refine mul_lt_mul' ?_ (by norm_num) (by norm_num) (pow_pos h 3) apply pow_le_pow_of_le_one h.le h' norm_num lemma sin_le (hx : 0 ≤ x) : sin x ≤ x := by obtain rfl | hx := hx.eq_or_lt · simp · exact (sin_lt hx).le lemma lt_sin (hx : x < 0) : x < sin x := by simpa using sin_lt <| neg_pos.2 hx lemma le_sin (hx : x ≤ 0) : x ≤ sin x := by simpa using sin_le <| neg_nonneg.2 hx theorem lt_sin_mul {x : ℝ} (hx : 0 < x) (hx' : x < 1) : x < sin (π / 2 * x) := by simpa [mul_comm x] using strictConcaveOn_sin_Icc.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ pi_div_two_pos.ne (sub_pos.2 hx') hx theorem le_sin_mul {x : ℝ} (hx : 0 ≤ x) (hx' : x ≤ 1) : x ≤ sin (π / 2 * x) := by simpa [mul_comm x] using strictConcaveOn_sin_Icc.concaveOn.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ (sub_nonneg.2 hx') hx theorem mul_lt_sin {x : ℝ} (hx : 0 < x) (hx' : x < π / 2) : 2 / π * x < sin x := by rw [← inv_div] simpa [-inv_div, mul_inv_cancel_left₀ pi_div_two_pos.ne'] using @lt_sin_mul ((π / 2)⁻¹ * x) (mul_pos (inv_pos.2 pi_div_two_pos) hx) (by rwa [← div_eq_inv_mul, div_lt_one pi_div_two_pos]) /-- One half of **Jordan's inequality**. In the range `[0, π / 2]`, we have a linear lower bound on `sin`. The other half is given by `Real.sin_le`. -/ theorem mul_le_sin {x : ℝ} (hx : 0 ≤ x) (hx' : x ≤ π / 2) : 2 / π * x ≤ sin x := by rw [← inv_div] simpa [-inv_div, mul_inv_cancel_left₀ pi_div_two_pos.ne'] using @le_sin_mul ((π / 2)⁻¹ * x) (mul_nonneg (inv_nonneg.2 pi_div_two_pos.le) hx) (by rwa [← div_eq_inv_mul, div_le_one pi_div_two_pos]) /-- Half of **Jordan's inequality** for negative values. -/ lemma sin_le_mul (hx : -(π / 2) ≤ x) (hx₀ : x ≤ 0) : sin x ≤ 2 / π * x := by simpa using mul_le_sin (neg_nonneg.2 hx₀) (neg_le.2 hx) /-- Half of **Jordan's inequality** for absolute values. -/ lemma mul_abs_le_abs_sin (hx : |x| ≤ π / 2) : 2 / π * |x| ≤ |sin x| := by wlog hx₀ : 0 ≤ x case inr => simpa using this (by rwa [abs_neg]) <| neg_nonneg.2 <| le_of_not_ge hx₀ rw [abs_of_nonneg hx₀] at hx ⊢ exact (mul_le_sin hx₀ hx).trans (le_abs_self _) lemma sin_sq_lt_sq (hx : x ≠ 0) : sin x ^ 2 < x ^ 2 := by wlog hx₀ : 0 < x case inr => simpa using this (neg_ne_zero.2 hx) <| neg_pos_of_neg <| hx.lt_of_le <| le_of_not_gt hx₀ rcases le_or_gt x 1 with hxπ | hxπ case inl => exact pow_lt_pow_left₀ (sin_lt hx₀) (sin_nonneg_of_nonneg_of_le_pi hx₀.le (by linarith [two_le_pi])) (by simp) case inr => exact (sin_sq_le_one _).trans_lt (by rwa [one_lt_sq_iff₀ hx₀.le]) lemma sin_sq_le_sq : sin x ^ 2 ≤ x ^ 2 := by rcases eq_or_ne x 0 with rfl | hx case inl => simp case inr => exact (sin_sq_lt_sq hx).le lemma abs_sin_lt_abs (hx : x ≠ 0) : |sin x| < |x| := sq_lt_sq.1 (sin_sq_lt_sq hx) lemma abs_sin_le_abs : |sin x| ≤ |x| := sq_le_sq.1 sin_sq_le_sq lemma one_sub_sq_div_two_lt_cos (hx : x ≠ 0) : 1 - x ^ 2 / 2 < cos x := by have := (sin_sq_lt_sq (by positivity)).trans_eq' (sin_sq_eq_half_sub (x / 2)).symm ring_nf at this linarith lemma one_sub_sq_div_two_le_cos : 1 - x ^ 2 / 2 ≤ cos x := by rcases eq_or_ne x 0 with rfl | hx case inl => simp case inr => exact (one_sub_sq_div_two_lt_cos hx).le /-- Half of **Jordan's inequality** for `cos`. -/ lemma one_sub_mul_le_cos (hx₀ : 0 ≤ x) (hx : x ≤ π / 2) : 1 - 2 / π * x ≤ cos x := by simpa [sin_pi_div_two_sub, mul_sub, div_mul_div_comm, mul_comm π, pi_pos.ne'] using mul_le_sin (x := π / 2 - x) (by simpa) (by simpa) /-- Half of **Jordan's inequality** for `cos` and negative values. -/ lemma one_add_mul_le_cos (hx₀ : -(π / 2) ≤ x) (hx : x ≤ 0) : 1 + 2 / π * x ≤ cos x := by simpa using one_sub_mul_le_cos (x := -x) (by linarith) (by linarith) lemma cos_le_one_sub_mul_cos_sq (hx : |x| ≤ π) : cos x ≤ 1 - 2 / π ^ 2 * x ^ 2 := by wlog hx₀ : 0 ≤ x case inr => simpa using this (by rwa [abs_neg]) <| neg_nonneg.2 <| le_of_not_ge hx₀ rw [abs_of_nonneg hx₀] at hx have : x / π ≤ sin (x / 2) := by simpa using mul_le_sin (x := x / 2) (by positivity) (by linarith) have := (pow_le_pow_left₀ (by positivity) this 2).trans_eq (sin_sq_eq_half_sub _) ring_nf at this ⊢ linarith /-- For 0 < x ≤ 1 we have x - x ^ 3 / 4 < sin x. This is also true for x > 1, but it's nontrivial for x just above 1. This inequality is not tight; the tighter inequality is sin x > x - x ^ 3 / 6 for all x > 0, but this inequality has a simpler proof. -/ theorem sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x := by have hx : |x| = x := abs_of_nonneg h.le have := neg_le_of_abs_le (sin_bound <| show |x| ≤ 1 by rwa [hx]) rw [le_sub_iff_add_le, hx] at this refine lt_of_lt_of_le ?_ this have : x ^ 3 / ↑4 - x ^ 3 / ↑6 = x ^ 3 * 12⁻¹ := by norm_num [div_eq_mul_inv, ← mul_sub] rw [add_comm, sub_add, sub_neg_eq_add, sub_lt_sub_iff_left, ← lt_sub_iff_add_lt', this] refine mul_lt_mul' ?_ (by norm_num) (by norm_num) (pow_pos h 3) apply pow_le_pow_of_le_one h.le h' norm_num /-- The derivative of `tan x - x` is `1/(cos x)^2 - 1` away from the zeroes of cos. -/ theorem deriv_tan_sub_id (x : ℝ) (h : cos x ≠ 0) : deriv (fun y : ℝ => tan y - y) x = 1 / cos x ^ 2 - 1 := HasDerivAt.deriv <| by simpa using (hasDerivAt_tan h).add (hasDerivAt_id x).neg /-- For all `0 < x < π/2` we have `x < tan x`. This is proved by checking that the function `tan x - x` vanishes at zero and has non-negative derivative. -/ theorem lt_tan {x : ℝ} (h1 : 0 < x) (h2 : x < π / 2) : x < tan x := by let U := Ico 0 (π / 2) have intU : interior U = Ioo 0 (π / 2) := interior_Ico have half_pi_pos : 0 < π / 2 := div_pos pi_pos two_pos have cos_pos {y : ℝ} (hy : y ∈ U) : 0 < cos y := by exact cos_pos_of_mem_Ioo (Ico_subset_Ioo_left (neg_lt_zero.mpr half_pi_pos) hy) have sin_pos {y : ℝ} (hy : y ∈ interior U) : 0 < sin y := by rw [intU] at hy exact sin_pos_of_mem_Ioo (Ioo_subset_Ioo_right (div_le_self pi_pos.le one_le_two) hy) have tan_cts_U : ContinuousOn tan U := by apply ContinuousOn.mono continuousOn_tan intro z hz simp only [mem_setOf_eq] exact (cos_pos hz).ne' have tan_minus_id_cts : ContinuousOn (fun y : ℝ => tan y - y) U := tan_cts_U.sub continuousOn_id have deriv_pos (y : ℝ) (hy : y ∈ interior U) : 0 < deriv (fun y' : ℝ => tan y' - y') y := by have := cos_pos (interior_subset hy) simp only [deriv_tan_sub_id y this.ne', one_div, gt_iff_lt, sub_pos] norm_cast have bd2 : cos y ^ 2 < 1 := by apply lt_of_le_of_ne y.cos_sq_le_one rw [cos_sq'] simpa only [Ne, sub_eq_self, sq_eq_zero_iff] using (sin_pos hy).ne' rwa [lt_inv_comm₀, inv_one] · exact zero_lt_one simpa only [sq, mul_self_pos] using this.ne' have mono := strictMonoOn_of_deriv_pos (convex_Ico 0 (π / 2)) tan_minus_id_cts deriv_pos have zero_in_U : (0 : ℝ) ∈ U := by rwa [left_mem_Ico] have x_in_U : x ∈ U := ⟨h1.le, h2⟩ simpa only [tan_zero, sub_zero, sub_pos] using mono zero_in_U x_in_U h1 theorem le_tan {x : ℝ} (h1 : 0 ≤ x) (h2 : x < π / 2) : x ≤ tan x := by rcases eq_or_lt_of_le h1 with (rfl | h1') · rw [tan_zero] · exact le_of_lt (lt_tan h1' h2) theorem cos_lt_one_div_sqrt_sq_add_one {x : ℝ} (hx1 : -(3 * π / 2) ≤ x) (hx2 : x ≤ 3 * π / 2) (hx3 : x ≠ 0) : cos x < (1 / √(x ^ 2 + 1) : ℝ) := by suffices ∀ {y : ℝ}, 0 < y → y ≤ 3 * π / 2 → cos y < 1 / √(y ^ 2 + 1) by rcases lt_or_lt_iff_ne.mpr hx3.symm with ⟨h⟩ · exact this h hx2 · convert this (by linarith : 0 < -x) (by linarith) using 1 · rw [cos_neg] · rw [neg_sq] intro y hy1 hy2 have hy3 : ↑0 < y ^ 2 + 1 := by linarith [sq_nonneg y] rcases lt_or_ge y (π / 2) with (hy2' | hy1') · -- Main case : `0 < y < π / 2` have hy4 : 0 < cos y := cos_pos_of_mem_Ioo ⟨by linarith, hy2'⟩ rw [← abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨by linarith, hy2'.le⟩), ← abs_of_nonneg (one_div_nonneg.mpr (sqrt_nonneg _)), ← sq_lt_sq, div_pow, one_pow, sq_sqrt hy3.le, lt_one_div (pow_pos hy4 _) hy3, ← inv_one_add_tan_sq hy4.ne', one_div, inv_inv, add_comm, add_lt_add_iff_left, sq_lt_sq, abs_of_pos hy1, abs_of_nonneg (tan_nonneg_of_nonneg_of_le_pi_div_two hy1.le hy2'.le)] exact Real.lt_tan hy1 hy2' · -- Easy case : `π / 2 ≤ y ≤ 3 * π / 2` refine lt_of_le_of_lt ?_ (one_div_pos.mpr <| sqrt_pos_of_pos hy3) exact cos_nonpos_of_pi_div_two_le_of_le hy1' (by linarith [pi_pos]) theorem cos_le_one_div_sqrt_sq_add_one {x : ℝ} (hx1 : -(3 * π / 2) ≤ x) (hx2 : x ≤ 3 * π / 2) : cos x ≤ (1 : ℝ) / √(x ^ 2 + 1) := by rcases eq_or_ne x 0 with (rfl | hx3) · simp · exact (cos_lt_one_div_sqrt_sq_add_one hx1 hx2 hx3).le end Real
Polynomial.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, Eric Wieser -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.Deriv.Add /-! # Derivatives of polynomials In this file we prove that derivatives of polynomials in the analysis sense agree with their derivatives in the algebraic sense. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## TODO * Add results about multivariable polynomials. * Generalize some (most?) results to an algebra over the base field. ## Keywords derivative, polynomial -/ universe u open scoped Polynomial open ContinuousLinearMap (smulRight) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {x : 𝕜} {s : Set 𝕜} namespace Polynomial /-! ### Derivative of a polynomial -/ variable {R : Type*} [CommSemiring R] [Algebra R 𝕜] variable (p : 𝕜[X]) (q : R[X]) /-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/ protected theorem hasStrictDerivAt (x : 𝕜) : HasStrictDerivAt (fun x => p.eval x) (p.derivative.eval x) x := by induction p using Polynomial.induction_on' with | add p q hp hq => simpa using hp.add hq | monomial n a => simpa [mul_assoc, derivative_monomial] using (hasStrictDerivAt_pow n x).const_mul a protected theorem hasStrictDerivAt_aeval (x : 𝕜) : HasStrictDerivAt (fun x => aeval x q) (aeval x (derivative q)) x := by simpa only [aeval_def, eval₂_eq_eval_map, derivative_map] using (q.map (algebraMap R 𝕜)).hasStrictDerivAt x /-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/ protected theorem hasDerivAt (x : 𝕜) : HasDerivAt (fun x => p.eval x) (p.derivative.eval x) x := (p.hasStrictDerivAt x).hasDerivAt protected theorem hasDerivAt_aeval (x : 𝕜) : HasDerivAt (fun x => aeval x q) (aeval x (derivative q)) x := (q.hasStrictDerivAt_aeval x).hasDerivAt protected theorem hasDerivWithinAt (x : 𝕜) (s : Set 𝕜) : HasDerivWithinAt (fun x => p.eval x) (p.derivative.eval x) s x := (p.hasDerivAt x).hasDerivWithinAt protected theorem hasDerivWithinAt_aeval (x : 𝕜) (s : Set 𝕜) : HasDerivWithinAt (fun x => aeval x q) (aeval x (derivative q)) s x := (q.hasDerivAt_aeval x).hasDerivWithinAt protected theorem differentiableAt : DifferentiableAt 𝕜 (fun x => p.eval x) x := (p.hasDerivAt x).differentiableAt protected theorem differentiableAt_aeval : DifferentiableAt 𝕜 (fun x => aeval x q) x := (q.hasDerivAt_aeval x).differentiableAt protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 (fun x => p.eval x) s x := p.differentiableAt.differentiableWithinAt protected theorem differentiableWithinAt_aeval : DifferentiableWithinAt 𝕜 (fun x => aeval x q) s x := q.differentiableAt_aeval.differentiableWithinAt @[fun_prop] protected theorem differentiable : Differentiable 𝕜 fun x => p.eval x := fun _ => p.differentiableAt protected theorem differentiable_aeval : Differentiable 𝕜 fun x : 𝕜 => aeval x q := fun _ => q.differentiableAt_aeval protected theorem differentiableOn : DifferentiableOn 𝕜 (fun x => p.eval x) s := p.differentiable.differentiableOn protected theorem differentiableOn_aeval : DifferentiableOn 𝕜 (fun x => aeval x q) s := q.differentiable_aeval.differentiableOn @[simp] protected theorem deriv : deriv (fun x => p.eval x) x = p.derivative.eval x := (p.hasDerivAt x).deriv @[simp] protected theorem deriv_aeval : deriv (fun x => aeval x q) x = aeval x (derivative q) := (q.hasDerivAt_aeval x).deriv protected theorem derivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => p.eval x) s x = p.derivative.eval x := by rw [DifferentiableAt.derivWithin p.differentiableAt hxs] exact p.deriv protected theorem derivWithin_aeval (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => aeval x q) s x = aeval x (derivative q) := by simpa only [aeval_def, eval₂_eq_eval_map, derivative_map] using (q.map (algebraMap R 𝕜)).derivWithin hxs protected theorem hasFDerivAt (x : 𝕜) : HasFDerivAt (fun x => p.eval x) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x)) x := p.hasDerivAt x protected theorem hasFDerivAt_aeval (x : 𝕜) : HasFDerivAt (fun x => aeval x q) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (aeval x (derivative q))) x := q.hasDerivAt_aeval x protected theorem hasFDerivWithinAt (x : 𝕜) : HasFDerivWithinAt (fun x => p.eval x) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x)) s x := (p.hasFDerivAt x).hasFDerivWithinAt protected theorem hasFDerivWithinAt_aeval (x : 𝕜) : HasFDerivWithinAt (fun x => aeval x q) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (aeval x (derivative q))) s x := (q.hasFDerivAt_aeval x).hasFDerivWithinAt @[simp] protected theorem fderiv : fderiv 𝕜 (fun x => p.eval x) x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x) := (p.hasFDerivAt x).fderiv @[simp] protected theorem fderiv_aeval : fderiv 𝕜 (fun x => aeval x q) x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (aeval x (derivative q)) := (q.hasFDerivAt_aeval x).fderiv protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x => p.eval x) s x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x) := (p.hasFDerivWithinAt x).fderivWithin hxs protected theorem fderivWithin_aeval (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x => aeval x q) s x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (aeval x (derivative q)) := (q.hasFDerivWithinAt_aeval x).fderivWithin hxs end Polynomial
Even.lean
/- Copyright (c) 2024 Artie Khovanov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Artie Khovanov -/ import Mathlib.Algebra.Group.Even import Mathlib.Algebra.Group.Subgroup.Defs /-! # Squares and even elements This file defines the subgroup of squares / even elements in an abelian group. -/ assert_not_exists RelIso MonoidWithZero namespace Subsemigroup variable {S : Type*} [CommSemigroup S] variable (S) in /-- In a commutative semigroup `S`, `Subsemigroup.square S` is the subsemigroup of squares in `S`. -/ @[to_additive /-- In a commutative additive semigroup `S`, `AddSubsemigroup.even S` is the subsemigroup of even elements in `S`. -/] def square : Subsemigroup S where carrier := {s : S | IsSquare s} mul_mem' := IsSquare.mul @[to_additive (attr := simp)] theorem mem_square {a : S} : a ∈ square S ↔ IsSquare a := Iff.rfl @[to_additive (attr := simp, norm_cast)] theorem coe_square : square S = {s : S | IsSquare s} := rfl end Subsemigroup namespace Submonoid variable {M : Type*} [CommMonoid M] variable (M) in /-- In a commutative monoid `M`, `Submonoid.square M` is the submonoid of squares in `M`. -/ @[to_additive /-- In a commutative additive monoid `M`, `AddSubmonoid.even M` is the submonoid of even elements in `M`. -/] def square : Submonoid M where __ := Subsemigroup.square M one_mem' := IsSquare.one @[to_additive (attr := simp)] theorem square_toSubsemigroup : (square M).toSubsemigroup = .square M := rfl @[to_additive (attr := simp)] theorem mem_square {a : M} : a ∈ square M ↔ IsSquare a := Iff.rfl @[to_additive (attr := simp, norm_cast)] theorem coe_square : square M = {s : M | IsSquare s} := rfl end Submonoid namespace Subgroup variable {G : Type*} [CommGroup G] variable (G) in /-- In an abelian group `G`, `Subgroup.square G` is the subgroup of squares in `G`. -/ @[to_additive /-- In an abelian additive group `G`, `AddSubgroup.even G` is the subgroup of even elements in `G`. -/] def square : Subgroup G where __ := Submonoid.square G inv_mem' := IsSquare.inv @[to_additive (attr := simp)] theorem square_toSubmonoid : (square G).toSubmonoid = .square G := rfl @[to_additive (attr := simp)] theorem mem_square {a : G} : a ∈ square G ↔ IsSquare a := Iff.rfl @[to_additive (attr := simp, norm_cast)] theorem coe_square : square G = {s : G | IsSquare s} := rfl end Subgroup
Basic.lean
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Johannes Hölzl, Reid Barton, Sean Leather, Yury Kudryashov -/ import Mathlib.CategoryTheory.Types /-! # Concrete categories A concrete category is a category `C` where the objects and morphisms correspond with types and (bundled) functions between these types. We define concrete categories using `class ConcreteCategory`. To convert an object to a type, write `ToHom`. To convert a morphism to a (bundled) function, write `hom`. Each concrete category `C` comes with a canonical faithful functor `forget C : C ⥤ Type*`, see `class HasForget`. In particular, we impose no restrictions on the category `C`, so `Type` has the identity forgetful functor. We say that a concrete category `C` admits a *forgetful functor* to a concrete category `D`, if it has a functor `forget₂ C D : C ⥤ D` such that `(forget₂ C D) ⋙ (forget D) = forget C`, see `class HasForget₂`. Due to `Faithful.div_comp`, it suffices to verify that `forget₂.obj` and `forget₂.map` agree with the equality above; then `forget₂` will satisfy the functor laws automatically, see `HasForget₂.mk'`. Two classes helping construct concrete categories in the two most common cases are provided in the files `BundledHom` and `UnbundledHom`, see their documentation for details. ## Implementation notes We are currently switching over from `HasForget` to a new class `ConcreteCategory`, see Zulip thread: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Concrete.20category.20class.20redesign Previously, `ConcreteCategory` had the same definition as now `HasForget`; the coercion of objects/morphisms to types/functions was defined as `(forget C).obj` and `(forget C).map` respectively. This leads to defeq issues since existing `CoeFun` and `FunLike` instances provide their own casts. We replace this with a less bundled `ConcreteCategory` that does not directly use these coercions. We do not use `CoeSort` to convert objects in a concrete category to types, since this would lead to elaboration mismatches between results taking a `[ConcreteCategory C]` instance and specific types `C` that hold a `ConcreteCategory C` instance: the first gets a literal `CoeSort.coe` and the second gets unfolded to the actual `coe` field. `ToType` and `ToHom` are `abbrev`s so that we do not need to copy over instances such as `Ring` or `RingHomClass` respectively. Since `X → Y` is not a `FunLike`, the category of types is not a `ConcreteCategory`, but it does have a `HasForget` instance. ## References See [Ahrens and Lumsdaine, *Displayed Categories*][ahrens2017] for related work. -/ assert_not_exists CategoryTheory.CommSq CategoryTheory.Adjunction universe w w' v v' v'' u u' u'' namespace CategoryTheory /-- A concrete category is a category `C` with a fixed faithful functor `Forget : C ⥤ Type`. Note that `HasForget` potentially depends on three independent universe levels, * the universe level `w` appearing in `Forget : C ⥤ Type w` * the universe level `v` of the morphisms (i.e. we have a `Category.{v} C`) * the universe level `u` of the objects (i.e `C : Type u`) They are specified that order, to avoid unnecessary universe annotations. -/ class HasForget (C : Type u) [Category.{v} C] where /-- We have a functor to Type -/ protected forget : C ⥤ Type w /-- That functor is faithful -/ [forget_faithful : forget.Faithful] attribute [inline, reducible] HasForget.forget attribute [instance] HasForget.forget_faithful /-- The forgetful functor from a concrete category to `Type u`. -/ abbrev forget (C : Type u) [Category.{v} C] [HasForget.{w} C] : C ⥤ Type w := HasForget.forget -- this is reducible because we want `forget (Type u)` to unfold to `𝟭 _` @[instance] abbrev HasForget.types : HasForget.{u, u, u+1} (Type u) where forget := 𝟭 _ /-- Provide a coercion to `Type u` for a concrete category. This is not marked as an instance as it could potentially apply to every type, and so is too expensive in typeclass search. You can use it on particular examples as: ``` instance : HasCoeToSort X := HasForget.hasCoeToSort X ``` -/ def HasForget.hasCoeToSort (C : Type u) [Category.{v} C] [HasForget.{w} C] : CoeSort C (Type w) where coe X := (forget C).obj X section attribute [local instance] HasForget.hasCoeToSort variable {C : Type u} [Category.{v} C] [HasForget.{w} C] /-- In any concrete category, `(forget C).map` is injective. -/ abbrev HasForget.instFunLike {X Y : C} : FunLike (X ⟶ Y) X Y where coe f := (forget C).map f coe_injective' _ _ h := (forget C).map_injective h attribute [local instance] HasForget.instFunLike /-- In any concrete category, we can test equality of morphisms by pointwise evaluations. -/ @[ext low] theorem ConcreteCategory.hom_ext {X Y : C} (f g : X ⟶ Y) (w : ∀ x : X, f x = g x) : f = g := by apply (forget C).map_injective dsimp [forget] funext x exact w x theorem forget_map_eq_coe {X Y : C} (f : X ⟶ Y) : (forget C).map f = f := rfl /-- Analogue of `congr_fun h x`, when `h : f = g` is an equality between morphisms in a concrete category. -/ theorem congr_hom {X Y : C} {f g : X ⟶ Y} (h : f = g) (x : X) : f x = g x := congrFun (congrArg (fun k : X ⟶ Y => (k : X → Y)) h) x theorem coe_id {X : C} : (𝟙 X : X → X) = id := (forget _).map_id X theorem coe_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g : X → Z) = g ∘ f := (forget _).map_comp f g @[simp] theorem id_apply {X : C} (x : X) : (𝟙 X : X → X) x = x := congr_fun ((forget _).map_id X) x @[simp] theorem comp_apply {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := congr_fun ((forget _).map_comp _ _) x /-- Variation of `ConcreteCategory.comp_apply` that uses `forget` instead. -/ theorem comp_apply' {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (forget C).map (f ≫ g) x = (forget C).map g ((forget C).map f x) := comp_apply f g x theorem ConcreteCategory.congr_hom {X Y : C} {f g : X ⟶ Y} (h : f = g) (x : X) : f x = g x := congr_fun (congr_arg (fun f : X ⟶ Y => (f : X → Y)) h) x theorem ConcreteCategory.congr_arg {X Y : C} (f : X ⟶ Y) {x x' : X} (h : x = x') : f x = f x' := congrArg (f : X → Y) h @[simp] theorem ConcreteCategory.hasCoeToFun_Type {X Y : Type u} (f : X ⟶ Y) : CoeFun.coe f = f := rfl end /-- `HasForget₂ C D`, where `C` and `D` are both concrete categories, provides a functor `forget₂ C D : C ⥤ D` and a proof that `forget₂ ⋙ (forget D) = forget C`. -/ class HasForget₂ (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] where /-- A functor from `C` to `D` -/ forget₂ : C ⥤ D /-- It covers the `HasForget.forget` for `C` and `D` -/ forget_comp : forget₂ ⋙ forget D = forget C := by aesop /-- The forgetful functor `C ⥤ D` between concrete categories for which we have an instance `HasForget₂ C`. -/ abbrev forget₂ (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] : C ⥤ D := HasForget₂.forget₂ attribute [local instance] HasForget.instFunLike HasForget.hasCoeToSort lemma forget₂_comp_apply {C : Type u} {D : Type u'} [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : (forget₂ C D).obj X) : ((forget₂ C D).map (f ≫ g) x) = (forget₂ C D).map g ((forget₂ C D).map f x) := by rw [Functor.map_comp, comp_apply] instance forget₂_faithful (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] : (forget₂ C D).Faithful := HasForget₂.forget_comp.faithful_of_comp instance InducedCategory.hasForget {C : Type u} {D : Type u'} [Category.{v'} D] [HasForget.{w} D] (f : C → D) : HasForget (InducedCategory D f) where forget := inducedFunctor f ⋙ forget D instance InducedCategory.hasForget₂ {C : Type u} {D : Type u'} [Category.{v} D] [HasForget.{w} D] (f : C → D) : HasForget₂ (InducedCategory D f) D where forget₂ := inducedFunctor f forget_comp := rfl instance FullSubcategory.hasForget {C : Type u} [Category.{v} C] [HasForget.{w} C] (P : ObjectProperty C) : HasForget P.FullSubcategory where forget := P.ι ⋙ forget C instance FullSubcategory.hasForget₂ {C : Type u} [Category.{v} C] [HasForget.{w} C] (P : ObjectProperty C) : HasForget₂ P.FullSubcategory C where forget₂ := P.ι forget_comp := rfl /-- In order to construct a “partially forgetting” functor, we do not need to verify functor laws; it suffices to ensure that compositions agree with `forget₂ C D ⋙ forget D = forget C`. -/ def HasForget₂.mk' {C : Type u} {D : Type u'} [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] (obj : C → D) (h_obj : ∀ X, (forget D).obj (obj X) = (forget C).obj X) (map : ∀ {X Y}, (X ⟶ Y) → (obj X ⟶ obj Y)) (h_map : ∀ {X Y} {f : X ⟶ Y}, (forget D).map (map f) ≍ (forget C).map f) : HasForget₂ C D where forget₂ := Functor.Faithful.div _ _ _ @h_obj _ @h_map forget_comp := by apply Functor.Faithful.div_comp /-- Composition of `HasForget₂` instances. -/ @[reducible] def HasForget₂.trans (C : Type u) [Category.{v} C] [HasForget.{w} C] (D : Type u') [Category.{v'} D] [HasForget.{w} D] (E : Type u'') [Category.{v''} E] [HasForget.{w} E] [HasForget₂ C D] [HasForget₂ D E] : HasForget₂ C E where forget₂ := CategoryTheory.forget₂ C D ⋙ CategoryTheory.forget₂ D E forget_comp := by change (CategoryTheory.forget₂ _ D) ⋙ (CategoryTheory.forget₂ D E ⋙ CategoryTheory.forget E) = _ simp only [HasForget₂.forget_comp] /-- Every forgetful functor factors through the identity functor. This is not a global instance as it is prone to creating type class resolution loops. -/ def hasForgetToType (C : Type u) [Category.{v} C] [HasForget.{w} C] : HasForget₂ C (Type w) where forget₂ := forget C forget_comp := Functor.comp_id _ section ConcreteCategory /-- A concrete category is a category `C` where objects correspond to types and morphisms to (bundled) functions between those types. In other words, it has a fixed faithful functor `forget : C ⥤ Type`. Note that `ConcreteCategory` potentially depends on three independent universe levels, * the universe level `w` appearing in `forget : C ⥤ Type w` * the universe level `v` of the morphisms (i.e. we have a `Category.{v} C`) * the universe level `u` of the objects (i.e `C : Type u`) They are specified that order, to avoid unnecessary universe annotations. -/ class ConcreteCategory (C : Type u) [Category.{v} C] (FC : outParam <| C → C → Type*) {CC : outParam <| C → Type w} [outParam <| ∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] where /-- Convert a morphism of `C` to a bundled function. -/ (hom : ∀ {X Y}, (X ⟶ Y) → FC X Y) /-- Convert a bundled function to a morphism of `C`. -/ (ofHom : ∀ {X Y}, FC X Y → (X ⟶ Y)) (hom_ofHom : ∀ {X Y} (f : FC X Y), hom (ofHom f) = f := by cat_disch) (ofHom_hom : ∀ {X Y} (f : X ⟶ Y), ofHom (hom f) = f := by cat_disch) (id_apply : ∀ {X} (x : CC X), hom (𝟙 X) x = x := by cat_disch) (comp_apply : ∀ {X Y Z} (f : X ⟶ Y) (g : Y ⟶ Z) (x : CC X), hom (f ≫ g) x = hom g (hom f x) := by cat_disch) export ConcreteCategory (id_apply comp_apply) variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] variable [ConcreteCategory C FC] /-- `ToType X` converts the object `X` of the concrete category `C` to a type. This is an `abbrev` so that instances on `X` (e.g. `Ring`) do not need to be redeclared. -/ @[nolint unusedArguments] -- Need the instance to trigger unification that finds `CC`. abbrev ToType [ConcreteCategory C FC] := CC /-- `ToHom X Y` is the type of (bundled) functions between objects `X Y : C`. This is an `abbrev` so that instances (e.g. `RingHomClass`) do not need to be redeclared. -/ @[nolint unusedArguments] -- Need the instance to trigger unification that finds `FC`. abbrev ToHom [ConcreteCategory C FC] := FC namespace ConcreteCategory attribute [simp] id_apply comp_apply /-- We can apply morphisms of concrete categories by first casting them down to the base functions. -/ instance {X Y : C} : CoeFun (X ⟶ Y) (fun _ ↦ ToType X → ToType Y) where coe f := hom f /-- `ConcreteCategory.hom` bundled as an `Equiv`. -/ def homEquiv {X Y : C} : (X ⟶ Y) ≃ ToHom X Y where toFun := hom invFun := ofHom left_inv := ofHom_hom right_inv := hom_ofHom lemma hom_bijective {X Y : C} : Function.Bijective (hom : (X ⟶ Y) → ToHom X Y) := homEquiv.bijective lemma hom_injective {X Y : C} : Function.Injective (hom : (X ⟶ Y) → ToHom X Y) := hom_bijective.injective /-- In any concrete category, we can test equality of morphisms by pointwise evaluations. -/ @[ext] lemma ext {X Y : C} {f g : X ⟶ Y} (h : hom f = hom g) : f = g := hom_injective h lemma coe_ext {X Y : C} {f g : X ⟶ Y} (h : ⇑(hom f) = ⇑(hom g)) : f = g := ext (DFunLike.coe_injective h) lemma ext_apply {X Y : C} {f g : X ⟶ Y} (h : ∀ x, f x = g x) : f = g := ext (DFunLike.ext _ _ h) /-- A concrete category comes with a forgetful functor to `Type`. Warning: because of the way that `ConcreteCategory` and `HasForget` are set up, we can't make `forget Type` reducibly defeq to the identity functor. -/ instance toHasForget : HasForget C where forget.obj := ToType forget.map f := ⇑(hom f) forget_faithful.map_injective h := coe_ext h end ConcreteCategory theorem forget_obj (X : C) : (forget C).obj X = ToType X := rfl @[simp] theorem ConcreteCategory.forget_map_eq_coe {X Y : C} (f : X ⟶ Y) : (forget C).map f = f := rfl /-- Analogue of `congr_fun h x`, when `h : f = g` is an equality between morphisms in a concrete category. -/ protected theorem congr_fun {X Y : C} {f g : X ⟶ Y} (h : f = g) (x : ToType X) : f x = g x := congrFun (congrArg (fun k : X ⟶ Y => (k : ToType X → ToType Y)) h) x /-- Analogue of `congr_arg f h`, when `h : x = x'` is an equality between elements of objects in a concrete category. -/ protected theorem congr_arg {X Y : C} (f : X ⟶ Y) {x x' : ToType X} (h : x = x') : f x = f x' := congrArg (f : ToType X → ToType Y) h theorem hom_id {X : C} : (𝟙 X : ToType X → ToType X) = id := (forget _).map_id X theorem hom_comp {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g : ToType X → ToType Z) = g ∘ f := (forget _).map_comp f g /-- Using the `FunLike` coercion of `HasForget` does the same as the original coercion. -/ theorem coe_toHasForget_instFunLike {C : Type*} [Category C] {FC : C → C → Type*} {CC : C → Type*} [inst : ∀ X Y : C, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC] {X Y : C} (f : X ⟶ Y) : @DFunLike.coe (X ⟶ Y) (ToType X) (fun _ => ToType Y) HasForget.instFunLike f = f := rfl lemma ConcreteCategory.forget₂_comp_apply {C : Type u} {D : Type u'} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] [Category.{v'} D] {FD : D → D → Type*} {CD : D → Type w} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{w} D FD] [HasForget₂ C D] {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (x : ToType ((forget₂ C D).obj X)) : ((forget₂ C D).map (f ≫ g) x) = (forget₂ C D).map g ((forget₂ C D).map f x) := by rw [Functor.map_comp, ConcreteCategory.comp_apply] instance hom_isIso {X Y : C} (f : X ⟶ Y) [IsIso f] : IsIso (C := Type _) ⇑(ConcreteCategory.hom f) := ((forget C).mapIso (asIso f)).isIso_hom @[simp] lemma NatTrans.naturality_apply {C D : Type*} [Category C] [Category D] {FD : D → D → Type*} {CD : D → Type*} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory D FD] {F G : C ⥤ D} (φ : F ⟶ G) {X Y : C} (f : X ⟶ Y) (x : ToType (F.obj X)) : φ.app Y (F.map f x) = G.map f (φ.app X x) := by simpa only [Functor.map_comp] using congr_fun ((forget D).congr_map (φ.naturality f)) x section variable (C) /-- Build a coercion to functions out of `HasForget`. The intended usecase is to provide a `FunLike` instance in `HasForget.toConcreteCategory`. See that definition for the considerations in making this an instance. See note [reducible non-instances]. -/ abbrev HasForget.toFunLike [HasForget C] (X Y : C) : FunLike (X ⟶ Y) ((forget C).obj X) ((forget C).obj Y) where coe := (forget C).map coe_injective' _ _ h := Functor.Faithful.map_injective h /-- Build a concrete category out of `HasForget`. The intended usecase is to prove theorems referencing only `(forget C)` and not `(forget C).obj X` nor `(forget C).map f`: those should be written as `ToType X` and `ConcreteCategory.hom f` respectively. See note [reducible non-instances]. -/ abbrev HasForget.toConcreteCategory [HasForget C] : ConcreteCategory C (· ⟶ ·) where hom f := f ofHom f := f id_apply := congr_fun ((forget C).map_id _) comp_apply _ _ := congr_fun ((forget C).map_comp _ _) /-- Check that the new `ConcreteCategory` has the same forgetful functor as we started with. -/ example [inst : HasForget C] : @forget C _ ((HasForget.toConcreteCategory _).toHasForget) = @forget C _ inst := by with_reducible_and_instances rfl /-- Note that the `ConcreteCategory` and `HasForget` instances here differ from `forget_map_eq_coe`. -/ theorem forget_eq_ConcreteCategory_hom [HasForget C] {X Y : C} (f : X ⟶ Y) : (forget C).map f = @ConcreteCategory.hom _ _ _ _ _ (HasForget.toConcreteCategory C) _ _ f := by with_reducible_and_instances rfl /-- A `FunLike` instance on plain functions, in order to instantiate a `ConcreteCategory` structure on the category of types. This is not an instance (yet) because that would require a lot of downstream fixes. See note [reducible non-instances]. -/ abbrev Types.instFunLike : ∀ X Y : Type u, FunLike (X ⟶ Y) X Y := HasForget.toFunLike _ /-- The category of types is concrete, using the identity functor. This is not an instance (yet) because that would require a lot of downstream fixes. See note [reducible non-instances]. -/ abbrev Types.instConcreteCategory : ConcreteCategory (Type u) (fun X Y => X ⟶ Y) where hom f := f ofHom f := f end open ConcreteCategory instance InducedCategory.concreteCategory {C : Type u} {D : Type u'} [Category.{v'} D] {FD : D → D → Type*} {CD : D → Type w} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{w} D FD] (f : C → D) : ConcreteCategory (InducedCategory D f) (fun X Y => FD (f X) (f Y)) where hom := hom (C := D) ofHom := ofHom (C := D) hom_ofHom := hom_ofHom (C := D) ofHom_hom := ofHom_hom (C := D) comp_apply := ConcreteCategory.comp_apply (C := D) id_apply := ConcreteCategory.id_apply (C := D) instance FullSubcategory.concreteCategory {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] (P : ObjectProperty C) : ConcreteCategory P.FullSubcategory (fun X Y => FC X.1 Y.1) where hom := hom (C := C) ofHom := ofHom (C := C) hom_ofHom := hom_ofHom (C := C) ofHom_hom := ofHom_hom (C := C) comp_apply := ConcreteCategory.comp_apply (C := C) id_apply := ConcreteCategory.id_apply (C := C) end ConcreteCategory end CategoryTheory
PPRoundtrip.lean
/- Copyright (c) 2024 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Lean.Elab.Command import Mathlib.Init /-! # The "ppRoundtrip" linter The "ppRoundtrip" linter emits a warning when the syntax of a command differs substantially from the pretty-printed version of itself. -/ open Lean Elab Command Linter namespace Mathlib.Linter /-- The "ppRoundtrip" linter emits a warning when the syntax of a command differs substantially from the pretty-printed version of itself. The linter makes an effort to start the highlighting at the first difference. However, it may not always be successful. It also prints both the source code and the "expected code" in a 5-character radius from the first difference. -/ register_option linter.ppRoundtrip : Bool := { defValue := false descr := "enable the ppRoundtrip linter" } /-- `polishPP s` takes as input a `String` `s`, assuming that it is the output of pretty-printing a lean command. The main intent is to convert `s` to a reasonable candidate for a desirable source code format. The function first replaces consecutive whitespace sequences into a single space (` `), in an attempt to side-step line-break differences. After that, it applies some pre-emptive changes: * doc-module beginnings tend to have some whitespace following them, so we add a space back in; * name quotations such as ``` ``Nat``` get pretty-printed as ``` `` Nat```, so we remove a space after double back-ticks, but take care of adding one more for triple (or more) back-ticks; * `notation3` is not followed by a pretty-printer space, so we add it here (https://github.com/leanprover-community/mathlib4/pull/15515). -/ def polishPP (s : String) : String := let s := s.split (·.isWhitespace) (" ".intercalate (s.filter (!·.isEmpty))) |>.replace "/-!" "/-! " |>.replace "``` " "``` " -- avoid losing an existing space after the triple back-ticks -- as a consequence of the following replacement |>.replace "`` " "``" -- weird pp ```#eval ``«Nat»``` pretty-prints as ```#eval `` «Nat»``` |>.replace "notation3(" "notation3 (" |>.replace "notation3\"" "notation3 \"" /-- `polishSource s` is similar to `polishPP s`, but expects the input to be actual source code. For this reason, `polishSource s` performs more conservative changes: it only replace all whitespace starting from a linebreak (`\n`) with a single whitespace. -/ def polishSource (s : String) : String × Array Nat := let split := s.split (· == '\n') let preWS := split.foldl (init := #[]) fun p q => let txt := q.trimLeft.length (p.push (q.length - txt)).push txt let preWS := preWS.eraseIdxIfInBounds 0 let s := (split.map .trimLeft).filter (· != "") (" ".intercalate (s.filter (!·.isEmpty)), preWS) /-- `posToShiftedPos lths diff` takes as input an array `lths` of natural numbers, and one further natural number `diff`. It adds up the elements of `lths` occupying the odd positions, as long as the sum of the elements in the even positions does not exceed `diff`. It returns the sum of the accumulated odds and `diff`. This is useful to figure out the difference between the output of `polishSource s` and `s` itself. It plays a role similar to the `fileMap`. -/ def posToShiftedPos (lths : Array Nat) (diff : Nat) : Nat := Id.run do let mut (ws, noWS) := (diff, 0) for con in [:lths.size / 2] do let curr := lths[2 * con]! if noWS + curr < diff then noWS := noWS + curr ws := ws + lths[2 * con + 1]! else break return ws /-- `zoomString str centre offset` returns the substring of `str` consisting of the `offset` characters around the `centre`th character. -/ def zoomString (str : String) (centre offset : Nat) : Substring := { str := str, startPos := ⟨centre - offset⟩, stopPos := ⟨centre + offset⟩ } /-- `capSourceInfo s p` "shortens" all end-position information in the `SourceInfo` `s` to be at most `p`, trimming down also the relevant substrings. -/ def capSourceInfo (s : SourceInfo) (p : Nat) : SourceInfo := match s with | .original leading pos trailing endPos => .original leading pos {trailing with stopPos := ⟨min endPos.1 p⟩} ⟨min endPos.1 p⟩ | .synthetic pos endPos canonical => .synthetic pos ⟨min endPos.1 p⟩ canonical | .none => s /-- `capSyntax stx p` applies `capSourceInfo · s` to all `SourceInfo`s in all `node`s, `atom`s and `ident`s contained in `stx`. This is used to trim away all "fluff" that follows a command: comments and whitespace after a command get removed with `capSyntax stx stx.getTailPos?.get!`. -/ partial def capSyntax (stx : Syntax) (p : Nat) : Syntax := match stx with | .node si k args => .node (capSourceInfo si p) k (args.map (capSyntax · p)) | .atom si val => .atom (capSourceInfo si p) (val.take p) | .ident si r v pr => .ident (capSourceInfo si p) { r with stopPos := ⟨min r.stopPos.1 p⟩ } v pr | s => s namespace PPRoundtrip @[inherit_doc Mathlib.Linter.linter.ppRoundtrip] def ppRoundtrip : Linter where run := withSetOptionIn fun stx ↦ do unless getLinterValue linter.ppRoundtrip (← getLinterOptions) do return if (← MonadState.get).messages.hasErrors then return let stx := capSyntax stx (stx.getTailPos?.getD default).1 let origSubstring := stx.getSubstring?.getD default let (real, lths) := polishSource origSubstring.toString let fmt ← (liftCoreM do PrettyPrinter.ppCategory `command stx <|> (do Linter.logLint linter.ppRoundtrip stx m!"The ppRoundtrip linter had some parsing issues: \ feel free to silence it with `set_option linter.ppRoundtrip false in` \ and report this error!" return real)) let st := polishPP fmt.pretty if st != real then let diff := real.firstDiffPos st let pos := posToShiftedPos lths diff.1 + origSubstring.startPos.1 let f := origSubstring.str.drop (pos) let extraLth := (f.takeWhile (· != st.get diff)).length let srcCtxt := zoomString real diff.1 5 let ppCtxt := zoomString st diff.1 5 Linter.logLint linter.ppRoundtrip (.ofRange ⟨⟨pos⟩, ⟨pos + extraLth + 1⟩⟩) m!"source context\n'{srcCtxt}'\n'{ppCtxt}'\npretty-printed context" initialize addLinter ppRoundtrip end Mathlib.Linter.PPRoundtrip
Zorn.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.Order.CompleteLattice.Chain import Mathlib.Order.Minimal /-! # Zorn's lemmas This file proves several formulations of Zorn's Lemma. ## Variants The primary statement of Zorn's lemma is `exists_maximal_of_chains_bounded`. Then it is specialized to particular relations: * `(≤)` with `zorn_le` * `(⊆)` with `zorn_subset` * `(⊇)` with `zorn_superset` Lemma names carry modifiers: * `₀`: Quantifies over a set, as opposed to over a type. * `_nonempty`: Doesn't ask to prove that the empty chain is bounded and lets you give an element that will be smaller than the maximal element found (the maximal element is no smaller than any other element, but it can also be incomparable to some). ## How-to This file comes across as confusing to those who haven't yet used it, so here is a detailed walkthrough: 1. Know what relation on which type/set you're looking for. See Variants above. You can discharge some conditions to Zorn's lemma directly using a `_nonempty` variant. 2. Write down the definition of your type/set, put a `suffices ∃ m, ∀ a, m ≺ a → a ≺ m by ...` (or whatever you actually need) followed by an `apply some_version_of_zorn`. 3. Fill in the details. This is where you start talking about chains. A typical proof using Zorn could look like this ```lean lemma zorny_lemma : zorny_statement := by let s : Set α := {x | whatever x} suffices ∃ x ∈ s, ∀ y ∈ s, y ⊆ x → y = x by -- or with another operator xxx proof_post_zorn apply zorn_subset -- or another variant rintro c hcs hc obtain rfl | hcnemp := c.eq_empty_or_nonempty -- you might need to disjunct on c empty or not · exact ⟨edge_case_construction, proof_that_edge_case_construction_respects_whatever, proof_that_edge_case_construction_contains_all_stuff_in_c⟩ · exact ⟨construction, proof_that_construction_respects_whatever, proof_that_construction_contains_all_stuff_in_c⟩ ``` ## Notes Originally ported from Isabelle/HOL. The [original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D. Fleuriot, Tobias Nipkow, Christian Sternagel. -/ open Set variable {α β : Type*} {r : α → α → Prop} {c : Set α} /-- Local notation for the relation being considered. -/ local infixl:50 " ≺ " => r /-- **Zorn's lemma** If every chain has an upper bound, then there exists a maximal element. -/ theorem exists_maximal_of_chains_bounded (h : ∀ c, IsChain r c → ∃ ub, ∀ a ∈ c, a ≺ ub) (trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) : ∃ m, ∀ a, m ≺ a → a ≺ m := have : ∃ ub, ∀ a ∈ maxChain r, a ≺ ub := h _ <| maxChain_spec.left let ⟨ub, (hub : ∀ a ∈ maxChain r, a ≺ ub)⟩ := this ⟨ub, fun a ha => have : IsChain r (insert a <| maxChain r) := maxChain_spec.1.insert fun b hb _ => Or.inr <| trans (hub b hb) ha hub a <| by rw [maxChain_spec.right this (subset_insert _ _)] exact mem_insert _ _⟩ /-- A variant of Zorn's lemma. If every nonempty chain of a nonempty type has an upper bound, then there is a maximal element. -/ theorem exists_maximal_of_nonempty_chains_bounded [Nonempty α] (h : ∀ c, IsChain r c → c.Nonempty → ∃ ub, ∀ a ∈ c, a ≺ ub) (trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) : ∃ m, ∀ a, m ≺ a → a ≺ m := exists_maximal_of_chains_bounded (fun c hc => (eq_empty_or_nonempty c).elim (fun h => ⟨Classical.arbitrary α, fun x hx => (h ▸ hx : x ∈ (∅ : Set α)).elim⟩) (h c hc)) trans section Preorder variable [Preorder α] theorem zorn_le (h : ∀ c : Set α, IsChain (· ≤ ·) c → BddAbove c) : ∃ m : α, IsMax m := exists_maximal_of_chains_bounded h le_trans theorem zorn_le_nonempty [Nonempty α] (h : ∀ c : Set α, IsChain (· ≤ ·) c → c.Nonempty → BddAbove c) : ∃ m : α, IsMax m := exists_maximal_of_nonempty_chains_bounded h le_trans theorem zorn_le₀ (s : Set α) (ih : ∀ c ⊆ s, IsChain (· ≤ ·) c → ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) : ∃ m, Maximal (· ∈ s) m := let ⟨⟨m, hms⟩, h⟩ := @zorn_le s _ fun c hc => let ⟨ub, hubs, hub⟩ := ih (Subtype.val '' c) (fun _ ⟨⟨_, hx⟩, _, h⟩ => h ▸ hx) (by rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq exact hc hpc hqc fun t => hpq (Subtype.ext_iff.1 t)) ⟨⟨ub, hubs⟩, fun ⟨_, _⟩ hc => hub _ ⟨_, hc, rfl⟩⟩ ⟨m, hms, fun z hzs hmz => @h ⟨z, hzs⟩ hmz⟩ theorem zorn_le_nonempty₀ (s : Set α) (ih : ∀ c ⊆ s, IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) (x : α) (hxs : x ∈ s) : ∃ m, x ≤ m ∧ Maximal (· ∈ s) m := by have H := zorn_le₀ ({ y ∈ s | x ≤ y }) fun c hcs hc => ?_ · rcases H with ⟨m, ⟨hms, hxm⟩, hm⟩ exact ⟨m, hxm, hms, fun z hzs hmz => @hm _ ⟨hzs, hxm.trans hmz⟩ hmz⟩ · rcases c.eq_empty_or_nonempty with (rfl | ⟨y, hy⟩) · exact ⟨x, ⟨hxs, le_rfl⟩, fun z => False.elim⟩ · rcases ih c (fun z hz => (hcs hz).1) hc y hy with ⟨z, hzs, hz⟩ exact ⟨z, ⟨hzs, (hcs hy).2.trans <| hz _ hy⟩, hz⟩ theorem zorn_le_nonempty_Ici₀ (a : α) (ih : ∀ c ⊆ Ici a, IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub, ∀ z ∈ c, z ≤ ub) (x : α) (hax : a ≤ x) : ∃ m, x ≤ m ∧ IsMax m := by let ⟨m, hxm, ham, hm⟩ := zorn_le_nonempty₀ (Ici a) (fun c hca hc y hy ↦ ?_) x hax · exact ⟨m, hxm, fun z hmz => hm (ham.trans hmz) hmz⟩ · have ⟨ub, hub⟩ := ih c hca hc y hy exact ⟨ub, (hca hy).trans (hub y hy), hub⟩ end Preorder theorem zorn_subset (S : Set (Set α)) (h : ∀ c ⊆ S, IsChain (· ⊆ ·) c → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) : ∃ m, Maximal (· ∈ S) m := zorn_le₀ S h theorem zorn_subset_nonempty (S : Set (Set α)) (H : ∀ c ⊆ S, IsChain (· ⊆ ·) c → c.Nonempty → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) (x) (hx : x ∈ S) : ∃ m, x ⊆ m ∧ Maximal (· ∈ S) m := zorn_le_nonempty₀ _ (fun _ cS hc y yc => H _ cS hc ⟨y, yc⟩) _ hx theorem zorn_superset (S : Set (Set α)) (h : ∀ c ⊆ S, IsChain (· ⊆ ·) c → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) : ∃ m, Minimal (· ∈ S) m := (@zorn_le₀ (Set α)ᵒᵈ _ S) fun c cS hc => h c cS hc.symm theorem zorn_superset_nonempty (S : Set (Set α)) (H : ∀ c ⊆ S, IsChain (· ⊆ ·) c → c.Nonempty → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) (x) (hx : x ∈ S) : ∃ m, m ⊆ x ∧ Minimal (· ∈ S) m := @zorn_le_nonempty₀ (Set α)ᵒᵈ _ S (fun _ cS hc y yc => H _ cS hc.symm ⟨y, yc⟩) _ hx /-- Every chain is contained in a maximal chain. This generalizes Hausdorff's maximality principle. -/ theorem IsChain.exists_maxChain (hc : IsChain r c) : ∃ M, @IsMaxChain _ r M ∧ c ⊆ M := by have H := zorn_subset_nonempty { s | c ⊆ s ∧ IsChain r s } ?_ c ⟨Subset.rfl, hc⟩ · obtain ⟨M, hcM, hM⟩ := H exact ⟨M, ⟨hM.prop.2, fun d hd hMd ↦ hM.eq_of_subset ⟨hcM.trans hMd, hd⟩ hMd⟩, hcM⟩ rintro cs hcs₀ hcs₁ ⟨s, hs⟩ refine ⟨⋃₀cs, ⟨fun _ ha => Set.mem_sUnion_of_mem ((hcs₀ hs).left ha) hs, ?_⟩, fun _ => Set.subset_sUnion_of_mem⟩ rintro y ⟨sy, hsy, hysy⟩ z ⟨sz, hsz, hzsz⟩ hyz obtain rfl | hsseq := eq_or_ne sy sz · exact (hcs₀ hsy).right hysy hzsz hyz rcases hcs₁ hsy hsz hsseq with h | h · exact (hcs₀ hsz).right (h hysy) hzsz hyz · exact (hcs₀ hsy).right hysy (h hzsz) hyz /-! ### Flags -/ namespace Flag variable [Preorder α] {c : Set α} {s : Flag α} {a b : α} lemma _root_.IsChain.exists_subset_flag (hc : IsChain (· ≤ ·) c) : ∃ s : Flag α, c ⊆ s := let ⟨s, hs, hcs⟩ := hc.exists_maxChain; ⟨ofIsMaxChain s hs, hcs⟩ lemma exists_mem (a : α) : ∃ s : Flag α, a ∈ s := let ⟨s, hs⟩ := Set.subsingleton_singleton (a := a).isChain.exists_subset_flag ⟨s, hs rfl⟩ lemma exists_mem_mem (hab : a ≤ b) : ∃ s : Flag α, a ∈ s ∧ b ∈ s := by simpa [Set.insert_subset_iff] using (IsChain.pair hab).exists_subset_flag instance : Nonempty (Flag α) := ⟨.ofIsMaxChain _ maxChain_spec⟩ end Flag
CountablyGenerated.lean
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Yury Kudryashov, Patrick Massot -/ import Mathlib.Data.Set.Countable import Mathlib.Order.Filter.Bases.Finite /-! # Countably generated filters In this file we define a typeclass `Filter.IsCountablyGenerated` saying that a filter is generated by a countable family of sets. We also define predicates `Filter.IsCountableBasis` and `Filter.HasCountableBasis` saying that a specific family of sets is a countable basis. -/ open Set namespace Filter variable {α β γ ι : Type*} {ι' : Sort*} /-- `IsCountablyGenerated f` means `f = generate s` for some countable `s`. -/ class IsCountablyGenerated (f : Filter α) : Prop where /-- There exists a countable set that generates the filter. -/ out : ∃ s : Set (Set α), s.Countable ∧ f = generate s /-- `IsCountableBasis p s` means the image of `s` bounded by `p` is a countable filter basis. -/ structure IsCountableBasis (p : ι → Prop) (s : ι → Set α) : Prop extends IsBasis p s where /-- The set of `i` that satisfy the predicate `p` is countable. -/ countable : (setOf p).Countable /-- We say that a filter `l` has a countable basis `s : ι → Set α` bounded by `p : ι → Prop`, if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`, and the set defined by `p` is countable. -/ structure HasCountableBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop extends HasBasis l p s where /-- The set of `i` that satisfy the predicate `p` is countable. -/ countable : (setOf p).Countable /-- A countable filter basis `B` on a type `α` is a nonempty countable collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. -/ structure CountableFilterBasis (α : Type*) extends FilterBasis α where /-- The set of sets of the filter basis is countable. -/ countable : sets.Countable -- For illustration purposes, the countable filter basis defining `(atTop : Filter ℕ)` instance Nat.inhabitedCountableFilterBasis : Inhabited (CountableFilterBasis ℕ) := ⟨⟨default, countable_range fun n => Ici n⟩⟩ theorem HasCountableBasis.isCountablyGenerated {f : Filter α} {p : ι → Prop} {s : ι → Set α} (h : f.HasCountableBasis p s) : f.IsCountablyGenerated := ⟨⟨{ t | ∃ i, p i ∧ s i = t }, h.countable.image s, h.toHasBasis.eq_generate⟩⟩ theorem HasBasis.isCountablyGenerated [Countable ι] {f : Filter α} {p : ι → Prop} {s : ι → Set α} (h : f.HasBasis p s) : f.IsCountablyGenerated := HasCountableBasis.isCountablyGenerated ⟨h, to_countable _⟩ theorem antitone_seq_of_seq (s : ℕ → Set α) : ∃ t : ℕ → Set α, Antitone t ∧ ⨅ i, 𝓟 (s i) = ⨅ i, 𝓟 (t i) := by use fun n => ⋂ m ≤ n, s m; constructor · exact fun i j hij => biInter_mono (Iic_subset_Iic.2 hij) fun n _ => Subset.rfl apply le_antisymm <;> rw [le_iInf_iff] <;> intro i · rw [le_principal_iff] refine (biInter_mem (finite_le_nat _)).2 fun j _ => ?_ exact mem_iInf_of_mem j (mem_principal_self _) · refine iInf_le_of_le i (principal_mono.2 <| iInter₂_subset i ?_) rfl theorem countable_biInf_eq_iInf_seq [CompleteLattice α] {B : Set ι} (Bcbl : B.Countable) (Bne : B.Nonempty) (f : ι → α) : ∃ x : ℕ → ι, ⨅ t ∈ B, f t = ⨅ i, f (x i) := let ⟨g, hg⟩ := Bcbl.exists_eq_range Bne ⟨g, hg.symm ▸ iInf_range⟩ theorem countable_biInf_eq_iInf_seq' [CompleteLattice α] {B : Set ι} (Bcbl : B.Countable) (f : ι → α) {i₀ : ι} (h : f i₀ = ⊤) : ∃ x : ℕ → ι, ⨅ t ∈ B, f t = ⨅ i, f (x i) := by rcases B.eq_empty_or_nonempty with hB | Bnonempty · rw [hB, iInf_emptyset] use fun _ => i₀ simp [h] · exact countable_biInf_eq_iInf_seq Bcbl Bnonempty f theorem countable_biInf_principal_eq_seq_iInf {B : Set (Set α)} (Bcbl : B.Countable) : ∃ x : ℕ → Set α, ⨅ t ∈ B, 𝓟 t = ⨅ i, 𝓟 (x i) := countable_biInf_eq_iInf_seq' Bcbl 𝓟 principal_univ section IsCountablyGenerated protected theorem HasAntitoneBasis.mem_iff [Preorder ι] {l : Filter α} {s : ι → Set α} (hs : l.HasAntitoneBasis s) {t : Set α} : t ∈ l ↔ ∃ i, s i ⊆ t := hs.toHasBasis.mem_iff.trans <| by simp only [true_and] protected theorem HasAntitoneBasis.mem [Preorder ι] {l : Filter α} {s : ι → Set α} (hs : l.HasAntitoneBasis s) (i : ι) : s i ∈ l := hs.toHasBasis.mem_of_mem trivial theorem HasAntitoneBasis.hasBasis_ge [Preorder ι] [IsDirected ι (· ≤ ·)] {l : Filter α} {s : ι → Set α} (hs : l.HasAntitoneBasis s) (i : ι) : l.HasBasis (fun j => i ≤ j) s := hs.1.to_hasBasis (fun j _ => (exists_ge_ge i j).imp fun _k hk => ⟨hk.1, hs.2 hk.2⟩) fun j _ => ⟨j, trivial, Subset.rfl⟩ /-- If `f` is countably generated and `f.HasBasis p s`, then `f` admits a decreasing basis enumerated by natural numbers such that all sets have the form `s i`. More precisely, there is a sequence `i n` such that `p (i n)` for all `n` and `s (i n)` is a decreasing sequence of sets which forms a basis of `f`. -/ theorem HasBasis.exists_antitone_subbasis {f : Filter α} [h : f.IsCountablyGenerated] {p : ι' → Prop} {s : ι' → Set α} (hs : f.HasBasis p s) : ∃ x : ℕ → ι', (∀ i, p (x i)) ∧ f.HasAntitoneBasis fun i => s (x i) := by obtain ⟨x', hx'⟩ : ∃ x : ℕ → Set α, f = ⨅ i, 𝓟 (x i) := by rcases h with ⟨s, hsc, rfl⟩ rw [generate_eq_biInf] exact countable_biInf_principal_eq_seq_iInf hsc have : ∀ i, x' i ∈ f := fun i => hx'.symm ▸ (iInf_le (fun i => 𝓟 (x' i)) i) (mem_principal_self _) let x : ℕ → { i : ι' // p i } := fun n => Nat.recOn n (hs.index _ <| this 0) fun n xn => hs.index _ <| inter_mem (this <| n + 1) (hs.mem_of_mem xn.2) have x_anti : Antitone fun i => s (x i).1 := antitone_nat_of_succ_le fun i => (hs.set_index_subset _).trans inter_subset_right have x_subset : ∀ i, s (x i).1 ⊆ x' i := by rintro (_ | i) exacts [hs.set_index_subset _, (hs.set_index_subset _).trans inter_subset_left] refine ⟨fun i => (x i).1, fun i => (x i).2, ?_⟩ have : (⨅ i, 𝓟 (s (x i).1)).HasAntitoneBasis fun i => s (x i).1 := .iInf_principal x_anti convert this exact le_antisymm (le_iInf fun i => le_principal_iff.2 <| by cases i <;> apply hs.set_index_mem) (hx'.symm ▸ le_iInf fun i => le_principal_iff.2 <| this.1.mem_iff.2 ⟨i, trivial, x_subset i⟩) /-- A countably generated filter admits a basis formed by an antitone sequence of sets. -/ theorem exists_antitone_basis (f : Filter α) [f.IsCountablyGenerated] : ∃ x : ℕ → Set α, f.HasAntitoneBasis x := let ⟨x, _, hx⟩ := f.basis_sets.exists_antitone_subbasis ⟨x, hx⟩ theorem exists_antitone_seq (f : Filter α) [f.IsCountablyGenerated] : ∃ x : ℕ → Set α, Antitone x ∧ ∀ {s}, s ∈ f ↔ ∃ i, x i ⊆ s := let ⟨x, hx⟩ := f.exists_antitone_basis ⟨x, hx.antitone, by simp [hx.1.mem_iff]⟩ instance Inf.isCountablyGenerated (f g : Filter α) [IsCountablyGenerated f] [IsCountablyGenerated g] : IsCountablyGenerated (f ⊓ g) := by rcases f.exists_antitone_basis with ⟨s, hs⟩ rcases g.exists_antitone_basis with ⟨t, ht⟩ exact HasCountableBasis.isCountablyGenerated ⟨hs.1.inf ht.1, Set.to_countable _⟩ instance map.isCountablyGenerated (l : Filter α) [l.IsCountablyGenerated] (f : α → β) : (map f l).IsCountablyGenerated := let ⟨_x, hxl⟩ := l.exists_antitone_basis (hxl.map _).isCountablyGenerated instance comap.isCountablyGenerated (l : Filter β) [l.IsCountablyGenerated] (f : α → β) : (comap f l).IsCountablyGenerated := let ⟨_x, hxl⟩ := l.exists_antitone_basis (hxl.comap _).isCountablyGenerated instance Sup.isCountablyGenerated (f g : Filter α) [IsCountablyGenerated f] [IsCountablyGenerated g] : IsCountablyGenerated (f ⊔ g) := by rcases f.exists_antitone_basis with ⟨s, hs⟩ rcases g.exists_antitone_basis with ⟨t, ht⟩ exact HasCountableBasis.isCountablyGenerated ⟨hs.1.sup ht.1, Set.to_countable _⟩ instance prod.isCountablyGenerated (la : Filter α) (lb : Filter β) [IsCountablyGenerated la] [IsCountablyGenerated lb] : IsCountablyGenerated (la ×ˢ lb) := Filter.Inf.isCountablyGenerated _ _ instance coprod.isCountablyGenerated (la : Filter α) (lb : Filter β) [IsCountablyGenerated la] [IsCountablyGenerated lb] : IsCountablyGenerated (la.coprod lb) := Filter.Sup.isCountablyGenerated _ _ end IsCountablyGenerated theorem isCountablyGenerated_seq [Countable ι'] (x : ι' → Set α) : IsCountablyGenerated (⨅ i, 𝓟 (x i)) := by use range x, countable_range x rw [generate_eq_biInf, iInf_range] theorem isCountablyGenerated_of_seq {f : Filter α} (h : ∃ x : ℕ → Set α, f = ⨅ i, 𝓟 (x i)) : f.IsCountablyGenerated := by rcases h with ⟨x, rfl⟩ apply isCountablyGenerated_seq theorem isCountablyGenerated_biInf_principal {B : Set (Set α)} (h : B.Countable) : IsCountablyGenerated (⨅ s ∈ B, 𝓟 s) := isCountablyGenerated_of_seq (countable_biInf_principal_eq_seq_iInf h) theorem isCountablyGenerated_iff_exists_antitone_basis {f : Filter α} : IsCountablyGenerated f ↔ ∃ x : ℕ → Set α, f.HasAntitoneBasis x := by constructor · intro h exact f.exists_antitone_basis · rintro ⟨x, h⟩ rw [h.1.eq_iInf] exact isCountablyGenerated_seq x @[instance] theorem isCountablyGenerated_principal (s : Set α) : IsCountablyGenerated (𝓟 s) := isCountablyGenerated_of_seq ⟨fun _ => s, iInf_const.symm⟩ @[instance] theorem isCountablyGenerated_pure (a : α) : IsCountablyGenerated (pure a) := by rw [← principal_singleton] exact isCountablyGenerated_principal _ @[instance] theorem isCountablyGenerated_bot : IsCountablyGenerated (⊥ : Filter α) := @principal_empty α ▸ isCountablyGenerated_principal _ @[instance] theorem isCountablyGenerated_top : IsCountablyGenerated (⊤ : Filter α) := @principal_univ α ▸ isCountablyGenerated_principal _ instance iInf.isCountablyGenerated {ι : Sort*} {α : Type*} [Countable ι] (f : ι → Filter α) [∀ i, IsCountablyGenerated (f i)] : IsCountablyGenerated (⨅ i, f i) := by choose s hs using fun i => exists_antitone_basis (f i) rw [← PLift.down_surjective.iInf_comp] refine HasCountableBasis.isCountablyGenerated ⟨.iInf fun n => (hs _).1, ?_⟩ refine (countable_range <| Sigma.map ((↑) : Finset (PLift ι) → Set (PLift ι)) fun _ => id).mono ?_ rintro ⟨I, f⟩ ⟨hI, -⟩ lift I to Finset (PLift ι) using hI exact ⟨⟨I, f⟩, rfl⟩ instance pi.isCountablyGenerated {ι : Type*} {α : ι → Type*} [Countable ι] (f : ∀ i, Filter (α i)) [∀ i, IsCountablyGenerated (f i)] : IsCountablyGenerated (pi f) := iInf.isCountablyGenerated _ end Filter
Nth.lean
/- Copyright (c) 2024 Ralf Stephan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ralf Stephan -/ import Mathlib.Data.Nat.Prime.Defs import Mathlib.Data.Nat.Nth /-! # The Nth primes -/ namespace Nat @[simp] theorem nth_prime_zero_eq_two : nth Prime 0 = 2 := nth_count prime_two @[simp] theorem nth_prime_one_eq_three : nth Nat.Prime 1 = 3 := nth_count prime_three @[simp] theorem nth_prime_two_eq_five : nth Nat.Prime 2 = 5 := nth_count prime_five @[simp] theorem nth_prime_three_eq_seven : nth Nat.Prime 3 = 7 := nth_count prime_seven @[simp] theorem nth_prime_four_eq_eleven : nth Nat.Prime 4 = 11 := nth_count prime_eleven end Nat
Simp.lean
/- Copyright (c) 2025 Paul Lezeau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul Lezeau -/ import Lean.Meta.Tactic.Simp.Types import Mathlib.Init import Qq /-! # Additional simp utilities This file adds additional tools for metaprogramming with the `simp` tactic -/ open Lean Meta Qq namespace Lean.Meta.Simp /-- `Qq` version of `Lean.Meta.Simp.Methods.discharge?`, which avoids having to use `~q` matching on the proof expression returned by `discharge?` `dischargeQ? (a : Q(Prop))` attempts to prove `a` using the discharger, returning `some (pf : Q(a))` if a proof is found and `none` otherwise. -/ @[inline] def Methods.dischargeQ? (M : Methods) (a : Q(Prop)) : SimpM <| Option Q($a) := M.discharge? a end Lean.Meta.Simp
MeasurePreserving.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.MeasureTheory.Measure.AEMeasurable import Mathlib.Order.Filter.EventuallyConst /-! # Measure preserving maps We say that `f : α → β` is a measure preserving map w.r.t. measures `μ : Measure α` and `ν : Measure β` if `f` is measurable and `map f μ = ν`. In this file we define the predicate `MeasureTheory.MeasurePreserving` and prove its basic properties. We use the term "measure preserving" because in many applications `α = β` and `μ = ν`. ## References Partially based on [this](https://www.isa-afp.org/browser_info/current/AFP/Ergodic_Theory/Measure_Preserving_Transformations.html) Isabelle formalization. ## Tags measure preserving map, measure -/ open MeasureTheory.Measure Function Set open scoped ENNReal variable {α β γ δ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] [MeasurableSpace δ] namespace MeasureTheory variable {μa : Measure α} {μb : Measure β} {μc : Measure γ} {μd : Measure δ} /-- `f` is a measure preserving map w.r.t. measures `μa` and `μb` if `f` is measurable and `map f μa = μb`. -/ structure MeasurePreserving (f : α → β) (μa : Measure α := by volume_tac) (μb : Measure β := by volume_tac) : Prop where protected measurable : Measurable f protected map_eq : map f μa = μb protected theorem _root_.Measurable.measurePreserving {f : α → β} (h : Measurable f) (μa : Measure α) : MeasurePreserving f μa (map f μa) := ⟨h, rfl⟩ namespace MeasurePreserving protected theorem id (μ : Measure α) : MeasurePreserving id μ μ := ⟨measurable_id, map_id⟩ protected theorem aemeasurable {f : α → β} (hf : MeasurePreserving f μa μb) : AEMeasurable f μa := hf.1.aemeasurable @[nontriviality] theorem of_isEmpty [IsEmpty β] (f : α → β) (μa : Measure α) (μb : Measure β) : MeasurePreserving f μa μb := ⟨measurable_of_subsingleton_codomain _, Subsingleton.elim _ _⟩ theorem symm (e : α ≃ᵐ β) {μa : Measure α} {μb : Measure β} (h : MeasurePreserving e μa μb) : MeasurePreserving e.symm μb μa := ⟨e.symm.measurable, by rw [← h.map_eq, map_map e.symm.measurable e.measurable, e.symm_comp_self, map_id]⟩ theorem restrict_preimage {f : α → β} (hf : MeasurePreserving f μa μb) {s : Set β} (hs : MeasurableSet s) : MeasurePreserving f (μa.restrict (f ⁻¹' s)) (μb.restrict s) := ⟨hf.measurable, by rw [← hf.map_eq, restrict_map hf.measurable hs]⟩ theorem restrict_preimage_emb {f : α → β} (hf : MeasurePreserving f μa μb) (h₂ : MeasurableEmbedding f) (s : Set β) : MeasurePreserving f (μa.restrict (f ⁻¹' s)) (μb.restrict s) := ⟨hf.measurable, by rw [← hf.map_eq, h₂.restrict_map]⟩ theorem restrict_image_emb {f : α → β} (hf : MeasurePreserving f μa μb) (h₂ : MeasurableEmbedding f) (s : Set α) : MeasurePreserving f (μa.restrict s) (μb.restrict (f '' s)) := by simpa only [Set.preimage_image_eq _ h₂.injective] using hf.restrict_preimage_emb h₂ (f '' s) theorem aemeasurable_comp_iff {f : α → β} (hf : MeasurePreserving f μa μb) (h₂ : MeasurableEmbedding f) {g : β → γ} : AEMeasurable (g ∘ f) μa ↔ AEMeasurable g μb := by rw [← hf.map_eq, h₂.aemeasurable_map_iff] protected theorem quasiMeasurePreserving {f : α → β} (hf : MeasurePreserving f μa μb) : QuasiMeasurePreserving f μa μb := ⟨hf.1, hf.2.absolutelyContinuous⟩ protected theorem comp {g : β → γ} {f : α → β} (hg : MeasurePreserving g μb μc) (hf : MeasurePreserving f μa μb) : MeasurePreserving (g ∘ f) μa μc := ⟨hg.1.comp hf.1, by rw [← map_map hg.1 hf.1, hf.2, hg.2]⟩ /-- An alias of `MeasureTheory.MeasurePreserving.comp` with a convenient defeq and argument order for `MeasurableEquiv` -/ protected theorem trans {e : α ≃ᵐ β} {e' : β ≃ᵐ γ} {μa : Measure α} {μb : Measure β} {μc : Measure γ} (h : MeasurePreserving e μa μb) (h' : MeasurePreserving e' μb μc) : MeasurePreserving (e.trans e') μa μc := h'.comp h protected theorem comp_left_iff {g : α → β} {e : β ≃ᵐ γ} (h : MeasurePreserving e μb μc) : MeasurePreserving (e ∘ g) μa μc ↔ MeasurePreserving g μa μb := by refine ⟨fun hg => ?_, fun hg => h.comp hg⟩ convert (MeasurePreserving.symm e h).comp hg simp [← Function.comp_assoc e.symm e g] protected theorem comp_right_iff {g : α → β} {e : γ ≃ᵐ α} (h : MeasurePreserving e μc μa) : MeasurePreserving (g ∘ e) μc μb ↔ MeasurePreserving g μa μb := by refine ⟨fun hg => ?_, fun hg => hg.comp h⟩ convert hg.comp (MeasurePreserving.symm e h) simp [Function.comp_assoc g e e.symm] protected theorem sigmaFinite {f : α → β} (hf : MeasurePreserving f μa μb) [SigmaFinite μb] : SigmaFinite μa := SigmaFinite.of_map μa hf.aemeasurable (by rwa [hf.map_eq]) protected theorem sfinite {f : α → β} (hf : MeasurePreserving f μa μb) [SFinite μa] : SFinite μb := by rw [← hf.map_eq] infer_instance theorem measure_preimage {f : α → β} (hf : MeasurePreserving f μa μb) {s : Set β} (hs : NullMeasurableSet s μb) : μa (f ⁻¹' s) = μb s := by rw [← hf.map_eq] at hs ⊢ rw [map_apply₀ hf.1.aemeasurable hs] theorem measureReal_preimage {f : α → β} (hf : MeasurePreserving f μa μb) {s : Set β} (hs : NullMeasurableSet s μb) : μa.real (f ⁻¹' s) = μb.real s := by simp [measureReal_def, measure_preimage hf hs] theorem measure_preimage_emb {f : α → β} (hf : MeasurePreserving f μa μb) (hfe : MeasurableEmbedding f) (s : Set β) : μa (f ⁻¹' s) = μb s := by rw [← hf.map_eq, hfe.map_apply] theorem measure_preimage_equiv {f : α ≃ᵐ β} (hf : MeasurePreserving f μa μb) (s : Set β) : μa (f ⁻¹' s) = μb s := measure_preimage_emb hf f.measurableEmbedding s theorem measure_preimage_le {f : α → β} (hf : MeasurePreserving f μa μb) (s : Set β) : μa (f ⁻¹' s) ≤ μb s := by rw [← hf.map_eq] exact le_map_apply hf.aemeasurable _ theorem preimage_null {f : α → β} (hf : MeasurePreserving f μa μb) {s : Set β} (hs : μb s = 0) : μa (f ⁻¹' s) = 0 := hf.quasiMeasurePreserving.preimage_null hs theorem aeconst_comp [MeasurableSingletonClass γ] {f : α → β} (hf : MeasurePreserving f μa μb) {g : β → γ} (hg : NullMeasurable g μb) : Filter.EventuallyConst (g ∘ f) (ae μa) ↔ Filter.EventuallyConst g (ae μb) := exists_congr fun s ↦ and_congr_left fun hs ↦ by simp only [Filter.mem_map, mem_ae_iff, ← hf.measure_preimage (hg hs.measurableSet).compl, preimage_comp, preimage_compl] theorem aeconst_preimage {f : α → β} (hf : MeasurePreserving f μa μb) {s : Set β} (hs : NullMeasurableSet s μb) : Filter.EventuallyConst (f ⁻¹' s) (ae μa) ↔ Filter.EventuallyConst s (ae μb) := aeconst_comp hf hs.mem theorem add_measure {f μa' μb'} (hf : MeasurePreserving f μa μb) (hf' : MeasurePreserving f μa' μb') : MeasurePreserving f (μa + μa') (μb + μb') where measurable := hf.measurable map_eq := by rw [Measure.map_add _ _ hf.measurable, hf.map_eq, hf'.map_eq] theorem smul_measure {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] {f : α → β} (hf : MeasurePreserving f μa μb) (c : R) : MeasurePreserving f (c • μa) (c • μb) where measurable := hf.measurable map_eq := by rw [Measure.map_smul, hf.map_eq] variable {μ : Measure α} {f : α → α} {s : Set α} protected theorem iterate (hf : MeasurePreserving f μ μ) : ∀ n, MeasurePreserving f^[n] μ μ | 0 => .id μ | n + 1 => (MeasurePreserving.iterate hf n).comp hf open scoped symmDiff in lemma measure_symmDiff_preimage_iterate_le (hf : MeasurePreserving f μ μ) (hs : NullMeasurableSet s μ) (n : ℕ) : μ (s ∆ (f^[n] ⁻¹' s)) ≤ n • μ (s ∆ (f ⁻¹' s)) := by induction' n with n ih; · simp simp only [add_smul, one_smul] refine le_trans (measure_symmDiff_le s (f^[n] ⁻¹' s) (f^[n+1] ⁻¹' s)) (add_le_add ih ?_) replace hs : NullMeasurableSet (s ∆ (f ⁻¹' s)) μ := hs.symmDiff <| hs.preimage hf.quasiMeasurePreserving rw [iterate_succ', preimage_comp, ← preimage_symmDiff, (hf.iterate n).measure_preimage hs] /-- If `μ univ < n * μ s` and `f` is a map preserving measure `μ`, then for some `x ∈ s` and `0 < m < n`, `f^[m] x ∈ s`. -/ theorem exists_mem_iterate_mem_of_measure_univ_lt_mul_measure (hf : MeasurePreserving f μ μ) (hs : NullMeasurableSet s μ) {n : ℕ} (hvol : μ (Set.univ : Set α) < n * μ s) : ∃ x ∈ s, ∃ m ∈ Set.Ioo 0 n, f^[m] x ∈ s := by have A : ∀ m, NullMeasurableSet (f^[m] ⁻¹' s) μ := fun m ↦ hs.preimage (hf.iterate m).quasiMeasurePreserving have B : ∀ m, μ (f^[m] ⁻¹' s) = μ s := fun m ↦ (hf.iterate m).measure_preimage hs have : μ (univ : Set α) < ∑ m ∈ Finset.range n, μ (f^[m] ⁻¹' s) := by simpa [B] obtain ⟨i, hi, j, hj, hij, x, hxi : f^[i] x ∈ s, hxj : f^[j] x ∈ s⟩ : ∃ i < n, ∃ j < n, i ≠ j ∧ (f^[i] ⁻¹' s ∩ f^[j] ⁻¹' s).Nonempty := by simpa using exists_nonempty_inter_of_measure_univ_lt_sum_measure μ (fun m _ ↦ A m) this wlog hlt : i < j generalizing i j · exact this j hj i hi hij.symm hxj hxi (hij.lt_or_gt.resolve_left hlt) refine ⟨f^[i] x, hxi, j - i, ⟨tsub_pos_of_lt hlt, lt_of_le_of_lt (j.sub_le i) hj⟩, ?_⟩ rwa [← iterate_add_apply, tsub_add_cancel_of_le hlt.le] /-- A self-map preserving a finite measure is conservative: if `μ s ≠ 0`, then at least one point `x ∈ s` comes back to `s` under iterations of `f`. Actually, a.e. point of `s` comes back to `s` infinitely many times, see `MeasureTheory.MeasurePreserving.conservative` and theorems about `MeasureTheory.Conservative`. -/ theorem exists_mem_iterate_mem [IsFiniteMeasure μ] (hf : MeasurePreserving f μ μ) (hs : NullMeasurableSet s μ) (hs' : μ s ≠ 0) : ∃ x ∈ s, ∃ m ≠ 0, f^[m] x ∈ s := by rcases ENNReal.exists_nat_mul_gt hs' (measure_ne_top μ (Set.univ : Set α)) with ⟨N, hN⟩ rcases hf.exists_mem_iterate_mem_of_measure_univ_lt_mul_measure hs hN with ⟨x, hx, m, hm, hmx⟩ exact ⟨x, hx, m, hm.1.ne', hmx⟩ end MeasurePreserving lemma measurePreserving_subtype_coe {s : Set α} (hs : MeasurableSet s) : MeasurePreserving (Subtype.val : s → α) (μa.comap Subtype.val) (μa.restrict s) where measurable := measurable_subtype_coe map_eq := map_comap_subtype_coe hs _ namespace MeasurableEquiv theorem measurePreserving_symm (μ : Measure α) (e : α ≃ᵐ β) : MeasurePreserving e.symm (map e μ) μ := (e.measurable.measurePreserving μ).symm _ end MeasurableEquiv end MeasureTheory
Cyclic.lean
/- Copyright (c) 2025 María Inés de Frutos-Fernández, Filippo A. E. Nuccio. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: María Inés de Frutos-Fernández, Filippo A. E. Nuccio -/ import Mathlib.Algebra.Order.Group.Basic import Mathlib.GroupTheory.SpecificGroups.Cyclic /-! # Cyclic linearly ordered groups This file contains basic results about cyclic linearly ordered groups and cyclic subgroups of linearly ordered groups. The definitions `LinearOrderedCommGroup.Subgroup.genLTOne` (*resp.* `LinearOrderedCommGroup.genLTOone`) yields a generator of a non-trivial subgroup of a linearly ordered commutative group with (*resp.* of a non-trivial linearly ordered commutative group) that is strictly less than `1`. The corresponding additive definitions are also provided. -/ noncomputable section namespace LinearOrderedCommGroup open LinearOrderedCommGroup variable {G : Type*} [CommGroup G] [LinearOrder G] [IsOrderedMonoid G] namespace Subgroup variable (H : Subgroup G) [Nontrivial H] [hH : IsCyclic H] @[to_additive exists_neg_generator] lemma exists_generator_lt_one : ∃ (a : G), a < 1 ∧ Subgroup.zpowers a = H := by obtain ⟨a, ha⟩ := H.isCyclic_iff_exists_zpowers_eq_top.mp hH obtain ha1 | rfl | ha1 := lt_trichotomy a 1 · exact ⟨a, ha1, ha⟩ · rw [Subgroup.zpowers_one_eq_bot] at ha exact absurd ha.symm <| (H.nontrivial_iff_ne_bot).mp inferInstance · use a⁻¹, Left.inv_lt_one_iff.mpr ha1 rw [Subgroup.zpowers_inv, ha] /-- Given a subgroup of a cyclic linearly ordered commutative group, this is a generator of the subgroup that is `< 1`. -/ @[to_additive negGen /-- Given an additive subgroup of an additive cyclic linearly ordered commutative group, this is a negative generator of the subgroup. -/] protected noncomputable def genLTOne : G := H.exists_generator_lt_one.choose @[to_additive negGen_neg] lemma genLTOne_lt_one : H.genLTOne < 1 := H.exists_generator_lt_one.choose_spec.1 @[to_additive (attr := simp) negGen_zmultiples_eq_top] lemma genLTOne_zpowers_eq_top : Subgroup.zpowers H.genLTOne = H := H.exists_generator_lt_one.choose_spec.2 lemma genLTOne_mem : H.genLTOne ∈ H := by nth_rewrite 1 [← H.genLTOne_zpowers_eq_top] exact Subgroup.mem_zpowers (Subgroup.genLTOne H) lemma genLTOne_unique {g : G} (hg : g < 1) (hH : Subgroup.zpowers g = H) : g = H.genLTOne := by have hg' : ¬ IsOfFinOrder g := not_isOfFinOrder_of_isMulTorsionFree (ne_of_lt hg) rw [← H.genLTOne_zpowers_eq_top] at hH rcases (Subgroup.zpowers_eq_zpowers_iff hg').mp hH with _ | h · assumption rw [← one_lt_inv', h] at hg exact (not_lt_of_gt hg <| Subgroup.genLTOne_lt_one _).elim lemma genLTOne_unique_of_zpowers_eq {g1 g2 : G} (hg1 : g1 < 1) (hg2 : g2 < 1) (h : Subgroup.zpowers g1 = Subgroup.zpowers g2) : g1 = g2 := by rcases (Subgroup.zpowers g2).bot_or_nontrivial with (h' | h') · rw [h'] at h simp_all only [Subgroup.zpowers_eq_bot] · have h1 : IsCyclic ↥(Subgroup.zpowers g2) := by rw [Subgroup.isCyclic_iff_exists_zpowers_eq_top]; use g2 have h2 : Nontrivial ↥(Subgroup.zpowers g1) := by rw [h]; exact h' have h3 : IsCyclic ↥(Subgroup.zpowers g1) := by rw [h]; exact h1 simp only [(Subgroup.zpowers g2).genLTOne_unique hg1 h] simp only [← h] simp only [(Subgroup.zpowers g1).genLTOne_unique hg2 h.symm] end Subgroup section IsCyclic variable (G) [Nontrivial G] [IsCyclic G] /-- Given a cyclic linearly ordered commutative group, this is a generator that is `< 1`. -/ @[to_additive negGen /-- Given an additive cyclic linearly ordered commutative group, this is a negative generator of it. -/] noncomputable def genLTOne : G := (⊤ : Subgroup G).genLTOne @[to_additive (attr := simp) negGen_eq_of_top] lemma genLTOne_eq_of_top : genLTOne G = (⊤ : Subgroup G).genLTOne := rfl lemma genLTOne_unique {g : G} (hg : g < 1) (htop : Subgroup.zpowers g = ⊤) : g = genLTOne G := (⊤ : Subgroup G).genLTOne_unique hg htop end IsCyclic end LinearOrderedCommGroup
Equiv.lean
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.AddConstMap.Basic /-! # Equivalences conjugating `(· + a)` to `(· + b)` In this file we define `AddConstEquiv G H a b` (notation: `G ≃+c[a, b] H`) to be the type of equivalences such that `∀ x, f (x + a) = f x + b`. We also define the corresponding typeclass and prove some basic properties. -/ assert_not_exists Finset open Function open scoped AddConstMap /-- An equivalence between `G` and `H` conjugating `(· + a)` to `(· + b)`, denoted as `G ≃+c[a, b] H`. -/ structure AddConstEquiv (G H : Type*) [Add G] [Add H] (a : G) (b : H) extends G ≃ H, G →+c[a, b] H /-- Interpret an `AddConstEquiv` as an `Equiv`. -/ add_decl_doc AddConstEquiv.toEquiv /-- Interpret an `AddConstEquiv` as an `AddConstMap`. -/ add_decl_doc AddConstEquiv.toAddConstMap @[inherit_doc] scoped [AddConstMap] notation:25 G " ≃+c[" a ", " b "] " H => AddConstEquiv G H a b namespace AddConstEquiv variable {G H K : Type*} [Add G] [Add H] [Add K] {a : G} {b : H} {c : K} lemma toEquiv_injective : Injective (toEquiv : (G ≃+c[a, b] H) → G ≃ H) | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl instance {G H : Type*} [Add G] [Add H] {a : G} {b : H} : EquivLike (G ≃+c[a, b] H) G H where coe f := f.toEquiv inv f := f.toEquiv.symm left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' _ _ h _ := toEquiv_injective <| DFunLike.ext' h instance {G H : Type*} [Add G] [Add H] {a : G} {b : H} : AddConstMapClass (G ≃+c[a, b] H) G H a b where map_add_const f x := f.map_add_const' x @[ext] lemma ext {e₁ e₂ : G ≃+c[a, b] H} (h : ∀ x, e₁ x = e₂ x) : e₁ = e₂ := DFunLike.ext _ _ h @[simp] lemma toEquiv_inj {e₁ e₂ : G ≃+c[a, b] H} : e₁.toEquiv = e₂.toEquiv ↔ e₁ = e₂ := toEquiv_injective.eq_iff @[simp] lemma coe_toEquiv (e : G ≃+c[a, b] H) : ⇑e.toEquiv = e := rfl /-- Inverse map of an `AddConstEquiv`, as an `AddConstEquiv`. -/ def symm (e : G ≃+c[a, b] H) : H ≃+c[b, a] G where toEquiv := e.toEquiv.symm map_add_const' := (AddConstMapClass.semiconj e).inverse_left e.left_inv e.right_inv /-- A custom projection for `simps`. -/ def Simps.symm_apply (e : G ≃+c[a, b] H) : H → G := e.symm initialize_simps_projections AddConstEquiv (toFun → apply, invFun → symm_apply) @[simp] lemma symm_symm (e : G ≃+c[a, b] H) : e.symm.symm = e := rfl /-- The identity map as an `AddConstEquiv`. -/ @[simps! toEquiv apply] def refl (a : G) : G ≃+c[a, a] G where toEquiv := .refl G map_add_const' _ := rfl @[simp] lemma symm_refl (a : G) : (refl a).symm = refl a := rfl /-- Composition of `AddConstEquiv`s, as an `AddConstEquiv`. -/ @[simps! +simpRhs toEquiv apply] def trans (e₁ : G ≃+c[a, b] H) (e₂ : H ≃+c[b, c] K) : G ≃+c[a, c] K where toEquiv := e₁.toEquiv.trans e₂.toEquiv map_add_const' := (AddConstMapClass.semiconj e₁).trans (AddConstMapClass.semiconj e₂) @[simp] lemma trans_refl (e : G ≃+c[a, b] H) : e.trans (.refl b) = e := rfl @[simp] lemma refl_trans (e : G ≃+c[a, b] H) : (refl a).trans e = e := rfl @[simp] lemma self_trans_symm (e : G ≃+c[a, b] H) : e.trans e.symm = .refl a := toEquiv_injective e.toEquiv.self_trans_symm @[simp] lemma symm_trans_self (e : G ≃+c[a, b] H) : e.symm.trans e = .refl b := toEquiv_injective e.toEquiv.symm_trans_self @[simp] lemma coe_symm_toEquiv (e : G ≃+c[a, b] H) : ⇑e.toEquiv.symm = e.symm := rfl @[simp] lemma toEquiv_symm (e : G ≃+c[a, b] H) : e.symm.toEquiv = e.toEquiv.symm := rfl @[simp] lemma toEquiv_trans (e₁ : G ≃+c[a, b] H) (e₂ : H ≃+c[b, c] K) : (e₁.trans e₂).toEquiv = e₁.toEquiv.trans e₂.toEquiv := rfl instance instOne : One (G ≃+c[a, a] G) := ⟨.refl _⟩ instance instMul : Mul (G ≃+c[a, a] G) := ⟨fun f g ↦ g.trans f⟩ instance instInv : Inv (G ≃+c[a, a] G) := ⟨.symm⟩ instance instDiv : Div (G ≃+c[a, a] G) := ⟨fun f g ↦ f * g⁻¹⟩ instance instPowNat : Pow (G ≃+c[a, a] G) ℕ where pow e n := ⟨e^n, (e.toAddConstMap^n).map_add_const'⟩ instance instPowInt : Pow (G ≃+c[a, a] G) ℤ where pow e n := ⟨e^n, match n with | .ofNat n => (e^n).map_add_const' | .negSucc n => (e.symm^(n + 1)).map_add_const'⟩ instance instGroup : Group (G ≃+c[a, a] G) := toEquiv_injective.group _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) fun _ _ ↦ rfl /-- Projection from `G ≃+c[a, a] G` to permutations `G ≃ G`, as a monoid homomorphism. -/ @[simps! apply] def toPerm : (G ≃+c[a, a] G) →* Equiv.Perm G := .mk' toEquiv fun _ _ ↦ rfl /-- Projection from `G ≃+c[a, a] G` to `G →+c[a, a] G`, as a monoid homomorphism. -/ @[simps! apply] def toAddConstMapHom : (G ≃+c[a, a] G) →* (G →+c[a, a] G) where toFun := toAddConstMap map_mul' _ _ := rfl map_one' := rfl /-- Group equivalence between `G ≃+c[a, a] G` and the units of `G →+c[a, a] G`. -/ @[simps!] def equivUnits : (G ≃+c[a, a] G) ≃* (G →+c[a, a] G)ˣ where toFun := toAddConstMapHom.toHomUnits invFun u := { toEquiv := Equiv.Perm.equivUnitsEnd.symm <| Units.map AddConstMap.toEnd u map_add_const' := u.1.2 } map_mul' _ _ := rfl end AddConstEquiv
Basic.lean
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Exact import Mathlib.LinearAlgebra.Span.Basic import Mathlib.RingTheory.Ideal.IsPrimary import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Noetherian.Defs /-! # Associated primes of a module We provide the definition and related lemmas about associated primes of modules. ## Main definition - `IsAssociatedPrime`: `IsAssociatedPrime I M` if the prime ideal `I` is the annihilator of some `x : M`. - `associatedPrimes`: The set of associated primes of a module. ## Main results - `exists_le_isAssociatedPrime_of_isNoetherianRing`: In a noetherian ring, any `ann(x)` is contained in an associated prime for `x ≠ 0`. - `associatedPrimes.eq_singleton_of_isPrimary`: In a noetherian ring, `I.radical` is the only associated prime of `R ⧸ I` when `I` is primary. ## TODO Generalize this to a non-commutative setting once there are annihilator for non-commutative rings. -/ variable {R : Type*} [CommRing R] (I J : Ideal R) (M : Type*) [AddCommGroup M] [Module R M] open LinearMap /-- `IsAssociatedPrime I M` if the prime ideal `I` is the annihilator of some `x : M`. -/ def IsAssociatedPrime : Prop := I.IsPrime ∧ ∃ x : M, I = ker (toSpanSingleton R M x) theorem isAssociatedPrime_iff_exists_injective_linearMap : IsAssociatedPrime I M ↔ I.IsPrime ∧ ∃ (f : R ⧸ I →ₗ[R] M), Function.Injective f := by rw [IsAssociatedPrime] congr! 1 refine ⟨fun ⟨_, h⟩ ↦ ⟨Submodule.liftQ _ _ h.le, ker_eq_bot.1 (Submodule.ker_liftQ_eq_bot' _ _ h)⟩, fun ⟨f, h⟩ ↦ ⟨(f ∘ₗ Submodule.mkQ I) 1, ?_⟩⟩ have := I.ker_mkQ ▸ ker_comp_of_ker_eq_bot (Submodule.mkQ I) (ker_eq_bot_of_injective h) convert this.symm using 2 ext; simp variable (R) /-- The set of associated primes of a module. -/ def associatedPrimes : Set (Ideal R) := { I | IsAssociatedPrime I M } variable {I J M R} variable {M' : Type*} [AddCommGroup M'] [Module R M'] (f : M →ₗ[R] M') theorem AssociatePrimes.mem_iff : I ∈ associatedPrimes R M ↔ IsAssociatedPrime I M := Iff.rfl theorem IsAssociatedPrime.isPrime (h : IsAssociatedPrime I M) : I.IsPrime := h.1 theorem IsAssociatedPrime.map_of_injective (h : IsAssociatedPrime I M) (hf : Function.Injective f) : IsAssociatedPrime I M' := by obtain ⟨x, rfl⟩ := h.2 refine ⟨h.1, ⟨f x, ?_⟩⟩ ext r simp_rw [mem_ker, toSpanSingleton_apply, ← map_smul, ← f.map_zero, hf.eq_iff] theorem LinearEquiv.isAssociatedPrime_iff (l : M ≃ₗ[R] M') : IsAssociatedPrime I M ↔ IsAssociatedPrime I M' := ⟨fun h => h.map_of_injective l l.injective, fun h => h.map_of_injective l.symm l.symm.injective⟩ theorem not_isAssociatedPrime_of_subsingleton [Subsingleton M] : ¬IsAssociatedPrime I M := by rintro ⟨hI, x, hx⟩ apply hI.ne_top simpa [Subsingleton.elim x 0] using hx variable (R) in theorem exists_le_isAssociatedPrime_of_isNoetherianRing [H : IsNoetherianRing R] (x : M) (hx : x ≠ 0) : ∃ P : Ideal R, IsAssociatedPrime P M ∧ ker (toSpanSingleton R M x) ≤ P := by have : ker (toSpanSingleton R M x) ≠ ⊤ := by rwa [Ne, Ideal.eq_top_iff_one, mem_ker, toSpanSingleton_apply, one_smul] obtain ⟨P, ⟨l, h₁, y, rfl⟩, h₃⟩ := set_has_maximal_iff_noetherian.mpr H { P | ker (toSpanSingleton R M x) ≤ P ∧ P ≠ ⊤ ∧ ∃ y : M, P = ker (toSpanSingleton R M y) } ⟨_, rfl.le, this, x, rfl⟩ refine ⟨_, ⟨⟨h₁, ?_⟩, y, rfl⟩, l⟩ intro a b hab rw [or_iff_not_imp_left] intro ha rw [mem_ker, toSpanSingleton_apply] at ha hab have H₁ : ker (toSpanSingleton R M y) ≤ ker (toSpanSingleton R M (a • y)) := by intro c hc rw [mem_ker, toSpanSingleton_apply] at hc ⊢ rw [smul_comm, hc, smul_zero] have H₂ : ker (toSpanSingleton R M (a • y)) ≠ ⊤ := by rwa [Ne, ker_eq_top, toSpanSingleton_eq_zero_iff] rwa [H₁.eq_of_not_lt (h₃ _ ⟨l.trans H₁, H₂, _, rfl⟩), mem_ker, toSpanSingleton_apply, smul_comm, smul_smul] namespace associatedPrimes variable {f} {M'' : Type*} [AddCommGroup M''] [Module R M''] {g : M' →ₗ[R] M''} /-- If `M → M'` is injective, then the set of associated primes of `M` is contained in that of `M'`. -/ @[stacks 02M3 "first part"] theorem subset_of_injective (hf : Function.Injective f) : associatedPrimes R M ⊆ associatedPrimes R M' := fun _I h => h.map_of_injective f hf /-- If `0 → M → M' → M''` is an exact sequence, then the set of associated primes of `M'` is contained in the union of those of `M` and `M''`. -/ @[stacks 02M3 "second part"] theorem subset_union_of_exact (hf : Function.Injective f) (hfg : Function.Exact f g) : associatedPrimes R M' ⊆ associatedPrimes R M ∪ associatedPrimes R M'' := by rintro p ⟨_, x, hx⟩ by_cases h : ∃ a ∈ p.primeCompl, ∃ y : M, f y = a • x · obtain ⟨a, ha, y, h⟩ := h left refine ⟨‹_›, y, le_antisymm (fun b hb ↦ ?_) (fun b hb ↦ ?_)⟩ · rw [hx] at hb rw [LinearMap.mem_ker, LinearMap.toSpanSingleton_apply] at hb ⊢ apply_fun _ using hf rw [map_smul, map_zero, h, smul_comm, hb, smul_zero] · rw [LinearMap.mem_ker, LinearMap.toSpanSingleton_apply] at hb apply_fun f at hb rw [map_smul, map_zero, h, ← mul_smul, ← LinearMap.toSpanSingleton_apply, ← LinearMap.mem_ker, ← hx] at hb contrapose! hb exact p.primeCompl.mul_mem hb ha · push_neg at h right refine ⟨‹_›, g x, le_antisymm (fun b hb ↦ ?_) (fun b hb ↦ ?_)⟩ · rw [hx] at hb rw [LinearMap.mem_ker, LinearMap.toSpanSingleton_apply] at hb ⊢ rw [← map_smul, hb, map_zero] · rw [LinearMap.mem_ker, LinearMap.toSpanSingleton_apply, ← map_smul, ← LinearMap.mem_ker, hfg.linearMap_ker_eq] at hb obtain ⟨y, hy⟩ := hb by_contra! H exact h b H y hy variable (R M M') in /-- The set of associated primes of the product of two modules is equal to the union of those of the two modules. -/ @[stacks 02M3 "third part"] theorem prod : associatedPrimes R (M × M') = associatedPrimes R M ∪ associatedPrimes R M' := (subset_union_of_exact LinearMap.inl_injective .inl_snd).antisymm (Set.union_subset_iff.2 ⟨subset_of_injective LinearMap.inl_injective, subset_of_injective LinearMap.inr_injective⟩) end associatedPrimes theorem LinearEquiv.AssociatedPrimes.eq (l : M ≃ₗ[R] M') : associatedPrimes R M = associatedPrimes R M' := le_antisymm (associatedPrimes.subset_of_injective l.injective) (associatedPrimes.subset_of_injective l.symm.injective) theorem associatedPrimes.eq_empty_of_subsingleton [Subsingleton M] : associatedPrimes R M = ∅ := by ext; simp only [Set.mem_empty_iff_false, iff_false] apply not_isAssociatedPrime_of_subsingleton variable (R M) theorem associatedPrimes.nonempty [IsNoetherianRing R] [Nontrivial M] : (associatedPrimes R M).Nonempty := by obtain ⟨x, hx⟩ := exists_ne (0 : M) obtain ⟨P, hP, _⟩ := exists_le_isAssociatedPrime_of_isNoetherianRing R x hx exact ⟨P, hP⟩ theorem biUnion_associatedPrimes_eq_zero_divisors [IsNoetherianRing R] : ⋃ p ∈ associatedPrimes R M, p = { r : R | ∃ x : M, x ≠ 0 ∧ r • x = 0 } := by refine subset_antisymm (Set.iUnion₂_subset ?_) ?_ · rintro _ ⟨h, x, ⟨⟩⟩ r h' refine ⟨x, ne_of_eq_of_ne (one_smul R x).symm ?_, h'⟩ exact (Ideal.ne_top_iff_one _).mp h.ne_top · intro r ⟨x, h, h'⟩ obtain ⟨P, hP, hx⟩ := exists_le_isAssociatedPrime_of_isNoetherianRing R x h exact Set.mem_biUnion hP (hx h') variable {R M} theorem IsAssociatedPrime.annihilator_le (h : IsAssociatedPrime I M) : (⊤ : Submodule R M).annihilator ≤ I := by obtain ⟨hI, x, rfl⟩ := h rw [← Submodule.annihilator_span_singleton] exact Submodule.annihilator_mono le_top theorem IsAssociatedPrime.eq_radical (hI : I.IsPrimary) (h : IsAssociatedPrime J (R ⧸ I)) : J = I.radical := by obtain ⟨hJ, x, e⟩ := h have : x ≠ 0 := by rintro rfl apply hJ.1 rwa [toSpanSingleton_zero, ker_zero] at e obtain ⟨x, rfl⟩ := Ideal.Quotient.mkₐ_surjective R _ x replace e : ∀ {y}, y ∈ J ↔ x * y ∈ I := by intro y rw [e, mem_ker, toSpanSingleton_apply, ← map_smul, smul_eq_mul, mul_comm, Ideal.Quotient.mkₐ_eq_mk, ← Ideal.Quotient.mk_eq_mk, Submodule.Quotient.mk_eq_zero] apply le_antisymm · intro y hy exact ((Ideal.isPrimary_iff.1 hI).2 <| e.mp hy).resolve_left ((Submodule.Quotient.mk_eq_zero I).not.mp this) · rw [hJ.radical_le_iff] intro y hy exact e.mpr (I.mul_mem_left x hy) theorem associatedPrimes.eq_singleton_of_isPrimary [IsNoetherianRing R] (hI : I.IsPrimary) : associatedPrimes R (R ⧸ I) = {I.radical} := by ext J rw [Set.mem_singleton_iff] refine ⟨IsAssociatedPrime.eq_radical hI, ?_⟩ rintro rfl haveI : Nontrivial (R ⧸ I) := by refine ⟨(Ideal.Quotient.mk I :) 1, (Ideal.Quotient.mk I :) 0, ?_⟩ rw [Ne, Ideal.Quotient.eq, sub_zero, ← Ideal.eq_top_iff_one] exact hI.1 obtain ⟨a, ha⟩ := associatedPrimes.nonempty R (R ⧸ I) exact ha.eq_radical hI ▸ ha
Basic.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, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov -/ import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.Ring.Defs /-! # Lemmas about additive closures of `Subsemigroup`. -/ open AddSubmonoid namespace MulMemClass variable {M R : Type*} [NonUnitalNonAssocSemiring R] [SetLike M R] [MulMemClass M R] {S : M} {a b : R} /-- The product of an element of the additive closure of a multiplicative subsemigroup `M` and an element of `M` is contained in the additive closure of `M`. -/ lemma mul_right_mem_add_closure (ha : a ∈ closure (S : Set R)) (hb : b ∈ S) : a * b ∈ closure (S : Set R) := by induction ha using closure_induction with | mem r hr => exact AddSubmonoid.mem_closure.mpr fun y hy => hy (mul_mem hr hb) | one => simp only [zero_mul, zero_mem _] | mul r s _ _ hr hs => simpa only [add_mul] using add_mem hr hs /-- The product of two elements of the additive closure of a submonoid `M` is an element of the additive closure of `M`. -/ lemma mul_mem_add_closure (ha : a ∈ closure (S : Set R)) (hb : b ∈ closure (S : Set R)) : a * b ∈ closure (S : Set R) := by induction hb using closure_induction with | mem r hr => exact MulMemClass.mul_right_mem_add_closure ha hr | one => simp only [mul_zero, zero_mem _] | mul r s _ _ hr hs => simpa only [mul_add] using add_mem hr hs /-- The product of an element of `S` and an element of the additive closure of a multiplicative submonoid `S` is contained in the additive closure of `S`. -/ lemma mul_left_mem_add_closure (ha : a ∈ S) (hb : b ∈ closure (S : Set R)) : a * b ∈ closure (S : Set R) := mul_mem_add_closure (AddSubmonoid.mem_closure.mpr fun _sT hT => hT ha) hb end MulMemClass
polydiv.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 choice. From mathcomp Require Import fintype bigop ssralg poly. (******************************************************************************) (* This file provides a library for the basic theory of Euclidean and pseudo- *) (* Euclidean division for polynomials over non trivial ring structures. *) (* The library defines two versions of the pseudo-euclidean division: one for *) (* coefficients in a (not necessarily commutative) non-trivial ring structure *) (* and one for coefficients equipped with a structure of integral domain. *) (* From the latter we derive the definition of the usual Euclidean division *) (* for coefficients in a field. Only the definition of the pseudo-division *) (* for coefficients in an integral domain is exported by default and benefits *) (* from notations. *) (* Also, the only theory exported by default is the one of division for *) (* polynomials with coefficients in a field. *) (* Other definitions and facts are qualified using name spaces indicating the *) (* hypotheses made on the structure of coefficients and the properties of the *) (* polynomial one divides with. *) (* *) (* Pdiv.Field (exported by the present library): *) (* edivp p q == pseudo-division of p by q with p q : {poly R} where *) (* R is an idomainType. *) (* Computes (k, quo, rem) : nat * {poly r} * {poly R}, *) (* such that size rem < size q and: *) (* + if lead_coef q is not a unit, then: *) (* (lead_coef q ^+ k) *: p = q * quo + rem *) (* + else if lead_coef q is a unit, then: *) (* p = q * quo + rem and k = 0 *) (* p %/ q == quotient (second component) computed by (edivp p q). *) (* p %% q == remainder (third component) computed by (edivp p q). *) (* scalp p q == exponent (first component) computed by (edivp p q). *) (* p %| q == tests the nullity of the remainder of the *) (* pseudo-division of p by q. *) (* rgcdp p q == Pseudo-greater common divisor obtained by performing *) (* the Euclidean algorithm on p and q using redivp as *) (* Euclidean division. *) (* p %= q == p and q are associate polynomials, i.e., p %| q and *) (* q %| p, or equivalently, p = c *: q for some nonzero *) (* constant c. *) (* gcdp p q == Pseudo-greater common divisor obtained by performing *) (* the Euclidean algorithm on p and q using edivp as *) (* Euclidean division. *) (* egcdp p q == The pair of Bezout coefficients: if e := egcdp p q, *) (* then size e.1 <= size q, size e.2 <= size p, and *) (* gcdp p q %= e.1 * p + e.2 * q *) (* coprimep p q == p and q are coprime, i.e., (gcdp p q) is a nonzero *) (* constant. *) (* gdcop q p == greatest divisor of p which is coprime to q. *) (* irreducible_poly p <-> p has only trivial (constant) divisors. *) (* mup x q == multplicity of x as a root of q *) (* *) (* Pdiv.Idomain: theory available for edivp and the related operation under *) (* the sole assumption that the ring of coefficients is canonically an *) (* integral domain (R : idomainType). *) (* *) (* Pdiv.IdomainMonic: theory available for edivp and the related operations *) (* under the assumption that the ring of coefficients is canonically *) (* and integral domain (R : idomainType) an the divisor is monic. *) (* *) (* Pdiv.IdomainUnit: theory available for edivp and the related operations *) (* under the assumption that the ring of coefficients is canonically an *) (* integral domain (R : idomainType) and the leading coefficient of the *) (* divisor is a unit. *) (* *) (* Pdiv.ClosedField: theory available for edivp and the related operation *) (* under the sole assumption that the ring of coefficients is canonically *) (* an algebraically closed field (R : closedField). *) (* *) (* Pdiv.Ring : *) (* redivp p q == pseudo-division of p by q with p q : {poly R} where R is *) (* a nzRingType. *) (* Computes (k, quo, rem) : nat * {poly r} * {poly R}, *) (* such that if rem = 0 then quo * q = p * (lead_coef q ^+ k) *) (* *) (* rdivp p q == quotient (second component) computed by (redivp p q). *) (* rmodp p q == remainder (third component) computed by (redivp p q). *) (* rscalp p q == exponent (first component) computed by (redivp p q). *) (* rdvdp p q == tests the nullity of the remainder of the pseudo-division *) (* of p by q. *) (* rgcdp p q == analogue of gcdp for coefficients in a nzRingType. *) (* rgdcop p q == analogue of gdcop for coefficients in a nzRingType. *) (*rcoprimep p q == analogue of coprimep p q for coefficients in a nzRingType. *) (* *) (* Pdiv.RingComRreg : theory of the operations defined in Pdiv.Ring, when the *) (* ring of coefficients is canonically commutative (R : comNzRingType) and *) (* the leading coefficient of the divisor is both right regular and *) (* commutes as a constant polynomial with the divisor itself *) (* *) (* Pdiv.RingMonic : theory of the operations defined in Pdiv.Ring, under the *) (* assumption that the divisor is monic. *) (* *) (* Pdiv.UnitRing: theory of the operations defined in Pdiv.Ring, when the *) (* ring R of coefficients is canonically with units (R : unitRingType). *) (* *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Local Open Scope ring_scope. Reserved Notation "p %= q" (at level 70, no associativity). Local Notation simp := Monoid.simpm. Module Pdiv. Module CommonRing. Section RingPseudoDivision. Variable R : nzRingType. Implicit Types d p q r : {poly R}. (* Pseudo division, defined on an arbitrary ring *) Definition redivp_rec (q : {poly R}) := let sq := size q in let cq := lead_coef q in fix loop (k : nat) (qq r : {poly R})(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 loop k.+1 qq1 r1 n1 else (k.+1, qq1, r1). Definition redivp_expanded_def p q := if q == 0 then (0, 0, p) else redivp_rec q 0 0 p (size p). Fact redivp_key : unit. Proof. by []. Qed. Definition redivp : {poly R} -> {poly R} -> nat * {poly R} * {poly R} := locked_with redivp_key redivp_expanded_def. Canonical redivp_unlockable := [unlockable fun redivp]. Definition rdivp p q := ((redivp p q).1).2. Definition rmodp p q := (redivp p q).2. Definition rscalp p q := ((redivp p q).1).1. Definition rdvdp p q := rmodp q p == 0. (*Definition rmultp := [rel m d | rdvdp d m].*) Lemma redivp_def p q : redivp p q = (rscalp p q, rdivp p q, rmodp p q). Proof. by rewrite /rscalp /rdivp /rmodp; case: (redivp p q) => [[]] /=. Qed. Lemma rdiv0p p : rdivp 0 p = 0. Proof. rewrite /rdivp unlock; case: ifP => // Hp; rewrite /redivp_rec !size_poly0. by rewrite polySpred ?Hp. Qed. Lemma rdivp0 p : rdivp p 0 = 0. Proof. by rewrite /rdivp unlock eqxx. Qed. Lemma rdivp_small p q : size p < size q -> rdivp p q = 0. Proof. rewrite /rdivp unlock; have [-> | _ ltpq] := eqP; first by rewrite size_poly0. by case: (size p) => [|s]; rewrite /= ltpq. Qed. Lemma leq_rdivp p q : size (rdivp p q) <= size p. Proof. have [/rdivp_small->|] := ltnP (size p) (size q); first by rewrite size_poly0. rewrite /rdivp /rmodp /rscalp unlock. have [->|q0] //= := eqVneq q 0. have: size (0 : {poly R}) <= size p by rewrite size_poly0. move: {2 3 4 6}(size p) (leqnn (size p)) => A. elim: (size p) 0%N (0 : {poly R}) {1 3 4}p (leqnn (size p)) => [|n ihn] k q1 r. by move/size_poly_leq0P->; rewrite /= size_poly0 size_poly_gt0 q0. move=> /= hrn hr hq1 hq; case: ltnP => //= hqr. have sq: 0 < size q by rewrite size_poly_gt0. have sr: 0 < size r by apply: leq_trans sq hqr. apply: ihn => //. - apply/leq_sizeP => j hnj. rewrite coefB -scalerAl coefZ coefXnM ltn_subRL ltnNge. have hj : (size r).-1 <= j by apply: leq_trans hnj; rewrite -ltnS prednK. rewrite [leqLHS]polySpred -?size_poly_gt0 // coefMC. rewrite (leq_ltn_trans hj) /=; last by rewrite -add1n leq_add2r. move: hj; rewrite leq_eqVlt prednK // => /predU1P [<- | hj]. by rewrite -subn1 subnAC subKn // !subn1 !lead_coefE subrr. have/leq_sizeP-> //: size q <= j - (size r - size q). by rewrite subnBA // leq_psubRL // leq_add2r. by move/leq_sizeP: (hj) => -> //; rewrite mul0r mulr0 subr0. - apply: leq_trans (size_polyD _ _) _; rewrite geq_max; apply/andP; split. apply: leq_trans (size_polyMleq _ _) _. by rewrite size_polyC lead_coef_eq0 q0 /= addn1. rewrite size_polyN; apply: leq_trans (size_polyMleq _ _) _. apply: leq_trans hr; rewrite -subn1 leq_subLR -[in (1 + _)%N](subnK hqr). by rewrite addnA leq_add2r add1n -(@size_polyXn R) size_scale_leq. apply: leq_trans (size_polyD _ _) _; rewrite geq_max; apply/andP; split. apply: leq_trans (size_polyMleq _ _) _. by rewrite size_polyC lead_coef_eq0 q0 /= addnS addn0. apply: leq_trans (size_scale_leq _ _) _. by rewrite size_polyXn -subSn // leq_subLR -add1n leq_add. Qed. Lemma rmod0p p : rmodp 0 p = 0. Proof. rewrite /rmodp unlock; case: ifP => // Hp; rewrite /redivp_rec !size_poly0. by rewrite polySpred ?Hp. Qed. Lemma rmodp0 p : rmodp p 0 = p. Proof. by rewrite /rmodp unlock eqxx. Qed. Lemma rscalp_small p q : size p < size q -> rscalp p q = 0. Proof. rewrite /rscalp unlock; case: eqP => _ // spq. by case sp: (size p) => [| s] /=; rewrite spq. Qed. Lemma ltn_rmodp p q : (size (rmodp p q) < size q) = (q != 0). Proof. rewrite /rdivp /rmodp /rscalp unlock; have [->|q0] := eqVneq q 0. by rewrite /= size_poly0 ltn0. elim: (size p) 0%N 0 {1 3}p (leqnn (size p)) => [|n ihn] k q1 r. move/size_poly_leq0P->. by rewrite /= size_poly0 size_poly_gt0 q0 size_poly0 size_poly_gt0. move=> hr /=; case: (ltnP (size r)) => // hsrq; apply/ihn/leq_sizeP => j hnj. rewrite coefB -scalerAl !coefZ coefXnM coefMC ltn_subRL ltnNge. have sq: 0 < size q by rewrite size_poly_gt0. have sr: 0 < size r by apply: leq_trans hsrq. have hj: (size r).-1 <= j by apply: leq_trans hnj; rewrite -ltnS prednK. move: (leq_add sq hj); rewrite add1n prednK // => -> /=. move: hj; rewrite leq_eqVlt prednK // => /predU1P [<- | hj]. by rewrite -predn_sub subKn // !lead_coefE subrr. have/leq_sizeP -> //: size q <= j - (size r - size q). by rewrite subnBA // leq_subRL ?leq_add2r // (leq_trans hj) // leq_addr. by move/leq_sizeP: hj => -> //; rewrite mul0r mulr0 subr0. Qed. Lemma ltn_rmodpN0 p q : q != 0 -> size (rmodp p q) < size q. Proof. by rewrite ltn_rmodp. Qed. Lemma rmodp1 p : rmodp p 1 = 0. Proof. apply/eqP; have := ltn_rmodp p 1. by rewrite !oner_neq0 -size_poly_eq0 size_poly1 ltnS leqn0. Qed. Lemma rmodp_small p q : size p < size q -> rmodp p q = p. Proof. rewrite /rmodp unlock; have [->|_] := eqP; first by rewrite size_poly0. by case sp: (size p) => [| s] Hs /=; rewrite sp Hs /=. Qed. Lemma leq_rmodp m d : size (rmodp m d) <= size m. Proof. have [/rmodp_small -> //|h] := ltnP (size m) (size d). have [->|d0] := eqVneq d 0; first by rewrite rmodp0. by apply: leq_trans h; apply: ltnW; rewrite ltn_rmodp. Qed. Lemma rmodpC p c : c != 0 -> rmodp p c%:P = 0. Proof. move=> Hc; apply/eqP; rewrite -size_poly_leq0 -ltnS. have -> : 1%N = nat_of_bool (c != 0) by rewrite Hc. by rewrite -size_polyC ltn_rmodp polyC_eq0. Qed. Lemma rdvdp0 d : rdvdp d 0. Proof. by rewrite /rdvdp rmod0p. Qed. Lemma rdvd0p n : rdvdp 0 n = (n == 0). Proof. by rewrite /rdvdp rmodp0. Qed. Lemma rdvd0pP n : reflect (n = 0) (rdvdp 0 n). Proof. by apply: (iffP idP); rewrite rdvd0p; move/eqP. Qed. Lemma rdvdpN0 p q : rdvdp p q -> q != 0 -> p != 0. Proof. by move=> pq hq; apply: contraTneq pq => ->; rewrite rdvd0p. Qed. Lemma rdvdp1 d : rdvdp d 1 = (size d == 1). Proof. rewrite /rdvdp; have [->|] := eqVneq d 0. by rewrite rmodp0 size_poly0 (negPf (oner_neq0 _)). rewrite -size_poly_leq0 -ltnS; case: ltngtP => // [|/eqP] hd _. by rewrite rmodp_small ?size_poly1 // oner_eq0. have [c cn0 ->] := size_poly1P _ hd. rewrite /rmodp unlock -size_poly_eq0 size_poly1 /= size_poly1 size_polyC cn0 /=. by rewrite polyC_eq0 (negPf cn0) !lead_coefC !scale1r subrr !size_poly0. Qed. Lemma rdvd1p m : rdvdp 1 m. Proof. by rewrite /rdvdp rmodp1. Qed. Lemma Nrdvdp_small (n d : {poly R}) : n != 0 -> size n < size d -> rdvdp d n = false. Proof. by move=> nn0 hs; rewrite /rdvdp (rmodp_small hs); apply: negPf. Qed. Lemma rmodp_eq0P p q : reflect (rmodp p q = 0) (rdvdp q p). Proof. exact: (iffP eqP). Qed. Lemma rmodp_eq0 p q : rdvdp q p -> rmodp p q = 0. Proof. exact: rmodp_eq0P. Qed. Lemma rdvdp_leq p q : rdvdp p q -> q != 0 -> size p <= size q. Proof. by move=> dvd_pq; rewrite leqNgt; apply: contra => /rmodp_small <-. Qed. Definition rgcdp p q := let: (p1, q1) := if size p < size q then (q, p) else (p, q) in if p1 == 0 then q1 else let fix loop (n : nat) (pp qq : {poly R}) {struct n} := let rr := rmodp pp qq in if rr == 0 then qq else if n is n1.+1 then loop n1 qq rr else rr in loop (size p1) p1 q1. Lemma rgcd0p : left_id 0 rgcdp. Proof. move=> p; rewrite /rgcdp size_poly0 size_poly_gt0 if_neg. case: ifP => /= [_ | nzp]; first by rewrite eqxx. by rewrite polySpred !(rmodp0, nzp) //; case: _.-1 => [|m]; rewrite rmod0p eqxx. Qed. Lemma rgcdp0 : right_id 0 rgcdp. Proof. move=> p; have:= rgcd0p p; rewrite /rgcdp size_poly0 size_poly_gt0. by case: eqVneq => p0; rewrite ?(eqxx, p0) //= eqxx. Qed. Lemma rgcdpE p q : rgcdp p q = if size p < size q then rgcdp (rmodp q p) p else rgcdp (rmodp p q) q. Proof. pose rgcdp_rec := fix rgcdp_rec (n : nat) (pp qq : {poly R}) {struct n} := let rr := rmodp pp qq in if rr == 0 then qq else if n is n1.+1 then rgcdp_rec n1 qq rr else rr. have Irec: forall m n p q, size q <= m -> size q <= n -> size q < size p -> rgcdp_rec m p q = rgcdp_rec n p q. + elim=> [|m Hrec] [|n] //= p1 q1. - move/size_poly_leq0P=> -> _; rewrite size_poly0 size_poly_gt0 rmodp0. by move/negPf->; case: n => [|n] /=; rewrite rmod0p eqxx. - move=> _ /size_poly_leq0P ->; rewrite size_poly0 size_poly_gt0 rmodp0. by move/negPf->; case: m {Hrec} => [|m] /=; rewrite rmod0p eqxx. case: eqVneq => Epq Sm Sn Sq //; have [->|nzq] := eqVneq q1 0. by case: n m {Sm Sn Hrec} => [|m] [|n] //=; rewrite rmod0p eqxx. apply: Hrec; last by rewrite ltn_rmodp. by rewrite -ltnS (leq_trans _ Sm) // ltn_rmodp. by rewrite -ltnS (leq_trans _ Sn) // ltn_rmodp. have [->|nzp] := eqVneq p 0. by rewrite rmod0p rmodp0 rgcd0p rgcdp0 if_same. have [->|nzq] := eqVneq q 0. by rewrite rmod0p rmodp0 rgcd0p rgcdp0 if_same. rewrite /rgcdp -/rgcdp_rec !ltn_rmodp (negPf nzp) (negPf nzq) /=. have [ltpq|leqp] := ltnP; rewrite !(negPf nzp, negPf nzq) //= polySpred //=. have [->|nzqp] := eqVneq. by case: (size p) => [|[|s]]; rewrite /= rmodp0 (negPf nzp) // rmod0p eqxx. apply: Irec => //; last by rewrite ltn_rmodp. by rewrite -ltnS -polySpred // (leq_trans _ ltpq) ?leqW // ltn_rmodp. by rewrite ltnW // ltn_rmodp. have [->|nzpq] := eqVneq. by case: (size q) => [|[|s]]; rewrite /= rmodp0 (negPf nzq) // rmod0p eqxx. apply: Irec => //; last by rewrite ltn_rmodp. by rewrite -ltnS -polySpred // (leq_trans _ leqp) // ltn_rmodp. by rewrite ltnW // ltn_rmodp. Qed. Variant comm_redivp_spec m d : nat * {poly R} * {poly R} -> Type := ComEdivnSpec k (q r : {poly R}) of (GRing.comm d (lead_coef d)%:P -> m * (lead_coef d ^+ k)%:P = q * d + r) & (d != 0 -> size r < size d) : comm_redivp_spec m d (k, q, r). Lemma comm_redivpP m d : comm_redivp_spec m d (redivp m d). Proof. rewrite unlock; have [->|Hd] := eqVneq d 0. by constructor; rewrite !(simp, eqxx). have: GRing.comm d (lead_coef d)%:P -> m * (lead_coef d ^+ 0)%:P = 0 * d + m. by rewrite !simp. elim: (size m) 0%N 0 {1 4 6}m (leqnn (size m)) => [|n IHn] k q r Hr /=. move/size_poly_leq0P: Hr ->. suff hsd: size (0: {poly R}) < size d by rewrite hsd => /= ?; constructor. by rewrite size_poly0 size_poly_gt0. case: ltnP => Hlt Heq; first by constructor. apply/IHn=> [|Cda]; last first. rewrite mulrDl addrAC -addrA subrK exprSr polyCM mulrA Heq //. by rewrite mulrDl -mulrA Cda mulrA. apply/leq_sizeP => j Hj; rewrite coefB coefMC -scalerAl coefZ coefXnM. rewrite ltn_subRL ltnNge (leq_trans Hr) /=; last first. by apply: leq_ltn_trans Hj _; rewrite -add1n leq_add2r size_poly_gt0. move: Hj; rewrite leq_eqVlt; case/predU1P => [<-{j} | Hj]; last first. rewrite !nth_default ?simp ?oppr0 ?(leq_trans Hr) //. by rewrite -{1}(subKn Hlt) leq_sub2r // (leq_trans Hr). move: Hr; rewrite leq_eqVlt ltnS; case/predU1P=> Hqq; last first. by rewrite !nth_default ?simp ?oppr0 // -{1}(subKn Hlt) leq_sub2r. rewrite /lead_coef Hqq polySpred // subSS subKn ?addrN //. by rewrite -subn1 leq_subLR add1n -Hqq. Qed. Lemma rmodpp p : GRing.comm p (lead_coef p)%:P -> rmodp p p = 0. Proof. move=> hC; rewrite /rmodp unlock; have [-> //|] := eqVneq. rewrite -size_poly_eq0 /redivp_rec; case sp: (size p)=> [|n] // _. rewrite sp ltnn subnn expr0 hC alg_polyC !simp subrr. by case: n sp => [|n] sp; rewrite size_polyC /= eqxx. Qed. Definition rcoprimep (p q : {poly R}) := size (rgcdp p q) == 1. Fixpoint rgdcop_rec q p n := if n is m.+1 then if rcoprimep p q then p else rgdcop_rec q (rdivp p (rgcdp p q)) m else (q == 0)%:R. Definition rgdcop q p := rgdcop_rec q p (size p). Lemma rgdcop0 q : rgdcop q 0 = (q == 0)%:R. Proof. by rewrite /rgdcop size_poly0. Qed. End RingPseudoDivision. End CommonRing. Module RingComRreg. Import CommonRing. Section ComRegDivisor. Variable R : nzRingType. Variable d : {poly R}. Hypothesis Cdl : GRing.comm d (lead_coef d)%:P. Hypothesis Rreg : GRing.rreg (lead_coef d). Implicit Types p q r : {poly R}. Lemma redivp_eq q r : size r < size d -> let k := (redivp (q * d + r) d).1.1 in let c := (lead_coef d ^+ k)%:P in redivp (q * d + r) d = (k, q * c, r * c). Proof. move=> lt_rd; case: comm_redivpP=> k q1 r1 /(_ Cdl) Heq. have dn0: d != 0 by case: (size d) lt_rd (size_poly_eq0 d) => // n _ <-. move=> /(_ dn0) Hs. have eC : q * d * (lead_coef d ^+ k)%:P = q * (lead_coef d ^+ k)%:P * d. by rewrite -mulrA polyC_exp (commrX k Cdl) mulrA. suff e1 : q1 = q * (lead_coef d ^+ k)%:P. congr (_, _, _) => //=; move/eqP: Heq. by rewrite [_ + r1]addrC -subr_eq e1 mulrDl addrAC eC subrr add0r; move/eqP. have : (q1 - q * (lead_coef d ^+ k)%:P) * d = r * (lead_coef d ^+ k)%:P - r1. apply: (@addIr _ r1); rewrite subrK. apply: (@addrI _ ((q * (lead_coef d ^+ k)%:P) * d)). by rewrite mulrDl mulNr !addrA [_ + (q1 * d)]addrC addrK -eC -mulrDl. move/eqP; rewrite -[_ == _ - _]subr_eq0 rreg_div0 //. by case/andP; rewrite subr_eq0; move/eqP. rewrite size_polyN; apply: (leq_ltn_trans (size_polyD _ _)); rewrite size_polyN. rewrite gtn_max Hs (leq_ltn_trans (size_polyMleq _ _)) //. rewrite size_polyC; case: (_ == _); last by rewrite addnS addn0. by rewrite addn0; apply: leq_ltn_trans lt_rd; case: size. Qed. (* this is a bad name *) Lemma rdivp_eq p : p * (lead_coef d ^+ (rscalp p d))%:P = (rdivp p d) * d + (rmodp p d). Proof. by rewrite /rdivp /rmodp /rscalp; case: comm_redivpP=> k q1 r1 Hc _; apply: Hc. Qed. (* section variables impose an inconvenient order on parameters *) Lemma eq_rdvdp k q1 p: p * ((lead_coef d)^+ k)%:P = q1 * d -> rdvdp d p. Proof. move=> he. have Hnq0 := rreg_lead0 Rreg; set lq := lead_coef d. pose v := rscalp p d; pose m := maxn v k. rewrite /rdvdp -(rreg_polyMC_eq0 _ (@rregX _ _ (m - v) Rreg)). suff: ((rdivp p d) * (lq ^+ (m - v))%:P - q1 * (lq ^+ (m - k))%:P) * d + (rmodp p d) * (lq ^+ (m - v))%:P == 0. rewrite rreg_div0 //; first by case/andP. by rewrite rreg_size ?ltn_rmodp //; exact: rregX. rewrite mulrDl addrAC mulNr -!mulrA polyC_exp -(commrX (m-v) Cdl). rewrite -polyC_exp mulrA -mulrDl -rdivp_eq // [(_ ^+ (m - k))%:P]polyC_exp. rewrite -(commrX (m-k) Cdl) -polyC_exp mulrA -he -!mulrA -!polyCM -/v. by rewrite -!exprD addnC subnK ?leq_maxl // addnC subnK ?subrr ?leq_maxr. Qed. Variant rdvdp_spec p q : {poly R} -> bool -> Type := | Rdvdp k q1 & p * ((lead_coef q)^+ k)%:P = q1 * q : rdvdp_spec p q 0 true | RdvdpN & rmodp p q != 0 : rdvdp_spec p q (rmodp p q) false. (* Is that version useable ? *) Lemma rdvdp_eqP p : rdvdp_spec p d (rmodp p d) (rdvdp d p). Proof. case hdvd: (rdvdp d p); last by apply: RdvdpN; move/rmodp_eq0P/eqP: hdvd. move/rmodp_eq0P: (hdvd)->; apply: (@Rdvdp _ _ (rscalp p d) (rdivp p d)). by rewrite rdivp_eq //; move/rmodp_eq0P: (hdvd)->; rewrite addr0. Qed. Lemma rdvdp_mull p : rdvdp d (p * d). Proof. by apply: (@eq_rdvdp 0 p); rewrite expr0 mulr1. Qed. Lemma rmodp_mull p : rmodp (p * d) d = 0. Proof. exact/eqP/rdvdp_mull. Qed. Lemma rmodpp : rmodp d d = 0. Proof. by rewrite -[d in rmodp d _]mul1r rmodp_mull. Qed. Lemma rdivpp : rdivp d d = (lead_coef d ^+ rscalp d d)%:P. Proof. have dn0 : d != 0 by rewrite -lead_coef_eq0 rreg_neq0. move: (rdivp_eq d); rewrite rmodpp addr0. suff ->: GRing.comm d (lead_coef d ^+ rscalp d d)%:P by move/(rreg_lead Rreg)->. by rewrite polyC_exp; apply: commrX. Qed. Lemma rdvdpp : rdvdp d d. Proof. exact/eqP/rmodpp. Qed. Lemma rdivpK p : rdvdp d p -> rdivp p d * d = p * (lead_coef d ^+ rscalp p d)%:P. Proof. by rewrite rdivp_eq /rdvdp; move/eqP->; rewrite addr0. Qed. End ComRegDivisor. End RingComRreg. Module RingMonic. Import CommonRing. Import RingComRreg. Section RingMonic. Variable R : nzRingType. Implicit Types p q r : {poly R}. Section MonicDivisor. Variable d : {poly R}. Hypothesis mond : d \is monic. Lemma redivp_eq q r : size r < size d -> let k := (redivp (q * d + r) d).1.1 in redivp (q * d + r) d = (k, q, r). Proof. case: (monic_comreg mond)=> Hc Hr /(redivp_eq Hc Hr q). by rewrite (eqP mond) => -> /=; rewrite expr1n !mulr1. Qed. Lemma rdivp_eq p : p = rdivp p d * d + rmodp p d. Proof. rewrite -rdivp_eq (eqP mond); last exact: commr1. by rewrite expr1n mulr1. Qed. Lemma rdivpp : rdivp d d = 1. Proof. by case: (monic_comreg mond) => hc hr; rewrite rdivpp // (eqP mond) expr1n. Qed. Lemma rdivp_addl_mul_small q r : size r < size d -> rdivp (q * d + r) d = q. Proof. by move=> Hd; case: (monic_comreg mond)=> Hc Hr; rewrite /rdivp redivp_eq. Qed. Lemma rdivp_addl_mul q r : rdivp (q * d + r) d = q + rdivp r d. Proof. case: (monic_comreg mond)=> Hc Hr; rewrite [r in _ * _ + r]rdivp_eq addrA. by rewrite -mulrDl rdivp_addl_mul_small // ltn_rmodp monic_neq0. Qed. Lemma rdivpDl q r : rdvdp d q -> rdivp (q + r) d = rdivp q d + rdivp r d. Proof. case: (monic_comreg mond)=> Hc Hr; rewrite [r in q + r]rdivp_eq addrA. rewrite [q in q + _ + _]rdivp_eq; move/rmodp_eq0P->. by rewrite addr0 -mulrDl rdivp_addl_mul_small // ltn_rmodp monic_neq0. Qed. Lemma rdivpDr q r : rdvdp d r -> rdivp (q + r) d = rdivp q d + rdivp r d. Proof. by rewrite addrC; move/rdivpDl->; rewrite addrC. Qed. Lemma rdivp_mull p : rdivp (p * d) d = p. Proof. by rewrite -[p * d]addr0 rdivp_addl_mul rdiv0p addr0. Qed. Lemma rmodp_mull p : rmodp (p * d) d = 0. Proof. by apply: rmodp_mull; rewrite (eqP mond); [apply: commr1 | apply: rreg1]. Qed. Lemma rmodpp : rmodp d d = 0. Proof. by apply: rmodpp; rewrite (eqP mond); [apply: commr1 | apply: rreg1]. Qed. Lemma rmodp_addl_mul_small q r : size r < size d -> rmodp (q * d + r) d = r. Proof. by move=> Hd; case: (monic_comreg mond)=> Hc Hr; rewrite /rmodp redivp_eq. Qed. Lemma rmodp_id (p : {poly R}) : rmodp (rmodp p d) d = rmodp p d. Proof. by rewrite rmodp_small // ltn_rmodpN0 // monic_neq0. Qed. Lemma rmodpD p q : rmodp (p + q) d = rmodp p d + rmodp q d. Proof. rewrite [p in LHS]rdivp_eq [q in LHS]rdivp_eq addrACA -mulrDl. rewrite rmodp_addl_mul_small //; apply: (leq_ltn_trans (size_polyD _ _)). by rewrite gtn_max !ltn_rmodp // monic_neq0. Qed. Lemma rmodpN p : rmodp (- p) d = - (rmodp p d). Proof. rewrite {1}(rdivp_eq p) opprD // -mulNr rmodp_addl_mul_small //. by rewrite size_polyN ltn_rmodp // monic_neq0. Qed. Lemma rmodpB p q : rmodp (p - q) d = rmodp p d - rmodp q d. Proof. by rewrite rmodpD rmodpN. Qed. Lemma rmodpZ a p : rmodp (a *: p) d = a *: (rmodp p d). Proof. case: (altP (a =P 0%R)) => [-> | cn0]; first by rewrite !scale0r rmod0p. have -> : ((a *: p) = (a *: (rdivp p d)) * d + a *: (rmodp p d))%R. by rewrite -scalerAl -scalerDr -rdivp_eq. rewrite rmodp_addl_mul_small //. rewrite -mul_polyC; apply: leq_ltn_trans (size_polyMleq _ _) _. rewrite size_polyC cn0 addSn add0n /= ltn_rmodp. exact: monic_neq0. Qed. Lemma rmodp_sum (I : Type) (r : seq I) (P : pred I) (F : I -> {poly R}) : rmodp (\sum_(i <- r | P i) F i) d = (\sum_(i <- r | P i) (rmodp (F i) d)). Proof. by elim/big_rec2: _ => [|i p q _ <-]; rewrite ?(rmod0p, rmodpD). Qed. Lemma rmodp_mulmr p q : rmodp (p * (rmodp q d)) d = rmodp (p * q) d. Proof. by rewrite [q in RHS]rdivp_eq mulrDr rmodpD mulrA rmodp_mull add0r. Qed. Lemma rdvdpp : rdvdp d d. Proof. by apply: rdvdpp; rewrite (eqP mond); [apply: commr1 | apply: rreg1]. Qed. (* section variables impose an inconvenient order on parameters *) Lemma eq_rdvdp q1 p : p = q1 * d -> rdvdp d p. Proof. (* this probably means I need to specify impl args for comm_rref_rdvdp *) move=> h; apply: (@eq_rdvdp _ _ _ _ 1 q1); rewrite (eqP mond). - exact: commr1. - exact: rreg1. by rewrite expr1n mulr1. Qed. Lemma rdvdp_mull p : rdvdp d (p * d). Proof. by apply: rdvdp_mull; rewrite (eqP mond) //; [apply: commr1 | apply: rreg1]. Qed. Lemma rdvdpP p : reflect (exists qq, p = qq * d) (rdvdp d p). Proof. case: (monic_comreg mond)=> Hc Hr; apply: (iffP idP) => [|[qq] /eq_rdvdp //]. by case: rdvdp_eqP=> // k qq; rewrite (eqP mond) expr1n mulr1 => ->; exists qq. Qed. Lemma rdivpK p : rdvdp d p -> (rdivp p d) * d = p. Proof. by move=> dvddp; rewrite [RHS]rdivp_eq rmodp_eq0 ?addr0. Qed. End MonicDivisor. Lemma drop_poly_rdivp n p : drop_poly n p = rdivp p 'X^n. Proof. rewrite -[p in RHS](poly_take_drop n) addrC rdivp_addl_mul ?monicXn//. by rewrite rdivp_small ?addr0// size_polyXn ltnS size_take_poly. Qed. Lemma take_poly_rmodp n p : take_poly n p = rmodp p 'X^n. Proof. have mX := monicXn R n; rewrite -[p in RHS](poly_take_drop n) rmodpD//. by rewrite rmodp_small ?rmodp_mull ?addr0// size_polyXn ltnS size_take_poly. Qed. End RingMonic. Section ComRingMonic. Variable R : comNzRingType. Implicit Types p q r : {poly R}. Variable d : {poly R}. Hypothesis mond : d \is monic. Lemma rmodp_mulml p q : rmodp (rmodp p d * q) d = rmodp (p * q) d. Proof. by rewrite [in LHS]mulrC [in RHS]mulrC rmodp_mulmr. Qed. Lemma rmodpX p n : rmodp ((rmodp p d) ^+ n) d = rmodp (p ^+ n) d. Proof. elim: n => [|n IH]; first by rewrite !expr0. rewrite !exprS -rmodp_mulmr // IH rmodp_mulmr //. by rewrite mulrC rmodp_mulmr // mulrC. Qed. Lemma rmodp_compr p q : rmodp (p \Po (rmodp q d)) d = (rmodp (p \Po q) d). Proof. elim/poly_ind: p => [|p c IH]; first by rewrite !comp_polyC !rmod0p. rewrite !comp_polyD !comp_polyM addrC rmodpD //. rewrite mulrC -rmodp_mulmr // IH rmodp_mulmr //. rewrite !comp_polyX !comp_polyC. by rewrite mulrC rmodp_mulmr // -rmodpD // addrC. Qed. End ComRingMonic. End RingMonic. Module Ring. Include CommonRing. Import RingMonic. Section ExtraMonicDivisor. Variable R : nzRingType. Implicit Types d p q r : {poly R}. Lemma rdivp1 p : rdivp p 1 = p. Proof. by rewrite -[p in LHS]mulr1 rdivp_mull // monic1. Qed. Lemma rdvdp_XsubCl p x : rdvdp ('X - x%:P) p = root p x. Proof. have [HcX Hr] := monic_comreg (monicXsubC x). apply/rmodp_eq0P/factor_theorem => [|[p1 ->]]; last exact/rmodp_mull/monicXsubC. move=> e0; exists (rdivp p ('X - x%:P)). by rewrite [LHS](rdivp_eq (monicXsubC x)) e0 addr0. Qed. Lemma polyXsubCP p x : reflect (p.[x] = 0) (rdvdp ('X - x%:P) p). Proof. by apply: (iffP idP); rewrite rdvdp_XsubCl; move/rootP. Qed. Lemma root_factor_theorem p x : root p x = (rdvdp ('X - x%:P) p). Proof. by rewrite rdvdp_XsubCl. Qed. End ExtraMonicDivisor. End Ring. Module ComRing. Import Ring. Import RingComRreg. Section CommutativeRingPseudoDivision. Variable R : comNzRingType. Implicit Types d p q m n r : {poly R}. Variant redivp_spec (m d : {poly R}) : nat * {poly R} * {poly R} -> Type := EdivnSpec k (q r: {poly R}) of (lead_coef d ^+ k) *: m = q * d + r & (d != 0 -> size r < size d) : redivp_spec m d (k, q, r). Lemma redivpP m d : redivp_spec m d (redivp m d). Proof. rewrite redivp_def; constructor; last by move=> dn0; rewrite ltn_rmodp. by rewrite -mul_polyC mulrC rdivp_eq //= /GRing.comm mulrC. Qed. Lemma rdivp_eq d p : (lead_coef d ^+ rscalp p d) *: p = rdivp p d * d + rmodp p d. Proof. by rewrite /rdivp /rmodp /rscalp; case: redivpP=> k q1 r1 Hc _; apply: Hc. Qed. Lemma rdvdp_eqP d p : rdvdp_spec p d (rmodp p d) (rdvdp d p). Proof. case hdvd: (rdvdp d p); last by move/rmodp_eq0P/eqP/RdvdpN: hdvd. move/rmodp_eq0P: (hdvd)->; apply: (@Rdvdp _ _ _ (rscalp p d) (rdivp p d)). by rewrite mulrC mul_polyC rdivp_eq; move/rmodp_eq0P: (hdvd)->; rewrite addr0. Qed. Lemma rdvdp_eq q p : rdvdp q p = (lead_coef q ^+ rscalp p q *: p == rdivp p q * q). Proof. rewrite rdivp_eq; apply/rmodp_eq0P/eqP => [->|/eqP]; first by rewrite addr0. by rewrite eq_sym addrC -subr_eq subrr; move/eqP<-. Qed. End CommutativeRingPseudoDivision. End ComRing. Module UnitRing. Import Ring. Section UnitRingPseudoDivision. Variable R : unitRingType. Implicit Type p q r d : {poly R}. Lemma uniq_roots_rdvdp p rs : all (root p) rs -> uniq_roots rs -> rdvdp (\prod_(z <- rs) ('X - z%:P)) p. Proof. move=> rrs /(uniq_roots_prod_XsubC rrs) [q ->]. exact/RingMonic.rdvdp_mull/monic_prod_XsubC. Qed. End UnitRingPseudoDivision. End UnitRing. Module IdomainDefs. Import Ring. Section IDomainPseudoDivisionDefs. Variable R : idomainType. Implicit Type p q r d : {poly R}. Definition edivp_expanded_def p q := let: (k, d, r) as edvpq := redivp p q in if lead_coef q \in GRing.unit then (0, (lead_coef q)^-k *: d, (lead_coef q)^-k *: r) else edvpq. Fact edivp_key : unit. Proof. by []. Qed. Definition edivp := locked_with edivp_key edivp_expanded_def. Canonical edivp_unlockable := [unlockable fun edivp]. Definition divp p q := ((edivp p q).1).2. Definition modp p q := (edivp p q).2. Definition scalp p q := ((edivp p q).1).1. Definition dvdp p q := modp q p == 0. Definition eqp p q := (dvdp p q) && (dvdp q p). End IDomainPseudoDivisionDefs. Notation "m %/ d" := (divp m d) : ring_scope. Notation "m %% d" := (modp m d) : ring_scope. Notation "p %| q" := (dvdp p q) : ring_scope. Notation "p %= q" := (eqp p q) : ring_scope. End IdomainDefs. Module WeakIdomain. Import Ring ComRing UnitRing IdomainDefs. Section WeakTheoryForIDomainPseudoDivision. Variable R : idomainType. Implicit Type p q r d : {poly R}. Lemma edivp_def p q : edivp p q = (scalp p q, divp p q, modp p q). Proof. by rewrite /scalp /divp /modp; case: (edivp p q) => [[]] /=. Qed. Lemma edivp_redivp p q : lead_coef q \in GRing.unit = false -> edivp p q = redivp p q. Proof. by move=> hu; rewrite unlock hu; case: (redivp p q) => [[? ?] ?]. Qed. Lemma divpE p q : p %/ q = if lead_coef q \in GRing.unit then lead_coef q ^- rscalp p q *: rdivp p q else rdivp p q. Proof. by case: ifP; rewrite /divp unlock redivp_def => ->. Qed. Lemma modpE p q : p %% q = if lead_coef q \in GRing.unit then lead_coef q ^- rscalp p q *: (rmodp p q) else rmodp p q. Proof. by case: ifP; rewrite /modp unlock redivp_def => ->. Qed. Lemma scalpE p q : scalp p q = if lead_coef q \in GRing.unit then 0 else rscalp p q. Proof. by case: ifP; rewrite /scalp unlock redivp_def => ->. Qed. Lemma dvdpE p q : p %| q = rdvdp p q. Proof. rewrite /dvdp modpE /rdvdp; case ulcq: (lead_coef p \in GRing.unit)=> //. rewrite -[in LHS]size_poly_eq0 size_scale ?size_poly_eq0 //. by rewrite invr_eq0 expf_neq0 //; apply: contraTneq ulcq => ->; rewrite unitr0. Qed. Lemma lc_expn_scalp_neq0 p q : lead_coef q ^+ scalp p q != 0. Proof. have [->|nzq] := eqVneq q 0; last by rewrite expf_neq0 ?lead_coef_eq0. by rewrite /scalp 2!unlock /= eqxx lead_coef0 unitr0 /= oner_neq0. Qed. Hint Resolve lc_expn_scalp_neq0 : core. Variant edivp_spec (m d : {poly R}) : nat * {poly R} * {poly R} -> bool -> Type := |Redivp_spec k (q r: {poly R}) of (lead_coef d ^+ k) *: m = q * d + r & lead_coef d \notin GRing.unit & (d != 0 -> size r < size d) : edivp_spec m d (k, q, r) false |Fedivp_spec (q r: {poly R}) of m = q * d + r & (lead_coef d \in GRing.unit) & (d != 0 -> size r < size d) : edivp_spec m d (0, q, r) true. (* There are several ways to state this fact. The most appropriate statement*) (* might be polished in light of usage. *) Lemma edivpP m d : edivp_spec m d (edivp m d) (lead_coef d \in GRing.unit). Proof. have hC : GRing.comm d (lead_coef d)%:P by rewrite /GRing.comm mulrC. case ud: (lead_coef d \in GRing.unit); last first. rewrite edivp_redivp // redivp_def; constructor; rewrite ?ltn_rmodp // ?ud //. by rewrite rdivp_eq. have cdn0: lead_coef d != 0 by apply: contraTneq ud => ->; rewrite unitr0. rewrite unlock ud redivp_def; constructor => //. rewrite -scalerAl -scalerDr -mul_polyC. have hn0 : (lead_coef d ^+ rscalp m d)%:P != 0. by rewrite polyC_eq0; apply: expf_neq0. apply: (mulfI hn0); rewrite !mulrA -exprVn !polyC_exp -exprMn -polyCM. by rewrite divrr // expr1n mul1r -polyC_exp mul_polyC rdivp_eq. move=> dn0; rewrite size_scale ?ltn_rmodp // -exprVn expf_eq0 negb_and. by rewrite invr_eq0 cdn0 orbT. Qed. Lemma edivp_eq d q r : size r < size d -> lead_coef d \in GRing.unit -> edivp (q * d + r) d = (0, q, r). Proof. have hC : GRing.comm d (lead_coef d)%:P by apply: mulrC. move=> hsrd hu; rewrite unlock hu; case et: (redivp _ _) => [[s qq] rr]. have cdn0 : lead_coef d != 0 by case: eqP hu => //= ->; rewrite unitr0. move: (et); rewrite RingComRreg.redivp_eq //; last exact/rregP. rewrite et /= mulrC (mulrC r) !mul_polyC; case=> <- <-. by rewrite !scalerA mulVr ?scale1r // unitrX. Qed. Lemma divp_eq p q : (lead_coef q ^+ scalp p q) *: p = (p %/ q) * q + (p %% q). Proof. rewrite divpE modpE scalpE. case uq: (lead_coef q \in GRing.unit); last by rewrite rdivp_eq. rewrite expr0 scale1r; have [->|qn0] := eqVneq q 0. by rewrite lead_coef0 expr0n /rscalp unlock eqxx invr1 !scale1r rmodp0 !simp. by rewrite -scalerAl -scalerDr -rdivp_eq scalerA mulVr (scale1r, unitrX). Qed. Lemma dvdp_eq q p : (q %| p) = (lead_coef q ^+ scalp p q *: p == (p %/ q) * q). Proof. rewrite dvdpE rdvdp_eq scalpE divpE; case: ifP => ulcq //. rewrite expr0 scale1r -scalerAl; apply/eqP/eqP => [<- | {2}->]. by rewrite scalerA mulVr ?scale1r // unitrX. by rewrite scalerA mulrV ?scale1r // unitrX. Qed. Lemma divpK d p : d %| p -> p %/ d * d = (lead_coef d ^+ scalp p d) *: p. Proof. by rewrite dvdp_eq; move/eqP->. Qed. Lemma divpKC d p : d %| p -> d * (p %/ d) = (lead_coef d ^+ scalp p d) *: p. Proof. by move=> ?; rewrite mulrC divpK. Qed. Lemma dvdpP q p : reflect (exists2 cqq, cqq.1 != 0 & cqq.1 *: p = cqq.2 * q) (q %| p). Proof. rewrite dvdp_eq; apply: (iffP eqP) => [e | [[c qq] cn0 e]]. by exists (lead_coef q ^+ scalp p q, p %/ q) => //=. apply/eqP; rewrite -dvdp_eq dvdpE. have Ecc: c%:P != 0 by rewrite polyC_eq0. have [->|nz_p] := eqVneq p 0; first by rewrite rdvdp0. pose p1 : {poly R} := lead_coef q ^+ rscalp p q *: qq - c *: (rdivp p q). have E1: c *: rmodp p q = p1 * q. rewrite mulrDl mulNr -scalerAl -e scalerA mulrC -scalerA -scalerAl. by rewrite -scalerBr rdivp_eq addrC addKr. suff: p1 * q == 0 by rewrite -E1 -mul_polyC mulf_eq0 (negPf Ecc). rewrite mulf_eq0; apply/norP; case=> p1_nz q_nz; have:= ltn_rmodp p q. by rewrite q_nz -(size_scale _ cn0) E1 size_mul // polySpred // ltnNge leq_addl. Qed. Lemma mulpK p q : q != 0 -> p * q %/ q = lead_coef q ^+ scalp (p * q) q *: p. Proof. move=> qn0; apply: (rregP qn0); rewrite -scalerAl divp_eq. suff -> : (p * q) %% q = 0 by rewrite addr0. rewrite modpE RingComRreg.rmodp_mull ?scaler0 ?if_same //. by red; rewrite mulrC. by apply/rregP; rewrite lead_coef_eq0. Qed. Lemma mulKp p q : q != 0 -> q * p %/ q = lead_coef q ^+ scalp (p * q) q *: p. Proof. by move=> nzq; rewrite mulrC; apply: mulpK. Qed. Lemma divpp p : p != 0 -> p %/ p = (lead_coef p ^+ scalp p p)%:P. Proof. move=> np0; have := divp_eq p p. suff -> : p %% p = 0 by rewrite addr0 -mul_polyC; move/(mulIf np0). rewrite modpE Ring.rmodpp; last by red; rewrite mulrC. by rewrite scaler0 if_same. Qed. End WeakTheoryForIDomainPseudoDivision. #[global] Hint Resolve lc_expn_scalp_neq0 : core. End WeakIdomain. Module CommonIdomain. Import Ring ComRing UnitRing IdomainDefs WeakIdomain. Section IDomainPseudoDivision. Variable R : idomainType. Implicit Type p q r d m n : {poly R}. Lemma scalp0 p : scalp p 0 = 0. Proof. by rewrite /scalp unlock lead_coef0 unitr0 unlock eqxx. Qed. Lemma divp_small p q : size p < size q -> p %/ q = 0. Proof. move=> spq; rewrite /divp unlock redivp_def /=. by case: ifP; rewrite rdivp_small // scaler0. Qed. Lemma leq_divp p q : (size (p %/ q) <= size p). Proof. rewrite /divp unlock redivp_def /=; case: ifP => ulcq; rewrite ?leq_rdivp //=. rewrite size_scale ?leq_rdivp // -exprVn expf_neq0 // invr_eq0. by case: eqP ulcq => // ->; rewrite unitr0. Qed. Lemma div0p p : 0 %/ p = 0. Proof. by rewrite /divp unlock redivp_def /=; case: ifP; rewrite rdiv0p // scaler0. Qed. Lemma divp0 p : p %/ 0 = 0. Proof. by rewrite /divp unlock redivp_def /=; case: ifP; rewrite rdivp0 // scaler0. Qed. Lemma divp1 m : m %/ 1 = m. Proof. by rewrite divpE lead_coefC unitr1 Ring.rdivp1 expr1n invr1 scale1r. Qed. Lemma modp0 p : p %% 0 = p. Proof. rewrite /modp unlock redivp_def; case: ifP; rewrite rmodp0 //= lead_coef0. by rewrite unitr0. Qed. Lemma mod0p p : 0 %% p = 0. Proof. by rewrite /modp unlock redivp_def /=; case: ifP; rewrite rmod0p // scaler0. Qed. Lemma modp1 p : p %% 1 = 0. Proof. by rewrite /modp unlock redivp_def /=; case: ifP; rewrite rmodp1 // scaler0. Qed. Hint Resolve divp0 divp1 mod0p modp0 modp1 : core. Lemma modp_small p q : size p < size q -> p %% q = p. Proof. move=> spq; rewrite /modp unlock redivp_def; case: ifP; rewrite rmodp_small //. by rewrite /= rscalp_small // expr0 /= invr1 scale1r. Qed. Lemma modpC p c : c != 0 -> p %% c%:P = 0. Proof. move=> cn0; rewrite /modp unlock redivp_def /=; case: ifP; rewrite ?rmodpC //. by rewrite scaler0. Qed. Lemma modp_mull p q : (p * q) %% q = 0. Proof. have [-> | nq0] := eqVneq q 0; first by rewrite modp0 mulr0. have rlcq : GRing.rreg (lead_coef q) by apply/rregP; rewrite lead_coef_eq0. have hC : GRing.comm q (lead_coef q)%:P by red; rewrite mulrC. rewrite modpE; case: ifP => ulcq; rewrite RingComRreg.rmodp_mull //. exact: scaler0. Qed. Lemma modp_mulr d p : (d * p) %% d = 0. Proof. by rewrite mulrC modp_mull. Qed. Lemma modpp d : d %% d = 0. Proof. by rewrite -[d in d %% _]mul1r modp_mull. Qed. Lemma ltn_modp p q : (size (p %% q) < size q) = (q != 0). Proof. rewrite /modp unlock redivp_def /=; case: ifP=> ulcq; rewrite ?ltn_rmodp //=. rewrite size_scale ?ltn_rmodp // -exprVn expf_neq0 // invr_eq0. by case: eqP ulcq => // ->; rewrite unitr0. Qed. Lemma ltn_divpl d q p : d != 0 -> (size (q %/ d) < size p) = (size q < size (p * d)). Proof. move=> dn0. have: (lead_coef d) ^+ (scalp q d) != 0 by apply: lc_expn_scalp_neq0. move/(size_scale q)<-; rewrite divp_eq; have [->|quo0] := eqVneq (q %/ d) 0. rewrite mul0r add0r size_poly0 size_poly_gt0. have [->|pn0] := eqVneq p 0; first by rewrite mul0r size_poly0 ltn0. by rewrite size_mul // (polySpred pn0) addSn ltn_addl // ltn_modp. rewrite size_polyDl; last first. by rewrite size_mul // (polySpred quo0) addSn /= ltn_addl // ltn_modp. have [->|pn0] := eqVneq p 0; first by rewrite mul0r size_poly0 !ltn0. by rewrite !size_mul ?quo0 // (polySpred dn0) !addnS ltn_add2r. Qed. Lemma leq_divpr d p q : d != 0 -> (size p <= size (q %/ d)) = (size (p * d) <= size q). Proof. by move=> dn0; rewrite leqNgt ltn_divpl // -leqNgt. Qed. Lemma divpN0 d p : d != 0 -> (p %/ d != 0) = (size d <= size p). Proof. move=> dn0. by rewrite -[d in RHS]mul1r -leq_divpr // size_polyC oner_eq0 size_poly_gt0. Qed. Lemma size_divp p q : q != 0 -> size (p %/ q) = (size p - (size q).-1)%N. Proof. move=> nq0; case: (leqP (size q) (size p)) => sqp; last first. move: (sqp); rewrite -{1}(ltn_predK sqp) ltnS -subn_eq0 divp_small //. by move/eqP->; rewrite size_poly0. have np0 : p != 0. by rewrite -size_poly_gt0; apply: leq_trans sqp; rewrite size_poly_gt0. have /= := congr1 (size \o @polyseq R) (divp_eq p q). rewrite size_scale; last by rewrite expf_eq0 lead_coef_eq0 (negPf nq0) andbF. have [->|qq0] := eqVneq (p %/ q) 0. by rewrite mul0r add0r=> es; move: nq0; rewrite -(ltn_modp p) -es ltnNge sqp. rewrite size_polyDl. by move->; apply/eqP; rewrite size_mul // (polySpred nq0) addnS /= addnK. rewrite size_mul ?qq0 //. move: nq0; rewrite -(ltn_modp p); move/leq_trans; apply. by rewrite (polySpred qq0) addSn /= leq_addl. Qed. Lemma ltn_modpN0 p q : q != 0 -> size (p %% q) < size q. Proof. by rewrite ltn_modp. Qed. Lemma modp_id p q : (p %% q) %% q = p %% q. Proof. by have [->|qn0] := eqVneq q 0; rewrite ?modp0 // modp_small ?ltn_modp. Qed. Lemma leq_modp m d : size (m %% d) <= size m. Proof. rewrite /modp unlock redivp_def /=; case: ifP; rewrite ?leq_rmodp //. move=> ud; rewrite size_scale ?leq_rmodp // invr_eq0 expf_neq0 //. by apply: contraTneq ud => ->; rewrite unitr0. Qed. Lemma dvdp0 d : d %| 0. Proof. by rewrite /dvdp mod0p. Qed. Hint Resolve dvdp0 : core. Lemma dvd0p p : (0 %| p) = (p == 0). Proof. by rewrite /dvdp modp0. Qed. Lemma dvd0pP p : reflect (p = 0) (0 %| p). Proof. by apply: (iffP idP); rewrite dvd0p; move/eqP. Qed. Lemma dvdpN0 p q : p %| q -> q != 0 -> p != 0. Proof. by move=> pq hq; apply: contraTneq pq => ->; rewrite dvd0p. Qed. Lemma dvdp1 d : (d %| 1) = (size d == 1). Proof. rewrite /dvdp modpE; case ud: (lead_coef d \in GRing.unit); last exact: rdvdp1. rewrite -size_poly_eq0 size_scale; first by rewrite size_poly_eq0 -rdvdp1. by rewrite invr_eq0 expf_neq0 //; apply: contraTneq ud => ->; rewrite unitr0. Qed. Lemma dvd1p m : 1 %| m. Proof. by rewrite /dvdp modp1. Qed. Lemma gtNdvdp p q : p != 0 -> size p < size q -> (q %| p) = false. Proof. by move=> nn0 hs; rewrite /dvdp; rewrite (modp_small hs); apply: negPf. Qed. Lemma modp_eq0P p q : reflect (p %% q = 0) (q %| p). Proof. exact: (iffP eqP). Qed. Lemma modp_eq0 p q : (q %| p) -> p %% q = 0. Proof. exact: modp_eq0P. Qed. Lemma leq_divpl d p q : d %| p -> (size (p %/ d) <= size q) = (size p <= size (q * d)). Proof. case: (eqVneq d 0) => [-> /dvd0pP -> | nd0 hd]. by rewrite divp0 size_poly0 !leq0n. rewrite leq_eqVlt ltn_divpl // (leq_eqVlt (size p)). case lhs: (size p < size (q * d)); rewrite ?orbT ?orbF //. have: (lead_coef d) ^+ (scalp p d) != 0 by rewrite expf_neq0 // lead_coef_eq0. move/(size_scale p)<-; rewrite divp_eq; move/modp_eq0P: hd->; rewrite addr0. have [-> | quon0] := eqVneq (p %/ d) 0. rewrite mul0r size_poly0 2!(eq_sym 0) !size_poly_eq0. by rewrite mulf_eq0 (negPf nd0) orbF. have [-> | nq0] := eqVneq q 0. by rewrite mul0r size_poly0 !size_poly_eq0 mulf_eq0 (negPf nd0) orbF. by rewrite !size_mul // (polySpred nd0) !addnS /= eqn_add2r. Qed. Lemma dvdp_leq p q : q != 0 -> p %| q -> size p <= size q. Proof. move=> nq0 /modp_eq0P. by case: leqP => // /modp_small -> /eqP; rewrite (negPf nq0). Qed. Lemma eq_dvdp c quo q p : c != 0 -> c *: p = quo * q -> q %| p. Proof. move=> cn0; case: (eqVneq p 0) => [->|nz_quo def_quo] //. pose p1 : {poly R} := lead_coef q ^+ scalp p q *: quo - c *: (p %/ q). have E1: c *: (p %% q) = p1 * q. rewrite mulrDl mulNr -scalerAl -def_quo scalerA mulrC -scalerA. by rewrite -scalerAl -scalerBr divp_eq addrAC subrr add0r. rewrite /dvdp; apply/idPn=> m_nz. have: p1 * q != 0 by rewrite -E1 -mul_polyC mulf_neq0 // polyC_eq0. rewrite mulf_eq0; case/norP=> p1_nz q_nz. have := ltn_modp p q; rewrite q_nz -(size_scale (p %% q) cn0) E1. by rewrite size_mul // polySpred // ltnNge leq_addl. Qed. Lemma dvdpp d : d %| d. Proof. by rewrite /dvdp modpp. Qed. Hint Resolve dvdpp : core. Lemma divp_dvd p q : p %| q -> (q %/ p) %| q. Proof. have [-> | np0] := eqVneq p 0; first by rewrite divp0. rewrite dvdp_eq => /eqP h. apply: (@eq_dvdp ((lead_coef p)^+ (scalp q p)) p); last by rewrite mulrC. by rewrite expf_neq0 // lead_coef_eq0. Qed. Lemma dvdp_mull m d n : d %| n -> d %| m * n. Proof. case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite mulr0 dvdpp. rewrite dvdp_eq => /eqP e. apply: (@eq_dvdp (lead_coef d ^+ scalp n d) (m * (n %/ d))). by rewrite expf_neq0 // lead_coef_eq0. by rewrite scalerAr e mulrA. Qed. Lemma dvdp_mulr n d m : d %| m -> d %| m * n. Proof. by move=> hdm; rewrite mulrC dvdp_mull. Qed. Hint Resolve dvdp_mull dvdp_mulr : core. Lemma dvdp_mul d1 d2 m1 m2 : d1 %| m1 -> d2 %| m2 -> d1 * d2 %| m1 * m2. Proof. case: (eqVneq d1 0) => [-> /dvd0pP -> | d1n0]; first by rewrite !mul0r dvdpp. case: (eqVneq d2 0) => [-> _ /dvd0pP -> | d2n0]; first by rewrite !mulr0. rewrite dvdp_eq; set c1 := _ ^+ _; set q1 := _ %/ _; move/eqP=> Hq1. rewrite dvdp_eq; set c2 := _ ^+ _; set q2 := _ %/ _; move/eqP=> Hq2. apply: (@eq_dvdp (c1 * c2) (q1 * q2)). by rewrite mulf_neq0 // expf_neq0 // lead_coef_eq0. rewrite -scalerA scalerAr scalerAl Hq1 Hq2 -!mulrA. by rewrite [d1 * (q2 * _)]mulrCA. Qed. Lemma dvdp_addr m d n : d %| m -> (d %| m + n) = (d %| n). Proof. case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite add0r. rewrite dvdp_eq; set c1 := _ ^+ _; set q1 := _ %/ _; move/eqP=> Eq1. apply/idP/idP; rewrite dvdp_eq; set c2 := _ ^+ _; set q2 := _ %/ _. have sn0 : c1 * c2 != 0. by rewrite !mulf_neq0 // expf_eq0 lead_coef_eq0 (negPf dn0) andbF. move/eqP=> Eq2; apply: (@eq_dvdp _ (c1 *: q2 - c2 *: q1) _ _ sn0). rewrite mulrDl -scaleNr -!scalerAl -Eq1 -Eq2 !scalerA. by rewrite mulNr mulrC scaleNr -scalerBr addrC addKr. have sn0 : c1 * c2 != 0. by rewrite !mulf_neq0 // expf_eq0 lead_coef_eq0 (negPf dn0) andbF. move/eqP=> Eq2; apply: (@eq_dvdp _ (c1 *: q2 + c2 *: q1) _ _ sn0). by rewrite mulrDl -!scalerAl -Eq1 -Eq2 !scalerA mulrC addrC scalerDr. Qed. Lemma dvdp_addl n d m : d %| n -> (d %| m + n) = (d %| m). Proof. by rewrite addrC; apply: dvdp_addr. Qed. Lemma dvdp_add d m n : d %| m -> d %| n -> d %| m + n. Proof. by move/dvdp_addr->. Qed. Lemma dvdp_add_eq d m n : d %| m + n -> (d %| m) = (d %| n). Proof. by move=> ?; apply/idP/idP; [move/dvdp_addr <-| move/dvdp_addl <-]. Qed. Lemma dvdp_subr d m n : d %| m -> (d %| m - n) = (d %| n). Proof. by move=> ?; apply: dvdp_add_eq; rewrite -addrA addNr simp. Qed. Lemma dvdp_subl d m n : d %| n -> (d %| m - n) = (d %| m). Proof. by move/dvdp_addl<-; rewrite subrK. Qed. Lemma dvdp_sub d m n : d %| m -> d %| n -> d %| m - n. Proof. by move=> *; rewrite dvdp_subl. Qed. Lemma dvdp_mod d n m : d %| n -> (d %| m) = (d %| m %% n). Proof. have [-> | nn0] := eqVneq n 0; first by rewrite modp0. case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite modp0. rewrite dvdp_eq; set c1 := _ ^+ _; set q1 := _ %/ _; move/eqP=> Eq1. apply/idP/idP; rewrite dvdp_eq; set c2 := _ ^+ _; set q2 := _ %/ _. have sn0 : c1 * c2 != 0. by rewrite !mulf_neq0 // expf_eq0 lead_coef_eq0 (negPf dn0) andbF. pose quo := (c1 * lead_coef n ^+ scalp m n) *: q2 - c2 *: (m %/ n) * q1. move/eqP=> Eq2; apply: (@eq_dvdp _ quo _ _ sn0). rewrite mulrDl mulNr -!scalerAl -!mulrA -Eq1 -Eq2 -scalerAr !scalerA. rewrite mulrC [_ * c2]mulrC mulrA -[((_ * _) * _) *: _]scalerA -scalerBr. by rewrite divp_eq addrC addKr. have sn0 : c1 * c2 * lead_coef n ^+ scalp m n != 0. rewrite !mulf_neq0 // expf_eq0 lead_coef_eq0 ?(negPf dn0) ?andbF //. by rewrite (negPf nn0) andbF. move/eqP=> Eq2; apply: (@eq_dvdp _ (c2 *: (m %/ n) * q1 + c1 *: q2) _ _ sn0). rewrite -scalerA divp_eq scalerDr -!scalerA Eq2 scalerAl scalerAr Eq1. by rewrite scalerAl mulrDl mulrA. Qed. Lemma dvdp_trans : transitive (@dvdp R). Proof. move=> n d m. case: (eqVneq d 0) => [-> /dvd0pP -> // | dn0]. case: (eqVneq n 0) => [-> _ /dvd0pP -> // | nn0]. rewrite dvdp_eq; set c1 := _ ^+ _; set q1 := _ %/ _; move/eqP=> Hq1. rewrite dvdp_eq; set c2 := _ ^+ _; set q2 := _ %/ _; move/eqP=> Hq2. have sn0 : c1 * c2 != 0 by rewrite mulf_neq0 // expf_neq0 // lead_coef_eq0. apply: (@eq_dvdp _ (q2 * q1) _ _ sn0). by rewrite -scalerA Hq2 scalerAr Hq1 mulrA. Qed. Lemma dvdp_mulIl p q : p %| p * q. Proof. exact/dvdp_mulr/dvdpp. Qed. Lemma dvdp_mulIr p q : q %| p * q. Proof. exact/dvdp_mull/dvdpp. Qed. Lemma dvdp_mul2r r p q : r != 0 -> (p * r %| q * r) = (p %| q). Proof. move=> nzr. have [-> | pn0] := eqVneq p 0. by rewrite mul0r !dvd0p mulf_eq0 (negPf nzr) orbF. have [-> | qn0] := eqVneq q 0; first by rewrite mul0r !dvdp0. apply/idP/idP; last by move=> ?; rewrite dvdp_mul ?dvdpp. rewrite dvdp_eq; set c := _ ^+ _; set x := _ %/ _; move/eqP=> Hx. apply: (@eq_dvdp c x); first by rewrite expf_neq0 // lead_coef_eq0 mulf_neq0. by apply: (mulIf nzr); rewrite -mulrA -scalerAl. Qed. Lemma dvdp_mul2l r p q: r != 0 -> (r * p %| r * q) = (p %| q). Proof. by rewrite ![r * _]mulrC; apply: dvdp_mul2r. Qed. Lemma ltn_divpr d p q : d %| q -> (size p < size (q %/ d)) = (size (p * d) < size q). Proof. by move=> dv_d_q; rewrite !ltnNge leq_divpl. Qed. Lemma dvdp_exp d k p : 0 < k -> d %| p -> d %| (p ^+ k). Proof. by case: k => // k _ d_dv_m; rewrite exprS dvdp_mulr. Qed. Lemma dvdp_exp2l d k l : k <= l -> d ^+ k %| d ^+ l. Proof. by move/subnK <-; rewrite exprD dvdp_mull // ?lead_coef_exp ?unitrX. Qed. Lemma dvdp_Pexp2l d k l : 1 < size d -> (d ^+ k %| d ^+ l) = (k <= l). Proof. move=> sd; case: leqP => [|gt_n_m]; first exact: dvdp_exp2l. have dn0 : d != 0 by rewrite -size_poly_gt0; apply: ltn_trans sd. rewrite gtNdvdp ?expf_neq0 // polySpred ?expf_neq0 // size_exp /=. rewrite [size (d ^+ k)]polySpred ?expf_neq0 // size_exp ltnS ltn_mul2l. by move: sd; rewrite -subn_gt0 subn1; move->. Qed. Lemma dvdp_exp2r p q k : p %| q -> p ^+ k %| q ^+ k. Proof. case: (eqVneq p 0) => [-> /dvd0pP -> // | pn0]. rewrite dvdp_eq; set c := _ ^+ _; set t := _ %/ _; move/eqP=> e. apply: (@eq_dvdp (c ^+ k) (t ^+ k)); first by rewrite !expf_neq0 ?lead_coef_eq0. by rewrite -exprMn -exprZn; congr (_ ^+ k). Qed. Lemma dvdp_exp_sub p q k l: p != 0 -> (p ^+ k %| q * p ^+ l) = (p ^+ (k - l) %| q). Proof. move=> pn0; case: (leqP k l)=> [|/ltnW] hkl. move: (hkl); rewrite -subn_eq0; move/eqP->; rewrite expr0 dvd1p. exact/dvdp_mull/dvdp_exp2l. by rewrite -[in LHS](subnK hkl) exprD dvdp_mul2r // expf_eq0 (negPf pn0) andbF. Qed. Lemma dvdp_XsubCl p x : ('X - x%:P) %| p = root p x. Proof. by rewrite dvdpE; apply: Ring.rdvdp_XsubCl. Qed. Lemma root_dvdp p q x : p %| q -> root p x -> root q x. Proof. by rewrite -!dvdp_XsubCl => /[swap]; exact: dvdp_trans. Qed. Lemma polyXsubCP p x : reflect (p.[x] = 0) (('X - x%:P) %| p). Proof. by rewrite dvdpE; apply: Ring.polyXsubCP. Qed. Lemma eqp_div_XsubC p c : (p == (p %/ ('X - c%:P)) * ('X - c%:P)) = ('X - c%:P %| p). Proof. by rewrite dvdp_eq lead_coefXsubC expr1n scale1r. Qed. Lemma root_factor_theorem p x : root p x = (('X - x%:P) %| p). Proof. by rewrite dvdp_XsubCl. Qed. Lemma uniq_roots_dvdp p rs : all (root p) rs -> uniq_roots rs -> (\prod_(z <- rs) ('X - z%:P)) %| p. Proof. move=> rrs; case/(uniq_roots_prod_XsubC rrs)=> q ->. by apply: dvdp_mull; rewrite // (eqP (monic_prod_XsubC _)) unitr1. Qed. Lemma root_bigmul x (ps : seq {poly R}) : ~~root (\big[*%R/1]_(p <- ps) p) x = all (fun p => ~~ root p x) ps. Proof. elim: ps => [|p ps ihp]; first by rewrite big_nil root1. by rewrite big_cons /= rootM negb_or ihp. Qed. Lemma eqpP m n : reflect (exists2 c12, (c12.1 != 0) && (c12.2 != 0) & c12.1 *: m = c12.2 *: n) (m %= n). Proof. apply: (iffP idP) => [| [[c1 c2]/andP[nz_c1 nz_c2 eq_cmn]]]; last first. rewrite /eqp (@eq_dvdp c2 c1%:P) -?eq_cmn ?mul_polyC // (@eq_dvdp c1 c2%:P)//. by rewrite eq_cmn mul_polyC. case: (eqVneq m 0) => [-> /andP [/dvd0pP -> _] | m_nz]. by exists (1, 1); rewrite ?scaler0 // oner_eq0. case: (eqVneq n 0) => [-> /andP [_ /dvd0pP ->] | n_nz /andP []]. by exists (1, 1); rewrite ?scaler0 // oner_eq0. rewrite !dvdp_eq; set c1 := _ ^+ _; set c2 := _ ^+ _. set q1 := _ %/ _; set q2 := _ %/ _; move/eqP => Hq1 /eqP Hq2; have Hc1 : c1 != 0 by rewrite expf_eq0 lead_coef_eq0 negb_and m_nz orbT. have Hc2 : c2 != 0 by rewrite expf_eq0 lead_coef_eq0 negb_and n_nz orbT. have def_q12: q1 * q2 = (c1 * c2)%:P. apply: (mulIf m_nz); rewrite mulrAC mulrC -Hq1 -scalerAr -Hq2 scalerA. by rewrite -mul_polyC. have: q1 * q2 != 0 by rewrite def_q12 -size_poly_eq0 size_polyC mulf_neq0. rewrite mulf_eq0; case/norP=> nz_q1 nz_q2. have: size q2 <= 1. have:= size_mul nz_q1 nz_q2; rewrite def_q12 size_polyC mulf_neq0 //=. by rewrite polySpred // => ->; rewrite leq_addl. rewrite leq_eqVlt ltnS size_poly_leq0 (negPf nz_q2) orbF. case/size_poly1P=> c cn0 cqe; exists (c2, c); first by rewrite Hc2. by rewrite Hq2 -mul_polyC -cqe. Qed. Lemma eqp_eq p q: p %= q -> (lead_coef q) *: p = (lead_coef p) *: q. Proof. move=> /eqpP [[c1 c2] /= /andP [nz_c1 nz_c2]] eq. have/(congr1 lead_coef) := eq; rewrite !lead_coefZ. move=> eqC; apply/(@mulfI _ c2%:P); rewrite ?polyC_eq0 //. by rewrite !mul_polyC scalerA -eqC mulrC -scalerA eq !scalerA mulrC. Qed. Lemma eqpxx : reflexive (@eqp R). Proof. by move=> p; rewrite /eqp dvdpp. Qed. Hint Resolve eqpxx : core. Lemma eqpW p q : p = q -> p %= q. Proof. by move->; rewrite eqpxx. Qed. Lemma eqp_sym : symmetric (@eqp R). Proof. by move=> p q; rewrite /eqp andbC. Qed. Lemma eqp_trans : transitive (@eqp R). Proof. move=> p q r; case/andP=> Dp pD; case/andP=> Dq qD. by rewrite /eqp (dvdp_trans Dp) // (dvdp_trans qD). Qed. Lemma eqp_ltrans : left_transitive (@eqp R). Proof. exact: sym_left_transitive eqp_sym eqp_trans. Qed. Lemma eqp_rtrans : right_transitive (@eqp R). Proof. exact: sym_right_transitive eqp_sym eqp_trans. Qed. Lemma eqp0 p : (p %= 0) = (p == 0). Proof. by apply/idP/eqP => [/andP [_ /dvd0pP] | -> //]. Qed. Lemma eqp01 : 0 %= (1 : {poly R}) = false. Proof. by rewrite eqp_sym eqp0 oner_eq0. Qed. Lemma eqp_scale p c : c != 0 -> c *: p %= p. Proof. move=> c0; apply/eqpP; exists (1, c); first by rewrite c0 oner_eq0. by rewrite scale1r. Qed. Lemma eqp_size p q : p %= q -> size p = size q. Proof. have [->|Eq] := eqVneq q 0; first by rewrite eqp0; move/eqP->. rewrite eqp_sym; have [->|Ep] := eqVneq p 0; first by rewrite eqp0; move/eqP->. by case/andP => Dp Dq; apply: anti_leq; rewrite !dvdp_leq. Qed. Lemma size_poly_eq1 p : (size p == 1) = (p %= 1). Proof. apply/size_poly1P/idP=> [[c cn0 ep] |]. by apply/eqpP; exists (1, c); rewrite ?oner_eq0 // alg_polyC scale1r. by move/eqp_size; rewrite size_poly1; move/eqP/size_poly1P. Qed. Lemma polyXsubC_eqp1 (x : R) : ('X - x%:P %= 1) = false. Proof. by rewrite -size_poly_eq1 size_XsubC. Qed. Lemma dvdp_eqp1 p q : p %| q -> q %= 1 -> p %= 1. Proof. move=> dpq hq. have sizeq : size q == 1 by rewrite size_poly_eq1. have n0q : q != 0 by case: eqP hq => // ->; rewrite eqp01. rewrite -size_poly_eq1 eqn_leq -{1}(eqP sizeq) dvdp_leq //= size_poly_gt0. by apply/eqP => p0; move: dpq n0q; rewrite p0 dvd0p => ->. Qed. Lemma eqp_dvdr q p d: p %= q -> d %| p = (d %| q). Proof. suff Hmn m n: m %= n -> (d %| m) -> (d %| n). by move=> mn; apply/idP/idP; apply: Hmn=> //; rewrite eqp_sym. by rewrite /eqp; case/andP=> pq qp dp; apply: (dvdp_trans dp). Qed. Lemma eqp_dvdl d2 d1 p : d1 %= d2 -> d1 %| p = (d2 %| p). suff Hmn m n: m %= n -> (m %| p) -> (n %| p). by move=> ?; apply/idP/idP; apply: Hmn; rewrite // eqp_sym. by rewrite /eqp; case/andP=> dd' d'd dp; apply: (dvdp_trans d'd). Qed. Lemma dvdpZr c m n : c != 0 -> m %| c *: n = (m %| n). Proof. by move=> cn0; exact/eqp_dvdr/eqp_scale. Qed. Lemma dvdpZl c m n : c != 0 -> (c *: m %| n) = (m %| n). Proof. by move=> cn0; exact/eqp_dvdl/eqp_scale. Qed. Lemma dvdpNl d p : (- d) %| p = (d %| p). Proof. by rewrite -scaleN1r; apply/eqp_dvdl/eqp_scale; rewrite oppr_eq0 oner_neq0. Qed. Lemma dvdpNr d p : d %| (- p) = (d %| p). Proof. by apply: eqp_dvdr; rewrite -scaleN1r eqp_scale ?oppr_eq0 ?oner_eq0. Qed. Lemma eqp_mul2r r p q : r != 0 -> (p * r %= q * r) = (p %= q). Proof. by move=> nz_r; rewrite /eqp !dvdp_mul2r. Qed. Lemma eqp_mul2l r p q: r != 0 -> (r * p %= r * q) = (p %= q). Proof. by move=> nz_r; rewrite /eqp !dvdp_mul2l. Qed. Lemma eqp_mull r p q: q %= r -> p * q %= p * r. Proof. case/eqpP=> [[c d]] /andP [c0 d0 e]; apply/eqpP; exists (c, d); rewrite ?c0 //. by rewrite scalerAr e -scalerAr. Qed. Lemma eqp_mulr q p r : p %= q -> p * r %= q * r. Proof. by move=> epq; rewrite ![_ * r]mulrC eqp_mull. Qed. Lemma eqp_exp p q k : p %= q -> p ^+ k %= q ^+ k. Proof. move=> pq; elim: k=> [|k ihk]; first by rewrite !expr0 eqpxx. by rewrite !exprS (@eqp_trans (q * p ^+ k)) // (eqp_mulr, eqp_mull). Qed. Lemma polyC_eqp1 (c : R) : (c%:P %= 1) = (c != 0). Proof. apply/eqpP/idP => [[[x y]] |nc0] /=. case: (eqVneq c) => [->|] //= /andP [_] /negPf <- /eqP. by rewrite alg_polyC scaler0 eq_sym polyC_eq0. exists (1, c); first by rewrite nc0 /= oner_neq0. by rewrite alg_polyC scale1r. Qed. Lemma dvdUp d p: d %= 1 -> d %| p. Proof. by move/eqp_dvdl->; rewrite dvd1p. Qed. Lemma dvdp_size_eqp p q : p %| q -> size p == size q = (p %= q). Proof. move=> pq; apply/idP/idP; last by move/eqp_size->. have [->|Hq] := eqVneq q 0; first by rewrite size_poly0 size_poly_eq0 eqp0. have [->|Hp] := eqVneq p 0. by rewrite size_poly0 eq_sym size_poly_eq0 eqp_sym eqp0. move: pq; rewrite dvdp_eq; set c := _ ^+ _; set x := _ %/ _; move/eqP=> eqpq. have /= := congr1 (size \o @polyseq R) eqpq. have cn0 : c != 0 by rewrite expf_neq0 // lead_coef_eq0. rewrite (@eqp_size _ q); last exact: eqp_scale. rewrite size_mul ?p0 // => [-> HH|]; last first. apply/eqP=> HH; move: eqpq; rewrite HH mul0r. by move/eqP; rewrite scale_poly_eq0 (negPf Hq) (negPf cn0). suff: size x == 1%N. case/size_poly1P=> y H1y H2y. by apply/eqpP; exists (y, c); rewrite ?H1y // eqpq H2y mul_polyC. case: (size p) HH (size_poly_eq0 p)=> [|n]; first by case: eqP Hp. by rewrite addnS -add1n eqn_add2r; move/eqP->. Qed. Lemma eqp_root p q : p %= q -> root p =1 root q. Proof. move/eqpP=> [[c d]] /andP [c0 d0 e] x; move/negPf:c0=>c0; move/negPf:d0=>d0. by rewrite rootE -[_==_]orFb -c0 -mulf_eq0 -hornerZ e hornerZ mulf_eq0 d0. Qed. Lemma eqp_rmod_mod p q : rmodp p q %= modp p q. Proof. rewrite modpE eqp_sym; case: ifP => ulcq //. apply: eqp_scale; rewrite invr_eq0 //. by apply: expf_neq0; apply: contraTneq ulcq => ->; rewrite unitr0. Qed. Lemma eqp_rdiv_div p q : rdivp p q %= divp p q. Proof. rewrite divpE eqp_sym; case: ifP=> ulcq//; apply: eqp_scale; rewrite invr_eq0//. by apply: expf_neq0; apply: contraTneq ulcq => ->; rewrite unitr0. Qed. Lemma dvd_eqp_divl d p q (dvd_dp : d %| q) (eq_pq : p %= q) : p %/ d %= q %/ d. Proof. case: (eqVneq q 0) eq_pq=> [->|q_neq0]; first by rewrite eqp0=> /eqP->. have d_neq0: d != 0 by apply: contraTneq dvd_dp=> ->; rewrite dvd0p. move=> eq_pq; rewrite -(@eqp_mul2r d) // !divpK // ?(eqp_dvdr _ eq_pq) //. rewrite (eqp_ltrans (eqp_scale _ _)) ?lc_expn_scalp_neq0 //. by rewrite (eqp_rtrans (eqp_scale _ _)) ?lc_expn_scalp_neq0. Qed. Definition gcdp p q := let: (p1, q1) := if size p < size q then (q, p) else (p, q) in if p1 == 0 then q1 else let fix loop (n : nat) (pp qq : {poly R}) {struct n} := let rr := modp pp qq in if rr == 0 then qq else if n is n1.+1 then loop n1 qq rr else rr in loop (size p1) p1 q1. Arguments gcdp : simpl never. Lemma gcd0p : left_id 0 gcdp. Proof. move=> p; rewrite /gcdp size_poly0 size_poly_gt0 if_neg. case: ifP => /= [_ | nzp]; first by rewrite eqxx. by rewrite polySpred !(modp0, nzp) //; case: _.-1 => [|m]; rewrite mod0p eqxx. Qed. Lemma gcdp0 : right_id 0 gcdp. Proof. move=> p; have:= gcd0p p; rewrite /gcdp size_poly0 size_poly_gt0. by case: eqVneq => //= ->; rewrite eqxx. Qed. Lemma gcdpE p q : gcdp p q = if size p < size q then gcdp (modp q p) p else gcdp (modp p q) q. Proof. pose gcdpE_rec := fix gcdpE_rec (n : nat) (pp qq : {poly R}) {struct n} := let rr := modp pp qq in if rr == 0 then qq else if n is n1.+1 then gcdpE_rec n1 qq rr else rr. have Irec: forall k l p q, size q <= k -> size q <= l -> size q < size p -> gcdpE_rec k p q = gcdpE_rec l p q. + elim=> [|m Hrec] [|n] //= p1 q1. - move/size_poly_leq0P=> -> _; rewrite size_poly0 size_poly_gt0 modp0. by move/negPf ->; case: n => [|n] /=; rewrite mod0p eqxx. - move=> _ /size_poly_leq0P ->; rewrite size_poly0 size_poly_gt0 modp0. by move/negPf ->; case: m {Hrec} => [|m] /=; rewrite mod0p eqxx. case: eqP => Epq Sm Sn Sq //; have [->|nzq] := eqVneq q1 0. by case: n m {Sm Sn Hrec} => [|m] [|n] //=; rewrite mod0p eqxx. apply: Hrec; last by rewrite ltn_modp. by rewrite -ltnS (leq_trans _ Sm) // ltn_modp. by rewrite -ltnS (leq_trans _ Sn) // ltn_modp. have [->|nzp] := eqVneq p 0; first by rewrite mod0p modp0 gcd0p gcdp0 if_same. have [->|nzq] := eqVneq q 0; first by rewrite mod0p modp0 gcd0p gcdp0 if_same. rewrite /gcdp !ltn_modp !(negPf nzp, negPf nzq) /=. have [ltpq|leqp] := ltnP; rewrite !(negPf nzp, negPf nzq) /= polySpred //. have [->|nzqp] := eqVneq. by case: (size p) => [|[|s]]; rewrite /= modp0 (negPf nzp) // mod0p eqxx. apply: Irec => //; last by rewrite ltn_modp. by rewrite -ltnS -polySpred // (leq_trans _ ltpq) ?leqW // ltn_modp. by rewrite ltnW // ltn_modp. case: eqVneq => [->|nzpq]. by case: (size q) => [|[|s]]; rewrite /= modp0 (negPf nzq) // mod0p eqxx. apply: Irec => //; rewrite ?ltn_modp //. by rewrite -ltnS -polySpred // (leq_trans _ leqp) // ltn_modp. by rewrite ltnW // ltn_modp. Qed. Lemma size_gcd1p p : size (gcdp 1 p) = 1. Proof. rewrite gcdpE size_polyC oner_eq0 /= modp1; have [|/size1_polyC ->] := ltnP. by rewrite gcd0p size_polyC oner_eq0. have [->|p00] := eqVneq p`_0 0; first by rewrite modp0 gcdp0 size_poly1. by rewrite modpC // gcd0p size_polyC p00. Qed. Lemma size_gcdp1 p : size (gcdp p 1) = 1. Proof. rewrite gcdpE size_polyC oner_eq0 /= modp1 ltnS; case: leqP. by move/size_poly_leq0P->; rewrite gcdp0 modp0 size_polyC oner_eq0. by rewrite gcd0p size_polyC oner_eq0. Qed. Lemma gcdpp : idempotent_op gcdp. Proof. by move=> p; rewrite gcdpE ltnn modpp gcd0p. Qed. Lemma dvdp_gcdlr p q : (gcdp p q %| p) && (gcdp p q %| q). Proof. have [r] := ubnP (minn (size q) (size p)); elim: r => // r IHr in p q *. have [-> | nz_p] := eqVneq p 0; first by rewrite gcd0p dvdpp andbT. have [-> | nz_q] := eqVneq q 0; first by rewrite gcdp0 dvdpp /=. rewrite ltnS gcdpE; case: leqP => [le_pq | lt_pq] le_qr. suffices /IHr/andP[E1 E2]: minn (size q) (size (p %% q)) < r. by rewrite E2 andbT (dvdp_mod _ E2). by rewrite gtn_min orbC (leq_trans _ le_qr) ?ltn_modp. suffices /IHr/andP[E1 E2]: minn (size p) (size (q %% p)) < r. by rewrite E2 (dvdp_mod _ E2). by rewrite gtn_min orbC (leq_trans _ le_qr) ?ltn_modp. Qed. Lemma dvdp_gcdl p q : gcdp p q %| p. Proof. by case/andP: (dvdp_gcdlr p q). Qed. Lemma dvdp_gcdr p q :gcdp p q %| q. Proof. by case/andP: (dvdp_gcdlr p q). Qed. Lemma leq_gcdpl p q : p != 0 -> size (gcdp p q) <= size p. Proof. by move=> pn0; move: (dvdp_gcdl p q); apply: dvdp_leq. Qed. Lemma leq_gcdpr p q : q != 0 -> size (gcdp p q) <= size q. Proof. by move=> qn0; move: (dvdp_gcdr p q); apply: dvdp_leq. Qed. Lemma dvdp_gcd p m n : p %| gcdp m n = (p %| m) && (p %| n). Proof. apply/idP/andP=> [dv_pmn | []]. by rewrite ?(dvdp_trans dv_pmn) ?dvdp_gcdl ?dvdp_gcdr. have [r] := ubnP (minn (size n) (size m)); elim: r => // r IHr in m n *. have [-> | nz_m] := eqVneq m 0; first by rewrite gcd0p. have [-> | nz_n] := eqVneq n 0; first by rewrite gcdp0. rewrite gcdpE ltnS; case: leqP => [le_nm | lt_mn] le_r dv_m dv_n. apply: IHr => //; last by rewrite -(dvdp_mod _ dv_n). by rewrite gtn_min orbC (leq_trans _ le_r) ?ltn_modp. apply: IHr => //; last by rewrite -(dvdp_mod _ dv_m). by rewrite gtn_min orbC (leq_trans _ le_r) ?ltn_modp. Qed. Lemma gcdpC p q : gcdp p q %= gcdp q p. Proof. by rewrite /eqp !dvdp_gcd !dvdp_gcdl !dvdp_gcdr. Qed. Lemma gcd1p p : gcdp 1 p %= 1. Proof. rewrite -size_poly_eq1 gcdpE size_poly1; case: ltnP. by rewrite modp1 gcd0p size_poly1 eqxx. move/size1_polyC=> e; rewrite e. have [->|p00] := eqVneq p`_0 0; first by rewrite modp0 gcdp0 size_poly1. by rewrite modpC // gcd0p size_polyC p00. Qed. Lemma gcdp1 p : gcdp p 1 %= 1. Proof. by rewrite (eqp_ltrans (gcdpC _ _)) gcd1p. Qed. Lemma gcdp_addl_mul p q r: gcdp r (p * r + q) %= gcdp r q. Proof. suff h m n d : gcdp d n %| gcdp d (m * d + n). apply/andP; split => //. by rewrite {2}(_: q = (-p) * r + (p * r + q)) ?H // mulNr addKr. by rewrite dvdp_gcd dvdp_gcdl /= dvdp_addr ?dvdp_gcdr ?dvdp_mull ?dvdp_gcdl. Qed. Lemma gcdp_addl m n : gcdp m (m + n) %= gcdp m n. Proof. by rewrite -[m in m + _]mul1r gcdp_addl_mul. Qed. Lemma gcdp_addr m n : gcdp m (n + m) %= gcdp m n. Proof. by rewrite addrC gcdp_addl. Qed. Lemma gcdp_mull m n : gcdp n (m * n) %= n. Proof. have [-> | nn0] := eqVneq n 0; first by rewrite gcd0p mulr0 eqpxx. have [-> | mn0] := eqVneq m 0; first by rewrite mul0r gcdp0 eqpxx. rewrite gcdpE modp_mull gcd0p size_mul //; case: leqP; last by rewrite eqpxx. rewrite (polySpred mn0) addSn /= -[leqRHS]add0n leq_add2r -ltnS. rewrite -polySpred //= leq_eqVlt ltnS size_poly_leq0 (negPf mn0) orbF. case/size_poly1P=> c cn0 -> {mn0 m}; rewrite mul_polyC. suff -> : n %% (c *: n) = 0 by rewrite gcd0p; apply: eqp_scale. by apply/modp_eq0P; rewrite dvdpZl. Qed. Lemma gcdp_mulr m n : gcdp n (n * m) %= n. Proof. by rewrite mulrC gcdp_mull. Qed. Lemma gcdp_scalel c m n : c != 0 -> gcdp (c *: m) n %= gcdp m n. Proof. move=> cn0; rewrite /eqp dvdp_gcd [gcdp m n %| _]dvdp_gcd !dvdp_gcdr !andbT. apply/andP; split; last first. by apply: dvdp_trans (dvdp_gcdl _ _) _; rewrite dvdpZr. by apply: dvdp_trans (dvdp_gcdl _ _) _; rewrite dvdpZl. Qed. Lemma gcdp_scaler c m n : c != 0 -> gcdp m (c *: n) %= gcdp m n. Proof. move=> cn0; apply: eqp_trans (gcdpC _ _) _. by apply: eqp_trans (gcdp_scalel _ _ _) _ => //; apply: gcdpC. Qed. Lemma dvdp_gcd_idl m n : m %| n -> gcdp m n %= m. Proof. have [-> | mn0] := eqVneq m 0. by rewrite dvd0p => /eqP ->; rewrite gcdp0 eqpxx. rewrite dvdp_eq; move/eqP/(f_equal (gcdp m)) => h. apply: eqp_trans (gcdp_mull (n %/ m) _). by rewrite -h eqp_sym gcdp_scaler // expf_neq0 // lead_coef_eq0. Qed. Lemma dvdp_gcd_idr m n : n %| m -> gcdp m n %= n. Proof. by move/dvdp_gcd_idl; exact/eqp_trans/gcdpC. Qed. Lemma gcdp_exp p k l : gcdp (p ^+ k) (p ^+ l) %= p ^+ minn k l. Proof. case: leqP => [|/ltnW] /subnK <-; rewrite exprD; first exact: gcdp_mull. exact/(eqp_trans (gcdpC _ _))/gcdp_mull. Qed. Lemma gcdp_eq0 p q : gcdp p q == 0 = (p == 0) && (q == 0). Proof. apply/idP/idP; last by case/andP => /eqP -> /eqP ->; rewrite gcdp0. have h m n: gcdp m n == 0 -> (m == 0). by rewrite -(dvd0p m); move/eqP<-; rewrite dvdp_gcdl. by move=> ?; rewrite (h _ q) // (h _ p) // -eqp0 (eqp_ltrans (gcdpC _ _)) eqp0. Qed. Lemma eqp_gcdr p q r : q %= r -> gcdp p q %= gcdp p r. Proof. move=> eqr; rewrite /eqp !(dvdp_gcd, dvdp_gcdl, andbT) /=. by rewrite -(eqp_dvdr _ eqr) dvdp_gcdr (eqp_dvdr _ eqr) dvdp_gcdr. Qed. Lemma eqp_gcdl r p q : p %= q -> gcdp p r %= gcdp q r. Proof. move=> eqr; rewrite /eqp !(dvdp_gcd, dvdp_gcdr, andbT) /=. by rewrite -(eqp_dvdr _ eqr) dvdp_gcdl (eqp_dvdr _ eqr) dvdp_gcdl. Qed. Lemma eqp_gcd p1 p2 q1 q2 : p1 %= p2 -> q1 %= q2 -> gcdp p1 q1 %= gcdp p2 q2. Proof. move=> e1 e2; exact: eqp_trans (eqp_gcdr _ e2) (eqp_gcdl _ e1). Qed. Lemma eqp_rgcd_gcd p q : rgcdp p q %= gcdp p q. Proof. move: {2}(minn (size p) (size q)) (leqnn (minn (size p) (size q))) => n. elim: n p q => [p q|n ihn p q hs]. rewrite leqn0; case: ltnP => _; rewrite size_poly_eq0; move/eqP->. by rewrite gcd0p rgcd0p eqpxx. by rewrite gcdp0 rgcdp0 eqpxx. have [-> | pn0] := eqVneq p 0; first by rewrite gcd0p rgcd0p eqpxx. have [-> | qn0] := eqVneq q 0; first by rewrite gcdp0 rgcdp0 eqpxx. rewrite gcdpE rgcdpE; case: ltnP hs => sp hs. have e := eqp_rmod_mod q p; apply/eqp_trans/ihn: (eqp_gcdl p e). by rewrite (eqp_size e) geq_min -ltnS (leq_trans _ hs) ?ltn_modp. have e := eqp_rmod_mod p q; apply/eqp_trans/ihn: (eqp_gcdl q e). by rewrite (eqp_size e) geq_min -ltnS (leq_trans _ hs) ?ltn_modp. Qed. Lemma gcdp_modl m n : gcdp (m %% n) n %= gcdp m n. Proof. have [/modp_small -> // | lenm] := ltnP (size m) (size n). by rewrite (gcdpE m n) ltnNge lenm. Qed. Lemma gcdp_modr m n : gcdp m (n %% m) %= gcdp m n. Proof. apply: eqp_trans (gcdpC _ _); apply: eqp_trans (gcdp_modl _ _); exact: gcdpC. Qed. Lemma gcdp_def d m n : d %| m -> d %| n -> (forall d', d' %| m -> d' %| n -> d' %| d) -> gcdp m n %= d. Proof. move=> dm dn h; rewrite /eqp dvdp_gcd dm dn !andbT. by apply: h; rewrite (dvdp_gcdl, dvdp_gcdr). Qed. Definition coprimep p q := size (gcdp p q) == 1%N. Lemma coprimep_size_gcd p q : coprimep p q -> size (gcdp p q) = 1. Proof. by rewrite /coprimep=> /eqP. Qed. Lemma coprimep_def p q : coprimep p q = (size (gcdp p q) == 1). Proof. done. Qed. Lemma coprimepZl c m n : c != 0 -> coprimep (c *: m) n = coprimep m n. Proof. by move=> ?; rewrite !coprimep_def (eqp_size (gcdp_scalel _ _ _)). Qed. Lemma coprimepZr c m n: c != 0 -> coprimep m (c *: n) = coprimep m n. Proof. by move=> ?; rewrite !coprimep_def (eqp_size (gcdp_scaler _ _ _)). Qed. Lemma coprimepp p : coprimep p p = (size p == 1). Proof. by rewrite coprimep_def gcdpp. Qed. Lemma gcdp_eqp1 p q : gcdp p q %= 1 = coprimep p q. Proof. by rewrite coprimep_def size_poly_eq1. Qed. Lemma coprimep_sym p q : coprimep p q = coprimep q p. Proof. by rewrite -!gcdp_eqp1; apply: eqp_ltrans; rewrite gcdpC. Qed. Lemma coprime1p p : coprimep 1 p. Proof. by rewrite /coprimep -[1%N](size_poly1 R); exact/eqP/eqp_size/gcd1p. Qed. Lemma coprimep1 p : coprimep p 1. Proof. by rewrite coprimep_sym; apply: coprime1p. Qed. Lemma coprimep0 p : coprimep p 0 = (p %= 1). Proof. by rewrite /coprimep gcdp0 size_poly_eq1. Qed. Lemma coprime0p p : coprimep 0 p = (p %= 1). Proof. by rewrite coprimep_sym coprimep0. Qed. (* This is different from coprimeP in div. shall we keep this? *) Lemma coprimepP p q : reflect (forall d, d %| p -> d %| q -> d %= 1) (coprimep p q). Proof. rewrite /coprimep; apply: (iffP idP) => [/eqP hs d dvddp dvddq | h]. have/dvdp_eqp1: d %| gcdp p q by rewrite dvdp_gcd dvddp dvddq. by rewrite -size_poly_eq1 hs; exact. by rewrite size_poly_eq1; case/andP: (dvdp_gcdlr p q); apply: h. Qed. Lemma coprimepPn p q : p != 0 -> reflect (exists d, (d %| gcdp p q) && ~~ (d %= 1)) (~~ coprimep p q). Proof. move=> p0; apply: (iffP idP). by rewrite -gcdp_eqp1=> ng1; exists (gcdp p q); rewrite dvdpp /=. case=> d /andP [dg]; apply: contra; rewrite -gcdp_eqp1=> g1. by move: dg; rewrite (eqp_dvdr _ g1) dvdp1 size_poly_eq1. Qed. Lemma coprimep_dvdl q p r : r %| q -> coprimep p q -> coprimep p r. Proof. move=> rp /coprimepP cpq'; apply/coprimepP => d dp dr. exact/cpq'/(dvdp_trans dr). Qed. Lemma coprimep_dvdr p q r : r %| p -> coprimep p q -> coprimep r q. Proof. by move=> rp; rewrite ![coprimep _ q]coprimep_sym; apply/coprimep_dvdl. Qed. Lemma coprimep_modl p q : coprimep (p %% q) q = coprimep p q. Proof. rewrite !coprimep_def [in RHS]gcdpE. by case: ltnP => // hpq; rewrite modp_small // gcdpE hpq. Qed. Lemma coprimep_modr q p : coprimep q (p %% q) = coprimep q p. Proof. by rewrite ![coprimep q _]coprimep_sym coprimep_modl. Qed. Lemma rcoprimep_coprimep q p : rcoprimep q p = coprimep q p. Proof. by rewrite /coprimep /rcoprimep (eqp_size (eqp_rgcd_gcd _ _)). Qed. Lemma eqp_coprimepr p q r : q %= r -> coprimep p q = coprimep p r. Proof. by rewrite -!gcdp_eqp1; move/(eqp_gcdr p)/eqp_ltrans. Qed. Lemma eqp_coprimepl p q r : q %= r -> coprimep q p = coprimep r p. Proof. by rewrite !(coprimep_sym _ p); apply: eqp_coprimepr. Qed. (* This should be implemented with an extended remainder sequence *) Fixpoint egcdp_rec p q k {struct k} : {poly R} * {poly R} := if k is k'.+1 then if q == 0 then (1, 0) else let: (u, v) := egcdp_rec q (p %% q) k' in (lead_coef q ^+ scalp p q *: v, (u - v * (p %/ q))) else (1, 0). Definition egcdp p q := if size q <= size p then egcdp_rec p q (size q) else let e := egcdp_rec q p (size p) in (e.2, e.1). (* No provable egcd0p *) Lemma egcdp0 p : egcdp p 0 = (1, 0). Proof. by rewrite /egcdp size_poly0. Qed. Lemma egcdp_recP : forall k p q, q != 0 -> size q <= k -> size q <= size p -> let e := (egcdp_rec p q k) in [/\ size e.1 <= size q, size e.2 <= size p & gcdp p q %= e.1 * p + e.2 * q]. Proof. elim=> [|k ihk] p q /= qn0; first by rewrite size_poly_leq0 (negPf qn0). move=> sqSn qsp; rewrite (negPf qn0). have sp : size p > 0 by apply: leq_trans qsp; rewrite size_poly_gt0. have [r0 | rn0] /= := eqVneq (p %%q) 0. rewrite r0 /egcdp_rec; case: k ihk sqSn => [|n] ihn sqSn /=. rewrite !scaler0 !mul0r subr0 add0r mul1r size_poly0 size_poly1. by rewrite dvdp_gcd_idr /dvdp ?r0. rewrite !eqxx mul0r scaler0 /= mul0r add0r subr0 mul1r size_poly0 size_poly1. by rewrite dvdp_gcd_idr /dvdp ?r0 //. have h1 : size (p %% q) <= k. by rewrite -ltnS; apply: leq_trans sqSn; rewrite ltn_modp. have h2 : size (p %% q) <= size q by rewrite ltnW // ltn_modp. have := ihk q (p %% q) rn0 h1 h2. case: (egcdp_rec _ _)=> u v /= => [[ihn'1 ihn'2 ihn'3]]. rewrite gcdpE ltnNge qsp //= (eqp_ltrans (gcdpC _ _)); split; last first. - apply: (eqp_trans ihn'3). rewrite mulrBl addrCA -scalerAl scalerAr -mulrA -mulrBr. by rewrite divp_eq addrAC subrr add0r eqpxx. - apply: (leq_trans (size_polyD _ _)). have [-> | vn0] := eqVneq v 0. rewrite mul0r size_polyN size_poly0 maxn0; apply: leq_trans ihn'1 _. exact: leq_modp. have [-> | qqn0] := eqVneq (p %/ q) 0. rewrite mulr0 size_polyN size_poly0 maxn0; apply: leq_trans ihn'1 _. exact: leq_modp. rewrite geq_max (leq_trans ihn'1) ?leq_modp //= size_polyN size_mul //. move: (ihn'2); rewrite (polySpred vn0) (polySpred qn0). rewrite -(ltn_add2r (size (p %/ q))) !addSn /= ltnS; move/leq_trans; apply. rewrite size_divp // addnBA ?addKn //. by apply: leq_trans qsp; apply: leq_pred. - by rewrite size_scale // lc_expn_scalp_neq0. Qed. Lemma egcdpP p q : p != 0 -> q != 0 -> forall (e := egcdp p q), [/\ size e.1 <= size q, size e.2 <= size p & gcdp p q %= e.1 * p + e.2 * q]. Proof. rewrite /egcdp => pn0 qn0; case: (leqP (size q) (size p)) => /= [|/ltnW] hp. exact: egcdp_recP. case: (egcdp_recP pn0 (leqnn (size p)) hp) => h1 h2 h3; split => //. by rewrite (eqp_ltrans (gcdpC _ _)) addrC. Qed. Lemma egcdpE p q (e := egcdp p q) : gcdp p q %= e.1 * p + e.2 * q. Proof. rewrite {}/e; have [-> /= | qn0] := eqVneq q 0. by rewrite gcdp0 egcdp0 mul1r mulr0 addr0. have [-> | pn0] := eqVneq p 0; last by case: (egcdpP pn0 qn0). by rewrite gcd0p /egcdp size_poly0 size_poly_leq0 (negPf qn0) /= !simp. Qed. Lemma Bezoutp p q : exists u, u.1 * p + u.2 * q %= (gcdp p q). Proof. have [-> | pn0] := eqVneq p 0. by rewrite gcd0p; exists (0, 1); rewrite mul0r mul1r add0r. have [-> | qn0] := eqVneq q 0. by rewrite gcdp0; exists (1, 0); rewrite mul0r mul1r addr0. pose e := egcdp p q; exists e; rewrite eqp_sym. by case: (egcdpP pn0 qn0). Qed. Lemma Bezout_coprimepP p q : reflect (exists u, u.1 * p + u.2 * q %= 1) (coprimep p q). Proof. rewrite -gcdp_eqp1; apply: (iffP idP)=> [g1|]. by case: (Bezoutp p q) => [[u v] Puv]; exists (u, v); apply: eqp_trans g1. case=> [[u v]]; rewrite eqp_sym=> Puv; rewrite /eqp (eqp_dvdr _ Puv). by rewrite dvdp_addr dvdp_mull ?dvdp_gcdl ?dvdp_gcdr //= dvd1p. Qed. Lemma coprimep_root p q x : coprimep p q -> root p x -> q.[x] != 0. Proof. case/Bezout_coprimepP=> [[u v] euv] px0. move/eqpP: euv => [[c1 c2]] /andP /= [c1n0 c2n0 e]. suffices: c1 * (v.[x] * q.[x]) != 0. by rewrite !mulf_eq0 !negb_or c1n0 /=; case/andP. have := f_equal (horner^~ x) e; rewrite /= !hornerZ hornerD. by rewrite !hornerM (eqP px0) mulr0 add0r hornerC mulr1; move->. Qed. Lemma Gauss_dvdpl p q d: coprimep d q -> (d %| p * q) = (d %| p). Proof. move/Bezout_coprimepP=>[[u v] Puv]; apply/idP/idP; last exact: dvdp_mulr. move/(eqp_mull p): Puv; rewrite mulr1 mulrDr eqp_sym=> peq dpq. rewrite (eqp_dvdr _ peq) dvdp_addr; first by rewrite mulrA mulrAC dvdp_mulr. by rewrite mulrA dvdp_mull ?dvdpp. Qed. Lemma Gauss_dvdpr p q d: coprimep d q -> (d %| q * p) = (d %| p). Proof. by rewrite mulrC; apply: Gauss_dvdpl. Qed. (* This could be simplified with the introduction of lcmp *) Lemma Gauss_dvdp m n p : coprimep m n -> (m * n %| p) = (m %| p) && (n %| p). Proof. have [-> | mn0] := eqVneq m 0. by rewrite coprime0p => /eqp_dvdl->; rewrite !mul0r dvd0p dvd1p andbT. have [-> | nn0] := eqVneq n 0. by rewrite coprimep0 => /eqp_dvdl->; rewrite !mulr0 dvd1p. move=> hc; apply/idP/idP => [mnmp | /andP [dmp dnp]]. move/Gauss_dvdpl: hc => <-; move: (dvdp_mull m mnmp); rewrite dvdp_mul2l //. move->; move: (dvdp_mulr n mnmp); rewrite dvdp_mul2r // andbT. exact: dvdp_mulr. move: (dnp); rewrite dvdp_eq. set c2 := _ ^+ _; set q2 := _ %/ _; move/eqP=> e2. have/esym := Gauss_dvdpl q2 hc; rewrite -e2. have -> : m %| c2 *: p by rewrite -mul_polyC dvdp_mull. rewrite dvdp_eq; set c3 := _ ^+ _; set q3 := _ %/ _; move/eqP=> e3. apply: (@eq_dvdp (c3 * c2) q3). by rewrite mulf_neq0 // expf_neq0 // lead_coef_eq0. by rewrite mulrA -e3 -scalerAl -e2 scalerA. Qed. Lemma Gauss_gcdpr p m n : coprimep p m -> gcdp p (m * n) %= gcdp p n. Proof. move=> co_pm; apply/eqP; rewrite /eqp !dvdp_gcd !dvdp_gcdl /= andbC. rewrite dvdp_mull ?dvdp_gcdr // -(@Gauss_dvdpl _ m). by rewrite mulrC dvdp_gcdr. apply/coprimepP=> d; rewrite dvdp_gcd; case/andP=> hdp _ hdm. by move/coprimepP: co_pm; apply. Qed. Lemma Gauss_gcdpl p m n : coprimep p n -> gcdp p (m * n) %= gcdp p m. Proof. by move=> co_pn; rewrite mulrC Gauss_gcdpr. Qed. Lemma coprimepMr p q r : coprimep p (q * r) = (coprimep p q && coprimep p r). Proof. apply/coprimepP/andP=> [hp | [/coprimepP-hq hr]]. by split; apply/coprimepP=> d dp dq; rewrite hp //; [apply/dvdp_mulr | apply/dvdp_mull]. move=> d dp dqr; move/(_ _ dp) in hq. rewrite Gauss_dvdpl in dqr; first exact: hq. by move/coprimep_dvdr: hr; apply. Qed. Lemma coprimepMl p q r: coprimep (q * r) p = (coprimep q p && coprimep r p). Proof. by rewrite ![coprimep _ p]coprimep_sym coprimepMr. Qed. Lemma modp_coprime k u n : k != 0 -> (k * u) %% n %= 1 -> coprimep k n. Proof. move=> kn0 hmod; apply/Bezout_coprimepP. exists (((lead_coef n)^+(scalp (k * u) n) *: u), (- (k * u %/ n))). rewrite -scalerAl mulrC (divp_eq (u * k) n) mulNr -addrAC subrr add0r. by rewrite mulrC. Qed. Lemma coprimep_pexpl k m n : 0 < k -> coprimep (m ^+ k) n = coprimep m n. Proof. case: k => // k _; elim: k => [|k IHk]; first by rewrite expr1. by rewrite exprS coprimepMl -IHk andbb. Qed. Lemma coprimep_pexpr k m n : 0 < k -> coprimep m (n ^+ k) = coprimep m n. Proof. by move=> k_gt0; rewrite !(coprimep_sym m) coprimep_pexpl. Qed. Lemma coprimep_expl k m n : coprimep m n -> coprimep (m ^+ k) n. Proof. by case: k => [|k] co_pm; rewrite ?coprime1p // coprimep_pexpl. Qed. Lemma coprimep_expr k m n : coprimep m n -> coprimep m (n ^+ k). Proof. by rewrite !(coprimep_sym m); apply: coprimep_expl. Qed. Lemma gcdp_mul2l p q r : gcdp (p * q) (p * r) %= (p * gcdp q r). Proof. have [->|hp] := eqVneq p 0; first by rewrite !mul0r gcdp0 eqpxx. rewrite /eqp !dvdp_gcd !dvdp_mul2l // dvdp_gcdr dvdp_gcdl !andbT. move: (Bezoutp q r) => [[u v]] huv. rewrite eqp_sym in huv; rewrite (eqp_dvdr _ (eqp_mull _ huv)). rewrite mulrDr ![p * (_ * _)]mulrCA. by apply: dvdp_add; rewrite dvdp_mull// (dvdp_gcdr, dvdp_gcdl). Qed. Lemma gcdp_mul2r q r p : gcdp (q * p) (r * p) %= gcdp q r * p. Proof. by rewrite ![_ * p]mulrC gcdp_mul2l. Qed. Lemma mulp_gcdr p q r : r * (gcdp p q) %= gcdp (r * p) (r * q). Proof. by rewrite eqp_sym gcdp_mul2l. Qed. Lemma mulp_gcdl p q r : (gcdp p q) * r %= gcdp (p * r) (q * r). Proof. by rewrite eqp_sym gcdp_mul2r. Qed. Lemma coprimep_div_gcd p q : (p != 0) || (q != 0) -> coprimep (p %/ (gcdp p q)) (q %/ gcdp p q). Proof. rewrite -negb_and -gcdp_eq0 -gcdp_eqp1 => gpq0. rewrite -(@eqp_mul2r (gcdp p q)) // mul1r (eqp_ltrans (mulp_gcdl _ _ _)). have: gcdp p q %| p by rewrite dvdp_gcdl. have: gcdp p q %| q by rewrite dvdp_gcdr. rewrite !dvdp_eq => /eqP <- /eqP <-. have lcn0 k : (lead_coef (gcdp p q)) ^+ k != 0. by rewrite expf_neq0 ?lead_coef_eq0. by apply: eqp_gcd; rewrite ?eqp_scale. Qed. Lemma divp_eq0 p q : (p %/ q == 0) = [|| p == 0, q ==0 | size p < size q]. Proof. apply/eqP/idP=> [d0|]; last first. case/or3P; [by move/eqP->; rewrite div0p| by move/eqP->; rewrite divp0|]. by move/divp_small. case: eqVneq => // _; case: eqVneq => // qn0. move: (divp_eq p q); rewrite d0 mul0r add0r. move/(f_equal (fun x : {poly R} => size x)). by rewrite size_scale ?lc_expn_scalp_neq0 // => ->; rewrite ltn_modp qn0 !orbT. Qed. Lemma dvdp_div_eq0 p q : q %| p -> (p %/ q == 0) = (p == 0). Proof. move=> dvdp_qp; have [->|p_neq0] := eqVneq p 0; first by rewrite div0p eqxx. rewrite divp_eq0 ltnNge dvdp_leq // (negPf p_neq0) orbF /=. by apply: contraTF dvdp_qp=> /eqP ->; rewrite dvd0p. Qed. Lemma Bezout_coprimepPn p q : p != 0 -> q != 0 -> reflect (exists2 uv : {poly R} * {poly R}, (0 < size uv.1 < size q) && (0 < size uv.2 < size p) & uv.1 * p = uv.2 * q) (~~ (coprimep p q)). Proof. move=> pn0 qn0; apply: (iffP idP); last first. case=> [[u v] /= /andP [/andP [ps1 s1] /andP [ps2 s2]] e]. have: ~~(size (q * p) <= size (u * p)). rewrite -ltnNge !size_mul // -?size_poly_gt0 // (polySpred pn0) !addnS. by rewrite ltn_add2r. apply: contra => ?; apply: dvdp_leq; rewrite ?mulf_neq0 // -?size_poly_gt0 //. by rewrite mulrC Gauss_dvdp // dvdp_mull // e dvdp_mull. rewrite coprimep_def neq_ltn ltnS size_poly_leq0 gcdp_eq0. rewrite (negPf pn0) (negPf qn0) /=. case sg: (size (gcdp p q)) => [|n] //; case: n sg=> [|n] // sg _. move: (dvdp_gcdl p q); rewrite dvdp_eq; set c1 := _ ^+ _; move/eqP=> hu1. move: (dvdp_gcdr p q); rewrite dvdp_eq; set c2 := _ ^+ _; move/eqP=> hv1. exists (c1 *: (q %/ gcdp p q), c2 *: (p %/ gcdp p q)); last first. by rewrite -!scalerAl !scalerAr hu1 hv1 mulrCA. rewrite !size_scale ?lc_expn_scalp_neq0 //= !size_poly_gt0 !divp_eq0. rewrite gcdp_eq0 !(negPf pn0) !(negPf qn0) /= -!leqNgt leq_gcdpl //. rewrite leq_gcdpr //= !ltn_divpl -?size_poly_eq0 ?sg //. rewrite !size_mul // -?size_poly_eq0 ?sg // ![(_ + n.+2)%N]addnS /=. by rewrite -!(addn1 (size _)) !leq_add2l. Qed. Lemma dvdp_pexp2r m n k : k > 0 -> (m ^+ k %| n ^+ k) = (m %| n). Proof. move=> k_gt0; apply/idP/idP; last exact: dvdp_exp2r. have [-> // | nn0] := eqVneq n 0; have [-> | mn0] := eqVneq m 0. move/prednK: k_gt0=> {1}<-; rewrite exprS mul0r //= !dvd0p expf_eq0. by case/andP=> _ ->. set d := gcdp m n; have := dvdp_gcdr m n; rewrite -/d dvdp_eq. set c1 := _ ^+ _; set n' := _ %/ _; move/eqP=> def_n. have := dvdp_gcdl m n; rewrite -/d dvdp_eq. set c2 := _ ^+ _; set m' := _ %/ _; move/eqP=> def_m. have dn0 : d != 0 by rewrite gcdp_eq0 negb_and nn0 orbT. have c1n0 : c1 != 0 by rewrite !expf_neq0 // lead_coef_eq0. have c2n0 : c2 != 0 by rewrite !expf_neq0 // lead_coef_eq0. have c2k_n0 : c2 ^+ k != 0 by rewrite !expf_neq0 // lead_coef_eq0. rewrite -(@dvdpZr (c1 ^+ k)) ?expf_neq0 ?lead_coef_eq0 //. rewrite -(@dvdpZl (c2 ^+ k)) // -!exprZn def_m def_n !exprMn. rewrite dvdp_mul2r ?expf_neq0 //. have: coprimep (m' ^+ k) (n' ^+ k). by rewrite coprimep_pexpl // coprimep_pexpr // coprimep_div_gcd ?mn0. move/coprimepP=> hc hd. have /size_poly1P [c cn0 em'] : size m' == 1. case: (eqVneq m' 0) def_m => [-> /eqP | m'_n0 def_m]. by rewrite mul0r scale_poly_eq0 (negPf mn0) (negPf c2n0). have := hc _ (dvdpp _) hd; rewrite -size_poly_eq1. rewrite polySpred; last by rewrite expf_eq0 negb_and m'_n0 orbT. by rewrite size_exp eqSS muln_eq0 orbC eqn0Ngt k_gt0 /= -eqSS -polySpred. rewrite -(@dvdpZl c2) // def_m em' mul_polyC dvdpZl //. by rewrite -(@dvdpZr c1) // def_n dvdp_mull. Qed. Lemma root_gcd p q x : root (gcdp p q) x = root p x && root q x. Proof. rewrite /= !root_factor_theorem; apply/idP/andP=> [dg| [dp dq]]. by split; apply: dvdp_trans dg _; rewrite ?(dvdp_gcdl, dvdp_gcdr). have:= Bezoutp p q => [[[u v]]]; rewrite eqp_sym=> e. by rewrite (eqp_dvdr _ e) dvdp_addl dvdp_mull. Qed. Lemma root_biggcd x (ps : seq {poly R}) : root (\big[gcdp/0]_(p <- ps) p) x = all (fun p => root p x) ps. Proof. elim: ps => [|p ps ihp]; first by rewrite big_nil root0. by rewrite big_cons /= root_gcd ihp. Qed. (* "gdcop Q P" is the Greatest Divisor of P which is coprime to Q *) (* if P null, we pose that gdcop returns 1 if Q null, 0 otherwise*) Fixpoint gdcop_rec q p k := if k is m.+1 then if coprimep p q then p else gdcop_rec q (divp p (gcdp p q)) m else (q == 0)%:R. Definition gdcop q p := gdcop_rec q p (size p). Variant gdcop_spec q p : {poly R} -> Type := GdcopSpec r of (dvdp r p) & ((coprimep r q) || (p == 0)) & (forall d, dvdp d p -> coprimep d q -> dvdp d r) : gdcop_spec q p r. Lemma gdcop0 q : gdcop q 0 = (q == 0)%:R. Proof. by rewrite /gdcop size_poly0. Qed. Lemma gdcop_recP q p k : size p <= k -> gdcop_spec q p (gdcop_rec q p k). Proof. elim: k p => [p | k ihk p] /=. move/size_poly_leq0P->. have [->|q0] := eqVneq; split; rewrite ?coprime1p // ?eqxx ?orbT //. by move=> d _; rewrite coprimep0 dvdp1 size_poly_eq1. move=> hs; case cop : (coprimep _ _); first by split; rewrite ?dvdpp ?cop. have [-> | p0] := eqVneq p 0. by rewrite div0p; apply: ihk; rewrite size_poly0 leq0n. have [-> | q0] := eqVneq q 0. rewrite gcdp0 divpp ?p0 //= => {hs ihk}; case: k=> /=. rewrite eqxx; split; rewrite ?dvd1p ?coprimep0 ?eqpxx //=. by move=> d _; rewrite coprimep0 dvdp1 size_poly_eq1. move=> n; rewrite coprimep0 polyC_eqp1 //; rewrite lc_expn_scalp_neq0. split; first by rewrite (@eqp_dvdl 1) ?dvd1p // polyC_eqp1 lc_expn_scalp_neq0. by rewrite coprimep0 polyC_eqp1 // ?lc_expn_scalp_neq0. by move=> d _; rewrite coprimep0; move/eqp_dvdl->; rewrite dvd1p. move: (dvdp_gcdl p q); rewrite dvdp_eq; move/eqP=> e. have sgp : size (gcdp p q) <= size p. by apply: dvdp_leq; rewrite ?gcdp_eq0 ?p0 ?q0 // dvdp_gcdl. have : p %/ gcdp p q != 0; last move/negPf=>p'n0. apply: dvdpN0 (dvdp_mulIl (p %/ gcdp p q) (gcdp p q)) _. by rewrite -e scale_poly_eq0 negb_or lc_expn_scalp_neq0. have gn0 : gcdp p q != 0. apply: dvdpN0 (dvdp_mulIr (p %/ gcdp p q) (gcdp p q)) _. by rewrite -e scale_poly_eq0 negb_or lc_expn_scalp_neq0. have sp' : size (p %/ (gcdp p q)) <= k. rewrite size_divp ?sgp // leq_subLR (leq_trans hs) // -add1n leq_add2r -subn1. by rewrite ltn_subRL add1n ltn_neqAle eq_sym [_ == _]cop size_poly_gt0 gn0. case (ihk _ sp')=> r' dr'p'; first rewrite p'n0 orbF=> cr'q maxr'. constructor=> //=; rewrite ?(negPf p0) ?orbF //. exact/(dvdp_trans dr'p')/divp_dvd/dvdp_gcdl. move=> d dp cdq; apply: maxr'; last by rewrite cdq. case dpq: (d %| gcdp p q). move: (dpq); rewrite dvdp_gcd dp /= => dq; apply: dvdUp. apply: contraLR cdq => nd1; apply/coprimepPn; last first. by exists d; rewrite dvdp_gcd dvdpp dq nd1. by apply: contraNneq p0 => d0; move: dp; rewrite d0 dvd0p. apply: contraLR dp => ndp'. rewrite (@eqp_dvdr ((lead_coef (gcdp p q) ^+ scalp p (gcdp p q))*:p)). by rewrite e; rewrite Gauss_dvdpl //; apply: (coprimep_dvdl (dvdp_gcdr _ _)). by rewrite eqp_sym eqp_scale // lc_expn_scalp_neq0. Qed. Lemma gdcopP q p : gdcop_spec q p (gdcop q p). Proof. by rewrite /gdcop; apply: gdcop_recP. Qed. Lemma coprimep_gdco p q : (q != 0)%B -> coprimep (gdcop p q) p. Proof. by move=> q_neq0; case: gdcopP=> d; rewrite (negPf q_neq0) orbF. Qed. Lemma size2_dvdp_gdco p q d : p != 0 -> size d = 2 -> (d %| (gdcop q p)) = (d %| p) && ~~(d %| q). Proof. have [-> | dn0] := eqVneq d 0; first by rewrite size_poly0. move=> p0 sd; apply/idP/idP. case: gdcopP=> r rp crq maxr dr; move/negPf: (p0)=> p0f. rewrite (dvdp_trans dr) //=. apply: contraL crq => dq; rewrite p0f orbF; apply/coprimepPn. by apply: contraNneq p0 => r0; move: rp; rewrite r0 dvd0p. by exists d; rewrite dvdp_gcd dr dq -size_poly_eq1 sd. case/andP=> dp dq; case: gdcopP=> r rp crq maxr; apply: maxr=> //. apply/coprimepP=> x xd xq. move: (dvdp_leq dn0 xd); rewrite leq_eqVlt sd; case/orP; last first. rewrite ltnS leq_eqVlt ltnS size_poly_leq0 orbC. case/predU1P => [x0|]; last by rewrite -size_poly_eq1. by move: xd; rewrite x0 dvd0p (negPf dn0). by rewrite -sd dvdp_size_eqp //; move/(eqp_dvdl q); rewrite xq (negPf dq). Qed. Lemma dvdp_gdco p q : (gdcop p q) %| q. Proof. by case: gdcopP. Qed. Lemma root_gdco p q x : p != 0 -> root (gdcop q p) x = root p x && ~~(root q x). Proof. move=> p0 /=; rewrite !root_factor_theorem. apply: size2_dvdp_gdco; rewrite ?p0 //. by rewrite size_polyDl size_polyX // size_polyN size_polyC ltnS; case: (x != 0). Qed. Lemma dvdp_comp_poly r p q : (p %| q) -> (p \Po r) %| (q \Po r). Proof. have [-> | pn0] := eqVneq p 0. by rewrite comp_poly0 !dvd0p; move/eqP->; rewrite comp_poly0. rewrite dvdp_eq; set c := _ ^+ _; set s := _ %/ _; move/eqP=> Hq. apply: (@eq_dvdp c (s \Po r)); first by rewrite expf_neq0 // lead_coef_eq0. by rewrite -comp_polyZ Hq comp_polyM. Qed. Lemma gcdp_comp_poly r p q : gcdp p q \Po r %= gcdp (p \Po r) (q \Po r). Proof. apply/andP; split. by rewrite dvdp_gcd !dvdp_comp_poly ?dvdp_gcdl ?dvdp_gcdr. case: (Bezoutp p q) => [[u v]] /andP []. move/(dvdp_comp_poly r) => Huv _. rewrite (dvdp_trans _ Huv) // comp_polyD !comp_polyM. by rewrite dvdp_add // dvdp_mull //; [ exact: dvdp_gcdl | exact: dvdp_gcdr]. Qed. Lemma coprimep_comp_poly r p q : coprimep p q -> coprimep (p \Po r) (q \Po r). Proof. rewrite -!gcdp_eqp1 -!size_poly_eq1 -!dvdp1; move/(dvdp_comp_poly r). rewrite comp_polyC => Hgcd. by apply: dvdp_trans Hgcd; case/andP: (gcdp_comp_poly r p q). Qed. Lemma coprimep_addl_mul p q r : coprimep r (p * r + q) = coprimep r q. Proof. by rewrite !coprimep_def (eqp_size (gcdp_addl_mul _ _ _)). Qed. Definition irreducible_poly p := (size p > 1) * (forall q, size q != 1 -> q %| p -> q %= p) : Prop. Lemma irredp_neq0 p : irreducible_poly p -> p != 0. Proof. by rewrite -size_poly_gt0 => [[/ltnW]]. Qed. Definition apply_irredp p (irr_p : irreducible_poly p) := irr_p.2. Coercion apply_irredp : irreducible_poly >-> Funclass. Lemma modp_XsubC p c : p %% ('X - c%:P) = p.[c]%:P. Proof. have/factor_theorem [q /(canRL (subrK _)) Dp]: root (p - p.[c]%:P) c. by rewrite /root !hornerE subrr. rewrite modpE /= lead_coefXsubC unitr1 expr1n invr1 scale1r [in LHS]Dp. rewrite RingMonic.rmodp_addl_mul_small // ?monicXsubC// size_XsubC size_polyC. by case: (p.[c] == 0). Qed. Lemma coprimep_XsubC p c : coprimep p ('X - c%:P) = ~~ root p c. Proof. rewrite -coprimep_modl modp_XsubC /root -alg_polyC. have [-> | /coprimepZl->] := eqVneq; last exact: coprime1p. by rewrite scale0r /coprimep gcd0p size_XsubC. Qed. Lemma coprimep_XsubC2 (a b : R) : b - a != 0 -> coprimep ('X - a%:P) ('X - b%:P). Proof. by move=> bBa_neq0; rewrite coprimep_XsubC rootE hornerXsubC. Qed. Lemma coprimepX p : coprimep p 'X = ~~ root p 0. Proof. by rewrite -['X]subr0 coprimep_XsubC. Qed. Lemma eqp_monic : {in monic &, forall p q, (p %= q) = (p == q)}. Proof. move=> p q monic_p monic_q; apply/idP/eqP=> [|-> //]. case/eqpP=> [[a b] /= /andP[a_neq0 _] eq_pq]. apply: (@mulfI _ a%:P); first by rewrite polyC_eq0. rewrite !mul_polyC eq_pq; congr (_ *: q); apply: (mulIf (oner_neq0 _)). by rewrite -[in LHS](monicP monic_q) -(monicP monic_p) -!lead_coefZ eq_pq. Qed. Lemma dvdp_mul_XsubC p q c : (p %| ('X - c%:P) * q) = ((if root p c then p %/ ('X - c%:P) else p) %| q). Proof. case: ifPn => [| not_pc0]; last by rewrite Gauss_dvdpr ?coprimep_XsubC. rewrite root_factor_theorem -eqp_div_XsubC mulrC => /eqP{1}->. by rewrite dvdp_mul2l ?polyXsubC_eq0. Qed. Lemma dvdp_prod_XsubC (I : Type) (r : seq I) (F : I -> R) p : p %| \prod_(i <- r) ('X - (F i)%:P) -> {m | p %= \prod_(i <- mask m r) ('X - (F i)%:P)}. Proof. elim: r => [|i r IHr] in p *. by rewrite big_nil dvdp1; exists nil; rewrite // big_nil -size_poly_eq1. rewrite big_cons dvdp_mul_XsubC root_factor_theorem -eqp_div_XsubC. case: eqP => [{2}-> | _] /IHr[m Dp]; last by exists (false :: m). by exists (true :: m); rewrite /= mulrC big_cons eqp_mul2l ?polyXsubC_eq0. Qed. Lemma irredp_XsubC (x : R) : irreducible_poly ('X - x%:P). Proof. split=> [|d size_d d_dv_Xx]; first by rewrite size_XsubC. have: ~ d %= 1 by apply/negP; rewrite -size_poly_eq1. have [|m /=] := @dvdp_prod_XsubC _ [:: x] id d; first by rewrite big_seq1. by case: m => [|[] [|_ _] /=]; rewrite (big_nil, big_seq1). Qed. Lemma irredp_XaddC (x : R) : irreducible_poly ('X + x%:P). Proof. by rewrite -[x]opprK rmorphN; apply: irredp_XsubC. Qed. Lemma irredp_XsubCP d p : irreducible_poly p -> d %| p -> {d %= 1} + {d %= p}. Proof. move=> irred_p dvd_dp; have [] := boolP (_ %= 1); first by left. by rewrite -size_poly_eq1=> /irred_p /(_ dvd_dp); right. Qed. Lemma dvdp_exp_XsubCP (p : {poly R}) (c : R) (n : nat) : reflect (exists2 k, (k <= n)%N & p %= ('X - c%:P) ^+ k) (p %| ('X - c%:P) ^+ n). Proof. apply: (iffP idP) => [|[k lkn /eqp_dvdl->]]; last by rewrite dvdp_exp2l. move=> /Pdiv.WeakIdomain.dvdpP[[/= a q] a_neq0]. have [m [r]] := multiplicity_XsubC p c; have [->|pN0]/= := eqVneq p 0. rewrite mulr0 => _ _ /eqP; rewrite scale_poly_eq0 (negPf a_neq0)/=. by rewrite expf_eq0/= andbC polyXsubC_eq0. move=> rNc ->; rewrite mulrA => eq_qrm; exists m. have: ('X - c%:P) ^+ m %| a *: ('X - c%:P) ^+ n by rewrite eq_qrm dvdp_mull. by rewrite (eqp_dvdr _ (eqp_scale _ _))// dvdp_Pexp2l// size_XsubC. suff /eqP : size r = 1%N. by rewrite size_poly_eq1 => /eqp_mulr/eqp_trans->//; rewrite mul1r eqpxx. have : r %| a *: ('X - c%:P) ^+ n by rewrite eq_qrm mulrAC dvdp_mull. rewrite (eqp_dvdr _ (eqp_scale _ _))//. move: rNc; rewrite -coprimep_XsubC => /(coprimep_expr n) /coprimepP. by move=> /(_ _ (dvdpp _)); rewrite -size_poly_eq1 => /(_ _)/eqP. Qed. End IDomainPseudoDivision. Arguments gcdp : simpl never. #[global] Hint Resolve eqpxx divp0 divp1 mod0p modp0 modp1 : core. #[global] Hint Resolve dvdp_mull dvdp_mulr dvdpp dvdp0 : core. Arguments dvdp_exp_XsubCP {R p c n}. End CommonIdomain. Module Idomain. Include IdomainDefs. Export IdomainDefs. Include WeakIdomain. Include CommonIdomain. End Idomain. Module IdomainMonic. Import Ring ComRing UnitRing IdomainDefs Idomain. Section IdomainMonic. Variable R : idomainType. Implicit Type p d r : {poly R}. Section MonicDivisor. Variable q : {poly R}. Hypothesis monq : q \is monic. Lemma divpE p : p %/ q = rdivp p q. Proof. by rewrite divpE (eqP monq) unitr1 expr1n invr1 scale1r. Qed. Lemma modpE p : p %% q = rmodp p q. Proof. by rewrite modpE (eqP monq) unitr1 expr1n invr1 scale1r. Qed. Lemma scalpE p : scalp p q = 0. Proof. by rewrite scalpE (eqP monq) unitr1. Qed. Lemma divp_eq p : p = (p %/ q) * q + (p %% q). Proof. by rewrite -divp_eq (eqP monq) expr1n scale1r. Qed. Lemma divpp p : q %/ q = 1. Proof. by rewrite divpp ?monic_neq0 // (eqP monq) expr1n. Qed. Lemma dvdp_eq p : (q %| p) = (p == (p %/ q) * q). Proof. by rewrite dvdp_eq (eqP monq) expr1n scale1r. Qed. Lemma dvdpP p : reflect (exists qq, p = qq * q) (q %| p). Proof. apply: (iffP idP); first by rewrite dvdp_eq; move/eqP=> e; exists (p %/ q). by case=> qq ->; rewrite dvdp_mull // dvdpp. Qed. Lemma mulpK p : p * q %/ q = p. Proof. by rewrite mulpK ?monic_neq0 // (eqP monq) expr1n scale1r. Qed. Lemma mulKp p : q * p %/ q = p. Proof. by rewrite mulrC mulpK. Qed. End MonicDivisor. Lemma drop_poly_divp n p : drop_poly n p = p %/ 'X^n. Proof. by rewrite RingMonic.drop_poly_rdivp divpE // monicXn. Qed. Lemma take_poly_modp n p : take_poly n p = p %% 'X^n. Proof. by rewrite RingMonic.take_poly_rmodp modpE // monicXn. Qed. End IdomainMonic. End IdomainMonic. Module IdomainUnit. Import Ring ComRing UnitRing IdomainDefs Idomain. Section UnitDivisor. Variable R : idomainType. Variable d : {poly R}. Hypothesis ulcd : lead_coef d \in GRing.unit. Implicit Type p q r : {poly R}. Lemma divp_eq p : p = (p %/ d) * d + (p %% d). Proof. by have := divp_eq p d; rewrite scalpE ulcd expr0 scale1r. Qed. Lemma edivpP p q r : p = q * d + r -> size r < size d -> q = (p %/ d) /\ r = p %% d. Proof. move=> ep srd; have := divp_eq p; rewrite [LHS]ep. move/eqP; rewrite -subr_eq -addrA addrC eq_sym -subr_eq -mulrBl; move/eqP. have lcdn0 : lead_coef d != 0 by apply: contraTneq ulcd => ->; rewrite unitr0. have [-> /esym /eqP|abs] := eqVneq (p %/ d) q. by rewrite subrr mul0r subr_eq0 => /eqP<-. have hleq : size d <= size ((p %/ d - q) * d). rewrite size_proper_mul; last first. by rewrite mulf_eq0 (negPf lcdn0) orbF lead_coef_eq0 subr_eq0. by move: abs; rewrite -subr_eq0; move/polySpred->; rewrite addSn /= leq_addl. have hlt : size (r - p %% d) < size d. apply: leq_ltn_trans (size_polyD _ _) _. by rewrite gtn_max srd size_polyN ltn_modp -lead_coef_eq0. by move=> e; have:= leq_trans hlt hleq; rewrite e ltnn. Qed. Lemma divpP p q r : p = q * d + r -> size r < size d -> q = (p %/ d). Proof. by move/edivpP=> h; case/h. Qed. Lemma modpP p q r : p = q * d + r -> size r < size d -> r = (p %% d). Proof. by move/edivpP=> h; case/h. Qed. Lemma ulc_eqpP p q : lead_coef q \is a GRing.unit -> reflect (exists2 c : R, c != 0 & p = c *: q) (p %= q). Proof. have [->|] := eqVneq (lead_coef q) 0; first by rewrite unitr0. rewrite lead_coef_eq0 => nz_q ulcq; apply: (iffP idP). have [->|nz_p] := eqVneq p 0; first by rewrite eqp_sym eqp0 (negPf nz_q). move/eqp_eq=> eq; exists (lead_coef p / lead_coef q). by rewrite mulf_neq0 // ?invr_eq0 lead_coef_eq0. by apply/(scaler_injl ulcq); rewrite scalerA mulrCA divrr // mulr1. by case=> c nz_c ->; apply/eqpP; exists (1, c); rewrite ?scale1r ?oner_eq0. Qed. Lemma dvdp_eq p : (d %| p) = (p == p %/ d * d). Proof. apply/eqP/eqP=> [modp0 | ->]; last exact: modp_mull. by rewrite [p in LHS]divp_eq modp0 addr0. Qed. Lemma ucl_eqp_eq p q : lead_coef q \is a GRing.unit -> p %= q -> p = (lead_coef p / lead_coef q) *: q. Proof. move=> ulcq /eqp_eq; move/(congr1 ( *:%R (lead_coef q)^-1 )). by rewrite !scalerA mulrC divrr // scale1r mulrC. Qed. Lemma modpZl c p : (c *: p) %% d = c *: (p %% d). Proof. have [-> | cn0] := eqVneq c 0; first by rewrite !scale0r mod0p. have e : (c *: p) = (c *: (p %/ d)) * d + c *: (p %% d). by rewrite -scalerAl -scalerDr -divp_eq. suff s: size (c *: (p %% d)) < size d by case: (edivpP e s) => _ ->. rewrite -mul_polyC; apply: leq_ltn_trans (size_polyMleq _ _) _. rewrite size_polyC cn0 addSn add0n /= ltn_modp -lead_coef_eq0. by apply: contraTneq ulcd => ->; rewrite unitr0. Qed. Lemma divpZl c p : (c *: p) %/ d = c *: (p %/ d). Proof. have [-> | cn0] := eqVneq c 0; first by rewrite !scale0r div0p. have e : (c *: p) = (c *: (p %/ d)) * d + c *: (p %% d). by rewrite -scalerAl -scalerDr -divp_eq. suff s: size (c *: (p %% d)) < size d by case: (edivpP e s) => ->. rewrite -mul_polyC; apply: leq_ltn_trans (size_polyMleq _ _) _. rewrite size_polyC cn0 addSn add0n /= ltn_modp -lead_coef_eq0. by apply: contraTneq ulcd => ->; rewrite unitr0. Qed. Lemma eqp_modpl p q : p %= q -> (p %% d) %= (q %% d). Proof. case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0 e]. by apply/eqpP; exists (c1, c2); rewrite ?c1n0 //= -!modpZl e. Qed. Lemma eqp_divl p q : p %= q -> (p %/ d) %= (q %/ d). Proof. case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0 e]. by apply/eqpP; exists (c1, c2); rewrite ?c1n0 // -!divpZl e. Qed. Lemma modpN p : (- p) %% d = - (p %% d). Proof. by rewrite -mulN1r -[RHS]mulN1r -polyCN !mul_polyC modpZl. Qed. Lemma divpN p : (- p) %/ d = - (p %/ d). Proof. by rewrite -mulN1r -[RHS]mulN1r -polyCN !mul_polyC divpZl. Qed. Lemma modpD p q : (p + q) %% d = p %% d + q %% d. Proof. have/edivpP [] // : (p + q) = (p %/ d + q %/ d) * d + (p %% d + q %% d). by rewrite mulrDl addrACA -!divp_eq. apply: leq_ltn_trans (size_polyD _ _) _. rewrite gtn_max !ltn_modp andbb -lead_coef_eq0. by apply: contraTneq ulcd => ->; rewrite unitr0. Qed. Lemma divpD p q : (p + q) %/ d = p %/ d + q %/ d. Proof. have/edivpP [] // : (p + q) = (p %/ d + q %/ d) * d + (p %% d + q %% d). by rewrite mulrDl addrACA -!divp_eq. apply: leq_ltn_trans (size_polyD _ _) _. rewrite gtn_max !ltn_modp andbb -lead_coef_eq0. by apply: contraTneq ulcd => ->; rewrite unitr0. Qed. Lemma mulpK q : (q * d) %/ d = q. Proof. case/esym/edivpP: (addr0 (q * d)); rewrite // size_poly0 size_poly_gt0. by rewrite -lead_coef_eq0; apply: contraTneq ulcd => ->; rewrite unitr0. Qed. Lemma mulKp q : (d * q) %/ d = q. Proof. by rewrite mulrC; apply: mulpK. Qed. Lemma divp_addl_mul_small q r : size r < size d -> (q * d + r) %/ d = q. Proof. by move=> srd; rewrite divpD (divp_small srd) addr0 mulpK. Qed. Lemma modp_addl_mul_small q r : size r < size d -> (q * d + r) %% d = r. Proof. by move=> srd; rewrite modpD modp_mull add0r modp_small. Qed. Lemma divp_addl_mul q r : (q * d + r) %/ d = q + r %/ d. Proof. by rewrite divpD mulpK. Qed. Lemma divpp : d %/ d = 1. Proof. by rewrite -[d in d %/ _]mul1r mulpK. Qed. Lemma leq_divMp m : size (m %/ d * d) <= size m. Proof. case: (eqVneq d 0) ulcd => [->|dn0 _]; first by rewrite lead_coef0 unitr0. have [->|q0] := eqVneq (m %/ d) 0; first by rewrite mul0r size_poly0 leq0n. rewrite {2}(divp_eq m) size_polyDl // size_mul // (polySpred q0) addSn /=. by rewrite ltn_addl // ltn_modp. Qed. Lemma dvdpP p : reflect (exists q, p = q * d) (d %| p). Proof. apply: (iffP idP) => [| [k ->]]; last by apply/eqP; rewrite modp_mull. by rewrite dvdp_eq; move/eqP->; exists (p %/ d). Qed. Lemma divpK p : d %| p -> p %/ d * d = p. Proof. by rewrite dvdp_eq; move/eqP. Qed. Lemma divpKC p : d %| p -> d * (p %/ d) = p. Proof. by move=> ?; rewrite mulrC divpK. Qed. Lemma dvdp_eq_div p q : d %| p -> (q == p %/ d) = (q * d == p). Proof. move/divpK=> {2}<-; apply/eqP/eqP; first by move->. apply/mulIf; rewrite -lead_coef_eq0; apply: contraTneq ulcd => ->. by rewrite unitr0. Qed. Lemma dvdp_eq_mul p q : d %| p -> (p == q * d) = (p %/ d == q). Proof. by move=> dv_d_p; rewrite eq_sym -dvdp_eq_div // eq_sym. Qed. Lemma divp_mulA p q : d %| q -> p * (q %/ d) = p * q %/ d. Proof. move=> hdm; apply/eqP; rewrite eq_sym -dvdp_eq_mul. by rewrite -mulrA divpK. by move/divpK: hdm<-; rewrite mulrA dvdp_mull // dvdpp. Qed. Lemma divp_mulAC m n : d %| m -> m %/ d * n = m * n %/ d. Proof. by move=> hdm; rewrite mulrC (mulrC m); apply: divp_mulA. Qed. Lemma divp_mulCA p q : d %| p -> d %| q -> p * (q %/ d) = q * (p %/ d). Proof. by move=> hdp hdq; rewrite mulrC divp_mulAC // divp_mulA. Qed. Lemma modp_mul p q : (p * (q %% d)) %% d = (p * q) %% d. Proof. by rewrite [q in RHS]divp_eq mulrDr modpD mulrA modp_mull add0r. Qed. End UnitDivisor. #[deprecated(since="mathcomp 2.4.0", note="Renamed to leq_divMp.")] Notation leq_trunc_divp := leq_divMp. Section MoreUnitDivisor. Variable R : idomainType. Variable d : {poly R}. Hypothesis ulcd : lead_coef d \in GRing.unit. Implicit Types p q : {poly R}. Lemma expp_sub m n : n <= m -> (d ^+ (m - n))%N = d ^+ m %/ d ^+ n. Proof. by move/subnK=> {2}<-; rewrite exprD mulpK // lead_coef_exp unitrX. Qed. Lemma divp_pmul2l p q : lead_coef q \in GRing.unit -> d * p %/ (d * q) = p %/ q. Proof. move=> uq; rewrite {1}(divp_eq uq p) mulrDr mulrCA divp_addl_mul //; last first. by rewrite lead_coefM unitrM_comm ?ulcd //; red; rewrite mulrC. have dn0 : d != 0. by rewrite -lead_coef_eq0; apply: contraTneq ulcd => ->; rewrite unitr0. have qn0 : q != 0. by rewrite -lead_coef_eq0; apply: contraTneq uq => ->; rewrite unitr0. have dqn0 : d * q != 0 by rewrite mulf_eq0 negb_or dn0. suff : size (d * (p %% q)) < size (d * q). by rewrite ltnNge -divpN0 // negbK => /eqP ->; rewrite addr0. have [-> | rn0] := eqVneq (p %% q) 0. by rewrite mulr0 size_poly0 size_poly_gt0. by rewrite !size_mul // (polySpred dn0) !addSn /= ltn_add2l ltn_modp. Qed. Lemma divp_pmul2r p q : lead_coef p \in GRing.unit -> q * d %/ (p * d) = q %/ p. Proof. by move=> uq; rewrite -!(mulrC d) divp_pmul2l. Qed. Lemma divp_divl r p q : lead_coef r \in GRing.unit -> lead_coef p \in GRing.unit -> q %/ p %/ r = q %/ (p * r). Proof. move=> ulcr ulcp. have e : q = (q %/ p %/ r) * (p * r) + ((q %/ p) %% r * p + q %% p). by rewrite addrA (mulrC p) mulrA -mulrDl; rewrite -divp_eq //; apply: divp_eq. have pn0 : p != 0. by rewrite -lead_coef_eq0; apply: contraTneq ulcp => ->; rewrite unitr0. have rn0 : r != 0. by rewrite -lead_coef_eq0; apply: contraTneq ulcr => ->; rewrite unitr0. have s : size ((q %/ p) %% r * p + q %% p) < size (p * r). have [-> | qn0] := eqVneq ((q %/ p) %% r) 0. rewrite mul0r add0r size_mul // (polySpred rn0) addnS /=. by apply: leq_trans (leq_addr _ _); rewrite ltn_modp. rewrite size_polyDl mulrC. by rewrite !size_mul // (polySpred pn0) !addSn /= ltn_add2l ltn_modp. rewrite size_mul // (polySpred qn0) addnS /=. by apply: leq_trans (leq_addr _ _); rewrite ltn_modp. case: (edivpP _ e s) => //; rewrite lead_coefM unitrM_comm ?ulcp //. by red; rewrite mulrC. Qed. Lemma divpAC p q : lead_coef p \in GRing.unit -> q %/ d %/ p = q %/ p %/ d. Proof. by move=> ulcp; rewrite !divp_divl // mulrC. Qed. Lemma modpZr c p : c \in GRing.unit -> p %% (c *: d) = (p %% d). Proof. case: (eqVneq d 0) => [-> | dn0 cn0]; first by rewrite scaler0 !modp0. have e : p = (c^-1 *: (p %/ d)) * (c *: d) + (p %% d). by rewrite scalerCA scalerA mulVr // scale1r -(divp_eq ulcd). suff s : size (p %% d) < size (c *: d). by rewrite (modpP _ e s) // -mul_polyC lead_coefM lead_coefC unitrM cn0. by rewrite size_scale ?ltn_modp //; apply: contraTneq cn0 => ->; rewrite unitr0. Qed. Lemma divpZr c p : c \in GRing.unit -> p %/ (c *: d) = c^-1 *: (p %/ d). Proof. case: (eqVneq d 0) => [-> | dn0 cn0]; first by rewrite scaler0 !divp0 scaler0. have e : p = (c^-1 *: (p %/ d)) * (c *: d) + (p %% d). by rewrite scalerCA scalerA mulVr // scale1r -(divp_eq ulcd). suff s : size (p %% d) < size (c *: d). by rewrite (divpP _ e s) // -mul_polyC lead_coefM lead_coefC unitrM cn0. by rewrite size_scale ?ltn_modp //; apply: contraTneq cn0 => ->; rewrite unitr0. Qed. End MoreUnitDivisor. End IdomainUnit. Module Field. Import Ring ComRing UnitRing. Include IdomainDefs. Export IdomainDefs. Include CommonIdomain. Section FieldDivision. Variable F : fieldType. Implicit Type p q r d : {poly F}. Lemma divp_eq p q : p = (p %/ q) * q + (p %% q). Proof. have [-> | qn0] := eqVneq q 0; first by rewrite modp0 mulr0 add0r. by apply: IdomainUnit.divp_eq; rewrite unitfE lead_coef_eq0. Qed. Lemma divp_modpP p q d r : p = q * d + r -> size r < size d -> q = (p %/ d) /\ r = p %% d. Proof. move=> he hs; apply: IdomainUnit.edivpP => //; rewrite unitfE lead_coef_eq0. by rewrite -size_poly_gt0; apply: leq_trans hs. Qed. Lemma divpP p q d r : p = q * d + r -> size r < size d -> q = (p %/ d). Proof. by move/divp_modpP=> h; case/h. Qed. Lemma modpP p q d r : p = q * d + r -> size r < size d -> r = (p %% d). Proof. by move/divp_modpP=> h; case/h. Qed. Lemma eqpfP p q : p %= q -> p = (lead_coef p / lead_coef q) *: q. Proof. have [->|nz_q] := eqVneq q 0; first by rewrite eqp0 scaler0 => /eqP ->. by apply/IdomainUnit.ucl_eqp_eq; rewrite unitfE lead_coef_eq0. Qed. Lemma dvdp_eq q p : (q %| p) = (p == p %/ q * q). Proof. have [-> | qn0] := eqVneq q 0; first by rewrite dvd0p mulr0 eq_sym. by apply: IdomainUnit.dvdp_eq; rewrite unitfE lead_coef_eq0. Qed. Lemma eqpf_eq p q : reflect (exists2 c, c != 0 & p = c *: q) (p %= q). Proof. apply: (iffP idP); last first. case=> c nz_c ->; apply/eqpP. by exists (1, c); rewrite ?scale1r ?oner_eq0. have [->|nz_q] := eqVneq q 0. by rewrite eqp0=> /eqP ->; exists 1; rewrite ?scale1r ?oner_eq0. case/IdomainUnit.ulc_eqpP; first by rewrite unitfE lead_coef_eq0. by move=> c nz_c ->; exists c. Qed. Lemma modpZl c p q : (c *: p) %% q = c *: (p %% q). Proof. have [-> | qn0] := eqVneq q 0; first by rewrite !modp0. by apply: IdomainUnit.modpZl; rewrite unitfE lead_coef_eq0. Qed. Lemma mulpK p q : q != 0 -> p * q %/ q = p. Proof. by move=> qn0; rewrite IdomainUnit.mulpK // unitfE lead_coef_eq0. Qed. Lemma mulKp p q : q != 0 -> q * p %/ q = p. Proof. by rewrite mulrC; apply: mulpK. Qed. Lemma divpZl c p q : (c *: p) %/ q = c *: (p %/ q). Proof. have [-> | qn0] := eqVneq q 0; first by rewrite !divp0 scaler0. by apply: IdomainUnit.divpZl; rewrite unitfE lead_coef_eq0. Qed. Lemma modpZr c p d : c != 0 -> p %% (c *: d) = (p %% d). Proof. case: (eqVneq d 0) => [-> | dn0 cn0]; first by rewrite scaler0 !modp0. have e : p = (c^-1 *: (p %/ d)) * (c *: d) + (p %% d). by rewrite scalerCA scalerA mulVf // scale1r -divp_eq. suff s : size (p %% d) < size (c *: d) by rewrite (modpP e s). by rewrite size_scale ?ltn_modp. Qed. Lemma divpZr c p d : c != 0 -> p %/ (c *: d) = c^-1 *: (p %/ d). Proof. case: (eqVneq d 0) => [-> | dn0 cn0]; first by rewrite scaler0 !divp0 scaler0. have e : p = (c^-1 *: (p %/ d)) * (c *: d) + (p %% d). by rewrite scalerCA scalerA mulVf // scale1r -divp_eq. suff s : size (p %% d) < size (c *: d) by rewrite (divpP e s). by rewrite size_scale ?ltn_modp. Qed. Lemma eqp_modpl d p q : p %= q -> (p %% d) %= (q %% d). Proof. case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0 e]. by apply/eqpP; exists (c1, c2); rewrite ?c1n0 // -!modpZl e. Qed. Lemma eqp_divl d p q : p %= q -> (p %/ d) %= (q %/ d). Proof. case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0 e]. by apply/eqpP; exists (c1, c2); rewrite ?c1n0 // -!divpZl e. Qed. Lemma eqp_modpr d p q : p %= q -> (d %% p) %= (d %% q). Proof. case/eqpP=> [[c1 c2]] /andP [c1n0 c2n0 e]. have -> : p = (c1^-1 * c2) *: q by rewrite -scalerA -e scalerA mulVf // scale1r. by rewrite modpZr ?eqpxx // mulf_eq0 negb_or invr_eq0 c1n0. Qed. Lemma eqp_mod p1 p2 q1 q2 : p1 %= p2 -> q1 %= q2 -> p1 %% q1 %= p2 %% q2. Proof. move=> e1 e2; exact: eqp_trans (eqp_modpl _ e1) (eqp_modpr _ e2). Qed. Lemma eqp_divr (d m n : {poly F}) : m %= n -> (d %/ m) %= (d %/ n). Proof. case/eqpP=> [[c1 c2]] /andP [c1n0 c2n0 e]. have -> : m = (c1^-1 * c2) *: n by rewrite -scalerA -e scalerA mulVf // scale1r. by rewrite divpZr ?eqp_scale // ?invr_eq0 mulf_eq0 negb_or invr_eq0 c1n0. Qed. Lemma eqp_div p1 p2 q1 q2 : p1 %= p2 -> q1 %= q2 -> p1 %/ q1 %= p2 %/ q2. Proof. move=> e1 e2; exact: eqp_trans (eqp_divl _ e1) (eqp_divr _ e2). Qed. Lemma eqp_gdcor p q r : q %= r -> gdcop p q %= gdcop p r. Proof. move=> eqr; rewrite /gdcop (eqp_size eqr). move: (size r)=> n; elim: n p q r eqr => [|n ihn] p q r; first by rewrite eqpxx. move=> eqr /=; rewrite (eqp_coprimepl p eqr); case: ifP => _ //. exact/ihn/eqp_div/eqp_gcdl. Qed. Lemma eqp_gdcol p q r : q %= r -> gdcop q p %= gdcop r p. Proof. move=> eqr; rewrite /gdcop; move: (size p)=> n. elim: n p q r eqr {1 3}p (eqpxx p) => [|n ihn] p q r eqr s esp /=. case: (eqVneq q 0) eqr => [-> | nq0 eqr] /=. by rewrite eqp_sym eqp0 => ->; rewrite eqpxx. by case: (eqVneq r 0) eqr nq0 => [->|]; rewrite ?eqpxx // eqp0 => ->. rewrite (eqp_coprimepr _ eqr) (eqp_coprimepl _ esp); case: ifP=> _ //. exact/ihn/eqp_div/eqp_gcd. Qed. Lemma eqp_rgdco_gdco q p : rgdcop q p %= gdcop q p. Proof. rewrite /rgdcop /gdcop; move: (size p)=> n. elim: n p q {1 3}p {1 3}q (eqpxx p) (eqpxx q) => [|n ihn] p q s t /= sp tq. case: (eqVneq t 0) tq => [-> | nt0 etq]. by rewrite eqp_sym eqp0 => ->; rewrite eqpxx. by case: (eqVneq q 0) etq nt0 => [->|]; rewrite ?eqpxx // eqp0 => ->. rewrite rcoprimep_coprimep (eqp_coprimepl t sp) (eqp_coprimepr p tq). case: ifP=> // _; apply: ihn => //; apply: eqp_trans (eqp_rdiv_div _ _) _. by apply: eqp_div => //; apply: eqp_trans (eqp_rgcd_gcd _ _) _; apply: eqp_gcd. Qed. Lemma modpD d p q : (p + q) %% d = p %% d + q %% d. Proof. have [-> | dn0] := eqVneq d 0; first by rewrite !modp0. by apply: IdomainUnit.modpD; rewrite unitfE lead_coef_eq0. Qed. Lemma modpN p q : (- p) %% q = - (p %% q). Proof. by apply/eqP; rewrite -addr_eq0 -modpD addNr mod0p. Qed. Lemma modNp p q : (- p) %% q = - (p %% q). Proof. exact: modpN. Qed. Lemma divpD d p q : (p + q) %/ d = p %/ d + q %/ d. Proof. have [-> | dn0] := eqVneq d 0; first by rewrite !divp0 addr0. by apply: IdomainUnit.divpD; rewrite unitfE lead_coef_eq0. Qed. Lemma divpN p q : (- p) %/ q = - (p %/ q). Proof. by apply/eqP; rewrite -addr_eq0 -divpD addNr div0p. Qed. Lemma divp_addl_mul_small d q r : size r < size d -> (q * d + r) %/ d = q. Proof. move=> srd; rewrite divpD (divp_small srd) addr0 mulpK // -size_poly_gt0. exact: leq_trans srd. Qed. Lemma modp_addl_mul_small d q r : size r < size d -> (q * d + r) %% d = r. Proof. by move=> srd; rewrite modpD modp_mull add0r modp_small. Qed. Lemma divp_addl_mul d q r : d != 0 -> (q * d + r) %/ d = q + r %/ d. Proof. by move=> dn0; rewrite divpD mulpK. Qed. Lemma divpp d : d != 0 -> d %/ d = 1. Proof. by move=> dn0; apply: IdomainUnit.divpp; rewrite unitfE lead_coef_eq0. Qed. Lemma leq_divMp d m : size (m %/ d * d) <= size m. Proof. have [-> | dn0] := eqVneq d 0; first by rewrite mulr0 size_poly0. by apply: IdomainUnit.leq_divMp; rewrite unitfE lead_coef_eq0. Qed. Lemma divpK d p : d %| p -> p %/ d * d = p. Proof. case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite mulr0. by apply: IdomainUnit.divpK; rewrite unitfE lead_coef_eq0. Qed. Lemma divpKC d p : d %| p -> d * (p %/ d) = p. Proof. by move=> ?; rewrite mulrC divpK. Qed. Lemma dvdp_eq_div d p q : d != 0 -> d %| p -> (q == p %/ d) = (q * d == p). Proof. by move=> dn0; apply: IdomainUnit.dvdp_eq_div; rewrite unitfE lead_coef_eq0. Qed. Lemma dvdp_eq_mul d p q : d != 0 -> d %| p -> (p == q * d) = (p %/ d == q). Proof. by move=> dn0 dv_d_p; rewrite eq_sym -dvdp_eq_div // eq_sym. Qed. Lemma divp_mulA d p q : d %| q -> p * (q %/ d) = p * q %/ d. Proof. case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite !divp0 mulr0. by apply: IdomainUnit.divp_mulA; rewrite unitfE lead_coef_eq0. Qed. Lemma divp_mulAC d m n : d %| m -> m %/ d * n = m * n %/ d. Proof. by move=> hdm; rewrite mulrC (mulrC m); apply: divp_mulA. Qed. Lemma divp_mulCA d p q : d %| p -> d %| q -> p * (q %/ d) = q * (p %/ d). Proof. by move=> hdp hdq; rewrite mulrC divp_mulAC // divp_mulA. Qed. Lemma expp_sub d m n : d != 0 -> m >= n -> (d ^+ (m - n))%N = d ^+ m %/ d ^+ n. Proof. by move=> dn0 /subnK=> {2}<-; rewrite exprD mulpK // expf_neq0. Qed. Lemma divp_pmul2l d q p : d != 0 -> q != 0 -> d * p %/ (d * q) = p %/ q. Proof. by move=> dn0 qn0; apply: IdomainUnit.divp_pmul2l; rewrite unitfE lead_coef_eq0. Qed. Lemma divp_pmul2r d p q : d != 0 -> p != 0 -> q * d %/ (p * d) = q %/ p. Proof. by move=> dn0 qn0; rewrite -!(mulrC d) divp_pmul2l. Qed. Lemma divp_divl r p q : q %/ p %/ r = q %/ (p * r). Proof. have [-> | rn0] := eqVneq r 0; first by rewrite mulr0 !divp0. have [-> | pn0] := eqVneq p 0; first by rewrite mul0r !divp0 div0p. by apply: IdomainUnit.divp_divl; rewrite unitfE lead_coef_eq0. Qed. Lemma divpAC d p q : q %/ d %/ p = q %/ p %/ d. Proof. by rewrite !divp_divl // mulrC. Qed. Lemma edivp_def p q : edivp p q = (0, p %/ q, p %% q). Proof. rewrite Idomain.edivp_def; congr (_, _, _); rewrite /scalp 2!unlock /=. have [-> | qn0] := eqVneq; first by rewrite lead_coef0 unitr0. by rewrite unitfE lead_coef_eq0 qn0 /=; case: (redivp_rec _ _ _ _) => [[]]. Qed. Lemma divpE p q : p %/ q = (lead_coef q)^-(rscalp p q) *: (rdivp p q). Proof. have [-> | qn0] := eqVneq q 0; first by rewrite rdivp0 divp0 scaler0. by rewrite Idomain.divpE unitfE lead_coef_eq0 qn0. Qed. Lemma modpE p q : p %% q = (lead_coef q)^-(rscalp p q) *: (rmodp p q). Proof. have [-> | qn0] := eqVneq q 0. by rewrite rmodp0 modp0 /rscalp unlock eqxx lead_coef0 expr0 invr1 scale1r. by rewrite Idomain.modpE unitfE lead_coef_eq0 qn0. Qed. Lemma scalpE p q : scalp p q = 0. Proof. have [-> | qn0] := eqVneq q 0; first by rewrite scalp0. by rewrite Idomain.scalpE unitfE lead_coef_eq0 qn0. Qed. (* Just to have it without importing the weak theory *) Lemma dvdpE p q : p %| q = rdvdp p q. Proof. exact: Idomain.dvdpE. Qed. Variant edivp_spec m d : nat * {poly F} * {poly F} -> Type := EdivpSpec n q r of m = q * d + r & (d != 0) ==> (size r < size d) : edivp_spec m d (n, q, r). Lemma edivpP m d : edivp_spec m d (edivp m d). Proof. rewrite edivp_def; constructor; first exact: divp_eq. by apply/implyP=> dn0; rewrite ltn_modp. Qed. Lemma edivp_eq d q r : size r < size d -> edivp (q * d + r) d = (0, q, r). Proof. move=> srd; apply: Idomain.edivp_eq; rewrite // unitfE lead_coef_eq0. by rewrite -size_poly_gt0; apply: leq_trans srd. Qed. Lemma modp_mul p q m : (p * (q %% m)) %% m = (p * q) %% m. Proof. by rewrite [in RHS](divp_eq q m) mulrDr modpD mulrA modp_mull add0r. Qed. Lemma horner_mod p q x : root q x -> (p %% q).[x] = p.[x]. Proof. by rewrite [in RHS](divp_eq p q) !hornerE => /eqP->; rewrite mulr0 add0r. Qed. Lemma dvdpP p q : reflect (exists qq, p = qq * q) (q %| p). Proof. have [-> | qn0] := eqVneq q 0; last first. by apply: IdomainUnit.dvdpP; rewrite unitfE lead_coef_eq0. by rewrite dvd0p; apply: (iffP eqP) => [->| [? ->]]; [exists 1|]; rewrite mulr0. Qed. Lemma Bezout_eq1_coprimepP p q : reflect (exists u, u.1 * p + u.2 * q = 1) (coprimep p q). Proof. apply: (iffP idP)=> [hpq|]; last first. by case=> -[u v] /= e; apply/Bezout_coprimepP; exists (u, v); rewrite e eqpxx. case/Bezout_coprimepP: hpq => [[u v]] /=. case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0] e. exists (c2^-1 *: (c1 *: u), c2^-1 *: (c1 *: v)); rewrite /= -!scalerAl. by rewrite -!scalerDr e scalerA mulVf // scale1r. Qed. Lemma dvdp_gdcor p q : q != 0 -> p %| (gdcop q p) * (q ^+ size p). Proof. rewrite /gdcop => nz_q; have [n hsp] := ubnPleq (size p). elim: n => [|n IHn] /= in p hsp *; first by rewrite (negPf nz_q) mul0r dvdp0. have [_ | ncop_pq] := ifPn; first by rewrite dvdp_mulr. have g_gt1: 1 < size (gcdp p q). rewrite ltn_neqAle eq_sym ncop_pq size_poly_gt0 gcdp_eq0. by rewrite negb_and nz_q orbT. have [-> | nz_p] := eqVneq p 0. by rewrite div0p exprSr mulrA dvdp_mulr // IHn // size_poly0. have le_d_p: size (p %/ gcdp p q) < size p. rewrite size_divp -?size_poly_eq0 -(subnKC g_gt1) // add2n /=. by rewrite polySpred // ltnS subSS leq_subr. rewrite -[p in p %| _](divpK (dvdp_gcdl p q)) exprSr mulrA. by rewrite dvdp_mul ?IHn ?dvdp_gcdr // -ltnS (leq_trans le_d_p). Qed. Lemma reducible_cubic_root p q : size p <= 4 -> 1 < size q < size p -> q %| p -> {r | root p r}. Proof. move=> p_le4 /andP[]; rewrite leq_eqVlt eq_sym. have [/poly2_root[x qx0] _ _ | _ /= q_gt2 p_gt_q] := size q =P 2. by exists x; rewrite -!dvdp_XsubCl in qx0 *; apply: (dvdp_trans qx0). case/dvdpP/sig_eqW=> r def_p; rewrite def_p. suffices /poly2_root[x rx0]: size r = 2 by exists x; rewrite rootM rx0. have /norP[nz_r nz_q]: ~~ [|| r == 0 | q == 0]. by rewrite -mulf_eq0 -def_p -size_poly_gt0 (leq_ltn_trans _ p_gt_q). rewrite def_p size_mul // -subn1 leq_subLR ltn_subRL in p_gt_q p_le4. by apply/eqP; rewrite -(eqn_add2r (size q)) eqn_leq (leq_trans p_le4). Qed. Lemma cubic_irreducible p : 1 < size p <= 4 -> (forall x, ~~ root p x) -> irreducible_poly p. Proof. move=> /andP[p_gt1 p_le4] root'p; split=> // q sz_q_neq1 q_dv_p. have nz_p: p != 0 by rewrite -size_poly_gt0 ltnW. have nz_q: q != 0 by apply: contraTneq q_dv_p => ->; rewrite dvd0p. have q_gt1: size q > 1 by rewrite ltn_neqAle eq_sym sz_q_neq1 size_poly_gt0. rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //= leqNgt; apply/negP=> p_gt_q. by have [|x /idPn//] := reducible_cubic_root p_le4 _ q_dv_p; rewrite q_gt1. Qed. Section Multiplicity. Definition mup x q := [arg max_(n > (ord0 : 'I_(size q).+1) | ('X - x%:P) ^+ n %| q) n] : nat. Lemma mup_geq x q n : q != 0 -> (n <= mup x q)%N = (('X - x%:P) ^+ n %| q). Proof. move=> q_neq0; rewrite /mup; symmetry. case: arg_maxnP; rewrite ?expr0 ?dvd1p//= => i i_dvd gti. case: ltnP => [|/dvdp_exp2l/dvdp_trans]; last exact. apply: contraTF => dvdq; rewrite -leqNgt. suff n_small : (n < (size q).+1)%N by exact: (gti (Ordinal n_small)). by rewrite ltnS ltnW// -(size_exp_XsubC _ x) dvdp_leq. Qed. Lemma mup_leq x q n : q != 0 -> (mup x q <= n)%N = ~~ (('X - x%:P) ^+ n.+1 %| q). Proof. by move=> qN0; rewrite leqNgt mup_geq. Qed. Lemma mup_ltn x q n : q != 0 -> (mup x q < n)%N = ~~ (('X - x%:P) ^+ n %| q). Proof. by move=> qN0; rewrite ltnNge mup_geq. Qed. Lemma XsubC_dvd x q : q != 0 -> ('X - x%:P %| q) = (0 < mup x q)%N. Proof. by move=> /mup_geq-/(_ _ 1%N)/esym; apply. Qed. Lemma mup_XsubCX n x y : mup x (('X - y%:P) ^+ n) = (if (y == x) then n else 0)%N. Proof. have Xxn0 : ('X - y%:P) ^+ n != 0 by rewrite ?expf_neq0 ?polyXsubC_eq0. apply/eqP; rewrite eqn_leq mup_leq ?mup_geq//. have [->|Nxy] := eqVneq x y. by rewrite /= dvdpp ?dvdp_Pexp2l ?size_XsubC ?ltnn. by rewrite dvd1p dvdp_XsubCl /root horner_exp !hornerE expf_neq0// subr_eq0. Qed. Lemma mupNroot x q : ~~ root q x -> mup x q = 0%N. Proof. move=> qNx; have qN0 : q != 0 by apply: contraNneq qNx => ->; rewrite root0. by move: qNx; rewrite -dvdp_XsubCl XsubC_dvd// lt0n negbK => /eqP. Qed. Lemma mupMr x q1 q2 : ~~ root q1 x -> mup x (q1 * q2) = mup x q2. Proof. move=> q1Nx; have q1N0 : q1 != 0 by apply: contraNneq q1Nx => ->; rewrite root0. have [->|q2N0] := eqVneq q2 0; first by rewrite mulr0. apply/esym/eqP; rewrite eqn_leq mup_geq ?mulf_neq0// dvdp_mull -?mup_geq//=. rewrite mup_leq ?mulf_neq0// Gauss_dvdpr -?mup_ltn//. by rewrite coprimep_expl// coprimep_sym coprimep_XsubC. Qed. Lemma mupMl x q1 q2 : ~~ root q2 x -> mup x (q1 * q2) = mup x q1. Proof. by rewrite mulrC; apply/mupMr. Qed. Lemma mupM x q1 q2 : q1 != 0 -> q2 != 0 -> mup x (q1 * q2) = (mup x q1 + mup x q2)%N. Proof. move=> q1N0 q2N0; apply/eqP; rewrite eqn_leq mup_leq ?mulf_neq0//. rewrite mup_geq ?mulf_neq0// exprD ?dvdp_mul; do ?by rewrite -mup_geq. have [m1 [r1]] := multiplicity_XsubC q1 x; rewrite q1N0 /= => r1Nx ->. have [m2 [r2]] := multiplicity_XsubC q2 x; rewrite q2N0 /= => r2Nx ->. rewrite !mupMr// ?mup_XsubCX eqxx/= mulrACA exprS exprD. rewrite dvdp_mul2r ?mulf_neq0 ?expf_neq0 ?polyXsubC_eq0//. by rewrite dvdp_XsubCl rootM negb_or r1Nx r2Nx. Qed. Lemma mu_prod_XsubC x (s : seq F) : mup x (\prod_(y <- s) ('X - y%:P)) = count_mem x s. Proof. elim: s => [|y s IHs]; rewrite (big_cons, big_nil)/=. by rewrite mupNroot// root1. rewrite mupM ?polyXsubC_eq0// ?monic_neq0 ?monic_prod_XsubC//. by rewrite IHs (@mup_XsubCX 1). Qed. Lemma prod_XsubC_eq (s t : seq F) : \prod_(x <- s) ('X - x%:P) = \prod_(x <- t) ('X - x%:P) -> perm_eq s t. Proof. move=> eq_prod; apply/allP => x _ /=; apply/eqP. by have /(congr1 (mup x)) := eq_prod; rewrite !mu_prod_XsubC. Qed. End Multiplicity. Section FieldRingMap. Variable rR : nzRingType. Variable f : {rmorphism F -> rR}. Local Notation "p ^f" := (map_poly f p) : ring_scope. Implicit Type a b : {poly F}. Lemma redivp_map a b : redivp a^f b^f = (rscalp a b, (rdivp a b)^f, (rmodp a b)^f). Proof. rewrite /rdivp /rscalp /rmodp !unlock map_poly_eq0 size_map_poly. have [// | q_nz] := ifPn; rewrite -(rmorph0 (map_poly f)) //. have [m _] := ubnPeq (size a); elim: m 0%N 0 a => [|m IHm] qq r a /=. rewrite -!mul_polyC !size_map_poly !lead_coef_map // -(map_polyXn f). by rewrite -!(map_polyC f) -!rmorphM -rmorphB -rmorphD; case: (_ < _). rewrite -!mul_polyC !size_map_poly !lead_coef_map // -(map_polyXn f). by rewrite -!(map_polyC f) -!rmorphM -rmorphB -rmorphD /= IHm; case: (_ < _). Qed. End FieldRingMap. Section FieldMap. Variable rR : idomainType. Variable f : {rmorphism F -> rR}. Local Notation "p ^f" := (map_poly f p) : ring_scope. Implicit Type a b : {poly F}. Lemma edivp_map a b : edivp a^f b^f = (0, (a %/ b)^f, (a %% b)^f). Proof. have [-> | bn0] := eqVneq b 0. rewrite (rmorph0 (map_poly f)) WeakIdomain.edivp_def !modp0 !divp0. by rewrite (rmorph0 (map_poly f)) scalp0. rewrite unlock redivp_map lead_coef_map rmorph_unit; last first. by rewrite unitfE lead_coef_eq0. rewrite modpE divpE !map_polyZ [in RHS]rmorphV ?rmorphXn // unitfE. by rewrite expf_neq0 // lead_coef_eq0. Qed. Lemma scalp_map p q : scalp p^f q^f = scalp p q. Proof. by rewrite /scalp edivp_map edivp_def. Qed. Lemma map_divp p q : (p %/ q)^f = p^f %/ q^f. Proof. by rewrite /divp edivp_map edivp_def. Qed. Lemma map_modp p q : (p %% q)^f = p^f %% q^f. Proof. by rewrite /modp edivp_map edivp_def. Qed. Lemma egcdp_map p q : egcdp (map_poly f p) (map_poly f q) = (map_poly f (egcdp p q).1, map_poly f (egcdp p q).2). Proof. wlog le_qp: p q / size q <= size p. move=> IH; have [/IH// | lt_qp] := leqP (size q) (size p). have /IH := ltnW lt_qp; rewrite /egcdp !size_map_poly ltnW // leqNgt lt_qp /=. by case: (egcdp_rec _ _ _) => u v [-> ->]. rewrite /egcdp !size_map_poly {}le_qp; move: (size q) => n. elim: n => /= [|n IHn] in p q *; first by rewrite rmorph1 rmorph0. rewrite map_poly_eq0; have [_ | nz_q] := ifPn; first by rewrite rmorph1 rmorph0. rewrite -map_modp (IHn q (p %% q)); case: (egcdp_rec _ _ n) => u v /=. rewrite map_polyZ lead_coef_map -rmorphXn scalp_map rmorphB rmorphM. by rewrite -map_divp. Qed. Lemma dvdp_map p q : (p^f %| q^f) = (p %| q). Proof. by rewrite /dvdp -map_modp map_poly_eq0. Qed. Lemma eqp_map p q : (p^f %= q^f) = (p %= q). Proof. by rewrite /eqp !dvdp_map. Qed. Lemma gcdp_map p q : (gcdp p q)^f = gcdp p^f q^f. Proof. wlog lt_p_q: p q / size p < size q. move=> IHpq; case: (ltnP (size p) (size q)) => [|le_q_p]; first exact: IHpq. rewrite gcdpE (gcdpE p^f) !size_map_poly ltnNge le_q_p /= -map_modp. have [-> | q_nz] := eqVneq q 0; first by rewrite rmorph0 !gcdp0. by rewrite IHpq ?ltn_modp. have [m le_q_m] := ubnP (size q); elim: m => // m IHm in p q lt_p_q le_q_m *. rewrite gcdpE (gcdpE p^f) !size_map_poly lt_p_q -map_modp. have [-> | q_nz] := eqVneq p 0; first by rewrite rmorph0 !gcdp0. by rewrite IHm ?(leq_trans lt_p_q) ?ltn_modp. Qed. Lemma coprimep_map p q : coprimep p^f q^f = coprimep p q. Proof. by rewrite -!gcdp_eqp1 -eqp_map rmorph1 gcdp_map. Qed. Lemma gdcop_rec_map p q n : (gdcop_rec p q n)^f = gdcop_rec p^f q^f n. Proof. elim: n p q => [|n IH] => /= p q. by rewrite map_poly_eq0; case: eqP; rewrite ?rmorph1 ?rmorph0. rewrite /coprimep -gcdp_map size_map_poly. by case: eqP => Hq0 //; rewrite -map_divp -IH. Qed. Lemma gdcop_map p q : (gdcop p q)^f = gdcop p^f q^f. Proof. by rewrite /gdcop gdcop_rec_map !size_map_poly. Qed. End FieldMap. End FieldDivision. #[deprecated(since="mathcomp 2.4.0", note="Renamed to leq_divMp.")] Notation leq_trunc_divp := leq_divMp. End Field. Module ClosedField. Import Field. Section closed. Variable F : closedFieldType. Lemma root_coprimep (p q : {poly F}) : (forall x, root p x -> q.[x] != 0) -> coprimep p q. Proof. move=> Ncmn; rewrite -gcdp_eqp1 -size_poly_eq1; apply/closed_rootP. by case=> r; rewrite root_gcd !rootE=> /andP [/Ncmn/negPf->]. Qed. Lemma coprimepP (p q : {poly F}) : reflect (forall x, root p x -> q.[x] != 0) (coprimep p q). Proof. by apply: (iffP idP)=> [/coprimep_root|/root_coprimep]. Qed. End closed. End ClosedField. End Pdiv. Export Pdiv.Field.
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.
order.v
(* (c) Copyright 2006-2019 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice seq. From mathcomp Require Import path fintype tuple bigop finset div prime finfun. From mathcomp Require Import finset. From mathcomp Require Export preorder. (******************************************************************************) (* Types equipped with order relations *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This files defines types equipped with order relations. *) (* *) (* * How to use orders in MathComp? *) (* Use one of the following modules implementing different theories (all *) (* located in the module Order): *) (* Order.LTheory: partially ordered types and lattices excluding complement *) (* and totality related theorems *) (* Order.CTheory: complemented lattices including Order.LTheory *) (* Order.TTheory: totally ordered types including Order.LTheory *) (* Order.Theory: ordered types including all of the above theory modules *) (* To access the definitions, notations, and the theory from, say, *) (* "Order.Xyz", insert "Import Order.Xyz." at the top of your scripts. You can*) (* also "Import Order.Def." to enjoy shorter notations (e.g., min instead of *) (* Order.min, nondecreasing instead of Order.nondecreasing, etc.). *) (* *) (* In order to reason about abstract orders, notations are accessible by *) (* opening the scope "order_scope" bound to the delimiting key "O"; however, *) (* when dealing with another notation scope providing order notations for *) (* a concrete instance (e.g., "ring_scope"), it is not recommended to open *) (* "order_scope" at the same time. *) (* *) (* * Control of inference (parsing) and printing *) (* One characteristic of ordered types is that one carrier type may have *) (* several orders. For example, natural numbers can be totally or partially *) (* ordered by the less than or equal relation, the divisibility relation, and *) (* their dual relations. Therefore, we need a way to control inference of *) (* ordered type instances and printing of generic relations and operations on *) (* ordered types. As a rule of thumb, we use the carrier type or its "alias" *) (* (named copy) to control inference (using canonical structures), and use a *) (* "display" to control the printing of notations. *) (* *) (* Each generic interface and operation for ordered types has, as its first *) (* argument, a "display" of type Order.disp_t. For example, the less than or *) (* equal relation has type: *) (* Order.le : forall {d : Order.disp_t} {T : porderType d}, rel T, *) (* where porderType d is the structure of partially ordered types with *) (* display d. (@Order.le dvd_display _ m n) is printed as m %| n because *) (* ordered type instances associated to the display dvd_display is intended *) (* to represent natural numbers partially ordered by the divisibility *) (* relation. *) (* *) (* We stress that order structure inference can be triggered only from the *) (* carrier type (or its alias), but not the display. For example, writing *) (* m %| n for m and n of type nat does not trigger an inference of the *) (* divisibility relation on natural numbers, which is associated to an alias *) (* natdvd for nat; such an inference should be triggered through the use of *) (* the corresponding alias, i.e., (m : natdvd) %| n. In other words, displays *) (* are merely used to inform the user and the notation mechanism of what the *) (* inference did; they are not additional input for the inference. *) (* *) (* See below for various aliases and their associated displays. *) (* *) (* NB: algebra/ssrnum.v provides the display ring_display to change the *) (* scope of the usual notations to ring_scope. *) (* *) (* Instantiating d with Disp tt tt or an unknown display will lead to a *) (* default display for notations. *) (* *) (* Alternative notation displays can be defined by : *) (* 1. declaring a new opaque definition of type unit. Using the idiom *) (* `Fact my_display : Order.disp_t. Proof. exact: Disp tt tt. Qed.` *) (* 2. using this symbol to tag canonical porderType structures using *) (* `HB.instance Definition _ := isPOrder.Build my_display my_type ...`, *) (* 3. declaring notations for the main operations of this library, by *) (* setting the first argument of the definition to the display, e.g. *) (* `Notation my_syndef_le x y := @Order.le my_display _ x y.` or *) (* `Notation "x <=< y" := @Order.lt my_display _ x y (at level ...).` *) (* Non overloaded notations will default to the default display. *) (* We suggest the user to refer to the example of natdvd below as a guideline *) (* example to add their own displays. *) (* *) (* * Interfaces *) (* We provide the following interfaces for types equipped with an order: *) (* *) (* porderType d == the type of partially ordered types *) (* The HB class is called POrder. *) (* bPOrderType d == porderType with a bottom element (\bot) *) (* The HB class is called BPOrder. *) (* tPOrderType d == porderType with a top element (\top) *) (* The HB class is called TPOrder. *) (* tbPOrderType d == porderType with both a top and a bottom *) (* The HB class is called TBPOrder. *) (* meetSemilatticeType d == the type of meet semilattices *) (* The HB class is called MeetSemilattice. *) (* bMeetSemilatticeType d == meetSemilatticeType with a bottom element *) (* The HB class is called BMeetSemilattice. *) (* tMeetSemilatticeType d == meetSemilatticeType with a top element *) (* The HB class is called TMeetSemilattice. *) (* tbMeetSemilatticeType d == meetSemilatticeType with both a top and a *) (* bottom *) (* The HB class is called TBMeetSemilattice. *) (* joinSemilatticeType d == the type of join semilattices *) (* The HB class is called JoinSemilattice. *) (* bJoinSemilatticeType d == joinSemilatticeType with a bottom element *) (* The HB class is called BJoinSemilattice. *) (* tJoinSemilatticeType d == joinSemilatticeType with a top element *) (* The HB class is called TJoinSemilattice. *) (* tbJoinSemilatticeType d == joinSemilatticeType with both a top and a *) (* bottom *) (* The HB class is called TBJoinSemilattice. *) (* latticeType d == the type of lattices *) (* The HB class is called Lattice. *) (* bLatticeType d == latticeType with a bottom element *) (* The HB class is called BLattice. *) (* tLatticeType d == latticeType with a top element *) (* The HB class is called TLattice. *) (* tbLatticeType d == latticeType with both a top and a bottom *) (* The HB class is called TBLattice. *) (* distrLatticeType d == the type of distributive lattices *) (* The HB class is called DistrLattice. *) (* bDistrLatticeType d == distrLatticeType with a bottom element *) (* The HB class is called BDistrLattice. *) (* tDistrLatticeType d == distrLatticeType with a top element *) (* The HB class is called TDistrLattice. *) (* tbDistrLatticeType d == distrLatticeType with both a top and a bottom *) (* The HB class is called TBDistrLattice. *) (* orderType d == the type of totally ordered types *) (* The HB class is called Total. *) (* bOrderType d == orderType with a bottom element *) (* The HB class is called BTotal. *) (* tOrderType d == orderType with a top element *) (* The HB class is called TTotal. *) (* tbOrderType d == orderType with both a top and a bottom *) (* The HB class is called TBTotal. *) (* cDistrLatticeType d == the type of relatively complemented *) (* distributive lattices, where each interval *) (* [a, b] is equipped with a complement operation*) (* The HB class is called CDistrLattice. *) (* cbDistrLatticeType d == the type of sectionally complemented *) (* distributive lattices, equipped with a bottom,*) (* a relative complement operation, and a *) (* difference operation, i.e., a complement *) (* operation for each interval of the form *) (* [\bot, b] *) (* The HB class is called CBDistrLattice. *) (* ctDistrLatticeType d == the type of dually sectionally complemented *) (* distributive lattices, equipped with a top, *) (* a relative complement operation, and a *) (* dual difference operation, i.e. a complement *) (* operation for each interval of the form *) (* [a, \top] *) (* The HB class is called CTDistrLattice. *) (* ctbDistrLatticeType d == the type of complemented distributive *) (* lattices, equipped with top, bottom, *) (* difference, dual difference, and complement *) (* The HB class is called CTBDistrLattice. *) (* finPOrderType d == the type of partially ordered finite types *) (* The HB class is called FinPOrder. *) (* finBPOrderType d == finPOrderType with a bottom element *) (* The HB class is called FinBPOrder. *) (* finTPOrderType d == finPOrderType with a top element *) (* The HB class is called FinTPOrder. *) (* finTBPOrderType d == finPOrderType with both a top and a bottom *) (* The HB class is called FinTBPOrder. *) (* finMeetSemilatticeType d == the type of finite meet semilattice types *) (* The HB class is called FinMeetSemilattice. *) (* finBMeetSemilatticeType d == finMeetSemilatticeType with a bottom element *) (* Note that finTMeetSemilatticeType is just *) (* finTBLatticeType. *) (* The HB class is called FinBMeetSemilattice. *) (* finJoinSemilatticeType d == the type of finite join semilattice types *) (* The HB class is called FinJoinSemilattice. *) (* finTJoinSemilatticeType d == finJoinSemilatticeType with a top element *) (* Note that finBJoinSemilatticeType is just *) (* finTBLatticeType. *) (* The HB class is called FinTJoinSemilattice. *) (* finLatticeType d == the type of finite lattices *) (* The HB class is called FinLattice. *) (* finTBLatticeType d == the type of nonempty finite lattices *) (* The HB class is called FinTBLattice. *) (* finDistrLatticeType d == the type of finite distributive lattices *) (* The HB class is called FinDistrLattice. *) (* finTBDistrLatticeType d == the type of nonempty finite distributive *) (* lattices *) (* The HB class is called FinTBDistrLattice. *) (* finOrderType d == the type of totally ordered finite types *) (* The HB class is called FinTotal. *) (* finTBOrderType d == the type of nonempty totally ordered finite *) (* types *) (* The HB class is called FinTBTotal. *) (* finCDistrLatticeType d == the type of finite relatively complemented *) (* distributive lattices *) (* The HB class is called FinCDistrLattice. *) (* finCTBDistrLatticeType d == the type of finite complemented distributive *) (* lattices *) (* The HB class is called FinCTBDistrLattice. *) (* *) (* and their joins with subType: *) (* *) (* subPOrder d T P d' == join of porderType d' and subType *) (* (P : pred T) such that val is monotonic *) (* The HB class is called SubPOrder. *) (* meetSubLattice d T P d' == join of latticeType d' and subType *) (* (P : pred T) such that val is monotonic and *) (* a morphism for meet *) (* The HB class is called MeetSubLattice. *) (* joinSubLattice d T P d' == join of latticeType d' and subType *) (* (P : pred T) such that val is monotonic and *) (* a morphism for join *) (* The HB class is called JoinSubLattice. *) (* subLattice d T P d' == join of JoinSubLattice and MeetSubLattice *) (* The HB class is called SubLattice. *) (* bJoinSubLattice d T P d' == join of JoinSubLattice and BLattice *) (* such that val is a morphism for \bot *) (* The HB class is called BJoinSubLattice. *) (* tMeetSubLattice d T P d' == join of MeetSubLattice and TLattice *) (* such that val is a morphism for \top *) (* The HB class is called TMeetSubLattice. *) (* bSubLattice d T P d' == join of SubLattice and BLattice *) (* such that val is a morphism for \bot *) (* The HB class is called BSubLattice. *) (* tSubLattice d T P d' == join of SubLattice and TLattice *) (* such that val is a morphism for \top *) (* The HB class is called BSubLattice. *) (* subOrder d T P d' == join of orderType d' and *) (* subLatticeType d T P d' *) (* The HB class is called SubOrder. *) (* subPOrderLattice d T P d' == join of SubPOrder and Lattice *) (* The HB class is called SubPOrderLattice. *) (* subPOrderBLattice d T P d' == join of SubPOrder and BLattice *) (* The HB class is called SubPOrderBLattice. *) (* subPOrderTLattice d T P d' == join of SubPOrder and TLattice *) (* The HB class is called SubPOrderTLattice. *) (* subPOrderTBLattice d T P d' == join of SubPOrder and TBLattice *) (* The HB class is called SubPOrderTBLattice. *) (* meetSubBLattice d T P d' == join of MeetSubLattice and BLattice *) (* The HB class is called MeetSubBLattice. *) (* meetSubTLattice d T P d' == join of MeetSubLattice and TLattice *) (* The HB class is called MeetSubTLattice. *) (* meetSubTBLattice d T P d' == join of MeetSubLattice and TBLattice *) (* The HB class is called MeetSubTBLattice. *) (* joinSubBLattice d T P d' == join of JoinSubLattice and BLattice *) (* The HB class is called JoinSubBLattice. *) (* joinSubTLattice d T P d' == join of JoinSubLattice and TLattice *) (* The HB class is called JoinSubTLattice. *) (* joinSubTBLattice d T P d' == join of JoinSubLattice and TBLattice *) (* The HB class is called JoinSubTBLattice. *) (* subBLattice d T P d' == join of SubLattice and BLattice *) (* The HB class is called SubBLattice. *) (* subTLattice d T P d' == join of SubLattice and TLattice *) (* The HB class is called SubTLattice. *) (* subTBLattice d T P d' == join of SubLattice and TBLattice *) (* The HB class is called SubTBLattice. *) (* bJoinSubTLattice d T P d' == join of BJoinSubLattice and TBLattice *) (* The HB class is called BJoinSubTLattice. *) (* tMeetSubBLattice d T P d' == join of TMeetSubLattice and TBLattice *) (* The HB class is called TMeetSubBLattice. *) (* bSubTLattice d T P d' == join of BSubLattice and TBLattice *) (* The HB class is called BSubTLattice. *) (* tSubBLattice d T P d' == join of TSubLattice and TBLattice *) (* The HB class is called TSubBLattice. *) (* tbSubBLattice d T P d' == join of BSubLattice and TSubLattice *) (* The HB class is called TBSubLattice. *) (* *) (* Morphisms between the above structures: *) (* *) (* MeetLatticeMorphism.type d T d' T', *) (* JoinLatticeMorphism.type d T d' T', *) (* LatticeMorphism.type d T d' T' == nondecreasing function between two *) (* lattices which are morphism for meet, join, and *) (* meet/join respectively *) (* BLatticeMorphism.type d T d' T' := {blmorphism T -> T'}, *) (* TLatticeMorphism.type d T d' T' := {tlmorphism T -> T'}, *) (* TBLatticeMorphism.type d T d' T' := {tblmorphism T -> T'} *) (* == nondecreasing function between two lattices with *) (* bottom/top which are morphism for bottom/top *) (* *) (* Closedness predicates for the algebraic structures: *) (* *) (* meetLatticeClosed d T == predicate closed under meet on T : latticeType d *) (* The HB class is MeetLatticeClosed. *) (* joinLatticeClosed d T == predicate closed under join on T : latticeType d *) (* The HB class is JoinLatticeClosed. *) (* latticeClosed d T == predicate closed under meet and join *) (* The HB class is JoinLatticeClosed. *) (* bLatticeClosed d T == predicate that contains bottom *) (* The HB class is BLatticeClosed. *) (* tLatticeClosed d T == predicate that contains top *) (* The HB class is TLatticeClosed. *) (* tbLatticeClosed d T == predicate that contains top and bottom *) (* the HB class ie TBLatticeClosed. *) (* bJoinLatticeClosed d T == predicate that contains bottom and is closed *) (* under join *) (* The HB class is BJoinLatticeClosed. *) (* tMeetLatticeClosed d T == predicate that contains top and is closed under *) (* meet *) (* The HB class is TMeetLatticeClosed. *) (* *) (* * Useful lemmas: *) (* On orderType, leP, ltP, and ltgtP are the three main lemmas for case *) (* analysis. *) (* On porderType, one may use comparableP, comparable_leP, comparable_ltP, *) (* and comparable_ltgtP, which are the four main lemmas for case analysis. *) (* *) (* * Order relations and operations: *) (* In general, an overloaded relation or operation on ordered types takes the *) (* following arguments: *) (* 1. a display d of type Order.disp_t, *) (* 2. an instance T of the minimal structure it operates on, and *) (* 3. operands. *) (* Here is the exhaustive list of all such operations together with their *) (* default notation (defined in order_scope unless specified otherwise). *) (* *) (* For T of type porderType d, x and y of type T, and C of type bool: *) (* x <= y := @Order.le d T x y *) (* <-> x is less than or equal to y. *) (* x < y := @Order.lt d T x y *) (* <-> x is less than y, i.e., (y != x) && (x <= y). *) (* x >= y := y <= x *) (* <-> x is greater than or equal to y. *) (* x > y := y < x *) (* <-> x is greater than y. *) (* x >=< y := @Order.comparable d T x y (:= (x <= y) || (y <= x)) *) (* <-> x and y are comparable. *) (* x >< y := ~~ x >=< y *) (* <-> x and y are incomparable. *) (* x <= y ?= iff C := @Order.leif d T x y C (:= (x <= y) * ((x == y) = C)) *) (* <-> x is less than y, or equal iff C is true. *) (* x < y ?<= if C := @Order.lteif d T x y C (:= if C then x <= y else x < y)*) (* <-> x is smaller than y, and strictly if C is false. *) (* Order.min x y := if x < y then x else y *) (* Order.max x y := if x < y then y else x *) (* f \min g == the function x |-> Order.min (f x) (g x); *) (* f \min g simplifies on application. *) (* f \max g == the function x |-> Order.max (f x) (g x); *) (* f \max g simplifies on application. *) (* nondecreasing f <-> the function f : T -> T' is nondecreasing, *) (* where T and T' are porderType *) (* := {homo f : x y / x <= y} *) (* Unary (partially applied) versions of order notations: *) (* >= y := @Order.le d T y *) (* == a predicate characterizing elements greater than or *) (* equal to y *) (* > y := @Order.lt d T y *) (* <= y := @Order.ge d T y *) (* < y := @Order.gt d T y *) (* >=< y := [pred x | @Order.comparable d T x y] *) (* >< y := [pred x | ~~ @Order.comparable d T x y] *) (* 0-ary versions of order notations (in function_scope): *) (* <=%O := @Order.le d T *) (* <%O := @Order.lt d T *) (* >=%O := @Order.ge d T *) (* >%O := @Order.gt d T *) (* >=<%O := @Order.comparable d T *) (* <?=%O := @Order.leif d T *) (* <?<=%O := @Order.lteif d T *) (* -> These conventions are compatible with Haskell's, *) (* where ((< y) x) = (x < y) = ((<) x y), *) (* except that we write <%O instead of (<). *) (* *) (* For T of type bPOrderType d: *) (* \bot := @Order.bottom d T *) (* == the bottom element of type T *) (* \max_<range> e := \big[Order.max / Order.bottom]_<range> e *) (* == iterated max of a preorder with a bottom *) (* the possible <range>s are documented in bigop.v *) (* For T of type tPOrderType d: *) (* \top := @Order.top d T *) (* == the top element of type T *) (* \min_<range> e := \big[Order.max / Order.top]_<range> e *) (* == iterated min of a preorder with a top *) (* the possible <range>s are documented in bigop.v *) (* *) (* For T of type meetSemilatticeType d, and x, y of type T: *) (* x `&` y := @Order.meet d T x y *) (* == the meet of x and y *) (* For T of type joinSemilatticeType d, and x, y of type T: *) (* x `|` y := @Order.join d T x y *) (* == the join of x and y *) (* *) (* For T of type tMeetSemilatticeType d: *) (* \meet_<range> e := \big[Order.meet / Order.top]_<range> e *) (* == iterated meet of a meet-semilattice with a top *) (* the possible <range>s are documented in bigop.v *) (* For T of type bJoinSemilatticeType d: *) (* \join_<range> e := \big[Order.join / Order.bottom]_<range> e *) (* == iterated join of a join-semilattice with a bottom *) (* the possible <range>s are documented in bigop.v *) (* *) (* For T of type cDistrLatticeType d, and x, y, z of type T: *) (* rcompl x y z == the (relative) complement of z in [x, y] *) (* *) (* For T of type cbDistrLatticeType d, and x, y of type T: *) (* x `\` y := @Order.diff d T x y *) (* == the (sectional) complement of y in [\bot, x], *) (* i.e., rcompl \bot x y *) (* *) (* For T of type ctDistrLatticeType d, and x, y of type T: *) (* codiff x y == the (dual sectional) complement of y in [x, \top], *) (* i.e., rcompl x \top y *) (* *) (* For T of type ctbDistrLatticeType d, and x of type T: *) (* ~` x := @Order.compl d T x *) (* == the complement of x in [\bot, \top], *) (* i.e., rcompl \bot \top x *) (* *) (* For preorderType we provide the following operations: *) (* [arg min_(i < i0 | P) M] == a value i : T minimizing M : R, subject to *) (* the condition P (i may appear in P and M), and *) (* provided P holds for i0. *) (* [arg max_(i > i0 | P) M] == a value i maximizing M subject to P and *) (* provided P holds for i0. *) (* [arg min_(i < i0 in A) M] == an i \in A minimizing M if i0 \in A. *) (* [arg max_(i > i0 in A) M] == an i \in A maximizing M if i0 \in A. *) (* [arg min_(i < i0) M] == an i : T minimizing M, given i0 : T. *) (* [arg max_(i > i0) M] == an i : T maximizing M, given i0 : T. *) (* with head symbols Order.arg_min and Order.arg_max *) (* The user may use extremumP or extremum_inP to eliminate them. *) (* *) (* -> patterns for contextual rewriting: *) (* leLHS := (X in (X <= _)%O)%pattern *) (* leRHS := (X in (_ <= X)%O)%pattern *) (* ltLHS := (X in (X < _)%O)%pattern *) (* ltRHS := (X in (_ < X)%O)%pattern *) (* *) (* We provide aliases for various types and their displays: *) (* natdvd := nat (associated with display dvd_display) *) (* == an alias for nat which is canonically ordered using *) (* divisibility predicate dvdn *) (* Notation %|, %<|, gcd, lcm are used instead of *) (* <=, <, meet and join. *) (* T^d := dual T, *) (* where dual is a new definition for (fun T => T) *) (* (associated with dual_display d where d is a display) *) (* == an alias for T, such that if T is canonically *) (* ordered, then T^d is canonically ordered with the *) (* dual order, and displayed with an extra ^d in the *) (* notation, i.e., <=^d, <^d, >=<^d, ><^d, `&`^d, `|`^d *) (* are used and displayed instead of *) (* <=, <, >=<, ><, `&`, `|` *) (* T *prod[d] T' := T * T' *) (* == an alias for the cartesian product such that, *) (* if T and T' are canonically ordered, *) (* then T *prod[d] T' is canonically ordered in product *) (* order, i.e., *) (* (x1, x2) <= (y1, y2) = (x1 <= y1) && (x2 <= y2), *) (* and displayed in display d *) (* T *p T' := T *prod[prod_display d d'] T' *) (* where d and d' are the displays of T and T', *) (* respectively, and prod_display adds an extra ^p to *) (* all notations *) (* T *lexi[d] T' := T * T' *) (* == an alias for the cartesian product such that, *) (* if T and T' are canonically ordered, *) (* then T *lexi[d] T' is canonically ordered in *) (* lexicographic order, *) (* i.e., (x1, x2) <= (y1, y2) = *) (* (x1 <= y1) && ((x1 >= y1) ==> (x2 <= y2)) *) (* and (x1, x2) < (y1, y2) = *) (* (x1 <= y1) && ((x1 >= y1) ==> (x2 < y2)) *) (* and displayed in display d *) (* T *l T' := T *lexi[lexi_display d d'] T' *) (* where d and d' are the displays of T and T', *) (* respectively, and lexi_display adds an extra ^l to *) (* all notations *) (* seqprod_with d T := seq T *) (* == an alias for seq, such that if T is canonically *) (* ordered, then seqprod_with d T is canonically ordered *) (* in product order, i.e., *) (* [:: x1, .., xn] <= [y1, .., yn] = *) (* (x1 <= y1) && ... && (xn <= yn) *) (* and displayed in display d *) (* n.-tupleprod[d] T == same with n.tuple T *) (* seqprod T := seqprod_with (seqprod_display d) T *) (* where d is the display of T, and seqprod_display adds *) (* an extra ^sp to all notations *) (* n.-tupleprod T := n.-tuple[seqprod_display d] T *) (* where d is the display of T *) (* seqlexi_with d T := seq T *) (* == an alias for seq, such that if T is canonically *) (* ordered, then seqprod_with d T is canonically ordered *) (* in lexicographic order, i.e., *) (* [:: x1, .., xn] <= [y1, .., yn] = *) (* (x1 <= x2) && ((x1 >= y1) ==> ((x2 <= y2) && ...)) *) (* and displayed in display d *) (* n.-tuplelexi[d] T == same with n.tuple T *) (* seqlexi T := lexiprod_with (seqlexi_display d) T *) (* where d is the display of T, and seqlexi_display adds *) (* an extra ^sl to all notations *) (* n.-tuplelexi T := n.-tuple[seqlexi_display d] T *) (* where d is the display of T *) (* {subset[d] T} := {set T} *) (* == an alias for set which is canonically ordered by the *) (* subset order and displayed in display d *) (* {subset T} := {subset[subset_display] T} *) (* *) (* The following notations are provided to build substructures: *) (* [SubChoice_isSubPOrder of U by <: with disp] == *) (* [SubChoice_isSubPOrder of U by <:] == porderType mixin for a subType *) (* whose base type is a porderType *) (* [SubPOrder_isSubLattice of U by <: with disp] == *) (* [SubPOrder_isSubLattice of U by <:] == *) (* [SubChoice_isSubLattice of U by <: with disp] == *) (* [SubChoice_isSubLattice of U by <:] == latticeType mixin for a subType *) (* whose base type is a latticeType and whose *) (* predicate is a latticeClosed *) (* [SubPOrder_isBSubLattice of U by <: with disp] == *) (* [SubPOrder_isBSubLattice of U by <:] == *) (* [SubChoice_isBSubLattice of U by <: with disp] == *) (* [SubChoice_isBSubLattice of U by <:] == blatticeType mixin for a subType *) (* whose base type is a blatticeType and whose *) (* predicate is both a latticeClosed *) (* and a bLatticeClosed *) (* [SubPOrder_isTSubLattice of U by <: with disp] == *) (* [SubPOrder_isTSubLattice of U by <:] == *) (* [SubChoice_isTSubLattice of U by <: with disp] == *) (* [SubChoice_isTSubLattice of U by <:] == tlatticeType mixin for a subType *) (* whose base type is a tlatticeType and whose *) (* predicate is both a latticeClosed *) (* and a tLatticeClosed *) (* [SubPOrder_isTBSubLattice of U by <: with disp] == *) (* [SubPOrder_isTBSubLattice of U by <:] == *) (* [SubChoice_isTBSubLattice of U by <: with disp] == *) (* [SubChoice_isTBSubLattice of U by <:] == tblatticeType mixin for a subType *) (* whose base type is a tblatticeType and whose *) (* predicate is both a latticeClosed *) (* and a tbLatticeClosed *) (* [SubLattice_isSubOrder of U by <: with disp] == *) (* [SubLattice_isSubOrder of U by <:] == *) (* [SubPOrder_isSubOrder of U by <: with disp] == *) (* [SubPOrder_isSubOrder of U by <:] == *) (* [SubChoice_isSubOrder of U by <: with disp] == *) (* [SubChoice_isSubOrder of U by <:] == orderType mixin for a subType whose *) (* base type is an orderType *) (* [POrder of U by <:] == porderType mixin for a subType whose base type is *) (* a porderType *) (* [Order of U by <:] == orderType mixin for a subType whose base type is *) (* an orderType *) (* *) (* We provide expected instances of ordered types for bool, nat (for leq and *) (* and dvdn), 'I_n, 'I_n.+1 (with a top and bottom), nat for dvdn, *) (* T *prod[disp] T', T *lexi[disp] T', {t : T & T' x} (with lexicographic *) (* ordering), seqprod_with d T (using product order), seqlexi_with d T *) (* (with lexicographic ordering), n.-tupleprod[disp] (using product order), *) (* n.-tuplelexi[d] T (with lexicographic ordering), on {subset[disp] T} *) (* (using subset order) and all possible finite type instances. *) (* (Use `HB.about type` to discover the instances on type.) *) (* *) (* In order to get a canonical order on prod, seq, tuple or set, one may *) (* import modules DefaultProdOrder or DefaultProdLexiOrder, *) (* DefaultSeqProdOrder or DefaultSeqLexiOrder, *) (* DefaultTupleProdOrder or DefaultTupleLexiOrder, *) (* and DefaultSetSubsetOrder. *) (* *) (* We also provide specialized versions of some theorems from path.v. *) (* *) (* We provide Order.enum_val, Order.enum_rank, and Order.enum_rank_in, which *) (* are monotonic variations of enum_val, enum_rank, and enum_rank_in *) (* whenever the type is porderType, and their monotonicity is provided if *) (* this order is total. The theory is in the module Order (Order.enum_valK, *) (* Order.enum_rank_inK, etc) but Order.Enum can be imported to shorten these. *) (* *) (* We provide an opaque monotonous bijection tagnat.sig / tagnat.rank between *) (* the finite types {i : 'I_n & 'I_(p_ i)} and 'I_(\sum_i p_ i): *) (* tagnat.sig : 'I_(\sum_i p_ i) -> {i : 'I_n & 'I_(p_ i)} *) (* tagnat.rank : {i : 'I_n & 'I_(p_ i)} -> 'I_(\sum_i p_ i) *) (* tagnat.sig1 : 'I_(\sum_i p_ i) -> 'I_n *) (* tagnat.sig2 : forall p : 'I_(\sum_i p_ i), 'I_(p_ (tagnat.sig1 p)) *) (* tagnat.Rank : forall i, 'I_(p_ i) -> 'I_(\sum_i p_ i) *) (* *) (* Acknowledgments: This file is based on prior work by D. Dreyer, G. *) (* Gonthier, A. Nanevski, P-Y Strub, B. Ziliani *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope order_scope. Delimit Scope order_scope with O. Local Open Scope order_scope. (* Reserved notations for lattice operations *) Reserved Notation "A `&` B" (at level 48, left associativity). Reserved Notation "A `|` B" (at level 52, left associativity). Reserved Notation "A `\` B" (at level 50, left associativity). Reserved Notation "~` A" (at level 35, right associativity). (* Reserved notations for dual order *) Reserved Notation "A `&^d` B" (at level 48, left associativity). Reserved Notation "A `|^d` B" (at level 52, left associativity). Reserved Notation "A `\^d` B" (at level 50, left associativity). Reserved Notation "~^d` A" (at level 35, right associativity). (* Reserved notations for product ordering of prod *) Reserved Notation "A `&^p` B" (at level 48, left associativity). Reserved Notation "A `|^p` B" (at level 52, left associativity). Reserved Notation "A `\^p` B" (at level 50, left associativity). Reserved Notation "~^p` A" (at level 35, right associativity). (* Reserved notations for product ordering of seq *) Reserved Notation "A `&^sp` B" (at level 48, left associativity). Reserved Notation "A `|^sp` B" (at level 52, left associativity). Reserved Notation "A `\^sp` B" (at level 50, left associativity). Reserved Notation "~^sp` A" (at level 35, right associativity). (* Reserved notations for lexicographic ordering of prod *) Reserved Notation "A `&^l` B" (at level 48, left associativity). Reserved Notation "A `|^l` B" (at level 52, left associativity). Reserved Notation "A `\^l` B" (at level 50, left associativity). Reserved Notation "~^l` A" (at level 35, right associativity). (* Reserved notations for lexicographic ordering of seq *) Reserved Notation "A `&^sl` B" (at level 48, left associativity). Reserved Notation "A `|^sl` B" (at level 52, left associativity). Reserved Notation "A `\^sl` B" (at level 50, left associativity). Reserved Notation "~^sl` A" (at level 35, right associativity). (* Reserved notations for divisibility *) Reserved Notation "\gcd_ i F" (at level 34, F at level 41, i at level 0, format "'[' \gcd_ i '/ ' F ']'"). Reserved Notation "\gcd_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \gcd_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\gcd_ ( i <- r ) F" (F at level 41, format "'[' \gcd_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\gcd_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \gcd_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\gcd_ ( m <= i < n ) F" (F at level 41, format "'[' \gcd_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\gcd_ ( i | P ) F" (F at level 41, format "'[' \gcd_ ( i | P ) '/ ' F ']'"). Reserved Notation "\gcd_ ( i : t | P ) F" (F at level 41). Reserved Notation "\gcd_ ( i : t ) F" (F at level 41). Reserved Notation "\gcd_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \gcd_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\gcd_ ( i < n ) F" (F at level 41, format "'[' \gcd_ ( i < n ) F ']'"). Reserved Notation "\gcd_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \gcd_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\gcd_ ( i 'in' A ) F" (F at level 41, format "'[' \gcd_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\lcm_ i F" (at level 34, F at level 41, i at level 0, format "'[' \lcm_ i '/ ' F ']'"). Reserved Notation "\lcm_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \lcm_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\lcm_ ( i <- r ) F" (F at level 41, format "'[' \lcm_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\lcm_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \lcm_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\lcm_ ( m <= i < n ) F" (F at level 41, format "'[' \lcm_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\lcm_ ( i | P ) F" (F at level 41, format "'[' \lcm_ ( i | P ) '/ ' F ']'"). Reserved Notation "\lcm_ ( i : t | P ) F" (F at level 41). Reserved Notation "\lcm_ ( i : t ) F" (F at level 41). Reserved Notation "\lcm_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \lcm_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\lcm_ ( i < n ) F" (F at level 41, format "'[' \lcm_ ( i < n ) F ']'"). Reserved Notation "\lcm_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \lcm_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\lcm_ ( i 'in' A ) F" (F at level 41, format "'[' \lcm_ ( i 'in' A ) '/ ' F ']'"). (* Reserved notations for iterative meet and join *) Reserved Notation "\meet_ i F" (at level 34, F at level 41, i at level 0, format "'[' \meet_ i '/ ' F ']'"). Reserved Notation "\meet_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \meet_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\meet_ ( i <- r ) F" (F at level 41, format "'[' \meet_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\meet_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \meet_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\meet_ ( m <= i < n ) F" (F at level 41, format "'[' \meet_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\meet_ ( i | P ) F" (F at level 41, format "'[' \meet_ ( i | P ) '/ ' F ']'"). Reserved Notation "\meet_ ( i : t | P ) F" (F at level 41). Reserved Notation "\meet_ ( i : t ) F" (F at level 41). Reserved Notation "\meet_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \meet_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\meet_ ( i < n ) F" (F at level 41, format "'[' \meet_ ( i < n ) F ']'"). Reserved Notation "\meet_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \meet_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\meet_ ( i 'in' A ) F" (F at level 41, format "'[' \meet_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\join_ i F" (at level 34, F at level 41, i at level 0, format "'[' \join_ i '/ ' F ']'"). Reserved Notation "\join_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \join_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\join_ ( i <- r ) F" (F at level 41, format "'[' \join_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\join_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \join_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\join_ ( m <= i < n ) F" (F at level 41, format "'[' \join_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\join_ ( i | P ) F" (F at level 41, format "'[' \join_ ( i | P ) '/ ' F ']'"). Reserved Notation "\join_ ( i : t | P ) F" (F at level 41). Reserved Notation "\join_ ( i : t ) F" (F at level 41). Reserved Notation "\join_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \join_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\join_ ( i < n ) F" (F at level 41, format "'[' \join_ ( i < n ) F ']'"). Reserved Notation "\join_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \join_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\join_ ( i 'in' A ) F" (F at level 41, format "'[' \join_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\meet^d_ i F" (at level 34, F at level 41, i at level 0, format "'[' \meet^d_ i '/ ' F ']'"). Reserved Notation "\meet^d_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \meet^d_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\meet^d_ ( i <- r ) F" (F at level 41, format "'[' \meet^d_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\meet^d_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \meet^d_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\meet^d_ ( m <= i < n ) F" (F at level 41, format "'[' \meet^d_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\meet^d_ ( i | P ) F" (F at level 41, format "'[' \meet^d_ ( i | P ) '/ ' F ']'"). Reserved Notation "\meet^d_ ( i : t | P ) F" (F at level 41). Reserved Notation "\meet^d_ ( i : t ) F" (F at level 41). Reserved Notation "\meet^d_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \meet^d_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\meet^d_ ( i < n ) F" (F at level 41, format "'[' \meet^d_ ( i < n ) F ']'"). Reserved Notation "\meet^d_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \meet^d_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\meet^d_ ( i 'in' A ) F" (F at level 41, format "'[' \meet^d_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\join^d_ i F" (at level 34, F at level 41, i at level 0, format "'[' \join^d_ i '/ ' F ']'"). Reserved Notation "\join^d_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \join^d_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\join^d_ ( i <- r ) F" (F at level 41, format "'[' \join^d_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\join^d_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \join^d_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\join^d_ ( m <= i < n ) F" (F at level 41, format "'[' \join^d_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\join^d_ ( i | P ) F" (F at level 41, format "'[' \join^d_ ( i | P ) '/ ' F ']'"). Reserved Notation "\join^d_ ( i : t | P ) F" (F at level 41). Reserved Notation "\join^d_ ( i : t ) F" (F at level 41). Reserved Notation "\join^d_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \join^d_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\join^d_ ( i < n ) F" (F at level 41, format "'[' \join^d_ ( i < n ) F ']'"). Reserved Notation "\join^d_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \join^d_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\join^d_ ( i 'in' A ) F" (F at level 41, format "'[' \join^d_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\meet^p_ i F" (at level 34, F at level 41, i at level 0, format "'[' \meet^p_ i '/ ' F ']'"). Reserved Notation "\meet^p_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \meet^p_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\meet^p_ ( i <- r ) F" (F at level 41, format "'[' \meet^p_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\meet^p_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \meet^p_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\meet^p_ ( m <= i < n ) F" (F at level 41, format "'[' \meet^p_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\meet^p_ ( i | P ) F" (F at level 41, format "'[' \meet^p_ ( i | P ) '/ ' F ']'"). Reserved Notation "\meet^p_ ( i : t | P ) F" (F at level 41). Reserved Notation "\meet^p_ ( i : t ) F" (F at level 41). Reserved Notation "\meet^p_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \meet^p_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\meet^p_ ( i < n ) F" (F at level 41, format "'[' \meet^p_ ( i < n ) F ']'"). Reserved Notation "\meet^p_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \meet^p_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\meet^p_ ( i 'in' A ) F" (F at level 41, format "'[' \meet^p_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\join^p_ i F" (at level 34, F at level 41, i at level 0, format "'[' \join^p_ i '/ ' F ']'"). Reserved Notation "\join^p_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \join^p_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\join^p_ ( i <- r ) F" (F at level 41, format "'[' \join^p_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\join^p_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \join^p_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\join^p_ ( m <= i < n ) F" (F at level 41, format "'[' \join^p_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\join^p_ ( i | P ) F" (F at level 41, format "'[' \join^p_ ( i | P ) '/ ' F ']'"). Reserved Notation "\join^p_ ( i : t | P ) F" (F at level 41). Reserved Notation "\join^p_ ( i : t ) F" (F at level 41). Reserved Notation "\join^p_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \join^p_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\join^p_ ( i < n ) F" (F at level 41, format "'[' \join^p_ ( i < n ) F ']'"). Reserved Notation "\join^p_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \join^p_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\join^p_ ( i 'in' A ) F" (F at level 41, format "'[' \join^p_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\min^p_ i F" (at level 34, F at level 41, i at level 0, format "'[' \min^p_ i '/ ' F ']'"). Reserved Notation "\min^p_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \min^p_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\min^p_ ( i <- r ) F" (F at level 41, format "'[' \min^p_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\min^p_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \min^p_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\min^p_ ( m <= i < n ) F" (F at level 41, format "'[' \min^p_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\min^p_ ( i | P ) F" (F at level 41, format "'[' \min^p_ ( i | P ) '/ ' F ']'"). Reserved Notation "\min^p_ ( i : t | P ) F" (F at level 41). Reserved Notation "\min^p_ ( i : t ) F" (F at level 41). Reserved Notation "\min^p_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \min^p_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\min^p_ ( i < n ) F" (F at level 41, format "'[' \min^p_ ( i < n ) F ']'"). Reserved Notation "\min^p_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \min^p_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\min^p_ ( i 'in' A ) F" (F at level 41, format "'[' \min^p_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\max^p_ i F" (at level 34, F at level 41, i at level 0, format "'[' \max^p_ i '/ ' F ']'"). Reserved Notation "\max^p_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \max^p_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\max^p_ ( i <- r ) F" (F at level 41, format "'[' \max^p_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\max^p_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \max^p_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\max^p_ ( m <= i < n ) F" (F at level 41, format "'[' \max^p_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\max^p_ ( i | P ) F" (F at level 41, format "'[' \max^p_ ( i | P ) '/ ' F ']'"). Reserved Notation "\max^p_ ( i : t | P ) F" (F at level 41). Reserved Notation "\max^p_ ( i : t ) F" (F at level 41). Reserved Notation "\max^p_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \max^p_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\max^p_ ( i < n ) F" (F at level 41, format "'[' \max^p_ ( i < n ) F ']'"). Reserved Notation "\max^p_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \max^p_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\max^p_ ( i 'in' A ) F" (F at level 41, format "'[' \max^p_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\meet^sp_ i F" (at level 34, F at level 41, i at level 0, format "'[' \meet^sp_ i '/ ' F ']'"). Reserved Notation "\meet^sp_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \meet^sp_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\meet^sp_ ( i <- r ) F" (F at level 41, format "'[' \meet^sp_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\meet^sp_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \meet^sp_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\meet^sp_ ( m <= i < n ) F" (F at level 41, format "'[' \meet^sp_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\meet^sp_ ( i | P ) F" (F at level 41, format "'[' \meet^sp_ ( i | P ) '/ ' F ']'"). Reserved Notation "\meet^sp_ ( i : t | P ) F" (F at level 41). Reserved Notation "\meet^sp_ ( i : t ) F" (F at level 41). Reserved Notation "\meet^sp_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \meet^sp_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\meet^sp_ ( i < n ) F" (F at level 41, format "'[' \meet^sp_ ( i < n ) F ']'"). Reserved Notation "\meet^sp_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \meet^sp_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\meet^sp_ ( i 'in' A ) F" (F at level 41, format "'[' \meet^sp_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\join^sp_ i F" (at level 34, F at level 41, i at level 0, format "'[' \join^sp_ i '/ ' F ']'"). Reserved Notation "\join^sp_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \join^sp_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\join^sp_ ( i <- r ) F" (F at level 41, format "'[' \join^sp_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\join^sp_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \join^sp_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\join^sp_ ( m <= i < n ) F" (F at level 41, format "'[' \join^sp_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\join^sp_ ( i | P ) F" (F at level 41, format "'[' \join^sp_ ( i | P ) '/ ' F ']'"). Reserved Notation "\join^sp_ ( i : t | P ) F" (F at level 41). Reserved Notation "\join^sp_ ( i : t ) F" (F at level 41). Reserved Notation "\join^sp_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \join^sp_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\join^sp_ ( i < n ) F" (F at level 41, format "'[' \join^sp_ ( i < n ) F ']'"). Reserved Notation "\join^sp_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \join^sp_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\join^sp_ ( i 'in' A ) F" (F at level 41, format "'[' \join^sp_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\min^sp_ i F" (at level 34, F at level 41, i at level 0, format "'[' \min^sp_ i '/ ' F ']'"). Reserved Notation "\min^sp_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \min^sp_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\min^sp_ ( i <- r ) F" (F at level 41, format "'[' \min^sp_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\min^sp_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \min^sp_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\min^sp_ ( m <= i < n ) F" (F at level 41, format "'[' \min^sp_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\min^sp_ ( i | P ) F" (F at level 41, format "'[' \min^sp_ ( i | P ) '/ ' F ']'"). Reserved Notation "\min^sp_ ( i : t | P ) F" (F at level 41). Reserved Notation "\min^sp_ ( i : t ) F" (F at level 41). Reserved Notation "\min^sp_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \min^sp_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\min^sp_ ( i < n ) F" (F at level 41, format "'[' \min^sp_ ( i < n ) F ']'"). Reserved Notation "\min^sp_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \min^sp_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\min^sp_ ( i 'in' A ) F" (F at level 41, format "'[' \min^sp_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\max^sp_ i F" (at level 34, F at level 41, i at level 0, format "'[' \max^sp_ i '/ ' F ']'"). Reserved Notation "\max^sp_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \max^sp_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\max^sp_ ( i <- r ) F" (F at level 41, format "'[' \max^sp_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\max^sp_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \max^sp_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\max^sp_ ( m <= i < n ) F" (F at level 41, format "'[' \max^sp_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\max^sp_ ( i | P ) F" (F at level 41, format "'[' \max^sp_ ( i | P ) '/ ' F ']'"). Reserved Notation "\max^sp_ ( i : t | P ) F" (F at level 41). Reserved Notation "\max^sp_ ( i : t ) F" (F at level 41). Reserved Notation "\max^sp_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \max^sp_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\max^sp_ ( i < n ) F" (F at level 41, format "'[' \max^sp_ ( i < n ) F ']'"). Reserved Notation "\max^sp_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \max^sp_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\max^sp_ ( i 'in' A ) F" (F at level 41, format "'[' \max^sp_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\meet^l_ i F" (at level 34, F at level 41, i at level 0, format "'[' \meet^l_ i '/ ' F ']'"). Reserved Notation "\meet^l_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \meet^l_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\meet^l_ ( i <- r ) F" (F at level 41, format "'[' \meet^l_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\meet^l_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \meet^l_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\meet^l_ ( m <= i < n ) F" (F at level 41, format "'[' \meet^l_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\meet^l_ ( i | P ) F" (F at level 41, format "'[' \meet^l_ ( i | P ) '/ ' F ']'"). Reserved Notation "\meet^l_ ( i : t | P ) F" (F at level 41). Reserved Notation "\meet^l_ ( i : t ) F" (F at level 41). Reserved Notation "\meet^l_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \meet^l_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\meet^l_ ( i < n ) F" (F at level 41, format "'[' \meet^l_ ( i < n ) F ']'"). Reserved Notation "\meet^l_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \meet^l_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\meet^l_ ( i 'in' A ) F" (F at level 41, format "'[' \meet^l_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\join^l_ i F" (at level 34, F at level 41, i at level 0, format "'[' \join^l_ i '/ ' F ']'"). Reserved Notation "\join^l_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \join^l_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\join^l_ ( i <- r ) F" (F at level 41, format "'[' \join^l_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\join^l_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \join^l_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\join^l_ ( m <= i < n ) F" (F at level 41, format "'[' \join^l_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\join^l_ ( i | P ) F" (F at level 41, format "'[' \join^l_ ( i | P ) '/ ' F ']'"). Reserved Notation "\join^l_ ( i : t | P ) F" (F at level 41). Reserved Notation "\join^l_ ( i : t ) F" (F at level 41). Reserved Notation "\join^l_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \join^l_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\join^l_ ( i < n ) F" (F at level 41, format "'[' \join^l_ ( i < n ) F ']'"). Reserved Notation "\join^l_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \join^l_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\join^l_ ( i 'in' A ) F" (F at level 41, format "'[' \join^l_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\min^l_ i F" (at level 34, F at level 41, i at level 0, format "'[' \min^l_ i '/ ' F ']'"). Reserved Notation "\min^l_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \min^l_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\min^l_ ( i <- r ) F" (F at level 41, format "'[' \min^l_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\min^l_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \min^l_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\min^l_ ( m <= i < n ) F" (F at level 41, format "'[' \min^l_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\min^l_ ( i | P ) F" (F at level 41, format "'[' \min^l_ ( i | P ) '/ ' F ']'"). Reserved Notation "\min^l_ ( i : t | P ) F" (F at level 41). Reserved Notation "\min^l_ ( i : t ) F" (F at level 41). Reserved Notation "\min^l_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \min^l_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\min^l_ ( i < n ) F" (F at level 41, format "'[' \min^l_ ( i < n ) F ']'"). Reserved Notation "\min^l_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \min^l_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\min^l_ ( i 'in' A ) F" (F at level 41, format "'[' \min^l_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\max^l_ i F" (at level 34, F at level 41, i at level 0, format "'[' \max^l_ i '/ ' F ']'"). Reserved Notation "\max^l_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \max^l_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\max^l_ ( i <- r ) F" (F at level 41, format "'[' \max^l_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\max^l_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \max^l_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\max^l_ ( m <= i < n ) F" (F at level 41, format "'[' \max^l_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\max^l_ ( i | P ) F" (F at level 41, format "'[' \max^l_ ( i | P ) '/ ' F ']'"). Reserved Notation "\max^l_ ( i : t | P ) F" (F at level 41). Reserved Notation "\max^l_ ( i : t ) F" (F at level 41). Reserved Notation "\max^l_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \max^l_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\max^l_ ( i < n ) F" (F at level 41, format "'[' \max^l_ ( i < n ) F ']'"). Reserved Notation "\max^l_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \max^l_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\max^l_ ( i 'in' A ) F" (F at level 41, format "'[' \max^l_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "'{' 'omorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'omorphism' U -> V }"). Reserved Notation "'{' 'mlmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'mlmorphism' U -> V }"). Reserved Notation "'{' 'jlmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'jlmorphism' U -> V }"). Reserved Notation "'{' 'lmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'lmorphism' U -> V }"). Reserved Notation "'{' 'blmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'blmorphism' U -> V }"). Reserved Notation "'{' 'tlmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'tlmorphism' U -> V }"). Reserved Notation "'{' 'tblmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'tblmorphism' U -> V }"). Module Order. Export Order. #[key="T", primitive] HB.mixin Record Preorder_isDuallyPOrder (d : disp_t) T of Preorder d T := { le_anti : antisymmetric (@le d T); ge_anti : antisymmetric (fun x y => @le d T y x); }. #[short(type="porderType")] HB.structure Definition POrder (d : disp_t) := { T of Preorder d T & Preorder_isDuallyPOrder d T }. #[short(type="bPOrderType")] HB.structure Definition BPOrder d := { T of hasBottom d T & POrder d T }. #[short(type="tPOrderType")] HB.structure Definition TPOrder d := { T of hasTop d T & POrder d T }. #[short(type="tbPOrderType")] HB.structure Definition TBPOrder d := { T of hasTop d T & BPOrder d T }. Module POrderExports. Arguments le_trans {d s} [_ _ _]. End POrderExports. HB.export POrderExports. (* Bind Scope order_scope with POrder.sort. *) #[key="T", primitive] HB.mixin Record POrder_isMeetSemilattice d (T : Type) of POrder d T := { meet : T -> T -> T; lexI : forall x y z, (x <= meet y z) = (x <= y) && (x <= z); }. #[key="T", primitive] HB.mixin Record POrder_isJoinSemilattice d T of POrder d T := { join : T -> T -> T; leUx : forall x y z, (join x y <= z) = (x <= z) && (y <= z); }. #[short(type="meetSemilatticeType")] HB.structure Definition MeetSemilattice d := { T of POrder d T & POrder_isMeetSemilattice d T }. #[short(type="bMeetSemilatticeType")] HB.structure Definition BMeetSemilattice d := { T of MeetSemilattice d T & hasBottom d T }. #[short(type="tMeetSemilatticeType")] HB.structure Definition TMeetSemilattice d := { T of MeetSemilattice d T & hasTop d T }. #[short(type="tbMeetSemilatticeType")] HB.structure Definition TBMeetSemilattice d := { T of BMeetSemilattice d T & hasTop d T }. #[short(type="joinSemilatticeType")] HB.structure Definition JoinSemilattice d := { T of POrder d T & POrder_isJoinSemilattice d T }. #[short(type="bJoinSemilatticeType")] HB.structure Definition BJoinSemilattice d := { T of JoinSemilattice d T & hasBottom d T }. #[short(type="tJoinSemilatticeType")] HB.structure Definition TJoinSemilattice d := { T of JoinSemilattice d T & hasTop d T }. #[short(type="tbJoinSemilatticeType")] HB.structure Definition TBJoinSemilattice d := { T of BJoinSemilattice d T & hasTop d T }. #[short(type="latticeType")] HB.structure Definition Lattice d := { T of JoinSemilattice d T & POrder_isMeetSemilattice d T }. #[short(type="bLatticeType")] HB.structure Definition BLattice d := { T of Lattice d T & hasBottom d T }. #[short(type="tLatticeType")] HB.structure Definition TLattice d := { T of Lattice d T & hasTop d T }. #[short(type="tbLatticeType")] HB.structure Definition TBLattice d := { T of BLattice d T & hasTop d T }. Section LatticeDef. Context {disp : disp_t} {T : latticeType disp}. Variant lel_xor_gt (x y : T) : T -> T -> T -> T -> T -> T -> T -> T -> bool -> bool -> Set := | LelNotGt of x <= y : lel_xor_gt x y x x y y x x y y true false | GtlNotLe of y < x : lel_xor_gt x y y y x x y y x x false true. Variant ltl_xor_ge (x y : T) : T -> T -> T -> T -> T -> T -> T -> T -> bool -> bool -> Set := | LtlNotGe of x < y : ltl_xor_ge x y x x y y x x y y false true | GelNotLt of y <= x : ltl_xor_ge x y y y x x y y x x true false. Variant comparel (x y : T) : T -> T -> T -> T -> T -> T -> T -> T -> bool -> bool -> bool -> bool -> bool -> bool -> Set := | ComparelLt of x < y : comparel x y x x y y x x y y false false false true false true | ComparelGt of y < x : comparel x y y y x x y y x x false false true false true false | ComparelEq of x = y : comparel x y x x x x x x x x true true true true false false. Variant incomparel (x y : T) : T -> T -> T -> T -> T -> T -> T -> T -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> Set := | InComparelLt of x < y : incomparel x y x x y y x x y y false false false true false true true true | InComparelGt of y < x : incomparel x y y y x x y y x x false false true false true false true true | InComparel of x >< y : incomparel x y x y y x (meet y x) (meet x y) (join y x) (join x y) false false false false false false false false | InComparelEq of x = y : incomparel x y x x x x x x x x true true true true false false true true. End LatticeDef. Module LatticeSyntax. Notation "x `&` y" := (meet x y) : order_scope. Notation "x `|` y" := (join x y) : order_scope. End LatticeSyntax. HB.export LatticeSyntax. Module BLatticeSyntax. Notation "\join_ ( i <- r | P ) F" := (\big[@join _ _ / \bot]_(i <- r | P%B) F%O) : order_scope. Notation "\join_ ( i <- r ) F" := (\big[@join _ _ / \bot]_(i <- r) F%O) : order_scope. Notation "\join_ ( i | P ) F" := (\big[@join _ _ / \bot]_(i | P%B) F%O) : order_scope. Notation "\join_ i F" := (\big[@join _ _ / \bot]_i F%O) : order_scope. Notation "\join_ ( i : I | P ) F" := (\big[@join _ _ / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\join_ ( i : I ) F" := (\big[@join _ _ / \bot]_(i : I) F%O) (only parsing) : order_scope. Notation "\join_ ( m <= i < n | P ) F" := (\big[@join _ _ / \bot]_(m <= i < n | P%B) F%O) : order_scope. Notation "\join_ ( m <= i < n ) F" := (\big[@join _ _ / \bot]_(m <= i < n) F%O) : order_scope. Notation "\join_ ( i < n | P ) F" := (\big[@join _ _ / \bot]_(i < n | P%B) F%O) : order_scope. Notation "\join_ ( i < n ) F" := (\big[@join _ _ / \bot]_(i < n) F%O) : order_scope. Notation "\join_ ( i 'in' A | P ) F" := (\big[@join _ _ / \bot]_(i in A | P%B) F%O) : order_scope. Notation "\join_ ( i 'in' A ) F" := (\big[@join _ _ / \bot]_(i in A) F%O) : order_scope. End BLatticeSyntax. HB.export BLatticeSyntax. Module TLatticeSyntax. Notation "\meet_ ( i <- r | P ) F" := (\big[meet / \top]_(i <- r | P%B) F%O) : order_scope. Notation "\meet_ ( i <- r ) F" := (\big[meet / \top]_(i <- r) F%O) : order_scope. Notation "\meet_ ( i | P ) F" := (\big[meet / \top]_(i | P%B) F%O) : order_scope. Notation "\meet_ i F" := (\big[meet / \top]_i F%O) : order_scope. Notation "\meet_ ( i : I | P ) F" := (\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\meet_ ( i : I ) F" := (\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope. Notation "\meet_ ( m <= i < n | P ) F" := (\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\meet_ ( m <= i < n ) F" := (\big[meet / \top]_(m <= i < n) F%O) : order_scope. Notation "\meet_ ( i < n | P ) F" := (\big[meet / \top]_(i < n | P%B) F%O) : order_scope. Notation "\meet_ ( i < n ) F" := (\big[meet / \top]_(i < n) F%O) : order_scope. Notation "\meet_ ( i 'in' A | P ) F" := (\big[meet / \top]_(i in A | P%B) F%O) : order_scope. Notation "\meet_ ( i 'in' A ) F" := (\big[meet / \top]_(i in A) F%O) : order_scope. End TLatticeSyntax. HB.export TLatticeSyntax. #[key="T", primitive] HB.mixin Record Lattice_isDistributive d (T : Type) of Lattice d T := { meetUl : @left_distributive T T meet join; joinIl : @left_distributive T T join meet; (* dual of meetUl *) }. #[short(type="distrLatticeType")] HB.structure Definition DistrLattice d := { T of Lattice_isDistributive d T & Lattice d T }. #[short(type="bDistrLatticeType")] HB.structure Definition BDistrLattice d := { T of DistrLattice d T & hasBottom d T }. #[short(type="tDistrLatticeType")] HB.structure Definition TDistrLattice d := { T of DistrLattice d T & hasTop d T }. #[short(type="tbDistrLatticeType")] HB.structure Definition TBDistrLattice d := { T of BDistrLattice d T & hasTop d T }. #[key="T", primitive] HB.mixin Record DistrLattice_isTotal d T of DistrLattice d T := { le_total : total (<=%O : rel T) }. #[short(type="orderType")] HB.structure Definition Total d := { T of DistrLattice_isTotal d T & DistrLattice d T }. #[short(type="bOrderType")] HB.structure Definition BTotal d := { T of Total d T & hasBottom d T }. #[short(type="tOrderType")] HB.structure Definition TTotal d := { T of Total d T & hasTop d T }. #[short(type="tbOrderType")] HB.structure Definition TBTotal d := { T of BTotal d T & hasTop d T }. #[key="T", primitive] HB.mixin Record DistrLattice_hasRelativeComplement d T of DistrLattice d T := { (* rcompl x y z is the complement of z in the interval [x, y]. *) rcompl : T -> T -> T -> T; rcomplPmeet : forall x y z, ((x `&` y) `|` z) `&` rcompl x y z = x `&` y; rcomplPjoin : forall x y z, ((y `|` x) `&` z) `|` rcompl x y z = y `|` x; }. #[short(type="cDistrLatticeType")] HB.structure Definition CDistrLattice d := { T of DistrLattice d T & DistrLattice_hasRelativeComplement d T }. #[key="T", primitive] HB.mixin Record CDistrLattice_hasSectionalComplement d T of CDistrLattice d T & hasBottom d T := { diff : T -> T -> T; (* FIXME: a bug in HB prevents us writing "rcompl \bot x y" *) diffErcompl : forall x y, diff x y = rcompl (\bot : T) x y; }. #[short(type="cbDistrLatticeType")] HB.structure Definition CBDistrLattice d := { T of CDistrLattice d T & hasBottom d T & CDistrLattice_hasSectionalComplement d T }. #[key="T", primitive] HB.mixin Record CDistrLattice_hasDualSectionalComplement d T of CDistrLattice d T & hasTop d T := { codiff : T -> T -> T; codiffErcompl : forall x y, codiff x y = rcompl x \top y; }. #[short(type="ctDistrLatticeType")] HB.structure Definition CTDistrLattice d := { T of CDistrLattice d T & hasTop d T & CDistrLattice_hasDualSectionalComplement d T }. Module Import CBDistrLatticeSyntax. Notation "x `\` y" := (diff x y) : order_scope. End CBDistrLatticeSyntax. #[key="T", primitive] HB.mixin Record CDistrLattice_hasComplement d T of CTDistrLattice d T & CBDistrLattice d T := { compl : T -> T; (* FIXME: a bug in HB prevents us writing "\top `\` x" and "codiff \bot x" *) complEdiff : forall x : T, compl x = (\top : T) `\` x; complEcodiff : forall x : T, compl x = codiff (\bot : T) x; }. #[short(type="ctbDistrLatticeType")] HB.structure Definition CTBDistrLattice d := { T of CBDistrLattice d T & CTDistrLattice d T & CDistrLattice_hasComplement d T }. Module Import CTBDistrLatticeSyntax. Notation "~` A" := (compl A) : order_scope. End CTBDistrLatticeSyntax. (**********) (* FINITE *) (**********) #[short(type="finPOrderType")] HB.structure Definition FinPOrder d := { T of Finite T & POrder d T }. #[short(type="finBPOrderType")] HB.structure Definition FinBPOrder d := { T of FinPOrder d T & hasBottom d T }. #[short(type="finTPOrderType")] HB.structure Definition FinTPOrder d := { T of FinPOrder d T & hasTop d T }. #[short(type="finTBPOrderType")] HB.structure Definition FinTBPOrder d := { T of FinBPOrder d T & hasTop d T }. #[short(type="finMeetSemilatticeType")] HB.structure Definition FinMeetSemilattice d := { T of Finite T & MeetSemilattice d T }. #[short(type="finBMeetSemilatticeType")] HB.structure Definition FinBMeetSemilattice d := { T of Finite T & BMeetSemilattice d T }. #[short(type="finJoinSemilatticeType")] HB.structure Definition FinJoinSemilattice d := { T of Finite T & JoinSemilattice d T }. #[short(type="finTJoinSemilatticeType")] HB.structure Definition FinTJoinSemilattice d := { T of Finite T & TJoinSemilattice d T }. #[short(type="finLatticeType")] HB.structure Definition FinLattice d := { T of Finite T & Lattice d T }. #[short(type="finTBLatticeType")] HB.structure Definition FinTBLattice d := { T of Finite T & TBLattice d T }. #[short(type="finDistrLatticeType")] HB.structure Definition FinDistrLattice d := { T of Finite T & DistrLattice d T }. #[short(type="finTBDistrLatticeType")] HB.structure Definition FinTBDistrLattice d := { T of Finite T & TBDistrLattice d T }. #[short(type="finOrderType")] HB.structure Definition FinTotal d := { T of Finite T & Total d T }. #[short(type="finTBOrderType")] HB.structure Definition FinTBTotal d := { T of Finite T & TBTotal d T }. #[short(type="finCDistrLatticeType")] HB.structure Definition FinCDistrLattice d := { T of Finite T & CDistrLattice d T }. #[short(type="finCTBDistrLatticeType")] HB.structure Definition FinCTBDistrLattice d := { T of Finite T & CTBDistrLattice d T }. (********) (* DUAL *) (********) Notation dual_meet := (@meet (dual_display _) _). Notation dual_join := (@join (dual_display _) _). Module Import DualSyntax. Notation "x `&^d` y" := (dual_meet x y) : order_scope. Notation "x `|^d` y" := (dual_join x y) : order_scope. (* The following Local Notations are here to define the \join^d_ and \meet^d_ *) (* notations later. Do not remove them. *) Local Notation "\bot" := dual_bottom. Local Notation "\top" := dual_top. Local Notation join := dual_join. Local Notation meet := dual_meet. Local Notation min := dual_min. Local Notation max := dual_max. Notation "\join^d_ ( i <- r | P ) F" := (\big[join / \bot]_(i <- r | P%B) F%O) : order_scope. Notation "\join^d_ ( i <- r ) F" := (\big[join / \bot]_(i <- r) F%O) : order_scope. Notation "\join^d_ ( i | P ) F" := (\big[join / \bot]_(i | P%B) F%O) : order_scope. Notation "\join^d_ i F" := (\big[join / \bot]_i F%O) : order_scope. Notation "\join^d_ ( i : I | P ) F" := (\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\join^d_ ( i : I ) F" := (\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope. Notation "\join^d_ ( m <= i < n | P ) F" := (\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope. Notation "\join^d_ ( m <= i < n ) F" := (\big[join / \bot]_(m <= i < n) F%O) : order_scope. Notation "\join^d_ ( i < n | P ) F" := (\big[join / \bot]_(i < n | P%B) F%O) : order_scope. Notation "\join^d_ ( i < n ) F" := (\big[join / \bot]_(i < n) F%O) : order_scope. Notation "\join^d_ ( i 'in' A | P ) F" := (\big[join / \bot]_(i in A | P%B) F%O) : order_scope. Notation "\join^d_ ( i 'in' A ) F" := (\big[join / \bot]_(i in A) F%O) : order_scope. Notation "\meet^d_ ( i <- r | P ) F" := (\big[meet / \top]_(i <- r | P%B) F%O) : order_scope. Notation "\meet^d_ ( i <- r ) F" := (\big[meet / \top]_(i <- r) F%O) : order_scope. Notation "\meet^d_ ( i | P ) F" := (\big[meet / \top]_(i | P%B) F%O) : order_scope. Notation "\meet^d_ i F" := (\big[meet / \top]_i F%O) : order_scope. Notation "\meet^d_ ( i : I | P ) F" := (\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\meet^d_ ( i : I ) F" := (\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope. Notation "\meet^d_ ( m <= i < n | P ) F" := (\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\meet^d_ ( m <= i < n ) F" := (\big[meet / \top]_(m <= i < n) F%O) : order_scope. Notation "\meet^d_ ( i < n | P ) F" := (\big[meet / \top]_(i < n | P%B) F%O) : order_scope. Notation "\meet^d_ ( i < n ) F" := (\big[meet / \top]_(i < n) F%O) : order_scope. Notation "\meet^d_ ( i 'in' A | P ) F" := (\big[meet / \top]_(i in A | P%B) F%O) : order_scope. Notation "\meet^d_ ( i 'in' A ) F" := (\big[meet / \top]_(i in A) F%O) : order_scope. Notation "\meet^d_ ( i <- r | P ) F" := (\big[meet / \top]_(i <- r | P%B) F%O) : order_scope. Notation "\meet^d_ ( i <- r ) F" := (\big[meet / \top]_(i <- r) F%O) : order_scope. Notation "\meet^d_ ( i | P ) F" := (\big[meet / \top]_(i | P%B) F%O) : order_scope. Notation "\meet^d_ i F" := (\big[meet / \top]_i F%O) : order_scope. Notation "\meet^d_ ( i : I | P ) F" := (\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\meet^d_ ( i : I ) F" := (\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope. Notation "\meet^d_ ( m <= i < n | P ) F" := (\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\meet^d_ ( m <= i < n ) F" := (\big[meet / \top]_(m <= i < n) F%O) : order_scope. Notation "\meet^d_ ( i < n | P ) F" := (\big[meet / \top]_(i < n | P%B) F%O) : order_scope. Notation "\meet^d_ ( i < n ) F" := (\big[meet / \top]_(i < n) F%O) : order_scope. Notation "\meet^d_ ( i 'in' A | P ) F" := (\big[meet / \top]_(i in A | P%B) F%O) : order_scope. Notation "\meet^d_ ( i 'in' A ) F" := (\big[meet / \top]_(i in A) F%O) : order_scope. Notation "\min^d_ i F" := (\big[min/top]_i F) : order_scope. Notation "\min^d_ ( i <- r | P ) F" := (\big[min/top]_(i <- r | P%B) F%O) : order_scope. Notation "\min^d_ ( i < r ) F" := (\big[min/top]_(i <- r) F%O) : order_scope. Notation "\min^d_ ( m <= i < n | P ) F" := (\big[min/top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\min^d_ ( m <= i < n ) F" := (\big[min/top]_(m <= i < n) F%O) : order_scope. Notation "\min^d_ ( i | P ) F" := (\big[min/top]_(i | P%B) F%O) : order_scope. Notation "\min^d_ ( i : t | P ) F" := (\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\min^d_ ( i : t ) F" := (\big[min/top]_(i : t) F%O) (only parsing) : order_scope. Notation "\min^d_ ( i < n | P ) F" := (\big[min/top]_(i < n | P%B) F%O) : order_scope. Notation "\min^d_ ( i < n ) F" := (\big[min/top]_(i < n) F%O) : order_scope. Notation "\min^d_ ( i 'in' A | P ) F" := (\big[min/top]_(i in A | P%B) F%O) : order_scope. Notation "\min^d_ ( i 'in' A ) F" := (\big[min/top]_(i in A) F%O) : order_scope. Notation "\max^d_ i F" := (\big[max/bottom]_i F%O) : order_scope. Notation "\max^d_ ( i <- r | P ) F" := (\big[max/bottom]_(i <- r | P%B) F%O) : order_scope. Notation "\max^d_ ( i < r ) F" := (\big[max/bottom]_(i <- r) F%O) : order_scope. Notation "\max^d_ ( m <= i < n | P ) F" := (\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope. Notation "\max^d_ ( m <= i < n ) F" := (\big[max/bottom]_(m <= i < n) F%O) : order_scope. Notation "\max^d_ ( i | P ) F" := (\big[max/bottom]_(i | P%B) F%O) : order_scope. Notation "\max^d_ ( i : t | P ) F" := (\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\max^d_ ( i : t ) F" := (\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope. Notation "\max^d_ ( i < n | P ) F" := (\big[max/bottom]_(i < n | P%B) F%O) : order_scope. Notation "\max^d_ ( i < n ) F" := (\big[max/bottom]_(i < n) F%O) : order_scope. Notation "\max^d_ ( i 'in' A | P ) F" := (\big[max/bottom]_(i in A | P%B) F%O) : order_scope. Notation "\max^d_ ( i 'in' A ) F" := (\big[max/bottom]_(i in A) F%O) : order_scope. End DualSyntax. (* FIXME: we have two issues in the dual instance declarations in the DualOrder module below: 1. HB.saturate is slow, and 2. if we declare them by HB.instance, some declarations fail because it unfolds [dual] and the generated instance does not typecheck (math-comp/hierarchy-builder#257). *) Module DualOrder. HB.instance Definition _ (d : disp_t) (T : porderType d) := Preorder_isDuallyPOrder.Build (dual_display d) T^d ge_anti le_anti. HB.instance Definition _ d (T : joinSemilatticeType d) := POrder_isMeetSemilattice.Build (dual_display d) T^d (fun x y z => leUx y z x). Lemma meetEdual d (T : joinSemilatticeType d) (x y : T) : ((x : T^d) `&^d` y) = (x `|` y). Proof. by []. Qed. HB.instance Definition _ d (T : meetSemilatticeType d) := POrder_isJoinSemilattice.Build (dual_display d) T^d (fun x y z => lexI z x y). Lemma joinEdual d (T : meetSemilatticeType d) (x y : T) : ((x : T^d) `|^d` y) = (x `&` y). Proof. by []. Qed. HB.saturate. HB.instance Definition _ d (T : distrLatticeType d) := Lattice_isDistributive.Build (dual_display d) T^d joinIl meetUl. HB.instance Definition _ d (T : orderType d) := DistrLattice_isTotal.Build (dual_display d) T^d (fun x y => le_total y x). HB.saturate. HB.instance Definition _ d (T : cDistrLatticeType d) := DistrLattice_hasRelativeComplement.Build (dual_display d) T^d (fun x y => rcomplPjoin y x) (fun x y => rcomplPmeet y x). HB.instance Definition _ d (T : ctDistrLatticeType d) := CDistrLattice_hasSectionalComplement.Build (dual_display d) T^d codiffErcompl. HB.instance Definition _ d (T : cbDistrLatticeType d) := CDistrLattice_hasDualSectionalComplement.Build (dual_display d) T^d diffErcompl. HB.instance Definition _ d (T : ctbDistrLatticeType d) := CDistrLattice_hasComplement.Build (dual_display d) T^d complEcodiff complEdiff. HB.saturate. End DualOrder. HB.export DualOrder. (**********) (* THEORY *) (**********) Module Import POrderTheory. Include PreorderTheory. Section POrderTheory. Context {disp : disp_t} {T : porderType disp}. Implicit Types (x y : T) (s : seq T). Lemma le_anti: antisymmetric (<=%O : rel T). Proof. exact: le_anti. Qed. Lemma ge_anti: antisymmetric (>=%O : rel T). Proof. by move=> x y /le_anti. Qed. Lemma eq_le x y: (x == y) = (x <= y <= x). Proof. by apply/eqP/idP => [->|/le_anti]; rewrite ?lexx. Qed. Lemma lt_def x y : (x < y) = (y != x) && (x <= y). Proof. rewrite andbC lt_le_def; case/boolP: (x <= y) => //= xy. congr negb; apply/idP/eqP => [yx|->]; last exact/lexx. by apply/le_anti; rewrite yx. Qed. Lemma lt_neqAle x y: (x < y) = (x != y) && (x <= y). Proof. by rewrite lt_def eq_sym. Qed. Lemma le_eqVlt x y: (x <= y) = (x == y) || (x < y). Proof. by rewrite lt_neqAle; case: eqP => //= ->; rewrite lexx. Qed. Definition lte_anti := (=^~ eq_le, @lt_asym disp T, @lt_le_asym disp T, @le_lt_asym disp T). Lemma lt_sorted_uniq_le s : sorted <%O s = uniq s && sorted <=%O s. Proof. rewrite le_sorted_pairwise lt_sorted_pairwise uniq_pairwise -pairwise_relI. by apply/eq_pairwise => ? ?; rewrite lt_neqAle. Qed. Lemma le_sorted_eq s1 s2 : sorted <=%O s1 -> sorted <=%O s2 -> perm_eq s1 s2 -> s1 = s2. Proof. exact/sorted_eq/le_anti/le_trans. Qed. Lemma count_lt_le_mem x s : (count (< x) s < count (<= x) s)%N = (x \in s). Proof. have := count_predUI (pred1 x) (< x) s. have -> : count (predI (pred1 x) (< x)) s = 0%N. rewrite (@eq_count _ _ pred0) ?count_pred0 // => y /=. by rewrite lt_neqAle; case: eqP => //= ->; rewrite eqxx. have /eq_count-> : [predU1 x & < x] =1 (<= x) by move=> y /=; rewrite le_eqVlt. by rewrite addn0 => ->; rewrite -add1n leq_add2r -has_count has_pred1. Qed. Lemma comparable_ltgtP x y : x >=< y -> compare x y (min y x) (min x y) (max y x) (max x y) (y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y). Proof. rewrite /min /max />=<%O !le_eqVlt [y == x]eq_sym. have := (eqVneq x y, (boolP (x < y), boolP (y < x))). move=> [[->//|neq_xy /=] [[] xy [] //=]] ; do ?by rewrite ?ltxx; constructor. by rewrite ltxx in xy. by rewrite le_gtF // ltW. Qed. Lemma comparable_leP x y : x >=< y -> le_xor_gt x y (min y x) (min x y) (max y x) (max x y) (x <= y) (y < x). Proof. by move=> /comparable_ltgtP [?|?|->]; constructor; rewrite // ltW. Qed. Lemma comparable_ltP x y : x >=< y -> lt_xor_ge x y (min y x) (min x y) (max y x) (max x y) (y <= x) (x < y). Proof. by move=> /comparable_ltgtP [?|?|->]; constructor; rewrite // ltW. Qed. Lemma comparableP x y : incompare x y (min y x) (min x y) (max y x) (max x y) (y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y) (y >=< x) (x >=< y). Proof. rewrite ![y >=< _]comparable_sym; have [c_xy|i_xy] := boolP (x >=< y). by case: (comparable_ltgtP c_xy) => ?; constructor. by rewrite /min /max ?incomparable_eqF ?incomparable_leF; rewrite ?incomparable_ltF// 1?comparable_sym //; constructor. Qed. (* leif *) Lemma leifP x y C : reflect (x <= y ?= iff C) (if C then x == y else x < y). Proof. rewrite /leif le_eqVlt; apply: (iffP idP)=> [|[]]. by case: C => [/eqP->|lxy]; rewrite ?eqxx // lxy lt_eqF. by move=> /orP[/eqP->|lxy] <-; rewrite ?eqxx // lt_eqF. Qed. Lemma leif_trans x1 x2 x3 C12 C23 : x1 <= x2 ?= iff C12 -> x2 <= x3 ?= iff C23 -> x1 <= x3 ?= iff C12 && C23. Proof. move=> ltx12 ltx23; apply/leifP; rewrite -ltx12. case eqx12: (x1 == x2). by rewrite (eqP eqx12) lt_neqAle !ltx23 andbT; case C23. by rewrite (@lt_le_trans _ _ x2) ?ltx23 // lt_neqAle eqx12 ltx12. Qed. Lemma leif_le x y : x <= y -> x <= y ?= iff (x >= y). Proof. by move=> lexy; split=> //; rewrite eq_le lexy. Qed. Lemma leif_eq x y : x <= y -> x <= y ?= iff (x == y). Proof. by []. Qed. Lemma ge_leif x y C : x <= y ?= iff C -> (y <= x) = C. Proof. by case=> le_xy; rewrite eq_le le_xy. Qed. Lemma lt_leif x y C : x <= y ?= iff C -> (x < y) = ~~ C. Proof. by move=> le_xy; rewrite lt_neqAle !le_xy andbT. Qed. Lemma ltNleif x y C : x <= y ?= iff ~~ C -> (x < y) = C. Proof. by move=> /lt_leif; rewrite negbK. Qed. (* lteif *) Lemma lteif_anti C1 C2 x y : (x < y ?<= if C1) && (y < x ?<= if C2) = C1 && C2 && (x == y). Proof. by case: C1 C2 => [][]; rewrite lte_anti. Qed. Lemma lteifN C x y : x < y ?<= if ~~ C -> ~~ (y < x ?<= if C). Proof. by case: C => /=; case: comparableP. Qed. (* min and max *) Lemma minEle x y : min x y = if x <= y then x else y. Proof. by case: comparableP. Qed. Lemma maxEle x y : max x y = if x <= y then y else x. Proof. by case: comparableP. Qed. Lemma comparable_minEgt x y : x >=< y -> min x y = if x > y then y else x. Proof. by case: comparableP. Qed. Lemma comparable_maxEgt x y : x >=< y -> max x y = if x > y then x else y. Proof. by case: comparableP. Qed. Lemma comparable_minEge x y : x >=< y -> min x y = if x >= y then y else x. Proof. by case: comparableP. Qed. Lemma comparable_maxEge x y : x >=< y -> max x y = if x >= y then x else y. Proof. by case: comparableP. Qed. Lemma min_l x y : x <= y -> min x y = x. Proof. by case: comparableP. Qed. Lemma min_r x y : y <= x -> min x y = y. Proof. by case: comparableP. Qed. Lemma max_l x y : y <= x -> max x y = x. Proof. by case: comparableP. Qed. Lemma max_r x y : x <= y -> max x y = y. Proof. by case: comparableP. Qed. Lemma eq_minl x y : (min x y == x) = (x <= y). Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP. Qed. Lemma eq_maxr x y : (max x y == y) = (x <= y). Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP. Qed. Lemma min_idPl x y : reflect (min x y = x) (x <= y). Proof. by rewrite -eq_minl; apply/eqP. Qed. Lemma max_idPr x y : reflect (max x y = y) (x <= y). Proof. by rewrite -eq_maxr; apply/eqP. Qed. Section Comparable2. Context (z x y : T) (cmp_xy : x >=< y). Lemma comparable_minC : min x y = min y x. Proof. by case: comparableP cmp_xy. Qed. Lemma comparable_maxC : max x y = max y x. Proof. by case: comparableP cmp_xy. Qed. Lemma comparable_eq_minr : (min x y == y) = (y <= x). Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP cmp_xy. Qed. Lemma comparable_eq_maxl : (max x y == x) = (y <= x). Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP cmp_xy. Qed. Lemma comparable_min_idPr : reflect (min x y = y) (y <= x). Proof. by rewrite -comparable_eq_minr; apply/eqP. Qed. Lemma comparable_max_idPl : reflect (max x y = x) (y <= x). Proof. by rewrite -comparable_eq_maxl; apply/eqP. Qed. Lemma comparable_lteifNE C : x >=< y -> x < y ?<= if ~~ C = ~~ (y < x ?<= if C). Proof. by case: C => /=; case: comparableP. Qed. End Comparable2. Section Comparable3. Context (x y z : T) (cmp_xy : x >=< y) (cmp_xz : x >=< z) (cmp_yz : y >=< z). Let P := comparableP. Lemma comparable_max_minl : max (min x y) z = min (max x z) (max y z). Proof. move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/=. move: (P x y) (P x z) (P y z). move=> [xy|xy|xy|<-] [xz|xz|xz|<-] [yz|yz|yz|//->]//= _; rewrite ?ltxx//. - by have := lt_trans xy (lt_trans yz xz); rewrite ltxx. - by have := lt_trans xy (lt_trans xz yz); rewrite ltxx. Qed. End Comparable3. Section Comparable4. Context (x y z w : T) (cmp_xy : x >=< y) (cmp_zw : z >=< w). Lemma comparable_le_min2 : x <= z -> y <= w -> Order.min x y <= Order.min z w. Proof. move: cmp_xy cmp_zw => /comparable_leP[] xy /comparable_leP[] zw // xz yw. - exact: le_trans xy yw. - exact: le_trans (ltW xy) xz. Qed. Lemma comparable_le_max2 : x <= z -> y <= w -> Order.max x y <= Order.max z w. Proof. move: cmp_xy cmp_zw => /comparable_leP[] xy /comparable_leP[] zw // xz yw. - exact: le_trans yw (ltW zw). - exact: le_trans xz zw. Qed. End Comparable4. Lemma comparable_minAC x y z : x >=< y -> x >=< z -> y >=< z -> min (min x y) z = min (min x z) y. Proof. move=> xy xz yz; rewrite -comparable_minA// [min y z]comparable_minC//. by rewrite comparable_minA// 1?comparable_sym. Qed. Lemma comparable_maxAC x y z : x >=< y -> x >=< z -> y >=< z -> max (max x y) z = max (max x z) y. Proof. move=> xy xz yz; rewrite -comparable_maxA// [max y z]comparable_maxC//. by rewrite comparable_maxA// 1?comparable_sym. Qed. Lemma comparable_minCA x y z : x >=< y -> x >=< z -> y >=< z -> min x (min y z) = min y (min x z). Proof. move=> xy xz yz; rewrite comparable_minA// [min x y]comparable_minC//. by rewrite -comparable_minA// 1?comparable_sym. Qed. Lemma comparable_maxCA x y z : x >=< y -> x >=< z -> y >=< z -> max x (max y z) = max y (max x z). Proof. move=> xy xz yz; rewrite comparable_maxA// [max x y]comparable_maxC//. by rewrite -comparable_maxA// 1?comparable_sym. Qed. Lemma comparable_minACA x y z t : x >=< y -> x >=< z -> x >=< t -> y >=< z -> y >=< t -> z >=< t -> min (min x y) (min z t) = min (min x z) (min y t). Proof. move=> xy xz xt yz yt zt; rewrite comparable_minA// ?comparable_minl//. rewrite [min _ z]comparable_minAC// -comparable_minA// ?comparable_minl//. by rewrite inE comparable_sym. Qed. Lemma comparable_maxACA x y z t : x >=< y -> x >=< z -> x >=< t -> y >=< z -> y >=< t -> z >=< t -> max (max x y) (max z t) = max (max x z) (max y t). Proof. move=> xy xz xt yz yt zt; rewrite comparable_maxA// ?comparable_maxl//. rewrite [max _ z]comparable_maxAC// -comparable_maxA// ?comparable_maxl//. by rewrite inE comparable_sym. Qed. Lemma comparable_min_maxr x y z : x >=< y -> x >=< z -> y >=< z -> min x (max y z) = max (min x y) (min x z). Proof. move=> xy xz yz; rewrite ![min x _]comparable_minC// ?comparable_maxr//. by rewrite comparable_min_maxl// 1?comparable_sym. Qed. (* monotonicity *) Lemma mono_in_leif (A : {pred T}) (f : T -> T) C : {in A &, {mono f : x y / x <= y}} -> {in A &, forall x y, (f x <= f y ?= iff C) = (x <= y ?= iff C)}. Proof. by move=> mf x y Ax Ay; rewrite /leif !eq_le !mf. Qed. Lemma mono_leif (f : T -> T) C : {mono f : x y / x <= y} -> forall x y, (f x <= f y ?= iff C) = (x <= y ?= iff C). Proof. by move=> mf x y; rewrite /leif !eq_le !mf. Qed. Lemma nmono_in_leif (A : {pred T}) (f : T -> T) C : {in A &, {mono f : x y /~ x <= y}} -> {in A &, forall x y, (f x <= f y ?= iff C) = (y <= x ?= iff C)}. Proof. by move=> mf x y Ax Ay; rewrite /leif !eq_le !mf. Qed. Lemma nmono_leif (f : T -> T) C : {mono f : x y /~ x <= y} -> forall x y, (f x <= f y ?= iff C) = (y <= x ?= iff C). Proof. by move=> mf x y; rewrite /leif !eq_le !mf. Qed. Section bigminmax. Context (I : Type) (r : seq I) (f : I -> T) (x0 x : T) (P : pred I). Lemma bigmax_le : x0 <= x -> (forall i, P i -> f i <= x) -> \big[max/x0]_(i <- r | P i) f i <= x. Proof. by move=> ? ?; elim/big_ind: _ => // *; rewrite maxEle; case: ifPn. Qed. Lemma le_bigmin : x <= x0 -> (forall i, P i -> x <= f i) -> x <= \big[min/x0]_(i <- r | P i) f i. Proof. by move=> ? ?; elim/big_ind: _ => // *; rewrite minEle; case: ifPn. Qed. End bigminmax. End POrderTheory. #[global] Hint Resolve comparable_minr comparable_minl : core. #[global] Hint Resolve comparable_maxr comparable_maxl : core. Section ContraTheory. Context {disp1 disp2 : disp_t} {T1 : porderType disp1} {T2 : porderType disp2}. Implicit Types (x y : T1) (z t : T2) (b : bool) (m n : nat) (P : Prop). Lemma contra_leT b x y : (~~ b -> x < y) -> (y <= x -> b). Proof. by case: comparableP; case: b. Qed. Lemma contra_ltT b x y : (~~ b -> x <= y) -> (y < x -> b). Proof. by case: comparableP; case: b. Qed. Lemma contra_leN b x y : (b -> x < y) -> (y <= x -> ~~ b). Proof. by case: comparableP; case: b. Qed. Lemma contra_ltN b x y : (b -> x <= y) -> (y < x -> ~~ b). Proof. by case: comparableP; case: b. Qed. Lemma contra_le_not P x y : (P -> x < y) -> (y <= x -> ~ P). Proof. by case: comparableP => // _ PF _ /PF. Qed. Lemma contra_lt_not P x y : (P -> x <= y) -> (y < x -> ~ P). Proof. by case: comparableP => // _ PF _ /PF. Qed. Lemma contra_leF b x y : (b -> x < y) -> (y <= x -> b = false). Proof. by case: comparableP; case: b => // _ /implyP. Qed. Lemma contra_ltF b x y : (b -> x <= y) -> (y < x -> b = false). Proof. by case: comparableP; case: b => // _ /implyP. Qed. Lemma contra_le_leq x y m n : ((n < m)%N -> y < x) -> (x <= y -> (m <= n)%N). Proof. by case: comparableP; case: ltngtP. Qed. Lemma contra_le_ltn x y m n : ((n <= m)%N -> y < x) -> (x <= y -> (m < n)%N). Proof. by case: comparableP; case: ltngtP. Qed. Lemma contra_lt_leq x y m n : ((n < m)%N -> y <= x) -> (x < y -> (m <= n)%N). Proof. by case: comparableP; case: ltngtP. Qed. Lemma contra_lt_ltn x y m n : ((n <= m)%N -> y <= x) -> (x < y -> (m < n)%N). Proof. by case: comparableP; case: ltngtP. Qed. End ContraTheory. Section POrderMonotonyTheory. Context {disp disp' : disp_t} {T : porderType disp} {T' : porderType disp'}. Context (D D' : {pred T}) (f : T -> T'). Let leT_anti := @le_anti _ T. Hint Resolve lexx lt_neqAle : core. Let ge_antiT : antisymmetric (>=%O : rel T). Proof. by move=> ? ? /le_anti. Qed. Lemma ltW_homo : {homo f : x y / x < y} -> {homo f : x y / x <= y}. Proof. exact: homoW. Qed. Lemma ltW_nhomo : {homo f : x y /~ x < y} -> {homo f : x y /~ x <= y}. Proof. by apply: homoW=> // x y; rewrite eq_sym. Qed. Lemma inj_homo_lt : injective f -> {homo f : x y / x <= y} -> {homo f : x y / x < y}. Proof. exact: inj_homo. Qed. Lemma inj_nhomo_lt : injective f -> {homo f : x y /~ x <= y} -> {homo f : x y /~ x < y}. Proof. by apply: inj_homo=> // x y; rewrite eq_sym. Qed. Lemma inc_inj : {mono f : x y / x <= y} -> injective f. Proof. exact: mono_inj. Qed. Lemma dec_inj : {mono f : x y /~ x <= y} -> injective f. Proof. exact: mono_inj. Qed. (* Monotony in D D' *) Lemma ltW_homo_in : {in D & D', {homo f : x y / x < y}} -> {in D & D', {homo f : x y / x <= y}}. Proof. exact: homoW_in. Qed. Lemma ltW_nhomo_in : {in D & D', {homo f : x y /~ x < y}} -> {in D & D', {homo f : x y /~ x <= y}}. Proof. by apply: homoW_in=> // x y; rewrite eq_sym. Qed. Lemma inj_homo_lt_in : {in D & D', injective f} -> {in D & D', {homo f : x y / x <= y}} -> {in D & D', {homo f : x y / x < y}}. Proof. exact: inj_homo_in. Qed. Lemma inj_nhomo_lt_in : {in D & D', injective f} -> {in D & D', {homo f : x y /~ x <= y}} -> {in D & D', {homo f : x y /~ x < y}}. Proof. by apply: inj_homo_in=> // x y; rewrite eq_sym. Qed. Lemma inc_inj_in : {in D &, {mono f : x y / x <= y}} -> {in D &, injective f}. Proof. exact: mono_inj_in. Qed. Lemma dec_inj_in : {in D &, {mono f : x y /~ x <= y}} -> {in D &, injective f}. Proof. exact: mono_inj_in. Qed. End POrderMonotonyTheory. End POrderTheory. Arguments leifP {disp T x y C}. Arguments mono_in_leif [disp T A f C]. Arguments nmono_in_leif [disp T A f C]. Arguments mono_leif [disp T f C]. Arguments nmono_leif [disp T f C]. Arguments min_idPl {disp T x y}. Arguments max_idPr {disp T x y}. Arguments comparable_min_idPr {disp T x y _}. Arguments comparable_max_idPl {disp T x y _}. Module Import BPOrderTheory. Export BPreorderTheory. Section BPOrderTheory. Context {disp : disp_t} {T : bPOrderType disp}. Implicit Types (x y : T). Lemma lex0 x : (x <= \bot) = (x == \bot). Proof. by rewrite le_eqVlt ltx0 orbF. Qed. Lemma lt0x x : (\bot < x) = (x != \bot). Proof. by rewrite lt_def le0x andbT. Qed. Variant eq0_xor_gt0 x : bool -> bool -> Set := Eq0NotPOs : x = \bot -> eq0_xor_gt0 x true false | POsNotEq0 : \bot < x -> eq0_xor_gt0 x false true. Lemma posxP x : eq0_xor_gt0 x (x == \bot) (\bot < x). Proof. by rewrite lt0x; have [] := eqVneq; constructor; rewrite ?lt0x. Qed. End BPOrderTheory. End BPOrderTheory. Module Import TPOrderTheory. Section TPOrderTheory. Context {disp : disp_t} {T : tPOrderType disp}. Implicit Types (x y : T). Lemma le1x x : (\top <= x) = (x == \top). Proof. exact: (@lex0 _ T^d). Qed. Lemma ltx1 x : (x < \top) = (x != \top). Proof. exact: (@lt0x _ T^d). Qed. End TPOrderTheory. End TPOrderTheory. Module Import MeetTheory. Section MeetTheory. Context {disp : disp_t} {L : meetSemilatticeType disp}. Implicit Types (x y : L). (* interaction with order *) Lemma lexI x y z : (x <= y `&` z) = (x <= y) && (x <= z). Proof. exact: lexI. Qed. Lemma leIr x y : y `&` x <= x. Proof. by have:= le_refl (meet y x); rewrite lexI => /andP []. Qed. Lemma leIl x y : x `&` y <= x. Proof. by have:= le_refl (meet x y); rewrite lexI => /andP []. Qed. Lemma leIxl x y z : y <= x -> y `&` z <= x. Proof. exact/le_trans/leIl. Qed. Lemma leIxr x y z : z <= x -> y `&` z <= x. Proof. exact/le_trans/leIr. Qed. Lemma leIx2 x y z : (y <= x) || (z <= x) -> y `&` z <= x. Proof. by case/orP => [/leIxl|/leIxr]. Qed. Lemma leEmeet x y : (x <= y) = (x `&` y == x). Proof. by rewrite eq_le lexI leIl lexx. Qed. Lemma eq_meetl x y : (x `&` y == x) = (x <= y). Proof. by apply/esym/leEmeet. Qed. Lemma eq_meetr x y : (x `&` y == y) = (y <= x). Proof. by rewrite eq_le lexI leIr lexx andbT. Qed. Lemma meet_idPl {x y} : reflect (x `&` y = x) (x <= y). Proof. by rewrite -eq_meetl; apply/eqP. Qed. Lemma meet_idPr {x y} : reflect (y `&` x = x) (x <= y). Proof. by rewrite -eq_meetr; apply/eqP. Qed. Lemma meet_l x y : x <= y -> x `&` y = x. Proof. exact/meet_idPl. Qed. Lemma meet_r x y : y <= x -> x `&` y = y. Proof. exact/meet_idPr. Qed. Lemma leIidl x y : (x <= x `&` y) = (x <= y). Proof. by rewrite lexI lexx. Qed. Lemma leIidr x y : (x <= y `&` x) = (x <= y). Proof. by rewrite lexI lexx andbT. Qed. Lemma leI2 x y z t : x <= z -> y <= t -> x `&` y <= z `&` t. Proof. by move=> xz yt; rewrite lexI !leIx2 ?xz ?yt ?orbT //. Qed. (* algebraic properties *) Lemma meetC : commutative (@meet _ L). Proof. by move=> x y; apply: le_anti; rewrite !lexI !leIr !leIl. Qed. Lemma meetA : associative (@meet _ L). Proof. move=> x y z; apply: le_anti. rewrite !lexI leIr leIl /= andbT -andbA. rewrite ![_ `&` (_ `&` _) <= _]leIxr ?(leIr, leIl) //=. by rewrite leIxl ?leIl // leIxl // leIr. Qed. HB.instance Definition _ := SemiGroup.isComLaw.Build L meet meetA meetC. Lemma meetxx : idempotent_op (@meet _ L). Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed. Lemma meetAC : right_commutative (@meet _ L). Proof. by move=> x y z; rewrite -!meetA [X in _ `&` X]meetC. Qed. Lemma meetCA : left_commutative (@meet _ L). Proof. by move=> x y z; rewrite !meetA [X in X `&` _]meetC. Qed. Lemma meetACA : interchange (@meet _ L) (@meet _ L). Proof. by move=> x y z t; rewrite !meetA [X in X `&` _]meetAC. Qed. Lemma meetKI y x : x `&` (x `&` y) = x `&` y. Proof. by rewrite meetA meetxx. Qed. Lemma meetIK y x : (x `&` y) `&` y = x `&` y. Proof. by rewrite -meetA meetxx. Qed. Lemma meetKIC y x : x `&` (y `&` x) = x `&` y. Proof. by rewrite meetC meetIK meetC. Qed. Lemma meetIKC y x : y `&` x `&` y = x `&` y. Proof. by rewrite meetAC meetC meetxx. Qed. End MeetTheory. End MeetTheory. Arguments meet_idPl {disp L x y}. Arguments meet_idPr {disp L x y}. Module Import BMeetTheory. Section BMeetTheory. Context {disp : disp_t} {L : bMeetSemilatticeType disp}. Lemma meet0x : left_zero \bot (@meet _ L). Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed. Lemma meetx0 : right_zero \bot (@meet _ L). Proof. by move=> x; rewrite meetC meet0x. Qed. HB.instance Definition _ := Monoid.isMulLaw.Build L \bot meet meet0x meetx0. End BMeetTheory. End BMeetTheory. Module Import TMeetTheory. Section TMeetTheory. Context {disp : disp_t} {L : tMeetSemilatticeType disp}. Implicit Types (I : finType) (T : eqType) (x y : L). Lemma meetx1 : right_id \top (@meet _ L). Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed. Lemma meet1x : left_id \top (@meet _ L). Proof. by move=> x; apply/eqP; rewrite meetC meetx1. Qed. Lemma meet_eq1 x y : (x `&` y == \top) = (x == \top) && (y == \top). Proof. apply/idP/idP; last by move=> /andP[/eqP-> /eqP->]; rewrite meetx1. by move=> /eqP xIy1; rewrite -!le1x -xIy1 leIl leIr. Qed. HB.instance Definition _ := Monoid.isMonoidLaw.Build L \top meet meet1x meetx1. Lemma meets_inf_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) : x \in r -> P x -> \meet_(i <- r | P i) F i <= F x. Proof. by move=> xr Px; rewrite (big_rem x) ?Px //= leIl. Qed. Lemma meets_max_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) (u : L) : x \in r -> P x -> F x <= u -> \meet_(x <- r | P x) F x <= u. Proof. by move=> ? ?; apply/le_trans/meets_inf_seq. Qed. Lemma meets_inf I (j : I) (P : {pred I}) (F : I -> L) : P j -> \meet_(i | P i) F i <= F j. Proof. exact: meets_inf_seq. Qed. Lemma meets_max I (j : I) (u : L) (P : {pred I}) (F : I -> L) : P j -> F j <= u -> \meet_(i | P i) F i <= u. Proof. exact: meets_max_seq. Qed. Lemma meets_ge J (r : seq J) (P : {pred J}) (F : J -> L) (u : L) : (forall x : J, P x -> u <= F x) -> u <= \meet_(x <- r | P x) F x. Proof. by move=> leFm; elim/big_rec: _ => // i x Px xu; rewrite lexI leFm. Qed. Lemma meetsP_seq T (r : seq T) (P : {pred T}) (F : T -> L) (l : L) : reflect (forall x : T, x \in r -> P x -> l <= F x) (l <= \meet_(x <- r | P x) F x). Proof. apply: (iffP idP) => leFm => [x xr Px|]. exact/(le_trans leFm)/meets_inf_seq. by rewrite big_seq_cond meets_ge// => x /andP[/leFm]. Qed. Lemma meetsP I (l : L) (P : {pred I}) (F : I -> L) : reflect (forall i : I, P i -> l <= F i) (l <= \meet_(i | P i) F i). Proof. by apply: (iffP (meetsP_seq _ _ _ _)) => H ? ?; apply: H. Qed. Lemma le_meets I (A B : {set I}) (F : I -> L) : A \subset B -> \meet_(i in B) F i <= \meet_(i in A) F i. Proof. by move=> /subsetP AB; apply/meetsP => i iA; apply/meets_inf/AB. Qed. Lemma meets_setU I (A B : {set I}) (F : I -> L) : \meet_(i in (A :|: B)) F i = \meet_(i in A) F i `&` \meet_(i in B) F i. Proof. rewrite -!big_enum; have /= <- := @big_cat _ _ meet. apply/eq_big_idem; first exact: meetxx. by move=> ?; rewrite mem_cat !fintype.mem_enum inE. Qed. Lemma meets_seq I (r : seq I) (F : I -> L) : \meet_(i <- r) F i = \meet_(i in r) F i. Proof. by rewrite -big_enum; apply/eq_big_idem => ?; rewrite /= ?meetxx ?fintype.mem_enum. Qed. End TMeetTheory. End TMeetTheory. Module Import JoinTheory. Section JoinTheory. Context {disp : disp_t} {L : joinSemilatticeType disp}. Implicit Types (x y : L). (* interaction with order *) Lemma leUx x y z : (x `|` y <= z) = (x <= z) && (y <= z). Proof. exact: leUx. Qed. Lemma leUr x y : x <= y `|` x. Proof. exact: (@leIr _ L^d). Qed. Lemma leUl x y : x <= x `|` y. Proof. exact: (@leIl _ L^d). Qed. Lemma lexUl x y z : x <= y -> x <= y `|` z. Proof. exact: (@leIxl _ L^d). Qed. Lemma lexUr x y z : x <= z -> x <= y `|` z. Proof. exact: (@leIxr _ L^d). Qed. Lemma lexU2 x y z : (x <= y) || (x <= z) -> x <= y `|` z. Proof. exact: (@leIx2 _ L^d). Qed. Lemma leEjoin x y : (x <= y) = (x `|` y == y). Proof. by rewrite [LHS](@leEmeet _ L^d) meetC. Qed. Lemma eq_joinl x y : (x `|` y == x) = (y <= x). Proof. exact: (@eq_meetl _ L^d). Qed. Lemma eq_joinr x y : (x `|` y == y) = (x <= y). Proof. exact: (@eq_meetr _ L^d). Qed. Lemma join_idPl {x y} : reflect (y `|` x = y) (x <= y). Proof. exact: (@meet_idPl _ L^d). Qed. Lemma join_idPr {x y} : reflect (x `|` y = y) (x <= y). Proof. exact: (@meet_idPr _ L^d). Qed. Lemma join_l x y : y <= x -> x `|` y = x. Proof. exact/join_idPl. Qed. Lemma join_r x y : x <= y -> x `|` y = y. Proof. exact/join_idPr. Qed. Lemma leUidl x y : (x `|` y <= y) = (x <= y). Proof. exact: (@leIidr _ L^d). Qed. Lemma leUidr x y : (y `|` x <= y) = (x <= y). Proof. exact: (@leIidl _ L^d). Qed. Lemma leU2 x y z t : x <= z -> y <= t -> x `|` y <= z `|` t. Proof. exact: (@leI2 _ L^d). Qed. (* algebraic properties *) Lemma joinC : commutative (@join _ L). Proof. exact: (@meetC _ L^d). Qed. Lemma joinA : associative (@join _ L). Proof. exact: (@meetA _ L^d). Qed. HB.instance Definition _ := SemiGroup.isComLaw.Build L join joinA joinC. Lemma joinxx : idempotent_op (@join _ L). Proof. exact: (@meetxx _ L^d). Qed. Lemma joinAC : right_commutative (@join _ L). Proof. exact: (@meetAC _ L^d). Qed. Lemma joinCA : left_commutative (@join _ L). Proof. exact: (@meetCA _ L^d). Qed. Lemma joinACA : interchange (@join _ L) (@join _ L). Proof. exact: (@meetACA _ L^d). Qed. Lemma joinKU y x : x `|` (x `|` y) = x `|` y. Proof. exact: (@meetKI _ L^d). Qed. Lemma joinUK y x : (x `|` y) `|` y = x `|` y. Proof. exact: (@meetIK _ L^d). Qed. Lemma joinKUC y x : x `|` (y `|` x) = x `|` y. Proof. exact: (@meetKIC _ L^d). Qed. Lemma joinUKC y x : y `|` x `|` y = x `|` y. Proof. exact: (@meetIKC _ L^d). Qed. End JoinTheory. End JoinTheory. Arguments join_idPl {disp L x y}. Arguments join_idPr {disp L x y}. Module Import BJoinTheory. Section BJoinTheory. Context {disp : disp_t} {L : bJoinSemilatticeType disp}. Implicit Types (I : finType) (T : eqType) (x y : L). Lemma joinx0 : right_id \bot (@join _ L). Proof. exact: (@meetx1 _ L^d). Qed. Lemma join0x : left_id \bot (@join _ L). Proof. exact: (@meet1x _ L^d). Qed. Lemma join_eq0 x y : (x `|` y == \bot) = (x == \bot) && (y == \bot). Proof. exact: (@meet_eq1 _ L^d). Qed. HB.instance Definition _ := Monoid.isMonoidLaw.Build L \bot join join0x joinx0. Lemma joins_sup_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) : x \in r -> P x -> F x <= \join_(i <- r | P i) F i. Proof. exact: (@meets_inf_seq _ L^d). Qed. Lemma joins_min_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) (l : L) : x \in r -> P x -> l <= F x -> l <= \join_(x <- r | P x) F x. Proof. exact: (@meets_max_seq _ L^d). Qed. Lemma joins_sup I (j : I) (P : {pred I}) (F : I -> L) : P j -> F j <= \join_(i | P i) F i. Proof. exact: (@meets_inf _ L^d). Qed. Lemma joins_min I (j : I) (l : L) (P : {pred I}) (F : I -> L) : P j -> l <= F j -> l <= \join_(i | P i) F i. Proof. exact: (@meets_max _ L^d). Qed. Lemma joins_le J (r : seq J) (P : {pred J}) (F : J -> L) (u : L) : (forall x : J, P x -> F x <= u) -> \join_(x <- r | P x) F x <= u. Proof. exact: (@meets_ge _ L^d). Qed. Lemma joinsP_seq T (r : seq T) (P : {pred T}) (F : T -> L) (u : L) : reflect (forall x : T, x \in r -> P x -> F x <= u) (\join_(x <- r | P x) F x <= u). Proof. exact: (@meetsP_seq _ L^d). Qed. Lemma joinsP I (u : L) (P : {pred I}) (F : I -> L) : reflect (forall i : I, P i -> F i <= u) (\join_(i | P i) F i <= u). Proof. exact: (@meetsP _ L^d). Qed. Lemma le_joins I (A B : {set I}) (F : I -> L) : A \subset B -> \join_(i in A) F i <= \join_(i in B) F i. Proof. exact: (@le_meets _ L^d). Qed. Lemma joins_setU I (A B : {set I}) (F : I -> L) : \join_(i in (A :|: B)) F i = \join_(i in A) F i `|` \join_(i in B) F i. Proof. exact: (@meets_setU _ L^d). Qed. Lemma joins_seq I (r : seq I) (F : I -> L) : \join_(i <- r) F i = \join_(i in r) F i. Proof. exact: (@meets_seq _ L^d). Qed. End BJoinTheory. End BJoinTheory. Module Import TJoinTheory. Section TJoinTheory. Context {disp : disp_t} {L : tJoinSemilatticeType disp}. Lemma joinx1 : right_zero \top (@join _ L). Proof. exact: (@meetx0 _ L^d). Qed. Lemma join1x : left_zero \top (@join _ L). Proof. exact: (@meet0x _ L^d). Qed. HB.instance Definition _ := Monoid.isMulLaw.Build L \top join join1x joinx1. End TJoinTheory. End TJoinTheory. Module Import LatticeTheory. Section LatticeTheory. Context {disp : disp_t} {L : latticeType disp}. Implicit Types (x y : L). Lemma meetUK x y : (x `&` y) `|` y = y. Proof. exact/join_idPr/leIr. Qed. Lemma meetUKC x y : (y `&` x) `|` y = y. Proof. by rewrite meetC meetUK. Qed. Lemma meetKUC y x : x `|` (y `&` x) = x. Proof. by rewrite joinC meetUK. Qed. Lemma meetKU y x : x `|` (x `&` y) = x. Proof. by rewrite meetC meetKUC. Qed. Lemma joinIK x y : (x `|` y) `&` y = y. Proof. exact/meet_idPr/leUr. Qed. Lemma joinIKC x y : (y `|` x) `&` y = y. Proof. by rewrite joinC joinIK. Qed. Lemma joinKIC y x : x `&` (y `|` x) = x. Proof. by rewrite meetC joinIK. Qed. Lemma joinKI y x : x `&` (x `|` y) = x. Proof. by rewrite joinC joinKIC. Qed. (* comparison predicates *) Lemma lcomparableP x y : incomparel x y (min y x) (min x y) (max y x) (max x y) (y `&` x) (x `&` y) (y `|` x) (x `|` y) (y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y) (y >=< x) (x >=< y). Proof. by case: (comparableP x) => [hxy|hxy|hxy|->]; do 1?have hxy' := ltW hxy; rewrite ?(meetxx, joinxx); rewrite ?(meet_l hxy', meet_r hxy', join_l hxy', join_r hxy'); constructor. Qed. Lemma lcomparable_ltgtP x y : x >=< y -> comparel x y (min y x) (min x y) (max y x) (max x y) (y `&` x) (x `&` y) (y `|` x) (x `|` y) (y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y). Proof. by case: (lcomparableP x) => // *; constructor. Qed. Lemma lcomparable_leP x y : x >=< y -> lel_xor_gt x y (min y x) (min x y) (max y x) (max x y) (y `&` x) (x `&` y) (y `|` x) (x `|` y) (x <= y) (y < x). Proof. by move/lcomparable_ltgtP => [/ltW xy|xy|->]; constructor. Qed. Lemma lcomparable_ltP x y : x >=< y -> ltl_xor_ge x y (min y x) (min x y) (max y x) (max x y) (y `&` x) (x `&` y) (y `|` x) (x `|` y) (y <= x) (x < y). Proof. by move=> /lcomparable_ltgtP [xy|/ltW xy|->]; constructor. Qed. End LatticeTheory. End LatticeTheory. Module Import DistrLatticeTheory. Section DistrLatticeTheory. Context {disp : disp_t} {L : distrLatticeType disp}. Lemma meetUl : left_distributive (@meet _ L) (@join _ L). Proof. exact: meetUl. Qed. Lemma meetUr : right_distributive (@meet _ L) (@join _ L). Proof. by move=> x y z; rewrite ![x `&` _]meetC meetUl. Qed. Lemma joinIl : left_distributive (@join _ L) (@meet _ L). Proof. exact: joinIl. Qed. Lemma joinIr : right_distributive (@join _ L) (@meet _ L). Proof. by move=> x y z; rewrite ![x `|` _]joinC joinIl. Qed. #[warning="-HB.no-new-instance"] HB.instance Definition _ := Monoid.isAddLaw.Build L meet join meetUl meetUr. HB.instance Definition _ := Monoid.isAddLaw.Build L join meet joinIl joinIr. End DistrLatticeTheory. End DistrLatticeTheory. Module Import BDistrLatticeTheory. Section BDistrLatticeTheory. Context {disp : disp_t} {L : bDistrLatticeType disp}. Implicit Types (x y z : L). Lemma leU2l_le y t x z : x `&` t = \bot -> x `|` y <= z `|` t -> x <= z. Proof. by move=> xIt0 /(leI2 (lexx x)); rewrite joinKI meetUr xIt0 joinx0 leIidl. Qed. Lemma leU2r_le y t x z : x `&` t = \bot -> y `|` x <= t `|` z -> x <= z. Proof. by rewrite joinC [_ `|` z]joinC => /leU2l_le H /H. Qed. Lemma disjoint_lexUl z x y : x `&` z = \bot -> (x <= y `|` z) = (x <= y). Proof. move=> xz0; apply/idP/idP=> xy; last by rewrite lexU2 ?xy. by apply: (@leU2l_le x z); rewrite ?joinxx. Qed. Lemma disjoint_lexUr z x y : x `&` z = \bot -> (x <= z `|` y) = (x <= y). Proof. by move=> xz0; rewrite joinC; rewrite disjoint_lexUl. Qed. Lemma leU2E x y z t : x `&` t = \bot -> y `&` z = \bot -> (x `|` y <= z `|` t) = (x <= z) && (y <= t). Proof. move=> dxt dyz; apply/idP/andP; last by case=> ? ?; exact: leU2. by move=> lexyzt; rewrite (leU2l_le _ lexyzt) // (leU2r_le _ lexyzt). Qed. Lemma joins_disjoint (I : finType) (d : L) (P : {pred I}) (F : I -> L) : (forall i : I, P i -> d `&` F i = \bot) -> d `&` \join_(i | P i) F i = \bot. Proof. move=> d_Fi_disj; have : \big[andb/true]_(i | P i) (d `&` F i == \bot). rewrite big_all_cond; apply/allP => i _ /=. by apply/implyP => /d_Fi_disj ->. elim/big_rec2: _ => [|i y]; first by rewrite meetx0. case; rewrite (andbF, andbT) // => Pi /(_ isT) dy /eqP dFi. by rewrite meetUr dy dFi joinxx. Qed. End BDistrLatticeTheory. End BDistrLatticeTheory. Module Import TDistrLatticeTheory. Section TDistrLatticeTheory. Context {disp : disp_t} {L : tDistrLatticeType disp}. Implicit Types (x y : L). Lemma leI2l_le y t x z : y `|` z = \top -> x `&` y <= z `&` t -> x <= z. Proof. by rewrite joinC; exact: (@leU2l_le _ L^d). Qed. Lemma leI2r_le y t x z : y `|` z = \top -> y `&` x <= t `&` z -> x <= z. Proof. by rewrite joinC; exact: (@leU2r_le _ L^d). Qed. Lemma cover_leIxl z x y : z `|` y = \top -> (x `&` z <= y) = (x <= y). Proof. by rewrite joinC; exact: (@disjoint_lexUl _ L^d). Qed. Lemma cover_leIxr z x y : z `|` y = \top -> (z `&` x <= y) = (x <= y). Proof. by rewrite joinC; exact: (@disjoint_lexUr _ L^d). Qed. Lemma leI2E x y z t : x `|` t = \top -> y `|` z = \top -> (x `&` y <= z `&` t) = (x <= z) && (y <= t). Proof. by move=> ? ?; apply: (@leU2E _ L^d); rewrite meetC. Qed. Lemma meets_total (I : finType) (d : L) (P : {pred I}) (F : I -> L) : (forall i : I, P i -> d `|` F i = \top) -> d `|` \meet_(i | P i) F i = \top. Proof. exact: (@joins_disjoint _ L^d). Qed. End TDistrLatticeTheory. End TDistrLatticeTheory. Module Import TotalTheory. Section TotalTheory. Context {disp : disp_t} {T : orderType disp}. Implicit Types (x y z t : T) (s : seq T). Definition le_total : total (<=%O : rel T) := le_total. Hint Resolve le_total : core. Lemma ge_total : total (>=%O : rel T). Proof. by move=> ? ?; apply: le_total. Qed. Hint Resolve ge_total : core. Lemma comparableT x y : x >=< y. Proof. exact: le_total. Qed. Hint Extern 0 (is_true (_ >=< _)%O) => solve [apply: comparableT] : core. Lemma sort_le_sorted s : sorted <=%O (sort <=%O s). Proof. exact: sort_sorted. Qed. Hint Resolve sort_le_sorted : core. Lemma sort_lt_sorted s : sorted <%O (sort <=%O s) = uniq s. Proof. by rewrite lt_sorted_uniq_le sort_uniq sort_le_sorted andbT. Qed. Lemma perm_sort_leP s1 s2 : reflect (sort <=%O s1 = sort <=%O s2) (perm_eq s1 s2). Proof. exact/perm_sortP/le_anti/le_trans/le_total. Qed. Lemma filter_sort_le p s : filter p (sort <=%O s) = sort <=%O (filter p s). Proof. exact/filter_sort/le_trans/le_total. Qed. Lemma mask_sort_le s (m : bitseq) : {m_s : bitseq | mask m_s (sort <=%O s) = sort <=%O (mask m s)}. Proof. exact/mask_sort/le_trans/le_total. Qed. Lemma sorted_mask_sort_le s (m : bitseq) : sorted <=%O (mask m s) -> {m_s : bitseq | mask m_s (sort <=%O s) = mask m s}. Proof. exact/sorted_mask_sort/le_trans/le_total. Qed. Lemma subseq_sort_le : {homo sort <=%O : s1 s2 / @subseq T s1 s2}. Proof. exact/subseq_sort/le_trans/le_total. Qed. Lemma sorted_subseq_sort_le s1 s2 : subseq s1 s2 -> sorted <=%O s1 -> subseq s1 (sort <=%O s2). Proof. exact/sorted_subseq_sort/le_trans/le_total. Qed. Lemma mem2_sort_le s x y : x <= y -> mem2 s x y -> mem2 (sort <=%O s) x y. Proof. exact/mem2_sort/le_trans/le_total. Qed. Lemma leNgt x y : (x <= y) = ~~ (y < x). Proof. exact: comparable_leNgt. Qed. Lemma ltNge x y : (x < y) = ~~ (y <= x). Proof. exact: comparable_ltNge. Qed. Definition ltgtP x y := LatticeTheory.lcomparable_ltgtP (comparableT x y). Definition leP x y := LatticeTheory.lcomparable_leP (comparableT x y). Definition ltP x y := LatticeTheory.lcomparable_ltP (comparableT x y). Lemma wlog_le P : (forall x y, P y x -> P x y) -> (forall x y, x <= y -> P x y) -> forall x y, P x y. Proof. by move=> sP hP x y; case: (leP x y) => [| /ltW] /hP // /sP. Qed. Lemma wlog_lt P : (forall x, P x x) -> (forall x y, (P y x -> P x y)) -> (forall x y, x < y -> P x y) -> forall x y, P x y. Proof. by move=> rP sP hP x y; case: (ltgtP x y) => [||->] // /hP // /sP. Qed. Lemma neq_lt x y : (x != y) = (x < y) || (y < x). Proof. by case: ltgtP. Qed. Lemma lt_total x y : x != y -> (x < y) || (y < x). Proof. by case: ltgtP. Qed. Lemma eq_leLR x y z t : (x <= y -> z <= t) -> (y < x -> t < z) -> (x <= y) = (z <= t). Proof. by rewrite !ltNge => ? /contraTT ?; apply/idP/idP. Qed. Lemma eq_leRL x y z t : (x <= y -> z <= t) -> (y < x -> t < z) -> (z <= t) = (x <= y). Proof. by move=> *; apply/esym/eq_leLR. Qed. Lemma eq_ltLR x y z t : (x < y -> z < t) -> (y <= x -> t <= z) -> (x < y) = (z < t). Proof. by rewrite !leNgt => ? /contraTT ?; apply/idP/idP. Qed. Lemma eq_ltRL x y z t : (x < y -> z < t) -> (y <= x -> t <= z) -> (z < t) = (x < y). Proof. by move=> *; apply/esym/eq_ltLR. Qed. (* max and min is join and meet *) Lemma meetEtotal x y : x `&` y = min x y. Proof. by case: leP. Qed. Lemma joinEtotal x y : x `|` y = max x y. Proof. by case: leP. Qed. (* max and min theory *) Lemma minEgt x y : min x y = if x > y then y else x. Proof. by case: ltP. Qed. Lemma maxEgt x y : max x y = if x > y then x else y. Proof. by case: ltP. Qed. Lemma minEge x y : min x y = if x >= y then y else x. Proof. by case: leP. Qed. Lemma maxEge x y : max x y = if x >= y then x else y. Proof. by case: leP. Qed. Lemma minC : commutative (min : T -> T -> T). Proof. by move=> x y; apply: comparable_minC. Qed. Lemma maxC : commutative (max : T -> T -> T). Proof. by move=> x y; apply: comparable_maxC. Qed. Lemma minA : associative (min : T -> T -> T). Proof. by move=> x y z; apply: comparable_minA. Qed. Lemma maxA : associative (max : T -> T -> T). Proof. by move=> x y z; apply: comparable_maxA. Qed. Lemma minAC : right_commutative (min : T -> T -> T). Proof. by move=> x y z; apply: comparable_minAC. Qed. Lemma maxAC : right_commutative (max : T -> T -> T). Proof. by move=> x y z; apply: comparable_maxAC. Qed. Lemma minCA : left_commutative (min : T -> T -> T). Proof. by move=> x y z; apply: comparable_minCA. Qed. Lemma maxCA : left_commutative (max : T -> T -> T). Proof. by move=> x y z; apply: comparable_maxCA. Qed. Lemma minACA : interchange (min : T -> T -> T) min. Proof. by move=> x y z t; apply: comparable_minACA. Qed. Lemma maxACA : interchange (max : T -> T -> T) max. Proof. by move=> x y z t; apply: comparable_maxACA. Qed. Lemma eq_minr x y : (min x y == y) = (y <= x). Proof. exact: comparable_eq_minr. Qed. Lemma eq_maxl x y : (max x y == x) = (y <= x). Proof. exact: comparable_eq_maxl. Qed. Lemma min_idPr x y : reflect (min x y = y) (y <= x). Proof. exact: comparable_min_idPr. Qed. Lemma max_idPl x y : reflect (max x y = x) (y <= x). Proof. exact: comparable_max_idPl. Qed. Lemma le_min z x y : (z <= min x y) = (z <= x) && (z <= y). Proof. exact: comparable_le_min. Qed. Lemma ge_min z x y : (min x y <= z) = (x <= z) || (y <= z). Proof. exact: comparable_ge_min. Qed. Lemma lt_min z x y : (z < min x y) = (z < x) && (z < y). Proof. exact: comparable_lt_min. Qed. Lemma gt_min z x y : (min x y < z) = (x < z) || (y < z). Proof. exact: comparable_gt_min. Qed. Lemma le_max z x y : (z <= max x y) = (z <= x) || (z <= y). Proof. exact: comparable_le_max. Qed. Lemma ge_max z x y : (max x y <= z) = (x <= z) && (y <= z). Proof. exact: comparable_ge_max. Qed. Lemma lt_max z x y : (z < max x y) = (z < x) || (z < y). Proof. exact: comparable_lt_max. Qed. Lemma gt_max z x y : (max x y < z) = (x < z) && (y < z). Proof. exact: comparable_gt_max. Qed. Lemma minxK x y : max (min x y) y = y. Proof. exact: comparable_minxK. Qed. Lemma minKx x y : max x (min x y) = x. Proof. exact: comparable_minKx. Qed. Lemma maxxK x y : min (max x y) y = y. Proof. exact: comparable_maxxK. Qed. Lemma maxKx x y : min x (max x y) = x. Proof. exact: comparable_maxKx. Qed. Lemma max_minl : left_distributive (max : T -> T -> T) min. Proof. by move=> x y z; apply: comparable_max_minl. Qed. Lemma min_maxl : left_distributive (min : T -> T -> T) max. Proof. by move=> x y z; apply: comparable_min_maxl. Qed. Lemma max_minr : right_distributive (max : T -> T -> T) min. Proof. by move=> x y z; apply: comparable_max_minr. Qed. Lemma min_maxr : right_distributive (min : T -> T -> T) max. Proof. by move=> x y z; apply: comparable_min_maxr. Qed. HB.instance Definition _ := SemiGroup.isComLaw.Build T max maxA maxC. HB.instance Definition _ := SemiGroup.isComLaw.Build T min minA minC. Lemma leIx x y z : (meet y z <= x) = (y <= x) || (z <= x). Proof. by rewrite meetEtotal ge_min. Qed. Lemma lexU x y z : (x <= join y z) = (x <= y) || (x <= z). Proof. by rewrite joinEtotal le_max. Qed. Lemma ltxI x y z : (x < meet y z) = (x < y) && (x < z). Proof. by rewrite !ltNge leIx negb_or. Qed. Lemma ltIx x y z : (meet y z < x) = (y < x) || (z < x). Proof. by rewrite !ltNge lexI negb_and. Qed. Lemma ltxU x y z : (x < join y z) = (x < y) || (x < z). Proof. by rewrite !ltNge leUx negb_and. Qed. Lemma ltUx x y z : (join y z < x) = (y < x) && (z < x). Proof. by rewrite !ltNge lexU negb_or. Qed. Definition ltexI := (@lexI _ T, ltxI). Definition lteIx := (leIx, ltIx). Definition ltexU := (lexU, ltxU). Definition lteUx := (@leUx _ T, ltUx). Lemma le_min2 x y z t : x <= z -> y <= t -> Order.min x y <= Order.min z t. Proof. exact: comparable_le_min2. Qed. Lemma le_max2 x y z t : x <= z -> y <= t -> Order.max x y <= Order.max z t. Proof. exact: comparable_le_max2. Qed. (* lteif *) Lemma lteifNE x y C : x < y ?<= if ~~ C = ~~ (y < x ?<= if C). Proof. by case: C => /=; case: leP. Qed. Lemma lteif_minr z x y C : (z < min x y ?<= if C) = (z < x ?<= if C) && (z < y ?<= if C). Proof. by case: C; rewrite /= (le_min, lt_min). Qed. Lemma lteif_minl z x y C : (min x y < z ?<= if C) = (x < z ?<= if C) || (y < z ?<= if C). Proof. by case: C; rewrite /= (ge_min, gt_min). Qed. Lemma lteif_maxr z x y C : (z < max x y ?<= if C) = (z < x ?<= if C) || (z < y ?<= if C). Proof. by case: C; rewrite /= (le_max, lt_max). Qed. Lemma lteif_maxl z x y C : (max x y < z ?<= if C) = (x < z ?<= if C) && (y < z ?<= if C). Proof. by case: C; rewrite /= (ge_max, gt_max). Qed. Section ArgExtremum. Context (I : finType) (i0 : I) (P : {pred I}) (F : I -> T) (Pi0 : P i0). Lemma arg_minP: extremum_spec <=%O P F (arg_min i0 P F). Proof. by apply: extremumP => //; apply: le_trans. Qed. Lemma arg_maxP: extremum_spec >=%O P F (arg_max i0 P F). Proof. by apply: extremumP => //; [apply: ge_refl | apply: ge_trans]. Qed. End ArgExtremum. Lemma count_le_gt x s : count (<= x) s = size s - count (> x) s. Proof. by rewrite -(count_predC (> x)) addKn; apply: eq_count => y; rewrite /= leNgt. Qed. Lemma count_lt_ge x s : count (< x) s = size s - count (>= x) s. Proof. by rewrite -(count_predC (>= x)) addKn; apply: eq_count => y; rewrite /= ltNge. Qed. Section bigminmax_Type. Context (I : Type) (r : seq I) (x : T). Implicit Types (P : pred I) (F : I -> T). Lemma bigmin_mkcond P F : \big[min/x]_(i <- r | P i) F i = \big[min/x]_(i <- r) (if P i then F i else x). Proof. by rewrite big_mkcond_idem //= minxx. Qed. Lemma bigmax_mkcond P F : \big[max/x]_(i <- r | P i) F i = \big[max/x]_(i <- r) if P i then F i else x. Proof. by rewrite big_mkcond_idem //= maxxx. Qed. Lemma bigmin_mkcondl P Q F : \big[min/x]_(i <- r | P i && Q i) F i = \big[min/x]_(i <- r | Q i) if P i then F i else x. Proof. rewrite bigmin_mkcond [RHS]bigmin_mkcond. by apply: eq_bigr => i _; case: P; case: Q. Qed. Lemma bigmin_mkcondr P Q F : \big[min/x]_(i <- r | P i && Q i) F i = \big[min/x]_(i <- r | P i) if Q i then F i else x. Proof. by under eq_bigl do rewrite andbC; apply: bigmin_mkcondl. Qed. Lemma bigmax_mkcondl P Q F : \big[max/x]_(i <- r | P i && Q i) F i = \big[max/x]_(i <- r | Q i) if P i then F i else x. Proof. rewrite bigmax_mkcond [RHS]bigmax_mkcond. by apply: eq_bigr => i _; case: P; case: Q. Qed. Lemma bigmax_mkcondr P Q F : \big[max/x]_(i <- r | P i && Q i) F i = \big[max/x]_(i <- r | P i) if Q i then F i else x. Proof. by under eq_bigl do rewrite andbC; apply: bigmax_mkcondl. Qed. Lemma bigmin_split P F1 F2 : \big[min/x]_(i <- r | P i) (min (F1 i) (F2 i)) = min (\big[min/x]_(i <- r | P i) F1 i) (\big[min/x]_(i <- r | P i) F2 i). Proof. by rewrite big_split_idem //= minxx. Qed. Lemma bigmax_split P F1 F2 : \big[max/x]_(i <- r | P i) (max (F1 i) (F2 i)) = max (\big[max/x]_(i <- r | P i) F1 i) (\big[max/x]_(i <- r | P i) F2 i). Proof. by rewrite big_split_idem //= maxxx. Qed. Lemma bigmin_idl P F : \big[min/x]_(i <- r | P i) F i = min x (\big[min/x]_(i <- r | P i) F i). Proof. by rewrite minC big_id_idem //= minxx. Qed. Lemma bigmax_idl P F : \big[max/x]_(i <- r | P i) F i = max x (\big[max/x]_(i <- r | P i) F i). Proof. by rewrite maxC big_id_idem //= maxxx. Qed. Lemma bigmin_idr P F : \big[min/x]_(i <- r | P i) F i = min (\big[min/x]_(i <- r | P i) F i) x. Proof. by rewrite [LHS]bigmin_idl minC. Qed. Lemma bigmax_idr P F : \big[max/x]_(i <- r | P i) F i = max (\big[max/x]_(i <- r | P i) F i) x. Proof. by rewrite [LHS]bigmax_idl maxC. Qed. Lemma bigminID a P F : \big[min/x]_(i <- r | P i) F i = min (\big[min/x]_(i <- r | P i && a i) F i) (\big[min/x]_(i <- r | P i && ~~ a i) F i). Proof. by rewrite (bigID_idem _ _ a) //= minxx. Qed. Lemma bigmaxID a P F : \big[max/x]_(i <- r | P i) F i = max (\big[max/x]_(i <- r | P i && a i) F i) (\big[max/x]_(i <- r | P i && ~~ a i) F i). Proof. by rewrite (bigID_idem _ _ a) //= maxxx. Qed. End bigminmax_Type. Let ge_min_id (x y : T) : x >= min x y. Proof. by rewrite ge_min lexx. Qed. Let le_max_id (x y : T) : x <= max x y. Proof. by rewrite le_max lexx. Qed. Lemma sub_bigmin [x0] I r (P P' : {pred I}) (F : I -> T) : (forall i, P' i -> P i) -> \big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r | P' i) F i. Proof. exact: (sub_le_big ge_refl). Qed. Lemma sub_bigmax [x0] I r (P P' : {pred I}) (F : I -> T) : (forall i, P i -> P' i) -> \big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r | P' i) F i. Proof. exact: sub_le_big. Qed. (* FIXME: Remove that. *) Local Notation "'{subset' x '<=' y '}'" := (sub_mem (mem x) (mem y)) (at level 0, x, y at level 1). Lemma sub_bigmin_seq [x0] (I : eqType) r r' P (F : I -> T) : {subset r' <= r} -> \big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r' | P i) F i. Proof. exact: (idem_sub_le_big ge_refl _ minxx). Qed. Lemma sub_bigmax_seq [x0] (I : eqType) r r' P (F : I -> T) : {subset r <= r'} -> \big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r' | P i) F i. Proof. exact: (idem_sub_le_big _ _ maxxx). Qed. Lemma sub_bigmin_cond [x0] (I : eqType) r r' P P' (F : I -> T) : {subset ([seq i <- r | P i]) <= ([seq i <- r' | P' i])} -> \big[min/x0]_(i <- r' | P' i) F i <= \big[min/x0]_(i <- r | P i) F i. Proof. exact: (idem_sub_le_big_cond ge_refl _ minxx). Qed. Lemma sub_bigmax_cond [x0] (I : eqType) r r' P P' (F : I -> T) : {subset ([seq i <- r | P i]) <= ([seq i <- r' | P' i])} -> \big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r' | P' i) F i. Proof. exact: (idem_sub_le_big_cond _ _ maxxx). Qed. Lemma sub_in_bigmin [x0] [I : eqType] (r : seq I) (P P' : {pred I}) F : {in r, forall i, P' i -> P i} -> \big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r | P' i) F i. Proof. exact: (sub_in_le_big ge_refl). Qed. Lemma sub_in_bigmax [x0] [I : eqType] (r : seq I) (P P' : {pred I}) F : {in r, forall i, P i -> P' i} -> \big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r | P' i) F i. Proof. exact: sub_in_le_big. Qed. Lemma le_bigmin_nat [x0] n m n' m' P (F : nat -> T) : (n <= n')%N -> (m' <= m)%N -> \big[min/x0]_(n <= i < m | P i) F i <= \big[min/x0]_(n' <= i < m' | P i) F i. Proof. exact: (le_big_nat ge_refl). Qed. Lemma le_bigmax_nat [x0] n m n' m' P (F : nat -> T) : (n' <= n)%N -> (m <= m')%N -> \big[max/x0]_(n <= i < m | P i) F i <= \big[max/x0]_(n' <= i < m' | P i) F i. Proof. exact: le_big_nat. Qed. Lemma le_bigmin_nat_cond [x0] n m n' m' (P P' : pred nat) (F : nat -> T) : (n <= n')%N -> (m' <= m)%N -> (forall i, (n' <= i < m')%N -> P' i -> P i) -> \big[min/x0]_(n <= i < m | P i) F i <= \big[min/x0]_(n' <= i < m' | P' i) F i. Proof. exact: (le_big_nat_cond ge_refl). Qed. Lemma le_bigmax_nat_cond [x0] n m n' m' (P P' : {pred nat}) (F : nat -> T) : (n' <= n)%N -> (m <= m')%N -> (forall i, (n <= i < m)%N -> P i -> P' i) -> \big[max/x0]_(n <= i < m | P i) F i <= \big[max/x0]_(n' <= i < m' | P' i) F i. Proof. exact: le_big_nat_cond. Qed. Lemma le_bigmin_ord [x0] n m (P : pred nat) (F : nat -> T) : (m <= n)%N -> \big[min/x0]_(i < n | P i) F i <= \big[min/x0]_(i < m | P i) F i. Proof. exact: (le_big_ord ge_refl). Qed. Lemma le_bigmax_ord [x0] n m (P : {pred nat}) (F : nat -> T) : (n <= m)%N -> \big[max/x0]_(i < n | P i) F i <= \big[max/x0]_(i < m | P i) F i. Proof. exact: le_big_ord. Qed. Lemma le_bigmin_ord_cond [x0] n m (P P' : pred nat) (F : nat -> T) : (m <= n)%N -> (forall i : 'I_m, P' i -> P i) -> \big[min/x0]_(i < n | P i) F i <= \big[min/x0]_(i < m | P' i) F i. Proof. exact: (le_big_ord_cond ge_refl). Qed. Lemma le_bigmax_ord_cond [x0] n m (P P' : {pred nat}) (F : nat -> T) : (n <= m)%N -> (forall i : 'I_n, P i -> P' i) -> \big[max/x0]_(i < n | P i) F i <= \big[max/x0]_(i < m | P' i) F i. Proof. exact: le_big_ord_cond. Qed. Lemma subset_bigmin [x0] [I : finType] [A A' P : {pred I}] (F : I -> T) : A' \subset A -> \big[min/x0]_(i in A | P i) F i <= \big[min/x0]_(i in A' | P i) F i. Proof. exact: (subset_le_big ge_refl). Qed. Lemma subset_bigmax [x0] [I : finType] (A A' P : {pred I}) (F : I -> T) : A \subset A' -> \big[max/x0]_(i in A | P i) F i <= \big[max/x0]_(i in A' | P i) F i. Proof. exact: subset_le_big. Qed. Lemma subset_bigmin_cond [x0] (I : finType) (A A' P P' : {pred I}) (F : I -> T) : [set i in A' | P' i] \subset [set i in A | P i] -> \big[min/x0]_(i in A | P i) F i <= \big[min/x0]_(i in A' | P' i) F i. Proof. exact: (subset_le_big_cond ge_refl). Qed. Lemma subset_bigmax_cond [x0] (I : finType) (A A' P P' : {pred I}) (F : I -> T) : [set i in A | P i] \subset [set i in A' | P' i] -> \big[max/x0]_(i in A | P i) F i <= \big[max/x0]_(i in A' | P' i) F i. Proof. exact: subset_le_big_cond. Qed. Section bigminmax_eqType. Context (I : eqType) (r : seq I) (x : T). Implicit Types (P : pred I) (F : I -> T). Lemma bigmin_le_id P F : \big[min/x]_(i <- r | P i) F i <= x. Proof. by rewrite bigmin_idl. Qed. Lemma bigmax_ge_id P F : \big[max/x]_(i <- r | P i) F i >= x. Proof. by rewrite bigmax_idl. Qed. Lemma bigmin_eq_id P F : (forall i, P i -> x <= F i) -> \big[min/x]_(i <- r | P i) F i = x. Proof. by move=> x_le; apply: le_anti; rewrite bigmin_le_id le_bigmin. Qed. Lemma bigmax_eq_id P F : (forall i, P i -> x >= F i) -> \big[max/x]_(i <- r | P i) F i = x. Proof. by move=> x_ge; apply: le_anti; rewrite bigmax_ge_id bigmax_le. Qed. End bigminmax_eqType. Section bigminmax_finType. Context (I : finType) (x : T). Implicit Types (P : pred I) (F : I -> T). Lemma bigminD1 j P F : P j -> \big[min/x]_(i | P i) F i = min (F j) (\big[min/x]_(i | P i && (i != j)) F i). Proof. by move/(bigD1 _) ->. Qed. Lemma bigmaxD1 j P F : P j -> \big[max/x]_(i | P i) F i = max (F j) (\big[max/x]_(i | P i && (i != j)) F i). Proof. by move/(bigD1 _) ->. Qed. Lemma bigmin_le_cond j P F : P j -> \big[min/x]_(i | P i) F i <= F j. Proof. have := mem_index_enum j; rewrite unlock; elim: (index_enum I) => //= i l ih. rewrite inE => /orP [/eqP-> ->|/ih leminlfi Pi]; first by rewrite ge_min lexx. by case: ifPn => Pj; [rewrite ge_min leminlfi// orbC|exact: leminlfi]. Qed. Lemma le_bigmax_cond j P F : P j -> F j <= \big[max/x]_(i | P i) F i. Proof. by move=> Pj; rewrite (bigmaxD1 _ Pj) le_max lexx. Qed. Lemma bigmin_le j F : \big[min/x]_i F i <= F j. Proof. exact: bigmin_le_cond. Qed. Lemma le_bigmax F j : F j <= \big[max/x]_i F i. Proof. exact: le_bigmax_cond. Qed. Lemma bigmin_inf j P m F : P j -> F j <= m -> \big[min/x]_(i | P i) F i <= m. Proof. by move=> Pj ?; apply: le_trans (bigmin_le_cond _ Pj) _. Qed. (* NB: as of [2022-08-02], bigop.bigmax_sup already exists for nat *) Lemma bigmax_sup j P m F : P j -> m <= F j -> m <= \big[max/x]_(i | P i) F i. Proof. by move=> Pj ?; apply: le_trans (le_bigmax_cond _ Pj). Qed. Lemma bigmin_geP m P F : reflect (m <= x /\ forall i, P i -> m <= F i) (m <= \big[min/x]_(i | P i) F i). Proof. apply: (iffP idP) => [lemFi|[lemx lemPi]]; [split|exact: le_bigmin]. - by rewrite (le_trans lemFi)// bigmin_idl ge_min lexx. - by move=> i Pi; rewrite (le_trans lemFi)// (bigminD1 _ Pi)// le_minl lexx. Qed. Lemma bigmax_leP m P F : reflect (x <= m /\ forall i, P i -> F i <= m) (\big[max/x]_(i | P i) F i <= m). Proof. apply: (iffP idP) => [|[? ?]]; last exact: bigmax_le. rewrite bigmax_idl ge_max => /andP[-> leFm]; split=> // i Pi. by apply: le_trans leFm; exact: le_bigmax_cond. Qed. Lemma bigmin_gtP m P F : reflect (m < x /\ forall i, P i -> m < F i) (m < \big[min/x]_(i | P i) F i). Proof. apply: (iffP idP) => [lemFi|[lemx lemPi]]; [split|exact: lt_bigmin]. - by rewrite (lt_le_trans lemFi)// bigmin_idl ge_min lexx. - by move=> i Pi; rewrite (lt_le_trans lemFi)// (bigminD1 _ Pi)// le_minl lexx. Qed. Lemma bigmax_ltP m P F : reflect (x < m /\ forall i, P i -> F i < m) (\big[max/x]_(i | P i) F i < m). Proof. apply: (iffP idP) => [|[? ?]]; last exact: bigmax_lt. rewrite bigmax_idl gt_max => /andP[-> ltFm]; split=> // i Pi. by apply: le_lt_trans ltFm; exact: le_bigmax_cond. Qed. Lemma bigmin_eq_arg j P F : P j -> (forall i, P i -> F i <= x) -> \big[min/x]_(i | P i) F i = F [arg min_(i < j | P i) F i]. Proof. move=> Pi0; case: arg_minP => //= i Pi PF PFx. apply/eqP; rewrite eq_le bigmin_le_cond //=. by apply/bigmin_geP; split => //; exact: PFx. Qed. Lemma bigmax_eq_arg j P F : P j -> (forall i, P i -> x <= F i) -> \big[max/x]_(i | P i) F i = F [arg max_(i > j | P i) F i]. Proof. move=> Pi0; case: arg_maxP => //= i Pi PF PxF. apply/eqP; rewrite eq_le le_bigmax_cond // andbT. by apply/bigmax_leP; split => //; exact: PxF. Qed. Lemma eq_bigmin j P F : P j -> (forall i, P i -> F i <= x) -> {i0 | i0 \in P & \big[min/x]_(i | P i) F i = F i0}. Proof. by move=> Pi0 Hx; rewrite (bigmin_eq_arg Pi0) //; eexists=> //; case: arg_minP. Qed. Lemma eq_bigmax j P F : P j -> (forall i, P i -> x <= F i) -> {i0 | i0 \in P & \big[max/x]_(i | P i) F i = F i0}. Proof. by move=> Pi0 Hx; rewrite (bigmax_eq_arg Pi0) //; eexists=> //; case: arg_maxP. Qed. Lemma le_bigmin2 P F1 F2 : (forall i, P i -> F1 i <= F2 i) -> \big[min/x]_(i | P i) F1 i <= \big[min/x]_(i | P i) F2 i. Proof. move=> FG; elim/big_ind2 : _ => // a b e f ba fe. rewrite ge_min 2!le_min ba fe /= andbT. move: (le_total a e) => /orP[/(le_trans ba)-> // | /(le_trans fe)->]. by rewrite orbT. Qed. Lemma le_bigmax2 P F1 F2 : (forall i, P i -> F1 i <= F2 i) -> \big[max/x]_(i | P i) F1 i <= \big[max/x]_(i | P i) F2 i. Proof. move=> FG; elim/big_ind2 : _ => // a b e f ba fe. rewrite le_max 2!ge_max ba fe /= andbT; have [//|/= af] := leP f a. by rewrite (le_trans ba) // (le_trans _ fe) // ltW. Qed. Lemma bigmaxUl (A B : {set I}) F : \big[max/x]_(i in A) F i <= \big[max/x]_(i in A :|: B) F i. Proof. by apply: sub_bigmax => t; rewrite in_setU => ->. Qed. Lemma bigmaxUr (A B : {set I}) F : \big[max/x]_(i in B) F i <= \big[max/x]_(i in A :|: B) F i. Proof. by under [leRHS]eq_bigl do rewrite setUC; apply: bigmaxUl. Qed. Lemma bigminUl (A B : {set I}) F : \big[min/x]_(i in A) F i >= \big[min/x]_(i in A :|: B) F i. Proof. by apply: sub_bigmin => t; rewrite in_setU => ->. Qed. Lemma bigminUr (A B : {set I}) F : \big[min/x]_(i in B) F i >= \big[min/x]_(i in A :|: B) F i. Proof. by under [leLHS]eq_bigl do rewrite setUC; apply: bigminUl. Qed. Lemma bigmaxIl (A B : {set I}) F : \big[max/x]_(i in A) F i >= \big[max/x]_(i in A :&: B) F i. Proof. by apply: sub_bigmax => t; rewrite in_setI => /andP[-> _]. Qed. Lemma bigmaxIr (A B : {set I}) F : \big[max/x]_(i in B) F i >= \big[max/x]_(i in A :&: B) F i. Proof. by under eq_bigl do rewrite setIC; apply: bigmaxIl. Qed. Lemma bigminIl (A B : {set I}) F : \big[min/x]_(i in A) F i <= \big[min/x]_(i in A :&: B) F i. Proof. by apply: sub_bigmin => t; rewrite in_setI => /andP[->_]. Qed. Lemma bigminIr (A B : {set I}) F : \big[min/x]_(i in B) F i <= \big[min/x]_(i in A :&: B) F i. Proof. by under [leRHS]eq_bigl do rewrite setIC; apply: bigminIl. Qed. Lemma bigmaxD (A B : {set I}) F : \big[max/x]_(i in B) F i >= \big[max/x]_(i in B :\: A) F i. Proof. by apply: sub_bigmax => t; rewrite in_setD => /andP[_->]. Qed. Lemma bigminD (A B : {set I}) F : \big[min/x]_(i in B) F i <= \big[min/x]_(i in B :\: A) F i. Proof. by apply: sub_bigmin => t; rewrite in_setD => /andP[_->]. Qed. Lemma bigmaxU (A B : {set I}) F : \big[max/x]_(i in A :|: B) F i = max (\big[max/x]_(i in A) F i) (\big[max/x]_(i in B) F i). Proof. apply: le_anti; rewrite ge_max bigmaxUl bigmaxUr !andbT; apply/bigmax_leP. split=> [|i /[!in_setU]/orP[iA|iB]]; first by rewrite le_max bigmax_ge_id. - by rewrite le_max le_bigmax_cond. - by rewrite le_max orbC le_bigmax_cond. Qed. Lemma bigminU (A B : {set I}) F : \big[min/x]_(i in A :|: B) F i = min (\big[min/x]_(i in A) F i) (\big[min/x]_(i in B) F i). Proof. apply: le_anti; rewrite le_min bigminUl bigminUr !andbT; apply/bigmin_geP. split=> [|i /[!in_setU]/orP[iA|iB]]; first by rewrite ge_min bigmin_le_id. - by rewrite ge_min bigmin_le_cond. - by rewrite ge_min orbC bigmin_le_cond. Qed. Lemma bigmin_set1 j F : \big[min/x]_(i in [set j]) F i = min (F j) x. Proof. exact: big_set1E. Qed. Lemma bigmax_set1 j F : \big[max/x]_(i in [set j]) F i = max (F j) x. Proof. exact: big_set1E. Qed. End bigminmax_finType. Lemma bigmin_imset [I J : finType] x [h : I -> J] [A : {set I}] (F : J -> T) : \big[min/x]_(j in [set h x | x in A]) F j = \big[min/x]_(i in A) F (h i). Proof. by apply: big_imset_idem; apply: minxx. Qed. Lemma bigmax_imset [I J : finType] x [h : I -> J] [A : {set I}] (F : J -> T) : \big[max/x]_(j in [set h x | x in A]) F j = \big[max/x]_(i in A) F (h i). Proof. by apply: big_imset_idem; apply: maxxx. Qed. End TotalTheory. #[global] Hint Resolve le_total : core. #[global] Hint Resolve ge_total : core. #[global] Hint Extern 0 (is_true (_ >=< _)%O) => solve [apply: comparableT] : core. #[global] Hint Resolve sort_le_sorted : core. Arguments min_idPr {disp T x y}. Arguments max_idPl {disp T x y}. Arguments bigmin_mkcond {disp T I r}. Arguments bigmax_mkcond {disp T I r}. Arguments bigminID {disp T I r}. Arguments bigmaxID {disp T I r}. Arguments bigminD1 {disp T I x} j. Arguments bigmaxD1 {disp T I x} j. Arguments bigmin_inf {disp T I x} j. Arguments bigmax_sup {disp T I x} j. Arguments bigmin_eq_arg {disp T I} x j. Arguments bigmax_eq_arg {disp T I} x j. Arguments eq_bigmin {disp T I x} j. Arguments eq_bigmax {disp T I x} j. (* FIXME: some lemmas in the following section should hold for any porderType *) Module Import DualTotalTheory. Section DualTotalTheory. Context {disp : disp_t} {T : orderType disp}. Implicit Type s : seq T. Lemma sorted_filter_gt x s : sorted <=%O s -> [seq y <- s | x < y] = drop (count (<= x) s) s. Proof. move=> s_sorted; rewrite count_le_gt -[LHS]revK -filter_rev. rewrite (@sorted_filter_lt _ T^d); first by rewrite take_rev revK count_rev. by rewrite rev_sorted. Qed. Lemma sorted_filter_ge x s : sorted <=%O s -> [seq y <- s | x <= y] = drop (count (< x) s) s. Proof. move=> s_sorted; rewrite count_lt_ge -[LHS]revK -filter_rev. rewrite (@sorted_filter_le _ T^d); first by rewrite take_rev revK count_rev. by rewrite rev_sorted. Qed. Lemma nth_count_ge x x0 s i : sorted <=%O s -> (count (< x) s <= i < size s)%N -> x <= nth x0 s i. Proof. move=> ss /andP[ige ilt]; rewrite -(subnKC ige) -nth_drop -sorted_filter_ge //. apply/(all_nthP _ (filter_all _ _)). by rewrite size_filter ltn_subLR // count_lt_ge subnK // count_size. Qed. Lemma nth_count_gt x x0 s i : sorted <=%O s -> (count (<= x) s <= i < size s)%N -> x < nth x0 s i. Proof. move=> ss /andP[ige ilt]; rewrite -(subnKC ige) -nth_drop -sorted_filter_gt //. apply/(all_nthP _ (filter_all _ _)). by rewrite size_filter ltn_subLR // count_le_gt subnK // count_size. Qed. Lemma nth_count_eq x x0 s i : sorted <=%O s -> (count (< x) s <= i < count (<= x) s)%N -> nth x0 s i = x. Proof. move=> ss /andP[ige ilt]; apply/le_anti. by rewrite nth_count_le// nth_count_ge// ige (leq_trans ilt (count_size _ _)). Qed. End DualTotalTheory. End DualTotalTheory. (* contra lemmas *) Section ContraTheory. Context {disp1 disp2 : disp_t} {T1 : porderType disp1} {T2 : orderType disp2}. Implicit Types (x y : T1) (z t : T2) (b : bool) (m n : nat) (P : Prop). Lemma contraTle b z t : (t < z -> ~~ b) -> (b -> z <= t). Proof. exact: comparable_contraTle. Qed. Lemma contraTlt b z t : (t <= z -> ~~ b) -> (b -> z < t). Proof. exact: comparable_contraTlt. Qed. Lemma contraPle P z t : (t < z -> ~ P) -> (P -> z <= t). Proof. exact: comparable_contraPle. Qed. Lemma contraPlt P z t : (t <= z -> ~ P) -> (P -> z < t). Proof. exact: comparable_contraPlt. Qed. Lemma contraNle b z t : (t < z -> b) -> (~~ b -> z <= t). Proof. exact: comparable_contraNle. Qed. Lemma contraNlt b z t : (t <= z -> b) -> (~~ b -> z < t). Proof. exact: comparable_contraNlt. Qed. Lemma contra_not_le P z t : (t < z -> P) -> (~ P -> z <= t). Proof. exact: comparable_contra_not_le. Qed. Lemma contra_not_lt P z t : (t <= z -> P) -> (~ P -> z < t). Proof. exact: comparable_contra_not_lt. Qed. Lemma contraFle b z t : (t < z -> b) -> (b = false -> z <= t). Proof. exact: comparable_contraFle. Qed. Lemma contraFlt b z t : (t <= z -> b) -> (b = false -> z < t). Proof. exact: comparable_contraFlt. Qed. Lemma contra_leq_le m n z t : (t < z -> (n < m)%N) -> ((m <= n)%N -> z <= t). Proof. exact: comparable_contra_leq_le. Qed. Lemma contra_leq_lt m n z t : (t <= z -> (n < m)%N) -> ((m <= n)%N -> z < t). Proof. exact: comparable_contra_leq_lt. Qed. Lemma contra_ltn_le m n z t : (t < z -> (n <= m)%N) -> ((m < n)%N -> z <= t). Proof. exact: comparable_contra_ltn_le. Qed. Lemma contra_ltn_lt m n z t : (t <= z -> (n <= m)%N) -> ((m < n)%N -> z < t). Proof. exact: comparable_contra_ltn_lt. Qed. Lemma contra_le x y z t : (t < z -> y < x) -> (x <= y -> z <= t). Proof. exact: comparable_contra_le. Qed. Lemma contra_le_lt x y z t : (t <= z -> y < x) -> (x <= y -> z < t). Proof. exact: comparable_contra_le_lt. Qed. Lemma contra_lt_le x y z t : (t < z -> y <= x) -> (x < y -> z <= t). Proof. exact: comparable_contra_lt_le. Qed. Lemma contra_lt x y z t : (t <= z -> y <= x) -> (x < y -> z < t). Proof. exact: comparable_contra_lt. Qed. End ContraTheory. Section TotalMonotonyTheory. Context {disp disp' : disp_t} {T : orderType disp} {T' : porderType disp'}. Context (D : {pred T}) (f : T -> T'). Implicit Types (x y z : T) (u v w : T'). Let leT_anti := @le_anti _ T. Let leT'_anti := @le_anti _ T'. Let ltT_neqAle := @lt_neqAle _ T. Let ltT'_neqAle := @lt_neqAle _ T'. Let ltT_def := @lt_def _ T. Let leT_total := @le_total _ T. Lemma le_mono : {homo f : x y / x < y} -> {mono f : x y / x <= y}. Proof. exact: total_homo_mono. Qed. Lemma le_nmono : {homo f : x y /~ x < y} -> {mono f : x y /~ x <= y}. Proof. by apply: total_homo_mono => // x y; rewrite eq_sym. Qed. Lemma le_mono_in : {in D &, {homo f : x y / x < y}} -> {in D &, {mono f : x y / x <= y}}. Proof. exact: total_homo_mono_in. Qed. Lemma le_nmono_in : {in D &, {homo f : x y /~ x < y}} -> {in D &, {mono f : x y /~ x <= y}}. Proof. by apply: total_homo_mono_in => // x y; rewrite eq_sym. Qed. End TotalMonotonyTheory. End TotalTheory. Module Import CDistrLatticeTheory. Section CDistrLatticeTheory. Context {disp : disp_t} {L : cDistrLatticeType disp}. Implicit Types (x y z : L). Lemma rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y. Proof. exact: rcomplPmeet. Qed. Lemma rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x. Proof. exact: rcomplPjoin. Qed. Lemma rcomplKI x y z : x <= y -> (x `|` z) `&` rcompl x y z = x. Proof. by move=> lexy; have := rcomplPmeet x y z; rewrite (meet_l lexy). Qed. Lemma rcomplKU x y z : x <= y -> (y `&` z) `|` rcompl x y z = y. Proof. by move=> lexy; have := rcomplPjoin x y z; rewrite (join_l lexy). Qed. End CDistrLatticeTheory. End CDistrLatticeTheory. Module Import CBDistrLatticeTheory. Section CBDistrLatticeTheory. Context {disp : disp_t} {L : cbDistrLatticeType disp}. Implicit Types (x y z : L). Lemma diffErcompl x y : x `\` y = rcompl \bot x y. Proof. exact: diffErcompl. Qed. Lemma diffKI x y : y `&` (x `\` y) = \bot. Proof. by have := rcomplKI y (le0x x); rewrite join0x diffErcompl. Qed. Lemma diffIK x y : (x `\` y) `&` y = \bot. Proof. by rewrite meetC diffKI. Qed. Lemma meetIB z x y : (z `&` y) `&` (x `\` y) = \bot. Proof. by rewrite -meetA diffKI meetx0. Qed. Lemma meetBI z x y : (x `\` y) `&` (z `&` y) = \bot. Proof. by rewrite meetC meetIB. Qed. Lemma joinIB y x : (x `&` y) `|` (x `\` y) = x. Proof. by rewrite diffErcompl rcomplKU. Qed. Lemma joinBI y x : (x `\` y) `|` (x `&` y) = x. Proof. by rewrite joinC joinIB. Qed. Lemma joinIBC y x : (y `&` x) `|` (x `\` y) = x. Proof. by rewrite meetC joinIB. Qed. Lemma joinBIC y x : (x `\` y) `|` (y `&` x) = x. Proof. by rewrite meetC joinBI. Qed. Lemma leBx x y : x `\` y <= x. Proof. by rewrite -[leRHS](joinIB y) leUr. Qed. Hint Resolve leBx : core. Lemma diffxx x : x `\` x = \bot. Proof. by have := diffKI x x; rewrite meet_r. Qed. Lemma leBl z x y : x <= y -> x `\` z <= y `\` z. Proof. rewrite -[leLHS](joinIB z) -[leRHS](joinIB z). by rewrite leU2E ?meetIB ?meetBI // => /andP []. Qed. Lemma diffKU y x : y `|` (x `\` y) = y `|` x. Proof. apply/eqP; rewrite eq_le leU2 //= leUx leUl. by apply/meet_idPl; have := joinIB y x; rewrite joinIl join_l. Qed. Lemma diffUK y x : (x `\` y) `|` y = x `|` y. Proof. by rewrite joinC diffKU joinC. Qed. Lemma leBKU y x : y <= x -> y `|` (x `\` y) = x. Proof. by move=> /join_r {2}<-; rewrite diffKU. Qed. Lemma leBUK y x : y <= x -> (x `\` y) `|` y = x. Proof. by move=> leyx; rewrite joinC leBKU. Qed. Lemma leBLR x y z : (x `\` y <= z) = (x <= y `|` z). Proof. apply/idP/idP; first by move=> /join_r <-; rewrite joinA diffKU joinAC leUr. by rewrite -{1}[x](joinIB y) => /(leU2r_le (diffIK _ _)). Qed. Lemma diffUx x y z : (x `|` y) `\` z = (x `\` z) `|` (y `\` z). Proof. apply/eqP; rewrite eq_le leUx !leBl ?leUr ?leUl ?andbT //. by rewrite leBLR joinA diffKU joinAC diffKU joinAC -joinA leUr. Qed. Lemma diff_eq0 x y : (x `\` y == \bot) = (x <= y). Proof. by rewrite -lex0 leBLR joinx0. Qed. Lemma joinxB x y z : x `|` (y `\` z) = ((x `|` y) `\` z) `|` (x `&` z). Proof. by rewrite diffUx joinAC joinBI. Qed. Lemma joinBx x y z : (y `\` z) `|` x = ((y `|` x) `\` z) `|` (z `&` x). Proof. by rewrite ![_ `|` x]joinC ![_ `&` x]meetC joinxB. Qed. Lemma leBr z x y : x <= y -> z `\` y <= z `\` x. Proof. by move=> lexy; rewrite leBLR joinxB meet_r ?leBUK ?leUr ?lexUl. Qed. Lemma leB2 x y z t : x <= z -> t <= y -> x `\` y <= z `\` t. Proof. by move=> /(@leBl t) ? /(@leBr x) /le_trans ->. Qed. Lemma meet_eq0E_diff z x y : x <= z -> (x `&` y == \bot) = (x <= z `\` y). Proof. move=> xz; apply/idP/idP; last by move=> /meet_r <-; rewrite -meetA meetBI. by move=> /eqP xIy_eq0; rewrite -[x](joinIB y) xIy_eq0 join0x leBl. Qed. Lemma leBRL x y z : (x <= z `\` y) = (x <= z) && (x `&` y == \bot). Proof. apply/idP/idP => [xyz|]; first by rewrite (@meet_eq0E_diff z) // (le_trans xyz). by move=> /andP [?]; rewrite -meet_eq0E_diff. Qed. Lemma eq_diff x y z : (x `\` y == z) = (z <= x <= y `|` z) && (z `&` y == \bot). Proof. by rewrite eq_le leBLR leBRL andbCA andbA. Qed. Lemma diffxU x y z : z `\` (x `|` y) = (z `\` x) `&` (z `\` y). Proof. apply/eqP; rewrite eq_le lexI !leBr ?leUl ?leUr //=. rewrite leBRL leIx2 ?leBx //= meetUr meetAC diffIK -meetA diffIK. by rewrite meet0x meetx0 joinx0. Qed. Lemma diffx0 x : x `\` \bot = x. Proof. by apply/eqP; rewrite eq_diff join0x meetx0 lexx eqxx. Qed. Lemma diff0x x : \bot `\` x = \bot. Proof. by apply/eqP; rewrite eq_diff joinx0 meet0x lexx eqxx le0x. Qed. Lemma diffIx x y z : (x `&` y) `\` z = (x `\` z) `&` (y `\` z). Proof. apply/eqP; rewrite eq_diff joinIr ?leI2 ?diffKU ?leUr ?leBx //=. by rewrite -meetA diffIK meetx0. Qed. Lemma meetxB x y z : x `&` (y `\` z) = (x `&` y) `\` z. Proof. by rewrite diffIx -{1}[x](joinBI z) meetUl meetIB joinx0. Qed. Lemma meetBx x y z : (x `\` y) `&` z = (x `&` z) `\` y. Proof. by rewrite ![_ `&` z]meetC meetxB. Qed. Lemma diffxI x y z : x `\` (y `&` z) = (x `\` y) `|` (x `\` z). Proof. apply/eqP; rewrite eq_diff leUx !leBx //= joinIl joinA joinCA !diffKU. rewrite joinCA -joinA [_ `|` x]joinC ![x `|` _]join_l //. by rewrite -joinIl leUr /= meetUl {1}[_ `&` z]meetC ?meetBI joinx0. Qed. Lemma diffBx x y z : (x `\` y) `\` z = x `\` (y `|` z). Proof. apply/eqP; rewrite eq_diff leBr ?leUl //=. by rewrite diffxU joinIr diffKU -joinIr meet_l ?leUr //= -meetA diffIK meetx0. Qed. Lemma diffxB x y z : x `\` (y `\` z) = (x `\` y) `|` (x `&` z). Proof. rewrite -[y in RHS](joinIB z) diffxU joinIl diffxI -joinA joinBI join_r //. by rewrite joinBx meetKU meetA meetAC diffIK meet0x joinx0 meet_r. Qed. Lemma joinBK x y : (y `|` x) `\` x = (y `\` x). Proof. by rewrite diffUx diffxx joinx0. Qed. Lemma joinBKC x y : (x `|` y) `\` x = (y `\` x). Proof. by rewrite diffUx diffxx join0x. Qed. Lemma disj_le x y : x `&` y == \bot -> x <= y = (x == \bot). Proof. by rewrite [x == \bot]eq_sym -eq_meetl => /eqP ->. Qed. Lemma disj_leC x y : y `&` x == \bot -> x <= y = (x == \bot). Proof. by rewrite meetC => /disj_le. Qed. Lemma disj_diffl x y : x `&` y == \bot -> x `\` y = x. Proof. by move=> dxy; apply/eqP; rewrite eq_diff dxy lexx leUr. Qed. Lemma disj_diffr x y : x `&` y == \bot -> y `\` x = y. Proof. by rewrite meetC => /disj_diffl. Qed. Lemma lt0B x y : x < y -> \bot < y `\` x. Proof. by move=> ?; rewrite lt_leAnge le0x leBLR joinx0 /= lt_geF. Qed. End CBDistrLatticeTheory. End CBDistrLatticeTheory. Module Import CTDistrLatticeTheory. Section CTDistrLatticeTheory. Context {disp : disp_t} {L : ctDistrLatticeType disp}. Implicit Types (x y z : L). Lemma codiffErcompl x y : codiff x y = rcompl x \top y. Proof. exact: codiffErcompl. Qed. (* TODO: complete this theory module *) End CTDistrLatticeTheory. End CTDistrLatticeTheory. Module Import CTBDistrLatticeTheory. Section CTBDistrLatticeTheory. Context {disp : disp_t} {L : ctbDistrLatticeType disp}. Implicit Types (x y z : L). Lemma complEdiff x : ~` x = \top `\` x. Proof. exact: complEdiff. Qed. #[deprecated(since="mathcomp 2.3.0", note="Use complEdiff instead.")] Notation complE := complEdiff. Lemma complEcodiff x : ~` x = codiff \bot x. Proof. exact: complEcodiff. Qed. Lemma complErcompl x : ~` x = rcompl \bot \top x. Proof. by rewrite complEdiff diffErcompl. Qed. Lemma diff1x x : \top `\` x = ~` x. Proof. exact/esym/complEdiff. Qed. Lemma diffE x y : x `\` y = x `&` ~` y. Proof. by rewrite complEdiff meetxB meetx1. Qed. Lemma complK : involutive (@compl _ L). Proof. by move=> x; rewrite !complEdiff diffxB diffxx meet1x join0x. Qed. Lemma compl_inj : injective (@compl _ L). Proof. exact/inv_inj/complK. Qed. Lemma disj_leC x y : (x `&` y == \bot) = (x <= ~` y). Proof. by rewrite -diff_eq0 diffE complK. Qed. Lemma leCx x y : (~` x <= y) = (~` y <= x). Proof. by rewrite !complEdiff !leBLR joinC. Qed. Lemma lexC x y : (x <= ~` y) = (y <= ~` x). Proof. by rewrite -[x in LHS]complK leCx complK. Qed. Lemma leC x y : (~` x <= ~` y) = (y <= x). Proof. by rewrite leCx complK. Qed. Lemma complU x y : ~` (x `|` y) = ~` x `&` ~` y. Proof. by rewrite !complEdiff diffxU. Qed. Lemma complI x y : ~` (x `&` y) = ~` x `|` ~` y. Proof. by rewrite !complEdiff diffxI. Qed. Lemma joinxC x : x `|` ~` x = \top. Proof. by rewrite complEdiff diffKU joinx1. Qed. Lemma joinCx x : ~` x `|` x = \top. Proof. by rewrite joinC joinxC. Qed. Lemma meetxC x : x `&` ~` x = \bot. Proof. by rewrite complEdiff diffKI. Qed. Lemma meetCx x : ~` x `&` x = \bot. Proof. by rewrite meetC meetxC. Qed. Lemma compl1 : ~` \top = \bot :> L. Proof. by rewrite complEdiff diffxx. Qed. Lemma compl0 : ~` \bot = \top :> L. Proof. by rewrite -compl1 complK. Qed. Lemma complB x y : ~` (x `\` y) = ~` x `|` y. Proof. by rewrite diffE complI complK. Qed. Lemma leBC x y : x `\` y <= ~` y. Proof. by rewrite leBLR joinxC lex1. Qed. Lemma compl_joins (J : Type) (r : seq J) (P : {pred J}) (F : J -> L) : ~` (\join_(j <- r | P j) F j) = \meet_(j <- r | P j) ~` F j. Proof. by elim/big_rec2: _=> [|i x y ? <-]; rewrite ?compl0 ?complU. Qed. Lemma compl_meets (J : Type) (r : seq J) (P : {pred J}) (F : J -> L) : ~` (\meet_(j <- r | P j) F j) = \join_(j <- r | P j) ~` F j. Proof. by elim/big_rec2: _=> [|i x y ? <-]; rewrite ?compl1 ?complI. Qed. End CTBDistrLatticeTheory. End CTBDistrLatticeTheory. (*************) (* FACTORIES *) (*************) (* porderType *) HB.factory Record Preorder_isPOrder (d : disp_t) T of Preorder d T := { le_anti : antisymmetric (@le d T); }. HB.builders Context (d : disp_t) T of Preorder_isPOrder d T. Let ge_anti : antisymmetric (fun x y => @le d T y x). Proof. by move=> x y; rewrite andbC; apply: le_anti. Qed. HB.instance Definition _ := Preorder_isDuallyPOrder.Build d T le_anti ge_anti. HB.end. HB.factory Record isPOrder (d : disp_t) T of Choice T := { le : rel T; lt : rel T; lt_def : forall x y, lt x y = (y != x) && (le x y); le_refl : reflexive le; le_anti : antisymmetric le; le_trans : transitive le; }. HB.builders Context (d : disp_t) T of isPOrder d T. Let lt_le_def x y : lt x y = le x y && ~~ le y x. Proof. rewrite lt_def andbC; case /boolP: (le x y) => //= xy. have [->|/negP xyE /=] := eqVneq y x; first by rewrite le_refl. by apply/esym/negP => yx; apply/xyE/eqP/le_anti; rewrite yx. Qed. HB.instance Definition _ := isPreorder.Build d T lt_le_def le_refl le_trans. HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti. HB.end. HB.factory Record Le_isPOrder (d : disp_t) T of Choice T := { le : rel T; le_refl : reflexive le; le_anti : antisymmetric le; le_trans : transitive le; }. HB.builders Context (d : disp_t) T of Le_isPOrder d T. (* TODO: print nice error message when keyed type is not provided *) HB.instance Definition _ := @Le_isPreorder.Build d T le le_refl le_trans. HB.instance Definition _ := @Preorder_isPOrder.Build d T le_anti. HB.end. HB.factory Record LtLe_isPOrder (d : disp_t) T of Choice T := { le : rel T; lt : rel T; le_def : forall x y, le x y = (x == y) || lt x y; lt_irr : irreflexive lt; lt_trans : transitive lt; }. HB.builders Context (d : disp_t) T of LtLe_isPOrder d T. HB.instance Definition _ := @LtLe_isPreorder.Build d T le lt le_def lt_irr lt_trans. Let le_anti : antisymmetric le. Proof. move=> x y; rewrite !le_def [y == _]eq_sym. have [//|neq_xy/=] := eqVneq x y => /andP[xy yx]. by have := lt_trans xy yx; rewrite lt_irr. Qed. HB.instance Definition _ := @Preorder_isPOrder.Build d T le_anti. HB.end. HB.factory Record Lt_isPOrder (d : disp_t) T of Choice T := { lt : rel T; lt_irr : irreflexive lt; lt_trans : transitive lt; }. HB.builders Context d T of Lt_isPOrder d T. #[warning="-HB.no-new-instance"] HB.instance Definition _ := @LtLe_isPOrder.Build d T _ lt (fun _ _ => erefl) lt_irr lt_trans. HB.end. (* meetSemilatticeType and joinSemilatticeType *) HB.factory Record POrder_Meet_isSemilattice d T of POrder d T := { meet : T -> T -> T; meetC : commutative meet; meetA : associative meet; leEmeet : forall x y, (x <= y) = (meet x y == x); }. HB.builders Context d T of POrder_Meet_isSemilattice d T. Fact meetxx : idempotent_op meet. Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed. Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z). Proof. rewrite !leEmeet; apply/eqP/andP => [<-|[/eqP<- /eqP<-]]. split; apply/eqP; last by rewrite meetA -meetA meetxx. by rewrite -!meetA (meetC z) (meetA y) meetxx. by rewrite -!meetA (meetC z) -meetA (meetA y) !meetxx. Qed. HB.instance Definition _ := @POrder_isMeetSemilattice.Build d T meet lexI. HB.end. HB.factory Record POrder_Join_isSemilattice d T of POrder d T := { join : T -> T -> T; joinC : commutative join; joinA : associative join; leEjoin : forall x y, (y <= x) = (join x y == x); }. HB.builders Context d T of POrder_Join_isSemilattice d T. Fact joinxx : idempotent_op join. Proof. by move=> x; apply/eqP; rewrite -leEjoin. Qed. Fact leUx x y z : (join x y <= z) = (x <= z) && (y <= z). rewrite !leEjoin; apply/eqP/andP => [<-|[/eqP<- /eqP<-]]. split; apply/eqP; last by rewrite joinA -joinA joinxx. by rewrite -joinA (joinC _ x) (joinA x) joinxx. by rewrite -!joinA (joinC y) -joinA (joinA x) !joinxx. Qed. HB.instance Definition _ := @POrder_isJoinSemilattice.Build d T join leUx. HB.end. (* latticeType *) HB.factory Record POrder_MeetJoin_isLattice d T of POrder d T := { meet : T -> T -> T; join : T -> T -> T; meetP : forall x y z, (x <= meet y z) = (x <= y) && (x <= z); joinP : forall x y z, (join x y <= z) = (x <= z) && (y <= z); }. HB.builders Context d T of POrder_MeetJoin_isLattice d T. HB.instance Definition _ := @POrder_isMeetSemilattice.Build d T meet meetP. HB.instance Definition _ := @POrder_isJoinSemilattice.Build d T join joinP. HB.end. HB.factory Record POrder_isLattice d T of POrder d T := { meet : T -> T -> T; join : T -> T -> T; meetC : commutative meet; joinC : commutative join; meetA : associative meet; joinA : associative join; joinKI : forall y x, meet x (join x y) = x; meetKU : forall y x, join x (meet x y) = x; leEmeet : forall x y, (x <= y) = (meet x y == x); }. HB.builders Context d T of POrder_isLattice d T. Fact leEjoin x y : (y <= x) = (join x y == x). Proof. rewrite leEmeet; apply/eqP/eqP => <-. by rewrite meetC meetKU. by rewrite joinC joinKI. Qed. Fact meetxx : idempotent_op meet. Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed. Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z). Proof. rewrite !leEmeet; apply/eqP/andP => [<-|[/eqP<- /eqP<-]]. split; apply/eqP; last by rewrite meetA -meetA meetxx. by rewrite -!meetA (meetC z) (meetA y) meetxx. by rewrite -!meetA (meetC z) -meetA (meetA y) !meetxx. Qed. Fact joinxx : idempotent_op join. Proof. by move=> x; apply/eqP; rewrite -leEjoin. Qed. Fact leUx x y z : (join x y <= z) = (x <= z) && (y <= z). rewrite !leEjoin; apply/eqP/andP => [<-|[/eqP<- /eqP<-]]. split; apply/eqP; last by rewrite joinA -joinA joinxx. by rewrite -joinA (joinC _ x) (joinA x) joinxx. by rewrite -!joinA (joinC y) -joinA (joinA x) !joinxx. Qed. HB.instance Definition _ := @POrder_MeetJoin_isLattice.Build d T meet join lexI leUx. HB.end. (* distrLatticeType *) HB.factory Record Lattice_Meet_isDistrLattice d T of Lattice d T := { meetUl : @left_distributive T T meet join; }. HB.builders Context d T of Lattice_Meet_isDistrLattice d T. Let meetUr : right_distributive (@meet _ T) (@join _ T). Proof. by move=> x y z; rewrite ![x `&` _]meetC meetUl. Qed. Let joinIl : left_distributive (@join _ T) (@meet _ T). Proof. by move=> x y z; rewrite meetUr joinIK meetUl -joinA meetUKC. Qed. HB.instance Definition _ := Lattice_isDistributive.Build d T meetUl joinIl. HB.end. HB.factory Record POrder_Meet_isDistrLattice d T of POrder d T := { meet : T -> T -> T; join : T -> T -> T; meetC : commutative meet; joinC : commutative join; meetA : associative meet; joinA : associative join; joinKI : forall y x, meet x (join x y) = x; meetKU : forall y x, join x (meet x y) = x; leEmeet : forall x y, (x <= y) = (meet x y == x); meetUl : left_distributive meet join; }. HB.builders Context d T of POrder_Meet_isDistrLattice d T. HB.instance Definition _ := @POrder_isLattice.Build d T meet join meetC joinC meetA joinA joinKI meetKU leEmeet. HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build d T meetUl. HB.end. HB.factory Record isMeetJoinDistrLattice (d : disp_t) T of Choice T := { le : rel T; lt : rel T; meet : T -> T -> T; join : T -> T -> T; le_def : forall x y : T, le x y = (meet x y == x); lt_def : forall x y : T, lt x y = (y != x) && le x y; meetC : commutative meet; joinC : commutative join; meetA : associative meet; joinA : associative join; joinKI : forall y x : T, meet x (join x y) = x; meetKU : forall y x : T, join x (meet x y) = x; meetUl : left_distributive meet join; meetxx : idempotent_op meet; }. HB.builders Context d T of isMeetJoinDistrLattice d T. Fact le_refl : reflexive le. Proof. by move=> x; rewrite le_def meetxx. Qed. Fact le_anti : antisymmetric le. Proof. by move=> x y; rewrite !le_def meetC => /andP [] /eqP {2}<- /eqP ->. Qed. Fact le_trans : transitive le. Proof. move=> y x z; rewrite !le_def => /eqP lexy /eqP leyz; apply/eqP. by rewrite -[in LHS]lexy -meetA leyz lexy. Qed. Fact lt_le_def x y : lt x y = (le x y) && ~~ (le y x). Proof. rewrite lt_def andbC; case/boolP: (le x y) => //= xy. congr negb; apply/eqP/idP => [->|yx]; first exact/le_refl. by apply/le_anti/andP; split. Qed. HB.instance Definition _ := isPreorder.Build d T lt_le_def le_refl le_trans. HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti. HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build d T meet join meetC joinC meetA joinA joinKI meetKU le_def meetUl. HB.end. (* complemented lattices *) HB.factory Record BDistrLattice_hasSectionalComplement d T of BDistrLattice d T := { diff : T -> T -> T; diffKI : forall x y, y `&` diff x y = \bot; joinIB : forall x y, (x `&` y) `|` diff x y = x; }. Module hasRelativeComplement. #[deprecated(since="mathcomp 2.3.0", note="Use BDistrLattice_hasSectionalComplement.Build instead.")] Notation Build d T := (BDistrLattice_hasSectionalComplement.Build d T) (only parsing). End hasRelativeComplement. #[deprecated(since="mathcomp 2.3.0", note="Use BDistrLattice_hasSectionalComplement instead.")] Notation hasRelativeComplement d T := (BDistrLattice_hasSectionalComplement d T) (only parsing). HB.builders Context d T of BDistrLattice_hasSectionalComplement d T. Definition rcompl x y z := (x `&` y) `|` diff (y `|` x) z. Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y. Proof. by rewrite meetUr joinIKC meetUl diffKI joinx0 meetKU. Qed. Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x. Proof. by rewrite joinCA joinIB joinA meetUK joinC. Qed. HB.instance Definition _ := @DistrLattice_hasRelativeComplement.Build d T rcompl rcomplPmeet rcomplPjoin. Fact diffErcompl x y : diff x y = rcompl \bot x y. Proof. by rewrite /rcompl meet0x join0x joinx0. Qed. HB.instance Definition _ := @CDistrLattice_hasSectionalComplement.Build d T diff diffErcompl. HB.end. HB.factory Record TDistrLattice_hasDualSectionalComplement d T of TDistrLattice d T := { codiff : T -> T -> T; codiffKU : forall x y, y `|` codiff x y = \top; meetUB : forall x y, (x `|` y) `&` codiff x y = x; }. HB.builders Context d T of TDistrLattice_hasDualSectionalComplement d T. Definition rcompl x y z := (y `|` x) `&` codiff (x `&` y) z. Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y. Proof. by rewrite meetCA meetUB meetA joinIK. Qed. Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x. Proof. by rewrite joinIr meetUKC joinIl codiffKU meetx1 joinKI. Qed. HB.instance Definition _ := @DistrLattice_hasRelativeComplement.Build d T rcompl rcomplPmeet rcomplPjoin. Fact codiffErcompl x y : codiff x y = rcompl x \top y. Proof. by rewrite /rcompl join1x meet1x meetx1. Qed. HB.instance Definition _ := @CDistrLattice_hasDualSectionalComplement.Build d T codiff codiffErcompl. HB.end. HB.factory Record CBDistrLattice_hasComplement d T of CBDistrLattice d T & hasTop d T := { compl : T -> T; complEdiff : forall x, compl x = (\top : T) `\` x; (* FIXME *) }. Module hasComplement. #[deprecated(since="mathcomp 2.3.0", note="Use CBDistrLattice_hasComplement.Build instead.")] Notation Build d T := (CBDistrLattice_hasComplement.Build d T) (only parsing). End hasComplement. #[deprecated(since="mathcomp 2.3.0", note="Use CBDistrLattice_hasComplement instead.")] Notation hasComplement d T := (CBDistrLattice_hasComplement d T) (only parsing). HB.builders Context d T of CBDistrLattice_hasComplement d T. HB.instance Definition _ := @CDistrLattice_hasDualSectionalComplement.Build d T (fun x y => rcompl x \top y) (fun _ _ => erefl). Fact complEcodiff (x : T) : compl x = codiff (\bot : T) x. Proof. by rewrite complEdiff diffErcompl. Qed. HB.instance Definition _ := @CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff. HB.end. HB.factory Record CTDistrLattice_hasComplement d T of CTDistrLattice d T & hasBottom d T := { compl : T -> T; complEcodiff : forall x, compl x = codiff (\bot : T) x; }. HB.builders Context d T of CTDistrLattice_hasComplement d T. HB.instance Definition _ := @CDistrLattice_hasSectionalComplement.Build d T (fun x y => rcompl (\bot : T) x y) (fun _ _ => erefl). Fact complEdiff (x : T) : compl x = (\top : T) `\` x. Proof. by rewrite complEcodiff codiffErcompl. Qed. HB.instance Definition _ := @CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff. HB.end. HB.factory Record TBDistrLattice_hasComplement d T of TBDistrLattice d T := { compl : T -> T; joinxC : forall x, x `|` compl x = \top; meetxC : forall x, x `&` compl x = \bot; }. HB.builders Context d T of TBDistrLattice_hasComplement d T. Definition diff x y := x `&` compl y. Definition codiff x y := x `|` compl y. Definition rcompl x y z := (x `&` y) `|` diff (y `|` x) z. Fact diffKI x y : y `&` diff x y = \bot. Proof. by rewrite meetCA meetxC meetx0. Qed. Fact joinIB x y : (x `&` y) `|` diff x y = x. Proof. by rewrite -meetUr joinxC meetx1. Qed. HB.instance Definition _ := @BDistrLattice_hasSectionalComplement.Build d T diff diffKI joinIB. Fact codiffErcompl x y : codiff x y = rcompl x \top y. Proof. by rewrite /rcompl /diff join1x meetx1 meet1x. Qed. HB.instance Definition _ := @CDistrLattice_hasDualSectionalComplement.Build d T codiff codiffErcompl. Fact complEdiff x : compl x = diff \top x. Proof. exact/esym/meet1x. Qed. Fact complEcodiff x : compl x = codiff \bot x. Proof. exact/esym/join0x. Qed. HB.instance Definition _ := @CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff. HB.end. (* orderType *) HB.factory Record Lattice_isTotal d T of Lattice d T := { le_total : total (<=%O : rel T) }. HB.builders Context d T of Lattice_isTotal d T. Fact meetUl : @left_distributive T T meet join. Proof. pose leP x y := lcomparable_leP (le_total x y); move=> x y z; apply/esym. by case: (leP x y) (leP x z) (leP y z) => [|/ltW] xy [|/ltW] xz [|/ltW] yz; (apply/join_idPl || apply/join_idPr) => //; apply: le_trans xy. Qed. HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build d T meetUl. HB.instance Definition _ := DistrLattice_isTotal.Build d T le_total. HB.end. HB.factory Record POrder_isTotal d T of POrder d T := { le_total : total (<=%O : rel T) }. HB.builders Context d T of POrder_isTotal d T. Implicit Types (x y z : T). Let comparableT x y : x >=< y := le_total x y. Fact ltgtP x y : compare x y (min y x) (min x y) (max y x) (max x y) (y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y). Proof. exact: comparable_ltgtP. Qed. Fact leP x y : le_xor_gt x y (min y x) (min x y) (max y x) (max x y) (x <= y) (y < x). Proof. exact: comparable_leP. Qed. Definition meet := @min _ T. Definition join := @max _ T. Fact meetC : commutative meet. Proof. by move=> x y; rewrite /meet; have [] := ltgtP. Qed. Fact joinC : commutative join. Proof. by move=> x y; rewrite /join; have [] := ltgtP. Qed. Fact meetA : associative meet. Proof. move=> x y z; rewrite /meet /min !(fun_if, if_arg). case: (leP z y) (leP y x) (leP z x) => [] zy [] yx [] zx//=. by have := le_lt_trans (le_trans zy yx) zx; rewrite ltxx. by apply/eqP; rewrite eq_le zx ltW// (lt_trans yx). Qed. Fact joinA : associative join. Proof. move=> x y z; rewrite /meet /min !(fun_if, if_arg). case: (leP z y) (leP y x) (leP z x) => [] zy [] yx [] zx//=. by have := le_lt_trans (le_trans zy yx) zx; rewrite ltxx. by apply/eqP; rewrite eq_le zx ltW// (lt_trans yx). Qed. Fact joinKI y x : meet x (join x y) = x. Proof. rewrite /meet /join /min /max !(fun_if, if_arg). by have []// := ltgtP x y; rewrite ltxx. Qed. Fact meetKU y x : join x (meet x y) = x. Proof. rewrite /meet /join /min /max !(fun_if, if_arg). by have []// := ltgtP x y; rewrite ltxx. Qed. Fact leEmeet x y : (x <= y) = (meet x y == x). Proof. by rewrite /meet; case: leP => ?; rewrite ?eqxx ?lt_eqF. Qed. HB.instance Definition _ := @POrder_isLattice.Build d T meet join meetC joinC meetA joinA joinKI meetKU leEmeet. HB.instance Definition _ := Lattice_isTotal.Build d T comparableT. HB.end. HB.factory Record isOrder (d : disp_t) T of Choice T := { le : rel T; lt : rel T; meet : T -> T -> T; join : T -> T -> T; lt_def : forall x y, lt x y = (y != x) && le x y; meet_def : forall x y, meet x y = if lt x y then x else y; join_def : forall x y, join x y = if lt x y then y else x; le_anti : antisymmetric le; le_trans : transitive le; le_total : total le; }. HB.builders Context d T of isOrder d T. Fact le_refl : reflexive le. Proof. by move=> x; case: (le x x) (le_total x x). Qed. Fact lt_le_def x y : lt x y = (le x y) && ~~ (le y x). Proof. rewrite lt_def andbC; case/boolP: (le x y) => //= xy. congr negb; apply/eqP/idP => [->|yx]; first exact/le_refl. by apply/le_anti/andP; split. Qed. HB.instance Definition _ := isPreorder.Build d T lt_le_def le_refl le_trans. HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti. Section GeneratedOrder. Local Definition T' := T. HB.instance Definition _ := POrder.on T'. HB.instance Definition _ := POrder_isTotal.Build d T' le_total. Implicit Types (x y z : T'). Fact meetE x y : meet x y = x `&` y. Proof. by rewrite meet_def. Qed. Fact joinE x y : join x y = x `|` y. Proof. by rewrite join_def. Qed. Fact meetC : commutative meet. Proof. by move=> *; rewrite !meetE meetC. Qed. Fact joinC : commutative join. Proof. by move=> *; rewrite !joinE joinC. Qed. Fact meetA : associative meet. Proof. by move=> *; rewrite !meetE meetA. Qed. Fact joinA : associative join. Proof. by move=> *; rewrite !joinE joinA. Qed. Fact joinKI y x : meet x (join x y) = x. Proof. by rewrite meetE joinE joinKI. Qed. Fact meetKU y x : join x (meet x y) = x. Proof. by rewrite meetE joinE meetKU. Qed. Fact meetUl : left_distributive meet join. Proof. by move=> *; rewrite !meetE !joinE meetUl. Qed. Fact meetxx : idempotent_op meet. Proof. by move=> *; rewrite meetE meetxx. Qed. Fact le_def x y : x <= y = (meet x y == x). Proof. by rewrite meetE (eq_meetl x y). Qed. End GeneratedOrder. HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build d T meet join meetC joinC meetA joinA joinKI meetKU le_def meetUl. HB.instance Definition _ := DistrLattice_isTotal.Build d T le_total. HB.end. HB.factory Record LtOrder (d : disp_t) T of Choice T := { le : rel T; lt : rel T; meet : T -> T -> T; join : T -> T -> T; le_def : forall x y, le x y = (x == y) || lt x y; meet_def : forall x y, meet x y = if lt x y then x else y; join_def : forall x y, join x y = if lt x y then y else x; lt_irr : irreflexive lt; lt_trans : transitive lt; lt_total : forall x y, x != y -> lt x y || lt y x; }. HB.builders Context d T of LtOrder d T. Fact lt_def x y : lt x y = (y != x) && le x y. Proof. by rewrite le_def; case: eqVneq => //= ->; rewrite lt_irr. Qed. Fact meet_def_le x y : meet x y = if lt x y then x else y. Proof. by rewrite meet_def lt_def; case: eqP. Qed. Fact join_def_le x y : join x y = if lt x y then y else x. Proof. by rewrite join_def lt_def; case: eqP. Qed. Fact le_anti : antisymmetric le. Proof. move=> x y; rewrite !le_def; case: eqVneq => //= _ /andP [] hxy. by move/(lt_trans hxy); rewrite lt_irr. Qed. Fact le_trans : transitive le. Proof. move=> y x z; rewrite !le_def; case: eqVneq => [->|_] //=. by case: eqVneq => [-> ->|_ hxy /(lt_trans hxy) ->]; rewrite orbT. Qed. Fact le_total : total le. Proof. by move=> x y; rewrite !le_def; case: eqVneq => //; exact: lt_total. Qed. HB.instance Definition _ := isOrder.Build d T lt_def meet_def_le join_def_le le_anti le_trans le_total. HB.end. HB.factory Record MonoTotal disp T of POrder disp T := { disp' : disp_t; T' : orderType disp'; f : T -> T'; f_mono : {mono f : x y / x <= y} }. HB.builders Context disp T of MonoTotal disp T. Fact totalT : total (<=%O : rel T). Proof. by move=> x y; rewrite -!f_mono le_total. Qed. HB.instance Definition _ := POrder_isTotal.Build disp T totalT. HB.end. Module CancelPartial. Import PreCancelPartial. Section CancelPartial. Variables (disp : disp_t) (T : choiceType). Variables (disp' : disp_t) (T' : porderType disp') (f : T -> T'). Section Pcan. Variables (f' : T' -> option T) (f_can : pcancel f f'). Fact anti : antisymmetric (le f). Proof. by move=> ? ? /le_anti; apply: pcan_inj. Qed. Fact lt_def x y : lt f x y = (y != x) && le f x y. Proof. by rewrite /lt lt_def (inj_eq (pcan_inj f_can)). Qed. Definition Pcan := isPOrder.Build disp (Choice.Pack (Choice.class T)) lt_def (@refl T disp' T' f) anti (@trans T disp' T' f). End Pcan. Definition Can f' (f_can : cancel f f') := Pcan (can_pcan f_can). End CancelPartial. End CancelPartial. Notation PCanIsPartial := CancelPartial.Pcan. Notation CanIsPartial := CancelPartial.Can. #[export] HB.instance Definition _ (disp : disp_t) (T : choiceType) (disp' : disp_t) (T' : porderType disp') (f : T -> T') (f' : T' -> option T) (f_can : pcancel f f') := Preorder_isPOrder.Build disp (pcan_type f_can) (CancelPartial.anti f_can). #[export] HB.instance Definition _ (disp : disp_t) (T : choiceType) (disp' : disp_t) (T' : porderType disp') (f : T -> T') (f' : T' -> T) (f_can : cancel f f') := Preorder_isPOrder.Build disp (can_type f_can) (CancelPartial.anti (can_pcan f_can)). Section CancelTotal. Variables (disp : disp_t) (T : choiceType). Variables (disp' : disp_t) (T' : orderType disp') (f : T -> T'). Section PCan. Variables (f' : T' -> option T) (f_can : pcancel f f'). #[local] HB.instance Definition _ := MonoTotal.Build disp (pcan_type f_can) (fun _ _ => erefl). Definition PCanIsTotal : DistrLattice_isTotal _ (pcan_type f_can) := Total.on (pcan_type f_can). End PCan. Section Can. Variables (f' : T' -> T) (f_can : cancel f f'). #[local] HB.instance Definition _ := MonoTotal.Build disp (can_type f_can) (fun _ _ => erefl). Definition CanIsTotal : DistrLattice_isTotal _ (can_type f_can) := Total.on (can_type f_can). End Can. End CancelTotal. HB.factory Record IsoLattice disp T of POrder disp T := { disp' : disp_t; T' : latticeType disp'; f : T -> T'; f' : T' -> T; f_can : cancel f f'; f'_can : cancel f' f; f_mono : {mono f : x y / x <= y}; }. HB.builders Context disp T of IsoLattice disp T. Definition meet (x y : T) := f' (meet (f x) (f y)). Definition join (x y : T) := f' (join (f x) (f y)). Fact meetC : commutative meet. Proof. by move=> x y; rewrite /meet meetC. Qed. Fact joinC : commutative join. Proof. by move=> x y; rewrite /join joinC. Qed. Fact meetA : associative meet. Proof. by move=> y x z; rewrite /meet !f'_can meetA. Qed. Fact joinA : associative join. Proof. by move=> y x z; rewrite /join !f'_can joinA. Qed. Fact joinKI y x : meet x (join x y) = x. Proof. by rewrite /meet /join f'_can joinKI f_can. Qed. Fact meetKI y x : join x (meet x y) = x. Proof. by rewrite /join /meet f'_can meetKU f_can. Qed. Fact meet_eql x y : (x <= y) = (meet x y == x). Proof. by rewrite /meet -(can_eq f_can) f'_can eq_meetl f_mono. Qed. HB.instance Definition _ := POrder_isLattice.Build _ T meetC joinC meetA joinA joinKI meetKI meet_eql. HB.end. HB.factory Record IsoDistrLattice disp T of POrder disp T := { disp' : disp_t; T' : distrLatticeType disp'; f : T -> T'; f' : T' -> T; f_can : cancel f f'; f'_can : cancel f' f; f_mono : {mono f : x y / x <= y}; }. HB.builders Context disp T of IsoDistrLattice disp T. HB.instance Definition _ := IsoLattice.Build _ T f_can f'_can f_mono. Fact meetUl : left_distributive (meet : T -> T -> T) join. Proof. by move=> x y z; rewrite /meet /join /= !f'_can meetUl. Qed. HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build _ T meetUl. HB.end. (* Morphism hierarchy. *) Export OrderMorphismTheory. Lemma omorph_lt (d : disp_t) (T : porderType d) (d' : disp_t) (T' : porderType d') (f : {omorphism T -> T'}) : injective f -> {homo f : x y / x < y}. Proof. by move/inj_homo_lt; apply; apply: omorph_le. Qed. Definition meet_morphism d (T : latticeType d) d' (T' : latticeType d') (f : T -> T') : Prop := {morph f : x y / x `&` y}. Definition join_morphism d (T : latticeType d) d' (T' : latticeType d') (f : T -> T') : Prop := {morph f : x y / x `|` y}. HB.mixin Record isMeetLatticeMorphism d (T : latticeType d) d' (T' : latticeType d') (apply : T -> T') := { omorphI_subproof : meet_morphism apply; }. HB.mixin Record isJoinLatticeMorphism d (T : latticeType d) d' (T' : latticeType d') (apply : T -> T') := { omorphU_subproof : join_morphism apply; }. HB.structure Definition MeetLatticeMorphism d (T : latticeType d) d' (T' : latticeType d') := {f of isMeetLatticeMorphism d T d' T' f & @OrderMorphism d T d' T' f}. HB.structure Definition JoinLatticeMorphism d (T : latticeType d) d' (T' : latticeType d') := {f of isJoinLatticeMorphism d T d' T' f & @OrderMorphism d T d' T' f}. HB.structure Definition LatticeMorphism d (T : latticeType d) d' (T' : latticeType d') := {f of @MeetLatticeMorphism d T d' T' f & @JoinLatticeMorphism d T d' T' f}. HB.factory Record isLatticeMorphism d (T : latticeType d) d' (T' : latticeType d') (f : T -> T') of @OrderMorphism d T d' T' f := { omorphI_subproof : meet_morphism f; omorphU_subproof : join_morphism f; }. HB.builders Context d T d' T' f of isLatticeMorphism d T d' T' f. HB.instance Definition _ := isMeetLatticeMorphism.Build d T d' T' f omorphI_subproof. HB.instance Definition _ := isJoinLatticeMorphism.Build d T d' T' f omorphU_subproof. HB.end. Module LatticeMorphismExports. Notation "{ 'mlmorphism' T -> T' }" := (@MeetLatticeMorphism.type _ T%type _ T'%type) : type_scope. Notation "{ 'jlmorphism' T -> T' }" := (@JoinLatticeMorphism.type _ T%type _ T'%type) : type_scope. Notation "{ 'lmorphism' T -> T' }" := (@LatticeMorphism.type _ T%type _ T'%type) : type_scope. Notation "[ 'mlmorphism' 'of' f 'as' g ]" := (MeetLatticeMorphism.clone _ _ _ _ f%function g) (format "[ 'mlmorphism' 'of' f 'as' g ]") : form_scope. Notation "[ 'mlmorphism' 'of' f ]" := (MeetLatticeMorphism.clone _ _ _ _ f%function _) (format "[ 'mlmorphism' 'of' f ]") : form_scope. Notation "[ 'jlmorphism' 'of' f 'as' g ]" := (JoinLatticeMorphism.clone _ _ _ _ f%function g) (format "[ 'jlmorphism' 'of' f 'as' g ]") : form_scope. Notation "[ 'jlmorphism' 'of' f ]" := (JoinLatticeMorphism.clone _ _ _ _ f%function _) (format "[ 'jlmorphism' 'of' f ]") : form_scope. Notation "[ 'lmorphism' 'of' f 'as' g ]" := (LatticeMorphism.clone _ _ _ _ f%function g) (format "[ 'lmorphism' 'of' f 'as' g ]") : form_scope. Notation "[ 'lmorphism' 'of' f ]" := (LatticeMorphism.clone _ _ _ _ f%function _) (format "[ 'lmorphism' 'of' f ]") : form_scope. End LatticeMorphismExports. HB.export LatticeMorphismExports. Module Import LatticeMorphismTheory. Section LatticeMorphismTheory. Section Properties. Variables (d : disp_t) (T : latticeType d) (d' : disp_t) (T' : latticeType d'). Lemma omorphI (f : {mlmorphism T -> T'}) : {morph f : x y / x `&` y}. Proof. exact: omorphI_subproof. Qed. Lemma omorphU (f : {jlmorphism T -> T'}) : {morph f : x y / x `|` y}. Proof. exact: omorphU_subproof. Qed. End Properties. Section IdCompFun. Variables (d : disp_t) (T : latticeType d) (d' : disp_t) (T' : latticeType d'). Variables (d'' : disp_t) (T'' : latticeType d''). Section MeetCompFun. Variables (f : {mlmorphism T' -> T''}) (g : {mlmorphism T -> T'}). Fact idfun_is_meet_morphism : meet_morphism (@idfun T). Proof. by []. Qed. #[export] HB.instance Definition _ := isMeetLatticeMorphism.Build d T d T idfun idfun_is_meet_morphism. Fact comp_is_meet_morphism : meet_morphism (f \o g). Proof. by move=> x y; rewrite /= !omorphI. Qed. #[export] HB.instance Definition _ := isMeetLatticeMorphism.Build d T d'' T'' (f \o g) comp_is_meet_morphism. End MeetCompFun. Section JoinCompFun. Variables (f : {jlmorphism T' -> T''}) (g : {jlmorphism T -> T'}). Fact idfun_is_join_morphism : join_morphism (@idfun T). Proof. by []. Qed. #[export] HB.instance Definition _ := isJoinLatticeMorphism.Build d T d T idfun idfun_is_join_morphism. Fact comp_is_join_morphism : join_morphism (f \o g). Proof. by move=> x y; rewrite /= !omorphU. Qed. #[export] HB.instance Definition _ := isJoinLatticeMorphism.Build d T d'' T'' (f \o g) comp_is_join_morphism. End JoinCompFun. End IdCompFun. End LatticeMorphismTheory. End LatticeMorphismTheory. HB.mixin Record isBLatticeMorphism d (T : bLatticeType d) d' (T' : bLatticeType d') (apply : T -> T') := { omorph0_subproof : apply \bot = \bot; }. HB.mixin Record isTLatticeMorphism d (T : tLatticeType d) d' (T' : tLatticeType d') (apply : T -> T') := { omorph1_subproof : apply \top = \top; }. HB.structure Definition BLatticeMorphism d (T : bLatticeType d) d' (T' : bLatticeType d') := {f of isBLatticeMorphism d T d' T' f}. HB.structure Definition TLatticeMorphism d (T : tLatticeType d) d' (T' : tLatticeType d') := {f of isTLatticeMorphism d T d' T' f}. HB.structure Definition TBLatticeMorphism d (T : tbLatticeType d) d' (T' : tbLatticeType d') := {f of @BLatticeMorphism d T d' T' f & @TLatticeMorphism d T d' T' f}. Module TBLatticeMorphismExports. Notation "{ 'blmorphism' T -> T' }" := (@BLatticeMorphism.type _ T%type _ T'%type) : type_scope. Notation "{ 'tlmorphism' T -> T' }" := (@TLatticeMorphism.type _ T%type _ T'%type) : type_scope. Notation "{ 'tblmorphism' T -> T' }" := (@TBLatticeMorphism.type _ T%type _ T'%type) : type_scope. End TBLatticeMorphismExports. HB.export TBLatticeMorphismExports. Module Import BLatticeMorphismTheory. Section BLatticeMorphismTheory. Section Properties. Variables (d : disp_t) (T : bLatticeType d). Variables (d' : disp_t) (T' : bLatticeType d'). Variables (f : {blmorphism T -> T'}). Lemma omorph0 : f \bot = \bot. Proof. exact: omorph0_subproof. Qed. End Properties. Section IdCompFun. Variables (d : disp_t) (T : bLatticeType d). Variables (d' : disp_t) (T' : bLatticeType d'). Variables (d'' : disp_t) (T'' : bLatticeType d''). Variables (f : {blmorphism T' -> T''}) (g : {blmorphism T -> T'}). Fact idfun_is_bottom_morphism : (@idfun T) \bot = \bot. Proof. by []. Qed. #[export] HB.instance Definition _ := isBLatticeMorphism.Build d T d T idfun idfun_is_bottom_morphism. Fact comp_is_bottom_morphism : (f \o g) \bot = \bot. Proof. by rewrite /= !omorph0. Qed. #[export] HB.instance Definition _ := isBLatticeMorphism.Build d T d'' T'' (f \o g) comp_is_bottom_morphism. End IdCompFun. End BLatticeMorphismTheory. End BLatticeMorphismTheory. Module Import TLatticeMorphismTheory. Section TLatticeMorphismTheory. Section Properties. Variables (d : disp_t) (T : tLatticeType d). Variables (d' : disp_t) (T' : tLatticeType d'). Variables (f : {tlmorphism T -> T'}). Lemma omorph1 : f \top = \top. Proof. exact: omorph1_subproof. Qed. End Properties. Section IdCompFun. Variables (d : disp_t) (T : tLatticeType d). Variables (d' : disp_t) (T' : tLatticeType d'). Variables (d'' : disp_t) (T'' : tLatticeType d''). Variables (f : {tlmorphism T' -> T''}) (g : {tlmorphism T -> T'}). Fact idfun_is_top_morphism : (@idfun T) \top = \top. Proof. by []. Qed. #[export] HB.instance Definition _ := isTLatticeMorphism.Build d T d T idfun idfun_is_top_morphism. Fact comp_is_top_morphism : (f \o g) \top = \top. Proof. by rewrite /= !omorph1. Qed. #[export] HB.instance Definition _ := isTLatticeMorphism.Build d T d'' T'' (f \o g) comp_is_top_morphism. End IdCompFun. End TLatticeMorphismTheory. End TLatticeMorphismTheory. Module Import ClosedPredicates. Section ClosedPredicates. Variable (d : disp_t) (T : latticeType d). Variable S : {pred T}. Definition meet_closed := {in S &, forall u v, u `&` v \in S}. Definition join_closed := {in S &, forall u v, u `|` v \in S}. End ClosedPredicates. End ClosedPredicates. (* Mixins for stability properties *) HB.mixin Record isMeetLatticeClosed d (T : latticeType d) (S : {pred T}) := { opredI : meet_closed S; }. HB.mixin Record isJoinLatticeClosed d (T : latticeType d) (S : {pred T}) := { opredU : join_closed S; }. HB.mixin Record isBLatticeClosed d (T : bLatticeType d) (S : {pred T}) := { opred0 : \bot \in S; }. HB.mixin Record isTLatticeClosed d (T : tLatticeType d) (S : {pred T}) := { opred1 : \top \in S; }. (* Structures for stability properties *) #[short(type="meetLatticeClosed")] HB.structure Definition MeetLatticeClosed d T := {S of isMeetLatticeClosed d T S}. #[short(type="joinLatticeClosed")] HB.structure Definition JoinLatticeClosed d T := {S of isJoinLatticeClosed d T S}. #[short(type="latticeClosed")] HB.structure Definition LatticeClosed d T := {S of @MeetLatticeClosed d T S & @JoinLatticeClosed d T S}. #[short(type="bLatticeClosed")] HB.structure Definition BLatticeClosed d T := {S of isBLatticeClosed d T S}. #[short(type="bJoinLatticeClosed")] HB.structure Definition BJoinLatticeClosed d T := {S of isBLatticeClosed d T S & @JoinLatticeClosed d T S}. #[short(type="tLatticeClosed")] HB.structure Definition TLatticeClosed d T := {S of isTLatticeClosed d T S}. #[short(type="tMeetLatticeClosed")] HB.structure Definition TMeetLatticeClosed d T := {S of isTLatticeClosed d T S & @MeetLatticeClosed d T S}. #[short(type="tbLatticeClosed")] HB.structure Definition TBLatticeClosed d (T : tbLatticeType d) := {S of @BLatticeClosed d T S & @TLatticeClosed d T S}. HB.factory Record isLatticeClosed d (T : latticeType d) (S : {pred T}) := { opredI : meet_closed S; opredU : join_closed S; }. HB.builders Context d T S of isLatticeClosed d T S. HB.instance Definition _ := isMeetLatticeClosed.Build d T S opredI. HB.instance Definition _ := isJoinLatticeClosed.Build d T S opredU. HB.end. HB.factory Record isTBLatticeClosed d (T : tbLatticeType d) (S : {pred T}) := { opredI : meet_closed S; opredU : join_closed S; opred0 : \bot \in S; opred1 : \top \in S; }. HB.builders Context d T S of isTBLatticeClosed d T S. HB.instance Definition _ := isLatticeClosed.Build d T S opredI opredU. HB.instance Definition _ := isBLatticeClosed.Build d T S opred0. HB.instance Definition _ := isTLatticeClosed.Build d T S opred1. HB.end. Module Import LatticePred. Section LatticePred. Variables (d : disp_t) (T : latticeType d). Lemma opredI (S : meetLatticeClosed T) : {in S &, forall u v, u `&` v \in S}. Proof. exact: opredI. Qed. Lemma opredU (S : joinLatticeClosed T) : {in S &, forall u v, u `|` v \in S}. Proof. exact: opredU. Qed. End LatticePred. Section BLatticePred. Variables (d : disp_t) (T : bLatticeType d). Lemma opred0 (S : bLatticeClosed T) : \bot \in S. Proof. exact: opred0. Qed. Lemma opred_joins (S : bJoinLatticeClosed T) I r (P : pred I) F : (forall i, P i -> F i \in S) -> \join_(i <- r | P i) F i \in S. Proof. by move=> FS; elim/big_ind: _; [exact: opred0 | exact: opredU |]. Qed. End BLatticePred. Section TLatticePred. Variables (d : disp_t) (T : tLatticeType d). Lemma opred1 (S : tLatticeClosed T) : \top \in S. Proof. exact: opred1. Qed. Lemma opred_meets (S : tMeetLatticeClosed T) I r (P : pred I) F : (forall i, P i -> F i \in S) -> \meet_(i <- r | P i) F i \in S. Proof. by move=> FS; elim/big_ind: _; [exact: opred1 | exact: opredI |]. Qed. End TLatticePred. End LatticePred. #[short(type="subPOrder")] HB.structure Definition SubPOrder d (T : porderType d) S d' := { U of SubEquality T S U & POrder d' U & isSubPreorder d T S d' U }. HB.factory Record SubChoice_isSubPOrder d (T : porderType d) S (d' : disp_t) U of SubChoice T S U := {}. HB.builders Context d T S d' U of SubChoice_isSubPOrder d T S d' U. HB.instance Definition _ := SubChoice_isSubPreorder.Build d T S d' U. HB.instance Definition _ := Preorder_isPOrder.Build d' U (@CancelPartial.anti U d T _ _ (@valK _ _ U)). HB.end. #[export] HB.instance Definition _ d (T : porderType d) (S : pred T) (d' : disp_t) (U : subType S) := SubChoice_isSubPOrder.Build d T S d' (sub_type U). HB.mixin Record isMeetSubLattice d (T : latticeType d) (S : pred T) d' U of SubType T S U & Lattice d' U := { valI_subproof : {morph (val : U -> T) : x y / x `&` y}; }. HB.mixin Record isJoinSubLattice d (T : latticeType d) (S : pred T) d' U of SubType T S U & Lattice d' U := { valU_subproof : {morph (val : U -> T) : x y / x `|` y}; }. #[short(type="subPOrderLattice")] HB.structure Definition SubPOrderLattice d (T : latticeType d) S d' := { U of @SubPOrder d T S d' U & Lattice d' U }. #[short(type="subPOrderBLattice")] HB.structure Definition SubPOrderBLattice d (T : latticeType d) S d' := { U of @SubPOrderLattice d T S d' U & BLattice d' U }. #[short(type="subPOrderTLattice")] HB.structure Definition SubPOrderTLattice d (T : latticeType d) S d' := { U of @SubPOrderLattice d T S d' U & TLattice d' U }. #[short(type="subPOrderTBLattice")] HB.structure Definition SubPOrderTBLattice d (T : latticeType d) S d' := { U of @SubPOrderLattice d T S d' U & TBLattice d' U }. #[short(type="meetSubLattice")] HB.structure Definition MeetSubLattice d (T : latticeType d) S d' := { U of @SubPOrderLattice d T S d' U & isMeetSubLattice d T S d' U }. #[short(type="meetSubBLattice")] HB.structure Definition MeetSubBLattice d (T : latticeType d) S d' := { U of @MeetSubLattice d T S d' U & BLattice d' U }. #[short(type="meetSubTLattice")] HB.structure Definition MeetSubTLattice d (T : latticeType d) S d' := { U of @MeetSubLattice d T S d' U & TLattice d' U }. #[short(type="meetSubTBLattice")] HB.structure Definition MeetSubTBLattice d (T : latticeType d) S d' := { U of @MeetSubLattice d T S d' U & TBLattice d' U }. #[short(type="joinSubLattice")] HB.structure Definition JoinSubLattice d (T : latticeType d) S d' := { U of @SubPOrderLattice d T S d' U & isJoinSubLattice d T S d' U }. #[short(type="joinSubBLattice")] HB.structure Definition JoinSubBLattice d (T : latticeType d) S d' := { U of @JoinSubLattice d T S d' U & BLattice d' U }. #[short(type="joinSubTLattice")] HB.structure Definition JoinSubTLattice d (T : latticeType d) S d' := { U of @JoinSubLattice d T S d' U & TLattice d' U }. #[short(type="joinSubTBLattice")] HB.structure Definition JoinSubTBLattice d (T : latticeType d) S d' := { U of @JoinSubLattice d T S d' U & TBLattice d' U }. #[short(type="subLattice")] HB.structure Definition SubLattice d (T : latticeType d) S d' := { U of @MeetSubLattice d T S d' U & @JoinSubLattice d T S d' U }. #[short(type="subBLattice")] HB.structure Definition SubBLattice d (T : latticeType d) S d' := { U of @SubLattice d T S d' U & BLattice d' U }. #[short(type="subTLattice")] HB.structure Definition SubTLattice d (T : latticeType d) S d' := { U of @SubLattice d T S d' U & TLattice d' U }. #[short(type="subTBLattice")] HB.structure Definition SubTBLattice d (T : latticeType d) S d' := { U of @SubLattice d T S d' U & TBLattice d' U }. #[export, warning="-HB.no-new-instance"] HB.instance Definition _ (d : disp_t) (T : latticeType d) (S : pred T) d' (U : MeetSubLattice.type S d') := isMeetLatticeMorphism.Build d' U d T val valI_subproof. #[export, warning="-HB.no-new-instance"] HB.instance Definition _ (d : disp_t) (T : latticeType d) (S : pred T) d' (U : JoinSubLattice.type S d') := isJoinLatticeMorphism.Build d' U d T val valU_subproof. HB.factory Record SubPOrder_isSubLattice d (T : latticeType d) S d' U of @SubPOrder d T S d' U := { opredI_subproof : meet_closed S; opredU_subproof : join_closed S; }. HB.builders Context d T S d' U of SubPOrder_isSubLattice d T S d' U. HB.instance Definition _ := isLatticeClosed.Build d T S opredI_subproof opredU_subproof. Let inU v Sv : U := Sub v Sv. Let meetU (u1 u2 : U) : U := inU (opredI (valP u1) (valP u2)). Let joinU (u1 u2 : U) : U := inU (opredU (valP u1) (valP u2)). Let meetUC : commutative meetU. Proof. by move=> x y; apply: val_inj; rewrite !SubK meetC. Qed. Let joinUC : commutative joinU. Proof. by move=> x y; apply: val_inj; rewrite !SubK joinC. Qed. Let meetUA : associative meetU. Proof. by move=> x y z; apply: val_inj; rewrite !SubK meetA. Qed. Let joinUA : associative joinU. Proof. by move=> x y z; apply: val_inj; rewrite !SubK joinA. Qed. Lemma joinUKI y x : meetU x (joinU x y) = x. Proof. by apply: val_inj; rewrite !SubK joinKI. Qed. Let meetUKU y x : joinU x (meetU x y) = x. Proof. by apply: val_inj; rewrite !SubK meetKU. Qed. Let le_meetU x y : (x <= y) = (meetU x y == x). Proof. by rewrite -le_val -(inj_eq val_inj) SubK leEmeet. Qed. HB.instance Definition _ := POrder_isLattice.Build d' U meetUC joinUC meetUA joinUA joinUKI meetUKU le_meetU. Fact valI : meet_morphism (val : U -> T). Proof. by move=> x y; rewrite !SubK. Qed. Fact valU : join_morphism (val : U -> T). Proof. by move=> x y; rewrite !SubK. Qed. HB.instance Definition _ := isMeetSubLattice.Build d T S d' U valI. HB.instance Definition _ := isJoinSubLattice.Build d T S d' U valU. HB.end. HB.factory Record SubChoice_isSubLattice d (T : latticeType d) S (d' : disp_t) U of SubChoice T S U := { opredI_subproof : meet_closed S; opredU_subproof : join_closed S; }. HB.builders Context d T S d' U of SubChoice_isSubLattice d T S d' U. HB.instance Definition _ := SubChoice_isSubPOrder.Build d T S d' U. HB.instance Definition _ := SubPOrder_isSubLattice.Build d T S d' U opredI_subproof opredU_subproof. HB.end. HB.mixin Record isBSubLattice d (T : bLatticeType d) (S : pred T) d' U of SubType T S U & BLattice d' U := { val0_subproof : (val : U -> T) \bot = \bot; }. #[short(type="bJoinSubLattice")] HB.structure Definition BJoinSubLattice d (T : bLatticeType d) S d' := { U of @JoinSubLattice d T S d' U & BLattice d' U & isBSubLattice d T S d' U }. #[short(type="bJoinSubTLattice")] HB.structure Definition BJoinSubTLattice d (T : bLatticeType d) S d' := { U of @BJoinSubLattice d T S d' U & TBLattice d' U }. #[short(type="bSubLattice")] HB.structure Definition BSubLattice d (T : bLatticeType d) S d' := { U of @SubLattice d T S d' U & @BJoinSubLattice d T S d' U }. #[short(type="bSubTLattice")] HB.structure Definition BSubTLattice d (T : bLatticeType d) S d' := { U of @BSubLattice d T S d' U & TBLattice d' U }. #[export] HB.instance Definition _ (d : disp_t) (T : bLatticeType d) (S : pred T) d' (U : BJoinSubLattice.type S d') := isBLatticeMorphism.Build d' U d T val val0_subproof. HB.factory Record SubPOrder_isBSubLattice d (T : bLatticeType d) S d' U of @SubPOrder d T S d' U & Lattice d' U := { opred0_subproof : \bot \in S; }. HB.builders Context d T S d' U of SubPOrder_isBSubLattice d T S d' U. Let inU v Sv : U := Sub v Sv. Let zeroU : U := inU opred0_subproof. Fact le0x x : zeroU <= x. Proof. by rewrite -le_val /= SubK le0x. Qed. HB.instance Definition _ := hasBottom.Build d' U le0x. Fact val0 : (val : U -> T) \bot = \bot. Proof. by rewrite SubK. Qed. #[warning="-HB.no-new-instance"] HB.instance Definition _ := isBSubLattice.Build d T S d' U val0. HB.end. HB.factory Record SubChoice_isBSubLattice d (T : bLatticeType d) S (d' : disp_t) U of SubChoice T S U := { opredI_subproof : meet_closed S; opredU_subproof : join_closed S; opred0_subproof : \bot \in S; }. HB.builders Context d T S d' U of SubChoice_isBSubLattice d T S d' U. HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U opredI_subproof opredU_subproof. HB.instance Definition _ := SubPOrder_isBSubLattice.Build d T S d' U opred0_subproof. HB.end. HB.mixin Record isTSubLattice d (T : tLatticeType d) (S : pred T) d' U of SubType T S U & TLattice d' U := { val1_subproof : (val : U -> T) \top = \top; }. #[short(type="tMeetSubLattice")] HB.structure Definition TMeetSubLattice d (T : tLatticeType d) S d' := { U of @MeetSubLattice d T S d' U & TLattice d' U & isTSubLattice d T S d' U }. #[short(type="tMeetSubBLattice")] HB.structure Definition TMeetSubBLattice d (T : tLatticeType d) S d' := { U of @TMeetSubLattice d T S d' U & TBLattice d' U }. #[short(type="tSubLattice")] HB.structure Definition TSubLattice d (T : tLatticeType d) S d' := { U of @SubLattice d T S d' U & @TMeetSubLattice d T S d' U }. #[short(type="tSubBLattice")] HB.structure Definition TSubBLattice d (T : tLatticeType d) S d' := { U of @TSubLattice d T S d' U & TBLattice d' U }. #[export] HB.instance Definition _ (d : disp_t) (T : tLatticeType d) (S : pred T) d' (U : TMeetSubLattice.type S d') := isTLatticeMorphism.Build d' U d T val val1_subproof. HB.factory Record SubPOrder_isTSubLattice d (T : tLatticeType d) S d' U of @SubPOrder d T S d' U & Lattice d' U := { opred1_subproof : \top \in S; }. HB.builders Context d T S d' U of SubPOrder_isTSubLattice d T S d' U. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU opred1_subproof. Fact lex1 x : x <= oneU. Proof. by rewrite -le_val /= SubK lex1. Qed. HB.instance Definition _ := hasTop.Build d' U lex1. Fact val1 : (val : U -> T) \top = \top. Proof. by rewrite SubK. Qed. #[warning="-HB.no-new-instance"] HB.instance Definition _ := isTSubLattice.Build d T S d' U val1. HB.end. HB.factory Record SubChoice_isTSubLattice d (T : tLatticeType d) S (d' : disp_t) U of SubChoice T S U := { opredI_subproof : meet_closed S; opredU_subproof : join_closed S; opred1_subproof : \top \in S; }. HB.builders Context d T S d' U of SubChoice_isTSubLattice d T S d' U. HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U opredI_subproof opredU_subproof. HB.instance Definition _ := SubPOrder_isTSubLattice.Build d T S d' U opred1_subproof. HB.end. #[short(type="tbSubLattice")] HB.structure Definition TBSubLattice d (T : tbLatticeType d) S d' := { U of @BSubLattice d T S d' U & @TSubLattice d T S d' U}. #[export] HB.instance Definition _ (d : disp_t) (T : tbLatticeType d) (S : pred T) d' (U : TBSubLattice.type S d') := BLatticeMorphism.on (val : U -> T). HB.factory Record SubPOrder_isTBSubLattice d (T : tbLatticeType d) S d' U of @SubPOrder d T S d' U & Lattice d' U := { opred0_subproof : \bot \in S; opred1_subproof : \top \in S; }. HB.builders Context d T S d' U of SubPOrder_isTBSubLattice d T S d' U. HB.instance Definition _ := SubPOrder_isBSubLattice.Build d T S d' U opred0_subproof. HB.instance Definition _ := SubPOrder_isTSubLattice.Build d T S d' U opred1_subproof. HB.end. HB.factory Record SubChoice_isTBSubLattice d (T : tbLatticeType d) S (d' : disp_t) U of SubChoice T S U := { opredI_subproof : meet_closed S; opredU_subproof : join_closed S; opred0_subproof : \bot \in S; opred1_subproof : \top \in S; }. HB.builders Context d T S d' U of SubChoice_isTBSubLattice d T S d' U. HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U opredI_subproof opredU_subproof. HB.instance Definition _ := SubPOrder_isTBSubLattice.Build d T S d' U opred0_subproof opred1_subproof. HB.end. #[short(type="subOrder")] HB.structure Definition SubOrder d (T : orderType d) S d' := { U of @SubLattice d T S d' U & Total d' U }. HB.factory Record SubLattice_isSubOrder d (T : orderType d) S d' U of @SubLattice d T S d' U := {}. HB.builders Context d T S d' U of SubLattice_isSubOrder d T S d' U. Lemma totalU : total (<=%O : rel U). Proof. by move=> x y; rewrite -!le_val le_total. Qed. HB.instance Definition _ := Lattice_isTotal.Build d' U totalU. HB.end. HB.factory Record SubPOrder_isSubOrder d (T : orderType d) S d' U of @SubPOrder d T S d' U := {}. HB.builders Context d T S d' U of SubPOrder_isSubOrder d T S d' U. Fact opredI : meet_closed S. Proof. by move=> x y Sx Sy; rewrite meetEtotal; case: leP. Qed. Fact opredU : join_closed S. Proof. by move=> x y Sx Sy; rewrite joinEtotal; case: leP. Qed. HB.instance Definition _ := SubPOrder_isSubLattice.Build d T S d' U opredI opredU. HB.instance Definition _ := SubLattice_isSubOrder.Build d T S d' U. HB.end. HB.factory Record SubChoice_isSubOrder d (T : orderType d) S (d' : disp_t) U of @SubChoice T S U := {}. HB.builders Context d T S d' U of SubChoice_isSubOrder d T S d' U. HB.instance Definition _ := SubChoice_isSubPOrder.Build d T S d' U. HB.instance Definition _ := SubPOrder_isSubOrder.Build d T S d' U. HB.end. Module SubOrderExports. Notation "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: ]" := (SubChoice_isSubPOrder.Build _ _ _ _ U) (format "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: 'with' disp ]" := (SubChoice_isSubPOrder.Build _ _ _ disp U) (format "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: ]" := (SubPOrder_isSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _)) (format "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: 'with' disp ]" := (SubPOrder_isSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _)) (format "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubChoice_isSubLattice' 'of' U 'by' <: ]" := (SubChoice_isSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _)) (format "[ 'SubChoice_isSubLattice' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLattice' 'of' U 'by' <: 'with' disp ]" := (SubChoice_isSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _)) (format "[ 'SubChoice_isSubLattice' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: ]" := (SubPOrder_isBSubLattice.Build _ _ _ _ U (opred0 _)) (format "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: 'with' disp ]" := (SubPOrder_isBSubLattice.Build _ _ _ disp U (opred0 _)) (format "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: ]" := (SubChoice_isBSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _) (opred0 _)) (format "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: 'with' disp ]" := (SubChoice_isBSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _) (opred0 _)) (format "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: ]" := (SubPOrder_isTSubLattice.Build _ _ _ _ U (opred1 _)) (format "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: 'with' disp ]" := (SubPOrder_isTSubLattice.Build _ _ _ disp U (opred1 _)) (format "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: ]" := (SubChoice_isTSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _) (opred1 _)) (format "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: 'with' disp ]" := (SubChoice_isTSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _) (opred1 _)) (format "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: ]" := (SubPOrder_isTBSubLattice.Build _ _ _ _ U (opred0 _) (opred1 _)) (format "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: 'with' disp ]" := (SubPOrder_isTBSubLattice.Build _ _ _ disp U (opred0 _) (opred1 _)) (format "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: ]" := (SubChoice_isTBSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _) (opred0 _) (opred1 _)) (format "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: 'with' disp ]" := (SubChoice_isTBSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _) (opred0 _) (opred1 _)) (format "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubLattice_isSubOrder' 'of' U 'by' <: ]" := (SubLattice_isSubOrder.Build _ _ _ _ U) (format "[ 'SubLattice_isSubOrder' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubLattice_isSubOrder' 'of' U 'by' <: 'with' disp ]" := (SubLattice_isSubOrder.Build _ _ _ disp U) (format "[ 'SubLattice_isSubOrder' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: ]" := (SubPOrder_isSubOrder.Build _ _ _ _ U) (format "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: 'with' disp ]" := (SubPOrder_isSubOrder.Build _ _ _ disp U) (format "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: 'with' disp ]") : form_scope. Notation "[ 'SubChoice_isSubOrder' 'of' U 'by' <: ]" := (SubChoice_isSubOrder.Build _ _ _ _ U) (format "[ 'SubChoice_isSubOrder' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubOrder' 'of' U 'by' <: 'with' disp ]" := (SubChoice_isSubOrder.Build _ _ _ disp U) (format "[ 'SubChoice_isSubOrder' 'of' U 'by' <: 'with' disp ]") : form_scope. End SubOrderExports. HB.export SubOrderExports. Module DeprecatedSubOrder. Section Total. Context {disp : disp_t} {T : orderType disp} (P : {pred T}) (sT : subType P). #[export] HB.instance Definition _ := SubPOrder_isSubOrder.Build disp T P disp (sub_type sT). End Total. Module Exports. HB.reexport DeprecatedSubOrder. Notation "[ 'POrder' 'of' T 'by' <: ]" := (POrder.copy T%type (sub_type T%type)) (format "[ 'POrder' 'of' T 'by' <: ]") : form_scope. Notation "[ 'Order' 'of' T 'by' <: ]" := (Total.copy T%type (sub_type T%type)) (only parsing) : form_scope. End Exports. End DeprecatedSubOrder. HB.export DeprecatedSubOrder.Exports. (*************) (* INSTANCES *) (*************) (********************) (* Instances on nat *) (********************) (******************************************************************************) (* This is an example of creation of multiple instances on the same type, *) (* with distinct displays, using natural numbers. *) (* We declare two distinct canonical orders: *) (* - leq which is total, and where meet and join are minn and maxn, on nat *) (* - dvdn which is partial, and where meet and join are gcdn and lcmn, *) (* on natdvd *) (******************************************************************************) (******************************************************************************) (* The Module NatOrder defines leq as the canonical order on the type nat, *) (* i.e., without creating an alias. We define and use nat_display and proceed *) (* like a standard canonical structure declaration, except that we use this *) (* display. We also use a single factory LeOrderMixin to instantiate three *) (* different canonical declarations porderType, distrLatticeType, orderType. *) (* We finish by providing theorems to convert the operations of ordered and *) (* lattice types to their definition without structure abstraction. *) (******************************************************************************) Module NatOrder. Section NatOrder. Export NatOrder. #[export] HB.instance Definition _ := Preorder_isPOrder.Build nat_display nat anti_leq. #[export] HB.instance Definition _ := POrder_isTotal.Build nat_display nat leq_total. End NatOrder. Module Exports. HB.reexport NatOrder. End Exports. End NatOrder. HB.export NatOrder.Exports. Module NatMonotonyTheory. Section NatMonotonyTheory. Export NatMonotonyTheory. Context {disp : disp_t} {T : porderType disp}. Variables (D : {pred nat}) (f : nat -> T). Hypothesis Dconvex : {in D &, forall i j k, i < k < j -> k \in D}. Lemma incn_inP : {in D, forall i, i.+1 \in D -> f i < f i.+1} -> {in D &, {mono f : i j / i <= j}}. Proof. by move=> f_inc; apply/le_mono_in/homo_ltn_lt_in. Qed. Lemma decn_inP : {in D, forall i, i.+1 \in D -> f i > f i.+1} -> {in D &, {mono f : i j /~ i <= j}}. Proof. by move=> f_dec; apply/le_nmono_in/nhomo_ltn_lt_in. Qed. Lemma incnP : (forall i, f i < f i.+1) -> {mono f : i j / i <= j}. Proof. by move=> f_inc; apply/le_mono/homo_ltn_lt. Qed. Lemma decnP : (forall i, f i > f i.+1) -> {mono f : i j /~ i <= j}. Proof. by move=> f_dec; apply/le_nmono/nhomo_ltn_lt. Qed. End NatMonotonyTheory. Arguments incn_inP {disp T} [D f]. Arguments decn_inP {disp T} [D f]. Arguments incnP {disp T} [f]. Arguments decnP {disp T} [f]. End NatMonotonyTheory. (****************************************************************************) (* The Module DvdSyntax introduces a new set of notations using the newly *) (* created display dvd_display. We first define the display as an opaque *) (* definition of type disp_t, and we use it as the first argument of the *) (* operator which display we want to change from the default one (here le, *) (* lt, dvd sdvd, meet, join, top and bottom, as well as big op notations on *) (* gcd and lcm). This notations will now be used for any ordered type which *) (* first parameter is set to dvd_display. *) (****************************************************************************) Module DvdSyntax. Export DvdSyntax. Notation gcd := (@meet dvd_display _). Notation "@ 'gcd' T" := (@meet dvd_display T) (at level 10, T at level 8, only parsing) : function_scope. Notation lcm := (@join dvd_display _). Notation "@ 'lcm' T" := (@join dvd_display T) (at level 10, T at level 8, only parsing) : function_scope. Notation "\gcd_ ( i <- r | P ) F" := (\big[gcd/nat0]_(i <- r | P%B) F%O) : order_scope. Notation "\gcd_ ( i <- r ) F" := (\big[gcd/nat0]_(i <- r) F%O) : order_scope. Notation "\gcd_ ( i | P ) F" := (\big[gcd/nat0]_(i | P%B) F%O) : order_scope. Notation "\gcd_ i F" := (\big[gcd/nat0]_i F%O) : order_scope. Notation "\gcd_ ( i : I | P ) F" := (\big[gcd/nat0]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\gcd_ ( i : I ) F" := (\big[gcd/nat0]_(i : I) F%O) (only parsing) : order_scope. Notation "\gcd_ ( m <= i < n | P ) F" := (\big[gcd/nat0]_(m <= i < n | P%B) F%O) : order_scope. Notation "\gcd_ ( m <= i < n ) F" := (\big[gcd/nat0]_(m <= i < n) F%O) : order_scope. Notation "\gcd_ ( i < n | P ) F" := (\big[gcd/nat0]_(i < n | P%B) F%O) : order_scope. Notation "\gcd_ ( i < n ) F" := (\big[gcd/nat0]_(i < n) F%O) : order_scope. Notation "\gcd_ ( i 'in' A | P ) F" := (\big[gcd/nat0]_(i in A | P%B) F%O) : order_scope. Notation "\gcd_ ( i 'in' A ) F" := (\big[gcd/nat0]_(i in A) F%O) : order_scope. Notation "\lcm_ ( i <- r | P ) F" := (\big[lcm/nat1]_(i <- r | P%B) F%O) : order_scope. Notation "\lcm_ ( i <- r ) F" := (\big[lcm/nat1]_(i <- r) F%O) : order_scope. Notation "\lcm_ ( i | P ) F" := (\big[lcm/nat1]_(i | P%B) F%O) : order_scope. Notation "\lcm_ i F" := (\big[lcm/nat1]_i F%O) : order_scope. Notation "\lcm_ ( i : I | P ) F" := (\big[lcm/nat1]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\lcm_ ( i : I ) F" := (\big[lcm/nat1]_(i : I) F%O) (only parsing) : order_scope. Notation "\lcm_ ( m <= i < n | P ) F" := (\big[lcm/nat1]_(m <= i < n | P%B) F%O) : order_scope. Notation "\lcm_ ( m <= i < n ) F" := (\big[lcm/nat1]_(m <= i < n) F%O) : order_scope. Notation "\lcm_ ( i < n | P ) F" := (\big[lcm/nat1]_(i < n | P%B) F%O) : order_scope. Notation "\lcm_ ( i < n ) F" := (\big[lcm/nat1]_(i < n) F%O) : order_scope. Notation "\lcm_ ( i 'in' A | P ) F" := (\big[lcm/nat1]_(i in A | P%B) F%O) : order_scope. Notation "\lcm_ ( i 'in' A ) F" := (\big[lcm/nat1]_(i in A) F%O) : order_scope. End DvdSyntax. (******************************************************************************) (* The Module NatDvd defines dvdn as the canonical order on NatDvd.t, which *) (* is abbreviated using the notation natdvd at the end of the module. *) (* We use the newly defined dvd_display, described above. *) (* We first recover structures that are common to both nat and natdvd *) (* (eqType, choiceType, countType) through the copy mechanism, then we use *) (* a single factory MeetJoinMixin to instantiate both porderType and *) (* distrLatticeType canonical structures, and end with top and bottom. *) (* We finish by providing theorems to convert the operations of ordered and *) (* lattice types to their definition without structure abstraction. *) (******************************************************************************) Module NatDvd. Export NatDvd. Section NatDvd. Implicit Types (m n p : natdvd). Lemma lcmnn n : lcmn n n = n. Proof. by case: n => // n; rewrite /lcmn gcdnn mulnK. Qed. Lemma le_def m n : m %| n = (gcdn m n == m)%N. Proof. by apply/gcdn_idPl/eqP. Qed. Lemma joinKI n m : gcdn m (lcmn m n) = m. Proof. by rewrite (gcdn_idPl _)// dvdn_lcml. Qed. Lemma meetKU n m : lcmn m (gcdn m n) = m. Proof. by rewrite (lcmn_idPl _)// dvdn_gcdl. Qed. Lemma meetUl : left_distributive gcdn lcmn. Proof. move=> [|m'] [|n'] [|p'] //=; rewrite ?lcmnn ?lcm0n ?lcmn0 ?gcd0n ?gcdn0//. - by rewrite gcdnC meetKU. - by rewrite lcmnC gcdnC meetKU. apply: eqn_from_log; rewrite ?(gcdn_gt0, lcmn_gt0)//= => p. by rewrite !(logn_gcd, logn_lcm) ?(gcdn_gt0, lcmn_gt0)// minn_maxl. Qed. Fact dvdn_anti : antisymmetric dvdn. Proof. by move=> a b => /andP[] /gcdn_idPl + /gcdn_idPr => ->. Qed. #[export] HB.instance Definition _ := Preorder_isPOrder.Build dvd_display t dvdn_anti. #[export] HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build dvd_display t gcdn lcmn gcdnC lcmnC gcdnA lcmnA joinKI meetKU le_def meetUl. Import DvdSyntax. Lemma sdvdE (m n : t) : m %<| n = (n != m) && (m %| n). Proof. exact/lt_def. Qed. Lemma gcdE : gcd = gcdn :> (t -> t -> t). Proof. by []. Qed. Lemma lcmE : lcm = lcmn :> (t -> t -> t). Proof. by []. Qed. End NatDvd. Module Exports. HB.reexport NatDvd. Definition sdvdEnat := sdvdE. Definition gcdEnat := gcdE. Definition lcmEnat := lcmE. End Exports. End NatDvd. HB.export NatDvd.Exports. (************************) (* Instances on ordinal *) (************************) Module OrdinalOrder. Export OrdinalOrder. #[export] HB.instance Definition _ (n : nat) := [SubChoice_isSubOrder of 'I_n by <: with ord_display]. End OrdinalOrder. HB.export OrdinalOrder. (*********************) (* Instances on bool *) (*********************) Module BoolOrder. Export BoolOrder. Section BoolOrder. Implicit Types (x y : bool). Fact andbE x y : x && y = if (x < y)%N then x else y. Proof. by case: x y => [] []. Qed. Fact orbE x y : x || y = if (x < y)%N then y else x. Proof. by case: x y => [] []. Qed. Fact anti : antisymmetric (leq : rel bool). Proof. by move=> x y /anti_leq /(congr1 odd); rewrite !oddb. Qed. #[export] HB.instance Definition _ := Preorder_isPOrder.Build bool_display bool anti. Fact orKb b a : a && (a || b) = a. Proof. by rewrite orbC orKb. Qed. Fact andKb y x : x || x && y = x. Proof. by rewrite andbC andKb. Qed. Fact leEmeet x y : (x <= y) = (x && y == x). Proof. by case: x; case: y. Qed. #[export] HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build bool_display bool andb orb andbC orbC andbA orbA orKb andKb leEmeet andb_orl. #[export] HB.instance Definition _ := DistrLattice_isTotal.Build bool_display bool leq_total. #[export] HB.instance Definition _ := @TBDistrLattice_hasComplement.Build _ bool negb orbN andbN. Lemma andEbool : meet = andb. Proof. by []. Qed. Lemma orEbool : meet = andb. Proof. by []. Qed. Lemma subEbool x y : x `\` y = x && ~~ y. Proof. by []. Qed. Lemma complEbool : compl = negb. Proof. by []. Qed. End BoolOrder. Module Exports. HB.reexport BoolOrder. Definition leEbool := leEbool. Definition ltEbool := ltEbool. Definition andEbool := andEbool. Definition orEbool := orEbool. Definition subEbool := subEbool. Definition complEbool := complEbool. End Exports. End BoolOrder. HB.export BoolOrder.Exports. (******************************) (* Definition of prod_display *) (******************************) Module Import ProdSyntax. Export ProdSyntax. (* The following Local Notations are here to define the \join^p_ and \meet^p_ *) (* notations later. Do not remove them. *) Local Notation "\bot" := (@bottom (prod_display _ _) _). Local Notation "\top" := (@top (prod_display _ _) _). Local Notation meet := (@meet (prod_display _ _) _). Local Notation join := (@join (prod_display _ _) _). Local Notation min := (@min (prod_display _ _) _). Local Notation max := (@max (prod_display _ _) _). Notation "x `&^p` y" := (meet x y) : order_scope. Notation "x `|^p` y" := (join x y) : order_scope. Notation "\join^p_ ( i <- r | P ) F" := (\big[join / \bot]_(i <- r | P%B) F%O) : order_scope. Notation "\join^p_ ( i <- r ) F" := (\big[join / \bot]_(i <- r) F%O) : order_scope. Notation "\join^p_ ( i | P ) F" := (\big[join / \bot]_(i | P%B) F%O) : order_scope. Notation "\join^p_ i F" := (\big[join / \bot]_i F%O) : order_scope. Notation "\join^p_ ( i : I | P ) F" := (\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\join^p_ ( i : I ) F" := (\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope. Notation "\join^p_ ( m <= i < n | P ) F" := (\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope. Notation "\join^p_ ( m <= i < n ) F" := (\big[join / \bot]_(m <= i < n) F%O) : order_scope. Notation "\join^p_ ( i < n | P ) F" := (\big[join / \bot]_(i < n | P%B) F%O) : order_scope. Notation "\join^p_ ( i < n ) F" := (\big[join / \bot]_(i < n) F%O) : order_scope. Notation "\join^p_ ( i 'in' A | P ) F" := (\big[join / \bot]_(i in A | P%B) F%O) : order_scope. Notation "\join^p_ ( i 'in' A ) F" := (\big[join / \bot]_(i in A) F%O) : order_scope. Notation "\meet^p_ ( i <- r | P ) F" := (\big[meet / \top]_(i <- r | P%B) F%O) : order_scope. Notation "\meet^p_ ( i <- r ) F" := (\big[meet / \top]_(i <- r) F%O) : order_scope. Notation "\meet^p_ ( i | P ) F" := (\big[meet / \top]_(i | P%B) F%O) : order_scope. Notation "\meet^p_ i F" := (\big[meet / \top]_i F%O) : order_scope. Notation "\meet^p_ ( i : I | P ) F" := (\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\meet^p_ ( i : I ) F" := (\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope. Notation "\meet^p_ ( m <= i < n | P ) F" := (\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\meet^p_ ( m <= i < n ) F" := (\big[meet / \top]_(m <= i < n) F%O) : order_scope. Notation "\meet^p_ ( i < n | P ) F" := (\big[meet / \top]_(i < n | P%B) F%O) : order_scope. Notation "\meet^p_ ( i < n ) F" := (\big[meet / \top]_(i < n) F%O) : order_scope. Notation "\meet^p_ ( i 'in' A | P ) F" := (\big[meet / \top]_(i in A | P%B) F%O) : order_scope. Notation "\meet^p_ ( i 'in' A ) F" := (\big[meet / \top]_(i in A) F%O) : order_scope. Notation "\min^p_ i F" := (\big[min/top]_i F) : order_scope. Notation "\min^p_ ( i <- r | P ) F" := (\big[min/top]_(i <- r | P%B) F%O) : order_scope. Notation "\min^p_ ( i < r ) F" := (\big[min/top]_(i <- r) F%O) : order_scope. Notation "\min^p_ ( m <= i < n | P ) F" := (\big[min/top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\min^p_ ( m <= i < n ) F" := (\big[min/top]_(m <= i < n) F%O) : order_scope. Notation "\min^p_ ( i | P ) F" := (\big[min/top]_(i | P%B) F%O) : order_scope. Notation "\min^p_ ( i : t | P ) F" := (\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\min^p_ ( i : t ) F" := (\big[min/top]_(i : t) F%O) (only parsing) : order_scope. Notation "\min^p_ ( i < n | P ) F" := (\big[min/top]_(i < n | P%B) F%O) : order_scope. Notation "\min^p_ ( i < n ) F" := (\big[min/top]_(i < n) F%O) : order_scope. Notation "\min^p_ ( i 'in' A | P ) F" := (\big[min/top]_(i in A | P%B) F%O) : order_scope. Notation "\min^p_ ( i 'in' A ) F" := (\big[min/top]_(i in A) F%O) : order_scope. Notation "\max^p_ i F" := (\big[max/bottom]_i F%O) : order_scope. Notation "\max^p_ ( i <- r | P ) F" := (\big[max/bottom]_(i <- r | P%B) F%O) : order_scope. Notation "\max^p_ ( i < r ) F" := (\big[max/bottom]_(i <- r) F%O) : order_scope. Notation "\max^p_ ( m <= i < n | P ) F" := (\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope. Notation "\max^p_ ( m <= i < n ) F" := (\big[max/bottom]_(m <= i < n) F%O) : order_scope. Notation "\max^p_ ( i | P ) F" := (\big[max/bottom]_(i | P%B) F%O) : order_scope. Notation "\max^p_ ( i : t | P ) F" := (\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\max^p_ ( i : t ) F" := (\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope. Notation "\max^p_ ( i < n | P ) F" := (\big[max/bottom]_(i < n | P%B) F%O) : order_scope. Notation "\max^p_ ( i < n ) F" := (\big[max/bottom]_(i < n) F%O) : order_scope. Notation "\max^p_ ( i 'in' A | P ) F" := (\big[max/bottom]_(i in A | P%B) F%O) : order_scope. Notation "\max^p_ ( i 'in' A ) F" := (\big[max/bottom]_(i in A) F%O) : order_scope. End ProdSyntax. Module Import SeqProdSyntax. Export SeqProdSyntax. (* The following Local Notations are here to define the \join^sp_ and *) (* \meet^sp_ notations later. Do not remove them. *) Local Notation "\bot" := (@bottom (seqprod_display _) _). Local Notation "\top" := (@top (seqprod_display _) _). Local Notation meet := (@meet (seqprod_display _) _). Local Notation join := (@join (seqprod_display _) _). Local Notation min := (@min (seqprod_display _) _). Local Notation max := (@max (seqprod_display _) _). Notation "x `&^sp` y" := (meet x y) : order_scope. Notation "x `|^sp` y" := (join x y) : order_scope. Notation "\join^sp_ ( i <- r | P ) F" := (\big[join / \bot]_(i <- r | P%B) F%O) : order_scope. Notation "\join^sp_ ( i <- r ) F" := (\big[join / \bot]_(i <- r) F%O) : order_scope. Notation "\join^sp_ ( i | P ) F" := (\big[join / \bot]_(i | P%B) F%O) : order_scope. Notation "\join^sp_ i F" := (\big[join / \bot]_i F%O) : order_scope. Notation "\join^sp_ ( i : I | P ) F" := (\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\join^sp_ ( i : I ) F" := (\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope. Notation "\join^sp_ ( m <= i < n | P ) F" := (\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope. Notation "\join^sp_ ( m <= i < n ) F" := (\big[join / \bot]_(m <= i < n) F%O) : order_scope. Notation "\join^sp_ ( i < n | P ) F" := (\big[join / \bot]_(i < n | P%B) F%O) : order_scope. Notation "\join^sp_ ( i < n ) F" := (\big[join / \bot]_(i < n) F%O) : order_scope. Notation "\join^sp_ ( i 'in' A | P ) F" := (\big[join / \bot]_(i in A | P%B) F%O) : order_scope. Notation "\join^sp_ ( i 'in' A ) F" := (\big[join / \bot]_(i in A) F%O) : order_scope. Notation "\meet^sp_ ( i <- r | P ) F" := (\big[meet / \top]_(i <- r | P%B) F%O) : order_scope. Notation "\meet^sp_ ( i <- r ) F" := (\big[meet / \top]_(i <- r) F%O) : order_scope. Notation "\meet^sp_ ( i | P ) F" := (\big[meet / \top]_(i | P%B) F%O) : order_scope. Notation "\meet^sp_ i F" := (\big[meet / \top]_i F%O) : order_scope. Notation "\meet^sp_ ( i : I | P ) F" := (\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\meet^sp_ ( i : I ) F" := (\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope. Notation "\meet^sp_ ( m <= i < n | P ) F" := (\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\meet^sp_ ( m <= i < n ) F" := (\big[meet / \top]_(m <= i < n) F%O) : order_scope. Notation "\meet^sp_ ( i < n | P ) F" := (\big[meet / \top]_(i < n | P%B) F%O) : order_scope. Notation "\meet^sp_ ( i < n ) F" := (\big[meet / \top]_(i < n) F%O) : order_scope. Notation "\meet^sp_ ( i 'in' A | P ) F" := (\big[meet / \top]_(i in A | P%B) F%O) : order_scope. Notation "\meet^sp_ ( i 'in' A ) F" := (\big[meet / \top]_(i in A) F%O) : order_scope. Notation "\min^sp_ i F" := (\big[min/top]_i F) : order_scope. Notation "\min^sp_ ( i <- r | P ) F" := (\big[min/top]_(i <- r | P%B) F%O) : order_scope. Notation "\min^sp_ ( i < r ) F" := (\big[min/top]_(i <- r) F%O) : order_scope. Notation "\min^sp_ ( m <= i < n | P ) F" := (\big[min/top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\min^sp_ ( m <= i < n ) F" := (\big[min/top]_(m <= i < n) F%O) : order_scope. Notation "\min^sp_ ( i | P ) F" := (\big[min/top]_(i | P%B) F%O) : order_scope. Notation "\min^sp_ ( i : t | P ) F" := (\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\min^sp_ ( i : t ) F" := (\big[min/top]_(i : t) F%O) (only parsing) : order_scope. Notation "\min^sp_ ( i < n | P ) F" := (\big[min/top]_(i < n | P%B) F%O) : order_scope. Notation "\min^sp_ ( i < n ) F" := (\big[min/top]_(i < n) F%O) : order_scope. Notation "\min^sp_ ( i 'in' A | P ) F" := (\big[min/top]_(i in A | P%B) F%O) : order_scope. Notation "\min^sp_ ( i 'in' A ) F" := (\big[min/top]_(i in A) F%O) : order_scope. Notation "\max^sp_ i F" := (\big[max/bottom]_i F%O) : order_scope. Notation "\max^sp_ ( i <- r | P ) F" := (\big[max/bottom]_(i <- r | P%B) F%O) : order_scope. Notation "\max^sp_ ( i < r ) F" := (\big[max/bottom]_(i <- r) F%O) : order_scope. Notation "\max^sp_ ( m <= i < n | P ) F" := (\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope. Notation "\max^sp_ ( m <= i < n ) F" := (\big[max/bottom]_(m <= i < n) F%O) : order_scope. Notation "\max^sp_ ( i | P ) F" := (\big[max/bottom]_(i | P%B) F%O) : order_scope. Notation "\max^sp_ ( i : t | P ) F" := (\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\max^sp_ ( i : t ) F" := (\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope. Notation "\max^sp_ ( i < n | P ) F" := (\big[max/bottom]_(i < n | P%B) F%O) : order_scope. Notation "\max^sp_ ( i < n ) F" := (\big[max/bottom]_(i < n) F%O) : order_scope. Notation "\max^sp_ ( i 'in' A | P ) F" := (\big[max/bottom]_(i in A | P%B) F%O) : order_scope. Notation "\max^sp_ ( i 'in' A ) F" := (\big[max/bottom]_(i in A) F%O) : order_scope. End SeqProdSyntax. Module Import LexiSyntax. Export LexiSyntax. Notation meetlexi := (@meet (lexi_display _ _) _). Notation joinlexi := (@join (lexi_display _ _) _). Notation "x `&^l` y" := (meetlexi x y) : order_scope. Notation "x `|^l` y" := (joinlexi x y) : order_scope. (* The following Local Notations are here to define the \join^l_ and \meet^l_ *) (* notations later. Do not remove them. *) Local Notation "\bot" := (@bottom (lexi_display _ _) _). Local Notation "\top" := (@top (lexi_display _ _) _). Local Notation meet := (@meet (lexi_display _ _) _). Local Notation join := (@join (lexi_display _ _) _). Local Notation min := (@min (lexi_display _ _) _). Local Notation max := (@max (lexi_display _ _) _). Notation "\join^l_ ( i <- r | P ) F" := (\big[join / \bot]_(i <- r | P%B) F%O) : order_scope. Notation "\join^l_ ( i <- r ) F" := (\big[join / \bot]_(i <- r) F%O) : order_scope. Notation "\join^l_ ( i | P ) F" := (\big[join / \bot]_(i | P%B) F%O) : order_scope. Notation "\join^l_ i F" := (\big[join / \bot]_i F%O) : order_scope. Notation "\join^l_ ( i : I | P ) F" := (\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\join^l_ ( i : I ) F" := (\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope. Notation "\join^l_ ( m <= i < n | P ) F" := (\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope. Notation "\join^l_ ( m <= i < n ) F" := (\big[join / \bot]_(m <= i < n) F%O) : order_scope. Notation "\join^l_ ( i < n | P ) F" := (\big[join / \bot]_(i < n | P%B) F%O) : order_scope. Notation "\join^l_ ( i < n ) F" := (\big[join / \bot]_(i < n) F%O) : order_scope. Notation "\join^l_ ( i 'in' A | P ) F" := (\big[join / \bot]_(i in A | P%B) F%O) : order_scope. Notation "\join^l_ ( i 'in' A ) F" := (\big[join / \bot]_(i in A) F%O) : order_scope. Notation "\meet^l_ ( i <- r | P ) F" := (\big[meet / \top]_(i <- r | P%B) F%O) : order_scope. Notation "\meet^l_ ( i <- r ) F" := (\big[meet / \top]_(i <- r) F%O) : order_scope. Notation "\meet^l_ ( i | P ) F" := (\big[meet / \top]_(i | P%B) F%O) : order_scope. Notation "\meet^l_ i F" := (\big[meet / \top]_i F%O) : order_scope. Notation "\meet^l_ ( i : I | P ) F" := (\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\meet^l_ ( i : I ) F" := (\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope. Notation "\meet^l_ ( m <= i < n | P ) F" := (\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\meet^l_ ( m <= i < n ) F" := (\big[meet / \top]_(m <= i < n) F%O) : order_scope. Notation "\meet^l_ ( i < n | P ) F" := (\big[meet / \top]_(i < n | P%B) F%O) : order_scope. Notation "\meet^l_ ( i < n ) F" := (\big[meet / \top]_(i < n) F%O) : order_scope. Notation "\meet^l_ ( i 'in' A | P ) F" := (\big[meet / \top]_(i in A | P%B) F%O) : order_scope. Notation "\meet^l_ ( i 'in' A ) F" := (\big[meet / \top]_(i in A) F%O) : order_scope. Notation "\min^l_ i F" := (\big[min/top]_i F) : order_scope. Notation "\min^l_ ( i <- r | P ) F" := (\big[min/top]_(i <- r | P%B) F%O) : order_scope. Notation "\min^l_ ( i < r ) F" := (\big[min/top]_(i <- r) F%O) : order_scope. Notation "\min^l_ ( m <= i < n | P ) F" := (\big[min/top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\min^l_ ( m <= i < n ) F" := (\big[min/top]_(m <= i < n) F%O) : order_scope. Notation "\min^l_ ( i | P ) F" := (\big[min/top]_(i | P%B) F%O) : order_scope. Notation "\min^l_ ( i : t | P ) F" := (\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\min^l_ ( i : t ) F" := (\big[min/top]_(i : t) F%O) (only parsing) : order_scope. Notation "\min^l_ ( i < n | P ) F" := (\big[min/top]_(i < n | P%B) F%O) : order_scope. Notation "\min^l_ ( i < n ) F" := (\big[min/top]_(i < n) F%O) : order_scope. Notation "\min^l_ ( i 'in' A | P ) F" := (\big[min/top]_(i in A | P%B) F%O) : order_scope. Notation "\min^l_ ( i 'in' A ) F" := (\big[min/top]_(i in A) F%O) : order_scope. Notation "\max^l_ i F" := (\big[max/bottom]_i F%O) : order_scope. Notation "\max^l_ ( i <- r | P ) F" := (\big[max/bottom]_(i <- r | P%B) F%O) : order_scope. Notation "\max^l_ ( i < r ) F" := (\big[max/bottom]_(i <- r) F%O) : order_scope. Notation "\max^l_ ( m <= i < n | P ) F" := (\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope. Notation "\max^l_ ( m <= i < n ) F" := (\big[max/bottom]_(m <= i < n) F%O) : order_scope. Notation "\max^l_ ( i | P ) F" := (\big[max/bottom]_(i | P%B) F%O) : order_scope. Notation "\max^l_ ( i : t | P ) F" := (\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\max^l_ ( i : t ) F" := (\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope. Notation "\max^l_ ( i < n | P ) F" := (\big[max/bottom]_(i < n | P%B) F%O) : order_scope. Notation "\max^l_ ( i < n ) F" := (\big[max/bottom]_(i < n) F%O) : order_scope. Notation "\max^l_ ( i 'in' A | P ) F" := (\big[max/bottom]_(i in A | P%B) F%O) : order_scope. Notation "\max^l_ ( i 'in' A ) F" := (\big[max/bottom]_(i in A) F%O) : order_scope. End LexiSyntax. Module Import SeqLexiSyntax. Export SeqLexiSyntax. Notation meetlexi := (@meet (seqlexi_display _) _). Notation joinlexi := (@join (seqlexi_display _) _). Notation "x `&^l` y" := (meetlexi x y) : order_scope. Notation "x `|^l` y" := (joinlexi x y) : order_scope. (* The following Local Notations are here to define the \join^l_ and \meet^l_ *) (* notations later. Do not remove them. *) Local Notation "\bot" := (@bottom (lexi_display _ _) _). Local Notation "\top" := (@top (lexi_display _ _) _). Local Notation meet := (@meet (lexi_display _ _) _). Local Notation join := (@join (lexi_display _ _) _). Local Notation min := (@min (lexi_display _ _) _). Local Notation max := (@max (lexi_display _ _) _). Notation "\join^l_ ( i <- r | P ) F" := (\big[join / \bot]_(i <- r | P%B) F%O) : order_scope. Notation "\join^l_ ( i <- r ) F" := (\big[join / \bot]_(i <- r) F%O) : order_scope. Notation "\join^l_ ( i | P ) F" := (\big[join / \bot]_(i | P%B) F%O) : order_scope. Notation "\join^l_ i F" := (\big[join / \bot]_i F%O) : order_scope. Notation "\join^l_ ( i : I | P ) F" := (\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\join^l_ ( i : I ) F" := (\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope. Notation "\join^l_ ( m <= i < n | P ) F" := (\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope. Notation "\join^l_ ( m <= i < n ) F" := (\big[join / \bot]_(m <= i < n) F%O) : order_scope. Notation "\join^l_ ( i < n | P ) F" := (\big[join / \bot]_(i < n | P%B) F%O) : order_scope. Notation "\join^l_ ( i < n ) F" := (\big[join / \bot]_(i < n) F%O) : order_scope. Notation "\join^l_ ( i 'in' A | P ) F" := (\big[join / \bot]_(i in A | P%B) F%O) : order_scope. Notation "\join^l_ ( i 'in' A ) F" := (\big[join / \bot]_(i in A) F%O) : order_scope. Notation "\meet^l_ ( i <- r | P ) F" := (\big[meet / \top]_(i <- r | P%B) F%O) : order_scope. Notation "\meet^l_ ( i <- r ) F" := (\big[meet / \top]_(i <- r) F%O) : order_scope. Notation "\meet^l_ ( i | P ) F" := (\big[meet / \top]_(i | P%B) F%O) : order_scope. Notation "\meet^l_ i F" := (\big[meet / \top]_i F%O) : order_scope. Notation "\meet^l_ ( i : I | P ) F" := (\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope. Notation "\meet^l_ ( i : I ) F" := (\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope. Notation "\meet^l_ ( m <= i < n | P ) F" := (\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\meet^l_ ( m <= i < n ) F" := (\big[meet / \top]_(m <= i < n) F%O) : order_scope. Notation "\meet^l_ ( i < n | P ) F" := (\big[meet / \top]_(i < n | P%B) F%O) : order_scope. Notation "\meet^l_ ( i < n ) F" := (\big[meet / \top]_(i < n) F%O) : order_scope. Notation "\meet^l_ ( i 'in' A | P ) F" := (\big[meet / \top]_(i in A | P%B) F%O) : order_scope. Notation "\meet^l_ ( i 'in' A ) F" := (\big[meet / \top]_(i in A) F%O) : order_scope. Notation "\min^l_ i F" := (\big[min/top]_i F) : order_scope. Notation "\min^l_ ( i <- r | P ) F" := (\big[min/top]_(i <- r | P%B) F%O) : order_scope. Notation "\min^l_ ( i < r ) F" := (\big[min/top]_(i <- r) F%O) : order_scope. Notation "\min^l_ ( m <= i < n | P ) F" := (\big[min/top]_(m <= i < n | P%B) F%O) : order_scope. Notation "\min^l_ ( m <= i < n ) F" := (\big[min/top]_(m <= i < n) F%O) : order_scope. Notation "\min^l_ ( i | P ) F" := (\big[min/top]_(i | P%B) F%O) : order_scope. Notation "\min^l_ ( i : t | P ) F" := (\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\min^l_ ( i : t ) F" := (\big[min/top]_(i : t) F%O) (only parsing) : order_scope. Notation "\min^l_ ( i < n | P ) F" := (\big[min/top]_(i < n | P%B) F%O) : order_scope. Notation "\min^l_ ( i < n ) F" := (\big[min/top]_(i < n) F%O) : order_scope. Notation "\min^l_ ( i 'in' A | P ) F" := (\big[min/top]_(i in A | P%B) F%O) : order_scope. Notation "\min^l_ ( i 'in' A ) F" := (\big[min/top]_(i in A) F%O) : order_scope. Notation "\max^l_ i F" := (\big[max/bottom]_i F%O) : order_scope. Notation "\max^l_ ( i <- r | P ) F" := (\big[max/bottom]_(i <- r | P%B) F%O) : order_scope. Notation "\max^l_ ( i < r ) F" := (\big[max/bottom]_(i <- r) F%O) : order_scope. Notation "\max^l_ ( m <= i < n | P ) F" := (\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope. Notation "\max^l_ ( m <= i < n ) F" := (\big[max/bottom]_(m <= i < n) F%O) : order_scope. Notation "\max^l_ ( i | P ) F" := (\big[max/bottom]_(i | P%B) F%O) : order_scope. Notation "\max^l_ ( i : t | P ) F" := (\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope. Notation "\max^l_ ( i : t ) F" := (\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope. Notation "\max^l_ ( i < n | P ) F" := (\big[max/bottom]_(i < n | P%B) F%O) : order_scope. Notation "\max^l_ ( i < n ) F" := (\big[max/bottom]_(i < n) F%O) : order_scope. Notation "\max^l_ ( i 'in' A | P ) F" := (\big[max/bottom]_(i in A | P%B) F%O) : order_scope. Notation "\max^l_ ( i 'in' A ) F" := (\big[max/bottom]_(i in A) F%O) : order_scope. End SeqLexiSyntax. (************************************************) (* We declare an alias of the cartesian product *) (* which has canonical product order. *) (************************************************) Module ProdOrder. Export ProdOrder. Local Open Scope type_scope. (* FIXME *) Section POrder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : porderType disp1) (T2 : porderType disp2). Fact anti : antisymmetric (@le disp1 disp2 disp2 T1 T2). Proof. case=> [? ?] [? ?]. by rewrite andbAC andbA andbAC -andbA => /= /andP [] /le_anti -> /le_anti ->. Qed. End POrder. Section POrder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : porderType disp1) (T2 : porderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Let T1' : Type := T1. HB.instance Definition _ := POrder.on T1'. Let T2' : Type := T2. HB.instance Definition _ := POrder.on T2'. #[export] HB.instance Definition _ := Preorder_isDuallyPOrder.Build disp3 (T1 * T2) (@anti _ _ T1' T2') (@anti _ _ T1^d T2^d). Lemma ltEprod x y : (x < y) = [&& x != y, x.1 <= y.1 & x.2 <= y.2]. Proof. by rewrite lt_neqAle. Qed. Lemma lt_pair (x1 y1 : T1) (x2 y2 : T2) : (x1, x2) < (y1, y2) :> T1 * T2 = [&& (x1 != y1) || (x2 != y2), x1 <= y1 & x2 <= y2]. Proof. by rewrite ltEprod negb_and. Qed. End POrder. Section MeetSemilattice. Context (disp1 disp2 : disp_t). Context (T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2). Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Let meet x y := (x.1 `&` y.1, x.2 `&` y.2). Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z). Proof. by rewrite leEprod !lexI andbACA. Qed. End MeetSemilattice. Section MeetSemilattice. Context (disp1 disp2 disp3 : disp_t). Context (T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Let T1' : Type := T1. HB.instance Definition _ := MeetSemilattice.on T1'. Let T2' : Type := T2. HB.instance Definition _ := MeetSemilattice.on T2'. Definition meet x y := (x.1 `&` y.1, x.2 `&` y.2). #[export] HB.instance Definition _ := @POrder_isMeetSemilattice.Build disp3 (T1 * T2) meet (@lexI _ _ T1' T2'). Lemma meetEprod x y : x `&` y = (x.1 `&` y.1, x.2 `&` y.2). Proof. by []. Qed. End MeetSemilattice. Section JoinSemilattice. Context (disp1 disp2 disp3 : disp_t). Context (T1 : joinSemilatticeType disp1) (T2 : joinSemilatticeType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Definition join x y := (x.1 `|` y.1, x.2 `|` y.2). #[export] HB.instance Definition _ := @POrder_isJoinSemilattice.Build disp3 (T1 * T2) join (fun x y z => @lexI _ _ T1^d T2^d z x y). Lemma joinEprod x y : x `|` y = (x.1 `|` y.1, x.2 `|` y.2). Proof. by []. Qed. End JoinSemilattice. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : bPOrderType disp1) (T2 : bPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tPOrderType disp1) (T2 : tPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tbPOrderType disp1) (T2 : tbPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : bMeetSemilatticeType disp1) (T2 : bMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tMeetSemilatticeType disp1) (T2 : tMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tbMeetSemilatticeType disp1) (T2 : tbMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : bJoinSemilatticeType disp1) (T2 : bJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tJoinSemilatticeType disp1) (T2 : tJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tbJoinSemilatticeType disp1) (T2 : tbJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : latticeType disp1) (T2 : latticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : bLatticeType disp1) (T2 : bLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tLatticeType disp1) (T2 : tLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tbLatticeType disp1) (T2 : tbLatticeType disp2) := POrder.on (type disp3 T1 T2). (* /FIXME *) Section DistrLattice. Context (disp1 disp2 : disp_t). Context (T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2). Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope. Fact meetUl : @left_distributive (T1 * T2) _ Order.meet Order.join. Proof. by move=> ? ? ?; rewrite meetEprod !meetUl. Qed. End DistrLattice. Section DistrLattice. Context (disp1 disp2 disp3 : disp_t). Context (T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Let T1' : Type := T1. HB.instance Definition _ := DistrLattice.on T1'. Let T2' : Type := T2. HB.instance Definition _ := DistrLattice.on T2'. #[export] HB.instance Definition _ := Lattice_isDistributive.Build disp3 (T1 * T2) (@meetUl _ _ T1' T2') (@meetUl _ _ T1^d T2^d). End DistrLattice. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : bDistrLatticeType disp1) (T2 : bDistrLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tDistrLatticeType disp1) (T2 : tDistrLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tbDistrLatticeType disp1) (T2 : tbDistrLatticeType disp2) := POrder.on (type disp3 T1 T2). (* /FIXME *) Section CDistrLattice. Context (disp1 disp2 : disp_t). Context (T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2). Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope. Implicit Types (x y z : T1 * T2). Let rcompl x y z := (rcompl x.1 y.1 z.1, rcompl x.2 y.2 z.2). Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y. Proof. by rewrite !(meetEprod, joinEprod) !rcomplPmeet. Qed. End CDistrLattice. Section CDistrLattice. Context (disp1 disp2 disp3 : disp_t). Context (T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y z : T1 * T2). Let T1' : Type := T1. HB.instance Definition _ := CDistrLattice.on T1'. Let T2' : Type := T2. HB.instance Definition _ := CDistrLattice.on T2'. Definition rcompl x y z := (rcompl x.1 y.1 z.1, rcompl x.2 y.2 z.2). #[export] HB.instance Definition _ := @DistrLattice_hasRelativeComplement.Build disp3 (T1 * T2) rcompl (@rcomplPmeet _ _ T1' T2') (fun x y => @rcomplPmeet _ _ T1^d T2^d y x). Lemma rcomplEprod x y z : rcompl x y z = (Order.rcompl x.1 y.1 z.1, Order.rcompl x.2 y.2 z.2). Proof. by []. Qed. End CDistrLattice. Section CBDistrLattice. Context (disp1 disp2 : disp_t). Context (T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2). Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Let diff x y := (diff x.1 y.1, diff x.2 y.2). Fact diffErcompl x y : diff x y = rcompl \bot x y. Proof. by rewrite /diff !diffErcompl. Qed. End CBDistrLattice. Section CBDistrLattice. Context (disp1 disp2 disp3 : disp_t). Context (T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Let T1' : Type := T1. HB.instance Definition _ := CBDistrLattice.on T1'. Let T2' : Type := T2. HB.instance Definition _ := CBDistrLattice.on T2'. Definition diff x y := (diff x.1 y.1, diff x.2 y.2). #[export] HB.instance Definition _ := @CDistrLattice_hasSectionalComplement.Build disp3 (T1 * T2) diff (@diffErcompl _ _ T1' T2'). Lemma diffEprod x y : x `\` y = (x.1 `\` y.1, x.2 `\` y.2). Proof. by []. Qed. End CBDistrLattice. Section CTDistrLattice. Context (disp1 disp2 disp3 : disp_t). Context (T1 : ctDistrLatticeType disp1) (T2 : ctDistrLatticeType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Definition codiff x y := (codiff x.1 y.1, codiff x.2 y.2). #[export] HB.instance Definition _ := @CDistrLattice_hasDualSectionalComplement.Build disp3 (T1 * T2) codiff (@diffErcompl _ _ T1^d T2^d). Lemma codiffEprod x y : codiff x y = (Order.codiff x.1 y.1, Order.codiff x.2 y.2). Proof. by []. Qed. End CTDistrLattice. Section CTBDistrLattice. Context (disp1 disp2 : disp_t). Context (T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2). Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope. Implicit Types (x : T1 * T2). Let compl x := (~` x.1, ~` x.2). Fact complEdiff x : compl x = (\top : T1 * T2) `\` x. Proof. by rewrite /compl !complEdiff. Qed. End CTBDistrLattice. Section CTBDistrLattice. Context (disp1 disp2 disp3 : disp_t). Context (T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x : T1 * T2). Let T1' : Type := T1. HB.instance Definition _ := CTBDistrLattice.on T1'. Let T2' : Type := T2. HB.instance Definition _ := CTBDistrLattice.on T2'. Definition compl x := (~` x.1, ~` x.2). #[export] HB.instance Definition _ := @CDistrLattice_hasComplement.Build _ (T1 * T2) compl (@complEdiff _ _ T1' T2') (@complEdiff _ _ T1^d T2^d). Lemma complEprod x : ~` x = (~` x.1, ~` x.2). Proof. by []. Qed. End CTBDistrLattice. (* FIXME: use HB.saturate *) Section FinOrder. Context (disp1 disp2 disp3 : disp_t). #[export] HB.instance Definition _ (T1 : finPOrderType disp1) (T2 : finPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finBPOrderType disp1) (T2 : finBPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTPOrderType disp1) (T2 : finTPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTBPOrderType disp1) (T2 : finTBPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finMeetSemilatticeType disp1) (T2 : finMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finBMeetSemilatticeType disp1) (T2 : finBMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finJoinSemilatticeType disp1) (T2 : finJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTJoinSemilatticeType disp1) (T2 : finTJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finLatticeType disp1) (T2 : finLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTBLatticeType disp1) (T2 : finTBLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finDistrLatticeType disp1) (T2 : finDistrLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTBDistrLatticeType disp1) (T2 : finTBDistrLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finCDistrLatticeType disp1) (T2 : finCDistrLatticeType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finCTBDistrLatticeType disp1) (T2 : finCTBDistrLatticeType disp2) := POrder.on (type disp3 T1 T2). End FinOrder. (* /FIXME *) Module Exports. HB.reexport ProdOrder. Definition ltEprod := @ltEprod. Definition lt_pair := @lt_pair. Definition meetEprod := @meetEprod. Definition joinEprod := @joinEprod. Definition rcomplEprod := @rcomplEprod. Definition diffEprod := @diffEprod. Definition codiffEprod := @codiffEprod. Definition complEprod := @complEprod. End Exports. End ProdOrder. HB.export ProdOrder.Exports. Module DefaultProdOrder. Export DefaultProdOrder. Section DefaultProdOrder. Context {disp1 disp2 : disp_t}. Let prod T1 T2 := T1 *prod[prod_display disp1 disp2] T2. (* FIXME: Scopes of arguments are broken in several places. *) (* FIXME: Declaring a bunch of copies is still a bit painful. *) HB.instance Definition _ (T1 : porderType disp1) (T2 : porderType disp2) := POrder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : bPOrderType disp1) (T2 : bPOrderType disp2) := BPOrder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tPOrderType disp1) (T2 : tPOrderType disp2) := TPOrder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tbPOrderType disp1) (T2 : tbPOrderType disp2) := TBPOrder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2) := MeetSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : bMeetSemilatticeType disp1) (T2 : bMeetSemilatticeType disp2) := BMeetSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tMeetSemilatticeType disp1) (T2 : tMeetSemilatticeType disp2) := TMeetSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tbMeetSemilatticeType disp1) (T2 : tbMeetSemilatticeType disp2) := TBMeetSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : joinSemilatticeType disp1) (T2 : joinSemilatticeType disp2) := JoinSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : bJoinSemilatticeType disp1) (T2 : bJoinSemilatticeType disp2) := BJoinSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tJoinSemilatticeType disp1) (T2 : tJoinSemilatticeType disp2) := TJoinSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tbJoinSemilatticeType disp1) (T2 : tbJoinSemilatticeType disp2) := TBJoinSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : latticeType disp1) (T2 : latticeType disp2) := Lattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : bLatticeType disp1) (T2 : bLatticeType disp2) := BLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tLatticeType disp1) (T2 : tLatticeType disp2) := TLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tbLatticeType disp1) (T2 : tbLatticeType disp2) := TBLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2) := DistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : bDistrLatticeType disp1) (T2 : bDistrLatticeType disp2) := BDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tDistrLatticeType disp1) (T2 : tDistrLatticeType disp2) := TDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tbDistrLatticeType disp1) (T2 : tbDistrLatticeType disp2) := TBDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2) := CDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2) := CBDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : ctDistrLatticeType disp1) (T2 : ctDistrLatticeType disp2) := CTDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2) := CTBDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finPOrderType disp1) (T2 : finPOrderType disp2) := FinPOrder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finBPOrderType disp1) (T2 : finBPOrderType disp2) := FinBPOrder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finTPOrderType disp1) (T2 : finTPOrderType disp2) := FinTPOrder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finTBPOrderType disp1) (T2 : finTBPOrderType disp2) := FinTBPOrder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finMeetSemilatticeType disp1) (T2 : finMeetSemilatticeType disp2) := FinMeetSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finBMeetSemilatticeType disp1) (T2 : finBMeetSemilatticeType disp2) := FinBMeetSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finJoinSemilatticeType disp1) (T2 : finJoinSemilatticeType disp2) := FinJoinSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finTJoinSemilatticeType disp1) (T2 : finTJoinSemilatticeType disp2) := FinTJoinSemilattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finLatticeType disp1) (T2 : finLatticeType disp2) := FinLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finTBLatticeType disp1) (T2 : finTBLatticeType disp2) := FinTBLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finDistrLatticeType disp1) (T2 : finDistrLatticeType disp2) := FinDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finTBDistrLatticeType disp1) (T2 : finTBDistrLatticeType disp2) := FinTBDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finCDistrLatticeType disp1) (T2 : finCDistrLatticeType disp2) := FinCDistrLattice.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finCTBDistrLatticeType disp1) (T2 : finCTBDistrLatticeType disp2) := FinCTBDistrLattice.copy (T1 * T2)%type (prod T1 T2). (* /FIXME *) End DefaultProdOrder. End DefaultProdOrder. (*********************************************************) (* We declare lexicographic ordering on dependent pairs. *) (*********************************************************) Module SigmaOrder. Section SigmaOrder. Context {disp1 disp2 : disp_t}. Section POrder. Context (T : porderType disp1) (T' : T -> porderType disp2). Implicit Types (x y : {t : T & T' t}). Definition le x y := (tag x <= tag y) && ((tag x >= tag y) ==> (tagged x <= tagged_as x y)). Definition lt x y := (tag x <= tag y) && ((tag x >= tag y) ==> (tagged x < tagged_as x y)). Fact refl : reflexive le. Proof. by move=> [x x']; rewrite /le tagged_asE/= !lexx. Qed. Fact anti : antisymmetric le. Proof. rewrite /le => -[x x'] [y y']/=; case: comparableP => //= eq_xy. by case: _ / eq_xy in y' *; rewrite !tagged_asE => /le_anti ->. Qed. Fact trans : transitive le. Proof. move=> [y y'] [x x'] [z z'] /andP[/= lexy lexy'] /andP[/= leyz leyz']. rewrite /= /le (le_trans lexy) //=; apply/implyP => lezx. elim: _ / (@le_anti _ _ x y) in y' z' lexy' leyz' *; last first. by rewrite lexy (le_trans leyz). elim: _ / (@le_anti _ _ x z) in z' leyz' *; last by rewrite (le_trans lexy). by rewrite lexx !tagged_asE/= in lexy' leyz' *; rewrite (le_trans lexy'). Qed. Fact lt_le_def x y : lt x y = le x y && ~~ le y x. Proof. rewrite /lt /le; case: x y => [x x'] [y y']//=. case: (comparableP x y) => //= xy. by subst y; rewrite !tagged_asE lt_le_def. Qed. #[export] HB.instance Definition _ := isPreorder.Build disp2 {t : T & T' t} lt_le_def refl trans. #[export] HB.instance Definition _ := Preorder_isPOrder.Build disp2 {t : T & T' t} anti. Lemma leEsig x y : x <= y = (tag x <= tag y) && ((tag x >= tag y) ==> (tagged x <= tagged_as x y)). Proof. by []. Qed. Lemma ltEsig x y : x < y = (tag x <= tag y) && ((tag x >= tag y) ==> (tagged x < tagged_as x y)). Proof. by []. Qed. Lemma le_Taggedl x (u : T' (tag x)) : (Tagged T' u <= x) = (u <= tagged x). Proof. by case: x => [t v]/= in u *; rewrite leEsig/= lexx/= tagged_asE. Qed. Lemma le_Taggedr x (u : T' (tag x)) : (x <= Tagged T' u) = (tagged x <= u). Proof. by case: x => [t v]/= in u *; rewrite leEsig/= lexx/= tagged_asE. Qed. Lemma lt_Taggedl x (u : T' (tag x)) : (Tagged T' u < x) = (u < tagged x). Proof. by case: x => [t v]/= in u *; rewrite ltEsig/= lexx/= tagged_asE. Qed. Lemma lt_Taggedr x (u : T' (tag x)) : (x < Tagged T' u) = (tagged x < u). Proof. by case: x => [t v]/= in u *; rewrite ltEsig/= lexx/= tagged_asE. Qed. End POrder. Section BPOrder. Context (T : bPOrderType disp1) (T' : T -> bPOrderType disp2). Fact le0x (x : {t : T & T' t}) : Tagged T' (\bot : T' \bot) <= x. Proof. by rewrite leEsig /= !le0x implybT. Qed. #[export] HB.instance Definition _ := hasBottom.Build _ {t : T & T' t} le0x. Lemma botEsig : \bot = Tagged T' (\bot : T' \bot). Proof. by []. Qed. End BPOrder. Section TPOrder. Context (T : tPOrderType disp1) (T' : T -> tPOrderType disp2). Fact lex1 (x : {t : T & T' t}) : x <= Tagged T' (\top : T' \top). Proof. rewrite leEsig /=; case: comparableP (lex1 (tag x)) => //=. by case: x => //= x px x0; rewrite x0 in px *; rewrite tagged_asE lex1. Qed. #[export] HB.instance Definition _ := hasTop.Build _ {t : T & T' t} lex1. Lemma topEsig : \top = Tagged T' (\top : T' \top). Proof. by []. Qed. End TPOrder. Section Total. Context (T : orderType disp1) (T' : T -> orderType disp2). Implicit Types (x y : {t : T & T' t}). Fact total : total (<=%O : rel {t : T & T' t}). Proof. move=> x y; rewrite !leEsig; case: (ltgtP (tag x) (tag y)) => //=. case: x y => [x x'] [y y']/= eqxy; elim: _ /eqxy in y' *. by rewrite !tagged_asE le_total. Qed. #[export] HB.instance Definition _ := POrder_isTotal.Build _ {t : T & T' t} total. End Total. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (T : bOrderType disp1) (T' : T -> bOrderType disp2) := POrder.on {t : T & T' t}. #[export] HB.instance Definition _ (T : tOrderType disp1) (T' : T -> tOrderType disp2) := POrder.on {t : T & T' t}. #[export] HB.instance Definition _ (T : tbOrderType disp1) (T' : T -> tbOrderType disp2) := POrder.on {t : T & T' t}. #[export] HB.instance Definition _ (T : finPOrderType disp1) (T' : T -> finPOrderType disp2) := POrder.on {t : T & T' t}. #[export] HB.instance Definition _ (T : finBPOrderType disp1) (T' : T -> finBPOrderType disp2) := POrder.on {t : T & T' t}. #[export] HB.instance Definition _ (T : finTPOrderType disp1) (T' : T -> finTPOrderType disp2) := POrder.on {t : T & T' t}. #[export] HB.instance Definition _ (T : finTBPOrderType disp1) (T' : T -> finTBPOrderType disp2) := POrder.on {t : T & T' t}. #[export] HB.instance Definition _ (T : finOrderType disp1) (T' : T -> finOrderType disp2) := POrder.on {t : T & T' t}. #[export] HB.instance Definition _ (T : finTBOrderType disp1) (T' : T -> finTBOrderType disp2) := POrder.on {t : T & T' t}. (* /FIXME *) End SigmaOrder. Module Exports. HB.reexport SigmaOrder. Definition leEsig := @leEsig. Definition ltEsig := @ltEsig. Definition le_Taggedl := @le_Taggedl. Definition lt_Taggedl := @lt_Taggedl. Definition le_Taggedr := @le_Taggedr. Definition lt_Taggedr := @lt_Taggedr. Definition topEsig := @topEsig. Definition botEsig := @botEsig. End Exports. End SigmaOrder. HB.export SigmaOrder.Exports. (*************************************************) (* We declare an alias of the cartesian product, *) (* which has canonical lexicographic order. *) (*************************************************) Module ProdLexiOrder. Export ProdLexiOrder. Local Open Scope type_scope. (* FIXME *) Section POrder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : porderType disp1) (T2 : porderType disp2). Fact anti : antisymmetric (@le disp1 disp2 disp2 T1 T2). Proof. by rewrite /le => -[x x'] [y y'] /=; case: comparableP => //= -> /le_anti->. Qed. End POrder. Section POrder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : porderType disp1) (T2 : porderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Let T1' : Type := T1. HB.instance Definition _ := POrder.on T1'. Let T2' : Type := T2. HB.instance Definition _ := POrder.on T2'. #[export] HB.instance Definition _ := Preorder_isDuallyPOrder.Build disp3 (T1 * T2) (@anti _ _ T1' T2') (@anti _ _ T1^d T2^d). End POrder. Section Total. Context (disp1 disp2 disp3 : disp_t). Context (T1 : orderType disp1) (T2 : orderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Fact total : total (<=%O : rel (T1 * T2)). Proof. by move=> x y; rewrite !leEprodlexi; case: ltgtP => //= _; exact: le_total. Qed. (* FIXME: In order to dualize this instance, we have to dualize the *) (* [POrder_isTotal] factory. However, [min] and max are not definitional dual *) (* (while [min x y] and [max y x] are). *) #[export] HB.instance Definition _ := POrder_isTotal.Build _ (T1 * T2) total. End Total. (* FIXME: use HB.saturate *) Section ProdLexiOrder. Context (disp1 disp2 disp3 : disp_t). #[export] HB.instance Definition _ (T1 : finPOrderType disp1) (T2 : finPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finBPOrderType disp1) (T2 : finBPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTPOrderType disp1) (T2 : finTPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTBPOrderType disp1) (T2 : finTBPOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finOrderType disp1) (T2 : finOrderType disp2) := POrder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTBOrderType disp1) (T2 : finTBOrderType disp2) := POrder.on (type disp3 T1 T2). End ProdLexiOrder. (* /FIXME *) Module Exports. HB.reexport ProdLexiOrder. End Exports. End ProdLexiOrder. HB.export ProdLexiOrder.Exports. Module DefaultProdLexiOrder. Export DefaultProdLexiOrder. Section DefaultProdLexiOrder. Context {disp1 disp2 : disp_t}. Let prodlexi T1 T2 := T1 *lexi[lexi_display disp1 disp2] T2. (* FIXME: Scopes of arguments are broken in several places. *) (* FIXME: Declaring a bunch of copies is still a bit painful. *) HB.instance Definition _ (T1 : porderType disp1) (T2 : porderType disp2) := POrder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : orderType disp1) (T2 : orderType disp2) := Total.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finPOrderType disp1) (T2 : finPOrderType disp2) := FinPOrder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finBPOrderType disp1) (T2 : finBPOrderType disp2) := FinBPOrder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finTPOrderType disp1) (T2 : finTPOrderType disp2) := FinTPOrder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finTBPOrderType disp1) (T2 : finTBPOrderType disp2) := FinTBPOrder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finOrderType disp1) (T2 : finOrderType disp2) := FinTotal.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finTBOrderType disp1) (T2 : finTBOrderType disp2) := FinTBTotal.copy (T1 * T2)%type (prodlexi T1 T2). (* /FIXME *) End DefaultProdLexiOrder. End DefaultProdLexiOrder. (*****************************************) (* We declare an alias of the sequences, *) (* which has canonical product order. *) (*****************************************) Module SeqProdOrder. Export SeqProdOrder. Section SeqProdOrder. Context {disp disp' : disp_t}. Local Notation seq := (type disp'). Section POrder. Variable T : porderType disp. Implicit Types s : seq T. Fact anti : antisymmetric (@le disp disp' T). Proof. by elim=> [|x s ihs] [|y s'] //=; rewrite andbACA => /andP[/le_anti-> /ihs->]. Qed. #[export] HB.instance Definition _ := Preorder_isPOrder.Build disp' (seq T) anti. End POrder. Section MeetSemilattice. Context (T : meetSemilatticeType disp). Implicit Types (s : seq T). Fixpoint meet s1 s2 := match s1, s2 with | x1 :: s1', x2 :: s2' => (x1 `&` x2) :: meet s1' s2' | _, _ => [::] end. Fact lexI s1 s2 s3 : (s1 <= meet s2 s3) = (s1 <= s2) && (s1 <= s3). Proof. elim: s1 s2 s3 => [|x s1 IHs1] [|y s2] [|z s3] //=; first by rewrite andbF. by rewrite leEseq lexI IHs1 andbACA. Qed. #[export] HB.instance Definition _ := @POrder_isMeetSemilattice.Build _ (seq T) meet lexI. Lemma meetEseq s1 s2 : s1 `&` s2 = [seq x.1 `&` x.2 | x <- zip s1 s2]. Proof. by elim: s1 s2 => [|x s1 ihs1] [|y s2]//=; rewrite -ihs1. Qed. Lemma meet_cons x1 s1 x2 s2 : (x1 :: s1 : seq T) `&` (x2 :: s2) = (x1 `&` x2) :: s1 `&` s2. Proof. by []. Qed. End MeetSemilattice. Section JoinSemilattice. Context (T : joinSemilatticeType disp). Implicit Types (s : seq T). Fixpoint join s1 s2 := match s1, s2 with | [::], _ => s2 | _, [::] => s1 | x1 :: s1', x2 :: s2' => (x1 `|` x2) :: join s1' s2' end. Fact leUx s1 s2 s3 : (join s1 s2 <= s3) = (s1 <= s3) && (s2 <= s3). Proof. elim : s1 s2 s3 => [|x s1 IHs1] [|y s2] [|z s3] //=; first by rewrite andbT. by rewrite leEseq leUx IHs1 andbACA. Qed. #[export] HB.instance Definition _ := @POrder_isJoinSemilattice.Build _ (seq T) join leUx. Lemma joinEseq s1 s2 : s1 `|` s2 = match s1, s2 with | [::], _ => s2 | _, [::] => s1 | x1 :: s1', x2 :: s2' => (x1 `|` x2) :: ((s1' : seq _) `|` s2') end. Proof. by case: s1. Qed. Lemma join_cons x1 s1 x2 s2 : (x1 :: s1 : seq T) `|` (x2 :: s2) = (x1 `|` x2) :: s1 `|` s2. Proof. by []. Qed. End JoinSemilattice. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (T : latticeType disp) := POrder.on (seq T). (* /FIXME *) Section DistrLattice. Context (T : distrLatticeType disp). Fact meetUl : left_distributive (@meet T) (@join T). Proof. by elim=> [|? ? ih] [|? ?] [|? ?] //=; rewrite meetUl ih. Qed. #[export] HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build _ (seq T) meetUl. End DistrLattice. End SeqProdOrder. Module Exports. HB.reexport SeqProdOrder. Definition meetEseq := @meetEseq. Definition meet_cons := @meet_cons. Definition joinEseq := @joinEseq. End Exports. End SeqProdOrder. HB.export SeqProdOrder.Exports. Module DefaultSeqProdOrder. Export DefaultSeqProdOrder. Section DefaultSeqProdOrder. Context {disp : disp_t}. HB.instance Definition _ (T : porderType disp) := POrder.copy (seq T) (seqprod T). HB.instance Definition _ (T : meetSemilatticeType disp) := BMeetSemilattice.copy (seq T) (seqprod T). HB.instance Definition _ (T : joinSemilatticeType disp) := BJoinSemilattice.copy (seq T) (seqprod T). HB.instance Definition _ (T : latticeType disp) := BLattice.copy (seq T) (seqprod T). HB.instance Definition _ (T : distrLatticeType disp) := BDistrLattice.copy (seq T) (seqprod T). End DefaultSeqProdOrder. End DefaultSeqProdOrder. (*********************************************) (* We declare an alias of the sequences, *) (* which has canonical lexicographic order. *) (*********************************************) Module SeqLexiOrder. Export SeqLexiOrder. Section SeqLexiOrder. Context {disp disp' : disp_t}. Local Notation seq := (type disp'). Section POrder. Variable T : porderType disp. Implicit Types s : seq T. Fact anti: antisymmetric (@le disp disp' T). Proof. move=> x y /andP []; elim: x y => [|x sx ih] [|y sy] //=. by case: comparableP => //= -> lesxsy /(ih _ lesxsy) ->. Qed. #[export] HB.instance Definition _ := Preorder_isPOrder.Build disp' (seq T) anti. Lemma neqhead_lexiE (x y : T) s1 s2 : x != y -> (x :: s1 <= y :: s2 :> seq _) = (x < y). Proof. by rewrite lexi_cons; case: comparableP. Qed. Lemma neqhead_ltxiE (x y : T) s1 s2 : x != y -> (x :: s1 < y :: s2 :> seq _) = (x < y). Proof. by rewrite ltxi_cons; case: (comparableP x y). Qed. End POrder. Section Total. Context (T : orderType disp). Fact total : total (<=%O : rel (seq T)). Proof. by elim=> [|x1 s1 ihs1] [|x2 s2]//=; rewrite !lexi_cons; case: ltgtP => /=. Qed. #[export] HB.instance Definition _ := POrder_isTotal.Build _ (seq T) total. End Total. End SeqLexiOrder. Module Exports. HB.reexport SeqLexiOrder. Definition neqhead_lexiE := @neqhead_lexiE. Definition neqhead_ltxiE := @neqhead_ltxiE. End Exports. End SeqLexiOrder. HB.export SeqLexiOrder.Exports. Module DefaultSeqLexiOrder. Export DefaultSeqLexiOrder. Section DefaultSeqLexiOrder. Context {disp : disp_t}. HB.instance Definition _ (T : porderType disp) := POrder.copy (seq T) (seqlexi T). HB.instance Definition _ (T : orderType disp) := BTotal.copy (seq T) (seqlexi T). End DefaultSeqLexiOrder. End DefaultSeqLexiOrder. (***************************************) (* We declare an alias of the tuples, *) (* which has canonical product order. *) (***************************************) Module TupleProdOrder. Export TupleProdOrder. Import DefaultSeqProdOrder. Section TupleProdOrder. Context {disp disp' : disp_t}. Local Notation "n .-tuple" := (type disp' n) : type_scope. Section POrder. Implicit Types (T : porderType disp). #[export, warning="-HB.no-new-instance"] HB.instance Definition _ n T := SubChoice.on (n.-tuple T). #[export] HB.instance Definition _ n T := [SubChoice_isSubPOrder of n.-tuple T by <: with disp']. End POrder. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (n : nat) (T : bPOrderType disp) := POrder.on (n.-tuple T). (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (n : nat) (T : tPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tbPOrderType disp) := POrder.on (n.-tuple T). (* /FIXME *) Section MeetSemilattice. Context (n : nat) (T : meetSemilatticeType disp). Implicit Types (t : n.-tuple T). Definition meet t1 t2 : n.-tuple T := [tuple tnth t1 i `&` tnth t2 i | i < n]. Fact lexI t1 t2 t3 : (t1 <= meet t2 t3) = (t1 <= t2) && (t1 <= t3). Proof. rewrite !leEtprod; apply/forallP/andP => [H|[Ht12 Ht13] i]; last first. by rewrite tnth_mktuple lexI (forallP Ht12) (forallP Ht13). by split; apply/forallP => i; move: (H i); rewrite tnth_mktuple lexI => /andP[]. Qed. #[export] HB.instance Definition _ := @POrder_isMeetSemilattice.Build _ (n.-tuple T) meet lexI. Lemma tnth_meet t1 t2 i : tnth (t1 `&` t2) i = tnth t1 i `&` tnth t2 i. Proof. exact: tnth_mktuple. Qed. Lemma meetEtprod t1 t2 : t1 `&` t2 = [tuple tnth t1 i `&` tnth t2 i | i < n]. Proof. by []. Qed. End MeetSemilattice. Section JoinSemilattice. Context (n : nat) (T : joinSemilatticeType disp). Implicit Types (t : n.-tuple T). Definition join t1 t2 : n.-tuple T := [tuple tnth t1 i `|` tnth t2 i | i < n]. Fact leUx t1 t2 t3 : (join t1 t2 <= t3) = (t1 <= t3) && (t2 <= t3). Proof. rewrite !leEtprod; apply/forallP/andP => [H|[Ht13 Ht23] i]; last first. by rewrite tnth_mktuple leUx (forallP Ht13) (forallP Ht23). by split; apply/forallP => i; move: (H i); rewrite tnth_mktuple leUx => /andP[]. Qed. #[export] HB.instance Definition _ := @POrder_isJoinSemilattice.Build _ (n.-tuple T) join leUx. Lemma tnth_join t1 t2 i : tnth (t1 `|` t2) i = tnth t1 i `|` tnth t2 i. Proof. exact: tnth_mktuple. Qed. Lemma joinEtprod t1 t2 : t1 `|` t2 = [tuple tnth t1 i `|` tnth t2 i | i < n]. Proof. by []. Qed. End JoinSemilattice. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (n : nat) (T : bMeetSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tMeetSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tbMeetSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : bJoinSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tJoinSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tbJoinSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : latticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : bLatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tLatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tbLatticeType disp) := POrder.on (n.-tuple T). (* /FIXME *) Section DistrLattice. Context (n : nat) (T : distrLatticeType disp). Implicit Types (t : n.-tuple T). Fact meetUl : left_distributive (@meet n T) (@join n T). Proof. by move=> t1 t2 t3; apply: eq_from_tnth => i; rewrite !tnth_mktuple meetUl. Qed. #[export] HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build _ (n.-tuple T) meetUl. End DistrLattice. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (n : nat) (T : bDistrLatticeType disp) := DistrLattice.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tDistrLatticeType disp) := DistrLattice.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tbDistrLatticeType disp) := DistrLattice.on (n.-tuple T). (* /FIXME *) Section CDistrLattice. Context (n : nat) (T : cDistrLatticeType disp). Implicit Types (t : n.-tuple T). Definition rcompl t1 t2 t3 := [tuple rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i) | i < n]. Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y. Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple rcomplPmeet. Qed. Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x. Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple rcomplPjoin. Qed. #[export] HB.instance Definition _ := @DistrLattice_hasRelativeComplement.Build _ (n.-tuple T) rcompl rcomplPmeet rcomplPjoin. Lemma tnth_rcompl t1 t2 t3 i : tnth (Order.rcompl t1 t2 t3) i = Order.rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i). Proof. exact: tnth_mktuple. Qed. Lemma rcomplEtprod t1 t2 t3 : Order.rcompl t1 t2 t3 = [tuple Order.rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i) | i < n]. Proof. by []. Qed. End CDistrLattice. Section CBDistrLattice. Context (n : nat) (T : cbDistrLatticeType disp). Implicit Types (t : n.-tuple T). Definition diff t1 t2 : n.-tuple T := [tuple tnth t1 i `\` tnth t2 i | i < n]. Fact diffErcompl t1 t2 : diff t1 t2 = rcompl \bot t1 t2. Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple diffErcompl. Qed. #[export] HB.instance Definition _ := @CDistrLattice_hasSectionalComplement.Build _ (n.-tuple T) diff diffErcompl. Lemma tnth_diff t1 t2 i : tnth (diff t1 t2) i = tnth t1 i `\` tnth t2 i. Proof. exact: tnth_mktuple. Qed. Lemma diffEtprod t1 t2 : t1 `\` t2 = [tuple tnth t1 i `\` tnth t2 i | i < n]. Proof. by []. Qed. End CBDistrLattice. Section CTDistrLattice. Context (n : nat) (T : ctDistrLatticeType disp). Implicit Types (t : n.-tuple T). Definition codiff t1 t2 : n.-tuple T := [tuple Order.codiff (tnth t1 i) (tnth t2 i) | i < n]. Fact codiffErcompl t1 t2 : codiff t1 t2 = rcompl t1 \top t2. Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple codiffErcompl. Qed. #[export] HB.instance Definition _ := @CDistrLattice_hasDualSectionalComplement.Build _ (n.-tuple T) codiff codiffErcompl. Lemma tnth_codiff t1 t2 i : tnth (Order.codiff t1 t2) i = Order.codiff (tnth t1 i) (tnth t2 i). Proof. exact: tnth_mktuple. Qed. Lemma codiffEtprod t1 t2 : Order.codiff t1 t2 = [tuple Order.codiff (tnth t1 i) (tnth t2 i) | i < n]. Proof. by []. Qed. End CTDistrLattice. Section CTBDistrLattice. Context (n : nat) (T : ctbDistrLatticeType disp). Implicit Types (t : n.-tuple T). Definition compl t : n.-tuple T := map_tuple compl t. Fact complEdiff t : compl t = (\top : n.-tuple T) `\` t. Proof. by apply: eq_from_tnth => i; rewrite tnth_map !tnth_mktuple complEdiff. Qed. Fact complEcodiff t : compl t = codiff (\bot : n.-tuple T) t. Proof. by apply: eq_from_tnth => i; rewrite tnth_map !tnth_mktuple complEcodiff. Qed. #[export] HB.instance Definition _ := @CDistrLattice_hasComplement.Build _ (n.-tuple T) compl complEdiff complEcodiff. Lemma tnth_compl t i : tnth (~` t) i = ~` tnth t i. Proof. by rewrite tnth_map. Qed. Lemma complEtprod t : ~` t = map_tuple Order.compl t. Proof. by []. Qed. End CTBDistrLattice. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (n : nat) (T : finPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finBPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTBPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finMeetSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finBMeetSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finJoinSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTJoinSemilatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finLatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTBLatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finDistrLatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTBDistrLatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finCDistrLatticeType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finCTBDistrLatticeType disp) := POrder.on (n.-tuple T). (* /FIXME *) End TupleProdOrder. Module Exports. HB.reexport TupleProdOrder. Definition tnth_meet := @tnth_meet. Definition meetEtprod := @meetEtprod. Definition tnth_join := @tnth_join. Definition joinEtprod := @joinEtprod. Definition tnth_rcompl := @tnth_rcompl. Definition rcomplEtprod := @rcomplEtprod. Definition tnth_diff := @tnth_diff. Definition diffEtprod := @diffEtprod. Definition tnth_codiff := @tnth_codiff. Definition codiffEtprod := @codiffEtprod. Definition tnth_compl := @tnth_compl. Definition complEtprod := @complEtprod. End Exports. End TupleProdOrder. HB.export TupleProdOrder.Exports. Module DefaultTupleProdOrder. Export DefaultTupleProdOrder. Section DefaultTupleProdOrder. Context {disp : disp_t}. HB.instance Definition _ n (T : porderType disp) := POrder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : bPOrderType disp) := BPOrder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tPOrderType disp) := TPOrder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tbPOrderType disp) := TBPOrder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : meetSemilatticeType disp) := MeetSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : bMeetSemilatticeType disp) := BMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tMeetSemilatticeType disp) := TMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tbMeetSemilatticeType disp) := TBMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : joinSemilatticeType disp) := JoinSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : bJoinSemilatticeType disp) := BJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tJoinSemilatticeType disp) := TJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tbJoinSemilatticeType disp) := TBJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : latticeType disp) := Lattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : bLatticeType disp) := BLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tLatticeType disp) := TLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tbLatticeType disp) := TBLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : distrLatticeType disp) := DistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : bDistrLatticeType disp) := BDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tDistrLatticeType disp) := TDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tbDistrLatticeType disp) := TBDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : cDistrLatticeType disp) := CDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : cbDistrLatticeType disp) := CBDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : ctDistrLatticeType disp) := CTDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : ctbDistrLatticeType disp) := CTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finPOrderType disp) := FinPOrder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finBPOrderType disp) := FinBPOrder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finTPOrderType disp) := FinTPOrder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finTBPOrderType disp) := FinTBPOrder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finMeetSemilatticeType disp) := FinMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finBMeetSemilatticeType disp) := FinBMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finJoinSemilatticeType disp) := FinJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finTJoinSemilatticeType disp) := FinTJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finLatticeType disp) := FinLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finTBLatticeType disp) := FinTBLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finDistrLatticeType disp) := FinDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finTBDistrLatticeType disp) := FinTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finCDistrLatticeType disp) := FinCDistrLattice.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : finCTBDistrLatticeType disp) := FinCTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T). End DefaultTupleProdOrder. End DefaultTupleProdOrder. (*********************************************) (* We declare an alias of the tuples, *) (* which has canonical lexicographic order. *) (*********************************************) Module TupleLexiOrder. Export TupleLexiOrder. Section TupleLexiOrder. Import DefaultSeqLexiOrder. Context {disp disp' : disp_t}. Local Notation "n .-tuple" := (type disp' n) : type_scope. Section POrder. Implicit Types (n : nat) (T : porderType disp). #[export] HB.instance Definition _ n T := [SubChoice_isSubPOrder of n.-tuple T by <: with disp']. Lemma lexi_tupleP n T (t1 t2 : n.-tuple T) : reflect (exists k : 'I_n.+1, forall i : 'I_n, (i <= k)%N -> tnth t1 i <= tnth t2 i ?= iff (i != k :> nat)) (t1 <= t2). Proof. elim: n => [|n IHn] in t1 t2 *. by rewrite tuple0 [t2]tuple0/= lexx; constructor; exists ord0 => -[]. case: (tupleP t1) (tupleP t2) => [x1 {}t1] [x2 {}t2]. rewrite [_ <= _]lexi_cons; apply: (iffP idP) => [|[k leif_xt12]]. case: comparableP => //= [ltx12 _|-> /IHn[k kP]]. exists ord0 => i; rewrite leqn0 => /eqP/(@ord_inj n.+1 i ord0)->. by apply/leifP; rewrite !tnth0. exists (lift ord0 k) => i; case: (unliftP ord0 i) => [j ->|-> _]. by rewrite !ltnS => /kP; rewrite !tnthS. by apply/leifP; rewrite !tnth0 eqxx. have /= := leif_xt12 ord0 isT; rewrite !tnth0 => leif_x12. rewrite leif_x12/=; move: leif_x12 leif_xt12 => /leifP. case: (unliftP ord0 k) => {k} [k-> /eqP<-{x2}|-> /lt_geF->//] leif_xt12. rewrite lexx implyTb; apply/IHn; exists k => i le_ik. by have := leif_xt12 (lift ord0 i) le_ik; rewrite !tnthS. Qed. Lemma ltxi_tupleP n T (t1 t2 : n.-tuple T) : reflect (exists k : 'I_n, forall i : 'I_n, (i <= k)%N -> tnth t1 i <= tnth t2 i ?= iff (i != k :> nat)) (t1 < t2). Proof. elim: n => [|n IHn] in t1 t2 *. by rewrite tuple0 [t2]tuple0/= ltxx; constructor => - [] []. case: (tupleP t1) (tupleP t2) => [x1 {}t1] [x2 {}t2]. rewrite [_ < _]ltxi_cons; apply: (iffP idP) => [|[k leif_xt12]]. case: (comparableP x1 x2) => //= [ltx12 _|-> /IHn[k kP]]. exists ord0 => i; rewrite leqn0 => /eqP/(@ord_inj n.+1 i ord0)->. by apply/leifP; rewrite !tnth0. exists (lift ord0 k) => i; case: (unliftP ord0 i) => {i} [i ->|-> _]. by rewrite !ltnS => /kP; rewrite !tnthS. by apply/leifP; rewrite !tnth0 eqxx. have /= := leif_xt12 ord0 isT; rewrite !tnth0 => leif_x12. rewrite leif_x12/=; move: leif_x12 leif_xt12 => /leifP. case: (unliftP ord0 k) => {k} [k-> /eqP<-{x2}|-> /lt_geF->//] leif_xt12. rewrite lexx implyTb; apply/IHn; exists k => i le_ik. by have := leif_xt12 (lift ord0 i) le_ik; rewrite !tnthS. Qed. Lemma ltxi_tuplePlt n T (t1 t2 : n.-tuple T) : reflect (exists2 k : 'I_n, forall i : 'I_n, (i < k)%N -> tnth t1 i = tnth t2 i & tnth t1 k < tnth t2 k) (t1 < t2). Proof. apply: (iffP (ltxi_tupleP _ _)) => [[k kP]|[k kP ltk12]]. exists k => [i i_lt|]; last by rewrite (lt_leif (kP _ _)) ?eqxx ?leqnn. by have /eqTleif->// := kP i (ltnW i_lt); rewrite ltn_eqF. by exists k => i; case: ltngtP => //= [/kP-> _|/ord_inj-> _]; apply/leifP. Qed. End POrder. #[export] HB.instance Definition _ n (T : orderType disp) := [SubChoice_isSubOrder of n.-tuple T by <: with disp']. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (n : nat) (T : bPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tbPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : bOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tbOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finBPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTBPOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finOrderType disp) := POrder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTBOrderType disp) := POrder.on (n.-tuple T). (* /FIXME *) End TupleLexiOrder. Module Exports. HB.reexport TupleLexiOrder. Definition lexi_tupleP := @lexi_tupleP. Arguments lexi_tupleP {disp disp' n T t1 t2}. Definition ltxi_tupleP := @ltxi_tupleP. Arguments ltxi_tupleP {disp disp' n T t1 t2}. Definition ltxi_tuplePlt := @ltxi_tuplePlt. Arguments ltxi_tuplePlt {disp disp' n T t1 t2}. End Exports. End TupleLexiOrder. HB.export TupleLexiOrder.Exports. Module DefaultTupleLexiOrder. Export DefaultTupleLexiOrder. Section DefaultTupleLexiOrder. Context {disp : disp_t}. HB.instance Definition _ n (T : porderType disp) := POrder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : bPOrderType disp) := BPOrder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : tPOrderType disp) := TPOrder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : tbPOrderType disp) := TBPOrder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : orderType disp) := Lattice.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : orderType disp) := DistrLattice.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : orderType disp) := Total.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : bOrderType disp) := BTotal.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : tOrderType disp) := TTotal.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : tbOrderType disp) := TBTotal.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : finPOrderType disp) := FinPOrder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : finBPOrderType disp) := FinBPOrder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : finTPOrderType disp) := FinTPOrder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : finTBPOrderType disp) := FinTBPOrder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : finOrderType disp) := FinTotal.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : finTBOrderType disp) := FinTBTotal.copy (n.-tuple T) (n.-tuplelexi T). End DefaultTupleLexiOrder. End DefaultTupleLexiOrder. (*********************************************) (* We declare an alias of the sets, *) (* which is canonically ordered by inclusion *) (*********************************************) Module SetSubsetOrder. Export SetSubsetOrder. Section SetSubsetOrder. Context {disp : disp_t} {T : finType}. Local Notation "{ 'subset' T }" := (type disp T). Implicit Type (A B C : type disp T). Lemma setKUC B A : A :&: (A :|: B) = A. Proof. by rewrite setUC setKU. Qed. Lemma setKIC B A : A :|: (A :&: B) = A. Proof. by rewrite setIC setKI. Qed. Fact le_anti : antisymmetric (fun A B => A \subset B). Proof. by move=> A B ABA; apply/eqP; rewrite eqEsubset. Qed. #[export] HB.instance Definition _ := Preorder_isPOrder.Build disp {subset T} le_anti. #[export] HB.instance Definition _ := POrder_Meet_isDistrLattice.Build disp {subset T} (@setIC _) (@setUC _) (@setIA _) (@setUA _) setKUC setKIC le_def (@setIUl _). Lemma setIDv A B : B :&: (A :\: B) = set0. Proof. apply/eqP; rewrite -subset0; apply/subsetP => x. by rewrite !inE => /and3P[->]. Qed. #[export] HB.instance Definition _ := @BDistrLattice_hasSectionalComplement.Build disp {subset T} (@setD _) setIDv (@setID _). Lemma setTDsym A : ~: A = setT :\: A. Proof. by rewrite setTD. Qed. #[export] HB.instance Definition _ := CBDistrLattice_hasComplement.Build disp {subset T} setTDsym. Lemma meetEsubset A B : A `&` B = A :&: B. Proof. by []. Qed. Lemma joinEsubset A B : A `|` B = A :|: B. Proof. by []. Qed. Lemma botEsubset : \bot = set0 :> {subset T}. Proof. by []. Qed. Lemma topEsubset : \top = setT :> {subset T}. Proof. by []. Qed. Lemma subEsubset A B : A `\` B = A :\: B. Proof. by []. Qed. Lemma complEsubset A : ~` A = ~: A. Proof. by []. Qed. End SetSubsetOrder. Module Exports. HB.reexport. Definition meetEsubset := @meetEsubset. Definition joinEsubset := @joinEsubset. Definition botEsubset := @botEsubset. Definition topEsubset := @topEsubset. Definition subEsubset := @subEsubset. Definition complEsubset := @complEsubset. End Exports. End SetSubsetOrder. Export SetSubsetOrder.Exports. Module DefaultSetSubsetOrder. Export DefaultSetSubsetOrder. HB.instance Definition _ (T : finType) := CTBDistrLattice.copy {set T} {subset T}. End DefaultSetSubsetOrder. Lemma mono_unique d (T T' : finPOrderType d) (f g : T -> T') : total (<=%O : rel T) -> (#|T'| <= #|T|)%N -> {mono f : x y / x <= y} -> {mono g : x y / x <= y} -> f =1 g. Proof. move=> le_total leT'T lef leg x0; move: {+}x0. suff: finfun f = finfun g by move=> /ffunP + x => /(_ x); rewrite !ffunE. apply: (can_inj fgraphK); apply/val_inj => /=; rewrite !codomE. under eq_map do rewrite ffunE; under [RHS]eq_map do rewrite ffunE. have [finj ginj] := (inc_inj lef, inc_inj leg). have [f' fK f'K] := inj_card_bij finj leT'T. have [g' gK g'K] := inj_card_bij ginj leT'T. apply/eqP; have : [seq f i | i <- enum T] = [seq g i | i <- enum T]. apply: (@sorted_eq _ <=%O le_trans le_anti); rewrite ?mono_sorted_enum//. apply: uniq_perm; rewrite ?map_inj_uniq ?sort_uniq ?fintype.enum_uniq//. move=> x; apply/mapP/mapP => -[y _ ->]. by exists (g' (f y)); rewrite ?mem_enum. by exists (f' (g y)); rewrite ?mem_enum. move=> /eqP; rewrite !eq_map_all all_map [in X in _ -> X]all_map. by have /permPl/perm_all-> := perm_sort <=%O (fintype.enum T). Qed. (* This module should be exported on demand, as in module tagnat below *) Module Import EnumVal. Export EnumVal. Section EnumVal. Import OrdinalOrder.Exports. Variables (d : disp_t) (T : finPOrderType d). Implicit Types (x : T) (A : {pred T}). Section total. (* We circumvent a shortcoming of finOrderType *) (* which requires the type to be nonempty and we do not want to rule this out *) Hypothesis (leT_total : total (<=%O : rel T)). Lemma le_enum_val A : {mono @enum_val _ _ A : i j / i <= j}. Proof. apply: le_mono => i j le_ij. rewrite /enum_val (set_nth_default (enum_default j)) -?cardE//. apply: (sorted_ltn_nth lt_trans); rewrite -?topredE/= -?cardE//. by rewrite lt_sorted_uniq_le enum_uniq/= sort_sorted. Qed. Lemma le_enum_rank_in x0 A (Ax0 : x0 \in A) : {in A &, {mono enum_rank_in Ax0 : x y / x <= y}}. Proof. apply: can_mono_in (@in2W _ _ predT predT _ (@le_enum_val A)) => //. exact/onW_can_in/enum_rankK_in. Qed. Lemma le_enum_rank : {mono @enum_rank d T : i j / i <= j}. Proof. exact: (can_mono (@enum_rankK _ _) (@le_enum_val predT)). Qed. End total. End EnumVal. End EnumVal. Notation le_enum_val := le_enum_val. Notation le_enum_rank_in := le_enum_rank_in. Notation le_enum_rank := le_enum_rank. Module Syntax. Export PreOSyntax. Export DualSyntax. Export DvdSyntax. Export LatticeSyntax. Export BLatticeSyntax. Export TLatticeSyntax. Export CBDistrLatticeSyntax. Export CTBDistrLatticeSyntax. Export DualSyntax. Export DvdSyntax. End Syntax. Module LTheory. Export PreorderTheory. Export BPreorderTheory. Export TPreorderTheory. Export DualPreorder. (* FIXME? *) Export PreOCoercions. Export PreorderTheory. Export POrderTheory. Export BPOrderTheory. Export TPOrderTheory. Export MeetTheory. Export BMeetTheory. Export TMeetTheory. Export JoinTheory. Export BJoinTheory. Export TJoinTheory. Export LatticeTheory. Export DistrLatticeTheory. Export BDistrLatticeTheory. Export TDistrLatticeTheory. Export DualTotalTheory. (* FIXME? *) Export DualOrder. (* FIXME? *) Export OrderMorphismTheory. Export LatticeMorphismTheory. Export BLatticeMorphismTheory. Export TLatticeMorphismTheory. Export ClosedPredicates. Export LatticePred. Export SubPreorderTheory. End LTheory. Module CTheory. Export LTheory. Export CDistrLatticeTheory. Export CBDistrLatticeTheory. Export CTDistrLatticeTheory. Export CTBDistrLatticeTheory. End CTheory. Module TTheory. Export LTheory TotalTheory. End TTheory. Module Theory. Export CTheory TotalTheory. End Theory. Module Exports. HB.reexport. End Exports. End Order. Export Order.Exports. Export Order.Syntax. Export order.Order.Exports. Export Order.POrder.Exports. Export Order.BPOrder.Exports. Export Order.TPOrder.Exports. Export Order.TBPOrder.Exports. Export Order.MeetSemilattice.Exports. Export Order.BMeetSemilattice.Exports. Export Order.TMeetSemilattice.Exports. Export Order.TBMeetSemilattice.Exports. Export Order.JoinSemilattice.Exports. Export Order.BJoinSemilattice.Exports. Export Order.TJoinSemilattice.Exports. Export Order.TBJoinSemilattice.Exports. Export Order.Lattice.Exports. Export Order.BLattice.Exports. Export Order.TLattice.Exports. Export Order.TBLattice.Exports. Export Order.DistrLattice.Exports. Export Order.BDistrLattice.Exports. Export Order.TDistrLattice.Exports. Export Order.TBDistrLattice.Exports. Export Order.Total.Exports. Export Order.BTotal.Exports. Export Order.TTotal.Exports. Export Order.TBTotal.Exports. Export Order.CDistrLattice.Exports. Export Order.CBDistrLattice.Exports. Export Order.CTDistrLattice.Exports. Export Order.CTBDistrLattice.Exports. Export Order.FinPOrder.Exports. Export Order.FinBPOrder.Exports. Export Order.FinTPOrder.Exports. Export Order.FinTBPOrder.Exports. Export Order.FinMeetSemilattice.Exports. Export Order.FinBMeetSemilattice.Exports. Export Order.FinJoinSemilattice.Exports. Export Order.FinTJoinSemilattice.Exports. Export Order.FinLattice.Exports. Export Order.FinTBLattice.Exports. Export Order.FinDistrLattice.Exports. Export Order.FinTBDistrLattice.Exports. Export Order.FinTotal.Exports. Export Order.FinTBTotal.Exports. Export Order.FinCDistrLattice.Exports. Export Order.FinCTBDistrLattice.Exports. (* FIXME: check if covered by Order.Exports *) (* Export Order.NatOrder.Exports. *) (* Export Order.NatMonotonyTheory. *) (* Export Order.NatDvd.Exports. *) (* Export Order.OrdinalOrder.Exports. *) (* Export Order.BoolOrder.Exports. *) (* Export Order.ProdOrder.Exports. *) (* Export Order.SigmaOrder.Exports. *) (* Export Order.ProdLexiOrder.Exports. *) (* Export Order.SeqProdOrder.Exports. *) (* Export Order.SeqLexiOrder.Exports. *) (* Export Order.TupleProdOrder.Exports. *) (* Export Order.TupleLexiOrder.Exports. *) Module DefaultProdOrder := Order.DefaultProdOrder. Module DefaultSeqProdOrder := Order.DefaultSeqProdOrder. Module DefaultTupleProdOrder := Order.DefaultTupleProdOrder. Module DefaultProdLexiOrder := Order.DefaultProdLexiOrder. Module DefaultSeqLexiOrder := Order.DefaultSeqLexiOrder. Module DefaultTupleLexiOrder := Order.DefaultTupleLexiOrder. Import Order.Theory. Module tagnat. Section tagnat. Import Order.EnumVal. Context {n : nat} {p_ : 'I_n -> nat}. Local Notation ordsum := 'I_(\sum_i p_ i)%N. Local Notation T := {i & 'I_(p_ i)}. Implicit Types (i : 'I_n) (s : ordsum) (p : T). Lemma card : #|{: T}| = \sum_i p_ i. Proof. rewrite card_tagged sumnE/= big_map big_enum. by apply: eq_bigr => i _; rewrite card_ord. Qed. Definition sig : ordsum -> T := enum_val \o cast_ord (esym card). Definition rank : T -> ordsum := cast_ord card \o enum_rank. Lemma sigK : cancel sig rank. Proof. by move=> s; rewrite /sig/rank/= enum_valK cast_ord_comp cast_ord_id. Qed. Lemma sig_inj : injective sig. Proof. exact: can_inj sigK. Qed. Lemma rankK : cancel rank sig. Proof. by move=> p; rewrite /sig/rank/= cast_ord_comp cast_ord_id enum_rankK. Qed. Lemma rank_inj : injective rank. Proof. exact: can_inj rankK. Qed. Definition sig1 s : 'I_n := tag (sig s). Definition sig2 s : 'I_(p_ (sig1 s)) := tagged (sig s). Definition Rank i (j : 'I_(p_ i)) := rank (Tagged _ j). Lemma sigE12 s : sig s = @Tagged _ (sig1 s) _ (sig2 s). Proof. by rewrite /sig1 /sig2; case: sig. Qed. Lemma rankE p : rank p = @Rank (tag p) (tagged p). Proof. by case: p. Qed. Lemma sig2K s : Rank (sig2 s) = s. Proof. by rewrite -rankE sigK. Qed. Lemma Rank1K i0 (k : 'I_(p_ i0)) : sig1 (Rank k) = i0. Proof. by rewrite /sig1 /Rank/= rankK/=. Qed. Lemma Rank2K i0 (k : 'I_(p_ i0)) : sig2 (Rank k) = cast_ord (congr1 p_ (esym (Rank1K k))) k. Proof. by apply: val_inj; rewrite /sig2/sig1/Rank/= rankK. Qed. #[local] Hint Resolve sigK rankK : core. Lemma rank_bij : bijective rank. Proof. by exists sig. Qed. Lemma sig_bij : bijective sig. Proof. by exists rank. Qed. Lemma rank_bij_on : {on [pred _ | true], bijective rank}. Proof. exact/onW_bij/rank_bij. Qed. Lemma sig_bij_on : {on [pred _ | true], bijective sig}. Proof. exact/onW_bij/sig_bij. Qed. Lemma le_sig : {mono sig : i j / i <= j}. Proof. by move=> i j; rewrite /sig/= le_enum_val//; apply: le_total. Qed. Lemma le_sig1 : {homo sig1 : i j / i <= j}. Proof. by move=> i j; rewrite /sig1/= -le_sig leEsig/=; case: leP. Qed. Lemma le_rank : {mono rank : p q / p <= q}. Proof. exact: can_mono le_sig. Qed. Lemma le_Rank i : {mono @Rank i : j k / j <= k}. Proof. by move=> j k; rewrite /Rank le_rank/= leEsig/= tagged_asE lexx. Qed. Lemma lt_sig : {mono sig : i j / i < j}. Proof. by move=> i j; rewrite !ltNge le_sig. Qed. Lemma lt_rank : {mono rank : p q / p < q}. Proof. by move=> p q; rewrite !ltNge le_rank. Qed. Lemma lt_Rank i : {mono @Rank i : j k / j < k}. Proof. by move=> j k; rewrite !ltNge le_Rank. Qed. Lemma eq_Rank i i' (j : 'I_(p_ i)) (j': 'I_(p_ i')) : (Rank j == Rank j' :> nat) = (i == i') && (j == j' :> nat). Proof. rewrite val_eqE /Rank -(can_eq sigK) !rankK. case: (i =P i') => ii' /=; last by case: eqVneq => // -[]. by case: _ / ii' in j' *; rewrite eq_Tagged. Qed. Lemma rankEsum p : rank p = \sum_(i < n | (i < tag p)%N) p_ i + tagged p :> nat. Proof. pose sum p := \sum_(i < n | (i < tag p)%N) p_ i + tagged p. rewrite -/(sum _); have sumlt : forall p, (sum p < \sum_i p_ i)%N. rewrite /sum => -[/= i j]. rewrite [ltnRHS](bigID [pred i' : 'I__ | (i' < i)%N])/= ltn_add2l. by rewrite (bigD1 i) ?ltnn//= ltn_addr. suff: rank =1 (fun p => Ordinal (sumlt p)) by move=> /(_ p)/(congr1 val). apply: (Order.mono_unique _ _ le_rank) => //=. - exact: le_total. - by rewrite card card_ord. apply: le_mono => /= -[i j] -[i' j']; rewrite ltEsig/= !ltEord/= /sum leEord/=. case: (ltngtP i i') => //= [ltii' _|/val_inj ii']; last first. by rewrite -ii' in j' *; rewrite tagged_asE => ltjj'; rewrite ltn_add2l. rewrite ltn_addr// (@leq_trans (\sum_(i0 < n | (i0 < i)%N) p_ i0 + p_ i))%N//. by rewrite ltn_add2l. rewrite [leqRHS](bigID [pred i' : 'I__ | (i' < i)%N])/=. rewrite leq_add//; last first. by rewrite (bigD1 i) ?ltnn ?ltii'//= leq_addr. rewrite [leqRHS](eq_bigl [pred k : 'I_n | (k < i)%N])// => k/=. by case: (ltnP k i); rewrite ?andbF// => /ltn_trans->. Qed. Lemma RankEsum i j : @Rank i j = \sum_(k < n | (k < i)%N) p_ k + j :> nat. Proof. by rewrite /Rank rankEsum/=. Qed. Lemma rect s : s = \sum_(i < n | (i < sig1 s)%N) p_ i + sig2 s :> nat. Proof. by rewrite -[s]sigK rankEsum /= sigK. Qed. Lemma eqRank (i0 j : nat) (li0 : (i0 < n)%N) (lj : (j < p_ (Ordinal li0))%N) : (\sum_(i < n | (i < i0)%N) p_ i) + j = Rank (Ordinal lj) :> nat. Proof. by rewrite RankEsum. Qed. End tagnat. End tagnat. Arguments tagnat.Rank {n p_}.
Exp.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Complex.Periodic import Mathlib.Analysis.Complex.UpperHalfPlane.Basic /-! # Exp on the upper half plane This file contains lemmas about the exponential function on the upper half plane. Useful for q-expansions of modular forms. -/ open Real Complex UpperHalfPlane Function local notation "𝕢" => Periodic.qParam theorem Function.Periodic.im_invQParam_pos_of_norm_lt_one {h : ℝ} (hh : 0 < h) {q : ℂ} (hq : ‖q‖ < 1) (hq_ne : q ≠ 0) : 0 < im (Periodic.invQParam h q) := im_invQParam .. ▸ mul_pos_of_neg_of_neg (div_neg_of_neg_of_pos (neg_lt_zero.mpr hh) Real.two_pi_pos) ((Real.log_neg_iff (norm_pos_iff.mpr hq_ne)).mpr hq) lemma Function.Periodic.norm_qParam_le_of_one_half_le_im {ξ : ℂ} (hξ : 1 / 2 ≤ ξ.im) : ‖𝕢 1 ξ‖ ≤ rexp (-π) := by rwa [Periodic.qParam, ofReal_one, div_one, Complex.norm_exp, Real.exp_le_exp, mul_right_comm, mul_I_re, neg_le_neg_iff, ← ofReal_ofNat, ← ofReal_mul, im_ofReal_mul, mul_comm _ π, mul_assoc, le_mul_iff_one_le_right Real.pi_pos, ← div_le_iff₀' two_pos] theorem UpperHalfPlane.norm_qParam_lt_one (n : ℕ) [NeZero n] (τ : ℍ) : ‖𝕢 n τ‖ < 1 := by rw [Periodic.norm_qParam, Real.exp_lt_one_iff, neg_mul, coe_im, neg_mul, neg_div, neg_lt_zero, div_pos_iff_of_pos_right (mod_cast Nat.pos_of_ne_zero <| NeZero.ne _)] positivity theorem UpperHalfPlane.norm_exp_two_pi_I_lt_one (τ : ℍ) : ‖(Complex.exp (2 * π * Complex.I * τ))‖ < 1 := by simpa [Function.Periodic.norm_qParam, Complex.norm_exp] using τ.norm_qParam_lt_one 1 @[deprecated (since := "2025-02-17")] alias Function.Periodic.im_invQParam_pos_of_abs_lt_one := Function.Periodic.im_invQParam_pos_of_norm_lt_one @[deprecated (since := "2025-02-17")] alias Function.Periodic.abs_qParam_le_of_one_half_le_im := Function.Periodic.norm_qParam_le_of_one_half_le_im @[deprecated (since := "2025-02-17")] alias UpperHalfPlane.abs_qParam_lt_one := UpperHalfPlane.norm_qParam_lt_one @[deprecated (since := "2025-02-17")] alias UpperHalfPlane.abs_exp_two_pi_I_lt_one := UpperHalfPlane.norm_exp_two_pi_I_lt_one
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.
Polynomial.lean
/- Copyright (c) 2023 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.MvPolynomial.Equiv /-! # Some lemmas relating polynomials and multivariable polynomials. -/ namespace MvPolynomial variable {R S σ : Type*} theorem polynomial_eval_eval₂ [CommSemiring R] [CommSemiring S] {x : S} (f : R →+* Polynomial S) (g : σ → Polynomial S) (p : MvPolynomial σ R) : Polynomial.eval x (eval₂ f g p) = eval₂ ((Polynomial.evalRingHom x).comp f) (fun s => Polynomial.eval x (g s)) p := by apply induction_on p · simp · intro p q hp hq simp [hp, hq] · intro p n hp simp [hp] theorem eval_polynomial_eval_finSuccEquiv {n : ℕ} {x : Fin n → R} [CommSemiring R] (f : MvPolynomial (Fin (n + 1)) R) (q : MvPolynomial (Fin n) R) : (eval x) (Polynomial.eval q (finSuccEquiv R n f)) = eval (Fin.cases (eval x q) x) f := by simp only [finSuccEquiv_apply, coe_eval₂Hom, polynomial_eval_eval₂, eval_eval₂] conv in RingHom.comp _ _ => refine @RingHom.ext _ _ _ _ _ (RingHom.id _) fun r => ?_ simp simp only [eval₂_id] congr funext i refine Fin.cases (by simp) (by simp) i end MvPolynomial
SimplicialObject.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.AlgebraicTopology.SimplicialCategory.Basic import Mathlib.CategoryTheory.Functor.FunctorHom /-! # The category of simplicial objects is simplicial In `CategoryTheory.Functor.FunctorHom`, it was shown that a category of functors `C ⥤ D` is enriched over a suitable category `C ⥤ Type _` of functors to types. In this file, we deduce that `SimplicialObject D` is enriched over `SSet.{v} D` (when `D : Type u` and `[Category.{v} D]`) and that `SimplicialObject D` is actually a simplicial category. In particular, the category of simplicial sets is a simplicial category. -/ universe v u namespace CategoryTheory variable {D : Type u} [Category.{v} D] namespace SimplicialObject noncomputable instance : EnrichedCategory SSet.{v} (SimplicialObject D) := inferInstanceAs (EnrichedCategory (_ ⥤ Type v) (_ ⥤ D)) noncomputable instance : SimplicialCategory (SimplicialObject D) where homEquiv := Functor.natTransEquiv.symm noncomputable instance : SimplicialCategory SSet.{v} := inferInstanceAs (SimplicialCategory (SimplicialObject (Type v))) end SimplicialObject end CategoryTheory
Basic.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Patrick Massot, Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Topology /-! # Integral over an interval In this file we define `∫ x in a..b, f x ∂μ` to be `∫ x in Ioc a b, f x ∂μ` if `a ≤ b` and `-∫ x in Ioc b a, f x ∂μ` if `b ≤ a`. ## Implementation notes ### Avoiding `if`, `min`, and `max` In order to avoid `if`s in the definition, we define `IntervalIntegrable f μ a b` as `IntegrableOn f (Ioc a b) μ ∧ IntegrableOn f (Ioc b a) μ`. For any `a`, `b` one of these intervals is empty and the other coincides with `Set.uIoc a b = Set.Ioc (min a b) (max a b)`. Similarly, we define `∫ x in a..b, f x ∂μ` to be `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ`. Again, for any `a`, `b` one of these integrals is zero, and the other gives the expected result. This way some properties can be translated from integrals over sets without dealing with the cases `a ≤ b` and `b ≤ a` separately. ### Choice of the interval We use integral over `Set.uIoc a b = Set.Ioc (min a b) (max a b)` instead of one of the other three possible intervals with the same endpoints for two reasons: * this way `∫ x in a..b, f x ∂μ + ∫ x in b..c, f x ∂μ = ∫ x in a..c, f x ∂μ` holds whenever `f` is integrable on each interval; in particular, it works even if the measure `μ` has an atom at `b`; this rules out `Set.Ioo` and `Set.Icc` intervals; * with this definition for a probability measure `μ`, the integral `∫ x in a..b, 1 ∂μ` equals the difference $F_μ(b)-F_μ(a)$, where $F_μ(a)=μ(-∞, a]$ is the [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function) of `μ`. ## Tags integral -/ noncomputable section open MeasureTheory Set Filter Function TopologicalSpace open scoped Topology Filter ENNReal Interval NNReal variable {ι 𝕜 ε ε' E F A : Type*} [NormedAddCommGroup E] [TopologicalSpace ε] [ENormedAddCommMonoid ε] [TopologicalSpace ε'] [ENormedAddCommMonoid ε'] /-! ### Integrability on an interval -/ /-- A function `f` is called *interval integrable* with respect to a measure `μ` on an unordered interval `a..b` if it is integrable on both intervals `(a, b]` and `(b, a]`. One of these intervals is always empty, so this property is equivalent to `f` being integrable on `(min a b, max a b]`. -/ def IntervalIntegrable (f : ℝ → ε) (μ : Measure ℝ) (a b : ℝ) : Prop := IntegrableOn f (Ioc a b) μ ∧ IntegrableOn f (Ioc b a) μ /-! ## Basic iff's for `IntervalIntegrable` -/ section variable [PseudoMetrizableSpace ε] {f : ℝ → ε} {a b : ℝ} {μ : Measure ℝ} /-- A function is interval integrable with respect to a given measure `μ` on `a..b` if and only if it is integrable on `uIoc a b` with respect to `μ`. This is an equivalent definition of `IntervalIntegrable`. -/ theorem intervalIntegrable_iff : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ι a b) μ := by rw [uIoc_eq_union, integrableOn_union, IntervalIntegrable] /-- If a function is interval integrable with respect to a given measure `μ` on `a..b` then it is integrable on `uIoc a b` with respect to `μ`. -/ theorem IntervalIntegrable.def' (h : IntervalIntegrable f μ a b) : IntegrableOn f (Ι a b) μ := intervalIntegrable_iff.mp h theorem IntervalIntegrable.congr {g : ℝ → ε} (hf : IntervalIntegrable f μ a b) (h : f =ᵐ[μ.restrict (Ι a b)] g) : IntervalIntegrable g μ a b := by rwa [intervalIntegrable_iff, ← integrableOn_congr_fun_ae h, ← intervalIntegrable_iff] /-- Interval integrability is invariant when functions change along discrete sets. -/ theorem IntervalIntegrable.congr_codiscreteWithin {g : ℝ → ε} [NoAtoms μ] (h : f =ᶠ[codiscreteWithin (Ι a b)] g) (hf : IntervalIntegrable f μ a b) : IntervalIntegrable g μ a b := hf.congr (ae_restrict_le_codiscreteWithin measurableSet_Ioc h) /-- Interval integrability is invariant when functions change along discrete sets. -/ theorem intervalIntegrable_congr_codiscreteWithin {g : ℝ → ε} [NoAtoms μ] (h : f =ᶠ[codiscreteWithin (Ι a b)] g) : IntervalIntegrable f μ a b ↔ IntervalIntegrable g μ a b := ⟨(IntervalIntegrable.congr_codiscreteWithin h ·), (IntervalIntegrable.congr_codiscreteWithin h.symm ·)⟩ theorem intervalIntegrable_iff_integrableOn_Ioc_of_le (hab : a ≤ b) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ioc a b) μ := by rw [intervalIntegrable_iff, uIoc_of_le hab] theorem intervalIntegrable_iff' [NoAtoms μ] (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f μ a b ↔ IntegrableOn f (uIcc a b) μ := by rw [intervalIntegrable_iff, ← Icc_min_max, uIoc, integrableOn_Icc_iff_integrableOn_Ioc h] theorem intervalIntegrable_iff_integrableOn_Icc_of_le [NoAtoms μ] (hab : a ≤ b) (ha : ‖f a‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Icc a b) μ := by rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hab, integrableOn_Icc_iff_integrableOn_Ioc ha] theorem intervalIntegrable_iff_integrableOn_Ico_of_le [NoAtoms μ] (hab : a ≤ b) (ha : ‖f a‖ₑ ≠ ∞ := by finiteness) (hb : ‖f b‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ico a b) μ := by rw [intervalIntegrable_iff_integrableOn_Icc_of_le hab ha, integrableOn_Icc_iff_integrableOn_Ico hb] theorem intervalIntegrable_iff_integrableOn_Ioo_of_le [NoAtoms μ] (hab : a ≤ b) (ha : ‖f a‖ₑ ≠ ∞ := by finiteness) (hb : ‖f b‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f μ a b ↔ IntegrableOn f (Ioo a b) μ := by rw [intervalIntegrable_iff_integrableOn_Icc_of_le hab ha, integrableOn_Icc_iff_integrableOn_Ioo ha hb] omit [PseudoMetrizableSpace ε] in /-- If a function is integrable with respect to a given measure `μ` then it is interval integrable with respect to `μ` on `uIcc a b`. -/ theorem MeasureTheory.Integrable.intervalIntegrable (hf : Integrable f μ) : IntervalIntegrable f μ a b := ⟨hf.integrableOn, hf.integrableOn⟩ omit [PseudoMetrizableSpace ε] in theorem MeasureTheory.IntegrableOn.intervalIntegrable (hf : IntegrableOn f [[a, b]] μ) : IntervalIntegrable f μ a b := ⟨MeasureTheory.IntegrableOn.mono_set hf (Ioc_subset_Icc_self.trans Icc_subset_uIcc), MeasureTheory.IntegrableOn.mono_set hf (Ioc_subset_Icc_self.trans Icc_subset_uIcc')⟩ theorem intervalIntegrable_const_iff {c : ε} (hc : ‖c‖ₑ ≠ ⊤ := by finiteness) : IntervalIntegrable (fun _ => c) μ a b ↔ c = 0 ∨ μ (Ι a b) < ∞ := by simp [intervalIntegrable_iff, integrableOn_const_iff hc] @[simp] theorem intervalIntegrable_const [IsLocallyFiniteMeasure μ] {c : E} (hc : ‖c‖ₑ ≠ ⊤ := by finiteness) : IntervalIntegrable (fun _ => c) μ a b := intervalIntegrable_const_iff hc |>.2 <| Or.inr measure_Ioc_lt_top end /-! ## Basic properties of interval integrability - interval integrability is symmetric, reflexive, transitive - monotonicity and strong measurability of the interval integral - if `f` is interval integrable, so are its absolute value and norm - arithmetic properties -/ namespace IntervalIntegrable section variable {f : ℝ → ε} {a b c d : ℝ} {μ ν : Measure ℝ} @[symm] nonrec theorem symm (h : IntervalIntegrable f μ a b) : IntervalIntegrable f μ b a := h.symm theorem symm_iff : IntervalIntegrable f μ a b ↔ IntervalIntegrable f μ b a := ⟨.symm, .symm⟩ @[refl, simp] theorem refl : IntervalIntegrable f μ a a := by constructor <;> simp variable [PseudoMetrizableSpace ε] @[trans] theorem trans {a b c : ℝ} (hab : IntervalIntegrable f μ a b) (hbc : IntervalIntegrable f μ b c) : IntervalIntegrable f μ a c := ⟨(hab.1.union hbc.1).mono_set Ioc_subset_Ioc_union_Ioc, (hbc.2.union hab.2).mono_set Ioc_subset_Ioc_union_Ioc⟩ theorem trans_iff (h : b ∈ [[a, c]]) : IntervalIntegrable f μ a c ↔ IntervalIntegrable f μ a b ∧ IntervalIntegrable f μ b c := by simp only [intervalIntegrable_iff, ← integrableOn_union, uIoc_union_uIoc h] theorem trans_iterate_Ico {a : ℕ → ℝ} {m n : ℕ} (hmn : m ≤ n) (hint : ∀ k ∈ Ico m n, IntervalIntegrable f μ (a k) (a <| k + 1)) : IntervalIntegrable f μ (a m) (a n) := by revert hint refine Nat.le_induction ?_ ?_ n hmn · simp · intro p hp IH h exact (IH fun k hk => h k (Ico_subset_Ico_right p.le_succ hk)).trans (h p (by simp [hp])) theorem trans_iterate {a : ℕ → ℝ} {n : ℕ} (hint : ∀ k < n, IntervalIntegrable f μ (a k) (a <| k + 1)) : IntervalIntegrable f μ (a 0) (a n) := trans_iterate_Ico bot_le fun k hk => hint k hk.2 theorem neg {f : ℝ → E} (h : IntervalIntegrable f μ a b) : IntervalIntegrable (-f) μ a b := ⟨h.1.neg, h.2.neg⟩ omit [PseudoMetrizableSpace ε] in theorem enorm (h : IntervalIntegrable f μ a b) : IntervalIntegrable (‖f ·‖ₑ) μ a b := ⟨h.1.enorm, h.2.enorm⟩ theorem norm {f : ℝ → E} (h : IntervalIntegrable f μ a b) : IntervalIntegrable (‖f ·‖) μ a b := ⟨h.1.norm, h.2.norm⟩ theorem intervalIntegrable_enorm_iff {μ : Measure ℝ} {a b : ℝ} (hf : AEStronglyMeasurable f (μ.restrict (Ι a b))) : IntervalIntegrable (fun t => ‖f t‖ₑ) μ a b ↔ IntervalIntegrable f μ a b := by simp_rw [intervalIntegrable_iff, IntegrableOn, integrable_enorm_iff hf] theorem intervalIntegrable_norm_iff {f : ℝ → E} {μ : Measure ℝ} {a b : ℝ} (hf : AEStronglyMeasurable f (μ.restrict (Ι a b))) : IntervalIntegrable (fun t => ‖f t‖) μ a b ↔ IntervalIntegrable f μ a b := by simp_rw [intervalIntegrable_iff, IntegrableOn, integrable_norm_iff hf] theorem abs {f : ℝ → ℝ} (h : IntervalIntegrable f μ a b) : IntervalIntegrable (fun x => |f x|) μ a b := h.norm theorem mono (hf : IntervalIntegrable f ν a b) (h1 : [[c, d]] ⊆ [[a, b]]) (h2 : μ ≤ ν) : IntervalIntegrable f μ c d := intervalIntegrable_iff.mpr <| hf.def'.mono (uIoc_subset_uIoc_of_uIcc_subset_uIcc h1) h2 theorem mono_measure (hf : IntervalIntegrable f ν a b) (h : μ ≤ ν) : IntervalIntegrable f μ a b := hf.mono Subset.rfl h theorem mono_set (hf : IntervalIntegrable f μ a b) (h : [[c, d]] ⊆ [[a, b]]) : IntervalIntegrable f μ c d := hf.mono h le_rfl theorem mono_set_ae (hf : IntervalIntegrable f μ a b) (h : Ι c d ≤ᵐ[μ] Ι a b) : IntervalIntegrable f μ c d := intervalIntegrable_iff.mpr <| hf.def'.mono_set_ae h theorem mono_set' (hf : IntervalIntegrable f μ a b) (hsub : Ι c d ⊆ Ι a b) : IntervalIntegrable f μ c d := hf.mono_set_ae <| Eventually.of_forall hsub theorem mono_fun_enorm [PseudoMetrizableSpace ε'] {g : ℝ → ε'} (hf : IntervalIntegrable f μ a b) (hgm : AEStronglyMeasurable g (μ.restrict (Ι a b))) (hle : (‖g ·‖ₑ) ≤ᵐ[μ.restrict (Ι a b)] (‖f ·‖ₑ)) : IntervalIntegrable g μ a b := intervalIntegrable_iff.2 <| hf.def'.integrable.mono_enorm hgm hle theorem mono_fun {f : ℝ → E} [NormedAddCommGroup F] {g : ℝ → F} (hf : IntervalIntegrable f μ a b) (hgm : AEStronglyMeasurable g (μ.restrict (Ι a b))) (hle : (fun x => ‖g x‖) ≤ᵐ[μ.restrict (Ι a b)] fun x => ‖f x‖) : IntervalIntegrable g μ a b := intervalIntegrable_iff.2 <| hf.def'.integrable.mono hgm hle -- XXX: the best spelling of this lemma may look slightly different (e.gl, with different domain) theorem mono_fun_enorm' {f : ℝ → ε} {g : ℝ → ℝ≥0∞} (hg : IntervalIntegrable g μ a b) (hfm : AEStronglyMeasurable f (μ.restrict (Ι a b))) (hle : (fun x => ‖f x‖ₑ) ≤ᵐ[μ.restrict (Ι a b)] g) : IntervalIntegrable f μ a b := intervalIntegrable_iff.2 <| hg.def'.integrable.mono_enorm hfm hle theorem mono_fun' {f : ℝ → E} {g : ℝ → ℝ} (hg : IntervalIntegrable g μ a b) (hfm : AEStronglyMeasurable f (μ.restrict (Ι a b))) (hle : (fun x => ‖f x‖) ≤ᵐ[μ.restrict (Ι a b)] g) : IntervalIntegrable f μ a b := intervalIntegrable_iff.2 <| hg.def'.integrable.mono' hfm hle omit [PseudoMetrizableSpace ε] in protected theorem aestronglyMeasurable (h : IntervalIntegrable f μ a b) : AEStronglyMeasurable f (μ.restrict (Ioc a b)) := h.1.aestronglyMeasurable omit [PseudoMetrizableSpace ε] in protected theorem aestronglyMeasurable' (h : IntervalIntegrable f μ a b) : AEStronglyMeasurable f (μ.restrict (Ioc b a)) := h.2.aestronglyMeasurable end variable [NormedRing A] {f g : ℝ → ε} {a b : ℝ} {μ : Measure ℝ} theorem smul {R : Type*} [NormedAddCommGroup R] [SMulZeroClass R E] [IsBoundedSMul R E] {f : ℝ → E} (h : IntervalIntegrable f μ a b) (r : R) : IntervalIntegrable (r • f) μ a b := ⟨h.1.smul r, h.2.smul r⟩ @[simp] theorem add [ContinuousAdd ε] (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) : IntervalIntegrable (fun x => f x + g x) μ a b := ⟨hf.1.add hg.1, hf.2.add hg.2⟩ @[simp] theorem sub {f g : ℝ → E} (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) : IntervalIntegrable (fun x => f x - g x) μ a b := ⟨hf.1.sub hg.1, hf.2.sub hg.2⟩ theorem sum [ContinuousAdd ε] (s : Finset ι) {f : ι → ℝ → ε} (h : ∀ i ∈ s, IntervalIntegrable (f i) μ a b) : IntervalIntegrable (∑ i ∈ s, f i) μ a b := ⟨integrable_finset_sum' s fun i hi => (h i hi).1, integrable_finset_sum' s fun i hi => (h i hi).2⟩ /-- Finsums of interval integrable functions are interval integrable. -/ @[simp] protected theorem finsum [ContinuousAdd ε] [PseudoMetrizableSpace ε] {f : ι → ℝ → ε} (h : ∀ i, IntervalIntegrable (f i) μ a b) : IntervalIntegrable (∑ᶠ i, f i) μ a b := by by_cases h₁ : f.support.Finite · simp [finsum_eq_sum _ h₁, IntervalIntegrable.sum h₁.toFinset (fun i _ ↦ h i)] · rw [finsum_of_infinite_support h₁] apply intervalIntegrable_const_iff (c := 0) (by simp) |>.2 tauto section Mul theorem mul_continuousOn {f g : ℝ → A} (hf : IntervalIntegrable f μ a b) (hg : ContinuousOn g [[a, b]]) : IntervalIntegrable (fun x => f x * g x) μ a b := by rw [intervalIntegrable_iff] at hf ⊢ exact hf.mul_continuousOn_of_subset hg measurableSet_Ioc isCompact_uIcc Ioc_subset_Icc_self theorem continuousOn_mul {f g : ℝ → A} (hf : IntervalIntegrable f μ a b) (hg : ContinuousOn g [[a, b]]) : IntervalIntegrable (fun x => g x * f x) μ a b := by rw [intervalIntegrable_iff] at hf ⊢ exact hf.continuousOn_mul_of_subset hg isCompact_uIcc measurableSet_Ioc Ioc_subset_Icc_self @[simp] theorem const_mul {f : ℝ → A} (hf : IntervalIntegrable f μ a b) (c : A) : IntervalIntegrable (fun x => c * f x) μ a b := hf.continuousOn_mul continuousOn_const @[simp] theorem mul_const {f : ℝ → A} (hf : IntervalIntegrable f μ a b) (c : A) : IntervalIntegrable (fun x => f x * c) μ a b := hf.mul_continuousOn continuousOn_const end Mul section SMul variable {f : ℝ → 𝕜} {g : ℝ → E} [NormedRing 𝕜] [Module 𝕜 E] [NormSMulClass 𝕜 E] theorem smul_continuousOn (hf : IntervalIntegrable f μ a b) (hg : ContinuousOn g [[a, b]]) : IntervalIntegrable (fun x => f x • g x) μ a b := by rw [intervalIntegrable_iff] at hf ⊢ exact hf.smul_continuousOn_of_subset hg measurableSet_Ioc isCompact_uIcc Ioc_subset_Icc_self theorem continuousOn_smul (hg : IntervalIntegrable g μ a b) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => f x • g x) μ a b := by rw [intervalIntegrable_iff] at hg ⊢ exact hg.continuousOn_smul_of_subset hf isCompact_uIcc measurableSet_Ioc Ioc_subset_Icc_self end SMul @[simp] theorem div_const {𝕜 : Type*} {f : ℝ → 𝕜} [NormedDivisionRing 𝕜] (h : IntervalIntegrable f μ a b) (c : 𝕜) : IntervalIntegrable (fun x => f x / c) μ a b := by simpa only [div_eq_mul_inv] using mul_const h c⁻¹ variable [PseudoMetrizableSpace ε] theorem comp_mul_left (hf : IntervalIntegrable f volume a b) {c : ℝ} (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) (h' : ‖f (c * min (a / c) (b / c))‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable (fun x => f (c * x)) volume (a / c) (b / c) := by rcases eq_or_ne c 0 with (hc | hc); · rw [hc]; simp rw [intervalIntegrable_iff' h] at hf rw [intervalIntegrable_iff' h'] at ⊢ have A : MeasurableEmbedding fun x => x * c⁻¹ := (Homeomorph.mulRight₀ _ (inv_ne_zero hc)).isClosedEmbedding.measurableEmbedding rw [← Real.smul_map_volume_mul_right (inv_ne_zero hc), IntegrableOn, Measure.restrict_smul, integrable_smul_measure (by simpa : ENNReal.ofReal |c⁻¹| ≠ 0) ENNReal.ofReal_ne_top, ← IntegrableOn, MeasurableEmbedding.integrableOn_map_iff A] convert hf using 1 · ext; simp only [comp_apply]; congr 1; field_simp · rw [preimage_mul_const_uIcc (inv_ne_zero hc)]; field_simp [hc] -- Note that `h'` is **not** implied by `h` if `c` is negative. -- TODO: generalise this lemma to enorms! theorem comp_mul_left_iff {f : ℝ → E} {c : ℝ} (hc : c ≠ 0) (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) (h' : ‖f (c * min (a / c) (b / c))‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable (fun x ↦ f (c * x)) volume (a / c) (b / c) ↔ IntervalIntegrable f volume a b := by exact ⟨fun h ↦ by simpa [hc] using h.comp_mul_left (c := c⁻¹) h' (by simp), (comp_mul_left · h h')⟩ theorem comp_mul_right (hf : IntervalIntegrable f volume a b) {c : ℝ} (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) (h' : ‖f (c * min (a / c) (b / c))‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable (fun x => f (x * c)) volume (a / c) (b / c) := by simpa only [mul_comm] using comp_mul_left hf h h' theorem comp_add_right (hf : IntervalIntegrable f volume a b) (c : ℝ) (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable (fun x ↦ f (x + c)) volume (a - c) (b - c) := by have h' : ‖f (min (a - c) (b - c) + c)‖ₑ ≠ ⊤ := by rw [min_sub_sub_right, sub_add, sub_self, sub_zero] exact h wlog hab : a ≤ b generalizing a b · apply IntervalIntegrable.symm (this hf.symm ?_ ?_ (le_of_not_ge hab)) · rw [min_comm]; exact h · rw [min_comm]; exact h' rw [intervalIntegrable_iff' h] at hf rw [intervalIntegrable_iff' h'] at ⊢ have A : MeasurableEmbedding fun x => x + c := (Homeomorph.addRight c).isClosedEmbedding.measurableEmbedding rw [← map_add_right_eq_self volume c] at hf convert (MeasurableEmbedding.integrableOn_map_iff A).mp hf using 1 rw [preimage_add_const_uIcc] theorem comp_add_left (hf : IntervalIntegrable f volume a b) (c : ℝ) (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable (fun x ↦ f (c + x)) volume (a - c) (b - c) := by simpa [add_comm] using IntervalIntegrable.comp_add_right hf c h theorem comp_sub_right (hf : IntervalIntegrable f volume a b) (c : ℝ) (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable (fun x ↦ f (x - c)) volume (a + c) (b + c) := by simpa only [sub_neg_eq_add] using IntervalIntegrable.comp_add_right hf (-c) h -- TODO: generalise this lemma to enorms! theorem iff_comp_neg {f : ℝ → E} (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f volume a b ↔ IntervalIntegrable (fun x ↦ f (-x)) volume (-a) (-b) := by rw [← comp_mul_left_iff (neg_ne_zero.2 one_ne_zero) h (by simp)]; simp [div_neg] -- TODO: generalise this lemma to enorms! theorem comp_sub_left {f : ℝ → E} (hf : IntervalIntegrable f volume a b) (c : ℝ) (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable (fun x ↦ f (c - x)) volume (c - a) (c - b) := by simpa only [neg_sub, ← sub_eq_add_neg] using (iff_comp_neg (by simp)).mp (hf.comp_add_left c h) -- TODO: generalise this lemma to enorms! theorem comp_sub_left_iff {f : ℝ → E} (c : ℝ) (h : ‖f (min a b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable (fun x => f (c - x)) volume (c - a) (c - b) ↔ IntervalIntegrable f volume a b := ⟨fun h ↦ by simpa using h.comp_sub_left c, (.comp_sub_left · c h)⟩ end IntervalIntegrable /-! ## Continuous functions are interval integrable -/ section variable {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] theorem ContinuousOn.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : ContinuousOn u (uIcc a b)) : IntervalIntegrable u μ a b := (ContinuousOn.integrableOn_Icc hu).intervalIntegrable theorem ContinuousOn.intervalIntegrable_of_Icc {u : ℝ → E} {a b : ℝ} (h : a ≤ b) (hu : ContinuousOn u (Icc a b)) : IntervalIntegrable u μ a b := ContinuousOn.intervalIntegrable ((uIcc_of_le h).symm ▸ hu) /-- A continuous function on `ℝ` is `IntervalIntegrable` with respect to any locally finite measure `ν` on ℝ. -/ theorem Continuous.intervalIntegrable {u : ℝ → E} (hu : Continuous u) (a b : ℝ) : IntervalIntegrable u μ a b := hu.continuousOn.intervalIntegrable end /-! ## Monotone and antitone functions are integral integrable -/ section variable {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] [ConditionallyCompleteLinearOrder E] [OrderTopology E] [SecondCountableTopology E] theorem MonotoneOn.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : MonotoneOn u (uIcc a b)) : IntervalIntegrable u μ a b := by rw [intervalIntegrable_iff] exact (hu.integrableOn_isCompact isCompact_uIcc).mono_set Ioc_subset_Icc_self theorem AntitoneOn.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : AntitoneOn u (uIcc a b)) : IntervalIntegrable u μ a b := hu.dual_right.intervalIntegrable theorem Monotone.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : Monotone u) : IntervalIntegrable u μ a b := (hu.monotoneOn _).intervalIntegrable theorem Antitone.intervalIntegrable {u : ℝ → E} {a b : ℝ} (hu : Antitone u) : IntervalIntegrable u μ a b := (hu.antitoneOn _).intervalIntegrable end /-! ## Interval integrability of functions with even or odd parity -/ section variable {f : ℝ → E} /-- An even function is interval integrable (with respect to the volume measure) on every interval of the form `0..x` if it is interval integrable (with respect to the volume measure) on every interval of the form `0..x`, for positive `x`. See `intervalIntegrable_of_even` for a stronger result. -/ lemma intervalIntegrable_of_even₀ (h₁f : ∀ x, f x = f (-x)) (h₂f : ∀ x, 0 < x → IntervalIntegrable f volume 0 x) {t : ℝ} (ht : ‖f (min 0 t)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f volume 0 t := by rcases lt_trichotomy t 0 with h | h | h · rw [IntervalIntegrable.iff_comp_neg ht] conv => arg 1; intro t; rw [← h₁f] simp [h₂f (-t) (by simp [h])] · rw [h] · exact h₂f t h /-- An even function is interval integrable (with respect to the volume measure) on every interval if it is interval integrable (with respect to the volume measure) on every interval of the form `0..x`, for positive `x`. -/ theorem intervalIntegrable_of_even (h₁f : ∀ x, f x = f (-x)) (h₂f : ∀ x, 0 < x → IntervalIntegrable f volume 0 x) {a b : ℝ} (ha : ‖f (min 0 a)‖ₑ ≠ ∞ := by finiteness) (hb : ‖f (min 0 b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f volume a b := -- Split integral and apply lemma (intervalIntegrable_of_even₀ h₁f h₂f ha).symm.trans (b := 0) (intervalIntegrable_of_even₀ h₁f h₂f hb) /-- An odd function is interval integrable (with respect to the volume measure) on every interval of the form `0..x` if it is interval integrable (with respect to the volume measure) on every interval of the form `0..x`, for positive `x`. See `intervalIntegrable_of_odd` for a stronger result. -/ lemma intervalIntegrable_of_odd₀ (h₁f : ∀ x, -f x = f (-x)) (h₂f : ∀ x, 0 < x → IntervalIntegrable f volume 0 x) {t : ℝ} (ht : ‖f (min 0 t)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f volume 0 t := by rcases lt_trichotomy t 0 with h | h | h · rw [IntervalIntegrable.iff_comp_neg] conv => arg 1; intro t; rw [← h₁f] apply IntervalIntegrable.neg simp [h₂f (-t) (by simp [h])] · rw [h] · exact h₂f t h /-- An odd function is interval integrable (with respect to the volume measure) on every interval iff it is interval integrable (with respect to the volume measure) on every interval of the form `0..x`, for positive `x`. -/ theorem intervalIntegrable_of_odd (h₁f : ∀ x, -f x = f (-x)) (h₂f : ∀ x, 0 < x → IntervalIntegrable f volume 0 x) {a b : ℝ} (ha : ‖f (min 0 a)‖ₑ ≠ ∞ := by finiteness) (hb : ‖f (min 0 b)‖ₑ ≠ ∞ := by finiteness) : IntervalIntegrable f volume a b := -- Split integral and apply lemma (intervalIntegrable_of_odd₀ h₁f h₂f ha).symm.trans (intervalIntegrable_of_odd₀ h₁f h₂f hb) end /-! ## Limits of intervals -/ /-- Let `l'` be a measurably generated filter; let `l` be a of filter such that each `s ∈ l'` eventually includes `Ioc u v` as both `u` and `v` tend to `l`. Let `μ` be a measure finite at `l'`. Suppose that `f : ℝ → E` has a finite limit at `l' ⊓ ae μ`. Then `f` is interval integrable on `u..v` provided that both `u` and `v` tend to `l`. Typeclass instances allow Lean to find `l'` based on `l` but not vice versa, so `apply Tendsto.eventually_intervalIntegrable_ae` will generate goals `Filter ℝ` and `TendstoIxxClass Ioc ?m_1 l'`. -/ theorem Filter.Tendsto.eventually_intervalIntegrable_ae {f : ℝ → E} {μ : Measure ℝ} {l l' : Filter ℝ} (hfm : StronglyMeasurableAtFilter f l' μ) [TendstoIxxClass Ioc l l'] [IsMeasurablyGenerated l'] (hμ : μ.FiniteAtFilter l') {c : E} (hf : Tendsto f (l' ⊓ ae μ) (𝓝 c)) {u v : ι → ℝ} {lt : Filter ι} (hu : Tendsto u lt l) (hv : Tendsto v lt l) : ∀ᶠ t in lt, IntervalIntegrable f μ (u t) (v t) := have := (hf.integrableAtFilter_ae hfm hμ).eventually ((hu.Ioc hv).eventually this).and <| (hv.Ioc hu).eventually this /-- Let `l'` be a measurably generated filter; let `l` be a of filter such that each `s ∈ l'` eventually includes `Ioc u v` as both `u` and `v` tend to `l`. Let `μ` be a measure finite at `l'`. Suppose that `f : ℝ → E` has a finite limit at `l`. Then `f` is interval integrable on `u..v` provided that both `u` and `v` tend to `l`. Typeclass instances allow Lean to find `l'` based on `l` but not vice versa, so `apply Tendsto.eventually_intervalIntegrable` will generate goals `Filter ℝ` and `TendstoIxxClass Ioc ?m_1 l'`. -/ theorem Filter.Tendsto.eventually_intervalIntegrable {f : ℝ → E} {μ : Measure ℝ} {l l' : Filter ℝ} (hfm : StronglyMeasurableAtFilter f l' μ) [TendstoIxxClass Ioc l l'] [IsMeasurablyGenerated l'] (hμ : μ.FiniteAtFilter l') {c : E} (hf : Tendsto f l' (𝓝 c)) {u v : ι → ℝ} {lt : Filter ι} (hu : Tendsto u lt l) (hv : Tendsto v lt l) : ∀ᶠ t in lt, IntervalIntegrable f μ (u t) (v t) := (hf.mono_left inf_le_left).eventually_intervalIntegrable_ae hfm hμ hu hv /-! ### Interval integral: definition and basic properties In this section we define `∫ x in a..b, f x ∂μ` as `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ` and prove some basic properties. -/ variable [NormedSpace ℝ E] /-- The interval integral `∫ x in a..b, f x ∂μ` is defined as `∫ x in Ioc a b, f x ∂μ - ∫ x in Ioc b a, f x ∂μ`. If `a ≤ b`, then it equals `∫ x in Ioc a b, f x ∂μ`, otherwise it equals `-∫ x in Ioc b a, f x ∂μ`. -/ def intervalIntegral (f : ℝ → E) (a b : ℝ) (μ : Measure ℝ) : E := (∫ x in Ioc a b, f x ∂μ) - ∫ x in Ioc b a, f x ∂μ @[inherit_doc intervalIntegral] notation3"∫ "(...)" in "a".."b", "r:60:(scoped f => f)" ∂"μ:70 => intervalIntegral r a b μ /-- The interval integral `∫ x in a..b, f x` is defined as `∫ x in Ioc a b, f x - ∫ x in Ioc b a, f x`. If `a ≤ b`, then it equals `∫ x in Ioc a b, f x`, otherwise it equals `-∫ x in Ioc b a, f x`. -/ notation3"∫ "(...)" in "a".."b", "r:60:(scoped f => intervalIntegral f a b volume) => r namespace intervalIntegral section Basic variable {a b : ℝ} {f g : ℝ → E} {μ : Measure ℝ} @[simp] theorem integral_zero : (∫ _ in a..b, (0 : E) ∂μ) = 0 := by simp [intervalIntegral] theorem integral_of_le (h : a ≤ b) : ∫ x in a..b, f x ∂μ = ∫ x in Ioc a b, f x ∂μ := by simp [intervalIntegral, h] @[simp] theorem integral_same : ∫ x in a..a, f x ∂μ = 0 := sub_self _ theorem integral_symm (a b) : ∫ x in b..a, f x ∂μ = -∫ x in a..b, f x ∂μ := by simp only [intervalIntegral, neg_sub] theorem integral_of_ge (h : b ≤ a) : ∫ x in a..b, f x ∂μ = -∫ x in Ioc b a, f x ∂μ := by simp only [integral_symm b, integral_of_le h] theorem intervalIntegral_eq_integral_uIoc (f : ℝ → E) (a b : ℝ) (μ : Measure ℝ) : ∫ x in a..b, f x ∂μ = (if a ≤ b then 1 else -1 : ℝ) • ∫ x in Ι a b, f x ∂μ := by split_ifs with h · simp only [integral_of_le h, uIoc_of_le h, one_smul] · simp only [integral_of_ge (not_le.1 h).le, uIoc_of_ge (not_le.1 h).le, neg_one_smul] theorem norm_intervalIntegral_eq (f : ℝ → E) (a b : ℝ) (μ : Measure ℝ) : ‖∫ x in a..b, f x ∂μ‖ = ‖∫ x in Ι a b, f x ∂μ‖ := by simp_rw [intervalIntegral_eq_integral_uIoc, norm_smul] split_ifs <;> simp only [norm_neg, norm_one, one_mul] theorem abs_intervalIntegral_eq (f : ℝ → ℝ) (a b : ℝ) (μ : Measure ℝ) : |∫ x in a..b, f x ∂μ| = |∫ x in Ι a b, f x ∂μ| := norm_intervalIntegral_eq f a b μ theorem integral_cases (f : ℝ → E) (a b) : (∫ x in a..b, f x ∂μ) ∈ ({∫ x in Ι a b, f x ∂μ, -∫ x in Ι a b, f x ∂μ} : Set E) := by rw [intervalIntegral_eq_integral_uIoc]; split_ifs <;> simp nonrec theorem integral_undef (h : ¬IntervalIntegrable f μ a b) : ∫ x in a..b, f x ∂μ = 0 := by rw [intervalIntegrable_iff] at h rw [intervalIntegral_eq_integral_uIoc, integral_undef h, smul_zero] theorem intervalIntegrable_of_integral_ne_zero {a b : ℝ} {f : ℝ → E} {μ : Measure ℝ} (h : (∫ x in a..b, f x ∂μ) ≠ 0) : IntervalIntegrable f μ a b := not_imp_comm.1 integral_undef h nonrec theorem integral_non_aestronglyMeasurable (hf : ¬AEStronglyMeasurable f (μ.restrict (Ι a b))) : ∫ x in a..b, f x ∂μ = 0 := by rw [intervalIntegral_eq_integral_uIoc, integral_non_aestronglyMeasurable hf, smul_zero] theorem integral_non_aestronglyMeasurable_of_le (h : a ≤ b) (hf : ¬AEStronglyMeasurable f (μ.restrict (Ioc a b))) : ∫ x in a..b, f x ∂μ = 0 := integral_non_aestronglyMeasurable <| by rwa [uIoc_of_le h] theorem norm_integral_min_max (f : ℝ → E) : ‖∫ x in min a b..max a b, f x ∂μ‖ = ‖∫ x in a..b, f x ∂μ‖ := by cases le_total a b <;> simp [*, integral_symm a b] theorem norm_integral_eq_norm_integral_uIoc (f : ℝ → E) : ‖∫ x in a..b, f x ∂μ‖ = ‖∫ x in Ι a b, f x ∂μ‖ := by rw [← norm_integral_min_max, integral_of_le min_le_max, uIoc] @[deprecated (since := "2025-04-19")] alias norm_integral_eq_norm_integral_Ioc := norm_integral_eq_norm_integral_uIoc theorem abs_integral_eq_abs_integral_uIoc (f : ℝ → ℝ) : |∫ x in a..b, f x ∂μ| = |∫ x in Ι a b, f x ∂μ| := norm_integral_eq_norm_integral_uIoc f theorem norm_integral_le_integral_norm_uIoc : ‖∫ x in a..b, f x ∂μ‖ ≤ ∫ x in Ι a b, ‖f x‖ ∂μ := calc ‖∫ x in a..b, f x ∂μ‖ = ‖∫ x in Ι a b, f x ∂μ‖ := norm_integral_eq_norm_integral_uIoc f _ ≤ ∫ x in Ι a b, ‖f x‖ ∂μ := norm_integral_le_integral_norm f @[deprecated (since := "2025-04-19")] alias norm_integral_le_integral_norm_Ioc := norm_integral_le_integral_norm_uIoc theorem norm_integral_le_abs_integral_norm : ‖∫ x in a..b, f x ∂μ‖ ≤ |∫ x in a..b, ‖f x‖ ∂μ| := by simp only [← Real.norm_eq_abs, norm_integral_eq_norm_integral_uIoc] exact le_trans (norm_integral_le_integral_norm _) (le_abs_self _) theorem norm_integral_le_integral_norm (h : a ≤ b) : ‖∫ x in a..b, f x ∂μ‖ ≤ ∫ x in a..b, ‖f x‖ ∂μ := norm_integral_le_integral_norm_uIoc.trans_eq <| by rw [uIoc_of_le h, integral_of_le h] theorem norm_integral_le_abs_of_norm_le {g : ℝ → ℝ} (h : ∀ᵐ t ∂μ.restrict <| Ι a b, ‖f t‖ ≤ g t) (hbound : IntervalIntegrable g μ a b) : ‖∫ t in a..b, f t ∂μ‖ ≤ |∫ t in a..b, g t ∂μ| := by rw [norm_intervalIntegral_eq, abs_intervalIntegral_eq] exact (norm_integral_le_of_norm_le hbound.def' h).trans (le_abs_self _) theorem norm_integral_le_of_norm_le {g : ℝ → ℝ} (hab : a ≤ b) (h : ∀ᵐ t ∂μ, t ∈ Set.Ioc a b → ‖f t‖ ≤ g t) (hbound : IntervalIntegrable g μ a b) : ‖∫ t in a..b, f t ∂μ‖ ≤ ∫ t in a..b, g t ∂μ := by simp only [integral_of_le hab, ← ae_restrict_iff' measurableSet_Ioc] at * exact MeasureTheory.norm_integral_le_of_norm_le hbound.1 h theorem norm_integral_le_of_norm_le_const_ae {a b C : ℝ} {f : ℝ → E} (h : ∀ᵐ x, x ∈ Ι a b → ‖f x‖ ≤ C) : ‖∫ x in a..b, f x‖ ≤ C * |b - a| := by rw [norm_integral_eq_norm_integral_uIoc] convert norm_setIntegral_le_of_norm_le_const_ae' _ h using 1 · rw [uIoc, Real.volume_real_Ioc_of_le inf_le_sup, max_sub_min_eq_abs] · simp [uIoc, Real.volume_Ioc] theorem norm_integral_le_of_norm_le_const {a b C : ℝ} {f : ℝ → E} (h : ∀ x ∈ Ι a b, ‖f x‖ ≤ C) : ‖∫ x in a..b, f x‖ ≤ C * |b - a| := norm_integral_le_of_norm_le_const_ae <| Eventually.of_forall h @[simp] nonrec theorem integral_add (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) : ∫ x in a..b, f x + g x ∂μ = (∫ x in a..b, f x ∂μ) + ∫ x in a..b, g x ∂μ := by simp only [intervalIntegral_eq_integral_uIoc, integral_add hf.def' hg.def', smul_add] nonrec theorem integral_finset_sum {ι} {s : Finset ι} {f : ι → ℝ → E} (h : ∀ i ∈ s, IntervalIntegrable (f i) μ a b) : ∫ x in a..b, ∑ i ∈ s, f i x ∂μ = ∑ i ∈ s, ∫ x in a..b, f i x ∂μ := by simp only [intervalIntegral_eq_integral_uIoc, integral_finset_sum s fun i hi => (h i hi).def', Finset.smul_sum] @[simp] nonrec theorem integral_neg : ∫ x in a..b, -f x ∂μ = -∫ x in a..b, f x ∂μ := by simp only [intervalIntegral, integral_neg]; abel @[simp] theorem integral_sub (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) : ∫ x in a..b, f x - g x ∂μ = (∫ x in a..b, f x ∂μ) - ∫ x in a..b, g x ∂μ := by simpa only [sub_eq_add_neg] using (integral_add hf hg.neg).trans (congr_arg _ integral_neg) /-- Compatibility with scalar multiplication. Note this assumes `𝕜` is a division ring in order to ensure that for `c ≠ 0`, `c • f` is integrable iff `f` is. For scalar multiplication by more general rings assuming integrability, see `IntervalIntegrable.integral_smul`. -/ @[simp] nonrec theorem integral_smul [NormedDivisionRing 𝕜] [Module 𝕜 E] [NormSMulClass 𝕜 E] [SMulCommClass ℝ 𝕜 E] (r : 𝕜) (f : ℝ → E) : ∫ x in a..b, r • f x ∂μ = r • ∫ x in a..b, f x ∂μ := by simp only [intervalIntegral, integral_smul, smul_sub] theorem _root_.IntervalIntegrable.integral_smul {R : Type*} [NormedRing R] [Module R E] [IsBoundedSMul R E] [SMulCommClass ℝ R E] {f : ℝ → E} (r : R) (hf : IntervalIntegrable f μ a b) : ∫ x in a..b, r • f x ∂μ = r • ∫ x in a..b, f x ∂μ := by simp only [intervalIntegral, smul_sub, hf.1.integral_smul, hf.2.integral_smul] @[simp] nonrec theorem integral_smul_const [CompleteSpace E] {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] (f : ℝ → 𝕜) (c : E) : ∫ x in a..b, f x • c ∂μ = (∫ x in a..b, f x ∂μ) • c := by simp only [intervalIntegral_eq_integral_uIoc, integral_smul_const, smul_assoc] @[simp] theorem integral_const_mul [NormedDivisionRing 𝕜] [NormedAlgebra ℝ 𝕜] (r : 𝕜) (f : ℝ → 𝕜) : ∫ x in a..b, r * f x ∂μ = r * ∫ x in a..b, f x ∂μ := integral_smul r f @[simp] theorem integral_mul_const {𝕜 : Type*} [RCLike 𝕜] (r : 𝕜) (f : ℝ → 𝕜) : ∫ x in a..b, f x * r ∂μ = (∫ x in a..b, f x ∂μ) * r := by simpa only [mul_comm r] using integral_const_mul r f @[simp] theorem integral_div {𝕜 : Type*} [RCLike 𝕜] (r : 𝕜) (f : ℝ → 𝕜) : ∫ x in a..b, f x / r ∂μ = (∫ x in a..b, f x ∂μ) / r := by simpa only [div_eq_mul_inv] using integral_mul_const r⁻¹ f theorem integral_const' [CompleteSpace E] (c : E) : ∫ _ in a..b, c ∂μ = (μ.real (Ioc a b) - μ.real (Ioc b a)) • c := by simp only [measureReal_def, intervalIntegral, setIntegral_const, sub_smul] @[simp] theorem integral_const [CompleteSpace E] (c : E) : ∫ _ in a..b, c = (b - a) • c := by simp only [integral_const', Real.volume_Ioc, ENNReal.toReal_ofReal', ← neg_sub b, max_zero_sub_eq_self, measureReal_def] nonrec theorem integral_smul_measure (c : ℝ≥0∞) : ∫ x in a..b, f x ∂c • μ = c.toReal • ∫ x in a..b, f x ∂μ := by simp only [intervalIntegral, Measure.restrict_smul, integral_smul_measure, smul_sub] end Basic -- TODO: add `Complex.ofReal` version of `_root_.integral_ofReal` nonrec theorem _root_.RCLike.intervalIntegral_ofReal {𝕜 : Type*} [RCLike 𝕜] {a b : ℝ} {μ : Measure ℝ} {f : ℝ → ℝ} : (∫ x in a..b, (f x : 𝕜) ∂μ) = ↑(∫ x in a..b, f x ∂μ) := by simp only [intervalIntegral, integral_ofReal, RCLike.ofReal_sub] nonrec theorem integral_ofReal {a b : ℝ} {μ : Measure ℝ} {f : ℝ → ℝ} : (∫ x in a..b, (f x : ℂ) ∂μ) = ↑(∫ x in a..b, f x ∂μ) := RCLike.intervalIntegral_ofReal section ContinuousLinearMap variable {a b : ℝ} {μ : Measure ℝ} {f : ℝ → E} variable [RCLike 𝕜] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] open ContinuousLinearMap theorem _root_.ContinuousLinearMap.intervalIntegral_apply {a b : ℝ} {φ : ℝ → F →L[𝕜] E} (hφ : IntervalIntegrable φ μ a b) (v : F) : (∫ x in a..b, φ x ∂μ) v = ∫ x in a..b, φ x v ∂μ := by simp_rw [intervalIntegral_eq_integral_uIoc, ← integral_apply hφ.def' v, coe_smul', Pi.smul_apply] variable [NormedSpace ℝ F] [CompleteSpace F] theorem _root_.ContinuousLinearMap.intervalIntegral_comp_comm [CompleteSpace E] (L : E →L[𝕜] F) (hf : IntervalIntegrable f μ a b) : (∫ x in a..b, L (f x) ∂μ) = L (∫ x in a..b, f x ∂μ) := by simp_rw [intervalIntegral, L.integral_comp_comm hf.1, L.integral_comp_comm hf.2, L.map_sub] end ContinuousLinearMap /-! ## Basic arithmetic Includes addition, scalar multiplication and affine transformations. -/ section Comp variable {a b c d : ℝ} (f : ℝ → E) @[simp] theorem integral_comp_mul_right (hc : c ≠ 0) : (∫ x in a..b, f (x * c)) = c⁻¹ • ∫ x in a * c..b * c, f x := by have A : MeasurableEmbedding fun x => x * c := (Homeomorph.mulRight₀ c hc).isClosedEmbedding.measurableEmbedding conv_rhs => rw [← Real.smul_map_volume_mul_right hc] simp_rw [integral_smul_measure, intervalIntegral, A.setIntegral_map, ENNReal.toReal_ofReal (abs_nonneg c)] rcases hc.lt_or_gt with h | h · simp [h, mul_div_cancel_right₀, hc, abs_of_neg, Measure.restrict_congr_set (α := ℝ) (μ := volume) Ico_ae_eq_Ioc] · simp [h, mul_div_cancel_right₀, hc, abs_of_pos] @[simp] theorem smul_integral_comp_mul_right (c) : (c • ∫ x in a..b, f (x * c)) = ∫ x in a * c..b * c, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_mul_right] @[simp] theorem integral_comp_mul_left (hc : c ≠ 0) : (∫ x in a..b, f (c * x)) = c⁻¹ • ∫ x in c * a..c * b, f x := by simpa only [mul_comm c] using integral_comp_mul_right f hc @[simp] theorem smul_integral_comp_mul_left (c) : (c • ∫ x in a..b, f (c * x)) = ∫ x in c * a..c * b, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_mul_left] @[simp] theorem integral_comp_div (hc : c ≠ 0) : (∫ x in a..b, f (x / c)) = c • ∫ x in a / c..b / c, f x := by simpa only [inv_inv] using integral_comp_mul_right f (inv_ne_zero hc) @[simp] theorem inv_smul_integral_comp_div (c) : (c⁻¹ • ∫ x in a..b, f (x / c)) = ∫ x in a / c..b / c, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_div] @[simp] theorem integral_comp_add_right (d) : (∫ x in a..b, f (x + d)) = ∫ x in a + d..b + d, f x := have A : MeasurableEmbedding fun x => x + d := (Homeomorph.addRight d).isClosedEmbedding.measurableEmbedding calc (∫ x in a..b, f (x + d)) = ∫ x in a + d..b + d, f x ∂Measure.map (fun x => x + d) volume := by simp [intervalIntegral, A.setIntegral_map] _ = ∫ x in a + d..b + d, f x := by rw [map_add_right_eq_self] @[simp] nonrec theorem integral_comp_add_left (d) : (∫ x in a..b, f (d + x)) = ∫ x in d + a..d + b, f x := by simpa only [add_comm d] using integral_comp_add_right f d @[simp] theorem integral_comp_mul_add (hc : c ≠ 0) (d) : (∫ x in a..b, f (c * x + d)) = c⁻¹ • ∫ x in c * a + d..c * b + d, f x := by rw [← integral_comp_add_right, ← integral_comp_mul_left _ hc] @[simp] theorem smul_integral_comp_mul_add (c d) : (c • ∫ x in a..b, f (c * x + d)) = ∫ x in c * a + d..c * b + d, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_mul_add] @[simp] theorem integral_comp_add_mul (hc : c ≠ 0) (d) : (∫ x in a..b, f (d + c * x)) = c⁻¹ • ∫ x in d + c * a..d + c * b, f x := by rw [← integral_comp_add_left, ← integral_comp_mul_left _ hc] @[simp] theorem smul_integral_comp_add_mul (c d) : (c • ∫ x in a..b, f (d + c * x)) = ∫ x in d + c * a..d + c * b, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_add_mul] @[simp] theorem integral_comp_div_add (hc : c ≠ 0) (d) : (∫ x in a..b, f (x / c + d)) = c • ∫ x in a / c + d..b / c + d, f x := by simpa only [div_eq_inv_mul, inv_inv] using integral_comp_mul_add f (inv_ne_zero hc) d @[simp] theorem inv_smul_integral_comp_div_add (c d) : (c⁻¹ • ∫ x in a..b, f (x / c + d)) = ∫ x in a / c + d..b / c + d, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_div_add] @[simp] theorem integral_comp_add_div (hc : c ≠ 0) (d) : (∫ x in a..b, f (d + x / c)) = c • ∫ x in d + a / c..d + b / c, f x := by simpa only [div_eq_inv_mul, inv_inv] using integral_comp_add_mul f (inv_ne_zero hc) d @[simp] theorem inv_smul_integral_comp_add_div (c d) : (c⁻¹ • ∫ x in a..b, f (d + x / c)) = ∫ x in d + a / c..d + b / c, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_add_div] @[simp] theorem integral_comp_mul_sub (hc : c ≠ 0) (d) : (∫ x in a..b, f (c * x - d)) = c⁻¹ • ∫ x in c * a - d..c * b - d, f x := by simpa only [sub_eq_add_neg] using integral_comp_mul_add f hc (-d) @[simp] theorem smul_integral_comp_mul_sub (c d) : (c • ∫ x in a..b, f (c * x - d)) = ∫ x in c * a - d..c * b - d, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_mul_sub] @[simp] theorem integral_comp_sub_mul (hc : c ≠ 0) (d) : (∫ x in a..b, f (d - c * x)) = c⁻¹ • ∫ x in d - c * b..d - c * a, f x := by simp only [sub_eq_add_neg, neg_mul_eq_neg_mul] rw [integral_comp_add_mul f (neg_ne_zero.mpr hc) d, integral_symm] simp only [inv_neg, smul_neg, neg_neg, neg_smul] @[simp] theorem smul_integral_comp_sub_mul (c d) : (c • ∫ x in a..b, f (d - c * x)) = ∫ x in d - c * b..d - c * a, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_sub_mul] @[simp] theorem integral_comp_div_sub (hc : c ≠ 0) (d) : (∫ x in a..b, f (x / c - d)) = c • ∫ x in a / c - d..b / c - d, f x := by simpa only [div_eq_inv_mul, inv_inv] using integral_comp_mul_sub f (inv_ne_zero hc) d @[simp] theorem inv_smul_integral_comp_div_sub (c d) : (c⁻¹ • ∫ x in a..b, f (x / c - d)) = ∫ x in a / c - d..b / c - d, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_div_sub] @[simp] theorem integral_comp_sub_div (hc : c ≠ 0) (d) : (∫ x in a..b, f (d - x / c)) = c • ∫ x in d - b / c..d - a / c, f x := by simpa only [div_eq_inv_mul, inv_inv] using integral_comp_sub_mul f (inv_ne_zero hc) d @[simp] theorem inv_smul_integral_comp_sub_div (c d) : (c⁻¹ • ∫ x in a..b, f (d - x / c)) = ∫ x in d - b / c..d - a / c, f x := by by_cases hc : c = 0 <;> simp [hc, integral_comp_sub_div] @[simp] theorem integral_comp_sub_right (d) : (∫ x in a..b, f (x - d)) = ∫ x in a - d..b - d, f x := by simpa only [sub_eq_add_neg] using integral_comp_add_right f (-d) @[simp] theorem integral_comp_sub_left (d) : (∫ x in a..b, f (d - x)) = ∫ x in d - b..d - a, f x := by simpa only [one_mul, one_smul, inv_one] using integral_comp_sub_mul f one_ne_zero d @[simp] theorem integral_comp_neg : (∫ x in a..b, f (-x)) = ∫ x in -b..-a, f x := by simpa only [zero_sub] using integral_comp_sub_left f 0 end Comp /-! ### Integral is an additive function of the interval In this section we prove that `∫ x in a..b, f x ∂μ + ∫ x in b..c, f x ∂μ = ∫ x in a..c, f x ∂μ` as well as a few other identities trivially equivalent to this one. We also prove that `∫ x in a..b, f x ∂μ = ∫ x, f x ∂μ` provided that `support f ⊆ Ioc a b`. -/ section OrderClosedTopology variable {a b c d : ℝ} {f g : ℝ → E} {μ : Measure ℝ} /-- If two functions are equal in the relevant interval, their interval integrals are also equal. -/ theorem integral_congr {a b : ℝ} (h : EqOn f g [[a, b]]) : ∫ x in a..b, f x ∂μ = ∫ x in a..b, g x ∂μ := by rcases le_total a b with hab | hab <;> simpa [hab, integral_of_le, integral_of_ge] using setIntegral_congr_fun measurableSet_Ioc (h.mono Ioc_subset_Icc_self) theorem integral_add_adjacent_intervals_cancel (hab : IntervalIntegrable f μ a b) (hbc : IntervalIntegrable f μ b c) : (((∫ x in a..b, f x ∂μ) + ∫ x in b..c, f x ∂μ) + ∫ x in c..a, f x ∂μ) = 0 := by have hac := hab.trans hbc simp only [intervalIntegral, sub_add_sub_comm, sub_eq_zero] iterate 4 rw [← setIntegral_union] · suffices Ioc a b ∪ Ioc b c ∪ Ioc c a = Ioc b a ∪ Ioc c b ∪ Ioc a c by rw [this] rw [Ioc_union_Ioc_union_Ioc_cycle, union_right_comm, Ioc_union_Ioc_union_Ioc_cycle, min_left_comm, max_left_comm] all_goals simp [*, hab.1, hab.2, hbc.1, hbc.2, hac.1, hac.2] theorem integral_add_adjacent_intervals (hab : IntervalIntegrable f μ a b) (hbc : IntervalIntegrable f μ b c) : ((∫ x in a..b, f x ∂μ) + ∫ x in b..c, f x ∂μ) = ∫ x in a..c, f x ∂μ := by rw [← add_neg_eq_zero, ← integral_symm, integral_add_adjacent_intervals_cancel hab hbc] theorem sum_integral_adjacent_intervals_Ico {a : ℕ → ℝ} {m n : ℕ} (hmn : m ≤ n) (hint : ∀ k ∈ Ico m n, IntervalIntegrable f μ (a k) (a <| k + 1)) : ∑ k ∈ Finset.Ico m n, ∫ x in a k..a <| k + 1, f x ∂μ = ∫ x in a m..a n, f x ∂μ := by revert hint refine Nat.le_induction ?_ ?_ n hmn · simp · intro p hmp IH h rw [Finset.sum_Ico_succ_top hmp, IH, integral_add_adjacent_intervals] · refine IntervalIntegrable.trans_iterate_Ico hmp fun k hk => h k ?_ exact (Ico_subset_Ico le_rfl (Nat.le_succ _)) hk · apply h simp [hmp] · intro k hk exact h _ (Ico_subset_Ico_right p.le_succ hk) theorem sum_integral_adjacent_intervals {a : ℕ → ℝ} {n : ℕ} (hint : ∀ k < n, IntervalIntegrable f μ (a k) (a <| k + 1)) : ∑ k ∈ Finset.range n, ∫ x in a k..a <| k + 1, f x ∂μ = ∫ x in (a 0)..(a n), f x ∂μ := by rw [← Nat.Ico_zero_eq_range] exact sum_integral_adjacent_intervals_Ico (zero_le n) fun k hk => hint k hk.2 theorem integral_interval_sub_left (hab : IntervalIntegrable f μ a b) (hac : IntervalIntegrable f μ a c) : ((∫ x in a..b, f x ∂μ) - ∫ x in a..c, f x ∂μ) = ∫ x in c..b, f x ∂μ := sub_eq_of_eq_add' <| Eq.symm <| integral_add_adjacent_intervals hac (hac.symm.trans hab) theorem integral_interval_add_interval_comm (hab : IntervalIntegrable f μ a b) (hcd : IntervalIntegrable f μ c d) (hac : IntervalIntegrable f μ a c) : ((∫ x in a..b, f x ∂μ) + ∫ x in c..d, f x ∂μ) = (∫ x in a..d, f x ∂μ) + ∫ x in c..b, f x ∂μ := by rw [← integral_add_adjacent_intervals hac hcd, add_assoc, add_left_comm, integral_add_adjacent_intervals hac (hac.symm.trans hab), add_comm] theorem integral_interval_sub_interval_comm (hab : IntervalIntegrable f μ a b) (hcd : IntervalIntegrable f μ c d) (hac : IntervalIntegrable f μ a c) : ((∫ x in a..b, f x ∂μ) - ∫ x in c..d, f x ∂μ) = (∫ x in a..c, f x ∂μ) - ∫ x in b..d, f x ∂μ := by simp only [sub_eq_add_neg, ← integral_symm, integral_interval_add_interval_comm hab hcd.symm (hac.trans hcd)] theorem integral_interval_sub_interval_comm' (hab : IntervalIntegrable f μ a b) (hcd : IntervalIntegrable f μ c d) (hac : IntervalIntegrable f μ a c) : ((∫ x in a..b, f x ∂μ) - ∫ x in c..d, f x ∂μ) = (∫ x in d..b, f x ∂μ) - ∫ x in c..a, f x ∂μ := by rw [integral_interval_sub_interval_comm hab hcd hac, integral_symm b d, integral_symm a c, sub_neg_eq_add, sub_eq_neg_add] theorem integral_Iic_sub_Iic (ha : IntegrableOn f (Iic a) μ) (hb : IntegrableOn f (Iic b) μ) : ((∫ x in Iic b, f x ∂μ) - ∫ x in Iic a, f x ∂μ) = ∫ x in a..b, f x ∂μ := by wlog hab : a ≤ b generalizing a b · rw [integral_symm, ← this hb ha (le_of_not_ge hab), neg_sub] rw [sub_eq_iff_eq_add', integral_of_le hab, ← setIntegral_union (Iic_disjoint_Ioc le_rfl), Iic_union_Ioc_eq_Iic hab] exacts [measurableSet_Ioc, ha, hb.mono_set fun _ => And.right] theorem integral_Iic_add_Ioi (h_left : IntegrableOn f (Iic b) μ) (h_right : IntegrableOn f (Ioi b) μ) : (∫ x in Iic b, f x ∂μ) + (∫ x in Ioi b, f x ∂μ) = ∫ (x : ℝ), f x ∂μ := by convert (setIntegral_union (Iic_disjoint_Ioi <| Eq.le rfl) measurableSet_Ioi h_left h_right).symm rw [Iic_union_Ioi, Measure.restrict_univ] theorem integral_Iio_add_Ici (h_left : IntegrableOn f (Iio b) μ) (h_right : IntegrableOn f (Ici b) μ) : (∫ x in Iio b, f x ∂μ) + (∫ x in Ici b, f x ∂μ) = ∫ (x : ℝ), f x ∂μ := by convert (setIntegral_union (Iio_disjoint_Ici <| Eq.le rfl) measurableSet_Ici h_left h_right).symm rw [Iio_union_Ici, Measure.restrict_univ] /-- If `μ` is a finite measure then `∫ x in a..b, c ∂μ = (μ (Iic b) - μ (Iic a)) • c`. -/ theorem integral_const_of_cdf [CompleteSpace E] [IsFiniteMeasure μ] (c : E) : ∫ _ in a..b, c ∂μ = (μ.real (Iic b) - μ.real (Iic a)) • c := by simp only [sub_smul, ← setIntegral_const] refine (integral_Iic_sub_Iic ?_ ?_).symm <;> simp theorem integral_eq_integral_of_support_subset {a b} (h : support f ⊆ Ioc a b) : ∫ x in a..b, f x ∂μ = ∫ x, f x ∂μ := by rcases le_total a b with hab | hab · rw [integral_of_le hab, ← integral_indicator measurableSet_Ioc, indicator_eq_self.2 h] · rw [Ioc_eq_empty hab.not_gt, subset_empty_iff, support_eq_empty_iff] at h simp [h] theorem integral_congr_ae' (h : ∀ᵐ x ∂μ, x ∈ Ioc a b → f x = g x) (h' : ∀ᵐ x ∂μ, x ∈ Ioc b a → f x = g x) : ∫ x in a..b, f x ∂μ = ∫ x in a..b, g x ∂μ := by simp only [intervalIntegral, setIntegral_congr_ae measurableSet_Ioc h, setIntegral_congr_ae measurableSet_Ioc h'] theorem integral_congr_ae (h : ∀ᵐ x ∂μ, x ∈ Ι a b → f x = g x) : ∫ x in a..b, f x ∂μ = ∫ x in a..b, g x ∂μ := integral_congr_ae' (ae_uIoc_iff.mp h).1 (ae_uIoc_iff.mp h).2 /-- Integrals are equal for functions that agree almost everywhere for the restricted measure. -/ theorem integral_congr_ae_restrict {a b : ℝ} {f g : ℝ → E} {μ : Measure ℝ} (h : f =ᵐ[μ.restrict (Ι a b)] g) : ∫ x in a..b, f x ∂μ = ∫ x in a..b, g x ∂μ := integral_congr_ae (ae_imp_of_ae_restrict h) /-- Integrals are invariant when functions change along discrete sets. -/ theorem integral_congr_codiscreteWithin {a b : ℝ} {f₁ f₂ : ℝ → ℝ} (hf : f₁ =ᶠ[codiscreteWithin (Ι a b)] f₂) : ∫ (x : ℝ) in a..b, f₁ x = ∫ (x : ℝ) in a..b, f₂ x := integral_congr_ae_restrict (ae_restrict_le_codiscreteWithin measurableSet_uIoc hf) theorem integral_zero_ae (h : ∀ᵐ x ∂μ, x ∈ Ι a b → f x = 0) : ∫ x in a..b, f x ∂μ = 0 := calc ∫ x in a..b, f x ∂μ = ∫ _ in a..b, 0 ∂μ := integral_congr_ae h _ = 0 := integral_zero nonrec theorem integral_indicator {a₁ a₂ a₃ : ℝ} (h : a₂ ∈ Icc a₁ a₃) : ∫ x in a₁..a₃, indicator {x | x ≤ a₂} f x ∂μ = ∫ x in a₁..a₂, f x ∂μ := by have : {x | x ≤ a₂} ∩ Ioc a₁ a₃ = Ioc a₁ a₂ := Iic_inter_Ioc_of_le h.2 rw [integral_of_le h.1, integral_of_le (h.1.trans h.2), integral_indicator, Measure.restrict_restrict, this] · exact measurableSet_Iic all_goals apply measurableSet_Iic end OrderClosedTopology section variable {f g : ℝ → ℝ} {a b : ℝ} {μ : Measure ℝ} theorem integral_eq_zero_iff_of_le_of_nonneg_ae (hab : a ≤ b) (hf : 0 ≤ᵐ[μ.restrict (Ioc a b)] f) (hfi : IntervalIntegrable f μ a b) : ∫ x in a..b, f x ∂μ = 0 ↔ f =ᵐ[μ.restrict (Ioc a b)] 0 := by rw [integral_of_le hab, integral_eq_zero_iff_of_nonneg_ae hf hfi.1] theorem integral_eq_zero_iff_of_nonneg_ae (hf : 0 ≤ᵐ[μ.restrict (Ioc a b ∪ Ioc b a)] f) (hfi : IntervalIntegrable f μ a b) : ∫ x in a..b, f x ∂μ = 0 ↔ f =ᵐ[μ.restrict (Ioc a b ∪ Ioc b a)] 0 := by rcases le_total a b with hab | hab <;> simp only [Ioc_eq_empty hab.not_gt, empty_union, union_empty] at hf ⊢ · exact integral_eq_zero_iff_of_le_of_nonneg_ae hab hf hfi · rw [integral_symm, neg_eq_zero, integral_eq_zero_iff_of_le_of_nonneg_ae hab hf hfi.symm] /-- If `f` is nonnegative and integrable on the unordered interval `Set.uIoc a b`, then its integral over `a..b` is positive if and only if `a < b` and the measure of `Function.support f ∩ Set.Ioc a b` is positive. -/ theorem integral_pos_iff_support_of_nonneg_ae' (hf : 0 ≤ᵐ[μ.restrict (Ι a b)] f) (hfi : IntervalIntegrable f μ a b) : (0 < ∫ x in a..b, f x ∂μ) ↔ a < b ∧ 0 < μ (support f ∩ Ioc a b) := by rcases lt_or_ge a b with hab | hba · rw [uIoc_of_le hab.le] at hf simp only [hab, true_and, integral_of_le hab.le, setIntegral_pos_iff_support_of_nonneg_ae hf hfi.1] · suffices (∫ x in a..b, f x ∂μ) ≤ 0 by simp only [this.not_gt, hba.not_gt, false_and] rw [integral_of_ge hba, neg_nonpos] rw [uIoc_comm, uIoc_of_le hba] at hf exact integral_nonneg_of_ae hf /-- If `f` is nonnegative a.e.-everywhere and it is integrable on the unordered interval `Set.uIoc a b`, then its integral over `a..b` is positive if and only if `a < b` and the measure of `Function.support f ∩ Set.Ioc a b` is positive. -/ theorem integral_pos_iff_support_of_nonneg_ae (hf : 0 ≤ᵐ[μ] f) (hfi : IntervalIntegrable f μ a b) : (0 < ∫ x in a..b, f x ∂μ) ↔ a < b ∧ 0 < μ (support f ∩ Ioc a b) := integral_pos_iff_support_of_nonneg_ae' (ae_mono Measure.restrict_le_self hf) hfi /-- If `f : ℝ → ℝ` is integrable on `(a, b]` for real numbers `a < b`, and positive on the interior of the interval, then its integral over `a..b` is strictly positive. -/ theorem intervalIntegral_pos_of_pos_on {f : ℝ → ℝ} {a b : ℝ} (hfi : IntervalIntegrable f volume a b) (hpos : ∀ x : ℝ, x ∈ Ioo a b → 0 < f x) (hab : a < b) : 0 < ∫ x : ℝ in a..b, f x := by have hsupp : Ioo a b ⊆ support f ∩ Ioc a b := fun x hx => ⟨mem_support.mpr (hpos x hx).ne', Ioo_subset_Ioc_self hx⟩ have h₀ : 0 ≤ᵐ[volume.restrict (uIoc a b)] f := by rw [EventuallyLE, uIoc_of_le hab.le] refine ae_restrict_of_ae_eq_of_ae_restrict Ioo_ae_eq_Ioc ?_ rw [ae_restrict_iff' measurableSet_Ioo] filter_upwards with x hx using (hpos x hx).le rw [integral_pos_iff_support_of_nonneg_ae' h₀ hfi] exact ⟨hab, ((Measure.measure_Ioo_pos _).mpr hab).trans_le (measure_mono hsupp)⟩ /-- If `f : ℝ → ℝ` is strictly positive everywhere, and integrable on `(a, b]` for real numbers `a < b`, then its integral over `a..b` is strictly positive. (See `intervalIntegral_pos_of_pos_on` for a version only assuming positivity of `f` on `(a, b)` rather than everywhere.) -/ theorem intervalIntegral_pos_of_pos {f : ℝ → ℝ} {a b : ℝ} (hfi : IntervalIntegrable f MeasureSpace.volume a b) (hpos : ∀ x, 0 < f x) (hab : a < b) : 0 < ∫ x in a..b, f x := intervalIntegral_pos_of_pos_on hfi (fun x _ => hpos x) hab /-- If `f` and `g` are two functions that are interval integrable on `a..b`, `a ≤ b`, `f x ≤ g x` for a.e. `x ∈ Set.Ioc a b`, and `f x < g x` on a subset of `Set.Ioc a b` of nonzero measure, then `∫ x in a..b, f x ∂μ < ∫ x in a..b, g x ∂μ`. -/ theorem integral_lt_integral_of_ae_le_of_measure_setOf_lt_ne_zero (hab : a ≤ b) (hfi : IntervalIntegrable f μ a b) (hgi : IntervalIntegrable g μ a b) (hle : f ≤ᵐ[μ.restrict (Ioc a b)] g) (hlt : μ.restrict (Ioc a b) {x | f x < g x} ≠ 0) : (∫ x in a..b, f x ∂μ) < ∫ x in a..b, g x ∂μ := by rw [← sub_pos, ← integral_sub hgi hfi, integral_of_le hab, MeasureTheory.integral_pos_iff_support_of_nonneg_ae] · refine pos_iff_ne_zero.2 (mt (measure_mono_null ?_) hlt) exact fun x hx => (sub_pos.2 hx.out).ne' exacts [hle.mono fun x => sub_nonneg.2, hgi.1.sub hfi.1] /-- If `f` and `g` are continuous on `[a, b]`, `a < b`, `f x ≤ g x` on this interval, and `f c < g c` at some point `c ∈ [a, b]`, then `∫ x in a..b, f x < ∫ x in a..b, g x`. -/ theorem integral_lt_integral_of_continuousOn_of_le_of_exists_lt {f g : ℝ → ℝ} {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hgc : ContinuousOn g (Icc a b)) (hle : ∀ x ∈ Ioc a b, f x ≤ g x) (hlt : ∃ c ∈ Icc a b, f c < g c) : (∫ x in a..b, f x) < ∫ x in a..b, g x := by apply integral_lt_integral_of_ae_le_of_measure_setOf_lt_ne_zero hab.le (hfc.intervalIntegrable_of_Icc hab.le) (hgc.intervalIntegrable_of_Icc hab.le) · simpa only [measurableSet_Ioc, ae_restrict_eq] using (ae_restrict_mem measurableSet_Ioc).mono hle contrapose! hlt have h_eq : f =ᵐ[volume.restrict (Ioc a b)] g := by simp only [← not_le, ← ae_iff] at hlt exact EventuallyLE.antisymm ((ae_restrict_iff' measurableSet_Ioc).2 <| Eventually.of_forall hle) hlt rw [Measure.restrict_congr_set Ioc_ae_eq_Icc] at h_eq exact fun c hc ↦ (Measure.eqOn_Icc_of_ae_eq volume hab.ne h_eq hfc hgc hc).ge theorem integral_nonneg_of_ae_restrict (hab : a ≤ b) (hf : 0 ≤ᵐ[μ.restrict (Icc a b)] f) : 0 ≤ ∫ u in a..b, f u ∂μ := by let H := ae_restrict_of_ae_restrict_of_subset Ioc_subset_Icc_self hf simpa only [integral_of_le hab] using setIntegral_nonneg_of_ae_restrict H theorem integral_nonneg_of_ae (hab : a ≤ b) (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ u in a..b, f u ∂μ := integral_nonneg_of_ae_restrict hab <| ae_restrict_of_ae hf theorem integral_nonneg_of_forall (hab : a ≤ b) (hf : ∀ u, 0 ≤ f u) : 0 ≤ ∫ u in a..b, f u ∂μ := integral_nonneg_of_ae hab <| Eventually.of_forall hf theorem integral_nonneg (hab : a ≤ b) (hf : ∀ u, u ∈ Icc a b → 0 ≤ f u) : 0 ≤ ∫ u in a..b, f u ∂μ := integral_nonneg_of_ae_restrict hab <| (ae_restrict_iff' measurableSet_Icc).mpr <| ae_of_all μ hf theorem abs_integral_le_integral_abs (hab : a ≤ b) : |∫ x in a..b, f x ∂μ| ≤ ∫ x in a..b, |f x| ∂μ := by simpa only [← Real.norm_eq_abs] using norm_integral_le_integral_norm hab lemma integral_pos (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hle : ∀ x ∈ Ioc a b, 0 ≤ f x) (hlt : ∃ c ∈ Icc a b, 0 < f c) : 0 < ∫ x in a..b, f x := (integral_lt_integral_of_continuousOn_of_le_of_exists_lt hab continuousOn_const hfc hle hlt).trans_eq' (by simp) section Mono theorem integral_mono_interval {c d} (hca : c ≤ a) (hab : a ≤ b) (hbd : b ≤ d) (hf : 0 ≤ᵐ[μ.restrict (Ioc c d)] f) (hfi : IntervalIntegrable f μ c d) : (∫ x in a..b, f x ∂μ) ≤ ∫ x in c..d, f x ∂μ := by rw [integral_of_le hab, integral_of_le (hca.trans (hab.trans hbd))] exact setIntegral_mono_set hfi.1 hf (Ioc_subset_Ioc hca hbd).eventuallyLE theorem abs_integral_mono_interval {c d} (h : Ι a b ⊆ Ι c d) (hf : 0 ≤ᵐ[μ.restrict (Ι c d)] f) (hfi : IntervalIntegrable f μ c d) : |∫ x in a..b, f x ∂μ| ≤ |∫ x in c..d, f x ∂μ| := have hf' : 0 ≤ᵐ[μ.restrict (Ι a b)] f := ae_mono (Measure.restrict_mono h le_rfl) hf calc |∫ x in a..b, f x ∂μ| = |∫ x in Ι a b, f x ∂μ| := abs_integral_eq_abs_integral_uIoc f _ = ∫ x in Ι a b, f x ∂μ := abs_of_nonneg (MeasureTheory.integral_nonneg_of_ae hf') _ ≤ ∫ x in Ι c d, f x ∂μ := setIntegral_mono_set hfi.def' hf h.eventuallyLE _ ≤ |∫ x in Ι c d, f x ∂μ| := le_abs_self _ _ = |∫ x in c..d, f x ∂μ| := (abs_integral_eq_abs_integral_uIoc f).symm variable (hab : a ≤ b) (hf : IntervalIntegrable f μ a b) (hg : IntervalIntegrable g μ a b) include hab hf hg theorem integral_mono_ae_restrict (h : f ≤ᵐ[μ.restrict (Icc a b)] g) : (∫ u in a..b, f u ∂μ) ≤ ∫ u in a..b, g u ∂μ := by let H := h.filter_mono <| ae_mono <| Measure.restrict_mono Ioc_subset_Icc_self <| le_refl μ simpa only [integral_of_le hab] using setIntegral_mono_ae_restrict hf.1 hg.1 H theorem integral_mono_ae (h : f ≤ᵐ[μ] g) : (∫ u in a..b, f u ∂μ) ≤ ∫ u in a..b, g u ∂μ := by simpa only [integral_of_le hab] using setIntegral_mono_ae hf.1 hg.1 h theorem integral_mono_on (h : ∀ x ∈ Icc a b, f x ≤ g x) : (∫ u in a..b, f u ∂μ) ≤ ∫ u in a..b, g u ∂μ := by let H x hx := h x <| Ioc_subset_Icc_self hx simpa only [integral_of_le hab] using setIntegral_mono_on hf.1 hg.1 measurableSet_Ioc H theorem integral_mono_on_of_le_Ioo [NoAtoms μ] (h : ∀ x ∈ Ioo a b, f x ≤ g x) : (∫ u in a..b, f u ∂μ) ≤ ∫ u in a..b, g u ∂μ := by simp only [integral_of_le hab, integral_Ioc_eq_integral_Ioo] apply setIntegral_mono_on · apply hf.1.mono Ioo_subset_Ioc_self le_rfl · apply hg.1.mono Ioo_subset_Ioc_self le_rfl · exact measurableSet_Ioo · exact h theorem integral_mono (h : f ≤ g) : (∫ u in a..b, f u ∂μ) ≤ ∫ u in a..b, g u ∂μ := integral_mono_ae hab hf hg <| ae_of_all _ h end Mono end section HasSum variable {μ : Measure ℝ} {f : ℝ → E} theorem _root_.MeasureTheory.Integrable.hasSum_intervalIntegral (hfi : Integrable f μ) (y : ℝ) : HasSum (fun n : ℤ => ∫ x in y + n..y + n + 1, f x ∂μ) (∫ x, f x ∂μ) := by simp_rw [integral_of_le (le_add_of_nonneg_right zero_le_one)] rw [← setIntegral_univ, ← iUnion_Ioc_add_intCast y] exact hasSum_integral_iUnion (fun i => measurableSet_Ioc) (pairwise_disjoint_Ioc_add_intCast y) hfi.integrableOn theorem _root_.MeasureTheory.Integrable.hasSum_intervalIntegral_comp_add_int (hfi : Integrable f) : HasSum (fun n : ℤ => ∫ x in (0 : ℝ)..(1 : ℝ), f (x + n)) (∫ x, f x) := by simpa only [integral_comp_add_right, zero_add, add_comm (1 : ℝ)] using hfi.hasSum_intervalIntegral 0 end HasSum end intervalIntegral
Synonym.lean
/- Copyright (c) 2024 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.RingTheory.Finiteness.Defs import Mathlib.Topology.Bornology.Constructions import Mathlib.Topology.UniformSpace.Equiv import Mathlib.Topology.Algebra.Module.Equiv import Mathlib.Topology.Algebra.IsUniformGroup.Basic /-! # Type synonym for types with a `CStarModule` structure It is often the case that we want to construct a `CStarModule` instance on a type that is already endowed with a norm, but this norm is not the one associated to its `CStarModule` structure. For this reason, we create a type synonym `WithCStarModule` which is endowed with the requisite `CStarModule` instance. We also introduce the scoped notation `C⋆ᵐᵒᵈ` for this type synonym. The common use cases are, when `A` is a C⋆-algebra: + `E × F` where `E` and `F` are `CStarModule`s over `A` + `Π i, E i` where `E i` is a `CStarModule` over `A` and `i : ι` with `ι` a `Fintype` In this way, the set up is very similar to the `WithLp` type synonym, although there is no way to reuse `WithLp` because the norms *do not* coincide in general. The `WithCStarModule` synonym is of vital importance, especially because the `CStarModule` class marks `A` as an `outParam`. Indeed, we want to infer `A` from the type of `E`, but, as with modules, a type `E` can be a `CStarModule` over different C⋆-algebras. For example, note that if `A` is a C⋆-algebra, then so is `A × A`, and therefore we may consider both `A` and `A × A` as `CStarModule`s over themselves, respectively. However, we may *also* consider `A × A` as a `CStarModule` over `A`. However, by utilizing the type synonym, these actually correspond to *different types*, namely: + `A` as a `CStarModule` over `A` corresponds to `A` + `A × A` as a `CStarModule` over `A × A` corresponds to `A × A` + `A × A` as a `CStarModule` over `A` corresponds to `C⋆ᵐᵒᵈ (A × A)` ## Main definitions * `WithCStarModule A E`: a copy of `E` to be equipped with a `CStarModule A` structure. * `WithCStarModule.equiv A E`: the canonical equivalence between `WithCStarModule A E` and `E`. * `WithCStarModule.linearEquiv ℂ A E`: the canonical `ℂ`-module isomorphism between `WithCStarModule A E` and `E`. ## Implementation notes The pattern here is the same one as is used by `Lex` for order structures; it avoids having a separate synonym for each type, and allows all the structure-copying code to be shared. -/ set_option linter.unusedVariables false in /-- A type synonym for endowing a given type with a `CStarModule` structure. This has the scoped notation `C⋆ᵐᵒᵈ`. -/ @[nolint unusedArguments] def WithCStarModule (A E : Type*) := E namespace WithCStarModule @[inherit_doc] scoped notation "C⋆ᵐᵒᵈ(" A ", " E ")" => WithCStarModule A E section Basic variable (R R' A E : Type*) /-- The canonical equivalence between `C⋆ᵐᵒᵈ(A, E)` and `E`. This should always be used to convert back and forth between the representations. -/ def equiv : WithCStarModule A E ≃ E := Equiv.refl _ instance instNontrivial [Nontrivial E] : Nontrivial C⋆ᵐᵒᵈ(A, E) := ‹Nontrivial E› instance instInhabited [Inhabited E] : Inhabited C⋆ᵐᵒᵈ(A, E) := ‹Inhabited E› instance instNonempty [Nonempty E] : Nonempty C⋆ᵐᵒᵈ(A, E) := ‹Nonempty E› instance instUnique [Unique E] : Unique C⋆ᵐᵒᵈ(A, E) := ‹Unique E› /-! ## `C⋆ᵐᵒᵈ(A, E)` inherits various module-adjacent structures from `E`. -/ instance instZero [Zero E] : Zero C⋆ᵐᵒᵈ(A, E) := ‹Zero E› instance instAdd [Add E] : Add C⋆ᵐᵒᵈ(A, E) := ‹Add E› instance instSub [Sub E] : Sub C⋆ᵐᵒᵈ(A, E) := ‹Sub E› instance instNeg [Neg E] : Neg C⋆ᵐᵒᵈ(A, E) := ‹Neg E› instance instAddMonoid [AddMonoid E] : AddMonoid C⋆ᵐᵒᵈ(A, E) := ‹AddMonoid E› instance instSubNegMonoid [SubNegMonoid E] : SubNegMonoid C⋆ᵐᵒᵈ(A, E) := ‹SubNegMonoid E› instance instSubNegZeroMonoid [SubNegZeroMonoid E] : SubNegZeroMonoid C⋆ᵐᵒᵈ(A, E) := ‹SubNegZeroMonoid E› instance instAddCommGroup [AddCommGroup E] : AddCommGroup C⋆ᵐᵒᵈ(A, E) := ‹AddCommGroup E› instance instSMul {R : Type*} [SMul R E] : SMul R C⋆ᵐᵒᵈ(A, E) := ‹SMul R E› instance instModule {R : Type*} [Semiring R] [AddCommGroup E] [Module R E] : Module R C⋆ᵐᵒᵈ(A, E) := ‹Module R E› instance instIsScalarTower [SMul R R'] [SMul R E] [SMul R' E] [IsScalarTower R R' E] : IsScalarTower R R' C⋆ᵐᵒᵈ(A, E) := ‹IsScalarTower R R' E› instance instSMulCommClass [SMul R E] [SMul R' E] [SMulCommClass R R' E] : SMulCommClass R R' C⋆ᵐᵒᵈ(A, E) := ‹SMulCommClass R R' E› section Equiv variable {R A E} variable [SMul R E] (c : R) (x y : C⋆ᵐᵒᵈ(A, E)) (x' y' : E) /-! `WithCStarModule.equiv` preserves the module structure. -/ section AddCommGroup variable [AddCommGroup E] @[simp] theorem equiv_zero : equiv A E 0 = 0 := rfl @[simp] theorem equiv_symm_zero : (equiv A E).symm 0 = 0 := rfl @[simp] theorem equiv_add : equiv A E (x + y) = equiv A E x + equiv A E y := rfl @[simp] theorem equiv_symm_add : (equiv A E).symm (x' + y') = (equiv A E).symm x' + (equiv A E).symm y' := rfl @[simp] theorem equiv_sub : equiv A E (x - y) = equiv A E x - equiv A E y := rfl @[simp] theorem equiv_symm_sub : (equiv A E).symm (x' - y') = (equiv A E).symm x' - (equiv A E).symm y' := rfl @[simp] theorem equiv_neg : equiv A E (-x) = -equiv A E x := rfl @[simp] theorem equiv_symm_neg : (equiv A E).symm (-x') = -(equiv A E).symm x' := rfl end AddCommGroup @[simp] theorem equiv_smul : equiv A E (c • x) = c • equiv A E x := rfl @[simp] theorem equiv_symm_smul : (equiv A E).symm (c • x') = c • (equiv A E).symm x' := rfl end Equiv /-- `WithCStarModule.equiv` as an additive equivalence. -/ def addEquiv [AddCommGroup E] : C⋆ᵐᵒᵈ(A, E) ≃+ E := { AddEquiv.refl _ with toFun := equiv _ _ invFun := (equiv _ _).symm } /-- `WithCStarModule.equiv` as a linear equivalence. -/ @[simps -fullyApplied] def linearEquiv [Semiring R] [AddCommGroup E] [Module R E] : C⋆ᵐᵒᵈ(A, E) ≃ₗ[R] E := { LinearEquiv.refl _ _ with toFun := equiv _ _ invFun := (equiv _ _).symm } lemma map_top_submodule {R : Type*} [Semiring R] [AddCommGroup E] [Module R E] : (⊤ : Submodule R E).map (linearEquiv R A E).symm = ⊤ := by ext x refine ⟨fun _ => trivial, fun _ => ?_⟩ rw [Submodule.mem_map] exact ⟨linearEquiv R A E x, by simp⟩ instance instModuleFinite [Semiring R] [AddCommGroup E] [Module R E] [Module.Finite R E] : Module.Finite R C⋆ᵐᵒᵈ(A, E) := ‹Module.Finite R E› /-! ## `C⋆ᵐᵒᵈ(A, E)` inherits the uniformity and bornology from `E`. -/ variable {A E} instance [u : UniformSpace E] : UniformSpace C⋆ᵐᵒᵈ(A, E) := u.comap <| equiv A E instance [Bornology E] : Bornology C⋆ᵐᵒᵈ(A, E) := Bornology.induced <| equiv A E /-- `WithCStarModule.equiv` as a uniform equivalence between `C⋆ᵐᵒᵈ(A, E)` and `E`. -/ def uniformEquiv [UniformSpace E] : C⋆ᵐᵒᵈ(A, E) ≃ᵤ E := equiv A E |>.toUniformEquivOfIsUniformInducing ⟨rfl⟩ /-- `WithCStarModule.equiv` as a continuous linear equivalence between `C⋆ᵐᵒᵈ E` and `E`. -/ @[simps! apply symm_apply] def equivL [Semiring R] [AddCommGroup E] [UniformSpace E] [Module R E] : C⋆ᵐᵒᵈ(A, E) ≃L[R] E := { linearEquiv R A E with continuous_toFun := UniformEquiv.continuous uniformEquiv continuous_invFun := UniformEquiv.continuous uniformEquiv.symm } instance [UniformSpace E] [CompleteSpace E] : CompleteSpace C⋆ᵐᵒᵈ(A, E) := uniformEquiv.completeSpace_iff.mpr inferInstance instance [AddCommGroup E] [UniformSpace E] [ContinuousAdd E] : ContinuousAdd C⋆ᵐᵒᵈ(A, E) := ContinuousAdd.induced (addEquiv A E) instance [AddCommGroup E] [UniformSpace E] [IsUniformAddGroup E] : IsUniformAddGroup C⋆ᵐᵒᵈ(A, E) := IsUniformAddGroup.comap (addEquiv A E) instance [Semiring R] [TopologicalSpace R] [AddCommGroup E] [UniformSpace E] [Module R E] [ContinuousSMul R E] : ContinuousSMul R C⋆ᵐᵒᵈ(A, E) := ContinuousSMul.induced (linearEquiv R A E) end Basic /-! ## Prod Register simplification lemmas for the applications of `WithCStarModule (E × F)` elements, as the usual lemmas for `Prod` will not trigger. -/ section Prod variable {R A E F : Type*} variable [SMul R E] [SMul R F] variable (x y : C⋆ᵐᵒᵈ(A, E × F)) (c : R) section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] @[simp] theorem zero_fst : (0 : C⋆ᵐᵒᵈ(A, E × F)).fst = 0 := rfl @[simp] theorem zero_snd : (0 : C⋆ᵐᵒᵈ(A, E × F)).snd = 0 := rfl @[simp] theorem add_fst : (x + y).fst = x.fst + y.fst := rfl @[simp] theorem add_snd : (x + y).snd = x.snd + y.snd := rfl @[simp] theorem sub_fst : (x - y).fst = x.fst - y.fst := rfl @[simp] theorem sub_snd : (x - y).snd = x.snd - y.snd := rfl @[simp] theorem neg_fst : (-x).fst = -x.fst := rfl @[simp] theorem neg_snd : (-x).snd = -x.snd := rfl end AddCommGroup @[simp] theorem smul_fst : (c • x).fst = c • x.fst := rfl @[simp] theorem smul_snd : (c • x).snd = c • x.snd := rfl /-! Note that the unapplied versions of these lemmas are deliberately omitted, as they break the use of the type synonym. -/ @[simp] theorem equiv_fst (x : C⋆ᵐᵒᵈ(A, E × F)) : (equiv A (E × F) x).fst = x.fst := rfl @[simp] theorem equiv_snd (x : C⋆ᵐᵒᵈ(A, E × F)) : (equiv A (E × F) x).snd = x.snd := rfl @[simp] theorem equiv_symm_fst (x : E × F) : ((equiv A (E × F)).symm x).fst = x.fst := rfl @[simp] theorem equiv_symm_snd (x : E × F) : ((equiv A (E × F)).symm x).snd = x.snd := rfl end Prod /-! ## Pi Register simplification lemmas for the applications of `WithCStarModule (Π i, E i)` elements, as the usual lemmas for `Pi` will not trigger. We also provide a `CoeFun` instance for `WithCStarModule (Π i, E i)`. -/ section Pi /- The following should not be a `FunLike` instance because then the coercion `⇑` would get unfolded to `FunLike.coe` instead of `WithCStarModule.equiv`. -/ instance {A ι : Type*} (E : ι → Type*) : CoeFun (C⋆ᵐᵒᵈ(A, Π i, E i)) (fun _ ↦ Π i, E i) where coe := equiv _ _ @[ext] protected theorem ext {A ι : Type*} {E : ι → Type*} {x y : C⋆ᵐᵒᵈ(A, Π i, E i)} (h : ∀ i, x i = y i) : x = y := funext h variable {R A ι : Type*} {E : ι → Type*} variable [∀ i, SMul R (E i)] variable (c : R) (x y : C⋆ᵐᵒᵈ(A, Π i, E i)) (i : ι) section AddCommGroup variable [∀ i, AddCommGroup (E i)] @[simp] theorem zero_apply : (0 : C⋆ᵐᵒᵈ(A, Π i, E i)) i = 0 := rfl @[simp] theorem add_apply : (x + y) i = x i + y i := rfl @[simp] theorem sub_apply : (x - y) i = x i - y i := rfl @[simp] theorem neg_apply : (-x) i = -x i := rfl end AddCommGroup @[simp] theorem smul_apply : (c • x) i = c • x i := rfl /-! Note that the unapplied versions of these lemmas are deliberately omitted, as they break the use of the type synonym. -/ @[simp] theorem equiv_pi_apply (i : ι) : equiv _ _ x i = x i := rfl @[simp] theorem equiv_symm_pi_apply (x : ∀ i, E i) (i : ι) : (equiv A _).symm x i = x i := rfl end Pi end WithCStarModule
Units.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.Normed.Ring.Units import Mathlib.Algebra.Algebra.Spectrum.Basic import Mathlib.Topology.ContinuousMap.Algebra /-! # Units of continuous functions This file concerns itself with `C(X, M)ˣ` and `C(X, Mˣ)` when `X` is a topological space and `M` has some monoid structure compatible with its topology. -/ variable {X M R 𝕜 : Type*} [TopologicalSpace X] namespace ContinuousMap section Monoid variable [Monoid M] [TopologicalSpace M] [ContinuousMul M] /-- Equivalence between continuous maps into the units of a monoid with continuous multiplication and the units of the monoid of continuous maps. -/ -- `simps` generates some lemmas here with LHS not in simp normal form, -- so we write them out manually below. @[to_additive (attr := simps apply_val_apply symm_apply_apply_val) /-- Equivalence between continuous maps into the additive units of an additive monoid with continuous addition and the additive units of the additive monoid of continuous maps. -/] def unitsLift : C(X, Mˣ) ≃ C(X, M)ˣ where toFun f := { val := ⟨fun x => f x, Units.continuous_val.comp f.continuous⟩ inv := ⟨fun x => ↑(f x)⁻¹, Units.continuous_val.comp (continuous_inv.comp f.continuous)⟩ val_inv := ext fun _ => Units.mul_inv _ inv_val := ext fun _ => Units.inv_mul _ } invFun f := { toFun := fun x => ⟨(f : C(X, M)) x, (↑f⁻¹ : C(X, M)) x, ContinuousMap.congr_fun f.mul_inv x, ContinuousMap.congr_fun f.inv_mul x⟩ continuous_toFun := continuous_induced_rng.2 <| (f : C(X, M)).continuous.prodMk <| MulOpposite.continuous_op.comp (↑f⁻¹ : C(X, M)).continuous } @[to_additive (attr := simp)] lemma unitsLift_apply_inv_apply (f : C(X, Mˣ)) (x : X) : (↑(ContinuousMap.unitsLift f)⁻¹ : C(X, M)) x = (f x)⁻¹ := rfl @[to_additive (attr := simp)] lemma unitsLift_symm_apply_apply_inv' (f : C(X, M)ˣ) (x : X) : (ContinuousMap.unitsLift.symm f x)⁻¹ = (↑f⁻¹ : C(X, M)) x := by rfl end Monoid section NormedRing variable [NormedRing R] [CompleteSpace R] theorem continuous_isUnit_unit {f : C(X, R)} (h : ∀ x, IsUnit (f x)) : Continuous fun x => (h x).unit := by refine continuous_induced_rng.2 (Continuous.prodMk f.continuous (MulOpposite.continuous_op.comp (continuous_iff_continuousAt.mpr fun x => ?_))) have := NormedRing.inverse_continuousAt (h x).unit simp only simp only [← Ring.inverse_unit, IsUnit.unit_spec] at this ⊢ exact this.comp (f.continuousAt x) /-- Construct a continuous map into the group of units of a normed ring from a function into the normed ring and a proof that every element of the range is a unit. -/ @[simps] noncomputable def unitsOfForallIsUnit {f : C(X, R)} (h : ∀ x, IsUnit (f x)) : C(X, Rˣ) where toFun x := (h x).unit continuous_toFun := continuous_isUnit_unit h instance canLift : CanLift C(X, R) C(X, Rˣ) (fun f => ⟨fun x => f x, Units.continuous_val.comp f.continuous⟩) fun f => ∀ x, IsUnit (f x) where prf f h := ⟨unitsOfForallIsUnit h, by ext; rfl⟩ theorem isUnit_iff_forall_isUnit (f : C(X, R)) : IsUnit f ↔ ∀ x, IsUnit (f x) := Iff.intro (fun h => fun x => ⟨unitsLift.symm h.unit x, rfl⟩) fun h => ⟨ContinuousMap.unitsLift (unitsOfForallIsUnit h), by ext; rfl⟩ end NormedRing section NormedField variable [NormedField 𝕜] [NormedDivisionRing R] [Algebra 𝕜 R] [CompleteSpace R] theorem isUnit_iff_forall_ne_zero (f : C(X, R)) : IsUnit f ↔ ∀ x, f x ≠ 0 := by simp_rw [f.isUnit_iff_forall_isUnit, isUnit_iff_ne_zero] theorem spectrum_eq_preimage_range (f : C(X, R)) : spectrum 𝕜 f = algebraMap _ _ ⁻¹' Set.range f := by ext x simp only [spectrum.mem_iff, isUnit_iff_forall_ne_zero, not_forall, sub_apply, Classical.not_not, Set.mem_range, sub_eq_zero, @eq_comm _ (x • 1 : R) _, Set.mem_preimage, Algebra.algebraMap_eq_smul_one, smul_apply, one_apply] theorem spectrum_eq_range [CompleteSpace 𝕜] (f : C(X, 𝕜)) : spectrum 𝕜 f = Set.range f := by rw [spectrum_eq_preimage_range, Algebra.algebraMap_self] exact Set.preimage_id end NormedField end ContinuousMap
countalg.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype bigop ssralg. (*****************************************************************************) (* The algebraic part of the algebraic hierarchy for countable types *) (* *) (* This file clones part of ssralg hierarchy for countable types; it does *) (* not cover the left module / algebra interfaces, providing only *) (* countNmodType == countable nmodType interface *) (* countZmodType == countable zmodType interface *) (* countPzSemiRingType == countable pzSemiRingType interface *) (* countNzSemiRingType == countable nzSemiRingType interface *) (* countPzRingType == countable pzRingType interface *) (* countNzRingType == countable nzRingType interface *) (* countComPzSemiRingType == countable comPzSemiRingType interface *) (* countComNzSemiRingType == countable comNzSemiRingType interface *) (* countComPzRingType == countable comPzRingType interface *) (* countComNzRingType == countable comNzRingType interface *) (* countUnitRingType == countable unitRingType interface *) (* countComUnitRingType == countable comUnitRingType interface *) (* countIdomainType == countable idomainType interface *) (* countFieldType == countable fieldType interface *) (* countDecFieldType == countable decFieldType interface *) (* countClosedFieldType == countable closedFieldType interface *) (* *) (* This file provides constructions for both simple extension and algebraic *) (* closure of countable fields. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory CodeSeq. Module CountRing. Import GRing.Theory. #[short(type="countNmodType")] HB.structure Definition Nmodule := {M of GRing.Nmodule M & Countable M}. #[short(type="countZmodType")] HB.structure Definition Zmodule := {M of GRing.Zmodule M & Countable M}. #[short(type="countPzSemiRingType")] HB.structure Definition PzSemiRing := {R of GRing.PzSemiRing R & Countable R}. #[short(type="countNzSemiRingType")] HB.structure Definition NzSemiRing := {R of GRing.NzSemiRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing instead.")] Notation SemiRing R := (NzSemiRing R) (only parsing). Module SemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.sort instead.")] Notation sort := (NzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.on instead.")] Notation on R := (NzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzSemiRing.copy instead.")] Notation copy T U := (NzSemiRing.copy T U) (only parsing). End SemiRing. #[short(type="countPzRingType")] HB.structure Definition PzRing := {R of GRing.PzRing R & Countable R}. #[short(type="countNzRingType")] HB.structure Definition NzRing := {R of GRing.NzRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing instead.")] Notation Ring R := (NzRing R) (only parsing). Module Ring. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.sort instead.")] Notation sort := (NzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.on instead.")] Notation on R := (NzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.NzRing.copy instead.")] Notation copy T U := (NzRing.copy T U) (only parsing). End Ring. #[short(type="countComPzSemiRingType")] HB.structure Definition ComPzSemiRing := {R of GRing.ComPzSemiRing R & Countable R}. #[short(type="countComNzSemiRingType")] HB.structure Definition ComNzSemiRing := {R of GRing.ComNzSemiRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing instead.")] Notation ComSemiRing R := (ComNzSemiRing R) (only parsing). Module ComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.sort instead.")] Notation sort := (ComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.on instead.")] Notation on R := (ComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzSemiRing.copy instead.")] Notation copy T U := (ComNzSemiRing.copy T U) (only parsing). End ComSemiRing. #[short(type="countComPzRingType")] HB.structure Definition ComPzRing := {R of GRing.ComPzRing R & Countable R}. #[short(type="countComNzRingType")] HB.structure Definition ComNzRing := {R of GRing.ComNzRing R & Countable R}. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing instead.")] Notation ComRing R := (ComNzRing R) (only parsing). Module ComRing. #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.sort instead.")] Notation sort := (ComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.on instead.")] Notation on R := (ComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use CountRing.ComNzRing.copy instead.")] Notation copy T U := (ComNzRing.copy T U) (only parsing). End ComRing. #[short(type="countUnitRingType")] HB.structure Definition UnitRing := {R of GRing.UnitRing R & Countable R}. #[short(type="countComUnitRingType")] HB.structure Definition ComUnitRing := {R of GRing.ComUnitRing R & Countable R}. #[short(type="countIdomainType")] HB.structure Definition IntegralDomain := {R of GRing.IntegralDomain R & Countable R}. #[short(type="countFieldType")] HB.structure Definition Field := {R of GRing.Field R & Countable R}. #[short(type="countDecFieldType")] HB.structure Definition DecidableField := {R of GRing.DecidableField R & Countable R}. #[short(type="countClosedFieldType")] HB.structure Definition ClosedField := {R of GRing.ClosedField R & Countable R}. Module ReguralExports. HB.instance Definition _ (R : countType) := Countable.on R^o. HB.instance Definition _ (R : countNmodType) := Nmodule.on R^o. HB.instance Definition _ (R : countZmodType) := Zmodule.on R^o. HB.instance Definition _ (R : countPzSemiRingType) := PzSemiRing.on R^o. HB.instance Definition _ (R : countNzSemiRingType) := NzSemiRing.on R^o. HB.instance Definition _ (R : countPzRingType) := PzRing.on R^o. HB.instance Definition _ (R : countNzRingType) := NzRing.on R^o. HB.instance Definition _ (R : countComPzSemiRingType) := ComPzSemiRing.on R^o. HB.instance Definition _ (R : countComNzSemiRingType) := ComNzSemiRing.on R^o. HB.instance Definition _ (R : countComPzRingType) := ComPzRing.on R^o. HB.instance Definition _ (R : countComNzRingType) := ComNzRing.on R^o. HB.instance Definition _ (R : countUnitRingType) := UnitRing.on R^o. HB.instance Definition _ (R : countComUnitRingType) := ComUnitRing.on R^o. HB.instance Definition _ (R : countIdomainType) := IntegralDomain.on R^o. HB.instance Definition _ (R : countFieldType) := Field.on R^o. HB.instance Definition _ (R : countDecFieldType) := DecidableField.on R^o. HB.instance Definition _ (R : countClosedFieldType) := ClosedField.on R^o. End ReguralExports. HB.export ReguralExports. End CountRing. Import CountRing. HB.reexport. #[deprecated(since="mathcomp 2.4.0", note="Use countNzSemiRingType instead.")] Notation countSemiRingType := (countNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countNzRingType instead.")] Notation countRingType := (countNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countComNzSemiRingType instead.")] Notation countComSemiRingType := (countComNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use countComNzRingType instead.")] Notation countComRingType := (countComNzRingType) (only parsing).
JapaneseBracket.lean
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Analysis.SpecialFunctions.Integrability.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.MeasureTheory.Integral.Layercake /-! # Japanese Bracket In this file, we show that Japanese bracket $(1 + \|x\|^2)^{1/2}$ can be estimated from above and below by $1 + \|x\|$. The functions $(1 + \|x\|^2)^{-r/2}$ and $(1 + |x|)^{-r}$ are integrable provided that `r` is larger than the dimension. ## Main statements * `integrable_one_add_norm`: the function $(1 + |x|)^{-r}$ is integrable * `integrable_jap` the Japanese bracket is integrable -/ noncomputable section open scoped NNReal Filter Topology ENNReal open Asymptotics Filter Set Real MeasureTheory Module variable {E : Type*} [NormedAddCommGroup E] theorem sqrt_one_add_norm_sq_le (x : E) : √((1 : ℝ) + ‖x‖ ^ 2) ≤ 1 + ‖x‖ := by rw [sqrt_le_left (by positivity)] simp [add_sq] theorem one_add_norm_le_sqrt_two_mul_sqrt (x : E) : (1 : ℝ) + ‖x‖ ≤ √2 * √(1 + ‖x‖ ^ 2) := by rw [← sqrt_mul zero_le_two] have := sq_nonneg (‖x‖ - 1) apply le_sqrt_of_sq_le linarith theorem rpow_neg_one_add_norm_sq_le {r : ℝ} (x : E) (hr : 0 < r) : ((1 : ℝ) + ‖x‖ ^ 2) ^ (-r / 2) ≤ (2 : ℝ) ^ (r / 2) * (1 + ‖x‖) ^ (-r) := calc ((1 : ℝ) + ‖x‖ ^ 2) ^ (-r / 2) = (2 : ℝ) ^ (r / 2) * ((√2 * √((1 : ℝ) + ‖x‖ ^ 2)) ^ r)⁻¹ := by rw [rpow_div_two_eq_sqrt, rpow_div_two_eq_sqrt, mul_rpow, mul_inv, rpow_neg, mul_inv_cancel_left₀] <;> positivity _ ≤ (2 : ℝ) ^ (r / 2) * ((1 + ‖x‖) ^ r)⁻¹ := by gcongr apply one_add_norm_le_sqrt_two_mul_sqrt _ = (2 : ℝ) ^ (r / 2) * (1 + ‖x‖) ^ (-r) := by rw [rpow_neg]; positivity theorem le_rpow_one_add_norm_iff_norm_le {r t : ℝ} (hr : 0 < r) (ht : 0 < t) (x : E) : t ≤ (1 + ‖x‖) ^ (-r) ↔ ‖x‖ ≤ t ^ (-r⁻¹) - 1 := by rw [le_sub_iff_add_le', neg_inv] exact (Real.le_rpow_inv_iff_of_neg (by positivity) ht (neg_lt_zero.mpr hr)).symm variable (E) theorem closedBall_rpow_sub_one_eq_empty_aux {r t : ℝ} (hr : 0 < r) (ht : 1 < t) : Metric.closedBall (0 : E) (t ^ (-r⁻¹) - 1) = ∅ := by rw [Metric.closedBall_eq_empty, sub_neg] exact Real.rpow_lt_one_of_one_lt_of_neg ht (by simp only [hr, Right.neg_neg_iff, inv_pos]) variable [NormedSpace ℝ E] [FiniteDimensional ℝ E] variable {E} theorem finite_integral_rpow_sub_one_pow_aux {r : ℝ} (n : ℕ) (hnr : (n : ℝ) < r) : (∫⁻ x : ℝ in Ioc 0 1, ENNReal.ofReal ((x ^ (-r⁻¹) - 1) ^ n)) < ∞ := by have hr : 0 < r := lt_of_le_of_lt n.cast_nonneg hnr have h_int x (hx : x ∈ Ioc (0 : ℝ) 1) := by calc ENNReal.ofReal ((x ^ (-r⁻¹) - 1) ^ n) ≤ .ofReal ((x ^ (-r⁻¹) - 0) ^ n) := by gcongr · rw [sub_nonneg] exact Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx.1 hx.2 (by simpa using hr.le) · norm_num _ = .ofReal (x ^ (-(r⁻¹ * n))) := by simp [rpow_mul hx.1.le, ← neg_mul] refine lt_of_le_of_lt (setLIntegral_mono' measurableSet_Ioc h_int) ?_ refine IntegrableOn.setLIntegral_lt_top ?_ rw [← intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] apply intervalIntegral.intervalIntegrable_rpow' rwa [neg_lt_neg_iff, inv_mul_lt_iff₀' hr, one_mul] variable [MeasurableSpace E] [BorelSpace E] {μ : Measure E} [μ.IsAddHaarMeasure] theorem finite_integral_one_add_norm {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : (∫⁻ x : E, ENNReal.ofReal ((1 + ‖x‖) ^ (-r)) ∂μ) < ∞ := by have hr : 0 < r := lt_of_le_of_lt (finrank ℝ E).cast_nonneg hnr -- We start by applying the layer cake formula have h_meas : Measurable fun ω : E => (1 + ‖ω‖) ^ (-r) := by fun_prop have h_pos : ∀ x : E, 0 ≤ (1 + ‖x‖) ^ (-r) := fun x ↦ by positivity rw [lintegral_eq_lintegral_meas_le μ (Eventually.of_forall h_pos) h_meas.aemeasurable] have h_int : ∀ t, 0 < t → μ {a : E | t ≤ (1 + ‖a‖) ^ (-r)} = μ (Metric.closedBall (0 : E) (t ^ (-r⁻¹) - 1)) := fun t ht ↦ by congr 1 ext x simp only [mem_setOf_eq, mem_closedBall_zero_iff] exact le_rpow_one_add_norm_iff_norm_le hr (mem_Ioi.mp ht) x rw [setLIntegral_congr_fun measurableSet_Ioi h_int] set f := fun t : ℝ ↦ μ (Metric.closedBall (0 : E) (t ^ (-r⁻¹) - 1)) set mB := μ (Metric.ball (0 : E) 1) -- the next two inequalities are in fact equalities but we don't need that calc ∫⁻ t in Ioi 0, f t ≤ ∫⁻ t in Ioc 0 1 ∪ Ioi 1, f t := lintegral_mono_set Ioi_subset_Ioc_union_Ioi _ ≤ (∫⁻ t in Ioc 0 1, f t) + ∫⁻ t in Ioi 1, f t := lintegral_union_le _ _ _ _ < ∞ := ENNReal.add_lt_top.2 ⟨?_, ?_⟩ · -- We use estimates from auxiliary lemmas to deal with integral from `0` to `1` have h_int' : ∀ t ∈ Ioc (0 : ℝ) 1, f t = ENNReal.ofReal ((t ^ (-r⁻¹) - 1) ^ finrank ℝ E) * mB := fun t ht ↦ by refine μ.addHaar_closedBall (0 : E) ?_ rw [sub_nonneg] exact Real.one_le_rpow_of_pos_of_le_one_of_nonpos ht.1 ht.2 (by simp [hr.le]) rw [setLIntegral_congr_fun measurableSet_Ioc h_int', lintegral_mul_const' _ _ measure_ball_lt_top.ne] exact ENNReal.mul_lt_top (finite_integral_rpow_sub_one_pow_aux (finrank ℝ E) hnr) measure_ball_lt_top · -- The integral from 1 to ∞ is zero: have h_int'' : ∀ t ∈ Ioi (1 : ℝ), f t = 0 := fun t ht => by simp only [f, closedBall_rpow_sub_one_eq_empty_aux E hr ht, measure_empty] -- The integral over the constant zero function is finite: rw [setLIntegral_congr_fun measurableSet_Ioi h_int'', lintegral_const 0, zero_mul] exact WithTop.top_pos theorem integrable_one_add_norm {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : Integrable (fun x ↦ (1 + ‖x‖) ^ (-r)) μ := by constructor · apply Measurable.aestronglyMeasurable (by fun_prop) -- Lower Lebesgue integral have : (∫⁻ a : E, ‖(1 + ‖a‖) ^ (-r)‖ₑ ∂μ) = ∫⁻ a : E, ENNReal.ofReal ((1 + ‖a‖) ^ (-r)) ∂μ := lintegral_enorm_of_nonneg fun _ => rpow_nonneg (by positivity) _ rw [hasFiniteIntegral_iff_enorm, this] exact finite_integral_one_add_norm hnr theorem integrable_rpow_neg_one_add_norm_sq {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : Integrable (fun x ↦ ((1 : ℝ) + ‖x‖ ^ 2) ^ (-r / 2)) μ := by have hr : 0 < r := lt_of_le_of_lt (finrank ℝ E).cast_nonneg hnr refine ((integrable_one_add_norm hnr).const_mul <| (2 : ℝ) ^ (r / 2)).mono' ?_ (Eventually.of_forall fun x => ?_) · apply Measurable.aestronglyMeasurable (by fun_prop) refine (abs_of_pos ?_).trans_le (rpow_neg_one_add_norm_sq_le x hr) positivity
Basic.lean
/- Copyright (c) 2019 Jean Lo. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo, Bhavik Mehta, Yaël Dillies -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.Convex.Hull import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Topology.Bornology.Absorbs /-! # Local convexity This file defines absorbent and balanced sets. An absorbent set is one that "surrounds" the origin. The idea is made precise by requiring that any point belongs to all large enough scalings of the set. This is the vector world analog of a topological neighborhood of the origin. A balanced set is one that is everywhere around the origin. This means that `a • s ⊆ s` for all `a` of norm less than `1`. ## Main declarations For a module over a normed ring: * `Absorbs`: A set `s` absorbs a set `t` if all large scalings of `s` contain `t`. * `Absorbent`: A set `s` is absorbent if every point eventually belongs to all large scalings of `s`. * `Balanced`: A set `s` is balanced if `a • s ⊆ s` for all `a` of norm less than `1`. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags absorbent, balanced, locally convex, LCTVS -/ open Set open Pointwise Topology variable {𝕜 𝕝 E F : Type*} {ι : Sort*} {κ : ι → Sort*} section SeminormedRing variable [SeminormedRing 𝕜] section SMul variable [SMul 𝕜 E] {s A B : Set E} variable (𝕜) in /-- A set `A` is balanced if `a • A` is contained in `A` whenever `a` has norm at most `1`. -/ def Balanced (A : Set E) := ∀ a : 𝕜, ‖a‖ ≤ 1 → a • A ⊆ A lemma absorbs_iff_norm : Absorbs 𝕜 A B ↔ ∃ r, ∀ c : 𝕜, r ≤ ‖c‖ → B ⊆ c • A := Filter.atTop_basis.cobounded_of_norm.eventually_iff.trans <| by simp only [true_and]; rfl alias ⟨_, Absorbs.of_norm⟩ := absorbs_iff_norm lemma Absorbs.exists_pos (h : Absorbs 𝕜 A B) : ∃ r > 0, ∀ c : 𝕜, r ≤ ‖c‖ → B ⊆ c • A := let ⟨r, hr₁, hr⟩ := (Filter.atTop_basis' 1).cobounded_of_norm.eventually_iff.1 h ⟨r, one_pos.trans_le hr₁, hr⟩ theorem balanced_iff_smul_mem : Balanced 𝕜 s ↔ ∀ ⦃a : 𝕜⦄, ‖a‖ ≤ 1 → ∀ ⦃x : E⦄, x ∈ s → a • x ∈ s := forall₂_congr fun _a _ha => smul_set_subset_iff alias ⟨Balanced.smul_mem, _⟩ := balanced_iff_smul_mem theorem balanced_iff_closedBall_smul : Balanced 𝕜 s ↔ Metric.closedBall (0 : 𝕜) 1 • s ⊆ s := by simp [balanced_iff_smul_mem, smul_subset_iff] @[simp] theorem balanced_empty : Balanced 𝕜 (∅ : Set E) := fun _ _ => by rw [smul_set_empty] @[simp] theorem balanced_univ : Balanced 𝕜 (univ : Set E) := fun _a _ha => subset_univ _ theorem Balanced.union (hA : Balanced 𝕜 A) (hB : Balanced 𝕜 B) : Balanced 𝕜 (A ∪ B) := fun _a ha => smul_set_union.subset.trans <| union_subset_union (hA _ ha) <| hB _ ha theorem Balanced.inter (hA : Balanced 𝕜 A) (hB : Balanced 𝕜 B) : Balanced 𝕜 (A ∩ B) := fun _a ha => smul_set_inter_subset.trans <| inter_subset_inter (hA _ ha) <| hB _ ha theorem balanced_iUnion {f : ι → Set E} (h : ∀ i, Balanced 𝕜 (f i)) : Balanced 𝕜 (⋃ i, f i) := fun _a ha => (smul_set_iUnion _ _).subset.trans <| iUnion_mono fun _ => h _ _ ha theorem balanced_iUnion₂ {f : ∀ i, κ i → Set E} (h : ∀ i j, Balanced 𝕜 (f i j)) : Balanced 𝕜 (⋃ (i) (j), f i j) := balanced_iUnion fun _ => balanced_iUnion <| h _ theorem Balanced.sInter {S : Set (Set E)} (h : ∀ s ∈ S, Balanced 𝕜 s) : Balanced 𝕜 (⋂₀ S) := fun _ _ => (smul_set_sInter_subset ..).trans (fun _ _ => by aesop) theorem balanced_iInter {f : ι → Set E} (h : ∀ i, Balanced 𝕜 (f i)) : Balanced 𝕜 (⋂ i, f i) := fun _a ha => (smul_set_iInter_subset _ _).trans <| iInter_mono fun _ => h _ _ ha theorem balanced_iInter₂ {f : ∀ i, κ i → Set E} (h : ∀ i j, Balanced 𝕜 (f i j)) : Balanced 𝕜 (⋂ (i) (j), f i j) := balanced_iInter fun _ => balanced_iInter <| h _ theorem Balanced.mulActionHom_preimage [SMul 𝕜 F] {s : Set F} (hs : Balanced 𝕜 s) (f : E →[𝕜] F) : Balanced 𝕜 (f ⁻¹' s) := fun a ha x ⟨y,⟨hy₁,hy₂⟩⟩ => by rw [mem_preimage, ← hy₂, map_smul] exact hs a ha (smul_mem_smul_set hy₁) variable [SMul 𝕝 E] [SMulCommClass 𝕜 𝕝 E] theorem Balanced.smul (a : 𝕝) (hs : Balanced 𝕜 s) : Balanced 𝕜 (a • s) := fun _b hb => (smul_comm _ _ _).subset.trans <| smul_set_mono <| hs _ hb end SMul section Module variable [AddCommGroup E] [Module 𝕜 E] {s t : Set E} theorem Balanced.neg : Balanced 𝕜 s → Balanced 𝕜 (-s) := forall₂_imp fun _ _ h => (smul_set_neg _ _).subset.trans <| neg_subset_neg.2 h @[simp] theorem balanced_neg : Balanced 𝕜 (-s) ↔ Balanced 𝕜 s := ⟨fun h ↦ neg_neg s ▸ h.neg, fun h ↦ h.neg⟩ theorem Balanced.neg_mem_iff [NormOneClass 𝕜] (h : Balanced 𝕜 s) {x : E} : -x ∈ s ↔ x ∈ s := ⟨fun hx ↦ by simpa using h.smul_mem (a := -1) (by simp) hx, fun hx ↦ by simpa using h.smul_mem (a := -1) (by simp) hx⟩ theorem Balanced.neg_eq [NormOneClass 𝕜] (h : Balanced 𝕜 s) : -s = s := Set.ext fun _ ↦ h.neg_mem_iff theorem Balanced.add (hs : Balanced 𝕜 s) (ht : Balanced 𝕜 t) : Balanced 𝕜 (s + t) := fun _a ha => (smul_add _ _ _).subset.trans <| add_subset_add (hs _ ha) <| ht _ ha theorem Balanced.sub (hs : Balanced 𝕜 s) (ht : Balanced 𝕜 t) : Balanced 𝕜 (s - t) := by simp_rw [sub_eq_add_neg] exact hs.add ht.neg theorem balanced_zero : Balanced 𝕜 (0 : Set E) := fun _a _ha => (smul_zero _).subset end Module end SeminormedRing section NormedDivisionRing variable [NormedDivisionRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t : Set E} theorem absorbs_iff_eventually_nhdsNE_zero : Absorbs 𝕜 s t ↔ ∀ᶠ c : 𝕜 in 𝓝[≠] 0, MapsTo (c • ·) t s := by rw [absorbs_iff_eventually_cobounded_mapsTo, ← Filter.inv_cobounded₀]; rfl @[deprecated (since := "2025-03-03")] alias absorbs_iff_eventually_nhdsWithin_zero := absorbs_iff_eventually_nhdsNE_zero alias ⟨Absorbs.eventually_nhdsNE_zero, _⟩ := absorbs_iff_eventually_nhdsNE_zero @[deprecated (since := "2025-03-03")] alias Absorbs.eventually_nhdsWithin_zero := Absorbs.eventually_nhdsNE_zero theorem absorbent_iff_eventually_nhdsNE_zero : Absorbent 𝕜 s ↔ ∀ x : E, ∀ᶠ c : 𝕜 in 𝓝[≠] 0, c • x ∈ s := forall_congr' fun x ↦ by simp only [absorbs_iff_eventually_nhdsNE_zero, mapsTo_singleton] @[deprecated (since := "2025-03-03")] alias absorbent_iff_eventually_nhdsWithin_zero := absorbent_iff_eventually_nhdsNE_zero alias ⟨Absorbent.eventually_nhdsNE_zero, _⟩ := absorbent_iff_eventually_nhdsWithin_zero @[deprecated (since := "2025-03-03")] alias Absorbent.eventually_nhdsWithin_zero := Absorbent.eventually_nhdsNE_zero theorem absorbs_iff_eventually_nhds_zero (h₀ : 0 ∈ s) : Absorbs 𝕜 s t ↔ ∀ᶠ c : 𝕜 in 𝓝 0, MapsTo (c • ·) t s := by rw [← nhdsNE_sup_pure, Filter.eventually_sup, Filter.eventually_pure, ← absorbs_iff_eventually_nhdsNE_zero, and_iff_left] intro x _ simpa only [zero_smul] theorem Absorbs.eventually_nhds_zero (h : Absorbs 𝕜 s t) (h₀ : 0 ∈ s) : ∀ᶠ c : 𝕜 in 𝓝 0, MapsTo (c • ·) t s := (absorbs_iff_eventually_nhds_zero h₀).1 h variable [NormedRing 𝕝] [Module 𝕜 𝕝] [NormSMulClass 𝕜 𝕝] [SMulWithZero 𝕝 E] [IsScalarTower 𝕜 𝕝 E] {a b : 𝕜} {x : E} /-- Scalar multiplication (by possibly different types) of a balanced set is monotone. -/ theorem Balanced.smul_mono (hs : Balanced 𝕝 s) {a : 𝕝} (h : ‖a‖ ≤ ‖b‖) : a • s ⊆ b • s := by obtain rfl | hb := eq_or_ne b 0 · rw [norm_zero, norm_le_zero_iff] at h simp only [h, ← image_smul, zero_smul, Subset.rfl] · calc a • s = b • (b⁻¹ • a) • s := by rw [smul_assoc, smul_inv_smul₀ hb] _ ⊆ b • s := smul_set_mono <| hs _ <| by rw [norm_smul, norm_inv, ← div_eq_inv_mul] exact div_le_one_of_le₀ h (norm_nonneg _) theorem Balanced.smul_mem_mono [SMulCommClass 𝕝 𝕜 E] (hs : Balanced 𝕝 s) {b : 𝕝} (ha : a • x ∈ s) (hba : ‖b‖ ≤ ‖a‖) : b • x ∈ s := by rcases eq_or_ne a 0 with rfl | ha₀ · simp_all · calc (a⁻¹ • b) • a • x ∈ s := by refine hs.smul_mem ?_ ha rw [norm_smul, norm_inv, ← div_eq_inv_mul] exact div_le_one_of_le₀ hba (norm_nonneg _) (a⁻¹ • b) • a • x = b • x := by rw [smul_comm, smul_assoc, smul_inv_smul₀ ha₀] theorem Balanced.subset_smul (hs : Balanced 𝕜 s) (ha : 1 ≤ ‖a‖) : s ⊆ a • s := by rw [← @norm_one 𝕜] at ha; simpa using hs.smul_mono ha theorem Balanced.smul_congr (hs : Balanced 𝕜 s) (h : ‖a‖ = ‖b‖) : a • s = b • s := (hs.smul_mono h.le).antisymm (hs.smul_mono h.ge) theorem Balanced.smul_eq (hs : Balanced 𝕜 s) (ha : ‖a‖ = 1) : a • s = s := (hs _ ha.le).antisymm <| hs.subset_smul ha.ge /-- A balanced set absorbs itself. -/ theorem Balanced.absorbs_self (hs : Balanced 𝕜 s) : Absorbs 𝕜 s s := .of_norm ⟨1, fun _ => hs.subset_smul⟩ end NormedDivisionRing section NormedField variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {s A : Set E} {x : E} {a b : 𝕜} theorem Balanced.smul_mem_iff (hs : Balanced 𝕜 s) (h : ‖a‖ = ‖b‖) : a • x ∈ s ↔ b • x ∈ s := ⟨(hs.smul_mem_mono · h.ge), (hs.smul_mem_mono · h.le)⟩ variable [TopologicalSpace E] [ContinuousSMul 𝕜 E] /-- Every neighbourhood of the origin is absorbent. -/ theorem absorbent_nhds_zero (hA : A ∈ 𝓝 (0 : E)) : Absorbent 𝕜 A := absorbent_iff_inv_smul.2 fun x ↦ Filter.tendsto_inv₀_cobounded.smul tendsto_const_nhds <| by rwa [zero_smul] /-- The union of `{0}` with the interior of a balanced set is balanced. -/ theorem Balanced.zero_insert_interior (hA : Balanced 𝕜 A) : Balanced 𝕜 (insert 0 (interior A)) := by intro a ha obtain rfl | h := eq_or_ne a 0 · rw [zero_smul_set] exacts [subset_union_left, ⟨0, Or.inl rfl⟩] · rw [← image_smul, image_insert_eq, smul_zero] apply insert_subset_insert exact ((isOpenMap_smul₀ h).mapsTo_interior <| hA.smul_mem ha).image_subset /-- The interior of a balanced set is balanced if it contains the origin. -/ protected theorem Balanced.interior (hA : Balanced 𝕜 A) (h : (0 : E) ∈ interior A) : Balanced 𝕜 (interior A) := by rw [← insert_eq_self.2 h] exact hA.zero_insert_interior protected theorem Balanced.closure (hA : Balanced 𝕜 A) : Balanced 𝕜 (closure A) := fun _a ha => (image_closure_subset_closure_image <| continuous_const_smul _).trans <| closure_mono <| hA _ ha end NormedField section NontriviallyNormedField variable [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {s : Set E} variable [Module ℝ E] [SMulCommClass ℝ 𝕜 E] protected theorem Balanced.convexHull (hs : Balanced 𝕜 s) : Balanced 𝕜 (convexHull ℝ s) := by suffices Convex ℝ { x | ∀ a : 𝕜, ‖a‖ ≤ 1 → a • x ∈ convexHull ℝ s } by rw [balanced_iff_smul_mem] at hs ⊢ refine fun a ha x hx => convexHull_min ?_ this hx a ha exact fun y hy a ha => subset_convexHull ℝ s (hs ha hy) intro x hx y hy u v hu hv huv a ha simp only [smul_add, ← smul_comm] exact convex_convexHull ℝ s (hx a ha) (hy a ha) hu hv huv end NontriviallyNormedField section Real variable [AddCommGroup E] [Module ℝ E] {s : Set E} theorem balanced_iff_neg_mem (hs : Convex ℝ s) : Balanced ℝ s ↔ ∀ ⦃x⦄, x ∈ s → -x ∈ s := by refine ⟨fun h x => h.neg_mem_iff.2, fun h a ha => smul_set_subset_iff.2 fun x hx => ?_⟩ rw [Real.norm_eq_abs, abs_le] at ha rw [show a = -((1 - a) / 2) + (a - -1) / 2 by ring, add_smul, neg_smul, ← smul_neg] exact hs (h hx) hx (div_nonneg (sub_nonneg_of_le ha.2) zero_le_two) (div_nonneg (sub_nonneg_of_le ha.1) zero_le_two) (by ring) end Real
ChangeOfRings.lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.Algebra.Category.ModuleCat.EpiMono import Mathlib.Algebra.Category.ModuleCat.Colimits import Mathlib.Algebra.Category.ModuleCat.Limits import Mathlib.Algebra.Algebra.RestrictScalars import Mathlib.CategoryTheory.Adjunction.Mates import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.LinearAlgebra.TensorProduct.Tower /-! # Change Of Rings ## Main definitions * `ModuleCat.restrictScalars`: given rings `R, S` and a ring homomorphism `R ⟶ S`, then `restrictScalars : ModuleCat S ⥤ ModuleCat R` is defined by `M ↦ M` where an `S`-module `M` is seen as an `R`-module by `r • m := f r • m` and `S`-linear map `l : M ⟶ M'` is `R`-linear as well. * `ModuleCat.extendScalars`: given **commutative** rings `R, S` and ring homomorphism `f : R ⟶ S`, then `extendScalars : ModuleCat R ⥤ ModuleCat S` is defined by `M ↦ S ⨂ M` where the module structure is defined by `s • (s' ⊗ m) := (s * s') ⊗ m` and `R`-linear map `l : M ⟶ M'` is sent to `S`-linear map `s ⊗ m ↦ s ⊗ l m : S ⨂ M ⟶ S ⨂ M'`. * `ModuleCat.coextendScalars`: given rings `R, S` and a ring homomorphism `R ⟶ S` then `coextendScalars : ModuleCat R ⥤ ModuleCat S` is defined by `M ↦ (S →ₗ[R] M)` where `S` is seen as an `R`-module by restriction of scalars and `l ↦ l ∘ _`. ## Main results * `ModuleCat.extendRestrictScalarsAdj`: given commutative rings `R, S` and a ring homomorphism `f : R →+* S`, the extension and restriction of scalars by `f` are adjoint functors. * `ModuleCat.restrictCoextendScalarsAdj`: given rings `R, S` and a ring homomorphism `f : R ⟶ S` then `coextendScalars f` is the right adjoint of `restrictScalars f`. ## List of notations Let `R, S` be rings and `f : R →+* S` * if `M` is an `R`-module, `s : S` and `m : M`, then `s ⊗ₜ[R, f] m` is the pure tensor `s ⊗ m : S ⊗[R, f] M`. -/ suppress_compilation open CategoryTheory Limits namespace ModuleCat universe v u₁ u₂ u₃ w namespace RestrictScalars variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) variable (M : ModuleCat.{v} S) /-- Any `S`-module M is also an `R`-module via a ring homomorphism `f : R ⟶ S` by defining `r • m := f r • m` (`Module.compHom`). This is called restriction of scalars. -/ def obj' : ModuleCat R := let _ := Module.compHom M f of R M /-- Given an `S`-linear map `g : M → M'` between `S`-modules, `g` is also `R`-linear between `M` and `M'` by means of restriction of scalars. -/ def map' {M M' : ModuleCat.{v} S} (g : M ⟶ M') : obj' f M ⟶ obj' f M' := -- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(X := ...)` and `(Y := ...)`. -- This suggests `RestrictScalars.obj'` needs to be redesigned. ofHom (X := obj' f M) (Y := obj' f M') { g.hom with map_smul' := fun r => g.hom.map_smul (f r) } end RestrictScalars /-- The restriction of scalars operation is functorial. For any `f : R →+* S` a ring homomorphism, * an `S`-module `M` can be considered as `R`-module by `r • m = f r • m` * an `S`-linear map is also `R`-linear -/ def restrictScalars {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) : ModuleCat.{v} S ⥤ ModuleCat.{v} R where obj := RestrictScalars.obj' f map := RestrictScalars.map' f instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) : (restrictScalars.{v} f).Faithful where map_injective h := by ext x simpa only using DFunLike.congr_fun (ModuleCat.hom_ext_iff.mp h) x instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) : (restrictScalars.{v} f).PreservesMonomorphisms where preserves _ h := by rwa [mono_iff_injective] at h ⊢ -- Porting note: this should be automatic -- TODO: this instance gives diamonds if `f : S →+* S`, see `PresheafOfModules.pushforward₀`. -- The correct solution is probably to define explicit maps between `M` and -- `(restrictScalars f).obj M`. instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] {f : R →+* S} {M : ModuleCat.{v} S} : Module S <| (restrictScalars f).obj M := inferInstanceAs <| Module S M @[simp] theorem restrictScalars.map_apply {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) {M M' : ModuleCat.{v} S} (g : M ⟶ M') (x) : (restrictScalars f).map g x = g x := rfl @[simp] theorem restrictScalars.smul_def {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) {M : ModuleCat.{v} S} (r : R) (m : (restrictScalars f).obj M) : r • m = f r • show M from m := rfl theorem restrictScalars.smul_def' {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) {M : ModuleCat.{v} S} (r : R) (m : M) : r • (show (restrictScalars f).obj M from m) = f r • m := rfl instance (priority := 100) sMulCommClass_mk {R : Type u₁} {S : Type u₂} [Ring R] [CommRing S] (f : R →+* S) (M : Type v) [I : AddCommGroup M] [Module S M] : haveI : SMul R M := (RestrictScalars.obj' f (ModuleCat.of S M)).isModule.toSMul SMulCommClass R S M := @SMulCommClass.mk R S M (_) _ fun r s m => (by simp [← mul_smul, mul_comm] : f r • s • m = s • f r • m) /-- Semilinear maps `M →ₛₗ[f] N` identify to morphisms `M ⟶ (ModuleCat.restrictScalars f).obj N`. -/ @[simps] def semilinearMapAddEquiv {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) (M : ModuleCat.{v} R) (N : ModuleCat.{v} S) : (M →ₛₗ[f] N) ≃+ (M ⟶ (ModuleCat.restrictScalars f).obj N) where -- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`. -- This suggests `restrictScalars` needs to be redesigned. toFun g := ofHom (Y := (ModuleCat.restrictScalars f).obj N) <| { toFun := g map_add' := by simp map_smul' := by simp } invFun g := { toFun := g map_add' := by simp map_smul' := g.hom.map_smul } map_add' _ _ := rfl section variable {R : Type u₁} [Ring R] (f : R →+* R) /-- For a `R`-module `M`, the restriction of scalars of `M` by the identity morphism identifies to `M`. -/ def restrictScalarsId'App (hf : f = RingHom.id R) (M : ModuleCat R) : (restrictScalars f).obj M ≅ M := LinearEquiv.toModuleIso <| @AddEquiv.toLinearEquiv _ _ _ _ _ _ (((restrictScalars f).obj M).isModule) _ (by rfl) (fun r x ↦ by subst hf; rfl) variable (hf : f = RingHom.id R) @[simp] lemma restrictScalarsId'App_hom_apply (M : ModuleCat R) (x : M) : (restrictScalarsId'App f hf M).hom x = x := rfl @[simp] lemma restrictScalarsId'App_inv_apply (M : ModuleCat R) (x : M) : (restrictScalarsId'App f hf M).inv x = x := rfl /-- The restriction of scalars by a ring morphism that is the identity identifies to the identity functor. -/ @[simps! hom_app inv_app] def restrictScalarsId' : ModuleCat.restrictScalars.{v} f ≅ 𝟭 _ := NatIso.ofComponents <| fun M ↦ restrictScalarsId'App f hf M @[reassoc] lemma restrictScalarsId'App_hom_naturality {M N : ModuleCat R} (φ : M ⟶ N) : (restrictScalars f).map φ ≫ (restrictScalarsId'App f hf N).hom = (restrictScalarsId'App f hf M).hom ≫ φ := (restrictScalarsId' f hf).hom.naturality φ @[reassoc] lemma restrictScalarsId'App_inv_naturality {M N : ModuleCat R} (φ : M ⟶ N) : φ ≫ (restrictScalarsId'App f hf N).inv = (restrictScalarsId'App f hf M).inv ≫ (restrictScalars f).map φ := (restrictScalarsId' f hf).inv.naturality φ variable (R) /-- The restriction of scalars by the identity morphism identifies to the identity functor. -/ abbrev restrictScalarsId := restrictScalarsId'.{v} (RingHom.id R) rfl end section variable {R₁ : Type u₁} {R₂ : Type u₂} {R₃ : Type u₃} [Ring R₁] [Ring R₂] [Ring R₃] (f : R₁ →+* R₂) (g : R₂ →+* R₃) (gf : R₁ →+* R₃) /-- For each `R₃`-module `M`, restriction of scalars of `M` by a composition of ring morphisms identifies to successively restricting scalars. -/ def restrictScalarsComp'App (hgf : gf = g.comp f) (M : ModuleCat R₃) : (restrictScalars gf).obj M ≅ (restrictScalars f).obj ((restrictScalars g).obj M) := (AddEquiv.toLinearEquiv (M := ↑((restrictScalars gf).obj M)) (M₂ := ↑((restrictScalars f).obj ((restrictScalars g).obj M))) (by rfl) (fun r x ↦ by subst hgf; rfl)).toModuleIso variable (hgf : gf = g.comp f) @[simp] lemma restrictScalarsComp'App_hom_apply (M : ModuleCat R₃) (x : M) : (restrictScalarsComp'App f g gf hgf M).hom x = x := rfl @[simp] lemma restrictScalarsComp'App_inv_apply (M : ModuleCat R₃) (x : M) : (restrictScalarsComp'App f g gf hgf M).inv x = x := rfl /-- The restriction of scalars by a composition of ring morphisms identifies to the composition of the restriction of scalars functors. -/ @[simps! hom_app inv_app] def restrictScalarsComp' : ModuleCat.restrictScalars.{v} gf ≅ ModuleCat.restrictScalars g ⋙ ModuleCat.restrictScalars f := NatIso.ofComponents <| fun M ↦ restrictScalarsComp'App f g gf hgf M @[reassoc] lemma restrictScalarsComp'App_hom_naturality {M N : ModuleCat R₃} (φ : M ⟶ N) : (restrictScalars gf).map φ ≫ (restrictScalarsComp'App f g gf hgf N).hom = (restrictScalarsComp'App f g gf hgf M).hom ≫ (restrictScalars f).map ((restrictScalars g).map φ) := (restrictScalarsComp' f g gf hgf).hom.naturality φ @[reassoc] lemma restrictScalarsComp'App_inv_naturality {M N : ModuleCat R₃} (φ : M ⟶ N) : (restrictScalars f).map ((restrictScalars g).map φ) ≫ (restrictScalarsComp'App f g gf hgf N).inv = (restrictScalarsComp'App f g gf hgf M).inv ≫ (restrictScalars gf).map φ := (restrictScalarsComp' f g gf hgf).inv.naturality φ /-- The restriction of scalars by a composition of ring morphisms identifies to the composition of the restriction of scalars functors. -/ abbrev restrictScalarsComp := restrictScalarsComp'.{v} f g _ rfl end /-- The equivalence of categories `ModuleCat S ≌ ModuleCat R` induced by `e : R ≃+* S`. -/ def restrictScalarsEquivalenceOfRingEquiv {R S} [Ring R] [Ring S] (e : R ≃+* S) : ModuleCat S ≌ ModuleCat R where functor := ModuleCat.restrictScalars e.toRingHom inverse := ModuleCat.restrictScalars e.symm unitIso := NatIso.ofComponents (fun M ↦ LinearEquiv.toModuleIso (X₁ := M) (X₂ := (restrictScalars e.symm.toRingHom).obj ((restrictScalars e.toRingHom).obj M)) { __ := AddEquiv.refl M map_smul' := fun s m ↦ congr_arg (· • m) (e.right_inv s).symm }) (by intros; rfl) counitIso := NatIso.ofComponents (fun M ↦ LinearEquiv.toModuleIso (X₁ := (restrictScalars e.toRingHom).obj ((restrictScalars e.symm.toRingHom).obj M)) (X₂ := M) { __ := AddEquiv.refl M map_smul' := fun r _ ↦ congr_arg (· • (_ : M)) (e.left_inv r)}) (by intros; rfl) functor_unitIso_comp := by intros; rfl instance restrictScalars_isEquivalence_of_ringEquiv {R S} [Ring R] [Ring S] (e : R ≃+* S) : (ModuleCat.restrictScalars e.toRingHom).IsEquivalence := (restrictScalarsEquivalenceOfRingEquiv e).isEquivalence_functor instance {R S} [Ring R] [Ring S] (f : R →+* S) : (restrictScalars f).Additive where instance restrictScalarsEquivalenceOfRingEquiv_additive {R S} [Ring R] [Ring S] (e : R ≃+* S) : (restrictScalarsEquivalenceOfRingEquiv e).functor.Additive where namespace Algebra instance {R₀ R S} [CommSemiring R₀] [Ring R] [Ring S] [Algebra R₀ R] [Algebra R₀ S] (f : R →ₐ[R₀] S) : (restrictScalars f.toRingHom).Linear R₀ where map_smul {M N} g r₀ := by ext m; exact congr_arg (· • g.hom m) (f.commutes r₀).symm instance restrictScalarsEquivalenceOfRingEquiv_linear {R₀ R S} [CommSemiring R₀] [Ring R] [Ring S] [Algebra R₀ R] [Algebra R₀ S] (e : R ≃ₐ[R₀] S) : (restrictScalarsEquivalenceOfRingEquiv e.toRingEquiv).functor.Linear R₀ := inferInstanceAs ((restrictScalars e.toAlgHom.toRingHom).Linear R₀) end Algebra open TensorProduct variable {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) section ModuleCat.Unbundled variable (M : Type v) [AddCommMonoid M] [Module R M] /-- Tensor product of elements along a base change. This notation is necessary because we need to reason about `s ⊗ₜ m` where `s : S` and `m : M`; without this notation, one needs to work with `s : (restrictScalars f).obj ⟨S⟩`. -/ scoped[ChangeOfRings] notation:100 s:100 " ⊗ₜ[" R "," f "] " m:101 => @TensorProduct.tmul R _ _ _ _ _ (Module.compHom _ f) _ s m end Unbundled open ChangeOfRings namespace ExtendScalars variable (M : ModuleCat.{v} R) /-- Extension of scalars turns an `R`-module into an `S`-module by M ↦ S ⨂ M -/ def obj' : ModuleCat S := of _ (TensorProduct R ((restrictScalars f).obj (of _ S)) M) /-- Extension of scalars is a functor where an `R`-module `M` is sent to `S ⊗ M` and `l : M1 ⟶ M2` is sent to `s ⊗ m ↦ s ⊗ l m` -/ def map' {M1 M2 : ModuleCat.{v} R} (l : M1 ⟶ M2) : obj' f M1 ⟶ obj' f M2 := ofHom (@LinearMap.baseChange R S M1 M2 _ _ ((algebraMap S _).comp f).toAlgebra _ _ _ _ l.hom) theorem map'_id {M : ModuleCat.{v} R} : map' f (𝟙 M) = 𝟙 _ := by ext x simp [map', obj'] theorem map'_comp {M₁ M₂ M₃ : ModuleCat.{v} R} (l₁₂ : M₁ ⟶ M₂) (l₂₃ : M₂ ⟶ M₃) : map' f (l₁₂ ≫ l₂₃) = map' f l₁₂ ≫ map' f l₂₃ := by ext x dsimp only [map'] induction x using TensorProduct.induction_on with | zero => rfl | tmul => rfl | add _ _ ihx ihy => rw [map_add, map_add, ihx, ihy] end ExtendScalars /-- Extension of scalars is a functor where an `R`-module `M` is sent to `S ⊗ M` and `l : M1 ⟶ M2` is sent to `s ⊗ m ↦ s ⊗ l m` -/ def extendScalars {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) : ModuleCat R ⥤ ModuleCat S where obj M := ExtendScalars.obj' f M map l := ExtendScalars.map' f l map_id _ := ExtendScalars.map'_id f map_comp := ExtendScalars.map'_comp f namespace ExtendScalars variable {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) @[simp] protected theorem smul_tmul {M : ModuleCat.{v} R} (s s' : S) (m : M) : s • (s' ⊗ₜ[R,f] m : (extendScalars f).obj M) = (s * s') ⊗ₜ[R,f] m := rfl @[simp] theorem map_tmul {M M' : ModuleCat.{v} R} (g : M ⟶ M') (s : S) (m : M) : (extendScalars f).map g (s ⊗ₜ[R,f] m) = s ⊗ₜ[R,f] g m := rfl variable {f} @[ext] lemma hom_ext {M : ModuleCat R} {N : ModuleCat S} {α β : (extendScalars f).obj M ⟶ N} (h : ∀ (m : M), α ((1 : S) ⊗ₜ m) = β ((1 : S) ⊗ₜ m)) : α = β := by apply (restrictScalars f).map_injective letI := f.toAlgebra ext : 1 apply TensorProduct.ext' intro (s : S) m change α (s ⊗ₜ m) = β (s ⊗ₜ m) have : s ⊗ₜ[R] (m : M) = s • (1 : S) ⊗ₜ[R] m := by rw [ExtendScalars.smul_tmul, mul_one] simp only [this, map_smul, h] end ExtendScalars namespace CoextendScalars variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) section Unbundled variable (M : Type v) [AddCommMonoid M] [Module R M] -- We use `S'` to denote `S` viewed as `R`-module, via the map `f`. -- Porting note: this seems to cause problems related to lack of reducibility -- local notation "S'" => (restrictScalars f).obj ⟨S⟩ /-- Given an `R`-module M, consider Hom(S, M) -- the `R`-linear maps between S (as an `R`-module by means of restriction of scalars) and M. `S` acts on Hom(S, M) by `s • g = x ↦ g (x • s)` -/ instance hasSMul : SMul S <| (restrictScalars f).obj (of _ S) →ₗ[R] M where smul s g := { toFun := fun s' : S => g (s' * s : S) map_add' := fun x y : S => by rw [add_mul, map_add] map_smul' := fun r (t : S) => by -- Porting note: needed some erw's even after dsimp to clean things up dsimp rw [← LinearMap.map_smul] erw [smul_eq_mul, smul_eq_mul, mul_assoc] } @[simp] theorem smul_apply' (s : S) (g : (restrictScalars f).obj (of _ S) →ₗ[R] M) (s' : S) : (s • g) s' = g (s' * s : S) := rfl instance mulAction : MulAction S <| (restrictScalars f).obj (of _ S) →ₗ[R] M := { CoextendScalars.hasSMul f _ with one_smul := fun g => LinearMap.ext fun s : S => by simp mul_smul := fun (s t : S) g => LinearMap.ext fun x : S => by simp [mul_assoc] } instance distribMulAction : DistribMulAction S <| (restrictScalars f).obj (of _ S) →ₗ[R] M := { CoextendScalars.mulAction f _ with smul_add := fun s g h => LinearMap.ext fun _ : S => by simp smul_zero := fun _ => LinearMap.ext fun _ : S => by simp } /-- `S` acts on Hom(S, M) by `s • g = x ↦ g (x • s)`, this action defines an `S`-module structure on Hom(S, M). -/ instance isModule : Module S <| (restrictScalars f).obj (of _ S) →ₗ[R] M := { CoextendScalars.distribMulAction f _ with add_smul := fun s1 s2 g => LinearMap.ext fun x : S => by simp [mul_add, LinearMap.map_add] zero_smul := fun g => LinearMap.ext fun x : S => by simp [LinearMap.map_zero] } end Unbundled variable (M : ModuleCat.{v} R) /-- If `M` is an `R`-module, then the set of `R`-linear maps `S →ₗ[R] M` is an `S`-module with scalar multiplication defined by `s • l := x ↦ l (x • s)` -/ def obj' : ModuleCat S := of _ ((restrictScalars f).obj (of _ S) →ₗ[R] M) instance : CoeFun (obj' f M) fun _ => S → M := inferInstanceAs <| CoeFun ((restrictScalars f).obj (of _ S) →ₗ[R] M) _ /-- If `M, M'` are `R`-modules, then any `R`-linear map `g : M ⟶ M'` induces an `S`-linear map `(S →ₗ[R] M) ⟶ (S →ₗ[R] M')` defined by `h ↦ g ∘ h` -/ @[simps!] def map' {M M' : ModuleCat R} (g : M ⟶ M') : obj' f M ⟶ obj' f M' := ofHom { toFun := fun h => g.hom.comp h map_add' := fun _ _ => LinearMap.comp_add _ _ _ map_smul' := fun s h => by ext; simp } end CoextendScalars /-- For any rings `R, S` and a ring homomorphism `f : R →+* S`, there is a functor from `R`-module to `S`-module defined by `M ↦ (S →ₗ[R] M)` where `S` is considered as an `R`-module via restriction of scalars and `g : M ⟶ M'` is sent to `h ↦ g ∘ h`. -/ def coextendScalars {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) : ModuleCat R ⥤ ModuleCat S where obj := CoextendScalars.obj' f map := CoextendScalars.map' f map_id _ := by ext; rfl map_comp _ _ := by ext; rfl namespace CoextendScalars variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) instance (M : ModuleCat R) : CoeFun ((coextendScalars f).obj M) fun _ => S → M := inferInstanceAs <| CoeFun (CoextendScalars.obj' f M) _ theorem smul_apply (M : ModuleCat R) (g : (coextendScalars f).obj M) (s s' : S) : (s • g) s' = g (s' * s) := rfl @[simp] theorem map_apply {M M' : ModuleCat R} (g : M ⟶ M') (x) (s : S) : (coextendScalars f).map g x s = g (x s) := rfl end CoextendScalars namespace RestrictionCoextensionAdj variable {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) /-- Given `R`-module X and `S`-module Y, any `g : (restrictScalars f).obj Y ⟶ X` corresponds to `Y ⟶ (coextendScalars f).obj X` by sending `y ↦ (s ↦ g (s • y))` -/ def HomEquiv.fromRestriction {X : ModuleCat R} {Y : ModuleCat S} (g : (restrictScalars f).obj Y ⟶ X) : Y ⟶ (coextendScalars f).obj X := ofHom { toFun := fun y : Y => { toFun := fun s : S => g <| (s • y : Y) map_add' := fun s1 s2 : S => by simp only [add_smul]; rw [LinearMap.map_add] map_smul' := fun r (s : S) => by -- Porting note: dsimp clears out some rw's but less eager to apply others with Lean 4 dsimp rw [← g.hom.map_smul] erw [smul_eq_mul, mul_smul] rfl } map_add' := fun y1 y2 : Y => LinearMap.ext fun s : S => by simp [smul_add, map_add] map_smul' := fun (s : S) (y : Y) => LinearMap.ext fun t : S => by simp [mul_smul] } /-- This should be autogenerated by `@[simps]` but we need to give `s` the correct type here. -/ @[simp] lemma HomEquiv.fromRestriction_hom_apply_apply {X : ModuleCat R} {Y : ModuleCat S} (g : (restrictScalars f).obj Y ⟶ X) (y) (s : S) : (HomEquiv.fromRestriction f g).hom y s = g (s • y) := rfl /-- Given `R`-module X and `S`-module Y, any `g : Y ⟶ (coextendScalars f).obj X` corresponds to `(restrictScalars f).obj Y ⟶ X` by `y ↦ g y 1` -/ def HomEquiv.toRestriction {X Y} (g : Y ⟶ (coextendScalars f).obj X) : (restrictScalars f).obj Y ⟶ X := -- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(X := ...)`. -- This suggests `restrictScalars` needs to be redesigned. ofHom (X := (restrictScalars f).obj Y) { toFun := fun y : Y => (g y) (1 : S) map_add' := fun x y => by dsimp; rw [g.hom.map_add, LinearMap.add_apply] map_smul' := fun r (y : Y) => by dsimp rw [← LinearMap.map_smul] erw [smul_eq_mul, mul_one, LinearMap.map_smul] rw [CoextendScalars.smul_apply (s := f r) (g := g y) (s' := 1), one_mul] simp } /-- This should be autogenerated by `@[simps]` but we need to give `1` the correct type here. -/ @[simp] lemma HomEquiv.toRestriction_hom_apply {X : ModuleCat R} {Y : ModuleCat S} (g : Y ⟶ (coextendScalars f).obj X) (y) : (HomEquiv.toRestriction f g).hom y = g.hom y (1 : S) := rfl /-- Auxiliary definition for `unit'`, to address timeouts. -/ def app' (Y : ModuleCat S) : Y →ₗ[S] (restrictScalars f ⋙ coextendScalars f).obj Y := { toFun := fun y : Y => { toFun := fun s : S => (s • y : Y) map_add' := fun _ _ => add_smul _ _ _ map_smul' := fun r (s : S) => by dsimp only [AddHom.toFun_eq_coe, AddHom.coe_mk, RingHom.id_apply] erw [smul_eq_mul, mul_smul] simp } map_add' := fun y1 y2 => LinearMap.ext fun s : S => by -- Porting note: double dsimp seems odd dsimp only [AddHom.toFun_eq_coe, AddHom.coe_mk, RingHom.id_apply, RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, MonoidHom.coe_coe, ZeroHom.coe_mk, smul_eq_mul, id_eq, eq_mpr_eq_cast, cast_eq, Functor.comp_obj] rw [LinearMap.add_apply, LinearMap.coe_mk, LinearMap.coe_mk, LinearMap.coe_mk] dsimp rw [smul_add] map_smul' := fun s (y : Y) => LinearMap.ext fun t : S => by -- Porting note: used to be simp [mul_smul] rw [RingHom.id_apply, LinearMap.coe_mk, CoextendScalars.smul_apply', LinearMap.coe_mk] dsimp rw [mul_smul] } /-- The natural transformation from identity functor to the composition of restriction and coextension of scalars. -/ @[simps] protected noncomputable def unit' : 𝟭 (ModuleCat S) ⟶ restrictScalars f ⋙ coextendScalars f where app Y := ofHom (app' f Y) naturality Y Y' g := hom_ext <| LinearMap.ext fun y : Y => LinearMap.ext fun s : S => by -- Porting note (https://github.com/leanprover-community/mathlib4/pull/10745): previously simp [CoextendScalars.map_apply] simp only [ModuleCat.hom_comp, Functor.id_map, Functor.id_obj, Functor.comp_obj, Functor.comp_map, LinearMap.coe_comp, Function.comp, CoextendScalars.map_apply, restrictScalars.map_apply f] change s • (g y) = g (s • y) rw [map_smul] /-- The natural transformation from the composition of coextension and restriction of scalars to identity functor. -/ @[simps] protected def counit' : coextendScalars f ⋙ restrictScalars f ⟶ 𝟭 (ModuleCat R) where -- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(X := ...)`. -- This suggests `restrictScalars` needs to be redesigned. app X := ofHom (X := (restrictScalars f).obj ((coextendScalars f).obj X)) { toFun := fun g => g.toFun (1 : S) map_add' := fun x1 x2 => by dsimp rw [LinearMap.add_apply] map_smul' := fun r (g : (restrictScalars f).obj ((coextendScalars f).obj X)) => by dsimp rw [CoextendScalars.smul_apply, one_mul, ← LinearMap.map_smul] congr change f r = f r • (1 : S) rw [smul_eq_mul (f r) 1, mul_one] } end RestrictionCoextensionAdj -- Porting note: very fiddly universes /-- Restriction of scalars is left adjoint to coextension of scalars. -/ -- @[simps] Porting note: not in normal form and not used def restrictCoextendScalarsAdj {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) : restrictScalars.{max v u₂,u₁,u₂} f ⊣ coextendScalars f := Adjunction.mk' { homEquiv := fun X Y ↦ { toFun := RestrictionCoextensionAdj.HomEquiv.fromRestriction.{u₁,u₂,v} f invFun := RestrictionCoextensionAdj.HomEquiv.toRestriction.{u₁,u₂,v} f left_inv := fun g => by ext; simp right_inv := fun g => hom_ext <| LinearMap.ext fun x => LinearMap.ext fun s : S => by -- Porting note (https://github.com/leanprover-community/mathlib4/pull/10745): once just simp rw [RestrictionCoextensionAdj.HomEquiv.fromRestriction_hom_apply_apply, RestrictionCoextensionAdj.HomEquiv.toRestriction_hom_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, CoextendScalars.smul_apply', one_mul] } unit := RestrictionCoextensionAdj.unit'.{u₁,u₂,v} f counit := RestrictionCoextensionAdj.counit'.{u₁,u₂,v} f homEquiv_unit := hom_ext <| LinearMap.ext fun _ => rfl homEquiv_counit := fun {X Y g} => by ext simp [RestrictionCoextensionAdj.counit'] } instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) : (restrictScalars.{max u₂ w} f).IsLeftAdjoint := (restrictCoextendScalarsAdj f).isLeftAdjoint instance {R : Type u₁} {S : Type u₂} [Ring R] [Ring S] (f : R →+* S) : (coextendScalars.{u₁, u₂, max u₂ w} f).IsRightAdjoint := (restrictCoextendScalarsAdj f).isRightAdjoint namespace ExtendRestrictScalarsAdj open TensorProduct variable {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) /-- Given `R`-module X and `S`-module Y and a map `g : (extendScalars f).obj X ⟶ Y`, i.e. `S`-linear map `S ⨂ X → Y`, there is a `X ⟶ (restrictScalars f).obj Y`, i.e. `R`-linear map `X ⟶ Y` by `x ↦ g (1 ⊗ x)`. -/ @[simps! hom_apply] def HomEquiv.toRestrictScalars {X Y} (g : (extendScalars f).obj X ⟶ Y) : X ⟶ (restrictScalars f).obj Y := -- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`. -- This suggests `restrictScalars` needs to be redesigned. ofHom (Y := (restrictScalars f).obj Y) { toFun := fun x => g <| (1 : S) ⊗ₜ[R,f] x map_add' := fun _ _ => by dsimp; rw [tmul_add, map_add] map_smul' := fun r s => by letI : Module R S := Module.compHom S f letI : Module R Y := Module.compHom Y f dsimp rw [RestrictScalars.smul_def, ← LinearMap.map_smul] erw [tmul_smul] congr } -- Porting note: forced to break apart fromExtendScalars due to timeouts /-- The map `S → X →ₗ[R] Y` given by `fun s x => s • (g x)` -/ @[simps] def HomEquiv.evalAt {X : ModuleCat R} {Y : ModuleCat S} (s : S) (g : X ⟶ (restrictScalars f).obj Y) : have : Module R Y := Module.compHom Y f X →ₗ[R] Y := @LinearMap.mk _ _ _ _ (RingHom.id R) X Y _ _ _ (_) { toFun := fun x => s • (g x : Y) map_add' := by intros dsimp only rw [map_add, smul_add] } (by intros r x rw [AddHom.toFun_eq_coe, AddHom.coe_mk, RingHom.id_apply, LinearMap.map_smul, smul_comm r s (g x : Y)] ) /-- Given `R`-module X and `S`-module Y and a map `X ⟶ (restrictScalars f).obj Y`, i.e `R`-linear map `X ⟶ Y`, there is a map `(extend_scalars f).obj X ⟶ Y`, i.e `S`-linear map `S ⨂ X → Y` by `s ⊗ x ↦ s • g x`. -/ @[simps! hom_apply] def HomEquiv.fromExtendScalars {X Y} (g : X ⟶ (restrictScalars f).obj Y) : (extendScalars f).obj X ⟶ Y := by letI m1 : Module R S := Module.compHom S f; letI m2 : Module R Y := Module.compHom Y f refine ofHom {toFun := fun z => TensorProduct.lift ?_ z, map_add' := ?_, map_smul' := ?_} · refine {toFun := fun s => HomEquiv.evalAt f s g, map_add' := fun (s₁ s₂ : S) => ?_, map_smul' := fun (r : R) (s : S) => ?_} · ext dsimp only [m2, evalAt_apply, LinearMap.add_apply] rw [← add_smul] · ext x apply mul_smul (f r) s (g x) · intros z₁ z₂ simp · intro s z change lift _ (s • z) = s • lift _ z induction z using TensorProduct.induction_on with | zero => rw [smul_zero, map_zero, smul_zero] | tmul s' x => rw [LinearMap.coe_mk, ExtendScalars.smul_tmul] erw [lift.tmul, lift.tmul] set s' : S := s' change (s * s') • (g x) = s • s' • (g x) rw [mul_smul] | add _ _ ih1 ih2 => rw [smul_add, map_add, ih1, ih2, map_add, smul_add] /-- Given `R`-module X and `S`-module Y, `S`-linear linear maps `(extendScalars f).obj X ⟶ Y` bijectively correspond to `R`-linear maps `X ⟶ (restrictScalars f).obj Y`. -/ @[simps symm_apply] def homEquiv {X Y} : ((extendScalars f).obj X ⟶ Y) ≃ (X ⟶ (restrictScalars.{max v u₂,u₁,u₂} f).obj Y) where toFun := HomEquiv.toRestrictScalars.{u₁,u₂,v} f invFun := HomEquiv.fromExtendScalars.{u₁,u₂,v} f left_inv g := by letI m1 : Module R S := Module.compHom S f; letI m2 : Module R Y := Module.compHom Y f apply hom_ext apply LinearMap.ext; intro z induction z using TensorProduct.induction_on with | zero => rw [map_zero, map_zero] | tmul x s => erw [TensorProduct.lift.tmul] simp only [LinearMap.coe_mk] change S at x dsimp erw [← LinearMap.map_smul, ExtendScalars.smul_tmul, mul_one x] rfl | add _ _ ih1 ih2 => rw [map_add, map_add, ih1, ih2] right_inv g := by letI m1 : Module R S := Module.compHom S f; letI m2 : Module R Y := Module.compHom Y f ext x rw [HomEquiv.toRestrictScalars_hom_apply] -- This needs to be `erw` because of some unfolding in `fromExtendScalars` erw [HomEquiv.fromExtendScalars_hom_apply] rw [lift.tmul, LinearMap.coe_mk, LinearMap.coe_mk] dsimp rw [one_smul] /-- For any `R`-module X, there is a natural `R`-linear map from `X` to `X ⨂ S` by sending `x ↦ x ⊗ 1` -/ -- @[simps] Porting note: not in normal form and not used def Unit.map {X} : X ⟶ (extendScalars f ⋙ restrictScalars f).obj X := -- TODO: after https://github.com/leanprover-community/mathlib4/pull/19511 we need to hint `(Y := ...)`. -- This suggests `restrictScalars` needs to be redesigned. ofHom (Y := (extendScalars f ⋙ restrictScalars f).obj X) { toFun := fun x => (1 : S) ⊗ₜ[R,f] x map_add' := fun x x' => by dsimp; rw [TensorProduct.tmul_add] map_smul' := fun r x => by letI m1 : Module R S := Module.compHom S f dsimp; rw [← TensorProduct.smul_tmul,TensorProduct.smul_tmul'] } /-- The natural transformation from identity functor on `R`-module to the composition of extension and restriction of scalars. -/ @[simps] def unit : 𝟭 (ModuleCat R) ⟶ extendScalars f ⋙ restrictScalars.{max v u₂,u₁,u₂} f where app _ := Unit.map.{u₁,u₂,v} f /-- For any `S`-module Y, there is a natural `R`-linear map from `S ⨂ Y` to `Y` by `s ⊗ y ↦ s • y` -/ @[simps! hom_apply] def Counit.map {Y} : (restrictScalars f ⋙ extendScalars f).obj Y ⟶ Y := ofHom { toFun := letI m1 : Module R S := Module.compHom S f letI m2 : Module R Y := Module.compHom Y f TensorProduct.lift { toFun := fun s : S => { toFun := fun y : Y => s • y, map_add' := smul_add _ map_smul' := fun r y => by change s • f r • y = f r • s • y rw [← mul_smul, mul_comm, mul_smul] }, map_add' := fun s₁ s₂ => by ext y change (s₁ + s₂) • y = s₁ • y + s₂ • y rw [add_smul] map_smul' := fun r s => by ext y change (f r • s) • y = (f r) • s • y rw [smul_eq_mul, mul_smul] } map_add' := fun _ _ => by rw [map_add] map_smul' := fun s z => by let m1 : Module R S := Module.compHom S f let m2 : Module R Y := Module.compHom Y f induction z using TensorProduct.induction_on with | zero => rw [smul_zero, map_zero, smul_zero] | tmul s' y => rw [ExtendScalars.smul_tmul, LinearMap.coe_mk] erw [TensorProduct.lift.tmul, TensorProduct.lift.tmul] set s' : S := s' change (s * s') • y = s • s' • y rw [mul_smul] | add _ _ ih1 ih2 => rw [smul_add, map_add, map_add, ih1, ih2, smul_add] } /-- The natural transformation from the composition of restriction and extension of scalars to the identity functor on `S`-module. -/ @[simps app] def counit : restrictScalars.{max v u₂,u₁,u₂} f ⋙ extendScalars f ⟶ 𝟭 (ModuleCat S) where app _ := Counit.map.{u₁,u₂,v} f naturality Y Y' g := by -- Porting note: this is very annoying; fix instances in concrete categories letI m1 : Module R S := Module.compHom S f letI m2 : Module R Y := Module.compHom Y f letI m2 : Module R Y' := Module.compHom Y' f ext z induction z using TensorProduct.induction_on with | zero => rw [map_zero, map_zero] | tmul s' y => dsimp -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [Counit.map_hom_apply] rw [lift.tmul, LinearMap.coe_mk, LinearMap.coe_mk] set s' : S := s' change s' • g y = g (s' • y) rw [map_smul] | add _ _ ih₁ ih₂ => rw [map_add, map_add]; congr 1 end ExtendRestrictScalarsAdj /-- Given commutative rings `R, S` and a ring hom `f : R →+* S`, the extension and restriction of scalars by `f` are adjoint to each other. -/ def extendRestrictScalarsAdj {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) : extendScalars.{u₁,u₂,max v u₂} f ⊣ restrictScalars.{max v u₂,u₁,u₂} f := Adjunction.mk' { homEquiv := fun _ _ ↦ ExtendRestrictScalarsAdj.homEquiv.{v,u₁,u₂} f unit := ExtendRestrictScalarsAdj.unit.{v,u₁,u₂} f counit := ExtendRestrictScalarsAdj.counit.{v,u₁,u₂} f homEquiv_unit := fun {X Y g} ↦ hom_ext <| LinearMap.ext fun x => by dsimp rfl homEquiv_counit := fun {X Y g} ↦ hom_ext <| LinearMap.ext fun x => by induction x using TensorProduct.induction_on with | zero => rw [map_zero, map_zero] | tmul => rw [ExtendRestrictScalarsAdj.homEquiv_symm_apply] dsimp -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [ExtendRestrictScalarsAdj.Counit.map_hom_apply, ExtendRestrictScalarsAdj.HomEquiv.fromExtendScalars_hom_apply] | add => rw [map_add, map_add]; congr 1 } lemma extendRestrictScalarsAdj_homEquiv_apply {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] {f : R →+* S} {M : ModuleCat.{max v u₂} R} {N : ModuleCat S} (φ : (extendScalars f).obj M ⟶ N) (m : M) : (extendRestrictScalarsAdj f).homEquiv _ _ φ m = φ ((1 : S) ⊗ₜ m) := rfl lemma extendRestrictScalarsAdj_unit_app_apply {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) (M : ModuleCat.{max v u₂} R) (m : M) : (extendRestrictScalarsAdj f).unit.app M m = (1 : S) ⊗ₜ[R,f] m := rfl instance {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) : (extendScalars.{u₁, u₂, max u₂ w} f).IsLeftAdjoint := (extendRestrictScalarsAdj f).isLeftAdjoint instance {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] (f : R →+* S) : (restrictScalars.{max u₂ w, u₁, u₂} f).IsRightAdjoint := (extendRestrictScalarsAdj f).isRightAdjoint noncomputable instance preservesLimit_restrictScalars {R : Type*} {S : Type*} [Ring R] [Ring S] (f : R →+* S) {J : Type*} [Category J] (F : J ⥤ ModuleCat.{v} S) [Small.{v} (F ⋙ forget _).sections] : PreservesLimit F (restrictScalars f) := ⟨fun {c} hc => ⟨by have hc' := isLimitOfPreserves (forget₂ _ AddCommGrp) hc exact isLimitOfReflects (forget₂ _ AddCommGrp) hc'⟩⟩ instance preservesColimit_restrictScalars {R S : Type*} [Ring R] [Ring S] (f : R →+* S) {J : Type*} [Category J] (F : J ⥤ ModuleCat.{v} S) [HasColimit (F ⋙ forget₂ _ AddCommGrp)] : PreservesColimit F (ModuleCat.restrictScalars.{v} f) := by have : HasColimit ((F ⋙ restrictScalars f) ⋙ forget₂ (ModuleCat R) AddCommGrp) := inferInstanceAs (HasColimit (F ⋙ forget₂ _ AddCommGrp)) apply preservesColimit_of_preserves_colimit_cocone (HasColimit.isColimitColimitCocone F) apply isColimitOfReflects (forget₂ _ AddCommGrp) apply isColimitOfPreserves (forget₂ (ModuleCat.{v} S) AddCommGrp.{v}) exact HasColimit.isColimitColimitCocone F variable (R) in /-- The extension of scalars by the identity of a ring is isomorphic to the identity functor. -/ noncomputable def extendScalarsId : extendScalars (RingHom.id R) ≅ 𝟭 _ := ((conjugateIsoEquiv (extendRestrictScalarsAdj (RingHom.id R)) Adjunction.id).symm (restrictScalarsId R)).symm lemma extendScalarsId_inv_app_apply (M : ModuleCat R) (m : M) : (extendScalarsId R).inv.app M m = (1 : R) ⊗ₜ m := rfl lemma homEquiv_extendScalarsId (M : ModuleCat R) : (extendRestrictScalarsAdj (RingHom.id R)).homEquiv _ _ ((extendScalarsId R).hom.app M) = (restrictScalarsId R).inv.app M := by ext m rw [extendRestrictScalarsAdj_homEquiv_apply, ← extendScalarsId_inv_app_apply, ← comp_apply] simp lemma extendScalarsId_hom_app_one_tmul (M : ModuleCat R) (m : M) : (extendScalarsId R).hom.app M ((1 : R) ⊗ₜ m) = m := by rw [← extendRestrictScalarsAdj_homEquiv_apply, homEquiv_extendScalarsId] dsimp section variable {R₁ R₂ R₃ R₄ : Type u₁} [CommRing R₁] [CommRing R₂] [CommRing R₃] [CommRing R₄] (f₁₂ : R₁ →+* R₂) (f₂₃ : R₂ →+* R₃) (f₃₄ : R₃ →+* R₄) /-- The extension of scalars by a composition of commutative ring morphisms identifies to the composition of the extension of scalars functors. -/ noncomputable def extendScalarsComp : extendScalars (f₂₃.comp f₁₂) ≅ extendScalars f₁₂ ⋙ extendScalars f₂₃ := (conjugateIsoEquiv ((extendRestrictScalarsAdj f₁₂).comp (extendRestrictScalarsAdj f₂₃)) (extendRestrictScalarsAdj (f₂₃.comp f₁₂))).symm (restrictScalarsComp f₁₂ f₂₃).symm lemma homEquiv_extendScalarsComp (M : ModuleCat R₁) : (extendRestrictScalarsAdj (f₂₃.comp f₁₂)).homEquiv _ _ ((extendScalarsComp f₁₂ f₂₃).hom.app M) = (extendRestrictScalarsAdj f₁₂).unit.app M ≫ (restrictScalars f₁₂).map ((extendRestrictScalarsAdj f₂₃).unit.app _) ≫ (restrictScalarsComp f₁₂ f₂₃).inv.app _ := by dsimp [extendScalarsComp, conjugateIsoEquiv, conjugateEquiv] simp only [Category.assoc, Category.id_comp, Category.comp_id, Adjunction.comp_unit_app, Adjunction.homEquiv_unit, Functor.map_comp, Adjunction.unit_naturality_assoc, Adjunction.right_triangle_components] rfl lemma extendScalarsComp_hom_app_one_tmul (M : ModuleCat R₁) (m : M) : (extendScalarsComp f₁₂ f₂₃).hom.app M ((1 : R₃) ⊗ₜ m) = (1 : R₃) ⊗ₜ[R₂,f₂₃] ((1 : R₂) ⊗ₜ[R₁,f₁₂] m) := by rw [← extendRestrictScalarsAdj_homEquiv_apply, homEquiv_extendScalarsComp] rfl @[reassoc] lemma extendScalars_assoc : (extendScalarsComp (f₂₃.comp f₁₂) f₃₄).hom ≫ Functor.whiskerRight (extendScalarsComp f₁₂ f₂₃).hom _ = (extendScalarsComp f₁₂ (f₃₄.comp f₂₃)).hom ≫ Functor.whiskerLeft _ (extendScalarsComp f₂₃ f₃₄).hom ≫ (Functor.associator _ _ _).inv := by ext M m have h₁ := extendScalarsComp_hom_app_one_tmul (f₂₃.comp f₁₂) f₃₄ M m have h₂ := extendScalarsComp_hom_app_one_tmul f₁₂ (f₃₄.comp f₂₃) M m have h₃ := extendScalarsComp_hom_app_one_tmul f₂₃ f₃₄ have h₄ := extendScalarsComp_hom_app_one_tmul f₁₂ f₂₃ M m dsimp at h₁ h₂ h₃ h₄ ⊢ rw [h₁] erw [h₂] rw [h₃, ExtendScalars.map_tmul, h₄] /-- The associativity compatibility for the extension of scalars, in the exact form that is needed in the definition `CommRingCat.moduleCatExtendScalarsPseudofunctor` in the file `Algebra.Category.ModuleCat.Pseudofunctor` -/ lemma extendScalars_assoc' : (extendScalarsComp (f₂₃.comp f₁₂) f₃₄).hom ≫ Functor.whiskerRight (extendScalarsComp f₁₂ f₂₃).hom _ ≫ (Functor.associator _ _ _).hom ≫ Functor.whiskerLeft _ (extendScalarsComp f₂₃ f₃₄).inv ≫ (extendScalarsComp f₁₂ (f₃₄.comp f₂₃)).inv = 𝟙 _ := by rw [extendScalars_assoc_assoc] simp only [Iso.inv_hom_id_assoc, ← Functor.whiskerLeft_comp_assoc, Iso.hom_inv_id, Functor.whiskerLeft_id', Category.id_comp] @[reassoc] lemma extendScalars_id_comp : (extendScalarsComp (RingHom.id R₁) f₁₂).hom ≫ Functor.whiskerRight (extendScalarsId R₁).hom _ ≫ (Functor.leftUnitor _).hom = 𝟙 _ := by ext M m dsimp erw [extendScalarsComp_hom_app_one_tmul (RingHom.id R₁) f₁₂ M m] rw [ExtendScalars.map_tmul] erw [extendScalarsId_hom_app_one_tmul] rfl @[reassoc] lemma extendScalars_comp_id : (extendScalarsComp f₁₂ (RingHom.id R₂)).hom ≫ Functor.whiskerLeft _ (extendScalarsId R₂).hom ≫ (Functor.rightUnitor _).hom = 𝟙 _ := by ext M m dsimp erw [extendScalarsComp_hom_app_one_tmul f₁₂ (RingHom.id R₂) M m, extendScalarsId_hom_app_one_tmul] rfl end end ModuleCat end ModuleCat
Image.lean
/- Copyright (c) 2023 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Yaël Dillies -/ import Mathlib.Order.Interval.Set.Basic import Mathlib.Data.Set.Function import Mathlib.Order.Directed /-! # Monotone functions on intervals This file shows many variants of the fact that a monotone function `f` sends an interval with endpoints `a` and `b` to the interval with endpoints `f a` and `f b`. -/ variable {α β : Type*} {f : α → β} open Set section Preorder variable [Preorder α] [Preorder β] {a b : α} lemma MonotoneOn.mapsTo_Ici (h : MonotoneOn f (Ici a)) : MapsTo f (Ici a) (Ici (f a)) := fun _ _ ↦ by aesop lemma MonotoneOn.mapsTo_Iic (h : MonotoneOn f (Iic b)) : MapsTo f (Iic b) (Iic (f b)) := fun _ _ ↦ by aesop lemma MonotoneOn.mapsTo_Icc (h : MonotoneOn f (Icc a b)) : MapsTo f (Icc a b) (Icc (f a) (f b)) := fun _c hc ↦ ⟨h (left_mem_Icc.2 <| hc.1.trans hc.2) hc hc.1, h hc (right_mem_Icc.2 <| hc.1.trans hc.2) hc.2⟩ lemma AntitoneOn.mapsTo_Ici (h : AntitoneOn f (Ici a)) : MapsTo f (Ici a) (Iic (f a)) := fun _ _ ↦ by aesop lemma AntitoneOn.mapsTo_Iic (h : AntitoneOn f (Iic b)) : MapsTo f (Iic b) (Ici (f b)) := fun _ _ ↦ by aesop lemma AntitoneOn.mapsTo_Icc (h : AntitoneOn f (Icc a b)) : MapsTo f (Icc a b) (Icc (f b) (f a)) := fun _c hc ↦ ⟨h hc (right_mem_Icc.2 <| hc.1.trans hc.2) hc.2, h (left_mem_Icc.2 <| hc.1.trans hc.2) hc hc.1⟩ lemma StrictMonoOn.mapsTo_Ioi (h : StrictMonoOn f (Ici a)) : MapsTo f (Ioi a) (Ioi (f a)) := fun _c hc ↦ h le_rfl hc.le hc lemma StrictMonoOn.mapsTo_Iio (h : StrictMonoOn f (Iic b)) : MapsTo f (Iio b) (Iio (f b)) := fun _c hc ↦ h hc.le le_rfl hc lemma StrictMonoOn.mapsTo_Ioo (h : StrictMonoOn f (Icc a b)) : MapsTo f (Ioo a b) (Ioo (f a) (f b)) := fun _c hc ↦ ⟨h (left_mem_Icc.2 (hc.1.trans hc.2).le) (Ioo_subset_Icc_self hc) hc.1, h (Ioo_subset_Icc_self hc) (right_mem_Icc.2 (hc.1.trans hc.2).le) hc.2⟩ lemma StrictAntiOn.mapsTo_Ioi (h : StrictAntiOn f (Ici a)) : MapsTo f (Ioi a) (Iio (f a)) := fun _c hc ↦ h le_rfl hc.le hc lemma StrictAntiOn.mapsTo_Iio (h : StrictAntiOn f (Iic b)) : MapsTo f (Iio b) (Ioi (f b)) := fun _c hc ↦ h hc.le le_rfl hc lemma StrictAntiOn.mapsTo_Ioo (h : StrictAntiOn f (Icc a b)) : MapsTo f (Ioo a b) (Ioo (f b) (f a)) := fun _c hc ↦ ⟨h (Ioo_subset_Icc_self hc) (right_mem_Icc.2 (hc.1.trans hc.2).le) hc.2, h (left_mem_Icc.2 (hc.1.trans hc.2).le) (Ioo_subset_Icc_self hc) hc.1⟩ lemma Monotone.mapsTo_Ici (h : Monotone f) : MapsTo f (Ici a) (Ici (f a)) := (h.monotoneOn _).mapsTo_Ici lemma Monotone.mapsTo_Iic (h : Monotone f) : MapsTo f (Iic b) (Iic (f b)) := (h.monotoneOn _).mapsTo_Iic lemma Monotone.mapsTo_Icc (h : Monotone f) : MapsTo f (Icc a b) (Icc (f a) (f b)) := (h.monotoneOn _).mapsTo_Icc lemma Antitone.mapsTo_Ici (h : Antitone f) : MapsTo f (Ici a) (Iic (f a)) := (h.antitoneOn _).mapsTo_Ici lemma Antitone.mapsTo_Iic (h : Antitone f) : MapsTo f (Iic b) (Ici (f b)) := (h.antitoneOn _).mapsTo_Iic lemma Antitone.mapsTo_Icc (h : Antitone f) : MapsTo f (Icc a b) (Icc (f b) (f a)) := (h.antitoneOn _).mapsTo_Icc lemma StrictMono.mapsTo_Ioi (h : StrictMono f) : MapsTo f (Ioi a) (Ioi (f a)) := (h.strictMonoOn _).mapsTo_Ioi lemma StrictMono.mapsTo_Iio (h : StrictMono f) : MapsTo f (Iio b) (Iio (f b)) := (h.strictMonoOn _).mapsTo_Iio lemma StrictMono.mapsTo_Ioo (h : StrictMono f) : MapsTo f (Ioo a b) (Ioo (f a) (f b)) := (h.strictMonoOn _).mapsTo_Ioo lemma StrictAnti.mapsTo_Ioi (h : StrictAnti f) : MapsTo f (Ioi a) (Iio (f a)) := (h.strictAntiOn _).mapsTo_Ioi lemma StrictAnti.mapsTo_Iio (h : StrictAnti f) : MapsTo f (Iio b) (Ioi (f b)) := (h.strictAntiOn _).mapsTo_Iio lemma StrictAnti.mapsTo_Ioo (h : StrictAnti f) : MapsTo f (Ioo a b) (Ioo (f b) (f a)) := (h.strictAntiOn _).mapsTo_Ioo lemma MonotoneOn.image_Ici_subset (h : MonotoneOn f (Ici a)) : f '' Ici a ⊆ Ici (f a) := h.mapsTo_Ici.image_subset lemma MonotoneOn.image_Iic_subset (h : MonotoneOn f (Iic b)) : f '' Iic b ⊆ Iic (f b) := h.mapsTo_Iic.image_subset lemma MonotoneOn.image_Icc_subset (h : MonotoneOn f (Icc a b)) : f '' Icc a b ⊆ Icc (f a) (f b) := h.mapsTo_Icc.image_subset lemma AntitoneOn.image_Ici_subset (h : AntitoneOn f (Ici a)) : f '' Ici a ⊆ Iic (f a) := h.mapsTo_Ici.image_subset lemma AntitoneOn.image_Iic_subset (h : AntitoneOn f (Iic b)) : f '' Iic b ⊆ Ici (f b) := h.mapsTo_Iic.image_subset lemma AntitoneOn.image_Icc_subset (h : AntitoneOn f (Icc a b)) : f '' Icc a b ⊆ Icc (f b) (f a) := h.mapsTo_Icc.image_subset lemma StrictMonoOn.image_Ioi_subset (h : StrictMonoOn f (Ici a)) : f '' Ioi a ⊆ Ioi (f a) := h.mapsTo_Ioi.image_subset lemma StrictMonoOn.image_Iio_subset (h : StrictMonoOn f (Iic b)) : f '' Iio b ⊆ Iio (f b) := h.mapsTo_Iio.image_subset lemma StrictMonoOn.image_Ioo_subset (h : StrictMonoOn f (Icc a b)) : f '' Ioo a b ⊆ Ioo (f a) (f b) := h.mapsTo_Ioo.image_subset lemma StrictAntiOn.image_Ioi_subset (h : StrictAntiOn f (Ici a)) : f '' Ioi a ⊆ Iio (f a) := h.mapsTo_Ioi.image_subset lemma StrictAntiOn.image_Iio_subset (h : StrictAntiOn f (Iic b)) : f '' Iio b ⊆ Ioi (f b) := h.mapsTo_Iio.image_subset lemma StrictAntiOn.image_Ioo_subset (h : StrictAntiOn f (Icc a b)) : f '' Ioo a b ⊆ Ioo (f b) (f a) := h.mapsTo_Ioo.image_subset lemma Monotone.image_Ici_subset (h : Monotone f) : f '' Ici a ⊆ Ici (f a) := (h.monotoneOn _).image_Ici_subset lemma Monotone.image_Iic_subset (h : Monotone f) : f '' Iic b ⊆ Iic (f b) := (h.monotoneOn _).image_Iic_subset lemma Monotone.image_Icc_subset (h : Monotone f) : f '' Icc a b ⊆ Icc (f a) (f b) := (h.monotoneOn _).image_Icc_subset lemma Antitone.image_Ici_subset (h : Antitone f) : f '' Ici a ⊆ Iic (f a) := (h.antitoneOn _).image_Ici_subset lemma Antitone.image_Iic_subset (h : Antitone f) : f '' Iic b ⊆ Ici (f b) := (h.antitoneOn _).image_Iic_subset lemma Antitone.image_Icc_subset (h : Antitone f) : f '' Icc a b ⊆ Icc (f b) (f a) := (h.antitoneOn _).image_Icc_subset lemma StrictMono.image_Ioi_subset (h : StrictMono f) : f '' Ioi a ⊆ Ioi (f a) := (h.strictMonoOn _).image_Ioi_subset lemma StrictMono.image_Iio_subset (h : StrictMono f) : f '' Iio b ⊆ Iio (f b) := (h.strictMonoOn _).image_Iio_subset lemma StrictMono.image_Ioo_subset (h : StrictMono f) : f '' Ioo a b ⊆ Ioo (f a) (f b) := (h.strictMonoOn _).image_Ioo_subset lemma StrictAnti.image_Ioi_subset (h : StrictAnti f) : f '' Ioi a ⊆ Iio (f a) := (h.strictAntiOn _).image_Ioi_subset lemma StrictAnti.image_Iio_subset (h : StrictAnti f) : f '' Iio b ⊆ Ioi (f b) := (h.strictAntiOn _).image_Iio_subset lemma StrictAnti.image_Ioo_subset (h : StrictAnti f) : f '' Ioo a b ⊆ Ioo (f b) (f a) := (h.strictAntiOn _).image_Ioo_subset end Preorder section PartialOrder variable [PartialOrder α] [Preorder β] {a b : α} lemma StrictMonoOn.mapsTo_Ico (h : StrictMonoOn f (Icc a b)) : MapsTo f (Ico a b) (Ico (f a) (f b)) := fun _c hc ↦ ⟨h.monotoneOn (left_mem_Icc.2 <| hc.1.trans hc.2.le) (Ico_subset_Icc_self hc) hc.1, h (Ico_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.trans hc.2.le) hc.2⟩ lemma StrictMonoOn.mapsTo_Ioc (h : StrictMonoOn f (Icc a b)) : MapsTo f (Ioc a b) (Ioc (f a) (f b)) := fun _c hc ↦ ⟨h (left_mem_Icc.2 <| hc.1.le.trans hc.2) (Ioc_subset_Icc_self hc) hc.1, h.monotoneOn (Ioc_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.le.trans hc.2) hc.2⟩ lemma StrictAntiOn.mapsTo_Ico (h : StrictAntiOn f (Icc a b)) : MapsTo f (Ico a b) (Ioc (f b) (f a)) := fun _c hc ↦ ⟨h (Ico_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.trans hc.2.le) hc.2, h.antitoneOn (left_mem_Icc.2 <| hc.1.trans hc.2.le) (Ico_subset_Icc_self hc) hc.1⟩ lemma StrictAntiOn.mapsTo_Ioc (h : StrictAntiOn f (Icc a b)) : MapsTo f (Ioc a b) (Ico (f b) (f a)) := fun _c hc ↦ ⟨h.antitoneOn (Ioc_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.le.trans hc.2) hc.2, h (left_mem_Icc.2 <| hc.1.le.trans hc.2) (Ioc_subset_Icc_self hc) hc.1⟩ lemma StrictMono.mapsTo_Ico (h : StrictMono f) : MapsTo f (Ico a b) (Ico (f a) (f b)) := (h.strictMonoOn _).mapsTo_Ico lemma StrictMono.mapsTo_Ioc (h : StrictMono f) : MapsTo f (Ioc a b) (Ioc (f a) (f b)) := (h.strictMonoOn _).mapsTo_Ioc lemma StrictAnti.mapsTo_Ico (h : StrictAnti f) : MapsTo f (Ico a b) (Ioc (f b) (f a)) := (h.strictAntiOn _).mapsTo_Ico lemma StrictAnti.mapsTo_Ioc (h : StrictAnti f) : MapsTo f (Ioc a b) (Ico (f b) (f a)) := (h.strictAntiOn _).mapsTo_Ioc lemma StrictMonoOn.image_Ico_subset (h : StrictMonoOn f (Icc a b)) : f '' Ico a b ⊆ Ico (f a) (f b) := h.mapsTo_Ico.image_subset lemma StrictMonoOn.image_Ioc_subset (h : StrictMonoOn f (Icc a b)) : f '' Ioc a b ⊆ Ioc (f a) (f b) := h.mapsTo_Ioc.image_subset lemma StrictAntiOn.image_Ico_subset (h : StrictAntiOn f (Icc a b)) : f '' Ico a b ⊆ Ioc (f b) (f a) := h.mapsTo_Ico.image_subset lemma StrictAntiOn.image_Ioc_subset (h : StrictAntiOn f (Icc a b)) : f '' Ioc a b ⊆ Ico (f b) (f a) := h.mapsTo_Ioc.image_subset lemma StrictMono.image_Ico_subset (h : StrictMono f) : f '' Ico a b ⊆ Ico (f a) (f b) := (h.strictMonoOn _).image_Ico_subset lemma StrictMono.image_Ioc_subset (h : StrictMono f) : f '' Ioc a b ⊆ Ioc (f a) (f b) := (h.strictMonoOn _).image_Ioc_subset lemma StrictAnti.image_Ico_subset (h : StrictAnti f) : f '' Ico a b ⊆ Ioc (f b) (f a) := (h.strictAntiOn _).image_Ico_subset lemma StrictAnti.image_Ioc_subset (h : StrictAnti f) : f '' Ioc a b ⊆ Ico (f b) (f a) := (h.strictAntiOn _).image_Ioc_subset end PartialOrder namespace Set private lemma image_subtype_val_Ixx_Ixi {p q r : α → α → Prop} {a b : α} (c : {x // p a x ∧ q x b}) (h : ∀ {x}, r c x → p a x) : Subtype.val '' {y : {x // p a x ∧ q x b} | r c.1 y.1} = {y : α | r c.1 y ∧ q y b} := (Subtype.image_preimage_val {x | p a x ∧ q x b} {y | r c.1 y}).trans <| by ext; simp +contextual [@and_comm (r _ _), h] private lemma image_subtype_val_Ixx_Iix {p q r : α → α → Prop} {a b : α} (c : {x // p a x ∧ q x b}) (h : ∀ {x}, r x c → q x b) : Subtype.val '' {y : {x // p a x ∧ q x b} | r y.1 c.1} = {y : α | p a y ∧ r y c.1} := (Subtype.image_preimage_val {x | p a x ∧ q x b} {y | r y c.1}).trans <| by ext; simp +contextual [h] variable [Preorder α] {p : α → Prop} @[simp] lemma preimage_subtype_val_Ici (a : {x // p x}) : (↑) ⁻¹' (Ici a.1) = Ici a := rfl @[simp] lemma preimage_subtype_val_Iic (a : {x // p x}) : (↑) ⁻¹' (Iic a.1) = Iic a := rfl @[simp] lemma preimage_subtype_val_Ioi (a : {x // p x}) : (↑) ⁻¹' (Ioi a.1) = Ioi a := rfl @[simp] lemma preimage_subtype_val_Iio (a : {x // p x}) : (↑) ⁻¹' (Iio a.1) = Iio a := rfl @[simp] lemma preimage_subtype_val_Icc (a b : {x // p x}) : (↑) ⁻¹' (Icc a.1 b) = Icc a b := rfl @[simp] lemma preimage_subtype_val_Ico (a b : {x // p x}) : (↑) ⁻¹' (Ico a.1 b) = Ico a b := rfl @[simp] lemma preimage_subtype_val_Ioc (a b : {x // p x}) : (↑) ⁻¹' (Ioc a.1 b) = Ioc a b := rfl @[simp] lemma preimage_subtype_val_Ioo (a b : {x // p x}) : (↑) ⁻¹' (Ioo a.1 b) = Ioo a b := rfl theorem image_subtype_val_Icc_subset (a b : {x // p x}) : Subtype.val '' Icc a b ⊆ Icc a.val b.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ico_subset (a b : {x // p x}) : Subtype.val '' Ico a b ⊆ Ico a.val b.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ioc_subset (a b : {x // p x}) : Subtype.val '' Ioc a b ⊆ Ioc a.val b.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ioo_subset (a b : {x // p x}) : Subtype.val '' Ioo a b ⊆ Ioo a.val b.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Iic_subset (a : {x // p x}) : Subtype.val '' Iic a ⊆ Iic a.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Iio_subset (a : {x // p x}) : Subtype.val '' Iio a ⊆ Iio a.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ici_subset (a : {x // p x}) : Subtype.val '' Ici a ⊆ Ici a.val := image_subset_iff.mpr fun _ m => m theorem image_subtype_val_Ioi_subset (a : {x // p x}) : Subtype.val '' Ioi a ⊆ Ioi a.val := image_subset_iff.mpr fun _ m => m @[simp] lemma image_subtype_val_Ici_Iic {a : α} (b : Ici a) : Subtype.val '' Iic b = Icc a b := (Subtype.image_preimage_val (Ici a) (Iic b.1)).trans Ici_inter_Iic @[simp] lemma image_subtype_val_Ici_Iio {a : α} (b : Ici a) : Subtype.val '' Iio b = Ico a b := (Subtype.image_preimage_val (Ici a) (Iio b.1)).trans Ici_inter_Iio @[simp] lemma image_subtype_val_Ici_Ici {a : α} (b : Ici a) : Subtype.val '' Ici b = Ici b.1 := (Subtype.image_preimage_val (Ici a) (Ici b.1)).trans <| inter_eq_right.2 <| Ici_subset_Ici.2 b.2 @[simp] lemma image_subtype_val_Ici_Ioi {a : α} (b : Ici a) : Subtype.val '' Ioi b = Ioi b.1 := (Subtype.image_preimage_val (Ici a) (Ioi b.1)).trans <| inter_eq_right.2 <| Ioi_subset_Ici b.2 @[simp] lemma image_subtype_val_Iic_Ici {a : α} (b : Iic a) : Subtype.val '' Ici b = Icc b.1 a := (Subtype.image_preimage_val _ _).trans <| inter_comm _ _ @[simp] lemma image_subtype_val_Iic_Ioi {a : α} (b : Iic a) : Subtype.val '' Ioi b = Ioc b.1 a := (Subtype.image_preimage_val _ _).trans <| inter_comm _ _ @[simp] lemma image_subtype_val_Iic_Iic {a : α} (b : Iic a) : Subtype.val '' Iic b = Iic b.1 := image_subtype_val_Ici_Ici (α := αᵒᵈ) _ @[simp] lemma image_subtype_val_Iic_Iio {a : α} (b : Iic a) : Subtype.val '' Iio b = Iio b.1 := image_subtype_val_Ici_Ioi (α := αᵒᵈ) _ @[simp] lemma image_subtype_val_Ioi_Ici {a : α} (b : Ioi a) : Subtype.val '' Ici b = Ici b.1 := (Subtype.image_preimage_val (Ioi a) (Ici b.1)).trans <| inter_eq_right.2 <| Ici_subset_Ioi.2 b.2 @[simp] lemma image_subtype_val_Ioi_Iic {a : α} (b : Ioi a) : Subtype.val '' Iic b = Ioc a b := (Subtype.image_preimage_val (Ioi a) (Iic b.1)).trans Ioi_inter_Iic @[simp] lemma image_subtype_val_Ioi_Ioi {a : α} (b : Ioi a) : Subtype.val '' Ioi b = Ioi b.1 := (Subtype.image_preimage_val (Ioi a) (Ioi b.1)).trans <| inter_eq_right.2 <| Ioi_subset_Ioi b.2.le @[simp] lemma image_subtype_val_Ioi_Iio {a : α} (b : Ioi a) : Subtype.val '' Iio b = Ioo a b := (Subtype.image_preimage_val (Ioi a) (Iio b.1)).trans Ioi_inter_Iio @[simp] lemma image_subtype_val_Iio_Ici {a : α} (b : Iio a) : Subtype.val '' Ici b = Ico b.1 a := (Subtype.image_preimage_val _ _).trans <| inter_comm _ _ @[simp] lemma image_subtype_val_Iio_Iic {a : α} (b : Iio a) : Subtype.val '' Iic b = Iic b.1 := image_subtype_val_Ioi_Ici (α := αᵒᵈ) _ @[simp] lemma image_subtype_val_Iio_Ioi {a : α} (b : Iio a) : Subtype.val '' Ioi b = Ioo b.1 a := (Subtype.image_preimage_val _ _).trans <| inter_comm _ _ @[simp] lemma image_subtype_val_Iio_Iio {a : α} (b : Iio a) : Subtype.val '' Iio b = Iio b.1 := image_subtype_val_Ioi_Ioi (α := αᵒᵈ) _ @[simp] lemma image_subtype_val_Icc_Ici {a b : α} (c : Icc a b) : Subtype.val '' Ici c = Icc c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans @[simp] lemma image_subtype_val_Icc_Iic {a b : α} (c : Icc a b) : Subtype.val '' Iic c = Icc a c := image_subtype_val_Ixx_Iix c (le_trans · c.2.2) @[simp] lemma image_subtype_val_Icc_Ioi {a b : α} (c : Icc a b) : Subtype.val '' Ioi c = Ioc c.1 b := image_subtype_val_Ixx_Ixi c (c.2.1.trans <| le_of_lt ·) @[simp] lemma image_subtype_val_Icc_Iio {a b : α} (c : Icc a b) : Subtype.val '' Iio c = Ico a c := image_subtype_val_Ixx_Iix c fun h ↦ (le_of_lt h).trans c.2.2 @[simp] lemma image_subtype_val_Ico_Ici {a b : α} (c : Ico a b) : Subtype.val '' Ici c = Ico c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans @[simp] lemma image_subtype_val_Ico_Iic {a b : α} (c : Ico a b) : Subtype.val '' Iic c = Icc a c := image_subtype_val_Ixx_Iix c (lt_of_le_of_lt · c.2.2) @[simp] lemma image_subtype_val_Ico_Ioi {a b : α} (c : Ico a b) : Subtype.val '' Ioi c = Ioo c.1 b := image_subtype_val_Ixx_Ixi c (c.2.1.trans <| le_of_lt ·) @[simp] lemma image_subtype_val_Ico_Iio {a b : α} (c : Ico a b) : Subtype.val '' Iio c = Ico a c := image_subtype_val_Ixx_Iix c (lt_trans · c.2.2) @[simp] lemma image_subtype_val_Ioc_Ici {a b : α} (c : Ioc a b) : Subtype.val '' Ici c = Icc c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans_le @[simp] lemma image_subtype_val_Ioc_Iic {a b : α} (c : Ioc a b) : Subtype.val '' Iic c = Ioc a c := image_subtype_val_Ixx_Iix c (le_trans · c.2.2) @[simp] lemma image_subtype_val_Ioc_Ioi {a b : α} (c : Ioc a b) : Subtype.val '' Ioi c = Ioc c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans @[simp] lemma image_subtype_val_Ioc_Iio {a b : α} (c : Ioc a b) : Subtype.val '' Iio c = Ioo a c := image_subtype_val_Ixx_Iix c fun h ↦ (le_of_lt h).trans c.2.2 @[simp] lemma image_subtype_val_Ioo_Ici {a b : α} (c : Ioo a b) : Subtype.val '' Ici c = Ico c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans_le @[simp] lemma image_subtype_val_Ioo_Iic {a b : α} (c : Ioo a b) : Subtype.val '' Iic c = Ioc a c := image_subtype_val_Ixx_Iix c (lt_of_le_of_lt · c.2.2) @[simp] lemma image_subtype_val_Ioo_Ioi {a b : α} (c : Ioo a b) : Subtype.val '' Ioi c = Ioo c.1 b := image_subtype_val_Ixx_Ixi c c.2.1.trans @[simp] lemma image_subtype_val_Ioo_Iio {a b : α} (c : Ioo a b) : Subtype.val '' Iio c = Ioo a c := image_subtype_val_Ixx_Iix c (lt_trans · c.2.2) end Set section Preorder variable [Preorder α] lemma directedOn_le_Iic (b : α) : DirectedOn (· ≤ ·) (Iic b) := fun _x hx _y hy ↦ ⟨b, le_rfl, hx, hy⟩ lemma directedOn_le_Icc (a b : α) : DirectedOn (· ≤ ·) (Icc a b) := fun _x hx _y hy ↦ ⟨b, right_mem_Icc.2 <| hx.1.trans hx.2, hx.2, hy.2⟩ lemma directedOn_le_Ioc (a b : α) : DirectedOn (· ≤ ·) (Ioc a b) := fun _x hx _y hy ↦ ⟨b, right_mem_Ioc.2 <| hx.1.trans_le hx.2, hx.2, hy.2⟩ lemma directedOn_ge_Ici (a : α) : DirectedOn (· ≥ ·) (Ici a) := fun _x hx _y hy ↦ ⟨a, le_rfl, hx, hy⟩ lemma directedOn_ge_Icc (a b : α) : DirectedOn (· ≥ ·) (Icc a b) := fun _x hx _y hy ↦ ⟨a, left_mem_Icc.2 <| hx.1.trans hx.2, hx.1, hy.1⟩ lemma directedOn_ge_Ico (a b : α) : DirectedOn (· ≥ ·) (Ico a b) := fun _x hx _y hy ↦ ⟨a, left_mem_Ico.2 <| hx.1.trans_lt hx.2, hx.1, hy.1⟩ end Preorder
zmodp.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool choice eqtype ssrnat seq. From mathcomp Require Import div fintype bigop finset prime fingroup perm. From mathcomp Require Import ssralg finalg countalg. (******************************************************************************) (* Definition of the additive group and ring Zp, represented as 'I_p *) (******************************************************************************) (* Definitions: *) (* From fintype.v: *) (* 'I_p == the subtype of integers less than p, taken here as the type of *) (* the integers mod p. *) (* This file: *) (* inZp == the natural projection from nat into the integers mod p, *) (* represented as 'I_p. Here p is implicit, but MUST be of the *) (* form n.+1. *) (* The operations: *) (* Zp0 == the identity element for addition *) (* Zp1 == the identity element for multiplication, and a generator of *) (* additive group *) (* Zp_opp == inverse function for addition *) (* Zp_add == addition *) (* Zp_mul == multiplication *) (* Zp_inv == inverse function for multiplication *) (* Note that while 'I_n.+1 has canonical finZmodType and finGroupType *) (* structures, only 'I_n.+2 has a canonical ring structure (it has, in fact, *) (* a canonical finComUnitRing structure), and hence an associated *) (* multiplicative unit finGroupType. To mitigate the issues caused by the *) (* trivial "ring" (which is, indeed is NOT a ring in the ssralg/finalg *) (* formalization), we define additional notation: *) (* 'Z_p == the type of integers mod (max p 2); this is always a proper *) (* ring, by constructions. Note that 'Z_p is provably equal to *) (* 'I_p if p > 1, and convertible to 'I_p if p is of the form *) (* n.+2. *) (* Zp p == the subgroup of integers mod (max p 1) in 'Z_p; this is thus *) (* all of 'Z_p if p > 1, and else the trivial group. *) (* units_Zp p == the group of all units of 'Z_p -- i.e., the group of *) (* (multiplicative) automorphisms of Zp p. *) (* We show that Zp and units_Zp are abelian, and compute their orders. *) (* We use a similar technique to represent the prime fields: *) (* 'F_p == the finite field of integers mod the first prime divisor of *) (* maxn p 2. This is provably equal to 'Z_p and 'I_p if p is *) (* provably prime, and indeed convertible to the above if p is *) (* a concrete prime such as 2, 5 or 23. *) (* Note finally that due to the canonical structures it is possible to use *) (* 0%R instead of Zp0, and 1%R instead of Zp1 (for the latter, p must be of *) (* the form n.+2, and 1%R : nat will simplify to 1%N). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Section ZpDef. (***********************************************************************) (* *) (* Mod p arithmetic on the finite set {0, 1, 2, ..., p - 1} *) (* *) (***********************************************************************) (* Operations on 'I_p without constraint on p. *) Section Generic. Variable p : nat. Implicit Types i j : 'I_p. Lemma Zp_opp_subproof i : (p - i) %% p < p. Proof. by case: p i => [[]//|k] i; apply/ltn_pmod. Qed. Definition Zp_opp i := Ordinal (Zp_opp_subproof i). Lemma Zp_add_subproof i j : (i + j) %% p < p. Proof. by case: p i j => [[]//|k] i j; apply/ltn_pmod. Qed. Definition Zp_add i j := Ordinal (Zp_add_subproof i j). Lemma Zp_mul_subproof i j : (i * j) %% p < p. Proof. by case: p i j => [[]//|k] i j; apply/ltn_pmod. Qed. Definition Zp_mul i j := Ordinal (Zp_mul_subproof i j). Lemma Zp_inv_subproof i : (egcdn i p).1 %% p < p. Proof. by case: p i => [[]//|k] i; apply/ltn_pmod. Qed. Definition Zp_inv i := if coprime p i then Ordinal (Zp_inv_subproof i) else i. Lemma Zp_addA : associative Zp_add. Proof. by move=> x y z; apply: val_inj; rewrite /= modnDml modnDmr addnA. Qed. Lemma Zp_addC : commutative Zp_add. Proof. by move=> x y; apply: val_inj; rewrite /= addnC. Qed. Lemma Zp_mulC : commutative Zp_mul. Proof. by move=> x y; apply: val_inj; rewrite /= mulnC. Qed. Lemma Zp_mulA : associative Zp_mul. Proof. by move=> x y z; apply: val_inj; rewrite /= modnMml modnMmr mulnA. Qed. Lemma Zp_mul_addr : right_distributive Zp_mul Zp_add. Proof. by move=> x y z; apply: val_inj; rewrite /= modnMmr modnDm mulnDr. Qed. Lemma Zp_mul_addl : left_distributive Zp_mul Zp_add. Proof. by move=> x y z; rewrite -!(Zp_mulC z) Zp_mul_addr. Qed. Lemma Zp_inv_out i : ~~ coprime p i -> Zp_inv i = i. Proof. by rewrite /Zp_inv => /negPf->. Qed. End Generic. Arguments Zp_opp {p}. Arguments Zp_add {p}. Arguments Zp_mul {p}. Arguments Zp_inv {p}. Variable p' : nat. Local Notation p := p'.+1. Implicit Types x y z : 'I_p. (* Standard injection; val (inZp i) = i %% p *) Definition inZp i := Ordinal (ltn_pmod i (ltn0Sn p')). Lemma modZp x : x %% p = x. Proof. by rewrite modn_small ?ltn_ord. Qed. Lemma valZpK x : inZp x = x. Proof. by apply: val_inj; rewrite /= modZp. Qed. (* Operations *) Definition Zp0 : 'I_p := ord0. Definition Zp1 := inZp 1. (* Additive group structure. *) Lemma Zp_add0z : left_id Zp0 Zp_add. Proof. by move=> x; apply: val_inj; rewrite /= modZp. Qed. Lemma Zp_addNz : left_inverse Zp0 Zp_opp Zp_add. Proof. by move=> x; apply: val_inj; rewrite /= modnDml subnK ?modnn // ltnW. Qed. HB.instance Definition _ := GRing.isZmodule.Build 'I_p (@Zp_addA _) (@Zp_addC _) Zp_add0z Zp_addNz. HB.instance Definition _ := [finGroupMixin of 'I_p for +%R]. (* Ring operations *) Lemma Zp_mul1z : left_id Zp1 Zp_mul. Proof. by move=> x; apply: val_inj; rewrite /= modnMml mul1n modZp. Qed. Lemma Zp_mulz1 : right_id Zp1 Zp_mul. Proof. by move=> x; rewrite Zp_mulC Zp_mul1z. Qed. Lemma Zp_mulVz x : coprime p x -> Zp_mul (Zp_inv x) x = Zp1. Proof. move=> co_p_x; apply: val_inj; rewrite /Zp_inv co_p_x /= modnMml. by rewrite -(chinese_modl co_p_x 1 0) /chinese addn0 mul1n mulnC. Qed. Lemma Zp_mulzV x : coprime p x -> Zp_mul x (Zp_inv x) = Zp1. Proof. by move=> Ux; rewrite /= Zp_mulC Zp_mulVz. Qed. Lemma Zp_intro_unit x y : Zp_mul y x = Zp1 -> coprime p x. Proof. case=> yx1; have:= coprimen1 p. by rewrite -coprime_modr -yx1 coprime_modr coprimeMr; case/andP. Qed. Lemma Zp_mulrn x n : x *+ n = inZp (x * n). Proof. apply: val_inj => /=; elim: n => [|n IHn]; first by rewrite muln0 modn_small. by rewrite !GRing.mulrS /= IHn modnDmr mulnS. Qed. Import GroupScope. Lemma Zp_mulgC : @commutative 'I_p _ mulg. Proof. exact: Zp_addC. Qed. Lemma Zp_abelian : abelian [set: 'I_p]. Proof. exact: FinRing.zmod_abelian. Qed. Lemma Zp_expg x n : x ^+ n = inZp (x * n). Proof. exact: Zp_mulrn. Qed. Lemma Zp1_expgz x : Zp1 ^+ x = x. Proof. rewrite Zp_expg; apply/val_inj. by move: (Zp_mul1z x) => /(congr1 val). Qed. Lemma Zp_cycle : setT = <[Zp1]>. Proof. by apply/setP=> x; rewrite -[x]Zp1_expgz inE groupX ?mem_gen ?set11. Qed. Lemma order_Zp1 : #[Zp1] = p. Proof. by rewrite orderE -Zp_cycle cardsT card_ord. Qed. End ZpDef. Arguments Zp0 {p'}. Arguments Zp1 {p'}. Arguments inZp {p'} i. Arguments valZpK {p'} x. (* We redefine fintype.ord1 to specialize it with 0 instead of ord0 *) (* since 'I_n is now canonically a zmodType *) Lemma ord1 : all_equal_to (0 : 'I_1). Proof. exact: ord1. Qed. Lemma lshift0 m n : lshift m (0 : 'I_n.+1) = (0 : 'I_(n + m).+1). Proof. exact: val_inj. Qed. Lemma rshift1 n : @rshift 1 n =1 lift (0 : 'I_n.+1). Proof. by move=> i; apply: val_inj. Qed. Lemma split1 n i : split (i : 'I_(1 + n)) = oapp (@inr _ _) (inl _ 0) (unlift 0 i). Proof. case: unliftP => [i'|] -> /=. by rewrite -rshift1 (unsplitK (inr _ _)). by rewrite -(lshift0 n 0) (unsplitK (inl _ _)). Qed. (* TODO: bigop is imported after zmodp in matrix.v and intdiv.v to prevent these warnings from triggering. We should restore the order of imports when these are removed. *) #[deprecated(since="mathcomp 2.3.0", note="Use bigop.big_ord1 instead.")] Notation big_ord1 := big_ord1 (only parsing). #[deprecated(since="mathcomp 2.3.0", note="Use bigop.big_ord1_cond instead.")] Notation big_ord1_cond := big_ord1_cond (only parsing). Section ZpNzRing. Variable p' : nat. Local Notation p := p'.+2. Lemma Zp_nontrivial : Zp1 != 0 :> 'I_p. Proof. by []. Qed. HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build 'I_p (@Zp_mulA _) (@Zp_mulC _) (@Zp_mul1z _) (@Zp_mul_addl _) Zp_nontrivial. HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build 'I_p (@Zp_mulVz _) (@Zp_intro_unit _) (@Zp_inv_out _). Lemma Zp_nat n : n%:R = inZp n :> 'I_p. Proof. by apply: val_inj; rewrite [n%:R]Zp_mulrn /= modnMml mul1n. Qed. Lemma natr_Zp (x : 'I_p) : x%:R = x. Proof. by rewrite Zp_nat valZpK. Qed. Lemma natr_negZp (x : 'I_p) : (- x)%:R = - x. Proof. by apply: val_inj; rewrite /= Zp_nat /= modn_mod. Qed. Import GroupScope. Lemma unit_Zp_mulgC : @commutative {unit 'I_p} _ mulg. Proof. by move=> u v; apply: val_inj; rewrite /= GRing.mulrC. Qed. Lemma unit_Zp_expg (u : {unit 'I_p}) n : val (u ^+ n) = inZp (val u ^ n) :> 'I_p. Proof. apply: val_inj => /=; elim: n => [|n IHn] //. by rewrite expgS /= IHn expnS modnMmr. Qed. End ZpNzRing. Definition Zp_trunc p := p.-2. Notation "''Z_' p" := 'I_(Zp_trunc p).+2 (at level 0, p at level 2, format "''Z_' p") : type_scope. Notation "''F_' p" := 'Z_(pdiv p) (at level 0, p at level 2, format "''F_' p") : type_scope. Arguments natr_Zp {p'} x. Section ZpNzRing. Import GRing.Theory. Lemma add_1_Zp p (x : 'Z_p) : 1 + x = ordS x. Proof. by case: p => [|[|p]] in x *; apply/val_inj. Qed. Lemma add_Zp_1 p (x : 'Z_p) : x + 1 = ordS x. Proof. by rewrite addrC add_1_Zp. Qed. Lemma sub_Zp_1 p (x : 'Z_p) : x - 1 = ord_pred x. Proof. by apply: (addIr 1); rewrite addrNK add_Zp_1 ord_predK. Qed. Lemma add_N1_Zp p (x : 'Z_p) : -1 + x = ord_pred x. Proof. by rewrite addrC sub_Zp_1. Qed. End ZpNzRing. Section Groups. Variable p : nat. Definition Zp := if p > 1 then [set: 'Z_p] else 1%g. Definition units_Zp := [set: {unit 'Z_p}]. Lemma Zp_cast : p > 1 -> (Zp_trunc p).+2 = p. Proof. by case: p => [|[]]. Qed. Lemma val_Zp_nat (p_gt1 : p > 1) n : (n%:R : 'Z_p) = (n %% p)%N :> nat. Proof. by rewrite Zp_nat /= Zp_cast. Qed. Lemma Zp_nat_mod (p_gt1 : p > 1)m : (m %% p)%:R = m%:R :> 'Z_p. Proof. by apply: ord_inj; rewrite !val_Zp_nat // modn_mod. Qed. Lemma pchar_Zp : p > 1 -> p%:R = 0 :> 'Z_p. Proof. by move=> p_gt1; rewrite -Zp_nat_mod ?modnn. Qed. Lemma unitZpE x : p > 1 -> ((x%:R : 'Z_p) \is a GRing.unit) = coprime p x. Proof. move=> p_gt1; rewrite qualifE /=. by rewrite val_Zp_nat ?Zp_cast ?coprime_modr. Qed. Lemma Zp_group_set : group_set Zp. Proof. by rewrite /Zp; case: (p > 1); apply: groupP. Qed. (* FIX ME : is this ok something similar is done in fingroup *) Canonical Zp_group := Group Zp_group_set. Lemma card_Zp : p > 0 -> #|Zp| = p. Proof. rewrite /Zp; case: p => [|[|p']] //= _; first by rewrite cards1. by rewrite cardsT card_ord. Qed. Lemma mem_Zp x : p > 1 -> x \in Zp. Proof. by rewrite /Zp => ->. Qed. Canonical units_Zp_group := [group of units_Zp]. Lemma card_units_Zp : p > 0 -> #|units_Zp| = totient p. Proof. move=> p_gt0; transitivity (totient p.-2.+2); last by case: p p_gt0 => [|[|p']]. rewrite cardsT card_sub -sum1_card big_mkcond /=. by rewrite totient_count_coprime big_mkord. Qed. Lemma units_Zp_abelian : abelian units_Zp. Proof. by apply/centsP=> u _ v _; apply: unit_Zp_mulgC. Qed. End Groups. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_Zp instead.")] Notation char_Zp := (pchar_Zp) (only parsing). (* Field structure for primes. *) Section PrimeField. Open Scope ring_scope. Variable p : nat. Section F_prime. Hypothesis p_pr : prime p. Lemma Fp_Zcast : Zp_trunc (pdiv p) = Zp_trunc p. Proof. by rewrite /pdiv primes_prime. Qed. Lemma Fp_cast : (Zp_trunc (pdiv p)).+2 = p. Proof. by rewrite Fp_Zcast ?Zp_cast ?prime_gt1. Qed. Lemma card_Fp : #|'F_p| = p. Proof. by rewrite card_ord Fp_cast. Qed. Lemma val_Fp_nat n : (n%:R : 'F_p) = (n %% p)%N :> nat. Proof. by rewrite Zp_nat /= Fp_cast. Qed. Lemma Fp_nat_mod m : (m %% p)%:R = m%:R :> 'F_p. Proof. by apply: ord_inj; rewrite !val_Fp_nat // modn_mod. Qed. Lemma pchar_Fp : p \in [pchar 'F_p]. Proof. by rewrite !inE -Fp_nat_mod p_pr ?modnn. Qed. Lemma pchar_Fp_0 : p%:R = 0 :> 'F_p. Proof. exact: GRing.pcharf0 pchar_Fp. Qed. Lemma unitFpE x : ((x%:R : 'F_p) \is a GRing.unit) = coprime p x. Proof. by rewrite pdiv_id // unitZpE // prime_gt1. Qed. End F_prime. Lemma Fp_fieldMixin : GRing.ComUnitRing_isField 'F_p. Proof. constructor => x nzx. rewrite qualifE /= prime_coprime ?gtnNdvd ?lt0n //. case: (ltnP 1 p) => [lt1p | ]; last by case: p => [|[|p']]. by rewrite Zp_cast ?prime_gt1 ?pdiv_prime. Qed. HB.instance Definition _ := Fp_fieldMixin. HB.instance Definition _ := FinRing.isField.Build 'F_p. End PrimeField. Section Sym. Import GRing. Lemma gen_tperm_step n (k : 'I_n.+1) : coprime n.+1 k -> <<[set tperm i (i + k) | i : 'I_n.+1]>>%g = [set: 'S_n.+1]. Proof. case: n k => [|n] k. move=> _; apply/eqP; rewrite eqEsubset subsetT/= -(gen_tperm 0)/= gen_subG. apply/subsetP => s /imsetP[/= [][|//] lt01 _ ->]. have ->: (Ordinal lt01) = 0 by apply/val_inj. by rewrite tperm1 group1. rewrite -unitZpE// natr_Zp => k_unit. apply/eqP; rewrite eqEsubset subsetT/= -(gen_tperm 0)/= gen_subG. apply/subsetP => s /imsetP[/= i _ ->]. rewrite -[i](mulVKr k_unit) -[_ * i]natr_Zp mulr_natr. elim: (val _) => //= {i} [|[|i] IHi]; first by rewrite tperm1 group1. by rewrite mulrSr mem_gen//; apply/imsetP; exists 0. have [->|kS2N0] := eqVneq (k *+ i.+2) 0; first by rewrite tperm1 group1. have kSSneqkS : k *+ i.+2 != k *+ i.+1. rewrite -subr_eq0 -mulrnBr// subSnn mulr1n. by apply: contraTneq k_unit => ->; rewrite unitr0. rewrite -(@tpermJ_tperm _ (k *+ i.+1)) 1?eq_sym//. rewrite groupJ// 1?tpermC// mulrSr 1?tpermC. by rewrite mem_gen//; apply/imsetP; exists (k *+ i.+1). Qed. Lemma perm_addr1X n m (j k : 'I_n.+1) : (perm (addrI m%R) ^+ j)%g k = m *+ j + k. Proof. by rewrite permX (eq_iter (permE _)) iter_addr. Qed. Lemma gen_tpermn_circular_shift n (i j : 'I_n.+2) (c := perm (addrI 1)) : coprime n.+2 (j - i)%R -> <<[set tperm i j ; c]>>%g = [set: 'S_n.+2]. Proof. move=> jBi_coprime; apply/eqP; rewrite eqEsubset subsetT/=. rewrite -(gen_tperm_step jBi_coprime) gen_subG. apply/subsetP => s /imsetP[/= k _ ->]. suff -> : tperm k (k + (j - i)) = (tperm i j ^ c ^+ (k - i)%R)%g. by rewrite groupJ ?groupX ?mem_gen ?inE ?eqxx ?orbT. by rewrite tpermJ !perm_addr1X natr_Zp addrNK addrAC addrA. Qed. End Sym. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_Fp instead.")] Notation char_Fp := (pchar_Fp) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pchar_Fp_0 instead.")] Notation char_Fp_0 := (pchar_Fp_0) (only parsing).
gseries.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 path. From mathcomp Require Import fintype bigop finset fingroup morphism. From mathcomp Require Import automorphism quotient action commutator center. (******************************************************************************) (* H <|<| G <=> H is subnormal in G, i.e., H <| ... <| G. *) (* invariant_factor A H G <=> A normalises both H and G, and H <| G. *) (* A.-invariant <=> the (invariant_factor A) relation, in the context *) (* of the g_rel.-series notation. *) (* g_rel.-series H s <=> H :: s is a sequence of groups whose projection *) (* to sets satisfies relation g_rel pairwise; for *) (* example H <|<| G iff G = last H s for some s such *) (* that normal.-series H s. *) (* stable_factor A H G == H <| G and A centralises G / H. *) (* A.-stable == the stable_factor relation, in the scope of the *) (* r.-series notation. *) (* G.-central == the central_factor relation, in the scope of the *) (* r.-series notation. *) (* maximal M G == M is a maximal proper subgroup of G. *) (* maximal_eq M G == (M == G) or (maximal M G). *) (* maxnormal M G N == M is a maximal subgroup of G normalized by N. *) (* minnormal M N == M is a minimal nontrivial group normalized by N. *) (* simple G == G is a (nontrivial) simple group. *) (* := minnormal G G *) (* G.-chief == the chief_factor relation, in the scope of the *) (* r.-series notation. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope group_rel_scope. Import GroupScope. Section GroupDefs. Variable gT : finGroupType. Implicit Types A B U V : {set gT}. Local Notation groupT := (group_of gT). Definition subnormal A B := (A \subset B) && (iter #|B| (fun N => generated (class_support A N)) B == A). Definition invariant_factor A B C := [&& A \subset 'N(B), A \subset 'N(C) & B <| C]. Definition group_rel_of (r : rel {set gT}) := [rel H G : groupT | r H G]. Definition stable_factor A V U := ([~: U, A] \subset V) && (V <| U). (* this orders allows and3P to be used *) Definition central_factor A V U := [&& [~: U, A] \subset V, V \subset U & U \subset A]. Definition maximal A B := [max A of G | G \proper B]. Definition maximal_eq A B := (A == B) || maximal A B. Definition maxnormal A B U := [max A of G | G \proper B & U \subset 'N(G)]. Definition minnormal A B := [min A of G | G :!=: 1 & B \subset 'N(G)]. Definition simple A := minnormal A A. Definition chief_factor A V U := maxnormal V U A && (U <| A). End GroupDefs. Arguments subnormal {gT} A%_g B%_g. Arguments invariant_factor {gT} A%_g B%_g C%_g. Arguments stable_factor {gT} A%_g V%_g U%_g. Arguments central_factor {gT} A%_g V%_g U%_g. Arguments maximal {gT} A%_g B%_g. Arguments maximal_eq {gT} A%_g B%_g. Arguments maxnormal {gT} A%_g B%_g U%_g. Arguments minnormal {gT} A%_g B%_g. Arguments simple {gT} A%_g. Arguments chief_factor {gT} A%_g V%_g U%_g. Notation "H <|<| G" := (subnormal H G) (at level 70, no associativity) : group_scope. Notation "A .-invariant" := (invariant_factor A) (format "A .-invariant") : group_rel_scope. Notation "A .-stable" := (stable_factor A) (format "A .-stable") : group_rel_scope. Notation "A .-central" := (central_factor A) (format "A .-central") : group_rel_scope. Notation "G .-chief" := (chief_factor G) (format "G .-chief") : group_rel_scope. Arguments group_rel_of {gT} r%_group_rel_scope _%_G _%_G : extra scopes. Notation "r .-series" := (path (rel_of_simpl (group_rel_of r))) (format "r .-series") : group_scope. Section Subnormal. Variable gT : finGroupType. Implicit Types (A B C D : {set gT}) (G H K : {group gT}). Let setIgr H G := (G :&: H)%G. Let sub_setIgr G H : G \subset H -> G = setIgr H G. Proof. by move/setIidPl/group_inj. Qed. Let path_setIgr H G s : normal.-series H s -> normal.-series (setIgr G H) (map (setIgr G) s). Proof. elim: s H => //= K s IHs H /andP[/andP[sHK nHK] Ksn]. by rewrite /normal setSI ?normsIG ?IHs. Qed. Lemma subnormalP H G : reflect (exists2 s, normal.-series H s & last H s = G) (H <|<| G). Proof. apply: (iffP andP) => [[sHG snHG] | [s Hsn <-{G}]]. move: #|G| snHG => m; elim: m => [|m IHm] in G sHG *. by exists [::]; last by apply/eqP; rewrite eq_sym. rewrite iterSr => /IHm[|s Hsn defG]. by rewrite sub_gen // class_supportEr (bigD1 1) //= conjsg1 subsetUl. exists (rcons s G); rewrite ?last_rcons // -cats1 cat_path Hsn defG /=. rewrite /normal gen_subG class_support_subG //=. by rewrite norms_gen ?class_support_norm. set f := fun _ => <<_>>; have idf: iter _ f H == H. by elim=> //= m IHm; rewrite (eqP IHm) /f class_support_id genGid. have [m] := ubnP (size s); elim: m s Hsn => // m IHm /lastP[//|s G]. rewrite size_rcons last_rcons rcons_path /= ltnS. set K := last H s => /andP[Hsn /andP[sKG nKG]] lt_s_m. have /[1!subEproper]/predU1P[<-|prKG] := sKG; first exact: IHm. pose L := [group of f G]. have sHK: H \subset K by case/IHm: Hsn. have sLK: L \subset K by rewrite gen_subG class_support_sub_norm. rewrite -(subnK (proper_card (sub_proper_trans sLK prKG))) iterD iterSr. have defH: H = setIgr L H by rewrite -sub_setIgr ?sub_gen ?sub_class_support. have: normal.-series H (map (setIgr L) s) by rewrite defH path_setIgr. case/IHm=> [|_]; first by rewrite size_map. rewrite [in last _]defH last_map (subset_trans sHK) //=. by rewrite (setIidPr sLK) => /eqP->. Qed. Lemma subnormal_refl G : G <|<| G. Proof. by apply/subnormalP; exists [::]. Qed. Lemma subnormal_trans K H G : H <|<| K -> K <|<| G -> H <|<| G. Proof. case/subnormalP=> [s1 Hs1 <-] /subnormalP[s2 Hs12 <-]. by apply/subnormalP; exists (s1 ++ s2); rewrite ?last_cat // cat_path Hs1. Qed. Lemma normal_subnormal H G : H <| G -> H <|<| G. Proof. by move=> nsHG; apply/subnormalP; exists [:: G]; rewrite //= nsHG. Qed. Lemma setI_subnormal G H K : K \subset G -> H <|<| G -> H :&: K <|<| K. Proof. move=> sKG /subnormalP[s Hs defG]; apply/subnormalP. exists (map (setIgr K) s); first exact: path_setIgr. rewrite (last_map (setIgr K)) defG. by apply: val_inj; rewrite /= (setIidPr sKG). Qed. Lemma subnormal_sub G H : H <|<| G -> H \subset G. Proof. by case/andP. Qed. Lemma invariant_subnormal A G H : A \subset 'N(G) -> A \subset 'N(H) -> H <|<| G -> exists2 s, (A.-invariant).-series H s & last H s = G. Proof. move=> nGA nHA /andP[]; move: #|G| => m. elim: m => [|m IHm] in G nGA * => sHG. by rewrite eq_sym; exists [::]; last apply/eqP. rewrite iterSr; set K := <<_>>. have nKA: A \subset 'N(K) by rewrite norms_gen ?norms_class_support. have sHK: H \subset K by rewrite sub_gen ?sub_class_support. case/IHm=> // s Hsn defK; exists (rcons s G); last by rewrite last_rcons. rewrite rcons_path Hsn !andbA defK nGA nKA /= -/K. by rewrite gen_subG class_support_subG ?norms_gen ?class_support_norm. Qed. Lemma subnormalEsupport G H : H <|<| G -> H :=: G \/ <<class_support H G>> \proper G. Proof. case/andP=> sHG; set K := <<_>> => /eqP <-. have: K \subset G by rewrite gen_subG class_support_subG. rewrite subEproper; case/predU1P=> [defK|]; [left | by right]. by elim: #|G| => //= _ ->. Qed. Lemma subnormalEr G H : H <|<| G -> H :=: G \/ (exists K : {group gT}, [/\ H <|<| K, K <| G & K \proper G]). Proof. case/subnormalP=> s Hs <-{G}. elim/last_ind: s Hs => [|s G IHs]; first by left. rewrite last_rcons -cats1 cat_path /= andbT; set K := last H s. case/andP=> Hs nsKG; have /[1!subEproper] := normal_sub nsKG. case/predU1P=> [<- | prKG]; [exact: IHs | right; exists K; split=> //]. by apply/subnormalP; exists s. Qed. Lemma subnormalEl G H : H <|<| G -> H :=: G \/ (exists K : {group gT}, [/\ H <| K, K <|<| G & H \proper K]). Proof. case/subnormalP=> s Hs <-{G}; elim: s H Hs => /= [|K s IHs] H; first by left. case/andP=> nsHK Ks; have /[1!subEproper] := normal_sub nsHK. case/predU1P=> [-> | prHK]; [exact: IHs | right; exists K; split=> //]. by apply/subnormalP; exists s. Qed. End Subnormal. Arguments subnormalP {gT H G}. Section MorphSubNormal. Variable gT : finGroupType. Implicit Type G H K : {group gT}. Lemma morphim_subnormal (rT : finGroupType) G (f : {morphism G >-> rT}) H K : H <|<| K -> f @* H <|<| f @* K. Proof. case/subnormalP => s Hs <-{K}; apply/subnormalP. elim: s H Hs => [|K s IHs] H /=; first by exists [::]. case/andP=> nsHK /IHs[fs Hfs <-]. by exists ([group of f @* K] :: fs); rewrite /= ?morphim_normal. Qed. Lemma quotient_subnormal H G K : G <|<| K -> G / H <|<| K / H. Proof. exact: morphim_subnormal. Qed. End MorphSubNormal. Section MaxProps. Variable gT : finGroupType. Implicit Types G H M : {group gT}. Lemma maximal_eqP M G : reflect (M \subset G /\ forall H, M \subset H -> H \subset G -> H :=: M \/ H :=: G) (maximal_eq M G). Proof. rewrite subEproper /maximal_eq; case: eqP => [->|_]; first left. by split=> // H sGH sHG; right; apply/eqP; rewrite eqEsubset sHG. apply: (iffP maxgroupP) => [] [sMG maxM]; split=> // H. by move/maxM=> maxMH; rewrite subEproper; case/predU1P; auto. by rewrite properEneq => /andP[/eqP neHG sHG] /maxM[]. Qed. Lemma maximal_exists H G : H \subset G -> H :=: G \/ (exists2 M : {group gT}, maximal M G & H \subset M). Proof. rewrite subEproper; case/predU1P=> sHG; first by left. suff [M *]: {M : {group gT} | maximal M G & H \subset M} by right; exists M. exact: maxgroup_exists. Qed. Lemma mulg_normal_maximal G M H : M <| G -> maximal M G -> H \subset G -> ~~ (H \subset M) -> (M * H = G)%g. Proof. case/andP=> sMG nMG /maxgroupP[_ maxM] sHG not_sHM. apply/eqP; rewrite eqEproper mul_subG // -norm_joinEr ?(subset_trans sHG) //. by apply: contra not_sHM => /maxM <-; rewrite ?joing_subl ?joing_subr. Qed. End MaxProps. Section MinProps. Variable gT : finGroupType. Implicit Types G H M : {group gT}. Lemma minnormal_exists G H : H :!=: 1 -> G \subset 'N(H) -> {M : {group gT} | minnormal M G & M \subset H}. Proof. by move=> ntH nHG; apply: mingroup_exists (H) _; rewrite ntH. Qed. End MinProps. Section MorphPreMax. Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}). Variables (M G : {group rT}). Hypotheses (dM : M \subset f @* D) (dG : G \subset f @* D). Lemma morphpre_maximal : maximal (f @*^-1 M) (f @*^-1 G) = maximal M G. Proof. apply/maxgroupP/maxgroupP; rewrite morphpre_proper //= => [] [ltMG maxM]. split=> // H ltHG sMH; have dH := subset_trans (proper_sub ltHG) dG. rewrite -(morphpreK dH) [f @*^-1 H]maxM ?morphpreK ?morphpreSK //. by rewrite morphpre_proper. split=> // H ltHG sMH. have dH: H \subset D := subset_trans (proper_sub ltHG) (subsetIl D _). have defH: f @*^-1 (f @* H) = H. by apply: morphimGK dH; apply: subset_trans sMH; apply: ker_sub_pre. rewrite -defH morphpre_proper ?morphimS // in ltHG. by rewrite -defH [f @* H]maxM // -(morphpreK dM) morphimS. Qed. Lemma morphpre_maximal_eq : maximal_eq (f @*^-1 M) (f @*^-1 G) = maximal_eq M G. Proof. by rewrite /maximal_eq morphpre_maximal !eqEsubset !morphpreSK. Qed. End MorphPreMax. Section InjmMax. Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}). Variables M G L : {group gT}. Hypothesis injf : 'injm f. Hypotheses (dM : M \subset D) (dG : G \subset D) (dL : L \subset D). Lemma injm_maximal : maximal (f @* M) (f @* G) = maximal M G. Proof. rewrite -(morphpre_invm injf) -(morphpre_invm injf G). by rewrite morphpre_maximal ?morphim_invm. Qed. Lemma injm_maximal_eq : maximal_eq (f @* M) (f @* G) = maximal_eq M G. Proof. by rewrite /maximal_eq injm_maximal // injm_eq. Qed. Lemma injm_maxnormal : maxnormal (f @* M) (f @* G) (f @* L) = maxnormal M G L. Proof. pose injfm := (injm_proper injf, injm_norms, injmSK injf, subsetIl). apply/maxgroupP/maxgroupP; rewrite !injfm // => [[nML maxM]]. split=> // H nHL sMH; have [/proper_sub sHG _] := andP nHL. have dH := subset_trans sHG dG; apply: (injm_morphim_inj injf) => //. by apply: maxM; rewrite !injfm. split=> // fH nHL sMH; have [/proper_sub sfHG _] := andP nHL. have{sfHG} dfH: fH \subset f @* D := subset_trans sfHG (morphim_sub f G). by rewrite -(morphpreK dfH) !injfm // in nHL sMH *; rewrite (maxM _ nHL). Qed. Lemma injm_minnormal : minnormal (f @* M) (f @* G) = minnormal M G. Proof. pose injfm := (morphim_injm_eq1 injf, injm_norms, injmSK injf, subsetIl). apply/mingroupP/mingroupP; rewrite !injfm // => [[nML minM]]. split=> // H nHG sHM; have dH := subset_trans sHM dM. by apply: (injm_morphim_inj injf) => //; apply: minM; rewrite !injfm. split=> // fH nHG sHM; have dfH := subset_trans sHM (morphim_sub f M). by rewrite -(morphpreK dfH) !injfm // in nHG sHM *; rewrite (minM _ nHG). Qed. End InjmMax. Section QuoMax. Variables (gT : finGroupType) (K G H : {group gT}). Lemma cosetpre_maximal (Q R : {group coset_of K}) : maximal (coset K @*^-1 Q) (coset K @*^-1 R) = maximal Q R. Proof. by rewrite morphpre_maximal ?sub_im_coset. Qed. Lemma cosetpre_maximal_eq (Q R : {group coset_of K}) : maximal_eq (coset K @*^-1 Q) (coset K @*^-1 R) = maximal_eq Q R. Proof. by rewrite /maximal_eq !eqEsubset !cosetpreSK cosetpre_maximal. Qed. Lemma quotient_maximal : K <| G -> K <| H -> maximal (G / K) (H / K) = maximal G H. Proof. by move=> nKG nKH; rewrite -cosetpre_maximal ?quotientGK. Qed. Lemma quotient_maximal_eq : K <| G -> K <| H -> maximal_eq (G / K) (H / K) = maximal_eq G H. Proof. by move=> nKG nKH; rewrite -cosetpre_maximal_eq ?quotientGK. Qed. Lemma maximalJ x : maximal (G :^ x) (H :^ x) = maximal G H. Proof. rewrite -{1}(setTI G) -{1}(setTI H) -!morphim_conj. by rewrite injm_maximal ?subsetT ?injm_conj. Qed. Lemma maximal_eqJ x : maximal_eq (G :^ x) (H :^ x) = maximal_eq G H. Proof. by rewrite /maximal_eq !eqEsubset !conjSg maximalJ. Qed. End QuoMax. Section MaxNormalProps. Variables (gT : finGroupType). Implicit Types (A B C : {set gT}) (G H K L M : {group gT}). Lemma maxnormal_normal A B : maxnormal A B B -> A <| B. Proof. by case/maxsetP=> /and3P[/gen_set_id /= -> pAB nAB]; rewrite /normal proper_sub. Qed. Lemma maxnormal_proper A B C : maxnormal A B C -> A \proper B. Proof. by case/maxsetP=> /and3P[gA pAB _] _; apply: (sub_proper_trans (subset_gen A)). Qed. Lemma maxnormal_sub A B C : maxnormal A B C -> A \subset B. Proof. by move=> maxA; rewrite proper_sub //; apply: (maxnormal_proper maxA). Qed. Lemma ex_maxnormal_ntrivg G : G :!=: 1-> {N : {group gT} | maxnormal N G G}. Proof. move=> ntG; apply: ex_maxgroup; exists [1 gT]%G; rewrite norm1 proper1G. by rewrite subsetT ntG. Qed. Lemma maxnormalM G H K : maxnormal H G G -> maxnormal K G G -> H :<>: K -> H * K = G. Proof. move=> maxH maxK /eqP; apply: contraNeq => ltHK_G. have [nsHG nsKG] := (maxnormal_normal maxH, maxnormal_normal maxK). have cHK: commute H K. exact: normC (subset_trans (normal_sub nsHG) (normal_norm nsKG)). wlog suffices: H K {maxH} maxK nsHG nsKG cHK ltHK_G / H \subset K. by move=> IH; rewrite eqEsubset !IH // -cHK. have{maxK} /maxgroupP[_ maxK] := maxK. apply/joing_idPr/maxK; rewrite ?joing_subr //= comm_joingE //. by rewrite properEneq ltHK_G; apply: normalM. Qed. Lemma maxnormal_minnormal G L M : G \subset 'N(M) -> L \subset 'N(G) -> maxnormal M G L -> minnormal (G / M) (L / M). Proof. move=> nMG nGL /maxgroupP[/andP[/andP[sMG ltMG] nML] maxM]; apply/mingroupP. rewrite -subG1 quotient_sub1 ?ltMG ?quotient_norms //. split=> // Hb /andP[ntHb nHbL]; have nsMG: M <| G by apply/andP. case/inv_quotientS=> // H defHb sMH sHG; rewrite defHb; congr (_ / M). apply/eqP; rewrite eqEproper sHG /=; apply: contra ntHb => ltHG. have nsMH: M <| H := normalS sMH sHG nsMG. rewrite defHb quotientS1 // (maxM H) // ltHG /= -(quotientGK nsMH) -defHb. exact: norm_quotient_pre. Qed. Lemma minnormal_maxnormal G L M : M <| G -> L \subset 'N(M) -> minnormal (G / M) (L / M) -> maxnormal M G L. Proof. case/andP=> sMG nMG nML /mingroupP[/andP[/= ntGM _] minGM]; apply/maxgroupP. split=> [|H /andP[/andP[sHG ltHG] nHL] sMH]. by rewrite /proper sMG nML andbT; apply: contra ntGM => /quotientS1 ->. apply/eqP; rewrite eqEsubset sMH andbT -quotient_sub1 ?(subset_trans sHG) //. rewrite subG1; apply: contraR ltHG => ntHM; rewrite -(quotientSGK nMG) //. by rewrite (minGM (H / M)%G) ?quotientS // ntHM quotient_norms. Qed. End MaxNormalProps. Section Simple. Implicit Types gT rT : finGroupType. Lemma simpleP gT (G : {group gT}) : reflect (G :!=: 1 /\ forall H : {group gT}, H <| G -> H :=: 1 \/ H :=: G) (simple G). Proof. apply: (iffP mingroupP); rewrite normG andbT => [[ntG simG]]. split=> // N /andP[sNG nNG]. by case: (eqsVneq N 1) => [|ntN]; [left | right; apply: simG; rewrite ?ntN]. split=> // N /andP[ntN nNG] sNG. by case: (simG N) ntN => // [|->]; [apply/andP | case/eqP]. Qed. Lemma quotient_simple gT (G H : {group gT}) : H <| G -> simple (G / H) = maxnormal H G G. Proof. move=> nsHG; have nGH := normal_norm nsHG. by apply/idP/idP; [apply: minnormal_maxnormal | apply: maxnormal_minnormal]. Qed. Lemma isog_simple gT rT (G : {group gT}) (M : {group rT}) : G \isog M -> simple G = simple M. Proof. move=> eqGM; wlog suffices: gT rT G M eqGM / simple M -> simple G. by move=> IH; apply/idP/idP; apply: IH; rewrite // isog_sym. case/isogP: eqGM => f injf <- /simpleP[ntGf simGf]. apply/simpleP; split=> [|N nsNG]; first by rewrite -(morphim_injm_eq1 injf). rewrite -(morphim_invm injf (normal_sub nsNG)). have: f @* N <| f @* G by rewrite morphim_normal. by case/simGf=> /= ->; [left | right]; rewrite (morphim1, morphim_invm). Qed. Lemma simple_maxnormal gT (G : {group gT}) : simple G = maxnormal 1 G G. Proof. by rewrite -quotient_simple ?normal1 // -(isog_simple (quotient1_isog G)). Qed. End Simple. Section Chiefs. Variable gT : finGroupType. Implicit Types G H U V : {group gT}. Lemma chief_factor_minnormal G V U : chief_factor G V U -> minnormal (U / V) (G / V). Proof. case/andP=> maxV /andP[sUG nUG]; apply: maxnormal_minnormal => //. by have /andP[_ nVG] := maxgroupp maxV; apply: subset_trans sUG nVG. Qed. Lemma acts_irrQ G U V : G \subset 'N(V) -> V <| U -> acts_irreducibly G (U / V) 'Q = minnormal (U / V) (G / V). Proof. move=> nVG nsVU; apply/mingroupP/mingroupP; case=> /andP[->] /=. rewrite astabsQ // subsetI nVG /= => nUG minUV. rewrite quotient_norms //; split=> // H /andP[ntH nHG] sHU. by apply: minUV (sHU); rewrite ntH -(cosetpreK H) actsQ // norm_quotient_pre. rewrite sub_quotient_pre // => nUG minU; rewrite astabsQ //. rewrite (subset_trans nUG); last first. by rewrite subsetI subsetIl /= -{2}(quotientGK nsVU) morphpre_norm. split=> // H /andP[ntH nHG] sHU. rewrite -{1}(cosetpreK H) astabsQ ?normal_cosetpre ?subsetI ?nVG //= in nHG. apply: minU sHU; rewrite ntH; apply: subset_trans (quotientS _ nHG) _. by rewrite -{2}(cosetpreK H) quotient_norm. Qed. Lemma chief_series_exists H G : H <| G -> {s | (G.-chief).-series 1%G s & last 1%G s = H}. Proof. have [m] := ubnP #|H|; elim: m H => // m IHm U leUm nsUG. have [-> | ntU] := eqVneq U 1%G; first by exists [::]. have [V maxV]: {V : {group gT} | maxnormal V U G}. by apply: ex_maxgroup; exists 1%G; rewrite proper1G ntU norms1. have /andP[ltVU nVG] := maxgroupp maxV. have [||s ch_s defV] := IHm V; first exact: leq_trans (proper_card ltVU) _. by rewrite /normal (subset_trans (proper_sub ltVU) (normal_sub nsUG)). exists (rcons s U); last by rewrite last_rcons. by rewrite rcons_path defV /= ch_s /chief_factor; apply/and3P. Qed. End Chiefs. Section Central. Variables (gT : finGroupType) (G : {group gT}). Implicit Types H K : {group gT}. Lemma central_factor_central H K : central_factor G H K -> (K / H) \subset 'Z(G / H). Proof. by case/and3P=> /quotient_cents2r *; rewrite subsetI quotientS. Qed. Lemma central_central_factor H K : (K / H) \subset 'Z(G / H) -> H <| K -> H <| G -> central_factor G H K. Proof. case/subsetIP=> sKGb cGKb /andP[sHK nHK] /andP[sHG nHG]. by rewrite /central_factor -quotient_cents2 // cGKb sHK -(quotientSGK nHK). Qed. End Central.
Upcrossing.lean
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Order.Interval.Set.Monotone import Mathlib.Probability.Process.HittingTime import Mathlib.Probability.Martingale.Basic import Mathlib.Tactic.AdaptationNote /-! # Doob's upcrossing estimate Given a discrete real-valued submartingale $(f_n)_{n \in \mathbb{N}}$, denoting by $U_N(a, b)$ the number of times $f_n$ crossed from below $a$ to above $b$ before time $N$, Doob's upcrossing estimate (also known as Doob's inequality) states that $$(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(f_N - a)^+].$$ Doob's upcrossing estimate is an important inequality and is central in proving the martingale convergence theorems. ## Main definitions * `MeasureTheory.upperCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing above `b` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.lowerCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing below `a` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.upcrossingStrat a b f N`: is the predictable process which is 1 if `n` is between a consecutive pair of lower and upper crossings and is 0 otherwise. Intuitively one might think of the `upcrossingStrat` as the strategy of buying 1 share whenever the process crosses below `a` for the first time after selling and selling 1 share whenever the process crosses above `b` for the first time after buying. * `MeasureTheory.upcrossingsBefore a b f N`: is the number of times `f` crosses from below `a` to above `b` before time `N`. * `MeasureTheory.upcrossings a b f`: is the number of times `f` crosses from below `a` to above `b`. This takes value in `ℝ≥0∞` and so is allowed to be `∞`. ## Main results * `MeasureTheory.Adapted.isStoppingTime_upperCrossingTime`: `upperCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Adapted.isStoppingTime_lowerCrossingTime`: `lowerCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part`: Doob's upcrossing estimate. * `MeasureTheory.Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part`: the inequality obtained by taking the supremum on both sides of Doob's upcrossing estimate. ### References We mostly follow the proof from [Kallenberg, *Foundations of modern probability*][kallenberg2021] -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology namespace MeasureTheory variable {Ω ι : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} /-! ## Proof outline In this section, we will denote by $U_N(a, b)$ the number of upcrossings of $(f_n)$ from below $a$ to above $b$ before time $N$. To define $U_N(a, b)$, we will construct two stopping times corresponding to when $(f_n)$ crosses below $a$ and above $b$. Namely, we define $$ \sigma_n := \inf \{n \ge \tau_n \mid f_n \le a\} \wedge N; $$ $$ \tau_{n + 1} := \inf \{n \ge \sigma_n \mid f_n \ge b\} \wedge N. $$ These are `lowerCrossingTime` and `upperCrossingTime` in our formalization which are defined using `MeasureTheory.hitting` allowing us to specify a starting and ending time. Then, we may simply define $U_N(a, b) := \sup \{n \mid \tau_n < N\}$. Fixing $a < b \in \mathbb{R}$, we will first prove the theorem in the special case that $0 \le f_0$ and $a \le f_N$. In particular, we will show $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[f_N]. $$ This is `MeasureTheory.integral_mul_upcrossingsBefore_le_integral` in our formalization. To prove this, we use the fact that given a non-negative, bounded, predictable process $(C_n)$ (i.e. $(C_{n + 1})$ is adapted), $(C \bullet f)_n := \sum_{k \le n} C_{k + 1}(f_{k + 1} - f_k)$ is a submartingale if $(f_n)$ is. Define $C_n := \sum_{k \le n} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)$. It is easy to see that $(1 - C_n)$ is non-negative, bounded and predictable, and hence, given a submartingale $(f_n)$, $(1 - C) \bullet f$ is also a submartingale. Thus, by the submartingale property, $0 \le \mathbb{E}[((1 - C) \bullet f)_0] \le \mathbb{E}[((1 - C) \bullet f)_N]$ implying $$ \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[(1 \bullet f)_N] = \mathbb{E}[f_N] - \mathbb{E}[f_0]. $$ Furthermore, \begin{align} (C \bullet f)_N & = \sum_{n \le N} \sum_{k \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} \sum_{n \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} (f_{\sigma_k + 1} - f_{\sigma_k} + f_{\sigma_k + 2} - f_{\sigma_k + 1} + \cdots + f_{\tau_{k + 1}} - f_{\tau_{k + 1} - 1})\\ & = \sum_{k \le N} (f_{\tau_{k + 1}} - f_{\sigma_k}) \ge \sum_{k < U_N(a, b)} (b - a) = (b - a) U_N(a, b) \end{align} where the inequality follows since for all $k < U_N(a, b)$, $f_{\tau_{k + 1}} - f_{\sigma_k} \ge b - a$ while for all $k > U_N(a, b)$, $f_{\tau_{k + 1}} = f_{\sigma_k} = f_N$ and $f_{\tau_{U_N(a, b) + 1}} - f_{\sigma_{U_N(a, b)}} = f_N - a \ge 0$. Hence, we have $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[f_N] - \mathbb{E}[f_0] \le \mathbb{E}[f_N], $$ as required. To obtain the general case, we simply apply the above to $((f_n - a)^+)_n$. -/ /-- `lowerCrossingTimeAux a f c N` is the first time `f` reached below `a` after time `c` before time `N`. -/ noncomputable def lowerCrossingTimeAux [Preorder ι] [InfSet ι] (a : ℝ) (f : ι → Ω → ℝ) (c N : ι) : Ω → ι := hitting f (Set.Iic a) c N /-- `upperCrossingTime a b f N n` is the first time before time `N`, `f` reaches above `b` after `f` reached below `a` for the `n - 1`-th time. -/ noncomputable def upperCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) : ℕ → Ω → ι | 0 => ⊥ | n + 1 => fun ω => hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω /-- `lowerCrossingTime a b f N n` is the first time before time `N`, `f` reaches below `a` after `f` reached above `b` for the `n`-th time. -/ noncomputable def lowerCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (n : ℕ) : Ω → ι := fun ω => hitting f (Set.Iic a) (upperCrossingTime a b f N n ω) N ω section variable [Preorder ι] [OrderBot ι] [InfSet ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n : ℕ} {ω : Ω} @[simp] theorem upperCrossingTime_zero : upperCrossingTime a b f N 0 = ⊥ := rfl @[simp] theorem lowerCrossingTime_zero : lowerCrossingTime a b f N 0 = hitting f (Set.Iic a) ⊥ N := rfl theorem upperCrossingTime_succ : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω := by rw [upperCrossingTime] theorem upperCrossingTime_succ_eq (ω : Ω) : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTime a b f N n ω) N ω := by simp only [upperCrossingTime_succ] rfl end section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω} theorem upperCrossingTime_le : upperCrossingTime a b f N n ω ≤ N := by cases n · simp only [upperCrossingTime_zero, Pi.bot_apply, bot_le] · simp only [upperCrossingTime_succ, hitting_le] @[simp] theorem upperCrossingTime_zero' : upperCrossingTime a b f ⊥ n ω = ⊥ := eq_bot_iff.2 upperCrossingTime_le theorem lowerCrossingTime_le : lowerCrossingTime a b f N n ω ≤ N := by simp only [lowerCrossingTime, hitting_le ω] theorem upperCrossingTime_le_lowerCrossingTime : upperCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N n ω := by simp only [lowerCrossingTime, le_hitting upperCrossingTime_le ω] theorem lowerCrossingTime_le_upperCrossingTime_succ : lowerCrossingTime a b f N n ω ≤ upperCrossingTime a b f N (n + 1) ω := by rw [upperCrossingTime_succ] exact le_hitting lowerCrossingTime_le ω theorem lowerCrossingTime_mono (hnm : n ≤ m) : lowerCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N m ω := by suffices Monotone fun n => lowerCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans lowerCrossingTime_le_upperCrossingTime_succ upperCrossingTime_le_lowerCrossingTime theorem upperCrossingTime_mono (hnm : n ≤ m) : upperCrossingTime a b f N n ω ≤ upperCrossingTime a b f N m ω := by suffices Monotone fun n => upperCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans upperCrossingTime_le_lowerCrossingTime lowerCrossingTime_le_upperCrossingTime_succ end ConditionallyCompleteLinearOrderBot variable {a b : ℝ} {f : ℕ → Ω → ℝ} {N : ℕ} {n m : ℕ} {ω : Ω} theorem stoppedValue_lowerCrossingTime (h : lowerCrossingTime a b f N n ω ≠ N) : stoppedValue f (lowerCrossingTime a b f N n) ω ≤ a := by obtain ⟨j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne lowerCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 lowerCrossingTime_le⟩, hj₂⟩ theorem stoppedValue_upperCrossingTime (h : upperCrossingTime a b f N (n + 1) ω ≠ N) : b ≤ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω := by obtain ⟨j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne upperCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 (hitting_le _)⟩, hj₂⟩ theorem upperCrossingTime_lt_lowerCrossingTime (hab : a < b) (hn : lowerCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N (n + 1) ω < lowerCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne upperCrossingTime_le_lowerCrossingTime fun h => not_le.2 hab <| le_trans ?_ (stoppedValue_lowerCrossingTime hn) simp only [stoppedValue] rw [← h] exact stoppedValue_upperCrossingTime (h.symm ▸ hn) theorem lowerCrossingTime_lt_upperCrossingTime (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : lowerCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne lowerCrossingTime_le_upperCrossingTime_succ fun h => not_le.2 hab <| le_trans (stoppedValue_upperCrossingTime hn) ?_ simp only [stoppedValue] rw [← h] exact stoppedValue_lowerCrossingTime (h.symm ▸ hn) theorem upperCrossingTime_lt_succ (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_lt_upperCrossingTime hab hn) theorem lowerCrossingTime_stabilize (hnm : n ≤ m) (hn : lowerCrossingTime a b f N n ω = N) : lowerCrossingTime a b f N m ω = N := le_antisymm lowerCrossingTime_le (le_trans (le_of_eq hn.symm) (lowerCrossingTime_mono hnm)) theorem upperCrossingTime_stabilize (hnm : n ≤ m) (hn : upperCrossingTime a b f N n ω = N) : upperCrossingTime a b f N m ω = N := le_antisymm upperCrossingTime_le (le_trans (le_of_eq hn.symm) (upperCrossingTime_mono hnm)) theorem lowerCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ lowerCrossingTime a b f N n ω) : lowerCrossingTime a b f N m ω = N := lowerCrossingTime_stabilize hnm (le_antisymm lowerCrossingTime_le hn) theorem upperCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ upperCrossingTime a b f N n ω) : upperCrossingTime a b f N m ω = N := upperCrossingTime_stabilize hnm (le_antisymm upperCrossingTime_le hn) -- `upperCrossingTime_bound_eq` provides an explicit bound theorem exists_upperCrossingTime_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) : ∃ n, upperCrossingTime a b f N n ω = N := by by_contra h; push_neg at h have : StrictMono fun n => upperCrossingTime a b f N n ω := strictMono_nat_of_lt_succ fun n => upperCrossingTime_lt_succ hab (h _) obtain ⟨_, ⟨k, rfl⟩, hk⟩ : ∃ (m : _) (_ : m ∈ Set.range fun n => upperCrossingTime a b f N n ω), N < m := ⟨upperCrossingTime a b f N (N + 1) ω, ⟨N + 1, rfl⟩, lt_of_lt_of_le N.lt_succ_self (StrictMono.id_le this (N + 1))⟩ exact not_le.2 hk upperCrossingTime_le theorem upperCrossingTime_lt_bddAbove (hab : a < b) : BddAbove {n | upperCrossingTime a b f N n ω < N} := by obtain ⟨k, hk⟩ := exists_upperCrossingTime_eq f N ω hab refine ⟨k, fun n (hn : upperCrossingTime a b f N n ω < N) => ?_⟩ by_contra hn' exact hn.ne (upperCrossingTime_stabilize (not_le.1 hn').le hk) theorem upperCrossingTime_lt_nonempty (hN : 0 < N) : {n | upperCrossingTime a b f N n ω < N}.Nonempty := ⟨0, hN⟩ theorem upperCrossingTime_bound_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) : upperCrossingTime a b f N N ω = N := by by_cases hN' : N < Nat.find (exists_upperCrossingTime_eq f N ω hab) · refine le_antisymm upperCrossingTime_le ?_ have hmono : StrictMonoOn (fun n => upperCrossingTime a b f N n ω) (Set.Iic (Nat.find (exists_upperCrossingTime_eq f N ω hab)).pred) := by refine strictMonoOn_Iic_of_lt_succ fun m hm => upperCrossingTime_lt_succ hab ?_ rw [Nat.lt_pred_iff] at hm convert Nat.find_min _ hm convert StrictMonoOn.Iic_id_le hmono N (Nat.le_sub_one_of_lt hN') · rw [not_lt] at hN' exact upperCrossingTime_stabilize hN' (Nat.find_spec (exists_upperCrossingTime_eq f N ω hab)) theorem upperCrossingTime_eq_of_bound_le (hab : a < b) (hn : N ≤ n) : upperCrossingTime a b f N n ω = N := le_antisymm upperCrossingTime_le (le_trans (upperCrossingTime_bound_eq f N ω hab).symm.le (upperCrossingTime_mono hn)) variable {ℱ : Filtration ℕ m0} theorem Adapted.isStoppingTime_crossing (hf : Adapted ℱ f) : IsStoppingTime ℱ (upperCrossingTime a b f N n) ∧ IsStoppingTime ℱ (lowerCrossingTime a b f N n) := by induction n with | zero => refine ⟨isStoppingTime_const _ 0, ?_⟩ simp [hitting_isStoppingTime hf measurableSet_Iic] | succ k ih => obtain ⟨_, ih₂⟩ := ih have : IsStoppingTime ℱ (upperCrossingTime a b f N (k + 1)) := by intro n simp_rw [upperCrossingTime_succ_eq] exact isStoppingTime_hitting_isStoppingTime ih₂ (fun _ => lowerCrossingTime_le) measurableSet_Ici hf _ refine ⟨this, ?_⟩ intro n exact isStoppingTime_hitting_isStoppingTime this (fun _ => upperCrossingTime_le) measurableSet_Iic hf _ theorem Adapted.isStoppingTime_upperCrossingTime (hf : Adapted ℱ f) : IsStoppingTime ℱ (upperCrossingTime a b f N n) := hf.isStoppingTime_crossing.1 theorem Adapted.isStoppingTime_lowerCrossingTime (hf : Adapted ℱ f) : IsStoppingTime ℱ (lowerCrossingTime a b f N n) := hf.isStoppingTime_crossing.2 /-- `upcrossingStrat a b f N n` is 1 if `n` is between a consecutive pair of lower and upper crossings and is 0 otherwise. `upcrossingStrat` is shifted by one index so that it is adapted rather than predictable. -/ noncomputable def upcrossingStrat (a b : ℝ) (f : ℕ → Ω → ℝ) (N n : ℕ) (ω : Ω) : ℝ := ∑ k ∈ Finset.range N, (Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)).indicator 1 n theorem upcrossingStrat_nonneg : 0 ≤ upcrossingStrat a b f N n ω := Finset.sum_nonneg fun _ _ => Set.indicator_nonneg (fun _ _ => zero_le_one) _ theorem upcrossingStrat_le_one : upcrossingStrat a b f N n ω ≤ 1 := by rw [upcrossingStrat, ← Finset.indicator_biUnion_apply] · exact Set.indicator_le_self' (fun _ _ => zero_le_one) _ intro i _ j _ hij simp only [Set.Ico_disjoint_Ico] obtain hij' | hij' := lt_or_gt_of_ne hij · rw [min_eq_left (upperCrossingTime_mono (Nat.succ_le_succ hij'.le) : upperCrossingTime a b f N _ ω ≤ upperCrossingTime a b f N _ ω), max_eq_right (lowerCrossingTime_mono hij'.le : lowerCrossingTime a b f N _ _ ≤ lowerCrossingTime _ _ _ _ _ _)] refine le_trans upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_mono (Nat.succ_le_of_lt hij')) · rw [min_eq_right (upperCrossingTime_mono (Nat.succ_le_succ hij'.le) : upperCrossingTime a b f N _ ω ≤ upperCrossingTime a b f N _ ω), max_eq_left (lowerCrossingTime_mono hij'.le : lowerCrossingTime a b f N _ _ ≤ lowerCrossingTime _ _ _ _ _ _)] refine le_trans upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_mono (Nat.succ_le_of_lt hij')) theorem Adapted.upcrossingStrat_adapted (hf : Adapted ℱ f) : Adapted ℱ (upcrossingStrat a b f N) := by intro n change StronglyMeasurable[ℱ n] fun ω => ∑ k ∈ Finset.range N, ({n | lowerCrossingTime a b f N k ω ≤ n} ∩ {n | n < upperCrossingTime a b f N (k + 1) ω}).indicator 1 n refine Finset.stronglyMeasurable_fun_sum _ fun i _ => stronglyMeasurable_const.indicator ((hf.isStoppingTime_lowerCrossingTime n).inter ?_) simp_rw [← not_le] exact (hf.isStoppingTime_upperCrossingTime n).compl theorem Submartingale.sum_upcrossingStrat_mul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (a b : ℝ) (N : ℕ) : Submartingale (fun n : ℕ => ∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)) ℱ μ := hf.sum_mul_sub hf.adapted.upcrossingStrat_adapted (fun _ _ => upcrossingStrat_le_one) fun _ _ => upcrossingStrat_nonneg theorem Submartingale.sum_sub_upcrossingStrat_mul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (a b : ℝ) (N : ℕ) : Submartingale (fun n : ℕ => ∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)) ℱ μ := by refine hf.sum_mul_sub (fun n => (adapted_const ℱ 1 n).sub (hf.adapted.upcrossingStrat_adapted n)) (?_ : ∀ n ω, (1 - upcrossingStrat a b f N n) ω ≤ 1) ?_ · exact fun n ω => sub_le_self _ upcrossingStrat_nonneg · intro n ω simp [upcrossingStrat_le_one] theorem Submartingale.sum_mul_upcrossingStrat_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) : μ[∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] ≤ μ[f n] - μ[f 0] := by have h₁ : (0 : ℝ) ≤ μ[∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)] := by have := (hf.sum_sub_upcrossingStrat_mul a b N).setIntegral_le (zero_le n) MeasurableSet.univ rw [setIntegral_univ, setIntegral_univ] at this refine le_trans ?_ this simp only [Finset.range_zero, Finset.sum_empty, integral_zero', le_refl] have h₂ : μ[∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)] = μ[∑ k ∈ Finset.range n, (f (k + 1) - f k)] - μ[∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] := by simp only [sub_mul, one_mul, Finset.sum_sub_distrib, Pi.sub_apply, Finset.sum_apply, Pi.mul_apply] refine integral_sub (Integrable.sub (integrable_finset_sum _ fun i _ => hf.integrable _) (integrable_finset_sum _ fun i _ => hf.integrable _)) ?_ convert (hf.sum_upcrossingStrat_mul a b N).integrable n using 1 ext; simp rw [h₂, sub_nonneg] at h₁ refine le_trans h₁ ?_ simp_rw [Finset.sum_range_sub, integral_sub' (hf.integrable _) (hf.integrable _), le_refl] /-- The number of upcrossings (strictly) before time `N`. -/ noncomputable def upcrossingsBefore [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (ω : Ω) : ℕ := sSup {n | upperCrossingTime a b f N n ω < N} @[simp] theorem upcrossingsBefore_bot [Preorder ι] [OrderBot ι] [InfSet ι] {a b : ℝ} {f : ι → Ω → ℝ} {ω : Ω} : upcrossingsBefore a b f ⊥ ω = ⊥ := by simp [upcrossingsBefore] theorem upcrossingsBefore_zero : upcrossingsBefore a b f 0 ω = 0 := by simp [upcrossingsBefore] @[simp] theorem upcrossingsBefore_zero' : upcrossingsBefore a b f 0 = 0 := by ext ω; exact upcrossingsBefore_zero theorem upperCrossingTime_lt_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n ≤ upcrossingsBefore a b f N ω) : upperCrossingTime a b f N n ω < N := haveI : upperCrossingTime a b f N (upcrossingsBefore a b f N ω) ω < N := (upperCrossingTime_lt_nonempty hN).csSup_mem ((OrderBot.bddBelow _).finite_of_bddAbove (upperCrossingTime_lt_bddAbove hab)) lt_of_le_of_lt (upperCrossingTime_mono hn) this theorem upperCrossingTime_eq_of_upcrossingsBefore_lt (hab : a < b) (hn : upcrossingsBefore a b f N ω < n) : upperCrossingTime a b f N n ω = N := by refine le_antisymm upperCrossingTime_le (not_lt.1 ?_) convert notMem_of_csSup_lt hn (upperCrossingTime_lt_bddAbove hab) using 1 theorem upcrossingsBefore_le (f : ℕ → Ω → ℝ) (ω : Ω) (hab : a < b) : upcrossingsBefore a b f N ω ≤ N := by by_cases hN : N = 0 · subst hN rw [upcrossingsBefore_zero] · refine csSup_le ⟨0, zero_lt_iff.2 hN⟩ fun n (hn : _ < N) => ?_ by_contra hnN exact hn.ne (upperCrossingTime_eq_of_bound_le hab (not_le.1 hnN).le) theorem crossing_eq_crossing_of_lowerCrossingTime_lt {M : ℕ} (hNM : N ≤ M) (h : lowerCrossingTime a b f N n ω < N) : upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω ∧ lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω := by have h' : upperCrossingTime a b f N n ω < N := lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime h induction n with | zero => simp only [upperCrossingTime_zero, bot_eq_zero', lowerCrossingTime_zero, true_and, eq_comm] refine hitting_eq_hitting_of_exists hNM ?_ rw [lowerCrossingTime, hitting_lt_iff] at h · obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl | succ k ih => specialize ih (lt_of_le_of_lt (lowerCrossingTime_mono (Nat.le_succ _)) h) (lt_of_le_of_lt (upperCrossingTime_mono (Nat.le_succ _)) h') have : upperCrossingTime a b f M k.succ ω = upperCrossingTime a b f N k.succ ω := by rw [upperCrossingTime_succ_eq, hitting_lt_iff] at h' · simp only [upperCrossingTime_succ_eq] obtain ⟨j, hj₁, hj₂⟩ := h' rw [eq_comm, ih.2] exact hitting_eq_hitting_of_exists hNM ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl refine ⟨this, ?_⟩ simp only [lowerCrossingTime, eq_comm, this, Nat.succ_eq_add_one] refine hitting_eq_hitting_of_exists hNM ?_ rw [lowerCrossingTime, hitting_lt_iff _ le_rfl] at h obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ theorem crossing_eq_crossing_of_upperCrossingTime_lt {M : ℕ} (hNM : N ≤ M) (h : upperCrossingTime a b f N (n + 1) ω < N) : upperCrossingTime a b f M (n + 1) ω = upperCrossingTime a b f N (n + 1) ω ∧ lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω := by have := (crossing_eq_crossing_of_lowerCrossingTime_lt hNM (lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ h)).2 refine ⟨?_, this⟩ rw [upperCrossingTime_succ_eq, upperCrossingTime_succ_eq, eq_comm, this] refine hitting_eq_hitting_of_exists hNM ?_ rw [upperCrossingTime_succ_eq, hitting_lt_iff] at h · obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl theorem upperCrossingTime_eq_upperCrossingTime_of_lt {M : ℕ} (hNM : N ≤ M) (h : upperCrossingTime a b f N n ω < N) : upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω := by cases n · simp · exact (crossing_eq_crossing_of_upperCrossingTime_lt hNM h).1 theorem upcrossingsBefore_mono (hab : a < b) : Monotone fun N ω => upcrossingsBefore a b f N ω := by intro N M hNM ω simp only [upcrossingsBefore] by_cases hemp : {n : ℕ | upperCrossingTime a b f N n ω < N}.Nonempty · refine csSup_le_csSup (upperCrossingTime_lt_bddAbove hab) hemp fun n hn => ?_ rw [Set.mem_setOf_eq, upperCrossingTime_eq_upperCrossingTime_of_lt hNM hn] exact lt_of_lt_of_le hn hNM · rw [Set.not_nonempty_iff_eq_empty] at hemp simp [hemp, csSup_empty] theorem upcrossingsBefore_lt_of_exists_upcrossing (hab : a < b) {N₁ N₂ : ℕ} (hN₁ : N ≤ N₁) (hN₁' : f N₁ ω < a) (hN₂ : N₁ ≤ N₂) (hN₂' : b < f N₂ ω) : upcrossingsBefore a b f N ω < upcrossingsBefore a b f (N₂ + 1) ω := by refine lt_of_lt_of_le (Nat.lt_succ_self _) (le_csSup (upperCrossingTime_lt_bddAbove hab) ?_) rw [Set.mem_setOf_eq, upperCrossingTime_succ_eq, hitting_lt_iff _ le_rfl] refine ⟨N₂, ⟨?_, Nat.lt_succ_self _⟩, hN₂'.le⟩ rw [lowerCrossingTime, hitting_le_iff_of_lt _ (Nat.lt_succ_self _)] refine ⟨N₁, ⟨le_trans ?_ hN₁, hN₂⟩, hN₁'.le⟩ by_cases hN : 0 < N · have : upperCrossingTime a b f N (upcrossingsBefore a b f N ω) ω < N := Nat.sSup_mem (upperCrossingTime_lt_nonempty hN) (upperCrossingTime_lt_bddAbove hab) rw [upperCrossingTime_eq_upperCrossingTime_of_lt (hN₁.trans (hN₂.trans <| Nat.le_succ _)) this] exact this.le · rw [not_lt, Nat.le_zero] at hN rw [hN, upcrossingsBefore_zero, upperCrossingTime_zero, Pi.bot_apply, bot_eq_zero'] theorem lowerCrossingTime_lt_of_lt_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n < upcrossingsBefore a b f N ω) : lowerCrossingTime a b f N n ω < N := lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn) theorem le_sub_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n < upcrossingsBefore a b f N ω) : b - a ≤ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω - stoppedValue f (lowerCrossingTime a b f N n) ω := sub_le_sub (stoppedValue_upperCrossingTime (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn).ne) (stoppedValue_lowerCrossingTime (lowerCrossingTime_lt_of_lt_upcrossingsBefore hN hab hn).ne) theorem sub_eq_zero_of_upcrossingsBefore_lt (hab : a < b) (hn : upcrossingsBefore a b f N ω < n) : stoppedValue f (upperCrossingTime a b f N (n + 1)) ω - stoppedValue f (lowerCrossingTime a b f N n) ω = 0 := by have : N ≤ upperCrossingTime a b f N n ω := by rw [upcrossingsBefore] at hn rw [← not_lt] exact fun h => not_le.2 hn (le_csSup (upperCrossingTime_lt_bddAbove hab) h) simp [stoppedValue, upperCrossingTime_stabilize' (Nat.le_succ n) this, lowerCrossingTime_stabilize' le_rfl (le_trans this upperCrossingTime_le_lowerCrossingTime)] theorem mul_upcrossingsBefore_le (hf : a ≤ f N ω) (hab : a < b) : (b - a) * upcrossingsBefore a b f N ω ≤ ∑ k ∈ Finset.range N, upcrossingStrat a b f N k ω * (f (k + 1) - f k) ω := by classical by_cases hN : N = 0 · simp [hN] simp_rw [upcrossingStrat, Finset.sum_mul, ← Set.indicator_mul_left _ _ (fun x ↦ (f (x + 1) - f x) ω), Pi.one_apply, Pi.sub_apply, one_mul] rw [Finset.sum_comm] have h₁ : ∀ k, ∑ n ∈ Finset.range N, (Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)).indicator (fun m => f (m + 1) ω - f m ω) n = stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω := by intro k rw [Finset.sum_indicator_eq_sum_filter, (_ : Finset.filter (fun i => i ∈ Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)) (Finset.range N) = Finset.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)), Finset.sum_Ico_eq_add_neg _ lowerCrossingTime_le_upperCrossingTime_succ, Finset.sum_range_sub fun n => f n ω, Finset.sum_range_sub fun n => f n ω, neg_sub, sub_add_sub_cancel] · rfl · ext i simp only [Set.mem_Ico, Finset.mem_filter, Finset.mem_range, Finset.mem_Ico, and_iff_right_iff_imp, and_imp] exact fun _ h => lt_of_lt_of_le h upperCrossingTime_le simp_rw [h₁] have h₂ : ∑ _k ∈ Finset.range (upcrossingsBefore a b f N ω), (b - a) ≤ ∑ k ∈ Finset.range N, (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by calc ∑ _k ∈ Finset.range (upcrossingsBefore a b f N ω), (b - a) ≤ ∑ k ∈ Finset.range (upcrossingsBefore a b f N ω), (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by gcongr ∑ k ∈ _, ?_ with i hi refine le_sub_of_le_upcrossingsBefore (zero_lt_iff.2 hN) hab ?_ rwa [Finset.mem_range] at hi _ ≤ ∑ k ∈ Finset.range N, (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by refine Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_subset.2 (upcrossingsBefore_le f ω hab)) fun i _ hi => ?_ by_cases hi' : i = upcrossingsBefore a b f N ω · subst hi' simp only [stoppedValue] rw [upperCrossingTime_eq_of_upcrossingsBefore_lt hab (Nat.lt_succ_self _)] by_cases heq : lowerCrossingTime a b f N (upcrossingsBefore a b f N ω) ω = N · rw [heq, sub_self] · rw [sub_nonneg] exact le_trans (stoppedValue_lowerCrossingTime heq) hf · rw [sub_eq_zero_of_upcrossingsBefore_lt hab] rw [Finset.mem_range, not_lt] at hi exact lt_of_le_of_ne hi (Ne.symm hi') refine le_trans ?_ h₂ rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_comm] theorem integral_mul_upcrossingsBefore_le_integral [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hfN : ∀ ω, a ≤ f N ω) (hfzero : 0 ≤ f 0) (hab : a < b) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[f N] := calc (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[∑ k ∈ Finset.range N, upcrossingStrat a b f N k * (f (k + 1) - f k)] := by rw [← integral_const_mul] refine integral_mono_of_nonneg ?_ ((hf.sum_upcrossingStrat_mul a b N).integrable N) ?_ · exact Eventually.of_forall fun ω => mul_nonneg (sub_nonneg.2 hab.le) (Nat.cast_nonneg _) · filter_upwards with ω simpa using mul_upcrossingsBefore_le (hfN ω) hab _ ≤ μ[f N] - μ[f 0] := hf.sum_mul_upcrossingStrat_le _ ≤ μ[f N] := (sub_le_self_iff _).2 (integral_nonneg hfzero) theorem crossing_pos_eq (hab : a < b) : upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = upperCrossingTime a b f N n ∧ lowerCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = lowerCrossingTime a b f N n := by have hab' : 0 < b - a := sub_pos.2 hab have hf : ∀ ω i, b - a ≤ (f i ω - a)⁺ ↔ b ≤ f i ω := by intro i ω refine ⟨fun h => ?_, fun h => ?_⟩ · rwa [← sub_le_sub_iff_right a, ← posPart_eq_of_posPart_pos (lt_of_lt_of_le hab' h)] · rw [← sub_le_sub_iff_right a] at h rwa [posPart_eq_self.2 (le_trans hab'.le h)] have hf' (ω i) : (f i ω - a)⁺ ≤ 0 ↔ f i ω ≤ a := by rw [posPart_nonpos, sub_nonpos] induction n with | zero => refine ⟨rfl, ?_⟩ simp +unfoldPartialApp only [lowerCrossingTime_zero, hitting, Set.mem_Icc, Set.mem_Iic] simp_all | succ k ih => have : upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N (k + 1) = upperCrossingTime a b f N (k + 1) := by ext ω simp only [upperCrossingTime_succ_eq, ← ih.2, hitting, Set.mem_Ici, tsub_le_iff_right] split_ifs with h₁ h₂ h₂ · simp_rw [← sub_le_iff_le_add, hf ω] · refine False.elim (h₂ ?_) simp_all only [Set.mem_Ici, not_true_eq_false] · refine False.elim (h₁ ?_) simp_all only [Set.mem_Ici] · rfl refine ⟨this, ?_⟩ ext ω simp only [lowerCrossingTime, this, hitting, Set.mem_Iic] split_ifs with h₁ h₂ h₂ · simp_rw [hf' ω] · refine False.elim (h₂ ?_) simp_all only [Set.mem_Iic, not_true_eq_false] · refine False.elim (h₁ ?_) simp_all only [Set.mem_Iic] · rfl theorem upcrossingsBefore_pos_eq (hab : a < b) : upcrossingsBefore 0 (b - a) (fun n ω => (f n ω - a)⁺) N ω = upcrossingsBefore a b f N ω := by simp_rw [upcrossingsBefore, (crossing_pos_eq hab).1] theorem mul_integral_upcrossingsBefore_le_integral_pos_part_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hab : a < b) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] := by refine le_trans (le_of_eq ?_) (integral_mul_upcrossingsBefore_le_integral (hf.sub_martingale (martingale_const _ _ _)).pos (fun ω => posPart_nonneg _) (fun ω => posPart_nonneg _) (sub_pos.2 hab)) simp_rw [sub_zero, ← upcrossingsBefore_pos_eq hab] rfl /-- **Doob's upcrossing estimate**: given a real valued discrete submartingale `f` and real values `a` and `b`, we have `(b - a) * 𝔼[upcrossingsBefore a b f N] ≤ 𝔼[(f N - a)⁺]` where `upcrossingsBefore a b f N` is the number of times the process `f` crossed from below `a` to above `b` before the time `N`. -/ theorem Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part [IsFiniteMeasure μ] (a b : ℝ) (hf : Submartingale f ℱ μ) (N : ℕ) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] := by by_cases hab : a < b · exact mul_integral_upcrossingsBefore_le_integral_pos_part_aux hf hab · rw [not_lt, ← sub_nonpos] at hab exact le_trans (mul_nonpos_of_nonpos_of_nonneg hab (by positivity)) (integral_nonneg fun ω => posPart_nonneg _) /-! ### Variant of the upcrossing estimate Now, we would like to prove a variant of the upcrossing estimate obtained by taking the supremum over $N$ of the original upcrossing estimate. Namely, we want the inequality $$ (b - a) \sup_N \mathbb{E}[U_N(a, b)] \le \sup_N \mathbb{E}[f_N]. $$ This inequality is central for the martingale convergence theorem as it provides a uniform bound for the upcrossings. We note that on top of taking the supremum on both sides of the inequality, we had also used the monotone convergence theorem on the left hand side to take the supremum outside of the integral. To do this, we need to make sure $U_N(a, b)$ is measurable and integrable. Integrability is easy to check as $U_N(a, b) ≤ N$ and so it suffices to show measurability. Indeed, by noting that $$ U_N(a, b) = \sum_{i = 1}^N \mathbf{1}_{\{U_N(a, b) < N\}} $$ $U_N(a, b)$ is measurable as $\{U_N(a, b) < N\}$ is a measurable set since $U_N(a, b)$ is a stopping time. -/ theorem upcrossingsBefore_eq_sum (hab : a < b) : upcrossingsBefore a b f N ω = ∑ i ∈ Finset.Ico 1 (N + 1), {n | upperCrossingTime a b f N n ω < N}.indicator 1 i := by by_cases hN : N = 0 · simp [hN] rw [← Finset.sum_Ico_consecutive _ (Nat.succ_le_succ zero_le') (Nat.succ_le_succ (upcrossingsBefore_le f ω hab))] have h₁ : ∀ k ∈ Finset.Ico 1 (upcrossingsBefore a b f N ω + 1), {n : ℕ | upperCrossingTime a b f N n ω < N}.indicator 1 k = 1 := by rintro k hk rw [Finset.mem_Ico] at hk rw [Set.indicator_of_mem] · rfl · exact upperCrossingTime_lt_of_le_upcrossingsBefore (zero_lt_iff.2 hN) hab (Nat.lt_succ_iff.1 hk.2) have h₂ : ∀ k ∈ Finset.Ico (upcrossingsBefore a b f N ω + 1) (N + 1), {n : ℕ | upperCrossingTime a b f N n ω < N}.indicator 1 k = 0 := by rintro k hk rw [Finset.mem_Ico, Nat.succ_le_iff] at hk rw [Set.indicator_of_notMem] simp only [Set.mem_setOf_eq, not_lt] exact (upperCrossingTime_eq_of_upcrossingsBefore_lt hab hk.1).symm.le rw [Finset.sum_congr rfl h₁, Finset.sum_congr rfl h₂, Finset.sum_const, Finset.sum_const, smul_eq_mul, mul_one, smul_eq_mul, mul_zero, Nat.card_Ico, Nat.add_succ_sub_one, add_zero, add_zero] theorem Adapted.measurable_upcrossingsBefore (hf : Adapted ℱ f) (hab : a < b) : Measurable (upcrossingsBefore a b f N) := by have : upcrossingsBefore a b f N = fun ω => ∑ i ∈ Finset.Ico 1 (N + 1), {n | upperCrossingTime a b f N n ω < N}.indicator 1 i := by ext ω exact upcrossingsBefore_eq_sum hab rw [this] exact Finset.measurable_fun_sum _ fun i _ => Measurable.indicator measurable_const <| ℱ.le N _ (hf.isStoppingTime_upperCrossingTime.measurableSet_lt_of_pred N) theorem Adapted.integrable_upcrossingsBefore [IsFiniteMeasure μ] (hf : Adapted ℱ f) (hab : a < b) : Integrable (fun ω => (upcrossingsBefore a b f N ω : ℝ)) μ := haveI : ∀ᵐ ω ∂μ, ‖(upcrossingsBefore a b f N ω : ℝ)‖ ≤ N := by filter_upwards with ω rw [Real.norm_eq_abs, Nat.abs_cast, Nat.cast_le] exact upcrossingsBefore_le _ _ hab ⟨Measurable.aestronglyMeasurable (measurable_from_top.comp (hf.measurable_upcrossingsBefore hab)), .of_bounded this⟩ /-- The number of upcrossings of a realization of a stochastic process (`upcrossings` takes value in `ℝ≥0∞` and so is allowed to be `∞`). -/ noncomputable def upcrossings [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (ω : Ω) : ℝ≥0∞ := ⨆ N, (upcrossingsBefore a b f N ω : ℝ≥0∞) theorem Adapted.measurable_upcrossings (hf : Adapted ℱ f) (hab : a < b) : Measurable (upcrossings a b f) := .iSup fun _ => measurable_from_top.comp (hf.measurable_upcrossingsBefore hab) theorem upcrossings_lt_top_iff : upcrossings a b f ω < ∞ ↔ ∃ k, ∀ N, upcrossingsBefore a b f N ω ≤ k := by have : upcrossings a b f ω < ∞ ↔ ∃ k : ℝ≥0, upcrossings a b f ω ≤ k := by constructor · intro h lift upcrossings a b f ω to ℝ≥0 using h.ne with r hr exact ⟨r, le_rfl⟩ · rintro ⟨k, hk⟩ exact lt_of_le_of_lt hk ENNReal.coe_lt_top simp_rw [this, upcrossings, iSup_le_iff] constructor <;> rintro ⟨k, hk⟩ · obtain ⟨m, hm⟩ := exists_nat_ge k refine ⟨m, fun N => Nat.cast_le.1 ((hk N).trans ?_)⟩ rwa [← ENNReal.coe_natCast, ENNReal.coe_le_coe] · refine ⟨k, fun N => ?_⟩ simp only [ENNReal.coe_natCast, Nat.cast_le, hk N] /-- A variant of Doob's upcrossing estimate obtained by taking the supremum on both sides. -/ theorem Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part [IsFiniteMeasure μ] (a b : ℝ) (hf : Submartingale f ℱ μ) : ENNReal.ofReal (b - a) * ∫⁻ ω, upcrossings a b f ω ∂μ ≤ ⨆ N, ∫⁻ ω, ENNReal.ofReal ((f N ω - a)⁺) ∂μ := by by_cases hab : a < b · simp_rw [upcrossings] have : ∀ N, ∫⁻ ω, ENNReal.ofReal ((f N ω - a)⁺) ∂μ = ENNReal.ofReal (∫ ω, (f N ω - a)⁺ ∂μ) := by intro N rw [ofReal_integral_eq_lintegral_ofReal] · exact (hf.sub_martingale (martingale_const _ _ _)).pos.integrable _ · exact Eventually.of_forall fun ω => posPart_nonneg _ rw [lintegral_iSup'] · simp_rw [this, ENNReal.mul_iSup, iSup_le_iff] intro N rw [(by simp : ∫⁻ ω, upcrossingsBefore a b f N ω ∂μ = ∫⁻ ω, ↑(upcrossingsBefore a b f N ω : ℝ≥0) ∂μ), lintegral_coe_eq_integral, ← ENNReal.ofReal_mul (sub_pos.2 hab).le] · simp_rw [NNReal.coe_natCast] exact (ENNReal.ofReal_le_ofReal (hf.mul_integral_upcrossingsBefore_le_integral_pos_part a b N)).trans (le_iSup (α := ℝ≥0∞) _ N) · simp only [NNReal.coe_natCast, hf.adapted.integrable_upcrossingsBefore hab] · exact fun n => measurable_from_top.comp_aemeasurable (hf.adapted.measurable_upcrossingsBefore hab).aemeasurable · filter_upwards with ω N M hNM rw [Nat.cast_le] exact upcrossingsBefore_mono hab hNM ω · rw [not_lt, ← sub_nonpos] at hab rw [ENNReal.ofReal_of_nonpos hab, zero_mul] exact zero_le _ end MeasureTheory
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.
Stalk.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Fangming Li -/ import Mathlib.AlgebraicGeometry.AffineScheme import Mathlib.AlgebraicGeometry.Morphisms.Preimmersion /-! # Stalks of a Scheme ## Main definitions and results - `AlgebraicGeometry.Scheme.fromSpecStalk`: The canonical morphism `Spec 𝒪_{X, x} ⟶ X`. - `AlgebraicGeometry.Scheme.range_fromSpecStalk`: The range of the map `Spec 𝒪_{X, x} ⟶ X` is exactly the `y`s that specialize to `x`. - `AlgebraicGeometry.SpecToEquivOfLocalRing`: Given a local ring `R` and scheme `X`, morphisms `Spec R ⟶ X` corresponds to pairs `(x, f)` where `x : X` and `f : 𝒪_{X, x} ⟶ R` is a local ring homomorphism. -/ namespace AlgebraicGeometry open CategoryTheory Opposite TopologicalSpace IsLocalRing universe u variable {X Y : Scheme.{u}} (f : X ⟶ Y) {U V : X.Opens} (hU : IsAffineOpen U) (hV : IsAffineOpen V) section fromSpecStalk /-- A morphism from `Spec(O_x)` to `X`, which is defined with the help of an affine open neighborhood `U` of `x`. -/ noncomputable def IsAffineOpen.fromSpecStalk {X : Scheme} {U : X.Opens} (hU : IsAffineOpen U) {x : X} (hxU : x ∈ U) : Spec (X.presheaf.stalk x) ⟶ X := Spec.map (X.presheaf.germ _ x hxU) ≫ hU.fromSpec /-- The morphism from `Spec(O_x)` to `X` given by `IsAffineOpen.fromSpec` does not depend on the affine open neighborhood of `x` we choose. -/ theorem IsAffineOpen.fromSpecStalk_eq (x : X) (hxU : x ∈ U) (hxV : x ∈ V) : hU.fromSpecStalk hxU = hV.fromSpecStalk hxV := by obtain ⟨U', h₁, h₂, h₃ : U' ≤ U ⊓ V⟩ := Opens.isBasis_iff_nbhd.mp (isBasis_affine_open X) (show x ∈ U ⊓ V from ⟨hxU, hxV⟩) transitivity fromSpecStalk h₁ h₂ · delta fromSpecStalk rw [← hU.map_fromSpec h₁ (homOfLE <| h₃.trans inf_le_left).op] erw [← Scheme.Spec_map (X.presheaf.map _).op, ← Scheme.Spec_map (X.presheaf.germ _ x h₂).op] rw [← Functor.map_comp_assoc, ← op_comp, TopCat.Presheaf.germ_res, Scheme.Spec_map, Quiver.Hom.unop_op] · delta fromSpecStalk rw [← hV.map_fromSpec h₁ (homOfLE <| h₃.trans inf_le_right).op] erw [← Scheme.Spec_map (X.presheaf.map _).op, ← Scheme.Spec_map (X.presheaf.germ _ x h₂).op] rw [← Functor.map_comp_assoc, ← op_comp, TopCat.Presheaf.germ_res, Scheme.Spec_map, Quiver.Hom.unop_op] /-- If `x` is a point of `X`, this is the canonical morphism from `Spec(O_x)` to `X`. -/ noncomputable def Scheme.fromSpecStalk (X : Scheme) (x : X) : Spec (X.presheaf.stalk x) ⟶ X := (isAffineOpen_opensRange (X.affineOpenCover.map x)).fromSpecStalk (X.affineOpenCover.covers x) @[simps over] noncomputable instance (X : Scheme.{u}) (x : X) : (Spec (X.presheaf.stalk x)).Over X := ⟨X.fromSpecStalk x⟩ noncomputable instance (X : Scheme.{u}) (x : X) : (Spec (X.presheaf.stalk x)).CanonicallyOver X where @[simp] theorem IsAffineOpen.fromSpecStalk_eq_fromSpecStalk {x : X} (hxU : x ∈ U) : hU.fromSpecStalk hxU = X.fromSpecStalk x := fromSpecStalk_eq .. instance IsAffineOpen.fromSpecStalk_isPreimmersion {X : Scheme.{u}} {U : Opens X} (hU : IsAffineOpen U) (x : X) (hx : x ∈ U) : IsPreimmersion (hU.fromSpecStalk hx) := by dsimp [IsAffineOpen.fromSpecStalk] haveI : IsPreimmersion (Spec.map (X.presheaf.germ U x hx)) := letI : Algebra Γ(X, U) (X.presheaf.stalk x) := (X.presheaf.germ U x hx).hom.toAlgebra haveI := hU.isLocalization_stalk ⟨x, hx⟩ IsPreimmersion.of_isLocalization (R := Γ(X, U)) (S := X.presheaf.stalk x) (hU.primeIdealOf ⟨x, hx⟩).asIdeal.primeCompl apply IsPreimmersion.comp instance {X : Scheme.{u}} (x : X) : IsPreimmersion (X.fromSpecStalk x) := IsAffineOpen.fromSpecStalk_isPreimmersion _ _ _ lemma IsAffineOpen.fromSpecStalk_closedPoint {U : Opens X} (hU : IsAffineOpen U) {x : X} (hxU : x ∈ U) : (hU.fromSpecStalk hxU).base (closedPoint (X.presheaf.stalk x)) = x := by rw [IsAffineOpen.fromSpecStalk, Scheme.comp_base_apply] rw [← hU.primeIdealOf_eq_map_closedPoint ⟨x, hxU⟩, hU.fromSpec_primeIdealOf ⟨x, hxU⟩] namespace Scheme @[simp] lemma fromSpecStalk_closedPoint {x : X} : (X.fromSpecStalk x).base (closedPoint (X.presheaf.stalk x)) = x := IsAffineOpen.fromSpecStalk_closedPoint _ _ lemma fromSpecStalk_app {x : X} (hxU : x ∈ U) : (X.fromSpecStalk x).app U = X.presheaf.germ U x hxU ≫ (ΓSpecIso (X.presheaf.stalk x)).inv ≫ (Spec (X.presheaf.stalk x)).presheaf.map (homOfLE le_top).op := by obtain ⟨_, ⟨V : X.Opens, hV, rfl⟩, hxV, hVU⟩ := (isBasis_affine_open X).exists_subset_of_mem_open hxU U.2 rw [← hV.fromSpecStalk_eq_fromSpecStalk hxV, IsAffineOpen.fromSpecStalk, Scheme.comp_app, hV.fromSpec_app_of_le _ hVU, ← X.presheaf.germ_res (homOfLE hVU) x hxV] simp [Category.assoc, ← ΓSpecIso_inv_naturality_assoc] lemma fromSpecStalk_appTop {x : X} : (X.fromSpecStalk x).appTop = X.presheaf.germ ⊤ x trivial ≫ (ΓSpecIso (X.presheaf.stalk x)).inv ≫ (Spec (X.presheaf.stalk x)).presheaf.map (homOfLE le_top).op := fromSpecStalk_app .. @[reassoc (attr := simp)] lemma Spec_map_stalkSpecializes_fromSpecStalk {x y : X} (h : x ⤳ y) : Spec.map (X.presheaf.stalkSpecializes h) ≫ X.fromSpecStalk y = X.fromSpecStalk x := by obtain ⟨_, ⟨U, hU, rfl⟩, hyU, -⟩ := (isBasis_affine_open X).exists_subset_of_mem_open (Set.mem_univ y) isOpen_univ have hxU : x ∈ U := h.mem_open U.2 hyU rw [← hU.fromSpecStalk_eq_fromSpecStalk hyU, ← hU.fromSpecStalk_eq_fromSpecStalk hxU, IsAffineOpen.fromSpecStalk, IsAffineOpen.fromSpecStalk, ← Category.assoc, ← Spec.map_comp, TopCat.Presheaf.germ_stalkSpecializes] instance {x y : X} (h : x ⤳ y) : (Spec.map (X.presheaf.stalkSpecializes h)).IsOver X where @[reassoc (attr := simp)] lemma Spec_map_stalkMap_fromSpecStalk {x} : Spec.map (f.stalkMap x) ≫ Y.fromSpecStalk _ = X.fromSpecStalk x ≫ f := by obtain ⟨_, ⟨U, hU, rfl⟩, hxU, -⟩ := (isBasis_affine_open Y).exists_subset_of_mem_open (Set.mem_univ (f.base x)) isOpen_univ obtain ⟨_, ⟨V, hV, rfl⟩, hxV, hVU⟩ := (isBasis_affine_open X).exists_subset_of_mem_open hxU (f ⁻¹ᵁ U).2 rw [← hU.fromSpecStalk_eq_fromSpecStalk hxU, ← hV.fromSpecStalk_eq_fromSpecStalk hxV, IsAffineOpen.fromSpecStalk, ← Spec.map_comp_assoc, Scheme.stalkMap_germ f _ x hxU, IsAffineOpen.fromSpecStalk, Spec.map_comp_assoc, ← X.presheaf.germ_res (homOfLE hVU) x hxV, Spec.map_comp_assoc, Category.assoc, ← Spec.map_comp_assoc (f.app _), Hom.app_eq_appLE, Hom.appLE_map, IsAffineOpen.Spec_map_appLE_fromSpec] instance [X.Over Y] {x} : Spec.map ((X ↘ Y).stalkMap x) |>.IsOver Y where lemma Spec_fromSpecStalk (R : CommRingCat) (x) : (Spec R).fromSpecStalk x = Spec.map ((ΓSpecIso R).inv ≫ (Spec R).presheaf.germ ⊤ x trivial) := by rw [← (isAffineOpen_top (Spec R)).fromSpecStalk_eq_fromSpecStalk (x := x) trivial, IsAffineOpen.fromSpecStalk, IsAffineOpen.fromSpec_top, isoSpec_Spec_inv, ← Spec.map_comp] -- This is not a simp lemma to respect the abstraction boundaries /-- A variant of `Spec_fromSpecStalk` that breaks abstraction boundaries. -/ lemma Spec_fromSpecStalk' (R : CommRingCat) (x) : (Spec R).fromSpecStalk x = Spec.map (StructureSheaf.toStalk R _) := Spec_fromSpecStalk _ _ @[stacks 01J7] lemma range_fromSpecStalk {x : X} : Set.range (X.fromSpecStalk x).base = { y | y ⤳ x } := by ext y constructor · rintro ⟨y, rfl⟩ exact ((IsLocalRing.specializes_closedPoint y).map (X.fromSpecStalk x).base.hom.2).trans (specializes_of_eq fromSpecStalk_closedPoint) · rintro (hy : y ⤳ x) have := fromSpecStalk_closedPoint (x := y) rw [← Spec_map_stalkSpecializes_fromSpecStalk hy] at this exact ⟨_, this⟩ /-- The canonical map `Spec 𝒪_{X, x} ⟶ U` given `x ∈ U ⊆ X`. -/ noncomputable def Opens.fromSpecStalkOfMem {X : Scheme.{u}} (U : X.Opens) (x : X) (hxU : x ∈ U) : Spec (X.presheaf.stalk x) ⟶ U := Spec.map (inv (U.ι.stalkMap ⟨x, hxU⟩)) ≫ U.toScheme.fromSpecStalk ⟨x, hxU⟩ @[reassoc (attr := simp)] lemma Opens.fromSpecStalkOfMem_ι {X : Scheme.{u}} (U : X.Opens) (x : X) (hxU : x ∈ U) : U.fromSpecStalkOfMem x hxU ≫ U.ι = X.fromSpecStalk x := by simp only [Opens.fromSpecStalkOfMem, Spec.map_inv, Category.assoc, IsIso.inv_comp_eq] exact (Scheme.Spec_map_stalkMap_fromSpecStalk U.ι (x := ⟨x, hxU⟩)).symm instance {X : Scheme.{u}} (U : X.Opens) (x : X) (hxU : x ∈ U) : (U.fromSpecStalkOfMem x hxU).IsOver X where @[reassoc] lemma fromSpecStalk_toSpecΓ (X : Scheme.{u}) (x : X) : X.fromSpecStalk x ≫ X.toSpecΓ = Spec.map (X.presheaf.germ ⊤ x trivial) := by rw [Scheme.toSpecΓ_naturality, ← SpecMap_ΓSpecIso_hom, ← Spec.map_comp, Scheme.fromSpecStalk_appTop] simp @[reassoc (attr := simp)] lemma Opens.fromSpecStalkOfMem_toSpecΓ {X : Scheme.{u}} (U : X.Opens) (x : X) (hxU : x ∈ U) : U.fromSpecStalkOfMem x hxU ≫ U.toSpecΓ = Spec.map (X.presheaf.germ U x hxU) := by rw [fromSpecStalkOfMem, Opens.toSpecΓ, Category.assoc, fromSpecStalk_toSpecΓ_assoc, ← Spec.map_comp, ← Spec.map_comp] congr 1 rw [IsIso.comp_inv_eq, Iso.inv_comp_eq] erw [stalkMap_germ U.ι U ⟨x, hxU⟩] rw [Opens.ι_app, Opens.topIso_hom, ← Functor.map_comp_assoc] exact (U.toScheme.presheaf.germ_res (homOfLE le_top) ⟨x, hxU⟩ (U := U.ι ⁻¹ᵁ U) hxU).symm end Scheme end fromSpecStalk variable (R : CommRingCat.{u}) [IsLocalRing R] section stalkClosedPointIso /-- For a local ring `(R, 𝔪)`, this is the isomorphism between the stalk of `Spec R` at `𝔪` and `R`. -/ noncomputable def stalkClosedPointIso : (Spec R).presheaf.stalk (closedPoint R) ≅ R := StructureSheaf.stalkIso _ _ ≪≫ (IsLocalization.atUnits R (closedPoint R).asIdeal.primeCompl fun _ ↦ not_not.mp).toRingEquiv.toCommRingCatIso.symm lemma stalkClosedPointIso_inv : (stalkClosedPointIso R).inv = StructureSheaf.toStalk R _ := by ext x exact StructureSheaf.localizationToStalk_of _ _ _ lemma ΓSpecIso_hom_stalkClosedPointIso_inv : (Scheme.ΓSpecIso R).hom ≫ (stalkClosedPointIso R).inv = (Spec R).presheaf.germ ⊤ (closedPoint _) trivial := by rw [stalkClosedPointIso_inv, ← Iso.eq_inv_comp] rfl @[reassoc (attr := simp)] lemma germ_stalkClosedPointIso_hom : (Spec R).presheaf.germ ⊤ (closedPoint _) trivial ≫ (stalkClosedPointIso R).hom = (Scheme.ΓSpecIso R).hom := by rw [← ΓSpecIso_hom_stalkClosedPointIso_inv, Category.assoc, Iso.inv_hom_id, Category.comp_id] lemma Spec_stalkClosedPointIso : Spec.map (stalkClosedPointIso R).inv = (Spec R).fromSpecStalk (closedPoint R) := by rw [stalkClosedPointIso_inv, Scheme.Spec_fromSpecStalk'] end stalkClosedPointIso section stalkClosedPointTo variable {R} (f : Spec R ⟶ X) namespace Scheme /-- Given a local ring `(R, 𝔪)` and a morphism `f : Spec R ⟶ X`, they induce a (local) ring homomorphism `φ : 𝒪_{X, f 𝔪} ⟶ R`. This is inverse to `φ ↦ Spec.map φ ≫ X.fromSpecStalk (f 𝔪)`. See `SpecToEquivOfLocalRing`. -/ noncomputable def stalkClosedPointTo : X.presheaf.stalk (f.base (closedPoint R)) ⟶ R := f.stalkMap (closedPoint R) ≫ (stalkClosedPointIso R).hom instance isLocalHom_stalkClosedPointTo : IsLocalHom (stalkClosedPointTo f).hom := inferInstanceAs <| IsLocalHom (f.stalkMap (closedPoint R) ≫ (stalkClosedPointIso R).hom).hom /-- Copy of `isLocalHom_stalkClosedPointTo` which unbundles the comm ring. Useful for use in combination with `CommRingCat.of K` for a field `K`. -/ instance isLocalHom_stalkClosedPointTo' {R : Type u} [CommRing R] [IsLocalRing R] (f : Spec(R) ⟶ X) : IsLocalHom (stalkClosedPointTo f).hom := isLocalHom_stalkClosedPointTo f lemma preimage_eq_top_of_closedPoint_mem {U : Opens X} (hU : f.base (closedPoint R) ∈ U) : f ⁻¹ᵁ U = ⊤ := IsLocalRing.closed_point_mem_iff.mp hU lemma stalkClosedPointTo_comp (g : X ⟶ Y) : stalkClosedPointTo (f ≫ g) = g.stalkMap _ ≫ stalkClosedPointTo f := by rw [stalkClosedPointTo, Scheme.stalkMap_comp] exact Category.assoc _ _ _ lemma germ_stalkClosedPointTo_Spec {R S : CommRingCat} [IsLocalRing S] (φ : R ⟶ S) : (Spec R).presheaf.germ ⊤ _ trivial ≫ stalkClosedPointTo (Spec.map φ) = (ΓSpecIso R).hom ≫ φ := by rw [stalkClosedPointTo, Scheme.stalkMap_germ_assoc, ← Iso.inv_comp_eq, ← ΓSpecIso_inv_naturality_assoc] simp_rw [Opens.map_top] rw [germ_stalkClosedPointIso_hom, Iso.inv_hom_id, Category.comp_id] @[reassoc] lemma germ_stalkClosedPointTo (U : Opens X) (hU : f.base (closedPoint R) ∈ U) : X.presheaf.germ U _ hU ≫ stalkClosedPointTo f = f.app U ≫ ((Spec R).presheaf.mapIso (eqToIso (preimage_eq_top_of_closedPoint_mem f hU).symm).op ≪≫ ΓSpecIso R).hom := by rw [stalkClosedPointTo, Scheme.stalkMap_germ_assoc, Iso.trans_hom] congr 1 rw [← Iso.eq_comp_inv, Category.assoc, ΓSpecIso_hom_stalkClosedPointIso_inv] simp only [Functor.mapIso_hom, Iso.op_hom, eqToIso.hom, TopCat.Presheaf.germ_res] @[reassoc] lemma germ_stalkClosedPointTo_Spec_fromSpecStalk {x : X} (f : X.presheaf.stalk x ⟶ R) [IsLocalHom f.hom] (U : Opens X) (hU) : X.presheaf.germ U _ hU ≫ stalkClosedPointTo (Spec.map f ≫ X.fromSpecStalk x) = X.presheaf.germ U x (by simpa using hU) ≫ f := by have : (Spec.map f ≫ X.fromSpecStalk x).base (closedPoint R) = x := by rw [comp_base_apply, Spec_closedPoint, fromSpecStalk_closedPoint] have : x ∈ U := this ▸ hU simp only [germ_stalkClosedPointTo, comp_app, fromSpecStalk_app (X := X) (x := x) this, Category.assoc, Iso.trans_hom, Functor.mapIso_hom, (Spec.map f).app_eq_appLE, Hom.appLE_map_assoc, Hom.map_appLE_assoc] simp_rw [← Opens.map_top (Spec.map f).base] rw [← (Spec.map f).app_eq_appLE, ΓSpecIso_naturality, Iso.inv_hom_id_assoc] lemma stalkClosedPointTo_fromSpecStalk (x : X) : stalkClosedPointTo (X.fromSpecStalk x) = (X.presheaf.stalkCongr (by rw [fromSpecStalk_closedPoint]; rfl)).hom := by refine TopCat.Presheaf.stalk_hom_ext _ fun U hxU ↦ ?_ simp only [TopCat.Presheaf.stalkCongr_hom, TopCat.Presheaf.germ_stalkSpecializes] have : X.fromSpecStalk x = Spec.map (𝟙 (X.presheaf.stalk x)) ≫ X.fromSpecStalk x := by simp convert germ_stalkClosedPointTo_Spec_fromSpecStalk (𝟙 (X.presheaf.stalk x)) U hxU @[reassoc] lemma Spec_stalkClosedPointTo_fromSpecStalk : Spec.map (stalkClosedPointTo f) ≫ X.fromSpecStalk _ = f := by obtain ⟨_, ⟨U, hU, rfl⟩, hxU, -⟩ := (isBasis_affine_open X).exists_subset_of_mem_open (Set.mem_univ (f.base (closedPoint R))) isOpen_univ have := IsAffineOpen.Spec_map_appLE_fromSpec f hU (isAffineOpen_top _) (preimage_eq_top_of_closedPoint_mem f hxU).ge rw [IsAffineOpen.fromSpec_top, Iso.eq_inv_comp, isoSpec_Spec_hom] at this rw [← hU.fromSpecStalk_eq_fromSpecStalk hxU, IsAffineOpen.fromSpecStalk, ← Spec.map_comp_assoc, germ_stalkClosedPointTo] simpa only [Iso.trans_hom, Functor.mapIso_hom, Iso.op_hom, Category.assoc, Hom.app_eq_appLE, Hom.appLE_map_assoc, Spec.map_comp_assoc] end Scheme end stalkClosedPointTo variable {R} omit [IsLocalRing R] in /-- useful lemma for applications of `SpecToEquivOfLocalRing` -/ lemma SpecToEquivOfLocalRing_eq_iff {f₁ f₂ : Σ x, { f : X.presheaf.stalk x ⟶ R // IsLocalHom f.hom }} : f₁ = f₂ ↔ ∃ h₁ : f₁.1 = f₂.1, f₁.2.1 = (X.presheaf.stalkCongr (by rw [h₁]; rfl)).hom ≫ f₂.2.1 := by constructor · rintro rfl; simp · obtain ⟨x₁, ⟨f₁, h₁⟩⟩ := f₁ obtain ⟨x₂, ⟨f₂, h₂⟩⟩ := f₂ rintro ⟨rfl : x₁ = x₂, e : f₁ = _⟩ simp [e] variable (X R) /-- Given a local ring `R` and scheme `X`, morphisms `Spec R ⟶ X` corresponds to pairs `(x, f)` where `x : X` and `f : 𝒪_{X, x} ⟶ R` is a local ring homomorphism. -/ @[simps] noncomputable def SpecToEquivOfLocalRing : (Spec R ⟶ X) ≃ Σ x, { f : X.presheaf.stalk x ⟶ R // IsLocalHom f.hom } where toFun f := ⟨f.base (closedPoint R), Scheme.stalkClosedPointTo f, inferInstance⟩ invFun xf := Spec.map xf.2.1 ≫ X.fromSpecStalk xf.1 left_inv := Scheme.Spec_stalkClosedPointTo_fromSpecStalk right_inv xf := by obtain ⟨x, ⟨f, hf⟩⟩ := xf symm refine SpecToEquivOfLocalRing_eq_iff.mpr ⟨?_, ?_⟩ · simp only [Scheme.comp_coeBase, TopCat.coe_comp, Function.comp_apply, Spec_closedPoint, Scheme.fromSpecStalk_closedPoint] · refine TopCat.Presheaf.stalk_hom_ext _ fun U hxU ↦ ?_ simp only [Scheme.germ_stalkClosedPointTo_Spec_fromSpecStalk, TopCat.Presheaf.stalkCongr_hom, TopCat.Presheaf.germ_stalkSpecializes_assoc] end AlgebraicGeometry
Canonical.lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro -/ import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Algebra.Order.Sub.Basic import Mathlib.Algebra.Ring.Parity /-! # Canonically ordered rings and semirings. -/ open Function universe u variable {R : Type u} set_option linter.deprecated false in /-- A canonically ordered commutative semiring is an ordered, commutative semiring in which `a ≤ b` iff there exists `c` with `b = a + c`. This is satisfied by the natural numbers, for example, but not the integers or other ordered groups. -/ @[deprecated "Use `[OrderedCommSemiring R] [CanonicallyOrderedAdd R] [NoZeroDivisors R]` instead." (since := "2025-01-13")] structure CanonicallyOrderedCommSemiring (R : Type*) extends CanonicallyOrderedAddCommMonoid R, CommSemiring R where /-- No zero divisors. -/ protected eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : R}, a * b = 0 → a = 0 ∨ b = 0 attribute [nolint docBlame] CanonicallyOrderedCommSemiring.toCommSemiring -- see Note [lower instance priority] instance (priority := 10) CanonicallyOrderedAdd.toZeroLEOneClass [AddZeroClass R] [One R] [LE R] [CanonicallyOrderedAdd R] : ZeroLEOneClass R where zero_le_one := zero_le _ -- this holds more generally if we refactor `Odd` to use -- either `2 • t` or `t + t` instead of `2 * t`. lemma Odd.pos [Semiring R] [PartialOrder R] [CanonicallyOrderedAdd R] [Nontrivial R] {a : R} : Odd a → 0 < a := by rintro ⟨k, rfl⟩; simp namespace CanonicallyOrderedAdd -- see Note [lower instance priority] instance (priority := 100) toMulLeftMono [NonUnitalNonAssocSemiring R] [LE R] [CanonicallyOrderedAdd R] : MulLeftMono R := by refine ⟨fun a b c h => ?_⟩ dsimp rcases exists_add_of_le h with ⟨c, rfl⟩ rw [mul_add] apply self_le_add_right -- see Note [lower instance priority] instance (priority := 100) toMulRightMono [NonUnitalNonAssocSemiring R] [LE R] [CanonicallyOrderedAdd R] : MulRightMono R := by refine ⟨fun a b c h => ?_⟩ dsimp [swap] rcases exists_add_of_le h with ⟨c, rfl⟩ rw [add_mul] apply self_le_add_right variable [CommSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R] -- TODO: make it an instance lemma toIsOrderedMonoid : IsOrderedMonoid R where mul_le_mul_left _ _ := mul_le_mul_left' -- TODO: make it an instance lemma toIsOrderedRing : IsOrderedRing R where zero_le_one := zero_le _ add_le_add_left _ _ := add_le_add_left mul_le_mul_of_nonneg_left _ _ _ h _ := mul_le_mul_left' h _ mul_le_mul_of_nonneg_right _ _ _ h _ := mul_le_mul_right' h _ @[simp] protected theorem mul_pos [NoZeroDivisors R] {a b : R} : 0 < a * b ↔ 0 < a ∧ 0 < b := by simp only [pos_iff_ne_zero, ne_eq, mul_eq_zero, not_or] lemma pow_pos [NoZeroDivisors R] {a : R} (ha : 0 < a) (n : ℕ) : 0 < a ^ n := pos_iff_ne_zero.2 <| pow_ne_zero _ ha.ne' protected lemma mul_lt_mul_of_lt_of_lt [PosMulStrictMono R] {a b c d : R} (hab : a < b) (hcd : c < d) : a * c < b * d := by -- TODO: This should be an instance but it currently times out have := posMulStrictMono_iff_mulPosStrictMono.1 ‹_› obtain rfl | hc := eq_zero_or_pos c · rw [mul_zero] exact mul_pos ((zero_le _).trans_lt hab) hcd · exact mul_lt_mul_of_pos' hab hcd hc ((zero_le _).trans_lt hab) end CanonicallyOrderedAdd section Sub section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R] [Sub R] [OrderedSub R] [IsTotal R (· ≤ ·)] namespace AddLECancellable protected theorem mul_tsub {a b c : R} (h : AddLECancellable (a * c)) : a * (b - c) = a * b - a * c := by obtain (hbc | hcb) := total_of (· ≤ ·) b c · rw [tsub_eq_zero_iff_le.2 hbc, mul_zero, tsub_eq_zero_iff_le.2 (mul_le_mul_left' hbc a)] · apply h.eq_tsub_of_add_eq rw [← mul_add, tsub_add_cancel_of_le hcb] protected theorem tsub_mul [MulRightMono R] {a b c : R} (h : AddLECancellable (b * c)) : (a - b) * c = a * c - b * c := by obtain (hab | hba) := total_of (· ≤ ·) a b · rw [tsub_eq_zero_iff_le.2 hab, zero_mul, tsub_eq_zero_iff_le.2 (mul_le_mul_right' hab c)] · apply h.eq_tsub_of_add_eq rw [← add_mul, tsub_add_cancel_of_le hba] end AddLECancellable variable [AddLeftReflectLE R] theorem mul_tsub (a b c : R) : a * (b - c) = a * b - a * c := Contravariant.AddLECancellable.mul_tsub theorem tsub_mul [MulRightMono R] (a b c : R) : (a - b) * c = a * c - b * c := Contravariant.AddLECancellable.tsub_mul end NonUnitalNonAssocSemiring section NonAssocSemiring variable [NonAssocSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R] [Sub R] [OrderedSub R] [IsTotal R (· ≤ ·)] lemma mul_tsub_one [AddLeftReflectLE R] (a b : R) : a * (b - 1) = a * b - a := by rw [mul_tsub, mul_one] lemma tsub_one_mul [MulRightMono R] [AddLeftReflectLE R] (a b : R) : (a - 1) * b = a * b - b := by rw [tsub_mul, one_mul] end NonAssocSemiring section CommSemiring variable [CommSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R] [Sub R] [OrderedSub R] [IsTotal R (· ≤ ·)] [AddLeftReflectLE R] /-- The `tsub` version of `mul_self_sub_mul_self`. Notably, this holds for `Nat` and `NNReal`. -/ theorem mul_self_tsub_mul_self (a b : R) : a * a - b * b = (a + b) * (a - b) := by rw [mul_tsub, add_mul, add_mul, tsub_add_eq_tsub_tsub, mul_comm b a, add_tsub_cancel_right] /-- The `tsub` version of `sq_sub_sq`. Notably, this holds for `Nat` and `NNReal`. -/ theorem sq_tsub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by rw [sq, sq, mul_self_tsub_mul_self] theorem mul_self_tsub_one (a : R) : a * a - 1 = (a + 1) * (a - 1) := by rw [← mul_self_tsub_mul_self, mul_one] end CommSemiring end Sub
Basic.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell -/ import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Order.Monotone.Defs /-! # Binomial coefficients This file defines binomial coefficients and proves simple lemmas (i.e. those not requiring more imports). For the lemma that `n.choose k` counts the `k`-element-subsets of an `n`-element set, see `Fintype.card_powersetCard` in `Mathlib/Data/Finset/Powerset.lean`. ## Main definition and results * `Nat.choose`: binomial coefficients, defined inductively * `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)` * `Nat.choose_symm`: symmetry of binomial coefficients * `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k` * `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2` * `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements for the ascending factorial. * `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations. The fact that this is indeed the correct counting function for multisets is proved in `Sym.card_sym_eq_multichoose` in `Data.Sym.Card`. * `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`. This is central to the "stars and bars" technique in informal mathematics, where we switch between counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements ("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail. ## Tags binomial coefficient, combination, multicombination, stars and bars -/ namespace Nat /-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial coefficients. For the fact that this is the number of `k`-element-subsets of an `n`-element set, see `Fintype.card_powersetCard`. -/ def choose : ℕ → ℕ → ℕ | _, 0 => 1 | 0, _ + 1 => 0 | n + 1, k + 1 => choose n k + choose n (k + 1) @[simp] theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl @[simp] theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 := rfl theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) := rfl theorem choose_succ_left (n k : ℕ) (hk : 0 < k) : choose (n + 1) k = choose n (k - 1) + choose n k := by obtain ⟨l, rfl⟩ : ∃ l, k = l + 1 := Nat.exists_eq_add_of_le' hk rfl theorem choose_succ_right (n k : ℕ) (hn : 0 < n) : choose n (k + 1) = choose (n - 1) k + choose (n - 1) (k + 1) := by obtain ⟨l, rfl⟩ : ∃ l, n = l + 1 := Nat.exists_eq_add_of_le' hn rfl theorem choose_eq_choose_pred_add {n k : ℕ} (hn : 0 < n) (hk : 0 < k) : choose n k = choose (n - 1) (k - 1) + choose (n - 1) k := by obtain ⟨l, rfl⟩ : ∃ l, k = l + 1 := Nat.exists_eq_add_of_le' hk rw [choose_succ_right _ _ hn, Nat.add_one_sub_one] theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0 | _, 0, hk => absurd hk (Nat.not_lt_zero _) | 0, _ + 1, _ => choose_zero_succ _ | n + 1, k + 1, hk => by have hnk : n < k := lt_of_succ_lt_succ hk have hnk1 : n < k + 1 := lt_of_succ_lt hk rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1] @[simp] theorem choose_self (n : ℕ) : choose n n = 1 := by induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)] @[simp] theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 := choose_eq_zero_of_lt (lt_succ_self _) @[simp] lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm] -- The `n+1`-st triangle number is `n` more than the `n`-th triangle number theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm] cases n <;> rfl; apply zero_lt_succ /-- `choose n 2` is the `n`-th triangle number. -/ theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by induction' n with n ih · simp · rw [triangle_succ n, choose, ih] simp [Nat.add_comm] theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k | 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide | n + 1, 0, _ => by simp | _ + 1, _ + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _ theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k := ⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩ theorem choose_ne_zero_iff {n k : ℕ} : n.choose k ≠ 0 ↔ k ≤ n := not_iff_not.1 <| by simp [choose_eq_zero_iff] lemma choose_ne_zero {n k : ℕ} (h : k ≤ n) : n.choose k ≠ 0 := (choose_pos h).ne' theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k | 0, 0 => by decide | 0, k + 1 => by simp [choose] | n + 1, 0 => by simp [choose, mul_succ, Nat.add_comm] | n + 1, k + 1 => by rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ← succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul] theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n ! | 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk] | n + 1, 0, _ => by simp | n + 1, succ k, hk => by rcases lt_or_eq_of_le hk with hk₁ | hk₁ · have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ] have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk) rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul, Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc, ← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm] · rw [hk₁]; simp [Nat.mul_comm, choose, Nat.sub_self] theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) : n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) := have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos] Nat.mul_right_cancel h <| calc n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) = n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc, Nat.mul_comm (n - k)!, Nat.mul_comm s !] _ = n ! := by rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn] _ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _), choose_mul_factorial_mul_factorial (hsk.trans hkn)] _ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc, Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc] theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) : choose n k = n ! / (k ! * (n - k)!) := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc] exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right, Nat.mul_comm] theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) : (i + j).choose j * i ! * j ! = (i + j)! := by rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right, Nat.mul_right_comm] theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _ theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by suffices i ! * (i + j - i) ! ∣ (i + j)! by rwa [Nat.add_sub_cancel_left i j] at this exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _) @[simp] theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _), Nat.sub_sub_self hk, Nat.mul_comm] theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by suffices choose n (n - b) = choose n b by rw [h, Nat.add_sub_cancel_right] at this; rwa [h] exact choose_symm (h ▸ le_add_left _ _) theorem choose_symm_add {a b : ℕ} : choose (a + b) a = choose (a + b) b := choose_symm_of_eq_add rfl theorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := by apply choose_symm_of_eq_add rw [Nat.add_comm m 1, Nat.add_assoc 1 m m, Nat.add_comm (2 * m) 1, Nat.two_mul m] theorem choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := by have e : (n + 1) * choose n k = choose n (k + 1) * (k + 1) + choose n k * (k + 1) := by rw [← Nat.add_mul, Nat.add_comm (choose _ _), ← choose_succ_succ, succ_mul_choose_eq] rw [← Nat.sub_eq_of_eq_add e, Nat.mul_comm, ← Nat.mul_sub_left_distrib, Nat.add_sub_add_right] @[simp] theorem choose_succ_self_right : ∀ n : ℕ, (n + 1).choose n = n + 1 | 0 => rfl | n + 1 => by rw [choose_succ_succ, choose_succ_self_right n, choose_self] theorem choose_mul_succ_eq (n k : ℕ) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) := by cases k with | zero => simp | succ k => obtain hk | hk := le_or_gt (k + 1) (n + 1) · rw [choose_succ_succ, Nat.add_mul, succ_sub_succ, ← choose_succ_right_eq, ← succ_sub_succ, Nat.mul_sub_left_distrib, Nat.add_sub_cancel' (Nat.mul_le_mul_left _ hk)] · rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), Nat.zero_mul, Nat.zero_mul] theorem ascFactorial_eq_factorial_mul_choose (n k : ℕ) : (n + 1).ascFactorial k = k ! * (n + k).choose k := by rw [Nat.mul_comm] apply Nat.mul_right_cancel (n + k - k).factorial_pos rw [choose_mul_factorial_mul_factorial <| Nat.le_add_left k n, Nat.add_sub_cancel_right, ← factorial_mul_ascFactorial, Nat.mul_comm] theorem ascFactorial_eq_factorial_mul_choose' (n k : ℕ) : n.ascFactorial k = k ! * (n + k - 1).choose k := by cases n · cases k · rw [ascFactorial_zero, choose_zero_right, factorial_zero, Nat.mul_one] · simp only [zero_ascFactorial, Nat.zero_add, succ_sub_succ_eq_sub, Nat.sub_zero, choose_succ_self, Nat.mul_zero] rw [ascFactorial_eq_factorial_mul_choose] simp only [succ_add_sub_one] theorem factorial_dvd_ascFactorial (n k : ℕ) : k ! ∣ n.ascFactorial k := ⟨(n + k - 1).choose k, ascFactorial_eq_factorial_mul_choose' _ _⟩ theorem choose_eq_asc_factorial_div_factorial (n k : ℕ) : (n + k).choose k = (n + 1).ascFactorial k / k ! := by apply Nat.mul_left_cancel k.factorial_pos rw [← ascFactorial_eq_factorial_mul_choose] exact (Nat.mul_div_cancel' <| factorial_dvd_ascFactorial _ _).symm theorem choose_eq_asc_factorial_div_factorial' (n k : ℕ) : (n + k - 1).choose k = n.ascFactorial k / k ! := Nat.eq_div_of_mul_eq_right k.factorial_ne_zero (ascFactorial_eq_factorial_mul_choose' _ _).symm theorem descFactorial_eq_factorial_mul_choose (n k : ℕ) : n.descFactorial k = k ! * n.choose k := by obtain h | h := Nat.lt_or_ge n k · rw [descFactorial_eq_zero_iff_lt.2 h, choose_eq_zero_of_lt h, Nat.mul_zero] rw [Nat.mul_comm] apply Nat.mul_right_cancel (n - k).factorial_pos rw [choose_mul_factorial_mul_factorial h, ← factorial_mul_descFactorial h, Nat.mul_comm] theorem factorial_dvd_descFactorial (n k : ℕ) : k ! ∣ n.descFactorial k := ⟨n.choose k, descFactorial_eq_factorial_mul_choose _ _⟩ theorem choose_eq_descFactorial_div_factorial (n k : ℕ) : n.choose k = n.descFactorial k / k ! := Nat.eq_div_of_mul_eq_right k.factorial_ne_zero (descFactorial_eq_factorial_mul_choose _ _).symm /-- A faster implementation of `choose`, to be used during bytecode evaluation and in compiled code. -/ def fast_choose n k := Nat.descFactorial n k / Nat.factorial k @[csimp] lemma choose_eq_fast_choose : Nat.choose = fast_choose := funext (fun _ => funext (Nat.choose_eq_descFactorial_div_factorial _)) /-! ### Inequalities -/ /-- Show that `Nat.choose` is increasing for small values of the right argument. -/ theorem choose_le_succ_of_lt_half_left {r n : ℕ} (h : r < n / 2) : choose n r ≤ choose n (r + 1) := by refine Nat.le_of_mul_le_mul_right ?_ (Nat.sub_pos_of_lt (h.trans_le (n.div_le_self 2))) rw [← choose_succ_right_eq] apply Nat.mul_le_mul_left rw [← Nat.lt_iff_add_one_le, Nat.lt_sub_iff_add_lt, ← Nat.mul_two] exact lt_of_lt_of_le (Nat.mul_lt_mul_of_pos_right h Nat.zero_lt_two) (n.div_mul_le_self 2) /-- Show that for small values of the right argument, the middle value is largest. -/ private theorem choose_le_middle_of_le_half_left {n r : ℕ} (hr : r ≤ n / 2) : choose n r ≤ choose n (n / 2) := by induction hr using decreasingInduction with | self => rfl | of_succ k hk ih => exact (choose_le_succ_of_lt_half_left hk).trans ih /-- `choose n r` is maximised when `r` is `n/2`. -/ theorem choose_le_middle (r n : ℕ) : choose n r ≤ choose n (n / 2) := by rcases le_or_gt r n with b | b · rcases le_or_gt r (n / 2) with a | h · apply choose_le_middle_of_le_half_left a · rw [← choose_symm b] apply choose_le_middle_of_le_half_left omega · rw [choose_eq_zero_of_lt b] apply zero_le /-! #### Inequalities about increasing the first argument -/ theorem choose_le_succ (a c : ℕ) : choose a c ≤ choose a.succ c := by cases c <;> simp [Nat.choose_succ_succ] theorem choose_le_add (a b c : ℕ) : choose a c ≤ choose (a + b) c := by induction' b with b_n b_ih · simp exact le_trans b_ih (choose_le_succ (a + b_n) c) theorem choose_le_choose {a b : ℕ} (c : ℕ) (h : a ≤ b) : choose a c ≤ choose b c := Nat.add_sub_cancel' h ▸ choose_le_add a (b - a) c theorem choose_mono (b : ℕ) : Monotone fun a => choose a b := fun _ _ => choose_le_choose b /-! #### Multichoose Whereas `choose n k` is the number of subsets of cardinality `k` from a type of cardinality `n`, `multichoose n k` is the number of multisets of cardinality `k` from a type of cardinality `n`. Alternatively, whereas `choose n k` counts the number of combinations, i.e. ways to select `k` items (up to permutation) from `n` items without replacement, `multichoose n k` counts the number of multicombinations, i.e. ways to select `k` items (up to permutation) from `n` items with replacement. Note that `multichoose` is *not* the multinomial coefficient, although it can be computed in terms of multinomial coefficients. For details see https://mathworld.wolfram.com/Multichoose.html TODO: Prove that `choose (-n) k = (-1)^k * multichoose n k`, where `choose` is the generalized binomial coefficient. <https://github.com/leanprover-community/mathlib/pull/15072#issuecomment-1171415738> -/ /-- `multichoose n k` is the number of multisets of cardinality `k` from a type of cardinality `n`. -/ def multichoose : ℕ → ℕ → ℕ | _, 0 => 1 | 0, _ + 1 => 0 | n + 1, k + 1 => multichoose n (k + 1) + multichoose (n + 1) k @[simp] theorem multichoose_zero_right (n : ℕ) : multichoose n 0 = 1 := by cases n <;> simp [multichoose] @[simp] theorem multichoose_zero_succ (k : ℕ) : multichoose 0 (k + 1) = 0 := by simp [multichoose] theorem multichoose_succ_succ (n k : ℕ) : multichoose (n + 1) (k + 1) = multichoose n (k + 1) + multichoose (n + 1) k := by simp [multichoose] @[simp] theorem multichoose_one (k : ℕ) : multichoose 1 k = 1 := by induction' k with k IH; · simp simp [multichoose_succ_succ 0 k, IH] @[simp] theorem multichoose_two (k : ℕ) : multichoose 2 k = k + 1 := by induction' k with k IH; · simp rw [multichoose, IH] simp [Nat.add_comm] @[simp] theorem multichoose_one_right (n : ℕ) : multichoose n 1 = n := by induction' n with n IH; · simp simp [multichoose_succ_succ n 0, IH] theorem multichoose_eq : ∀ n k : ℕ, multichoose n k = (n + k - 1).choose k | _, 0 => by simp | 0, k + 1 => by simp | n + 1, k + 1 => by have : n + (k + 1) < (n + 1) + (k + 1) := Nat.add_lt_add_right (Nat.lt_succ_self _) _ have : (n + 1) + k < (n + 1) + (k + 1) := Nat.add_lt_add_left (Nat.lt_succ_self _) _ rw [multichoose_succ_succ, Nat.add_comm, Nat.succ_add_sub_one, ← Nat.add_assoc, Nat.choose_succ_succ] simp [multichoose_eq n (k+1), multichoose_eq (n+1) k] end Nat
bigop.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 fintype tuple finfun. (******************************************************************************) (* Finitely iterated operators *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file provides a generic definition for iterating an operator over a *) (* set of indices (bigop); this big operator is parameterized by the return *) (* type (R), the type of indices (I), the operator (op), the default value on *) (* empty lists (idx), the range of indices (r), the filter applied on this *) (* range (P) and the expression we are iterating (F). The definition is not *) (* to be used directly, but via the wide range of notations provided and *) (* which support a natural use of big operators. *) (* To improve performance of the Coq typechecker on large expressions, the *) (* bigop constant is OPAQUE. It can however be unlocked to reveal the *) (* transparent constant reducebig, to let Coq expand summation on an explicit *) (* sequence with an explicit test. *) (* The lemmas can be classified according to the operator being iterated: *) (* 1. Results independent of the operator: extensionality with respect to *) (* the range of indices, to the filtering predicate or to the expression *) (* being iterated; reindexing, widening or narrowing of the range of *) (* indices; we provide lemmas for the special cases where indices are *) (* natural numbers or bounded natural numbers ("ordinals"). We supply *) (* several "functional" induction principles that can be used with the *) (* ssreflect 1.3 "elim" tactic to do induction over the index range for *) (* up to 3 bigops simultaneously. *) (* 2. Results depending on the properties of the operator: *) (* We distinguish: *) (* - semigroup laws (op is associative) *) (* - commutative semigroup laws (semigroup laws, op is commutative) *) (* - monoid laws (semigroup laws, idx is an identity element) *) (* - abelian monoid laws (op is also commutative) *) (* - laws with a distributive operation (semirings) *) (* Examples of such results are splitting, permuting, and exchanging *) (* bigops. *) (* A special section is dedicated to big operators on natural numbers. *) (******************************************************************************) (* Notations: *) (* The general form for iterated operators is *) (* <bigop>_<range> <general_term> *) (* - <bigop> is one of \big[op/idx], \sum, \prod, or \max (see below). *) (* - <general_term> can be any expression. *) (* - <range> binds an index variable in <general_term>; <range> is one of *) (* (i <- s) i ranges over the sequence s. *) (* (m <= i < n) i ranges over the nat interval m, m+1, ..., n-1. *) (* (i < n) i ranges over the (finite) type 'I_n (i.e., ordinal n). *) (* (i : T) i ranges over the finite type T. *) (* i or (i) i ranges over its (inferred) finite type. *) (* (i in A) i ranges over the elements that satisfy the collective *) (* predicate A (the domain of A must be a finite type). *) (* (i <- s | <condition>) limits the range to the i for which <condition> *) (* holds. <condition> can be any expression that coerces to *) (* bool, and may mention the bound index i. All six kinds of *) (* ranges above can have a <condition> part. *) (* - One can use the "\big[op/idx]" notations for any operator. *) (* - BIG_F and BIG_P are pattern abbreviations for the <general_term> and *) (* <condition> part of a \big ... expression; for (i in A) and (i in A | C) *) (* ranges the term matched by BIG_P will include the i \in A condition. *) (* - The (locked) head constant of a \big notation is bigop. *) (* - The "\sum", "\prod" and "\max" notations in the %N scope are used for *) (* natural numbers with addition, multiplication and maximum (and their *) (* corresponding neutral elements), respectively. *) (* - The "\sum" and "\prod" reserved notations are overloaded in ssralg in *) (* the %R scope; in mxalgebra, vector & falgebra in the %MS and %VS scopes; *) (* "\prod" is also overloaded in fingroup, in the %g and %G scopes. *) (* - We reserve "\bigcup" and "\bigcap" notations for iterated union and *) (* intersection (of sets, groups, vector spaces, etc.). *) (******************************************************************************) (* Tips for using lemmas in this file: *) (* To apply a lemma for a specific operator: if no special property is *) (* required for the operator, simply apply the lemma; if the lemma needs *) (* certain properties for the operator, make sure the appropriate instances *) (* are declared using, e.g., Check addn : Monoid.law _. to check that addn *) (* is equipped with the monoid laws. *) (******************************************************************************) (* Interfaces for operator properties are packaged in the SemiGroup and *) (* Monoid submodules: *) (* SemiGroup.law == interface (keyed on the operator) for associative *) (* operators *) (* The HB class is SemiGroup. *) (* SemiGroup.com_law == interface for associative and commutative operators *) (* The HB class is SemiGroup.ComLaw. *) (* Monoid.law idx == interface for associative operators with identity *) (* element idx *) (* The HB class is Monoid.Law. *) (* Monoid.com_law idx == extension of Monoid.law for operators that are also *) (* commutative *) (* The HB class is Monoid.ComLaw. *) (* Monoid.mul_law abz == interface for operators with absorbing (zero) *) (* element abz *) (* The HB class is Monoid.MulLaw. *) (* Monoid.add_law idx mop == extension of Monoid.com_law for operators over *) (* which operation mop distributes (mop will often also *) (* have a Monoid.mul_law idx structure) *) (* The HB class is Monoid.AddLaw. *) (* SemiGroup.Theory == submodule containing basic generic algebra lemmas *) (* for operators satisfying the SemiGroup interfaces *) (* Monoid.Theory == submodule containing basic generic algebra lemmas *) (* for operators satisfying the Monoid interfaces, *) (* exports SemiGroup.Theory *) (* Monoid.simpm == generic monoid simplification rewrite multirule *) (* oAC op == convert an AC operator op : T -> T -> T *) (* to a Monoid.com_law on option T *) (* Monoid structures are predeclared for many basic operators: (_ && _)%B, *) (* (_ || _)%B, (_ (+) _)%B (exclusive or), (_ + _)%N, (_ * _)%N, maxn, *) (* gcdn, lcmn and (_ ++ _)%SEQ (list concatenation) *) (******************************************************************************) (* Reference: Y. Bertot, G. Gonthier, S. Ould Biha, I. Pasca, Canonical Big *) (* Operators, TPHOLs 2008, LNCS vol. 5170, Springer, available at: *) (* http://hal.inria.fr/docs/00/33/11/93/PDF/main.pdf *) (******************************************************************************) (* Examples of use in: poly.v, matrix.v *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope big_scope. Reserved Notation "\big [ op / idx ]_ i F" (at level 36, F at level 36, op, idx at level 10, i at level 0, right associativity, format "'[' \big [ op / idx ]_ i '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( i <- r | P ) F" (F at level 36, i, r at level 60, format "'[' \big [ op / idx ]_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( i <- r ) F" (F at level 36, format "'[' \big [ op / idx ]_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( m <= i < n | P ) F" (F at level 36, i, n at level 60, format "'[' \big [ op / idx ]_ ( m <= i < n | P ) F ']'"). Reserved Notation "\big [ op / idx ]_ ( m <= i < n ) F" (at level 36, F at level 36, format "'[' \big [ op / idx ]_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( i | P ) F" (F at level 36, format "'[' \big [ op / idx ]_ ( i | P ) '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( i : t | P ) F" (F at level 36, format "'[' \big [ op / idx ]_ ( i : t | P ) '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( i : t ) F" (F at level 36, format "'[' \big [ op / idx ]_ ( i : t ) '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( i < n | P ) F" (F at level 36, n at level 60, format "'[' \big [ op / idx ]_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( i < n ) F" (F at level 36, format "'[' \big [ op / idx ]_ ( i < n ) F ']'"). Reserved Notation "\big [ op / idx ]_ ( i 'in' A | P ) F" (F at level 36, A at level 60, format "'[' \big [ op / idx ]_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\big [ op / idx ]_ ( i 'in' A ) F" (F at level 36, format "'[' \big [ op / idx ]_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\sum_ i F" (at level 34, F at level 41, i at level 0, right associativity, format "'[' \sum_ i '/ ' F ']'"). Reserved Notation "\sum_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \sum_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\sum_ ( i <- r ) F" (F at level 41, format "'[' \sum_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\sum_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \sum_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\sum_ ( m <= i < n ) F" (F at level 41, format "'[' \sum_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\sum_ ( i | P ) F" (F at level 41, format "'[' \sum_ ( i | P ) '/ ' F ']'"). Reserved Notation "\sum_ ( i : t | P ) F" (F at level 41). (* only parsing *) Reserved Notation "\sum_ ( i : t ) F" (F at level 41). (* only parsing *) Reserved Notation "\sum_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \sum_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\sum_ ( i < n ) F" (F at level 41, format "'[' \sum_ ( i < n ) '/ ' F ']'"). Reserved Notation "\sum_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \sum_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\sum_ ( i 'in' A ) F" (F at level 41, format "'[' \sum_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\max_ i F" (at level 34, F at level 41, i at level 0, format "'[' \max_ i '/ ' F ']'"). Reserved Notation "\max_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \max_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\max_ ( i <- r ) F" (F at level 41, format "'[' \max_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\max_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \max_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\max_ ( m <= i < n ) F" (F at level 41, format "'[' \max_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\max_ ( i | P ) F" (F at level 41, format "'[' \max_ ( i | P ) '/ ' F ']'"). Reserved Notation "\max_ ( i : t | P ) F" (F at level 41). (* only parsing *) Reserved Notation "\max_ ( i : t ) F" (F at level 41). (* only parsing *) Reserved Notation "\max_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \max_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\max_ ( i < n ) F" (F at level 41, n at level 60, format "'[' \max_ ( i < n ) F ']'"). Reserved Notation "\max_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \max_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\max_ ( i 'in' A ) F" (F at level 41, format "'[' \max_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\prod_ i F" (at level 34, F at level 36, i at level 0, format "'[' \prod_ i '/ ' F ']'"). Reserved Notation "\prod_ ( i <- r | P ) F" (F at level 36, i, r at level 60, format "'[' \prod_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\prod_ ( i <- r ) F" (F at level 36, format "'[' \prod_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\prod_ ( m <= i < n | P ) F" (F at level 36, i, n at level 60, format "'[' \prod_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\prod_ ( m <= i < n ) F" (F at level 36, format "'[' \prod_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\prod_ ( i | P ) F" (F at level 36, format "'[' \prod_ ( i | P ) '/ ' F ']'"). Reserved Notation "\prod_ ( i : t | P ) F" (F at level 36). (* only parsing *) Reserved Notation "\prod_ ( i : t ) F" (F at level 36). (* only parsing *) Reserved Notation "\prod_ ( i < n | P ) F" (F at level 36, n at level 60, format "'[' \prod_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\prod_ ( i < n ) F" (F at level 36, format "'[' \prod_ ( i < n ) '/ ' F ']'"). Reserved Notation "\prod_ ( i 'in' A | P ) F" (F at level 36, A at level 60, format "'[' \prod_ ( i 'in' A | P ) F ']'"). Reserved Notation "\prod_ ( i 'in' A ) F" (F at level 36, format "'[' \prod_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\bigcup_ i F" (at level 41, F at level 41, i at level 0, format "'[' \bigcup_ i '/ ' F ']'"). Reserved Notation "\bigcup_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \bigcup_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( i <- r ) F" (F at level 41, format "'[' \bigcup_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \bigcup_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( m <= i < n ) F" (F at level 41, format "'[' \bigcup_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( i | P ) F" (F at level 41, format "'[' \bigcup_ ( i | P ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( i : t | P ) F" (F at level 41, format "'[' \bigcup_ ( i : t | P ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( i : t ) F" (F at level 41, format "'[' \bigcup_ ( i : t ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \bigcup_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( i < n ) F" (F at level 41, format "'[' \bigcup_ ( i < n ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \bigcup_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\bigcup_ ( i 'in' A ) F" (F at level 41, format "'[' \bigcup_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\bigcap_ i F" (at level 41, F at level 41, i at level 0, format "'[' \bigcap_ i '/ ' F ']'"). Reserved Notation "\bigcap_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \bigcap_ ( i <- r | P ) F ']'"). Reserved Notation "\bigcap_ ( i <- r ) F" (F at level 41, format "'[' \bigcap_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \bigcap_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( m <= i < n ) F" (F at level 41, format "'[' \bigcap_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( i | P ) F" (F at level 41, format "'[' \bigcap_ ( i | P ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( i : t | P ) F" (F at level 41, format "'[' \bigcap_ ( i : t | P ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( i : t ) F" (F at level 41, format "'[' \bigcap_ ( i : t ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \bigcap_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( i < n ) F" (F at level 41, format "'[' \bigcap_ ( i < n ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \bigcap_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\bigcap_ ( i 'in' A ) F" (F at level 41, format "'[' \bigcap_ ( i 'in' A ) '/ ' F ']'"). Module SemiGroup. HB.mixin Record isLaw T (op : T -> T -> T) := { opA : associative op; }. #[export] HB.structure Definition Law T := {op of isLaw T op}. Notation law := Law.type. HB.mixin Record isCommutativeLaw T (op : T -> T -> T) := { opC : commutative op; }. #[export] HB.structure Definition ComLaw T := {op of Law T op & isCommutativeLaw T op}. Notation com_law := ComLaw.type. HB.factory Record isComLaw T (op : T -> T -> T) := { opA : associative op; opC : commutative op; }. HB.builders Context T op of isComLaw T op. HB.instance Definition _ := isLaw.Build T op opA. HB.instance Definition _ := isCommutativeLaw.Build T op opC. HB.end. Module Import Exports. HB.reexport. End Exports. Module Theory. Section Theory. Variables (T : Type). Section Plain. Variable mul : law T. Lemma mulmA : associative mul. Proof. exact: opA. Qed. End Plain. Section Commutative. Variable mul : com_law T. Lemma mulmC : commutative mul. Proof. exact: opC. Qed. Lemma mulmCA : left_commutative mul. Proof. by move=> x y z; rewrite !mulmA [_ x _]mulmC. Qed. Lemma mulmAC : right_commutative mul. Proof. by move=> x y z; rewrite -!mulmA [_ y _]mulmC. Qed. Lemma mulmACA : interchange mul mul. Proof. by move=> x y z t; rewrite -!mulmA [_ y _]mulmCA. Qed. End Commutative. End Theory. End Theory. Include Theory. End SemiGroup. Export SemiGroup.Exports. Module Monoid. Export SemiGroup. HB.mixin Record isMonoidLaw T (idm : T) (op : T -> T -> T) := { op1m : left_id idm op; opm1 : right_id idm op; }. #[export] HB.structure Definition Law T idm := {op of SemiGroup.Law T op & isMonoidLaw T idm op}. Notation law := Law.type. HB.factory Record isLaw T (idm : T) (op : T -> T -> T) := { opA : associative op; op1m : left_id idm op; opm1 : right_id idm op; }. HB.builders Context T idm op of isLaw T idm op. HB.instance Definition _ := SemiGroup.isLaw.Build T op opA. HB.instance Definition _ := isMonoidLaw.Build T idm op op1m opm1. HB.end. #[export] HB.structure Definition ComLaw T idm := {op of Law T idm op & isCommutativeLaw T op}. Notation com_law := ComLaw.type. HB.factory Record isComLaw T (idm : T) (op : T -> T -> T) := { opA : associative op; opC : commutative op; op1m : left_id idm op; }. HB.builders Context T idm op of isComLaw T idm op. Lemma opm1 : right_id idm op. Proof. by move=> x; rewrite opC op1m. Qed. HB.instance Definition _ := isLaw.Build T idm op opA op1m opm1. HB.instance Definition _ := isCommutativeLaw.Build T op opC. HB.end. HB.mixin Record isMulLaw T (zero : T) (mul : T -> T -> T) := { mul_zerol : left_zero zero mul; mul_zeror : right_zero zero mul; }. #[export] HB.structure Definition MulLaw T zero := {mul of isMulLaw T zero mul}. Notation mul_law := MulLaw.type. HB.mixin Record isAddLaw T (mul : T -> T -> T) (op : T -> T -> T) := { mul_op_Dl : left_distributive mul op; mul_op_Dr : right_distributive mul op; }. #[export] HB.structure Definition AddLaw T zero mul := {add of ComLaw T zero add & isAddLaw T mul add}. Notation add_law := AddLaw.type. Module Import Exports. HB.reexport. End Exports. Section CommutativeAxioms. Variable (T : Type) (zero one : T) (mul add : T -> T -> T). Hypothesis mulC : commutative mul. Lemma mulC_id : left_id one mul -> right_id one mul. Proof. by move=> mul1x x; rewrite mulC. Qed. Lemma mulC_zero : left_zero zero mul -> right_zero zero mul. Proof. by move=> mul0x x; rewrite mulC. Qed. Lemma mulC_dist : left_distributive mul add -> right_distributive mul add. Proof. by move=> mul_addl x y z; rewrite !(mulC x). Qed. End CommutativeAxioms. Module Theory. Export SemiGroup.Theory. Section Theory. Variables (T : Type) (idm : T). Section Plain. Variable mul : law idm. Lemma mul1m : left_id idm mul. Proof. exact: op1m. Qed. Lemma mulm1 : right_id idm mul. Proof. exact: opm1. Qed. Lemma iteropE n x : iterop n mul x idm = iter n (mul x) idm. Proof. by case: n => // n; rewrite iterSr mulm1 iteropS. Qed. End Plain. Section Mul. Variable mul : mul_law idm. Lemma mul0m : left_zero idm mul. Proof. exact: mul_zerol. Qed. Lemma mulm0 : right_zero idm mul. Proof. exact: mul_zeror. Qed. End Mul. Section Add. Variables (mul : T -> T -> T) (add : add_law idm mul). Lemma addmA : associative add. Proof. exact: mulmA. Qed. Lemma addmC : commutative add. Proof. exact: mulmC. Qed. Lemma addmCA : left_commutative add. Proof. exact: mulmCA. Qed. Lemma addmAC : right_commutative add. Proof. exact: mulmAC. Qed. Lemma add0m : left_id idm add. Proof. exact: mul1m. Qed. Lemma addm0 : right_id idm add. Proof. exact: mulm1. Qed. Lemma mulmDl : left_distributive mul add. Proof. exact: mul_op_Dl. Qed. Lemma mulmDr : right_distributive mul add. Proof. exact: mul_op_Dr. Qed. End Add. Definition simpm := (mulm1, mulm0, mul1m, mul0m, mulmA). End Theory. End Theory. Include SemiGroup.Theory. Include Theory. End Monoid. Export Monoid.Exports. Section PervasiveMonoids. Import Monoid. HB.instance Definition _ := isComLaw.Build bool true andb andbA andbC andTb. HB.instance Definition _ := isMulLaw.Build bool false andb andFb andbF. HB.instance Definition _ := isComLaw.Build bool false orb orbA orbC orFb. HB.instance Definition _ := isMulLaw.Build bool true orb orTb orbT. HB.instance Definition _ := isComLaw.Build bool false addb addbA addbC addFb. HB.instance Definition _ := isAddLaw.Build bool andb orb andb_orl andb_orr. HB.instance Definition _ := isAddLaw.Build bool orb andb orb_andl orb_andr. HB.instance Definition _ := isAddLaw.Build bool andb addb andb_addl andb_addr. HB.instance Definition _ := isComLaw.Build nat 0 addn addnA addnC add0n. HB.instance Definition _ := isComLaw.Build nat 1 muln mulnA mulnC mul1n. HB.instance Definition _ := isMulLaw.Build nat 0 muln mul0n muln0. HB.instance Definition _ := isAddLaw.Build nat muln addn mulnDl mulnDr. HB.instance Definition _ := isComLaw.Build nat 0 maxn maxnA maxnC max0n. HB.instance Definition _ := isAddLaw.Build nat muln maxn maxnMl maxnMr. HB.instance Definition _ := isComLaw.Build nat 0 gcdn gcdnA gcdnC gcd0n. HB.instance Definition _ := isAddLaw.Build nat muln gcdn muln_gcdl muln_gcdr. HB.instance Definition _ := isComLaw.Build nat 1 lcmn lcmnA lcmnC lcm1n. HB.instance Definition _ := isAddLaw.Build nat muln lcmn muln_lcml muln_lcmr. HB.instance Definition _ T := isLaw.Build (seq T) nil cat (@catA T) (@cat0s T) (@cats0 T). End PervasiveMonoids. (* Unit test for the [...law of ...] Notations Definition myp := addn. Definition mym := muln. Canonical myp_mon := [law of myp]. Canonical myp_cmon := [com_law of myp]. Canonical mym_mul := [mul_law of mym]. Canonical myp_add := [add_law _ of myp]. Print myp_add. Print Canonical Projections. *) Delimit Scope big_scope with BIG. Open Scope big_scope. (* The bigbody wrapper is a workaround for a quirk of the Coq pretty-printer, *) (* which would fail to redisplay the \big notation when the <general_term> or *) (* <condition> do not depend on the bound index. The BigBody constructor *) (* packages both in in a term in which i occurs; it also depends on the *) (* iterated <op>, as this can give more information on the expected type of *) (* the <general_term>, thus allowing for the insertion of coercions. *) Variant bigbody R I := BigBody of I & (R -> R -> R) & bool & R. Definition applybig {R I} (body : bigbody R I) x := let: BigBody _ op b v := body in if b then op v x else x. Definition reducebig R I idx r (body : I -> bigbody R I) := foldr (applybig \o body) idx r. HB.lock Definition bigop := reducebig. Canonical bigop_unlock := Unlockable bigop.unlock. Definition index_iota m n := iota m (n - m). Lemma mem_index_iota m n i : i \in index_iota m n = (m <= i < n). Proof. rewrite mem_iota; case le_m_i: (m <= i) => //=. by rewrite -leq_subLR subSn // -subn_gt0 -subnDA subnKC // subn_gt0. Qed. (* Legacy mathcomp scripts have been relying on the fact that enum A and *) (* filter A (index_enum T) are convertible. This is likely to change in the *) (* next mathcomp release when enum, pick, subset and card are generalised to *) (* predicates with finite support in a choiceType - in fact the two will only *) (* be equal up to permutation in this new theory. *) (* It is therefore advisable to stop relying on this, and use the new *) (* facilities provided in this library: lemmas big_enumP, big_enum, big_image *) (* and such. Users wishing to test compliance should change the Defined in *) (* index_enum_key to Qed, and comment out the filter_index_enum compatibility *) (* definition below. *) Fact index_enum_key : unit. Proof. split. Defined. (* Qed. *) Definition index_enum (T : finType) := locked_with index_enum_key (Finite.enum T). Lemma deprecated_filter_index_enum T P : filter P (index_enum T) = enum P. Proof. by rewrite [index_enum T]unlock. Qed. Lemma mem_index_enum T i : i \in index_enum T. Proof. by rewrite [index_enum T]unlock -enumT mem_enum. Qed. #[global] Hint Resolve mem_index_enum : core. Lemma index_enum_uniq T : uniq (index_enum T). Proof. by rewrite [index_enum T]unlock -enumT enum_uniq. Qed. Notation "\big [ op / idx ]_ ( i <- r | P ) F" := (bigop idx r (fun i => BigBody i op P%B F)) : big_scope. Notation "\big [ op / idx ]_ ( i <- r ) F" := (bigop idx r (fun i => BigBody i op true F)) : big_scope. Notation "\big [ op / idx ]_ ( m <= i < n | P ) F" := (bigop idx (index_iota m n) (fun i : nat => BigBody i op P%B F)) : big_scope. Notation "\big [ op / idx ]_ ( m <= i < n ) F" := (bigop idx (index_iota m n) (fun i : nat => BigBody i op true F)) : big_scope. Notation "\big [ op / idx ]_ ( i | P ) F" := (bigop idx (index_enum _) (fun i => BigBody i op P%B F)) : big_scope. Notation "\big [ op / idx ]_ i F" := (bigop idx (index_enum _) (fun i => BigBody i op true F)) : big_scope. Notation "\big [ op / idx ]_ ( i : t | P ) F" := (bigop idx (index_enum _) (fun i : t => BigBody i op P%B F)) (only parsing) : big_scope. Notation "\big [ op / idx ]_ ( i : t ) F" := (bigop idx (index_enum _) (fun i : t => BigBody i op true F)) (only parsing) : big_scope. Notation "\big [ op / idx ]_ ( i < n | P ) F" := (\big[op/idx]_(i : ordinal n | P%B) F) : big_scope. Notation "\big [ op / idx ]_ ( i < n ) F" := (\big[op/idx]_(i : ordinal n) F) : big_scope. Notation "\big [ op / idx ]_ ( i 'in' A | P ) F" := (\big[op/idx]_(i | (i \in A) && P) F) : big_scope. Notation "\big [ op / idx ]_ ( i 'in' A ) F" := (\big[op/idx]_(i | i \in A) F) : big_scope. Notation BIG_F := (F in \big[_/_]_(i <- _ | _) F i)%pattern. Notation BIG_P := (P in \big[_/_]_(i <- _ | P i) _)%pattern. Local Notation "+%N" := addn (only parsing). Notation "\sum_ ( i <- r | P ) F" := (\big[+%N/0%N]_(i <- r | P%B) F%N) : nat_scope. Notation "\sum_ ( i <- r ) F" := (\big[+%N/0%N]_(i <- r) F%N) : nat_scope. Notation "\sum_ ( m <= i < n | P ) F" := (\big[+%N/0%N]_(m <= i < n | P%B) F%N) : nat_scope. Notation "\sum_ ( m <= i < n ) F" := (\big[+%N/0%N]_(m <= i < n) F%N) : nat_scope. Notation "\sum_ ( i | P ) F" := (\big[+%N/0%N]_(i | P%B) F%N) : nat_scope. Notation "\sum_ i F" := (\big[+%N/0%N]_i F%N) : nat_scope. Notation "\sum_ ( i : t | P ) F" := (\big[+%N/0%N]_(i : t | P%B) F%N) (only parsing) : nat_scope. Notation "\sum_ ( i : t ) F" := (\big[+%N/0%N]_(i : t) F%N) (only parsing) : nat_scope. Notation "\sum_ ( i < n | P ) F" := (\big[+%N/0%N]_(i < n | P%B) F%N) : nat_scope. Notation "\sum_ ( i < n ) F" := (\big[+%N/0%N]_(i < n) F%N) : nat_scope. Notation "\sum_ ( i 'in' A | P ) F" := (\big[+%N/0%N]_(i in A | P%B) F%N) : nat_scope. Notation "\sum_ ( i 'in' A ) F" := (\big[+%N/0%N]_(i in A) F%N) : nat_scope. Local Notation "*%N" := muln (only parsing). Notation "\prod_ ( i <- r | P ) F" := (\big[*%N/1%N]_(i <- r | P%B) F%N) : nat_scope. Notation "\prod_ ( i <- r ) F" := (\big[*%N/1%N]_(i <- r) F%N) : nat_scope. Notation "\prod_ ( m <= i < n | P ) F" := (\big[*%N/1%N]_(m <= i < n | P%B) F%N) : nat_scope. Notation "\prod_ ( m <= i < n ) F" := (\big[*%N/1%N]_(m <= i < n) F%N) : nat_scope. Notation "\prod_ ( i | P ) F" := (\big[*%N/1%N]_(i | P%B) F%N) : nat_scope. Notation "\prod_ i F" := (\big[*%N/1%N]_i F%N) : nat_scope. Notation "\prod_ ( i : t | P ) F" := (\big[*%N/1%N]_(i : t | P%B) F%N) (only parsing) : nat_scope. Notation "\prod_ ( i : t ) F" := (\big[*%N/1%N]_(i : t) F%N) (only parsing) : nat_scope. Notation "\prod_ ( i < n | P ) F" := (\big[*%N/1%N]_(i < n | P%B) F%N) : nat_scope. Notation "\prod_ ( i < n ) F" := (\big[*%N/1%N]_(i < n) F%N) : nat_scope. Notation "\prod_ ( i 'in' A | P ) F" := (\big[*%N/1%N]_(i in A | P%B) F%N) : nat_scope. Notation "\prod_ ( i 'in' A ) F" := (\big[*%N/1%N]_(i in A) F%N) : nat_scope. Notation "\max_ ( i <- r | P ) F" := (\big[maxn/0%N]_(i <- r | P%B) F%N) : nat_scope. Notation "\max_ ( i <- r ) F" := (\big[maxn/0%N]_(i <- r) F%N) : nat_scope. Notation "\max_ ( i | P ) F" := (\big[maxn/0%N]_(i | P%B) F%N) : nat_scope. Notation "\max_ i F" := (\big[maxn/0%N]_i F%N) : nat_scope. Notation "\max_ ( i : I | P ) F" := (\big[maxn/0%N]_(i : I | P%B) F%N) (only parsing) : nat_scope. Notation "\max_ ( i : I ) F" := (\big[maxn/0%N]_(i : I) F%N) (only parsing) : nat_scope. Notation "\max_ ( m <= i < n | P ) F" := (\big[maxn/0%N]_(m <= i < n | P%B) F%N) : nat_scope. Notation "\max_ ( m <= i < n ) F" := (\big[maxn/0%N]_(m <= i < n) F%N) : nat_scope. Notation "\max_ ( i < n | P ) F" := (\big[maxn/0%N]_(i < n | P%B) F%N) : nat_scope. Notation "\max_ ( i < n ) F" := (\big[maxn/0%N]_(i < n) F%N) : nat_scope. Notation "\max_ ( i 'in' A | P ) F" := (\big[maxn/0%N]_(i in A | P%B) F%N) : nat_scope. Notation "\max_ ( i 'in' A ) F" := (\big[maxn/0%N]_(i in A) F%N) : nat_scope. (* Induction loading *) Lemma big_load R (K K' : R -> Type) idx op I r (P : pred I) F : K (\big[op/idx]_(i <- r | P i) F i) * K' (\big[op/idx]_(i <- r | P i) F i) -> K' (\big[op/idx]_(i <- r | P i) F i). Proof. by case. Qed. Arguments big_load [R] K [K'] idx op [I]. Section Elim3. Variables (R1 R2 R3 : Type) (K : R1 -> R2 -> R3 -> Type). Variables (id1 : R1) (op1 : R1 -> R1 -> R1). Variables (id2 : R2) (op2 : R2 -> R2 -> R2). Variables (id3 : R3) (op3 : R3 -> R3 -> R3). Hypothesis Kid : K id1 id2 id3. Lemma big_rec3 I r (P : pred I) F1 F2 F3 (K_F : forall i y1 y2 y3, P i -> K y1 y2 y3 -> K (op1 (F1 i) y1) (op2 (F2 i) y2) (op3 (F3 i) y3)) : K (\big[op1/id1]_(i <- r | P i) F1 i) (\big[op2/id2]_(i <- r | P i) F2 i) (\big[op3/id3]_(i <- r | P i) F3 i). Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: K_F. Qed. Hypothesis Kop : forall x1 x2 x3 y1 y2 y3, K x1 x2 x3 -> K y1 y2 y3-> K (op1 x1 y1) (op2 x2 y2) (op3 x3 y3). Lemma big_ind3 I r (P : pred I) F1 F2 F3 (K_F : forall i, P i -> K (F1 i) (F2 i) (F3 i)) : K (\big[op1/id1]_(i <- r | P i) F1 i) (\big[op2/id2]_(i <- r | P i) F2 i) (\big[op3/id3]_(i <- r | P i) F3 i). Proof. by apply: big_rec3 => i x1 x2 x3 /K_F; apply: Kop. Qed. End Elim3. Arguments big_rec3 [R1 R2 R3] K [id1 op1 id2 op2 id3 op3] _ [I r P F1 F2 F3]. Arguments big_ind3 [R1 R2 R3] K [id1 op1 id2 op2 id3 op3] _ _ [I r P F1 F2 F3]. Section Elim2. Variables (R1 R2 : Type) (K : R1 -> R2 -> Type) (f : R2 -> R1). Variables (id1 : R1) (op1 : R1 -> R1 -> R1). Variables (id2 : R2) (op2 : R2 -> R2 -> R2). Hypothesis Kid : K id1 id2. Lemma big_rec2 I r (P : pred I) F1 F2 (K_F : forall i y1 y2, P i -> K y1 y2 -> K (op1 (F1 i) y1) (op2 (F2 i) y2)) : K (\big[op1/id1]_(i <- r | P i) F1 i) (\big[op2/id2]_(i <- r | P i) F2 i). Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: K_F. Qed. Hypothesis Kop : forall x1 x2 y1 y2, K x1 x2 -> K y1 y2 -> K (op1 x1 y1) (op2 x2 y2). Lemma big_ind2 I r (P : pred I) F1 F2 (K_F : forall i, P i -> K (F1 i) (F2 i)) : K (\big[op1/id1]_(i <- r | P i) F1 i) (\big[op2/id2]_(i <- r | P i) F2 i). Proof. by apply: big_rec2 => i x1 x2 /K_F; apply: Kop. Qed. Hypotheses (f_op : {morph f : x y / op2 x y >-> op1 x y}) (f_id : f id2 = id1). Lemma big_morph I r (P : pred I) F : f (\big[op2/id2]_(i <- r | P i) F i) = \big[op1/id1]_(i <- r | P i) f (F i). Proof. by rewrite unlock; elim: r => //= i r <-; rewrite -f_op -fun_if. Qed. End Elim2. Arguments big_rec2 [R1 R2] K [id1 op1 id2 op2] _ [I r P F1 F2]. Arguments big_ind2 [R1 R2] K [id1 op1 id2 op2] _ _ [I r P F1 F2]. Arguments big_morph [R1 R2] f [id1 op1 id2 op2] _ _ [I]. Section Elim1. Variables (R : Type) (K : R -> Type) (f : R -> R). Variables (idx : R) (op op' : R -> R -> R). Hypothesis Kid : K idx. Lemma big_rec I r (P : pred I) F (Kop : forall i x, P i -> K x -> K (op (F i) x)) : K (\big[op/idx]_(i <- r | P i) F i). Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: Kop. Qed. Hypothesis Kop : forall x y, K x -> K y -> K (op x y). Lemma big_ind I r (P : pred I) F (K_F : forall i, P i -> K (F i)) : K (\big[op/idx]_(i <- r | P i) F i). Proof. by apply: big_rec => // i x /K_F /Kop; apply. Qed. Hypothesis Kop' : forall x y, K x -> K y -> op x y = op' x y. Lemma eq_big_op I r (P : pred I) F (K_F : forall i, P i -> K (F i)) : \big[op/idx]_(i <- r | P i) F i = \big[op'/idx]_(i <- r | P i) F i. Proof. by elim/(big_load K): _; elim/big_rec2: _ => // i _ y Pi [Ky <-]; auto. Qed. Hypotheses (fM : {morph f : x y / op x y}) (f_id : f idx = idx). Lemma big_endo I r (P : pred I) F : f (\big[op/idx]_(i <- r | P i) F i) = \big[op/idx]_(i <- r | P i) f (F i). Proof. exact: big_morph. Qed. End Elim1. Arguments big_rec [R] K [idx op] _ [I r P F]. Arguments big_ind [R] K [idx op] _ _ [I r P F]. Arguments eq_big_op [R] K [idx op] op' _ _ _ [I]. Arguments big_endo [R] f [idx op] _ _ [I]. Lemma big_morph_in (R1 R2 : Type) (Q : {pred R2}) (f : R2 -> R1) (id1 : R1) (op1 : R1 -> R1 -> R1) (id2 : R2) (op2 : R2 -> R2 -> R2) : {in Q &, forall x y, op2 x y \in Q} -> id2 \in Q -> {in Q &, {morph f : x y / op2 x y >-> op1 x y}} -> f id2 = id1 -> forall [I : Type] (r : seq I) (P : pred I) (F : I -> R2), (forall i, P i -> F i \in Q) -> f (\big[op2/id2]_(i <- r | P i) F i) = \big[op1/id1]_(i <- r | P i) f (F i). Proof. move=> Qop Qid fop fid I r P F QF; elim/(big_load Q): _. by elim/big_rec2: _ => // j x y Pj [Qx <-]; rewrite [Q _]Qop ?fop ?QF. Qed. Arguments big_morph_in [R1 R2] Q f [id1 op1 id2 op2]. Section oAC. Variables (T : Type) (op : T -> T -> T). Definition oAC of associative op & commutative op := fun x => oapp (fun y => Some (oapp (op^~ y) y x)) x. Arguments oAC : simpl never. Hypothesis (opA : associative op) (opC : commutative op). Local Notation oop := (oAC opA opC). Lemma oACE x y : oop (Some x) (Some y) = some (op x y). Proof. by []. Qed. Lemma oopA_subdef : associative oop. Proof. by move=> [x|] [y|] [z|]//; rewrite /oAC/= opA. Qed. Lemma oopx1_subdef : left_id None oop. Proof. by case. Qed. Lemma oop1x_subdef : right_id None oop. Proof. by []. Qed. Lemma oopC_subdef : commutative oop. Proof. by move=> [x|] [y|]//; rewrite /oAC/= opC. Qed. HB.instance Definition _ := Monoid.isComLaw.Build (option T) None oop oopA_subdef oopC_subdef oopx1_subdef. Context [x : T]. Lemma some_big_AC_mk_monoid [I : Type] r P (F : I -> T) : Some (\big[op/x]_(i <- r | P i) F i) = oop (\big[oop/None]_(i <- r | P i) Some (F i)) (Some x). Proof. by elim/big_rec2 : _ => //= i [y|] _ Pi [] -> //=; rewrite opA. Qed. Lemma big_AC_mk_monoid [I : Type] r P (F : I -> T) : \big[op/x]_(i <- r | P i) F i = odflt x (oop (\big[oop/None]_(i <- r | P i) Some (F i)) (Some x)). Proof. by apply: Some_inj; rewrite some_big_AC_mk_monoid. Qed. End oAC. Arguments oAC : simpl never. Section Extensionality. Variables (R : Type) (idx : R) (op : R -> R -> R). Section SeqExtension. Variable I : Type. Lemma foldrE r : foldr op idx r = \big[op/idx]_(x <- r) x. Proof. by rewrite unlock. Qed. Lemma big_filter r (P : pred I) F : \big[op/idx]_(i <- filter P r) F i = \big[op/idx]_(i <- r | P i) F i. Proof. by rewrite unlock; elim: r => //= i r <-; case (P i). Qed. Lemma big_filter_cond r (P1 P2 : pred I) F : \big[op/idx]_(i <- filter P1 r | P2 i) F i = \big[op/idx]_(i <- r | P1 i && P2 i) F i. Proof. rewrite -big_filter -(big_filter r); congr bigop. by rewrite -filter_predI; apply: eq_filter => i; apply: andbC. Qed. Lemma eq_bigl r (P1 P2 : pred I) F : P1 =1 P2 -> \big[op/idx]_(i <- r | P1 i) F i = \big[op/idx]_(i <- r | P2 i) F i. Proof. by move=> eqP12; rewrite -!(big_filter r) (eq_filter eqP12). Qed. (* A lemma to permute aggregate conditions. *) Lemma big_andbC r (P Q : pred I) F : \big[op/idx]_(i <- r | P i && Q i) F i = \big[op/idx]_(i <- r | Q i && P i) F i. Proof. by apply: eq_bigl => i; apply: andbC. Qed. Lemma eq_bigr r (P : pred I) F1 F2 : (forall i, P i -> F1 i = F2 i) -> \big[op/idx]_(i <- r | P i) F1 i = \big[op/idx]_(i <- r | P i) F2 i. Proof. by move=> eqF12; elim/big_rec2: _ => // i x _ /eqF12-> ->. Qed. Lemma eq_big r (P1 P2 : pred I) F1 F2 : P1 =1 P2 -> (forall i, P1 i -> F1 i = F2 i) -> \big[op/idx]_(i <- r | P1 i) F1 i = \big[op/idx]_(i <- r | P2 i) F2 i. Proof. by move/eq_bigl <-; move/eq_bigr->. Qed. Lemma congr_big r1 r2 (P1 P2 : pred I) F1 F2 : r1 = r2 -> P1 =1 P2 -> (forall i, P1 i -> F1 i = F2 i) -> \big[op/idx]_(i <- r1 | P1 i) F1 i = \big[op/idx]_(i <- r2 | P2 i) F2 i. Proof. by move=> <-{r2}; apply: eq_big. Qed. Lemma big_nil (P : pred I) F : \big[op/idx]_(i <- [::] | P i) F i = idx. Proof. by rewrite unlock. Qed. Lemma big_cons i r (P : pred I) F : let x := \big[op/idx]_(j <- r | P j) F j in \big[op/idx]_(j <- i :: r | P j) F j = if P i then op (F i) x else x. Proof. by rewrite unlock. Qed. Lemma big_rcons_op i r (P : pred I) F : let idx' := if P i then op (F i) idx else idx in \big[op/idx]_(j <- rcons r i | P j) F j = \big[op/idx']_(j <- r | P j) F j. Proof. by elim: r => /= [|j r]; rewrite !(big_nil, big_cons, unlock)// => ->. Qed. Lemma big_map J (h : J -> I) r (P : pred I) F : \big[op/idx]_(i <- map h r | P i) F i = \big[op/idx]_(j <- r | P (h j)) F (h j). Proof. by rewrite unlock; elim: r => //= j r ->. Qed. Lemma big_nth x0 r (P : pred I) F : \big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(0 <= i < size r | P (nth x0 r i)) (F (nth x0 r i)). Proof. by rewrite -[r in LHS](mkseq_nth x0) big_map /index_iota subn0. Qed. Lemma big_hasC r (P : pred I) F : ~~ has P r -> \big[op/idx]_(i <- r | P i) F i = idx. Proof. by rewrite -big_filter has_count -size_filter -eqn0Ngt unlock => /nilP->. Qed. Lemma big_pred0_eq (r : seq I) F : \big[op/idx]_(i <- r | false) F i = idx. Proof. by rewrite big_hasC // has_pred0. Qed. Lemma big_pred0 r (P : pred I) F : P =1 xpred0 -> \big[op/idx]_(i <- r | P i) F i = idx. Proof. by move/eq_bigl->; apply: big_pred0_eq. Qed. Lemma big_cat_nested r1 r2 (P : pred I) F : let x := \big[op/idx]_(i <- r2 | P i) F i in \big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/x]_(i <- r1 | P i) F i. Proof. by rewrite unlock /reducebig foldr_cat. Qed. Lemma big_catl r1 r2 (P : pred I) F : ~~ has P r2 -> \big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/idx]_(i <- r1 | P i) F i. Proof. by rewrite big_cat_nested => /big_hasC->. Qed. Lemma big_catr r1 r2 (P : pred I) F : ~~ has P r1 -> \big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/idx]_(i <- r2 | P i) F i. Proof. rewrite -big_filter -(big_filter r2) filter_cat. by rewrite has_count -size_filter; case: filter. Qed. End SeqExtension. Lemma big_map_id J (h : J -> R) r (P : pred R) : \big[op/idx]_(i <- map h r | P i) i = \big[op/idx]_(j <- r | P (h j)) h j. Proof. exact: big_map. Qed. Lemma big_condT (J : finType) (A : {pred J}) F : \big[op/idx]_(i in A | true) F i = \big[op/idx]_(i in A) F i. Proof. by apply: eq_bigl => i; exact: andbT. Qed. (* The following lemmas can be used to localise extensionality to a specific *) (* index sequence. This is done by ssreflect rewriting, before applying *) (* congruence or induction lemmas. *) Lemma big_seq_cond (I : eqType) r (P : pred I) F : \big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(i <- r | (i \in r) && P i) F i. Proof. by rewrite -!(big_filter r); congr bigop; apply: eq_in_filter => i ->. Qed. Lemma big_seq (I : eqType) (r : seq I) F : \big[op/idx]_(i <- r) F i = \big[op/idx]_(i <- r | i \in r) F i. Proof. by rewrite big_seq_cond big_andbC. Qed. Lemma eq_big_seq (I : eqType) (r : seq I) F1 F2 : {in r, F1 =1 F2} -> \big[op/idx]_(i <- r) F1 i = \big[op/idx]_(i <- r) F2 i. Proof. by move=> eqF; rewrite !big_seq (eq_bigr _ eqF). Qed. (* Similar lemmas for exposing integer indexing in the predicate. *) Lemma big_nat_cond m n (P : pred nat) F : \big[op/idx]_(m <= i < n | P i) F i = \big[op/idx]_(m <= i < n | (m <= i < n) && P i) F i. Proof. by rewrite big_seq_cond; apply: eq_bigl => i; rewrite mem_index_iota. Qed. Lemma big_nat m n F : \big[op/idx]_(m <= i < n) F i = \big[op/idx]_(m <= i < n | m <= i < n) F i. Proof. by rewrite big_nat_cond big_andbC. Qed. Lemma congr_big_nat m1 n1 m2 n2 P1 P2 F1 F2 : m1 = m2 -> n1 = n2 -> (forall i, m1 <= i < n2 -> P1 i = P2 i) -> (forall i, P1 i && (m1 <= i < n2) -> F1 i = F2 i) -> \big[op/idx]_(m1 <= i < n1 | P1 i) F1 i = \big[op/idx]_(m2 <= i < n2 | P2 i) F2 i. Proof. move=> <- <- eqP12 eqF12; rewrite big_seq_cond (big_seq_cond _ P2). apply: eq_big => i; rewrite ?inE /= !mem_index_iota. by apply: andb_id2l; apply: eqP12. by rewrite andbC; apply: eqF12. Qed. Lemma eq_big_nat m n F1 F2 : (forall i, m <= i < n -> F1 i = F2 i) -> \big[op/idx]_(m <= i < n) F1 i = \big[op/idx]_(m <= i < n) F2 i. Proof. by move=> eqF; apply: congr_big_nat. Qed. Lemma big_geq m n (P : pred nat) F : m >= n -> \big[op/idx]_(m <= i < n | P i) F i = idx. Proof. by move=> ge_m_n; rewrite /index_iota (eqnP ge_m_n) big_nil. Qed. Lemma big_ltn_cond m n (P : pred nat) F : m < n -> let x := \big[op/idx]_(m.+1 <= i < n | P i) F i in \big[op/idx]_(m <= i < n | P i) F i = if P m then op (F m) x else x. Proof. by case: n => [//|n] le_m_n; rewrite /index_iota subSn // big_cons. Qed. Lemma big_ltn m n F : m < n -> \big[op/idx]_(m <= i < n) F i = op (F m) (\big[op/idx]_(m.+1 <= i < n) F i). Proof. by move=> lt_mn; apply: big_ltn_cond. Qed. Lemma big_addn m n a (P : pred nat) F : \big[op/idx]_(m + a <= i < n | P i) F i = \big[op/idx]_(m <= i < n - a | P (i + a)) F (i + a). Proof. rewrite /index_iota -subnDA addnC iotaDl big_map. by apply: eq_big => ? *; rewrite addnC. Qed. Lemma big_add1 m n (P : pred nat) F : \big[op/idx]_(m.+1 <= i < n | P i) F i = \big[op/idx]_(m <= i < n.-1 | P (i.+1)) F (i.+1). Proof. by rewrite -addn1 big_addn subn1; apply: eq_big => ? *; rewrite addn1. Qed. Lemma big_nat_recl n m F : m <= n -> \big[op/idx]_(m <= i < n.+1) F i = op (F m) (\big[op/idx]_(m <= i < n) F i.+1). Proof. by move=> lemn; rewrite big_ltn // big_add1. Qed. Lemma big_mkord n (P : pred nat) F : \big[op/idx]_(0 <= i < n | P i) F i = \big[op/idx]_(i < n | P i) F i. Proof. rewrite /index_iota subn0 -(big_map (@nat_of_ord n)). by congr bigop; rewrite /index_enum 2!unlock val_ord_enum. Qed. Lemma big_mknat n (P : pred 'I_n.+1) F : \big[op/idx]_(i < n.+1 | P i) F i = \big[op/idx]_(0 <= i < n.+1 | P (inord i)) F (inord i). Proof. by rewrite big_mkord; apply: eq_big => ?; rewrite inord_val. Qed. Lemma big_nat_widen m n1 n2 (P : pred nat) F : n1 <= n2 -> \big[op/idx]_(m <= i < n1 | P i) F i = \big[op/idx]_(m <= i < n2 | P i && (i < n1)) F i. Proof. move=> len12; symmetry; rewrite -big_filter filter_predI big_filter. have [ltn_trans eq_by_mem] := (ltn_trans, irr_sorted_eq ltn_trans ltnn). congr bigop; apply: eq_by_mem; rewrite ?sorted_filter ?iota_ltn_sorted // => i. rewrite mem_filter !mem_index_iota andbCA andbA andb_idr => // /andP[_]. by move/leq_trans->. Qed. Lemma big_ord_widen_cond n1 n2 (P : pred nat) (F : nat -> R) : n1 <= n2 -> \big[op/idx]_(i < n1 | P i) F i = \big[op/idx]_(i < n2 | P i && (i < n1)) F i. Proof. by move/big_nat_widen=> len12; rewrite -big_mkord len12 big_mkord. Qed. Lemma big_ord_widen n1 n2 (F : nat -> R) : n1 <= n2 -> \big[op/idx]_(i < n1) F i = \big[op/idx]_(i < n2 | i < n1) F i. Proof. by move=> le_n12; apply: (big_ord_widen_cond (predT)). Qed. Lemma big_ord_widen_leq n1 n2 (P : pred 'I_(n1.+1)) F : n1 < n2 -> \big[op/idx]_(i < n1.+1 | P i) F i = \big[op/idx]_(i < n2 | P (inord i) && (i <= n1)) F (inord i). Proof. move=> len12; pose g G i := G (inord i : 'I_(n1.+1)). rewrite -(big_ord_widen_cond (g _ P) (g _ F) len12) {}/g. by apply: eq_big => i *; rewrite inord_val. Qed. Lemma big_ord0 P F : \big[op/idx]_(i < 0 | P i) F i = idx. Proof. by rewrite big_pred0 => [|[]]. Qed. Lemma big_mask_tuple I n m (t : n.-tuple I) (P : pred I) F : \big[op/idx]_(i <- mask m t | P i) F i = \big[op/idx]_(i < n | nth false m i && P (tnth t i)) F (tnth t i). Proof. rewrite [t in LHS]tuple_map_ord/= -map_mask big_map. by rewrite mask_enum_ord big_filter_cond/= enumT. Qed. Lemma big_mask I r m (P : pred I) (F : I -> R) (r_ := tnth (in_tuple r)) : \big[op/idx]_(i <- mask m r | P i) F i = \big[op/idx]_(i < size r | nth false m i && P (r_ i)) F (r_ i). Proof. exact: (big_mask_tuple _ (in_tuple r)). Qed. Lemma big_tnth I r (P : pred I) F (r_ := tnth (in_tuple r)) : \big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(i < size r | P (r_ i)) (F (r_ i)). Proof. rewrite /= -[r in LHS](mask_true (leqnn (size r))) big_mask//. by apply: eq_bigl => i /=; rewrite nth_nseq ltn_ord. Qed. Lemma big_index_uniq (I : eqType) (r : seq I) (E : 'I_(size r) -> R) : uniq r -> \big[op/idx]_i E i = \big[op/idx]_(x <- r) oapp E idx (insub (index x r)). Proof. move=> Ur; apply/esym; rewrite big_tnth. by under [LHS]eq_bigr do rewrite index_uniq// valK. Qed. Lemma big_tuple I n (t : n.-tuple I) (P : pred I) F : \big[op/idx]_(i <- t | P i) F i = \big[op/idx]_(i < n | P (tnth t i)) F (tnth t i). Proof. by rewrite big_tnth tvalK; case: _ / (esym _). Qed. Lemma big_ord_narrow_cond n1 n2 (P : pred 'I_n2) F (le_n12 : n1 <= n2) : let w := widen_ord le_n12 in \big[op/idx]_(i < n2 | P i && (i < n1)) F i = \big[op/idx]_(i < n1 | P (w i)) F (w i). Proof. case: n1 => [|n1] /= in le_n12 *. by rewrite big_ord0 big_pred0 // => i; rewrite andbF. rewrite (big_ord_widen_leq _ _ le_n12); apply: eq_big => i. by apply: andb_id2r => le_i_n1; congr P; apply: val_inj; rewrite /= inordK. by case/andP=> _ le_i_n1; congr F; apply: val_inj; rewrite /= inordK. Qed. Lemma big_ord_narrow_cond_leq n1 n2 (P : pred _) F (le_n12 : n1 <= n2) : let w := @widen_ord n1.+1 n2.+1 le_n12 in \big[op/idx]_(i < n2.+1 | P i && (i <= n1)) F i = \big[op/idx]_(i < n1.+1 | P (w i)) F (w i). Proof. exact: (@big_ord_narrow_cond n1.+1 n2.+1). Qed. Lemma big_ord_narrow n1 n2 F (le_n12 : n1 <= n2) : let w := widen_ord le_n12 in \big[op/idx]_(i < n2 | i < n1) F i = \big[op/idx]_(i < n1) F (w i). Proof. exact: (big_ord_narrow_cond (predT)). Qed. Lemma big_ord_narrow_leq n1 n2 F (le_n12 : n1 <= n2) : let w := @widen_ord n1.+1 n2.+1 le_n12 in \big[op/idx]_(i < n2.+1 | i <= n1) F i = \big[op/idx]_(i < n1.+1) F (w i). Proof. exact: (big_ord_narrow_cond_leq (predT)). Qed. Lemma big_ord_recl n F : \big[op/idx]_(i < n.+1) F i = op (F ord0) (\big[op/idx]_(i < n) F (@lift n.+1 ord0 i)). Proof. pose G i := F (inord i); have eqFG i: F i = G i by rewrite /G inord_val. under eq_bigr do rewrite eqFG; under [in RHS]eq_bigr do rewrite eqFG. by rewrite -(big_mkord _ (fun _ => _) G) eqFG big_ltn // big_add1 /= big_mkord. Qed. Lemma big_nseq_cond I n a (P : pred I) F : \big[op/idx]_(i <- nseq n a | P i) F i = if P a then iter n (op (F a)) idx else idx. Proof. by rewrite unlock; elim: n => /= [|n ->]; case: (P a). Qed. Lemma big_nseq I n a (F : I -> R): \big[op/idx]_(i <- nseq n a) F i = iter n (op (F a)) idx. Proof. exact: big_nseq_cond. Qed. End Extensionality. Variant big_enum_spec (I : finType) (P : pred I) : seq I -> Type := BigEnumSpec e of forall R idx op (F : I -> R), \big[op/idx]_(i <- e) F i = \big[op/idx]_(i | P i) F i & uniq e /\ (forall i, i \in e = P i) & (let cP := [pred i | P i] in perm_eq e (enum cP) /\ size e = #|cP|) : big_enum_spec P e. (* This lemma can be used to introduce an enumeration into a non-abelian *) (* bigop, in one of three ways: *) (* have [e big_e [Ue mem_e] [e_enum size_e]] := big_enumP P. *) (* gives a permutation e of enum P alongside a equation big_e for converting *) (* between bigops iterating on (i <- e) and ones on (i | P i). Usually not *) (* all properties of e are needed, but see below the big_distr_big_dep proof *) (* where most are. *) (* rewrite -big_filter; have [e ...] := big_enumP. *) (* uses big_filter to do this conversion first, and then abstracts the *) (* resulting filter P (index_enum T) enumeration as an e with the same *) (* properties (see big_enum_cond below for an example of this usage). *) (* Finally *) (* rewrite -big_filter; case def_e: _ / big_enumP => [e ...] *) (* does the same while remembering the definition of e. *) Lemma big_enumP I P : big_enum_spec P (filter P (index_enum I)). Proof. set e := filter P _; have Ue: uniq e by apply/filter_uniq/index_enum_uniq. have mem_e i: i \in e = P i by rewrite mem_filter mem_index_enum andbT. split=> // [R idx op F | cP]; first by rewrite big_filter. suffices De: perm_eq e (enum cP) by rewrite (perm_size De) cardE. by apply/uniq_perm=> // [|i]; rewrite ?enum_uniq ?mem_enum ?mem_e. Qed. Section BigConst. Variables (R : Type) (idx : R) (op : R -> R -> R). Lemma big_const_seq I r (P : pred I) x : \big[op/idx]_(i <- r | P i) x = iter (count P r) (op x) idx. Proof. by rewrite unlock; elim: r => //= i r ->; case: (P i). Qed. Lemma big_const (I : finType) (A : {pred I}) x : \big[op/idx]_(i in A) x = iter #|A| (op x) idx. Proof. by have [e <- _ [_ <-]] := big_enumP A; rewrite big_const_seq count_predT. Qed. Lemma big_const_nat m n x : \big[op/idx]_(m <= i < n) x = iter (n - m) (op x) idx. Proof. by rewrite big_const_seq count_predT size_iota. Qed. Lemma big_const_ord n x : \big[op/idx]_(i < n) x = iter n (op x) idx. Proof. by rewrite big_const card_ord. Qed. End BigConst. Section Plain. Variable R : Type. Variable op : R -> R -> R. Variable x : R. Lemma big_seq1_id I (i : I) (F : I -> R) : \big[op/x]_(j <- [:: i]) F j = op (F i) x. Proof. by rewrite big_cons big_nil. Qed. Lemma big_nat1_id n F : \big[op/x]_(n <= i < n.+1) F i = op (F n) x. Proof. by rewrite big_ltn // big_geq // mulm1. Qed. Lemma big_pred1_eq_id (I : finType) (i : I) F : \big[op/x]_(j | j == i) F j = op (F i) x. Proof. have [e1 <- _ [e_enum _]] := big_enumP (pred1 i). by rewrite (perm_small_eq _ e_enum) enum1 ?big_seq1_id. Qed. Lemma big_pred1_id (I : finType) i (P : pred I) F : P =1 pred1 i -> \big[op/x]_(j | P j) F j = op (F i) x. Proof. by move/(eq_bigl _ _)->; apply: big_pred1_eq_id. Qed. End Plain. Section SemiGroupProperties. Variable R : Type. #[local] Notation opA := SemiGroup.opA. #[local] Notation opC := SemiGroup.opC. Section Id. Variable op : SemiGroup.law R. Variable x : R. Hypothesis opxx : op x x = x. Lemma big_const_idem I (r : seq I) P : \big[op/x]_(i <- r | P i) x = x. Proof. by elim/big_ind : _ => // _ _ -> ->. Qed. Lemma big1_idem I r (P : pred I) F : (forall i, P i -> F i = x) -> \big[op/x]_(i <- r | P i) F i = x. Proof. move=> Fix; under eq_bigr => ? ? do rewrite Fix//; exact: big_const_idem. Qed. Lemma big_id_idem I (r : seq I) P F : op (\big[op/x]_(i <- r | P i) F i) x = \big[op/x]_(i <- r | P i) F i. Proof. by elim/big_rec : _ => // ? ? ?; rewrite -opA => ->. Qed. End Id. Section Abelian. Variable op : SemiGroup.com_law R. Let opCA : left_commutative op. Proof. by move=> x *; rewrite !opA /= (opC x). Qed. Variable x : R. Lemma big_rem_AC (I : eqType) (r : seq I) z (P : pred I) F : z \in r -> \big[op/x]_(y <- r | P y) F y = if P z then op (F z) (\big[op/x]_(y <- rem z r | P y) F y) else \big[op/x]_(y <- rem z r | P y) F y. Proof. elim: r =>// i r ih; rewrite big_cons rem_cons inE =>/predU1P[-> /[!eqxx]//|zr]. by case: eqP => [-> //|]; rewrite ih// big_cons; case: ifPn; case: ifPn. Qed. Lemma big_undup (I : eqType) (r : seq I) (P : pred I) F : idempotent_op op -> \big[op/x]_(i <- undup r | P i) F i = \big[op/x]_(i <- r | P i) F i. Proof. move=> opxx; rewrite -!(big_filter _ _ _ P) filter_undup. elim: {P r}(filter P r) => //= i r IHr. case: ifP => [r_i | _]; rewrite !big_cons {}IHr //. by rewrite (big_rem_AC _ _ r_i) opA /= opxx. Qed. Lemma perm_big (I : eqType) r1 r2 (P : pred I) F : perm_eq r1 r2 -> \big[op/x]_(i <- r1 | P i) F i = \big[op/x]_(i <- r2 | P i) F i. Proof. elim: r1 r2 => [|i r1 IHr1] r2 eq_r12. by case: r2 eq_r12 => [//|i r2] /[1!perm_sym] /perm_nilP. have r2i: i \in r2 by rewrite -has_pred1 has_count -(permP eq_r12) /= eqxx. rewrite big_cons (IHr1 (rem i r2)) -?big_rem_AC// -(perm_cons i). exact: perm_trans (perm_to_rem _). Qed. Lemma big_enum_cond (I : finType) (A : {pred I}) (P : pred I) F : \big[op/x]_(i <- enum A | P i) F i = \big[op/x]_(i in A | P i) F i. Proof. by rewrite -big_filter_cond; have [e _ _ [/perm_big->]] := big_enumP. Qed. Lemma big_enum (I : finType) (A : {pred I}) F : \big[op/x]_(i <- enum A) F i = \big[op/x]_(i in A) F i. Proof. by rewrite big_enum_cond big_andbC. Qed. Lemma big_uniq (I : finType) (r : seq I) F : uniq r -> \big[op/x]_(i <- r) F i = \big[op/x]_(i in r) F i. Proof. move=> uniq_r; rewrite -big_enum; apply: perm_big. by rewrite uniq_perm ?enum_uniq // => i; rewrite mem_enum. Qed. Lemma bigD1 (I : finType) j (P : pred I) F : P j -> \big[op/x]_(i | P i) F i = op (F j) (\big[op/x]_(i | P i && (i != j)) F i). Proof. rewrite (big_rem_AC _ _ (mem_index_enum j)) => ->. by rewrite rem_filter ?index_enum_uniq// big_filter_cond big_andbC. Qed. Arguments bigD1 [I] j [P F]. Lemma bigD1_seq (I : eqType) (r : seq I) j F : j \in r -> uniq r -> \big[op/x]_(i <- r) F i = op (F j) (\big[op/x]_(i <- r | i != j) F i). Proof. by move=> /big_rem_AC-> /rem_filter->; rewrite big_filter. Qed. Lemma big_image_cond I (J : finType) (h : J -> I) (A : pred J) (P : pred I) F : \big[op/x]_(i <- [seq h j | j in A] | P i) F i = \big[op/x]_(j in A | P (h j)) F (h j). Proof. by rewrite big_map big_enum_cond. Qed. Lemma big_image I (J : finType) (h : J -> I) (A : pred J) F : \big[op/x]_(i <- [seq h j | j in A]) F i = \big[op/x]_(j in A) F (h j). Proof. by rewrite big_map big_enum. Qed. Lemma cardD1x (I : finType) (A : pred I) j : A j -> #|SimplPred A| = 1 + #|[pred i | A i & i != j]|. Proof. move=> Aj; rewrite (cardD1 j) [j \in A]Aj; congr (_ + _). by apply: eq_card => i; rewrite inE /= andbC. Qed. Arguments cardD1x [I A]. Lemma reindex_omap (I J : finType) (h : J -> I) h' (P : pred I) F : (forall i, P i -> omap h (h' i) = some i) -> \big[op/x]_(i | P i) F i = \big[op/x]_(j | P (h j) && (h' (h j) == some j)) F (h j). Proof. move=> h'K; have [n lePn] := ubnP #|P|; elim: n => // n IHn in P h'K lePn *. case: (pickP P) => [i Pi | P0]; last first. by rewrite !big_pred0 // => j; rewrite P0. have := h'K i Pi; case h'i_eq : (h' i) => [/= j|//] [hj_eq]. rewrite (bigD1 i Pi) (bigD1 j) hj_eq ?Pi ?h'i_eq ?eqxx //=; congr (op : _ -> _). rewrite {}IHn => [|k /andP[]|]; [|by auto | by rewrite (cardD1x i) in lePn]. apply: eq_bigl => k; rewrite andbC -andbA (andbCA (P _)); case: eqP => //= hK. congr (_ && ~~ _); apply/eqP/eqP => [|->//]. by move=> /(congr1 h'); rewrite h'i_eq hK => -[]. Qed. Arguments reindex_omap [I J] h h' [P F]. Lemma reindex_onto (I J : finType) (h : J -> I) h' (P : pred I) F : (forall i, P i -> h (h' i) = i) -> \big[op/x]_(i | P i) F i = \big[op/x]_(j | P (h j) && (h' (h j) == j)) F (h j). Proof. by move=> h'K; rewrite (reindex_omap h (some \o h'))//= => i Pi; rewrite h'K. Qed. Arguments reindex_onto [I J] h h' [P F]. Lemma reindex (I J : finType) (h : J -> I) (P : pred I) F : {on [pred i | P i], bijective h} -> \big[op/x]_(i | P i) F i = \big[op/x]_(j | P (h j)) F (h j). Proof. case=> h' hK h'K; rewrite (reindex_onto h h' h'K). by apply: eq_bigl => j /[!inE]; case Pi: (P _); rewrite //= hK ?eqxx. Qed. Arguments reindex [I J] h [P F]. Lemma reindex_inj (I : finType) (h : I -> I) (P : pred I) F : injective h -> \big[op/x]_(i | P i) F i = \big[op/x]_(j | P (h j)) F (h j). Proof. by move=> injh; apply: reindex (onW_bij _ (injF_bij injh)). Qed. Arguments reindex_inj [I h P F]. Lemma bigD1_ord n j (P : pred 'I_n) F : P j -> \big[op/x]_(i < n | P i) F i = op (F j) (\big[op/x]_(i < n.-1 | P (lift j i)) F (lift j i)). Proof. move=> Pj; rewrite (bigD1 j Pj) (reindex_omap (lift j) (unlift j))/=. by under eq_bigl do rewrite liftK eq_sym eqxx neq_lift ?andbT. by move=> i; case: unliftP => [k ->|->]; rewrite ?eqxx ?andbF. Qed. Lemma big_enum_val_cond (I : finType) (A : pred I) (P : pred I) F : \big[op/x]_(x in A | P x) F x = \big[op/x]_(i < #|A| | P (enum_val i)) F (enum_val i). Proof. have [A_eq0|/card_gt0P[x0 x0A]] := posnP #|A|. rewrite !big_pred0 // => i; last by rewrite card0_eq. by have: false by move: i => []; rewrite A_eq0. rewrite (reindex (enum_val : 'I_#|A| -> I)). by apply: eq_big => [y|y Py]; rewrite ?enum_valP. by apply: subon_bij (enum_val_bij_in x0A) => y /andP[]. Qed. Arguments big_enum_val_cond [I A] P F. Lemma big_enum_rank_cond (I : finType) (A : pred I) z (zA : z \in A) P F (h := enum_rank_in zA) : \big[op/x]_(i < #|A| | P i) F i = \big[op/x]_(s in A | P (h s)) F (h s). Proof. rewrite big_enum_val_cond {}/h. by apply: eq_big => [i|i Pi]; rewrite ?enum_valK_in. Qed. Arguments big_enum_rank_cond [I A z] zA P F. Lemma big_nat_rev m n P F : \big[op/x]_(m <= i < n | P i) F i = \big[op/x]_(m <= i < n | P (m + n - i.+1)) F (m + n - i.+1). Proof. case: (ltnP m n) => ltmn; last by rewrite !big_geq. rewrite -{3 4}(subnK (ltnW ltmn)) addnA. do 2!rewrite (big_addn _ _ 0) big_mkord; rewrite (reindex_inj rev_ord_inj)/=. by apply: eq_big => [i | i _]; rewrite /= -addSn subnDr addnC addnBA. Qed. Lemma big_rev_mkord m n P F : \big[op/x]_(m <= k < n | P k) F k = \big[op/x]_(k < n - m | P (n - k.+1)) F (n - k.+1). Proof. rewrite big_nat_rev (big_addn _ _ 0) big_mkord. by apply: eq_big => [i|i _]; rewrite -addSn addnC subnDr. Qed. Section Id. Hypothesis opxx : op x x = x. Lemma big_mkcond_idem I r (P : pred I) F : \big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) (if P i then F i else x). Proof. elim: r => [|i r]; rewrite ?(big_nil, big_cons)//. by case: ifPn => Pi ->//; rewrite -[in LHS]big_id_idem // opC. Qed. Lemma big_mkcondr_idem I r (P Q : pred I) F : \big[op/x]_(i <- r | P i && Q i) F i = \big[op/x]_(i <- r | P i) (if Q i then F i else x). Proof. by rewrite -big_filter_cond big_mkcond_idem big_filter. Qed. Lemma big_mkcondl_idem I r (P Q : pred I) F : \big[op/x]_(i <- r | P i && Q i) F i = \big[op/x]_(i <- r | Q i) (if P i then F i else x). Proof. by rewrite big_andbC big_mkcondr_idem. Qed. Lemma big_rmcond_idem I (r : seq I) (P : pred I) F : (forall i, ~~ P i -> F i = x) -> \big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) F i. Proof. move=> F_eq1; rewrite big_mkcond_idem; apply: eq_bigr => i. by case: (P i) (F_eq1 i) => // ->. Qed. Lemma big_rmcond_in_idem (I : eqType) (r : seq I) (P : pred I) F : (forall i, i \in r -> ~~ P i -> F i = x) -> \big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) F i. Proof. move=> F_eq1; rewrite big_seq_cond [RHS]big_seq_cond !big_mkcondl_idem. by rewrite big_rmcond_idem => // i /F_eq1; case: ifP => // _ ->. Qed. Lemma big_cat_idem I r1 r2 (P : pred I) F : \big[op/x]_(i <- r1 ++ r2 | P i) F i = op (\big[op/x]_(i <- r1 | P i) F i) (\big[op/x]_(i <- r2 | P i) F i). Proof. elim: r1 => [/=|i r1 IHr1]; first by rewrite big_nil opC big_id_idem. by rewrite /= big_cons IHr1 big_cons; case: (P i); rewrite // opA. Qed. Lemma big_allpairs_dep_idem I1 (I2 : I1 -> Type) J (h : forall i1, I2 i1 -> J) (r1 : seq I1) (r2 : forall i1, seq (I2 i1)) (F : J -> R) : \big[op/x]_(i <- [seq h i1 i2 | i1 <- r1, i2 <- r2 i1]) F i = \big[op/x]_(i1 <- r1) \big[op/x]_(i2 <- r2 i1) F (h i1 i2). Proof. elim: r1 => [|i1 r1 IHr1]; first by rewrite !big_nil. by rewrite big_cat_idem IHr1 big_cons big_map. Qed. Lemma big_allpairs_idem I1 I2 (r1 : seq I1) (r2 : seq I2) F : \big[op/x]_(i <- [seq (i1, i2) | i1 <- r1, i2 <- r2]) F i = \big[op/x]_(i1 <- r1) \big[op/x]_(i2 <- r2) F (i1, i2). Proof. exact: big_allpairs_dep_idem. Qed. Lemma big_cat_nat_idem n m p (P : pred nat) F : m <= n -> n <= p -> \big[op/x]_(m <= i < p | P i) F i = op (\big[op/x]_(m <= i < n | P i) F i) (\big[op/x]_(n <= i < p | P i) F i). Proof. move=> le_mn le_np; rewrite -big_cat_idem -{2}(subnKC le_mn) -iotaD subnDA. by rewrite subnKC // leq_sub. Qed. Lemma big_split_idem I r (P : pred I) F1 F2 : \big[op/x]_(i <- r | P i) op (F1 i) (F2 i) = op (\big[op/x]_(i <- r | P i) F1 i) (\big[op/x]_(i <- r | P i) F2 i). Proof. by elim/big_rec3: _ => [|i x' y _ _ ->]; rewrite ?opxx// opCA -!opA opCA. Qed. Lemma big_id_idem_AC I (r : seq I) P F : \big[op/x]_(i <- r | P i) op (F i) x = \big[op/x]_(i <- r | P i) F i. Proof. by rewrite big_split_idem big_const_idem ?big_id_idem. Qed. Lemma bigID_idem I r (a P : pred I) F : \big[op/x]_(i <- r | P i) F i = op (\big[op/x]_(i <- r | P i && a i) F i) (\big[op/x]_(i <- r | P i && ~~ a i) F i). Proof. rewrite -big_id_idem_AC big_mkcond_idem !(big_mkcond_idem _ _ F) -big_split_idem. by apply: eq_bigr => i; case: ifPn => //=; case: ifPn; rewrite // opC. Qed. Arguments bigID_idem [I r]. Lemma bigU_idem (I : finType) (A B : pred I) F : [disjoint A & B] -> \big[op/x]_(i in [predU A & B]) F i = op (\big[op/x]_(i in A) F i) (\big[op/x]_(i in B) F i). Proof. move=> dAB; rewrite (bigID_idem (mem A)). congr (op : _ -> _); apply: eq_bigl => i; first by rewrite orbK. by have:= pred0P dAB i; rewrite andbC /= !inE; case: (i \in A). Qed. Lemma partition_big_idem I (s : seq I) (J : finType) (P : pred I) (p : I -> J) (Q : pred J) F : (forall i, P i -> Q (p i)) -> \big[op/x]_(i <- s | P i) F i = \big[op/x]_(j : J | Q j) \big[op/x]_(i <- s | (P i) && (p i == j)) F i. Proof. move=> Qp; transitivity (\big[op/x]_(i <- s | P i && Q (p i)) F i). by apply: eq_bigl => i; case Pi: (P i); rewrite // Qp. have [n leQn] := ubnP #|Q|; elim: n => // n IHn in Q {Qp} leQn *. case: (pickP Q) => [j Qj | Q0]; last first. by rewrite !big_pred0 // => i; rewrite Q0 andbF. rewrite (bigD1 j) // -IHn; last by rewrite ltnS (cardD1x j Qj) in leQn. rewrite (bigID_idem (fun i => p i == j)). congr (op : _ -> _); apply: eq_bigl => i; last by rewrite andbA. by case: eqP => [->|_]; rewrite !(Qj, andbT, andbF). Qed. Arguments partition_big_idem [I s J P] p Q [F]. Lemma sig_big_dep_idem (I : finType) (J : I -> finType) (P : pred I) (Q : forall {i}, pred (J i)) (F : forall {i}, J i -> R) : \big[op/x]_(i | P i) \big[op/x]_(j : J i | Q j) F j = \big[op/x]_(p : {i : I & J i} | P (tag p) && Q (tagged p)) F (tagged p). Proof. pose s := [seq Tagged J j | i <- index_enum I, j <- index_enum (J i)]. rewrite [LHS]big_mkcond_idem big_mkcondl_idem. rewrite [RHS]big_mkcond_idem -[RHS](@perm_big _ s). rewrite big_allpairs_dep_idem/=; apply: eq_bigr => i _. by rewrite -big_mkcond_idem/=; case: P; rewrite // big1_idem. rewrite uniq_perm ?index_enum_uniq//. by rewrite allpairs_uniq_dep// => [|i|[i j] []]; rewrite ?index_enum_uniq. by move=> [i j]; rewrite ?mem_index_enum; apply/allpairsPdep; exists i, j. Qed. Lemma pair_big_dep_idem (I J : finType) (P : pred I) (Q : I -> pred J) F : \big[op/x]_(i | P i) \big[op/x]_(j | Q i j) F i j = \big[op/x]_(p | P p.1 && Q p.1 p.2) F p.1 p.2. Proof. rewrite sig_big_dep_idem; apply: (reindex (fun x => Tagged (fun=> J) x.2)). by exists (fun x => (projT1 x, projT2 x)) => -[]. Qed. Lemma pair_big_idem (I J : finType) (P : pred I) (Q : pred J) F : \big[op/x]_(i | P i) \big[op/x]_(j | Q j) F i j = \big[op/x]_(p | P p.1 && Q p.2) F p.1 p.2. Proof. exact: pair_big_dep_idem. Qed. Lemma pair_bigA_idem (I J : finType) (F : I -> J -> R) : \big[op/x]_i \big[op/x]_j F i j = \big[op/x]_p F p.1 p.2. Proof. exact: pair_big_dep_idem. Qed. Lemma exchange_big_dep_idem I J rI rJ (P : pred I) (Q : I -> pred J) (xQ : pred J) F : (forall i j, P i -> Q i j -> xQ j) -> \big[op/x]_(i <- rI | P i) \big[op/x]_(j <- rJ | Q i j) F i j = \big[op/x]_(j <- rJ | xQ j) \big[op/x]_(i <- rI | P i && Q i j) F i j. Proof. move=> PQxQ; pose p u := (u.2, u.1). under [LHS]eq_bigr do rewrite big_tnth; rewrite [LHS]big_tnth. under [RHS]eq_bigr do rewrite big_tnth; rewrite [RHS]big_tnth. rewrite !pair_big_dep_idem (reindex_onto (p _ _) (p _ _)) => [|[]] //=. apply: eq_big => [] [j i] //=; symmetry; rewrite eqxx andbT andb_idl //. by case/andP; apply: PQxQ. Qed. Arguments exchange_big_dep_idem [I J rI rJ P Q] xQ [F]. Lemma exchange_big_idem I J rI rJ (P : pred I) (Q : pred J) F : \big[op/x]_(i <- rI | P i) \big[op/x]_(j <- rJ | Q j) F i j = \big[op/x]_(j <- rJ | Q j) \big[op/x]_(i <- rI | P i) F i j. Proof. rewrite (exchange_big_dep_idem Q) //. by under eq_bigr => i Qi do under eq_bigl do rewrite Qi andbT. Qed. Lemma exchange_big_dep_nat_idem m1 n1 m2 n2 (P : pred nat) (Q : rel nat) (xQ : pred nat) F : (forall i j, m1 <= i < n1 -> m2 <= j < n2 -> P i -> Q i j -> xQ j) -> \big[op/x]_(m1 <= i < n1 | P i) \big[op/x]_(m2 <= j < n2 | Q i j) F i j = \big[op/x]_(m2 <= j < n2 | xQ j) \big[op/x]_(m1 <= i < n1 | P i && Q i j) F i j. Proof. move=> PQxQ; under eq_bigr do rewrite big_seq_cond. rewrite big_seq_cond /= (exchange_big_dep_idem xQ) => [|i j]; last first. by rewrite !mem_index_iota => /andP[mn_i Pi] /andP[mn_j /PQxQ->]. rewrite 2!(big_seq_cond _ _ _ xQ); apply: eq_bigr => j /andP[-> _] /=. by rewrite [rhs in _ = rhs]big_seq_cond; apply: eq_bigl => i; rewrite -andbA. Qed. Arguments exchange_big_dep_nat_idem [m1 n1 m2 n2 P Q] xQ [F]. Lemma exchange_big_nat_idem m1 n1 m2 n2 (P Q : pred nat) F : \big[op/x]_(m1 <= i < n1 | P i) \big[op/x]_(m2 <= j < n2 | Q j) F i j = \big[op/x]_(m2 <= j < n2 | Q j) \big[op/x]_(m1 <= i < n1 | P i) F i j. Proof. rewrite (exchange_big_dep_nat_idem Q) //. by under eq_bigr => i Qi do under eq_bigl do rewrite Qi andbT. Qed. End Id. End Abelian. End SemiGroupProperties. Arguments big_undup [R op x I]. Arguments perm_big [R op x I r1 r2]. Arguments bigD1 [R op x I] j [P F]. Arguments reindex_omap [R op x I J] h h' [P F]. Arguments reindex_onto [R op x I J] h h' [P F]. Arguments reindex [R op x I J] h [P F]. Arguments reindex_inj [R op x I h P F]. Arguments big_enum_val_cond [R op x I A] P F. Arguments big_enum_rank_cond [R op x I A z] zA P F. Section MonoidProperties. Import Monoid.Theory. Variable R : Type. Variable idx : R. Local Notation "1" := idx. Section Plain. Variable op : Monoid.law 1. Local Notation "*%M" := op. Local Notation "x * y" := (op x y). Lemma foldlE x r : foldl *%M x r = \big[*%M/1]_(y <- x :: r) y. Proof. by rewrite -foldrE; elim: r => [|y r IHr]/= in x *; rewrite ?mulm1 ?mulmA ?IHr. Qed. Lemma foldl_idx r : foldl *%M 1 r = \big[*%M/1]_(x <- r) x. Proof. by rewrite foldlE big_cons mul1m. Qed. Lemma eq_big_idx_seq idx' I r (P : pred I) F : right_id idx' *%M -> has P r -> \big[*%M/idx']_(i <- r | P i) F i = \big[*%M/1]_(i <- r | P i) F i. Proof. move=> op_idx'; rewrite -!(big_filter _ _ r) has_count -size_filter. case/lastP: (filter P r) => {r}// r i _. by rewrite -cats1 !(big_cat_nested, big_cons, big_nil) op_idx' mulm1. Qed. Lemma eq_big_idx idx' (I : finType) i0 (P : pred I) F : P i0 -> right_id idx' *%M -> \big[*%M/idx']_(i | P i) F i = \big[*%M/1]_(i | P i) F i. Proof. by move=> Pi0 op_idx'; apply: eq_big_idx_seq => //; apply/hasP; exists i0. Qed. Lemma big_change_idx I x r (P : pred I) F : \big[*%M/x]_(j <- r | P j) F j = (\big[*%M/1]_(j <- r | P j) F j) * x. Proof. elim: r => [|i r]; rewrite ?(big_nil, big_cons, mul1m)// => ->. by case: ifP => // Pi; rewrite mulmA. Qed. Lemma big1_eq I r (P : pred I) : \big[*%M/1]_(i <- r | P i) 1 = 1. Proof. by rewrite big1_idem //= mul1m. Qed. Lemma big1 I r (P : pred I) F : (forall i, P i -> F i = 1) -> \big[*%M/1]_(i <- r | P i) F i = 1. Proof. by move/(eq_bigr _)->; apply: big1_eq. Qed. Lemma big1_seq (I : eqType) r (P : pred I) F : (forall i, P i && (i \in r) -> F i = 1) -> \big[*%M/1]_(i <- r | P i) F i = 1. Proof. by move=> eqF1; rewrite big_seq_cond big_andbC big1. Qed. Lemma big_seq1 I (i : I) F : \big[*%M/1]_(j <- [:: i]) F j = F i. Proof. by rewrite big_seq1_id mulm1. Qed. Lemma big_rcons I i r (P : pred I) F : \big[*%M/1]_(j <- rcons r i | P j) F j = (\big[*%M/1]_(j <- r | P j) F j) * (if P i then F i else idx). Proof. by rewrite big_rcons_op big_change_idx mulm1. Qed. Lemma big_mkcond I r (P : pred I) F : \big[*%M/1]_(i <- r | P i) F i = \big[*%M/1]_(i <- r) (if P i then F i else 1). Proof. by rewrite unlock; elim: r => //= i r ->; case P; rewrite ?mul1m. Qed. Lemma big_mkcondr I r (P Q : pred I) F : \big[*%M/1]_(i <- r | P i && Q i) F i = \big[*%M/1]_(i <- r | P i) (if Q i then F i else 1). Proof. by rewrite -big_filter_cond big_mkcond big_filter. Qed. Lemma big_mkcondl I r (P Q : pred I) F : \big[*%M/1]_(i <- r | P i && Q i) F i = \big[*%M/1]_(i <- r | Q i) (if P i then F i else 1). Proof. by rewrite big_andbC big_mkcondr. Qed. Lemma big_rmcond I (r : seq I) (P : pred I) F : (forall i, ~~ P i -> F i = 1) -> \big[*%M/1]_(i <- r | P i) F i = \big[*%M/1]_(i <- r) F i. Proof. move=> F_eq1; rewrite big_mkcond; apply: eq_bigr => i. by case: (P i) (F_eq1 i) => // ->. Qed. Lemma big_rmcond_in (I : eqType) (r : seq I) (P : pred I) F : (forall i, i \in r -> ~~ P i -> F i = 1) -> \big[*%M/1]_(i <- r | P i) F i = \big[*%M/1]_(i <- r) F i. Proof. move=> F_eq1; rewrite big_seq_cond [RHS]big_seq_cond !big_mkcondl big_rmcond//. by move=> i /F_eq1; case: ifP => // _ ->. Qed. Lemma big_cat I r1 r2 (P : pred I) F : \big[*%M/1]_(i <- r1 ++ r2 | P i) F i = \big[*%M/1]_(i <- r1 | P i) F i * \big[*%M/1]_(i <- r2 | P i) F i. Proof. rewrite !(big_mkcond _ P) unlock. by elim: r1 => /= [|i r1 ->]; rewrite (mul1m, mulmA). Qed. Lemma big_allpairs_dep I1 (I2 : I1 -> Type) J (h : forall i1, I2 i1 -> J) (r1 : seq I1) (r2 : forall i1, seq (I2 i1)) (F : J -> R) : \big[*%M/1]_(i <- [seq h i1 i2 | i1 <- r1, i2 <- r2 i1]) F i = \big[*%M/1]_(i1 <- r1) \big[*%M/1]_(i2 <- r2 i1) F (h i1 i2). Proof. elim: r1 => [|i1 r1 IHr1]; first by rewrite !big_nil. by rewrite big_cat IHr1 big_cons big_map. Qed. Lemma big_allpairs I1 I2 (r1 : seq I1) (r2 : seq I2) F : \big[*%M/1]_(i <- [seq (i1, i2) | i1 <- r1, i2 <- r2]) F i = \big[*%M/1]_(i1 <- r1) \big[op/idx]_(i2 <- r2) F (i1, i2). Proof. exact: big_allpairs_dep. Qed. Lemma rev_big_rev I (r : seq I) P F : \big[*%M/1]_(i <- rev r | P i) F i = \big[(fun x y => y * x)/1]_(i <- r | P i) F i. Proof. elim: r => [|i r IHr]; rewrite ?big_nil// big_cons rev_cons big_rcons IHr. by case: (P i); rewrite ?mulm1. Qed. Lemma big_only1 (I : finType) (i : I) (P : pred I) (F : I -> R) : P i -> (forall j, j != i -> P j -> F j = idx) -> \big[op/idx]_(j | P j) F j = F i. Proof. move=> Pi Fisx; have := index_enum_uniq I. have : i \in index_enum I by rewrite mem_index_enum. elim: index_enum => //= j r IHr /[!inE]; case: eqVneq => [<-|nij]//=. move=> _ /andP[iNr runiq]; rewrite big_cons/= Pi big1_seq ?Monoid.mulm1//. by move=> {}j /andP[/Fisx + jr] => ->//; apply: contraNneq iNr => <-. move=> ir /andP[jNr runiq]; rewrite big_cons IHr//. by case: ifPn => // /Fisx->; rewrite 1?eq_sym// Monoid.mul1m. Qed. Lemma big_pred1_eq (I : finType) (i : I) F : \big[*%M/1]_(j | j == i) F j = F i. Proof. by rewrite (@big_only1 _ i)// => j /negPf->. Qed. Lemma big_pred1 (I : finType) i (P : pred I) F : P =1 pred1 i -> \big[*%M/1]_(j | P j) F j = F i. Proof. by move/(eq_bigl _ _)->; apply: big_pred1_eq. Qed. Lemma big_ord1 F : \big[op/idx]_(i < 1) F i = F ord0. Proof. by rewrite big_ord_recl big_ord0 Monoid.mulm1. Qed. Lemma big_ord1_cond P F : \big[op/idx]_(i < 1 | P i) F i = if P ord0 then F ord0 else idx. Proof. by rewrite big_mkcond big_ord1. Qed. Lemma big_ord1_eq (F : nat -> R) i n : \big[op/idx]_(j < n | j == i :> nat) F j = if i < n then F i else idx. Proof. case: ltnP => [i_lt|i_ge]; first by rewrite (big_pred1_eq (Ordinal _)). by rewrite big_pred0// => j; apply: contra_leqF i_ge => /eqP <-. Qed. Lemma big_ord1_cond_eq (F : nat -> R) (P : pred nat) i n : \big[op/idx]_(j < n | P j && (j == i :> nat)) F j = if (i < n) && P i then F i else idx. Proof. by rewrite big_mkcondl if_and (big_ord1_eq (fun j => if P j then F j else _)). Qed. Lemma big_cat_nat n m p (P : pred nat) F : m <= n -> n <= p -> \big[*%M/1]_(m <= i < p | P i) F i = (\big[*%M/1]_(m <= i < n | P i) F i) * (\big[*%M/1]_(n <= i < p | P i) F i). Proof. move=> le_mn le_np; rewrite -big_cat -{2}(subnKC le_mn) -iotaD subnDA. by rewrite subnKC // leq_sub. Qed. Lemma big_nat_widenl (m1 m2 n : nat) (P : pred nat) F : m2 <= m1 -> \big[op/idx]_(m1 <= i < n | P i) F i = \big[op/idx]_(m2 <= i < n | P i && (m1 <= i)) F i. Proof. move=> le_m21; have [le_nm1|lt_m1n] := leqP n m1. rewrite big_geq// big_nat_cond big1//. by move=> i /and3P[/andP[_ /leq_trans/(_ le_nm1)/ltn_geF->]]. rewrite big_mkcond big_mkcondl (big_cat_nat _ _ le_m21) 1?ltnW//. rewrite [X in op X]big_nat_cond [X in op X]big_pred0; last first. by move=> k; case: ltnP; rewrite andbF. by rewrite Monoid.mul1m; apply: congr_big_nat => // k /andP[]. Qed. Lemma big_geq_mkord (m n : nat) (P : pred nat) F : \big[op/idx]_(m <= i < n | P i) F i = \big[op/idx]_(i < n | P i && (m <= i)) F i. Proof. by rewrite (@big_nat_widenl _ 0)// big_mkord. Qed. Lemma big_nat1_eq (F : nat -> R) i m n : \big[op/idx]_(m <= j < n | j == i) F j = if m <= i < n then F i else idx. Proof. by rewrite big_geq_mkord big_andbC big_ord1_cond_eq andbC. Qed. Lemma big_nat1_cond_eq (F : nat -> R) (P : pred nat) i m n : \big[op/idx]_(m <= j < n | P j && (j == i)) F j = if (m <= i < n) && P i then F i else idx. Proof. by rewrite big_mkcondl big_nat1_eq -if_and. Qed. Lemma big_nat1 n F : \big[*%M/1]_(n <= i < n.+1) F i = F n. Proof. by rewrite big_ltn // big_geq // mulm1. Qed. Lemma big_nat_recr n m F : m <= n -> \big[*%M/1]_(m <= i < n.+1) F i = (\big[*%M/1]_(m <= i < n) F i) * F n. Proof. by move=> lemn; rewrite (@big_cat_nat n) ?leqnSn // big_nat1. Qed. Lemma big_nat_mul n k F : \big[*%M/1]_(0 <= i < n * k) F i = \big[*%M/1]_(0 <= i < n) \big[*%M/1]_(i * k <= j < i.+1 * k) F j. Proof. elim: n => [|n ih]; first by rewrite mul0n 2!big_nil. rewrite [in RHS]big_nat_recr//= -ih mulSn addnC [in LHS]/index_iota subn0 iotaD. rewrite big_cat /= [in X in _ = X * _]/index_iota subn0; congr (_ * _). by rewrite add0n /index_iota (addnC _ k) addnK. Qed. Lemma big_ord_recr n F : \big[*%M/1]_(i < n.+1) F i = (\big[*%M/1]_(i < n) F (widen_ord (leqnSn n) i)) * F ord_max. Proof. transitivity (\big[*%M/1]_(0 <= i < n.+1) F (inord i)). by rewrite big_mkord; apply: eq_bigr=> i _; rewrite inord_val. rewrite big_nat_recr // big_mkord; congr (_ * F _); last first. by apply: val_inj; rewrite /= inordK. by apply: eq_bigr => [] i _; congr F; apply: ord_inj; rewrite inordK //= leqW. Qed. Lemma big_sumType (I1 I2 : finType) (P : pred (I1 + I2)) F : \big[*%M/1]_(i | P i) F i = (\big[*%M/1]_(i | P (inl _ i)) F (inl _ i)) * (\big[*%M/1]_(i | P (inr _ i)) F (inr _ i)). Proof. by rewrite ![index_enum _]unlock [@Finite.enum in LHS]unlock/= big_cat !big_map. Qed. Lemma big_split_ord m n (P : pred 'I_(m + n)) F : \big[*%M/1]_(i | P i) F i = (\big[*%M/1]_(i | P (lshift n i)) F (lshift n i)) * (\big[*%M/1]_(i | P (rshift m i)) F (rshift m i)). Proof. rewrite -(big_map _ _ (lshift n) _ P F) -(big_map _ _ (@rshift m _) _ P F). rewrite -big_cat; congr bigop; apply: (inj_map val_inj). rewrite map_cat -!map_comp (map_comp (addn m)) /=. by rewrite ![index_enum _]unlock unlock !val_ord_enum -iotaDl addn0 iotaD. Qed. Lemma big_flatten I rr (P : pred I) F : \big[*%M/1]_(i <- flatten rr | P i) F i = \big[*%M/1]_(r <- rr) \big[*%M/1]_(i <- r | P i) F i. Proof. by elim: rr => [|r rr IHrr]; rewrite ?big_nil //= big_cat big_cons -IHrr. Qed. Lemma big_pmap J I (h : J -> option I) (r : seq J) F : \big[op/idx]_(i <- pmap h r) F i = \big[op/idx]_(j <- r) oapp F idx (h j). Proof. elim: r => [| r0 r IHr]/=; first by rewrite !big_nil. rewrite /= big_cons; case: (h r0) => [i|] /=; last by rewrite mul1m. by rewrite big_cons IHr. Qed. Lemma telescope_big (f : nat -> nat -> R) (n m : nat) : (forall k, n < k < m -> op (f n k) (f k k.+1) = f n k.+1) -> \big[op/idx]_(n <= i < m) f i i.+1 = if n < m then f n m else idx. Proof. elim: m => [//| m IHm]; first by rewrite ltn0 big_geq. move=> tm; rewrite ltnS; case: ltnP=> // mn; first by rewrite big_geq. rewrite big_nat_recr// IHm//; last first. by move=> k /andP[nk /ltnW nm]; rewrite tm// nk. by case: ltngtP mn=> //= [nm|<-]; rewrite ?mul1m// tm// nm leqnn. Qed. End Plain. Section Abelian. Variable op : Monoid.com_law 1. Local Notation "'*%M'" := op. Local Notation "x * y" := (op x y). Lemma big_rem (I : eqType) r x (P : pred I) F : x \in r -> \big[*%M/1]_(y <- r | P y) F y = (if P x then F x else 1) * \big[*%M/1]_(y <- rem x r | P y) F y. Proof. by move/perm_to_rem/(perm_big _)->; rewrite !(big_mkcond _ _ P) big_cons. Qed. Lemma big_rev I (r : seq I) P F : \big[*%M/1]_(i <- rev r | P i) F i = \big[*%M/1]_(i <- r | P i) F i. Proof. by rewrite rev_big_rev; apply: (eq_big_op (fun=> True)) => // *; apply: mulmC. Qed. Lemma eq_big_idem (I : eqType) (r1 r2 : seq I) (P : pred I) F : idempotent_op *%M -> r1 =i r2 -> \big[*%M/1]_(i <- r1 | P i) F i = \big[*%M/1]_(i <- r2 | P i) F i. Proof. move=> idM eq_r; rewrite -big_undup // -(big_undup r2) //; apply/perm_big. by rewrite uniq_perm ?undup_uniq // => i; rewrite !mem_undup eq_r. Qed. Lemma big_undup_iterop_count (I : eqType) (r : seq I) (P : pred I) F : \big[*%M/1]_(i <- undup r | P i) iterop (count_mem i r) *%M (F i) 1 = \big[*%M/1]_(i <- r | P i) F i. Proof. rewrite -[RHS](perm_big _ F (perm_count_undup _)) big_flatten big_map. by rewrite [LHS]big_mkcond; apply: eq_bigr=> i _; rewrite big_nseq_cond iteropE. Qed. Lemma big_split I r (P : pred I) F1 F2 : \big[*%M/1]_(i <- r | P i) (F1 i * F2 i) = \big[*%M/1]_(i <- r | P i) F1 i * \big[*%M/1]_(i <- r | P i) F2 i. Proof. exact/big_split_idem/mul1m. Qed. Lemma bigID I r (a P : pred I) F : \big[*%M/1]_(i <- r | P i) F i = \big[*%M/1]_(i <- r | P i && a i) F i * \big[*%M/1]_(i <- r | P i && ~~ a i) F i. Proof. exact/bigID_idem/mul1m. Qed. Arguments bigID [I r]. Lemma big_if I r (P Q : pred I) F G : \big[*%M/1]_(i <- r | P i) (if Q i then F i else G i) = \big[*%M/1]_(i <- r | P i && Q i) F i * \big[*%M/1]_(i <- r | P i && ~~ Q i) G i. Proof. rewrite (bigID Q); congr (_ * _); apply: eq_bigr => i /andP[_]. by move=> ->. by move=> /negPf ->. Qed. Lemma bigU (I : finType) (A B : pred I) F : [disjoint A & B] -> \big[*%M/1]_(i in [predU A & B]) F i = (\big[*%M/1]_(i in A) F i) * (\big[*%M/1]_(i in B) F i). Proof. exact/bigU_idem/mul1m. Qed. Lemma partition_big I (s : seq I) (J : finType) (P : pred I) (p : I -> J) (Q : pred J) F : (forall i, P i -> Q (p i)) -> \big[*%M/1]_(i <- s | P i) F i = \big[*%M/1]_(j : J | Q j) \big[*%M/1]_(i <- s | (P i) && (p i == j)) F i. Proof. move=> Qp; transitivity (\big[*%M/1]_(i <- s | P i && Q (p i)) F i). by apply: eq_bigl => i; case Pi: (P i); rewrite // Qp. have [n leQn] := ubnP #|Q|; elim: n => // n IHn in Q {Qp} leQn *. case: (pickP Q) => [j Qj | Q0]; last first. by rewrite !big_pred0 // => i; rewrite Q0 andbF. rewrite (bigD1 j) // -IHn; last by rewrite ltnS (cardD1x Qj) in leQn. rewrite (bigID (fun i => p i == j)); congr (_ * _); apply: eq_bigl => i. by case: eqP => [-> | _]; rewrite !(Qj, simpm). by rewrite andbA. Qed. Arguments partition_big [I s J P] p Q [F]. Lemma big_enum_val (I : finType) (A : pred I) F : \big[op/idx]_(x in A) F x = \big[op/idx]_(i < #|A|) F (enum_val i). Proof. by rewrite -(big_enum_val_cond predT) big_mkcondr. Qed. Arguments big_enum_val [I A] F. Lemma big_enum_rank (I : finType) (A : pred I) x (xA : x \in A) F (h := enum_rank_in xA) : \big[op/idx]_(i < #|A|) F i = \big[op/idx]_(s in A) F (h s). Proof. by rewrite (big_enum_rank_cond xA) big_mkcondr. Qed. Arguments big_enum_rank [I A x] xA F. Lemma big_sub_cond (I : finType) (A P : {pred I}) (F : I -> R) : \big[*%M/1]_(i in A | P i) F i = \big[*%M/1]_(x : {x in A} | P (val x)) F (val x). Proof. rewrite (reindex_omap (val : {x in A} -> I) insub); last first. by move=> i /andP[iA Pi]; rewrite insubT. by apply: eq_bigl=> -[i iA]/=; rewrite insubT ?iA /= eqxx andbT. Qed. Lemma big_sub (I : finType) (A : {pred I}) (F : I -> R) : \big[*%M/1]_(i in A) F i = \big[*%M/1]_(x : {x in A}) F (val x). Proof. by rewrite -(big_sub_cond A xpredT) big_mkcondr. Qed. Lemma sig_big_dep (I : finType) (J : I -> finType) (P : pred I) (Q : forall {i}, pred (J i)) (F : forall {i}, J i -> R) : \big[op/idx]_(i | P i) \big[op/idx]_(j : J i | Q j) F j = \big[op/idx]_(p : {i : I & J i} | P (tag p) && Q (tagged p)) F (tagged p). Proof. exact/sig_big_dep_idem/mul1m. Qed. Lemma pair_big_dep (I J : finType) (P : pred I) (Q : I -> pred J) F : \big[*%M/1]_(i | P i) \big[*%M/1]_(j | Q i j) F i j = \big[*%M/1]_(p | P p.1 && Q p.1 p.2) F p.1 p.2. Proof. exact/pair_big_dep_idem/mul1m. Qed. Lemma pair_big (I J : finType) (P : pred I) (Q : pred J) F : \big[*%M/1]_(i | P i) \big[*%M/1]_(j | Q j) F i j = \big[*%M/1]_(p | P p.1 && Q p.2) F p.1 p.2. Proof. exact/pair_big_idem/mul1m. Qed. Lemma pair_bigA (I J : finType) (F : I -> J -> R) : \big[*%M/1]_i \big[*%M/1]_j F i j = \big[*%M/1]_p F p.1 p.2. Proof. exact/pair_bigA_idem/mul1m. Qed. Lemma exchange_big_dep I J rI rJ (P : pred I) (Q : I -> pred J) (xQ : pred J) F : (forall i j, P i -> Q i j -> xQ j) -> \big[*%M/1]_(i <- rI | P i) \big[*%M/1]_(j <- rJ | Q i j) F i j = \big[*%M/1]_(j <- rJ | xQ j) \big[*%M/1]_(i <- rI | P i && Q i j) F i j. Proof. exact/exchange_big_dep_idem/mul1m. Qed. Arguments exchange_big_dep [I J rI rJ P Q] xQ [F]. Lemma exchange_big I J rI rJ (P : pred I) (Q : pred J) F : \big[*%M/1]_(i <- rI | P i) \big[*%M/1]_(j <- rJ | Q j) F i j = \big[*%M/1]_(j <- rJ | Q j) \big[*%M/1]_(i <- rI | P i) F i j. Proof. exact/exchange_big_idem/mul1m. Qed. Lemma exchange_big_dep_nat m1 n1 m2 n2 (P : pred nat) (Q : rel nat) (xQ : pred nat) F : (forall i j, m1 <= i < n1 -> m2 <= j < n2 -> P i -> Q i j -> xQ j) -> \big[*%M/1]_(m1 <= i < n1 | P i) \big[*%M/1]_(m2 <= j < n2 | Q i j) F i j = \big[*%M/1]_(m2 <= j < n2 | xQ j) \big[*%M/1]_(m1 <= i < n1 | P i && Q i j) F i j. Proof. exact/exchange_big_dep_nat_idem/mul1m. Qed. Arguments exchange_big_dep_nat [m1 n1 m2 n2 P Q] xQ [F]. Lemma exchange_big_nat m1 n1 m2 n2 (P Q : pred nat) F : \big[*%M/1]_(m1 <= i < n1 | P i) \big[*%M/1]_(m2 <= j < n2 | Q j) F i j = \big[*%M/1]_(m2 <= j < n2 | Q j) \big[*%M/1]_(m1 <= i < n1 | P i) F i j. Proof. exact/exchange_big_nat_idem/mul1m. Qed. End Abelian. End MonoidProperties. Arguments big_filter [R idx op I]. Arguments big_filter_cond [R idx op I]. Arguments congr_big [R idx op I r1] r2 [P1] P2 [F1] F2. Arguments eq_big [R idx op I r P1] P2 [F1] F2. Arguments eq_bigl [R idx op I r P1] P2. Arguments eq_bigr [R idx op I r P F1] F2. Arguments eq_big_idx [R idx op idx' I] i0 [P F]. Arguments big_seq_cond [R idx op I r]. Arguments eq_big_seq [R idx op I r F1] F2. Arguments congr_big_nat [R idx op m1 n1] m2 n2 [P1] P2 [F1] F2. Arguments big_map [R idx op I J] h [r]. Arguments big_nth [R idx op I] x0 [r]. Arguments big_catl [R idx op I r1 r2 P F]. Arguments big_catr [R idx op I r1 r2 P F]. Arguments big_geq [R idx op m n P F]. Arguments big_ltn_cond [R idx op m n P F]. Arguments big_ltn [R idx op m n F]. Arguments big_addn [R idx op]. Arguments big_mkord [R idx op n]. Arguments big_nat_widen [R idx op]. Arguments big_nat_widenl [R idx op]. Arguments big_geq_mkord [R idx op]. Arguments big_ord_widen_cond [R idx op n1]. Arguments big_ord_widen [R idx op n1]. Arguments big_ord_widen_leq [R idx op n1]. Arguments big_ord_narrow_cond [R idx op n1 n2 P F]. Arguments big_ord_narrow_cond_leq [R idx op n1 n2 P F]. Arguments big_ord_narrow [R idx op n1 n2 F]. Arguments big_ord_narrow_leq [R idx op n1 n2 F]. Arguments big_mkcond [R idx op I r]. Arguments big1_eq [R idx op I]. Arguments big1_seq [R idx op I]. Arguments big1 [R idx op I]. Arguments big_only1 {R idx op I} i [P F]. Arguments big_pred1 [R idx op I] i [P F]. Arguments perm_big [R op x I r1] r2 [P F]. Arguments big_uniq [R op x I] r [F]. Arguments big_rem [R idx op I r] x [P F]. Arguments bigID [R idx op I r]. Arguments bigU [R idx op I]. Arguments bigD1 [R op x I] j [P F]. Arguments bigD1_seq [R op x I r] j [F]. Arguments bigD1_ord [R op x n] j [P F]. Arguments partition_big [R idx op I s J P] p Q [F]. Arguments reindex_omap [R op x I J] h h' [P F]. Arguments reindex_onto [R op x I J] h h' [P F]. Arguments reindex [R op x I J] h [P F]. Arguments reindex_inj [R op x I h P F]. Arguments big_enum_val_cond [R op x I A] P F. Arguments big_enum_rank_cond [R op x I A z] zA P F. Arguments big_enum_val [R idx op I A] F. Arguments big_enum_rank [R idx op I A x] xA F. Arguments big_sub_cond [R idx op I]. Arguments big_sub [R idx op I]. Arguments sig_big_dep [R idx op I J]. Arguments pair_big_dep [R idx op I J]. Arguments pair_big [R idx op I J]. Arguments big_allpairs_dep {R idx op I1 I2 J h r1 r2 F}. Arguments big_allpairs {R idx op I1 I2 r1 r2 F}. Arguments exchange_big_dep [R idx op I J rI rJ P Q] xQ [F]. Arguments exchange_big_dep_nat [R idx op m1 n1 m2 n2 P Q] xQ [F]. Arguments big_ord_recl [R idx op]. Arguments big_ord_recr [R idx op]. Arguments big_nat_recl [R idx op]. Arguments big_nat_recr [R idx op]. Arguments big_cat_nat_idem [R op x] opxx [n m p P F]. Arguments big_cat_nat [R idx op n m p P F]. Arguments big_pmap [R idx op J I] h [r]. Arguments telescope_big [R idx op] f [n m]. Section IncreasingSemiGroup. Variables (R : Type) (op : SemiGroup.com_law R). Variable le : rel R. Hypothesis le_refl : reflexive le. Hypothesis op_incr : forall x y, le x (op x y). Context [x : R]. Local Notation opA := SemiGroup.opA. Local Notation opC := SemiGroup.opC. Lemma sub_le_big I [s] (P P' : {pred I}) (F : I -> R) : (forall i, P i -> P' i) -> le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s | P' i) F i). Proof. move=> PP'; rewrite [X in le _ X](big_AC_mk_monoid opA opC) (bigID P P') /=. under [in X in le _ X]eq_bigl do rewrite (andb_idl (PP' _)). rewrite [X in le X _](big_AC_mk_monoid opA opC). case: (bigop _ _ _) (bigop _ _ _) => [y|] [z|]//=. by rewrite -opA [_ y x]opC opA op_incr. by rewrite opC op_incr. Qed. Lemma sub_le_big_seq (I : eqType) s s' P (F : I -> R) : (forall i, count_mem i s <= count_mem i s')%N -> le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i). Proof. rewrite (big_AC_mk_monoid opA opC) => /count_subseqP[_ /subseqP[m sm ->]]. move/(perm_big _)->; rewrite big_mask [X in le _ X]big_tnth. by rewrite -!(big_AC_mk_monoid opA opC) sub_le_big // => j /andP[]. Qed. Lemma sub_le_big_seq_cond (I : eqType) s s' P P' (F : I -> R) : (forall i, count_mem i (filter P s) <= count_mem i (filter P' s'))%N -> le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i). Proof. by move=> /(sub_le_big_seq xpredT F); rewrite !big_filter. Qed. Lemma uniq_sub_le_big (I : eqType) s s' P (F : I -> R) : uniq s -> uniq s' -> {subset s <= s'} -> le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i). Proof. move=> us us' ss'; rewrite sub_le_big_seq => // i; rewrite !count_uniq_mem//. by have /implyP := ss' i; case: (_ \in s) (_ \in s') => [] []. Qed. Lemma uniq_sub_le_big_cond (I : eqType) s s' P P' (F : I -> R) : uniq (filter P s) -> uniq (filter P' s') -> {subset [seq i <- s | P i] <= [seq i <- s' | P' i]} -> le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i). Proof. by move=> u v /(uniq_sub_le_big xpredT F u v); rewrite !big_filter. Qed. Section Id. Hypothesis opK : idempotent_op op. Lemma idem_sub_le_big (I : eqType) s s' P (F : I -> R) : {subset s <= s'} -> le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i). Proof. move=> ss'; rewrite -big_undup// -[X in le _ X]big_undup//. by rewrite uniq_sub_le_big ?undup_uniq// => i; rewrite !mem_undup; apply: ss'. Qed. Lemma idem_sub_le_big_cond (I : eqType) s s' P P' (F : I -> R) : {subset [seq i <- s | P i] <= [seq i <- s' | P' i]} -> le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i). Proof. by move=> /(idem_sub_le_big xpredT F); rewrite !big_filter. Qed. End Id. Lemma sub_in_le_big [I : eqType] (s : seq I) (P P' : {pred I}) (F : I -> R) : {in s, forall i, P i -> P' i} -> le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s | P' i) F i). Proof. move=> PP'; apply: sub_le_big_seq_cond => i; rewrite leq_count_subseq//. rewrite subseq_filter filter_subseq andbT; apply/allP => j. by rewrite !mem_filter => /andP[/PP'/[apply]->]. Qed. Lemma le_big_ord n m [P : {pred nat}] [F : nat -> R] : (n <= m)%N -> le (\big[op/x]_(i < n | P i) F i) (\big[op/x]_(i < m | P i) F i). Proof. by move=> nm; rewrite (big_ord_widen_cond m)// sub_le_big => //= ? /andP[]. Qed. Lemma subset_le_big [I : finType] [A A' P : {pred I}] (F : I -> R) : A \subset A' -> le (\big[op/x]_(i in A | P i) F i) (\big[op/x]_(i in A' | P i) F i). Proof. move=> AA'; apply: sub_le_big => y /andP[yA yP]; apply/andP; split => //. exact: subsetP yA. Qed. Lemma le_big_nat_cond n m n' m' (P P' : {pred nat}) (F : nat -> R) : (n' <= n)%N -> (m <= m')%N -> (forall i, (n <= i < m)%N -> P i -> P' i) -> le (\big[op/x]_(n <= i < m | P i) F i) (\big[op/x]_(n' <= i < m' | P' i) F i). Proof. move=> len'n lemm' PP'i; rewrite uniq_sub_le_big_cond ?filter_uniq ?iota_uniq//. move=> i; rewrite !mem_filter !mem_index_iota => /and3P[Pi ni im]. by rewrite PP'i ?ni//= (leq_trans _ ni)// (leq_trans im). Qed. Lemma le_big_nat n m n' m' [P] [F : nat -> R] : (n' <= n)%N -> (m <= m')%N -> le (\big[op/x]_(n <= i < m | P i) F i) (\big[op/x]_(n' <= i < m' | P i) F i). Proof. by move=> len'n lemm'; rewrite le_big_nat_cond. Qed. Lemma le_big_ord_cond n m (P P' : {pred nat}) (F : nat -> R) : (n <= m)%N -> (forall i : 'I_n, P i -> P' i) -> le (\big[op/x]_(i < n | P i) F i) (\big[op/x]_(i < m | P' i) F i). Proof. move=> nm PP'; rewrite -!big_mkord le_big_nat_cond//= => i ni. by have := PP' (Ordinal ni). Qed. End IncreasingSemiGroup. Section EqSupport. Variables (R : eqType) (idx : R). Section MonoidSupport. Variables (op : Monoid.law idx) (I : Type). Lemma eq_bigl_supp (r : seq I) (P1 : pred I) (P2 : pred I) (F : I -> R) : {in [pred x | F x != idx], P1 =1 P2} -> \big[op/idx]_(i <- r | P1 i) F i = \big[op/idx]_(i <- r | P2 i) F i. Proof. move=> P12; rewrite big_mkcond [RHS]big_mkcond; apply: eq_bigr => i _. by case: (eqVneq (F i) idx) => [->|/P12->]; rewrite ?if_same. Qed. End MonoidSupport. Section ComoidSupport. Variables (op : Monoid.com_law idx) (I : eqType). Lemma perm_big_supp_cond [r s : seq I] [P : pred I] (F : I -> R) : perm_eq [seq i <- r | P i && (F i != idx)] [seq i <- s | P i && (F i != idx)] -> \big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(i <- s | P i) F i. Proof. move=> prs; rewrite !(bigID [pred i | F i == idx] P F)/=. rewrite big1 ?Monoid.mul1m; last by move=> i /andP[_ /eqP->]. rewrite [in RHS]big1 ?Monoid.mul1m; last by move=> i /andP[_ /eqP->]. by rewrite -[in LHS]big_filter -[in RHS]big_filter; apply perm_big. Qed. Lemma perm_big_supp [r s : seq I] [P : pred I] (F : I -> R) : perm_eq [seq i <- r | F i != idx] [seq i <- s | F i != idx] -> \big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(i <- s | P i) F i. Proof. by move=> ?; apply: perm_big_supp_cond; rewrite !filter_predI perm_filter. Qed. End ComoidSupport. End EqSupport. Arguments eq_bigl_supp [R idx op I r P1]. Arguments perm_big_supp_cond [R idx op I r s P]. Arguments perm_big_supp [R idx op I r s P]. Section Distributivity. Import Monoid.Theory. Variable R : Type. Variables zero one : R. Local Notation "0" := zero. Local Notation "1" := one. Variable times : Monoid.mul_law 0. Local Notation "*%M" := times. Local Notation "x * y" := (times x y). Variable plus : Monoid.add_law 0 *%M. Local Notation "+%M" := plus. Local Notation "x + y" := (plus x y). Lemma big_distrl I r a (P : pred I) F : \big[+%M/0]_(i <- r | P i) F i * a = \big[+%M/0]_(i <- r | P i) (F i * a). Proof. by rewrite (big_endo ( *%M^~ a)) ?mul0m // => x y; apply: mulmDl. Qed. Lemma big_distrr I r a (P : pred I) F : a * \big[+%M/0]_(i <- r | P i) F i = \big[+%M/0]_(i <- r | P i) (a * F i). Proof. by rewrite big_endo ?mulm0 // => x y; apply: mulmDr. Qed. Lemma big_distrlr I J rI rJ (pI : pred I) (pJ : pred J) F G : (\big[+%M/0]_(i <- rI | pI i) F i) * (\big[+%M/0]_(j <- rJ | pJ j) G j) = \big[+%M/0]_(i <- rI | pI i) \big[+%M/0]_(j <- rJ | pJ j) (F i * G j). Proof. by rewrite big_distrl; under eq_bigr do rewrite big_distrr. Qed. Lemma big_distr_big_dep (I J : finType) j0 (P : pred I) (Q : I -> pred J) F : \big[*%M/1]_(i | P i) \big[+%M/0]_(j | Q i j) F i j = \big[+%M/0]_(f in pfamily j0 P Q) \big[*%M/1]_(i | P i) F i (f i). Proof. pose fIJ := {ffun I -> J}; pose Pf := pfamily j0 (_ : seq I) Q. have [r big_r [Ur mem_r] _] := big_enumP P. symmetry; transitivity (\big[+%M/0]_(f in Pf r) \big[*%M/1]_(i <- r) F i (f i)). by apply: eq_big => // f; apply: eq_forallb => i; rewrite /= mem_r. rewrite -{P mem_r}big_r; elim: r Ur => /= [_ | i r IHr]. rewrite (big_pred1 [ffun=> j0]) ?big_nil //= => f. apply/familyP/eqP=> /= [Df |->{f} i]; last by rewrite ffunE !inE. by apply/ffunP=> i; rewrite ffunE; apply/eqP/Df. case/andP=> /negbTE nri; rewrite big_cons big_distrl => {}/IHr<-. rewrite (partition_big (fun f : fIJ => f i) (Q i)) => [|f]; last first. by move/familyP/(_ i); rewrite /= inE /= eqxx. pose seti j (f : fIJ) := [ffun k => if k == i then j else f k]. apply: eq_bigr => j Qij. rewrite (reindex_onto (seti j) (seti j0)) => [|f /andP[_ /eqP fi]]; last first. by apply/ffunP=> k; rewrite !ffunE; case: eqP => // ->. rewrite big_distrr; apply: eq_big => [f | f eq_f]; last first. rewrite big_cons ffunE eqxx !big_seq; congr (_ * _). by apply: eq_bigr => k; rewrite ffunE; case: eqP nri => // -> ->. rewrite !ffunE !eqxx andbT; apply/andP/familyP=> /= [[Pjf fij0] k | Pff]. have /[!(ffunE, inE)] := familyP Pjf k; case: eqP => // -> _. by rewrite nri -(eqP fij0) !ffunE !inE !eqxx. (split; [apply/familyP | apply/eqP/ffunP]) => k; have /[!(ffunE, inE)]:= Pff k. by case: eqP => // ->. by case: eqP => // ->; rewrite nri /= => /eqP. Qed. Lemma big_distr_big (I J : finType) j0 (P : pred I) (Q : pred J) F : \big[*%M/1]_(i | P i) \big[+%M/0]_(j | Q j) F i j = \big[+%M/0]_(f in pffun_on j0 P Q) \big[*%M/1]_(i | P i) F i (f i). Proof. rewrite (big_distr_big_dep j0); apply: eq_bigl => f. by apply/familyP/familyP=> Pf i; case: ifP (Pf i). Qed. Lemma bigA_distr_big_dep (I J : finType) (Q : I -> pred J) F : \big[*%M/1]_i \big[+%M/0]_(j | Q i j) F i j = \big[+%M/0]_(f in family Q) \big[*%M/1]_i F i (f i). Proof. have [j _ | J0] := pickP J; first by rewrite (big_distr_big_dep j). have Q0 i: Q i =i pred0 by move=> /J0/esym/notF[]. transitivity (iter #|I| ( *%M 0) 1). by rewrite -big_const; apply/eq_bigr=> i; have /(big_pred0 _)-> := Q0 i. have [i _ | I0] := pickP I. rewrite (cardD1 i) //= mul0m big_pred0 // => f. by apply/familyP=> /(_ i); rewrite Q0. have f: I -> J by move=> /I0/esym/notF[]. rewrite eq_card0 // (big_pred1 (finfun f)) ?big_pred0 // => g. by apply/familyP/eqP=> _; first apply/ffunP; move=> /I0/esym/notF[]. Qed. Lemma bigA_distr_big (I J : finType) (Q : pred J) (F : I -> J -> R) : \big[*%M/1]_i \big[+%M/0]_(j | Q j) F i j = \big[+%M/0]_(f in ffun_on Q) \big[*%M/1]_i F i (f i). Proof. exact: bigA_distr_big_dep. Qed. Lemma bigA_distr_bigA (I J : finType) F : \big[*%M/1]_(i : I) \big[+%M/0]_(j : J) F i j = \big[+%M/0]_(f : {ffun I -> J}) \big[*%M/1]_i F i (f i). Proof. by rewrite bigA_distr_big; apply: eq_bigl => ?; apply/familyP. Qed. End Distributivity. Arguments big_distrl [R zero times plus I r]. Arguments big_distrr [R zero times plus I r]. Arguments big_distr_big_dep [R zero one times plus I J]. Arguments big_distr_big [R zero one times plus I J]. Arguments bigA_distr_big_dep [R zero one times plus I J]. Arguments bigA_distr_big [R zero one times plus I J]. Arguments bigA_distr_bigA [R zero one times plus I J]. Section BigBool. Section Seq. Variables (I : Type) (r : seq I) (P B : pred I). Lemma big_has : \big[orb/false]_(i <- r) B i = has B r. Proof. by rewrite unlock. Qed. Lemma big_all : \big[andb/true]_(i <- r) B i = all B r. Proof. by rewrite unlock. Qed. Lemma big_has_cond : \big[orb/false]_(i <- r | P i) B i = has (predI P B) r. Proof. by rewrite big_mkcond unlock. Qed. Lemma big_all_cond : \big[andb/true]_(i <- r | P i) B i = all [pred i | P i ==> B i] r. Proof. by rewrite big_mkcond unlock. Qed. Lemma big_bool R (idx : R) (op : Monoid.com_law idx) (F : bool -> R): \big[op/idx]_(i : bool) F i = op (F true) (F false). Proof. by rewrite /index_enum !unlock /= Monoid.mulm1. Qed. End Seq. Section FinType. Variables (I : finType) (P B : pred I). Lemma big_orE : \big[orb/false]_(i | P i) B i = [exists (i | P i), B i]. Proof. by rewrite big_has_cond; apply/hasP/existsP=> [] [i]; exists i. Qed. Lemma big_andE : \big[andb/true]_(i | P i) B i = [forall (i | P i), B i]. Proof. rewrite big_all_cond; apply/allP/forallP=> /= allB i; rewrite allB //. exact: mem_index_enum. Qed. End FinType. End BigBool. Section NatConst. Variables (I : finType) (A : pred I). Lemma sum_nat_const n : \sum_(i in A) n = #|A| * n. Proof. by rewrite big_const iter_addn_0 mulnC. Qed. Lemma sum1_card : \sum_(i in A) 1 = #|A|. Proof. by rewrite sum_nat_const muln1. Qed. Lemma sum1_count J (r : seq J) (a : pred J) : \sum_(j <- r | a j) 1 = count a r. Proof. by rewrite big_const_seq iter_addn_0 mul1n. Qed. Lemma sum1_size J (r : seq J) : \sum_(j <- r) 1 = size r. Proof. by rewrite sum1_count count_predT. Qed. Lemma prod_nat_const n : \prod_(i in A) n = n ^ #|A|. Proof. by rewrite big_const -Monoid.iteropE. Qed. Lemma sum_nat_const_nat n1 n2 n : \sum_(n1 <= i < n2) n = (n2 - n1) * n. Proof. by rewrite big_const_nat iter_addn_0 mulnC. Qed. Lemma prod_nat_const_nat n1 n2 n : \prod_(n1 <= i < n2) n = n ^ (n2 - n1). Proof. by rewrite big_const_nat -Monoid.iteropE. Qed. End NatConst. Lemma telescope_sumn_in n m f : n <= m -> (forall i, n <= i < m -> f i <= f i.+1) -> \sum_(n <= k < m) (f k.+1 - f k) = f m - f n. Proof. move=> nm fle; rewrite (telescope_big (fun i j => f j - f i)). by case: ltngtP nm => // ->; rewrite subnn. move=> k /andP[nk km]; rewrite /= addnBAC ?subnKC ?fle ?(ltnW nk)//. elim: k nk km => [//| k IHk /[!ltnS]/[1!leq_eqVlt]+ km]. move=> /predU1P[/[dup]nk -> | nk]; first by rewrite fle ?nk ?leqnn 1?ltnW. by rewrite (leq_trans (IHk _ _) (fle _ _))// ltnW// ltnW. Qed. Lemma telescope_sumn n m f : {homo f : x y / x <= y} -> \sum_(n <= k < m) (f k.+1 - f k) = f m - f n. Proof. move=> fle; case: (ltnP n m) => nm. by apply: (telescope_sumn_in (ltnW nm)) => ? ?; apply: fle. by apply/esym/eqP; rewrite big_geq// subn_eq0 fle. Qed. Lemma sumnE r : sumn r = \sum_(i <- r) i. Proof. exact: foldrE. Qed. Lemma card_bseq n (T : finType) : #|{bseq n of T}| = \sum_(i < n.+1) #|T| ^ i. Proof. rewrite (bij_eq_card bseq_tagged_tuple_bij) card_tagged sumnE big_map big_enum. by under eq_bigr do rewrite card_tuple. Qed. Lemma leqif_sum (I : finType) (P C : pred I) (E1 E2 : I -> nat) : (forall i, P i -> E1 i <= E2 i ?= iff C i) -> \sum_(i | P i) E1 i <= \sum_(i | P i) E2 i ?= iff [forall (i | P i), C i]. Proof. move=> leE12; rewrite -big_andE. by elim/big_rec3: _ => // i Ci m1 m2 /leE12; apply: leqif_add. Qed. Lemma leq_sum I r (P : pred I) (E1 E2 : I -> nat) : (forall i, P i -> E1 i <= E2 i) -> \sum_(i <- r | P i) E1 i <= \sum_(i <- r | P i) E2 i. Proof. by move=> leE12; elim/big_ind2: _ => // m1 m2 n1 n2; apply: leq_add. Qed. Lemma sumnB I r (P : pred I) (E1 E2 : I -> nat) : (forall i, P i -> E1 i <= E2 i) -> \sum_(i <- r | P i) (E2 i - E1 i) = \sum_(i <- r | P i) E2 i - \sum_(i <- r | P i) E1 i. Proof. by move=> /(_ _ _)/subnK-/(eq_bigr _)<-; rewrite big_split addnK. Qed. Lemma sum_nat_eq0 (I : finType) (P : pred I) (E : I -> nat) : (\sum_(i | P i) E i == 0)%N = [forall (i | P i), E i == 0%N]. Proof. by rewrite eq_sym -(@leqif_sum I P _ (fun _ => 0%N) E) ?big1_eq. Qed. Lemma sum_nat_seq_eq0 I r (P : pred I) F : (\sum_(i <- r | P i) F i == 0)%N = all (fun i => P i ==> (F i == 0%N)) r. Proof. by rewrite (big_morph _ (id1:=true) addn_eq0)// big_all_cond. Qed. Lemma sum_nat_seq_neq0 I r (P : pred I) F : (\sum_(i <- r | P i) F i != 0)%N = has (fun i => P i && (F i != 0)%N) r. Proof. by rewrite sum_nat_seq_eq0// -has_predC; apply: eq_has => x /=; case Px: (P x). Qed. Lemma sum_nat_eq1 (I : finType) (P : pred I) (F : I -> nat) : reflect (exists i : I, [/\ P i, F i = 1 & forall j, j != i -> P j -> F j = 0]%N) (\sum_(i | P i) F i == 1)%N. Proof. apply/(iffP idP) => [sumF_eq1 | [i [Pi Fi1 zFj]]]; last first. rewrite (bigD1 i)//= Fi1 addn_eq1//= orbF sum_nat_eq0. by apply/forall_inP => j /andP[Pj ji]; apply/eqP/zFj. have /forall_inPn [i Pi FiN0]: ~~ [forall i in P, F i == 0]. by apply: contraTN sumF_eq1 => /'forall_in_eqP F0; rewrite big1. move: sumF_eq1; rewrite (bigD1 i)//= addn_eq1 (negPf FiN0)/= orbF. move=> /andP[/eqP Fi1]; rewrite sum_nat_eq0 => /'forall_in_eqP FNi0. by exists i; split; rewrite // => j /[swap] Nij /(conj Nij)/andP/FNi0. Qed. Lemma sum_nat_seq_eq1 (I : eqType) r (P : pred I) (F : I -> nat) : (\sum_(i <- r | P i) F i = 1)%N -> exists i, [/\ i \in r, P i, F i = 1 & forall j, j != i -> j \in r -> P j -> F j = 0]%N. Proof. rewrite big_tnth/= => /eqP/sum_nat_eq1[/= i [Pi Fi FNi]]. exists (tnth (in_tuple r) i); split; rewrite //= ?mem_tnth// => j. move=> /[swap] /(tnthP (in_tuple r))[{} j -> Nij /FNi->//]. by apply: contra_neq Nij => ->. Qed. Lemma prod_nat_seq_eq0 I r (P : pred I) F : (\prod_(i <- r | P i) F i == 0)%N = has (fun i => P i && (F i == 0%N)) r. Proof. by rewrite (big_morph _ (id1 := false) muln_eq0)// big_has_cond. Qed. Lemma prod_nat_seq_neq0 I r (P : pred I) F : (\prod_(i <- r | P i) F i != 0)%N = all (fun i => P i ==> (F i != 0%N)) r. Proof. by rewrite prod_nat_seq_eq0 -all_predC; apply: eq_all => i /=; case: (P i). Qed. Lemma prod_nat_seq_eq1 I r (P : pred I) F : (\prod_(i <- r | P i) F i == 1)%N = all (fun i => P i ==> (F i == 1%N)) r. Proof. by rewrite (big_morph _ (id1:=true) muln_eq1)// big_all_cond. Qed. Lemma prod_nat_seq_neq1 I r (P : pred I) F : (\prod_(i <- r | P i) F i != 1)%N = has (fun i => P i && (F i != 1%N)) r. Proof. by rewrite prod_nat_seq_eq1 -has_predC; apply: eq_has => i /=; case: (P i). Qed. Lemma leq_prod I r (P : pred I) (E1 E2 : I -> nat) : (forall i, P i -> E1 i <= E2 i) -> \prod_(i <- r | P i) E1 i <= \prod_(i <- r | P i) E2 i. Proof. by move=> leE12; elim/big_ind2: _ => // m1 m2 n1 n2; apply: leq_mul. Qed. Arguments leq_prod [I r P E1 E2]. Lemma prodn_cond_gt0 I r (P : pred I) F : (forall i, P i -> 0 < F i) -> 0 < \prod_(i <- r | P i) F i. Proof. by move=> Fpos; elim/big_ind: _ => // n1 n2; rewrite muln_gt0 => ->. Qed. Arguments prodn_cond_gt0 [I r P F]. Lemma prodn_gt0 I r (P : pred I) F : (forall i, 0 < F i) -> 0 < \prod_(i <- r | P i) F i. Proof. by move=> Fpos; apply: prodn_cond_gt0. Qed. Arguments prodn_gt0 [I r P F]. Lemma gt0_prodn_seq (I : eqType) r (P : pred I) F : 0 < \prod_(i <- r | P i) F i -> forall i, i \in r -> P i -> 0 < F i. Proof. move=> + i ri Pi; rewrite !lt0n; apply: contra_neq => Fi_eq0. by case: (path.splitP ri) => *; rewrite big_cat big_rcons Pi Fi_eq0/= muln0. Qed. Arguments gt0_prodn_seq [I r P F]. Lemma gt0_prodn (I : finType) (P : pred I) F : 0 < \prod_(i | P i) F i -> forall i, P i -> 0 < F i. Proof. by move=> /gt0_prodn_seq + i => /[apply]; apply. Qed. Arguments gt0_prodn [I P F]. Lemma leq_bigmax_seq (I : eqType) r (P : pred I) F i0 : i0 \in r -> P i0 -> F i0 <= \max_(i <- r | P i) F i. Proof. move=> + Pi0; elim: r => // h t ih; rewrite inE big_cons. move=> /predU1P[<-|i0t]; first by rewrite Pi0 leq_maxl. by case: ifPn => Ph; [rewrite leq_max ih// orbT|rewrite ih]. Qed. Arguments leq_bigmax_seq [I r P F]. Lemma leq_bigmax_cond (I : finType) (P : pred I) F i0 : P i0 -> F i0 <= \max_(i | P i) F i. Proof. exact: leq_bigmax_seq. Qed. Arguments leq_bigmax_cond [I P F]. Lemma leq_bigmax (I : finType) F (i0 : I) : F i0 <= \max_i F i. Proof. exact: leq_bigmax_cond. Qed. Arguments leq_bigmax [I F]. Lemma bigmax_leqP (I : finType) (P : pred I) m F : reflect (forall i, P i -> F i <= m) (\max_(i | P i) F i <= m). Proof. apply: (iffP idP) => leFm => [i Pi|]. by apply: leq_trans leFm; apply: leq_bigmax_cond. by elim/big_ind: _ => // m1 m2; rewrite geq_max => ->. Qed. Lemma bigmax_leqP_seq (I : eqType) r (P : pred I) m F : reflect (forall i, i \in r -> P i -> F i <= m) (\max_(i <- r | P i) F i <= m). Proof. apply: (iffP idP) => leFm => [i ri Pi|]. exact/(leq_trans _ leFm)/leq_bigmax_seq. rewrite big_seq_cond; elim/big_ind: _ => // [m1 m2|i /andP[ri]]. by rewrite geq_max => ->. exact: leFm. Qed. Lemma bigmax_sup (I : finType) i0 (P : pred I) m F : P i0 -> m <= F i0 -> m <= \max_(i | P i) F i. Proof. by move=> Pi0 le_m_Fi0; apply: leq_trans (leq_bigmax_cond i0 Pi0). Qed. Arguments bigmax_sup [I] i0 [P m F]. Lemma bigmax_sup_seq (I : eqType) r i0 (P : pred I) m F : i0 \in r -> P i0 -> m <= F i0 -> m <= \max_(i <- r | P i) F i. Proof. by move=> i0r Pi0 ?; apply: leq_trans (leq_bigmax_seq i0 _ _). Qed. Arguments bigmax_sup_seq [I r] i0 [P m F]. Lemma bigmax_eq_arg (I : finType) i0 (P : pred I) F : P i0 -> \max_(i | P i) F i = F [arg max_(i > i0 | P i) F i]. Proof. move=> Pi0; case: arg_maxnP => //= i Pi maxFi. by apply/eqP; rewrite eqn_leq leq_bigmax_cond // andbT; apply/bigmax_leqP. Qed. Arguments bigmax_eq_arg [I] i0 [P F]. Lemma eq_bigmax_cond (I : finType) (A : pred I) F : #|A| > 0 -> {i0 | i0 \in A & \max_(i in A) F i = F i0}. Proof. case: (pickP A) => [i0 Ai0 _ | ]; last by move/eq_card0->. by exists [arg max_(i > i0 in A) F i]; [case: arg_maxnP | apply: bigmax_eq_arg]. Qed. Lemma eq_bigmax (I : finType) F : #|I| > 0 -> {i0 : I | \max_i F i = F i0}. Proof. by case/(eq_bigmax_cond F) => x _ ->; exists x. Qed. Lemma expn_sum m I r (P : pred I) F : (m ^ (\sum_(i <- r | P i) F i) = \prod_(i <- r | P i) m ^ F i)%N. Proof. exact: (big_morph _ (expnD m)). Qed. Lemma dvdn_biglcmP (I : finType) (P : pred I) F m : reflect (forall i, P i -> F i %| m) (\big[lcmn/1%N]_(i | P i) F i %| m). Proof. apply: (iffP idP) => [dvFm i Pi | dvFm]. by rewrite (bigD1 i) // dvdn_lcm in dvFm; case/andP: dvFm. by elim/big_ind: _ => // p q p_m; rewrite dvdn_lcm p_m. Qed. Lemma biglcmn_sup (I : finType) i0 (P : pred I) F m : P i0 -> m %| F i0 -> m %| \big[lcmn/1%N]_(i | P i) F i. Proof. by move=> Pi0 m_Fi0; rewrite (dvdn_trans m_Fi0) // (bigD1 i0) ?dvdn_lcml. Qed. Arguments biglcmn_sup [I] i0 [P F m]. Lemma dvdn_biggcdP (I : finType) (P : pred I) F m : reflect (forall i, P i -> m %| F i) (m %| \big[gcdn/0]_(i | P i) F i). Proof. apply: (iffP idP) => [dvmF i Pi | dvmF]. by rewrite (bigD1 i) // dvdn_gcd in dvmF; case/andP: dvmF. by elim/big_ind: _ => // p q m_p; rewrite dvdn_gcd m_p. Qed. Lemma biggcdn_inf (I : finType) i0 (P : pred I) F m : P i0 -> F i0 %| m -> \big[gcdn/0]_(i | P i) F i %| m. Proof. by move=> Pi0; apply: dvdn_trans; rewrite (bigD1 i0) ?dvdn_gcdl. Qed. Arguments biggcdn_inf [I] i0 [P F m].
Yoneda.lean
/- Copyright (c) 2025 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.Algebra.Category.Grp.Abelian import Mathlib.CategoryTheory.Abelian.DiagramLemmas.Four import Mathlib.CategoryTheory.Abelian.Projective.Basic import Mathlib.CategoryTheory.Generator.Preadditive import Mathlib.CategoryTheory.Limits.Preserves.Opposites /-! # Fullness of restrictions of `preadditiveCoyonedaObj` In this file we give a sufficient criterion for a restriction of the functor `preadditiveCoyonedaObj G` to be full: this is the case if `C` is an abelian category and `G : C` is a projective separator such that every object in the relevant subcategory is a quotient of `G`. -/ open CategoryTheory Opposite Limits universe v v' u u' variable {C : Type u} [Category.{v} C] [Abelian C] namespace CategoryTheory.Abelian section attribute [local instance] preservesFiniteLimits_op theorem preadditiveCoyonedaObj_map_surjective {G : C} [Projective G] (hG : IsSeparator G) {X : C} (p : G ⟶ X) [Epi p] {Y : C} : Function.Surjective ((preadditiveCoyonedaObj G).map : (X ⟶ Y) → _) := by rw [← Functor.coe_mapAddHom, ← AddCommGrp.hom_ofHom (preadditiveCoyonedaObj G).mapAddHom, ← AddCommGrp.epi_iff_surjective] let cm : ShortComplex C := ⟨kernel.ι p, p, by simp⟩ have exact : cm.Exact := ShortComplex.exact_of_f_is_kernel _ (kernelIsKernel _) have mono : Mono cm.op.f := by dsimp [cm]; infer_instance let φ := preadditiveCoyonedaObj G have faithful : φ.Faithful := by rwa [← isSeparator_iff_faithful_preadditiveCoyonedaObj] apply ShortComplex.epi_of_mono_of_epi_of_mono (cm.op.mapNatTrans (preadditiveYonedaMap _ _)) · exact exact.op.map_of_mono_of_preservesKernel _ mono inferInstance · simp only [ShortComplex.map_f] infer_instance · suffices φ.map.Surjective by simpa [AddCommGrp.epi_iff_surjective, Functor.coe_mapAddHom] exact fun f => ⟨f (𝟙 G), by cat_disch⟩ · simp [AddCommGrp.mono_iff_injective, Functor.coe_mapAddHom, Functor.map_injective] end variable {D : Type u'} [Category.{v'} D] (F : D ⥤ C) theorem full_comp_preadditiveCoyonedaObj [F.Full] {G : C} [Projective G] (hG : IsSeparator G) (hG₂ : ∀ X, ∃ (p : G ⟶ F.obj X), Epi p) : (F ⋙ preadditiveCoyonedaObj G).Full where map_surjective {X Y} f := by obtain ⟨p, _⟩ := hG₂ X obtain ⟨f, rfl⟩ := preadditiveCoyonedaObj_map_surjective hG p f obtain ⟨f, rfl⟩ := F.map_surjective f exact ⟨f, rfl⟩ end CategoryTheory.Abelian
ToSquareZero.lean
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Derivation.Basic import Mathlib.RingTheory.Ideal.Quotient.Operations /-! # Results - `derivationToSquareZeroOfLift`: The `R`-derivations from `A` into a square-zero ideal `I` of `B` corresponds to the lifts `A →ₐ[R] B` of the map `A →ₐ[R] B ⧸ I`. -/ section ToSquareZero universe u v w variable {R : Type u} {A : Type v} {B : Type w} [CommSemiring R] [CommSemiring A] [CommRing B] variable [Algebra R A] [Algebra R B] (I : Ideal B) /-- If `f₁ f₂ : A →ₐ[R] B` are two lifts of the same `A →ₐ[R] B ⧸ I`, we may define a map `f₁ - f₂ : A →ₗ[R] I`. -/ def diffToIdealOfQuotientCompEq (f₁ f₂ : A →ₐ[R] B) (e : (Ideal.Quotient.mkₐ R I).comp f₁ = (Ideal.Quotient.mkₐ R I).comp f₂) : A →ₗ[R] I := LinearMap.codRestrict (I.restrictScalars _) (f₁.toLinearMap - f₂.toLinearMap) (by intro x change f₁ x - f₂ x ∈ I rw [← Ideal.Quotient.eq, ← Ideal.Quotient.mkₐ_eq_mk R, ← AlgHom.comp_apply, e] rfl) @[simp] theorem diffToIdealOfQuotientCompEq_apply (f₁ f₂ : A →ₐ[R] B) (e : (Ideal.Quotient.mkₐ R I).comp f₁ = (Ideal.Quotient.mkₐ R I).comp f₂) (x : A) : ((diffToIdealOfQuotientCompEq I f₁ f₂ e) x : B) = f₁ x - f₂ x := rfl variable [Algebra A B] /-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, each lift `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I` corresponds to an `R`-derivation from `A` to `I`. -/ def derivationToSquareZeroOfLift [IsScalarTower R A B] (hI : I ^ 2 = ⊥) (f : A →ₐ[R] B) (e : (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I)) : Derivation R A I := by refine { diffToIdealOfQuotientCompEq I f (IsScalarTower.toAlgHom R A B) ?_ with map_one_eq_zero' := ?_ leibniz' := ?_ } · rw [e]; ext; rfl · ext; simp · intro x y let F := diffToIdealOfQuotientCompEq I f (IsScalarTower.toAlgHom R A B) (by rw [e]; ext; rfl) have : (f x - algebraMap A B x) * (f y - algebraMap A B y) = 0 := by rw [← Ideal.mem_bot, ← hI, pow_two] convert Ideal.mul_mem_mul (F x).2 (F y).2 using 1 ext dsimp only [Submodule.coe_add, Submodule.coe_mk, LinearMap.coe_mk, diffToIdealOfQuotientCompEq_apply, Submodule.coe_smul_of_tower, IsScalarTower.coe_toAlgHom', LinearMap.toFun_eq_coe] simp only [map_mul, sub_mul, mul_sub, Algebra.smul_def] at this ⊢ rw [sub_eq_iff_eq_add, sub_eq_iff_eq_add] at this simp only [this] ring variable (hI : I ^ 2 = ⊥) theorem derivationToSquareZeroOfLift_apply [IsScalarTower R A B] (f : A →ₐ[R] B) (e : (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I)) (x : A) : (derivationToSquareZeroOfLift I hI f e x : B) = f x - algebraMap A B x := rfl /-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, each `R`-derivation from `A` to `I` corresponds to a lift `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I`. -/ @[simps -isSimp] def liftOfDerivationToSquareZero [IsScalarTower R A B] (hI : I ^ 2 = ⊥) (f : Derivation R A I) : A →ₐ[R] B := { ((I.restrictScalars R).subtype.comp f.toLinearMap + (IsScalarTower.toAlgHom R A B).toLinearMap : A →ₗ[R] B) with toFun := fun x => f x + algebraMap A B x map_one' := by -- Note: added the `(algebraMap _ _)` hint because otherwise it would match `f 1` rw [map_one (algebraMap _ _), f.map_one_eq_zero, Submodule.coe_zero, zero_add] map_mul' := fun x y => by have : (f x : B) * f y = 0 := by rw [← Ideal.mem_bot, ← hI, pow_two] convert Ideal.mul_mem_mul (f x).2 (f y).2 using 1 simp only [map_mul, f.leibniz, add_mul, mul_add, Submodule.coe_add, Submodule.coe_smul_of_tower, Algebra.smul_def, this] ring commutes' := fun r => by simp only [Derivation.map_algebraMap, zero_add, Submodule.coe_zero, ← IsScalarTower.algebraMap_apply R A B r] map_zero' := ((I.restrictScalars R).subtype.comp f.toLinearMap + (IsScalarTower.toAlgHom R A B).toLinearMap).map_zero } -- @[simp] -- Porting note: simp normal form is `liftOfDerivationToSquareZero_mk_apply'` theorem liftOfDerivationToSquareZero_mk_apply [IsScalarTower R A B] (d : Derivation R A I) (x : A) : Ideal.Quotient.mk I (liftOfDerivationToSquareZero I hI d x) = algebraMap A (B ⧸ I) x := by rw [liftOfDerivationToSquareZero_apply, map_add, Ideal.Quotient.eq_zero_iff_mem.mpr (d x).prop, zero_add] rfl @[simp] theorem liftOfDerivationToSquareZero_mk_apply' (d : Derivation R A I) (x : A) : (Ideal.Quotient.mk I) (d x) + (algebraMap A (B ⧸ I)) x = algebraMap A (B ⧸ I) x := by simp only [Ideal.Quotient.eq_zero_iff_mem.mpr (d x).prop, zero_add] /-- Given a tower of algebras `R → A → B`, and a square-zero `I : Ideal B`, there is a 1-1 correspondence between `R`-derivations from `A` to `I` and lifts `A →ₐ[R] B` of the canonical map `A →ₐ[R] B ⧸ I`. -/ @[simps!] def derivationToSquareZeroEquivLift [IsScalarTower R A B] : Derivation R A I ≃ { f : A →ₐ[R] B // (Ideal.Quotient.mkₐ R I).comp f = IsScalarTower.toAlgHom R A (B ⧸ I) } := by refine ⟨fun d => ⟨liftOfDerivationToSquareZero I hI d, ?_⟩, fun f => (derivationToSquareZeroOfLift I hI f.1 f.2 :), ?_, ?_⟩ · ext x; exact liftOfDerivationToSquareZero_mk_apply I hI d x · intro d; ext x; exact add_sub_cancel_right (d x : B) (algebraMap A B x) · rintro ⟨f, hf⟩; ext x; exact sub_add_cancel (f x) (algebraMap A B x) end ToSquareZero
M.lean
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro, Simon Hudon -/ import Mathlib.Data.PFunctor.Multivariate.Basic import Mathlib.Data.PFunctor.Univariate.M /-! # The M construction as a multivariate polynomial functor. M types are potentially infinite tree-like structures. They are defined as the greatest fixpoint of a polynomial functor. ## Main definitions * `M.mk` - constructor * `M.dest` - destructor * `M.corec` - corecursor: useful for formulating infinite, productive computations * `M.bisim` - bisimulation: proof technique to show the equality of infinite objects ## Implementation notes Dual view of M-types: * `mp`: polynomial functor * `M`: greatest fixed point of a polynomial functor Specifically, we define the polynomial functor `mp` as: * A := a possibly infinite tree-like structure without information in the nodes * B := given the tree-like structure `t`, `B t` is a valid path from the root of `t` to any given node. As a result `mp α` is made of a dataless tree and a function from its valid paths to values of `α` The difference with the polynomial functor of an initial algebra is that `A` is a possibly infinite tree. ## Reference * Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u open MvFunctor namespace MvPFunctor open TypeVec variable {n : ℕ} (P : MvPFunctor.{u} (n + 1)) /-- A path from the root of a tree to one of its node -/ inductive M.Path : P.last.M → Fin2 n → Type u | root (x : P.last.M) (a : P.A) (f : P.last.B a → P.last.M) (h : PFunctor.M.dest x = ⟨a, f⟩) (i : Fin2 n) (c : P.drop.B a i) : M.Path x i | child (x : P.last.M) (a : P.A) (f : P.last.B a → P.last.M) (h : PFunctor.M.dest x = ⟨a, f⟩) (j : P.last.B a) (i : Fin2 n) (c : M.Path (f j) i) : M.Path x i instance M.Path.inhabited (x : P.last.M) {i} [Inhabited (P.drop.B x.head i)] : Inhabited (M.Path P x i) := let a := PFunctor.M.head x let f := PFunctor.M.children x ⟨M.Path.root _ a f (PFunctor.M.casesOn' x (r := fun _ => PFunctor.M.dest x = ⟨a, f⟩) <| by intros; simp [a]; rfl) _ default⟩ /-- Polynomial functor of the M-type of `P`. `A` is a data-less possibly infinite tree whereas, for a given `a : A`, `B a` is a valid path in tree `a` so that `mp α` is made of a tree and a function from its valid paths to the values it contains -/ def mp : MvPFunctor n where A := P.last.M B := M.Path P /-- `n`-ary M-type for `P` -/ def M (α : TypeVec n) : Type _ := P.mp α instance mvfunctorM : MvFunctor P.M := by delta M; infer_instance instance inhabitedM {α : TypeVec _} [I : Inhabited P.A] [∀ i : Fin2 n, Inhabited (α i)] : Inhabited (P.M α) := @Obj.inhabited _ (mp P) _ (@PFunctor.M.inhabited P.last I) _ /-- construct through corecursion the shape of an M-type without its contents -/ def M.corecShape {β : Type u} (g₀ : β → P.A) (g₂ : ∀ b : β, P.last.B (g₀ b) → β) : β → P.last.M := PFunctor.M.corec fun b => ⟨g₀ b, g₂ b⟩ /-- Proof of type equality as an arrow -/ def castDropB {a a' : P.A} (h : a = a') : P.drop.B a ⟹ P.drop.B a' := fun _i b => Eq.recOn h b /-- Proof of type equality as a function -/ def castLastB {a a' : P.A} (h : a = a') : P.last.B a → P.last.B a' := fun b => Eq.recOn h b /-- Using corecursion, construct the contents of an M-type -/ def M.corecContents {α : TypeVec.{u} n} {β : Type u} (g₀ : β → P.A) (g₁ : ∀ b : β, P.drop.B (g₀ b) ⟹ α) (g₂ : ∀ b : β, P.last.B (g₀ b) → β) (x : _) (b : β) (h : x = M.corecShape P g₀ g₂ b) : M.Path P x ⟹ α | _, M.Path.root x a f h' i c => have : a = g₀ b := by rw [h, M.corecShape, PFunctor.M.dest_corec] at h' cases h' rfl g₁ b i (P.castDropB this i c) | _, M.Path.child x a f h' j i c => have h₀ : a = g₀ b := by rw [h, M.corecShape, PFunctor.M.dest_corec] at h' cases h' rfl have h₁ : f j = M.corecShape P g₀ g₂ (g₂ b (castLastB P h₀ j)) := by rw [h, M.corecShape, PFunctor.M.dest_corec] at h' cases h' rfl M.corecContents g₀ g₁ g₂ (f j) (g₂ b (P.castLastB h₀ j)) h₁ i c /-- Corecursor for M-type of `P` -/ def M.corec' {α : TypeVec n} {β : Type u} (g₀ : β → P.A) (g₁ : ∀ b : β, P.drop.B (g₀ b) ⟹ α) (g₂ : ∀ b : β, P.last.B (g₀ b) → β) : β → P.M α := fun b => ⟨M.corecShape P g₀ g₂ b, M.corecContents P g₀ g₁ g₂ _ _ rfl⟩ /-- Corecursor for M-type of `P` -/ def M.corec {α : TypeVec n} {β : Type u} (g : β → P (α.append1 β)) : β → P.M α := M.corec' P (fun b => (g b).fst) (fun b => dropFun (g b).snd) fun b => lastFun (g b).snd /-- Implementation of destructor for M-type of `P` -/ def M.pathDestLeft {α : TypeVec n} {x : P.last.M} {a : P.A} {f : P.last.B a → P.last.M} (h : PFunctor.M.dest x = ⟨a, f⟩) (f' : M.Path P x ⟹ α) : P.drop.B a ⟹ α := fun i c => f' i (M.Path.root x a f h i c) /-- Implementation of destructor for M-type of `P` -/ def M.pathDestRight {α : TypeVec n} {x : P.last.M} {a : P.A} {f : P.last.B a → P.last.M} (h : PFunctor.M.dest x = ⟨a, f⟩) (f' : M.Path P x ⟹ α) : ∀ j : P.last.B a, M.Path P (f j) ⟹ α := fun j i c => f' i (M.Path.child x a f h j i c) /-- Destructor for M-type of `P` -/ def M.dest' {α : TypeVec n} {x : P.last.M} {a : P.A} {f : P.last.B a → P.last.M} (h : PFunctor.M.dest x = ⟨a, f⟩) (f' : M.Path P x ⟹ α) : P (α.append1 (P.M α)) := ⟨a, splitFun (M.pathDestLeft P h f') fun x => ⟨f x, M.pathDestRight P h f' x⟩⟩ /-- Destructor for M-types -/ def M.dest {α : TypeVec n} (x : P.M α) : P (α ::: P.M α) := M.dest' P (Sigma.eta <| PFunctor.M.dest x.fst).symm x.snd /-- Constructor for M-types -/ def M.mk {α : TypeVec n} : P (α.append1 (P.M α)) → P.M α := M.corec _ fun i => appendFun id (M.dest P) <$$> i theorem M.dest'_eq_dest' {α : TypeVec n} {x : P.last.M} {a₁ : P.A} {f₁ : P.last.B a₁ → P.last.M} (h₁ : PFunctor.M.dest x = ⟨a₁, f₁⟩) {a₂ : P.A} {f₂ : P.last.B a₂ → P.last.M} (h₂ : PFunctor.M.dest x = ⟨a₂, f₂⟩) (f' : M.Path P x ⟹ α) : M.dest' P h₁ f' = M.dest' P h₂ f' := by cases h₁.symm.trans h₂; rfl theorem M.dest_eq_dest' {α : TypeVec n} {x : P.last.M} {a : P.A} {f : P.last.B a → P.last.M} (h : PFunctor.M.dest x = ⟨a, f⟩) (f' : M.Path P x ⟹ α) : M.dest P ⟨x, f'⟩ = M.dest' P h f' := M.dest'_eq_dest' _ _ _ _ theorem M.dest_corec' {α : TypeVec.{u} n} {β : Type u} (g₀ : β → P.A) (g₁ : ∀ b : β, P.drop.B (g₀ b) ⟹ α) (g₂ : ∀ b : β, P.last.B (g₀ b) → β) (x : β) : M.dest P (M.corec' P g₀ g₁ g₂ x) = ⟨g₀ x, splitFun (g₁ x) (M.corec' P g₀ g₁ g₂ ∘ g₂ x)⟩ := rfl theorem M.dest_corec {α : TypeVec n} {β : Type u} (g : β → P (α.append1 β)) (x : β) : M.dest P (M.corec P g x) = appendFun id (M.corec P g) <$$> g x := by trans · apply M.dest_corec' obtain ⟨a, f⟩ := g x; dsimp rw [MvPFunctor.map_eq]; congr conv_rhs => rw [← split_dropFun_lastFun f, appendFun_comp_splitFun] rfl theorem M.bisim_lemma {α : TypeVec n} {a₁ : (mp P).A} {f₁ : (mp P).B a₁ ⟹ α} {a' : P.A} {f' : (P.B a').drop ⟹ α} {f₁' : (P.B a').last → M P α} (e₁ : M.dest P ⟨a₁, f₁⟩ = ⟨a', splitFun f' f₁'⟩) : ∃ (g₁' : _)(e₁' : PFunctor.M.dest a₁ = ⟨a', g₁'⟩), f' = M.pathDestLeft P e₁' f₁ ∧ f₁' = fun x : (last P).B a' => ⟨g₁' x, M.pathDestRight P e₁' f₁ x⟩ := by generalize ef : @splitFun n _ (append1 α (M P α)) f' f₁' = ff at e₁ let he₁' := PFunctor.M.dest a₁ rcases e₁' : he₁' with ⟨a₁', g₁'⟩ rw [M.dest_eq_dest' _ e₁'] at e₁ cases e₁; exact ⟨_, e₁', splitFun_inj ef⟩ theorem M.bisim {α : TypeVec n} (R : P.M α → P.M α → Prop) (h : ∀ x y, R x y → ∃ a f f₁ f₂, M.dest P x = ⟨a, splitFun f f₁⟩ ∧ M.dest P y = ⟨a, splitFun f f₂⟩ ∧ ∀ i, R (f₁ i) (f₂ i)) (x y) (r : R x y) : x = y := by obtain ⟨a₁, f₁⟩ := x obtain ⟨a₂, f₂⟩ := y dsimp [mp] at * have : a₁ = a₂ := by refine PFunctor.M.bisim (fun a₁ a₂ => ∃ x y, R x y ∧ x.1 = a₁ ∧ y.1 = a₂) ?_ _ _ ⟨⟨a₁, f₁⟩, ⟨a₂, f₂⟩, r, rfl, rfl⟩ rintro _ _ ⟨⟨a₁, f₁⟩, ⟨a₂, f₂⟩, r, rfl, rfl⟩ rcases h _ _ r with ⟨a', f', f₁', f₂', e₁, e₂, h'⟩ rcases M.bisim_lemma P e₁ with ⟨g₁', e₁', rfl, rfl⟩ rcases M.bisim_lemma P e₂ with ⟨g₂', e₂', _, rfl⟩ rw [e₁', e₂'] exact ⟨_, _, _, rfl, rfl, fun b => ⟨_, _, h' b, rfl, rfl⟩⟩ subst this congr with (i p) induction p with ( obtain ⟨a', f', f₁', f₂', e₁, e₂, h''⟩ := h _ _ r obtain ⟨g₁', e₁', rfl, rfl⟩ := M.bisim_lemma P e₁ obtain ⟨g₂', e₂', e₃, rfl⟩ := M.bisim_lemma P e₂ cases h'.symm.trans e₁' cases h'.symm.trans e₂') | root x a f h' i c => exact congr_fun (congr_fun e₃ i) c | child x a f h' i c p IH => exact IH _ _ (h'' _) theorem M.bisim₀ {α : TypeVec n} (R : P.M α → P.M α → Prop) (h₀ : Equivalence R) (h : ∀ x y, R x y → (id ::: Quot.mk R) <$$> M.dest _ x = (id ::: Quot.mk R) <$$> M.dest _ y) (x y) (r : R x y) : x = y := by apply M.bisim P R _ _ _ r clear r x y introv Hr specialize h _ _ Hr clear Hr revert h rcases M.dest P x with ⟨ax, fx⟩ rcases M.dest P y with ⟨ay, fy⟩ intro h rw [map_eq, map_eq] at h injection h with h₀ h₁ subst ay simp? at h₁ says simp only [heq_eq_eq] at h₁ have Hdrop : dropFun fx = dropFun fy := by replace h₁ := congr_arg dropFun h₁ simpa using h₁ exists ax, dropFun fx, lastFun fx, lastFun fy rw [split_dropFun_lastFun, Hdrop, split_dropFun_lastFun] simp only [true_and] intro i replace h₁ := congr_fun (congr_fun h₁ Fin2.fz) i simp only [TypeVec.comp, appendFun, splitFun] at h₁ replace h₁ := Quot.eqvGen_exact h₁ rw [h₀.eqvGen_iff] at h₁ exact h₁ theorem M.bisim' {α : TypeVec n} (R : P.M α → P.M α → Prop) (h : ∀ x y, R x y → (id ::: Quot.mk R) <$$> M.dest _ x = (id ::: Quot.mk R) <$$> M.dest _ y) (x y) (r : R x y) : x = y := by have := M.bisim₀ P (Relation.EqvGen R) ?_ ?_ · solve_by_elim [Relation.EqvGen.rel] · apply Relation.EqvGen.is_equivalence · clear r x y introv Hr have : ∀ x y, R x y → Relation.EqvGen R x y := @Relation.EqvGen.rel _ R induction Hr · rw [← Quot.factor_mk_eq R (Relation.EqvGen R) this] rwa [appendFun_comp_id, ← MvFunctor.map_map, ← MvFunctor.map_map, h] all_goals simp_all theorem M.dest_map {α β : TypeVec n} (g : α ⟹ β) (x : P.M α) : M.dest P (g <$$> x) = (appendFun g fun x => g <$$> x) <$$> M.dest P x := by obtain ⟨a, f⟩ := x rw [map_eq] conv => rhs rw [M.dest, M.dest', map_eq, appendFun_comp_splitFun] rfl theorem M.map_dest {α β : TypeVec n} (g : (α ::: P.M α) ⟹ (β ::: P.M β)) (x : P.M α) (h : ∀ x : P.M α, lastFun g x = (dropFun g <$$> x : P.M β)) : g <$$> M.dest P x = M.dest P (dropFun g <$$> x) := by rw [M.dest_map]; congr apply eq_of_drop_last_eq (by simp) simp only [lastFun_appendFun] ext1; apply h end MvPFunctor
Cokernel.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Module.Presentation.Basic /-! # Presentation of a cokernel If `f : M₁ →ₗ[A] M₂` is a linear map between modules, `pres₂` is a presentation of `M₂` and `g₁ : ι → M₁` is a family of generators of `M₁` (which is expressed as `hg₁ : Submodule.span A (Set.range g₁) = ⊤`), then we provide a way to obtain a presentation of the cokernel of `f`. It requires an additional data `data : pres₂.CokernelData f g₁`, which consists of liftings of the images by `f` of the generators of `M₁` as linear combinations of the generators of `M₂`. Then, we obtain a presentation `pres₂.cokernel data hg₁ : Presentation A (M₂ ⧸ LinearMap.range f)`. More generally, if we have an exact sequence `M₁ → M₂ → M₃ → 0`, we obtain a presentation of `M₃`, see `Presentation.ofExact`. -/ universe w w₁ w₂₀ w₂₁ v₁ v₂ v₃ u namespace Module variable {A : Type u} [Ring A] {M₁ : Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} [AddCommGroup M₁] [Module A M₁] [AddCommGroup M₂] [Module A M₂] [AddCommGroup M₃] [Module A M₃] namespace Presentation section Cokernel variable (pres₂ : Presentation.{w₂₀, w₂₁} A M₂) (f : M₁ →ₗ[A] M₂) {ι : Type w₁} (g₁ : ι → M₁) /-- Given a linear map `f : M₁ →ₗ[A] M₂`, a presentation of `M₂` and a choice of generators of `M₁`, this structure specifies a lifting of the image by `f` of each generator of `M₁` as a linear combination of the generators of `M₂`. -/ structure CokernelData where /-- a lifting of `f (g₁ i)` in `pres₂.G →₀ A` -/ lift (i : ι) : pres₂.G →₀ A π_lift (i : ι) : pres₂.π (lift i) = f (g₁ i) /-- Constructor for `Presentation.CokernelData` in case we have a chosen set-theoretic section of the projection `(pres₂.G →₀ A) → M₂`. -/ @[simps] def CokernelData.ofSection (s : M₂ → (pres₂.G →₀ A)) (hs : ∀ (m₂ : M₂), pres₂.π (s m₂) = m₂) : pres₂.CokernelData f g₁ where lift i := s (f (g₁ i)) π_lift i := by simp [hs] instance nonempty_cokernelData : Nonempty (pres₂.CokernelData f g₁) := by obtain ⟨s, hs⟩ := pres₂.surjective_π.hasRightInverse exact ⟨CokernelData.ofSection _ _ _ s hs⟩ variable {g₁ f} (data : pres₂.CokernelData f g₁) /-- The shape of the presentation by generators and relations of the cokernel of `f : M₁ →ₗ[A] M₂`. It consists of a generator for each generator of `M₂`, and there are two types of relations: one for each relation in the presentation in `M₂`, and one for each generator of `M₁`. -/ @[simps] def cokernelRelations : Relations A where G := pres₂.G R := Sum pres₂.R ι relation | .inl r => pres₂.relation r | .inr i => data.lift i /-- The obvious solution in `M₂ ⧸ LinearMap.range f` to the equations in `pres₂.cokernelRelations data`. -/ @[simps] def cokernelSolution : (pres₂.cokernelRelations data).Solution (M₂ ⧸ LinearMap.range f) where var g := Submodule.mkQ _ (pres₂.var g) linearCombination_var_relation := by intro x erw [← Finsupp.apply_linearCombination] obtain (r | i) := x · erw [pres₂.linearCombination_var_relation] dsimp · erw [data.π_lift] simp variable (hg₁ : Submodule.span A (Set.range g₁) = ⊤) namespace cokernelSolution /-- The cokernel can be defined by generators and relations. -/ noncomputable def isPresentationCore : Relations.Solution.IsPresentationCore.{w} (pres₂.cokernelSolution data) where desc s := (LinearMap.range f).liftQ (pres₂.desc { var := s.var linearCombination_var_relation := fun r ↦ s.linearCombination_var_relation (.inl r) }) (by rw [LinearMap.range_eq_map, ← hg₁, Submodule.map_span, Submodule.span_le, Set.image_subset_iff] rintro _ ⟨i, rfl⟩ rw [Set.mem_preimage, SetLike.mem_coe, LinearMap.mem_ker, ← data.π_lift, Relations.Solution.IsPresentation.π_desc_apply] exact s.linearCombination_var_relation (.inr i)) postcomp_desc s := by aesop postcomp_injective h := by ext : 1 apply pres₂.toIsPresentation.postcomp_injective ext g exact Relations.Solution.congr_var h g include hg₁ in lemma isPresentation : (pres₂.cokernelSolution data).IsPresentation := (isPresentationCore pres₂ data hg₁).isPresentation end cokernelSolution /-- The presentation of the cokernel of a linear map `f : M₁ →ₗ[A] M₂` that is obtained from a presentation `pres₂` of `M₂`, a choice of generators `g₁ : ι → M₁` of `M₁`, and an additional data in `pres₂.CokernelData f g₁`. -/ @[simps!] def cokernel : Presentation A (M₂ ⧸ LinearMap.range f) := ofIsPresentation (cokernelSolution.isPresentation pres₂ data hg₁) end Cokernel /-- Given an exact sequence of `A`-modules `M₁ → M₂ → M₃ → 0`, this is the presentation of `M₃` that is obtained from a presentation `pres₂` of `M₂`, a choice of generators `g₁ : ι → M₁` of `M₁`, and an additional data in a `Presentation.CokernelData` structure. -/ @[simps!] noncomputable def ofExact {f : M₁ →ₗ[A] M₂} {g : M₂ →ₗ[A] M₃} (pres₂ : Presentation.{w₂₀, w₂₁} A M₂) {ι : Type w₁} {g₁ : ι → M₁} (data : pres₂.CokernelData f g₁) (hfg : Function.Exact f g) (hg : Function.Surjective g) (hg₁ : Submodule.span A (Set.range g₁) = ⊤) : Presentation A M₃ := (pres₂.cokernel data hg₁).ofLinearEquiv (hfg.linearEquivOfSurjective hg) end Presentation end Module
Basic.lean
import Mathlib.Tactic.RewriteSearch set_option autoImplicit true -- You can enable tracing of the `rw_search` algorithm using -- set_option trace.rw_search true -- You can get timing information (very useful if tweaking the search algorithm!) using -- set_option profiler true /-- info: Try this: rw [List.length_append, Nat.add_comm] -- no goals -/ #guard_msgs in example (xs ys : List α) : (xs ++ ys).length = ys.length + xs.length := by rw_search -- This worked in previous versions, but for now doesn't. -- There are of course better tools for AC rewriting, but it would be nice if `rw_search` -- could do a little of it in the course of a longer rewrite. set_option linter.style.longLine false in /-! -- /- -- info: Try this: rw [← add_assoc, add_right_comm, add_assoc, add_add_add_comm, ← add_assoc, add_right_comm] -- -/ -- #guard_msgs (drop info) in -- example [AddCommMonoid α] {a b c d : α} : (a + b) + (c + d) = a + d + c + b := by -- rw_search -/ /-- info: Try this: rw [List.length_append, List.length_append, Nat.two_mul, add_rotate] -- no goals -/ #guard_msgs in example (xs ys : List α) : (xs ++ ys ++ ys).length = 2 * ys.length + xs.length := by rw_search set_option linter.style.longLine false in /-! info: Try this: rw [List.length_append, List.length_append, Nat.two_mul, Nat.add_assoc, Nat.add_left_comm, Nat.add_right_comm, Nat.add_assoc] -/ #guard_msgs (drop info) in example (xs ys : List α) : (xs ++ ys ++ ys).length = 2 * ys.length + xs.length := by rw_search [-add_rotate] set_option linter.style.longLine false in /-! info: Try this: rw [Int.add_right_comm, add_right_cancel_iff, add_sub_left_comm, add_sub, Int.add_sub_cancel] -/ #guard_msgs (drop info) in example {a b c : Int} : a + b = c + b + (a - c) := by rw_search /-! A test of the current tokenization scheme. -/ /-- info: ["(", "[", "5", ",", "3", "]", ",", "4", "+", "(", "2", "*", "1", ")", ")"] -/ #guard_msgs in open Mathlib.Tactic.RewriteSearch in #eval ("([5, 3], 4 + (2 * 1))".splitOn.map splitDelimiters).flatten -- Function that always constructs `[0]`. Used in the following example. def makeSingleton : Nat → List Nat | 0 => [0] | b + 1 => makeSingleton b /-- info: Try this: rw [← ih] -- no goals -/ #guard_msgs in set_option maxHeartbeats 1000 in theorem foo (n : Nat) : makeSingleton n = [0] := by induction' n with n' ih · simp only [makeSingleton] · -- At one point, this failed with: unknown free variable '_uniq.62770' rw_search
Flatten.lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn, Mario Carneiro, Martin Dvorak -/ import Mathlib.Tactic.GCongr.Core import Mathlib.Util.AssertExists /-! # Join of a list of lists This file proves basic properties of `List.flatten`, which concatenates a list of lists. It is defined in `Init.Data.List.Basic`. -/ -- Make sure we don't import algebra assert_not_exists Monoid variable {α β : Type*} namespace List @[gcongr] protected theorem Sublist.flatten {l₁ l₂ : List (List α)} (h : l₁ <+ l₂) : l₁.flatten <+ l₂.flatten := by induction h with | slnil => simp | cons _ _ ih => rw [flatten_cons] exact ih.trans (sublist_append_right _ _) | cons₂ _ _ ih => simpa @[gcongr] protected theorem Sublist.flatMap {l₁ l₂ : List α} (h : l₁ <+ l₂) (f : α → List β) : l₁.flatMap f <+ l₂.flatMap f := (h.map f).flatten /-- Taking only the first `i+1` elements in a list, and then dropping the first `i` ones, one is left with a list of length `1` made of the `i`-th element of the original list. -/ theorem drop_take_succ_eq_cons_getElem (L : List α) (i : Nat) (h : i < L.length) : (L.take (i + 1)).drop i = [L[i]] := by induction L generalizing i with | nil => exact (Nat.not_succ_le_zero i h).elim | cons head tail ih => rcases i with _ | i · simp · simpa using ih _ (by simpa using h) /-- We can rebracket `x ++ (l₁ ++ x) ++ (l₂ ++ x) ++ ... ++ (lₙ ++ x)` to `(x ++ l₁) ++ (x ++ l₂) ++ ... ++ (x ++ lₙ) ++ x` where `L = [l₁, l₂, ..., lₙ]`. -/ theorem append_flatten_map_append (L : List (List α)) (x : List α) : x ++ (L.map (· ++ x)).flatten = (L.map (x ++ ·)).flatten ++ x := by induction L with | nil => rw [map_nil, flatten, append_nil, map_nil, flatten, nil_append] | cons _ _ ih => rw [map_cons, flatten, map_cons, flatten, append_assoc, ih, append_assoc, append_assoc] end List
levenshtein.lean
import Mathlib.Data.List.EditDistance.Defs import Mathlib.Algebra.Group.Nat.Defs #guard (suffixLevenshtein Levenshtein.defaultCost "kitten".toList "sitting".toList).1 = [3, 3, 4, 5, 6, 6, 7] #guard levenshtein Levenshtein.defaultCost "but our fish said, 'no! no!'".toList "'put me down!' said the fish.".toList = 21
Finite.lean
/- Copyright (c) 2025 Sophie Morel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sophie Morel -/ import Mathlib.Algebra.DirectSum.Module import Mathlib.RingTheory.Finiteness.Basic /-! # A finite direct sum of finite modules is finite This file defines a `Module.Finite` instance for a finite direct sum of finite modules. -/ open DirectSum variable {R ι : Type*} [Semiring R] [Finite ι] (M : ι → Type*) [∀ i : ι, AddCommMonoid (M i)] [∀ i : ι, Module R (M i)] [∀ (i : ι), Module.Finite R (M i)] instance Module.Finite.instDFinsupp : Module.Finite R (Π₀ (i : ι), M i) := letI : Fintype ι := Fintype.ofFinite _ Module.Finite.equiv DFinsupp.linearEquivFunOnFintype.symm instance Module.Finite.instDirectSum : Module.Finite R (⨁ i, M i) := Module.Finite.instDFinsupp M
Orthonormal.lean
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis -/ import Mathlib.Analysis.InnerProductSpace.LinearMap import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.RingTheory.LocalRing.Basic /-! # Orthonormal sets This file defines orthonormal sets in inner product spaces. ## Main results - We define `Orthonormal`, a predicate on a function `v : ι → E`, and prove the existence of a maximal orthonormal set, `exists_maximal_orthonormal`. - Bessel's inequality, `Orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`, the sum of the norm-squares of the inner products `⟪v i, x⟫` is no more than the norm-square of `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file `Analysis.InnerProductSpace.projection`. -/ noncomputable section open RCLike Real Filter Module Topology ComplexConjugate Finsupp open LinearMap (BilinForm) variable {𝕜 E F : Type*} [RCLike 𝕜] section OrthonormalSets_Seminormed variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => inner 𝕜 x y variable {ι : Type*} (𝕜) /-- An orthonormal set of vectors in an `InnerProductSpace` -/ def Orthonormal (v : ι → E) : Prop := (∀ i, ‖v i‖ = 1) ∧ Pairwise fun i j => ⟪v i, v j⟫ = 0 variable {𝕜} @[simp] lemma Orthonormal.of_isEmpty [IsEmpty ι] (v : ι → E) : Orthonormal 𝕜 v := ⟨IsEmpty.elim ‹_›, Subsingleton.pairwise⟩ @[simp] lemma orthonormal_vecCons_iff {n : ℕ} {v : E} {vs : Fin n → E} : Orthonormal 𝕜 (Matrix.vecCons v vs) ↔ ‖v‖ = 1 ∧ (∀ i, ⟪v, vs i⟫ = 0) ∧ Orthonormal 𝕜 vs := by simp_rw [Orthonormal, pairwise_fin_succ_iff_of_isSymm, Fin.forall_fin_succ] tauto lemma Orthonormal.norm_eq_one {v : ι → E} (h : Orthonormal 𝕜 v) (i : ι) : ‖v i‖ = 1 := h.1 i lemma Orthonormal.nnnorm_eq_one {v : ι → E} (h : Orthonormal 𝕜 v) (i : ι) : ‖v i‖₊ = 1 := by suffices (‖v i‖₊ : ℝ) = 1 by norm_cast at this simp [h.norm_eq_one] lemma Orthonormal.enorm_eq_one {v : ι → E} (h : Orthonormal 𝕜 v) (i : ι) : ‖v i‖ₑ = 1 := by rw [← ofReal_norm]; simp [h.norm_eq_one] lemma Orthonormal.inner_eq_zero {v : ι → E} {i j : ι} (h : Orthonormal 𝕜 v) (hij : i ≠ j) : ⟪v i, v j⟫ = 0 := h.2 hij /-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal. (Inner product equals Kronecker delta.) -/ theorem orthonormal_iff_ite [DecidableEq ι] {v : ι → E} : Orthonormal 𝕜 v ↔ ∀ i j, ⟪v i, v j⟫ = if i = j then (1 : 𝕜) else (0 : 𝕜) := by constructor · intro hv i j split_ifs with h · simp [h, inner_self_eq_norm_sq_to_K, hv.norm_eq_one] · exact hv.inner_eq_zero h · intro h constructor · intro i have h' : ‖v i‖ ^ 2 = 1 ^ 2 := by simp [@norm_sq_eq_re_inner 𝕜, h i i] have h₁ : 0 ≤ ‖v i‖ := norm_nonneg _ have h₂ : (0 : ℝ) ≤ 1 := zero_le_one rwa [sq_eq_sq₀ h₁ h₂] at h' · intro i j hij simpa [hij] using h i j /-- `if ... then ... else` characterization of a set of vectors being orthonormal. (Inner product equals Kronecker delta.) -/ theorem orthonormal_subtype_iff_ite [DecidableEq E] {s : Set E} : Orthonormal 𝕜 (Subtype.val : s → E) ↔ ∀ v ∈ s, ∀ w ∈ s, ⟪v, w⟫ = if v = w then 1 else 0 := by rw [orthonormal_iff_ite] simp /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_finsupp {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) : ⟪v i, linearCombination 𝕜 v l⟫ = l i := by classical simpa [linearCombination_apply, Finsupp.inner_sum, orthonormal_iff_ite.mp hv] using Eq.symm /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) {s : Finset ι} {i : ι} (hi : i ∈ s) : ⟪v i, ∑ i ∈ s, l i • v i⟫ = l i := by classical simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv, hi] /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_fintype [Fintype ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) : ⟪v i, ∑ i : ι, l i • v i⟫ = l i := hv.inner_right_sum l (Finset.mem_univ _) /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_finsupp {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) : ⟪linearCombination 𝕜 v l, v i⟫ = conj (l i) := by rw [← inner_conj_symm, hv.inner_right_finsupp] /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) {s : Finset ι} {i : ι} (hi : i ∈ s) : ⟪∑ i ∈ s, l i • v i, v i⟫ = conj (l i) := by classical simp only [sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv, hi, mul_boole, Finset.sum_ite_eq', if_true] /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_fintype [Fintype ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) : ⟪∑ i : ι, l i • v i, v i⟫ = conj (l i) := hv.inner_left_sum l (Finset.mem_univ _) /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum over the first `Finsupp`. -/ theorem Orthonormal.inner_finsupp_eq_sum_left {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) : ⟪linearCombination 𝕜 v l₁, linearCombination 𝕜 v l₂⟫ = l₁.sum fun i y => conj y * l₂ i := by simp only [l₁.linearCombination_apply _, Finsupp.sum_inner, hv.inner_right_finsupp, smul_eq_mul] /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum over the second `Finsupp`. -/ theorem Orthonormal.inner_finsupp_eq_sum_right {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) : ⟪linearCombination 𝕜 v l₁, linearCombination 𝕜 v l₂⟫ = l₂.sum fun i y => conj (l₁ i) * y := by simp only [l₂.linearCombination_apply _, Finsupp.inner_sum, hv.inner_left_finsupp, mul_comm, smul_eq_mul] /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum. -/ protected theorem Orthonormal.inner_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι → 𝕜) (s : Finset ι) : ⟪∑ i ∈ s, l₁ i • v i, ∑ i ∈ s, l₂ i • v i⟫ = ∑ i ∈ s, conj (l₁ i) * l₂ i := by simp_rw [sum_inner, inner_smul_left] refine Finset.sum_congr rfl fun i hi => ?_ rw [hv.inner_right_sum l₂ hi] /-- The double sum of weighted inner products of pairs of vectors from an orthonormal sequence is the sum of the weights. -/ theorem Orthonormal.inner_left_right_finset {s : Finset ι} {v : ι → E} (hv : Orthonormal 𝕜 v) {a : ι → ι → 𝕜} : (∑ i ∈ s, ∑ j ∈ s, a i j • ⟪v j, v i⟫) = ∑ k ∈ s, a k k := by classical simp [orthonormal_iff_ite.mp hv] /-- An orthonormal set is linearly independent. -/ theorem Orthonormal.linearIndependent {v : ι → E} (hv : Orthonormal 𝕜 v) : LinearIndependent 𝕜 v := by rw [linearIndependent_iff] intro l hl ext i have key : ⟪v i, Finsupp.linearCombination 𝕜 v l⟫ = ⟪v i, 0⟫ := by rw [hl] simpa only [hv.inner_right_finsupp, inner_zero_right] using key /-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an orthonormal family. -/ theorem Orthonormal.comp {ι' : Type*} {v : ι → E} (hv : Orthonormal 𝕜 v) (f : ι' → ι) (hf : Function.Injective f) : Orthonormal 𝕜 (v ∘ f) := by classical rw [orthonormal_iff_ite] at hv ⊢ intro i j convert hv (f i) (f j) using 1 simp [hf.eq_iff] /-- An injective family `v : ι → E` is orthonormal if and only if `Subtype.val : (range v) → E` is orthonormal. -/ theorem orthonormal_subtype_range {v : ι → E} (hv : Function.Injective v) : Orthonormal 𝕜 (Subtype.val : Set.range v → E) ↔ Orthonormal 𝕜 v := by let f : ι ≃ Set.range v := Equiv.ofInjective v hv refine ⟨fun h => h.comp f f.injective, fun h => ?_⟩ rw [← Equiv.self_comp_ofInjective_symm hv] exact h.comp f.symm f.symm.injective /-- If `v : ι → E` is an orthonormal family, then `Subtype.val : (range v) → E` is an orthonormal family. -/ theorem Orthonormal.toSubtypeRange {v : ι → E} (hv : Orthonormal 𝕜 v) : Orthonormal 𝕜 (Subtype.val : Set.range v → E) := (orthonormal_subtype_range hv.linearIndependent.injective).2 hv /-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the set. -/ theorem Orthonormal.inner_finsupp_eq_zero {v : ι → E} (hv : Orthonormal 𝕜 v) {s : Set ι} {i : ι} (hi : i ∉ s) {l : ι →₀ 𝕜} (hl : l ∈ Finsupp.supported 𝕜 𝕜 s) : ⟪Finsupp.linearCombination 𝕜 v l, v i⟫ = 0 := by rw [Finsupp.mem_supported'] at hl simp only [hv.inner_left_finsupp, hl i hi, map_zero] /-- Given an orthonormal family, a second family of vectors is orthonormal if every vector equals the corresponding vector in the original family or its negation. -/ theorem Orthonormal.orthonormal_of_forall_eq_or_eq_neg {v w : ι → E} (hv : Orthonormal 𝕜 v) (hw : ∀ i, w i = v i ∨ w i = -v i) : Orthonormal 𝕜 w := by classical rw [orthonormal_iff_ite] at * intro i j rcases hw i with hi | hi <;> rcases hw j with hj | hj <;> replace hv := hv i j <;> split_ifs at hv ⊢ with h <;> simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv /- The material that follows, culminating in the existence of a maximal orthonormal subset, is adapted from the corresponding development of the theory of linearly independents sets. See `exists_linearIndependent` in particular. -/ variable (𝕜 E) theorem orthonormal_empty : Orthonormal 𝕜 (fun x => x : (∅ : Set E) → E) := by classical simp variable {𝕜 E} theorem orthonormal_iUnion_of_directed {η : Type*} {s : η → Set E} (hs : Directed (· ⊆ ·) s) (h : ∀ i, Orthonormal 𝕜 (fun x => x : s i → E)) : Orthonormal 𝕜 (fun x => x : (⋃ i, s i) → E) := by classical rw [orthonormal_subtype_iff_ite] rintro x ⟨_, ⟨i, rfl⟩, hxi⟩ y ⟨_, ⟨j, rfl⟩, hyj⟩ obtain ⟨k, hik, hjk⟩ := hs i j have h_orth : Orthonormal 𝕜 (fun x => x : s k → E) := h k rw [orthonormal_subtype_iff_ite] at h_orth exact h_orth x (hik hxi) y (hjk hyj) theorem orthonormal_sUnion_of_directed {s : Set (Set E)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, Orthonormal 𝕜 (fun x => ((x : a) : E))) : Orthonormal 𝕜 (fun x => x : ⋃₀ s → E) := by rw [Set.sUnion_eq_iUnion]; exact orthonormal_iUnion_of_directed hs.directed_val (by simpa using h) /-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set containing it. -/ theorem exists_maximal_orthonormal {s : Set E} (hs : Orthonormal 𝕜 (Subtype.val : s → E)) : ∃ w ⊇ s, Orthonormal 𝕜 (Subtype.val : w → E) ∧ ∀ u ⊇ w, Orthonormal 𝕜 (Subtype.val : u → E) → u = w := by have := zorn_subset_nonempty { b | Orthonormal 𝕜 (Subtype.val : b → E) } ?_ _ hs · obtain ⟨b, hb⟩ := this exact ⟨b, hb.1, hb.2.1, fun u hus hu => hb.2.eq_of_ge hu hus⟩ · refine fun c hc cc _c0 => ⟨⋃₀ c, ?_, ?_⟩ · exact orthonormal_sUnion_of_directed cc.directedOn fun x xc => hc xc · exact fun _ => Set.subset_sUnion_of_mem open Module /-- A family of orthonormal vectors with the correct cardinality forms a basis. -/ def basisOfOrthonormalOfCardEqFinrank [Fintype ι] [Nonempty ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (card_eq : Fintype.card ι = finrank 𝕜 E) : Basis ι 𝕜 E := basisOfLinearIndependentOfCardEqFinrank hv.linearIndependent card_eq @[simp] theorem coe_basisOfOrthonormalOfCardEqFinrank [Fintype ι] [Nonempty ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (card_eq : Fintype.card ι = finrank 𝕜 E) : (basisOfOrthonormalOfCardEqFinrank hv card_eq : ι → E) = v := coe_basisOfLinearIndependentOfCardEqFinrank _ _ theorem Orthonormal.ne_zero {v : ι → E} (hv : Orthonormal 𝕜 v) (i : ι) : v i ≠ 0 := by refine ne_of_apply_ne norm ?_ rw [hv.1 i, norm_zero] norm_num end OrthonormalSets_Seminormed section Norm_Seminormed open scoped InnerProductSpace variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => inner 𝕜 x y section variable {ι : Type*} {ι' : Type*} {ι'' : Type*} variable {E' : Type*} [SeminormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] variable {E'' : Type*} [SeminormedAddCommGroup E''] [InnerProductSpace 𝕜 E''] /-- A linear isometry preserves the property of being orthonormal. -/ theorem LinearIsometry.orthonormal_comp_iff {v : ι → E} (f : E →ₗᵢ[𝕜] E') : Orthonormal 𝕜 (f ∘ v) ↔ Orthonormal 𝕜 v := by classical simp_rw [orthonormal_iff_ite, Function.comp_apply, LinearIsometry.inner_map_map] /-- A linear isometry preserves the property of being orthonormal. -/ theorem Orthonormal.comp_linearIsometry {v : ι → E} (hv : Orthonormal 𝕜 v) (f : E →ₗᵢ[𝕜] E') : Orthonormal 𝕜 (f ∘ v) := by rwa [f.orthonormal_comp_iff] /-- A linear isometric equivalence preserves the property of being orthonormal. -/ theorem Orthonormal.comp_linearIsometryEquiv {v : ι → E} (hv : Orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') : Orthonormal 𝕜 (f ∘ v) := hv.comp_linearIsometry f.toLinearIsometry /-- A linear isometric equivalence, applied with `Basis.map`, preserves the property of being orthonormal. -/ theorem Orthonormal.mapLinearIsometryEquiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') : Orthonormal 𝕜 (v.map f.toLinearEquiv) := hv.comp_linearIsometryEquiv f /-- A linear map that sends an orthonormal basis to orthonormal vectors is a linear isometry. -/ def LinearMap.isometryOfOrthonormal (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : E →ₗᵢ[𝕜] E' := f.isometryOfInner fun x y => by classical rw [← v.linearCombination_repr x, ← v.linearCombination_repr y, Finsupp.apply_linearCombination, Finsupp.apply_linearCombination, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left] @[simp] theorem LinearMap.coe_isometryOfOrthonormal (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : ⇑(f.isometryOfOrthonormal hv hf) = f := rfl @[simp] theorem LinearMap.isometryOfOrthonormal_toLinearMap (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : (f.isometryOfOrthonormal hv hf).toLinearMap = f := rfl /-- A linear equivalence that sends an orthonormal basis to orthonormal vectors is a linear isometric equivalence. -/ def LinearEquiv.isometryOfOrthonormal (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : E ≃ₗᵢ[𝕜] E' := f.isometryOfInner fun x y => by rw [← LinearEquiv.coe_coe] at hf classical rw [← v.linearCombination_repr x, ← v.linearCombination_repr y, ← LinearEquiv.coe_coe f, Finsupp.apply_linearCombination, Finsupp.apply_linearCombination, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left] @[simp] theorem LinearEquiv.coe_isometryOfOrthonormal (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : ⇑(f.isometryOfOrthonormal hv hf) = f := rfl @[simp] theorem LinearEquiv.isometryOfOrthonormal_toLinearEquiv (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : (f.isometryOfOrthonormal hv hf).toLinearEquiv = f := rfl /-- A linear isometric equivalence that sends an orthonormal basis to a given orthonormal basis. -/ def Orthonormal.equiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : E ≃ₗᵢ[𝕜] E' := (v.equiv v' e).isometryOfOrthonormal hv (by have h : v.equiv v' e ∘ v = v' ∘ e := by ext i simp rw [h] classical exact hv'.comp _ e.injective) @[simp] theorem Orthonormal.equiv_toLinearEquiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : (hv.equiv hv' e).toLinearEquiv = v.equiv v' e := rfl @[simp] theorem Orthonormal.equiv_apply {ι' : Type*} {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') (i : ι) : hv.equiv hv' e (v i) = v' (e i) := Basis.equiv_apply _ _ _ _ @[simp] theorem Orthonormal.equiv_trans {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') {v'' : Basis ι'' 𝕜 E''} (hv'' : Orthonormal 𝕜 v'') (e' : ι' ≃ ι'') : (hv.equiv hv' e).trans (hv'.equiv hv'' e') = hv.equiv hv'' (e.trans e') := v.ext_linearIsometryEquiv fun i => by simp only [LinearIsometryEquiv.trans_apply, Orthonormal.equiv_apply, e.coe_trans, Function.comp_apply] theorem Orthonormal.map_equiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : v.map (hv.equiv hv' e).toLinearEquiv = v'.reindex e.symm := v.map_equiv _ _ end section variable {ι : Type*} {ι' : Type*} {E' : Type*} [SeminormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] @[simp] theorem Orthonormal.equiv_refl {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) : hv.equiv hv (Equiv.refl ι) = LinearIsometryEquiv.refl 𝕜 E := v.ext_linearIsometryEquiv fun i => by simp only [Orthonormal.equiv_apply, Equiv.coe_refl, id, LinearIsometryEquiv.coe_refl] @[simp] theorem Orthonormal.equiv_symm {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : (hv.equiv hv' e).symm = hv'.equiv hv e.symm := v'.ext_linearIsometryEquiv fun i => (hv.equiv hv' e).injective <| by simp only [LinearIsometryEquiv.apply_symm_apply, Orthonormal.equiv_apply, e.apply_symm_apply] end end Norm_Seminormed section BesselsInequality variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable {ι : Type*} (x : E) {v : ι → E} local notation "⟪" x ", " y "⟫" => inner 𝕜 x y /-- Bessel's inequality for finite sums. -/ theorem Orthonormal.sum_inner_products_le {s : Finset ι} (hv : Orthonormal 𝕜 v) : ∑ i ∈ s, ‖⟪v i, x⟫‖ ^ 2 ≤ ‖x‖ ^ 2 := by have h₂ : (∑ i ∈ s, ∑ j ∈ s, ⟪v i, x⟫ * ⟪x, v j⟫ * ⟪v j, v i⟫) = (∑ k ∈ s, ⟪v k, x⟫ * ⟪x, v k⟫ : 𝕜) := by classical exact hv.inner_left_right_finset have h₃ : ∀ z : 𝕜, re (z * conj z) = ‖z‖ ^ 2 := by intro z simp only [mul_conj] norm_cast suffices hbf : ‖x - ∑ i ∈ s, ⟪v i, x⟫ • v i‖ ^ 2 = ‖x‖ ^ 2 - ∑ i ∈ s, ‖⟪v i, x⟫‖ ^ 2 by rw [← sub_nonneg, ← hbf] simp only [norm_nonneg, pow_nonneg] rw [@norm_sub_sq 𝕜, sub_add] simp only [@InnerProductSpace.norm_sq_eq_re_inner 𝕜 E, inner_sum, sum_inner] simp only [inner_smul_right, two_mul, inner_smul_left, inner_conj_symm, ← mul_assoc, h₂, add_sub_cancel_right, sub_right_inj] simp only [map_sum, ← inner_conj_symm x, ← h₃] /-- Bessel's inequality. -/ theorem Orthonormal.tsum_inner_products_le (hv : Orthonormal 𝕜 v) : ∑' i, ‖⟪v i, x⟫‖ ^ 2 ≤ ‖x‖ ^ 2 := by refine tsum_le_of_sum_le' ?_ fun s => hv.sum_inner_products_le x simp only [norm_nonneg, pow_nonneg] /-- The sum defined in Bessel's inequality is summable. -/ theorem Orthonormal.inner_products_summable (hv : Orthonormal 𝕜 v) : Summable fun i => ‖⟪v i, x⟫‖ ^ 2 := by use ⨆ s : Finset ι, ∑ i ∈ s, ‖⟪v i, x⟫‖ ^ 2 apply hasSum_of_isLUB_of_nonneg · intro b simp only [norm_nonneg, pow_nonneg] · refine isLUB_ciSup ?_ use ‖x‖ ^ 2 rintro y ⟨s, rfl⟩ exact hv.sum_inner_products_le x end BesselsInequality
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).
ssrnum.v
From mathcomp Require Export orderedzmod. From mathcomp Require Export numdomain. From mathcomp Require Export numfield. Module Num. Export orderedzmod.Num. Export numdomain.Num. Export numfield.Num. Module Theory. Export orderedzmod.Num.Theory. Export numdomain.Num.Theory. Export numfield.Num.Theory. End Theory. Module Def. Export orderedzmod.Num.Def. Export numdomain.Num.Def. Export numfield.Num.Def. End Def. Module ExtraDef. #[deprecated(since="mathcomp 2.5.0", note="Use Num.Def.sqrtr instead.")] Notation sqrtr := numfield.Num.Def.sqrtr. End ExtraDef. End Num.
Factorization.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.MorphismProperty.Basic /-! # The factorization axiom In this file, we introduce a type-class `HasFactorization W₁ W₂`, which, given two classes of morphisms `W₁` and `W₂` in a category `C`, asserts that any morphism in `C` can be factored as a morphism in `W₁` followed by a morphism in `W₂`. The data of such factorizations can be packaged in the type `FactorizationData W₁ W₂`. This shall be used in the formalization of model categories for which the CM5 axiom asserts that any morphism can be factored as a cofibration followed by a trivial fibration (or a trivial cofibration followed by a fibration). We also provide a structure `FunctorialFactorizationData W₁ W₂` which contains the data of a functorial factorization as above. With this design, when we formalize certain constructions (e.g. cylinder objects in model categories), we may first construct them using using `data : FactorizationData W₁ W₂`. Without duplication of code, it shall be possible to show these cylinders are functorial when a term `data : FunctorialFactorizationData W₁ W₂` is available, the existence of which is asserted in the type-class `HasFunctorialFactorization W₁ W₂`. We also introduce the class `W₁.comp W₂` of morphisms of the form `i ≫ p` with `W₁ i` and `W₂ p` and show that `W₁.comp W₂ = ⊤` iff `HasFactorization W₁ W₂` holds (this is `MorphismProperty.comp_eq_top_iff`). -/ namespace CategoryTheory namespace MorphismProperty variable {C : Type*} [Category C] (W₁ W₂ : MorphismProperty C) /-- Given two classes of morphisms `W₁` and `W₂` on a category `C`, this is the data of the factorization of a morphism `f : X ⟶ Y` as `i ≫ p` with `W₁ i` and `W₂ p`. -/ structure MapFactorizationData {X Y : C} (f : X ⟶ Y) where /-- the intermediate object in the factorization -/ Z : C /-- the first morphism in the factorization -/ i : X ⟶ Z /-- the second morphism in the factorization -/ p : Z ⟶ Y fac : i ≫ p = f := by cat_disch hi : W₁ i hp : W₂ p attribute [reassoc (attr := simp)] MapFactorizationData.fac /-- The data of a term in `MapFactorizationData W₁ W₂ f` for any morphism `f`. -/ abbrev FactorizationData := ∀ {X Y : C} (f : X ⟶ Y), MapFactorizationData W₁ W₂ f /-- The factorization axiom for two classes of morphisms `W₁` and `W₂` in a category `C`. It asserts that any morphism can be factored as a morphism in `W₁` followed by a morphism in `W₂`. -/ class HasFactorization : Prop where nonempty_mapFactorizationData {X Y : C} (f : X ⟶ Y) : Nonempty (MapFactorizationData W₁ W₂ f) /-- A chosen term in `FactorizationData W₁ W₂` when `HasFactorization W₁ W₂` holds. -/ noncomputable def factorizationData [HasFactorization W₁ W₂] : FactorizationData W₁ W₂ := fun _ => Nonempty.some (HasFactorization.nonempty_mapFactorizationData _) /-- The class of morphisms that are of the form `i ≫ p` with `W₁ i` and `W₂ p`. -/ def comp : MorphismProperty C := fun _ _ f => Nonempty (MapFactorizationData W₁ W₂ f) lemma comp_eq_top_iff : W₁.comp W₂ = ⊤ ↔ HasFactorization W₁ W₂ := by constructor · intro h refine ⟨fun f => ?_⟩ have : W₁.comp W₂ f := by simp only [h, top_apply] exact ⟨this.some⟩ · intro ext X Y f simp only [top_apply, iff_true] exact ⟨factorizationData W₁ W₂ f⟩ /-- The data of a functorial factorization of any morphism in `C` as a morphism in `W₁` followed by a morphism in `W₂`. -/ structure FunctorialFactorizationData where /-- the intermediate objects in the factorizations -/ Z : Arrow C ⥤ C /-- the first morphism in the factorizations -/ i : Arrow.leftFunc ⟶ Z /-- the second morphism in the factorizations -/ p : Z ⟶ Arrow.rightFunc fac : i ≫ p = Arrow.leftToRight := by cat_disch hi (f : Arrow C) : W₁ (i.app f) hp (f : Arrow C) : W₂ (p.app f) namespace FunctorialFactorizationData variable {W₁ W₂} variable (data : FunctorialFactorizationData W₁ W₂) attribute [reassoc (attr := simp)] fac @[reassoc (attr := simp)] lemma fac_app {f : Arrow C} : data.i.app f ≫ data.p.app f = f.hom := by rw [← NatTrans.comp_app, fac,Arrow.leftToRight_app] /-- If `W₁ ≤ W₁'` and `W₂ ≤ W₂'`, then a functorial factorization for `W₁` and `W₂` induces a functorial factorization for `W₁'` and `W₂'`. -/ def ofLE {W₁' W₂' : MorphismProperty C} (le₁ : W₁ ≤ W₁') (le₂ : W₂ ≤ W₂') : FunctorialFactorizationData W₁' W₂' where Z := data.Z i := data.i p := data.p hi f := le₁ _ (data.hi f) hp f := le₂ _ (data.hp f) /-- The term in `FactorizationData W₁ W₂` that is deduced from a functorial factorization. -/ def factorizationData : FactorizationData W₁ W₂ := fun f => { Z := data.Z.obj (Arrow.mk f) i := data.i.app (Arrow.mk f) p := data.p.app (Arrow.mk f) hi := data.hi _ hp := data.hp _ } section variable {X Y X' Y' : C} {f : X ⟶ Y} {g : X' ⟶ Y'} (φ : Arrow.mk f ⟶ Arrow.mk g) /-- When `data : FunctorialFactorizationData W₁ W₂`, this is the morphism `(data.factorizationData f).Z ⟶ (data.factorizationData g).Z` expressing the functoriality of the intermediate objects of the factorizations for `φ : Arrow.mk f ⟶ Arrow.mk g`. -/ def mapZ : (data.factorizationData f).Z ⟶ (data.factorizationData g).Z := data.Z.map φ @[reassoc (attr := simp)] lemma i_mapZ : (data.factorizationData f).i ≫ data.mapZ φ = φ.left ≫ (data.factorizationData g).i := (data.i.naturality φ).symm @[reassoc (attr := simp)] lemma mapZ_p : data.mapZ φ ≫ (data.factorizationData g).p = (data.factorizationData f).p ≫ φ.right := data.p.naturality φ variable (f) in @[simp] lemma mapZ_id : data.mapZ (𝟙 (Arrow.mk f)) = 𝟙 _ := data.Z.map_id _ @[reassoc, simp] lemma mapZ_comp {X'' Y'' : C} {h : X'' ⟶ Y''} (ψ : Arrow.mk g ⟶ Arrow.mk h) : data.mapZ (φ ≫ ψ) = data.mapZ φ ≫ data.mapZ ψ := data.Z.map_comp _ _ end section variable (J : Type*) [Category J] /-- Auxiliary definition for `FunctorialFactorizationData.functorCategory`. -/ @[simps] def functorCategory.Z : Arrow (J ⥤ C) ⥤ J ⥤ C where obj f := { obj := fun j => (data.factorizationData (f.hom.app j)).Z map := fun φ => data.mapZ { left := f.left.map φ right := f.right.map φ } map_id := fun j => by dsimp rw [← data.mapZ_id (f.hom.app j)] congr <;> simp map_comp := fun _ _ => by dsimp rw [← data.mapZ_comp] congr <;> simp } map τ := { app := fun j => data.mapZ { left := τ.left.app j right := τ.right.app j w := congr_app τ.w j } naturality := fun _ _ α => by dsimp rw [← data.mapZ_comp, ← data.mapZ_comp] congr 1 ext <;> simp } map_id f := by ext j dsimp rw [← data.mapZ_id] congr 1 map_comp f g := by ext j dsimp rw [← data.mapZ_comp] congr 1 /-- A functorial factorization in the category `C` extends to the functor category `J ⥤ C`. -/ def functorCategory : FunctorialFactorizationData (W₁.functorCategory J) (W₂.functorCategory J) where Z := functorCategory.Z data J i := { app := fun f => { app := fun j => (data.factorizationData (f.hom.app j)).i } } p := { app := fun f => { app := fun j => (data.factorizationData (f.hom.app j)).p } } hi _ _ := data.hi _ hp _ _ := data.hp _ end end FunctorialFactorizationData /-- The functorial factorization axiom for two classes of morphisms `W₁` and `W₂` in a category `C`. It asserts that any morphism can be factored in a functorial manner as a morphism in `W₁` followed by a morphism in `W₂`. -/ class HasFunctorialFactorization : Prop where nonempty_functorialFactorizationData : Nonempty (FunctorialFactorizationData W₁ W₂) /-- A chosen term in `FunctorialFactorizationData W₁ W₂` when the functorial factorization axiom `HasFunctorialFactorization W₁ W₂` holds. -/ noncomputable def functorialFactorizationData [HasFunctorialFactorization W₁ W₂] : FunctorialFactorizationData W₁ W₂ := Nonempty.some (HasFunctorialFactorization.nonempty_functorialFactorizationData) instance [HasFunctorialFactorization W₁ W₂] : HasFactorization W₁ W₂ where nonempty_mapFactorizationData f := ⟨(functorialFactorizationData W₁ W₂).factorizationData f⟩ instance [HasFunctorialFactorization W₁ W₂] (J : Type*) [Category J] : HasFunctorialFactorization (W₁.functorCategory J) (W₂.functorCategory J) := ⟨⟨(functorialFactorizationData W₁ W₂).functorCategory J⟩⟩ end MorphismProperty end CategoryTheory
FourierMotzkin.lean
/- Copyright (c) 2020 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.Std.Data.HashMap import Batteries.Lean.HashMap import Mathlib.Tactic.Linarith.Datatypes /-! # The Fourier-Motzkin elimination procedure The Fourier-Motzkin procedure is a variable elimination method for linear inequalities. <https://en.wikipedia.org/wiki/Fourier%E2%80%93Motzkin_elimination> Given a set of linear inequalities `comps = {tᵢ Rᵢ 0}`, we aim to eliminate a single variable `a` from the set. We partition `comps` into `comps_pos`, `comps_neg`, and `comps_zero`, where `comps_pos` contains the comparisons `tᵢ Rᵢ 0` in which the coefficient of `a` in `tᵢ` is positive, and similar. For each pair of comparisons `tᵢ Rᵢ 0 ∈ comps_pos`, `tⱼ Rⱼ 0 ∈ comps_neg`, we compute coefficients `vᵢ, vⱼ ∈ ℕ` such that `vᵢ*tᵢ + vⱼ*tⱼ` cancels out `a`. We collect these sums `vᵢ*tᵢ + vⱼ*tⱼ R' 0` in a set `S` and set `comps' = S ∪ comps_zero`, a new set of comparisons in which `a` has been eliminated. Theorem: `comps` and `comps'` are equisatisfiable. We recursively eliminate all variables from the system. If we derive an empty clause `0 < 0`, we conclude that the original system was unsatisfiable. -/ open Batteries open Std (format ToFormat TreeSet) namespace Std.TreeSet variable {α : Type*} {cmp} /-- `O(n₂ * log (n₁ + n₂))`. Merges the maps `t₁` and `t₂`. If equal keys exist in both, the key from `t₂` is preferred. -/ def union (t₁ t₂ : TreeSet α cmp) : TreeSet α cmp := t₂.foldl .insert t₁ instance : Union (TreeSet α cmp) := ⟨TreeSet.union⟩ /-- `O(n₁ * (log n₁ + log n₂))`. Constructs the set of all elements of `t₁` that are not in `t₂`. -/ def sdiff (t₁ t₂ : TreeSet α cmp) : TreeSet α cmp := t₁.filter (!t₂.contains ·) instance : SDiff (TreeSet α cmp) := ⟨TreeSet.sdiff⟩ end Std.TreeSet namespace Mathlib.Tactic.Linarith /-! ### Datatypes The `CompSource` and `PComp` datatypes are specific to the FM elimination routine; they are not shared with other components of `linarith`. -/ /-- `CompSource` tracks the source of a comparison. The atomic source of a comparison is an assumption, indexed by a natural number. Two comparisons can be added to produce a new comparison, and one comparison can be scaled by a natural number to produce a new comparison. -/ inductive CompSource : Type | assump : Nat → CompSource | add : CompSource → CompSource → CompSource | scale : Nat → CompSource → CompSource deriving Inhabited /-- Given a `CompSource` `cs`, `cs.flatten` maps an assumption index to the number of copies of that assumption that appear in the history of `cs`. For example, suppose `cs` is produced by scaling assumption 2 by 5, and adding to that the sum of assumptions 1 and 2. `cs.flatten` maps `1 ↦ 1, 2 ↦ 6`. -/ def CompSource.flatten : CompSource → Std.HashMap Nat Nat | (CompSource.assump n) => (∅ : Std.HashMap Nat Nat).insert n 1 | (CompSource.add c1 c2) => (CompSource.flatten c1).mergeWith (fun _ b b' => b + b') (CompSource.flatten c2) | (CompSource.scale n c) => (CompSource.flatten c).mapVal (fun _ v => v * n) /-- Formats a `CompSource` for printing. -/ def CompSource.toString : CompSource → String | (CompSource.assump e) => ToString.toString e | (CompSource.add c1 c2) => CompSource.toString c1 ++ " + " ++ CompSource.toString c2 | (CompSource.scale n c) => ToString.toString n ++ " * " ++ CompSource.toString c instance : ToFormat CompSource := ⟨fun a => CompSource.toString a⟩ /-- A `PComp` stores a linear comparison `Σ cᵢ*xᵢ R 0`, along with information about how this comparison was derived. The original expressions fed into `linarith` are each assigned a unique natural number label. The *historical set* `PComp.history` stores the labels of expressions that were used in deriving the current `PComp`. Variables are also indexed by natural numbers. The sets `PComp.effective`, `PComp.implicit`, and `PComp.vars` contain variable indices. * `PComp.vars` contains the variables that appear in any inequality in the historical set. * `PComp.effective` contains the variables that have been effectively eliminated from `PComp`. A variable `n` is said to be *effectively eliminated* in `p : PComp` if the elimination of `n` produced at least one of the ancestors of `p` (or `p` itself). * `PComp.implicit` contains the variables that have been implicitly eliminated from `PComp`. A variable `n` is said to be *implicitly eliminated* in `p` if it satisfies the following properties: - `n` appears in some inequality in the historical set (i.e. in `p.vars`). - `n` does not appear in `p.c.vars` (i.e. it has been eliminated). - `n` was not effectively eliminated. We track these sets in order to compute whether the history of a `PComp` is *minimal*. Checking this directly is expensive, but effective approximations can be defined in terms of these sets. During the variable elimination process, a `PComp` with non-minimal history can be discarded. -/ structure PComp : Type where /-- The comparison `Σ cᵢ*xᵢ R 0`. -/ c : Comp /-- We track how the comparison was constructed by adding and scaling previous comparisons, back to the original assumptions. -/ src : CompSource /-- The set of original assumptions which have been used in constructing this comparison. -/ history : TreeSet ℕ Ord.compare /-- The variables which have been *effectively eliminated*, i.e. by running the elimination algorithm on that variable. -/ effective : TreeSet ℕ Ord.compare /-- The variables which have been *implicitly eliminated*. These are variables that appear in the historical set, do not appear in `c` itself, and are not in `effective. -/ implicit : TreeSet ℕ Ord.compare /-- The union of all variables appearing in those original assumptions which appear in the `history` set. -/ vars : TreeSet ℕ Ord.compare /-- Any comparison whose history is not minimal is redundant, and need not be included in the new set of comparisons. `elimedGE : ℕ` is a natural number such that all variables with index ≥ `elimedGE` have been removed from the system. This test is an overapproximation to minimality. It gives necessary but not sufficient conditions. If the history of `c` is minimal, then `c.maybeMinimal` is true, but `c.maybeMinimal` may also be true for some `c` with non-minimal history. Thus, if `c.maybeMinimal` is false, `c` is known not to be minimal and must be redundant. See https://doi.org/10.1016/B978-0-444-88771-9.50019-2 (Theorem 13). The condition described there considers only implicitly eliminated variables that have been officially eliminated from the system. This is not the case for every implicitly eliminated variable. Consider eliminating `z` from `{x + y + z < 0, x - y - z < 0}`. The result is the set `{2*x < 0}`; `y` is implicitly but not officially eliminated. This implementation of Fourier-Motzkin elimination processes variables in decreasing order of indices. Immediately after a step that eliminates variable `k`, variable `k'` has been eliminated iff `k' ≥ k`. Thus we can compute the intersection of officially and implicitly eliminated variables by taking the set of implicitly eliminated variables with indices ≥ `elimedGE`. -/ def PComp.maybeMinimal (c : PComp) (elimedGE : ℕ) : Bool := c.history.size ≤ 1 + ((c.implicit.filter (· ≥ elimedGE)).union c.effective).size /-- The `src : CompSource` field is ignored when comparing `PComp`s. Two `PComp`s proving the same comparison, with different sources, are considered equivalent. -/ def PComp.cmp (p1 p2 : PComp) : Ordering := p1.c.cmp p2.c /-- `PComp.scale c n` scales the coefficients of `c` by `n` and notes this in the `CompSource`. -/ def PComp.scale (c : PComp) (n : ℕ) : PComp := { c with c := c.c.scale n, src := c.src.scale n } /-- `PComp.add c1 c2 elimVar` creates the result of summing the linear comparisons `c1` and `c2`, during the process of eliminating the variable `elimVar`. The computation assumes, but does not enforce, that `elimVar` appears in both `c1` and `c2` and does not appear in the sum. Computing the sum of the two comparisons is easy; the complicated details lie in tracking the additional fields of `PComp`. * The historical set `pcomp.history` of `c1 + c2` is the union of the two historical sets. * `vars` is the union of `c1.vars` and `c2.vars`. * The effectively eliminated variables of `c1 + c2` are the union of the two effective sets, with `elim_var` inserted. * The implicitly eliminated variables of `c1 + c2` are those that appear in `vars` but not `c.vars` or `effective`. (Note that the description of the implicitly eliminated variables of `c1 + c2` in the algorithm described in Section 6 of https://doi.org/10.1016/B978-0-444-88771-9.50019-2 seems to be wrong: that says it should be `(c1.implicit.union c2.implicit).sdiff explicit`. Since the implicitly eliminated sets start off empty for the assumption, this formula would leave them always empty.) -/ def PComp.add (c1 c2 : PComp) (elimVar : ℕ) : PComp := let c := c1.c.add c2.c let src := c1.src.add c2.src let history := c1.history.union c2.history let vars := c1.vars.union c2.vars let effective := (c1.effective.union c2.effective).insert elimVar let implicit := (vars.sdiff (.ofList c.vars _)).sdiff effective ⟨c, src, history, effective, implicit, vars⟩ /-- `PComp.assump c n` creates a `PComp` whose comparison is `c` and whose source is `CompSource.assump n`, that is, `c` is derived from the `n`th hypothesis. The history is the singleton set `{n}`. No variables have been eliminated (effectively or implicitly). -/ def PComp.assump (c : Comp) (n : ℕ) : PComp where c := c src := CompSource.assump n history := {n} effective := .empty implicit := .empty vars := .ofList c.vars _ instance : ToFormat PComp := ⟨fun p => format p.c.coeffs ++ toString p.c.str ++ "0"⟩ instance : ToString PComp := ⟨fun p => toString p.c.coeffs ++ toString p.c.str ++ "0"⟩ /-- A collection of comparisons. -/ abbrev PCompSet := TreeSet PComp PComp.cmp /-! ### Elimination procedure -/ /-- If `c1` and `c2` both contain variable `a` with opposite coefficients, produces `v1` and `v2` such that `a` has been cancelled in `v1*c1 + v2*c2`. -/ def elimVar (c1 c2 : Comp) (a : ℕ) : Option (ℕ × ℕ) := let v1 := c1.coeffOf a let v2 := c2.coeffOf a if v1 * v2 < 0 then let vlcm := Nat.lcm v1.natAbs v2.natAbs some ⟨vlcm / v1.natAbs, vlcm / v2.natAbs⟩ else none /-- `pelimVar p1 p2` calls `elimVar` on the `Comp` components of `p1` and `p2`. If this returns `v1` and `v2`, it creates a new `PComp` equal to `v1*p1 + v2*p2`, and tracks this in the `CompSource`. -/ def pelimVar (p1 p2 : PComp) (a : ℕ) : Option PComp := do let (n1, n2) ← elimVar p1.c p2.c a return (p1.scale n1).add (p2.scale n2) a /-- A `PComp` represents a contradiction if its `Comp` field represents a contradiction. -/ def PComp.isContr (p : PComp) : Bool := p.c.isContr /-- `elimWithSet a p comps` collects the result of calling `pelimVar p p' a` for every `p' ∈ comps`. -/ def elimWithSet (a : ℕ) (p : PComp) (comps : PCompSet) : PCompSet := comps.foldl (fun s pc => match pelimVar p pc a with | some pc => if pc.maybeMinimal a then s.insert pc else s | none => s) TreeSet.empty /-- The state for the elimination monad. * `maxVar`: the largest variable index that has not been eliminated. * `comps`: a set of comparisons The elimination procedure proceeds by eliminating variable `v` from `comps` progressively in decreasing order. -/ structure LinarithData : Type where /-- The largest variable index that has not been (officially) eliminated. -/ maxVar : ℕ /-- The set of comparisons. -/ comps : PCompSet /-- The linarith monad extends an exceptional monad with a `LinarithData` state. An exception produces a contradictory `PComp`. -/ abbrev LinarithM : Type → Type := StateT LinarithData (ExceptT PComp Lean.Core.CoreM) /-- Returns the current max variable. -/ def getMaxVar : LinarithM ℕ := LinarithData.maxVar <$> get /-- Return the current comparison set. -/ def getPCompSet : LinarithM PCompSet := LinarithData.comps <$> get /-- Throws an exception if a contradictory `PComp` is contained in the current state. -/ def validate : LinarithM Unit := do match (← getPCompSet).toList.find? (fun p : PComp => p.isContr) with | none => return () | some c => throwThe _ c /-- Updates the current state with a new max variable and comparisons, and calls `validate` to check for a contradiction. -/ def update (maxVar : ℕ) (comps : PCompSet) : LinarithM Unit := do StateT.set ⟨maxVar, comps⟩ validate /-- `splitSetByVarSign a comps` partitions the set `comps` into three parts. * `pos` contains the elements of `comps` in which `a` has a positive coefficient. * `neg` contains the elements of `comps` in which `a` has a negative coefficient. * `notPresent` contains the elements of `comps` in which `a` has coefficient 0. Returns `(pos, neg, notPresent)`. -/ def splitSetByVarSign (a : ℕ) (comps : PCompSet) : PCompSet × PCompSet × PCompSet := comps.foldl (fun ⟨pos, neg, notPresent⟩ pc => let n := pc.c.coeffOf a if n > 0 then ⟨pos.insert pc, neg, notPresent⟩ else if n < 0 then ⟨pos, neg.insert pc, notPresent⟩ else ⟨pos, neg, notPresent.insert pc⟩) ⟨TreeSet.empty, TreeSet.empty, TreeSet.empty⟩ /-- `elimVarM a` performs one round of Fourier-Motzkin elimination, eliminating the variable `a` from the `linarith` state. -/ def elimVarM (a : ℕ) : LinarithM Unit := do let vs ← getMaxVar if (a ≤ vs) then Lean.Core.checkSystem decl_name%.toString let ⟨pos, neg, notPresent⟩ := splitSetByVarSign a (← getPCompSet) update (vs - 1) (← pos.foldlM (fun s p => do Lean.Core.checkSystem decl_name%.toString pure (s.union (elimWithSet a p neg))) notPresent) else pure () /-- `elimAllVarsM` eliminates all variables from the linarith state, leaving it with a set of ground comparisons. If this succeeds without exception, the original `linarith` state is consistent. -/ def elimAllVarsM : LinarithM Unit := do for i in (List.range ((← getMaxVar) + 1)).reverse do elimVarM i /-- `mkLinarithData hyps vars` takes a list of hypotheses and the largest variable present in those hypotheses. It produces an initial state for the elimination monad. -/ def mkLinarithData (hyps : List Comp) (maxVar : ℕ) : LinarithData := ⟨maxVar, .ofList (hyps.mapIdx fun n cmp => PComp.assump cmp n) _⟩ /-- An oracle that uses Fourier-Motzkin elimination. -/ def CertificateOracle.fourierMotzkin : CertificateOracle where produceCertificate hyps maxVar := do let linarithData := mkLinarithData hyps maxVar let result ← (ExceptT.run (StateT.run (do validate; elimAllVarsM : LinarithM Unit) linarithData) :) match result with | (Except.ok _) => failure | (Except.error contr) => return contr.src.flatten end Mathlib.Tactic.Linarith
field.lean
import Mathlib example (x y : ℝ) (h : x ≠ y) : (x^2 - y^2)/(x - y) = x + y := by grind example (x y : ℝ) (h : (x + y)^2 ≠ 0) : (x^2 - y^2)/(x + y) = x - y := by grind
Defs.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov -/ import Mathlib.Algebra.Module.LinearMap.Defs /-! # Algebras over commutative semirings In this file we define associative unital `Algebra`s over commutative (semi)rings. * algebra homomorphisms `AlgHom` are defined in `Mathlib/Algebra/Algebra/Hom.lean`; * algebra equivalences `AlgEquiv` are defined in `Mathlib/Algebra/Algebra/Equiv.lean`; * `Subalgebra`s are defined in `Mathlib/Algebra/Algebra/Subalgebra.lean`; * The category `AlgCat R` of `R`-algebras is defined in the file `Mathlib/Algebra/Category/Algebra/Basic.lean`. See the implementation notes for remarks about non-associative and non-unital algebras. ## Main definitions: * `Algebra R A`: the algebra typeclass. * `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the preferred spelling of this map, it is also available as: * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`. * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file). ## Implementation notes Given a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a (possibly noncommutative) (semi)ring `A`: * By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the center of `A`. * By requiring `A` be an `R`-module such that the action associates and commutes with multiplication as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`. We define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and requiring that this scalar action `r • x` must agree with left multiplication by the image of the structure morphism `algebraMap R A r * x`. As a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring: 1. ```lean variable [CommSemiring R] [Semiring A] variable [Algebra R A] ``` 2. ```lean variable [CommSemiring R] [Semiring A] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] ``` The first approach implies the second via typeclass search; so any lemma stated with the second set of arguments will automatically apply to the first set. Typeclass search does not know that the second approach implies the first, but this can be shown with: ```lean example {R A : Type*} [CommSemiring R] [Semiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A := Algebra.ofModule smul_mul_assoc mul_smul_comm ``` The advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and `Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally convenient. The advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can all be relaxed independently; for instance, this allows us to: * Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or non-associative algebras. * Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`, which when `R' = Rˣ` lets us talk about the "algebra-like" action of `Rˣ` on an `R`-algebra `A`. While `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can. You should always use the first approach when working with associative unital algebras, and mimic the second approach only when you need to weaken a condition on either `R` or `A`. -/ assert_not_exists Field Finset Module.End universe u v w u₁ v₁ section Prio /-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`. See the implementation notes in this file for discussion of the details of this definition. -/ class Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A where /-- Embedding `R →+* A` given by `Algebra` structure. Use `algebraMap` from the root namespace instead. -/ protected algebraMap : R →+* A commutes' : ∀ r x, algebraMap r * x = x * algebraMap r smul_def' : ∀ r x, r • x = algebraMap r * x end Prio /-- Embedding `R →+* A` given by `Algebra` structure. -/ def algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A := Algebra.algebraMap /-- Coercion from a commutative semiring to an algebra over this semiring. -/ @[coe, reducible] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A := algebraMap R A namespace algebraMap scoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] : CoeHTCT R A := ⟨Algebra.cast⟩ section CommSemiringSemiring variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] @[norm_cast] theorem coe_zero : (↑(0 : R) : A) = 0 := map_zero (algebraMap R A) @[norm_cast] theorem coe_one : (↑(1 : R) : A) = 1 := map_one (algebraMap R A) @[norm_cast] theorem coe_natCast (a : ℕ) : (↑(a : R) : A) = a := map_natCast (algebraMap R A) a @[norm_cast] theorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b := map_add (algebraMap R A) a b @[norm_cast] theorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b := map_mul (algebraMap R A) a b @[norm_cast] theorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n := map_pow (algebraMap R A) _ _ end CommSemiringSemiring section CommRingRing variable {R A : Type*} [CommRing R] [Ring A] [Algebra R A] @[norm_cast] theorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x := map_neg (algebraMap R A) x @[norm_cast] theorem coe_sub (a b : R) : (↑(a - b : R) : A) = ↑a - ↑b := map_sub (algebraMap R A) a b end CommRingRing end algebraMap /-- Creating an algebra from a morphism to the center of a semiring. See note [reducible non-instances]. *Warning:* In general this should not be used if `S` already has a `SMul R S` instance, since this creates another `SMul R S` instance from the supplied `RingHom` and this will likely create a diamond. -/ abbrev RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S) (h : ∀ c x, i c * x = x * i c) : Algebra R S where smul c x := i c * x commutes' := h smul_def' _ _ := rfl algebraMap := i -- just simple lemmas for a declaration that is itself primed, no need for docstrings set_option linter.docPrime false in theorem RingHom.smul_toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S) (h : ∀ c x, i c * x = x * i c) (r : R) (s : S) : let _ := RingHom.toAlgebra' i h r • s = i r * s := rfl set_option linter.docPrime false in theorem RingHom.algebraMap_toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S) (h : ∀ c x, i c * x = x * i c) : @algebraMap R S _ _ (i.toAlgebra' h) = i := rfl /-- Creating an algebra from a morphism to a commutative semiring. See note [reducible non-instances]. *Warning:* In general this should not be used if `S` already has a `SMul R S` instance, since this creates another `SMul R S` instance from the supplied `RingHom` and this will likely create a diamond. -/ abbrev RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S := i.toAlgebra' fun _ => mul_comm _ theorem RingHom.smul_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) (r : R) (s : S) : let _ := RingHom.toAlgebra i r • s = i r * s := rfl theorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : @algebraMap R S _ _ i.toAlgebra = i := rfl namespace Algebra variable {R : Type u} {S : Type v} {A : Type w} {B : Type*} /-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure. If `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra` over `R`. See note [reducible non-instances]. -/ abbrev ofModule' [CommSemiring R] [Semiring A] [Module R A] (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x) (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where algebraMap := { toFun r := r • (1 : A) map_one' := one_smul _ _ map_mul' r₁ r₂ := by simp only [h₁, mul_smul] map_zero' := zero_smul _ _ map_add' r₁ r₂ := add_smul r₁ r₂ 1 } commutes' r x := by simp [h₁, h₂] smul_def' r x := by simp [h₁] /-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure. If `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A` is an `Algebra` over `R`. See note [reducible non-instances]. -/ abbrev ofModule [CommSemiring R] [Semiring A] [Module R A] (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y)) (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A := ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one] section Semiring variable [CommSemiring R] [CommSemiring S] variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] -- We'll later use this to show `Algebra ℤ M` is a subsingleton. /-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree, it suffices to check the `algebraMap`s agree. -/ @[ext] theorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A) (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) : P = Q := by replace h : P.algebraMap = Q.algebraMap := DFunLike.ext _ _ h have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by funext r a rw [P.smul_def', Q.smul_def', h] rcases P with @⟨⟨P⟩⟩ rcases Q with @⟨⟨Q⟩⟩ congr /-- An auxiliary lemma used to prove theorems of the form `RingHom.X (algebraMap R S) ↔ Algebra.X R S`. -/ lemma _root_.toAlgebra_algebraMap [Algebra R S] : (algebraMap R S).toAlgebra = ‹_› := algebra_ext _ _ fun _ ↦ rfl -- see Note [lower instance priority] instance (priority := 200) toModule {R A} {_ : CommSemiring R} {_ : Semiring A} [Algebra R A] : Module R A where one_smul _ := by simp [smul_def'] mul_smul := by simp [smul_def', mul_assoc] smul_add := by simp [smul_def', mul_add] smul_zero := by simp [smul_def'] add_smul := by simp [smul_def', add_mul] zero_smul := by simp [smul_def'] theorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x := Algebra.smul_def' r x theorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) := calc algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm _ = r • (1 : A) := (Algebra.smul_def r 1).symm theorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) := funext algebraMap_eq_smul_one /-- `mul_comm` for `Algebra`s when one element is from the base ring. -/ theorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r := Algebra.commutes' r x lemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x := Algebra.commutes r x lemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) := (Algebra.commutes r x).symm /-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/ theorem left_comm (x : A) (r : R) (y : A) : x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by rw [← mul_assoc, ← commutes, mul_assoc] /-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/ theorem right_comm (x : A) (r : R) (y : A) : x * algebraMap R A r * y = x * y * algebraMap R A r := by rw [mul_assoc, commutes, ← mul_assoc] instance _root_.IsScalarTower.right : IsScalarTower R A A := ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩ @[simp] theorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A := RingHom.ext fun r => (algebraMap_eq_smul_one r).symm -- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using -- `mul_smul_comm s x y`. /-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass search (and was here first). -/ @[simp] protected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by rw [smul_def, smul_def, left_comm] /-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass search (and was here first). -/ @[simp] protected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) := smul_mul_assoc r x y @[simp] theorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A] [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by rw [algebraMap_eq_smul_one, smul_comm a r (1 : A), smul_one] section compHom variable (A) (f : S →+* R) /-- Compose an `Algebra` with a `RingHom`, with action `f s • m`. This is the algebra version of `Module.compHom`. -/ abbrev compHom : Algebra S A where smul s a := f s • a algebraMap := (algebraMap R A).comp f commutes' _ _ := Algebra.commutes _ _ smul_def' _ _ := Algebra.smul_def _ _ theorem compHom_smul_def (s : S) (x : A) : letI := compHom A f s • x = f s • x := rfl theorem compHom_algebraMap_eq : letI := compHom A f algebraMap S A = (algebraMap R A).comp f := rfl theorem compHom_algebraMap_apply (s : S) : letI := compHom A f algebraMap S A s = (algebraMap R A) (f s) := rfl end compHom variable (R A) /-- The canonical ring homomorphism `algebraMap R A : R →+* A` for any `R`-algebra `A`, packaged as an `R`-linear map. -/ protected def linearMap : R →ₗ[R] A := { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] } @[simp] theorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r := rfl theorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A := rfl /-- The identity map inducing an `Algebra` structure. -/ instance (priority := 1100) id : Algebra R R where -- We override `toFun` and `toSMul` because `RingHom.id` is not reducible and cannot -- be made so without a significant performance hit. -- see library note [reducible non-instances]. toSMul := Mul.toSMul _ __ := ({RingHom.id R with toFun x := x}).toAlgebra @[simp] lemma linearMap_self : Algebra.linearMap R R = .id := rfl variable {R A} @[simp] lemma algebraMap_self : algebraMap R R = .id _ := rfl lemma algebraMap_self_apply (x : R) : algebraMap R R x = x := rfl namespace id @[deprecated algebraMap_self (since := "2025-07-17")] theorem map_eq_id : algebraMap R R = RingHom.id _ := rfl @[deprecated algebraMap_self_apply (since := "2025-07-17")] theorem map_eq_self (x : R) : algebraMap R R x = x := rfl @[simp] theorem smul_eq_mul (x y : R) : x • y = x * y := rfl end id end Semiring end Algebra @[norm_cast] theorem algebraMap.coe_smul (A B C : Type*) [SMul A B] [CommSemiring B] [Semiring C] [Algebra B C] [SMul A C] [IsScalarTower A B C] (a : A) (b : B) : (a • b : B) = a • (b : C) := calc ((a • b : B) : C) = (a • b) • 1 := Algebra.algebraMap_eq_smul_one _ _ = a • (b • 1) := smul_assoc .. _ = a • (b : C) := congrArg _ (Algebra.algebraMap_eq_smul_one b).symm
Asymptotics.lean
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.Basic import Mathlib.Analysis.Asymptotics.Defs /-! # Asymptotic statements about the operator norm This file contains lemmas about how operator norm on continuous linear maps interacts with `IsBigO`. -/ open Asymptotics variable {𝕜 𝕜₂ 𝕜₃ E F G : Type*} variable [SeminormedAddCommGroup E] [SeminormedAddCommGroup F] [SeminormedAddCommGroup G] variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃] [NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜₃ G] {σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃} namespace ContinuousLinearMap variable [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) (l : Filter E) theorem isBigOWith_id : IsBigOWith ‖f‖ l f fun x => x := isBigOWith_of_le' _ f.le_opNorm theorem isBigO_id : f =O[l] fun x => x := (f.isBigOWith_id l).isBigO theorem isBigOWith_comp [RingHomIsometric σ₂₃] {α : Type*} (g : F →SL[σ₂₃] G) (f : α → F) (l : Filter α) : IsBigOWith ‖g‖ l (fun x' => g (f x')) f := (g.isBigOWith_id ⊤).comp_tendsto le_top theorem isBigO_comp [RingHomIsometric σ₂₃] {α : Type*} (g : F →SL[σ₂₃] G) (f : α → F) (l : Filter α) : (fun x' => g (f x')) =O[l] f := (g.isBigOWith_comp f l).isBigO theorem isBigOWith_sub (x : E) : IsBigOWith ‖f‖ l (fun x' => f (x' - x)) fun x' => x' - x := f.isBigOWith_comp _ l theorem isBigO_sub (x : E) : (fun x' => f (x' - x)) =O[l] fun x' => x' - x := f.isBigO_comp _ l end ContinuousLinearMap namespace ContinuousLinearEquiv variable {σ₂₁ : 𝕜₂ →+* 𝕜} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂] (e : E ≃SL[σ₁₂] F) section variable [RingHomIsometric σ₁₂] theorem isBigO_comp {α : Type*} (f : α → E) (l : Filter α) : (fun x' => e (f x')) =O[l] f := (e : E →SL[σ₁₂] F).isBigO_comp f l theorem isBigO_sub (l : Filter E) (x : E) : (fun x' => e (x' - x)) =O[l] fun x' => x' - x := (e : E →SL[σ₁₂] F).isBigO_sub l x end section variable [RingHomIsometric σ₂₁] theorem isBigO_comp_rev {α : Type*} (f : α → E) (l : Filter α) : f =O[l] fun x' => e (f x') := (e.symm.isBigO_comp _ l).congr_left fun _ => e.symm_apply_apply _ theorem isBigO_sub_rev (l : Filter E) (x : E) : (fun x' => x' - x) =O[l] fun x' => e (x' - x) := e.isBigO_comp_rev _ _ end end ContinuousLinearEquiv
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, Yury Kudryashov -/ import Mathlib.Order.Bounds.Image import Mathlib.Order.Hom.Set /-! # Order isomorphisms and bounds. -/ open Set namespace OrderIso variable {α β : Type*} [Preorder α] [Preorder β] (f : α ≃o β) theorem upperBounds_image {s : Set α} : upperBounds (f '' s) = f '' upperBounds s := Subset.antisymm (fun x hx => ⟨f.symm x, fun _ hy => f.le_symm_apply.2 (hx <| mem_image_of_mem _ hy), f.apply_symm_apply x⟩) f.monotone.image_upperBounds_subset_upperBounds_image theorem lowerBounds_image {s : Set α} : lowerBounds (f '' s) = f '' lowerBounds s := @upperBounds_image αᵒᵈ βᵒᵈ _ _ f.dual _ @[simp] theorem isLUB_image {s : Set α} {x : β} : IsLUB (f '' s) x ↔ IsLUB s (f.symm x) := ⟨fun h => IsLUB.of_image (by simp) ((f.apply_symm_apply x).symm ▸ h), fun h => (IsLUB.of_image (by simp)) <| (f.symm_image_image s).symm ▸ h⟩ theorem isLUB_image' {s : Set α} {x : α} : IsLUB (f '' s) (f x) ↔ IsLUB s x := by rw [isLUB_image, f.symm_apply_apply] @[simp] theorem isGLB_image {s : Set α} {x : β} : IsGLB (f '' s) x ↔ IsGLB s (f.symm x) := f.dual.isLUB_image theorem isGLB_image' {s : Set α} {x : α} : IsGLB (f '' s) (f x) ↔ IsGLB s x := f.dual.isLUB_image' @[simp] theorem isLUB_preimage {s : Set β} {x : α} : IsLUB (f ⁻¹' s) x ↔ IsLUB s (f x) := by rw [← f.symm_symm, ← image_eq_preimage, isLUB_image] theorem isLUB_preimage' {s : Set β} {x : β} : IsLUB (f ⁻¹' s) (f.symm x) ↔ IsLUB s x := by rw [isLUB_preimage, f.apply_symm_apply] @[simp] theorem isGLB_preimage {s : Set β} {x : α} : IsGLB (f ⁻¹' s) x ↔ IsGLB s (f x) := f.dual.isLUB_preimage theorem isGLB_preimage' {s : Set β} {x : β} : IsGLB (f ⁻¹' s) (f.symm x) ↔ IsGLB s x := f.dual.isLUB_preimage' end OrderIso
Parity.lean
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Group.Nat.Even import Mathlib.Data.Nat.Cast.Basic import Mathlib.Data.Nat.Cast.Commute import Mathlib.Data.Set.Operations import Mathlib.Logic.Function.Iterate /-! # Even and odd elements in rings This file defines odd elements and proves some general facts about even and odd elements of rings. As opposed to `Even`, `Odd` does not have a multiplicative counterpart. ## TODO Try to generalize `Even` lemmas further. For example, there are still a few lemmas whose `Semiring` assumptions I (DT) am not convinced are necessary. If that turns out to be true, they could be moved to `Mathlib/Algebra/Group/Even.lean`. ## See also `Mathlib/Algebra/Group/Even.lean` for the definition of even elements. -/ assert_not_exists DenselyOrdered OrderedRing open MulOpposite variable {F α β : Type*} section Monoid variable [Monoid α] [HasDistribNeg α] {n : ℕ} {a : α} @[simp] lemma Even.neg_pow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a simp_rw [← two_mul, pow_mul, neg_sq] lemma Even.neg_one_pow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow] end Monoid section DivisionMonoid variable [DivisionMonoid α] [HasDistribNeg α] {a : α} {n : ℤ} lemma Even.neg_zpow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [← Int.two_mul, zpow_mul, zpow_two, neg_mul_neg] lemma Even.neg_one_zpow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow] end DivisionMonoid @[simp] lemma IsSquare.zero [MulZeroClass α] : IsSquare (0 : α) := ⟨0, (mul_zero _).symm⟩ section Semiring variable [Semiring α] [Semiring β] {a b : α} {m n : ℕ} lemma even_iff_exists_two_mul : Even a ↔ ∃ b, a = 2 * b := by simp [even_iff_exists_two_nsmul] lemma even_iff_two_dvd : Even a ↔ 2 ∣ a := by simp [Even, Dvd.dvd, two_mul] alias ⟨Even.two_dvd, _⟩ := even_iff_two_dvd lemma Even.trans_dvd (ha : Even a) (hab : a ∣ b) : Even b := even_iff_two_dvd.2 <| ha.two_dvd.trans hab lemma Dvd.dvd.even (hab : a ∣ b) (ha : Even a) : Even b := ha.trans_dvd hab @[simp] lemma range_two_mul (α) [NonAssocSemiring α] : Set.range (fun x : α ↦ 2 * x) = {a | Even a} := by ext x simp [eq_comm, two_mul, Even] @[simp] lemma even_two : Even (2 : α) := ⟨1, by rw [one_add_one_eq_two]⟩ @[simp] lemma Even.mul_left (ha : Even a) (b) : Even (b * a) := ha.map (AddMonoidHom.mulLeft _) @[simp] lemma Even.mul_right (ha : Even a) (b) : Even (a * b) := ha.map (AddMonoidHom.mulRight _) lemma even_two_mul (a : α) : Even (2 * a) := ⟨a, two_mul _⟩ lemma Even.pow_of_ne_zero (ha : Even a) : ∀ {n : ℕ}, n ≠ 0 → Even (a ^ n) | n + 1, _ => by rw [pow_succ]; exact ha.mul_left _ /-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/ def Odd (a : α) : Prop := ∃ k, a = 2 * k + 1 lemma odd_iff_exists_bit1 : Odd a ↔ ∃ b, a = 2 * b + 1 := exists_congr fun b ↦ by rw [two_mul] alias ⟨Odd.exists_bit1, _⟩ := odd_iff_exists_bit1 @[simp] lemma range_two_mul_add_one (α : Type*) [Semiring α] : Set.range (fun x : α ↦ 2 * x + 1) = {a | Odd a} := by ext x; simp [Odd, eq_comm] lemma Even.add_odd : Even a → Odd b → Odd (a + b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩; exact ⟨a + b, by rw [mul_add, ← two_mul, add_assoc]⟩ lemma Even.odd_add (ha : Even a) (hb : Odd b) : Odd (b + a) := add_comm a b ▸ ha.add_odd hb lemma Odd.add_even (ha : Odd a) (hb : Even b) : Odd (a + b) := add_comm a b ▸ hb.add_odd ha lemma Odd.add_odd : Odd a → Odd b → Even (a + b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ⟨a + b + 1, ?_⟩ rw [two_mul, two_mul] ac_rfl @[simp] lemma odd_one : Odd (1 : α) := ⟨0, (zero_add _).symm.trans (congr_arg (· + (1 : α)) (mul_zero _).symm)⟩ @[simp] lemma Even.add_one (h : Even a) : Odd (a + 1) := h.add_odd odd_one @[simp] lemma Even.one_add (h : Even a) : Odd (1 + a) := h.odd_add odd_one @[simp] lemma Odd.add_one (h : Odd a) : Even (a + 1) := h.add_odd odd_one @[simp] lemma Odd.one_add (h : Odd a) : Even (1 + a) := odd_one.add_odd h lemma odd_two_mul_add_one (a : α) : Odd (2 * a + 1) := ⟨_, rfl⟩ @[simp] lemma odd_add_self_one' : Odd (a + (a + 1)) := by simp [← add_assoc] @[simp] lemma odd_add_one_self : Odd (a + 1 + a) := by simp [add_comm _ a] @[simp] lemma odd_add_one_self' : Odd (a + (1 + a)) := by simp [add_comm 1 a] lemma Odd.map [FunLike F α β] [RingHomClass F α β] (f : F) : Odd a → Odd (f a) := by rintro ⟨a, rfl⟩; exact ⟨f a, by simp [two_mul]⟩ lemma Odd.natCast {R : Type*} [Semiring R] {n : ℕ} (hn : Odd n) : Odd (n : R) := hn.map <| Nat.castRingHom R @[simp] lemma Odd.mul : Odd a → Odd b → Odd (a * b) := by rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ⟨2 * a * b + b + a, ?_⟩ rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc, ← Nat.cast_two, ← Nat.cast_comm] lemma Odd.pow {n : ℕ} (ha : Odd a) : Odd (a ^ n) := by induction n with | zero => simp [pow_zero] | succ n hrec => rw [pow_succ]; exact hrec.mul ha lemma Odd.pow_add_pow_eq_zero [IsCancelAdd α] (hn : Odd n) (hab : a + b = 0) : a ^ n + b ^ n = 0 := by obtain ⟨k, rfl⟩ := hn induction k with | zero => simpa | succ k ih => ?_ have : a ^ 2 = b ^ 2 := add_right_cancel <| calc a ^ 2 + a * b = 0 := by rw [sq, ← mul_add, hab, mul_zero] _ = b ^ 2 + a * b := by rw [sq, ← add_mul, add_comm, hab, zero_mul] refine add_right_cancel (b := b ^ (2 * k + 1) * a ^ 2) ?_ calc _ = (a ^ (2 * k + 1) + b ^ (2 * k + 1)) * a ^ 2 + b ^ (2 * k + 3) := by rw [add_mul, ← pow_add, add_right_comm]; rfl _ = _ := by rw [ih, zero_mul, zero_add, zero_add, this, ← pow_add] theorem Even.of_isUnit_two (h : IsUnit (2 : α)) (a : α) : Even a := let ⟨u, hu⟩ := h; ⟨u⁻¹ * a, by rw [← mul_add, ← two_mul, ← hu, Units.inv_mul_cancel_left]⟩ theorem isUnit_two_iff_forall_even : IsUnit (2 : α) ↔ ∀ a : α, Even a := by refine ⟨Even.of_isUnit_two, fun h => ?_⟩ obtain ⟨a, ha⟩ := h 1 rw [← two_mul, eq_comm] at ha exact ⟨⟨2, a, ha, .trans (Commute.ofNat_right _ _).eq ha⟩, rfl⟩ end Semiring section Ring variable [Ring α] theorem Odd.of_isUnit_two (h : IsUnit (2 : α)) (a : α) : Odd a := by rw [← sub_add_cancel a 1] exact (Even.of_isUnit_two h _).add_one end Ring section Monoid variable [Monoid α] [HasDistribNeg α] {n : ℕ} lemma Odd.neg_pow : Odd n → ∀ a : α, (-a) ^ n = -a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [pow_add, pow_mul, neg_sq, pow_one, mul_neg] @[simp] lemma Odd.neg_one_pow (h : Odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_pow, one_pow] end Monoid section Ring variable [Ring α] {a b : α} {n : ℕ} lemma even_neg_two : Even (-2 : α) := by simp only [even_neg, even_two] lemma Odd.neg (hp : Odd a) : Odd (-a) := by obtain ⟨k, hk⟩ := hp use -(k + 1) rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add, neg_add_cancel_right, ← neg_add, hk] @[simp] lemma odd_neg : Odd (-a) ↔ Odd a := ⟨fun h ↦ neg_neg a ▸ h.neg, Odd.neg⟩ lemma odd_neg_one : Odd (-1 : α) := by simp lemma Odd.sub_even (ha : Odd a) (hb : Even b) : Odd (a - b) := by rw [sub_eq_add_neg]; exact ha.add_even hb.neg lemma Even.sub_odd (ha : Even a) (hb : Odd b) : Odd (a - b) := by rw [sub_eq_add_neg]; exact ha.add_odd hb.neg lemma Odd.sub_odd (ha : Odd a) (hb : Odd b) : Even (a - b) := by rw [sub_eq_add_neg]; exact ha.add_odd hb.neg end Ring namespace Nat variable {m n : ℕ} @[grind =] lemma odd_iff : Odd n ↔ n % 2 = 1 := ⟨fun ⟨m, hm⟩ ↦ by omega, fun h ↦ ⟨n / 2, by omega⟩⟩ instance : DecidablePred (Odd : ℕ → Prop) := fun _ ↦ decidable_of_iff _ odd_iff.symm lemma not_odd_iff : ¬Odd n ↔ n % 2 = 0 := by grind @[simp, grind =] lemma not_odd_iff_even : ¬Odd n ↔ Even n := by grind @[simp] lemma not_even_iff_odd : ¬Even n ↔ Odd n := by grind @[simp] lemma not_odd_zero : ¬Odd 0 := by grind lemma _root_.Odd.not_two_dvd_nat (h : Odd n) : ¬(2 ∣ n) := by grind lemma even_xor_odd (n : ℕ) : Xor' (Even n) (Odd n) := by grind lemma even_or_odd (n : ℕ) : Even n ∨ Odd n := (even_xor_odd n).or lemma even_or_odd' (n : ℕ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 := by simpa only [← two_mul, exists_or, Odd, Even] using even_or_odd n lemma even_xor_odd' (n : ℕ) : ∃ k, Xor' (n = 2 * k) (n = 2 * k + 1) := by obtain ⟨k, rfl⟩ | ⟨k, rfl⟩ := even_or_odd n <;> · use k grind lemma odd_add_one {n : ℕ} : Odd (n + 1) ↔ ¬ Odd n := by grind lemma mod_two_add_add_odd_mod_two (m : ℕ) {n : ℕ} (hn : Odd n) : m % 2 + (m + n) % 2 = 1 := by grind @[simp] lemma mod_two_add_succ_mod_two (m : ℕ) : m % 2 + (m + 1) % 2 = 1 := by omega @[simp] lemma succ_mod_two_add_mod_two (m : ℕ) : (m + 1) % 2 + m % 2 = 1 := by omega lemma even_add' : Even (m + n) ↔ (Odd m ↔ Odd n) := by grind @[simp] lemma not_even_bit1 (n : ℕ) : ¬Even (2 * n + 1) := by simp [parity_simps] lemma not_even_two_mul_add_one (n : ℕ) : ¬ Even (2 * n + 1) := by grind lemma even_sub' (h : n ≤ m) : Even (m - n) ↔ (Odd m ↔ Odd n) := by grind lemma Odd.sub_odd (hm : Odd m) (hn : Odd n) : Even (m - n) := by grind alias _root_.Odd.tsub_odd := Nat.Odd.sub_odd lemma odd_mul : Odd (m * n) ↔ Odd m ∧ Odd n := by grind lemma Odd.of_mul_left (h : Odd (m * n)) : Odd m := (odd_mul.mp h).1 lemma Odd.of_mul_right (h : Odd (m * n)) : Odd n := (odd_mul.mp h).2 lemma odd_pow_iff {e : ℕ} (he : e ≠ 0) : Odd (n ^ e) ↔ Odd n := by grind lemma even_div : Even (m / n) ↔ m % (2 * n) / n = 0 := by rw [even_iff_two_dvd, dvd_iff_mod_eq_zero, ← Nat.mod_mul_right_div_self, mul_comm] @[parity_simps] lemma odd_add : Odd (m + n) ↔ (Odd m ↔ Even n) := by grind lemma odd_add' : Odd (m + n) ↔ (Odd n ↔ Even m) := by grind lemma ne_of_odd_add (h : Odd (m + n)) : m ≠ n := by grind @[parity_simps] lemma odd_sub (h : n ≤ m) : Odd (m - n) ↔ (Odd m ↔ Even n) := by grind lemma Odd.sub_even (h : n ≤ m) (hm : Odd m) (hn : Even n) : Odd (m - n) := by grind lemma odd_sub' (h : n ≤ m) : Odd (m - n) ↔ (Odd n ↔ Even m) := by grind lemma Even.sub_odd (h : n ≤ m) (hm : Even m) (hn : Odd n) : Odd (m - n) := by grind lemma two_mul_div_two_add_one_of_odd (h : Odd n) : 2 * (n / 2) + 1 = n := by grind lemma div_two_mul_two_add_one_of_odd (h : Odd n) : n / 2 * 2 + 1 = n := by grind lemma one_add_div_two_mul_two_of_odd (h : Odd n) : 1 + n / 2 * 2 = n := by grind -- Here are examples of how `parity_simps` can be used with `Nat`. example (m n : ℕ) (h : Even m) : ¬Even (n + 3) ↔ Even (m ^ 2 + m + n) := by simp [*, parity_simps] example : ¬Even 25394535 := by decide end Nat open Nat namespace Function namespace Involutive variable {α : Type*} {f : α → α} {n : ℕ} section lemma iterate_bit0 (hf : Involutive f) (n : ℕ) : f^[2 * n] = id := by rw [iterate_mul, involutive_iff_iter_2_eq_id.1 hf, iterate_id] lemma iterate_bit1 (hf : Involutive f) (n : ℕ) : f^[2 * n + 1] = f := by rw [← succ_eq_add_one, iterate_succ, hf.iterate_bit0, id_comp] end lemma iterate_two_mul (hf : Involutive f) (n : ℕ) : f^[2 * n] = id := by rw [iterate_mul, involutive_iff_iter_2_eq_id.1 hf, iterate_id] lemma iterate_even (hf : Involutive f) (hn : Even n) : f^[n] = id := by obtain ⟨m, rfl⟩ := hn rw [← two_mul, hf.iterate_two_mul] lemma iterate_odd (hf : Involutive f) (hn : Odd n) : f^[n] = f := by obtain ⟨m, rfl⟩ := hn rw [iterate_add, hf.iterate_two_mul, id_comp, iterate_one] lemma iterate_eq_self (hf : Involutive f) (hne : f ≠ id) : f^[n] = f ↔ Odd n := ⟨fun H ↦ not_even_iff_odd.1 fun hn ↦ hne <| by rwa [hf.iterate_even hn, eq_comm] at H, hf.iterate_odd⟩ lemma iterate_eq_id (hf : Involutive f) (hne : f ≠ id) : f^[n] = id ↔ Even n := ⟨fun H ↦ not_odd_iff_even.1 fun hn ↦ hne <| by rwa [hf.iterate_odd hn] at H, hf.iterate_even⟩ end Involutive end Function section DistribNeg variable {R : Type*} [Monoid R] [HasDistribNeg R] {m n : ℕ} lemma neg_one_pow_eq_ite : (-1 : R) ^ n = if Even n then 1 else (-1) := by cases even_or_odd n with | inl h => rw [h.neg_one_pow, if_pos h] | inr h => rw [h.neg_one_pow, if_neg (by simpa using h)] lemma neg_one_pow_congr (h : Even m ↔ Even n) : (-1 : R) ^ m = (-1) ^ n := by simp [h, neg_one_pow_eq_ite] lemma neg_one_pow_eq_one_iff_even (h : (-1 : R) ≠ 1) : (-1 : R) ^ n = 1 ↔ Even n := by simp [neg_one_pow_eq_ite, h] lemma neg_one_pow_eq_neg_one_iff_odd (h : (-1 : R) ≠ 1) : (-1 : R) ^ n = -1 ↔ Odd n := by simp [neg_one_pow_eq_ite, h.symm] end DistribNeg section CharTwo -- We state the following theorems in terms of the slightly more general `2 = 0` hypothesis. variable {R : Type*} [AddMonoidWithOne R] private theorem natCast_eq_zero_or_one_of_two_eq_zero' (n : ℕ) (h : (2 : R) = 0) : (Even n → (n : R) = 0) ∧ (Odd n → (n : R) = 1) := by induction n using Nat.twoStepInduction with | zero => simp | one => simp | more n _ _ => simpa [add_assoc, Nat.even_add_one, Nat.odd_add_one, h] theorem natCast_eq_zero_of_even_of_two_eq_zero {n : ℕ} (hn : Even n) (h : (2 : R) = 0) : (n : R) = 0 := (natCast_eq_zero_or_one_of_two_eq_zero' n h).1 hn theorem natCast_eq_one_of_odd_of_two_eq_zero {n : ℕ} (hn : Odd n) (h : (2 : R) = 0) : (n : R) = 1 := (natCast_eq_zero_or_one_of_two_eq_zero' n h).2 hn theorem natCast_eq_zero_or_one_of_two_eq_zero (n : ℕ) (h : (2 : R) = 0) : (n : R) = 0 ∨ (n : R) = 1 := by obtain hn | hn := Nat.even_or_odd n · exact Or.inl <| natCast_eq_zero_of_even_of_two_eq_zero hn h · exact Or.inr <| natCast_eq_one_of_odd_of_two_eq_zero hn h end CharTwo
Ideal.lean
/- Copyright (c) 2024 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Wojciech Nawrocki -/ import Mathlib.Data.Matrix.Basis import Mathlib.GroupTheory.Congruence.BigOperators import Mathlib.RingTheory.Ideal.Lattice import Mathlib.RingTheory.TwoSidedIdeal.Operations import Mathlib.RingTheory.Jacobson.Ideal /-! # Ideals in a matrix ring This file defines left (resp. two-sided) ideals in a matrix semiring (resp. ring) over left (resp. two-sided) ideals in the base semiring (resp. ring). We also characterize Jacobson radicals of ideals in such rings. ## Main results * `TwoSidedIdeal.equivMatrix` and `TwoSidedIdeal.orderIsoMatrix` establish an order isomorphism between two-sided ideals in $R$ and those in $Mₙ(R)$. * `TwoSidedIdeal.jacobson_matrix` shows that $J(Mₙ(I)) = Mₙ(J(I))$ for any two-sided ideal $I ≤ R$. -/ /-! ### Left ideals in a matrix semiring -/ namespace Ideal open Matrix variable {R : Type*} [Semiring R] (n : Type*) [Fintype n] [DecidableEq n] /-- The left ideal of matrices with entries in `I ≤ R`. -/ def matrix (I : Ideal R) : Ideal (Matrix n n R) where __ := I.toAddSubmonoid.matrix smul_mem' M N hN := by intro i j rw [smul_eq_mul, mul_apply] apply sum_mem intro k _ apply I.mul_mem_left _ (hN k j) @[deprecated (since := "2025-07-28")] alias matricesOver := matrix @[simp] theorem mem_matrix (I : Ideal R) (M : Matrix n n R) : M ∈ I.matrix n ↔ ∀ i j, M i j ∈ I := by rfl @[deprecated (since := "2025-07-28")] alias mem_matricesOver := mem_matrix theorem matrix_monotone : Monotone (matrix (R := R) n) := fun _ _ IJ _ MI i j => IJ (MI i j) @[deprecated (since := "2025-07-28")] alias matricesOver_monotone := matrix_monotone theorem matrix_strictMono_of_nonempty [Nonempty n] : StrictMono (matrix (R := R) n) := matrix_monotone n |>.strictMono_of_injective <| fun I J eq => by ext x have : (∀ _ _, x ∈ I) ↔ (∀ _ _, x ∈ J) := congr((Matrix.of fun _ _ => x) ∈ $eq) simpa only [forall_const] using this @[deprecated (since := "2025-07-28")] alias matricesOver_strictMono_of_nonempty := matrix_strictMono_of_nonempty @[simp] theorem matrix_bot : (⊥ : Ideal R).matrix n = ⊥ := by ext M simp only [mem_matrix, mem_bot] constructor · intro H; ext; apply H · intro H; simp [H] @[deprecated (since := "2025-07-28")] alias matricesOver_bot := matrix_bot @[simp] theorem matrix_top : (⊤ : Ideal R).matrix n = ⊤ := by ext; simp @[deprecated (since := "2025-07-28")] alias matricesOver_top := matrix_top end Ideal /-! ### Jacobson radicals of left ideals in a matrix ring -/ namespace Ideal open Matrix variable {R : Type*} [Ring R] {n : Type*} [Fintype n] [DecidableEq n] /-- A standard basis matrix is in $J(Mₙ(I))$ as long as its one possibly non-zero entry is in $J(I)$. -/ theorem single_mem_jacobson_matrix (I : Ideal R) : ∀ x ∈ I.jacobson, ∀ (i j : n), single i j x ∈ (I.matrix n).jacobson := by -- Proof generalized from example 8 in -- https://ysharifi.wordpress.com/2022/08/16/the-jacobson-radical-basic-examples/ simp_rw [Ideal.mem_jacobson_iff] intro x xIJ p q M have ⟨z, zMx⟩ := xIJ (M q p) let N : Matrix n n R := 1 - ∑ i, single i q (if i = q then 1 - z else (M i p)*x*z) use N intro i j obtain rfl | qj := eq_or_ne q j · by_cases iq : i = q · simp [iq, N, zMx, single, mul_apply, sum_apply, ite_and, sub_mul] · convert I.mul_mem_left (-M i p * x) zMx simp [iq, N, single, mul_apply, sum_apply, ite_and, sub_mul] simp [sub_add, mul_add, mul_sub, mul_assoc] · simp [N, qj, sum_apply, mul_apply] @[deprecated (since := "2025-05-05")] alias stdBasisMatrix_mem_jacobson_matricesOver := single_mem_jacobson_matrix @[deprecated (since := "2025-07-28")] alias single_mem_jacobson_matricesOver := single_mem_jacobson_matrix /-- For any left ideal $I ≤ R$, we have $Mₙ(J(I)) ≤ J(Mₙ(I))$. -/ theorem matrix_jacobson_le (I : Ideal R) : I.jacobson.matrix n ≤ (I.matrix n).jacobson := by intro M MI rw [matrix_eq_sum_single M] apply sum_mem intro i _ apply sum_mem intro j _ apply single_mem_jacobson_matrix I _ (MI i j) @[deprecated (since := "2025-07-28")] alias matricesOver_jacobson_le := matrix_jacobson_le end Ideal /-! ### Two-sided ideals in a matrix ring -/ namespace RingCon variable {R n : Type*} section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] [Fintype n] variable (n) /-- The ring congruence of matrices with entries related by `c`. -/ def matrix (c : RingCon R) : RingCon (Matrix n n R) where r M N := ∀ i j, c (M i j) (N i j) -- note: kept `fun` to distinguish `RingCon`'s binders from `r`'s binders. iseqv.refl _ := fun _ _ ↦ c.refl _ iseqv.symm h := fun _ _ ↦ c.symm <| h _ _ iseqv.trans h₁ h₂ := fun _ _ ↦ c.trans (h₁ _ _) (h₂ _ _) add' h₁ h₂ := fun _ _ ↦ c.add (h₁ _ _) (h₂ _ _) mul' h₁ h₂ := fun _ _ ↦ c.finset_sum _ fun _ _ => c.mul (h₁ _ _) (h₂ _ _) @[simp low] theorem matrix_apply {c : RingCon R} {M N : Matrix n n R} : c.matrix n M N ↔ ∀ i j, c (M i j) (N i j) := Iff.rfl @[simp] theorem matrix_apply_single [DecidableEq n] {c : RingCon R} {i j : n} {x y : R} : c.matrix n (Matrix.single i j x) (Matrix.single i j y) ↔ c x y := by refine ⟨fun h ↦ by simpa using h i j, fun h i' j' ↦ ?_⟩ obtain hi | rfl := ne_or_eq i i' · simpa [hi] using c.refl 0 obtain hj | rfl := ne_or_eq j j' · simpa [hj] using c.refl _ simpa using h @[deprecated (since := "2025-05-05")] alias matrix_apply_stdBasisMatrix := matrix_apply_single theorem matrix_monotone : Monotone (matrix (R := R) n) := fun _ _ hc _ _ h _ _ ↦ hc (h _ _) theorem matrix_injective [Nonempty n] : Function.Injective (matrix (R := R) n) := fun I J eq ↦ RingCon.ext fun r s ↦ by have := congr_fun (DFunLike.congr_fun eq (Matrix.of fun _ _ ↦ r)) (Matrix.of fun _ _ ↦ s) simpa using this theorem matrix_strictMono_of_nonempty [Nonempty n] : StrictMono (matrix (R := R) n) := matrix_monotone n |>.strictMono_of_injective <| matrix_injective _ @[simp] theorem matrix_bot : (⊥ : RingCon R).matrix n = ⊥ := eq_bot_iff.2 fun _ _ h ↦ Matrix.ext h @[simp] theorem matrix_top : (⊤ : RingCon R).matrix n = ⊤ := eq_top_iff.2 fun _ _ _ _ _ ↦ by simp open Matrix variable {n} /-- The congruence relation induced by `c` on `single i j`. -/ def ofMatrix [DecidableEq n] (c : RingCon (Matrix n n R)) : RingCon R where r x y := ∀ i j, c (single i j x) (single i j y) iseqv.refl _ := fun _ _ ↦ c.refl _ iseqv.symm h := fun _ _ ↦ c.symm <| h _ _ iseqv.trans h₁ h₂ := fun _ _ ↦ c.trans (h₁ _ _) (h₂ _ _) add' h₁ h₂ := fun _ _ ↦ by simpa [single_add] using c.add (h₁ _ _) (h₂ _ _) mul' h₁ h₂ := fun i j ↦ by simpa using c.mul (h₁ i i) (h₂ i j) @[simp] theorem ofMatrix_rel [DecidableEq n] {c : RingCon (Matrix n n R)} {x y : R} : ofMatrix c x y ↔ ∀ i j, c (single i j x) (single i j y) := Iff.rfl @[simp] theorem ofMatrix_matrix [DecidableEq n] [Nonempty n] (c : RingCon R) : ofMatrix (matrix n c) = c := by ext x y classical constructor · intro h inhabit n simpa using h default default default default · intro h i j rwa [matrix_apply_single] end NonUnitalNonAssocSemiring section NonAssocSemiring variable [NonAssocSemiring R] [Fintype n] open Matrix /-- Note that this does not apply to a non-unital ring, with counterexample where the elementwise congruence relation `!![⊤,⊤;⊤,(· ≡ · [PMOD 4])]` is a ring congruence over `Matrix (Fin 2) (Fin 2) 2ℤ`. -/ @[simp] theorem matrix_ofMatrix [DecidableEq n] (c : RingCon (Matrix n n R)) : matrix n (ofMatrix c) = c := by ext x y classical constructor · intro h rw [matrix_eq_sum_single x, matrix_eq_sum_single y] refine c.finset_sum _ fun i _ ↦ c.finset_sum _ fun j _ ↦ h i j i j · intro h i' j' i j simpa using c.mul (c.mul (c.refl <| single i i' 1) h) (c.refl <| single j' j 1) /-- A version of `ofMatrix_rel` for a single matrix index, rather than all indices. -/ theorem ofMatrix_rel' [DecidableEq n] {c : RingCon (Matrix n n R)} {x y : R} (i j : n) : ofMatrix c x y ↔ c (single i j x) (single i j y) := by refine ⟨fun h ↦ h i j, fun h i' j' ↦ ?_⟩ simpa using c.mul (c.mul (c.refl <| single i' i 1) h) (c.refl <| single j j' 1) theorem coe_ofMatrix_eq_relationMap [DecidableEq n] {c : RingCon (Matrix n n R)} (i j : n) : ⇑(ofMatrix c) = Relation.Map c (· i j) (· i j) := by ext x y constructor · intro h refine ⟨_,_, h i j, ?_⟩ simp · rintro ⟨X, Y, h, rfl, rfl⟩ i' j' simpa using c.mul (c.mul (c.refl <| single i' i 1) h) (c.refl <| single j j' 1) end NonAssocSemiring end RingCon namespace TwoSidedIdeal open Matrix variable {R : Type*} (n : Type*) section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing R] [Fintype n] /-- The two-sided ideal of matrices with entries in `I ≤ R`. -/ @[simps] def matrix (I : TwoSidedIdeal R) : TwoSidedIdeal (Matrix n n R) where ringCon := I.ringCon.matrix n @[deprecated (since := "2025-07-28")] alias matricesOver := matrix @[simp] lemma mem_matrix (I : TwoSidedIdeal R) (M : Matrix n n R) : M ∈ I.matrix n ↔ ∀ i j, M i j ∈ I := Iff.rfl @[deprecated (since := "2025-07-28")] alias mem_matricesOver := mem_matrix theorem matrix_monotone : Monotone (matrix (R := R) n) := fun _ _ IJ _ MI i j => IJ (MI i j) @[deprecated (since := "2025-07-28")] alias matricesOver_monotone := matrix_monotone theorem matrix_strictMono_of_nonempty [h : Nonempty n] : StrictMono (matrix (R := R) n) := matrix_monotone n |>.strictMono_of_injective <| .comp (fun _ _ => mk.inj) <| (RingCon.matrix_injective n).comp ringCon_injective @[deprecated (since := "2025-07-28")] alias matricesOver_strictMono_of_nonempty := matrix_strictMono_of_nonempty @[simp] theorem matrix_bot : (⊥ : TwoSidedIdeal R).matrix n = ⊥ := ringCon_injective <| RingCon.matrix_bot _ @[deprecated (since := "2025-07-28")] alias matricesOver_bot := matrix_bot @[simp] theorem matrix_top : (⊤ : TwoSidedIdeal R).matrix n = ⊤ := ringCon_injective <| RingCon.matrix_top _ @[deprecated (since := "2025-07-28")] alias matricesOver_top := matrix_top end NonUnitalNonAssocRing section NonAssocRing variable [NonAssocRing R] [Fintype n] [Nonempty n] [DecidableEq n] variable {n} /-- Two-sided ideals in $R$ correspond bijectively to those in $Mₙ(R)$. Given an ideal $I ≤ R$, we send it to $Mₙ(I)$. Given an ideal $J ≤ Mₙ(R)$, we send it to $\{Nᵢⱼ ∣ ∃ N ∈ J\}$. -/ @[simps] def equivMatrix [Nonempty n] [DecidableEq n] : TwoSidedIdeal R ≃ TwoSidedIdeal (Matrix n n R) where toFun I := I.matrix n invFun J := { ringCon := J.ringCon.ofMatrix } right_inv _ := ringCon_injective <| RingCon.matrix_ofMatrix _ left_inv _ := ringCon_injective <| RingCon.ofMatrix_matrix _ @[deprecated (since := "2025-07-28")] alias equivMatricesOver := equivMatrix theorem coe_equivMatrix_symm_apply (I : TwoSidedIdeal (Matrix n n R)) (i j : n) : equivMatrix.symm I = {N i j | N ∈ I} := by ext r constructor · intro h exact ⟨single i j r, by simpa using h i j, by simp⟩ · rintro ⟨n, hn, rfl⟩ rw [SetLike.mem_coe, mem_iff, equivMatrix_symm_apply_ringCon, RingCon.coe_ofMatrix_eq_relationMap i j] exact ⟨n, 0, (I.mem_iff n).mp hn, rfl, rfl⟩ @[deprecated (since := "2025-07-28")] alias coe_equivMatricesOver_symm_apply := coe_equivMatrix_symm_apply /-- Two-sided ideals in $R$ are order-isomorphic with those in $Mₙ(R)$. See also `equivMatrix`. -/ @[simps!] def orderIsoMatrix : TwoSidedIdeal R ≃o TwoSidedIdeal (Matrix n n R) where __ := equivMatrix map_rel_iff' {I J} := by simp only [equivMatrix_apply] constructor · intro le x xI specialize @le (of fun _ _ => x) (by simp [xI]) simpa using le · intro IJ M MI i j exact IJ <| MI i j @[deprecated (since := "2025-07-28")] alias orderIsoMatricesOver := orderIsoMatrix end NonAssocRing section Ring variable [Ring R] [Fintype n] theorem asIdeal_matrix [DecidableEq n] (I : TwoSidedIdeal R) : asIdeal (I.matrix n) = (asIdeal I).matrix n := by ext; simp @[deprecated (since := "2025-07-28")] alias asIdeal_matricesOver := asIdeal_matrix end Ring end TwoSidedIdeal /-! ### Jacobson radicals of two-sided ideals in a matrix ring -/ namespace TwoSidedIdeal open Matrix variable {R : Type*} [Ring R] {n : Type*} [Fintype n] [DecidableEq n] private lemma jacobson_matrix_le (I : TwoSidedIdeal R) : (I.matrix n).jacobson ≤ I.jacobson.matrix n := by -- Proof generalized from example 8 in -- https://ysharifi.wordpress.com/2022/08/16/the-jacobson-radical-basic-examples/ intro M Mmem p q simp only [zero_apply, ← mem_iff] rw [mem_jacobson_iff] replace Mmem := mul_mem_right _ _ (single q p 1) Mmem rw [mem_jacobson_iff] at Mmem intro y specialize Mmem (y • single p p 1) have ⟨N, NxMI⟩ := Mmem use N p p simpa [mul_apply, single, ite_and] using NxMI p p @[deprecated (since := "2025-07-28")] alias jacobson_matricesOver_le := jacobson_matrix_le /-- For any two-sided ideal $I ≤ R$, we have $J(Mₙ(I)) = Mₙ(J(I))$. -/ theorem jacobson_matrix (I : TwoSidedIdeal R) : (I.matrix n).jacobson = I.jacobson.matrix n := by apply le_antisymm · apply jacobson_matrix_le · change asIdeal (I.matrix n).jacobson ≥ asIdeal (I.jacobson.matrix n) simp [asIdeal_jacobson, asIdeal_matrix, Ideal.matrix_jacobson_le] @[deprecated (since := "2025-07-28")] alias jacobson_matricesOver := jacobson_matrix theorem matrix_jacobson_bot : (⊥ : TwoSidedIdeal R).jacobson.matrix n = (⊥ : TwoSidedIdeal (Matrix n n R)).jacobson := matrix_bot n (R := R) ▸ (jacobson_matrix _).symm @[deprecated (since := "2025-07-28")] alias matricesOver_jacobson_bot := matrix_jacobson_bot end TwoSidedIdeal
Paracompact.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Yury Kudryashov -/ import Mathlib.Data.Option.Basic import Mathlib.Topology.Separation.Regular /-! # Paracompact topological spaces A topological space `X` is said to be paracompact if every open covering of `X` admits a locally finite refinement. The definition requires that each set of the new covering is a subset of one of the sets of the initial covering. However, one can ensure that each open covering `s : ι → Set X` admits a *precise* locally finite refinement, i.e., an open covering `t : ι → Set X` with the same index set such that `∀ i, t i ⊆ s i`, see lemma `precise_refinement`. We also provide a convenience lemma `precise_refinement_set` that deals with open coverings of a closed subset of `X` instead of the whole space. We also prove the following facts. * Every compact space is paracompact, see instance `paracompact_of_compact`. * A locally compact sigma compact Hausdorff space is paracompact, see instance `paracompact_of_locallyCompact_sigmaCompact`. Moreover, we can choose a locally finite refinement with sets in a given collection of filter bases of `𝓝 x`, `x : X`, see `refinement_of_locallyCompact_sigmaCompact_of_nhds_basis`. For example, in a proper metric space every open covering `⋃ i, s i` admits a refinement `⋃ i, Metric.ball (c i) (r i)`. * Every paracompact Hausdorff space is normal. This statement is not an instance to avoid loops in the instance graph. * Every `EMetricSpace` is a paracompact space, see instance `EMetric.instParacompactSpace` in `Topology/EMetricSpace/Paracompact`. ## TODO Prove (some of) [Michael's theorems](https://ncatlab.org/nlab/show/Michael%27s+theorem). ## Tags compact space, paracompact space, locally finite covering -/ open Set Filter Function open Filter Topology universe u v w /-- A topological space is called paracompact, if every open covering of this space admits a locally finite refinement. We use the same universe for all types in the definition to avoid creating a class like `ParacompactSpace.{u v}`. Due to lemma `precise_refinement` below, every open covering `s : α → Set X` indexed on `α : Type v` has a *precise* locally finite refinement, i.e., a locally finite refinement `t : α → Set X` indexed on the same type such that each `∀ i, t i ⊆ s i`. -/ class ParacompactSpace (X : Type v) [TopologicalSpace X] : Prop where /-- Every open cover of a paracompact space assumes a locally finite refinement. -/ locallyFinite_refinement : ∀ (α : Type v) (s : α → Set X), (∀ a, IsOpen (s a)) → (⋃ a, s a = univ) → ∃ (β : Type v) (t : β → Set X), (∀ b, IsOpen (t b)) ∧ (⋃ b, t b = univ) ∧ LocallyFinite t ∧ ∀ b, ∃ a, t b ⊆ s a variable {ι : Type u} {X : Type v} {Y : Type w} [TopologicalSpace X] [TopologicalSpace Y] /-- Any open cover of a paracompact space has a locally finite *precise* refinement, that is, one indexed on the same type with each open set contained in the corresponding original one. -/ theorem precise_refinement [ParacompactSpace X] (u : ι → Set X) (uo : ∀ a, IsOpen (u a)) (uc : ⋃ i, u i = univ) : ∃ v : ι → Set X, (∀ a, IsOpen (v a)) ∧ ⋃ i, v i = univ ∧ LocallyFinite v ∧ ∀ a, v a ⊆ u a := by -- Apply definition to `range u`, then turn existence quantifiers into functions using `choose` have := ParacompactSpace.locallyFinite_refinement (range u) (fun r ↦ (r : Set X)) (forall_subtype_range_iff.2 uo) (by rwa [← sUnion_range, Subtype.range_coe]) simp only [exists_subtype_range_iff, iUnion_eq_univ_iff] at this choose α t hto hXt htf ind hind using this choose t_inv ht_inv using hXt choose U hxU hU using htf -- Send each `i` to the union of `t a` over `a ∈ ind ⁻¹' {i}` refine ⟨fun i ↦ ⋃ (a : α) (_ : ind a = i), t a, ?_, ?_, ?_, ?_⟩ · exact fun a ↦ isOpen_iUnion fun a ↦ isOpen_iUnion fun _ ↦ hto a · simp only [eq_univ_iff_forall, mem_iUnion] exact fun x ↦ ⟨ind (t_inv x), _, rfl, ht_inv _⟩ · refine fun x ↦ ⟨U x, hxU x, ((hU x).image ind).subset ?_⟩ simp only [subset_def, mem_iUnion, mem_setOf_eq, Set.Nonempty, mem_inter_iff] rintro i ⟨y, ⟨a, rfl, hya⟩, hyU⟩ exact mem_image_of_mem _ ⟨y, hya, hyU⟩ · simp only [subset_def, mem_iUnion] rintro i x ⟨a, rfl, hxa⟩ exact hind _ hxa /-- In a paracompact space, every open covering of a closed set admits a locally finite refinement indexed by the same type. -/ theorem precise_refinement_set [ParacompactSpace X] {s : Set X} (hs : IsClosed s) (u : ι → Set X) (uo : ∀ i, IsOpen (u i)) (us : s ⊆ ⋃ i, u i) : ∃ v : ι → Set X, (∀ i, IsOpen (v i)) ∧ (s ⊆ ⋃ i, v i) ∧ LocallyFinite v ∧ ∀ i, v i ⊆ u i := by have uc : (iUnion fun i => Option.elim' sᶜ u i) = univ := by apply Subset.antisymm (subset_univ _) · simp_rw [← compl_union_self s, Option.elim', iUnion_option] apply union_subset_union_right sᶜ us rcases precise_refinement (Option.elim' sᶜ u) (Option.forall.2 ⟨isOpen_compl_iff.2 hs, uo⟩) uc with ⟨v, vo, vc, vf, vu⟩ refine ⟨v ∘ some, fun i ↦ vo _, ?_, vf.comp_injective (Option.some_injective _), fun i ↦ vu _⟩ · simp only [iUnion_option, ← compl_subset_iff_union] at vc exact Subset.trans (subset_compl_comm.1 <| vu Option.none) vc theorem Topology.IsClosedEmbedding.paracompactSpace [ParacompactSpace Y] {e : X → Y} (he : IsClosedEmbedding e) : ParacompactSpace X where locallyFinite_refinement α s ho hu := by choose U hUo hU using fun a ↦ he.isOpen_iff.1 (ho a) simp only [← hU] at hu ⊢ have heU : range e ⊆ ⋃ i, U i := by simpa only [range_subset_iff, mem_iUnion, iUnion_eq_univ_iff] using hu rcases precise_refinement_set he.isClosed_range U hUo heU with ⟨V, hVo, heV, hVf, hVU⟩ refine ⟨α, fun a ↦ e ⁻¹' (V a), fun a ↦ (hVo a).preimage he.continuous, ?_, hVf.preimage_continuous he.continuous, fun a ↦ ⟨a, preimage_mono (hVU a)⟩⟩ simpa only [range_subset_iff, mem_iUnion, iUnion_eq_univ_iff] using heV theorem Homeomorph.paracompactSpace_iff (e : X ≃ₜ Y) : ParacompactSpace X ↔ ParacompactSpace Y := ⟨fun _ ↦ e.symm.isClosedEmbedding.paracompactSpace, fun _ ↦ e.isClosedEmbedding.paracompactSpace⟩ /-- The product of a compact space and a paracompact space is a paracompact space. The formalization is based on https://dantopology.wordpress.com/2009/10/24/compact-x-paracompact-is-paracompact/ with some minor modifications. This version assumes that `X` in `X × Y` is compact and `Y` is paracompact, see next lemma for the other case. -/ instance (priority := 200) [CompactSpace X] [ParacompactSpace Y] : ParacompactSpace (X × Y) where locallyFinite_refinement α s ho hu := by have : ∀ (x : X) (y : Y), ∃ (a : α) (U : Set X) (V : Set Y), IsOpen U ∧ IsOpen V ∧ x ∈ U ∧ y ∈ V ∧ U ×ˢ V ⊆ s a := fun x y ↦ (iUnion_eq_univ_iff.1 hu (x, y)).imp fun a ha ↦ isOpen_prod_iff.1 (ho a) x y ha choose a U V hUo hVo hxU hyV hUV using this choose T hT using fun y ↦ CompactSpace.elim_nhds_subcover (U · y) fun x ↦ (hUo x y).mem_nhds (hxU x y) set W : Y → Set Y := fun y ↦ ⋂ x ∈ T y, V x y have hWo : ∀ y, IsOpen (W y) := fun y ↦ isOpen_biInter_finset fun _ _ ↦ hVo _ _ have hW : ∀ y, y ∈ W y := fun _ ↦ mem_iInter₂.2 fun _ _ ↦ hyV _ _ rcases precise_refinement W hWo (iUnion_eq_univ_iff.2 fun y ↦ ⟨y, hW y⟩) with ⟨E, hEo, hE, hEf, hEA⟩ refine ⟨Σ y, T y, fun z ↦ U z.2.1 z.1 ×ˢ E z.1, fun _ ↦ (hUo _ _).prod (hEo _), iUnion_eq_univ_iff.2 fun (x, y) ↦ ?_, fun (x, y) ↦ ?_, fun ⟨y, x, hx⟩ ↦ ?_⟩ · rcases iUnion_eq_univ_iff.1 hE y with ⟨b, hb⟩ rcases iUnion₂_eq_univ_iff.1 (hT b) x with ⟨a, ha, hx⟩ exact ⟨⟨b, a, ha⟩, hx, hb⟩ · rcases hEf y with ⟨t, ht, htf⟩ refine ⟨univ ×ˢ t, prod_mem_nhds univ_mem ht, ?_⟩ refine (htf.biUnion fun y _ ↦ finite_range (Sigma.mk y)).subset ?_ rintro ⟨b, a, ha⟩ ⟨⟨c, d⟩, ⟨-, hd : d ∈ E b⟩, -, hdt : d ∈ t⟩ exact mem_iUnion₂.2 ⟨b, ⟨d, hd, hdt⟩, mem_range_self _⟩ · refine ⟨a x y, (Set.prod_mono Subset.rfl ?_).trans (hUV x y)⟩ exact (hEA _).trans (iInter₂_subset x hx) instance (priority := 200) [ParacompactSpace X] [CompactSpace Y] : ParacompactSpace (X × Y) := (Homeomorph.prodComm X Y).paracompactSpace_iff.2 inferInstance -- See note [lower instance priority] /-- A compact space is paracompact. -/ instance (priority := 100) paracompact_of_compact [CompactSpace X] : ParacompactSpace X := by -- the proof is trivial: we choose a finite subcover using compactness, and use it refine ⟨fun ι s ho hu ↦ ?_⟩ rcases isCompact_univ.elim_finite_subcover _ ho hu.ge with ⟨T, hT⟩ refine ⟨(T : Set ι), fun t ↦ s t, fun t ↦ ho _, ?_, locallyFinite_of_finite _, fun t ↦ ⟨t, Subset.rfl⟩⟩ simpa only [iUnion_coe_set, ← univ_subset_iff] /-- Let `X` be a locally compact sigma compact Hausdorff topological space, let `s` be a closed set in `X`. Suppose that for each `x ∈ s` the sets `B x : ι x → Set X` with the predicate `p x : ι x → Prop` form a basis of the filter `𝓝 x`. Then there exists a locally finite covering `fun i ↦ B (c i) (r i)` of `s` such that all “centers” `c i` belong to `s` and each `r i` satisfies `p (c i)`. The notation is inspired by the case `B x r = Metric.ball x r` but the theorem applies to `nhds_basis_opens` as well. If the covering must be subordinate to some open covering of `s`, then the user should use a basis obtained by `Filter.HasBasis.restrict_subset` or a similar lemma, see the proof of `paracompact_of_locallyCompact_sigmaCompact` for an example. The formalization is based on two [ncatlab](https://ncatlab.org/) proofs: * [locally compact and sigma compact spaces are paracompact](https://ncatlab.org/nlab/show/locally+compact+and+sigma-compact+spaces+are+paracompact); * [open cover of smooth manifold admits locally finite refinement by closed balls](https://ncatlab.org/nlab/show/partition+of+unity#ExistenceOnSmoothManifolds). See also `refinement_of_locallyCompact_sigmaCompact_of_nhds_basis` for a version of this lemma dealing with a covering of the whole space. In most cases (namely, if `B c r ∪ B c r'` is again a set of the form `B c r''`) it is possible to choose `α = X`. This fact is not yet formalized in `mathlib`. -/ theorem refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set [WeaklyLocallyCompactSpace X] [SigmaCompactSpace X] [T2Space X] {ι : X → Type u} {p : ∀ x, ι x → Prop} {B : ∀ x, ι x → Set X} {s : Set X} (hs : IsClosed s) (hB : ∀ x ∈ s, (𝓝 x).HasBasis (p x) (B x)) : ∃ (α : Type v) (c : α → X) (r : ∀ a, ι (c a)), (∀ a, c a ∈ s ∧ p (c a) (r a)) ∧ (s ⊆ ⋃ a, B (c a) (r a)) ∧ LocallyFinite fun a ↦ B (c a) (r a) := by classical -- For technical reasons we prepend two empty sets to the sequence `CompactExhaustion.choice X` set K' : CompactExhaustion X := CompactExhaustion.choice X set K : CompactExhaustion X := K'.shiftr.shiftr set Kdiff := fun n ↦ K (n + 1) \ interior (K n) -- Now we restate some properties of `CompactExhaustion` for `K`/`Kdiff` have hKcov : ∀ x, x ∈ Kdiff (K'.find x + 1) := fun x ↦ by simpa only [K'.find_shiftr] using diff_subset_diff_right interior_subset (K'.shiftr.mem_diff_shiftr_find x) have Kdiffc : ∀ n, IsCompact (Kdiff n ∩ s) := fun n ↦ ((K.isCompact _).diff isOpen_interior).inter_right hs -- Next we choose a finite covering `B (c n i) (r n i)` of each -- `Kdiff (n + 1) ∩ s` such that `B (c n i) (r n i) ∩ s` is disjoint with `K n` have : ∀ (n) (x : ↑(Kdiff (n + 1) ∩ s)), (K n)ᶜ ∈ 𝓝 (x : X) := fun n x ↦ (K.isClosed n).compl_mem_nhds fun hx' ↦ x.2.1.2 <| K.subset_interior_succ _ hx' choose! r hrp hr using fun n (x : ↑(Kdiff (n + 1) ∩ s)) ↦ (hB x x.2.2).mem_iff.1 (this n x) have hxr : ∀ (n x) (hx : x ∈ Kdiff (n + 1) ∩ s), B x (r n ⟨x, hx⟩) ∈ 𝓝 x := fun n x hx ↦ (hB x hx.2).mem_of_mem (hrp _ ⟨x, hx⟩) choose T hT using fun n ↦ (Kdiffc (n + 1)).elim_nhds_subcover' _ (hxr n) set T' : ∀ n, Set ↑(Kdiff (n + 1) ∩ s) := fun n ↦ T n -- Finally, we take the union of all these coverings refine ⟨Σ n, T' n, fun a ↦ a.2, fun a ↦ r a.1 a.2, ?_, ?_, ?_⟩ · rintro ⟨n, x, hx⟩ exact ⟨x.2.2, hrp _ _⟩ · refine fun x hx ↦ mem_iUnion.2 ?_ rcases mem_iUnion₂.1 (hT _ ⟨hKcov x, hx⟩) with ⟨⟨c, hc⟩, hcT, hcx⟩ exact ⟨⟨_, ⟨c, hc⟩, hcT⟩, hcx⟩ · intro x refine ⟨interior (K (K'.find x + 3)), IsOpen.mem_nhds isOpen_interior (K.subset_interior_succ _ (hKcov x).1), ?_⟩ have : (⋃ k ≤ K'.find x + 2, range (Sigma.mk k) : Set (Σ n, T' n)).Finite := (finite_le_nat _).biUnion fun k _ ↦ finite_range _ apply this.subset rintro ⟨k, c, hc⟩ simp only [mem_iUnion, mem_setOf_eq, Subtype.coe_mk] rintro ⟨x, hxB : x ∈ B c (r k c), hxK⟩ refine ⟨k, ?_, ⟨c, hc⟩, rfl⟩ have := (mem_compl_iff _ _).1 (hr k c hxB) contrapose! this with hnk exact K.subset hnk (interior_subset hxK) /-- Let `X` be a locally compact sigma compact Hausdorff topological space. Suppose that for each `x` the sets `B x : ι x → Set X` with the predicate `p x : ι x → Prop` form a basis of the filter `𝓝 x`. Then there exists a locally finite covering `fun i ↦ B (c i) (r i)` of `X` such that each `r i` satisfies `p (c i)`. The notation is inspired by the case `B x r = Metric.ball x r` but the theorem applies to `nhds_basis_opens` as well. If the covering must be subordinate to some open covering of `s`, then the user should use a basis obtained by `Filter.HasBasis.restrict_subset` or a similar lemma, see the proof of `paracompact_of_locallyCompact_sigmaCompact` for an example. The formalization is based on two [ncatlab](https://ncatlab.org/) proofs: * [locally compact and sigma compact spaces are paracompact](https://ncatlab.org/nlab/show/locally+compact+and+sigma-compact+spaces+are+paracompact); * [open cover of smooth manifold admits locally finite refinement by closed balls](https://ncatlab.org/nlab/show/partition+of+unity#ExistenceOnSmoothManifolds). See also `refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set` for a version of this lemma dealing with a covering of a closed set. In most cases (namely, if `B c r ∪ B c r'` is again a set of the form `B c r''`) it is possible to choose `α = X`. This fact is not yet formalized in `mathlib`. -/ theorem refinement_of_locallyCompact_sigmaCompact_of_nhds_basis [WeaklyLocallyCompactSpace X] [SigmaCompactSpace X] [T2Space X] {ι : X → Type u} {p : ∀ x, ι x → Prop} {B : ∀ x, ι x → Set X} (hB : ∀ x, (𝓝 x).HasBasis (p x) (B x)) : ∃ (α : Type v) (c : α → X) (r : ∀ a, ι (c a)), (∀ a, p (c a) (r a)) ∧ ⋃ a, B (c a) (r a) = univ ∧ LocallyFinite fun a ↦ B (c a) (r a) := let ⟨α, c, r, hp, hU, hfin⟩ := refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set isClosed_univ fun x _ ↦ hB x ⟨α, c, r, fun a ↦ (hp a).2, univ_subset_iff.1 hU, hfin⟩ -- See note [lower instance priority] /-- A locally compact sigma compact Hausdorff space is paracompact. See also `refinement_of_locallyCompact_sigmaCompact_of_nhds_basis` for a more precise statement. -/ instance (priority := 100) paracompact_of_locallyCompact_sigmaCompact [WeaklyLocallyCompactSpace X] [SigmaCompactSpace X] [T2Space X] : ParacompactSpace X := by refine ⟨fun α s ho hc ↦ ?_⟩ choose i hi using iUnion_eq_univ_iff.1 hc have : ∀ x : X, (𝓝 x).HasBasis (fun t : Set X ↦ (x ∈ t ∧ IsOpen t) ∧ t ⊆ s (i x)) id := fun x : X ↦ (nhds_basis_opens x).restrict_subset (IsOpen.mem_nhds (ho (i x)) (hi x)) rcases refinement_of_locallyCompact_sigmaCompact_of_nhds_basis this with ⟨β, c, t, hto, htc, htf⟩ exact ⟨β, t, fun x ↦ (hto x).1.2, htc, htf, fun b ↦ ⟨i <| c b, (hto b).2⟩⟩ /-- **Dieudonné's theorem**: a paracompact Hausdorff space is normal. Formalization is based on the proof at [ncatlab](https://ncatlab.org/nlab/show/paracompact+Hausdorff+spaces+are+normal). -/ instance (priority := 100) T4Space.of_paracompactSpace_t2Space [T2Space X] [ParacompactSpace X] : T4Space X := by -- First we show how to go from points to a set on one side. have : ∀ s t : Set X, IsClosed s → (∀ x ∈ s, ∃ u v, IsOpen u ∧ IsOpen v ∧ x ∈ u ∧ t ⊆ v ∧ Disjoint u v) → ∃ u v, IsOpen u ∧ IsOpen v ∧ s ⊆ u ∧ t ⊆ v ∧ Disjoint u v := fun s t hs H ↦ by /- For each `x ∈ s` we choose open disjoint `u x ∋ x` and `v x ⊇ t`. The sets `u x` form an open covering of `s`. We choose a locally finite refinement `u' : s → Set X`, then `⋃ i, u' i` and `(closure (⋃ i, u' i))ᶜ` are disjoint open neighborhoods of `s` and `t`. -/ choose u v hu hv hxu htv huv using SetCoe.forall'.1 H rcases precise_refinement_set hs u hu fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, hxu _⟩ with ⟨u', hu'o, hcov', hu'fin, hsub⟩ refine ⟨⋃ i, u' i, (closure (⋃ i, u' i))ᶜ, isOpen_iUnion hu'o, isClosed_closure.isOpen_compl, hcov', ?_, disjoint_compl_right.mono le_rfl (compl_le_compl subset_closure)⟩ rw [hu'fin.closure_iUnion, compl_iUnion, subset_iInter_iff] refine fun i x hxt hxu ↦ absurd (htv i hxt) (closure_minimal ?_ (isClosed_compl_iff.2 <| hv _) hxu) exact fun y hyu hyv ↦ (huv i).le_bot ⟨hsub _ hyu, hyv⟩ -- Now we apply the lemma twice: first to `s` and `t`, then to `t` and each point of `s`. refine { normal := fun s t hs ht hst ↦ this s t hs fun x hx ↦ ?_ } rcases this t {x} ht fun y hy ↦ (by simp_rw [singleton_subset_iff] exact t2_separation (hst.symm.ne_of_mem hy hx)) with ⟨v, u, hv, hu, htv, hxu, huv⟩ exact ⟨u, v, hu, hv, singleton_subset_iff.1 hxu, htv, huv.symm⟩
AbelRuffini.lean
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Analysis.Calculus.LocalExtr.Polynomial import Mathlib.Analysis.Complex.Polynomial.Basic import Mathlib.FieldTheory.AbelRuffini import Mathlib.RingTheory.Polynomial.Eisenstein.Criterion import Mathlib.RingTheory.Int.Basic import Mathlib.RingTheory.RootsOfUnity.Minpoly /-! # Construction of an algebraic number that is not solvable by radicals. The main ingredients are: * `solvableByRad.isSolvable'` in `Mathlib/FieldTheory/AbelRuffini.lean` : an irreducible polynomial with an `IsSolvableByRad` root has solvable Galois group * `galActionHom_bijective_of_prime_degree'` in `Mathlib/FieldTheory/PolynomialGaloisGroup.lean` : an irreducible polynomial of prime degree with 1-3 non-real roots has full Galois group * `Equiv.Perm.not_solvable` in `Mathlib/GroupTheory/Solvable.lean` : the symmetric group is not solvable Then all that remains is the construction of a specific polynomial satisfying the conditions of `galActionHom_bijective_of_prime_degree'`, which is done in this file. -/ namespace AbelRuffini open Function Polynomial Polynomial.Gal Ideal open scoped Polynomial attribute [local instance] splits_ℚ_ℂ variable (R : Type*) [CommRing R] (a b : ℕ) /-- A quintic polynomial that we will show is irreducible -/ noncomputable def Φ : R[X] := X ^ 5 - C (a : R) * X + C (b : R) variable {R} @[simp] theorem map_Phi {S : Type*} [CommRing S] (f : R →+* S) : (Φ R a b).map f = Φ S a b := by simp [Φ] @[simp] theorem coeff_zero_Phi : (Φ R a b).coeff 0 = (b : R) := by simp [Φ, coeff_X_pow] @[simp] theorem coeff_five_Phi : (Φ R a b).coeff 5 = 1 := by simp [Φ, -map_natCast] variable [Nontrivial R] theorem degree_Phi : (Φ R a b).degree = ((5 : ℕ) : WithBot ℕ) := by suffices degree (X ^ 5 - C (a : R) * X) = ((5 : ℕ) : WithBot ℕ) by rwa [Φ, degree_add_eq_left_of_degree_lt] convert (degree_C_le (R := R)).trans_lt (WithBot.coe_lt_coe.mpr (show 0 < 5 by simp)) rw [degree_sub_eq_left_of_degree_lt] <;> rw [degree_X_pow] exact (degree_C_mul_X_le (a : R)).trans_lt (WithBot.coe_lt_coe.mpr (show 1 < 5 by simp)) theorem natDegree_Phi : (Φ R a b).natDegree = 5 := natDegree_eq_of_degree_eq_some (degree_Phi a b) theorem leadingCoeff_Phi : (Φ R a b).leadingCoeff = 1 := by rw [Polynomial.leadingCoeff, natDegree_Phi, coeff_five_Phi] theorem monic_Phi : (Φ R a b).Monic := leadingCoeff_Phi a b theorem irreducible_Phi (p : ℕ) (hp : p.Prime) (hpa : p ∣ a) (hpb : p ∣ b) (hp2b : ¬p ^ 2 ∣ b) : Irreducible (Φ ℚ a b) := by rw [← map_Phi a b (Int.castRingHom ℚ), ← IsPrimitive.Int.irreducible_iff_irreducible_map_cast] on_goal 1 => apply irreducible_of_eisenstein_criterion · rwa [span_singleton_prime (Int.natCast_ne_zero.mpr hp.ne_zero), Int.prime_iff_natAbs_prime] · rw [leadingCoeff_Phi, mem_span_singleton] exact mod_cast mt Nat.dvd_one.mp hp.ne_one · intro n hn rw [mem_span_singleton] rw [degree_Phi] at hn; norm_cast at hn interval_cases n <;> simp +decide only [Φ, coeff_X_pow, coeff_C, Int.natCast_dvd_natCast.mpr, hpb, if_true, coeff_C_mul, if_false, coeff_X_zero, hpa, coeff_add, zero_add, mul_zero, coeff_sub, add_zero, zero_sub, dvd_neg, neg_zero, dvd_mul_of_dvd_left] · simp only [degree_Phi, ← WithBot.coe_zero] decide · rw [coeff_zero_Phi, span_singleton_pow, mem_span_singleton] exact mt Int.natCast_dvd_natCast.mp hp2b all_goals exact Monic.isPrimitive (monic_Phi a b) attribute [local simp] map_ofNat in -- use `ofNat` simp theorem with bad keys theorem real_roots_Phi_le : Fintype.card ((Φ ℚ a b).rootSet ℝ) ≤ 3 := by rw [← map_Phi a b (algebraMap ℤ ℚ), Φ, ← one_mul (X ^ 5), ← C_1] apply (card_rootSet_le_derivative _).trans (Nat.succ_le_succ ((card_rootSet_le_derivative _).trans (Nat.succ_le_succ _))) suffices (Polynomial.rootSet (C (20 : ℚ) * X ^ 3) ℝ).Subsingleton by norm_num [Fintype.card_le_one_iff_subsingleton, ← mul_assoc] at * exact this rw [rootSet_C_mul_X_pow] <;> norm_num theorem real_roots_Phi_ge_aux (hab : b < a) : ∃ x y : ℝ, x ≠ y ∧ aeval x (Φ ℚ a b) = 0 ∧ aeval y (Φ ℚ a b) = 0 := by let f : ℝ → ℝ := fun x : ℝ => aeval x (Φ ℚ a b) have hf : f = fun x : ℝ => x ^ 5 - a * x + b := by simp [f, Φ] have hc : ∀ s : Set ℝ, ContinuousOn f s := fun s => (Φ ℚ a b).continuousOn_aeval have ha : (1 : ℝ) ≤ a := Nat.one_le_cast.mpr (Nat.one_le_of_lt hab) have hle : (0 : ℝ) ≤ 1 := zero_le_one have hf0 : 0 ≤ f 0 := by simp [hf] by_cases hb : (1 : ℝ) - a + b < 0 · have hf1 : f 1 < 0 := by simp [hf, hb] have hfa : 0 ≤ f a := by simp_rw [hf, ← sq] refine add_nonneg (sub_nonneg.mpr (pow_right_mono₀ ha ?_)) ?_ <;> norm_num obtain ⟨x, ⟨-, hx1⟩, hx2⟩ := intermediate_value_Ico' hle (hc _) (Set.mem_Ioc.mpr ⟨hf1, hf0⟩) obtain ⟨y, ⟨hy1, -⟩, hy2⟩ := intermediate_value_Ioc ha (hc _) (Set.mem_Ioc.mpr ⟨hf1, hfa⟩) exact ⟨x, y, (hx1.trans hy1).ne, hx2, hy2⟩ · replace hb : (b : ℝ) = a - 1 := by linarith [show (b : ℝ) + 1 ≤ a from mod_cast hab] have hf1 : f 1 = 0 := by simp [hf, hb] have hfa := calc f (-a) = (a : ℝ) ^ 2 - (a : ℝ) ^ 5 + b := by norm_num [hf, ← sq, sub_eq_add_neg, add_comm, Odd.neg_pow (by decide : Odd 5)] _ ≤ (a : ℝ) ^ 2 - (a : ℝ) ^ 3 + (a - 1) := by gcongr <;> linarith _ = -((a : ℝ) - 1) ^ 2 * (a + 1) := by ring _ ≤ 0 := by nlinarith have ha' := neg_nonpos.mpr (hle.trans ha) obtain ⟨x, ⟨-, hx1⟩, hx2⟩ := intermediate_value_Icc ha' (hc _) (Set.mem_Icc.mpr ⟨hfa, hf0⟩) exact ⟨x, 1, (hx1.trans_lt zero_lt_one).ne, hx2, hf1⟩ theorem real_roots_Phi_ge (hab : b < a) : 2 ≤ Fintype.card ((Φ ℚ a b).rootSet ℝ) := by have q_ne_zero : Φ ℚ a b ≠ 0 := (monic_Phi a b).ne_zero obtain ⟨x, y, hxy, hx, hy⟩ := real_roots_Phi_ge_aux a b hab have key : ↑({x, y} : Finset ℝ) ⊆ (Φ ℚ a b).rootSet ℝ := by simp [Set.insert_subset, mem_rootSet_of_ne q_ne_zero, hx, hy] convert Fintype.card_le_of_embedding (Set.embeddingOfSubset _ _ key) simp only [Finset.coe_sort_coe, Fintype.card_coe, Finset.card_singleton, Finset.card_insert_of_notMem (mt Finset.mem_singleton.mp hxy)] theorem complex_roots_Phi (h : (Φ ℚ a b).Separable) : Fintype.card ((Φ ℚ a b).rootSet ℂ) = 5 := (card_rootSet_eq_natDegree h (IsAlgClosed.splits_codomain _)).trans (natDegree_Phi a b) theorem gal_Phi (hab : b < a) (h_irred : Irreducible (Φ ℚ a b)) : Bijective (galActionHom (Φ ℚ a b) ℂ) := by apply galActionHom_bijective_of_prime_degree' h_irred · simp only [natDegree_Phi]; decide · rw [complex_roots_Phi a b h_irred.separable, Nat.succ_le_succ_iff] exact (real_roots_Phi_le a b).trans (Nat.le_succ 3) · simp_rw [complex_roots_Phi a b h_irred.separable, Nat.succ_le_succ_iff] exact real_roots_Phi_ge a b hab theorem not_solvable_by_rad (p : ℕ) (x : ℂ) (hx : aeval x (Φ ℚ a b) = 0) (hab : b < a) (hp : p.Prime) (hpa : p ∣ a) (hpb : p ∣ b) (hp2b : ¬p ^ 2 ∣ b) : ¬IsSolvableByRad ℚ x := by have h_irred := irreducible_Phi a b p hp hpa hpb hp2b apply mt (solvableByRad.isSolvable' h_irred hx) intro h refine Equiv.Perm.not_solvable _ (le_of_eq ?_) (solvable_of_surjective (gal_Phi a b hab h_irred).2) rw_mod_cast [Cardinal.mk_fintype, complex_roots_Phi a b h_irred.separable] theorem not_solvable_by_rad' (x : ℂ) (hx : aeval x (Φ ℚ 4 2) = 0) : ¬IsSolvableByRad ℚ x := by apply not_solvable_by_rad 4 2 2 x hx <;> decide /-- **Abel-Ruffini Theorem** -/ theorem exists_not_solvable_by_rad : ∃ x : ℂ, IsAlgebraic ℚ x ∧ ¬IsSolvableByRad ℚ x := by obtain ⟨x, hx⟩ := exists_root_of_splits (algebraMap ℚ ℂ) (IsAlgClosed.splits_codomain (Φ ℚ 4 2)) (ne_of_eq_of_ne (degree_Phi 4 2) (mt WithBot.coe_eq_coe.mp (show 5 ≠ 0 by simp))) exact ⟨x, ⟨Φ ℚ 4 2, (monic_Phi 4 2).ne_zero, hx⟩, not_solvable_by_rad' x hx⟩ end AbelRuffini
finmodule.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 bigop ssralg finset fingroup. From mathcomp Require Import morphism perm finalg action gproduct commutator . From mathcomp Require Import cyclic. (******************************************************************************) (* This file regroups constructions and results that are based on the most *) (* primitive version of representation theory -- viewing an abelian group as *) (* the additive group of a (finite) Z-module. This includes the Gaschutz *) (* splitting and transitivity theorem, from which we will later derive the *) (* Schur-Zassenhaus theorem and the elementary abelian special case of *) (* Maschke's theorem, the coprime abelian centraliser/commutator trivial *) (* intersection theorem, which is used to show that p-groups under coprime *) (* action factor into special groups, and the construction of the transfer *) (* homomorphism and its expansion relative to a cycle, from which we derive *) (* the Higman Focal Subgroup and the Burnside Normal Complement theorems. *) (* The definitions and lemmas for the finite Z-module induced by an abelian *) (* are packaged in an auxiliary FiniteModule submodule: they should not be *) (* needed much outside this file, which contains all the results that exploit *) (* this construction. *) (* FiniteModule defines the Z[N(A)]-module associated with a finite abelian *) (* abelian group A, given a proof (abelA : abelian A) : *) (* fmod_of abelA == the type of elements of the module (similar to but *) (* distinct from [subg A]). *) (* fmod abelA x == the injection of x into fmod_of abelA if x \in A, else 0 *) (* fmval u == the projection of u : fmod_of abelA onto A *) (* u ^@ x == the action of x \in 'N(A) on u : fmod_of abelA *) (* The transfer morphism is be constructed from a morphism f : H >-> rT, and *) (* a group G, along with the two assumptions sHG : H \subset G and *) (* abfH : abelian (f @* H): *) (* transfer sGH abfH == the function gT -> FiniteModule.fmod_of abfH that *) (* implements the transfer morphism induced by f on G. *) (* The Lemma transfer_indep states that the transfer morphism can be expanded *) (* using any transversal of the partition HG := rcosets H G of G. *) (* Further, for any g \in G, HG :* <[g]> is also a partition of G (Lemma *) (* rcosets_cycle_partition), and for any transversal X of HG :* <[g]> the *) (* function r mapping x : gT to rcosets (H :* x) <[g]> is (constructively) a *) (* bijection from X to the <[g]>-orbit partition of HG, and Lemma *) (* transfer_cycle_expansion gives a simplified expansion of the transfer *) (* morphism. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope GRing.Theory FinRing.Theory. Local Open Scope ring_scope. Module FiniteModule. Reserved Notation "u ^@ x" (at level 31, left associativity). Inductive fmod_of (gT : finGroupType) (A : {group gT}) (abelA : abelian A) := Fmod x & x \in A. Bind Scope ring_scope with fmod_of. Section OneFinMod. (* TODO: understand why FinGroup has to be changed to BaseFinGroup here. *) Let f2sub (gT : finGroupType) (A : {group gT}) (abA : abelian A) := fun u : fmod_of abA => let : Fmod x Ax := u in Subg Ax : BaseFinGroup.arg_sort _. Local Coercion f2sub : fmod_of >-> BaseFinGroup.arg_sort. Variables (gT : finGroupType) (A : {group gT}) (abelA : abelian A). Local Notation fmodA := (fmod_of abelA). Implicit Types (x y z : gT) (u v w : fmodA). Let sub2f (s : [subg A]) := Fmod abelA (valP s). Definition fmval u := val (f2sub u). #[export] HB.instance Definition _ := [isSub for fmval]. Local Notation valA := (val: fmodA -> gT) (only parsing). #[export] HB.instance Definition _ := [Finite of fmodA by <:]. Definition fmod x := sub2f (subg A x). Definition actr u x := if x \in 'N(A) then fmod (fmval u ^ x) else u. Definition fmod_opp u := sub2f u^-1. Definition fmod_add u v := sub2f (u * v). Fact fmod_add0r : left_id (sub2f 1) fmod_add. Proof. by move=> u; apply: val_inj; apply: mul1g. Qed. Fact fmod_addrA : associative fmod_add. Proof. by move=> u v w; apply: val_inj; apply: mulgA. Qed. Fact fmod_addNr : left_inverse (sub2f 1) fmod_opp fmod_add. Proof. by move=> u; apply: val_inj; apply: mulVg. Qed. Fact fmod_addrC : commutative fmod_add. Proof. by case=> x Ax [y Ay]; apply: val_inj; apply: (centsP abelA). Qed. #[export] HB.instance Definition _ := GRing.isZmodule.Build fmodA fmod_addrA fmod_addrC fmod_add0r fmod_addNr. (* TODO: Should isZmodule and the like be exported from ssralg *) #[export] HB.instance Definition _ := [finGroupMixin of fmodA for +%R]. Lemma fmodP u : val u \in A. Proof. exact: valP. Qed. Lemma fmod_inj : injective fmval. Proof. exact: val_inj. Qed. Lemma congr_fmod u v : u = v -> fmval u = fmval v. Proof. exact: congr1. Qed. Lemma fmvalA : {morph valA : x y / x + y >-> (x * y)%g}. Proof. by []. Qed. Lemma fmvalN : {morph valA : x / - x >-> x^-1%g}. Proof. by []. Qed. Lemma fmval0 : valA 0 = 1%g. Proof. by []. Qed. Canonical fmval_morphism := @Morphism _ _ setT fmval (in2W fmvalA). Definition fmval_sum := big_morph fmval fmvalA fmval0. Lemma fmvalZ n : {morph valA : x / x *+ n >-> (x ^+ n)%g}. Proof. by move=> u; rewrite /= morphX ?inE. Qed. Lemma fmodKcond x : val (fmod x) = if x \in A then x else 1%g. Proof. by rewrite /= /fmval /= val_insubd. Qed. Lemma fmodK : {in A, cancel fmod val}. Proof. exact: subgK. Qed. Lemma fmvalK : cancel val fmod. Proof. by case=> x Ax; apply: val_inj; rewrite /fmod /= sgvalK. Qed. Lemma fmod1 : fmod 1 = 0. Proof. by rewrite -fmval0 fmvalK. Qed. Lemma fmodM : {in A &, {morph fmod : x y / (x * y)%g >-> x + y}}. Proof. by move=> x y Ax Ay /=; apply: val_inj; rewrite /fmod morphM. Qed. Canonical fmod_morphism := Morphism fmodM. Lemma fmodX n : {in A, {morph fmod : x / (x ^+ n)%g >-> x *+ n}}. Proof. exact: morphX. Qed. Lemma fmodV : {morph fmod : x / x^-1%g >-> - x}. Proof. move=> x; apply: val_inj; rewrite fmvalN !fmodKcond groupV. by case: (x \in A); rewrite ?invg1. Qed. Lemma injm_fmod : 'injm fmod. Proof. by apply/injmP=> x y Ax Ay []; move/val_inj; apply: (injmP (injm_subg A)). Qed. Notation "u ^@ x" := (actr u x) : ring_scope. Lemma fmvalJcond u x : val (u ^@ x) = if x \in 'N(A) then val u ^ x else val u. Proof. by case: ifP => Nx; rewrite /actr Nx ?fmodK // memJ_norm ?fmodP. Qed. Lemma fmvalJ u x : x \in 'N(A) -> val (u ^@ x) = val u ^ x. Proof. by move=> Nx; rewrite fmvalJcond Nx. Qed. Lemma fmodJ x y : y \in 'N(A) -> fmod (x ^ y) = fmod x ^@ y. Proof. move=> Ny; apply: val_inj; rewrite fmvalJ ?fmodKcond ?memJ_norm //. by case: ifP => // _; rewrite conj1g. Qed. Fact actr_is_action : is_action 'N(A) actr. Proof. split=> [a u v eq_uv_a | u a b Na Nb]. case Na: (a \in 'N(A)); last by rewrite /actr Na in eq_uv_a. by apply: val_inj; apply: (conjg_inj a); rewrite -!fmvalJ ?eq_uv_a. by apply: val_inj; rewrite !fmvalJ ?groupM ?conjgM. Qed. Canonical actr_action := Action actr_is_action. Notation "''M'" := actr_action : action_scope. Lemma act0r x : 0 ^@ x = 0. Proof. by rewrite /actr conj1g morph1 if_same. Qed. Lemma actAr x : {morph actr^~ x : u v / u + v}. Proof. by move=> u v; apply: val_inj; rewrite !(fmvalA, fmvalJcond) conjMg; case: ifP. Qed. Definition actr_sum x := big_morph _ (actAr x) (act0r x). Lemma actNr x : {morph actr^~ x : u / - u}. Proof. by move=> u; apply: (addrI (u ^@ x)); rewrite -actAr !subrr act0r. Qed. Lemma actZr x n : {morph actr^~ x : u / u *+ n}. Proof. by move=> u; elim: n => [|n IHn]; rewrite ?act0r // !mulrS actAr IHn. Qed. Fact actr_is_groupAction : is_groupAction setT 'M. Proof. move=> a Na /[1!inE]; apply/andP; split; first by apply/subsetP=> u _ /[1!inE]. by apply/morphicP=> u v _ _; rewrite !permE /= actAr. Qed. Canonical actr_groupAction := GroupAction actr_is_groupAction. Notation "''M'" := actr_groupAction : groupAction_scope. Lemma actr1 u : u ^@ 1 = u. Proof. exact: act1. Qed. Lemma actrM : {in 'N(A) &, forall x y u, u ^@ (x * y) = u ^@ x ^@ y}. Proof. by move=> x y Nx Ny /= u; apply: val_inj; rewrite !fmvalJ ?conjgM ?groupM. Qed. Lemma actrK x : cancel (actr^~ x) (actr^~ x^-1%g). Proof. move=> u; apply: val_inj; rewrite !fmvalJcond groupV. by case: ifP => -> //; rewrite conjgK. Qed. Lemma actrKV x : cancel (actr^~ x^-1%g) (actr^~ x). Proof. by move=> u; rewrite /= -{2}(invgK x) actrK. Qed. End OneFinMod. Bind Scope ring_scope with fmod_of. Prenex Implicits fmval fmod actr. Notation "u ^@ x" := (actr u x) : ring_scope. Notation "''M'" := actr_action : action_scope. Notation "''M'" := actr_groupAction : groupAction_scope. Module Exports. HB.reexport FiniteModule. End Exports. End FiniteModule. HB.export FiniteModule.Exports. Arguments FiniteModule.fmodK {gT A} abelA [x] Ax. Arguments FiniteModule.fmvalK {gT A abelA} x. Arguments FiniteModule.actrK {gT A abelA} x. Arguments FiniteModule.actrKV {gT A abelA} x. (* Still allow ring notations, but give priority to groups now. *) Import FiniteModule GroupScope. Section Gaschutz. Variables (gT : finGroupType) (G H P : {group gT}). Implicit Types K L : {group gT}. Hypotheses (nsHG : H <| G) (sHP : H \subset P) (sPG : P \subset G). Hypotheses (abelH : abelian H) (coHiPG : coprime #|H| #|G : P|). Let sHG := normal_sub nsHG. Let nHG := subsetP (normal_norm nsHG). Let m := (expg_invn H #|G : P|). Implicit Types a b : fmod_of abelH. Local Notation fmod := (fmod abelH). Theorem Gaschutz_split : [splits G, over H] = [splits P, over H]. Proof. apply/splitsP/splitsP=> [[K /complP[tiHK eqHK]] | [Q /complP[tiHQ eqHQ]]]. exists (K :&: P)%G; rewrite inE setICA (setIidPl sHP) setIC tiHK eqxx. by rewrite group_modl // eqHK (sameP eqP setIidPr). have sQP: Q \subset P by rewrite -eqHQ mulG_subr. pose rP x := repr (P :* x); pose pP x := x * (rP x)^-1. have PpP x: pP x \in P by rewrite -mem_rcoset rcoset_repr rcoset_refl. have rPmul x y: x \in P -> rP (x * y) = rP y. by move=> Px; rewrite /rP rcosetM rcoset_id. pose pQ x := remgr H Q x; pose rH x := pQ (pP x) * rP x. have pQhq: {in H & Q, forall h q, pQ (h * q) = q} by apply: remgrMid. have pQmul: {in P &, {morph pQ : x y / x * y}}. by apply: remgrM; [apply/complP | apply: normalS (nsHG)]. have HrH x: rH x \in H :* x. by rewrite rcoset_sym mem_rcoset invMg mulgA mem_divgr // eqHQ PpP. have GrH x: x \in G -> rH x \in G. move=> Gx; case/rcosetP: (HrH x) => y Hy ->. by rewrite groupM // (subsetP sHG). have rH_Pmul x y: x \in P -> rH (x * y) = pQ x * rH y. by move=> Px; rewrite /rH mulgA -pQmul; first by rewrite /pP rPmul ?mulgA. have rH_Hmul h y: h \in H -> rH (h * y) = rH y. by move=> Hh; rewrite rH_Pmul ?(subsetP sHP) // -(mulg1 h) pQhq ?mul1g. pose mu x y := fmod ((rH x * rH y)^-1 * rH (x * y)). pose nu y := (\sum_(Px in rcosets P G) mu (repr Px) y)%R. have rHmul: {in G &, forall x y, rH (x * y) = rH x * rH y * val (mu x y)}. move=> x y Gx Gy; rewrite /= fmodK ?mulKVg // -mem_lcoset lcoset_sym. rewrite -norm_rlcoset; last by rewrite nHG ?GrH ?groupM. by rewrite (rcoset_eqP (HrH _)) -rcoset_mul ?nHG ?GrH // mem_mulg. have actrH a x: x \in G -> (a ^@ rH x = a ^@ x)%R. move=> Gx; apply: val_inj; rewrite /= !fmvalJ ?nHG ?GrH //. case/rcosetP: (HrH x) => b /(fmodK abelH) <- ->; rewrite conjgM. by congr (_ ^ _); rewrite conjgE -fmvalN -!fmvalA (addrC a) addKr. have mu_Pmul x y z: x \in P -> mu (x * y) z = mu y z. move=> Px; congr fmod; rewrite -mulgA !(rH_Pmul x) ?rPmul //. by rewrite -mulgA invMg -mulgA mulKg. have mu_Hmul x y z: x \in G -> y \in H -> mu x (y * z) = mu x z. move=> Gx Hy; congr fmod; rewrite (mulgA x) (conjgCV x) -mulgA 2?rH_Hmul //. by rewrite -mem_conjg (normP _) ?nHG. have{mu_Hmul} nu_Hmul y z: y \in H -> nu (y * z) = nu z. move=> Hy; apply: eq_bigr => _ /rcosetsP[x Gx ->]; apply: mu_Hmul y z _ Hy. by rewrite -(groupMl _ (subsetP sPG _ (PpP x))) mulgKV. have cocycle_mu: {in G & &, forall x y z, mu (x * y)%g z + mu x y ^@ z = mu y z + mu x (y * z)%g}%R. - move=> x y z Gx Gy Gz; apply: val_inj. apply: (mulgI (rH x * rH y * rH z)). rewrite -(actrH _ _ Gz) addrC [in LHS]fmvalA fmvalJ ?nHG ?GrH //. rewrite mulgA -(mulgA _ (rH z)) -conjgC mulgA -!rHmul ?groupM //. by rewrite mulgA -mulgA -2!(mulgA (rH x)) -!rHmul ?groupM. move: mu => mu in rHmul mu_Pmul cocycle_mu nu nu_Hmul. have{cocycle_mu} cocycle_nu: {in G &, forall y z, nu z + nu y ^@ z = mu y z *+ #|G : P| + nu (y * z)%g}%R. - move=> y z Gy Gz; rewrite /= (actr_sum z) /=. have ->: (nu z = \sum_(Px in rcosets P G) mu (repr Px * y)%g z)%R. rewrite /nu (reindex_acts _ (actsRs_rcosets P G) Gy) /=. apply: eq_bigr => _ /rcosetsP[x Gx /= ->]. rewrite rcosetE -rcosetM. case: repr_rcosetP=> p1 Pp1; case: repr_rcosetP=> p2 Pp2. by rewrite -mulgA [x * y]lock !mu_Pmul. rewrite -sumr_const -!big_split /=; apply: eq_bigr => _ /rcosetsP[x Gx ->]. rewrite -cocycle_mu //; case: repr_rcosetP => p1 Pp1. by rewrite groupMr // (subsetP sPG). move: nu => nu in nu_Hmul cocycle_nu. pose f x := rH x * val (nu x *+ m)%R. have{cocycle_nu} fM: {in G &, {morph f : x y / x * y}}. move=> x y Gx Gy; rewrite /f ?rHmul // -3!mulgA; congr (_ * _). rewrite (mulgA _ (rH y)) (conjgC _ (rH y)) -mulgA; congr (_ * _). rewrite -fmvalJ ?actrH ?nHG ?GrH // -!fmvalA actZr -mulrnDl. rewrite -(addrC (nu y)) cocycle_nu // mulrnDl !fmvalA; congr (_ * _). by rewrite !fmvalZ expgK ?fmodP. exists (Morphism fM @* G)%G; apply/complP; split. apply/trivgP/subsetP=> x /setIP[Hx /morphimP[y _ Gy eq_x]]. apply/set1P; move: Hx; rewrite {x}eq_x /= groupMr ?subgP //. rewrite -{1}(mulgKV y (rH y)) groupMl -?mem_rcoset // => Hy. by rewrite -(mulg1 y) /f nu_Hmul // rH_Hmul //; apply: (morph1 (Morphism fM)). apply/setP=> x; apply/mulsgP/idP=> [[h y Hh fy ->{x}] | Gx]. rewrite groupMl; last exact: (subsetP sHG). case/morphimP: fy => z _ Gz ->{h Hh y}. by rewrite /= /f groupMl ?GrH // (subsetP sHG) ?fmodP. exists (x * (f x)^-1) (f x); last first; first by rewrite mulgKV. by apply/morphimP; exists x. rewrite -groupV invMg invgK -mulgA (conjgC (val _)) mulgA. by rewrite groupMl -(mem_rcoset, mem_conjg) // (normP _) ?nHG ?fmodP. Qed. Theorem Gaschutz_transitive : {in [complements to H in G] &, forall K L, K :&: P = L :&: P -> exists2 x, x \in H & L :=: K :^ x}. Proof. move=> K L /=; set Q := K :&: P => /complP[tiHK eqHK] cpHL QeqLP. have [trHL eqHL] := complP cpHL. pose nu x := fmod (divgr H L x^-1). have sKG: {subset K <= G} by apply/subsetP; rewrite -eqHK mulG_subr. have sLG: {subset L <= G} by apply/subsetP; rewrite -eqHL mulG_subr. have val_nu x: x \in G -> val (nu x) = divgr H L x^-1. by move=> Gx; rewrite fmodK // mem_divgr // eqHL groupV. have nu_cocycle: {in G &, forall x y, nu (x * y)%g = nu x ^@ y + nu y}%R. move=> x y Gx Gy; apply: val_inj; rewrite fmvalA fmvalJ ?nHG //. rewrite !val_nu ?groupM // /divgr conjgE !mulgA mulgK. by rewrite !(invMg, remgrM cpHL) ?groupV ?mulgA. have nuL x: x \in L -> nu x = 0%R. move=> Lx; apply: val_inj; rewrite val_nu ?sLG //. by rewrite /divgr remgr_id ?groupV ?mulgV. exists (fmval ((\sum_(X in rcosets Q K) nu (repr X)) *+ m)). exact: fmodP. apply/eqP; rewrite eq_sym eqEcard; apply/andP; split; last first. by rewrite cardJg -(leq_pmul2l (cardG_gt0 H)) -!TI_cardMg // eqHL eqHK. apply/subsetP=> _ /imsetP[x Kx ->]; rewrite conjgE mulgA (conjgC _ x). have Gx: x \in G by rewrite sKG. rewrite conjVg -mulgA -fmvalJ ?nHG // -fmvalN -fmvalA (_ : _ + _ = nu x)%R. by rewrite val_nu // mulKVg groupV mem_remgr // eqHL groupV. rewrite actZr -!mulNrn -mulrnDl actr_sum. rewrite addrC (reindex_acts _ (actsRs_rcosets _ K) Kx) -sumrB /= -/Q. rewrite (eq_bigr (fun _ => nu x)) => [|_ /imsetP[y Ky ->]]; last first. rewrite !rcosetE -rcosetM QeqLP. case: repr_rcosetP => z /setIP[Lz _]; case: repr_rcosetP => t /setIP[Lt _]. rewrite !nu_cocycle ?groupM ?(sKG y) // ?sLG //. by rewrite (nuL z) ?(nuL t) // !act0r !add0r addrC addKr. apply: val_inj; rewrite sumr_const !fmvalZ. rewrite -{2}(expgK coHiPG (fmodP (nu x))); congr (_ ^+ _ ^+ _). rewrite -[#|_|]divgS ?subsetIl // -(divnMl (cardG_gt0 H)). rewrite -!TI_cardMg //; last by rewrite setIA setIAC (setIidPl sHP). by rewrite group_modl // eqHK (setIidPr sPG) divgS. Qed. End Gaschutz. (* This is the TI part of B & G, Proposition 1.6(d). *) (* We go with B & G rather than Aschbacher and will derive 1.6(e) from (d), *) (* rather than the converse, because the derivation of 24.6 from 24.3 in *) (* Aschbacher requires a separate reduction to p-groups to yield 1.6(d), *) (* making it altogether longer than the direct Gaschutz-style proof. *) (* This Lemma is used in maximal.v for the proof of Aschbacher 24.7. *) Lemma coprime_abel_cent_TI (gT : finGroupType) (A G : {group gT}) : A \subset 'N(G) -> coprime #|G| #|A| -> abelian G -> 'C_[~: G, A](A) = 1. Proof. move=> nGA coGA abG; pose f x := val (\sum_(a in A) fmod abG x ^@ a)%R. have fM: {in G &, {morph f : x y / x * y}}. move=> x y Gx Gy /=; rewrite -fmvalA -big_split /=; congr (fmval _). by apply: eq_bigr => a Aa; rewrite fmodM // actAr. have nfA x a: a \in A -> f (x ^ a) = f x. move=> Aa; rewrite {2}/f (reindex_inj (mulgI a)) /=; congr (fmval _). apply: eq_big => [b | b Ab]; first by rewrite groupMl. by rewrite -!fmodJ ?groupM ?(subsetP nGA) // conjgM. have kerR: [~: G, A] \subset 'ker (Morphism fM). rewrite gen_subG; apply/subsetP=> xa; case/imset2P=> x a Gx Aa -> {xa}. have Gxa: x ^ a \in G by rewrite memJ_norm ?(subsetP nGA). rewrite commgEl; apply/kerP; rewrite (groupM, morphM) ?(groupV, morphV) //=. by rewrite nfA ?mulVg. apply/trivgP; apply/subsetP=> x /setIP[Rx cAx]; apply/set1P. have Gx: x \in G by apply: subsetP Rx; rewrite commg_subl. rewrite -(expgK coGA Gx) (_ : x ^+ _ = 1) ?expg1n //. rewrite -(fmodK abG Gx) -fmvalZ -(mker (subsetP kerR x Rx)); congr fmval. rewrite -GRing.sumr_const; apply: eq_bigr => a Aa. by rewrite -fmodJ ?(subsetP nGA) // /conjg (centP cAx) // mulKg. Qed. Section Transfer. Variables (gT aT : finGroupType) (G H : {group gT}). Variable alpha : {morphism H >-> aT}. Hypotheses (sHG : H \subset G) (abelA : abelian (alpha @* H)). Local Notation HG := (rcosets (gval H) (gval G)). Fact transfer_morph_subproof : H \subset alpha @*^-1 (alpha @* H). Proof. by rewrite -sub_morphim_pre. Qed. Let fmalpha := restrm transfer_morph_subproof (fmod abelA \o alpha). Let V (rX : {set gT} -> gT) g := \sum_(Hx in rcosets H G) fmalpha (rX Hx * g * (rX (Hx :* g))^-1). Definition transfer g := V repr g. (* This is Aschbacher (37.2). *) Lemma transferM : {in G &, {morph transfer : x y / (x * y)%g >-> x + y}}. Proof. move=> s t Gs Gt /=. rewrite [transfer t](reindex_acts 'Rs _ Gs) ?actsRs_rcosets //= -big_split /=. apply: eq_bigr => _ /rcosetsP[x Gx ->]; rewrite !rcosetE -!rcosetM. rewrite -zmodMgE -morphM -?mem_rcoset; first by rewrite !mulgA mulgKV rcosetM. by rewrite rcoset_repr rcosetM mem_rcoset mulgK mem_repr_rcoset. by rewrite rcoset_repr (rcosetM _ _ t) mem_rcoset mulgK mem_repr_rcoset. Qed. Canonical transfer_morphism := Morphism transferM. (* This is Aschbacher (37.1). *) Lemma transfer_indep X (rX := transversal_repr 1 X) : is_transversal X HG G -> {in G, transfer =1 V rX}. Proof. move=> trX g Gg; have mem_rX := repr_mem_pblock trX 1; rewrite -/rX in mem_rX. apply: (addrI (\sum_(Hx in HG) fmalpha (repr Hx * (rX Hx)^-1))). rewrite {1}(reindex_acts 'Rs _ Gg) ?actsRs_rcosets // -!big_split /=. apply: eq_bigr => _ /rcosetsP[x Gx ->]; rewrite !rcosetE -!rcosetM. case: repr_rcosetP => h1 Hh1; case: repr_rcosetP => h2 Hh2. have: H :* (x * g) \in rcosets H G by rewrite -rcosetE imset_f ?groupM. have: H :* x \in rcosets H G by rewrite -rcosetE imset_f. case/mem_rX/rcosetP=> h3 Hh3 -> /mem_rX/rcosetP[h4 Hh4 ->]. rewrite -!(mulgA h1) -!(mulgA h2) -!(mulgA h3) !(mulKVg, invMg). by rewrite addrC -!zmodMgE -!morphM ?groupM ?groupV // -!mulgA !mulKg. Qed. Section FactorTransfer. Variable g : gT. Hypothesis Gg : g \in G. Let sgG : <[g]> \subset G. Proof. by rewrite cycle_subG. Qed. Let H_g_rcosets x : {set {set gT}} := rcosets (H :* x) <[g]>. Let n_ x := #|<[g]> : H :* x|. Lemma mulg_exp_card_rcosets x : x * (g ^+ n_ x) \in H :* x. Proof. rewrite /n_ /indexg -orbitRs -porbit_actperm ?inE //. rewrite -{2}(iter_porbit (actperm 'Rs g) (H :* x)) -permX -morphX ?inE //. by rewrite actpermE //= rcosetE -rcosetM rcoset_refl. Qed. Let HGg : {set {set {set gT}}} := orbit 'Rs <[g]> @: HG. Let partHG : partition HG G := rcosets_partition sHG. Let actsgHG : [acts <[g]>, on HG | 'Rs]. Proof. exact: subset_trans sgG (actsRs_rcosets H G). Qed. Let partHGg : partition HGg HG := orbit_partition actsgHG. Let injHGg : {in HGg &, injective cover}. Proof. by have [] := partition_partition partHG partHGg. Qed. Let defHGg : HG :* <[g]> = cover @: HGg. Proof. rewrite -imset_comp [_ :* _]imset2_set1r; apply: eq_imset => Hx /=. by rewrite cover_imset -curry_imset2r. Qed. Lemma rcosets_cycle_partition : partition (HG :* <[g]>) G. Proof. by rewrite defHGg; have [] := partition_partition partHG partHGg. Qed. Variable X : {set gT}. Hypothesis trX : is_transversal X (HG :* <[g]>) G. Let sXG : {subset X <= G}. Proof. exact/subsetP/(transversal_sub trX). Qed. Lemma rcosets_cycle_transversal : H_g_rcosets @: X = HGg. Proof. have sHXgHGg x: x \in X -> H_g_rcosets x \in HGg. by move/sXG=> Gx; apply: imset_f; rewrite -rcosetE imset_f. apply/setP=> Hxg; apply/imsetP/idP=> [[x /sHXgHGg HGgHxg -> //] | HGgHxg]. have [_ /rcosetsP[z Gz ->] ->] := imsetP HGgHxg. pose Hzg := H :* z * <[g]>; pose x := transversal_repr 1 X Hzg. have HGgHzg: Hzg \in HG :* <[g]>. by rewrite mem_mulg ?set11 // -rcosetE imset_f. have Hzg_x: x \in Hzg by rewrite (repr_mem_pblock trX). exists x; first by rewrite (repr_mem_transversal trX). case/mulsgP: Hzg_x => y u /rcoset_eqP <- /(orbit_act 'Rs) <- -> /=. by rewrite rcosetE -rcosetM. Qed. Local Notation defHgX := rcosets_cycle_transversal. Let injHg: {in X &, injective H_g_rcosets}. Proof. apply/imset_injP; rewrite defHgX (card_transversal trX) defHGg. by rewrite (card_in_imset injHGg). Qed. Lemma sum_index_rcosets_cycle : (\sum_(x in X) n_ x)%N = #|G : H|. Proof. by rewrite [#|G : H|](card_partition partHGg) -defHgX big_imset. Qed. Lemma transfer_cycle_expansion : transfer g = \sum_(x in X) fmalpha ((g ^+ n_ x) ^ (x^-1)). Proof. pose Y := \bigcup_(x in X) [set x * g ^+ i | i : 'I_(n_ x)]. pose rY := transversal_repr 1 Y. pose pcyc x := porbit (actperm 'Rs g) (H :* x). pose traj x := traject (actperm 'Rs g) (H :* x) #|pcyc x|. have Hgr_eq x: H_g_rcosets x = pcyc x. by rewrite /H_g_rcosets -orbitRs -porbit_actperm ?inE. have pcyc_eq x: pcyc x =i traj x by apply: porbit_traject. have uniq_traj x: uniq (traj x) by apply: uniq_traject_porbit. have n_eq x: n_ x = #|pcyc x| by rewrite -Hgr_eq. have size_traj x: size (traj x) = n_ x by rewrite n_eq size_traject. have nth_traj x j: j < n_ x -> nth (H :* x) (traj x) j = H :* (x * g ^+ j). move=> lt_j_x; rewrite nth_traject -?n_eq //. by rewrite -permX -morphX ?inE // actpermE //= rcosetE rcosetM. have sYG: Y \subset G. apply/bigcupsP=> x Xx; apply/subsetP=> _ /imsetP[i _ ->]. by rewrite groupM ?groupX // sXG. have trY: is_transversal Y HG G. apply/and3P; split=> //; apply/forall_inP=> Hy. have /and3P[/eqP <- _ _] := partHGg; rewrite -defHgX cover_imset. case/bigcupP=> x Xx; rewrite Hgr_eq pcyc_eq => /trajectP[i]. rewrite -n_eq -permX -morphX ?in_setT // actpermE /= rcosetE -rcosetM => lti. set y := x * _ => ->{Hy}; pose oi := Ordinal lti. have Yy: y \in Y by apply/bigcupP; exists x => //; apply/imsetP; exists oi. apply/cards1P; exists y; apply/esym/eqP. rewrite eqEsubset sub1set inE Yy rcoset_refl. apply/subsetP=> _ /setIP[/bigcupP[x' Xx' /imsetP[j _ ->]] Hy_x'gj]. have eq_xx': x = x'. apply: (pblock_inj trX) => //; have /andP[/and3P[_ tiX _] _] := trX. have HGgHyg: H :* y * <[g]> \in HG :* <[g]>. by rewrite mem_mulg ?set11 // -rcosetE imset_f ?(subsetP sYG). rewrite !(def_pblock tiX HGgHyg) //. by rewrite -[x'](mulgK (g ^+ j)) mem_mulg // groupV mem_cycle. by rewrite -[x](mulgK (g ^+ i)) mem_mulg ?rcoset_refl // groupV mem_cycle. apply/set1P; rewrite /y eq_xx'; congr (_ * _ ^+ _) => //; apply/eqP. rewrite -(@nth_uniq _ (H :* x) (traj x)) ?size_traj // ?eq_xx' //. by rewrite !nth_traj ?(rcoset_eqP Hy_x'gj) // -eq_xx'. have rYE x i : x \in X -> i < n_ x -> rY (H :* x :* g ^+ i) = x * g ^+ i. move=> Xx lt_i_x; rewrite -rcosetM; apply: (canLR_in (pblockK trY 1)). by apply/bigcupP; exists x => //; apply/imsetP; exists (Ordinal lt_i_x). apply/esym/def_pblock; last exact: rcoset_refl; first by case/and3P: partHG. by rewrite -rcosetE imset_f ?groupM ?groupX // sXG. rewrite (transfer_indep trY Gg) /V -/rY (set_partition_big _ partHGg) /=. rewrite -defHgX big_imset /=; last first. apply/imset_injP; rewrite defHgX (card_transversal trX) defHGg. by rewrite (card_in_imset injHGg). apply eq_bigr=> x Xx; rewrite Hgr_eq (eq_bigl _ _ (pcyc_eq x)) -big_uniq //=. have n_gt0: 0 < n_ x by rewrite indexg_gt0. rewrite /traj -n_eq; case def_n: (n_ x) (n_gt0) => // [n] _. rewrite conjgE invgK -{1}[H :* x]rcoset1 -{1}(expg0 g). elim: {1 3}n 0%N (addn0 n) => [|m IHm] i def_i /=. rewrite big_seq1 {i}[i]def_i rYE // ?def_n //. rewrite -(mulgA _ _ g) -rcosetM -expgSr -[(H :* x) :* _]rcosetE. rewrite -actpermE morphX ?inE // permX // -{2}def_n n_eq iter_porbit mulgA. by rewrite -[H :* x]rcoset1 (rYE _ 0) ?mulg1. rewrite big_cons rYE //; last by rewrite def_n -def_i ltnS leq_addl. rewrite permE /= rcosetE -rcosetM -(mulgA _ _ g) -expgSr. rewrite addSnnS in def_i; rewrite IHm //. rewrite rYE //; last by rewrite def_n -def_i ltnS leq_addl. by rewrite mulgV [fmalpha 1]morph1 add0r. Qed. End FactorTransfer. End Transfer.
Matrix.lean
/- Copyright (c) 2025 Bryan Wang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bryan Wang -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Diagonal import Mathlib.Algebra.Algebra.Subalgebra.Basic /-! # Matrix subalgebras In this file we define the subalgebra of square matrices with entries in some subalgebra. ## Main definitions * `Subalgebra.matrix`: the subalgebra of square matrices with entries in some subalgebra. -/ open Matrix open Algebra namespace Subalgebra variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable {n : Type*} [Fintype n] [DecidableEq n] /-- A version of `Set.matrix` for `Subalgebra`s. Given a `Subalgebra` `S`, `S.matrix` is the `Subalgebra` of square matrices `m` all of whose entries `m i j` belong to `S`. -/ @[simps!] def matrix (S : Subalgebra R A) : Subalgebra R (Matrix n n A) where __ := S.toSubsemiring.matrix algebraMap_mem' _ := (diagonal_mem_matrix_iff (Subalgebra.zero_mem _)).mpr (fun _ => Subalgebra.algebraMap_mem _ _) end Subalgebra
Kernels.lean
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Johan Commelin, Kim Morrison -/ import Mathlib.Analysis.Normed.Group.SemiNormedGrp import Mathlib.Analysis.Normed.Group.Quotient import Mathlib.CategoryTheory.Limits.Shapes.Kernels /-! # Kernels and cokernels in SemiNormedGrp₁ and SemiNormedGrp We show that `SemiNormedGrp₁` has cokernels (for which of course the `cokernel.π f` maps are norm non-increasing), as well as the easier result that `SemiNormedGrp` has cokernels. We also show that `SemiNormedGrp` has kernels. So far, I don't see a way to state nicely what we really want: `SemiNormedGrp` has cokernels, and `cokernel.π f` is norm non-increasing. The problem is that the limits API doesn't promise you any particular model of the cokernel, and in `SemiNormedGrp` one can always take a cokernel and rescale its norm (and hence making `cokernel.π f` arbitrarily large in norm), obtaining another categorical cokernel. -/ open CategoryTheory CategoryTheory.Limits universe u namespace SemiNormedGrp₁ noncomputable section /-- Auxiliary definition for `HasCokernels SemiNormedGrp₁`. -/ def cokernelCocone {X Y : SemiNormedGrp₁.{u}} (f : X ⟶ Y) : Cofork f 0 := Cofork.ofπ (@SemiNormedGrp₁.mkHom _ (Y ⧸ NormedAddGroupHom.range f.1) _ _ f.hom.1.range.normedMk (NormedAddGroupHom.isQuotientQuotient _).norm_le) (by ext x -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5026): was -- simp only [ConcreteCategory.comp_apply, Limits.zero_comp, NormedAddGroupHom.zero_apply, -- SemiNormedGrp₁.mkHom_apply, SemiNormedGrp₁.zero_apply, -- ← NormedAddGroupHom.mem_ker, f.1.range.ker_normedMk, f.1.mem_range] rw [Limits.zero_comp, comp_apply, SemiNormedGrp₁.mkHom_apply, SemiNormedGrp₁.zero_apply, ← NormedAddGroupHom.mem_ker, f.hom.1.range.ker_normedMk, f.hom.1.mem_range] use x) /-- Auxiliary definition for `HasCokernels SemiNormedGrp₁`. -/ def cokernelLift {X Y : SemiNormedGrp₁.{u}} (f : X ⟶ Y) (s : CokernelCofork f) : (cokernelCocone f).pt ⟶ s.pt := by fconstructor -- The lift itself: · apply NormedAddGroupHom.lift _ s.π.1 rintro _ ⟨b, rfl⟩ change (f ≫ s.π) b = 0 simp -- The lift has norm at most one: exact NormedAddGroupHom.lift_normNoninc _ _ _ s.π.2 instance : HasCokernels SemiNormedGrp₁.{u} where has_colimit f := HasColimit.mk { cocone := cokernelCocone f isColimit := isColimitAux _ (cokernelLift f) (fun s => by ext apply NormedAddGroupHom.lift_mk f.1.range rintro _ ⟨b, rfl⟩ change (f ≫ s.π) b = 0 simp) fun _ _ w => SemiNormedGrp₁.hom_ext <| Subtype.eq (NormedAddGroupHom.lift_unique f.1.range _ _ _ (congr_arg Subtype.val (congr_arg Hom.hom w))) } -- Sanity check example : HasCokernels SemiNormedGrp₁ := by infer_instance end end SemiNormedGrp₁ namespace SemiNormedGrp section EqualizersAndKernels noncomputable instance {V W : SemiNormedGrp.{u}} : Norm (V ⟶ W) where norm f := norm f.hom noncomputable instance {V W : SemiNormedGrp.{u}} : NNNorm (V ⟶ W) where nnnorm f := nnnorm f.hom /-- The equalizer cone for a parallel pair of morphisms of seminormed groups. -/ def fork {V W : SemiNormedGrp.{u}} (f g : V ⟶ W) : Fork f g := @Fork.ofι _ _ _ _ _ _ (of (f - g).hom.ker) (ofHom (NormedAddGroupHom.incl (f - g).hom.ker)) <| by ext v have : v.1 ∈ (f - g).hom.ker := v.2 simpa [-SetLike.coe_mem, NormedAddGroupHom.mem_ker, sub_eq_zero] using this instance hasLimit_parallelPair {V W : SemiNormedGrp.{u}} (f g : V ⟶ W) : HasLimit (parallelPair f g) where exists_limit := Nonempty.intro { cone := fork f g isLimit := have this := fun (c : Fork f g) => show NormedAddGroupHom.compHom (f - g).hom c.ι.hom = 0 by rw [hom_sub, AddMonoidHom.map_sub, AddMonoidHom.sub_apply, sub_eq_zero] exact congr_arg Hom.hom c.condition Fork.IsLimit.mk _ (fun c => ofHom <| NormedAddGroupHom.ker.lift (Fork.ι c).hom _ <| this c) (fun _ => SemiNormedGrp.hom_ext <| NormedAddGroupHom.ker.incl_comp_lift _ _ (this _)) fun c g h => by ext x; dsimp; simp_rw [← h]; rfl} instance : Limits.HasEqualizers.{u, u + 1} SemiNormedGrp := @hasEqualizers_of_hasLimit_parallelPair SemiNormedGrp _ fun {_ _ f g} => SemiNormedGrp.hasLimit_parallelPair f g end EqualizersAndKernels section Cokernel -- PROJECT: can we reuse the work to construct cokernels in `SemiNormedGrp₁` here? -- I don't see a way to do this that is less work than just repeating the relevant parts. /-- Auxiliary definition for `HasCokernels SemiNormedGrp`. -/ noncomputable def cokernelCocone {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : Cofork f 0 := Cofork.ofπ (P := SemiNormedGrp.of (Y ⧸ NormedAddGroupHom.range f.hom)) (ofHom f.hom.range.normedMk) (by aesop) /-- Auxiliary definition for `HasCokernels SemiNormedGrp`. -/ noncomputable def cokernelLift {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) (s : CokernelCofork f) : (cokernelCocone f).pt ⟶ s.pt := ofHom <| NormedAddGroupHom.lift _ s.π.hom (by rintro _ ⟨b, rfl⟩ change (f ≫ s.π) b = 0 simp) /-- Auxiliary definition for `HasCokernels SemiNormedGrp`. -/ noncomputable def isColimitCokernelCocone {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : IsColimit (cokernelCocone f) := isColimitAux _ (cokernelLift f) (fun s => by ext apply NormedAddGroupHom.lift_mk f.hom.range rintro _ ⟨b, rfl⟩ change (f ≫ s.π) b = 0 simp) fun _ _ w => SemiNormedGrp.hom_ext <| NormedAddGroupHom.lift_unique f.hom.range _ _ _ <| congr_arg Hom.hom w instance : HasCokernels SemiNormedGrp.{u} where has_colimit f := HasColimit.mk { cocone := cokernelCocone f isColimit := isColimitCokernelCocone f } -- Sanity check example : HasCokernels SemiNormedGrp := by infer_instance section ExplicitCokernel /-- An explicit choice of cokernel, which has good properties with respect to the norm. -/ noncomputable def explicitCokernel {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : SemiNormedGrp.{u} := (cokernelCocone f).pt /-- Descend to the explicit cokernel. -/ noncomputable def explicitCokernelDesc {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : explicitCokernel f ⟶ Z := (isColimitCokernelCocone f).desc (Cofork.ofπ g (by simp [w])) /-- The projection from `Y` to the explicit cokernel of `X ⟶ Y`. -/ noncomputable def explicitCokernelπ {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : Y ⟶ explicitCokernel f := (cokernelCocone f).ι.app WalkingParallelPair.one theorem explicitCokernelπ_surjective {X Y : SemiNormedGrp.{u}} {f : X ⟶ Y} : Function.Surjective (explicitCokernelπ f) := Quot.mk_surjective @[reassoc (attr := simp)] theorem comp_explicitCokernelπ {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : f ≫ explicitCokernelπ f = 0 := by convert (cokernelCocone f).w WalkingParallelPairHom.left simp @[simp] theorem explicitCokernelπ_apply_dom_eq_zero {X Y : SemiNormedGrp.{u}} {f : X ⟶ Y} (x : X) : (explicitCokernelπ f) (f x) = 0 := show (f ≫ explicitCokernelπ f) x = 0 by rw [comp_explicitCokernelπ]; rfl @[simp, reassoc] theorem explicitCokernelπ_desc {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : explicitCokernelπ f ≫ explicitCokernelDesc w = g := (isColimitCokernelCocone f).fac _ _ @[simp] theorem explicitCokernelπ_desc_apply {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {cond : f ≫ g = 0} (x : Y) : explicitCokernelDesc cond (explicitCokernelπ f x) = g x := show (explicitCokernelπ f ≫ explicitCokernelDesc cond) x = g x by rw [explicitCokernelπ_desc] theorem explicitCokernelDesc_unique {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) (e : explicitCokernel f ⟶ Z) (he : explicitCokernelπ f ≫ e = g) : e = explicitCokernelDesc w := by apply (isColimitCokernelCocone f).uniq (Cofork.ofπ g (by simp [w])) rintro (_ | _) · convert w.symm simp · exact he theorem explicitCokernelDesc_comp_eq_desc {X Y Z W : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {h : Z ⟶ W} {cond : f ≫ g = 0} : explicitCokernelDesc cond ≫ h = explicitCokernelDesc (show f ≫ g ≫ h = 0 by rw [← CategoryTheory.Category.assoc, cond, Limits.zero_comp]) := by refine explicitCokernelDesc_unique _ _ ?_ rw [← CategoryTheory.Category.assoc, explicitCokernelπ_desc] @[simp] theorem explicitCokernelDesc_zero {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} : explicitCokernelDesc (show f ≫ (0 : Y ⟶ Z) = 0 from CategoryTheory.Limits.comp_zero) = 0 := Eq.symm <| explicitCokernelDesc_unique _ _ CategoryTheory.Limits.comp_zero @[ext] theorem explicitCokernel_hom_ext {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} (e₁ e₂ : explicitCokernel f ⟶ Z) (h : explicitCokernelπ f ≫ e₁ = explicitCokernelπ f ≫ e₂) : e₁ = e₂ := by let g : Y ⟶ Z := explicitCokernelπ f ≫ e₂ have w : f ≫ g = 0 := by simp [g] have : e₂ = explicitCokernelDesc w := by apply explicitCokernelDesc_unique; rfl rw [this] apply explicitCokernelDesc_unique exact h instance explicitCokernelπ.epi {X Y : SemiNormedGrp.{u}} {f : X ⟶ Y} : Epi (explicitCokernelπ f) := by constructor intro Z g h H ext x rw [H] theorem isQuotient_explicitCokernelπ {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : NormedAddGroupHom.IsQuotient (explicitCokernelπ f).hom := NormedAddGroupHom.isQuotientQuotient _ theorem normNoninc_explicitCokernelπ {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : (explicitCokernelπ f).hom.NormNoninc := (isQuotient_explicitCokernelπ f).norm_le open scoped NNReal theorem explicitCokernelDesc_norm_le_of_norm_le {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) (c : ℝ≥0) (h : ‖g‖ ≤ c) : ‖explicitCokernelDesc w‖ ≤ c := NormedAddGroupHom.lift_norm_le _ _ _ h theorem explicitCokernelDesc_normNoninc {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {cond : f ≫ g = 0} (hg : g.hom.NormNoninc) : (explicitCokernelDesc cond).hom.NormNoninc := by refine NormedAddGroupHom.NormNoninc.normNoninc_iff_norm_le_one.2 ?_ rw [← NNReal.coe_one] exact explicitCokernelDesc_norm_le_of_norm_le cond 1 (NormedAddGroupHom.NormNoninc.normNoninc_iff_norm_le_one.1 hg) theorem explicitCokernelDesc_comp_eq_zero {X Y Z W : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {h : Z ⟶ W} (cond : f ≫ g = 0) (cond2 : g ≫ h = 0) : explicitCokernelDesc cond ≫ h = 0 := by rw [← cancel_epi (explicitCokernelπ f), ← Category.assoc, explicitCokernelπ_desc] simp [cond2] theorem explicitCokernelDesc_norm_le {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : ‖explicitCokernelDesc w‖ ≤ ‖g‖ := explicitCokernelDesc_norm_le_of_norm_le w ‖g‖₊ le_rfl /-- The explicit cokernel is isomorphic to the usual cokernel. -/ noncomputable def explicitCokernelIso {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : explicitCokernel f ≅ cokernel f := (isColimitCokernelCocone f).coconePointUniqueUpToIso (colimit.isColimit _) @[simp] theorem explicitCokernelIso_hom_π {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : explicitCokernelπ f ≫ (explicitCokernelIso f).hom = cokernel.π _ := by simp [explicitCokernelπ, explicitCokernelIso, IsColimit.coconePointUniqueUpToIso] @[simp] theorem explicitCokernelIso_inv_π {X Y : SemiNormedGrp.{u}} (f : X ⟶ Y) : cokernel.π f ≫ (explicitCokernelIso f).inv = explicitCokernelπ f := by simp [explicitCokernelπ, explicitCokernelIso] @[simp] theorem explicitCokernelIso_hom_desc {X Y Z : SemiNormedGrp.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : (explicitCokernelIso f).hom ≫ cokernel.desc f g w = explicitCokernelDesc w := by ext1 simp [explicitCokernelDesc, explicitCokernelπ, explicitCokernelIso, IsColimit.coconePointUniqueUpToIso] /-- A special case of `CategoryTheory.Limits.cokernel.map` adapted to `explicitCokernel`. -/ noncomputable def explicitCokernel.map {A B C D : SemiNormedGrp.{u}} {fab : A ⟶ B} {fbd : B ⟶ D} {fac : A ⟶ C} {fcd : C ⟶ D} (h : fab ≫ fbd = fac ≫ fcd) : explicitCokernel fab ⟶ explicitCokernel fcd := @explicitCokernelDesc _ _ _ fab (fbd ≫ explicitCokernelπ _) <| by simp [reassoc_of% h] /-- A special case of `CategoryTheory.Limits.cokernel.map_desc` adapted to `explicitCokernel`. -/ theorem ExplicitCoker.map_desc {A B C D B' D' : SemiNormedGrp.{u}} {fab : A ⟶ B} {fbd : B ⟶ D} {fac : A ⟶ C} {fcd : C ⟶ D} {h : fab ≫ fbd = fac ≫ fcd} {fbb' : B ⟶ B'} {fdd' : D ⟶ D'} {condb : fab ≫ fbb' = 0} {condd : fcd ≫ fdd' = 0} {g : B' ⟶ D'} (h' : fbb' ≫ g = fbd ≫ fdd') : explicitCokernelDesc condb ≫ g = explicitCokernel.map h ≫ explicitCokernelDesc condd := by delta explicitCokernel.map simp only [← Category.assoc, ← cancel_epi (explicitCokernelπ fab)] simp [Category.assoc, explicitCokernelπ_desc, h'] end ExplicitCokernel end Cokernel end SemiNormedGrp
ConstMulAction.lean
/- Copyright (c) 2021 Alex Kontorovich, Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Heather Macbeth -/ import Mathlib.Algebra.Group.Pointwise.Set.Lattice import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set import Mathlib.Algebra.Module.ULift import Mathlib.GroupTheory.GroupAction.Defs import Mathlib.Topology.Algebra.Constructions import Mathlib.Topology.Algebra.Support /-! # Monoid actions continuous in the second variable In this file we define class `ContinuousConstSMul`. We say `ContinuousConstSMul Γ T` if `Γ` acts on `T` and for each `γ`, the map `x ↦ γ • x` is continuous. (This differs from `ContinuousSMul`, which requires simultaneous continuity in both variables.) ## Main definitions * `ContinuousConstSMul Γ T` : typeclass saying that the map `x ↦ γ • x` is continuous on `T`; * `ProperlyDiscontinuousSMul`: says that the scalar multiplication `(•) : Γ → T → T` is properly discontinuous, that is, for any pair of compact sets `K, L` in `T`, only finitely many `γ:Γ` move `K` to have nontrivial intersection with `L`. * `Homeomorph.smul`: scalar multiplication by an element of a group `Γ` acting on `T` is a homeomorphism of `T`. *`Homeomorph.smulOfNeZero`: if a group with zero `G₀` (e.g., a field) acts on `X` and `c : G₀` is a nonzero element of `G₀`, then scalar multiplication by `c` is a homeomorphism of `X`; * `Homeomorph.smul`: scalar multiplication by an element of a group `G` acting on `X` is a homeomorphism of `X`. ## Main results * `isOpenMap_quotient_mk'_mul` : The quotient map by a group action is open. * `t2Space_of_properlyDiscontinuousSMul_of_t2Space` : The quotient by a discontinuous group action of a locally compact t2 space is t2. ## Tags Hausdorff, discrete group, properly discontinuous, quotient space -/ assert_not_exists IsOrderedRing open Topology Pointwise Filter Set TopologicalSpace /-- Class `ContinuousConstSMul Γ T` says that the scalar multiplication `(•) : Γ → T → T` is continuous in the second argument. We use the same class for all kinds of multiplicative actions, including (semi)modules and algebras. Note that both `ContinuousConstSMul α α` and `ContinuousConstSMul αᵐᵒᵖ α` are weaker versions of `ContinuousMul α`. -/ class ContinuousConstSMul (Γ : Type*) (T : Type*) [TopologicalSpace T] [SMul Γ T] : Prop where /-- The scalar multiplication `(•) : Γ → T → T` is continuous in the second argument. -/ continuous_const_smul : ∀ γ : Γ, Continuous fun x : T => γ • x /-- Class `ContinuousConstVAdd Γ T` says that the additive action `(+ᵥ) : Γ → T → T` is continuous in the second argument. We use the same class for all kinds of additive actions, including (semi)modules and algebras. Note that both `ContinuousConstVAdd α α` and `ContinuousConstVAdd αᵐᵒᵖ α` are weaker versions of `ContinuousVAdd α`. -/ class ContinuousConstVAdd (Γ : Type*) (T : Type*) [TopologicalSpace T] [VAdd Γ T] : Prop where /-- The additive action `(+ᵥ) : Γ → T → T` is continuous in the second argument. -/ continuous_const_vadd : ∀ γ : Γ, Continuous fun x : T => γ +ᵥ x attribute [to_additive] ContinuousConstSMul export ContinuousConstSMul (continuous_const_smul) export ContinuousConstVAdd (continuous_const_vadd) variable {M α β : Type*} section SMul variable [TopologicalSpace α] [SMul M α] [ContinuousConstSMul M α] @[to_additive] instance : ContinuousConstSMul (ULift M) α := ⟨fun γ ↦ continuous_const_smul (ULift.down γ)⟩ @[to_additive] theorem Filter.Tendsto.const_smul {f : β → α} {l : Filter β} {a : α} (hf : Tendsto f l (𝓝 a)) (c : M) : Tendsto (fun x => c • f x) l (𝓝 (c • a)) := ((continuous_const_smul _).tendsto _).comp hf variable [TopologicalSpace β] {g : β → α} {b : β} {s : Set β} @[to_additive] nonrec theorem ContinuousWithinAt.const_smul (hg : ContinuousWithinAt g s b) (c : M) : ContinuousWithinAt (fun x => c • g x) s b := hg.const_smul c @[to_additive (attr := fun_prop)] nonrec theorem ContinuousAt.const_smul (hg : ContinuousAt g b) (c : M) : ContinuousAt (fun x => c • g x) b := hg.const_smul c @[to_additive (attr := fun_prop)] theorem ContinuousOn.const_smul (hg : ContinuousOn g s) (c : M) : ContinuousOn (fun x => c • g x) s := fun x hx => (hg x hx).const_smul c @[to_additive (attr := continuity, fun_prop)] theorem Continuous.const_smul (hg : Continuous g) (c : M) : Continuous fun x => c • g x := (continuous_const_smul _).comp hg /-- If a scalar is central, then its right action is continuous when its left action is. -/ @[to_additive /-- If an additive action is central, then its right action is continuous when its left action is. -/] instance ContinuousConstSMul.op [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] : ContinuousConstSMul Mᵐᵒᵖ α := ⟨MulOpposite.rec' fun c => by simpa only [op_smul_eq_smul] using continuous_const_smul c⟩ @[to_additive] instance MulOpposite.continuousConstSMul : ContinuousConstSMul M αᵐᵒᵖ := ⟨fun c => MulOpposite.continuous_op.comp <| MulOpposite.continuous_unop.const_smul c⟩ @[to_additive] instance : ContinuousConstSMul M αᵒᵈ := ‹ContinuousConstSMul M α› @[to_additive] instance OrderDual.continuousConstSMul' : ContinuousConstSMul Mᵒᵈ α := ‹ContinuousConstSMul M α› @[to_additive] instance Prod.continuousConstSMul [SMul M β] [ContinuousConstSMul M β] : ContinuousConstSMul M (α × β) := ⟨fun _ => (continuous_fst.const_smul _).prodMk (continuous_snd.const_smul _)⟩ @[to_additive] instance {ι : Type*} {γ : ι → Type*} [∀ i, TopologicalSpace (γ i)] [∀ i, SMul M (γ i)] [∀ i, ContinuousConstSMul M (γ i)] : ContinuousConstSMul M (∀ i, γ i) := ⟨fun _ => continuous_pi fun i => (continuous_apply i).const_smul _⟩ @[to_additive] theorem IsCompact.smul {α β} [SMul α β] [TopologicalSpace β] [ContinuousConstSMul α β] (a : α) {s : Set β} (hs : IsCompact s) : IsCompact (a • s) := hs.image (continuous_id.const_smul a) @[to_additive] theorem Specializes.const_smul {x y : α} (h : x ⤳ y) (c : M) : (c • x) ⤳ (c • y) := h.map (continuous_const_smul c) @[to_additive] theorem Inseparable.const_smul {x y : α} (h : Inseparable x y) (c : M) : Inseparable (c • x) (c • y) := h.map (continuous_const_smul c) @[to_additive] theorem Topology.IsInducing.continuousConstSMul {N β : Type*} [SMul N β] [TopologicalSpace β] {g : β → α} (hg : IsInducing g) (f : N → M) (hf : ∀ {c : N} {x : β}, g (c • x) = f c • g x) : ContinuousConstSMul N β where continuous_const_smul c := by simpa only [Function.comp_def, hf, hg.continuous_iff] using hg.continuous.const_smul (f c) end SMul section Monoid variable [TopologicalSpace α] variable [Monoid M] [MulAction M α] [ContinuousConstSMul M α] @[to_additive] instance Units.continuousConstSMul : ContinuousConstSMul Mˣ α where continuous_const_smul m := continuous_const_smul (m : M) @[to_additive] theorem smul_closure_subset (c : M) (s : Set α) : c • closure s ⊆ closure (c • s) := ((Set.mapsTo_image _ _).closure <| continuous_const_smul c).image_subset @[to_additive] theorem smul_closure_orbit_subset (c : M) (x : α) : c • closure (MulAction.orbit M x) ⊆ closure (MulAction.orbit M x) := (smul_closure_subset c _).trans <| closure_mono <| MulAction.smul_orbit_subset _ _ theorem isClosed_setOf_map_smul {N : Type*} [Monoid N] (α β) [MulAction M α] [MulAction N β] [TopologicalSpace β] [T2Space β] [ContinuousConstSMul N β] (σ : M → N) : IsClosed { f : α → β | ∀ c x, f (c • x) = σ c • f x } := by simp only [Set.setOf_forall] exact isClosed_iInter fun c => isClosed_iInter fun x => isClosed_eq (continuous_apply _) ((continuous_apply _).const_smul _) end Monoid section Group variable {G : Type*} [TopologicalSpace α] [Group G] [MulAction G α] [ContinuousConstSMul G α] @[to_additive] theorem tendsto_const_smul_iff {f : β → α} {l : Filter β} {a : α} (c : G) : Tendsto (fun x => c • f x) l (𝓝 <| c • a) ↔ Tendsto f l (𝓝 a) := ⟨fun h => by simpa only [inv_smul_smul] using h.const_smul c⁻¹, fun h => h.const_smul _⟩ variable [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} @[to_additive] theorem continuousWithinAt_const_smul_iff (c : G) : ContinuousWithinAt (fun x => c • f x) s b ↔ ContinuousWithinAt f s b := tendsto_const_smul_iff c @[to_additive] theorem continuousOn_const_smul_iff (c : G) : ContinuousOn (fun x => c • f x) s ↔ ContinuousOn f s := forall₂_congr fun _ _ => continuousWithinAt_const_smul_iff c @[to_additive] theorem continuousAt_const_smul_iff (c : G) : ContinuousAt (fun x => c • f x) b ↔ ContinuousAt f b := tendsto_const_smul_iff c @[to_additive] theorem continuous_const_smul_iff (c : G) : (Continuous fun x => c • f x) ↔ Continuous f := by simp only [continuous_iff_continuousAt, continuousAt_const_smul_iff] /-- The homeomorphism given by scalar multiplication by a given element of a group `Γ` acting on `T` is a homeomorphism from `T` to itself. -/ @[to_additive (attr := simps!)] def Homeomorph.smul (γ : G) : α ≃ₜ α where toEquiv := MulAction.toPerm γ continuous_toFun := continuous_const_smul γ continuous_invFun := continuous_const_smul γ⁻¹ /-- The homeomorphism given by affine-addition by an element of an additive group `Γ` acting on `T` is a homeomorphism from `T` to itself. -/ add_decl_doc Homeomorph.vadd @[to_additive] theorem isOpenMap_smul (c : G) : IsOpenMap fun x : α => c • x := (Homeomorph.smul c).isOpenMap @[to_additive] theorem IsOpen.smul {s : Set α} (hs : IsOpen s) (c : G) : IsOpen (c • s) := isOpenMap_smul c s hs @[to_additive] theorem isClosedMap_smul (c : G) : IsClosedMap fun x : α => c • x := (Homeomorph.smul c).isClosedMap @[to_additive] theorem IsClosed.smul {s : Set α} (hs : IsClosed s) (c : G) : IsClosed (c • s) := isClosedMap_smul c s hs @[to_additive] theorem closure_smul (c : G) (s : Set α) : closure (c • s) = c • closure s := ((Homeomorph.smul c).image_closure s).symm @[to_additive] theorem Dense.smul (c : G) {s : Set α} (hs : Dense s) : Dense (c • s) := by rw [dense_iff_closure_eq] at hs ⊢; rw [closure_smul, hs, smul_set_univ] @[to_additive] theorem interior_smul (c : G) (s : Set α) : interior (c • s) = c • interior s := ((Homeomorph.smul c).image_interior s).symm @[to_additive] theorem IsOpen.smul_left {s : Set G} {t : Set α} (ht : IsOpen t) : IsOpen (s • t) := by rw [← iUnion_smul_set] exact isOpen_biUnion fun a _ => ht.smul _ @[to_additive] theorem subset_interior_smul_right {s : Set G} {t : Set α} : s • interior t ⊆ interior (s • t) := interior_maximal (Set.smul_subset_smul_left interior_subset) isOpen_interior.smul_left @[to_additive (attr := simp)] theorem smul_mem_nhds_smul_iff {t : Set α} (g : G) {a : α} : g • t ∈ 𝓝 (g • a) ↔ t ∈ 𝓝 a := (Homeomorph.smul g).isOpenEmbedding.image_mem_nhds @[to_additive] alias ⟨_, smul_mem_nhds_smul⟩ := smul_mem_nhds_smul_iff @[to_additive (attr := simp)] theorem smul_mem_nhds_self [TopologicalSpace G] [ContinuousConstSMul G G] {g : G} {s : Set G} : g • s ∈ 𝓝 g ↔ s ∈ 𝓝 1 := by rw [← smul_mem_nhds_smul_iff g⁻¹]; simp end Group section GroupWithZero variable {G₀ : Type*} [TopologicalSpace α] [GroupWithZero G₀] [MulAction G₀ α] [ContinuousConstSMul G₀ α] theorem tendsto_const_smul_iff₀ {f : β → α} {l : Filter β} {a : α} {c : G₀} (hc : c ≠ 0) : Tendsto (fun x => c • f x) l (𝓝 <| c • a) ↔ Tendsto f l (𝓝 a) := tendsto_const_smul_iff (Units.mk0 c hc) variable [TopologicalSpace β] {f : β → α} {b : β} {c : G₀} {s : Set β} theorem continuousWithinAt_const_smul_iff₀ (hc : c ≠ 0) : ContinuousWithinAt (fun x => c • f x) s b ↔ ContinuousWithinAt f s b := tendsto_const_smul_iff (Units.mk0 c hc) theorem continuousOn_const_smul_iff₀ (hc : c ≠ 0) : ContinuousOn (fun x => c • f x) s ↔ ContinuousOn f s := continuousOn_const_smul_iff (Units.mk0 c hc) theorem continuousAt_const_smul_iff₀ (hc : c ≠ 0) : ContinuousAt (fun x => c • f x) b ↔ ContinuousAt f b := continuousAt_const_smul_iff (Units.mk0 c hc) theorem continuous_const_smul_iff₀ (hc : c ≠ 0) : (Continuous fun x => c • f x) ↔ Continuous f := continuous_const_smul_iff (Units.mk0 c hc) /-- Scalar multiplication by a non-zero element of a group with zero acting on `α` is a homeomorphism from `α` onto itself. -/ @[simps! -fullyApplied apply] protected def Homeomorph.smulOfNeZero (c : G₀) (hc : c ≠ 0) : α ≃ₜ α := Homeomorph.smul (Units.mk0 c hc) @[simp] theorem Homeomorph.smulOfNeZero_symm_apply {c : G₀} (hc : c ≠ 0) : ⇑(Homeomorph.smulOfNeZero c hc).symm = (c⁻¹ • · : α → α) := rfl theorem isOpenMap_smul₀ {c : G₀} (hc : c ≠ 0) : IsOpenMap fun x : α => c • x := (Homeomorph.smulOfNeZero c hc).isOpenMap theorem IsOpen.smul₀ {c : G₀} {s : Set α} (hs : IsOpen s) (hc : c ≠ 0) : IsOpen (c • s) := isOpenMap_smul₀ hc s hs theorem interior_smul₀ {c : G₀} (hc : c ≠ 0) (s : Set α) : interior (c • s) = c • interior s := ((Homeomorph.smulOfNeZero c hc).image_interior s).symm theorem closure_smul₀' {c : G₀} (hc : c ≠ 0) (s : Set α) : closure (c • s) = c • closure s := ((Homeomorph.smulOfNeZero c hc).image_closure s).symm theorem closure_smul₀ {E} [Zero E] [MulActionWithZero G₀ E] [TopologicalSpace E] [T1Space E] [ContinuousConstSMul G₀ E] (c : G₀) (s : Set E) : closure (c • s) = c • closure s := by rcases eq_or_ne c 0 with (rfl | hc) · rcases eq_empty_or_nonempty s with (rfl | hs) · simp · rw [zero_smul_set hs, zero_smul_set hs.closure] exact closure_singleton · exact closure_smul₀' hc s /-- `smul` is a closed map in the second argument. The lemma that `smul` is a closed map in the first argument (for a normed space over a complete normed field) is `isClosedMap_smul_left` in `Analysis.Normed.Module.FiniteDimension`. -/ theorem isClosedMap_smul_of_ne_zero {c : G₀} (hc : c ≠ 0) : IsClosedMap fun x : α => c • x := (Homeomorph.smulOfNeZero c hc).isClosedMap theorem IsClosed.smul_of_ne_zero {c : G₀} {s : Set α} (hs : IsClosed s) (hc : c ≠ 0) : IsClosed (c • s) := isClosedMap_smul_of_ne_zero hc s hs /-- `smul` is a closed map in the second argument. The lemma that `smul` is a closed map in the first argument (for a normed space over a complete normed field) is `isClosedMap_smul_left` in `Analysis.Normed.Module.FiniteDimension`. -/ theorem isClosedMap_smul₀ {E : Type*} [Zero E] [MulActionWithZero G₀ E] [TopologicalSpace E] [T1Space E] [ContinuousConstSMul G₀ E] (c : G₀) : IsClosedMap fun x : E => c • x := by rcases eq_or_ne c 0 with (rfl | hne) · simp only [zero_smul] exact isClosedMap_const · exact (Homeomorph.smulOfNeZero c hne).isClosedMap theorem IsClosed.smul₀ {E : Type*} [Zero E] [MulActionWithZero G₀ E] [TopologicalSpace E] [T1Space E] [ContinuousConstSMul G₀ E] (c : G₀) {s : Set E} (hs : IsClosed s) : IsClosed (c • s) := isClosedMap_smul₀ c s hs theorem HasCompactMulSupport.comp_smul {β : Type*} [One β] {f : α → β} (h : HasCompactMulSupport f) {c : G₀} (hc : c ≠ 0) : HasCompactMulSupport fun x => f (c • x) := h.comp_homeomorph (Homeomorph.smulOfNeZero c hc) theorem HasCompactSupport.comp_smul {β : Type*} [Zero β] {f : α → β} (h : HasCompactSupport f) {c : G₀} (hc : c ≠ 0) : HasCompactSupport fun x => f (c • x) := h.comp_homeomorph (Homeomorph.smulOfNeZero c hc) end GroupWithZero namespace IsUnit variable [Monoid M] [TopologicalSpace α] [MulAction M α] [ContinuousConstSMul M α] nonrec theorem tendsto_const_smul_iff {f : β → α} {l : Filter β} {a : α} {c : M} (hc : IsUnit c) : Tendsto (fun x => c • f x) l (𝓝 <| c • a) ↔ Tendsto f l (𝓝 a) := tendsto_const_smul_iff hc.unit variable [TopologicalSpace β] {f : β → α} {b : β} {c : M} {s : Set β} nonrec theorem continuousWithinAt_const_smul_iff (hc : IsUnit c) : ContinuousWithinAt (fun x => c • f x) s b ↔ ContinuousWithinAt f s b := continuousWithinAt_const_smul_iff hc.unit nonrec theorem continuousOn_const_smul_iff (hc : IsUnit c) : ContinuousOn (fun x => c • f x) s ↔ ContinuousOn f s := continuousOn_const_smul_iff hc.unit nonrec theorem continuousAt_const_smul_iff (hc : IsUnit c) : ContinuousAt (fun x => c • f x) b ↔ ContinuousAt f b := continuousAt_const_smul_iff hc.unit nonrec theorem continuous_const_smul_iff (hc : IsUnit c) : (Continuous fun x => c • f x) ↔ Continuous f := continuous_const_smul_iff hc.unit nonrec theorem isOpenMap_smul (hc : IsUnit c) : IsOpenMap fun x : α => c • x := isOpenMap_smul hc.unit nonrec theorem isClosedMap_smul (hc : IsUnit c) : IsClosedMap fun x : α => c • x := isClosedMap_smul hc.unit nonrec theorem smul_mem_nhds_smul_iff (hc : IsUnit c) {s : Set α} {a : α} : c • s ∈ 𝓝 (c • a) ↔ s ∈ 𝓝 a := smul_mem_nhds_smul_iff hc.unit end IsUnit -- TODO: use `Set.Nonempty` /-- Class `ProperlyDiscontinuousSMul Γ T` says that the scalar multiplication `(•) : Γ → T → T` is properly discontinuous, that is, for any pair of compact sets `K, L` in `T`, only finitely many `γ:Γ` move `K` to have nontrivial intersection with `L`. -/ class ProperlyDiscontinuousSMul (Γ : Type*) (T : Type*) [TopologicalSpace T] [SMul Γ T] : Prop where /-- Given two compact sets `K` and `L`, `γ • K ∩ L` is nonempty for finitely many `γ`. -/ finite_disjoint_inter_image : ∀ {K L : Set T}, IsCompact K → IsCompact L → Set.Finite { γ : Γ | (γ • ·) '' K ∩ L ≠ ∅ } /-- Class `ProperlyDiscontinuousVAdd Γ T` says that the additive action `(+ᵥ) : Γ → T → T` is properly discontinuous, that is, for any pair of compact sets `K, L` in `T`, only finitely many `γ:Γ` move `K` to have nontrivial intersection with `L`. -/ class ProperlyDiscontinuousVAdd (Γ : Type*) (T : Type*) [TopologicalSpace T] [VAdd Γ T] : Prop where /-- Given two compact sets `K` and `L`, `γ +ᵥ K ∩ L` is nonempty for finitely many `γ`. -/ finite_disjoint_inter_image : ∀ {K L : Set T}, IsCompact K → IsCompact L → Set.Finite { γ : Γ | (γ +ᵥ ·) '' K ∩ L ≠ ∅ } attribute [to_additive] ProperlyDiscontinuousSMul variable {Γ : Type*} [Group Γ] {T : Type*} [TopologicalSpace T] [MulAction Γ T] /-- A finite group action is always properly discontinuous. -/ @[to_additive /-- A finite group action is always properly discontinuous. -/] instance (priority := 100) Finite.to_properlyDiscontinuousSMul [Finite Γ] : ProperlyDiscontinuousSMul Γ T where finite_disjoint_inter_image _ _ := Set.toFinite _ export ProperlyDiscontinuousSMul (finite_disjoint_inter_image) export ProperlyDiscontinuousVAdd (finite_disjoint_inter_image) /-- The quotient map by a group action is open, i.e. the quotient by a group action is an open quotient. -/ @[to_additive /-- The quotient map by a group action is open, i.e. the quotient by a group action is an open quotient. -/] theorem isOpenMap_quotient_mk'_mul [ContinuousConstSMul Γ T] : letI := MulAction.orbitRel Γ T IsOpenMap (Quotient.mk' : T → Quotient (MulAction.orbitRel Γ T)) := fun U hU => by rw [isOpen_coinduced, MulAction.quotient_preimage_image_eq_union_mul U] exact isOpen_iUnion fun γ => isOpenMap_smul γ U hU @[to_additive] theorem MulAction.isOpenQuotientMap_quotientMk [ContinuousConstSMul Γ T] : IsOpenQuotientMap (Quotient.mk (MulAction.orbitRel Γ T)) := ⟨Quot.mk_surjective, continuous_quot_mk, isOpenMap_quotient_mk'_mul⟩ /-- The quotient by a discontinuous group action of a locally compact t2 space is t2. -/ @[to_additive /-- The quotient by a discontinuous group action of a locally compact t2 space is t2. -/] instance (priority := 100) t2Space_of_properlyDiscontinuousSMul_of_t2Space [T2Space T] [LocallyCompactSpace T] [ContinuousConstSMul Γ T] [ProperlyDiscontinuousSMul Γ T] : T2Space (Quotient (MulAction.orbitRel Γ T)) := by letI := MulAction.orbitRel Γ T set Q := Quotient (MulAction.orbitRel Γ T) rw [t2Space_iff_nhds] let f : T → Q := Quotient.mk' have f_op : IsOpenMap f := isOpenMap_quotient_mk'_mul rintro ⟨x₀⟩ ⟨y₀⟩ (hxy : f x₀ ≠ f y₀) change ∃ U ∈ 𝓝 (f x₀), ∃ V ∈ 𝓝 (f y₀), _ have hγx₀y₀ : ∀ γ : Γ, γ • x₀ ≠ y₀ := not_exists.mp (mt Quotient.sound hxy.symm :) obtain ⟨K₀, hK₀, K₀_in⟩ := exists_compact_mem_nhds x₀ obtain ⟨L₀, hL₀, L₀_in⟩ := exists_compact_mem_nhds y₀ let bad_Γ_set := { γ : Γ | (γ • ·) '' K₀ ∩ L₀ ≠ ∅ } have bad_Γ_finite : bad_Γ_set.Finite := finite_disjoint_inter_image (Γ := Γ) hK₀ hL₀ choose u v hu hv u_v_disjoint using fun γ => t2_separation_nhds (hγx₀y₀ γ) let U₀₀ := ⋂ γ ∈ bad_Γ_set, (γ • ·) ⁻¹' u γ let U₀ := U₀₀ ∩ K₀ let V₀₀ := ⋂ γ ∈ bad_Γ_set, v γ let V₀ := V₀₀ ∩ L₀ have U_nhds : f '' U₀ ∈ 𝓝 (f x₀) := by refine f_op.image_mem_nhds (inter_mem ((biInter_mem bad_Γ_finite).mpr fun γ _ => ?_) K₀_in) exact (continuous_const_smul _).continuousAt (hu γ) have V_nhds : f '' V₀ ∈ 𝓝 (f y₀) := f_op.image_mem_nhds (inter_mem ((biInter_mem bad_Γ_finite).mpr fun γ _ => hv γ) L₀_in) refine ⟨f '' U₀, U_nhds, f '' V₀, V_nhds, MulAction.disjoint_image_image_iff.2 ?_⟩ rintro x ⟨x_in_U₀₀, x_in_K₀⟩ γ by_cases H : γ ∈ bad_Γ_set · exact fun h => (u_v_disjoint γ).le_bot ⟨mem_iInter₂.mp x_in_U₀₀ γ H, mem_iInter₂.mp h.1 γ H⟩ · rintro ⟨-, h'⟩ simp only [bad_Γ_set, image_smul, Classical.not_not, mem_setOf_eq, Ne] at H exact eq_empty_iff_forall_notMem.mp H (γ • x) ⟨mem_image_of_mem _ x_in_K₀, h'⟩ /-- The quotient of a second countable space by a group action is second countable. -/ @[to_additive /-- The quotient of a second countable space by an additive group action is second countable. -/] theorem ContinuousConstSMul.secondCountableTopology [SecondCountableTopology T] [ContinuousConstSMul Γ T] : SecondCountableTopology (Quotient (MulAction.orbitRel Γ T)) := TopologicalSpace.Quotient.secondCountableTopology isOpenMap_quotient_mk'_mul section nhds section MulAction variable {G₀ : Type*} [GroupWithZero G₀] [MulAction G₀ α] [TopologicalSpace α] [ContinuousConstSMul G₀ α] /-- Scalar multiplication by a nonzero scalar preserves neighborhoods. -/ theorem smul_mem_nhds_smul_iff₀ {c : G₀} {s : Set α} {x : α} (hc : c ≠ 0) : c • s ∈ 𝓝 (c • x : α) ↔ s ∈ 𝓝 x := smul_mem_nhds_smul_iff (Units.mk0 c hc) alias ⟨_, smul_mem_nhds_smul₀⟩ := smul_mem_nhds_smul_iff₀ end MulAction section DistribMulAction variable {G₀ : Type*} [GroupWithZero G₀] [AddMonoid α] [DistribMulAction G₀ α] [TopologicalSpace α] [ContinuousConstSMul G₀ α] theorem set_smul_mem_nhds_zero_iff {s : Set α} {c : G₀} (hc : c ≠ 0) : c • s ∈ 𝓝 (0 : α) ↔ s ∈ 𝓝 (0 : α) := by refine Iff.trans ?_ (smul_mem_nhds_smul_iff₀ hc) rw [smul_zero] end DistribMulAction end nhds
StronglyRegular.lean
/- Copyright (c) 2021 Alena Gusakov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alena Gusakov, Jeremy Tan -/ import Mathlib.Combinatorics.Enumerative.DoubleCounting import Mathlib.Combinatorics.SimpleGraph.AdjMatrix /-! # Strongly regular graphs ## Main definitions * `G.IsSRGWith n k ℓ μ` (see `SimpleGraph.IsSRGWith`) is a structure for a `SimpleGraph` satisfying the following conditions: * The cardinality of the vertex set is `n` * `G` is a regular graph with degree `k` * The number of common neighbors between any two adjacent vertices in `G` is `ℓ` * The number of common neighbors between any two nonadjacent vertices in `G` is `μ` ## Main theorems * `IsSRGWith.compl`: the complement of a strongly regular graph is strongly regular. * `IsSRGWith.param_eq`: `k * (k - ℓ - 1) = (n - k - 1) * μ` when `0 < n`. * `IsSRGWith.matrix_eq`: let `A` and `C` be `G`'s and `Gᶜ`'s adjacency matrices respectively and `I` be the identity matrix, then `A ^ 2 = k • I + ℓ • A + μ • C`. -/ open Finset universe u namespace SimpleGraph variable {V : Type u} [Fintype V] variable (G : SimpleGraph V) [DecidableRel G.Adj] /-- A graph is strongly regular with parameters `n k ℓ μ` if * its vertex set has cardinality `n` * it is regular with degree `k` * every pair of adjacent vertices has `ℓ` common neighbors * every pair of nonadjacent vertices has `μ` common neighbors -/ structure IsSRGWith (n k ℓ μ : ℕ) : Prop where card : Fintype.card V = n regular : G.IsRegularOfDegree k of_adj : ∀ v w, G.Adj v w → Fintype.card (G.commonNeighbors v w) = ℓ of_not_adj : Pairwise fun v w ↦ ¬G.Adj v w → Fintype.card (G.commonNeighbors v w) = μ variable {G} {n k ℓ μ : ℕ} /-- Empty graphs are strongly regular. Note that `ℓ` can take any value for empty graphs, since there are no pairs of adjacent vertices. -/ theorem bot_strongly_regular : (⊥ : SimpleGraph V).IsSRGWith (Fintype.card V) 0 ℓ 0 where card := rfl regular := bot_degree of_adj _ _ h := h.elim of_not_adj v w _ := by simp only [card_eq_zero, Fintype.card_ofFinset, forall_true_left, not_false_iff, bot_adj] ext simp [mem_commonNeighbors] /-- **Conway's 99-graph problem** (from https://oeis.org/A248380/a248380.pdf) can be reformulated as the existence of a strongly regular graph with params (99, 14, 1, 2). This is an open problem, and has no known proof of existence. -/ proof_wanted conway_99 : ∃ α : Type*, ∃ (g : SimpleGraph α), IsSRGWith G 99 14 1 2 variable [DecidableEq V] /-- Complete graphs are strongly regular. Note that `μ` can take any value for complete graphs, since there are no distinct pairs of non-adjacent vertices. -/ theorem IsSRGWith.top : (⊤ : SimpleGraph V).IsSRGWith (Fintype.card V) (Fintype.card V - 1) (Fintype.card V - 2) μ where card := rfl regular := IsRegularOfDegree.top of_adj _ _ := card_commonNeighbors_top of_not_adj v w h h' := (h' ((top_adj v w).2 h)).elim theorem IsSRGWith.card_neighborFinset_union_eq {v w : V} (h : G.IsSRGWith n k ℓ μ) : #(G.neighborFinset v ∪ G.neighborFinset w) = 2 * k - Fintype.card (G.commonNeighbors v w) := by apply Nat.add_right_cancel (m := Fintype.card (G.commonNeighbors v w)) rw [Nat.sub_add_cancel, ← Set.toFinset_card] · simp [commonNeighbors, ← neighborFinset_def, Finset.card_union_add_card_inter, h.regular.degree_eq, two_mul] · apply le_trans (card_commonNeighbors_le_degree_left _ _ _) simp [h.regular.degree_eq, two_mul] /-- Assuming `G` is strongly regular, `2*(k + 1) - m` in `G` is the number of vertices that are adjacent to either `v` or `w` when `¬G.Adj v w`. So it's the cardinality of `G.neighborSet v ∪ G.neighborSet w`. -/ theorem IsSRGWith.card_neighborFinset_union_of_not_adj {v w : V} (h : G.IsSRGWith n k ℓ μ) (hne : v ≠ w) (ha : ¬G.Adj v w) : #(G.neighborFinset v ∪ G.neighborFinset w) = 2 * k - μ := by rw [← h.of_not_adj hne ha] exact h.card_neighborFinset_union_eq theorem IsSRGWith.card_neighborFinset_union_of_adj {v w : V} (h : G.IsSRGWith n k ℓ μ) (ha : G.Adj v w) : #(G.neighborFinset v ∪ G.neighborFinset w) = 2 * k - ℓ := by rw [← h.of_adj v w ha] exact h.card_neighborFinset_union_eq theorem compl_neighborFinset_sdiff_inter_eq {v w : V} : (G.neighborFinset v)ᶜ \ {v} ∩ ((G.neighborFinset w)ᶜ \ {w}) = ((G.neighborFinset v)ᶜ ∩ (G.neighborFinset w)ᶜ) \ ({w} ∪ {v}) := by ext rw [← not_iff_not] simp [imp_iff_not_or, or_assoc, or_comm, or_left_comm] theorem sdiff_compl_neighborFinset_inter_eq {v w : V} (h : G.Adj v w) : ((G.neighborFinset v)ᶜ ∩ (G.neighborFinset w)ᶜ) \ ({w} ∪ {v}) = (G.neighborFinset v)ᶜ ∩ (G.neighborFinset w)ᶜ := by ext simp only [and_imp, mem_union, mem_sdiff, mem_compl, and_iff_left_iff_imp, mem_neighborFinset, mem_inter, mem_singleton] rintro hnv hnw (rfl | rfl) · exact hnv h · apply hnw rwa [adj_comm] theorem IsSRGWith.compl_is_regular (h : G.IsSRGWith n k ℓ μ) : Gᶜ.IsRegularOfDegree (n - k - 1) := by rw [← h.card, Nat.sub_sub, add_comm, ← Nat.sub_sub] exact h.regular.compl theorem IsSRGWith.card_commonNeighbors_eq_of_adj_compl (h : G.IsSRGWith n k ℓ μ) {v w : V} (ha : Gᶜ.Adj v w) : Fintype.card (Gᶜ.commonNeighbors v w) = n - (2 * k - μ) - 2 := by simp only [← Set.toFinset_card, commonNeighbors, Set.toFinset_inter, neighborSet_compl, Set.toFinset_diff, Set.toFinset_singleton, Set.toFinset_compl, ← neighborFinset_def] simp_rw [compl_neighborFinset_sdiff_inter_eq] have hne : v ≠ w := ne_of_adj _ ha rw [compl_adj] at ha rw [card_sdiff, ← insert_eq, card_insert_of_notMem, card_singleton, ← Finset.compl_union] · rw [card_compl, h.card_neighborFinset_union_of_not_adj hne ha.2, ← h.card] · simp only [hne.symm, not_false_iff, mem_singleton] · intro u simp only [mem_union, mem_compl, mem_neighborFinset, mem_inter, mem_singleton] rintro (rfl | rfl) <;> simpa [adj_comm] using ha.2 theorem IsSRGWith.card_commonNeighbors_eq_of_not_adj_compl (h : G.IsSRGWith n k ℓ μ) {v w : V} (hn : v ≠ w) (hna : ¬Gᶜ.Adj v w) : Fintype.card (Gᶜ.commonNeighbors v w) = n - (2 * k - ℓ) := by simp only [← Set.toFinset_card, commonNeighbors, Set.toFinset_inter, neighborSet_compl, Set.toFinset_diff, Set.toFinset_singleton, Set.toFinset_compl, ← neighborFinset_def] simp only [not_and, Classical.not_not, compl_adj] at hna have h2' := hna hn simp_rw [compl_neighborFinset_sdiff_inter_eq, sdiff_compl_neighborFinset_inter_eq h2'] rwa [← Finset.compl_union, card_compl, h.card_neighborFinset_union_of_adj, ← h.card] /-- The complement of a strongly regular graph is strongly regular. -/ theorem IsSRGWith.compl (h : G.IsSRGWith n k ℓ μ) : Gᶜ.IsSRGWith n (n - k - 1) (n - (2 * k - μ) - 2) (n - (2 * k - ℓ)) where card := h.card regular := h.compl_is_regular of_adj _ _ := h.card_commonNeighbors_eq_of_adj_compl of_not_adj _ _ := h.card_commonNeighbors_eq_of_not_adj_compl /-- The parameters of a strongly regular graph with at least one vertex satisfy `k * (k - ℓ - 1) = (n - k - 1) * μ`. -/ theorem IsSRGWith.param_eq {V : Type u} [Fintype V] (G : SimpleGraph V) [DecidableRel G.Adj] (h : G.IsSRGWith n k ℓ μ) (hn : 0 < n) : k * (k - ℓ - 1) = (n - k - 1) * μ := by letI := Classical.decEq V rw [← h.card, Fintype.card_pos_iff] at hn obtain ⟨v⟩ := hn convert card_mul_eq_card_mul G.Adj (s := G.neighborFinset v) (t := Gᶜ.neighborFinset v) _ _ · simp [h.regular v] · simp [h.compl.regular v] · intro w hw rw [mem_neighborFinset] at hw simp_rw [bipartiteAbove, ← mem_neighborFinset, filter_mem_eq_inter] have s : {v} ⊆ G.neighborFinset w \ G.neighborFinset v := by rw [singleton_subset_iff, mem_sdiff, mem_neighborFinset] exact ⟨hw.symm, G.notMem_neighborFinset_self v⟩ rw [inter_comm, neighborFinset_compl, ← inter_sdiff_assoc, ← sdiff_eq_inter_compl, card_sdiff s, card_singleton, ← sdiff_inter_self_left, card_sdiff inter_subset_left] congr · simp [h.regular w] · simp_rw [inter_comm, neighborFinset_def, ← Set.toFinset_inter, ← h.of_adj v w hw, ← Set.toFinset_card] congr! · intro w hw simp_rw [neighborFinset_compl, mem_sdiff, mem_compl, mem_singleton, mem_neighborFinset, ← Ne.eq_def] at hw simp_rw [bipartiteBelow, adj_comm, ← mem_neighborFinset, filter_mem_eq_inter, neighborFinset_def, ← Set.toFinset_inter, ← h.of_not_adj hw.2.symm hw.1, ← Set.toFinset_card] congr! /-- Let `A` and `C` be the adjacency matrices of a strongly regular graph with parameters `n k ℓ μ` and its complement respectively and `I` be the identity matrix, then `A ^ 2 = k • I + ℓ • A + μ • C`. `C` is equivalent to the expression `J - I - A` more often found in the literature, where `J` is the all-ones matrix. -/ theorem IsSRGWith.matrix_eq {α : Type*} [Semiring α] (h : G.IsSRGWith n k ℓ μ) : G.adjMatrix α ^ 2 = k • (1 : Matrix V V α) + ℓ • G.adjMatrix α + μ • Gᶜ.adjMatrix α := by ext v w simp only [adjMatrix_pow_apply_eq_card_walk, Set.coe_setOf, Matrix.add_apply, Matrix.smul_apply, adjMatrix_apply, compl_adj] rw [Fintype.card_congr (G.walkLengthTwoEquivCommonNeighbors v w)] obtain rfl | hn := eq_or_ne v w · rw [← Set.toFinset_card] simp [commonNeighbors, ← neighborFinset_def, h.regular v] · simp only [Matrix.one_apply_ne' hn.symm, ne_eq, hn] by_cases ha : G.Adj v w <;> simp only [ha, ite_true, ite_false, add_zero, zero_add, nsmul_eq_mul, smul_zero, mul_one, not_true_eq_false, not_false_eq_true, and_false, and_self] · rw [h.of_adj v w ha] · rw [h.of_not_adj hn ha] end SimpleGraph
TopCommRingCat.lean
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Category.Ring.Basic import Mathlib.Topology.Category.TopCat.Basic import Mathlib.Topology.Algebra.Ring.Basic /-! # Category of topological commutative rings We introduce the category `TopCommRingCat` of topological commutative rings together with the relevant forgetful functors to topological spaces and commutative rings. -/ universe u open CategoryTheory /-- A bundled topological commutative ring. -/ structure TopCommRingCat where /-- carrier of a topological commutative ring. -/ α : Type u [isCommRing : CommRing α] [isTopologicalSpace : TopologicalSpace α] [isTopologicalRing : IsTopologicalRing α] namespace TopCommRingCat instance : Inhabited TopCommRingCat := ⟨⟨PUnit⟩⟩ instance : CoeSort TopCommRingCat (Type u) := ⟨TopCommRingCat.α⟩ attribute [instance] isCommRing isTopologicalSpace isTopologicalRing instance : Category TopCommRingCat.{u} where Hom R S := { f : R →+* S // Continuous f } id R := ⟨RingHom.id R, by rw [RingHom.id]; continuity⟩ comp f g := ⟨g.val.comp f.val, by -- TODO automate cases f cases g continuity⟩ instance (R S : TopCommRingCat.{u}) : FunLike { f : R →+* S // Continuous f } R S where coe f := f.val coe_injective' _ _ h := Subtype.ext (DFunLike.coe_injective h) instance : ConcreteCategory TopCommRingCat.{u} fun R S => { f : R →+* S // Continuous f } where hom f := f ofHom f := f /-- Construct a bundled `TopCommRingCat` from the underlying type and the appropriate typeclasses. -/ abbrev of (X : Type u) [CommRing X] [TopologicalSpace X] [IsTopologicalRing X] : TopCommRingCat := ⟨X⟩ theorem coe_of (X : Type u) [CommRing X] [TopologicalSpace X] [IsTopologicalRing X] : (of X : Type u) = X := rfl instance hasForgetToCommRingCat : HasForget₂ TopCommRingCat CommRingCat := HasForget₂.mk' (fun R => CommRingCat.of R) (fun _ => rfl) (fun f => CommRingCat.ofHom f.val) HEq.rfl instance forgetToCommRingCatTopologicalSpace (R : TopCommRingCat) : TopologicalSpace ((forget₂ TopCommRingCat CommRingCat).obj R) := R.isTopologicalSpace /-- The forgetful functor to `TopCat`. -/ instance hasForgetToTopCat : HasForget₂ TopCommRingCat TopCat := HasForget₂.mk' (fun R => TopCat.of R) (fun _ => rfl) (fun f => TopCat.ofHom ⟨⇑f.1, f.2⟩) HEq.rfl instance forgetToTopCatCommRing (R : TopCommRingCat) : CommRing ((forget₂ TopCommRingCat TopCat).obj R) := R.isCommRing instance forgetToTopCatTopologicalRing (R : TopCommRingCat) : IsTopologicalRing ((forget₂ TopCommRingCat TopCat).obj R) := R.isTopologicalRing /-- The forgetful functors to `Type` do not reflect isomorphisms, but the forgetful functor from `TopCommRingCat` to `TopCat` does. -/ instance : (forget₂ TopCommRingCat.{u} TopCat.{u}).ReflectsIsomorphisms where reflects {X Y} f _ := by -- We have an isomorphism in `TopCat`, let i_Top := asIso ((forget₂ TopCommRingCat TopCat).map f) -- and a `RingEquiv`. let e_Ring : X ≃+* Y := { f.1, ((forget TopCat).mapIso i_Top).toEquiv with } -- Putting these together we obtain the isomorphism we're after: exact ⟨⟨⟨e_Ring.symm, i_Top.inv.hom.2⟩, ⟨by ext x exact e_Ring.left_inv x, by ext x exact e_Ring.right_inv x⟩⟩⟩ end TopCommRingCat
sylow.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 prime bigop finset fingroup morphism. From mathcomp Require Import automorphism quotient action cyclic gproduct . From mathcomp Require Import gfunctor commutator pgroup center nilpotent. (******************************************************************************) (* The Sylow theorem and its consequences, including the Frattini argument, *) (* the nilpotence of p-groups, and the Baer-Suzuki theorem. *) (* This file also defines: *) (* Zgroup G == G is a Z-group, i.e., has only cyclic Sylow p-subgroups. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. (* The mod p lemma for the action of p-groups. *) Section ModP. Variable (aT : finGroupType) (sT : finType) (D : {group aT}). Variable to : action D sT. Lemma pgroup_fix_mod (p : nat) (G : {group aT}) (S : {set sT}) : p.-group G -> [acts G, on S | to] -> #|S| = #|'Fix_(S | to)(G)| %[mod p]. Proof. move=> pG nSG; have sGD: G \subset D := acts_dom nSG. apply/eqP; rewrite -(cardsID 'Fix_to(G)) eqn_mod_dvd (leq_addr, addKn) //. have: [acts G, on S :\: 'Fix_to(G) | to]; last move/acts_sum_card_orbit <-. rewrite actsD // -(setIidPr sGD); apply: subset_trans (acts_subnorm_fix _ _). by rewrite setIS ?normG. apply: dvdn_sum => _ /imsetP[x /setDP[_ nfx] ->]. have [k oGx]: {k | #|orbit to G x| = (p ^ k)%N}. by apply: p_natP; apply: pnat_dvd pG; rewrite card_orbit_in ?dvdn_indexg. case: k oGx => [/card_orbit1 fix_x | k ->]; last by rewrite expnS dvdn_mulr. by case/afixP: nfx => a Ga; apply/set1P; rewrite -fix_x mem_orbit. Qed. End ModP. Section ModularGroupAction. Variables (aT rT : finGroupType) (D : {group aT}) (R : {group rT}). Variables (to : groupAction D R) (p : nat). Implicit Types (G H : {group aT}) (M : {group rT}). Lemma nontrivial_gacent_pgroup G M : p.-group G -> p.-group M -> {acts G, on group M | to} -> M :!=: 1 -> 'C_(M | to)(G) :!=: 1. Proof. move=> pG pM [nMG sMR] ntM; have [p_pr p_dv_M _] := pgroup_pdiv pM ntM. rewrite -cardG_gt1 (leq_trans (prime_gt1 p_pr)) 1?dvdn_leq ?cardG_gt0 //= /dvdn. by rewrite gacentE ?(acts_dom nMG) // setIA (setIidPl sMR) -pgroup_fix_mod. Qed. Lemma pcore_sub_astab_irr G M : p.-group M -> M \subset R -> acts_irreducibly G M to -> 'O_p(G) \subset 'C_G(M | to). Proof. move=> pM sMR /mingroupP[/andP[ntM nMG] minM]. have /andP[sGpG nGpG]: 'O_p(G) <| G := gFnormal _ G. have sGD := acts_dom nMG; have sGpD: 'O_p(G) \subset D := gFsub_trans _ sGD. rewrite subsetI sGpG -gacentC //=; apply/setIidPl; apply: minM (subsetIl _ _). rewrite nontrivial_gacent_pgroup ?pcore_pgroup //=; last first. by split; rewrite ?gFsub_trans. by apply: subset_trans (acts_subnorm_subgacent sGpD nMG); rewrite subsetI subxx. Qed. Lemma pcore_faithful_irr_act G M : p.-group M -> M \subset R -> acts_irreducibly G M to -> [faithful G, on M | to] -> 'O_p(G) = 1. Proof. move=> pM sMR irrG ffulG; apply/trivgP; apply: subset_trans ffulG. exact: pcore_sub_astab_irr. Qed. End ModularGroupAction. Section Sylow. Variables (p : nat) (gT : finGroupType) (G : {group gT}). Implicit Types P Q H K : {group gT}. Theorem Sylow's_theorem : [/\ forall P, [max P | p.-subgroup(G) P] = p.-Sylow(G) P, [transitive G, on 'Syl_p(G) | 'JG], forall P, p.-Sylow(G) P -> #|'Syl_p(G)| = #|G : 'N_G(P)| & prime p -> #|'Syl_p(G)| %% p = 1%N]. Proof. pose maxp A P := [max P | p.-subgroup(A) P]; pose S := [set P | maxp G P]. pose oG := orbit 'JG%act G. have actS: [acts G, on S | 'JG]. apply/subsetP=> x Gx; rewrite 3!inE; apply/subsetP=> P; rewrite 3!inE. exact: max_pgroupJ. have S_pG P: P \in S -> P \subset G /\ p.-group P. by rewrite inE => /maxgroupp/andP[]. have SmaxN P Q: Q \in S -> Q \subset 'N(P) -> maxp 'N_G(P) Q. rewrite inE => /maxgroupP[/andP[sQG pQ] maxQ] nPQ. apply/maxgroupP; rewrite /psubgroup subsetI sQG nPQ. by split=> // R; rewrite subsetI -andbA andbCA => /andP[_]; apply: maxQ. have nrmG P: P \subset G -> P <| 'N_G(P). by move=> sPG; rewrite /normal subsetIr subsetI sPG normG. have sylS P: P \in S -> p.-Sylow('N_G(P)) P. move=> S_P; have [sPG pP] := S_pG P S_P. by rewrite normal_max_pgroup_Hall ?nrmG //; apply: SmaxN; rewrite ?normG. have{SmaxN} defCS P: P \in S -> 'Fix_(S |'JG)(P) = [set P]. move=> S_P; apply/setP=> Q; rewrite {1}in_setI {1}afixJG. apply/andP/set1P=> [[S_Q nQP]|->{Q}]; last by rewrite normG. apply/esym/val_inj; case: (S_pG Q) => //= sQG _. by apply: uniq_normal_Hall (SmaxN Q _ _ _) => //=; rewrite ?sylS ?nrmG. have{defCS} oG_mod: {in S &, forall P Q, #|oG P| = (Q \in oG P) %[mod p]}. move=> P Q S_P S_Q; have [sQG pQ] := S_pG _ S_Q. have soP_S: oG P \subset S by rewrite acts_sub_orbit. have /pgroup_fix_mod-> //: [acts Q, on oG P | 'JG]. apply/actsP=> x /(subsetP sQG) Gx R; apply: orbit_transl. exact: mem_orbit. rewrite -{1}(setIidPl soP_S) -setIA defCS // (cardsD1 Q) setDE. by rewrite -setIA setICr setI0 cards0 addn0 inE set11 andbT. have [P S_P]: exists P, P \in S. have: p.-subgroup(G) 1 by rewrite /psubgroup sub1G pgroup1. by case/(@maxgroup_exists _ (p.-subgroup(G))) => P; exists P; rewrite inE. have trS: [transitive G, on S | 'JG]. apply/imsetP; exists P => //; apply/eqP. rewrite eqEsubset andbC acts_sub_orbit // S_P; apply/subsetP=> Q S_Q. have /[1!inE] /maxgroupP[/andP[_ pP]] := S_P. have [-> max1 | ntP _] := eqVneq P 1%G. move/andP/max1: (S_pG _ S_Q) => Q1. by rewrite (group_inj (Q1 (sub1G Q))) orbit_refl. have:= oG_mod _ _ S_P S_P; rewrite (oG_mod _ Q) // orbit_refl. have p_gt1: p > 1 by apply: prime_gt1; case/pgroup_pdiv: pP. by case: (Q \in oG P) => //; rewrite mod0n modn_small. have oS1: prime p -> #|S| %% p = 1%N. move/prime_gt1 => p_gt1. by rewrite -(atransP trS P S_P) (oG_mod P P) // orbit_refl modn_small. have oSiN Q: Q \in S -> #|S| = #|G : 'N_G(Q)|. by move=> S_Q; rewrite -(atransP trS Q S_Q) card_orbit astab1JG. have sylP: p.-Sylow(G) P. rewrite pHallE; case: (S_pG P) => // -> /= pP. case p_pr: (prime p); last first. rewrite p_part lognE p_pr /= -trivg_card1; apply/idPn=> ntP. by case/pgroup_pdiv: pP p_pr => // ->. rewrite -(LagrangeI G 'N(P)) /= mulnC partnM ?cardG_gt0 // part_p'nat. by rewrite mul1n (card_Hall (sylS P S_P)). by rewrite p'natE // -indexgI -oSiN // /dvdn oS1. have eqS Q: maxp G Q = p.-Sylow(G) Q. apply/idP/idP=> [S_Q|]; last exact: Hall_max. have{} S_Q: Q \in S by rewrite inE. rewrite pHallE -(card_Hall sylP); case: (S_pG Q) => // -> _ /=. by case: (atransP2 trS S_P S_Q) => x _ ->; rewrite cardJg. have ->: 'Syl_p(G) = S by apply/setP=> Q; rewrite 2!inE. by split=> // Q sylQ; rewrite -oSiN ?inE ?eqS. Qed. Lemma max_pgroup_Sylow P : [max P | p.-subgroup(G) P] = p.-Sylow(G) P. Proof. by case Sylow's_theorem. Qed. Lemma Sylow_superset Q : Q \subset G -> p.-group Q -> {P : {group gT} | p.-Sylow(G) P & Q \subset P}. Proof. move=> sQG pQ. have [|P] := @maxgroup_exists _ (p.-subgroup(G)) Q; first exact/andP. by rewrite max_pgroup_Sylow; exists P. Qed. Lemma Sylow_exists : {P : {group gT} | p.-Sylow(G) P}. Proof. by case: (Sylow_superset (sub1G G) (pgroup1 _ p)) => P; exists P. Qed. Lemma Syl_trans : [transitive G, on 'Syl_p(G) | 'JG]. Proof. by case Sylow's_theorem. Qed. Lemma Sylow_trans P Q : p.-Sylow(G) P -> p.-Sylow(G) Q -> exists2 x, x \in G & Q :=: P :^ x. Proof. move=> sylP sylQ; have /[!inE] := (atransP2 Syl_trans) P Q. by case=> // x Gx ->; exists x. Qed. Lemma Sylow_subJ P Q : p.-Sylow(G) P -> Q \subset G -> p.-group Q -> exists2 x, x \in G & Q \subset P :^ x. Proof. move=> sylP sQG pQ; have [Px sylPx] := Sylow_superset sQG pQ. by have [x Gx ->] := Sylow_trans sylP sylPx; exists x. Qed. Lemma Sylow_Jsub P Q : p.-Sylow(G) P -> Q \subset G -> p.-group Q -> exists2 x, x \in G & Q :^ x \subset P. Proof. move=> sylP sQG pQ; have [x Gx] := Sylow_subJ sylP sQG pQ. by exists x^-1; rewrite (groupV, sub_conjgV). Qed. Lemma card_Syl P : p.-Sylow(G) P -> #|'Syl_p(G)| = #|G : 'N_G(P)|. Proof. by case: Sylow's_theorem P. Qed. Lemma card_Syl_dvd : #|'Syl_p(G)| %| #|G|. Proof. by case Sylow_exists => P /card_Syl->; apply: dvdn_indexg. Qed. Lemma card_Syl_mod : prime p -> #|'Syl_p(G)| %% p = 1%N. Proof. by case Sylow's_theorem. Qed. Lemma Frattini_arg H P : G <| H -> p.-Sylow(G) P -> G * 'N_H(P) = H. Proof. case/andP=> sGH nGH sylP; rewrite -normC ?subIset ?nGH ?orbT // -astab1JG. move/subgroup_transitiveP: Syl_trans => ->; rewrite ?inE //. apply/imsetP; exists P; rewrite ?inE //. apply/eqP; rewrite eqEsubset -{1}((atransP Syl_trans) P) ?inE // imsetS //=. by apply/subsetP=> _ /imsetP[x Hx ->]; rewrite inE -(normsP nGH x Hx) pHallJ2. Qed. End Sylow. Section MoreSylow. Variables (gT : finGroupType) (p : nat). Implicit Types G H P : {group gT}. Lemma Sylow_setI_normal G H P : G <| H -> p.-Sylow(H) P -> p.-Sylow(G) (G :&: P). Proof. case/normalP=> sGH nGH sylP; have [Q sylQ] := Sylow_exists p G. have /maxgroupP[/andP[sQG pQ] maxQ] := Hall_max sylQ. have [R sylR sQR] := Sylow_superset (subset_trans sQG sGH) pQ. have [[x Hx ->] pR] := (Sylow_trans sylR sylP, pHall_pgroup sylR). rewrite -(nGH x Hx) -conjIg pHallJ2. have /maxQ-> //: Q \subset G :&: R by rewrite subsetI sQG. by rewrite /psubgroup subsetIl (pgroupS _ pR) ?subsetIr. Qed. Lemma normal_sylowP G : reflect (exists2 P : {group gT}, p.-Sylow(G) P & P <| G) (#|'Syl_p(G)| == 1%N). Proof. apply: (iffP idP) => [syl1 | [P sylP nPG]]; last first. by rewrite (card_Syl sylP) (setIidPl _) (indexgg, normal_norm). have [P sylP] := Sylow_exists p G; exists P => //. rewrite /normal (pHall_sub sylP); apply/setIidPl; apply/eqP. rewrite eqEcard subsetIl -(LagrangeI G 'N(P)) -indexgI /=. by rewrite -(card_Syl sylP) (eqP syl1) muln1. Qed. Lemma trivg_center_pgroup P : p.-group P -> 'Z(P) = 1 -> P :=: 1. Proof. move=> pP Z1; apply/eqP/idPn=> ntP. have{ntP} [p_pr p_dv_P _] := pgroup_pdiv pP ntP. suff: p %| #|'Z(P)| by rewrite Z1 cards1 gtnNdvd ?prime_gt1. by rewrite /center /dvdn -afixJ -pgroup_fix_mod // astabsJ normG. Qed. Lemma p2group_abelian P : p.-group P -> logn p #|P| <= 2 -> abelian P. Proof. move=> pP lePp2; pose Z := 'Z(P); have sZP: Z \subset P := center_sub P. have [/(trivg_center_pgroup pP) ->|] := eqVneq Z 1; first exact: abelian1. case/(pgroup_pdiv (pgroupS sZP pP)) => p_pr _ [k oZ]. apply: cyclic_center_factor_abelian. have [->|] := eqVneq (P / Z) 1; first exact: cyclic1. have pPq := quotient_pgroup 'Z(P) pP; case/(pgroup_pdiv pPq) => _ _ [j oPq]. rewrite prime_cyclic // oPq; case: j oPq lePp2 => //= j. rewrite card_quotient ?gFnorm //. by rewrite -(Lagrange sZP) lognM // => ->; rewrite oZ !pfactorK ?addnS. Qed. Lemma card_p2group_abelian P : prime p -> #|P| = (p ^ 2)%N -> abelian P. Proof. move=> primep oP; have pP: p.-group P by rewrite /pgroup oP pnatX pnat_id. by rewrite (p2group_abelian pP) // oP pfactorK. Qed. Lemma Sylow_transversal_gen (T : {set {group gT}}) G : (forall P, P \in T -> P \subset G) -> (forall p, p \in \pi(G) -> exists2 P, P \in T & p.-Sylow(G) P) -> << \bigcup_(P in T) P >> = G. Proof. move=> G_T T_G; apply/eqP; rewrite eqEcard gen_subG. apply/andP; split; first exact/bigcupsP. apply: dvdn_leq (cardG_gt0 _) _; apply/dvdn_partP=> // q /T_G[P T_P sylP]. by rewrite -(card_Hall sylP); apply: cardSg; rewrite sub_gen // bigcup_sup. Qed. Lemma Sylow_gen G : <<\bigcup_(P : {group gT} | Sylow G P) P>> = G. Proof. set T := [set P : {group gT} | Sylow G P]. rewrite -{2}(@Sylow_transversal_gen T G) => [|P | q _]. - by congr <<_>>; apply: eq_bigl => P; rewrite inE. - by rewrite inE => /and3P[]. by case: (Sylow_exists q G) => P sylP; exists P; rewrite // inE (p_Sylow sylP). Qed. End MoreSylow. Section SomeHall. Variable gT : finGroupType. Implicit Types (p : nat) (pi : nat_pred) (G H K P R : {group gT}). Lemma Hall_pJsub p pi G H P : pi.-Hall(G) H -> p \in pi -> P \subset G -> p.-group P -> exists2 x, x \in G & P :^ x \subset H. Proof. move=> hallH pi_p sPG pP. have [S sylS] := Sylow_exists p H; have sylS_G := subHall_Sylow hallH pi_p sylS. have [x Gx sPxS] := Sylow_Jsub sylS_G sPG pP; exists x => //. exact: subset_trans sPxS (pHall_sub sylS). Qed. Lemma Hall_psubJ p pi G H P : pi.-Hall(G) H -> p \in pi -> P \subset G -> p.-group P -> exists2 x, x \in G & P \subset H :^ x. Proof. move=> hallH pi_p sPG pP; have [x Gx sPxH] := Hall_pJsub hallH pi_p sPG pP. by exists x^-1; rewrite ?groupV -?sub_conjg. Qed. Lemma Hall_setI_normal pi G K H : K <| G -> pi.-Hall(G) H -> pi.-Hall(K) (H :&: K). Proof. move=> nsKG hallH; have [sHG piH _] := and3P hallH. have [sHK_H sHK_K] := (subsetIl H K, subsetIr H K). rewrite pHallE sHK_K /= -(part_pnat_id (pgroupS sHK_H piH)); apply/eqP. rewrite (widen_partn _ (subset_leq_card sHK_K)); apply: eq_bigr => p pi_p. have [P sylP] := Sylow_exists p H. have sylPK := Sylow_setI_normal nsKG (subHall_Sylow hallH pi_p sylP). rewrite -!p_part -(card_Hall sylPK); symmetry; apply: card_Hall. by rewrite (pHall_subl _ sHK_K) //= setIC setSI ?(pHall_sub sylP). Qed. Lemma coprime_mulG_setI_norm H G K R : K * R = G -> G \subset 'N(H) -> coprime #|K| #|R| -> (K :&: H) * (R :&: H) = G :&: H. Proof. move=> defG nHG coKR; apply/eqP; rewrite eqEcard mulG_subG /= -defG. rewrite !setSI ?mulG_subl ?mulG_subr //=. rewrite coprime_cardMg ?(coKR, coprimeSg (subsetIl _ _), coprime_sym) //=. pose pi := \pi(K); have piK: pi.-group K by apply: pgroup_pi. have pi'R: pi^'.-group R by rewrite /pgroup -coprime_pi' /=. have [hallK hallR] := coprime_mulpG_Hall defG piK pi'R. have nsHG: H :&: G <| G by rewrite /normal subsetIr normsI ?normG. rewrite -!(setIC H) defG -(partnC pi (cardG_gt0 _)). rewrite -(card_Hall (Hall_setI_normal nsHG hallR)) /= setICA. rewrite -(card_Hall (Hall_setI_normal nsHG hallK)) /= setICA. by rewrite -defG (setIidPl (mulG_subl _ _)) (setIidPl (mulG_subr _ _)). Qed. End SomeHall. Section Nilpotent. Variable gT : finGroupType. Implicit Types (G H K P L : {group gT}) (p q : nat). Lemma pgroup_nil p P : p.-group P -> nilpotent P. Proof. move: {2}_.+1 (ltnSn #|P|) => n. elim: n gT P => // n IHn pT P; rewrite ltnS=> lePn pP. have [Z1 | ntZ] := eqVneq 'Z(P) 1. by rewrite (trivg_center_pgroup pP Z1) nilpotent1. rewrite -quotient_center_nil IHn ?morphim_pgroup // (leq_trans _ lePn) //. rewrite card_quotient ?normal_norm ?center_normal // -divgS ?subsetIl //. by rewrite ltn_Pdiv // ltnNge -trivg_card_le1. Qed. Lemma pgroup_sol p P : p.-group P -> solvable P. Proof. by move/pgroup_nil; apply: nilpotent_sol. Qed. Lemma small_nil_class G : nil_class G <= 5 -> nilpotent G. Proof. move=> leK5; case: (ltnP 5 #|G|) => [lt5G | leG5 {leK5}]. by rewrite nilpotent_class (leq_ltn_trans leK5). apply: pgroup_nil (pdiv #|G|) _ _; apply/andP; split=> //. by case: #|G| leG5 => //; do 5!case=> //. Qed. Lemma nil_class2 G : (nil_class G <= 2) = (G^`(1) \subset 'Z(G)). Proof. rewrite subsetI der_sub; apply/idP/commG1P=> [clG2 | L3G1]. by apply/(lcn_nil_classP 2); rewrite ?small_nil_class ?(leq_trans clG2). by apply/(lcn_nil_classP 2) => //; apply/lcnP; exists 2. Qed. Lemma nil_class3 G : (nil_class G <= 3) = ('L_3(G) \subset 'Z(G)). Proof. rewrite subsetI lcn_sub; apply/idP/commG1P=> [clG3 | L4G1]. by apply/(lcn_nil_classP 3); rewrite ?small_nil_class ?(leq_trans clG3). by apply/(lcn_nil_classP 3) => //; apply/lcnP; exists 3. Qed. Lemma nilpotent_maxp_normal pi G H : nilpotent G -> [max H | pi.-subgroup(G) H] -> H <| G. Proof. move=> nilG /maxgroupP[/andP[sHG piH] maxH]. have nHN: H <| 'N_G(H) by rewrite normal_subnorm. have{maxH} hallH: pi.-Hall('N_G(H)) H. apply: normal_max_pgroup_Hall => //; apply/maxgroupP. rewrite /psubgroup normal_sub // piH; split=> // K. by rewrite subsetI -andbA andbCA => /andP[_ /maxH]. rewrite /normal sHG; apply/setIidPl/esym. apply: nilpotent_sub_norm; rewrite ?subsetIl ?setIS //= char_norms //. by congr (_ \char _): (pcore_char pi 'N_G(H)); apply: normal_Hall_pcore. Qed. Lemma nilpotent_Hall_pcore pi G H : nilpotent G -> pi.-Hall(G) H -> H :=: 'O_pi(G). Proof. move=> nilG hallH; have maxH := Hall_max hallH; apply/eqP. rewrite eqEsubset pcore_max ?(pHall_pgroup hallH) //. by rewrite (normal_sub_max_pgroup maxH) ?pcore_pgroup ?pcore_normal. exact: nilpotent_maxp_normal maxH. Qed. Lemma nilpotent_pcore_Hall pi G : nilpotent G -> pi.-Hall(G) 'O_pi(G). Proof. move=> nilG; case: (@maxgroup_exists _ (psubgroup pi G) 1) => [|H maxH _]. by rewrite /psubgroup sub1G pgroup1. have hallH := normal_max_pgroup_Hall maxH (nilpotent_maxp_normal nilG maxH). by rewrite -(nilpotent_Hall_pcore nilG hallH). Qed. Lemma nilpotent_pcoreC pi G : nilpotent G -> 'O_pi(G) \x 'O_pi^'(G) = G. Proof. move=> nilG; have trO: 'O_pi(G) :&: 'O_pi^'(G) = 1. by apply: coprime_TIg; apply: (@pnat_coprime pi); apply: pcore_pgroup. rewrite dprodE //. apply/eqP; rewrite eqEcard mul_subG ?pcore_sub // (TI_cardMg trO). by rewrite !(card_Hall (nilpotent_pcore_Hall _ _)) // partnC ?leqnn. rewrite (sameP commG1P trivgP) -trO subsetI commg_subl commg_subr. by rewrite !gFsub_trans ?gFnorm. Qed. Lemma sub_nilpotent_cent2 H K G : nilpotent G -> K \subset G -> H \subset G -> coprime #|K| #|H| -> H \subset 'C(K). Proof. move=> nilG sKG sHG; rewrite coprime_pi' // => p'H. have sub_Gp := sub_Hall_pcore (nilpotent_pcore_Hall _ nilG). have [_ _ cGpp' _] := dprodP (nilpotent_pcoreC \pi(K) nilG). by apply: centSS cGpp'; rewrite sub_Gp ?pgroup_pi. Qed. Lemma pi_center_nilpotent G : nilpotent G -> \pi('Z(G)) = \pi(G). Proof. move=> nilG; apply/eq_piP => /= p. apply/idP/idP=> [|pG]; first exact: (piSg (center_sub _)). move: (pG); rewrite !mem_primes !cardG_gt0; case/andP=> p_pr _. pose Z := 'O_p(G) :&: 'Z(G); have ntZ: Z != 1. rewrite meet_center_nil ?pcore_normal // trivg_card_le1 -ltnNge. rewrite (card_Hall (nilpotent_pcore_Hall p nilG)) p_part. by rewrite (ltn_exp2l 0 _ (prime_gt1 p_pr)) logn_gt0. have pZ: p.-group Z := pgroupS (subsetIl _ _) (pcore_pgroup _ _). have{ntZ pZ} [_ pZ _] := pgroup_pdiv pZ ntZ. by rewrite p_pr (dvdn_trans pZ) // cardSg ?subsetIr. Qed. Lemma Sylow_subnorm p G P : p.-Sylow('N_G(P)) P = p.-Sylow(G) P. Proof. apply/idP/idP=> sylP; last first. apply: pHall_subl (subsetIl _ _) (sylP). by rewrite subsetI normG (pHall_sub sylP). have [/subsetIP[sPG sPN] pP _] := and3P sylP. have [Q sylQ sPQ] := Sylow_superset sPG pP; have [sQG pQ _] := and3P sylQ. rewrite -(nilpotent_sub_norm (pgroup_nil pQ) sPQ) {sylQ}//. rewrite subEproper eq_sym eqEcard subsetI sPQ sPN dvdn_leq //. rewrite -(part_pnat_id (pgroupS (subsetIl _ _) pQ)) (card_Hall sylP). by rewrite partn_dvd // cardSg ?setSI. Qed. End Nilpotent. Lemma nil_class_pgroup (gT : finGroupType) (p : nat) (P : {group gT}) : p.-group P -> nil_class P <= maxn 1 (logn p #|P|).-1. Proof. move=> pP; move def_c: (nil_class P) => c. elim: c => // c IHc in gT P def_c pP *; set e := logn p _. have nilP := pgroup_nil pP; have sZP := center_sub P. have [e_le2 | e_gt2] := leqP e 2. by rewrite -def_c leq_max nil_class1 (p2group_abelian pP). have pPq: p.-group (P / 'Z(P)) by apply: quotient_pgroup. rewrite -(subnKC e_gt2) ltnS (leq_trans (IHc _ _ _ pPq)) //. by rewrite nil_class_quotient_center ?def_c. rewrite geq_max /= -add1n -leq_subLR -subn1 -subnDA -subSS leq_sub2r //. rewrite ltn_log_quotient //= -(setIidPr sZP) meet_center_nil //. by rewrite -nil_class0 def_c. Qed. Definition Zgroup (gT : finGroupType) (A : {set gT}) := [forall (V : {group gT} | Sylow A V), cyclic V]. Section Zgroups. Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}). Implicit Types G H K : {group gT}. Lemma ZgroupS G H : H \subset G -> Zgroup G -> Zgroup H. Proof. move=> sHG /forallP zgG; apply/forall_inP=> V /SylowP[p p_pr /and3P[sVH]]. case/(Sylow_superset (subset_trans sVH sHG))=> P sylP sVP _. by have:= zgG P; rewrite (p_Sylow sylP); apply: cyclicS. Qed. Lemma morphim_Zgroup G : Zgroup G -> Zgroup (f @* G). Proof. move=> zgG; wlog sGD: G zgG / G \subset D. by rewrite -morphimIdom; apply; rewrite (ZgroupS _ zgG, subsetIl) ?subsetIr. apply/forall_inP=> fV /SylowP[p pr_p sylfV]. have [P sylP] := Sylow_exists p G. have [|z _ ->] := @Sylow_trans p _ _ (f @* P)%G _ _ sylfV. by apply: morphim_pHall (sylP); apply: subset_trans (pHall_sub sylP) sGD. by rewrite cyclicJ morphim_cyclic ?(forall_inP zgG) //; apply/SylowP; exists p. Qed. Lemma nil_Zgroup_cyclic G : Zgroup G -> nilpotent G -> cyclic G. Proof. have [n] := ubnP #|G|; elim: n G => // n IHn G /ltnSE-leGn ZgG nilG. have [->|[p pr_p pG]] := trivgVpdiv G; first by rewrite -cycle1 cycle_cyclic. have /dprodP[_ defG Cpp' _] := nilpotent_pcoreC p nilG. have /cyclicP[x def_p]: cyclic 'O_p(G). have:= forallP ZgG 'O_p(G)%G. by rewrite (p_Sylow (nilpotent_pcore_Hall p nilG)). have /cyclicP[x' def_p']: cyclic 'O_p^'(G). have sp'G := pcore_sub p^' G. apply: IHn (leq_trans _ leGn) (ZgroupS sp'G _) (nilpotentS sp'G _) => //. rewrite proper_card // properEneq sp'G andbT; case: eqP => //= def_p'. by have:= pcore_pgroup p^' G; rewrite def_p' /pgroup p'natE ?pG. apply/cyclicP; exists (x * x'); rewrite -{}defG def_p def_p' cycleM //. by red; rewrite -(centsP Cpp') // (def_p, def_p') cycle_id. by rewrite /order -def_p -def_p' (@pnat_coprime p) //; apply: pcore_pgroup. Qed. End Zgroups. Arguments Zgroup {gT} A%_g. Section NilPGroups. Variables (p : nat) (gT : finGroupType). Implicit Type G P N : {group gT}. (* B & G 1.22 p.9 *) Lemma normal_pgroup r P N : p.-group P -> N <| P -> r <= logn p #|N| -> exists Q : {group gT}, [/\ Q \subset N, Q <| P & #|Q| = (p ^ r)%N]. Proof. elim: r gT P N => [|r IHr] gTr P N pP nNP le_r. by exists (1%G : {group gTr}); rewrite sub1G normal1 cards1. have [NZ_1 | ntNZ] := eqVneq (N :&: 'Z(P)) 1. by rewrite (TI_center_nil (pgroup_nil pP)) // cards1 logn1 in le_r. have: p.-group (N :&: 'Z(P)) by apply: pgroupS pP; rewrite /= setICA subsetIl. case/pgroup_pdiv=> // p_pr /Cauchy[// | z]. rewrite -cycle_subG !subsetI => /and3P[szN szP cPz] ozp _. have{cPz} nzP: P \subset 'N(<[z]>) by rewrite cents_norm // centsC. have: N / <[z]> <| P / <[z]> by rewrite morphim_normal. case/IHr=> [||Qb [sQNb nQPb]]; first exact: morphim_pgroup. rewrite card_quotient ?(subset_trans (normal_sub nNP)) // -ltnS. apply: (leq_trans le_r); rewrite -(Lagrange szN) [#|_|]ozp. by rewrite lognM // ?prime_gt0 // logn_prime ?eqxx. case/(inv_quotientN _): nQPb sQNb => [|Q -> szQ nQP]; first exact/andP. have nzQ := subset_trans (normal_sub nQP) nzP. rewrite quotientSGK // card_quotient // => sQN izQ. by exists Q; split=> //; rewrite expnS -izQ -ozp Lagrange. Qed. Theorem Baer_Suzuki x G : x \in G -> (forall y, y \in G -> p.-group <<[set x; x ^ y]>>) -> x \in 'O_p(G). Proof. have [n] := ubnP #|G|; elim: n G x => // n IHn G x /ltnSE-leGn Gx pE. set E := x ^: G; have{} pE: {in E &, forall x1 x2, p.-group <<[set x1; x2]>>}. move=> _ _ /imsetP[y1 Gy1 ->] /imsetP[y2 Gy2 ->]. rewrite -(mulgKV y1 y2) conjgM -2!conjg_set1 -conjUg genJ pgroupJ. by rewrite pE // groupMl ?groupV. have sEG: <<E>> \subset G by rewrite gen_subG class_subG. have nEG: G \subset 'N(E) by apply: class_norm. have Ex: x \in E by apply: class_refl. have [P Px sylP]: exists2 P : {group gT}, x \in P & p.-Sylow(<<E>>) P. have sxxE: <<[set x; x]>> \subset <<E>> by rewrite genS // setUid sub1set. have{sxxE} [P sylP sxxP] := Sylow_superset sxxE (pE _ _ Ex Ex). by exists P => //; rewrite (subsetP sxxP) ?mem_gen ?setU11. case sEP: (E \subset P). apply: subsetP Ex; rewrite -gen_subG; apply: pcore_max. by apply: pgroupS (pHall_pgroup sylP); rewrite gen_subG. by rewrite /normal gen_subG class_subG // norms_gen. pose P_yD D := [pred y in E :\: P | p.-group <<y |: D>>]. pose P_D := [pred D : {set gT} | D \subset P :&: E & [exists y, P_yD D y]]. have{Ex Px}: P_D [set x]. rewrite /= sub1set inE Px Ex; apply/existsP=> /=. by case/subsetPn: sEP => y Ey Py; exists y; rewrite inE Ey Py pE. case/(@maxset_exists _ P_D)=> D /maxsetP[]; rewrite {P_yD P_D}/=. rewrite subsetI sub1set -andbA => /and3P[sDP sDE /existsP[y0]]. set B := _ |: D; rewrite inE -andbA => /and3P[Py0 Ey0 pB] maxD Dx. have sDgE: D \subset <<E>> by apply: sub_gen. have sDG: D \subset G by apply: subset_trans sEG. have sBE: B \subset E by rewrite subUset sub1set Ey0. have sBG: <<B>> \subset G by apply: subset_trans (genS _) sEG. have sDB: D \subset B by rewrite subsetUr. have defD: D :=: P :&: <<B>> :&: E. apply/eqP; rewrite eqEsubset ?subsetI sDP sDE sub_gen //=. apply/setUidPl; apply: maxD; last apply: subsetUl. rewrite subUset subsetI sDP sDE setIAC subsetIl. apply/existsP; exists y0; rewrite inE Py0 Ey0 /= setUA -/B. by rewrite -[<<_>>]joing_idl joingE setKI genGid. have nDD: D \subset 'N(D). apply/subsetP=> z Dz; rewrite inE defD. apply/subsetP=> _ /imsetP[y /setIP[PBy Ey] ->]. rewrite inE groupJ // ?inE ?(subsetP sDP) ?mem_gen ?setU1r //= memJ_norm //. exact: (subsetP (subset_trans sDG nEG)). case nDG: (G \subset 'N(D)). apply: subsetP Dx; rewrite -gen_subG pcore_max ?(pgroupS (genS _) pB) //. by rewrite /normal gen_subG sDG norms_gen. have{n leGn IHn nDG} pN: p.-group <<'N_E(D)>>. apply: pgroupS (pcore_pgroup p 'N_G(D)); rewrite gen_subG /=. apply/subsetP=> x1 /setIP[Ex1 Nx1]; apply: IHn => [||y Ny]. - apply: leq_trans leGn; rewrite proper_card // /proper subsetIl. by rewrite subsetI nDG andbF. - by rewrite inE Nx1 (subsetP sEG) ?mem_gen. have Ex1y: x1 ^ y \in E. by rewrite -mem_conjgV (normsP nEG) // groupV; case/setIP: Ny. by apply: pgroupS (genS _) (pE _ _ Ex1 Ex1y); apply/subsetP => u /[!inE]. have [y1 Ny1 Py1]: exists2 y1, y1 \in 'N_E(D) & y1 \notin P. case sNN: ('N_<<B>>('N_<<B>>(D)) \subset 'N_<<B>>(D)). exists y0 => //; have By0: y0 \in <<B>> by rewrite mem_gen ?setU11. rewrite inE Ey0 -By0 -in_setI. by rewrite -['N__(D)](nilpotent_sub_norm (pgroup_nil pB)) ?subsetIl. case/subsetPn: sNN => z /setIP[Bz NNz]; rewrite inE Bz inE. case/subsetPn=> y; rewrite mem_conjg => Dzy Dy. have:= Dzy; rewrite {1}defD; do 2![case/setIP]=> _ Bzy Ezy. have Ey: y \in E by rewrite -(normsP nEG _ (subsetP sBG z Bz)) mem_conjg. have /setIP[By Ny]: y \in 'N_<<B>>(D). by rewrite -(normP NNz) mem_conjg inE Bzy ?(subsetP nDD). exists y; first by rewrite inE Ey. by rewrite defD 2!inE Ey By !andbT in Dy. have [y2 Ny2 Dy2]: exists2 y2, y2 \in 'N_(P :&: E)(D) & y2 \notin D. case sNN: ('N_P('N_P(D)) \subset 'N_P(D)). have [z /= Ez sEzP] := Sylow_Jsub sylP (genS sBE) pB. have Gz: z \in G by apply: subsetP Ez. have /subsetPn[y Bzy Dy]: ~~ (B :^ z \subset D). apply/negP; move/subset_leq_card; rewrite cardJg cardsU1. by rewrite {1}defD 2!inE (negPf Py0) ltnn. exists y => //; apply: subsetP Bzy. rewrite -setIA setICA subsetI sub_conjg (normsP nEG) ?groupV // sBE. have nilP := pgroup_nil (pHall_pgroup sylP). by rewrite -['N__(_)](nilpotent_sub_norm nilP) ?subsetIl // -gen_subG genJ. case/subsetPn: sNN => z /setIP[Pz NNz]; rewrite 2!inE Pz. case/subsetPn=> y Dzy Dy; exists y => //; apply: subsetP Dzy. rewrite -setIA setICA subsetI sub_conjg (normsP nEG) ?groupV //. by rewrite sDE -(normP NNz); rewrite conjSg subsetI sDP. by apply: subsetP Pz; apply: (subset_trans (pHall_sub sylP)). suff{Dy2} Dy2D: y2 |: D = D by rewrite -Dy2D setU11 in Dy2. apply: maxD; last by rewrite subsetUr. case/setIP: Ny2 => PEy2 Ny2; case/setIP: Ny1 => Ey1 Ny1. rewrite subUset sub1set PEy2 subsetI sDP sDE. apply/existsP; exists y1; rewrite inE Ey1 Py1; apply: pgroupS pN. rewrite genS // !subUset !sub1set !in_setI Ey1 Ny1. by case/setIP: PEy2 => _ ->; rewrite Ny2 subsetI sDE. Qed. End NilPGroups.
Basic.lean
/- Copyright (c) 2025 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Anne Baanen -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.LinearAlgebra.Matrix.Determinant.Basic /-! # Resultant of two polynomials This file contains basic facts about resultant of two polynomials over commutative rings. ## Main definitions * `Polynomial.resultant`: The resultant of two polynomials `p` and `q` is defined as the determinant of the Sylvester matrix of `p` and `q`. ## TODO * The eventual goal is to prove the following property: `resultant (∏ a ∈ s, (X - C a)) f = ∏ a ∈ s, f.eval a`. This allows us to write the `resultant f g` as the product of terms of the form `a - b` where `a` is a root of `f` and `b` is a root of `g`. * A smaller intermediate goal is to show that the Sylvester matrix corresponds to the linear map that we will call the Sylvester map, which is `R[X]_n × R[X]_m →ₗ[R] R[X]_(n + m)` given by `(p, q) ↦ f * p + g * q`, where `R[X]_n` is `Polynomial.degreeLT` in `Mathlib.RingTheory.Polynomial.Basic`. * Resultant of two binary forms (i.e. homogeneous polynomials in two variables), after binary forms are implemented. -/ universe u namespace Polynomial section sylvester variable {R : Type u} [Semiring R] /-- The Sylvester matrix of two polynomials `f` and `g` of degrees `m` and `n` respectively is a `(n+m) × (n+m)` matrix with the coefficients of `f` and `g` arranged in a specific way. Here, `m` and `n` are free variables, not necessarily equal to the actual degrees of the polynomials `f` and `g`. -/ def sylvester (f g : R[X]) (m n : ℕ) : Matrix (Fin (n + m)) (Fin (n + m)) R := .of fun i j ↦ j.addCases (fun j₁ ↦ if (i : ℕ) ∈ Set.Icc (j₁ : ℕ) (j₁ + m) then f.coeff (i - j₁) else 0) (fun j₁ ↦ if (i : ℕ) ∈ Set.Icc (j₁ : ℕ) (j₁ + n) then g.coeff (i - j₁) else 0) variable (f g : R[X]) (m n : ℕ) @[simp] theorem sylvester_C_right (a : R) : sylvester f (C a) m 0 = Matrix.diagonal (fun _ ↦ a) := Matrix.ext fun i j ↦ j.addCases nofun fun j ↦ by rw [sylvester, Matrix.of_apply, Fin.addCases_right, Matrix.diagonal_apply] split_ifs <;> simp_all [Fin.ext_iff] end sylvester section resultant variable {R : Type u} [CommRing R] /-- The resultant of two polynomials `f` and `g` is the determinant of the Sylvester matrix of `f` and `g`. The size arguments `m` and `n` are implemented as `optParam`, meaning that the default values are `f.natDegree` and `g.natDegree` respectively, but they can also be specified to be other values. -/ def resultant (f g : R[X]) (m : ℕ := f.natDegree) (n : ℕ := g.natDegree) : R := (sylvester f g m n).det variable (f g : R[X]) (m n : ℕ) /-- For polynomial `f` and constant `a`, `Res(f, a) = a ^ m`. -/ @[simp] theorem resultant_C_zero_right (a : R) : resultant f (C a) m 0 = a ^ m := by simp [resultant] /-- For polynomial `f` and constant `a`, `Res(f, a) = a ^ m`. -/ theorem resultant_C_right (a : R) : resultant f (C a) m = a ^ m := by simp end resultant end Polynomial