filename
stringlengths
5
42
content
stringlengths
15
319k
HasFibers.lean
/- Copyright (c) 2024 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne, Paul Lezeau -/ import Mathlib.CategoryTheory.FiberedCategory.Fiber import Mathlib.CategoryTheory.FiberedCategory.Fibered /-! # Fibers of functors In this file we introduce a typeclass `HasFibers` for a functor `p : 𝒳 ⥤ 𝒮`, consisting of: - A collection of categories `Fib S` for every `S` in `𝒮` (the fiber categories) - Functors `ι : Fib S ⥤ 𝒳` such that `ι ⋙ p = const (Fib S) S - The induced functor `Fib S ⥤ Fiber p S` is an equivalence. We also provide a canonical `HasFibers` instance, which uses the standard fibers `Fiber p S` (see `Mathlib/CategoryTheory/FiberedCategory/Fiber.lean`). This makes it so that any result proven about `HasFibers` can be used for the standard fibers as well. The reason for introducing this typeclass is that in practice, when working with (pre)fibered categories one often already has a collection of categories `Fib S` for every `S` that are equivalent to the fibers `Fiber p S`. One would then like to use these categories `Fib S` directly, instead of working through this equivalence of categories. By developing an API for the `HasFibers` typeclass, this will be possible. Here is an example of when this typeclass is useful. Suppose we have a presheaf of types `F : 𝒮ᵒᵖ ⥤ Type _`. The associated fibered category then has objects `(S, a)` where `S : 𝒮` and `a` is an element of `F(S)`. The fiber category `Fiber p S` is then equivalent to the discrete category `Fib S` with objects `a` in `F(S)`. In this case, the `HasFibers` instance is given by the categories `F(S)` and the functor `ι` sends `a : F(S)` to `(S, a)` in the fibered category. ## Main API The following API is developed so that the fibers from a `HasFibers` instance can be used analogously to the standard fibers. - `Fib.homMk φ` is a lift of a morphism `φ : (ι S).obj a ⟶ (ι S).obj b` in `𝒳`, which lies over `𝟙 S`, to a morphism in the fiber over `S`. - `Fib.mk` gives an object in the fiber over `S` which is isomorphic to a given `a : 𝒳` that satisfies `p(a) = S`. The isomorphism is given by `Fib.mkIsoSelf`. - `HasFibers.mkPullback` is a version of `IsPreFibered.mkPullback` which ensures that the object lies in a given fiber. The corresponding cartesian morphism is given by `HasFibers.pullbackMap`. - `HasFibers.inducedMap` is a version of `IsCartesian.inducedMap` which gives the corresponding morphism in the fiber category. - `fiber_factorization` is the statement that any morphism in `𝒳` can be factored as a morphism in some fiber followed by a pullback. -/ universe v₃ u₃ v₂ u₂ v₁ u₁ open CategoryTheory Functor Category IsCartesian IsHomLift Fiber variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒮] [Category.{v₂} 𝒳] /-- HasFibers is an extrinsic notion of fibers on a functor `p : 𝒳 ⥤ 𝒮`. It is given by a collection of categories `Fib S` for every `S : 𝒮` (the fiber categories), each equipped with a functors `ι : Fib S ⥤ 𝒳` which map constantly to `S` on the base such that the induced functor `Fib S ⥤ Fiber p S` is an equivalence. -/ @[nolint checkUnivs] class HasFibers (p : 𝒳 ⥤ 𝒮) where /-- The type of objects of the category `Fib S` for each `S`. -/ Fib (S : 𝒮) : Type u₃ /-- `Fib S` is a category. -/ category (S : 𝒮) : Category.{v₃} (Fib S) := by infer_instance /-- The functor `ι : Fib S ⥤ 𝒳`. -/ ι (S : 𝒮) : Fib S ⥤ 𝒳 /-- The composition with the functor `p` is *equal* to the constant functor mapping to `S`. -/ comp_const (S : 𝒮) : ι S ⋙ p = (const (Fib S)).obj S /-- The induced functor from `Fib S` to the fiber of `𝒳 ⥤ 𝒮` over `S` is an equivalence. -/ equiv (S : 𝒮) : Functor.IsEquivalence (inducedFunctor (comp_const S)) := by infer_instance namespace HasFibers /-- The `HasFibers` on `p : 𝒳 ⥤ 𝒮` given by the fibers of `p` -/ def canonical (p : 𝒳 ⥤ 𝒮) : HasFibers p where Fib := Fiber p ι S := fiberInclusion comp_const S := fiberInclusion_comp_eq_const equiv S := by exact isEquivalence_of_iso (F := 𝟭 (Fiber p S)) (Iso.refl _) section variable (p : 𝒳 ⥤ 𝒮) [HasFibers p] (S : 𝒮) attribute [instance] category /-- The induced functor from `Fib p S` to the standard fiber. -/ @[simps!] def inducedFunctor : Fib p S ⥤ Fiber p S := Fiber.inducedFunctor (comp_const S) /-- The natural transformation `ι S ≅ (inducedFunctor p S) ⋙ (fiberInclusion p S)` -/ def inducedFunctor.natIso : ι S ≅ (inducedFunctor p S) ⋙ fiberInclusion := Fiber.inducedFunctorCompIsoSelf (comp_const S) lemma inducedFunctor_comp : ι S = (inducedFunctor p S) ⋙ fiberInclusion := Fiber.inducedFunctor_comp (comp_const S) instance : Functor.IsEquivalence (inducedFunctor p S) := equiv S instance : Functor.Faithful (ι (p:=p) S) := Functor.Faithful.of_iso (inducedFunctor.natIso p S).symm end section variable {p : 𝒳 ⥤ 𝒮} [HasFibers p] @[simp] lemma proj_eq {S : 𝒮} (a : Fib p S) : p.obj ((ι S).obj a) = S := by simp only [← comp_obj, comp_const, const_obj_obj] /-- The morphism `R ⟶ S` in `𝒮` obtained by projecting a morphism `φ : (ι R).obj a ⟶ (ι S).obj b`. -/ def projMap {R S : 𝒮} {a : Fib p R} {b : Fib p S} (φ : (ι R).obj a ⟶ (ι S).obj b) : R ⟶ S := eqToHom (proj_eq a).symm ≫ (p.map φ) ≫ eqToHom (proj_eq b) /-- For any homomorphism `φ` in a fiber `Fib S`, its image under `ι S` lies over `𝟙 S`. -/ instance homLift {S : 𝒮} {a b : Fib p S} (φ : a ⟶ b) : IsHomLift p (𝟙 S) ((ι S).map φ) := by apply of_fac p _ _ (proj_eq a) (proj_eq b) rw [← Functor.comp_map, Functor.congr_hom (comp_const S)] simp /-- A version of fullness of the functor `Fib S ⥤ Fiber p S` that can be used inside the category `𝒳`. -/ noncomputable def Fib.homMk {S : 𝒮} {a b : Fib p S} (φ : (ι S).obj a ⟶ (ι S).obj b) [IsHomLift p (𝟙 S) φ] : a ⟶ b := (inducedFunctor _ S).preimage (Fiber.homMk p S φ) @[simp] lemma Fib.map_homMk {S : 𝒮} {a b : Fib p S} (φ : (ι S).obj a ⟶ (ι S).obj b) [IsHomLift p (𝟙 S) φ] : (ι S).map (homMk φ) = φ := by simp [Fib.homMk, congr_hom (inducedFunctor_comp p S)] @[ext] lemma Fib.hom_ext {S : 𝒮} {a b : Fib p S} {f g : a ⟶ b} (h : (ι S).map f = (ι S).map g) : f = g := (ι S).map_injective h /-- The lift of an isomorphism `Φ : (ι S).obj a ≅ (ι S).obj b` lying over `𝟙 S` to an isomorphism in `Fib S`. -/ @[simps] noncomputable def Fib.isoMk {S : 𝒮} {a b : Fib p S} (Φ : (ι S).obj a ≅ (ι S).obj b) (hΦ : IsHomLift p (𝟙 S) Φ.hom) : a ≅ b where hom := Fib.homMk Φ.hom inv := Fib.homMk Φ.inv /-- An object in `Fib p S` isomorphic in `𝒳` to a given object `a : 𝒳` such that `p(a) = S`. -/ noncomputable def Fib.mk {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : Fib p S := Functor.objPreimage (inducedFunctor p S) (Fiber.mk ha) /-- Applying `ι S` to the preimage of `a : 𝒳` in `Fib p S` yields an object isomorphic to `a`. -/ noncomputable def Fib.mkIsoSelf {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : (ι S).obj (Fib.mk ha) ≅ a := fiberInclusion.mapIso (Functor.objObjPreimageIso (inducedFunctor p S) (Fiber.mk ha)) instance Fib.mkIsoSelfIsHomLift {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : IsHomLift p (𝟙 S) (Fib.mkIsoSelf ha).hom := (Functor.objObjPreimageIso (inducedFunctor p S) (Fiber.mk ha)).hom.2 section variable [IsPreFibered p] {R S : 𝒮} {a : 𝒳} (f : R ⟶ S) (ha : p.obj a = S) /-- The domain, taken in `Fib p R`, of some cartesian morphism lifting a given `f : R ⟶ S` in `𝒮` -/ noncomputable def mkPullback : Fib p R := Fib.mk (domain_eq p f (IsPreFibered.pullbackMap ha f)) /-- A cartesian morphism lifting `f : R ⟶ S` with domain in the image of `Fib p R` -/ noncomputable def pullbackMap : (ι R).obj (mkPullback f ha) ⟶ a := (Fib.mkIsoSelf (domain_eq p f (IsPreFibered.pullbackMap ha f))).hom ≫ (IsPreFibered.pullbackMap ha f) instance pullbackMap.isCartesian : IsCartesian p f (pullbackMap f ha) := by conv in f => rw [← id_comp f] simp only [id_comp, pullbackMap] infer_instance end section variable {R S : 𝒮} {a : 𝒳} {b b' : Fib p R} (f : R ⟶ S) (ψ : (ι R).obj b' ⟶ a) [IsCartesian p f ψ] (φ : (ι R).obj b ⟶ a) [IsHomLift p f φ] /-- Given a fibered category p, b' b in Fib R, and a pullback ψ : b ⟶ a in 𝒳, i.e. ``` b' b --ψ--> a | | | v v v R ====== R --f--> S ``` Then the induced map τ : b' ⟶ b can be lifted to the fiber over R -/ noncomputable def inducedMap : b ⟶ b' := Fib.homMk (IsCartesian.map p f ψ φ) @[reassoc] lemma inducedMap_comp : (ι R).map (inducedMap f ψ φ) ≫ ψ = φ := by simp only [inducedMap, Fib.map_homMk, IsCartesian.fac] end section variable [IsFibered p] {R S : 𝒮} {a : 𝒳} {b : Fib p R} /-- Given `a : 𝒳`, `b : Fib p R`, and a diagram ``` b --φ--> a - - | | v v R --f--> S ``` It can be factorized as ``` b --τ--> b'--ψ--> a - - - | | | v v v R ====== R --f--> S ``` with `ψ` cartesian over `f` and `τ` a map in `Fib p R`. -/ lemma fiber_factorization (ha : p.obj a = S) {b : Fib p R} (f : R ⟶ S) (φ : (ι R).obj b ⟶ a) [IsHomLift p f φ] : ∃ (b' : Fib p R) (τ : b ⟶ b') (ψ : (ι R).obj b' ⟶ a), IsStronglyCartesian p f ψ ∧ (((ι R).map τ) ≫ ψ = φ) := let ψ := pullbackMap f ha ⟨mkPullback f ha, inducedMap f ψ φ, ψ, inferInstance, inducedMap_comp f ψ φ⟩ end end end HasFibers
Embedding.lean
/- Copyright (c) 2025 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.Data.ENat.Lattice import Mathlib.Data.Fin.Tuple.Embedding import Mathlib.Data.Finite.Card import Mathlib.Data.Set.Card /-! # Existence of embeddings from finite types Let `s : Set α` be a finite set. * `Fin.Embedding.exists_embedding_disjoint_range_of_add_le_ENat_card` If `s.ncard + n ≤ ENat.card α`, then there exists an embedding `Fin n ↪ α` whose range is disjoint from `s`. * `Fin.Embedding.exists_embedding_disjoint_range_of_add_le_Nat_card` If `α` is finite and `s.ncard + n ≤ Nat.card α`, then there exists an embedding `Fin n ↪ α` whose range is disjoint from `s`. * `Fin.Embedding.restrictSurjective_of_add_le_ENatCard` If `m + n ≤ ENat.card α`, then the restriction map from `Fin (m + n) ↪ α` to `Fin m ↪ α` is surjective. * `Fin.Embedding.restrictSurjective_of_add_le_natCard` If `α` is finite and `m + n ≤ Nat.card α`, then the restriction map from `Fin (m + n) ↪ α` to `Fin m ↪ α` is surjective. -/ open Set Fin Function Function.Embedding namespace Fin.Embedding variable {α : Type*} {m n : ℕ} {s : Set α} theorem exists_embedding_disjoint_range_of_add_le_ENat_card [Finite s] (hs : s.ncard + n ≤ ENat.card α) : ∃ y : Fin n ↪ α, Disjoint s (range y) := by rsuffices ⟨y⟩ : Nonempty (Fin n ↪ (sᶜ : Set α)) · use y.trans (subtype _) rw [Set.disjoint_right] rintro _ ⟨i, rfl⟩ simpa only [← mem_compl_iff] using Subtype.coe_prop (y i) rcases finite_or_infinite α with hα | hα · let _ : Fintype α := Fintype.ofFinite α classical apply nonempty_of_card_le rwa [Fintype.card_fin, ← add_le_add_iff_left s.ncard, ← Nat.card_eq_fintype_card, Nat.card_coe_set_eq, ncard_add_ncard_compl, ← ENat.coe_le_coe, ← ENat.card_eq_coe_natCard, ENat.coe_add] · exact ⟨valEmbedding.trans s.toFinite.infinite_compl.to_subtype.natEmbedding⟩ theorem exists_embedding_disjoint_range_of_add_le_Nat_card [Finite α] (hs : s.ncard + n ≤ Nat.card α) : ∃ y : Fin n ↪ α, Disjoint s (range y) := by apply exists_embedding_disjoint_range_of_add_le_ENat_card rwa [← ENat.coe_add, ENat.card_eq_coe_natCard, ENat.coe_le_coe] theorem restrictSurjective_of_add_le_ENatCard (hn : m + n ≤ ENat.card α) : Surjective (fun (x : Fin (m + n) ↪ α) ↦ (Fin.castAddEmb n).trans x) := by intro x obtain ⟨y, hxy⟩ := exists_embedding_disjoint_range_of_add_le_ENat_card (s := range x) (by simpa [← Nat.card_coe_set_eq, Nat.card_range_of_injective x.injective]) use append hxy ext i simp [trans_apply, coe_castAddEmb, append] theorem restrictSurjective_of_add_le_natCard [Finite α] (hn : m + n ≤ Nat.card α) : Surjective (fun x : Fin (m + n) ↪ α ↦ (castAddEmb n).trans x) := by apply restrictSurjective_of_add_le_ENatCard rwa [← ENat.coe_add, ENat.card_eq_coe_natCard, ENat.coe_le_coe] end Fin.Embedding
TensorProduct.lean
/- Copyright (c) 2024 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Andrew Yang -/ import Mathlib.RingTheory.Bialgebra.Equiv import Mathlib.RingTheory.Coalgebra.TensorProduct import Mathlib.RingTheory.TensorProduct.Basic /-! # Tensor products of bialgebras We define the data in the monoidal structure on the category of bialgebras - e.g. the bialgebra instance on a tensor product of bialgebras, and the tensor product of two `BialgHom`s as a `BialgHom`. This is done by combining the corresponding API for coalgebras and algebras. -/ open scoped TensorProduct namespace Bialgebra.TensorProduct open Coalgebra.TensorProduct variable (R S A B C D : Type*) [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] [Bialgebra S A] [Bialgebra R B] [Algebra R A] [Algebra R S] [IsScalarTower R S A] lemma counit_eq_algHom_toLinearMap : Coalgebra.counit (R := S) (A := A ⊗[R] B) = ((Algebra.TensorProduct.rid _ _ _).toAlgHom.comp (Algebra.TensorProduct.map (Bialgebra.counitAlgHom S A) (Bialgebra.counitAlgHom R B))).toLinearMap := rfl lemma comul_eq_algHom_toLinearMap : Coalgebra.comul (R := S) (A := A ⊗[R] B) = ((Algebra.TensorProduct.tensorTensorTensorComm R S R S A A B B).toAlgHom.comp (Algebra.TensorProduct.map (Bialgebra.comulAlgHom S A) (Bialgebra.comulAlgHom R B))).toLinearMap := rfl noncomputable instance _root_.TensorProduct.instBialgebra : Bialgebra S (A ⊗[R] B) := by have hcounit := congr(DFunLike.coe $(counit_eq_algHom_toLinearMap R S A B)) have hcomul := congr(DFunLike.coe $(comul_eq_algHom_toLinearMap R S A B)) refine Bialgebra.mk' S (A ⊗[R] B) ?_ (fun {x y} => ?_) ?_ (fun {x y} => ?_) <;> simp_all only [AlgHom.toLinearMap_apply] <;> simp only [map_one, map_mul] variable {R S A B C D} variable [Semiring C] [Semiring D] [Bialgebra S C] [Bialgebra R D] [Algebra R C] [IsScalarTower R S C] /-- The tensor product of two bialgebra morphisms as a bialgebra morphism. -/ noncomputable def map (f : A →ₐc[S] C) (g : B →ₐc[R] D) : A ⊗[R] B →ₐc[S] C ⊗[R] D := { Coalgebra.TensorProduct.map (f : A →ₗc[S] C) (g : B →ₗc[R] D), Algebra.TensorProduct.map (f : A →ₐ[S] C) (g : B →ₐ[R] D) with } @[simp] theorem map_tmul (f : A →ₐc[S] C) (g : B →ₐc[R] D) (x : A) (y : B) : map f g (x ⊗ₜ y) = f x ⊗ₜ g y := rfl @[simp] theorem map_toCoalgHom (f : A →ₐc[S] C) (g : B →ₐc[R] D) : map f g = Coalgebra.TensorProduct.map (f : A →ₗc[S] C) (g : B →ₗc[R] D) := rfl @[simp] theorem map_toAlgHom (f : A →ₐc[S] C) (g : B →ₐc[R] D) : (map f g : A ⊗[R] B →ₐ[S] C ⊗[R] D) = Algebra.TensorProduct.map (f : A →ₐ[S] C) (g : B →ₐ[R] D) := rfl variable (R S A C D) in /-- The associator for tensor products of R-bialgebras, as a bialgebra equivalence. -/ protected noncomputable def assoc : (A ⊗[S] C) ⊗[R] D ≃ₐc[S] A ⊗[S] (C ⊗[R] D) := { Coalgebra.TensorProduct.assoc R S A C D, Algebra.TensorProduct.assoc R S A C D with } @[simp] theorem assoc_tmul (x : A) (y : C) (z : D) : Bialgebra.TensorProduct.assoc R S A C D ((x ⊗ₜ y) ⊗ₜ z) = x ⊗ₜ (y ⊗ₜ z) := rfl @[simp] theorem assoc_symm_tmul (x : A) (y : C) (z : D) : (Bialgebra.TensorProduct.assoc R S A C D).symm (x ⊗ₜ (y ⊗ₜ z)) = (x ⊗ₜ y) ⊗ₜ z := rfl @[simp] theorem assoc_toCoalgEquiv : (Bialgebra.TensorProduct.assoc R S A C D : _ ≃ₗc[S] _) = Coalgebra.TensorProduct.assoc R S A C D := rfl @[simp] theorem assoc_toAlgEquiv : (Bialgebra.TensorProduct.assoc R S A C D : _ ≃ₐ[S] _) = Algebra.TensorProduct.assoc R S A C D := rfl variable (R B) in /-- The base ring is a left identity for the tensor product of bialgebras, up to bialgebra equivalence. -/ protected noncomputable def lid : R ⊗[R] B ≃ₐc[R] B := { Coalgebra.TensorProduct.lid R B, Algebra.TensorProduct.lid R B with } @[simp] theorem lid_toCoalgEquiv : (Bialgebra.TensorProduct.lid R B : R ⊗[R] B ≃ₗc[R] B) = Coalgebra.TensorProduct.lid R B := rfl @[simp] theorem lid_toAlgEquiv : (Bialgebra.TensorProduct.lid R B : R ⊗[R] B ≃ₐ[R] B) = Algebra.TensorProduct.lid R B := rfl @[simp] theorem lid_tmul (r : R) (a : B) : Bialgebra.TensorProduct.lid R B (r ⊗ₜ a) = r • a := rfl @[simp] theorem lid_symm_apply (a : B) : (Bialgebra.TensorProduct.lid R B).symm a = 1 ⊗ₜ a := rfl theorem coalgebra_rid_eq_algebra_rid_apply (x : A ⊗[R] R) : Coalgebra.TensorProduct.rid R S A x = Algebra.TensorProduct.rid R R A x := rfl variable (R S A) in /-- The base ring is a right identity for the tensor product of bialgebras, up to bialgebra equivalence. -/ protected noncomputable def rid : A ⊗[R] R ≃ₐc[S] A where toCoalgEquiv := Coalgebra.TensorProduct.rid R S A map_mul' x y := by simp only [CoalgEquiv.toCoalgHom_eq_coe, CoalgHom.toLinearMap_eq_coe, AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, CoalgHom.coe_toLinearMap, CoalgHom.coe_coe, coalgebra_rid_eq_algebra_rid_apply, map_mul] @[simp] theorem rid_toCoalgEquiv : (TensorProduct.rid R S A : A ⊗[R] R ≃ₗc[S] A) = Coalgebra.TensorProduct.rid R S A := rfl @[simp] theorem rid_toAlgEquiv : (Bialgebra.TensorProduct.rid R S A : A ⊗[R] R ≃ₐ[S] A) = Algebra.TensorProduct.rid R S A := by ext x exact coalgebra_rid_eq_algebra_rid_apply x @[simp] theorem rid_tmul (r : R) (a : A) : Bialgebra.TensorProduct.rid R S A (a ⊗ₜ r) = r • a := rfl @[simp] theorem rid_symm_apply (a : A) : (Bialgebra.TensorProduct.rid R S A).symm a = a ⊗ₜ 1 := rfl end Bialgebra.TensorProduct namespace BialgHom variable {R A B C : Type*} [CommRing R] [Ring A] [Ring B] [Ring C] [Bialgebra R A] [Bialgebra R B] [Bialgebra R C] variable (A) /-- `lTensor A f : A ⊗ B →ₐc A ⊗ C` is the natural bialgebra morphism induced by `f : B →ₐc C`. -/ noncomputable abbrev lTensor (f : B →ₐc[R] C) : A ⊗[R] B →ₐc[R] A ⊗[R] C := Bialgebra.TensorProduct.map (BialgHom.id R A) f /-- `rTensor A f : B ⊗ A →ₐc C ⊗ A` is the natural bialgebra morphism induced by `f : B →ₐc C`. -/ noncomputable abbrev rTensor (f : B →ₐc[R] C) : B ⊗[R] A →ₐc[R] C ⊗[R] A := Bialgebra.TensorProduct.map f (BialgHom.id R A) end BialgHom
Prod.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.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Localization.Predicate import Mathlib.CategoryTheory.MorphismProperty.Composition /-! # Localization of product categories In this file, it is shown that if functors `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` are localization functors for morphisms properties `W₁` and `W₂`, then the product functor `C₁ × C₂ ⥤ D₁ × D₂` is a localization functor for `W₁.prod W₂ : MorphismProperty (C₁ × C₂)`, at least if both `W₁` and `W₂` contain identities. This main result is the instance `Functor.IsLocalization.prod`. The proof proceeds by showing first `Localization.Construction.prodIsLocalization`, which asserts that this holds for the localization functors `W₁.Q` and `W₂.Q` to the constructed localized categories: this is done by showing that the product functor `W₁.Q.prod W₂.Q : C₁ × C₂ ⥤ W₁.Localization × W₂.Localization` satisfies the strict universal property of the localization for `W₁.prod W₂`. The general case follows by transporting this result through equivalences of categories. -/ universe v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅ namespace CategoryTheory open Functor variable {C₁ : Type u₁} {C₂ : Type u₂} {D₁ : Type u₃} {D₂ : Type u₄} [Category.{v₁} C₁] [Category.{v₂} C₂] [Category.{v₃} D₁] [Category.{v₄} D₂] (L₁ : C₁ ⥤ D₁) {W₁ : MorphismProperty C₁} (L₂ : C₂ ⥤ D₂) {W₂ : MorphismProperty C₂} namespace Localization namespace StrictUniversalPropertyFixedTarget variable {E : Type u₅} [Category.{v₅} E] (F : C₁ × C₂ ⥤ E) lemma prod_uniq (F₁ F₂ : (W₁.Localization × W₂.Localization ⥤ E)) (h : (W₁.Q.prod W₂.Q) ⋙ F₁ = (W₁.Q.prod W₂.Q) ⋙ F₂) : F₁ = F₂ := by apply Functor.curry_obj_injective apply Construction.uniq apply Functor.flip_injective apply Construction.uniq apply Functor.flip_injective apply Functor.uncurry_obj_injective simpa only [Functor.uncurry_obj_curry_obj_flip_flip] using h /-- Auxiliary definition for `prodLift`. -/ noncomputable def prodLift₁ [W₂.ContainsIdentities] (hF : (W₁.prod W₂).IsInvertedBy F) : W₁.Localization ⥤ C₂ ⥤ E := Construction.lift (curry.obj F) (fun _ _ f₁ hf₁ => by haveI : ∀ (X₂ : C₂), IsIso (((curry.obj F).map f₁).app X₂) := fun X₂ => hF _ ⟨hf₁, MorphismProperty.id_mem _ _⟩ apply NatIso.isIso_of_isIso_app) variable (hF : (W₁.prod W₂).IsInvertedBy F) lemma prod_fac₁ [W₂.ContainsIdentities] : W₁.Q ⋙ prodLift₁ F hF = curry.obj F := Construction.fac _ _ variable [W₁.ContainsIdentities] [W₂.ContainsIdentities] /-- The lifting of a functor `F : C₁ × C₂ ⥤ E` inverting `W₁.prod W₂` to a functor `W₁.Localization × W₂.Localization ⥤ E` -/ noncomputable def prodLift : W₁.Localization × W₂.Localization ⥤ E := by refine uncurry.obj (Construction.lift (prodLift₁ F hF).flip ?_).flip intro _ _ f₂ hf₂ haveI : ∀ (X₁ : W₁.Localization), IsIso (((Functor.flip (prodLift₁ F hF)).map f₂).app X₁) := fun X₁ => by obtain ⟨X₁, rfl⟩ := (Construction.objEquiv W₁).surjective X₁ exact ((MorphismProperty.isomorphisms E).arrow_mk_iso_iff (((Functor.mapArrowFunctor _ _).mapIso (eqToIso (Functor.congr_obj (prod_fac₁ F hF) X₁))).app (Arrow.mk f₂))).2 (hF _ ⟨MorphismProperty.id_mem _ _, hf₂⟩) apply NatIso.isIso_of_isIso_app lemma prod_fac₂ : W₂.Q ⋙ (curry.obj (prodLift F hF)).flip = (prodLift₁ F hF).flip := by simp only [prodLift, Functor.curry_obj_uncurry_obj, Functor.flip_flip] apply Construction.fac lemma prod_fac : (W₁.Q.prod W₂.Q) ⋙ prodLift F hF = F := by rw [← Functor.uncurry_obj_curry_obj_flip_flip', prod_fac₂, Functor.flip_flip, prod_fac₁, Functor.uncurry_obj_curry_obj] variable (W₁ W₂) /-- The product of two (constructed) localized categories satisfies the universal property of the localized category of the product. -/ noncomputable def prod : StrictUniversalPropertyFixedTarget (W₁.Q.prod W₂.Q) (W₁.prod W₂) E where inverts := (Localization.inverts W₁.Q W₁).prod (Localization.inverts W₂.Q W₂) lift := fun F hF => prodLift F hF fac := fun F hF => prod_fac F hF uniq := prod_uniq end StrictUniversalPropertyFixedTarget variable (W₁ W₂) variable [W₁.ContainsIdentities] [W₂.ContainsIdentities] lemma Construction.prodIsLocalization : (W₁.Q.prod W₂.Q).IsLocalization (W₁.prod W₂) := Functor.IsLocalization.mk' _ _ (StrictUniversalPropertyFixedTarget.prod W₁ W₂) (StrictUniversalPropertyFixedTarget.prod W₁ W₂) end Localization open Localization namespace Functor namespace IsLocalization variable (W₁ W₂) variable [W₁.ContainsIdentities] [W₂.ContainsIdentities] /-- If `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` are localization functors for `W₁ : MorphismProperty C₁` and `W₂ : MorphismProperty C₂` respectively, and if both `W₁` and `W₂` contain identities, then the product functor `L₁.prod L₂ : C₁ × C₂ ⥤ D₁ × D₂` is a localization functor for `W₁.prod W₂`. -/ instance prod [L₁.IsLocalization W₁] [L₂.IsLocalization W₂] : (L₁.prod L₂).IsLocalization (W₁.prod W₂) := by haveI := Construction.prodIsLocalization W₁ W₂ exact of_equivalence_target (W₁.Q.prod W₂.Q) (W₁.prod W₂) (L₁.prod L₂) ((uniq W₁.Q L₁ W₁).prod (uniq W₂.Q L₂ W₂)) (NatIso.prod (compUniqFunctor W₁.Q L₁ W₁) (compUniqFunctor W₂.Q L₂ W₂)) end IsLocalization end Functor end CategoryTheory
Ptolemy.lean
/- Copyright (c) 2021 Manuel Candales. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Manuel Candales, Benjamin Davidson -/ import Mathlib.Geometry.Euclidean.Sphere.Power import Mathlib.Geometry.Euclidean.Triangle /-! # Ptolemy's theorem This file proves Ptolemy's theorem on the lengths of the diagonals and sides of a cyclic quadrilateral. ## Main theorems * `mul_dist_add_mul_dist_eq_mul_dist_of_cospherical`: Ptolemy’s Theorem (Freek No. 95). TODO: The current statement of Ptolemy’s theorem works around the lack of a "cyclic polygon" concept in mathlib, which is what the theorem statement would naturally use (or two such concepts, since both a strict version, where all vertices must be distinct, and a weak version, where consecutive vertices may be equal, would be useful; Ptolemy's theorem should then use the weak one). An API needs to be built around that concept, which would include: - strict cyclic implies weak cyclic, - weak cyclic and consecutive points distinct implies strict cyclic, - weak/strict cyclic implies weak/strict cyclic for any subsequence, - any three points on a sphere are weakly or strictly cyclic according to whether they are distinct, - any number of points on a sphere intersected with a two-dimensional affine subspace are cyclic in some order, - a list of points is cyclic if and only if its reversal is, - a list of points is cyclic if and only if any cyclic permutation is, while other permutations are not when the points are distinct, - a point P where the diagonals of a cyclic polygon cross exists (and is unique) with weak/strict betweenness depending on weak/strict cyclicity, - four points on a sphere with such a point P are cyclic in the appropriate order, and so on. -/ open Real open scoped EuclideanGeometry RealInnerProductSpace Real namespace EuclideanGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] variable {P : Type*} [MetricSpace P] [NormedAddTorsor V P] /-- **Ptolemy’s Theorem**. -/ theorem mul_dist_add_mul_dist_eq_mul_dist_of_cospherical {a b c d p : P} (h : Cospherical ({a, b, c, d} : Set P)) (hapc : ∠ a p c = π) (hbpd : ∠ b p d = π) : dist a b * dist c d + dist b c * dist d a = dist a c * dist b d := by have h' : Cospherical ({a, c, b, d} : Set P) := by rwa [Set.insert_comm c b {d}] have hmul := mul_dist_eq_mul_dist_of_cospherical_of_angle_eq_pi h' hapc hbpd have hbp := left_dist_ne_zero_of_angle_eq_pi hbpd have h₁ : dist c d = dist c p / dist b p * dist a b := by rw [dist_mul_of_eq_angle_of_dist_mul b p a c p d, dist_comm a b] · rw [angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi hbpd hapc, angle_comm] all_goals field_simp [mul_comm, hmul] have h₂ : dist d a = dist a p / dist b p * dist b c := by rw [dist_mul_of_eq_angle_of_dist_mul c p b d p a, dist_comm c b] · rwa [angle_comm, angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi]; rwa [angle_comm] all_goals field_simp [mul_comm, hmul] have h₃ : dist d p = dist a p * dist c p / dist b p := by field_simp [mul_comm, hmul] have h₄ : ∀ x y : ℝ, x * (y * x) = x * x * y := fun x y => by rw [mul_left_comm, mul_comm] -- takes 450ms, but the "equivalent" simp call leaves some remaining goals field_simp [h₁, h₂, dist_eq_add_dist_of_angle_eq_pi hbpd, h₃, hbp, dist_comm a b, h₄, ← sq, dist_sq_mul_dist_add_dist_sq_mul_dist b, hapc] end EuclideanGeometry
GoalsLocation.lean
/- Copyright (c) 2023 Jovan Gerbscheid. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jovan Gerbscheid -/ import Mathlib.Init import Lean.Meta.Tactic.Util import Lean.SubExpr /-! This file defines some functions for dealing with `SubExpr.GoalsLocation`. -/ namespace Lean.SubExpr.GoalsLocation /-- The root expression of the position specified by the `GoalsLocation`. -/ def rootExpr : GoalsLocation → MetaM Expr | ⟨_, .hyp fvarId⟩ => do instantiateMVars (← fvarId.getType) | ⟨_, .hypType fvarId _⟩ => do instantiateMVars (← fvarId.getType) | ⟨_, .hypValue fvarId _⟩ => do instantiateMVars (← fvarId.getDecl).value | ⟨mvarId, .target _⟩ => do instantiateMVars (← mvarId.getType) /-- The `SubExpr.Pos` specified by the `GoalsLocation`. -/ def pos : GoalsLocation → Pos | ⟨_, .hyp _⟩ => .root | ⟨_, .hypType _ pos⟩ => pos | ⟨_, .hypValue _ pos⟩ => pos | ⟨_, .target pos⟩ => pos /-- The hypothesis specified by the `GoalsLocation`. -/ def fvarId? : GoalsLocation → Option FVarId | ⟨_, .hyp fvarId⟩ => fvarId | ⟨_, .hypType fvarId _⟩ => fvarId | ⟨_, .hypValue fvarId _⟩ => fvarId | ⟨_, .target _⟩ => none end Lean.SubExpr.GoalsLocation
Units.lean
/- Copyright (c) 2021 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Order.GroupWithZero.Submonoid import Mathlib.Algebra.Order.Ring.Defs /-! # Unit subgroups of a ring -/ /-- The subgroup of positive units of a linear ordered semiring. -/ def Units.posSubgroup (R : Type*) [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] : Subgroup Rˣ := { (Submonoid.pos R).comap (Units.coeHom R) with carrier := { x | (0 : R) < x } inv_mem' := Units.inv_pos.mpr } @[simp] theorem Units.mem_posSubgroup {R : Type*} [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] (u : Rˣ) : u ∈ Units.posSubgroup R ↔ (0 : R) < u := Iff.rfl
Metric.lean
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Complex.UpperHalfPlane.Topology import Mathlib.Analysis.SpecialFunctions.Arsinh import Mathlib.Geometry.Euclidean.Inversion.Basic /-! # Metric on the upper half-plane In this file we define a `MetricSpace` structure on the `UpperHalfPlane`. We use hyperbolic (Poincaré) distance given by `dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))` instead of the induced Euclidean distance because the hyperbolic distance is invariant under holomorphic automorphisms of the upper half-plane. However, we ensure that the projection to `TopologicalSpace` is definitionally equal to the induced topological space structure. We also prove that a metric ball/closed ball/sphere in Poincaré metric is a Euclidean ball/closed ball/sphere with another center and radius. -/ noncomputable section open Filter Metric Real Set Topology open scoped UpperHalfPlane ComplexConjugate NNReal Topology MatrixGroups variable {z w : ℍ} {r : ℝ} namespace UpperHalfPlane instance : Dist ℍ := ⟨fun z w => 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))⟩ theorem dist_eq (z w : ℍ) : dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im))) := rfl theorem sinh_half_dist (z w : ℍ) : sinh (dist z w / 2) = dist (z : ℂ) w / (2 * √(z.im * w.im)) := by rw [dist_eq, mul_div_cancel_left₀ (arsinh _) two_ne_zero, sinh_arsinh] theorem cosh_half_dist (z w : ℍ) : cosh (dist z w / 2) = dist (z : ℂ) (conj (w : ℂ)) / (2 * √(z.im * w.im)) := by rw [← sq_eq_sq₀, cosh_sq', sinh_half_dist, div_pow, div_pow, one_add_div, mul_pow, sq_sqrt] · congr 1 simp only [Complex.dist_eq, Complex.sq_norm, Complex.normSq_sub, Complex.normSq_conj, Complex.conj_conj, Complex.mul_re, Complex.conj_re, Complex.conj_im, coe_im] ring all_goals positivity theorem tanh_half_dist (z w : ℍ) : tanh (dist z w / 2) = dist (z : ℂ) w / dist (z : ℂ) (conj ↑w) := by rw [tanh_eq_sinh_div_cosh, sinh_half_dist, cosh_half_dist, div_div_div_comm, div_self, div_one] positivity theorem exp_half_dist (z w : ℍ) : exp (dist z w / 2) = (dist (z : ℂ) w + dist (z : ℂ) (conj ↑w)) / (2 * √(z.im * w.im)) := by rw [← sinh_add_cosh, sinh_half_dist, cosh_half_dist, add_div] theorem cosh_dist (z w : ℍ) : cosh (dist z w) = 1 + dist (z : ℂ) w ^ 2 / (2 * z.im * w.im) := by rw [dist_eq, cosh_two_mul, cosh_sq', add_assoc, ← two_mul, sinh_arsinh, div_pow, mul_pow, sq_sqrt, sq (2 : ℝ), mul_assoc, ← mul_div_assoc, mul_assoc, mul_div_mul_left] <;> positivity theorem sinh_half_dist_add_dist (a b c : ℍ) : sinh ((dist a b + dist b c) / 2) = (dist (a : ℂ) b * dist (c : ℂ) (conj ↑b) + dist (b : ℂ) c * dist (a : ℂ) (conj ↑b)) / (2 * √(a.im * c.im) * dist (b : ℂ) (conj ↑b)) := by simp only [add_div _ _ (2 : ℝ), sinh_add, sinh_half_dist, cosh_half_dist, div_mul_div_comm] rw [← add_div, Complex.dist_self_conj, coe_im, abs_of_pos b.im_pos, mul_comm (dist (b : ℂ) _), dist_comm (b : ℂ), Complex.dist_conj_comm, mul_mul_mul_comm, mul_mul_mul_comm _ _ _ b.im] congr 2 rw [sqrt_mul, sqrt_mul, sqrt_mul, mul_comm (√a.im), mul_mul_mul_comm, mul_self_sqrt, mul_comm] <;> exact (im_pos _).le protected theorem dist_comm (z w : ℍ) : dist z w = dist w z := by simp only [dist_eq, dist_comm (z : ℂ), mul_comm] theorem dist_le_iff_le_sinh : dist z w ≤ r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) ≤ sinh (r / 2) := by rw [← div_le_div_iff_of_pos_right (zero_lt_two' ℝ), ← sinh_le_sinh, sinh_half_dist] theorem dist_eq_iff_eq_sinh : dist z w = r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) = sinh (r / 2) := by rw [← div_left_inj' (two_ne_zero' ℝ), ← sinh_inj, sinh_half_dist] theorem dist_eq_iff_eq_sq_sinh (hr : 0 ≤ r) : dist z w = r ↔ dist (z : ℂ) w ^ 2 / (4 * z.im * w.im) = sinh (r / 2) ^ 2 := by rw [dist_eq_iff_eq_sinh, ← sq_eq_sq₀, div_pow, mul_pow, sq_sqrt, mul_assoc] · norm_num all_goals positivity protected theorem dist_triangle (a b c : ℍ) : dist a c ≤ dist a b + dist b c := by rw [dist_le_iff_le_sinh, sinh_half_dist_add_dist, div_mul_eq_div_div _ _ (dist _ _), le_div_iff₀, div_mul_eq_mul_div] · gcongr exact EuclideanGeometry.mul_dist_le_mul_dist_add_mul_dist (a : ℂ) b c (conj (b : ℂ)) · rw [dist_comm, dist_pos, Ne, Complex.conj_eq_iff_im] exact b.im_ne_zero theorem dist_le_dist_coe_div_sqrt (z w : ℍ) : dist z w ≤ dist (z : ℂ) w / √(z.im * w.im) := by rw [dist_le_iff_le_sinh, ← div_mul_eq_div_div_swap, self_le_sinh_iff] positivity /-- An auxiliary `MetricSpace` instance on the upper half-plane. This instance has bad projection to `TopologicalSpace`. We replace it later. -/ def metricSpaceAux : MetricSpace ℍ where dist := dist dist_self z := by rw [dist_eq, dist_self, zero_div, arsinh_zero, mul_zero] dist_comm := UpperHalfPlane.dist_comm dist_triangle := UpperHalfPlane.dist_triangle eq_of_dist_eq_zero {z w} h := by simpa [dist_eq, Real.sqrt_eq_zero', (mul_pos z.im_pos w.im_pos).not_ge, Set.ext_iff] using h open Complex theorem cosh_dist' (z w : ℍ) : Real.cosh (dist z w) = ((z.re - w.re) ^ 2 + z.im ^ 2 + w.im ^ 2) / (2 * z.im * w.im) := by field_simp [cosh_dist, Complex.dist_eq, Complex.sq_norm, normSq_apply] ring /-- Euclidean center of the circle with center `z` and radius `r` in the hyperbolic metric. -/ def center (z : ℍ) (r : ℝ) : ℍ := ⟨⟨z.re, z.im * Real.cosh r⟩, by positivity⟩ @[simp] theorem center_re (z r) : (center z r).re = z.re := rfl @[simp] theorem center_im (z r) : (center z r).im = z.im * Real.cosh r := rfl @[simp] theorem center_zero (z : ℍ) : center z 0 = z := ext' rfl <| by rw [center_im, Real.cosh_zero, mul_one] theorem dist_coe_center_sq (z w : ℍ) (r : ℝ) : dist (z : ℂ) (w.center r) ^ 2 = 2 * z.im * w.im * (Real.cosh (dist z w) - Real.cosh r) + (w.im * Real.sinh r) ^ 2 := by have H : 2 * z.im * w.im ≠ 0 := by positivity simp only [Complex.dist_eq, Complex.sq_norm, normSq_apply, coe_re, coe_im, center_re, center_im, cosh_dist', mul_div_cancel₀ _ H, sub_sq z.im, mul_pow, Real.cosh_sq, sub_re, sub_im, mul_sub, ← sq] ring theorem dist_coe_center (z w : ℍ) (r : ℝ) : dist (z : ℂ) (w.center r) = √(2 * z.im * w.im * (Real.cosh (dist z w) - Real.cosh r) + (w.im * Real.sinh r) ^ 2) := by rw [← sqrt_sq dist_nonneg, dist_coe_center_sq] theorem cmp_dist_eq_cmp_dist_coe_center (z w : ℍ) (r : ℝ) : cmp (dist z w) r = cmp (dist (z : ℂ) (w.center r)) (w.im * Real.sinh r) := by letI := metricSpaceAux rcases lt_or_ge r 0 with hr₀ | hr₀ · trans Ordering.gt exacts [(hr₀.trans_le dist_nonneg).cmp_eq_gt, ((mul_neg_of_pos_of_neg w.im_pos (sinh_neg_iff.2 hr₀)).trans_le dist_nonneg).cmp_eq_gt.symm] have hr₀' : 0 ≤ w.im * Real.sinh r := by positivity have hzw₀ : 0 < 2 * z.im * w.im := by positivity simp only [← cosh_strictMonoOn.cmp_map_eq dist_nonneg hr₀, ← (pow_left_strictMonoOn₀ (M₀ := ℝ) two_ne_zero).cmp_map_eq dist_nonneg hr₀', dist_coe_center_sq] rw [← cmp_mul_pos_left hzw₀, ← cmp_sub_zero, ← mul_sub, ← cmp_add_right, zero_add] theorem dist_eq_iff_dist_coe_center_eq : dist z w = r ↔ dist (z : ℂ) (w.center r) = w.im * Real.sinh r := eq_iff_eq_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) @[simp] theorem dist_self_center (z : ℍ) (r : ℝ) : dist (z : ℂ) (z.center r) = z.im * (Real.cosh r - 1) := by rw [dist_of_re_eq (z.center_re r).symm, dist_comm, Real.dist_eq, mul_sub, mul_one] exact abs_of_nonneg (sub_nonneg.2 <| le_mul_of_one_le_right z.im_pos.le (one_le_cosh _)) @[simp] theorem dist_center_dist (z w : ℍ) : dist (z : ℂ) (w.center (dist z w)) = w.im * Real.sinh (dist z w) := dist_eq_iff_dist_coe_center_eq.1 rfl theorem dist_lt_iff_dist_coe_center_lt : dist z w < r ↔ dist (z : ℂ) (w.center r) < w.im * Real.sinh r := lt_iff_lt_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) theorem lt_dist_iff_lt_dist_coe_center : r < dist z w ↔ w.im * Real.sinh r < dist (z : ℂ) (w.center r) := lt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 <| cmp_dist_eq_cmp_dist_coe_center z w r) theorem dist_le_iff_dist_coe_center_le : dist z w ≤ r ↔ dist (z : ℂ) (w.center r) ≤ w.im * Real.sinh r := le_iff_le_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) theorem le_dist_iff_le_dist_coe_center : r < dist z w ↔ w.im * Real.sinh r < dist (z : ℂ) (w.center r) := lt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 <| cmp_dist_eq_cmp_dist_coe_center z w r) /-- For two points on the same vertical line, the distance is equal to the distance between the logarithms of their imaginary parts. -/ nonrec theorem dist_of_re_eq (h : z.re = w.re) : dist z w = dist (log z.im) (log w.im) := by have h₀ : 0 < z.im / w.im := by positivity rw [dist_eq_iff_dist_coe_center_eq, Real.dist_eq, ← abs_sinh, ← log_div z.im_ne_zero w.im_ne_zero, sinh_log h₀, dist_of_re_eq, coe_im, coe_im, center_im, cosh_abs, cosh_log h₀, inv_div] <;> [skip; exact h] nth_rw 4 [← abs_of_pos w.im_pos] simp only [← _root_.abs_mul, Real.dist_eq] congr 1 field_simp ring /-- Hyperbolic distance between two points is greater than or equal to the distance between the logarithms of their imaginary parts. -/ theorem dist_log_im_le (z w : ℍ) : dist (log z.im) (log w.im) ≤ dist z w := calc dist (log z.im) (log w.im) = dist (mk ⟨0, z.im⟩ z.im_pos) (mk ⟨0, w.im⟩ w.im_pos) := Eq.symm <| dist_of_re_eq rfl _ ≤ dist z w := by simp_rw [dist_eq] dsimp only [coe_mk, mk_im] gcongr simpa [sqrt_sq_eq_abs] using Complex.abs_im_le_norm (z - w) theorem im_le_im_mul_exp_dist (z w : ℍ) : z.im ≤ w.im * Real.exp (dist z w) := by rw [← div_le_iff₀' w.im_pos, ← exp_log z.im_pos, ← exp_log w.im_pos, ← Real.exp_sub, exp_le_exp] exact (le_abs_self _).trans (dist_log_im_le z w) theorem im_div_exp_dist_le (z w : ℍ) : z.im / Real.exp (dist z w) ≤ w.im := (div_le_iff₀ (exp_pos _)).2 (im_le_im_mul_exp_dist z w) /-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance and the imaginary part of one of the points. -/ theorem dist_coe_le (z w : ℍ) : dist (z : ℂ) w ≤ w.im * (Real.exp (dist z w) - 1) := calc dist (z : ℂ) w ≤ dist (z : ℂ) (w.center (dist z w)) + dist (w : ℂ) (w.center (dist z w)) := dist_triangle_right _ _ _ _ = w.im * (Real.exp (dist z w) - 1) := by rw [dist_center_dist, dist_self_center, ← mul_add, ← add_sub_assoc, Real.sinh_add_cosh] /-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance and the imaginary part of one of the points. -/ theorem le_dist_coe (z w : ℍ) : w.im * (1 - Real.exp (-dist z w)) ≤ dist (z : ℂ) w := calc w.im * (1 - Real.exp (-dist z w)) = dist (z : ℂ) (w.center (dist z w)) - dist (w : ℂ) (w.center (dist z w)) := by rw [dist_center_dist, dist_self_center, ← Real.cosh_sub_sinh]; ring _ ≤ dist (z : ℂ) w := sub_le_iff_le_add.2 <| dist_triangle _ _ _ /-- The hyperbolic metric on the upper half plane. We ensure that the projection to `TopologicalSpace` is definitionally equal to the subtype topology. -/ instance : MetricSpace ℍ := metricSpaceAux.replaceTopology <| by refine le_antisymm (continuous_id_iff_le.1 ?_) ?_ · refine (@continuous_iff_continuous_dist ℍ ℍ metricSpaceAux.toPseudoMetricSpace _ _).2 ?_ have : ∀ x : ℍ × ℍ, 2 * √(x.1.im * x.2.im) ≠ 0 := fun x => by positivity -- `continuity` fails to apply `Continuous.div` apply_rules [Continuous.div, Continuous.mul, continuous_const, Continuous.arsinh, Continuous.dist, continuous_coe.comp, continuous_fst, continuous_snd, Real.continuous_sqrt.comp, continuous_im.comp] · letI : MetricSpace ℍ := metricSpaceAux refine le_of_nhds_le_nhds fun z => ?_ rw [nhds_induced] refine (nhds_basis_ball.le_basis_iff (nhds_basis_ball.comap _)).2 fun R hR => ?_ have h₁ : 1 < R / im z + 1 := lt_add_of_pos_left _ (div_pos hR z.im_pos) have h₀ : 0 < R / im z + 1 := one_pos.trans h₁ refine ⟨log (R / im z + 1), Real.log_pos h₁, ?_⟩ refine fun w hw => (dist_coe_le w z).trans_lt ?_ rwa [← lt_div_iff₀' z.im_pos, sub_lt_iff_lt_add, ← Real.lt_log_iff_exp_lt h₀] theorem im_pos_of_dist_center_le {z : ℍ} {r : ℝ} {w : ℂ} (h : dist w (center z r) ≤ z.im * Real.sinh r) : 0 < w.im := calc 0 < z.im * (Real.cosh r - Real.sinh r) := mul_pos z.im_pos (sub_pos.2 <| sinh_lt_cosh _) _ = (z.center r).im - z.im * Real.sinh r := mul_sub _ _ _ _ ≤ (z.center r).im - dist (z.center r : ℂ) w := sub_le_sub_left (by rwa [dist_comm]) _ _ ≤ w.im := sub_le_comm.1 <| (le_abs_self _).trans (abs_im_le_norm <| z.center r - w) theorem image_coe_closedBall (z : ℍ) (r : ℝ) : ((↑) : ℍ → ℂ) '' closedBall (α := ℍ) z r = closedBall ↑(z.center r) (z.im * Real.sinh r) := by ext w; constructor · rintro ⟨w, hw, rfl⟩ exact dist_le_iff_dist_coe_center_le.1 hw · intro hw lift w to ℍ using im_pos_of_dist_center_le hw exact mem_image_of_mem _ (dist_le_iff_dist_coe_center_le.2 hw) theorem image_coe_ball (z : ℍ) (r : ℝ) : ((↑) : ℍ → ℂ) '' ball (α := ℍ) z r = ball ↑(z.center r) (z.im * Real.sinh r) := by ext w; constructor · rintro ⟨w, hw, rfl⟩ exact dist_lt_iff_dist_coe_center_lt.1 hw · intro hw lift w to ℍ using im_pos_of_dist_center_le (ball_subset_closedBall hw) exact mem_image_of_mem _ (dist_lt_iff_dist_coe_center_lt.2 hw) theorem image_coe_sphere (z : ℍ) (r : ℝ) : ((↑) : ℍ → ℂ) '' sphere (α := ℍ) z r = sphere ↑(z.center r) (z.im * Real.sinh r) := by ext w; constructor · rintro ⟨w, hw, rfl⟩ exact dist_eq_iff_dist_coe_center_eq.1 hw · intro hw lift w to ℍ using im_pos_of_dist_center_le (sphere_subset_closedBall hw) exact mem_image_of_mem _ (dist_eq_iff_dist_coe_center_eq.2 hw) instance : ProperSpace ℍ := by refine ⟨fun z r => ?_⟩ rw [IsInducing.subtypeVal.isCompact_iff (f := ((↑) : ℍ → ℂ)), image_coe_closedBall] apply isCompact_closedBall theorem isometry_vertical_line (a : ℝ) : Isometry fun y => mk ⟨a, exp y⟩ (exp_pos y) := by refine Isometry.of_dist_eq fun y₁ y₂ => ?_ rw [dist_of_re_eq] exacts [congr_arg₂ _ (log_exp _) (log_exp _), rfl] theorem isometry_real_vadd (a : ℝ) : Isometry (a +ᵥ · : ℍ → ℍ) := Isometry.of_dist_eq fun y₁ y₂ => by simp only [dist_eq, coe_vadd, vadd_im, dist_add_left] theorem isometry_pos_mul (a : { x : ℝ // 0 < x }) : Isometry (a • · : ℍ → ℍ) := by refine Isometry.of_dist_eq fun y₁ y₂ => ?_ simp only [dist_eq, coe_pos_real_smul, pos_real_im]; congr 2 rw [dist_smul₀, mul_mul_mul_comm, Real.sqrt_mul (mul_self_nonneg _), Real.sqrt_mul_self_eq_abs, Real.norm_eq_abs, mul_left_comm] exact mul_div_mul_left _ _ (mt _root_.abs_eq_zero.1 a.2.ne') /-- `SL(2, ℝ)` acts on the upper half plane as an isometry. -/ instance : IsIsometricSMul SL(2, ℝ) ℍ := ⟨fun g => by have h₀ : Isometry (fun z => ModularGroup.S • z : ℍ → ℍ) := Isometry.of_dist_eq fun y₁ y₂ => by have h₁ : 0 ≤ im y₁ * im y₂ := mul_nonneg y₁.property.le y₂.property.le have h₂ : ‖(y₁ * y₂ : ℂ)‖ ≠ 0 := by simp [y₁.ne_zero, y₂.ne_zero] simp_rw [modular_S_smul, inv_neg, dist_eq, coe_mk, dist_neg_neg, dist_inv_inv₀ y₁.ne_zero y₂.ne_zero, mk_im, neg_im, inv_im, coe_im, neg_div, neg_neg, div_mul_div_comm, ← normSq_mul, Real.sqrt_div h₁, ← norm_def, mul_div (2 : ℝ)] rw [div_div_div_comm, ← norm_mul, div_self h₂, div_one] by_cases hc : g 1 0 = 0 · obtain ⟨u, v, h⟩ := exists_SL2_smul_eq_of_apply_zero_one_eq_zero g hc rw [h] exact (isometry_real_vadd v).comp (isometry_pos_mul u) · obtain ⟨u, v, w, h⟩ := exists_SL2_smul_eq_of_apply_zero_one_ne_zero g hc rw [h] exact (isometry_real_vadd w).comp (h₀.comp <| (isometry_real_vadd v).comp <| isometry_pos_mul u)⟩ end UpperHalfPlane
Matrix.lean
/- Copyright (c) 2024 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.LinearAlgebra.Matrix.Ideal import Mathlib.RingTheory.SimpleRing.Basic /-! The matrix ring over a simple ring is simple -/ namespace IsSimpleRing variable (ι A : Type*) [Ring A] [Fintype ι] [Nonempty ι] instance matrix [IsSimpleRing A] : IsSimpleRing (Matrix ι ι A) where simple := letI := Classical.decEq ι; TwoSidedIdeal.orderIsoMatrix |>.symm.isSimpleOrder end IsSimpleRing
Linear.lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps /-! # The derivative of bounded linear maps For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of bounded linear maps. -/ open Asymptotics section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : E → F} variable (e : E →L[𝕜] F) variable {x : E} variable {s : Set E} variable {L : Filter E} section ContinuousLinearMap /-! ### Continuous linear maps There are currently two variants of these in mathlib, the bundled version (named `ContinuousLinearMap`, and denoted `E →L[𝕜] F`), and the unbundled version (with a predicate `IsBoundedLinearMap`). We give statements for both versions. -/ @[fun_prop] protected theorem ContinuousLinearMap.hasStrictFDerivAt {x : E} : HasStrictFDerivAt e e x := .of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left fun x => by simp only [e.map_sub, sub_self, Pi.zero_apply] protected theorem ContinuousLinearMap.hasFDerivAtFilter : HasFDerivAtFilter e e x L := .of_isLittleOTVS <| (IsLittleOTVS.zero _ _).congr_left fun x => by simp only [e.map_sub, sub_self, Pi.zero_apply] @[fun_prop] protected theorem ContinuousLinearMap.hasFDerivWithinAt : HasFDerivWithinAt e e s x := e.hasFDerivAtFilter @[fun_prop] protected theorem ContinuousLinearMap.hasFDerivAt : HasFDerivAt e e x := e.hasFDerivAtFilter @[simp, fun_prop] protected theorem ContinuousLinearMap.differentiableAt : DifferentiableAt 𝕜 e x := e.hasFDerivAt.differentiableAt @[fun_prop] protected theorem ContinuousLinearMap.differentiableWithinAt : DifferentiableWithinAt 𝕜 e s x := e.differentiableAt.differentiableWithinAt @[simp] protected theorem ContinuousLinearMap.fderiv : fderiv 𝕜 e x = e := e.hasFDerivAt.fderiv protected theorem ContinuousLinearMap.fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 e s x = e := by rw [DifferentiableAt.fderivWithin e.differentiableAt hxs] exact e.fderiv @[simp, fun_prop] protected theorem ContinuousLinearMap.differentiable : Differentiable 𝕜 e := fun _ => e.differentiableAt @[fun_prop] protected theorem ContinuousLinearMap.differentiableOn : DifferentiableOn 𝕜 e s := e.differentiable.differentiableOn theorem IsBoundedLinearMap.hasFDerivAtFilter (h : IsBoundedLinearMap 𝕜 f) : HasFDerivAtFilter f h.toContinuousLinearMap x L := h.toContinuousLinearMap.hasFDerivAtFilter @[fun_prop] theorem IsBoundedLinearMap.hasFDerivWithinAt (h : IsBoundedLinearMap 𝕜 f) : HasFDerivWithinAt f h.toContinuousLinearMap s x := h.hasFDerivAtFilter @[fun_prop] theorem IsBoundedLinearMap.hasFDerivAt (h : IsBoundedLinearMap 𝕜 f) : HasFDerivAt f h.toContinuousLinearMap x := h.hasFDerivAtFilter @[fun_prop] theorem IsBoundedLinearMap.differentiableAt (h : IsBoundedLinearMap 𝕜 f) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt @[fun_prop] theorem IsBoundedLinearMap.differentiableWithinAt (h : IsBoundedLinearMap 𝕜 f) : DifferentiableWithinAt 𝕜 f s x := h.differentiableAt.differentiableWithinAt theorem IsBoundedLinearMap.fderiv (h : IsBoundedLinearMap 𝕜 f) : fderiv 𝕜 f x = h.toContinuousLinearMap := HasFDerivAt.fderiv h.hasFDerivAt theorem IsBoundedLinearMap.fderivWithin (h : IsBoundedLinearMap 𝕜 f) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = h.toContinuousLinearMap := by rw [DifferentiableAt.fderivWithin h.differentiableAt hxs] exact h.fderiv @[fun_prop] theorem IsBoundedLinearMap.differentiable (h : IsBoundedLinearMap 𝕜 f) : Differentiable 𝕜 f := fun _ => h.differentiableAt @[fun_prop] theorem IsBoundedLinearMap.differentiableOn (h : IsBoundedLinearMap 𝕜 f) : DifferentiableOn 𝕜 f s := h.differentiable.differentiableOn end ContinuousLinearMap end
all_order.v
Require Export order.
Imo1975Q1.lean
/- Copyright (c) 2022 Mantas Bakšys. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mantas Bakšys -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.Rearrangement import Mathlib.Data.Real.Basic import Mathlib.Order.Interval.Finset.Nat /-! # IMO 1975 Q1 Let `x₁, x₂, ... , xₙ` and `y₁, y₂, ... , yₙ` be two sequences of real numbers, such that `x₁ ≥ x₂ ≥ ... ≥ xₙ` and `y₁ ≥ y₂ ≥ ... ≥ yₙ`. Prove that if `z₁, z₂, ... , zₙ` is any permutation of `y₁, y₂, ... , yₙ`, then `∑ (xᵢ - yᵢ)^2 ≤ ∑ (xᵢ - zᵢ)^2` # Solution Firstly, we expand the squares within both sums and distribute into separate finite sums. Then, noting that `∑ yᵢ ^ 2 = ∑ zᵢ ^ 2`, it remains to prove that `∑ xᵢ * zᵢ ≤ ∑ xᵢ * yᵢ`, which is true by the Rearrangement Inequality -/ /- Let `n` be a natural number, `x` and `y` be as in the problem statement and `σ` be the permutation of natural numbers such that `z = y ∘ σ` -/ variable (n : ℕ) (σ : Equiv.Perm ℕ) (x y : ℕ → ℝ) theorem imo1975_q1 (hσ : {x | σ x ≠ x} ⊆ Finset.Icc 1 n) (hx : AntitoneOn x (Finset.Icc 1 n)) (hy : AntitoneOn y (Finset.Icc 1 n)) : ∑ i ∈ Finset.Icc 1 n, (x i - y i) ^ 2 ≤ ∑ i ∈ Finset.Icc 1 n, (x i - y (σ i)) ^ 2 := by simp only [sub_sq, Finset.sum_add_distrib, Finset.sum_sub_distrib] -- a finite sum is invariant if we permute the order of summation have hσy : ∑ i ∈ Finset.Icc 1 n, y i ^ 2 = ∑ i ∈ Finset.Icc 1 n, y (σ i) ^ 2 := by rw [← Equiv.Perm.sum_comp σ (Finset.Icc 1 n) _ hσ] -- let's cancel terms appearing on both sides rw [hσy, add_le_add_iff_right, sub_le_sub_iff_left] simp only [mul_assoc, ← Finset.mul_sum, zero_lt_two, mul_le_mul_left] -- what's left to prove is a version of the rearrangement inequality apply MonovaryOn.sum_mul_comp_perm_le_sum_mul _ hσ -- finally we need to show that `x` and `y` 'vary' together on `[1, n]` and this is due to both of -- them being `decreasing` exact AntitoneOn.monovaryOn hx hy
Henselian.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.Polynomial.Taylor import Mathlib.RingTheory.LocalRing.ResidueField.Basic import Mathlib.RingTheory.AdicCompletion.Basic /-! # Henselian rings In this file we set up the basic theory of Henselian (local) rings. A ring `R` is *Henselian* at an ideal `I` if the following conditions hold: * `I` is contained in the Jacobson radical of `R` * for every polynomial `f` over `R`, with a *simple* root `a₀` over the quotient ring `R/I`, there exists a lift `a : R` of `a₀` that is a root of `f`. (Here, saying that a root `b` of a polynomial `g` is *simple* means that `g.derivative.eval b` is a unit. Warning: if `R/I` is not a field then it is not enough to assume that `g` has a factorization into monic linear factors in which `X - b` shows up only once; for example `1` is not a simple root of `X^2-1` over `ℤ/4ℤ`.) A local ring `R` is *Henselian* if it is Henselian at its maximal ideal. In this case the first condition is automatic, and in the second condition we may ask for `f.derivative.eval a ≠ 0`, since the quotient ring `R/I` is a field in this case. ## Main declarations * `HenselianRing`: a typeclass on commutative rings, asserting that the ring is Henselian at the ideal `I`. * `HenselianLocalRing`: a typeclass on commutative rings, asserting that the ring is local Henselian * `Field.henselian`: fields are Henselian local rings * `Henselian.TFAE`: equivalent ways of expressing the Henselian property for local rings * `IsAdicComplete.henselianRing`: a ring `R` with ideal `I` that is `I`-adically complete is Henselian at `I` ## References https://stacks.math.columbia.edu/tag/04GE ## TODO After a good API for etale ring homomorphisms has been developed, we can give more equivalent characterization of Henselian rings. In particular, this can give a proof that factorizations into coprime polynomials can be lifted from the residue field to the Henselian ring. The following gist contains some code sketches in that direction. https://gist.github.com/jcommelin/47d94e4af092641017a97f7f02bf9598 -/ noncomputable section universe u v open Polynomial IsLocalRing Function List theorem isLocalHom_of_le_jacobson_bot {R : Type*} [CommRing R] (I : Ideal R) (h : I ≤ Ideal.jacobson ⊥) : IsLocalHom (Ideal.Quotient.mk I) := by constructor intro a h have : IsUnit (Ideal.Quotient.mk (Ideal.jacobson ⊥) a) := by rw [isUnit_iff_exists_inv] at * obtain ⟨b, hb⟩ := h obtain ⟨b, rfl⟩ := Ideal.Quotient.mk_surjective b use Ideal.Quotient.mk _ b rw [← (Ideal.Quotient.mk _).map_one, ← (Ideal.Quotient.mk _).map_mul, Ideal.Quotient.eq] at hb ⊢ exact h hb obtain ⟨⟨x, y, h1, h2⟩, rfl : x = _⟩ := this obtain ⟨y, rfl⟩ := Ideal.Quotient.mk_surjective y rw [← (Ideal.Quotient.mk _).map_mul, ← (Ideal.Quotient.mk _).map_one, Ideal.Quotient.eq, Ideal.mem_jacobson_bot] at h1 h2 specialize h1 1 simp? at h1 says simp only [mul_one, sub_add_cancel, IsUnit.mul_iff] at h1 exact h1.1 /-- A ring `R` is *Henselian* at an ideal `I` if the following condition holds: for every polynomial `f` over `R`, with a *simple* root `a₀` over the quotient ring `R/I`, there exists a lift `a : R` of `a₀` that is a root of `f`. (Here, saying that a root `b` of a polynomial `g` is *simple* means that `g.derivative.eval b` is a unit. Warning: if `R/I` is not a field then it is not enough to assume that `g` has a factorization into monic linear factors in which `X - b` shows up only once; for example `1` is not a simple root of `X^2-1` over `ℤ/4ℤ`.) -/ class HenselianRing (R : Type*) [CommRing R] (I : Ideal R) : Prop where jac : I ≤ Ideal.jacobson ⊥ is_henselian : ∀ (f : R[X]) (_ : f.Monic) (a₀ : R) (_ : f.eval a₀ ∈ I) (_ : IsUnit (Ideal.Quotient.mk I (f.derivative.eval a₀))), ∃ a : R, f.IsRoot a ∧ a - a₀ ∈ I /-- A local ring `R` is *Henselian* if the following condition holds: for every polynomial `f` over `R`, with a *simple* root `a₀` over the residue field, there exists a lift `a : R` of `a₀` that is a root of `f`. (Recall that a root `b` of a polynomial `g` is *simple* if it is not a double root, so if `g.derivative.eval b ≠ 0`.) In other words, `R` is local Henselian if it is Henselian at the ideal `I`, in the sense of `HenselianRing`. -/ class HenselianLocalRing (R : Type*) [CommRing R] : Prop extends IsLocalRing R where is_henselian : ∀ (f : R[X]) (_ : f.Monic) (a₀ : R) (_ : f.eval a₀ ∈ maximalIdeal R) (_ : IsUnit (f.derivative.eval a₀)), ∃ a : R, f.IsRoot a ∧ a - a₀ ∈ maximalIdeal R -- see Note [lower instance priority] instance (priority := 100) Field.henselian (K : Type*) [Field K] : HenselianLocalRing K where is_henselian f _ a₀ h₁ _ := by simp only [(maximalIdeal K).eq_bot_of_prime, Ideal.mem_bot] at h₁ ⊢ exact ⟨a₀, h₁, sub_self _⟩ theorem HenselianLocalRing.TFAE (R : Type u) [CommRing R] [IsLocalRing R] : TFAE [HenselianLocalRing R, ∀ f : R[X], f.Monic → ∀ a₀ : ResidueField R, aeval a₀ f = 0 → aeval a₀ (derivative f) ≠ 0 → ∃ a : R, f.IsRoot a ∧ residue R a = a₀, ∀ {K : Type u} [Field K], ∀ (φ : R →+* K), Surjective φ → ∀ f : R[X], f.Monic → ∀ a₀ : K, f.eval₂ φ a₀ = 0 → f.derivative.eval₂ φ a₀ ≠ 0 → ∃ a : R, f.IsRoot a ∧ φ a = a₀] := by tfae_have 3 → 2 | H => H (residue R) Ideal.Quotient.mk_surjective tfae_have 2 → 1 | H => by constructor intro f hf a₀ h₁ h₂ specialize H f hf (residue R a₀) have aux := flip mem_nonunits_iff.mp h₂ simp only [aeval_def, ResidueField.algebraMap_eq, eval₂_at_apply, ← Ideal.Quotient.eq_zero_iff_mem, ← IsLocalRing.mem_maximalIdeal] at H h₁ aux obtain ⟨a, ha₁, ha₂⟩ := H h₁ aux refine ⟨a, ha₁, ?_⟩ rw [← Ideal.Quotient.eq_zero_iff_mem] rwa [← sub_eq_zero, ← RingHom.map_sub] at ha₂ tfae_have 1 → 3 | hR, K, _K, φ, hφ, f, hf, a₀, h₁, h₂ => by obtain ⟨a₀, rfl⟩ := hφ a₀ have H := HenselianLocalRing.is_henselian f hf a₀ simp only [← ker_eq_maximalIdeal φ hφ, eval₂_at_apply, RingHom.mem_ker] at H h₁ h₂ obtain ⟨a, ha₁, ha₂⟩ := H h₁ (by contrapose! h₂ rwa [← mem_nonunits_iff, ← mem_maximalIdeal, ← ker_eq_maximalIdeal φ hφ, RingHom.mem_ker] at h₂) refine ⟨a, ha₁, ?_⟩ rwa [φ.map_sub, sub_eq_zero] at ha₂ tfae_finish instance (R : Type*) [CommRing R] [hR : HenselianLocalRing R] : HenselianRing R (maximalIdeal R) where jac := by rw [Ideal.jacobson, le_sInf_iff] rintro I ⟨-, hI⟩ exact (eq_maximalIdeal hI).ge is_henselian := by intro f hf a₀ h₁ h₂ refine HenselianLocalRing.is_henselian f hf a₀ h₁ ?_ contrapose! h₂ rw [← mem_nonunits_iff, ← IsLocalRing.mem_maximalIdeal, ← Ideal.Quotient.eq_zero_iff_mem] at h₂ rw [h₂] exact not_isUnit_zero -- see Note [lower instance priority] /-- A ring `R` that is `I`-adically complete is Henselian at `I`. -/ instance (priority := 100) IsAdicComplete.henselianRing (R : Type*) [CommRing R] (I : Ideal R) [IsAdicComplete I R] : HenselianRing R I where jac := IsAdicComplete.le_jacobson_bot _ is_henselian := by intro f _ a₀ h₁ h₂ classical let f' := derivative f -- we define a sequence `c n` by starting at `a₀` and then continually -- applying the function sending `b` to `b - f(b)/f'(b)` (Newton's method). -- Note that `f'.eval b` is a unit, because `b` has the same residue as `a₀` modulo `I`. let c : ℕ → R := fun n => Nat.recOn n a₀ fun _ b => b - f.eval b * Ring.inverse (f'.eval b) have hc : ∀ n, c (n + 1) = c n - f.eval (c n) * Ring.inverse (f'.eval (c n)) := by intro n simp only [c] -- we now spend some time determining properties of the sequence `c : ℕ → R` -- `hc_mod`: for every `n`, we have `c n ≡ a₀ [SMOD I]` -- `hf'c` : for every `n`, `f'.eval (c n)` is a unit -- `hfcI` : for every `n`, `f.eval (c n)` is contained in `I ^ (n+1)` have hc_mod : ∀ n, c n ≡ a₀ [SMOD I] := by intro n induction' n with n ih · rfl rw [hc, sub_eq_add_neg, ← add_zero a₀] refine ih.add ?_ rw [SModEq.zero, Ideal.neg_mem_iff] refine I.mul_mem_right _ ?_ rw [← SModEq.zero] at h₁ ⊢ exact (ih.eval f).trans h₁ have hf'c : ∀ n, IsUnit (f'.eval (c n)) := by intro n haveI := isLocalHom_of_le_jacobson_bot I (IsAdicComplete.le_jacobson_bot I) apply IsUnit.of_map (Ideal.Quotient.mk I) convert h₂ using 1 exact SModEq.def.mp ((hc_mod n).eval _) have hfcI : ∀ n, f.eval (c n) ∈ I ^ (n + 1) := by intro n induction' n with n ih · simpa only [Nat.rec_zero, zero_add, pow_one] using h₁ rw [← taylor_eval_sub (c n), hc, sub_eq_add_neg, sub_eq_add_neg, add_neg_cancel_comm] rw [eval_eq_sum, sum_over_range' _ _ _ (lt_add_of_pos_right _ zero_lt_two), ← Finset.sum_range_add_sum_Ico _ (Nat.le_add_left _ _)] swap · intro i rw [zero_mul] refine Ideal.add_mem _ ?_ ?_ · rw [← one_add_one_eq_two, Finset.sum_range_succ, Finset.range_one, Finset.sum_singleton, taylor_coeff_zero, taylor_coeff_one, pow_zero, pow_one, mul_one, mul_neg, mul_left_comm, Ring.mul_inverse_cancel _ (hf'c n), mul_one, add_neg_cancel] exact Ideal.zero_mem _ · refine Submodule.sum_mem _ ?_ simp only [Finset.mem_Ico] rintro i ⟨h2i, _⟩ have aux : n + 2 ≤ i * (n + 1) := by trans 2 * (n + 1) <;> nlinarith only [h2i] refine Ideal.mul_mem_left _ _ (Ideal.pow_le_pow_right aux ?_) rw [pow_mul'] exact Ideal.pow_mem_pow ((Ideal.neg_mem_iff _).2 <| Ideal.mul_mem_right _ _ ih) _ -- we are now in the position to show that `c : ℕ → R` is a Cauchy sequence have aux : ∀ m n, m ≤ n → c m ≡ c n [SMOD (I ^ m • ⊤ : Ideal R)] := by intro m n hmn rw [← Ideal.one_eq_top, Ideal.smul_eq_mul, mul_one] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn clear hmn induction' k with k ih · rw [add_zero] rw [← add_assoc, hc, ← add_zero (c m), sub_eq_add_neg] refine ih.add ?_ symm rw [SModEq.zero, Ideal.neg_mem_iff] refine Ideal.mul_mem_right _ _ (Ideal.pow_le_pow_right ?_ (hfcI _)) rw [add_assoc] exact le_self_add -- hence the sequence converges to some limit point `a`, which is the `a` we are looking for obtain ⟨a, ha⟩ := IsPrecomplete.prec' c (aux _ _) refine ⟨a, ?_, ?_⟩ · show f.IsRoot a suffices ∀ n, f.eval a ≡ 0 [SMOD (I ^ n • ⊤ : Ideal R)] by exact IsHausdorff.haus' _ this intro n specialize ha n rw [← Ideal.one_eq_top, Ideal.smul_eq_mul, mul_one] at ha ⊢ refine (ha.symm.eval f).trans ?_ rw [SModEq.zero] exact Ideal.pow_le_pow_right le_self_add (hfcI _) · show a - a₀ ∈ I specialize ha (0 + 1) rw [hc, pow_one, ← Ideal.one_eq_top, Ideal.smul_eq_mul, mul_one, sub_eq_add_neg] at ha rw [← SModEq.sub_mem, ← add_zero a₀] refine ha.symm.trans (SModEq.rfl.add ?_) rw [SModEq.zero, Ideal.neg_mem_iff] exact Ideal.mul_mem_right _ _ h₁
DirichletTheorem.lean
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.LinearAlgebra.Matrix.Gershgorin import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.ConvexBody import Mathlib.NumberTheory.NumberField.Units.Basic /-! # Dirichlet theorem on the group of units of a number field This file is devoted to the proof of Dirichlet unit theorem that states that the group of units `(𝓞 K)ˣ` of units of the ring of integers `𝓞 K` of a number field `K` modulo its torsion subgroup is a free `ℤ`-module of rank `card (InfinitePlace K) - 1`. ## Main definitions * `NumberField.Units.rank`: the unit rank of the number field `K`. * `NumberField.Units.fundSystem`: a fundamental system of units of `K`. * `NumberField.Units.basisModTorsion`: a `ℤ`-basis of `(𝓞 K)ˣ ⧸ (torsion K)` as an additive `ℤ`-module. ## Main results * `NumberField.Units.rank_modTorsion`: the `ℤ`-rank of `(𝓞 K)ˣ ⧸ (torsion K)` is equal to `card (InfinitePlace K) - 1`. * `NumberField.Units.exist_unique_eq_mul_prod`: **Dirichlet Unit Theorem**. Any unit of `𝓞 K` can be written uniquely as the product of a root of unity and powers of the units of the fundamental system `fundSystem`. ## Tags number field, units, Dirichlet unit theorem -/ noncomputable section open Module NumberField NumberField.InfinitePlace NumberField.Units variable (K : Type*) [Field K] namespace NumberField.Units.dirichletUnitTheorem /-! ### Dirichlet Unit Theorem We define a group morphism from `(𝓞 K)ˣ` to `logSpace K`, defined as `{w : InfinitePlace K // w ≠ w₀} → ℝ` where `w₀` is a distinguished (arbitrary) infinite place, prove that its kernel is the torsion subgroup (see `logEmbedding_eq_zero_iff`) and that its image, called `unitLattice`, is a full `ℤ`-lattice. It follows that `unitLattice` is a free `ℤ`-module (see `instModuleFree_unitLattice`) of rank `card (InfinitePlaces K) - 1` (see `unitLattice_rank`). To prove that the `unitLattice` is a full `ℤ`-lattice, we need to prove that it is discrete (see `unitLattice_inter_ball_finite`) and that it spans the full space over `ℝ` (see `unitLattice_span_eq_top`); this is the main part of the proof, see the section `span_top` below for more details. -/ open Finset variable {K} section NumberField variable [NumberField K] /-- The distinguished infinite place. -/ def w₀ : InfinitePlace K := (inferInstance : Nonempty (InfinitePlace K)).some variable (K) in /-- The `logSpace` is defined as `{w : InfinitePlace K // w ≠ w₀} → ℝ` where `w₀` is the distinguished infinite place. -/ abbrev logSpace := {w : InfinitePlace K // w ≠ w₀} → ℝ variable (K) in /-- The logarithmic embedding of the units (seen as an `Additive` group). -/ def _root_.NumberField.Units.logEmbedding : Additive ((𝓞 K)ˣ) →+ logSpace K := { toFun := fun x w ↦ mult w.val * Real.log (w.val ↑x.toMul) map_zero' := by simp; rfl map_add' := fun _ _ ↦ by simp [Real.log_mul, mul_add]; rfl } @[simp] theorem logEmbedding_component (x : (𝓞 K)ˣ) (w : {w : InfinitePlace K // w ≠ w₀}) : (logEmbedding K (Additive.ofMul x)) w = mult w.val * Real.log (w.val x) := rfl open scoped Classical in theorem sum_logEmbedding_component (x : (𝓞 K)ˣ) : ∑ w, logEmbedding K (Additive.ofMul x) w = -mult (w₀ : InfinitePlace K) * Real.log (w₀ (x : K)) := by have h := sum_mult_mul_log x rw [Fintype.sum_eq_add_sum_subtype_ne _ w₀, add_comm, add_eq_zero_iff_eq_neg, ← neg_mul] at h simpa [logEmbedding_component] using h end NumberField theorem mult_log_place_eq_zero {x : (𝓞 K)ˣ} {w : InfinitePlace K} : mult w * Real.log (w x) = 0 ↔ w x = 1 := by rw [mul_eq_zero, or_iff_right, Real.log_eq_zero, or_iff_right, or_iff_left] · linarith [(apply_nonneg _ _ : 0 ≤ w x)] · exact (Units.pos_at_place _ _).ne' · exact mult_coe_ne_zero variable [NumberField K] theorem logEmbedding_eq_zero_iff {x : (𝓞 K)ˣ} : logEmbedding K (Additive.ofMul x) = 0 ↔ x ∈ torsion K := by rw [mem_torsion] refine ⟨fun h w ↦ ?_, fun h ↦ ?_⟩ · by_cases hw : w = w₀ · suffices -mult w₀ * Real.log (w₀ (x : K)) = 0 by rw [neg_mul, neg_eq_zero, ← hw] at this exact mult_log_place_eq_zero.mp this rw [← sum_logEmbedding_component, sum_eq_zero] exact fun w _ ↦ congrFun h w · exact mult_log_place_eq_zero.mp (congrFun h ⟨w, hw⟩) · ext w rw [logEmbedding_component, h w.val, Real.log_one, mul_zero, Pi.zero_apply] open scoped Classical in theorem logEmbedding_component_le {r : ℝ} {x : (𝓞 K)ˣ} (hr : 0 ≤ r) (h : ‖logEmbedding K x‖ ≤ r) (w : {w : InfinitePlace K // w ≠ w₀}) : |logEmbedding K (Additive.ofMul x) w| ≤ r := by lift r to NNReal using hr simp_rw [Pi.norm_def, NNReal.coe_le_coe, Finset.sup_le_iff, ← NNReal.coe_le_coe] at h exact h w (mem_univ _) open scoped Classical in theorem log_le_of_logEmbedding_le {r : ℝ} {x : (𝓞 K)ˣ} (hr : 0 ≤ r) (h : ‖logEmbedding K (Additive.ofMul x)‖ ≤ r) (w : InfinitePlace K) : |Real.log (w x)| ≤ (Fintype.card (InfinitePlace K)) * r := by have tool : ∀ x : ℝ, 0 ≤ x → x ≤ mult w * x := fun x hx ↦ by nth_rw 1 [← one_mul x] refine mul_le_mul ?_ le_rfl hx ?_ all_goals { rw [mult]; split_ifs <;> norm_num } by_cases hw : w = w₀ · have hyp := congr_arg (‖·‖) (sum_logEmbedding_component x).symm replace hyp := (le_of_eq hyp).trans (norm_sum_le _ _) simp_rw [norm_mul, norm_neg, Real.norm_eq_abs, Nat.abs_cast] at hyp refine (le_trans ?_ hyp).trans ?_ · rw [← hw] exact tool _ (abs_nonneg _) · refine (sum_le_card_nsmul univ _ _ (fun w _ ↦ logEmbedding_component_le hr h w)).trans ?_ rw [nsmul_eq_mul] refine mul_le_mul ?_ le_rfl hr (Fintype.card (InfinitePlace K)).cast_nonneg simp · have hyp := logEmbedding_component_le hr h ⟨w, hw⟩ rw [logEmbedding_component, abs_mul, Nat.abs_cast] at hyp refine (le_trans ?_ hyp).trans ?_ · exact tool _ (abs_nonneg _) · nth_rw 1 [← one_mul r] exact mul_le_mul (Nat.one_le_cast.mpr Fintype.card_pos) (le_of_eq rfl) hr (Nat.cast_nonneg _) variable (K) /-- The lattice formed by the image of the logarithmic embedding. -/ noncomputable def _root_.NumberField.Units.unitLattice : Submodule ℤ (logSpace K) := Submodule.map (logEmbedding K).toIntLinearMap ⊤ open scoped Classical in theorem unitLattice_inter_ball_finite (r : ℝ) : ((unitLattice K : Set (logSpace K)) ∩ Metric.closedBall 0 r).Finite := by obtain hr | hr := lt_or_ge r 0 · convert Set.finite_empty rw [Metric.closedBall_eq_empty.mpr hr] exact Set.inter_empty _ · suffices {x : (𝓞 K)ˣ | IsIntegral ℤ (x : K) ∧ ∀ (φ : K →+* ℂ), ‖φ x‖ ≤ Real.exp ((Fintype.card (InfinitePlace K)) * r)}.Finite by refine (Set.Finite.image (logEmbedding K) this).subset ?_ rintro _ ⟨⟨x, ⟨_, rfl⟩⟩, hx⟩ refine ⟨x, ⟨x.val.prop, (le_iff_le _ _).mp (fun w ↦ (Real.log_le_iff_le_exp ?_).mp ?_)⟩, rfl⟩ · exact pos_iff.mpr (coe_ne_zero x) · rw [mem_closedBall_zero_iff] at hx exact (le_abs_self _).trans (log_le_of_logEmbedding_le hr hx w) refine Set.Finite.of_finite_image ?_ (coe_injective K).injOn refine (Embeddings.finite_of_norm_le K ℂ (Real.exp ((Fintype.card (InfinitePlace K)) * r))).subset ?_ rintro _ ⟨x, ⟨⟨h_int, h_le⟩, rfl⟩⟩ exact ⟨h_int, h_le⟩ section span_top /-! #### Section `span_top` In this section, we prove that the span over `ℝ` of the `unitLattice` is equal to the full space. For this, we construct for each infinite place `w₁ ≠ w₀` a unit `u_w₁` of `K` such that, for all infinite places `w` such that `w ≠ w₁`, we have `Real.log w (u_w₁) < 0` (and thus `Real.log w₁ (u_w₁) > 0`). It follows then from a determinant computation (using `Matrix.det_ne_zero_of_sum_col_lt_diag`) that the image by `logEmbedding` of these units is a `ℝ`-linearly independent family. The unit `u_w₁` is obtained by constructing a sequence `seq n` of nonzero algebraic integers that is strictly decreasing at infinite places distinct from `w₁` and of norm `≤ B`. Since there are finitely many ideals of norm `≤ B`, there exists two term in the sequence defining the same ideal and their quotient is the desired unit `u_w₁` (see `exists_unit`). -/ open NumberField.mixedEmbedding NNReal variable (w₁ : InfinitePlace K) {B : ℕ} (hB : minkowskiBound K 1 < (convexBodyLTFactor K) * B) include hB in /-- This result shows that there always exists a next term in the sequence. -/ theorem seq_next {x : 𝓞 K} (hx : x ≠ 0) : ∃ y : 𝓞 K, y ≠ 0 ∧ (∀ w, w ≠ w₁ → w y < w x) ∧ |Algebra.norm ℚ (y : K)| ≤ B := by have hx' := RingOfIntegers.coe_ne_zero_iff.mpr hx let f : InfinitePlace K → ℝ≥0 := fun w ↦ ⟨(w x) / 2, div_nonneg (AbsoluteValue.nonneg _ _) (by simp)⟩ suffices ∀ w, w ≠ w₁ → f w ≠ 0 by obtain ⟨g, h_geqf, h_gprod⟩ := adjust_f K B this obtain ⟨y, h_ynz, h_yle⟩ := exists_ne_zero_mem_ringOfIntegers_lt K (f := g) (by rw [convexBodyLT_volume]; convert hB; exact congr_arg ((↑) : NNReal → ENNReal) h_gprod) refine ⟨y, h_ynz, fun w hw ↦ (h_geqf w hw ▸ h_yle w).trans ?_, ?_⟩ · rw [← Rat.cast_le (K := ℝ), Rat.cast_natCast] calc _ = ∏ w : InfinitePlace K, w (algebraMap _ K y) ^ mult w := (prod_eq_abs_norm (algebraMap _ K y)).symm _ ≤ ∏ w : InfinitePlace K, (g w : ℝ) ^ mult w := by gcongr with w; exact (h_yle w).le _ ≤ (B : ℝ) := by simp_rw [← NNReal.coe_pow, ← NNReal.coe_prod] exact le_of_eq (congr_arg toReal h_gprod) · refine div_lt_self ?_ (by simp) exact pos_iff.mpr hx' intro _ _ rw [ne_eq, Nonneg.mk_eq_zero, div_eq_zero_iff, map_eq_zero, not_or] exact ⟨hx', by simp⟩ /-- An infinite sequence of nonzero algebraic integers of `K` satisfying the following properties: • `seq n` is nonzero; • for `w : InfinitePlace K`, `w ≠ w₁ → w (seq n + 1) < w (seq n)`; • `∣norm (seq n)∣ ≤ B`. -/ def seq : ℕ → { x : 𝓞 K // x ≠ 0 } | 0 => ⟨1, by simp⟩ | n + 1 => ⟨(seq_next K w₁ hB (seq n).prop).choose, (seq_next K w₁ hB (seq n).prop).choose_spec.1⟩ /-- The terms of the sequence are nonzero. -/ theorem seq_ne_zero (n : ℕ) : algebraMap (𝓞 K) K (seq K w₁ hB n) ≠ 0 := RingOfIntegers.coe_ne_zero_iff.mpr (seq K w₁ hB n).prop /-- The sequence is strictly decreasing at infinite places distinct from `w₁`. -/ theorem seq_decreasing {n m : ℕ} (h : n < m) (w : InfinitePlace K) (hw : w ≠ w₁) : w (algebraMap (𝓞 K) K (seq K w₁ hB m)) < w (algebraMap (𝓞 K) K (seq K w₁ hB n)) := by induction m with | zero => exfalso exact Nat.not_succ_le_zero n h | succ m m_ih => cases eq_or_lt_of_le (Nat.le_of_lt_succ h) with | inl hr => rw [hr] exact (seq_next K w₁ hB (seq K w₁ hB m).prop).choose_spec.2.1 w hw | inr hr => refine lt_trans ?_ (m_ih hr) exact (seq_next K w₁ hB (seq K w₁ hB m).prop).choose_spec.2.1 w hw /-- The terms of the sequence have norm bounded by `B`. -/ theorem seq_norm_le (n : ℕ) : Int.natAbs (Algebra.norm ℤ (seq K w₁ hB n : 𝓞 K)) ≤ B := by cases n with | zero => have : 1 ≤ B := by contrapose! hB simp only [Nat.lt_one_iff.mp hB, CharP.cast_eq_zero, mul_zero, zero_le] simp only [ne_eq, seq, map_one, Int.natAbs_one, this] | succ n => rw [← Nat.cast_le (α := ℚ), Int.cast_natAbs, Int.cast_abs, Algebra.coe_norm_int] exact (seq_next K w₁ hB (seq K w₁ hB n).prop).choose_spec.2.2 /-- Construct a unit associated to the place `w₁`. The family, for `w₁ ≠ w₀`, formed by the image by the `logEmbedding` of these units is `ℝ`-linearly independent, see `unitLattice_span_eq_top`. -/ theorem exists_unit (w₁ : InfinitePlace K) : ∃ u : (𝓞 K)ˣ, ∀ w : InfinitePlace K, w ≠ w₁ → Real.log (w u) < 0 := by obtain ⟨B, hB⟩ : ∃ B : ℕ, minkowskiBound K 1 < (convexBodyLTFactor K) * B := by conv => congr; ext; rw [mul_comm] exact ENNReal.exists_nat_mul_gt (ENNReal.coe_ne_zero.mpr (convexBodyLTFactor_ne_zero K)) (ne_of_lt (minkowskiBound_lt_top K 1)) rsuffices ⟨n, m, hnm, h⟩ : ∃ n m, n < m ∧ (Ideal.span ({ (seq K w₁ hB n : 𝓞 K) }) = Ideal.span ({ (seq K w₁ hB m : 𝓞 K) })) · have hu := Ideal.span_singleton_eq_span_singleton.mp h refine ⟨hu.choose, fun w hw ↦ Real.log_neg (pos_at_place hu.choose w) ?_⟩ calc _ = w (algebraMap (𝓞 K) K (seq K w₁ hB m) * (algebraMap (𝓞 K) K (seq K w₁ hB n))⁻¹) := by rw [← congr_arg (algebraMap (𝓞 K) K) hu.choose_spec, mul_comm, map_mul (algebraMap _ _), ← mul_assoc, inv_mul_cancel₀ (seq_ne_zero K w₁ hB n), one_mul] _ = w (algebraMap (𝓞 K) K (seq K w₁ hB m)) * w (algebraMap (𝓞 K) K (seq K w₁ hB n))⁻¹ := map_mul _ _ _ _ < 1 := by rw [map_inv₀, mul_inv_lt_iff₀' (pos_iff.mpr (seq_ne_zero K w₁ hB n)), mul_one] exact seq_decreasing K w₁ hB hnm w hw refine Set.Finite.exists_lt_map_eq_of_forall_mem (t := {I : Ideal (𝓞 K) | Ideal.absNorm I ≤ B}) (fun n ↦ ?_) (Ideal.finite_setOf_absNorm_le B) rw [Set.mem_setOf_eq, Ideal.absNorm_span_singleton] exact seq_norm_le K w₁ hB n theorem unitLattice_span_eq_top : Submodule.span ℝ (unitLattice K : Set (logSpace K)) = ⊤ := by classical refine le_antisymm le_top ?_ -- The standard basis let B := Pi.basisFun ℝ {w : InfinitePlace K // w ≠ w₀} -- The image by log_embedding of the family of units constructed above let v := fun w : { w : InfinitePlace K // w ≠ w₀ } ↦ logEmbedding K (Additive.ofMul (exists_unit K w).choose) -- To prove the result, it is enough to prove that the family `v` is linearly independent suffices B.det v ≠ 0 by rw [← isUnit_iff_ne_zero, ← Basis.is_basis_iff_det] at this rw [← this.2] refine Submodule.span_monotone fun _ ⟨w, hw⟩ ↦ ⟨(exists_unit K w).choose, trivial, hw⟩ rw [Basis.det_apply] -- We use a specific lemma to prove that this determinant is nonzero refine det_ne_zero_of_sum_col_lt_diag (fun w ↦ ?_) simp_rw [Real.norm_eq_abs, B, Basis.coePiBasisFun.toMatrix_eq_transpose, Matrix.transpose_apply] rw [← sub_pos, sum_congr rfl (fun x hx ↦ abs_of_neg ?_), sum_neg_distrib, sub_neg_eq_add, sum_erase_eq_sub (mem_univ _), ← add_comm_sub] · refine add_pos_of_nonneg_of_pos ?_ ?_ · rw [sub_nonneg] exact le_abs_self _ · rw [sum_logEmbedding_component (exists_unit K w).choose] refine mul_pos_of_neg_of_neg ?_ ((exists_unit K w).choose_spec _ w.prop.symm) rw [mult]; split_ifs <;> norm_num · refine mul_neg_of_pos_of_neg ?_ ((exists_unit K w).choose_spec x ?_) · rw [mult]; split_ifs <;> norm_num · exact Subtype.ext_iff_val.not.mp (ne_of_mem_erase hx) end span_top end dirichletUnitTheorem section statements variable [NumberField K] open dirichletUnitTheorem Module /-- The unit rank of the number field `K`, it is equal to `card (InfinitePlace K) - 1`. -/ def rank : ℕ := Fintype.card (InfinitePlace K) - 1 instance instDiscrete_unitLattice : DiscreteTopology (unitLattice K) := by classical refine discreteTopology_of_isOpen_singleton_zero ?_ refine isOpen_singleton_of_finite_mem_nhds 0 (s := Metric.closedBall 0 1) ?_ ?_ · exact Metric.closedBall_mem_nhds _ (by simp) · refine Set.Finite.of_finite_image ?_ (Set.injOn_of_injective Subtype.val_injective) convert unitLattice_inter_ball_finite K 1 ext x refine ⟨?_, fun ⟨hx1, hx2⟩ ↦ ⟨⟨x, hx1⟩, hx2, rfl⟩⟩ rintro ⟨x, hx, rfl⟩ exact ⟨Subtype.mem x, hx⟩ open scoped Classical in instance instZLattice_unitLattice : IsZLattice ℝ (unitLattice K) where span_top := unitLattice_span_eq_top K protected theorem finrank_eq_rank : finrank ℝ (logSpace K) = Units.rank K := by classical simp only [finrank_fintype_fun_eq_card, Fintype.card_subtype_compl, Fintype.card_ofSubsingleton, rank] @[simp] theorem unitLattice_rank : finrank ℤ (unitLattice K) = Units.rank K := by classical rw [← Units.finrank_eq_rank, ZLattice.rank ℝ] /-- The map obtained by quotienting by the kernel of `logEmbedding`. -/ def logEmbeddingQuot : Additive ((𝓞 K)ˣ ⧸ (torsion K)) →+ logSpace K := MonoidHom.toAdditive' <| (QuotientGroup.kerLift (AddMonoidHom.toMultiplicative' (logEmbedding K))).comp (QuotientGroup.quotientMulEquivOfEq (by ext rw [MonoidHom.mem_ker, AddMonoidHom.toMultiplicative'_apply_apply, ofAdd_eq_one, ← logEmbedding_eq_zero_iff])).toMonoidHom @[simp] theorem logEmbeddingQuot_apply (x : (𝓞 K)ˣ) : logEmbeddingQuot K (Additive.ofMul (QuotientGroup.mk x)) = logEmbedding K (Additive.ofMul x) := rfl theorem logEmbeddingQuot_injective : Function.Injective (logEmbeddingQuot K) := by unfold logEmbeddingQuot intro _ _ h simp_rw [MonoidHom.toAdditive'_apply_apply, MonoidHom.coe_comp, MulEquiv.coe_toMonoidHom, Function.comp_apply, EmbeddingLike.apply_eq_iff_eq] at h exact (EmbeddingLike.apply_eq_iff_eq _).mp <| (QuotientGroup.kerLift_injective _).eq_iff.mp h /-- The linear equivalence between `(𝓞 K)ˣ ⧸ (torsion K)` as an additive `ℤ`-module and `unitLattice` . -/ def logEmbeddingEquiv : Additive ((𝓞 K)ˣ ⧸ (torsion K)) ≃ₗ[ℤ] (unitLattice K) := LinearEquiv.ofBijective ((logEmbeddingQuot K).codRestrict (unitLattice K) (Quotient.ind fun _ ↦ logEmbeddingQuot_apply K _ ▸ Submodule.mem_map_of_mem trivial)).toIntLinearMap ⟨fun _ _ ↦ by rw [AddMonoidHom.coe_toIntLinearMap, AddMonoidHom.codRestrict_apply, AddMonoidHom.codRestrict_apply, Subtype.mk.injEq] apply logEmbeddingQuot_injective K, fun ⟨a, ⟨b, _, ha⟩⟩ ↦ ⟨⟦b⟧, by simpa using ha⟩⟩ @[simp] theorem logEmbeddingEquiv_apply (x : (𝓞 K)ˣ) : logEmbeddingEquiv K (Additive.ofMul (QuotientGroup.mk x)) = logEmbedding K (Additive.ofMul x) := rfl instance : Module.Free ℤ (Additive ((𝓞 K)ˣ ⧸ (torsion K))) := by classical exact Module.Free.of_equiv (logEmbeddingEquiv K).symm instance : Module.Finite ℤ (Additive ((𝓞 K)ˣ ⧸ (torsion K))) := by classical exact Module.Finite.equiv (logEmbeddingEquiv K).symm -- Note that we prove this instance first and then deduce from it the instance -- `Monoid.FG (𝓞 K)ˣ`, and not the other way around, due to no `Subgroup` version -- of `Submodule.fg_of_fg_map_of_fg_inf_ker` existing. instance : Module.Finite ℤ (Additive (𝓞 K)ˣ) := by rw [Module.finite_def] refine Submodule.fg_of_fg_map_of_fg_inf_ker (MonoidHom.toAdditive (QuotientGroup.mk' (torsion K))).toIntLinearMap ?_ ?_ · rw [Submodule.map_top, LinearMap.range_eq_top.mpr (by exact QuotientGroup.mk'_surjective (torsion K)), ← Module.finite_def] infer_instance · rw [inf_of_le_right le_top, AddMonoidHom.coe_toIntLinearMap_ker, MonoidHom.coe_toAdditive_ker, QuotientGroup.ker_mk', Submodule.fg_iff_add_subgroup_fg, AddSubgroup.toIntSubmodule_toAddSubgroup, ← AddGroup.fg_iff_addSubgroup_fg] have : Finite (Subgroup.toAddSubgroup (torsion K)) := (inferInstance : Finite (torsion K)) exact AddGroup.fg_of_finite instance : Monoid.FG (𝓞 K)ˣ := by rw [Monoid.fg_iff_add_fg, ← AddGroup.fg_iff_addMonoid_fg, ← Module.Finite.iff_addGroup_fg] infer_instance theorem rank_modTorsion : Module.finrank ℤ (Additive ((𝓞 K)ˣ ⧸ (torsion K))) = rank K := by rw [← LinearEquiv.finrank_eq (logEmbeddingEquiv K).symm, unitLattice_rank] /-- A basis of the quotient `(𝓞 K)ˣ ⧸ (torsion K)` seen as an additive ℤ-module. -/ def basisModTorsion : Basis (Fin (rank K)) ℤ (Additive ((𝓞 K)ˣ ⧸ (torsion K))) := Basis.reindex (Module.Free.chooseBasis ℤ _) (Fintype.equivOfCardEq <| by rw [← Module.finrank_eq_card_chooseBasisIndex, rank_modTorsion, Fintype.card_fin]) /-- The basis of the `unitLattice` obtained by mapping `basisModTorsion` via `logEmbedding`. -/ def basisUnitLattice : Basis (Fin (rank K)) ℤ (unitLattice K) := (basisModTorsion K).map (logEmbeddingEquiv K) /-- A fundamental system of units of `K`. The units of `fundSystem` are arbitrary lifts of the units in `basisModTorsion`. -/ def fundSystem : Fin (rank K) → (𝓞 K)ˣ := -- `:)` prevents the `⧸` decaying to a quotient by `leftRel` when we unfold this later fun i ↦ Quotient.out ((basisModTorsion K i).toMul :) theorem fundSystem_mk (i : Fin (rank K)) : Additive.ofMul (QuotientGroup.mk (fundSystem K i)) = (basisModTorsion K i) := by simp_rw [fundSystem, Equiv.apply_eq_iff_eq_symm_apply, Additive.ofMul_symm_eq, Quotient.out_eq'] theorem logEmbedding_fundSystem (i : Fin (rank K)) : logEmbedding K (Additive.ofMul (fundSystem K i)) = basisUnitLattice K i := by rw [basisUnitLattice, Basis.map_apply, ← fundSystem_mk, logEmbeddingEquiv_apply] /-- The exponents that appear in the unique decomposition of a unit as the product of a root of unity and powers of the units of the fundamental system `fundSystem` (see `exist_unique_eq_mul_prod`) are given by the representation of the unit on `basisModTorsion`. -/ theorem fun_eq_repr {x ζ : (𝓞 K)ˣ} {f : Fin (rank K) → ℤ} (hζ : ζ ∈ torsion K) (h : x = ζ * ∏ i, (fundSystem K i) ^ (f i)) : f = (basisModTorsion K).repr (Additive.ofMul ↑x) := by suffices Additive.ofMul ↑x = ∑ i, (f i) • (basisModTorsion K i) by rw [← (basisModTorsion K).repr_sum_self f, ← this] calc Additive.ofMul ↑x _ = ∑ i, (f i) • Additive.ofMul ↑(fundSystem K i) := by rw [h, QuotientGroup.mk_mul, (QuotientGroup.eq_one_iff _).mpr hζ, one_mul, QuotientGroup.mk_prod, ofMul_prod]; rfl _ = ∑ i, (f i) • (basisModTorsion K i) := by simp_rw [fundSystem, QuotientGroup.out_eq', ofMul_toMul] /-- **Dirichlet Unit Theorem**. Any unit `x` of `𝓞 K` can be written uniquely as the product of a root of unity and powers of the units of the fundamental system `fundSystem`. -/ theorem exist_unique_eq_mul_prod (x : (𝓞 K)ˣ) : ∃! ζe : torsion K × (Fin (rank K) → ℤ), x = ζe.1 * ∏ i, (fundSystem K i) ^ (ζe.2 i) := by let ζ := x * (∏ i, (fundSystem K i) ^ ((basisModTorsion K).repr (Additive.ofMul ↑x) i))⁻¹ have h_tors : ζ ∈ torsion K := by rw [← QuotientGroup.eq_one_iff, QuotientGroup.mk_mul, QuotientGroup.mk_inv, ← ofMul_eq_zero, ofMul_mul, ofMul_inv, QuotientGroup.mk_prod, ofMul_prod] simp_rw [QuotientGroup.mk_zpow, ofMul_zpow, fundSystem, QuotientGroup.out_eq'] rw [add_eq_zero_iff_eq_neg, neg_neg] exact ((basisModTorsion K).sum_repr (Additive.ofMul ↑x)).symm refine ⟨⟨⟨ζ, h_tors⟩, ((basisModTorsion K).repr (Additive.ofMul ↑x) : Fin (rank K) → ℤ)⟩, ?_, ?_⟩ · simp only [ζ, _root_.inv_mul_cancel_right] · rintro ⟨⟨ζ', h_tors'⟩, η⟩ hf simp only [ζ, ← fun_eq_repr K h_tors' hf, Prod.mk.injEq, Subtype.mk.injEq, and_true] nth_rewrite 1 [hf] rw [_root_.mul_inv_cancel_right] end statements end NumberField.Units
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.
apply_congr.lean
import Mathlib.Tactic.ApplyCongr import Mathlib.Algebra.BigOperators.Group.Finset.Powerset example (f g : ℤ → ℤ) (S : Finset ℤ) (h : ∀ m ∈ S, f m = g m) : Finset.sum S f = Finset.sum S g := by conv_lhs => -- If we just call `congr` here, in the second goal we're helpless, -- because we are only given the opportunity to rewrite `f`. -- However `apply_congr` uses the appropriate `@[congr]` lemma, -- so we get to rewrite `f x`, in the presence of the crucial `H : x ∈ S` hypothesis. apply_congr · skip · simp [*]
Pi.lean
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.MeasurableSpace.Constructions import Mathlib.MeasureTheory.PiSystem /-! # Bases of the indexed product σ-algebra In this file we prove several versions of the following lemma: given a finite indexed collection of measurable spaces `α i`, if the σ-algebra on each `α i` is generated by `C i`, then the sets `{x | ∀ i, x i ∈ s i}`, where `s i ∈ C i`, generate the σ-algebra on the indexed product of `α i`s. -/ noncomputable section open Function Set MeasurableSpace Encodable variable {ι : Type*} {α : ι → Type*} /-! We start with some measurability properties -/ lemma MeasurableSpace.pi_eq_generateFrom_projections {mα : ∀ i, MeasurableSpace (α i)} : pi = generateFrom {B | ∃ (i : ι) (A : Set (α i)), MeasurableSet A ∧ eval i ⁻¹' A = B} := by simp only [pi, ← generateFrom_iUnion_measurableSet, iUnion_setOf, measurableSet_comap] /-- Boxes formed by π-systems form a π-system. -/ theorem IsPiSystem.pi {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsPiSystem (C i)) : IsPiSystem (pi univ '' pi univ C) := by rintro _ ⟨s₁, hs₁, rfl⟩ _ ⟨s₂, hs₂, rfl⟩ hst rw [← pi_inter_distrib] at hst ⊢; rw [univ_pi_nonempty_iff] at hst exact mem_image_of_mem _ fun i _ => hC i _ (hs₁ i (mem_univ i)) _ (hs₂ i (mem_univ i)) (hst i) /-- Boxes form a π-system. -/ theorem isPiSystem_pi [∀ i, MeasurableSpace (α i)] : IsPiSystem (pi univ '' pi univ fun i => { s : Set (α i) | MeasurableSet s }) := IsPiSystem.pi fun _ => isPiSystem_measurableSet section Finite variable [Finite ι] /-- Boxes of countably spanning sets are countably spanning. -/ theorem IsCountablySpanning.pi {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsCountablySpanning (C i)) : IsCountablySpanning (pi univ '' pi univ C) := by choose s h1s h2s using hC cases nonempty_encodable (ι → ℕ) let e : ℕ → ι → ℕ := fun n => (@decode (ι → ℕ) _ n).iget refine ⟨fun n => Set.pi univ fun i => s i (e n i), fun n => mem_image_of_mem _ fun i _ => h1s i _, ?_⟩ simp_rw [e, (surjective_decode_iget (ι → ℕ)).iUnion_comp fun x => Set.pi univ fun i => s i (x i), iUnion_univ_pi s, h2s, pi_univ] /-- The product of generated σ-algebras is the one generated by boxes, if both generating sets are countably spanning. -/ theorem generateFrom_pi_eq {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsCountablySpanning (C i)) : (@MeasurableSpace.pi _ _ fun i => generateFrom (C i)) = generateFrom (pi univ '' pi univ C) := by classical cases nonempty_encodable ι apply le_antisymm · refine iSup_le ?_; intro i; rw [comap_generateFrom] apply generateFrom_le; rintro _ ⟨s, hs, rfl⟩ choose t h1t h2t using hC simp_rw [eval_preimage, ← h2t] rw [← @iUnion_const _ ℕ _ s] have : Set.pi univ (update (fun i' : ι => iUnion (t i')) i (⋃ _ : ℕ, s)) = Set.pi univ fun k => ⋃ j : ℕ, @update ι (fun i' => Set (α i')) _ (fun i' => t i' j) i s k := by ext; simp_rw [mem_univ_pi]; apply forall_congr'; intro i' by_cases h : i' = i · subst h; simp · rw [← Ne] at h; simp [h] rw [this, ← iUnion_univ_pi] apply MeasurableSet.iUnion intro n; apply measurableSet_generateFrom apply mem_image_of_mem; intro j _; dsimp only by_cases h : j = i · subst h; rwa [update_self] · rw [update_of_ne h]; apply h1t · apply generateFrom_le; rintro _ ⟨s, hs, rfl⟩ rw [univ_pi_eq_iInter]; apply MeasurableSet.iInter; intro i apply @measurable_pi_apply _ _ (fun i => generateFrom (C i)) exact measurableSet_generateFrom (hs i (mem_univ i)) /-- If `C` and `D` generate the σ-algebras on `α` resp. `β`, then rectangles formed by `C` and `D` generate the σ-algebra on `α × β`. -/ theorem generateFrom_eq_pi [h : ∀ i, MeasurableSpace (α i)] {C : ∀ i, Set (Set (α i))} (hC : ∀ i, generateFrom (C i) = h i) (h2C : ∀ i, IsCountablySpanning (C i)) : generateFrom (pi univ '' pi univ C) = MeasurableSpace.pi := by simp only [← funext hC, generateFrom_pi_eq h2C] /-- The product σ-algebra is generated from boxes, i.e. `s ×ˢ t` for sets `s : set α` and `t : set β`. -/ theorem generateFrom_pi [∀ i, MeasurableSpace (α i)] : generateFrom (pi univ '' pi univ fun i => { s : Set (α i) | MeasurableSet s }) = MeasurableSpace.pi := generateFrom_eq_pi (fun _ => generateFrom_measurableSet) fun _ => isCountablySpanning_measurableSet end Finite
ShiftSequence.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.CategoryTheory.Shift.Basic import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! Sequences of functors from a category equipped with a shift Let `F : C ⥤ A` be a functor from a category `C` that is equipped with a shift by an additive monoid `M`. In this file, we define a typeclass `F.ShiftSequence M` which includes the data of a sequence of functors `F.shift a : C ⥤ A` for all `a : A`. For each `a : A`, we have an isomorphism `F.isoShift a : shiftFunctor C a ⋙ F ≅ F.shift a` which satisfies some coherence relations. This allows to state results (e.g. the long exact sequence of an homology functor (TODO)) using functors `F.shift a` rather than `shiftFunctor C a ⋙ F`. The reason for this design is that we can often choose functors `F.shift a` that have better definitional properties than `shiftFunctor C a ⋙ F`. For example, if `C` is the derived category (TODO) of an abelian category `A` and `F` is the homology functor in degree `0`, then for any `n : ℤ`, we may choose `F.shift n` to be the homology functor in degree `n`. -/ open CategoryTheory Category ZeroObject Limits variable {C A : Type*} [Category C] [Category A] (F : C ⥤ A) (M : Type*) [AddMonoid M] [HasShift C M] {G : Type*} [AddGroup G] [HasShift C G] namespace CategoryTheory namespace Functor /-- A shift sequence for a functor `F : C ⥤ A` when `C` is equipped with a shift by a monoid `M` involves a sequence of functor `sequence n : C ⥤ A` for all `n : M` which behave like `shiftFunctor C n ⋙ F`. -/ class ShiftSequence where /-- a sequence of functors -/ sequence : M → C ⥤ A /-- `sequence 0` identifies to the given functor -/ isoZero : sequence 0 ≅ F /-- compatibility isomorphism with the shift -/ shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ sequence a ≅ sequence a' shiftIso_zero (a : M) : shiftIso 0 a a (zero_add a) = isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ shiftIso_add : ∀ (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a''), shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (shiftIso n a a' ha') ≪≫ shiftIso m a' a'' ha'' /-- The tautological shift sequence on a functor. -/ noncomputable def ShiftSequence.tautological : ShiftSequence F M where sequence n := shiftFunctor C n ⋙ F isoZero := isoWhiskerRight (shiftFunctorZero C M) F ≪≫ F.rightUnitor shiftIso n a a' ha' := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (shiftFunctorAdd' C n a a' ha').symm _ shiftIso_zero a := by rw [shiftFunctorAdd'_zero_add] cat_disch shiftIso_add n m a a' a'' ha' ha'' := by ext X dsimp simp only [id_comp, ← Functor.map_comp] congr simpa only [← cancel_epi ((shiftFunctor C a).map ((shiftFunctorAdd C m n).hom.app X)), shiftFunctorAdd'_eq_shiftFunctorAdd, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, id_comp] using shiftFunctorAdd'_assoc_inv_app m n a (m+n) a' a'' rfl ha' (by rw [← ha'', ← ha', add_assoc]) X section variable {M} variable [F.ShiftSequence M] /-- The shifted functors given by the shift sequence. -/ def shift (n : M) : C ⥤ A := ShiftSequence.sequence F n /-- Compatibility isomorphism `shiftFunctor C n ⋙ F.shift a ≅ F.shift a'` when `n + a = a'`. -/ def shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ F.shift a ≅ F.shift a' := ShiftSequence.shiftIso n a a' ha' @[reassoc (attr := simp)] lemma shiftIso_hom_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) : (shift F a).map (f⟦n⟧') ≫ (shiftIso F n a a' ha').hom.app Y = (shiftIso F n a a' ha').hom.app X ≫ (shift F a').map f := (F.shiftIso n a a' ha').hom.naturality f @[reassoc] lemma shiftIso_inv_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) : (shift F a').map f ≫ (shiftIso F n a a' ha').inv.app Y = (shiftIso F n a a' ha').inv.app X ≫ (shift F a).map (f⟦n⟧') := by simp variable (M) in /-- The canonical isomorphism `F.shift 0 ≅ F`. -/ def isoShiftZero : F.shift (0 : M) ≅ F := ShiftSequence.isoZero /-- The canonical isomorphism `shiftFunctor C n ⋙ F ≅ F.shift n`. -/ def isoShift (n : M) : shiftFunctor C n ⋙ F ≅ F.shift n := isoWhiskerLeft _ (F.isoShiftZero M).symm ≪≫ F.shiftIso _ _ _ (add_zero n) @[reassoc] lemma isoShift_hom_naturality (n : M) {X Y : C} (f : X ⟶ Y) : F.map (f⟦n⟧') ≫ (F.isoShift n).hom.app Y = (F.isoShift n).hom.app X ≫ (F.shift n).map f := (F.isoShift n).hom.naturality f attribute [simp] isoShift_hom_naturality @[reassoc] lemma isoShift_inv_naturality (n : M) {X Y : C} (f : X ⟶ Y) : (F.shift n).map f ≫ (F.isoShift n).inv.app Y = (F.isoShift n).inv.app X ≫ F.map (f⟦n⟧') := (F.isoShift n).inv.naturality f lemma shiftIso_zero (a : M) : F.shiftIso 0 a a (zero_add a) = isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ := ShiftSequence.shiftIso_zero a @[simp] lemma shiftIso_zero_hom_app (a : M) (X : C) : (F.shiftIso 0 a a (zero_add a)).hom.app X = (shift F a).map ((shiftFunctorZero C M).hom.app X) := by simp [F.shiftIso_zero a] @[simp] lemma shiftIso_zero_inv_app (a : M) (X : C) : (F.shiftIso 0 a a (zero_add a)).inv.app X = (shift F a).map ((shiftFunctorZero C M).inv.app X) := by simp [F.shiftIso_zero a] lemma shiftIso_add (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' := ShiftSequence.shiftIso_add _ _ _ _ _ _ _ lemma shiftIso_add_hom_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).hom.app X = (shift F a).map ((shiftFunctorAdd C m n).hom.app X) ≫ (shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫ (shiftIso F m a' a'' ha'').hom.app X := by simp [F.shiftIso_add n m a a' a'' ha' ha''] lemma shiftIso_add_inv_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).inv.app X = (shiftIso F m a' a'' ha'').inv.app X ≫ (shiftIso F n a a' ha').inv.app ((shiftFunctor C m).obj X) ≫ (shift F a).map ((shiftFunctorAdd C m n).inv.app X) := by simp [F.shiftIso_add n m a a' a'' ha' ha''] lemma shiftIso_add' (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc]) = isoWhiskerRight (shiftFunctorAdd' C m n _ hnm) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' := by subst hnm rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftIso_add] lemma shiftIso_add'_hom_app (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X = (shift F a).map ((shiftFunctorAdd' C m n mn hnm).hom.app X) ≫ (shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫ (shiftIso F m a' a'' ha'').hom.app X := by simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha''] lemma shiftIso_add'_inv_app (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).inv.app X = (shiftIso F m a' a'' ha'').inv.app X ≫ (shiftIso F n a a' ha').inv.app ((shiftFunctor C m).obj X) ≫ (shift F a).map ((shiftFunctorAdd' C m n mn hnm).inv.app X) := by simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha''] @[reassoc] lemma shiftIso_hom_app_comp (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫ (shiftIso F m a' a'' ha'').hom.app X = (shift F a).map ((shiftFunctorAdd' C m n mn hnm).inv.app X) ≫ (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X := by rw [F.shiftIso_add'_hom_app n m mn hnm a a' a'' ha' ha'', ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.map_id, id_comp] /-- The morphism `(F.shift a).obj X ⟶ (F.shift a').obj Y` induced by a morphism `f : X ⟶ Y⟦n⟧` when `n + a = a'`. -/ def shiftMap {X Y : C} {n : M} (f : X ⟶ Y⟦n⟧) (a a' : M) (ha' : n + a = a') : (F.shift a).obj X ⟶ (F.shift a').obj Y := (F.shift a).map f ≫ (F.shiftIso _ _ _ ha').hom.app Y @[reassoc] lemma shiftMap_comp {X Y Z : C} {n : M} (f : X ⟶ Y⟦n⟧) (g : Y ⟶ Z) (a a' : M) (ha' : n + a = a') : F.shiftMap (f ≫ g⟦n⟧') a a' ha' = F.shiftMap f a a' ha' ≫ (F.shift a').map g := by simp [shiftMap] @[reassoc] lemma shiftMap_comp' {X Y Z : C} {n : M} (f : X ⟶ Y) (g : Y ⟶ Z⟦n⟧) (a a' : M) (ha' : n + a = a') : F.shiftMap (f ≫ g) a a' ha' = (F.shift a).map f ≫ F.shiftMap g a a' ha' := by simp [shiftMap] /-- When `f : X ⟶ Y⟦m⟧`, `m + n = mn`, `n + a = a'` and `ha'' : m + a' = a''`, this lemma relates the two morphisms `F.shiftMap f a' a'' ha''` and `(F.shift a).map (f⟦n⟧')`. Indeed, via canonical isomorphisms, they both identity to morphisms `(F.shift a').obj X ⟶ (F.shift a'').obj Y`. -/ lemma shiftIso_hom_app_comp_shiftMap {X Y : C} {m : M} (f : X ⟶ Y⟦m⟧) (n mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : (F.shiftIso n a a' ha').hom.app X ≫ F.shiftMap f a' a'' ha'' = (F.shift a).map (f⟦n⟧') ≫ (F.shift a).map ((shiftFunctorAdd' C m n mn hnm).inv.app Y) ≫ (F.shiftIso mn a a'' (by rw [← ha'', ← ha', ← hnm, add_assoc])).hom.app Y := by simp only [F.shiftIso_add'_hom_app n m mn hnm a a' a'' ha' ha'' Y, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.map_id, id_comp, comp_obj, shiftIso_hom_naturality_assoc, shiftMap] /-- If `f : X ⟶ Y⟦m⟧`, `n + m = 0` and `ha' : m + a = a'`, this lemma relates the two morphisms `F.shiftMap f a a' ha'` and `(F.shift a').map (f⟦n⟧')`. Indeed, via canonical isomorphisms, they both identify to morphisms `(F.shift a).obj X ⟶ (F.shift a').obj Y`. -/ lemma shiftIso_hom_app_comp_shiftMap_of_add_eq_zero [F.ShiftSequence G] {X Y : C} {m : G} (f : X ⟶ Y⟦m⟧) (n : G) (hnm : n + m = 0) (a a' : G) (ha' : m + a = a') : (F.shiftIso n a' a (by rw [← ha', ← add_assoc, hnm, zero_add])).hom.app X ≫ F.shiftMap f a a' ha' = (F.shift a').map (f⟦n⟧' ≫ (shiftFunctorCompIsoId C m n (by rw [← add_left_inj m, add_assoc, hnm, zero_add, add_zero])).hom.app Y) := by have hnm' : m + n = 0 := by rw [← add_left_inj m, add_assoc, hnm, zero_add, add_zero] simp [F.shiftIso_hom_app_comp_shiftMap f n 0 hnm' a' a, shiftIso_zero_hom_app, shiftFunctorCompIsoId] section variable [HasZeroMorphisms C] [HasZeroMorphisms A] [F.PreservesZeroMorphisms] [∀ (n : M), (shiftFunctor C n).PreservesZeroMorphisms] instance (n : M) : (F.shift n).PreservesZeroMorphisms := preservesZeroMorphisms_of_iso (F.isoShift n) @[simp] lemma shiftMap_zero (X Y : C) (n a a' : M) (ha' : n + a = a') : F.shiftMap (0 : X ⟶ Y⟦n⟧) a a' ha' = 0 := by simp [shiftMap] end section variable [Preadditive C] [Preadditive A] [F.Additive] [∀ (n : M), (shiftFunctor C n).Additive] instance (n : M) : (F.shift n).Additive := additive_of_iso (F.isoShift n) end end end Functor end CategoryTheory
Action.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.Dynamics.Ergodic.MeasurePreserving import Mathlib.Dynamics.Minimal import Mathlib.GroupTheory.GroupAction.Hom import Mathlib.MeasureTheory.Group.MeasurableEquiv import Mathlib.MeasureTheory.Measure.Regular import Mathlib.MeasureTheory.Group.Defs import Mathlib.Order.Filter.EventuallyConst /-! # Measures invariant under group actions A measure `μ : Measure α` is said to be *invariant* under an action of a group `G` if scalar multiplication by `c : G` is a measure preserving map for all `c`. In this file we define a typeclass for measures invariant under action of an (additive or multiplicative) group and prove some basic properties of such measures. -/ open scoped ENNReal NNReal Pointwise Topology open MeasureTheory.Measure Set Function Filter namespace MeasureTheory universe u v w variable {G : Type u} {M : Type v} {α : Type w} namespace SMulInvariantMeasure @[to_additive] instance zero [MeasurableSpace α] [SMul M α] : SMulInvariantMeasure M α (0 : Measure α) := ⟨fun _ _ _ => rfl⟩ variable [SMul M α] {m : MeasurableSpace α} {μ ν : Measure α} @[to_additive] instance add [SMulInvariantMeasure M α μ] [SMulInvariantMeasure M α ν] : SMulInvariantMeasure M α (μ + ν) := ⟨fun c _s hs => show _ + _ = _ + _ from congr_arg₂ (· + ·) (measure_preimage_smul c hs) (measure_preimage_smul c hs)⟩ @[to_additive] instance smul [SMulInvariantMeasure M α μ] (c : ℝ≥0∞) : SMulInvariantMeasure M α (c • μ) := ⟨fun a _s hs => show c • _ = c • _ from congr_arg (c • ·) (measure_preimage_smul a hs)⟩ @[to_additive] instance smul_nnreal [SMulInvariantMeasure M α μ] (c : ℝ≥0) : SMulInvariantMeasure M α (c • μ) := SMulInvariantMeasure.smul c end SMulInvariantMeasure section AE_smul variable {m : MeasurableSpace α} [SMul G α] (μ : Measure α) [SMulInvariantMeasure G α μ] {s : Set α} /-- See also `measure_preimage_smul_of_nullMeasurableSet` and `measure_preimage_smul`. -/ @[to_additive /-- See also `measure_preimage_smul_of_nullMeasurableSet` and `measure_preimage_smul`. -/] theorem measure_preimage_smul_le (c : G) (s : Set α) : μ ((c • ·) ⁻¹' s) ≤ μ s := (outerMeasure_le_iff (m := .map (c • ·) μ.1)).2 (fun _s hs ↦ (SMulInvariantMeasure.measure_preimage_smul _ hs).le) _ /-- See also `smul_ae`. -/ @[to_additive /-- See also `vadd_ae`. -/] theorem tendsto_smul_ae (c : G) : Filter.Tendsto (c • ·) (ae μ) (ae μ) := fun _s hs ↦ eq_bot_mono (measure_preimage_smul_le μ c _) hs variable {μ} @[to_additive] theorem measure_preimage_smul_null (h : μ s = 0) (c : G) : μ ((c • ·) ⁻¹' s) = 0 := eq_bot_mono (measure_preimage_smul_le μ c _) h @[to_additive] theorem measure_preimage_smul_of_nullMeasurableSet (hs : NullMeasurableSet s μ) (c : G) : μ ((c • ·) ⁻¹' s) = μ s := by rw [← measure_toMeasurable s, ← SMulInvariantMeasure.measure_preimage_smul c (measurableSet_toMeasurable μ s)] exact measure_congr (tendsto_smul_ae μ c hs.toMeasurable_ae_eq) |>.symm end AE_smul section AE variable {m : MeasurableSpace α} [Group G] [MulAction G α] (μ : Measure α) [SMulInvariantMeasure G α μ] @[to_additive (attr := simp)] theorem measure_preimage_smul (c : G) (s : Set α) : μ ((c • ·) ⁻¹' s) = μ s := (measure_preimage_smul_le μ c s).antisymm <| by simpa [preimage_preimage] using measure_preimage_smul_le μ c⁻¹ ((c • ·) ⁻¹' s) @[to_additive (attr := simp)] theorem measure_smul (c : G) (s : Set α) : μ (c • s) = μ s := by simpa only [preimage_smul_inv] using measure_preimage_smul μ c⁻¹ s variable {μ} @[to_additive] theorem measure_smul_eq_zero_iff {s} (c : G) : μ (c • s) = 0 ↔ μ s = 0 := by rw [measure_smul] @[to_additive] theorem measure_smul_null {s} (h : μ s = 0) (c : G) : μ (c • s) = 0 := (measure_smul_eq_zero_iff _).2 h @[to_additive (attr := simp)] theorem smul_mem_ae (c : G) {s : Set α} : c • s ∈ ae μ ↔ s ∈ ae μ := by simp only [mem_ae_iff, ← smul_set_compl, measure_smul_eq_zero_iff] @[to_additive (attr := simp)] theorem smul_ae (c : G) : c • ae μ = ae μ := by ext s simp only [mem_smul_filter, preimage_smul, smul_mem_ae] @[to_additive (attr := simp)] theorem eventuallyConst_smul_set_ae (c : G) {s : Set α} : EventuallyConst (c • s : Set α) (ae μ) ↔ EventuallyConst s (ae μ) := by rw [← preimage_smul_inv, eventuallyConst_preimage, Filter.map_smul, smul_ae] @[to_additive (attr := simp)] theorem smul_set_ae_le (c : G) {s t : Set α} : c • s ≤ᵐ[μ] c • t ↔ s ≤ᵐ[μ] t := by simp only [ae_le_set, ← smul_set_sdiff, measure_smul_eq_zero_iff] @[to_additive (attr := simp)] theorem smul_set_ae_eq (c : G) {s t : Set α} : c • s =ᵐ[μ] c • t ↔ s =ᵐ[μ] t := by simp only [Filter.eventuallyLE_antisymm_iff, smul_set_ae_le] end AE section MeasurableSMul variable {m : MeasurableSpace α} [MeasurableSpace M] [SMul M α] [MeasurableSMul M α] (c : M) (μ : Measure α) [SMulInvariantMeasure M α μ] @[to_additive (attr := simp)] theorem measurePreserving_smul : MeasurePreserving (c • ·) μ μ := { measurable := measurable_const_smul c map_eq := by ext1 s hs rw [map_apply (measurable_const_smul c) hs] exact SMulInvariantMeasure.measure_preimage_smul c hs } @[to_additive (attr := simp)] protected theorem map_smul : map (c • ·) μ = μ := (measurePreserving_smul c μ).map_eq end MeasurableSMul @[to_additive] theorem MeasurePreserving.smulInvariantMeasure_iterateMulAct {f : α → α} {_ : MeasurableSpace α} {μ : Measure α} (hf : MeasurePreserving f μ μ) : SMulInvariantMeasure (IterateMulAct f) α μ := ⟨fun n _s hs ↦ (hf.iterate n.val).measure_preimage hs.nullMeasurableSet⟩ @[to_additive] theorem smulInvariantMeasure_iterateMulAct {f : α → α} {_ : MeasurableSpace α} {μ : Measure α} (hf : Measurable f) : SMulInvariantMeasure (IterateMulAct f) α μ ↔ MeasurePreserving f μ μ := ⟨fun _ ↦ have := hf.measurableSMul₂_iterateMulAct measurePreserving_smul (IterateMulAct.mk (f := f) 1) μ, MeasurePreserving.smulInvariantMeasure_iterateMulAct⟩ section SMulHomClass universe uM uN uα uβ variable {M : Type uM} {N : Type uN} {α : Type uα} {β : Type uβ} [MeasurableSpace M] [MeasurableSpace N] [MeasurableSpace α] [MeasurableSpace β] @[to_additive] theorem smulInvariantMeasure_map [SMul M α] [SMul M β] [MeasurableSMul M β] (μ : Measure α) [SMulInvariantMeasure M α μ] (f : α → β) (hsmul : ∀ (m : M) a, f (m • a) = m • f a) (hf : Measurable f) : SMulInvariantMeasure M β (map f μ) where measure_preimage_smul m S hS := calc map f μ ((m • ·) ⁻¹' S) _ = μ (f ⁻¹' ((m • ·) ⁻¹' S)) := map_apply hf <| hS.preimage (measurable_const_smul _) _ = μ ((m • f ·) ⁻¹' S) := by rw [preimage_preimage] _ = μ ((f <| m • ·) ⁻¹' S) := by simp_rw [hsmul] _ = μ ((m • ·) ⁻¹' (f ⁻¹' S)) := by rw [← preimage_preimage] _ = μ (f ⁻¹' S) := by rw [SMulInvariantMeasure.measure_preimage_smul m (hS.preimage hf)] _ = map f μ S := (map_apply hf hS).symm @[to_additive] instance smulInvariantMeasure_map_smul [SMul M α] [SMul N α] [SMulCommClass N M α] [MeasurableSMul M α] [MeasurableSMul N α] (μ : Measure α) [SMulInvariantMeasure M α μ] (n : N) : SMulInvariantMeasure M α (map (n • ·) μ) := smulInvariantMeasure_map μ _ (smul_comm n) <| measurable_const_smul _ end SMulHomClass variable (G) {m : MeasurableSpace α} [Group G] [MulAction G α] (μ : Measure α) variable [MeasurableSpace G] [MeasurableSMul G α] in /-- Equivalent definitions of a measure invariant under a multiplicative action of a group. - 0: `SMulInvariantMeasure G α μ`; - 1: for every `c : G` and a measurable set `s`, the measure of the preimage of `s` under scalar multiplication by `c` is equal to the measure of `s`; - 2: for every `c : G` and a measurable set `s`, the measure of the image `c • s` of `s` under scalar multiplication by `c` is equal to the measure of `s`; - 3, 4: properties 2, 3 for any set, including non-measurable ones; - 5: for any `c : G`, scalar multiplication by `c` maps `μ` to `μ`; - 6: for any `c : G`, scalar multiplication by `c` is a measure preserving map. -/ @[to_additive] theorem smulInvariantMeasure_tfae : List.TFAE [SMulInvariantMeasure G α μ, ∀ (c : G) (s), MeasurableSet s → μ ((c • ·) ⁻¹' s) = μ s, ∀ (c : G) (s), MeasurableSet s → μ (c • s) = μ s, ∀ (c : G) (s), μ ((c • ·) ⁻¹' s) = μ s, ∀ (c : G) (s), μ (c • s) = μ s, ∀ c : G, Measure.map (c • ·) μ = μ, ∀ c : G, MeasurePreserving (c • ·) μ μ] := by tfae_have 1 ↔ 2 := ⟨fun h => h.1, fun h => ⟨h⟩⟩ tfae_have 1 → 6 := fun h c => (measurePreserving_smul c μ).map_eq tfae_have 6 → 7 := fun H c => ⟨measurable_const_smul c, H c⟩ tfae_have 7 → 4 := fun H c => (H c).measure_preimage_emb (measurableEmbedding_const_smul c) tfae_have 4 → 5 | H, c, s => by rw [← preimage_smul_inv] apply H tfae_have 5 → 3 := fun H c s _ => H c s tfae_have 3 → 2 | H, c, s, hs => by rw [preimage_smul] exact H c⁻¹ s hs tfae_finish /-- Equivalent definitions of a measure invariant under an additive action of a group. - 0: `VAddInvariantMeasure G α μ`; - 1: for every `c : G` and a measurable set `s`, the measure of the preimage of `s` under vector addition `(c +ᵥ ·)` is equal to the measure of `s`; - 2: for every `c : G` and a measurable set `s`, the measure of the image `c +ᵥ s` of `s` under vector addition `(c +ᵥ ·)` is equal to the measure of `s`; - 3, 4: properties 2, 3 for any set, including non-measurable ones; - 5: for any `c : G`, vector addition of `c` maps `μ` to `μ`; - 6: for any `c : G`, vector addition of `c` is a measure preserving map. -/ add_decl_doc vaddInvariantMeasure_tfae variable {G} variable [SMulInvariantMeasure G α μ] variable {μ} variable [MeasurableSpace G] [MeasurableSMul G α] in @[to_additive] theorem NullMeasurableSet.smul {s} (hs : NullMeasurableSet s μ) (c : G) : NullMeasurableSet (c • s) μ := by simpa only [← preimage_smul_inv] using hs.preimage (measurePreserving_smul _ _).quasiMeasurePreserving section IsMinimal variable (G) variable [TopologicalSpace α] [ContinuousConstSMul G α] [MulAction.IsMinimal G α] {K U : Set α} include G in /-- If measure `μ` is invariant under a group action and is nonzero on a compact set `K`, then it is positive on any nonempty open set. In case of a regular measure, one can assume `μ ≠ 0` instead of `μ K ≠ 0`, see `MeasureTheory.measure_isOpen_pos_of_smulInvariant_of_ne_zero`. -/ @[to_additive] theorem measure_isOpen_pos_of_smulInvariant_of_compact_ne_zero (hK : IsCompact K) (hμK : μ K ≠ 0) (hU : IsOpen U) (hne : U.Nonempty) : 0 < μ U := let ⟨t, ht⟩ := hK.exists_finite_cover_smul G hU hne pos_iff_ne_zero.2 fun hμU => hμK <| measure_mono_null ht <| (measure_biUnion_null_iff t.countable_toSet).2 fun _ _ => by rwa [measure_smul] /-- If measure `μ` is invariant under an additive group action and is nonzero on a compact set `K`, then it is positive on any nonempty open set. In case of a regular measure, one can assume `μ ≠ 0` instead of `μ K ≠ 0`, see `MeasureTheory.measure_isOpen_pos_of_vaddInvariant_of_ne_zero`. -/ add_decl_doc measure_isOpen_pos_of_vaddInvariant_of_compact_ne_zero include G @[to_additive] theorem isLocallyFiniteMeasure_of_smulInvariant (hU : IsOpen U) (hne : U.Nonempty) (hμU : μ U ≠ ∞) : IsLocallyFiniteMeasure μ := ⟨fun x => let ⟨g, hg⟩ := hU.exists_smul_mem G x hne ⟨(g • ·) ⁻¹' U, (hU.preimage (continuous_id.const_smul _)).mem_nhds hg, Ne.lt_top <| by rwa [measure_preimage_smul]⟩⟩ variable [Measure.Regular μ] @[to_additive] theorem measure_isOpen_pos_of_smulInvariant_of_ne_zero (hμ : μ ≠ 0) (hU : IsOpen U) (hne : U.Nonempty) : 0 < μ U := let ⟨_K, hK, hμK⟩ := Regular.exists_isCompact_not_null.mpr hμ measure_isOpen_pos_of_smulInvariant_of_compact_ne_zero G hK hμK hU hne @[to_additive] theorem measure_pos_iff_nonempty_of_smulInvariant (hμ : μ ≠ 0) (hU : IsOpen U) : 0 < μ U ↔ U.Nonempty := ⟨fun h => nonempty_of_measure_ne_zero h.ne', measure_isOpen_pos_of_smulInvariant_of_ne_zero G hμ hU⟩ @[to_additive] theorem measure_eq_zero_iff_eq_empty_of_smulInvariant (hμ : μ ≠ 0) (hU : IsOpen U) : μ U = 0 ↔ U = ∅ := by rw [← not_iff_not, ← Ne, ← pos_iff_ne_zero, measure_pos_iff_nonempty_of_smulInvariant G hμ hU, nonempty_iff_ne_empty] end IsMinimal end MeasureTheory
SemistandardTableau.lean
/- Copyright (c) 2022 Jake Levinson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jake Levinson -/ import Mathlib.Combinatorics.Young.YoungDiagram /-! # Semistandard Young tableaux A semistandard Young tableau is a filling of a Young diagram by natural numbers, such that the entries are weakly increasing left-to-right along rows (i.e. for fixed `i`), and strictly-increasing top-to-bottom along columns (i.e. for fixed `j`). An example of an SSYT of shape `μ = [4, 2, 1]` is: ```text 0 0 0 2 1 1 2 ``` We represent a semistandard Young tableau as a function `ℕ → ℕ → ℕ`, which is required to be zero for all pairs `(i, j) ∉ μ` and to satisfy the row-weak and column-strict conditions on `μ`. ## Main definitions - `SemistandardYoungTableau (μ : YoungDiagram)`: semistandard Young tableaux of shape `μ`. There is a `coe` instance such that `T i j` is value of the `(i, j)` entry of the semistandard Young tableau `T`. - `SemistandardYoungTableau.highestWeight (μ : YoungDiagram)`: the semistandard Young tableau whose `i`th row consists entirely of `i`s, for each `i`. ## Tags Semistandard Young tableau ## References <https://en.wikipedia.org/wiki/Young_tableau> -/ /-- A semistandard Young tableau is a filling of the cells of a Young diagram by natural numbers, such that the entries in each row are weakly increasing (left to right), and the entries in each column are strictly increasing (top to bottom). Here, a semistandard Young tableau is represented as an unrestricted function `ℕ → ℕ → ℕ` that, for reasons of extensionality, is required to vanish outside `μ`. -/ structure SemistandardYoungTableau (μ : YoungDiagram) where /-- `entry i j` is value of the `(i, j)` entry of the SSYT `μ`. -/ entry : ℕ → ℕ → ℕ /-- The entries in each row are weakly increasing (left to right). -/ row_weak' : ∀ {i j1 j2 : ℕ}, j1 < j2 → (i, j2) ∈ μ → entry i j1 ≤ entry i j2 /-- The entries in each column are strictly increasing (top to bottom). -/ col_strict' : ∀ {i1 i2 j : ℕ}, i1 < i2 → (i2, j) ∈ μ → entry i1 j < entry i2 j /-- `entry` is required to be zero for all pairs `(i, j) ∉ μ`. -/ zeros' : ∀ {i j}, (i, j) ∉ μ → entry i j = 0 namespace SemistandardYoungTableau instance instFunLike {μ : YoungDiagram} : FunLike (SemistandardYoungTableau μ) ℕ (ℕ → ℕ) where coe := SemistandardYoungTableau.entry coe_injective' T T' h := by cases T cases T' congr @[simp] theorem to_fun_eq_coe {μ : YoungDiagram} {T : SemistandardYoungTableau μ} : T.entry = (T : ℕ → ℕ → ℕ) := rfl @[ext] theorem ext {μ : YoungDiagram} {T T' : SemistandardYoungTableau μ} (h : ∀ i j, T i j = T' i j) : T = T' := DFunLike.ext T T' fun _ ↦ by funext apply h /-- Copy of an `SemistandardYoungTableau μ` with a new `entry` equal to the old one. Useful to fix definitional equalities. -/ protected def copy {μ : YoungDiagram} (T : SemistandardYoungTableau μ) (entry' : ℕ → ℕ → ℕ) (h : entry' = T) : SemistandardYoungTableau μ where entry := entry' row_weak' := h.symm ▸ T.row_weak' col_strict' := h.symm ▸ T.col_strict' zeros' := h.symm ▸ T.zeros' @[simp] theorem coe_copy {μ : YoungDiagram} (T : SemistandardYoungTableau μ) (entry' : ℕ → ℕ → ℕ) (h : entry' = T) : ⇑(T.copy entry' h) = entry' := rfl theorem copy_eq {μ : YoungDiagram} (T : SemistandardYoungTableau μ) (entry' : ℕ → ℕ → ℕ) (h : entry' = T) : T.copy entry' h = T := DFunLike.ext' h theorem row_weak {μ : YoungDiagram} (T : SemistandardYoungTableau μ) {i j1 j2 : ℕ} (hj : j1 < j2) (hcell : (i, j2) ∈ μ) : T i j1 ≤ T i j2 := T.row_weak' hj hcell theorem col_strict {μ : YoungDiagram} (T : SemistandardYoungTableau μ) {i1 i2 j : ℕ} (hi : i1 < i2) (hcell : (i2, j) ∈ μ) : T i1 j < T i2 j := T.col_strict' hi hcell theorem zeros {μ : YoungDiagram} (T : SemistandardYoungTableau μ) {i j : ℕ} (not_cell : (i, j) ∉ μ) : T i j = 0 := T.zeros' not_cell theorem row_weak_of_le {μ : YoungDiagram} (T : SemistandardYoungTableau μ) {i j1 j2 : ℕ} (hj : j1 ≤ j2) (cell : (i, j2) ∈ μ) : T i j1 ≤ T i j2 := by rcases eq_or_lt_of_le hj with h | h · rw [h] · exact T.row_weak h cell theorem col_weak {μ : YoungDiagram} (T : SemistandardYoungTableau μ) {i1 i2 j : ℕ} (hi : i1 ≤ i2) (cell : (i2, j) ∈ μ) : T i1 j ≤ T i2 j := by rcases eq_or_lt_of_le hi with h | h · rw [h] · exact le_of_lt (T.col_strict h cell) /-- The "highest weight" SSYT of a given shape has all i's in row i, for each i. -/ def highestWeight (μ : YoungDiagram) : SemistandardYoungTableau μ where entry i j := if (i, j) ∈ μ then i else 0 row_weak' hj hcell := by rw [if_pos hcell, if_pos (μ.up_left_mem (by rfl) (le_of_lt hj) hcell)] col_strict' hi hcell := by rwa [if_pos hcell, if_pos (μ.up_left_mem (le_of_lt hi) (by rfl) hcell)] zeros' not_cell := if_neg not_cell @[simp] theorem highestWeight_apply {μ : YoungDiagram} {i j : ℕ} : highestWeight μ i j = if (i, j) ∈ μ then i else 0 := rfl instance {μ : YoungDiagram} : Inhabited (SemistandardYoungTableau μ) := ⟨highestWeight μ⟩ end SemistandardYoungTableau
Uniqueness.lean
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.Linear import Mathlib.Analysis.Analytic.Composition import Mathlib.Analysis.Analytic.Constructions import Mathlib.Analysis.Normed.Module.Completion import Mathlib.Analysis.Analytic.ChangeOrigin /-! # Uniqueness principle for analytic functions We show that two analytic functions which coincide around a point coincide on whole connected sets, in `AnalyticOnNhd.eqOn_of_preconnected_of_eventuallyEq`. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] open Set open scoped Topology ENNReal NNReal /-! ### Uniqueness of power series If a function `f : E → F` has two representations as power series at a point `x : E`, corresponding to formal multilinear series `p₁` and `p₂`, then these representations agree term-by-term. That is, for any `n : ℕ` and `y : E`, `p₁ n (fun i ↦ y) = p₂ n (fun i ↦ y)`. In the one-dimensional case, when `f : 𝕜 → E`, the continuous multilinear maps `p₁ n` and `p₂ n` are given by `ContinuousMultilinearMap.mkPiRing`, and hence are determined completely by the value of `p₁ n (fun i ↦ 1)`, so `p₁ = p₂`. Consequently, the radius of convergence for one series can be transferred to the other. -/ section Uniqueness open ContinuousMultilinearMap theorem Asymptotics.IsBigO.continuousMultilinearMap_apply_eq_zero {n : ℕ} {p : E [×n]→L[𝕜] F} (h : (fun y => p fun _ => y) =O[𝓝 0] fun y => ‖y‖ ^ (n + 1)) (y : E) : (p fun _ => y) = 0 := by obtain ⟨c, c_pos, hc⟩ := h.exists_pos obtain ⟨t, ht, t_open, z_mem⟩ := eventually_nhds_iff.mp (isBigOWith_iff.mp hc) obtain ⟨δ, δ_pos, δε⟩ := (Metric.isOpen_iff.mp t_open) 0 z_mem clear h hc z_mem rcases n with - | n · exact norm_eq_zero.mp (by simpa only [fin0_apply_norm, norm_eq_zero, norm_zero, zero_add, pow_one, mul_zero, norm_le_zero_iff] using ht 0 (δε (Metric.mem_ball_self δ_pos))) · refine Or.elim (Classical.em (y = 0)) (fun hy => by simpa only [hy] using p.map_zero) fun hy => ?_ replace hy := norm_pos_iff.mpr hy refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add fun ε ε_pos => ?_) (norm_nonneg _)) have h₀ := _root_.mul_pos c_pos (pow_pos hy (n.succ + 1)) obtain ⟨k, k_pos, k_norm⟩ := NormedField.exists_norm_lt 𝕜 (lt_min (mul_pos δ_pos (inv_pos.mpr hy)) (mul_pos ε_pos (inv_pos.mpr h₀))) have h₁ : ‖k • y‖ < δ := by rw [norm_smul] exact inv_mul_cancel_right₀ hy.ne.symm δ ▸ mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_left _ _)) hy have h₂ := calc ‖p fun _ => k • y‖ ≤ c * ‖k • y‖ ^ (n.succ + 1) := by -- Porting note: now Lean wants `_root_.` simpa only [norm_pow, _root_.norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁)) --simpa only [norm_pow, norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁)) _ = ‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by simp only [norm_smul, mul_pow] ring have h₃ : ‖k‖ * (c * ‖y‖ ^ (n.succ + 1)) < ε := inv_mul_cancel_right₀ h₀.ne.symm ε ▸ mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_right _ _)) h₀ calc ‖p fun _ => y‖ = ‖k⁻¹ ^ n.succ‖ * ‖p fun _ => k • y‖ := by simpa only [inv_smul_smul₀ (norm_pos_iff.mp k_pos), norm_smul, Finset.prod_const, Finset.card_fin] using congr_arg norm (p.map_smul_univ (fun _ : Fin n.succ => k⁻¹) fun _ : Fin n.succ => k • y) _ ≤ ‖k⁻¹ ^ n.succ‖ * (‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))) := by gcongr _ = ‖(k⁻¹ * k) ^ n.succ‖ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by rw [← mul_assoc] simp [norm_mul, mul_pow] _ ≤ 0 + ε := by rw [inv_mul_cancel₀ (norm_pos_iff.mp k_pos)] simpa using h₃.le /-- If a formal multilinear series `p` represents the zero function at `x : E`, then the terms `p n (fun i ↦ y)` appearing in the sum are zero for any `n : ℕ`, `y : E`. -/ theorem HasFPowerSeriesAt.apply_eq_zero {p : FormalMultilinearSeries 𝕜 E F} {x : E} (h : HasFPowerSeriesAt 0 p x) (n : ℕ) : ∀ y : E, (p n fun _ => y) = 0 := by refine Nat.strong_induction_on n fun k hk => ?_ have psum_eq : p.partialSum (k + 1) = fun y => p k fun _ => y := by funext z refine Finset.sum_eq_single _ (fun b hb hnb => ?_) fun hn => ?_ · have := Finset.mem_range_succ_iff.mp hb simp only [hk b (this.lt_of_ne hnb)] · exact False.elim (hn (Finset.mem_range.mpr (lt_add_one k))) replace h := h.isBigO_sub_partialSum_pow k.succ simp only [psum_eq, zero_sub, Pi.zero_apply, Asymptotics.isBigO_neg_left] at h exact h.continuousMultilinearMap_apply_eq_zero /-- A one-dimensional formal multilinear series representing the zero function is zero. -/ theorem HasFPowerSeriesAt.eq_zero {p : FormalMultilinearSeries 𝕜 𝕜 E} {x : 𝕜} (h : HasFPowerSeriesAt 0 p x) : p = 0 := by ext n rw [← mkPiRing_apply_one_eq_self (p n)] simp [h.apply_eq_zero n 1] /-- One-dimensional formal multilinear series representing the same function are equal. -/ theorem HasFPowerSeriesAt.eq_formalMultilinearSeries {p₁ p₂ : FormalMultilinearSeries 𝕜 𝕜 E} {f : 𝕜 → E} {x : 𝕜} (h₁ : HasFPowerSeriesAt f p₁ x) (h₂ : HasFPowerSeriesAt f p₂ x) : p₁ = p₂ := sub_eq_zero.mp (HasFPowerSeriesAt.eq_zero (x := x) (by simpa only [sub_self] using h₁.sub h₂)) theorem HasFPowerSeriesAt.eq_formalMultilinearSeries_of_eventually {p q : FormalMultilinearSeries 𝕜 𝕜 E} {f g : 𝕜 → E} {x : 𝕜} (hp : HasFPowerSeriesAt f p x) (hq : HasFPowerSeriesAt g q x) (heq : ∀ᶠ z in 𝓝 x, f z = g z) : p = q := (hp.congr heq).eq_formalMultilinearSeries hq /-- A one-dimensional formal multilinear series representing a locally zero function is zero. -/ theorem HasFPowerSeriesAt.eq_zero_of_eventually {p : FormalMultilinearSeries 𝕜 𝕜 E} {f : 𝕜 → E} {x : 𝕜} (hp : HasFPowerSeriesAt f p x) (hf : f =ᶠ[𝓝 x] 0) : p = 0 := (hp.congr hf).eq_zero /-- If a function `f : 𝕜 → E` has two power series representations at `x`, then the given radii in which convergence is guaranteed may be interchanged. This can be useful when the formal multilinear series in one representation has a particularly nice form, but the other has a larger radius. -/ theorem HasFPowerSeriesOnBall.exchange_radius {p₁ p₂ : FormalMultilinearSeries 𝕜 𝕜 E} {f : 𝕜 → E} {r₁ r₂ : ℝ≥0∞} {x : 𝕜} (h₁ : HasFPowerSeriesOnBall f p₁ x r₁) (h₂ : HasFPowerSeriesOnBall f p₂ x r₂) : HasFPowerSeriesOnBall f p₁ x r₂ := h₂.hasFPowerSeriesAt.eq_formalMultilinearSeries h₁.hasFPowerSeriesAt ▸ h₂ /-- If a function `f : 𝕜 → E` has power series representation `p` on a ball of some radius and for each positive radius it has some power series representation, then `p` converges to `f` on the whole `𝕜`. -/ theorem HasFPowerSeriesOnBall.r_eq_top_of_exists {f : 𝕜 → E} {r : ℝ≥0∞} {x : 𝕜} {p : FormalMultilinearSeries 𝕜 𝕜 E} (h : HasFPowerSeriesOnBall f p x r) (h' : ∀ (r' : ℝ≥0) (_ : 0 < r'), ∃ p' : FormalMultilinearSeries 𝕜 𝕜 E, HasFPowerSeriesOnBall f p' x r') : HasFPowerSeriesOnBall f p x ∞ := { r_le := ENNReal.le_of_forall_pos_nnreal_lt fun r hr _ => let ⟨_, hp'⟩ := h' r hr (h.exchange_radius hp').r_le r_pos := ENNReal.coe_lt_top hasSum := fun {y} _ => let ⟨r', hr'⟩ := exists_gt ‖y‖₊ let ⟨_, hp'⟩ := h' r' hr'.ne_bot.bot_lt (h.exchange_radius hp').hasSum <| mem_emetric_ball_zero_iff.mpr (ENNReal.coe_lt_coe.2 hr') } end Uniqueness namespace AnalyticOnNhd /-- If an analytic function vanishes around a point, then it is uniformly zero along a connected set. Superseded by `AnalyticOnNhd.eqOn_zero_of_preconnected_of_eventuallyEq_zero` which does not assume completeness of the target space. -/ theorem eqOn_zero_of_preconnected_of_eventuallyEq_zero_aux [CompleteSpace F] {f : E → F} {U : Set E} (hf : AnalyticOnNhd 𝕜 f U) (hU : IsPreconnected U) {z₀ : E} (h₀ : z₀ ∈ U) (hfz₀ : f =ᶠ[𝓝 z₀] 0) : EqOn f 0 U := by /- Let `u` be the set of points around which `f` vanishes. It is clearly open. We have to show that its limit points in `U` still belong to it, from which the inclusion `U ⊆ u` will follow by connectedness. -/ let u := {x | f =ᶠ[𝓝 x] 0} suffices main : closure u ∩ U ⊆ u by have Uu : U ⊆ u := hU.subset_of_closure_inter_subset isOpen_setOf_eventually_nhds ⟨z₀, h₀, hfz₀⟩ main intro z hz simpa using mem_of_mem_nhds (Uu hz) /- Take a limit point `x`, then a ball `B (x, r)` on which it has a power series expansion, and then `y ∈ B (x, r/2) ∩ u`. Then `f` has a power series expansion on `B (y, r/2)` as it is contained in `B (x, r)`. All the coefficients in this series expansion vanish, as `f` is zero on a neighborhood of `y`. Therefore, `f` is zero on `B (y, r/2)`. As this ball contains `x`, it follows that `f` vanishes on a neighborhood of `x`, proving the claim. -/ rintro x ⟨xu, xU⟩ rcases hf x xU with ⟨p, r, hp⟩ obtain ⟨y, yu, hxy⟩ : ∃ y ∈ u, edist x y < r / 2 := EMetric.mem_closure_iff.1 xu (r / 2) (ENNReal.half_pos hp.r_pos.ne') let q := p.changeOrigin (y - x) have has_series : HasFPowerSeriesOnBall f q y (r / 2) := by have A : (‖y - x‖₊ : ℝ≥0∞) < r / 2 := by rwa [edist_comm, edist_eq_enorm_sub] at hxy have := hp.changeOrigin (A.trans_le ENNReal.half_le_self) simp only [add_sub_cancel] at this apply this.mono (ENNReal.half_pos hp.r_pos.ne') apply ENNReal.le_sub_of_add_le_left ENNReal.coe_ne_top apply (add_le_add A.le (le_refl (r / 2))).trans (le_of_eq _) exact ENNReal.add_halves _ have M : EMetric.ball y (r / 2) ∈ 𝓝 x := EMetric.isOpen_ball.mem_nhds hxy filter_upwards [M] with z hz have A : HasSum (fun n : ℕ => q n fun _ : Fin n => z - y) (f z) := has_series.hasSum_sub hz have B : HasSum (fun n : ℕ => q n fun _ : Fin n => z - y) 0 := by have : HasFPowerSeriesAt 0 q y := has_series.hasFPowerSeriesAt.congr yu convert hasSum_zero (α := F) using 2 ext n exact this.apply_eq_zero n _ exact HasSum.unique A B /-- The *identity principle* for analytic functions: If an analytic function vanishes in a whole neighborhood of a point `z₀`, then it is uniformly zero along a connected set. For a one-dimensional version assuming only that the function vanishes at some points arbitrarily close to `z₀`, see `AnalyticOnNhd.eqOn_zero_of_preconnected_of_frequently_eq_zero`. -/ theorem eqOn_zero_of_preconnected_of_eventuallyEq_zero {f : E → F} {U : Set E} (hf : AnalyticOnNhd 𝕜 f U) (hU : IsPreconnected U) {z₀ : E} (h₀ : z₀ ∈ U) (hfz₀ : f =ᶠ[𝓝 z₀] 0) : EqOn f 0 U := by let F' := UniformSpace.Completion F set e : F →L[𝕜] F' := UniformSpace.Completion.toComplL have : AnalyticOnNhd 𝕜 (e ∘ f) U := fun x hx => (e.analyticAt _).comp (hf x hx) have A : EqOn (e ∘ f) 0 U := by apply eqOn_zero_of_preconnected_of_eventuallyEq_zero_aux this hU h₀ filter_upwards [hfz₀] with x hx simp only [hx, Function.comp_apply, Pi.zero_apply, map_zero] intro z hz have : e (f z) = e 0 := by simpa only using A hz exact UniformSpace.Completion.coe_injective F this /-- The *identity principle* for analytic functions: If two analytic functions coincide in a whole neighborhood of a point `z₀`, then they coincide globally along a connected set. For a one-dimensional version assuming only that the functions coincide at some points arbitrarily close to `z₀`, see `AnalyticOnNhd.eqOn_of_preconnected_of_frequently_eq`. -/ theorem eqOn_of_preconnected_of_eventuallyEq {f g : E → F} {U : Set E} (hf : AnalyticOnNhd 𝕜 f U) (hg : AnalyticOnNhd 𝕜 g U) (hU : IsPreconnected U) {z₀ : E} (h₀ : z₀ ∈ U) (hfg : f =ᶠ[𝓝 z₀] g) : EqOn f g U := by have hfg' : f - g =ᶠ[𝓝 z₀] 0 := hfg.mono fun z h => by simp [h] simpa [sub_eq_zero] using fun z hz => (hf.sub hg).eqOn_zero_of_preconnected_of_eventuallyEq_zero hU h₀ hfg' hz /-- The *identity principle* for analytic functions: If two analytic functions on a normed space coincide in a neighborhood of a point `z₀`, then they coincide everywhere. For a one-dimensional version assuming only that the functions coincide at some points arbitrarily close to `z₀`, see `AnalyticOnNhd.eq_of_frequently_eq`. -/ theorem eq_of_eventuallyEq {f g : E → F} [PreconnectedSpace E] (hf : AnalyticOnNhd 𝕜 f univ) (hg : AnalyticOnNhd 𝕜 g univ) {z₀ : E} (hfg : f =ᶠ[𝓝 z₀] g) : f = g := funext fun x => eqOn_of_preconnected_of_eventuallyEq hf hg isPreconnected_univ (mem_univ z₀) hfg (mem_univ x) end AnalyticOnNhd
Banach.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Baire.Lemmas import Mathlib.Topology.Baire.CompleteMetrizable import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Analysis.Normed.Affine.Isometry import Mathlib.Analysis.Normed.Group.InfiniteSum /-! # Banach open mapping theorem This file contains the Banach open mapping theorem, i.e., the fact that a bijective bounded linear map between Banach spaces has a bounded inverse. -/ open Function Metric Set Filter Finset Topology NNReal open LinearMap (range ker) variable {𝕜 𝕜' : Type*} [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜'] {σ : 𝕜 →+* 𝕜'} variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜' F] (f : E →SL[σ] F) namespace ContinuousLinearMap /-- A (possibly nonlinear) right inverse to a continuous linear map, which doesn't have to be linear itself but which satisfies a bound `‖inverse x‖ ≤ C * ‖x‖`. A surjective continuous linear map doesn't always have a continuous linear right inverse, but it always has a nonlinear inverse in this sense, by Banach's open mapping theorem. -/ structure NonlinearRightInverse where /-- The underlying function. Do NOT use directly. Use the coercion instead. -/ toFun : F → E /-- The bound `C` so that `‖inverse x‖ ≤ C * ‖x‖` for all `x`. -/ nnnorm : ℝ≥0 bound' : ∀ y, ‖toFun y‖ ≤ nnnorm * ‖y‖ right_inv' : ∀ y, f (toFun y) = y instance : CoeFun (NonlinearRightInverse f) fun _ => F → E := ⟨fun fsymm => fsymm.toFun⟩ @[simp] theorem NonlinearRightInverse.right_inv {f : E →SL[σ] F} (fsymm : NonlinearRightInverse f) (y : F) : f (fsymm y) = y := fsymm.right_inv' y theorem NonlinearRightInverse.bound {f : E →SL[σ] F} (fsymm : NonlinearRightInverse f) (y : F) : ‖fsymm y‖ ≤ fsymm.nnnorm * ‖y‖ := fsymm.bound' y end ContinuousLinearMap variable {σ' : 𝕜' →+* 𝕜} [RingHomInvPair σ σ'] [RingHomIsometric σ] [RingHomIsometric σ'] /-- Given a continuous linear equivalence, the inverse is in particular an instance of `ContinuousLinearMap.NonlinearRightInverse` (which turns out to be linear). -/ noncomputable def ContinuousLinearEquiv.toNonlinearRightInverse [RingHomInvPair σ' σ] (f : E ≃SL[σ] F) : ContinuousLinearMap.NonlinearRightInverse (f : E →SL[σ] F) where toFun := f.invFun nnnorm := ‖(f.symm : F →SL[σ'] E)‖₊ bound' _ := ContinuousLinearMap.le_opNorm (f.symm : F →SL[σ'] E) _ right_inv' := f.apply_symm_apply noncomputable instance [RingHomInvPair σ' σ] (f : E ≃SL[σ] F) : Inhabited (ContinuousLinearMap.NonlinearRightInverse (f : E →SL[σ] F)) := ⟨f.toNonlinearRightInverse⟩ /-! ### Proof of the Banach open mapping theorem -/ variable [CompleteSpace F] namespace ContinuousLinearMap include σ' in /-- First step of the proof of the Banach open mapping theorem (using completeness of `F`): by Baire's theorem, there exists a ball in `E` whose image closure has nonempty interior. Rescaling everything, it follows that any `y ∈ F` is arbitrarily well approached by images of elements of norm at most `C * ‖y‖`. For further use, we will only need such an element whose image is within distance `‖y‖/2` of `y`, to apply an iterative process. -/ theorem exists_approx_preimage_norm_le (surj : Surjective f) : ∃ C ≥ 0, ∀ y, ∃ x, dist (f x) y ≤ 1 / 2 * ‖y‖ ∧ ‖x‖ ≤ C * ‖y‖ := by have A : ⋃ n : ℕ, closure (f '' ball 0 n) = Set.univ := by refine Subset.antisymm (subset_univ _) fun y _ => ?_ rcases surj y with ⟨x, hx⟩ rcases exists_nat_gt ‖x‖ with ⟨n, hn⟩ refine mem_iUnion.2 ⟨n, subset_closure ?_⟩ refine (mem_image _ _ _).2 ⟨x, ⟨?_, hx⟩⟩ rwa [mem_ball, dist_eq_norm, sub_zero] have : ∃ (n : ℕ) (x : _), x ∈ interior (closure (f '' ball 0 n)) := nonempty_interior_of_iUnion_of_closed (fun n => isClosed_closure) A simp only [mem_interior_iff_mem_nhds, Metric.mem_nhds_iff] at this rcases this with ⟨n, a, ε, ⟨εpos, H⟩⟩ rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ refine ⟨(ε / 2)⁻¹ * ‖c‖ * 2 * n, by positivity, fun y => ?_⟩ rcases eq_or_ne y 0 with rfl | hy · use 0 simp · have hc' : 1 < ‖σ c‖ := by simp only [RingHomIsometric.norm_map, hc] rcases rescale_to_shell hc' (half_pos εpos) hy with ⟨d, hd, ydlt, -, dinv⟩ let δ := ‖d‖ * ‖y‖ / 4 have δpos : 0 < δ := by positivity have : a + d • y ∈ ball a ε := by simp [dist_eq_norm, lt_of_le_of_lt ydlt.le (half_lt_self εpos)] rcases Metric.mem_closure_iff.1 (H this) _ δpos with ⟨z₁, z₁im, h₁⟩ rcases (mem_image _ _ _).1 z₁im with ⟨x₁, hx₁, xz₁⟩ rw [← xz₁] at h₁ rw [mem_ball, dist_eq_norm, sub_zero] at hx₁ have : a ∈ ball a ε := by simp only [mem_ball, dist_self] exact εpos rcases Metric.mem_closure_iff.1 (H this) _ δpos with ⟨z₂, z₂im, h₂⟩ rcases (mem_image _ _ _).1 z₂im with ⟨x₂, hx₂, xz₂⟩ rw [← xz₂] at h₂ rw [mem_ball, dist_eq_norm, sub_zero] at hx₂ let x := x₁ - x₂ have I : ‖f x - d • y‖ ≤ 2 * δ := calc ‖f x - d • y‖ = ‖f x₁ - (a + d • y) - (f x₂ - a)‖ := by congr 1 simp only [x, f.map_sub] abel _ ≤ ‖f x₁ - (a + d • y)‖ + ‖f x₂ - a‖ := norm_sub_le _ _ _ ≤ δ + δ := by rw [dist_eq_norm'] at h₁ h₂; gcongr _ = 2 * δ := (two_mul _).symm have J : ‖f (σ' d⁻¹ • x) - y‖ ≤ 1 / 2 * ‖y‖ := calc ‖f (σ' d⁻¹ • x) - y‖ = ‖d⁻¹ • f x - (d⁻¹ * d) • y‖ := by rwa [f.map_smulₛₗ _, inv_mul_cancel₀, one_smul, map_inv₀, map_inv₀, RingHomCompTriple.comp_apply, RingHom.id_apply] _ = ‖d⁻¹ • (f x - d • y)‖ := by rw [mul_smul, smul_sub] _ = ‖d‖⁻¹ * ‖f x - d • y‖ := by rw [norm_smul, norm_inv] _ ≤ ‖d‖⁻¹ * (2 * δ) := by gcongr _ = ‖d‖⁻¹ * ‖d‖ * ‖y‖ / 2 := by simp only [δ] ring _ = ‖y‖ / 2 := by rw [inv_mul_cancel₀, one_mul] simp [norm_eq_zero, hd] _ = 1 / 2 * ‖y‖ := by ring rw [← dist_eq_norm] at J have K : ‖σ' d⁻¹ • x‖ ≤ (ε / 2)⁻¹ * ‖c‖ * 2 * ↑n * ‖y‖ := calc ‖σ' d⁻¹ • x‖ = ‖d‖⁻¹ * ‖x₁ - x₂‖ := by rw [norm_smul, RingHomIsometric.norm_map, norm_inv] _ ≤ (ε / 2)⁻¹ * ‖c‖ * ‖y‖ * (n + n) := by gcongr · simpa using dinv · exact le_trans (norm_sub_le _ _) (by gcongr) _ = (ε / 2)⁻¹ * ‖c‖ * 2 * ↑n * ‖y‖ := by ring exact ⟨σ' d⁻¹ • x, J, K⟩ variable [CompleteSpace E] section include σ' /-- The Banach open mapping theorem: if a bounded linear map between Banach spaces is onto, then any point has a preimage with controlled norm. -/ theorem exists_preimage_norm_le (surj : Surjective f) : ∃ C > 0, ∀ y, ∃ x, f x = y ∧ ‖x‖ ≤ C * ‖y‖ := by obtain ⟨C, C0, hC⟩ := exists_approx_preimage_norm_le f surj /- Second step of the proof: starting from `y`, we want an exact preimage of `y`. Let `g y` be the approximate preimage of `y` given by the first step, and `h y = y - f(g y)` the part that has no preimage yet. We will iterate this process, taking the approximate preimage of `h y`, leaving only `h^2 y` without preimage yet, and so on. Let `u n` be the approximate preimage of `h^n y`. Then `u` is a converging series, and by design the sum of the series is a preimage of `y`. This uses completeness of `E`. -/ choose g hg using hC let h y := y - f (g y) have hle : ∀ y, ‖h y‖ ≤ 1 / 2 * ‖y‖ := by intro y rw [← dist_eq_norm, dist_comm] exact (hg y).1 refine ⟨2 * C + 1, by linarith, fun y => ?_⟩ have hnle : ∀ n : ℕ, ‖h^[n] y‖ ≤ (1 / 2) ^ n * ‖y‖ := by intro n induction n with | zero => simp only [one_div, one_mul, iterate_zero_apply, pow_zero, le_rfl] | succ n IH => rw [iterate_succ'] apply le_trans (hle _) _ rw [pow_succ', mul_assoc] gcongr let u n := g (h^[n] y) have ule : ∀ n, ‖u n‖ ≤ (1 / 2) ^ n * (C * ‖y‖) := fun n ↦ by apply le_trans (hg _).2 calc C * ‖h^[n] y‖ ≤ C * ((1 / 2) ^ n * ‖y‖) := mul_le_mul_of_nonneg_left (hnle n) C0 _ = (1 / 2) ^ n * (C * ‖y‖) := by ring have sNu : Summable fun n => ‖u n‖ := by refine .of_nonneg_of_le (fun n => norm_nonneg _) ule ?_ exact Summable.mul_right _ (summable_geometric_of_lt_one (by simp) (by norm_num)) have su : Summable u := sNu.of_norm let x := tsum u have x_ineq : ‖x‖ ≤ (2 * C + 1) * ‖y‖ := calc ‖x‖ ≤ ∑' n, ‖u n‖ := norm_tsum_le_tsum_norm sNu _ ≤ ∑' n, (1 / 2) ^ n * (C * ‖y‖) := sNu.tsum_le_tsum ule <| Summable.mul_right _ summable_geometric_two _ = (∑' n, (1 / 2) ^ n) * (C * ‖y‖) := tsum_mul_right _ = 2 * C * ‖y‖ := by rw [tsum_geometric_two, mul_assoc] _ ≤ 2 * C * ‖y‖ + ‖y‖ := le_add_of_nonneg_right (norm_nonneg y) _ = (2 * C + 1) * ‖y‖ := by ring have fsumeq : ∀ n : ℕ, f (∑ i ∈ Finset.range n, u i) = y - h^[n] y := by intro n induction n with | zero => simp [f.map_zero] | succ n IH => rw [sum_range_succ, f.map_add, IH, iterate_succ_apply', sub_add] have : Tendsto (fun n => ∑ i ∈ Finset.range n, u i) atTop (𝓝 x) := su.hasSum.tendsto_sum_nat have L₁ : Tendsto (fun n => f (∑ i ∈ Finset.range n, u i)) atTop (𝓝 (f x)) := (f.continuous.tendsto _).comp this simp only [fsumeq] at L₁ have L₂ : Tendsto (fun n => y - h^[n] y) atTop (𝓝 (y - 0)) := by refine tendsto_const_nhds.sub ?_ rw [tendsto_iff_norm_sub_tendsto_zero] simp only [sub_zero] refine squeeze_zero (fun _ => norm_nonneg _) hnle ?_ rw [← zero_mul ‖y‖] refine (_root_.tendsto_pow_atTop_nhds_zero_of_lt_one ?_ ?_).mul tendsto_const_nhds <;> norm_num have feq : f x = y - 0 := tendsto_nhds_unique L₁ L₂ rw [sub_zero] at feq exact ⟨x, feq, x_ineq⟩ /-- The Banach open mapping theorem: a surjective bounded linear map between Banach spaces is open. -/ protected theorem isOpenMap (surj : Surjective f) : IsOpenMap f := by intro s hs rcases exists_preimage_norm_le f surj with ⟨C, Cpos, hC⟩ refine isOpen_iff.2 fun y yfs => ?_ rcases yfs with ⟨x, xs, fxy⟩ rcases isOpen_iff.1 hs x xs with ⟨ε, εpos, hε⟩ refine ⟨ε / C, div_pos εpos Cpos, fun z hz => ?_⟩ rcases hC (z - y) with ⟨w, wim, wnorm⟩ have : f (x + w) = z := by rw [f.map_add, wim, fxy, add_sub_cancel] rw [← this] have : x + w ∈ ball x ε := calc dist (x + w) x = ‖w‖ := by rw [dist_eq_norm] simp _ ≤ C * ‖z - y‖ := wnorm _ < C * (ε / C) := by apply mul_lt_mul_of_pos_left _ Cpos rwa [mem_ball, dist_eq_norm] at hz _ = ε := mul_div_cancel₀ _ (ne_of_gt Cpos) exact Set.mem_image_of_mem _ (hε this) theorem isQuotientMap (surj : Surjective f) : IsQuotientMap f := (f.isOpenMap surj).isQuotientMap f.continuous surj end theorem _root_.AffineMap.isOpenMap {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] {P Q : Type*} [MetricSpace P] [NormedAddTorsor E P] [MetricSpace Q] [NormedAddTorsor F Q] (f : P →ᵃ[𝕜] Q) (hf : Continuous f) (surj : Surjective f) : IsOpenMap f := AffineMap.isOpenMap_linear_iff.mp <| ContinuousLinearMap.isOpenMap { f.linear with cont := AffineMap.continuous_linear_iff.mpr hf } (f.linear_surjective_iff.mpr surj) /-! ### Applications of the Banach open mapping theorem -/ section include σ' theorem interior_preimage (hsurj : Surjective f) (s : Set F) : interior (f ⁻¹' s) = f ⁻¹' interior s := ((f.isOpenMap hsurj).preimage_interior_eq_interior_preimage f.continuous s).symm theorem closure_preimage (hsurj : Surjective f) (s : Set F) : closure (f ⁻¹' s) = f ⁻¹' closure s := ((f.isOpenMap hsurj).preimage_closure_eq_closure_preimage f.continuous s).symm theorem frontier_preimage (hsurj : Surjective f) (s : Set F) : frontier (f ⁻¹' s) = f ⁻¹' frontier s := ((f.isOpenMap hsurj).preimage_frontier_eq_frontier_preimage f.continuous s).symm theorem exists_nonlinearRightInverse_of_surjective (f : E →SL[σ] F) (hsurj : LinearMap.range f = ⊤) : ∃ fsymm : NonlinearRightInverse f, 0 < fsymm.nnnorm := by choose C hC fsymm h using exists_preimage_norm_le _ (LinearMap.range_eq_top.1 hsurj) use { toFun := fsymm nnnorm := ⟨C, hC.lt.le⟩ bound' := fun y => (h y).2 right_inv' := fun y => (h y).1 } exact hC end /-- A surjective continuous linear map between Banach spaces admits a (possibly nonlinear) controlled right inverse. In general, it is not possible to ensure that such a right inverse is linear (take for instance the map from `E` to `E/F` where `F` is a closed subspace of `E` without a closed complement. Then it doesn't have a continuous linear right inverse.) -/ noncomputable irreducible_def nonlinearRightInverseOfSurjective (f : E →SL[σ] F) (hsurj : LinearMap.range f = ⊤) : NonlinearRightInverse f := Classical.choose (exists_nonlinearRightInverse_of_surjective f hsurj) theorem nonlinearRightInverseOfSurjective_nnnorm_pos (f : E →SL[σ] F) (hsurj : LinearMap.range f = ⊤) : 0 < (nonlinearRightInverseOfSurjective f hsurj).nnnorm := by rw [nonlinearRightInverseOfSurjective] exact Classical.choose_spec (exists_nonlinearRightInverse_of_surjective f hsurj) end ContinuousLinearMap namespace LinearEquiv variable [CompleteSpace E] [RingHomInvPair σ' σ] /-- If a bounded linear map is a bijection, then its inverse is also a bounded linear map. -/ @[continuity] theorem continuous_symm (e : E ≃ₛₗ[σ] F) (h : Continuous e) : Continuous e.symm := by rw [continuous_def] intro s hs rw [← e.image_eq_preimage] rw [← e.coe_coe] at h ⊢ exact ContinuousLinearMap.isOpenMap (σ := σ) ⟨_, h⟩ e.surjective s hs /-- Associating to a linear equivalence between Banach spaces a continuous linear equivalence when the direct map is continuous, thanks to the Banach open mapping theorem that ensures that the inverse map is also continuous. -/ def toContinuousLinearEquivOfContinuous (e : E ≃ₛₗ[σ] F) (h : Continuous e) : E ≃SL[σ] F := { e with continuous_toFun := h continuous_invFun := e.continuous_symm h } @[simp] theorem coeFn_toContinuousLinearEquivOfContinuous (e : E ≃ₛₗ[σ] F) (h : Continuous e) : ⇑(e.toContinuousLinearEquivOfContinuous h) = e := rfl @[simp] theorem coeFn_toContinuousLinearEquivOfContinuous_symm (e : E ≃ₛₗ[σ] F) (h : Continuous e) : ⇑(e.toContinuousLinearEquivOfContinuous h).symm = e.symm := rfl end LinearEquiv namespace ContinuousLinearMap variable [CompleteSpace E] [RingHomInvPair σ' σ] {f : E →SL[σ] F} /-- An injective continuous linear map with a closed range defines a continuous linear equivalence between its domain and its range. -/ noncomputable def equivRange (hinj : Injective f) (hclo : IsClosed (range f)) : E ≃SL[σ] LinearMap.range f := have : CompleteSpace (LinearMap.range f) := hclo.completeSpace_coe LinearEquiv.toContinuousLinearEquivOfContinuous (LinearEquiv.ofInjective f.toLinearMap hinj) <| (f.continuous.codRestrict fun x ↦ LinearMap.mem_range_self f x).congr fun _ ↦ rfl @[simp] theorem coe_linearMap_equivRange (hinj : Injective f) (hclo : IsClosed (range f)) : f.equivRange hinj hclo = f.rangeRestrict := rfl @[simp] theorem coe_equivRange (hinj : Injective f) (hclo : IsClosed (range f)) : (f.equivRange hinj hclo : E → LinearMap.range f) = f.rangeRestrict := rfl @[simp] lemma equivRange_symm_toLinearEquiv (hinj : Injective f) (hclo : IsClosed (range f)) : (f.equivRange hinj hclo).toLinearEquiv.symm = (LinearEquiv.ofInjective f.toLinearMap hinj).symm := rfl @[simp] lemma equivRange_symm_apply (hinj : Injective f) (hclo : IsClosed (range f)) (x : E) : (f.equivRange hinj hclo).symm ⟨f x, by simp⟩ = x := by suffices f ((f.equivRange hinj hclo).symm ⟨f x, by simp⟩) = f x from hinj this trans f ((f.equivRange hinj hclo).symm.toLinearEquiv ⟨f x, by simp⟩) · rfl -- is there an API lemma for this already? simp only [ContinuousLinearEquiv.toLinearEquiv_symm, equivRange_symm_toLinearEquiv] set x' : LinearMap.range f := ⟨f x, by simp⟩ set f' : E →ₛₗ[σ] F := ↑f change f' ((LinearEquiv.ofInjective f' hinj).symm x') = _ rw [LinearEquiv.ofInjective_symm_apply (f := f') (h := hinj) x'] section variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace E] [CompleteSpace F] -- TODO: once mathlib has Fredholm operators, generalise the next two lemmas accordingly /-- If `f : E →L[𝕜] F` is injective with closed range (and `E` and `F` are Banach spaces), `f` is anti-Lipschitz. -/ lemma antilipschitz_of_injective_of_isClosed_range (f : E →L[𝕜] F) (hf : Injective f) (hf' : IsClosed (Set.range f)) : ∃ K, AntilipschitzWith K f := by let S : (LinearMap.range f) →L[𝕜] E := (f.equivRange hf hf').symm use ⟨S.opNorm, S.opNorm_nonneg⟩ apply ContinuousLinearMap.antilipschitz_of_bound intro x calc ‖x‖ _ = ‖S ⟨f x, by simp⟩‖ := by simp [S] _ ≤ S.opNorm * ‖f x‖ := le_opNorm S ⟨f x, by simp⟩ /-- An injective bounded linear operator between Banach spaces has closed range iff it is anti-Lipschitz. -/ lemma isClosed_range_iff_antilipschitz_of_injective (f : E →L[𝕜] F) (hf : Injective f) : IsClosed (Set.range f) ↔ ∃ K, AntilipschitzWith K f := by refine ⟨fun h ↦ f.antilipschitz_of_injective_of_isClosed_range hf h, fun h ↦ ?_⟩ choose K hf' using h exact hf'.isClosed_range f.uniformContinuous end end ContinuousLinearMap namespace ContinuousLinearEquiv variable [CompleteSpace E] [RingHomInvPair σ' σ] /-- Convert a bijective continuous linear map `f : E →SL[σ] F` from a Banach space to a normed space to a continuous linear equivalence. -/ noncomputable def ofBijective (f : E →SL[σ] F) (hinj : ker f = ⊥) (hsurj : LinearMap.range f = ⊤) : E ≃SL[σ] F := (LinearEquiv.ofBijective f ⟨LinearMap.ker_eq_bot.mp hinj, LinearMap.range_eq_top.mp hsurj⟩).toContinuousLinearEquivOfContinuous -- Porting note: `by exact` was not previously needed. Why is it needed now? (by exact f.continuous) @[simp] theorem coeFn_ofBijective (f : E →SL[σ] F) (hinj : ker f = ⊥) (hsurj : LinearMap.range f = ⊤) : ⇑(ofBijective f hinj hsurj) = f := rfl theorem coe_ofBijective (f : E →SL[σ] F) (hinj : ker f = ⊥) (hsurj : LinearMap.range f = ⊤) : ↑(ofBijective f hinj hsurj) = f := by ext rfl @[simp] theorem ofBijective_symm_apply_apply (f : E →SL[σ] F) (hinj : ker f = ⊥) (hsurj : LinearMap.range f = ⊤) (x : E) : (ofBijective f hinj hsurj).symm (f x) = x := (ofBijective f hinj hsurj).symm_apply_apply x @[simp] theorem ofBijective_apply_symm_apply (f : E →SL[σ] F) (hinj : ker f = ⊥) (hsurj : LinearMap.range f = ⊤) (y : F) : f ((ofBijective f hinj hsurj).symm y) = y := (ofBijective f hinj hsurj).apply_symm_apply y lemma _root_.ContinuousLinearMap.isUnit_iff_bijective {f : E →L[𝕜] E} : IsUnit f ↔ Bijective f := by constructor · rintro ⟨f, rfl⟩ exact ofUnit f |>.bijective · refine fun h ↦ ⟨toUnit <| .ofBijective f ?_ ?_, rfl⟩ <;> simp only [LinearMap.range_eq_top, LinearMapClass.ker_eq_bot, h.1, h.2] end ContinuousLinearEquiv namespace ContinuousLinearMap variable [CompleteSpace E] /-- Intermediate definition used to show `ContinuousLinearMap.closed_complemented_range_of_isCompl_of_ker_eq_bot`. This is `f.coprod G.subtypeL` as a `ContinuousLinearEquiv`. -/ noncomputable def coprodSubtypeLEquivOfIsCompl {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] (f : E →L[𝕜] F) {G : Submodule 𝕜 F} (h : IsCompl (LinearMap.range f) G) [CompleteSpace G] (hker : ker f = ⊥) : (E × G) ≃L[𝕜] F := ContinuousLinearEquiv.ofBijective (f.coprod G.subtypeL) (by rw [ker_coprod_of_disjoint_range] · rw [hker, Submodule.ker_subtypeL, Submodule.prod_bot] · rw [Submodule.range_subtypeL] exact h.disjoint) (by simp only [range_coprod, Submodule.range_subtypeL, h.sup_eq_top]) theorem range_eq_map_coprodSubtypeLEquivOfIsCompl {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] (f : E →L[𝕜] F) {G : Submodule 𝕜 F} (h : IsCompl (LinearMap.range f) G) [CompleteSpace G] (hker : ker f = ⊥) : LinearMap.range f = ((⊤ : Submodule 𝕜 E).prod (⊥ : Submodule 𝕜 G)).map (f.coprodSubtypeLEquivOfIsCompl h hker : E × G →ₗ[𝕜] F) := by rw [coprodSubtypeLEquivOfIsCompl, ContinuousLinearEquiv.coe_ofBijective, coe_coprod, LinearMap.coprod_map_prod, Submodule.map_bot, sup_bot_eq, Submodule.map_top] rfl /- TODO: remove the assumption `f.ker = ⊥` in the next lemma, by using the map induced by `f` on `E / f.ker`, once we have quotient normed spaces. -/ theorem closed_complemented_range_of_isCompl_of_ker_eq_bot {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] (f : E →L[𝕜] F) (G : Submodule 𝕜 F) (h : IsCompl (LinearMap.range f) G) (hG : IsClosed (G : Set F)) (hker : ker f = ⊥) : IsClosed (LinearMap.range f : Set F) := by haveI : CompleteSpace G := hG.completeSpace_coe let g := coprodSubtypeLEquivOfIsCompl f h hker -- Porting note: was `rw [congr_arg coe ...]` rw [range_eq_map_coprodSubtypeLEquivOfIsCompl f h hker] apply g.toHomeomorph.isClosed_image.2 exact isClosed_univ.prod isClosed_singleton end ContinuousLinearMap section ClosedGraphThm variable [CompleteSpace E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] (g : E →ₗ[𝕜] F) /-- The **closed graph theorem** : a linear map between two Banach spaces whose graph is closed is continuous. -/ theorem LinearMap.continuous_of_isClosed_graph (hg : IsClosed (g.graph : Set <| E × F)) : Continuous g := by letI : CompleteSpace g.graph := completeSpace_coe_iff_isComplete.mpr hg.isComplete let φ₀ : E →ₗ[𝕜] E × F := LinearMap.id.prod g have : Function.LeftInverse Prod.fst φ₀ := fun x => rfl let φ : E ≃ₗ[𝕜] g.graph := (LinearEquiv.ofLeftInverse this).trans (LinearEquiv.ofEq _ _ g.graph_eq_range_prod.symm) let ψ : g.graph ≃L[𝕜] E := φ.symm.toContinuousLinearEquivOfContinuous continuous_subtype_val.fst exact (continuous_subtype_val.comp ψ.symm.continuous).snd /-- A useful form of the **closed graph theorem** : let `f` be a linear map between two Banach spaces. To show that `f` is continuous, it suffices to show that for any convergent sequence `uₙ ⟶ x`, if `f(uₙ) ⟶ y` then `y = f(x)`. -/ theorem LinearMap.continuous_of_seq_closed_graph (hg : ∀ (u : ℕ → E) (x y), Tendsto u atTop (𝓝 x) → Tendsto (g ∘ u) atTop (𝓝 y) → y = g x) : Continuous g := by refine g.continuous_of_isClosed_graph (IsSeqClosed.isClosed ?_) rintro φ ⟨x, y⟩ hφg hφ refine hg (Prod.fst ∘ φ) x y ((continuous_fst.tendsto _).comp hφ) ?_ have : g ∘ Prod.fst ∘ φ = Prod.snd ∘ φ := by ext n exact (hφg n).symm rw [this] exact (continuous_snd.tendsto _).comp hφ variable {g} namespace ContinuousLinearMap /-- Upgrade a `LinearMap` to a `ContinuousLinearMap` using the **closed graph theorem**. -/ def ofIsClosedGraph (hg : IsClosed (g.graph : Set <| E × F)) : E →L[𝕜] F where toLinearMap := g cont := g.continuous_of_isClosed_graph hg @[simp] theorem coeFn_ofIsClosedGraph (hg : IsClosed (g.graph : Set <| E × F)) : ⇑(ContinuousLinearMap.ofIsClosedGraph hg) = g := rfl theorem coe_ofIsClosedGraph (hg : IsClosed (g.graph : Set <| E × F)) : ↑(ContinuousLinearMap.ofIsClosedGraph hg) = g := by ext rfl /-- Upgrade a `LinearMap` to a `ContinuousLinearMap` using a variation on the **closed graph theorem**. -/ def ofSeqClosedGraph (hg : ∀ (u : ℕ → E) (x y), Tendsto u atTop (𝓝 x) → Tendsto (g ∘ u) atTop (𝓝 y) → y = g x) : E →L[𝕜] F where toLinearMap := g cont := g.continuous_of_seq_closed_graph hg @[simp] theorem coeFn_ofSeqClosedGraph (hg : ∀ (u : ℕ → E) (x y), Tendsto u atTop (𝓝 x) → Tendsto (g ∘ u) atTop (𝓝 y) → y = g x) : ⇑(ContinuousLinearMap.ofSeqClosedGraph hg) = g := rfl theorem coe_ofSeqClosedGraph (hg : ∀ (u : ℕ → E) (x y), Tendsto u atTop (𝓝 x) → Tendsto (g ∘ u) atTop (𝓝 y) → y = g x) : ↑(ContinuousLinearMap.ofSeqClosedGraph hg) = g := by ext rfl end ContinuousLinearMap end ClosedGraphThm section BijectivityCriteria namespace ContinuousLinearMap variable {σ : 𝕜 →+* 𝕜'} {σ' : 𝕜' →+* 𝕜} [RingHomInvPair σ σ'] variable {F : Type u_4} [NormedAddCommGroup F] [NormedSpace 𝕜' F] variable [CompleteSpace E] lemma closed_range_of_antilipschitz {f : E →SL[σ] F} {c : ℝ≥0} (hf : AntilipschitzWith c f) : (LinearMap.range f).topologicalClosure = LinearMap.range f := SetLike.ext'_iff.mpr <| (hf.isClosed_range f.uniformContinuous).closure_eq variable [CompleteSpace F] lemma _root_.AntilipschitzWith.completeSpace_range_clm {f : E →SL[σ] F} {c : ℝ≥0} (hf : AntilipschitzWith c f) : CompleteSpace (LinearMap.range f) := IsClosed.completeSpace_coe <| hf.isClosed_range f.uniformContinuous variable [RingHomInvPair σ' σ] [RingHomIsometric σ] [RingHomIsometric σ'] open Function lemma bijective_iff_dense_range_and_antilipschitz (f : E →SL[σ] F) : Bijective f ↔ (LinearMap.range f).topologicalClosure = ⊤ ∧ ∃ c, AntilipschitzWith c f := by refine ⟨fun h ↦ ⟨?eq_top, ?anti⟩, fun ⟨hd, c, hf⟩ ↦ ⟨hf.injective, ?surj⟩⟩ case eq_top => simpa [SetLike.ext'_iff] using h.2.denseRange.closure_eq case anti => refine ⟨_, ContinuousLinearEquiv.ofBijective f ?_ ?_ |>.antilipschitz⟩ <;> simp only [LinearMap.range_eq_top, LinearMapClass.ker_eq_bot, h.1, h.2] case surj => rwa [← LinearMap.range_eq_top, ← closed_range_of_antilipschitz hf] end ContinuousLinearMap end BijectivityCriteria
LinearDisjoint.lean
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.IntermediateField.Adjoin.Basic import Mathlib.RingTheory.AlgebraicIndependent.RankAndCardinality import Mathlib.RingTheory.LinearDisjoint /-! # Linearly disjoint fields This file contains basics about the linearly disjoint fields. We adapt the definitions in <https://en.wikipedia.org/wiki/Linearly_disjoint>. See the file `Mathlib/LinearAlgebra/LinearDisjoint.lean` and `Mathlib/RingTheory/LinearDisjoint.lean` for details. ## Main definitions - `IntermediateField.LinearDisjoint`: an intermediate field `A` of `E / F` and an abstract field `L` between `E / F` (as a special case, two intermediate fields) are linearly disjoint over `F`, if they are linearly disjoint as subalgebras (`Subalgebra.LinearDisjoint`). ## Implementation notes The `Subalgebra.LinearDisjoint` is stated for two `Subalgebra`s. The original design of `IntermediateField.LinearDisjoint` is also stated for two `IntermediateField`s (see `IntermediateField.linearDisjoint_iff'` for the original statement). But it's probably useful if one of them can be generalized to an abstract field (see <https://github.com/leanprover-community/mathlib4/pull/9651#discussion_r1464070324>). This leads to the current design of `IntermediateField.LinearDisjoint` which is for one `IntermediateField` and one abstract field. It is not generalized to two abstract fields as this will break the dot notation. ## Main results ### Equivalent characterization of linear disjointness - `IntermediateField.LinearDisjoint.linearIndependent_left`: if `A` and `L` are linearly disjoint, then any `F`-linearly independent family on `A` remains linearly independent over `L`. - `IntermediateField.LinearDisjoint.of_basis_left`: conversely, if there exists an `F`-basis of `A` which remains linearly independent over `L`, then `A` and `L` are linearly disjoint. - `IntermediateField.LinearDisjoint.linearIndependent_right`: `IntermediateField.LinearDisjoint.linearIndependent_right'`: if `A` and `L` are linearly disjoint, then any `F`-linearly independent family on `L` remains linearly independent over `A`. - `IntermediateField.LinearDisjoint.of_basis_right`: `IntermediateField.LinearDisjoint.of_basis_right'`: conversely, if there exists an `F`-basis of `L` which remains linearly independent over `A`, then `A` and `L` are linearly disjoint. - `IntermediateField.LinearDisjoint.linearIndependent_mul`: `IntermediateField.LinearDisjoint.linearIndependent_mul'`: if `A` and `L` are linearly disjoint, then for any family of `F`-linearly independent elements `{ a_i }` of `A`, and any family of `F`-linearly independent elements `{ b_j }` of `L`, the family `{ a_i * b_j }` in `S` is also `F`-linearly independent. - `IntermediateField.LinearDisjoint.of_basis_mul`: `IntermediateField.LinearDisjoint.of_basis_mul'`: conversely, if `{ a_i }` is an `F`-basis of `A`, if `{ b_j }` is an `F`-basis of `L`, such that the family `{ a_i * b_j }` in `E` is `F`-linearly independent, then `A` and `L` are linearly disjoint. ### Equivalent characterization by `IsDomain` or `IsField` of tensor product The following results are related to the equivalent characterizations in <https://mathoverflow.net/questions/8324>. - `IntermediateField.LinearDisjoint.isDomain'`, `IntermediateField.LinearDisjoint.exists_field_of_isDomain`: if `A` and `B` are field extensions of `F`, then `A ⊗[F] B` is a domain if and only if there exists a field extension of `F` that `A` and `B` embed into with linearly disjoint images. - `IntermediateField.LinearDisjoint.isField_of_forall`, `IntermediateField.LinearDisjoint.of_isField'`: if `A` and `B` are field extensions of `F`, then `A ⊗[F] B` is a field if and only if for any field extension of `F` that `A` and `B` embed into, their images are linearly disjoint. - `Algebra.TensorProduct.isField_of_isAlgebraic`: if `E` and `K` are field extensions of `F`, one of them is algebraic, and `E ⊗[F] K` is a domain, then `E ⊗[F] K` is also a field. See `Algebra.TensorProduct.isAlgebraic_of_isField` for its converse (in an earlier file). - `IntermediateField.LinearDisjoint.isField_of_isAlgebraic`, `IntermediateField.LinearDisjoint.isField_of_isAlgebraic'`: if `A` and `B` are field extensions of `F`, one of them is algebraic, such that they are linearly disjoint (more generally, if there exists a field extension of `F` that they embed into with linearly disjoint images), then `A ⊗[F] B` is a field. ### Other main results - `IntermediateField.LinearDisjoint.symm`, `IntermediateField.linearDisjoint_comm`: linear disjointness is symmetric. - `IntermediateField.LinearDisjoint.map`: linear disjointness is preserved by algebra homomorphism. - `IntermediateField.LinearDisjoint.rank_sup`, `IntermediateField.LinearDisjoint.finrank_sup`: if `A` and `B` are linearly disjoint, then the rank of `A ⊔ B` is equal to the product of the rank of `A` and `B`. - `IntermediateField.LinearDisjoint.of_finrank_sup`: conversely, if `A` and `B` are finite extensions, such that rank of `A ⊔ B` is equal to the product of the rank of `A` and `B`, then `A` and `B` are linearly disjoint. - `IntermediateField.LinearDisjoint.of_finrank_coprime`: if the rank of `A` and `B` are coprime, then `A` and `B` are linearly disjoint. - `IntermediateField.LinearDisjoint.inf_eq_bot`: if `A` and `B` are linearly disjoint, then they are disjoint. - `IntermediateField.LinearDisjoint.algEquiv_of_isAlgebraic`: linear disjointness is preserved by isomorphisms, provided that one of the field is algebraic. ## Tags linearly disjoint, linearly independent, tensor product -/ open scoped TensorProduct open Module IntermediateField noncomputable section universe u v w namespace IntermediateField variable {F : Type u} {E : Type v} [Field F] [Field E] [Algebra F E] variable (A B : IntermediateField F E) variable (L : Type w) [Field L] [Algebra F L] [Algebra L E] [IsScalarTower F L E] /-- If `A` is an intermediate field of `E / F`, and `E / L / F` is a field extension tower, then `A` and `L` are linearly disjoint, if they are linearly disjoint as subalgebras of `E` (`Subalgebra.LinearDisjoint`). -/ protected abbrev LinearDisjoint : Prop := A.toSubalgebra.LinearDisjoint (IsScalarTower.toAlgHom F L E).range theorem linearDisjoint_iff : A.LinearDisjoint L ↔ A.toSubalgebra.LinearDisjoint (IsScalarTower.toAlgHom F L E).range := Iff.rfl variable {A B L} /-- Two intermediate fields are linearly disjoint if and only if they are linearly disjoint as subalgebras. -/ theorem linearDisjoint_iff' : A.LinearDisjoint B ↔ A.toSubalgebra.LinearDisjoint B.toSubalgebra := by rw [linearDisjoint_iff] congr! ext; simp /-- Linear disjointness is symmetric. -/ theorem LinearDisjoint.symm (H : A.LinearDisjoint B) : B.LinearDisjoint A := linearDisjoint_iff'.2 (linearDisjoint_iff'.1 H).symm /-- Linear disjointness is symmetric. -/ theorem linearDisjoint_comm : A.LinearDisjoint B ↔ B.LinearDisjoint A := ⟨LinearDisjoint.symm, LinearDisjoint.symm⟩ section variable {L' : Type*} [Field L'] [Algebra F L'] [Algebra L' E] [IsScalarTower F L' E] /-- Linear disjointness is symmetric. -/ theorem LinearDisjoint.symm' (H : (IsScalarTower.toAlgHom F L E).fieldRange.LinearDisjoint L') : (IsScalarTower.toAlgHom F L' E).fieldRange.LinearDisjoint L := Subalgebra.LinearDisjoint.symm H /-- Linear disjointness is symmetric. -/ theorem linearDisjoint_comm' : (IsScalarTower.toAlgHom F L E).fieldRange.LinearDisjoint L' ↔ (IsScalarTower.toAlgHom F L' E).fieldRange.LinearDisjoint L := ⟨LinearDisjoint.symm', LinearDisjoint.symm'⟩ end namespace LinearDisjoint /-- Linear disjointness of intermediate fields is preserved by algebra homomorphisms. -/ theorem map (H : A.LinearDisjoint B) {K : Type*} [Field K] [Algebra F K] (f : E →ₐ[F] K) : (A.map f).LinearDisjoint (B.map f) := linearDisjoint_iff'.2 ((linearDisjoint_iff'.1 H).map f f.injective) /-- Linear disjointness of an intermediate field with a tower of field embeddings is preserved by algebra homomorphisms. -/ theorem map' (H : A.LinearDisjoint L) (K : Type*) [Field K] [Algebra F K] [Algebra L K] [IsScalarTower F L K] [Algebra E K] [IsScalarTower F E K] [IsScalarTower L E K] : (A.map (IsScalarTower.toAlgHom F E K)).LinearDisjoint L := by rw [linearDisjoint_iff] at H ⊢ have := H.map (IsScalarTower.toAlgHom F E K) (RingHom.injective _) rw [← AlgHom.range_comp] at this convert this ext; exact IsScalarTower.algebraMap_apply L E K _ /-- Linear disjointness is preserved by algebra homomorphism. -/ theorem map'' {L' : Type*} [Field L'] [Algebra F L'] [Algebra L' E] [IsScalarTower F L' E] (H : (IsScalarTower.toAlgHom F L E).fieldRange.LinearDisjoint L') (K : Type*) [Field K] [Algebra F K] [Algebra L K] [IsScalarTower F L K] [Algebra L' K] [IsScalarTower F L' K] [Algebra E K] [IsScalarTower F E K] [IsScalarTower L E K] [IsScalarTower L' E K] : (IsScalarTower.toAlgHom F L K).fieldRange.LinearDisjoint L' := by rw [linearDisjoint_iff] at H ⊢ have := H.map (IsScalarTower.toAlgHom F E K) (RingHom.injective _) simp_rw [AlgHom.fieldRange_toSubalgebra, ← AlgHom.range_comp] at this rw [AlgHom.fieldRange_toSubalgebra] convert this <;> (ext; exact IsScalarTower.algebraMap_apply _ E K _) variable (A) in theorem self_right : A.LinearDisjoint F := Subalgebra.LinearDisjoint.bot_right _ variable (A) in theorem bot_right : A.LinearDisjoint (⊥ : IntermediateField F E) := linearDisjoint_iff'.2 (Subalgebra.LinearDisjoint.bot_right _) variable (F E L) in theorem bot_left : (⊥ : IntermediateField F E).LinearDisjoint L := Subalgebra.LinearDisjoint.bot_left _ /-- If `A` and `L` are linearly disjoint, then any `F`-linearly independent family on `A` remains linearly independent over `L`. -/ theorem linearIndependent_left (H : A.LinearDisjoint L) {ι : Type*} {a : ι → A} (ha : LinearIndependent F a) : LinearIndependent L (A.val ∘ a) := (Subalgebra.LinearDisjoint.linearIndependent_left_of_flat H ha).map_of_injective_injective (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)) (AddMonoidHom.id E) (by simp) (by simp) (fun _ _ ↦ by simp_rw [Algebra.smul_def]; rfl) /-- If there exists an `F`-basis of `A` which remains linearly independent over `L`, then `A` and `L` are linearly disjoint. -/ theorem of_basis_left {ι : Type*} (a : Basis ι F A) (H : LinearIndependent L (A.val ∘ a)) : A.LinearDisjoint L := Subalgebra.LinearDisjoint.of_basis_left _ _ a <| H.map_of_surjective_injective (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)) (AddMonoidHom.id E) (AlgEquiv.surjective _) (by simp) (fun _ _ ↦ by simp_rw [Algebra.smul_def]; rfl) /-- If `A` and `B` are linearly disjoint, then any `F`-linearly independent family on `B` remains linearly independent over `A`. -/ theorem linearIndependent_right (H : A.LinearDisjoint B) {ι : Type*} {b : ι → B} (hb : LinearIndependent F b) : LinearIndependent A (B.val ∘ b) := (linearDisjoint_iff'.1 H).linearIndependent_right_of_flat hb /-- If there exists an `F`-basis of `B` which remains linearly independent over `A`, then `A` and `B` are linearly disjoint. -/ theorem of_basis_right {ι : Type*} (b : Basis ι F B) (H : LinearIndependent A (B.val ∘ b)) : A.LinearDisjoint B := linearDisjoint_iff'.2 (.of_basis_right _ _ b H) /-- If `A` and `L` are linearly disjoint, then any `F`-linearly independent family on `L` remains linearly independent over `A`. -/ theorem linearIndependent_right' (H : A.LinearDisjoint L) {ι : Type*} {b : ι → L} (hb : LinearIndependent F b) : LinearIndependent A (algebraMap L E ∘ b) := by apply Subalgebra.LinearDisjoint.linearIndependent_right_of_flat H <| hb.map' _ (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)).toLinearEquiv.ker /-- If there exists an `F`-basis of `L` which remains linearly independent over `A`, then `A` and `L` are linearly disjoint. -/ theorem of_basis_right' {ι : Type*} (b : Basis ι F L) (H : LinearIndependent A (algebraMap L E ∘ b)) : A.LinearDisjoint L := Subalgebra.LinearDisjoint.of_basis_right _ _ (b.map (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)).toLinearEquiv) H /-- If `A` and `B` are linearly disjoint, then for any `F`-linearly independent families `{ u_i }`, `{ v_j }` of `A`, `B`, the products `{ u_i * v_j }` are linearly independent over `F`. -/ theorem linearIndependent_mul (H : A.LinearDisjoint B) {κ ι : Type*} {a : κ → A} {b : ι → B} (ha : LinearIndependent F a) (hb : LinearIndependent F b) : LinearIndependent F fun (i : κ × ι) ↦ (a i.1).1 * (b i.2).1 := (linearDisjoint_iff'.1 H).linearIndependent_mul_of_flat_left ha hb /-- If `A` and `L` are linearly disjoint, then for any `F`-linearly independent families `{ u_i }`, `{ v_j }` of `A`, `L`, the products `{ u_i * v_j }` are linearly independent over `F`. -/ theorem linearIndependent_mul' (H : A.LinearDisjoint L) {κ ι : Type*} {a : κ → A} {b : ι → L} (ha : LinearIndependent F a) (hb : LinearIndependent F b) : LinearIndependent F fun (i : κ × ι) ↦ (a i.1).1 * algebraMap L E (b i.2) := by apply Subalgebra.LinearDisjoint.linearIndependent_mul_of_flat_left H ha <| hb.map' _ (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)).toLinearEquiv.ker /-- If there are `F`-bases `{ u_i }`, `{ v_j }` of `A`, `B`, such that the products `{ u_i * v_j }` are linearly independent over `F`, then `A` and `B` are linearly disjoint. -/ theorem of_basis_mul {κ ι : Type*} (a : Basis κ F A) (b : Basis ι F B) (H : LinearIndependent F fun (i : κ × ι) ↦ (a i.1).1 * (b i.2).1) : A.LinearDisjoint B := linearDisjoint_iff'.2 (.of_basis_mul _ _ a b H) /-- If there are `F`-bases `{ u_i }`, `{ v_j }` of `A`, `L`, such that the products `{ u_i * v_j }` are linearly independent over `F`, then `A` and `L` are linearly disjoint. -/ theorem of_basis_mul' {κ ι : Type*} (a : Basis κ F A) (b : Basis ι F L) (H : LinearIndependent F fun (i : κ × ι) ↦ (a i.1).1 * algebraMap L E (b i.2)) : A.LinearDisjoint L := Subalgebra.LinearDisjoint.of_basis_mul _ _ a (b.map (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)).toLinearEquiv) H theorem of_le_left {A' : IntermediateField F E} (H : A.LinearDisjoint L) (h : A' ≤ A) : A'.LinearDisjoint L := Subalgebra.LinearDisjoint.of_le_left_of_flat H h theorem of_le_right {B' : IntermediateField F E} (H : A.LinearDisjoint B) (h : B' ≤ B) : A.LinearDisjoint B' := linearDisjoint_iff'.2 ((linearDisjoint_iff'.1 H).of_le_right_of_flat h) /-- Similar to `IntermediateField.LinearDisjoint.of_le_right` but this is for abstract fields. -/ theorem of_le_right' (H : A.LinearDisjoint L) (L' : Type*) [Field L'] [Algebra F L'] [Algebra L' L] [IsScalarTower F L' L] [Algebra L' E] [IsScalarTower F L' E] [IsScalarTower L' L E] : A.LinearDisjoint L' := by refine Subalgebra.LinearDisjoint.of_le_right_of_flat H ?_ convert AlgHom.range_comp_le_range (IsScalarTower.toAlgHom F L' L) (IsScalarTower.toAlgHom F L E) ext; exact IsScalarTower.algebraMap_apply L' L E _ /-- If `A` and `B` are linearly disjoint, `A'` and `B'` are contained in `A` and `B`, respectively, then `A'` and `B'` are also linearly disjoint. -/ theorem of_le {A' B' : IntermediateField F E} (H : A.LinearDisjoint B) (hA : A' ≤ A) (hB : B' ≤ B) : A'.LinearDisjoint B' := H.of_le_left hA |>.of_le_right hB /-- Similar to `IntermediateField.LinearDisjoint.of_le` but this is for abstract fields. -/ theorem of_le' {A' : IntermediateField F E} (H : A.LinearDisjoint L) (hA : A' ≤ A) (L' : Type*) [Field L'] [Algebra F L'] [Algebra L' L] [IsScalarTower F L' L] [Algebra L' E] [IsScalarTower F L' E] [IsScalarTower L' L E] : A'.LinearDisjoint L' := H.of_le_left hA |>.of_le_right' L' /-- If `A` and `B` are linearly disjoint over `F`, then their intersection is equal to `F`. -/ theorem inf_eq_bot (H : A.LinearDisjoint B) : A ⊓ B = ⊥ := toSubalgebra_injective (linearDisjoint_iff'.1 H).inf_eq_bot /-- If `A` and `A` itself are linearly disjoint over `F`, then it is equal to `F`. -/ theorem eq_bot_of_self (H : A.LinearDisjoint A) : A = ⊥ := inf_idem A ▸ H.inf_eq_bot /-- If `A` and `B` are linearly disjoint over `F`, then the rank of `A ⊔ B` is equal to the product of that of `A` and `B`. -/ theorem rank_sup (H : A.LinearDisjoint B) : Module.rank F ↥(A ⊔ B) = Module.rank F A * Module.rank F B := have h := le_sup_toSubalgebra A B (rank_sup_le A B).antisymm <| (linearDisjoint_iff'.1 H).rank_sup_of_free.ge.trans <| (Subalgebra.inclusion h).toLinearMap.rank_le_of_injective (Subalgebra.inclusion_injective h) /-- If `A` and `B` are linearly disjoint over `F`, then the `Module.finrank` of `A ⊔ B` is equal to the product of that of `A` and `B`. -/ theorem finrank_sup (H : A.LinearDisjoint B) : finrank F ↥(A ⊔ B) = finrank F A * finrank F B := by simpa only [map_mul] using congr(Cardinal.toNat $(H.rank_sup)) /-- If `A` and `B` are finite extensions of `F`, such that rank of `A ⊔ B` is equal to the product of the rank of `A` and `B`, then `A` and `B` are linearly disjoint. -/ theorem of_finrank_sup [FiniteDimensional F A] [FiniteDimensional F B] (H : finrank F ↥(A ⊔ B) = finrank F A * finrank F B) : A.LinearDisjoint B := linearDisjoint_iff'.2 <| .of_finrank_sup_of_free (by rwa [← sup_toSubalgebra_of_left]) /-- If `A` and `L` are linearly disjoint over `F`, one of them is algebraic, then `[L(A) : L] = [A : F]`. -/ theorem adjoin_rank_eq_rank_left_of_isAlgebraic (H : A.LinearDisjoint L) (halg : Algebra.IsAlgebraic F A ∨ Algebra.IsAlgebraic F L) : Module.rank L (adjoin L (A : Set E)) = Module.rank F A := by refine Eq.trans ?_ (Subalgebra.LinearDisjoint.adjoin_rank_eq_rank_left H) set L' := (IsScalarTower.toAlgHom F L E).range let i : L ≃ₐ[F] L' := AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E) have heq : (adjoin L (A : Set E)).toSubalgebra.toSubsemiring = (Algebra.adjoin L' (A : Set E)).toSubsemiring := by rw [adjoin_toSubalgebra_of_isAlgebraic _ _ halg.symm, Algebra.adjoin_toSubsemiring, Algebra.adjoin_toSubsemiring] congr 2 ext x simp only [Set.mem_range, Subtype.exists] exact ⟨fun ⟨y, h⟩ ↦ ⟨x, ⟨y, h⟩, rfl⟩, fun ⟨a, ⟨y, h1⟩, h2⟩ ↦ ⟨y, h1.trans h2⟩⟩ refine rank_eq_of_equiv_equiv i (RingEquiv.subsemiringCongr heq).toAddEquiv i.bijective fun a ⟨x, hx⟩ ↦ ?_ ext simp_rw [Algebra.smul_def] rfl theorem adjoin_rank_eq_rank_left_of_isAlgebraic_left (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F A] : Module.rank L (adjoin L (A : Set E)) = Module.rank F A := H.adjoin_rank_eq_rank_left_of_isAlgebraic (.inl ‹_›) theorem adjoin_rank_eq_rank_left_of_isAlgebraic_right (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F L] : Module.rank L (adjoin L (A : Set E)) = Module.rank F A := H.adjoin_rank_eq_rank_left_of_isAlgebraic (.inr ‹_›) /-- If `A` and `L` are linearly disjoint over `F`, one of them is algebraic, then `[L(A) : A] = [L : F]`. Note that in Lean `L(A)` is not naturally an `A`-algebra, so this result is stated in a cumbersome way. -/ theorem lift_adjoin_rank_eq_lift_rank_right_of_isAlgebraic (H : A.LinearDisjoint L) (halg : Algebra.IsAlgebraic F A ∨ Algebra.IsAlgebraic F L) : Cardinal.lift.{w} (Module.rank A (extendScalars (show A ≤ (adjoin L (A : Set E)).restrictScalars F from subset_adjoin L (A : Set E)))) = Cardinal.lift.{v} (Module.rank F L) := by rw [(AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)).toLinearEquiv.lift_rank_eq, Cardinal.lift_inj, ← Subalgebra.LinearDisjoint.adjoin_rank_eq_rank_right H] set L' := (IsScalarTower.toAlgHom F L E).range have heq : (adjoin L (A : Set E)).toSubalgebra.toSubsemiring = (Algebra.adjoin A (L' : Set E)).toSubsemiring := by rw [adjoin_toSubalgebra_of_isAlgebraic _ _ halg.symm, Algebra.adjoin_toSubsemiring, Algebra.adjoin_toSubsemiring, Set.union_comm] congr 2 ext x simp refine rank_eq_of_equiv_equiv (RingHom.id A) (RingEquiv.subsemiringCongr heq).toAddEquiv Function.bijective_id fun ⟨a, ha⟩ ⟨x, hx⟩ ↦ ?_ ext simp_rw [Algebra.smul_def] rfl theorem lift_adjoin_rank_eq_lift_rank_right_of_isAlgebraic_left (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F A] : Cardinal.lift.{w} (Module.rank A (extendScalars (show A ≤ (adjoin L (A : Set E)).restrictScalars F from subset_adjoin L (A : Set E)))) = Cardinal.lift.{v} (Module.rank F L) := H.lift_adjoin_rank_eq_lift_rank_right_of_isAlgebraic (.inl ‹_›) theorem lift_adjoin_rank_eq_lift_rank_right_of_isAlgebraic_right (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F L] : Cardinal.lift.{w} (Module.rank A (extendScalars (show A ≤ (adjoin L (A : Set E)).restrictScalars F from subset_adjoin L (A : Set E)))) = Cardinal.lift.{v} (Module.rank F L) := H.lift_adjoin_rank_eq_lift_rank_right_of_isAlgebraic (.inr ‹_›) /-- If `A` is an intermediate field of `E / F`, `L` is an abstract field between `E / F`, such that they are linearly disjoint over `F`, and one of them is algebraic, then `[L : F] * [E : L(A)] = [E : A]`. -/ theorem lift_rank_right_mul_lift_adjoin_rank_eq_of_isAlgebraic (H : A.LinearDisjoint L) (halg : Algebra.IsAlgebraic F A ∨ Algebra.IsAlgebraic F L) : Cardinal.lift.{v} (Module.rank F L) * Cardinal.lift.{w} (Module.rank (adjoin L (A : Set E)) E) = Cardinal.lift.{w} (Module.rank A E) := by rw [← H.lift_adjoin_rank_eq_lift_rank_right_of_isAlgebraic halg, ← Cardinal.lift_mul, Cardinal.lift_inj] exact rank_mul_rank A (extendScalars (show A ≤ (adjoin L (A : Set E)).restrictScalars F from subset_adjoin L (A : Set E))) E theorem lift_rank_right_mul_lift_adjoin_rank_eq_of_isAlgebraic_left (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F A] : Cardinal.lift.{v} (Module.rank F L) * Cardinal.lift.{w} (Module.rank (adjoin L (A : Set E)) E) = Cardinal.lift.{w} (Module.rank A E) := H.lift_rank_right_mul_lift_adjoin_rank_eq_of_isAlgebraic (.inl ‹_›) theorem lift_rank_right_mul_lift_adjoin_rank_eq_of_isAlgebraic_right (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F L] : Cardinal.lift.{v} (Module.rank F L) * Cardinal.lift.{w} (Module.rank (adjoin L (A : Set E)) E) = Cardinal.lift.{w} (Module.rank A E) := H.lift_rank_right_mul_lift_adjoin_rank_eq_of_isAlgebraic (.inr ‹_›) section variable {L : Type v} [Field L] [Algebra F L] [Algebra L E] [IsScalarTower F L E] /-- The same-universe version of `IntermediateField.LinearDisjoint.lift_adjoin_rank_eq_lift_rank_right_of_isAlgebraic`. -/ theorem adjoin_rank_eq_rank_right_of_isAlgebraic (H : A.LinearDisjoint L) (halg : Algebra.IsAlgebraic F A ∨ Algebra.IsAlgebraic F L) : Module.rank A (extendScalars (show A ≤ (adjoin L (A : Set E)).restrictScalars F from subset_adjoin L (A : Set E))) = Module.rank F L := by simpa only [Cardinal.lift_id] using H.lift_adjoin_rank_eq_lift_rank_right_of_isAlgebraic halg theorem adjoin_rank_eq_rank_right_of_isAlgebraic_left (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F A] : Module.rank A (extendScalars (show A ≤ (adjoin L (A : Set E)).restrictScalars F from subset_adjoin L (A : Set E))) = Module.rank F L := H.adjoin_rank_eq_rank_right_of_isAlgebraic (.inl ‹_›) theorem adjoin_rank_eq_rank_right_of_isAlgebraic_right (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F L] : Module.rank A (extendScalars (show A ≤ (adjoin L (A : Set E)).restrictScalars F from subset_adjoin L (A : Set E))) = Module.rank F L := H.adjoin_rank_eq_rank_right_of_isAlgebraic (.inr ‹_›) /-- The same-universe version of `IntermediateField.LinearDisjoint.lift_rank_right_mul_lift_adjoin_rank_eq_of_isAlgebraic`. -/ theorem rank_right_mul_adjoin_rank_eq_of_isAlgebraic (H : A.LinearDisjoint L) (halg : Algebra.IsAlgebraic F A ∨ Algebra.IsAlgebraic F L) : Module.rank F L * Module.rank (adjoin L (A : Set E)) E = Module.rank A E := by simpa only [Cardinal.lift_id] using H.lift_rank_right_mul_lift_adjoin_rank_eq_of_isAlgebraic halg theorem rank_right_mul_adjoin_rank_eq_of_isAlgebraic_left (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F A] : Module.rank F L * Module.rank (adjoin L (A : Set E)) E = Module.rank A E := H.rank_right_mul_adjoin_rank_eq_of_isAlgebraic (.inl ‹_›) theorem rank_right_mul_adjoin_rank_eq_of_isAlgebraic_right (H : A.LinearDisjoint L) [Algebra.IsAlgebraic F L] : Module.rank F L * Module.rank (adjoin L (A : Set E)) E = Module.rank A E := H.rank_right_mul_adjoin_rank_eq_of_isAlgebraic (.inr ‹_›) end /-- If `A` and `L` have coprime degree over `F`, then they are linearly disjoint. -/ theorem of_finrank_coprime (H : (finrank F A).Coprime (finrank F L)) : A.LinearDisjoint L := letI : Field (AlgHom.range (IsScalarTower.toAlgHom F L E)) := inferInstanceAs <| Field (AlgHom.fieldRange (IsScalarTower.toAlgHom F L E)) letI : Field A.toSubalgebra := inferInstanceAs <| Field A Subalgebra.LinearDisjoint.of_finrank_coprime_of_free <| by rwa [(AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)).toLinearEquiv.finrank_eq] at H /-- If `A` and `L` are linearly disjoint over `F`, then `A ⊗[F] L` is a domain. -/ theorem isDomain (H : A.LinearDisjoint L) : IsDomain (A ⊗[F] L) := have : IsDomain (A ⊗[F] _) := Subalgebra.LinearDisjoint.isDomain H (Algebra.TensorProduct.congr (AlgEquiv.refl : A ≃ₐ[F] A) (AlgEquiv.ofInjective (IsScalarTower.toAlgHom F L E) (RingHom.injective _))).toMulEquiv.isDomain /-- If `A` and `B` are field extensions of `F`, there exists a field extension `E` of `F` that `A` and `B` embed into with linearly disjoint images, then `A ⊗[F] B` is a domain. -/ theorem isDomain' {A B : Type*} [Field A] [Algebra F A] [Field B] [Algebra F B] {fa : A →ₐ[F] E} {fb : B →ₐ[F] E} (H : fa.fieldRange.LinearDisjoint fb.fieldRange) : IsDomain (A ⊗[F] B) := by simp_rw [linearDisjoint_iff', AlgHom.fieldRange_toSubalgebra] at H exact H.isDomain_of_injective fa.injective fb.injective /-- If `A ⊗[F] L` is a field, then `A` and `L` are linearly disjoint over `F`. -/ theorem of_isField (H : IsField (A ⊗[F] L)) : A.LinearDisjoint L := by apply Subalgebra.LinearDisjoint.of_isField -- need these otherwise the `exact` will stuck at typeclass haveI : SMulCommClass F A A := SMulCommClass.of_commMonoid F A A haveI : SMulCommClass F A.toSubalgebra A.toSubalgebra := ‹SMulCommClass F A A› letI : Mul (A ⊗[F] L) := Algebra.TensorProduct.instMul letI : Mul (A.toSubalgebra ⊗[F] (IsScalarTower.toAlgHom F L E).range) := Algebra.TensorProduct.instMul exact Algebra.TensorProduct.congr (AlgEquiv.refl : A ≃ₐ[F] A) (AlgEquiv.ofInjective (IsScalarTower.toAlgHom F L E) (RingHom.injective _)) |>.symm.toMulEquiv.isField H /-- If `A` and `B` are field extensions of `F`, such that `A ⊗[F] B` is a field, then for any field extension of `F` that `A` and `B` embed into, their images are linearly disjoint. -/ theorem of_isField' {A : Type v} [Field A] {B : Type w} [Field B] [Algebra F A] [Algebra F B] (H : IsField (A ⊗[F] B)) {K : Type*} [Field K] [Algebra F K] (fa : A →ₐ[F] K) (fb : B →ₐ[F] K) : fa.fieldRange.LinearDisjoint fb.fieldRange := by rw [linearDisjoint_iff'] apply Subalgebra.LinearDisjoint.of_isField exact Algebra.TensorProduct.congr (AlgEquiv.ofInjective fa fa.injective) (AlgEquiv.ofInjective fb fb.injective) |>.symm.toMulEquiv.isField H variable (F) in /-- If `A` and `B` are field extensions of `F`, such that `A ⊗[F] B` is a domain, then there exists a field extension of `F` that `A` and `B` embed into with linearly disjoint images. -/ theorem exists_field_of_isDomain (A : Type v) [Field A] (B : Type w) [Field B] [Algebra F A] [Algebra F B] [IsDomain (A ⊗[F] B)] : ∃ (K : Type (max v w)) (_ : Field K) (_ : Algebra F K) (fa : A →ₐ[F] K) (fb : B →ₐ[F] K), fa.fieldRange.LinearDisjoint fb.fieldRange := have ⟨K, inst1, inst2, fa, fb, _, _, H⟩ := Subalgebra.LinearDisjoint.exists_field_of_isDomain_of_injective F A B (RingHom.injective _) (RingHom.injective _) ⟨K, inst1, inst2, fa, fb, linearDisjoint_iff'.2 H⟩ variable (F) in /-- If for any field extension `K` of `F` that `A` and `B` embed into, their images are linearly disjoint, then `A ⊗[F] B` is a field. (In the proof we choose `K` to be the quotient of `A ⊗[F] B` by a maximal ideal.) -/ theorem isField_of_forall (A : Type v) [Field A] (B : Type w) [Field B] [Algebra F A] [Algebra F B] (H : ∀ (K : Type (max v w)) [Field K] [Algebra F K], ∀ (fa : A →ₐ[F] K) (fb : B →ₐ[F] K), fa.fieldRange.LinearDisjoint fb.fieldRange) : IsField (A ⊗[F] B) := by obtain ⟨M, hM⟩ := Ideal.exists_maximal (A ⊗[F] B) apply not_imp_not.1 (Ring.ne_bot_of_isMaximal_of_not_isField hM) let K : Type (max v w) := A ⊗[F] B ⧸ M letI : Field K := Ideal.Quotient.field _ let i := IsScalarTower.toAlgHom F (A ⊗[F] B) K let fa := i.comp (Algebra.TensorProduct.includeLeft : A →ₐ[F] _) let fb := i.comp (Algebra.TensorProduct.includeRight : B →ₐ[F] _) replace H := H K fa fb simp_rw [linearDisjoint_iff', AlgHom.fieldRange_toSubalgebra, Subalgebra.linearDisjoint_iff_injective] at H have hi : i = (fa.range.mulMap fb.range).comp (Algebra.TensorProduct.congr (AlgEquiv.ofInjective fa fa.injective) (AlgEquiv.ofInjective fb fb.injective)) := by ext <;> simp [fa, fb] replace H : Function.Injective i := by simpa only [hi, AlgHom.coe_comp, AlgHom.coe_coe, EquivLike.injective_comp, fa, this, K, fb] change Function.Injective (Ideal.Quotient.mk M) at H rwa [RingHom.injective_iff_ker_eq_bot, Ideal.mk_ker] at H variable (F E) in /-- If `E` and `K` are field extensions of `F`, one of them is algebraic, such that `E ⊗[F] K` is a domain, then `E ⊗[F] K` is also a field. It is a corollary of `Subalgebra.LinearDisjoint.exists_field_of_isDomain_of_injective` and `IntermediateField.sup_toSubalgebra_of_isAlgebraic`. See `Algebra.TensorProduct.isAlgebraic_of_isField` for its converse (in an earlier file). -/ theorem _root_.Algebra.TensorProduct.isField_of_isAlgebraic (K : Type*) [Field K] [Algebra F K] [IsDomain (E ⊗[F] K)] (halg : Algebra.IsAlgebraic F E ∨ Algebra.IsAlgebraic F K) : IsField (E ⊗[F] K) := have ⟨L, _, _, fa, fb, hfa, hfb, H⟩ := Subalgebra.LinearDisjoint.exists_field_of_isDomain_of_injective F E K (RingHom.injective _) (RingHom.injective _) let f : E ⊗[F] K ≃ₐ[F] ↥(fa.fieldRange ⊔ fb.fieldRange) := Algebra.TensorProduct.congr (AlgEquiv.ofInjective fa hfa) (AlgEquiv.ofInjective fb hfb) |>.trans (Subalgebra.LinearDisjoint.mulMap H) |>.trans (Subalgebra.equivOfEq _ _ (sup_toSubalgebra_of_isAlgebraic fa.fieldRange fb.fieldRange <| by rwa [(AlgEquiv.ofInjective fa hfa).isAlgebraic_iff, (AlgEquiv.ofInjective fb hfb).isAlgebraic_iff] at halg).symm) f.toMulEquiv.isField (Field.toIsField _) /-- If `A` and `L` are linearly disjoint over `F` and one of them is algebraic, then `A ⊗[F] L` is a field. -/ theorem isField_of_isAlgebraic (H : A.LinearDisjoint L) (halg : Algebra.IsAlgebraic F A ∨ Algebra.IsAlgebraic F L) : IsField (A ⊗[F] L) := have := H.isDomain Algebra.TensorProduct.isField_of_isAlgebraic F A L halg /-- If `A` and `B` are field extensions of `F`, one of them is algebraic, such that there exists a field `E` that `A` and `B` embeds into with linearly disjoint images, then `A ⊗[F] B` is a field. -/ theorem isField_of_isAlgebraic' {A B : Type*} [Field A] [Algebra F A] [Field B] [Algebra F B] {fa : A →ₐ[F] E} {fb : B →ₐ[F] E} (H : fa.fieldRange.LinearDisjoint fb.fieldRange) (halg : Algebra.IsAlgebraic F A ∨ Algebra.IsAlgebraic F B) : IsField (A ⊗[F] B) := have := H.isDomain' Algebra.TensorProduct.isField_of_isAlgebraic F A B halg /-- If `A` and `L` are linearly disjoint, one of them is algebraic, then for any `B` and `L'` isomorphic to `A` and `L` respectively, `B` and `L'` are also linearly disjoint. -/ theorem algEquiv_of_isAlgebraic (H : A.LinearDisjoint L) {E' : Type*} [Field E'] [Algebra F E'] (B : IntermediateField F E') (L' : Type*) [Field L'] [Algebra F L'] [Algebra L' E'] [IsScalarTower F L' E'] (f1 : A ≃ₐ[F] B) (f2 : L ≃ₐ[F] L') (halg : Algebra.IsAlgebraic F A ∨ Algebra.IsAlgebraic F L) : B.LinearDisjoint L' := .of_isField ((Algebra.TensorProduct.congr f1 f2).symm.toMulEquiv.isField (H.isField_of_isAlgebraic halg)) end LinearDisjoint end IntermediateField
tuple.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. From mathcomp Require Import seq choice fintype path. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. (******************************************************************************) (* This file defines tuples, i.e., sequences with a fixed (known) length, *) (* and sequences with bounded length. *) (* For tuples we define: *) (* n.-tuple T == the type of n-tuples of elements of type T *) (* [tuple of s] == the tuple whose underlying sequence (value) is s *) (* The size of s must be known: specifically, Coq must *) (* be able to infer a Canonical tuple projecting on s. *) (* in_tuple s == the (size s).-tuple with value s *) (* [tuple] == the empty tuple *) (* [tuple x1; ..; xn] == the explicit n.-tuple <x1; ..; xn> *) (* [tuple E | i < n] == the n.-tuple with general term E (i : 'I_n is bound *) (* in E) *) (* tcast Emn t == the m.-tuple t cast as an n.-tuple using Emn : m = n *) (* As n.-tuple T coerces to seq t, all seq operations (size, nth, ...) can be *) (* applied to t : n.-tuple T; we provide a few specialized instances when *) (* avoids the need for a default value. *) (* tsize t == the size of t (the n in n.-tuple T) *) (* tnth t i == the i'th component of t, where i : 'I_n *) (* [tnth t i] == the i'th component of t, where i : nat and i < n *) (* is convertible to true *) (* thead t == the first element of t, when n is m.+1 for some m *) (* For bounded sequences we define: *) (* n.-bseq T == the type of bounded sequences of elements of type T, *) (* the length of a bounded sequence is smaller or *) (* or equal to n *) (* [bseq of s] == the bounded sequence whose underlying value is s *) (* The size of s must be known. *) (* in_bseq s == the (size s).-bseq with value s *) (* [bseq] == the empty bseq *) (* insub_bseq n s == the n.-bseq of value s if size s <= n, else [bseq] *) (* [bseq x1; ..; xn] == the explicit n.-bseq <x1; ..; xn> *) (* cast_bseq Emn t == the m.-bseq t cast as an n.-tuple using Emn : m = n *) (* widen_bseq Lmn t == the m.-bseq t cast as an n.-tuple using Lmn : m <= n *) (* Most seq constructors (cons, behead, cat, rcons, belast, take, drop, rot, *) (* rotr, map, ...) can be used to build tuples and bounded sequences via *) (* the [tuple of s] and [bseq of s] constructs respectively. *) (* Tuples and bounded sequences are actually instances of subType of seq, *) (* and inherit all combinatorial structures, including the finType structure. *) (* Some useful lemmas and definitions: *) (* tuple0 : [tuple] is the only 0.-tuple *) (* bseq0 : [bseq] is the only 0.-bseq *) (* tupleP : elimination view for n.+1.-tuple *) (* ord_tuple n : the n.-tuple of all i : 'I_n *) (******************************************************************************) Section TupleDef. Variables (n : nat) (T : Type). Structure tuple_of : Type := Tuple {tval :> seq T; _ : size tval == n}. HB.instance Definition _ := [isSub for tval]. Implicit Type t : tuple_of. Definition tsize of tuple_of := n. Lemma size_tuple t : size t = n. Proof. exact: (eqP (valP t)). Qed. Lemma tnth_default t : 'I_n -> T. Proof. by rewrite -(size_tuple t); case: (tval t) => [|//] []. Qed. Definition tnth t i := nth (tnth_default t i) t i. Lemma tnth_nth x t i : tnth t i = nth x t i. Proof. by apply: set_nth_default; rewrite size_tuple. Qed. Lemma tnth_onth x t i : tnth t i = x <-> onth t i = Some x. Proof. rewrite (tnth_nth x) onthE (nth_map x) ?size_tuple//. by split; [move->|case]. Qed. Lemma map_tnth_enum t : map (tnth t) (enum 'I_n) = t. Proof. case def_t: {-}(val t) => [|x0 t']. by rewrite [enum _]size0nil // -cardE card_ord -(size_tuple t) def_t. apply: (@eq_from_nth _ x0) => [|i]; rewrite size_map. by rewrite -cardE size_tuple card_ord. move=> lt_i_e; have lt_i_n: i < n by rewrite -cardE card_ord in lt_i_e. by rewrite (nth_map (Ordinal lt_i_n)) // (tnth_nth x0) nth_enum_ord. Qed. Lemma eq_from_tnth t1 t2 : tnth t1 =1 tnth t2 -> t1 = t2. Proof. by move/eq_map=> eq_t; apply: val_inj; rewrite /= -!map_tnth_enum eq_t. Qed. Definition tuple t mkT : tuple_of := mkT (let: Tuple _ tP := t return size t == n in tP). Lemma tupleE t : tuple (fun sP => @Tuple t sP) = t. Proof. by case: t. Qed. End TupleDef. Notation "n .-tuple" := (tuple_of n) (format "n .-tuple") : type_scope. Notation "{ 'tuple' n 'of' T }" := (n.-tuple T : predArgType) (only parsing) : type_scope. Notation "[ 'tuple' 'of' s ]" := (tuple (fun sP => @Tuple _ _ s sP)) (format "[ 'tuple' 'of' s ]") : form_scope. Notation "[ 'tnth' t i ]" := (tnth t (@Ordinal (tsize t) i (erefl true))) (t, i at level 8, format "[ 'tnth' t i ]") : form_scope. Canonical nil_tuple T := Tuple (isT : @size T [::] == 0). Canonical cons_tuple n T x (t : n.-tuple T) := Tuple (valP t : size (x :: t) == n.+1). Notation "[ 'tuple' x1 ; .. ; xn ]" := [tuple of x1 :: .. [:: xn] ..] (format "[ 'tuple' '[' x1 ; '/' .. ; '/' xn ']' ]") : form_scope. Notation "[ 'tuple' ]" := [tuple of [::]] (format "[ 'tuple' ]") : form_scope. Section CastTuple. Variable T : Type. Definition in_tuple (s : seq T) := Tuple (eqxx (size s)). Definition tcast m n (eq_mn : m = n) t := let: erefl in _ = n := eq_mn return n.-tuple T in t. Lemma tcastE m n (eq_mn : m = n) t i : tnth (tcast eq_mn t) i = tnth t (cast_ord (esym eq_mn) i). Proof. by case: n / eq_mn in i *; rewrite cast_ord_id. Qed. Lemma tcast_id n (eq_nn : n = n) t : tcast eq_nn t = t. Proof. by rewrite (eq_axiomK eq_nn). Qed. Lemma tcastK m n (eq_mn : m = n) : cancel (tcast eq_mn) (tcast (esym eq_mn)). Proof. by case: n / eq_mn. Qed. Lemma tcastKV m n (eq_mn : m = n) : cancel (tcast (esym eq_mn)) (tcast eq_mn). Proof. by case: n / eq_mn. Qed. Lemma tcast_trans m n p (eq_mn : m = n) (eq_np : n = p) t: tcast (etrans eq_mn eq_np) t = tcast eq_np (tcast eq_mn t). Proof. by case: n / eq_mn eq_np; case: p /. Qed. Lemma tvalK n (t : n.-tuple T) : in_tuple t = tcast (esym (size_tuple t)) t. Proof. by apply: val_inj => /=; case: _ / (esym _). Qed. Lemma val_tcast m n (eq_mn : m = n) (t : m.-tuple T) : tcast eq_mn t = t :> seq T. Proof. by case: n / eq_mn. Qed. Lemma in_tupleE s : in_tuple s = s :> seq T. Proof. by []. Qed. End CastTuple. Section SeqTuple. Variables (n m : nat) (T U rT : Type). Implicit Type t : n.-tuple T. Lemma rcons_tupleP t x : size (rcons t x) == n.+1. Proof. by rewrite size_rcons size_tuple. Qed. Canonical rcons_tuple t x := Tuple (rcons_tupleP t x). Lemma nseq_tupleP x : @size T (nseq n x) == n. Proof. by rewrite size_nseq. Qed. Canonical nseq_tuple x := Tuple (nseq_tupleP x). Lemma iota_tupleP : size (iota m n) == n. Proof. by rewrite size_iota. Qed. Canonical iota_tuple := Tuple iota_tupleP. Lemma behead_tupleP t : size (behead t) == n.-1. Proof. by rewrite size_behead size_tuple. Qed. Canonical behead_tuple t := Tuple (behead_tupleP t). Lemma belast_tupleP x t : size (belast x t) == n. Proof. by rewrite size_belast size_tuple. Qed. Canonical belast_tuple x t := Tuple (belast_tupleP x t). Lemma cat_tupleP t (u : m.-tuple T) : size (t ++ u) == n + m. Proof. by rewrite size_cat !size_tuple. Qed. Canonical cat_tuple t u := Tuple (cat_tupleP t u). Lemma take_tupleP t : size (take m t) == minn m n. Proof. by rewrite size_take size_tuple eqxx. Qed. Canonical take_tuple t := Tuple (take_tupleP t). Lemma drop_tupleP t : size (drop m t) == n - m. Proof. by rewrite size_drop size_tuple. Qed. Canonical drop_tuple t := Tuple (drop_tupleP t). Lemma rev_tupleP t : size (rev t) == n. Proof. by rewrite size_rev size_tuple. Qed. Canonical rev_tuple t := Tuple (rev_tupleP t). Lemma rot_tupleP t : size (rot m t) == n. Proof. by rewrite size_rot size_tuple. Qed. Canonical rot_tuple t := Tuple (rot_tupleP t). Lemma rotr_tupleP t : size (rotr m t) == n. Proof. by rewrite size_rotr size_tuple. Qed. Canonical rotr_tuple t := Tuple (rotr_tupleP t). Lemma map_tupleP f t : @size rT (map f t) == n. Proof. by rewrite size_map size_tuple. Qed. Canonical map_tuple f t := Tuple (map_tupleP f t). Lemma scanl_tupleP f x t : @size rT (scanl f x t) == n. Proof. by rewrite size_scanl size_tuple. Qed. Canonical scanl_tuple f x t := Tuple (scanl_tupleP f x t). Lemma pairmap_tupleP f x t : @size rT (pairmap f x t) == n. Proof. by rewrite size_pairmap size_tuple. Qed. Canonical pairmap_tuple f x t := Tuple (pairmap_tupleP f x t). Lemma zip_tupleP t (u : n.-tuple U) : size (zip t u) == n. Proof. by rewrite size1_zip !size_tuple. Qed. Canonical zip_tuple t u := Tuple (zip_tupleP t u). Lemma allpairs_tupleP f t (u : m.-tuple U) : @size rT (allpairs f t u) == n * m. Proof. by rewrite size_allpairs !size_tuple. Qed. Canonical allpairs_tuple f t u := Tuple (allpairs_tupleP f t u). Lemma sort_tupleP r t : size (sort r t) == n. Proof. by rewrite size_sort size_tuple. Qed. Canonical sort_tuple r t := Tuple (sort_tupleP r t). Definition thead (u : n.+1.-tuple T) := tnth u ord0. Lemma tnth0 x t : tnth [tuple of x :: t] ord0 = x. Proof. by []. Qed. Lemma tnthS x t i : tnth [tuple of x :: t] (lift ord0 i) = tnth t i. Proof. by rewrite (tnth_nth (tnth_default t i)). Qed. Lemma theadE x t : thead [tuple of x :: t] = x. Proof. by []. Qed. Lemma tuple0 : all_equal_to ([tuple] : 0.-tuple T). Proof. by move=> t; apply: val_inj; case: t => [[]]. Qed. Variant tuple1_spec : n.+1.-tuple T -> Type := Tuple1spec x t : tuple1_spec [tuple of x :: t]. Lemma tupleP u : tuple1_spec u. Proof. case: u => [[|x s] //= sz_s]; pose t := @Tuple n _ s sz_s. by rewrite (_ : Tuple _ = [tuple of x :: t]) //; apply: val_inj. Qed. Lemma tnth_map f t i : tnth [tuple of map f t] i = f (tnth t i) :> rT. Proof. by apply: nth_map; rewrite size_tuple. Qed. Lemma tnth_nseq x i : tnth [tuple of nseq n x] i = x. Proof. by rewrite !(tnth_nth (tnth_default (nseq_tuple x) i)) nth_nseq ltn_ord. Qed. End SeqTuple. Lemma tnth_behead n T (t : n.+1.-tuple T) i : tnth [tuple of behead t] i = tnth t (inord i.+1). Proof. by case/tupleP: t => x t; rewrite !(tnth_nth x) inordK ?ltnS. Qed. Lemma tuple_eta n T (t : n.+1.-tuple T) : t = [tuple of thead t :: behead t]. Proof. by case/tupleP: t => x t; apply: val_inj. Qed. Section tnth_shift. Context {T : Type} {n1 n2} (t1 : n1.-tuple T) (t2 : n2.-tuple T). Lemma tnth_lshift i : tnth [tuple of t1 ++ t2] (lshift n2 i) = tnth t1 i. Proof. have x0 := tnth_default t1 i; rewrite !(tnth_nth x0). by rewrite nth_cat size_tuple /= ltn_ord. Qed. Lemma tnth_rshift j : tnth [tuple of t1 ++ t2] (rshift n1 j) = tnth t2 j. Proof. have x0 := tnth_default t2 j; rewrite !(tnth_nth x0). by rewrite nth_cat size_tuple ltnNge leq_addr /= addKn. Qed. End tnth_shift. Section TupleQuantifiers. Variables (n : nat) (T : Type). Implicit Types (a : pred T) (t : n.-tuple T). Lemma forallb_tnth a t : [forall i, a (tnth t i)] = all a t. Proof. apply: negb_inj; rewrite -has_predC -has_map negb_forall. apply/existsP/(has_nthP true) => [[i a_t_i] | [i lt_i_n a_t_i]]. by exists i; rewrite ?size_tuple // -tnth_nth tnth_map. rewrite size_tuple in lt_i_n; exists (Ordinal lt_i_n). by rewrite -tnth_map (tnth_nth true). Qed. Lemma existsb_tnth a t : [exists i, a (tnth t i)] = has a t. Proof. by apply: negb_inj; rewrite negb_exists -all_predC -forallb_tnth. Qed. Lemma all_tnthP a t : reflect (forall i, a (tnth t i)) (all a t). Proof. by rewrite -forallb_tnth; apply: forallP. Qed. Lemma has_tnthP a t : reflect (exists i, a (tnth t i)) (has a t). Proof. by rewrite -existsb_tnth; apply: existsP. Qed. End TupleQuantifiers. Arguments all_tnthP {n T a t}. Arguments has_tnthP {n T a t}. Section EqTuple. Variables (n : nat) (T : eqType). HB.instance Definition _ : hasDecEq (n.-tuple T) := [Equality of n.-tuple T by <:]. Canonical tuple_predType := PredType (pred_of_seq : n.-tuple T -> pred T). Lemma eqEtuple (t1 t2 : n.-tuple T) : (t1 == t2) = [forall i, tnth t1 i == tnth t2 i]. Proof. by apply/eqP/'forall_eqP => [->|/eq_from_tnth]. Qed. Lemma memtE (t : n.-tuple T) : mem t = mem (tval t). Proof. by []. Qed. Lemma mem_tnth i (t : n.-tuple T) : tnth t i \in t. Proof. by rewrite mem_nth ?size_tuple. Qed. Lemma memt_nth x0 (t : n.-tuple T) i : i < n -> nth x0 t i \in t. Proof. by move=> i_lt_n; rewrite mem_nth ?size_tuple. Qed. Lemma tnthP (t : n.-tuple T) x : reflect (exists i, x = tnth t i) (x \in t). Proof. apply: (iffP idP) => [/(nthP x)[i ltin <-] | [i ->]]; last exact: mem_tnth. by rewrite size_tuple in ltin; exists (Ordinal ltin); rewrite (tnth_nth x). Qed. Lemma seq_tnthP (s : seq T) x : x \in s -> {i | x = tnth (in_tuple s) i}. Proof. move=> s_x; pose i := index x s; have lt_i: i < size s by rewrite index_mem. by exists (Ordinal lt_i); rewrite (tnth_nth x) nth_index. Qed. Lemma tuple_uniqP (t : n.-tuple T) : reflect (injective (tnth t)) (uniq t). Proof. case: {+}n => [|m] in t *; first by rewrite tuple0; constructor => -[]. pose x0 := tnth t ord0; apply/(equivP (uniqP x0)); split=> tinj i j. by rewrite !(tnth_nth x0) => /tinj/val_inj; apply; rewrite size_tuple inE. rewrite !size_tuple !inE => im jm; have := tinj (Ordinal im) (Ordinal jm). by rewrite !(tnth_nth x0) => /[apply]-[]. Qed. End EqTuple. HB.instance Definition _ n (T : choiceType) := [Choice of n.-tuple T by <:]. HB.instance Definition _ n (T : countType) := [Countable of n.-tuple T by <:]. Module Type FinTupleSig. Section FinTupleSig. Variables (n : nat) (T : finType). Parameter enum : seq (n.-tuple T). Axiom enumP : Finite.axiom enum. Axiom size_enum : size enum = #|T| ^ n. End FinTupleSig. End FinTupleSig. Module FinTuple : FinTupleSig. Section FinTuple. Variables (n : nat) (T : finType). Definition enum : seq (n.-tuple T) := let extend e := flatten (codom (fun x => map (cons x) e)) in pmap insub (iter n extend [::[::]]). Lemma enumP : Finite.axiom enum. Proof. case=> /= t t_n; rewrite -(count_map _ (pred1 t)) (pmap_filter (insubK _)). rewrite count_filter -(@eq_count _ (pred1 t)) => [|s /=]; last first. by rewrite isSome_insub; case: eqP=> // ->. elim: n t t_n => [|m IHm] [|x t] //= {}/IHm; move: (iter m _ _) => em IHm. transitivity (x \in T : nat); rewrite // -mem_enum codomE. elim: (fintype.enum T) (enum_uniq T) => //= y e IHe /andP[/negPf ney]. rewrite count_cat count_map inE /preim /= [in LHS]/eq_op /= eq_sym => /IHe->. by case: eqP => [->|_]; rewrite ?(ney, count_pred0, IHm). Qed. Lemma size_enum : size enum = #|T| ^ n. Proof. rewrite /= cardE size_pmap_sub; elim: n => //= m IHm. rewrite expnS /codom /image_mem; elim: {2 3}(fintype.enum T) => //= x e IHe. by rewrite count_cat {}IHe count_map IHm. Qed. End FinTuple. End FinTuple. Section UseFinTuple. Variables (n : nat) (T : finType). (* tuple_finMixin could, in principle, be made Canonical to allow for folding *) (* Finite.enum of a finite tuple type (see comments around eqE in eqtype.v), *) (* but in practice it will not work because the mixin_enum projector *) (* has been buried under an opaque alias, to avoid some performance issues *) (* during type inference. *) HB.instance Definition _ := isFinite.Build (n.-tuple T) (@FinTuple.enumP n T). Lemma card_tuple : #|{:n.-tuple T}| = #|T| ^ n. Proof. by rewrite [#|_|]cardT enumT unlock FinTuple.size_enum. Qed. Lemma enum_tupleP (A : {pred T}) : size (enum A) == #|A|. Proof. by rewrite -cardE. Qed. Canonical enum_tuple A := Tuple (enum_tupleP A). Definition ord_tuple : n.-tuple 'I_n := Tuple (introT eqP (size_enum_ord n)). Lemma val_ord_tuple : val ord_tuple = enum 'I_n. Proof. by []. Qed. Lemma tuple_map_ord U (t : n.-tuple U) : t = [tuple of map (tnth t) ord_tuple]. Proof. by apply: val_inj => /=; rewrite map_tnth_enum. Qed. Lemma tnth_ord_tuple i : tnth ord_tuple i = i. Proof. apply: val_inj; rewrite (tnth_nth i) -(nth_map _ 0) ?size_tuple //. by rewrite /= enumT unlock val_ord_enum nth_iota. Qed. Section ImageTuple. Variables (T' : Type) (f : T -> T') (A : {pred T}). Canonical image_tuple : #|A|.-tuple T' := [tuple of image f A]. Canonical codom_tuple : #|T|.-tuple T' := [tuple of codom f]. End ImageTuple. Section MkTuple. Variables (T' : Type) (f : 'I_n -> T'). Definition mktuple := map_tuple f ord_tuple. Lemma tnth_mktuple i : tnth mktuple i = f i. Proof. by rewrite tnth_map tnth_ord_tuple. Qed. Lemma nth_mktuple x0 (i : 'I_n) : nth x0 mktuple i = f i. Proof. by rewrite -tnth_nth tnth_mktuple. Qed. End MkTuple. Lemma eq_mktuple T' (f1 f2 : 'I_n -> T') : f1 =1 f2 -> mktuple f1 = mktuple f2. Proof. by move=> eq_f; apply eq_from_tnth=> i; rewrite !tnth_map eq_f. Qed. End UseFinTuple. Notation "[ 'tuple' F | i < n ]" := (mktuple (fun i : 'I_n => F)) (i at level 0, format "[ '[hv' 'tuple' F '/' | i < n ] ']'") : form_scope. Arguments eq_mktuple {n T'} [f1] f2 eq_f12. Section BseqDef. Variables (n : nat) (T : Type). Structure bseq_of : Type := Bseq {bseqval :> seq T; _ : size bseqval <= n}. HB.instance Definition _ := [isSub for bseqval]. Implicit Type bs : bseq_of. Lemma size_bseq bs : size bs <= n. Proof. by case: bs. Qed. Definition bseq bs mkB : bseq_of := mkB (let: Bseq _ bsP := bs return size bs <= n in bsP). Lemma bseqE bs : bseq (fun sP => @Bseq bs sP) = bs. Proof. by case: bs. Qed. End BseqDef. Canonical nil_bseq n T := Bseq (isT : @size T [::] <= n). Canonical cons_bseq n T x (t : bseq_of n T) := Bseq (valP t : size (x :: t) <= n.+1). Notation "n .-bseq" := (bseq_of n) (format "n .-bseq") : type_scope. Notation "{ 'bseq' n 'of' T }" := (n.-bseq T : predArgType) (only parsing) : type_scope. Notation "[ 'bseq' 'of' s ]" := (bseq (fun sP => @Bseq _ _ s sP)) (format "[ 'bseq' 'of' s ]") : form_scope. Notation "[ 'bseq' x1 ; .. ; xn ]" := [bseq of x1 :: .. [:: xn] ..] (format "[ 'bseq' '[' x1 ; '/' .. ; '/' xn ']' ]") : form_scope. Notation "[ 'bseq' ]" := [bseq of [::]] (format "[ 'bseq' ]") : form_scope. Coercion bseq_of_tuple n T (t : n.-tuple T) : n.-bseq T := Bseq (eq_leq (size_tuple t)). Definition insub_bseq n T (s : seq T) : n.-bseq T := insubd [bseq] s. Lemma size_insub_bseq n T (s : seq T) : size (insub_bseq n s) <= size s. Proof. by rewrite /insub_bseq /insubd; case: insubP => // ? ? ->. Qed. Section CastBseq. Variable T : Type. Definition in_bseq (s : seq T) : (size s).-bseq T := Bseq (leqnn (size s)). Definition cast_bseq m n (eq_mn : m = n) bs := let: erefl in _ = n := eq_mn return n.-bseq T in bs. Definition widen_bseq m n (lemn : m <= n) (bs : m.-bseq T) : n.-bseq T := @Bseq n T bs (leq_trans (size_bseq bs) lemn). Lemma cast_bseq_id n (eq_nn : n = n) bs : cast_bseq eq_nn bs = bs. Proof. by rewrite (eq_axiomK eq_nn). Qed. Lemma cast_bseqK m n (eq_mn : m = n) : cancel (cast_bseq eq_mn) (cast_bseq (esym eq_mn)). Proof. by case: n / eq_mn. Qed. Lemma cast_bseqKV m n (eq_mn : m = n) : cancel (cast_bseq (esym eq_mn)) (cast_bseq eq_mn). Proof. by case: n / eq_mn. Qed. Lemma cast_bseq_trans m n p (eq_mn : m = n) (eq_np : n = p) bs : cast_bseq (etrans eq_mn eq_np) bs = cast_bseq eq_np (cast_bseq eq_mn bs). Proof. by case: n / eq_mn eq_np; case: p /. Qed. Lemma size_cast_bseq m n (eq_mn : m = n) (bs : m.-bseq T) : size (cast_bseq eq_mn bs) = size bs. Proof. by case: n / eq_mn. Qed. Lemma widen_bseq_id n (lenn : n <= n) (bs : n.-bseq T) : widen_bseq lenn bs = bs. Proof. exact: val_inj. Qed. Lemma cast_bseqEwiden m n (eq_mn : m = n) (bs : m.-bseq T) : cast_bseq eq_mn bs = widen_bseq (eq_leq eq_mn) bs. Proof. by case: n / eq_mn; rewrite widen_bseq_id. Qed. Lemma widen_bseqK m n (lemn : m <= n) (lenm : n <= m) : cancel (@widen_bseq m n lemn) (widen_bseq lenm). Proof. by move=> t; apply: val_inj. Qed. Lemma widen_bseq_trans m n p (lemn : m <= n) (lenp : n <= p) (bs : m.-bseq T) : widen_bseq (leq_trans lemn lenp) bs = widen_bseq lenp (widen_bseq lemn bs). Proof. exact/val_inj. Qed. Lemma size_widen_bseq m n (lemn : m <= n) (bs : m.-bseq T) : size (widen_bseq lemn bs) = size bs. Proof. by []. Qed. Lemma in_bseqE s : in_bseq s = s :> seq T. Proof. by []. Qed. Lemma widen_bseq_in_bseq n (bs : n.-bseq T) : widen_bseq (size_bseq bs) (in_bseq bs) = bs. Proof. exact: val_inj. Qed. End CastBseq. Section SeqBseq. Variables (n m : nat) (T U rT : Type). Implicit Type s : n.-bseq T. Lemma rcons_bseqP s x : size (rcons s x) <= n.+1. Proof. by rewrite size_rcons ltnS size_bseq. Qed. Canonical rcons_bseq s x := Bseq (rcons_bseqP s x). Lemma behead_bseqP s : size (behead s) <= n.-1. Proof. rewrite size_behead -!subn1; apply/leq_sub2r/size_bseq. Qed. Canonical behead_bseq s := Bseq (behead_bseqP s). Lemma belast_bseqP x s : size (belast x s) <= n. Proof. by rewrite size_belast; apply/size_bseq. Qed. Canonical belast_bseq x s := Bseq (belast_bseqP x s). Lemma cat_bseqP s (s' : m.-bseq T) : size (s ++ s') <= n + m. Proof. by rewrite size_cat; apply/leq_add/size_bseq/size_bseq. Qed. Canonical cat_bseq s (s' : m.-bseq T) := Bseq (cat_bseqP s s'). Lemma take_bseqP s : size (take m s) <= n. Proof. by rewrite size_take_min (leq_trans _ (size_bseq s)) // geq_minr. Qed. Canonical take_bseq s := Bseq (take_bseqP s). Lemma drop_bseqP s : size (drop m s) <= n - m. Proof. by rewrite size_drop; apply/leq_sub2r/size_bseq. Qed. Canonical drop_bseq s := Bseq (drop_bseqP s). Lemma rev_bseqP s : size (rev s) <= n. Proof. by rewrite size_rev size_bseq. Qed. Canonical rev_bseq s := Bseq (rev_bseqP s). Lemma rot_bseqP s : size (rot m s) <= n. Proof. by rewrite size_rot size_bseq. Qed. Canonical rot_bseq s := Bseq (rot_bseqP s). Lemma rotr_bseqP s : size (rotr m s) <= n. Proof. by rewrite size_rotr size_bseq. Qed. Canonical rotr_bseq s := Bseq (rotr_bseqP s). Lemma map_bseqP f s : @size rT (map f s) <= n. Proof. by rewrite size_map size_bseq. Qed. Canonical map_bseq f s := Bseq (map_bseqP f s). Lemma scanl_bseqP f x s : @size rT (scanl f x s) <= n. Proof. by rewrite size_scanl size_bseq. Qed. Canonical scanl_bseq f x s := Bseq (scanl_bseqP f x s). Lemma pairmap_bseqP f x s : @size rT (pairmap f x s) <= n. Proof. by rewrite size_pairmap size_bseq. Qed. Canonical pairmap_bseq f x s := Bseq (pairmap_bseqP f x s). Lemma allpairs_bseqP f s (s' : m.-bseq U) : @size rT (allpairs f s s') <= n * m. Proof. by rewrite size_allpairs; apply/leq_mul/size_bseq/size_bseq. Qed. Canonical allpairs_bseq f s (s' : m.-bseq U) := Bseq (allpairs_bseqP f s s'). Lemma sort_bseqP r s : size (sort r s) <= n. Proof. by rewrite size_sort size_bseq. Qed. Canonical sort_bseq r s := Bseq (sort_bseqP r s). Lemma bseq0 : all_equal_to ([bseq] : 0.-bseq T). Proof. by move=> s; apply: val_inj; case: s => [[]]. Qed. End SeqBseq. HB.instance Definition bseq_hasDecEq n (T : eqType) := [Equality of n.-bseq T by <:]. Canonical bseq_predType n (T : eqType) := Eval hnf in PredType (fun t : n.-bseq T => mem_seq t). Lemma membsE n (T : eqType) (bs : n.-bseq T) : mem bs = mem (bseqval bs). Proof. by []. Qed. HB.instance Definition bseq_hasChoice n (T : choiceType) := [Choice of n.-bseq T by <:]. HB.instance Definition bseq_isCountable n (T : countType) := [Countable of n.-bseq T by <:]. Definition bseq_tagged_tuple n T (s : n.-bseq T) : {k : 'I_n.+1 & k.-tuple T} := Tagged _ (in_tuple s : (Ordinal (size_bseq s : size s < n.+1)).-tuple _). Arguments bseq_tagged_tuple {n T}. Definition tagged_tuple_bseq n T (t : {k : 'I_n.+1 & k.-tuple T}) : n.-bseq T := widen_bseq (leq_ord (tag t)) (tagged t). Arguments tagged_tuple_bseq {n T}. Lemma bseq_tagged_tupleK {n T} : cancel (@bseq_tagged_tuple n T) tagged_tuple_bseq. Proof. by move=> bs; apply/val_inj. Qed. Lemma tagged_tuple_bseqK {n T} : cancel (@tagged_tuple_bseq n T) bseq_tagged_tuple. Proof. move=> [[k lt_kn] t]; apply: eq_existT_curried => [|k_eq]; apply/val_inj. by rewrite /= size_tuple. by refine (let: erefl := k_eq in _). Qed. Lemma bseq_tagged_tuple_bij {n T} : bijective (@bseq_tagged_tuple n T). Proof. exact/Bijective/tagged_tuple_bseqK/bseq_tagged_tupleK. Qed. Lemma tagged_tuple_bseq_bij {n T} : bijective (@tagged_tuple_bseq n T). Proof. exact/Bijective/bseq_tagged_tupleK/tagged_tuple_bseqK. Qed. #[global] Hint Resolve bseq_tagged_tuple_bij tagged_tuple_bseq_bij : core. #[non_forgetful_inheritance] HB.instance Definition _ n (T : finType) := isFinite.Build (n.-bseq T) (pcan_enumP (can_pcan (@bseq_tagged_tupleK n T))).
Basic.lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Control.Bifunctor import Mathlib.Control.Traversable.Basic /-! # Bitraversable type class Type class for traversing bifunctors. Simple examples of `Bitraversable` are `Prod` and `Sum`. A more elaborate example is to define an a-list as: ``` def AList (key val : Type) := List (key × val) ``` Then we can use `f : key → IO key'` and `g : val → IO val'` to manipulate the `AList`'s key and value respectively with `Bitraverse f g : AList key val → IO (AList key' val')`. ## Main definitions * `Bitraversable`: Bare typeclass to hold the `Bitraverse` function. * `LawfulBitraversable`: Typeclass for the laws of the `Bitraverse` function. Similar to `LawfulTraversable`. ## References The concepts and laws are taken from <https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Bitraversable.html> ## Tags traversable bitraversable iterator functor bifunctor applicative -/ universe u /-- Lawless bitraversable bifunctor. This only holds data for the bimap and bitraverse. -/ class Bitraversable (t : Type u → Type u → Type u) extends Bifunctor t where bitraverse : ∀ {m : Type u → Type u} [Applicative m] {α α' β β'}, (α → m α') → (β → m β') → t α β → m (t α' β') export Bitraversable (bitraverse) /-- A bitraversable functor commutes with all applicative functors. -/ def bisequence {t m} [Bitraversable t] [Applicative m] {α β} : t (m α) (m β) → m (t α β) := bitraverse id id open Functor /-- Bifunctor. This typeclass asserts that a lawless bitraversable bifunctor is lawful. -/ class LawfulBitraversable (t : Type u → Type u → Type u) [Bitraversable t] : Prop extends LawfulBifunctor t where id_bitraverse : ∀ {α β} (x : t α β), (bitraverse pure pure x : Id _) = pure x comp_bitraverse : ∀ {F G} [Applicative F] [Applicative G] [LawfulApplicative F] [LawfulApplicative G] {α α' β β' γ γ'} (f : β → F γ) (f' : β' → F γ') (g : α → G β) (g' : α' → G β') (x : t α α'), bitraverse (Comp.mk ∘ map f ∘ g) (Comp.mk ∘ map f' ∘ g') x = Comp.mk (bitraverse f f' <$> bitraverse g g' x) bitraverse_eq_bimap_id : ∀ {α α' β β'} (f : α → β) (f' : α' → β') (x : t α α'), bitraverse (m := Id) (pure ∘ f) (pure ∘ f') x = pure (bimap f f' x) binaturality : ∀ {F G} [Applicative F] [Applicative G] [LawfulApplicative F] [LawfulApplicative G] (η : ApplicativeTransformation F G) {α α' β β'} (f : α → F β) (f' : α' → F β') (x : t α α'), η (bitraverse f f' x) = bitraverse (@η _ ∘ f) (@η _ ∘ f') x export LawfulBitraversable (id_bitraverse comp_bitraverse bitraverse_eq_bimap_id) open LawfulBitraversable attribute [higher_order bitraverse_id_id] id_bitraverse attribute [higher_order bitraverse_comp] comp_bitraverse attribute [higher_order] binaturality bitraverse_eq_bimap_id export LawfulBitraversable (bitraverse_id_id bitraverse_comp)
Submodule.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Module.Submodule.Pointwise import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Localization.Module import Mathlib.Algebra.Algebra.Operations /-! # Localization of Submodules Results about localizations of submodules and quotient modules are provided in this file. ## Main results - `Submodule.localized`: The localization of an `R`-submodule of `M` at `p` viewed as an `Rₚ`-submodule of `Mₚ`. A direct consequence of this is that `Rₚ` is flat over `R, see `IsLocalization.flat`. - `Submodule.toLocalized`: The localization map of a submodule `M' →ₗ[R] M'.localized p`. - `Submodule.toLocalizedQuotient`: The localization map of a quotient module `M ⧸ M' →ₗ[R] LocalizedModule p M ⧸ M'.localized p`. ## TODO - Statements regarding the exactness of localization. -/ open nonZeroDivisors variable {R S M N : Type*} variable (S) [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [AddCommMonoid N] variable [Module R M] [Module R N] [Algebra R S] [Module S N] [IsScalarTower R S N] variable (p : Submonoid R) [IsLocalization p S] (f : M →ₗ[R] N) [IsLocalizedModule p f] variable (M' : Submodule R M) namespace Submodule /-- Let `N` be a localization of an `R`-module `M` at `p`. This is the localization of an `R`-submodule of `M` viewed as an `R`-submodule of `N`. -/ def localized₀ : Submodule R N where carrier := { x | ∃ m ∈ M', ∃ s : p, IsLocalizedModule.mk' f m s = x } add_mem' := fun {x y} ⟨m, hm, s, hx⟩ ⟨n, hn, t, hy⟩ ↦ ⟨t • m + s • n, add_mem (M'.smul_mem t hm) (M'.smul_mem s hn), s * t, by rw [← hx, ← hy, IsLocalizedModule.mk'_add_mk']⟩ zero_mem' := ⟨0, zero_mem _, 1, by simp⟩ smul_mem' r x := by rintro ⟨m, hm, s, hx⟩ exact ⟨r • m, smul_mem M' _ hm, s, by rw [IsLocalizedModule.mk'_smul, hx]⟩ /-- Let `S` be the localization of `R` at `p` and `N` be a localization of `M` at `p`. This is the localization of an `R`-submodule of `M` viewed as an `S`-submodule of `N`. -/ def localized' : Submodule S N where __ := localized₀ p f M' smul_mem' := fun r x ⟨m, hm, s, hx⟩ ↦ by have ⟨y, t, hyt⟩ := IsLocalization.mk'_surjective p r exact ⟨y • m, M'.smul_mem y hm, t * s, by simp [← hyt, ← hx, IsLocalizedModule.mk'_smul_mk']⟩ lemma mem_localized₀ (x : N) : x ∈ localized₀ p f M' ↔ ∃ m ∈ M', ∃ s : p, IsLocalizedModule.mk' f m s = x := Iff.rfl lemma mem_localized' (x : N) : x ∈ localized' S p f M' ↔ ∃ m ∈ M', ∃ s : p, IsLocalizedModule.mk' f m s = x := Iff.rfl /-- `localized₀` is the same as `localized'` considered as a submodule over the base ring. -/ lemma restrictScalars_localized' : (localized' S p f M').restrictScalars R = localized₀ p f M' := rfl theorem localized'_eq_span : localized' S p f M' = span S (f '' M') := by refine le_antisymm ?_ (span_le.mpr <| by rintro _ ⟨m, hm, rfl⟩; exact ⟨m, hm, 1, by simp⟩) rintro _ ⟨m, hm, s, rfl⟩ rw [← one_smul R m, ← mul_one s, ← IsLocalizedModule.mk'_smul_mk' S] exact smul_mem _ _ (subset_span ⟨m, hm, by simp⟩) /-- The Galois insertion between `Submodule R M` and `Submodule S N`, where `S` is the localization of `R` at `p` and `N` is the localization of `M` at `p`. -/ def localized'gi : GaloisInsertion (localized' S p f) (comap f <| ·.restrictScalars R) where gc M' N' := ⟨fun h m hm ↦ h ⟨m, hm, 1, by simp⟩, fun h ↦ by rw [localized'_eq_span, span_le]; apply map_le_iff_le_comap.mpr h⟩ le_l_u N' n hn := by obtain ⟨⟨m, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective p f n refine ⟨m, ?_, s, rfl⟩ rw [mem_comap, restrictScalars_mem, ← IsLocalizedModule.mk'_cancel' _ _ s, Submonoid.smul_def, ← algebraMap_smul S] exact smul_mem _ _ hn choice x _ := localized' S p f x choice_eq _ _ := rfl /-- The localization of an `R`-submodule of `M` at `p` viewed as an `Rₚ`-submodule of `Mₚ`. -/ noncomputable abbrev localized : Submodule (Localization p) (LocalizedModule p M) := M'.localized' (Localization p) p (LocalizedModule.mkLinearMap p M) @[simp] lemma localized₀_bot : (⊥ : Submodule R M).localized₀ p f = ⊥ := by rw [← le_bot_iff] rintro _ ⟨_, rfl, s, rfl⟩ simp only [IsLocalizedModule.mk'_zero, mem_bot] @[simp] lemma localized'_bot : (⊥ : Submodule R M).localized' S p f = ⊥ := SetLike.ext' (by apply SetLike.ext'_iff.mp <| Submodule.localized₀_bot p f) @[simp] lemma localized₀_top : (⊤ : Submodule R M).localized₀ p f = ⊤ := by rw [← top_le_iff] rintro x _ obtain ⟨⟨x, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective p f x exact ⟨x, trivial, s, rfl⟩ @[simp] lemma localized'_top : (⊤ : Submodule R M).localized' S p f = ⊤ := SetLike.ext' (by apply SetLike.ext'_iff.mp <| Submodule.localized₀_top p f) @[simp] lemma localized'_span (s : Set M) : (span R s).localized' S p f = span S (f '' s) := by rw [localized'_eq_span, ← map_coe, map_span, span_span_of_tower] lemma localized₀_smul (I : Submodule R R) : (I • M').localized₀ p f = I • M'.localized₀ p f := by apply le_antisymm · rintro _ ⟨a, ha, s, rfl⟩ refine Submodule.smul_induction_on ha ?_ ?_ · intro r hr n hn rw [IsLocalizedModule.mk'_smul] exact Submodule.smul_mem_smul hr ⟨n, hn, s, rfl⟩ · simp +contextual only [IsLocalizedModule.mk'_add, add_mem, implies_true] · refine Submodule.smul_le.mpr ?_ rintro r hr _ ⟨a, ha, s, rfl⟩ rw [← IsLocalizedModule.mk'_smul] exact ⟨_, Submodule.smul_mem_smul hr ha, s, rfl⟩ lemma restrictScalars_localized'_smul (I : Submodule R R) (N' : Submodule S N) : (I.localized' S p (Algebra.linearMap R S) • N').restrictScalars R = I • N'.restrictScalars R := by refine le_antisymm (fun x hx ↦ ?_) (Submodule.smul_le.mpr fun r hr n hn ↦ ?_) · refine smul_induction_on ((Submodule.restrictScalars_mem _ _ _).mp hx) ?_ fun _ _ ↦ add_mem rintro _ ⟨r, hr, s, rfl⟩ n hn rw [← IsLocalization.mk'_eq_mk', IsLocalization.mk'_eq_mul_mk'_one, mul_smul, algebraMap_smul] exact smul_mem_smul hr ((Submodule.restrictScalars_mem _ _ _).mpr <| smul_mem _ _ hn) · rw [← algebraMap_smul S, Submodule.restrictScalars_mem] exact Submodule.smul_mem_smul ⟨_, hr, 1, by simp⟩ hn lemma localized'_smul (I : Submodule R R) : (I • M').localized' S p f = I.localized' S p (Algebra.linearMap R S) • M'.localized' S p f := Submodule.restrictScalars_injective R _ _ <| by simp_rw [restrictScalars_localized'_smul, restrictScalars_localized', localized₀_smul] /-- The localization map of a submodule. -/ @[simps!] def toLocalized₀ : M' →ₗ[R] M'.localized₀ p f := f.restrict fun x hx ↦ ⟨x, hx, 1, by simp⟩ /-- The localization map of a submodule. -/ @[simps!] def toLocalized' : M' →ₗ[R] M'.localized' S p f := toLocalized₀ p f M' /-- The localization map of a submodule. -/ noncomputable abbrev toLocalized : M' →ₗ[R] M'.localized p := M'.toLocalized' (Localization p) p (LocalizedModule.mkLinearMap p M) instance : IsLocalizedModule p (M'.toLocalized₀ p f) where map_units x := by simp_rw [Module.End.isUnit_iff] constructor · exact fun _ _ e ↦ Subtype.ext (IsLocalizedModule.smul_injective f x (congr_arg Subtype.val e)) · rintro ⟨_, m, hm, s, rfl⟩ refine ⟨⟨IsLocalizedModule.mk' f m (s * x), ⟨_, hm, _, rfl⟩⟩, Subtype.ext ?_⟩ rw [Module.algebraMap_end_apply, SetLike.val_smul_of_tower, ← IsLocalizedModule.mk'_smul, ← Submonoid.smul_def, IsLocalizedModule.mk'_cancel_right] surj' := by rintro ⟨y, x, hx, s, rfl⟩ exact ⟨⟨⟨x, hx⟩, s⟩, by ext; simp⟩ exists_of_eq e := by simpa [Subtype.ext_iff] using IsLocalizedModule.exists_of_eq (S := p) (f := f) (congr_arg Subtype.val e) instance isLocalizedModule : IsLocalizedModule p (M'.toLocalized' S p f) := inferInstanceAs (IsLocalizedModule p (M'.toLocalized₀ p f)) /-- The canonical isomorphism between the localization of a submodule and its realization as a submodule in the localized module. -/ noncomputable def localizedEquiv : M'.localized p ≃ₗ[Localization p] LocalizedModule p M' := have := IsLocalization.linearMap_compatibleSMul p IsLocalizedModule.linearEquiv p (M'.toLocalized p) (LocalizedModule.mkLinearMap _ _) |>.restrictScalars _ open Pointwise lemma localized₀_le_localized₀_of_smul_le {P Q : Submodule R M} (x : p) (h : x • P ≤ Q) : P.localized₀ p f ≤ Q.localized₀ p f := by rintro - ⟨a, ha, r, rfl⟩ refine ⟨x • a, h ⟨a, ha, rfl⟩, x * r, ?_⟩ simp lemma localized'_le_localized'_of_smul_le {P Q : Submodule R M} (x : p) (h : x • P ≤ Q) : P.localized' S p f ≤ Q.localized' S p f := localized₀_le_localized₀_of_smul_le p f x h end Submodule section Quotient variable {R S M N : Type*} variable (S) [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] [Algebra R S] [Module S N] [IsScalarTower R S N] variable (p : Submonoid R) [IsLocalization p S] (f : M →ₗ[R] N) [IsLocalizedModule p f] variable (M' : Submodule R M) /-- The localization map of a quotient module. -/ def Submodule.toLocalizedQuotient' : M ⧸ M' →ₗ[R] N ⧸ M'.localized' S p f := Submodule.mapQ M' ((M'.localized' S p f).restrictScalars R) f (fun x hx ↦ ⟨x, hx, 1, by simp⟩) /-- The localization map of a quotient module. -/ noncomputable abbrev Submodule.toLocalizedQuotient : M ⧸ M' →ₗ[R] LocalizedModule p M ⧸ M'.localized p := M'.toLocalizedQuotient' (Localization p) p (LocalizedModule.mkLinearMap p M) @[simp] lemma Submodule.toLocalizedQuotient'_mk (x : M) : M'.toLocalizedQuotient' S p f (Submodule.Quotient.mk x) = Submodule.Quotient.mk (f x) := rfl open Submodule Submodule.Quotient IsLocalization in instance IsLocalizedModule.toLocalizedQuotient' (M' : Submodule R M) : IsLocalizedModule p (M'.toLocalizedQuotient' S p f) where map_units x := by refine (Module.End.isUnit_iff _).mpr ⟨fun m n e ↦ ?_, fun m ↦ ⟨(IsLocalization.mk' S 1 x) • m, by rw [Module.algebraMap_end_apply, ← smul_assoc, smul_mk'_one, mk'_self', one_smul]⟩⟩ obtain ⟨⟨m, rfl⟩, n, rfl⟩ := PProd.mk (mk_surjective _ m) (mk_surjective _ n) simp only [Module.algebraMap_end_apply, ← mk_smul, Submodule.Quotient.eq, ← smul_sub] at e replace e := Submodule.smul_mem _ (IsLocalization.mk' S 1 x) e rwa [smul_comm, ← smul_assoc, smul_mk'_one, mk'_self', one_smul, ← Submodule.Quotient.eq] at e surj' y := by obtain ⟨y, rfl⟩ := mk_surjective _ y obtain ⟨⟨y, s⟩, rfl⟩ := IsLocalizedModule.mk'_surjective p f y exact ⟨⟨Submodule.Quotient.mk y, s⟩, by simp only [Function.uncurry_apply_pair, toLocalizedQuotient'_mk, ← mk_smul, mk'_cancel']⟩ exists_of_eq {m n} e := by obtain ⟨⟨m, rfl⟩, n, rfl⟩ := PProd.mk (mk_surjective _ m) (mk_surjective _ n) obtain ⟨x, hx, s, hs⟩ : f (m - n) ∈ _ := by simpa [Submodule.Quotient.eq] using e obtain ⟨c, hc⟩ := exists_of_eq (S := p) (show f (s • (m - n)) = f x by simp [-map_sub, ← hs]) exact ⟨c * s, by simpa only [← Quotient.mk_smul, Submodule.Quotient.eq, ← smul_sub, mul_smul, hc] using M'.smul_mem c hx⟩ instance (M' : Submodule R M) : IsLocalizedModule p (M'.toLocalizedQuotient p) := IsLocalizedModule.toLocalizedQuotient' _ _ _ _ /-- The canonical isomorphism between the localization of a quotient module and its realization as a quotient of the localized module. -/ noncomputable def localizedQuotientEquiv : (LocalizedModule p M ⧸ M'.localized p) ≃ₗ[Localization p] LocalizedModule p (M ⧸ M') := have := IsLocalization.linearMap_compatibleSMul p IsLocalizedModule.linearEquiv p (M'.toLocalizedQuotient p) (LocalizedModule.mkLinearMap _ _) |>.restrictScalars _ end Quotient namespace LinearMap variable {P : Type*} [AddCommMonoid P] [Module R P] variable {Q : Type*} [AddCommMonoid Q] [Module R Q] [Module S Q] [IsScalarTower R S Q] variable (f' : P →ₗ[R] Q) [IsLocalizedModule p f'] open Submodule IsLocalizedModule lemma ker_localizedMap_eq_localized₀_ker (g : M →ₗ[R] P) : ker (map p f f' g) = (ker g).localized₀ p f := by ext x simp only [Submodule.mem_localized₀, mem_ker] refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨⟨a, b⟩, rfl⟩ := IsLocalizedModule.mk'_surjective p f x simp only [Function.uncurry_apply_pair, map_mk', mk'_eq_zero, eq_zero_iff p f'] at h obtain ⟨c, hc⟩ := h refine ⟨c • a, by simpa, c * b, by simp⟩ · rintro ⟨m, hm, a, ha, rfl⟩ simp [IsLocalizedModule.map_mk', hm] lemma localized'_ker_eq_ker_localizedMap (g : M →ₗ[R] P) : (ker g).localized' S p f = ker ((map p f f' g).extendScalarsOfIsLocalization p S) := SetLike.ext (by apply SetLike.ext_iff.mp (f.ker_localizedMap_eq_localized₀_ker p f' g).symm) lemma ker_localizedMap_eq_localized'_ker (g : M →ₗ[R] P) : ker (map p f f' g) = ((ker g).localized' S p f).restrictScalars _ := by ext simp [localized'_ker_eq_ker_localizedMap S p f f'] /-- The canonical map from the kernel of `g` to the kernel of `g` localized at a submonoid. This is a localization map by `LinearMap.toKerLocalized_isLocalizedModule`. -/ @[simps!] noncomputable def toKerIsLocalized (g : M →ₗ[R] P) : ker g →ₗ[R] ker (map p f f' g) := f.restrict (fun x hx ↦ by simp [mem_ker, mem_ker.mp hx]) include S in /-- The canonical map to the kernel of the localization of `g` is localizing. In other words, localization commutes with kernels. -/ lemma toKerLocalized_isLocalizedModule (g : M →ₗ[R] P) : IsLocalizedModule p (toKerIsLocalized p f f' g) := let e : Submodule.localized' S p f (ker g) ≃ₗ[S] ker ((map p f f' g).extendScalarsOfIsLocalization p S) := LinearEquiv.ofEq _ _ (localized'_ker_eq_ker_localizedMap S p f f' g) IsLocalizedModule.of_linearEquiv p (Submodule.toLocalized' S p f (ker g)) (e.restrictScalars R) lemma range_localizedMap_eq_localized₀_range (g : M →ₗ[R] P) : range (map p f f' g) = (range g).localized₀ p f' := by ext; simp [mem_localized₀, mem_range, (mk'_surjective p f).exists] /-- Localization commutes with ranges. -/ lemma localized'_range_eq_range_localizedMap (g : M →ₗ[R] P) : (range g).localized' S p f' = range ((map p f f' g).extendScalarsOfIsLocalization p S) := SetLike.ext (by apply SetLike.ext_iff.mp (f.range_localizedMap_eq_localized₀_range p f' g).symm) end LinearMap
TFAE.lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Reid Barton, Simon Hudon, Thomas Murrills, Mario Carneiro -/ import Qq import Mathlib.Data.Nat.Notation import Mathlib.Util.AtomM import Mathlib.Data.List.TFAE import Mathlib.Tactic.ExtendDoc /-! # The Following Are Equivalent (TFAE) This file provides the tactics `tfae_have` and `tfae_finish` for proving goals of the form `TFAE [P₁, P₂, ...]`. -/ namespace Mathlib.Tactic.TFAE /-! # Parsing and syntax We implement `tfae_have` in terms of a syntactic `have`. To support as much of the same syntax as possible, we recreate the parsers for `have`, except with the changes necessary for `tfae_have`. -/ open Lean.Parser Term namespace Parser /- An arrow of the form `←`, `→`, or `↔`. -/ private def impTo : Parser := leading_parser unicodeSymbol " → " " -> " private def impFrom : Parser := leading_parser unicodeSymbol " ← " " <- " private def impIff : Parser := leading_parser unicodeSymbol " ↔ " " <-> " private def impArrow : Parser := leading_parser impTo <|> impFrom <|> impIff /-- A `tfae_have` type specification, e.g. `1 ↔ 3` The numbers refer to the proposition at the corresponding position in the `TFAE` goal (starting at 1). -/ private def tfaeType := leading_parser num >> impArrow >> num /-! The following parsers are similar to those for `have` in `Lean.Parser.Term`, but instead of `optType`, we use `tfaeType := num >> impArrow >> num` (as a `tfae_have` invocation must always include this specification). Also, we disallow including extra binders, as that makes no sense in this context; we also include `" : "` after the binder to avoid breaking `tfae_have 1 → 2` syntax (which, unlike `have`, omits `" : "`). -/ /- We need this to ensure `<|>` in `tfaeHaveIdLhs` takes in the same number of syntax trees on each side. -/ private def binder := leading_parser ppSpace >> binderIdent >> " : " /- See `haveIdLhs`. We omit `many (ppSpace >> letIdBinder)`, as it makes no sense to add extra arguments to a `tfae_have` decl. -/ private def tfaeHaveIdLhs := leading_parser (binder <|> hygieneInfo) >> tfaeType /- See `haveIdDecl`. E.g. `h : 1 → 3 := term`. -/ private def tfaeHaveIdDecl := leading_parser (withAnonymousAntiquot := false) atomic (tfaeHaveIdLhs >> " := ") >> termParser /- See `haveEqnsDecl`. E.g. `h : 1 → 3 | p => f p`. -/ private def tfaeHaveEqnsDecl := leading_parser (withAnonymousAntiquot := false) tfaeHaveIdLhs >> matchAlts /- See `letPatDecl`. E.g. `⟨mp, mpr⟩ : 1 ↔ 3 := term`. -/ private def tfaeHavePatDecl := leading_parser (withAnonymousAntiquot := false) atomic (termParser >> pushNone >> " : " >> tfaeType >> " := ") >> termParser /- See `haveDecl`. Any of `tfaeHaveIdDecl`, `tfaeHavePatDecl`, or `tfaeHaveEqnsDecl`. -/ private def tfaeHaveDecl := leading_parser (withAnonymousAntiquot := false) tfaeHaveIdDecl <|> (ppSpace >> tfaeHavePatDecl) <|> tfaeHaveEqnsDecl end Parser open Parser /-- `tfae_have` introduces hypotheses for proving goals of the form `TFAE [P₁, P₂, ...]`. Specifically, `tfae_have i <arrow> j := ...` introduces a hypothesis of type `Pᵢ <arrow> Pⱼ` to the local context, where `<arrow>` can be `→`, `←`, or `↔`. Note that `i` and `j` are natural number indices (beginning at 1) used to specify the propositions `P₁, P₂, ...` that appear in the goal. ```lean4 example (h : P → R) : TFAE [P, Q, R] := by tfae_have 1 → 3 := h ... ``` The resulting context now includes `tfae_1_to_3 : P → R`. Once sufficient hypotheses have been introduced by `tfae_have`, `tfae_finish` can be used to close the goal. For example, ```lean4 example : TFAE [P, Q, R] := by tfae_have 1 → 2 := sorry /- proof of P → Q -/ tfae_have 2 → 1 := sorry /- proof of Q → P -/ tfae_have 2 ↔ 3 := sorry /- proof of Q ↔ R -/ tfae_finish ``` All features of `have` are supported by `tfae_have`, including naming, matching, destructuring, and goal creation. These are demonstrated below. ```lean4 example : TFAE [P, Q] := by -- assert `tfae_1_to_2 : P → Q`: tfae_have 1 → 2 := sorry -- assert `hpq : P → Q`: tfae_have hpq : 1 → 2 := sorry -- match on `p : P` and prove `Q` via `f p`: tfae_have 1 → 2 | p => f p -- assert `pq : P → Q`, `qp : Q → P`: tfae_have ⟨pq, qp⟩ : 1 ↔ 2 := sorry -- assert `h : P → Q`; `?a` is a new goal: tfae_have h : 1 → 2 := f ?a ... ``` -/ syntax (name := tfaeHave) "tfae_have " tfaeHaveDecl : tactic /-- `tfae_finish` is used to close goals of the form `TFAE [P₁, P₂, ...]` once a sufficient collection of hypotheses of the form `Pᵢ → Pⱼ` or `Pᵢ ↔ Pⱼ` have been introduced to the local context. `tfae_have` can be used to conveniently introduce these hypotheses; see `tfae_have`. Example: ```lean4 example : TFAE [P, Q, R] := by tfae_have 1 → 2 := sorry /- proof of P → Q -/ tfae_have 2 → 1 := sorry /- proof of Q → P -/ tfae_have 2 ↔ 3 := sorry /- proof of Q ↔ R -/ tfae_finish ``` -/ syntax (name := tfaeFinish) "tfae_finish" : tactic /-! # Setup -/ open List Lean Meta Expr Elab Tactic Mathlib.Tactic Qq /-- Extract a list of `Prop` expressions from an expression of the form `TFAE [P₁, P₂, ...]` as long as `[P₁, P₂, ...]` is an explicit list. -/ partial def getTFAEList (t : Expr) : MetaM (Q(List Prop) × List Q(Prop)) := do let .app tfae (l : Q(List Prop)) ← whnfR <|← instantiateMVars t | throwError "goal must be of the form TFAE [P₁, P₂, ...]" unless (← withNewMCtxDepth <| isDefEq tfae q(TFAE)) do throwError "goal must be of the form TFAE [P₁, P₂, ...]" return (l, ← getExplicitList l) where /-- Convert an expression representing an explicit list into a list of expressions. -/ getExplicitList (l : Q(List Prop)) : MetaM (List Q(Prop)) := do match l with | ~q([]) => return ([] : List Expr) | ~q($a :: $l') => return (a :: (← getExplicitList l')) | e => throwError "{e} must be an explicit list of propositions" /-! # Proof construction -/ variable (hyps : Array (ℕ × ℕ × Expr)) (atoms : Array Q(Prop)) /-- Uses depth-first search to find a path from `P` to `P'`. -/ partial def dfs (i j : ℕ) (P P' : Q(Prop)) (hP : Q($P)) : StateT (Std.HashSet ℕ) MetaM Q($P') := do if i == j then return hP modify (·.insert i) for (a, b, h) in hyps do if i == a then if !(← get).contains b then have Q := atoms[b]! have h : Q($P → $Q) := h try return ← dfs b j Q P' q($h $hP) catch _ => pure () failure /-- Prove an implication via depth-first traversal. -/ def proveImpl (i j : ℕ) (P P' : Q(Prop)) : MetaM Q($P → $P') := do try withLocalDeclD (← mkFreshUserName `h) P fun (h : Q($P)) => do mkLambdaFVars #[h] <|← dfs hyps atoms i j P P' h |>.run' {} catch _ => throwError "couldn't prove {P} → {P'}" /-- Generate a proof of `Chain (· → ·) P l`. We assume `P : Prop` and `l : List Prop`, and that `l` is an explicit list. -/ partial def proveChain (i : ℕ) (is : List ℕ) (P : Q(Prop)) (l : Q(List Prop)) : MetaM Q(Chain (· → ·) $P $l) := do match l with | ~q([]) => return q(Chain.nil) | ~q($P' :: $l') => -- `id` is a workaround for https://github.com/leanprover-community/quote4/issues/30 let i' :: is' := id is | unreachable! have cl' : Q(Chain (· → ·) $P' $l') := ← proveChain i' is' q($P') q($l') let p ← proveImpl hyps atoms i i' P P' return q(Chain.cons $p $cl') /-- Attempt to prove `getLastD l P' → P` given an explicit list `l`. -/ partial def proveGetLastDImpl (i i' : ℕ) (is : List ℕ) (P P' : Q(Prop)) (l : Q(List Prop)) : MetaM Q(getLastD $l $P' → $P) := do match l with | ~q([]) => proveImpl hyps atoms i' i P' P | ~q($P'' :: $l') => -- `id` is a workaround for https://github.com/leanprover-community/quote4/issues/30 let i'' :: is' := id is | unreachable! proveGetLastDImpl i i'' is' P P'' l' /-- Attempt to prove a statement of the form `TFAE [P₁, P₂, ...]`. -/ def proveTFAE (is : List ℕ) (l : Q(List Prop)) : MetaM Q(TFAE $l) := do match l with | ~q([]) => return q(tfae_nil) | ~q([$P]) => return q(tfae_singleton $P) | ~q($P :: $P' :: $l') => -- `id` is a workaround for https://github.com/leanprover-community/quote4/issues/30 let i :: i' :: is' := id is | unreachable! let c ← proveChain hyps atoms i (i'::is') P q($P' :: $l') let il ← proveGetLastDImpl hyps atoms i i' is' P P' l' return q(tfae_of_cycle $c $il) /-! # `tfae_have` components -/ /-- Construct a name for a hypothesis introduced by `tfae_have`. -/ def mkTFAEId : TSyntax ``tfaeType → MacroM Name | `(tfaeType|$i:num $arr:impArrow $j:num) => do let arr ← match arr with | `(impArrow| ← ) => pure "from" | `(impArrow| → ) => pure "to" | `(impArrow| ↔ ) => pure "iff" | _ => Macro.throwUnsupported return .mkSimple <| String.intercalate "_" ["tfae", s!"{i.getNat}", arr, s!"{j.getNat}"] | _ => Macro.throwUnsupported /-- Turn syntax for a given index into a natural number, as long as it lies between `1` and `maxIndex`. -/ def elabIndex (i : TSyntax `num) (maxIndex : ℕ) : MetaM ℕ := do let i' := i.getNat unless 1 ≤ i' && i' ≤ maxIndex do throwErrorAt i "{i} must be between 1 and {maxIndex}" return i' /-! # Tactic implementation -/ /-- Accesses the propositions at indices `i` and `j` of `tfaeList`, and constructs the expression `Pi <arr> Pj`, which will be the type of our `tfae_have` hypothesis -/ def elabTFAEType (tfaeList : List Q(Prop)) : TSyntax ``tfaeType → TermElabM Expr | stx@`(tfaeType|$i:num $arr:impArrow $j:num) => do let l := tfaeList.length let i' ← elabIndex i l let j' ← elabIndex j l let Pi := tfaeList[i'-1]! let Pj := tfaeList[j'-1]! /- TODO: this is a hack to show the types `Pi`, `Pj` on hover. See [Zulip](https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Pre-RFC.3A.20Forcing.20terms.20to.20be.20shown.20in.20hover.3F). -/ Term.addTermInfo' i q(sorry : $Pi) Pi Term.addTermInfo' j q(sorry : $Pj) Pj let (ty : Q(Prop)) ← match arr with | `(impArrow| ← ) => pure q($Pj → $Pi) | `(impArrow| → ) => pure q($Pi → $Pj) | `(impArrow| ↔ ) => pure q($Pi ↔ $Pj) | _ => throwUnsupportedSyntax Term.addTermInfo' stx q(sorry : $ty) ty return ty | _ => throwUnsupportedSyntax /- Convert `tfae_have i <arr> j ...` to `tfae_have tfae_i_arr_j : i <arr> j ...`. See `expandHave`, which is responsible for inserting `this` in `have : A := ...`. -/ macro_rules | `(tfaeHave|tfae_have $hy:hygieneInfo $t:tfaeType := $val) => do let id := HygieneInfo.mkIdent hy (← mkTFAEId t) (canonical := true) `(tfaeHave|tfae_have $id : $t := $val) | `(tfaeHave|tfae_have $hy:hygieneInfo $t:tfaeType $alts:matchAlts) => do let id := HygieneInfo.mkIdent hy (← mkTFAEId t) (canonical := true) `(tfaeHave|tfae_have $id : $t $alts) open Term elab_rules : tactic | `(tfaeHave|tfae_have $d:tfaeHaveDecl) => withMainContext do let goal ← getMainGoal let (_, tfaeList) ← getTFAEList (← goal.getType) withRef d do match d with | `(tfaeHaveDecl| $b : $t:tfaeType := $pf:term) => let type ← elabTFAEType tfaeList t evalTactic <|← `(tactic|have $b : $(← exprToSyntax type) := $pf) | `(tfaeHaveDecl| $b : $t:tfaeType $alts:matchAlts) => let type ← elabTFAEType tfaeList t evalTactic <|← `(tactic|have $b : $(← exprToSyntax type) $alts:matchAlts) | `(tfaeHaveDecl| $pat:term : $t:tfaeType := $pf:term) => let type ← elabTFAEType tfaeList t evalTactic <|← `(tactic|have $pat:term : $(← exprToSyntax type) := $pf) | _ => throwUnsupportedSyntax elab_rules : tactic | `(tactic| tfae_finish) => do let goal ← getMainGoal goal.withContext do let (tfaeListQ, tfaeList) ← getTFAEList (← goal.getType) closeMainGoal `tfae_finish <|← AtomM.run .reducible do let is ← tfaeList.mapM (fun e ↦ Prod.fst <$> AtomM.addAtom e) let mut hyps := #[] for hyp in ← getLocalHyps do let ty ← whnfR <|← instantiateMVars <|← inferType hyp if let (``Iff, #[p1, p2]) := ty.getAppFnArgs then let (q1, _) ← AtomM.addAtom p1 let (q2, _) ← AtomM.addAtom p2 hyps := hyps.push (q1, q2, ← mkAppM ``Iff.mp #[hyp]) hyps := hyps.push (q2, q1, ← mkAppM ``Iff.mpr #[hyp]) else if ty.isArrow then let (q1, _) ← AtomM.addAtom ty.bindingDomain! let (q2, _) ← AtomM.addAtom ty.bindingBody! hyps := hyps.push (q1, q2, hyp) proveTFAE hyps (← get).atoms is tfaeListQ end Mathlib.Tactic.TFAE /-! # Deprecated "Goal-style" `tfae_have` This syntax and its implementation, which behaves like "Mathlib `have`" is deprecated; we preserve it here to provide graceful deprecation behavior. -/ /-- Re-enables "goal-style" syntax for `tfae_have` when `true`. -/ register_option Mathlib.Tactic.TFAE.useDeprecated : Bool := { descr := "Re-enable \"goal-style\" 'tfae_have' syntax" defValue := false } namespace Mathlib.Tactic.TFAE open Lean Parser Meta Elab Tactic @[inherit_doc tfaeHave] syntax (name := tfaeHave') "tfae_have " tfaeHaveIdLhs : tactic extend_docs tfaeHave' before "\"Goal-style\" `tfae_have` syntax is deprecated. Now, `tfae_have ...` should be followed\ by `:= ...`; see below for the new behavior. This warning can be turned off with \ `set_option Mathlib.Tactic.TFAE.useDeprecated true`.\n\n***" elab_rules : tactic | `(tfaeHave'|tfae_have $d:tfaeHaveIdLhs) => withMainContext do -- Deprecate syntax: let ref ← getRef unless useDeprecated.get (← getOptions) do logWarning <| .tagged ``Linter.deprecatedAttr m!"\ \"Goal-style\" syntax '{ref}' is deprecated in favor of '{ref} := ...'.\n\n\ To turn this warning off, use set_option Mathlib.Tactic.TFAE.useDeprecated true" let goal ← getMainGoal let (_, tfaeList) ← getTFAEList (← goal.getType) let (b, t) ← liftMacroM <| match d with | `(tfaeHaveIdLhs| $hy:hygieneInfo $t:tfaeType) => do pure (HygieneInfo.mkIdent hy (← mkTFAEId t) (canonical := true), t) | `(tfaeHaveIdLhs| $b:ident : $t:tfaeType) => pure (b, t) | _ => Macro.throwUnsupported let n := b.getId let type ← elabTFAEType tfaeList t let p ← mkFreshExprMVar type MetavarKind.syntheticOpaque n let (fv, mainGoal) ← (← MVarId.assert goal n type p).intro1P mainGoal.withContext do Term.addTermInfo' (isBinder := true) b (mkFVar fv) replaceMainGoal [p.mvarId!, mainGoal] end TFAE end Mathlib.Tactic
Topology.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.Topology.Algebra.Module.Multilinear.Topology import Mathlib.Topology.Algebra.Module.Alternating.Basic /-! # Topology on continuous alternating maps In this file we define `UniformSpace` and `TopologicalSpace` structures on the space of continuous alternating maps between topological vector spaces. The structures are induced by those on `ContinuousMultilinearMap`s, and most of the lemmas follow from the corresponding lemmas about `ContinuousMultilinearMap`s. -/ open Bornology Function Set Topology open scoped UniformConvergence Filter namespace ContinuousAlternatingMap variable {𝕜 E F ι : Type*} [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [AddCommGroup F] [Module 𝕜 F] section IsClosedRange variable [TopologicalSpace F] [IsTopologicalAddGroup F] instance instTopologicalSpace : TopologicalSpace (E [⋀^ι]→L[𝕜] F) := .induced toContinuousMultilinearMap inferInstance lemma isClosed_range_toContinuousMultilinearMap [ContinuousSMul 𝕜 E] [T2Space F] : IsClosed (Set.range (toContinuousMultilinearMap : (E [⋀^ι]→L[𝕜] F) → ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ E) F)) := by simp only [range_toContinuousMultilinearMap, setOf_forall] repeat refine isClosed_iInter fun _ ↦ ?_ exact isClosed_singleton.preimage (continuous_eval_const _) end IsClosedRange section IsUniformAddGroup variable [UniformSpace F] [IsUniformAddGroup F] instance instUniformSpace : UniformSpace (E [⋀^ι]→L[𝕜] F) := .comap toContinuousMultilinearMap inferInstance lemma isUniformEmbedding_toContinuousMultilinearMap : IsUniformEmbedding (toContinuousMultilinearMap : (E [⋀^ι]→L[𝕜] F) → _) where injective := toContinuousMultilinearMap_injective comap_uniformity := rfl lemma uniformContinuous_toContinuousMultilinearMap : UniformContinuous (toContinuousMultilinearMap : (E [⋀^ι]→L[𝕜] F) → _) := isUniformEmbedding_toContinuousMultilinearMap.uniformContinuous theorem uniformContinuous_coe_fun [ContinuousSMul 𝕜 E] : UniformContinuous (DFunLike.coe : (E [⋀^ι]→L[𝕜] F) → (ι → E) → F) := ContinuousMultilinearMap.uniformContinuous_coe_fun.comp uniformContinuous_toContinuousMultilinearMap theorem uniformContinuous_eval_const [ContinuousSMul 𝕜 E] (x : ι → E) : UniformContinuous fun f : E [⋀^ι]→L[𝕜] F ↦ f x := uniformContinuous_pi.1 uniformContinuous_coe_fun x instance instIsUniformAddGroup : IsUniformAddGroup (E [⋀^ι]→L[𝕜] F) := isUniformEmbedding_toContinuousMultilinearMap.isUniformAddGroup (toContinuousMultilinearMapLinear (R := ℕ)) instance instUniformContinuousConstSMul {M : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass 𝕜 M F] [ContinuousConstSMul M F] : UniformContinuousConstSMul M (E [⋀^ι]→L[𝕜] F) := isUniformEmbedding_toContinuousMultilinearMap.uniformContinuousConstSMul fun _ _ ↦ rfl theorem isUniformInducing_postcomp {G : Type*} [AddCommGroup G] [UniformSpace G] [IsUniformAddGroup G] [Module 𝕜 G] (g : F →L[𝕜] G) (hg : IsUniformInducing g) : IsUniformInducing (g.compContinuousAlternatingMap : (E [⋀^ι]→L[𝕜] F) → (E [⋀^ι]→L[𝕜] G)) := by rw [← isUniformEmbedding_toContinuousMultilinearMap.1.of_comp_iff] exact (ContinuousMultilinearMap.isUniformInducing_postcomp g hg).comp isUniformEmbedding_toContinuousMultilinearMap.1 section CompleteSpace variable [ContinuousSMul 𝕜 E] [ContinuousConstSMul 𝕜 F] [CompleteSpace F] open UniformOnFun in theorem completeSpace (h : IsCoherentWith {s : Set (ι → E) | IsVonNBounded 𝕜 s}) : CompleteSpace (E [⋀^ι]→L[𝕜] F) := by wlog hF : T2Space F generalizing F · rw [(isUniformInducing_postcomp (SeparationQuotient.mkCLM _ _) SeparationQuotient.isUniformInducing_mk).completeSpace_congr] · exact this inferInstance · intro f use (SeparationQuotient.outCLM _ _).compContinuousAlternatingMap f ext simp have := ContinuousMultilinearMap.completeSpace (F := F) h rw [completeSpace_iff_isComplete_range isUniformEmbedding_toContinuousMultilinearMap.isUniformInducing] apply isClosed_range_toContinuousMultilinearMap.isComplete instance instCompleteSpace [IsTopologicalAddGroup E] [SequentialSpace (ι → E)] : CompleteSpace (E [⋀^ι]→L[𝕜] F) := completeSpace <| .of_seq fun _u x hux ↦ (hux.isVonNBounded_range 𝕜).insert x end CompleteSpace section RestrictScalars variable (𝕜' : Type*) [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜' 𝕜] [Module 𝕜' E] [IsScalarTower 𝕜' 𝕜 E] [Module 𝕜' F] [IsScalarTower 𝕜' 𝕜 F] [ContinuousSMul 𝕜 E] theorem isUniformEmbedding_restrictScalars : IsUniformEmbedding (restrictScalars 𝕜' : E [⋀^ι]→L[𝕜] F → E [⋀^ι]→L[𝕜'] F) := by rw [← isUniformEmbedding_toContinuousMultilinearMap.of_comp_iff] exact (ContinuousMultilinearMap.isUniformEmbedding_restrictScalars 𝕜').comp isUniformEmbedding_toContinuousMultilinearMap theorem uniformContinuous_restrictScalars : UniformContinuous (restrictScalars 𝕜' : E [⋀^ι]→L[𝕜] F → E [⋀^ι]→L[𝕜'] F) := (isUniformEmbedding_restrictScalars 𝕜').uniformContinuous end RestrictScalars end IsUniformAddGroup variable [TopologicalSpace F] [IsTopologicalAddGroup F] lemma isEmbedding_toContinuousMultilinearMap : IsEmbedding (toContinuousMultilinearMap : (E [⋀^ι]→L[𝕜] F → _)) := letI := IsTopologicalAddGroup.toUniformSpace F haveI := isUniformAddGroup_of_addCommGroup (G := F) isUniformEmbedding_toContinuousMultilinearMap.isEmbedding instance instIsTopologicalAddGroup : IsTopologicalAddGroup (E [⋀^ι]→L[𝕜] F) := isEmbedding_toContinuousMultilinearMap.topologicalAddGroup (toContinuousMultilinearMapLinear (R := ℕ)) @[continuity, fun_prop] lemma continuous_toContinuousMultilinearMap : Continuous (toContinuousMultilinearMap : (E [⋀^ι]→L[𝕜] F → _)) := isEmbedding_toContinuousMultilinearMap.continuous instance instContinuousConstSMul {M : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass 𝕜 M F] [ContinuousConstSMul M F] : ContinuousConstSMul M (E [⋀^ι]→L[𝕜] F) := isEmbedding_toContinuousMultilinearMap.continuousConstSMul id rfl instance instContinuousSMul [ContinuousSMul 𝕜 F] : ContinuousSMul 𝕜 (E [⋀^ι]→L[𝕜] F) := isEmbedding_toContinuousMultilinearMap.continuousSMul continuous_id rfl theorem hasBasis_nhds_zero_of_basis {ι' : Type*} {p : ι' → Prop} {b : ι' → Set F} (h : (𝓝 (0 : F)).HasBasis p b) : (𝓝 (0 : E [⋀^ι]→L[𝕜] F)).HasBasis (fun Si : Set (ι → E) × ι' => IsVonNBounded 𝕜 Si.1 ∧ p Si.2) fun Si => { f | MapsTo f Si.1 (b Si.2) } := by rw [nhds_induced] exact (ContinuousMultilinearMap.hasBasis_nhds_zero_of_basis h).comap _ theorem hasBasis_nhds_zero : (𝓝 (0 : E [⋀^ι]→L[𝕜] F)).HasBasis (fun SV : Set (ι → E) × Set F => IsVonNBounded 𝕜 SV.1 ∧ SV.2 ∈ 𝓝 0) fun SV => { f | MapsTo f SV.1 SV.2 } := hasBasis_nhds_zero_of_basis (Filter.basis_sets _) variable [ContinuousSMul 𝕜 E] lemma isClosedEmbedding_toContinuousMultilinearMap [T2Space F] : IsClosedEmbedding (toContinuousMultilinearMap : (E [⋀^ι]→L[𝕜] F) → ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ E) F) := ⟨isEmbedding_toContinuousMultilinearMap, isClosed_range_toContinuousMultilinearMap⟩ instance instContinuousEvalConst : ContinuousEvalConst (E [⋀^ι]→L[𝕜] F) (ι → E) F := .of_continuous_forget continuous_toContinuousMultilinearMap instance instT2Space [T2Space F] : T2Space (E [⋀^ι]→L[𝕜] F) := .of_injective_continuous DFunLike.coe_injective continuous_coeFun instance instT3Space [T2Space F] : T3Space (E [⋀^ι]→L[𝕜] F) := inferInstance /-- The inclusion of *alternating* continuous multi-linear maps into continuous multi-linear maps as a continuous linear map. -/ @[simps! -fullyApplied] def toContinuousMultilinearMapCLM (R : Type*) [Semiring R] [Module R F] [ContinuousConstSMul R F] [SMulCommClass 𝕜 R F] : E [⋀^ι]→L[𝕜] F →L[R] ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ E) F := ⟨toContinuousMultilinearMapLinear, continuous_induced_dom⟩ section RestrictScalars variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜' 𝕜] [Module 𝕜' E] [IsScalarTower 𝕜' 𝕜 E] [Module 𝕜' F] [IsScalarTower 𝕜' 𝕜 F] theorem isEmbedding_restrictScalars : IsEmbedding (restrictScalars 𝕜' : E [⋀^ι]→L[𝕜] F → E [⋀^ι]→L[𝕜'] F) := letI : UniformSpace F := IsTopologicalAddGroup.toUniformSpace F haveI : IsUniformAddGroup F := isUniformAddGroup_of_addCommGroup (isUniformEmbedding_restrictScalars _).isEmbedding @[continuity, fun_prop] theorem continuous_restrictScalars : Continuous (restrictScalars 𝕜' : E [⋀^ι]→L[𝕜] F → E [⋀^ι]→L[𝕜'] F) := isEmbedding_restrictScalars.continuous variable (𝕜') in /-- `ContinuousMultilinearMap.restrictScalars` as a `ContinuousLinearMap`. -/ @[simps -fullyApplied apply] def restrictScalarsCLM [ContinuousConstSMul 𝕜' F] : E [⋀^ι]→L[𝕜] F →L[𝕜'] E [⋀^ι]→L[𝕜'] F where toFun := restrictScalars 𝕜' map_add' _ _ := rfl map_smul' _ _ := rfl end RestrictScalars variable (𝕜 E F) /-- The application of a multilinear map as a `ContinuousLinearMap`. -/ def apply [ContinuousConstSMul 𝕜 F] (m : ι → E) : E [⋀^ι]→L[𝕜] F →L[𝕜] F where toFun c := c m map_add' _ _ := rfl map_smul' _ _ := rfl cont := continuous_eval_const m variable {𝕜 E F} @[simp] lemma apply_apply [ContinuousConstSMul 𝕜 F] {m : ι → E} {c : E [⋀^ι]→L[𝕜] F} : apply 𝕜 E F m c = c m := rfl theorem hasSum_eval {α : Type*} {p : α → E [⋀^ι]→L[𝕜] F} {q : E [⋀^ι]→L[𝕜] F} (h : HasSum p q) (m : ι → E) : HasSum (fun a => p a m) (q m) := h.map (applyAddHom m) (continuous_eval_const m) theorem tsum_eval [T2Space F] {α : Type*} {p : α → E [⋀^ι]→L[𝕜] F} (hp : Summable p) (m : ι → E) : (∑' a, p a) m = ∑' a, p a m := (hasSum_eval hp.hasSum m).tsum_eq.symm end ContinuousAlternatingMap
ExtClass.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.DerivedCategory.Ext.Basic import Mathlib.Algebra.Homology.DerivedCategory.SingleTriangle /-! # The Ext class of a short exact sequence In this file, given a short exact short complex `S : ShortComplex C` in an abelian category, we construct the associated class in `Ext S.X₃ S.X₁ 1`. -/ assert_not_exists TwoSidedIdeal universe w' w v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Abelian C] [HasExt.{w} C] open Localization Limits ZeroObject DerivedCategory Pretriangulated open Abelian namespace ShortComplex variable (S : ShortComplex C) lemma ext_mk₀_f_comp_ext_mk₀_g : (Ext.mk₀ S.f).comp (Ext.mk₀ S.g) (zero_add 0) = 0 := by simp namespace ShortExact variable {S} variable (hS : S.ShortExact) section local notation "W" => HomologicalComplex.quasiIso C (ComplexShape.up ℤ) local notation "S'" => S.map (CochainComplex.singleFunctor C 0) local notation "hS'" => hS.map_of_exact (HomologicalComplex.single _ _ _) local notation "K" => CochainComplex.mappingCone (ShortComplex.f S') local notation "qis" => CochainComplex.mappingCone.descShortComplex S' local notation "hqis" => CochainComplex.mappingCone.quasiIso_descShortComplex hS' local notation "δ" => Triangle.mor₃ (CochainComplex.mappingCone.triangle (ShortComplex.f S')) instance : HasSmallLocalizedShiftedHom.{w} W ℤ (S').X₃ (S').X₁ := by dsimp infer_instance include hS in private lemma hasSmallLocalizedHom_S'_X₃_K : HasSmallLocalizedHom.{w} W (S').X₃ K := by rw [Localization.hasSmallLocalizedHom_iff_target W (S').X₃ qis hqis] dsimp apply Localization.hasSmallLocalizedHom_of_hasSmallLocalizedShiftedHom₀ (M := ℤ) include hS in private lemma hasSmallLocalizedShiftedHom_K_S'_X₁ : HasSmallLocalizedShiftedHom.{w} W ℤ K (S').X₁ := by rw [Localization.hasSmallLocalizedShiftedHom_iff_source.{w} W ℤ qis hqis (S').X₁] infer_instance /-- The class in `Ext S.X₃ S.X₁ 1` that is attached to a short exact short complex `S` in an abelian category. -/ noncomputable def extClass : Ext.{w} S.X₃ S.X₁ 1 := by have := hS.hasSmallLocalizedHom_S'_X₃_K have := hS.hasSmallLocalizedShiftedHom_K_S'_X₁ change SmallHom W (S').X₃ ((S').X₁⟦(1 : ℤ)⟧) exact (SmallHom.mkInv qis hqis).comp (SmallHom.mk W δ) @[simp] lemma extClass_hom [HasDerivedCategory.{w'} C] : hS.extClass.hom = hS.singleδ := by change SmallShiftedHom.equiv W Q hS.extClass = _ dsimp [extClass, SmallShiftedHom.equiv] erw [SmallHom.equiv_comp, Iso.homToEquiv_apply] rw [SmallHom.equiv_mkInv, SmallHom.equiv_mk] dsimp [singleδ, triangleOfSESδ] rw [Category.assoc, Category.assoc, Category.assoc, singleFunctorsPostcompQIso_hom_hom, singleFunctorsPostcompQIso_inv_hom] erw [Category.id_comp, Functor.map_id, Category.comp_id] rfl end @[simp] lemma comp_extClass : (Ext.mk₀ S.g).comp hS.extClass (zero_add 1) = 0 := by letI := HasDerivedCategory.standard C ext simp only [Ext.comp_hom, Ext.mk₀_hom, extClass_hom, Ext.zero_hom, ShiftedHom.mk₀_comp] exact comp_distTriang_mor_zero₂₃ _ hS.singleTriangle_distinguished @[simp] lemma comp_extClass_assoc {Y : C} {n : ℕ} (γ : Ext S.X₁ Y n) {n' : ℕ} (h : 1 + n = n') : (Ext.mk₀ S.g).comp (hS.extClass.comp γ h) (zero_add n') = 0 := by rw [← Ext.comp_assoc (a₁₂ := 1) _ _ _ (by omega) (by omega) (by omega), comp_extClass, Ext.zero_comp] @[simp] lemma extClass_comp : hS.extClass.comp (Ext.mk₀ S.f) (add_zero 1) = 0 := by letI := HasDerivedCategory.standard C ext simp only [Ext.comp_hom, Ext.mk₀_hom, extClass_hom, Ext.zero_hom, ShiftedHom.comp_mk₀] exact comp_distTriang_mor_zero₃₁ _ hS.singleTriangle_distinguished @[simp] lemma extClass_comp_assoc {Y : C} {n : ℕ} (γ : Ext S.X₂ Y n) {n' : ℕ} {h : 1 + n = n'} : hS.extClass.comp ((Ext.mk₀ S.f).comp γ (zero_add n)) h = 0 := by rw [← Ext.comp_assoc (a₁₂ := 1) _ _ _ (by omega) (by omega) (by omega), extClass_comp, Ext.zero_comp] end ShortExact end ShortComplex end CategoryTheory
DocPrime.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 this linter explicitly to ensure that -- this file has a valid copyright header and module docstring. import Mathlib.Tactic.Linter.Header /-! # The "docPrime" linter The "docPrime" linter emits a warning on declarations that have no doc-string and whose name ends with a `'`. Such declarations are expected to have a documented explanation for the presence of a `'` in their name. This may consist of discussion of the difference relative to an unprimed version of that declaration, or an explanation as to why no better naming scheme is possible. -/ open Lean Elab Linter namespace Mathlib.Linter /-- The "docPrime" linter emits a warning on declarations that have no doc-string and whose name ends with a `'`. The file `scripts/nolints_prime_decls.txt` contains a list of temporary exceptions to this linter. This list should not be appended to, and become emptied over time. -/ register_option linter.docPrime : Bool := { defValue := false descr := "enable the docPrime linter" } namespace DocPrime @[inherit_doc Mathlib.Linter.linter.docPrime] def docPrimeLinter : Linter where run := withSetOptionIn fun stx ↦ do unless getLinterValue linter.docPrime (← getLinterOptions) do return if (← get).messages.hasErrors then return unless [``Lean.Parser.Command.declaration, `lemma].contains stx.getKind do return -- ignore private declarations if (stx.find? (·.isOfKind ``Lean.Parser.Command.private)).isSome then return -- ignore examples if (stx.find? (·.isOfKind ``Lean.Parser.Command.example)).isSome then return let docstring := stx[0][0] -- The current declaration's id, possibly followed by a list of universe names. let declId := if stx[1].isOfKind ``Lean.Parser.Command.instance then stx[1][3][0] else stx[1][1] if let .missing := declId then return -- The name of the current declaration, with namespaces resolved. let declName : Name := if let `_root_ :: rest := declId[0].getId.components then rest.foldl (· ++ ·) default else (← getCurrNamespace) ++ declId[0].getId let msg := m!"`{declName}` is missing a doc-string, please add one.\n\ Declarations whose name ends with a `'` are expected to contain an explanation for the \ presence of a `'` in their doc-string. This may consist of discussion of the difference \ relative to the unprimed version, or an explanation as to why no better naming scheme \ is possible." if docstring[0][1].getAtomVal.isEmpty && declName.toString.back == '\'' then if ← System.FilePath.pathExists "scripts/nolints_prime_decls.txt" then if (← IO.FS.lines "scripts/nolints_prime_decls.txt").contains declName.toString then return else Linter.logLint linter.docPrime declId msg else Linter.logLint linter.docPrime declId msg initialize addLinter docPrimeLinter end DocPrime end Mathlib.Linter
Tower.lean
/- Copyright (c) 2020 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.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower /-! # Subalgebras in towers of algebras In this file we prove facts about subalgebras in towers of algebras. An algebra tower A/S/R is expressed by having instances of `Algebra A S`, `Algebra R S`, `Algebra R A` and `IsScalarTower R S A`, the latter asserting the compatibility condition `(r • s) • a = r • (s • a)`. ## Main results * `IsScalarTower.Subalgebra`: if `A/S/R` is a tower and `S₀` is a subalgebra between `S` and `R`, then `A/S/S₀` is a tower * `IsScalarTower.Subalgebra'`: if `A/S/R` is a tower and `S₀` is a subalgebra between `S` and `R`, then `A/S₀/R` is a tower * `Subalgebra.restrictScalars`: turn an `S`-subalgebra of `A` into an `R`-subalgebra of `A`, given that `A/S/R` is a tower -/ open Pointwise universe u v w u₁ v₁ variable (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) (M : Type v₁) namespace Algebra variable [CommSemiring R] [Semiring A] [Algebra R A] variable [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] variable {A} theorem lmul_algebraMap (x : R) : Algebra.lmul R A (algebraMap R A x) = Algebra.lsmul R R A x := Eq.symm <| LinearMap.ext <| smul_def x end Algebra namespace IsScalarTower section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] variable [Algebra R S] [Algebra S A] instance subalgebra (S₀ : Subalgebra R S) : IsScalarTower S₀ S A := of_algebraMap_eq fun _ ↦ rfl variable [Algebra R A] [IsScalarTower R S A] instance subalgebra' (S₀ : Subalgebra R S) : IsScalarTower R S₀ A := @IsScalarTower.of_algebraMap_eq R S₀ A _ _ _ _ _ _ fun _ ↦ (IsScalarTower.algebraMap_apply R S A _ :) end Semiring end IsScalarTower namespace Subalgebra open IsScalarTower section Semiring variable {S A B} [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra S A] [Algebra R A] [Algebra S B] [Algebra R B] variable [IsScalarTower R S A] [IsScalarTower R S B] /-- Given a tower `A / ↥U / S / R` of algebras, where `U` is an `S`-subalgebra of `A`, reinterpret `U` as an `R`-subalgebra of `A`. -/ def restrictScalars (U : Subalgebra S A) : Subalgebra R A := { U with algebraMap_mem' := fun x ↦ by rw [algebraMap_apply R S A] exact U.algebraMap_mem _ } @[simp] theorem coe_restrictScalars {U : Subalgebra S A} : (restrictScalars R U : Set A) = (U : Set A) := rfl @[simp] theorem restrictScalars_top : restrictScalars R (⊤ : Subalgebra S A) = ⊤ := -- Porting note: `by dsimp` used to be `rfl`. This appears to work but causes -- this theorem to timeout in the kernel after minutes of thinking. SetLike.coe_injective <| by dsimp @[simp] theorem restrictScalars_toSubmodule {U : Subalgebra S A} : Subalgebra.toSubmodule (U.restrictScalars R) = U.toSubmodule.restrictScalars R := SetLike.coe_injective rfl @[simp] theorem mem_restrictScalars {U : Subalgebra S A} {x : A} : x ∈ restrictScalars R U ↔ x ∈ U := Iff.rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : Subalgebra S A → Subalgebra R A) := fun U V H ↦ ext fun x ↦ by rw [← mem_restrictScalars R, H, mem_restrictScalars] /-- Produces an `R`-algebra map from `U.restrictScalars R` given an `S`-algebra map from `U`. This is a special case of `AlgHom.restrictScalars` that can be helpful in elaboration. -/ @[simp] def ofRestrictScalars (U : Subalgebra S A) (f : U →ₐ[S] B) : U.restrictScalars R →ₐ[R] B := f.restrictScalars R end Semiring section CommSemiring @[simp] lemma range_isScalarTower_toAlgHom [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) : LinearMap.range (IsScalarTower.toAlgHom R S A) = Subalgebra.toSubmodule S := by ext simp [algebraMap_eq] end CommSemiring end Subalgebra namespace IsScalarTower open Subalgebra variable [CommSemiring R] [CommSemiring S] [CommSemiring A] variable [Algebra R S] [Algebra S A] [Algebra R A] [IsScalarTower R S A] theorem adjoin_range_toAlgHom (t : Set A) : (Algebra.adjoin (toAlgHom R S A).range t).restrictScalars R = (Algebra.adjoin S t).restrictScalars R := Subalgebra.ext fun z ↦ show z ∈ Subsemiring.closure (Set.range (algebraMap (toAlgHom R S A).range A) ∪ t : Set A) ↔ z ∈ Subsemiring.closure (Set.range (algebraMap S A) ∪ t : Set A) by suffices Set.range (algebraMap (toAlgHom R S A).range A) = Set.range (algebraMap S A) by rw [this] ext z exact ⟨fun ⟨⟨_, y, h1⟩, h2⟩ ↦ ⟨y, h2 ▸ h1⟩, fun ⟨y, hy⟩ ↦ ⟨⟨z, y, hy⟩, rfl⟩⟩ end IsScalarTower
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.
CompactlyGeneratedSpace.lean
/- Copyright (c) 2024 Etienne Marion. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Etienne Marion -/ import Mathlib.Topology.Category.CompHaus.Basic import Mathlib.Topology.Compactification.OnePoint.Basic /-! # Compactly generated topological spaces This file defines compactly generated topological spaces. A compactly generated space is a space `X` whose topology is coinduced by continuous maps from compact Hausdorff spaces to `X`. In such a space, a set `s` is closed (resp. open) if and only if for all compact Hausdorff space `K` and `f : K → X` continuous, `f ⁻¹' s` is closed (resp. open) in `K`. We provide two definitions. `UCompactlyGeneratedSpace.{u} X` corresponds to the type class where the compact Hausdorff spaces are taken in an arbitrary universe `u`, and should therefore always be used with an explicit universe parameter. It is intended for categorical purposes. `CompactlyGeneratedSpace X` corresponds to the case where compact Hausdorff spaces are taken in the same universe as `X`, and is intended for topological purposes. We prove basic properties and instances, and prove that a `SequentialSpace` is compactly generated, as well as a Hausdorff `WeaklyLocallyCompactSpace`. ## Main definitions * `UCompactlyGeneratedSpace.{u} X`: the topology of `X` is coinduced by continuous maps coming from compact Hausdorff spaces in universe `u`. * `CompactlyGeneratedSpace X`: the topology of `X` is coinduced by continuous maps coming from compact Hausdorff spaces in the same universe as `X`. ## References * <https://en.wikipedia.org/wiki/Compactly_generated_space> * <https://ncatlab.org/nlab/files/StricklandCGHWSpaces.pdf> ## Tags compactly generated space -/ universe u v w x open TopologicalSpace Filter Topology Set section UCompactlyGeneratedSpace variable {X : Type w} {Y : Type x} /-- The compactly generated topology on a topological space `X`. This is the finest topology which makes all maps from compact Hausdorff spaces to `X`, which are continuous for the original topology, continuous. Note: this definition should be used with an explicit universe parameter `u` for the size of the compact Hausdorff spaces mapping to `X`. -/ def TopologicalSpace.compactlyGenerated (X : Type w) [TopologicalSpace X] : TopologicalSpace X := let f : (Σ (i : (S : CompHaus.{u}) × C(S, X)), i.fst) → X := fun ⟨⟨_, i⟩, s⟩ ↦ i s coinduced f inferInstance lemma continuous_from_compactlyGenerated [TopologicalSpace X] [t : TopologicalSpace Y] (f : X → Y) (h : ∀ (S : CompHaus.{u}) (g : C(S, X)), Continuous (f ∘ g)) : Continuous[compactlyGenerated.{u} X, t] f := by rw [continuous_coinduced_dom] continuity /-- A topological space `X` is compactly generated if its topology is finer than (and thus equal to) the compactly generated topology, i.e. it is coinduced by the continuous maps from compact Hausdorff spaces to `X`. This version includes an explicit universe parameter `u` which should always be specified. It is intended for categorical purposes. See `CompactlyGeneratedSpace` for the version without this parameter, intended for topological purposes. -/ class UCompactlyGeneratedSpace (X : Type v) [t : TopologicalSpace X] : Prop where /-- The topology of `X` is finer than the compactly generated topology. -/ le_compactlyGenerated : t ≤ compactlyGenerated.{u} X lemma eq_compactlyGenerated [t : TopologicalSpace X] [UCompactlyGeneratedSpace.{u} X] : t = compactlyGenerated.{u} X := by apply le_antisymm · exact UCompactlyGeneratedSpace.le_compactlyGenerated · simp only [compactlyGenerated, ← continuous_iff_coinduced_le, continuous_sigma_iff, Sigma.forall] exact fun S f ↦ f.2 instance (X : Type v) [t : TopologicalSpace X] [DiscreteTopology X] : UCompactlyGeneratedSpace.{u} X where le_compactlyGenerated := by rw [DiscreteTopology.eq_bot (t := t)] exact bot_le /- The unused variable linter flags `[tY : TopologicalSpace Y]`, but we want to use this as a named argument, so we need to disable the linter. -/ set_option linter.unusedVariables false in /-- Let `f : X → Y`. Suppose that to prove that `f` is continuous, it suffices to show that for every compact Hausdorff space `K` and every continuous map `g : K → X`, `f ∘ g` is continuous. Then `X` is compactly generated. -/ lemma uCompactlyGeneratedSpace_of_continuous_maps [t : TopologicalSpace X] (h : ∀ {Y : Type w} [tY : TopologicalSpace Y] (f : X → Y), (∀ (S : CompHaus.{u}) (g : C(S, X)), Continuous (f ∘ g)) → Continuous f) : UCompactlyGeneratedSpace.{u} X where le_compactlyGenerated := by suffices Continuous[t, compactlyGenerated.{u} X] (id : X → X) by rwa [← continuous_id_iff_le] apply h (tY := compactlyGenerated.{u} X) intro S g let f : (Σ (i : (T : CompHaus.{u}) × C(T, X)), i.fst) → X := fun ⟨⟨_, i⟩, s⟩ ↦ i s suffices ∀ (i : (T : CompHaus.{u}) × C(T, X)), Continuous[inferInstance, compactlyGenerated X] (fun (a : i.fst) ↦ f ⟨i, a⟩) from this ⟨S, g⟩ rw [← @continuous_sigma_iff] apply continuous_coinduced_rng variable [tX : TopologicalSpace X] [tY : TopologicalSpace Y] /-- If `X` is compactly generated, to prove that `f : X → Y` is continuous it is enough to show that for every compact Hausdorff space `K` and every continuous map `g : K → X`, `f ∘ g` is continuous. -/ lemma continuous_from_uCompactlyGeneratedSpace [UCompactlyGeneratedSpace.{u} X] (f : X → Y) (h : ∀ (S : CompHaus.{u}) (g : C(S, X)), Continuous (f ∘ g)) : Continuous f := by apply continuous_le_dom UCompactlyGeneratedSpace.le_compactlyGenerated exact continuous_from_compactlyGenerated f h /-- A topological space `X` is compactly generated if a set `s` is closed when `f ⁻¹' s` is closed for every continuous map `f : K → X`, where `K` is compact Hausdorff. -/ theorem uCompactlyGeneratedSpace_of_isClosed (h : ∀ (s : Set X), (∀ (S : CompHaus.{u}) (f : C(S, X)), IsClosed (f ⁻¹' s)) → IsClosed s) : UCompactlyGeneratedSpace.{u} X := uCompactlyGeneratedSpace_of_continuous_maps fun _ h' ↦ continuous_iff_isClosed.2 fun _ hs ↦ h _ fun S g ↦ hs.preimage (h' S g) /-- A topological space `X` is compactly generated if a set `s` is open when `f ⁻¹' s` is open for every continuous map `f : K → X`, where `K` is compact Hausdorff. -/ theorem uCompactlyGeneratedSpace_of_isOpen (h : ∀ (s : Set X), (∀ (S : CompHaus.{u}) (f : C(S, X)), IsOpen (f ⁻¹' s)) → IsOpen s) : UCompactlyGeneratedSpace.{u} X := uCompactlyGeneratedSpace_of_continuous_maps fun _ h' ↦ continuous_def.2 fun _ hs ↦ h _ fun S g ↦ hs.preimage (h' S g) /-- In a compactly generated space `X`, a set `s` is closed when `f ⁻¹' s` is closed for every continuous map `f : K → X`, where `K` is compact Hausdorff. -/ theorem UCompactlyGeneratedSpace.isClosed [UCompactlyGeneratedSpace.{u} X] {s : Set X} (hs : ∀ (S : CompHaus.{u}) (f : C(S, X)), IsClosed (f ⁻¹' s)) : IsClosed s := by rw [eq_compactlyGenerated (X := X), TopologicalSpace.compactlyGenerated, isClosed_coinduced, isClosed_sigma_iff] exact fun ⟨S, f⟩ ↦ hs S f /-- In a compactly generated space `X`, a set `s` is open when `f ⁻¹' s` is open for every continuous map `f : K → X`, where `K` is compact Hausdorff. -/ theorem UCompactlyGeneratedSpace.isOpen [UCompactlyGeneratedSpace.{u} X] {s : Set X} (hs : ∀ (S : CompHaus.{u}) (f : C(S, X)), IsOpen (f ⁻¹' s)) : IsOpen s := by rw [eq_compactlyGenerated (X := X), TopologicalSpace.compactlyGenerated, isOpen_coinduced, isOpen_sigma_iff] exact fun ⟨S, f⟩ ↦ hs S f /-- If the topology of `X` is coinduced by a continuous function whose domain is compactly generated, then so is `X`. -/ theorem uCompactlyGeneratedSpace_of_coinduced [UCompactlyGeneratedSpace.{u} X] {f : X → Y} (hf : Continuous f) (ht : tY = coinduced f tX) : UCompactlyGeneratedSpace.{u} Y := by refine uCompactlyGeneratedSpace_of_isClosed fun s h ↦ ?_ rw [ht, isClosed_coinduced] exact UCompactlyGeneratedSpace.isClosed fun _ ⟨g, hg⟩ ↦ h _ ⟨_, hf.comp hg⟩ /-- The quotient of a compactly generated space is compactly generated. -/ instance {S : Setoid X} [UCompactlyGeneratedSpace.{u} X] : UCompactlyGeneratedSpace.{u} (Quotient S) := uCompactlyGeneratedSpace_of_coinduced continuous_quotient_mk' rfl /-- The sum of two compactly generated spaces is compactly generated. -/ instance [UCompactlyGeneratedSpace.{u} X] [UCompactlyGeneratedSpace.{v} Y] : UCompactlyGeneratedSpace.{max u v} (X ⊕ Y) := by refine uCompactlyGeneratedSpace_of_isClosed fun s h ↦ isClosed_sum_iff.2 ⟨?_, ?_⟩ all_goals refine UCompactlyGeneratedSpace.isClosed fun S ⟨f, hf⟩ ↦ ?_ · let g : ULift.{v} S → X ⊕ Y := Sum.inl ∘ f ∘ ULift.down have hg : Continuous g := continuous_inl.comp <| hf.comp continuous_uliftDown exact (h (CompHaus.of (ULift.{v} S)) ⟨g, hg⟩).preimage continuous_uliftUp · let g : ULift.{u} S → X ⊕ Y := Sum.inr ∘ f ∘ ULift.down have hg : Continuous g := continuous_inr.comp <| hf.comp continuous_uliftDown exact (h (CompHaus.of (ULift.{u} S)) ⟨g, hg⟩).preimage continuous_uliftUp /-- The sigma type associated to a family of compactly generated spaces is compactly generated. -/ instance {ι : Type v} {X : ι → Type w} [∀ i, TopologicalSpace (X i)] [∀ i, UCompactlyGeneratedSpace.{u} (X i)] : UCompactlyGeneratedSpace.{u} (Σ i, X i) := uCompactlyGeneratedSpace_of_isClosed fun _ h ↦ isClosed_sigma_iff.2 fun i ↦ UCompactlyGeneratedSpace.isClosed fun S ⟨f, hf⟩ ↦ h S ⟨Sigma.mk i ∘ f, continuous_sigmaMk.comp hf⟩ open OnePoint in /-- A sequential space is compactly generated. The proof is taken from <https://ncatlab.org/nlab/files/StricklandCGHWSpaces.pdf>, Proposition 1.6. -/ instance (priority := 100) [SequentialSpace X] : UCompactlyGeneratedSpace.{u} X := by refine uCompactlyGeneratedSpace_of_isClosed fun s h ↦ SequentialSpace.isClosed_of_seq _ fun u p hu hup ↦ ?_ let g : ULift.{u} (OnePoint ℕ) → X := (continuousMapMkNat u p hup) ∘ ULift.down change ULift.up ∞ ∈ g ⁻¹' s have : Filter.Tendsto (@OnePoint.some ℕ) Filter.atTop (𝓝 ∞) := by rw [← Nat.cofinite_eq_atTop, ← cocompact_eq_cofinite, ← coclosedCompact_eq_cocompact] exact tendsto_coe_infty apply IsClosed.mem_of_tendsto _ ((continuous_uliftUp.tendsto ∞).comp this) · simp only [Function.comp_apply, mem_preimage, eventually_atTop, ge_iff_le] exact ⟨0, fun b _ ↦ hu b⟩ · exact h (CompHaus.of (ULift.{u} (OnePoint ℕ))) ⟨g, (continuousMapMkNat u p hup).continuous.comp continuous_uliftDown⟩ end UCompactlyGeneratedSpace section CompactlyGeneratedSpace variable {X : Type u} {Y : Type v} [TopologicalSpace X] [TopologicalSpace Y] /-- A topological space `X` is compactly generated if its topology is finer than (and thus equal to) the compactly generated topology, i.e. it is coinduced by the continuous maps from compact Hausdorff spaces to `X`. In this version, intended for topological purposes, the compact spaces are taken in the same universe as `X`. See `UCompactlyGeneratedSpace` for a version with an explicit universe parameter, intended for categorical purposes. -/ abbrev CompactlyGeneratedSpace (X : Type u) [TopologicalSpace X] : Prop := UCompactlyGeneratedSpace.{u} X /-- If `X` is compactly generated, to prove that `f : X → Y` is continuous it is enough to show that for every compact Hausdorff space `K` and every continuous map `g : K → X`, `f ∘ g` is continuous. -/ lemma continuous_from_compactlyGeneratedSpace [CompactlyGeneratedSpace X] (f : X → Y) (h : ∀ (K : Type u) [TopologicalSpace K], [CompactSpace K] → [T2Space K] → (∀ g : K → X, Continuous g → Continuous (f ∘ g))) : Continuous f := continuous_from_uCompactlyGeneratedSpace f fun K ⟨g, hg⟩ ↦ h K g hg /-- Let `f : X → Y`. Suppose that to prove that `f` is continuous, it suffices to show that for every compact Hausdorff space `K` and every continuous map `g : K → X`, `f ∘ g` is continuous. Then `X` is compactly generated. -/ lemma compactlyGeneratedSpace_of_continuous_maps (h : ∀ {Y : Type u} [TopologicalSpace Y] (f : X → Y), (∀ (K : Type u) [TopologicalSpace K], [CompactSpace K] → [T2Space K] → (∀ g : K → X, Continuous g → Continuous (f ∘ g))) → Continuous f) : CompactlyGeneratedSpace X := uCompactlyGeneratedSpace_of_continuous_maps fun f h' ↦ h f fun K _ _ _ g hg ↦ h' (CompHaus.of K) ⟨g, hg⟩ /-- A topological space `X` is compactly generated if a set `s` is closed when `f ⁻¹' s` is closed for every continuous map `f : K → X`, where `K` is compact Hausdorff. -/ theorem compactlyGeneratedSpace_of_isClosed (h : ∀ (s : Set X), (∀ (K : Type u) [TopologicalSpace K], [CompactSpace K] → [T2Space K] → ∀ (f : K → X), Continuous f → IsClosed (f ⁻¹' s)) → IsClosed s) : CompactlyGeneratedSpace X := uCompactlyGeneratedSpace_of_isClosed fun s h' ↦ h s fun K _ _ _ f hf ↦ h' (CompHaus.of K) ⟨f, hf⟩ /-- In a compactly generated space `X`, a set `s` is closed when `f ⁻¹' s` is closed for every continuous map `f : K → X`, where `K` is compact Hausdorff. -/ theorem CompactlyGeneratedSpace.isClosed' [CompactlyGeneratedSpace X] {s : Set X} (hs : ∀ (K : Type u) [TopologicalSpace K], [CompactSpace K] → [T2Space K] → ∀ (f : K → X), Continuous f → IsClosed (f ⁻¹' s)) : IsClosed s := UCompactlyGeneratedSpace.isClosed fun S ⟨f, hf⟩ ↦ hs S f hf /-- In a compactly generated space `X`, a set `s` is closed when `s ∩ K` is closed for every compact set `K`. -/ theorem CompactlyGeneratedSpace.isClosed [CompactlyGeneratedSpace X] {s : Set X} (hs : ∀ ⦃K⦄, IsCompact K → IsClosed (s ∩ K)) : IsClosed s := by refine isClosed' fun K _ _ _ f hf ↦ ?_ rw [← Set.preimage_inter_range] exact (hs (isCompact_range hf)).preimage hf /-- A topological space `X` is compactly generated if a set `s` is open when `f ⁻¹' s` is open for every continuous map `f : K → X`, where `K` is compact Hausdorff. -/ theorem compactlyGeneratedSpace_of_isOpen (h : ∀ (s : Set X), (∀ (K : Type u) [TopologicalSpace K], [CompactSpace K] → [T2Space K] → ∀ (f : K → X), Continuous f → IsOpen (f ⁻¹' s)) → IsOpen s) : CompactlyGeneratedSpace X := uCompactlyGeneratedSpace_of_isOpen fun s h' ↦ h s fun K _ _ _ f hf ↦ h' (CompHaus.of K) ⟨f, hf⟩ /-- In a compactly generated space `X`, a set `s` is open when `f ⁻¹' s` is open for every continuous map `f : K → X`, where `K` is compact Hausdorff. -/ theorem CompactlyGeneratedSpace.isOpen' [CompactlyGeneratedSpace X] {s : Set X} (hs : ∀ (K : Type u) [TopologicalSpace K], [CompactSpace K] → [T2Space K] → ∀ (f : K → X), Continuous f → IsOpen (f ⁻¹' s)) : IsOpen s := UCompactlyGeneratedSpace.isOpen fun S ⟨f, hf⟩ ↦ hs S f hf /-- In a compactly generated space `X`, a set `s` is open when `s ∩ K` is closed for every open set `K`. -/ theorem CompactlyGeneratedSpace.isOpen [CompactlyGeneratedSpace X] {s : Set X} (hs : ∀ ⦃K⦄, IsCompact K → IsOpen (s ∩ K)) : IsOpen s := by refine isOpen' fun K _ _ _ f hf ↦ ?_ rw [← Set.preimage_inter_range] exact (hs (isCompact_range hf)).preimage hf /-- If the topology of `X` is coinduced by a continuous function whose domain is compactly generated, then so is `X`. -/ theorem compactlyGeneratedSpace_of_coinduced {X : Type u} [tX : TopologicalSpace X] {Y : Type u} [tY : TopologicalSpace Y] [CompactlyGeneratedSpace X] {f : X → Y} (hf : Continuous f) (ht : tY = coinduced f tX) : CompactlyGeneratedSpace Y := uCompactlyGeneratedSpace_of_coinduced hf ht /-- The sigma type associated to a family of compactly generated spaces is compactly generated. -/ instance {ι : Type u} {X : ι → Type v} [∀ i, TopologicalSpace (X i)] [∀ i, CompactlyGeneratedSpace (X i)] : CompactlyGeneratedSpace (Σ i, X i) := by refine compactlyGeneratedSpace_of_isClosed fun s h ↦ isClosed_sigma_iff.2 fun i ↦ CompactlyGeneratedSpace.isClosed' fun K _ _ _ f hf ↦ ?_ let g : ULift.{u} K → (Σ i, X i) := Sigma.mk i ∘ f ∘ ULift.down have hg : Continuous g := continuous_sigmaMk.comp <| hf.comp continuous_uliftDown exact (h _ g hg).preimage continuous_uliftUp variable [T2Space X] theorem CompactlyGeneratedSpace.isClosed_iff_of_t2 [CompactlyGeneratedSpace X] (s : Set X) : IsClosed s ↔ ∀ ⦃K⦄, IsCompact K → IsClosed (s ∩ K) where mp hs _ hK := hs.inter hK.isClosed mpr := CompactlyGeneratedSpace.isClosed /-- Let `s ⊆ X`. Suppose that `X` is Hausdorff, and that to prove that `s` is closed, it suffices to show that for every compact set `K ⊆ X`, `s ∩ K` is closed. Then `X` is compactly generated. -/ theorem compactlyGeneratedSpace_of_isClosed_of_t2 (h : ∀ s, (∀ (K : Set X), IsCompact K → IsClosed (s ∩ K)) → IsClosed s) : CompactlyGeneratedSpace X := by refine compactlyGeneratedSpace_of_isClosed fun s hs ↦ h s fun K hK ↦ ?_ rw [Set.inter_comm, ← Subtype.image_preimage_coe] apply hK.isClosed.isClosedMap_subtype_val have : CompactSpace ↑K := isCompact_iff_compactSpace.1 hK exact hs _ Subtype.val continuous_subtype_val open scoped Set.Notation in /-- Let `s ⊆ X`. Suppose that `X` is Hausdorff, and that to prove that `s` is open, it suffices to show that for every compact set `K ⊆ X`, `s ∩ K` is open in `K`. Then `X` is compactly generated. -/ theorem compactlyGeneratedSpace_of_isOpen_of_t2 (h : ∀ s, (∀ (K : Set X), IsCompact K → IsOpen (K ↓∩ s)) → IsOpen s) : CompactlyGeneratedSpace X := by refine compactlyGeneratedSpace_of_isOpen fun s hs ↦ h s fun K hK ↦ ?_ have : CompactSpace ↑K := isCompact_iff_compactSpace.1 hK exact hs _ Subtype.val continuous_subtype_val /-- A Hausdorff and weakly locally compact space is compactly generated. -/ instance (priority := 100) [WeaklyLocallyCompactSpace X] : CompactlyGeneratedSpace X := by refine compactlyGeneratedSpace_of_isClosed_of_t2 fun s h ↦ ?_ rw [isClosed_iff_forall_filter] intro x ℱ hℱ₁ hℱ₂ hℱ₃ rcases exists_compact_mem_nhds x with ⟨K, hK, K_mem⟩ exact Set.mem_of_mem_inter_left <| isClosed_iff_forall_filter.1 (h _ hK) x ℱ hℱ₁ (Filter.inf_principal ▸ le_inf hℱ₂ (le_trans hℱ₃ <| Filter.le_principal_iff.2 K_mem)) hℱ₃ /-- Every compactly generated space is a compactly coherent space. -/ instance to_compactlyCoherentSpace [CompactlyGeneratedSpace X] : CompactlyCoherentSpace X := CompactlyCoherentSpace.of_isOpen_forall_compactSpace fun _ h ↦ CompactlyGeneratedSpace.isOpen' fun K _ _ _ f hf ↦ h K f hf /-- A compactly coherent space that is Hausdorff is compactly generated. -/ instance of_compactlyCoherentSpace_of_t2 [T2Space X] [CompactlyCoherentSpace X] : CompactlyGeneratedSpace X := by apply compactlyGeneratedSpace_of_isClosed_of_t2 intro s hs rw [CompactlyCoherentSpace.isClosed_iff] intro K hK rw [← Subtype.preimage_coe_inter_self] exact (hs K hK).preimage_val end CompactlyGeneratedSpace
Integrals.lean
/- Copyright (c) 2023 Joachim Breitner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joachim Breitner -/ import Mathlib.Probability.ProbabilityMassFunction.Basic import Mathlib.Probability.ProbabilityMassFunction.Constructions import Mathlib.MeasureTheory.Integral.Bochner.Basic /-! # Integrals with a measure derived from probability mass functions. This files connects `PMF` with `integral`. The main result is that the integral (i.e. the expected value) with regard to a measure derived from a `PMF` is a sum weighted by the `PMF`. It also provides the expected value for specific probability mass functions. -/ namespace PMF open MeasureTheory NNReal ENNReal TopologicalSpace section General variable {α : Type*} [MeasurableSpace α] [MeasurableSingletonClass α] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] theorem integral_eq_tsum (p : PMF α) (f : α → E) (hf : Integrable f p.toMeasure) : ∫ a, f a ∂(p.toMeasure) = ∑' a, (p a).toReal • f a := calc _ = ∫ a in p.support, f a ∂(p.toMeasure) := by rw [restrict_toMeasure_support p] _ = ∑' (a : support p), (p.toMeasure {a.val}).toReal • f a := by apply integral_countable f p.support_countable rwa [IntegrableOn, restrict_toMeasure_support p] _ = ∑' (a : support p), (p a).toReal • f a := by congr with x; congr 2 apply PMF.toMeasure_apply_singleton p x (MeasurableSet.singleton _) _ = ∑' a, (p a).toReal • f a := tsum_subtype_eq_of_support_subset <| calc (fun a ↦ (p a).toReal • f a).support ⊆ (fun a ↦ (p a).toReal).support := Function.support_smul_subset_left _ _ _ ⊆ support p := fun x h1 h2 => h1 (by simp [h2]) theorem integral_eq_sum [Fintype α] (p : PMF α) (f : α → E) : ∫ a, f a ∂(p.toMeasure) = ∑ a, (p a).toReal • f a := by rw [integral_fintype _ .of_finite] congr with x rw [measureReal_def] congr 2 exact PMF.toMeasure_apply_singleton p x (MeasurableSet.singleton _) end General theorem bernoulli_expectation {p : ℝ≥0} (h : p ≤ 1) : ∫ b, cond b 1 0 ∂((bernoulli p h).toMeasure) = p.toReal := by simp [integral_eq_sum] end PMF
Kuratowski.lean
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Lp.lpSpace import Mathlib.Topology.Sets.Compacts /-! # The Kuratowski embedding Any separable metric space can be embedded isometrically in `ℓ^∞(ℕ, ℝ)`. Any partially defined Lipschitz map into `ℓ^∞` can be extended to the whole space. -/ noncomputable section open Set Metric TopologicalSpace NNReal ENNReal lp Function universe u variable {α : Type u} namespace KuratowskiEmbedding /-! ### Any separable metric space can be embedded isometrically in ℓ^∞(ℕ, ℝ) -/ variable {n : ℕ} [MetricSpace α] (x : ℕ → α) (a : α) /-- A metric space can be embedded in `l^∞(ℝ)` via the distances to points in a fixed countable set, if this set is dense. This map is given in `kuratowskiEmbedding`, without density assumptions. -/ def embeddingOfSubset : ℓ^∞(ℕ) := ⟨fun n => dist a (x n) - dist (x 0) (x n), by apply memℓp_infty use dist a (x 0) rintro - ⟨n, rfl⟩ exact abs_dist_sub_le _ _ _⟩ theorem embeddingOfSubset_coe : embeddingOfSubset x a n = dist a (x n) - dist (x 0) (x n) := rfl /-- The embedding map is always a semi-contraction. -/ theorem embeddingOfSubset_dist_le (a b : α) : dist (embeddingOfSubset x a) (embeddingOfSubset x b) ≤ dist a b := by refine lp.norm_le_of_forall_le dist_nonneg fun n => ?_ simp only [lp.coeFn_sub, Pi.sub_apply, embeddingOfSubset_coe] convert abs_dist_sub_le a b (x n) using 2 ring /-- When the reference set is dense, the embedding map is an isometry on its image. -/ theorem embeddingOfSubset_isometry (H : DenseRange x) : Isometry (embeddingOfSubset x) := by refine Isometry.of_dist_eq fun a b => ?_ refine (embeddingOfSubset_dist_le x a b).antisymm (le_of_forall_pos_le_add fun e epos => ?_) -- First step: find n with dist a (x n) < e rcases Metric.mem_closure_range_iff.1 (H a) (e / 2) (half_pos epos) with ⟨n, hn⟩ -- Second step: use the norm control at index n to conclude have C : dist b (x n) - dist a (x n) = embeddingOfSubset x b n - embeddingOfSubset x a n := by simp only [embeddingOfSubset_coe, sub_sub_sub_cancel_right] have := calc dist a b ≤ dist a (x n) + dist (x n) b := dist_triangle _ _ _ _ = 2 * dist a (x n) + (dist b (x n) - dist a (x n)) := by simp [dist_comm]; ring _ ≤ 2 * dist a (x n) + |dist b (x n) - dist a (x n)| := by apply_rules [add_le_add_left, le_abs_self] _ ≤ 2 * (e / 2) + |embeddingOfSubset x b n - embeddingOfSubset x a n| := by rw [C] gcongr _ ≤ 2 * (e / 2) + dist (embeddingOfSubset x b) (embeddingOfSubset x a) := by gcongr simp only [dist_eq_norm] exact lp.norm_apply_le_norm ENNReal.top_ne_zero (embeddingOfSubset x b - embeddingOfSubset x a) n _ = dist (embeddingOfSubset x b) (embeddingOfSubset x a) + e := by ring simpa [dist_comm] using this /-- Every separable metric space embeds isometrically in `ℓ^∞(ℕ)`. -/ theorem exists_isometric_embedding (α : Type u) [MetricSpace α] [SeparableSpace α] : ∃ f : α → ℓ^∞(ℕ), Isometry f := by rcases (univ : Set α).eq_empty_or_nonempty with h | h · use fun _ => 0; intro x; exact absurd h (Nonempty.ne_empty ⟨x, mem_univ x⟩) · -- We construct a map x : ℕ → α with dense image rcases h with ⟨basepoint⟩ haveI : Inhabited α := ⟨basepoint⟩ have : ∃ s : Set α, s.Countable ∧ Dense s := exists_countable_dense α rcases this with ⟨S, ⟨S_countable, S_dense⟩⟩ rcases Set.countable_iff_exists_subset_range.1 S_countable with ⟨x, x_range⟩ -- Use embeddingOfSubset to construct the desired isometry exact ⟨embeddingOfSubset x, embeddingOfSubset_isometry x (S_dense.mono x_range)⟩ end KuratowskiEmbedding open KuratowskiEmbedding /-- The Kuratowski embedding is an isometric embedding of a separable metric space in `ℓ^∞(ℕ, ℝ)`. -/ def kuratowskiEmbedding (α : Type u) [MetricSpace α] [SeparableSpace α] : α → ℓ^∞(ℕ) := Classical.choose (KuratowskiEmbedding.exists_isometric_embedding α) /-- The Kuratowski embedding is an isometry. Theorem 2.1 of [Assaf Naor, *Metric Embeddings and Lipschitz Extensions*][Naor-2015]. -/ protected theorem kuratowskiEmbedding.isometry (α : Type u) [MetricSpace α] [SeparableSpace α] : Isometry (kuratowskiEmbedding α) := Classical.choose_spec (exists_isometric_embedding α) /-- Version of the Kuratowski embedding for nonempty compacts -/ nonrec def NonemptyCompacts.kuratowskiEmbedding (α : Type u) [MetricSpace α] [CompactSpace α] [Nonempty α] : NonemptyCompacts ℓ^∞(ℕ) where carrier := range (kuratowskiEmbedding α) isCompact' := isCompact_range (kuratowskiEmbedding.isometry α).continuous nonempty' := range_nonempty _ /-- A function `f : α → ℓ^∞(ι, ℝ)` which is `K`-Lipschitz on a subset `s` admits a `K`-Lipschitz extension to the whole space. Theorem 2.2 of [Assaf Naor, *Metric Embeddings and Lipschitz Extensions*][Naor-2015] The same result for the case of a finite type `ι` is implemented in `LipschitzOnWith.extend_pi`. -/ theorem LipschitzOnWith.extend_lp_infty [PseudoMetricSpace α] {s : Set α} {ι : Type*} {f : α → ℓ^∞(ι)} {K : ℝ≥0} (hfl : LipschitzOnWith K f s) : ∃ g : α → ℓ^∞(ι), LipschitzWith K g ∧ EqOn f g s := by -- Construct the coordinate-wise extensions rw [LipschitzOnWith.coordinate] at hfl have (i : ι) : ∃ g : α → ℝ, LipschitzWith K g ∧ EqOn (fun x => f x i) g s := LipschitzOnWith.extend_real (hfl i) -- use the nonlinear Hahn-Banach theorem here! choose g hgl hgeq using this rcases s.eq_empty_or_nonempty with rfl | ⟨a₀, ha₀_in_s⟩ · exact ⟨0, LipschitzWith.const' 0, by simp⟩ · -- Show that the extensions are uniformly bounded have hf_extb : ∀ a : α, Memℓp (swap g a) ∞ := by apply LipschitzWith.uniformly_bounded (swap g) hgl a₀ use ‖f a₀‖ rintro - ⟨i, rfl⟩ simp_rw [← hgeq i ha₀_in_s] exact lp.norm_apply_le_norm top_ne_zero (f a₀) i -- Construct witness by bundling the function with its certificate of membership in ℓ^∞ let f_ext' : α → ℓ^∞(ι) := fun i ↦ ⟨swap g i, hf_extb i⟩ refine ⟨f_ext', ?_, ?_⟩ · rw [LipschitzWith.coordinate] exact hgl · intro a hyp ext i exact (hgeq i) hyp
Div.lean
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.GroupWithZero.Action.Pi import Mathlib.Algebra.Order.Group.Nat import Mathlib.Algebra.Order.Module.Defs import Mathlib.Algebra.Order.Sub.Basic import Mathlib.Data.Finsupp.SMulWithZero import Mathlib.Order.Preorder.Finsupp /-! # Flooring, ceiling division This file defines division rounded up and down. The setup is an ordered monoid `α` acting on an ordered monoid `β`. If `a : α`, `b : β`, we would like to be able to "divide" `b` by `a`, namely find `c : β` such that `a • c = b`. This is of course not always possible, but in some cases at least there is a least `c` such that `b ≤ a • c` and a greatest `c` such that `a • c ≤ b`. We call the first one the "ceiling division of `b` by `a`" and the second one the "flooring division of `b` by `a`" If `α` and `β` are both `ℕ`, then one can check that our flooring and ceiling divisions really are the floor and ceil of the exact division. If `α` is `ℕ` and `β` is the functions `ι → ℕ`, then the flooring and ceiling divisions are taken pointwise. In order theory terms, those operations are respectively the right and left adjoints to the map `b ↦ a • b`. ## Main declarations * `FloorDiv`: Typeclass for the existence of a flooring division, denoted `b ⌊/⌋ a`. * `CeilDiv`: Typeclass for the existence of a ceiling division, denoted `b ⌈/⌉ a`. Note in both cases we only allow dividing by positive inputs. We enforce the following junk values: * `b ⌊/⌋ a = b ⌈/⌉ a = 0` if `a ≤ 0` * `0 ⌊/⌋ a = 0 ⌈/⌉ a = 0` ## Notation * `b ⌊/⌋ a` for the flooring division of `b` by `a` * `b ⌈/⌉ a` for the ceiling division of `b` by `a` ## TODO * `norm_num` extension * Prove `⌈a / b⌉ = a ⌈/⌉ b` when `a, b : ℕ` -/ variable {ι α β : Type*} section OrderedAddCommMonoid variable (α β) [AddCommMonoid α] [PartialOrder α] [AddCommMonoid β] [PartialOrder β] [SMulZeroClass α β] /-- Typeclass for division rounded down. For each `a > 0`, this asserts the existence of a right adjoint to the map `b ↦ a • b : β → β`. -/ class FloorDiv where /-- Flooring division. If `a > 0`, then `b ⌊/⌋ a` is the greatest `c` such that `a • c ≤ b`. -/ floorDiv : β → α → β /-- Do not use this. Use `gc_floorDiv_smul` or `gc_floorDiv_mul` instead. -/ protected floorDiv_gc ⦃a⦄ : 0 < a → GaloisConnection (a • ·) (floorDiv · a) /-- Do not use this. Use `floorDiv_nonpos` instead. -/ protected floorDiv_nonpos ⦃a⦄ : a ≤ 0 → ∀ b, floorDiv b a = 0 /-- Do not use this. Use `zero_floorDiv` instead. -/ protected zero_floorDiv (a) : floorDiv 0 a = 0 /-- Typeclass for division rounded up. For each `a > 0`, this asserts the existence of a left adjoint to the map `b ↦ a • b : β → β`. -/ class CeilDiv where /-- Ceiling division. If `a > 0`, then `b ⌈/⌉ a` is the least `c` such that `b ≤ a • c`. -/ ceilDiv : β → α → β /-- Do not use this. Use `gc_smul_ceilDiv` or `gc_mul_ceilDiv` instead. -/ protected ceilDiv_gc ⦃a⦄ : 0 < a → GaloisConnection (ceilDiv · a) (a • ·) /-- Do not use this. Use `ceilDiv_nonpos` instead. -/ protected ceilDiv_nonpos ⦃a⦄ : a ≤ 0 → ∀ b, ceilDiv b a = 0 /-- Do not use this. Use `zero_ceilDiv` instead. -/ protected zero_ceilDiv (a) : ceilDiv 0 a = 0 @[inherit_doc] infixl:70 " ⌊/⌋ " => FloorDiv.floorDiv @[inherit_doc] infixl:70 " ⌈/⌉ " => CeilDiv.ceilDiv variable {α β} section FloorDiv variable [FloorDiv α β] {a : α} {b c : β} lemma gc_floorDiv_smul (ha : 0 < a) : GaloisConnection (a • · : β → β) (· ⌊/⌋ a) := FloorDiv.floorDiv_gc ha @[simp] lemma le_floorDiv_iff_smul_le (ha : 0 < a) : c ≤ b ⌊/⌋ a ↔ a • c ≤ b := (gc_floorDiv_smul ha _ _).symm @[simp] lemma floorDiv_of_nonpos (ha : a ≤ 0) (b : β) : b ⌊/⌋ a = 0 := FloorDiv.floorDiv_nonpos ha _ lemma floorDiv_zero (b : β) : b ⌊/⌋ (0 : α) = 0 := by simp @[simp] lemma zero_floorDiv (a : α) : (0 : β) ⌊/⌋ a = 0 := FloorDiv.zero_floorDiv _ lemma smul_floorDiv_le (ha : 0 < a) : a • (b ⌊/⌋ a) ≤ b := (le_floorDiv_iff_smul_le ha).1 le_rfl end FloorDiv section CeilDiv variable [CeilDiv α β] {a : α} {b c : β} lemma gc_smul_ceilDiv (ha : 0 < a) : GaloisConnection (· ⌈/⌉ a) (a • · : β → β) := CeilDiv.ceilDiv_gc ha @[simp] lemma ceilDiv_le_iff_le_smul (ha : 0 < a) : b ⌈/⌉ a ≤ c ↔ b ≤ a • c := gc_smul_ceilDiv ha _ _ @[simp] lemma ceilDiv_of_nonpos (ha : a ≤ 0) (b : β) : b ⌈/⌉ a = 0 := CeilDiv.ceilDiv_nonpos ha _ lemma ceilDiv_zero (b : β) : b ⌈/⌉ (0 : α) = 0 := by simp @[simp] lemma zero_ceilDiv (a : α) : (0 : β) ⌈/⌉ a = 0 := CeilDiv.zero_ceilDiv _ lemma le_smul_ceilDiv (ha : 0 < a) : b ≤ a • (b ⌈/⌉ a) := (ceilDiv_le_iff_le_smul ha).1 le_rfl end CeilDiv end OrderedAddCommMonoid section LinearOrderedAddCommMonoid variable [AddCommMonoid α] [LinearOrder α] [AddCommMonoid β] [PartialOrder β] [SMulZeroClass α β] [PosSMulReflectLE α β] [FloorDiv α β] [CeilDiv α β] {a : α} {b : β} lemma floorDiv_le_ceilDiv : b ⌊/⌋ a ≤ b ⌈/⌉ a := by obtain ha | ha := le_or_gt a 0 · simp [ha] · exact le_of_smul_le_smul_left ((smul_floorDiv_le ha).trans <| le_smul_ceilDiv ha) ha end LinearOrderedAddCommMonoid section OrderedSemiring variable [Semiring α] [PartialOrder α] [AddCommMonoid β] [PartialOrder β] [MulActionWithZero α β] section FloorDiv variable [FloorDiv α β] {a : α} @[simp] lemma floorDiv_one [IsOrderedRing α] [Nontrivial α] (b : β) : b ⌊/⌋ (1 : α) = b := eq_of_forall_le_iff <| fun c ↦ by simp [zero_lt_one' α] @[simp] lemma smul_floorDiv [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) (b : β) : a • b ⌊/⌋ a = b := eq_of_forall_le_iff <| by simp [smul_le_smul_iff_of_pos_left, ha] end FloorDiv section CeilDiv variable [CeilDiv α β] {a : α} @[simp] lemma ceilDiv_one [IsOrderedRing α] [Nontrivial α] (b : β) : b ⌈/⌉ (1 : α) = b := eq_of_forall_ge_iff <| fun c ↦ by simp [zero_lt_one' α] @[simp] lemma smul_ceilDiv [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) (b : β) : a • b ⌈/⌉ a = b := eq_of_forall_ge_iff <| by simp [smul_le_smul_iff_of_pos_left, ha] end CeilDiv section FloorDiv variable [FloorDiv α α] {a b c : α} lemma gc_floorDiv_mul (ha : 0 < a) : GaloisConnection (a * ·) (· ⌊/⌋ a) := gc_floorDiv_smul ha lemma le_floorDiv_iff_mul_le (ha : 0 < a) : c ≤ b ⌊/⌋ a ↔ a • c ≤ b := le_floorDiv_iff_smul_le ha end FloorDiv section CeilDiv variable [CeilDiv α α] {a b c : α} lemma gc_mul_ceilDiv (ha : 0 < a) : GaloisConnection (· ⌈/⌉ a) (a * ·) := gc_smul_ceilDiv ha lemma ceilDiv_le_iff_le_mul (ha : 0 < a) : b ⌈/⌉ a ≤ c ↔ b ≤ a * c := ceilDiv_le_iff_le_smul ha end CeilDiv end OrderedSemiring namespace Nat instance instFloorDiv : FloorDiv ℕ ℕ where floorDiv := HDiv.hDiv floorDiv_gc a ha := by simpa [mul_comm] using Nat.galoisConnection_mul_div ha floorDiv_nonpos a ha b := by rw [ha.antisymm <| zero_le _, Nat.div_zero] zero_floorDiv := Nat.zero_div instance instCeilDiv : CeilDiv ℕ ℕ where ceilDiv a b := (a + b - 1) / b ceilDiv_gc a ha b c := by simp [div_le_iff_le_mul_add_pred ha, add_assoc, tsub_add_cancel_of_le <| succ_le_iff.2 ha] ceilDiv_nonpos a ha b := by simp_rw [ha.antisymm <| zero_le _, Nat.div_zero] zero_ceilDiv a := by cases a <;> simp [Nat.div_eq_zero_iff] @[simp] lemma floorDiv_eq_div (a b : ℕ) : a ⌊/⌋ b = a / b := rfl lemma ceilDiv_eq_add_pred_div (a b : ℕ) : a ⌈/⌉ b = (a + b - 1) / b := rfl end Nat namespace Pi variable {π : ι → Type*} [AddCommMonoid α] [PartialOrder α] [∀ i, AddCommMonoid (π i)] [∀ i, PartialOrder (π i)] [∀ i, SMulZeroClass α (π i)] section FloorDiv variable [∀ i, FloorDiv α (π i)] instance instFloorDiv : FloorDiv α (∀ i, π i) where floorDiv f a i := f i ⌊/⌋ a floorDiv_gc _a ha _f _g := forall_congr' fun _i ↦ gc_floorDiv_smul ha _ _ floorDiv_nonpos a ha f := by ext i; exact floorDiv_of_nonpos ha _ zero_floorDiv a := by ext i; exact zero_floorDiv a lemma floorDiv_def (f : ∀ i, π i) (a : α) : f ⌊/⌋ a = fun i ↦ f i ⌊/⌋ a := rfl @[simp] lemma floorDiv_apply (f : ∀ i, π i) (a : α) (i : ι) : (f ⌊/⌋ a) i = f i ⌊/⌋ a := rfl end FloorDiv section CeilDiv variable [∀ i, CeilDiv α (π i)] instance instCeilDiv : CeilDiv α (∀ i, π i) where ceilDiv f a i := f i ⌈/⌉ a ceilDiv_gc _a ha _f _g := forall_congr' fun _i ↦ gc_smul_ceilDiv ha _ _ ceilDiv_nonpos a ha f := by ext i; exact ceilDiv_of_nonpos ha _ zero_ceilDiv a := by ext; exact zero_ceilDiv _ lemma ceilDiv_def (f : ∀ i, π i) (a : α) : f ⌈/⌉ a = fun i ↦ f i ⌈/⌉ a := rfl @[simp] lemma ceilDiv_apply (f : ∀ i, π i) (a : α) (i : ι) : (f ⌈/⌉ a) i = f i ⌈/⌉ a := rfl end CeilDiv end Pi namespace Finsupp variable [AddCommMonoid α] [PartialOrder α] [AddCommMonoid β] [PartialOrder β] [SMulZeroClass α β] section FloorDiv variable [FloorDiv α β] {f : ι →₀ β} {a : α} noncomputable instance instFloorDiv : FloorDiv α (ι →₀ β) where floorDiv f a := f.mapRange (· ⌊/⌋ a) <| zero_floorDiv _ floorDiv_gc _a ha f _g := forall_congr' fun i ↦ by simpa only [coe_smul, Pi.smul_apply, mapRange_apply] using gc_floorDiv_smul ha (f i) _ floorDiv_nonpos a ha f := by ext i; exact floorDiv_of_nonpos ha _ zero_floorDiv a := by ext; exact zero_floorDiv _ lemma floorDiv_def (f : ι →₀ β) (a : α) : f ⌊/⌋ a = f.mapRange (· ⌊/⌋ a) (zero_floorDiv _) := rfl @[norm_cast] lemma coe_floorDiv (f : ι →₀ β) (a : α) : f ⌊/⌋ a = fun i ↦ f i ⌊/⌋ a := rfl @[simp] lemma floorDiv_apply (f : ι →₀ β) (a : α) (i : ι) : (f ⌊/⌋ a) i = f i ⌊/⌋ a := rfl lemma support_floorDiv_subset : (f ⌊/⌋ a).support ⊆ f.support := by simp +contextual [Finset.subset_iff, not_imp_not] end FloorDiv section CeilDiv variable [CeilDiv α β] {f : ι →₀ β} {a : α} noncomputable instance instCeilDiv : CeilDiv α (ι →₀ β) where ceilDiv f a := f.mapRange (· ⌈/⌉ a) <| zero_ceilDiv _ ceilDiv_gc _a ha f _g := forall_congr' fun i ↦ by simpa only [coe_smul, Pi.smul_apply, mapRange_apply] using gc_smul_ceilDiv ha (f i) _ ceilDiv_nonpos a ha f := by ext i; exact ceilDiv_of_nonpos ha _ zero_ceilDiv a := by ext; exact zero_ceilDiv _ lemma ceilDiv_def (f : ι →₀ β) (a : α) : f ⌈/⌉ a = f.mapRange (· ⌈/⌉ a) (zero_ceilDiv _) := rfl @[norm_cast] lemma coe_ceilDiv_def (f : ι →₀ β) (a : α) : f ⌈/⌉ a = fun i ↦ f i ⌈/⌉ a := rfl @[simp] lemma ceilDiv_apply (f : ι →₀ β) (a : α) (i : ι) : (f ⌈/⌉ a) i = f i ⌈/⌉ a := rfl lemma support_ceilDiv_subset : (f ⌈/⌉ a).support ⊆ f.support := by simp +contextual [Finset.subset_iff, not_imp_not] end CeilDiv end Finsupp /-- This is the motivating example. -/ noncomputable example : FloorDiv ℕ (ℕ →₀ ℕ) := inferInstance
Reflective.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.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Functor.EpiMono import Mathlib.CategoryTheory.HomCongr /-! # Reflective functors Basic properties of reflective functors, especially those relating to their essential image. Note properties of reflective functors relating to limits and colimits are included in `Mathlib/CategoryTheory/Monad/Limits.lean`. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ noncomputable section namespace CategoryTheory open Category Adjunction variable {C : Type u₁} {D : Type u₂} {E : Type u₃} variable [Category.{v₁} C] [Category.{v₂} D] [Category.{v₃} E] /-- A functor is *reflective*, or *a reflective inclusion*, if it is fully faithful and right adjoint. -/ class Reflective (R : D ⥤ C) extends R.Full, R.Faithful where /-- a choice of a left adjoint to `R` -/ L : C ⥤ D /-- `R` is a right adjoint -/ adj : L ⊣ R variable (i : D ⥤ C) /-- The reflector `C ⥤ D` when `R : D ⥤ C` is reflective. -/ def reflector [Reflective i] : C ⥤ D := Reflective.L (R := i) /-- The adjunction `reflector i ⊣ i` when `i` is reflective. -/ def reflectorAdjunction [Reflective i] : reflector i ⊣ i := Reflective.adj instance [Reflective i] : i.IsRightAdjoint := ⟨_, ⟨reflectorAdjunction i⟩⟩ instance [Reflective i] : (reflector i).IsLeftAdjoint := ⟨_, ⟨reflectorAdjunction i⟩⟩ /-- A reflective functor is fully faithful. -/ def Functor.fullyFaithfulOfReflective [Reflective i] : i.FullyFaithful := (reflectorAdjunction i).fullyFaithfulROfIsIsoCounit -- TODO: This holds more generally for idempotent adjunctions, not just reflective adjunctions. /-- For a reflective functor `i` (with left adjoint `L`), with unit `η`, we have `η_iL = iL η`. -/ theorem unit_obj_eq_map_unit [Reflective i] (X : C) : (reflectorAdjunction i).unit.app (i.obj ((reflector i).obj X)) = i.map ((reflector i).map ((reflectorAdjunction i).unit.app X)) := by rw [← cancel_mono (i.map ((reflectorAdjunction i).counit.app ((reflector i).obj X))), ← i.map_comp] simp /-- When restricted to objects in `D` given by `i : D ⥤ C`, the unit is an isomorphism. In other words, `η_iX` is an isomorphism for any `X` in `D`. More generally this applies to objects essentially in the reflective subcategory, see `Functor.essImage.unit_isIso`. -/ example [Reflective i] {B : D} : IsIso ((reflectorAdjunction i).unit.app (i.obj B)) := inferInstance variable {i} /-- If `A` is essentially in the image of a reflective functor `i`, then `η_A` is an isomorphism. This gives that the "witness" for `A` being in the essential image can instead be given as the reflection of `A`, with the isomorphism as `η_A`. (For any `B` in the reflective subcategory, we automatically have that `ε_B` is an iso.) -/ theorem Functor.essImage.unit_isIso [Reflective i] {A : C} (h : i.essImage A) : IsIso ((reflectorAdjunction i).unit.app A) := by rwa [isIso_unit_app_iff_mem_essImage] /-- If `η_A` is a split monomorphism, then `A` is in the reflective subcategory. -/ theorem mem_essImage_of_unit_isSplitMono [Reflective i] {A : C} [IsSplitMono ((reflectorAdjunction i).unit.app A)] : i.essImage A := by let η : 𝟭 C ⟶ reflector i ⋙ i := (reflectorAdjunction i).unit haveI : IsIso (η.app (i.obj ((reflector i).obj A))) := Functor.essImage.unit_isIso ((i.obj_mem_essImage _)) have : Epi (η.app A) := by refine @epi_of_epi _ _ _ _ _ (retraction (η.app A)) (η.app A) ?_ rw [show retraction _ ≫ η.app A = _ from η.naturality (retraction (η.app A))] apply epi_comp (η.app (i.obj ((reflector i).obj A))) haveI := isIso_of_epi_of_isSplitMono (η.app A) exact (reflectorAdjunction i).mem_essImage_of_unit_isIso A /-- Composition of reflective functors. -/ instance Reflective.comp (F : C ⥤ D) (G : D ⥤ E) [Reflective F] [Reflective G] : Reflective (F ⋙ G) where L := reflector G ⋙ reflector F adj := (reflectorAdjunction G).comp (reflectorAdjunction F) /-- (Implementation) Auxiliary definition for `unitCompPartialBijective`. -/ def unitCompPartialBijectiveAux [Reflective i] (A : C) (B : D) : (A ⟶ i.obj B) ≃ (i.obj ((reflector i).obj A) ⟶ i.obj B) := ((reflectorAdjunction i).homEquiv _ _).symm.trans (Functor.FullyFaithful.ofFullyFaithful i).homEquiv /-- The description of the inverse of the bijection `unitCompPartialBijectiveAux`. -/ theorem unitCompPartialBijectiveAux_symm_apply [Reflective i] {A : C} {B : D} (f : i.obj ((reflector i).obj A) ⟶ i.obj B) : (unitCompPartialBijectiveAux _ _).symm f = (reflectorAdjunction i).unit.app A ≫ f := by simp [unitCompPartialBijectiveAux, Adjunction.homEquiv_unit] /-- If `i` has a reflector `L`, then the function `(i.obj (L.obj A) ⟶ B) → (A ⟶ B)` given by precomposing with `η.app A` is a bijection provided `B` is in the essential image of `i`. That is, the function `fun (f : i.obj (L.obj A) ⟶ B) ↦ η.app A ≫ f` is bijective, as long as `B` is in the essential image of `i`. This definition gives an equivalence: the key property that the inverse can be described nicely is shown in `unitCompPartialBijective_symm_apply`. This establishes there is a natural bijection `(A ⟶ B) ≃ (i.obj (L.obj A) ⟶ B)`. In other words, from the point of view of objects in `D`, `A` and `i.obj (L.obj A)` look the same: specifically that `η.app A` is an isomorphism. -/ def unitCompPartialBijective [Reflective i] (A : C) {B : C} (hB : i.essImage B) : (A ⟶ B) ≃ (i.obj ((reflector i).obj A) ⟶ B) := calc (A ⟶ B) ≃ (A ⟶ i.obj (Functor.essImage.witness hB)) := Iso.homCongr (Iso.refl _) hB.getIso.symm _ ≃ (i.obj _ ⟶ i.obj (Functor.essImage.witness hB)) := unitCompPartialBijectiveAux _ _ _ ≃ (i.obj ((reflector i).obj A) ⟶ B) := Iso.homCongr (Iso.refl _) (Functor.essImage.getIso hB) @[simp] theorem unitCompPartialBijective_symm_apply [Reflective i] (A : C) {B : C} (hB : i.essImage B) (f) : (unitCompPartialBijective A hB).symm f = (reflectorAdjunction i).unit.app A ≫ f := by simp [unitCompPartialBijective, unitCompPartialBijectiveAux_symm_apply] theorem unitCompPartialBijective_symm_natural [Reflective i] (A : C) {B B' : C} (h : B ⟶ B') (hB : i.essImage B) (hB' : i.essImage B') (f : i.obj ((reflector i).obj A) ⟶ B) : (unitCompPartialBijective A hB').symm (f ≫ h) = (unitCompPartialBijective A hB).symm f ≫ h := by simp theorem unitCompPartialBijective_natural [Reflective i] (A : C) {B B' : C} (h : B ⟶ B') (hB : i.essImage B) (hB' : i.essImage B') (f : A ⟶ B) : (unitCompPartialBijective A hB') (f ≫ h) = unitCompPartialBijective A hB f ≫ h := by rw [← Equiv.eq_symm_apply, unitCompPartialBijective_symm_natural A h, Equiv.symm_apply_apply] instance [Reflective i] (X : Functor.EssImageSubcategory i) : IsIso (NatTrans.app (reflectorAdjunction i).unit X.obj) := Functor.essImage.unit_isIso X.property -- These attributes are necessary to make automation work in `equivEssImageOfReflective`. -- Making them global doesn't break anything elsewhere, but this is enough for now. -- TODO: investigate further. attribute [local simp 900] ObjectProperty.ι_map in attribute [local ext] Functor.essImage_ext in /-- If `i : D ⥤ C` is reflective, the inverse functor of `i ≌ F.essImage` can be explicitly defined by the reflector. -/ @[simps] def equivEssImageOfReflective [Reflective i] : D ≌ i.EssImageSubcategory where functor := i.toEssImage inverse := i.essImage.ι ⋙ reflector i unitIso := (asIso <| (reflectorAdjunction i).counit).symm counitIso := Functor.fullyFaithfulCancelRight i.essImage.ι <| NatIso.ofComponents (fun X ↦ (asIso ((reflectorAdjunction i).unit.app X.obj)).symm) /-- A functor is *coreflective*, or *a coreflective inclusion*, if it is fully faithful and left adjoint. -/ class Coreflective (L : C ⥤ D) extends L.Full, L.Faithful where /-- a choice of a right adjoint to `L` -/ R : D ⥤ C /-- `L` is a left adjoint -/ adj : L ⊣ R variable (j : C ⥤ D) /-- The coreflector `D ⥤ C` when `L : C ⥤ D` is coreflective. -/ def coreflector [Coreflective j] : D ⥤ C := Coreflective.R (L := j) /-- The adjunction `j ⊣ coreflector j` when `j` is coreflective. -/ def coreflectorAdjunction [Coreflective j] : j ⊣ coreflector j := Coreflective.adj instance [Coreflective j] : j.IsLeftAdjoint := ⟨_, ⟨coreflectorAdjunction j⟩⟩ instance [Coreflective j] : (coreflector j).IsRightAdjoint := ⟨_, ⟨coreflectorAdjunction j⟩⟩ /-- A coreflective functor is fully faithful. -/ def Functor.fullyFaithfulOfCoreflective [Coreflective j] : j.FullyFaithful := (coreflectorAdjunction j).fullyFaithfulLOfIsIsoUnit lemma counit_obj_eq_map_counit [Coreflective j] (X : D) : (coreflectorAdjunction j).counit.app (j.obj ((coreflector j).obj X)) = j.map ((coreflector j).map ((coreflectorAdjunction j).counit.app X)) := by rw [← cancel_epi (j.map ((coreflectorAdjunction j).unit.app ((coreflector j).obj X))), ← j.map_comp] simp example [Coreflective j] {B : C} : IsIso ((coreflectorAdjunction j).counit.app (j.obj B)) := inferInstance variable {j} lemma Functor.essImage.counit_isIso [Coreflective j] {A : D} (h : j.essImage A) : IsIso ((coreflectorAdjunction j).counit.app A) := by rwa [isIso_counit_app_iff_mem_essImage] lemma mem_essImage_of_counit_isSplitEpi [Coreflective j] {A : D} [IsSplitEpi ((coreflectorAdjunction j).counit.app A)] : j.essImage A := by let ε : coreflector j ⋙ j ⟶ 𝟭 D := (coreflectorAdjunction j).counit haveI : IsIso (ε.app (j.obj ((coreflector j).obj A))) := Functor.essImage.counit_isIso ((j.obj_mem_essImage _)) have : Mono (ε.app A) := by refine @mono_of_mono _ _ _ _ _ (ε.app A) (section_ (ε.app A)) ?_ rw [show ε.app A ≫ section_ _ = _ from (ε.naturality (section_ (ε.app A))).symm] apply mono_comp _ (ε.app (j.obj ((coreflector j).obj A))) haveI := isIso_of_mono_of_isSplitEpi (ε.app A) exact (coreflectorAdjunction j).mem_essImage_of_counit_isIso A instance Coreflective.comp (F : C ⥤ D) (G : D ⥤ E) [Coreflective F] [Coreflective G] : Coreflective (F ⋙ G) where R := coreflector G ⋙ coreflector F adj := (coreflectorAdjunction F).comp (coreflectorAdjunction G) end CategoryTheory
TotalComplexSymmetry.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.TotalComplex /-! The symmetry of the total complex of a bicomplex Let `K : HomologicalComplex₂ C c₁ c₂` be a bicomplex. If we assume both `[TotalComplexShape c₁ c₂ c]` and `[TotalComplexShape c₂ c₁ c]`, we may form the total complex `K.total c` and `K.flip.total c`. In this file, we show that if we assume `[TotalComplexShapeSymmetry c₁ c₂ c]`, then there is an isomorphism `K.totalFlipIso c : K.flip.total c ≅ K.total c`. Moreover, if we also have `[TotalComplexShapeSymmetry c₂ c₁ c]` and that the signs are compatible `[TotalComplexShapeSymmetrySymmetry c₁ c₂ c]`, then the isomorphisms `K.totalFlipIso c` and `K.flip.totalFlipIso c` are inverse to each other. -/ assert_not_exists Ideal TwoSidedIdeal open CategoryTheory Category Limits namespace HomologicalComplex₂ variable {C I₁ I₂ J : Type*} [Category C] [Preadditive C] {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} (K : HomologicalComplex₂ C c₁ c₂) (c : ComplexShape J) [TotalComplexShape c₁ c₂ c] [TotalComplexShape c₂ c₁ c] [TotalComplexShapeSymmetry c₁ c₂ c] instance [K.HasTotal c] : K.flip.HasTotal c := fun j => hasCoproduct_of_equiv_of_iso (K.toGradedObject.mapObjFun (ComplexShape.π c₁ c₂ c) j) _ (ComplexShape.symmetryEquiv c₁ c₂ c j) (fun _ => Iso.refl _) lemma flip_hasTotal_iff : K.flip.HasTotal c ↔ K.HasTotal c := by constructor · intro change K.flip.flip.HasTotal c have := TotalComplexShapeSymmetry.symmetry c₁ c₂ c infer_instance · intro infer_instance variable [K.HasTotal c] [DecidableEq J] attribute [local simp] smul_smul /-- Auxiliary definition for `totalFlipIso`. -/ noncomputable def totalFlipIsoX (j : J) : (K.flip.total c).X j ≅ (K.total c).X j where hom := K.flip.totalDesc (fun i₂ i₁ h => ComplexShape.σ c₁ c₂ c i₁ i₂ • K.ιTotal c i₁ i₂ j (by rw [← ComplexShape.π_symm c₁ c₂ c i₁ i₂, h])) inv := K.totalDesc (fun i₁ i₂ h => ComplexShape.σ c₁ c₂ c i₁ i₂ • K.flip.ιTotal c i₂ i₁ j (by rw [ComplexShape.π_symm c₁ c₂ c i₁ i₂, h])) hom_inv_id := by ext; simp inv_hom_id := by ext; simp @[reassoc] lemma totalFlipIsoX_hom_D₁ (j j' : J) : (K.totalFlipIsoX c j).hom ≫ K.D₁ c j j' = K.flip.D₂ c j j' ≫ (K.totalFlipIsoX c j').hom := by by_cases h₀ : c.Rel j j' · ext i₂ i₁ h₁ dsimp [totalFlipIsoX] rw [ι_totalDesc_assoc, Linear.units_smul_comp, ι_D₁, ι_D₂_assoc] dsimp by_cases h₂ : c₁.Rel i₁ (c₁.next i₁) · have h₃ : ComplexShape.π c₂ c₁ c ⟨i₂, c₁.next i₁⟩ = j' := by rw [← ComplexShape.next_π₂ c₂ c i₂ h₂, h₁, c.next_eq' h₀] have h₄ : ComplexShape.π c₁ c₂ c ⟨c₁.next i₁, i₂⟩ = j' := by rw [← h₃, ComplexShape.π_symm c₁ c₂ c] rw [K.d₁_eq _ h₂ _ _ h₄, K.flip.d₂_eq _ _ h₂ _ h₃, Linear.units_smul_comp, assoc, ι_totalDesc, Linear.comp_units_smul, smul_smul, smul_smul, ComplexShape.σ_ε₁ c₂ c h₂ i₂] dsimp only [flip_X_X, flip_X_d] · rw [K.d₁_eq_zero _ _ _ _ h₂, K.flip.d₂_eq_zero _ _ _ _ h₂, smul_zero, zero_comp] · rw [K.D₁_shape _ _ _ h₀, K.flip.D₂_shape c _ _ h₀, zero_comp, comp_zero] @[reassoc] lemma totalFlipIsoX_hom_D₂ (j j' : J) : (K.totalFlipIsoX c j).hom ≫ K.D₂ c j j' = K.flip.D₁ c j j' ≫ (K.totalFlipIsoX c j').hom := by by_cases h₀ : c.Rel j j' · ext i₂ i₁ h₁ dsimp [totalFlipIsoX] rw [ι_totalDesc_assoc, Linear.units_smul_comp, ι_D₂, ι_D₁_assoc] dsimp by_cases h₂ : c₂.Rel i₂ (c₂.next i₂) · have h₃ : ComplexShape.π c₂ c₁ c (ComplexShape.next c₂ i₂, i₁) = j' := by rw [← ComplexShape.next_π₁ c₁ c h₂ i₁, h₁, c.next_eq' h₀] have h₄ : ComplexShape.π c₁ c₂ c (i₁, ComplexShape.next c₂ i₂) = j' := by rw [← h₃, ComplexShape.π_symm c₁ c₂ c] rw [K.d₂_eq _ _ h₂ _ h₄, K.flip.d₁_eq _ h₂ _ _ h₃, Linear.units_smul_comp, assoc, ι_totalDesc, Linear.comp_units_smul, smul_smul, smul_smul, ComplexShape.σ_ε₂ c₁ c i₁ h₂] rfl · rw [K.d₂_eq_zero _ _ _ _ h₂, K.flip.d₁_eq_zero _ _ _ _ h₂, smul_zero, zero_comp] · rw [K.D₂_shape _ _ _ h₀, K.flip.D₁_shape c _ _ h₀, zero_comp, comp_zero] /-- The symmetry isomorphism `K.flip.total c ≅ K.total c` of the total complex of a bicomplex when we have `[TotalComplexShapeSymmetry c₁ c₂ c]`. -/ noncomputable def totalFlipIso : K.flip.total c ≅ K.total c := HomologicalComplex.Hom.isoOfComponents (K.totalFlipIsoX c) (fun j j' _ => by simp only [total_d, Preadditive.comp_add, totalFlipIsoX_hom_D₁, totalFlipIsoX_hom_D₂, Preadditive.add_comp] rw [add_comm]) @[reassoc] lemma totalFlipIso_hom_f_D₁ (j j' : J) : (K.totalFlipIso c).hom.f j ≫ K.D₁ c j j' = K.flip.D₂ c j j' ≫ (K.totalFlipIso c).hom.f j' := by apply totalFlipIsoX_hom_D₁ @[reassoc] lemma totalFlipIso_hom_f_D₂ (j j' : J) : (K.totalFlipIso c).hom.f j ≫ K.D₂ c j j' = K.flip.D₁ c j j' ≫ (K.totalFlipIso c).hom.f j' := by apply totalFlipIsoX_hom_D₂ @[reassoc (attr := simp)] lemma ιTotal_totalFlipIso_f_hom (i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₂ c₁ c (i₂, i₁) = j) : K.flip.ιTotal c i₂ i₁ j h ≫ (K.totalFlipIso c).hom.f j = ComplexShape.σ c₁ c₂ c i₁ i₂ • K.ιTotal c i₁ i₂ j (by rw [← ComplexShape.π_symm c₁ c₂ c i₁ i₂, h]) := by simp [totalFlipIso, totalFlipIsoX] @[reassoc (attr := simp)] lemma ιTotal_totalFlipIso_f_inv (i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₁ c₂ c (i₁, i₂) = j) : K.ιTotal c i₁ i₂ j h ≫ (K.totalFlipIso c).inv.f j = ComplexShape.σ c₁ c₂ c i₁ i₂ • K.flip.ιTotal c i₂ i₁ j (by rw [ComplexShape.π_symm c₁ c₂ c i₁ i₂, h]) := by simp [totalFlipIso, totalFlipIsoX] instance : K.flip.flip.HasTotal c := (inferInstance : K.HasTotal c) section variable [TotalComplexShapeSymmetry c₂ c₁ c] [TotalComplexShapeSymmetrySymmetry c₁ c₂ c] lemma flip_totalFlipIso : K.flip.totalFlipIso c = (K.totalFlipIso c).symm := by ext j i₁ i₂ h rw [Iso.symm_hom, ιTotal_totalFlipIso_f_hom] dsimp only [flip_flip] rw [ιTotal_totalFlipIso_f_inv, ComplexShape.σ_symm] end end HomologicalComplex₂
ssrAC.v
From HB Require Import structures. From Corelib Require Import PosDef. (* use #[warning="-hiding-delimiting-key"] attribute once we require Coq 8.18 *) (* (the warning was completely removed in 9.0) *) Set Warnings "-hiding-delimiting-key". From mathcomp Require Import ssreflect ssrbool ssrfun ssrnat eqtype seq bigop. Set Warnings "hiding-delimiting-key". Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. (************************************************************************) (* Small Scale Rewriting using Associativity and Commutativity *) (* *) (* Rewriting with AC (not modulo AC), using a small scale command. *) (* Replaces opA, opC, opAC, opCA, ... and any combinations of them *) (* *) (* Usage : *) (* rewrite [pattern](AC patternshape reordering) *) (* rewrite [pattern](ACl reordering) *) (* rewrite [pattern](ACof reordering reordering) *) (* rewrite [pattern]op.[AC patternshape reordering] *) (* rewrite [pattern]op.[ACl reordering] *) (* rewrite [pattern]op.[ACof reordering reordering] *) (* *) (* - if op is specified, the rule is specialized to op *) (* otherwise, the head symbol is a generic comm_law *) (* and the rewrite might be less efficient *) (* NOTE because of a bug in Coq's notations coq/coq#8190 *) (* op must not contain any hole. *) (* *%R.[AC p s] currently does not work because of that *) (* (@GRing.mul R).[AC p s] must be used instead *) (* *) (* - pattern is optional, as usual, but must be used to select the *) (* appropriate operator in case of ambiguity such an operator must *) (* have a canonical Monoid.com_law structure *) (* (additions, multiplications, conjunction and disjunction do) *) (* *) (* - patternshape is expressed using the syntax *) (* p := n | p * p' *) (* where "*" is purely formal *) (* and n > 0 is the number of left associated symbols *) (* examples of pattern shapes: *) (* + 4 represents (n * m * p * q) *) (* + (1*2) represents (n * (m * p)) *) (* *) (* - reordering is expressed using the syntax *) (* s := n | s * s' *) (* where "*" is purely formal and n > 0 is the position in the LHS *) (* positions start at 1 ! *) (* *) (* If the ACl variant is used, the patternshape defaults to the *) (* pattern fully associated to the left i.e. n i.e (x * y * ...) *) (* *) (* Examples of reorderings: *) (* - ACl ((1*2)*3) is the identity (and will fail with error message) *) (* - opAC == op.[ACl (1*3)*2] == op.[AC 3 ((1*3)*2)] *) (* - opCA == op.[AC (2*1) (1*2*3)] *) (* - opACA == op.[AC (2*2) ((1*3)*(2*4))] *) (* - rewrite opAC -opA == rewrite op.[ACl 1*(3*2)] *) (* ... *) (************************************************************************) Declare Scope AC_scope. Delimit Scope AC_scope with AC. Reserved Notation "op .[ 'ACof' p s ]" (p at level 1, left associativity). Reserved Notation "op .[ 'AC' p s ]" (p at level 1, left associativity). Reserved Notation "op .[ 'ACl' s ]" (left associativity). Definition change_type ty ty' (x : ty) (strategy : ty = ty') : ty' := ecast ty ty strategy x. Notation simplrefl := (ltac: (simpl; reflexivity)) (only parsing). Notation cbvrefl := (ltac: (cbv; reflexivity)) (only parsing). Notation vmrefl := (ltac: (vm_compute; reflexivity)) (only parsing). (* From stdlib *) Module Pos. Import Pos. (** ** Conversion with a decimal representation for printing/parsing *) Local Notation ten := (xO (xI (xO xH))). Fixpoint of_uint_acc (d:Decimal.uint) (acc:positive) := match d with | Decimal.Nil => acc | Decimal.D0 l => of_uint_acc l (mul ten acc) | Decimal.D1 l => of_uint_acc l (add 1 (mul ten acc)) | Decimal.D2 l => of_uint_acc l (add 1~0 (mul ten acc)) | Decimal.D3 l => of_uint_acc l (add 1~1 (mul ten acc)) | Decimal.D4 l => of_uint_acc l (add 1~0~0 (mul ten acc)) | Decimal.D5 l => of_uint_acc l (add 1~0~1 (mul ten acc)) | Decimal.D6 l => of_uint_acc l (add 1~1~0 (mul ten acc)) | Decimal.D7 l => of_uint_acc l (add 1~1~1 (mul ten acc)) | Decimal.D8 l => of_uint_acc l (add 1~0~0~0 (mul ten acc)) | Decimal.D9 l => of_uint_acc l (add 1~0~0~1 (mul ten acc)) end. Fixpoint of_uint (d:Decimal.uint) : N := match d with | Decimal.Nil => N0 | Decimal.D0 l => of_uint l | Decimal.D1 l => Npos (of_uint_acc l 1) | Decimal.D2 l => Npos (of_uint_acc l 1~0) | Decimal.D3 l => Npos (of_uint_acc l 1~1) | Decimal.D4 l => Npos (of_uint_acc l 1~0~0) | Decimal.D5 l => Npos (of_uint_acc l 1~0~1) | Decimal.D6 l => Npos (of_uint_acc l 1~1~0) | Decimal.D7 l => Npos (of_uint_acc l 1~1~1) | Decimal.D8 l => Npos (of_uint_acc l 1~0~0~0) | Decimal.D9 l => Npos (of_uint_acc l 1~0~0~1) end. Local Notation sixteen := (xO (xO (xO (xO xH)))). Fixpoint of_hex_uint_acc (d:Hexadecimal.uint) (acc:positive) := match d with | Hexadecimal.Nil => acc | Hexadecimal.D0 l => of_hex_uint_acc l (mul sixteen acc) | Hexadecimal.D1 l => of_hex_uint_acc l (add 1 (mul sixteen acc)) | Hexadecimal.D2 l => of_hex_uint_acc l (add 1~0 (mul sixteen acc)) | Hexadecimal.D3 l => of_hex_uint_acc l (add 1~1 (mul sixteen acc)) | Hexadecimal.D4 l => of_hex_uint_acc l (add 1~0~0 (mul sixteen acc)) | Hexadecimal.D5 l => of_hex_uint_acc l (add 1~0~1 (mul sixteen acc)) | Hexadecimal.D6 l => of_hex_uint_acc l (add 1~1~0 (mul sixteen acc)) | Hexadecimal.D7 l => of_hex_uint_acc l (add 1~1~1 (mul sixteen acc)) | Hexadecimal.D8 l => of_hex_uint_acc l (add 1~0~0~0 (mul sixteen acc)) | Hexadecimal.D9 l => of_hex_uint_acc l (add 1~0~0~1 (mul sixteen acc)) | Hexadecimal.Da l => of_hex_uint_acc l (add 1~0~1~0 (mul sixteen acc)) | Hexadecimal.Db l => of_hex_uint_acc l (add 1~0~1~1 (mul sixteen acc)) | Hexadecimal.Dc l => of_hex_uint_acc l (add 1~1~0~0 (mul sixteen acc)) | Hexadecimal.Dd l => of_hex_uint_acc l (add 1~1~0~1 (mul sixteen acc)) | Hexadecimal.De l => of_hex_uint_acc l (add 1~1~1~0 (mul sixteen acc)) | Hexadecimal.Df l => of_hex_uint_acc l (add 1~1~1~1 (mul sixteen acc)) end. Fixpoint of_hex_uint (d:Hexadecimal.uint) : N := match d with | Hexadecimal.Nil => N0 | Hexadecimal.D0 l => of_hex_uint l | Hexadecimal.D1 l => Npos (of_hex_uint_acc l 1) | Hexadecimal.D2 l => Npos (of_hex_uint_acc l 1~0) | Hexadecimal.D3 l => Npos (of_hex_uint_acc l 1~1) | Hexadecimal.D4 l => Npos (of_hex_uint_acc l 1~0~0) | Hexadecimal.D5 l => Npos (of_hex_uint_acc l 1~0~1) | Hexadecimal.D6 l => Npos (of_hex_uint_acc l 1~1~0) | Hexadecimal.D7 l => Npos (of_hex_uint_acc l 1~1~1) | Hexadecimal.D8 l => Npos (of_hex_uint_acc l 1~0~0~0) | Hexadecimal.D9 l => Npos (of_hex_uint_acc l 1~0~0~1) | Hexadecimal.Da l => Npos (of_hex_uint_acc l 1~0~1~0) | Hexadecimal.Db l => Npos (of_hex_uint_acc l 1~0~1~1) | Hexadecimal.Dc l => Npos (of_hex_uint_acc l 1~1~0~0) | Hexadecimal.Dd l => Npos (of_hex_uint_acc l 1~1~0~1) | Hexadecimal.De l => Npos (of_hex_uint_acc l 1~1~1~0) | Hexadecimal.Df l => Npos (of_hex_uint_acc l 1~1~1~1) end. Definition of_int (d:Decimal.int) : option positive := match d with | Decimal.Pos d => match of_uint d with | N0 => None | Npos p => Some p end | Decimal.Neg _ => None end. Definition of_hex_int (d:Hexadecimal.int) : option positive := match d with | Hexadecimal.Pos d => match of_hex_uint d with | N0 => None | Npos p => Some p end | Hexadecimal.Neg _ => None end. Definition of_num_int (d:Number.int) : option positive := match d with | Number.IntDecimal d => of_int d | Number.IntHexadecimal d => of_hex_int d end. Fixpoint to_little_uint p := match p with | xH => Decimal.D1 Decimal.Nil | xI p => Decimal.Little.succ_double (to_little_uint p) | xO p => Decimal.Little.double (to_little_uint p) end. Definition to_uint p := Decimal.rev (to_little_uint p). Definition to_num_uint p := Number.UIntDecimal (to_uint p). (** ** Successor *) Definition Nsucc n := match n with | N0 => Npos xH | Npos p => Npos (Pos.succ p) end. Lemma nat_of_succ_bin b : nat_of_bin (Nsucc b) = 1 + nat_of_bin b :> nat. Proof. by case: b => [//|p /=]; rewrite nat_of_succ_pos. Qed. Theorem eqb_eq p q : Pos.eqb p q = true <-> p=q. Proof. by elim: p q => [p IHp|p IHp|] [q|q|] //=; split=> [/IHp->//|]; case=> /IHp. Qed. End Pos. Module AC. HB.instance Definition _ := hasDecEq.Build positive (fun _ _ => equivP idP (Pos.eqb_eq _ _)). Inductive syntax := Leaf of positive | Op of syntax & syntax. Coercion serial := (fix loop (acc : seq positive) (s : syntax) := match s with | Leaf n => n :: acc | Op s s' => (loop^~ s (loop^~ s' acc)) end) [::]. Lemma serial_Op s1 s2 : Op s1 s2 = s1 ++ s2 :> seq _. Proof. rewrite /serial; set loop := (X in X [::]); rewrite -/loop. elim: s1 (loop [::] s2) => [n|s11 IHs1 s12 IHs2] //= l. by rewrite IHs1 [in RHS]IHs1 IHs2 catA. Qed. Definition Leaf_of_nat n := Leaf (Pos.sub (pos_of_nat n n) xH). Module Import Syntax. Bind Scope AC_scope with syntax. Number Notation positive Pos.of_num_int Pos.to_num_uint : AC_scope. Coercion Leaf : positive >-> syntax. Coercion Leaf_of_nat : nat >-> syntax. Notation "x * y" := (Op x%AC y%AC) : AC_scope. End Syntax. Definition pattern (s : syntax) := ((fix loop n s := match s with | Leaf 1%positive => (Leaf n, Pos.succ n) | Leaf m => Pos.iter (fun oi => (Op oi.1 (Leaf oi.2), Pos.succ oi.2)) (Leaf n, Pos.succ n) (Pos.sub m xH) | Op s s' => let: (p, n') := loop n s in let: (p', n'') := loop n' s' in (Op p p', n'') end) 1%positive s).1. Section eval. Variables (T : Type) (idx : T) (op : T -> T -> T). Inductive env := Empty | ENode of T & env & env. Definition pos := fix loop (e : env) p {struct e} := match e, p with | ENode t _ _, 1%positive => t | ENode t e _, (p~0)%positive => loop e p | ENode t _ e, (p~1)%positive => loop e p | _, _ => idx end. Definition set_pos (f : T -> T) := fix loop e p {struct p} := match e, p with | ENode t e e', 1%positive => ENode (f t) e e' | ENode t e e', (p~0)%positive => ENode t (loop e p) e' | ENode t e e', (p~1)%positive => ENode t e (loop e' p) | Empty, 1%positive => ENode (f idx) Empty Empty | Empty, (p~0)%positive => ENode idx (loop Empty p) Empty | Empty, (p~1)%positive => ENode idx Empty (loop Empty p) end. Lemma pos_set_pos (f : T -> T) e (p p' : positive) : pos (set_pos f e p) p' = if p == p' then f (pos e p) else pos e p'. Proof. by elim: p e p' => [p IHp|p IHp|] [|???] [?|?|]//=; rewrite IHp. Qed. Fixpoint unzip z (e : env) : env := match z with | [::] => e | (x, inl e') :: z' => unzip z' (ENode x e' e) | (x, inr e') :: z' => unzip z' (ENode x e e') end. Definition set_pos_trec (f : T -> T) := fix loop z e p {struct p} := match e, p with | ENode t e e', 1%positive => unzip z (ENode (f t) e e') | ENode t e e', (p~0)%positive => loop ((t, inr e') :: z) e p | ENode t e e', (p~1)%positive => loop ((t, inl e) :: z) e' p | Empty, 1%positive => unzip z (ENode (f idx) Empty Empty) | Empty, (p~0)%positive => loop ((idx, (inr Empty)) :: z) Empty p | Empty, (p~1)%positive => loop ((idx, (inl Empty)) :: z) Empty p end. Lemma set_pos_trecE f z e p : set_pos_trec f z e p = unzip z (set_pos f e p). Proof. by elim: p e z => [p IHp|p IHp|] [|???] [|[??]?] //=; rewrite ?IHp. Qed. Definition eval (e : env) := fix loop (s : syntax) := match s with | Leaf n => pos e n | Op s s' => op (loop s) (loop s') end. End eval. Arguments Empty {T}. Definition content := (fix loop (acc : env N) s := match s with | Leaf n => set_pos_trec N0 Pos.Nsucc [::] acc n | Op s s' => loop (loop acc s') s end) Empty. Lemma count_memE x (t : syntax) : count_mem x t = nat_of_bin (pos N0 (content t) x). Proof. rewrite /content; set loop := (X in X Empty); rewrite -/loop. rewrite -[LHS]addn0. have <- : nat_of_bin (pos N0 Empty x) = 0 :> nat by elim: x. elim: t Empty => [n|s IHs s' IHs'] e //=; last first. by rewrite serial_Op count_cat -addnA IHs' IHs. rewrite ?addn0 set_pos_trecE pos_set_pos; case: (altP eqP) => [->|] //=. by rewrite Pos.nat_of_succ_bin. Qed. Definition cforall N T : env N -> (env T -> Type) -> Type := env_rect (@^~ Empty) (fun _ e IHe e' IHe' R => forall x, IHe (fun xe => IHe' (R \o ENode x xe))). Lemma cforallP N T R : (forall e : env T, R e) -> forall (e : env N), cforall e R. Proof. move=> Re e; elim: e R Re => [|? e /= IHe e' IHe' ?? x] //=. by apply: IHe => ?; apply: IHe' => /=. Qed. Section eq_eval. Variables (T : Type) (idx : T) (op : Monoid.com_law idx). Lemma proof (p s : syntax) : content p = content s -> forall env, eval idx op env p = eval idx op env s. Proof. suff evalE env t : eval idx op env t = \big[op/idx]_(i <- t) (pos idx env i). move=> cps e; rewrite !evalE; apply: perm_big. by apply/allP => x _ /=; rewrite !count_memE cps. elim: t => //= [n|t -> t' ->]; last by rewrite serial_Op big_cat. by rewrite big_cons big_nil Monoid.mulm1. Qed. Definition direct p s ps := cforallP (@proof p s ps) (content p). End eq_eval. Module Exports. Export AC.Syntax. End Exports. End AC. Export AC.Exports. Notation AC_check_pattern := (ltac: (match goal with |- AC.content ?pat = AC.content ?ord => let pat' := fresh "pat" in let pat' := eval compute in pat in tryif unify pat' ord then fail 1 "AC: equality between" pat "and" ord "is trivial, cannot progress" else tryif vm_compute; reflexivity then idtac else fail 2 "AC: mismatch between shape" pat "=" pat' "and reordering" ord | |- ?G => fail 3 "AC: no pattern to check" G end)) (only parsing). Notation opACof law p s := ((fun T idx op assoc lid rid comm => (change_type (@AC.direct T idx (Monoid.ComLaw.Pack (* FIXME: find a way to make this robust to hierarchy evolutions *) (Monoid.ComLaw.Class (SemiGroup.isLaw.Axioms_ op assoc) (Monoid.isMonoidLaw.Axioms_ idx op lid rid) (SemiGroup.isCommutativeLaw.Axioms_ op comm))) p%AC s%AC AC_check_pattern) cbvrefl)) _ _ law (Monoid.mulmA _) (Monoid.mul1m _) (Monoid.mulm1 _) (Monoid.mulmC _)) (only parsing). Notation opAC op p s := (opACof op (AC.pattern p%AC) s%AC) (only parsing). Notation opACl op s := (opAC op (AC.Leaf_of_nat (size (AC.serial s%AC))) s%AC) (only parsing). Notation "op .[ 'ACof' p s ]" := (opACof op p%AC s%AC) (only parsing). Notation "op .[ 'AC' p s ]" := (opAC op p%AC s%AC) (only parsing). Notation "op .[ 'ACl' s ]" := (opACl op s%AC) (only parsing). Notation AC_strategy := (ltac: (cbv -[Monoid.ComLaw.sort Monoid.Law.sort]; reflexivity)) (only parsing). Notation ACof p s := (change_type (@AC.direct _ _ _ p%AC s%AC AC_check_pattern) AC_strategy) (only parsing). Notation AC p s := (ACof (AC.pattern p%AC) s%AC) (only parsing). Notation ACl s := (AC (AC.Leaf_of_nat (size (AC.serial s%AC))) s%AC) (only parsing).
Basic.lean
/- Copyright (c) 2020 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard -/ import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.LocalRing.RingHom.Basic import Mathlib.RingTheory.UniqueFactorizationDomain.Basic import Mathlib.RingTheory.Valuation.PrimeMultiplicity import Mathlib.RingTheory.Valuation.ValuationRing /-! # Discrete valuation rings This file defines discrete valuation rings (DVRs) and develops a basic interface for them. ## Important definitions There are various definitions of a DVR in the literature; we define a DVR to be a local PID which is not a field (the first definition in Wikipedia) and prove that this is equivalent to being a PID with a unique non-zero prime ideal (the definition in Serre's book "Local Fields"). Let R be an integral domain, assumed to be a principal ideal ring and a local ring. * `IsDiscreteValuationRing R` : a predicate expressing that R is a DVR. ### Definitions * `addVal R : AddValuation R PartENat` : the additive valuation on a DVR. ## Implementation notes It's a theorem that an element of a DVR is a uniformizer if and only if it's irreducible. We do not hence define `Uniformizer` at all, because we can use `Irreducible` instead. ## Tags discrete valuation ring -/ universe u open Ideal IsLocalRing /-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which is not a field. -/ class IsDiscreteValuationRing (R : Type u) [CommRing R] [IsDomain R] : Prop extends IsPrincipalIdealRing R, IsLocalRing R where not_a_field' : maximalIdeal R ≠ ⊥ namespace IsDiscreteValuationRing variable (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] theorem not_a_field : maximalIdeal R ≠ ⊥ := not_a_field' /-- A discrete valuation ring `R` is not a field. -/ theorem not_isField : ¬IsField R := IsLocalRing.isField_iff_maximalIdeal_eq.not.mpr (not_a_field R) variable {R} open PrincipalIdealRing theorem irreducible_of_span_eq_maximalIdeal {R : Type*} [CommSemiring R] [IsLocalRing R] [IsDomain R] (ϖ : R) (hϖ : ϖ ≠ 0) (h : maximalIdeal R = Ideal.span {ϖ}) : Irreducible ϖ := by have h2 : ¬IsUnit ϖ := show ϖ ∈ maximalIdeal R from h.symm ▸ Submodule.mem_span_singleton_self ϖ refine ⟨h2, ?_⟩ intro a b hab by_contra! h obtain ⟨ha : a ∈ maximalIdeal R, hb : b ∈ maximalIdeal R⟩ := h rw [h, mem_span_singleton'] at ha hb rcases ha with ⟨a, rfl⟩ rcases hb with ⟨b, rfl⟩ rw [show a * ϖ * (b * ϖ) = ϖ * (ϖ * (a * b)) by ring] at hab apply hϖ apply eq_zero_of_mul_eq_self_right _ hab.symm exact fun hh => h2 (isUnit_of_dvd_one ⟨_, hh.symm⟩) /-- An element of a DVR is irreducible iff it is a uniformizer, that is, generates the maximal ideal of `R`. -/ theorem irreducible_iff_uniformizer (ϖ : R) : Irreducible ϖ ↔ maximalIdeal R = Ideal.span {ϖ} := ⟨fun hϖ => (eq_maximalIdeal (isMaximal_of_irreducible hϖ)).symm, fun h => irreducible_of_span_eq_maximalIdeal ϖ (fun e => not_a_field R <| by rwa [h, span_singleton_eq_bot]) h⟩ theorem _root_.Irreducible.maximalIdeal_eq {ϖ : R} (h : Irreducible ϖ) : maximalIdeal R = Ideal.span {ϖ} := (irreducible_iff_uniformizer _).mp h variable (R) /-- Uniformizers exist in a DVR. -/ theorem exists_irreducible : ∃ ϖ : R, Irreducible ϖ := by simp_rw [irreducible_iff_uniformizer] exact (IsPrincipalIdealRing.principal <| maximalIdeal R).principal /-- Uniformizers exist in a DVR. -/ theorem exists_prime : ∃ ϖ : R, Prime ϖ := (exists_irreducible R).imp fun _ => irreducible_iff_prime.1 /-- An integral domain is a DVR iff it's a PID with a unique non-zero prime ideal. -/ theorem iff_pid_with_one_nonzero_prime (R : Type u) [CommRing R] [IsDomain R] : IsDiscreteValuationRing R ↔ IsPrincipalIdealRing R ∧ ∃! P : Ideal R, P ≠ ⊥ ∧ IsPrime P := by constructor · intro RDVR rcases id RDVR with ⟨Rlocal⟩ constructor · assumption use IsLocalRing.maximalIdeal R constructor · exact ⟨Rlocal, inferInstance⟩ · rintro Q ⟨hQ1, hQ2⟩ obtain ⟨q, rfl⟩ := (IsPrincipalIdealRing.principal Q).1 have hq : q ≠ 0 := by rintro rfl apply hQ1 simp rw [submodule_span_eq, span_singleton_prime hq] at hQ2 replace hQ2 := hQ2.irreducible rw [irreducible_iff_uniformizer] at hQ2 exact hQ2.symm · rintro ⟨RPID, Punique⟩ haveI : IsLocalRing R := IsLocalRing.of_unique_nonzero_prime Punique refine { not_a_field' := ?_ } rcases Punique with ⟨P, ⟨hP1, hP2⟩, _⟩ have hPM : P ≤ maximalIdeal R := le_maximalIdeal hP2.1 intro h rw [h, le_bot_iff] at hPM exact hP1 hPM theorem associated_of_irreducible {a b : R} (ha : Irreducible a) (hb : Irreducible b) : Associated a b := by rw [irreducible_iff_uniformizer] at ha hb rw [← span_singleton_eq_span_singleton, ← ha, hb] variable (R : Type*) /-- Alternative characterisation of discrete valuation rings. -/ def HasUnitMulPowIrreducibleFactorization [CommRing R] : Prop := ∃ p : R, Irreducible p ∧ ∀ {x : R}, x ≠ 0 → ∃ n : ℕ, Associated (p ^ n) x namespace HasUnitMulPowIrreducibleFactorization variable {R} [CommRing R] theorem unique_irreducible (hR : HasUnitMulPowIrreducibleFactorization R) ⦃p q : R⦄ (hp : Irreducible p) (hq : Irreducible q) : Associated p q := by rcases hR with ⟨ϖ, hϖ, hR⟩ suffices ∀ {p : R} (_ : Irreducible p), Associated p ϖ by apply Associated.trans (this hp) (this hq).symm clear hp hq p q intro p hp obtain ⟨n, hn⟩ := hR hp.ne_zero have : Irreducible (ϖ ^ n) := hn.symm.irreducible hp rcases lt_trichotomy n 1 with (H | rfl | H) · obtain rfl : n = 0 := by clear hn this revert H n decide simp [not_irreducible_one, pow_zero] at this · simpa only [pow_one] using hn.symm · obtain ⟨n, rfl⟩ : ∃ k, n = 1 + k + 1 := Nat.exists_eq_add_of_lt H rw [pow_succ'] at this rcases this.isUnit_or_isUnit rfl with (H0 | H0) · exact (hϖ.not_isUnit H0).elim · rw [add_comm, pow_succ'] at H0 exact (hϖ.not_isUnit (isUnit_of_mul_isUnit_left H0)).elim variable [IsDomain R] /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a unique factorization domain. See `IsDiscreteValuationRing.ofHasUnitMulPowIrreducibleFactorization`. -/ theorem toUniqueFactorizationMonoid (hR : HasUnitMulPowIrreducibleFactorization R) : UniqueFactorizationMonoid R := let p := Classical.choose hR let spec := Classical.choose_spec hR UniqueFactorizationMonoid.of_exists_prime_factors fun x hx => by use Multiset.replicate (Classical.choose (spec.2 hx)) p constructor · intro q hq have hpq := Multiset.eq_of_mem_replicate hq rw [hpq] refine ⟨spec.1.ne_zero, spec.1.not_isUnit, ?_⟩ intro a b h by_cases ha : a = 0 · rw [ha] simp only [true_or, dvd_zero] obtain ⟨m, u, rfl⟩ := spec.2 ha rw [mul_assoc, mul_left_comm, Units.dvd_mul_left] at h rw [Units.dvd_mul_right] by_cases hm : m = 0 · simp only [hm, one_mul, pow_zero] at h ⊢ right exact h left obtain ⟨m, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hm rw [pow_succ'] apply dvd_mul_of_dvd_left dvd_rfl _ · rw [Multiset.prod_replicate] exact Classical.choose_spec (spec.2 hx) theorem of_ufd_of_unique_irreducible [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : HasUnitMulPowIrreducibleFactorization R := by obtain ⟨p, hp⟩ := h₁ refine ⟨p, hp, ?_⟩ intro x hx obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx refine ⟨Multiset.card fx, ?_⟩ have H := hfx.2 rw [← Associates.mk_eq_mk_iff_associated] at H ⊢ rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate] congr 1 symm rw [Multiset.eq_replicate] simp only [true_and, and_imp, Multiset.card_map, Multiset.mem_map, exists_imp] rintro _ q hq rfl rw [Associates.mk_eq_mk_iff_associated] apply h₂ (hfx.1 _ hq) hp end HasUnitMulPowIrreducibleFactorization theorem aux_pid_of_ufd_of_unique_irreducible (R : Type u) [CommRing R] [IsDomain R] [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : IsPrincipalIdealRing R := by classical constructor intro I by_cases I0 : I = ⊥ · rw [I0] use 0 simp only [Set.singleton_zero, Submodule.span_zero] obtain ⟨x, hxI, hx0⟩ : ∃ x ∈ I, x ≠ (0 : R) := I.ne_bot_iff.mp I0 obtain ⟨p, _, H⟩ := HasUnitMulPowIrreducibleFactorization.of_ufd_of_unique_irreducible h₁ h₂ have ex : ∃ n : ℕ, p ^ n ∈ I := by obtain ⟨n, u, rfl⟩ := H hx0 refine ⟨n, ?_⟩ simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hxI constructor use p ^ Nat.find ex change I = Ideal.span _ apply le_antisymm · intro r hr by_cases hr0 : r = 0 · simp only [hr0, Submodule.zero_mem] obtain ⟨n, u, rfl⟩ := H hr0 simp only [mem_span_singleton, Units.isUnit, IsUnit.dvd_mul_right] apply pow_dvd_pow apply Nat.find_min' simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hr · rw [span_singleton_le_iff_mem] exact Nat.find_spec ex /-- A unique factorization domain with at least one irreducible element in which all irreducible elements are associated is a discrete valuation ring. -/ theorem of_ufd_of_unique_irreducible {R : Type u} [CommRing R] [IsDomain R] [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : IsDiscreteValuationRing R := by rw [iff_pid_with_one_nonzero_prime] haveI PID : IsPrincipalIdealRing R := aux_pid_of_ufd_of_unique_irreducible R h₁ h₂ obtain ⟨p, hp⟩ := h₁ refine ⟨PID, ⟨Ideal.span {p}, ⟨?_, ?_⟩, ?_⟩⟩ · rw [Submodule.ne_bot_iff] exact ⟨p, Ideal.mem_span_singleton.mpr (dvd_refl p), hp.ne_zero⟩ · rwa [Ideal.span_singleton_prime hp.ne_zero, ← UniqueFactorizationMonoid.irreducible_iff_prime] · intro I rw [← Submodule.IsPrincipal.span_singleton_generator I] rintro ⟨I0, hI⟩ apply span_singleton_eq_span_singleton.mpr apply h₂ _ hp rw [Ne, Submodule.span_singleton_eq_bot] at I0 rwa [UniqueFactorizationMonoid.irreducible_iff_prime, ← Ideal.span_singleton_prime I0] /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a discrete valuation ring. -/ theorem ofHasUnitMulPowIrreducibleFactorization {R : Type u} [CommRing R] [IsDomain R] (hR : HasUnitMulPowIrreducibleFactorization R) : IsDiscreteValuationRing R := by letI : UniqueFactorizationMonoid R := hR.toUniqueFactorizationMonoid apply of_ufd_of_unique_irreducible _ hR.unique_irreducible obtain ⟨p, hp, H⟩ := hR exact ⟨p, hp⟩ /- If a ring is equivalent to a DVR, it is itself a DVR. -/ theorem RingEquivClass.isDiscreteValuationRing {A B E : Type*} [CommRing A] [IsDomain A] [CommRing B] [IsDomain B] [IsDiscreteValuationRing A] [EquivLike E A B] [RingEquivClass E A B] (e : E) : IsDiscreteValuationRing B where principal := (isPrincipalIdealRing_iff _).1 <| IsPrincipalIdealRing.of_surjective _ (e : A ≃+* B).surjective __ : IsLocalRing B := (e : A ≃+* B).isLocalRing not_a_field' := by obtain ⟨a, ha⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr <| IsDiscreteValuationRing.not_a_field A) rw [Submodule.ne_bot_iff] refine ⟨e a, ⟨?_, by simp only [ne_eq, EmbeddingLike.map_eq_zero_iff, ZeroMemClass.coe_eq_zero, ha, not_false_eq_true]⟩⟩ rw [IsLocalRing.mem_maximalIdeal, map_mem_nonunits_iff e, ← IsLocalRing.mem_maximalIdeal] exact a.2 section variable [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] variable {R} theorem associated_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) : ∃ n : ℕ, Associated x (ϖ ^ n) := by have : WfDvdMonoid R := IsNoetherianRing.wfDvdMonoid obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx use Multiset.card fx have H := hfx.2 rw [← Associates.mk_eq_mk_iff_associated] at H ⊢ rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate] congr 1 rw [Multiset.eq_replicate] simp only [true_and, and_imp, Multiset.card_map, Multiset.mem_map, exists_imp] rintro _ _ _ rfl rw [Associates.mk_eq_mk_iff_associated] refine associated_of_irreducible _ ?_ hirr apply hfx.1 assumption theorem eq_unit_mul_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) : ∃ (n : ℕ) (u : Rˣ), x = u * ϖ ^ n := by obtain ⟨n, hn⟩ := associated_pow_irreducible hx hirr obtain ⟨u, rfl⟩ := hn.symm use n, u apply mul_comm open Submodule.IsPrincipal theorem ideal_eq_span_pow_irreducible {s : Ideal R} (hs : s ≠ ⊥) {ϖ : R} (hirr : Irreducible ϖ) : ∃ n : ℕ, s = Ideal.span {ϖ ^ n} := by have gen_ne_zero : generator s ≠ 0 := by rw [Ne, ← eq_bot_iff_generator_eq_zero] assumption rcases associated_pow_irreducible gen_ne_zero hirr with ⟨n, u, hnu⟩ use n have : span _ = _ := Ideal.span_singleton_generator s rw [← this, ← hnu, span_singleton_eq_span_singleton] use u theorem unit_mul_pow_congr_pow {p q : R} (hp : Irreducible p) (hq : Irreducible q) (u v : Rˣ) (m n : ℕ) (h : ↑u * p ^ m = v * q ^ n) : m = n := by have key : Associated (Multiset.replicate m p).prod (Multiset.replicate n q).prod := by rw [Multiset.prod_replicate, Multiset.prod_replicate, Associated] refine ⟨u * v⁻¹, ?_⟩ simp only [Units.val_mul] rw [mul_left_comm, ← mul_assoc, h, mul_right_comm, Units.mul_inv, one_mul] have := by refine Multiset.card_eq_card_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ key) all_goals intro x hx obtain rfl := Multiset.eq_of_mem_replicate hx assumption simpa only [Multiset.card_replicate] theorem unit_mul_pow_congr_unit {ϖ : R} (hirr : Irreducible ϖ) (u v : Rˣ) (m n : ℕ) (h : ↑u * ϖ ^ m = v * ϖ ^ n) : u = v := by obtain rfl : m = n := unit_mul_pow_congr_pow hirr hirr u v m n h rw [← sub_eq_zero] at h rw [← sub_mul, mul_eq_zero] at h rcases h with h | h · rw [sub_eq_zero] at h exact mod_cast h · apply (hirr.ne_zero (pow_eq_zero h)).elim /-! ## The additive valuation on a DVR -/ open Classical in /-- The `ℕ∞`-valued additive valuation on a DVR. -/ noncomputable def addVal (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] : AddValuation R ℕ∞ := multiplicity_addValuation (Classical.choose_spec (exists_prime R)) theorem addVal_def (r : R) (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) (hr : r = u * ϖ ^ n) : addVal R r = n := by classical rw [addVal, multiplicity_addValuation_apply, hr, emultiplicity_eq_of_associated_left (associated_of_irreducible R hϖ (Classical.choose_spec (exists_prime R)).irreducible), emultiplicity_eq_of_associated_right (Associated.symm ⟨u, mul_comm _ _⟩), emultiplicity_pow_self_of_prime (irreducible_iff_prime.1 hϖ)] /-- An alternative definition of the additive valuation, taking units into account -/ theorem addVal_def' (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) : addVal R ((u : R) * ϖ ^ n) = n := addVal_def _ u hϖ n rfl theorem addVal_zero : addVal R 0 = ⊤ := (addVal R).map_zero theorem addVal_one : addVal R 1 = 0 := (addVal R).map_one @[simp] theorem addVal_uniformizer {ϖ : R} (hϖ : Irreducible ϖ) : addVal R ϖ = 1 := by simpa only [one_mul, eq_self_iff_true, Units.val_one, pow_one, forall_true_left, Nat.cast_one] using addVal_def ϖ 1 hϖ 1 theorem addVal_mul {a b : R} : addVal R (a * b) = addVal R a + addVal R b := (addVal R).map_mul _ _ theorem addVal_pow (a : R) (n : ℕ) : addVal R (a ^ n) = n • addVal R a := (addVal R).map_pow _ _ nonrec theorem _root_.Irreducible.addVal_pow {ϖ : R} (h : Irreducible ϖ) (n : ℕ) : addVal R (ϖ ^ n) = n := by rw [addVal_pow, addVal_uniformizer h, nsmul_one] theorem addVal_eq_top_iff {a : R} : addVal R a = ⊤ ↔ a = 0 := by have hi := (Classical.choose_spec (exists_prime R)).irreducible constructor · contrapose intro h obtain ⟨n, ha⟩ := associated_pow_irreducible h hi obtain ⟨u, rfl⟩ := ha.symm rw [mul_comm, addVal_def' u hi n] nofun · rintro rfl exact addVal_zero theorem addVal_le_iff_dvd {a b : R} : addVal R a ≤ addVal R b ↔ a ∣ b := by classical have hp := Classical.choose_spec (exists_prime R) constructor <;> intro h · by_cases ha0 : a = 0 · rw [ha0, addVal_zero, top_le_iff, addVal_eq_top_iff] at h rw [h] apply dvd_zero obtain ⟨n, ha⟩ := associated_pow_irreducible ha0 hp.irreducible rw [addVal, multiplicity_addValuation_apply, multiplicity_addValuation_apply, emultiplicity_le_emultiplicity_iff] at h exact ha.dvd.trans (h n ha.symm.dvd) · rw [addVal, multiplicity_addValuation_apply, multiplicity_addValuation_apply] exact emultiplicity_le_emultiplicity_of_dvd_right h theorem addVal_add {a b : R} : min (addVal R a) (addVal R b) ≤ addVal R (a + b) := (addVal R).map_add _ _ @[simp] lemma addVal_eq_zero_of_unit (u : Rˣ) : addVal R u = 0 := by obtain ⟨ϖ, hϖ⟩ := exists_irreducible R rw [addVal_def (u : R) u hϖ 0] <;> simp lemma addVal_eq_zero_iff {x : R} : addVal R x = 0 ↔ IsUnit x := by rcases eq_or_ne x 0 with rfl | hx · simp obtain ⟨ϖ, hϖ⟩ := exists_irreducible R obtain ⟨n, u, rfl⟩ := eq_unit_mul_pow_irreducible hx hϖ simp [isUnit_pow_iff_of_not_isUnit hϖ.not_isUnit, hϖ] end instance (R : Type*) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] : IsHausdorff (maximalIdeal R) R where haus' x hx := by obtain ⟨ϖ, hϖ⟩ := exists_irreducible R simp only [← Ideal.one_eq_top, smul_eq_mul, mul_one, SModEq.zero, hϖ.maximalIdeal_eq, Ideal.span_singleton_pow, Ideal.mem_span_singleton, ← addVal_le_iff_dvd, hϖ.addVal_pow] at hx rwa [← addVal_eq_top_iff, WithTop.eq_top_iff_forall_ge] end IsDiscreteValuationRing section variable (A : Type u) [CommRing A] [IsDomain A] [IsDiscreteValuationRing A] /-- A DVR is a valuation ring. -/ instance (priority := 100) of_isDiscreteValuationRing : ValuationRing A := inferInstance end namespace Valuation.Integers variable {K Γ₀ O : Type*} [Field K] [LinearOrderedCommGroupWithZero Γ₀] [CommRing O] [Algebra O K] {v : Valuation K Γ₀} (hv : v.Integers O) include hv lemma maximalIdeal_eq_setOf_le_v_algebraMap : letI : IsDomain O := hv.hom_inj.isDomain ∀ [IsDiscreteValuationRing O] {ϖ : O} (_h : Irreducible ϖ), (IsLocalRing.maximalIdeal O : Set O) = {y : O | v (algebraMap O K y) ≤ v (algebraMap O K ϖ)} := by letI : IsDomain O := hv.hom_inj.isDomain intros _ _ h rw [← hv.coe_span_singleton_eq_setOf_le_v_algebraMap, ← h.maximalIdeal_eq] lemma maximalIdeal_pow_eq_setOf_le_v_algebraMap_pow : letI : IsDomain O := hv.hom_inj.isDomain ∀ [IsDiscreteValuationRing O] {ϖ : O} (_h : Irreducible ϖ) (n : ℕ), ((IsLocalRing.maximalIdeal O ^ n : Ideal O) : Set O) = {y : O | v (algebraMap O K y) ≤ v (algebraMap O K ϖ) ^ n} := by letI : IsDomain O := hv.hom_inj.isDomain intros _ ϖ h n have : (v (algebraMap O K ϖ)) ^ n = v (algebraMap O K (ϖ ^ n)) := by simp rw [this, ← hv.coe_span_singleton_eq_setOf_le_v_algebraMap, ← Ideal.span_singleton_pow, ← h.maximalIdeal_eq] end Valuation.Integers section Valuation.integer variable {K Γ₀ : Type*} [Field K] [LinearOrderedCommGroupWithZero Γ₀] (v : Valuation K Γ₀) lemma _root_.Irreducible.maximalIdeal_eq_setOf_le_v_coe [IsDiscreteValuationRing v.integer] {ϖ : v.integer} (h : Irreducible ϖ) : (IsLocalRing.maximalIdeal v.integer : Set v.integer) = {y : v.integer | v y ≤ v ϖ} := (Valuation.integer.integers v).maximalIdeal_eq_setOf_le_v_algebraMap h lemma _root_.Irreducible.maximalIdeal_pow_eq_setOf_le_v_coe_pow [IsDiscreteValuationRing v.integer] {ϖ : v.integer} (h : Irreducible ϖ) (n : ℕ) : ((IsLocalRing.maximalIdeal v.integer ^ n : Ideal v.integer) : Set v.integer) = {y : v.integer | v y ≤ v (ϖ : K) ^ n} := (Valuation.integer.integers v).maximalIdeal_pow_eq_setOf_le_v_algebraMap_pow h _ end Valuation.integer
Int.lean
/- Copyright (c) 2023 Koundinya Vajjha. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Koundinya Vajjha, Thomas Browning -/ import Mathlib.NumberTheory.Harmonic.Defs import Mathlib.NumberTheory.Padics.PadicNumbers import Mathlib.Tactic.Positivity /-! The nth Harmonic number is not an integer. We formalize the proof using 2-adic valuations. This proof is due to Kürschák. Reference: https://kconrad.math.uconn.edu/blurbs/gradnumthy/padicharmonicsum.pdf -/ lemma harmonic_pos {n : ℕ} (Hn : n ≠ 0) : 0 < harmonic n := by unfold harmonic rw [← Finset.nonempty_range_iff] at Hn positivity /-- The 2-adic valuation of the n-th harmonic number is the negative of the logarithm of n. -/ theorem padicValRat_two_harmonic (n : ℕ) : padicValRat 2 (harmonic n) = -Nat.log 2 n := by induction n with | zero => simp | succ n ih => rcases eq_or_ne n 0 with rfl | hn · simp rw [harmonic_succ] have key : padicValRat 2 (harmonic n) ≠ padicValRat 2 (↑(n + 1))⁻¹ := by rw [ih, padicValRat.inv, padicValRat.of_nat, Ne, neg_inj, Nat.cast_inj] exact Nat.log_ne_padicValNat_succ hn rw [padicValRat.add_eq_min (harmonic_succ n ▸ (harmonic_pos n.succ_ne_zero).ne') (harmonic_pos hn).ne' (inv_ne_zero (Nat.cast_ne_zero.mpr n.succ_ne_zero)) key, ih, padicValRat.inv, padicValRat.of_nat, min_neg_neg, neg_inj, ← Nat.cast_max, Nat.cast_inj] exact Nat.max_log_padicValNat_succ_eq_log_succ n /-- The 2-adic norm of the n-th harmonic number is 2 raised to the logarithm of n in base 2. -/ lemma padicNorm_two_harmonic {n : ℕ} (hn : n ≠ 0) : ‖(harmonic n : ℚ_[2])‖ = 2 ^ (Nat.log 2 n) := by rw [padicNormE.eq_padicNorm, padicNorm.eq_zpow_of_nonzero (harmonic_pos hn).ne', padicValRat_two_harmonic, neg_neg, zpow_natCast, Rat.cast_pow, Rat.cast_natCast, Nat.cast_ofNat] /-- The n-th harmonic number is not an integer for n ≥ 2. -/ theorem harmonic_not_int {n : ℕ} (h : 2 ≤ n) : ¬ (harmonic n).isInt := by apply padicNorm.not_int_of_not_padic_int 2 rw [padicNorm.eq_zpow_of_nonzero (harmonic_pos (ne_zero_of_lt h)).ne', padicValRat_two_harmonic, neg_neg, zpow_natCast] exact one_lt_pow₀ one_lt_two (Nat.log_pos one_lt_two h).ne'
Semigroup.lean
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn -/ import Mathlib.Algebra.Group.Defs import Mathlib.Topology.Separation.Hausdorff /-! # Idempotents in topological semigroups This file provides a sufficient condition for a semigroup `M` to contain an idempotent (i.e. an element `m` such that `m * m = m `), namely that `M` is a nonempty compact Hausdorff space where right-multiplication by constants is continuous. We also state a corresponding lemma guaranteeing that a subset of `M` contains an idempotent. -/ /-- Any nonempty compact Hausdorff semigroup where right-multiplication is continuous contains an idempotent, i.e. an `m` such that `m * m = m`. -/ @[to_additive /-- Any nonempty compact Hausdorff additive semigroup where right-addition is continuous contains an idempotent, i.e. an `m` such that `m + m = m` -/] theorem exists_idempotent_of_compact_t2_of_continuous_mul_left {M} [Nonempty M] [Semigroup M] [TopologicalSpace M] [CompactSpace M] [T2Space M] (continuous_mul_left : ∀ r : M, Continuous (· * r)) : ∃ m : M, m * m = m := by /- We apply Zorn's lemma to the poset of nonempty closed subsemigroups of `M`. It will turn out that any minimal element is `{m}` for an idempotent `m : M`. -/ let S : Set (Set M) := { N | IsClosed N ∧ N.Nonempty ∧ ∀ (m) (_ : m ∈ N) (m') (_ : m' ∈ N), m * m' ∈ N } rsuffices ⟨N, hN⟩ : ∃ N', Minimal (· ∈ S) N' · obtain ⟨N_closed, ⟨m, hm⟩, N_mul⟩ := hN.prop use m /- We now have an element `m : M` of a minimal subsemigroup `N`, and want to show `m + m = m`. We first show that every element of `N` is of the form `m' + m`. -/ have scaling_eq_self : (· * m) '' N = N := by apply hN.eq_of_subset · refine ⟨(continuous_mul_left m).isClosedMap _ N_closed, ⟨_, ⟨m, hm, rfl⟩⟩, ?_⟩ rintro _ ⟨m'', hm'', rfl⟩ _ ⟨m', hm', rfl⟩ exact ⟨m'' * m * m', N_mul _ (N_mul _ hm'' _ hm) _ hm', mul_assoc _ _ _⟩ · rintro _ ⟨m', hm', rfl⟩ exact N_mul _ hm' _ hm /- In particular, this means that `m' * m = m` for some `m'`. We now use minimality again to show that this holds for all `m' ∈ N`. -/ have absorbing_eq_self : N ∩ { m' | m' * m = m } = N := by apply hN.eq_of_subset · refine ⟨N_closed.inter ((T1Space.t1 m).preimage (continuous_mul_left m)), ?_, ?_⟩ · rwa [← scaling_eq_self] at hm · rintro m'' ⟨mem'', eq'' : _ = m⟩ m' ⟨mem', eq' : _ = m⟩ refine ⟨N_mul _ mem'' _ mem', ?_⟩ rw [Set.mem_setOf_eq, mul_assoc, eq', eq''] apply Set.inter_subset_left rw [← absorbing_eq_self] at hm exact hm.2 refine zorn_superset _ fun c hcs hc => ?_ refine ⟨⋂₀ c, ⟨isClosed_sInter fun t ht => (hcs ht).1, ?_, fun m hm m' hm' => ?_⟩, fun s hs => Set.sInter_subset_of_mem hs⟩ · obtain rfl | hcnemp := c.eq_empty_or_nonempty · rw [Set.sInter_empty] apply Set.univ_nonempty convert @IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ _ _ hcnemp.coe_sort ((↑) : c → Set M) ?_ ?_ ?_ ?_ · exact Set.sInter_eq_iInter · refine DirectedOn.directed_val (IsChain.directedOn hc.symm) exacts [fun i => (hcs i.prop).2.1, fun i => (hcs i.prop).1.isCompact, fun i => (hcs i.prop).1] · rw [Set.mem_sInter] exact fun t ht => (hcs ht).2.2 m (Set.mem_sInter.mp hm t ht) m' (Set.mem_sInter.mp hm' t ht) /-- A version of `exists_idempotent_of_compact_t2_of_continuous_mul_left` where the idempotent lies in some specified nonempty compact subsemigroup. -/ @[to_additive exists_idempotent_in_compact_add_subsemigroup /-- A version of `exists_idempotent_of_compact_t2_of_continuous_add_left` where the idempotent lies in some specified nonempty compact additive subsemigroup. -/] theorem exists_idempotent_in_compact_subsemigroup {M} [Semigroup M] [TopologicalSpace M] [T2Space M] (continuous_mul_left : ∀ r : M, Continuous (· * r)) (s : Set M) (snemp : s.Nonempty) (s_compact : IsCompact s) (s_add : ∀ᵉ (x ∈ s) (y ∈ s), x * y ∈ s) : ∃ m ∈ s, m * m = m := by let M' := { m // m ∈ s } letI : Semigroup M' := { mul := fun p q => ⟨p.1 * q.1, s_add _ p.2 _ q.2⟩ mul_assoc := fun p q r => Subtype.eq (mul_assoc _ _ _) } haveI : CompactSpace M' := isCompact_iff_compactSpace.mp s_compact haveI : Nonempty M' := nonempty_subtype.mpr snemp have : ∀ p : M', Continuous (· * p) := fun p => ((continuous_mul_left p.1).comp continuous_subtype_val).subtype_mk _ obtain ⟨⟨m, hm⟩, idem⟩ := exists_idempotent_of_compact_t2_of_continuous_mul_left this exact ⟨m, hm, Subtype.ext_iff.mp idem⟩
Gluing.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.AlgebraicGeometry.Restrict import Mathlib.CategoryTheory.LocallyDirected import Mathlib.Geometry.RingedSpace.PresheafedSpace.Gluing /-! # Gluing Schemes Given a family of gluing data of schemes, we may glue them together. Also see the section about "locally directed" gluing, which is a special case where the conditions are easier to check. ## Main definitions * `AlgebraicGeometry.Scheme.GlueData`: A structure containing the family of gluing data. * `AlgebraicGeometry.Scheme.GlueData.glued`: The glued scheme. This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API can be used. * `AlgebraicGeometry.Scheme.GlueData.ι`: The immersion `ι i : U i ⟶ glued` for each `i : J`. * `AlgebraicGeometry.Scheme.GlueData.isoCarrier`: The isomorphism between the underlying space of the glued scheme and the gluing of the underlying topological spaces. * `AlgebraicGeometry.Scheme.OpenCover.gluedCover`: The glue data associated with an open cover. * `AlgebraicGeometry.Scheme.OpenCover.fromGlued`: The canonical morphism `𝒰.gluedCover.glued ⟶ X`. This has an `is_iso` instance. * `AlgebraicGeometry.Scheme.OpenCover.glueMorphisms`: We may glue a family of compatible morphisms defined on an open cover of a scheme. ## Main results * `AlgebraicGeometry.Scheme.GlueData.ι_isOpenImmersion`: The map `ι i : U i ⟶ glued` is an open immersion for each `i : J`. * `AlgebraicGeometry.Scheme.GlueData.ι_jointly_surjective` : The underlying maps of `ι i : U i ⟶ glued` are jointly surjective. * `AlgebraicGeometry.Scheme.GlueData.vPullbackConeIsLimit` : `V i j` is the pullback (intersection) of `U i` and `U j` over the glued space. * `AlgebraicGeometry.Scheme.GlueData.ι_eq_iff` : `ι i x = ι j y` if and only if they coincide when restricted to `V i i`. * `AlgebraicGeometry.Scheme.GlueData.isOpen_iff` : A subset of the glued scheme is open iff all its preimages in `U i` are open. ## Implementation details All the hard work is done in `AlgebraicGeometry/PresheafedSpace/Gluing.lean` where we glue presheafed spaces, sheafed spaces, and locally ringed spaces. -/ noncomputable section universe v u open TopologicalSpace CategoryTheory Opposite Topology open CategoryTheory.Limits AlgebraicGeometry.PresheafedSpace open CategoryTheory.GlueData namespace AlgebraicGeometry namespace Scheme /-- A family of gluing data consists of 1. An index type `J` 2. A scheme `U i` for each `i : J`. 3. A scheme `V i j` for each `i j : J`. (Note that this is `J × J → Scheme` rather than `J → J → Scheme` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the schemes `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subschemes of the glued space. -/ structure GlueData extends CategoryTheory.GlueData Scheme where f_open : ∀ i j, IsOpenImmersion (f i j) attribute [instance] GlueData.f_open namespace GlueData variable (D : GlueData.{u}) local notation "𝖣" => D.toGlueData /-- The glue data of locally ringed spaces associated to a family of glue data of schemes. -/ abbrev toLocallyRingedSpaceGlueData : LocallyRingedSpace.GlueData := { f_open := D.f_open toGlueData := 𝖣.mapGlueData forgetToLocallyRingedSpace } instance (i j : 𝖣.J) : LocallyRingedSpace.IsOpenImmersion ((D.toLocallyRingedSpaceGlueData).toGlueData.f i j) := by apply GlueData.f_open instance (i j : 𝖣.J) : SheafedSpace.IsOpenImmersion (D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toGlueData.f i j) := by apply GlueData.f_open instance (i j : 𝖣.J) : PresheafedSpace.IsOpenImmersion (D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toGlueData.f i j) := by apply GlueData.f_open instance (i : 𝖣.J) : LocallyRingedSpace.IsOpenImmersion ((D.toLocallyRingedSpaceGlueData).toGlueData.ι i) := by apply LocallyRingedSpace.GlueData.ι_isOpenImmersion /-- (Implementation). The glued scheme of a glue data. This should not be used outside this file. Use `AlgebraicGeometry.Scheme.GlueData.glued` instead. -/ def gluedScheme : Scheme := by apply LocallyRingedSpace.IsOpenImmersion.scheme D.toLocallyRingedSpaceGlueData.toGlueData.glued intro x obtain ⟨i, y, rfl⟩ := D.toLocallyRingedSpaceGlueData.ι_jointly_surjective x refine ⟨_, ((D.U i).affineCover.map y).toLRSHom ≫ D.toLocallyRingedSpaceGlueData.toGlueData.ι i, ?_⟩ constructor · simp only [LocallyRingedSpace.comp_toShHom, SheafedSpace.comp_base, TopCat.hom_comp, ContinuousMap.coe_comp, Set.range_comp] refine Set.mem_image_of_mem _ ?_ exact (D.U i).affineCover.covers y · infer_instance instance : CreatesColimit 𝖣.diagram.multispan forgetToLocallyRingedSpace := createsColimitOfFullyFaithfulOfIso D.gluedScheme (HasColimit.isoOfNatIso (𝖣.diagramIso forgetToLocallyRingedSpace).symm) instance : PreservesColimit (𝖣.diagram.multispan) forgetToTop := inferInstanceAs (PreservesColimit (𝖣.diagram).multispan (forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget CommRingCat)) instance : PreservesColimit (𝖣.diagram.multispan) forget := inferInstanceAs (PreservesColimit (𝖣.diagram).multispan (forgetToTop ⋙ CategoryTheory.forget _)) instance : HasMulticoequalizer 𝖣.diagram := hasColimit_of_created _ forgetToLocallyRingedSpace /-- The glued scheme of a glued space. -/ abbrev glued : Scheme := 𝖣.glued /-- The immersion from `D.U i` into the glued space. -/ abbrev ι (i : D.J) : D.U i ⟶ D.glued := 𝖣.ι i /-- The gluing as sheafed spaces is isomorphic to the gluing as presheafed spaces. -/ abbrev isoLocallyRingedSpace : D.glued.toLocallyRingedSpace ≅ D.toLocallyRingedSpaceGlueData.toGlueData.glued := 𝖣.gluedIso forgetToLocallyRingedSpace theorem ι_isoLocallyRingedSpace_inv (i : D.J) : D.toLocallyRingedSpaceGlueData.toGlueData.ι i ≫ D.isoLocallyRingedSpace.inv = (𝖣.ι i).toLRSHom := 𝖣.ι_gluedIso_inv forgetToLocallyRingedSpace i instance ι_isOpenImmersion (i : D.J) : IsOpenImmersion (𝖣.ι i) := by rw [IsOpenImmersion, ← D.ι_isoLocallyRingedSpace_inv]; infer_instance theorem ι_jointly_surjective (x : 𝖣.glued.carrier) : ∃ (i : D.J) (y : (D.U i).carrier), (D.ι i).base y = x := 𝖣.ι_jointly_surjective forget x /-- Promoted to higher priority to short circuit simplifier. -/ @[simp (high), reassoc] theorem glue_condition (i j : D.J) : D.t i j ≫ D.f j i ≫ D.ι j = D.f i j ≫ D.ι i := 𝖣.glue_condition i j /-- The pullback cone spanned by `V i j ⟶ U i` and `V i j ⟶ U j`. This is a pullback diagram (`vPullbackConeIsLimit`). -/ def vPullbackCone (i j : D.J) : PullbackCone (D.ι i) (D.ι j) := PullbackCone.mk (D.f i j) (D.t i j ≫ D.f j i) (by simp) /-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`. ``` Vᵢⱼ ⟶ Uᵢ | | ↓ ↓ Uⱼ ⟶ X ``` -/ def vPullbackConeIsLimit (i j : D.J) : IsLimit (D.vPullbackCone i j) := 𝖣.vPullbackConeIsLimitOfMap forgetToLocallyRingedSpace i j (D.toLocallyRingedSpaceGlueData.vPullbackConeIsLimit _ _) local notation "D_" => TopCat.GlueData.toGlueData <| D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toTopGlueData /-- The underlying topological space of the glued scheme is isomorphic to the gluing of the underlying spaces -/ def isoCarrier : D.glued.carrier ≅ (D_).glued := by refine (PresheafedSpace.forget _).mapIso ?_ ≪≫ GlueData.gluedIso _ (PresheafedSpace.forget.{_, _, u} _) refine SheafedSpace.forgetToPresheafedSpace.mapIso ?_ ≪≫ SheafedSpace.GlueData.isoPresheafedSpace _ refine LocallyRingedSpace.forgetToSheafedSpace.mapIso ?_ ≪≫ LocallyRingedSpace.GlueData.isoSheafedSpace _ exact Scheme.GlueData.isoLocallyRingedSpace _ @[simp] theorem ι_isoCarrier_inv (i : D.J) : (D_).ι i ≫ D.isoCarrier.inv = (D.ι i).base := by delta isoCarrier rw [Iso.trans_inv, GlueData.ι_gluedIso_inv_assoc, Functor.mapIso_inv, Iso.trans_inv, Functor.mapIso_inv, Iso.trans_inv, SheafedSpace.forgetToPresheafedSpace_map, PresheafedSpace.forget_map, PresheafedSpace.forget_map, ← PresheafedSpace.comp_base, ← Category.assoc, D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.ι_isoPresheafedSpace_inv i] erw [← Category.assoc, D.toLocallyRingedSpaceGlueData.ι_isoSheafedSpace_inv i] change (_ ≫ D.isoLocallyRingedSpace.inv).base = _ rw [D.ι_isoLocallyRingedSpace_inv i] /-- An equivalence relation on `Σ i, D.U i` that holds iff `𝖣.ι i x = 𝖣.ι j y`. See `AlgebraicGeometry.Scheme.GlueData.ι_eq_iff`. -/ def Rel (a b : Σ i, ((D.U i).carrier : Type _)) : Prop := ∃ x : (D.V (a.1, b.1)).carrier, (D.f _ _).base x = a.2 ∧ (D.t _ _ ≫ D.f _ _).base x = b.2 theorem ι_eq_iff (i j : D.J) (x : (D.U i).carrier) (y : (D.U j).carrier) : (𝖣.ι i).base x = (𝖣.ι j).base y ↔ D.Rel ⟨i, x⟩ ⟨j, y⟩ := by refine Iff.trans ?_ (TopCat.GlueData.ι_eq_iff_rel D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toTopGlueData i j x y) rw [← ((TopCat.mono_iff_injective D.isoCarrier.inv).mp _).eq_iff, ← ConcreteCategory.comp_apply] · simp_rw [← D.ι_isoCarrier_inv] rfl -- `rfl` was not needed before https://github.com/leanprover-community/mathlib4/pull/13170 · infer_instance theorem isOpen_iff (U : Set D.glued.carrier) : IsOpen U ↔ ∀ i, IsOpen ((D.ι i).base ⁻¹' U) := by rw [← (TopCat.homeoOfIso D.isoCarrier.symm).isOpen_preimage, TopCat.GlueData.isOpen_iff] apply forall_congr' intro i rw [← Set.preimage_comp, ← ι_isoCarrier_inv] rfl /-- The open cover of the glued space given by the glue data. -/ @[simps -isSimp] def openCover (D : Scheme.GlueData) : OpenCover D.glued where J := D.J obj := D.U map := D.ι f x := (D.ι_jointly_surjective x).choose covers x := ⟨_, (D.ι_jointly_surjective x).choose_spec.choose_spec⟩ end GlueData namespace Cover variable {X : Scheme.{u}} (𝒰 : OpenCover.{u} X) /-- (Implementation) the transition maps in the glue data associated with an open cover. -/ def gluedCoverT' (x y z : 𝒰.J) : pullback (pullback.fst (𝒰.map x) (𝒰.map y)) (pullback.fst (𝒰.map x) (𝒰.map z)) ⟶ pullback (pullback.fst (𝒰.map y) (𝒰.map z)) (pullback.fst (𝒰.map y) (𝒰.map x)) := by refine (pullbackRightPullbackFstIso _ _ _).hom ≫ ?_ refine ?_ ≫ (pullbackSymmetry _ _).hom refine ?_ ≫ (pullbackRightPullbackFstIso _ _ _).inv refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_ · simp [pullback.condition] · simp @[simp, reassoc] theorem gluedCoverT'_fst_fst (x y z : 𝒰.J) : 𝒰.gluedCoverT' x y z ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by delta gluedCoverT'; simp @[simp, reassoc] theorem gluedCoverT'_fst_snd (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by delta gluedCoverT'; simp @[simp, reassoc] theorem gluedCoverT'_snd_fst (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ pullback.snd _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by delta gluedCoverT'; simp @[simp, reassoc] theorem gluedCoverT'_snd_snd (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by delta gluedCoverT'; simp theorem glued_cover_cocycle_fst (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y ≫ pullback.fst _ _ = pullback.fst _ _ := by apply pullback.hom_ext <;> simp theorem glued_cover_cocycle_snd (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y ≫ pullback.snd _ _ = pullback.snd _ _ := by apply pullback.hom_ext <;> simp [pullback.condition] theorem glued_cover_cocycle (x y z : 𝒰.J) : gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y = 𝟙 _ := by apply pullback.hom_ext <;> simp_rw [Category.id_comp, Category.assoc] · apply glued_cover_cocycle_fst · apply glued_cover_cocycle_snd /-- The glue data associated with an open cover. The canonical isomorphism `𝒰.gluedCover.glued ⟶ X` is provided by `𝒰.fromGlued`. -/ @[simps] def gluedCover : Scheme.GlueData.{u} where J := 𝒰.J U := 𝒰.obj V := fun ⟨x, y⟩ => pullback (𝒰.map x) (𝒰.map y) f _ _ := pullback.fst _ _ f_id _ := inferInstance t _ _ := (pullbackSymmetry _ _).hom t_id x := by simp t' x y z := gluedCoverT' 𝒰 x y z t_fac x y z := by apply pullback.hom_ext <;> simp -- The `cocycle` field could have been `by tidy` but lean timeouts. cocycle x y z := glued_cover_cocycle 𝒰 x y z f_open _ := inferInstance /-- The canonical morphism from the gluing of an open cover of `X` into `X`. This is an isomorphism, as witnessed by an `IsIso` instance. -/ def fromGlued : 𝒰.gluedCover.glued ⟶ X := by fapply Multicoequalizer.desc · exact fun x => 𝒰.map x rintro ⟨x, y⟩ change pullback.fst _ _ ≫ _ = ((pullbackSymmetry _ _).hom ≫ pullback.fst _ _) ≫ _ simpa using pullback.condition @[simp, reassoc] theorem ι_fromGlued (x : 𝒰.J) : 𝒰.gluedCover.ι x ≫ 𝒰.fromGlued = 𝒰.map x := Multicoequalizer.π_desc _ _ _ _ _ theorem fromGlued_injective : Function.Injective 𝒰.fromGlued.base := by intro x y h obtain ⟨i, x, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective x obtain ⟨j, y, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective y rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply] at h simp_rw [← Scheme.comp_base] at h rw [ι_fromGlued, ι_fromGlued] at h let e := (TopCat.pullbackConeIsLimit _ _).conePointUniqueUpToIso (isLimitOfHasPullbackOfPreservesLimit Scheme.forgetToTop (𝒰.map i) (𝒰.map j)) rw [𝒰.gluedCover.ι_eq_iff] use e.hom ⟨⟨x, y⟩, h⟩ constructor · erw [← ConcreteCategory.comp_apply e.hom, IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left] rfl · erw [← ConcreteCategory.comp_apply e.hom, pullbackSymmetry_hom_comp_fst, IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right] rfl instance fromGlued_stalk_iso (x : 𝒰.gluedCover.glued.carrier) : IsIso (𝒰.fromGlued.stalkMap x) := by obtain ⟨i, x, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective x have := stalkMap_congr_hom _ _ (𝒰.ι_fromGlued i) x rw [stalkMap_comp, ← IsIso.eq_comp_inv] at this rw [this] infer_instance theorem fromGlued_open_map : IsOpenMap 𝒰.fromGlued.base := by intro U hU rw [isOpen_iff_forall_mem_open] intro x hx rw [𝒰.gluedCover.isOpen_iff] at hU use 𝒰.fromGlued.base '' U ∩ Set.range (𝒰.map (𝒰.f x)).base use Set.inter_subset_left constructor · rw [← Set.image_preimage_eq_inter_range] apply (show IsOpenImmersion (𝒰.map (𝒰.f x)) from inferInstance).base_open.isOpenMap convert hU (𝒰.f x) using 1 simp only [← ι_fromGlued, gluedCover_U, comp_coeBase, TopCat.hom_comp, ContinuousMap.coe_comp, Set.preimage_comp] congr! 1 exact Set.preimage_image_eq _ 𝒰.fromGlued_injective · exact ⟨hx, 𝒰.covers x⟩ theorem fromGlued_isOpenEmbedding : IsOpenEmbedding 𝒰.fromGlued.base := .of_continuous_injective_isOpenMap (by fun_prop) 𝒰.fromGlued_injective 𝒰.fromGlued_open_map instance : Epi 𝒰.fromGlued.base := by rw [TopCat.epi_iff_surjective] intro x obtain ⟨y, h⟩ := 𝒰.covers x use (𝒰.gluedCover.ι (𝒰.f x)).base y rw [← ConcreteCategory.comp_apply] rw [← 𝒰.ι_fromGlued (𝒰.f x)] at h exact h instance fromGlued_open_immersion : IsOpenImmersion 𝒰.fromGlued := IsOpenImmersion.of_stalk_iso _ 𝒰.fromGlued_isOpenEmbedding instance : IsIso 𝒰.fromGlued := let F := Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace have : IsIso (F.map (fromGlued 𝒰)) := by change IsIso 𝒰.fromGlued.toPshHom apply PresheafedSpace.IsOpenImmersion.to_iso isIso_of_reflects_iso _ F /-- Given an open cover of `X`, and a morphism `𝒰.obj x ⟶ Y` for each open subscheme in the cover, such that these morphisms are compatible in the intersection (pullback), we may glue the morphisms together into a morphism `X ⟶ Y`. Note: If `X` is exactly (defeq to) the gluing of `U i`, then using `Multicoequalizer.desc` suffices. -/ def glueMorphisms (𝒰 : OpenCover.{v} X) {Y : Scheme.{u}} (f : ∀ x, 𝒰.obj x ⟶ Y) (hf : ∀ x y, pullback.fst (𝒰.map x) (𝒰.map y) ≫ f x = pullback.snd _ _ ≫ f y) : X ⟶ Y := by refine inv 𝒰.ulift.fromGlued ≫ ?_ fapply Multicoequalizer.desc · exact fun i ↦ f _ rintro ⟨i, j⟩ dsimp change pullback.fst _ _ ≫ f _ = (_ ≫ _) ≫ f _ simp [pullbackSymmetry_hom_comp_fst] exact hf _ _ theorem hom_ext (𝒰 : OpenCover.{v} X) {Y : Scheme} (f₁ f₂ : X ⟶ Y) (h : ∀ x, 𝒰.map x ≫ f₁ = 𝒰.map x ≫ f₂) : f₁ = f₂ := by rw [← cancel_epi 𝒰.ulift.fromGlued] apply Multicoequalizer.hom_ext intro x rw [fromGlued, Multicoequalizer.π_desc_assoc, Multicoequalizer.π_desc_assoc] exact h _ @[simp, reassoc] theorem ι_glueMorphisms (𝒰 : OpenCover.{v} X) {Y : Scheme} (f : ∀ x, 𝒰.obj x ⟶ Y) (hf : ∀ x y, pullback.fst (𝒰.map x) (𝒰.map y) ≫ f x = pullback.snd _ _ ≫ f y) (x : 𝒰.J) : 𝒰.map x ≫ 𝒰.glueMorphisms f hf = f x := by refine (𝒰.ulift.pullbackCover (𝒰.map x)).hom_ext _ _ fun i ↦ ?_ dsimp only [ulift_J, ulift_obj, ulift_map, pullbackCover_obj, pullbackCover_map] simp_rw [pullback.condition_assoc, ← ulift_map, ← ι_fromGlued, Category.assoc, glueMorphisms, IsIso.hom_inv_id_assoc, ulift_map, hf] erw [Multicoequalizer.π_desc] end Cover lemma hom_ext_of_forall {X Y : Scheme} (f g : X ⟶ Y) (H : ∀ x : X, ∃ U : X.Opens, x ∈ U ∧ U.ι ≫ f = U.ι ≫ g) : f = g := by choose U hxU hU using H let 𝒰 : X.OpenCover := { J := X, obj i := (U i), map i := (U i).ι, f x := x, covers := by simpa } exact 𝒰.hom_ext _ _ hU /-! ## Locally directed gluing We say that a diagram of open immersions is "locally directed" if for any `V, W ⊆ U` in the diagram, `V ∩ W` is a union of elements in the diagram. Equivalently, for every `x ∈ U` in the diagram, the set of elements containing `x` is directed (and hence the name). For such a diagram, we can glue them directly since the gluing conditions are always satisfied. The intended usage is to provide the following instances: - `∀ {i j} (f : i ⟶ j), IsOpenImmersion (F.map f)` - `(F ⋙ forget).IsLocallyDirected` and to directly use the `colimit` API. Also see `AlgebraicGeometry.Scheme.IsLocallyDirected.openCover` for the open cover of the `colimit`. -/ section IsLocallyDirected open TopologicalSpace.Opens universe w variable {J : Type w} [Category.{v} J] (F : J ⥤ Scheme.{u}) variable [∀ {i j} (f : i ⟶ j), IsOpenImmersion (F.map f)] namespace IsLocallyDirected /-- (Implementation detail) The intersection `V` in the glue data associated to a locally directed diagram. -/ noncomputable def V (i j : J) : (F.obj i).Opens := ⨆ (k : Σ k, (k ⟶ i) × (k ⟶ j)), (F.map k.2.1).opensRange lemma V_self (i) : V F i i = ⊤ := top_le_iff.mp (le_iSup_of_le ⟨i, 𝟙 _, 𝟙 _⟩ (by simp [Scheme.Hom.opensRange_of_isIso])) variable [(F ⋙ forget).IsLocallyDirected] lemma exists_of_pullback_V_V {i j k : J} (x : pullback (C := Scheme) (V F i j).ι (V F i k).ι) : ∃ (l : J) (fi : l ⟶ i) (fj : l ⟶ j) (fk : l ⟶ k) (α : F.obj l ⟶ pullback (V F i j).ι (V F i k).ι) (z : F.obj l), IsOpenImmersion α ∧ α ≫ pullback.fst _ _ = (F.map fi).isoOpensRange.hom ≫ (F.obj i).homOfLE (le_iSup_of_le ⟨l, _, fj⟩ le_rfl) ∧ α ≫ pullback.snd _ _ = (F.map fi).isoOpensRange.hom ≫ (F.obj i).homOfLE (le_iSup_of_le ⟨l, _, fk⟩ le_rfl) ∧ α.base z = x := by obtain ⟨k₁, y₁, hy₁⟩ := mem_iSup.mp ((pullback.fst (C := Scheme) _ _).base x).2 obtain ⟨k₂, y₂, hy₂⟩ := mem_iSup.mp ((pullback.snd (C := Scheme) _ _).base x).2 obtain ⟨l, hli, hlk, z, rfl, rfl⟩ := (F ⋙ forget).exists_map_eq_of_isLocallyDirected k₁.2.1 k₂.2.1 y₁ y₂ (by simpa [hy₁, hy₂] using congr($(pullback.condition (f := (V F i j).ι)).base x)) let α : F.obj l ⟶ pullback (V F i j).ι (V F i k).ι := pullback.lift ((F.map (hli ≫ k₁.2.1)).isoOpensRange.hom ≫ Scheme.homOfLE _ (le_iSup_of_le ⟨l, hli ≫ k₁.2.1, hli ≫ k₁.2.2⟩ le_rfl)) ((F.map (hli ≫ k₁.2.1)).isoOpensRange.hom ≫ Scheme.homOfLE _ (le_iSup_of_le ⟨l, hli ≫ k₁.2.1, hlk ≫ k₂.2.2⟩ le_rfl)) (by simp) have : IsOpenImmersion α := by apply (config := { allowSynthFailures := true }) IsOpenImmersion.of_comp · exact inferInstanceAs (IsOpenImmersion (pullback.fst _ _)) · simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, α] infer_instance have : α.base z = x := by apply (pullback.fst (C := Scheme) _ _).isOpenEmbedding.injective apply (V F i j).ι.isOpenEmbedding.injective rw [← Scheme.comp_base_apply, ← Scheme.comp_base_apply, pullback.lift_fst_assoc] simpa using hy₁ exact ⟨l, hli ≫ k₁.2.1, hli ≫ k₁.2.2, hlk ≫ k₂.2.2, α, z, ‹_›, by simp [α], by simp [α], ‹_›⟩ variable [Quiver.IsThin J] lemma fst_inv_eq_snd_inv {i j : J} (k₁ k₂ : (k : J) × (k ⟶ i) × (k ⟶ j)) {U : (F.obj i).Opens} (h₁ : (F.map k₁.2.1).opensRange ≤ U) (h₂ : (F.map k₂.2.1).opensRange ≤ U) : pullback.fst ((F.obj i).homOfLE h₁) ((F.obj i).homOfLE h₂) ≫ (F.map k₁.2.1).isoOpensRange.inv ≫ F.map k₁.2.2 = pullback.snd ((F.obj i).homOfLE h₁) ((F.obj i).homOfLE h₂) ≫ (F.map k₂.2.1).isoOpensRange.inv ≫ F.map k₂.2.2 := by apply Scheme.hom_ext_of_forall intro x obtain ⟨l, hli, hlj, y, hy₁, hy₂⟩ := (F ⋙ forget).exists_map_eq_of_isLocallyDirected k₁.2.1 k₂.2.1 ((pullback.fst _ _ ≫ (F.map k₁.2.1).isoOpensRange.inv).base x) ((pullback.snd _ _ ≫ (F.map k₂.2.1).isoOpensRange.inv).base x) (by simp only [Functor.comp_obj, forget_obj, Functor.comp_map, forget_map, ← comp_base_apply, Category.assoc, Hom.isoOpensRange_inv_comp] congr 5 simpa using congr($(pullback.condition (f := (F.obj i).homOfLE h₁) (g := (F.obj i).homOfLE h₂)) ≫ Scheme.Opens.ι _)) let α : F.obj l ⟶ pullback ((F.obj i).homOfLE h₁) ((F.obj i).homOfLE h₂) := pullback.lift (F.map hli ≫ (F.map k₁.2.1).isoOpensRange.hom) (F.map hlj ≫ (F.map k₂.2.1).isoOpensRange.hom) (by simp [← cancel_mono (Scheme.Opens.ι _), ← Functor.map_comp, Subsingleton.elim (hli ≫ k₁.2.1) (hlj ≫ k₂.2.1)]) have : IsOpenImmersion α := by have : IsOpenImmersion (α ≫ pullback.fst _ _) := by simp only [pullback.lift_fst, α]; infer_instance exact .of_comp _ (pullback.fst _ _) have : α.base y = x := by simp only [Functor.comp_obj, forget_obj, Functor.comp_map, forget_map, comp_coeBase, TopCat.hom_comp, ContinuousMap.comp_apply] at hy₁ apply (pullback.fst ((F.obj i).homOfLE h₁) _).isOpenEmbedding.injective simp only [← Scheme.comp_base_apply, α, pullback.lift_fst] simp [hy₁] refine ⟨α.opensRange, ⟨y, this⟩, ?_⟩ rw [← cancel_epi α.isoOpensRange.hom] simp [α, ← Functor.map_comp, Subsingleton.elim (hli ≫ k₁.2.2) (hlj ≫ k₂.2.2)] /-- (Implementation detail) The inclusion map `V i j ⟶ F j` in the glue data associated to a locally directed diagram. -/ def tAux (i j : J) : (V F i j).toScheme ⟶ F.obj j := (Scheme.Opens.iSupOpenCover _).glueMorphisms (fun k ↦ (F.map k.2.1).isoOpensRange.inv ≫ F.map k.2.2) fun k₁ k₂ ↦ by dsimp [Scheme.Opens.iSupOpenCover] apply fst_inv_eq_snd_inv F @[reassoc] lemma homOfLE_tAux (i j : J) {k : J} (fi : k ⟶ i) (fj : k ⟶ j) : (F.obj i).homOfLE (le_iSup_of_le ⟨k, fi, fj⟩ le_rfl) ≫ tAux F i j = (F.map fi).isoOpensRange.inv ≫ F.map fj := (Scheme.Opens.iSupOpenCover (J := Σ k, (k ⟶ i) × (k ⟶ j)) _).ι_glueMorphisms _ _ ⟨k, fi, fj⟩ /-- (Implementation detail) The transition map `V i j ⟶ V j i` in the glue data associated to a locally directed diagram. -/ def t (i j : J) : (V F i j).toScheme ⟶ (V F j i).toScheme := IsOpenImmersion.lift (V F j i).ι (tAux F i j) (by rintro _ ⟨x, rfl⟩ obtain ⟨l, x, rfl⟩ := (Scheme.Opens.iSupOpenCover _).exists_eq x simp only [V, tAux, ← Scheme.comp_base_apply, Cover.ι_glueMorphisms] simp only [Opens.range_ι, iSup_mk, carrier_eq_coe, Hom.coe_opensRange, coe_mk, comp_coeBase, TopCat.hom_comp, ContinuousMap.comp_apply] exact Set.mem_iUnion.mpr ⟨⟨l.1, l.2.2, l.2.1⟩, ⟨_, rfl⟩⟩) lemma t_id (i : J) : t F i i = 𝟙 _ := by refine (Scheme.Opens.iSupOpenCover _).hom_ext _ _ fun k ↦ ?_ simp only [Category.comp_id, ← cancel_mono (Scheme.Opens.ι _), Category.assoc, IsOpenImmersion.lift_fac, Scheme.Cover.ι_glueMorphisms, t, tAux, V] simp [Scheme.Opens.iSupOpenCover, Iso.inv_comp_eq, Subsingleton.elim k.2.1 k.2.2] variable [Small.{u} J] local notation3:max "↓"j:arg => Equiv.symm (equivShrink _) j /-- (Implementation detail) The glue data associated to a locally directed diagram. One usually does not want to use this directly, and instead use the generic `colimit` API. -/ def glueData : Scheme.GlueData where J := Shrink.{u} J U j := F.obj ↓j V ij := V F ↓ij.1 ↓ij.2 f i j := Scheme.Opens.ι _ f_id i := V_self F ↓i ▸ (Scheme.topIso _).isIso_hom f_hasPullback := inferInstance f_open := inferInstance t i j := t F ↓i ↓j t_id i := t_id F ↓i t' i j k := pullback.lift (IsOpenImmersion.lift (V F ↓j ↓k).ι (pullback.fst _ _ ≫ tAux F ↓i ↓j) (by rintro _ ⟨x, rfl⟩ obtain ⟨l, fi, fj, fk, α, z, hα, hα₁, hα₂, rfl⟩ := exists_of_pullback_V_V F x rw [← Scheme.comp_base_apply, reassoc_of% hα₁, homOfLE_tAux F ↓i ↓j fi fj, Iso.hom_inv_id_assoc, Scheme.Opens.range_ι, SetLike.mem_coe] exact TopologicalSpace.Opens.mem_iSup.mpr ⟨⟨l, fj, fk⟩, ⟨z, rfl⟩⟩)) (pullback.fst _ _ ≫ t F _ _) (by simp [t]) t_fac i j k := pullback.lift_snd _ _ _ cocycle i j k := by refine Scheme.hom_ext_of_forall _ _ fun x ↦ ?_ have := exists_of_pullback_V_V F x obtain ⟨l, fi, fj, fk, α, z, hα, hα₁, hα₂, e⟩ := this -- doing them in the same step times out. refine ⟨α.opensRange, ⟨_, e⟩, ?_⟩ rw [← cancel_mono (pullback.snd _ _), ← cancel_mono (Scheme.Opens.ι _)] simp only [t, Category.assoc, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, limit.lift_π_assoc, cospan_left, IsOpenImmersion.lift_fac, Category.id_comp] rw [IsOpenImmersion.comp_lift_assoc] simp only [limit.lift_π_assoc, PullbackCone.mk_pt, cospan_left, PullbackCone.mk_π_app] rw [← cancel_epi α.isoOpensRange.hom] simp_rw [Scheme.Hom.isoOpensRange_hom_ι_assoc, IsOpenImmersion.comp_lift_assoc] simp only [reassoc_of% hα₁, homOfLE_tAux F _ _ fi fj, Iso.hom_inv_id_assoc, reassoc_of% hα₂] generalize_proofs _ h₁ have : IsOpenImmersion.lift (V F ↓j ↓k).ι (F.map fj) h₁ = (F.map fj).isoOpensRange.hom ≫ (F.obj ↓j).homOfLE (le_iSup_of_le ⟨l, fj, fk⟩ le_rfl) := by rw [← cancel_mono (Scheme.Opens.ι _), Category.assoc, IsOpenImmersion.lift_fac, ← Iso.inv_comp_eq, Scheme.Hom.isoOpensRange_inv_comp] exact (Scheme.homOfLE_ι _ _).symm simp_rw [this, Category.assoc, homOfLE_tAux F _ _ fj fk, Iso.hom_inv_id_assoc] generalize_proofs h₂ have : IsOpenImmersion.lift (V F ↓k ↓i).ι (F.map fk) h₂ = (F.map fk).isoOpensRange.hom ≫ (F.obj ↓k).homOfLE (le_iSup_of_le ⟨l, fk, fi⟩ le_rfl) := by rw [← cancel_mono (Scheme.Opens.ι _), Category.assoc, IsOpenImmersion.lift_fac, ← Iso.inv_comp_eq, Scheme.Hom.isoOpensRange_inv_comp] exact (Scheme.homOfLE_ι _ _).symm simp_rw [this, Category.assoc, homOfLE_tAux F _ _ fk fi, Iso.hom_inv_id_assoc, ← Iso.inv_comp_eq, Scheme.Hom.isoOpensRange_inv_comp] exact (Scheme.homOfLE_ι _ _).symm lemma glueDataι_naturality {i j : Shrink.{u} J} (f : ↓i ⟶ ↓j) : F.map f ≫ (glueData F).ι j = (glueData F).ι i := by have : IsIso (V F ↓i ↓j).ι := by have : V F ↓i ↓j = ⊤ := top_le_iff.mp (le_iSup_of_le ⟨_, 𝟙 i, f⟩ (by simp [Scheme.Hom.opensRange_of_isIso])) exact this ▸ (topIso _).isIso_hom have : t F ↓i ↓j ≫ (V F ↓j ↓i).ι ≫ _ = (V F ↓i ↓j).ι ≫ _ := (glueData F).glue_condition i j simp only [t, IsOpenImmersion.lift_fac_assoc] at this rw [← cancel_epi (V F ↓i ↓j).ι, ← this, ← Category.assoc, ← (Iso.eq_inv_comp _).mp (homOfLE_tAux F ↓i ↓j (𝟙 i) f), ← Category.assoc, ← Category.assoc, Category.assoc] convert Category.id_comp _ rw [← cancel_mono (Opens.ι _)] simp [V, InducedCategory.category, Shrink.instCategoryShrink] /-- (Implementation detail) The cocone associated to a locally directed diagram. One usually does not want to use this directly, and instead use the generic `colimit` API. -/ def cocone : Cocone F where pt := (glueData F).glued ι.app j := F.map (eqToHom (by simp)) ≫ (glueData F).ι (equivShrink _ j) ι.naturality {i j} f := by simp only [← IsIso.inv_comp_eq, ← Functor.map_inv, ← Functor.map_comp_assoc, glueDataι_naturality, Functor.const_obj_obj, Functor.const_obj_map, Category.comp_id] /-- (Implementation detail) The cocone associated to a locally directed diagram is a colimit. One usually does not want to use this directly, and instead use the generic `colimit` API. -/ noncomputable def isColimit : IsColimit (cocone F) where desc s := Multicoequalizer.desc _ _ (fun i ↦ s.ι.app ↓i) (by rintro ⟨i, j⟩ dsimp [glueData, GlueData.diagram] simp only [t, IsOpenImmersion.lift_fac] apply (Scheme.Opens.iSupOpenCover _).hom_ext _ _ fun k ↦ ?_ simp only [Opens.iSupOpenCover, V, Scheme.homOfLE_ι_assoc] rw [homOfLE_tAux_assoc F ↓i ↓j k.2.1 k.2.2, Iso.eq_inv_comp] simp) fac s j := by refine (Category.assoc _ _ _).trans ?_ conv_lhs => enter [2]; tactic => exact Multicoequalizer.π_desc _ _ _ _ _ simp uniq s m hm := Multicoequalizer.hom_ext _ _ _ fun i ↦ by simp [← hm ↓i, cocone, reassoc_of% glueDataι_naturality] rfl /-- (Implementation detail) The cocone associated to a locally directed diagram is a colimit as locally ringed spaces. One usually does not want to use this directly, and instead use the generic `colimit` API. -/ noncomputable def isColimitForgetToLocallyRingedSpace : IsColimit (Scheme.forgetToLocallyRingedSpace.mapCocone (cocone F)) where desc s := (glueData F).isoLocallyRingedSpace.hom ≫ Multicoequalizer.desc _ _ (fun i ↦ s.ι.app ↓i) (by rintro ⟨i, j⟩ dsimp [glueData, GlueData.diagram] simp only [t, IsOpenImmersion.lift_fac, ← Scheme.comp_toLRSHom] rw [← cancel_epi (Scheme.Opens.iSupOpenCover _).ulift.fromGlued.toLRSHom, ← cancel_epi (Scheme.Opens.iSupOpenCover _).ulift.gluedCover.isoLocallyRingedSpace.inv] refine Multicoequalizer.hom_ext _ _ _ fun ⟨k, hk⟩ ↦ ?_ rw [← CategoryTheory.GlueData.ι, reassoc_of% GlueData.ι_isoLocallyRingedSpace_inv, reassoc_of% GlueData.ι_isoLocallyRingedSpace_inv, ← cancel_epi (Hom.isoOpensRange (F.map _)).hom.toLRSHom] simp only [Opens.iSupOpenCover, Cover.ulift, V, ← comp_toLRSHom_assoc, Cover.ι_fromGlued_assoc, homOfLE_ι, Hom.isoOpensRange_hom_ι] generalize_proofs _ h rw [homOfLE_tAux F ↓i ↓j h.choose.2.1 h.choose.2.2, Iso.hom_inv_id_assoc] exact (s.w h.choose.2.1).trans (s.w h.choose.2.2).symm) fac s j := by simp only [cocone, Functor.mapCocone_ι_app, Scheme.comp_toLRSHom, forgetToLocallyRingedSpace_map, ← GlueData.ι_isoLocallyRingedSpace_inv] simpa [CategoryTheory.GlueData.ι] using s.w _ uniq s m hm := by rw [← Iso.inv_comp_eq] refine Multicoequalizer.hom_ext _ _ _ fun i ↦ ?_ conv_lhs => rw [← ι.eq_def] dsimp simp [cocone, ← hm, glueDataι_naturality, ← GlueData.ι_isoLocallyRingedSpace_inv, -ι_gluedIso_inv_assoc, -ι_gluedIso_inv] instance : HasColimit F := ⟨_, isColimit F⟩ instance : PreservesColimit F Scheme.forgetToLocallyRingedSpace := preservesColimit_of_preserves_colimit_cocone (isColimit F) (isColimitForgetToLocallyRingedSpace F) instance : CreatesColimit F Scheme.forgetToLocallyRingedSpace := CategoryTheory.createsColimitOfReflectsIsomorphismsOfPreserves /-- The open cover of the colimit of a locally directed diagram by the components. -/ def openCover : (colimit F).OpenCover := ((coverOfIsIso ((isColimit F).coconePointUniqueUpToIso (colimit.isColimit F)).hom).bind fun i ↦ (glueData F).openCover).copy J F.obj (colimit.ι F) ((equivShrink J).trans <| (Equiv.uniqueSigma fun (_ : Unit) ↦ Shrink J).symm) (fun _ ↦ F.mapIso (eqToIso (by simp [GlueData.openCover, glueData]))) fun i ↦ by change colimit.ι F i = _ ≫ (glueData F).ι (equivShrink J i) ≫ _ simp [← Category.assoc, ← Iso.comp_inv_eq, cocone] @[simp] lemma openCover_J : (openCover F).J = J := rfl @[simp] lemma openCover_obj : (openCover F).obj = F.obj := rfl @[simp] lemma openCover_map : (openCover F).map = colimit.ι F := rfl instance (i) : IsOpenImmersion (colimit.ι F i) := inferInstanceAs (IsOpenImmersion ((openCover F).map i)) lemma ι_eq_ι_iff {i j : J} {xi : F.obj i} {xj : F.obj j} : (colimit.ι F i).base xi = (colimit.ι F j).base xj ↔ ∃ k fi fj, ∃ (x : F.obj k), (F.map fi).base x = xi ∧ (F.map fj).base x = xj := by constructor; swap · rintro ⟨k, fi, fj, x, rfl, rfl⟩; simp only [← Scheme.comp_base_apply, colimit.w] obtain ⟨i, rfl⟩ := (equivShrink J).symm.surjective i obtain ⟨j, rfl⟩ := (equivShrink J).symm.surjective j rw [← ((isColimit F).coconePointUniqueUpToIso (colimit.isColimit F)).inv.isOpenEmbedding.injective.eq_iff] simp only [Limits.colimit, ← Scheme.comp_base_apply, colimit.comp_coconePointUniqueUpToIso_inv, cocone, glueDataι_naturality] refine ?_ ∘ ((glueData F).ι_eq_iff _ _ _ _).mp dsimp only [GlueData.Rel] rintro ⟨x, rfl, rfl⟩ obtain ⟨⟨k, ki, kj⟩, y, hy : (F.map ki).base y = ((glueData F).f i j).base x⟩ := mem_iSup.mp x.2 refine ⟨k, ki, kj, y, hy, ?_⟩ obtain ⟨k, rfl⟩ := (equivShrink J).symm.surjective k apply ((glueData F).ι _).isOpenEmbedding.injective simp only [← Scheme.comp_base_apply, Category.assoc, GlueData.glue_condition] trans ((glueData F).ι k).base y · simp [← glueDataι_naturality F kj]; rfl · simp [← glueDataι_naturality F ki, ← hy]; rfl instance (F : WidePushoutShape J ⥤ Scheme.{u}) [∀ {i j} (f : i ⟶ j), IsOpenImmersion (F.map f)] : (F ⋙ forget).IsLocallyDirected := have (i : _) : Mono ((F ⋙ forget).map (.init i)) := (mono_iff_injective _).mpr (F.map _).isOpenEmbedding.injective inferInstance end IsLocallyDirected end IsLocallyDirected end Scheme end AlgebraicGeometry
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.
Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro, Anne Baanen -/ import Mathlib.GroupTheory.QuotientGroup.Finite import Mathlib.LinearAlgebra.Quotient.Defs import Mathlib.RingTheory.Congruence.Basic import Mathlib.RingTheory.Ideal.Basic import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.Tactic.FinCases /-! # Ideal quotients This file defines ideal quotients as a special case of submodule quotients and proves some basic results about these quotients. See `Algebra.RingQuot` for quotients of semirings. ## Main definitions - `Ideal.Quotient.Ring`: the quotient of a ring `R` by a two-sided ideal `I : Ideal R` -/ universe u v w namespace Ideal open Set variable {R : Type u} [Ring R] (I J : Ideal R) {a b : R} variable {S : Type v} namespace Quotient variable {I} {x y : R} theorem zero_eq_one_iff : (0 : R ⧸ I) = 1 ↔ I = ⊤ := eq_comm.trans <| (Submodule.Quotient.mk_eq_zero _).trans (eq_top_iff_one _).symm theorem zero_ne_one_iff : (0 : R ⧸ I) ≠ 1 ↔ I ≠ ⊤ := not_congr zero_eq_one_iff protected theorem nontrivial (hI : I ≠ ⊤) : Nontrivial (R ⧸ I) := ⟨⟨0, 1, zero_ne_one_iff.2 hI⟩⟩ theorem subsingleton_iff : Subsingleton (R ⧸ I) ↔ I = ⊤ := by rw [Submodule.Quotient.subsingleton_iff, eq_top_iff, SetLike.le_def] simp_rw [Submodule.mem_top, true_implies] instance : Unique (R ⧸ (⊤ : Ideal R)) := ⟨⟨0⟩, by rintro ⟨x⟩; exact Quotient.eq_zero_iff_mem.mpr Submodule.mem_top⟩ variable [I.IsTwoSided] -- this instance is harder to find than the one via `Algebra α (R ⧸ I)`, so use a lower priority instance (priority := 100) isScalarTower_right {α} [SMul α R] [IsScalarTower α R R] : IsScalarTower α (R ⧸ I) (R ⧸ I) := (Quotient.ringCon I).isScalarTower_right instance smulCommClass {α} [SMul α R] [IsScalarTower α R R] [SMulCommClass α R R] : SMulCommClass α (R ⧸ I) (R ⧸ I) := (Quotient.ringCon I).smulCommClass instance smulCommClass' {α} [SMul α R] [IsScalarTower α R R] [SMulCommClass R α R] : SMulCommClass (R ⧸ I) α (R ⧸ I) := (Quotient.ringCon I).smulCommClass' theorem eq_zero_iff_dvd {R} [CommRing R] (x y : R) : Ideal.Quotient.mk (Ideal.span ({x} : Set R)) y = 0 ↔ x ∣ y := by rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton] @[simp] lemma mk_singleton_self (x : R) [(Ideal.span {x}).IsTwoSided] : mk (Ideal.span {x}) x = 0 := (Submodule.Quotient.mk_eq_zero _).mpr (mem_span_singleton_self _) variable (I) instance noZeroDivisors [hI : I.IsPrime] : NoZeroDivisors (R ⧸ I) where eq_zero_or_eq_zero_of_mul_eq_zero {a b} := Quotient.inductionOn₂' a b fun {_ _} hab => (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim (Or.inl ∘ eq_zero_iff_mem.2) (Or.inr ∘ eq_zero_iff_mem.2) instance isDomain [hI : I.IsPrime] : IsDomain (R ⧸ I) := let _ := Quotient.nontrivial hI.1 NoZeroDivisors.to_isDomain _ theorem isDomain_iff_prime : IsDomain (R ⧸ I) ↔ I.IsPrime := by refine ⟨fun H => ⟨zero_ne_one_iff.1 ?_, fun {x y} h => ?_⟩, fun h => inferInstance⟩ · haveI : Nontrivial (R ⧸ I) := ⟨H.2.1⟩ exact zero_ne_one · simp only [← eq_zero_iff_mem, (mk I).map_mul] at h ⊢ haveI := @IsDomain.to_noZeroDivisors (R ⧸ I) _ H exact eq_zero_or_eq_zero_of_mul_eq_zero h variable {I} in theorem exists_inv [hI : I.IsMaximal] : ∀ {a : R ⧸ I}, a ≠ 0 → ∃ b : R ⧸ I, a * b = 1 := by apply exists_right_inv_of_exists_left_inv rintro ⟨a⟩ h rcases hI.exists_inv (mt eq_zero_iff_mem.2 h) with ⟨b, c, hc, abc⟩ refine ⟨mk _ b, Quot.sound ?_⟩ simp only [Submodule.quotientRel_def] rw [← eq_sub_iff_add_eq'] at abc rwa [abc, ← neg_mem_iff (G := R) (H := I), neg_sub] at hc open Classical in /-- The quotient by a maximal ideal is a group with zero. This is a `def` rather than `instance`, since users will have computable inverses in some applications. See note [reducible non-instances]. -/ protected noncomputable abbrev groupWithZero [hI : I.IsMaximal] : GroupWithZero (R ⧸ I) := fast_instance% { inv := fun a => if ha : a = 0 then 0 else Classical.choose (exists_inv ha) mul_inv_cancel := fun a (ha : a ≠ 0) => show a * dite _ _ _ = _ by rw [dif_neg ha]; exact Classical.choose_spec (exists_inv ha) inv_zero := dif_pos rfl __ := Quotient.nontrivial hI.out.1 } /-- The quotient by a two-sided ideal that is maximal as a left ideal is a division ring. This is a `def` rather than `instance`, since users will have computable inverses (and `qsmul`, `ratCast`) in some applications. See note [reducible non-instances]. -/ protected noncomputable abbrev divisionRing [I.IsMaximal] : DivisionRing (R ⧸ I) := fast_instance% { __ := ring _ __ := Quotient.groupWithZero _ nnqsmul := _ nnqsmul_def _ _ := rfl qsmul := _ qsmul_def _ _ := rfl } /-- The quotient of a commutative ring by a maximal ideal is a field. This is a `def` rather than `instance`, since users will have computable inverses (and `qsmul`, `ratCast`) in some applications. See note [reducible non-instances]. -/ protected noncomputable abbrev field {R} [CommRing R] (I : Ideal R) [I.IsMaximal] : Field (R ⧸ I) := fast_instance% { __ := commRing _ __ := Quotient.divisionRing I } /-- If the quotient by an ideal is a field, then the ideal is maximal. -/ theorem maximal_of_isField {R} [CommRing R] (I : Ideal R) (hqf : IsField (R ⧸ I)) : I.IsMaximal := by apply Ideal.isMaximal_iff.2 constructor · intro h rcases hqf.exists_pair_ne with ⟨⟨x⟩, ⟨y⟩, hxy⟩ exact hxy (Ideal.Quotient.eq.2 (mul_one (x - y) ▸ I.mul_mem_left _ h)) · intro J x hIJ hxnI hxJ rcases hqf.mul_inv_cancel (mt Ideal.Quotient.eq_zero_iff_mem.1 hxnI) with ⟨⟨y⟩, hy⟩ rw [← zero_add (1 : R), ← sub_self (x * y), sub_add] exact J.sub_mem (J.mul_mem_right _ hxJ) (hIJ (Ideal.Quotient.eq.1 hy)) /-- The quotient of a ring by an ideal is a field iff the ideal is maximal. -/ theorem maximal_ideal_iff_isField_quotient {R} [CommRing R] (I : Ideal R) : I.IsMaximal ↔ IsField (R ⧸ I) := ⟨fun h => let _i := @Quotient.field _ _ I h Field.toIsField _, maximal_of_isField _⟩ end Quotient section Pi variable (ι : Type v) /-- `R^n/I^n` is a `R/I`-module. -/ instance modulePi [I.IsTwoSided] : Module (R ⧸ I) ((ι → R) ⧸ pi fun _ ↦ I) where smul c m := Quotient.liftOn₂' c m (fun r m ↦ Submodule.Quotient.mk <| r • m) <| by intro c₁ m₁ c₂ m₂ hc hm apply Ideal.Quotient.eq.2 rw [Submodule.quotientRel_def] at hc hm intro i exact I.mul_sub_mul_mem hc (hm i) one_smul := by rintro ⟨a⟩; exact congr_arg _ (one_smul _ _) mul_smul := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; exact congr_arg _ (mul_smul _ _ _) smul_add := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; exact congr_arg _ (smul_add _ _ _) smul_zero := by rintro ⟨a⟩; exact congr_arg _ (smul_zero _) add_smul := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; exact congr_arg _ (add_smul _ _ _) zero_smul := by rintro ⟨a⟩; exact congr_arg _ (zero_smul _ _) /-- `R^n/I^n` is isomorphic to `(R/I)^n` as an `R/I`-module. -/ noncomputable def piQuotEquiv [I.IsTwoSided] : ((ι → R) ⧸ pi fun _ ↦ I) ≃ₗ[R ⧸ I] ι → (R ⧸ I) where toFun x := Quotient.liftOn' x (fun f i ↦ Ideal.Quotient.mk I (f i)) fun _ _ hab ↦ funext fun i ↦ (Submodule.Quotient.eq' _).2 (QuotientAddGroup.leftRel_apply.mp hab i) map_add' := by rintro ⟨_⟩ ⟨_⟩; rfl map_smul' := by rintro ⟨_⟩ ⟨_⟩; rfl invFun x := Ideal.Quotient.mk _ (Quotient.out <| x ·) left_inv := by rintro ⟨x⟩ exact Ideal.Quotient.eq.2 fun i ↦ Ideal.Quotient.eq.1 (Quotient.out_eq' _) right_inv x := funext fun i ↦ Quotient.out_eq' (x i) /-- If `f : R^n → R^m` is an `R`-linear map and `I ⊆ R` is an ideal, then the image of `I^n` is contained in `I^m`. -/ theorem map_pi [I.IsTwoSided] {ι : Type*} [Finite ι] {ι' : Type w} (x : ι → R) (hi : ∀ i, x i ∈ I) (f : (ι → R) →ₗ[R] ι' → R) (i : ι') : f x i ∈ I := by classical cases nonempty_fintype ι rw [pi_eq_sum_univ x] simp only [Finset.sum_apply, smul_eq_mul, map_sum, Pi.smul_apply, map_smul] exact I.sum_mem fun j _ => I.mul_mem_right _ (hi j) end Pi open scoped Pointwise in /-- A ring is made up of a disjoint union of cosets of an ideal. -/ lemma univ_eq_iUnion_image_add : (Set.univ (α := R)) = ⋃ x : R ⧸ I, x.out +ᵥ (I : Set R) := QuotientAddGroup.univ_eq_iUnion_vadd I.toAddSubgroup variable {I} in lemma _root_.Finite.of_finite_quot_finite_ideal [hI : Finite I] [h : Finite (R ⧸ I)] : Finite R := @Finite.of_finite_quot_finite_addSubgroup _ _ _ hI h end Ideal
Domineering.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.SetTheory.Game.State import Mathlib.Tactic.Linter.DeprecatedModule deprecated_module "This module is now at `CombinatorialGames.Game.Specific.Domineering` in the CGT repo <https://github.com/vihdzp/combinatorial-games>" (since := "2025-08-06") /-! # Domineering as a combinatorial game. We define the game of Domineering, played on a chessboard of arbitrary shape (possibly even disconnected). Left moves by placing a domino vertically, while Right moves by placing a domino horizontally. This is only a fragment of a full development; in order to successfully analyse positions we would need some more theorems. Most importantly, we need a general statement that allows us to discard irrelevant moves. Specifically to domineering, we need the fact that disjoint parts of the chessboard give sums of games. -/ namespace SetTheory namespace PGame namespace Domineering open Function /-- The equivalence `(x, y) ↦ (x, y+1)`. -/ @[simps!] def shiftUp : ℤ × ℤ ≃ ℤ × ℤ := (Equiv.refl ℤ).prodCongr (Equiv.addRight (1 : ℤ)) /-- The equivalence `(x, y) ↦ (x+1, y)`. -/ @[simps!] def shiftRight : ℤ × ℤ ≃ ℤ × ℤ := (Equiv.addRight (1 : ℤ)).prodCongr (Equiv.refl ℤ) /-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/ -- Porting note: reducibility cannot be `local`. For now there are no dependents of this file so -- being globally reducible is fine. abbrev Board := Finset (ℤ × ℤ) /-- Left can play anywhere that a square and the square below it are open. -/ def left (b : Board) : Finset (ℤ × ℤ) := b ∩ b.map shiftUp /-- Right can play anywhere that a square and the square to the left are open. -/ def right (b : Board) : Finset (ℤ × ℤ) := b ∩ b.map shiftRight theorem mem_left {b : Board} (x : ℤ × ℤ) : x ∈ left b ↔ x ∈ b ∧ (x.1, x.2 - 1) ∈ b := Finset.mem_inter.trans (and_congr Iff.rfl Finset.mem_map_equiv) theorem mem_right {b : Board} (x : ℤ × ℤ) : x ∈ right b ↔ x ∈ b ∧ (x.1 - 1, x.2) ∈ b := Finset.mem_inter.trans (and_congr Iff.rfl Finset.mem_map_equiv) /-- After Left moves, two vertically adjacent squares are removed from the board. -/ def moveLeft (b : Board) (m : ℤ × ℤ) : Board := (b.erase m).erase (m.1, m.2 - 1) /-- After Left moves, two horizontally adjacent squares are removed from the board. -/ def moveRight (b : Board) (m : ℤ × ℤ) : Board := (b.erase m).erase (m.1 - 1, m.2) theorem fst_pred_mem_erase_of_mem_right {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) : (m.1 - 1, m.2) ∈ b.erase m := by rw [mem_right] at h apply Finset.mem_erase_of_ne_of_mem _ h.2 exact ne_of_apply_ne Prod.fst (pred_ne_self m.1) theorem snd_pred_mem_erase_of_mem_left {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) : (m.1, m.2 - 1) ∈ b.erase m := by rw [mem_left] at h apply Finset.mem_erase_of_ne_of_mem _ h.2 exact ne_of_apply_ne Prod.snd (pred_ne_self m.2) theorem card_of_mem_left {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) : 2 ≤ Finset.card b := by have w₁ : m ∈ b := (Finset.mem_inter.1 h).1 have w₂ : (m.1, m.2 - 1) ∈ b.erase m := snd_pred_mem_erase_of_mem_left h have i₁ := Finset.card_erase_lt_of_mem w₁ have i₂ := Nat.lt_of_le_of_lt (Nat.zero_le _) (Finset.card_erase_lt_of_mem w₂) exact Nat.lt_of_le_of_lt i₂ i₁ theorem card_of_mem_right {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) : 2 ≤ Finset.card b := by have w₁ : m ∈ b := (Finset.mem_inter.1 h).1 have w₂ := fst_pred_mem_erase_of_mem_right h have i₁ := Finset.card_erase_lt_of_mem w₁ have i₂ := Nat.lt_of_le_of_lt (Nat.zero_le _) (Finset.card_erase_lt_of_mem w₂) exact Nat.lt_of_le_of_lt i₂ i₁ theorem moveLeft_card {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) : Finset.card (moveLeft b m) + 2 = Finset.card b := by dsimp only [moveLeft] rw [Finset.card_erase_of_mem (snd_pred_mem_erase_of_mem_left h)] rw [Finset.card_erase_of_mem (Finset.mem_of_mem_inter_left h)] exact tsub_add_cancel_of_le (card_of_mem_left h) theorem moveRight_card {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) : Finset.card (moveRight b m) + 2 = Finset.card b := by dsimp only [moveRight] rw [Finset.card_erase_of_mem (fst_pred_mem_erase_of_mem_right h)] rw [Finset.card_erase_of_mem (Finset.mem_of_mem_inter_left h)] exact tsub_add_cancel_of_le (card_of_mem_right h) theorem moveLeft_smaller {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) : Finset.card (moveLeft b m) / 2 < Finset.card b / 2 := by simp [← moveLeft_card h] theorem moveRight_smaller {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) : Finset.card (moveRight b m) / 2 < Finset.card b / 2 := by simp [← moveRight_card h] /-- The instance describing allowed moves on a Domineering board. -/ instance state : State Board where turnBound s := s.card / 2 l s := (left s).image (moveLeft s) r s := (right s).image (moveRight s) left_bound m := by simp only [Finset.mem_image, Prod.exists] at m rcases m with ⟨_, _, ⟨h, rfl⟩⟩ exact moveLeft_smaller h right_bound m := by simp only [Finset.mem_image, Prod.exists] at m rcases m with ⟨_, _, ⟨h, rfl⟩⟩ exact moveRight_smaller h end Domineering /-- Construct a pre-game from a Domineering board. -/ def domineering (b : Domineering.Board) : PGame := PGame.ofState b /-- All games of Domineering are short, because each move removes two squares. -/ instance shortDomineering (b : Domineering.Board) : Short (domineering b) := by dsimp only [domineering] infer_instance /-- The Domineering board with two squares arranged vertically, in which Left has the only move. -/ def domineering.one := domineering [(0, 0), (0, 1)].toFinset /-- The `L` shaped Domineering board, in which Left is exactly half a move ahead. -/ def domineering.L := domineering [(0, 2), (0, 1), (0, 0), (1, 0)].toFinset instance shortOne : Short domineering.one := by dsimp [domineering.one]; infer_instance instance shortL : Short domineering.L := by dsimp [domineering.L]; infer_instance -- The VM can play small games successfully: -- #eval decide (domineering.one ≈ 1) -- #eval decide (domineering.L + domineering.L ≈ 1) -- The following no longer works since Lean 3.29, since definitions by well-founded -- recursion no longer reduce definitionally. -- We can check that `Decidable` instances reduce as expected, -- and so our implementation of domineering is computable. -- run_cmd tactic.whnf `(by apply_instance : Decidable (domineering.one ≤ 1)) >>= tactic.trace -- dec_trivial can handle most of the dictionary of small games described in [conway2001] -- example : domineering.one ≈ 1 := by decide -- example : domineering.L + domineering.L ≈ 1 := by decide -- example : domineering.L ≈ PGame.ofLists [0] [1] := by decide -- example : (domineering ([(0,0), (0,1), (0,2), (0,3)].toFinset) ≈ 2) := by decide -- example : (domineering ([(0,0), (0,1), (1,0), (1,1)].toFinset) ≈ PGame.ofLists [1] [-1]) := -- by decide -- The 3x3 grid is doable, but takes a minute... -- example : -- (domineering ([(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)].toFinset) ≈ -- PGame.ofLists [1] [-1]) := by decide -- The 5x5 grid is actually 0, but brute-forcing this is too challenging even for the VM. -- #eval decide (domineering ([ -- (0,0), (0,1), (0,2), (0,3), (0,4), -- (1,0), (1,1), (1,2), (1,3), (1,4), -- (2,0), (2,1), (2,2), (2,3), (2,4), -- (3,0), (3,1), (3,2), (3,3), (3,4), -- (4,0), (4,1), (4,2), (4,3), (4,4) -- ].toFinset) ≈ 0) end PGame end SetTheory
Constructions.lean
/- Copyright (c) 2022 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Sébastien Gouëzel, Heather Macbeth, Floris van Doorn -/ import Mathlib.Topology.FiberBundle.Constructions import Mathlib.Topology.VectorBundle.Basic import Mathlib.Analysis.NormedSpace.OperatorNorm.Prod /-! # Standard constructions on vector bundles This file contains several standard constructions on vector bundles: * `Bundle.Trivial.vectorBundle 𝕜 B F`: the trivial vector bundle with scalar field `𝕜` and model fiber `F` over the base `B` * `VectorBundle.prod`: for vector bundles `E₁` and `E₂` with scalar field `𝕜` over a common base, a vector bundle structure on their direct sum `E₁ ×ᵇ E₂` (the notation stands for `fun x ↦ E₁ x × E₂ x`). * `VectorBundle.pullback`: for a vector bundle `E` over `B`, a vector bundle structure on its pullback `f *ᵖ E` by a map `f : B' → B` (the notation is a type synonym for `E ∘ f`). ## Tags Vector bundle, direct sum, pullback -/ noncomputable section open Bundle Set FiberBundle /-! ### The trivial vector bundle -/ namespace Bundle.Trivial variable (𝕜 : Type*) (B : Type*) (F : Type*) [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace B] instance trivialization.isLinear : (trivialization B F).IsLinear 𝕜 where linear _ _ := ⟨fun _ _ => rfl, fun _ _ => rfl⟩ variable {𝕜} in theorem trivialization.coordChangeL (b : B) : (trivialization B F).coordChangeL 𝕜 (trivialization B F) b = ContinuousLinearEquiv.refl 𝕜 F := by ext v rw [Trivialization.coordChangeL_apply'] exacts [rfl, ⟨mem_univ _, mem_univ _⟩] instance vectorBundle : VectorBundle 𝕜 F (Bundle.Trivial B F) where trivialization_linear' e he := by rw [eq_trivialization B F e] infer_instance continuousOn_coordChange' e e' he he' := by obtain rfl := eq_trivialization B F e obtain rfl := eq_trivialization B F e' simp only [trivialization.coordChangeL] exact continuous_const.continuousOn @[simp] lemma linearMapAt_trivialization (x : B) : (trivialization B F).linearMapAt 𝕜 x = LinearMap.id := by ext v rw [Trivialization.coe_linearMapAt_of_mem _ (by simp)] rfl @[simp] lemma continuousLinearMapAt_trivialization (x : B) : (trivialization B F).continuousLinearMapAt 𝕜 x = ContinuousLinearMap.id 𝕜 F := by ext; simp @[simp] lemma symmₗ_trivialization (x : B) : (trivialization B F).symmₗ 𝕜 x = LinearMap.id := by ext; simp [Trivialization.coe_symmₗ, trivialization_symm_apply B F] @[simp] lemma symmL_trivialization (x : B) : (trivialization B F).symmL 𝕜 x = ContinuousLinearMap.id 𝕜 F := by ext; simp [trivialization_symm_apply B F] @[simp] lemma continuousLinearEquivAt_trivialization (x : B) : (trivialization B F).continuousLinearEquivAt 𝕜 x (mem_univ _) = ContinuousLinearEquiv.refl 𝕜 F := by ext; simp end Bundle.Trivial /-! ### Direct sum of two vector bundles -/ section variable (𝕜 : Type*) {B : Type*} [NontriviallyNormedField 𝕜] [TopologicalSpace B] (F₁ : Type*) [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] (E₁ : B → Type*) [TopologicalSpace (TotalSpace F₁ E₁)] (F₂ : Type*) [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] (E₂ : B → Type*) [TopologicalSpace (TotalSpace F₂ E₂)] namespace Trivialization variable {F₁ E₁ F₂ E₂} variable [∀ x, AddCommMonoid (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [∀ x, AddCommMonoid (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] (e₁ e₁' : Trivialization F₁ (π F₁ E₁)) (e₂ e₂' : Trivialization F₂ (π F₂ E₂)) instance prod.isLinear [e₁.IsLinear 𝕜] [e₂.IsLinear 𝕜] : (e₁.prod e₂).IsLinear 𝕜 where linear := fun _ ⟨h₁, h₂⟩ => (((e₁.linear 𝕜 h₁).mk' _).prodMap ((e₂.linear 𝕜 h₂).mk' _)).isLinear @[simp] theorem coordChangeL_prod [e₁.IsLinear 𝕜] [e₁'.IsLinear 𝕜] [e₂.IsLinear 𝕜] [e₂'.IsLinear 𝕜] ⦃b⦄ (hb : (b ∈ e₁.baseSet ∧ b ∈ e₂.baseSet) ∧ b ∈ e₁'.baseSet ∧ b ∈ e₂'.baseSet) : ((e₁.prod e₂).coordChangeL 𝕜 (e₁'.prod e₂') b : F₁ × F₂ →L[𝕜] F₁ × F₂) = (e₁.coordChangeL 𝕜 e₁' b : F₁ →L[𝕜] F₁).prodMap (e₂.coordChangeL 𝕜 e₂' b) := by rw [ContinuousLinearMap.ext_iff, ContinuousLinearMap.coe_prodMap'] rintro ⟨v₁, v₂⟩ change (e₁.prod e₂).coordChangeL 𝕜 (e₁'.prod e₂') b (v₁, v₂) = (e₁.coordChangeL 𝕜 e₁' b v₁, e₂.coordChangeL 𝕜 e₂' b v₂) rw [e₁.coordChangeL_apply e₁', e₂.coordChangeL_apply e₂', (e₁.prod e₂).coordChangeL_apply'] exacts [rfl, hb, ⟨hb.1.2, hb.2.2⟩, ⟨hb.1.1, hb.2.1⟩] variable {e₁ e₂} [∀ x : B, TopologicalSpace (E₁ x)] [∀ x : B, TopologicalSpace (E₂ x)] [FiberBundle F₁ E₁] [FiberBundle F₂ E₂] theorem prod_apply' [e₁.IsLinear 𝕜] [e₂.IsLinear 𝕜] {x : B} (hx₁ : x ∈ e₁.baseSet) (hx₂ : x ∈ e₂.baseSet) (v₁ : E₁ x) (v₂ : E₂ x) : prod e₁ e₂ ⟨x, (v₁, v₂)⟩ = ⟨x, e₁.continuousLinearEquivAt 𝕜 x hx₁ v₁, e₂.continuousLinearEquivAt 𝕜 x hx₂ v₂⟩ := rfl end Trivialization open Trivialization variable [∀ x, AddCommMonoid (E₁ x)] [∀ x, Module 𝕜 (E₁ x)] [∀ x, AddCommMonoid (E₂ x)] [∀ x, Module 𝕜 (E₂ x)] [∀ x : B, TopologicalSpace (E₁ x)] [∀ x : B, TopologicalSpace (E₂ x)] [FiberBundle F₁ E₁] [FiberBundle F₂ E₂] /-- The product of two vector bundles is a vector bundle. -/ instance VectorBundle.prod [VectorBundle 𝕜 F₁ E₁] [VectorBundle 𝕜 F₂ E₂] : VectorBundle 𝕜 (F₁ × F₂) (E₁ ×ᵇ E₂) where trivialization_linear' := by rintro _ ⟨e₁, e₂, he₁, he₂, rfl⟩ infer_instance continuousOn_coordChange' := by rintro _ _ ⟨e₁, e₂, he₁, he₂, rfl⟩ ⟨e₁', e₂', he₁', he₂', rfl⟩ refine (((continuousOn_coordChange 𝕜 e₁ e₁').mono ?_).prod_mapL 𝕜 ((continuousOn_coordChange 𝕜 e₂ e₂').mono ?_)).congr ?_ <;> dsimp only [prod_baseSet, mfld_simps] · mfld_set_tac · mfld_set_tac · rintro b hb rw [ContinuousLinearMap.ext_iff] rintro ⟨v₁, v₂⟩ change (e₁.prod e₂).coordChangeL 𝕜 (e₁'.prod e₂') b (v₁, v₂) = (e₁.coordChangeL 𝕜 e₁' b v₁, e₂.coordChangeL 𝕜 e₂' b v₂) rw [e₁.coordChangeL_apply e₁', e₂.coordChangeL_apply e₂', (e₁.prod e₂).coordChangeL_apply'] exacts [rfl, hb, ⟨hb.1.2, hb.2.2⟩, ⟨hb.1.1, hb.2.1⟩] variable {𝕜 F₁ E₁ F₂ E₂} @[simp] theorem Trivialization.continuousLinearEquivAt_prod {e₁ : Trivialization F₁ (π F₁ E₁)} {e₂ : Trivialization F₂ (π F₂ E₂)} [e₁.IsLinear 𝕜] [e₂.IsLinear 𝕜] {x : B} (hx : x ∈ (e₁.prod e₂).baseSet) : (e₁.prod e₂).continuousLinearEquivAt 𝕜 x hx = (e₁.continuousLinearEquivAt 𝕜 x hx.1).prodCongr (e₂.continuousLinearEquivAt 𝕜 x hx.2) := by ext v : 2 obtain ⟨v₁, v₂⟩ := v rw [(e₁.prod e₂).continuousLinearEquivAt_apply 𝕜, Trivialization.prod] exact (congr_arg Prod.snd (prod_apply' 𝕜 hx.1 hx.2 v₁ v₂) :) end /-! ### Pullbacks of vector bundles -/ section variable (R 𝕜 : Type*) {B : Type*} (F : Type*) (E : B → Type*) {B' : Type*} (f : B' → B) instance [i : ∀ x : B, AddCommMonoid (E x)] (x : B') : AddCommMonoid ((f *ᵖ E) x) := i _ instance [Semiring R] [∀ x : B, AddCommMonoid (E x)] [i : ∀ x, Module R (E x)] (x : B') : Module R ((f *ᵖ E) x) := i _ variable {E F} [TopologicalSpace B'] [TopologicalSpace (TotalSpace F E)] [NontriviallyNormedField 𝕜] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [TopologicalSpace B] [∀ x, AddCommMonoid (E x)] [∀ x, Module 𝕜 (E x)] {K : Type*} [FunLike K B' B] [ContinuousMapClass K B' B] instance Trivialization.pullback_linear (e : Trivialization F (π F E)) [e.IsLinear 𝕜] (f : K) : (Trivialization.pullback (B' := B') e f).IsLinear 𝕜 where linear _ h := e.linear 𝕜 h instance VectorBundle.pullback [∀ x, TopologicalSpace (E x)] [FiberBundle F E] [VectorBundle 𝕜 F E] (f : K) : VectorBundle 𝕜 F ((f : B' → B) *ᵖ E) where trivialization_linear' := by rintro _ ⟨e, he, rfl⟩ infer_instance continuousOn_coordChange' := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ refine ((continuousOn_coordChange 𝕜 e e').comp (map_continuous f).continuousOn fun b hb => hb).congr ?_ rintro b (hb : f b ∈ e.baseSet ∩ e'.baseSet); ext v change ((e.pullback f).coordChangeL 𝕜 (e'.pullback f) b) v = (e.coordChangeL 𝕜 e' (f b)) v rw [e.coordChangeL_apply e' hb, (e.pullback f).coordChangeL_apply' _] exacts [rfl, hb] end
Defs.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Anne Baanen, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Group.Hom.Instances import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Module.RingHom import Mathlib.Algebra.Ring.CompTypeclasses import Mathlib.GroupTheory.GroupAction.Hom /-! # (Semi)linear maps In this file we define * `LinearMap σ M M₂`, `M →ₛₗ[σ] M₂` : a semilinear map between two `Module`s. Here, `σ` is a `RingHom` from `R` to `R₂` and an `f : M →ₛₗ[σ] M₂` satisfies `f (c • x) = (σ c) • (f x)`. We recover plain linear maps by choosing `σ` to be `RingHom.id R`. This is denoted by `M →ₗ[R] M₂`. We also add the notation `M →ₗ⋆[R] M₂` for star-linear maps. * `IsLinearMap R f` : predicate saying that `f : M → M₂` is a linear map. (Note that this was not generalized to semilinear maps.) We then provide `LinearMap` with the following instances: * `LinearMap.addCommMonoid` and `LinearMap.addCommGroup`: the elementwise addition structures corresponding to addition in the codomain * `LinearMap.distribMulAction` and `LinearMap.module`: the elementwise scalar action structures corresponding to applying the action in the codomain. ## Implementation notes To ensure that composition works smoothly for semilinear maps, we use the typeclasses `RingHomCompTriple`, `RingHomInvPair` and `RingHomSurjective` from `Mathlib/Algebra/Ring/CompTypeclasses.lean`. ## Notation * Throughout the file, we denote regular linear maps by `fₗ`, `gₗ`, etc, and semilinear maps by `f`, `g`, etc. ## TODO * Parts of this file have not yet been generalized to semilinear maps (i.e. `CompatibleSMul`) ## Tags linear map -/ assert_not_exists TrivialStar DomMulAct Pi.module WCovBy.image Field open Function universe u u' v w variable {R R₁ R₂ R₃ S S₃ T M M₁ M₂ M₃ N₂ N₃ : Type*} /-- A map `f` between modules over a semiring is linear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = c • f x`. The predicate `IsLinearMap R f` asserts this property. A bundled version is available with `LinearMap`, and should be favored over `IsLinearMap` most of the time. -/ structure IsLinearMap (R : Type u) {M : Type v} {M₂ : Type w} [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] (f : M → M₂) : Prop where /-- A linear map preserves addition. -/ map_add : ∀ x y, f (x + y) = f x + f y /-- A linear map preserves scalar multiplication. -/ map_smul : ∀ (c : R) (x), f (c • x) = c • f x section /-- A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. Elements of `LinearMap σ M M₂` (available under the notation `M →ₛₗ[σ] M₂`) are bundled versions of such maps. For plain linear maps (i.e. for which `σ = RingHom.id R`), the notation `M →ₗ[R] M₂` is available. An unbundled version of plain linear maps is available with the predicate `IsLinearMap`, but it should be avoided most of the time. -/ structure LinearMap {R S : Type*} [Semiring R] [Semiring S] (σ : R →+* S) (M : Type*) (M₂ : Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] extends AddHom M M₂, MulActionHom σ M M₂ /-- The `MulActionHom` underlying a `LinearMap`. -/ add_decl_doc LinearMap.toMulActionHom /-- The `AddHom` underlying a `LinearMap`. -/ add_decl_doc LinearMap.toAddHom /-- `M →ₛₗ[σ] N` is the type of `σ`-semilinear maps from `M` to `N`. -/ notation:25 M " →ₛₗ[" σ:25 "] " M₂:0 => LinearMap σ M M₂ /-- `M →ₗ[R] N` is the type of `R`-linear maps from `M` to `N`. -/ notation:25 M " →ₗ[" R:25 "] " M₂:0 => LinearMap (RingHom.id R) M M₂ /-- `SemilinearMapClass F σ M M₂` asserts `F` is a type of bundled `σ`-semilinear maps `M → M₂`. See also `LinearMapClass F R M M₂` for the case where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and `f (c • x) = (σ c) • f x`. -/ class SemilinearMapClass (F : Type*) {R S : outParam Type*} [Semiring R] [Semiring S] (σ : outParam (R →+* S)) (M M₂ : outParam Type*) [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] [FunLike F M M₂] : Prop extends AddHomClass F M M₂, MulActionSemiHomClass F σ M M₂ end -- `map_smulₛₗ` should be `@[simp]` but doesn't fire due to https://github.com/leanprover/lean4/pull/3701. -- attribute [simp] map_smulₛₗ /-- `LinearMapClass F R M M₂` asserts `F` is a type of bundled `R`-linear maps `M → M₂`. This is an abbreviation for `SemilinearMapClass F (RingHom.id R) M M₂`. -/ abbrev LinearMapClass (F : Type*) (R : outParam Type*) (M M₂ : Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] [FunLike F M M₂] := SemilinearMapClass F (RingHom.id R) M M₂ protected lemma LinearMapClass.map_smul {R M M₂ : outParam Type*} [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] {F : Type*} [FunLike F M M₂] [LinearMapClass F R M M₂] (f : F) (r : R) (x : M) : f (r • x) = r • f x := by rw [map_smul] namespace SemilinearMapClass variable (F : Type*) variable [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module S M₃] variable {σ : R →+* S} instance (priority := 100) instAddMonoidHomClass [FunLike F M M₃] [SemilinearMapClass F σ M M₃] : AddMonoidHomClass F M M₃ := { SemilinearMapClass.toAddHomClass with map_zero := fun f ↦ show f 0 = 0 by rw [← zero_smul R (0 : M), map_smulₛₗ] simp } instance (priority := 100) distribMulActionSemiHomClass [FunLike F M M₃] [SemilinearMapClass F σ M M₃] : DistribMulActionSemiHomClass F σ M M₃ := { SemilinearMapClass.toAddHomClass with map_smulₛₗ := fun f c x ↦ by rw [map_smulₛₗ] } variable {F} (f : F) [FunLike F M M₃] [SemilinearMapClass F σ M M₃] theorem map_smul_inv {σ' : S →+* R} [RingHomInvPair σ σ'] (c : S) (x : M) : c • f x = f (σ' c • x) := by simp [map_smulₛₗ _] /-- Reinterpret an element of a type of semilinear maps as a semilinear map. -/ @[coe] def semilinearMap : M →ₛₗ[σ] M₃ where toFun := f map_add' := map_add f map_smul' := map_smulₛₗ f /-- Reinterpret an element of a type of semilinear maps as a semilinear map. -/ instance instCoeToSemilinearMap : CoeHead F (M →ₛₗ[σ] M₃) where coe f := semilinearMap f end SemilinearMapClass namespace LinearMapClass variable {F : Type*} [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : F) [FunLike F M₁ M₂] [LinearMapClass F R M₁ M₂] /-- Reinterpret an element of a type of linear maps as a linear map. -/ abbrev linearMap : M₁ →ₗ[R] M₂ := SemilinearMapClass.semilinearMap f /-- Reinterpret an element of a type of linear maps as a linear map. -/ instance instCoeToLinearMap : CoeHead F (M₁ →ₗ[R] M₂) where coe f := SemilinearMapClass.semilinearMap f end LinearMapClass namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring S] section variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module S M₃] variable {σ : R →+* S} instance instFunLike : FunLike (M →ₛₗ[σ] M₃) M M₃ where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h instance semilinearMapClass : SemilinearMapClass (M →ₛₗ[σ] M₃) σ M M₃ where map_add f := f.map_add' map_smulₛₗ := LinearMap.map_smul' @[simp, norm_cast] lemma coe_coe {F : Type*} [FunLike F M M₃] [SemilinearMapClass F σ M M₃] {f : F} : ⇑(f : M →ₛₗ[σ] M₃) = f := rfl /-- The `DistribMulActionHom` underlying a `LinearMap`. -/ def toDistribMulActionHom (f : M →ₛₗ[σ] M₃) : DistribMulActionHom σ.toMonoidHom M M₃ := { f with map_zero' := show f 0 = 0 from map_zero f } @[simp] theorem coe_toAddHom (f : M →ₛₗ[σ] M₃) : ⇑f.toAddHom = f := rfl -- Porting note: no longer a `simp` theorem toFun_eq_coe {f : M →ₛₗ[σ] M₃} : f.toFun = (f : M → M₃) := rfl @[ext] theorem ext {f g : M →ₛₗ[σ] M₃} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h /-- Copy of a `LinearMap` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : M →ₛₗ[σ] M₃) (f' : M → M₃) (h : f' = ⇑f) : M →ₛₗ[σ] M₃ where toFun := f' map_add' := h.symm ▸ f.map_add' map_smul' := h.symm ▸ f.map_smul' @[simp] theorem coe_copy (f : M →ₛₗ[σ] M₃) (f' : M → M₃) (h : f' = ⇑f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : M →ₛₗ[σ] M₃) (f' : M → M₃) (h : f' = ⇑f) : f.copy f' h = f := DFunLike.ext' h initialize_simps_projections LinearMap (toFun → apply) @[simp] theorem coe_mk {σ : R →+* S} (f : AddHom M M₃) (h) : ((LinearMap.mk f h : M →ₛₗ[σ] M₃) : M → M₃) = f := rfl @[simp] theorem coe_addHom_mk {σ : R →+* S} (f : AddHom M M₃) (h) : ((LinearMap.mk f h : M →ₛₗ[σ] M₃) : AddHom M M₃) = f := rfl theorem coe_semilinearMap {F : Type*} [FunLike F M M₃] [SemilinearMapClass F σ M M₃] (f : F) : ((f : M →ₛₗ[σ] M₃) : M → M₃) = f := rfl theorem toLinearMap_injective {F : Type*} [FunLike F M M₃] [SemilinearMapClass F σ M M₃] {f g : F} (h : (f : M →ₛₗ[σ] M₃) = (g : M →ₛₗ[σ] M₃)) : f = g := by apply DFunLike.ext intro m exact DFunLike.congr_fun h m /-- Identity map as a `LinearMap` -/ def id : M →ₗ[R] M := { DistribMulActionHom.id R with toFun := _root_.id } theorem id_apply (x : M) : @id R M _ _ _ x = x := rfl @[simp, norm_cast] theorem id_coe : ((LinearMap.id : M →ₗ[R] M) : M → M) = _root_.id := rfl /-- A generalisation of `LinearMap.id` that constructs the identity function as a `σ`-semilinear map for any ring homomorphism `σ` which we know is the identity. -/ @[simps] def id' {σ : R →+* R} [RingHomId σ] : M →ₛₗ[σ] M where toFun x := x map_add' _ _ := rfl map_smul' r x := by have := (RingHomId.eq_id : σ = _) subst this rfl @[simp, norm_cast] theorem id'_coe {σ : R →+* R} [RingHomId σ] : ((id' : M →ₛₗ[σ] M) : M → M) = _root_.id := rfl end section variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R M₂] [Module S M₃] variable (σ : R →+* S) variable (fₗ : M →ₗ[R] M₂) (f g : M →ₛₗ[σ] M₃) theorem isLinear : IsLinearMap R fₗ := ⟨fₗ.map_add', fₗ.map_smul'⟩ variable {fₗ f g σ} theorem coe_injective : Injective (DFunLike.coe : (M →ₛₗ[σ] M₃) → _) := DFunLike.coe_injective protected theorem congr_arg {x x' : M} : x = x' → f x = f x' := DFunLike.congr_arg f /-- If two linear maps are equal, they are equal at each point. -/ protected theorem congr_fun (h : f = g) (x : M) : f x = g x := DFunLike.congr_fun h x @[simp] lemma mk_coe (f : M →ₛₗ[σ] M₃) (h) : (mk f h : M →ₛₗ[σ] M₃) = f := rfl @[simp] lemma mk_coe' (f : M →ₛₗ[σ] M₃) (h) : (mk f.toAddHom h : M →ₛₗ[σ] M₃) = f := rfl variable (fₗ f g) protected theorem map_add (x y : M) : f (x + y) = f x + f y := map_add f x y protected theorem map_zero : f 0 = 0 := map_zero f -- Porting note: `simp` wasn't picking up `map_smulₛₗ` for `LinearMap`s without specifying -- `map_smulₛₗ f`, so we marked this as `@[simp]` in Mathlib3. -- For Mathlib4, let's try without the `@[simp]` attribute and hope it won't need to be re-enabled. -- This has to be re-tagged as `@[simp]` in https://github.com/leanprover-community/mathlib4/pull/8386 (see also https://github.com/leanprover/lean4/issues/3107). @[simp] protected theorem map_smulₛₗ (c : R) (x : M) : f (c • x) = σ c • f x := map_smulₛₗ f c x protected theorem map_smul (c : R) (x : M) : fₗ (c • x) = c • fₗ x := map_smul fₗ c x protected theorem map_smul_inv {σ' : S →+* R} [RingHomInvPair σ σ'] (c : S) (x : M) : c • f x = f (σ' c • x) := by simp @[simp] theorem map_eq_zero_iff (h : Function.Injective f) {x : M} : f x = 0 ↔ x = 0 := _root_.map_eq_zero_iff f h variable (M M₂) /-- A typeclass for `SMul` structures which can be moved through a `LinearMap`. This typeclass is generated automatically from an `IsScalarTower` instance, but exists so that we can also add an instance for `AddCommGroup.toIntModule`, allowing `z •` to be moved even if `S` does not support negation. -/ class CompatibleSMul (R S : Type*) [Semiring S] [SMul R M] [Module S M] [SMul R M₂] [Module S M₂] : Prop where /-- Scalar multiplication by `R` of `M` can be moved through linear maps. -/ map_smul : ∀ (fₗ : M →ₗ[S] M₂) (c : R) (x : M), fₗ (c • x) = c • fₗ x variable {M M₂} section variable {R S : Type*} [Semiring S] [SMul R M] [Module S M] [SMul R M₂] [Module S M₂] instance (priority := 100) IsScalarTower.compatibleSMul [SMul R S] [IsScalarTower R S M] [IsScalarTower R S M₂] : CompatibleSMul M M₂ R S := ⟨fun fₗ c x ↦ by rw [← smul_one_smul S c x, ← smul_one_smul S c (fₗ x), map_smul]⟩ instance IsScalarTower.compatibleSMul' [SMul R S] [IsScalarTower R S M] : CompatibleSMul S M R S where map_smul := (IsScalarTower.smulHomClass R S M (S →ₗ[S] M)).map_smulₛₗ @[simp] theorem map_smul_of_tower [CompatibleSMul M M₂ R S] (fₗ : M →ₗ[S] M₂) (c : R) (x : M) : fₗ (c • x) = c • fₗ x := CompatibleSMul.map_smul fₗ c x theorem _root_.LinearMapClass.map_smul_of_tower {F : Type*} [CompatibleSMul M M₂ R S] [FunLike F M M₂] [LinearMapClass F S M M₂] (fₗ : F) (c : R) (x : M) : fₗ (c • x) = c • fₗ x := LinearMap.CompatibleSMul.map_smul (fₗ : M →ₗ[S] M₂) c x variable (R R) in theorem isScalarTower_of_injective [SMul R S] [CompatibleSMul M M₂ R S] [IsScalarTower R S M₂] (f : M →ₗ[S] M₂) (hf : Function.Injective f) : IsScalarTower R S M where smul_assoc r s _ := hf <| by rw [f.map_smul_of_tower r, map_smul, map_smul, smul_assoc] @[simp] lemma _root_.map_zsmul_unit {F M N : Type*} [AddGroup M] [AddGroup N] [FunLike F M N] [AddMonoidHomClass F M N] (f : F) (c : ℤˣ) (m : M) : f (c • m) = c • f m := by simp [Units.smul_def] end variable (R) in theorem isLinearMap_of_compatibleSMul [Module S M] [Module S M₂] [CompatibleSMul M M₂ R S] (f : M →ₗ[S] M₂) : IsLinearMap R f where map_add := map_add f map_smul := map_smul_of_tower f /-- convert a linear map to an additive map -/ def toAddMonoidHom : M →+ M₃ where toFun := f map_zero' := f.map_zero map_add' := f.map_add @[simp] theorem toAddMonoidHom_coe : ⇑f.toAddMonoidHom = f := rfl section RestrictScalars variable (R) variable [Module S M] [Module S M₂] [CompatibleSMul M M₂ R S] /-- If `M` and `M₂` are both `R`-modules and `S`-modules and `R`-module structures are defined by an action of `R` on `S` (formally, we have two scalar towers), then any `S`-linear map from `M` to `M₂` is `R`-linear. See also `LinearMap.map_smul_of_tower`. -/ @[coe] def restrictScalars (fₗ : M →ₗ[S] M₂) : M →ₗ[R] M₂ where toFun := fₗ map_add' := fₗ.map_add map_smul' := fₗ.map_smul_of_tower instance coeIsScalarTower : CoeHTCT (M →ₗ[S] M₂) (M →ₗ[R] M₂) := ⟨restrictScalars R⟩ @[simp, norm_cast] theorem coe_restrictScalars (f : M →ₗ[S] M₂) : ((f : M →ₗ[R] M₂) : M → M₂) = f := rfl theorem restrictScalars_apply (fₗ : M →ₗ[S] M₂) (x) : restrictScalars R fₗ x = fₗ x := rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : (M →ₗ[S] M₂) → M →ₗ[R] M₂) := fun _ _ h ↦ ext (LinearMap.congr_fun h :) @[simp] theorem restrictScalars_inj (fₗ gₗ : M →ₗ[S] M₂) : fₗ.restrictScalars R = gₗ.restrictScalars R ↔ fₗ = gₗ := (restrictScalars_injective R).eq_iff end RestrictScalars theorem toAddMonoidHom_injective : Function.Injective (toAddMonoidHom : (M →ₛₗ[σ] M₃) → M →+ M₃) := fun fₗ gₗ h ↦ ext <| (DFunLike.congr_fun h : ∀ x, fₗ.toAddMonoidHom x = gₗ.toAddMonoidHom x) /-- If two `σ`-linear maps from `R` are equal on `1`, then they are equal. -/ @[ext high] theorem ext_ring {f g : R →ₛₗ[σ] M₃} (h : f 1 = g 1) : f = g := ext fun x ↦ by rw [← mul_one x, ← smul_eq_mul, f.map_smulₛₗ, g.map_smulₛₗ, h] end /-- Interpret a `RingHom` `f` as an `f`-semilinear map. -/ @[simps] def _root_.RingHom.toSemilinearMap (f : R →+* S) : R →ₛₗ[f] S := { f with map_smul' := f.map_mul } @[simp] theorem _root_.RingHom.coe_toSemilinearMap (f : R →+* S) : ⇑f.toSemilinearMap = f := rfl section variable [Semiring R₁] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable {module_M₁ : Module R₁ M₁} {module_M₂ : Module R₂ M₂} {module_M₃ : Module R₃ M₃} variable {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} /-- Composition of two linear maps is a linear map -/ def comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₂] M₂) : M₁ →ₛₗ[σ₁₃] M₃ where toFun := f ∘ g map_add' := by simp only [map_add, forall_const, Function.comp_apply] -- Note that https://github.com/leanprover-community/mathlib4/pull/8386 changed `map_smulₛₗ` to `map_smulₛₗ _` map_smul' r x := by simp only [Function.comp_apply, map_smulₛₗ _, RingHomCompTriple.comp_apply] variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable (f : M₂ →ₛₗ[σ₂₃] M₃) (g : M₁ →ₛₗ[σ₁₂] M₂) /-- `∘ₗ` is notation for composition of two linear (not semilinear!) maps into a linear map. This is useful when Lean is struggling to infer the `RingHomCompTriple` instance. -/ notation3:80 (name := compNotation) f:81 " ∘ₗ " g:80 => LinearMap.comp (σ₁₂ := RingHom.id _) (σ₂₃ := RingHom.id _) (σ₁₃ := RingHom.id _) f g @[inherit_doc] infixr:90 " ∘ₛₗ " => comp theorem comp_apply (x : M₁) : f.comp g x = f (g x) := rfl @[simp, norm_cast] theorem coe_comp : (f.comp g : M₁ → M₃) = f ∘ g := rfl @[simp] theorem comp_id : f.comp id = f := rfl @[simp] theorem id_comp : id.comp f = f := rfl theorem comp_assoc {R₄ M₄ : Type*} [Semiring R₄] [AddCommMonoid M₄] [Module R₄ M₄] {σ₃₄ : R₃ →+* R₄} {σ₂₄ : R₂ →+* R₄} {σ₁₄ : R₁ →+* R₄} [RingHomCompTriple σ₂₃ σ₃₄ σ₂₄] [RingHomCompTriple σ₁₃ σ₃₄ σ₁₄] [RingHomCompTriple σ₁₂ σ₂₄ σ₁₄] (f : M₁ →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃) (h : M₃ →ₛₗ[σ₃₄] M₄) : ((h.comp g : M₂ →ₛₗ[σ₂₄] M₄).comp f : M₁ →ₛₗ[σ₁₄] M₄) = h.comp (g.comp f : M₁ →ₛₗ[σ₁₃] M₃) := rfl variable {f g} {f' : M₂ →ₛₗ[σ₂₃] M₃} {g' : M₁ →ₛₗ[σ₁₂] M₂} /-- The linear map version of `Function.Surjective.injective_comp_right` -/ lemma _root_.Function.Surjective.injective_linearMapComp_right (hg : Surjective g) : Injective fun f : M₂ →ₛₗ[σ₂₃] M₃ ↦ f.comp g := fun _ _ h ↦ ext <| hg.forall.2 (LinearMap.ext_iff.1 h) @[simp] theorem cancel_right (hg : Surjective g) : f.comp g = f'.comp g ↔ f = f' := hg.injective_linearMapComp_right.eq_iff /-- The linear map version of `Function.Injective.comp_left` -/ lemma _root_.Function.Injective.injective_linearMapComp_left (hf : Injective f) : Injective fun g : M₁ →ₛₗ[σ₁₂] M₂ ↦ f.comp g := fun g₁ g₂ (h : f.comp g₁ = f.comp g₂) ↦ ext fun x ↦ hf <| by rw [← comp_apply, h, comp_apply] theorem surjective_comp_left_of_exists_rightInverse {σ₃₂ : R₃ →+* R₂} [RingHomInvPair σ₂₃ σ₃₂] [RingHomCompTriple σ₁₃ σ₃₂ σ₁₂] (hf : ∃ f' : M₃ →ₛₗ[σ₃₂] M₂, f.comp f' = .id) : Surjective fun g : M₁ →ₛₗ[σ₁₂] M₂ ↦ f.comp g := by intro h obtain ⟨f', hf'⟩ := hf refine ⟨f'.comp h, ?_⟩ simp_rw [← comp_assoc, hf', id_comp] @[simp] theorem cancel_left (hf : Injective f) : f.comp g = f.comp g' ↔ g = g' := hf.injective_linearMapComp_left.eq_iff end variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] /-- If a function `g` is a left and right inverse of a linear map `f`, then `g` is linear itself. -/ def inverse (f : M →ₛₗ[σ] M₂) (g : M₂ → M) (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : M₂ →ₛₗ[σ'] M := by dsimp [LeftInverse, Function.RightInverse] at h₁ h₂ exact { toFun := g map_add' := fun x y ↦ by rw [← h₁ (g (x + y)), ← h₁ (g x + g y)]; simp [h₂] map_smul' := fun a b ↦ by rw [← h₁ (g (a • b)), ← h₁ (σ' a • g b)] simp [h₂] } variable (f : M →ₛₗ[σ] M₂) (g : M₂ →ₛₗ[σ'] M) (h : g.comp f = .id) include h theorem injective_of_comp_eq_id : Injective f := .of_comp (f := g) <| by simp_rw [← coe_comp, h, id_coe, bijective_id.1] theorem surjective_of_comp_eq_id : Surjective g := .of_comp (g := f) <| by simp_rw [← coe_comp, h, id_coe, bijective_id.2] end AddCommMonoid section AddCommGroup variable [Semiring R] [Semiring S] [AddCommGroup M] [AddCommGroup M₂] variable {module_M : Module R M} {module_M₂ : Module S M₂} {σ : R →+* S} variable (f : M →ₛₗ[σ] M₂) protected theorem map_neg (x : M) : f (-x) = -f x := map_neg f x protected theorem map_sub (x y : M) : f (x - y) = f x - f y := map_sub f x y instance CompatibleSMul.intModule {S : Type*} [Semiring S] [Module S M] [Module S M₂] : CompatibleSMul M M₂ ℤ S := ⟨fun fₗ c x ↦ by induction c with | zero => simp | succ n ih => simp [add_smul] | pred n ih => simp [sub_smul]⟩ instance CompatibleSMul.units {R S : Type*} [Monoid R] [MulAction R M] [MulAction R M₂] [Semiring S] [Module S M] [Module S M₂] [CompatibleSMul M M₂ R S] : CompatibleSMul M M₂ Rˣ S := ⟨fun fₗ c x ↦ (CompatibleSMul.map_smul fₗ (c : R) x :)⟩ end AddCommGroup end LinearMap namespace Module /-- `g : R →+* S` is `R`-linear when the module structure on `S` is `Module.compHom S g` . -/ @[simps] def compHom.toLinearMap {R S : Type*} [Semiring R] [Semiring S] (g : R →+* S) : letI := compHom S g; R →ₗ[R] S := letI := compHom S g { toFun := (g : R → S) map_add' := g.map_add map_smul' := g.map_mul } end Module namespace DistribMulActionHom variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Semiring R] [Module R M] [Semiring S] [Module S M₂] [Module R M₃] variable {σ : R →+* S} instance : SemilinearMapClass (M →ₑ+[σ.toMonoidHom] M₂) σ M M₂ where /-- A `DistribMulActionHom` between two modules is a linear map. -/ instance : LinearMapClass (M →+[R] M₃) R M M₃ where @[simp] theorem coe_toLinearMap (f : M →ₑ+[σ.toMonoidHom] M₂) : ((f : M →ₛₗ[σ] M₂) : M → M₂) = f := rfl theorem toLinearMap_injective {f g : M →ₑ+[σ.toMonoidHom] M₂} (h : (f : M →ₛₗ[σ] M₂) = (g : M →ₛₗ[σ] M₂)) : f = g := by ext m exact LinearMap.congr_fun h m end DistribMulActionHom namespace IsLinearMap section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] /-- Convert an `IsLinearMap` predicate to a `LinearMap` -/ def mk' (f : M → M₂) (lin : IsLinearMap R f) : M →ₗ[R] M₂ where toFun := f map_add' := lin.1 map_smul' := lin.2 @[simp] theorem mk'_apply {f : M → M₂} (lin : IsLinearMap R f) (x : M) : mk' f lin x = f x := rfl theorem isLinearMap_smul {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] (c : R) : IsLinearMap R fun z : M ↦ c • z := by refine IsLinearMap.mk (smul_add c) ?_ intro _ _ simp only [smul_smul, mul_comm] theorem isLinearMap_smul' {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] (a : M) : IsLinearMap R fun c : R ↦ c • a := IsLinearMap.mk (fun x y ↦ add_smul x y a) fun x y ↦ mul_smul x y a theorem map_zero {f : M → M₂} (lin : IsLinearMap R f) : f (0 : M) = (0 : M₂) := (lin.mk' f).map_zero end AddCommMonoid section AddCommGroup variable [Semiring R] [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R M₂] theorem isLinearMap_neg : IsLinearMap R fun z : M ↦ -z := IsLinearMap.mk neg_add fun x y ↦ (smul_neg x y).symm theorem map_neg {f : M → M₂} (lin : IsLinearMap R f) (x : M) : f (-x) = -f x := (lin.mk' f).map_neg x theorem map_sub {f : M → M₂} (lin : IsLinearMap R f) (x y : M) : f (x - y) = f x - f y := (lin.mk' f).map_sub x y end AddCommGroup end IsLinearMap /-- Reinterpret an additive homomorphism as an `ℕ`-linear map. -/ def AddMonoidHom.toNatLinearMap [AddCommMonoid M] [AddCommMonoid M₂] (f : M →+ M₂) : M →ₗ[ℕ] M₂ where toFun := f map_add' := f.map_add map_smul' := map_nsmul f theorem AddMonoidHom.toNatLinearMap_injective [AddCommMonoid M] [AddCommMonoid M₂] : Function.Injective (@AddMonoidHom.toNatLinearMap M M₂ _ _) := by intro f g h ext x exact LinearMap.congr_fun h x @[simp] theorem AddMonoidHom.coe_toNatLinearMap [AddCommMonoid M] [AddCommMonoid M₂] (f : M →+ M₂) : ⇑f.toNatLinearMap = f := rfl /-- Reinterpret an additive homomorphism as a `ℤ`-linear map. -/ def AddMonoidHom.toIntLinearMap [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : M →ₗ[ℤ] M₂ where toFun := f map_add' := f.map_add map_smul' := map_zsmul f theorem AddMonoidHom.toIntLinearMap_injective [AddCommGroup M] [AddCommGroup M₂] : Function.Injective (@AddMonoidHom.toIntLinearMap M M₂ _ _) := by intro f g h ext x exact LinearMap.congr_fun h x @[simp] theorem AddMonoidHom.coe_toIntLinearMap [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : ⇑f.toIntLinearMap = f := rfl namespace LinearMap section SMul variable [Semiring R] [Semiring R₂] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable {σ₁₂ : R →+* R₂} variable [Monoid S] [DistribMulAction S M₂] [SMulCommClass R₂ S M₂] variable [Monoid T] [DistribMulAction T M₂] [SMulCommClass R₂ T M₂] instance : SMul S (M →ₛₗ[σ₁₂] M₂) := ⟨fun a f ↦ { toFun := a • (f : M → M₂) map_add' := fun x y ↦ by simp only [Pi.smul_apply, f.map_add, smul_add] map_smul' := fun c x ↦ by simp [Pi.smul_apply, smul_comm] }⟩ @[simp] theorem smul_apply (a : S) (f : M →ₛₗ[σ₁₂] M₂) (x : M) : (a • f) x = a • f x := rfl theorem coe_smul (a : S) (f : M →ₛₗ[σ₁₂] M₂) : (a • f : M →ₛₗ[σ₁₂] M₂) = a • (f : M → M₂) := rfl instance [SMulCommClass S T M₂] : SMulCommClass S T (M →ₛₗ[σ₁₂] M₂) := ⟨fun _ _ _ ↦ ext fun _ ↦ smul_comm _ _ _⟩ -- example application of this instance: if S -> T -> R are homomorphisms of commutative rings and -- M and M₂ are R-modules then the S-module and T-module structures on Hom_R(M,M₂) are compatible. instance [SMul S T] [IsScalarTower S T M₂] : IsScalarTower S T (M →ₛₗ[σ₁₂] M₂) where smul_assoc _ _ _ := ext fun _ ↦ smul_assoc _ _ _ instance [DistribMulAction Sᵐᵒᵖ M₂] [SMulCommClass R₂ Sᵐᵒᵖ M₂] [IsCentralScalar S M₂] : IsCentralScalar S (M →ₛₗ[σ₁₂] M₂) where op_smul_eq_smul _ _ := ext fun _ ↦ op_smul_eq_smul _ _ end SMul /-! ### Arithmetic on the codomain -/ section Arithmetic variable [Semiring R₁] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [AddCommGroup N₂] [AddCommGroup N₃] variable [Module R₁ M] [Module R₂ M₂] [Module R₃ M₃] variable [Module R₂ N₂] [Module R₃ N₃] variable {σ₁₂ : R₁ →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R₁ →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] /-- The constant 0 map is linear. -/ instance : Zero (M →ₛₗ[σ₁₂] M₂) := ⟨{ toFun := 0 map_add' := by simp map_smul' := by simp }⟩ @[simp] theorem zero_apply (x : M) : (0 : M →ₛₗ[σ₁₂] M₂) x = 0 := rfl @[simp] theorem comp_zero (g : M₂ →ₛₗ[σ₂₃] M₃) : (g.comp (0 : M →ₛₗ[σ₁₂] M₂) : M →ₛₗ[σ₁₃] M₃) = 0 := ext fun c ↦ by rw [comp_apply, zero_apply, zero_apply, g.map_zero] @[simp] theorem zero_comp (f : M →ₛₗ[σ₁₂] M₂) : ((0 : M₂ →ₛₗ[σ₂₃] M₃).comp f : M →ₛₗ[σ₁₃] M₃) = 0 := rfl instance : Inhabited (M →ₛₗ[σ₁₂] M₂) := ⟨0⟩ @[simp] theorem default_def : (default : M →ₛₗ[σ₁₂] M₂) = 0 := rfl instance uniqueOfLeft [Subsingleton M] : Unique (M →ₛₗ[σ₁₂] M₂) := { inferInstanceAs (Inhabited (M →ₛₗ[σ₁₂] M₂)) with uniq := fun f => ext fun x => by rw [Subsingleton.elim x 0, map_zero, map_zero] } instance uniqueOfRight [Subsingleton M₂] : Unique (M →ₛₗ[σ₁₂] M₂) := coe_injective.unique theorem ne_zero_of_injective [Nontrivial M] {f : M →ₛₗ[σ₁₂] M₂} (hf : Injective f) : f ≠ 0 := have ⟨x, ne⟩ := exists_ne (0 : M) fun h ↦ hf.ne ne <| by simp [h] theorem ne_zero_of_surjective [Nontrivial M₂] {f : M →ₛₗ[σ₁₂] M₂} (hf : Surjective f) : f ≠ 0 := by have ⟨y, ne⟩ := exists_ne (0 : M₂) obtain ⟨x, rfl⟩ := hf y exact fun h ↦ ne congr($h x) /-- The sum of two linear maps is linear. -/ instance : Add (M →ₛₗ[σ₁₂] M₂) := ⟨fun f g ↦ { toFun := f + g map_add' := by simp [add_comm, add_left_comm] map_smul' := by simp [smul_add] }⟩ @[simp] theorem add_apply (f g : M →ₛₗ[σ₁₂] M₂) (x : M) : (f + g) x = f x + g x := rfl theorem add_comp (f : M →ₛₗ[σ₁₂] M₂) (g h : M₂ →ₛₗ[σ₂₃] M₃) : ((h + g).comp f : M →ₛₗ[σ₁₃] M₃) = h.comp f + g.comp f := rfl theorem comp_add (f g : M →ₛₗ[σ₁₂] M₂) (h : M₂ →ₛₗ[σ₂₃] M₃) : (h.comp (f + g) : M →ₛₗ[σ₁₃] M₃) = h.comp f + h.comp g := ext fun _ ↦ h.map_add _ _ /-- The type of linear maps is an additive monoid. -/ instance addCommMonoid : AddCommMonoid (M →ₛₗ[σ₁₂] M₂) := DFunLike.coe_injective.addCommMonoid _ rfl (fun _ _ ↦ rfl) fun _ _ ↦ rfl /-- The negation of a linear map is linear. -/ instance : Neg (M →ₛₗ[σ₁₂] N₂) := ⟨fun f ↦ { toFun := -f map_add' := by simp [add_comm] map_smul' := by simp }⟩ @[simp] theorem neg_apply (f : M →ₛₗ[σ₁₂] N₂) (x : M) : (-f) x = -f x := rfl @[simp] theorem neg_comp (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] N₃) : (-g).comp f = -g.comp f := rfl @[simp] theorem comp_neg (f : M →ₛₗ[σ₁₂] N₂) (g : N₂ →ₛₗ[σ₂₃] N₃) : g.comp (-f) = -g.comp f := ext fun _ ↦ g.map_neg _ /-- The subtraction of two linear maps is linear. -/ instance : Sub (M →ₛₗ[σ₁₂] N₂) := ⟨fun f g ↦ { toFun := f - g map_add' := fun x y ↦ by simp only [Pi.sub_apply, map_add, add_sub_add_comm] map_smul' := fun r x ↦ by simp [Pi.sub_apply, smul_sub] }⟩ @[simp] theorem sub_apply (f g : M →ₛₗ[σ₁₂] N₂) (x : M) : (f - g) x = f x - g x := rfl theorem sub_comp (f : M →ₛₗ[σ₁₂] M₂) (g h : M₂ →ₛₗ[σ₂₃] N₃) : (g - h).comp f = g.comp f - h.comp f := rfl theorem comp_sub (f g : M →ₛₗ[σ₁₂] N₂) (h : N₂ →ₛₗ[σ₂₃] N₃) : h.comp (g - f) = h.comp g - h.comp f := ext fun _ ↦ h.map_sub _ _ /-- The type of linear maps is an additive group. -/ instance addCommGroup : AddCommGroup (M →ₛₗ[σ₁₂] N₂) := DFunLike.coe_injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) fun _ _ ↦ rfl /-- Evaluation of a `σ₁₂`-linear map at a fixed `a`, as an `AddMonoidHom`. -/ @[simps] def evalAddMonoidHom (a : M) : (M →ₛₗ[σ₁₂] M₂) →+ M₂ where toFun f := f a map_add' f g := LinearMap.add_apply f g a map_zero' := rfl /-- `LinearMap.toAddMonoidHom` promoted to an `AddMonoidHom`. -/ @[simps] def toAddMonoidHom' : (M →ₛₗ[σ₁₂] M₂) →+ M →+ M₂ where toFun := toAddMonoidHom map_zero' := by ext; rfl map_add' := by intros; ext; rfl /-- If `M` is the zero module, then the identity map of `M` is the zero map. -/ @[simp] theorem identityMapOfZeroModuleIsZero [Subsingleton M] : id (R := R₁) (M := M) = 0 := Subsingleton.eq_zero id end Arithmetic section Actions variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] section SMul variable [Monoid S] [DistribMulAction S M₂] [SMulCommClass R₂ S M₂] variable [Monoid S₃] [DistribMulAction S₃ M₃] [SMulCommClass R₃ S₃ M₃] instance : DistribMulAction S (M →ₛₗ[σ₁₂] M₂) where one_smul _ := ext fun _ ↦ one_smul _ _ mul_smul _ _ _ := ext fun _ ↦ mul_smul _ _ _ smul_add _ _ _ := ext fun _ ↦ smul_add _ _ _ smul_zero _ := ext fun _ ↦ smul_zero _ theorem smul_comp (a : S₃) (g : M₂ →ₛₗ[σ₂₃] M₃) (f : M →ₛₗ[σ₁₂] M₂) : (a • g).comp f = a • g.comp f := rfl -- TODO: generalize this to semilinear maps theorem comp_smul [Module R M₂] [Module R M₃] [SMulCommClass R S M₂] [DistribMulAction S M₃] [SMulCommClass R S M₃] [CompatibleSMul M₃ M₂ S R] (g : M₃ →ₗ[R] M₂) (a : S) (f : M →ₗ[R] M₃) : g.comp (a • f) = a • g.comp f := ext fun _ ↦ g.map_smul_of_tower _ _ end SMul section Module variable [Semiring S] [Module S M] [Module S M₂] [SMulCommClass R₂ S M₂] instance module : Module S (M →ₛₗ[σ₁₂] M₂) where add_smul _ _ _ := ext fun _ ↦ add_smul _ _ _ zero_smul _ := ext fun _ ↦ zero_smul _ _ end Module end Actions section RestrictScalarsAsLinearMap variable {R S M N P : Type*} [Semiring R] [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] [Module S M] [Module S N] [CompatibleSMul M N R S] variable (R S M N) in @[simp] lemma restrictScalars_zero : (0 : M →ₗ[S] N).restrictScalars R = 0 := rfl @[simp] theorem restrictScalars_add (f g : M →ₗ[S] N) : (f + g).restrictScalars R = f.restrictScalars R + g.restrictScalars R := rfl @[simp] theorem restrictScalars_neg {M N : Type*} [AddCommMonoid M] [AddCommGroup N] [Module R M] [Module R N] [Module S M] [Module S N] [CompatibleSMul M N R S] (f : M →ₗ[S] N) : (-f).restrictScalars R = -f.restrictScalars R := rfl variable {R₁ : Type*} [Semiring R₁] [Module R₁ N] [SMulCommClass S R₁ N] [SMulCommClass R R₁ N] @[simp] theorem restrictScalars_smul (c : R₁) (f : M →ₗ[S] N) : (c • f).restrictScalars R = c • f.restrictScalars R := rfl @[simp] lemma restrictScalars_comp [AddCommMonoid P] [Module S P] [Module R P] [CompatibleSMul N P R S] [CompatibleSMul M P R S] (f : N →ₗ[S] P) (g : M →ₗ[S] N) : (f ∘ₗ g).restrictScalars R = f.restrictScalars R ∘ₗ g.restrictScalars R := rfl @[simp] lemma restrictScalars_trans {T : Type*} [Semiring T] [Module T M] [Module T N] [CompatibleSMul M N S T] [CompatibleSMul M N R T] (f : M →ₗ[T] N) : (f.restrictScalars S).restrictScalars R = f.restrictScalars R := rfl variable (S M N R R₁) /-- `LinearMap.restrictScalars` as a `LinearMap`. -/ @[simps apply] def restrictScalarsₗ : (M →ₗ[S] N) →ₗ[R₁] M →ₗ[R] N where toFun := restrictScalars R map_add' := restrictScalars_add map_smul' := restrictScalars_smul end RestrictScalarsAsLinearMap end LinearMap
SkewAdjoint.lean
/- Copyright (c) 2020 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Matrix import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.Tactic.NoncommRing /-! # Lie algebras of skew-adjoint endomorphisms of a bilinear form When a module carries a bilinear form, the Lie algebra of endomorphisms of the module contains a distinguished Lie subalgebra: the skew-adjoint endomorphisms. Such subalgebras are important because they provide a simple, explicit construction of the so-called classical Lie algebras. This file defines the Lie subalgebra of skew-adjoint endomorphisms cut out by a bilinear form on a module and proves some basic related results. It also provides the corresponding definitions and results for the Lie algebra of square matrices. ## Main definitions * `skewAdjointLieSubalgebra` * `skewAdjointLieSubalgebraEquiv` * `skewAdjointMatricesLieSubalgebra` * `skewAdjointMatricesLieSubalgebraEquiv` ## Tags lie algebra, skew-adjoint, bilinear form -/ universe u v w w₁ section SkewAdjointEndomorphisms open LinearMap (BilinForm) variable {R : Type u} {M : Type v} [CommRing R] [AddCommGroup M] [Module R M] variable (B : BilinForm R M) theorem LinearMap.BilinForm.isSkewAdjoint_bracket {f g : Module.End R M} (hf : f ∈ B.skewAdjointSubmodule) (hg : g ∈ B.skewAdjointSubmodule) : ⁅f, g⁆ ∈ B.skewAdjointSubmodule := by rw [mem_skewAdjointSubmodule] at * have hfg : IsAdjointPair B B (f * g) (g * f) := by rw [← neg_mul_neg g f]; exact hg.comp hf have hgf : IsAdjointPair B B (g * f) (f * g) := by rw [← neg_mul_neg f g]; exact hf.comp hg change IsAdjointPair B B (f * g - g * f) (-(f * g - g * f)); rw [neg_sub] exact hfg.sub hgf /-- Given an `R`-module `M`, equipped with a bilinear form, the skew-adjoint endomorphisms form a Lie subalgebra of the Lie algebra of endomorphisms. -/ def skewAdjointLieSubalgebra : LieSubalgebra R (Module.End R M) := { B.skewAdjointSubmodule with lie_mem' := B.isSkewAdjoint_bracket } variable {N : Type w} [AddCommGroup N] [Module R N] (e : N ≃ₗ[R] M) /-- An equivalence of modules with bilinear forms gives equivalence of Lie algebras of skew-adjoint endomorphisms. -/ def skewAdjointLieSubalgebraEquiv : skewAdjointLieSubalgebra (B.compl₁₂ (e : N →ₗ[R] M) e) ≃ₗ⁅R⁆ skewAdjointLieSubalgebra B := by apply LieEquiv.ofSubalgebras _ _ e.lieConj ext f simp only [Submodule.mem_map_equiv, LieSubalgebra.mem_map_submodule] exact (LinearMap.isPairSelfAdjoint_equiv (B := -B) (F := B) e f).symm @[simp] theorem skewAdjointLieSubalgebraEquiv_apply (f : skewAdjointLieSubalgebra (B.compl₁₂ (Qₗ := N) (Qₗ' := N) ↑e ↑e)) : ↑(skewAdjointLieSubalgebraEquiv B e f) = e.lieConj f := by simp [skewAdjointLieSubalgebraEquiv] @[simp] theorem skewAdjointLieSubalgebraEquiv_symm_apply (f : skewAdjointLieSubalgebra B) : ↑((skewAdjointLieSubalgebraEquiv B e).symm f) = e.symm.lieConj f := by simp [skewAdjointLieSubalgebraEquiv] end SkewAdjointEndomorphisms section SkewAdjointMatrices open scoped Matrix variable {R : Type u} {n : Type w} [CommRing R] [DecidableEq n] [Fintype n] variable (J : Matrix n n R) theorem Matrix.lie_transpose (A B : Matrix n n R) : ⁅A, B⁆ᵀ = ⁅Bᵀ, Aᵀ⁆ := show (A * B - B * A)ᵀ = Bᵀ * Aᵀ - Aᵀ * Bᵀ by simp theorem Matrix.isSkewAdjoint_bracket {A B : Matrix n n R} (hA : A ∈ skewAdjointMatricesSubmodule J) (hB : B ∈ skewAdjointMatricesSubmodule J) : ⁅A, B⁆ ∈ skewAdjointMatricesSubmodule J := by simp only [mem_skewAdjointMatricesSubmodule] at * change ⁅A, B⁆ᵀ * J = J * (-⁅A, B⁆) change Aᵀ * J = J * (-A) at hA change Bᵀ * J = J * (-B) at hB rw [Matrix.lie_transpose, LieRing.of_associative_ring_bracket, LieRing.of_associative_ring_bracket, sub_mul, mul_assoc, mul_assoc, hA, hB, ← mul_assoc, ← mul_assoc, hA, hB] noncomm_ring /-- The Lie subalgebra of skew-adjoint square matrices corresponding to a square matrix `J`. -/ def skewAdjointMatricesLieSubalgebra : LieSubalgebra R (Matrix n n R) := { skewAdjointMatricesSubmodule J with lie_mem' := J.isSkewAdjoint_bracket } @[simp] theorem mem_skewAdjointMatricesLieSubalgebra (A : Matrix n n R) : A ∈ skewAdjointMatricesLieSubalgebra J ↔ A ∈ skewAdjointMatricesSubmodule J := Iff.rfl /-- An invertible matrix `P` gives a Lie algebra equivalence between those endomorphisms that are skew-adjoint with respect to a square matrix `J` and those with respect to `PᵀJP`. -/ def skewAdjointMatricesLieSubalgebraEquiv (P : Matrix n n R) (h : Invertible P) : skewAdjointMatricesLieSubalgebra J ≃ₗ⁅R⁆ skewAdjointMatricesLieSubalgebra (Pᵀ * J * P) := LieEquiv.ofSubalgebras _ _ (P.lieConj h).symm <| by ext A suffices P.lieConj h A ∈ skewAdjointMatricesSubmodule J ↔ A ∈ skewAdjointMatricesSubmodule (Pᵀ * J * P) by simp only [Submodule.mem_map_equiv, LieSubalgebra.mem_map_submodule] exact this simp [Matrix.IsSkewAdjoint, J.isAdjointPair_equiv _ _ P (isUnit_of_invertible P)] theorem skewAdjointMatricesLieSubalgebraEquiv_apply (P : Matrix n n R) (h : Invertible P) (A : skewAdjointMatricesLieSubalgebra J) : ↑(skewAdjointMatricesLieSubalgebraEquiv J P h A) = P⁻¹ * A * P := by simp [skewAdjointMatricesLieSubalgebraEquiv] /-- An equivalence of matrix algebras commuting with the transpose endomorphisms restricts to an equivalence of Lie algebras of skew-adjoint matrices. -/ def skewAdjointMatricesLieSubalgebraEquivTranspose {m : Type w} [DecidableEq m] [Fintype m] (e : Matrix n n R ≃ₐ[R] Matrix m m R) (h : ∀ A, (e A)ᵀ = e Aᵀ) : skewAdjointMatricesLieSubalgebra J ≃ₗ⁅R⁆ skewAdjointMatricesLieSubalgebra (e J) := LieEquiv.ofSubalgebras _ _ e.toLieEquiv <| by ext A suffices J.IsSkewAdjoint (e.symm A) ↔ (e J).IsSkewAdjoint A by simpa [- LieSubalgebra.mem_map, LieSubalgebra.mem_map_submodule] simp only [Matrix.IsSkewAdjoint, Matrix.IsAdjointPair, ← h, ← Function.Injective.eq_iff e.injective, map_mul, AlgEquiv.apply_symm_apply, map_neg] @[simp] theorem skewAdjointMatricesLieSubalgebraEquivTranspose_apply {m : Type w} [DecidableEq m] [Fintype m] (e : Matrix n n R ≃ₐ[R] Matrix m m R) (h : ∀ A, (e A)ᵀ = e Aᵀ) (A : skewAdjointMatricesLieSubalgebra J) : (skewAdjointMatricesLieSubalgebraEquivTranspose J e h A : Matrix m m R) = e A := rfl theorem mem_skewAdjointMatricesLieSubalgebra_unit_smul (u : Rˣ) (J A : Matrix n n R) : A ∈ skewAdjointMatricesLieSubalgebra (u • J) ↔ A ∈ skewAdjointMatricesLieSubalgebra J := by change A ∈ skewAdjointMatricesSubmodule (u • J) ↔ A ∈ skewAdjointMatricesSubmodule J simp only [mem_skewAdjointMatricesSubmodule, Matrix.IsSkewAdjoint, Matrix.IsAdjointPair] constructor <;> intro h · simpa using congr_arg (fun B => u⁻¹ • B) h · simp [h] end SkewAdjointMatrices
Cospan.lean
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Markus Himmel, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts /-! # Cospan & Span We define a category `WalkingCospan` (resp. `WalkingSpan`), which is the index category for the given data for a pullback (resp. pushout) diagram. Convenience methods `cospan f g` and `span f g` construct functors from the walking (co)span, hitting the given morphisms. ## References * [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U) * [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025) -/ noncomputable section open CategoryTheory universe w v₁ v₂ v u u₂ namespace CategoryTheory.Limits -- Porting note: `aesop cases` does not work on type synonyms like `WidePullbackShape` -- attribute [local aesop safe cases] WidePullbackShape WalkingPair /-- The type of objects for the diagram indexing a pullback, defined as a special case of `WidePullbackShape`. -/ abbrev WalkingCospan : Type := WidePullbackShape WalkingPair /-- The left point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.left : WalkingCospan := some WalkingPair.left /-- The right point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.right : WalkingCospan := some WalkingPair.right /-- The central point of the walking cospan. -/ @[match_pattern] abbrev WalkingCospan.one : WalkingCospan := none /-- The type of objects for the diagram indexing a pushout, defined as a special case of `WidePushoutShape`. -/ abbrev WalkingSpan : Type := WidePushoutShape WalkingPair /-- The left point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.left : WalkingSpan := some WalkingPair.left /-- The right point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.right : WalkingSpan := some WalkingPair.right /-- The central point of the walking span. -/ @[match_pattern] abbrev WalkingSpan.zero : WalkingSpan := none namespace WalkingCospan /-- The type of arrows for the diagram indexing a pullback. -/ abbrev Hom : WalkingCospan → WalkingCospan → Type := WidePullbackShape.Hom /-- The left arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inl : left ⟶ one := WidePullbackShape.Hom.term _ /-- The right arrow of the walking cospan. -/ @[match_pattern] abbrev Hom.inr : right ⟶ one := WidePullbackShape.Hom.term _ /-- The identity arrows of the walking cospan. -/ @[match_pattern] abbrev Hom.id (X : WalkingCospan) : X ⟶ X := WidePullbackShape.Hom.id X instance (X Y : WalkingCospan) : Subsingleton (X ⟶ Y) := by constructor; intros; simp [eq_iff_true_of_subsingleton] end WalkingCospan namespace WalkingSpan /-- The type of arrows for the diagram indexing a pushout. -/ abbrev Hom : WalkingSpan → WalkingSpan → Type := WidePushoutShape.Hom /-- The left arrow of the walking span. -/ @[match_pattern] abbrev Hom.fst : zero ⟶ left := WidePushoutShape.Hom.init _ /-- The right arrow of the walking span. -/ @[match_pattern] abbrev Hom.snd : zero ⟶ right := WidePushoutShape.Hom.init _ /-- The identity arrows of the walking span. -/ @[match_pattern] abbrev Hom.id (X : WalkingSpan) : X ⟶ X := WidePushoutShape.Hom.id X instance (X Y : WalkingSpan) : Subsingleton (X ⟶ Y) := by constructor; intros a b; simp [eq_iff_true_of_subsingleton] end WalkingSpan open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom variable {C : Type u} [Category.{v} C] /-- To construct an isomorphism of cones over the walking cospan, it suffices to construct an isomorphism of the cone points and check it commutes with the legs to `left` and `right`. -/ def WalkingCospan.ext {F : WalkingCospan ⥤ C} {s t : Cone F} (i : s.pt ≅ t.pt) (w₁ : s.π.app WalkingCospan.left = i.hom ≫ t.π.app WalkingCospan.left) (w₂ : s.π.app WalkingCospan.right = i.hom ≫ t.π.app WalkingCospan.right) : s ≅ t := by apply Cones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.π.naturality WalkingCospan.Hom.inl dsimp at h₁ simp only [Category.id_comp] at h₁ have h₂ := t.π.naturality WalkingCospan.Hom.inl dsimp at h₂ simp only [Category.id_comp] at h₂ simp_rw [h₂, ← Category.assoc, ← w₁, ← h₁] · exact w₁ · exact w₂ /-- To construct an isomorphism of cocones over the walking span, it suffices to construct an isomorphism of the cocone points and check it commutes with the legs from `left` and `right`. -/ def WalkingSpan.ext {F : WalkingSpan ⥤ C} {s t : Cocone F} (i : s.pt ≅ t.pt) (w₁ : s.ι.app WalkingCospan.left ≫ i.hom = t.ι.app WalkingCospan.left) (w₂ : s.ι.app WalkingCospan.right ≫ i.hom = t.ι.app WalkingCospan.right) : s ≅ t := by apply Cocones.ext i _ rintro (⟨⟩ | ⟨⟨⟩⟩) · have h₁ := s.ι.naturality WalkingSpan.Hom.fst dsimp at h₁ simp only [Category.comp_id] at h₁ have h₂ := t.ι.naturality WalkingSpan.Hom.fst dsimp at h₂ simp only [Category.comp_id] at h₂ simp_rw [← h₁, Category.assoc, w₁, h₂] · exact w₁ · exact w₂ /-- `cospan f g` is the functor from the walking cospan hitting `f` and `g`. -/ def cospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : WalkingCospan ⥤ C := WidePullbackShape.wideCospan Z (fun j => WalkingPair.casesOn j X Y) fun j => WalkingPair.casesOn j f g /-- `span f g` is the functor from the walking span hitting `f` and `g`. -/ def span {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : WalkingSpan ⥤ C := WidePushoutShape.wideSpan X (fun j => WalkingPair.casesOn j Y Z) fun j => WalkingPair.casesOn j f g @[simp] theorem cospan_left {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.left = X := rfl @[simp] theorem span_left {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.left = Y := rfl @[simp] theorem cospan_right {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.right = Y := rfl @[simp] theorem span_right {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.right = Z := rfl @[simp] theorem cospan_one {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.one = Z := rfl @[simp] theorem span_zero {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.zero = X := rfl @[simp] theorem cospan_map_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inl = f := rfl @[simp] theorem span_map_fst {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.fst = f := rfl @[simp] theorem cospan_map_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).map WalkingCospan.Hom.inr = g := rfl @[simp] theorem span_map_snd {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.snd = g := rfl theorem cospan_map_id {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (w : WalkingCospan) : (cospan f g).map (WalkingCospan.Hom.id w) = 𝟙 _ := rfl theorem span_map_id {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (w : WalkingSpan) : (span f g).map (WalkingSpan.Hom.id w) = 𝟙 _ := rfl /-- Every diagram indexing a pullback is naturally isomorphic (actually, equal) to a `cospan` -/ -- @[simps (rhsMd := semireducible)] Porting note: no semireducible @[simps!] def diagramIsoCospan (F : WalkingCospan ⥤ C) : F ≅ cospan (F.map inl) (F.map inr) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp) /-- Every diagram indexing a pushout is naturally isomorphic (actually, equal) to a `span` -/ -- @[simps (rhsMd := semireducible)] Porting note: no semireducible @[simps!] def diagramIsoSpan (F : WalkingSpan ⥤ C) : F ≅ span (F.map fst) (F.map snd) := NatIso.ofComponents (fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl)) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp) variable {D : Type u₂} [Category.{v₂} D] /-- A functor applied to a cospan is a cospan. -/ def cospanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : cospan f g ⋙ F ≅ cospan (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp) section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) @[simp] theorem cospanCompIso_app_left : (cospanCompIso F f g).app WalkingCospan.left = Iso.refl _ := rfl @[simp] theorem cospanCompIso_app_right : (cospanCompIso F f g).app WalkingCospan.right = Iso.refl _ := rfl @[simp] theorem cospanCompIso_app_one : (cospanCompIso F f g).app WalkingCospan.one = Iso.refl _ := rfl @[simp] theorem cospanCompIso_hom_app_left : (cospanCompIso F f g).hom.app WalkingCospan.left = 𝟙 _ := rfl @[simp] theorem cospanCompIso_hom_app_right : (cospanCompIso F f g).hom.app WalkingCospan.right = 𝟙 _ := rfl @[simp] theorem cospanCompIso_hom_app_one : (cospanCompIso F f g).hom.app WalkingCospan.one = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_left : (cospanCompIso F f g).inv.app WalkingCospan.left = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_right : (cospanCompIso F f g).inv.app WalkingCospan.right = 𝟙 _ := rfl @[simp] theorem cospanCompIso_inv_app_one : (cospanCompIso F f g).inv.app WalkingCospan.one = 𝟙 _ := rfl end /-- A functor applied to a span is a span. -/ def spanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : span f g ⋙ F ≅ span (F.map f) (F.map g) := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp) section variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) @[simp] theorem spanCompIso_app_left : (spanCompIso F f g).app WalkingSpan.left = Iso.refl _ := rfl @[simp] theorem spanCompIso_app_right : (spanCompIso F f g).app WalkingSpan.right = Iso.refl _ := rfl @[simp] theorem spanCompIso_app_zero : (spanCompIso F f g).app WalkingSpan.zero = Iso.refl _ := rfl @[simp] theorem spanCompIso_hom_app_left : (spanCompIso F f g).hom.app WalkingSpan.left = 𝟙 _ := rfl @[simp] theorem spanCompIso_hom_app_right : (spanCompIso F f g).hom.app WalkingSpan.right = 𝟙 _ := rfl @[simp] theorem spanCompIso_hom_app_zero : (spanCompIso F f g).hom.app WalkingSpan.zero = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_left : (spanCompIso F f g).inv.app WalkingSpan.left = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_right : (spanCompIso F f g).inv.app WalkingSpan.right = 𝟙 _ := rfl @[simp] theorem spanCompIso_inv_app_zero : (spanCompIso F f g).inv.app WalkingSpan.zero = 𝟙 _ := rfl end section variable {X Y Z X' Y' Z' : C} (iX : X ≅ X') (iY : Y ≅ Y') (iZ : Z ≅ Z') section variable {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'} /-- Construct an isomorphism of cospans from components. -/ def cospanExt (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) : cospan f g ≅ cospan f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iZ, iX, iY]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp [wf, wg]) variable (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem cospanExt_app_left : (cospanExt iX iY iZ wf wg).app WalkingCospan.left = iX := rfl @[simp] theorem cospanExt_app_right : (cospanExt iX iY iZ wf wg).app WalkingCospan.right = iY := rfl @[simp] theorem cospanExt_app_one : (cospanExt iX iY iZ wf wg).app WalkingCospan.one = iZ := rfl @[simp] theorem cospanExt_hom_app_left : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.left = iX.hom := rfl @[simp] theorem cospanExt_hom_app_right : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.right = iY.hom := rfl @[simp] theorem cospanExt_hom_app_one : (cospanExt iX iY iZ wf wg).hom.app WalkingCospan.one = iZ.hom := rfl @[simp] theorem cospanExt_inv_app_left : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.left = iX.inv := rfl @[simp] theorem cospanExt_inv_app_right : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.right = iY.inv := rfl @[simp] theorem cospanExt_inv_app_one : (cospanExt iX iY iZ wf wg).inv.app WalkingCospan.one = iZ.inv := by rfl end section variable {f : X ⟶ Y} {g : X ⟶ Z} {f' : X' ⟶ Y'} {g' : X' ⟶ Z'} /-- Construct an isomorphism of spans from components. -/ def spanExt (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) : span f g ≅ span f' g' := NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iX, iY, iZ]) (by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> simp [wf, wg]) variable (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) @[simp] theorem spanExt_app_left : (spanExt iX iY iZ wf wg).app WalkingSpan.left = iY := rfl @[simp] theorem spanExt_app_right : (spanExt iX iY iZ wf wg).app WalkingSpan.right = iZ := rfl @[simp] theorem spanExt_app_one : (spanExt iX iY iZ wf wg).app WalkingSpan.zero = iX := rfl @[simp] theorem spanExt_hom_app_left : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.left = iY.hom := rfl @[simp] theorem spanExt_hom_app_right : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.right = iZ.hom := rfl @[simp] theorem spanExt_hom_app_zero : (spanExt iX iY iZ wf wg).hom.app WalkingSpan.zero = iX.hom := rfl @[simp] theorem spanExt_inv_app_left : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.left = iY.inv := rfl @[simp] theorem spanExt_inv_app_right : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.right = iZ.inv := rfl @[simp] theorem spanExt_inv_app_zero : (spanExt iX iY iZ wf wg).inv.app WalkingSpan.zero = iX.inv := rfl end end end CategoryTheory.Limits
Scheme.lean
import Mathlib.AlgebraicGeometry.Restrict universe u open AlgebraicGeometry variable (X : Scheme.{u}) (x : X) in /-- info: x : ↥X -/ #guard_msgs in #check x variable (R : CommRingCat.{u}) (x : Spec R) in /-- info: x : ↥(Spec R) -/ #guard_msgs in #check x variable (X : Scheme.{u}) (U : X.Opens) (x : U.toScheme) in /-- info: x : ↥↑U -/ #guard_msgs in #check x variable (X : Scheme.{u}) (U : X.Opens) (x : U) in /-- info: x : ↥U -/ #guard_msgs in #check x
Ideal.lean
/- Copyright (c) 2022 Pierre-Alexandre Bazin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Pierre-Alexandre Bazin -/ import Mathlib.LinearAlgebra.DFinsupp import Mathlib.RingTheory.Ideal.BigOperators import Mathlib.RingTheory.Ideal.Operations /-! # An additional lemma about coprime ideals This lemma generalises `exists_sum_eq_one_iff_pairwise_coprime` to the case of non-principal ideals. It is on a separate file due to import requirements. -/ namespace Ideal variable {ι R : Type*} [CommSemiring R] /-- A finite family of ideals is pairwise coprime (that is, any two of them generate the whole ring) iff when taking all the possible intersections of all but one of these ideals, the resulting family of ideals still generate the whole ring. For example with three ideals : `I ⊔ J = I ⊔ K = J ⊔ K = ⊤ ↔ (I ⊓ J) ⊔ (I ⊓ K) ⊔ (J ⊓ K) = ⊤`. When ideals are all of the form `I i = R ∙ s i`, this is equivalent to the `exists_sum_eq_one_iff_pairwise_coprime` lemma. -/ theorem iSup_iInf_eq_top_iff_pairwise {t : Finset ι} (h : t.Nonempty) (I : ι → Ideal R) : (⨆ i ∈ t, ⨅ (j) (_ : j ∈ t) (_ : j ≠ i), I j) = ⊤ ↔ (t : Set ι).Pairwise fun i j => I i ⊔ I j = ⊤ := by haveI : DecidableEq ι := Classical.decEq ι rw [eq_top_iff_one, Submodule.mem_iSup_finset_iff_exists_sum] refine h.cons_induction ?_ ?_ <;> clear t h · simp only [Finset.sum_singleton, Finset.coe_singleton, Set.pairwise_singleton, iff_true] refine fun a => ⟨fun i => if h : i = a then ⟨1, ?_⟩ else 0, ?_⟩ · simp [h] · simp only [dif_pos, Submodule.coe_mk] intro a t hat h ih rw [Finset.coe_cons, Set.pairwise_insert_of_symmetric fun i j (h : I i ⊔ I j = ⊤) ↦ (sup_comm _ _).trans h] constructor · rintro ⟨μ, hμ⟩ rw [Finset.sum_cons] at hμ -- Porting note: `refine` yields goals in a different order than in lean3. refine ⟨ih.mp ⟨Pi.single h.choose ⟨μ a, ?a1⟩ + fun i => ⟨μ i, ?a2⟩, ?a3⟩, fun b hb ab => ?a4⟩ case a1 => have := Submodule.coe_mem (μ a) rw [mem_iInf] at this ⊢ --for some reason `simp only [mem_iInf]` times out intro i specialize this i rw [mem_iInf, mem_iInf] at this ⊢ intro hi _ apply this (Finset.subset_cons _ hi) rintro rfl exact hat hi case a2 => have := Submodule.coe_mem (μ i) simp only [mem_iInf] at this ⊢ intro j hj ij exact this _ (Finset.subset_cons _ hj) ij case a3 => rw [← @if_pos _ _ h.choose_spec R (μ a) 0, ← Finset.sum_pi_single', ← Finset.sum_add_distrib] at hμ convert hμ rename_i i _ rw [Pi.add_apply, Submodule.coe_add, Submodule.coe_mk] by_cases hi : i = h.choose · rw [hi, Pi.single_eq_same, Pi.single_eq_same, Submodule.coe_mk] · rw [Pi.single_eq_of_ne hi, Pi.single_eq_of_ne hi, Submodule.coe_zero] case a4 => rw [eq_top_iff_one, Submodule.mem_sup] rw [add_comm] at hμ refine ⟨_, ?_, _, ?_, hμ⟩ · refine sum_mem _ fun x hx => ?_ have := Submodule.coe_mem (μ x) simp only [mem_iInf] at this apply this _ (Finset.mem_cons_self _ _) rintro rfl exact hat hx · have := Submodule.coe_mem (μ a) simp only [mem_iInf] at this exact this _ (Finset.subset_cons _ hb) ab.symm · rintro ⟨hs, Hb⟩ obtain ⟨μ, hμ⟩ := ih.mpr hs have := sup_iInf_eq_top fun b hb => Hb b hb (ne_of_mem_of_not_mem hb hat).symm rw [eq_top_iff_one, Submodule.mem_sup] at this obtain ⟨u, hu, v, hv, huv⟩ := this refine ⟨fun i => if hi : i = a then ⟨v, ?_⟩ else ⟨u * μ i, ?_⟩, ?_⟩ · simp only [mem_iInf] at hv ⊢ intro j hj ij rw [Finset.mem_cons, ← hi] at hj exact hv _ (hj.resolve_left ij) · have := Submodule.coe_mem (μ i) simp only [mem_iInf] at this ⊢ intro j hj ij rcases Finset.mem_cons.mp hj with (rfl | hj) · exact mul_mem_right _ _ hu · exact mul_mem_left _ _ (this _ hj ij) · dsimp only rw [Finset.sum_cons, dif_pos rfl, add_comm] rw [← mul_one u] at huv rw [← huv, ← hμ, Finset.mul_sum] congr 1 apply Finset.sum_congr rfl intro j hj rw [dif_neg] rintro rfl exact hat hj end Ideal
FinEnum.lean
/- Copyright (c) 2019 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Data.Fintype.Basic import Mathlib.Data.Fintype.EquivFin import Mathlib.Data.List.ProdSigma import Mathlib.Data.List.Pi /-! Type class for finitely enumerable types. The property is stronger than `Fintype` in that it assigns each element a rank in a finite enumeration. -/ universe u v open Finset /-- `FinEnum α` means that `α` is finite and can be enumerated in some order, i.e. `α` has an explicit bijection with `Fin n` for some n. -/ class FinEnum (α : Sort*) where /-- `FinEnum.card` is the cardinality of the `FinEnum` -/ card : ℕ /-- `FinEnum.Equiv` states that type `α` is in bijection with `Fin card`, the size of the `FinEnum` -/ equiv : α ≃ Fin card [decEq : DecidableEq α] attribute [instance 100] FinEnum.decEq namespace FinEnum variable {α : Type u} {β : α → Type v} /-- transport a `FinEnum` instance across an equivalence -/ def ofEquiv (α) {β} [FinEnum α] (h : β ≃ α) : FinEnum β where card := card α equiv := h.trans (equiv) decEq := (h.trans (equiv)).decidableEq /-- create a `FinEnum` instance from an exhaustive list without duplicates -/ def ofNodupList [DecidableEq α] (xs : List α) (h : ∀ x : α, x ∈ xs) (h' : List.Nodup xs) : FinEnum α where card := xs.length equiv := ⟨fun x => ⟨xs.idxOf x, by rw [List.idxOf_lt_length_iff]; apply h⟩, xs.get, fun x => by simp, fun i => by ext; simp [List.idxOf_getElem h']⟩ /-- create a `FinEnum` instance from an exhaustive list; duplicates are removed -/ def ofList [DecidableEq α] (xs : List α) (h : ∀ x : α, x ∈ xs) : FinEnum α := ofNodupList xs.dedup (by simp [*]) (List.nodup_dedup _) /-- create an exhaustive list of the values of a given type -/ def toList (α) [FinEnum α] : List α := (List.finRange (card α)).map (equiv).symm open Function @[simp] theorem mem_toList [FinEnum α] (x : α) : x ∈ toList α := by simp only [toList, List.mem_map, List.mem_finRange, true_and]; exists equiv x; simp @[simp] theorem nodup_toList [FinEnum α] : List.Nodup (toList α) := by simp only [toList]; apply List.Nodup.map <;> [apply Equiv.injective; apply List.nodup_finRange] /-- create a `FinEnum` instance using a surjection -/ def ofSurjective {β} (f : β → α) [DecidableEq α] [FinEnum β] (h : Surjective f) : FinEnum α := ofList ((toList β).map f) (by intro; simpa using h _) /-- create a `FinEnum` instance using an injection -/ noncomputable def ofInjective {α β} (f : α → β) [DecidableEq α] [FinEnum β] (h : Injective f) : FinEnum α := ofList ((toList β).filterMap (partialInv f)) (by intro x simp only [mem_toList, true_and, List.mem_filterMap] use f x simp only [h, Function.partialInv_left]) instance _root_.ULift.instFinEnum [FinEnum α] : FinEnum (ULift α) := ⟨card α, Equiv.ulift.trans equiv⟩ @[simp] theorem card_ulift [FinEnum (ULift α)] [FinEnum α] : card (ULift α) = card α := Fin.equiv_iff_eq.mp ⟨equiv.symm.trans Equiv.ulift |>.trans equiv⟩ section ULift variable [FinEnum α] (a : α) (a' : ULift α) (i : Fin (card α)) @[simp] lemma equiv_up : equiv (ULift.up a) = equiv a := rfl @[simp] lemma equiv_down : equiv a'.down = equiv a' := rfl @[simp] lemma up_equiv_symm : ULift.up (equiv.symm i) = (equiv (α := ULift α)).symm i := rfl @[simp] lemma down_equiv_symm : ((equiv (α := ULift α)).symm i).down = equiv.symm i := rfl end ULift instance pempty : FinEnum PEmpty := ofList [] fun x => PEmpty.elim x instance empty : FinEnum Empty := ofList [] fun x => Empty.elim x instance punit : FinEnum PUnit := ofList [PUnit.unit] fun x => by cases x; simp instance prod {β} [FinEnum α] [FinEnum β] : FinEnum (α × β) := ofList (toList α ×ˢ toList β) fun x => by cases x; simp instance sum {β} [FinEnum α] [FinEnum β] : FinEnum (α ⊕ β) := ofList ((toList α).map Sum.inl ++ (toList β).map Sum.inr) fun x => by cases x <;> simp instance fin {n} : FinEnum (Fin n) := ofList (List.finRange _) (by simp) @[simp] theorem card_fin {n} [FinEnum (Fin n)] : card (Fin n) = n := Fin.equiv_iff_eq.mp ⟨equiv.symm⟩ instance Quotient.enum [FinEnum α] (s : Setoid α) [DecidableRel ((· ≈ ·) : α → α → Prop)] : FinEnum (Quotient s) := FinEnum.ofSurjective Quotient.mk'' fun x => Quotient.inductionOn x fun x => ⟨x, rfl⟩ /-- enumerate all finite sets of a given type -/ def Finset.enum [DecidableEq α] : List α → List (Finset α) | [] => [∅] | x :: xs => do let r ← Finset.enum xs [r, insert x r] @[simp, grind =] theorem Finset.mem_enum [DecidableEq α] (s : Finset α) (xs : List α) : s ∈ Finset.enum xs ↔ ∀ x ∈ s, x ∈ xs := by induction xs generalizing s with | nil => simp [enum, eq_empty_iff_forall_notMem] | cons x xs ih => simp only [enum, List.bind_eq_flatMap, List.mem_flatMap, List.mem_cons, List.not_mem_nil, or_false, ih] refine ⟨by aesop, fun hs => ⟨s.erase x, ?_⟩⟩ simp only [or_iff_not_imp_left] at hs simp +contextual [eq_comm (a := s), or_iff_not_imp_left, hs] instance Finset.finEnum [FinEnum α] : FinEnum (Finset α) := ofList (Finset.enum (toList α)) (by intro; simp) instance Subtype.finEnum [FinEnum α] (p : α → Prop) [DecidablePred p] : FinEnum { x // p x } := ofList ((toList α).filterMap fun x => if h : p x then some ⟨_, h⟩ else none) (by rintro ⟨x, h⟩; simpa) instance (β : α → Type v) [FinEnum α] [∀ a, FinEnum (β a)] : FinEnum (Sigma β) := ofList ((toList α).flatMap fun a => (toList (β a)).map <| Sigma.mk a) (by intro x; cases x; simp) instance PSigma.finEnum [FinEnum α] [∀ a, FinEnum (β a)] : FinEnum (Σ' a, β a) := FinEnum.ofEquiv _ (Equiv.psigmaEquivSigma _) instance PSigma.finEnumPropLeft {α : Prop} {β : α → Type v} [∀ a, FinEnum (β a)] [Decidable α] : FinEnum (Σ' a, β a) := if h : α then ofList ((toList (β h)).map <| PSigma.mk h) fun ⟨a, Ba⟩ => by simp else ofList [] fun ⟨a, _⟩ => (h a).elim instance PSigma.finEnumPropRight {β : α → Prop} [FinEnum α] [∀ a, Decidable (β a)] : FinEnum (Σ' a, β a) := FinEnum.ofEquiv { a // β a } ⟨fun ⟨x, y⟩ => ⟨x, y⟩, fun ⟨x, y⟩ => ⟨x, y⟩, fun ⟨_, _⟩ => rfl, fun ⟨_, _⟩ => rfl⟩ instance PSigma.finEnumPropProp {α : Prop} {β : α → Prop} [Decidable α] [∀ a, Decidable (β a)] : FinEnum (Σ' a, β a) := if h : ∃ a, β a then ofList [⟨h.fst, h.snd⟩] (by rintro ⟨⟩; simp) else ofList [] fun a => (h ⟨a.fst, a.snd⟩).elim instance [DecidableEq α] (xs : List α) : FinEnum { x : α // x ∈ xs } := ofList xs.attach (by simp) instance (priority := 100) [FinEnum α] : Fintype α where elems := univ.map (equiv).symm.toEmbedding complete := by intros; simp /-- The enumeration merely adds an ordering, leaving the cardinality as is. -/ theorem card_eq_fintypeCard {α : Type u} [FinEnum α] [Fintype α] : card α = Fintype.card α := Fintype.truncEquivFin α |>.inductionOn (fun h ↦ Fin.equiv_iff_eq.mp ⟨equiv.symm.trans h⟩) /-- Any two enumerations of the same type have the same length. -/ theorem card_unique {α : Type u} (e₁ e₂ : FinEnum α) : e₁.card = e₂.card := calc _ _ = _ := @card_eq_fintypeCard _ e₁ inferInstance _ = _ := Fintype.card_congr' rfl _ = _ := @card_eq_fintypeCard _ e₂ inferInstance |>.symm /-- A type indexable by `Fin 0` is empty and vice versa. -/ theorem card_eq_zero_iff {α : Type u} [FinEnum α] : card α = 0 ↔ IsEmpty α := Eq.congr_left card_eq_fintypeCard |>.trans Fintype.card_eq_zero_iff /-- Any enumeration of an empty type has length 0. -/ theorem card_eq_zero {α : Type u} [FinEnum α] [IsEmpty α] : card α = 0 := card_eq_zero_iff.mpr ‹_› /-- A type indexable by `Fin n` with positive `n` is inhabited and vice versa. -/ theorem card_pos_iff {α : Type u} [FinEnum α] : 0 < card α ↔ Nonempty α := card_eq_fintypeCard (α := α) ▸ Fintype.card_pos_iff /-- Any non-empty enumeration has more than one element. -/ lemma card_pos {α : Type*} [FinEnum α] [Nonempty α] : 0 < card α := card_pos_iff.mpr ‹_› /-- No non-empty enumeration has 0 elements. -/ lemma card_ne_zero {α : Type*} [FinEnum α] [Nonempty α] : card α ≠ 0 := card_pos.ne' /-- Any enumeration of a type with unique inhabitant has length 1. -/ theorem card_eq_one (α : Type u) [FinEnum α] [Unique α] : card α = 1 := card_eq_fintypeCard.trans <| Fintype.card_eq_one_iff_nonempty_unique.mpr ⟨‹_›⟩ instance [IsEmpty α] : Unique (FinEnum α) where default := ⟨0, Equiv.equivOfIsEmpty α (Fin 0)⟩ uniq e := by change FinEnum.mk e.1 e.2 = _ congr 1 · exact card_eq_zero · refine heq_of_cast_eq ?_ (Subsingleton.allEq _ _) exact congrArg (α ≃ Fin ·) <| card_eq_zero · funext x exact ‹IsEmpty α›.elim x /-- An empty type has a trivial enumeration. Not registered as an instance, to make sure that there aren't two definitionally differing instances around. -/ def ofIsEmpty [IsEmpty α] : FinEnum α := default instance [Unique α] : Unique (FinEnum α) where default := ⟨1, Equiv.ofUnique α (Fin 1)⟩ uniq e := by change FinEnum.mk e.1 e.2 = _ congr 1 · exact card_eq_one α · refine heq_of_cast_eq ?_ (Subsingleton.allEq _ _) exact congrArg (α ≃ Fin ·) <| card_eq_one α · subsingleton /-- A type with unique inhabitant has a trivial enumeration. Not registered as an instance, to make sure that there aren't two definitionally differing instances around. -/ def ofUnique [Unique α] : FinEnum α := default end FinEnum namespace List variable {α : Type*} [FinEnum α] {β : α → Type*} [∀ a, FinEnum (β a)] open FinEnum theorem mem_pi_toList (xs : List α) (f : ∀ a, a ∈ xs → β a) : f ∈ pi xs fun x => toList (β x) := (mem_pi _ _).mpr fun _ _ ↦ mem_toList _ /-- enumerate all functions whose domain and range are finitely enumerable -/ def Pi.enum (β : α → Type*) [∀ a, FinEnum (β a)] : List (∀ a, β a) := (pi (toList α) fun x => toList (β x)).map (fun f x => f x (mem_toList _)) theorem Pi.mem_enum (f : ∀ a, β a) : f ∈ Pi.enum β := by simpa [Pi.enum] using ⟨fun a _ => f a, mem_pi_toList _ _, rfl⟩ instance Pi.finEnum : FinEnum (∀ a, β a) := ofList (Pi.enum _) fun _ => Pi.mem_enum _ instance pfunFinEnum (p : Prop) [Decidable p] (α : p → Type) [∀ hp, FinEnum (α hp)] : FinEnum (∀ hp : p, α hp) := if hp : p then ofList ((toList (α hp)).map fun x _ => x) (by intro x; simpa using ⟨x hp, rfl⟩) else ofList [fun hp' => (hp hp').elim] (by simp [funext_iff, hp]) end List
KummerDedekind.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Paul Lezeau -/ import Mathlib.RingTheory.DedekindDomain.Ideal.Lemmas import Mathlib.RingTheory.IsAdjoinRoot /-! # Kummer-Dedekind theorem This file proves the Kummer-Dedekind theorem on the splitting of prime ideals in an extension of the ring of integers. This states the following: assume we are given - A prime ideal `I` of Dedekind domain `R` - An `R`-algebra `S` that is a Dedekind Domain - An `α : S` such that that is integral over `R` with minimal polynomial `f` If the conductor `𝓒` of `x` is such that `𝓒 ∩ R` is coprime to `I` then the prime factorisations of `I * S` and `f mod I` have the same shape, i.e. they have the same number of prime factors, and each prime factors of `I * S` can be paired with a prime factor of `f mod I` in a way that ensures multiplicities match (in fact, this pairing can be made explicit with a formula). ## Main definitions * `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` : The bijection in the Kummer-Dedekind theorem. This is the pairing between the prime factors of `I * S` and the prime factors of `f mod I`. ## Main results * `normalizedFactors_ideal_map_eq_normalizedFactors_min_poly_mk_map` : The Kummer-Dedekind theorem. * `Ideal.irreducible_map_of_irreducible_minpoly` : `I.map (algebraMap R S)` is irreducible if `(map (Ideal.Quotient.mk I) (minpoly R pb.gen))` is irreducible, where `pb` is a power basis of `S` over `R`. * `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk_symm_apply_eq_span` : Let `Q` be a lift of factor of the minimal polynomial of `x`, a generator of `S` over `R`, taken `mod I`. Then (the reduction of) `Q` corresponds via `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` to `span (I.map (algebraMap R S) ∪ {Q.aeval x})`. ## TODO * Prove the converse of `Ideal.irreducible_map_of_irreducible_minpoly`. ## References * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags kummer, dedekind, kummer dedekind, dedekind-kummer, dedekind kummer -/ variable (R : Type*) {S : Type*} [CommRing R] [CommRing S] [Algebra R S] open Ideal Polynomial DoubleQuot UniqueFactorizationMonoid Algebra RingHom local notation:max R "<" x:max ">" => adjoin R ({x} : Set S) /-- Let `S / R` be a ring extension and `x : S`, then the conductor of `R<x>` is the biggest ideal of `S` contained in `R<x>`. -/ def conductor (x : S) : Ideal S where carrier := {a | ∀ b : S, a * b ∈ R<x>} zero_mem' b := by simp only [zero_mul, zero_mem] add_mem' ha hb c := by simpa only [add_mul] using Subalgebra.add_mem _ (ha c) (hb c) smul_mem' c a ha b := by simpa only [smul_eq_mul, mul_left_comm, mul_assoc] using ha (c * b) variable {R} {x : S} theorem conductor_eq_of_eq {y : S} (h : (R<x> : Set S) = R<y>) : conductor R x = conductor R y := Ideal.ext fun _ => forall_congr' fun _ => Set.ext_iff.mp h _ theorem conductor_subset_adjoin : (conductor R x : Set S) ⊆ R<x> := fun y hy => by simpa only [mul_one] using hy 1 theorem mem_conductor_iff {y : S} : y ∈ conductor R x ↔ ∀ b : S, y * b ∈ R<x> := ⟨fun h => h, fun h => h⟩ theorem conductor_eq_top_of_adjoin_eq_top (h : R<x> = ⊤) : conductor R x = ⊤ := by simp only [Ideal.eq_top_iff_one, mem_conductor_iff, h, mem_top, forall_const] theorem conductor_eq_top_of_powerBasis (pb : PowerBasis R S) : conductor R pb.gen = ⊤ := conductor_eq_top_of_adjoin_eq_top pb.adjoin_gen_eq_top theorem adjoin_eq_top_of_conductor_eq_top {x : S} (h : conductor R x = ⊤) : Algebra.adjoin R {x} = ⊤ := Algebra.eq_top_iff.mpr fun y ↦ one_mul y ▸ (mem_conductor_iff).mp ((Ideal.eq_top_iff_one (conductor R x)).mp h) y theorem conductor_eq_top_iff_adjoin_eq_top {x : S} : conductor R x = ⊤ ↔ Algebra.adjoin R {x} = ⊤ := ⟨fun h ↦ adjoin_eq_top_of_conductor_eq_top h, fun h ↦ conductor_eq_top_of_adjoin_eq_top h⟩ open IsLocalization in lemma mem_coeSubmodule_conductor {L} [CommRing L] [Algebra S L] [Algebra R L] [IsScalarTower R S L] [NoZeroSMulDivisors S L] {x : S} {y : L} : y ∈ coeSubmodule L (conductor R x) ↔ ∀ z : S, y * (algebraMap S L) z ∈ Algebra.adjoin R {algebraMap S L x} := by cases subsingleton_or_nontrivial L · rw [Subsingleton.elim (coeSubmodule L _) ⊤, Subsingleton.elim (Algebra.adjoin R _) ⊤]; simp trans ∀ z, y * (algebraMap S L) z ∈ (Algebra.adjoin R {x}).map (IsScalarTower.toAlgHom R S L) · simp only [coeSubmodule, Submodule.mem_map, Algebra.linearMap_apply, Subalgebra.mem_map, IsScalarTower.coe_toAlgHom'] constructor · rintro ⟨y, hy, rfl⟩ z exact ⟨_, hy z, map_mul _ _ _⟩ · intro H obtain ⟨y, _, e⟩ := H 1 rw [map_one, mul_one] at e subst e simp only [← map_mul, (FaithfulSMul.algebraMap_injective S L).eq_iff, exists_eq_right] at H exact ⟨_, H, rfl⟩ · rw [AlgHom.map_adjoin, Set.image_singleton]; rfl variable {I : Ideal R} /-- This technical lemma tell us that if `C` is the conductor of `R<x>` and `I` is an ideal of `R` then `p * (I * S) ⊆ I * R<x>` for any `p` in `C ∩ R` -/ theorem prod_mem_ideal_map_of_mem_conductor {p : R} {z : S} (hp : p ∈ Ideal.comap (algebraMap R S) (conductor R x)) (hz' : z ∈ I.map (algebraMap R S)) : algebraMap R S p * z ∈ algebraMap R<x> S '' ↑(I.map (algebraMap R R<x>)) := by rw [Ideal.map, Ideal.span, Finsupp.mem_span_image_iff_linearCombination] at hz' obtain ⟨l, H, H'⟩ := hz' rw [Finsupp.linearCombination_apply] at H' rw [← H', mul_comm, Finsupp.sum_mul] have lem : ∀ {a : R}, a ∈ I → l a • algebraMap R S a * algebraMap R S p ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>) := by intro a ha rw [Algebra.id.smul_eq_mul, mul_assoc, mul_comm, mul_assoc, Set.mem_image] refine Exists.intro (algebraMap R R<x> a * ⟨l a * algebraMap R S p, show l a * algebraMap R S p ∈ R<x> from ?h⟩) ?_ case h => rw [mul_comm] exact mem_conductor_iff.mp (Ideal.mem_comap.mp hp) _ · refine ⟨?_, ?_⟩ · rw [mul_comm] apply Ideal.mul_mem_left (I.map (algebraMap R R<x>)) _ (Ideal.mem_map_of_mem _ ha) · simp only [RingHom.map_mul, mul_comm (algebraMap R S p) (l a)] rfl refine Finset.sum_induction _ (fun u => u ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>)) (fun a b => ?_) ?_ ?_ · rintro ⟨z, hz, rfl⟩ ⟨y, hy, rfl⟩ rw [← RingHom.map_add] exact ⟨z + y, Ideal.add_mem _ (SetLike.mem_coe.mp hz) hy, rfl⟩ · exact ⟨0, SetLike.mem_coe.mpr <| Ideal.zero_mem _, RingHom.map_zero _⟩ · intro y hy exact lem ((Finsupp.mem_supported _ l).mp H hy) /-- A technical result telling us that `(I * S) ∩ R<x> = I * R<x>` for any ideal `I` of `R`. -/ theorem comap_map_eq_map_adjoin_of_coprime_conductor (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) : (I.map (algebraMap R S)).comap (algebraMap R<x> S) = I.map (algebraMap R R<x>) := by apply le_antisymm · -- This is adapted from [Neukirch1992]. Let `C = (conductor R x)`. The idea of the proof -- is that since `I` and `C ∩ R` are coprime, we have -- `(I * S) ∩ R<x> ⊆ (I + C) * ((I * S) ∩ R<x>) ⊆ I * R<x> + I * C * S ⊆ I * R<x>`. intro y hy obtain ⟨z, hz⟩ := y obtain ⟨p, hp, q, hq, hpq⟩ := Submodule.mem_sup.mp ((Ideal.eq_top_iff_one _).mp hx) have temp : algebraMap R S p * z + algebraMap R S q * z = z := by simp only [← add_mul, ← RingHom.map_add (algebraMap R S), hpq, map_one, one_mul] suffices z ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>) ↔ (⟨z, hz⟩ : R<x>) ∈ I.map (algebraMap R R<x>) by rw [← this, ← temp] obtain ⟨a, ha⟩ := (Set.mem_image _ _ _).mp (prod_mem_ideal_map_of_mem_conductor hp (show z ∈ I.map (algebraMap R S) by rwa [Ideal.mem_comap] at hy)) use a + algebraMap R R<x> q * ⟨z, hz⟩ refine ⟨Ideal.add_mem (I.map (algebraMap R R<x>)) ha.left ?_, by simp only [ha.right, map_add, map_mul, add_right_inj]; rfl⟩ rw [mul_comm] exact Ideal.mul_mem_left (I.map (algebraMap R R<x>)) _ (Ideal.mem_map_of_mem _ hq) refine ⟨fun h => ?_, fun h => (Set.mem_image _ _ _).mpr (Exists.intro ⟨z, hz⟩ ⟨by simp [h], rfl⟩)⟩ obtain ⟨x₁, hx₁, hx₂⟩ := (Set.mem_image _ _ _).mp h have : x₁ = ⟨z, hz⟩ := by apply h_alg simp only [hx₂, algebraMap_eq_smul_one] rw [Submonoid.mk_smul, smul_eq_mul, mul_one] rwa [← this] · -- The converse inclusion is trivial have : algebraMap R S = (algebraMap _ S).comp (algebraMap R R<x>) := by ext; rfl rw [this, ← Ideal.map_map] apply Ideal.le_comap_map /-- The canonical morphism of rings from `R<x> ⧸ (I*R<x>)` to `S ⧸ (I*S)` is an isomorphism when `I` and `(conductor R x) ∩ R` are coprime. -/ noncomputable def quotAdjoinEquivQuotMap (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) : R<x> ⧸ I.map (algebraMap R R<x>) ≃+* S ⧸ I.map (algebraMap R S) := by let f : R<x> ⧸ I.map (algebraMap R R<x>) →+* S ⧸ I.map (algebraMap R S) := (Ideal.Quotient.lift (I.map (algebraMap R R<x>)) ((Ideal.Quotient.mk (I.map (algebraMap R S))).comp (algebraMap R<x> S)) (fun r hr => by have : algebraMap R S = (algebraMap R<x> S).comp (algebraMap R R<x>) := by ext; rfl rw [RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem, this, ← Ideal.map_map] exact Ideal.mem_map_of_mem _ hr)) refine RingEquiv.ofBijective f ⟨?_, ?_⟩ · --the kernel of the map is clearly `(I * S) ∩ R<x>`. To get injectivity, we need to show that --this is contained in `I * R<x>`, which is the content of the previous lemma. refine RingHom.lift_injective_of_ker_le_ideal _ _ fun u hu => ?_ rwa [RingHom.mem_ker, RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem, ← Ideal.mem_comap, comap_map_eq_map_adjoin_of_coprime_conductor hx h_alg] at hu · -- Surjectivity follows from the surjectivity of the canonical map `R<x> → S ⧸ (I * S)`, -- which in turn follows from the fact that `I * S + (conductor R x) = S`. refine Ideal.Quotient.lift_surjective_of_surjective _ _ fun y => ?_ obtain ⟨z, hz⟩ := Ideal.Quotient.mk_surjective y have : z ∈ conductor R x ⊔ I.map (algebraMap R S) := by suffices conductor R x ⊔ I.map (algebraMap R S) = ⊤ by simp only [this, Submodule.mem_top] rw [Ideal.eq_top_iff_one] at hx ⊢ replace hx := Ideal.mem_map_of_mem (algebraMap R S) hx rw [Ideal.map_sup, RingHom.map_one] at hx exact (sup_le_sup (show ((conductor R x).comap (algebraMap R S)).map (algebraMap R S) ≤ conductor R x from Ideal.map_comap_le) (le_refl (I.map (algebraMap R S)))) hx rw [← Ideal.mem_quotient_iff_mem_sup, hz, Ideal.mem_map_iff_of_surjective] at this · obtain ⟨u, hu, hu'⟩ := this use ⟨u, conductor_subset_adjoin hu⟩ simp only [← hu'] rfl · exact Ideal.Quotient.mk_surjective @[simp] theorem quotAdjoinEquivQuotMap_apply_mk (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) (a : R<x>) : quotAdjoinEquivQuotMap hx h_alg (Ideal.Quotient.mk (I.map (algebraMap R R<x>)) a) = Ideal.Quotient.mk (I.map (algebraMap R S)) ↑a := rfl namespace KummerDedekind open scoped Polynomial variable [IsDomain R] [IsIntegrallyClosed R] variable [IsDedekindDomain S] variable [NoZeroSMulDivisors R S] attribute [local instance] Ideal.Quotient.field /-- The isomorphism of rings between `S / I` and `(R / I)[X] / minpoly x` when `I` and `(conductor R x) ∩ R` are coprime. -/ noncomputable def quotMapEquivQuotQuotMap (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : S ⧸ I.map (algebraMap R S) ≃+* (R ⧸ I)[X] ⧸ span {(minpoly R x).map (Ideal.Quotient.mk I)} := (quotAdjoinEquivQuotMap hx (FaithfulSMul.algebraMap_injective (Algebra.adjoin R {x}) S)).symm.trans <| ((Algebra.adjoin.powerBasis' hx').quotientEquivQuotientMinpolyMap I).toRingEquiv.trans <| quotEquivOfEq (by rw [Algebra.adjoin.powerBasis'_minpoly_gen hx']) lemma quotMapEquivQuotQuotMap_symm_apply (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) (Q : R[X]) : (quotMapEquivQuotQuotMap hx hx').symm (Q.map (Ideal.Quotient.mk I)) = Q.aeval x := by apply (quotMapEquivQuotQuotMap hx hx').injective rw [quotMapEquivQuotQuotMap, AlgEquiv.toRingEquiv_eq_coe, RingEquiv.symm_trans_apply, RingEquiv.symm_symm, RingEquiv.coe_trans, Function.comp_apply, RingEquiv.symm_apply_apply, RingEquiv.symm_trans_apply, quotEquivOfEq_symm, quotEquivOfEq_mk] congr convert (adjoin.powerBasis' hx').quotientEquivQuotientMinpolyMap_symm_apply_mk I Q apply (quotAdjoinEquivQuotMap hx (FaithfulSMul.algebraMap_injective ((adjoin R {x})) S)).injective simp only [RingEquiv.apply_symm_apply, adjoin.powerBasis'_gen, quotAdjoinEquivQuotMap_apply_mk, coe_aeval_mk_apply] open Classical in /-- The first half of the **Kummer-Dedekind Theorem**, stating that the prime factors of `I*S` are in bijection with those of the minimal polynomial of the generator of `S` over `R`, taken `mod I`. -/ noncomputable def normalizedFactorsMapEquivNormalizedFactorsMinPolyMk (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : {J : Ideal S | J ∈ normalizedFactors (I.map (algebraMap R S))} ≃ {d : (R ⧸ I)[X] | d ∈ normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))} := by refine (normalizedFactorsEquivOfQuotEquiv (quotMapEquivQuotQuotMap hx hx') ?_ ?_).trans ?_ · rwa [Ne, map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective R S), ← Ne] · by_contra h exact (show Polynomial.map (Ideal.Quotient.mk I) (minpoly R x) ≠ 0 from Polynomial.map_monic_ne_zero (minpoly.monic hx')) (span_singleton_eq_bot.mp h) · refine (normalizedFactorsEquivSpanNormalizedFactors ?_).symm exact Polynomial.map_monic_ne_zero (minpoly.monic hx') open Classical in /-- The second half of the **Kummer-Dedekind Theorem**, stating that the bijection `FactorsEquiv'` defined in the first half preserves multiplicities. -/ theorem emultiplicity_factors_map_eq_emultiplicity (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) {J : Ideal S} (hJ : J ∈ normalizedFactors (I.map (algebraMap R S))) : emultiplicity J (I.map (algebraMap R S)) = emultiplicity (↑(normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' ⟨J, hJ⟩)) (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)) := by rw [normalizedFactorsMapEquivNormalizedFactorsMinPolyMk, Equiv.coe_trans, Function.comp_apply, emultiplicity_normalizedFactorsEquivSpanNormalizedFactors_symm_eq_emultiplicity, normalizedFactorsEquivOfQuotEquiv_emultiplicity_eq_emultiplicity] open Classical in /-- The **Kummer-Dedekind Theorem**. -/ theorem normalizedFactors_ideal_map_eq_normalizedFactors_min_poly_mk_map (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : normalizedFactors (I.map (algebraMap R S)) = Multiset.map (fun f => ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm f : Ideal S)) (normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))).attach := by ext J -- WLOG, assume J is a normalized factor by_cases hJ : J ∈ normalizedFactors (I.map (algebraMap R S)) swap · rw [Multiset.count_eq_zero.mpr hJ, eq_comm, Multiset.count_eq_zero, Multiset.mem_map] simp only [not_exists] rintro J' ⟨_, rfl⟩ exact hJ ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm J').prop -- Then we just have to compare the multiplicities, which we already proved are equal. have := emultiplicity_factors_map_eq_emultiplicity hI hI' hx hx' hJ rw [emultiplicity_eq_count_normalizedFactors, emultiplicity_eq_count_normalizedFactors, UniqueFactorizationMonoid.normalize_normalized_factor _ hJ, UniqueFactorizationMonoid.normalize_normalized_factor, Nat.cast_inj] at this · refine this.trans ?_ -- Get rid of the `map` by applying the equiv to both sides. generalize hJ' : (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx') ⟨J, hJ⟩ = J' have : ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm J' : Ideal S) = J := by rw [← hJ', Equiv.symm_apply_apply _ _, Subtype.coe_mk] subst this -- Get rid of the `attach` by applying the subtype `coe` to both sides. rw [Multiset.count_map_eq_count' fun f => ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm f : Ideal S), Multiset.count_attach] · exact Subtype.coe_injective.comp (Equiv.injective _) · exact (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' _).prop · exact irreducible_of_normalized_factor _ (normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' _).prop · exact Polynomial.map_monic_ne_zero (minpoly.monic hx') · exact irreducible_of_normalized_factor _ hJ · rwa [← bot_eq_zero, Ne, map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective R S)] theorem Ideal.irreducible_map_of_irreducible_minpoly (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) (hf : Irreducible (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))) : Irreducible (I.map (algebraMap R S)) := by classical have mem_norm_factors : normalize (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)) ∈ normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)) := by simp [normalizedFactors_irreducible hf] suffices ∃ y, normalizedFactors (I.map (algebraMap R S)) = {y} by obtain ⟨y, hy⟩ := this have h := prod_normalizedFactors (show I.map (algebraMap R S) ≠ 0 by rwa [← bot_eq_zero, Ne, map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective R S)]) rw [associated_iff_eq, hy, Multiset.prod_singleton] at h rw [← h] exact irreducible_of_normalized_factor y (show y ∈ normalizedFactors (I.map (algebraMap R S)) by simp [hy]) rw [normalizedFactors_ideal_map_eq_normalizedFactors_min_poly_mk_map hI hI' hx hx'] use ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm ⟨normalize (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)), mem_norm_factors⟩ : Ideal S) rw [Multiset.map_eq_singleton] use ⟨normalize (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)), mem_norm_factors⟩ refine ⟨?_, rfl⟩ apply Multiset.map_injective Subtype.coe_injective rw [Multiset.attach_map_val, Multiset.map_singleton, Subtype.coe_mk] exact normalizedFactors_irreducible hf open Set Classical in /-- Let `Q` be a lift of factor of the minimal polynomial of `x`, a generator of `S` over `R`, taken `mod I`. Then (the reduction of) `Q` corresponds via `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` to `span (I.map (algebraMap R S) ∪ {Q.aeval x})`. -/ theorem normalizedFactorsMapEquivNormalizedFactorsMinPolyMk_symm_apply_eq_span (hI : I.IsMaximal) {Q : R[X]} (hQ : Q.map (Ideal.Quotient.mk I) ∈ normalizedFactors ((minpoly R x).map (Ideal.Quotient.mk I))) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : ((normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx').symm ⟨_, hQ⟩).val = span (I.map (algebraMap R S) ∪ {Q.aeval x}) := by dsimp [normalizedFactorsMapEquivNormalizedFactorsMinPolyMk, normalizedFactorsEquivSpanNormalizedFactors] rw [normalizedFactorsEquivOfQuotEquiv_symm] dsimp [normalizedFactorsEquivOfQuotEquiv, idealFactorsEquivOfQuotEquiv, OrderIso.ofHomInv] simp only [map_span, image_singleton, coe_coe, quotMapEquivQuotQuotMap_symm_apply hx hx' Q] refine le_antisymm (fun a ha ↦ ?_) (span_le.mpr <| union_subset_iff.mpr <| ⟨le_comap_of_map_le (by simp), by simp [mem_span_singleton]⟩) rw [mem_comap, Ideal.mem_span_singleton] at ha obtain ⟨a', ha'⟩ := ha obtain ⟨b, hb⟩ := Ideal.Quotient.mk_surjective a' rw [← hb, ← map_mul, Quotient.mk_eq_mk_iff_sub_mem] at ha' rw [union_comm, span_union, span_eq, mem_span_singleton_sup] exact ⟨b, a - Q.aeval x * b, ha', by ring⟩ end KummerDedekind
Preprocessing.lean
/- Copyright (c) 2025 Vasilii Nesterov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vasilii Nesterov -/ import Mathlib.Tactic.Order.CollectFacts /-! # Facts preprocessing for the `order` tactic In this file we implement the preprocessing procedure for the `order` tactic. See `Mathlib/Tactic/Order.lean` for details of preprocessing. -/ namespace Mathlib.Tactic.Order universe u open Lean Expr Meta section Lemmas lemma not_lt_of_not_le {α : Type u} [Preorder α] {x y : α} (h : ¬(x ≤ y)) : ¬(x < y) := (h ·.le) lemma le_of_not_lt_le {α : Type u} [Preorder α] {x y : α} (h1 : ¬(x < y)) (h2 : x ≤ y) : y ≤ x := not_lt_iff_le_imp_ge.mp h1 h2 end Lemmas /-- Preprocesses facts for preorders. Replaces `x < y` with two equivalent facts: `x ≤ y` and `¬ (y ≤ x)`. Replaces `x = y` with `x ≤ y`, `y ≤ x` and removes `x ≠ y`. -/ def preprocessFactsPreorder (facts : Array AtomicFact) : MetaM <| Array AtomicFact := do let mut res : Array AtomicFact := #[] for fact in facts do match fact with | .lt lhs rhs proof => res := res.push <| .le lhs rhs (← mkAppM ``le_of_lt #[proof]) res := res.push <| .nle rhs lhs (← mkAppM ``not_le_of_gt #[proof]) | .eq lhs rhs proof => res := res.push <| .le lhs rhs (← mkAppM ``le_of_eq #[proof]) res := res.push <| .le rhs lhs (← mkAppM ``ge_of_eq #[proof]) | .ne _ _ _ => continue | _ => res := res.push fact return res /-- Preprocesses facts for partial orders. Replaces `x < y`, `¬ (x ≤ y)`, and `x = y` with equivalent facts involving only `≤`, `≠`, and `≮`. For each fact `x = y ⊔ z` adds `y ≤ x` and `z ≤ x` facts, and similarly for `⊓`. -/ def preprocessFactsPartial (facts : Array AtomicFact) (idxToAtom : Std.HashMap Nat Expr) : MetaM <| Array AtomicFact := do let mut res : Array AtomicFact := #[] for fact in facts do match fact with | .lt lhs rhs proof => res := res.push <| .ne lhs rhs (← mkAppM ``ne_of_lt #[proof]) res := res.push <| .le lhs rhs (← mkAppM ``le_of_lt #[proof]) | .nle lhs rhs proof => res := res.push <| .ne lhs rhs (← mkAppM ``ne_of_not_le #[proof]) res := res.push <| .nlt lhs rhs (← mkAppM ``not_lt_of_not_le #[proof]) | .eq lhs rhs proof => res := res.push <| .le lhs rhs (← mkAppM ``le_of_eq #[proof]) res := res.push <| .le rhs lhs (← mkAppM ``ge_of_eq #[proof]) | .isSup lhs rhs sup => res := res.push <| .le lhs sup (← mkAppOptM ``le_sup_left #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push <| .le rhs sup (← mkAppOptM ``le_sup_right #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push fact | .isInf lhs rhs inf => res := res.push <| .le inf lhs (← mkAppOptM ``inf_le_left #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push <| .le inf rhs (← mkAppOptM ``inf_le_right #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push fact | _ => res := res.push fact return res /-- Preprocesses facts for linear orders. Replaces `x < y`, `¬ (x ≤ y)`, `¬ (x < y)`, and `x = y` with equivalent facts involving only `≤` and `≠`. For each fact `x = y ⊔ z` adds `y ≤ x` and `z ≤ x` facts, and similarly for `⊓`. -/ def preprocessFactsLinear (facts : Array AtomicFact) (idxToAtom : Std.HashMap Nat Expr) : MetaM <| Array AtomicFact := do let mut res : Array AtomicFact := #[] for fact in facts do match fact with | .lt lhs rhs proof => res := res.push <| .ne lhs rhs (← mkAppM ``ne_of_lt #[proof]) res := res.push <| .le lhs rhs (← mkAppM ``le_of_lt #[proof]) | .nle lhs rhs proof => res := res.push <| .ne lhs rhs (← mkAppM ``ne_of_not_le #[proof]) res := res.push <| .le rhs lhs (← mkAppM ``le_of_not_ge #[proof]) | .nlt lhs rhs proof => res := res.push <| .le rhs lhs (← mkAppM ``le_of_not_gt #[proof]) | .eq lhs rhs proof => res := res.push <| .le lhs rhs (← mkAppM ``le_of_eq #[proof]) res := res.push <| .le rhs lhs (← mkAppM ``ge_of_eq #[proof]) | .isSup lhs rhs sup => res := res.push <| .le lhs sup (← mkAppOptM ``le_sup_left #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push <| .le rhs sup (← mkAppOptM ``le_sup_right #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push fact | .isInf lhs rhs inf => res := res.push <| .le inf lhs (← mkAppOptM ``inf_le_left #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push <| .le inf rhs (← mkAppOptM ``inf_le_right #[none, none, idxToAtom.get! lhs, idxToAtom.get! rhs]) res := res.push fact | _ => res := res.push fact return res end Mathlib.Tactic.Order
Basic.lean
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Heather Macbeth, Sébastien Gouëzel -/ import Mathlib.LinearAlgebra.Alternating.Basic import Mathlib.LinearAlgebra.BilinearMap import Mathlib.Topology.Algebra.Module.Equiv import Mathlib.Topology.Algebra.Module.Multilinear.Basic /-! # Continuous alternating multilinear maps In this file we define bundled continuous alternating maps and develop basic API about these maps, by reusing API about continuous multilinear maps and alternating maps. ## Notation `M [⋀^ι]→L[R] N`: notation for `R`-linear continuous alternating maps from `M` to `N`; the arguments are indexed by `i : ι`. ## Keywords multilinear map, alternating map, continuous -/ open Function Matrix /-- A continuous alternating map from `ι → M` to `N`, denoted `M [⋀^ι]→L[R] N`, is a continuous map that is - multilinear : `f (update m i (c • x)) = c • f (update m i x)` and `f (update m i (x + y)) = f (update m i x) + f (update m i y)`; - alternating : `f v = 0` whenever `v` has two equal coordinates. -/ structure ContinuousAlternatingMap (R M N ι : Type*) [Semiring R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [AddCommMonoid N] [Module R N] [TopologicalSpace N] extends ContinuousMultilinearMap R (fun _ : ι => M) N, M [⋀^ι]→ₗ[R] N where /-- Projection to `ContinuousMultilinearMap`s. -/ add_decl_doc ContinuousAlternatingMap.toContinuousMultilinearMap /-- Projection to `AlternatingMap`s. -/ add_decl_doc ContinuousAlternatingMap.toAlternatingMap @[inherit_doc] notation M " [⋀^" ι "]→L[" R "] " N:100 => ContinuousAlternatingMap R M N ι namespace ContinuousAlternatingMap section Semiring variable {R M M' N N' ι : Type*} [Semiring R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [AddCommMonoid M'] [Module R M'] [TopologicalSpace M'] [AddCommMonoid N] [Module R N] [TopologicalSpace N] [AddCommMonoid N'] [Module R N'] [TopologicalSpace N'] {n : ℕ} (f g : M [⋀^ι]→L[R] N) theorem toContinuousMultilinearMap_injective : Injective (ContinuousAlternatingMap.toContinuousMultilinearMap : M [⋀^ι]→L[R] N → ContinuousMultilinearMap R (fun _ : ι => M) N) | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl theorem range_toContinuousMultilinearMap : Set.range (toContinuousMultilinearMap : M [⋀^ι]→L[R] N → ContinuousMultilinearMap R (fun _ : ι => M) N) = {f | ∀ (v : ι → M) (i j : ι), v i = v j → i ≠ j → f v = 0} := Set.ext fun f => ⟨fun ⟨g, hg⟩ => hg ▸ g.2, fun h => ⟨⟨f, h⟩, rfl⟩⟩ instance funLike : FunLike (M [⋀^ι]→L[R] N) (ι → M) N where coe f := f.toFun coe_injective' _ _ h := toContinuousMultilinearMap_injective <| DFunLike.ext' h instance continuousMapClass : ContinuousMapClass (M [⋀^ι]→L[R] N) (ι → M) N where map_continuous f := f.cont initialize_simps_projections ContinuousAlternatingMap (toFun → apply) @[continuity] theorem coe_continuous : Continuous f := f.cont @[simp] theorem coe_toContinuousMultilinearMap : ⇑f.toContinuousMultilinearMap = f := rfl @[simp] theorem coe_mk (f : ContinuousMultilinearMap R (fun _ : ι => M) N) (h) : ⇑(mk f h) = f := rfl -- not a `simp` lemma because this projection is a reducible call to `mk`, so `simp` can prove -- this lemma theorem coe_toAlternatingMap : ⇑f.toAlternatingMap = f := rfl @[ext] theorem ext {f g : M [⋀^ι]→L[R] N} (H : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ H theorem toAlternatingMap_injective : Injective (toAlternatingMap : (M [⋀^ι]→L[R] N) → (M [⋀^ι]→ₗ[R] N)) := fun f g h => DFunLike.ext' <| by convert DFunLike.ext'_iff.1 h @[simp] theorem range_toAlternatingMap : Set.range (toAlternatingMap : M [⋀^ι]→L[R] N → (M [⋀^ι]→ₗ[R] N)) = {f : M [⋀^ι]→ₗ[R] N | Continuous f} := Set.ext fun f => ⟨fun ⟨g, hg⟩ => hg ▸ g.cont, fun h => ⟨{ f with cont := h }, DFunLike.ext' rfl⟩⟩ @[simp] theorem map_update_add [DecidableEq ι] (m : ι → M) (i : ι) (x y : M) : f (update m i (x + y)) = f (update m i x) + f (update m i y) := f.map_update_add' m i x y @[simp] theorem map_update_smul [DecidableEq ι] (m : ι → M) (i : ι) (c : R) (x : M) : f (update m i (c • x)) = c • f (update m i x) := f.map_update_smul' m i c x theorem map_coord_zero {m : ι → M} (i : ι) (h : m i = 0) : f m = 0 := f.toMultilinearMap.map_coord_zero i h @[simp] theorem map_update_zero [DecidableEq ι] (m : ι → M) (i : ι) : f (update m i 0) = 0 := f.toMultilinearMap.map_update_zero m i @[simp] theorem map_zero [Nonempty ι] : f 0 = 0 := f.toMultilinearMap.map_zero theorem map_eq_zero_of_eq (v : ι → M) {i j : ι} (h : v i = v j) (hij : i ≠ j) : f v = 0 := f.map_eq_zero_of_eq' v i j h hij theorem map_eq_zero_of_not_injective (v : ι → M) (hv : ¬Function.Injective v) : f v = 0 := f.toAlternatingMap.map_eq_zero_of_not_injective v hv /-- Restrict the codomain of a continuous alternating map to a submodule. -/ @[simps!] def codRestrict (f : M [⋀^ι]→L[R] N) (p : Submodule R N) (h : ∀ v, f v ∈ p) : M [⋀^ι]→L[R] p := { f.toAlternatingMap.codRestrict p h with toContinuousMultilinearMap := f.1.codRestrict p h } instance : Zero (M [⋀^ι]→L[R] N) := ⟨⟨0, (0 : M [⋀^ι]→ₗ[R] N).map_eq_zero_of_eq⟩⟩ instance : Inhabited (M [⋀^ι]→L[R] N) := ⟨0⟩ @[simp] theorem coe_zero : ⇑(0 : M [⋀^ι]→L[R] N) = 0 := rfl @[simp] theorem toContinuousMultilinearMap_zero : (0 : M [⋀^ι]→L[R] N).toContinuousMultilinearMap = 0 := rfl @[simp] theorem toAlternatingMap_zero : (0 : M [⋀^ι]→L[R] N).toAlternatingMap = 0 := rfl section SMul variable {R' R'' A : Type*} [Monoid R'] [Monoid R''] [Semiring A] [Module A M] [Module A N] [DistribMulAction R' N] [ContinuousConstSMul R' N] [SMulCommClass A R' N] [DistribMulAction R'' N] [ContinuousConstSMul R'' N] [SMulCommClass A R'' N] instance : SMul R' (M [⋀^ι]→L[A] N) := ⟨fun c f => ⟨c • f.1, (c • f.toAlternatingMap).map_eq_zero_of_eq⟩⟩ @[simp] theorem coe_smul (f : M [⋀^ι]→L[A] N) (c : R') : ⇑(c • f) = c • ⇑f := rfl theorem smul_apply (f : M [⋀^ι]→L[A] N) (c : R') (v : ι → M) : (c • f) v = c • f v := rfl @[simp] theorem toContinuousMultilinearMap_smul (c : R') (f : M [⋀^ι]→L[A] N) : (c • f).toContinuousMultilinearMap = c • f.toContinuousMultilinearMap := rfl @[simp] theorem toAlternatingMap_smul (c : R') (f : M [⋀^ι]→L[A] N) : (c • f).toAlternatingMap = c • f.toAlternatingMap := rfl instance [SMulCommClass R' R'' N] : SMulCommClass R' R'' (M [⋀^ι]→L[A] N) := ⟨fun _ _ _ => ext fun _ => smul_comm _ _ _⟩ instance [SMul R' R''] [IsScalarTower R' R'' N] : IsScalarTower R' R'' (M [⋀^ι]→L[A] N) := ⟨fun _ _ _ => ext fun _ => smul_assoc _ _ _⟩ instance [DistribMulAction R'ᵐᵒᵖ N] [IsCentralScalar R' N] : IsCentralScalar R' (M [⋀^ι]→L[A] N) := ⟨fun _ _ => ext fun _ => op_smul_eq_smul _ _⟩ instance : MulAction R' (M [⋀^ι]→L[A] N) := toContinuousMultilinearMap_injective.mulAction toContinuousMultilinearMap fun _ _ => rfl end SMul section ContinuousAdd variable [ContinuousAdd N] instance : Add (M [⋀^ι]→L[R] N) := ⟨fun f g => ⟨f.1 + g.1, (f.toAlternatingMap + g.toAlternatingMap).map_eq_zero_of_eq⟩⟩ @[simp] theorem coe_add : ⇑(f + g) = ⇑f + ⇑g := rfl @[simp] theorem add_apply (v : ι → M) : (f + g) v = f v + g v := rfl @[simp] theorem toContinuousMultilinearMap_add (f g : M [⋀^ι]→L[R] N) : (f + g).1 = f.1 + g.1 := rfl @[simp] theorem toAlternatingMap_add (f g : M [⋀^ι]→L[R] N) : (f + g).toAlternatingMap = f.toAlternatingMap + g.toAlternatingMap := rfl instance addCommMonoid : AddCommMonoid (M [⋀^ι]→L[R] N) := toContinuousMultilinearMap_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl /-- Evaluation of a `ContinuousAlternatingMap` at a vector as an `AddMonoidHom`. -/ def applyAddHom (v : ι → M) : M [⋀^ι]→L[R] N →+ N := ⟨⟨fun f => f v, rfl⟩, fun _ _ => rfl⟩ @[simp] theorem sum_apply {α : Type*} (f : α → M [⋀^ι]→L[R] N) (m : ι → M) {s : Finset α} : (∑ a ∈ s, f a) m = ∑ a ∈ s, f a m := map_sum (applyAddHom m) f s /-- Projection to `ContinuousMultilinearMap`s as a bundled `AddMonoidHom`. -/ @[simps] def toMultilinearAddHom : M [⋀^ι]→L[R] N →+ ContinuousMultilinearMap R (fun _ : ι => M) N := ⟨⟨fun f => f.1, rfl⟩, fun _ _ => rfl⟩ end ContinuousAdd /-- If `f` is a continuous alternating map, then `f.toContinuousLinearMap m i` is the continuous linear map obtained by fixing all coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/ @[simps! apply] def toContinuousLinearMap [DecidableEq ι] (m : ι → M) (i : ι) : M →L[R] N := f.1.toContinuousLinearMap m i /-- The cartesian product of two continuous alternating maps, as a continuous alternating map. -/ @[simps!] def prod (f : M [⋀^ι]→L[R] N) (g : M [⋀^ι]→L[R] N') : M [⋀^ι]→L[R] (N × N') := ⟨f.1.prod g.1, (f.toAlternatingMap.prod g.toAlternatingMap).map_eq_zero_of_eq⟩ /-- Combine a family of continuous alternating maps with the same domain and codomains `M' i` into a continuous alternating map taking values in the space of functions `Π i, M' i`. -/ def pi {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, TopologicalSpace (M' i)] [∀ i, Module R (M' i)] (f : ∀ i, M [⋀^ι]→L[R] M' i) : M [⋀^ι]→L[R] ∀ i, M' i := ⟨ContinuousMultilinearMap.pi fun i => (f i).1, (AlternatingMap.pi fun i => (f i).toAlternatingMap).map_eq_zero_of_eq⟩ @[simp] theorem coe_pi {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, TopologicalSpace (M' i)] [∀ i, Module R (M' i)] (f : ∀ i, M [⋀^ι]→L[R] M' i) : ⇑(pi f) = fun m j => f j m := rfl theorem pi_apply {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, TopologicalSpace (M' i)] [∀ i, Module R (M' i)] (f : ∀ i, M [⋀^ι]→L[R] M' i) (m : ι → M) (j : ι') : pi f m j = f j m := rfl section variable (R M N) /-- The natural equivalence between continuous linear maps from `M` to `N` and continuous 1-multilinear alternating maps from `M` to `N`. -/ @[simps! apply_apply symm_apply_apply apply_toContinuousMultilinearMap] def ofSubsingleton [Subsingleton ι] (i : ι) : (M →L[R] N) ≃ M [⋀^ι]→L[R] N where toFun f := { AlternatingMap.ofSubsingleton R M N i f with toContinuousMultilinearMap := ContinuousMultilinearMap.ofSubsingleton R M N i f } invFun f := (ContinuousMultilinearMap.ofSubsingleton R M N i).symm f.1 right_inv _ := toContinuousMultilinearMap_injective <| (ContinuousMultilinearMap.ofSubsingleton R M N i).apply_symm_apply _ @[simp] theorem ofSubsingleton_toAlternatingMap [Subsingleton ι] (i : ι) (f : M →L[R] N) : (ofSubsingleton R M N i f).toAlternatingMap = AlternatingMap.ofSubsingleton R M N i f := rfl variable (ι) {N} /-- The constant map is alternating when `ι` is empty. -/ @[simps! toContinuousMultilinearMap apply] def constOfIsEmpty [IsEmpty ι] (m : N) : M [⋀^ι]→L[R] N := { AlternatingMap.constOfIsEmpty R M ι m with toContinuousMultilinearMap := ContinuousMultilinearMap.constOfIsEmpty R (fun _ => M) m } @[simp] theorem constOfIsEmpty_toAlternatingMap [IsEmpty ι] (m : N) : (constOfIsEmpty R M ι m).toAlternatingMap = AlternatingMap.constOfIsEmpty R M ι m := rfl end /-- If `g` is continuous alternating and `f` is a continuous linear map, then `g (f m₁, ..., f mₙ)` is again a continuous alternating map, that we call `g.compContinuousLinearMap f`. -/ def compContinuousLinearMap (g : M [⋀^ι]→L[R] N) (f : M' →L[R] M) : M' [⋀^ι]→L[R] N := { g.toAlternatingMap.compLinearMap (f : M' →ₗ[R] M) with toContinuousMultilinearMap := g.1.compContinuousLinearMap fun _ => f } @[simp] theorem compContinuousLinearMap_apply (g : M [⋀^ι]→L[R] N) (f : M' →L[R] M) (m : ι → M') : g.compContinuousLinearMap f m = g (f ∘ m) := rfl /-- Composing a continuous alternating map with a continuous linear map gives again a continuous alternating map. -/ def _root_.ContinuousLinearMap.compContinuousAlternatingMap (g : N →L[R] N') (f : M [⋀^ι]→L[R] N) : M [⋀^ι]→L[R] N' := { (g : N →ₗ[R] N').compAlternatingMap f.toAlternatingMap with toContinuousMultilinearMap := g.compContinuousMultilinearMap f.1 } @[simp] theorem _root_.ContinuousLinearMap.compContinuousAlternatingMap_coe (g : N →L[R] N') (f : M [⋀^ι]→L[R] N) : ⇑(g.compContinuousAlternatingMap f) = g ∘ f := rfl /-- A continuous linear equivalence of domains defines an equivalence between continuous alternating maps. This is available as a continuous linear isomorphism at `ContinuousLinearEquiv.continuousAlternatingMapCongrLeft`. This is `ContinuousAlternatingMap.compContinuousLinearMap` as an equivalence. -/ @[simps -fullyApplied apply] def _root_.ContinuousLinearEquiv.continuousAlternatingMapCongrLeftEquiv (e : M ≃L[R] M') : M [⋀^ι]→L[R] N ≃ M' [⋀^ι]→L[R] N where toFun f := f.compContinuousLinearMap ↑e.symm invFun f := f.compContinuousLinearMap ↑e left_inv f := by ext; simp [Function.comp_def] right_inv f := by ext; simp [Function.comp_def] @[deprecated (since := "2025-04-16")] alias _root_.ContinuousLinearEquiv.continuousAlternatingMapComp := ContinuousLinearEquiv.continuousAlternatingMapCongrLeftEquiv /-- A continuous linear equivalence of codomains defines an equivalence between continuous alternating maps. -/ @[simps -fullyApplied apply] def _root_.ContinuousLinearEquiv.continuousAlternatingMapCongrRightEquiv (e : N ≃L[R] N') : M [⋀^ι]→L[R] N ≃ M [⋀^ι]→L[R] N' where toFun := (e : N →L[R] N').compContinuousAlternatingMap invFun := (e.symm : N' →L[R] N).compContinuousAlternatingMap left_inv f := by ext; simp [(· ∘ ·)] right_inv f := by ext; simp [(· ∘ ·)] @[deprecated (since := "2025-04-16")] alias _root_.ContinuousLinearEquiv.compContinuousAlternatingMap := ContinuousLinearEquiv.continuousAlternatingMapCongrRightEquiv set_option linter.deprecated false in @[simp] theorem _root_.ContinuousLinearEquiv.compContinuousAlternatingMap_coe (e : N ≃L[R] N') (f : M [⋀^ι]→L[R] N) : ⇑(e.compContinuousAlternatingMap f) = e ∘ f := rfl /-- Continuous linear equivalences between domains and codomains define an equivalence between the spaces of continuous alternating maps. -/ def _root_.ContinuousLinearEquiv.continuousAlternatingMapCongrEquiv (e : M ≃L[R] M') (e' : N ≃L[R] N') : M [⋀^ι]→L[R] N ≃ M' [⋀^ι]→L[R] N' := e.continuousAlternatingMapCongrLeftEquiv.trans e'.continuousAlternatingMapCongrRightEquiv /-- `ContinuousAlternatingMap.pi` as an `Equiv`. -/ @[simps] def piEquiv {ι' : Type*} {N : ι' → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, TopologicalSpace (N i)] [∀ i, Module R (N i)] : (∀ i, M [⋀^ι]→L[R] N i) ≃ M [⋀^ι]→L[R] ∀ i, N i where toFun := pi invFun f i := (ContinuousLinearMap.proj i : _ →L[R] N i).compContinuousAlternatingMap f /-- In the specific case of continuous alternating maps on spaces indexed by `Fin (n+1)`, where one can build an element of `Π(i : Fin (n+1)), M i` using `cons`, one can express directly the additivity of an alternating map along the first variable. -/ theorem cons_add (f : ContinuousAlternatingMap R M N (Fin (n + 1))) (m : Fin n → M) (x y : M) : f (Fin.cons (x + y) m) = f (Fin.cons x m) + f (Fin.cons y m) := f.toMultilinearMap.cons_add m x y /-- In the specific case of continuous alternating maps on spaces indexed by `Fin (n+1)`, where one can build an element of `Π(i : Fin (n+1)), M i` using `cons`, one can express directly the additivity of an alternating map along the first variable. -/ theorem vecCons_add (f : ContinuousAlternatingMap R M N (Fin (n + 1))) (m : Fin n → M) (x y : M) : f (vecCons (x + y) m) = f (vecCons x m) + f (vecCons y m) := f.toMultilinearMap.cons_add m x y /-- In the specific case of continuous alternating maps on spaces indexed by `Fin (n+1)`, where one can build an element of `Π(i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of an alternating map along the first variable. -/ theorem cons_smul (f : ContinuousAlternatingMap R M N (Fin (n + 1))) (m : Fin n → M) (c : R) (x : M) : f (Fin.cons (c • x) m) = c • f (Fin.cons x m) := f.toMultilinearMap.cons_smul m c x /-- In the specific case of continuous alternating maps on spaces indexed by `Fin (n+1)`, where one can build an element of `Π(i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of an alternating map along the first variable. -/ theorem vecCons_smul (f : ContinuousAlternatingMap R M N (Fin (n + 1))) (m : Fin n → M) (c : R) (x : M) : f (vecCons (c • x) m) = c • f (vecCons x m) := f.toMultilinearMap.cons_smul m c x theorem map_piecewise_add [DecidableEq ι] (m m' : ι → M) (t : Finset ι) : f (t.piecewise (m + m') m') = ∑ s ∈ t.powerset, f (s.piecewise m m') := f.toMultilinearMap.map_piecewise_add _ _ _ /-- Additivity of a continuous alternating map along all coordinates at the same time, writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/ theorem map_add_univ [DecidableEq ι] [Fintype ι] (m m' : ι → M) : f (m + m') = ∑ s : Finset ι, f (s.piecewise m m') := f.toMultilinearMap.map_add_univ _ _ section ApplySum open Fintype Finset variable {α : ι → Type*} [Fintype ι] [DecidableEq ι] (g' : ∀ i, α i → M) (A : ∀ i, Finset (α i)) /-- If `f` is continuous alternating, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ..., `r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each coordinate. -/ theorem map_sum_finset : (f fun i => ∑ j ∈ A i, g' i j) = ∑ r ∈ piFinset A, f fun i => g' i (r i) := f.toMultilinearMap.map_sum_finset _ _ /-- If `f` is continuous alternating, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from multilinearity by expanding successively with respect to each coordinate. -/ theorem map_sum [∀ i, Fintype (α i)] : (f fun i => ∑ j, g' i j) = ∑ r : ∀ i, α i, f fun i => g' i (r i) := f.toMultilinearMap.map_sum _ end ApplySum section RestrictScalar variable (R) variable {A : Type*} [Semiring A] [SMul R A] [Module A M] [Module A N] [IsScalarTower R A M] [IsScalarTower R A N] /-- Reinterpret a continuous `A`-alternating map as a continuous `R`-alternating map, if `A` is an algebra over `R` and their actions on all involved modules agree with the action of `R` on `A`. -/ def restrictScalars (f : M [⋀^ι]→L[A] N) : M [⋀^ι]→L[R] N := { f with toContinuousMultilinearMap := f.1.restrictScalars R } @[simp] theorem coe_restrictScalars (f : M [⋀^ι]→L[A] N) : ⇑(f.restrictScalars R) = f := rfl end RestrictScalar end Semiring section Ring variable {R M N ι : Type*} [Ring R] [AddCommGroup M] [Module R M] [TopologicalSpace M] [AddCommGroup N] [Module R N] [TopologicalSpace N] (f g : M [⋀^ι]→L[R] N) @[simp] theorem map_update_sub [DecidableEq ι] (m : ι → M) (i : ι) (x y : M) : f (update m i (x - y)) = f (update m i x) - f (update m i y) := f.toMultilinearMap.map_update_sub _ _ _ _ section IsTopologicalAddGroup variable [IsTopologicalAddGroup N] instance : Neg (M [⋀^ι]→L[R] N) := ⟨fun f => { -f.toAlternatingMap with toContinuousMultilinearMap := -f.1 }⟩ @[simp] theorem coe_neg : ⇑(-f) = -f := rfl theorem neg_apply (m : ι → M) : (-f) m = -f m := rfl instance : Sub (M [⋀^ι]→L[R] N) := ⟨fun f g => { f.toAlternatingMap - g.toAlternatingMap with toContinuousMultilinearMap := f.1 - g.1 }⟩ @[simp] theorem coe_sub : ⇑(f - g) = ⇑f - ⇑g := rfl theorem sub_apply (m : ι → M) : (f - g) m = f m - g m := rfl instance : AddCommGroup (M [⋀^ι]→L[R] N) := toContinuousMultilinearMap_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl end IsTopologicalAddGroup end Ring section CommSemiring variable {R M N ι : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [AddCommMonoid N] [Module R N] [TopologicalSpace N] (f : M [⋀^ι]→L[R] N) theorem map_piecewise_smul [DecidableEq ι] (c : ι → R) (m : ι → M) (s : Finset ι) : f (s.piecewise (fun i => c i • m i) m) = (∏ i ∈ s, c i) • f m := f.toMultilinearMap.map_piecewise_smul _ _ _ /-- Multiplicativity of a continuous alternating map along all coordinates at the same time, writing `f (fun i ↦ c i • m i)` as `(∏ i, c i) • f m`. -/ theorem map_smul_univ [Fintype ι] (c : ι → R) (m : ι → M) : (f fun i => c i • m i) = (∏ i, c i) • f m := f.toMultilinearMap.map_smul_univ _ _ /-- If two continuous `R`-alternating maps from `R` are equal on 1, then they are equal. This is the alternating version of `ContinuousLinearMap.ext_ring`. -/ @[ext] theorem ext_ring [Finite ι] [TopologicalSpace R] ⦃f g : R [⋀^ι]→L[R] M⦄ (h : f (fun _ ↦ 1) = g (fun _ ↦ 1)) : f = g := toAlternatingMap_injective <| AlternatingMap.ext_ring h /-- The only continuous `R`-alternating map from two or more copies of `R` is the zero map. -/ instance uniqueOfCommRing [Finite ι] [Nontrivial ι] [TopologicalSpace R] : Unique (R [⋀^ι]→L[R] N) where uniq _ := toAlternatingMap_injective <| Subsingleton.elim _ _ end CommSemiring section DistribMulAction variable {R A M N ι : Type*} [Monoid R] [Semiring A] [AddCommMonoid M] [AddCommMonoid N] [TopologicalSpace M] [TopologicalSpace N] [Module A M] [Module A N] [DistribMulAction R N] [ContinuousConstSMul R N] [SMulCommClass A R N] instance [ContinuousAdd N] : DistribMulAction R (M [⋀^ι]→L[A] N) := Function.Injective.distribMulAction toMultilinearAddHom toContinuousMultilinearMap_injective fun _ _ => rfl end DistribMulAction section Module variable {R A M N ι : Type*} [Semiring R] [Semiring A] [AddCommMonoid M] [AddCommMonoid N] [TopologicalSpace M] [TopologicalSpace N] [ContinuousAdd N] [Module A M] [Module A N] [Module R N] [ContinuousConstSMul R N] [SMulCommClass A R N] /-- The space of continuous alternating maps over an algebra over `R` is a module over `R`, for the pointwise addition and scalar multiplication. -/ instance : Module R (M [⋀^ι]→L[A] N) := Function.Injective.module _ toMultilinearAddHom toContinuousMultilinearMap_injective fun _ _ => rfl /-- Linear map version of the map `toMultilinearMap` associating to a continuous alternating map the corresponding multilinear map. -/ @[simps] def toContinuousMultilinearMapLinear : M [⋀^ι]→L[A] N →ₗ[R] ContinuousMultilinearMap A (fun _ : ι => M) N where toFun := toContinuousMultilinearMap map_add' _ _ := rfl map_smul' _ _ := rfl /-- Linear map version of the map `toAlternatingMap` associating to a continuous alternating map the corresponding alternating map. -/ @[simps -fullyApplied apply] def toAlternatingMapLinear : (M [⋀^ι]→L[A] N) →ₗ[R] (M [⋀^ι]→ₗ[A] N) where toFun := toAlternatingMap map_add' := by simp map_smul' := by simp /-- `ContinuousAlternatingMap.pi` as a `LinearEquiv`. -/ @[simps +simpRhs] def piLinearEquiv {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, TopologicalSpace (M' i)] [∀ i, ContinuousAdd (M' i)] [∀ i, Module R (M' i)] [∀ i, Module A (M' i)] [∀ i, SMulCommClass A R (M' i)] [∀ i, ContinuousConstSMul R (M' i)] : (∀ i, M [⋀^ι]→L[A] M' i) ≃ₗ[R] M [⋀^ι]→L[A] ∀ i, M' i := { piEquiv with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } end Module section SMulRight variable {R M N ι : Type*} [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] [TopologicalSpace R] [TopologicalSpace M] [TopologicalSpace N] [ContinuousSMul R N] (f : M [⋀^ι]→L[R] R) (z : N) /-- Given a continuous `R`-alternating map `f` taking values in `R`, `f.smulRight z` is the continuous alternating map sending `m` to `f m • z`. -/ @[simps! toContinuousMultilinearMap apply] def smulRight : M [⋀^ι]→L[R] N := { f.toAlternatingMap.smulRight z with toContinuousMultilinearMap := f.1.smulRight z } end SMulRight section Semiring variable {R M M' N N' ι : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [AddCommMonoid M'] [Module R M'] [TopologicalSpace M'] [AddCommMonoid N] [Module R N] [TopologicalSpace N] [ContinuousAdd N] [ContinuousConstSMul R N] [AddCommMonoid N'] [Module R N'] [TopologicalSpace N'] [ContinuousAdd N'] [ContinuousConstSMul R N'] /-- `ContinuousAlternatingMap.compContinuousLinearMap` as a bundled `LinearMap`. -/ @[simps] def compContinuousLinearMapₗ (f : M →L[R] M') : (M' [⋀^ι]→L[R] N) →ₗ[R] (M [⋀^ι]→L[R] N) where toFun g := g.compContinuousLinearMap f map_add' g g' := by ext; simp map_smul' c g := by ext; simp variable (R M N N') /-- `ContinuousLinearMap.compContinuousAlternatingMap` as a bundled bilinear map. -/ def _root_.ContinuousLinearMap.compContinuousAlternatingMapₗ : (N →L[R] N') →ₗ[R] (M [⋀^ι]→L[R] N) →ₗ[R] (M [⋀^ι]→L[R] N') := LinearMap.mk₂ R ContinuousLinearMap.compContinuousAlternatingMap (fun _ _ _ => rfl) (fun _ _ _ => rfl) (fun f g₁ g₂ => by ext1; apply f.map_add) fun c f g => by ext1; simp end Semiring end ContinuousAlternatingMap namespace ContinuousMultilinearMap variable {R M N ι : Type*} [Semiring R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [AddCommGroup N] [Module R N] [TopologicalSpace N] [IsTopologicalAddGroup N] [Fintype ι] [DecidableEq ι] (f : ContinuousMultilinearMap R (fun _ : ι => M) N) /-- Alternatization of a continuous multilinear map. -/ @[simps -isSimp apply_toContinuousMultilinearMap] def alternatization : ContinuousMultilinearMap R (fun _ : ι => M) N →+ M [⋀^ι]→L[R] N where toFun f := { toContinuousMultilinearMap := ∑ σ : Equiv.Perm ι, Equiv.Perm.sign σ • f.domDomCongr σ map_eq_zero_of_eq' := fun v i j hv hne => by simpa [MultilinearMap.alternatization_apply] using f.1.alternatization.map_eq_zero_of_eq' v i j hv hne } map_zero' := by ext; simp map_add' _ _ := by ext; simp [Finset.sum_add_distrib] theorem alternatization_apply_apply (v : ι → M) : alternatization f v = ∑ σ : Equiv.Perm ι, Equiv.Perm.sign σ • f (v ∘ σ) := by simp [alternatization, Function.comp_def] @[simp] theorem alternatization_apply_toAlternatingMap : (alternatization f).toAlternatingMap = MultilinearMap.alternatization f.1 := by ext v simp [alternatization_apply_apply, MultilinearMap.alternatization_apply, Function.comp_def] end ContinuousMultilinearMap
Girard.lean
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Logic.Basic import Mathlib.Data.Set.Defs /-! # Girard's paradox Girard's paradox is a proof that `Type : Type` entails a contradiction. We can't say this directly in Lean because `Type : Type 1` and it's not possible to give `Type` a different type via an axiom, so instead we axiomatize the behavior of the Pi type and application if the typing rule for Pi was `(Type → Type) → Type` instead of `(Type → Type) → Type 1`. Furthermore, we don't actually want false axioms in mathlib, so rather than introducing the axioms using `axiom` or `constant` declarations, we take them as assumptions to the `girard` theorem. Based on Watkins' LF implementation of Hurkens' simplification of Girard's paradox: <http://www.cs.cmu.edu/~kw/research/hurkens95tlca.elf>. ## Main statements * `girard`: there are no Girard universes. -/ namespace Counterexample /-- **Girard's paradox**: there are no universes `u` such that `Type u : Type u`. Since we can't actually change the type of Lean's `Π` operator, we assume the existence of `pi`, `lam`, `app` and the `beta` rule equivalent to the `Π` and `app` constructors of type theory. -/ theorem girard.{u} (pi : (Type u → Type u) → Type u) (lam : ∀ {A : Type u → Type u}, (∀ x, A x) → pi A) (app : ∀ {A}, pi A → ∀ x, A x) (beta : ∀ {A : Type u → Type u} (f : ∀ x, A x) (x), app (lam f) x = f x) : False := let F (X) := (Set (Set X) → X) → Set (Set X) let U := pi F let G (T : Set (Set U)) (X) : F X := fun f => {p | {x : U | f (app x X f) ∈ p} ∈ T} let τ (T : Set (Set U)) : U := lam (G T) let σ (S : U) : Set (Set U) := app S U τ have στ : ∀ {s S}, s ∈ σ (τ S) ↔ {x | τ (σ x) ∈ s} ∈ S := fun {s S} => iff_of_eq (congr_arg (fun f : F U => s ∈ f τ) (beta (G S) U) :) let ω : Set (Set U) := {p | ∀ x, p ∈ σ x → x ∈ p} let δ (S : Set (Set U)) := ∀ p, p ∈ S → τ S ∈ p have : δ ω := fun _p d => d (τ ω) <| στ.2 fun x h => d (τ (σ x)) (στ.2 h) this {y | ¬δ (σ y)} (fun _x e f => f _ e fun _p h => f _ (στ.1 h)) fun _p h => this _ (στ.1 h) end Counterexample
Completion.lean
/- Copyright (c) 2024 Salvatore Mercuri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Salvatore Mercuri -/ import Mathlib.Algebra.Field.Subfield.Basic import Mathlib.Analysis.Normed.Module.Completion import Mathlib.Analysis.Normed.Field.WithAbs import Mathlib.NumberTheory.NumberField.InfinitePlace.Basic /-! # The completion of a number field at an infinite place This file contains the completion of a number field at an infinite place. This is ultimately achieved by applying the `UniformSpace.Completion` functor, however each infinite place induces its own `UniformSpace` instance on the number field, so the inference system cannot automatically infer these. A common approach to handle the ambiguity that arises from having multiple sources of instances is through the use of type synonyms. In this case, we use the type synonym `WithAbs` of a semiring. In particular this type synonym depends on an absolute value, which provides a systematic way of assigning and inferring instances of the semiring that also depend on an absolute value. The completion of a field at multiple absolute values is defined in `Mathlib/Algebra/Ring/WithAbs.lean` as `AbsoluteValue.Completion`. The completion of a number field at an infinite place is then derived in this file, as `InfinitePlace` is a subtype of `AbsoluteValue`. ## Main definitions - `NumberField.InfinitePlace.Completion` : the completion of a number field `K` at an infinite place, obtained by completing `K` with respect to the absolute value associated to the infinite place. - `NumberField.InfinitePlace.Completion.extensionEmbedding` : the embedding `v.embedding : K →+* ℂ` extended to `v.Completion →+* ℂ`. - `NumberField.InfinitePlace.Completion.extensionEmbeddingOfIsReal` : if the infinite place `v` is real, then this extends the embedding `v.embedding_of_isReal : K →+* ℝ` to `v.Completion →+* ℝ`. - `NumberField.InfinitePlace.Completion.ringEquivRealOfIsReal` : the ring isomorphism `v.Completion ≃+* ℝ` when `v` is a real infinite place; the forward direction of this is `extensionEmbeddingOfIsReal`. - `NumberField.InfinitePlace.Completion.ringEquivComplexOfIsComplex` : the ring isomorphism `v.Completion ≃+* ℂ` when `v` is a complex infinite place; the forward direction of this is `extensionEmbedding`. ## Main results - `NumberField.Completion.locallyCompactSpace` : the completion of a number field at an infinite place is locally compact. - `NumberField.Completion.isometry_extensionEmbedding` : the embedding `v.Completion →+* ℂ` is an isometry. See also `isometry_extensionEmbedding_of_isReal` for the corresponding result on `v.Completion →+* ℝ` when `v` is real. - `NumberField.Completion.bijective_extensionEmbedding_of_isComplex` : the embedding `v.Completion →+* ℂ` is bijective when `v` is complex. See also `bijective_extensionEmebdding_of_isReal` for the corresponding result for `v.Completion →+* ℝ` when `v` is real. ## Tags number field, embeddings, infinite places, completion, absolute value -/ noncomputable section namespace NumberField.InfinitePlace open AbsoluteValue.Completion variable {K : Type*} [Field K] (v : InfinitePlace K) /-- The completion of a number field at an infinite place. -/ abbrev Completion := v.1.Completion namespace Completion instance : NormedField v.Completion := letI := (WithAbs.isUniformInducing_of_comp v.norm_embedding_eq).completableTopField UniformSpace.Completion.instNormedFieldOfCompletableTopField (WithAbs v.1) lemma norm_coe (x : WithAbs v.1) : ‖(x : v.Completion)‖ = v (WithAbs.equiv v.1 x) := UniformSpace.Completion.norm_coe x instance : Algebra K v.Completion := inferInstanceAs <| Algebra (WithAbs v.1) v.1.Completion /-- The coercion from the rationals to its completion along an infinite place is `Rat.cast`. -/ lemma WithAbs.ratCast_equiv (v : InfinitePlace ℚ) (x : WithAbs v.1) : Rat.cast (WithAbs.equiv _ x) = (x : v.Completion) := (eq_ratCast (UniformSpace.Completion.coeRingHom.comp (WithAbs.equiv v.1).symm.toRingHom) x).symm lemma Rat.norm_infinitePlace_completion (v : InfinitePlace ℚ) (x : ℚ) : ‖(x : v.Completion)‖ = |x| := by rw [← (WithAbs.equiv v.1).apply_symm_apply x, WithAbs.ratCast_equiv, norm_coe, (WithAbs.equiv v.1).apply_symm_apply, Rat.infinitePlace_apply] /-- The completion of a number field at an infinite place is locally compact. -/ instance locallyCompactSpace : LocallyCompactSpace (v.Completion) := AbsoluteValue.Completion.locallyCompactSpace v.norm_embedding_eq /-- The embedding associated to an infinite place extended to an embedding `v.Completion →+* ℂ`. -/ def extensionEmbedding : v.Completion →+* ℂ := extensionEmbedding_of_comp v.norm_embedding_eq /-- The embedding `K →+* ℝ` associated to a real infinite place extended to `v.Completion →+* ℝ`. -/ def extensionEmbeddingOfIsReal {v : InfinitePlace K} (hv : IsReal v) : v.Completion →+* ℝ := extensionEmbedding_of_comp <| v.norm_embedding_of_isReal hv @[simp] theorem extensionEmbedding_coe (x : K) : extensionEmbedding v x = v.embedding x := extensionEmbedding_of_comp_coe v.norm_embedding_eq x @[simp] theorem extensionEmbedding_of_isReal_coe {v : InfinitePlace K} (hv : IsReal v) (x : K) : extensionEmbeddingOfIsReal hv x = embedding_of_isReal hv x := extensionEmbedding_of_comp_coe (v.norm_embedding_of_isReal hv) x /-- The embedding `v.Completion →+* ℂ` is an isometry. -/ theorem isometry_extensionEmbedding : Isometry (extensionEmbedding v) := Isometry.of_dist_eq (extensionEmbedding_dist_eq_of_comp v.norm_embedding_eq) /-- The embedding `v.Completion →+* ℝ` at a real infinite place is an isometry. -/ theorem isometry_extensionEmbedding_of_isReal {v : InfinitePlace K} (hv : IsReal v) : Isometry (extensionEmbeddingOfIsReal hv) := Isometry.of_dist_eq (extensionEmbedding_dist_eq_of_comp <| v.norm_embedding_of_isReal hv) /-- The embedding `v.Completion →+* ℂ` has closed image inside `ℂ`. -/ theorem isClosed_image_extensionEmbedding : IsClosed (Set.range (extensionEmbedding v)) := (isClosedEmbedding_extensionEmbedding_of_comp v.norm_embedding_eq).isClosed_range /-- The embedding `v.Completion →+* ℝ` associated to a real infinite place has closed image inside `ℝ`. -/ theorem isClosed_image_extensionEmbedding_of_isReal {v : InfinitePlace K} (hv : IsReal v) : IsClosed (Set.range (extensionEmbeddingOfIsReal hv)) := (isClosedEmbedding_extensionEmbedding_of_comp <| v.norm_embedding_of_isReal hv).isClosed_range theorem subfield_ne_real_of_isComplex {v : InfinitePlace K} (hv : IsComplex v) : (extensionEmbedding v).fieldRange ≠ Complex.ofRealHom.fieldRange := by contrapose! hv simp only [not_isComplex_iff_isReal, isReal_iff] ext x obtain ⟨r, hr⟩ := hv ▸ extensionEmbedding_coe v x ▸ RingHom.mem_fieldRange_self _ _ simp only [ComplexEmbedding.conjugate_coe_eq, ← hr, Complex.ofRealHom_eq_coe, Complex.conj_ofReal] /-- If `v` is a complex infinite place, then the embedding `v.Completion →+* ℂ` is surjective. -/ theorem surjective_extensionEmbedding_of_isComplex {v : InfinitePlace K} (hv : IsComplex v) : Function.Surjective (extensionEmbedding v) := by rw [← RingHom.fieldRange_eq_top_iff] exact (Complex.subfield_eq_of_closed <| isClosed_image_extensionEmbedding v).resolve_left <| subfield_ne_real_of_isComplex hv /-- If `v` is a complex infinite place, then the embedding `v.Completion →+* ℂ` is bijective. -/ theorem bijective_extensionEmbedding_of_isComplex {v : InfinitePlace K} (hv : IsComplex v) : Function.Bijective (extensionEmbedding v) := ⟨(extensionEmbedding v).injective, surjective_extensionEmbedding_of_isComplex hv⟩ /-- The ring isomorphism `v.Completion ≃+* ℂ`, when `v` is complex, given by the bijection `v.Completion →+* ℂ`. -/ def ringEquivComplexOfIsComplex {v : InfinitePlace K} (hv : IsComplex v) : v.Completion ≃+* ℂ := RingEquiv.ofBijective _ (bijective_extensionEmbedding_of_isComplex hv) /-- If the infinite place `v` is complex, then `v.Completion` is isometric to `ℂ`. -/ def isometryEquivComplexOfIsComplex {v : InfinitePlace K} (hv : IsComplex v) : v.Completion ≃ᵢ ℂ where toEquiv := ringEquivComplexOfIsComplex hv isometry_toFun := isometry_extensionEmbedding v /-- If `v` is a real infinite place, then the embedding `v.Completion →+* ℝ` is surjective. -/ theorem surjective_extensionEmbedding_of_isReal {v : InfinitePlace K} (hv : IsReal v) : Function.Surjective (extensionEmbeddingOfIsReal hv) := by rw [← RingHom.fieldRange_eq_top_iff, ← Real.subfield_eq_of_closed] exact isClosed_image_extensionEmbedding_of_isReal hv /-- If `v` is a real infinite place, then the embedding `v.Completion →+* ℝ` is bijective. -/ theorem bijective_extensionEmbedding_of_isReal {v : InfinitePlace K} (hv : IsReal v) : Function.Bijective (extensionEmbeddingOfIsReal hv) := ⟨(extensionEmbeddingOfIsReal hv).injective, surjective_extensionEmbedding_of_isReal hv⟩ /-- The ring isomorphism `v.Completion ≃+* ℝ`, when `v` is real, given by the bijection `v.Completion →+* ℝ`. -/ def ringEquivRealOfIsReal {v : InfinitePlace K} (hv : IsReal v) : v.Completion ≃+* ℝ := RingEquiv.ofBijective _ (bijective_extensionEmbedding_of_isReal hv) /-- If the infinite place `v` is real, then `v.Completion` is isometric to `ℝ`. -/ def isometryEquivRealOfIsReal {v : InfinitePlace K} (hv : IsReal v) : v.Completion ≃ᵢ ℝ where toEquiv := ringEquivRealOfIsReal hv isometry_toFun := isometry_extensionEmbedding_of_isReal hv end NumberField.InfinitePlace.Completion
Formula.lean
/- Copyright (c) 2025 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.AlgebraicGeometry.EllipticCurve.Affine.Formula import Mathlib.AlgebraicGeometry.EllipticCurve.Jacobian.Basic /-! # Negation and addition formulae for nonsingular points in Jacobian coordinates Let `W` be a Weierstrass curve over a field `F`. The nonsingular Jacobian points on `W` can be given negation and addition operations defined by an analogue of the secant-and-tangent process in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine/Formula.lean`, but the polynomials involved are `(2, 3, 1)`-homogeneous, so any instances of division become multiplication in the `Z`-coordinate. Most computational proofs are immediate from their analogous proofs for affine coordinates. This file defines polynomials associated to negation, doubling, and addition of Jacobian point representatives. The group operations and the group law on actual nonsingular Jacobian points will be defined in `Mathlib/AlgebraicGeometry/EllipticCurve/Jacobian/Point.lean`. ## Main definitions * `WeierstrassCurve.Jacobian.negY`: the `Y`-coordinate of `-P`. * `WeierstrassCurve.Jacobian.dblZ`: the `Z`-coordinate of `2 • P`. * `WeierstrassCurve.Jacobian.dblX`: the `X`-coordinate of `2 • P`. * `WeierstrassCurve.Jacobian.negDblY`: the `Y`-coordinate of `-(2 • P)`. * `WeierstrassCurve.Jacobian.dblY`: the `Y`-coordinate of `2 • P`. * `WeierstrassCurve.Jacobian.addZ`: the `Z`-coordinate of `P + Q`. * `WeierstrassCurve.Jacobian.addX`: the `X`-coordinate of `P + Q`. * `WeierstrassCurve.Jacobian.negAddY`: the `Y`-coordinate of `-(P + Q)`. * `WeierstrassCurve.Jacobian.addY`: the `Y`-coordinate of `P + Q`. ## Implementation notes The definitions of `WeierstrassCurve.Jacobian.addX` and `WeierstrassCurve.Jacobian.negAddY` are given explicitly by large polynomials that are homogeneous of degrees `8` and `12` respectively. Clearing the denominators of their corresponding affine rational functions in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine/Formula.lean` would give polynomials that are homogeneous of degrees `12` and `18` respectively, so their actual definitions are off by powers of a certain polynomial factor that is homogeneous of degree `2`. This factor divides their corresponding affine polynomials only modulo the `(2, 3, 1)`-homogeneous Weierstrass equation, so their large quotient polynomials are calculated explicitly in a computer algebra system. All of this is done to ensure that the definitions of both `WeierstrassCurve.Jacobian.dblXYZ` and `WeierstrassCurve.Jacobian.addXYZ` are `(2, 3, 1)`-homogeneous of degree `4`. Whenever possible, all changes to documentation and naming of definitions and theorems should be mirrored in `Mathlib/AlgebraicGeometry/EllipticCurve/Projective/Formula.lean`. ## References [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, Jacobian, negation, doubling, addition, group law -/ local notation3 "x" => (0 : Fin 3) local notation3 "y" => (1 : Fin 3) local notation3 "z" => (2 : Fin 3) open MvPolynomial local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_C, map_X, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀, WeierstrassCurve.map, Function.comp_apply]) universe r s u v namespace WeierstrassCurve variable {R : Type r} {S : Type s} {A F : Type u} {B K : Type v} [CommRing R] [CommRing S] [CommRing A] [CommRing B] [Field F] [Field K] {W' : Jacobian R} {W : Jacobian F} namespace Jacobian /-! ## Negation formulae in Jacobian coordinates -/ variable (W') in /-- The `Y`-coordinate of a representative of `-P` for a Jacobian point representative `P` on a Weierstrass curve. -/ def negY (P : Fin 3 → R) : R := -P y - W'.a₁ * P x * P z - W'.a₃ * P z ^ 3 lemma negY_eq (X Y Z : R) : W'.negY ![X, Y, Z] = -Y - W'.a₁ * X * Z - W'.a₃ * Z ^ 3 := rfl lemma negY_smul (P : Fin 3 → R) (u : R) : W'.negY (u • P) = u ^ 3 * W'.negY P := by simp only [negY, smul_fin3_ext] ring1 lemma negY_of_Z_eq_zero {P : Fin 3 → R} (hPz : P z = 0) : W'.negY P = -P y := by rw [negY, hPz, mul_zero, sub_zero, zero_pow three_ne_zero, mul_zero, sub_zero] lemma negY_of_Z_ne_zero {P : Fin 3 → F} (hPz : P z ≠ 0) : W.negY P / P z ^ 3 = W.toAffine.negY (P x / P z ^ 2) (P y / P z ^ 3) := by linear_combination (norm := (rw [negY, Affine.negY]; ring1)) -W.a₁ * P x / P z ^ 2 * div_self hPz - W.a₃ * div_self (pow_ne_zero 3 hPz) lemma Y_sub_Y_mul_Y_sub_negY {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : (P y * Q z ^ 3 - Q y * P z ^ 3) * (P y * Q z ^ 3 - W'.negY Q * P z ^ 3) = 0 := by linear_combination (norm := (rw [negY]; ring1)) Q z ^ 6 * (equation_iff P).mp hP - P z ^ 6 * (equation_iff Q).mp hQ + (P x ^ 2 * Q z ^ 4 + P x * Q x * P z ^ 2 * Q z ^ 2 + Q x ^ 2 * P z ^ 4 - W'.a₁ * P y * P z * Q z ^ 4 + W'.a₂ * P x * P z ^ 2 * Q z ^ 4 + W'.a₂ * Q x * P z ^ 4 * Q z ^ 2 + W'.a₄ * P z ^ 4 * Q z ^ 4) * hx lemma Y_eq_of_Y_ne [NoZeroDivisors R] {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ Q y * P z ^ 3) : P y * Q z ^ 3 = W'.negY Q * P z ^ 3 := sub_eq_zero.mp <| (mul_eq_zero.mp <| Y_sub_Y_mul_Y_sub_negY hP hQ hx).resolve_left <| sub_ne_zero.mpr hy lemma Y_eq_of_Y_ne' [NoZeroDivisors R] {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W'.negY Q * P z ^ 3) : P y * Q z ^ 3 = Q y * P z ^ 3 := sub_eq_zero.mp <| (mul_eq_zero.mp <| Y_sub_Y_mul_Y_sub_negY hP hQ hx).resolve_right <| sub_ne_zero.mpr hy lemma Y_eq_iff' {P Q : Fin 3 → F} (hPz : P z ≠ 0) (hQz : Q z ≠ 0) : P y * Q z ^ 3 = W.negY Q * P z ^ 3 ↔ P y / P z ^ 3 = W.toAffine.negY (Q x / Q z ^ 2) (Q y / Q z ^ 3) := negY_of_Z_ne_zero hQz ▸ (div_eq_div_iff (pow_ne_zero 3 hPz) (pow_ne_zero 3 hQz)).symm lemma Y_sub_Y_add_Y_sub_negY {P Q : Fin 3 → R} (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : (P y * Q z ^ 3 - Q y * P z ^ 3) + (P y * Q z ^ 3 - W'.negY Q * P z ^ 3) = (P y - W'.negY P) * Q z ^ 3 := by linear_combination (norm := (rw [negY, negY]; ring1)) -W'.a₁ * P z * Q z * hx lemma Y_ne_negY_of_Y_ne [NoZeroDivisors R] {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ Q y * P z ^ 3) : P y ≠ W'.negY P := by have hy' : P y * Q z ^ 3 - W'.negY Q * P z ^ 3 = 0 := (mul_eq_zero.mp <| Y_sub_Y_mul_Y_sub_negY hP hQ hx).resolve_left <| sub_ne_zero_of_ne hy contrapose! hy linear_combination (norm := ring1) Y_sub_Y_add_Y_sub_negY hx + Q z ^ 3 * hy - hy' lemma Y_ne_negY_of_Y_ne' [NoZeroDivisors R] {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W'.negY Q * P z ^ 3) : P y ≠ W'.negY P := by have hy' : P y * Q z ^ 3 - Q y * P z ^ 3 = 0 := (mul_eq_zero.mp <| Y_sub_Y_mul_Y_sub_negY hP hQ hx).resolve_right <| sub_ne_zero_of_ne hy contrapose! hy linear_combination (norm := ring1) Y_sub_Y_add_Y_sub_negY hx + Q z ^ 3 * hy - hy' lemma Y_eq_negY_of_Y_eq [NoZeroDivisors R] {P Q : Fin 3 → R} (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W'.negY Q * P z ^ 3) : P y = W'.negY P := mul_left_injective₀ (pow_ne_zero 3 hQz) <| by linear_combination (norm := ring1) -Y_sub_Y_add_Y_sub_negY hx + hy + hy' lemma nonsingular_iff_of_Y_eq_negY {P : Fin 3 → F} (hPz : P z ≠ 0) (hy : P y = W.negY P) : W.Nonsingular P ↔ W.Equation P ∧ eval P W.polynomialX ≠ 0 := by have hy' : eval P W.polynomialY = P y - W.negY P := by rw [negY, eval_polynomialY]; ring1 rw [nonsingular_iff_of_Z_ne_zero hPz, hy', hy, sub_self, ne_self_iff_false, or_false] /-! ## Doubling formulae in Jacobian coordinates -/ variable (W') in /-- The unit associated to a representative of `2 • P` for a Jacobian point representative `P` on a Weierstrass curve `W` that is `2`-torsion. More specifically, the unit `u` such that `W.add P P = u • ![1, 1, 0]` where `P = W.neg P`. -/ noncomputable def dblU (P : Fin 3 → R) : R := eval P W'.polynomialX lemma dblU_eq (P : Fin 3 → R) : W'.dblU P = W'.a₁ * P y * P z - (3 * P x ^ 2 + 2 * W'.a₂ * P x * P z ^ 2 + W'.a₄ * P z ^ 4) := by rw [dblU, eval_polynomialX] lemma dblU_smul (P : Fin 3 → R) (u : R) : W'.dblU (u • P) = u ^ 4 * W'.dblU P := by simp only [dblU_eq, smul_fin3_ext] ring1 lemma dblU_of_Z_eq_zero {P : Fin 3 → R} (hPz : P z = 0) : W'.dblU P = -3 * P x ^ 2 := by rw [dblU_eq, hPz] ring1 lemma dblU_ne_zero_of_Y_eq {P Q : Fin 3 → F} (hP : W.Nonsingular P) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W.negY Q * P z ^ 3) : W.dblU P ≠ 0 := ((nonsingular_iff_of_Y_eq_negY hPz <| Y_eq_negY_of_Y_eq hQz hx hy hy').mp hP).right lemma isUnit_dblU_of_Y_eq {P Q : Fin 3 → F} (hP : W.Nonsingular P) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W.negY Q * P z ^ 3) : IsUnit (W.dblU P) := (dblU_ne_zero_of_Y_eq hP hPz hQz hx hy hy').isUnit variable (W') in /-- The `Z`-coordinate of a representative of `2 • P` for a Jacobian point representative `P` on a Weierstrass curve. -/ def dblZ (P : Fin 3 → R) : R := P z * (P y - W'.negY P) lemma dblZ_smul (P : Fin 3 → R) (u : R) : W'.dblZ (u • P) = u ^ 4 * W'.dblZ P := by simp only [dblZ, negY_smul, smul_fin3_ext] ring1 lemma dblZ_of_Z_eq_zero {P : Fin 3 → R} (hPz : P z = 0) : W'.dblZ P = 0 := by rw [dblZ, hPz, zero_mul] lemma dblZ_of_Y_eq [NoZeroDivisors R] {P Q : Fin 3 → R} (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W'.negY Q * P z ^ 3) : W'.dblZ P = 0 := by rw [dblZ, Y_eq_negY_of_Y_eq hQz hx hy hy', sub_self, mul_zero] lemma dblZ_ne_zero_of_Y_ne [NoZeroDivisors R] {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hPz : P z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ Q y * P z ^ 3) : W'.dblZ P ≠ 0 := mul_ne_zero hPz <| sub_ne_zero.mpr <| Y_ne_negY_of_Y_ne hP hQ hx hy lemma isUnit_dblZ_of_Y_ne {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ Q y * P z ^ 3) : IsUnit (W.dblZ P) := (dblZ_ne_zero_of_Y_ne hP hQ hPz hx hy).isUnit lemma dblZ_ne_zero_of_Y_ne' [NoZeroDivisors R] {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hPz : P z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W'.negY Q * P z ^ 3) : W'.dblZ P ≠ 0 := mul_ne_zero hPz <| sub_ne_zero.mpr <| Y_ne_negY_of_Y_ne' hP hQ hx hy lemma isUnit_dblZ_of_Y_ne' {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W.negY Q * P z ^ 3) : IsUnit (W.dblZ P) := (dblZ_ne_zero_of_Y_ne' hP hQ hPz hx hy).isUnit private lemma toAffine_slope_of_eq [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W.negY Q * P z ^ 3) : W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3) = -W.dblU P / W.dblZ P := by have hPy : P y - W.negY P ≠ 0 := sub_ne_zero.mpr <| Y_ne_negY_of_Y_ne' hP hQ hx hy simp only [X_eq_iff hPz hQz, ne_eq, Y_eq_iff' hPz hQz] at hx hy rw [Affine.slope_of_Y_ne hx <| negY_of_Z_ne_zero hQz ▸ hy, ← negY_of_Z_ne_zero hPz, dblU_eq, dblZ] field_simp [pow_ne_zero 2 hPz] ring1 variable (W') in /-- The `X`-coordinate of a representative of `2 • P` for a Jacobian point representative `P` on a Weierstrass curve. -/ noncomputable def dblX (P : Fin 3 → R) : R := W'.dblU P ^ 2 - W'.a₁ * W'.dblU P * P z * (P y - W'.negY P) - W'.a₂ * P z ^ 2 * (P y - W'.negY P) ^ 2 - 2 * P x * (P y - W'.negY P) ^ 2 lemma dblX_smul (P : Fin 3 → R) (u : R) : W'.dblX (u • P) = (u ^ 4) ^ 2 * W'.dblX P := by simp only [dblX, dblU_smul, negY_smul, smul_fin3_ext] ring1 lemma dblX_of_Z_eq_zero {P : Fin 3 → R} (hP : W'.Equation P) (hPz : P z = 0) : W'.dblX P = (P x ^ 2) ^ 2 := by linear_combination (norm := (rw [dblX, dblU_of_Z_eq_zero hPz, negY_of_Z_eq_zero hPz, hPz]; ring1)) -8 * P x * (equation_of_Z_eq_zero hPz).mp hP lemma dblX_of_Y_eq [NoZeroDivisors R] {P Q : Fin 3 → R} (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W'.negY Q * P z ^ 3) : W'.dblX P = W'.dblU P ^ 2 := by rw [dblX, Y_eq_negY_of_Y_eq hQz hx hy hy'] ring1 private lemma toAffine_addX_of_eq {P : Fin 3 → F} (hPz : P z ≠ 0) {n d : F} (hd : d ≠ 0) : W.toAffine.addX (P x / P z ^ 2) (P x / P z ^ 2) (-n / (P z * d)) = (n ^ 2 - W.a₁ * n * P z * d - W.a₂ * P z ^ 2 * d ^ 2 - 2 * P x * d ^ 2) / (P z * d) ^ 2 := by field_simp [mul_ne_zero hPz hd] ring1 lemma dblX_of_Z_ne_zero [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W.negY Q * P z ^ 3) : W.dblX P / W.dblZ P ^ 2 = W.toAffine.addX (P x / P z ^ 2) (Q x / Q z ^ 2) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)) := by rw [dblX, toAffine_slope_of_eq hP hQ hPz hQz hx hy, dblZ, ← (X_eq_iff hPz hQz).mp hx, toAffine_addX_of_eq hPz <| sub_ne_zero.mpr <| Y_ne_negY_of_Y_ne' hP hQ hx hy] variable (W') in /-- The `Y`-coordinate of a representative of `-(2 • P)` for a Jacobian point representative `P` on a Weierstrass curve. -/ noncomputable def negDblY (P : Fin 3 → R) : R := -W'.dblU P * (W'.dblX P - P x * (P y - W'.negY P) ^ 2) + P y * (P y - W'.negY P) ^ 3 lemma negDblY_smul (P : Fin 3 → R) (u : R) : W'.negDblY (u • P) = (u ^ 4) ^ 3 * W'.negDblY P := by simp only [negDblY, dblU_smul, dblX_smul, negY_smul, smul_fin3_ext] ring1 lemma negDblY_of_Z_eq_zero {P : Fin 3 → R} (hP : W'.Equation P) (hPz : P z = 0) : W'.negDblY P = -(P x ^ 2) ^ 3 := by linear_combination (norm := (rw [negDblY, dblU_of_Z_eq_zero hPz, dblX_of_Z_eq_zero hP hPz, negY_of_Z_eq_zero hPz]; ring1)) (8 * P y ^ 2 - 4 * P x ^ 3) * (equation_of_Z_eq_zero hPz).mp hP lemma negDblY_of_Y_eq [NoZeroDivisors R] {P Q : Fin 3 → R} (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W'.negY Q * P z ^ 3) : W'.negDblY P = (-W'.dblU P) ^ 3 := by rw [negDblY, dblX_of_Y_eq hQz hx hy hy', Y_eq_negY_of_Y_eq hQz hx hy hy'] ring1 private lemma toAffine_negAddY_of_eq {P : Fin 3 → F} (hPz : P z ≠ 0) {n d : F} (hd : d ≠ 0) : W.toAffine.negAddY (P x / P z ^ 2) (P x / P z ^ 2) (P y / P z ^ 3) (-n / (P z * d)) = (-n * (n ^ 2 - W.a₁ * n * P z * d - W.a₂ * P z ^ 2 * d ^ 2 - 2 * P x * d ^ 2 - P x * d ^ 2) + P y * d ^ 3) / (P z * d) ^ 3 := by rw [Affine.negAddY, toAffine_addX_of_eq hPz hd] field_simp [mul_ne_zero (pow_ne_zero 2 <| mul_ne_zero hPz hd) <| pow_ne_zero 2 hPz] ring1 lemma negDblY_of_Z_ne_zero [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W.negY Q * P z ^ 3) : W.negDblY P / W.dblZ P ^ 3 = W.toAffine.negAddY (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)) := by rw [negDblY, dblX, toAffine_slope_of_eq hP hQ hPz hQz hx hy, dblZ, ← (X_eq_iff hPz hQz).mp hx, toAffine_negAddY_of_eq hPz <| sub_ne_zero.mpr <| Y_ne_negY_of_Y_ne' hP hQ hx hy] variable (W') in /-- The `Y`-coordinate of a representative of `2 • P` for a Jacobian point representative `P` on a Weierstrass curve. -/ noncomputable def dblY (P : Fin 3 → R) : R := W'.negY ![W'.dblX P, W'.negDblY P, W'.dblZ P] lemma dblY_smul (P : Fin 3 → R) (u : R) : W'.dblY (u • P) = (u ^ 4) ^ 3 * W'.dblY P := by simp only [dblY, negY_eq, negDblY_smul, dblX_smul, dblZ_smul] ring1 lemma dblY_of_Z_eq_zero {P : Fin 3 → R} (hP : W'.Equation P) (hPz : P z = 0) : W'.dblY P = (P x ^ 2) ^ 3 := by rw [dblY, negY_eq, negDblY_of_Z_eq_zero hP hPz, dblZ_of_Z_eq_zero hPz] ring1 lemma dblY_of_Y_eq [NoZeroDivisors R] {P Q : Fin 3 → R} (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W'.negY Q * P z ^ 3) : W'.dblY P = W'.dblU P ^ 3 := by rw [dblY, negY_eq, negDblY_of_Y_eq hQz hx hy hy', dblZ_of_Y_eq hQz hx hy hy'] ring1 lemma dblY_of_Z_ne_zero [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W.negY Q * P z ^ 3) : W.dblY P / W.dblZ P ^ 3 = W.toAffine.addY (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)) := by erw [dblY, negY_of_Z_ne_zero <| dblZ_ne_zero_of_Y_ne' hP hQ hPz hx hy, dblX_of_Z_ne_zero hP hQ hPz hQz hx hy, negDblY_of_Z_ne_zero hP hQ hPz hQz hx hy, Affine.addY] variable (W') in /-- The coordinates of a representative of `2 • P` for a Jacobian point representative `P` on a Weierstrass curve. -/ noncomputable def dblXYZ (P : Fin 3 → R) : Fin 3 → R := ![W'.dblX P, W'.dblY P, W'.dblZ P] lemma dblXYZ_X (P : Fin 3 → R) : W'.dblXYZ P x = W'.dblX P := rfl lemma dblXYZ_Y (P : Fin 3 → R) : W'.dblXYZ P y = W'.dblY P := rfl lemma dblXYZ_Z (P : Fin 3 → R) : W'.dblXYZ P z = W'.dblZ P := rfl lemma dblXYZ_smul (P : Fin 3 → R) (u : R) : W'.dblXYZ (u • P) = u ^ 4 • W'.dblXYZ P := by rw [dblXYZ, dblX_smul, dblY_smul, dblZ_smul, smul_fin3, dblXYZ_X, dblXYZ_Y, dblXYZ_Z] lemma dblXYZ_of_Z_eq_zero {P : Fin 3 → R} (hP : W'.Equation P) (hPz : P z = 0) : W'.dblXYZ P = P x ^ 2 • ![1, 1, 0] := by erw [dblXYZ, dblX_of_Z_eq_zero hP hPz, dblY_of_Z_eq_zero hP hPz, dblZ_of_Z_eq_zero hPz, smul_fin3, mul_one, mul_one, mul_zero] lemma dblXYZ_of_Y_eq' [NoZeroDivisors R] {P Q : Fin 3 → R} (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W'.negY Q * P z ^ 3) : W'.dblXYZ P = ![W'.dblU P ^ 2, W'.dblU P ^ 3, 0] := by rw [dblXYZ, dblX_of_Y_eq hQz hx hy hy', dblY_of_Y_eq hQz hx hy hy', dblZ_of_Y_eq hQz hx hy hy'] lemma dblXYZ_of_Y_eq {P Q : Fin 3 → F} (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 = Q y * P z ^ 3) (hy' : P y * Q z ^ 3 = W.negY Q * P z ^ 3) : W.dblXYZ P = W.dblU P • ![1, 1, 0] := by erw [dblXYZ_of_Y_eq' hQz hx hy hy', smul_fin3, mul_one, mul_one, mul_zero] lemma dblXYZ_of_Z_ne_zero [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) (hy : P y * Q z ^ 3 ≠ W.negY Q * P z ^ 3) : W.dblXYZ P = W.dblZ P • ![W.toAffine.addX (P x / P z ^ 2) (Q x / Q z ^ 2) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)), W.toAffine.addY (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)), 1] := by have hZ {n : ℕ} : IsUnit <| W.dblZ P ^ n := (isUnit_dblZ_of_Y_ne' hP hQ hPz hx hy).pow n erw [dblXYZ, smul_fin3, ← dblX_of_Z_ne_zero hP hQ hPz hQz hx hy, hZ.mul_div_cancel, ← dblY_of_Z_ne_zero hP hQ hPz hQz hx hy, hZ.mul_div_cancel, mul_one] /-! ## Addition formulae in Jacobian coordinates -/ /-- The unit associated to a representative of `P + Q` for two Jacobian point representatives `P` and `Q` on a Weierstrass curve `W` that are not `2`-torsion. More specifically, the unit `u` such that `W.add P Q = u • ![1, 1, 0]` where `P x / P z ^ 2 = Q x / Q z ^ 2` but `P ≠ W.neg P`. -/ def addU (P Q : Fin 3 → F) : F := -((P y * Q z ^ 3 - Q y * P z ^ 3) / (P z * Q z)) lemma addU_smul {P Q : Fin 3 → F} (hPz : P z ≠ 0) (hQz : Q z ≠ 0) {u v : F} (hu : u ≠ 0) (hv : v ≠ 0) : addU (u • P) (v • Q) = (u * v) ^ 2 * addU P Q := by field_simp [addU, smul_fin3_ext] ring1 lemma addU_of_Z_eq_zero_left {P Q : Fin 3 → F} (hPz : P z = 0) : addU P Q = 0 := by rw [addU, hPz, zero_mul, div_zero, neg_zero] lemma addU_of_Z_eq_zero_right {P Q : Fin 3 → F} (hQz : Q z = 0) : addU P Q = 0 := by rw [addU, hQz, mul_zero, div_zero, neg_zero] lemma addU_ne_zero_of_Y_ne {P Q : Fin 3 → F} (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hy : P y * Q z ^ 3 ≠ Q y * P z ^ 3) : addU P Q ≠ 0 := neg_ne_zero.mpr <| div_ne_zero (sub_ne_zero.mpr hy) <| mul_ne_zero hPz hQz lemma isUnit_addU_of_Y_ne {P Q : Fin 3 → F} (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hy : P y * Q z ^ 3 ≠ Q y * P z ^ 3) : IsUnit (addU P Q) := (addU_ne_zero_of_Y_ne hPz hQz hy).isUnit /-- The `Z`-coordinate of a representative of `P + Q` for two distinct Jacobian point representatives `P` and `Q` on a Weierstrass curve. If the representatives of `P` and `Q` are equal, then this returns the value `0`. -/ def addZ (P Q : Fin 3 → R) : R := P x * Q z ^ 2 - Q x * P z ^ 2 lemma addZ_smul (P Q : Fin 3 → R) (u v : R) : addZ (u • P) (v • Q) = (u * v) ^ 2 * addZ P Q := by simp only [addZ, smul_fin3_ext] ring1 lemma addZ_self (P : Fin 3 → R) : addZ P P = 0 := sub_self <| P x * P z ^ 2 lemma addZ_of_Z_eq_zero_left {P Q : Fin 3 → R} (hPz : P z = 0) : addZ P Q = P x * Q z * Q z := by rw [addZ, hPz] ring1 lemma addZ_of_Z_eq_zero_right {P Q : Fin 3 → R} (hQz : Q z = 0) : addZ P Q = -(Q x * P z) * P z := by rw [addZ, hQz] ring1 lemma addZ_of_X_eq {P Q : Fin 3 → R} (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : addZ P Q = 0 := by rw [addZ, hx, sub_self] lemma addZ_ne_zero_of_X_ne {P Q : Fin 3 → R} (hx : P x * Q z ^ 2 ≠ Q x * P z ^ 2) : addZ P Q ≠ 0 := sub_ne_zero.mpr hx lemma isUnit_addZ_of_X_ne {P Q : Fin 3 → F} (hx : P x * Q z ^ 2 ≠ Q x * P z ^ 2) : IsUnit <| addZ P Q := (addZ_ne_zero_of_X_ne hx).isUnit private lemma toAffine_slope_of_ne [DecidableEq F] {P Q : Fin 3 → F} (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 ≠ Q x * P z ^ 2) : W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3) = (P y * Q z ^ 3 - Q y * P z ^ 3) / (P z * Q z * addZ P Q) := by rw [Affine.slope_of_X_ne <| by rwa [ne_eq, ← X_eq_iff hPz hQz], div_sub_div _ _ (pow_ne_zero 2 hPz) (pow_ne_zero 2 hQz), mul_comm <| _ ^ 2, addZ] field_simp [mul_ne_zero (mul_ne_zero hPz hQz) <| sub_ne_zero.mpr hx, mul_ne_zero (mul_ne_zero (pow_ne_zero 3 hPz) (pow_ne_zero 3 hQz)) <| sub_ne_zero.mpr hx] ring1 variable (W') in /-- The `X`-coordinate of a representative of `P + Q` for two distinct Jacobian point representatives `P` and `Q` on a Weierstrass curve. If the representatives of `P` and `Q` are equal, then this returns the value `0`. -/ def addX (P Q : Fin 3 → R) : R := P x * Q x ^ 2 * P z ^ 2 - 2 * P y * Q y * P z * Q z + P x ^ 2 * Q x * Q z ^ 2 - W'.a₁ * P x * Q y * P z ^ 2 * Q z - W'.a₁ * P y * Q x * P z * Q z ^ 2 + 2 * W'.a₂ * P x * Q x * P z ^ 2 * Q z ^ 2 - W'.a₃ * Q y * P z ^ 4 * Q z - W'.a₃ * P y * P z * Q z ^ 4 + W'.a₄ * Q x * P z ^ 4 * Q z ^ 2 + W'.a₄ * P x * P z ^ 2 * Q z ^ 4 + 2 * W'.a₆ * P z ^ 4 * Q z ^ 4 lemma addX_eq' {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) : W'.addX P Q * (P z * Q z) ^ 2 = (P y * Q z ^ 3 - Q y * P z ^ 3) ^ 2 + W'.a₁ * (P y * Q z ^ 3 - Q y * P z ^ 3) * P z * Q z * addZ P Q - W'.a₂ * P z ^ 2 * Q z ^ 2 * addZ P Q ^ 2 - P x * Q z ^ 2 * addZ P Q ^ 2 - Q x * P z ^ 2 * addZ P Q ^ 2 := by linear_combination (norm := (rw [addX, addZ]; ring1)) -Q z ^ 6 * (equation_iff P).mp hP - P z ^ 6 * (equation_iff Q).mp hQ lemma addX_eq {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) : W.addX P Q = ((P y * Q z ^ 3 - Q y * P z ^ 3) ^ 2 + W.a₁ * (P y * Q z ^ 3 - Q y * P z ^ 3) * P z * Q z * addZ P Q - W.a₂ * P z ^ 2 * Q z ^ 2 * addZ P Q ^ 2 - P x * Q z ^ 2 * addZ P Q ^ 2 - Q x * P z ^ 2 * addZ P Q ^ 2) / (P z * Q z) ^ 2 := by rw [← addX_eq' hP hQ, mul_div_cancel_right₀ _ <| pow_ne_zero 2 <| mul_ne_zero hPz hQz] lemma addX_smul (P Q : Fin 3 → R) (u v : R) : W'.addX (u • P) (v • Q) = ((u * v) ^ 2) ^ 2 * W'.addX P Q := by simp only [addX, smul_fin3_ext] ring1 lemma addX_self {P : Fin 3 → R} (hP : W'.Equation P) : W'.addX P P = 0 := by linear_combination (norm := (rw [addX]; ring1)) -2 * P z ^ 2 * (equation_iff _).mp hP lemma addX_of_Z_eq_zero_left {P Q : Fin 3 → R} (hPz : P z = 0) : W'.addX P Q = (P x * Q z) ^ 2 * Q x := by rw [addX, hPz] ring1 lemma addX_of_Z_eq_zero_right {P Q : Fin 3 → R} (hQz : Q z = 0) : W'.addX P Q = (-(Q x * P z)) ^ 2 * P x := by rw [addX, hQz] ring1 lemma addX_of_X_eq' {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : W'.addX P Q * (P z * Q z) ^ 2 = (P y * Q z ^ 3 - Q y * P z ^ 3) ^ 2 := by rw [addX_eq' hP hQ, addZ_of_X_eq hx] ring1 lemma addX_of_X_eq {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : W.addX P Q = addU P Q ^ 2 := by rw [addU, neg_sq, div_pow, ← addX_of_X_eq' hP hQ hx, mul_div_cancel_right₀ _ <| pow_ne_zero 2 <| mul_ne_zero hPz hQz] private lemma toAffine_addX_of_ne {P Q : Fin 3 → F} (hPz : P z ≠ 0) (hQz : Q z ≠ 0) {n d : F} (hd : d ≠ 0) : W.toAffine.addX (P x / P z ^ 2) (Q x / Q z ^ 2) (n / (P z * Q z * d)) = (n ^ 2 + W.a₁ * n * P z * Q z * d - W.a₂ * P z ^ 2 * Q z ^ 2 * d ^ 2 - P x * Q z ^ 2 * d ^ 2 - Q x * P z ^ 2 * d ^ 2) / (P z * Q z) ^ 2 / d ^ 2 := by field_simp [mul_ne_zero (mul_ne_zero hPz hQz) hd] ring1 lemma addX_of_Z_ne_zero [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 ≠ Q x * P z ^ 2) : W.addX P Q / addZ P Q ^ 2 = W.toAffine.addX (P x / P z ^ 2) (Q x / Q z ^ 2) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)) := by rw [addX_eq hP hQ hPz hQz, toAffine_slope_of_ne hPz hQz hx, toAffine_addX_of_ne hPz hQz <| addZ_ne_zero_of_X_ne hx] variable (W') in /-- The `Y`-coordinate of a representative of `-(P + Q)` for two distinct Jacobian point representatives `P` and `Q` on a Weierstrass curve. If the representatives of `P` and `Q` are equal, then this returns the value `0`. -/ def negAddY (P Q : Fin 3 → R) : R := -P y * Q x ^ 3 * P z ^ 3 + 2 * P y * Q y ^ 2 * P z ^ 3 - 3 * P x ^ 2 * Q x * Q y * P z ^ 2 * Q z + 3 * P x * P y * Q x ^ 2 * P z * Q z ^ 2 + P x ^ 3 * Q y * Q z ^ 3 - 2 * P y ^ 2 * Q y * Q z ^ 3 + W'.a₁ * P x * Q y ^ 2 * P z ^ 4 + W'.a₁ * P y * Q x * Q y * P z ^ 3 * Q z - W'.a₁ * P x * P y * Q y * P z * Q z ^ 3 - W'.a₁ * P y ^ 2 * Q x * Q z ^ 4 - 2 * W'.a₂ * P x * Q x * Q y * P z ^ 4 * Q z + 2 * W'.a₂ * P x * P y * Q x * P z * Q z ^ 4 + W'.a₃ * Q y ^ 2 * P z ^ 6 - W'.a₃ * P y ^ 2 * Q z ^ 6 - W'.a₄ * Q x * Q y * P z ^ 6 * Q z - W'.a₄ * P x * Q y * P z ^ 4 * Q z ^ 3 + W'.a₄ * P y * Q x * P z ^ 3 * Q z ^ 4 + W'.a₄ * P x * P y * P z * Q z ^ 6 - 2 * W'.a₆ * Q y * P z ^ 6 * Q z ^ 3 + 2 * W'.a₆ * P y * P z ^ 3 * Q z ^ 6 lemma negAddY_eq' (P Q : Fin 3 → R) : W'.negAddY P Q * (P z * Q z) ^ 3 = (P y * Q z ^ 3 - Q y * P z ^ 3) * (W'.addX P Q * (P z * Q z) ^ 2 - P x * Q z ^ 2 * addZ P Q ^ 2) + P y * Q z ^ 3 * addZ P Q ^ 3 := by rw [negAddY, addX, addZ] ring1 lemma negAddY_eq {P Q : Fin 3 → F} (hPz : P z ≠ 0) (hQz : Q z ≠ 0) : W.negAddY P Q = ((P y * Q z ^ 3 - Q y * P z ^ 3) * (W.addX P Q * (P z * Q z) ^ 2 - P x * Q z ^ 2 * addZ P Q ^ 2) + P y * Q z ^ 3 * addZ P Q ^ 3) / (P z * Q z) ^ 3 := by rw [← negAddY_eq', mul_div_cancel_right₀ _ <| pow_ne_zero 3 <| mul_ne_zero hPz hQz] lemma negAddY_smul (P Q : Fin 3 → R) (u v : R) : W'.negAddY (u • P) (v • Q) = ((u * v) ^ 2) ^ 3 * W'.negAddY P Q := by simp only [negAddY, smul_fin3_ext] ring1 lemma negAddY_self (P : Fin 3 → R) : W'.negAddY P P = 0 := by rw [negAddY] ring1 lemma negAddY_of_Z_eq_zero_left {P Q : Fin 3 → R} (hP : W'.Equation P) (hPz : P z = 0) : W'.negAddY P Q = (P x * Q z) ^ 3 * W'.negY Q := by linear_combination (norm := (rw [negAddY, negY, hPz]; ring1)) (W'.negY Q - Q y) * Q z ^ 3 * (equation_of_Z_eq_zero hPz).mp hP lemma negAddY_of_Z_eq_zero_right {P Q : Fin 3 → R} (hQ : W'.Equation Q) (hQz : Q z = 0) : W'.negAddY P Q = (-(Q x * P z)) ^ 3 * W'.negY P := by linear_combination (norm := (rw [negAddY, negY, hQz]; ring1)) (P y - W'.negY P) * P z ^ 3 * (equation_of_Z_eq_zero hQz).mp hQ lemma negAddY_of_X_eq' {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : W'.negAddY P Q * (P z * Q z) ^ 3 = (P y * Q z ^ 3 - Q y * P z ^ 3) ^ 3 := by rw [negAddY_eq', addX_eq' hP hQ, addZ_of_X_eq hx] ring1 lemma negAddY_of_X_eq {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : W.negAddY P Q = (-addU P Q) ^ 3 := by rw [addU, neg_neg, div_pow, ← negAddY_of_X_eq' hP hQ hx, mul_div_cancel_right₀ _ <| pow_ne_zero 3 <| mul_ne_zero hPz hQz] private lemma toAffine_negAddY_of_ne {P Q : Fin 3 → F} (hPz : P z ≠ 0) (hQz : Q z ≠ 0) {n d : F} (hd : d ≠ 0) : W.toAffine.negAddY (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (n / (P z * Q z * d)) = (n * (n ^ 2 + W.a₁ * n * P z * Q z * d - W.a₂ * P z ^ 2 * Q z ^ 2 * d ^ 2 - P x * Q z ^ 2 * d ^ 2 - Q x * P z ^ 2 * d ^ 2 - P x * Q z ^ 2 * d ^ 2) + P y * Q z ^ 3 * d ^ 3) / (P z * Q z) ^ 3 / d ^ 3 := by rw [Affine.negAddY, toAffine_addX_of_ne hPz hQz hd] field_simp [mul_ne_zero (mul_ne_zero hPz hQz) hd, mul_ne_zero (mul_ne_zero (pow_ne_zero 2 <| mul_ne_zero hPz hQz) <| pow_ne_zero 2 hd) <| pow_ne_zero 2 hPz] ring1 lemma negAddY_of_Z_ne_zero [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 ≠ Q x * P z ^ 2) : W.negAddY P Q / addZ P Q ^ 3 = W.toAffine.negAddY (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)) := by rw [negAddY_eq hPz hQz, addX_eq' hP hQ, toAffine_slope_of_ne hPz hQz hx, toAffine_negAddY_of_ne hPz hQz <| addZ_ne_zero_of_X_ne hx] variable (W') in /-- The `Y`-coordinate of a representative of `P + Q` for two distinct Jacobian point representatives `P` and `Q` on a Weierstrass curve. If the representatives of `P` and `Q` are equal, then this returns the value `0`. -/ def addY (P Q : Fin 3 → R) : R := W'.negY ![W'.addX P Q, W'.negAddY P Q, addZ P Q] lemma addY_smul (P Q : Fin 3 → R) (u v : R) : W'.addY (u • P) (v • Q) = ((u * v) ^ 2) ^ 3 * W'.addY P Q := by simp only [addY, negY_eq, negAddY_smul, addX_smul, addZ_smul] ring1 lemma addY_self {P : Fin 3 → R} (hP : W'.Equation P) : W'.addY P P = 0 := by rw [addY, negY_eq, addX_self hP, negAddY_self, addZ_self] ring1 lemma addY_of_Z_eq_zero_left {P Q : Fin 3 → R} (hP : W'.Equation P) (hPz : P z = 0) : W'.addY P Q = (P x * Q z) ^ 3 * Q y := by rw [addY, negY_eq, negAddY_of_Z_eq_zero_left hP hPz, negY, addX_of_Z_eq_zero_left hPz, addZ_of_Z_eq_zero_left hPz] ring1 lemma addY_of_Z_eq_zero_right {P Q : Fin 3 → R} (hQ : W'.Equation Q) (hQz : Q z = 0) : W'.addY P Q = (-(Q x * P z)) ^ 3 * P y := by rw [addY, negY_eq, negAddY_of_Z_eq_zero_right hQ hQz, negY, addX_of_Z_eq_zero_right hQz, addZ_of_Z_eq_zero_right hQz] ring1 lemma addY_of_X_eq' {P Q : Fin 3 → R} (hP : W'.Equation P) (hQ : W'.Equation Q) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : W'.addY P Q * (P z * Q z) ^ 3 = (-(P y * Q z ^ 3 - Q y * P z ^ 3)) ^ 3 := by linear_combination (norm := (rw [addY, negY_eq, addZ_of_X_eq hx]; ring1)) -negAddY_of_X_eq' hP hQ hx lemma addY_of_X_eq {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : W.addY P Q = addU P Q ^ 3 := by rw [addU, ← neg_div, div_pow, ← addY_of_X_eq' hP hQ hx, mul_div_cancel_right₀ _ <| pow_ne_zero 3 <| mul_ne_zero hPz hQz] lemma addY_of_Z_ne_zero [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 ≠ Q x * P z ^ 2) : W.addY P Q / addZ P Q ^ 3 = W.toAffine.addY (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)) := by erw [addY, negY_of_Z_ne_zero <| addZ_ne_zero_of_X_ne hx, addX_of_Z_ne_zero hP hQ hPz hQz hx, negAddY_of_Z_ne_zero hP hQ hPz hQz hx, Affine.addY] variable (W') in /-- The coordinates of a representative of `P + Q` for two distinct Jacobian point representatives `P` and `Q` on a Weierstrass curve. If the representatives of `P` and `Q` are equal, then this returns the value `![0, 0, 0]`. -/ noncomputable def addXYZ (P Q : Fin 3 → R) : Fin 3 → R := ![W'.addX P Q, W'.addY P Q, addZ P Q] lemma addXYZ_X (P Q : Fin 3 → R) : W'.addXYZ P Q x = W'.addX P Q := rfl lemma addXYZ_Y (P Q : Fin 3 → R) : W'.addXYZ P Q y = W'.addY P Q := rfl lemma addXYZ_Z (P Q : Fin 3 → R) : W'.addXYZ P Q z = addZ P Q := rfl lemma addXYZ_smul (P Q : Fin 3 → R) (u v : R) : W'.addXYZ (u • P) (v • Q) = (u * v) ^ 2 • W'.addXYZ P Q := by rw [addXYZ, addX_smul, addY_smul, addZ_smul, smul_fin3, addXYZ_X, addXYZ_Y, addXYZ_Z] lemma addXYZ_self {P : Fin 3 → R} (hP : W'.Equation P) : W'.addXYZ P P = ![0, 0, 0] := by rw [addXYZ, addX_self hP, addY_self hP, addZ_self] lemma addXYZ_of_Z_eq_zero_left {P Q : Fin 3 → R} (hP : W'.Equation P) (hPz : P z = 0) : W'.addXYZ P Q = (P x * Q z) • Q := by rw [addXYZ, addX_of_Z_eq_zero_left hPz, addY_of_Z_eq_zero_left hP hPz, addZ_of_Z_eq_zero_left hPz, smul_fin3] lemma addXYZ_of_Z_eq_zero_right {P Q : Fin 3 → R} (hQ : W'.Equation Q) (hQz : Q z = 0) : W'.addXYZ P Q = -(Q x * P z) • P := by rw [addXYZ, addX_of_Z_eq_zero_right hQz, addY_of_Z_eq_zero_right hQ hQz, addZ_of_Z_eq_zero_right hQz, smul_fin3] lemma addXYZ_of_X_eq {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 = Q x * P z ^ 2) : W.addXYZ P Q = addU P Q • ![1, 1, 0] := by erw [addXYZ, addX_of_X_eq hP hQ hPz hQz hx, addY_of_X_eq hP hQ hPz hQz hx, addZ_of_X_eq hx, smul_fin3, mul_one, mul_one, mul_zero] lemma addXYZ_of_Z_ne_zero [DecidableEq F] {P Q : Fin 3 → F} (hP : W.Equation P) (hQ : W.Equation Q) (hPz : P z ≠ 0) (hQz : Q z ≠ 0) (hx : P x * Q z ^ 2 ≠ Q x * P z ^ 2) : W.addXYZ P Q = addZ P Q • ![W.toAffine.addX (P x / P z ^ 2) (Q x / Q z ^ 2) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)), W.toAffine.addY (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (W.toAffine.slope (P x / P z ^ 2) (Q x / Q z ^ 2) (P y / P z ^ 3) (Q y / Q z ^ 3)), 1] := by have hZ {n : ℕ} : IsUnit <| addZ P Q ^ n := (isUnit_addZ_of_X_ne hx).pow n erw [addXYZ, smul_fin3, ← addX_of_Z_ne_zero hP hQ hPz hQz hx, hZ.mul_div_cancel, ← addY_of_Z_ne_zero hP hQ hPz hQz hx, hZ.mul_div_cancel, mul_one] /-! ## Maps and base changes -/ variable (f : R →+* S) (P Q : Fin 3 → R) @[simp] lemma map_negY : (W'.map f).toJacobian.negY (f ∘ P) = f (W'.negY P) := by simp only [negY] map_simp @[simp] lemma map_dblU : (W'.map f).toJacobian.dblU (f ∘ P) = f (W'.dblU P) := by simp only [dblU_eq] map_simp @[simp] lemma map_dblZ : (W'.map f).toJacobian.dblZ (f ∘ P) = f (W'.dblZ P) := by simp only [dblZ, negY] map_simp @[simp] lemma map_dblX : (W'.map f).toJacobian.dblX (f ∘ P) = f (W'.dblX P) := by simp only [dblX, map_dblU, map_negY] map_simp @[simp] lemma map_negDblY : (W'.map f).toJacobian.negDblY (f ∘ P) = f (W'.negDblY P) := by simp only [negDblY, map_dblU, map_dblX, map_negY] simp @[simp] lemma map_dblY : (W'.map f).toJacobian.dblY (f ∘ P) = f (W'.dblY P) := by simp only [dblY, negY_eq, map_negDblY, map_dblX, map_dblZ] map_simp @[simp] lemma map_dblXYZ : (W'.map f).toJacobian.dblXYZ (f ∘ P) = f ∘ dblXYZ W' P := by simp only [dblXYZ, map_dblX, map_dblY, map_dblZ, comp_fin3] @[simp] lemma map_addU (f : F →+* K) (P Q : Fin 3 → F) : addU (f ∘ P) (f ∘ Q) = f (addU P Q) := by simp only [addU] map_simp @[simp] lemma map_addZ : addZ (f ∘ P) (f ∘ Q) = f (addZ P Q) := by simp only [addZ] map_simp @[simp] lemma map_addX : (W'.map f).toJacobian.addX (f ∘ P) (f ∘ Q) = f (W'.addX P Q) := by simp only [addX] map_simp @[simp] lemma map_negAddY : (W'.map f).toJacobian.negAddY (f ∘ P) (f ∘ Q) = f (W'.negAddY P Q) := by simp only [negAddY] map_simp @[simp] lemma map_addY : (W'.map f).toJacobian.addY (f ∘ P) (f ∘ Q) = f (W'.addY P Q) := by simp only [addY, negY_eq, map_negAddY, map_addX, map_addZ] map_simp @[simp] lemma map_addXYZ : (W'.map f).toJacobian.addXYZ (f ∘ P) (f ∘ Q) = f ∘ addXYZ W' P Q := by simp only [addXYZ, map_addX, map_addY, map_addZ, comp_fin3] variable [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [Algebra R B] [Algebra S B] [IsScalarTower R S B] (f : A →ₐ[S] B) (P Q : Fin 3 → A) lemma baseChange_negY : (W'.baseChange B).toJacobian.negY (f ∘ P) = f ((W'.baseChange A).toJacobian.negY P) := by rw [← RingHom.coe_coe, ← map_negY, map_baseChange] lemma baseChange_dblU : (W'.baseChange B).toJacobian.dblU (f ∘ P) = f ((W'.baseChange A).toJacobian.dblU P) := by rw [← RingHom.coe_coe, ← map_dblU, map_baseChange] lemma baseChange_dblZ : (W'.baseChange B).toJacobian.dblZ (f ∘ P) = f ((W'.baseChange A).toJacobian.dblZ P) := by rw [← RingHom.coe_coe, ← map_dblZ, map_baseChange] lemma baseChange_dblX : (W'.baseChange B).toJacobian.dblX (f ∘ P) = f ((W'.baseChange A).toJacobian.dblX P) := by rw [← RingHom.coe_coe, ← map_dblX, map_baseChange] lemma baseChange_negDblY : (W'.baseChange B).toJacobian.negDblY (f ∘ P) = f ((W'.baseChange A).toJacobian.negDblY P) := by rw [← RingHom.coe_coe, ← map_negDblY, map_baseChange] lemma baseChange_dblY : (W'.baseChange B).toJacobian.dblY (f ∘ P) = f ((W'.baseChange A).toJacobian.dblY P) := by rw [← RingHom.coe_coe, ← map_dblY, map_baseChange] lemma baseChange_dblXYZ : (W'.baseChange B).toJacobian.dblXYZ (f ∘ P) = f ∘ (W'.baseChange A).toJacobian.dblXYZ P := by rw [← RingHom.coe_coe, ← map_dblXYZ, map_baseChange] lemma baseChange_addX : (W'.baseChange B).toJacobian.addX (f ∘ P) (f ∘ Q) = f ((W'.baseChange A).toJacobian.addX P Q) := by rw [← RingHom.coe_coe, ← map_addX, map_baseChange] lemma baseChange_negAddY : (W'.baseChange B).toJacobian.negAddY (f ∘ P) (f ∘ Q) = f ((W'.baseChange A).toJacobian.negAddY P Q) := by rw [← RingHom.coe_coe, ← map_negAddY, map_baseChange] lemma baseChange_addY : (W'.baseChange B).toJacobian.addY (f ∘ P) (f ∘ Q) = f ((W'.baseChange A).toJacobian.addY P Q) := by rw [← RingHom.coe_coe, ← map_addY, map_baseChange] lemma baseChange_addXYZ : (W'.baseChange B).toJacobian.addXYZ (f ∘ P) (f ∘ Q) = f ∘ (W'.baseChange A).toJacobian.addXYZ P Q := by rw [← RingHom.coe_coe, ← map_addXYZ, map_baseChange] end Jacobian end WeierstrassCurve
VitaliCaratheodory.lean
/- Copyright (c) 2021 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.Regular import Mathlib.Topology.Semicontinuous import Mathlib.MeasureTheory.Integral.Bochner.Basic import Mathlib.Topology.Instances.EReal.Lemmas /-! # Vitali-Carathéodory theorem Vitali-Carathéodory theorem asserts the following. Consider an integrable function `f : α → ℝ` on a space with a regular measure. Then there exists a function `g : α → EReal` such that `f x < g x` everywhere, `g` is lower semicontinuous, and the integral of `g` is arbitrarily close to that of `f`. This theorem is proved in this file, as `exists_lt_lower_semicontinuous_integral_lt`. Symmetrically, there exists `g < f` which is upper semicontinuous, with integral arbitrarily close to that of `f`. It follows from the previous statement applied to `-f`. It is formalized under the name `exists_upper_semicontinuous_lt_integral_gt`. The most classical version of Vitali-Carathéodory theorem only ensures a large inequality `f x ≤ g x`. For applications to the fundamental theorem of calculus, though, the strict inequality `f x < g x` is important. Therefore, we prove the stronger version with strict inequalities in this file. There is a price to pay: we require that the measure is `σ`-finite, which is not necessary for the classical Vitali-Carathéodory theorem. Since this is satisfied in all applications, this is not a real problem. ## Sketch of proof Decomposing `f` as the difference of its positive and negative parts, it suffices to show that a positive function can be bounded from above by a lower semicontinuous function, and from below by an upper semicontinuous function, with integrals close to that of `f`. For the bound from above, write `f` as a series `∑' n, cₙ * indicator (sₙ)` of simple functions. Then, approximate `sₙ` by a larger open set `uₙ` with measure very close to that of `sₙ` (this is possible by regularity of the measure), and set `g = ∑' n, cₙ * indicator (uₙ)`. It is lower semicontinuous as a series of lower semicontinuous functions, and its integral is arbitrarily close to that of `f`. For the bound from below, use finitely many terms in the series, and approximate `sₙ` from inside by a closed set `Fₙ`. Then `∑ n < N, cₙ * indicator (Fₙ)` is bounded from above by `f`, it is upper semicontinuous as a finite sum of upper semicontinuous functions, and its integral is arbitrarily close to that of `f`. The main pain point in the implementation is that one needs to jump between the spaces `ℝ`, `ℝ≥0`, `ℝ≥0∞` and `EReal` (and be careful that addition is not well behaved on `EReal`), and between `lintegral` and `integral`. We first show the bound from above for simple functions and the nonnegative integral (this is the main nontrivial mathematical point), then deduce it for general nonnegative functions, first for the nonnegative integral and then for the Bochner integral. Then we follow the same steps for the lower bound. Finally, we glue them together to obtain the main statement `exists_lt_lower_semicontinuous_integral_lt`. ## Related results Are you looking for a result on approximation by continuous functions (not just semicontinuous)? See result `MeasureTheory.Lp.boundedContinuousFunction_dense`, in the file `Mathlib/MeasureTheory/Function/ContinuousMapDense.lean`. ## References [Rudin, *Real and Complex Analysis* (Theorem 2.24)][rudin2006real] -/ open scoped ENNReal NNReal open MeasureTheory MeasureTheory.Measure variable {α : Type*} [TopologicalSpace α] [MeasurableSpace α] [BorelSpace α] (μ : Measure α) [WeaklyRegular μ] namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc /-! ### Lower semicontinuous upper bound for nonnegative functions -/ /-- Given a simple function `f` with values in `ℝ≥0`, there exists a lower semicontinuous function `g ≥ f` with integral arbitrarily close to that of `f`. Formulation in terms of `lintegral`. Auxiliary lemma for Vitali-Carathéodory theorem `exists_lt_lower_semicontinuous_integral_lt`. -/ theorem SimpleFunc.exists_le_lowerSemicontinuous_lintegral_ge (f : α →ₛ ℝ≥0) {ε : ℝ≥0∞} (ε0 : ε ≠ 0) : ∃ g : α → ℝ≥0, (∀ x, f x ≤ g x) ∧ LowerSemicontinuous g ∧ (∫⁻ x, g x ∂μ) ≤ (∫⁻ x, f x ∂μ) + ε := by induction f using MeasureTheory.SimpleFunc.induction generalizing ε with | @const c s hs => let f := SimpleFunc.piecewise s hs (SimpleFunc.const α c) (SimpleFunc.const α 0) by_cases h : ∫⁻ x, f x ∂μ = ⊤ · refine ⟨fun _ => c, fun x => ?_, lowerSemicontinuous_const, by simp only [f, _root_.top_add, le_top, h]⟩ simp only [SimpleFunc.coe_const, SimpleFunc.const_zero, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, SimpleFunc.coe_piecewise] exact Set.indicator_le_self _ _ _ by_cases hc : c = 0 · refine ⟨fun _ => 0, ?_, lowerSemicontinuous_const, ?_⟩ · classical simp only [hc, Set.indicator_zero', Pi.zero_apply, SimpleFunc.const_zero, imp_true_iff, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, SimpleFunc.coe_piecewise, le_zero_iff] · simp only [lintegral_const, zero_mul, zero_le, ENNReal.coe_zero] have ne_top : μ s ≠ ⊤ := by classical simpa [f, hs, hc, lt_top_iff_ne_top, SimpleFunc.coe_const, Function.const_apply, lintegral_const, ENNReal.coe_indicator, Set.univ_inter, ENNReal.coe_ne_top, MeasurableSet.univ, ENNReal.mul_eq_top, SimpleFunc.const_zero, lintegral_indicator, ENNReal.coe_eq_zero, Ne, not_false_iff, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, SimpleFunc.coe_piecewise, restrict_apply] using h have : μ s < μ s + ε / c := by have : (0 : ℝ≥0∞) < ε / c := ENNReal.div_pos_iff.2 ⟨ε0, ENNReal.coe_ne_top⟩ simpa using ENNReal.add_lt_add_left ne_top this obtain ⟨u, su, u_open, μu⟩ : ∃ (u : _), u ⊇ s ∧ IsOpen u ∧ μ u < μ s + ε / c := s.exists_isOpen_lt_of_lt _ this refine ⟨Set.indicator u fun _ => c, fun x => ?_, u_open.lowerSemicontinuous_indicator (zero_le _), ?_⟩ · simp only [SimpleFunc.coe_const, SimpleFunc.const_zero, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, SimpleFunc.coe_piecewise] exact Set.indicator_le_indicator_of_subset su (fun x => zero_le _) _ · suffices (c : ℝ≥0∞) * μ u ≤ c * μ s + ε by classical simpa only [ENNReal.coe_indicator, u_open.measurableSet, lintegral_indicator, lintegral_const, MeasurableSet.univ, Measure.restrict_apply, Set.univ_inter, const_zero, coe_piecewise, coe_const, coe_zero, Set.piecewise_eq_indicator, Function.const_apply, hs] calc (c : ℝ≥0∞) * μ u ≤ c * (μ s + ε / c) := mul_le_mul_left' μu.le _ _ = c * μ s + ε := by simp_rw [mul_add] rw [ENNReal.mul_div_cancel _ ENNReal.coe_ne_top] simpa using hc | @add f₁ f₂ _ h₁ h₂ => rcases h₁ (ENNReal.half_pos ε0).ne' with ⟨g₁, f₁_le_g₁, g₁cont, g₁int⟩ rcases h₂ (ENNReal.half_pos ε0).ne' with ⟨g₂, f₂_le_g₂, g₂cont, g₂int⟩ refine ⟨fun x => g₁ x + g₂ x, fun x => add_le_add (f₁_le_g₁ x) (f₂_le_g₂ x), g₁cont.add g₂cont, ?_⟩ simp only [SimpleFunc.coe_add, ENNReal.coe_add, Pi.add_apply] rw [lintegral_add_left f₁.measurable.coe_nnreal_ennreal, lintegral_add_left g₁cont.measurable.coe_nnreal_ennreal] convert add_le_add g₁int g₂int using 1 conv_lhs => rw [← ENNReal.add_halves ε] abel open SimpleFunc in /-- Given a measurable function `f` with values in `ℝ≥0`, there exists a lower semicontinuous function `g ≥ f` with integral arbitrarily close to that of `f`. Formulation in terms of `lintegral`. Auxiliary lemma for Vitali-Carathéodory theorem `exists_lt_lower_semicontinuous_integral_lt`. -/ theorem exists_le_lowerSemicontinuous_lintegral_ge (f : α → ℝ≥0∞) (hf : Measurable f) {ε : ℝ≥0∞} (εpos : ε ≠ 0) : ∃ g : α → ℝ≥0∞, (∀ x, f x ≤ g x) ∧ LowerSemicontinuous g ∧ (∫⁻ x, g x ∂μ) ≤ (∫⁻ x, f x ∂μ) + ε := by rcases ENNReal.exists_pos_sum_of_countable' εpos ℕ with ⟨δ, δpos, hδ⟩ have : ∀ n, ∃ g : α → ℝ≥0, (∀ x, eapproxDiff f n x ≤ g x) ∧ LowerSemicontinuous g ∧ (∫⁻ x, g x ∂μ) ≤ (∫⁻ x, eapproxDiff f n x ∂μ) + δ n := fun n => SimpleFunc.exists_le_lowerSemicontinuous_lintegral_ge μ (eapproxDiff f n) (δpos n).ne' choose g f_le_g gcont hg using this refine ⟨fun x => ∑' n, g n x, fun x => ?_, ?_, ?_⟩ · rw [← tsum_eapproxDiff f hf] exact ENNReal.tsum_le_tsum fun n => ENNReal.coe_le_coe.2 (f_le_g n x) · refine lowerSemicontinuous_tsum fun n => ?_ exact ENNReal.continuous_coe.comp_lowerSemicontinuous (gcont n) fun x y hxy => ENNReal.coe_le_coe.2 hxy · calc ∫⁻ x, ∑' n : ℕ, g n x ∂μ = ∑' n, ∫⁻ x, g n x ∂μ := by rw [lintegral_tsum fun n => (gcont n).measurable.coe_nnreal_ennreal.aemeasurable] _ ≤ ∑' n, ((∫⁻ x, eapproxDiff f n x ∂μ) + δ n) := ENNReal.tsum_le_tsum hg _ = ∑' n, ∫⁻ x, eapproxDiff f n x ∂μ + ∑' n, δ n := ENNReal.tsum_add _ ≤ (∫⁻ x : α, f x ∂μ) + ε := by refine add_le_add ?_ hδ.le rw [← lintegral_tsum] · simp_rw [tsum_eapproxDiff f hf, le_refl] · intro n; exact (SimpleFunc.measurable _).coe_nnreal_ennreal.aemeasurable /-- Given a measurable function `f` with values in `ℝ≥0` in a sigma-finite space, there exists a lower semicontinuous function `g > f` with integral arbitrarily close to that of `f`. Formulation in terms of `lintegral`. Auxiliary lemma for Vitali-Carathéodory theorem `exists_lt_lower_semicontinuous_integral_lt`. -/ theorem exists_lt_lowerSemicontinuous_lintegral_ge [SigmaFinite μ] (f : α → ℝ≥0) (fmeas : Measurable f) {ε : ℝ≥0∞} (ε0 : ε ≠ 0) : ∃ g : α → ℝ≥0∞, (∀ x, (f x : ℝ≥0∞) < g x) ∧ LowerSemicontinuous g ∧ (∫⁻ x, g x ∂μ) ≤ (∫⁻ x, f x ∂μ) + ε := by have : ε / 2 ≠ 0 := (ENNReal.half_pos ε0).ne' rcases exists_pos_lintegral_lt_of_sigmaFinite μ this with ⟨w, wpos, wmeas, wint⟩ let f' x := ((f x + w x : ℝ≥0) : ℝ≥0∞) rcases exists_le_lowerSemicontinuous_lintegral_ge μ f' (fmeas.add wmeas).coe_nnreal_ennreal this with ⟨g, le_g, gcont, gint⟩ refine ⟨g, fun x => ?_, gcont, ?_⟩ · calc (f x : ℝ≥0∞) < f' x := by simpa only [← ENNReal.coe_lt_coe, add_zero] using add_lt_add_left (wpos x) (f x) _ ≤ g x := le_g x · calc (∫⁻ x : α, g x ∂μ) ≤ (∫⁻ x : α, f x + w x ∂μ) + ε / 2 := gint _ = ((∫⁻ x : α, f x ∂μ) + ∫⁻ x : α, w x ∂μ) + ε / 2 := by rw [lintegral_add_right _ wmeas.coe_nnreal_ennreal] _ ≤ (∫⁻ x : α, f x ∂μ) + ε / 2 + ε / 2 := add_le_add_right (add_le_add_left wint.le _) _ _ = (∫⁻ x : α, f x ∂μ) + ε := by rw [add_assoc, ENNReal.add_halves] /-- Given an almost everywhere measurable function `f` with values in `ℝ≥0` in a sigma-finite space, there exists a lower semicontinuous function `g > f` with integral arbitrarily close to that of `f`. Formulation in terms of `lintegral`. Auxiliary lemma for Vitali-Carathéodory theorem `exists_lt_lower_semicontinuous_integral_lt`. -/ theorem exists_lt_lowerSemicontinuous_lintegral_ge_of_aemeasurable [SigmaFinite μ] (f : α → ℝ≥0) (fmeas : AEMeasurable f μ) {ε : ℝ≥0∞} (ε0 : ε ≠ 0) : ∃ g : α → ℝ≥0∞, (∀ x, (f x : ℝ≥0∞) < g x) ∧ LowerSemicontinuous g ∧ (∫⁻ x, g x ∂μ) ≤ (∫⁻ x, f x ∂μ) + ε := by have : ε / 2 ≠ 0 := (ENNReal.half_pos ε0).ne' rcases exists_lt_lowerSemicontinuous_lintegral_ge μ (fmeas.mk f) fmeas.measurable_mk this with ⟨g0, f_lt_g0, g0_cont, g0_int⟩ rcases exists_measurable_superset_of_null fmeas.ae_eq_mk with ⟨s, hs, smeas, μs⟩ rcases exists_le_lowerSemicontinuous_lintegral_ge μ (s.indicator fun _x => ∞) (measurable_const.indicator smeas) this with ⟨g1, le_g1, g1_cont, g1_int⟩ refine ⟨fun x => g0 x + g1 x, fun x => ?_, g0_cont.add g1_cont, ?_⟩ · by_cases h : x ∈ s · have := le_g1 x simp only [h, Set.indicator_of_mem, top_le_iff] at this simp [this] · have : f x = fmeas.mk f x := by rw [Set.compl_subset_comm] at hs; exact hs h rw [this] exact (f_lt_g0 x).trans_le le_self_add · calc ∫⁻ x, g0 x + g1 x ∂μ = (∫⁻ x, g0 x ∂μ) + ∫⁻ x, g1 x ∂μ := lintegral_add_left g0_cont.measurable _ _ ≤ (∫⁻ x, f x ∂μ) + ε / 2 + (0 + ε / 2) := by refine add_le_add ?_ ?_ · convert g0_int using 2 exact lintegral_congr_ae (fmeas.ae_eq_mk.fun_comp _) · convert g1_int simp only [smeas, μs, lintegral_const, Set.univ_inter, MeasurableSet.univ, lintegral_indicator, mul_zero, restrict_apply] _ = (∫⁻ x, f x ∂μ) + ε := by simp only [add_assoc, ENNReal.add_halves, zero_add] variable {μ} /-- Given an integrable function `f` with values in `ℝ≥0` in a sigma-finite space, there exists a lower semicontinuous function `g > f` with integral arbitrarily close to that of `f`. Formulation in terms of `integral`. Auxiliary lemma for Vitali-Carathéodory theorem `exists_lt_lower_semicontinuous_integral_lt`. -/ theorem exists_lt_lowerSemicontinuous_integral_gt_nnreal [SigmaFinite μ] (f : α → ℝ≥0) (fint : Integrable (fun x => (f x : ℝ)) μ) {ε : ℝ} (εpos : 0 < ε) : ∃ g : α → ℝ≥0∞, (∀ x, (f x : ℝ≥0∞) < g x) ∧ LowerSemicontinuous g ∧ (∀ᵐ x ∂μ, g x < ⊤) ∧ Integrable (fun x => (g x).toReal) μ ∧ (∫ x, (g x).toReal ∂μ) < (∫ x, ↑(f x) ∂μ) + ε := by have fmeas : AEMeasurable f μ := by convert fint.aestronglyMeasurable.real_toNNReal.aemeasurable simp only [Real.toNNReal_coe] lift ε to ℝ≥0 using εpos.le obtain ⟨δ, δpos, hδε⟩ : ∃ δ : ℝ≥0, 0 < δ ∧ δ < ε := exists_between εpos have int_f_ne_top : (∫⁻ a : α, f a ∂μ) ≠ ∞ := (hasFiniteIntegral_iff_ofNNReal.1 fint.hasFiniteIntegral).ne rcases exists_lt_lowerSemicontinuous_lintegral_ge_of_aemeasurable μ f fmeas (ENNReal.coe_ne_zero.2 δpos.ne') with ⟨g, f_lt_g, gcont, gint⟩ have gint_ne : (∫⁻ x : α, g x ∂μ) ≠ ∞ := ne_top_of_le_ne_top (by simpa) gint have g_lt_top : ∀ᵐ x : α ∂μ, g x < ∞ := ae_lt_top gcont.measurable gint_ne have Ig : (∫⁻ a : α, ENNReal.ofReal (g a).toReal ∂μ) = ∫⁻ a : α, g a ∂μ := by apply lintegral_congr_ae filter_upwards [g_lt_top] with _ hx simp only [hx.ne, ENNReal.ofReal_toReal, Ne, not_false_iff] refine ⟨g, f_lt_g, gcont, g_lt_top, ?_, ?_⟩ · refine ⟨gcont.measurable.ennreal_toReal.aemeasurable.aestronglyMeasurable, ?_⟩ simp only [hasFiniteIntegral_iff_norm, Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg] convert gint_ne.lt_top using 1 · rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae] · calc ENNReal.toReal (∫⁻ a : α, ENNReal.ofReal (g a).toReal ∂μ) = ENNReal.toReal (∫⁻ a : α, g a ∂μ) := by congr 1 _ ≤ ENNReal.toReal ((∫⁻ a : α, f a ∂μ) + δ) := by apply ENNReal.toReal_mono _ gint simpa using int_f_ne_top _ = ENNReal.toReal (∫⁻ a : α, f a ∂μ) + δ := by rw [ENNReal.toReal_add int_f_ne_top ENNReal.coe_ne_top, ENNReal.coe_toReal] _ < ENNReal.toReal (∫⁻ a : α, f a ∂μ) + ε := add_lt_add_left hδε _ _ = (∫⁻ a : α, ENNReal.ofReal ↑(f a) ∂μ).toReal + ε := by simp · apply Filter.Eventually.of_forall fun x => _; simp · exact fmeas.coe_nnreal_real.aestronglyMeasurable · apply Filter.Eventually.of_forall fun x => _; simp · apply gcont.measurable.ennreal_toReal.aemeasurable.aestronglyMeasurable /-! ### Upper semicontinuous lower bound for nonnegative functions -/ /-- Given a simple function `f` with values in `ℝ≥0`, there exists an upper semicontinuous function `g ≤ f` with integral arbitrarily close to that of `f`. Formulation in terms of `lintegral`. Auxiliary lemma for Vitali-Carathéodory theorem `exists_lt_lower_semicontinuous_integral_lt`. -/ theorem SimpleFunc.exists_upperSemicontinuous_le_lintegral_le (f : α →ₛ ℝ≥0) (int_f : (∫⁻ x, f x ∂μ) ≠ ∞) {ε : ℝ≥0∞} (ε0 : ε ≠ 0) : ∃ g : α → ℝ≥0, (∀ x, g x ≤ f x) ∧ UpperSemicontinuous g ∧ (∫⁻ x, f x ∂μ) ≤ (∫⁻ x, g x ∂μ) + ε := by induction f using MeasureTheory.SimpleFunc.induction generalizing ε with | @const c s hs => by_cases hc : c = 0 · refine ⟨fun _ => 0, ?_, upperSemicontinuous_const, ?_⟩ · classical simp only [hc, Set.indicator_zero', Pi.zero_apply, SimpleFunc.const_zero, imp_true_iff, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, SimpleFunc.coe_piecewise, le_zero_iff] · classical simp only [hc, Set.indicator_zero', lintegral_const, zero_mul, Pi.zero_apply, SimpleFunc.const_zero, zero_add, zero_le', SimpleFunc.coe_zero, Set.piecewise_eq_indicator, ENNReal.coe_zero, SimpleFunc.coe_piecewise] have μs_lt_top : μ s < ∞ := by classical simpa only [hs, hc, lt_top_iff_ne_top, true_and, SimpleFunc.coe_const, or_false, lintegral_const, ENNReal.coe_indicator, Set.univ_inter, ENNReal.coe_ne_top, Measure.restrict_apply MeasurableSet.univ, ENNReal.mul_eq_top, SimpleFunc.const_zero, Function.const_apply, lintegral_indicator, ENNReal.coe_eq_zero, Ne, not_false_iff, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, SimpleFunc.coe_piecewise, false_and] using int_f have : (0 : ℝ≥0∞) < ε / c := ENNReal.div_pos_iff.2 ⟨ε0, ENNReal.coe_ne_top⟩ obtain ⟨F, Fs, F_closed, μF⟩ : ∃ (F : _), F ⊆ s ∧ IsClosed F ∧ μ s < μ F + ε / c := hs.exists_isClosed_lt_add μs_lt_top.ne this.ne' refine ⟨Set.indicator F fun _ => c, fun x => ?_, F_closed.upperSemicontinuous_indicator (zero_le _), ?_⟩ · simp only [SimpleFunc.coe_const, SimpleFunc.const_zero, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, SimpleFunc.coe_piecewise] exact Set.indicator_le_indicator_of_subset Fs (fun x => zero_le _) _ · suffices (c : ℝ≥0∞) * μ s ≤ c * μ F + ε by classical simpa only [hs, F_closed.measurableSet, SimpleFunc.coe_const, Function.const_apply, lintegral_const, ENNReal.coe_indicator, Set.univ_inter, MeasurableSet.univ, SimpleFunc.const_zero, lintegral_indicator, SimpleFunc.coe_zero, Set.piecewise_eq_indicator, SimpleFunc.coe_piecewise, Measure.restrict_apply] calc (c : ℝ≥0∞) * μ s ≤ c * (μ F + ε / c) := mul_le_mul_left' μF.le _ _ = c * μ F + ε := by simp_rw [mul_add] rw [ENNReal.mul_div_cancel _ ENNReal.coe_ne_top] simpa using hc | @add f₁ f₂ _ h₁ h₂ => have A : ((∫⁻ x : α, f₁ x ∂μ) + ∫⁻ x : α, f₂ x ∂μ) ≠ ⊤ := by rwa [← lintegral_add_left f₁.measurable.coe_nnreal_ennreal] rcases h₁ (ENNReal.add_ne_top.1 A).1 (ENNReal.half_pos ε0).ne' with ⟨g₁, f₁_le_g₁, g₁cont, g₁int⟩ rcases h₂ (ENNReal.add_ne_top.1 A).2 (ENNReal.half_pos ε0).ne' with ⟨g₂, f₂_le_g₂, g₂cont, g₂int⟩ refine ⟨fun x => g₁ x + g₂ x, fun x => add_le_add (f₁_le_g₁ x) (f₂_le_g₂ x), g₁cont.add g₂cont, ?_⟩ simp only [SimpleFunc.coe_add, ENNReal.coe_add, Pi.add_apply] rw [lintegral_add_left f₁.measurable.coe_nnreal_ennreal, lintegral_add_left g₁cont.measurable.coe_nnreal_ennreal] convert add_le_add g₁int g₂int using 1 conv_lhs => rw [← ENNReal.add_halves ε] abel /-- Given an integrable function `f` with values in `ℝ≥0`, there exists an upper semicontinuous function `g ≤ f` with integral arbitrarily close to that of `f`. Formulation in terms of `lintegral`. Auxiliary lemma for Vitali-Carathéodory theorem `exists_lt_lower_semicontinuous_integral_lt`. -/ theorem exists_upperSemicontinuous_le_lintegral_le (f : α → ℝ≥0) (int_f : (∫⁻ x, f x ∂μ) ≠ ∞) {ε : ℝ≥0∞} (ε0 : ε ≠ 0) : ∃ g : α → ℝ≥0, (∀ x, g x ≤ f x) ∧ UpperSemicontinuous g ∧ (∫⁻ x, f x ∂μ) ≤ (∫⁻ x, g x ∂μ) + ε := by obtain ⟨fs, fs_le_f, int_fs⟩ : ∃ fs : α →ₛ ℝ≥0, (∀ x, fs x ≤ f x) ∧ (∫⁻ x, f x ∂μ) ≤ (∫⁻ x, fs x ∂μ) + ε / 2 := by have := ENNReal.lt_add_right int_f (ENNReal.half_pos ε0).ne' conv_rhs at this => rw [lintegral_eq_nnreal (fun x => (f x : ℝ≥0∞)) μ] erw [ENNReal.biSup_add] at this <;> [skip; exact ⟨0, fun x => by simp⟩] simp only [lt_iSup_iff] at this rcases this with ⟨fs, fs_le_f, int_fs⟩ refine ⟨fs, fun x => by simpa only [ENNReal.coe_le_coe] using fs_le_f x, ?_⟩ convert int_fs.le rw [← SimpleFunc.lintegral_eq_lintegral] simp only [SimpleFunc.coe_map, Function.comp_apply] have int_fs_lt_top : (∫⁻ x, fs x ∂μ) ≠ ∞ := by refine ne_top_of_le_ne_top int_f (lintegral_mono fun x => ?_) simpa only [ENNReal.coe_le_coe] using fs_le_f x obtain ⟨g, g_le_fs, gcont, gint⟩ : ∃ g : α → ℝ≥0, (∀ x, g x ≤ fs x) ∧ UpperSemicontinuous g ∧ (∫⁻ x, fs x ∂μ) ≤ (∫⁻ x, g x ∂μ) + ε / 2 := fs.exists_upperSemicontinuous_le_lintegral_le int_fs_lt_top (ENNReal.half_pos ε0).ne' refine ⟨g, fun x => (g_le_fs x).trans (fs_le_f x), gcont, ?_⟩ calc (∫⁻ x, f x ∂μ) ≤ (∫⁻ x, fs x ∂μ) + ε / 2 := int_fs _ ≤ (∫⁻ x, g x ∂μ) + ε / 2 + ε / 2 := add_le_add gint le_rfl _ = (∫⁻ x, g x ∂μ) + ε := by rw [add_assoc, ENNReal.add_halves] /-- Given an integrable function `f` with values in `ℝ≥0`, there exists an upper semicontinuous function `g ≤ f` with integral arbitrarily close to that of `f`. Formulation in terms of `integral`. Auxiliary lemma for Vitali-Carathéodory theorem `exists_lt_lower_semicontinuous_integral_lt`. -/ theorem exists_upperSemicontinuous_le_integral_le (f : α → ℝ≥0) (fint : Integrable (fun x => (f x : ℝ)) μ) {ε : ℝ} (εpos : 0 < ε) : ∃ g : α → ℝ≥0, (∀ x, g x ≤ f x) ∧ UpperSemicontinuous g ∧ Integrable (fun x => (g x : ℝ)) μ ∧ (∫ x, (f x : ℝ) ∂μ) - ε ≤ ∫ x, ↑(g x) ∂μ := by lift ε to ℝ≥0 using εpos.le rw [NNReal.coe_pos, ← ENNReal.coe_pos] at εpos have If : (∫⁻ x, f x ∂μ) < ∞ := hasFiniteIntegral_iff_ofNNReal.1 fint.hasFiniteIntegral rcases exists_upperSemicontinuous_le_lintegral_le f If.ne εpos.ne' with ⟨g, gf, gcont, gint⟩ have Ig : (∫⁻ x, g x ∂μ) < ∞ := by refine lt_of_le_of_lt (lintegral_mono fun x => ?_) If simpa using gf x refine ⟨g, gf, gcont, ?_, ?_⟩ · refine Integrable.mono fint gcont.measurable.coe_nnreal_real.aemeasurable.aestronglyMeasurable ?_ exact Filter.Eventually.of_forall fun x => by simp [gf x] · rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae] · rw [sub_le_iff_le_add] convert ENNReal.toReal_mono _ gint · simp · rw [ENNReal.toReal_add Ig.ne ENNReal.coe_ne_top]; simp · simpa using Ig.ne · apply Filter.Eventually.of_forall; simp · exact gcont.measurable.coe_nnreal_real.aemeasurable.aestronglyMeasurable · apply Filter.Eventually.of_forall; simp · exact fint.aestronglyMeasurable /-! ### Vitali-Carathéodory theorem -/ /-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close to that of `f`. This function has to be `EReal`-valued in general. -/ theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ) {ε : ℝ} (εpos : 0 < ε) : ∃ g : α → EReal, (∀ x, (f x : EReal) < g x) ∧ LowerSemicontinuous g ∧ Integrable (fun x => EReal.toReal (g x)) μ ∧ (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩ have δpos : 0 < δ := half_pos εpos let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x) have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩ let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x) have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩ let g : α → EReal := fun x => (gp x : EReal) - gm x have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by filter_upwards [gp_lt_top] with _ hx rw [EReal.toReal_sub] <;> simp [hx.ne] refine ⟨g, ?lt, ?lsc, ?int, ?aelt, ?intlt⟩ case int => show Integrable (fun x => EReal.toReal (g x)) μ rw [integrable_congr ae_g] convert gp_integrable.sub gm_integrable simp case intlt => show (∫ x : α, (g x).toReal ∂μ) < (∫ x : α, f x ∂μ) + ε exact calc (∫ x : α, (g x).toReal ∂μ) = ∫ x : α, EReal.toReal (gp x) - EReal.toReal (gm x) ∂μ := integral_congr_ae ae_g _ = (∫ x : α, EReal.toReal (gp x) ∂μ) - ∫ x : α, ↑(gm x) ∂μ := by simp only [EReal.toReal_coe_ennreal, ENNReal.coe_toReal] exact integral_sub gp_integrable gm_integrable _ < (∫ x : α, ↑(fp x) ∂μ) + ↑δ - ∫ x : α, ↑(gm x) ∂μ := by apply sub_lt_sub_right convert gpint simp only [EReal.toReal_coe_ennreal] _ ≤ (∫ x : α, ↑(fp x) ∂μ) + ↑δ - ((∫ x : α, ↑(fm x) ∂μ) - δ) := sub_le_sub_left gmint _ _ = (∫ x : α, f x ∂μ) + 2 * δ := by simp_rw [integral_eq_integral_pos_part_sub_integral_neg_part hf]; ring _ = (∫ x : α, f x ∂μ) + ε := by congr 1; field_simp [δ, mul_comm] case aelt => show ∀ᵐ x : α ∂μ, g x < ⊤ filter_upwards [gp_lt_top] with ?_ hx simp only [g, sub_eq_add_neg, Ne, (EReal.add_lt_top _ _).ne, lt_top_iff_ne_top, lt_top_iff_ne_top.1 hx, EReal.coe_ennreal_eq_top_iff, not_false_iff, EReal.neg_eq_top_iff, EReal.coe_ennreal_ne_bot] case lt => show ∀ x, (f x : EReal) < g x intro x rw [EReal.coe_real_ereal_eq_coe_toNNReal_sub_coe_toNNReal (f x)] refine EReal.sub_lt_sub_of_lt_of_le ?_ ?_ ?_ ?_ · simp only [EReal.coe_ennreal_lt_coe_ennreal_iff]; exact fp_lt_gp x · simp only [ENNReal.coe_le_coe, EReal.coe_ennreal_le_coe_ennreal_iff] exact gm_le_fm x · simp only [EReal.coe_ennreal_ne_bot, Ne, not_false_iff] · simp only [EReal.coe_nnreal_ne_top, Ne, not_false_iff] case lsc => show LowerSemicontinuous g apply LowerSemicontinuous.add' · exact continuous_coe_ennreal_ereal.comp_lowerSemicontinuous gpcont fun x y hxy => EReal.coe_ennreal_le_coe_ennreal_iff.2 hxy · apply continuous_neg.comp_upperSemicontinuous_antitone _ fun x y hxy => EReal.neg_le_neg_iff.2 hxy dsimp apply continuous_coe_ennreal_ereal.comp_upperSemicontinuous _ fun x y hxy => EReal.coe_ennreal_le_coe_ennreal_iff.2 hxy exact ENNReal.continuous_coe.comp_upperSemicontinuous gmcont fun x y hxy => ENNReal.coe_le_coe.2 hxy · intro x exact EReal.continuousAt_add (by simp) (by simp) /-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an integrable function `g < f` which is upper semicontinuous, with integral arbitrarily close to that of `f`. This function has to be `EReal`-valued in general. -/ theorem exists_upperSemicontinuous_lt_integral_gt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ) {ε : ℝ} (εpos : 0 < ε) : ∃ g : α → EReal, (∀ x, (g x : EReal) < f x) ∧ UpperSemicontinuous g ∧ Integrable (fun x => EReal.toReal (g x)) μ ∧ (∀ᵐ x ∂μ, ⊥ < g x) ∧ (∫ x, f x ∂μ) < (∫ x, EReal.toReal (g x) ∂μ) + ε := by rcases exists_lt_lowerSemicontinuous_integral_lt (fun x => -f x) hf.neg εpos with ⟨g, g_lt_f, gcont, g_integrable, g_lt_top, gint⟩ refine ⟨fun x => -g x, ?_, ?_, ?_, ?_, ?_⟩ · exact fun x => EReal.neg_lt_comm.1 (by simpa only [EReal.coe_neg] using g_lt_f x) · exact continuous_neg.comp_lowerSemicontinuous_antitone gcont fun x y hxy => EReal.neg_le_neg_iff.2 hxy · convert g_integrable.neg simp · simpa [bot_lt_iff_ne_bot, lt_top_iff_ne_top] using g_lt_top · simp_rw [integral_neg, lt_neg_add_iff_add_lt] at gint rw [add_comm] at gint simpa [integral_neg] using gint end MeasureTheory
Hamiltonian.lean
/- Copyright (c) 2023 Bhavik Mehta, Rishi Mehta, Linus Sommer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Rishi Mehta, Linus Sommer -/ import Mathlib.Algebra.GroupWithZero.Nat import Mathlib.Algebra.Order.Group.Nat import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected /-! # Hamiltonian Graphs In this file we introduce hamiltonian paths, cycles and graphs. ## Main definitions - `SimpleGraph.Walk.IsHamiltonian`: Predicate for a walk to be hamiltonian. - `SimpleGraph.Walk.IsHamiltonianCycle`: Predicate for a walk to be a hamiltonian cycle. - `SimpleGraph.IsHamiltonian`: Predicate for a graph to be hamiltonian. -/ open Finset Function namespace SimpleGraph variable {α β : Type*} [DecidableEq α] [DecidableEq β] {G : SimpleGraph α} {a b : α} {p : G.Walk a b} namespace Walk /-- A hamiltonian path is a walk `p` that visits every vertex exactly once. Note that while this definition doesn't contain that `p` is a path, `p.isPath` gives that. -/ def IsHamiltonian (p : G.Walk a b) : Prop := ∀ a, p.support.count a = 1 lemma IsHamiltonian.map {H : SimpleGraph β} (f : G →g H) (hf : Bijective f) (hp : p.IsHamiltonian) : (p.map f).IsHamiltonian := by simp [IsHamiltonian, hf.surjective.forall, hf.injective, hp _] /-- A hamiltonian path visits every vertex. -/ @[simp] lemma IsHamiltonian.mem_support (hp : p.IsHamiltonian) (c : α) : c ∈ p.support := by simp only [← List.count_pos_iff, hp _, Nat.zero_lt_one] /-- Hamiltonian paths are paths. -/ lemma IsHamiltonian.isPath (hp : p.IsHamiltonian) : p.IsPath := IsPath.mk' <| List.nodup_iff_count_le_one.2 <| (le_of_eq <| hp ·) /-- A path whose support contains every vertex is hamiltonian. -/ lemma IsPath.isHamiltonian_of_mem (hp : p.IsPath) (hp' : ∀ w, w ∈ p.support) : p.IsHamiltonian := fun _ ↦ le_antisymm (List.nodup_iff_count_le_one.1 hp.support_nodup _) (List.count_pos_iff.2 (hp' _)) lemma IsPath.isHamiltonian_iff (hp : p.IsPath) : p.IsHamiltonian ↔ ∀ w, w ∈ p.support := ⟨(·.mem_support), hp.isHamiltonian_of_mem⟩ section variable [Fintype α] /-- The support of a hamiltonian walk is the entire vertex set. -/ lemma IsHamiltonian.support_toFinset (hp : p.IsHamiltonian) : p.support.toFinset = Finset.univ := by simp [eq_univ_iff_forall, hp] /-- The length of a hamiltonian path is one less than the number of vertices of the graph. -/ lemma IsHamiltonian.length_eq (hp : p.IsHamiltonian) : p.length = Fintype.card α - 1 := eq_tsub_of_add_eq <| by rw [← length_support, ← List.sum_toFinset_count_eq_length, Finset.sum_congr rfl fun _ _ ↦ hp _, ← card_eq_sum_ones, hp.support_toFinset, card_univ] end /-- A hamiltonian cycle is a cycle that visits every vertex once. -/ structure IsHamiltonianCycle (p : G.Walk a a) : Prop extends p.IsCycle where isHamiltonian_tail : p.tail.IsHamiltonian variable {p : G.Walk a a} lemma IsHamiltonianCycle.isCycle (hp : p.IsHamiltonianCycle) : p.IsCycle := hp.toIsCycle lemma IsHamiltonianCycle.map {H : SimpleGraph β} (f : G →g H) (hf : Bijective f) (hp : p.IsHamiltonianCycle) : (p.map f).IsHamiltonianCycle where toIsCycle := hp.isCycle.map hf.injective isHamiltonian_tail := by simp only [IsHamiltonian, hf.surjective.forall] intro x rcases p with (_ | ⟨y, p⟩) · cases hp.ne_nil rfl simp only [map_cons, getVert_cons_succ, tail_cons_eq, support_copy,support_map] rw [List.count_map_of_injective _ _ hf.injective, ← support_copy, ← tail_cons_eq] exact hp.isHamiltonian_tail _ lemma isHamiltonianCycle_isCycle_and_isHamiltonian_tail : p.IsHamiltonianCycle ↔ p.IsCycle ∧ p.tail.IsHamiltonian := ⟨fun ⟨h, h'⟩ ↦ ⟨h, h'⟩, fun ⟨h, h'⟩ ↦ ⟨h, h'⟩⟩ lemma isHamiltonianCycle_iff_isCycle_and_support_count_tail_eq_one : p.IsHamiltonianCycle ↔ p.IsCycle ∧ ∀ a, (support p).tail.count a = 1 := by simp +contextual [isHamiltonianCycle_isCycle_and_isHamiltonian_tail, IsHamiltonian, support_tail, IsCycle.not_nil] /-- A hamiltonian cycle visits every vertex. -/ lemma IsHamiltonianCycle.mem_support (hp : p.IsHamiltonianCycle) (b : α) : b ∈ p.support := List.mem_of_mem_tail <| support_tail p hp.1.not_nil ▸ hp.isHamiltonian_tail.mem_support _ /-- The length of a hamiltonian cycle is the number of vertices. -/ lemma IsHamiltonianCycle.length_eq [Fintype α] (hp : p.IsHamiltonianCycle) : p.length = Fintype.card α := by rw [← length_tail_add_one hp.not_nil, hp.isHamiltonian_tail.length_eq, Nat.sub_add_cancel] rw [Nat.succ_le, Fintype.card_pos_iff] exact ⟨a⟩ lemma IsHamiltonianCycle.count_support_self (hp : p.IsHamiltonianCycle) : p.support.count a = 2 := by rw [support_eq_cons, List.count_cons_self, ← support_tail _ hp.1.not_nil, hp.isHamiltonian_tail] lemma IsHamiltonianCycle.support_count_of_ne (hp : p.IsHamiltonianCycle) (h : a ≠ b) : p.support.count b = 1 := by rw [← cons_support_tail p hp.1.not_nil, List.count_cons_of_ne h, hp.isHamiltonian_tail] end Walk variable [Fintype α] /-- A hamiltonian graph is a graph that contains a hamiltonian cycle. By convention, the singleton graph is considered to be hamiltonian. -/ def IsHamiltonian (G : SimpleGraph α) : Prop := Fintype.card α ≠ 1 → ∃ a, ∃ p : G.Walk a a, p.IsHamiltonianCycle lemma IsHamiltonian.mono {H : SimpleGraph α} (hGH : G ≤ H) (hG : G.IsHamiltonian) : H.IsHamiltonian := fun hα ↦ let ⟨_, p, hp⟩ := hG hα; ⟨_, p.map <| .ofLE hGH, hp.map _ bijective_id⟩ lemma IsHamiltonian.connected (hG : G.IsHamiltonian) : G.Connected where preconnected a b := by obtain rfl | hab := eq_or_ne a b · rfl have : Nontrivial α := ⟨a, b, hab⟩ obtain ⟨_, p, hp⟩ := hG Fintype.one_lt_card.ne' have a_mem := hp.mem_support a have b_mem := hp.mem_support b exact ((p.takeUntil a a_mem).reverse.append <| p.takeUntil b b_mem).reachable nonempty := not_isEmpty_iff.1 fun _ ↦ by simpa using hG <| by simp [@Fintype.card_eq_zero] end SimpleGraph
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}.
FourFunctions.lean
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Pi import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Finset.Sups import Mathlib.Order.Birkhoff import Mathlib.Order.Booleanisation import Mathlib.Order.Sublattice import Mathlib.Tactic.Positivity.Basic import Mathlib.Tactic.Ring import Mathlib.Tactic.GCongr /-! # The four functions theorem and corollaries This file proves the four functions theorem. The statement is that if `f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)` for all `a`, `b` in a finite distributive lattice, then `(∑ x ∈ s, f₁ x) * (∑ x ∈ t, f₂ x) ≤ (∑ x ∈ s ⊼ t, f₃ x) * (∑ x ∈ s ⊻ t, f₄ x)` where `s ⊼ t = {a ⊓ b | a ∈ s, b ∈ t}`, `s ⊻ t = {a ⊔ b | a ∈ s, b ∈ t}`. The proof uses Birkhoff's representation theorem to restrict to the case where the finite distributive lattice is in fact a finite powerset algebra, namely `Finset α` for some finite `α`. Then it proves this new statement by induction on the size of `α`. ## Main declarations The two versions of the four functions theorem are * `Finset.four_functions_theorem` for finite powerset algebras. * `four_functions_theorem` for any finite distributive lattices. We deduce a number of corollaries: * `Finset.le_card_infs_mul_card_sups`: Daykin inequality. `|s| |t| ≤ |s ⊼ t| |s ⊻ t|` * `holley`: Holley inequality. * `fkg`: Fortuin-Kastelyn-Ginibre inequality. * `Finset.card_le_card_diffs`: Marica-Schönheim inequality. `|s| ≤ |{a \ b | a, b ∈ s}|` ## TODO Prove that lattices in which `Finset.le_card_infs_mul_card_sups` holds are distributive. See Daykin, *A lattice is distributive iff |A| |B| <= |A ∨ B| |A ∧ B|* Prove the Fishburn-Shepp inequality. Is `collapse` a construct generally useful for set family inductions? If so, we should move it to an earlier file and give it a proper API. ## References [*Applications of the FKG Inequality and Its Relatives*, Graham][Graham1983] -/ open Finset Fintype Function open scoped FinsetFamily variable {α β : Type*} section Finset variable [DecidableEq α] [CommSemiring β] [LinearOrder β] [IsStrictOrderedRing β] {𝒜 : Finset (Finset α)} {a : α} {f f₁ f₂ f₃ f₄ : Finset α → β} {s t u : Finset α} /-- The `n = 1` case of the Ahlswede-Daykin inequality. Note that we can't just expand everything out and bound termwise since `c₀ * d₁` appears twice on the RHS of the assumptions while `c₁ * d₀` does not appear. -/ private lemma ineq [ExistsAddOfLE β] {a₀ a₁ b₀ b₁ c₀ c₁ d₀ d₁ : β} (ha₀ : 0 ≤ a₀) (ha₁ : 0 ≤ a₁) (hb₀ : 0 ≤ b₀) (hb₁ : 0 ≤ b₁) (hc₀ : 0 ≤ c₀) (hc₁ : 0 ≤ c₁) (hd₀ : 0 ≤ d₀) (hd₁ : 0 ≤ d₁) (h₀₀ : a₀ * b₀ ≤ c₀ * d₀) (h₁₀ : a₁ * b₀ ≤ c₀ * d₁) (h₀₁ : a₀ * b₁ ≤ c₀ * d₁) (h₁₁ : a₁ * b₁ ≤ c₁ * d₁) : (a₀ + a₁) * (b₀ + b₁) ≤ (c₀ + c₁) * (d₀ + d₁) := by calc _ = a₀ * b₀ + (a₀ * b₁ + a₁ * b₀) + a₁ * b₁ := by ring _ ≤ c₀ * d₀ + (c₀ * d₁ + c₁ * d₀) + c₁ * d₁ := add_le_add_three h₀₀ ?_ h₁₁ _ = (c₀ + c₁) * (d₀ + d₁) := by ring obtain hcd | hcd := (mul_nonneg hc₀ hd₁).eq_or_lt' · rw [hcd] at h₀₁ h₁₀ rw [h₀₁.antisymm, h₁₀.antisymm, add_zero] <;> positivity refine le_of_mul_le_mul_right ?_ hcd calc (a₀ * b₁ + a₁ * b₀) * (c₀ * d₁) = a₀ * b₁ * (c₀ * d₁) + c₀ * d₁ * (a₁ * b₀) := by ring _ ≤ a₀ * b₁ * (a₁ * b₀) + c₀ * d₁ * (c₀ * d₁) := mul_add_mul_le_mul_add_mul h₀₁ h₁₀ _ = a₀ * b₀ * (a₁ * b₁) + c₀ * d₁ * (c₀ * d₁) := by ring _ ≤ c₀ * d₀ * (c₁ * d₁) + c₀ * d₁ * (c₀ * d₁) := by gcongr _ = (c₀ * d₁ + c₁ * d₀) * (c₀ * d₁) := by ring private def collapse (𝒜 : Finset (Finset α)) (a : α) (f : Finset α → β) (s : Finset α) : β := ∑ t ∈ 𝒜 with t.erase a = s, f t private lemma erase_eq_iff (hs : a ∉ s) : t.erase a = s ↔ t = s ∨ t = insert a s := by by_cases ht : a ∈ t <;> · simp [erase_eq_iff_eq_insert, *] aesop private lemma filter_collapse_eq (ha : a ∉ s) (𝒜 : Finset (Finset α)) : {t ∈ 𝒜 | t.erase a = s} = if s ∈ 𝒜 then (if insert a s ∈ 𝒜 then {s, insert a s} else {s}) else (if insert a s ∈ 𝒜 then {insert a s} else ∅) := by ext t; split_ifs <;> simp [erase_eq_iff ha] <;> aesop omit [LinearOrder β] [IsStrictOrderedRing β] in lemma collapse_eq (ha : a ∉ s) (𝒜 : Finset (Finset α)) (f : Finset α → β) : collapse 𝒜 a f s = (if s ∈ 𝒜 then f s else 0) + if insert a s ∈ 𝒜 then f (insert a s) else 0 := by rw [collapse, filter_collapse_eq ha] split_ifs <;> simp [(ne_of_mem_of_not_mem' (mem_insert_self a s) ha).symm, *] omit [LinearOrder β] [IsStrictOrderedRing β] in lemma collapse_of_mem (ha : a ∉ s) (ht : t ∈ 𝒜) (hu : u ∈ 𝒜) (hts : t = s) (hus : u = insert a s) : collapse 𝒜 a f s = f t + f u := by subst hts; subst hus; simp_rw [collapse_eq ha, if_pos ht, if_pos hu] lemma le_collapse_of_mem (ha : a ∉ s) (hf : 0 ≤ f) (hts : t = s) (ht : t ∈ 𝒜) : f t ≤ collapse 𝒜 a f s := by subst hts rw [collapse_eq ha, if_pos ht] split_ifs · exact le_add_of_nonneg_right <| hf _ · rw [add_zero] lemma le_collapse_of_insert_mem (ha : a ∉ s) (hf : 0 ≤ f) (hts : t = insert a s) (ht : t ∈ 𝒜) : f t ≤ collapse 𝒜 a f s := by rw [collapse_eq ha, ← hts, if_pos ht] split_ifs · exact le_add_of_nonneg_left <| hf _ · rw [zero_add] lemma collapse_nonneg (hf : 0 ≤ f) : 0 ≤ collapse 𝒜 a f := fun _s ↦ sum_nonneg fun _t _ ↦ hf _ lemma collapse_modular [ExistsAddOfLE β] (hu : a ∉ u) (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄) (h : ∀ ⦃s⦄, s ⊆ insert a u → ∀ ⦃t⦄, t ⊆ insert a u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)) (𝒜 ℬ : Finset (Finset α)) : ∀ ⦃s⦄, s ⊆ u → ∀ ⦃t⦄, t ⊆ u → collapse 𝒜 a f₁ s * collapse ℬ a f₂ t ≤ collapse (𝒜 ⊼ ℬ) a f₃ (s ∩ t) * collapse (𝒜 ⊻ ℬ) a f₄ (s ∪ t) := by rintro s hsu t htu -- Gather a bunch of facts we'll need a lot have := hsu.trans <| subset_insert a _ have := htu.trans <| subset_insert a _ have := insert_subset_insert a hsu have := insert_subset_insert a htu have has := notMem_mono hsu hu have hat := notMem_mono htu hu have : a ∉ s ∩ t := notMem_mono (inter_subset_left.trans hsu) hu have := notMem_union.2 ⟨has, hat⟩ rw [collapse_eq has] split_ifs · rw [collapse_eq hat] split_ifs · rw [collapse_of_mem ‹_› (inter_mem_infs ‹_› ‹_›) (inter_mem_infs ‹_› ‹_›) rfl (insert_inter_distrib _ _ _).symm, collapse_of_mem ‹_› (union_mem_sups ‹_› ‹_›) (union_mem_sups ‹_› ‹_›) rfl (insert_union_distrib _ _ _).symm] refine ineq (h₁ _) (h₁ _) (h₂ _) (h₂ _) (h₃ _) (h₃ _) (h₄ _) (h₄ _) (h ‹_› ‹_›) ?_ ?_ ?_ · simpa [*] using h ‹insert a s ⊆ _› ‹t ⊆ _› · simpa [*] using h ‹s ⊆ _› ‹insert a t ⊆ _› · simpa [*] using h ‹insert a s ⊆ _› ‹insert a t ⊆ _› · rw [add_zero, add_mul] refine (add_le_add (h ‹_› ‹_›) <| h ‹_› ‹_›).trans ?_ rw [collapse_of_mem ‹_› (union_mem_sups ‹_› ‹_›) (union_mem_sups ‹_› ‹_›) rfl (insert_union _ _ _), insert_inter_of_notMem ‹_›, ← mul_add] gcongr exacts [add_nonneg (h₄ _) <| h₄ _, le_collapse_of_mem ‹_› h₃ rfl <| inter_mem_infs ‹_› ‹_›] · rw [zero_add, add_mul] refine (add_le_add (h ‹_› ‹_›) <| h ‹_› ‹_›).trans ?_ rw [collapse_of_mem ‹_› (inter_mem_infs ‹_› ‹_›) (inter_mem_infs ‹_› ‹_›) (inter_insert_of_notMem ‹_›) (insert_inter_distrib _ _ _).symm, union_insert, insert_union_distrib, ← add_mul] gcongr exacts [add_nonneg (h₃ _) <| h₃ _, le_collapse_of_insert_mem ‹_› h₄ (insert_union_distrib _ _ _).symm (union_mem_sups ‹_› ‹_›)] · rw [add_zero, mul_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg h₄ _ · rw [add_zero, collapse_eq hat, mul_add] split_ifs · refine (add_le_add (h ‹_› ‹_›) <| h ‹_› ‹_›).trans ?_ rw [collapse_of_mem ‹_› (union_mem_sups ‹_› ‹_›) (union_mem_sups ‹_› ‹_›) rfl (union_insert _ _ _), inter_insert_of_notMem ‹_›, ← mul_add] exact mul_le_mul_of_nonneg_right (le_collapse_of_mem ‹_› h₃ rfl <| inter_mem_infs ‹_› ‹_›) <| add_nonneg (h₄ _) <| h₄ _ · rw [mul_zero, add_zero] exact (h ‹_› ‹_›).trans <| mul_le_mul (le_collapse_of_mem ‹_› h₃ rfl <| inter_mem_infs ‹_› ‹_›) (le_collapse_of_mem ‹_› h₄ rfl <| union_mem_sups ‹_› ‹_›) (h₄ _) <| collapse_nonneg h₃ _ · rw [mul_zero, zero_add] refine (h ‹_› ‹_›).trans <| mul_le_mul ?_ (le_collapse_of_insert_mem ‹_› h₄ (union_insert _ _ _) <| union_mem_sups ‹_› ‹_›) (h₄ _) <| collapse_nonneg h₃ _ exact le_collapse_of_mem (notMem_mono inter_subset_left ‹_›) h₃ (inter_insert_of_notMem ‹_›) <| inter_mem_infs ‹_› ‹_› · simp_rw [mul_zero, add_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg h₄ _ · rw [zero_add, collapse_eq hat, mul_add] split_ifs · refine (add_le_add (h ‹_› ‹_›) <| h ‹_› ‹_›).trans ?_ rw [collapse_of_mem ‹_› (inter_mem_infs ‹_› ‹_›) (inter_mem_infs ‹_› ‹_›) (insert_inter_of_notMem ‹_›) (insert_inter_distrib _ _ _).symm, insert_inter_of_notMem ‹_›, ← insert_inter_distrib, insert_union, insert_union_distrib, ← add_mul] exact mul_le_mul_of_nonneg_left (le_collapse_of_insert_mem ‹_› h₄ (insert_union_distrib _ _ _).symm <| union_mem_sups ‹_› ‹_›) <| add_nonneg (h₃ _) <| h₃ _ · rw [mul_zero, add_zero] refine (h ‹_› ‹_›).trans <| mul_le_mul (le_collapse_of_mem ‹_› h₃ (insert_inter_of_notMem ‹_›) <| inter_mem_infs ‹_› ‹_›) (le_collapse_of_insert_mem ‹_› h₄ (insert_union _ _ _) <| union_mem_sups ‹_› ‹_›) (h₄ _) <| collapse_nonneg h₃ _ · rw [mul_zero, zero_add] exact (h ‹_› ‹_›).trans <| mul_le_mul (le_collapse_of_insert_mem ‹_› h₃ (insert_inter_distrib _ _ _).symm <| inter_mem_infs ‹_› ‹_›) (le_collapse_of_insert_mem ‹_› h₄ (insert_union_distrib _ _ _).symm <| union_mem_sups ‹_› ‹_›) (h₄ _) <| collapse_nonneg h₃ _ · simp_rw [mul_zero, add_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg h₄ _ · simp_rw [add_zero, zero_mul] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg h₄ _ omit [LinearOrder β] [IsStrictOrderedRing β] in lemma sum_collapse (h𝒜 : 𝒜 ⊆ (insert a u).powerset) (hu : a ∉ u) : ∑ s ∈ u.powerset, collapse 𝒜 a f s = ∑ s ∈ 𝒜, f s := by calc _ = ∑ s ∈ u.powerset ∩ 𝒜, f s + ∑ s ∈ u.powerset.image (insert a) ∩ 𝒜, f s := ?_ _ = ∑ s ∈ u.powerset ∩ 𝒜, f s + ∑ s ∈ ((insert a u).powerset \ u.powerset) ∩ 𝒜, f s := ?_ _ = ∑ s ∈ 𝒜, f s := ?_ · rw [← Finset.sum_ite_mem, ← Finset.sum_ite_mem, sum_image, ← sum_add_distrib] · exact sum_congr rfl fun s hs ↦ collapse_eq (notMem_mono (mem_powerset.1 hs) hu) _ _ · exact (insert_erase_invOn.2.injOn).mono fun s hs ↦ notMem_mono (mem_powerset.1 hs) hu · congr with s simp only [mem_image, mem_powerset, mem_sdiff, subset_insert_iff] refine ⟨?_, fun h ↦ ⟨_, h.1, ?_⟩⟩ · rintro ⟨s, hs, rfl⟩ exact ⟨subset_insert_iff.1 <| insert_subset_insert _ hs, fun h ↦ hu <| h <| mem_insert_self _ _⟩ · rw [insert_erase (erase_ne_self.1 fun hs ↦ ?_)] rw [hs] at h exact h.2 h.1 · rw [← sum_union (disjoint_sdiff_self_right.mono inf_le_left inf_le_left), ← union_inter_distrib_right, union_sdiff_of_subset (powerset_mono.2 <| subset_insert _ _), inter_eq_right.2 h𝒜] variable [ExistsAddOfLE β] /-- The **Four Functions Theorem** on a powerset algebra. See `four_functions_theorem` for the finite distributive lattice generalisation. -/ protected lemma Finset.four_functions_theorem (u : Finset α) (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄) (h : ∀ ⦃s⦄, s ⊆ u → ∀ ⦃t⦄, t ⊆ u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)) {𝒜 ℬ : Finset (Finset α)} (h𝒜 : 𝒜 ⊆ u.powerset) (hℬ : ℬ ⊆ u.powerset) : (∑ s ∈ 𝒜, f₁ s) * ∑ s ∈ ℬ, f₂ s ≤ (∑ s ∈ 𝒜 ⊼ ℬ, f₃ s) * ∑ s ∈ 𝒜 ⊻ ℬ, f₄ s := by induction u using Finset.induction generalizing f₁ f₂ f₃ f₄ 𝒜 ℬ with | empty => simp only [Finset.powerset_empty, Finset.subset_singleton_iff] at h𝒜 hℬ obtain rfl | rfl := h𝒜 <;> obtain rfl | rfl := hℬ <;> simp; exact h (subset_refl ∅) subset_rfl | insert a u hu ih => specialize ih (collapse_nonneg h₁) (collapse_nonneg h₂) (collapse_nonneg h₃) (collapse_nonneg h₄) (collapse_modular hu h₁ h₂ h₃ h₄ h 𝒜 ℬ) Subset.rfl Subset.rfl have : 𝒜 ⊼ ℬ ⊆ powerset (insert a u) := by simpa using infs_subset h𝒜 hℬ have : 𝒜 ⊻ ℬ ⊆ powerset (insert a u) := by simpa using sups_subset h𝒜 hℬ simpa only [powerset_sups_powerset_self, powerset_infs_powerset_self, sum_collapse, not_false_eq_true, *] using ih variable (f₁ f₂ f₃ f₄) [Fintype α] private lemma four_functions_theorem_aux (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄) (h : ∀ s t, f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)) (𝒜 ℬ : Finset (Finset α)) : (∑ s ∈ 𝒜, f₁ s) * ∑ s ∈ ℬ, f₂ s ≤ (∑ s ∈ 𝒜 ⊼ ℬ, f₃ s) * ∑ s ∈ 𝒜 ⊻ ℬ, f₄ s := by refine univ.four_functions_theorem h₁ h₂ h₃ h₄ ?_ ?_ ?_ <;> simp [h] end Finset section DistribLattice variable [DistribLattice α] [CommSemiring β] [LinearOrder β] [IsStrictOrderedRing β] [ExistsAddOfLE β] (f f₁ f₂ f₃ f₄ g μ : α → β) /-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/ lemma four_functions_theorem [DecidableEq α] (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄) (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) : (∑ a ∈ s, f₁ a) * ∑ a ∈ t, f₂ a ≤ (∑ a ∈ s ⊼ t, f₃ a) * ∑ a ∈ s ⊻ t, f₄ a := by classical set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1, isSublattice_latticeClosure.2⟩ have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype set s' : Finset L := s.preimage (↑) Subtype.coe_injective.injOn set t' : Finset L := t.preimage (↑) Subtype.coe_injective.injOn have hs' : s'.map ⟨L.subtype, Subtype.coe_injective⟩ = s := by simp [s', map_eq_image, image_preimage, filter_eq_self] exact fun a ha ↦ subset_latticeClosure <| Set.subset_union_left ha have ht' : t'.map ⟨L.subtype, Subtype.coe_injective⟩ = t := by simp [t', map_eq_image, image_preimage, filter_eq_self] exact fun a ha ↦ subset_latticeClosure <| Set.subset_union_right ha clear_value s' t' obtain ⟨β, _, _, g, hg⟩ := exists_birkhoff_representation L have := four_functions_theorem_aux (extend g (f₁ ∘ (↑)) 0) (extend g (f₂ ∘ (↑)) 0) (extend g (f₃ ∘ (↑)) 0) (extend g (f₄ ∘ (↑)) 0) (extend_nonneg (fun _ ↦ h₁ _) le_rfl) (extend_nonneg (fun _ ↦ h₂ _) le_rfl) (extend_nonneg (fun _ ↦ h₃ _) le_rfl) (extend_nonneg (fun _ ↦ h₄ _) le_rfl) ?_ (s'.map ⟨g, hg⟩) (t'.map ⟨g, hg⟩) · simpa only [← hs', ← ht', ← map_sups, ← map_infs, sum_map, Embedding.coeFn_mk, hg.extend_apply] using this rintro s t classical obtain ⟨a, rfl⟩ | hs := em (∃ a, g a = s) · obtain ⟨b, rfl⟩ | ht := em (∃ b, g b = t) · simp_rw [← sup_eq_union, ← inf_eq_inter, ← map_sup, ← map_inf, hg.extend_apply] exact h _ _ · simpa [extend_apply' _ _ _ ht] using mul_nonneg (extend_nonneg (fun a : L ↦ h₃ a) le_rfl _) (extend_nonneg (fun a : L ↦ h₄ a) le_rfl _) · simpa [extend_apply' _ _ _ hs] using mul_nonneg (extend_nonneg (fun a : L ↦ h₃ a) le_rfl _) (extend_nonneg (fun a : L ↦ h₄ a) le_rfl _) /-- An inequality of Daykin. Interestingly, any lattice in which this inequality holds is distributive. -/ lemma Finset.le_card_infs_mul_card_sups [DecidableEq α] (s t : Finset α) : #s * #t ≤ #(s ⊼ t) * #(s ⊻ t) := by simpa using four_functions_theorem (1 : α → ℕ) 1 1 1 zero_le_one zero_le_one zero_le_one zero_le_one (fun _ _ ↦ le_rfl) s t variable [Fintype α] /-- Special case of the **Four Functions Theorem** when `s = t = univ`. -/ lemma four_functions_theorem_univ (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄) (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) : (∑ a, f₁ a) * ∑ a, f₂ a ≤ (∑ a, f₃ a) * ∑ a, f₄ a := by classical simpa using four_functions_theorem f₁ f₂ f₃ f₄ h₁ h₂ h₃ h₄ h univ univ /-- The **Holley Inequality**. -/ lemma holley (hμ₀ : 0 ≤ μ) (hf : 0 ≤ f) (hg : 0 ≤ g) (hμ : Monotone μ) (hfg : ∑ a, f a = ∑ a, g a) (h : ∀ a b, f a * g b ≤ f (a ⊓ b) * g (a ⊔ b)) : ∑ a, μ a * f a ≤ ∑ a, μ a * g a := by classical obtain rfl | hf := hf.eq_or_lt · simp only [Pi.zero_apply, sum_const_zero, eq_comm, Fintype.sum_eq_zero_iff_of_nonneg hg] at hfg simp [hfg] obtain rfl | hg := hg.eq_or_lt · simp only [Pi.zero_apply, sum_const_zero, Fintype.sum_eq_zero_iff_of_nonneg hf.le] at hfg simp [hfg] have := four_functions_theorem g (μ * f) f (μ * g) hg.le (mul_nonneg hμ₀ hf.le) hf.le (mul_nonneg hμ₀ hg.le) (fun a b ↦ ?_) univ univ · simpa [hfg, sum_pos hg] using this · simp_rw [Pi.mul_apply, mul_left_comm _ (μ _), mul_comm (g _)] rw [sup_comm, inf_comm] exact mul_le_mul (hμ le_sup_left) (h _ _) (mul_nonneg (hf.le _) <| hg.le _) <| hμ₀ _ /-- The **Fortuin-Kastelyn-Ginibre Inequality**. -/ lemma fkg (hμ₀ : 0 ≤ μ) (hf₀ : 0 ≤ f) (hg₀ : 0 ≤ g) (hf : Monotone f) (hg : Monotone g) (hμ : ∀ a b, μ a * μ b ≤ μ (a ⊓ b) * μ (a ⊔ b)) : (∑ a, μ a * f a) * ∑ a, μ a * g a ≤ (∑ a, μ a) * ∑ a, μ a * (f a * g a) := by refine four_functions_theorem_univ (μ * f) (μ * g) μ _ (mul_nonneg hμ₀ hf₀) (mul_nonneg hμ₀ hg₀) hμ₀ (mul_nonneg hμ₀ <| mul_nonneg hf₀ hg₀) (fun a b ↦ ?_) dsimp rw [mul_mul_mul_comm, ← mul_assoc (μ (a ⊓ b))] exact mul_le_mul (hμ _ _) (mul_le_mul (hf le_sup_left) (hg le_sup_right) (hg₀ _) <| hf₀ _) (mul_nonneg (hf₀ _) <| hg₀ _) <| mul_nonneg (hμ₀ _) <| hμ₀ _ end DistribLattice open Booleanisation variable [DecidableEq α] [GeneralizedBooleanAlgebra α] /-- A slight generalisation of the **Marica-Schönheim Inequality**. -/ lemma Finset.le_card_diffs_mul_card_diffs (s t : Finset α) : #s * #t ≤ #(s \\ t) * #(t \\ s) := by have : ∀ s t : Finset α, (s \\ t).map ⟨_, liftLatticeHom_injective⟩ = s.map ⟨_, liftLatticeHom_injective⟩ \\ t.map ⟨_, liftLatticeHom_injective⟩ := by rintro s t simp_rw [map_eq_image] exact image_image₂_distrib fun a b ↦ rfl simpa [← card_compls (_ ⊻ _), ← map_sup, ← map_inf, ← this] using (s.map ⟨_, liftLatticeHom_injective⟩).le_card_infs_mul_card_sups (t.map ⟨_, liftLatticeHom_injective⟩)ᶜˢ /-- The **Marica-Schönheim Inequality**. -/ lemma Finset.card_le_card_diffs (s : Finset α) : #s ≤ #(s \\ s) := le_of_pow_le_pow_left₀ two_ne_zero (zero_le _) <| by simpa [← sq] using s.le_card_diffs_mul_card_diffs s
DoubleCounting.lean
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Nat /-! # Double countings This file gathers a few double counting arguments. ## Bipartite graphs In a bipartite graph (considered as a relation `r : α → β → Prop`), we can bound the number of edges between `s : Finset α` and `t : Finset β` by the minimum/maximum of edges over all `a ∈ s` times the size of `s`. Similarly for `t`. Combining those two yields inequalities between the sizes of `s` and `t`. * `bipartiteBelow`: `s.bipartiteBelow r b` are the elements of `s` below `b` wrt to `r`. Its size is the number of edges of `b` in `s`. * `bipartiteAbove`: `t.bipartite_Above r a` are the elements of `t` above `a` wrt to `r`. Its size is the number of edges of `a` in `t`. * `card_mul_le_card_mul`, `card_mul_le_card_mul'`: Double counting the edges of a bipartite graph from below and from above. * `card_mul_eq_card_mul`: Equality combination of the previous. ## Implementation notes For the formulation of double-counting arguments where a bipartite graph is considered as a bipartite simple graph `G : SimpleGraph V`, see `Mathlib/Combinatorics/SimpleGraph/Bipartite.lean`. -/ assert_not_exists Field open Finset Function Relator variable {R α β : Type*} /-! ### Bipartite graph -/ namespace Finset section Bipartite variable (r : α → β → Prop) (s : Finset α) (t : Finset β) (a : α) (b : β) [DecidablePred (r a)] [∀ a, Decidable (r a b)] {m n : ℕ} /-- Elements of `s` which are "below" `b` according to relation `r`. -/ def bipartiteBelow : Finset α := {a ∈ s | r a b} /-- Elements of `t` which are "above" `a` according to relation `r`. -/ def bipartiteAbove : Finset β := {b ∈ t | r a b} theorem bipartiteBelow_swap : t.bipartiteBelow (swap r) a = t.bipartiteAbove r a := rfl theorem bipartiteAbove_swap : s.bipartiteAbove (swap r) b = s.bipartiteBelow r b := rfl @[simp, norm_cast] theorem coe_bipartiteBelow : s.bipartiteBelow r b = ({a ∈ s | r a b} : Set α) := coe_filter _ _ @[simp, norm_cast] theorem coe_bipartiteAbove : t.bipartiteAbove r a = ({b ∈ t | r a b} : Set β) := coe_filter _ _ variable {s t a b} @[simp] theorem mem_bipartiteBelow {a : α} : a ∈ s.bipartiteBelow r b ↔ a ∈ s ∧ r a b := mem_filter @[simp] theorem mem_bipartiteAbove {b : β} : b ∈ t.bipartiteAbove r a ↔ b ∈ t ∧ r a b := mem_filter @[to_additive] theorem prod_prod_bipartiteAbove_eq_prod_prod_bipartiteBelow [CommMonoid R] (f : α → β → R) [∀ a b, Decidable (r a b)] : ∏ a ∈ s, ∏ b ∈ t.bipartiteAbove r a, f a b = ∏ b ∈ t, ∏ a ∈ s.bipartiteBelow r b, f a b := by simp_rw [bipartiteAbove, bipartiteBelow, prod_filter] exact prod_comm theorem sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow [∀ a b, Decidable (r a b)] : (∑ a ∈ s, #(t.bipartiteAbove r a)) = ∑ b ∈ t, #(s.bipartiteBelow r b) := by simp_rw [card_eq_sum_ones, sum_sum_bipartiteAbove_eq_sum_sum_bipartiteBelow] section OrderedSemiring variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {m n : R} /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is an upper bound. -/ theorem card_nsmul_le_card_nsmul [∀ a b, Decidable (r a b)] (hm : ∀ a ∈ s, m ≤ #(t.bipartiteAbove r a)) (hn : ∀ b ∈ t, #(s.bipartiteBelow r b) ≤ n) : #s • m ≤ #t • n := calc _ ≤ ∑ a ∈ s, (#(t.bipartiteAbove r a) : R) := s.card_nsmul_le_sum _ _ hm _ = ∑ b ∈ t, (#(s.bipartiteBelow r b) : R) := by norm_cast; rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow] _ ≤ _ := t.sum_le_card_nsmul _ _ hn /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is an upper bound. -/ theorem card_nsmul_le_card_nsmul' [∀ a b, Decidable (r a b)] (hn : ∀ b ∈ t, n ≤ #(s.bipartiteBelow r b)) (hm : ∀ a ∈ s, #(t.bipartiteAbove r a) ≤ m) : #t • n ≤ #s • m := card_nsmul_le_card_nsmul (swap r) hn hm end OrderedSemiring section StrictOrderedSemiring variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] (r : α → β → Prop) {s : Finset α} {t : Finset β} (a b) {m n : R} /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a strict lower bound on the number of edges while the RHS is an upper bound. -/ theorem card_nsmul_lt_card_nsmul_of_lt_of_le [∀ a b, Decidable (r a b)] (hs : s.Nonempty) (hm : ∀ a ∈ s, m < #(t.bipartiteAbove r a)) (hn : ∀ b ∈ t, #(s.bipartiteBelow r b) ≤ n) : #s • m < #t • n := calc _ = ∑ _a ∈ s, m := by rw [sum_const] _ < ∑ a ∈ s, (#(t.bipartiteAbove r a) : R) := sum_lt_sum_of_nonempty hs hm _ = ∑ b ∈ t, (#(s.bipartiteBelow r b) : R) := by norm_cast; rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow] _ ≤ _ := t.sum_le_card_nsmul _ _ hn /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is a strict upper bound. -/ theorem card_nsmul_lt_card_nsmul_of_le_of_lt [∀ a b, Decidable (r a b)] (ht : t.Nonempty) (hm : ∀ a ∈ s, m ≤ #(t.bipartiteAbove r a)) (hn : ∀ b ∈ t, #(s.bipartiteBelow r b) < n) : #s • m < #t • n := calc _ ≤ ∑ a ∈ s, (#(t.bipartiteAbove r a) : R) := s.card_nsmul_le_sum _ _ hm _ = ∑ b ∈ t, (#(s.bipartiteBelow r b) : R) := by norm_cast; rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow] _ < ∑ _b ∈ t, n := sum_lt_sum_of_nonempty ht hn _ = _ := sum_const _ /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a strict lower bound on the number of edges while the RHS is an upper bound. -/ theorem card_nsmul_lt_card_nsmul_of_lt_of_le' [∀ a b, Decidable (r a b)] (ht : t.Nonempty) (hn : ∀ b ∈ t, n < #(s.bipartiteBelow r b)) (hm : ∀ a ∈ s, #(t.bipartiteAbove r a) ≤ m) : #t • n < #s • m := card_nsmul_lt_card_nsmul_of_lt_of_le (swap r) ht hn hm /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is a strict upper bound. -/ theorem card_nsmul_lt_card_nsmul_of_le_of_lt' [∀ a b, Decidable (r a b)] (hs : s.Nonempty) (hn : ∀ b ∈ t, n ≤ #(s.bipartiteBelow r b)) (hm : ∀ a ∈ s, #(t.bipartiteAbove r a) < m) : #t • n < #s • m := card_nsmul_lt_card_nsmul_of_le_of_lt (swap r) hs hn hm end StrictOrderedSemiring /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is an upper bound. -/ theorem card_mul_le_card_mul [∀ a b, Decidable (r a b)] (hm : ∀ a ∈ s, m ≤ #(t.bipartiteAbove r a)) (hn : ∀ b ∈ t, #(s.bipartiteBelow r b) ≤ n) : #s * m ≤ #t * n := card_nsmul_le_card_nsmul _ hm hn theorem card_mul_le_card_mul' [∀ a b, Decidable (r a b)] (hn : ∀ b ∈ t, n ≤ #(s.bipartiteBelow r b)) (hm : ∀ a ∈ s, #(t.bipartiteAbove r a) ≤ m) : #t * n ≤ #s * m := card_nsmul_le_card_nsmul' _ hn hm theorem card_mul_eq_card_mul [∀ a b, Decidable (r a b)] (hm : ∀ a ∈ s, #(t.bipartiteAbove r a) = m) (hn : ∀ b ∈ t, #(s.bipartiteBelow r b) = n) : #s * m = #t * n := (card_mul_le_card_mul _ (fun a ha ↦ (hm a ha).ge) fun b hb ↦ (hn b hb).le).antisymm <| card_mul_le_card_mul' _ (fun a ha ↦ (hn a ha).ge) fun b hb ↦ (hm b hb).le theorem card_le_card_of_forall_subsingleton (hs : ∀ a ∈ s, ∃ b, b ∈ t ∧ r a b) (ht : ∀ b ∈ t, ({ a ∈ s | r a b } : Set α).Subsingleton) : #s ≤ #t := by classical rw [← mul_one #s, ← mul_one #t] exact card_mul_le_card_mul r (fun a h ↦ card_pos.2 (by rw [← coe_nonempty, coe_bipartiteAbove] exact hs _ h : (t.bipartiteAbove r a).Nonempty)) (fun b h ↦ card_le_one.2 (by simp_rw [mem_bipartiteBelow] exact ht _ h)) theorem card_le_card_of_forall_subsingleton' (ht : ∀ b ∈ t, ∃ a, a ∈ s ∧ r a b) (hs : ∀ a ∈ s, ({ b ∈ t | r a b } : Set β).Subsingleton) : #t ≤ #s := card_le_card_of_forall_subsingleton (swap r) ht hs end Bipartite end Finset namespace Fintype variable [Fintype α] [Fintype β] {r : α → β → Prop} theorem card_le_card_of_leftTotal_unique (h₁ : LeftTotal r) (h₂ : LeftUnique r) : Fintype.card α ≤ Fintype.card β := card_le_card_of_forall_subsingleton r (by simpa using h₁) fun _ _ _ ha₁ _ ha₂ ↦ h₂ ha₁.2 ha₂.2 theorem card_le_card_of_rightTotal_unique (h₁ : RightTotal r) (h₂ : RightUnique r) : Fintype.card β ≤ Fintype.card α := card_le_card_of_forall_subsingleton' r (by simpa using h₁) fun _ _ _ ha₁ _ ha₂ ↦ h₂ ha₁.2 ha₂.2 end Fintype
Group.lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Order.Filter.AtTopBot.Basic import Mathlib.Order.Filter.AtTopBot.Map import Mathlib.Order.Filter.AtTopBot.Monoid /-! # Convergence to ±infinity in ordered commutative groups -/ variable {α G : Type*} open Set namespace Filter section OrderedCommGroup variable [CommGroup G] [PartialOrder G] [IsOrderedMonoid G] (l : Filter α) {f g : α → G} @[to_additive] theorem tendsto_atTop_mul_left_of_le' (C : G) (hf : ∀ᶠ x in l, C ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := .atTop_of_isBoundedUnder_le_mul (f := f⁻¹) ⟨C⁻¹, by simpa⟩ (by simpa) @[to_additive] theorem tendsto_atBot_mul_left_of_ge' (C : G) (hf : ∀ᶠ x in l, f x ≤ C) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := tendsto_atTop_mul_left_of_le' (G := Gᵒᵈ) _ C hf hg @[to_additive] theorem tendsto_atTop_mul_left_of_le (C : G) (hf : ∀ x, C ≤ f x) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := tendsto_atTop_mul_left_of_le' l C (univ_mem' hf) hg @[to_additive] theorem tendsto_atBot_mul_left_of_ge (C : G) (hf : ∀ x, f x ≤ C) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := tendsto_atTop_mul_left_of_le (G := Gᵒᵈ) _ C hf hg @[to_additive] theorem tendsto_atTop_mul_right_of_le' (C : G) (hf : Tendsto f l atTop) (hg : ∀ᶠ x in l, C ≤ g x) : Tendsto (fun x => f x * g x) l atTop := .atTop_of_mul_isBoundedUnder_le (g := g⁻¹) ⟨C⁻¹, by simpa⟩ (by simpa) @[to_additive] theorem tendsto_atBot_mul_right_of_ge' (C : G) (hf : Tendsto f l atBot) (hg : ∀ᶠ x in l, g x ≤ C) : Tendsto (fun x => f x * g x) l atBot := tendsto_atTop_mul_right_of_le' (G := Gᵒᵈ) _ C hf hg @[to_additive] theorem tendsto_atTop_mul_right_of_le (C : G) (hf : Tendsto f l atTop) (hg : ∀ x, C ≤ g x) : Tendsto (fun x => f x * g x) l atTop := tendsto_atTop_mul_right_of_le' l C hf (univ_mem' hg) @[to_additive] theorem tendsto_atBot_mul_right_of_ge (C : G) (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ C) : Tendsto (fun x => f x * g x) l atBot := tendsto_atTop_mul_right_of_le (G := Gᵒᵈ) _ C hf hg @[to_additive] theorem tendsto_atTop_mul_const_left (C : G) (hf : Tendsto f l atTop) : Tendsto (fun x => C * f x) l atTop := tendsto_atTop_mul_left_of_le' l C (univ_mem' fun _ => le_refl C) hf @[to_additive] theorem tendsto_atBot_mul_const_left (C : G) (hf : Tendsto f l atBot) : Tendsto (fun x => C * f x) l atBot := tendsto_atTop_mul_const_left (G := Gᵒᵈ) _ C hf @[to_additive] theorem tendsto_atTop_mul_const_right (C : G) (hf : Tendsto f l atTop) : Tendsto (fun x => f x * C) l atTop := tendsto_atTop_mul_right_of_le' l C hf (univ_mem' fun _ => le_refl C) @[to_additive] theorem tendsto_atBot_mul_const_right (C : G) (hf : Tendsto f l atBot) : Tendsto (fun x => f x * C) l atBot := tendsto_atTop_mul_const_right (G := Gᵒᵈ) _ C hf @[to_additive] theorem map_inv_atBot : map (Inv.inv : G → G) atBot = atTop := (OrderIso.inv G).map_atBot @[to_additive] theorem map_inv_atTop : map (Inv.inv : G → G) atTop = atBot := (OrderIso.inv G).map_atTop @[to_additive] theorem comap_inv_atBot : comap (Inv.inv : G → G) atBot = atTop := (OrderIso.inv G).comap_atTop @[to_additive] theorem comap_inv_atTop : comap (Inv.inv : G → G) atTop = atBot := (OrderIso.inv G).comap_atBot @[to_additive] theorem tendsto_inv_atTop_atBot : Tendsto (Inv.inv : G → G) atTop atBot := (OrderIso.inv G).tendsto_atTop @[to_additive] theorem tendsto_inv_atBot_atTop : Tendsto (Inv.inv : G → G) atBot atTop := tendsto_inv_atTop_atBot (G := Gᵒᵈ) variable {l} @[to_additive (attr := simp)] theorem tendsto_inv_atTop_iff : Tendsto (fun x => (f x)⁻¹) l atTop ↔ Tendsto f l atBot := (OrderIso.inv G).tendsto_atBot_iff @[to_additive (attr := simp)] theorem tendsto_inv_atBot_iff : Tendsto (fun x => (f x)⁻¹) l atBot ↔ Tendsto f l atTop := (OrderIso.inv G).tendsto_atTop_iff end OrderedCommGroup section LinearOrderedCommGroup variable [CommGroup G] [LinearOrder G] /-- $\lim_{x\to+\infty}|x|_m=+\infty$ -/ @[to_additive /-- $\lim_{x\to+\infty}|x|=+\infty$ -/] theorem tendsto_mabs_atTop_atTop : Tendsto (mabs : G → G) atTop atTop := tendsto_atTop_mono le_mabs_self tendsto_id /-- $\lim_{x\to\infty^{-1}|x|_m=+\infty$ -/ @[to_additive /-- $\lim_{x\to-\infty}|x|=+\infty$ -/] theorem tendsto_mabs_atBot_atTop [IsOrderedMonoid G] : Tendsto (mabs : G → G) atBot atTop := tendsto_atTop_mono inv_le_mabs tendsto_inv_atBot_atTop @[to_additive (attr := simp)] theorem comap_mabs_atTop [IsOrderedMonoid G] : comap (mabs : G → G) atTop = atBot ⊔ atTop := by refine le_antisymm (((atTop_basis.comap _).le_basis_iff (atBot_basis.sup atTop_basis)).2 ?_) (sup_le tendsto_mabs_atBot_atTop.le_comap tendsto_mabs_atTop_atTop.le_comap) rintro ⟨a, b⟩ - refine ⟨max (a⁻¹) b, trivial, fun x hx => ?_⟩ rw [mem_preimage, mem_Ici, le_mabs', max_le_iff, ← min_inv_inv', le_min_iff, inv_inv] at hx exact hx.imp And.left And.right end LinearOrderedCommGroup end Filter
Even.lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Algebra.Group.Int.Defs import Mathlib.Algebra.Group.Nat.Even import Mathlib.Data.Int.Sqrt /-! # Parity of integers -/ open Nat namespace Int /-! #### Parity -/ variable {m n : ℤ} @[simp] lemma emod_two_ne_one : ¬n % 2 = 1 ↔ n % 2 = 0 := by grind @[simp] lemma one_emod_two : (1 : Int) % 2 = 1 := rfl -- `EuclideanDomain.mod_eq_zero` uses (2 ∣ n) as normal form @[local simp] lemma emod_two_ne_zero : ¬n % 2 = 0 ↔ n % 2 = 1 := by grind @[grind =] lemma even_iff : Even n ↔ n % 2 = 0 where mp := fun ⟨m, hm⟩ ↦ by simp [← Int.two_mul, hm] mpr h := ⟨n / 2, by grind⟩ lemma not_even_iff : ¬Even n ↔ n % 2 = 1 := by grind @[simp] lemma two_dvd_ne_zero : ¬2 ∣ n ↔ n % 2 = 1 := by grind instance : DecidablePred (Even : ℤ → Prop) := fun _ ↦ decidable_of_iff _ even_iff.symm /-- `IsSquare` can be decided on `ℤ` by checking against the square root. -/ instance : DecidablePred (IsSquare : ℤ → Prop) := fun m ↦ decidable_of_iff' (sqrt m * sqrt m = m) <| by simp_rw [← exists_mul_self m, IsSquare, eq_comm] @[simp] lemma not_even_one : ¬Even (1 : ℤ) := by simp [even_iff] @[parity_simps] lemma even_add : Even (m + n) ↔ (Even m ↔ Even n) := by grind lemma two_not_dvd_two_mul_add_one (n : ℤ) : ¬2 ∣ 2 * n + 1 := by grind @[parity_simps] lemma even_sub : Even (m - n) ↔ (Even m ↔ Even n) := by grind @[parity_simps] lemma even_add_one : Even (n + 1) ↔ ¬Even n := by grind @[parity_simps] lemma even_sub_one : Even (n - 1) ↔ ¬Even n := by grind @[parity_simps, grind =] lemma even_mul : Even (m * n) ↔ Even m ∨ Even n := by rcases emod_two_eq_zero_or_one m with h₁ | h₁ <;> rcases emod_two_eq_zero_or_one n with h₂ | h₂ <;> simp [even_iff, h₁, h₂, Int.mul_emod] @[parity_simps, grind =] lemma even_pow {n : ℕ} : Even (m ^ n) ↔ Even m ∧ n ≠ 0 := by induction n with grind lemma even_pow' {n : ℕ} (h : n ≠ 0) : Even (m ^ n) ↔ Even m := by grind @[simp, norm_cast, grind =] lemma even_coe_nat (n : ℕ) : Even (n : ℤ) ↔ Even n := by rw_mod_cast [even_iff, Nat.even_iff] lemma two_mul_ediv_two_of_even : Even n → 2 * (n / 2) = n := by grind lemma ediv_two_mul_two_of_even : Even n → n / 2 * 2 = n := by grind -- Here are examples of how `parity_simps` can be used with `Int`. example (m n : ℤ) (h : Even m) : ¬Even (n + 3) ↔ Even (m ^ 2 + m + n) := by simp +decide [*, parity_simps] example : ¬Even (25394535 : ℤ) := by decide @[simp] theorem isSquare_sign_iff {z : ℤ} : IsSquare z.sign ↔ 0 ≤ z := by induction z using Int.induction_on with | zero => simpa using ⟨0, by simp⟩ | succ => norm_cast; simp | pred => rw [sign_eq_neg_one_of_neg (by omega), ← neg_add', Int.neg_nonneg] norm_cast simp only [reduceNeg, le_zero_eq, Nat.add_eq_zero, succ_ne_self, and_false, iff_false] rintro ⟨a | a, ⟨⟩⟩ end Int
NoZeroDivisors.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.UniqueProds.Basic import Mathlib.Algebra.MonoidAlgebra.Opposite /-! # Variations on non-zero divisors in `AddMonoidAlgebra`s This file studies the interaction between typeclass assumptions on two Types `R` and `A` and whether `R[A]` has non-zero zero-divisors. For some background on related questions, see [Kaplansky's Conjectures](https://en.wikipedia.org/wiki/Kaplansky%27s_conjectures), especially the *zero divisor conjecture*. _Conjecture._ Let `K` be a field, and `G` a torsion-free group. The group ring `K[G]` does not contain nontrivial zero divisors, that is, it is a domain. In this file we show that if `R` satisfies `NoZeroDivisors` and `A` is a grading type satisfying `UniqueProds A` (resp. `UniqueSums A`), then `MonoidAlgebra R A` (resp. `R[A]`) also satisfies `NoZeroDivisors`. Because of the instances to `UniqueProds/Sums`, we obtain a formalization of the well-known result that if `R` is a field and `A` is a left-ordered group, then `R[A]` contains no non-zero zero-divisors. The actual assumptions on `R` are weaker. ## Main results * `MonoidAlgebra.mul_apply_mul_eq_mul_of_uniqueMul` and `AddMonoidAlgebra.mul_apply_add_eq_mul_of_uniqueAdd` general sufficient results stating that certain monomials in a product have as coefficient a product of coefficients of the factors. * The instance showing that `Semiring R, NoZeroDivisors R, Mul A, UniqueProds A` imply `NoZeroDivisors (MonoidAlgebra R A)`. * The instance showing that `Semiring R, NoZeroDivisors R, Add A, UniqueSums A` imply `NoZeroDivisors R[A]`. TODO: move the rest of the docs to UniqueProds? * `NoZeroDivisors.of_left_ordered` shows that if `R` is a semiring with no non-zero zero-divisors, `A` is a linearly ordered, add right cancel semigroup with strictly monotone left addition, then `R[A]` has no non-zero zero-divisors. * `NoZeroDivisors.of_right_ordered` shows that if `R` is a semiring with no non-zero zero-divisors, `A` is a linearly ordered, add left cancel semigroup with strictly monotone right addition, then `R[A]` has no non-zero zero-divisors. The conditions on `A` imposed in `NoZeroDivisors.of_left_ordered` are sometimes referred to as `left-ordered`. The conditions on `A` imposed in `NoZeroDivisors.of_right_ordered` are sometimes referred to as `right-ordered`. These conditions are sufficient, but not necessary. As mentioned above, *Kaplansky's Conjecture* asserts that `A` being torsion-free may be enough. -/ open Finsupp variable {R A : Type*} section Semiring variable [Semiring R] namespace MonoidAlgebra /-- The coefficient of a monomial in a product `f * g` that can be reached in at most one way as a product of monomials in the supports of `f` and `g` is a product. -/ theorem mul_apply_mul_eq_mul_of_uniqueMul [Mul A] {f g : MonoidAlgebra R A} {a0 b0 : A} (h : UniqueMul f.support g.support a0 b0) : (f * g) (a0 * b0) = f a0 * g b0 := by classical simp_rw [mul_apply, sum, ← Finset.sum_product'] refine (Finset.sum_eq_single (a0, b0) ?_ ?_).trans (if_pos rfl) <;> simp_rw [Finset.mem_product] · refine fun ab hab hne ↦ if_neg (fun he ↦ hne <| Prod.ext ?_ ?_) exacts [(h hab.1 hab.2 he).1, (h hab.1 hab.2 he).2] · refine fun hnotMem ↦ ite_eq_right_iff.mpr (fun _ ↦ ?_) rcases not_and_or.mp hnotMem with af | bg · rw [notMem_support_iff.mp af, zero_mul] · rw [notMem_support_iff.mp bg, mul_zero] instance [NoZeroDivisors R] [Mul A] [UniqueProds A] : NoZeroDivisors (MonoidAlgebra R A) where eq_zero_or_eq_zero_of_mul_eq_zero {a b} ab := by contrapose! ab obtain ⟨da, a0, db, b0, h⟩ := UniqueProds.uniqueMul_of_nonempty (support_nonempty_iff.mpr ab.1) (support_nonempty_iff.mpr ab.2) refine support_nonempty_iff.mp ⟨da * db, ?_⟩ rw [mem_support_iff] at a0 b0 ⊢ exact mul_apply_mul_eq_mul_of_uniqueMul h ▸ mul_ne_zero a0 b0 instance [IsCancelAdd R] [IsLeftCancelMulZero R] [Mul A] [UniqueProds A] : IsLeftCancelMulZero (MonoidAlgebra R A) where mul_left_cancel_of_ne_zero {f} hf {g₁ g₂} eq := by classical induction hg : g₁.support ∪ g₂.support using Finset.eraseInduction generalizing g₁ g₂ with | _ s ih => obtain h | h := s.eq_empty_or_nonempty <;> subst s · simp_rw [Finset.union_eq_empty, support_eq_empty] at h; exact h.1.trans h.2.symm have ⟨af, haf, ag, hag, uniq⟩ := UniqueProds.uniqueMul_of_nonempty (support_nonempty_iff.2 hf) h have h := mul_apply_mul_eq_mul_of_uniqueMul (uniq.mono subset_rfl Finset.subset_union_left) dsimp only at eq rw [eq, mul_apply_mul_eq_mul_of_uniqueMul (uniq.mono subset_rfl Finset.subset_union_right)] at h have := mul_left_cancel₀ (mem_support_iff.mp haf) h rw [← g₁.erase_add_single ag, ← g₂.erase_add_single ag, this] at eq ⊢ simp_rw [mul_add, add_right_cancel_iff] at eq rw [ih ag hag eq] simp_rw [support_erase, Finset.erase_union_distrib] instance [IsCancelAdd R] [IsRightCancelMulZero R] [Mul A] [UniqueProds A] : IsRightCancelMulZero (MonoidAlgebra R A) := MulOpposite.isLeftCancelMulZero_iff.mp <| MonoidAlgebra.opRingEquiv.injective.isLeftCancelMulZero _ (map_zero _) (map_mul _) instance [IsCancelAdd R] [IsCancelMulZero R] [Mul A] [UniqueProds A] : IsCancelMulZero (MonoidAlgebra R A) where instance [IsCancelAdd R] [IsDomain R] [Monoid A] [UniqueProds A] : IsDomain (MonoidAlgebra R A) where end MonoidAlgebra namespace AddMonoidAlgebra /-- The coefficient of a monomial in a product `f * g` that can be reached in at most one way as a product of monomials in the supports of `f` and `g` is a product. -/ theorem mul_apply_add_eq_mul_of_uniqueAdd [Add A] {f g : R[A]} {a0 b0 : A} (h : UniqueAdd f.support g.support a0 b0) : (f * g) (a0 + b0) = f a0 * g b0 := MonoidAlgebra.mul_apply_mul_eq_mul_of_uniqueMul (A := Multiplicative A) h instance [NoZeroDivisors R] [Add A] [UniqueSums A] : NoZeroDivisors R[A] := inferInstanceAs (NoZeroDivisors (MonoidAlgebra R (Multiplicative A))) instance [IsCancelAdd R] [IsLeftCancelMulZero R] [Add A] [UniqueSums A] : IsLeftCancelMulZero R[A] := inferInstanceAs (IsLeftCancelMulZero (MonoidAlgebra R (Multiplicative A))) instance [IsCancelAdd R] [IsRightCancelMulZero R] [Add A] [UniqueSums A] : IsRightCancelMulZero R[A] := inferInstanceAs (IsRightCancelMulZero (MonoidAlgebra R (Multiplicative A))) instance [IsCancelAdd R] [IsCancelMulZero R] [Add A] [UniqueSums A] : IsCancelMulZero R[A] where instance [IsCancelAdd R] [IsDomain R] [AddMonoid A] [UniqueSums A] : IsDomain R[A] where end AddMonoidAlgebra end Semiring
Projective.lean
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Antoine Labelle -/ import Mathlib.Algebra.Module.Shrink import Mathlib.LinearAlgebra.TensorProduct.Basis import Mathlib.Logic.UnivLE /-! # Projective modules This file contains a definition of a projective module, the proof that our definition is equivalent to a lifting property, and the proof that all free modules are projective. ## Main definitions Let `R` be a ring (or a semiring) and let `M` be an `R`-module. * `Module.Projective R M` : the proposition saying that `M` is a projective `R`-module. ## Main theorems * `Module.projective_lifting_property` : a map from a projective module can be lifted along a surjection. * `Module.Projective.of_lifting_property` : If for all R-module surjections `A →ₗ B`, all maps `M →ₗ B` lift to `M →ₗ A`, then `M` is projective. * `Module.Projective.of_free` : Free modules are projective ## Implementation notes The actual definition of projective we use is that the natural R-module map from the free R-module on the type M down to M splits. This is more convenient than certain other definitions which involve quantifying over universes, and also universe-polymorphic (the ring and module can be in different universes). We require that the module sits in at least as high a universe as the ring: without this, free modules don't even exist, and it's unclear if projective modules are even a useful notion. ## References https://en.wikipedia.org/wiki/Projective_module ## TODO - Direct sum of two projective modules is projective. - Arbitrary sum of projective modules is projective. All of these should be relatively straightforward. ## Tags projective module -/ universe w v u open LinearMap hiding id open Finsupp /- The actual implementation we choose: `P` is projective if the natural surjection from the free `R`-module on `P` to `P` splits. -/ /-- An R-module is projective if it is a direct summand of a free module, or equivalently if maps from the module lift along surjections. There are several other equivalent definitions. -/ class Module.Projective (R : Type*) [Semiring R] (P : Type*) [AddCommMonoid P] [Module R P] : Prop where out : ∃ s : P →ₗ[R] P →₀ R, Function.LeftInverse (Finsupp.linearCombination R id) s namespace Module section Semiring variable {R : Type*} [Semiring R] {P : Type*} [AddCommMonoid P] [Module R P] {M : Type*} [AddCommMonoid M] [Module R M] {N : Type*} [AddCommMonoid N] [Module R N] theorem projective_def : Projective R P ↔ ∃ s : P →ₗ[R] P →₀ R, Function.LeftInverse (linearCombination R id) s := ⟨fun h => h.1, fun h => ⟨h⟩⟩ theorem projective_def' : Projective R P ↔ ∃ s : P →ₗ[R] P →₀ R, Finsupp.linearCombination R id ∘ₗ s = .id := by simp_rw [projective_def, DFunLike.ext_iff, Function.LeftInverse, comp_apply, id_apply] /-- A projective R-module has the property that maps from it lift along surjections. -/ theorem projective_lifting_property [h : Projective R P] (f : M →ₗ[R] N) (g : P →ₗ[R] N) (hf : Function.Surjective f) : ∃ h : P →ₗ[R] M, f ∘ₗ h = g := by /- Here's the first step of the proof. Recall that `X →₀ R` is Lean's way of talking about the free `R`-module on a type `X`. The universal property `Finsupp.linearCombination` says that to a map `X → N` from a type to an `R`-module, we get an associated R-module map `(X →₀ R) →ₗ N`. Apply this to a (noncomputable) map `P → M` coming from the map `P →ₗ N` and a random splitting of the surjection `M →ₗ N`, and we get a map `φ : (P →₀ R) →ₗ M`. -/ let φ : (P →₀ R) →ₗ[R] M := Finsupp.linearCombination _ fun p => Function.surjInv hf (g p) -- By projectivity we have a map `P →ₗ (P →₀ R)`; obtain ⟨s, hs⟩ := h.out -- Compose to get `P →ₗ M`. This works. use φ.comp s ext p conv_rhs => rw [← hs p] simp [φ, Finsupp.linearCombination_apply, Function.surjInv_eq hf, map_finsuppSum] theorem _root_.LinearMap.exists_rightInverse_of_surjective [Projective R P] (f : M →ₗ[R] P) (hf_surj : range f = ⊤) : ∃ g : P →ₗ[R] M, f ∘ₗ g = LinearMap.id := projective_lifting_property f (.id : P →ₗ[R] P) (LinearMap.range_eq_top.1 hf_surj) open Function in theorem _root_.Function.Surjective.surjective_linearMapComp_left [Projective R P] {f : M →ₗ[R] P} (hf_surj : Surjective f) : Surjective (fun g : N →ₗ[R] M ↦ f.comp g) := surjective_comp_left_of_exists_rightInverse <| f.exists_rightInverse_of_surjective <| range_eq_top_of_surjective f hf_surj /-- A module which satisfies the universal property is projective: If all surjections of `R`-modules `(P →₀ R) →ₗ[R] P` have `R`-linear left inverse maps, then `P` is projective. -/ theorem Projective.of_lifting_property'' {R : Type u} [Semiring R] {P : Type v} [AddCommMonoid P] [Module R P] (huniv : ∀ (f : (P →₀ R) →ₗ[R] P), Function.Surjective f → ∃ h : P →ₗ[R] (P →₀ R), f.comp h = .id) : Projective R P := projective_def'.2 <| huniv (Finsupp.linearCombination R (id : P → P)) (linearCombination_surjective _ Function.surjective_id) variable {Q : Type*} [AddCommMonoid Q] [Module R Q] instance [Projective R P] [Projective R Q] : Projective R (P × Q) := by refine .of_lifting_property'' fun f hf ↦ ?_ rcases projective_lifting_property f (.inl _ _ _) hf with ⟨g₁, hg₁⟩ rcases projective_lifting_property f (.inr _ _ _) hf with ⟨g₂, hg₂⟩ refine ⟨coprod g₁ g₂, ?_⟩ rw [LinearMap.comp_coprod, hg₁, hg₂, LinearMap.coprod_inl_inr] variable {ι : Type*} (A : ι → Type*) [∀ i : ι, AddCommMonoid (A i)] [∀ i : ι, Module R (A i)] instance [h : ∀ i : ι, Projective R (A i)] : Projective R (Π₀ i, A i) := .of_lifting_property'' fun f hf ↦ by classical choose g hg using fun i ↦ projective_lifting_property f (DFinsupp.lsingle i) hf replace hg : ∀ i x, f (g i x) = DFinsupp.single i x := fun i ↦ DFunLike.congr_fun (hg i) refine ⟨DFinsupp.coprodMap g, ?_⟩ ext i x j simp only [comp_apply, id_apply, DFinsupp.lsingle_apply, DFinsupp.coprodMap_apply_single, hg] /-- Free modules are projective. -/ theorem Projective.of_basis {ι : Type*} (b : Basis ι R P) : Projective R P := by -- need P →ₗ (P →₀ R) for definition of projective. -- get it from `ι → (P →₀ R)` coming from `b`. use b.constr ℕ fun i => Finsupp.single (b i) (1 : R) intro m simp only [b.constr_apply, mul_one, id, Finsupp.smul_single', Finsupp.linearCombination_single, map_finsuppSum] exact b.linearCombination_repr m instance (priority := 100) Projective.of_free [Module.Free R P] : Module.Projective R P := .of_basis <| Module.Free.chooseBasis R P /-- A direct summand of a projective module is projective. -/ theorem Projective.of_split [Module.Projective R M] (i : P →ₗ[R] M) (s : M →ₗ[R] P) (H : s.comp i = LinearMap.id) : Module.Projective R P := by obtain ⟨g, hg⟩ := projective_lifting_property (Finsupp.linearCombination R id) s (fun x ↦ ⟨Finsupp.single x 1, by simp⟩) refine ⟨g.comp i, fun x ↦ ?_⟩ rw [LinearMap.comp_apply, ← LinearMap.comp_apply, hg, ← LinearMap.comp_apply, H, LinearMap.id_apply] theorem Projective.of_equiv [Module.Projective R M] (e : M ≃ₗ[R] P) : Module.Projective R P := Projective.of_split e.symm e.toLinearMap (by ext; simp) /-- A quotient of a projective module is projective iff it is a direct summand. -/ theorem Projective.iff_split_of_projective [Module.Projective R M] (s : M →ₗ[R] P) (hs : Function.Surjective s) : Module.Projective R P ↔ ∃ i, s ∘ₗ i = LinearMap.id := ⟨fun _ ↦ projective_lifting_property _ _ hs, fun ⟨i, H⟩ ↦ Projective.of_split i s H⟩ attribute [local instance] RingHomInvPair.of_ringEquiv in theorem Projective.of_ringEquiv {R S} [Semiring R] [Semiring S] {M N} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module S N] (e₁ : R ≃+* S) (e₂ : M ≃ₛₗ[RingHomClass.toRingHom e₁] N) [Projective R M] : Projective S N := by obtain ⟨f, hf⟩ := ‹Projective R M› let g : N →ₗ[S] N →₀ S := { toFun := fun x ↦ (equivCongrLeft e₂ (f (e₂.symm x))).mapRange e₁ e₁.map_zero map_add' := fun x y ↦ by ext; simp map_smul' := fun r v ↦ by ext i; simp [e₂.symm.map_smulₛₗ] } refine ⟨⟨g, fun x ↦ ?_⟩⟩ replace hf := congr(e₂ $(hf (e₂.symm x))) simpa [linearCombination_apply, sum_mapRange_index, g, map_finsuppSum, e₂.map_smulₛₗ] using hf end Semiring section Ring variable {R : Type u} [Semiring R] {P : Type v} [AddCommMonoid P] [Module R P] variable {R₀ M N} [CommSemiring R₀] [Algebra R₀ R] [AddCommMonoid M] [Module R₀ M] [Module R M] variable [IsScalarTower R₀ R M] [AddCommMonoid N] [Module R₀ N] /-- A variant of `Projective.iff_split` allowing for a more flexible selection of the universe for the free module `M`. -/ theorem Projective.iff_split' [Small.{w} R] [Small.{w} P] : Module.Projective R P ↔ ∃ (M : Type w) (_ : AddCommMonoid M) (_ : Module R M) (_ : Module.Free R M) (i : P →ₗ[R] M) (s : M →ₗ[R] P), s.comp i = LinearMap.id := by let e : (Shrink.{w, v} P →₀ Shrink.{w, u} R) ≃ₗ[R] P →₀ R := Finsupp.mapDomain.linearEquiv _ R (equivShrink P).symm ≪≫ₗ Finsupp.mapRange.linearEquiv (Shrink.linearEquiv R R) refine ⟨fun ⟨i, hi⟩ ↦ ⟨(Shrink.{w} P) →₀ (Shrink.{w} R), _, _, Free.of_basis ⟨e⟩, e.symm.toLinearMap ∘ₗ i, (linearCombination R id) ∘ₗ e.toLinearMap, ?_⟩, fun ⟨_, _, _, _, i, s, H⟩ ↦ Projective.of_split i s H⟩ apply LinearMap.ext simp only [coe_comp, LinearEquiv.coe_coe, Function.comp_apply, e.apply_symm_apply] exact hi /-- A module is projective iff it is the direct summand of a free module. -/ theorem Projective.iff_split : Module.Projective R P ↔ ∃ (M : Type max u v) (_ : AddCommMonoid M) (_ : Module R M) (_ : Module.Free R M) (i : P →ₗ[R] M) (s : M →ₗ[R] P), s.comp i = LinearMap.id := Projective.iff_split'.{max u v} open TensorProduct in instance Projective.tensorProduct [hM : Module.Projective R M] [hN : Module.Projective R₀ N] : Module.Projective R (M ⊗[R₀] N) := by obtain ⟨sM, hsM⟩ := hM obtain ⟨sN, hsN⟩ := hN have : Module.Projective R (M ⊗[R₀] (N →₀ R₀)) := by fapply Projective.of_split (R := R) (M := ((M →₀ R) ⊗[R₀] (N →₀ R₀))) · exact (AlgebraTensorModule.map sM (LinearMap.id (R := R₀) (M := N →₀ R₀))) · exact (AlgebraTensorModule.map (Finsupp.linearCombination R id) (LinearMap.id (R := R₀) (M := N →₀ R₀))) · ext; simp [hsM _] fapply Projective.of_split (R := R) (M := (M ⊗[R₀] (N →₀ R₀))) · exact (AlgebraTensorModule.map (LinearMap.id (R := R) (M := M)) sN) · exact (AlgebraTensorModule.map (LinearMap.id (R := R) (M := M)) (linearCombination R₀ id)) · ext; simp [hsN _] end Ring section OfLiftingProperty /-- A module which satisfies the universal property is projective. -/ theorem Projective.of_lifting_property' {R : Type u} [Semiring R] {P : Type v} [AddCommMonoid P] [Module R P] [Small.{v} R] -- If for all surjections of `R`-modules `M →ₗ N`, all maps `P →ₗ N` lift to `P →ₗ M`, (h : ∀ {M : Type v} {N : Type v} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] (f : M →ₗ[R] N) (g : P →ₗ[R] N), Function.Surjective f → ∃ h : P →ₗ[R] M, f.comp h = g) : -- then `P` is projective. Projective R P := by refine of_lifting_property'' (fun p hp ↦ ?_) let e := Finsupp.mapRange.linearEquiv (α := P) (Shrink.linearEquiv R R) rcases h (p ∘ₗ e.toLinearMap) LinearMap.id (hp.comp e.surjective) with ⟨g, hg⟩ exact ⟨e.toLinearMap ∘ₗ g, hg⟩ /-- A variant of `of_lifting_property'` when we're working over a `[Ring R]`, which only requires quantifying over modules with an `AddCommGroup` instance. -/ theorem Projective.of_lifting_property {R : Type u} [Ring R] {P : Type v} [AddCommGroup P] [Module R P] [Small.{v} R] -- If for all surjections of `R`-modules `M →ₗ N`, all maps `P →ₗ N` lift to `P →ₗ M`, (h : ∀ {M : Type v} {N : Type v} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] (f : M →ₗ[R] N) (g : P →ₗ[R] N), Function.Surjective f → ∃ h : P →ₗ[R] M, f.comp h = g) : -- then `P` is projective. Projective R P := by refine of_lifting_property'' (fun p hp ↦ ?_) let e := Finsupp.mapRange.linearEquiv (α := P) (Shrink.linearEquiv R R) rcases h (p ∘ₗ e.toLinearMap) LinearMap.id (hp.comp e.surjective) with ⟨g, hg⟩ exact ⟨e.toLinearMap ∘ₗ g, hg⟩ end OfLiftingProperty end Module
Order.lean
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Order.Hom.Ring import Mathlib.Algebra.Order.Ring.InjSurj import Mathlib.Algebra.Ring.Subring.Defs /-! # Subrings of ordered rings We study subrings of ordered rings and prove their basic properties. ## Main definitions and results * `Subring.orderedSubtype`: the inclusion `S → R` of a subring as an ordered ring homomorphism * various ordered instances: a subring of an `OrderedRing`, `OrderedCommRing`, `LinearOrderedRing`, `toLinearOrderedCommRing` is again an ordering ring -/ namespace Subring variable {R : Type*} /-- A subring of an ordered ring is an ordered ring. -/ instance toIsOrderedRing [Ring R] [PartialOrder R] [IsOrderedRing R] (s : Subring R) : IsOrderedRing s := Subtype.coe_injective.isOrderedRing Subtype.val rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- A subring of a strict ordered ring is a strict ordered ring. -/ instance toIsStrictOrderedRing [Ring R] [PartialOrder R] [IsStrictOrderedRing R] (s : Subring R) : IsStrictOrderedRing s := Subtype.coe_injective.isStrictOrderedRing Subtype.val rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl /-- The inclusion `S → R` of a subring, as an ordered ring homomorphism. -/ def orderedSubtype {R : Type*} [Ring R] [PartialOrder R] (s : Subring R) : s →+*o R where __ := s.subtype monotone' := fun _ _ h ↦ h variable {R : Type*} [Ring R] [PartialOrder R] lemma orderedSubtype_coe (s : Subring R) : Subring.orderedSubtype s = Subring.subtype s := rfl end Subring
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.
Imo1961Q3.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.Analysis.SpecialFunctions.Trigonometric.Complex /-! # IMO 1961 Q3 Solve the equation $\cos^n x - \sin^n x = 1$, where $n$ is a given positive integer. The solution is based on the one at the [Art of Problem Solving](https://artofproblemsolving.com/wiki/index.php/1961_IMO_Problems/Problem_3) website. -/ open Real theorem Imo1961Q3 {n : ℕ} {x : ℝ} (h₀ : n ≠ 0) : (cos x) ^ n - (sin x) ^ n = 1 ↔ (∃ k : ℤ, k * π = x) ∧ Even n ∨ (∃ k : ℤ, k * (2 * π) = x) ∧ Odd n ∨ (∃ k : ℤ, -(π / 2) + k * (2 * π) = x) ∧ Odd n := by constructor · intro h rcases eq_or_ne (sin x) 0 with hsinx | hsinx · rw [hsinx, zero_pow h₀, sub_zero, pow_eq_one_iff_of_ne_zero h₀, cos_eq_one_iff, cos_eq_neg_one_iff] at h rcases h with ⟨k, rfl⟩ | ⟨⟨k, rfl⟩, hn⟩ · cases n.even_or_odd with | inl hn => refine .inl ⟨⟨k * 2, ?_⟩, hn⟩; simp [mul_assoc] | inr hn => exact .inr <| .inl ⟨⟨_, rfl⟩, hn⟩ · exact .inl ⟨⟨2 * k + 1, by push_cast; ring⟩, hn⟩ · rcases eq_or_ne (cos x) 0 with hcosx | hcosx · right; right rw [hcosx, zero_pow h₀, zero_sub, ← neg_inj, neg_neg, pow_eq_neg_one_iff, sin_eq_neg_one_iff] at h simpa only [eq_comm] using h · have hcos1 : |cos x| < 1 := by rw [abs_cos_eq_sqrt_one_sub_sin_sq, sqrt_lt' one_pos] simp [sq_pos_of_ne_zero hsinx] have hsin1 : |sin x| < 1 := by rw [abs_sin_eq_sqrt_one_sub_cos_sq, sqrt_lt' one_pos] simp [sq_pos_of_ne_zero hcosx] match n with | 1 => rw [pow_one, pow_one, sub_eq_iff_eq_add] at h have : 2 * sin x * cos x = 0 := by simpa [h, add_sq, add_assoc, ← two_mul, mul_add, mul_assoc, ← sq] using cos_sq_add_sin_sq x simp [hsinx, hcosx] at this | 2 => rw [← cos_sq_add_sin_sq x, sub_eq_add_neg, add_right_inj, neg_eq_self ℝ] at h exact absurd (pow_eq_zero h) hsinx | (n + 1 + 2) => set m := n + 1 refine absurd ?_ h.not_lt calc (cos x) ^ (m + 2) - (sin x) ^ (m + 2) ≤ |cos x| ^ (m + 2) + |sin x| ^ (m + 2) := by simp only [← abs_pow, sub_eq_add_neg] gcongr exacts [le_abs_self _, neg_le_abs _] _ = |cos x| ^ m * cos x ^ 2 + |sin x| ^ m * sin x ^ 2 := by simp [pow_add] _ < 1 ^ m * cos x ^ 2 + 1 ^ m * sin x ^ 2 := by gcongr _ = 1 := by simp · rintro (⟨⟨k, rfl⟩, hn⟩ | ⟨⟨k, rfl⟩, -⟩ | ⟨⟨k, rfl⟩, hn⟩) · rw [sin_int_mul_pi, zero_pow h₀, sub_zero, ← hn.pow_abs, abs_cos_int_mul_pi, one_pow] · have : sin (k * (2 * π)) = 0 := by simpa [mul_assoc] using sin_int_mul_pi (k * 2) simp [h₀, this] · simp [hn.neg_pow, h₀]
Opposite.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.GroupWithZero.NeZero /-! # Opposites of groups with zero -/ assert_not_exists Ring variable {α : Type*} namespace MulOpposite instance instMulZeroClass [MulZeroClass α] : MulZeroClass αᵐᵒᵖ where zero_mul _ := unop_injective <| mul_zero _ mul_zero _ := unop_injective <| zero_mul _ instance instMulZeroOneClass [MulZeroOneClass α] : MulZeroOneClass αᵐᵒᵖ where __ := instMulOneClass __ := instMulZeroClass instance instSemigroupWithZero [SemigroupWithZero α] : SemigroupWithZero αᵐᵒᵖ where __ := instSemigroup __ := instMulZeroClass instance instMonoidWithZero [MonoidWithZero α] : MonoidWithZero αᵐᵒᵖ where __ := instMonoid __ := instMulZeroOneClass instance instGroupWithZero [GroupWithZero α] : GroupWithZero αᵐᵒᵖ where __ := instMonoidWithZero __ := instNontrivial __ := instDivInvMonoid mul_inv_cancel _ hx := unop_injective <| inv_mul_cancel₀ <| unop_injective.ne hx inv_zero := unop_injective inv_zero instance instNoZeroDivisors [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors αᵐᵒᵖ where eq_zero_or_eq_zero_of_mul_eq_zero (H : op (_ * _) = op (0 : α)) := Or.casesOn (eq_zero_or_eq_zero_of_mul_eq_zero <| op_injective H) (fun hy => Or.inr <| unop_injective <| hy) fun hx => Or.inl <| unop_injective <| hx instance [Mul α] [Zero α] [IsLeftCancelMulZero α] : IsRightCancelMulZero αᵐᵒᵖ where mul_right_cancel_of_ne_zero h _ _ eq := unop_injective <| mul_left_cancel₀ (unop_injective.ne_iff.mpr h) (congr_arg unop eq) instance [Mul α] [Zero α] [IsRightCancelMulZero α] : IsLeftCancelMulZero αᵐᵒᵖ where mul_left_cancel_of_ne_zero h _ _ eq := unop_injective <| mul_right_cancel₀ (unop_injective.ne_iff.mpr h) (congr_arg unop eq) instance [Mul α] [Zero α] [IsCancelMulZero α] : IsCancelMulZero αᵐᵒᵖ where @[simp] theorem isLeftCancelMulZero_iff [Mul α] [Zero α] : IsLeftCancelMulZero αᵐᵒᵖ ↔ IsRightCancelMulZero α where mp _ := (op_injective.comp op_injective).isRightCancelMulZero _ rfl fun _ _ ↦ rfl mpr _ := inferInstance @[simp] theorem isRightCancelMulZero_iff [Mul α] [Zero α] : IsRightCancelMulZero αᵐᵒᵖ ↔ IsLeftCancelMulZero α where mp _ := (op_injective.comp op_injective).isLeftCancelMulZero _ rfl fun _ _ ↦ rfl mpr _ := inferInstance @[simp] theorem isCancelMulZero_iff [Mul α] [Zero α] : IsCancelMulZero αᵐᵒᵖ ↔ IsCancelMulZero α where mp _ := (op_injective.comp op_injective).isCancelMulZero _ rfl fun _ _ ↦ rfl mpr _ := inferInstance end MulOpposite namespace AddOpposite instance instMulZeroClass [MulZeroClass α] : MulZeroClass αᵃᵒᵖ where zero_mul _ := unop_injective <| zero_mul _ mul_zero _ := unop_injective <| mul_zero _ instance instMulZeroOneClass [MulZeroOneClass α] : MulZeroOneClass αᵃᵒᵖ where __ := instMulOneClass __ := instMulZeroClass instance instSemigroupWithZero [SemigroupWithZero α] : SemigroupWithZero αᵃᵒᵖ where __ := instSemigroup __ := instMulZeroClass instance instMonoidWithZero [MonoidWithZero α] : MonoidWithZero αᵃᵒᵖ where __ := instMonoid __ := instMulZeroOneClass instance instNoZeroDivisors [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors αᵃᵒᵖ where eq_zero_or_eq_zero_of_mul_eq_zero (H : op (_ * _) = op (0 : α)) := Or.imp (fun hx => unop_injective hx) (fun hy => unop_injective hy) (@eq_zero_or_eq_zero_of_mul_eq_zero α _ _ _ _ _ <| op_injective H) instance instGroupWithZero [GroupWithZero α] : GroupWithZero αᵃᵒᵖ where __ := instMonoidWithZero __ := instNontrivial __ := instDivInvMonoid mul_inv_cancel _ hx := unop_injective <| mul_inv_cancel₀ <| unop_injective.ne hx inv_zero := unop_injective inv_zero end AddOpposite
MeanInequalities.lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.Algebra.BigOperators.Expect import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.Convex.Jensen import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Data.Real.ConjExponents /-! # Mean value inequalities In this file we prove several inequalities for finite sums, including AM-GM inequality, HM-GM inequality, Young's inequality, Hölder inequality, and Minkowski inequality. Versions for integrals of some of these inequalities are available in `Mathlib/MeasureTheory/Integral/MeanInequalities.lean`. ## Main theorems ### AM-GM inequality: The inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal to their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$ are two non-negative vectors and $\sum_{i\in s} w_i=1$, then $$ \prod_{i\in s} z_i^{w_i} ≤ \sum_{i\in s} w_iz_i. $$ The classical version is a special case of this inequality for $w_i=\frac{1}{n}$. We prove a few versions of this inequality. Each of the following lemmas comes in two versions: a version for real-valued non-negative functions is in the `Real` namespace, and a version for `NNReal`-valued functions is in the `NNReal` namespace. - `geom_mean_le_arith_mean_weighted` : weighted version for functions on `Finset`s; - `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers; - `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers; - `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers. ### HM-GM inequality: The inequality says that the harmonic mean of a tuple of positive numbers is less than or equal to their geometric mean. We prove the weighted version of this inequality: if $w$ and $z$ are two positive vectors and $\sum_{i\in s} w_i=1$, then $$ 1/(\sum_{i\in s} w_i/z_i) ≤ \prod_{i\in s} z_i^{w_i} $$ The classical version is proven as a special case of this inequality for $w_i=\frac{1}{n}$. The inequalities are proven only for real valued positive functions on `Finset`s, and namespaced in `Real`. The weighted version follows as a corollary of the weighted AM-GM inequality. ### Young's inequality Young's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that $\frac{1}{p}+\frac{1}{q}=1$ we have $$ ab ≤ \frac{a^p}{p} + \frac{b^q}{q}. $$ This inequality is a special case of the AM-GM inequality. It is then used to prove Hölder's inequality (see below). ### Hölder's inequality The inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers such that $\frac{1}{p}+\frac{1}{q}=1$) and any two non-negative vectors their inner product is less than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the second vector: $$ \sum_{i\in s} a_ib_i ≤ \sqrt[p]{\sum_{i\in s} a_i^p}\sqrt[q]{\sum_{i\in s} b_i^q}. $$ We give versions of this result in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. There are at least two short proofs of this inequality. In our proof we prenormalize both vectors, then apply Young's inequality to each $a_ib_i$. Another possible proof would be to deduce this inequality from the generalized mean inequality for well-chosen vectors and weights. ### Minkowski's inequality The inequality says that for `p ≥ 1` the function $$ \|a\|_p=\sqrt[p]{\sum_{i\in s} a_i^p} $$ satisfies the triangle inequality $\|a+b\|_p\le \|a\|_p+\|b\|_p$. We give versions of this result in `Real`, `ℝ≥0` and `ℝ≥0∞`. We deduce this inequality from Hölder's inequality. Namely, Hölder inequality implies that $\|a\|_p$ is the maximum of the inner product $\sum_{i\in s}a_ib_i$ over `b` such that $\|b\|_q\le 1$. Now Minkowski's inequality follows from the fact that the maximum value of the sum of two functions is less than or equal to the sum of the maximum values of the summands. ## TODO - each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them is to define `StrictConvexOn` functions. - generalized mean inequality with any `p ≤ q`, including negative numbers; - prove that the power mean tends to the geometric mean as the exponent tends to zero. -/ universe u v open Finset NNReal ENNReal open scoped BigOperators noncomputable section variable {ι : Type u} (s : Finset ι) section GeomMeanLEArithMean /-! ### AM-GM inequality -/ namespace Real /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for real-valued nonnegative functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i ≤ ∑ i ∈ s, w i * z i := by -- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative. by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0 · rcases A with ⟨i, his, hzi, hwi⟩ rw [prod_eq_zero his] · exact sum_nonneg fun j hj => mul_nonneg (hw j hj) (hz j hj) · rw [hzi] exact zero_rpow hwi -- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality -- for `exp` and numbers `log (z i)` with weights `w i`. · simp only [not_exists, not_and, Ne, Classical.not_not] at A have := convexOn_exp.map_sum_le hw hw' fun i _ => Set.mem_univ <| log (z i) simp only [exp_sum, smul_eq_mul, mul_comm (w _) (log _)] at this convert this using 1 <;> [apply prod_congr rfl;apply sum_congr rfl] <;> intro i hi · rcases eq_or_lt_of_le (hz i hi) with hz | hz · simp [A i hi hz.symm] · exact rpow_def_of_pos hz _ · rcases eq_or_lt_of_le (hz i hi) with hz | hz · simp [A i hi hz.symm] · rw [exp_log hz] /-- **AM-GM inequality**: The **geometric mean is less than or equal to the arithmetic mean. -/ theorem geom_mean_le_arith_mean {ι : Type*} (s : Finset ι) (w : ι → ℝ) (z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : 0 < ∑ i ∈ s, w i) (hz : ∀ i ∈ s, 0 ≤ z i) : (∏ i ∈ s, z i ^ w i) ^ (∑ i ∈ s, w i)⁻¹ ≤ (∑ i ∈ s, w i * z i) / (∑ i ∈ s, w i) := by convert geom_mean_le_arith_mean_weighted s (fun i => (w i) / ∑ i ∈ s, w i) z ?_ ?_ hz using 2 · rw [← finset_prod_rpow _ _ (fun i hi => rpow_nonneg (hz _ hi) _) _] refine Finset.prod_congr rfl (fun _ ih => ?_) rw [div_eq_mul_inv, rpow_mul (hz _ ih)] · simp_rw [div_eq_mul_inv, mul_assoc, mul_comm, ← mul_assoc, ← Finset.sum_mul, mul_comm] · exact fun _ hi => div_nonneg (hw _ hi) (le_of_lt hw') · simp_rw [div_eq_mul_inv, ← Finset.sum_mul] exact mul_inv_cancel₀ (by linarith) theorem geom_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∏ i ∈ s, z i ^ w i = x := calc ∏ i ∈ s, z i ^ w i = ∏ i ∈ s, x ^ w i := by refine prod_congr rfl fun i hi => ?_ rcases eq_or_ne (w i) 0 with h₀ | h₀ · rw [h₀, rpow_zero, rpow_zero] · rw [hx i hi h₀] _ = x := by rw [← rpow_sum_of_nonneg _ hw, hw', rpow_one] have : (∑ i ∈ s, w i) ≠ 0 := by rw [hw'] exact one_ne_zero obtain ⟨i, his, hi⟩ := exists_ne_zero_of_sum_ne_zero this rw [← hx i his hi] exact hz i his theorem arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw' : ∑ i ∈ s, w i = 1) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∑ i ∈ s, w i * z i = x := calc ∑ i ∈ s, w i * z i = ∑ i ∈ s, w i * x := by refine sum_congr rfl fun i hi => ?_ rcases eq_or_ne (w i) 0 with hwi | hwi · rw [hwi, zero_mul, zero_mul] · rw [hx i hi hwi] _ = x := by rw [← sum_mul, hw', one_mul] theorem geom_mean_eq_arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i := by rw [geom_mean_weighted_of_constant, arith_mean_weighted_of_constant] <;> assumption /-- **AM-GM inequality - equality condition**: This theorem provides the equality condition for the *positive* weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_eq_arith_mean_weighted_iff' (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i ↔ ∀ j ∈ s, z j = ∑ i ∈ s, w i * z i := by by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0 · rcases A with ⟨i, his, hzi, hwi⟩ rw [prod_eq_zero his] · constructor · intro h rw [← h] intro j hj apply eq_zero_of_ne_zero_of_mul_left_eq_zero (ne_of_lt (hw j hj)).symm apply (sum_eq_zero_iff_of_nonneg ?_).mp h.symm j hj exact fun i hi => (mul_nonneg_iff_of_pos_left (hw i hi)).mpr (hz i hi) · intro h convert h i his exact hzi.symm · rw [hzi] exact zero_rpow hwi · simp only [not_exists, not_and] at A have hz' := fun i h => lt_of_le_of_ne (hz i h) (fun a => (A i h a.symm) (ne_of_gt (hw i h))) have := strictConvexOn_exp.map_sum_eq_iff hw hw' fun i _ => Set.mem_univ <| log (z i) simp only [exp_sum, smul_eq_mul, mul_comm (w _) (log _)] at this convert this using 1 · apply Eq.congr <;> [apply prod_congr rfl; apply sum_congr rfl] <;> intro i hi <;> simp only [exp_mul, exp_log (hz' i hi)] · constructor <;> intro h j hj · rw [← arith_mean_weighted_of_constant s w _ (log (z j)) hw' fun i _ => congrFun rfl] apply sum_congr rfl intro x hx simp only [mul_comm, h j hj, h x hx] · rw [← arith_mean_weighted_of_constant s w _ (z j) hw' fun i _ => congrFun rfl] apply sum_congr rfl intro x hx simp only [log_injOn_pos (hz' j hj) (hz' x hx), h j hj, h x hx] /-- **AM-GM inequality - equality condition**: This theorem provides the equality condition for the weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_eq_arith_mean_weighted_iff (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i ↔ ∀ j ∈ s, w j ≠ 0 → z j = ∑ i ∈ s, w i * z i := by have h (i) (_ : i ∈ s) : w i * z i ≠ 0 → w i ≠ 0 := by apply left_ne_zero_of_mul have h' (i) (_ : i ∈ s) : z i ^ w i ≠ 1 → w i ≠ 0 := by by_contra! obtain ⟨h1, h2⟩ := this simp only [h2, rpow_zero, ne_self_iff_false] at h1 rw [← sum_filter_of_ne h, ← prod_filter_of_ne h', geom_mean_eq_arith_mean_weighted_iff'] · simp · simp +contextual [(hw _ _).lt_iff_ne'] · rwa [sum_filter_ne_zero] · simp_all only [ne_eq, mul_eq_zero, not_or, not_false_eq_true, implies_true, mem_filter] /-- **AM-GM inequality - strict inequality condition**: This theorem provides the strict inequality condition for the *positive* weighted version of the AM-GM inequality for real-valued nonnegative functions. -/ theorem geom_mean_lt_arith_mean_weighted_iff_of_pos (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : ∏ i ∈ s, z i ^ w i < ∑ i ∈ s, w i * z i ↔ ∃ j ∈ s, ∃ k ∈ s, z j ≠ z k:= by constructor · intro h by_contra! h_contra rw [(geom_mean_eq_arith_mean_weighted_iff' s w z hw hw' hz).mpr ?_] at h · exact (lt_self_iff_false _).mp h · intro j hjs rw [← arith_mean_weighted_of_constant s w (fun _ => z j) (z j) hw' fun _ _ => congrFun rfl] apply sum_congr rfl (fun x a => congrArg (HMul.hMul (w x)) (h_contra j hjs x a)) · rintro ⟨j, hjs, k, hks, hzjk⟩ have := geom_mean_le_arith_mean_weighted s w z (fun i a => le_of_lt (hw i a)) hw' hz by_contra! h apply le_antisymm this at h apply (geom_mean_eq_arith_mean_weighted_iff' s w z hw hw' hz).mp at h simp only [h j hjs, h k hks, ne_eq, not_true_eq_false] at hzjk end Real namespace NNReal /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for `NNReal`-valued functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) : (∏ i ∈ s, z i ^ (w i : ℝ)) ≤ ∑ i ∈ s, w i * z i := mod_cast Real.geom_mean_le_arith_mean_weighted _ _ _ (fun i _ => (w i).coe_nonneg) (by assumption_mod_cast) fun i _ => (z i).coe_nonneg /-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted version for two `NNReal` numbers. -/ theorem geom_mean_le_arith_mean2_weighted (w₁ w₂ p₁ p₂ : ℝ≥0) : w₁ + w₂ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂] ![p₁, p₂] theorem geom_mean_le_arith_mean3_weighted (w₁ w₂ w₃ p₁ p₂ p₃ : ℝ≥0) : w₁ + w₂ + w₃ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃] ![p₁, p₂, p₃] theorem geom_mean_le_arith_mean4_weighted (w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ≥0) : w₁ + w₂ + w₃ + w₄ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) * p₄ ^ (w₄ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := by simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty, Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃, w₄] ![p₁, p₂, p₃, p₄] end NNReal namespace Real theorem geom_mean_le_arith_mean2_weighted {w₁ w₂ p₁ p₂ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hw : w₁ + w₂ = 1) : p₁ ^ w₁ * p₂ ^ w₂ ≤ w₁ * p₁ + w₂ * p₂ := NNReal.geom_mean_le_arith_mean2_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ <| NNReal.coe_inj.1 <| by assumption theorem geom_mean_le_arith_mean3_weighted {w₁ w₂ w₃ p₁ p₂ p₃ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hw : w₁ + w₂ + w₃ = 1) : p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := NNReal.geom_mean_le_arith_mean3_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ <| NNReal.coe_inj.1 hw theorem geom_mean_le_arith_mean4_weighted {w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hw₄ : 0 ≤ w₄) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hp₄ : 0 ≤ p₄) (hw : w₁ + w₂ + w₃ + w₄ = 1) : p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ * p₄ ^ w₄ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := NNReal.geom_mean_le_arith_mean4_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨w₄, hw₄⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ ⟨p₄, hp₄⟩ <| NNReal.coe_inj.1 <| by assumption end Real end GeomMeanLEArithMean section HarmMeanLEGeomMean /-! ### HM-GM inequality -/ namespace Real /-- **HM-GM inequality**: The harmonic mean is less than or equal to the geometric mean, weighted version for real-valued nonnegative functions. -/ theorem harm_mean_le_geom_mean_weighted (w z : ι → ℝ) (hs : s.Nonempty) (hw : ∀ i ∈ s, 0 < w i) (hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 < z i) : (∑ i ∈ s, w i / z i)⁻¹ ≤ ∏ i ∈ s, z i ^ w i := by have : ∏ i ∈ s, (1 / z) i ^ w i ≤ ∑ i ∈ s, w i * (1 / z) i := geom_mean_le_arith_mean_weighted s w (1/z) (fun i hi ↦ le_of_lt (hw i hi)) hw' (fun i hi ↦ one_div_nonneg.2 (le_of_lt (hz i hi))) have p_pos : 0 < ∏ i ∈ s, (z i)⁻¹ ^ w i := prod_pos fun i hi => rpow_pos_of_pos (inv_pos.2 (hz i hi)) _ have s_pos : 0 < ∑ i ∈ s, w i * (z i)⁻¹ := sum_pos (fun i hi => mul_pos (hw i hi) (inv_pos.2 (hz i hi))) hs norm_num at this rw [← inv_le_inv₀ s_pos p_pos] at this apply le_trans this have p_pos₂ : 0 < (∏ i ∈ s, (z i) ^ w i)⁻¹ := inv_pos.2 (prod_pos fun i hi => rpow_pos_of_pos ((hz i hi)) _ ) rw [← inv_inv (∏ i ∈ s, z i ^ w i), inv_le_inv₀ p_pos p_pos₂, ← Finset.prod_inv_distrib] gcongr · exact fun i hi ↦ inv_nonneg.mpr (Real.rpow_nonneg (le_of_lt (hz i hi)) _) · rw [Real.inv_rpow]; apply fun i hi ↦ le_of_lt (hz i hi); assumption /-- **HM-GM inequality**: The **harmonic mean is less than or equal to the geometric mean. -/ theorem harm_mean_le_geom_mean {ι : Type*} (s : Finset ι) (hs : s.Nonempty) (w : ι → ℝ) (z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i) (hw' : 0 < ∑ i ∈ s, w i) (hz : ∀ i ∈ s, 0 < z i) : (∑ i ∈ s, w i) / (∑ i ∈ s, w i / z i) ≤ (∏ i ∈ s, z i ^ w i) ^ (∑ i ∈ s, w i)⁻¹ := by have := harm_mean_le_geom_mean_weighted s (fun i => (w i) / ∑ i ∈ s, w i) z hs ?_ ?_ hz · simp only at this set n := ∑ i ∈ s, w i nth_rw 1 [div_eq_mul_inv, (show n = (n⁻¹)⁻¹ by simp), ← mul_inv, Finset.mul_sum _ _ n⁻¹] simp_rw [inv_mul_eq_div n ((w _)/(z _)), div_right_comm _ _ n] convert this rw [← Real.finset_prod_rpow s _ (fun i hi ↦ Real.rpow_nonneg (le_of_lt <| hz i hi) _)] refine Finset.prod_congr rfl (fun i hi => ?_) rw [← Real.rpow_mul (le_of_lt <| hz i hi) (w _) n⁻¹, div_eq_mul_inv (w _) n] · exact fun i hi ↦ div_pos (hw i hi) hw' · simp_rw [div_eq_mul_inv (w _) (∑ i ∈ s, w i), ← Finset.sum_mul _ _ (∑ i ∈ s, w i)⁻¹] exact mul_inv_cancel₀ hw'.ne' end Real end HarmMeanLEGeomMean section Young /-! ### Young's inequality -/ namespace Real /-- **Young's inequality**, a version for nonnegative real numbers. -/ theorem young_inequality_of_nonneg {a b p q : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hpq : p.HolderConjugate q) : a * b ≤ a ^ p / p + b ^ q / q := by simpa [← rpow_mul, ha, hb, hpq.ne_zero, hpq.symm.ne_zero, _root_.div_eq_inv_mul] using geom_mean_le_arith_mean2_weighted hpq.inv_nonneg hpq.symm.inv_nonneg (rpow_nonneg ha p) (rpow_nonneg hb q) hpq.inv_add_inv_eq_one /-- **Young's inequality**, a version for arbitrary real numbers. -/ theorem young_inequality (a b : ℝ) {p q : ℝ} (hpq : p.HolderConjugate q) : a * b ≤ |a| ^ p / p + |b| ^ q / q := calc a * b ≤ |a * b| := le_abs_self (a * b) _ = |a| * |b| := abs_mul a b _ ≤ |a| ^ p / p + |b| ^ q / q := Real.young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq end Real namespace NNReal /-- **Young's inequality**, `ℝ≥0` version. We use `{p q : ℝ≥0}` in order to avoid constructing witnesses of `0 ≤ p` and `0 ≤ q` for the denominators. -/ theorem young_inequality (a b : ℝ≥0) {p q : ℝ≥0} (hpq : p.HolderConjugate q) : a * b ≤ a ^ (p : ℝ) / p + b ^ (q : ℝ) / q := Real.young_inequality_of_nonneg a.coe_nonneg b.coe_nonneg hpq.coe /-- **Young's inequality**, `ℝ≥0` version with real conjugate exponents. -/ theorem young_inequality_real (a b : ℝ≥0) {p q : ℝ} (hpq : p.HolderConjugate q) : a * b ≤ a ^ p / Real.toNNReal p + b ^ q / Real.toNNReal q := by simpa [Real.coe_toNNReal, hpq.nonneg, hpq.symm.nonneg] using young_inequality a b hpq.toNNReal end NNReal namespace ENNReal /-- **Young's inequality**, `ℝ≥0∞` version with real conjugate exponents. -/ theorem young_inequality (a b : ℝ≥0∞) {p q : ℝ} (hpq : p.HolderConjugate q) : a * b ≤ a ^ p / ENNReal.ofReal p + b ^ q / ENNReal.ofReal q := by by_cases h : a = ⊤ ∨ b = ⊤ · refine le_trans le_top (le_of_eq ?_) repeat rw [div_eq_mul_inv] rcases h with h | h <;> rw [h] <;> simp [hpq.pos, hpq.symm.pos] push_neg at h -- if a ≠ ⊤ and b ≠ ⊤, use the nnreal version: nnreal.young_inequality_real rw [← coe_toNNReal h.left, ← coe_toNNReal h.right, ← coe_mul, ← coe_rpow_of_nonneg _ hpq.nonneg, ← coe_rpow_of_nonneg _ hpq.symm.nonneg, ENNReal.ofReal, ENNReal.ofReal, ← @coe_div (Real.toNNReal p) _ (by simp [hpq.pos]), ← @coe_div (Real.toNNReal q) _ (by simp [hpq.symm.pos]), ← coe_add, coe_le_coe] exact NNReal.young_inequality_real a.toNNReal b.toNNReal hpq end ENNReal end Young section HoelderMinkowski /-! ### Hölder's and Minkowski's inequalities -/ namespace NNReal private theorem inner_le_Lp_mul_Lp_of_norm_le_one (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.HolderConjugate q) (hf : ∑ i ∈ s, f i ^ p ≤ 1) (hg : ∑ i ∈ s, g i ^ q ≤ 1) : ∑ i ∈ s, f i * g i ≤ 1 := by have hp : 0 < p.toNNReal := zero_lt_one.trans hpq.toNNReal.lt have hq : 0 < q.toNNReal := zero_lt_one.trans hpq.toNNReal.symm.lt calc ∑ i ∈ s, f i * g i ≤ ∑ i ∈ s, (f i ^ p / Real.toNNReal p + g i ^ q / Real.toNNReal q) := Finset.sum_le_sum fun i _ => young_inequality_real (f i) (g i) hpq _ = (∑ i ∈ s, f i ^ p) / Real.toNNReal p + (∑ i ∈ s, g i ^ q) / Real.toNNReal q := by rw [sum_add_distrib, sum_div, sum_div] _ ≤ 1 / Real.toNNReal p + 1 / Real.toNNReal q := by refine add_le_add ?_ ?_ <;> rwa [div_le_iff₀, div_mul_cancel₀] <;> positivity _ = 1 := by simp_rw [one_div, hpq.toNNReal.inv_add_inv_eq_one] private theorem inner_le_Lp_mul_Lp_of_norm_eq_zero (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.HolderConjugate q) (hf : ∑ i ∈ s, f i ^ p = 0) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by simp only [hf, hpq.ne_zero, one_div, sum_eq_zero_iff, zero_rpow, zero_mul, inv_eq_zero, Ne, not_false_iff, le_zero_iff, mul_eq_zero] intro i his left rw [sum_eq_zero_iff] at hf exact (rpow_eq_zero_iff.mp (hf i his)).left /-- **Hölder inequality**: The scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with `ℝ≥0`-valued functions. -/ theorem inner_le_Lp_mul_Lq (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.HolderConjugate q) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by obtain hf | hf := eq_zero_or_pos (∑ i ∈ s, f i ^ p) · exact inner_le_Lp_mul_Lp_of_norm_eq_zero s f g hpq hf obtain hg | hg := eq_zero_or_pos (∑ i ∈ s, g i ^ q) · calc ∑ i ∈ s, f i * g i = ∑ i ∈ s, g i * f i := by congr with i rw [mul_comm] _ ≤ (∑ i ∈ s, g i ^ q) ^ (1 / q) * (∑ i ∈ s, f i ^ p) ^ (1 / p) := (inner_le_Lp_mul_Lp_of_norm_eq_zero s g f hpq.symm hg) _ = (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := mul_comm _ _ let f' i := f i / (∑ i ∈ s, f i ^ p) ^ (1 / p) let g' i := g i / (∑ i ∈ s, g i ^ q) ^ (1 / q) suffices (∑ i ∈ s, f' i * g' i) ≤ 1 by simp_rw [f', g', div_mul_div_comm, ← sum_div] at this rwa [div_le_iff₀, one_mul] at this -- TODO: We are missing a positivity extension here exact mul_pos (rpow_pos hf) (rpow_pos hg) refine inner_le_Lp_mul_Lp_of_norm_le_one s f' g' hpq (le_of_eq ?_) (le_of_eq ?_) · simp_rw [f', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel₀ hpq.ne_zero, rpow_one, div_self hf.ne'] · simp_rw [g', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel₀ hpq.symm.ne_zero, rpow_one, div_self hg.ne'] /-- **Weighted Hölder inequality**. -/ lemma inner_le_weight_mul_Lp (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) (w f : ι → ℝ≥0) : ∑ i ∈ s, w i * f i ≤ (∑ i ∈ s, w i) ^ (1 - p⁻¹) * (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by obtain rfl | hp := hp.eq_or_lt · simp calc _ = ∑ i ∈ s, w i ^ (1 - p⁻¹) * (w i ^ p⁻¹ * f i) := ?_ _ ≤ (∑ i ∈ s, (w i ^ (1 - p⁻¹)) ^ (1 - p⁻¹)⁻¹) ^ (1 / (1 - p⁻¹)⁻¹) * (∑ i ∈ s, (w i ^ p⁻¹ * f i) ^ p) ^ (1 / p) := inner_le_Lp_mul_Lq _ _ _ (.symm <| Real.holderConjugate_iff.mpr ⟨hp, by simp⟩) _ = _ := ?_ · congr with i rw [← mul_assoc, ← rpow_of_add_eq _ one_ne_zero, rpow_one] simp · have hp₀ : p ≠ 0 := by positivity have hp₁ : 1 - p⁻¹ ≠ 0 := by simp [sub_eq_zero, hp.ne'] simp [mul_rpow, div_inv_eq_mul, one_mul, one_div, hp₀, hp₁] /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_hasSum`. -/ theorem inner_le_Lp_mul_Lq_tsum {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.HolderConjugate q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : (Summable fun i => f i * g i) ∧ ∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by have H₁ : ∀ s : Finset ι, ∑ i ∈ s, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by intro s refine le_trans (inner_le_Lp_mul_Lq s f g hpq) (mul_le_mul ?_ ?_ bot_le bot_le) · rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.pos)] exact hf.sum_le_tsum _ (fun _ _ => zero_le _) · rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.symm.pos)] exact hg.sum_le_tsum _ (fun _ _ => zero_le _) have bdd : BddAbove (Set.range fun s => ∑ i ∈ s, f i * g i) := by refine ⟨(∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q), ?_⟩ rintro a ⟨s, rfl⟩ exact H₁ s have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable exact ⟨H₂, H₂.tsum_le_of_sum_le H₁⟩ theorem summable_mul_of_Lp_Lq {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.HolderConjugate q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : Summable fun i => f i * g i := (inner_le_Lp_mul_Lq_tsum hpq hf hg).1 theorem inner_le_Lp_mul_Lq_tsum' {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.HolderConjugate q) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) : ∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := (inner_le_Lp_mul_Lq_tsum hpq hf hg).2 /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_tsum`. -/ theorem inner_le_Lp_mul_Lq_hasSum {f g : ι → ℝ≥0} {A B : ℝ≥0} {p q : ℝ} (hpq : p.HolderConjugate q) (hf : HasSum (fun i => f i ^ p) (A ^ p)) (hg : HasSum (fun i => g i ^ q) (B ^ q)) : ∃ C, C ≤ A * B ∧ HasSum (fun i => f i * g i) C := by obtain ⟨H₁, H₂⟩ := inner_le_Lp_mul_Lq_tsum hpq hf.summable hg.summable have hA : A = (∑' i : ι, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hpq.ne_zero] have hB : B = (∑' i : ι, g i ^ q) ^ (1 / q) := by rw [hg.tsum_eq, rpow_inv_rpow_self hpq.symm.ne_zero] refine ⟨∑' i, f i * g i, ?_, ?_⟩ · simpa [hA, hB] using H₂ · simpa only [rpow_self_rpow_inv hpq.ne_zero] using H₁.hasSum /-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ≥0`-valued functions. -/ theorem rpow_sum_le_const_mul_sum_rpow (f : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) : (∑ i ∈ s, f i) ^ p ≤ (#s : ℝ≥0) ^ (p - 1) * ∑ i ∈ s, f i ^ p := by rcases eq_or_lt_of_le hp with hp | hp · simp [← hp] let q : ℝ := p / (p - 1) have hpq : p.HolderConjugate q := .conjExponent hp have hp₁ : 1 / p * p = 1 := one_div_mul_cancel hpq.ne_zero have hq : 1 / q * p = p - 1 := by rw [← hpq.div_conj_eq_sub_one] ring simpa only [NNReal.mul_rpow, ← NNReal.rpow_mul, hp₁, hq, one_mul, one_rpow, rpow_one, Pi.one_apply, sum_const, Nat.smul_one_eq_cast] using NNReal.rpow_le_rpow (inner_le_Lp_mul_Lq s 1 f hpq.symm) hpq.nonneg /-- The `L_p` seminorm of a vector `f` is the greatest value of the inner product `∑ i ∈ s, f i * g i` over functions `g` of `L_q` seminorm less than or equal to one. -/ theorem isGreatest_Lp (f : ι → ℝ≥0) {p q : ℝ} (hpq : p.HolderConjugate q) : IsGreatest ((fun g : ι → ℝ≥0 => ∑ i ∈ s, f i * g i) '' { g | ∑ i ∈ s, g i ^ q ≤ 1 }) ((∑ i ∈ s, f i ^ p) ^ (1 / p)) := by constructor · use fun i => f i ^ p / f i / (∑ i ∈ s, f i ^ p) ^ (1 / q) obtain hf | hf := eq_zero_or_pos (∑ i ∈ s, f i ^ p) · simp [hf, hpq.ne_zero, hpq.symm.ne_zero] · have A : p + q - q ≠ 0 := by simp [hpq.ne_zero] have B : ∀ y : ℝ≥0, y * y ^ p / y = y ^ p := by refine fun y => mul_div_cancel_left_of_imp fun h => ?_ simp [h, hpq.ne_zero] simp only [Set.mem_setOf_eq, div_rpow, ← sum_div, ← rpow_mul, div_mul_cancel₀ _ hpq.symm.ne_zero, rpow_one, div_le_iff₀ hf, one_mul, hpq.mul_eq_add, ← rpow_sub' A, add_sub_cancel_right, le_refl, true_and, ← mul_div_assoc, B] rw [div_eq_iff, ← rpow_add hf.ne', one_div, one_div, hpq.inv_add_inv_eq_one, rpow_one] simpa [hpq.symm.ne_zero] using hf.ne' · rintro _ ⟨g, hg, rfl⟩ apply le_trans (inner_le_Lp_mul_Lq s f g hpq) simpa only [mul_one] using mul_le_mul_left' (NNReal.rpow_le_one hg (le_of_lt hpq.symm.one_div_pos)) _ /-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `NNReal`-valued functions. -/ theorem Lp_add_le (f g : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) : (∑ i ∈ s, (f i + g i) ^ p) ^ (1 / p) ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) + (∑ i ∈ s, g i ^ p) ^ (1 / p) := by -- The result is trivial when `p = 1`, so we can assume `1 < p`. rcases eq_or_lt_of_le hp with (rfl | hp) · simp [Finset.sum_add_distrib] have hpq := Real.HolderConjugate.conjExponent hp have := isGreatest_Lp s (f + g) hpq simp only [Pi.add_apply, add_mul, sum_add_distrib] at this rcases this.1 with ⟨φ, hφ, H⟩ rw [← H] exact add_le_add ((isGreatest_Lp s f hpq).2 ⟨φ, hφ, rfl⟩) ((isGreatest_Lp s g hpq).2 ⟨φ, hφ, rfl⟩) /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `Lp_add_le_hasSum_of_nonneg`. -/ theorem Lp_add_le_tsum {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : (Summable fun i => (f i + g i) ^ p) ∧ (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := by have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp have H₁ : ∀ s : Finset ι, (∑ i ∈ s, (f i + g i) ^ p) ≤ ((∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p)) ^ p := by intro s rw [one_div, ← NNReal.rpow_inv_le_iff pos, ← one_div] refine le_trans (Lp_add_le s f g hp) (add_le_add ?_ ?_) <;> rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr pos)] <;> refine Summable.sum_le_tsum _ (fun _ _ => zero_le _) ?_ exacts [hf, hg] have bdd : BddAbove (Set.range fun s => ∑ i ∈ s, (f i + g i) ^ p) := by refine ⟨((∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p)) ^ p, ?_⟩ rintro a ⟨s, rfl⟩ exact H₁ s have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable refine ⟨H₂, ?_⟩ rw [one_div, NNReal.rpow_inv_le_iff pos, ← one_div] exact H₂.tsum_le_of_sum_le H₁ theorem summable_Lp_add {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : Summable fun i => (f i + g i) ^ p := (Lp_add_le_tsum hp hf hg).1 theorem Lp_add_le_tsum' {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ p) : (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := (Lp_add_le_tsum hp hf hg).2 /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `Lp_add_le_tsum_of_nonneg`. -/ theorem Lp_add_le_hasSum {f g : ι → ℝ≥0} {A B : ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : HasSum (fun i => f i ^ p) (A ^ p)) (hg : HasSum (fun i => g i ^ p) (B ^ p)) : ∃ C, C ≤ A + B ∧ HasSum (fun i => (f i + g i) ^ p) (C ^ p) := by have hp' : p ≠ 0 := (lt_of_lt_of_le zero_lt_one hp).ne' obtain ⟨H₁, H₂⟩ := Lp_add_le_tsum hp hf.summable hg.summable have hA : A = (∑' i : ι, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hp'] have hB : B = (∑' i : ι, g i ^ p) ^ (1 / p) := by rw [hg.tsum_eq, rpow_inv_rpow_self hp'] refine ⟨(∑' i, (f i + g i) ^ p) ^ (1 / p), ?_, ?_⟩ · simpa [hA, hB] using H₂ · simpa only [rpow_self_rpow_inv hp'] using H₁.hasSum end NNReal namespace Real variable (f g : ι → ℝ) {p q : ℝ} /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with real-valued functions. -/ theorem inner_le_Lp_mul_Lq (hpq : HolderConjugate p q) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, |f i| ^ p) ^ (1 / p) * (∑ i ∈ s, |g i| ^ q) ^ (1 / q) := by have := NNReal.coe_le_coe.2 (NNReal.inner_le_Lp_mul_Lq s (fun i => ⟨_, abs_nonneg (f i)⟩) (fun i => ⟨_, abs_nonneg (g i)⟩) hpq) push_cast at this refine le_trans (sum_le_sum fun i _ => ?_) this simp only [← abs_mul, le_abs_self] /-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ`-valued functions. -/ theorem rpow_sum_le_const_mul_sum_rpow (hp : 1 ≤ p) : (∑ i ∈ s, |f i|) ^ p ≤ (#s : ℝ) ^ (p - 1) * ∑ i ∈ s, |f i| ^ p := by have := NNReal.coe_le_coe.2 (NNReal.rpow_sum_le_const_mul_sum_rpow s (fun i => ⟨_, abs_nonneg (f i)⟩) hp) push_cast at this exact this -- for some reason `exact_mod_cast` can't replace this argument /-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `Real`-valued functions. -/ theorem Lp_add_le (hp : 1 ≤ p) : (∑ i ∈ s, |f i + g i| ^ p) ^ (1 / p) ≤ (∑ i ∈ s, |f i| ^ p) ^ (1 / p) + (∑ i ∈ s, |g i| ^ p) ^ (1 / p) := by have := NNReal.coe_le_coe.2 (NNReal.Lp_add_le s (fun i => ⟨_, abs_nonneg (f i)⟩) (fun i => ⟨_, abs_nonneg (g i)⟩) hp) push_cast at this refine le_trans (rpow_le_rpow ?_ (sum_le_sum fun i _ => ?_) ?_) this <;> simp [sum_nonneg, rpow_nonneg, abs_nonneg, le_trans zero_le_one hp, abs_add, rpow_le_rpow] variable {f g} /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with real-valued nonnegative functions. -/ theorem inner_le_Lp_mul_Lq_of_nonneg (hpq : HolderConjugate p q) (hf : ∀ i ∈ s, 0 ≤ f i) (hg : ∀ i ∈ s, 0 ≤ g i) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by convert inner_le_Lp_mul_Lq s f g hpq using 3 <;> apply sum_congr rfl <;> intro i hi <;> simp only [abs_of_nonneg, hf i hi, hg i hi] /-- **Weighted Hölder inequality**. -/ lemma inner_le_weight_mul_Lp_of_nonneg (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) (w f : ι → ℝ) (hw : ∀ i, 0 ≤ w i) (hf : ∀ i, 0 ≤ f i) : ∑ i ∈ s, w i * f i ≤ (∑ i ∈ s, w i) ^ (1 - p⁻¹) * (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by lift w to ι → ℝ≥0 using hw lift f to ι → ℝ≥0 using hf beta_reduce at * norm_cast at * exact NNReal.inner_le_weight_mul_Lp _ hp _ _ /-- **Weighted Hölder inequality** in terms of `Finset.expect`. -/ lemma compact_inner_le_weight_mul_Lp_of_nonneg (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) {w f : ι → ℝ} (hw : ∀ i, 0 ≤ w i) (hf : ∀ i, 0 ≤ f i) : 𝔼 i ∈ s, w i * f i ≤ (𝔼 i ∈ s, w i) ^ (1 - p⁻¹) * (𝔼 i ∈ s, w i * f i ^ p) ^ p⁻¹ := by simp_rw [expect_eq_sum_div_card] rw [div_rpow, div_rpow, div_mul_div_comm, ← rpow_add', sub_add_cancel, rpow_one] · gcongr exact inner_le_weight_mul_Lp_of_nonneg s hp _ _ hw hf any_goals simp · exact sum_nonneg fun i _ ↦ by have := hw i; have := hf i; positivity · exact sum_nonneg fun i _ ↦ by have := hw i; positivity /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `ℝ`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_hasSum_of_nonneg`. -/ theorem inner_le_Lp_mul_Lq_tsum_of_nonneg (hpq : p.HolderConjugate q) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) : (Summable fun i => f i * g i) ∧ ∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by lift f to ι → ℝ≥0 using hf lift g to ι → ℝ≥0 using hg -- After https://github.com/leanprover/lean4/pull/2734, `norm_cast` needs help with beta reduction. beta_reduce at * norm_cast at * exact NNReal.inner_le_Lp_mul_Lq_tsum hpq hf_sum hg_sum theorem summable_mul_of_Lp_Lq_of_nonneg (hpq : p.HolderConjugate q) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) : Summable fun i => f i * g i := (inner_le_Lp_mul_Lq_tsum_of_nonneg hpq hf hg hf_sum hg_sum).1 theorem inner_le_Lp_mul_Lq_tsum_of_nonneg' (hpq : p.HolderConjugate q) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) : ∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := (inner_le_Lp_mul_Lq_tsum_of_nonneg hpq hf hg hf_sum hg_sum).2 /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `inner_le_Lp_mul_Lq_tsum_of_nonneg`. -/ theorem inner_le_Lp_mul_Lq_hasSum_of_nonneg (hpq : p.HolderConjugate q) {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : HasSum (fun i => f i ^ p) (A ^ p)) (hg_sum : HasSum (fun i => g i ^ q) (B ^ q)) : ∃ C : ℝ, 0 ≤ C ∧ C ≤ A * B ∧ HasSum (fun i => f i * g i) C := by lift f to ι → ℝ≥0 using hf lift g to ι → ℝ≥0 using hg lift A to ℝ≥0 using hA lift B to ℝ≥0 using hB -- After https://github.com/leanprover/lean4/pull/2734, `norm_cast` needs help with beta reduction. beta_reduce at * norm_cast at hf_sum hg_sum obtain ⟨C, hC, H⟩ := NNReal.inner_le_Lp_mul_Lq_hasSum hpq hf_sum hg_sum refine ⟨C, C.prop, hC, ?_⟩ norm_cast /-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with nonnegative `ℝ`-valued functions. -/ theorem rpow_sum_le_const_mul_sum_rpow_of_nonneg (hp : 1 ≤ p) (hf : ∀ i ∈ s, 0 ≤ f i) : (∑ i ∈ s, f i) ^ p ≤ (#s : ℝ) ^ (p - 1) * ∑ i ∈ s, f i ^ p := by convert rpow_sum_le_const_mul_sum_rpow s f hp using 2 <;> apply sum_congr rfl <;> intro i hi <;> simp only [abs_of_nonneg, hf i hi] /-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `ℝ`-valued nonnegative functions. -/ theorem Lp_add_le_of_nonneg (hp : 1 ≤ p) (hf : ∀ i ∈ s, 0 ≤ f i) (hg : ∀ i ∈ s, 0 ≤ g i) : (∑ i ∈ s, (f i + g i) ^ p) ^ (1 / p) ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) + (∑ i ∈ s, g i ^ p) ^ (1 / p) := by convert Lp_add_le s f g hp using 2 <;> [skip;congr 1;congr 1] <;> apply sum_congr rfl <;> intro i hi <;> simp only [abs_of_nonneg, hf i hi, hg i hi, add_nonneg] /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `ℝ`-valued functions. For an alternative version, convenient if the infinite sums are already expressed as `p`-th powers, see `Lp_add_le_hasSum_of_nonneg`. -/ theorem Lp_add_le_tsum_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) : (Summable fun i => (f i + g i) ^ p) ∧ (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := by lift f to ι → ℝ≥0 using hf lift g to ι → ℝ≥0 using hg -- After https://github.com/leanprover/lean4/pull/2734, `norm_cast` needs help with beta reduction. beta_reduce at * norm_cast0 at * exact NNReal.Lp_add_le_tsum hp hf_sum hg_sum theorem summable_Lp_add_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) : Summable fun i => (f i + g i) ^ p := (Lp_add_le_tsum_of_nonneg hp hf hg hf_sum hg_sum).1 theorem Lp_add_le_tsum_of_nonneg' (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) : (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) := (Lp_add_le_tsum_of_nonneg hp hf hg hf_sum hg_sum).2 /-- **Minkowski inequality**: the `L_p` seminorm of the infinite sum of two vectors is less than or equal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both exist. A version for `ℝ`-valued functions. For an alternative version, convenient if the infinite sums are not already expressed as `p`-th powers, see `Lp_add_le_tsum_of_nonneg`. -/ theorem Lp_add_le_hasSum_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hfA : HasSum (fun i => f i ^ p) (A ^ p)) (hgB : HasSum (fun i => g i ^ p) (B ^ p)) : ∃ C, 0 ≤ C ∧ C ≤ A + B ∧ HasSum (fun i => (f i + g i) ^ p) (C ^ p) := by lift f to ι → ℝ≥0 using hf lift g to ι → ℝ≥0 using hg lift A to ℝ≥0 using hA lift B to ℝ≥0 using hB -- After https://github.com/leanprover/lean4/pull/2734, `norm_cast` needs help with beta reduction. beta_reduce at hfA hgB norm_cast at hfA hgB obtain ⟨C, hC₁, hC₂⟩ := NNReal.Lp_add_le_hasSum hp hfA hgB use C -- After https://github.com/leanprover/lean4/pull/2734, `norm_cast` needs help with beta reduction. beta_reduce norm_cast exact ⟨zero_le _, hC₁, hC₂⟩ end Real namespace ENNReal variable (f g : ι → ℝ≥0∞) {p q : ℝ} /-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with `ℝ≥0∞`-valued functions. -/ theorem inner_le_Lp_mul_Lq (hpq : p.HolderConjugate q) : ∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by by_cases H : (∑ i ∈ s, f i ^ p) ^ (1 / p) = 0 ∨ (∑ i ∈ s, g i ^ q) ^ (1 / q) = 0 · replace H : (∀ i ∈ s, f i = 0) ∨ ∀ i ∈ s, g i = 0 := by simpa [ENNReal.rpow_eq_zero_iff, hpq.pos, hpq.symm.pos, asymm hpq.pos, asymm hpq.symm.pos, sum_eq_zero_iff_of_nonneg] using H have : ∀ i ∈ s, f i * g i = 0 := fun i hi => by rcases H with H | H <;> simp [H i hi] simp [sum_eq_zero this] push_neg at H by_cases H' : (∑ i ∈ s, f i ^ p) ^ (1 / p) = ⊤ ∨ (∑ i ∈ s, g i ^ q) ^ (1 / q) = ⊤ · rcases H' with H' | H' <;> simp [H', -one_div, -sum_eq_zero_iff, -rpow_eq_zero_iff, H] replace H' : (∀ i ∈ s, f i ≠ ⊤) ∧ ∀ i ∈ s, g i ≠ ⊤ := by simpa [ENNReal.rpow_eq_top_iff, asymm hpq.pos, asymm hpq.symm.pos, hpq.pos, hpq.symm.pos, ENNReal.sum_eq_top, not_or] using H' have := ENNReal.coe_le_coe.2 (@NNReal.inner_le_Lp_mul_Lq _ s (fun i => ENNReal.toNNReal (f i)) (fun i => ENNReal.toNNReal (g i)) _ _ hpq) simp [ENNReal.coe_rpow_of_nonneg, hpq.pos.le, hpq.symm.pos.le] at this convert this using 1 <;> [skip; congr 2] <;> [skip; skip; simp; skip; simp] <;> · refine Finset.sum_congr rfl fun i hi => ?_ simp [H'.1 i hi, H'.2 i hi, -WithZero.coe_mul] /-- **Weighted Hölder inequality**. -/ lemma inner_le_weight_mul_Lp_of_nonneg (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) (w f : ι → ℝ≥0∞) : ∑ i ∈ s, w i * f i ≤ (∑ i ∈ s, w i) ^ (1 - p⁻¹) * (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by obtain rfl | hp := hp.eq_or_lt · simp have hp₀ : 0 < p := by positivity have hp₁ : p⁻¹ < 1 := inv_lt_one_of_one_lt₀ hp by_cases H : (∑ i ∈ s, w i) ^ (1 - p⁻¹) = 0 ∨ (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ = 0 · replace H : (∀ i ∈ s, w i = 0) ∨ ∀ i ∈ s, w i = 0 ∨ f i = 0 := by simpa [hp₀, hp₁, hp₀.not_gt, hp₁.not_gt, sum_eq_zero_iff_of_nonneg] using H have (i) (hi : i ∈ s) : w i * f i = 0 := by rcases H with H | H <;> simp [H i hi] simp [sum_eq_zero this] push_neg at H by_cases H' : (∑ i ∈ s, w i) ^ (1 - p⁻¹) = ⊤ ∨ (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ = ⊤ · rcases H' with H' | H' <;> simp [H', -one_div, -sum_eq_zero_iff, -rpow_eq_zero_iff, H] replace H' : (∀ i ∈ s, w i ≠ ⊤) ∧ ∀ i ∈ s, w i * f i ^ p ≠ ⊤ := by simpa [rpow_eq_top_iff,hp₀, hp₁, hp₀.not_gt, hp₁.not_gt, sum_eq_top, not_or] using H' have := coe_le_coe.2 <| NNReal.inner_le_weight_mul_Lp s hp.le (fun i ↦ ENNReal.toNNReal (w i)) fun i ↦ ENNReal.toNNReal (f i) rw [coe_mul] at this simp_rw [coe_rpow_of_nonneg _ <| inv_nonneg.2 hp₀.le, coe_finset_sum, ← ENNReal.toNNReal_rpow, ← ENNReal.toNNReal_mul, sum_congr rfl fun i hi ↦ coe_toNNReal (H'.2 i hi)] at this simp [ENNReal.coe_rpow_of_nonneg, hp₁.le] at this convert this using 2 with i hi · obtain hw | hw := eq_or_ne (w i) 0 · simp [hw] rw [coe_toNNReal (H'.1 _ hi), coe_toNNReal] simpa [mul_eq_top, hw, hp₀, hp₀.not_gt, H'.1 _ hi] using H'.2 _ hi · convert rfl with i hi exact coe_toNNReal (H'.1 _ hi) /-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the sum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ≥0∞`-valued functions. -/ theorem rpow_sum_le_const_mul_sum_rpow (hp : 1 ≤ p) : (∑ i ∈ s, f i) ^ p ≤ (card s : ℝ≥0∞) ^ (p - 1) * ∑ i ∈ s, f i ^ p := by rcases eq_or_lt_of_le hp with hp | hp · simp [← hp] let q : ℝ := p / (p - 1) have hpq : p.HolderConjugate q := .conjExponent hp have hp₁ : 1 / p * p = 1 := one_div_mul_cancel hpq.ne_zero have hq : 1 / q * p = p - 1 := by rw [← hpq.div_conj_eq_sub_one] ring simpa only [ENNReal.mul_rpow_of_nonneg _ _ hpq.nonneg, ← ENNReal.rpow_mul, hp₁, hq, coe_one, one_mul, one_rpow, rpow_one, Pi.one_apply, sum_const, Nat.smul_one_eq_cast] using ENNReal.rpow_le_rpow (inner_le_Lp_mul_Lq s 1 f hpq.symm) hpq.nonneg /-- **Minkowski inequality**: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `ℝ≥0∞` valued nonnegative functions. -/ theorem Lp_add_le (hp : 1 ≤ p) : (∑ i ∈ s, (f i + g i) ^ p) ^ (1 / p) ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) + (∑ i ∈ s, g i ^ p) ^ (1 / p) := by by_cases H' : (∑ i ∈ s, f i ^ p) ^ (1 / p) = ⊤ ∨ (∑ i ∈ s, g i ^ p) ^ (1 / p) = ⊤ · rcases H' with H' | H' <;> simp [H', -one_div] have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp replace H' : (∀ i ∈ s, f i ≠ ⊤) ∧ ∀ i ∈ s, g i ≠ ⊤ := by simpa [ENNReal.rpow_eq_top_iff, asymm pos, pos, ENNReal.sum_eq_top, not_or] using H' have := ENNReal.coe_le_coe.2 (@NNReal.Lp_add_le _ s (fun i => ENNReal.toNNReal (f i)) (fun i => ENNReal.toNNReal (g i)) _ hp) push_cast [ENNReal.coe_rpow_of_nonneg, le_of_lt pos, le_of_lt (one_div_pos.2 pos)] at this convert this using 2 <;> [skip; congr 1; congr 1] <;> · refine Finset.sum_congr rfl fun i hi => ?_ simp [H'.1 i hi, H'.2 i hi] end ENNReal end HoelderMinkowski
End.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.Limits.Shapes.Multiequalizer /-! # Ends and coends In this file, given a functor `F : Jᵒᵖ ⥤ J ⥤ C`, we define its end `end_ F`, which is a suitable multiequalizer of the objects `(F.obj (op j)).obj j` for all `j : J`. For this shape of limits, cones are named wedges: the corresponding type is `Wedge F`. We also introduce `coend F` as multicoequalizers of `(F.obj (op j)).obj j` for all `j : J`. In this cases, cocones are named cowedges. ## References * https://ncatlab.org/nlab/show/end -/ universe v v' u u' namespace CategoryTheory open Opposite namespace Limits variable {J : Type u} [Category.{v} J] {C : Type u'} [Category.{v'} C] (F : Jᵒᵖ ⥤ J ⥤ C) variable (J) in /-- The shape of multiequalizer diagrams involved in the definition of ends. -/ @[simps] def multicospanShapeEnd : MulticospanShape where L := J R := Arrow J fst f := f.left snd f := f.right variable (J) in /-- The shape of multicoequalizer diagrams involved in the definition of coends. -/ @[simps] def multispanShapeCoend : MultispanShape where L := Arrow J R := J fst f := f.left snd f := f.right /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this is the multicospan index which shall be used to define the end of `F`. -/ @[simps] def multicospanIndexEnd : MulticospanIndex (multicospanShapeEnd J) C where left j := (F.obj (op j)).obj j right f := (F.obj (op f.left)).obj f.right fst f := (F.obj (op f.left)).map f.hom snd f := (F.map f.hom.op).app f.right /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this is the multispan used to define the coend of `F`. -/ @[simps] def multispanIndexCoend : MultispanIndex (multispanShapeCoend J) C where left f := (F.obj (op f.right)).obj f.left right j := (F.obj (op j)).obj j fst f := (F.map f.hom.op).app f.left snd f := (F.obj (op f.right)).map f.hom /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, a wedge for `F` is a type of cones (specifically the type of multiforks for `multicospanIndexEnd F`): the point of universal of these wedges shall be the end of `F`. -/ abbrev Wedge := Multifork (multicospanIndexEnd F) namespace Wedge variable {F} /-- A variant of `CategoryTheory.Limits.Cones.ext` specialized to produce isomorphisms of wedges. -/ @[simps!] def ext {W₁ W₂ : Wedge F} (e : W₁.pt ≅ W₂.pt) (he : ∀ j : J, W₁.ι j = e.hom ≫ W₂.ι j := by cat_disch) : W₁ ≅ W₂ := Cones.ext e (fun j => match j with | .left _ => he _ | .right f => by simpa using (he f.left) =≫ _) section Constructor variable (pt : C) (π : ∀ (j : J), pt ⟶ (F.obj (op j)).obj j) (hπ : ∀ ⦃i j : J⦄ (f : i ⟶ j), π i ≫ (F.obj (op i)).map f = π j ≫ (F.map f.op).app j) /-- Constructor for wedges. -/ @[simps! pt] abbrev mk : Wedge F := Multifork.ofι _ pt π (fun f ↦ hπ f.hom) @[simp] lemma mk_ι (j : J) : (mk pt π hπ).ι j = π j := rfl end Constructor @[reassoc] lemma condition (c : Wedge F) {i j : J} (f : i ⟶ j) : c.ι i ≫ (F.obj (op i)).map f = c.ι j ≫ (F.map f.op).app j := Multifork.condition c (Arrow.mk f) namespace IsLimit variable {c : Wedge F} (hc : IsLimit c) lemma hom_ext (hc : IsLimit c) {X : C} {f g : X ⟶ c.pt} (h : ∀ j, f ≫ c.ι j = g ≫ c.ι j) : f = g := Multifork.IsLimit.hom_ext hc h /-- Construct a morphism to the end from its universal property. -/ def lift (hc : IsLimit c) {X : C} (f : ∀ j, X ⟶ (F.obj (op j)).obj j) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), f i ≫ (F.obj (op i)).map g = f j ≫ (F.map g.op).app j) : X ⟶ c.pt := Multifork.IsLimit.lift hc f (fun _ ↦ hf _) @[reassoc (attr := simp)] lemma lift_ι (hc : IsLimit c) {X : C} (f : ∀ j, X ⟶ (F.obj (op j)).obj j) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), f i ≫ (F.obj (op i)).map g = f j ≫ (F.map g.op).app j) (j : J) : lift hc f hf ≫ c.ι j = f j := by apply IsLimit.fac end IsLimit end Wedge /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, a cowedge for `F` is a type of cocones (specifically the type of multicoforks for `multispanIndexCoend F`): the point of a universal cowedge is the coend of `F`. -/ abbrev Cowedge := Multicofork (multispanIndexCoend F) namespace Cowedge variable {F} /-- A variant of `CategoryTheory.Limits.Cocones.ext` specialized to produce isomorphisms of cowedges. -/ @[simps!] def ext {W₁ W₂ : Cowedge F} (e : W₁.pt ≅ W₂.pt) (he : ∀ j : J, W₁.π j ≫ e.hom = W₂.π j := by cat_disch) : W₁ ≅ W₂ := Cocones.ext e (fun j => match j with | .right _ => he _ | .left f => by simpa using _ ≫= (he f.left)) section Constructor variable (pt : C) (ι : ∀ (j : J), (F.obj (op j)).obj j ⟶ pt) (hι : ∀ ⦃i j : J⦄ (f : i ⟶ j), (F.map f.op).app i ≫ ι i = (F.obj (op j)).map f ≫ ι j) /-- Constructor for cowedges. -/ @[simps! pt] abbrev mk : Cowedge F := Multicofork.ofπ _ pt ι (fun f ↦ hι f.hom) @[simp] lemma mk_π (j : J) : (mk pt ι hι).π j = ι j := rfl end Constructor @[reassoc] lemma condition (c : Cowedge F) {i j : J} (f : i ⟶ j) : (F.map f.op).app i ≫ c.π i = (F.obj (op j)).map f ≫ c.π j := Multicofork.condition c (Arrow.mk f) namespace IsColimit variable {c : Cowedge F} (hc : IsColimit c) lemma hom_ext (hc : IsColimit c) {X : C} {f g : c.pt ⟶ X} (h : ∀ j, c.π j ≫ f = c.π j ≫ g) : f = g := Multicofork.IsColimit.hom_ext hc h /-- Construct a morphism from the coend using its universal property. -/ def desc (hc : IsColimit c) {X : C} (f : ∀ j, (F.obj (op j)).obj j ⟶ X) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), (F.map g.op).app i ≫ f i = (F.obj (op j)).map g ≫ f j) : c.pt ⟶ X := Multicofork.IsColimit.desc hc f (fun _ ↦ hf _) @[reassoc (attr := simp)] lemma π_desc (hc : IsColimit c) {X : C} (f : ∀ j, (F.obj (op j)).obj j ⟶ X) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), (F.map g.op).app i ≫ f i = (F.obj (op j)).map g ≫ f j) (j : J) : c.π j ≫ desc hc f hf = f j := by apply IsColimit.fac end IsColimit end Cowedge section End /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this property asserts the existence of the end of `F`. -/ abbrev HasEnd := HasMultiequalizer (multicospanIndexEnd F) variable [HasEnd F] /-- The end of a functor `F : Jᵒᵖ ⥤ J ⥤ C`. -/ noncomputable def end_ : C := multiequalizer (multicospanIndexEnd F) /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this is the projection `end_ F ⟶ (F.obj (op j)).obj j` for any `j : J`. -/ noncomputable def end_.π (j : J) : end_ F ⟶ (F.obj (op j)).obj j := Multiequalizer.ι _ _ @[reassoc] lemma end_.condition {i j : J} (f : i ⟶ j) : π F i ≫ (F.obj (op i)).map f = π F j ≫ (F.map f.op).app j := by apply Wedge.condition variable {F} @[ext] lemma end_.hom_ext {X : C} {f g : X ⟶ end_ F} (h : ∀ j, f ≫ end_.π F j = g ≫ end_.π F j) : f = g := Multiequalizer.hom_ext _ _ _ (fun _ ↦ h _) @[deprecated (since := "2025-06-06")] alias _root_.CategoryTheory.Limits.hom_ext := end_.hom_ext section variable {X : C} (f : ∀ j, X ⟶ (F.obj (op j)).obj j) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), f i ≫ (F.obj (op i)).map g = f j ≫ (F.map g.op).app j) /-- Constructor for morphisms to the end of a functor. -/ noncomputable def end_.lift : X ⟶ end_ F := Wedge.IsLimit.lift (limit.isLimit _) f hf @[reassoc (attr := simp)] lemma end_.lift_π (j : J) : lift f hf ≫ π F j = f j := by apply IsLimit.fac variable {F' : Jᵒᵖ ⥤ J ⥤ C} [HasEnd F'] (f : F ⟶ F') /-- A natural transformation of functors F ⟶ F' induces a map end_ F ⟶ end_ F'. -/ noncomputable def end_.map : end_ F ⟶ end_ F' := end_.lift (fun x ↦ end_.π _ _ ≫ (f.app (op x)).app x) (fun j j' φ ↦ by have e := (f.app (op j)).naturality φ simp only [Category.assoc] rw [← e, reassoc_of% end_.condition F φ] simp) @[reassoc (attr := simp)] lemma end_.map_π (j : J) : end_.map f ≫ end_.π F' j = end_.π _ _ ≫ (f.app (op j)).app j := by simp [end_.map] @[reassoc (attr := simp)] lemma end_.map_comp {F'' : Jᵒᵖ ⥤ J ⥤ C} [HasEnd F''] (g : F' ⟶ F'') : end_.map f ≫ end_.map g = end_.map (f ≫ g) := by cat_disch @[simp] lemma end_.map_id : end_.map (𝟙 F) = 𝟙 _ := by cat_disch end variable (J C) in /-- If all bifunctors `Jᵒᵖ ⥤ J ⥤ C` have an end, then the construction `F ↦ end_ F` defines a functor `(Jᵒᵖ ⥤ J ⥤ C) ⥤ C`. -/ @[simps] noncomputable def endFunctor [∀ (F : Jᵒᵖ ⥤ J ⥤ C), HasEnd F] : (Jᵒᵖ ⥤ J ⥤ C) ⥤ C where obj F := end_ F map f := end_.map f end End section Coend /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this property asserts the existence of the coend of `F`. -/ abbrev HasCoend := HasMulticoequalizer (multispanIndexCoend F) variable [HasCoend F] /-- The end of a functor `F : Jᵒᵖ ⥤ J ⥤ C`. -/ noncomputable def coend : C := multicoequalizer (multispanIndexCoend F) /-- Given `F : Jᵒᵖ ⥤ J ⥤ C`, this is the inclusion `(F.obj (op j)).obj j ⟶ coend F` for any `j : J`. -/ noncomputable def coend.ι (j : J) : (F.obj (op j)).obj j ⟶ coend F := Multicoequalizer.π (multispanIndexCoend F) _ @[reassoc] lemma coend.condition {i j : J} (f : i ⟶ j) : (F.map f.op).app i ≫ ι F i = (F.obj (op j)).map f ≫ ι F j := by apply Cowedge.condition variable {F} @[ext] lemma coend.hom_ext {X : C} {f g : coend F ⟶ X} (h : ∀ j, coend.ι F j ≫ f = coend.ι F j ≫ g) : f = g := Multicoequalizer.hom_ext _ _ _ (fun _ ↦ h _) section variable {X : C} (f : ∀ j, (F.obj (op j)).obj j ⟶ X) (hf : ∀ ⦃i j : J⦄ (g : i ⟶ j), (F.map g.op).app i ≫ f i = (F.obj (op j)).map g ≫ f j) /-- Constructor for morphisms to the coend of a functor. -/ noncomputable def coend.desc : coend F ⟶ X := Cowedge.IsColimit.desc (colimit.isColimit _) f hf @[reassoc (attr := simp)] lemma coend.ι_desc (j : J) : ι F j ≫ desc f hf = f j := by apply IsColimit.fac variable {F' : Jᵒᵖ ⥤ J ⥤ C} [HasCoend F'] (f : F ⟶ F') /-- A natural transformation of functors F ⟶ F' induces a map coend F ⟶ coend F'. -/ noncomputable def coend.map : coend F ⟶ coend F' := coend.desc (fun x ↦ (f.app (op x)).app x ≫ coend.ι _ _ ) (fun j j' φ ↦ by simp [coend.condition]) @[reassoc (attr := simp)] lemma coend.ι_map (j : J) : coend.ι _ _ ≫ coend.map f = (f.app (op j)).app j ≫ coend.ι _ _ := by simp [coend.map] @[reassoc (attr := simp)] lemma coend.map_comp {F'' : Jᵒᵖ ⥤ J ⥤ C} [HasCoend F''] (g : F' ⟶ F'') : coend.map f ≫ coend.map g = coend.map (f ≫ g) := by cat_disch @[simp] lemma coend.map_id : coend.map (𝟙 F) = 𝟙 _ := by cat_disch end variable (J C) in /-- If all bifunctors `Jᵒᵖ ⥤ J ⥤ C` have a coend, then the construction `F ↦ coend F` defines a functor `(Jᵒᵖ ⥤ J ⥤ C) ⥤ C`. -/ @[simps] noncomputable def coendFunctor [∀ (F : Jᵒᵖ ⥤ J ⥤ C), HasCoend F] : (Jᵒᵖ ⥤ J ⥤ C) ⥤ C where obj F := coend F map f := coend.map f end Coend end Limits end CategoryTheory
StoneCech.lean
/- Copyright (c) 2018 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton -/ import Mathlib.Topology.Bases import Mathlib.Topology.DenseEmbedding import Mathlib.Topology.Connected.TotallyDisconnected /-! # Stone-Čech compactification Construction of the Stone-Čech compactification using ultrafilters. For any topological space `α`, we build a compact Hausdorff space `StoneCech α` and a continuous map `stoneCechUnit : α → StoneCech α` which is minimal in the sense of the following universal property: for any compact Hausdorff space `β` and every map `f : α → β` such that `hf : Continuous f`, there is a unique map `stoneCechExtend hf : StoneCech α → β` such that `stoneCechExtend_extends : stoneCechExtend hf ∘ stoneCechUnit = f`. Continuity of this extension is asserted by `continuous_stoneCechExtend` and uniqueness by `stoneCech_hom_ext`. Beware that the terminology “extend” is slightly misleading since `stoneCechUnit` is not always injective, so one cannot always think of `α` as being “inside” its compactification `StoneCech α`. ## Implementation notes Parts of the formalization are based on “Ultrafilters and Topology” by Marius Stekelenburg, particularly section 5. However the construction in the general case is different because the equivalence relation on spaces of ultrafilters described by Stekelenburg causes issues with universes since it involves a condition on all compact Hausdorff spaces. We replace it by a two steps construction. The first step called `PreStoneCech` guarantees the expected universal property but not the Hausdorff condition. We then define `StoneCech α` as `T2Quotient (PreStoneCech α)`. -/ noncomputable section open Filter Set open Topology universe u v section Ultrafilter /- The set of ultrafilters on α carries a natural topology which makes it the Stone-Čech compactification of α (viewed as a discrete space). -/ /-- Basis for the topology on `Ultrafilter α`. -/ def ultrafilterBasis (α : Type u) : Set (Set (Ultrafilter α)) := range fun s : Set α ↦ { u | s ∈ u } variable {α : Type u} instance Ultrafilter.topologicalSpace : TopologicalSpace (Ultrafilter α) := TopologicalSpace.generateFrom (ultrafilterBasis α) theorem ultrafilterBasis_is_basis : TopologicalSpace.IsTopologicalBasis (ultrafilterBasis α) := ⟨by rintro _ ⟨a, rfl⟩ _ ⟨b, rfl⟩ u ⟨ua, ub⟩ refine ⟨_, ⟨a ∩ b, rfl⟩, inter_mem ua ub, fun v hv ↦ ⟨?_, ?_⟩⟩ <;> apply mem_of_superset hv <;> simp [inter_subset_right], eq_univ_of_univ_subset <| subset_sUnion_of_mem <| ⟨univ, eq_univ_of_forall fun _ ↦ univ_mem⟩, rfl⟩ /-- The basic open sets for the topology on ultrafilters are open. -/ theorem ultrafilter_isOpen_basic (s : Set α) : IsOpen { u : Ultrafilter α | s ∈ u } := ultrafilterBasis_is_basis.isOpen ⟨s, rfl⟩ /-- The basic open sets for the topology on ultrafilters are also closed. -/ theorem ultrafilter_isClosed_basic (s : Set α) : IsClosed { u : Ultrafilter α | s ∈ u } := by rw [← isOpen_compl_iff] convert ultrafilter_isOpen_basic sᶜ using 1 ext u exact Ultrafilter.compl_mem_iff_notMem.symm /-- Every ultrafilter `u` on `Ultrafilter α` converges to a unique point of `Ultrafilter α`, namely `joinM u`. -/ theorem ultrafilter_converges_iff {u : Ultrafilter (Ultrafilter α)} {x : Ultrafilter α} : ↑u ≤ 𝓝 x ↔ x = joinM u := by rw [eq_comm, ← Ultrafilter.coe_le_coe] change ↑u ≤ 𝓝 x ↔ ∀ s ∈ x, { v : Ultrafilter α | s ∈ v } ∈ u simp only [TopologicalSpace.nhds_generateFrom, le_iInf_iff, ultrafilterBasis, le_principal_iff, mem_setOf_eq] constructor · intro h a ha exact h _ ⟨ha, a, rfl⟩ · rintro h a ⟨xi, a, rfl⟩ exact h _ xi instance ultrafilter_compact : CompactSpace (Ultrafilter α) := ⟨isCompact_iff_ultrafilter_le_nhds.mpr fun f _ ↦ ⟨joinM f, trivial, ultrafilter_converges_iff.mpr rfl⟩⟩ instance Ultrafilter.t2Space : T2Space (Ultrafilter α) := t2_iff_ultrafilter.mpr fun {x y} f fx fy ↦ have hx : x = joinM f := ultrafilter_converges_iff.mp fx have hy : y = joinM f := ultrafilter_converges_iff.mp fy hx.trans hy.symm instance : TotallyDisconnectedSpace (Ultrafilter α) := by rw [totallyDisconnectedSpace_iff_connectedComponent_singleton] intro A simp only [Set.eq_singleton_iff_unique_mem, mem_connectedComponent, true_and] intro B hB rw [← Ultrafilter.coe_le_coe] intro s hs rw [connectedComponent_eq_iInter_isClopen, Set.mem_iInter] at hB let Z := { F : Ultrafilter α | s ∈ F } have hZ : IsClopen Z := ⟨ultrafilter_isClosed_basic s, ultrafilter_isOpen_basic s⟩ exact hB ⟨Z, hZ, hs⟩ @[simp] theorem Ultrafilter.tendsto_pure_self (b : Ultrafilter α) : Tendsto pure b (𝓝 b) := by rw [Tendsto, ← coe_map, ultrafilter_converges_iff] ext s change s ∈ b ↔ {t | s ∈ t} ∈ map pure b simp_rw [mem_map, preimage_setOf_eq, mem_pure, setOf_mem_eq] theorem ultrafilter_comap_pure_nhds (b : Ultrafilter α) : comap pure (𝓝 b) ≤ b := by rw [TopologicalSpace.nhds_generateFrom] simp only [comap_iInf, comap_principal] intro s hs rw [← le_principal_iff] refine iInf_le_of_le { u | s ∈ u } ?_ refine iInf_le_of_le ⟨hs, ⟨s, rfl⟩⟩ ?_ exact principal_mono.2 fun _ ↦ id section Embedding @[deprecated (since := "2025-08-14")] alias ultrafilter_pure_injective := Ultrafilter.pure_injective open TopologicalSpace /-- The range of `pure : α → Ultrafilter α` is dense in `Ultrafilter α`. -/ theorem denseRange_pure : DenseRange (pure : α → Ultrafilter α) := fun x ↦ mem_closure_iff_ultrafilter.mpr ⟨x.map pure, range_mem_map, ultrafilter_converges_iff.mpr (bind_pure x).symm⟩ /-- The map `pure : α → Ultrafilter α` induces on `α` the discrete topology. -/ theorem induced_topology_pure : TopologicalSpace.induced (pure : α → Ultrafilter α) Ultrafilter.topologicalSpace = ⊥ := by apply eq_bot_of_singletons_open intro x use { u : Ultrafilter α | {x} ∈ u }, ultrafilter_isOpen_basic _ simp /-- `pure : α → Ultrafilter α` defines a dense inducing of `α` in `Ultrafilter α`. -/ theorem isDenseInducing_pure : @IsDenseInducing _ _ ⊥ _ (pure : α → Ultrafilter α) := letI : TopologicalSpace α := ⊥ ⟨⟨induced_topology_pure.symm⟩, denseRange_pure⟩ -- The following refined version will never be used /-- `pure : α → Ultrafilter α` defines a dense embedding of `α` in `Ultrafilter α`. -/ theorem isDenseEmbedding_pure : @IsDenseEmbedding _ _ ⊥ _ (pure : α → Ultrafilter α) := letI : TopologicalSpace α := ⊥ { isDenseInducing_pure with injective := Ultrafilter.pure_injective } end Embedding section Extension /- Goal: Any function `α → γ` to a compact Hausdorff space `γ` has a unique extension to a continuous function `Ultrafilter α → γ`. We already know it must be unique because `α → Ultrafilter α` is a dense embedding and `γ` is Hausdorff. For existence, we will invoke `IsDenseInducing.continuous_extend`. -/ variable {γ : Type*} [TopologicalSpace γ] /-- The extension of a function `α → γ` to a function `Ultrafilter α → γ`. When `γ` is a compact Hausdorff space it will be continuous. -/ def Ultrafilter.extend (f : α → γ) : Ultrafilter α → γ := letI : TopologicalSpace α := ⊥ isDenseInducing_pure.extend f variable [T2Space γ] @[simp] lemma ultrafilter_extend_extends (f : α → γ) : Ultrafilter.extend f ∘ pure = f := by letI : TopologicalSpace α := ⊥ haveI : DiscreteTopology α := ⟨rfl⟩ exact funext (isDenseInducing_pure.extend_eq continuous_of_discreteTopology) @[simp] lemma ultrafilter_extend_pure (f : α → γ) (a : α) : Ultrafilter.extend f (pure a) = f a := congr_fun (ultrafilter_extend_extends f) a variable [CompactSpace γ] theorem continuous_ultrafilter_extend (f : α → γ) : Continuous (Ultrafilter.extend f) := by have h (b : Ultrafilter α) : ∃ c, Tendsto f (comap pure (𝓝 b)) (𝓝 c) := -- b.map f is an ultrafilter on γ, which is compact, so it converges to some c in γ. let ⟨c, _, h'⟩ := isCompact_univ.ultrafilter_le_nhds (b.map f) (by rw [le_principal_iff]; exact univ_mem) ⟨c, le_trans (map_mono (ultrafilter_comap_pure_nhds _)) h'⟩ let _ : TopologicalSpace α := ⊥ exact isDenseInducing_pure.continuous_extend h /-- The value of `Ultrafilter.extend f` on an ultrafilter `b` is the unique limit of the ultrafilter `b.map f` in `γ`. -/ theorem ultrafilter_extend_eq_iff {f : α → γ} {b : Ultrafilter α} {c : γ} : Ultrafilter.extend f b = c ↔ ↑(b.map f) ≤ 𝓝 c := ⟨fun h ↦ by -- Write b as an ultrafilter limit of pure ultrafilters, and use -- the facts that ultrafilter.extend is a continuous extension of f. let b' : Ultrafilter (Ultrafilter α) := b.map pure have t : ↑b' ≤ 𝓝 b := ultrafilter_converges_iff.mpr (bind_pure _).symm rw [← h] have := (continuous_ultrafilter_extend f).tendsto b refine le_trans ?_ (le_trans (map_mono t) this) change _ ≤ map (Ultrafilter.extend f ∘ pure) ↑b rw [ultrafilter_extend_extends] exact le_rfl, fun h ↦ let _ : TopologicalSpace α := ⊥ isDenseInducing_pure.extend_eq_of_tendsto (le_trans (map_mono (ultrafilter_comap_pure_nhds _)) h)⟩ end Extension end Ultrafilter section PreStoneCech variable (α : Type u) [TopologicalSpace α] /-- Auxiliary construction towards the Stone-Čech compactification of a topological space. It should not be used after the Stone-Čech compactification is constructed. -/ def PreStoneCech : Type u := Quot fun F G : Ultrafilter α ↦ ∃ x, (F : Filter α) ≤ 𝓝 x ∧ (G : Filter α) ≤ 𝓝 x variable {α} instance : TopologicalSpace (PreStoneCech α) := inferInstanceAs (TopologicalSpace <| Quot _) instance : CompactSpace (PreStoneCech α) := Quot.compactSpace instance [Inhabited α] : Inhabited (PreStoneCech α) := inferInstanceAs (Inhabited <| Quot _) /-- The natural map from α to its pre-Stone-Čech compactification. -/ def preStoneCechUnit (x : α) : PreStoneCech α := Quot.mk _ (pure x : Ultrafilter α) theorem continuous_preStoneCechUnit : Continuous (preStoneCechUnit : α → PreStoneCech α) := continuous_iff_ultrafilter.mpr fun x g gx ↦ by have : (g.map pure).toFilter ≤ 𝓝 g := by rw [ultrafilter_converges_iff, ← bind_pure g] rfl have : (map preStoneCechUnit g : Filter (PreStoneCech α)) ≤ 𝓝 (Quot.mk _ g) := (map_mono this).trans (continuous_quot_mk.tendsto _) convert this exact Quot.sound ⟨x, pure_le_nhds x, gx⟩ theorem denseRange_preStoneCechUnit : DenseRange (preStoneCechUnit : α → PreStoneCech α) := Quot.mk_surjective.denseRange.comp denseRange_pure continuous_coinduced_rng section Extension variable {β : Type v} [TopologicalSpace β] [T2Space β] theorem preStoneCech_hom_ext {g₁ g₂ : PreStoneCech α → β} (h₁ : Continuous g₁) (h₂ : Continuous g₂) (h : g₁ ∘ preStoneCechUnit = g₂ ∘ preStoneCechUnit) : g₁ = g₂ := by apply Continuous.ext_on denseRange_preStoneCechUnit h₁ h₂ rintro x ⟨x, rfl⟩ apply congr_fun h x variable [CompactSpace β] variable {g : α → β} (hg : Continuous g) include hg lemma preStoneCechCompat {F G : Ultrafilter α} {x : α} (hF : ↑F ≤ 𝓝 x) (hG : ↑G ≤ 𝓝 x) : Ultrafilter.extend g F = Ultrafilter.extend g G := by replace hF := (map_mono hF).trans hg.continuousAt replace hG := (map_mono hG).trans hg.continuousAt rwa [show Ultrafilter.extend g G = g x by rwa [ultrafilter_extend_eq_iff, G.coe_map], ultrafilter_extend_eq_iff, F.coe_map] /-- The extension of a continuous function from `α` to a compact Hausdorff space `β` to the pre-Stone-Čech compactification of `α`. -/ def preStoneCechExtend : PreStoneCech α → β := Quot.lift (Ultrafilter.extend g) fun _ _ ⟨_, hF, hG⟩ ↦ preStoneCechCompat hg hF hG @[simp] lemma preStoneCechExtend_extends : preStoneCechExtend hg ∘ preStoneCechUnit = g := ultrafilter_extend_extends g @[simp] lemma preStoneCechExtend_preStoneCechUnit (a : α) : preStoneCechExtend hg (preStoneCechUnit a) = g a := congr_fun (preStoneCechExtend_extends hg) a lemma eq_if_preStoneCechUnit_eq {a b : α} (h : preStoneCechUnit a = preStoneCechUnit b) : g a = g b := by have e := ultrafilter_extend_extends g rw [← congrFun e a, ← congrFun e b, Function.comp_apply, Function.comp_apply] rw [preStoneCechUnit, preStoneCechUnit, Quot.eq] at h generalize (pure a : Ultrafilter α) = F at h generalize (pure b : Ultrafilter α) = G at h induction h with | rel x y a => exact let ⟨a, hx, hy⟩ := a; preStoneCechCompat hg hx hy | refl x => rfl | symm x y _ h => rw [h] | trans x y z _ _ h h' => exact h.trans h' theorem continuous_preStoneCechExtend : Continuous (preStoneCechExtend hg) := continuous_quot_lift _ (continuous_ultrafilter_extend g) end Extension end PreStoneCech section StoneCech variable (α : Type u) [TopologicalSpace α] /-- The Stone-Čech compactification of a topological space. -/ def StoneCech : Type u := T2Quotient (PreStoneCech α) variable {α} instance : TopologicalSpace (StoneCech α) := inferInstanceAs <| TopologicalSpace <| T2Quotient _ instance : T2Space (StoneCech α) := inferInstanceAs <| T2Space <| T2Quotient _ instance : CompactSpace (StoneCech α) := Quot.compactSpace instance [Inhabited α] : Inhabited (StoneCech α) := inferInstanceAs <| Inhabited <| Quotient _ /-- The natural map from α to its Stone-Čech compactification. -/ def stoneCechUnit (x : α) : StoneCech α := T2Quotient.mk (preStoneCechUnit x) theorem continuous_stoneCechUnit : Continuous (stoneCechUnit : α → StoneCech α) := (T2Quotient.continuous_mk _).comp continuous_preStoneCechUnit /-- The image of `stoneCechUnit` is dense. (But `stoneCechUnit` need not be an embedding, for example if the original space is not Hausdorff.) -/ theorem denseRange_stoneCechUnit : DenseRange (stoneCechUnit : α → StoneCech α) := by unfold stoneCechUnit T2Quotient.mk have : Function.Surjective (T2Quotient.mk : PreStoneCech α → StoneCech α) := by exact Quot.mk_surjective exact this.denseRange.comp denseRange_preStoneCechUnit continuous_coinduced_rng section Extension variable {β : Type v} [TopologicalSpace β] [T2Space β] variable {g : α → β} (hg : Continuous g) theorem stoneCech_hom_ext {g₁ g₂ : StoneCech α → β} (h₁ : Continuous g₁) (h₂ : Continuous g₂) (h : g₁ ∘ stoneCechUnit = g₂ ∘ stoneCechUnit) : g₁ = g₂ := by apply h₁.ext_on denseRange_stoneCechUnit h₂ rintro _ ⟨x, rfl⟩ exact congr_fun h x variable [CompactSpace β] /-- The extension of a continuous function from `α` to a compact Hausdorff space `β` to the Stone-Čech compactification of `α`. This extension implements the universal property of this compactification. -/ def stoneCechExtend : StoneCech α → β := T2Quotient.lift (continuous_preStoneCechExtend hg) @[simp] lemma stoneCechExtend_extends : stoneCechExtend hg ∘ stoneCechUnit = g := by ext x rw [stoneCechExtend, Function.comp_apply, stoneCechUnit, T2Quotient.lift_mk] apply congrFun (preStoneCechExtend_extends hg) @[simp] lemma stoneCechExtend_stoneCechUnit (a : α) : stoneCechExtend hg (stoneCechUnit a) = g a := congr_fun (stoneCechExtend_extends hg) a theorem continuous_stoneCechExtend : Continuous (stoneCechExtend hg) := continuous_coinduced_dom.mpr (continuous_preStoneCechExtend hg) lemma eq_if_stoneCechUnit_eq {a b : α} {f : α → β} (hcf : Continuous f) (h : stoneCechUnit a = stoneCechUnit b) : f a = f b := by rw [← congrFun (stoneCechExtend_extends hcf), ← congrFun (stoneCechExtend_extends hcf)] exact congrArg (stoneCechExtend hcf) h end Extension end StoneCech
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).
Recall.lean
/- Copyright (c) 2023 Mac Malone. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mac Malone, Kyle Miller -/ import Mathlib.Init import Lean.Elab.Command import Lean.Elab.DeclUtil /-! # `recall` command -/ namespace Mathlib.Tactic.Recall /-- The `recall` command redeclares a previous definition for illustrative purposes. This can be useful for files that give an expository account of some theory in Lean. The syntax of the command mirrors `def`, so all the usual bells and whistles work. ``` recall List.cons_append (a : α) (as bs : List α) : (a :: as) ++ bs = a :: (as ++ bs) := rfl ``` Also, one can leave out the body. ``` recall Nat.add_comm (n m : Nat) : n + m = m + n ``` The command verifies that the new definition type-checks and that the type and value provided are definitionally equal to the original declaration. However, this does not capture some details (like binders), so the following works without error. ``` recall Nat.add_comm {n m : Nat} : n + m = m + n ``` -/ syntax (name := recall) "recall " ident ppIndent(optDeclSig) (declVal)? : command open Lean Meta Elab Command Term elab_rules : command | `(recall $id $sig:optDeclSig $[$val?]?) => withoutModifyingEnv do let declName := id.getId let some info := (← getEnv).find? declName | throwError "unknown constant '{declName}'" let declConst : Expr := mkConst declName <| info.levelParams.map Level.param discard <| liftTermElabM <| addTermInfo id declConst let newId := ({ namePrefix := declName : DeclNameGenerator }.mkUniqueName (← getEnv) `recall).1 let newId := mkIdentFrom id newId if let some val := val? then let some infoVal := info.value? | throwErrorAt val "constant '{declName}' has no defined value" elabCommand <| ← `(noncomputable def $newId $sig:optDeclSig $val) let some newInfo := (← getEnv).find? newId.getId | return -- def already threw liftTermElabM do let mvs ← newInfo.levelParams.mapM fun _ => mkFreshLevelMVar let newType := newInfo.type.instantiateLevelParams newInfo.levelParams mvs unless (← isDefEq info.type newType) do throwTypeMismatchError none info.type newInfo.type declConst let newVal := newInfo.value?.get!.instantiateLevelParams newInfo.levelParams mvs unless (← isDefEq infoVal newVal) do let err := m!"\ value mismatch{indentExpr declConst}\nhas value{indentExpr newVal}\n\ but is expected to have value{indentExpr infoVal}" throwErrorAt val err else let (binders, type?) := expandOptDeclSig sig if let some type := type? then runTermElabM fun vars => do withAutoBoundImplicit do elabBinders binders.getArgs fun xs => do let xs ← addAutoBoundImplicits xs none let type ← elabType type Term.synthesizeSyntheticMVarsNoPostponing let type ← mkForallFVars xs type let type ← mkForallFVars vars type (usedOnly := true) unless (← isDefEq info.type type) do throwTypeMismatchError none info.type type declConst else unless binders.getNumArgs == 0 do throwError "expected type after ':'" end Mathlib.Tactic.Recall
action.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun ssrnotations eqtype. From mathcomp Require Import ssrnat div seq prime fintype bigop finset. From mathcomp Require Import fingroup morphism perm automorphism quotient. (******************************************************************************) (* Group action: orbits, stabilisers, transitivity. *) (* is_action D to == the function to : T -> aT -> T defines an action *) (* of D : {set aT} on T. *) (* action D T == structure for a function defining an action of D. *) (* act_dom to == the domain D of to : action D rT. *) (* {action: aT &-> T} == structure for a total action. *) (* := action [set: aT] T *) (* TotalAction to1 toM == the constructor for total actions; to1 and toM *) (* are the proofs of the action identities for 1 and *) (* a * b, respectively. *) (* is_groupAction R to == to is a group action on range R: for all a in D, *) (* the permutation induced by to a is in Aut R. Thus *) (* the action of D must be trivial outside R. *) (* groupAction D R == the structure for group actions of D on R. This *) (* is a telescope on action D rT. *) (* gact_range to == the range R of to : groupAction D R. *) (* GroupAction toAut == constructs a groupAction for action to from *) (* toAut : actm to @* D \subset Aut R (actm to is *) (* the morphism to {perm rT} associated to 'to'). *) (* orbit to A x == the orbit of x under the action of A via to. *) (* orbit_transversal to A S == a transversal of the partition orbit to A @: S *) (* of S, provided A acts on S via to. *) (* amove to A x y == the set of a in A whose action sends x to y. *) (* 'C_A[x | to] == the stabiliser of x : rT in A :&: D. *) (* 'C_A(S | to) == the pointwise stabiliser of S : {set rT} in D :&: A. *) (* 'N_A(S | to) == the global stabiliser of S : {set rT} in D :&: A. *) (* 'Fix_(S | to)[a] == the set of fixpoints of a in S. *) (* 'Fix_(S | to)(A) == the set of fixpoints of A in S. *) (* In the first three _A can be omitted and defaults to the domain D of to; *) (* in the last two S can be omitted and defaults to [set: T], so 'Fix_to[a] *) (* is the set of all fixpoints of a. *) (* The domain restriction ensures that stabilisers have a canonical group *) (* structure, but note that 'Fix sets are generally not groups. Indeed, we *) (* provide alternative definitions when to is a group action on R: *) (* 'C_(G | to)(A) == the centraliser in R :&: G of the group action of *) (* D :&: A via to *) (* 'C_(G | to)[a] == the centraliser in R :&: G of a \in D, via to. *) (* These sets are groups when G is; G can be omitted: 'C(|to)(A) is the *) (* centraliser in R of the action of D :&: A via to. *) (* [acts A, on S | to] == A \subset D acts on the set S via to. *) (* {acts A, on S | to} == A acts on the set S (Prop statement). *) (* {acts A, on group G | to} == [acts A, on S | to] /\ G \subset R, i.e., *) (* A \subset D acts on G \subset R, via *) (* to : groupAction D R. *) (* [transitive A, on S | to] == A acts transitively on S. *) (* [faithful A, on S | to] == A acts faithfully on S. *) (* acts_irreducibly to A G == A acts irreducibly via the groupAction to *) (* on the nontrivial group G, i.e., A does *) (* not act on any nontrivial subgroup of G. *) (* Important caveat: the definitions of orbit, amove, 'Fix_(S | to)(A), *) (* transitive and faithful assume that A is a subset of the domain D. As most *) (* of the permutation actions we consider are total this is usually harmless. *) (* (Note that the theory of partial actions is only partially developed.) *) (* In all of the above, to is expected to be the actual action structure, *) (* not merely the function. There is a special scope %act for actions, and *) (* constructions and notations for many classical actions: *) (* 'P == natural action of a permutation group via aperm. *) (* 'J == internal group action (conjugation) via conjg (_ ^ _). *) (* 'R == regular group action (right translation) via mulg (_ * _). *) (* (However, to limit ambiguity, _ * _ is NOT a canonical action.) *) (* to^* == the action induced by to on {set rT} via to^* (== setact to). *) (* 'Js == the internal action on subsets via _ :^ _, equivalent to 'J^*. *) (* 'Rs == the regular action on subsets via rcoset, equivalent to 'R^*. *) (* 'JG == the conjugation action on {group rT} via (_ :^ _)%G. *) (* to / H == the action induced by to on coset_of H via qact to H, and *) (* restricted to (qact_dom to H) == 'N(rcosets H 'N(H) | to^* ). *) (* 'Q == the action induced to cosets by conjugation; the domain is *) (* qact_dom 'J H, which is provably equal to 'N(H). *) (* to %% A == the action of coset_of A via modact to A, with domain D / A *) (* and support restricted to 'C(D :&: A | to). *) (* to \ sAD == the action of A via ract to sAD == to, if sAD : A \subset D. *) (* [Aut G] == the permutation action restricted to Aut G, via autact G. *) (* <[nRA]> == the action of A on R via actby nRA == to in A and on R, and *) (* the trivial action elsewhere; here nRA : [acts A, on R | to] *) (* or nRA : {acts A, on group R | to}. *) (* to^? == the action induced by to on sT : @subType rT P, via subact to *) (* with domain subact_dom P to == 'N([set x | P x] | to). *) (* <<phi>> == the action of phi : D >-> {perm rT}, via mact phi. *) (* to \o f == the composite action (with domain f @*^-1 D) of the action to *) (* with f : {morphism G >-> aT}, via comp_act to f. Here f must *) (* be the actual morphism object (e.g., coset_morphism H), not *) (* the underlying function (e.g., coset H). *) (* The explicit application of an action to is usually written (to%act x a), *) (* but %act can be omitted if to is an abstract action or a set action to^*. *) (* Note that this form will simplify and expose the acting function. *) (* There is a %gact scope for group actions; the notations above are *) (* recognised in %gact when they denote canonical group actions. *) (* Actions can be used to define morphisms: *) (* actperm to == the morphism D >-> {perm rT} induced by to. *) (* actm to a == if a \in D the function on D induced by the action to, else *) (* the identity function. If to is a group action with range R *) (* then actm to a is canonically a morphism on R. *) (* We also define here the restriction operation on permutations (the domain *) (* of this operations is a stabiliser), and local automorphism groups: *) (* restr_perm S p == if p acts on S, the permutation with support in S that *) (* coincides with p on S; else the identity. Note that *) (* restr_perm is a permutation group morphism that maps *) (* Aut G to Aut S when S is a subgroup of G. *) (* Aut_in A G == the local permutation group 'N_A(G | 'P) / 'C_A(G | 'P) *) (* Usually A is an automorphism group, and then Aut_in A G *) (* is isomorphic to a subgroup of Aut G, specifically *) (* restr_perm @* A. *) (* Finally, gproduct.v will provide a semi-direct group construction that *) (* maps an external group action to an internal one; the theory of morphisms *) (* between such products makes use of the following definition: *) (* morph_act to to' f fA <=> the action of to' on the images of f and fA is *) (* the image of the action of to, i.e., for all x and a we *) (* have f (to x a) = to' (f x) (fA a). Note that there is *) (* no mention of the domains of to and to'; if needed, this *) (* predicate should be restricted via the {in ...} notation *) (* and domain conditions should be added. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope action_scope. Declare Scope groupAction_scope. Import GroupScope. Section ActionDef. Variables (aT : finGroupType) (D : {set aT}) (rT : Type). Implicit Types a b : aT. Implicit Type x : rT. Definition act_morph to x := forall a b, to x (a * b) = to (to x a) b. Definition is_action to := left_injective to /\ forall x, {in D &, act_morph to x}. Record action := Action {act :> rT -> aT -> rT; _ : is_action act}. Definition clone_action to := let: Action _ toP := to return {type of Action for to} -> action in fun k => k toP. End ActionDef. (* Need to close the Section here to avoid re-declaring all Argument Scopes *) Delimit Scope action_scope with act. Bind Scope action_scope with action. Arguments act_morph {aT rT%_type} to x%_g. Arguments is_action {aT} D%_g {rT} to. Arguments act {aT D%_g rT%_type} to%_act x%_g a%_g : rename. Arguments clone_action [aT D%_g rT%_type to%_act] _. Notation "{ 'action' aT &-> T }" := (action [set: aT] T) (format "{ 'action' aT &-> T }") : type_scope. Notation "[ 'action' 'of' to ]" := (clone_action (@Action _ _ _ to)) (format "[ 'action' 'of' to ]") : form_scope. Definition act_dom aT D rT of @action aT D rT := D. Section TotalAction. Variables (aT : finGroupType) (rT : Type) (to : rT -> aT -> rT). Hypotheses (to1 : to^~ 1 =1 id) (toM : forall x, act_morph to x). Lemma is_total_action : is_action setT to. Proof. split=> [a | x a b _ _] /=; last by rewrite toM. by apply: can_inj (to^~ a^-1) _ => x; rewrite -toM ?mulgV. Qed. Definition TotalAction := Action is_total_action. End TotalAction. Section ActionDefs. Variables (aT aT' : finGroupType) (D : {set aT}) (D' : {set aT'}). Definition morph_act rT rT' (to : action D rT) (to' : action D' rT') f fA := forall x a, f (to x a) = to' (f x) (fA a). Variable rT : finType. (* Most definitions require a finType structure on rT *) Implicit Type to : action D rT. Implicit Type A : {set aT}. Implicit Type S : {set rT}. Definition actm to a := if a \in D then to^~ a else id. Definition setact to S a := [set to x a | x in S]. Definition orbit to A x := to x @: A. Definition amove to A x y := [set a in A | to x a == y]. Definition afix to A := [set x | A \subset [set a | to x a == x]]. Definition astab S to := D :&: [set a | S \subset [set x | to x a == x]]. Definition astabs S to := D :&: [set a | S \subset to^~ a @^-1: S]. Definition acts_on A S to := {in A, forall a x, (to x a \in S) = (x \in S)}. Definition atrans A S to := S \in orbit to A @: S. Definition faithful A S to := A :&: astab S to \subset [1]. End ActionDefs. Arguments setact {aT D%_g rT} to%_act S%_g a%_g. Arguments orbit {aT D%_g rT} to%_act A%_g x%_g. Arguments amove {aT D%_g rT} to%_act A%_g x%_g y%_g. Arguments afix {aT D%_g rT} to%_act A%_g. Arguments astab {aT D%_g rT} S%_g to%_act. Arguments astabs {aT D%_g rT} S%_g to%_act. Arguments acts_on {aT D%_g rT} A%_g S%_g to%_act. Arguments atrans {aT D%_g rT} A%_g S%_g to%_act. Arguments faithful {aT D%_g rT} A%_g S%_g to%_act. Notation "to ^*" := (setact to) : function_scope. Prenex Implicits orbit amove. Notation "''Fix_' to ( A )" := (afix to A) (to at level 2, format "''Fix_' to ( A )") : group_scope. (* camlp4 grammar factoring *) Notation "''Fix_' ( to ) ( A )" := 'Fix_to(A) (only parsing) : group_scope. Notation "''Fix_' ( S | to ) ( A )" := (S :&: 'Fix_to(A)) (format "''Fix_' ( S | to ) ( A )") : group_scope. Notation "''Fix_' to [ a ]" := ('Fix_to([set a])) (to at level 2, format "''Fix_' to [ a ]") : group_scope. Notation "''Fix_' ( S | to ) [ a ]" := (S :&: 'Fix_to[a]) (format "''Fix_' ( S | to ) [ a ]") : group_scope. Notation "''C' ( S | to )" := (astab S to) : group_scope. Notation "''C_' A ( S | to )" := (A :&: 'C(S | to)) : group_scope. Notation "''C_' ( A ) ( S | to )" := 'C_A(S | to) (only parsing) : group_scope. Notation "''C' [ x | to ]" := ('C([set x] | to)) : group_scope. Notation "''C_' A [ x | to ]" := (A :&: 'C[x | to]) : group_scope. Notation "''C_' ( A ) [ x | to ]" := 'C_A[x | to] (only parsing) : group_scope. Notation "''N' ( S | to )" := (astabs S to) (format "''N' ( S | to )") : group_scope. Notation "''N_' A ( S | to )" := (A :&: 'N(S | to)) (A at level 2, format "''N_' A ( S | to )") : group_scope. Notation "[ 'acts' A , 'on' S | to ]" := (A \subset pred_of_set 'N(S | to)) (format "[ 'acts' A , 'on' S | to ]") : form_scope. Notation "{ 'acts' A , 'on' S | to }" := (acts_on A S to) (format "{ 'acts' A , 'on' S | to }") : type_scope. Notation "[ 'transitive' A , 'on' S | to ]" := (atrans A S to) (format "[ 'transitive' A , 'on' S | to ]") : form_scope. Notation "[ 'faithful' A , 'on' S | to ]" := (faithful A S to) (format "[ 'faithful' A , 'on' S | to ]") : form_scope. Section RawAction. (* Lemmas that do not require the group structure on the action domain. *) (* Some lemmas like actMin would be actually be valid for arbitrary rT, *) (* e.g., for actions on a function type, but would be difficult to use *) (* as a view due to the confusion between parameters and assumptions. *) Variables (aT : finGroupType) (D : {set aT}) (rT : finType) (to : action D rT). Implicit Types (a : aT) (x y : rT) (A B : {set aT}) (S T : {set rT}). Lemma act_inj : left_injective to. Proof. by case: to => ? []. Qed. Arguments act_inj : clear implicits. Lemma actMin x : {in D &, act_morph to x}. Proof. by case: to => ? []. Qed. Lemma actmEfun a : a \in D -> actm to a = to^~ a. Proof. by rewrite /actm => ->. Qed. Lemma actmE a : a \in D -> actm to a =1 to^~ a. Proof. by move=> Da; rewrite actmEfun. Qed. Lemma setactE S a : to^* S a = [set to x a | x in S]. Proof. by []. Qed. Lemma mem_setact S a x : x \in S -> to x a \in to^* S a. Proof. exact: imset_f. Qed. Lemma card_setact S a : #|to^* S a| = #|S|. Proof. by apply: card_imset; apply: act_inj. Qed. Lemma setact_is_action : is_action D to^*. Proof. split=> [a R S eqRS | a b Da Db S]; last first. by rewrite /setact /= -imset_comp; apply: eq_imset => x; apply: actMin. apply/setP=> x; apply/idP/idP=> /(mem_setact a). by rewrite eqRS => /imsetP[y Sy /act_inj->]. by rewrite -eqRS => /imsetP[y Sy /act_inj->]. Qed. Canonical set_action := Action setact_is_action. Lemma orbitE A x : orbit to A x = to x @: A. Proof. by []. Qed. Lemma orbitP A x y : reflect (exists2 a, a \in A & to x a = y) (y \in orbit to A x). Proof. by apply: (iffP imsetP) => [] [a]; exists a. Qed. Lemma mem_orbit A x a : a \in A -> to x a \in orbit to A x. Proof. exact: imset_f. Qed. Lemma afixP A x : reflect (forall a, a \in A -> to x a = x) (x \in 'Fix_to(A)). Proof. rewrite inE; apply: (iffP subsetP) => [xfix a /xfix | xfix a Aa]. by rewrite inE => /eqP. by rewrite inE xfix. Qed. Lemma afixS A B : A \subset B -> 'Fix_to(B) \subset 'Fix_to(A). Proof. by move=> sAB; apply/subsetP=> u /[!inE]; apply: subset_trans. Qed. Lemma afixU A B : 'Fix_to(A :|: B) = 'Fix_to(A) :&: 'Fix_to(B). Proof. by apply/setP=> x; rewrite !inE subUset. Qed. Lemma afix1P a x : reflect (to x a = x) (x \in 'Fix_to[a]). Proof. by rewrite inE sub1set inE; apply: eqP. Qed. Lemma astabIdom S : 'C_D(S | to) = 'C(S | to). Proof. by rewrite setIA setIid. Qed. Lemma astab_dom S : {subset 'C(S | to) <= D}. Proof. by move=> a /setIP[]. Qed. Lemma astab_act S a x : a \in 'C(S | to) -> x \in S -> to x a = x. Proof. rewrite 2!inE => /andP[_ cSa] Sx; apply/eqP. by have /[1!inE] := subsetP cSa x Sx. Qed. Lemma astabS S1 S2 : S1 \subset S2 -> 'C(S2 | to) \subset 'C(S1 | to). Proof. by move=> sS12; apply/subsetP=> x /[!inE] /andP[->]; apply: subset_trans. Qed. Lemma astabsIdom S : 'N_D(S | to) = 'N(S | to). Proof. by rewrite setIA setIid. Qed. Lemma astabs_dom S : {subset 'N(S | to) <= D}. Proof. by move=> a /setIdP[]. Qed. Lemma astabs_act S a x : a \in 'N(S | to) -> (to x a \in S) = (x \in S). Proof. rewrite 2!inE subEproper properEcard => /andP[_]. rewrite (card_preimset _ (act_inj _)) ltnn andbF orbF => /eqP{2}->. by rewrite inE. Qed. Lemma astab_sub S : 'C(S | to) \subset 'N(S | to). Proof. apply/subsetP=> a cSa; rewrite !inE (astab_dom cSa). by apply/subsetP=> x Sx; rewrite inE (astab_act cSa). Qed. Lemma astabsC S : 'N(~: S | to) = 'N(S | to). Proof. apply/setP=> a; apply/idP/idP=> nSa; rewrite !inE (astabs_dom nSa). by rewrite -setCS -preimsetC; apply/subsetP=> x; rewrite inE astabs_act. by rewrite preimsetC setCS; apply/subsetP=> x; rewrite inE astabs_act. Qed. Lemma astabsI S T : 'N(S | to) :&: 'N(T | to) \subset 'N(S :&: T | to). Proof. apply/subsetP=> a; rewrite !inE -!andbA preimsetI => /and4P[-> nSa _ nTa] /=. by rewrite setISS. Qed. Lemma astabs_setact S a : a \in 'N(S | to) -> to^* S a = S. Proof. move=> nSa; apply/eqP; rewrite eqEcard card_setact leqnn andbT. by apply/subsetP=> _ /imsetP[x Sx ->]; rewrite astabs_act. Qed. Lemma astab1_set S : 'C[S | set_action] = 'N(S | to). Proof. apply/setP=> a; apply/idP/idP=> nSa. case/setIdP: nSa => Da; rewrite !inE Da sub1set inE => /eqP defS. by apply/subsetP=> x Sx; rewrite inE -defS mem_setact. by rewrite !inE (astabs_dom nSa) sub1set inE /= astabs_setact. Qed. Lemma astabs_set1 x : 'N([set x] | to) = 'C[x | to]. Proof. apply/eqP; rewrite eqEsubset astab_sub andbC setIS //. by apply/subsetP=> a; rewrite ?(inE,sub1set). Qed. Lemma acts_dom A S : [acts A, on S | to] -> A \subset D. Proof. by move=> nSA; rewrite (subset_trans nSA) ?subsetIl. Qed. Lemma acts_act A S : [acts A, on S | to] -> {acts A, on S | to}. Proof. by move=> nAS a Aa x; rewrite astabs_act ?(subsetP nAS). Qed. Lemma astabCin A S : A \subset D -> (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)). Proof. move=> sAD; apply/subsetP/subsetP=> [sAC x xS | sSF a aA]. by apply/afixP=> a aA; apply: astab_act (sAC _ aA) xS. rewrite !inE (subsetP sAD _ aA); apply/subsetP=> x xS. by move/afixP/(_ _ aA): (sSF _ xS) => /[1!inE] ->. Qed. Section ActsSetop. Variables (A : {set aT}) (S T : {set rT}). Hypotheses (AactS : [acts A, on S | to]) (AactT : [acts A, on T | to]). Lemma astabU : 'C(S :|: T | to) = 'C(S | to) :&: 'C(T | to). Proof. by apply/setP=> a; rewrite !inE subUset; case: (a \in D). Qed. Lemma astabsU : 'N(S | to) :&: 'N(T | to) \subset 'N(S :|: T | to). Proof. by rewrite -(astabsC S) -(astabsC T) -(astabsC (S :|: T)) setCU astabsI. Qed. Lemma astabsD : 'N(S | to) :&: 'N(T | to) \subset 'N(S :\: T| to). Proof. by rewrite setDE -(astabsC T) astabsI. Qed. Lemma actsI : [acts A, on S :&: T | to]. Proof. by apply: subset_trans (astabsI S T); rewrite subsetI AactS. Qed. Lemma actsU : [acts A, on S :|: T | to]. Proof. by apply: subset_trans astabsU; rewrite subsetI AactS. Qed. Lemma actsD : [acts A, on S :\: T | to]. Proof. by apply: subset_trans astabsD; rewrite subsetI AactS. Qed. End ActsSetop. Lemma acts_in_orbit A S x y : [acts A, on S | to] -> y \in orbit to A x -> x \in S -> y \in S. Proof. by move=> nSA/imsetP[a Aa ->{y}] Sx; rewrite (astabs_act _ (subsetP nSA a Aa)). Qed. Lemma subset_faithful A B S : B \subset A -> [faithful A, on S | to] -> [faithful B, on S | to]. Proof. by move=> sAB; apply: subset_trans; apply: setSI. Qed. Section Reindex. Variables (vT : Type) (idx : vT) (op : Monoid.com_law idx) (S : {set rT}). Lemma reindex_astabs a F : a \in 'N(S | to) -> \big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a). Proof. move=> nSa; rewrite (reindex_inj (act_inj a)); apply: eq_bigl => x. exact: astabs_act. Qed. Lemma reindex_acts A a F : [acts A, on S | to] -> a \in A -> \big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a). Proof. by move=> nSA /(subsetP nSA); apply: reindex_astabs. Qed. End Reindex. End RawAction. Arguments act_inj {aT D rT} to a [x1 x2] : rename. Notation "to ^*" := (set_action to) : action_scope. Arguments orbitP {aT D rT to A x y}. Arguments afixP {aT D rT to A x}. Arguments afix1P {aT D rT to a x}. Arguments reindex_astabs [aT D rT] to [vT idx op S] a [F]. Arguments reindex_acts [aT D rT] to [vT idx op S A a F]. Section PartialAction. (* Lemmas that require a (partial) group domain. *) Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Implicit Types a : aT. Implicit Types x y : rT. Implicit Types A B : {set aT}. Implicit Types G H : {group aT}. Implicit Types S : {set rT}. Lemma act1 x : to x 1 = x. Proof. by apply: (act_inj to 1); rewrite -actMin ?mulg1. Qed. Lemma actKin : {in D, right_loop invg to}. Proof. by move=> a Da /= x; rewrite -actMin ?groupV // mulgV act1. Qed. Lemma actKVin : {in D, rev_right_loop invg to}. Proof. by move=> a Da /= x; rewrite -{2}(invgK a) actKin ?groupV. Qed. Lemma setactVin S a : a \in D -> to^* S a^-1 = to^~ a @^-1: S. Proof. by move=> Da; apply: can2_imset_pre; [apply: actKVin | apply: actKin]. Qed. Lemma actXin x a i : a \in D -> to x (a ^+ i) = iter i (to^~ a) x. Proof. move=> Da; elim: i => /= [|i <-]; first by rewrite act1. by rewrite expgSr actMin ?groupX. Qed. Lemma afix1 : 'Fix_to(1) = setT. Proof. by apply/setP=> x; rewrite !inE sub1set inE act1 eqxx. Qed. Lemma afixD1 G : 'Fix_to(G^#) = 'Fix_to(G). Proof. by rewrite -{2}(setD1K (group1 G)) afixU afix1 setTI. Qed. Lemma orbit_refl G x : x \in orbit to G x. Proof. by rewrite -{1}[x]act1 mem_orbit. Qed. Local Notation orbit_rel A := (fun x y => x \in orbit to A y). Lemma contra_orbit G x y : x \notin orbit to G y -> x != y. Proof. by apply: contraNneq => ->; apply: orbit_refl. Qed. Lemma orbit_in_sym G : G \subset D -> symmetric (orbit_rel G). Proof. move=> sGD; apply: symmetric_from_pre => x y /imsetP[a Ga]. by move/(canLR (actKin (subsetP sGD a Ga))) <-; rewrite mem_orbit ?groupV. Qed. Lemma orbit_in_trans G : G \subset D -> transitive (orbit_rel G). Proof. move=> sGD _ _ z /imsetP[a Ga ->] /imsetP[b Gb ->]. by rewrite -actMin ?mem_orbit ?groupM // (subsetP sGD). Qed. Lemma orbit_in_eqP G x y : G \subset D -> reflect (orbit to G x = orbit to G y) (x \in orbit to G y). Proof. move=> sGD; apply: (iffP idP) => [yGx|<-]; last exact: orbit_refl. by apply/setP=> z; apply/idP/idP=> /orbit_in_trans-> //; rewrite orbit_in_sym. Qed. Lemma orbit_in_transl G x y z : G \subset D -> y \in orbit to G x -> (y \in orbit to G z) = (x \in orbit to G z). Proof. by move=> sGD Gxy; rewrite !(orbit_in_sym sGD _ z) (orbit_in_eqP y x sGD Gxy). Qed. Lemma orbit_act_in x a G : G \subset D -> a \in G -> orbit to G (to x a) = orbit to G x. Proof. by move=> sGD /mem_orbit/orbit_in_eqP->. Qed. Lemma orbit_actr_in x a G y : G \subset D -> a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x). Proof. by move=> sGD /mem_orbit/orbit_in_transl->. Qed. Lemma orbit_inv_in A x y : A \subset D -> (y \in orbit to A^-1 x) = (x \in orbit to A y). Proof. move/subsetP=> sAD; apply/imsetP/imsetP=> [] [a Aa ->]. by exists a^-1; rewrite -?mem_invg ?actKin // -groupV sAD -?mem_invg. by exists a^-1; rewrite ?memV_invg ?actKin // sAD. Qed. Lemma orbit_lcoset_in A a x : A \subset D -> a \in D -> orbit to (a *: A) x = orbit to A (to x a). Proof. move/subsetP=> sAD Da; apply/setP=> y; apply/imsetP/imsetP=> [] [b Ab ->{y}]. by exists (a^-1 * b); rewrite -?actMin ?mulKVg // ?sAD -?mem_lcoset. by exists (a * b); rewrite ?mem_mulg ?set11 ?actMin // sAD. Qed. Lemma orbit_rcoset_in A a x y : A \subset D -> a \in D -> (to y a \in orbit to (A :* a) x) = (y \in orbit to A x). Proof. move=> sAD Da; rewrite -orbit_inv_in ?mul_subG ?sub1set // invMg. by rewrite invg_set1 orbit_lcoset_in ?inv_subG ?groupV ?actKin ?orbit_inv_in. Qed. Lemma orbit_conjsg_in A a x y : A \subset D -> a \in D -> (to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x). Proof. move=> sAD Da; rewrite conjsgE. by rewrite orbit_lcoset_in ?groupV ?mul_subG ?sub1set ?actKin ?orbit_rcoset_in. Qed. Lemma orbit1P G x : reflect (orbit to G x = [set x]) (x \in 'Fix_to(G)). Proof. apply: (iffP afixP) => [xfix | xfix a Ga]. apply/eqP; rewrite eq_sym eqEsubset sub1set -{1}[x]act1 imset_f //=. by apply/subsetP=> y; case/imsetP=> a Ga ->; rewrite inE xfix. by apply/set1P; rewrite -xfix imset_f. Qed. Lemma card_orbit1 G x : #|orbit to G x| = 1%N -> orbit to G x = [set x]. Proof. move=> orb1; apply/eqP; rewrite eq_sym eqEcard {}orb1 cards1. by rewrite sub1set orbit_refl. Qed. Lemma orbit_partition G S : [acts G, on S | to] -> partition (orbit to G @: S) S. Proof. move=> actsGS; have sGD := acts_dom actsGS. have eqiG: {in S & &, equivalence_rel [rel x y | y \in orbit to G x]}. by move=> x y z * /=; rewrite orbit_refl; split=> // /orbit_in_eqP->. congr (partition _ _): (equivalence_partitionP eqiG). apply: eq_in_imset => x Sx; apply/setP=> y. by rewrite inE /= andb_idl // => /acts_in_orbit->. Qed. Definition orbit_transversal A S := transversal (orbit to A @: S) S. Lemma orbit_transversalP G S (P := orbit to G @: S) (X := orbit_transversal G S) : [acts G, on S | to] -> [/\ is_transversal X P S, X \subset S, {in X &, forall x y, (y \in orbit to G x) = (x == y)} & forall x, x \in S -> exists2 a, a \in G & to x a \in X]. Proof. move/orbit_partition; rewrite -/P => partP. have [/eqP defS tiP _] := and3P partP. have trXP: is_transversal X P S := transversalP partP. have sXS: X \subset S := transversal_sub trXP. split=> // [x y Xx Xy /= | x Sx]. have Sx := subsetP sXS x Xx. rewrite -(inj_in_eq (pblock_inj trXP)) // eq_pblock ?defS //. by rewrite (def_pblock tiP (imset_f _ Sx)) ?orbit_refl. have /imsetP[y Xy defxG]: orbit to G x \in pblock P @: X. by rewrite (pblock_transversal trXP) ?imset_f. suffices /orbitP[a Ga def_y]: y \in orbit to G x by exists a; rewrite ?def_y. by rewrite defxG mem_pblock defS (subsetP sXS). Qed. Lemma group_set_astab S : group_set 'C(S | to). Proof. apply/group_setP; split=> [|a b cSa cSb]. by rewrite !inE group1; apply/subsetP=> x _; rewrite inE act1. rewrite !inE groupM ?(@astab_dom _ _ _ to S) //; apply/subsetP=> x Sx. by rewrite inE actMin ?(@astab_dom _ _ _ to S) ?(astab_act _ Sx). Qed. Canonical astab_group S := group (group_set_astab S). Lemma afix_gen_in A : A \subset D -> 'Fix_to(<<A>>) = 'Fix_to(A). Proof. move=> sAD; apply/eqP; rewrite eqEsubset afixS ?sub_gen //=. by rewrite -astabCin gen_subG ?astabCin. Qed. Lemma afix_cycle_in a : a \in D -> 'Fix_to(<[a]>) = 'Fix_to[a]. Proof. by move=> Da; rewrite afix_gen_in ?sub1set. Qed. Lemma afixYin A B : A \subset D -> B \subset D -> 'Fix_to(A <*> B) = 'Fix_to(A) :&: 'Fix_to(B). Proof. by move=> sAD sBD; rewrite afix_gen_in ?afixU // subUset sAD. Qed. Lemma afixMin G H : G \subset D -> H \subset D -> 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H). Proof. by move=> sGD sHD; rewrite -afix_gen_in ?mul_subG // genM_join afixYin. Qed. Lemma sub_astab1_in A x : A \subset D -> (A \subset 'C[x | to]) = (x \in 'Fix_to(A)). Proof. by move=> sAD; rewrite astabCin ?sub1set. Qed. Lemma group_set_astabs S : group_set 'N(S | to). Proof. apply/group_setP; split=> [|a b cSa cSb]. by rewrite !inE group1; apply/subsetP=> x Sx; rewrite inE act1. rewrite !inE groupM ?(@astabs_dom _ _ _ to S) //; apply/subsetP=> x Sx. by rewrite inE actMin ?(@astabs_dom _ _ _ to S) ?astabs_act. Qed. Canonical astabs_group S := group (group_set_astabs S). Lemma astab_norm S : 'N(S | to) \subset 'N('C(S | to)). Proof. apply/subsetP=> a nSa; rewrite inE sub_conjg; apply/subsetP=> b cSb. have [Da Db] := (astabs_dom nSa, astab_dom cSb). rewrite mem_conjgV !inE groupJ //; apply/subsetP=> x Sx. rewrite inE !actMin ?groupM ?groupV //. by rewrite (astab_act cSb) ?actKVin ?astabs_act ?groupV. Qed. Lemma astab_normal S : 'C(S | to) <| 'N(S | to). Proof. by rewrite /normal astab_sub astab_norm. Qed. Lemma acts_sub_orbit G S x : [acts G, on S | to] -> (orbit to G x \subset S) = (x \in S). Proof. move/acts_act=> GactS. apply/subsetP/idP=> [| Sx y]; first by apply; apply: orbit_refl. by case/orbitP=> a Ga <-{y}; rewrite GactS. Qed. Lemma acts_orbit G x : G \subset D -> [acts G, on orbit to G x | to]. Proof. move/subsetP=> sGD; apply/subsetP=> a Ga; rewrite !inE sGD //. apply/subsetP=> _ /imsetP[b Gb ->]. by rewrite inE -actMin ?sGD // imset_f ?groupM. Qed. Lemma acts_subnorm_fix A : [acts 'N_D(A), on 'Fix_to(D :&: A) | to]. Proof. apply/subsetP=> a nAa; have [Da _] := setIP nAa; rewrite !inE Da. apply/subsetP=> x Cx /[1!inE]; apply/afixP=> b DAb. have [Db _]:= setIP DAb; rewrite -actMin // conjgCV actMin ?groupJ ?groupV //. by rewrite /= (afixP Cx) // memJ_norm // groupV (subsetP (normsGI _ _) _ nAa). Qed. Lemma atrans_orbit G x : [transitive G, on orbit to G x | to]. Proof. by apply: imset_f; apply: orbit_refl. Qed. Section OrbitStabilizer. Variables (G : {group aT}) (x : rT). Hypothesis sGD : G \subset D. Let ssGD := subsetP sGD. Lemma amove_act a : a \in G -> amove to G x (to x a) = 'C_G[x | to] :* a. Proof. move=> Ga; apply/setP=> b; have Da := ssGD Ga. rewrite mem_rcoset !(inE, sub1set) !groupMr ?groupV //. by case Gb: (b \in G); rewrite //= actMin ?groupV ?ssGD ?(canF_eq (actKVin Da)). Qed. Lemma amove_orbit : amove to G x @: orbit to G x = rcosets 'C_G[x | to] G. Proof. apply/setP => Ha; apply/imsetP/rcosetsP=> [[y] | [a Ga ->]]. by case/imsetP=> b Gb -> ->{Ha y}; exists b => //; rewrite amove_act. by rewrite -amove_act //; exists (to x a); first apply: mem_orbit. Qed. Lemma amoveK : {in orbit to G x, cancel (amove to G x) (fun Ca => to x (repr Ca))}. Proof. move=> _ /orbitP[a Ga <-]; rewrite amove_act //= -[G :&: _]/(gval _). case: repr_rcosetP => b; rewrite !(inE, sub1set)=> /and3P[Gb _ xbx]. by rewrite actMin ?ssGD ?(eqP xbx). Qed. Lemma orbit_stabilizer : orbit to G x = [set to x (repr Ca) | Ca in rcosets 'C_G[x | to] G]. Proof. rewrite -amove_orbit -imset_comp /=; apply/setP=> z. by apply/idP/imsetP=> [xGz | [y xGy ->]]; first exists z; rewrite /= ?amoveK. Qed. Lemma act_reprK : {in rcosets 'C_G[x | to] G, cancel (to x \o repr) (amove to G x)}. Proof. move=> _ /rcosetsP[a Ga ->] /=; rewrite amove_act ?rcoset_repr //. rewrite -[G :&: _]/(gval _); case: repr_rcosetP => b /setIP[Gb _]. exact: groupM. Qed. End OrbitStabilizer. Lemma card_orbit_in G x : G \subset D -> #|orbit to G x| = #|G : 'C_G[x | to]|. Proof. move=> sGD; rewrite orbit_stabilizer 1?card_in_imset //. exact: can_in_inj (act_reprK _). Qed. Lemma card_orbit_in_stab G x : G \subset D -> (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|. Proof. by move=> sGD; rewrite mulnC card_orbit_in ?Lagrange ?subsetIl. Qed. Lemma acts_sum_card_orbit G S : [acts G, on S | to] -> \sum_(T in orbit to G @: S) #|T| = #|S|. Proof. by move/orbit_partition/card_partition. Qed. Lemma astab_setact_in S a : a \in D -> 'C(to^* S a | to) = 'C(S | to) :^ a. Proof. move=> Da; apply/setP=> b; rewrite mem_conjg !inE -mem_conjg conjGid //. apply: andb_id2l => Db; rewrite sub_imset_pre; apply: eq_subset_r => x. by rewrite !inE !actMin ?groupM ?groupV // invgK (canF_eq (actKVin Da)). Qed. Lemma astab1_act_in x a : a \in D -> 'C[to x a | to] = 'C[x | to] :^ a. Proof. by move=> Da; rewrite -astab_setact_in // /setact imset_set1. Qed. Theorem Frobenius_Cauchy G S : [acts G, on S | to] -> \sum_(a in G) #|'Fix_(S | to)[a]| = (#|orbit to G @: S| * #|G|)%N. Proof. move=> GactS; have sGD := acts_dom GactS. transitivity (\sum_(a in G) \sum_(x in 'Fix_(S | to)[a]) 1%N). by apply: eq_bigr => a _; rewrite -sum1_card. rewrite (exchange_big_dep [in S]) /= => [|a x _]; last by case/setIP. rewrite (set_partition_big _ (orbit_partition GactS)) -sum_nat_const /=. apply: eq_bigr => _ /imsetP[x Sx ->]. rewrite -(card_orbit_in_stab x sGD) -sum_nat_const. apply: eq_bigr => y; rewrite orbit_in_sym // => /imsetP[a Ga defx]. rewrite defx astab1_act_in ?(subsetP sGD) //. rewrite -{2}(conjGid Ga) -conjIg cardJg -sum1_card setIA (setIidPl sGD). by apply: eq_bigl => b; rewrite !(sub1set, inE) -(acts_act GactS Ga) -defx Sx. Qed. Lemma atrans_dvd_index_in G S : G \subset D -> [transitive G, on S | to] -> #|S| %| #|G : 'C_G(S | to)|. Proof. move=> sGD /imsetP[x Sx {1}->]; rewrite card_orbit_in //. by rewrite indexgS // setIS // astabS // sub1set. Qed. Lemma atrans_dvd_in G S : G \subset D -> [transitive G, on S | to] -> #|S| %| #|G|. Proof. move=> sGD transG; apply: dvdn_trans (atrans_dvd_index_in sGD transG) _. exact: dvdn_indexg. Qed. Lemma atransPin G S : G \subset D -> [transitive G, on S | to] -> forall x, x \in S -> orbit to G x = S. Proof. by move=> sGD /imsetP[y _ ->] x; apply/orbit_in_eqP. Qed. Lemma atransP2in G S : G \subset D -> [transitive G, on S | to] -> {in S &, forall x y, exists2 a, a \in G & y = to x a}. Proof. by move=> sGD transG x y /(atransPin sGD transG) <- /imsetP. Qed. Lemma atrans_acts_in G S : G \subset D -> [transitive G, on S | to] -> [acts G, on S | to]. Proof. move=> sGD transG; apply/subsetP=> a Ga; rewrite !inE (subsetP sGD) //. by apply/subsetP=> x /(atransPin sGD transG) <-; rewrite inE imset_f. Qed. Lemma subgroup_transitivePin G H S x : x \in S -> H \subset G -> G \subset D -> [transitive G, on S | to] -> reflect ('C_G[x | to] * H = G) [transitive H, on S | to]. Proof. move=> Sx sHG sGD trG; have sHD := subset_trans sHG sGD. apply: (iffP idP) => [trH | defG]. rewrite group_modr //; apply/setIidPl/subsetP=> a Ga. have Sxa: to x a \in S by rewrite (acts_act (atrans_acts_in sGD trG)). have [b Hb xab]:= atransP2in sHD trH Sxa Sx. have Da := subsetP sGD a Ga; have Db := subsetP sHD b Hb. rewrite -(mulgK b a) mem_mulg ?groupV // !inE groupM //= sub1set inE. by rewrite actMin -?xab. apply/imsetP; exists x => //; apply/setP=> y; rewrite -(atransPin sGD trG Sx). apply/imsetP/imsetP=> [] [a]; last by exists a; first apply: (subsetP sHG). rewrite -defG => /imset2P[c b /setIP[_ cxc] Hb ->] ->. exists b; rewrite ?actMin ?(astab_dom cxc) ?(subsetP sHD) //. by rewrite (astab_act cxc) ?inE. Qed. End PartialAction. Arguments orbit_transversal {aT D%_g rT} to%_act A%_g S%_g. Arguments orbit_in_eqP {aT D rT to G x y}. Arguments orbit1P {aT D rT to G x}. Arguments contra_orbit [aT D rT] to G [x y]. Notation "''C' ( S | to )" := (astab_group to S) : Group_scope. Notation "''C_' A ( S | to )" := (setI_group A 'C(S | to)) : Group_scope. Notation "''C_' ( A ) ( S | to )" := (setI_group A 'C(S | to)) (only parsing) : Group_scope. Notation "''C' [ x | to ]" := (astab_group to [set x%g]) : Group_scope. Notation "''C_' A [ x | to ]" := (setI_group A 'C[x | to]) : Group_scope. Notation "''C_' ( A ) [ x | to ]" := (setI_group A 'C[x | to]) (only parsing) : Group_scope. Notation "''N' ( S | to )" := (astabs_group to S) : Group_scope. Notation "''N_' A ( S | to )" := (setI_group A 'N(S | to)) : Group_scope. Section TotalActions. (* These lemmas are only established for total actions (domain = [set: rT]) *) Variable (aT : finGroupType) (rT : finType). Variable to : {action aT &-> rT}. Implicit Types (a b : aT) (x y z : rT) (A B : {set aT}) (G H : {group aT}). Implicit Type S : {set rT}. Lemma actM x a b : to x (a * b) = to (to x a) b. Proof. by rewrite actMin ?inE. Qed. Lemma actK : right_loop invg to. Proof. by move=> a; apply: actKin; rewrite inE. Qed. Lemma actKV : rev_right_loop invg to. Proof. by move=> a; apply: actKVin; rewrite inE. Qed. Lemma actX x a n : to x (a ^+ n) = iter n (to^~ a) x. Proof. by elim: n => [|n /= <-]; rewrite ?act1 // -actM expgSr. Qed. Lemma actCJ a b x : to (to x a) b = to (to x b) (a ^ b). Proof. by rewrite !actM actK. Qed. Lemma actCJV a b x : to (to x a) b = to (to x (b ^ a^-1)) a. Proof. by rewrite (actCJ _ a) conjgKV. Qed. Lemma orbit_sym G x y : (x \in orbit to G y) = (y \in orbit to G x). Proof. exact/orbit_in_sym/subsetT. Qed. Lemma orbit_trans G x y z : x \in orbit to G y -> y \in orbit to G z -> x \in orbit to G z. Proof. exact/orbit_in_trans/subsetT. Qed. Lemma orbit_eqP G x y : reflect (orbit to G x = orbit to G y) (x \in orbit to G y). Proof. exact/orbit_in_eqP/subsetT. Qed. Lemma orbit_transl G x y z : y \in orbit to G x -> (y \in orbit to G z) = (x \in orbit to G z). Proof. exact/orbit_in_transl/subsetT. Qed. Lemma orbit_act G a x: a \in G -> orbit to G (to x a) = orbit to G x. Proof. exact/orbit_act_in/subsetT. Qed. Lemma orbit_actr G a x y : a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x). Proof. by move/mem_orbit/orbit_transl; apply. Qed. Lemma orbit_eq_mem G x y : (orbit to G x == orbit to G y) = (x \in orbit to G y). Proof. exact: sameP eqP (orbit_eqP G x y). Qed. Lemma orbit_inv A x y : (y \in orbit to A^-1 x) = (x \in orbit to A y). Proof. by rewrite orbit_inv_in ?subsetT. Qed. Lemma orbit_lcoset A a x : orbit to (a *: A) x = orbit to A (to x a). Proof. by rewrite orbit_lcoset_in ?subsetT ?inE. Qed. Lemma orbit_rcoset A a x y : (to y a \in orbit to (A :* a) x) = (y \in orbit to A x). Proof. by rewrite orbit_rcoset_in ?subsetT ?inE. Qed. Lemma orbit_conjsg A a x y : (to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x). Proof. by rewrite orbit_conjsg_in ?subsetT ?inE. Qed. Lemma astabP S a : reflect (forall x, x \in S -> to x a = x) (a \in 'C(S | to)). Proof. apply: (iffP idP) => [cSa x|cSa]; first exact: astab_act. by rewrite !inE; apply/subsetP=> x Sx; rewrite inE cSa. Qed. Lemma astab1P x a : reflect (to x a = x) (a \in 'C[x | to]). Proof. by rewrite !inE sub1set inE; apply: eqP. Qed. Lemma sub_astab1 A x : (A \subset 'C[x | to]) = (x \in 'Fix_to(A)). Proof. by rewrite sub_astab1_in ?subsetT. Qed. Lemma astabC A S : (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)). Proof. by rewrite astabCin ?subsetT. Qed. Lemma afix_cycle a : 'Fix_to(<[a]>) = 'Fix_to[a]. Proof. by rewrite afix_cycle_in ?inE. Qed. Lemma afix_gen A : 'Fix_to(<<A>>) = 'Fix_to(A). Proof. by rewrite afix_gen_in ?subsetT. Qed. Lemma afixM G H : 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H). Proof. by rewrite afixMin ?subsetT. Qed. Lemma astabsP S a : reflect (forall x, (to x a \in S) = (x \in S)) (a \in 'N(S | to)). Proof. apply: (iffP idP) => [nSa x|nSa]; first exact: astabs_act. by rewrite !inE; apply/subsetP=> x; rewrite inE nSa. Qed. Lemma card_orbit G x : #|orbit to G x| = #|G : 'C_G[x | to]|. Proof. by rewrite card_orbit_in ?subsetT. Qed. Lemma dvdn_orbit G x : #|orbit to G x| %| #|G|. Proof. by rewrite card_orbit dvdn_indexg. Qed. Lemma card_orbit_stab G x : (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|. Proof. by rewrite mulnC card_orbit Lagrange ?subsetIl. Qed. Lemma actsP A S : reflect {acts A, on S | to} [acts A, on S | to]. Proof. apply: (iffP idP) => [nSA x|nSA]; first exact: acts_act. by apply/subsetP=> a Aa /[!inE]; apply/subsetP=> x; rewrite inE nSA. Qed. Arguments actsP {A S}. Lemma setact_orbit A x b : to^* (orbit to A x) b = orbit to (A :^ b) (to x b). Proof. apply/setP=> y; apply/idP/idP=> /imsetP[_ /imsetP[a Aa ->] ->{y}]. by rewrite actCJ mem_orbit ?memJ_conjg. by rewrite -actCJ mem_setact ?mem_orbit. Qed. Lemma astab_setact S a : 'C(to^* S a | to) = 'C(S | to) :^ a. Proof. apply/setP=> b; rewrite mem_conjg. apply/astabP/astabP=> stab x => [Sx|]. by rewrite conjgE invgK !actM stab ?actK //; apply/imsetP; exists x. by case/imsetP=> y Sy ->{x}; rewrite -actM conjgCV actM stab. Qed. Lemma astab1_act x a : 'C[to x a | to] = 'C[x | to] :^ a. Proof. by rewrite -astab_setact /setact imset_set1. Qed. Lemma atransP G S : [transitive G, on S | to] -> forall x, x \in S -> orbit to G x = S. Proof. by case/imsetP=> x _ -> y; apply/orbit_eqP. Qed. Lemma atransP2 G S : [transitive G, on S | to] -> {in S &, forall x y, exists2 a, a \in G & y = to x a}. Proof. by move=> GtrS x y /(atransP GtrS) <- /imsetP. Qed. Lemma atrans_acts G S : [transitive G, on S | to] -> [acts G, on S | to]. Proof. move=> GtrS; apply/subsetP=> a Ga; rewrite !inE. by apply/subsetP=> x /(atransP GtrS) <-; rewrite inE imset_f. Qed. Lemma atrans_supgroup G H S : G \subset H -> [transitive G, on S | to] -> [transitive H, on S | to] = [acts H, on S | to]. Proof. move=> sGH trG; apply/idP/idP=> [|actH]; first exact: atrans_acts. case/imsetP: trG => x Sx defS; apply/imsetP; exists x => //. by apply/eqP; rewrite eqEsubset acts_sub_orbit ?Sx // defS imsetS. Qed. Lemma atrans_acts_card G S : [transitive G, on S | to] = [acts G, on S | to] && (#|orbit to G @: S| == 1%N). Proof. apply/idP/andP=> [GtrS | [nSG]]. split; first exact: atrans_acts. rewrite ((_ @: S =P [set S]) _) ?cards1 // eqEsubset sub1set. apply/andP; split=> //; apply/subsetP=> _ /imsetP[x Sx ->]. by rewrite inE (atransP GtrS). rewrite eqn_leq andbC lt0n => /andP[/existsP[X /imsetP[x Sx X_Gx]]]. rewrite (cardD1 X) {X}X_Gx imset_f // ltnS leqn0 => /eqP GtrS. apply/imsetP; exists x => //; apply/eqP. rewrite eqEsubset acts_sub_orbit // Sx andbT. apply/subsetP=> y Sy; have:= card0_eq GtrS (orbit to G y). by rewrite !inE /= imset_f // andbT => /eqP <-; apply: orbit_refl. Qed. Lemma atrans_dvd G S : [transitive G, on S | to] -> #|S| %| #|G|. Proof. by case/imsetP=> x _ ->; apply: dvdn_orbit. Qed. (* This is Aschbacher (5.2) *) Lemma acts_fix_norm A B : A \subset 'N(B) -> [acts A, on 'Fix_to(B) | to]. Proof. move=> nAB; have:= acts_subnorm_fix to B; rewrite !setTI. exact: subset_trans. Qed. Lemma faithfulP A S : reflect (forall a, a \in A -> {in S, to^~ a =1 id} -> a = 1) [faithful A, on S | to]. Proof. apply: (iffP subsetP) => [Cto1 a Aa Ca | Cto1 a]. by apply/set1P; rewrite Cto1 // inE Aa; apply/astabP. by case/setIP=> Aa /astabP Ca; apply/set1P; apply: Cto1. Qed. (* This is the first part of Aschbacher (5.7) *) Lemma astab_trans_gcore G S u : [transitive G, on S | to] -> u \in S -> 'C(S | to) = gcore 'C[u | to] G. Proof. move=> transG Su; apply/eqP; rewrite eqEsubset. rewrite gcore_max ?astabS ?sub1set //=; last first. exact: subset_trans (atrans_acts transG) (astab_norm _ _). apply/subsetP=> x cSx; apply/astabP=> uy. case/(atransP2 transG Su) => y Gy ->{uy}. by apply/astab1P; rewrite astab1_act (bigcapP cSx). Qed. (* This is Aschbacher (5.20) *) Theorem subgroup_transitiveP G H S x : x \in S -> H \subset G -> [transitive G, on S | to] -> reflect ('C_G[x | to] * H = G) [transitive H, on S | to]. Proof. by move=> Sx sHG; apply: subgroup_transitivePin (subsetT G). Qed. (* This is Aschbacher (5.21) *) Lemma trans_subnorm_fixP x G H S : let C := 'C_G[x | to] in let T := 'Fix_(S | to)(H) in [transitive G, on S | to] -> x \in S -> H \subset C -> reflect ((H :^: G) ::&: C = H :^: C) [transitive 'N_G(H), on T | to]. Proof. move=> C T trGS Sx sHC; have actGS := acts_act (atrans_acts trGS). have:= sHC; rewrite subsetI sub_astab1 => /andP[sHG cHx]. have Tx: x \in T by rewrite inE Sx. apply: (iffP idP) => [trN | trC]. apply/setP=> Ha; apply/setIdP/imsetP=> [[]|[a Ca ->{Ha}]]; last first. by rewrite conj_subG //; case/setIP: Ca => Ga _; rewrite imset_f. case/imsetP=> a Ga ->{Ha}; rewrite subsetI !sub_conjg => /andP[_ sHCa]. have Txa: to x a^-1 \in T. by rewrite inE -sub_astab1 astab1_act actGS ?Sx ?groupV. have [b] := atransP2 trN Tx Txa; case/setIP=> Gb nHb cxba. exists (b * a); last by rewrite conjsgM (normP nHb). by rewrite inE groupM //; apply/astab1P; rewrite actM -cxba actKV. apply/imsetP; exists x => //; apply/setP=> y; apply/idP/idP=> [Ty|]. have [Sy cHy]:= setIP Ty; have [a Ga defy] := atransP2 trGS Sx Sy. have: H :^ a^-1 \in H :^: C. rewrite -trC inE subsetI imset_f 1?conj_subG ?groupV // sub_conjgV. by rewrite -astab1_act -defy sub_astab1. case/imsetP=> b /setIP[Gb /astab1P cxb] defHb. rewrite defy -{1}cxb -actM mem_orbit // inE groupM //. by apply/normP; rewrite conjsgM -defHb conjsgKV. case/imsetP=> a /setIP[Ga nHa] ->{y}. by rewrite inE actGS // Sx (acts_act (acts_fix_norm _) nHa). Qed. End TotalActions. Arguments astabP {aT rT to S a}. Arguments orbit_eqP {aT rT to G x y}. Arguments astab1P {aT rT to x a}. Arguments astabsP {aT rT to S a}. Arguments atransP {aT rT to G S}. Arguments actsP {aT rT to A S}. Arguments faithfulP {aT rT to A S}. Section Restrict. Variables (aT : finGroupType) (D : {set aT}) (rT : Type). Variables (to : action D rT) (A : {set aT}). Definition ract of A \subset D := act to. Variable sAD : A \subset D. Lemma ract_is_action : is_action A (ract sAD). Proof. rewrite /ract; case: to => f [injf fM]. by split=> // x; apply: (sub_in2 (subsetP sAD)). Qed. Canonical raction := Action ract_is_action. Lemma ractE : raction =1 to. Proof. by []. Qed. (* Other properties of raction need rT : finType; we defer them *) (* until after the definition of actperm. *) End Restrict. Notation "to \ sAD" := (raction to sAD) (at level 50) : action_scope. Section ActBy. Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Definition actby_cond (A : {set aT}) R (to : action D rT) : Prop := [acts A, on R | to]. Definition actby A R to of actby_cond A R to := fun x a => if (x \in R) && (a \in A) then to x a else x. Variables (A : {group aT}) (R : {set rT}) (to : action D rT). Hypothesis nRA : actby_cond A R to. Lemma actby_is_action : is_action A (actby nRA). Proof. rewrite /actby; split=> [a x y | x a b Aa Ab /=]; last first. rewrite Aa Ab groupM // !andbT actMin ?(subsetP (acts_dom nRA)) //. by case Rx: (x \in R); rewrite ?(acts_act nRA) ?Rx. case Aa: (a \in A); rewrite ?andbF ?andbT //. case Rx: (x \in R); case Ry: (y \in R) => // eqxy; first exact: act_inj eqxy. by rewrite -eqxy (acts_act nRA Aa) Rx in Ry. by rewrite eqxy (acts_act nRA Aa) Ry in Rx. Qed. Canonical action_by := Action actby_is_action. Local Notation "<[nRA]>" := action_by : action_scope. Lemma actbyE x a : x \in R -> a \in A -> <[nRA]>%act x a = to x a. Proof. by rewrite /= /actby => -> ->. Qed. Lemma afix_actby B : 'Fix_<[nRA]>(B) = ~: R :|: 'Fix_to(A :&: B). Proof. apply/setP=> x; rewrite !inE /= /actby. case: (x \in R); last by apply/subsetP=> a _ /[!inE]. apply/subsetP/subsetP=> [cBx a | cABx a Ba] /[!inE]. by case/andP=> Aa /cBx; rewrite inE Aa. by case: ifP => //= Aa; have:= cABx a; rewrite !inE Aa => ->. Qed. Lemma astab_actby S : 'C(S | <[nRA]>) = 'C_A(R :&: S | to). Proof. apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE. case Aa: (a \in A) => //=; apply/subsetP/subsetP=> cRSa x => [|Sx]. by case/setIP=> Rx /cRSa; rewrite !inE actbyE. by have:= cRSa x; rewrite !inE /= /actby Aa Sx; case: (x \in R) => //; apply. Qed. Lemma astabs_actby S : 'N(S | <[nRA]>) = 'N_A(R :&: S | to). Proof. apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE. case Aa: (a \in A) => //=; apply/subsetP/subsetP=> nRSa x => [|Sx]. by case/setIP=> Rx /nRSa; rewrite !inE actbyE ?(acts_act nRA) ?Rx. have:= nRSa x; rewrite !inE /= /actby Aa Sx ?(acts_act nRA) //. by case: (x \in R) => //; apply. Qed. Lemma acts_actby (B : {set aT}) S : [acts B, on S | <[nRA]>] = (B \subset A) && [acts B, on R :&: S | to]. Proof. by rewrite astabs_actby subsetI. Qed. End ActBy. Notation "<[ nRA ] >" := (action_by nRA) : action_scope. Section SubAction. Variables (aT : finGroupType) (D : {group aT}). Variables (rT : finType) (sP : pred rT) (sT : subFinType sP) (to : action D rT). Implicit Type A : {set aT}. Implicit Type u : sT. Implicit Type S : {set sT}. Definition subact_dom := 'N([set x | sP x] | to). Canonical subact_dom_group := [group of subact_dom]. Implicit Type Na : {a | a \in subact_dom}. Lemma sub_act_proof u Na : sP (to (val u) (val Na)). Proof. by case: Na => a /= /(astabs_act (val u)); rewrite !inE valP. Qed. Definition subact u a := if insub a is Some Na then Sub _ (sub_act_proof u Na) else u. Lemma val_subact u a : val (subact u a) = if a \in subact_dom then to (val u) a else val u. Proof. by rewrite /subact -if_neg; case: insubP => [Na|] -> //=; rewrite SubK => ->. Qed. Lemma subact_is_action : is_action subact_dom subact. Proof. split=> [a u v eq_uv | u a b Na Nb]; apply: val_inj. move/(congr1 val): eq_uv; rewrite !val_subact. by case: (a \in _); first move/act_inj. have Da := astabs_dom Na; have Db := astabs_dom Nb. by rewrite !val_subact Na Nb groupM ?actMin. Qed. Canonical subaction := Action subact_is_action. Lemma astab_subact S : 'C(S | subaction) = subact_dom :&: 'C(val @: S | to). Proof. apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa. have [Da _] := setIP sDa; rewrite !inE Da. apply/subsetP/subsetP=> [cSa _ /imsetP[x Sx ->] | cSa x Sx] /[!inE]. by have:= cSa x Sx; rewrite inE -val_eqE val_subact sDa. by have:= cSa _ (imset_f val Sx); rewrite inE -val_eqE val_subact sDa. Qed. Lemma astabs_subact S : 'N(S | subaction) = subact_dom :&: 'N(val @: S | to). Proof. apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa. have [Da _] := setIP sDa; rewrite !inE Da. apply/subsetP/subsetP=> [nSa _ /imsetP[x Sx ->] | nSa x Sx] /[!inE]. by have /[1!inE]/(imset_f val) := nSa x Sx; rewrite val_subact sDa. have /[1!inE]/imsetP[y Sy def_y] := nSa _ (imset_f val Sx). by rewrite ((_ a =P y) _) // -val_eqE val_subact sDa def_y. Qed. Lemma afix_subact A : A \subset subact_dom -> 'Fix_subaction(A) = val @^-1: 'Fix_to(A). Proof. move/subsetP=> sAD; apply/setP=> u. rewrite !inE !(sameP setIidPl eqP); congr (_ == A). apply/setP=> a /[!inE]; apply: andb_id2l => Aa. by rewrite -val_eqE val_subact sAD. Qed. End SubAction. Notation "to ^?" := (subaction _ to) (format "to ^?") : action_scope. Section QuotientAction. Variables (aT : finGroupType) (D : {group aT}) (rT : finGroupType). Variables (to : action D rT) (H : {group rT}). Definition qact_dom := 'N(rcosets H 'N(H) | to^*). Canonical qact_dom_group := [group of qact_dom]. Local Notation subdom := (subact_dom (coset_range H) to^*). Fact qact_subdomE : subdom = qact_dom. Proof. by congr 'N(_|_); apply/setP=> Hx; rewrite !inE genGid. Qed. Lemma qact_proof : qact_dom \subset subdom. Proof. by rewrite qact_subdomE. Qed. Definition qact : coset_of H -> aT -> coset_of H := act (to^*^? \ qact_proof). Canonical quotient_action := [action of qact]. Lemma acts_qact_dom : [acts qact_dom, on 'N(H) | to]. Proof. apply/subsetP=> a nNa; rewrite !inE (astabs_dom nNa); apply/subsetP=> x Nx. have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f. rewrite inE -(astabs_act _ nNa) => /rcosetsP[y Ny defHy]. have: to x a \in H :* y by rewrite -defHy (imset_f (to^~a)) ?rcoset_refl. by apply: subsetP; rewrite mul_subG ?sub1set ?normG. Qed. Lemma qactEcond x a : x \in 'N(H) -> quotient_action (coset H x) a = coset H (if a \in qact_dom then to x a else x). Proof. move=> Nx; apply: val_inj; rewrite val_subact //= qact_subdomE. have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f. case nNa: (a \in _); rewrite // -(astabs_act _ nNa). rewrite !val_coset ?(acts_act acts_qact_dom nNa) //=. case/rcosetsP=> y Ny defHy; rewrite defHy; apply: rcoset_eqP. by rewrite rcoset_sym -defHy (imset_f (_^~_)) ?rcoset_refl. Qed. Lemma qactE x a : x \in 'N(H) -> a \in qact_dom -> quotient_action (coset H x) a = coset H (to x a). Proof. by move=> Nx nNa; rewrite qactEcond ?nNa. Qed. Lemma acts_quotient (A : {set aT}) (B : {set rT}) : A \subset 'N_qact_dom(B | to) -> [acts A, on B / H | quotient_action]. Proof. move=> nBA; apply: subset_trans {A}nBA _; apply/subsetP=> a /setIP[dHa nBa]. rewrite inE dHa inE; apply/subsetP=> _ /morphimP[x nHx Bx ->]. rewrite inE /= qactE //. by rewrite mem_morphim ?(acts_act acts_qact_dom) ?(astabs_act _ nBa). Qed. Lemma astabs_quotient (G : {group rT}) : H <| G -> 'N(G / H | quotient_action) = 'N_qact_dom(G | to). Proof. move=> nsHG; have [_ nHG] := andP nsHG. apply/eqP; rewrite eqEsubset acts_quotient // andbT. apply/subsetP=> a nGa; have dHa := astabs_dom nGa; have [Da _]:= setIdP dHa. rewrite inE dHa 2!inE Da; apply/subsetP=> x Gx; have nHx := subsetP nHG x Gx. rewrite -(quotientGK nsHG) 2!inE (acts_act acts_qact_dom) ?nHx //= inE. by rewrite -qactE // (astabs_act _ nGa) mem_morphim. Qed. End QuotientAction. Notation "to / H" := (quotient_action to H) : action_scope. Section ModAction. Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Implicit Types (G : {group aT}) (S : {set rT}). Section GenericMod. Variable H : {group aT}. Local Notation dom := 'N_D(H). Local Notation range := 'Fix_to(D :&: H). Let acts_dom : {acts dom, on range | to} := acts_act (acts_subnorm_fix to H). Definition modact x (Ha : coset_of H) := if x \in range then to x (repr (D :&: Ha)) else x. Lemma modactEcond x a : a \in dom -> modact x (coset H a) = (if x \in range then to x a else x). Proof. case/setIP=> Da Na; case: ifP => Cx; rewrite /modact Cx //. rewrite val_coset // -group_modr ?sub1set //. case: (repr _) / (repr_rcosetP (D :&: H) a) => a' Ha'. by rewrite actMin ?(afixP Cx _ Ha') //; case/setIP: Ha'. Qed. Lemma modactE x a : a \in D -> a \in 'N(H) -> x \in range -> modact x (coset H a) = to x a. Proof. by move=> Da Na Rx; rewrite modactEcond ?Rx // inE Da. Qed. Lemma modact_is_action : is_action (D / H) modact. Proof. split=> [Ha x y | x Ha Hb]; last first. case/morphimP=> a Na Da ->{Ha}; case/morphimP=> b Nb Db ->{Hb}. rewrite -morphM //= !modactEcond // ?groupM ?(introT setIP _) //. by case: ifP => Cx; rewrite ?(acts_dom, Cx, actMin, introT setIP _). case: (set_0Vmem (D :&: Ha)) => [Da0 | [a /setIP[Da NHa]]]. by rewrite /modact Da0 repr_set0 !act1 !if_same. have Na := subsetP (coset_norm _) _ NHa. have NDa: a \in 'N_D(H) by rewrite inE Da. rewrite -(coset_mem NHa) !modactEcond //. do 2![case: ifP]=> Cy Cx // eqxy; first exact: act_inj eqxy. by rewrite -eqxy acts_dom ?Cx in Cy. by rewrite eqxy acts_dom ?Cy in Cx. Qed. Canonical mod_action := Action modact_is_action. Section Stabilizers. Variable S : {set rT}. Hypothesis cSH : H \subset 'C(S | to). Let fixSH : S \subset 'Fix_to(D :&: H). Proof. by rewrite -astabCin ?subsetIl // subIset ?cSH ?orbT. Qed. Lemma astabs_mod : 'N(S | mod_action) = 'N(S | to) / H. Proof. apply/setP=> Ha; apply/idP/morphimP=> [nSa | [a nHa nSa ->]]. case/morphimP: (astabs_dom nSa) => a nHa Da defHa. exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE. by have:= Sx; rewrite -(astabs_act x nSa) defHa /= modactE ?(subsetP fixSH). have Da := astabs_dom nSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx. by rewrite !inE /= modactE ?(astabs_act x nSa) ?(subsetP fixSH). Qed. Lemma astab_mod : 'C(S | mod_action) = 'C(S | to) / H. Proof. apply/setP=> Ha; apply/idP/morphimP=> [cSa | [a nHa cSa ->]]. case/morphimP: (astab_dom cSa) => a nHa Da defHa. exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE. by rewrite -{2}[x](astab_act cSa) // defHa /= modactE ?(subsetP fixSH). have Da := astab_dom cSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx. by rewrite !inE /= modactE ?(astab_act cSa) ?(subsetP fixSH). Qed. End Stabilizers. Lemma afix_mod G S : H \subset 'C(S | to) -> G \subset 'N_D(H) -> 'Fix_(S | mod_action)(G / H) = 'Fix_(S | to)(G). Proof. move=> cSH /subsetIP[sGD nHG]. apply/eqP; rewrite eqEsubset !subsetI !subsetIl /= -!astabCin ?quotientS //. have cfixH F: H \subset 'C(S :&: F | to). by rewrite (subset_trans cSH) // astabS ?subsetIl. rewrite andbC astab_mod ?quotientS //=; last by rewrite astabCin ?subsetIr. by rewrite -(quotientSGK nHG) //= -astab_mod // astabCin ?quotientS ?subsetIr. Qed. End GenericMod. Lemma modact_faithful G S : [faithful G / 'C_G(S | to), on S | mod_action 'C_G(S | to)]. Proof. rewrite /faithful astab_mod ?subsetIr //=. by rewrite -quotientIG ?subsetIr ?trivg_quotient. Qed. End ModAction. Notation "to %% H" := (mod_action to H) : action_scope. Section ActPerm. (* Morphism to permutations induced by an action. *) Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Variable to : action D rT. Definition actperm a := perm (act_inj to a). Lemma actpermM : {in D &, {morph actperm : a b / a * b}}. Proof. by move=> a b Da Db; apply/permP=> x; rewrite permM !permE actMin. Qed. Canonical actperm_morphism := Morphism actpermM. Lemma actpermE a x : actperm a x = to x a. Proof. by rewrite permE. Qed. Lemma actpermK x a : aperm x (actperm a) = to x a. Proof. exact: actpermE. Qed. Lemma ker_actperm : 'ker actperm = 'C(setT | to). Proof. congr (_ :&: _); apply/setP=> a /[!inE]/=. apply/eqP/subsetP=> [a1 x _ | a1]; first by rewrite inE -actpermE a1 perm1. by apply/permP=> x; apply/eqP; have:= a1 x; rewrite !inE actpermE perm1 => ->. Qed. End ActPerm. Section RestrictActionTheory. Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Variables (to : action D rT). Lemma faithful_isom (A : {group aT}) S (nSA : actby_cond A S to) : [faithful A, on S | to] -> isom A (actperm <[nSA]> @* A) (actperm <[nSA]>). Proof. by move=> ffulAS; apply/isomP; rewrite ker_actperm astab_actby setIT. Qed. Variables (A : {set aT}) (sAD : A \subset D). Lemma ractpermE : actperm (to \ sAD) =1 actperm to. Proof. by move=> a; apply/permP=> x; rewrite !permE. Qed. Lemma afix_ract B : 'Fix_(to \ sAD)(B) = 'Fix_to(B). Proof. by []. Qed. Lemma astab_ract S : 'C(S | to \ sAD) = 'C_A(S | to). Proof. by rewrite setIA (setIidPl sAD). Qed. Lemma astabs_ract S : 'N(S | to \ sAD) = 'N_A(S | to). Proof. by rewrite setIA (setIidPl sAD). Qed. Lemma acts_ract (B : {set aT}) S : [acts B, on S | to \ sAD] = (B \subset A) && [acts B, on S | to]. Proof. by rewrite astabs_ract subsetI. Qed. End RestrictActionTheory. Section MorphAct. (* Action induced by a morphism to permutations. *) Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable phi : {morphism D >-> {perm rT}}. Definition mact x a := phi a x. Lemma mact_is_action : is_action D mact. Proof. split=> [a x y | x a b Da Db]; first exact: perm_inj. by rewrite /mact morphM //= permM. Qed. Canonical morph_action := Action mact_is_action. Lemma mactE x a : morph_action x a = phi a x. Proof. by []. Qed. Lemma injm_faithful : 'injm phi -> [faithful D, on setT | morph_action]. Proof. move/injmP=> phi_inj; apply/subsetP=> a /setIP[Da /astab_act a1]. apply/set1P/phi_inj => //; apply/permP=> x. by rewrite morph1 perm1 -mactE a1 ?inE. Qed. Lemma perm_mact a : actperm morph_action a = phi a. Proof. by apply/permP=> x; rewrite permE. Qed. End MorphAct. Notation "<< phi >>" := (morph_action phi) : action_scope. Section CompAct. Variables (gT aT : finGroupType) (rT : finType). Variables (D : {set aT}) (to : action D rT). Variables (B : {set gT}) (f : {morphism B >-> aT}). Definition comp_act x e := to x (f e). Lemma comp_is_action : is_action (f @*^-1 D) comp_act. Proof. split=> [e | x e1 e2]; first exact: act_inj. move=> /morphpreP[Be1 Dfe1] /morphpreP[Be2 Dfe2]. by rewrite /comp_act morphM ?actMin. Qed. Canonical comp_action := Action comp_is_action. Lemma comp_actE x e : comp_action x e = to x (f e). Proof. by []. Qed. Lemma afix_comp (A : {set gT}) : A \subset B -> 'Fix_comp_action(A) = 'Fix_to(f @* A). Proof. move=> sAB; apply/setP=> x; rewrite !inE /morphim (setIidPr sAB). apply/subsetP/subsetP; first by move=> + _ /imsetP[a + ->] => /[apply]/[!inE]. by move=> + a Aa => /(_ (f a)); rewrite !inE imset_f// => ->. Qed. Lemma astab_comp S : 'C(S | comp_action) = f @*^-1 'C(S | to). Proof. by apply/setP=> x; rewrite !inE -andbA. Qed. Lemma astabs_comp S : 'N(S | comp_action) = f @*^-1 'N(S | to). Proof. by apply/setP=> x; rewrite !inE -andbA. Qed. End CompAct. Notation "to \o f" := (comp_action to f) : action_scope. Section PermAction. (* Natural action of permutation groups. *) Variable rT : finType. Local Notation gT := {perm rT}. Implicit Types a b c : gT. Lemma aperm_is_action : is_action setT (@aperm rT). Proof. by apply: is_total_action => [x|x a b]; rewrite apermE (perm1, permM). Qed. Canonical perm_action := Action aperm_is_action. Lemma porbitE a : porbit a = orbit perm_action <[a]>%g. Proof. by rewrite unlock. Qed. Lemma perm_act1P a : reflect (forall x, aperm x a = x) (a == 1). Proof. apply: (iffP eqP) => [-> x | a1]; first exact: act1. by apply/permP=> x; rewrite -apermE a1 perm1. Qed. Lemma perm_faithful A : [faithful A, on setT | perm_action]. Proof. apply/subsetP=> a /setIP[Da crTa]. by apply/set1P; apply/permP=> x; rewrite -apermE perm1 (astabP crTa) ?inE. Qed. Lemma actperm_id p : actperm perm_action p = p. Proof. by apply/permP=> x; rewrite permE. Qed. End PermAction. Arguments perm_act1P {rT a}. Notation "'P" := (perm_action _) : action_scope. Section ActpermOrbits. Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Lemma orbit_morphim_actperm (A : {set aT}) : A \subset D -> orbit 'P (actperm to @* A) =1 orbit to A. Proof. move=> sAD x; rewrite morphimEsub // /orbit -imset_comp. by apply: eq_imset => a //=; rewrite actpermK. Qed. Lemma porbit_actperm (a : aT) : a \in D -> porbit (actperm to a) =1 orbit to <[a]>. Proof. move=> Da x. by rewrite porbitE -orbit_morphim_actperm ?cycle_subG ?morphim_cycle. Qed. End ActpermOrbits. Section RestrictPerm. Variables (T : finType) (S : {set T}). Definition restr_perm := actperm (<[subxx 'N(S | 'P)]>). Canonical restr_perm_morphism := [morphism of restr_perm]. Lemma restr_perm_on p : perm_on S (restr_perm p). Proof. apply/subsetP=> x; apply: contraR => notSx. by rewrite permE /= /actby (negPf notSx). Qed. Lemma triv_restr_perm p : p \notin 'N(S | 'P) -> restr_perm p = 1. Proof. move=> not_nSp; apply/permP=> x. by rewrite !permE /= /actby (negPf not_nSp) andbF. Qed. Lemma restr_permE : {in 'N(S | 'P) & S, forall p, restr_perm p =1 p}. Proof. by move=> y x nSp Sx; rewrite /= actpermE actbyE. Qed. Lemma ker_restr_perm : 'ker restr_perm = 'C(S | 'P). Proof. by rewrite ker_actperm astab_actby setIT (setIidPr (astab_sub _ _)). Qed. Lemma im_restr_perm p : restr_perm p @: S = S. Proof. exact: im_perm_on (restr_perm_on p). Qed. Lemma restr_perm_commute s : commute (restr_perm s) s. Proof. have [sC|/triv_restr_perm->] := boolP (s \in 'N(S | 'P)); last first. exact: (commute_sym (commute1 _)). apply/permP => x; have /= xsS := astabsP sC x; rewrite !permM. have [xS|xNS] := boolP (x \in S); first by rewrite ?(restr_permE) ?xsS. by rewrite !(out_perm (restr_perm_on _)) ?xsS. Qed. End RestrictPerm. Section Symmetry. Variables (T : finType) (S : {set T}). Lemma SymE : Sym S = 'C(~: S | 'P). Proof. apply/setP => s; rewrite inE; apply/idP/astabP => [sS x|/= S_id]. by rewrite inE /= apermE => /out_perm->. by apply/subsetP => x; move=> /(contra_neqN (S_id _)); rewrite inE negbK. Qed. End Symmetry. Section AutIn. Variable gT : finGroupType. Definition Aut_in A (B : {set gT}) := 'N_A(B | 'P) / 'C_A(B | 'P). Variables G H : {group gT}. Hypothesis sHG: H \subset G. Lemma Aut_restr_perm a : a \in Aut G -> restr_perm H a \in Aut H. Proof. move=> AutGa. case nHa: (a \in 'N(H | 'P)); last by rewrite triv_restr_perm ?nHa ?group1. rewrite inE restr_perm_on; apply/morphicP=> x y Hx Hy /=. by rewrite !restr_permE ?groupM // -(autmE AutGa) morphM ?(subsetP sHG). Qed. Lemma restr_perm_Aut : restr_perm H @* Aut G \subset Aut H. Proof. by apply/subsetP=> a'; case/morphimP=> a _ AutGa ->{a'}; apply: Aut_restr_perm. Qed. Lemma Aut_in_isog : Aut_in (Aut G) H \isog restr_perm H @* Aut G. Proof. rewrite /Aut_in -ker_restr_perm kerE -morphpreIdom -morphimIdom -kerE /=. by rewrite setIA (setIC _ (Aut G)) first_isog_loc ?subsetIr. Qed. Lemma Aut_sub_fullP : reflect (forall h : {morphism H >-> gT}, 'injm h -> h @* H = H -> exists g : {morphism G >-> gT}, [/\ 'injm g, g @* G = G & {in H, g =1 h}]) (Aut_in (Aut G) H \isog Aut H). Proof. rewrite (isog_transl _ Aut_in_isog) /=; set rG := _ @* _. apply: (iffP idP) => [iso_rG h injh hH| AutHinG]. have: aut injh hH \in rG; last case/morphimP=> g nHg AutGg def_g. suffices ->: rG = Aut H by apply: Aut_aut. by apply/eqP; rewrite eqEcard restr_perm_Aut /= (card_isog iso_rG). exists (autm_morphism AutGg); rewrite injm_autm im_autm; split=> // x Hx. by rewrite -(autE injh hH Hx) def_g actpermE actbyE. suffices ->: rG = Aut H by apply: isog_refl. apply/eqP; rewrite eqEsubset restr_perm_Aut /=. apply/subsetP=> h AutHh; have hH := im_autm AutHh. have [g [injg gG eq_gh]] := AutHinG _ (injm_autm AutHh) hH. have [Ng AutGg]: aut injg gG \in 'N(H | 'P) /\ aut injg gG \in Aut G. rewrite Aut_aut !inE; split=> //; apply/subsetP=> x Hx. by rewrite inE /= /aperm autE ?(subsetP sHG) // -hH eq_gh ?mem_morphim. apply/morphimP; exists (aut injg gG) => //; apply: (eq_Aut AutHh) => [|x Hx]. by rewrite (subsetP restr_perm_Aut) // mem_morphim. by rewrite restr_permE //= /aperm autE ?eq_gh ?(subsetP sHG). Qed. End AutIn. Arguments Aut_in {gT} A%_g B%_g. Section InjmAutIn. Variables (gT rT : finGroupType) (D G H : {group gT}) (f : {morphism D >-> rT}). Hypotheses (injf : 'injm f) (sGD : G \subset D) (sHG : H \subset G). Let sHD := subset_trans sHG sGD. Local Notation fGisom := (Aut_isom injf sGD). Local Notation fHisom := (Aut_isom injf sHD). Local Notation inH := (restr_perm H). Local Notation infH := (restr_perm (f @* H)). Lemma astabs_Aut_isom a : a \in Aut G -> (fGisom a \in 'N(f @* H | 'P)) = (a \in 'N(H | 'P)). Proof. move=> AutGa; rewrite !inE sub_morphim_pre // subsetI sHD /= /aperm. rewrite !(sameP setIidPl eqP) !eqEsubset !subsetIl; apply: eq_subset_r => x. rewrite !inE; apply: andb_id2l => Hx; have Gx: x \in G := subsetP sHG x Hx. have Dax: a x \in D by rewrite (subsetP sGD) // Aut_closed. by rewrite Aut_isomE // -!sub1set -morphim_set1 // injmSK ?sub1set. Qed. Lemma isom_restr_perm a : a \in Aut G -> fHisom (inH a) = infH (fGisom a). Proof. move=> AutGa; case nHa: (a \in 'N(H | 'P)); last first. by rewrite !triv_restr_perm ?astabs_Aut_isom ?nHa ?morph1. apply: (eq_Aut (Aut_Aut_isom injf sHD _)) => [|fx Hfx /=]. by rewrite (Aut_restr_perm (morphimS f sHG)) ?Aut_Aut_isom. have [x Dx Hx def_fx] := morphimP Hfx; have Gx := subsetP sHG x Hx. rewrite {1}def_fx Aut_isomE ?(Aut_restr_perm sHG) //. by rewrite !restr_permE ?astabs_Aut_isom // def_fx Aut_isomE. Qed. Lemma restr_perm_isom : isom (inH @* Aut G) (infH @* Aut (f @* G)) fHisom. Proof. apply: sub_isom; rewrite ?restr_perm_Aut ?injm_Aut_isom //=. rewrite -(im_Aut_isom injf sGD) -!morphim_comp. apply: eq_in_morphim; last exact: isom_restr_perm. (* TODO: investigate why rewrite does not match in the same order *) apply/setP=> a; rewrite in_setI [in RHS]in_setI; apply: andb_id2r => AutGa. (* the middle rewrite was rewrite 2!in_setI *) rewrite /= inE andbC inE (Aut_restr_perm sHG) //=. by symmetry; rewrite inE AutGa inE astabs_Aut_isom. Qed. Lemma injm_Aut_sub : Aut_in (Aut (f @* G)) (f @* H) \isog Aut_in (Aut G) H. Proof. do 2!rewrite isog_sym (isog_transl _ (Aut_in_isog _ _)). by rewrite isog_sym (isom_isog _ _ restr_perm_isom) // restr_perm_Aut. Qed. Lemma injm_Aut_full : (Aut_in (Aut (f @* G)) (f @* H) \isog Aut (f @* H)) = (Aut_in (Aut G) H \isog Aut H). Proof. by rewrite (isog_transl _ injm_Aut_sub) (isog_transr _ (injm_Aut injf sHD)). Qed. End InjmAutIn. Section GroupAction. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Local Notation actT := (action D rT). Definition is_groupAction (to : actT) := {in D, forall a, actperm to a \in Aut R}. Structure groupAction := GroupAction {gact :> actT; _ : is_groupAction gact}. Definition clone_groupAction to := let: GroupAction _ toA := to return {type of GroupAction for to} -> _ in fun k => k toA : groupAction. End GroupAction. Delimit Scope groupAction_scope with gact. Bind Scope groupAction_scope with groupAction. Arguments is_groupAction {aT rT D%_g} R%_g to%_act. Arguments groupAction {aT rT} D%_g R%_g. Arguments gact {aT rT D%_g R%_g} to%_gact : rename. Notation "[ 'groupAction' 'of' to ]" := (clone_groupAction (@GroupAction _ _ _ _ to)) (format "[ 'groupAction' 'of' to ]") : form_scope. Section GroupActionDefs. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Implicit Type A : {set aT}. Implicit Type S : {set rT}. Implicit Type to : groupAction D R. Definition gact_range of groupAction D R := R. Definition gacent to A := 'Fix_(R | to)(D :&: A). Definition acts_on_group A S to := [acts A, on S | to] /\ S \subset R. Coercion actby_cond_group A S to : acts_on_group A S to -> actby_cond A S to := @proj1 _ _. Definition acts_irreducibly A S to := [min S of G | G :!=: 1 & [acts A, on G | to]]. End GroupActionDefs. Arguments gacent {aT rT D%_g R%_g} to%_gact A%_g. Arguments acts_on_group {aT rT D%_g R%_g} A%_g S%_g to%_gact. Arguments acts_irreducibly {aT rT D%_g R%_g} A%_g S%_g to%_gact. Notation "''C_' ( | to ) ( A )" := (gacent to A) : group_scope. Notation "''C_' ( G | to ) ( A )" := (G :&: 'C_(|to)(A)) : group_scope. Notation "''C_' ( | to ) [ a ]" := 'C_(|to)([set a]) : group_scope. Notation "''C_' ( G | to ) [ a ]" := 'C_(G | to)([set a]) : group_scope. Notation "{ 'acts' A , 'on' 'group' G | to }" := (acts_on_group A G to) (format "{ 'acts' A , 'on' 'group' G | to }") : type_scope. Section RawGroupAction. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Variable to : groupAction D R. Lemma actperm_Aut : is_groupAction R to. Proof. by case: to. Qed. Lemma im_actperm_Aut : actperm to @* D \subset Aut R. Proof. by apply/subsetP=> _ /morphimP[a _ Da ->]; apply: actperm_Aut. Qed. Lemma gact_out x a : a \in D -> x \notin R -> to x a = x. Proof. by move=> Da Rx; rewrite -actpermE (out_Aut _ Rx) ?actperm_Aut. Qed. Lemma gactM : {in D, forall a, {in R &, {morph to^~ a : x y / x * y}}}. Proof. move=> a Da /= x y; rewrite -!(actpermE to); apply: morphicP x y. by rewrite Aut_morphic ?actperm_Aut. Qed. Lemma actmM a : {in R &, {morph actm to a : x y / x * y}}. Proof. by rewrite /actm; case: ifP => //; apply: gactM. Qed. Canonical act_morphism a := Morphism (actmM a). Lemma morphim_actm : {in D, forall a (S : {set rT}), S \subset R -> actm to a @* S = to^* S a}. Proof. by move=> a Da /= S sSR; rewrite /morphim /= actmEfun ?(setIidPr _). Qed. Variables (a : aT) (A B : {set aT}) (S : {set rT}). Lemma gacentIdom : 'C_(|to)(D :&: A) = 'C_(|to)(A). Proof. by rewrite /gacent setIA setIid. Qed. Lemma gacentIim : 'C_(R | to)(A) = 'C_(|to)(A). Proof. by rewrite setIA setIid. Qed. Lemma gacentS : A \subset B -> 'C_(|to)(B) \subset 'C_(|to)(A). Proof. by move=> sAB; rewrite !(setIS, afixS). Qed. Lemma gacentU : 'C_(|to)(A :|: B) = 'C_(|to)(A) :&: 'C_(|to)(B). Proof. by rewrite -setIIr -afixU -setIUr. Qed. Hypotheses (Da : a \in D) (sAD : A \subset D) (sSR : S \subset R). Lemma gacentE : 'C_(|to)(A) = 'Fix_(R | to)(A). Proof. by rewrite -{2}(setIidPr sAD). Qed. Lemma gacent1E : 'C_(|to)[a] = 'Fix_(R | to)[a]. Proof. by rewrite /gacent [D :&: _](setIidPr _) ?sub1set. Qed. Lemma subgacentE : 'C_(S | to)(A) = 'Fix_(S | to)(A). Proof. by rewrite gacentE setIA (setIidPl sSR). Qed. Lemma subgacent1E : 'C_(S | to)[a] = 'Fix_(S | to)[a]. Proof. by rewrite gacent1E setIA (setIidPl sSR). Qed. End RawGroupAction. Section GroupActionTheory. Variables aT rT : finGroupType. Variables (D : {group aT}) (R : {group rT}) (to : groupAction D R). Implicit Type A B : {set aT}. Implicit Types G H : {group aT}. Implicit Type S : {set rT}. Implicit Types M N : {group rT}. Lemma gact1 : {in D, forall a, to 1 a = 1}. Proof. by move=> a Da; rewrite /= -actmE ?morph1. Qed. Lemma gactV : {in D, forall a, {in R, {morph to^~ a : x / x^-1}}}. Proof. by move=> a Da /= x Rx; move; rewrite -!actmE ?morphV. Qed. Lemma gactX : {in D, forall a n, {in R, {morph to^~ a : x / x ^+ n}}}. Proof. by move=> a Da /= n x Rx; rewrite -!actmE // morphX. Qed. Lemma gactJ : {in D, forall a, {in R &, {morph to^~ a : x y / x ^ y}}}. Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphJ. Qed. Lemma gactR : {in D, forall a, {in R &, {morph to^~ a : x y / [~ x, y]}}}. Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphR. Qed. Lemma gact_stable : {acts D, on R | to}. Proof. apply: acts_act; apply/subsetP=> a Da; rewrite !inE Da. apply/subsetP=> x; rewrite inE; apply: contraLR => R'xa. by rewrite -(actKin to Da x) gact_out ?groupV. Qed. Lemma group_set_gacent A : group_set 'C_(|to)(A). Proof. apply/group_setP; split=> [|x y]. by rewrite !inE group1; apply/subsetP=> a /setIP[Da _]; rewrite inE gact1. case/setIP=> Rx /afixP cAx /setIP[Ry /afixP cAy]. rewrite inE groupM //; apply/afixP=> a Aa. by rewrite gactM ?cAx ?cAy //; case/setIP: Aa. Qed. Canonical gacent_group A := Group (group_set_gacent A). Lemma gacent1 : 'C_(|to)(1) = R. Proof. by rewrite /gacent (setIidPr (sub1G _)) afix1 setIT. Qed. Lemma gacent_gen A : A \subset D -> 'C_(|to)(<<A>>) = 'C_(|to)(A). Proof. by move=> sAD; rewrite /gacent ![D :&: _](setIidPr _) ?gen_subG ?afix_gen_in. Qed. Lemma gacentD1 A : 'C_(|to)(A^#) = 'C_(|to)(A). Proof. rewrite -gacentIdom -gacent_gen ?subsetIl // setIDA genD1 ?group1 //. by rewrite gacent_gen ?subsetIl // gacentIdom. Qed. Lemma gacent_cycle a : a \in D -> 'C_(|to)(<[a]>) = 'C_(|to)[a]. Proof. by move=> Da; rewrite gacent_gen ?sub1set. Qed. Lemma gacentY A B : A \subset D -> B \subset D -> 'C_(|to)(A <*> B) = 'C_(|to)(A) :&: 'C_(|to)(B). Proof. by move=> sAD sBD; rewrite gacent_gen ?gacentU // subUset sAD. Qed. Lemma gacentM G H : G \subset D -> H \subset D -> 'C_(|to)(G * H) = 'C_(|to)(G) :&: 'C_(|to)(H). Proof. by move=> sGD sHB; rewrite -gacent_gen ?mul_subG // genM_join gacentY. Qed. Lemma astab1 : 'C(1 | to) = D. Proof. by apply/setP=> x; rewrite ?(inE, sub1set) andb_idr //; move/gact1=> ->. Qed. Lemma astab_range : 'C(R | to) = 'C(setT | to). Proof. apply/eqP; rewrite eqEsubset andbC astabS ?subsetT //=. apply/subsetP=> a cRa; have Da := astab_dom cRa; rewrite !inE Da. apply/subsetP=> x; rewrite -(setUCr R) !inE. by case/orP=> ?; [rewrite (astab_act cRa) | rewrite gact_out]. Qed. Lemma gacentC A S : A \subset D -> S \subset R -> (S \subset 'C_(|to)(A)) = (A \subset 'C(S | to)). Proof. by move=> sAD sSR; rewrite subsetI sSR astabCin // (setIidPr sAD). Qed. Lemma astab_gen S : S \subset R -> 'C(<<S>> | to) = 'C(S | to). Proof. move=> sSR; apply/setP=> a; case Da: (a \in D); last by rewrite !inE Da. by rewrite -!sub1set -!gacentC ?sub1set ?gen_subG. Qed. Lemma astabM M N : M \subset R -> N \subset R -> 'C(M * N | to) = 'C(M | to) :&: 'C(N | to). Proof. move=> sMR sNR; rewrite -astabU -astab_gen ?mul_subG // genM_join. by rewrite astab_gen // subUset sMR. Qed. Lemma astabs1 : 'N(1 | to) = D. Proof. by rewrite astabs_set1 astab1. Qed. Lemma astabs_range : 'N(R | to) = D. Proof. apply/setIidPl; apply/subsetP=> a Da; rewrite inE. by apply/subsetP=> x Rx; rewrite inE gact_stable. Qed. Lemma astabsD1 S : 'N(S^# | to) = 'N(S | to). Proof. case S1: (1 \in S); last first. by rewrite (setDidPl _) // disjoint_sym disjoints_subset sub1set inE S1. apply/eqP; rewrite eqEsubset andbC -{1}astabsIdom -{1}astabs1 setIC astabsD /=. by rewrite -{2}(setD1K S1) -astabsIdom -{1}astabs1 astabsU. Qed. Lemma gacts_range A : A \subset D -> {acts A, on group R | to}. Proof. by move=> sAD; split; rewrite ?astabs_range. Qed. Lemma acts_subnorm_gacent A : A \subset D -> [acts 'N_D(A), on 'C_(| to)(A) | to]. Proof. move=> sAD; rewrite gacentE // actsI ?astabs_range ?subsetIl //. by rewrite -{2}(setIidPr sAD) acts_subnorm_fix. Qed. Lemma acts_subnorm_subgacent A B S : A \subset D -> [acts B, on S | to] -> [acts 'N_B(A), on 'C_(S | to)(A) | to]. Proof. move=> sAD actsB; rewrite actsI //; first by rewrite subIset ?actsB. by rewrite (subset_trans _ (acts_subnorm_gacent sAD)) ?setSI ?(acts_dom actsB). Qed. Lemma acts_gen A S : S \subset R -> [acts A, on S | to] -> [acts A, on <<S>> | to]. Proof. move=> sSR actsA; apply: {A}subset_trans actsA _. apply/subsetP=> a nSa; have Da := astabs_dom nSa; rewrite !inE Da. apply: subset_trans (_ : <<S>> \subset actm to a @*^-1 <<S>>) _. rewrite gen_subG subsetI sSR; apply/subsetP=> x Sx. by rewrite inE /= actmE ?mem_gen // astabs_act. by apply/subsetP=> x /[!inE]; case/andP=> Rx; rewrite /= actmE. Qed. Lemma acts_joing A M N : M \subset R -> N \subset R -> [acts A, on M | to] -> [acts A, on N | to] -> [acts A, on M <*> N | to]. Proof. by move=> sMR sNR nMA nNA; rewrite acts_gen ?actsU // subUset sMR. Qed. Lemma injm_actm a : 'injm (actm to a). Proof. apply/injmP=> x y Rx Ry; rewrite /= /actm; case: ifP => Da //. exact: act_inj. Qed. Lemma im_actm a : actm to a @* R = R. Proof. apply/eqP; rewrite eqEcard (card_injm (injm_actm a)) // leqnn andbT. apply/subsetP=> _ /morphimP[x Rx _ ->] /=. by rewrite /actm; case: ifP => // Da; rewrite gact_stable. Qed. Lemma acts_char G M : G \subset D -> M \char R -> [acts G, on M | to]. Proof. move=> sGD /charP[sMR charM]. apply/subsetP=> a Ga; have Da := subsetP sGD a Ga; rewrite !inE Da. apply/subsetP=> x Mx; have Rx := subsetP sMR x Mx. by rewrite inE -(charM _ (injm_actm a) (im_actm a)) -actmE // mem_morphim. Qed. Lemma gacts_char G M : G \subset D -> M \char R -> {acts G, on group M | to}. (* TODO: investigate why rewrite does not match in the same order *) Proof. by move=> sGD charM; split; rewrite ?acts_char// char_sub. Qed. (* was ending with rewrite (acts_char, char_sub)// *) Section Restrict. Variables (A : {group aT}) (sAD : A \subset D). Lemma ract_is_groupAction : is_groupAction R (to \ sAD). Proof. by move=> a Aa /=; rewrite ractpermE actperm_Aut ?(subsetP sAD). Qed. Canonical ract_groupAction := GroupAction ract_is_groupAction. Lemma gacent_ract B : 'C_(|ract_groupAction)(B) = 'C_(|to)(A :&: B). Proof. by rewrite /gacent afix_ract setIA (setIidPr sAD). Qed. End Restrict. Section ActBy. Variables (A : {group aT}) (G : {group rT}) (nGAg : {acts A, on group G | to}). Lemma actby_is_groupAction : is_groupAction G <[nGAg]>. Proof. move=> a Aa; rewrite /= inE; apply/andP; split. apply/subsetP=> x; apply: contraR => Gx. by rewrite actpermE /= /actby (negbTE Gx). apply/morphicP=> x y Gx Gy; rewrite !actpermE /= /actby Aa groupM ?Gx ?Gy //=. by case nGAg; move/acts_dom; do 2!move/subsetP=> ?; rewrite gactM; auto. Qed. Canonical actby_groupAction := GroupAction actby_is_groupAction. Lemma gacent_actby B : 'C_(|actby_groupAction)(B) = 'C_(G | to)(A :&: B). Proof. rewrite /gacent afix_actby !setIA setIid setIUr setICr set0U. by have [nAG sGR] := nGAg; rewrite (setIidPr (acts_dom nAG)) (setIidPl sGR). Qed. End ActBy. Section Quotient. Variable H : {group rT}. Lemma acts_qact_dom_norm : {acts qact_dom to H, on 'N(H) | to}. Proof. move=> a HDa /= x; rewrite {2}(('N(H) =P to^~ a @^-1: 'N(H)) _) ?inE {x}//. rewrite eqEcard (card_preimset _ (act_inj _ _)) leqnn andbT. apply/subsetP=> x Nx; rewrite inE; move/(astabs_act (H :* x)): HDa. rewrite mem_rcosets mulSGid ?normG // Nx => /rcosetsP[y Ny defHy]. suffices: to x a \in H :* y by apply: subsetP; rewrite mul_subG ?sub1set ?normG. by rewrite -defHy; apply: imset_f; apply: rcoset_refl. Qed. Lemma qact_is_groupAction : is_groupAction (R / H) (to / H). Proof. move=> a HDa /=; have Da := astabs_dom HDa. rewrite inE; apply/andP; split. apply/subsetP=> Hx /=; case: (cosetP Hx) => x Nx ->{Hx}. apply: contraR => R'Hx; rewrite actpermE qactE // gact_out //. by apply: contra R'Hx; apply: mem_morphim. apply/morphicP=> Hx Hy; rewrite !actpermE. case/morphimP=> x Nx Gx ->{Hx}; case/morphimP=> y Ny Gy ->{Hy}. by rewrite -morphM ?qactE ?groupM ?gactM // morphM ?acts_qact_dom_norm. Qed. Canonical quotient_groupAction := GroupAction qact_is_groupAction. Lemma qact_domE : H \subset R -> qact_dom to H = 'N(H | to). Proof. move=> sHR; apply/setP=> a; apply/idP/idP=> nHa; have Da := astabs_dom nHa. rewrite !inE Da; apply/subsetP=> x Hx; rewrite inE -(rcoset1 H). have /rcosetsP[y Ny defHy]: to^~ a @: H \in rcosets H 'N(H). by rewrite (astabs_act _ nHa); apply/rcosetsP; exists 1; rewrite ?mulg1. by rewrite (rcoset_eqP (_ : 1 \in H :* y)) -defHy -1?(gact1 Da) mem_setact. rewrite !inE Da; apply/subsetP=> Hx /[1!inE] /rcosetsP[x Nx ->{Hx}]. apply/imsetP; exists (to x a). case Rx: (x \in R); last by rewrite gact_out ?Rx. rewrite inE; apply/subsetP=> _ /imsetP[y Hy ->]. rewrite -(actKVin to Da y) -gactJ // ?(subsetP sHR, astabs_act, groupV) //. by rewrite memJ_norm // astabs_act ?groupV. apply/eqP; rewrite rcosetE eqEcard. rewrite (card_imset _ (act_inj _ _)) !card_rcoset leqnn andbT. apply/subsetP=> _ /imsetP[y Hxy ->]; rewrite !mem_rcoset in Hxy *. have Rxy := subsetP sHR _ Hxy; rewrite -(mulgKV x y). case Rx: (x \in R); last by rewrite !gact_out ?mulgK // 1?groupMl ?Rx. by rewrite -gactV // -gactM 1?groupMr ?groupV // mulgK astabs_act. Qed. End Quotient. Section Mod. Variable H : {group aT}. Lemma modact_is_groupAction : is_groupAction 'C_(|to)(H) (to %% H). Proof. move=> Ha /morphimP[a Na Da ->]; have NDa: a \in 'N_D(H) by apply/setIP. rewrite inE; apply/andP; split. apply/subsetP=> x; rewrite 2!inE andbC actpermE /= modactEcond //. by apply: contraR; case: ifP => // E Rx; rewrite gact_out. apply/morphicP=> x y /setIP[Rx cHx] /setIP[Ry cHy]. rewrite /= !actpermE /= !modactE ?gactM //. suffices: x * y \in 'C_(|to)(H) by case/setIP. by rewrite groupM //; apply/setIP. Qed. Canonical mod_groupAction := GroupAction modact_is_groupAction. Lemma modgactE x a : H \subset 'C(R | to) -> a \in 'N_D(H) -> (to %% H)%act x (coset H a) = to x a. Proof. move=> cRH NDa /=; have [Da Na] := setIP NDa. have [Rx | notRx] := boolP (x \in R). by rewrite modactE //; apply/afixP=> b /setIP[_ /(subsetP cRH)/astab_act->]. rewrite gact_out //= /modact; case: ifP => // _; rewrite gact_out //. suffices: a \in D :&: coset H a by case/mem_repr/setIP. by rewrite inE Da val_coset // rcoset_refl. Qed. Lemma gacent_mod G M : H \subset 'C(M | to) -> G \subset 'N(H) -> 'C_(M | mod_groupAction)(G / H) = 'C_(M | to)(G). Proof. move=> cMH nHG; rewrite -gacentIdom gacentE ?subsetIl // setICA. have sHD: H \subset D by rewrite (subset_trans cMH) ?subsetIl. rewrite -quotientGI // afix_mod ?setIS // setICA -gacentIim (setIC R) -setIA. rewrite -gacentE ?subsetIl // gacentIdom setICA (setIidPr _) //. by rewrite gacentC // ?(subset_trans cMH) ?astabS ?subsetIl // setICA subsetIl. Qed. Lemma acts_irr_mod G M : H \subset 'C(M | to) -> G \subset 'N(H) -> acts_irreducibly G M to -> acts_irreducibly (G / H) M mod_groupAction. Proof. move=> cMH nHG /mingroupP[/andP[ntM nMG] minM]. apply/mingroupP; rewrite ntM astabs_mod ?quotientS //; split=> // L modL ntL. have cLH: H \subset 'C(L | to) by rewrite (subset_trans cMH) ?astabS //. apply: minM => //; case/andP: modL => ->; rewrite astabs_mod ?quotientSGK //. by rewrite (subset_trans cLH) ?astab_sub. Qed. End Mod. Lemma modact_coset_astab x a : a \in D -> (to %% 'C(R | to))%act x (coset _ a) = to x a. Proof. move=> Da; apply: modgactE => {x}//. rewrite !inE Da; apply/subsetP=> _ /imsetP[c Cc ->]. have Dc := astab_dom Cc; rewrite !inE groupJ //. apply/subsetP=> x Rx; rewrite inE conjgE !actMin ?groupM ?groupV //. by rewrite (astab_act Cc) ?actKVin // gact_stable ?groupV. Qed. Lemma acts_irr_mod_astab G M : acts_irreducibly G M to -> acts_irreducibly (G / 'C_G(M | to)) M (mod_groupAction _). Proof. move=> irrG; have /andP[_ nMG] := mingroupp irrG. apply: acts_irr_mod irrG; first exact: subsetIr. by rewrite normsI ?normG // (subset_trans nMG) // astab_norm. Qed. Section CompAct. Variables (gT : finGroupType) (G : {group gT}) (f : {morphism G >-> aT}). Lemma comp_is_groupAction : is_groupAction R (comp_action to f). Proof. move=> a /morphpreP[Ba Dfa]; apply: etrans (actperm_Aut to Dfa). by congr (_ \in Aut R); apply/permP=> x; rewrite !actpermE. Qed. Canonical comp_groupAction := GroupAction comp_is_groupAction. Lemma gacent_comp U : 'C_(|comp_groupAction)(U) = 'C_(|to)(f @* U). Proof. rewrite /gacent afix_comp ?subIset ?subxx //. by rewrite -(setIC U) (setIC D) morphim_setIpre. Qed. End CompAct. End GroupActionTheory. Notation "''C_' ( | to ) ( A )" := (gacent_group to A) : Group_scope. Notation "''C_' ( G | to ) ( A )" := (setI_group G 'C_(|to)(A)) : Group_scope. Notation "''C_' ( | to ) [ a ]" := (gacent_group to [set a%g]) : Group_scope. Notation "''C_' ( G | to ) [ a ]" := (setI_group G 'C_(|to)[a]) : Group_scope. Notation "to \ sAD" := (ract_groupAction to sAD) : groupAction_scope. Notation "<[ nGA ] >" := (actby_groupAction nGA) : groupAction_scope. Notation "to / H" := (quotient_groupAction to H) : groupAction_scope. Notation "to %% H" := (mod_groupAction to H) : groupAction_scope. Notation "to \o f" := (comp_groupAction to f) : groupAction_scope. (* Operator group isomorphism. *) Section MorphAction. Variables (aT1 aT2 : finGroupType) (rT1 rT2 : finType). Variables (D1 : {group aT1}) (D2 : {group aT2}). Variables (to1 : action D1 rT1) (to2 : action D2 rT2). Variables (A : {set aT1}) (R S : {set rT1}). Variables (h : rT1 -> rT2) (f : {morphism D1 >-> aT2}). Hypotheses (actsDR : {acts D1, on R | to1}) (injh : {in R &, injective h}). Hypothesis defD2 : f @* D1 = D2. Hypotheses (sSR : S \subset R) (sAD1 : A \subset D1). Hypothesis hfJ : {in S & D1, morph_act to1 to2 h f}. Lemma morph_astabs : f @* 'N(S | to1) = 'N(h @: S | to2). Proof. apply/setP=> fx; apply/morphimP/idP=> [[x D1x nSx ->] | nSx]. rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->]. by rewrite inE -hfJ ?imset_f // (astabs_act _ nSx). have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1). by rewrite defD2 (astabs_dom nSx). exists x => //; rewrite !inE D1x; apply/subsetP=> u Su. have /imsetP[u' Su' /injh def_u']: h (to1 u x) \in h @: S. by rewrite hfJ // -def_fx (astabs_act _ nSx) imset_f. by rewrite inE def_u' ?actsDR ?(subsetP sSR). Qed. Lemma morph_astab : f @* 'C(S | to1) = 'C(h @: S | to2). Proof. apply/setP=> fx; apply/morphimP/idP=> [[x D1x cSx ->] | cSx]. rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->]. by rewrite inE -hfJ // (astab_act cSx). have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1). by rewrite defD2 (astab_dom cSx). exists x => //; rewrite !inE D1x; apply/subsetP=> u Su. rewrite inE -(inj_in_eq injh) ?actsDR ?(subsetP sSR) ?hfJ //. by rewrite -def_fx (astab_act cSx) ?imset_f. Qed. Lemma morph_afix : h @: 'Fix_(S | to1)(A) = 'Fix_(h @: S | to2)(f @* A). Proof. apply/setP=> hu; apply/imsetP/setIP=> [[u /setIP[Su cAu] ->]|]. split; first by rewrite imset_f. by apply/afixP=> _ /morphimP[x D1x Ax ->]; rewrite -hfJ ?(afixP cAu). case=> /imsetP[u Su ->] /afixP c_hu_fA; exists u; rewrite // inE Su. apply/afixP=> x Ax; have Dx := subsetP sAD1 x Ax. by apply: injh; rewrite ?actsDR ?(subsetP sSR) ?hfJ // c_hu_fA ?mem_morphim. Qed. End MorphAction. Section MorphGroupAction. Variables (aT1 aT2 rT1 rT2 : finGroupType). Variables (D1 : {group aT1}) (D2 : {group aT2}). Variables (R1 : {group rT1}) (R2 : {group rT2}). Variables (to1 : groupAction D1 R1) (to2 : groupAction D2 R2). Variables (h : {morphism R1 >-> rT2}) (f : {morphism D1 >-> aT2}). Hypotheses (iso_h : isom R1 R2 h) (iso_f : isom D1 D2 f). Hypothesis hfJ : {in R1 & D1, morph_act to1 to2 h f}. Implicit Types (A : {set aT1}) (S : {set rT1}) (M : {group rT1}). Lemma morph_gastabs S : S \subset R1 -> f @* 'N(S | to1) = 'N(h @* S | to2). Proof. have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h). move=> sSR1; rewrite (morphimEsub _ sSR1). apply: (morph_astabs (gact_stable to1) (injmP injh)) => // u x. by move/(subsetP sSR1); apply: hfJ. Qed. Lemma morph_gastab S : S \subset R1 -> f @* 'C(S | to1) = 'C(h @* S | to2). Proof. have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h). move=> sSR1; rewrite (morphimEsub _ sSR1). apply: (morph_astab (gact_stable to1) (injmP injh)) => // u x. by move/(subsetP sSR1); apply: hfJ. Qed. Lemma morph_gacent A : A \subset D1 -> h @* 'C_(|to1)(A) = 'C_(|to2)(f @* A). Proof. have [[_ defD2] [injh defR2]] := (isomP iso_f, isomP iso_h). move=> sAD1; rewrite !gacentE //; last by rewrite -defD2 morphimS. rewrite morphimEsub ?subsetIl // -{1}defR2 morphimEdom. exact: (morph_afix (gact_stable to1) (injmP injh)). Qed. Lemma morph_gact_irr A M : A \subset D1 -> M \subset R1 -> acts_irreducibly (f @* A) (h @* M) to2 = acts_irreducibly A M to1. Proof. move=> sAD1 sMR1. have [[injf defD2] [injh defR2]] := (isomP iso_f, isomP iso_h). have h_eq1 := morphim_injm_eq1 injh. apply/mingroupP/mingroupP=> [] [/andP[ntM actAM] minM]. split=> [|U]; first by rewrite -h_eq1 // ntM -(injmSK injf) ?morph_gastabs. case/andP=> ntU acts_fAU sUM; have sUR1 := subset_trans sUM sMR1. apply: (injm_morphim_inj injh) => //; apply: minM; last exact: morphimS. by rewrite h_eq1 // ntU -morph_gastabs ?morphimS. split=> [|U]; first by rewrite h_eq1 // ntM -morph_gastabs ?morphimS. case/andP=> ntU acts_fAU sUhM. have sUhR1 := subset_trans sUhM (morphimS h sMR1). have sU'M: h @*^-1 U \subset M by rewrite sub_morphpre_injm. rewrite /= -(minM _ _ sU'M) ?morphpreK // -h_eq1 ?subsetIl // -(injmSK injf) //. by rewrite morph_gastabs ?(subset_trans sU'M) // morphpreK ?ntU. Qed. End MorphGroupAction. (* Conjugation and right translation actions. *) Section InternalActionDefs. Variable gT : finGroupType. Implicit Type A : {set gT}. Implicit Type G : {group gT}. (* This is not a Canonical action because it is seldom used, and it would *) (* cause too many spurious matches (any group product would be viewed as an *) (* action!). *) Definition mulgr_action := TotalAction (@mulg1 gT) (@mulgA gT). Canonical conjg_action := TotalAction (@conjg1 gT) (@conjgM gT). Lemma conjg_is_groupAction : is_groupAction setT conjg_action. Proof. move=> a _; rewrite inE; apply/andP; split; first by apply/subsetP=> x /[1!inE]. by apply/morphicP=> x y _ _; rewrite !actpermE /= conjMg. Qed. Canonical conjg_groupAction := GroupAction conjg_is_groupAction. Lemma rcoset_is_action : is_action setT (@rcoset gT). Proof. by apply: is_total_action => [A|A x y]; rewrite !rcosetE (mulg1, rcosetM). Qed. Canonical rcoset_action := Action rcoset_is_action. Canonical conjsg_action := TotalAction (@conjsg1 gT) (@conjsgM gT). Lemma conjG_is_action : is_action setT (@conjG_group gT). Proof. apply: is_total_action => [G | G x y]; apply: val_inj; rewrite /= ?act1 //. exact: actM. Qed. Definition conjG_action := Action conjG_is_action. End InternalActionDefs. Notation "'R" := (@mulgr_action _) : action_scope. Notation "'Rs" := (@rcoset_action _) : action_scope. Notation "'J" := (@conjg_action _) : action_scope. Notation "'J" := (@conjg_groupAction _) : groupAction_scope. Notation "'Js" := (@conjsg_action _) : action_scope. Notation "'JG" := (@conjG_action _) : action_scope. Notation "'Q" := ('J / _)%act : action_scope. Notation "'Q" := ('J / _)%gact : groupAction_scope. Section InternalGroupAction. Variable gT : finGroupType. Implicit Types A B : {set gT}. Implicit Types G H : {group gT}. Implicit Type x : gT. (* Various identities for actions on groups. *) Lemma orbitR G x : orbit 'R G x = x *: G. Proof. by rewrite -lcosetE. Qed. Lemma astab1R x : 'C[x | 'R] = 1. Proof. apply/trivgP/subsetP=> y cxy. by rewrite -(mulKg x y) [x * y](astab1P cxy) mulVg set11. Qed. Lemma astabR G : 'C(G | 'R) = 1. Proof. apply/trivgP/subsetP=> x cGx. by rewrite -(mul1g x) [1 * x](astabP cGx) group1. Qed. Lemma astabsR G : 'N(G | 'R) = G. Proof. apply/setP=> x; rewrite !inE -setactVin ?inE //=. by rewrite -groupV -{1 3}(mulg1 G) rcoset_sym -sub1set -mulGS -!rcosetE. Qed. Lemma atransR G : [transitive G, on G | 'R]. Proof. by rewrite /atrans -{1}(mul1g G) -orbitR imset_f. Qed. Lemma faithfulR G : [faithful G, on G | 'R]. Proof. by rewrite /faithful astabR subsetIr. Qed. Definition Cayley_repr G := actperm <[atrans_acts (atransR G)]>. Theorem Cayley_isom G : isom G (Cayley_repr G @* G) (Cayley_repr G). Proof. exact: faithful_isom (faithfulR G). Qed. Theorem Cayley_isog G : G \isog Cayley_repr G @* G. Proof. exact: isom_isog (Cayley_isom G). Qed. Lemma orbitJ G x : orbit 'J G x = x ^: G. Proof. by []. Qed. Lemma afixJ A : 'Fix_('J)(A) = 'C(A). Proof. apply/setP=> x; apply/afixP/centP=> cAx y Ay /=. by rewrite /commute conjgC cAx. by rewrite conjgE cAx ?mulKg. Qed. Lemma astabJ A : 'C(A |'J) = 'C(A). Proof. apply/setP=> x; apply/astabP/centP=> cAx y Ay /=. by apply: esym; rewrite conjgC cAx. by rewrite conjgE -cAx ?mulKg. Qed. Lemma astab1J x : 'C[x |'J] = 'C[x]. Proof. by rewrite astabJ cent_set1. Qed. Lemma astabsJ A : 'N(A | 'J) = 'N(A). Proof. by apply/setP=> x; rewrite -2!groupV !inE -conjg_preim -sub_conjg. Qed. Lemma setactJ A x : 'J^*%act A x = A :^ x. Proof. by []. Qed. Lemma gacentJ A : 'C_(|'J)(A) = 'C(A). Proof. by rewrite gacentE ?setTI ?subsetT ?afixJ. Qed. Lemma orbitRs G A : orbit 'Rs G A = rcosets A G. Proof. by []. Qed. Lemma sub_afixRs_norms G x A : (G :* x \in 'Fix_('Rs)(A)) = (A \subset G :^ x). Proof. rewrite inE /=; apply: eq_subset_r => a. rewrite inE rcosetE -(can2_eq (rcosetKV x) (rcosetK x)) -!rcosetM. rewrite eqEcard card_rcoset leqnn andbT mulgA (conjgCV x) mulgK. by rewrite -{2 3}(mulGid G) mulGS sub1set -mem_conjg. Qed. Lemma sub_afixRs_norm G x : (G :* x \in 'Fix_('Rs)(G)) = (x \in 'N(G)). Proof. by rewrite sub_afixRs_norms -groupV inE sub_conjgV. Qed. Lemma afixRs_rcosets A G : 'Fix_(rcosets G A | 'Rs)(G) = rcosets G 'N_A(G). Proof. apply/setP=> Gx; apply/setIP/rcosetsP=> [[/rcosetsP[x Ax ->]]|[x]]. by rewrite sub_afixRs_norm => Nx; exists x; rewrite // inE Ax. by case/setIP=> Ax Nx ->; rewrite -{1}rcosetE imset_f // sub_afixRs_norm. Qed. Lemma astab1Rs G : 'C[G : {set gT} | 'Rs] = G. Proof. apply/setP=> x. by apply/astab1P/idP=> /= [<- | Gx]; rewrite rcosetE ?rcoset_refl ?rcoset_id. Qed. Lemma actsRs_rcosets H G : [acts G, on rcosets H G | 'Rs]. Proof. by rewrite -orbitRs acts_orbit ?subsetT. Qed. Lemma transRs_rcosets H G : [transitive G, on rcosets H G | 'Rs]. Proof. by rewrite -orbitRs atrans_orbit. Qed. (* This is the second part of Aschbacher (5.7) *) Lemma astabRs_rcosets H G : 'C(rcosets H G | 'Rs) = gcore H G. Proof. have transGH := transRs_rcosets H G. by rewrite (astab_trans_gcore transGH (orbit_refl _ G _)) astab1Rs. Qed. Lemma orbitJs G A : orbit 'Js G A = A :^: G. Proof. by []. Qed. Lemma astab1Js A : 'C[A | 'Js] = 'N(A). Proof. by apply/setP=> x; apply/astab1P/normP. Qed. Lemma card_conjugates A G : #|A :^: G| = #|G : 'N_G(A)|. Proof. by rewrite card_orbit astab1Js. Qed. Lemma afixJG G A : (G \in 'Fix_('JG)(A)) = (A \subset 'N(G)). Proof. by apply/afixP/normsP=> nG x Ax; apply/eqP; move/eqP: (nG x Ax). Qed. Lemma astab1JG G : 'C[G | 'JG] = 'N(G). Proof. by apply/setP=> x; apply/astab1P/normP=> [/congr_group | /group_inj]. Qed. Lemma dom_qactJ H : qact_dom 'J H = 'N(H). Proof. by rewrite qact_domE ?subsetT ?astabsJ. Qed. Lemma qactJ H (Hy : coset_of H) x : 'Q%act Hy x = if x \in 'N(H) then Hy ^ coset H x else Hy. Proof. case: (cosetP Hy) => y Ny ->{Hy}. by rewrite qactEcond // dom_qactJ; case Nx: (x \in 'N(H)); rewrite ?morphJ. Qed. Lemma actsQ A B H : A \subset 'N(H) -> A \subset 'N(B) -> [acts A, on B / H | 'Q]. Proof. by move=> nHA nBA; rewrite acts_quotient // subsetI dom_qactJ nHA astabsJ. Qed. Lemma astabsQ G H : H <| G -> 'N(G / H | 'Q) = 'N(H) :&: 'N(G). Proof. by move=> nsHG; rewrite astabs_quotient // dom_qactJ astabsJ. Qed. Lemma astabQ H Abar : 'C(Abar |'Q) = coset H @*^-1 'C(Abar). Proof. apply/setP=> x; rewrite inE /= dom_qactJ morphpreE in_setI /=. apply: andb_id2l => Nx; rewrite !inE -sub1set centsC cent_set1. apply: eq_subset_r => {Abar} Hy; rewrite inE qactJ Nx (sameP eqP conjg_fixP). by rewrite (sameP cent1P eqP) (sameP commgP eqP). Qed. Lemma sub_astabQ A H Bbar : (A \subset 'C(Bbar | 'Q)) = (A \subset 'N(H)) && (A / H \subset 'C(Bbar)). Proof. rewrite astabQ -morphpreIdom subsetI; apply: andb_id2l => nHA. by rewrite -sub_quotient_pre. Qed. Lemma sub_astabQR A B H : A \subset 'N(H) -> B \subset 'N(H) -> (A \subset 'C(B / H | 'Q)) = ([~: A, B] \subset H). Proof. move=> nHA nHB; rewrite sub_astabQ nHA /= (sameP commG1P eqP). by rewrite eqEsubset sub1G andbT -quotientR // quotient_sub1 // comm_subG. Qed. Lemma astabQR A H : A \subset 'N(H) -> 'C(A / H | 'Q) = [set x in 'N(H) | [~: [set x], A] \subset H]. Proof. move=> nHA; apply/setP=> x; rewrite astabQ -morphpreIdom 2!inE -astabQ. by case nHx: (x \in _); rewrite //= -sub1set sub_astabQR ?sub1set. Qed. Lemma quotient_astabQ H Abar : 'C(Abar | 'Q) / H = 'C(Abar). Proof. by rewrite astabQ cosetpreK. Qed. Lemma conj_astabQ A H x : x \in 'N(H) -> 'C(A / H | 'Q) :^ x = 'C(A :^ x / H | 'Q). Proof. move=> nHx; apply/setP=> y; rewrite !astabQ mem_conjg !in_setI -mem_conjg. rewrite -normJ (normP nHx) quotientJ //; apply/andb_id2l => nHy. by rewrite !inE centJ morphJ ?groupV ?morphV // -mem_conjg. Qed. Section CardClass. Variable G : {group gT}. Lemma index_cent1 x : #|G : 'C_G[x]| = #|x ^: G|. Proof. by rewrite -astab1J -card_orbit. Qed. Lemma classes_partition : partition (classes G) G. Proof. by apply: orbit_partition; apply/actsP=> x Gx y; apply: groupJr. Qed. Lemma sum_card_class : \sum_(C in classes G) #|C| = #|G|. Proof. by apply: acts_sum_card_orbit; apply/actsP=> x Gx y; apply: groupJr. Qed. Lemma class_formula : \sum_(C in classes G) #|G : 'C_G[repr C]| = #|G|. Proof. rewrite -sum_card_class; apply: eq_bigr => _ /imsetP[x Gx ->]. have: x \in x ^: G by rewrite -{1}(conjg1 x) imset_f. by case/mem_repr/imsetP=> y Gy ->; rewrite index_cent1 classGidl. Qed. Lemma abelian_classP : reflect {in G, forall x, x ^: G = [set x]} (abelian G). Proof. rewrite /abelian -astabJ astabC. by apply: (iffP subsetP) => cGG x Gx; apply/orbit1P; apply: cGG. Qed. Lemma card_classes_abelian : abelian G = (#|classes G| == #|G|). Proof. have cGgt0 C: C \in classes G -> 1 <= #|C| ?= iff (#|C| == 1)%N. by case/imsetP=> x _ ->; rewrite eq_sym -index_cent1. rewrite -sum_card_class -sum1_card (leqif_sum cGgt0). apply/abelian_classP/forall_inP=> [cGG _ /imsetP[x Gx ->]| cGG x Gx]. by rewrite cGG ?cards1. apply/esym/eqP; rewrite eqEcard sub1set cards1 class_refl leq_eqVlt cGG //. exact: imset_f. Qed. End CardClass. End InternalGroupAction. Lemma gacentQ (gT : finGroupType) (H : {group gT}) (A : {set gT}) : 'C_(|'Q)(A) = 'C(A / H). Proof. apply/setP=> Hx; case: (cosetP Hx) => x Nx ->{Hx}. rewrite -sub_cent1 -astab1J astabC sub1set -(quotientInorm H A). have defD: qact_dom 'J H = 'N(H) by rewrite qact_domE ?subsetT ?astabsJ. rewrite !(inE, mem_quotient) //= defD setIC. apply/subsetP/subsetP=> [cAx _ /morphimP[a Na Aa ->] | cAx a Aa]. by move/cAx: Aa; rewrite !inE qactE ?defD ?morphJ. have [_ Na] := setIP Aa; move/implyP: (cAx (coset H a)); rewrite mem_morphim //. by rewrite !inE qactE ?defD ?morphJ. Qed. Section AutAct. Variable (gT : finGroupType) (G : {set gT}). Definition autact := act ('P \ subsetT (Aut G)). Canonical aut_action := [action of autact]. Lemma autactK a : actperm aut_action a = a. Proof. by apply/permP=> x; rewrite permE. Qed. Lemma autact_is_groupAction : is_groupAction G aut_action. Proof. by move=> a Aa /=; rewrite autactK. Qed. Canonical aut_groupAction := GroupAction autact_is_groupAction. Section perm_prime_orbit. Variable (T : finType) (c : {perm T}). Hypothesis Tp : prime #|T|. Hypothesis cc : #[c]%g = #|T|. Let cp : prime #[c]%g. Proof. by rewrite cc. Qed. Lemma perm_prime_atrans : [transitive <[c]>, on setT | 'P]. Proof. apply/imsetP; suff /existsP[x] : [exists x, ~~ (#|orbit 'P <[c]> x| < #[c])]. move=> oxT; suff /eqP orbit_x : orbit 'P <[c]> x == setT by exists x. by rewrite eqEcard subsetT cardsT -cc leqNgt. apply/forallP => olT; have o1 x : #|orbit 'P <[c]> x| == 1%N. by case/primeP: cp => _ /(_ _ (dvdn_orbit 'P _ x))/orP[]//; rewrite ltn_eqF. suff c1 : c = 1%g by rewrite c1 ?order1 in (cp). apply/permP => x; rewrite perm1; apply/set1P. by rewrite -(card_orbit1 (eqP (o1 _))) (mem_orbit 'P) ?cycle_id. Qed. Lemma perm_prime_orbit x : orbit 'P <[c]> x = [set: T]. Proof. by apply: atransP => //; apply: perm_prime_atrans. Qed. Lemma perm_prime_astab x : 'C_<[c]>[x | 'P]%g = 1%g. Proof. by apply/card1_trivg/eqP; rewrite -(@eqn_pmul2l #|orbit 'P <[c]> x|) ?card_orbit_stab ?perm_prime_orbit ?cardsT ?muln1 ?prime_gt0// -cc. Qed. End perm_prime_orbit. End AutAct. Arguments autact {gT} G%_g. Arguments aut_action {gT} G%_g. Arguments aut_groupAction {gT} G%_g. Notation "[ 'Aut' G ]" := (aut_action G) : action_scope. Notation "[ 'Aut' G ]" := (aut_groupAction G) : groupAction_scope.
ZeroHypercover.lean
/- Copyright (c) 2025 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Sites.Coverage /-! # 0-hypercovers Given a coverage `J` on a category `C`, we define the type of `0`-hypercovers of an object `S : C`. They consists of a covering family of morphisms `X i ⟶ S` indexed by a type `I₀` such that the induced presieve is in `J`. We define this with respect to a coverage and not to a Grothendieck topology, because this yields more control over the components of the cover. -/ universe w' w v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] /-- The categorical data that is involved in a `0`-hypercover of an object `S`. This consists of a family of morphisms `f i : X i ⟶ S` for `i : I₀`. -/ structure PreZeroHypercover (S : C) where /-- the index type of the covering of `S` -/ I₀ : Type w /-- the objects in the covering of `S` -/ X (i : I₀) : C /-- the morphisms in the covering of `S` -/ f (i : I₀) : X i ⟶ S namespace PreZeroHypercover variable {S T : C} (E : PreZeroHypercover.{w} S) /-- The assumption that the pullback of `X i₁` and `X i₂` over `S` exists for any `i₁` and `i₂`. -/ abbrev HasPullbacks := ∀ (i₁ i₂ : E.I₀), HasPullback (E.f i₁) (E.f i₂) /-- The presieve of `S` that is generated by the morphisms `f i : X i ⟶ S`. -/ abbrev presieve₀ : Presieve S := .ofArrows _ E.f /-- The sieve of `S` that is generated by the morphisms `f i : X i ⟶ S`. -/ abbrev sieve₀ : Sieve S := .ofArrows _ E.f /-- The pre-`0`-hypercover defined by a single morphism. -/ @[simps] def singleton (f : S ⟶ T) : PreZeroHypercover.{w} T where I₀ := PUnit X _ := S f _ := f /-- Pullback of a pre-`0`-hypercover along a morphism. The components are `pullback f (E.f i)`. -/ @[simps] noncomputable def pullback₁ (f : S ⟶ T) (E : PreZeroHypercover.{w} T) [∀ i, HasPullback f (E.f i)] : PreZeroHypercover.{w} S where I₀ := E.I₀ X i := pullback f (E.f i) f _ := pullback.fst _ _ /-- Pullback of a pre-`0`-hypercover along a morphism. The components are `pullback (E.f i) f`. -/ @[simps] noncomputable def pullback₂ (f : S ⟶ T) (E : PreZeroHypercover.{w} T) [∀ i, HasPullback (E.f i) f] : PreZeroHypercover.{w} S where I₀ := E.I₀ X i := pullback (E.f i) f f _ := pullback.snd _ _ lemma presieve₀_pullback₁ [Limits.HasPullbacks C] (f : S ⟶ T) (E : PreZeroHypercover.{w} T) : presieve₀ (E.pullback₂ f) = E.presieve₀.pullbackArrows f := by refine le_antisymm ?_ ?_ · rintro - - ⟨i⟩ use _, _, i · rintro W g ⟨-, -, ⟨i⟩⟩ use i /-- Refining each component of a pre-`0`-hypercover yields a refined pre-`0`-hypercover of the base. -/ @[simps] def bind (E : PreZeroHypercover.{w} T) (F : ∀ i, PreZeroHypercover.{w'} (E.X i)) : PreZeroHypercover.{max w w'} T where I₀ := Σ (i : E.I₀), (F i).I₀ X := fun ⟨i, j⟩ ↦ (F i).X j f := fun ⟨i, j⟩ ↦ (F i).f j ≫ E.f i section Category variable {E : PreZeroHypercover.{w} S} {F : PreZeroHypercover.{w'} S} /-- A morphism of pre-`0`-hypercovers of `S` is a family of refinement morphisms commuting with the structure morphisms of `E` and `F`. -/ @[ext] structure Hom (E : PreZeroHypercover.{w} S) (F : PreZeroHypercover.{w'} S) where /-- The map between indexing types of the coverings of `S` -/ s₀ (i : E.I₀) : F.I₀ /-- The refinement morphisms between objects in the coverings of `S`. -/ h₀ (i : E.I₀) : E.X i ⟶ F.X (s₀ i) w₀ (i : E.I₀) : h₀ i ≫ F.f (s₀ i) = E.f i := by cat_disch attribute [reassoc (attr := simp)] Hom.w₀ /-- The identity refinement of a pre-`0`-hypercover. -/ @[simps] def Hom.id (E : PreZeroHypercover S) : Hom E E where s₀ := _root_.id h₀ _ := 𝟙 _ variable {G : PreZeroHypercover S} /-- Composition of refinement morphisms of pre-`0`-hypercovers. -/ @[simps] def Hom.comp (f : E.Hom F) (g : F.Hom G) : E.Hom G where s₀ := g.s₀ ∘ f.s₀ h₀ i := f.h₀ i ≫ g.h₀ _ @[simps! id_s₀ id_h₀ comp_s₀ comp_h₀] instance : Category (PreZeroHypercover S) where Hom := Hom id E := Hom.id E comp f g := f.comp g end Category end PreZeroHypercover namespace Coverage variable (J : Coverage C) /-- The type of `0`-hypercovers of an object `S : C` in a category equipped with a coverage `J`. This can be constructed from a covering of `S`. -/ structure ZeroHypercover (S : C) extends PreZeroHypercover.{w} S where mem₀ : toPreZeroHypercover.presieve₀ ∈ J S namespace ZeroHypercover variable {S T : C} /-- The `0`-hypercover defined by a single covering morphism. -/ @[simps toPreZeroHypercover] def singleton (f : S ⟶ T) (hf : Presieve.singleton f ∈ J T) : J.ZeroHypercover T where __ := PreZeroHypercover.singleton f mem₀ := by simpa [PreZeroHypercover.presieve₀, PreZeroHypercover.singleton, Presieve.ofArrows_pUnit] /-- Pullback of a `0`-hypercover along a morphism. The components are `pullback f (E.f i)`. -/ @[simps toPreZeroHypercover] noncomputable def pullback₁ [J.IsStableUnderBaseChange] [Limits.HasPullbacks C] (f : S ⟶ T) (E : ZeroHypercover.{w} J T) : J.ZeroHypercover S where __ := E.toPreZeroHypercover.pullback₁ f mem₀ := J.mem_covering_of_isPullback E.f E.mem₀ f _ (fun _ ↦ pullback.snd _ _) fun i ↦ IsPullback.of_hasPullback f (E.f i) /-- Pullback of a `0`-hypercover along a morphism. The components are `pullback (E.f i) f`. -/ @[simps toPreZeroHypercover] noncomputable def pullback₂ [J.IsStableUnderBaseChange] [Limits.HasPullbacks C] (f : S ⟶ T) (E : ZeroHypercover.{w} J T) : J.ZeroHypercover S where __ := E.toPreZeroHypercover.pullback₂ f mem₀ := J.mem_covering_of_isPullback E.f E.mem₀ f _ (fun _ ↦ pullback.fst _ _) fun i ↦ (IsPullback.of_hasPullback (E.f i) f).flip /-- Refining each component of a `0`-hypercover yields a refined `0`-hypercover of the base. -/ def bind [J.IsStableUnderComposition] (E : ZeroHypercover.{w} J T) (F : ∀ i, ZeroHypercover.{w'} J (E.X i)) : ZeroHypercover.{max w w'} J T where __ := E.toPreZeroHypercover.bind (fun i ↦ (F i).toPreZeroHypercover) mem₀ := mem_covering_comp (f := E.f) (g := fun i j ↦ (F i).f j) E.mem₀ (fun i ↦ (F i).mem₀) /-- A morphism of `0`-hypercovers is a morphism of the underlying pre-`0`-hypercovers. -/ abbrev Hom (E : ZeroHypercover.{w} J S) (F : ZeroHypercover.{w'} J S) := E.toPreZeroHypercover.Hom F.toPreZeroHypercover @[simps! id_s₀ id_h₀ comp_s₀ comp_h₀] instance : Category (ZeroHypercover.{w} J S) where Hom := Hom J id _ := PreZeroHypercover.Hom.id _ comp := PreZeroHypercover.Hom.comp end ZeroHypercover end Coverage end CategoryTheory
GeomSum.lean
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Ring.Opposite /-! # Partial sums of geometric series in a ring This file determines the values of the geometric series $\sum_{i=0}^{n-1} x^i$ and $\sum_{i=0}^{n-1} x^i y^{n-1-i}$ and variants thereof. Several variants are recorded, generalising in particular to the case of a noncommutative ring in which `x` and `y` commute. Even versions not using division or subtraction, valid in each semiring, are recorded. -/ assert_not_exists Field IsOrderedRing open Finset MulOpposite variable {R S : Type*} section Semiring variable [Semiring R] [Semiring S] {x y : R} lemma geom_sum_succ {x : R} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = (x * ∑ i ∈ range n, x ^ i) + 1 := by simp only [mul_sum, ← pow_succ', sum_range_succ', pow_zero] lemma geom_sum_succ' {x : R} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = x ^ n + ∑ i ∈ range n, x ^ i := (sum_range_succ _ _).trans (add_comm _ _) lemma geom_sum_zero (x : R) : ∑ i ∈ range 0, x ^ i = 0 := rfl lemma geom_sum_one (x : R) : ∑ i ∈ range 1, x ^ i = 1 := by simp @[simp] lemma geom_sum_two {x : R} : ∑ i ∈ range 2, x ^ i = x + 1 := by simp [geom_sum_succ'] @[simp] lemma zero_geom_sum : ∀ {n}, ∑ i ∈ range n, (0 : R) ^ i = if n = 0 then 0 else 1 | 0 => by simp | 1 => by simp | n + 2 => by rw [geom_sum_succ'] simp [zero_geom_sum] lemma one_geom_sum (n : ℕ) : ∑ i ∈ range n, (1 : R) ^ i = n := by simp lemma op_geom_sum (x : R) (n : ℕ) : op (∑ i ∈ range n, x ^ i) = ∑ i ∈ range n, op x ^ i := by simp @[simp] lemma op_geom_sum₂ (x y : R) (n : ℕ) : ∑ i ∈ range n, op y ^ (n - 1 - i) * op x ^ i = ∑ i ∈ range n, op y ^ i * op x ^ (n - 1 - i) := by rw [← sum_range_reflect] refine sum_congr rfl fun j j_in => ?_ grind lemma geom_sum₂_with_one (x : R) (n : ℕ) : ∑ i ∈ range n, x ^ i * 1 ^ (n - 1 - i) = ∑ i ∈ range n, x ^ i := sum_congr rfl fun i _ => by rw [one_pow, mul_one] /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ protected lemma Commute.geom_sum₂_mul_add {x y : R} (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := by let f : ℕ → ℕ → R := fun m i : ℕ => (x + y) ^ i * y ^ (m - 1 - i) change (∑ i ∈ range n, (f n) i) * x + y ^ n = (x + y) ^ n induction n with | zero => rw [range_zero, sum_empty, zero_mul, zero_add, pow_zero, pow_zero] | succ n ih => have f_last : f (n + 1) n = (x + y) ^ n := by dsimp only [f] rw [← tsub_add_eq_tsub_tsub, Nat.add_comm, tsub_self, pow_zero, mul_one] have f_succ : ∀ i, i ∈ range n → f (n + 1) i = y * f n i := fun i hi => by dsimp only [f] have : Commute y ((x + y) ^ i) := (h.symm.add_right (Commute.refl y)).pow_right i rw [← mul_assoc, this.eq, mul_assoc, ← pow_succ' y (n - 1 - i), add_tsub_cancel_right, ← tsub_add_eq_tsub_tsub, add_comm 1 i] have : i + 1 + (n - (i + 1)) = n := add_tsub_cancel_of_le (mem_range.mp hi) rw [add_comm (i + 1)] at this rw [← this, add_tsub_cancel_right, add_comm i 1, ← add_assoc, add_tsub_cancel_right] rw [pow_succ' (x + y), add_mul, sum_range_succ_comm, add_mul, f_last, add_assoc, (((Commute.refl x).add_right h).pow_right n).eq, sum_congr rfl f_succ, ← mul_sum, pow_succ' y, mul_assoc, ← mul_add y, ih] lemma geom_sum₂_self (x : R) (n : ℕ) : ∑ i ∈ range n, x ^ i * x ^ (n - 1 - i) = n * x ^ (n - 1) := calc ∑ i ∈ Finset.range n, x ^ i * x ^ (n - 1 - i) = ∑ i ∈ Finset.range n, x ^ (i + (n - 1 - i)) := by simp_rw [← pow_add] _ = ∑ _i ∈ Finset.range n, x ^ (n - 1) := Finset.sum_congr rfl fun _ hi => congr_arg _ <| add_tsub_cancel_of_le <| Nat.le_sub_one_of_lt <| Finset.mem_range.1 hi _ = #(range n) • x ^ (n - 1) := sum_const _ _ = n * x ^ (n - 1) := by rw [Finset.card_range, nsmul_eq_mul] lemma geom_sum_mul_add (x : R) (n : ℕ) : (∑ i ∈ range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n := by have := (Commute.one_right x).geom_sum₂_mul_add n rw [one_pow, geom_sum₂_with_one] at this exact this protected lemma Commute.geom_sum₂_comm (n : ℕ) (h : Commute x y) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = ∑ i ∈ range n, y ^ i * x ^ (n - 1 - i) := by cases n; · simp simp only [Nat.add_sub_cancel] rw [← Finset.sum_flip] refine Finset.sum_congr rfl fun i hi => ?_ simpa [Nat.sub_sub_self (Nat.succ_le_succ_iff.mp (Finset.mem_range.mp hi))] using h.pow_pow _ _ -- TODO: for consistency, the next two lemmas should be moved to the root namespace lemma RingHom.map_geom_sum (x : R) (n : ℕ) (f : R →+* S) : f (∑ i ∈ range n, x ^ i) = ∑ i ∈ range n, f x ^ i := by simp [map_sum f] lemma RingHom.map_geom_sum₂ (x y : R) (n : ℕ) (f : R →+* S) : f (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = ∑ i ∈ range n, f x ^ i * f y ^ (n - 1 - i) := by simp [map_sum f] end Semiring section CommSemiring variable [CommSemiring R] /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ lemma geom_sum₂_mul_add (x y : R) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := (Commute.all x y).geom_sum₂_mul_add n lemma geom_sum₂_comm (x y : R) (n : ℕ) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = ∑ i ∈ range n, y ^ i * x ^ (n - 1 - i) := (Commute.all x y).geom_sum₂_comm n variable [PartialOrder R] [AddLeftReflectLE R] [AddLeftMono R] [ExistsAddOfLE R] [Sub R] [OrderedSub R] {x y : R} lemma geom_sum₂_mul_of_ge (hxy : y ≤ x) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by apply eq_tsub_of_add_eq simpa only [tsub_add_cancel_of_le hxy] using geom_sum₂_mul_add (x - y) y n lemma geom_sum₂_mul_of_le (hxy : x ≤ y) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (y - x) = y ^ n - x ^ n := by rw [← Finset.sum_range_reflect] convert geom_sum₂_mul_of_ge hxy n using 3 simp_all only [Finset.mem_range] rw [mul_comm] congr omega lemma geom_sum_mul_of_one_le (hx : 1 ≤ x) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (x - 1) = x ^ n - 1 := by simpa using geom_sum₂_mul_of_ge hx n lemma geom_sum_mul_of_le_one (hx : x ≤ 1) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (1 - x) = 1 - x ^ n := by simpa using geom_sum₂_mul_of_le hx n end CommSemiring section Ring variable [Ring R] {x y : R} @[simp] lemma neg_one_geom_sum {n : ℕ} : ∑ i ∈ range n, (-1 : R) ^ i = if Even n then 0 else 1 := by induction n with | zero => simp | succ k hk => simp only [geom_sum_succ', Nat.even_add_one, hk] split_ifs with h · rw [h.neg_one_pow, add_zero] · rw [(Nat.not_even_iff_odd.1 h).neg_one_pow, neg_add_cancel] protected lemma Commute.geom_sum₂_mul (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by have := (h.sub_left (Commute.refl y)).geom_sum₂_mul_add n rw [sub_add_cancel] at this rw [← this, add_sub_cancel_right] lemma Commute.mul_neg_geom_sum₂ (h : Commute x y) (n : ℕ) : ((y - x) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = y ^ n - x ^ n := by apply op_injective simp only [op_mul, op_sub, op_pow] simp [(Commute.op h.symm).geom_sum₂_mul n] lemma Commute.mul_geom_sum₂ (h : Commute x y) (n : ℕ) : ((x - y) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = x ^ n - y ^ n := by rw [← neg_sub (y ^ n), ← h.mul_neg_geom_sum₂, ← neg_mul, neg_sub] lemma Commute.sub_dvd_pow_sub_pow (h : Commute x y) (n : ℕ) : x - y ∣ x ^ n - y ^ n := Dvd.intro _ <| h.mul_geom_sum₂ _ lemma one_sub_dvd_one_sub_pow (x : R) (n : ℕ) : 1 - x ∣ 1 - x ^ n := by conv_rhs => rw [← one_pow n] exact (Commute.one_left x).sub_dvd_pow_sub_pow n lemma sub_one_dvd_pow_sub_one (x : R) (n : ℕ) : x - 1 ∣ x ^ n - 1 := by conv_rhs => rw [← one_pow n] exact (Commute.one_right x).sub_dvd_pow_sub_pow n lemma pow_one_sub_dvd_pow_mul_sub_one (x : R) (m n : ℕ) : x ^ m - 1 ∣ x ^ (m * n) - 1 := by rw [pow_mul]; exact sub_one_dvd_pow_sub_one (x ^ m) n lemma geom_sum_mul (x : R) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (x - 1) = x ^ n - 1 := by have := (Commute.one_right x).geom_sum₂_mul n rw [one_pow, geom_sum₂_with_one] at this exact this lemma mul_geom_sum (x : R) (n : ℕ) : ((x - 1) * ∑ i ∈ range n, x ^ i) = x ^ n - 1 := op_injective <| by simpa using geom_sum_mul (op x) n lemma geom_sum_mul_neg (x : R) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (1 - x) = 1 - x ^ n := by have := congr_arg Neg.neg (geom_sum_mul x n) rw [neg_sub, ← mul_neg, neg_sub] at this exact this lemma mul_neg_geom_sum (x : R) (n : ℕ) : ((1 - x) * ∑ i ∈ range n, x ^ i) = 1 - x ^ n := op_injective <| by simpa using geom_sum_mul_neg (op x) n protected lemma Commute.mul_geom_sum₂_Ico (h : Commute x y) {m n : ℕ} (hmn : m ≤ n) : ((x - y) * ∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = x ^ n - x ^ m * y ^ (n - m) := by rw [sum_Ico_eq_sub _ hmn] have : ∑ k ∈ range m, x ^ k * y ^ (n - 1 - k) = ∑ k ∈ range m, x ^ k * (y ^ (n - m) * y ^ (m - 1 - k)) := by refine sum_congr rfl fun j j_in => ?_ rw [← pow_add] congr rw [mem_range] at j_in omega rw [this] simp_rw [pow_mul_comm y (n - m) _] simp_rw [← mul_assoc] rw [← sum_mul, mul_sub, h.mul_geom_sum₂, ← mul_assoc, h.mul_geom_sum₂, sub_mul, ← pow_add, add_tsub_cancel_of_le hmn, sub_sub_sub_cancel_right (x ^ n) (x ^ m * y ^ (n - m)) (y ^ n)] protected lemma Commute.geom_sum₂_succ_eq (h : Commute x y) {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i * y ^ (n - i) = x ^ n + y * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := by simp_rw [mul_sum, sum_range_succ_comm, tsub_self, pow_zero, mul_one, add_right_inj, ← mul_assoc, (h.symm.pow_right _).eq, mul_assoc, ← pow_succ'] refine sum_congr rfl fun i hi => ?_ suffices n - 1 - i + 1 = n - i by rw [this] rw [Finset.mem_range] at hi omega protected lemma Commute.geom_sum₂_Ico_mul (h : Commute x y) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ (n - m) * x ^ m := by apply op_injective simp only [op_sub, op_mul, op_pow, op_sum] have : (∑ k ∈ Ico m n, MulOpposite.op y ^ (n - 1 - k) * MulOpposite.op x ^ k) = ∑ k ∈ Ico m n, MulOpposite.op x ^ k * MulOpposite.op y ^ (n - 1 - k) := by refine sum_congr rfl fun k _ => ?_ have hp := Commute.pow_pow (Commute.op h.symm) (n - 1 - k) k simpa [Commute, SemiconjBy] using hp simp only [this] convert (Commute.op h).mul_geom_sum₂_Ico hmn lemma geom_sum_Ico_mul (x : R) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i) * (x - 1) = x ^ n - x ^ m := by rw [sum_Ico_eq_sub _ hmn, sub_mul, geom_sum_mul, geom_sum_mul, sub_sub_sub_cancel_right] lemma geom_sum_Ico_mul_neg (x : R) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i) * (1 - x) = x ^ m - x ^ n := by rw [sum_Ico_eq_sub _ hmn, sub_mul, geom_sum_mul_neg, geom_sum_mul_neg, sub_sub_sub_cancel_left] end Ring section CommRing variable [CommRing R] lemma geom_sum₂_mul (x y : R) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := (Commute.all x y).geom_sum₂_mul n lemma sub_dvd_pow_sub_pow (x y : R) (n : ℕ) : x - y ∣ x ^ n - y ^ n := (Commute.all x y).sub_dvd_pow_sub_pow n lemma Odd.add_dvd_pow_add_pow (x y : R) {n : ℕ} (h : Odd n) : x + y ∣ x ^ n + y ^ n := by have h₁ := geom_sum₂_mul x (-y) n rw [Odd.neg_pow h y, sub_neg_eq_add, sub_neg_eq_add] at h₁ exact Dvd.intro_left _ h₁ lemma geom_sum₂_succ_eq (x y : R) {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i * y ^ (n - i) = x ^ n + y * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := (Commute.all x y).geom_sum₂_succ_eq lemma mul_geom_sum₂_Ico (x y : R) {m n : ℕ} (hmn : m ≤ n) : ((x - y) * ∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = x ^ n - x ^ m * y ^ (n - m) := (Commute.all x y).mul_geom_sum₂_Ico hmn end CommRing lemma nat_sub_dvd_pow_sub_pow (x y n : ℕ) : x - y ∣ x ^ n - y ^ n := by rcases le_or_gt y x with h | h · have : y ^ n ≤ x ^ n := Nat.pow_le_pow_left h _ exact mod_cast sub_dvd_pow_sub_pow (x : ℤ) (↑y) n · have : x ^ n ≤ y ^ n := Nat.pow_le_pow_left h.le _ exact (Nat.sub_eq_zero_of_le this).symm ▸ dvd_zero (x - y) lemma nat_pow_one_sub_dvd_pow_mul_sub_one (x m n : ℕ) : x ^ m - 1 ∣ x ^ (m * n) - 1 := by nth_rw 2 [← Nat.one_pow n] rw [Nat.pow_mul x m n] apply nat_sub_dvd_pow_sub_pow (x ^ m) 1 lemma Odd.nat_add_dvd_pow_add_pow (x y : ℕ) {n : ℕ} (h : Odd n) : x + y ∣ x ^ n + y ^ n := mod_cast Odd.add_dvd_pow_add_pow (x : ℤ) (↑y) h /-- Value of a geometric sum over the naturals. Note: see `geom_sum_mul_add` for a formulation that avoids division and subtraction. -/ lemma Nat.geomSum_eq {m : ℕ} (hm : 2 ≤ m) (n : ℕ) : ∑ k ∈ range n, m ^ k = (m ^ n - 1) / (m - 1) := by refine (Nat.div_eq_of_eq_mul_left (tsub_pos_iff_lt.2 hm) <| tsub_eq_of_eq_add ?_).symm simpa only [tsub_add_cancel_of_le (by omega : 1 ≤ m), eq_comm] using geom_sum_mul_add (m - 1) n
poly.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice. From mathcomp Require Import fintype bigop finset tuple div ssralg. From mathcomp Require Import countalg binomial. (******************************************************************************) (* This file provides a library for univariate polynomials over ring *) (* structures; it also provides an extended theory for polynomials whose *) (* coefficients range over commutative rings and integral domains. *) (* *) (* {poly R} == the type of polynomials with coefficients of type R, *) (* represented as lists with a non zero last element *) (* (big endian representation); the coefficient type R *) (* must have a canonical nzRingType structure cR. In *) (* fact {poly R} denotes the concrete type polynomial *) (* cR; R is just a phantom argument that lets type *) (* inferencereconstruct the (hidden) nzRingType *) (* structure cR. *) (* p : seq R == the big-endian sequence of coefficients of p, via *) (* the coercion polyseq : polynomial >-> seq. *) (* Poly s == the polynomial with coefficient sequence s (ignoring *) (* trailing zeroes). *) (* \poly_(i < n) E(i) == the polynomial of degree at most n - 1 whose *) (* coefficients are given by the general term E(i) *) (* 0, 1, - p, p + q, == the usual ring operations: {poly R} has a canonical *) (* p * q, p ^+ n, ... nzRingType structure, which is commutative / integral*) (* when R is commutative / integral, respectively. *) (* polyC c, c%:P == the constant polynomial c *) (* 'X == the (unique) variable *) (* 'X^n == a power of 'X; 'X^0 is 1, 'X^1 is convertible to 'X *) (* p`_i == the coefficient of 'X^i in p; this is in fact just *) (* the ring_scope notation generic seq-indexing using *) (* nth 0%R, combined with the polyseq coercion. *) (* *** The multi-rule coefE simplifies p`_i *) (* coefp i == the linear function p |-> p`_i (self-exapanding). *) (* size p == 1 + the degree of p, or 0 if p = 0 (this is the *) (* generic seq function combined with polyseq). *) (* lead_coef p == the coefficient of the highest monomial in p, or 0 *) (* if p = 0 (hence lead_coef p = 0 iff p = 0) *) (* p \is monic <=> lead_coef p == 1 (0 is not monic). *) (* p \is a polyOver S <=> the coefficients of p satisfy S; S should have a *) (* key that should be (at least) an addrPred. *) (* p.[x] == the evaluation of a polynomial p at a point x using *) (* the Horner scheme *) (* *** The multi-rule hornerE (resp., hornerE_comm) unwinds *) (* horner evaluation of a polynomial expression (resp., *) (* in a non commutative ring, with side conditions). *) (* p^`() == formal derivative of p *) (* p^`(n) == formal n-derivative of p *) (* p^`N(n) == formal n-derivative of p divided by n! *) (* p \Po q == polynomial composition; because this is naturally a *) (* a linear morphism in the first argument, this *) (* notation is transposed (q comes before p for redex *) (* selection, etc). *) (* := \sum(i < size p) p`_i *: q ^+ i *) (* odd_poly p == monomials of odd degree of p *) (* even_poly p == monomials of even degree of p *) (* take_poly n p == polynomial p without its monomials of degree >= n *) (* drop_poly n p == polynomial p divided by X^n *) (* comm_poly p x == x and p.[x] commute; this is a sufficient condition *) (* for evaluating (q * p).[x] as q.[x] * p.[x] when R *) (* is not commutative. *) (* comm_coef p x == x commutes with all the coefficients of p (clearly, *) (* this implies comm_poly p x). *) (* root p x == x is a root of p, i.e., p.[x] = 0 *) (* n.-unity_root x == x is an nth root of unity, i.e., a root of 'X^n - 1 *) (* n.-primitive_root x == x is a primitive nth root of unity, i.e., n is the *) (* least positive integer m > 0 such that x ^+ m = 1. *) (* *** The submodule poly.UnityRootTheory can be used to *) (* import selectively the part of the theory of roots *) (* of unity that doesn't mention polynomials explicitly *) (* map_poly f p == the image of the polynomial by the function f (which *) (* (locally, p^f) is usually a ring morphism). *) (* p^:P == p lifted to {poly {poly R}} (:= map_poly polyC p). *) (* commr_rmorph f u == u commutes with the image of f (i.e., with all f x). *) (* horner_morph cfu == given cfu : commr_rmorph f u, the function mapping p *) (* to the value of map_poly f p at u; this is a ring *) (* morphism from {poly R} to the codomain of f when f *) (* is a ring morphism. *) (* horner_eval u == the function mapping p to p.[u]; this function can *) (* only be used for u in a commutative ring, so it is *) (* always a linear ring morphism from {poly R} to R. *) (* horner_alg a == given a in some R-algebra A, the function evaluating *) (* a polynomial p at a; it is always a linear ring *) (* morphism from {poly R} to A. *) (* diff_roots x y == x and y are distinct roots; if R is a field, this *) (* just means x != y, but this concept is generalized *) (* to the case where R is only a ring with units (i.e., *) (* a unitRingType); in which case it means that x and y *) (* commute, and that the difference x - y is a unit *) (* (i.e., has a multiplicative inverse) in R. *) (* to just x != y). *) (* uniq_roots s == s is a sequence or pairwise distinct roots, in the *) (* sense of diff_roots p above. *) (* *** We only show that these operations and properties are transferred by *) (* morphisms whose domain is a field (thus ensuring injectivity). *) (* We prove the factor_theorem, and the max_poly_roots inequality relating *) (* the number of distinct roots of a polynomial and its size. *) (* The some polynomial lemmas use following suffix interpretation : *) (* C - constant polynomial (as in polyseqC : a%:P = nseq (a != 0) a). *) (* X - the polynomial variable 'X (as in coefX : 'X`_i = (i == 1%N)). *) (* Xn - power of 'X (as in monicXn : monic 'X^n). *) (* *) (* Pdeg2.Field (exported by the present library) : theory of the degree 2 *) (* polynomials. *) (* Pdeg2.FieldMonic : theory of Pdeg2.Field specialized to monic polynomials. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope unity_root_scope. Import GRing.Theory. Local Open Scope ring_scope. Reserved Notation "{ 'poly' T }" (format "{ 'poly' T }"). Reserved Notation "c %:P" (format "c %:P"). Reserved Notation "p ^:P" (format "p ^:P"). Reserved Notation "'X". Reserved Notation "''X^' n" (at level 1, format "''X^' n"). Reserved Notation "\poly_ ( i < n ) E" (at level 34, E at level 36, i, n at level 50, format "\poly_ ( i < n ) E"). Reserved Notation "p \Po q" (at level 50). Reserved Notation "p ^`N ( n )" (format "p ^`N ( n )"). Reserved Notation "n .-unity_root" (format "n .-unity_root"). Reserved Notation "n .-primitive_root" (format "n .-primitive_root"). Local Notation simp := Monoid.simpm. Section Polynomial. Variable R : nzSemiRingType. (* Defines a polynomial as a sequence with <> 0 last element *) Record polynomial := Polynomial {polyseq :> seq R; _ : last 1 polyseq != 0}. HB.instance Definition _ := [isSub for polyseq]. HB.instance Definition _ := [Choice of polynomial by <:]. Lemma poly_inj : injective polyseq. Proof. exact: val_inj. Qed. Definition coefp i (p : polynomial) := p`_i. End Polynomial. (* We need to break off the section here to let the Bind Scope directives *) (* take effect. *) Bind Scope ring_scope with polynomial. Arguments polynomial R%_type. Arguments polyseq {R} p%_R. Arguments poly_inj {R} [p1%_R p2%_R] : rename. Arguments coefp {R} i%_N / p%_R. Notation "{ 'poly' T }" := (polynomial T) : type_scope. Section SemiPolynomialTheory. Variable R : nzSemiRingType. Implicit Types (a b c x y z : R) (p q r d : {poly R}). Definition lead_coef p := p`_(size p).-1. Lemma lead_coefE p : lead_coef p = p`_(size p).-1. Proof. by []. Qed. Definition poly_nil := @Polynomial R [::] (oner_neq0 R). Definition polyC c : {poly R} := insubd poly_nil [:: c]. Local Notation "c %:P" := (polyC c). (* Remember the boolean (c != 0) is coerced to 1 if true and 0 if false *) Lemma polyseqC c : c%:P = nseq (c != 0) c :> seq R. Proof. by rewrite val_insubd /=; case: (c == 0). Qed. Lemma size_polyC c : size c%:P = (c != 0). Proof. by rewrite polyseqC size_nseq. Qed. Lemma coefC c i : c%:P`_i = if i == 0 then c else 0. Proof. by rewrite polyseqC; case: i => [|[]]; case: eqP. Qed. Lemma polyCK : cancel polyC (coefp 0). Proof. by move=> c; rewrite [coefp 0 _]coefC. Qed. Lemma polyC_inj : injective polyC. Proof. by move=> c1 c2 eqc12; have:= coefC c2 0; rewrite -eqc12 coefC. Qed. Lemma lead_coefC c : lead_coef c%:P = c. Proof. by rewrite /lead_coef polyseqC; case: eqP. Qed. (* Extensional interpretation (poly <=> nat -> R) *) Lemma polyP p q : nth 0 p =1 nth 0 q <-> p = q. Proof. split=> [eq_pq | -> //]; apply: poly_inj. without loss lt_pq: p q eq_pq / size p < size q. move=> IH; case: (ltngtP (size p) (size q)); try by move/IH->. by move/(@eq_from_nth _ 0); apply. case: q => q nz_q /= in lt_pq eq_pq *; case/eqP: nz_q. by rewrite (last_nth 0) -(subnKC lt_pq) /= -eq_pq nth_default ?leq_addr. Qed. Lemma size1_polyC p : size p <= 1 -> p = (p`_0)%:P. Proof. move=> le_p_1; apply/polyP=> i; rewrite coefC. by case: i => // i; rewrite nth_default // (leq_trans le_p_1). Qed. (* Builds a polynomial by extension. *) Definition cons_poly c p : {poly R} := if p is Polynomial ((_ :: _) as s) ns then @Polynomial R (c :: s) ns else c%:P. Lemma polyseq_cons c p : cons_poly c p = (if ~~ nilp p then c :: p else c%:P) :> seq R. Proof. by case: p => [[]]. Qed. Lemma size_cons_poly c p : size (cons_poly c p) = (if nilp p && (c == 0) then 0 else (size p).+1). Proof. by case: p => [[|c' s] _] //=; rewrite size_polyC; case: eqP. Qed. Lemma coef_cons c p i : (cons_poly c p)`_i = if i == 0 then c else p`_i.-1. Proof. by case: p i => [[|c' s] _] [] //=; rewrite polyseqC; case: eqP => //= _ []. Qed. (* Build a polynomial directly from a list of coefficients. *) Definition Poly := foldr cons_poly 0%:P. Lemma PolyK c s : last c s != 0 -> Poly s = s :> seq R. Proof. case: s => {c}/= [_ |c s]; first by rewrite polyseqC eqxx. elim: s c => /= [|a s IHs] c nz_c; rewrite polyseq_cons ?{}IHs //. by rewrite !polyseqC !eqxx nz_c. Qed. Lemma polyseqK p : Poly p = p. Proof. by apply: poly_inj; apply: PolyK (valP p). Qed. Lemma size_Poly s : size (Poly s) <= size s. Proof. elim: s => [|c s IHs] /=; first by rewrite polyseqC eqxx. by rewrite polyseq_cons; case: ifP => // _; rewrite size_polyC; case: (~~ _). Qed. Lemma coef_Poly s i : (Poly s)`_i = s`_i. Proof. by elim: s i => [|c s IHs] /= [|i]; rewrite !(coefC, eqxx, coef_cons) /=. Qed. (* Build a polynomial from an infinite sequence of coefficients and a bound. *) Definition poly_expanded_def n E := Poly (mkseq E n). Fact poly_key : unit. Proof. by []. Qed. Definition poly := locked_with poly_key poly_expanded_def. Canonical poly_unlockable := [unlockable fun poly]. Local Notation "\poly_ ( i < n ) E" := (poly n (fun i : nat => E)). Lemma polyseq_poly n E : E n.-1 != 0 -> \poly_(i < n) E i = mkseq [eta E] n :> seq R. Proof. rewrite unlock; case: n => [|n] nzEn; first by rewrite polyseqC eqxx. by rewrite (@PolyK 0) // -nth_last nth_mkseq size_mkseq. Qed. Lemma size_poly n E : size (\poly_(i < n) E i) <= n. Proof. by rewrite unlock (leq_trans (size_Poly _)) ?size_mkseq. Qed. Lemma size_poly_eq n E : E n.-1 != 0 -> size (\poly_(i < n) E i) = n. Proof. by move/polyseq_poly->; apply: size_mkseq. Qed. Lemma coef_poly n E k : (\poly_(i < n) E i)`_k = (if k < n then E k else 0). Proof. rewrite unlock coef_Poly. have [lt_kn | le_nk] := ltnP k n; first by rewrite nth_mkseq. by rewrite nth_default // size_mkseq. Qed. Lemma lead_coef_poly n E : n > 0 -> E n.-1 != 0 -> lead_coef (\poly_(i < n) E i) = E n.-1. Proof. by case: n => // n _ nzE; rewrite /lead_coef size_poly_eq // coef_poly leqnn. Qed. Lemma coefK p : \poly_(i < size p) p`_i = p. Proof. by apply/polyP=> i; rewrite coef_poly; case: ltnP => // /(nth_default 0)->. Qed. (* Nmodule structure for polynomial *) Definition add_poly_def p q := \poly_(i < maxn (size p) (size q)) (p`_i + q`_i). Fact add_poly_key : unit. Proof. by []. Qed. Definition add_poly := locked_with add_poly_key add_poly_def. Canonical add_poly_unlockable := [unlockable fun add_poly]. Fact coef_add_poly p q i : (add_poly p q)`_i = p`_i + q`_i. Proof. rewrite unlock coef_poly; case: leqP => //. by rewrite geq_max => /andP[le_p_i le_q_i]; rewrite !nth_default ?add0r. Qed. Fact add_polyA : associative add_poly. Proof. by move=> p q r; apply/polyP=> i; rewrite !coef_add_poly addrA. Qed. Fact add_polyC : commutative add_poly. Proof. by move=> p q; apply/polyP=> i; rewrite !coef_add_poly addrC. Qed. Fact add_poly0 : left_id 0%:P add_poly. Proof. by move=> p; apply/polyP=> i; rewrite coef_add_poly coefC if_same add0r. Qed. HB.instance Definition _ := GRing.isNmodule.Build (polynomial R) add_polyA add_polyC add_poly0. (* Properties of the zero polynomial *) Lemma polyC0 : 0%:P = 0 :> {poly R}. Proof. by []. Qed. Lemma polyseq0 : (0 : {poly R}) = [::] :> seq R. Proof. by rewrite polyseqC eqxx. Qed. Lemma size_poly0 : size (0 : {poly R}) = 0%N. Proof. by rewrite polyseq0. Qed. Lemma coef0 i : (0 : {poly R})`_i = 0. Proof. by rewrite coefC if_same. Qed. Lemma lead_coef0 : lead_coef 0 = 0 :> R. Proof. exact: lead_coefC. Qed. Lemma size_poly_eq0 p : (size p == 0) = (p == 0). Proof. by rewrite size_eq0 -polyseq0. Qed. Lemma size_poly_leq0 p : (size p <= 0) = (p == 0). Proof. by rewrite leqn0 size_poly_eq0. Qed. Lemma size_poly_leq0P p : reflect (p = 0) (size p <= 0). Proof. by apply: (iffP idP); rewrite size_poly_leq0; move/eqP. Qed. Lemma size_poly_gt0 p : (0 < size p) = (p != 0). Proof. by rewrite lt0n size_poly_eq0. Qed. Lemma gt_size_poly_neq0 p n : (size p > n)%N -> p != 0. Proof. by move=> /(leq_ltn_trans _) h; rewrite -size_poly_eq0 lt0n_neq0 ?h. Qed. Lemma nil_poly p : nilp p = (p == 0). Proof. exact: size_poly_eq0. Qed. Lemma poly0Vpos p : {p = 0} + {size p > 0}. Proof. by rewrite lt0n size_poly_eq0; case: eqVneq; [left | right]. Qed. Lemma polySpred p : p != 0 -> size p = (size p).-1.+1. Proof. by rewrite -size_poly_eq0 -lt0n => /prednK. Qed. Lemma lead_coef_eq0 p : (lead_coef p == 0) = (p == 0). Proof. rewrite -nil_poly /lead_coef nth_last. by case: p => [[|x s] /= /negbTE // _]; rewrite eqxx. Qed. Lemma polyC_eq0 (c : R) : (c%:P == 0) = (c == 0). Proof. by rewrite -nil_poly polyseqC; case: (c == 0). Qed. Lemma size_poly1P p : reflect (exists2 c, c != 0 & p = c%:P) (size p == 1). Proof. apply: (iffP eqP) => [pC | [c nz_c ->]]; last by rewrite size_polyC nz_c. have def_p: p = (p`_0)%:P by rewrite -size1_polyC ?pC. by exists p`_0; rewrite // -polyC_eq0 -def_p -size_poly_eq0 pC. Qed. Lemma size_polyC_leq1 (c : R) : (size c%:P <= 1)%N. Proof. by rewrite size_polyC; case: (c == 0). Qed. Lemma leq_sizeP p i : reflect (forall j, i <= j -> p`_j = 0) (size p <= i). Proof. apply: (iffP idP) => [hp j hij| hp]. by apply: nth_default; apply: leq_trans hij. case: (eqVneq p) (lead_coef_eq0 p) => [->|p0]; first by rewrite size_poly0. rewrite leqNgt; apply/contraFN => hs. by apply/eqP/hp; rewrite -ltnS (ltn_predK hs). Qed. (* Size, leading coef, morphism properties of coef *) Lemma coefD p q i : (p + q)`_i = p`_i + q`_i. Proof. exact: coef_add_poly. Qed. Lemma polyCD : {morph polyC : a b / a + b}. Proof. by move=> a b; apply/polyP=> [[|i]]; rewrite coefD !coefC ?addr0. Qed. Lemma size_polyD p q : size (p + q) <= maxn (size p) (size q). Proof. by rewrite -[+%R]/add_poly unlock; exact: size_poly. Qed. Lemma size_polyDl p q : size p > size q -> size (p + q) = size p. Proof. move=> ltqp; rewrite -[+%R]/add_poly unlock size_poly_eq (maxn_idPl (ltnW _))//. by rewrite addrC nth_default ?simp ?nth_last //; case: p ltqp => [[]]. Qed. Lemma size_sum I (r : seq I) (P : pred I) (F : I -> {poly R}) : size (\sum_(i <- r | P i) F i) <= \max_(i <- r | P i) size (F i). Proof. elim/big_rec2: _ => [|i p q _ IHp]; first by rewrite size_poly0. by rewrite -(maxn_idPr IHp) maxnA leq_max size_polyD. Qed. Lemma lead_coefDl p q : size p > size q -> lead_coef (p + q) = lead_coef p. Proof. move=> ltqp; rewrite /lead_coef coefD size_polyDl //. by rewrite addrC nth_default ?simp // -ltnS (ltn_predK ltqp). Qed. Lemma lead_coefDr p q : size q > size p -> lead_coef (p + q) = lead_coef q. Proof. by move/lead_coefDl<-; rewrite addrC. Qed. (* Polynomial semiring structure. *) Definition mul_poly_def p q := \poly_(i < (size p + size q).-1) (\sum_(j < i.+1) p`_j * q`_(i - j)). Fact mul_poly_key : unit. Proof. by []. Qed. Definition mul_poly := locked_with mul_poly_key mul_poly_def. Canonical mul_poly_unlockable := [unlockable fun mul_poly]. Fact coef_mul_poly p q i : (mul_poly p q)`_i = \sum_(j < i.+1) p`_j * q`_(i - j)%N. Proof. rewrite unlock coef_poly -subn1 ltn_subRL add1n; case: leqP => // le_pq_i1. rewrite big1 // => j _; have [lq_q_ij | gt_q_ij] := leqP (size q) (i - j). by rewrite [q`__]nth_default ?mulr0. rewrite nth_default ?mul0r // -(leq_add2r (size q)) (leq_trans le_pq_i1) //. by rewrite -leq_subLR -subnSK. Qed. Fact coef_mul_poly_rev p q i : (mul_poly p q)`_i = \sum_(j < i.+1) p`_(i - j)%N * q`_j. Proof. rewrite coef_mul_poly (reindex_inj rev_ord_inj) /=. by apply: eq_bigr => j _; rewrite (sub_ordK j). Qed. Fact mul_polyA : associative mul_poly. Proof. move=> p q r; apply/polyP=> i; rewrite coef_mul_poly coef_mul_poly_rev. pose coef3 j k := p`_j * (q`_(i - j - k)%N * r`_k). transitivity (\sum_(j < i.+1) \sum_(k < i.+1 | k <= i - j) coef3 j k). apply: eq_bigr => /= j _; rewrite coef_mul_poly_rev big_distrr /=. by rewrite (big_ord_narrow_leq (leq_subr _ _)). rewrite (exchange_big_dep predT) //=; apply: eq_bigr => k _. transitivity (\sum_(j < i.+1 | j <= i - k) coef3 j k). apply: eq_bigl => j; rewrite -ltnS -(ltnS j) -!subSn ?leq_ord //. by rewrite -subn_gt0 -(subn_gt0 j) -!subnDA addnC. rewrite (big_ord_narrow_leq (leq_subr _ _)) coef_mul_poly big_distrl /=. by apply: eq_bigr => j _; rewrite /coef3 -!subnDA addnC mulrA. Qed. Fact mul_1poly : left_id 1%:P mul_poly. Proof. move=> p; apply/polyP => i; rewrite coef_mul_poly big_ord_recl subn0. by rewrite big1 => [|j _]; rewrite coefC !simp. Qed. Fact mul_poly1 : right_id 1%:P mul_poly. Proof. move=> p; apply/polyP => i; rewrite coef_mul_poly_rev big_ord_recl subn0. by rewrite big1 => [|j _]; rewrite coefC !simp. Qed. Fact mul_polyDl : left_distributive mul_poly +%R. Proof. move=> p q r; apply/polyP=> i; rewrite coefD !coef_mul_poly -big_split. by apply: eq_bigr => j _; rewrite coefD mulrDl. Qed. Fact mul_polyDr : right_distributive mul_poly +%R. Proof. move=> p q r; apply/polyP=> i; rewrite coefD !coef_mul_poly -big_split. by apply: eq_bigr => j _; rewrite coefD mulrDr. Qed. Fact mul_0poly : left_zero 0%:P mul_poly. Proof. move=> p; apply/polyP => i; rewrite coef_mul_poly big_ord_recl subn0. by rewrite big1 => [|j _]; rewrite coefC !simp // coefC; case: ifP. Qed. Fact mul_poly0 : right_zero 0%:P mul_poly. Proof. move=> p; apply/polyP => i; rewrite coef_mul_poly_rev big_ord_recl subn0. by rewrite big1 => [|j _]; rewrite coefC !simp // coefC; case: ifP. Qed. Fact poly1_neq0 : 1%:P != 0 :> {poly R}. Proof. by rewrite polyC_eq0 oner_neq0. Qed. HB.instance Definition _ := GRing.Nmodule_isNzSemiRing.Build (polynomial R) mul_polyA mul_1poly mul_poly1 mul_polyDl mul_polyDr mul_0poly mul_poly0 poly1_neq0. Lemma polyC1 : 1%:P = 1 :> {poly R}. Proof. by []. Qed. Lemma polyseq1 : (1 : {poly R}) = [:: 1] :> seq R. Proof. by rewrite polyseqC oner_neq0. Qed. Lemma size_poly1 : size (1 : {poly R}) = 1. Proof. by rewrite polyseq1. Qed. Lemma coef1 i : (1 : {poly R})`_i = (i == 0)%:R. Proof. by case: i => [|i]; rewrite polyseq1 /= ?nth_nil. Qed. Lemma lead_coef1 : lead_coef 1 = 1 :> R. Proof. exact: lead_coefC. Qed. Lemma coefM p q i : (p * q)`_i = \sum_(j < i.+1) p`_j * q`_(i - j)%N. Proof. exact: coef_mul_poly. Qed. Lemma coefMr p q i : (p * q)`_i = \sum_(j < i.+1) p`_(i - j)%N * q`_j. Proof. exact: coef_mul_poly_rev. Qed. Lemma coef0M p q : (p * q)`_0 = p`_0 * q`_0. Proof. by rewrite coefM big_ord1. Qed. Lemma coef0_prod I rI (F : I -> {poly R}) P : (\prod_(i <- rI| P i) F i)`_0 = \prod_(i <- rI | P i) (F i)`_0. Proof. by apply: (big_morph _ coef0M); rewrite coef1 eqxx. Qed. Lemma size_polyMleq p q : size (p * q) <= (size p + size q).-1. Proof. by rewrite -[*%R]/mul_poly unlock size_poly. Qed. Lemma mul_lead_coef p q : lead_coef p * lead_coef q = (p * q)`_(size p + size q).-2. Proof. pose dp := (size p).-1; pose dq := (size q).-1. have [-> | nz_p] := eqVneq p 0; first by rewrite lead_coef0 !mul0r coef0. have [-> | nz_q] := eqVneq q 0; first by rewrite lead_coef0 !mulr0 coef0. have ->: (size p + size q).-2 = (dp + dq)%N. by do 2!rewrite polySpred // addSn addnC. have lt_p_pq: dp < (dp + dq).+1 by rewrite ltnS leq_addr. rewrite coefM (bigD1 (Ordinal lt_p_pq)) ?big1 ?simp ?addKn //= => i. rewrite -val_eqE neq_ltn /= => /orP[lt_i_p | gt_i_p]; last first. by rewrite nth_default ?mul0r //; rewrite -polySpred in gt_i_p. rewrite [q`__]nth_default ?mulr0 //= -subSS -{1}addnS -polySpred //. by rewrite addnC -addnBA ?leq_addr. Qed. Lemma size_proper_mul p q : lead_coef p * lead_coef q != 0 -> size (p * q) = (size p + size q).-1. Proof. apply: contraNeq; rewrite mul_lead_coef eqn_leq size_polyMleq -ltnNge => lt_pq. by rewrite nth_default // -subn1 -(leq_add2l 1) -leq_subLR leq_sub2r. Qed. Lemma lead_coef_proper_mul p q : let c := lead_coef p * lead_coef q in c != 0 -> lead_coef (p * q) = c. Proof. by move=> /= nz_c; rewrite mul_lead_coef -size_proper_mul. Qed. Lemma size_poly_prod_leq (I : finType) (P : pred I) (F : I -> {poly R}) : size (\prod_(i | P i) F i) <= (\sum_(i | P i) size (F i)).+1 - #|P|. Proof. rewrite -sum1_card. elim/big_rec3: _ => [|i n m p _ IHp]; first by rewrite size_poly1. have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 size_poly0. rewrite (leq_trans (size_polyMleq _ _)) // subnS -!subn1 leq_sub2r //. rewrite -addnS -addnBA ?leq_add2l // ltnW // -subn_gt0 (leq_trans _ IHp) //. by rewrite polySpred. Qed. Lemma coefCM c p i : (c%:P * p)`_i = c * p`_i. Proof. rewrite coefM big_ord_recl subn0. by rewrite big1 => [|j _]; rewrite coefC !simp. Qed. Lemma coefMC c p i : (p * c%:P)`_i = p`_i * c. Proof. rewrite coefMr big_ord_recl subn0. by rewrite big1 => [|j _]; rewrite coefC !simp. Qed. Lemma polyCM : {morph polyC : a b / a * b}. Proof. by move=> a b; apply/polyP=> [[|i]]; rewrite coefCM !coefC ?simp. Qed. Lemma size_poly_exp_leq p n : size (p ^+ n) <= ((size p).-1 * n).+1. Proof. elim: n => [|n IHn]; first by rewrite size_poly1. have [-> | nzp] := poly0Vpos p; first by rewrite exprS mul0r size_poly0. rewrite exprS (leq_trans (size_polyMleq _ _)) //. by rewrite -{1}(prednK nzp) mulnS -addnS leq_add2l. Qed. End SemiPolynomialTheory. #[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyD`")] Notation size_add := size_polyD (only parsing). #[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyDl`")] Notation size_addl := size_polyDl (only parsing). #[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyMleq`")] Notation size_mul_leq := size_polyMleq (only parsing). #[deprecated(since="mathcomp 2.4.0", note="renamed to `size_poly_prod_leq`")] Notation size_prod_leq := size_poly_prod_leq (only parsing). #[deprecated(since="mathcomp 2.4.0", note="renamed to `size_poly_exp_leq`")] Notation size_exp_leq := size_poly_exp_leq (only parsing). Section PolynomialTheory. Variable R : nzRingType. Implicit Types (a b c x y z : R) (p q r d : {poly R}). Local Notation "c %:P" := (polyC c). Local Notation "\poly_ ( i < n ) E" := (poly n (fun i : nat => E)). (* Zmodule structure for polynomial *) Definition opp_poly_def p := \poly_(i < size p) - p`_i. Fact opp_poly_key : unit. Proof. by []. Qed. Definition opp_poly := locked_with opp_poly_key opp_poly_def. Canonical opp_poly_unlockable := [unlockable fun opp_poly]. Fact coef_opp_poly p i : (opp_poly p)`_i = - p`_i. Proof. rewrite unlock coef_poly /=. by case: leqP => // le_p_i; rewrite nth_default ?oppr0. Qed. Fact add_polyN : left_inverse 0%:P opp_poly (@add_poly _). Proof. move=> p; apply/polyP=> i. by rewrite coef_add_poly coef_opp_poly coefC if_same addNr. Qed. HB.instance Definition _ := GRing.Nmodule_isZmodule.Build (polynomial R) add_polyN. (* Size, leading coef, morphism properties of coef *) Lemma coefN p i : (- p)`_i = - p`_i. Proof. exact: coef_opp_poly. Qed. Lemma coefB p q i : (p - q)`_i = p`_i - q`_i. Proof. by rewrite coefD coefN. Qed. HB.instance Definition _ i := GRing.isZmodMorphism.Build {poly R} R (coefp i) (fun p => (coefB p)^~ i). Lemma coefMn p n i : (p *+ n)`_i = p`_i *+ n. Proof. exact: (raddfMn (coefp i)). Qed. Lemma coefMNn p n i : (p *- n)`_i = p`_i *- n. Proof. by rewrite coefN coefMn. Qed. Lemma coef_sum I (r : seq I) (P : pred I) (F : I -> {poly R}) k : (\sum_(i <- r | P i) F i)`_k = \sum_(i <- r | P i) (F i)`_k. Proof. exact: (raddf_sum (coefp k)). Qed. Lemma polyCN : {morph (@polyC R) : c / - c}. Proof. by move=> c; apply/polyP=> [[|i]]; rewrite coefN !coefC ?oppr0. Qed. Lemma polyCB : {morph (@polyC R) : a b / a - b}. Proof. by move=> a b; rewrite polyCD polyCN. Qed. HB.instance Definition _ := GRing.isZmodMorphism.Build R {poly R} (@polyC _) polyCB. Lemma polyCMn n : {morph (@polyC R) : c / c *+ n}. Proof. exact: raddfMn. Qed. Lemma size_polyN p : size (- p) = size p. Proof. by apply/eqP; rewrite eqn_leq -{3}(opprK p) -[-%R]/opp_poly unlock !size_poly. Qed. Lemma lead_coefN p : lead_coef (- p) = - lead_coef p. Proof. by rewrite /lead_coef size_polyN coefN. Qed. (* Polynomial ring structure. *) Fact polyC_is_monoid_morphism : monoid_morphism (@polyC R). Proof. by split; last apply: polyCM. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `polyC_is_monoid_morphism` instead")] Definition polyC_multiplicative := (fun g => (g.2, g.1)) polyC_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build R {poly R} (@polyC R) polyC_is_monoid_morphism. Lemma polyC_exp n : {morph (@polyC R) : c / c ^+ n}. Proof. exact: rmorphXn. Qed. Lemma polyC_natr n : n%:R%:P = n%:R :> {poly R}. Proof. by rewrite rmorph_nat. Qed. Lemma pchar_poly : [pchar {poly R}] =i [pchar R]. Proof. move=> p; rewrite !inE; congr (_ && _). apply/eqP/eqP=> [/(congr1 val) /=|]; last by rewrite -polyC_natr => ->. by rewrite polyseq0 -polyC_natr polyseqC; case: eqP. Qed. Lemma size_Msign p n : size ((-1) ^+ n * p) = size p. Proof. by rewrite -signr_odd; case: (odd n); rewrite ?mul1r// mulN1r size_polyN. Qed. Fact coefp0_is_monoid_morphism : monoid_morphism (coefp 0 : {poly R} -> R). Proof. split=> [|p q]; first by rewrite polyCK. by rewrite [coefp 0 _]coefM big_ord_recl big_ord0 addr0. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `coefp0_is_monoid_morphism` instead")] Definition coefp0_multiplicative := (fun g => (g.2, g.1)) coefp0_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly R} R (coefp 0) coefp0_is_monoid_morphism. (* Algebra structure of polynomials. *) Definition scale_poly_def a (p : {poly R}) := \poly_(i < size p) (a * p`_i). Fact scale_poly_key : unit. Proof. by []. Qed. Definition scale_poly := locked_with scale_poly_key scale_poly_def. Canonical scale_poly_unlockable := [unlockable fun scale_poly]. Fact scale_polyE a p : scale_poly a p = a%:P * p. Proof. apply/polyP=> n; rewrite unlock coef_poly coefCM. by case: leqP => // le_p_n; rewrite nth_default ?mulr0. Qed. Fact scale_polyA a b p : scale_poly a (scale_poly b p) = scale_poly (a * b) p. Proof. by rewrite !scale_polyE mulrA polyCM. Qed. Fact scale_1poly : left_id 1 scale_poly. Proof. by move=> p; rewrite scale_polyE mul1r. Qed. Fact scale_polyDr a : {morph scale_poly a : p q / p + q}. Proof. by move=> p q; rewrite !scale_polyE mulrDr. Qed. Fact scale_polyDl p : {morph scale_poly^~ p : a b / a + b}. Proof. by move=> a b /=; rewrite !scale_polyE raddfD mulrDl. Qed. Fact scale_polyAl a p q : scale_poly a (p * q) = scale_poly a p * q. Proof. by rewrite !scale_polyE mulrA. Qed. HB.instance Definition _ := GRing.Zmodule_isLmodule.Build R (polynomial R) scale_polyA scale_1poly scale_polyDr scale_polyDl. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build R (polynomial R) scale_polyAl. Lemma mul_polyC a p : a%:P * p = a *: p. Proof. by rewrite -scale_polyE. Qed. Lemma scale_polyC a b : a *: b%:P = (a * b)%:P. Proof. by rewrite -mul_polyC polyCM. Qed. Lemma alg_polyC a : a%:A = a%:P :> {poly R}. Proof. by rewrite -mul_polyC mulr1. Qed. Lemma coefZ a p i : (a *: p)`_i = a * p`_i. Proof. rewrite -[*:%R]/scale_poly unlock coef_poly. by case: leqP => // le_p_n; rewrite nth_default ?mulr0. Qed. Lemma size_scale_leq a p : size (a *: p) <= size p. Proof. by rewrite -[*:%R]/scale_poly unlock size_poly. Qed. HB.instance Definition _ i := GRing.isScalable.Build R {poly R} R *%R (coefp i) (fun a => (coefZ a) ^~ i). HB.instance Definition _ := GRing.Linear.on (coefp 0). (* The indeterminate, at last! *) Definition polyX_def := @Poly R [:: 0; 1]. Fact polyX_key : unit. Proof. by []. Qed. Definition polyX : {poly R} := locked_with polyX_key polyX_def. Canonical polyX_unlockable := [unlockable of polyX]. Local Notation "'X" := polyX. Lemma polyseqX : 'X = [:: 0; 1] :> seq R. Proof. by rewrite unlock !polyseq_cons nil_poly eqxx /= polyseq1. Qed. Lemma size_polyX : size 'X = 2. Proof. by rewrite polyseqX. Qed. Lemma polyX_eq0 : ('X == 0) = false. Proof. by rewrite -size_poly_eq0 size_polyX. Qed. Lemma coefX i : 'X`_i = (i == 1)%:R. Proof. by case: i => [|[|i]]; rewrite polyseqX //= nth_nil. Qed. Lemma lead_coefX : lead_coef 'X = 1. Proof. by rewrite /lead_coef polyseqX. Qed. Lemma commr_polyX p : GRing.comm p 'X. Proof. apply/polyP=> i; rewrite coefMr coefM. by apply: eq_bigr => j _; rewrite coefX commr_nat. Qed. Lemma coefMX p i : (p * 'X)`_i = (if (i == 0)%N then 0 else p`_i.-1). Proof. rewrite coefMr big_ord_recl coefX ?simp. case: i => [|i]; rewrite ?big_ord0 //= big_ord_recl polyseqX subn1 /=. by rewrite big1 ?simp // => j _; rewrite nth_nil !simp. Qed. Lemma coefXM p i : ('X * p)`_i = (if (i == 0)%N then 0 else p`_i.-1). Proof. by rewrite -commr_polyX coefMX. Qed. Lemma cons_poly_def p a : cons_poly a p = p * 'X + a%:P. Proof. apply/polyP=> i; rewrite coef_cons coefD coefMX coefC. by case: ifP; rewrite !simp. Qed. Lemma poly_ind (K : {poly R} -> Type) : K 0 -> (forall p c, K p -> K (p * 'X + c%:P)) -> (forall p, K p). Proof. move=> K0 Kcons p; rewrite -[p]polyseqK. by elim: {p}(p : seq R) => //= p c IHp; rewrite cons_poly_def; apply: Kcons. Qed. Lemma polyseqXaddC a : 'X + a%:P = [:: a; 1] :> seq R. Proof. by rewrite -['X]mul1r -cons_poly_def polyseq_cons polyseq1. Qed. Lemma polyseqXsubC a : 'X - a%:P = [:: - a; 1] :> seq R. Proof. by rewrite -polyCN polyseqXaddC. Qed. Lemma size_XsubC a : size ('X - a%:P) = 2. Proof. by rewrite polyseqXsubC. Qed. Lemma size_XaddC b : size ('X + b%:P) = 2. Proof. by rewrite -[b]opprK rmorphN size_XsubC. Qed. Lemma lead_coefXaddC a : lead_coef ('X + a%:P) = 1. Proof. by rewrite lead_coefE polyseqXaddC. Qed. Lemma lead_coefXsubC a : lead_coef ('X - a%:P) = 1. Proof. by rewrite lead_coefE polyseqXsubC. Qed. Lemma polyXsubC_eq0 a : ('X - a%:P == 0) = false. Proof. by rewrite -nil_poly polyseqXsubC. Qed. Lemma size_MXaddC p c : size (p * 'X + c%:P) = (if (p == 0) && (c == 0) then 0 else (size p).+1). Proof. by rewrite -cons_poly_def size_cons_poly nil_poly. Qed. Lemma polyseqMX p : p != 0 -> p * 'X = 0 :: p :> seq R. Proof. by move=> nz_p; rewrite -[p * _]addr0 -cons_poly_def polyseq_cons nil_poly nz_p. Qed. Lemma size_mulX p : p != 0 -> size (p * 'X) = (size p).+1. Proof. by move/polyseqMX->. Qed. Lemma lead_coefMX p : lead_coef (p * 'X) = lead_coef p. Proof. have [-> | nzp] := eqVneq p 0; first by rewrite mul0r. by rewrite /lead_coef !nth_last polyseqMX. Qed. Lemma size_XmulC a : a != 0 -> size ('X * a%:P) = 2. Proof. by move=> nz_a; rewrite -commr_polyX size_mulX ?polyC_eq0 ?size_polyC nz_a. Qed. Local Notation "''X^' n" := ('X ^+ n). Lemma coefXn n i : 'X^n`_i = (i == n)%:R. Proof. by elim: n i => [|n IHn] [|i]; rewrite ?coef1 // exprS coefXM ?IHn. Qed. Lemma polyseqXn n : 'X^n = rcons (nseq n 0) 1 :> seq R. Proof. elim: n => [|n IHn]; rewrite ?polyseq1 // exprSr. by rewrite polyseqMX -?size_poly_eq0 IHn ?size_rcons. Qed. Lemma size_polyXn n : size 'X^n = n.+1. Proof. by rewrite polyseqXn size_rcons size_nseq. Qed. Lemma commr_polyXn p n : GRing.comm p 'X^n. Proof. exact/commrX/commr_polyX. Qed. Lemma lead_coefXn n : lead_coef 'X^n = 1. Proof. by rewrite /lead_coef nth_last polyseqXn last_rcons. Qed. Lemma lead_coefXnaddC n c : 0 < n -> lead_coef ('X^n + c%:P) = 1. Proof. move=> n_gt0; rewrite lead_coefDl ?lead_coefXn//. by rewrite size_polyC size_polyXn ltnS (leq_trans (leq_b1 _)). Qed. Lemma lead_coefXnsubC n c : 0 < n -> lead_coef ('X^n - c%:P) = 1. Proof. by move=> n_gt0; rewrite -polyCN lead_coefXnaddC. Qed. Lemma size_XnaddC n c : 0 < n -> size ('X^n + c%:P) = n.+1. Proof. by move=> *; rewrite size_polyDl ?size_polyXn// size_polyC; case: eqP. Qed. Lemma size_XnsubC n c : 0 < n -> size ('X^n - c%:P) = n.+1. Proof. by move=> *; rewrite -polyCN size_XnaddC. Qed. Lemma polyseqMXn n p : p != 0 -> p * 'X^n = ncons n 0 p :> seq R. Proof. case: n => [|n] nz_p; first by rewrite mulr1. elim: n => [|n IHn]; first exact: polyseqMX. by rewrite exprSr mulrA polyseqMX -?nil_poly IHn. Qed. Lemma coefMXn n p i : (p * 'X^n)`_i = if i < n then 0 else p`_(i - n). Proof. have [-> | /polyseqMXn->] := eqVneq p 0; last exact: nth_ncons. by rewrite mul0r !coef0 if_same. Qed. Lemma size_mulXn n p : p != 0 -> size (p * 'X^n) = (n + size p)%N. Proof. elim: n p => [p p_neq0| n IH p p_neq0]; first by rewrite mulr1. by rewrite exprS mulrA IH -?size_poly_eq0 size_mulX // addnS. Qed. Lemma coefXnM n p i : ('X^n * p)`_i = if i < n then 0 else p`_(i - n). Proof. by rewrite -commr_polyXn coefMXn. Qed. Lemma coef_sumMXn I (r : seq I) (P : pred I) (p : I -> R) (n : I -> nat) k : (\sum_(i <- r | P i) p i *: 'X^(n i))`_k = \sum_(i <- r | P i && (n i == k)) p i. Proof. rewrite coef_sum big_mkcondr; apply: eq_bigr => i Pi. by rewrite coefZ coefXn mulr_natr mulrb eq_sym. Qed. (* Expansion of a polynomial as an indexed sum *) Lemma poly_def n E : \poly_(i < n) E i = \sum_(i < n) E i *: 'X^i. Proof. by apply/polyP => i; rewrite coef_sumMXn coef_poly big_ord1_eq. Qed. (* Monic predicate *) Definition monic_pred := fun p => lead_coef p == 1. Arguments monic_pred _ /. Definition monic := [qualify p | monic_pred p]. Lemma monicE p : (p \is monic) = (lead_coef p == 1). Proof. by []. Qed. Lemma monicP p : reflect (lead_coef p = 1) (p \is monic). Proof. exact: eqP. Qed. Lemma monic1 : 1 \is monic. Proof. exact/eqP/lead_coef1. Qed. Lemma monicX : 'X \is monic. Proof. exact/eqP/lead_coefX. Qed. Lemma monicXn n : 'X^n \is monic. Proof. exact/eqP/lead_coefXn. Qed. Lemma monic_neq0 p : p \is monic -> p != 0. Proof. by rewrite -lead_coef_eq0 => /eqP->; apply: oner_neq0. Qed. Lemma lead_coef_monicM p q : p \is monic -> lead_coef (p * q) = lead_coef q. Proof. have [-> | nz_q] := eqVneq q 0; first by rewrite mulr0. by move/monicP=> mon_p; rewrite lead_coef_proper_mul mon_p mul1r ?lead_coef_eq0. Qed. Lemma lead_coef_Mmonic p q : q \is monic -> lead_coef (p * q) = lead_coef p. Proof. have [-> | nz_p] := eqVneq p 0; first by rewrite mul0r. by move/monicP=> mon_q; rewrite lead_coef_proper_mul mon_q mulr1 ?lead_coef_eq0. Qed. Lemma size_monicM p q : p \is monic -> q != 0 -> size (p * q) = (size p + size q).-1. Proof. move/monicP=> mon_p nz_q. by rewrite size_proper_mul // mon_p mul1r lead_coef_eq0. Qed. Lemma size_Mmonic p q : p != 0 -> q \is monic -> size (p * q) = (size p + size q).-1. Proof. move=> nz_p /monicP mon_q. by rewrite size_proper_mul // mon_q mulr1 lead_coef_eq0. Qed. Lemma monicMl p q : p \is monic -> (p * q \is monic) = (q \is monic). Proof. by move=> mon_p; rewrite !monicE lead_coef_monicM. Qed. Lemma monicMr p q : q \is monic -> (p * q \is monic) = (p \is monic). Proof. by move=> mon_q; rewrite !monicE lead_coef_Mmonic. Qed. Fact monic_mulr_closed : mulr_closed monic. Proof. by split=> [|p q mon_p]; rewrite (monic1, monicMl). Qed. HB.instance Definition _ := GRing.isMulClosed.Build {poly R} monic_pred monic_mulr_closed. Lemma monic_exp p n : p \is monic -> p ^+ n \is monic. Proof. exact: rpredX. Qed. Lemma monic_prod I rI (P : pred I) (F : I -> {poly R}): (forall i, P i -> F i \is monic) -> \prod_(i <- rI | P i) F i \is monic. Proof. exact: rpred_prod. Qed. Lemma monicXaddC c : 'X + c%:P \is monic. Proof. exact/eqP/lead_coefXaddC. Qed. Lemma monicXsubC c : 'X - c%:P \is monic. Proof. exact/eqP/lead_coefXsubC. Qed. Lemma monic_prod_XsubC I rI (P : pred I) (F : I -> R) : \prod_(i <- rI | P i) ('X - (F i)%:P) \is monic. Proof. by apply: monic_prod => i _; apply: monicXsubC. Qed. Lemma lead_coef_prod_XsubC I rI (P : pred I) (F : I -> R) : lead_coef (\prod_(i <- rI | P i) ('X - (F i)%:P)) = 1. Proof. exact/eqP/monic_prod_XsubC. Qed. Lemma size_prod_XsubC I rI (F : I -> R) : size (\prod_(i <- rI) ('X - (F i)%:P)) = (size rI).+1. Proof. elim: rI => [|i r /= <-]; rewrite ?big_nil ?size_poly1 // big_cons. rewrite size_monicM ?monicXsubC ?monic_neq0 ?monic_prod_XsubC //. by rewrite size_XsubC. Qed. Lemma size_exp_XsubC n a : size (('X - a%:P) ^+ n) = n.+1. Proof. rewrite -[n]card_ord -prodr_const -big_filter size_prod_XsubC. by have [e _ _ [_ ->]] := big_enumP. Qed. Lemma monicXnaddC n c : 0 < n -> 'X^n + c%:P \is monic. Proof. by move=> n_gt0; rewrite monicE lead_coefXnaddC. Qed. Lemma monicXnsubC n c : 0 < n -> 'X^n - c%:P \is monic. Proof. by move=> n_gt0; rewrite monicE lead_coefXnsubC. Qed. (* Some facts about regular elements. *) Lemma lreg_lead p : GRing.lreg (lead_coef p) -> GRing.lreg p. Proof. move/mulrI_eq0=> reg_p; apply: mulrI0_lreg => q /eqP; apply: contraTeq => nz_q. by rewrite -lead_coef_eq0 lead_coef_proper_mul reg_p lead_coef_eq0. Qed. Lemma rreg_lead p : GRing.rreg (lead_coef p) -> GRing.rreg p. Proof. move/mulIr_eq0=> reg_p; apply: mulIr0_rreg => q /eqP; apply: contraTeq => nz_q. by rewrite -lead_coef_eq0 lead_coef_proper_mul reg_p lead_coef_eq0. Qed. Lemma lreg_lead0 p : GRing.lreg (lead_coef p) -> p != 0. Proof. by move/lreg_neq0; rewrite lead_coef_eq0. Qed. Lemma rreg_lead0 p : GRing.rreg (lead_coef p) -> p != 0. Proof. by move/rreg_neq0; rewrite lead_coef_eq0. Qed. Lemma lreg_size c p : GRing.lreg c -> size (c *: p) = size p. Proof. move=> reg_c; have [-> | nz_p] := eqVneq p 0; first by rewrite scaler0. rewrite -mul_polyC size_proper_mul; first by rewrite size_polyC lreg_neq0. by rewrite lead_coefC mulrI_eq0 ?lead_coef_eq0. Qed. Lemma lreg_polyZ_eq0 c p : GRing.lreg c -> (c *: p == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 => /lreg_size->. Qed. Lemma lead_coef_lreg c p : GRing.lreg c -> lead_coef (c *: p) = c * lead_coef p. Proof. by move=> reg_c; rewrite !lead_coefE coefZ lreg_size. Qed. Lemma rreg_size c p : GRing.rreg c -> size (p * c%:P) = size p. Proof. move=> reg_c; have [-> | nz_p] := eqVneq p 0; first by rewrite mul0r. rewrite size_proper_mul; first by rewrite size_polyC rreg_neq0 ?addn1. by rewrite lead_coefC mulIr_eq0 ?lead_coef_eq0. Qed. Lemma rreg_polyMC_eq0 c p : GRing.rreg c -> (p * c%:P == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 => /rreg_size->. Qed. Lemma rreg_div0 q r d : GRing.rreg (lead_coef d) -> size r < size d -> (q * d + r == 0) = (q == 0) && (r == 0). Proof. move=> reg_d lt_r_d; rewrite addrC addr_eq0. have [-> | nz_q] := eqVneq q 0; first by rewrite mul0r oppr0. apply: contraTF lt_r_d => /eqP->; rewrite -leqNgt size_polyN. rewrite size_proper_mul ?mulIr_eq0 ?lead_coef_eq0 //. by rewrite (polySpred nz_q) leq_addl. Qed. Lemma monic_comreg p : p \is monic -> GRing.comm p (lead_coef p)%:P /\ GRing.rreg (lead_coef p). Proof. by move/monicP->; split; [apply: commr1 | apply: rreg1]. Qed. Lemma monic_lreg p : p \is monic -> GRing.lreg p. Proof. by move=> /eqP lp1; apply/lreg_lead; rewrite lp1; apply/lreg1. Qed. Lemma monic_rreg p : p \is monic -> GRing.rreg p. Proof. by move=> /eqP lp1; apply/rreg_lead; rewrite lp1; apply/rreg1. Qed. (* Horner evaluation of polynomials *) Implicit Types s rs : seq R. Fixpoint horner_rec s x := if s is a :: s' then horner_rec s' x * x + a else 0. Definition horner p := horner_rec p. Local Notation "p .[ x ]" := (horner p x) : ring_scope. Lemma horner0 x : (0 : {poly R}).[x] = 0. Proof. by rewrite /horner polyseq0. Qed. Lemma hornerC c x : (c%:P).[x] = c. Proof. by rewrite /horner polyseqC; case: eqP; rewrite /= ?simp. Qed. Lemma hornerX x : 'X.[x] = x. Proof. by rewrite /horner polyseqX /= !simp. Qed. Lemma horner_cons p c x : (cons_poly c p).[x] = p.[x] * x + c. Proof. rewrite /horner polyseq_cons; case: nilP => //= ->. by rewrite !simp -/(_.[x]) hornerC. Qed. Lemma horner_coef0 p : p.[0] = p`_0. Proof. by rewrite /horner; case: (p : seq R) => //= c p'; rewrite !simp. Qed. Lemma hornerMXaddC p c x : (p * 'X + c%:P).[x] = p.[x] * x + c. Proof. by rewrite -cons_poly_def horner_cons. Qed. Lemma hornerMX p x : (p * 'X).[x] = p.[x] * x. Proof. by rewrite -[p * 'X]addr0 hornerMXaddC addr0. Qed. Lemma horner_Poly s x : (Poly s).[x] = horner_rec s x. Proof. by elim: s => [|a s /= <-]; rewrite (horner0, horner_cons). Qed. Lemma horner_coef p x : p.[x] = \sum_(i < size p) p`_i * x ^+ i. Proof. rewrite /horner. elim: {p}(p : seq R) => /= [|a s ->]; first by rewrite big_ord0. rewrite big_ord_recl simp addrC big_distrl /=. by congr (_ + _); apply: eq_bigr => i _; rewrite -mulrA exprSr. Qed. Lemma horner_coef_wide n p x : size p <= n -> p.[x] = \sum_(i < n) p`_i * x ^+ i. Proof. move=> le_p_n. rewrite horner_coef (big_ord_widen n (fun i => p`_i * x ^+ i)) // big_mkcond. by apply: eq_bigr => i _; case: ltnP => // le_p_i; rewrite nth_default ?simp. Qed. Lemma horner_poly n E x : (\poly_(i < n) E i).[x] = \sum_(i < n) E i * x ^+ i. Proof. rewrite (@horner_coef_wide n) ?size_poly //. by apply: eq_bigr => i _; rewrite coef_poly ltn_ord. Qed. Lemma hornerN p x : (- p).[x] = - p.[x]. Proof. rewrite -[-%R]/opp_poly unlock horner_poly horner_coef -sumrN /=. by apply: eq_bigr => i _; rewrite mulNr. Qed. Lemma hornerD p q x : (p + q).[x] = p.[x] + q.[x]. Proof. rewrite -[+%R]/(@add_poly R) unlock horner_poly; set m := maxn _ _. rewrite !(@horner_coef_wide m) ?leq_max ?leqnn ?orbT // -big_split /=. by apply: eq_bigr => i _; rewrite -mulrDl. Qed. Lemma hornerXsubC a x : ('X - a%:P).[x] = x - a. Proof. by rewrite hornerD hornerN hornerC hornerX. Qed. Lemma horner_sum I (r : seq I) (P : pred I) F x : (\sum_(i <- r | P i) F i).[x] = \sum_(i <- r | P i) (F i).[x]. Proof. by elim/big_rec2: _ => [|i _ p _ <-]; rewrite (horner0, hornerD). Qed. Lemma hornerCM a p x : (a%:P * p).[x] = a * p.[x]. Proof. elim/poly_ind: p => [|p c IHp]; first by rewrite !(mulr0, horner0). by rewrite mulrDr mulrA -polyCM !hornerMXaddC IHp mulrDr mulrA. Qed. Lemma hornerZ c p x : (c *: p).[x] = c * p.[x]. Proof. by rewrite -mul_polyC hornerCM. Qed. Lemma hornerMn n p x : (p *+ n).[x] = p.[x] *+ n. Proof. by elim: n => [| n IHn]; rewrite ?horner0 // !mulrS hornerD IHn. Qed. Definition comm_coef p x := forall i, p`_i * x = x * p`_i. Definition comm_poly p x := x * p.[x] = p.[x] * x. Lemma comm_coef_poly p x : comm_coef p x -> comm_poly p x. Proof. move=> cpx; rewrite /comm_poly !horner_coef big_distrl big_distrr /=. by apply: eq_bigr => i _; rewrite /= mulrA -cpx -!mulrA commrX. Qed. Lemma comm_poly0 x : comm_poly 0 x. Proof. by rewrite /comm_poly !horner0 !simp. Qed. Lemma comm_poly1 x : comm_poly 1 x. Proof. by rewrite /comm_poly !hornerC !simp. Qed. Lemma comm_polyX x : comm_poly 'X x. Proof. by rewrite /comm_poly !hornerX. Qed. Lemma comm_polyD p q x: comm_poly p x -> comm_poly q x -> comm_poly (p + q) x. Proof. by rewrite /comm_poly hornerD mulrDr mulrDl => -> ->. Qed. Lemma commr_horner a b p : GRing.comm a b -> comm_coef p a -> GRing.comm a p.[b]. Proof. move=> cab cpa; rewrite horner_coef; apply: commr_sum => i _. by apply: commrM => //; apply: commrX. Qed. Lemma hornerM_comm p q x : comm_poly q x -> (p * q).[x] = p.[x] * q.[x]. Proof. move=> comm_qx. elim/poly_ind: p => [|p c IHp]; first by rewrite !(simp, horner0). rewrite mulrDl hornerD hornerCM -mulrA -commr_polyX mulrA hornerMX. by rewrite {}IHp -mulrA -comm_qx mulrA -mulrDl hornerMXaddC. Qed. Lemma comm_polyM p q x: comm_poly p x -> comm_poly q x -> comm_poly (p * q) x. Proof. by move=> px qx; rewrite /comm_poly hornerM_comm// mulrA px -mulrA qx mulrA. Qed. Lemma horner_exp_comm p x n : comm_poly p x -> (p ^+ n).[x] = p.[x] ^+ n. Proof. move=> comm_px; elim: n => [|n IHn]; first by rewrite hornerC. by rewrite !exprSr -IHn hornerM_comm. Qed. Lemma comm_poly_exp p n x: comm_poly p x -> comm_poly (p ^+ n) x. Proof. by move=> px; rewrite /comm_poly !horner_exp_comm// commrX. Qed. Lemma hornerXn x n : ('X^n).[x] = x ^+ n. Proof. by rewrite horner_exp_comm /comm_poly hornerX. Qed. Definition hornerE_comm := (hornerD, hornerN, hornerX, hornerC, horner_cons, simp, hornerCM, hornerZ, (fun p x => hornerM_comm p (comm_polyX x))). Definition root p : pred R := fun x => p.[x] == 0. Lemma mem_root p x : x \in root p = (p.[x] == 0). Proof. by []. Qed. Lemma rootE p x : (root p x = (p.[x] == 0)) * ((x \in root p) = (p.[x] == 0)). Proof. by []. Qed. Lemma rootP p x : reflect (p.[x] = 0) (root p x). Proof. exact: eqP. Qed. Lemma rootPt p x : reflect (p.[x] == 0) (root p x). Proof. exact: idP. Qed. Lemma rootPf p x : reflect ((p.[x] == 0) = false) (~~ root p x). Proof. exact: negPf. Qed. Lemma rootC a x : root a%:P x = (a == 0). Proof. by rewrite rootE hornerC. Qed. Lemma root0 x : root 0 x. Proof. by rewrite rootC. Qed. Lemma root1 x : ~~ root 1 x. Proof. by rewrite rootC oner_eq0. Qed. Lemma rootX x : root 'X x = (x == 0). Proof. by rewrite rootE hornerX. Qed. Lemma rootN p x : root (- p) x = root p x. Proof. by rewrite rootE hornerN oppr_eq0. Qed. Lemma root_size_gt1 a p : p != 0 -> root p a -> 1 < size p. Proof. rewrite ltnNge => nz_p; apply: contraL => /size1_polyC Dp. by rewrite Dp rootC -polyC_eq0 -Dp. Qed. Lemma root_XsubC a x : root ('X - a%:P) x = (x == a). Proof. by rewrite rootE hornerXsubC subr_eq0. Qed. Lemma root_XaddC a x : root ('X + a%:P) x = (x == - a). Proof. by rewrite -root_XsubC rmorphN opprK. Qed. Theorem factor_theorem p a : reflect (exists q, p = q * ('X - a%:P)) (root p a). Proof. apply: (iffP eqP) => [pa0 | [q ->]]; last first. by rewrite hornerM_comm /comm_poly hornerXsubC subrr ?simp. exists (\poly_(i < size p) horner_rec (drop i.+1 p) a). apply/polyP=> i; rewrite mulrBr coefB coefMX coefMC !coef_poly. apply: canRL (addrK _) _; rewrite addrC; have [le_p_i | lt_i_p] := leqP. rewrite nth_default // !simp drop_oversize ?if_same //. exact: leq_trans (leqSpred _). case: i => [|i] in lt_i_p *; last by rewrite ltnW // (drop_nth 0 lt_i_p). by rewrite drop1 /= -{}pa0 /horner; case: (p : seq R) lt_i_p. Qed. Lemma multiplicity_XsubC p a : {m | exists2 q, (p != 0) ==> ~~ root q a & p = q * ('X - a%:P) ^+ m}. Proof. have [n le_p_n] := ubnP (size p); elim: n => // n IHn in p le_p_n *. have [-> | nz_p /=] := eqVneq p 0; first by exists 0, 0; rewrite ?mul0r. have [/sig_eqW[p1 Dp] | nz_pa] := altP (factor_theorem p a); last first. by exists 0%N, p; rewrite ?mulr1. have nz_p1: p1 != 0 by apply: contraNneq nz_p => p1_0; rewrite Dp p1_0 mul0r. have /IHn[m /sig2_eqW[q nz_qa Dp1]]: size p1 < n. by rewrite Dp size_Mmonic ?monicXsubC // size_XsubC addn2 in le_p_n. by exists m.+1, q; [rewrite nz_p1 in nz_qa | rewrite exprSr mulrA -Dp1]. Qed. (* Roots of unity. *) #[deprecated(since="mathcomp 2.3.0",note="Use size_XnsubC instead.")] Lemma size_Xn_sub_1 n : n > 0 -> size ('X^n - 1 : {poly R}) = n.+1. Proof. exact/size_XnsubC. Qed. #[deprecated(since="mathcomp 2.3.0'",note="Use monicXnsubC instead.")] Lemma monic_Xn_sub_1 n : n > 0 -> 'X^n - 1 \is monic. Proof. exact/monicXnsubC. Qed. Definition root_of_unity n : pred R := root ('X^n - 1). Local Notation "n .-unity_root" := (root_of_unity n) : ring_scope. Lemma unity_rootE n z : n.-unity_root z = (z ^+ n == 1). Proof. by rewrite /root_of_unity rootE hornerD hornerN hornerXn hornerC subr_eq0. Qed. Lemma unity_rootP n z : reflect (z ^+ n = 1) (n.-unity_root z). Proof. by rewrite unity_rootE; apply: eqP. Qed. Definition primitive_root_of_unity n z := (n > 0) && [forall i : 'I_n, i.+1.-unity_root z == (i.+1 == n)]. Local Notation "n .-primitive_root" := (primitive_root_of_unity n) : ring_scope. Lemma prim_order_exists n z : n > 0 -> z ^+ n = 1 -> {m | m.-primitive_root z & (m %| n)}. Proof. move=> n_gt0 zn1. have: exists m, (m > 0) && (z ^+ m == 1) by exists n; rewrite n_gt0 /= zn1. case/ex_minnP=> m /andP[m_gt0 /eqP zm1] m_min. exists m. apply/andP; split=> //; apply/eqfunP=> [[i]] /=. rewrite leq_eqVlt unity_rootE. case: eqP => [-> _ | _]; first by rewrite zm1 eqxx. by apply: contraTF => zi1; rewrite -leqNgt m_min. have: n %% m < m by rewrite ltn_mod. apply: contraLR; rewrite -lt0n -leqNgt => nm_gt0; apply: m_min. by rewrite nm_gt0 /= expr_mod ?zn1. Qed. Section OnePrimitive. Variables (n : nat) (z : R). Hypothesis prim_z : n.-primitive_root z. Lemma prim_order_gt0 : n > 0. Proof. by case/andP: prim_z. Qed. Let n_gt0 := prim_order_gt0. Lemma prim_expr_order : z ^+ n = 1. Proof. case/andP: prim_z => _; rewrite -(prednK n_gt0) => /forallP/(_ ord_max). by rewrite unity_rootE eqxx eqb_id => /eqP. Qed. Lemma prim_expr_mod i : z ^+ (i %% n) = z ^+ i. Proof. exact: expr_mod prim_expr_order. Qed. Lemma prim_order_dvd i : (n %| i) = (z ^+ i == 1). Proof. move: n_gt0; rewrite -prim_expr_mod /dvdn -(ltn_mod i). case: {i}(i %% n)%N => [|i] lt_i; first by rewrite !eqxx. case/andP: prim_z => _ /forallP/(_ (Ordinal (ltnW lt_i)))/eqP. by rewrite unity_rootE eqn_leq andbC leqNgt lt_i. Qed. Lemma eq_prim_root_expr i j : (z ^+ i == z ^+ j) = (i == j %[mod n]). Proof. wlog le_ji: i j / j <= i. move=> IH; case: (leqP j i) => [|/ltnW] /IH //. by rewrite eq_sym (eq_sym (j %% n)%N). rewrite -{1}(subnKC le_ji) exprD -prim_expr_mod eqn_mod_dvd //. rewrite prim_order_dvd; apply/eqP/eqP=> [|->]; last by rewrite mulr1. move/(congr1 ( *%R (z ^+ (n - j %% n)))); rewrite mulrA -exprD. by rewrite subnK ?prim_expr_order ?mul1r // ltnW ?ltn_mod. Qed. Lemma exp_prim_root k : (n %/ gcdn k n).-primitive_root (z ^+ k). Proof. set d := gcdn k n; have d_gt0: (0 < d)%N by rewrite gcdn_gt0 orbC n_gt0. have [d_dv_k d_dv_n]: (d %| k /\ d %| n)%N by rewrite dvdn_gcdl dvdn_gcdr. set q := (n %/ d)%N; rewrite /q.-primitive_root ltn_divRL // n_gt0. apply/forallP=> i; rewrite unity_rootE -exprM -prim_order_dvd. rewrite -(divnK d_dv_n) -/q -(divnK d_dv_k) mulnAC dvdn_pmul2r //. apply/eqP; apply/idP/idP=> [|/eqP->]; last by rewrite dvdn_mull. rewrite Gauss_dvdr; first by rewrite eqn_leq ltn_ord; apply: dvdn_leq. by rewrite /coprime gcdnC -(eqn_pmul2r d_gt0) mul1n muln_gcdl !divnK. Qed. Lemma dvdn_prim_root m : (m %| n)%N -> m.-primitive_root (z ^+ (n %/ m)). Proof. set k := (n %/ m)%N => m_dv_n; rewrite -{1}(mulKn m n_gt0) -divnA // -/k. by rewrite -{1}(@gcdn_idPl k n _) ?exp_prim_root // -(divnK m_dv_n) dvdn_mulr. Qed. Lemma prim_root_eq0 : (z == 0) = (n == 0%N). Proof. rewrite gtn_eqF//; apply/eqP => z0; have /esym/eqP := prim_expr_order. by rewrite z0 expr0n gtn_eqF//= oner_eq0. Qed. End OnePrimitive. Lemma prim_root_exp_coprime n z k : n.-primitive_root z -> n.-primitive_root (z ^+ k) = coprime k n. Proof. move=> prim_z; have n_gt0 := prim_order_gt0 prim_z. apply/idP/idP=> [prim_zk | co_k_n]. set d := gcdn k n; have dv_d_n: (d %| n)%N := dvdn_gcdr _ _. rewrite /coprime -/d -(eqn_pmul2r n_gt0) mul1n -{2}(gcdnMl n d). rewrite -{2}(divnK dv_d_n) (mulnC _ d) -muln_gcdr (gcdn_idPr _) //. rewrite (prim_order_dvd prim_zk) -exprM -(prim_order_dvd prim_z). by rewrite muln_divCA_gcd dvdn_mulr. have zkn_1: z ^+ k ^+ n = 1 by rewrite exprAC (prim_expr_order prim_z) expr1n. have{zkn_1} [m prim_zk dv_m_n]:= prim_order_exists n_gt0 zkn_1. suffices /eqP <-: m == n by []. rewrite eqn_dvd dv_m_n -(@Gauss_dvdr n k m) 1?coprime_sym //=. by rewrite (prim_order_dvd prim_z) exprM (prim_expr_order prim_zk). Qed. (* Lifting a ring predicate to polynomials. *) Implicit Type S : {pred R}. Definition polyOver_pred S := fun p : {poly R} => all (mem S) p. Arguments polyOver_pred _ _ /. Definition polyOver S := [qualify a p | polyOver_pred S p]. Lemma polyOverS (S1 S2 : {pred R}) : {subset S1 <= S2} -> {subset polyOver S1 <= polyOver S2}. Proof. by move=> sS12 p /(all_nthP 0)S1p; apply/(all_nthP 0)=> i /S1p; apply: sS12. Qed. Lemma polyOver0 S : 0 \is a polyOver S. Proof. by rewrite qualifE /= polyseq0. Qed. Lemma polyOver_poly S n E : (forall i, i < n -> E i \in S) -> \poly_(i < n) E i \is a polyOver S. Proof. move=> S_E; apply/(all_nthP 0)=> i lt_i_p /=; rewrite coef_poly. by case: ifP => [/S_E// | /idP[]]; apply: leq_trans lt_i_p (size_poly n E). Qed. Section PolyOverAdd. Variable S : addrClosed R. Lemma polyOverP {p} : reflect (forall i, p`_i \in S) (p \in polyOver S). Proof. apply: (iffP (all_nthP 0)) => [Sp i | Sp i _]; last exact: Sp. by have [/Sp // | /(nth_default 0)->] := ltnP i (size p); apply: rpred0. Qed. Lemma polyOverC c : (c%:P \in polyOver S) = (c \in S). Proof. by rewrite [LHS]qualifE /= polyseqC; case: eqP => [->|] /=; rewrite ?andbT ?rpred0. Qed. Fact polyOver_addr_closed : addr_closed (polyOver S). Proof. split=> [|p q Sp Sq]; first exact: polyOver0. by apply/polyOverP=> i; rewrite coefD rpredD ?(polyOverP _). Qed. HB.instance Definition _ := GRing.isAddClosed.Build {poly R} (polyOver_pred S) polyOver_addr_closed. End PolyOverAdd. Section PolyOverSemiRing2. Variable S : semiring2Closed R. Lemma polyOver_mulr_2closed : GRing.mulr_2closed (polyOver S). Proof. move=> p q /polyOverP Sp /polyOverP Sq; apply/polyOverP=> i. by rewrite coefM rpred_sum // => j _; rewrite rpredM. Qed. HB.instance Definition _ := GRing.isMul2Closed.Build {poly R} (polyOver_pred S) polyOver_mulr_2closed. End PolyOverSemiRing2. Fact polyOverNr (zmodS : zmodClosed R) : oppr_closed (polyOver zmodS). Proof. by move=> p /polyOverP Sp; apply/polyOverP=> i; rewrite coefN rpredN. Qed. HB.instance Definition _ (zmodS : zmodClosed R) := GRing.isOppClosed.Build {poly R} (polyOver_pred zmodS) (@polyOverNr _). Section PolyOverSemiring. Variable S : semiringClosed R. Fact polyOver_mul1_closed : 1 \in (polyOver S). Proof. by rewrite polyOverC rpred1. Qed. HB.instance Definition _ := GRing.isMul1Closed.Build {poly R} (polyOver_pred S) polyOver_mul1_closed. Lemma polyOverZ : {in S & polyOver S, forall c p, c *: p \is a polyOver S}. Proof. by move=> c p Sc /polyOverP Sp; apply/polyOverP=> i; rewrite coefZ rpredM ?Sp. Qed. Lemma polyOverX : 'X \in polyOver S. Proof. by rewrite qualifE /= polyseqX /= rpred0 rpred1. Qed. Lemma polyOverXn n : 'X^n \in polyOver S. Proof. by rewrite rpredX// polyOverX. Qed. Lemma rpred_horner : {in polyOver S & S, forall p x, p.[x] \in S}. Proof. move=> p x /polyOverP Sp Sx; rewrite horner_coef rpred_sum // => i _. by rewrite rpredM ?rpredX. Qed. End PolyOverSemiring. Section PolyOverRing. Variable S : subringClosed R. HB.instance Definition _ := GRing.MulClosed.on (polyOver_pred S). Lemma polyOverXaddC c : ('X + c%:P \in polyOver S) = (c \in S). Proof. by rewrite rpredDl ?polyOverX ?polyOverC. Qed. Lemma polyOverXnaddC n c : ('X^n + c%:P \is a polyOver S) = (c \in S). Proof. by rewrite rpredDl ?polyOverXn// ?polyOverC. Qed. Lemma polyOverXsubC c : ('X - c%:P \in polyOver S) = (c \in S). Proof. by rewrite rpredBl ?polyOverX ?polyOverC. Qed. Lemma polyOverXnsubC n c : ('X^n - c%:P \is a polyOver S) = (c \in S). Proof. by rewrite rpredBl ?polyOverXn// ?polyOverC. Qed. End PolyOverRing. (* Single derivative. *) Definition deriv p := \poly_(i < (size p).-1) (p`_i.+1 *+ i.+1). Local Notation "a ^` ()" := (deriv a). Lemma coef_deriv p i : p^`()`_i = p`_i.+1 *+ i.+1. Proof. rewrite coef_poly -subn1 ltn_subRL. by case: leqP => // /(nth_default 0) ->; rewrite mul0rn. Qed. Lemma polyOver_deriv (ringS : semiringClosed R) : {in polyOver ringS, forall p, p^`() \is a polyOver ringS}. Proof. by move=> p /polyOverP Kp; apply/polyOverP=> i; rewrite coef_deriv rpredMn ?Kp. Qed. Lemma derivC c : c%:P^`() = 0. Proof. by apply/polyP=> i; rewrite coef_deriv coef0 coefC mul0rn. Qed. Lemma derivX : ('X)^`() = 1. Proof. by apply/polyP=> [[|i]]; rewrite coef_deriv coef1 coefX ?mul0rn. Qed. Lemma derivXn n : ('X^n)^`() = 'X^(n.-1) *+ n. Proof. case: n => [|n]; first exact: derivC. apply/polyP=> i; rewrite coef_deriv coefMn !coefXn eqSS. by case: eqP => [-> // | _]; rewrite !mul0rn. Qed. Fact deriv_is_linear : linear deriv. Proof. move=> k p q; apply/polyP=> i. by rewrite !(coef_deriv, coefD, coefZ) mulrnDl mulrnAr. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} {poly R} _ deriv (GRing.semilinear_linear deriv_is_linear). Lemma deriv0 : 0^`() = 0. Proof. exact: linear0. Qed. Lemma derivD : {morph deriv : p q / p + q}. Proof. exact: linearD. Qed. Lemma derivN : {morph deriv : p / - p}. Proof. exact: linearN. Qed. Lemma derivB : {morph deriv : p q / p - q}. Proof. exact: linearB. Qed. Lemma derivXsubC (a : R) : ('X - a%:P)^`() = 1. Proof. by rewrite derivB derivX derivC subr0. Qed. Lemma derivMn n p : (p *+ n)^`() = p^`() *+ n. Proof. exact: linearMn. Qed. Lemma derivMNn n p : (p *- n)^`() = p^`() *- n. Proof. exact: linearMNn. Qed. Lemma derivZ c p : (c *: p)^`() = c *: p^`(). Proof. exact: linearZ. Qed. Lemma deriv_mulC c p : (c%:P * p)^`() = c%:P * p^`(). Proof. by rewrite !mul_polyC derivZ. Qed. Lemma derivMXaddC p c : (p * 'X + c%:P)^`() = p + p^`() * 'X. Proof. apply/polyP=> i; rewrite raddfD /= derivC addr0 coefD !(coefMX, coef_deriv). by case: i; rewrite ?addr0. Qed. Lemma derivM p q : (p * q)^`() = p^`() * q + p * q^`(). Proof. elim/poly_ind: p => [|p b IHp]; first by rewrite !(mul0r, add0r, derivC). rewrite mulrDl -mulrA -commr_polyX mulrA -[_ * 'X]addr0 raddfD /= !derivMXaddC. by rewrite deriv_mulC IHp !mulrDl -!mulrA !commr_polyX !addrA. Qed. Definition derivE := Eval lazy beta delta [morphism_2 morphism_1] in (derivZ, deriv_mulC, derivC, derivX, derivMXaddC, derivXsubC, derivM, derivB, derivD, derivN, derivXn, derivM, derivMn). (* Iterated derivative. *) Definition derivn n p := iter n deriv p. Local Notation "a ^` ( n )" := (derivn n a) : ring_scope. Lemma derivn0 p : p^`(0) = p. Proof. by []. Qed. Lemma derivn1 p : p^`(1) = p^`(). Proof. by []. Qed. Lemma derivnS p n : p^`(n.+1) = p^`(n)^`(). Proof. by []. Qed. Lemma derivSn p n : p^`(n.+1) = p^`()^`(n). Proof. exact: iterSr. Qed. Lemma coef_derivn n p i : p^`(n)`_i = p`_(n + i) *+ (n + i) ^_ n. Proof. elim: n i => [|n IHn] i; first by rewrite ffactn0 mulr1n. by rewrite derivnS coef_deriv IHn -mulrnA ffactnSr addSnnS addKn. Qed. Lemma polyOver_derivn (ringS : semiringClosed R) : {in polyOver ringS, forall p n, p^`(n) \is a polyOver ringS}. Proof. move=> p /polyOverP Kp /= n; apply/polyOverP=> i. by rewrite coef_derivn rpredMn. Qed. Fact derivn_is_linear n : linear (derivn n). Proof. by elim: n => // n IHn a p q; rewrite derivnS IHn linearP. Qed. HB.instance Definition _ n := GRing.isSemilinear.Build R {poly R} {poly R} _ (derivn n) (GRing.semilinear_linear (derivn_is_linear n)). Lemma derivnC c n : c%:P^`(n) = if n == 0 then c%:P else 0. Proof. by case: n => // n; rewrite derivSn derivC linear0. Qed. Lemma derivnD n : {morph derivn n : p q / p + q}. Proof. exact: linearD. Qed. Lemma derivnB n : {morph derivn n : p q / p - q}. Proof. exact: linearB. Qed. Lemma derivnMn n m p : (p *+ m)^`(n) = p^`(n) *+ m. Proof. exact: linearMn. Qed. Lemma derivnMNn n m p : (p *- m)^`(n) = p^`(n) *- m. Proof. exact: linearMNn. Qed. Lemma derivnN n : {morph derivn n : p / - p}. Proof. exact: linearN. Qed. Lemma derivnZ n : scalable (derivn n). Proof. exact: linearZZ. Qed. Lemma derivnXn m n : ('X^m)^`(n) = 'X^(m - n) *+ m ^_ n. Proof. apply/polyP=>i; rewrite coef_derivn coefMn !coefXn. case: (ltnP m n) => [lt_m_n | le_m_n]. by rewrite eqn_leq leqNgt ltn_addr // mul0rn ffact_small. by rewrite -{1 3}(subnKC le_m_n) eqn_add2l; case: eqP => [->|]; rewrite ?mul0rn. Qed. Lemma derivnMXaddC n p c : (p * 'X + c%:P)^`(n.+1) = p^`(n) *+ n.+1 + p^`(n.+1) * 'X. Proof. elim: n => [|n IHn]; first by rewrite derivn1 derivMXaddC. rewrite derivnS IHn derivD derivM derivX mulr1 derivMn -!derivnS. by rewrite addrA addrAC -mulrSr. Qed. Lemma derivn_poly0 p n : size p <= n -> p^`(n) = 0. Proof. move=> le_p_n; apply/polyP=> i; rewrite coef_derivn. rewrite nth_default; first by rewrite mul0rn coef0. exact/(leq_trans le_p_n)/leq_addr. Qed. Lemma lt_size_deriv (p : {poly R}) : p != 0 -> size p^`() < size p. Proof. by move=> /polySpred->; apply: size_poly. Qed. (* A normalising version of derivation to get the division by n! in Taylor *) Definition nderivn n p := \poly_(i < size p - n) (p`_(n + i) *+ 'C(n + i, n)). Local Notation "a ^`N ( n )" := (nderivn n a) : ring_scope. Lemma coef_nderivn n p i : p^`N(n)`_i = p`_(n + i) *+ 'C(n + i, n). Proof. rewrite coef_poly ltn_subRL; case: leqP => // le_p_ni. by rewrite nth_default ?mul0rn. Qed. (* Here is the division by n! *) Lemma nderivn_def n p : p^`(n) = p^`N(n) *+ n`!. Proof. by apply/polyP=> i; rewrite coefMn coef_nderivn coef_derivn -mulrnA bin_ffact. Qed. Lemma polyOver_nderivn (ringS : semiringClosed R) : {in polyOver ringS, forall p n, p^`N(n) \in polyOver ringS}. Proof. move=> p /polyOverP Sp /= n; apply/polyOverP=> i. by rewrite coef_nderivn rpredMn. Qed. Lemma nderivn0 p : p^`N(0) = p. Proof. by rewrite -[p^`N(0)](nderivn_def 0). Qed. Lemma nderivn1 p : p^`N(1) = p^`(). Proof. by rewrite -[p^`N(1)](nderivn_def 1). Qed. Lemma nderivnC c n : (c%:P)^`N(n) = if n == 0 then c%:P else 0. Proof. apply/polyP=> i; rewrite coef_nderivn. by case: n => [|n]; rewrite ?bin0 // coef0 coefC mul0rn. Qed. Lemma nderivnXn m n : ('X^m)^`N(n) = 'X^(m - n) *+ 'C(m, n). Proof. apply/polyP=> i; rewrite coef_nderivn coefMn !coefXn. have [lt_m_n | le_n_m] := ltnP m n. by rewrite eqn_leq leqNgt ltn_addr // mul0rn bin_small. by rewrite -{1 3}(subnKC le_n_m) eqn_add2l; case: eqP => [->|]; rewrite ?mul0rn. Qed. Fact nderivn_is_linear n : linear (nderivn n). Proof. move=> k p q; apply/polyP=> i. by rewrite !(coef_nderivn, coefD, coefZ) mulrnDl mulrnAr. Qed. HB.instance Definition _ n := GRing.isSemilinear.Build R {poly R} {poly R} _ (nderivn n) (GRing.semilinear_linear (nderivn_is_linear n)). Lemma nderivnD n : {morph nderivn n : p q / p + q}. Proof. exact: linearD. Qed. Lemma nderivnB n : {morph nderivn n : p q / p - q}. Proof. exact: linearB. Qed. Lemma nderivnMn n m p : (p *+ m)^`N(n) = p^`N(n) *+ m. Proof. exact: linearMn. Qed. Lemma nderivnMNn n m p : (p *- m)^`N(n) = p^`N(n) *- m. Proof. exact: linearMNn. Qed. Lemma nderivnN n : {morph nderivn n : p / - p}. Proof. exact: linearN. Qed. Lemma nderivnZ n : scalable (nderivn n). Proof. exact: linearZZ. Qed. Lemma nderivnMXaddC n p c : (p * 'X + c%:P)^`N(n.+1) = p^`N(n) + p^`N(n.+1) * 'X. Proof. apply/polyP=> i; rewrite coef_nderivn !coefD !coefMX coefC. rewrite !addSn /= !coef_nderivn addr0 binS mulrnDr addrC; congr (_ + _). by rewrite addSnnS; case: i; rewrite // addn0 bin_small. Qed. Lemma nderivn_poly0 p n : size p <= n -> p^`N(n) = 0. Proof. move=> le_p_n; apply/polyP=> i; rewrite coef_nderivn. rewrite nth_default; first by rewrite mul0rn coef0. exact/(leq_trans le_p_n)/leq_addr. Qed. Lemma nderiv_taylor p x h : GRing.comm x h -> p.[x + h] = \sum_(i < size p) p^`N(i).[x] * h ^+ i. Proof. move/commrX=> cxh; elim/poly_ind: p => [|p c IHp]. by rewrite size_poly0 big_ord0 horner0. rewrite hornerMXaddC size_MXaddC. have [-> | nz_p] := eqVneq p 0. rewrite horner0 !simp; have [-> | _] := c =P 0; first by rewrite big_ord0. by rewrite size_poly0 big_ord_recl big_ord0 nderivn0 hornerC !simp. rewrite big_ord_recl nderivn0 !simp hornerMXaddC addrAC; congr (_ + _). rewrite mulrDr {}IHp !big_distrl polySpred //= big_ord_recl /= mulr1 -addrA. rewrite nderivn0 /bump /(addn 1) /=; congr (_ + _). rewrite !big_ord_recr /= nderivnMXaddC -mulrA -exprSr -polySpred // !addrA. congr (_ + _); last by rewrite (nderivn_poly0 (leqnn _)) !simp. rewrite addrC -big_split /=; apply: eq_bigr => i _. by rewrite nderivnMXaddC !hornerE_comm /= mulrDl -!mulrA -exprSr cxh. Qed. Lemma nderiv_taylor_wide n p x h : GRing.comm x h -> size p <= n -> p.[x + h] = \sum_(i < n) p^`N(i).[x] * h ^+ i. Proof. move/nderiv_taylor=> -> le_p_n. rewrite (big_ord_widen n (fun i => p^`N(i).[x] * h ^+ i)) // big_mkcond. apply: eq_bigr => i _; case: leqP => // /nderivn_poly0->. by rewrite horner0 simp. Qed. Lemma eq_poly n E1 E2 : (forall i, i < n -> E1 i = E2 i) -> poly n E1 = poly n E2 :> {poly R}. Proof. by move=> E; rewrite !poly_def; apply: eq_bigr => i _; rewrite E. Qed. End PolynomialTheory. #[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyN`")] Notation size_opp := size_polyN (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pchar_poly instead.")] Notation char_poly := pchar_poly (only parsing). Prenex Implicits polyC polyCK Poly polyseqK lead_coef root horner polyOver. Arguments monic {R}. Notation "\poly_ ( i < n ) E" := (poly n (fun i => E)) : ring_scope. Notation "c %:P" := (polyC c) : ring_scope. Notation "'X" := (polyX _) : ring_scope. Notation "''X^' n" := ('X ^+ n) : ring_scope. Notation "p .[ x ]" := (horner p x) : ring_scope. Notation "n .-unity_root" := (root_of_unity n) : ring_scope. Notation "n .-primitive_root" := (primitive_root_of_unity n) : ring_scope. Notation "a ^` ()" := (deriv a) : ring_scope. Notation "a ^` ( n )" := (derivn n a) : ring_scope. Notation "a ^`N ( n )" := (nderivn n a) : ring_scope. Arguments monic_pred _ _ /. Arguments monicP {R p}. Arguments rootP {R p x}. Arguments rootPf {R p x}. Arguments rootPt {R p x}. Arguments unity_rootP {R n z}. Arguments polyOver_pred _ _ _ /. Arguments polyOverP {R S p}. Arguments polyC_inj {R} [x1 x2] eq_x12P. Arguments eq_poly {R n} [E1] E2 eq_E12. Section IdomainPrimRoot. Variables (R : idomainType) (n : nat) (z : R). Hypothesis prim_z : n.-primitive_root z. Import prime. Let n_gt0 := prim_order_gt0 prim_z. Lemma prim_root_pcharF p : (p %| n)%N -> p \in [pchar R] = false. Proof. move=> pn; apply: contraTF isT => pchar_p; have p_prime := pcharf_prime pchar_p. have /dvdnP[[|k] n_eq_kp] := pn; first by rewrite n_eq_kp in (n_gt0). have /eqP := prim_expr_order prim_z; rewrite n_eq_kp exprM. rewrite -pFrobenius_autE -(pFrobenius_aut1 pchar_p) -subr_eq0 -rmorphB/=. rewrite pFrobenius_autE expf_eq0// prime_gt0//= subr_eq0 => /eqP. move=> /eqP; rewrite -(prim_order_dvd prim_z) n_eq_kp. rewrite -[X in _ %| X]muln1 dvdn_pmul2l ?dvdn1// => /eqP peq1. by rewrite peq1 in p_prime. Qed. Lemma pchar_prim_root : [pchar R]^'.-nat n. Proof. by apply/pnatP=> // p pp pn; rewrite inE/= prim_root_pcharF. Qed. Lemma prim_root_pi_eq0 m : \pi(n).-nat m -> m%:R != 0 :> R. Proof. by rewrite natf_neq0_pchar; apply: sub_in_pnat => p _; apply: pnatPpi pchar_prim_root. Qed. Lemma prim_root_dvd_eq0 m : (m %| n)%N -> m%:R != 0 :> R. Proof. case: m => [|m mn]; first by rewrite dvd0n gtn_eqF. by rewrite prim_root_pi_eq0 ?(sub_in_pnat (in1W (pi_of_dvd mn _))) ?pnat_pi. Qed. Lemma prim_root_natf_neq0 : n%:R != 0 :> R. Proof. by rewrite prim_root_dvd_eq0. Qed. End IdomainPrimRoot. #[deprecated(since="mathcomp 2.4.0", note="Use prim_root_pcharF instead.")] Notation prim_root_charF := prim_root_pcharF (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pchar_prim_root instead.")] Notation char_prim_root := pchar_prim_root (only parsing). (* Container morphism. *) Section MapPoly. Section Definitions. Variables (aR rR : nzRingType) (f : aR -> rR). Definition map_poly (p : {poly aR}) := \poly_(i < size p) f p`_i. (* Alternative definition; the one above is more convenient because it lets *) (* us use the lemmas on \poly, e.g., size (map_poly p) <= size p is an *) (* instance of size_poly. *) Lemma map_polyE p : map_poly p = Poly (map f p). Proof. rewrite /map_poly unlock; congr Poly. apply: (@eq_from_nth _ 0); rewrite size_mkseq ?size_map // => i lt_i_p. by rewrite [RHS](nth_map 0) ?nth_mkseq. Qed. Definition commr_rmorph u := forall x, GRing.comm u (f x). Definition horner_morph u of commr_rmorph u := fun p => (map_poly p).[u]. End Definitions. Variables aR rR : nzRingType. Section Combinatorial. Variables (iR : nzRingType) (f : aR -> rR). Local Notation "p ^f" := (map_poly f p) : ring_scope. Lemma map_poly0 : 0^f = 0. Proof. by rewrite map_polyE polyseq0. Qed. Lemma eq_map_poly (g : aR -> rR) : f =1 g -> map_poly f =1 map_poly g. Proof. by move=> eq_fg p; rewrite !map_polyE (eq_map eq_fg). Qed. Lemma map_poly_id g (p : {poly iR}) : {in (p : seq iR), g =1 id} -> map_poly g p = p. Proof. by move=> g_id; rewrite map_polyE map_id_in ?polyseqK. Qed. Lemma coef_map_id0 p i : f 0 = 0 -> (p^f)`_i = f p`_i. Proof. by move=> f0; rewrite coef_poly; case: ltnP => // le_p_i; rewrite nth_default. Qed. Lemma map_Poly_id0 s : f 0 = 0 -> (Poly s)^f = Poly (map f s). Proof. move=> f0; apply/polyP=> j; rewrite coef_map_id0 ?coef_Poly //. have [/(nth_map 0 0)->// | le_s_j] := ltnP j (size s). by rewrite !nth_default ?size_map. Qed. Lemma map_poly_comp_id0 (g : iR -> aR) p : f 0 = 0 -> map_poly (f \o g) p = (map_poly g p)^f. Proof. by move=> f0; rewrite map_polyE map_comp -map_Poly_id0 -?map_polyE. Qed. Lemma size_map_poly_id0 p : f (lead_coef p) != 0 -> size p^f = size p. Proof. by move=> nz_fp; apply: size_poly_eq. Qed. Lemma map_poly_eq0_id0 p : f (lead_coef p) != 0 -> (p^f == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 => /size_map_poly_id0->. Qed. Lemma lead_coef_map_id0 p : f 0 = 0 -> f (lead_coef p) != 0 -> lead_coef p^f = f (lead_coef p). Proof. by move=> f0 nz_fp; rewrite lead_coefE coef_map_id0 ?size_map_poly_id0. Qed. Hypotheses (inj_f : injective f) (f_0 : f 0 = 0). Lemma size_map_inj_poly p : size p^f = size p. Proof. have [-> | nz_p] := eqVneq p 0; first by rewrite map_poly0 !size_poly0. by rewrite size_map_poly_id0 // -f_0 (inj_eq inj_f) lead_coef_eq0. Qed. Lemma map_inj_poly : injective (map_poly f). Proof. move=> p q /polyP eq_pq; apply/polyP=> i; apply: inj_f. by rewrite -!coef_map_id0 ?eq_pq. Qed. Lemma lead_coef_map_inj p : lead_coef p^f = f (lead_coef p). Proof. by rewrite !lead_coefE size_map_inj_poly coef_map_id0. Qed. End Combinatorial. Lemma map_polyK (f : aR -> rR) g : cancel g f -> f 0 = 0 -> cancel (map_poly g) (map_poly f). Proof. by move=> gK f_0 p; rewrite /= -map_poly_comp_id0 ?map_poly_id // => x _ //=. Qed. Lemma eq_in_map_poly_id0 (f g : aR -> rR) (S : addrClosed aR) : f 0 = 0 -> g 0 = 0 -> {in S, f =1 g} -> {in polyOver S, map_poly f =1 map_poly g}. Proof. move=> f0 g0 eq_fg p pP; apply/polyP => i. by rewrite !coef_map_id0// eq_fg// (polyOverP _). Qed. Lemma eq_in_map_poly (f g : {additive aR -> rR}) (S : addrClosed aR) : {in S, f =1 g} -> {in polyOver S, map_poly f =1 map_poly g}. Proof. by move=> /eq_in_map_poly_id0; apply; rewrite //?raddf0. Qed. Section Additive. Variables (iR : nzRingType) (f : {additive aR -> rR}). Local Notation "p ^f" := (map_poly (GRing.Additive.sort f) p) : ring_scope. Lemma coef_map p i : p^f`_i = f p`_i. Proof. exact: coef_map_id0 (raddf0 f). Qed. Lemma map_Poly s : (Poly s)^f = Poly (map f s). Proof. exact: map_Poly_id0 (raddf0 f). Qed. Lemma map_poly_comp (g : iR -> aR) p : map_poly (f \o g) p = map_poly f (map_poly g p). Proof. exact: map_poly_comp_id0 (raddf0 f). Qed. Fact map_poly_is_zmod_morphism : zmod_morphism (map_poly f). Proof. by move=> p q; apply/polyP=> i; rewrite !(coef_map, coefB) raddfB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `map_poly_is_zmod_morphism` instead")] Definition map_poly_is_additive := map_poly_is_zmod_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build {poly aR} {poly rR} (map_poly f) map_poly_is_zmod_morphism. Lemma map_polyC a : (a%:P)^f = (f a)%:P. Proof. by apply/polyP=> i; rewrite !(coef_map, coefC) -!mulrb raddfMn. Qed. Lemma lead_coef_map_eq p : f (lead_coef p) != 0 -> lead_coef p^f = f (lead_coef p). Proof. exact: lead_coef_map_id0 (raddf0 f). Qed. End Additive. Variable f : {rmorphism aR -> rR}. Implicit Types p : {poly aR}. Local Notation "p ^f" := (map_poly (GRing.RMorphism.sort f) p) : ring_scope. Fact map_poly_is_monoid_morphism : monoid_morphism (map_poly f). Proof. split=> [|p q]; apply/polyP=> i. by rewrite !(coef_map, coef1) /= rmorph_nat. rewrite coef_map /= !coefM /= !rmorph_sum; apply: eq_bigr => j _. by rewrite !coef_map rmorphM. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `map_poly_is_monoid_morphism` instead")] Definition map_poly_is_multiplicative := (fun g => (g.2, g.1)) map_poly_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly aR} {poly rR} (map_poly f) map_poly_is_monoid_morphism. Lemma map_polyZ c p : (c *: p)^f = f c *: p^f. Proof. by apply/polyP=> i; rewrite !(coef_map, coefZ) /= rmorphM. Qed. HB.instance Definition _ := GRing.isScalable.Build aR {poly aR} {poly rR} (f \; *:%R) (map_poly f) map_polyZ. Lemma map_polyX : ('X)^f = 'X. Proof. by apply/polyP=> i; rewrite coef_map !coefX /= rmorph_nat. Qed. Lemma map_polyXn n : ('X^n)^f = 'X^n. Proof. by rewrite rmorphXn /= map_polyX. Qed. Lemma map_polyXaddC x : ('X + x%:P)^f = 'X + (f x)%:P. Proof. by rewrite raddfD/= map_polyX map_polyC. Qed. Lemma map_polyXsubC x : ('X - x%:P)^f = 'X - (f x)%:P. Proof. by rewrite raddfB/= map_polyX map_polyC. Qed. Lemma map_prod_XsubC I (rI : seq I) P F : (\prod_(i <- rI | P i) ('X - (F i)%:P))^f = \prod_(i <- rI | P i) ('X - (f (F i))%:P). Proof. by rewrite rmorph_prod//; apply/eq_bigr => x /=; rewrite map_polyXsubC. Qed. Lemma prod_map_poly (ar : seq aR) P : \prod_(x <- map f ar | P x) ('X - x%:P) = (\prod_(x <- ar | P (f x)) ('X - x%:P))^f. Proof. by rewrite big_map map_prod_XsubC. Qed. Lemma monic_map p : p \is monic -> p^f \is monic. Proof. move/monicP=> mon_p; rewrite monicE. by rewrite lead_coef_map_eq mon_p /= rmorph1 ?oner_neq0. Qed. Lemma horner_map p x : p^f.[f x] = f p.[x]. Proof. elim/poly_ind: p => [|p c IHp]; first by rewrite !(rmorph0, horner0). rewrite hornerMXaddC !rmorphD !rmorphM /=. by rewrite map_polyX map_polyC hornerMXaddC IHp. Qed. Lemma map_comm_poly p x : comm_poly p x -> comm_poly p^f (f x). Proof. by rewrite /comm_poly horner_map -!rmorphM // => ->. Qed. Lemma map_comm_coef p x : comm_coef p x -> comm_coef p^f (f x). Proof. by move=> cpx i; rewrite coef_map -!rmorphM ?cpx. Qed. Lemma rmorph_root p x : root p x -> root p^f (f x). Proof. by move/eqP=> px0; rewrite rootE horner_map px0 rmorph0. Qed. Lemma rmorph_unity_root n z : n.-unity_root z -> n.-unity_root (f z). Proof. move/rmorph_root; rewrite rootE rmorphB hornerD hornerN. by rewrite /= map_polyXn rmorph1 hornerC hornerXn subr_eq0 unity_rootE. Qed. Section HornerMorph. Variable u : rR. Hypothesis cfu : commr_rmorph f u. Lemma horner_morphC a : horner_morph cfu a%:P = f a. Proof. by rewrite /horner_morph map_polyC hornerC. Qed. Lemma horner_morphX : horner_morph cfu 'X = u. Proof. by rewrite /horner_morph map_polyX hornerX. Qed. Fact horner_is_linear : linear_for (f \; *%R) (horner_morph cfu). Proof. by move=> c p q; rewrite /horner_morph linearP /= hornerD hornerZ. Qed. Fact horner_is_monoid_morphism : monoid_morphism (horner_morph cfu). Proof. split=> [|p q]; first by rewrite /horner_morph rmorph1 hornerC. rewrite /horner_morph rmorphM /= hornerM_comm //. by apply: comm_coef_poly => i; rewrite coef_map cfu. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `horner_is_monoid_morphism` instead")] Definition horner_is_multiplicative := (fun g => (g.2, g.1)) horner_is_monoid_morphism. HB.instance Definition _ := GRing.isSemilinear.Build aR {poly aR} rR _ (horner_morph cfu) (GRing.semilinear_linear horner_is_linear). HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly aR} rR (horner_morph cfu) horner_is_monoid_morphism. End HornerMorph. Lemma deriv_map p : p^f^`() = (p^`())^f. Proof. by apply/polyP => i; rewrite !(coef_map, coef_deriv) //= rmorphMn. Qed. Lemma derivn_map p n : p^f^`(n) = (p^`(n))^f. Proof. by apply/polyP => i; rewrite !(coef_map, coef_derivn) //= rmorphMn. Qed. Lemma nderivn_map p n : p^f^`N(n) = (p^`N(n))^f. Proof. by apply/polyP => i; rewrite !(coef_map, coef_nderivn) //= rmorphMn. Qed. End MapPoly. Lemma mapf_root (F : fieldType) (R : nzRingType) (f : {rmorphism F -> R}) (p : {poly F}) (x : F) : root (map_poly f p) (f x) = root p x. Proof. by rewrite !rootE horner_map fmorph_eq0. Qed. (* Morphisms from the polynomial ring, and the initiality of polynomials *) (* with respect to these. *) Section MorphPoly. Variable (aR rR : nzRingType) (pf : {rmorphism {poly aR} -> rR}). Lemma poly_morphX_comm : commr_rmorph (pf \o polyC) (pf 'X). Proof. by move=> a; rewrite /GRing.comm /= -!rmorphM // commr_polyX. Qed. Lemma poly_initial : pf =1 horner_morph poly_morphX_comm. Proof. apply: poly_ind => [|p a IHp]; first by rewrite !rmorph0. by rewrite !rmorphD !rmorphM /= -{}IHp horner_morphC ?horner_morphX. Qed. End MorphPoly. Notation "p ^:P" := (map_poly polyC p) : ring_scope. Section PolyCompose. Variable R : nzRingType. Implicit Types p q : {poly R}. Definition comp_poly q p := p^:P.[q]. Local Notation "p \Po q" := (comp_poly q p) : ring_scope. Lemma size_map_polyC p : size p^:P = size p. Proof. exact/(size_map_inj_poly polyC_inj). Qed. Lemma map_polyC_eq0 p : (p^:P == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 size_map_polyC. Qed. Lemma root_polyC p x : root p^:P x%:P = root p x. Proof. by rewrite rootE horner_map polyC_eq0. Qed. Lemma comp_polyE p q : p \Po q = \sum_(i < size p) p`_i *: q^+i. Proof. by rewrite [p \Po q]horner_poly; apply: eq_bigr => i _; rewrite mul_polyC. Qed. Lemma coef_comp_poly p q n : (p \Po q)`_n = \sum_(i < size p) p`_i * (q ^+ i)`_n. Proof. by rewrite comp_polyE coef_sum; apply: eq_bigr => i; rewrite coefZ. Qed. Lemma polyOver_comp (ringS : semiringClosed R) : {in polyOver ringS &, forall p q, p \Po q \in polyOver ringS}. Proof. move=> p q /polyOverP Sp Sq; rewrite comp_polyE rpred_sum // => i _. by rewrite polyOverZ ?rpredX. Qed. Lemma comp_polyCr p c : p \Po c%:P = p.[c]%:P. Proof. exact: horner_map. Qed. Lemma comp_poly0r p : p \Po 0 = (p`_0)%:P. Proof. by rewrite comp_polyCr horner_coef0. Qed. Lemma comp_polyC c p : c%:P \Po p = c%:P. Proof. by rewrite /(_ \Po p) map_polyC hornerC. Qed. Fact comp_poly_is_linear p : linear (comp_poly p). Proof. move=> a q r. by rewrite /comp_poly rmorphD /= map_polyZ !hornerE_comm mul_polyC. Qed. HB.instance Definition _ p := GRing.isSemilinear.Build R {poly R} {poly R} _ (comp_poly p) (GRing.semilinear_linear (comp_poly_is_linear p)). Lemma comp_poly0 p : 0 \Po p = 0. Proof. exact: raddf0. Qed. Lemma comp_polyD p q r : (p + q) \Po r = (p \Po r) + (q \Po r). Proof. exact: raddfD. Qed. Lemma comp_polyB p q r : (p - q) \Po r = (p \Po r) - (q \Po r). Proof. exact: raddfB. Qed. Lemma comp_polyZ c p q : (c *: p) \Po q = c *: (p \Po q). Proof. exact: linearZZ. Qed. Lemma comp_polyXr p : p \Po 'X = p. Proof. by rewrite -{2}/(idfun p) poly_initial. Qed. Lemma comp_polyX p : 'X \Po p = p. Proof. by rewrite /(_ \Po p) map_polyX hornerX. Qed. Lemma comp_poly_MXaddC c p q : (p * 'X + c%:P) \Po q = (p \Po q) * q + c%:P. Proof. by rewrite /(_ \Po q) rmorphD rmorphM /= map_polyX map_polyC hornerMXaddC. Qed. Lemma comp_polyXaddC_K p z : (p \Po ('X + z%:P)) \Po ('X - z%:P) = p. Proof. have addzK: ('X + z%:P) \Po ('X - z%:P) = 'X. by rewrite raddfD /= comp_polyC comp_polyX subrK. elim/poly_ind: p => [|p c IHp]; first by rewrite !comp_poly0. rewrite comp_poly_MXaddC linearD /= comp_polyC {1}/comp_poly rmorphM /=. by rewrite hornerM_comm /comm_poly -!/(_ \Po _) ?IHp ?addzK ?commr_polyX. Qed. Lemma size_comp_poly_leq p q : size (p \Po q) <= ((size p).-1 * (size q).-1).+1. Proof. rewrite comp_polyE (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP => i _. rewrite (leq_trans (size_scale_leq _ _))//. rewrite (leq_trans (size_poly_exp_leq _ _))//. by rewrite ltnS mulnC leq_mul // -{2}(subnKC (valP i)) leq_addr. Qed. Lemma comp_Xn_poly p n : 'X^n \Po p = p ^+ n. Proof. by rewrite /(_ \Po p) map_polyXn hornerXn. Qed. Lemma coef_comp_poly_Xn p n i : 0 < n -> (p \Po 'X^n)`_i = if n %| i then p`_(i %/ n) else 0. Proof. move=> n_gt0; rewrite comp_polyE; under eq_bigr do rewrite -exprM mulnC. rewrite coef_sumMXn/=; case: dvdnP => [[j ->]|nD]; last first. by rewrite big1// => j /eqP ?; case: nD; exists j. under eq_bigl do rewrite eqn_mul2r gtn_eqF//. by rewrite big_ord1_eq if_nth ?leqVgt ?mulnK. Qed. Lemma comp_poly_Xn p n : 0 < n -> p \Po 'X^n = \poly_(i < size p * n) if n %| i then p`_(i %/ n) else 0. Proof. move=> n_gt0; apply/polyP => i; rewrite coef_comp_poly_Xn // coef_poly. case: dvdnP => [[k ->]|]; last by rewrite if_same. by rewrite mulnK // ltn_mul2r n_gt0 if_nth ?leqVgt. Qed. End PolyCompose. Notation "p \Po q" := (comp_poly q p) : ring_scope. Lemma map_comp_poly (aR rR : nzRingType) (f : {rmorphism aR -> rR}) p q : map_poly f (p \Po q) = map_poly f p \Po map_poly f q. Proof. elim/poly_ind: p => [|p a IHp]; first by rewrite !raddf0. rewrite comp_poly_MXaddC !rmorphD !rmorphM /= !map_polyC map_polyX. by rewrite comp_poly_MXaddC -IHp. Qed. Section Surgery. Variable R : nzRingType. Implicit Type p q : {poly R}. (* Even part of a polynomial *) Definition even_poly p : {poly R} := \poly_(i < uphalf (size p)) p`_i.*2. Lemma size_even_poly p : size (even_poly p) <= uphalf (size p). Proof. exact: size_poly. Qed. Lemma coef_even_poly p i : (even_poly p)`_i = p`_i.*2. Proof. by rewrite coef_poly gtn_uphalf_double if_nth ?leqVgt. Qed. Lemma even_polyE s p : size p <= s.*2 -> even_poly p = \poly_(i < s) p`_i.*2. Proof. move=> pLs2; apply/polyP => i; rewrite coef_even_poly !coef_poly if_nth //. by case: ltnP => //= ?; rewrite (leq_trans pLs2) ?leq_double. Qed. Lemma size_even_poly_eq p : odd (size p) -> size (even_poly p) = uphalf (size p). Proof. move=> p_even; rewrite size_poly_eq// double_pred odd_uphalfK//=. by rewrite lead_coef_eq0 -size_poly_eq0; case: size p_even. Qed. Lemma even_polyD p q : even_poly (p + q) = even_poly p + even_poly q. Proof. by apply/polyP => i; rewrite !(coef_even_poly, coefD). Qed. Lemma even_polyZ k p : even_poly (k *: p) = k *: even_poly p. Proof. by apply/polyP => i; rewrite !(coefZ, coef_even_poly). Qed. Fact even_poly_is_linear : linear even_poly. Proof. by move=> k p q; rewrite even_polyD even_polyZ. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} {poly R} _ even_poly (GRing.semilinear_linear even_poly_is_linear). Lemma even_polyC (c : R) : even_poly c%:P = c%:P. Proof. by apply/polyP => i; rewrite coef_even_poly !coefC; case: i. Qed. (* Odd part of a polynomial *) Definition odd_poly p : {poly R} := \poly_(i < (size p)./2) p`_i.*2.+1. Lemma size_odd_poly p : size (odd_poly p) <= (size p)./2. Proof. exact: size_poly. Qed. Lemma coef_odd_poly p i : (odd_poly p)`_i = p`_i.*2.+1. Proof. by rewrite coef_poly gtn_half_double if_nth ?leqVgt. Qed. Lemma odd_polyE s p : size p <= s.*2.+1 -> odd_poly p = \poly_(i < s) p`_i.*2.+1. Proof. move=> pLs2; apply/polyP => i; rewrite coef_odd_poly !coef_poly if_nth //. by case: ltnP => //= ?; rewrite (leq_trans pLs2) ?ltnS ?leq_double. Qed. Lemma odd_polyC (c : R) : odd_poly c%:P = 0. Proof. by apply/polyP => i; rewrite coef_odd_poly !coefC; case: i. Qed. Lemma odd_polyD p q : odd_poly (p + q) = odd_poly p + odd_poly q. Proof. by apply/polyP => i; rewrite !(coef_odd_poly, coefD). Qed. Lemma odd_polyZ k p : odd_poly (k *: p) = k *: odd_poly p. Proof. by apply/polyP => i; rewrite !(coefZ, coef_odd_poly). Qed. Fact odd_poly_is_linear : linear odd_poly. Proof. by move=> k p q; rewrite odd_polyD odd_polyZ. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} {poly R} _ odd_poly (GRing.semilinear_linear odd_poly_is_linear). Lemma size_odd_poly_eq p : ~~ odd (size p) -> size (odd_poly p) = (size p)./2. Proof. have [->|p_neq0] := eqVneq p 0; first by rewrite odd_polyC size_poly0. move=> p_odd; rewrite size_poly_eq// -subn1 doubleB subn2 even_halfK//. rewrite prednK ?lead_coef_eq0// ltn_predRL. by move: p_neq0 p_odd; rewrite -size_poly_eq0; case: (size p) => [|[]]. Qed. Lemma odd_polyMX p : odd_poly (p * 'X) = even_poly p. Proof. have [->|pN0] := eqVneq p 0; first by rewrite mul0r even_polyC odd_polyC. by apply/polyP => i; rewrite !coef_poly size_mulX // coefMX. Qed. Lemma even_polyMX p : even_poly (p * 'X) = odd_poly p * 'X. Proof. have [->|pN0] := eqVneq p 0; first by rewrite mul0r even_polyC odd_polyC mul0r. by apply/polyP => -[|i]; rewrite !(coefMX, coef_poly, if_same, size_mulX). Qed. Lemma sum_even_poly p : \sum_(i < size p | ~~ odd i) p`_i *: 'X^i = even_poly p \Po 'X^2. Proof. apply/polyP => i; rewrite coef_comp_poly_Xn// coef_sumMXn coef_even_poly. rewrite (big_ord1_cond_eq _ _ (negb \o _))/= -dvdn2 andbC -muln2. by case: dvdnP => //= -[k ->]; rewrite mulnK// if_nth ?leqVgt. Qed. Lemma sum_odd_poly p : \sum_(i < size p | odd i) p`_i *: 'X^i = (odd_poly p \Po 'X^2) * 'X. Proof. apply/polyP => i; rewrite coefMX coef_comp_poly_Xn// coef_sumMXn coef_odd_poly/=. case: i => [|i]//=; first by rewrite big_andbC big1// => -[[|j]//]. rewrite big_ord1_cond_eq/= -dvdn2 andbC -muln2. by case: dvdnP => //= -[k ->]; rewrite mulnK// if_nth ?leqVgt. Qed. (* Decomposition in odd and even part *) Lemma poly_even_odd p : even_poly p \Po 'X^2 + (odd_poly p \Po 'X^2) * 'X = p. Proof. rewrite -sum_even_poly -sum_odd_poly addrC -(bigID _ xpredT). by rewrite -[RHS]coefK poly_def. Qed. (* take and drop for polynomials *) Definition take_poly m p := \poly_(i < m) p`_i. Lemma size_take_poly m p : size (take_poly m p) <= m. Proof. exact: size_poly. Qed. Lemma coef_take_poly m p i : (take_poly m p)`_i = if i < m then p`_i else 0. Proof. exact: coef_poly. Qed. Lemma take_poly_id m p : size p <= m -> take_poly m p = p. Proof. move=> /leq_trans gep; apply/polyP => i; rewrite coef_poly if_nth//=. by case: ltnP => // /gep->. Qed. Lemma take_polyD m p q : take_poly m (p + q) = take_poly m p + take_poly m q. Proof. by apply/polyP => i; rewrite !(coefD, coef_poly); case: leqP; rewrite ?add0r. Qed. Lemma take_polyZ k m p : take_poly m (k *: p) = k *: take_poly m p. Proof. apply/polyP => i; rewrite !(coefZ, coef_take_poly); case: leqP => //. by rewrite mulr0. Qed. Fact take_poly_is_linear m : linear (take_poly m). Proof. by move=> k p q; rewrite take_polyD take_polyZ. Qed. HB.instance Definition _ m := GRing.isSemilinear.Build R {poly R} {poly R} _ (take_poly m) (GRing.semilinear_linear (take_poly_is_linear m)). Lemma take_poly_sum m I r P (p : I -> {poly R}) : take_poly m (\sum_(i <- r | P i) p i) = \sum_(i <- r| P i) take_poly m (p i). Proof. exact: linear_sum. Qed. Lemma take_poly0l p : take_poly 0 p = 0. Proof. exact/size_poly_leq0P/size_take_poly. Qed. Lemma take_poly0r m : take_poly m 0 = 0. Proof. exact: linear0. Qed. Lemma take_polyMXn m n p : take_poly m (p * 'X^n) = take_poly (m - n) p * 'X^n. Proof. have [->|/eqP p_neq0] := p =P 0; first by rewrite !(mul0r, take_poly0r). apply/polyP => i; rewrite !(coef_take_poly, coefMXn). by have [iLn|nLi] := leqP n i; rewrite ?if_same// ltn_sub2rE. Qed. Lemma take_polyMXn_0 n p : take_poly n (p * 'X^n) = 0. Proof. by rewrite take_polyMXn subnn take_poly0l mul0r. Qed. Lemma take_polyDMXn n p q : size p <= n -> take_poly n (p + q * 'X^n) = p. Proof. by move=> ?; rewrite take_polyD take_poly_id// take_polyMXn_0 addr0. Qed. Definition drop_poly m p := \poly_(i < size p - m) p`_(i + m). Lemma coef_drop_poly m p i : (drop_poly m p)`_i = p`_(i + m). Proof. by rewrite coef_poly ltn_subRL addnC if_nth ?leqVgt. Qed. Lemma drop_poly_eq0 m p : size p <= m -> drop_poly m p = 0. Proof. move=> sLm; apply/polyP => i; rewrite coef_poly coef0 ltn_subRL addnC. by rewrite if_nth ?leqVgt// nth_default// (leq_trans _ (leq_addl _ _)). Qed. Lemma size_drop_poly n p : size (drop_poly n p) = (size p - n)%N. Proof. have [pLn|nLp] := leqP (size p) n. by rewrite (eqP pLn) drop_poly_eq0 ?size_poly0. have p_neq0 : p != 0 by rewrite -size_poly_gt0 (leq_trans _ nLp). by rewrite size_poly_eq// predn_sub subnK ?lead_coef_eq0// -ltnS -polySpred. Qed. Lemma sum_drop_poly n p : \sum_(n <= i < size p) p`_i *: 'X^i = drop_poly n p * 'X^n. Proof. rewrite (big_addn 0) big_mkord /drop_poly poly_def mulr_suml. by apply: eq_bigr => i _; rewrite exprD scalerAl. Qed. Lemma drop_polyD m p q : drop_poly m (p + q) = drop_poly m p + drop_poly m q. Proof. by apply/polyP => i; rewrite coefD !coef_drop_poly coefD. Qed. Lemma drop_polyZ k m p : drop_poly m (k *: p) = k *: drop_poly m p. Proof. by apply/polyP => i; rewrite coefZ !coef_drop_poly coefZ. Qed. Fact drop_poly_is_linear m : linear (drop_poly m). Proof. by move=> k p q; rewrite drop_polyD drop_polyZ. Qed. HB.instance Definition _ m := GRing.isSemilinear.Build R {poly R} {poly R} _ (drop_poly m) (GRing.semilinear_linear (drop_poly_is_linear m)). Lemma drop_poly_sum m I r P (p : I -> {poly R}) : drop_poly m (\sum_(i <- r | P i) p i) = \sum_(i <- r | P i) drop_poly m (p i). Proof. exact: linear_sum. Qed. Lemma drop_poly0l p : drop_poly 0 p = p. Proof. by apply/polyP => i; rewrite coef_poly subn0 addn0 if_nth ?leqVgt. Qed. Lemma drop_poly0r m : drop_poly m 0 = 0. Proof. exact: linear0. Qed. Lemma drop_polyMXn m n p : drop_poly m (p * 'X^n) = drop_poly (m - n) p * 'X^(n - m). Proof. have [->|p_neq0] := eqVneq p 0; first by rewrite mul0r !drop_poly0r mul0r. apply/polyP => i; rewrite !(coefMXn, coef_drop_poly) ltn_subRL [(m + i)%N]addnC. have [i_small|i_big]// := ltnP; congr nth. by have [mn|/ltnW mn] := leqP m n; rewrite (eqP mn) (addn0, subn0) (subnBA, addnBA). Qed. Lemma drop_polyMXn_id n p : drop_poly n (p * 'X^ n) = p. Proof. by rewrite drop_polyMXn subnn drop_poly0l expr0 mulr1. Qed. Lemma drop_polyDMXn n p q : size p <= n -> drop_poly n (p + q * 'X^n) = q. Proof. by move=> ?; rewrite drop_polyD drop_poly_eq0// drop_polyMXn_id add0r. Qed. Lemma poly_take_drop n p : take_poly n p + drop_poly n p * 'X^n = p. Proof. apply/polyP => i; rewrite coefD coefMXn coef_take_poly coef_drop_poly. by case: ltnP => ni; rewrite ?addr0 ?add0r//= subnK. Qed. Lemma eqp_take_drop n p q : take_poly n p = take_poly n q -> drop_poly n p = drop_poly n q -> p = q. Proof. by move=> tpq dpq; rewrite -[p](poly_take_drop n) -[q](poly_take_drop n) tpq dpq. Qed. End Surgery. Definition coefE := (coef0, coef1, coefC, coefX, coefXn, coef_sumMXn, coefZ, coefMC, coefCM, coefXnM, coefMXn, coefXM, coefMX, coefMNn, coefMn, coefN, coefB, coefD, coef_even_poly, coef_odd_poly, coef_take_poly, coef_drop_poly, coef_cons, coef_Poly, coef_poly, coef_deriv, coef_nderivn, coef_derivn, coef_map, coef_sum, coef_comp_poly_Xn, coef_comp_poly). Section PolynomialComNzRing. Variable R : comNzRingType. Implicit Types p q : {poly R}. Fact poly_mul_comm p q : p * q = q * p. Proof. apply/polyP=> i; rewrite coefM coefMr. by apply: eq_bigr => j _; rewrite mulrC. Qed. HB.instance Definition _ := GRing.PzRing_hasCommutativeMul.Build (polynomial R) poly_mul_comm. HB.instance Definition _ := GRing.Lalgebra_isComAlgebra.Build R (polynomial R). Lemma coef_prod_XsubC (ps : seq R) (n : nat) : (n <= size ps)%N -> (\prod_(p <- ps) ('X - p%:P))`_n = (-1) ^+ (size ps - n)%N * \sum_(I in {set 'I_(size ps)} | #|I| == (size ps - n)%N) \prod_(i in I) ps`_i. Proof. move=> nle. under eq_bigr => i _ do rewrite addrC -raddfN/=. rewrite -{1}(in_tupleE ps) -(map_tnth_enum (_ ps)) big_map. rewrite enumT bigA_distr /= coef_sum. transitivity (\sum_(I in {set 'I_(size ps)}) if #|I| == (size ps - n)%N then \prod_(i < size ps | i \in I) - ps`_i else 0). apply eq_bigr => I _. rewrite big_if/= big_const iter_mulr_1 -rmorph_prod/= coefCM coefXn. under eq_bigr => i _ do rewrite (tnth_nth 0)/=. rewrite -[#|I| == _](eqn_add2r n) subnK//. rewrite -[X in (_ + _)%N == X]card_ord -(cardC I) eqn_add2l. by case: ifP; rewrite ?mulr1 ?mulr0. by rewrite -big_mkcond mulr_sumr/=; apply: eq_bigr => I /eqP <-; rewrite prodrN. Qed. Lemma coefPn_prod_XsubC (ps : seq R) : size ps != 0 -> (\prod_(p <- ps) ('X - p%:P))`_(size ps).-1 = - \sum_(p <- ps) p. Proof. rewrite coef_prod_XsubC ?leq_pred// => ps0. have -> : (size ps - (size ps).-1 = 1)%N. by move: ps0; case: (size ps) => // n _; exact: subSnn. rewrite expr1 mulN1r; congr GRing.opp. set f : 'I_(size ps) -> {set 'I_(size ps)} := fun a => [set a]. transitivity (\sum_(I in imset f (mem setT)) \prod_(i in I) ps`_i). apply: congr_big => // I /=. by apply/cards1P/imsetP => [[a ->] | [a _ ->]]; exists a. rewrite big_imset/=; last first. by move=> i j _ _ ij; apply/set1P; rewrite -/(f j) -ij set11. rewrite -[in RHS](in_tupleE ps) -(map_tnth_enum (_ ps)) big_map enumT. apply: congr_big => // i; first exact: in_setT. by rewrite big_set1 (tnth_nth 0). Qed. Lemma coef0_prod_XsubC (ps : seq R) : (\prod_(p <- ps) ('X - p%:P))`_0 = (-1) ^+ (size ps) * \prod_(p <- ps) p. Proof. rewrite coef_prod_XsubC// subn0; congr GRing.mul. transitivity (\sum_(I in [set setT : {set 'I_(size ps)}]) \prod_(i in I) ps`_i). apply: congr_big =>// i/=. apply/idP/set1P => [/eqP cardE | ->]; last by rewrite cardsT card_ord. by apply/eqP; rewrite eqEcard subsetT cardsT card_ord cardE leqnn. rewrite big_set1 -[in RHS](in_tupleE ps) -(map_tnth_enum (_ ps)) big_map enumT. apply: congr_big => // i; first exact: in_setT. by rewrite (tnth_nth 0). Qed. Lemma hornerM p q x : (p * q).[x] = p.[x] * q.[x]. Proof. by rewrite hornerM_comm //; apply: mulrC. Qed. Lemma horner_exp p x n : (p ^+ n).[x] = p.[x] ^+ n. Proof. by rewrite horner_exp_comm //; apply: mulrC. Qed. Lemma horner_prod I r (P : pred I) (F : I -> {poly R}) x : (\prod_(i <- r | P i) F i).[x] = \prod_(i <- r | P i) (F i).[x]. Proof. by elim/big_rec2: _ => [|i _ p _ <-]; rewrite (hornerM, hornerC). Qed. Definition hornerE := (hornerD, hornerN, hornerX, hornerC, horner_exp, simp, hornerCM, hornerZ, hornerM, horner_cons). Definition horner_eval (x : R) := horner^~ x. Lemma horner_evalE x p : horner_eval x p = p.[x]. Proof. by []. Qed. Fact horner_eval_is_linear x : linear_for *%R (horner_eval x). Proof. have cxid: commr_rmorph idfun x by apply: mulrC. have evalE : horner_eval x =1 horner_morph cxid. by move=> p; congr _.[x]; rewrite map_poly_id. by move=> c p q; rewrite !evalE linearP. Qed. Fact horner_eval_is_monoid_morphism x : monoid_morphism (horner_eval x). Proof. have cxid: commr_rmorph idfun x by apply: mulrC. have evalE : horner_eval x =1 horner_morph cxid. by move=> p; congr _.[x]; rewrite map_poly_id. by split=> [|p q]; rewrite !evalE ?rmorph1// rmorphM. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `horner_eval_is_monoid_morphism` instead")] Definition horner_eval_is_multiplicative x := (fun g => (g.2, g.1)) (horner_eval_is_monoid_morphism x). HB.instance Definition _ x := GRing.isSemilinear.Build R {poly R} R _ (horner_eval x) (GRing.semilinear_linear (horner_eval_is_linear x)). HB.instance Definition _ x := GRing.isMonoidMorphism.Build {poly R} R (horner_eval x) (horner_eval_is_monoid_morphism x). Section HornerAlg. Variable A : algType R. (* For univariate polys, commutativity is not needed *) Section Defs. Variable a : A. Lemma in_alg_comm : commr_rmorph (in_alg A) a. Proof. move=> r /=; by rewrite /GRing.comm comm_alg. Qed. Definition horner_alg := horner_morph in_alg_comm. Lemma horner_algC c : horner_alg c%:P = c%:A. Proof. exact: horner_morphC. Qed. Lemma horner_algX : horner_alg 'X = a. Proof. exact: horner_morphX. Qed. HB.instance Definition _ := GRing.LRMorphism.on horner_alg. End Defs. Variable (pf : {lrmorphism {poly R} -> A}). Lemma poly_alg_initial : pf =1 horner_alg (pf 'X). Proof. apply: poly_ind => [|p a IHp]; first by rewrite !rmorph0. rewrite !rmorphD !rmorphM /= -{}IHp horner_algC ?horner_algX. by rewrite -alg_polyC rmorph_alg. Qed. End HornerAlg. Fact comp_poly_is_monoid_morphism q : monoid_morphism (comp_poly q). Proof. split=> [|p1 p2]; first by rewrite comp_polyC. by rewrite /comp_poly rmorphM hornerM_comm //; apply: mulrC. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `comp_poly_is_monoid_morphism` instead")] Definition comp_poly_multiplicative q := (fun g => (g.2, g.1)) (comp_poly_is_monoid_morphism q). HB.instance Definition _ q := GRing.isMonoidMorphism.Build _ _ (comp_poly q) (comp_poly_is_monoid_morphism q). Lemma comp_polyM p q r : (p * q) \Po r = (p \Po r) * (q \Po r). Proof. exact: rmorphM. Qed. Lemma comp_polyA p q r : p \Po (q \Po r) = (p \Po q) \Po r. Proof. elim/poly_ind: p => [|p c IHp]; first by rewrite !comp_polyC. by rewrite !comp_polyD !comp_polyM !comp_polyX IHp !comp_polyC. Qed. Lemma horner_comp p q x : (p \Po q).[x] = p.[q.[x]]. Proof. by apply: polyC_inj; rewrite -!comp_polyCr comp_polyA. Qed. Lemma root_comp p q x : root (p \Po q) x = root p (q.[x]). Proof. by rewrite !rootE horner_comp. Qed. Lemma deriv_comp p q : (p \Po q) ^`() = (p ^`() \Po q) * q^`(). Proof. elim/poly_ind: p => [|p c IHp]; first by rewrite !(deriv0, comp_poly0) mul0r. rewrite comp_poly_MXaddC derivD derivC derivM IHp derivMXaddC comp_polyD. by rewrite comp_polyM comp_polyX addr0 addrC mulrAC -mulrDl. Qed. Lemma deriv_exp p n : (p ^+ n)^`() = p^`() * p ^+ n.-1 *+ n. Proof. elim: n => [|n IHn]; first by rewrite expr0 mulr0n derivC. by rewrite exprS derivM {}IHn (mulrC p) mulrnAl -mulrA -exprSr mulrS; case n. Qed. Definition derivCE := (derivE, deriv_exp). End PolynomialComNzRing. Section PolynomialIdomain. (* Integral domain structure on poly *) Variable R : idomainType. Implicit Types (a b x y : R) (p q r m : {poly R}). Lemma size_mul p q : p != 0 -> q != 0 -> size (p * q) = (size p + size q).-1. Proof. by move=> nz_p nz_q; rewrite -size_proper_mul ?mulf_neq0 ?lead_coef_eq0. Qed. Fact poly_idomainAxiom p q : p * q = 0 -> (p == 0) || (q == 0). Proof. move=> pq0; apply/norP=> [[p_nz q_nz]]; move/eqP: (size_mul p_nz q_nz). by rewrite eq_sym pq0 size_poly0 (polySpred p_nz) (polySpred q_nz) addnS. Qed. Definition poly_unit : pred {poly R} := fun p => (size p == 1) && (p`_0 \in GRing.unit). Definition poly_inv p := if p \in poly_unit then (p`_0)^-1%:P else p. Fact poly_mulVp : {in poly_unit, left_inverse 1 poly_inv *%R}. Proof. move=> p Up; rewrite /poly_inv Up. by case/andP: Up => /size_poly1P[c _ ->]; rewrite coefC -polyCM => /mulVr->. Qed. Fact poly_intro_unit p q : q * p = 1 -> p \in poly_unit. Proof. move=> pq1; apply/andP; split; last first. apply/unitrP; exists q`_0. by rewrite 2!mulrC -!/(coefp 0 _) -rmorphM pq1 rmorph1. have: size (q * p) == 1 by rewrite pq1 size_poly1. have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 size_poly0. have [-> | nz_q] := eqVneq q 0; first by rewrite mul0r size_poly0. rewrite size_mul // (polySpred nz_p) (polySpred nz_q) addnS addSn !eqSS. by rewrite addn_eq0 => /andP[]. Qed. Fact poly_inv_out : {in [predC poly_unit], poly_inv =1 id}. Proof. by rewrite /poly_inv => p /negbTE/= ->. Qed. HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build (polynomial R) poly_mulVp poly_intro_unit poly_inv_out. HB.instance Definition _ := GRing.ComUnitRing_isIntegral.Build (polynomial R) poly_idomainAxiom. Lemma poly_unitE p : (p \in GRing.unit) = (size p == 1) && (p`_0 \in GRing.unit). Proof. by []. Qed. Lemma poly_invE p : p ^-1 = if p \in GRing.unit then (p`_0)^-1%:P else p. Proof. by []. Qed. Lemma polyCV c : c%:P^-1 = (c^-1)%:P. Proof. have [/rmorphV-> // | nUc] := boolP (c \in GRing.unit). by rewrite !invr_out // poly_unitE coefC (negbTE nUc) andbF. Qed. Lemma rootM p q x : root (p * q) x = root p x || root q x. Proof. by rewrite !rootE hornerM mulf_eq0. Qed. Lemma rootZ x a p : a != 0 -> root (a *: p) x = root p x. Proof. by move=> nz_a; rewrite -mul_polyC rootM rootC (negPf nz_a). Qed. Lemma root_exp p n a: comm_poly p a -> (0 < n)%N -> root (p ^+ n) a = root p a. Proof. by move=> ? n0; rewrite !rootE horner_exp_comm// expf_eq0 n0. Qed. Lemma size_scale a p : a != 0 -> size (a *: p) = size p. Proof. by move/lregP/lreg_size->. Qed. Lemma size_Cmul a p : a != 0 -> size (a%:P * p) = size p. Proof. by rewrite mul_polyC => /size_scale->. Qed. Lemma lead_coefM p q : lead_coef (p * q) = lead_coef p * lead_coef q. Proof. have [-> | nz_p] := eqVneq p 0; first by rewrite !(mul0r, lead_coef0). have [-> | nz_q] := eqVneq q 0; first by rewrite !(mulr0, lead_coef0). by rewrite lead_coef_proper_mul // mulf_neq0 ?lead_coef_eq0. Qed. Lemma lead_coef_prod I rI (P : {pred I}) (p : I -> {poly R}) : lead_coef (\prod_(i <- rI | P i) p i) = \prod_(i <- rI | P i) lead_coef (p i). Proof. by apply/big_morph/lead_coef1; apply: lead_coefM. Qed. Lemma lead_coefZ a p : lead_coef (a *: p) = a * lead_coef p. Proof. by rewrite -mul_polyC lead_coefM lead_coefC. Qed. Lemma scale_poly_eq0 a p : (a *: p == 0) = (a == 0) || (p == 0). Proof. by rewrite -mul_polyC mulf_eq0 polyC_eq0. Qed. Lemma size_prod (I : finType) (P : pred I) (F : I -> {poly R}) : (forall i, P i -> F i != 0) -> size (\prod_(i | P i) F i) = ((\sum_(i | P i) size (F i)).+1 - #|P|)%N. Proof. move=> nzF; transitivity (\sum_(i | P i) (size (F i)).-1).+1; last first. apply: canRL (addKn _) _; rewrite addnS -sum1_card -big_split /=. by congr _.+1; apply: eq_bigr => i /nzF/polySpred. elim/big_rec2: _ => [|i d p /nzF nzFi IHp]; first by rewrite size_poly1. by rewrite size_mul // -?size_poly_eq0 IHp // addnS polySpred. Qed. Lemma size_prod_seq (I : eqType) (s : seq I) (F : I -> {poly R}) : (forall i, i \in s -> F i != 0) -> size (\prod_(i <- s) F i) = ((\sum_(i <- s) size (F i)).+1 - size s)%N. Proof. move=> nzF; rewrite big_tnth size_prod; last by move=> i; rewrite nzF ?mem_tnth. by rewrite cardT /= size_enum_ord [in RHS]big_tnth. Qed. Lemma size_mul_eq1 p q : (size (p * q) == 1) = ((size p == 1) && (size q == 1)). Proof. have [->|pNZ] := eqVneq p 0; first by rewrite mul0r size_poly0. have [->|qNZ] := eqVneq q 0; first by rewrite mulr0 size_poly0 andbF. rewrite size_mul //. by move: pNZ qNZ; rewrite -!size_poly_gt0; (do 2 case: size) => //= n [|[|]]. Qed. Lemma size_prod_seq_eq1 (I : eqType) (s : seq I) (P : pred I) (F : I -> {poly R}) : reflect (forall i, P i && (i \in s) -> size (F i) = 1) (size (\prod_(i <- s | P i) F i) == 1%N). Proof. rewrite (big_morph _ (id1:=true) size_mul_eq1) ?size_polyC ?oner_neq0//. rewrite big_all_cond; apply/(iffP allP). by move=> h i /andP[Pi ins]; apply/eqP/(implyP (h i ins) Pi). by move=> h i ins; apply/implyP => Pi; rewrite h ?Pi. Qed. Lemma size_prod_eq1 (I : finType) (P : pred I) (F : I -> {poly R}) : reflect (forall i, P i -> size (F i) = 1) (size (\prod_(i | P i) F i) == 1). Proof. apply: (iffP (size_prod_seq_eq1 _ _ _)) => Hi i. by move=> Pi; apply: Hi; rewrite Pi /= mem_index_enum. by rewrite mem_index_enum andbT; apply: Hi. Qed. Lemma size_exp p n : (size (p ^+ n)).-1 = ((size p).-1 * n)%N. Proof. elim: n => [|n IHn]; first by rewrite size_poly1 muln0. have [-> | nz_p] := eqVneq p 0; first by rewrite exprS mul0r size_poly0. rewrite exprS size_mul ?expf_neq0 // mulnS -{}IHn. by rewrite polySpred // [size (p ^+ n)]polySpred ?expf_neq0 ?addnS. Qed. Lemma lead_coef_exp p n : lead_coef (p ^+ n) = lead_coef p ^+ n. Proof. elim: n => [|n IHn]; first by rewrite !expr0 lead_coef1. by rewrite !exprS lead_coefM IHn. Qed. Lemma root_prod_XsubC rs x : root (\prod_(a <- rs) ('X - a%:P)) x = (x \in rs). Proof. elim: rs => [|a rs IHrs]; first by rewrite rootE big_nil hornerC oner_eq0. by rewrite big_cons rootM IHrs root_XsubC. Qed. Lemma root_exp_XsubC n a x : root (('X - a%:P) ^+ n.+1) x = (x == a). Proof. by rewrite rootE horner_exp expf_eq0 [_ == 0]root_XsubC. Qed. Lemma size_comp_poly p q : (size (p \Po q)).-1 = ((size p).-1 * (size q).-1)%N. Proof. have [-> | nz_p] := eqVneq p 0; first by rewrite comp_poly0 size_poly0. have [/size1_polyC-> | nc_q] := leqP (size q) 1. by rewrite comp_polyCr !size_polyC -!sub1b -!subnS muln0. have nz_q: q != 0 by rewrite -size_poly_eq0 -(subnKC nc_q). rewrite mulnC comp_polyE (polySpred nz_p) /= big_ord_recr /= addrC. rewrite size_polyDl size_scale ?lead_coef_eq0 ?size_exp //=. rewrite [ltnRHS]polySpred ?expf_neq0 // ltnS size_exp. rewrite (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP => i _. rewrite (leq_trans (size_scale_leq _ _)) // polySpred ?expf_neq0 //. by rewrite size_exp -(subnKC nc_q) ltn_pmul2l. Qed. Lemma lead_coef_comp p q : size q > 1 -> lead_coef (p \Po q) = (lead_coef p) * lead_coef q ^+ (size p).-1. Proof. move=> q_gt1; rewrite !lead_coefE coef_comp_poly size_comp_poly. have [->|nz_p] := eqVneq p 0; first by rewrite size_poly0 big_ord0 coef0 mul0r. rewrite polySpred //= big_ord_recr /= big1 ?add0r => [|i _]. by rewrite -!lead_coefE -lead_coef_exp !lead_coefE size_exp mulnC. rewrite [X in _ * X]nth_default ?mulr0 ?(leq_trans (size_poly_exp_leq _ _)) //. by rewrite mulnC ltn_mul2r -subn1 subn_gt0 q_gt1 /=. Qed. Lemma comp_poly_eq0 p q : size q > 1 -> (p \Po q == 0) = (p == 0). Proof. move=> sq_gt1; rewrite -!lead_coef_eq0 lead_coef_comp //. rewrite mulf_eq0 expf_eq0 !lead_coef_eq0 -[q == 0]size_poly_leq0. by rewrite [_ <= 0]leqNgt (leq_ltn_trans _ sq_gt1) ?andbF ?orbF. Qed. Lemma size_comp_poly2 p q : size q = 2 -> size (p \Po q) = size p. Proof. move=> sq2; have [->|pN0] := eqVneq p 0; first by rewrite comp_polyC. by rewrite polySpred ?size_comp_poly ?comp_poly_eq0 ?sq2 // muln1 polySpred. Qed. Lemma comp_poly2_eq0 p q : size q = 2 -> (p \Po q == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 => /size_comp_poly2->. Qed. Theorem max_poly_roots p rs : p != 0 -> all (root p) rs -> uniq rs -> size rs < size p. Proof. elim: rs p => [p pn0 _ _ | r rs ihrs p pn0] /=; first by rewrite size_poly_gt0. case/andP => rpr arrs /andP [rnrs urs]; case/factor_theorem: rpr => q epq. have [q0 | ?] := eqVneq q 0; first by move: pn0; rewrite epq q0 mul0r eqxx. have -> : size p = (size q).+1. by rewrite epq size_Mmonic ?monicXsubC // size_XsubC addnC. suff /eq_in_all h : {in rs, root q =1 root p} by apply: ihrs => //; rewrite h. move=> x xrs; rewrite epq rootM root_XsubC orbC; case: (eqVneq x r) => // exr. by move: rnrs; rewrite -exr xrs. Qed. Lemma roots_geq_poly_eq0 p (rs : seq R) : all (root p) rs -> uniq rs -> (size rs >= size p)%N -> p = 0. Proof. by move=> ??; apply: contraTeq => ?; rewrite leqNgt max_poly_roots. Qed. End PolynomialIdomain. (* FIXME: these are seamingly artificial ways to close the inheritance graph *) (* We make parameters more and more precise to trigger completion by HB *) HB.instance Definition _ (R : countNzRingType) := [Countable of polynomial R by <:]. HB.instance Definition _ (R : countComNzRingType) := [Countable of polynomial R by <:]. HB.instance Definition _ (R : countIdomainType) := [Countable of polynomial R by <:]. Section MapFieldPoly. Variables (F : fieldType) (R : nzRingType) (f : {rmorphism F -> R}). Local Notation "p ^f" := (map_poly f p) : ring_scope. Lemma size_map_poly p : size p^f = size p. Proof. have [-> | nz_p] := eqVneq p 0; first by rewrite rmorph0 !size_poly0. by rewrite size_poly_eq // fmorph_eq0 // lead_coef_eq0. Qed. Lemma lead_coef_map p : lead_coef p^f = f (lead_coef p). Proof. have [-> | nz_p] := eqVneq p 0; first by rewrite !(rmorph0, lead_coef0). by rewrite lead_coef_map_eq // fmorph_eq0 // lead_coef_eq0. Qed. Lemma map_poly_eq0 p : (p^f == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 size_map_poly. Qed. Lemma map_poly_inj : injective (map_poly f). Proof. move=> p q eqfpq; apply/eqP; rewrite -subr_eq0 -map_poly_eq0. by rewrite rmorphB /= eqfpq subrr. Qed. Lemma map_monic p : (p^f \is monic) = (p \is monic). Proof. by rewrite [in LHS]monicE lead_coef_map fmorph_eq1. Qed. Lemma map_poly_com p x : comm_poly p^f (f x). Proof. exact: map_comm_poly (mulrC x _). Qed. Lemma fmorph_root p x : root p^f (f x) = root p x. Proof. by rewrite rootE horner_map // fmorph_eq0. Qed. Lemma fmorph_unity_root n z : n.-unity_root (f z) = n.-unity_root z. Proof. by rewrite !unity_rootE -(inj_eq (fmorph_inj f)) rmorphXn ?rmorph1. Qed. Lemma fmorph_primitive_root n z : n.-primitive_root (f z) = n.-primitive_root z. Proof. by congr (_ && _); apply: eq_forallb => i; rewrite fmorph_unity_root. Qed. End MapFieldPoly. Arguments map_poly_inj {F R} f [p1 p2] : rename. Section MaxRoots. Variable R : unitRingType. Implicit Types (x y : R) (rs : seq R) (p : {poly R}). Definition diff_roots (x y : R) := (x * y == y * x) && (y - x \in GRing.unit). Fixpoint uniq_roots rs := if rs is x :: rs' then all (diff_roots x) rs' && uniq_roots rs' else true. Lemma uniq_roots_prod_XsubC p rs : all (root p) rs -> uniq_roots rs -> exists q, p = q * \prod_(z <- rs) ('X - z%:P). Proof. elim: rs => [|z rs IHrs] /=; first by rewrite big_nil; exists p; rewrite mulr1. case/andP=> rpz rprs /andP[drs urs]; case: IHrs => {urs rprs}// q def_p. have [|q' def_q] := factor_theorem q z _; last first. by exists q'; rewrite big_cons mulrA -def_q. rewrite {p}def_p in rpz. elim/last_ind: rs drs rpz => [|rs t IHrs] /=; first by rewrite big_nil mulr1. rewrite all_rcons => /andP[/andP[/eqP czt Uzt] /IHrs{}IHrs]. rewrite -cats1 big_cat big_seq1 /= mulrA rootE hornerM_comm; last first. by rewrite /comm_poly hornerXsubC mulrBl mulrBr czt. rewrite hornerXsubC -opprB mulrN oppr_eq0 -(mul0r (t - z)). by rewrite (inj_eq (mulIr Uzt)) => /IHrs. Qed. Theorem max_ring_poly_roots p rs : p != 0 -> all (root p) rs -> uniq_roots rs -> size rs < size p. Proof. move=> nz_p _ /(@uniq_roots_prod_XsubC p)[// | q def_p]; rewrite def_p in nz_p *. have nz_q: q != 0 by apply: contraNneq nz_p => ->; rewrite mul0r. rewrite size_Mmonic ?monic_prod_XsubC // (polySpred nz_q) addSn /=. by rewrite size_prod_XsubC leq_addl. Qed. Lemma all_roots_prod_XsubC p rs : size p = (size rs).+1 -> all (root p) rs -> uniq_roots rs -> p = lead_coef p *: \prod_(z <- rs) ('X - z%:P). Proof. move=> size_p /uniq_roots_prod_XsubC def_p Urs. case/def_p: Urs => q -> {p def_p} in size_p *. have [q0 | nz_q] := eqVneq q 0; first by rewrite q0 mul0r size_poly0 in size_p. have{q nz_q size_p} /size_poly1P[c _ ->]: size q == 1. rewrite -(eqn_add2r (size rs)) add1n -size_p. by rewrite size_Mmonic ?monic_prod_XsubC // size_prod_XsubC addnS. by rewrite lead_coef_Mmonic ?monic_prod_XsubC // lead_coefC mul_polyC. Qed. End MaxRoots. Section FieldRoots. Variable F : fieldType. Implicit Types (p : {poly F}) (rs : seq F). Lemma poly2_root p : size p = 2 -> {r | root p r}. Proof. case: p => [[|p0 [|p1 []]] //= nz_p1]; exists (- p0 / p1). by rewrite /root addr_eq0 /= mul0r add0r mulrC divfK ?opprK. Qed. Lemma uniq_rootsE rs : uniq_roots rs = uniq rs. Proof. elim: rs => //= r rs ->; congr (_ && _); rewrite -has_pred1 -all_predC. by apply: eq_all => t; rewrite /diff_roots mulrC eqxx unitfE subr_eq0. Qed. Lemma root_ZXsubC (a b r : F) : a != 0 -> root (a *: 'X - b%:P) r = (r == b / a). Proof. move=> a0; rewrite rootE !hornerE. by rewrite -[r in RHS]divr1 eqr_div ?oner_neq0// mulr1 mulrC subr_eq0. Qed. Section UnityRoots. Variable n : nat. Lemma max_unity_roots rs : n > 0 -> all n.-unity_root rs -> uniq rs -> size rs <= n. Proof. move=> n_gt0 rs_n_1 Urs; have szPn := size_XnsubC (1 : F) n_gt0. by rewrite -ltnS -szPn max_poly_roots -?size_poly_eq0 ?szPn. Qed. Lemma mem_unity_roots rs : n > 0 -> all n.-unity_root rs -> uniq rs -> size rs = n -> n.-unity_root =i rs. Proof. move=> n_gt0 rs_n_1 Urs sz_rs_n x; rewrite -topredE /=. apply/idP/idP=> xn1; last exact: (allP rs_n_1). apply: contraFT (ltnn n) => not_rs_x. by rewrite -{1}sz_rs_n (@max_unity_roots (x :: rs)) //= ?xn1 ?not_rs_x. Qed. (* Showing the existence of a primitive root requires the theory in cyclic. *) Variable z : F. Hypothesis prim_z : n.-primitive_root z. Let zn := [seq z ^+ i | i <- index_iota 0 n]. Lemma factor_Xn_sub_1 : \prod_(0 <= i < n) ('X - (z ^+ i)%:P) = 'X^n - 1. Proof. transitivity (\prod_(w <- zn) ('X - w%:P)); first by rewrite big_map. have n_gt0: n > 0 := prim_order_gt0 prim_z. rewrite (@all_roots_prod_XsubC _ ('X^n - 1) zn); first 1 last. - by rewrite size_XnsubC // size_map size_iota subn0. - apply/allP=> _ /mapP[i _ ->] /=; rewrite rootE !hornerE. by rewrite exprAC (prim_expr_order prim_z) expr1n subrr. - rewrite uniq_rootsE map_inj_in_uniq ?iota_uniq // => i j. rewrite !mem_index_iota => ltin ltjn /eqP. by rewrite (eq_prim_root_expr prim_z) !modn_small // => /eqP. by rewrite (monicP (monicXnsubC 1 n_gt0)) scale1r. Qed. Lemma prim_rootP x : x ^+ n = 1 -> {i : 'I_n | x = z ^+ i}. Proof. move=> xn1; pose logx := [pred i : 'I_n | x == z ^+ i]. case: (pickP logx) => [i /eqP-> | no_i]; first by exists i. case: notF; suffices{no_i}: x \in zn. case/mapP=> i; rewrite mem_index_iota => lt_i_n def_x. by rewrite -(no_i (Ordinal lt_i_n)) /= -def_x. rewrite -root_prod_XsubC big_map factor_Xn_sub_1. by rewrite [root _ x]unity_rootE xn1. Qed. End UnityRoots. End FieldRoots. Section MapPolyRoots. Variables (F : fieldType) (R : unitRingType) (f : {rmorphism F -> R}). Lemma map_diff_roots x y : diff_roots (f x) (f y) = (x != y). Proof. rewrite /diff_roots -rmorphB // fmorph_unit // subr_eq0 //. by rewrite rmorph_comm // eqxx eq_sym. Qed. Lemma map_uniq_roots s : uniq_roots (map f s) = uniq s. Proof. elim: s => //= x s ->; congr (_ && _); elim: s => //= y s ->. by rewrite map_diff_roots -negb_or. Qed. End MapPolyRoots. Section AutPolyRoot. (* The action of automorphisms on roots of unity. *) Variable F : fieldType. Implicit Types u v : {rmorphism F -> F}. Lemma aut_prim_rootP u z n : n.-primitive_root z -> {k | coprime k n & u z = z ^+ k}. Proof. move=> prim_z; have:= prim_z; rewrite -(fmorph_primitive_root u) => prim_uz. have [[k _] /= def_uz] := prim_rootP prim_z (prim_expr_order prim_uz). by exists k; rewrite // -(prim_root_exp_coprime _ prim_z) -def_uz. Qed. Lemma aut_unity_rootP u z n : n > 0 -> z ^+ n = 1 -> {k | u z = z ^+ k}. Proof. by move=> _ /prim_order_exists[// | m /(aut_prim_rootP u)[k]]; exists k. Qed. Lemma aut_unity_rootC u v z n : n > 0 -> z ^+ n = 1 -> u (v z) = v (u z). Proof. move=> n_gt0 /(aut_unity_rootP _ n_gt0) def_z. have [[i def_uz] [j def_vz]] := (def_z u, def_z v). by rewrite def_vz def_uz !rmorphXn /= def_vz def_uz exprAC. Qed. End AutPolyRoot. Module UnityRootTheory. Notation "n .-unity_root" := (root_of_unity n) : unity_root_scope. Notation "n .-primitive_root" := (primitive_root_of_unity n) : unity_root_scope. Open Scope unity_root_scope. Definition unity_rootE := unity_rootE. Definition unity_rootP := @unity_rootP. Arguments unity_rootP {R n z}. Definition prim_order_exists := prim_order_exists. Notation prim_order_gt0 := prim_order_gt0. Notation prim_expr_order := prim_expr_order. Definition prim_expr_mod := prim_expr_mod. Definition prim_order_dvd := prim_order_dvd. Definition eq_prim_root_expr := eq_prim_root_expr. Definition rmorph_unity_root := rmorph_unity_root. Definition fmorph_unity_root := fmorph_unity_root. Definition fmorph_primitive_root := fmorph_primitive_root. Definition max_unity_roots := max_unity_roots. Definition mem_unity_roots := mem_unity_roots. Definition prim_rootP := prim_rootP. End UnityRootTheory. Module Export Pdeg2. Module Export Field. Section Pdeg2Field. Variable F : fieldType. Hypothesis nz2 : 2 != 0 :> F. 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 a2neq0 : 2 * a != 0. Proof. by rewrite mulf_neq0. Qed. Let sqa2neq0 : (2 * a) ^+ 2 != 0. Proof. exact: expf_neq0. Qed. Let aa4 : 4 * a * a = (2 * a)^+2. Proof. by rewrite expr2 mulrACA mulrA -natrM. Qed. Let splitr (x : F) : x = x / 2 + x / 2. Proof. by apply: (mulIf nz2); rewrite -mulrDl mulfVK// mulr_natr mulr2n. Qed. Let pE : p = a *: 'X^2 + b *: 'X + c%:P. Proof. apply/polyP => + /[!coefE] => -[|[|[|i]]] /=; rewrite !Monoid.simpm//. by rewrite nth_default// degp. Qed. Let delta := b ^+ 2 - 4 * a * c. Lemma deg2_poly_canonical : p = a *: (('X + (b / (2 * a))%:P)^+2 - (delta / (4 * a ^+ 2))%:P). Proof. rewrite pE sqrrD -!addrA scalerDr; congr +%R; rewrite addrA scalerDr; congr +%R. - rewrite -mulrDr -polyCD -!mul_polyC mulrA mulrAC -polyCM. by rewrite [a * _]mulrC mulrDl invfM -!mulrA mulVf// mulr1 -splitr. - rewrite [a ^+ 2]expr2 mulrA aa4 -polyC_exp -polyCB expr_div_n -mulrBl subKr. by rewrite scale_polyC mulrCA mulrACA aa4 mulrCA mulfV// mulr1. Qed. Variable r : F. Hypothesis r_sqrt_delta : r ^+ 2 = delta. Let r1 := (- b - r) / (2 * a). Let r2 := (- b + r) / (2 * a). Lemma deg2_poly_factor : p = a *: ('X - r1%:P) * ('X - r2%:P). Proof. rewrite [p]deg2_poly_canonical//= -/a -/b -/c -/delta /r1 /r2. rewrite ![(- b + _) * _]mulrDl 2!polyCD 2!opprD 2!addrA !mulNr !polyCN !opprK. rewrite -scalerAl [in RHS]mulrC -subr_sqr -polyC_exp -[4]/(2 * 2)%:R natrM. by rewrite -expr2 -exprMn [in RHS]exprMn exprVn r_sqrt_delta. Qed. Lemma deg2_poly_root1 : root p r1. Proof. apply/factor_theorem. by exists (a *: ('X - r2%:P)); rewrite deg2_poly_factor -!scalerAl mulrC. Qed. Lemma deg2_poly_root2 : root p r2. Proof. apply/factor_theorem. by exists (a *: ('X - r1%:P)); rewrite deg2_poly_factor -!scalerAl. Qed. End Pdeg2Field. End Field. Module FieldMonic. Section Pdeg2FieldMonic. Variable F : fieldType. Hypothesis nz2 : 2 != 0 :> F. 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 a1 : a = 1. Proof. by move: (monicP monicp); rewrite lead_coefE degp. Qed. Let delta := b ^+ 2 - 4 * c. Lemma deg2_poly_canonical : p = (('X + (b / 2)%:P)^+2 - (delta / 4)%:P). Proof. by rewrite [p]deg2_poly_canonical// -/a a1 scale1r expr1n !mulr1. Qed. Variable r : F. Hypothesis r_sqrt_delta : r ^+ 2 = delta. Let r1 := (- b - r) / 2. Let r2 := (- b + r) / 2. Lemma deg2_poly_factor : p = ('X - r1%:P) * ('X - r2%:P). Proof. by rewrite [p](@deg2_poly_factor _ _ _ _ r)// -/a a1 !mulr1 ?scale1r. Qed. Lemma deg2_poly_root1 : root p r1. Proof. rewrite /r1 -[2]mulr1 -[X in 2 * X]a1. by apply: deg2_poly_root1; rewrite // -/a a1 mulr1. Qed. Lemma deg2_poly_root2 : root p r2. Proof. rewrite /r2 -[2]mulr1 -[X in 2 * X]a1. by apply: deg2_poly_root2; rewrite // -/a a1 mulr1. Qed. End Pdeg2FieldMonic. End FieldMonic. End Pdeg2. Section DecField. Variable F : decFieldType. Lemma dec_factor_theorem (p : {poly F}) : {s : seq F & {q : {poly F} | p = q * \prod_(x <- s) ('X - x%:P) /\ (q != 0 -> forall x, ~~ root q x)}}. Proof. pose polyT (p : seq F) := (foldr (fun c f => f * 'X_0 + c%:T) (0%R)%:T p)%T. have eval_polyT (q : {poly F}) x : GRing.eval [:: x] (polyT q) = q.[x]. by rewrite /horner; elim: (val q) => //= ? ? ->. have [n] := ubnP (size p); elim: n => // n IHn in p *. have /decPcases /= := @satP F [::] ('exists 'X_0, polyT p == 0%T). case: ifP => [_ /sig_eqW[x]|_ noroot]; last first. exists [::], p; rewrite big_nil mulr1; split => // p_neq0 x. by apply/negP=> /rootP rpx; apply: noroot; exists x; rewrite eval_polyT. rewrite eval_polyT => /rootP/factor_theorem/sig_eqW[p1 ->]. have [->|nz_p1] := eqVneq p1 0; first by exists [::], 0; rewrite !mul0r eqxx. rewrite size_Mmonic ?monicXsubC // size_XsubC addn2 => /IHn[s [q [-> irr_q]]]. by exists (rcons s x), q; rewrite -cats1 big_cat big_seq1 mulrA. Qed. End DecField. Module PreClosedField. Section UseAxiom. Variable F : fieldType. Hypothesis closedF : GRing.closed_field_axiom F. Implicit Type p : {poly F}. Lemma closed_rootP p : reflect (exists x, root p x) (size p != 1). Proof. have [-> | nz_p] := eqVneq p 0. by rewrite size_poly0; left; exists 0; rewrite root0. rewrite neq_ltn [in _ < 1]polySpred //=. apply: (iffP idP) => [p_gt1 | [a]]; last exact: root_size_gt1. pose n := (size p).-1; have n_gt0: n > 0 by rewrite -ltnS -polySpred. have [a Dan] := closedF (fun i => - p`_i / lead_coef p) n_gt0. exists a; apply/rootP; rewrite horner_coef polySpred // big_ord_recr /= -/n. rewrite {}Dan mulr_sumr -big_split big1 //= => i _. by rewrite -!mulrA mulrCA mulNr mulVKf ?subrr ?lead_coef_eq0. Qed. Lemma closed_nonrootP p : reflect (exists x, ~~ root p x) (p != 0). Proof. apply: (iffP idP) => [nz_p | [x]]; last first. by apply: contraNneq => ->; apply: root0. have [[x /rootP p1x0]|] := altP (closed_rootP (p - 1)). by exists x; rewrite -[p](subrK 1) /root hornerD p1x0 add0r hornerC oner_eq0. rewrite negbK => /size_poly1P[c _ /(canRL (subrK 1)) Dp]. by exists 0; rewrite Dp -raddfD polyC_eq0 rootC in nz_p *. Qed. End UseAxiom. End PreClosedField. Section ClosedField. Variable F : closedFieldType. Implicit Type p : {poly F}. Let closedF := @solve_monicpoly F. Lemma closed_rootP p : reflect (exists x, root p x) (size p != 1). Proof. exact: PreClosedField.closed_rootP. Qed. Lemma closed_nonrootP p : reflect (exists x, ~~ root p x) (p != 0). Proof. exact: PreClosedField.closed_nonrootP. Qed. Lemma closed_field_poly_normal p : {r : seq F | p = lead_coef p *: \prod_(z <- r) ('X - z%:P)}. Proof. apply: sig_eqW; have [r [q [->]]] /= := dec_factor_theorem p. have [->|] := eqVneq; first by exists [::]; rewrite mul0r lead_coef0 scale0r. have [[x rqx ? /(_ isT x) /negP /(_ rqx)] //|] := altP (closed_rootP q). rewrite negbK => /size_poly1P [c c_neq0-> _ _]; exists r. rewrite mul_polyC lead_coefZ (monicP _) ?mulr1 //. by rewrite monic_prod => // i; rewrite monicXsubC. Qed. End ClosedField.
Basic.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Anne Baanen -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.Data.Matrix.RowCol import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.GroupTheory.Perm.Fin import Mathlib.LinearAlgebra.Alternating.Basic import Mathlib.LinearAlgebra.Matrix.SemiringInverse /-! # Determinant of a matrix This file defines the determinant of a matrix, `Matrix.det`, and its essential properties. ## Main definitions - `Matrix.det`: the determinant of a square matrix, as a sum over permutations - `Matrix.detRowAlternating`: the determinant, as an `AlternatingMap` in the rows of the matrix ## Main results - `det_mul`: the determinant of `A * B` is the product of determinants - `det_zero_of_row_eq`: the determinant is zero if there is a repeated row - `det_block_diagonal`: the determinant of a block diagonal matrix is a product of the blocks' determinants ## Implementation notes It is possible to configure `simp` to compute determinants. See the file `MathlibTest/matrix.lean` for some examples. -/ universe u v w z open Equiv Equiv.Perm Finset Function namespace Matrix variable {m n : Type*} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] variable {R : Type v} [CommRing R] local notation "ε " σ:arg => ((sign σ : ℤ) : R) /-- `det` is an `AlternatingMap` in the rows of the matrix. -/ def detRowAlternating : (n → R) [⋀^n]→ₗ[R] R := MultilinearMap.alternatization ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj) /-- The determinant of a matrix given by the Leibniz formula. -/ abbrev det (M : Matrix n n R) : R := detRowAlternating M theorem det_apply (M : Matrix n n R) : M.det = ∑ σ : Perm n, Equiv.Perm.sign σ • ∏ i, M (σ i) i := MultilinearMap.alternatization_apply _ M -- This is what the old definition was. We use it to avoid having to change the old proofs below theorem det_apply' (M : Matrix n n R) : M.det = ∑ σ : Perm n, ε σ * ∏ i, M (σ i) i := by simp [det_apply, Units.smul_def] theorem det_eq_detp_sub_detp (M : Matrix n n R) : M.det = M.detp 1 - M.detp (-1) := by rw [det_apply, ← Equiv.sum_comp (Equiv.inv (Perm n)), ← ofSign_disjUnion, sum_disjUnion] simp_rw [inv_apply, sign_inv, sub_eq_add_neg, detp, ← sum_neg_distrib] refine congr_arg₂ (· + ·) (sum_congr rfl fun σ hσ ↦ ?_) (sum_congr rfl fun σ hσ ↦ ?_) <;> rw [mem_ofSign.mp hσ, ← Equiv.prod_comp σ] <;> simp @[simp] theorem det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i := by rw [det_apply'] refine (Finset.sum_eq_single 1 ?_ ?_).trans ?_ · rintro σ - h2 obtain ⟨x, h3⟩ := not_forall.1 (mt Equiv.ext h2) convert mul_zero (ε σ) apply Finset.prod_eq_zero (mem_univ x) exact if_neg h3 · simp · simp theorem det_zero (_ : Nonempty n) : det (0 : Matrix n n R) = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_zero @[simp] theorem det_one : det (1 : Matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one] theorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply] @[simp] theorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R → R) = Function.const _ 1 := by ext exact det_isEmpty theorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 := haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h det_isEmpty /-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element. Although `Unique` implies `DecidableEq` and `Fintype`, the instances might not be syntactically equal. Thus, we need to fill in the args explicitly. -/ @[simp] theorem det_unique {n : Type*} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) : det A = A default default := by simp [det_apply, univ_unique] theorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) : det A = A k k := by have := uniqueOfSubsingleton k convert det_unique A theorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) : det A = A k k := haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le det_eq_elem_of_subsingleton _ _ theorem det_mul_aux {M N : Matrix n n R} {p : n → n} (H : ¬Bijective p) : (∑ σ : Perm n, ε σ * ∏ x, M (σ x) (p x) * N (p x) x) = 0 := by obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by rw [← Finite.injective_iff_bijective, Injective] at H push_neg at H exact H exact sum_involution (fun σ _ => σ * Equiv.swap i j) (fun σ _ => by have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) := Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]) simp [this, sign_swap hij, -sign_swap', prod_mul_distrib]) (fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ => mul_swap_involutive i j σ @[simp] theorem det_mul (M N : Matrix n n R) : det (M * N) = det M * det N := calc det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ] rw [Finset.sum_comm] _ = ∑ p : n → n with Bijective p, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by refine (sum_subset (filter_subset _ _) fun f _ hbij ↦ det_mul_aux ?_).symm simpa only [mem_filter_univ] using hbij _ = ∑ τ : Perm n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (τ i) * N (τ i) i := sum_bij (fun p h ↦ Equiv.ofBijective p (mem_filter.1 h).2) (fun _ _ ↦ mem_univ _) (fun _ _ _ _ h ↦ by injection h) (fun b _ ↦ ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩) fun _ _ ↦ rfl _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * ε τ * ∏ j, M (τ j) (σ j) := by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc] _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * (ε σ * ε τ) * ∏ i, M (τ i) i := (sum_congr rfl fun σ _ => Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ fun τ => by have : (∏ j, M (τ j) (σ j)) = ∏ j, M ((τ * σ⁻¹) j) j := by rw [← (σ⁻¹ : _ ≃ _).prod_comp] simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply] have h : ε σ * ε (τ * σ⁻¹) = ε τ := calc ε σ * ε (τ * σ⁻¹) = ε (τ * σ⁻¹ * σ) := by rw [mul_comm, sign_mul (τ * σ⁻¹)] simp only [Int.cast_mul, Units.val_mul] _ = ε τ := by simp only [inv_mul_cancel_right] simp_rw [Equiv.coe_mulRight, h] simp only [this]) _ = det M * det N := by simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm, mul_assoc] /-- The determinant of a matrix, as a monoid homomorphism. -/ def detMonoidHom : Matrix n n R →* R where toFun := det map_one' := det_one map_mul' := det_mul @[simp] theorem coe_detMonoidHom : (detMonoidHom : Matrix n n R → R) = det := rfl /-- On square matrices, `mul_comm` applies under `det`. -/ theorem det_mul_comm (M N : Matrix m m R) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] /-- On square matrices, `mul_left_comm` applies under `det`. -/ theorem det_mul_left_comm (M N P : Matrix m m R) : det (M * (N * P)) = det (N * (M * P)) := by rw [← Matrix.mul_assoc, ← Matrix.mul_assoc, det_mul, det_mul_comm M N, ← det_mul] /-- On square matrices, `mul_right_comm` applies under `det`. -/ theorem det_mul_right_comm (M N P : Matrix m m R) : det (M * N * P) = det (M * P * N) := by rw [Matrix.mul_assoc, Matrix.mul_assoc, det_mul, det_mul_comm N P, ← det_mul] -- TODO(https://github.com/leanprover-community/mathlib4/issues/6607): fix elaboration so `val` isn't needed theorem det_units_conj (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det (M.val * N * M⁻¹.val) = det N := by rw [det_mul_right_comm, Units.mul_inv, one_mul] -- TODO(https://github.com/leanprover-community/mathlib4/issues/6607): fix elaboration so `val` isn't needed theorem det_units_conj' (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det (M⁻¹.val * N * ↑M.val) = det N := det_units_conj M⁻¹ N /-- Transposing a matrix preserves the determinant. -/ @[simp] theorem det_transpose (M : Matrix n n R) : Mᵀ.det = M.det := by rw [det_apply', det_apply'] refine Fintype.sum_bijective _ inv_involutive.bijective _ _ ?_ intro σ rw [sign_inv] congr 1 apply Fintype.prod_equiv σ simp /-- Permuting the columns changes the sign of the determinant. -/ theorem det_permute (σ : Perm n) (M : Matrix n n R) : (M.submatrix σ id).det = Perm.sign σ * M.det := ((detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_perm M σ).trans (by simp [Units.smul_def]) /-- Permuting the rows changes the sign of the determinant. -/ theorem det_permute' (σ : Perm n) (M : Matrix n n R) : (M.submatrix id σ).det = Perm.sign σ * M.det := by rw [← det_transpose, transpose_submatrix, det_permute, det_transpose] /-- Permuting rows and columns with the same equivalence does not change the determinant. -/ @[simp] theorem det_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m R) : det (A.submatrix e e) = det A := by rw [det_apply', det_apply'] apply Fintype.sum_equiv (Equiv.permCongr e) intro σ rw [Equiv.Perm.sign_permCongr e σ] congr 1 apply Fintype.prod_equiv e intro i rw [Equiv.permCongr_apply, Equiv.symm_apply_apply, submatrix_apply] /-- Permuting rows and columns with two equivalences does not change the absolute value of the determinant. -/ @[simp] theorem abs_det_submatrix_equiv_equiv {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (e₁ e₂ : n ≃ m) (A : Matrix m m R) : |(A.submatrix e₁ e₂).det| = |A.det| := by have hee : e₂ = e₁.trans (e₁.symm.trans e₂) := by ext; simp rw [hee] change |((A.submatrix id (e₁.symm.trans e₂)).submatrix e₁ e₁).det| = |A.det| rw [Matrix.det_submatrix_equiv_self, Matrix.det_permute', abs_mul, abs_unit_intCast, one_mul] /-- Reindexing both indices along the same equivalence preserves the determinant. For the `simp` version of this lemma, see `det_submatrix_equiv_self`; this one is unsuitable because `Matrix.reindex_apply` unfolds `reindex` first. -/ theorem det_reindex_self (e : m ≃ n) (A : Matrix m m R) : det (reindex e e A) = det A := det_submatrix_equiv_self e.symm A /-- Reindexing both indices along equivalences preserves the absolute of the determinant. For the `simp` version of this lemma, see `abs_det_submatrix_equiv_equiv`; this one is unsuitable because `Matrix.reindex_apply` unfolds `reindex` first. -/ theorem abs_det_reindex {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (e₁ e₂ : m ≃ n) (A : Matrix m m R) : |det (reindex e₁ e₂ A)| = |det A| := abs_det_submatrix_equiv_equiv e₁.symm e₂.symm A theorem det_smul (A : Matrix n n R) (c : R) : det (c • A) = c ^ Fintype.card n * det A := calc det (c • A) = det ((diagonal fun _ => c) * A) := by rw [smul_eq_diagonal_mul] _ = det (diagonal fun _ => c) * det A := det_mul _ _ _ = c ^ Fintype.card n * det A := by simp @[simp] theorem det_smul_of_tower {α} [Monoid α] [MulAction α R] [IsScalarTower α R R] [SMulCommClass α R R] (c : α) (A : Matrix n n R) : det (c • A) = c ^ Fintype.card n • det A := by rw [← smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul] theorem det_neg (A : Matrix n n R) : det (-A) = (-1) ^ Fintype.card n * det A := by rw [← det_smul, neg_one_smul] /-- A variant of `Matrix.det_neg` with scalar multiplication by `Units ℤ` instead of multiplication by `R`. -/ theorem det_neg_eq_smul (A : Matrix n n R) : det (-A) = (-1 : Units ℤ) ^ Fintype.card n • det A := by rw [← det_smul_of_tower, Units.neg_smul, one_smul] /-- Multiplying each row by a fixed `v i` multiplies the determinant by the product of the `v`s. -/ theorem det_mul_row (v : n → R) (A : Matrix n n R) : det (of fun i j => v j * A i j) = (∏ i, v i) * det A := calc det (of fun i j => v j * A i j) = det (A * diagonal v) := congr_arg det <| by ext simp [mul_comm] _ = (∏ i, v i) * det A := by rw [det_mul, det_diagonal, mul_comm] /-- Multiplying each column by a fixed `v j` multiplies the determinant by the product of the `v`s. -/ theorem det_mul_column (v : n → R) (A : Matrix n n R) : det (of fun i j => v i * A i j) = (∏ i, v i) * det A := MultilinearMap.map_smul_univ _ v A @[simp] theorem det_pow (M : Matrix m m R) (n : ℕ) : det (M ^ n) = det M ^ n := (detMonoidHom : Matrix m m R →* R).map_pow M n section HomMap variable {S : Type w} [CommRing S] theorem _root_.RingHom.map_det (f : R →+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) := by simp [Matrix.det_apply', map_sum f, map_prod f] theorem _root_.RingEquiv.map_det (f : R ≃+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) := f.toRingHom.map_det _ theorem _root_.AlgHom.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S →ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) := f.toRingHom.map_det _ theorem _root_.AlgEquiv.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S ≃ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) := f.toAlgHom.map_det _ @[norm_cast] theorem _root_.Int.cast_det (M : Matrix n n ℤ) : (M.det : R) = (M.map fun x ↦ (x : R)).det := Int.castRingHom R |>.map_det M @[norm_cast] theorem _root_.Rat.cast_det {F : Type*} [Field F] [CharZero F] (M : Matrix n n ℚ) : (M.det : F) = (M.map fun x ↦ (x : F)).det := Rat.castHom F |>.map_det M end HomMap @[simp] theorem det_conjTranspose [StarRing R] (M : Matrix m m R) : det Mᴴ = star (det M) := ((starRingEnd R).map_det _).symm.trans <| congr_arg star M.det_transpose section DetZero /-! ### `det_zero` section Prove that a matrix with a repeated column has determinant equal to zero. -/ theorem det_eq_zero_of_row_eq_zero {A : Matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_coord_zero i (funext h) theorem det_eq_zero_of_column_eq_zero {A : Matrix n n R} (j : n) (h : ∀ i, A i j = 0) : det A = 0 := by rw [← det_transpose] exact det_eq_zero_of_row_eq_zero j h variable {M : Matrix n n R} {i j : n} /-- If a matrix has a repeated row, the determinant will be zero. -/ theorem det_zero_of_row_eq (i_ne_j : i ≠ j) (hij : M i = M j) : M.det = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_eq_zero_of_eq M hij i_ne_j /-- If a matrix has a repeated column, the determinant will be zero. -/ theorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : ∀ k, M k i = M k j) : M.det = 0 := by rw [← det_transpose, det_zero_of_row_eq i_ne_j] exact funext hij /-- If we repeat a row of a matrix, we get a matrix of determinant zero. -/ theorem det_updateRow_eq_zero (h : i ≠ j) : (M.updateRow j (M i)).det = 0 := det_zero_of_row_eq h (by simp [h]) /-- If we repeat a column of a matrix, we get a matrix of determinant zero. -/ theorem det_updateCol_eq_zero (h : i ≠ j) : (M.updateCol j (fun k ↦ M k i)).det = 0 := det_zero_of_column_eq h (by simp [h]) end DetZero theorem det_updateRow_add (M : Matrix n n R) (j : n) (u v : n → R) : det (updateRow M j <| u + v) = det (updateRow M j u) + det (updateRow M j v) := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_update_add M j u v theorem det_updateCol_add (M : Matrix n n R) (j : n) (u v : n → R) : det (updateCol M j <| u + v) = det (updateCol M j u) + det (updateCol M j v) := by rw [← det_transpose, ← updateRow_transpose, det_updateRow_add] simp [updateRow_transpose, det_transpose] theorem det_updateRow_smul (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateRow M j <| s • u) = s * det (updateRow M j u) := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_update_smul M j s u theorem det_updateCol_smul (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateCol M j <| s • u) = s * det (updateCol M j u) := by rw [← det_transpose, ← updateRow_transpose, det_updateRow_smul] simp [updateRow_transpose, det_transpose] theorem det_updateRow_smul_left (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateRow (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateRow M j u) := MultilinearMap.map_update_smul_left _ M j s u theorem det_updateCol_smul_left (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateCol (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateCol M j u) := by rw [← det_transpose, ← updateRow_transpose, transpose_smul, det_updateRow_smul_left] simp [updateRow_transpose, det_transpose] theorem det_updateRow_sum_aux (M : Matrix n n R) {j : n} (s : Finset n) (hj : j ∉ s) (c : n → R) (a : R) : (M.updateRow j (a • M j + ∑ k ∈ s, (c k) • M k)).det = a • M.det := by induction s using Finset.induction_on with | empty => rw [Finset.sum_empty, add_zero, smul_eq_mul, det_updateRow_smul, updateRow_eq_self] | insert k _ hk h_ind => have h : k ≠ j := fun h ↦ (h ▸ hj) (Finset.mem_insert_self _ _) rw [Finset.sum_insert hk, add_comm ((c k) • M k), ← add_assoc, det_updateRow_add, det_updateRow_smul, det_updateRow_eq_zero h, mul_zero, add_zero, h_ind] exact fun h ↦ hj (Finset.mem_insert_of_mem h) /-- If we replace a row of a matrix by a linear combination of its rows, then the determinant is multiplied by the coefficient of that row. -/ theorem det_updateRow_sum (A : Matrix n n R) (j : n) (c : n → R) : (A.updateRow j (∑ k, (c k) • A k)).det = (c j) • A.det := by convert det_updateRow_sum_aux A (Finset.univ.erase j) (Finset.univ.notMem_erase j) c (c j) rw [← Finset.univ.add_sum_erase _ (Finset.mem_univ j)] /-- If we replace a column of a matrix by a linear combination of its columns, then the determinant is multiplied by the coefficient of that column. -/ theorem det_updateCol_sum (A : Matrix n n R) (j : n) (c : n → R) : (A.updateCol j (fun k ↦ ∑ i, (c i) • A k i)).det = (c j) • A.det := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] convert det_updateRow_sum A.transpose j c simp only [smul_eq_mul, Finset.sum_apply, Pi.smul_apply, transpose_apply] section DetEq /-! ### `det_eq` section Lemmas showing the determinant is invariant under a variety of operations. -/ theorem det_eq_of_eq_mul_det_one {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1) (hA : A = B * C) : det A = det B := calc det A = det (B * C) := congr_arg _ hA _ = det B * det C := det_mul _ _ _ = det B := by rw [hC, mul_one] theorem det_eq_of_eq_det_one_mul {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1) (hA : A = C * B) : det A = det B := calc det A = det (C * B) := congr_arg _ hA _ = det C * det B := det_mul _ _ _ = det B := by rw [hC, one_mul] theorem det_updateRow_add_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) : det (updateRow A i (A i + A j)) = det A := by simp [det_updateRow_add, det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)] theorem det_updateCol_add_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) : det (updateCol A i fun k => A k i + A k j) = det A := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] exact det_updateRow_add_self Aᵀ hij theorem det_updateRow_add_smul_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) (c : R) : det (updateRow A i (A i + c • A j)) = det A := by simp [det_updateRow_add, det_updateRow_smul, det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)] theorem det_updateCol_add_smul_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) (c : R) : det (updateCol A i fun k => A k i + c • A k j) = det A := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] exact det_updateRow_add_smul_self Aᵀ hij c theorem det_eq_zero_of_not_linearIndependent_rows [IsDomain R] {A : Matrix m m R} (hA : ¬ LinearIndependent R (fun i ↦ A i)) : det A = 0 := by obtain ⟨c, hc0, i, hci⟩ := Fintype.not_linearIndependent_iff.1 hA have h0 := A.det_updateRow_sum i c rwa [det_eq_zero_of_row_eq_zero (i := i) (fun j ↦ by simp [hc0]), smul_eq_mul, eq_comm, mul_eq_zero_iff_left hci] at h0 theorem linearIndependent_rows_of_det_ne_zero [IsDomain R] {A : Matrix m m R} (hA : A.det ≠ 0) : LinearIndependent R (fun i ↦ A i) := by contrapose! hA exact det_eq_zero_of_not_linearIndependent_rows hA theorem linearIndependent_cols_of_det_ne_zero [IsDomain R] {A : Matrix m m R} (hA : A.det ≠ 0) : LinearIndependent R A.col := Matrix.linearIndependent_rows_of_det_ne_zero (by simpa [Matrix.col]) theorem det_eq_zero_of_not_linearIndependent_cols [IsDomain R] {A : Matrix m m R} (hA : ¬ LinearIndependent R (fun i ↦ Aᵀ i)) : det A = 0 := by contrapose! hA exact linearIndependent_cols_of_det_ne_zero hA theorem det_eq_of_forall_row_eq_smul_add_const_aux {A B : Matrix n n R} {s : Finset n} : ∀ (c : n → R) (_ : ∀ i, i ∉ s → c i = 0) (k : n) (_ : k ∉ s) (_ : ∀ i j, A i j = B i j + c i * B k j), det A = det B := by induction s using Finset.induction_on generalizing B with | empty => rintro c hs k - A_eq have : ∀ i, c i = 0 := by grind congr ext i j rw [A_eq, this, zero_mul, add_zero] | insert i s _hi ih => intro c hs k hk A_eq have hAi : A i = B i + c i • B k := funext (A_eq i) rw [@ih (updateRow B i (A i)) (Function.update c i 0), hAi, det_updateRow_add_smul_self] · exact mt (fun h => show k ∈ insert i s from h ▸ Finset.mem_insert_self _ _) hk · intro i' hi' rw [Function.update_apply] split_ifs with hi'i · rfl · exact hs i' fun h => hi' ((Finset.mem_insert.mp h).resolve_left hi'i) · exact k · exact fun h => hk (Finset.mem_insert_of_mem h) · intro i' j' rw [updateRow_apply, Function.update_apply] split_ifs with hi'i · simp [hi'i] rw [A_eq, updateRow_ne fun h : k = i => hk <| h ▸ Finset.mem_insert_self k s] /-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/ theorem det_eq_of_forall_row_eq_smul_add_const {A B : Matrix n n R} (c : n → R) (k : n) (hk : c k = 0) (A_eq : ∀ i j, A i j = B i j + c i * B k j) : det A = det B := det_eq_of_forall_row_eq_smul_add_const_aux c (fun i => not_imp_comm.mp fun hi => Finset.mem_erase.mpr ⟨mt (fun h : i = k => show c i = 0 from h.symm ▸ hk) hi, Finset.mem_univ i⟩) k (Finset.notMem_erase k Finset.univ) A_eq theorem det_eq_of_forall_row_eq_smul_add_pred_aux {n : ℕ} (k : Fin (n + 1)) : ∀ (c : Fin n → R) (_hc : ∀ i : Fin n, k < i.succ → c i = 0) {M N : Matrix (Fin n.succ) (Fin n.succ) R} (_h0 : ∀ j, M 0 j = N 0 j) (_hsucc : ∀ (i : Fin n) (j), M i.succ j = N i.succ j + c i * M (Fin.castSucc i) j), det M = det N := by refine Fin.induction ?_ (fun k ih => ?_) k <;> intro c hc M N h0 hsucc · congr ext i j refine Fin.cases (h0 j) (fun i => ?_) i rw [hsucc, hc i (Fin.succ_pos _), zero_mul, add_zero] set M' := updateRow M k.succ (N k.succ) with hM' have hM : M = updateRow M' k.succ (M' k.succ + c k • M (Fin.castSucc k)) := by ext i j by_cases hi : i = k.succ · simp [hi, hM', hsucc, updateRow_self] rw [updateRow_ne hi, hM', updateRow_ne hi] have k_ne_succ : (Fin.castSucc k) ≠ k.succ := (Fin.castSucc_lt_succ k).ne have M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) := (updateRow_ne k_ne_succ).symm rw [hM, M_k, det_updateRow_add_smul_self M' k_ne_succ.symm, ih (Function.update c k 0)] · intro i hi rw [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff] at hi rw [Function.update_apply] split_ifs with hik · rfl exact hc _ (Fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (Ne.symm hik))) · rwa [hM', updateRow_ne (Fin.succ_ne_zero _).symm] intro i j rw [Function.update_apply] split_ifs with hik · rw [zero_mul, add_zero, hM', hik, updateRow_self] rw [hM', updateRow_ne ((Fin.succ_injective _).ne hik), hsucc] by_cases hik2 : k < i · simp [hc i (Fin.succ_lt_succ_iff.mpr hik2)] rw [updateRow_ne] apply ne_of_lt rwa [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff, ← not_lt] /-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/ theorem det_eq_of_forall_row_eq_smul_add_pred {n : ℕ} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R} (c : Fin n → R) (A_zero : ∀ j, A 0 j = B 0 j) (A_succ : ∀ (i : Fin n) (j), A i.succ j = B i.succ j + c i * A (Fin.castSucc i) j) : det A = det B := det_eq_of_forall_row_eq_smul_add_pred_aux (Fin.last _) c (fun _ hi => absurd hi (not_lt_of_ge (Fin.le_last _))) A_zero A_succ /-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/ theorem det_eq_of_forall_col_eq_smul_add_pred {n : ℕ} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R} (c : Fin n → R) (A_zero : ∀ i, A i 0 = B i 0) (A_succ : ∀ (i) (j : Fin n), A i j.succ = B i j.succ + c j * A i (Fin.castSucc j)) : det A = det B := by rw [← det_transpose A, ← det_transpose B] exact det_eq_of_forall_row_eq_smul_add_pred c A_zero fun i j => A_succ j i end DetEq @[simp] theorem det_blockDiagonal {o : Type*} [Fintype o] [DecidableEq o] (M : o → Matrix n n R) : (blockDiagonal M).det = ∏ k, (M k).det := by -- Rewrite the determinants as a sum over permutations. simp_rw [det_apply'] -- The right hand side is a product of sums, rewrite it as a sum of products. rw [Finset.prod_sum] simp_rw [Finset.prod_attach_univ, Finset.univ_pi_univ] -- We claim that the only permutations contributing to the sum are those that -- preserve their second component. let preserving_snd : Finset (Equiv.Perm (n × o)) := {σ | ∀ x, (σ x).snd = x.snd} have mem_preserving_snd : ∀ {σ : Equiv.Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd := fun {σ} => Finset.mem_filter.trans ⟨fun h => h.2, fun h => ⟨Finset.mem_univ _, h⟩⟩ rw [← Finset.sum_subset (Finset.subset_univ preserving_snd) _] -- And that these are in bijection with `o → Equiv.Perm m`. · refine (Finset.sum_bij (fun σ _ => prodCongrLeft fun k ↦ σ k (mem_univ k)) ?_ ?_ ?_ ?_).symm · intro σ _ rw [mem_preserving_snd] rintro ⟨-, x⟩ simp only [prodCongrLeft_apply] · intro σ _ σ' _ eq ext x hx k simp only at eq have : ∀ k x, prodCongrLeft (fun k => σ k (Finset.mem_univ _)) (k, x) = prodCongrLeft (fun k => σ' k (Finset.mem_univ _)) (k, x) := fun k x => by rw [eq] simp only [prodCongrLeft_apply, Prod.mk_inj] at this exact (this k x).1 · intro σ hσ rw [mem_preserving_snd] at hσ have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd := by intro x conv_rhs => rw [← Perm.apply_inv_self σ x, hσ] have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k) := by intro k x ext · simp only · simp only [hσ] have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k) := by grind refine ⟨fun k _ => ⟨fun x => (σ (x, k)).fst, fun x => (σ⁻¹ (x, k)).fst, ?_, ?_⟩, ?_, ?_⟩ · intro x simp only [mk_apply_eq, inv_apply_self] · intro x simp only [mk_inv_apply_eq, apply_inv_self] · apply Finset.mem_univ · ext ⟨k, x⟩ · simp only [coe_fn_mk, prodCongrLeft_apply] · simp only [prodCongrLeft_apply, hσ] · intro σ _ rw [Finset.prod_mul_distrib, ← Finset.univ_product_univ, Finset.prod_product_right] simp only [sign_prodCongrLeft, Units.coe_prod, Int.cast_prod, blockDiagonal_apply_eq, prodCongrLeft_apply] · intro σ _ hσ rw [mem_preserving_snd] at hσ obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ rw [Finset.prod_eq_zero (Finset.mem_univ (k, x)), mul_zero] rw [blockDiagonal_apply_ne] exact hkx /-- The determinant of a 2×2 block matrix with the lower-left block equal to zero is the product of the determinants of the diagonal blocks. For the generalization to any number of blocks, see `Matrix.det_of_upperTriangular`. -/ @[simp] theorem det_fromBlocks_zero₂₁ (A : Matrix m m R) (B : Matrix m n R) (D : Matrix n n R) : (Matrix.fromBlocks A B 0 D).det = A.det * D.det := by classical simp_rw [det_apply'] convert Eq.symm <| sum_subset (M := R) (subset_univ ((sumCongrHom m n).range : Set (Perm (m ⊕ n))).toFinset) ?_ · simp_rw [sum_mul_sum, ← sum_product', univ_product_univ] refine sum_nbij (fun σ ↦ σ.fst.sumCongr σ.snd) ?_ ?_ ?_ ?_ · intro σ₁₂ _ simp · intro σ₁ _ σ₂ _ dsimp only intro h have h2 : ∀ x, Perm.sumCongr σ₁.fst σ₁.snd x = Perm.sumCongr σ₂.fst σ₂.snd x := DFunLike.congr_fun h simp only [Sum.map_inr, Sum.map_inl, Perm.sumCongr_apply, Sum.forall, Sum.inl.injEq, Sum.inr.injEq] at h2 ext x · exact h2.left x · exact h2.right x · intro σ hσ rw [mem_coe, Set.mem_toFinset] at hσ obtain ⟨σ₁₂, hσ₁₂⟩ := hσ use σ₁₂ rw [← hσ₁₂] simp · simp only [forall_prop_of_true, Prod.forall, mem_univ] intro σ₁ σ₂ rw [Fintype.prod_sum_type] simp_rw [Equiv.sumCongr_apply, Sum.map_inr, Sum.map_inl, fromBlocks_apply₁₁, fromBlocks_apply₂₂] rw [mul_mul_mul_comm] congr rw [sign_sumCongr, Units.val_mul, Int.cast_mul] · rintro σ - hσn have h1 : ¬∀ x, ∃ y, Sum.inl y = σ (Sum.inl x) := by rw [Set.mem_toFinset] at hσn simpa only [Set.MapsTo, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff] using mt mem_sumCongrHom_range_of_perm_mapsTo_inl hσn obtain ⟨a, ha⟩ := not_forall.mp h1 rcases hx : σ (Sum.inl a) with a2 | b · have hn := (not_exists.mp ha) a2 exact absurd hx.symm hn · rw [Finset.prod_eq_zero (Finset.mem_univ (Sum.inl a)), mul_zero] rw [hx, fromBlocks_apply₂₁, zero_apply] /-- The determinant of a 2×2 block matrix with the upper-right block equal to zero is the product of the determinants of the diagonal blocks. For the generalization to any number of blocks, see `Matrix.det_of_lowerTriangular`. -/ @[simp] theorem det_fromBlocks_zero₁₂ (A : Matrix m m R) (C : Matrix n m R) (D : Matrix n n R) : (Matrix.fromBlocks A 0 C D).det = A.det * D.det := by rw [← det_transpose, fromBlocks_transpose, transpose_zero, det_fromBlocks_zero₂₁, det_transpose, det_transpose] /-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column 0. -/ theorem det_succ_column_zero {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) R) : det A = ∑ i : Fin n.succ, (-1) ^ (i : ℕ) * A i 0 * det (A.submatrix i.succAbove Fin.succ) := by rw [Matrix.det_apply, Finset.univ_perm_fin_succ, ← Finset.univ_product_univ] simp only [Finset.sum_map, Equiv.toEmbedding_apply, Finset.sum_product, Matrix.submatrix] refine Finset.sum_congr rfl fun i _ => Fin.cases ?_ (fun i => ?_) i · simp only [Fin.prod_univ_succ, Matrix.det_apply, Finset.mul_sum, Equiv.Perm.decomposeFin_symm_apply_zero, Fin.val_zero, one_mul, Equiv.Perm.decomposeFin.symm_sign, Equiv.swap_self, if_true, id, Equiv.Perm.decomposeFin_symm_apply_succ, Fin.succAbove_zero, Equiv.coe_refl, pow_zero, mul_smul_comm, of_apply] -- `univ_perm_fin_succ` gives a different embedding of `Perm (Fin n)` into -- `Perm (Fin n.succ)` than the determinant of the submatrix we want, -- permute `A` so that we get the correct one. have : (-1 : R) ^ (i : ℕ) = (Perm.sign i.cycleRange) := by simp [Fin.sign_cycleRange] rw [Fin.val_succ, pow_succ', this, mul_assoc, mul_assoc, mul_left_comm (ε _), ← det_permute, Matrix.det_apply, Finset.mul_sum, Finset.mul_sum] -- now we just need to move the corresponding parts to the same place refine Finset.sum_congr rfl fun σ _ => ?_ rw [Equiv.Perm.decomposeFin.symm_sign, if_neg (Fin.succ_ne_zero i)] calc ((-1 * Perm.sign σ : ℤ) • ∏ i', A (Perm.decomposeFin.symm (Fin.succ i, σ) i') i') = (-1 * Perm.sign σ : ℤ) • (A (Fin.succ i) 0 * ∏ i', A ((Fin.succ i).succAbove (Fin.cycleRange i (σ i'))) i'.succ) := by simp only [Fin.prod_univ_succ, Fin.succAbove_cycleRange, Equiv.Perm.decomposeFin_symm_apply_zero, Equiv.Perm.decomposeFin_symm_apply_succ] _ = -1 * (A (Fin.succ i) 0 * (Perm.sign σ : ℤ) • ∏ i', A ((Fin.succ i).succAbove (Fin.cycleRange i (σ i'))) i'.succ) := by simp [_root_.neg_mul, one_mul, zsmul_eq_mul, neg_smul, Fin.succAbove_cycleRange, mul_left_comm] /-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row 0. -/ theorem det_succ_row_zero {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) R) : det A = ∑ j : Fin n.succ, (-1) ^ (j : ℕ) * A 0 j * det (A.submatrix Fin.succ j.succAbove) := by rw [← det_transpose A, det_succ_column_zero] refine Finset.sum_congr rfl fun i _ => ?_ rw [← det_transpose] simp only [transpose_apply, transpose_submatrix, transpose_transpose] /-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row `i`. -/ theorem det_succ_row {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) R) (i : Fin n.succ) : det A = ∑ j : Fin n.succ, (-1) ^ (i + j : ℕ) * A i j * det (A.submatrix i.succAbove j.succAbove) := by simp_rw [pow_add, mul_assoc, ← mul_sum] have : det A = (-1 : R) ^ (i : ℕ) * (Perm.sign i.cycleRange⁻¹) * det A := by calc det A = ↑((-1 : ℤˣ) ^ (i : ℕ) * (-1 : ℤˣ) ^ (i : ℕ) : ℤˣ) * det A := by simp _ = (-1 : R) ^ (i : ℕ) * (Perm.sign i.cycleRange⁻¹) * det A := by simp [-Int.units_mul_self] rw [this, mul_assoc] congr rw [← det_permute, det_succ_row_zero] refine Finset.sum_congr rfl fun j _ => ?_ rw [mul_assoc, Matrix.submatrix_apply, submatrix_submatrix, id_comp, Function.comp_def, id] congr 3 · rw [Equiv.Perm.inv_def, Fin.cycleRange_symm_zero] · ext i' j' rw [Equiv.Perm.inv_def, Matrix.submatrix_apply, Matrix.submatrix_apply, Fin.cycleRange_symm_succ] /-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column `j`. -/ theorem det_succ_column {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) R) (j : Fin n.succ) : det A = ∑ i : Fin n.succ, (-1) ^ (i + j : ℕ) * A i j * det (A.submatrix i.succAbove j.succAbove) := by rw [← det_transpose, det_succ_row _ j] refine Finset.sum_congr rfl fun i _ => ?_ rw [add_comm, ← det_transpose, transpose_apply, transpose_submatrix, transpose_transpose] /-- Determinant of 0x0 matrix -/ @[simp] theorem det_fin_zero {A : Matrix (Fin 0) (Fin 0) R} : det A = 1 := det_isEmpty /-- Determinant of 1x1 matrix -/ theorem det_fin_one (A : Matrix (Fin 1) (Fin 1) R) : det A = A 0 0 := det_unique A theorem det_fin_one_of (a : R) : det !![a] = a := det_fin_one _ /-- Determinant of 2x2 matrix -/ theorem det_fin_two (A : Matrix (Fin 2) (Fin 2) R) : det A = A 0 0 * A 1 1 - A 0 1 * A 1 0 := by simp only [det_succ_row_zero, det_unique, Fin.default_eq_zero, submatrix_apply, Fin.succ_zero_eq_one, Fin.sum_univ_succ, Fin.val_zero, Fin.zero_succAbove, univ_unique, Fin.val_succ, Fin.val_eq_zero, Fin.succ_succAbove_zero, sum_singleton] ring @[simp] theorem det_fin_two_of (a b c d : R) : Matrix.det !![a, b; c, d] = a * d - b * c := det_fin_two _ /-- Determinant of 3x3 matrix -/ theorem det_fin_three (A : Matrix (Fin 3) (Fin 3) R) : det A = A 0 0 * A 1 1 * A 2 2 - A 0 0 * A 1 2 * A 2 1 - A 0 1 * A 1 0 * A 2 2 + A 0 1 * A 1 2 * A 2 0 + A 0 2 * A 1 0 * A 2 1 - A 0 2 * A 1 1 * A 2 0 := by simp only [det_succ_row_zero, submatrix_apply, Fin.succ_zero_eq_one, submatrix_submatrix, det_unique, Fin.default_eq_zero, Function.comp_apply, Fin.succ_one_eq_two, Fin.sum_univ_succ, Fin.val_zero, Fin.zero_succAbove, univ_unique, Fin.val_succ, Fin.val_eq_zero, Fin.succ_succAbove_zero, sum_singleton, Fin.succ_succAbove_one] ring end Matrix
Rotate.lean
/- Copyright (c) 2025 Paul Lezeau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul Lezeau, Lawrence Wu -/ import Mathlib.Algebra.Group.Fin.Basic import Mathlib.Logic.Equiv.Fin.Basic /-! # Maximum order cyclic permutations on `Fin n` This file defines `finRotate`, which corresponds to the cycle `(1, ..., n)` on `Fin n`, and proves various lemmas about it. -/ open Nat variable {n : ℕ} /-- Rotate `Fin n` one step to the right. -/ def finRotate : ∀ n, Equiv.Perm (Fin n) | 0 => Equiv.refl _ | n + 1 => finAddFlip.trans (finCongr (Nat.add_comm 1 n)) @[simp] lemma finRotate_zero : finRotate 0 = Equiv.refl _ := rfl lemma finRotate_succ (n : ℕ) : finRotate (n + 1) = finAddFlip.trans (finCongr (Nat.add_comm 1 n)) := rfl theorem finRotate_of_lt {k : ℕ} (h : k < n) : finRotate (n + 1) ⟨k, h.trans_le n.le_succ⟩ = ⟨k + 1, Nat.succ_lt_succ h⟩ := by ext dsimp [finRotate_succ] simp [finAddFlip_apply_mk_left h, Nat.add_comm] theorem finRotate_last' : finRotate (n + 1) ⟨n, by omega⟩ = ⟨0, Nat.zero_lt_succ _⟩ := by dsimp [finRotate_succ] rw [finAddFlip_apply_mk_right le_rfl] simp theorem finRotate_last : finRotate (n + 1) (Fin.last _) = 0 := finRotate_last' theorem Fin.snoc_eq_cons_rotate {α : Type*} (v : Fin n → α) (a : α) : @Fin.snoc _ (fun _ => α) v a = fun i => @Fin.cons _ (fun _ => α) a v (finRotate _ i) := by ext ⟨i, h⟩ by_cases h' : i < n · rw [finRotate_of_lt h', Fin.snoc, Fin.cons, dif_pos h'] rfl · have h'' : n = i := by simp only [not_lt] at h' exact (Nat.eq_of_le_of_lt_succ h' h).symm subst h'' rw [finRotate_last', Fin.snoc, Fin.cons, dif_neg (lt_irrefl _)] rfl @[simp] theorem finRotate_one : finRotate 1 = Equiv.refl _ := Subsingleton.elim _ _ @[simp] theorem finRotate_succ_apply (i : Fin (n + 1)) : finRotate (n + 1) i = i + 1 := by cases n · exact @Subsingleton.elim (Fin 1) _ _ _ obtain rfl | h := Fin.eq_or_lt_of_le i.le_last · simp [finRotate_last] · cases i simp only [Fin.lt_iff_val_lt_val, Fin.val_last] at h simp [finRotate_of_lt h, Fin.add_def, Nat.mod_eq_of_lt (Nat.succ_lt_succ h)] theorem finRotate_apply_zero : finRotate n.succ 0 = 1 := by simp theorem coe_finRotate_of_ne_last {i : Fin n.succ} (h : i ≠ Fin.last n) : (finRotate (n + 1) i : ℕ) = i + 1 := by rw [finRotate_succ_apply] have : (i : ℕ) < n := Fin.val_lt_last h exact Fin.val_add_one_of_lt this theorem coe_finRotate (i : Fin n.succ) : (finRotate n.succ i : ℕ) = if i = Fin.last n then (0 : ℕ) else i + 1 := by rw [finRotate_succ_apply, Fin.val_add_one i] theorem lt_finRotate_iff_ne_last (i : Fin (n + 1)) : i < finRotate _ i ↔ i ≠ Fin.last n := by refine ⟨fun hi hc ↦ ?_, fun hi ↦ ?_⟩ · simp only [hc, finRotate_succ_apply, Fin.last_add_one, Fin.not_lt_zero] at hi · rw [Fin.lt_iff_val_lt_val, coe_finRotate_of_ne_last hi, Nat.lt_add_one_iff] theorem lt_finRotate_iff_ne_neg_one [NeZero n] (i : Fin n) : i < finRotate _ i ↔ i ≠ -1 := by obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero (NeZero.ne n) rw [lt_finRotate_iff_ne_last, ne_eq, not_iff_not, ←Fin.neg_last, neg_neg] @[simp] lemma finRotate_succ_symm_apply [NeZero n] (i : Fin n) : (finRotate _).symm i = i - 1 := by obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero (NeZero.ne n) apply (finRotate n.succ).symm_apply_eq.mpr rw [finRotate_succ_apply, sub_add_cancel] lemma coe_finRotate_symm_of_ne_zero [NeZero n] {i : Fin n} (hi : i ≠ 0) : ((finRotate _).symm i : ℕ) = i - 1 := by obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero (NeZero.ne n) rwa [finRotate_succ_symm_apply, Fin.val_sub_one_of_ne_zero] theorem finRotate_symm_lt_iff_ne_zero [NeZero n] (i : Fin n) : (finRotate _).symm i < i ↔ i ≠ 0 := by obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero (NeZero.ne n) refine ⟨fun hi hc ↦ ?_, fun hi ↦ ?_⟩ · simp only [hc, Fin.not_lt_zero] at hi · rw [Fin.lt_iff_val_lt_val, coe_finRotate_symm_of_ne_zero hi] apply sub_lt (zero_lt_of_ne_zero <| Fin.val_ne_zero_iff.mpr hi) Nat.zero_lt_one
AEDisjoint.lean
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.MeasureTheory.Measure.MeasureSpaceDef /-! # Almost everywhere disjoint sets We say that sets `s` and `t` are `μ`-a.e. disjoint (see `MeasureTheory.AEDisjoint`) if their intersection has measure zero. This assumption can be used instead of `Disjoint` in most theorems in measure theory. -/ open Set Function namespace MeasureTheory variable {ι α : Type*} {m : MeasurableSpace α} (μ : Measure α) /-- Two sets are said to be `μ`-a.e. disjoint if their intersection has measure zero. -/ def AEDisjoint (s t : Set α) := μ (s ∩ t) = 0 variable {μ} {s t u v : Set α} /-- If `s : ι → Set α` is a countable family of pairwise a.e. disjoint sets, then there exists a family of measurable null sets `t i` such that `s i \ t i` are pairwise disjoint. -/ theorem exists_null_pairwise_disjoint_diff [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s)) : ∃ t : ι → Set α, (∀ i, MeasurableSet (t i)) ∧ (∀ i, μ (t i) = 0) ∧ Pairwise (Disjoint on fun i => s i \ t i) := by refine ⟨fun i => toMeasurable μ (s i ∩ ⋃ j ∈ ({i}ᶜ : Set ι), s j), fun i => measurableSet_toMeasurable _ _, fun i => ?_, ?_⟩ · simp only [measure_toMeasurable, inter_iUnion] exact (measure_biUnion_null_iff <| to_countable _).2 fun j hj => hd (Ne.symm hj) · simp only [Pairwise, disjoint_left, onFun, mem_diff, not_and, and_imp, Classical.not_not] intro i j hne x hi hU hj replace hU : x ∉ s i ∩ iUnion fun j ↦ iUnion fun _ ↦ s j := fun h ↦ hU (subset_toMeasurable _ _ h) simp only [mem_inter_iff, mem_iUnion, not_and, not_exists] at hU exact (hU hi j hne.symm hj).elim namespace AEDisjoint protected theorem eq (h : AEDisjoint μ s t) : μ (s ∩ t) = 0 := h @[symm] protected theorem symm (h : AEDisjoint μ s t) : AEDisjoint μ t s := by rwa [AEDisjoint, inter_comm] protected theorem symmetric : Symmetric (AEDisjoint μ) := fun _ _ => AEDisjoint.symm protected theorem comm : AEDisjoint μ s t ↔ AEDisjoint μ t s := ⟨AEDisjoint.symm, AEDisjoint.symm⟩ protected theorem _root_.Disjoint.aedisjoint (h : Disjoint s t) : AEDisjoint μ s t := by rw [AEDisjoint, disjoint_iff_inter_eq_empty.1 h, measure_empty] protected theorem _root_.Pairwise.aedisjoint {f : ι → Set α} (hf : Pairwise (Disjoint on f)) : Pairwise (AEDisjoint μ on f) := hf.mono fun _i _j h => h.aedisjoint protected theorem _root_.Set.PairwiseDisjoint.aedisjoint {f : ι → Set α} {s : Set ι} (hf : s.PairwiseDisjoint f) : s.Pairwise (AEDisjoint μ on f) := hf.mono' fun _i _j h => h.aedisjoint theorem mono_ae (h : AEDisjoint μ s t) (hu : u ≤ᵐ[μ] s) (hv : v ≤ᵐ[μ] t) : AEDisjoint μ u v := measure_mono_null_ae (hu.inter hv) h protected theorem mono (h : AEDisjoint μ s t) (hu : u ⊆ s) (hv : v ⊆ t) : AEDisjoint μ u v := mono_ae h (HasSubset.Subset.eventuallyLE hu) (HasSubset.Subset.eventuallyLE hv) protected theorem congr (h : AEDisjoint μ s t) (hu : u =ᵐ[μ] s) (hv : v =ᵐ[μ] t) : AEDisjoint μ u v := mono_ae h (Filter.EventuallyEq.le hu) (Filter.EventuallyEq.le hv) @[simp] theorem iUnion_left_iff {ι : Sort*} [Countable ι] {s : ι → Set α} : AEDisjoint μ (⋃ i, s i) t ↔ ∀ i, AEDisjoint μ (s i) t := by simp only [AEDisjoint, iUnion_inter, measure_iUnion_null_iff] @[simp] theorem iUnion_right_iff {ι : Sort*} [Countable ι] {t : ι → Set α} : AEDisjoint μ s (⋃ i, t i) ↔ ∀ i, AEDisjoint μ s (t i) := by simp only [AEDisjoint, inter_iUnion, measure_iUnion_null_iff] @[simp] theorem union_left_iff : AEDisjoint μ (s ∪ t) u ↔ AEDisjoint μ s u ∧ AEDisjoint μ t u := by simp [union_eq_iUnion, and_comm] @[simp] theorem union_right_iff : AEDisjoint μ s (t ∪ u) ↔ AEDisjoint μ s t ∧ AEDisjoint μ s u := by simp [union_eq_iUnion, and_comm] theorem union_left (hs : AEDisjoint μ s u) (ht : AEDisjoint μ t u) : AEDisjoint μ (s ∪ t) u := union_left_iff.mpr ⟨hs, ht⟩ theorem union_right (ht : AEDisjoint μ s t) (hu : AEDisjoint μ s u) : AEDisjoint μ s (t ∪ u) := union_right_iff.2 ⟨ht, hu⟩ theorem diff_ae_eq_left (h : AEDisjoint μ s t) : (s \ t : Set α) =ᵐ[μ] s := @diff_self_inter _ s t ▸ diff_null_ae_eq_self h theorem diff_ae_eq_right (h : AEDisjoint μ s t) : (t \ s : Set α) =ᵐ[μ] t := diff_ae_eq_left <| AEDisjoint.symm h theorem measure_diff_left (h : AEDisjoint μ s t) : μ (s \ t) = μ s := measure_congr <| AEDisjoint.diff_ae_eq_left h theorem measure_diff_right (h : AEDisjoint μ s t) : μ (t \ s) = μ t := measure_congr <| AEDisjoint.diff_ae_eq_right h /-- If `s` and `t` are `μ`-a.e. disjoint, then `s \ u` and `t` are disjoint for some measurable null set `u`. -/ theorem exists_disjoint_diff (h : AEDisjoint μ s t) : ∃ u, MeasurableSet u ∧ μ u = 0 ∧ Disjoint (s \ u) t := ⟨toMeasurable μ (s ∩ t), measurableSet_toMeasurable _ _, (measure_toMeasurable _).trans h, disjoint_sdiff_self_left.mono_left (b := s \ t) fun x hx => by simpa using ⟨hx.1, fun hxt => hx.2 <| subset_toMeasurable _ _ ⟨hx.1, hxt⟩⟩⟩ theorem of_null_right (h : μ t = 0) : AEDisjoint μ s t := measure_mono_null inter_subset_right h theorem of_null_left (h : μ s = 0) : AEDisjoint μ s t := AEDisjoint.symm (of_null_right h) end AEDisjoint theorem aedisjoint_compl_left : AEDisjoint μ sᶜ s := (@disjoint_compl_left _ _ s).aedisjoint theorem aedisjoint_compl_right : AEDisjoint μ s sᶜ := (@disjoint_compl_right _ _ s).aedisjoint end MeasureTheory
Core.lean
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Lean.Expr.Rat import Mathlib.Tactic.NormNum.Result import Mathlib.Util.Qq import Lean.Elab.Tactic.Location /-! ## `norm_num` core functionality This file sets up the `norm_num` tactic and the `@[norm_num]` attribute, which allow for plugging in new normalization functionality around a simp-based driver. The actual behavior is in `@[norm_num]`-tagged definitions in `Tactic.NormNum.Basic` and elsewhere. -/ open Lean open Lean.Meta Qq Lean.Elab Term /-- Attribute for identifying `norm_num` extensions. -/ syntax (name := norm_num) "norm_num " term,+ : attr namespace Mathlib namespace Meta.NormNum initialize registerTraceClass `Tactic.norm_num /-- An extension for `norm_num`. -/ structure NormNumExt where /-- The extension should be run in the `pre` phase when used as simp plugin. -/ pre := true /-- The extension should be run in the `post` phase when used as simp plugin. -/ post := true /-- Attempts to prove an expression is equal to some explicit number of the relevant type. -/ eval {u : Level} {α : Q(Type u)} (e : Q($α)) : MetaM (Result e) /-- The name of the `norm_num` extension. -/ name : Name := by exact decl_name% variable {u : Level} /-- Read a `norm_num` extension from a declaration of the right type. -/ def mkNormNumExt (n : Name) : ImportM NormNumExt := do let { env, opts, .. } ← read IO.ofExcept <| unsafe env.evalConstCheck NormNumExt opts ``NormNumExt n /-- Each `norm_num` extension is labelled with a collection of patterns which determine the expressions to which it should be applied. -/ abbrev Entry := Array (Array DiscrTree.Key) × Name /-- The state of the `norm_num` extension environment -/ structure NormNums where /-- The tree of `norm_num` extensions. -/ tree : DiscrTree NormNumExt := {} /-- Erased `norm_num`s. -/ erased : PHashSet Name := {} deriving Inhabited /-- Environment extensions for `norm_num` declarations -/ initialize normNumExt : ScopedEnvExtension Entry (Entry × NormNumExt) NormNums ← -- we only need this to deduplicate entries in the DiscrTree have : BEq NormNumExt := ⟨fun _ _ ↦ false⟩ /- Insert `v : NormNumExt` into the tree `dt` on all key sequences given in `kss`. -/ let insert kss v dt := kss.foldl (fun dt ks ↦ dt.insertCore ks v) dt registerScopedEnvExtension { mkInitial := pure {} ofOLeanEntry := fun _ e@(_, n) ↦ return (e, ← mkNormNumExt n) toOLeanEntry := (·.1) addEntry := fun { tree, erased } ((kss, n), ext) ↦ { tree := insert kss ext tree, erased := erased.erase n } } /-- Run each registered `norm_num` extension on an expression, returning a `NormNum.Result`. -/ def derive {α : Q(Type u)} (e : Q($α)) (post := false) : MetaM (Result e) := do if e.isRawNatLit then let lit : Q(ℕ) := e return .isNat (q(instAddMonoidWithOneNat) : Q(AddMonoidWithOne ℕ)) lit (q(IsNat.raw_refl $lit) : Expr) profileitM Exception "norm_num" (← getOptions) do let s ← saveState let normNums := normNumExt.getState (← getEnv) let arr ← normNums.tree.getMatch e for ext in arr do if (bif post then ext.post else ext.pre) && ! normNums.erased.contains ext.name then try let new ← withReducibleAndInstances <| ext.eval e trace[Tactic.norm_num] "{ext.name}:\n{e} ==> {new}" return new catch err => trace[Tactic.norm_num] "{ext.name} failed {e}: {err.toMessageData}" s.restore throwError "{e}: no norm_nums apply" /-- Run each registered `norm_num` extension on a typed expression `e : α`, returning a typed expression `lit : ℕ`, and a proof of `isNat e lit`. -/ def deriveNat {α : Q(Type u)} (e : Q($α)) (_inst : Q(AddMonoidWithOne $α) := by with_reducible assumption) : MetaM ((lit : Q(ℕ)) × Q(IsNat $e $lit)) := do let .isNat _ lit proof ← derive e | failure pure ⟨lit, proof⟩ /-- Run each registered `norm_num` extension on a typed expression `e : α`, returning a typed expression `lit : ℤ`, and a proof of `IsInt e lit` in expression form. -/ def deriveInt {α : Q(Type u)} (e : Q($α)) (_inst : Q(Ring $α) := by with_reducible assumption) : MetaM ((lit : Q(ℤ)) × Q(IsInt $e $lit)) := do let some ⟨_, lit, proof⟩ := (← derive e).toInt | failure pure ⟨lit, proof⟩ /-- Run each registered `norm_num` extension on a typed expression `e : α`, returning a rational number, typed expressions `n : ℤ` and `d : ℕ` for the numerator and denominator, and a proof of `IsRat e n d` in expression form. -/ def deriveRat {α : Q(Type u)} (e : Q($α)) (_inst : Q(DivisionRing $α) := by with_reducible assumption) : MetaM (ℚ × (n : Q(ℤ)) × (d : Q(ℕ)) × Q(IsRat $e $n $d)) := do let some res := (← derive e).toRat' | failure pure res /-- Run each registered `norm_num` extension on a typed expression `p : Prop`, and returning the truth or falsity of `p' : Prop` from an equivalence `p ↔ p'`. -/ def deriveBool (p : Q(Prop)) : MetaM ((b : Bool) × BoolResult p b) := do let .isBool b prf ← derive q($p) | failure pure ⟨b, prf⟩ /-- Run each registered `norm_num` extension on a typed expression `p : Prop`, and returning the truth or falsity of `p' : Prop` from an equivalence `p ↔ p'`. -/ def deriveBoolOfIff (p p' : Q(Prop)) (hp : Q($p ↔ $p')) : MetaM ((b : Bool) × BoolResult p' b) := do let ⟨b, pb⟩ ← deriveBool p match b with | true => return ⟨true, q(Iff.mp $hp $pb)⟩ | false => return ⟨false, q((Iff.not $hp).mp $pb)⟩ /-- Run each registered `norm_num` extension on an expression, returning a `Simp.Result`. -/ def eval (e : Expr) (post := false) : MetaM Simp.Result := do if e.isExplicitNumber then return { expr := e } let ⟨_, _, e⟩ ← inferTypeQ' e (← derive e post).toSimpResult /-- Erases a name marked `norm_num` by adding it to the state's `erased` field and removing it from the state's list of `Entry`s. -/ def NormNums.eraseCore (d : NormNums) (declName : Name) : NormNums := { d with erased := d.erased.insert declName } /-- Erase a name marked as a `norm_num` attribute. Check that it does in fact have the `norm_num` attribute by making sure it names a `NormNumExt` found somewhere in the state's tree, and is not erased. -/ def NormNums.erase {m : Type → Type} [Monad m] [MonadError m] (d : NormNums) (declName : Name) : m NormNums := do unless d.tree.values.any (·.name == declName) && ! d.erased.contains declName do throwError "'{declName}' does not have [norm_num] attribute" return d.eraseCore declName initialize registerBuiltinAttribute { name := `norm_num descr := "adds a norm_num extension" applicationTime := .afterCompilation add := fun declName stx kind ↦ match stx with | `(attr| norm_num $es,*) => do let env ← getEnv unless (env.getModuleIdxFor? declName).isNone do throwError "invalid attribute 'norm_num', declaration is in an imported module" if (IR.getSorryDep env declName).isSome then return -- ignore in progress definitions let ext ← mkNormNumExt declName let keys ← MetaM.run' <| es.getElems.mapM fun stx ↦ do let e ← TermElabM.run' <| withSaveInfoContext <| withAutoBoundImplicit <| withReader ({ · with ignoreTCFailures := true }) do let e ← elabTerm stx none let (_, _, e) ← lambdaMetaTelescope (← mkLambdaFVars (← getLCtx).getFVars e) return e DiscrTree.mkPath e normNumExt.add ((keys, declName), ext) kind | _ => throwUnsupportedSyntax erase := fun declName => do let s := normNumExt.getState (← getEnv) let s ← s.erase declName modifyEnv fun env => normNumExt.modifyState env fun _ => s } /-- A simp plugin which calls `NormNum.eval`. -/ def tryNormNum (post := false) (e : Expr) : SimpM Simp.Step := do try return .done (← eval e post) catch _ => return .continue variable (ctx : Simp.Context) (useSimp := true) in mutual /-- A discharger which calls `norm_num`. -/ partial def discharge (e : Expr) : SimpM (Option Expr) := do (← deriveSimp e).ofTrue /-- A `Methods` implementation which calls `norm_num`. -/ partial def methods : Simp.Methods := if useSimp then { pre := Simp.preDefault #[] >> tryNormNum post := Simp.postDefault #[] >> tryNormNum (post := true) discharge? := discharge } else { pre := tryNormNum post := tryNormNum (post := true) discharge? := discharge } /-- Traverses the given expression using simp and normalises any numbers it finds. -/ partial def deriveSimp (e : Expr) : MetaM Simp.Result := (·.1) <$> Simp.main e ctx (methods := methods) end -- FIXME: had to inline a bunch of stuff from `simpGoal` here /-- The core of `norm_num` as a tactic in `MetaM`. * `g`: The goal to simplify * `ctx`: The simp context, constructed by `mkSimpContext` and containing any additional simp rules we want to use * `fvarIdsToSimp`: The selected set of hypotheses used in the location argument * `simplifyTarget`: true if the target is selected in the location argument * `useSimp`: true if we used `norm_num` instead of `norm_num1` -/ def normNumAt (g : MVarId) (ctx : Simp.Context) (fvarIdsToSimp : Array FVarId) (simplifyTarget := true) (useSimp := true) : MetaM (Option (Array FVarId × MVarId)) := g.withContext do g.checkNotAssigned `norm_num let mut g := g let mut toAssert := #[] let mut replaced := #[] for fvarId in fvarIdsToSimp do let localDecl ← fvarId.getDecl let type ← instantiateMVars localDecl.type let ctx := ctx.setSimpTheorems (ctx.simpTheorems.eraseTheorem (.fvar localDecl.fvarId)) let r ← deriveSimp ctx useSimp type match r.proof? with | some _ => let some (value, type) ← applySimpResult g (mkFVar fvarId) type r | return none toAssert := toAssert.push { userName := localDecl.userName, type, value } | none => if r.expr.isConstOf ``False then g.assign (← mkFalseElim (← g.getType) (mkFVar fvarId)) return none g ← g.replaceLocalDeclDefEq fvarId r.expr replaced := replaced.push fvarId if simplifyTarget then let res ← g.withContext do let target ← instantiateMVars (← g.getType) let r ← deriveSimp ctx useSimp target let some proof ← r.ofTrue | some <$> applySimpResultToTarget g target r g.assign proof pure none let some gNew := res | return none g := gNew let (fvarIdsNew, gNew) ← g.assertHypotheses toAssert let toClear := fvarIdsToSimp.filter fun fvarId ↦ !replaced.contains fvarId let gNew ← gNew.tryClearMany toClear return some (fvarIdsNew, gNew) open Tactic in /-- Constructs a simp context from the simp argument syntax. -/ def getSimpContext (cfg args : Syntax) (simpOnly := false) : TacticM Simp.Context := do let config ← elabSimpConfigCore cfg let simpTheorems ← if simpOnly then simpOnlyBuiltins.foldlM (·.addConst ·) {} else getSimpTheorems let { ctx, .. } ← elabSimpArgs args[0] (eraseLocal := false) (kind := .simp) (simprocs := {}) (← Simp.mkContext config (simpTheorems := #[simpTheorems]) (congrTheorems := ← getSimpCongrTheorems)) return ctx open Elab.Tactic in /-- Elaborates a call to `norm_num only? [args]` or `norm_num1`. * `args`: the `(simpArgs)?` syntax for simp arguments * `loc`: the `(location)?` syntax for the optional location argument * `simpOnly`: true if `only` was used in `norm_num` * `useSimp`: false if `norm_num1` was used, in which case only the structural parts of `simp` will be used, not any of the post-processing that `simp only` does without lemmas -/ -- FIXME: had to inline a bunch of stuff from `mkSimpContext` and `simpLocation` here def elabNormNum (cfg args loc : Syntax) (simpOnly := false) (useSimp := true) : TacticM Unit := do let g ← getMainGoal g.withContext do let ctx ← getSimpContext cfg args (!useSimp || simpOnly) let res ← match expandOptLocation loc with | .targets hyps simplifyTarget => normNumAt g ctx (← getFVarIds hyps) simplifyTarget useSimp | .wildcard => normNumAt g ctx (← g.getNondepPropHyps) (simplifyTarget := true) useSimp match res with | none => replaceMainGoal [] | some (_, g) => replaceMainGoal [g] end Meta.NormNum namespace Tactic open Lean.Parser.Tactic Meta.NormNum /-- Normalize numerical expressions. Supports the operations `+` `-` `*` `/` `⁻¹` `^` and `%` over numerical types such as `ℕ`, `ℤ`, `ℚ`, `ℝ`, `ℂ` and some general algebraic types, and can prove goals of the form `A = B`, `A ≠ B`, `A < B` and `A ≤ B`, where `A` and `B` are numerical expressions. It also has a relatively simple primality prover. -/ elab (name := normNum) "norm_num" cfg:optConfig only:&" only"? args:(simpArgs ?) loc:(location ?) : tactic => elabNormNum cfg args loc (simpOnly := only.isSome) (useSimp := true) /-- Basic version of `norm_num` that does not call `simp`. -/ elab (name := normNum1) "norm_num1" loc:(location ?) : tactic => elabNormNum mkNullNode mkNullNode loc (simpOnly := true) (useSimp := false) open Lean Elab Tactic @[inherit_doc normNum1] syntax (name := normNum1Conv) "norm_num1" : conv /-- Elaborator for `norm_num1` conv tactic. -/ @[tactic normNum1Conv] def elabNormNum1Conv : Tactic := fun _ ↦ withMainContext do let ctx ← getSimpContext mkNullNode mkNullNode true Conv.applySimpResult (← deriveSimp ctx (← instantiateMVars (← Conv.getLhs)) (useSimp := false)) @[inherit_doc normNum] syntax (name := normNumConv) "norm_num" optConfig &" only"? (simpArgs)? : conv /-- Elaborator for `norm_num` conv tactic. -/ @[tactic normNumConv] def elabNormNumConv : Tactic := fun stx ↦ withMainContext do let ctx ← getSimpContext stx[1] stx[3] !stx[2].isNone Conv.applySimpResult (← deriveSimp ctx (← instantiateMVars (← Conv.getLhs)) (useSimp := true)) /-- The basic usage is `#norm_num e`, where `e` is an expression, which will print the `norm_num` form of `e`. Syntax: `#norm_num` (`only`)? (`[` simp lemma list `]`)? `:`? expression This accepts the same options as the `#simp` command. You can specify additional simp lemmas as usual, for example using `#norm_num [f, g] : e`. (The colon is optional but helpful for the parser.) The `only` restricts `norm_num` to using only the provided lemmas, and so `#norm_num only : e` behaves similarly to `norm_num1`. Unlike `norm_num`, this command does not fail when no simplifications are made. `#norm_num` understands local variables, so you can use them to introduce parameters. -/ macro (name := normNumCmd) "#norm_num" cfg:optConfig o:(&" only")? args:(Parser.Tactic.simpArgs)? " :"? ppSpace e:term : command => `(command| #conv norm_num $cfg:optConfig $[only%$o]? $(args)? => $e) end Mathlib.Tactic
Adhesive.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.CategoryTheory.Extensive import Mathlib.CategoryTheory.Limits.Shapes.KernelPair import Mathlib.CategoryTheory.Limits.Constructions.EpiMono /-! # Adhesive categories ## Main definitions - `CategoryTheory.IsPushout.IsVanKampen`: A convenience formulation for a pushout being a van Kampen colimit. - `CategoryTheory.Adhesive`: A category is adhesive if it has pushouts and pullbacks along monomorphisms, and such pushouts are van Kampen. ## Main Results - `CategoryTheory.Type.adhesive`: The category of `Type` is adhesive. - `CategoryTheory.Adhesive.isPullback_of_isPushout_of_mono_left`: In adhesive categories, pushouts along monomorphisms are pullbacks. - `CategoryTheory.Adhesive.mono_of_isPushout_of_mono_left`: In adhesive categories, monomorphisms are stable under pushouts. - `CategoryTheory.Adhesive.toRegularMonoCategory`: Monomorphisms in adhesive categories are regular (this implies that adhesive categories are balanced). - `CategoryTheory.adhesive_functor`: The category `C ⥤ D` is adhesive if `D` has all pullbacks and all pushouts and is adhesive ## References - https://ncatlab.org/nlab/show/adhesive+category - [Stephen Lack and Paweł Sobociński, Adhesive Categories][adhesive2004] -/ namespace CategoryTheory open Limits universe v' u' v u variable {J : Type v'} [Category.{u'} J] {C : Type u} [Category.{v} C] variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} -- This only makes sense when the original diagram is a pushout. /-- A convenience formulation for a pushout being a van Kampen colimit. See `IsPushout.isVanKampen_iff` below. -/ @[nolint unusedArguments] def IsPushout.IsVanKampen (_ : IsPushout f g h i) : Prop := ∀ ⦃W' X' Y' Z' : C⦄ (f' : W' ⟶ X') (g' : W' ⟶ Y') (h' : X' ⟶ Z') (i' : Y' ⟶ Z') (αW : W' ⟶ W) (αX : X' ⟶ X) (αY : Y' ⟶ Y) (αZ : Z' ⟶ Z) (_ : IsPullback f' αW αX f) (_ : IsPullback g' αW αY g) (_ : CommSq h' αX αZ h) (_ : CommSq i' αY αZ i) (_ : CommSq f' g' h' i'), IsPushout f' g' h' i' ↔ IsPullback h' αX αZ h ∧ IsPullback i' αY αZ i theorem IsPushout.IsVanKampen.flip {H : IsPushout f g h i} (H' : H.IsVanKampen) : H.flip.IsVanKampen := by introv W' hf hg hh hi w simpa only [IsPushout.flip_iff, IsPullback.flip_iff, and_comm] using H' g' f' i' h' αW αY αX αZ hg hf hi hh w.flip theorem IsPushout.isVanKampen_iff (H : IsPushout f g h i) : H.IsVanKampen ↔ IsVanKampenColimit (PushoutCocone.mk h i H.w) := by constructor · intro H F' c' α fα eα hα refine Iff.trans ?_ ((H (F'.map WalkingSpan.Hom.fst) (F'.map WalkingSpan.Hom.snd) (c'.ι.app _) (c'.ι.app _) (α.app _) (α.app _) (α.app _) fα (by convert hα WalkingSpan.Hom.fst) (by convert hα WalkingSpan.Hom.snd) ?_ ?_ ?_).trans ?_) · have : F'.map WalkingSpan.Hom.fst ≫ c'.ι.app WalkingSpan.left = F'.map WalkingSpan.Hom.snd ≫ c'.ι.app WalkingSpan.right := by simp only [Cocone.w] rw [(IsColimit.equivOfNatIsoOfIso (diagramIsoSpan F') c' (PushoutCocone.mk _ _ this) _).nonempty_congr] · exact ⟨fun h => ⟨⟨this⟩, h⟩, fun h => h.2⟩ · refine Cocones.ext (Iso.refl c'.pt) ?_ rintro (_ | _ | _) <;> dsimp <;> simp only [c'.w, Category.id_comp, Category.comp_id] · exact ⟨NatTrans.congr_app eα.symm _⟩ · exact ⟨NatTrans.congr_app eα.symm _⟩ · exact ⟨by simp⟩ constructor · rintro ⟨h₁, h₂⟩ (_ | _ | _) · rw [← c'.w WalkingSpan.Hom.fst]; exact (hα WalkingSpan.Hom.fst).paste_horiz h₁ exacts [h₁, h₂] · intro h; exact ⟨h _, h _⟩ · introv H W' hf hg hh hi w refine Iff.trans ?_ ((H w.cocone ⟨by rintro (_ | _ | _); exacts [αW, αX, αY], ?_⟩ αZ ?_ ?_).trans ?_) rotate_left · rintro i _ (_ | _ | _) · dsimp; simp only [Functor.map_id, Category.comp_id, Category.id_comp] exacts [hf.w, hg.w] · ext (_ | _ | _) · dsimp rw [PushoutCocone.condition_zero, Category.assoc] erw [hh.w] rw [hf.w_assoc] exacts [hh.w.symm, hi.w.symm] · rintro i _ (_ | _ | _) · dsimp; simp_rw [Functor.map_id] exact IsPullback.of_horiz_isIso ⟨by rw [Category.comp_id, Category.id_comp]⟩ exacts [hf, hg] · constructor · intro h; exact ⟨h WalkingCospan.left, h WalkingCospan.right⟩ · rintro ⟨h₁, h₂⟩ (_ | _ | _) · dsimp; rw [PushoutCocone.condition_zero]; exact hf.paste_horiz h₁ exacts [h₁, h₂] · exact ⟨fun h => h.2, fun h => ⟨w, h⟩⟩ theorem is_coprod_iff_isPushout {X E Y YE : C} (c : BinaryCofan X E) (hc : IsColimit c) {f : X ⟶ Y} {iY : Y ⟶ YE} {fE : c.pt ⟶ YE} (H : CommSq f c.inl iY fE) : Nonempty (IsColimit (BinaryCofan.mk (c.inr ≫ fE) iY)) ↔ IsPushout f c.inl iY fE := by constructor · rintro ⟨h⟩ refine ⟨H, ⟨Limits.PushoutCocone.isColimitAux' _ ?_⟩⟩ intro s dsimp only [PushoutCocone.inr, PushoutCocone.mk] -- Porting note: Originally `dsimp` refine ⟨h.desc (BinaryCofan.mk (c.inr ≫ s.inr) s.inl), h.fac _ ⟨WalkingPair.right⟩, ?_, ?_⟩ · apply BinaryCofan.IsColimit.hom_ext hc · rw [← H.w_assoc]; erw [h.fac _ ⟨WalkingPair.right⟩]; exact s.condition · rw [← Category.assoc]; exact h.fac _ ⟨WalkingPair.left⟩ · intro m e₁ e₂ apply BinaryCofan.IsColimit.hom_ext h · dsimp only [BinaryCofan.mk, id] -- Porting note: Originally `dsimp` rw [Category.assoc, e₂, eq_comm]; exact h.fac _ ⟨WalkingPair.left⟩ · refine e₁.trans (Eq.symm ?_); exact h.fac _ _ · refine fun H => ⟨?_⟩ fapply Limits.BinaryCofan.isColimitMk · exact fun s => H.isColimit.desc (PushoutCocone.mk s.inr _ <| (hc.fac (BinaryCofan.mk (f ≫ s.inr) s.inl) ⟨WalkingPair.left⟩).symm) · intro s rw [Category.assoc] erw [H.isColimit.fac _ WalkingSpan.right] erw [hc.fac] rfl · intro s; exact H.isColimit.fac _ WalkingSpan.left · intro s m e₁ e₂ apply PushoutCocone.IsColimit.hom_ext H.isColimit · symm; exact (H.isColimit.fac _ WalkingSpan.left).trans e₂.symm · rw [H.isColimit.fac _ WalkingSpan.right] apply BinaryCofan.IsColimit.hom_ext hc · erw [hc.fac] erw [← H.w_assoc] rw [e₂] rfl · refine ((Category.assoc _ _ _).symm.trans e₁).trans ?_; symm; exact hc.fac _ _ theorem IsPushout.isVanKampen_inl {W E X Z : C} (c : BinaryCofan W E) [FinitaryExtensive C] [HasPullbacks C] (hc : IsColimit c) (f : W ⟶ X) (h : X ⟶ Z) (i : c.pt ⟶ Z) (H : IsPushout f c.inl h i) : H.IsVanKampen := by obtain ⟨hc₁⟩ := (is_coprod_iff_isPushout c hc H.1).mpr H introv W' hf hg hh hi w obtain ⟨hc₂⟩ := ((BinaryCofan.isVanKampen_iff _).mp (FinitaryExtensive.vanKampen c hc) (BinaryCofan.mk _ (pullback.fst _ _)) _ _ _ hg.w.symm pullback.condition.symm).mpr ⟨hg, IsPullback.of_hasPullback αY c.inr⟩ refine (is_coprod_iff_isPushout _ hc₂ w).symm.trans ?_ refine ((BinaryCofan.isVanKampen_iff _).mp (FinitaryExtensive.vanKampen _ hc₁) (BinaryCofan.mk _ _) (pullback.snd _ _) _ _ ?_ hh.w.symm).trans ?_ · dsimp; rw [← pullback.condition_assoc, Category.assoc, hi.w] constructor · rintro ⟨hc₃, hc₄⟩ refine ⟨hc₄, ?_⟩ let Y'' := pullback αZ i let cmp : Y' ⟶ Y'' := pullback.lift i' αY hi.w have e₁ : (g' ≫ cmp) ≫ pullback.snd _ _ = αW ≫ c.inl := by rw [Category.assoc, pullback.lift_snd, hg.w] have e₂ : (pullback.fst _ _ ≫ cmp : pullback αY c.inr ⟶ _) ≫ pullback.snd _ _ = pullback.snd _ _ ≫ c.inr := by rw [Category.assoc, pullback.lift_snd, pullback.condition] obtain ⟨hc₄⟩ := ((BinaryCofan.isVanKampen_iff _).mp (FinitaryExtensive.vanKampen c hc) (BinaryCofan.mk _ _) αW _ _ e₁.symm e₂.symm).mpr <| by constructor · apply IsPullback.of_right _ e₁ (IsPullback.of_hasPullback _ _) rw [Category.assoc, pullback.lift_fst, ← H.w, ← w.w]; exact hf.paste_horiz hc₄ · apply IsPullback.of_right _ e₂ (IsPullback.of_hasPullback _ _) rw [Category.assoc, pullback.lift_fst]; exact hc₃ rw [← Category.id_comp αZ, ← show cmp ≫ pullback.snd _ _ = αY from pullback.lift_snd _ _ _] apply IsPullback.paste_vert _ (IsPullback.of_hasPullback αZ i) have : cmp = (hc₂.coconePointUniqueUpToIso hc₄).hom := by apply BinaryCofan.IsColimit.hom_ext hc₂ exacts [(hc₂.comp_coconePointUniqueUpToIso_hom hc₄ ⟨WalkingPair.left⟩).symm, (hc₂.comp_coconePointUniqueUpToIso_hom hc₄ ⟨WalkingPair.right⟩).symm] rw [this] exact IsPullback.of_vert_isIso ⟨by rw [← this, Category.comp_id, pullback.lift_fst]⟩ · rintro ⟨hc₃, hc₄⟩ exact ⟨(IsPullback.of_hasPullback αY c.inr).paste_horiz hc₄, hc₃⟩ theorem IsPushout.IsVanKampen.isPullback_of_mono_left [Mono f] {H : IsPushout f g h i} (H' : H.IsVanKampen) : IsPullback f g h i := ((H' (𝟙 _) g g (𝟙 Y) (𝟙 _) f (𝟙 _) i (IsKernelPair.id_of_mono f) (IsPullback.of_vert_isIso ⟨by simp⟩) H.1.flip ⟨rfl⟩ ⟨by simp⟩).mp (IsPushout.of_horiz_isIso ⟨by simp⟩)).1.flip theorem IsPushout.IsVanKampen.isPullback_of_mono_right [Mono g] {H : IsPushout f g h i} (H' : H.IsVanKampen) : IsPullback f g h i := ((H' f (𝟙 _) (𝟙 _) f (𝟙 _) (𝟙 _) g h (IsPullback.of_vert_isIso ⟨by simp⟩) (IsKernelPair.id_of_mono g) ⟨rfl⟩ H.1 ⟨by simp⟩).mp (IsPushout.of_vert_isIso ⟨by simp⟩)).2 theorem IsPushout.IsVanKampen.mono_of_mono_left [Mono f] {H : IsPushout f g h i} (H' : H.IsVanKampen) : Mono i := IsKernelPair.mono_of_isIso_fst ((H' (𝟙 _) g g (𝟙 Y) (𝟙 _) f (𝟙 _) i (IsKernelPair.id_of_mono f) (IsPullback.of_vert_isIso ⟨by simp⟩) H.1.flip ⟨rfl⟩ ⟨by simp⟩).mp (IsPushout.of_horiz_isIso ⟨by simp⟩)).2 theorem IsPushout.IsVanKampen.mono_of_mono_right [Mono g] {H : IsPushout f g h i} (H' : H.IsVanKampen) : Mono h := IsKernelPair.mono_of_isIso_fst ((H' f (𝟙 _) (𝟙 _) f (𝟙 _) (𝟙 _) g h (IsPullback.of_vert_isIso ⟨by simp⟩) (IsKernelPair.id_of_mono g) ⟨rfl⟩ H.1 ⟨by simp⟩).mp (IsPushout.of_vert_isIso ⟨by simp⟩)).1 /-- A category is adhesive if it has pushouts and pullbacks along monomorphisms, and such pushouts are van Kampen. -/ class Adhesive (C : Type u) [Category.{v} C] : Prop where [hasPullback_of_mono_left : ∀ {X Y S : C} (f : X ⟶ S) (g : Y ⟶ S) [Mono f], HasPullback f g] [hasPushout_of_mono_left : ∀ {X Y S : C} (f : S ⟶ X) (g : S ⟶ Y) [Mono f], HasPushout f g] van_kampen : ∀ {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} [Mono f] (H : IsPushout f g h i), H.IsVanKampen attribute [instance] Adhesive.hasPullback_of_mono_left Adhesive.hasPushout_of_mono_left theorem Adhesive.van_kampen' [Adhesive C] [Mono g] (H : IsPushout f g h i) : H.IsVanKampen := (Adhesive.van_kampen H.flip).flip theorem Adhesive.isPullback_of_isPushout_of_mono_left [Adhesive C] (H : IsPushout f g h i) [Mono f] : IsPullback f g h i := (Adhesive.van_kampen H).isPullback_of_mono_left theorem Adhesive.isPullback_of_isPushout_of_mono_right [Adhesive C] (H : IsPushout f g h i) [Mono g] : IsPullback f g h i := (Adhesive.van_kampen' H).isPullback_of_mono_right theorem Adhesive.mono_of_isPushout_of_mono_left [Adhesive C] (H : IsPushout f g h i) [Mono f] : Mono i := (Adhesive.van_kampen H).mono_of_mono_left theorem Adhesive.mono_of_isPushout_of_mono_right [Adhesive C] (H : IsPushout f g h i) [Mono g] : Mono h := (Adhesive.van_kampen' H).mono_of_mono_right instance Type.adhesive : Adhesive (Type u) := ⟨fun {_ _ _ _ f _ _ _ _} H => (IsPushout.isVanKampen_inl _ (Types.isCoprodOfMono f) _ _ _ H.flip).flip⟩ noncomputable instance (priority := 100) Adhesive.toRegularMonoCategory [Adhesive C] : IsRegularMonoCategory C := ⟨fun f _ => ⟨{ Z := pushout f f left := pushout.inl _ _ right := pushout.inr _ _ w := pushout.condition isLimit := (Adhesive.isPullback_of_isPushout_of_mono_left (IsPushout.of_hasPushout f f)).isLimitFork }⟩⟩ -- This then implies that adhesive categories are balanced example [Adhesive C] : Balanced C := inferInstance section functor universe v'' u'' variable {D : Type u''} [Category.{v''} D] instance adhesive_functor [Adhesive C] [HasPullbacks C] [HasPushouts C] : Adhesive (D ⥤ C) := by constructor intros W X Y Z f g h i hf H rw [IsPushout.isVanKampen_iff] apply isVanKampenColimit_of_evaluation intro x refine (IsVanKampenColimit.precompose_isIso_iff (diagramIsoSpan _).inv).mp ?_ refine IsVanKampenColimit.of_iso ?_ (PushoutCocone.isoMk _).symm refine (IsPushout.isVanKampen_iff (H.map ((evaluation _ _).obj x))).mp ?_ apply Adhesive.van_kampen theorem adhesive_of_preserves_and_reflects (F : C ⥤ D) [Adhesive D] [H₁ : ∀ {X Y S : C} (f : X ⟶ S) (g : Y ⟶ S) [Mono f], HasPullback f g] [H₂ : ∀ {X Y S : C} (f : S ⟶ X) (g : S ⟶ Y) [Mono f], HasPushout f g] [PreservesLimitsOfShape WalkingCospan F] [ReflectsLimitsOfShape WalkingCospan F] [PreservesColimitsOfShape WalkingSpan F] [ReflectsColimitsOfShape WalkingSpan F] : Adhesive C := by apply Adhesive.mk (hasPullback_of_mono_left := H₁) (hasPushout_of_mono_left := H₂) intros W X Y Z f g h i hf H rw [IsPushout.isVanKampen_iff] refine IsVanKampenColimit.of_mapCocone F ?_ refine (IsVanKampenColimit.precompose_isIso_iff (diagramIsoSpan _).inv).mp ?_ refine IsVanKampenColimit.of_iso ?_ (PushoutCocone.isoMk _).symm refine (IsPushout.isVanKampen_iff (H.map F)).mp ?_ apply Adhesive.van_kampen theorem adhesive_of_preserves_and_reflects_isomorphism (F : C ⥤ D) [Adhesive D] [HasPullbacks C] [HasPushouts C] [PreservesLimitsOfShape WalkingCospan F] [PreservesColimitsOfShape WalkingSpan F] [F.ReflectsIsomorphisms] : Adhesive C := by haveI : ReflectsLimitsOfShape WalkingCospan F := reflectsLimitsOfShape_of_reflectsIsomorphisms haveI : ReflectsColimitsOfShape WalkingSpan F := reflectsColimitsOfShape_of_reflectsIsomorphisms exact adhesive_of_preserves_and_reflects F theorem adhesive_of_reflective [HasPullbacks D] [Adhesive C] [HasPullbacks C] [HasPushouts C] [H₂ : ∀ {X Y S : D} (f : S ⟶ X) (g : S ⟶ Y) [Mono f], HasPushout f g] {Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful] [PreservesLimitsOfShape WalkingCospan Gl] : Adhesive D := by have := adj.leftAdjoint_preservesColimits have := adj.rightAdjoint_preservesLimits apply Adhesive.mk (hasPushout_of_mono_left := H₂) intro W X Y Z f g h i _ H have := Adhesive.van_kampen (IsPushout.of_hasPushout (Gr.map f) (Gr.map g)) rw [IsPushout.isVanKampen_iff] at this ⊢ refine (IsVanKampenColimit.precompose_isIso_iff (Functor.isoWhiskerLeft _ (asIso adj.counit) ≪≫ Functor.rightUnitor _).hom).mp ?_ refine ((this.precompose_isIso (spanCompIso _ _ _).hom).map_reflective adj).of_iso (IsColimit.uniqueUpToIso ?_ ?_) · exact isColimitOfPreserves Gl ((IsColimit.precomposeHomEquiv _ _).symm <| pushoutIsPushout _ _) · exact (IsColimit.precomposeHomEquiv _ _).symm H.isColimit end functor end CategoryTheory
PicardLindelof.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Winston Yin -/ import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.Topology.Algebra.Order.Floor import Mathlib.Topology.MetricSpace.Contracting /-! # Picard-Lindelöf (Cauchy-Lipschitz) Theorem We prove the (local) existence of integral curves and flows to time-dependent vector fields. Let `f : ℝ → E → E` be a time-dependent (local) vector field on a Banach space, and let `t₀ : ℝ` and `x₀ : E`. If `f` is Lipschitz continuous in `x` within a closed ball around `x₀` of radius `a ≥ 0` at every `t` and continuous in `t` at every `x`, then there exists a (local) solution `α : ℝ → E` to the initial value problem `α t₀ = x₀` and `deriv α t = f t (α t)` for all `t ∈ Icc tmin tmax`, where `L * max (tmax - t₀) (t₀ - tmin) ≤ a`. We actually prove a more general version of this theorem for the existence of local flows. If there is some `r ≥ 0` such that `L * max (tmax - t₀) (t₀ - tmin) ≤ a - r`, then for every `x ∈ closedBall x₀ r`, there exists a (local) solution `α x` with the initial condition `α t₀ = x`. In other words, there exists a local flow `α : E → ℝ → E` defined on `closedBall x₀ r` and `Icc tmin tmax`. The proof relies on demonstrating the existence of a solution `α` to the following integral equation: $$\alpha(t) = x_0 + \int_{t_0}^t f(\tau, \alpha(\tau))\,\mathrm{d}\tau.$$ This is done via the contraction mapping theorem, applied to the space of Lipschitz continuous functions from a closed interval to a Banach space. The needed contraction map is constructed by repeated applications of the right hand side of this equation. ## Main definitions and results * `picard f t₀ x₀ α t`: the Picard iteration, applied to the curve `α` * `IsPicardLindelof`: the structure holding the assumptions of the Picard-Lindelöf theorem * `IsPicardLindelof.exists_eq_forall_mem_Icc_hasDerivWithinAt`: the existence theorem for local solutions to time-dependent ODEs * `IsPicardLindelof.exists_forall_mem_closedBall_eq_forall_mem_Icc_hasDerivWithinAt`: the existence theorem for local flows to time-dependent vector fields * `IsPicardLindelof.exists_forall_mem_closedBall_eq_hasDerivWithinAt_lipschitzOnWith`: there exists a local flow to time-dependent vector fields, and it is Lipschitz-continuous with respect to the starting point. ## Implementation notes * The structure `FunSpace` and theorems within this namespace are implementation details of the proof of the Picard-Lindelöf theorem and are not intended to be used outside of this file. * Some sources, such as Lang, define `FunSpace` as the space of continuous functions from a closed interval to a closed ball. We instead define `FunSpace` here as the space of Lipschitz continuous functions from a closed interval. This slightly stronger condition allows us to postpone the usage of the completeness condition on the space `E` until the application of the contraction mapping theorem. * We have chosen to formalise many of the real constants as `ℝ≥0`, so that the non-negativity of certain quantities constructed from them can be shown more easily. When subtraction is involved, especially note whether it is the usual subtraction between two reals or the truncated subtraction between two non-negative reals. * In this file, We only prove the existence of a solution. For uniqueness, see `ODE_solution_unique` and related theorems in `Mathlib/Analysis/ODE/Gronwall.lean`. ## Tags differential equation, dynamical system, initial value problem, Picard-Lindelöf theorem, Cauchy-Lipschitz theorem -/ open Function intervalIntegral MeasureTheory Metric Set open scoped Nat NNReal Topology /-! ## Assumptions of the Picard-Lindelöf theorem-/ /-- Prop structure holding the assumptions of the Picard-Lindelöf theorem. `IsPicardLindelof f t₀ x₀ a r L K`, where `t₀ ∈ Icc tmin tmax`, means that the time-dependent vector field `f` satisfies the conditions to admit an integral curve `α : ℝ → E` to `f` defined on `Icc tmin tmax` with the initial condition `α t₀ = x`, where `‖x - x₀‖ ≤ r`. Note that the initial point `x` is allowed to differ from the point `x₀` about which the conditions on `f` are stated. -/ structure IsPicardLindelof {E : Type*} [NormedAddCommGroup E] (f : ℝ → E → E) {tmin tmax : ℝ} (t₀ : Icc tmin tmax) (x₀ : E) (a r L K : ℝ≥0) : Prop where /-- The vector field at any time is Lipschitz with constant `K` within a closed ball. -/ lipschitzOnWith : ∀ t ∈ Icc tmin tmax, LipschitzOnWith K (f t) (closedBall x₀ a) /-- The vector field is continuous in time within a closed ball. -/ continuousOn : ∀ x ∈ closedBall x₀ a, ContinuousOn (f · x) (Icc tmin tmax) /-- `L` is an upper bound of the norm of the vector field. -/ norm_le : ∀ t ∈ Icc tmin tmax, ∀ x ∈ closedBall x₀ a, ‖f t x‖ ≤ L /-- The time interval of validity -/ mul_max_le : L * max (tmax - t₀) (t₀ - tmin) ≤ a - r namespace ODE /-! ## Integral equation For any time-dependent vector field `f : ℝ → E → E`, we define an integral equation that is equivalent to the initial value problem defined by `f`. -/ section variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : ℝ → E → E} {α : ℝ → E} {s : Set ℝ} {u : Set E} {t₀ tmin tmax : ℝ} /-- The Picard iteration. It will be shown that if `α : ℝ → E` and `picard f t₀ x₀ α` agree on an interval containing `t₀`, then `α` is a solution to `f` with `α t₀ = x₀` on this interval. -/ noncomputable def picard (f : ℝ → E → E) (t₀ : ℝ) (x₀ : E) (α : ℝ → E) : ℝ → E := fun t ↦ x₀ + ∫ τ in t₀..t, f τ (α τ) @[simp] lemma picard_apply {x₀ : E} {t : ℝ} : picard f t₀ x₀ α t = x₀ + ∫ τ in t₀..t, f τ (α τ) := rfl lemma picard_apply₀ {x₀ : E} : picard f t₀ x₀ α t₀ = x₀ := by simp /-- Given a $C^n$ time-dependent vector field `f` and a $C^n$ curve `α`, the composition `f t (α t)` is $C^n$ in `t`. -/ lemma contDiffOn_comp {n : WithTop ℕ∞} (hf : ContDiffOn ℝ n (uncurry f) (s ×ˢ u)) (hα : ContDiffOn ℝ n α s) (hmem : ∀ t ∈ s, α t ∈ u) : ContDiffOn ℝ n (fun t ↦ f t (α t)) s := by have : (fun t ↦ f t (α t)) = (uncurry f) ∘ fun t ↦ (t, α t) := rfl rw [this] apply hf.comp (by fun_prop) intro _ ht rw [mem_prod] exact ⟨ht, hmem _ ht⟩ /-- Given a continuous time-dependent vector field `f` and a continuous curve `α`, the composition `f t (α t)` is continuous in `t`. -/ lemma continuousOn_comp (hf : ContinuousOn (uncurry f) (s ×ˢ u)) (hα : ContinuousOn α s) (hmem : MapsTo α s u) : ContinuousOn (fun t ↦ f t (α t)) s := contDiffOn_zero.mp <| (contDiffOn_comp (contDiffOn_zero.mpr hf) (contDiffOn_zero.mpr hα) hmem) end /-! ## Space of Lipschitz functions on a closed interval We define the space of Lipschitz continuous functions from a closed interval. This will be shown to be a complete metric space on which `picard` is a contracting map, leading to a fixed point that will serve as the solution to the ODE. The domain is a closed interval in order to easily inherit the sup metric from continuous maps on compact spaces. We cannot use functions `ℝ → E` with junk values outside the domain, as the supremum within a closed interval will only be a pseudo-metric, and the contracting map will fail to have a fixed point. In order to accommodate flows, we do not require a specific initial condition. Rather, `FunSpace` contains curves whose initial condition is within a closed ball. -/ /-- The space of `L`-Lipschitz functions `α : Icc tmin tmax → E` -/ structure FunSpace {E : Type*} [NormedAddCommGroup E] {tmin tmax : ℝ} (t₀ : Icc tmin tmax) (x₀ : E) (r L : ℝ≥0) where /-- The domain is `Icc tmin tmax`. -/ toFun : Icc tmin tmax → E lipschitzWith : LipschitzWith L toFun mem_closedBall₀ : toFun t₀ ∈ closedBall x₀ r namespace FunSpace variable {E : Type*} [NormedAddCommGroup E] section variable {tmin tmax : ℝ} {t₀ : Icc tmin tmax} {x₀ : E} {a r L : ℝ≥0} instance : CoeFun (FunSpace t₀ x₀ r L) fun _ ↦ Icc tmin tmax → E := ⟨fun α ↦ α.toFun⟩ /-- `FunSpace t₀ x₀ r L` contains the constant map at `x₀`. -/ instance : Inhabited (FunSpace t₀ x₀ r L) := ⟨fun _ ↦ x₀, (LipschitzWith.const _).weaken (zero_le _), mem_closedBall_self r.2⟩ protected lemma continuous (α : FunSpace t₀ x₀ L r) : Continuous α := α.lipschitzWith.continuous /-- The embedding of `FunSpace` into the space of continuous maps -/ def toContinuousMap : FunSpace t₀ x₀ r L ↪ C(Icc tmin tmax, E) := ⟨fun α ↦ ⟨α, α.continuous⟩, fun α β h ↦ by cases α; cases β; simpa using h⟩ @[simp] lemma toContinuousMap_apply_eq_apply (α : FunSpace t₀ x₀ r L) (t : Icc tmin tmax) : α.toContinuousMap t = α t := rfl /-- The metric between two curves `α` and `β` is the supremum of the metric between `α t` and `β t` over all `t` in the domain. This is finite when the domain is compact, such as a closed interval in our case. -/ noncomputable instance : MetricSpace (FunSpace t₀ x₀ r L) := MetricSpace.induced toContinuousMap toContinuousMap.injective inferInstance lemma isUniformInducing_toContinuousMap : IsUniformInducing fun α : FunSpace t₀ x₀ r L ↦ α.toContinuousMap := ⟨rfl⟩ lemma range_toContinuousMap : range (fun α : FunSpace t₀ x₀ r L ↦ α.toContinuousMap) = { α : C(Icc tmin tmax, E) | LipschitzWith L α ∧ α t₀ ∈ closedBall x₀ r } := by ext α constructor · rintro ⟨⟨α, hα1, hα2⟩, rfl⟩ exact ⟨hα1, hα2⟩ · rintro ⟨hα1, hα2⟩ exact ⟨⟨α, hα1, hα2⟩, rfl⟩ /-- We show that `FunSpace` is complete in order to apply the contraction mapping theorem. -/ instance [CompleteSpace E] : CompleteSpace (FunSpace t₀ x₀ r L) := by rw [completeSpace_iff_isComplete_range isUniformInducing_toContinuousMap] apply IsClosed.isComplete rw [range_toContinuousMap, setOf_and] apply isClosed_setOf_lipschitzWith L |>.preimage continuous_coeFun |>.inter simp_rw [mem_closedBall_iff_norm] exact isClosed_le (by fun_prop) continuous_const /-- Extend the domain of `α` from `Icc tmin tmax` to `ℝ` such that `α t = α tmin` for all `t ≤ tmin` and `α t = α tmax` for all `t ≥ tmax`. -/ noncomputable def compProj (α : FunSpace t₀ x₀ r L) (t : ℝ) : E := α <| projIcc tmin tmax (le_trans t₀.2.1 t₀.2.2) t @[simp] lemma compProj_apply {α : FunSpace t₀ x₀ r L} {t : ℝ} : α.compProj t = α (projIcc tmin tmax (le_trans t₀.2.1 t₀.2.2) t) := rfl lemma compProj_val {α : FunSpace t₀ x₀ r L} {t : Icc tmin tmax} : α.compProj t = α t := by simp only [compProj_apply, projIcc_val] lemma compProj_of_mem {α : FunSpace t₀ x₀ r L} {t : ℝ} (ht : t ∈ Icc tmin tmax) : α.compProj t = α ⟨t, ht⟩ := by rw [compProj_apply, projIcc_of_mem] @[continuity, fun_prop] lemma continuous_compProj (α : FunSpace t₀ x₀ r L) : Continuous α.compProj := α.continuous.comp continuous_projIcc /-- The image of a function in `FunSpace` is contained within a closed ball. -/ protected lemma mem_closedBall {α : FunSpace t₀ x₀ r L} (h : L * max (tmax - t₀) (t₀ - tmin) ≤ a - r) {t : Icc tmin tmax} : α t ∈ closedBall x₀ a := by rw [mem_closedBall, dist_eq_norm] calc ‖α t - x₀‖ ≤ ‖α t - α t₀‖ + ‖α t₀ - x₀‖ := norm_sub_le_norm_sub_add_norm_sub .. _ ≤ L * |t.1 - t₀.1| + r := by apply add_le_add _ <| mem_closedBall_iff_norm.mp α.mem_closedBall₀ rw [← dist_eq_norm] exact α.lipschitzWith.dist_le_mul t t₀ _ ≤ L * max (tmax - t₀) (t₀ - tmin) + r := by gcongr exact abs_sub_le_max_sub t.2.1 t.2.2 _ _ ≤ a - r + r := add_le_add_right h _ _ = a := sub_add_cancel _ _ lemma compProj_mem_closedBall (α : FunSpace t₀ x₀ r L) (h : L * max (tmax - t₀) (t₀ - tmin) ≤ a - r) {t : ℝ} : α.compProj t ∈ closedBall x₀ a := by rw [compProj_apply] exact α.mem_closedBall h end /-! ## Contracting map on the space of Lipschitz functions -/ section variable [NormedSpace ℝ E] {f : ℝ → E → E} {tmin tmax : ℝ} {t₀ : Icc tmin tmax} {x₀ x y : E} {a r L K : ℝ≥0} /-- The integrand in `next` is continuous. -/ lemma continuousOn_comp_compProj (hf : IsPicardLindelof f t₀ x₀ a r L K) (α : FunSpace t₀ x₀ r L) : ContinuousOn (fun t' ↦ f t' (α.compProj t')) (Icc tmin tmax) := continuousOn_comp (continuousOn_prod_of_continuousOn_lipschitzOnWith' (uncurry f) K hf.lipschitzOnWith hf.continuousOn) α.continuous_compProj.continuousOn fun _ _ ↦ α.mem_closedBall hf.mul_max_le /-- The integrand in `next` is integrable. -/ lemma intervalIntegrable_comp_compProj (hf : IsPicardLindelof f t₀ x₀ a r L K) (α : FunSpace t₀ x₀ r L) (t : Icc tmin tmax) : IntervalIntegrable (fun t' ↦ f t' (α.compProj t')) volume t₀ t := by apply ContinuousOn.intervalIntegrable apply α.continuousOn_comp_compProj hf |>.mono exact uIcc_subset_Icc t₀.2 t.2 /-- The map on `FunSpace` defined by `picard`, some `n`-th iterate of which will be a contracting map -/ noncomputable def next (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (α : FunSpace t₀ x₀ r L) : FunSpace t₀ x₀ r L where toFun t := picard f t₀ x α.compProj t lipschitzWith := LipschitzWith.of_dist_le_mul fun t₁ t₂ ↦ by rw [dist_eq_norm, picard_apply, picard_apply, add_sub_add_left_eq_sub, integral_interval_sub_left (intervalIntegrable_comp_compProj hf _ t₁) (intervalIntegrable_comp_compProj hf _ t₂), Subtype.dist_eq, Real.dist_eq] apply intervalIntegral.norm_integral_le_of_norm_le_const intro t ht -- Can `grind` do this in the future? have ht : t ∈ Icc tmin tmax := subset_trans uIoc_subset_uIcc (uIcc_subset_Icc t₂.2 t₁.2) ht exact hf.norm_le _ ht _ <| α.mem_closedBall hf.mul_max_le mem_closedBall₀ := by simp [hx] @[simp] lemma next_apply (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (α : FunSpace t₀ x₀ r L) {t : Icc tmin tmax} : next hf hx α t = picard f t₀ x α.compProj t := rfl lemma next_apply₀ (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (α : FunSpace t₀ x₀ r L) : next hf hx α t₀ = x := by simp /-- A key step in the inductive case of `dist_iterate_next_apply_le` -/ lemma dist_comp_iterate_next_le (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (n : ℕ) (t : Icc tmin tmax) {α β : FunSpace t₀ x₀ r L} (h : dist ((next hf hx)^[n] α t) ((next hf hx)^[n] β t) ≤ (K * |t - t₀.1|) ^ n / n ! * dist α β) : dist (f t ((next hf hx)^[n] α t)) (f t ((next hf hx)^[n] β t)) ≤ K ^ (n + 1) * |t - t₀.1| ^ n / n ! * dist α β := calc _ ≤ K * dist ((next hf hx)^[n] α t) ((next hf hx)^[n] β t) := hf.lipschitzOnWith t.1 t.2 |>.dist_le_mul _ (FunSpace.mem_closedBall hf.mul_max_le) _ (FunSpace.mem_closedBall hf.mul_max_le) _ ≤ K ^ (n + 1) * |t - t₀.1| ^ n / n ! * dist α β := by rw [pow_succ', mul_assoc, mul_div_assoc, mul_assoc] gcongr rwa [← mul_pow] /-- A time-dependent bound on the distance between the `n`-th iterates of `next` on two curves -/ lemma dist_iterate_next_apply_le (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (α β : FunSpace t₀ x₀ r L) (n : ℕ) (t : Icc tmin tmax) : dist ((next hf hx)^[n] α t) ((next hf hx)^[n] β t) ≤ (K * |t.1 - t₀.1|) ^ n / n ! * dist α β := by induction n generalizing t with | zero => simpa using ContinuousMap.dist_apply_le_dist (f := toContinuousMap α) (g := toContinuousMap β) _ | succ n hn => rw [iterate_succ_apply', iterate_succ_apply', dist_eq_norm, next_apply, next_apply, picard_apply, picard_apply, add_sub_add_left_eq_sub, ← intervalIntegral.integral_sub (intervalIntegrable_comp_compProj hf _ t) (intervalIntegrable_comp_compProj hf _ t)] calc _ ≤ ∫ τ in uIoc t₀.1 t.1, K ^ (n + 1) * |τ - t₀| ^ n / n ! * dist α β := by rw [intervalIntegral.norm_intervalIntegral_eq] apply MeasureTheory.norm_integral_le_of_norm_le (Continuous.integrableOn_uIoc (by fun_prop)) apply ae_restrict_mem measurableSet_Ioc |>.mono intro t' ht' -- Can `grind` do this in the future? have ht' : t' ∈ Icc tmin tmax := subset_trans uIoc_subset_uIcc (uIcc_subset_Icc t₀.2 t.2) ht' rw [← dist_eq_norm, compProj_of_mem, compProj_of_mem] exact dist_comp_iterate_next_le hf hx _ ⟨t', ht'⟩ (hn _) _ ≤ (K * |t.1 - t₀.1|) ^ (n + 1) / (n + 1) ! * dist α β := by apply le_of_abs_le -- critical: `integral_pow_abs_sub_uIoc` rw [← intervalIntegral.abs_intervalIntegral_eq, intervalIntegral.integral_mul_const, intervalIntegral.integral_div, intervalIntegral.integral_const_mul, abs_mul, abs_div, abs_mul, intervalIntegral.abs_intervalIntegral_eq, integral_pow_abs_sub_uIoc, abs_div, abs_pow, abs_pow, abs_dist, NNReal.abs_eq, abs_abs, mul_div, div_div, ← abs_mul, ← Nat.cast_succ, ← Nat.cast_mul, ← Nat.factorial_succ, Nat.abs_cast, ← mul_pow] /-- The `n`-th iterate of `next` is Lipschitz continuous with respect to `FunSpace`, with constant $(K \max(t_{\mathrm{max}}, t_{\mathrm{min}})^n / n!$. -/ lemma dist_iterate_next_iterate_next_le (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (α β : FunSpace t₀ x₀ r L) (n : ℕ) : dist ((next hf hx)^[n] α) ((next hf hx)^[n] β) ≤ (K * max (tmax - t₀) (t₀ - tmin)) ^ n / n ! * dist α β := by rw [← MetricSpace.isometry_induced FunSpace.toContinuousMap FunSpace.toContinuousMap.injective |>.dist_eq, ContinuousMap.dist_le] · intro t apply le_trans <| dist_iterate_next_apply_le hf hx α β n t gcongr exact abs_sub_le_max_sub t.2.1 t.2.2 _ · have : 0 ≤ max (tmax - t₀) (t₀ - tmin) := le_max_of_le_left <| sub_nonneg_of_le t₀.2.2 positivity /-- Some `n`-th iterate of `next` is a contracting map, and its associated Lipschitz constant is independent of the initial point. -/ lemma exists_contractingWith_iterate_next (hf : IsPicardLindelof f t₀ x₀ a r L K) : ∃ (n : ℕ) (C : ℝ≥0), ∀ (x : E) (hx : x ∈ closedBall x₀ r), ContractingWith C (next hf hx)^[n] := by obtain ⟨n, hn⟩ := FloorSemiring.tendsto_pow_div_factorial_atTop (K * max (tmax - t₀) (t₀ - tmin)) |>.eventually (gt_mem_nhds zero_lt_one) |>.exists have : (0 : ℝ) ≤ (K * max (tmax - t₀) (t₀ - tmin)) ^ n / n ! := by have : 0 ≤ max (tmax - t₀) (t₀ - tmin) := le_max_of_le_left <| sub_nonneg_of_le t₀.2.2 positivity refine ⟨n, ⟨_, this⟩, fun x hx ↦ ?_⟩ exact ⟨hn, LipschitzWith.of_dist_le_mul fun α β ↦ dist_iterate_next_iterate_next_le hf hx α β n⟩ /-- The map `next` has a fixed point in the space of curves. This will be used to construct a solution `α : ℝ → E` to the ODE. -/ lemma exists_isFixedPt_next [CompleteSpace E] (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) : ∃ α : FunSpace t₀ x₀ r L, IsFixedPt (next hf hx) α := let ⟨_, _, h⟩ := exists_contractingWith_iterate_next hf ⟨_, h x hx |>.isFixedPt_fixedPoint_iterate⟩ /-! ## Lipschitz continuity of the solution with respect to the initial condition The proof relies on the fact that the repeated application of `next` to any curve `α` converges to the fixed point of `next`, so it suffices to bound the distance between `α` and `next^[n] α`. Since there is some `m : ℕ` such that `next^[m]` is a contracting map, it further suffices to bound the distance between `α` and `next^[m]^[n] α`. -/ /-- A key step in the base case of `exists_forall_closedBall_funSpace_dist_le_mul` -/ lemma dist_next_next (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (hy : y ∈ closedBall x₀ r) (α : FunSpace t₀ x₀ r L) : dist (next hf hx α) (next hf hy α) = dist x y := by have : Nonempty (Icc tmin tmax) := ⟨t₀⟩ -- needed for `ciSup_const` rw [← MetricSpace.isometry_induced FunSpace.toContinuousMap FunSpace.toContinuousMap.injective |>.dist_eq, dist_eq_norm, ContinuousMap.norm_eq_iSup_norm] simp [add_sub_add_right_eq_sub, dist_eq_norm] lemma dist_iterate_next_le (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (α : FunSpace t₀ x₀ r L) (n : ℕ) : dist α ((next hf hx)^[n] α) ≤ (∑ i ∈ Finset.range n, (K * max (tmax - t₀) (t₀ - tmin)) ^ i / i !) * dist α (next hf hx α) := by nth_rw 1 [← iterate_zero_apply (next hf hx) α] rw [Finset.sum_mul] apply dist_le_range_sum_of_dist_le (f := fun i ↦ (next hf hx)^[i] α) intro i hi rw [iterate_succ_apply] exact dist_iterate_next_iterate_next_le hf hx _ _ i lemma dist_iterate_iterate_next_le_of_lipschitzWith (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) (α : FunSpace t₀ x₀ r L) {m : ℕ} {C : ℝ≥0} (hm : LipschitzWith C (next hf hx)^[m]) (n : ℕ) : dist α ((next hf hx)^[m]^[n] α) ≤ (∑ i ∈ Finset.range m, (K * max (tmax - t₀) (t₀ - tmin)) ^ i / i !) * (∑ i ∈ Finset.range n, (C : ℝ) ^ i) * dist α (next hf hx α) := by nth_rw 1 [← iterate_zero_apply (next hf hx) α] rw [Finset.mul_sum, Finset.sum_mul] apply dist_le_range_sum_of_dist_le (f := fun i ↦ (next hf hx)^[m]^[i] α) intro i hi rw [iterate_succ_apply] apply le_trans <| hm.dist_iterate_succ_le_geometric α i rw [mul_assoc, mul_comm ((C : ℝ) ^ i), ← mul_assoc] gcongr exact dist_iterate_next_le hf hx α m /-- The pointwise distance between any two integral curves `α` and `β` over their domains is bounded by a constant `L'` times the distance between their respective initial points. This is the result of taking the limit of `dist_iterate_iterate_next_le_of_lipschitzWith` as `n → ∞`. This implies that the local solution of a vector field is Lipschitz continuous in the initial condition. -/ lemma exists_forall_closedBall_funSpace_dist_le_mul [CompleteSpace E] (hf : IsPicardLindelof f t₀ x₀ a r L K) : ∃ L' : ℝ≥0, ∀ (x y : E) (hx : x ∈ closedBall x₀ r) (hy : y ∈ closedBall x₀ r) (α β : FunSpace t₀ x₀ r L) (_ : IsFixedPt (next hf hx) α) (_ : IsFixedPt (next hf hy) β), dist α β ≤ L' * dist x y := by obtain ⟨m, C, h⟩ := exists_contractingWith_iterate_next hf let L' := (∑ i ∈ Finset.range m, (K * max (tmax - t₀) (t₀ - tmin)) ^ i / i !) * (1 - C)⁻¹ have hL' : 0 ≤ L' := by have : 0 ≤ max (tmax - t₀) (t₀ - tmin) := le_max_of_le_left <| sub_nonneg_of_le t₀.2.2 positivity refine ⟨⟨L', hL'⟩, fun x y hx hy α β hα hβ ↦ ?_⟩ rw [NNReal.coe_mk] apply le_of_tendsto_of_tendsto' (b := Filter.atTop) _ _ <| dist_iterate_iterate_next_le_of_lipschitzWith hf hy α (h y hy).2 · apply Filter.Tendsto.comp (y := 𝓝 β) (tendsto_const_nhds.dist Filter.tendsto_id) rw [h y hy |>.fixedPoint_unique (hβ.iterate m)] exact h y hy |>.tendsto_iterate_fixedPoint α · nth_rw 1 [← hα, dist_next_next] apply Filter.Tendsto.mul_const apply Filter.Tendsto.const_mul convert hasSum_geometric_of_lt_one C.2 (h y hy).1 |>.tendsto_sum_nat simp [NNReal.coe_sub <| le_of_lt (h y hy).1, NNReal.coe_one] end end FunSpace /-! ## Properties of the integral equation -/ section variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : ℝ → E → E} {α : ℝ → E} {s : Set ℝ} {u : Set E} {t₀ tmin tmax : ℝ} -- TODO: generalise to open sets and `Ici` and `Iic` /-- If the time-dependent vector field `f` and the curve `α` are continuous, then `f t (α t)` is the derivative of `picard f t₀ x₀ α`. -/ lemma hasDerivWithinAt_picard_Icc (ht₀ : t₀ ∈ Icc tmin tmax) (hf : ContinuousOn (uncurry f) ((Icc tmin tmax) ×ˢ u)) (hα : ContinuousOn α (Icc tmin tmax)) (hmem : ∀ t ∈ Icc tmin tmax, α t ∈ u) (x₀ : E) {t : ℝ} (ht : t ∈ Icc tmin tmax) : HasDerivWithinAt (picard f t₀ x₀ α) (f t (α t)) (Icc tmin tmax) t := by apply HasDerivWithinAt.const_add have : Fact (t ∈ Icc tmin tmax) := ⟨ht⟩ -- needed to synthesise `FTCFilter` for `Icc` apply intervalIntegral.integral_hasDerivWithinAt_right _ -- need `CompleteSpace E` and `Icc` (continuousOn_comp hf hα hmem |>.stronglyMeasurableAtFilter_nhdsWithin measurableSet_Icc t) (continuousOn_comp hf hα hmem _ ht) apply ContinuousOn.intervalIntegrable apply continuousOn_comp hf hα hmem |>.mono by_cases h : t < t₀ · rw [uIcc_of_gt h] exact Icc_subset_Icc ht.1 ht₀.2 · rw [uIcc_of_le (not_lt.mp h)] exact Icc_subset_Icc ht₀.1 ht.2 end end ODE namespace IsPicardLindelof /-! ## Properties of `IsPicardLindelof` -/ section variable {E : Type*} [NormedAddCommGroup E] {f : ℝ → E → E} {tmin tmax : ℝ} {t₀ : Icc tmin tmax} {x₀ x : E} {a r L K : ℝ≥0} lemma continuousOn_uncurry (hf : IsPicardLindelof f t₀ x₀ a r L K) : ContinuousOn (uncurry f) ((Icc tmin tmax) ×ˢ (closedBall x₀ a)) := continuousOn_prod_of_continuousOn_lipschitzOnWith' _ K hf.lipschitzOnWith hf.continuousOn /-- The special case where the vector field is independent of time -/ lemma of_time_independent {f : E → E} {tmin tmax : ℝ} {t₀ : Icc tmin tmax} {x₀ : E} {a r L K : ℝ≥0} (hb : ∀ x ∈ closedBall x₀ a, ‖f x‖ ≤ L) (hl : LipschitzOnWith K f (closedBall x₀ a)) (hm : L * max (tmax - t₀) (t₀ - tmin) ≤ a - r) : (IsPicardLindelof (fun _ ↦ f) t₀ x₀ a r L K) where lipschitzOnWith := fun _ _ ↦ hl continuousOn := fun _ _ ↦ continuousOn_const norm_le := fun _ _ ↦ hb mul_max_le := hm /-- A time-independent, continuously differentiable ODE satisfies the hypotheses of the Picard-Lindelöf theorem. -/ lemma of_contDiffAt_one [NormedSpace ℝ E] {f : E → E} {x₀ : E} (hf : ContDiffAt ℝ 1 f x₀) (t₀ : ℝ) : ∃ (ε : ℝ) (hε : 0 < ε) (a r L K : ℝ≥0) (_ : 0 < r), IsPicardLindelof (fun _ ↦ f) (tmin := t₀ - ε) (tmax := t₀ + ε) ⟨t₀, (by simp [le_of_lt hε])⟩ x₀ a r L K := by -- Obtain ball of radius `a` within the domain in which f is `K`-lipschitz obtain ⟨K, s, hs, hl⟩ := hf.exists_lipschitzOnWith obtain ⟨a, ha : 0 < a, has⟩ := Metric.mem_nhds_iff.mp hs set L := K * a + ‖f x₀‖ + 1 with hL have hL0 : 0 < L := by positivity have hb (x : E) (hx : x ∈ closedBall x₀ (a / 2)) : ‖f x‖ ≤ L := by rw [hL] calc ‖f x‖ ≤ ‖f x - f x₀‖ + ‖f x₀‖ := norm_le_norm_sub_add _ _ _ ≤ K * ‖x - x₀‖ + ‖f x₀‖ := by gcongr rw [← dist_eq_norm, ← dist_eq_norm] apply hl.dist_le_mul x _ x₀ (mem_of_mem_nhds hs) apply subset_trans _ has hx exact closedBall_subset_ball <| half_lt_self ha -- this is where we need `a / 2` _ ≤ K * a + ‖f x₀‖ := by gcongr rw [← mem_closedBall_iff_norm] exact closedBall_subset_closedBall (half_le_self (le_of_lt ha)) hx _ ≤ L := le_add_of_nonneg_right zero_le_one let ε := a / L / 2 / 2 have hε0 : 0 < ε := by positivity refine ⟨ε, hε0, ⟨a / 2, le_of_lt <| half_pos ha⟩, ⟨a / 2, le_of_lt <| half_pos ha⟩ / 2, ⟨L, le_of_lt hL0⟩, K, half_pos <| half_pos ha, ?_⟩ apply of_time_independent hb <| hl.mono <| subset_trans (closedBall_subset_ball (half_lt_self ha)) has rw [NNReal.coe_mk, add_sub_cancel_left, sub_sub_cancel, max_self, NNReal.coe_div, NNReal.coe_two, NNReal.coe_mk, mul_comm, ← le_div_iff₀ hL0, sub_half, div_right_comm (a / 2), div_right_comm a] end /-! ## Existence of solutions to ODEs -/ open ODE variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : ℝ → E → E} {tmin tmax : ℝ} {t₀ : Icc tmin tmax} {x₀ x : E} {a r L K : ℝ≥0} /-- **Picard-Lindelöf (Cauchy-Lipschitz) theorem**, integral form. This version shows the existence of a local solution whose initial point `x` may be be different from the centre `x₀` of the closed ball within which the properties of the vector field hold. -/ theorem exists_eq_forall_mem_Icc_eq_picard (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) : ∃ α : ℝ → E, α t₀ = x ∧ ∀ t ∈ Icc tmin tmax, α t = ODE.picard f t₀ x α t := by obtain ⟨α, hα⟩ := FunSpace.exists_isFixedPt_next hf hx refine ⟨(FunSpace.next hf hx α).compProj, by simp, fun t ht ↦ ?_⟩ rw [FunSpace.compProj_apply, FunSpace.next_apply, hα, projIcc_of_mem _ ht] /-- **Picard-Lindelöf (Cauchy-Lipschitz) theorem**, differential form. This version shows the existence of a local solution whose initial point `x` may be be different from the centre `x₀` of the closed ball within which the properties of the vector field hold. -/ theorem exists_eq_forall_mem_Icc_hasDerivWithinAt (hf : IsPicardLindelof f t₀ x₀ a r L K) (hx : x ∈ closedBall x₀ r) : ∃ α : ℝ → E, α t₀ = x ∧ ∀ t ∈ Icc tmin tmax, HasDerivWithinAt α (f t (α t)) (Icc tmin tmax) t := by obtain ⟨α, hα⟩ := FunSpace.exists_isFixedPt_next hf hx refine ⟨α.compProj, by rw [FunSpace.compProj_val, ← hα, FunSpace.next_apply₀], fun t ht ↦ ?_⟩ apply hasDerivWithinAt_picard_Icc t₀.2 hf.continuousOn_uncurry α.continuous_compProj.continuousOn (fun _ ht' ↦ α.compProj_mem_closedBall hf.mul_max_le) x ht |>.congr_of_mem _ ht intro t' ht' nth_rw 1 [← hα] rw [FunSpace.compProj_of_mem ht', FunSpace.next_apply] /-- **Picard-Lindelöf (Cauchy-Lipschitz) theorem**, differential form. -/ theorem exists_eq_forall_mem_Icc_hasDerivWithinAt₀ (hf : IsPicardLindelof f t₀ x₀ a 0 L K) : ∃ α : ℝ → E, α t₀ = x₀ ∧ ∀ t ∈ Icc tmin tmax, HasDerivWithinAt α (f t (α t)) (Icc tmin tmax) t := exists_eq_forall_mem_Icc_hasDerivWithinAt hf (mem_closedBall_self le_rfl) @[deprecated (since := "2025-06-24")] alias exists_forall_hasDerivWithinAt_Icc_eq := exists_eq_forall_mem_Icc_hasDerivWithinAt₀ open Classical in /-- **Picard-Lindelöf (Cauchy-Lipschitz) theorem**, differential form. This version shows the existence of a local flow and that it is Lipschitz continuous in the initial point. -/ theorem exists_forall_mem_closedBall_eq_hasDerivWithinAt_lipschitzOnWith (hf : IsPicardLindelof f t₀ x₀ a r L K) : ∃ α : E → ℝ → E, (∀ x ∈ closedBall x₀ r, α x t₀ = x ∧ ∀ t ∈ Icc tmin tmax, HasDerivWithinAt (α x) (f t (α x t)) (Icc tmin tmax) t) ∧ ∃ L' : ℝ≥0, ∀ t ∈ Icc tmin tmax, LipschitzOnWith L' (α · t) (closedBall x₀ r) := by have (x) (hx : x ∈ closedBall x₀ r) := FunSpace.exists_isFixedPt_next hf hx choose α hα using this set α' := fun (x : E) ↦ if hx : x ∈ closedBall x₀ r then α x hx |>.compProj else 0 with hα' refine ⟨α', fun x hx ↦ ⟨?_, fun t ht ↦ ?_⟩, ?_⟩ · rw [hα'] beta_reduce rw [dif_pos hx, FunSpace.compProj_val, ← hα, FunSpace.next_apply₀] · rw [hα'] beta_reduce rw [dif_pos hx, FunSpace.compProj_apply] apply hasDerivWithinAt_picard_Icc t₀.2 hf.continuousOn_uncurry (α x hx |>.continuous_compProj.continuousOn) (fun _ ht' ↦ α x hx |>.compProj_mem_closedBall hf.mul_max_le) x ht |>.congr_of_mem _ ht intro t' ht' nth_rw 1 [← hα] rw [FunSpace.compProj_of_mem ht', FunSpace.next_apply] · obtain ⟨L', h⟩ := FunSpace.exists_forall_closedBall_funSpace_dist_le_mul hf refine ⟨L', fun t ht ↦ LipschitzOnWith.of_dist_le_mul fun x hx y hy ↦ ?_⟩ simp_rw [hα'] rw [dif_pos hx, dif_pos hy, FunSpace.compProj_apply, FunSpace.compProj_apply, ← FunSpace.toContinuousMap_apply_eq_apply, ← FunSpace.toContinuousMap_apply_eq_apply] have : Nonempty (Icc tmin tmax) := ⟨t₀⟩ apply ContinuousMap.dist_le_iff_of_nonempty.mp exact h x y hx hy (α x hx) (α y hy) (hα x hx) (hα y hy) /-- **Picard-Lindelöf (Cauchy-Lipschitz) theorem**, differential form. This version shows the existence of a local flow and that it is continuous on its domain as a (partial) map `E × ℝ → E`. -/ theorem exists_forall_mem_closedBall_eq_hasDerivWithinAt_continuousOn (hf : IsPicardLindelof f t₀ x₀ a r L K) : ∃ α : E × ℝ → E, (∀ x ∈ closedBall x₀ r, α ⟨x, t₀⟩ = x ∧ ∀ t ∈ Icc tmin tmax, HasDerivWithinAt (α ⟨x, ·⟩) (f t (α ⟨x, t⟩)) (Icc tmin tmax) t) ∧ ContinuousOn α (closedBall x₀ r ×ˢ Icc tmin tmax) := by obtain ⟨α, hα1, L', hα2⟩ := hf.exists_forall_mem_closedBall_eq_hasDerivWithinAt_lipschitzOnWith refine ⟨uncurry α, hα1, ?_⟩ apply continuousOn_prod_of_continuousOn_lipschitzOnWith _ L' _ hα2 intro x hx t ht exact (hα1 x hx).2 t ht |>.continuousWithinAt /-- **Picard-Lindelöf (Cauchy-Lipschitz) theorem**, differential form. This version shows the existence of a local flow. -/ theorem exists_forall_mem_closedBall_eq_forall_mem_Icc_hasDerivWithinAt (hf : IsPicardLindelof f t₀ x₀ a r L K) : ∃ α : E → ℝ → E, ∀ x ∈ closedBall x₀ r, α x t₀ = x ∧ ∀ t ∈ Icc tmin tmax, HasDerivWithinAt (α x) (f t (α x t)) (Icc tmin tmax) t := have ⟨α, hα⟩ := exists_forall_mem_closedBall_eq_hasDerivWithinAt_lipschitzOnWith hf ⟨α, hα.1⟩ end IsPicardLindelof /-! ## $C^1$ vector field -/ namespace ContDiffAt variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : E → E} {x₀ : E} /-- If a vector field `f : E → E` is continuously differentiable at `x₀ : E`, then it admits an integral curve `α : ℝ → E` defined on an open interval, with initial condition `α t₀ = x`, where `x` may be different from `x₀`. -/ theorem exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt (hf : ContDiffAt ℝ 1 f x₀) (t₀ : ℝ) : ∃ r > (0 : ℝ), ∃ ε > (0 : ℝ), ∀ x ∈ closedBall x₀ r, ∃ α : ℝ → E, α t₀ = x ∧ ∀ t ∈ Ioo (t₀ - ε) (t₀ + ε), HasDerivAt α (f (α t)) t := by have ⟨ε, hε, a, r, _, _, hr, hpl⟩ := IsPicardLindelof.of_contDiffAt_one hf t₀ refine ⟨r, hr, ε, hε, fun x hx ↦ ?_⟩ have ⟨α, hα1, hα2⟩ := hpl.exists_eq_forall_mem_Icc_hasDerivWithinAt hx refine ⟨α, hα1, fun t ht ↦ ?_⟩ exact hα2 t (Ioo_subset_Icc_self ht) |>.hasDerivAt (Icc_mem_nhds ht.1 ht.2) /-- If a vector field `f : E → E` is continuously differentiable at `x₀ : E`, then it admits an integral curve `α : ℝ → E` defined on an open interval, with initial condition `α t₀ = x₀`. -/ theorem exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt₀ (hf : ContDiffAt ℝ 1 f x₀) (t₀ : ℝ) : ∃ α : ℝ → E, α t₀ = x₀ ∧ ∃ ε > (0 : ℝ), ∀ t ∈ Ioo (t₀ - ε) (t₀ + ε), HasDerivAt α (f (α t)) t := have ⟨_, hr, ε, hε, H⟩ := exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt hf t₀ have ⟨α, hα1, hα2⟩ := H x₀ (mem_closedBall_self (le_of_lt hr)) ⟨α, hα1, ε, hε, hα2⟩ @[deprecated (since := "2025-06-24")] alias exists_forall_hasDerivAt_Ioo_eq_of_contDiffAt := exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt₀ open Classical in /-- If a vector field `f : E → E` is continuously differentiable at `x₀ : E`, then it admits a flow `α : E → ℝ → E` defined on an open domain, with initial condition `α x t₀ = x` for all `x` within the domain. -/ theorem exists_eventually_eq_hasDerivAt (hf : ContDiffAt ℝ 1 f x₀) (t₀ : ℝ) : ∃ α : E → ℝ → E, ∀ᶠ xt in 𝓝 x₀ ×ˢ 𝓝 t₀, α xt.1 t₀ = xt.1 ∧ HasDerivAt (α xt.1) (f (α xt.1 xt.2)) xt.2 := by obtain ⟨r, hr, ε, hε, H⟩ := exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt hf t₀ choose α hα using H refine ⟨fun (x : E) ↦ if hx : x ∈ closedBall x₀ r then α x hx else 0, ?_⟩ rw [Filter.eventually_iff_exists_mem] refine ⟨closedBall x₀ r ×ˢ Ioo (t₀ - ε) (t₀ + ε), ?_, ?_⟩ · rw [Filter.prod_mem_prod_iff] exact ⟨closedBall_mem_nhds x₀ hr, Ioo_mem_nhds (by linarith) (by linarith)⟩ · intro ⟨x, t⟩ ⟨hx, ht⟩ grind end ContDiffAt
Pi.lean
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Topology.EMetricSpace.Basic import Mathlib.Topology.UniformSpace.Pi /-! # Indexed product of extended metric spaces -/ open Set Filter universe u v w variable {α : Type u} {β : Type v} {X : Type*} open scoped Uniformity Topology NNReal ENNReal Pointwise variable [PseudoEMetricSpace α] open EMetric section Pi open Finset variable {X : β → Type*} [Fintype β] instance [∀ b, EDist (X b)] : EDist (∀ b, X b) where edist f g := Finset.sup univ fun b => edist (f b) (g b) theorem edist_pi_def [∀ b, EDist (X b)] (f g : ∀ b, X b) : edist f g = Finset.sup univ fun b => edist (f b) (g b) := rfl theorem edist_le_pi_edist [∀ b, EDist (X b)] (f g : ∀ b, X b) (b : β) : edist (f b) (g b) ≤ edist f g := le_sup (f := fun b => edist (f b) (g b)) (Finset.mem_univ b) theorem edist_pi_le_iff [∀ b, EDist (X b)] {f g : ∀ b, X b} {d : ℝ≥0∞} : edist f g ≤ d ↔ ∀ b, edist (f b) (g b) ≤ d := Finset.sup_le_iff.trans <| by simp only [Finset.mem_univ, forall_const] theorem edist_pi_const_le (a b : α) : (edist (fun _ : β => a) fun _ => b) ≤ edist a b := edist_pi_le_iff.2 fun _ => le_rfl @[simp] theorem edist_pi_const [Nonempty β] (a b : α) : (edist (fun _ : β => a) fun _ => b) = edist a b := Finset.sup_const univ_nonempty (edist a b) /-- The product of a finite number of pseudoemetric spaces, with the max distance, is still a pseudoemetric space. This construction would also work for infinite products, but it would not give rise to the product topology. Hence, we only formalize it in the good situation of finitely many spaces. -/ instance pseudoEMetricSpacePi [∀ b, PseudoEMetricSpace (X b)] : PseudoEMetricSpace (∀ b, X b) where edist_self f := bot_unique <| Finset.sup_le <| by simp edist_comm f g := by simp [edist_pi_def, edist_comm] edist_triangle _ g _ := edist_pi_le_iff.2 fun b => le_trans (edist_triangle _ (g b) _) (add_le_add (edist_le_pi_edist _ _ _) (edist_le_pi_edist _ _ _)) toUniformSpace := Pi.uniformSpace _ uniformity_edist := by simp only [Pi.uniformity, PseudoEMetricSpace.uniformity_edist, comap_iInf, gt_iff_lt, preimage_setOf_eq, comap_principal, edist_pi_def] rw [iInf_comm]; congr; funext ε rw [iInf_comm]; congr; funext εpos simp [setOf_forall, εpos] end Pi variable {γ : Type w} [EMetricSpace γ] section Pi open Finset variable {X : β → Type*} [Fintype β] /-- The product of a finite number of emetric spaces, with the max distance, is still an emetric space. This construction would also work for infinite products, but it would not give rise to the product topology. Hence, we only formalize it in the good situation of finitely many spaces. -/ instance emetricSpacePi [∀ b, EMetricSpace (X b)] : EMetricSpace (∀ b, X b) := .ofT0PseudoEMetricSpace _ end Pi
Fractions.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.CalculusOfFractions /-! # Lemmas on fractions Let `W : MorphismProperty C`, and objects `X` and `Y` in `C`. In this file, we introduce structures like `W.LeftFraction₂ X Y` which consists of two left fractions with the "same denominator" which shall be important in the construction of the preadditive structure on the localized category when `C` is preadditive and `W` has a left calculus of fractions. When `W` has a left calculus of fractions, we generalize the lemmas `RightFraction.exists_leftFraction` as `RightFraction₂.exists_leftFraction₂`, `Localization.exists_leftFraction` as `Localization.exists_leftFraction₂` and `Localization.exists_leftFraction₃`, and `LeftFraction.map_eq_iff` as `LeftFraction₂.map_eq_iff`. ## Implementation note The lemmas in this file are phrased with data that is bundled into structures like `LeftFraction₂` or `LeftFraction₃`. It could have been possible to phrase them with "unbundled data". However, this would require introducing 4 or 5 variables instead of one. It is also very convenient to use dot notation. Many definitions have been made reducible so as to ease rewrites when this API is used. -/ namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] namespace MorphismProperty /-- This structure contains the data of two left fractions for `W : MorphismProperty C` that have the same "denominator". -/ structure LeftFraction₂ (X Y : C) where /-- the auxiliary object of left fractions -/ {Y' : C} /-- the numerator of the first left fraction -/ f : X ⟶ Y' /-- the numerator of the second left fraction -/ f' : X ⟶ Y' /-- the denominator of the left fractions -/ s : Y ⟶ Y' /-- the condition that the denominator belongs to the given morphism property -/ hs : W s /-- This structure contains the data of three left fractions for `W : MorphismProperty C` that have the same "denominator". -/ structure LeftFraction₃ (X Y : C) where /-- the auxiliary object of left fractions -/ {Y' : C} /-- the numerator of the first left fraction -/ f : X ⟶ Y' /-- the numerator of the second left fraction -/ f' : X ⟶ Y' /-- the numerator of the third left fraction -/ f'' : X ⟶ Y' /-- the denominator of the left fractions -/ s : Y ⟶ Y' /-- the condition that the denominator belongs to the given morphism property -/ hs : W s /-- This structure contains the data of two right fractions for `W : MorphismProperty C` that have the same "denominator". -/ structure RightFraction₂ (X Y : C) where /-- the auxiliary object of right fractions -/ {X' : C} /-- the denominator of the right fractions -/ s : X' ⟶ X /-- the condition that the denominator belongs to the given morphism property -/ hs : W s /-- the numerator of the first right fraction -/ f : X' ⟶ Y /-- the numerator of the second right fraction -/ f' : X' ⟶ Y variable {W} /-- The equivalence relation on tuples of left fractions with the same denominator for a morphism property `W`. The fact it is an equivalence relation is not formalized, but it would follow easily from `LeftFraction₂.map_eq_iff`. -/ def LeftFraction₂Rel {X Y : C} (z₁ z₂ : W.LeftFraction₂ X Y) : Prop := ∃ (Z : C) (t₁ : z₁.Y' ⟶ Z) (t₂ : z₂.Y' ⟶ Z) (_ : z₁.s ≫ t₁ = z₂.s ≫ t₂) (_ : z₁.f ≫ t₁ = z₂.f ≫ t₂) (_ : z₁.f' ≫ t₁ = z₂.f' ≫ t₂), W (z₁.s ≫ t₁) namespace LeftFraction₂ variable {X Y : C} (φ : W.LeftFraction₂ X Y) /-- The first left fraction. -/ abbrev fst : W.LeftFraction X Y where Y' := φ.Y' f := φ.f s := φ.s hs := φ.hs /-- The second left fraction. -/ abbrev snd : W.LeftFraction X Y where Y' := φ.Y' f := φ.f' s := φ.s hs := φ.hs /-- The exchange of the two fractions. -/ abbrev symm : W.LeftFraction₂ X Y where Y' := φ.Y' f := φ.f' f' := φ.f s := φ.s hs := φ.hs end LeftFraction₂ namespace LeftFraction₃ variable {X Y : C} (φ : W.LeftFraction₃ X Y) /-- The first left fraction. -/ abbrev fst : W.LeftFraction X Y where Y' := φ.Y' f := φ.f s := φ.s hs := φ.hs /-- The second left fraction. -/ abbrev snd : W.LeftFraction X Y where Y' := φ.Y' f := φ.f' s := φ.s hs := φ.hs /-- The third left fraction. -/ abbrev thd : W.LeftFraction X Y where Y' := φ.Y' f := φ.f'' s := φ.s hs := φ.hs /-- Forgets the first fraction. -/ abbrev forgetFst : W.LeftFraction₂ X Y where Y' := φ.Y' f := φ.f' f' := φ.f'' s := φ.s hs := φ.hs /-- Forgets the second fraction. -/ abbrev forgetSnd : W.LeftFraction₂ X Y where Y' := φ.Y' f := φ.f f' := φ.f'' s := φ.s hs := φ.hs /-- Forgets the third fraction. -/ abbrev forgetThd : W.LeftFraction₂ X Y where Y' := φ.Y' f := φ.f f' := φ.f' s := φ.s hs := φ.hs end LeftFraction₃ namespace LeftFraction₂Rel variable {X Y : C} {z₁ z₂ : W.LeftFraction₂ X Y} lemma fst (h : LeftFraction₂Rel z₁ z₂) : LeftFractionRel z₁.fst z₂.fst := by obtain ⟨Z, t₁, t₂, hst, hft, _, ht⟩ := h exact ⟨Z, t₁, t₂, hst, hft, ht⟩ lemma snd (h : LeftFraction₂Rel z₁ z₂) : LeftFractionRel z₁.snd z₂.snd := by obtain ⟨Z, t₁, t₂, hst, _, hft', ht⟩ := h exact ⟨Z, t₁, t₂, hst, hft', ht⟩ end LeftFraction₂Rel namespace LeftFraction₂ variable (W) variable [W.HasLeftCalculusOfFractions] lemma map_eq_iff {X Y : C} (φ ψ : W.LeftFraction₂ X Y) : (φ.fst.map L (Localization.inverts _ _) = ψ.fst.map L (Localization.inverts _ _) ∧ φ.snd.map L (Localization.inverts _ _) = ψ.snd.map L (Localization.inverts _ _)) ↔ LeftFraction₂Rel φ ψ := by simp only [LeftFraction.map_eq_iff L W] constructor · intro ⟨h, h'⟩ obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h obtain ⟨Z', t₁', t₂', hst', hft', ht'⟩ := h' dsimp at t₁ t₂ t₁' t₂' hst hft hst' hft' ht ht' have ⟨α, hα⟩ := (RightFraction.mk _ ht (φ.s ≫ t₁')).exists_leftFraction simp only [Category.assoc] at hα obtain ⟨Z'', u, hu, fac⟩ := HasLeftCalculusOfFractions.ext _ _ _ φ.hs hα have hα' : ψ.s ≫ t₂ ≫ α.f ≫ u = ψ.s ≫ t₂' ≫ α.s ≫ u := by rw [← reassoc_of% hst, ← reassoc_of% hα, ← reassoc_of% hst'] obtain ⟨Z''', u', hu', fac'⟩ := HasLeftCalculusOfFractions.ext _ _ _ ψ.hs hα' simp only [Category.assoc] at fac fac' refine ⟨Z''', t₁' ≫ α.s ≫ u ≫ u', t₂' ≫ α.s ≫ u ≫ u', ?_, ?_, ?_, ?_⟩ · rw [reassoc_of% hst'] · rw [reassoc_of% fac, reassoc_of% hft, fac'] · rw [reassoc_of% hft'] · rw [← Category.assoc] exact W.comp_mem _ _ ht' (W.comp_mem _ _ α.hs (W.comp_mem _ _ hu hu')) · intro h exact ⟨h.fst, h.snd⟩ end LeftFraction₂ namespace RightFraction₂ variable {X Y : C} variable (φ : W.RightFraction₂ X Y) /-- The first right fraction. -/ abbrev fst : W.RightFraction X Y where X' := φ.X' f := φ.f s := φ.s hs := φ.hs /-- The second right fraction. -/ abbrev snd : W.RightFraction X Y where X' := φ.X' f := φ.f' s := φ.s hs := φ.hs lemma exists_leftFraction₂ [W.HasLeftCalculusOfFractions] : ∃ (ψ : W.LeftFraction₂ X Y), φ.f ≫ ψ.s = φ.s ≫ ψ.f ∧ φ.f' ≫ ψ.s = φ.s ≫ ψ.f' := by obtain ⟨ψ₁, hψ₁⟩ := φ.fst.exists_leftFraction obtain ⟨ψ₂, hψ₂⟩ := φ.snd.exists_leftFraction obtain ⟨α, hα⟩ := (RightFraction.mk _ ψ₁.hs ψ₂.s).exists_leftFraction dsimp at hψ₁ hψ₂ hα refine ⟨LeftFraction₂.mk (ψ₁.f ≫ α.f) (ψ₂.f ≫ α.s) (ψ₂.s ≫ α.s) (W.comp_mem _ _ ψ₂.hs α.hs), ?_, ?_⟩ · dsimp rw [hα, reassoc_of% hψ₁] · rw [reassoc_of% hψ₂] end RightFraction₂ end MorphismProperty namespace Localization variable [W.HasLeftCalculusOfFractions] open MorphismProperty lemma exists_leftFraction₂ {X Y : C} (f f' : L.obj X ⟶ L.obj Y) : ∃ (φ : W.LeftFraction₂ X Y), f = φ.fst.map L (inverts L W) ∧ f' = φ.snd.map L (inverts L W) := by have ⟨φ, hφ⟩ := exists_leftFraction L W f have ⟨φ', hφ'⟩ := exists_leftFraction L W f' obtain ⟨α, hα⟩ := (RightFraction.mk _ φ.hs φ'.s).exists_leftFraction let ψ : W.LeftFraction₂ X Y := { Y' := α.Y' f := φ.f ≫ α.f f' := φ'.f ≫ α.s s := φ'.s ≫ α.s hs := W.comp_mem _ _ φ'.hs α.hs } have := inverts L W _ φ'.hs have := inverts L W _ α.hs have : IsIso (L.map (φ'.s ≫ α.s)) := by rw [L.map_comp] infer_instance refine ⟨ψ, ?_, ?_⟩ · rw [← cancel_mono (L.map (φ'.s ≫ α.s)), LeftFraction.map_comp_map_s, hα, L.map_comp, hφ, LeftFraction.map_comp_map_s_assoc, L.map_comp] · rw [← cancel_mono (L.map (φ'.s ≫ α.s)), hφ'] nth_rw 1 [L.map_comp] rw [LeftFraction.map_comp_map_s_assoc, LeftFraction.map_comp_map_s, L.map_comp] lemma exists_leftFraction₃ {X Y : C} (f f' f'' : L.obj X ⟶ L.obj Y) : ∃ (φ : W.LeftFraction₃ X Y), f = φ.fst.map L (inverts L W) ∧ f' = φ.snd.map L (inverts L W) ∧ f'' = φ.thd.map L (inverts L W) := by obtain ⟨α, hα, hα'⟩ := exists_leftFraction₂ L W f f' have ⟨β, hβ⟩ := exists_leftFraction L W f'' obtain ⟨γ, hγ⟩ := (RightFraction.mk _ α.hs β.s).exists_leftFraction dsimp at hγ let ψ : W.LeftFraction₃ X Y := { Y' := γ.Y' f := α.f ≫ γ.f f' := α.f' ≫ γ.f f'' := β.f ≫ γ.s s := β.s ≫ γ.s hs := W.comp_mem _ _ β.hs γ.hs } have := inverts L W _ β.hs have := inverts L W _ γ.hs have : IsIso (L.map (β.s ≫ γ.s)) := by rw [L.map_comp] infer_instance refine ⟨ψ, ?_, ?_, ?_⟩ · rw [← cancel_mono (L.map (β.s ≫ γ.s)), LeftFraction.map_comp_map_s, hα, hγ, L.map_comp, LeftFraction.map_comp_map_s_assoc, L.map_comp] · rw [← cancel_mono (L.map (β.s ≫ γ.s)), LeftFraction.map_comp_map_s, hα', hγ, L.map_comp, LeftFraction.map_comp_map_s_assoc, L.map_comp] · rw [← cancel_mono (L.map (β.s ≫ γ.s)), hβ] nth_rw 1 [L.map_comp] rw [LeftFraction.map_comp_map_s_assoc, LeftFraction.map_comp_map_s, L.map_comp] end Localization end CategoryTheory
Constructions.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Kim Morrison, Chris Hughes, Anne Baanen -/ import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.LinearAlgebra.Basis.Prod import Mathlib.LinearAlgebra.Dimension.Free import Mathlib.LinearAlgebra.TensorProduct.Basis /-! # Rank of various constructions ## Main statements - `rank_quotient_add_rank_le` : `rank M/N + rank N ≤ rank M`. - `lift_rank_add_lift_rank_le_rank_prod`: `rank M × N ≤ rank M + rank N`. - `rank_span_le_of_finite`: `rank (span s) ≤ #s` for finite `s`. For free modules, we have - `rank_prod` : `rank M × N = rank M + rank N`. - `rank_finsupp` : `rank (ι →₀ M) = #ι * rank M` - `rank_directSum`: `rank (⨁ Mᵢ) = ∑ rank Mᵢ` - `rank_tensorProduct`: `rank (M ⊗ N) = rank M * rank N`. Lemmas for ranks of submodules and subalgebras are also provided. We have finrank variants for most lemmas as well. -/ noncomputable section universe u u' v v' u₁' w w' variable {R : Type u} {S : Type u'} {M : Type v} {M' : Type v'} {M₁ : Type v} variable {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*} open Basis Cardinal DirectSum Function Module Set Submodule section Quotient variable [Ring R] [CommRing S] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] theorem LinearIndependent.sumElim_of_quotient {M' : Submodule R M} {ι₁ ι₂} {f : ι₁ → M'} (hf : LinearIndependent R f) (g : ι₂ → M) (hg : LinearIndependent R (Submodule.Quotient.mk (p := M') ∘ g)) : LinearIndependent R (Sum.elim (f · : ι₁ → M) g) := by refine .sum_type (hf.map' M'.subtype M'.ker_subtype) (.of_comp M'.mkQ hg) ?_ refine disjoint_def.mpr fun x h₁ h₂ ↦ ?_ have : x ∈ M' := span_le.mpr (Set.range_subset_iff.mpr fun i ↦ (f i).prop) h₁ obtain ⟨c, rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp h₂ simp_rw [← Quotient.mk_eq_zero, ← mkQ_apply, map_finsuppSum, map_smul, mkQ_apply] at this rw [linearIndependent_iff.mp hg _ this, Finsupp.sum_zero_index] @[deprecated (since := "2025-02-21")] alias LinearIndependent.sum_elim_of_quotient := LinearIndependent.sumElim_of_quotient theorem LinearIndepOn.union_of_quotient {s t : Set ι} {f : ι → M} (hs : LinearIndepOn R f s) (ht : LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t) : LinearIndepOn R f (s ∪ t) := by apply hs.union ht.of_comp convert (Submodule.range_ker_disjoint ht).symm · simp aesop theorem LinearIndepOn.union_id_of_quotient {M' : Submodule R M} {s : Set M} (hs : s ⊆ M') (hs' : LinearIndepOn R id s) {t : Set M} (ht : LinearIndepOn R (mkQ M') t) : LinearIndepOn R id (s ∪ t) := hs'.union_of_quotient <| by rw [image_id] exact ht.of_comp ((span R s).mapQ M' (LinearMap.id) (span_le.2 hs)) @[deprecated (since := "2025-02-16")] alias LinearIndependent.union_of_quotient := LinearIndepOn.union_id_of_quotient theorem linearIndepOn_union_iff_quotient {s t : Set ι} {f : ι → M} (hst : Disjoint s t) : LinearIndepOn R f (s ∪ t) ↔ LinearIndepOn R f s ∧ LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ h.1.union_of_quotient h.2⟩ · exact h.mono subset_union_left apply (h.mono subset_union_right).map simpa [← image_eq_range] using ((linearIndepOn_union_iff hst).1 h).2.2.symm theorem LinearIndepOn.quotient_iff_union {s t : Set ι} {f : ι → M} (hs : LinearIndepOn R f s) (hst : Disjoint s t) : LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t ↔ LinearIndepOn R f (s ∪ t) := by rw [linearIndepOn_union_iff_quotient hst, and_iff_right hs] theorem rank_quotient_add_rank_le [Nontrivial R] (M' : Submodule R M) : Module.rank R (M ⧸ M') + Module.rank R M' ≤ Module.rank R M := by conv_lhs => simp only [Module.rank_def] rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range _) _ (bddAbove_range _)] refine ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ ?_ choose f hf using Submodule.Quotient.mk_surjective M' simpa [add_comm] using (LinearIndependent.sumElim_of_quotient ht (fun (i : s) ↦ f i) (by simpa [Function.comp_def, hf] using hs)).cardinal_le_rank theorem rank_quotient_le (p : Submodule R M) : Module.rank R (M ⧸ p) ≤ Module.rank R M := (mkQ p).rank_le_of_surjective Quot.mk_surjective /-- The dimension of a quotient is bounded by the dimension of the ambient space. -/ theorem Submodule.finrank_quotient_le [StrongRankCondition R] [Module.Finite R M] (s : Submodule R M) : finrank R (M ⧸ s) ≤ finrank R M := toNat_le_toNat ((Submodule.mkQ s).rank_le_of_surjective Quot.mk_surjective) (rank_lt_aleph0 _ _) end Quotient variable [Semiring R] [CommSemiring S] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M₁] variable [Module R M] section ULift @[simp] theorem rank_ulift : Module.rank R (ULift.{w} M) = Cardinal.lift.{w} (Module.rank R M) := Cardinal.lift_injective.{v} <| Eq.symm <| (lift_lift _).trans ULift.moduleEquiv.symm.lift_rank_eq @[simp] theorem finrank_ulift : finrank R (ULift M) = finrank R M := by simp_rw [finrank, rank_ulift, toNat_lift] end ULift section Prod variable (R M M') variable [Module R M₁] [Module R M'] theorem rank_add_rank_le_rank_prod [Nontrivial R] : Module.rank R M + Module.rank R M₁ ≤ Module.rank R (M × M₁) := by conv_lhs => simp only [Module.rank_def] rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range _) _ (bddAbove_range _)] exact ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ (linearIndependent_inl_union_inr' hs ht).cardinal_le_rank theorem lift_rank_add_lift_rank_le_rank_prod [Nontrivial R] : lift.{v'} (Module.rank R M) + lift.{v} (Module.rank R M') ≤ Module.rank R (M × M') := by rw [← rank_ulift, ← rank_ulift] exact (rank_add_rank_le_rank_prod R _).trans_eq (ULift.moduleEquiv.prodCongr ULift.moduleEquiv).rank_eq variable {R M M'} variable [StrongRankCondition R] [Module.Free R M] [Module.Free R M'] [Module.Free R M₁] open Module.Free /-- If `M` and `M'` are free, then the rank of `M × M'` is `(Module.rank R M).lift + (Module.rank R M').lift`. -/ @[simp] theorem rank_prod : Module.rank R (M × M') = Cardinal.lift.{v'} (Module.rank R M) + Cardinal.lift.{v, v'} (Module.rank R M') := by simpa [rank_eq_card_chooseBasisIndex R M, rank_eq_card_chooseBasisIndex R M', lift_umax] using ((chooseBasis R M).prod (chooseBasis R M')).mk_eq_rank.symm /-- If `M` and `M'` are free (and lie in the same universe), the rank of `M × M'` is `(Module.rank R M) + (Module.rank R M')`. -/ theorem rank_prod' : Module.rank R (M × M₁) = Module.rank R M + Module.rank R M₁ := by simp /-- The finrank of `M × M'` is `(finrank R M) + (finrank R M')`. -/ @[simp] theorem Module.finrank_prod [Module.Finite R M] [Module.Finite R M'] : finrank R (M × M') = finrank R M + finrank R M' := by simp [finrank, rank_lt_aleph0 R M, rank_lt_aleph0 R M'] end Prod section Finsupp variable (R M M') variable [StrongRankCondition R] [Module.Free R M] [Module R M'] [Module.Free R M'] open Module.Free @[simp] theorem rank_finsupp (ι : Type w) : Module.rank R (ι →₀ M) = Cardinal.lift.{v} #ι * Cardinal.lift.{w} (Module.rank R M) := by obtain ⟨⟨_, bs⟩⟩ := Module.Free.exists_basis (R := R) (M := M) rw [← bs.mk_eq_rank'', ← (Finsupp.basis fun _ : ι => bs).mk_eq_rank'', Cardinal.mk_sigma, Cardinal.sum_const] theorem rank_finsupp' (ι : Type v) : Module.rank R (ι →₀ M) = #ι * Module.rank R M := by simp [rank_finsupp] /-- The rank of `(ι →₀ R)` is `(#ι).lift`. -/ theorem rank_finsupp_self (ι : Type w) : Module.rank R (ι →₀ R) = Cardinal.lift.{u} #ι := by simp /-- If `R` and `ι` lie in the same universe, the rank of `(ι →₀ R)` is `# ι`. -/ theorem rank_finsupp_self' {ι : Type u} : Module.rank R (ι →₀ R) = #ι := by simp /-- The rank of the direct sum is the sum of the ranks. -/ @[simp] theorem rank_directSum {ι : Type v} (M : ι → Type w) [∀ i : ι, AddCommMonoid (M i)] [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] : Module.rank R (⨁ i, M i) = Cardinal.sum fun i => Module.rank R (M i) := by let B i := chooseBasis R (M i) let b : Basis _ R (⨁ i, M i) := DFinsupp.basis fun i => B i simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank''] /-- If `m` and `n` are finite, the rank of `m × n` matrices over a module `M` is `(#m).lift * (#n).lift * rank R M`. -/ @[simp] theorem rank_matrix_module (m : Type w) (n : Type w') [Finite m] [Finite n] : Module.rank R (Matrix m n M) = lift.{max v w'} #m * lift.{max v w} #n * lift.{max w w'} (Module.rank R M) := by cases nonempty_fintype m cases nonempty_fintype n obtain ⟨I, b⟩ := Module.Free.exists_basis (R := R) (M := M) rw [← (b.matrix m n).mk_eq_rank''] simp only [mk_prod, lift_mul, lift_lift, ← mul_assoc, b.mk_eq_rank''] /-- If `m` and `n` are finite and lie in the same universe, the rank of `m × n` matrices over a module `M` is `(#m * #n).lift * rank R M`. -/ @[simp high] theorem rank_matrix_module' (m n : Type w) [Finite m] [Finite n] : Module.rank R (Matrix m n M) = lift.{max v} (#m * #n) * lift.{w} (Module.rank R M) := by rw [rank_matrix_module, lift_mul, lift_umax.{w, v}] /-- If `m` and `n` are finite, the rank of `m × n` matrices is `(#m).lift * (#n).lift`. -/ theorem rank_matrix (m : Type v) (n : Type w) [Finite m] [Finite n] : Module.rank R (Matrix m n R) = Cardinal.lift.{max v w u, v} #m * Cardinal.lift.{max v w u, w} #n := by rw [rank_matrix_module, rank_self, lift_one, mul_one, ← lift_lift.{v, max u w}, lift_id, ← lift_lift.{w, max u v}, lift_id] /-- If `m` and `n` are finite and lie in the same universe, the rank of `m × n` matrices is `(#n * #m).lift`. -/ theorem rank_matrix' (m n : Type v) [Finite m] [Finite n] : Module.rank R (Matrix m n R) = Cardinal.lift.{u} (#m * #n) := by rw [rank_matrix, lift_mul, lift_umax.{v, u}] /-- If `m` and `n` are finite and lie in the same universe as `R`, the rank of `m × n` matrices is `# m * # n`. -/ theorem rank_matrix'' (m n : Type u) [Finite m] [Finite n] : Module.rank R (Matrix m n R) = #m * #n := by simp open Fintype namespace Module @[simp] theorem finrank_finsupp {ι : Type v} [Fintype ι] : finrank R (ι →₀ M) = card ι * finrank R M := by rw [finrank, finrank, rank_finsupp, ← mk_toNat_eq_card, toNat_mul, toNat_lift, toNat_lift] /-- The finrank of `(ι →₀ R)` is `Fintype.card ι`. -/ @[simp] theorem finrank_finsupp_self {ι : Type v} [Fintype ι] : finrank R (ι →₀ R) = card ι := by rw [finrank, rank_finsupp_self, ← mk_toNat_eq_card, toNat_lift] /-- The finrank of the direct sum is the sum of the finranks. -/ @[simp] theorem finrank_directSum {ι : Type v} [Fintype ι] (M : ι → Type w) [∀ i : ι, AddCommMonoid (M i)] [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] [∀ i : ι, Module.Finite R (M i)] : finrank R (⨁ i, M i) = ∑ i, finrank R (M i) := by letI := nontrivial_of_invariantBasisNumber R simp only [finrank, fun i => rank_eq_card_chooseBasisIndex R (M i), rank_directSum, ← mk_sigma, mk_toNat_eq_card, card_sigma] /-- If `m` and `n` are `Fintype`, the finrank of `m × n` matrices over a module `M` is `(Fintype.card m) * (Fintype.card n) * finrank R M`. -/ theorem finrank_matrix (m n : Type*) [Fintype m] [Fintype n] : finrank R (Matrix m n M) = card m * card n * finrank R M := by simp [finrank] end Module end Finsupp section Pi variable [StrongRankCondition R] [Module.Free R M] variable [∀ i, AddCommMonoid (φ i)] [∀ i, Module R (φ i)] [∀ i, Module.Free R (φ i)] open Module.Free open LinearMap /-- The rank of a finite product of free modules is the sum of the ranks. -/ -- this result is not true without the freeness assumption @[simp] theorem rank_pi [Finite η] : Module.rank R (∀ i, φ i) = Cardinal.sum fun i => Module.rank R (φ i) := by cases nonempty_fintype η let B i := chooseBasis R (φ i) let b : Basis _ R (∀ i, φ i) := Pi.basis fun i => B i simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank''] variable (R) /-- The finrank of `(ι → R)` is `Fintype.card ι`. -/ theorem Module.finrank_pi {ι : Type v} [Fintype ι] : finrank R (ι → R) = Fintype.card ι := by simp [finrank] --TODO: this should follow from `LinearEquiv.finrank_eq`, that is over a field. /-- The finrank of a finite product is the sum of the finranks. -/ theorem Module.finrank_pi_fintype {ι : Type v} [Fintype ι] {M : ι → Type w} [∀ i : ι, AddCommMonoid (M i)] [∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] [∀ i : ι, Module.Finite R (M i)] : finrank R (∀ i, M i) = ∑ i, finrank R (M i) := by letI := nontrivial_of_invariantBasisNumber R simp only [finrank, fun i => rank_eq_card_chooseBasisIndex R (M i), rank_pi, ← mk_sigma, mk_toNat_eq_card, Fintype.card_sigma] variable {R} variable [Fintype η] theorem rank_fun {M η : Type u} [Fintype η] [AddCommMonoid M] [Module R M] [Module.Free R M] : Module.rank R (η → M) = Fintype.card η * Module.rank R M := by rw [rank_pi, Cardinal.sum_const', Cardinal.mk_fintype] theorem rank_fun_eq_lift_mul : Module.rank R (η → M) = (Fintype.card η : Cardinal.{max u₁' v}) * Cardinal.lift.{u₁'} (Module.rank R M) := by rw [rank_pi, Cardinal.sum_const, Cardinal.mk_fintype, Cardinal.lift_natCast] theorem rank_fun' : Module.rank R (η → R) = Fintype.card η := by rw [rank_fun_eq_lift_mul, rank_self, Cardinal.lift_one, mul_one] theorem rank_fin_fun (n : ℕ) : Module.rank R (Fin n → R) = n := by simp variable (R) /-- The vector space of functions on a `Fintype ι` has finrank equal to the cardinality of `ι`. -/ @[simp] theorem Module.finrank_fintype_fun_eq_card : finrank R (η → R) = Fintype.card η := finrank_eq_of_rank_eq rank_fun' /-- The vector space of functions on `Fin n` has finrank equal to `n`. -/ theorem Module.finrank_fin_fun {n : ℕ} : finrank R (Fin n → R) = n := by simp variable {R} -- TODO: merge with the `Finrank` content /-- An `n`-dimensional `R`-vector space is equivalent to `Fin n → R`. -/ def finDimVectorspaceEquiv (n : ℕ) (hn : Module.rank R M = n) : M ≃ₗ[R] Fin n → R := by haveI := nontrivial_of_invariantBasisNumber R have : Cardinal.lift.{u} (n : Cardinal.{v}) = Cardinal.lift.{v} (n : Cardinal.{u}) := by simp have hn := Cardinal.lift_inj.{v, u}.2 hn rw [this] at hn rw [← @rank_fin_fun R _ _ n] at hn haveI : Module.Free R (Fin n → R) := Module.Free.pi _ _ exact Classical.choice (nonempty_linearEquiv_of_lift_rank_eq hn) end Pi section TensorProduct open TensorProduct variable [StrongRankCondition R] [StrongRankCondition S] variable [Module S M] [Module S M'] [Module.Free S M'] variable [Module S M₁] [Module.Free S M₁] variable [Algebra S R] [IsScalarTower S R M] [Module.Free R M] open Module.Free /-- The `S`-rank of `M ⊗[R] M'` is `(Module.rank S M).lift * (Module.rank R M').lift`. -/ @[simp] theorem rank_tensorProduct : Module.rank R (M ⊗[S] M') = Cardinal.lift.{v'} (Module.rank R M) * Cardinal.lift.{v} (Module.rank S M') := by obtain ⟨⟨_, bM⟩⟩ := Module.Free.exists_basis (R := R) (M := M) obtain ⟨⟨_, bN⟩⟩ := Module.Free.exists_basis (R := S) (M := M') rw [← bM.mk_eq_rank'', ← bN.mk_eq_rank'', ← (bM.tensorProduct bN).mk_eq_rank'', Cardinal.mk_prod] /-- If `M` and `M'` lie in the same universe, the `S`-rank of `M ⊗[R] M'` is `(Module.rank S M) * (Module.rank R M')`. -/ theorem rank_tensorProduct' : Module.rank R (M ⊗[S] M₁) = Module.rank R M * Module.rank S M₁ := by simp theorem Module.rank_baseChange : Module.rank R (R ⊗[S] M') = Cardinal.lift.{u} (Module.rank S M') := by simp /-- The `S`-finrank of `M ⊗[R] M'` is `(finrank S M) * (finrank R M')`. -/ @[simp] theorem Module.finrank_tensorProduct : finrank R (M ⊗[S] M') = finrank R M * finrank S M' := by simp [finrank] theorem Module.finrank_baseChange : finrank R (R ⊗[S] M') = finrank S M' := by simp end TensorProduct section SubmoduleRank section open Module namespace Submodule theorem lt_of_le_of_finrank_lt_finrank {s t : Submodule R M} (le : s ≤ t) (lt : finrank R s < finrank R t) : s < t := lt_of_le_of_ne le fun h => ne_of_lt lt (by rw [h]) theorem lt_top_of_finrank_lt_finrank {s : Submodule R M} (lt : finrank R s < finrank R M) : s < ⊤ := by rw [← finrank_top R M] at lt exact lt_of_le_of_finrank_lt_finrank le_top lt end Submodule variable [StrongRankCondition R] /-- The dimension of a submodule is bounded by the dimension of the ambient space. -/ theorem Submodule.finrank_le [Module.Finite R M] (s : Submodule R M) : finrank R s ≤ finrank R M := toNat_le_toNat (Submodule.rank_le s) (rank_lt_aleph0 _ _) /-- Pushforwards of finite submodules have a smaller finrank. -/ theorem Submodule.finrank_map_le [Module R M'] (f : M →ₗ[R] M') (p : Submodule R M) [Module.Finite R p] : finrank R (p.map f) ≤ finrank R p := finrank_le_finrank_of_rank_le_rank (lift_rank_map_le _ _) (rank_lt_aleph0 _ _) theorem Submodule.finrank_mono {s t : Submodule R M} [Module.Finite R t] (hst : s ≤ t) : finrank R s ≤ finrank R t := Cardinal.toNat_le_toNat (Submodule.rank_mono hst) (rank_lt_aleph0 R ↥t) end end SubmoduleRank section Span variable [StrongRankCondition R] theorem rank_span_le (s : Set M) : Module.rank R (span R s) ≤ #s := by rw [Finsupp.span_eq_range_linearCombination, ← lift_strictMono.le_iff_le] refine (lift_rank_range_le _).trans ?_ rw [rank_finsupp_self] simp only [lift_lift, le_refl] theorem rank_span_finset_le (s : Finset M) : Module.rank R (span R (s : Set M)) ≤ s.card := by simpa using rank_span_le s.toSet theorem rank_span_of_finset (s : Finset M) : Module.rank R (span R (s : Set M)) < ℵ₀ := (rank_span_finset_le s).trans_lt (Cardinal.nat_lt_aleph0 _) open Submodule Module variable (R) in /-- The rank of a set of vectors as a natural number. -/ protected noncomputable def Set.finrank (s : Set M) : ℕ := finrank R (span R s) theorem finrank_span_le_card (s : Set M) [Fintype s] : finrank R (span R s) ≤ s.toFinset.card := finrank_le_of_rank_le (by simpa using rank_span_le (R := R) s) theorem finrank_span_finset_le_card (s : Finset M) : (s : Set M).finrank R ≤ s.card := calc (s : Set M).finrank R ≤ (s : Set M).toFinset.card := finrank_span_le_card (M := M) s _ = s.card := by simp theorem finrank_range_le_card {ι : Type*} [Fintype ι] (b : ι → M) : (Set.range b).finrank R ≤ Fintype.card ι := by classical refine (finrank_span_le_card _).trans ?_ rw [Set.toFinset_range] exact Finset.card_image_le theorem finrank_span_eq_card [Nontrivial R] {ι : Type*} [Fintype ι] {b : ι → M} (hb : LinearIndependent R b) : finrank R (span R (Set.range b)) = Fintype.card ι := finrank_eq_of_rank_eq (by have : Module.rank R (span R (Set.range b)) = #(Set.range b) := rank_span hb rwa [← lift_inj, mk_range_eq_of_injective hb.injective, Cardinal.mk_fintype, lift_natCast, lift_eq_nat_iff] at this) theorem finrank_span_set_eq_card {s : Set M} [Fintype s] (hs : LinearIndepOn R id s) : finrank R (span R s) = s.toFinset.card := finrank_eq_of_rank_eq (by have : Module.rank R (span R s) = #s := rank_span_set hs rwa [Cardinal.mk_fintype, ← Set.toFinset_card] at this) theorem finrank_span_finset_eq_card {s : Finset M} (hs : LinearIndepOn R id (s : Set M)) : finrank R (span R (s : Set M)) = s.card := by convert finrank_span_set_eq_card (s := (s : Set M)) hs ext simp theorem span_lt_of_subset_of_card_lt_finrank {s : Set M} [Fintype s] {t : Submodule R M} (subset : s ⊆ t) (card_lt : s.toFinset.card < finrank R t) : span R s < t := lt_of_le_of_finrank_lt_finrank (span_le.mpr subset) (lt_of_le_of_lt (finrank_span_le_card _) card_lt) theorem span_lt_top_of_card_lt_finrank {s : Set M} [Fintype s] (card_lt : s.toFinset.card < finrank R M) : span R s < ⊤ := lt_top_of_finrank_lt_finrank (lt_of_le_of_lt (finrank_span_le_card _) card_lt) lemma finrank_le_of_span_eq_top {ι : Type*} [Fintype ι] {v : ι → M} (hv : Submodule.span R (Set.range v) = ⊤) : finrank R M ≤ Fintype.card ι := by classical rw [← finrank_top, ← hv] exact (finrank_span_le_card _).trans (by convert Fintype.card_range_le v; rw [Set.toFinset_card]) end Span section SubalgebraRank open Module section Semiring variable {F E : Type*} [CommSemiring F] [Semiring E] [Algebra F E] @[simp] theorem Subalgebra.rank_toSubmodule (S : Subalgebra F E) : Module.rank F (Subalgebra.toSubmodule S) = Module.rank F S := rfl @[simp] theorem Subalgebra.finrank_toSubmodule (S : Subalgebra F E) : finrank F (Subalgebra.toSubmodule S) = finrank F S := rfl theorem subalgebra_top_rank_eq_submodule_top_rank : Module.rank F (⊤ : Subalgebra F E) = Module.rank F (⊤ : Submodule F E) := by rw [← Algebra.top_toSubmodule] rfl theorem subalgebra_top_finrank_eq_submodule_top_finrank : finrank F (⊤ : Subalgebra F E) = finrank F (⊤ : Submodule F E) := by rw [← Algebra.top_toSubmodule] rfl theorem Subalgebra.rank_top : Module.rank F (⊤ : Subalgebra F E) = Module.rank F E := by rw [subalgebra_top_rank_eq_submodule_top_rank] exact _root_.rank_top F E end Semiring section Ring variable {F E : Type*} [CommRing F] [Ring E] [Algebra F E] variable [StrongRankCondition F] [NoZeroSMulDivisors F E] [Nontrivial E] @[simp] theorem Subalgebra.rank_bot : Module.rank F (⊥ : Subalgebra F E) = 1 := (Subalgebra.toSubmoduleEquiv (⊥ : Subalgebra F E)).symm.rank_eq.trans <| by rw [Algebra.toSubmodule_bot, one_eq_span, rank_span_set, mk_singleton _] letI := Module.nontrivial F E exact LinearIndepOn.id_singleton _ one_ne_zero @[simp] theorem Subalgebra.finrank_bot : finrank F (⊥ : Subalgebra F E) = 1 := finrank_eq_of_rank_eq (by simp) end Ring end SubalgebraRank
Linear.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.Quotient import Mathlib.CategoryTheory.Linear.LinearFunctor /-! # The quotient category is linear If `r : HomRel C` is a congruence on a preadditive category `C` which satisfies certain compatibilities, we have already defined a preadditive structure on `Quotient r` in the file `CategoryTheory.Quotient.Preadditive` such that `functor r : C ⥤ Quotient r` is an additive functor. In this file, assuming moreover that `C` is a `R`-linear category and that the relation `r` is compatible with the scalar multiplication by any `a : R`, we show that `Quotient r` is a `R`-linear category and that `functor r : C ⥤ Quotient r` is a `R`-linear functor. -/ namespace CategoryTheory namespace Quotient variable {R C : Type*} [Semiring R] [Category C] [Preadditive C] [Linear R C] (r : HomRel C) [Congruence r] namespace Linear /-- The scalar multiplications on morphisms in `Quotient R`. -/ def smul (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) (X Y : Quotient r) : SMul R (X ⟶ Y) where smul a := Quot.lift (fun g => Quot.mk _ (a • g)) (fun f₁ f₂ h₁₂ => by dsimp simp only [compClosure_eq_self] at h₁₂ apply Quot.sound rw [compClosure_eq_self] exact hr _ _ _ h₁₂) @[simp] lemma smul_eq (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) (a : R) {X Y : C} (f : X ⟶ Y) : letI := smul r hr a • (functor r).map f = (functor r).map (a • f) := rfl /-- Auxiliary definition for `Quotient.Linear.module`. -/ def module' (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) [Preadditive (Quotient r)] [(functor r).Additive] (X Y : C) : Module R ((functor r).obj X ⟶ (functor r).obj Y) := letI smul := smul r hr ((functor r).obj X) ((functor r).obj Y) { smul_zero := fun a => by rw [← (functor r).map_zero X Y, smul_eq, smul_zero] zero_smul := fun f => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f dsimp [smul] rw [zero_smul, Functor.map_zero] one_smul := fun f => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f dsimp [smul] rw [one_smul] mul_smul := fun a b f => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f dsimp [smul] rw [mul_smul] smul_add := fun a f g => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f obtain ⟨g, rfl⟩ := (functor r).map_surjective g dsimp [smul] rw [← (functor r).map_add, smul_eq, ← (functor r).map_add, smul_add] add_smul := fun a b f => by obtain ⟨f, rfl⟩ := (functor r).map_surjective f dsimp [smul] rw [add_smul, Functor.map_add] } /-- Auxiliary definition for `Quotient.linear`. -/ def module (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) [Preadditive (Quotient r)] [(functor r).Additive] (X Y : Quotient r) : Module R (X ⟶ Y) := module' r hr X.as Y.as end Linear variable (R) /-- Assuming `Quotient r` has already been endowed with a preadditive category structure such that `functor r : C ⥤ Quotient r` is additive, and that `C` has a `R`-linear category structure compatible with `r`, this is the induced `R`-linear category structure on `Quotient r`. -/ def linear (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) [Preadditive (Quotient r)] [(functor r).Additive] : Linear R (Quotient r) := by letI := Linear.module r hr exact { smul_comp := by rintro ⟨X⟩ ⟨Y⟩ ⟨Z⟩ a f g obtain ⟨f, rfl⟩ := (functor r).map_surjective f obtain ⟨g, rfl⟩ := (functor r).map_surjective g rw [Linear.smul_eq, ← Functor.map_comp, ← Functor.map_comp, Linear.smul_eq, Linear.smul_comp] comp_smul := by rintro ⟨X⟩ ⟨Y⟩ ⟨Z⟩ f a g obtain ⟨f, rfl⟩ := (functor r).map_surjective f obtain ⟨g, rfl⟩ := (functor r).map_surjective g rw [Linear.smul_eq, ← Functor.map_comp, ← Functor.map_comp, Linear.smul_eq, Linear.comp_smul] } instance linear_functor (hr : ∀ (a : R) ⦃X Y : C⦄ (f₁ f₂ : X ⟶ Y) (_ : r f₁ f₂), r (a • f₁) (a • f₂)) [Preadditive (Quotient r)] [(functor r).Additive] : letI := linear R r hr; Functor.Linear R (functor r) := by letI := linear R r hr; exact { } end Quotient end CategoryTheory
Positive.lean
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.InnerProductSpace.Adjoint import Mathlib.Analysis.InnerProductSpace.Spectrum /-! # Positive operators In this file we define when an operator in a Hilbert space is positive. We follow Bourbaki's choice of requiring self adjointness in the definition. ## Main definitions * `LinearMap.IsPositive` : a linear map is positive if it is symmetric and `∀ x, 0 ≤ re ⟪T x, x⟫`. * `ContinuousLinearMap.IsPositive` : a continuous linear map is positive if it is self adjoint and `∀ x, 0 ≤ re ⟪T x, x⟫`. ## Main statements * `ContinuousLinearMap.IsPositive.conj_adjoint` : if `T : E →L[𝕜] E` is positive, then for any `S : E →L[𝕜] F`, `S ∘L T ∘L S†` is also positive. * `ContinuousLinearMap.isPositive_iff_complex` : in a ***complex*** Hilbert space, checking that `⟪T x, x⟫` is a nonnegative real number for all `x` suffices to prove that `T` is positive. ## References * [Bourbaki, *Topological Vector Spaces*][bourbaki1987] ## Tags Positive operator -/ open InnerProductSpace RCLike LinearMap ContinuousLinearMap open scoped InnerProduct ComplexConjugate variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 F] local notation "⟪" x ", " y "⟫" => inner 𝕜 x y namespace LinearMap /-- A linear operator `T` on a Hilbert space is **positive** if it is symmetric and `∀ x, 0 ≤ re ⟪T x, x⟫`. -/ def IsPositive (T : E →ₗ[𝕜] E) : Prop := IsSymmetric T ∧ ∀ x, 0 ≤ re ⟪T x, x⟫ theorem IsPositive.isSymmetric {T : E →ₗ[𝕜] E} (hT : IsPositive T) : IsSymmetric T := hT.1 theorem IsPositive.re_inner_nonneg_left {T : E →ₗ[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ re ⟪T x, x⟫ := hT.2 x theorem IsPositive.re_inner_nonneg_right {T : E →ₗ[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ re ⟪x, T x⟫ := inner_re_symm (𝕜 := 𝕜) _ x ▸ hT.re_inner_nonneg_left x section Complex variable {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace ℂ E'] theorem isPositive_iff_complex (T : E' →ₗ[ℂ] E') : IsPositive T ↔ ∀ x, (re ⟪T x, x⟫_ℂ : ℂ) = ⟪T x, x⟫_ℂ ∧ 0 ≤ re ⟪T x, x⟫_ℂ := by simp_rw [IsPositive, forall_and, isSymmetric_iff_inner_map_self_real, conj_eq_iff_re, re_to_complex, Complex.coe_algebraMap] end Complex theorem IsPositive.isSelfAdjoint [FiniteDimensional 𝕜 E] {T : E →ₗ[𝕜] E} (hT : IsPositive T) : IsSelfAdjoint T := (isSymmetric_iff_isSelfAdjoint _).mp hT.isSymmetric theorem IsPositive.adjoint_eq [FiniteDimensional 𝕜 E] {T : E →ₗ[𝕜] E} (hT : IsPositive T) : T.adjoint = T := hT.isSelfAdjoint open ComplexOrder in theorem isPositive_iff (T : E →ₗ[𝕜] E) : IsPositive T ↔ IsSymmetric T ∧ ∀ x, 0 ≤ ⟪T x, x⟫ := by simp_rw [IsPositive, and_congr_right_iff, ← RCLike.ofReal_nonneg (K := 𝕜)] intro hT simp [hT] open ComplexOrder in theorem IsPositive.inner_nonneg_left {T : E →ₗ[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ ⟪T x, x⟫ := (T.isPositive_iff.mp hT).right x open ComplexOrder in theorem IsPositive.inner_nonneg_right {T : E →ₗ[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ ⟪x, T x⟫ := hT.isSymmetric _ _ ▸ hT.inner_nonneg_left x @[simp] theorem isPositive_zero : IsPositive (0 : E →ₗ[𝕜] E) := ⟨.zero, by simp⟩ @[simp] theorem isPositive_one : IsPositive (1 : E →ₗ[𝕜] E) := ⟨.id, fun _ => inner_self_nonneg⟩ @[simp] theorem isPositive_natCast {n : ℕ} : IsPositive (n : E →ₗ[𝕜] E) := by refine ⟨IsSymmetric.natCast n, fun x => ?_⟩ simp only [Module.End.natCast_apply, ← Nat.cast_smul_eq_nsmul 𝕜, inner_smul_left, map_natCast, mul_re, natCast_re, inner_self_im, mul_zero, sub_zero] exact mul_nonneg n.cast_nonneg' inner_self_nonneg @[simp] theorem isPositive_ofNat {n : ℕ} [n.AtLeastTwo] : IsPositive (ofNat(n) : E →ₗ[𝕜] E) := isPositive_natCast @[aesop safe apply] theorem IsPositive.add {T S : E →ₗ[𝕜] E} (hT : T.IsPositive) (hS : S.IsPositive) : (T + S).IsPositive := by refine ⟨hT.isSymmetric.add hS.isSymmetric, fun x => ?_⟩ rw [add_apply, inner_add_left, map_add] exact add_nonneg (hT.re_inner_nonneg_left x) (hS.re_inner_nonneg_left x) open ComplexOrder in @[aesop safe apply] theorem IsPositive.smul_of_nonneg {T : E →ₗ[𝕜] E} (hT : T.IsPositive) {c : 𝕜} (hc : 0 ≤ c) : (c • T).IsPositive := by have hc' : starRingEnd 𝕜 c = c := by simp [conj_eq_iff_im, ← (le_iff_re_im.mp hc).right] refine ⟨hT.left.smul hc', fun x => ?_⟩ rw [smul_apply, inner_smul_left, hc', mul_re, conj_eq_iff_im.mp hc', zero_mul, sub_zero] exact mul_nonneg ((re_nonneg_of_nonneg hc').mpr hc) (re_inner_nonneg_left hT x) theorem IsPositive.nonneg_eigenvalues [FiniteDimensional 𝕜 E] {T : E →ₗ[𝕜] E} {n : ℕ} (hT : T.IsPositive) (hn : Module.finrank 𝕜 E = n) (i : Fin n) : 0 ≤ hT.isSymmetric.eigenvalues hn i := by simpa only [hT.isSymmetric.apply_eigenvectorBasis, inner_smul_real_left, RCLike.smul_re, inner_self_eq_norm_sq, OrthonormalBasis.norm_eq_one, one_pow, mul_one] using hT.right (hT.isSymmetric.eigenvectorBasis hn i) section PartialOrder /-- The (Loewner) partial order on linear maps on a Hilbert space determined by `f ≤ g` if and only if `g - f` is a positive linear map (in the sense of `LinearMap.IsPositive`). -/ instance instLoewnerPartialOrder : PartialOrder (E →ₗ[𝕜] E) where le f g := (g - f).IsPositive le_refl _ := by simp le_trans _ _ _ h₁ h₂ := by simpa using h₁.add h₂ le_antisymm f₁ f₂ h₁ h₂ := by rw [← sub_eq_zero, ← h₂.isSymmetric.inner_map_self_eq_zero] intro x have hba2 := h₁.2 x rw [← neg_le_neg_iff, ← map_neg, ← inner_neg_left, ← neg_apply, neg_sub, neg_zero] at hba2 rw [← h₂.isSymmetric.coe_re_inner_apply_self, RCLike.ofReal_eq_zero] exact le_antisymm hba2 (h₂.2 _) lemma le_def (f g : E →ₗ[𝕜] E) : f ≤ g ↔ (g - f).IsPositive := Iff.rfl lemma nonneg_iff_isPositive (f : E →ₗ[𝕜] E) : 0 ≤ f ↔ f.IsPositive := by simpa using le_def 0 f end PartialOrder /-- An idempotent linear map is positive iff it is symmetric. -/ theorem IsIdempotentElem.isPositive_iff_isSymmetric {T : E →ₗ[𝕜] E} (hT : IsIdempotentElem T) : T.IsPositive ↔ T.IsSymmetric := by refine ⟨fun h => h.isSymmetric, fun h => ⟨h, fun x => ?_⟩⟩ rw [← hT.eq, Module.End.mul_apply, h] exact inner_self_nonneg end LinearMap namespace ContinuousLinearMap variable [CompleteSpace E] [CompleteSpace F] /-- A continuous linear endomorphism `T` of a Hilbert space is **positive** if it is self adjoint and `∀ x, 0 ≤ re ⟪T x, x⟫`. -/ def IsPositive (T : E →L[𝕜] E) : Prop := IsSelfAdjoint T ∧ ∀ x, 0 ≤ T.reApplyInnerSelf x theorem IsPositive.isSelfAdjoint {T : E →L[𝕜] E} (hT : IsPositive T) : IsSelfAdjoint T := hT.1 theorem IsPositive.inner_left_eq_inner_right {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) : ⟪T x, x⟫ = ⟪x, T x⟫ := by rw [← adjoint_inner_left, hT.isSelfAdjoint.adjoint_eq] theorem IsPositive.re_inner_nonneg_left {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ re ⟪T x, x⟫ := hT.2 x theorem IsPositive.re_inner_nonneg_right {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ re ⟪x, T x⟫ := by rw [inner_re_symm]; exact hT.re_inner_nonneg_left x omit [CompleteSpace E] in lemma _root_.LinearMap.isPositive_toContinuousLinearMap_iff [FiniteDimensional 𝕜 E] (T : E →ₗ[𝕜] E) : have : CompleteSpace E := FiniteDimensional.complete 𝕜 _ T.toContinuousLinearMap.IsPositive ↔ T.IsPositive := by simp_rw [IsPositive, LinearMap.IsPositive, reApplyInnerSelf, isSelfAdjoint_iff_isSymmetric] rfl lemma isPositive_toLinearMap_iff (T : E →L[𝕜] E) : (T : E →ₗ[𝕜] E).IsPositive ↔ T.IsPositive := by rw [LinearMap.IsPositive, coe_coe, IsPositive, ← isSelfAdjoint_iff_isSymmetric] rfl alias ⟨_, IsPositive.toLinearMap⟩ := isPositive_toLinearMap_iff open ComplexOrder in theorem isPositive_iff (T : E →L[𝕜] E) : IsPositive T ↔ IsSelfAdjoint T ∧ ∀ x, 0 ≤ ⟪T x, x⟫ := by simp [← isPositive_toLinearMap_iff, isSelfAdjoint_iff_isSymmetric, LinearMap.isPositive_iff] open ComplexOrder in theorem IsPositive.inner_nonneg_left {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ ⟪T x, x⟫ := (T.isPositive_iff.mp hT).right x open ComplexOrder in theorem IsPositive.inner_nonneg_right {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) : 0 ≤ ⟪x, T x⟫ := by rw [← hT.inner_left_eq_inner_right] exact inner_nonneg_left hT x @[simp] theorem isPositive_zero : IsPositive (0 : E →L[𝕜] E) := (isPositive_toLinearMap_iff _).mp LinearMap.isPositive_zero @[simp] theorem isPositive_one : IsPositive (1 : E →L[𝕜] E) := ⟨.one _, fun _ => inner_self_nonneg⟩ @[simp] theorem isPositive_natCast {n : ℕ} : IsPositive (n : E →L[𝕜] E) := (isPositive_toLinearMap_iff _).mp LinearMap.isPositive_natCast @[simp] theorem isPositive_ofNat {n : ℕ} [n.AtLeastTwo] : IsPositive (ofNat(n) : E →L[𝕜] E) := isPositive_natCast @[aesop safe apply] theorem IsPositive.add {T S : E →L[𝕜] E} (hT : T.IsPositive) (hS : S.IsPositive) : (T + S).IsPositive := (isPositive_toLinearMap_iff _).mp (hT.toLinearMap.add hS.toLinearMap) open ComplexOrder in @[aesop safe apply] theorem IsPositive.smul_of_nonneg {T : E →L[𝕜] E} (hT : T.IsPositive) {c : 𝕜} (hc : 0 ≤ c) : (c • T).IsPositive := (isPositive_toLinearMap_iff _).mp (hT.toLinearMap.smul_of_nonneg hc) @[aesop safe apply] theorem IsPositive.conj_adjoint {T : E →L[𝕜] E} (hT : T.IsPositive) (S : E →L[𝕜] F) : (S ∘L T ∘L S†).IsPositive := by refine ⟨hT.isSelfAdjoint.conj_adjoint S, fun x => ?_⟩ rw [reApplyInnerSelf, comp_apply, ← adjoint_inner_right] exact hT.re_inner_nonneg_left _ @[aesop safe apply] theorem IsPositive.adjoint_conj {T : E →L[𝕜] E} (hT : T.IsPositive) (S : F →L[𝕜] E) : (S† ∘L T ∘L S).IsPositive := by convert hT.conj_adjoint (S†) rw [adjoint_adjoint] section LinearMap omit [CompleteSpace E] [CompleteSpace F] variable [FiniteDimensional 𝕜 E] [FiniteDimensional 𝕜 F] @[aesop safe apply] theorem _root_.LinearMap.IsPositive.conj_adjoint {T : E →ₗ[𝕜] E} (hT : T.IsPositive) (S : E →ₗ[𝕜] F) : (S ∘ₗ T ∘ₗ S.adjoint).IsPositive := by have := FiniteDimensional.complete 𝕜 E have := FiniteDimensional.complete 𝕜 F simpa [← isPositive_toContinuousLinearMap_iff] using ((T.isPositive_toContinuousLinearMap_iff.mpr hT).conj_adjoint S.toContinuousLinearMap) @[aesop safe apply] theorem _root_.LinearMap.IsPositive.adjoint_conj {T : E →ₗ[𝕜] E} (hT : T.IsPositive) (S : F →ₗ[𝕜] E) : (S.adjoint ∘ₗ T ∘ₗ S).IsPositive := by convert hT.conj_adjoint S.adjoint rw [LinearMap.adjoint_adjoint] end LinearMap theorem IsPositive.conj_starProjection (U : Submodule 𝕜 E) {T : E →L[𝕜] E} (hT : T.IsPositive) [U.HasOrthogonalProjection] : (U.starProjection ∘L T ∘L U.starProjection).IsPositive := by have := hT.conj_adjoint (U.starProjection) rwa [(isSelfAdjoint_starProjection U).adjoint_eq] at this theorem IsPositive.orthogonalProjection_comp {T : E →L[𝕜] E} (hT : T.IsPositive) (U : Submodule 𝕜 E) [CompleteSpace U] : (U.orthogonalProjection ∘L T ∘L U.subtypeL).IsPositive := by have := hT.conj_adjoint (U.orthogonalProjection : E →L[𝕜] U) rwa [U.adjoint_orthogonalProjection] at this open scoped NNReal lemma antilipschitz_of_forall_le_inner_map {H : Type*} [NormedAddCommGroup H] [InnerProductSpace 𝕜 H] (f : H →L[𝕜] H) {c : ℝ≥0} (hc : 0 < c) (h : ∀ x, ‖x‖ ^ 2 * c ≤ ‖⟪f x, x⟫_𝕜‖) : AntilipschitzWith c⁻¹ f := by refine f.antilipschitz_of_bound (K := c⁻¹) fun x ↦ ?_ rw [NNReal.coe_inv, inv_mul_eq_div, le_div_iff₀ (by exact_mod_cast hc)] simp_rw [sq, mul_assoc] at h by_cases hx0 : x = 0 · simp [hx0] · apply (map_le_map_iff <| OrderIso.mulLeft₀ ‖x‖ (norm_pos_iff.mpr hx0)).mp exact (h x).trans <| (norm_inner_le_norm _ _).trans <| (mul_comm _ _).le lemma isUnit_of_forall_le_norm_inner_map (f : E →L[𝕜] E) {c : ℝ≥0} (hc : 0 < c) (h : ∀ x, ‖x‖ ^ 2 * c ≤ ‖⟪f x, x⟫_𝕜‖) : IsUnit f := by rw [isUnit_iff_bijective, bijective_iff_dense_range_and_antilipschitz] have h_anti : AntilipschitzWith c⁻¹ f := antilipschitz_of_forall_le_inner_map f hc h refine ⟨?_, ⟨_, h_anti⟩⟩ have _inst := h_anti.completeSpace_range_clm rw [Submodule.topologicalClosure_eq_top_iff, Submodule.eq_bot_iff] intro x hx have : ‖x‖ ^ 2 * c = 0 := le_antisymm (by simpa only [hx (f x) ⟨x, rfl⟩, norm_zero] using h x) (by positivity) aesop section Complex variable {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace ℂ E'] [CompleteSpace E'] theorem isPositive_iff_complex (T : E' →L[ℂ] E') : IsPositive T ↔ ∀ x, (re ⟪T x, x⟫_ℂ : ℂ) = ⟪T x, x⟫_ℂ ∧ 0 ≤ re ⟪T x, x⟫_ℂ := by simp [← isPositive_toLinearMap_iff, LinearMap.isPositive_iff_complex] end Complex section PartialOrder /-- The (Loewner) partial order on continuous linear maps on a Hilbert space determined by `f ≤ g` if and only if `g - f` is a positive linear map (in the sense of `ContinuousLinearMap.IsPositive`). With this partial order, the continuous linear maps form a `StarOrderedRing`. -/ instance instLoewnerPartialOrder : PartialOrder (E →L[𝕜] E) where le f g := (g - f).IsPositive le_refl _ := by simp le_trans _ _ _ h₁ h₂ := by simpa using h₁.add h₂ le_antisymm _ _ h₁ h₂ := coe_inj.mp (le_antisymm h₁.toLinearMap h₂.toLinearMap) lemma le_def (f g : E →L[𝕜] E) : f ≤ g ↔ (g - f).IsPositive := Iff.rfl lemma coe_le_coe_iff (f g : E →L[𝕜] E) : (f : E →ₗ[𝕜] E) ≤ g ↔ f ≤ g := isPositive_toLinearMap_iff (g - f) lemma nonneg_iff_isPositive (f : E →L[𝕜] E) : 0 ≤ f ↔ f.IsPositive := by simpa using le_def 0 f end PartialOrder /-- An idempotent operator is positive if and only if it is self-adjoint. -/ @[grind →] theorem IsIdempotentElem.isPositive_iff_isSelfAdjoint {p : E →L[𝕜] E} (hp : IsIdempotentElem p) : p.IsPositive ↔ IsSelfAdjoint p := by rw [← isPositive_toLinearMap_iff, IsIdempotentElem.isPositive_iff_isSymmetric hp.toLinearMap] exact isSelfAdjoint_iff_isSymmetric.symm /-- A star projection operator is positive. The proof of this will soon be simplified to `IsStarProjection.nonneg` when we have `StarOrderedRing (E →L[𝕜] E)`. -/ @[aesop 10% apply, grind →] theorem IsPositive.of_isStarProjection {p : E →L[𝕜] E} (hp : IsStarProjection p) : p.IsPositive := hp.isIdempotentElem.isPositive_iff_isSelfAdjoint.mpr hp.isSelfAdjoint /-- For an idempotent operator `p`, TFAE: * `p` is normal * `p` is self-adjoint * `p` is positive * `(range p)ᗮ = ker p` -/ theorem IsIdempotentElem.TFAE {p : E →L[𝕜] E} (hp : IsIdempotentElem p) : [IsStarNormal p, IsSelfAdjoint p, p.IsPositive, (LinearMap.range p)ᗮ = LinearMap.ker p].TFAE := by tfae_have 1 ↔ 2 := hp.isSelfAdjoint_iff_isStarNormal.symm tfae_have 2 ↔ 3 := hp.isPositive_iff_isSelfAdjoint.symm tfae_have 2 ↔ 4 := p.isSelfAdjoint_iff_isSymmetric.eq ▸ (ContinuousLinearMap.IsIdempotentElem.isSymmetric_iff_orthogonal_range hp) tfae_finish end ContinuousLinearMap namespace LinearMap /-- A star projection operator is positive. -/ @[aesop 10% apply, grind →] theorem IsPositive.of_isStarProjection [FiniteDimensional 𝕜 E] {T : E →ₗ[𝕜] E} (hT : IsStarProjection T) : T.IsPositive := have := FiniteDimensional.complete 𝕜 E T.isPositive_toContinuousLinearMap_iff.mp (ContinuousLinearMap.IsPositive.of_isStarProjection (isStarProjection_toContinuousLinearMap_iff.mpr hT)) end LinearMap
Height.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.Data.ENat.Lattice import Mathlib.Order.OrderIsoNat import Mathlib.Tactic.TFAE /-! # Maximal length of chains This file contains lemmas to work with the maximal length of strictly descending finite sequences (chains) in a partial order. ## Main definition - `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`. - `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order. This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`. ## Main results - `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there exists `s.subchain` of length `n`. - `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`. - `Set.chainHeight_image`: If `f` is an order embedding, then `(f '' s).chainHeight = s.chainHeight`. - `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then `(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`. - `Set.wellFoundedGT_of_chainHeight_ne_top`: If `s` has finite height, then `>` is well-founded on `s`. - `Set.wellFoundedLT_of_chainHeight_ne_top`: If `s` has finite height, then `<` is well-founded on `s`. -/ assert_not_exists Field open List hiding le_antisymm open OrderDual universe u v variable {α β : Type*} namespace Set section LT variable [LT α] [LT β] (s t : Set α) /-- The set of strictly ascending lists of `α` contained in a `Set α`. -/ def subchain : Set (List α) := { l | l.Chain' (· < ·) ∧ ∀ i ∈ l, i ∈ s } @[simp] theorem nil_mem_subchain : [] ∈ s.subchain := ⟨trivial, fun _ ↦ nofun⟩ variable {s} {l : List α} {a : α} theorem cons_mem_subchain_iff : (a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by simp only [subchain, mem_setOf_eq, forall_mem_cons, chain'_cons', and_left_comm, and_comm, and_assoc] @[simp] theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff] instance : Nonempty s.subchain := ⟨⟨[], s.nil_mem_subchain⟩⟩ variable (s) /-- The maximal length of a strictly ascending sequence in a partial order. -/ noncomputable def chainHeight : ℕ∞ := ⨆ l ∈ s.subchain, length l theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length := iSup_subtype' theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) : ∃ l ∈ s.subchain, length l = n := by rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;> rw [chainHeight_eq_iSup_subtype] at ha · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ := not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take).trans <| min_eq_left <| le_of_not_ge h₃⟩ · rw [ENat.iSup_coe_lt_top] at ha obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha refine ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take).trans <| min_eq_left <| ?_⟩ rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype] theorem le_chainHeight_TFAE (n : ℕ) : TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by tfae_have 1 → 2 := s.exists_chain_of_le_chainHeight tfae_have 2 → 3 := fun ⟨l, hls, he⟩ ↦ ⟨l, hls, he.ge⟩ tfae_have 3 → 1 := fun ⟨l, hs, hn⟩ ↦ le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn) tfae_finish variable {s t} theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n := (le_chainHeight_TFAE s n).out 0 1 theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight := le_chainHeight_iff.mpr ⟨l, hl, rfl⟩ theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩ contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <| (length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩ @[simp] theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by rw [← Nat.cast_one, Set.le_chainHeight_iff] simp only [length_eq_one_iff, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and, singleton_mem_subchain_iff, Set.Nonempty] @[simp] theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by rw [← not_iff_not, ← Ne, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff, nonempty_iff_ne_empty] @[simp] theorem chainHeight_empty : (∅ : Set α).chainHeight = 0 := chainHeight_eq_zero_iff.2 rfl @[simp] theorem chainHeight_of_isEmpty [IsEmpty α] : s.chainHeight = 0 := chainHeight_eq_zero_iff.mpr (Subsingleton.elim _ _) theorem le_chainHeight_add_nat_iff {n m : ℕ} : ↑n ≤ s.chainHeight + m ↔ ∃ l ∈ s.subchain, n ≤ length l + m := by simp_rw [← tsub_le_iff_right, ← ENat.coe_sub, (le_chainHeight_TFAE s (n - m)).out 0 2] theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) : s.chainHeight + n ≤ t.chainHeight + m ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by refine ⟨fun e l h ↦ le_chainHeight_add_nat_iff.1 ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e), fun H ↦ ?_⟩ by_cases h : s.chainHeight = ⊤ · suffices t.chainHeight = ⊤ by rw [this, top_add] exact le_top rw [chainHeight_eq_top_iff] at h ⊢ intro k have := (le_chainHeight_TFAE t k).out 1 2 rw [this] obtain ⟨l, hs, hl⟩ := h (k + m) obtain ⟨l', ht, hl'⟩ := H l hs exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩ · obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h obtain ⟨l, hs, hl⟩ := le_chainHeight_iff.1 hk.le rw [← hk, ← hl] exact le_chainHeight_add_nat_iff.2 (H l hs) theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) : TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l', ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by tfae_have 1 ↔ 3 := by convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero tfae_have 2 ↔ 3 := by refine forall₂_congr fun l _ ↦ ?_ simp_rw [← (le_chainHeight_TFAE t l.length).out 1 2, eq_comm] tfae_finish theorem chainHeight_le_chainHeight_iff {t : Set β} : s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l' := (chainHeight_le_chainHeight_TFAE s t).out 0 1 theorem chainHeight_le_chainHeight_iff_le {t : Set β} : s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l' := (chainHeight_le_chainHeight_TFAE s t).out 0 2 theorem chainHeight_mono (h : s ⊆ t) : s.chainHeight ≤ t.chainHeight := chainHeight_le_chainHeight_iff.2 fun l hl ↦ ⟨l, ⟨hl.1, fun i hi ↦ h <| hl.2 i hi⟩, rfl⟩ theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) : (f '' s).chainHeight = s.chainHeight := by apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff] · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by intro l hl obtain ⟨l', h₁, rfl⟩ := this l hl exact ⟨l', h₁, length_map _⟩ intro l induction l with | nil => exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil h).elim⟩, rfl⟩ | cons x xs hx => intro h rw [cons_mem_subchain_iff] at h obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h obtain ⟨l', h₃, rfl⟩ := hx h₁ refine ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, ?_⟩, rfl⟩ cases l' · simp · simpa [← hf] using h₂ · intro l hl refine ⟨l.map f, ⟨?_, ?_⟩, ?_⟩ · simp_rw [chain'_map, ← hf] exact hl.1 · intro _ e obtain ⟨a, ha, rfl⟩ := mem_map.mp e exact Set.mem_image_of_mem _ (hl.2 _ ha) · rw [length_map] variable (s) @[simp] theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by apply le_antisymm <;> · rw [chainHeight_le_chainHeight_iff] rintro l ⟨h₁, h₂⟩ exact ⟨l.reverse, ⟨chain'_reverse.mpr h₁, fun i h ↦ h₂ i (mem_reverse.mp h)⟩, length_reverse.symm⟩ end LT section Preorder variable (s t : Set α) [Preorder α] theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by apply le_antisymm · refine iSup₂_le ?_ rintro (_ | ⟨x, xs⟩) h · exact zero_le _ · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1) apply length_le_chainHeight_of_mem_subchain refine ⟨h.1, fun i hi ↦ ⟨h.2 i hi, ?_⟩⟩ cases hi · exact left_mem_Ici rename_i hi obtain - | h' := chain'_iff_pairwise.mp h.1 exact (h' _ hi).le · exact iSup₂_le fun i _ ↦ chainHeight_mono Set.inter_subset_left theorem chainHeight_eq_iSup_Iic : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Iic i).chainHeight := by simp_rw [← chainHeight_dual (_ ∩ _)] rw [← chainHeight_dual, chainHeight_eq_iSup_Ici] rfl variable {s t} theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) : (insert a s).chainHeight = s.chainHeight + 1 := by rw [← add_zero (insert a s).chainHeight] change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ) apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add] · rintro (_ | ⟨y, ys⟩) h · exact ⟨[], nil_mem_subchain _, zero_le _⟩ · have h' := cons_mem_subchain_iff.mp h refine ⟨ys, ⟨h'.2.1.1, fun i hi ↦ ?_⟩, by simp⟩ apply (h'.2.1.2 i hi).resolve_left rintro rfl obtain - | hy := chain'_iff_pairwise.mp h.1 rcases h'.1 with h' | h' exacts [(hy _ hi).ne h', not_le_of_gt (hy _ hi) (hx _ h').le] · intro l hl refine ⟨a::l, ⟨?_, ?_⟩, by simp⟩ · rw [chain'_cons'] exact ⟨fun y hy ↦ hx _ (hl.2 _ (mem_of_mem_head? hy)), hl.1⟩ · rintro x (_ | _) exacts [Or.inl (Set.mem_singleton a), Or.inr (hl.2 x ‹x ∈ l›)] theorem chainHeight_insert_of_forall_lt (a : α) (ha : ∀ b ∈ s, b < a) : (insert a s).chainHeight = s.chainHeight + 1 := by rw [← chainHeight_dual, ← chainHeight_dual s] exact chainHeight_insert_of_forall_gt _ ha theorem chainHeight_union_le : (s ∪ t).chainHeight ≤ s.chainHeight + t.chainHeight := by classical refine iSup₂_le fun l hl ↦ ?_ let l₁ := l.filter (· ∈ s) let l₂ := l.filter (· ∈ t) have hl₁ : ↑l₁.length ≤ s.chainHeight := by apply Set.length_le_chainHeight_of_mem_subchain exact ⟨hl.1.sublist filter_sublist, fun i h ↦ by simpa using (of_mem_filter h :)⟩ have hl₂ : ↑l₂.length ≤ t.chainHeight := by apply Set.length_le_chainHeight_of_mem_subchain exact ⟨hl.1.sublist filter_sublist, fun i h ↦ by simpa using (of_mem_filter h :)⟩ refine le_trans ?_ (add_le_add hl₁ hl₂) simp_rw [l₁, l₂, ← Nat.cast_add, ← Multiset.coe_card, ← Multiset.card_add, ← Multiset.filter_coe] rw [Multiset.filter_add_filter, Multiset.filter_eq_self.mpr, Multiset.card_add, Nat.cast_add] exacts [le_add_right rfl.le, hl.2] theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) : (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by cases h : t.chainHeight · rw [add_top, eq_top_iff, ← h] exact Set.chainHeight_mono subset_union_right apply le_antisymm · rw [← h] exact chainHeight_union_le rw [← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero, ENat.some_eq_coe, chainHeight_add_le_chainHeight_add] intro l hl obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le refine ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ ?_, fun i hi ↦ ?_⟩, by simp⟩ · exact H x (hl.2 _ <| mem_of_mem_getLast? hx) y (hl'.2 _ <| mem_of_mem_head? hy) · rw [mem_append] at hi rcases hi with hi | hi exacts [Or.inl (hl.2 _ hi), Or.inr (hl'.2 _ hi)] theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) : WellFoundedGT s := by haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs refine ⟨RelEmbedding.wellFounded_iff_isEmpty.2 ⟨fun f ↦ ?_⟩⟩ refine n.lt_succ_self.not_ge (WithTop.coe_le_coe.1 <| hn.symm ▸ ?_) refine le_iSup₂_of_le ((ofFn (n := n.succ) fun i ↦ f i).map Subtype.val) ⟨chain'_map_of_chain' ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id) (chain'_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2), fun i h ↦ ?_⟩ ?_ · obtain ⟨a, -, rfl⟩ := mem_map.1 h exact a.prop · rw [length_map, length_ofFn] exact le_rfl theorem wellFoundedLT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) : WellFoundedLT s := wellFoundedGT_of_chainHeight_ne_top (ofDual ⁻¹' s) <| by rwa [chainHeight_dual] end Preorder end Set
EpiMono.lean
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.Algebra.Category.ModuleCat.Basic import Mathlib.CategoryTheory.ConcreteCategory.EpiMono /-! # Monomorphisms in `Module R` This file shows that an `R`-linear map is a monomorphism in the category of `R`-modules if and only if it is injective, and similarly an epimorphism if and only if it is surjective. -/ universe v u open CategoryTheory namespace ModuleCat variable {R : Type u} [Ring R] {X Y : ModuleCat.{v} R} (f : X ⟶ Y) variable {M : Type v} [AddCommGroup M] [Module R M] theorem ker_eq_bot_of_mono [Mono f] : LinearMap.ker f.hom = ⊥ := LinearMap.ker_eq_bot_of_cancel fun u v h => ModuleCat.hom_ext_iff.mp <| (@cancel_mono _ _ _ _ _ f _ (↟u) (↟v)).1 <| ModuleCat.hom_ext_iff.mpr h theorem range_eq_top_of_epi [Epi f] : LinearMap.range f.hom = ⊤ := LinearMap.range_eq_top_of_cancel fun u v h => ModuleCat.hom_ext_iff.mp <| (@cancel_epi _ _ _ _ _ f _ (↟u) (↟v)).1 <| ModuleCat.hom_ext_iff.mpr h theorem mono_iff_ker_eq_bot : Mono f ↔ LinearMap.ker f.hom = ⊥ := ⟨fun _ => ker_eq_bot_of_mono _, fun hf => ConcreteCategory.mono_of_injective _ <| by convert LinearMap.ker_eq_bot.1 hf⟩ theorem mono_iff_injective : Mono f ↔ Function.Injective f := by rw [mono_iff_ker_eq_bot, LinearMap.ker_eq_bot] theorem epi_iff_range_eq_top : Epi f ↔ LinearMap.range f.hom = ⊤ := ⟨fun _ => range_eq_top_of_epi _, fun hf => ConcreteCategory.epi_of_surjective _ <| by convert LinearMap.range_eq_top.1 hf⟩ theorem epi_iff_surjective : Epi f ↔ Function.Surjective f := by rw [epi_iff_range_eq_top, LinearMap.range_eq_top] /-- If the zero morphism is an epi then the codomain is trivial. -/ def uniqueOfEpiZero (X) [h : Epi (0 : X ⟶ of R M)] : Unique M := uniqueOfSurjectiveZero X ((ModuleCat.epi_iff_surjective _).mp h) instance mono_as_hom'_subtype (U : Submodule R X) : Mono (ModuleCat.ofHom U.subtype) := (mono_iff_ker_eq_bot _).mpr (Submodule.ker_subtype U) instance epi_as_hom''_mkQ (U : Submodule R X) : Epi (ModuleCat.ofHom U.mkQ) := (epi_iff_range_eq_top _).mpr <| Submodule.range_mkQ _ instance forget_preservesEpimorphisms : (forget (ModuleCat.{v} R)).PreservesEpimorphisms where preserves f hf := by rw [CategoryTheory.epi_iff_surjective, ConcreteCategory.forget_map_eq_coe, ← epi_iff_surjective] exact hf instance forget_preservesMonomorphisms : (forget (ModuleCat.{v} R)).PreservesMonomorphisms where preserves f hf := by rw [CategoryTheory.mono_iff_injective, ConcreteCategory.forget_map_eq_coe, ← mono_iff_injective] exact hf end ModuleCat
RegularMeasure.lean
import Mathlib.MeasureTheory.Group.Measure import Mathlib.Topology.Metrizable.Urysohn /-! Check that typeclass inference knows that a Haar measure on a locally compact second countable topological group is automatically regular and inner regular. -/ open MeasureTheory Measure variable {G : Type*} [MeasurableSpace G] [Group G] [TopologicalSpace G] [IsTopologicalGroup G] [LocallyCompactSpace G] [SecondCountableTopology G] [BorelSpace G] (μ : Measure G) [IsHaarMeasure μ] example : Regular μ := inferInstance example : InnerRegular μ := inferInstance /- Check that typeclass inference works to guarantee regularity and inner regularity in interesting situations. -/ variable {α : Type*} [TopologicalSpace α] [MeasurableSpace α] [LocallyCompactSpace α] [RegularSpace α] [BorelSpace α] [SecondCountableTopology α] example (μ : Measure α) [IsFiniteMeasureOnCompacts μ] : Regular μ := inferInstance example (μ : Measure α) [IsFiniteMeasureOnCompacts μ] : InnerRegular μ := inferInstance
MulOpposite.lean
/- Copyright (c) 2022 Alex Kontorovich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Eric Wieser -/ import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.Algebra.Group.Submonoid.MulOpposite /-! # Mul-opposite subgroups ## Tags subgroup, subgroups -/ variable {ι : Sort*} {G : Type*} [Group G] namespace Subgroup /-- Pull a subgroup back to an opposite subgroup along `MulOpposite.unop` -/ @[to_additive (attr := simps) /-- Pull an additive subgroup back to an opposite additive subgroup along `AddOpposite.unop` -/] protected def op (H : Subgroup G) : Subgroup Gᵐᵒᵖ where carrier := MulOpposite.unop ⁻¹' (H : Set G) one_mem' := H.one_mem mul_mem' ha hb := H.mul_mem hb ha inv_mem' := H.inv_mem @[to_additive (attr := simp)] theorem mem_op {x : Gᵐᵒᵖ} {S : Subgroup G} : x ∈ S.op ↔ x.unop ∈ S := Iff.rfl @[to_additive (attr := simp)] lemma op_toSubmonoid (H : Subgroup G) : H.op.toSubmonoid = H.toSubmonoid.op := rfl /-- Pull an opposite subgroup back to a subgroup along `MulOpposite.op` -/ @[to_additive (attr := simps) /-- Pull an opposite additive subgroup back to an additive subgroup along `AddOpposite.op` -/] protected def unop (H : Subgroup Gᵐᵒᵖ) : Subgroup G where carrier := MulOpposite.op ⁻¹' (H : Set Gᵐᵒᵖ) one_mem' := H.one_mem mul_mem' := fun ha hb => H.mul_mem hb ha inv_mem' := H.inv_mem @[to_additive (attr := simp)] theorem mem_unop {x : G} {S : Subgroup Gᵐᵒᵖ} : x ∈ S.unop ↔ MulOpposite.op x ∈ S := Iff.rfl @[to_additive (attr := simp)] lemma unop_toSubmonoid (H : Subgroup Gᵐᵒᵖ) : H.unop.toSubmonoid = H.toSubmonoid.unop := rfl @[to_additive (attr := simp)] theorem unop_op (S : Subgroup G) : S.op.unop = S := rfl @[to_additive (attr := simp)] theorem op_unop (S : Subgroup Gᵐᵒᵖ) : S.unop.op = S := rfl /-! ### Lattice results -/ @[to_additive] theorem op_le_iff {S₁ : Subgroup G} {S₂ : Subgroup Gᵐᵒᵖ} : S₁.op ≤ S₂ ↔ S₁ ≤ S₂.unop := MulOpposite.op_surjective.forall @[to_additive] theorem le_op_iff {S₁ : Subgroup Gᵐᵒᵖ} {S₂ : Subgroup G} : S₁ ≤ S₂.op ↔ S₁.unop ≤ S₂ := MulOpposite.op_surjective.forall @[to_additive (attr := simp)] theorem op_le_op_iff {S₁ S₂ : Subgroup G} : S₁.op ≤ S₂.op ↔ S₁ ≤ S₂ := MulOpposite.op_surjective.forall @[to_additive (attr := simp)] theorem unop_le_unop_iff {S₁ S₂ : Subgroup Gᵐᵒᵖ} : S₁.unop ≤ S₂.unop ↔ S₁ ≤ S₂ := MulOpposite.unop_surjective.forall /-- A subgroup `H` of `G` determines a subgroup `H.op` of the opposite group `Gᵐᵒᵖ`. -/ @[to_additive (attr := simps) /-- An additive subgroup `H` of `G` determines an additive subgroup `H.op` of the opposite additive group `Gᵃᵒᵖ`. -/] def opEquiv : Subgroup G ≃o Subgroup Gᵐᵒᵖ where toFun := Subgroup.op invFun := Subgroup.unop left_inv := unop_op right_inv := op_unop map_rel_iff' := op_le_op_iff @[to_additive] theorem op_injective : (@Subgroup.op G _).Injective := opEquiv.injective @[to_additive] theorem unop_injective : (@Subgroup.unop G _).Injective := opEquiv.symm.injective @[to_additive (attr := simp)] theorem op_inj {S T : Subgroup G} : S.op = T.op ↔ S = T := opEquiv.eq_iff_eq @[to_additive (attr := simp)] theorem unop_inj {S T : Subgroup Gᵐᵒᵖ} : S.unop = T.unop ↔ S = T := opEquiv.symm.eq_iff_eq /-- Bijection between a subgroup `H` and its opposite. -/ @[to_additive (attr := simps!) /-- Bijection between an additive subgroup `H` and its opposite. -/] def equivOp (H : Subgroup G) : H ≃ H.op := MulOpposite.opEquiv.subtypeEquiv fun _ => Iff.rfl @[to_additive] theorem op_normalizer (H : Subgroup G) : H.normalizer.op = H.op.normalizer := by ext x simp [mem_normalizer_iff', iff_comm] @[to_additive] theorem unop_normalizer (H : Subgroup Gᵐᵒᵖ) : H.normalizer.unop = H.unop.normalizer := by rw [← op_inj, op_unop, op_normalizer, op_unop] end Subgroup
ListOfFn.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Data.List.OfFn import Mathlib.Algebra.BigOperators.Group.List.Defs import Mathlib.Algebra.Group.Pointwise.Set.Basic /-! # Pointwise operations with lists of sets This file proves some lemmas about pointwise algebraic operations with lists of sets. -/ namespace Set variable {α : Type*} [Monoid α] {s : Set α} {n : ℕ} open Pointwise @[to_additive] theorem mem_prod_list_ofFn {a : α} {s : Fin n → Set α} : a ∈ (List.ofFn s).prod ↔ ∃ f : ∀ i : Fin n, s i, (List.ofFn fun i ↦ (f i : α)).prod = a := by induction' n with n ih generalizing a · simp_rw [List.ofFn_zero, List.prod_nil, Fin.exists_fin_zero_pi, eq_comm, Set.mem_one] · simp_rw [List.ofFn_succ, List.prod_cons, Fin.exists_fin_succ_pi, Fin.cons_zero, Fin.cons_succ, mem_mul, @ih, exists_exists_eq_and, SetCoe.exists, exists_prop] @[to_additive] theorem mem_list_prod {l : List (Set α)} {a : α} : a ∈ l.prod ↔ ∃ l' : List (Σ s : Set α, ↥s), List.prod (l'.map fun x ↦ (Sigma.snd x : α)) = a ∧ l'.map Sigma.fst = l := by induction' l using List.ofFnRec with n f simp only [mem_prod_list_ofFn, List.exists_iff_exists_tuple, List.map_ofFn, List.ofFn_inj', Sigma.mk.inj_iff, and_left_comm, exists_and_left, exists_eq_left, heq_eq_eq] constructor · rintro ⟨fi, rfl⟩ exact ⟨fun i ↦ ⟨_, fi i⟩, rfl, rfl⟩ · rintro ⟨fi, rfl, rfl⟩ exact ⟨fun i ↦ _, rfl⟩ @[to_additive] theorem mem_pow {a : α} {n : ℕ} : a ∈ s ^ n ↔ ∃ f : Fin n → s, (List.ofFn fun i ↦ (f i : α)).prod = a := by rw [← mem_prod_list_ofFn, List.ofFn_const, List.prod_replicate] end Set
DFinsupp.lean
/- Copyright (c) 2024 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Sophie Morel -/ import Mathlib.Data.Fintype.Quotient import Mathlib.LinearAlgebra.DFinsupp import Mathlib.LinearAlgebra.Multilinear.Basic /-! # Interactions between finitely-supported functions and multilinear maps ## Main definitions * `MultilinearMap.dfinsupp_ext` * `MultilinearMap.dfinsuppFamily`, which satisfies `dfinsuppFamily f x p = f p (fun i => x i (p i))`. This is the finitely-supported version of `MultilinearMap.piFamily`. This is useful because all the intermediate results are bundled: - `MultilinearMap.dfinsuppFamily f x` is a `DFinsupp` supported by families of indices `p`. - `MultilinearMap.dfinsuppFamily f` is a `MultilinearMap` operating on finitely-supported functions `x`. - `MultilinearMap.dfinsuppFamilyₗ` is a `LinearMap`, linear in the family of multilinear maps `f`. -/ universe uι uκ uS uR uM uN variable {ι : Type uι} {κ : ι → Type uκ} variable {S : Type uS} {R : Type uR} namespace MultilinearMap section Semiring variable {M : ∀ i, κ i → Type uM} {N : Type uN} variable [Finite ι] [Semiring R] variable [∀ i k, AddCommMonoid (M i k)] [AddCommMonoid N] variable [∀ i k, Module R (M i k)] [Module R N] /-- Two multilinear maps from finitely supported functions are equal if they agree on the generators. This is a multilinear version of `DFinsupp.lhom_ext'`. -/ @[ext] theorem dfinsupp_ext [∀ i, DecidableEq (κ i)] ⦃f g : MultilinearMap R (fun i ↦ Π₀ j : κ i, M i j) N⦄ (h : ∀ p : Π i, κ i, f.compLinearMap (fun i => DFinsupp.lsingle (p i)) = g.compLinearMap (fun i => DFinsupp.lsingle (p i))) : f = g := by ext x change f (fun i ↦ x i) = g (fun i ↦ x i) classical cases nonempty_fintype ι rw [funext (fun i ↦ Eq.symm (DFinsupp.sum_single (f := x i)))] simp_rw [DFinsupp.sum, MultilinearMap.map_sum_finset] congr! 1 with p simp_rw [MultilinearMap.ext_iff] at h exact h _ _ end Semiring section dfinsuppFamily variable {M : ∀ i, κ i → Type uM} {N : (Π i, κ i) → Type uN} section Semiring variable [DecidableEq ι] [Fintype ι] [Semiring R] variable [∀ i k, AddCommMonoid (M i k)] [∀ p, AddCommMonoid (N p)] variable [∀ i k, Module R (M i k)] [∀ p, Module R (N p)] /-- Given a family of indices `κ` and a multilinear map `f p` for each way `p` to select one index from each family, `dfinsuppFamily f` maps a family of finitely-supported functions (one for each domain `κ i`) into a finitely-supported function from each selection of indices (with domain `Π i, κ i`). Strictly this doesn't need multilinearity, only the fact that `f p m = 0` whenever `m i = 0` for some `i`. This is the `DFinsupp` version of `MultilinearMap.piFamily`. -/ @[simps] def dfinsuppFamily (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : MultilinearMap R (fun i => Π₀ j : κ i, M i j) (Π₀ t : Π i, κ i, N t) where toFun x := { toFun := fun p => f p (fun i => x i (p i)) support' := (Trunc.finChoice fun i => (x i).support').map fun s => ⟨ Finset.univ.val.pi (fun i ↦ (s i).val) |>.map fun f i => f i (Finset.mem_univ _), fun p => by simp only [Multiset.mem_map, Multiset.mem_pi, Finset.mem_val, Finset.mem_univ, forall_true_left] simp_rw [or_iff_not_imp_right] intro h push_neg at h refine ⟨fun i _ => p i, fun i => (s i).prop _ |>.resolve_right ?_, rfl⟩ exact mt ((f p).map_coord_zero (m := fun i => x i _) i) h⟩} map_update_add' {dec} m i x y := DFinsupp.ext fun p => by dsimp simp_rw [Function.apply_update (fun i m => m (p i)) m, DFinsupp.add_apply, (f p).map_update_add] map_update_smul' {dec} m i c x := DFinsupp.ext fun p => by dsimp simp_rw [Function.apply_update (fun i m => m (p i)) m, DFinsupp.smul_apply, (f p).map_update_smul] theorem support_dfinsuppFamily_subset [∀ i, DecidableEq (κ i)] [∀ i j, (x : M i j) → Decidable (x ≠ 0)] [∀ i, (x : N i) → Decidable (x ≠ 0)] (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) (x : ∀ i, Π₀ j : κ i, M i j) : (dfinsuppFamily f x).support ⊆ Fintype.piFinset fun i => (x i).support := by intro p hp simp only [DFinsupp.mem_support_toFun, dfinsuppFamily_apply_toFun, ne_eq, Fintype.mem_piFinset] at hp ⊢ intro i exact mt ((f p).map_coord_zero (m := fun i => x i _) i) hp /-- When applied to a family of finitely-supported functions each supported on a single element, `dfinsuppFamily` is itself supported on a single element, with value equal to the map `f` applied at that point. -/ @[simp] theorem dfinsuppFamily_single [∀ i, DecidableEq (κ i)] (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) (p : ∀ i, κ i) (m : ∀ i, M i (p i)) : dfinsuppFamily f (fun i => .single (p i) (m i)) = DFinsupp.single p (f p m) := by ext q obtain rfl | hpq := eq_or_ne p q · simp · rw [DFinsupp.single_eq_of_ne hpq] rw [Function.ne_iff] at hpq obtain ⟨i, hpqi⟩ := hpq apply (f q).map_coord_zero i simp_rw [DFinsupp.single_eq_of_ne hpqi] /-- When only one member of the family of multilinear maps is nonzero, the result consists only of the component from that member. -/ @[simp] theorem dfinsuppFamily_single_left_apply [∀ i, DecidableEq (κ i)] (p : Π i, κ i) (f : MultilinearMap R (fun i ↦ M i (p i)) (N p)) (x : Π i, Π₀ j, M i j) : dfinsuppFamily (Pi.single p f) x = DFinsupp.single p (f fun i => x _ (p i)) := by ext p' obtain rfl | hp := eq_or_ne p p' · simp · simp [hp] theorem dfinsuppFamily_single_left [∀ i, DecidableEq (κ i)] (p : Π i, κ i) (f : MultilinearMap R (fun i ↦ M i (p i)) (N p)) : dfinsuppFamily (Pi.single p f) = (DFinsupp.lsingle p).compMultilinearMap (f.compLinearMap fun i => DFinsupp.lapply (p i)) := ext <| dfinsuppFamily_single_left_apply _ _ @[simp] theorem dfinsuppFamily_compLinearMap_lsingle [∀ i, DecidableEq (κ i)] (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) (p : ∀ i, κ i) : (dfinsuppFamily f).compLinearMap (fun i => DFinsupp.lsingle (p i)) = (DFinsupp.lsingle p).compMultilinearMap (f p) := MultilinearMap.ext <| dfinsuppFamily_single f p @[simp] theorem dfinsuppFamily_zero : dfinsuppFamily (0 : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) = 0 := by ext; simp @[simp] theorem dfinsuppFamily_add (f g : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : dfinsuppFamily (f + g) = dfinsuppFamily f + dfinsuppFamily g := by ext; simp @[simp] theorem dfinsuppFamily_smul [Monoid S] [∀ p, DistribMulAction S (N p)] [∀ p, SMulCommClass R S (N p)] (s : S) (f : Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) : dfinsuppFamily (s • f) = s • dfinsuppFamily f := by ext; simp end Semiring section CommSemiring variable [DecidableEq ι] [Fintype ι] [CommSemiring R] variable [∀ i k, AddCommMonoid (M i k)] [∀ p, AddCommMonoid (N p)] variable [∀ i k, Module R (M i k)] [∀ p, Module R (N p)] /-- `MultilinearMap.dfinsuppFamily` as a linear map. -/ @[simps] def dfinsuppFamilyₗ : (Π (p : Π i, κ i), MultilinearMap R (fun i ↦ M i (p i)) (N p)) →ₗ[R] MultilinearMap R (fun i => Π₀ j : κ i, M i j) (Π₀ t : Π i, κ i, N t) where toFun := dfinsuppFamily map_add' := dfinsuppFamily_add map_smul' := dfinsuppFamily_smul end CommSemiring end dfinsuppFamily end MultilinearMap
cyclotomic.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 div choice fintype tuple finfun bigop prime. From mathcomp Require Import ssralg poly finset fingroup finalg zmodp cyclic. From mathcomp Require Import ssrnum ssrint archimedean polydiv intdiv mxpoly. From mathcomp Require Import rat vector falgebra fieldext separable galois algC. (******************************************************************************) (* This file provides few basic properties of cyclotomic polynomials. *) (* We define: *) (* cyclotomic z n == the factorization of the nth cyclotomic polynomial in *) (* a ring R in which z is an nth primitive root of unity. *) (* 'Phi_n == the nth cyclotomic polynomial in int. *) (* This library is quite limited, and should be extended in the future. In *) (* particular the irreducibity of 'Phi_n is only stated indirectly, as the *) (* fact that its embedding in the algebraics (algC) is the minimal polynomial *) (* of an nth primitive root of unity. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory Num.Theory. Local Open Scope ring_scope. Section CyclotomicPoly. Section NzRing. Variable R : nzRingType. Definition cyclotomic (z : R) n := \prod_(k < n | coprime k n) ('X - (z ^+ k)%:P). Lemma cyclotomic_monic z n : cyclotomic z n \is monic. Proof. exact: monic_prod_XsubC. Qed. Lemma size_cyclotomic z n : size (cyclotomic z n) = (totient n).+1. Proof. rewrite /cyclotomic -big_filter size_prod_XsubC; congr _.+1. case: big_enumP => _ _ _ [_ ->]. rewrite totient_count_coprime -big_mkcond big_mkord -sum1_card. by apply: eq_bigl => k; rewrite coprime_sym. Qed. End NzRing. Lemma separable_Xn_sub_1 (R : idomainType) n : n%:R != 0 :> R -> @separable_poly R ('X^n - 1). Proof. case: n => [/eqP// | n nz_n]; rewrite unlock linearB /= derivC subr0. rewrite derivXn -scaler_nat coprimepZr //= exprS -scaleN1r coprimep_sym. by rewrite coprimep_addl_mul coprimepZr ?coprimep1 // (signr_eq0 _ 1). Qed. Section Field. Variables (F : fieldType) (n : nat) (z : F). Hypothesis prim_z : n.-primitive_root z. Let n_gt0 := prim_order_gt0 prim_z. Lemma root_cyclotomic x : root (cyclotomic z n) x = n.-primitive_root x. Proof. transitivity (x \in [seq z ^+ i | i : 'I_n in [pred i : 'I_n | coprime i n]]). by rewrite -root_prod_XsubC big_image. apply/imageP/idP=> [[k co_k_n ->] | prim_x]. by rewrite prim_root_exp_coprime. have [k Dx] := prim_rootP prim_z (prim_expr_order prim_x). exists (Ordinal (ltn_pmod k n_gt0)) => /=; last by rewrite prim_expr_mod. by rewrite inE coprime_modl -(prim_root_exp_coprime k prim_z) -Dx. Qed. Lemma prod_cyclotomic : 'X^n - 1 = \prod_(d <- divisors n) cyclotomic (z ^+ (n %/ d)) d. Proof. have in_d d: (d %| n)%N -> val (@inord n d) = d by move/dvdn_leq/inordK=> /= ->. have dv_n k: (n %/ gcdn k n %| n)%N. by rewrite -{3}(divnK (dvdn_gcdr k n)) dvdn_mulr. have [uDn _ inDn] := divisors_correct n_gt0. have defDn: divisors n = map val (map (@inord n) (divisors n)). by rewrite -map_comp map_id_in // => d; rewrite inDn => /in_d. rewrite defDn big_map big_uniq /=; last first. by rewrite -(map_inj_uniq val_inj) -defDn. pose h (k : 'I_n) : 'I_n.+1 := inord (n %/ gcdn k n). rewrite -(factor_Xn_sub_1 prim_z) big_mkord. rewrite (partition_big h (dvdn^~ n)) /= => [|k _]; last by rewrite in_d ?dv_n. apply: eq_big => d; first by rewrite -(mem_map val_inj) -defDn inDn. set q := (n %/ d)%N => d_dv_n. have [q_gt0 d_gt0]: (0 < q /\ 0 < d)%N by apply/andP; rewrite -muln_gt0 divnK. have fP (k : 'I_d): (q * k < n)%N by rewrite divn_mulAC ?ltn_divLR ?ltn_pmul2l. rewrite (reindex (fun k => Ordinal (fP k))); last first. have f'P (k : 'I_n): (k %/ q < d)%N by rewrite ltn_divLR // mulnC divnK. exists (fun k => Ordinal (f'P k)) => [k _ | k /eqnP/=]. by apply: val_inj; rewrite /= mulKn. rewrite in_d // => Dd; apply: val_inj; rewrite /= mulnC divnK // /q -Dd. by rewrite divnA ?mulKn ?dvdn_gcdl ?dvdn_gcdr. apply: eq_big => k; rewrite ?exprM // -val_eqE in_d //=. rewrite -eqn_mul ?dvdn_gcdr ?gcdn_gt0 ?n_gt0 ?orbT //. rewrite -[n in gcdn _ n](divnK d_dv_n) -muln_gcdr mulnCA mulnA divnK //. by rewrite mulnC eqn_mul // divnn n_gt0 eq_sym. Qed. End Field. End CyclotomicPoly. Local Notation ZtoQ := (intr : int -> rat). Local Notation ZtoC := (intr : int -> algC). Local Notation QtoC := (ratr : rat -> algC). Local Notation intrp := (map_poly intr). Local Notation pZtoQ := (map_poly ZtoQ). Local Notation pZtoC := (map_poly ZtoC). Local Notation pQtoC := (map_poly ratr). Local Definition algC_intr_inj := @intr_inj algC. #[local] Hint Resolve algC_intr_inj : core. Local Notation intCK := (@intrKfloor algC). Lemma C_prim_root_exists n : (n > 0)%N -> {z : algC | n.-primitive_root z}. Proof. pose p : {poly algC} := 'X^n - 1; have [r Dp] := closed_field_poly_normal p. move=> n_gt0; apply/sigW; rewrite (monicP _) ?monicXnsubC // scale1r in Dp. have rn1: all n.-unity_root r by apply/allP=> z; rewrite -root_prod_XsubC -Dp. have sz_r: (n < (size r).+1)%N. by rewrite -(size_prod_XsubC r id) -Dp size_XnsubC. have [|z] := hasP (has_prim_root n_gt0 rn1 _ sz_r); last by exists z. by rewrite -separable_prod_XsubC -Dp separable_Xn_sub_1 // pnatr_eq0 -lt0n. Qed. (* (Integral) Cyclotomic polynomials. *) Definition Cyclotomic n : {poly int} := let: exist z _ := C_prim_root_exists (ltn0Sn n.-1) in map_poly Num.floor (cyclotomic z n). Notation "''Phi_' n" := (Cyclotomic n) (at level 8, n at level 2, format "''Phi_' n"). Lemma Cyclotomic_monic n : 'Phi_n \is monic. Proof. rewrite /'Phi_n; case: (C_prim_root_exists _) => z /= _. rewrite monicE lead_coefE coef_map_id0 ?(int_algC_K 0) ?floor0 //. by rewrite size_poly_eq -lead_coefE (monicP (cyclotomic_monic _ _)) (intCK 1). Qed. Lemma Cintr_Cyclotomic n z : n.-primitive_root z -> pZtoC 'Phi_n = cyclotomic z n. Proof. elim/ltn_ind: n z => n IHn z0 prim_z0. rewrite /'Phi_n; case: (C_prim_root_exists _) => z /=. have n_gt0 := prim_order_gt0 prim_z0; rewrite prednK // => prim_z. have [uDn _ inDn] := divisors_correct n_gt0. pose q := \prod_(d <- rem n (divisors n)) 'Phi_d. have mon_q: q \is monic by apply: monic_prod => d _; apply: Cyclotomic_monic. have defXn1: cyclotomic z n * pZtoC q = 'X^n - 1. rewrite (prod_cyclotomic prim_z) (big_rem n) ?inDn //=. rewrite divnn n_gt0 rmorph_prod /=; congr (_ * _). apply: eq_big_seq => d; rewrite mem_rem_uniq ?inE //= inDn => /andP[n'd ddvn]. by rewrite -IHn ?dvdn_prim_root // ltn_neqAle n'd dvdn_leq. have mapXn1 (R1 R2 : nzRingType) (f : {rmorphism R1 -> R2}): map_poly f ('X^n - 1) = 'X^n - 1. - by rewrite rmorphB /= rmorph1 map_polyXn. have nz_q: pZtoC q != 0. by rewrite -size_poly_eq0 size_map_inj_poly // size_poly_eq0 monic_neq0. have [r def_zn]: exists r, cyclotomic z n = pZtoC r. have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> a; rewrite /= rmorph_int. have /dvdpP[r0 Dr0]: map_poly ZtoQ q %| 'X^n - 1. rewrite -(dvdp_map (@ratr algC)) mapXn1 -map_poly_comp. by rewrite -(eq_map_poly defZtoC) -defXn1 dvdp_mull. have [r [a nz_a Dr]] := rat_poly_scale r0. exists (zprimitive r); apply: (mulIf nz_q); rewrite defXn1. rewrite -rmorphM -(zprimitive_monic mon_q) -zprimitiveM /=. have ->: r * q = a *: ('X^n - 1). apply: (map_inj_poly (intr_inj : injective ZtoQ)) => //. rewrite map_polyZ mapXn1 Dr0 Dr -scalerAl scalerKV ?intr_eq0 //. by rewrite rmorphM. by rewrite zprimitiveZ // zprimitive_monic ?monicXnsubC ?mapXn1. rewrite floorpK; last by apply/polyOverP=> i; rewrite def_zn coef_map /=. pose f e (k : 'I_n) := Ordinal (ltn_pmod (k * e) n_gt0). have [e Dz0] := prim_rootP prim_z (prim_expr_order prim_z0). have co_e_n: coprime e n by rewrite -(prim_root_exp_coprime e prim_z) -Dz0. have injf: injective (f e). apply: can_inj (f (egcdn e n).1) _ => k; apply: val_inj => /=. rewrite modnMml -mulnA -modnMmr -{1}(mul1n e). by rewrite (chinese_modr co_e_n 0) modnMmr muln1 modn_small. rewrite [_ n](reindex_inj injf); apply: eq_big => k /=. by rewrite coprime_modl coprimeMl co_e_n andbT. by rewrite prim_expr_mod // mulnC exprM -Dz0. Qed. Lemma prod_Cyclotomic n : (n > 0)%N -> \prod_(d <- divisors n) 'Phi_d = 'X^n - 1. Proof. move=> n_gt0; have [z prim_z] := C_prim_root_exists n_gt0. apply: (map_inj_poly (intr_inj : injective ZtoC)) => //. rewrite rmorphB rmorph1 rmorph_prod /= map_polyXn (prod_cyclotomic prim_z). apply: eq_big_seq => d; rewrite -dvdn_divisors // => d_dv_n. by rewrite -Cintr_Cyclotomic ?dvdn_prim_root. Qed. Lemma Cyclotomic0 : 'Phi_0 = 1. Proof. rewrite /'Phi_0; case: (C_prim_root_exists _) => z /= _. by rewrite -[1]polyseqK /cyclotomic big_ord0 map_polyE !polyseq1 /= (intCK 1). Qed. Lemma size_Cyclotomic n : size 'Phi_n = (totient n).+1. Proof. have [-> | n_gt0] := posnP n; first by rewrite Cyclotomic0 polyseq1. have [z prim_z] := C_prim_root_exists n_gt0. rewrite -(size_map_inj_poly (can_inj intCK)) //. by rewrite (Cintr_Cyclotomic prim_z) size_cyclotomic. Qed. Lemma minCpoly_cyclotomic n z : n.-primitive_root z -> minCpoly z = cyclotomic z n. Proof. move=> prim_z; have n_gt0 := prim_order_gt0 prim_z. have Dpz := Cintr_Cyclotomic prim_z; set pz := cyclotomic z n in Dpz *. have mon_pz: pz \is monic by apply: cyclotomic_monic. have pz0: root pz z by rewrite root_cyclotomic. have [pf [Dpf mon_pf] dv_pf] := minCpolyP z. have /dvdpP_rat_int[f [af nz_af Df] [g /esym Dfg]]: pf %| pZtoQ 'Phi_n. rewrite -dv_pf; congr (root _ z): pz0; rewrite -Dpz -map_poly_comp. by apply: eq_map_poly => b; rewrite /= rmorph_int. without loss{nz_af} [mon_f mon_g]: af f g Df Dfg / f \is monic /\ g \is monic. move=> IH; pose cf := lead_coef f; pose cg := lead_coef g. have cfg1: cf * cg = 1. by rewrite -lead_coefM Dfg (monicP (Cyclotomic_monic n)). apply: (IH (af *~ cf) (f *~ cg) (g *~ cf)). - by rewrite rmorphMz -scalerMzr scalerMzl -mulrzA cfg1. - by rewrite mulrzAl mulrzAr -mulrzA cfg1. by rewrite !(intz, =^~ scaler_int) !monicE !lead_coefZ mulrC cfg1. have{af} Df: pQtoC pf = pZtoC f. have:= congr1 lead_coef Df. rewrite lead_coefZ lead_coef_map_inj //; last exact: intr_inj. rewrite !(monicP _) // mulr1 Df => <-; rewrite scale1r -map_poly_comp. by apply: eq_map_poly => b; rewrite /= rmorph_int. have [/size1_polyC Dg | g_gt1] := leqP (size g) 1. rewrite monicE Dg lead_coefC in mon_g. by rewrite -Dpz -Dfg Dg (eqP mon_g) mulr1 Dpf. have [zk gzk0]: exists zk, root (pZtoC g) zk. have [rg] := closed_field_poly_normal (pZtoC g). rewrite lead_coef_map_inj // (monicP mon_g) scale1r => Dg. rewrite -(size_map_inj_poly (can_inj intCK)) // Dg in g_gt1. rewrite size_prod_XsubC in g_gt1. by exists rg`_0; rewrite Dg root_prod_XsubC mem_nth. have [k cokn Dzk]: exists2 k, coprime k n & zk = z ^+ k. have: root pz zk by rewrite -Dpz -Dfg rmorphM rootM gzk0 orbT. rewrite -[pz](big_image _ _ _ _ (fun r => 'X - r%:P)) root_prod_XsubC. by case/imageP=> k; exists k. have co_fg (R : idomainType): n%:R != 0 :> R -> @coprimep R (intrp f) (intrp g). move=> nz_n; have: separable_poly (intrp ('X^n - 1) : {poly R}). by rewrite rmorphB rmorph1 /= map_polyXn separable_Xn_sub_1. rewrite -prod_Cyclotomic // (big_rem n) -?dvdn_divisors //= -Dfg. by rewrite !rmorphM /= !separable_mul => /and3P[] /and3P[]. suffices fzk0: root (pZtoC f) zk. have [] // := negP (coprimep_root (co_fg _ _) fzk0). by rewrite pnatr_eq0 -lt0n. move: gzk0 cokn; rewrite {zk}Dzk; elim/ltn_ind: k => k IHk gzk0 cokn. have [|k_gt1] := leqP k 1; last have [p p_pr /dvdnP[k1 Dk]] := pdivP k_gt1. rewrite -[leq k 1](mem_iota 0 2) !inE => /pred2P[k0 | ->]; last first. by rewrite -Df dv_pf. have /eqP := size_Cyclotomic n; rewrite -Dfg size_Mmonic ?monic_neq0 //. rewrite k0 /coprime gcd0n in cokn; rewrite (eqP cokn). rewrite -(size_map_inj_poly (can_inj intCK)) // -Df -Dpf. by rewrite -(subnKC g_gt1) -(subnKC (size_minCpoly z)) !addnS. move: cokn; rewrite Dk coprimeMl => /andP[cok1n]. rewrite prime_coprime // (dvdn_pcharf (pchar_Fp p_pr)) => /co_fg {co_fg}. have pcharFpX: p \in [pchar {poly 'F_p}] by rewrite (rmorph_pchar polyC) ?pchar_Fp. rewrite -(coprimep_pexpr _ _ (prime_gt0 p_pr)) -(pFrobenius_autE pcharFpX). rewrite -[g]comp_polyXr map_comp_poly -horner_map /= pFrobenius_autE -rmorphXn. rewrite -!map_poly_comp (@eq_map_poly _ _ _ (polyC \o *~%R 1)); last first. by move=> a; rewrite /= !rmorph_int. rewrite map_poly_comp -[_.[_]]map_comp_poly /= => co_fg. suffices: coprimep (pZtoC f) (pZtoC (g \Po 'X^p)). move/coprimep_root=> /=/(_ (z ^+ k1))/implyP. rewrite map_comp_poly map_polyXn horner_comp hornerXn. rewrite -exprM -Dk [_ == 0]gzk0 implybF => /negP[]. have: root pz (z ^+ k1). by rewrite root_cyclotomic // prim_root_exp_coprime. rewrite -Dpz -Dfg rmorphM rootM => /orP[] //= /IHk-> //. rewrite -[k1]muln1 Dk ltn_pmul2l ?prime_gt1 //. by have:= ltnW k_gt1; rewrite Dk muln_gt0 => /andP[]. suffices: coprimep f (g \Po 'X^p). case/Bezout_coprimepP=> [[u v]]; rewrite -size_poly_eq1. rewrite -(size_map_inj_poly (can_inj intCK)) // rmorphD !rmorphM /=. rewrite size_poly_eq1 => {}co_fg; apply/Bezout_coprimepP. by exists (pZtoC u, pZtoC v). apply: contraLR co_fg => /coprimepPn[|d]; first exact: monic_neq0. rewrite andbC -size_poly_eq1 dvdp_gcd => /and3P[sz_d]. pose d1 := zprimitive d. have d_dv_mon h: d %| h -> h \is monic -> exists h1, h = d1 * h1. case/Pdiv.Idomain.dvdpP=> [[c h1] /= nz_c Dh] mon_h; exists (zprimitive h1). by rewrite -zprimitiveM mulrC -Dh zprimitiveZ ?zprimitive_monic. case/d_dv_mon=> // f1 Df1 /d_dv_mon[|f2 ->]. rewrite monicE lead_coefE size_comp_poly size_polyXn /=. rewrite comp_polyE coef_sum polySpred ?monic_neq0 //= mulnC. rewrite big_ord_recr /= -lead_coefE (monicP mon_g) scale1r. rewrite -exprM coefXn eqxx big1 ?add0r // => i _. rewrite coefZ -exprM coefXn eqn_pmul2l ?prime_gt0 //. by rewrite eqn_leq leqNgt ltn_ord mulr0. have monFp h: h \is monic -> size (map_poly intr h) = size h. by move=> mon_h; rewrite size_poly_eq // -lead_coefE (monicP mon_h) oner_eq0. apply/coprimepPn; last exists (map_poly intr d1). by rewrite -size_poly_eq0 monFp // size_poly_eq0 monic_neq0. rewrite Df1 !rmorphM dvdp_gcd !dvdp_mulr //= -size_poly_eq1. rewrite monFp ?size_zprimitive //. rewrite monicE [_ d1]intEsg sgz_lead_primitive -zprimitive_eq0 -/d1. rewrite -lead_coef_eq0 -absz_eq0. have/esym/eqP := congr1 (absz \o lead_coef) Df1. by rewrite /= (monicP mon_f) lead_coefM abszM muln_eq1 => /andP[/eqP-> _]. Qed.
Idempotents.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Ring.GeomSum import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Nilpotent.Defs /-! ## Idempotents in rings The predicate `IsIdempotentElem` is defined for general monoids in `Algebra/Ring/Idempotents.lean`. In this file we provide various results regarding idempotent elements in rings. ## Main definitions - `OrthogonalIdempotents`: A family `{ eᵢ }` of idempotent elements is orthogonal if `eᵢ * eⱼ = 0` for all `i ≠ j`. - `CompleteOrthogonalIdempotents`: A family `{ eᵢ }` of orthogonal idempotent elements is complete if `∑ eᵢ = 1`. ## Main results - `CompleteOrthogonalIdempotents.lift_of_isNilpotent_ker`: If the kernel of `f : R →+* S` consists of nilpotent elements, and `{ eᵢ }` is a family of complete orthogonal idempotents in the range of `f`, then `{ eᵢ }` is the image of some complete orthogonal idempotents in `R`. - `existsUnique_isIdempotentElem_eq_of_ker_isNilpotent`: If `R` is commutative and the kernel of `f : R →+* S` consists of nilpotent elements, then every idempotent in the range of `f` lifts to a unique idempotent in `R`. - `CompleteOrthogonalIdempotents.bijective_pi`: If `R` is commutative, then a family `{ eᵢ }` of complete orthogonal idempotent elements induces a ring isomorphism `R ≃ ∏ R ⧸ ⟨1 - eᵢ⟩`. -/ section Semiring variable {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) variable {I : Type*} (e : I → R) /-- A family `{ eᵢ }` of idempotent elements is orthogonal if `eᵢ * eⱼ = 0` for all `i ≠ j`. -/ @[mk_iff] structure OrthogonalIdempotents : Prop where idem : ∀ i, IsIdempotentElem (e i) ortho : Pairwise (e · * e · = 0) variable {e} lemma OrthogonalIdempotents.mul_eq [DecidableEq I] (he : OrthogonalIdempotents e) (i j) : e i * e j = if i = j then e i else 0 := by split · simp [*, (he.idem j).eq] · exact he.ortho ‹_› lemma OrthogonalIdempotents.iff_mul_eq [DecidableEq I] : OrthogonalIdempotents e ↔ ∀ i j, e i * e j = if i = j then e i else 0 := ⟨mul_eq, fun H ↦ ⟨fun i ↦ by simpa using H i i, fun i j e ↦ by simpa [e] using H i j⟩⟩ lemma OrthogonalIdempotents.isIdempotentElem_sum (he : OrthogonalIdempotents e) {s : Finset I} : IsIdempotentElem (∑ i ∈ s, e i) := by classical simp [IsIdempotentElem, Finset.sum_mul, Finset.mul_sum, he.mul_eq] lemma OrthogonalIdempotents.mul_sum_of_mem (he : OrthogonalIdempotents e) {i : I} {s : Finset I} (h : i ∈ s) : e i * ∑ j ∈ s, e j = e i := by classical simp [Finset.mul_sum, he.mul_eq, h] lemma OrthogonalIdempotents.mul_sum_of_notMem (he : OrthogonalIdempotents e) {i : I} {s : Finset I} (h : i ∉ s) : e i * ∑ j ∈ s, e j = 0 := by classical simp [Finset.mul_sum, he.mul_eq, h] @[deprecated (since := "2025-05-23")] alias OrthogonalIdempotents.mul_sum_of_not_mem := OrthogonalIdempotents.mul_sum_of_notMem lemma OrthogonalIdempotents.map (he : OrthogonalIdempotents e) : OrthogonalIdempotents (f ∘ e) := by classical simp [iff_mul_eq, he.mul_eq, ← map_mul f, apply_ite f] lemma OrthogonalIdempotents.map_injective_iff (hf : Function.Injective f) : OrthogonalIdempotents (f ∘ e) ↔ OrthogonalIdempotents e := by classical simp [iff_mul_eq, ← hf.eq_iff, apply_ite] lemma OrthogonalIdempotents.embedding (he : OrthogonalIdempotents e) {J} (i : J ↪ I) : OrthogonalIdempotents (e ∘ i) := by classical simp [iff_mul_eq, he.mul_eq] lemma OrthogonalIdempotents.equiv {J} (i : J ≃ I) : OrthogonalIdempotents (e ∘ i) ↔ OrthogonalIdempotents e := by classical simp [iff_mul_eq, i.forall_congr_left] lemma OrthogonalIdempotents.unique [Unique I] : OrthogonalIdempotents e ↔ IsIdempotentElem (e default) := by simp only [orthogonalIdempotents_iff, Unique.forall_iff, Subsingleton.pairwise, and_true] lemma OrthogonalIdempotents.option (he : OrthogonalIdempotents e) [Fintype I] (x) (hx : IsIdempotentElem x) (hx₁ : x * ∑ i, e i = 0) (hx₂ : (∑ i, e i) * x = 0) : OrthogonalIdempotents (Option.elim · x e) where idem i := i.rec hx he.idem ortho i j ne := by classical rcases i with - | i <;> rcases j with - | j · cases ne rfl · simpa only [mul_assoc, Finset.sum_mul, he.mul_eq, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, zero_mul] using congr_arg (· * e j) hx₁ · simpa only [Option.elim_some, Option.elim_none, ← mul_assoc, Finset.mul_sum, he.mul_eq, Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte, mul_zero] using congr_arg (e i * ·) hx₂ · exact he.ortho (Option.some_inj.ne.mp ne) variable [Fintype I] /-- A family `{ eᵢ }` of idempotent elements is complete orthogonal if 1. (orthogonal) `eᵢ * eⱼ = 0` for all `i ≠ j`. 2. (complete) `∑ eᵢ = 1` -/ @[mk_iff] structure CompleteOrthogonalIdempotents (e : I → R) : Prop extends OrthogonalIdempotents e where complete : ∑ i, e i = 1 /-- If a family is complete orthogonal, it consists of idempotents. -/ lemma CompleteOrthogonalIdempotents.iff_ortho_complete : CompleteOrthogonalIdempotents e ↔ Pairwise (e · * e · = 0) ∧ ∑ i, e i = 1 := by rw [completeOrthogonalIdempotents_iff, orthogonalIdempotents_iff, and_assoc, and_iff_right_of_imp] intro ⟨ortho, complete⟩ i apply_fun (e i * ·) at complete rwa [Finset.mul_sum, Finset.sum_eq_single i (fun _ _ ne ↦ ortho ne.symm) (by simp at ·), mul_one] at complete lemma CompleteOrthogonalIdempotents.pair_iff'ₛ {x y : R} : CompleteOrthogonalIdempotents ![x, y] ↔ x * y = 0 ∧ y * x = 0 ∧ x + y = 1 := by simp [iff_ortho_complete, Pairwise, Fin.forall_fin_two, and_assoc] lemma CompleteOrthogonalIdempotents.pair_iffₛ {R} [CommSemiring R] {x y : R} : CompleteOrthogonalIdempotents ![x, y] ↔ x * y = 0 ∧ x + y = 1 := by rw [pair_iff'ₛ, and_left_comm, and_iff_right_of_imp]; exact (mul_comm x y ▸ ·.1) lemma CompleteOrthogonalIdempotents.unique_iff [Unique I] : CompleteOrthogonalIdempotents e ↔ e default = 1 := by rw [completeOrthogonalIdempotents_iff, OrthogonalIdempotents.unique, Fintype.sum_unique, and_iff_right_iff_imp] exact (· ▸ IsIdempotentElem.one) lemma CompleteOrthogonalIdempotents.single {I : Type*} [Fintype I] [DecidableEq I] (R : I → Type*) [∀ i, Semiring (R i)] : CompleteOrthogonalIdempotents (Pi.single (M := R) · 1) := by refine ⟨⟨by simp [IsIdempotentElem, ← Pi.single_mul], ?_⟩, Finset.univ_sum_single 1⟩ intros i j hij ext k by_cases hi : i = k · subst hi; simp [hij] · simp [hi] lemma CompleteOrthogonalIdempotents.map (he : CompleteOrthogonalIdempotents e) : CompleteOrthogonalIdempotents (f ∘ e) where __ := he.toOrthogonalIdempotents.map f complete := by simp only [Function.comp_apply, ← map_sum, he.complete, map_one] lemma CompleteOrthogonalIdempotents.map_injective_iff (hf : Function.Injective f) : CompleteOrthogonalIdempotents (f ∘ e) ↔ CompleteOrthogonalIdempotents e := by simp [completeOrthogonalIdempotents_iff, ← hf.eq_iff, OrthogonalIdempotents.map_injective_iff f hf] lemma CompleteOrthogonalIdempotents.equiv {J} [Fintype J] (i : J ≃ I) : CompleteOrthogonalIdempotents (e ∘ i) ↔ CompleteOrthogonalIdempotents e := by simp only [completeOrthogonalIdempotents_iff, OrthogonalIdempotents.equiv, Function.comp_apply, Fintype.sum_equiv i _ e (fun _ ↦ rfl)] @[nontriviality] lemma CompleteOrthogonalIdempotents.of_subsingleton [Subsingleton R] : CompleteOrthogonalIdempotents e := ⟨⟨fun _ ↦ Subsingleton.elim _ _, fun _ _ _ ↦ Subsingleton.elim _ _⟩, Subsingleton.elim _ _⟩ end Semiring section Ring variable {R S : Type*} [Ring R] [Ring S] (f : R →+* S) theorem isIdempotentElem_one_sub_one_sub_pow_pow (x : R) (n : ℕ) (hx : (x - x ^ 2) ^ n = 0) : IsIdempotentElem (1 - (1 - x ^ n) ^ n) := by have : (x - x ^ 2) ^ n ∣ (1 - (1 - x ^ n) ^ n) - (1 - (1 - x ^ n) ^ n) ^ 2 := by conv_rhs => rw [pow_two, ← mul_one_sub, sub_sub_cancel] nth_rw 1 3 [← one_pow n] rw [← (Commute.one_left x).mul_geom_sum₂, ← (Commute.one_left (1 - x ^ n)).mul_geom_sum₂] simp only [sub_sub_cancel, one_pow, one_mul] rw [Commute.mul_pow, Commute.mul_mul_mul_comm, ← Commute.mul_pow, mul_one_sub, ← pow_two] · exact ⟨_, rfl⟩ · simp · refine .pow_right (.sub_right (.one_right _) (.sum_left _ _ _ fun _ _ ↦ .pow_left ?_ _)) _ simp · exact .sub_left (.one_left _) (.sum_right _ _ _ fun _ _ ↦ .pow_right rfl _) rwa [hx, zero_dvd_iff, sub_eq_zero, eq_comm, pow_two] at this theorem exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent_aux (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (e₁ : S) (he : e₁ ∈ f.range) (he₁ : IsIdempotentElem e₁) (e₂ : R) (he₂ : IsIdempotentElem e₂) (he₁e₂ : e₁ * f e₂ = 0) : ∃ e' : R, IsIdempotentElem e' ∧ f e' = e₁ ∧ e' * e₂ = 0 := by obtain ⟨e₁, rfl⟩ := he cases subsingleton_or_nontrivial R · exact ⟨_, Subsingleton.elim _ _, rfl, Subsingleton.elim _ _⟩ let a := e₁ - e₁ * e₂ have ha : f a = f e₁ := by rw [map_sub, map_mul, he₁e₂, sub_zero] have ha' : a * e₂ = 0 := by rw [sub_mul, mul_assoc, he₂.eq, sub_self] have hx' : a - a ^ 2 ∈ RingHom.ker f := by simp [RingHom.mem_ker, pow_two, ha, he₁.eq] obtain ⟨n, hn⟩ := h _ hx' refine ⟨_, isIdempotentElem_one_sub_one_sub_pow_pow _ _ hn, ?_, ?_⟩ · rcases n with - | n · simp at hn simp only [map_sub, map_one, map_pow, ha, he₁.pow_succ_eq, he₁.one_sub.pow_succ_eq, sub_sub_cancel] · obtain ⟨k, hk⟩ := (Commute.one_left (MulOpposite.op <| 1 - a ^ n)).sub_dvd_pow_sub_pow n apply_fun MulOpposite.unop at hk have : 1 - (1 - a ^ n) ^ n = MulOpposite.unop k * a ^ n := by simpa using hk rw [this, mul_assoc] rcases n with - | n · simp at hn rw [pow_succ, mul_assoc, ha', mul_zero, mul_zero] /-- Orthogonal idempotents lift along nil ideals. -/ theorem exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (e₁ : S) (he : e₁ ∈ f.range) (he₁ : IsIdempotentElem e₁) (e₂ : R) (he₂ : IsIdempotentElem e₂) (he₁e₂ : e₁ * f e₂ = 0) (he₂e₁ : f e₂ * e₁ = 0) : ∃ e' : R, IsIdempotentElem e' ∧ f e' = e₁ ∧ e' * e₂ = 0 ∧ e₂ * e' = 0 := by obtain ⟨e', h₁, rfl, h₂⟩ := exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent_aux f h e₁ he he₁ e₂ he₂ he₁e₂ refine ⟨(1 - e₂) * e', ?_, ?_, ?_, ?_⟩ · rw [IsIdempotentElem, mul_assoc, ← mul_assoc e', mul_sub, mul_one, h₂, sub_zero, h₁.eq] · rw [map_mul, map_sub, map_one, sub_mul, one_mul, he₂e₁, sub_zero] · rw [mul_assoc, h₂, mul_zero] · rw [← mul_assoc, mul_sub, mul_one, he₂.eq, sub_self, zero_mul] /-- Idempotents lift along nil ideals. -/ theorem exists_isIdempotentElem_eq_of_ker_isNilpotent (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (e : S) (he : e ∈ f.range) (he' : IsIdempotentElem e) : ∃ e' : R, IsIdempotentElem e' ∧ f e' = e := by simpa using exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent f h e he he' 0 .zero (by simp) lemma OrthogonalIdempotents.lift_of_isNilpotent_ker_aux (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) {n} {e : Fin n → S} (he : OrthogonalIdempotents e) (he' : ∀ i, e i ∈ f.range) : ∃ e' : Fin n → R, OrthogonalIdempotents e' ∧ f ∘ e' = e := by induction' n with n IH · refine ⟨0, ⟨finZeroElim, finZeroElim⟩, funext finZeroElim⟩ · obtain ⟨e', h₁, h₂⟩ := IH (he.embedding (Fin.succEmb n)) (fun i ↦ he' _) have h₂' (i) : f (e' i) = e i.succ := congr_fun h₂ i obtain ⟨e₀, h₃, h₄, h₅, h₆⟩ := exists_isIdempotentElem_mul_eq_zero_of_ker_isNilpotent f h _ (he' 0) (he.idem 0) _ h₁.isIdempotentElem_sum (by simp [Finset.mul_sum, h₂', he.mul_eq, eq_comm]) (by simp [Finset.sum_mul, h₂', he.mul_eq]) refine ⟨_, (h₁.option _ h₃ h₅ h₆).embedding (finSuccEquiv n).toEmbedding, funext fun i ↦ ?_⟩ obtain ⟨_ | i, rfl⟩ := (finSuccEquiv n).symm.surjective i <;> simp [*] variable {I : Type*} {e : I → R} /-- A family of orthogonal idempotents lift along nil ideals. -/ lemma OrthogonalIdempotents.lift_of_isNilpotent_ker [Finite I] (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) {e : I → S} (he : OrthogonalIdempotents e) (he' : ∀ i, e i ∈ f.range) : ∃ e' : I → R, OrthogonalIdempotents e' ∧ f ∘ e' = e := by cases nonempty_fintype I obtain ⟨e', h₁, h₂⟩ := lift_of_isNilpotent_ker_aux f h (he.embedding (Fintype.equivFin I).symm.toEmbedding) (fun _ ↦ he' _) refine ⟨_, h₁.embedding (Fintype.equivFin I).toEmbedding, by ext x; simpa using congr_fun h₂ (Fintype.equivFin I x)⟩ lemma CompleteOrthogonalIdempotents.pair_iff {x y : R} : CompleteOrthogonalIdempotents ![x, y] ↔ IsIdempotentElem x ∧ y = 1 - x := by rw [pair_iff'ₛ, ← eq_sub_iff_add_eq', ← and_assoc, and_congr_left_iff] rintro rfl simp [mul_sub, sub_mul, IsIdempotentElem, sub_eq_zero, eq_comm] lemma CompleteOrthogonalIdempotents.of_isIdempotentElem {e : R} (he : IsIdempotentElem e) : CompleteOrthogonalIdempotents ![e, 1 - e] := pair_iff.mpr ⟨he, rfl⟩ variable [Fintype I] lemma CompleteOrthogonalIdempotents.option (he : OrthogonalIdempotents e) : CompleteOrthogonalIdempotents (Option.elim · (1 - ∑ i, e i) e) where __ := he.option _ he.isIdempotentElem_sum.one_sub (by simp [sub_mul, he.isIdempotentElem_sum.eq]) (by simp [mul_sub, he.isIdempotentElem_sum.eq]) complete := by rw [Fintype.sum_option] exact sub_add_cancel _ _ lemma CompleteOrthogonalIdempotents.lift_of_isNilpotent_ker_aux (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) {n} {e : Fin n → S} (he : CompleteOrthogonalIdempotents e) (he' : ∀ i, e i ∈ f.range) : ∃ e' : Fin n → R, CompleteOrthogonalIdempotents e' ∧ f ∘ e' = e := by cases subsingleton_or_nontrivial R · choose e' he' using he' exact ⟨e', .of_subsingleton, funext he'⟩ cases subsingleton_or_nontrivial S · obtain ⟨n, hn⟩ := h 1 (Subsingleton.elim _ _) simp at hn rcases n with - | n · simpa using he.complete obtain ⟨e', h₁, h₂⟩ := OrthogonalIdempotents.lift_of_isNilpotent_ker f h he.1 he' refine ⟨_, (equiv (finSuccEquiv n)).mpr (CompleteOrthogonalIdempotents.option (h₁.embedding (Fin.succEmb _))), funext fun i ↦ ?_⟩ have (i : _) : f (e' i) = e i := congr_fun h₂ i cases i using Fin.cases with | zero => simp [this, Fin.sum_univ_succ, ← he.complete] | succ i => simp [this] /-- A system of complete orthogonal idempotents lift along nil ideals. -/ lemma CompleteOrthogonalIdempotents.lift_of_isNilpotent_ker (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) {e : I → S} (he : CompleteOrthogonalIdempotents e) (he' : ∀ i, e i ∈ f.range) : ∃ e' : I → R, CompleteOrthogonalIdempotents e' ∧ f ∘ e' = e := by obtain ⟨e', h₁, h₂⟩ := lift_of_isNilpotent_ker_aux f h ((equiv (Fintype.equivFin I).symm).mpr he) (fun _ ↦ he' _) refine ⟨_, ((equiv (Fintype.equivFin I)).mpr h₁), by ext x; simpa using congr_fun h₂ (Fintype.equivFin I x)⟩ theorem eq_of_isNilpotent_sub_of_isIdempotentElem_of_commute {e₁ e₂ : R} (he₁ : IsIdempotentElem e₁) (he₂ : IsIdempotentElem e₂) (H : IsNilpotent (e₁ - e₂)) (H' : Commute e₁ e₂) : e₁ = e₂ := by have : (e₁ - e₂) ^ 3 = (e₁ - e₂) := by simp only [pow_succ, pow_zero, mul_sub, one_mul, sub_mul, he₁.eq, he₂.eq, H'.eq, mul_assoc] simp only [← mul_assoc, he₂.eq] abel obtain ⟨n, hn⟩ := H have : (e₁ - e₂) ^ (2 * n + 1) = (e₁ - e₂) := by clear hn; induction n <;> simp [mul_add, add_assoc, pow_add _ (2 * _) 3, ← pow_succ, *] rwa [pow_succ, two_mul, pow_add, hn, zero_mul, zero_mul, eq_comm, sub_eq_zero] at this theorem CompleteOrthogonalIdempotents.of_ker_isNilpotent_of_isMulCentral (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (he : ∀ i, IsIdempotentElem (e i)) (he' : ∀ i, IsMulCentral (e i)) (he'' : CompleteOrthogonalIdempotents (f ∘ e)) : CompleteOrthogonalIdempotents e := by obtain ⟨e', h₁, h₂⟩ := lift_of_isNilpotent_ker f h he'' (fun _ ↦ ⟨_, rfl⟩) obtain rfl : e = e' := by ext i refine eq_of_isNilpotent_sub_of_isIdempotentElem_of_commute (he _) (h₁.idem _) (h _ ?_) ((he' i).comm _) simpa [RingHom.mem_ker, sub_eq_zero] using congr_fun h₂.symm i exact h₁ end Ring section CommRing variable {R S : Type*} [CommRing R] [Ring S] (f : R →+* S) theorem eq_of_isNilpotent_sub_of_isIdempotentElem {e₁ e₂ : R} (he₁ : IsIdempotentElem e₁) (he₂ : IsIdempotentElem e₂) (H : IsNilpotent (e₁ - e₂)) : e₁ = e₂ := eq_of_isNilpotent_sub_of_isIdempotentElem_of_commute he₁ he₂ H (.all _ _) @[stacks 00J9] theorem existsUnique_isIdempotentElem_eq_of_ker_isNilpotent (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (e : S) (he : e ∈ f.range) (he' : IsIdempotentElem e) : ∃! e' : R, IsIdempotentElem e' ∧ f e' = e := by obtain ⟨e', he₂, rfl⟩ := exists_isIdempotentElem_eq_of_ker_isNilpotent f h e he he' exact ⟨e', ⟨he₂, rfl⟩, fun x ⟨hx, hx'⟩ ↦ eq_of_isNilpotent_sub_of_isIdempotentElem hx he₂ (h _ (by rw [RingHom.mem_ker, map_sub, hx', sub_self]))⟩ /-- A family of orthogonal idempotents induces an surjection `R ≃+* ∏ R ⧸ ⟨1 - eᵢ⟩` -/ lemma OrthogonalIdempotents.surjective_pi {I : Type*} [Finite I] {e : I → R} (he : OrthogonalIdempotents e) : Function.Surjective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {1 - e i})) := by suffices Pairwise fun i j ↦ IsCoprime (Ideal.span {1 - e i}) (Ideal.span {1 - e j}) by intro x obtain ⟨x, rfl⟩ := Ideal.quotientInfToPiQuotient_surj this x obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x exact ⟨x, by ext i; simp [Ideal.quotientInfToPiQuotient]⟩ intros i j hij rw [Ideal.isCoprime_span_singleton_iff] exact ⟨1, e i, by simp [mul_sub, he.ortho hij]⟩ lemma OrthogonalIdempotents.prod_one_sub {I : Type*} {e : I → R} (he : OrthogonalIdempotents e) (s : Finset I) : ∏ i ∈ s, (1 - e i) = 1 - ∑ i ∈ s, e i := by induction s using Finset.cons_induction with | empty => simp | cons a s has ih => simp [ih, sub_mul, mul_sub, he.mul_sum_of_notMem has, sub_sub] variable {I : Type*} [Fintype I] {e : I → R} theorem CompleteOrthogonalIdempotents.of_ker_isNilpotent (h : ∀ x ∈ RingHom.ker f, IsNilpotent x) (he : ∀ i, IsIdempotentElem (e i)) (he' : CompleteOrthogonalIdempotents (f ∘ e)) : CompleteOrthogonalIdempotents e := of_ker_isNilpotent_of_isMulCentral f h he (fun _ ↦ Semigroup.mem_center_iff.mpr (mul_comm · _)) he' lemma CompleteOrthogonalIdempotents.prod_one_sub (he : CompleteOrthogonalIdempotents e) : ∏ i, (1 - e i) = 0 := by rw [he.1.prod_one_sub, he.complete, sub_self] lemma CompleteOrthogonalIdempotents.of_prod_one_sub (he : OrthogonalIdempotents e) (he' : ∏ i, (1 - e i) = 0) : CompleteOrthogonalIdempotents e where __ := he complete := by rwa [he.prod_one_sub, sub_eq_zero, eq_comm] at he' /-- A family of complete orthogonal idempotents induces an isomorphism `R ≃+* ∏ R ⧸ ⟨1 - eᵢ⟩` -/ lemma CompleteOrthogonalIdempotents.bijective_pi (he : CompleteOrthogonalIdempotents e) : Function.Bijective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {1 - e i})) := by classical refine ⟨?_, he.1.surjective_pi⟩ rw [injective_iff_map_eq_zero] intro x hx simp [funext_iff, Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton] at hx suffices ∀ s : Finset I, (∏ i ∈ s, (1 - e i)) * x = x by rw [← this Finset.univ, he.prod_one_sub, zero_mul] refine fun s ↦ Finset.induction_on s (by simp) ?_ intros a s has e' suffices (1 - e a) * x = x by simp [has, mul_assoc, e', this] obtain ⟨c, rfl⟩ := hx a rw [← mul_assoc, (he.idem a).one_sub.eq] lemma CompleteOrthogonalIdempotents.bijective_pi' (he : CompleteOrthogonalIdempotents (1 - e ·)) : Function.Bijective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {e i})) := by obtain ⟨e', rfl, h⟩ : ∃ e' : I → R, (e' = e) ∧ Function.Bijective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {e' i})) := ⟨_, funext (by simp), he.bijective_pi⟩ exact h lemma RingHom.pi_bijective_of_isIdempotentElem (e : I → R) (he : ∀ i, IsIdempotentElem (e i)) (he₁ : ∀ i j, i ≠ j → (1 - e i) * (1 - e j) = 0) (he₂ : ∏ i, e i = 0) : Function.Bijective (Pi.ringHom fun i ↦ Ideal.Quotient.mk (Ideal.span {e i})) := (CompleteOrthogonalIdempotents.of_prod_one_sub ⟨fun i ↦ (he i).one_sub, he₁⟩ (by simpa using he₂)).bijective_pi' lemma RingHom.prod_bijective_of_isIdempotentElem {e f : R} (he : IsIdempotentElem e) (hf : IsIdempotentElem f) (hef₁ : e + f = 1) (hef₂ : e * f = 0) : Function.Bijective ((Ideal.Quotient.mk <| Ideal.span {e}).prod (Ideal.Quotient.mk <| Ideal.span {f})) := by let o (i : Fin 2) : R := match i with | 0 => e | 1 => f change Function.Bijective (piFinTwoEquiv _ ∘ Pi.ringHom (fun i : Fin 2 ↦ Ideal.Quotient.mk (Ideal.span {o i}))) rw [(Equiv.bijective _).of_comp_iff'] apply pi_bijective_of_isIdempotentElem · intro i fin_cases i <;> simpa [o] · intro i j hij fin_cases i <;> fin_cases j <;> simp at hij ⊢ <;> simp [o, mul_comm, hef₂, ← hef₁] · simpa variable (R) in /-- If `e` and `f` are idempotent elements such that `e + f = 1` and `e * f = 0`, `S` is isomorphic as an `R`-algebra to `S ⧸ (e) × S ⧸ (f)`. -/ @[simps! -isSimp apply, simps! apply_fst apply_snd] noncomputable def AlgEquiv.prodQuotientOfIsIdempotentElem {S : Type*} [CommRing S] [Algebra R S] {e f : S} (he : IsIdempotentElem e) (hf : IsIdempotentElem f) (hef₁ : e + f = 1) (hef₂ : e * f = 0) : S ≃ₐ[R] (S ⧸ Ideal.span {e}) × S ⧸ Ideal.span {f} := AlgEquiv.ofBijective ((Ideal.Quotient.mkₐ _ _).prod (Ideal.Quotient.mkₐ _ _)) <| RingHom.prod_bijective_of_isIdempotentElem he hf hef₁ hef₂ end CommRing section corner variable {R : Type*} (e : R) namespace Subsemigroup variable [Semigroup R] /-- The corner associated to an element `e` in a semigroup is the subsemigroup of all elements of the form `e * r * e`. -/ def corner : Subsemigroup R where carrier := Set.range (e * · * e) mul_mem' := by rintro _ _ ⟨a, rfl⟩ ⟨b, rfl⟩; exact ⟨a * e * e * b, by simp_rw [mul_assoc]⟩ variable {e} (idem : IsIdempotentElem e) include idem lemma mem_corner_iff {r : R} : r ∈ corner e ↔ e * r = r ∧ r * e = r := ⟨by rintro ⟨r, rfl⟩; simp_rw [← mul_assoc, idem.eq, mul_assoc, idem.eq, true_and], (⟨r, by simp_rw [·]⟩)⟩ lemma mem_corner_iff_mul_left (hc : IsMulCentral e) {r : R} : r ∈ corner e ↔ e * r = r := by rw [mem_corner_iff idem, and_iff_left_of_imp]; intro; rwa [← hc.comm] lemma mem_corner_iff_mul_right (hc : IsMulCentral e) {r : R} : r ∈ corner e ↔ r * e = r := by rw [mem_corner_iff_mul_left idem hc, hc.comm] lemma mem_corner_iff_mem_range_mul_left (hc : IsMulCentral e) {r : R} : r ∈ corner e ↔ r ∈ Set.range (e * ·) := by simp_rw [corner, mem_mk, Set.mem_range, ← (hc.comm _).eq, ← mul_assoc, idem.eq] lemma mem_corner_iff_mem_range_mul_right (hc : IsMulCentral e) {r : R} : r ∈ corner e ↔ r ∈ Set.range (· * e) := by simp_rw [mem_corner_iff_mem_range_mul_left idem hc, (hc.comm _).eq] /-- The corner associated to an idempotent `e` in a semiring without 1 is the semiring with `e` as 1 consisting of all element of the form `e * r * e`. -/ @[nolint unusedArguments] def _root_.IsIdempotentElem.Corner (_ : IsIdempotentElem e) : Type _ := Subsemigroup.corner e end Subsemigroup /-- The corner associated to an element `e` in a semiring without 1 is the subsemiring without 1 of all elements of the form `e * r * e`. -/ def NonUnitalSubsemiring.corner [NonUnitalSemiring R] : NonUnitalSubsemiring R where __ := Subsemigroup.corner e add_mem' := by rintro _ _ ⟨a, rfl⟩ ⟨b, rfl⟩; exact ⟨a + b, by simp_rw [mul_add, add_mul]⟩ zero_mem' := ⟨0, by simp_rw [mul_zero, zero_mul]⟩ /-- The corner associated to an element `e` in a ring without ` is the subring without 1 of all elements of the form `e * r * e`. -/ def NonUnitalRing.corner [NonUnitalRing R] : NonUnitalSubring R where __ := NonUnitalSubsemiring.corner e neg_mem' := by rintro _ ⟨a, rfl⟩; exact ⟨-a, by simp_rw [mul_neg, neg_mul]⟩ instance [NonUnitalSemiring R] (idem : IsIdempotentElem e) : Semiring idem.Corner where __ : NonUnitalSemiring (NonUnitalSubsemiring.corner e) := inferInstance one := ⟨e, e, by simp_rw [idem.eq]⟩ one_mul r := Subtype.ext ((Subsemigroup.mem_corner_iff idem).mp r.2).1 mul_one r := Subtype.ext ((Subsemigroup.mem_corner_iff idem).mp r.2).2 instance [NonUnitalCommSemiring R] (idem : IsIdempotentElem e) : CommSemiring idem.Corner where __ : NonUnitalCommSemiring (NonUnitalSubsemiring.corner e) := inferInstance __ : Semiring idem.Corner := inferInstance instance [NonUnitalRing R] (idem : IsIdempotentElem e) : Ring idem.Corner where __ : NonUnitalRing (NonUnitalRing.corner e) := inferInstance __ : Semiring idem.Corner := inferInstance instance [NonUnitalCommRing R] (idem : IsIdempotentElem e) : CommRing idem.Corner where __ : NonUnitalCommRing (NonUnitalRing.corner e) := inferInstance __ : Semiring idem.Corner := inferInstance variable {I : Type*} [Fintype I] {e : I → R} /-- A complete orthogonal family of central idempotents in a semiring give rise to a direct product decomposition. -/ def CompleteOrthogonalIdempotents.ringEquivOfIsMulCentral [Semiring R] (he : CompleteOrthogonalIdempotents e) (hc : ∀ i, IsMulCentral (e i)) : R ≃+* Π i, (he.idem i).Corner where toFun r i := ⟨_, r, rfl⟩ invFun r := ∑ i, (r i).1 left_inv r := by simp_rw [((hc _).comm _).eq, mul_assoc, (he.idem _).eq, ← Finset.mul_sum, he.complete, mul_one] right_inv r := funext fun i ↦ Subtype.ext <| by simp_rw [Finset.mul_sum, Finset.sum_mul] rw [Finset.sum_eq_single i _ (by simp at ·)] · have ⟨r', eq⟩ := (r i).2 rw [← eq]; simp_rw [← mul_assoc, (he.idem i).eq, mul_assoc, (he.idem i).eq] · intro j _ ne; have ⟨r', eq⟩ := (r j).2 rw [← eq]; simp_rw [← mul_assoc, he.ortho ne.symm, zero_mul] map_mul' r₁ r₂ := funext fun i ↦ Subtype.ext <| calc e i * (r₁ * r₂) * e i _ = e i * (r₁ * e i * r₂) * e i := by simp_rw [← ((hc i).comm r₁).eq, ← mul_assoc, (he.idem i).eq] _ = e i * r₁ * e i * (e i * r₂ * e i) := by conv in (r₁ * _ * r₂) => rw [← (he.idem i).eq] simp_rw [mul_assoc] map_add' r₁ r₂ := funext fun i ↦ Subtype.ext <| by simpa [mul_add] using add_mul .. /-- A complete orthogonal family of idempotents in a commutative semiring give rise to a direct product decomposition. -/ def CompleteOrthogonalIdempotents.ringEquivOfComm [CommSemiring R] (he : CompleteOrthogonalIdempotents e) : R ≃+* Π i, (he.idem i).Corner := he.ringEquivOfIsMulCentral fun _ ↦ Semigroup.mem_center_iff.mpr fun _ ↦ mul_comm .. @[deprecated (since := "2025-04-14")] alias CompleteOrthogonalIdempotents.mulEquivOfIsMulCentral := CompleteOrthogonalIdempotents.ringEquivOfIsMulCentral @[deprecated (since := "2025-04-14")] alias CompleteOrthogonalIdempotents.mulEquivOfComm := CompleteOrthogonalIdempotents.ringEquivOfComm end corner