source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/AlgebraicGeometry/Cover/Over.lean | import Mathlib.AlgebraicGeometry.Morphisms.UnderlyingMap
import Mathlib.CategoryTheory.Limits.MorphismProperty
/-!
# Covers of schemes over a base
In this file we define the typeclass `Cover.Over`. For a cover `𝒰` of an `S`-scheme `X`,
the datum `𝒰.Over S` contains `S`-scheme structures on the components of `𝒰` and asserts
that the component maps are morphisms of `S`-schemes.
We provide instances of `𝒰.Over S` for standard constructions on covers.
-/
universe v u
noncomputable section
open CategoryTheory Limits
namespace AlgebraicGeometry.Scheme
variable {P : MorphismProperty Scheme.{u}} (S : Scheme.{u})
/-- Bundle an `S`-scheme with `P` into an object of `P.Over ⊤ S`. -/
abbrev asOverProp (X : Scheme.{u}) (S : Scheme.{u}) [X.Over S] (h : P (X ↘ S)) : P.Over ⊤ S :=
⟨X.asOver S, h⟩
/-- Bundle an `S`-morphism of `S`-scheme with `P` into a morphism in `P.Over ⊤ S`. -/
abbrev Hom.asOverProp {X Y : Scheme.{u}} (f : X.Hom Y) (S : Scheme.{u}) [X.Over S] [Y.Over S]
[f.IsOver S] {hX : P (X ↘ S)} {hY : P (Y ↘ S)} : X.asOverProp S hX ⟶ Y.asOverProp S hY :=
⟨f.asOver S, trivial, trivial⟩
/-- A `P`-cover of a scheme `X` over `S` is a cover, where the components are over `S` and the
component maps commute with the structure morphisms. -/
protected class Cover.Over {P : MorphismProperty Scheme.{u}} [P.IsStableUnderBaseChange]
[IsJointlySurjectivePreserving P] {X : Scheme.{u}} [X.Over S]
(𝒰 : X.Cover (precoverage P)) where
over (j : 𝒰.I₀) : (𝒰.X j).Over S := by infer_instance
isOver_map (j : 𝒰.I₀) : (𝒰.f j).IsOver S := by infer_instance
attribute [instance] Cover.Over.over Cover.Over.isOver_map
variable [P.IsStableUnderBaseChange] [IsJointlySurjectivePreserving P]
instance [P.ContainsIdentities] [P.RespectsIso] {X Y : Scheme.{u}} (f : X ⟶ Y) [X.Over S] [Y.Over S]
[f.IsOver S] [IsIso f] : (coverOfIsIso (P := P) f).Over S where
over _ := inferInstanceAs <| X.Over S
isOver_map _ := inferInstanceAs <| f.IsOver S
section
variable {X W : Scheme.{u}} (𝒰 : X.Cover (precoverage P)) (f : W ⟶ X) [W.Over S] [X.Over S]
[𝒰.Over S] [f.IsOver S]
/-- The pullback of a cover of `S`-schemes along a morphism of `S`-schemes. This is not
definitionally equal to `AlgebraicGeometry.Scheme.Cover.pullback₁`, as here we take
the pullback in `Over S`, whose underlying scheme is only isomorphic but not equal to the
pullback in `Scheme`. -/
@[simps]
def Cover.pullbackCoverOver : W.Cover (precoverage P) where
I₀ := 𝒰.I₀
X x := (pullback (f.asOver S) ((𝒰.f x).asOver S)).left
f x := (pullback.fst (f.asOver S) ((𝒰.f x).asOver S)).left
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, fun j ↦ ?_⟩
· obtain ⟨i, hy⟩ := Cover.exists_eq (𝒰.pullback₁ f) x
use i
exact (mem_range_iff_of_surjective ((𝒰.pullback₁ f).f i) _
((PreservesPullback.iso (Over.forget S) (f.asOver S) ((𝒰.f _).asOver S)).inv)
(PreservesPullback.iso_inv_fst _ _ _) x).mp hy
· dsimp only
rw [← Over.forget_map, ← PreservesPullback.iso_hom_fst, P.cancel_left_of_respectsIso]
exact P.pullback_fst _ _ (𝒰.map_prop j)
instance (j : 𝒰.I₀) : ((𝒰.pullbackCoverOver S f).X j).Over S where
hom := (pullback (f.asOver S) ((𝒰.f j).asOver S)).hom
instance : (𝒰.pullbackCoverOver S f).Over S where
isOver_map j := { comp_over := by exact Over.w (pullback.fst (f.asOver S) ((𝒰.f j).asOver S)) }
/-- A variant of `AlgebraicGeometry.Scheme.Cover.pullbackCoverOver` with the arguments in the
fiber products flipped. -/
@[simps]
def Cover.pullbackCoverOver' : W.Cover (precoverage P) where
I₀ := 𝒰.I₀
X x := (pullback ((𝒰.f x).asOver S) (f.asOver S)).left
f x := (pullback.snd ((𝒰.f x).asOver S) (f.asOver S)).left
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, fun j ↦ ?_⟩
· obtain ⟨i, hy⟩ := Cover.exists_eq (𝒰.pullback₂ f) x
use i
exact (mem_range_iff_of_surjective ((𝒰.pullback₂ f).f _) _
((PreservesPullback.iso (Over.forget S) ((𝒰.f _).asOver S) (f.asOver S)).inv)
(PreservesPullback.iso_inv_snd _ _ _) x).mp hy
· dsimp only
rw [← Over.forget_map, ← PreservesPullback.iso_hom_snd, P.cancel_left_of_respectsIso]
exact P.pullback_snd _ _ (𝒰.map_prop j)
instance (j : 𝒰.I₀) : ((𝒰.pullbackCoverOver' S f).X j).Over S where
hom := (pullback ((𝒰.f j).asOver S) (f.asOver S)).hom
instance : (𝒰.pullbackCoverOver' S f).Over S where
isOver_map j := { comp_over := by exact Over.w (pullback.snd ((𝒰.f j).asOver S) (f.asOver S)) }
variable {Q : MorphismProperty Scheme.{u}} [Q.HasOfPostcompProperty Q]
[Q.IsStableUnderBaseChange] [Q.IsStableUnderComposition]
variable (hX : Q (X ↘ S)) (hW : Q (W ↘ S)) (hQ : ∀ j, Q (𝒰.X j ↘ S))
/-- The pullback of a cover of `S`-schemes with `Q` along a morphism of `S`-schemes. This is not
definitionally equal to `AlgebraicGeometry.Scheme.Cover.pullbackCover`, as here we take
the pullback in `Q.Over ⊤ S`, whose underlying scheme is only isomorphic but not equal to the
pullback in `Scheme`. -/
@[simps -isSimp]
def Cover.pullbackCoverOverProp : W.Cover (precoverage P) where
I₀ := 𝒰.I₀
X x := (pullback (f.asOverProp (hX := hW) (hY := hX) S)
((𝒰.f x).asOverProp (hX := hQ x) (hY := hX) S)).left
f x := (pullback.fst (f.asOverProp S) ((𝒰.f x).asOverProp S)).left
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, fun j ↦ ?_⟩
· obtain ⟨i, hy⟩ := Cover.exists_eq (𝒰.pullback₁ f) x
use i
exact (mem_range_iff_of_surjective ((𝒰.pullback₁ f).f i) _
((PreservesPullback.iso (MorphismProperty.Over.forget Q _ _ ⋙ Over.forget S)
(f.asOverProp S) ((𝒰.f _).asOverProp S)).inv)
(PreservesPullback.iso_inv_fst _ _ _) x).mp hy
· dsimp only
rw [← Over.forget_map, MorphismProperty.Comma.toCommaMorphism_eq_hom,
← MorphismProperty.Comma.forget_map, ← Functor.comp_map]
rw [← PreservesPullback.iso_hom_fst, P.cancel_left_of_respectsIso]
exact P.pullback_fst _ _ (𝒰.map_prop j)
instance (j : 𝒰.I₀) : ((𝒰.pullbackCoverOverProp S f hX hW hQ).X j).Over S where
hom := (pullback (f.asOverProp (hX := hW) (hY := hX) S)
((𝒰.f j).asOverProp (hX := hQ j) (hY := hX) S)).hom
instance : (𝒰.pullbackCoverOverProp S f hX hW hQ).Over S where
isOver_map j :=
{ comp_over := by exact (pullback.fst (f.asOverProp S) ((𝒰.f j).asOverProp S)).w }
/-- A variant of `AlgebraicGeometry.Scheme.Cover.pullbackCoverOverProp` with the arguments in the
fiber products flipped. -/
@[simps -isSimp]
def Cover.pullbackCoverOverProp' : W.Cover (precoverage P) where
I₀ := 𝒰.I₀
X x := (pullback ((𝒰.f x).asOverProp (hX := hQ x) (hY := hX) S)
(f.asOverProp (hX := hW) (hY := hX) S)).left
f x := (pullback.snd ((𝒰.f x).asOverProp S) (f.asOverProp S)).left
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, fun j ↦ ?_⟩
· obtain ⟨i, hy⟩ := Cover.exists_eq (𝒰.pullback₂ f) x
use i
exact (mem_range_iff_of_surjective ((𝒰.pullback₂ f).f i) _
((PreservesPullback.iso (MorphismProperty.Over.forget Q _ _ ⋙ Over.forget S)
((𝒰.f _).asOverProp S) (f.asOverProp S)).inv)
(PreservesPullback.iso_inv_snd _ _ _) x).mp hy
· dsimp only
rw [← Over.forget_map, MorphismProperty.Comma.toCommaMorphism_eq_hom,
← MorphismProperty.Comma.forget_map, ← Functor.comp_map]
rw [← PreservesPullback.iso_hom_snd, P.cancel_left_of_respectsIso]
exact P.pullback_snd _ _ (𝒰.map_prop j)
instance (j : 𝒰.I₀) : ((𝒰.pullbackCoverOverProp' S f hX hW hQ).X j).Over S where
hom := (pullback ((𝒰.f j).asOverProp (hX := hQ j) (hY := hX) S)
(f.asOverProp (hX := hW) (hY := hX) S)).hom
instance : (𝒰.pullbackCoverOverProp' S f hX hW hQ).Over S where
isOver_map j :=
{ comp_over := by exact (pullback.snd ((𝒰.f j).asOverProp S) (f.asOverProp S)).w }
end
variable [P.IsStableUnderComposition]
variable {X : Scheme.{u}} (𝒰 : X.Cover (precoverage P)) (𝒱 : ∀ x, (𝒰.X x).Cover (precoverage P))
[X.Over S] [𝒰.Over S] [∀ x, (𝒱 x).Over S]
instance (j : (𝒰.bind 𝒱).I₀) : ((𝒰.bind 𝒱).X j).Over S :=
inferInstanceAs <| ((𝒱 j.1).X j.2).Over S
instance {X : Scheme.{u}} (𝒰 : X.Cover (precoverage P)) (𝒱 : ∀ x, (𝒰.X x).Cover (precoverage P))
[X.Over S] [𝒰.Over S] [∀ x, (𝒱 x).Over S] : Cover.Over S (𝒰.bind 𝒱) where
over := fun ⟨i, j⟩ ↦ inferInstanceAs <| ((𝒱 i).X j).Over S
isOver_map := fun ⟨i, j⟩ ↦ { comp_over := by simp }
end AlgebraicGeometry.Scheme |
.lake/packages/mathlib/Mathlib/AlgebraicGeometry/Cover/Open.lean | import Mathlib.AlgebraicGeometry.Cover.MorphismProperty
/-!
# Open covers of schemes
This file provides the basic API for open covers of schemes.
## Main definition
- `AlgebraicGeometry.Scheme.OpenCover`: The type of open covers of a scheme `X`,
consisting of a family of open immersions into `X`,
and for each `x : X` an open immersion (indexed by `f x`) that covers `x`.
- `AlgebraicGeometry.Scheme.affineCover`: `X.affineCover` is a choice of an affine cover of `X`.
- `AlgebraicGeometry.Scheme.AffineOpenCover`: The type of affine open covers of a scheme `X`.
-/
noncomputable section
open TopologicalSpace CategoryTheory Opposite CategoryTheory.Limits
universe v v₁ v₂ u
namespace AlgebraicGeometry
namespace Scheme
instance : MorphismProperty.HasPullbacks IsOpenImmersion where
hasPullback _ _ := inferInstance
/-- An open cover of a scheme `X` is a cover where all component maps are open immersions. -/
abbrev OpenCover (X : Scheme.{u}) : Type _ := Cover.{v} (precoverage @IsOpenImmersion) X
variable {X Y Z : Scheme.{u}} (𝒰 : OpenCover X) (f : X ⟶ Z) (g : Y ⟶ Z)
variable [∀ x, HasPullback (𝒰.f x ≫ f) g]
instance (i : 𝒰.I₀) : IsOpenImmersion (𝒰.f i) := 𝒰.map_prop i
/-- The affine cover of a scheme. -/
def affineCover (X : Scheme.{u}) : OpenCover X where
I₀ := X
X x := Spec (X.local_affine x).choose_spec.choose
f x :=
⟨(X.local_affine x).choose_spec.choose_spec.some.inv ≫ X.toLocallyRingedSpace.ofRestrict _⟩
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, inferInstance⟩
use x
simp only [LocallyRingedSpace.comp_toShHom, SheafedSpace.comp_base, TopCat.hom_comp,
ContinuousMap.coe_comp]
rw [Set.range_comp, Set.range_eq_univ.mpr, Set.image_univ]
· erw [Subtype.range_coe_subtype]
exact (X.local_affine x).choose.2
rw [← TopCat.epi_iff_surjective]
change Epi ((SheafedSpace.forget _).map (LocallyRingedSpace.forgetToSheafedSpace.map _))
infer_instance
instance : Inhabited X.OpenCover :=
⟨X.affineCover⟩
theorem OpenCover.iSup_opensRange {X : Scheme.{u}} (𝒰 : X.OpenCover) :
⨆ i, (𝒰.f i).opensRange = ⊤ :=
Opens.ext <| by rw [Opens.coe_iSup]; exact 𝒰.iUnion_range
/-- The ranges of the maps in a scheme-theoretic open cover are a topological open cover. -/
lemma OpenCover.isOpenCover_opensRange {X : Scheme.{u}} (𝒰 : X.OpenCover) :
IsOpenCover fun i ↦ (𝒰.f i).opensRange :=
.mk 𝒰.iSup_opensRange
/-- Every open cover of a quasi-compact scheme can be refined into a finite subcover.
-/
@[simps! X f]
def OpenCover.finiteSubcover {X : Scheme.{u}} (𝒰 : OpenCover X) [H : CompactSpace X] :
OpenCover X := by
have :=
@CompactSpace.elim_nhds_subcover _ _ H (fun x : X => Set.range (𝒰.f (𝒰.idx x)))
fun x => (IsOpenImmersion.isOpen_range (𝒰.f (𝒰.idx x))).mem_nhds (𝒰.covers x)
let t := this.choose
have h : ∀ x : X, ∃ y : t, x ∈ Set.range (𝒰.f (𝒰.idx y)) := by
intro x
have h' : x ∈ (⊤ : Set X) := trivial
rw [← Classical.choose_spec this, Set.mem_iUnion] at h'
rcases h' with ⟨y, _, ⟨hy, rfl⟩, hy'⟩
exact ⟨⟨y, hy⟩, hy'⟩
exact
{ I₀ := t
X := fun x => 𝒰.X (𝒰.idx x.1)
f := fun x => 𝒰.f (𝒰.idx x.1)
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
exact ⟨h, inferInstance⟩ }
instance [H : CompactSpace X] : Fintype 𝒰.finiteSubcover.I₀ := by
delta OpenCover.finiteSubcover; infer_instance
theorem OpenCover.compactSpace {X : Scheme.{u}} (𝒰 : X.OpenCover) [Finite 𝒰.I₀]
[H : ∀ i, CompactSpace (𝒰.X i)] : CompactSpace X := by
cases nonempty_fintype 𝒰.I₀
rw [← isCompact_univ_iff, ← 𝒰.iUnion_range]
apply isCompact_iUnion
intro i
rw [isCompact_iff_compactSpace]
exact
@Homeomorph.compactSpace _ _ _ _ (H i)
(TopCat.homeoOfIso
(asIso
(IsOpenImmersion.isoOfRangeEq (𝒰.f i)
(X.ofRestrict (Opens.isOpenEmbedding ⟨_, (𝒰.map_prop i).base_open.isOpen_range⟩))
Subtype.range_coe.symm).hom.base))
/--
An affine open cover of `X` consists of a family of open immersions into `X` from
spectra of rings.
-/
abbrev AffineOpenCover (X : Scheme.{u}) : Type _ :=
AffineCover.{v} @IsOpenImmersion X
namespace AffineOpenCover
instance {X : Scheme.{u}} (𝒰 : X.AffineOpenCover) (j : 𝒰.I₀) : IsOpenImmersion (𝒰.f j) :=
𝒰.map_prop j
/-- The open cover associated to an affine open cover. -/
@[simps! I₀ X f]
def openCover {X : Scheme.{u}} (𝒰 : X.AffineOpenCover) : X.OpenCover :=
AffineCover.cover 𝒰
end AffineOpenCover
/-- A choice of an affine open cover of a scheme. -/
@[simps]
def affineOpenCover (X : Scheme.{u}) : X.AffineOpenCover where
X := _
I₀ := X.affineCover.I₀
f := X.affineCover.f
idx x := (X.affineCover.exists_eq x).choose
covers x := (X.affineCover.exists_eq x).choose_spec
@[simp]
lemma openCover_affineOpenCover (X : Scheme.{u}) : X.affineOpenCover.openCover = X.affineCover :=
rfl
/-- Given any open cover `𝓤`, this is an affine open cover which refines it.
The morphism in the category of open covers which proves that this is indeed a refinement, see
`AlgebraicGeometry.Scheme.OpenCover.fromAffineRefinement`.
-/
def OpenCover.affineRefinement {X : Scheme.{u}} (𝓤 : X.OpenCover) : X.AffineOpenCover where
X := _
I₀ := (𝓤.bind fun j => (𝓤.X j).affineCover).I₀
f := (𝓤.bind fun j => (𝓤.X j).affineCover).f
idx := Cover.idx (𝓤.bind fun j => (𝓤.X j).affineCover)
covers := Cover.covers (𝓤.bind fun j => (𝓤.X j).affineCover)
/-- The pullback of the affine refinement is the pullback of the affine cover. -/
def OpenCover.pullbackCoverAffineRefinementObjIso (f : X ⟶ Y) (𝒰 : Y.OpenCover) (i) :
(𝒰.affineRefinement.openCover.pullback₁ f).X i ≅
((𝒰.X i.1).affineCover.pullback₁ (𝒰.pullbackHom f i.1)).X i.2 :=
pullbackSymmetry _ _ ≪≫ (pullbackRightPullbackFstIso _ _ _).symm ≪≫
pullbackSymmetry _ _ ≪≫ asIso (pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _)
(by simp [Cover.pullbackHom]) (by simp))
@[reassoc]
lemma OpenCover.pullbackCoverAffineRefinementObjIso_inv_map (f : X ⟶ Y) (𝒰 : Y.OpenCover) (i) :
(𝒰.pullbackCoverAffineRefinementObjIso f i).inv ≫
(𝒰.affineRefinement.openCover.pullback₁ f).f i =
((𝒰.X i.1).affineCover.pullback₁ (𝒰.pullbackHom f i.1)).f i.2 ≫
(𝒰.pullback₁ f).f i.1 := by
simp only [Precoverage.ZeroHypercover.pullback₁_toPreZeroHypercover,
PreZeroHypercover.pullback₁_X, AffineOpenCover.openCover_X, AffineOpenCover.openCover_f,
pullbackCoverAffineRefinementObjIso, Iso.trans_inv, asIso_inv, Iso.symm_inv, Category.assoc,
PreZeroHypercover.pullback₁_f, pullbackSymmetry_inv_comp_fst, IsIso.inv_comp_eq,
limit.lift_π_assoc, PullbackCone.mk_pt, cospan_left, PullbackCone.mk_π_app,
pullbackSymmetry_hom_comp_fst]
convert pullbackSymmetry_inv_comp_snd_assoc
((𝒰.X i.1).affineCover.f i.2) (pullback.fst _ _) _ using 2
exact pullbackRightPullbackFstIso_hom_snd _ _ _
@[reassoc]
lemma OpenCover.pullbackCoverAffineRefinementObjIso_inv_pullbackHom
(f : X ⟶ Y) (𝒰 : Y.OpenCover) (i) :
(𝒰.pullbackCoverAffineRefinementObjIso f i).inv ≫
𝒰.affineRefinement.openCover.pullbackHom f i =
(𝒰.X i.1).affineCover.pullbackHom (𝒰.pullbackHom f i.1) i.2 := by
simp only [Precoverage.ZeroHypercover.pullback₁_toPreZeroHypercover,
PreZeroHypercover.pullback₁_X, Cover.pullbackHom, AffineOpenCover.openCover_X,
AffineOpenCover.openCover_f, pullbackCoverAffineRefinementObjIso, Iso.trans_inv, asIso_inv,
Iso.symm_inv, Category.assoc, pullbackSymmetry_inv_comp_snd, IsIso.inv_comp_eq, limit.lift_π,
PullbackCone.mk_pt, PullbackCone.mk_π_app, Category.comp_id]
convert pullbackSymmetry_inv_comp_fst ((𝒰.X i.1).affineCover.f i.2) (pullback.fst _ _)
exact pullbackRightPullbackFstIso_hom_fst _ _ _
/-- A family of elements spanning the unit ideal of `R` gives a affine open cover of `Spec R`. -/
@[simps]
noncomputable
def affineOpenCoverOfSpanRangeEqTop {R : CommRingCat} {ι : Type*} (s : ι → R)
(hs : Ideal.span (Set.range s) = ⊤) : (Spec R).AffineOpenCover where
I₀ := ι
X i := .of (Localization.Away (s i))
f i := Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away (s i))))
idx x := by
have : ∃ i, s i ∉ x.asIdeal := by
by_contra! h; apply x.2.ne_top; rwa [← top_le_iff, ← hs, Ideal.span_le, Set.range_subset_iff]
exact this.choose
covers x := by
generalize_proofs H
let i := H.choose
have := PrimeSpectrum.localization_away_comap_range (Localization.Away (s i)) (s i)
exact (eq_iff_iff.mp congr(x ∈ $this)).mpr H.choose_spec
/-- Given any open cover `𝓤`, this is an affine open cover which refines it. -/
def OpenCover.fromAffineRefinement {X : Scheme.{u}} (𝓤 : X.OpenCover) :
𝓤.affineRefinement.openCover ⟶ 𝓤 where
idx j := j.fst
app j := (𝓤.X j.fst).affineCover.f _
/-- If two global sections agree after restriction to each member of an open cover, then
they agree globally. -/
lemma OpenCover.ext_elem {X : Scheme.{u}} {U : X.Opens} (f g : Γ(X, U)) (𝒰 : X.OpenCover)
(h : ∀ i : 𝒰.I₀, (𝒰.f i).app U f = (𝒰.f i).app U g) : f = g := by
fapply TopCat.Sheaf.eq_of_locally_eq' X.sheaf
(fun i ↦ (𝒰.f (𝒰.idx i)).opensRange ⊓ U) _ (fun _ ↦ homOfLE inf_le_right)
· intro x hx
simp only [Opens.iSup_mk, Opens.carrier_eq_coe, Opens.coe_inf, Hom.coe_opensRange, Opens.coe_mk,
Set.mem_iUnion, Set.mem_inter_iff, Set.mem_range, SetLike.mem_coe, exists_and_right]
refine ⟨?_, hx⟩
simpa using ⟨_, 𝒰.covers x⟩
· intro x
replace h := h (𝒰.idx x)
rw [← IsOpenImmersion.map_ΓIso_inv] at h
exact (IsOpenImmersion.ΓIso (𝒰.f (𝒰.idx x)) U).commRingCatIsoToRingEquiv.symm.injective h
/-- If the restriction of a global section to each member of an open cover is zero, then it is
globally zero. -/
lemma zero_of_zero_cover {X : Scheme.{u}} {U : X.Opens} (s : Γ(X, U)) (𝒰 : X.OpenCover)
(h : ∀ i : 𝒰.I₀, (𝒰.f i).app U s = 0) : s = 0 :=
𝒰.ext_elem s 0 (fun i ↦ by rw [map_zero]; exact h i)
/-- If a global section is nilpotent on each member of a finite open cover, then `f` is
nilpotent. -/
lemma isNilpotent_of_isNilpotent_cover {X : Scheme.{u}} {U : X.Opens} (s : Γ(X, U))
(𝒰 : X.OpenCover) [Finite 𝒰.I₀] (h : ∀ i : 𝒰.I₀, IsNilpotent ((𝒰.f i).app U s)) :
IsNilpotent s := by
choose fn hfn using h
have : Fintype 𝒰.I₀ := Fintype.ofFinite 𝒰.I₀
/- the maximum of all `fn i` (exists, because `𝒰.I₀` is finite) -/
let N : ℕ := Finset.sup Finset.univ fn
have hfnleN (i : 𝒰.I₀) : fn i ≤ N := Finset.le_sup (Finset.mem_univ i)
use N
apply zero_of_zero_cover (𝒰 := 𝒰)
on_goal 1 => intro i; simp only [map_pow]
-- This closes both remaining goals at once.
exact pow_eq_zero_of_le (hfnleN i) (hfn i)
section deprecated
/-- The basic open sets form an affine open cover of `Spec R`. -/
def affineBasisCoverOfAffine (R : CommRingCat.{u}) : OpenCover (Spec R) where
I₀ := R
X r := Spec <| .of <| Localization.Away r
f r := Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away r)))
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ⟨1, ?_⟩, AlgebraicGeometry.Scheme.isOpenImmersion_SpecMap_localizationAway⟩
rw [Set.range_eq_univ.mpr ((TopCat.epi_iff_surjective _).mp _)]
· exact trivial
· infer_instance
/-- We may bind the basic open sets of an open affine cover to form an affine cover that is also
a basis. -/
def affineBasisCover (X : Scheme.{u}) : OpenCover X :=
X.affineCover.bind fun _ => affineBasisCoverOfAffine _
/-- The coordinate ring of a component in the `affine_basis_cover`. -/
def affineBasisCoverRing (X : Scheme.{u}) (i : X.affineBasisCover.I₀) : CommRingCat :=
CommRingCat.of <| @Localization.Away (X.local_affine i.1).choose_spec.choose _ i.2
theorem affineBasisCover_obj (X : Scheme.{u}) (i : X.affineBasisCover.I₀) :
X.affineBasisCover.X i = Spec (X.affineBasisCoverRing i) :=
rfl
theorem affineBasisCover_map_range (X : Scheme.{u}) (x : X)
(r : (X.local_affine x).choose_spec.choose) :
Set.range (X.affineBasisCover.f ⟨x, r⟩) =
(X.affineCover.f x) '' (PrimeSpectrum.basicOpen r).1 := by
simp only [affineBasisCover, Precoverage.ZeroHypercover.bind_toPreZeroHypercover, Set.range_comp,
PreZeroHypercover.bind_f, Hom.comp_base, TopCat.hom_comp, ContinuousMap.coe_comp]
congr
exact (PrimeSpectrum.localization_away_comap_range (Localization.Away r) r :)
theorem affineBasisCover_is_basis (X : Scheme.{u}) :
TopologicalSpace.IsTopologicalBasis
{x : Set X |
∃ a : X.affineBasisCover.I₀, x = Set.range (X.affineBasisCover.f a)} := by
apply TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds
· rintro _ ⟨a, rfl⟩
exact IsOpenImmersion.isOpen_range (X.affineBasisCover.f a)
· rintro a U haU hU
rcases X.affineCover.covers a with ⟨x, e⟩
let U' := (X.affineCover.f (X.affineCover.idx a)) ⁻¹' U
have hxU' : x ∈ U' := by rw [← e] at haU; exact haU
rcases PrimeSpectrum.isBasis_basic_opens.exists_subset_of_mem_open hxU'
((X.affineCover.f (X.affineCover.idx a)).continuous.isOpen_preimage _
hU) with
⟨_, ⟨_, ⟨s, rfl⟩, rfl⟩, hxV, hVU⟩
refine ⟨_, ⟨⟨_, s⟩, rfl⟩, ?_, ?_⟩ <;> rw [affineBasisCover_map_range]
· exact ⟨x, hxV, e⟩
· rw [Set.image_subset_iff]; exact hVU
end deprecated
end Scheme
end AlgebraicGeometry |
.lake/packages/mathlib/Mathlib/AlgebraicGeometry/Cover/MorphismProperty.lean | import Mathlib.AlgebraicGeometry.Sites.MorphismProperty
import Mathlib.CategoryTheory.MorphismProperty.Limits
/-!
# Covers of schemes
This file provides the basic API for covers of schemes. A cover of a scheme `X` with respect to
a morphism property `P` is a jointly surjective indexed family of scheme morphisms with
target `X` all satisfying `P`.
## Implementation details
The definition on the pullback of a cover along a morphism depends on results that
are developed later in the import tree. Hence in this file, they have additional assumptions
that will be automatically satisfied in later files. The motivation here is that we already
know that these assumptions are satisfied for open immersions and hence the cover API for open
immersions can be used to deduce these assumptions in the general case.
-/
noncomputable section
open TopologicalSpace CategoryTheory Opposite CategoryTheory.Limits
universe v v₁ v₂ u
namespace AlgebraicGeometry
namespace Scheme
variable (K : Precoverage Scheme.{u})
/-- A coverage `K` on `Scheme` is called jointly surjective if every covering family in `K`
is jointly surjective. -/
class JointlySurjective (K : Precoverage Scheme.{u}) : Prop where
exists_eq {X : Scheme.{u}} (S : Presieve X) (hS : S ∈ K X) (x : X) :
∃ (Y : Scheme.{u}) (g : Y ⟶ X), S g ∧ x ∈ Set.range g
/-- A cover of `X` in the coverage `K` is a `0`-hypercover for `K`. -/
abbrev Cover (K : Precoverage Scheme.{u}) := Precoverage.ZeroHypercover.{v} K
variable {K}
variable {X Y Z : Scheme.{u}} (𝒰 : X.Cover K) (f : X ⟶ Z) (g : Y ⟶ Z)
variable [∀ x, HasPullback (𝒰.f x ≫ f) g]
lemma Cover.exists_eq [JointlySurjective K] (𝒰 : X.Cover K) (x : X) :
∃ i y, 𝒰.f i y = x := by
obtain ⟨Y, g, ⟨i⟩, y, hy⟩ := JointlySurjective.exists_eq 𝒰.presieve₀ 𝒰.mem₀ x
use i, y
/-- A choice of an index `i` such that `x` is in the range of `𝒰.f i`. -/
def Cover.idx [JointlySurjective K] (𝒰 : X.Cover K) (x : X) : 𝒰.I₀ :=
(𝒰.exists_eq x).choose
lemma Cover.covers [JointlySurjective K] (𝒰 : X.Cover K) (x : X) :
x ∈ Set.range (𝒰.f (𝒰.idx x)) :=
(𝒰.exists_eq x).choose_spec
theorem Cover.iUnion_range [JointlySurjective K] {X : Scheme.{u}} (𝒰 : X.Cover K) :
⋃ i, Set.range (𝒰.f i) = Set.univ := by
rw [Set.eq_univ_iff_forall]
intro x
rw [Set.mem_iUnion]
exact 𝒰.exists_eq x
instance Cover.nonempty_of_nonempty [JointlySurjective K] [Nonempty X] (𝒰 : X.Cover K) :
Nonempty 𝒰.I₀ := by
obtain ⟨i, _⟩ := 𝒰.exists_eq ‹Nonempty X›.some
use i
section MorphismProperty
variable {P Q : MorphismProperty Scheme.{u}}
lemma presieve₀_mem_precoverage_iff (E : PreZeroHypercover X) :
E.presieve₀ ∈ precoverage P X ↔ (∀ x, ∃ i, x ∈ Set.range (E.f i)) ∧ ∀ i, P (E.f i) := by
simp
@[grind ←]
lemma Cover.map_prop (𝒰 : X.Cover (precoverage P)) (i : 𝒰.I₀) : P (𝒰.f i) :=
𝒰.mem₀.2 ⟨i⟩
/-- Given a family of schemes with morphisms to `X` satisfying `P` that jointly
cover `X`, `Cover.mkOfCovers` is an associated `P`-cover of `X`. -/
@[simps!]
def Cover.mkOfCovers (J : Type*) (obj : J → Scheme.{u}) (map : (j : J) → obj j ⟶ X)
(covers : ∀ x, ∃ j y, map j y = x)
(map_prop : ∀ j, P (map j) := by infer_instance) : X.Cover (precoverage P) where
I₀ := J
X := obj
f := map
mem₀ := by
simp_rw [presieve₀_mem_precoverage_iff, Set.mem_range]
grind
/-- An isomorphism `X ⟶ Y` is a `P`-cover of `Y`. -/
@[simps! I₀ X f]
def coverOfIsIso [P.ContainsIdentities] [P.RespectsIso] {X Y : Scheme.{u}} (f : X ⟶ Y)
[IsIso f] : Cover.{v} (precoverage P) Y :=
.mkOfCovers PUnit (fun _ ↦ X)
(fun _ ↦ f)
(fun x ↦ ⟨⟨⟩, inv f x, by simp [← Hom.comp_apply]⟩)
(fun _ ↦ P.of_isIso f)
instance : JointlySurjective (precoverage P) where
exists_eq {X} R := fun ⟨hR, _⟩ x ↦ by
rw [jointlySurjectivePrecoverage, Presieve.mem_comap_jointlySurjectivePrecoverage_iff] at hR
obtain ⟨Y, g, hg, heq⟩ := hR x
use Y, g, hg
exact heq
/-- Turn a `K`-cover into a `Q`-cover by showing that the components satisfy `Q`. -/
def Cover.changeProp [JointlySurjective K] (𝒰 : X.Cover K) (h : ∀ j, Q (𝒰.f j)) :
X.Cover (precoverage Q) where
I₀ := 𝒰.I₀
X := 𝒰.X
f := 𝒰.f
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
exact ⟨𝒰.exists_eq, h⟩
/-- We construct a cover from another, by providing the needed fields and showing that the
provided fields are isomorphic with the original cover. -/
@[simps I₀ X f]
def Cover.copy [P.RespectsIso] {X : Scheme.{u}} (𝒰 : X.Cover (precoverage P))
(J : Type*) (obj : J → Scheme)
(map : ∀ i, obj i ⟶ X) (e₁ : J ≃ 𝒰.I₀) (e₂ : ∀ i, obj i ≅ 𝒰.X (e₁ i))
(h : ∀ i, map i = (e₂ i).hom ≫ 𝒰.f (e₁ i)) : X.Cover (precoverage P) where
I₀ := J
X := obj
f := map
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, ?_⟩
· obtain ⟨i, y, rfl⟩ := 𝒰.exists_eq x
obtain ⟨i, rfl⟩ := e₁.surjective i
use i, (e₂ i).inv y
simp [h]
· simp_rw [h, MorphismProperty.cancel_left_of_respectsIso]
intro i
exact 𝒰.map_prop _
/-- The pushforward of a cover along an isomorphism. -/
@[simps! I₀ X f]
def Cover.pushforwardIso [P.RespectsIso] [P.ContainsIdentities] [P.IsStableUnderComposition]
{X Y : Scheme.{u}} (𝒰 : Cover.{v} (precoverage P) X) (f : X ⟶ Y) [IsIso f] :
Cover.{v} (precoverage P) Y :=
Cover.copy ((coverOfIsIso.{v, u} f).bind fun _ => 𝒰) 𝒰.I₀ _ _
((Equiv.punitProd _).symm.trans (Equiv.sigmaEquivProd PUnit 𝒰.I₀).symm) (fun _ => Iso.refl _)
fun _ => (Category.id_comp _).symm
/-- Adding map satisfying `P` into a cover gives another cover. -/
@[simps toPreZeroHypercover]
nonrec def Cover.add {X Y : Scheme.{u}} (𝒰 : X.Cover (precoverage P)) (f : Y ⟶ X)
(hf : P f := by infer_instance) : X.Cover (precoverage P) where
__ := 𝒰.toPreZeroHypercover.add f
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ⟨some <| 𝒰.idx x, 𝒰.covers x⟩, ?_⟩
rintro (i|i) <;> simp [hf, 𝒰.map_prop]
@[deprecated (since := "2025-10-02")]
alias Cover.pullbackCover := Precoverage.ZeroHypercover.pullback₁
/-- The family of morphisms from the pullback cover to the original cover. -/
def Cover.pullbackHom [P.IsStableUnderBaseChange] [IsJointlySurjectivePreserving P]
{X W : Scheme.{u}} (𝒰 : X.Cover (precoverage P)) (f : W ⟶ X) (i) [∀ x, HasPullback f (𝒰.f x)] :
(𝒰.pullback₁ f).X i ⟶ 𝒰.X i :=
pullback.snd f (𝒰.f i)
@[reassoc (attr := simp)]
lemma Cover.pullbackHom_map [P.IsStableUnderBaseChange] [IsJointlySurjectivePreserving P]
{X W : Scheme.{u}} (𝒰 : X.Cover (precoverage P)) (f : W ⟶ X)
[∀ (x : 𝒰.I₀), HasPullback f (𝒰.f x)] (i) :
𝒰.pullbackHom f i ≫ 𝒰.f i = (𝒰.pullback₁ f).f i ≫ f := pullback.condition.symm
@[deprecated (since := "2025-10-02")]
alias Cover.pullbackCover' := Precoverage.ZeroHypercover.pullback₂
/--
An affine cover of `X` consists of a jointly surjective family of maps into `X` from
spectra of rings.
Note: The `map_prop` field is equipped with a default argument `by infer_instance`. In general
this causes worse error messages, but in practice `P` is mostly defined via `class`.
-/
structure AffineCover (P : MorphismProperty Scheme.{u}) (S : Scheme.{u}) where
/-- index set of an affine cover of a scheme `S` -/
I₀ : Type v
/-- the ring associated to a component of an affine cover -/
X (j : I₀) : CommRingCat.{u}
/-- the components map to `S` -/
f (j : I₀) : Spec (X j) ⟶ S
/-- given a point of `x : S`, `idx x` is the index of the component which contains `x` -/
idx (x : S) : I₀
/-- the components cover `S` -/
covers (x : S) : x ∈ Set.range (f (idx x))
/-- the component maps satisfy `P` -/
map_prop (j : I₀) : P (f j) := by infer_instance
@[deprecated (since := "2025-09-19")]
alias AffineCover.J := AffineCover.I₀
@[deprecated (since := "2025-09-19")]
alias AffineCover.obj := AffineCover.X
@[deprecated (since := "2025-09-19")]
alias AffineCover.map := AffineCover.f
/-- The cover associated to an affine cover. -/
@[simps]
def AffineCover.cover {X : Scheme.{u}} (𝒰 : X.AffineCover P) :
X.Cover (precoverage P) where
I₀ := 𝒰.I₀
X j := Spec (𝒰.X j)
f := 𝒰.f
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, 𝒰.map_prop⟩
obtain ⟨y, hy⟩ := 𝒰.covers x
use 𝒰.idx x, y
/-- Any `v`-cover `𝒰` induces a `u`-cover indexed by the points of `X`. -/
@[simps!]
def Cover.ulift (𝒰 : Cover.{v} (precoverage P) X) : Cover.{u} (precoverage P) X where
I₀ := X
X x := 𝒰.X (𝒰.idx x)
f x := 𝒰.f _
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, fun i ↦ 𝒰.map_prop _⟩
use x, (𝒰.exists_eq x).choose_spec.choose, (𝒰.exists_eq x).choose_spec.choose_spec
instance : Precoverage.Small.{u} (precoverage P) where
zeroHypercoverSmall {S} 𝒰 := ⟨S, Cover.idx 𝒰, (Cover.ulift 𝒰).mem₀⟩
section category
-- TODO: replace this by `ZeroHypercover.Hom`
/--
A morphism between covers `𝒰 ⟶ 𝒱` indicates that `𝒰` is a refinement of `𝒱`.
Since covers of schemes are indexed, the definition also involves a map on the
indexing types.
-/
@[ext]
structure Cover.Hom {X : Scheme.{u}} (𝒰 𝒱 : Cover.{v} (precoverage P) X) where
/-- The map on indexing types associated to a morphism of covers. -/
idx : 𝒰.I₀ → 𝒱.I₀
/-- The morphism between open subsets associated to a morphism of covers. -/
app (j : 𝒰.I₀) : 𝒰.X j ⟶ 𝒱.X (idx j)
app_prop (j : 𝒰.I₀) : P (app j) := by infer_instance
w (j : 𝒰.I₀) : app j ≫ 𝒱.f _ = 𝒰.f _ := by cat_disch
attribute [reassoc (attr := simp)] Cover.Hom.w
/-- The identity morphism in the category of covers of a scheme. -/
def Cover.Hom.id [P.ContainsIdentities] {X : Scheme.{u}} (𝒰 : Cover.{v} (precoverage P) X) :
𝒰.Hom 𝒰 where
idx j := j
app _ := 𝟙 _
app_prop _ := P.id_mem _
/-- The composition of two morphisms in the category of covers of a scheme. -/
def Cover.Hom.comp [P.IsStableUnderComposition] {X : Scheme.{u}}
{𝒰 𝒱 𝒲 : Cover.{v} (precoverage P) X} (f : 𝒰.Hom 𝒱) (g : 𝒱.Hom 𝒲) : 𝒰.Hom 𝒲 where
idx j := g.idx <| f.idx j
app _ := f.app _ ≫ g.app _
app_prop _ := P.comp_mem _ _ (f.app_prop _) (g.app_prop _)
instance Cover.category [P.IsMultiplicative] {X : Scheme.{u}} :
Category (Cover.{v} (precoverage P) X) where
Hom 𝒰 𝒱 := 𝒰.Hom 𝒱
id := Cover.Hom.id
comp f g := f.comp g
variable [P.IsMultiplicative]
@[simp]
lemma Cover.id_idx_apply {X : Scheme.{u}} (𝒰 : X.Cover (precoverage P)) (j : 𝒰.I₀) :
(𝟙 𝒰 : 𝒰 ⟶ 𝒰).idx j = j := rfl
@[simp]
lemma Cover.id_app {X : Scheme.{u}} (𝒰 : X.Cover (precoverage P)) (j : 𝒰.I₀) :
(𝟙 𝒰 : 𝒰 ⟶ 𝒰).app j = 𝟙 _ := rfl
@[simp]
lemma Cover.comp_idx_apply {X : Scheme.{u}} {𝒰 𝒱 𝒲 : X.Cover (precoverage P)}
(f : 𝒰 ⟶ 𝒱) (g : 𝒱 ⟶ 𝒲) (j : 𝒰.I₀) :
(f ≫ g).idx j = g.idx (f.idx j) := rfl
@[simp]
lemma Cover.comp_app {X : Scheme.{u}} {𝒰 𝒱 𝒲 : X.Cover (precoverage P)}
(f : 𝒰 ⟶ 𝒱) (g : 𝒱 ⟶ 𝒲) (j : 𝒰.I₀) :
(f ≫ g).app j = f.app j ≫ g.app _ := rfl
end category
end MorphismProperty
end Scheme
end AlgebraicGeometry |
.lake/packages/mathlib/Mathlib/AlgebraicGeometry/Cover/Directed.lean | import Mathlib.CategoryTheory.LocallyDirected
import Mathlib.AlgebraicGeometry.PullbackCarrier
import Mathlib.AlgebraicGeometry.Gluing
/-!
# Locally directed covers
A locally directed `P`-cover of a scheme `X` is a cover `𝒰` with an ordering
on the indices and compatible transition maps `𝒰ᵢ ⟶ 𝒰ⱼ` for `i ≤ j` such that
every `x : 𝒰ᵢ ×[X] 𝒰ⱼ` comes from some `𝒰ₖ` for a `k ≤ i` and `k ≤ j`.
Gluing along directed covers is easier, because the intersections `𝒰ᵢ ×[X] 𝒰ⱼ` can
be covered by a subcover of `𝒰`. In particular, if `𝒰` is a Zariski cover,
`X` naturally is the colimit of the `𝒰ᵢ`.
Many natural covers are naturally directed, most importantly the cover of all affine
opens of a scheme.
-/
universe u
noncomputable section
open CategoryTheory Limits
namespace AlgebraicGeometry.Scheme
variable {P : MorphismProperty Scheme.{u}} {X : Scheme.{u}}
namespace Cover
/-- A directed `P`-cover of a scheme `X` is a cover `𝒰` with an ordering
on the indices and compatible transition maps `𝒰ᵢ ⟶ 𝒰ⱼ` for `i ≤ j` such that
every `x : 𝒰ᵢ ×[X] 𝒰ⱼ` comes from some `𝒰ₖ` for a `k ≤ i` and `k ≤ j`. -/
class LocallyDirected (𝒰 : X.Cover (precoverage P)) [Category 𝒰.I₀] where
/-- The transition map `𝒰ᵢ ⟶ 𝒰ⱼ` for `i ≤ j`. -/
trans {i j : 𝒰.I₀} (hij : i ⟶ j) : 𝒰.X i ⟶ 𝒰.X j
trans_id (i : 𝒰.I₀) : trans (𝟙 i) = 𝟙 (𝒰.X i)
trans_comp {i j k : 𝒰.I₀} (hij : i ⟶ j) (hjk : j ⟶ k): trans (hij ≫ hjk) = trans hij ≫ trans hjk
w {i j : 𝒰.I₀} (hij : i ⟶ j) : trans hij ≫ 𝒰.f j = 𝒰.f i := by aesop_cat
directed {i j : 𝒰.I₀} (x : (pullback (𝒰.f i) (𝒰.f j)).carrier) :
∃ (k : 𝒰.I₀) (hki : k ⟶ i) (hkj : k ⟶ j) (y : 𝒰.X k),
pullback.lift (trans hki) (trans hkj) (by simp [w]) y = x
property_trans {i j : 𝒰.I₀} (hij : i ⟶ j) : P (trans hij) := by infer_instance
variable (𝒰 : X.Cover (precoverage P)) [Category 𝒰.I₀] [𝒰.LocallyDirected]
/-- The transition maps of a directed cover. -/
def trans {i j : 𝒰.I₀} (hij : i ⟶ j) : 𝒰.X i ⟶ 𝒰.X j := LocallyDirected.trans hij
@[simp]
lemma trans_map {i j : 𝒰.I₀} (hij : i ⟶ j) : 𝒰.trans hij ≫ 𝒰.f j = 𝒰.f i :=
LocallyDirected.w hij
@[simp]
lemma trans_id (i : 𝒰.I₀) : 𝒰.trans (𝟙 i) = 𝟙 (𝒰.X i) := LocallyDirected.trans_id i
@[simp]
lemma trans_comp {i j k : 𝒰.I₀} (hij : i ⟶ j) (hjk : j ⟶ k) :
𝒰.trans (hij ≫ hjk) = 𝒰.trans hij ≫ 𝒰.trans hjk := LocallyDirected.trans_comp hij hjk
lemma exists_lift_trans_eq {i j : 𝒰.I₀} (x : (pullback (𝒰.f i) (𝒰.f j)).carrier) :
∃ (k : 𝒰.I₀) (hki : k ⟶ i) (hkj : k ⟶ j) (y : 𝒰.X k),
pullback.lift (𝒰.trans hki) (𝒰.trans hkj) (by simp) y = x :=
LocallyDirected.directed x
lemma property_trans {i j : 𝒰.I₀} (hij : i ⟶ j) : P (𝒰.trans hij) :=
LocallyDirected.property_trans hij
/-- If `𝒰` is a directed cover of `X`, this is the cover of `𝒰ᵢ ×[X] 𝒰ⱼ` by `{𝒰ₖ}` where
`k ≤ i` and `k ≤ j`. -/
@[simps f]
def intersectionOfLocallyDirected [P.IsStableUnderBaseChange] [P.HasOfPostcompProperty P]
(i j : 𝒰.I₀) : (pullback (𝒰.f i) (𝒰.f j)).Cover (precoverage P) where
I₀ := Σ (k : 𝒰.I₀), (k ⟶ i) × (k ⟶ j)
X k := 𝒰.X k.1
f k := pullback.lift (𝒰.trans k.2.1) (𝒰.trans k.2.2) (by simp)
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, fun k ↦ ?_⟩
· use ⟨(𝒰.exists_lift_trans_eq x).choose, (𝒰.exists_lift_trans_eq x).choose_spec.choose,
(𝒰.exists_lift_trans_eq x).choose_spec.choose_spec.choose⟩
exact (𝒰.exists_lift_trans_eq x).choose_spec.choose_spec.choose_spec
· apply P.of_postcomp (W' := P) _ (pullback.fst _ _) (P.pullback_fst _ _ (𝒰.map_prop _))
rw [pullback.lift_fst]
exact 𝒰.property_trans _
/-- The canonical diagram induced by a locally directed cover. -/
@[simps]
def functorOfLocallyDirected : 𝒰.I₀ ⥤ Scheme.{u} where
obj := 𝒰.X
map := 𝒰.trans
instance : (𝒰.functorOfLocallyDirected ⋙ Scheme.forget).IsLocallyDirected where
cond {i j k} fi fj xi xj hxij := by
simp only [Functor.comp_obj, Cover.functorOfLocallyDirected_obj, forget_obj, Functor.comp_map,
Cover.functorOfLocallyDirected_map, forget_map] at hxij
have : 𝒰.f i xi = 𝒰.f j xj := by
rw [← 𝒰.trans_map fi, ← 𝒰.trans_map fj, Hom.comp_base, Hom.comp_base,
ConcreteCategory.comp_apply, hxij, ConcreteCategory.comp_apply]
obtain ⟨z, rfl, rfl⟩ := Scheme.Pullback.exists_preimage_pullback xi xj this
obtain ⟨l, gi, gj, y, rfl⟩ := 𝒰.exists_lift_trans_eq z
refine ⟨l, gi, gj, y, ?_, ?_⟩ <;> simp [← Scheme.Hom.comp_apply]
/--
The canonical cocone with point `X` on the functor induced by the locally directed cover `𝒰`.
If `𝒰` is an open cover, this is colimiting (see `OpenCover.isColimitCoconeOfLocallyDirected`).
-/
@[simps]
def coconeOfLocallyDirected : Cocone 𝒰.functorOfLocallyDirected where
pt := X
ι.app := 𝒰.f
section BaseChange
variable [P.IsStableUnderBaseChange] (𝒰 : X.Cover (precoverage P))
[Category 𝒰.I₀] [𝒰.LocallyDirected] {Y : Scheme.{u}} (f : Y ⟶ X)
instance : Category (𝒰.pullback₁ f).I₀ := inferInstanceAs <| Category 𝒰.I₀
instance locallyDirectedPullbackCover : Cover.LocallyDirected (𝒰.pullback₁ f) where
trans {i j} hij := pullback.map f (𝒰.f i) f (𝒰.f j) (𝟙 _) (𝒰.trans hij) (𝟙 _)
(by simp) (by simp)
trans_id i := by simp
trans_comp hij hjk := by simp [pullback.map_comp]
directed {i j} x := by
dsimp at i j x ⊢
let iso : pullback (pullback.fst f (𝒰.f i)) (pullback.fst f (𝒰.f j)) ≅
pullback f (pullback.fst (𝒰.f i) (𝒰.f j) ≫ 𝒰.f i) :=
pullbackRightPullbackFstIso _ _ _ ≪≫ pullback.congrHom pullback.condition rfl ≪≫
pullbackAssoc ..
have (k : 𝒰.I₀) (hki : k ⟶ i) (hkj : k ⟶ j) :
(pullback.lift
(pullback.map f (𝒰.f k) f (𝒰.f i) (𝟙 Y) (𝒰.trans hki) (𝟙 X) (by simp) (by simp))
(pullback.map f (𝒰.f k) f (𝒰.f j) (𝟙 Y) (𝒰.trans hkj) (𝟙 X) (by simp) (by simp))
(by simp)) =
pullback.map _ _ _ _ (𝟙 Y) (pullback.lift (𝒰.trans hki) (𝒰.trans hkj) (by simp)) (𝟙 X)
(by simp) (by simp) ≫ iso.inv := by
apply pullback.hom_ext <;> apply pullback.hom_ext <;> simp [iso]
obtain ⟨k, hki, hkj, yk, hyk⟩ := 𝒰.exists_lift_trans_eq ((iso.hom ≫ pullback.snd _ _) x)
refine ⟨k, hki, hkj, show x ∈ Set.range _ from ?_⟩
rw [this, Scheme.Hom.comp_base, TopCat.coe_comp, Set.range_comp, Pullback.range_map]
use iso.hom x
simp only [Hom.id_base, TopCat.hom_id, ContinuousMap.coe_id, Set.range_id, Set.preimage_univ,
Set.univ_inter, Set.mem_preimage, Set.mem_range, hom_inv_apply, and_true]
exact ⟨yk, hyk⟩
property_trans {i j} hij := by
let iso : pullback f (𝒰.f i) ≅ pullback (pullback.snd f (𝒰.f j)) (𝒰.trans hij) :=
pullback.congrHom rfl (by simp) ≪≫ (pullbackLeftPullbackSndIso _ _ _).symm
rw [← P.cancel_left_of_respectsIso iso.inv]
simp [Iso.trans_inv, Iso.symm_inv, pullback.congrHom_inv,
Category.assoc, iso]
convert P.pullback_fst _ _ (𝒰.property_trans hij)
apply pullback.hom_ext <;> simp [pullback.condition]
end BaseChange
end Cover
namespace OpenCover
variable (𝒰 : X.OpenCover) [Category 𝒰.I₀] [𝒰.LocallyDirected]
instance {i j : 𝒰.I₀} (f : i ⟶ j) : IsOpenImmersion (𝒰.trans f) :=
𝒰.property_trans f
instance {i j : 𝒰.I₀} (f : i ⟶ j) : IsOpenImmersion (𝒰.functorOfLocallyDirected.map f) :=
𝒰.property_trans f
/--
If `𝒰` is a directed open cover of `X`, to glue morphisms `{gᵢ : 𝒰ᵢ ⟶ Y}` it suffices
to check compatibility with the transition maps.
See `OpenCover.isColimitCoconeOfLocallyDirected` for this result stated in the language of
colimits.
-/
def glueMorphismsOfLocallyDirected (𝒰 : X.OpenCover) [Category 𝒰.I₀] [𝒰.LocallyDirected]
{Y : Scheme.{u}}
(g : ∀ i, 𝒰.X i ⟶ Y) (h : ∀ {i j : 𝒰.I₀} (hij : i ⟶ j), 𝒰.trans hij ≫ g j = g i) :
X ⟶ Y :=
𝒰.glueMorphisms g <| fun i j ↦ by
apply (𝒰.intersectionOfLocallyDirected i j).hom_ext
intro k
simp [h]
@[reassoc (attr := simp)]
lemma map_glueMorphismsOfLocallyDirected {Y : Scheme.{u}} (g : ∀ i, 𝒰.X i ⟶ Y)
(h : ∀ {i j : 𝒰.I₀} (hij : i ⟶ j), 𝒰.trans hij ≫ g j = g i) (i : 𝒰.I₀) :
𝒰.f i ≫ 𝒰.glueMorphismsOfLocallyDirected g h = g i := by
simp [glueMorphismsOfLocallyDirected]
/-- If `𝒰` is an open cover of `X` that is locally directed, `X` is
the colimit of the components of `𝒰`. -/
def isColimitCoconeOfLocallyDirected : IsColimit 𝒰.coconeOfLocallyDirected where
desc s := 𝒰.glueMorphismsOfLocallyDirected s.ι.app fun _ ↦ s.ι.naturality _
uniq s m hm := 𝒰.hom_ext _ _ fun j ↦ by simpa using hm j
/-- If `𝒰` is a directed open cover of `X`, to glue morphisms `{gᵢ : 𝒰ᵢ ⟶ Y}` over `S` it suffices
to check compatibility with the transition maps. -/
def glueMorphismsOverOfLocallyDirected {S : Scheme.{u}} {X : Over S}
(𝒰 : X.left.OpenCover) [Category 𝒰.I₀] [𝒰.LocallyDirected] {Y : Over S}
(g : ∀ i, 𝒰.X i ⟶ Y.left)
(h : ∀ {i j : 𝒰.I₀} (hij : i ⟶ j), 𝒰.trans hij ≫ g j = g i)
(w : ∀ i, g i ≫ Y.hom = 𝒰.f i ≫ X.hom) :
X ⟶ Y :=
Over.homMk (𝒰.glueMorphismsOfLocallyDirected g h) <| by
apply 𝒰.hom_ext
intro i
simp [w]
@[reassoc (attr := simp)]
lemma map_glueMorphismsOverOfLocallyDirected_left {S : Scheme.{u}} {X : Over S}
(𝒰 : X.left.OpenCover) [Category 𝒰.I₀] [𝒰.LocallyDirected] {Y : Over S}
(g : ∀ i, 𝒰.X i ⟶ Y.left) (h : ∀ {i j : 𝒰.I₀} (hij : i ⟶ j), 𝒰.trans hij ≫ g j = g i)
(w : ∀ i, g i ≫ Y.hom = 𝒰.f i ≫ X.hom) (i : 𝒰.I₀) :
𝒰.f i ≫ (𝒰.glueMorphismsOverOfLocallyDirected g h w).left = g i := by
simp [glueMorphismsOverOfLocallyDirected]
end OpenCover
/-- If `𝒰` is an open cover such that the images of the components form a basis of the topology
of `X`, `𝒰` is directed by the ordering of subset inclusion of the images. -/
def Cover.LocallyDirected.ofIsBasisOpensRange {𝒰 : X.OpenCover} [Preorder 𝒰.I₀]
(hle : ∀ {i j : 𝒰.I₀}, i ≤ j ↔ (𝒰.f i).opensRange ≤ (𝒰.f j).opensRange)
(H : TopologicalSpace.Opens.IsBasis (Set.range <| fun i ↦ (𝒰.f i).opensRange)) :
𝒰.LocallyDirected where
trans {i j} hij := IsOpenImmersion.lift (𝒰.f j) (𝒰.f i) (hle.mp (leOfHom hij))
trans_id i := by rw [← cancel_mono (𝒰.f i)]; simp
trans_comp hij hjk := by rw [← cancel_mono (𝒰.f _)]; simp
directed {i j} x := by
have : (pullback.fst (𝒰.f i) (𝒰.f j) ≫ 𝒰.f i) x ∈
(pullback.fst (𝒰.f i) (𝒰.f j) ≫ 𝒰.f i).opensRange := ⟨x, rfl⟩
obtain ⟨k, ⟨k, rfl⟩, ⟨y, hy⟩, h⟩ := TopologicalSpace.Opens.isBasis_iff_nbhd.mp H this
refine ⟨k, homOfLE <| hle.mpr <| le_trans h ?_, homOfLE <| hle.mpr <| le_trans h ?_, y, ?_⟩
· rw [Scheme.Hom.opensRange_comp]
exact Set.image_subset_range _ _
· simp_rw [pullback.condition, Scheme.Hom.opensRange_comp]
exact Set.image_subset_range _ _
· apply (pullback.fst (𝒰.f i) (𝒰.f j) ≫ 𝒰.f i).isOpenEmbedding.injective
rw [← Scheme.Hom.comp_apply, pullback.lift_fst_assoc, IsOpenImmersion.lift_fac, hy]
section Constructions
section
variable {𝒰 : X.OpenCover} [Preorder 𝒰.I₀]
(hle : ∀ {i j : 𝒰.I₀}, i ≤ j ↔ (𝒰.f i).opensRange ≤ (𝒰.f j).opensRange)
(H : TopologicalSpace.Opens.IsBasis (Set.range <| fun i ↦ (𝒰.f i).opensRange))
include hle in
lemma Cover.LocallyDirected.ofIsBasisOpensRange_le_iff (i j : 𝒰.I₀) :
letI := Cover.LocallyDirected.ofIsBasisOpensRange hle H
i ≤ j ↔ (𝒰.f i).opensRange ≤ (𝒰.f j).opensRange := hle
lemma Cover.LocallyDirected.ofIsBasisOpensRange_trans {i j : 𝒰.I₀} :
letI := Cover.LocallyDirected.ofIsBasisOpensRange hle H
(hij : i ≤ j) → 𝒰.trans (homOfLE hij) = IsOpenImmersion.lift (𝒰.f j) (𝒰.f i) (hle.mp hij) :=
fun _ ↦ rfl
end
variable (X) in
open TopologicalSpace.Opens in
/-- The directed affine open cover of `X` given by all affine opens. -/
@[simps I₀ X f]
def directedAffineCover : X.OpenCover where
I₀ := X.affineOpens
X U := U
f U := U.1.ι
mem₀ := by
rw [presieve₀_mem_precoverage_iff]
refine ⟨fun x ↦ ?_, inferInstance⟩
use ⟨(isBasis_iff_nbhd.mp X.isBasis_affineOpens (mem_top x)).choose,
(isBasis_iff_nbhd.mp X.isBasis_affineOpens (mem_top x)).choose_spec.1⟩
simpa using (isBasis_iff_nbhd.mp X.isBasis_affineOpens (mem_top x)).choose_spec.2.1
instance : Preorder X.directedAffineCover.I₀ := inferInstanceAs <| Preorder X.affineOpens
instance : Scheme.Cover.LocallyDirected X.directedAffineCover :=
.ofIsBasisOpensRange (by simp) <| by
convert X.isBasis_affineOpens
simp
@[simp]
lemma directedAffineCover_trans {U V : X.affineOpens} (hUV : U ≤ V) :
Cover.trans X.directedAffineCover (homOfLE hUV) = X.homOfLE hUV := rfl
end Constructions
end AlgebraicGeometry.Scheme |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Maschke.lean | import Mathlib.Algebra.Group.TypeTags.Finite
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.RingTheory.SimpleModule.Basic
/-!
# Maschke's theorem
We prove **Maschke's theorem** for finite groups,
in the formulation that every submodule of a `k[G]` module has a complement,
when `k` is a field with `Fintype.card G` invertible in `k`.
We do the core computation in greater generality.
For any commutative ring `k` in which `Fintype.card G` is invertible,
and a `k[G]`-linear map `i : V → W` which admits a `k`-linear retraction `π`,
we produce a `k[G]`-linear retraction by
taking the average over `G` of the conjugates of `π`.
## Implementation Notes
* These results assume `IsUnit (Fintype.card G : k)` which is equivalent to the more
familiar `¬(ringChar k ∣ Fintype.card G)`.
## Future work
It's not so far to give the usual statement, that every finite-dimensional representation
of a finite group is semisimple (i.e. a direct sum of irreducibles).
-/
universe u v w
noncomputable section
open Module MonoidAlgebra
/-!
We now do the key calculation in Maschke's theorem.
Given `V → W`, an inclusion of `k[G]` modules,
assume we have some retraction `π` (i.e. `∀ v, π (i v) = v`),
just as a `k`-linear map.
(When `k` is a field, this will be available cheaply, by choosing a basis.)
We now construct a retraction of the inclusion as a `k[G]`-linear map,
by the formula
$$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$
-/
namespace LinearMap
-- At first we work with any `[CommRing k]`, and add the assumption that
-- `IsUnit (Fintype.card G : k)` when it is required.
variable {k : Type u} [CommRing k] {G : Type u} [Group G]
variable {V : Type v} [AddCommGroup V] [Module k V] [Module (MonoidAlgebra k G) V]
variable [IsScalarTower k (MonoidAlgebra k G) V]
variable {W : Type w} [AddCommGroup W] [Module k W] [Module (MonoidAlgebra k G) W]
variable [IsScalarTower k (MonoidAlgebra k G) W]
variable (π : W →ₗ[k] V)
/-- We define the conjugate of `π` by `g`, as a `k`-linear map. -/
def conjugate (g : G) : W →ₗ[k] V :=
GroupSMul.linearMap k V g⁻¹ ∘ₗ π ∘ₗ GroupSMul.linearMap k W g
theorem conjugate_apply (g : G) (v : W) :
π.conjugate g v = MonoidAlgebra.single g⁻¹ (1 : k) • π (MonoidAlgebra.single g (1 : k) • v) :=
rfl
variable (i : V →ₗ[MonoidAlgebra k G] W)
section
theorem conjugate_i (h : ∀ v : V, π (i v) = v) (g : G) (v : V) :
(conjugate π g : W → V) (i v) = v := by
rw [conjugate_apply, ← i.map_smul, h, ← mul_smul, single_mul_single, mul_one, inv_mul_cancel,
← one_def, one_smul]
end
variable (G) [Fintype G]
/-- The sum of the conjugates of `π` by each element `g : G`, as a `k`-linear map.
(We postpone dividing by the size of the group as long as possible.)
-/
def sumOfConjugates : W →ₗ[k] V :=
∑ g : G, π.conjugate g
lemma sumOfConjugates_apply (v : W) : π.sumOfConjugates G v = ∑ g : G, π.conjugate g v :=
LinearMap.sum_apply _ _ _
/-- In fact, the sum over `g : G` of the conjugate of `π` by `g` is a `k[G]`-linear map.
-/
def sumOfConjugatesEquivariant : W →ₗ[MonoidAlgebra k G] V :=
MonoidAlgebra.equivariantOfLinearOfComm (π.sumOfConjugates G) fun g v => by
simp only [sumOfConjugates_apply, Finset.smul_sum, conjugate_apply]
refine Fintype.sum_bijective (· * g) (Group.mulRight_bijective g) _ _ fun i ↦ ?_
simp only [smul_smul, single_mul_single, mul_inv_rev, mul_inv_cancel_left, one_mul]
theorem sumOfConjugatesEquivariant_apply (v : W) :
π.sumOfConjugatesEquivariant G v = ∑ g : G, π.conjugate g v :=
π.sumOfConjugates_apply G v
section
/-- We construct our `k[G]`-linear retraction of `i` as
$$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$
-/
def equivariantProjection : W →ₗ[MonoidAlgebra k G] V :=
Ring.inverse (Fintype.card G : k) • π.sumOfConjugatesEquivariant G
theorem equivariantProjection_apply (v : W) :
π.equivariantProjection G v = Ring.inverse (Fintype.card G : k) • ∑ g : G, π.conjugate g v := by
simp only [equivariantProjection, smul_apply, sumOfConjugatesEquivariant_apply]
theorem equivariantProjection_condition (hcard : IsUnit (Fintype.card G : k))
(h : ∀ v : V, π (i v) = v) (v : V) : (π.equivariantProjection G) (i v) = v := by
rw [equivariantProjection_apply]
simp only [conjugate_i π i h]
rw [Finset.sum_const, Finset.card_univ, ← Nat.cast_smul_eq_nsmul k, smul_smul,
Ring.inverse_mul_cancel _ hcard, one_smul]
end
end LinearMap
end
namespace MonoidAlgebra
-- Now we work over a `[Field k]`.
variable {k : Type u} [Field k] {G : Type u} [Fintype G] [NeZero (Fintype.card G : k)]
variable [Group G]
variable {V : Type u} [AddCommGroup V] [Module (MonoidAlgebra k G) V]
variable {W : Type u} [AddCommGroup W] [Module (MonoidAlgebra k G) W]
theorem exists_leftInverse_of_injective
(f : V →ₗ[MonoidAlgebra k G] W) (hf : LinearMap.ker f = ⊥) :
∃ g : W →ₗ[MonoidAlgebra k G] V, g.comp f = LinearMap.id := by
let A := MonoidAlgebra k G
letI : Module k W := .compHom W (algebraMap k A)
letI : Module k V := .compHom V (algebraMap k A)
have := IsScalarTower.of_compHom k A W
have := IsScalarTower.of_compHom k A V
obtain ⟨φ, hφ⟩ := (f.restrictScalars k).exists_leftInverse_of_injective <| by
simp only [hf, Submodule.restrictScalars_bot, LinearMap.ker_restrictScalars]
refine ⟨φ.equivariantProjection G, DFunLike.ext _ _ ?_⟩
exact φ.equivariantProjection_condition G _ (.mk0 _ <| NeZero.ne _) <| DFunLike.congr_fun hφ
namespace Submodule
theorem exists_isCompl (p : Submodule (MonoidAlgebra k G) V) :
∃ q : Submodule (MonoidAlgebra k G) V, IsCompl p q := by
rcases MonoidAlgebra.exists_leftInverse_of_injective p.subtype p.ker_subtype with ⟨f, hf⟩
exact ⟨LinearMap.ker f, LinearMap.isCompl_of_proj <| DFunLike.congr_fun hf⟩
/-- This also implies instances `ComplementedLattice (Submodule (MonoidAlgebra k G) V)` and
`IsSemisimpleRing (MonoidAlgebra k G)`. -/
instance : IsSemisimpleModule (MonoidAlgebra k G) V where
exists_isCompl := exists_isCompl
instance [AddGroup G] : IsSemisimpleRing (AddMonoidAlgebra k G) :=
haveI : NeZero (Fintype.card (Multiplicative G) : k) := by
rwa [Fintype.card_congr Multiplicative.toAdd]
(AddMonoidAlgebra.toMultiplicativeAlgEquiv k G (R := ℕ)).toRingEquiv.symm.isSemisimpleRing
end Submodule
end MonoidAlgebra |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Coinduced.lean | import Mathlib.CategoryTheory.Preadditive.Projective.Preserves
import Mathlib.RepresentationTheory.Rep
/-!
# Coinduced representations
Given a commutative ring `k`, a monoid homomorphism `φ : G →* H`, and a `k`-linear
`G`-representation `A`, this file introduces the coinduced representation $Coind_G^H(A)$ of `A` as
an `H`-representation.
By `coind φ A` we mean the submodule of functions `H → A` such that for all `g : G`, `h : H`,
`f (φ g * h) = ρ g (f h)`. We define a representation of `H` on this submodule by sending `h : H`
and `f : coind φ A` to the function `H → A` sending `h₁` to `f (h₁ * h)`.
Alternatively, we could define $Coind_G^H(A)$ as the morphisms $Hom(k[H], A)$ in the category
`Rep k G`, which we equip with the `H`-representation sending `h : H` and `f : k[H] ⟶ A` to the
representation morphism sending `r · h₁` to `r • f (h₁ * h)`. We include this definition as
`coind' φ A` and prove the two representations are isomorphic.
We also prove that the restriction functor `Rep k H ⥤ Rep k G` along `φ` is left adjoint to the
coinduction functor and hence that the coinduction functor preserves limits.
## Main definitions
* `Representation.coind φ ρ` : the coinduction of `ρ` along `φ` defined as the `k`-submodule of
`G`-equivariant functions `H → A`, with `H`-action given by `(h • f) h₁ := f (h₁ * h)` for
`f : H → A`, `h, h₁ : H`.
* `Representation.coind' φ A` : the coinduction of `A` along `φ` defined as the set of
`G`-representation morphisms `k[H] ⟶ A`, with `H`-action given by
`(h • f) (r • h₁) := r • f(h₁ * h)` for `f : k[H] ⟶ A`, `h, h₁ : H`, `r : k`.
* `Rep.resCoindAdjunction k φ`: given a monoid homomorphism `φ : G →* H`, this is the adjunction
between the restriction functor `Rep k H ⥤ Rep k G` along `φ` and the coinduction functor
along `φ`.
-/
universe u
namespace Representation
variable {k G H : Type*} [CommSemiring k] [Monoid G] [Monoid H] (φ : G →* H) {A : Type*}
[AddCommMonoid A] [Module k A] (ρ : Representation k G A)
/--
If `ρ : Representation k G A` and `φ : G →* H` then `coindV φ ρ` is the sub-`k`-module of
functions `H → A` underlying the coinduction of `ρ` along `φ`, i.e., the functions `f : H → A`
such that `f (φ g * h) = (ρ g) (f h)` for all `g : G` and `h : H`.
-/
@[simps]
def coindV : Submodule k (H → A) where
carrier := {f : H → A | ∀ (g : G) (h : H), f (φ g * h) = ρ g (f h) }
add_mem' _ _ _ _ := by simp_all
zero_mem' := by simp
smul_mem' _ _ _ := by simp_all
/--
If `ρ : Representation k G A` and `φ : G →* H` then `coind φ ρ` is the representation
coinduced by `ρ` along `φ`, defined as the following action of `H` on the submodule `coindV φ ρ`
of `G`-equivariant functions from `H` to `A`: we let `h : H` send the function `f : H → A`
to the function sending `h₁` to `f (h₁ * h)`.
See also `Rep.coind` and `Representation.coind'` for variants involving the category `Rep k G`.
-/
@[simps]
def coind : Representation k H (coindV φ ρ) where
toFun h := (LinearMap.funLeft _ _ (· * h)).restrict fun x hx g h₁ => by
simpa [mul_assoc] using hx g (h₁ * h)
map_one' := by ext; simp
map_mul' _ _ := by ext; simp [mul_assoc]
end Representation
namespace Rep
open CategoryTheory Finsupp
variable {k G H : Type u} [CommRing k] [Monoid G] [Monoid H] (φ : G →* H) (A : Rep k G)
section Coind
/--
If `φ : G →* H` and `A : Rep k G` then `coind φ A` is the coinduction of `A` along `φ`,
defined by letting `H` act on the `G`-equivariant functions `H → A` by `(h • f) h₁ := f (h₁ * h)`.
-/
noncomputable abbrev coind : Rep k H := Rep.of (Representation.coind φ A.ρ)
/-- Given a monoid morphism `φ : G →* H` and a morphism of `G`-representations `f : A ⟶ B`, there
is a natural `H`-representation morphism `coind φ A ⟶ coind φ B`, given by postcomposition by
`f`. -/
@[simps]
noncomputable def coindMap {A B : Rep k G} (f : A ⟶ B) : coind φ A ⟶ coind φ B where
hom := ModuleCat.ofHom <| (f.hom.hom.compLeft H).restrict
fun x h y z => by simp [h y z, hom_comm_apply]
comm _ := by ext; simp [ModuleCat.endRingEquiv]
variable (k) in
/-- Given a monoid homomorphism `φ : G →* H`, this is the functor sending a `G`-representation `A`
to the coinduced `H`-representation `coind φ A`, with action on maps given by postcomposition. -/
@[simps obj map]
noncomputable def coindFunctor : Rep k G ⥤ Rep k H where
obj A := coind φ A
map f := coindMap φ f
instance {G : Type u} [Group G] (S : Subgroup G) :
(coindFunctor k S.subtype).PreservesEpimorphisms where
preserves {X Y} f := (Rep.epi_iff_surjective _).2 fun y => by
letI := QuotientGroup.rightRel S
choose! s hs using (Rep.epi_iff_surjective f).1 ‹_›
choose! i hi using Quotient.mk'_surjective (α := G)
let γ (g : G) : S := ⟨g * (i (Quotient.mk' g))⁻¹,
(QuotientGroup.rightRel_apply.1 (Quotient.eq'.1 (hi (Quotient.mk' g))))⟩
have hmk (s : S) (g : G) : Quotient.mk' (s.1 * g) = Quotient.mk' g :=
Quotient.eq'.2 (QuotientGroup.rightRel_apply.2 (by simp))
have hγ (s : S) (g : G) : γ (s.1 * g) = s * γ g := by ext; simp [mul_assoc, γ, hmk]
let x (g : G) : X := X.ρ (γ g) (s (y.1 (i (Quotient.mk' g))))
refine ⟨⟨x, fun _ _ => ?_⟩, Subtype.ext <| funext fun g => ?_⟩
· simp [x, ← Module.End.mul_apply, ← map_mul, hmk, hγ]
· simp_all [x, hom_comm_apply, ← y.2 (γ g), γ]
end Coind
section Coind'
/--
If `φ : G →* H` and `A : Rep k G` then `coind' φ A`, the coinduction of `A` along `φ`,
is defined as an `H`-action on `Hom_{k[G]}(k[H], A)`. If `f : k[H] → A` is `G`-equivariant
then `(h • f) (r • h₁) := r • f (h₁ * h)`, where `r : k`.
-/
@[simps]
noncomputable def _root_.Representation.coind' :
Representation k H ((Action.res _ φ).obj (leftRegular k H) ⟶ A) where
toFun h := {
toFun f := (Action.res _ φ).map ((leftRegularHomEquiv (leftRegular k H)).symm (single h 1)) ≫ f
map_add' _ _ := by rfl
map_smul' _ _ := by rfl }
map_one' := by
ext x : 3
refine lhom_ext' fun _ => LinearMap.ext_ring ?_
simp [leftRegularHomEquiv_symm_apply (leftRegular k H)]
map_mul' _ _ := by
ext x : 3
refine lhom_ext' fun _ => LinearMap.ext_ring ?_
simp [leftRegularHomEquiv_symm_apply (leftRegular k H), mul_assoc]
/--
If `φ : G →* H` and `A : Rep k G` then `coind' φ A`, the coinduction of `A` along `φ`,
is defined as an `H`-action on `Hom_{k[G]}(k[H], A)`. If `f : k[H] → A` is `G`-equivariant
then `(h • f) (r • h₁) := r • f (h₁ * h)`, where `r : k`.
-/
noncomputable abbrev coind' : Rep k H := Rep.of (Representation.coind' φ A)
variable {A} in
@[ext]
lemma coind'_ext {f g : coind' φ A}
(hfg : ∀ h, f.hom (single h 1) = g.hom (single h 1)) : f = g :=
Action.Hom.ext <| ModuleCat.hom_ext <| lhom_ext' fun h => LinearMap.ext_ring <| hfg h
/-- Given a monoid morphism `φ : G →* H` and a morphism of `G`-representations `f : A ⟶ B`, there
is a natural `H`-representation morphism `coind' φ A ⟶ coind' φ B`, given by postcomposition
by `f`. -/
@[simps]
noncomputable def coindMap' {A B : Rep k G} (f : A ⟶ B) : coind' φ A ⟶ coind' φ B where
hom := ModuleCat.ofHom <| Linear.rightComp k _ f
comm h := by ext; simp [ModuleCat.endRingEquiv]
variable (k) in
/-- Given a monoid homomorphism `φ : G →* H`, this is the functor sending a `G`-representation `A`
to the coinduced `H`-representation `coind' φ A`, with action on maps given by postcomposition. -/
@[simps obj map]
noncomputable def coindFunctor' : Rep k G ⥤ Rep k H where
obj A := coind' φ A
map f := coindMap' φ f
end Coind'
section CoindIso
/--
If `φ : G →* H` and `A : Rep k G` then the `k`-submodule of functions `f : H → A`
such that for all `g : G`, `h : H`, `f (φ g * h) = A.ρ g (f h)`, is `k`-linearly equivalent
to the `G`-representation morphisms `k[H] ⟶ A`.
-/
@[simps]
noncomputable def coindVEquiv :
A.ρ.coindV φ ≃ₗ[k] ((Action.res _ φ).obj (leftRegular k H) ⟶ A) where
toFun f := {
hom := ModuleCat.ofHom <| linearCombination _ f.1
comm g := ModuleCat.hom_ext <| lhom_ext' fun _ => LinearMap.ext_ring <| by
simp [ModuleCat.endRingEquiv, f.2 g] }
map_add' _ _ := coind'_ext φ fun _ => by simp
map_smul' _ _ := coind'_ext φ fun _ => by simp
invFun f := {
val h := f.hom (single h 1)
property g h := by have := (hom_comm_apply f g (single h 1)).symm; simp_all [Rep.res_obj_ρ φ] }
left_inv x := by simp
right_inv x := coind'_ext φ fun _ => by simp
/-- `coind φ A` and `coind' φ A` are isomorphic representations, with the underlying
`k`-linear equivalence given by `coindVEquiv`. -/
@[simps! hom_hom_hom inv_hom_hom]
noncomputable def coindIso : coind φ A ≅ coind' φ A :=
Action.mkIso (coindVEquiv φ A).toModuleIso fun h => by
ext
simp [ModuleCat.endRingEquiv, leftRegularHomEquiv_symm_apply (leftRegular k H)]
/-- Given a monoid homomorphism `φ : G →* H`, the coinduction functors `Rep k G ⥤ Rep k H` given by
`coindFunctor k φ` and `coindFunctor' k φ` are naturally isomorphic, with isomorphism on objects
given by `coindIso φ`. -/
@[simps!]
noncomputable def coindFunctorIso : coindFunctor k φ ≅ coindFunctor' k φ :=
NatIso.ofComponents (coindIso φ) fun _ => by
simp only [coindFunctor_obj, coindFunctor'_obj]
ext
simp
end CoindIso
section Adjunction
/-- Given a monoid homomorphism `φ : G →* H`, an `H`-representation `B`, and a `G`-representation
`A`, there is a `k`-linear equivalence between the `G`-representation morphisms `B ⟶ A` and the
`H`-representation morphisms `B ⟶ coind φ A`. -/
@[simps]
noncomputable def resCoindHomEquiv (B : Rep k H) (A : Rep k G) :
((Action.res _ φ).obj B ⟶ A) ≃ₗ[k] (B ⟶ coind φ A) where
toFun f := {
hom := ModuleCat.ofHom <| (LinearMap.pi fun h => f.hom.hom ∘ₗ Rep.ρ B h).codRestrict _
fun _ _ _ => by simpa using hom_comm_apply f _ _
comm _ := by ext; simp [ModuleCat.endRingEquiv] }
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f := {
hom := ModuleCat.ofHom (LinearMap.proj 1 ∘ₗ ((Rep.ρ A).coindV φ).subtype ∘ₗ f.hom.hom)
comm g := by
ext x
have := ((f.hom x).2 g 1).symm
have := hom_comm_apply f (φ g) x
simp_all }
left_inv := by intro; ext; simp
right_inv z := by ext; have := hom_comm_apply z; simp_all
variable (k) in
/-- Given a monoid homomorphism `φ : G →* H`, the coinduction functor `Rep k G ⥤ Rep k H` is right
adjoint to the restriction functor along `φ`. -/
@[simps! counit_app_hom_hom unit_app_hom_hom]
noncomputable abbrev resCoindAdjunction : Action.res _ φ ⊣ coindFunctor k φ :=
Adjunction.mkOfHomEquiv {
homEquiv X Y := (resCoindHomEquiv φ X Y).toEquiv
homEquiv_naturality_left_symm := by intros; rfl
homEquiv_naturality_right := by intros; ext; rfl }
noncomputable instance : (coindFunctor k φ).IsRightAdjoint :=
(resCoindAdjunction k φ).isRightAdjoint
noncomputable instance : (Action.res (ModuleCat.{u} k) φ).IsLeftAdjoint :=
(resCoindAdjunction k φ).isLeftAdjoint
instance {G : Type u} [Group G] (S : Subgroup G) :
(Action.res (ModuleCat.{u} k) S.subtype).PreservesProjectiveObjects :=
(Action.res _ S.subtype).preservesProjectiveObjects_of_adjunction_of_preservesEpimorphisms
(resCoindAdjunction k S.subtype)
end Adjunction
end Rep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/FDRep.lean | import Mathlib.Algebra.Category.FGModuleCat.Limits
import Mathlib.Algebra.Category.FGModuleCat.Colimits
import Mathlib.CategoryTheory.Monoidal.Rigid.Braided
import Mathlib.CategoryTheory.Preadditive.Schur
import Mathlib.RepresentationTheory.Basic
import Mathlib.RepresentationTheory.Rep
/-!
# `FDRep k G` is the category of finite-dimensional `k`-linear representations of `G`.
If `V : FDRep k G`, there is a coercion that allows you to treat `V` as a type,
and this type comes equipped with `Module k V` and `FiniteDimensional k V` instances.
Also `V.ρ` gives the homomorphism `G →* (V →ₗ[k] V)`.
Conversely, given a homomorphism `ρ : G →* (V →ₗ[k] V)`,
you can construct the bundled representation as `Rep.of ρ`.
We prove Schur's Lemma: the dimension of the `Hom`-space between two irreducible representation is
`0` if they are not isomorphic, and `1` if they are.
This is the content of `finrank_hom_simple_simple`
We verify that `FDRep k G` is a `k`-linear monoidal category, and rigid when `G` is a group.
`FDRep k G` has all finite limits.
## Implementation notes
We define `FDRep R G` for any ring `R` and monoid `G`,
as the category of finitely generated `R`-linear representations of `G`.
The main case of interest is when `R = k` is a field and `G` is a group,
and this is reflected in the documentation.
## TODO
* `FdRep k G ≌ FullSubcategory (FiniteDimensional k)`
* `FdRep k G` has all finite colimits.
* `FdRep k G` is abelian.
* `FdRep k G ≌ FGModuleCat (MonoidAlgebra k G)`.
-/
suppress_compilation
universe u
open CategoryTheory
open CategoryTheory.Limits
/-- The category of finitely generated `R`-linear representations of a monoid `G`.
Note that `R` can be any ring,
but the main case of interest is when `R = k` is a field and `G` is a group. -/
abbrev FDRep (R G : Type u) [Ring R] [Monoid G] :=
Action (FGModuleCat.{u} R) G
namespace FDRep
variable {R k G : Type u} [CommRing R] [Field k] [Monoid G]
-- The `LargeCategory, ConcreteCategory, Preadditive, HasFiniteLimits` instances should be
-- constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance : LargeCategory (FDRep R G) := inferInstance
instance : ConcreteCategory (FDRep R G) (Action.HomSubtype _ _) := inferInstance
instance : Preadditive (FDRep R G) := inferInstance
instance : HasFiniteLimits (FDRep k G) := inferInstance
instance : Linear R (FDRep R G) := by infer_instance
instance : CoeSort (FDRep R G) (Type u) :=
⟨fun V => V.V⟩
instance (V : FDRep R G) : AddCommGroup V := by
change AddCommGroup ((forget₂ (FDRep R G) (FGModuleCat R)).obj V).obj; infer_instance
instance (V : FDRep R G) : Module R V := by
change Module R ((forget₂ (FDRep R G) (FGModuleCat R)).obj V).obj; infer_instance
instance (V : FDRep R G) : Module.Finite R V := by
change Module.Finite R ((forget₂ (FDRep R G) (FGModuleCat R)).obj V); infer_instance
instance (V : FDRep k G) : FiniteDimensional k V := by
infer_instance
/-- All hom spaces are finite dimensional. -/
instance (V W : FDRep k G) : FiniteDimensional k (V ⟶ W) :=
FiniteDimensional.of_injective ((forget₂ (FDRep k G) (FGModuleCat k)).mapLinearMap k)
(Functor.map_injective (forget₂ (FDRep k G) (FGModuleCat k)))
/-- The monoid homomorphism corresponding to the action of `G` onto `V : FDRep R G`. -/
def ρ (V : FDRep R G) : G →* V →ₗ[R] V :=
(ModuleCat.endRingEquiv _).toMonoidHom.comp (Action.ρ V)
@[simp]
lemma endRingEquiv_symm_comp_ρ (V : FDRep R G) :
(MonoidHomClass.toMonoidHom (ModuleCat.endRingEquiv V.V.obj).symm).comp (ρ V) =
(Action.ρ V) :=
rfl
@[simp]
lemma endRingEquiv_comp_ρ (V : FDRep R G) :
(MonoidHomClass.toMonoidHom (ModuleCat.endRingEquiv V.V.obj)).comp (Action.ρ V) = ρ V := rfl
@[simp]
lemma hom_action_ρ (V : FDRep R G) (g : G) : (Action.ρ V g).hom = ρ V g := rfl
/-- The underlying `LinearEquiv` of an isomorphism of representations. -/
def isoToLinearEquiv {V W : FDRep R G} (i : V ≅ W) : V ≃ₗ[R] W :=
FGModuleCat.isoToLinearEquiv ((Action.forget (FGModuleCat R) G).mapIso i)
theorem Iso.conj_ρ {V W : FDRep R G} (i : V ≅ W) (g : G) :
W.ρ g = (FDRep.isoToLinearEquiv i).conj (V.ρ g) := by
rw [FDRep.isoToLinearEquiv, ← hom_action_ρ V, ← FGModuleCat.Iso.conj_hom_eq_conj, Iso.conj_apply,
← ModuleCat.hom_ofHom (W.ρ g), ← ModuleCat.hom_ext_iff,
Iso.eq_inv_comp ((Action.forget (FGModuleCat R) G).mapIso i)]
exact (i.hom.comm g).symm
/-- Lift an unbundled representation to `FDRep`. -/
@[simps ρ]
abbrev of {V : Type u} [AddCommGroup V] [Module R V] [Module.Finite R V]
(ρ : Representation R G V) : FDRep R G :=
⟨FGModuleCat.of R V, (ModuleCat.endRingEquiv _).symm.toMonoidHom.comp ρ⟩
/-- This lemma is about `FDRep.ρ`, instead of `Action.ρ` for `of_ρ`. -/
@[simp]
theorem of_ρ' {V : Type u} [AddCommGroup V] [Module R V] [Module.Finite R V] (ρ : G →* V →ₗ[R] V) :
(of ρ).ρ = ρ := rfl
@[deprecated Representation.inv_self_apply (since := "2025-05-09")]
theorem ρ_inv_self_apply {G : Type u} [Group G] {A : FDRep R G} (g : G) (x : A) :
A.ρ g⁻¹ (A.ρ g x) = x :=
show (A.ρ g⁻¹ * A.ρ g) x = x by rw [← map_mul, inv_mul_cancel, map_one, Module.End.one_apply]
@[deprecated Representation.self_inv_apply (since := "2025-05-09")]
theorem ρ_self_inv_apply {G : Type u} [Group G] {A : FDRep R G} (g : G) (x : A) :
A.ρ g (A.ρ g⁻¹ x) = x :=
show (A.ρ g * A.ρ g⁻¹) x = x by rw [← map_mul, mul_inv_cancel, map_one, Module.End.one_apply]
instance : HasForget₂ (FDRep R G) (Rep R G) where
forget₂ := (forget₂ (FGModuleCat R) (ModuleCat R)).mapAction G
theorem forget₂_ρ (V : FDRep R G) : ((forget₂ (FDRep R G) (Rep R G)).obj V).ρ = V.ρ := by
ext g v; rfl
instance [IsNoetherianRing R] : PreservesFiniteLimits (forget₂ (FDRep R G) (Rep R G)) :=
inferInstanceAs <| PreservesFiniteLimits <| (forget₂ (FGModuleCat R) (ModuleCat R)).mapAction G
instance : PreservesFiniteColimits (forget₂ (FDRep R G) (Rep R G)) :=
inferInstanceAs <| PreservesFiniteColimits <| (forget₂ (FGModuleCat R) (ModuleCat R)).mapAction G
-- Verify that the monoidal structure is available.
example : MonoidalCategory (FDRep R G) := by infer_instance
example : MonoidalPreadditive (FDRep R G) := by infer_instance
example : MonoidalLinear R (FDRep R G) := by infer_instance
open Module
-- We need to provide this instance explicitly as otherwise `finrank_hom_simple_simple` gives a
-- deterministic timeout.
instance : HasKernels (FDRep k G) := by infer_instance
open scoped Classical in
/-- Schur's Lemma: the dimension of the `Hom`-space between two irreducible representation is `0` if
they are not isomorphic, and `1` if they are. -/
theorem finrank_hom_simple_simple [IsAlgClosed k] (V W : FDRep k G) [Simple V] [Simple W] :
finrank k (V ⟶ W) = if Nonempty (V ≅ W) then 1 else 0 :=
CategoryTheory.finrank_hom_simple_simple k V W
/-- The forgetful functor to `Rep k G` preserves hom-sets and their vector space structure. -/
def forget₂HomLinearEquiv (X Y : FDRep R G) :
((forget₂ (FDRep R G) (Rep R G)).obj X ⟶
(forget₂ (FDRep R G) (Rep R G)).obj Y) ≃ₗ[R] X ⟶ Y where
toFun f := ⟨f.hom, f.comm⟩
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f := ⟨(forget₂ (FGModuleCat R) (ModuleCat R)).map f.hom, f.comm⟩
instance : (forget₂ (FDRep R G) (Rep R G)).Full := by
dsimp [forget₂, HasForget₂.forget₂]
infer_instance
instance : (forget₂ (FDRep R G) (Rep R G)).Faithful := by
dsimp [forget₂, HasForget₂.forget₂]
infer_instance
end FDRep
namespace FDRep
variable {k G : Type u} [Field k] [Group G]
-- Verify that the right rigid structure is available when the monoid is a group.
noncomputable instance : RightRigidCategory (FDRep k G) := by
change RightRigidCategory (Action (FGModuleCat k) G); infer_instance
example : RigidCategory (FDRep k G) := by infer_instance
end FDRep
namespace FDRep
-- The variables in this section are slightly weird, living half in `Representation` and half in
-- `FDRep`. When we have a better API for general monoidal closed and rigid categories and these
-- structures on `FDRep`, we should remove the dependency of statements about `FDRep` on
-- `Representation.linHom` and `Representation.dual`. The isomorphism `dualTensorIsoLinHom`
-- below should then just be obtained from general results about rigid categories.
open Representation
variable {k G V : Type u} [Field k] [Group G]
variable [AddCommGroup V] [Module k V]
variable [FiniteDimensional k V]
variable (ρV : Representation k G V) (W : FDRep k G)
open scoped MonoidalCategory
/-- Auxiliary definition for `FDRep.dualTensorIsoLinHom`. -/
noncomputable def dualTensorIsoLinHomAux :
(FDRep.of ρV.dual ⊗ W).V ≅ (FDRep.of (linHom ρV W.ρ)).V :=
LinearEquiv.toFGModuleCatIso (dualTensorHomEquiv k V W)
/-- When `V` and `W` are finite-dimensional representations of a group `G`, the isomorphism
`dualTensorHomEquiv k V W` of vector spaces induces an isomorphism of representations. -/
noncomputable def dualTensorIsoLinHom : FDRep.of ρV.dual ⊗ W ≅ FDRep.of (linHom ρV W.ρ) := by
refine Action.mkIso (dualTensorIsoLinHomAux ρV W) (fun g => ?_)
ext : 1
exact dualTensorHom_comm ρV W.ρ g
@[simp]
theorem dualTensorIsoLinHom_hom_hom :
(dualTensorIsoLinHom ρV W).hom.hom = ModuleCat.ofHom (dualTensorHom k V W) :=
rfl
end FDRep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Coinvariants.lean | import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
import Mathlib.RepresentationTheory.Rep
/-!
# Coinvariants of a group representation
Given a commutative ring `k` and a monoid `G`, this file introduces the coinvariants of a
`k`-linear `G`-representation `(V, ρ)`.
We first define `Representation.Coinvariants.ker`, the submodule of `V` generated by elements
of the form `ρ g x - x` for `x : V`, `g : G`. Then the coinvariants of `(V, ρ)` are the quotient of
`V` by this submodule. We show that the functor sending a representation to its coinvariants is
left adjoint to the functor equipping a module with the trivial representation.
## Main definitions
* `Representation.Coinvariants ρ`: the coinvariants of a representation `ρ`.
* `Representation.coinvariantsFinsuppLEquiv ρ α`: given a type `α`, this is the `k`-linear
equivalence between `(α →₀ V)_G` and `α →₀ V_G`.
* `Representation.coinvariantsTprodLeftRegularLEquiv ρ`: the `k`-linear equivalence between
`(V ⊗ k[G])_G` and `V` sending `⟦v ⊗ single g r⟧ ↦ r • ρ(g⁻¹)(v)`.
* `Rep.coinvariantsAdjunction k G`: the adjunction between the functor sending a representation to
its coinvariants and the functor equipping a module with the trivial representation.
* `Rep.coinvariantsTensor k G`: the functor sending representations `A, B` to `(A ⊗[k] B)_G`. This
is naturally isomorphic to the functor sending `A, B` to `A ⊗[k[G]] B`, where we give `A` the
`k[G]ᵐᵒᵖ`-module structure defined by `g • a := A.ρ g⁻¹ a`.
* `Rep.coinvariantsTensorFreeLEquiv A α`: given a representation `A` and a type `α`, this is the
`k`-linear equivalence between `(A ⊗ (α →₀ k[G]))_G` and `α →₀ A` sending
`⟦a ⊗ single x (single g r)⟧ ↦ single x (r • ρ(g⁻¹)(a))`. This is useful for group homology.
-/
universe u v
namespace Representation
variable {k G V W X : Type*} [CommRing k] [Monoid G] [AddCommGroup V] [Module k V]
[AddCommGroup W] [Module k W] [AddCommGroup X] [Module k X]
(ρ : Representation k G V) (τ : Representation k G W) (υ : Representation k G X)
/-- The submodule of a representation generated by elements of the form `ρ g x - x`. -/
def Coinvariants.ker : Submodule k V :=
Submodule.span k (Set.range fun (gv : G × V) => ρ gv.1 gv.2 - gv.2)
/-- The coinvariants of a representation, `V ⧸ ⟨{ρ g x - x | g ∈ G, x ∈ V}⟩`. -/
def Coinvariants := V ⧸ Coinvariants.ker ρ
namespace Coinvariants
instance : AddCommGroup (Coinvariants ρ) := inferInstanceAs <| AddCommGroup (_ ⧸ _)
instance : Module k (Coinvariants ρ) := inferInstanceAs <| Module k (_ ⧸ _)
variable {ρ}
lemma sub_mem_ker (g : G) (x : V) : ρ g x - x ∈ Coinvariants.ker ρ :=
Submodule.subset_span <| Set.mem_range_self (g, x)
lemma mem_ker_of_eq (g : G) (x : V) (a : V) (h : ρ g x - x = a) : a ∈ ker ρ :=
Submodule.subset_span ⟨(g, x), h⟩
variable (ρ)
/-- The quotient map from a representation to its coinvariants as a linear map. -/
def mk : V →ₗ[k] Coinvariants ρ := Submodule.mkQ (ker ρ)
theorem mk_eq_iff {x y : V} :
mk ρ x = mk ρ y ↔ x - y ∈ Coinvariants.ker ρ :=
Submodule.Quotient.eq _
theorem mk_eq_zero {x : V} :
mk ρ x = 0 ↔ x ∈ Coinvariants.ker ρ :=
Submodule.Quotient.mk_eq_zero _
theorem mk_surjective : Function.Surjective (mk ρ) :=
Submodule.Quotient.mk_surjective _
@[simp]
lemma mk_self_apply (g : G) (x : V) :
mk ρ (ρ g x) = mk ρ x :=
(mk_eq_iff _).2 <| mem_ker_of_eq g x _ rfl
variable {ρ} in
@[elab_as_elim]
theorem induction_on {motive : Coinvariants ρ → Prop} (x : Coinvariants ρ)
(h : ∀ v : V, motive (mk ρ v)) :
motive x :=
Submodule.Quotient.induction_on _ x h
/-- A `G`-invariant linear map induces a linear map out of the coinvariants of a
`G`-representation. -/
def lift (f : V →ₗ[k] W) (h : ∀ (x : G), f ∘ₗ ρ x = f) :
ρ.Coinvariants →ₗ[k] W :=
Submodule.liftQ _ f <| Submodule.span_le.2 fun x ⟨⟨g, y⟩, hy⟩ => by
simpa only [← hy, SetLike.mem_coe, LinearMap.mem_ker, map_sub, sub_eq_zero, LinearMap.coe_comp,
Function.comp_apply] using LinearMap.ext_iff.1 (h g) y
@[simp]
theorem lift_comp_mk (f : V →ₗ[k] W) (h : ∀ (x : G), f ∘ₗ ρ x = f) :
lift ρ f h ∘ₗ mk ρ = f := rfl
@[simp]
theorem lift_mk (f : V →ₗ[k] W) (h : ∀ (x : G), f ∘ₗ ρ x = f) (x : V) :
lift ρ f h (mk _ x) = f x := rfl
variable {ρ} in
@[ext high]
lemma hom_ext {f g : Coinvariants ρ →ₗ[k] W} (H : f ∘ₗ mk ρ = g ∘ₗ mk ρ) : f = g :=
Submodule.linearMap_qext _ H
/-- Given `G`-representations on `k`-modules `V, W`, a linear map `V →ₗ[k] W` commuting with
the representations induces a `k`-linear map between the coinvariants. -/
noncomputable def map (f : V →ₗ[k] W) (hf : ∀ g, f ∘ₗ ρ g = τ g ∘ₗ f) :
Coinvariants ρ →ₗ[k] Coinvariants τ :=
lift _ (mk _ ∘ₗ f) fun g => LinearMap.ext fun x => (mk_eq_iff _).2 <|
mem_ker_of_eq g (f x) _ <| by simpa using congr($((hf g).symm) x)
variable {ρ τ}
@[simp]
lemma map_comp_mk (f : V →ₗ[k] W) (hf : ∀ g, f ∘ₗ ρ g = τ g ∘ₗ f) :
map ρ τ f hf ∘ₗ mk ρ = mk τ ∘ₗ f := rfl
@[simp]
lemma map_mk (f : V →ₗ[k] W) (hf : ∀ g, f ∘ₗ ρ g = τ g ∘ₗ f) (x : V) :
map ρ τ f hf (mk _ x) = mk _ (f x) := rfl
@[simp]
lemma map_id (ρ : Representation k G V) :
map ρ ρ LinearMap.id (by simp) = LinearMap.id := by
ext; rfl
@[simp]
lemma map_comp (φ : V →ₗ[k] W) (ψ : W →ₗ[k] X)
(H : ∀ g, φ ∘ₗ ρ g = τ g ∘ₗ φ) (h : ∀ g, ψ ∘ₗ τ g = υ g ∘ₗ ψ) :
map τ υ ψ h ∘ₗ map ρ τ φ H = map ρ υ (ψ ∘ₗ φ) (fun g => by
ext x; have : φ _ = _ := congr($(H g) x); have : ψ _ = _ := congr($(h g) (φ x)); simp_all) :=
hom_ext rfl
end Coinvariants
section
open Coinvariants
variable {k G V : Type*} [CommRing k] [Group G] [AddCommGroup V] [Module k V]
variable (ρ : Representation k G V) (S : Subgroup G) [S.Normal]
lemma Coinvariants.le_comap_ker (g : G) :
ker (ρ.comp S.subtype) ≤ (ker <| ρ.comp S.subtype).comap (ρ g) :=
Submodule.span_le.2 fun _ ⟨⟨s, x⟩, hs⟩ => by
simpa [← hs] using mem_ker_of_eq
⟨g * s * g⁻¹, Subgroup.Normal.conj_mem ‹_› s.1 s.2 g⟩ (ρ g x) _ <| by simp
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` restricts to a `G`-representation on
the kernel of the quotient map to the coinvariants of `ρ|_S`. -/
noncomputable abbrev toCoinvariantsKer :
Representation k G (ker <| ρ.comp S.subtype) :=
subrepresentation ρ (ker <| ρ.comp S.subtype) fun g => le_comap_ker ρ S g
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` induces a `G`-representation on the
coinvariants of `ρ|_S`. -/
noncomputable def toCoinvariants :
Representation k G (Coinvariants <| ρ.comp S.subtype) :=
quotient ρ (ker <| ρ.comp S.subtype) fun g => le_comap_ker ρ S g
@[simp]
lemma toCoinvariants_mk (g : G) (x : V) :
toCoinvariants ρ S g (Coinvariants.mk _ x) = Coinvariants.mk _ (ρ g x) := rfl
instance : IsTrivial ((toCoinvariants ρ S).comp S.subtype) where
out g := by
ext x
exact (Coinvariants.mk_eq_iff _).2 <| mem_ker_of_eq g x _ rfl
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` induces a `G ⧸ S`-representation on
the coinvariants of `ρ|_S`. -/
noncomputable abbrev quotientToCoinvariants :
Representation k (G ⧸ S) (Coinvariants (ρ.comp S.subtype)) :=
ofQuotient (toCoinvariants ρ S) S
end
section Finsupp
open Finsupp Coinvariants
variable {k G V : Type*} [CommRing k] [Group G] [AddCommGroup V] [Module k V]
(ρ : Representation k G V) (α : Type*)
/-- Given a `G`-representation `(V, ρ)` and a type `α`, this is the map `(α →₀ V)_G →ₗ (α →₀ V_G)`
sending `⟦single a v⟧ ↦ single a ⟦v⟧`. -/
noncomputable def coinvariantsToFinsupp :
Coinvariants (ρ.finsupp α) →ₗ[k] α →₀ Coinvariants ρ :=
Coinvariants.lift _ (mapRange.linearMap (Coinvariants.mk _)) <| fun _ => by ext; simp
variable {ρ α}
@[simp]
lemma coinvariantsToFinsupp_mk_single (x : α) (a : V) :
coinvariantsToFinsupp ρ α (Coinvariants.mk _ (single x a)) =
single x (Coinvariants.mk _ a) := by
simp [coinvariantsToFinsupp]
variable (ρ α) in
/-- Given a `G`-representation `(V, ρ)` and a type `α`, this is the map `(α →₀ V_G) →ₗ (α →₀ V)_G`
sending `single a ⟦v⟧ ↦ ⟦single a v⟧`. -/
noncomputable def finsuppToCoinvariants :
(α →₀ Coinvariants ρ) →ₗ[k] Coinvariants (ρ.finsupp α) :=
lsum (R := k) k fun a => Coinvariants.lift _ (Coinvariants.mk _ ∘ₗ lsingle a) fun g =>
LinearMap.ext fun x => (mk_eq_iff _).2 <| mem_ker_of_eq g (single a x) _ <| by simp
@[simp]
lemma finsuppToCoinvariants_single_mk (a : α) (x : V) :
finsuppToCoinvariants ρ α (single a <| Coinvariants.mk _ x) =
Coinvariants.mk _ (single a x) := by
simp [finsuppToCoinvariants]
variable (ρ α) in
/-- Given a `G`-representation `(V, ρ)` and a type `α`, this is the linear equivalence
`(α →₀ V)_G ≃ₗ (α →₀ V_G)` sending `⟦single a v⟧ ↦ single a ⟦v⟧`. -/
@[simps! symm_apply]
noncomputable def coinvariantsFinsuppLEquiv :
Coinvariants (ρ.finsupp α) ≃ₗ[k] α →₀ Coinvariants ρ :=
LinearEquiv.ofLinear (coinvariantsToFinsupp ρ α) (finsuppToCoinvariants ρ α)
(by ext; simp) (by ext; simp)
@[simp]
lemma coinvariantsFinsuppLEquiv_apply (x : Coinvariants (ρ.finsupp α)) :
coinvariantsFinsuppLEquiv ρ α x = coinvariantsToFinsupp ρ α x := by rfl
end Finsupp
section TensorProduct
open TensorProduct Coinvariants Finsupp
variable {k G V W : Type*} [CommRing k] [Group G] [AddCommGroup V] [Module k V]
[AddCommGroup W] [Module k W] (ρ : Representation k G V) (τ : Representation k G W)
-- the next two lemmas eliminate inverses
@[simp]
lemma Coinvariants.mk_inv_tmul (x : V) (y : W) (g : G) :
Coinvariants.mk (ρ.tprod τ) (ρ g⁻¹ x ⊗ₜ[k] y) = Coinvariants.mk (ρ.tprod τ) (x ⊗ₜ[k] τ g y) :=
(mk_eq_iff _).2 <| mem_ker_of_eq g⁻¹ (x ⊗ₜ[k] τ g y) _ <| by simp
@[simp]
lemma Coinvariants.mk_tmul_inv (x : V) (y : W) (g : G) :
Coinvariants.mk (ρ.tprod τ) (x ⊗ₜ[k] τ g⁻¹ y) = Coinvariants.mk (ρ.tprod τ) (ρ g x ⊗ₜ[k] y) :=
(mk_eq_iff _).2 <| mem_ker_of_eq g⁻¹ (ρ g x ⊗ₜ[k] y) _ <| by simp
/-- Given a `k`-linear `G`-representation `V, ρ`, this is the map `(V ⊗ k[G])_G →ₗ[k] V` sending
`⟦v ⊗ single g r⟧ ↦ r • ρ(g⁻¹)(v)`. -/
noncomputable def ofCoinvariantsTprodLeftRegular :
Coinvariants (ρ.tprod (leftRegular k G)) →ₗ[k] V :=
Coinvariants.lift _ (TensorProduct.lift (Finsupp.linearCombination _ fun g => ρ g⁻¹) ∘ₗ
(TensorProduct.comm _ _ _).toLinearMap) fun _ => by ext; simp
@[simp]
lemma ofCoinvariantsTprodLeftRegular_mk_tmul_single (x : V) (g : G) (r : k) :
ofCoinvariantsTprodLeftRegular ρ (Coinvariants.mk _ (x ⊗ₜ Finsupp.single g r)) = r • ρ g⁻¹ x :=
congr($(Finsupp.linearCombination_single k (v := fun g => ρ g⁻¹) r g) x)
/-- Given a `k`-linear `G`-representation `(V, ρ)`, this is the linear equivalence
`(V ⊗ k[G])_G ≃ₗ[k] V` sending `⟦v ⊗ single g r⟧ ↦ r • ρ(g⁻¹)(v)`. -/
@[simps! symm_apply]
noncomputable def coinvariantsTprodLeftRegularLEquiv :
Coinvariants (ρ.tprod (leftRegular k G)) ≃ₗ[k] V :=
LinearEquiv.ofLinear (ofCoinvariantsTprodLeftRegular ρ)
(Coinvariants.mk _ ∘ₗ (TensorProduct.mk k V (G →₀ k)).flip (single 1 1))
(by ext; simp) (by ext; simp)
@[simp]
lemma coinvariantsTprodLeftRegularLEquiv_apply (x : (ρ.tprod (leftRegular k G)).Coinvariants) :
coinvariantsTprodLeftRegularLEquiv ρ x = ofCoinvariantsTprodLeftRegular ρ x := by
rfl
end TensorProduct
end Representation
namespace Rep
open CategoryTheory Representation
variable {k G : Type u} [CommRing k]
noncomputable section
variable [Group G] (A : Rep k G) (S : Subgroup G) [S.Normal]
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `A` restricts to a `G`-representation on
the kernel of the quotient map to the `S`-coinvariants `A_S`. -/
abbrev toCoinvariantsKer : Rep k G := Rep.of (A.ρ.toCoinvariantsKer S)
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `A` induces a `G`-representation on
the `S`-coinvariants `A_S`. -/
abbrev toCoinvariants : Rep k G := Rep.of (A.ρ.toCoinvariants S)
/-- The quotient map `A → A_S` as a representation morphism. -/
def toCoinvariantsMkQ : A ⟶ toCoinvariants A S := mkQ _ _ _
@[simp]
lemma toCoinvariantsMkQ_hom :
(toCoinvariantsMkQ A S).hom.hom = Coinvariants.mk (A.ρ.comp S.subtype) := rfl
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` induces a `G ⧸ S`-representation on
the coinvariants of `ρ|_S`. -/
abbrev quotientToCoinvariants : Rep k (G ⧸ S) := ofQuotient (toCoinvariants A S) S
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `A` induces a short exact sequence of
`G`-representations `0 ⟶ Ker(mk) ⟶ A ⟶ A_S ⟶ 0` where `mk` is the quotient map to the
`S`-coinvariants `A_S`. -/
@[simps X₁ X₂ X₃ f g]
def coinvariantsShortComplex : ShortComplex (Rep k G) where
X₁ := toCoinvariantsKer A S
X₂ := A
X₃ := toCoinvariants A S
f := subtype ..
g := toCoinvariantsMkQ A S
zero := by ext x; exact (Submodule.Quotient.mk_eq_zero _).2 x.2
lemma coinvariantsShortComplex_shortExact : (coinvariantsShortComplex A S).ShortExact where
exact := (forget₂ _ (ModuleCat k)).reflects_exact_of_faithful _ <|
(ShortComplex.moduleCat_exact_iff _).2
fun x hx => ⟨(⟨x, (Submodule.Quotient.mk_eq_zero _).1 hx⟩ :
Representation.Coinvariants.ker <| A.ρ.comp S.subtype), rfl⟩
mono_f := (Rep.mono_iff_injective _).2 fun _ _ h => Subtype.ext h
epi_g := (Rep.epi_iff_surjective _).2 <| Submodule.mkQ_surjective _
end
variable (k G) [Monoid G] (A B : Rep k G)
/-- The functor sending a representation to its coinvariants. -/
@[simps! obj_carrier map_hom]
noncomputable def coinvariantsFunctor : Rep k G ⥤ ModuleCat k where
obj A := ModuleCat.of k A.ρ.Coinvariants
map f := ModuleCat.ofHom (Representation.Coinvariants.map _ _ f.hom.hom
fun g => ModuleCat.hom_ext_iff.1 <| f.comm g)
map_id _ := by simp
map_comp _ _ := by ext; simp
/-- The quotient map from a representation to its coinvariants induces a natural transformation
from the forgetful functor `Rep k G ⥤ ModuleCat k` to the coinvariants functor. -/
@[simps! app_hom]
noncomputable def coinvariantsMk : Action.forget (ModuleCat k) G ⟶ coinvariantsFunctor k G where
app (X : Rep k G) := ModuleCat.ofHom <| Representation.Coinvariants.mk X.ρ
instance (X : Rep k G) : Epi ((coinvariantsMk k G).app X) :=
(ModuleCat.epi_iff_surjective _).2 <| Representation.Coinvariants.mk_surjective X.ρ
variable {k G A B}
@[ext]
lemma coinvariantsFunctor_hom_ext {M : ModuleCat k} {f g : (coinvariantsFunctor k G).obj A ⟶ M}
(hfg : (coinvariantsMk k G).app A ≫ f = (coinvariantsMk k G).app A ≫ g) :
f = g := (cancel_epi _).1 hfg
/-- The linear map underlying a `G`-representation morphism `A ⟶ B`, where `B` has the trivial
representation, factors through `A_G`. -/
noncomputable abbrev desc [B.ρ.IsTrivial] (f : A ⟶ B) :
(coinvariantsFunctor k G).obj A ⟶ B.V :=
ModuleCat.ofHom <| Representation.Coinvariants.lift _ f.hom.hom fun _ => by
ext
have := hom_comm_apply f
simp_all
variable (k G)
instance : (coinvariantsFunctor k G).Additive where
instance : (coinvariantsFunctor k G).Linear k where
/-- The adjunction between the functor sending a representation to its coinvariants and the functor
equipping a module with the trivial representation. -/
@[simps]
noncomputable def coinvariantsAdjunction : coinvariantsFunctor k G ⊣ trivialFunctor k G where
unit := { app X := {
hom := (coinvariantsMk k G).app X
comm _ := by ext; simp [ModuleCat.endRingEquiv, trivialFunctor] }}
counit := { app X := desc (B := trivial k G X) (𝟙 _) }
@[simp]
theorem coinvariantsAdjunction_homEquiv_apply_hom {X : Rep k G} {Y : ModuleCat k}
(f : (coinvariantsFunctor k G).obj X ⟶ Y) :
((coinvariantsAdjunction k G).homEquiv X Y f).hom = (coinvariantsMk k G).app X ≫ f := by
rfl
@[simp]
theorem coinvariantsAdjunction_homEquiv_symm_apply_hom {X : Rep k G} {Y : ModuleCat k}
(f : X ⟶ (trivialFunctor k G).obj Y) :
((coinvariantsAdjunction k G).homEquiv X Y).symm f = desc f := by
ext
simp [coinvariantsAdjunction, Adjunction.homEquiv_symm_apply]
instance : (coinvariantsFunctor k G).PreservesZeroMorphisms where
instance : (coinvariantsFunctor k G).IsLeftAdjoint := (coinvariantsAdjunction k G).isLeftAdjoint
/-- The functor sending `A, B` to `(A ⊗[k] B)_G`. This is naturally isomorphic to the functor
sending `A, B` to `A ⊗[k[G]] B`, where we give `A` the `k[G]ᵐᵒᵖ`-module structure defined by
`g • a := A.ρ g⁻¹ a`. -/
noncomputable abbrev coinvariantsTensor : Rep k G ⥤ Rep k G ⥤ ModuleCat k :=
(Functor.postcompose₂.obj (coinvariantsFunctor k G)).obj (MonoidalCategory.curriedTensor _)
variable {k G} (A B)
/-- The bilinear map sending `a : A, b : B` to `⟦a ⊗ₜ b⟧` in `(A ⊗[k] B)_G`. -/
noncomputable abbrev coinvariantsTensorMk :
A →ₗ[k] B →ₗ[k] ((coinvariantsTensor k G).obj A).obj B :=
(TensorProduct.mk k A B).compr₂ (Coinvariants.mk _)
variable {A B}
lemma coinvariantsTensorMk_apply (a : A) (b : B) :
coinvariantsTensorMk A B a b = Coinvariants.mk _ (a ⊗ₜ[k] b) := rfl
@[ext]
lemma coinvariantsTensor_hom_ext {M : ModuleCat k}
{f g : ((coinvariantsTensor k G).obj A).obj B ⟶ M}
(hfg : (coinvariantsTensorMk A B).compr₂ f.hom = (coinvariantsTensorMk A B).compr₂ g.hom) :
f = g := coinvariantsFunctor_hom_ext <| ModuleCat.hom_ext <| TensorProduct.ext <| hfg
instance (A : Rep k G) : ((coinvariantsTensor k G).obj A).Additive where
instance (A : Rep k G) : ((coinvariantsTensor k G).obj A).Linear k where
section
variable (k : Type u) {G : Type u} [CommRing k] [Group G]
/-- Given a normal subgroup `S ≤ G`, this is the functor sending a `G`-representation `A` to the
`G ⧸ S`-representation it induces on `A_S`. -/
@[simps obj_V map_hom]
noncomputable def quotientToCoinvariantsFunctor (S : Subgroup G) [S.Normal] :
Rep k G ⥤ Rep k (G ⧸ S) where
obj X := X.quotientToCoinvariants S
map {X Y} f := {
hom := (coinvariantsFunctor k S).map ((Action.res _ S.subtype).map f)
comm g := QuotientGroup.induction_on g fun g => by
ext; simp [ModuleCat.endRingEquiv, hom_comm_apply] }
section Finsupp
variable {k} (A : Rep k G) (α : Type u) [DecidableEq α]
open MonoidalCategory Finsupp ModuleCat.MonoidalCategory
/-- Given a `k`-linear `G`-representation `(A, ρ)` and a type `α`, this is the map
`(A ⊗ (α →₀ k[G]))_G →ₗ[k] (α →₀ A)` sending
`⟦a ⊗ single x (single g r)⟧ ↦ single x (r • ρ(g⁻¹)(a)).` -/
noncomputable def coinvariantsTensorFreeToFinsupp :
(A ⊗ free k G α).ρ.Coinvariants →ₗ[k] (α →₀ A) :=
(coinvariantsFinsuppLEquiv _ α ≪≫ₗ lcongr (Equiv.refl α)
(coinvariantsTprodLeftRegularLEquiv A.ρ)).toLinearMap ∘ₗ
((coinvariantsFunctor k G).map (finsuppTensorRight A (leftRegular k G) α).hom).hom
variable {A α}
@[simp]
lemma coinvariantsTensorFreeToFinsupp_mk_tmul_single (x : A) (i : α) (g : G) (r : k) :
DFunLike.coe (F := (A.ρ.tprod (Representation.free k G α)).Coinvariants →ₗ[k] α →₀ A.V)
(coinvariantsTensorFreeToFinsupp A α) (Coinvariants.mk _ (x ⊗ₜ single i (single g r))) =
single i (r • A.ρ g⁻¹ x) := by
simp [tensorObj_carrier, coinvariantsTensorFreeToFinsupp,
Coinvariants.map, finsuppTensorRight, TensorProduct.finsuppRight]
variable (A α)
/-- Given a `k`-linear `G`-representation `(A, ρ)` and a type `α`, this is the map
`(α →₀ A) →ₗ[k] (A ⊗ (α →₀ k[G]))_G` sending `single x a ↦ ⟦a ⊗ₜ single x 1⟧.` -/
noncomputable def finsuppToCoinvariantsTensorFree :
(α →₀ A) →ₗ[k] Coinvariants (A ⊗ (free k G α)).ρ :=
((coinvariantsFunctor k G).map ((finsuppTensorRight A (leftRegular k G) α)).inv).hom ∘ₗ
(coinvariantsFinsuppLEquiv _ α ≪≫ₗ
lcongr (Equiv.refl α) (coinvariantsTprodLeftRegularLEquiv A.ρ)).symm.toLinearMap
variable {A α}
@[simp]
lemma finsuppToCoinvariantsTensorFree_single (i : α) (x : A) :
DFunLike.coe (F := (α →₀ A.V) →ₗ[k] (A.ρ.tprod (Representation.free k G α)).Coinvariants)
(finsuppToCoinvariantsTensorFree A α) (single i x) =
Coinvariants.mk _ (x ⊗ₜ single i (single (1 : G) (1 : k))) := by
simp [finsuppToCoinvariantsTensorFree, Coinvariants.map, tensorObj_carrier]
variable (A α)
/-- Given a `k`-linear `G`-representation `(A, ρ)` and a type `α`, this is the linear equivalence
`(A ⊗ (α →₀ k[G]))_G ≃ₗ[k] (α →₀ A)` sending
`⟦a ⊗ single x (single g r)⟧ ↦ single x (r • ρ(g⁻¹)(a)).` -/
@[simps! symm_apply]
noncomputable abbrev coinvariantsTensorFreeLEquiv :
Coinvariants (A ⊗ free k G α).ρ ≃ₗ[k] (α →₀ A) :=
LinearEquiv.ofLinear (coinvariantsTensorFreeToFinsupp A α) (finsuppToCoinvariantsTensorFree A α)
(lhom_ext fun i x => by
simp [finsuppToCoinvariantsTensorFree_single i,
coinvariantsTensorFreeToFinsupp_mk_tmul_single x]) <|
Coinvariants.hom_ext <| TensorProduct.ext <| LinearMap.ext fun a => lhom_ext' fun i =>
lhom_ext fun g r => by
simp [coinvariantsTensorFreeToFinsupp_mk_tmul_single a,
finsuppToCoinvariantsTensorFree_single (A := A) i, TensorProduct.smul_tmul]
@[simp]
lemma coinvariantsTensorFreeLEquiv_apply (x : (A ⊗ free k G α).ρ.Coinvariants) :
DFunLike.coe (F := (A.ρ.tprod (Representation.free k G α)).Coinvariants →ₗ[k] α →₀ A)
(A.coinvariantsTensorFreeToFinsupp α) x = coinvariantsTensorFreeToFinsupp A α x := by
rfl
end Finsupp
end
end Rep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Tannaka.lean | import Mathlib.RepresentationTheory.FDRep
/-!
# Tannaka duality for finite groups
In this file we prove Tannaka duality for finite groups.
The theorem can be formulated as follows: for any integral domain `k`, a finite group `G` can be
recovered from `FDRep k G`, the monoidal category of finite-dimensional `k`-linear representations
of `G`, and the monoidal forgetful functor `forget : FDRep k G ⥤ FGModuleCat k`.
The main result is the isomorphism `equiv : G ≃* Aut (forget k G)`.
## Reference
<https://math.leidenuniv.nl/scripties/1bachCommelin.pdf>
-/
noncomputable section
open CategoryTheory MonoidalCategory ModuleCat Finset Pi
universe u
namespace TannakaDuality
namespace FiniteGroup
variable {k G : Type u} [CommRing k] [Group G]
section definitions
instance : (forget₂ (FDRep k G) (FGModuleCat k)).Monoidal := by
change (Action.forget _ _).Monoidal; infer_instance
variable (k G) in
/-- The monoidal forgetful functor from `FDRep k G` to `FGModuleCat k`. -/
def forget := LaxMonoidalFunctor.of (forget₂ (FDRep k G) (FGModuleCat k))
@[simp] lemma forget_obj (X : FDRep k G) : (forget k G).obj X = X.V := rfl
@[simp] lemma forget_map (X Y : FDRep k G) (f : X ⟶ Y) : (forget k G).map f = f.hom := rfl
/-- Definition of `equivHom g : Aut (forget k G)` by its components. -/
@[simps]
def equivApp (g : G) (X : FDRep k G) : X.V ≅ X.V where
hom := ofHom (X.ρ g)
inv := ofHom (X.ρ g⁻¹)
hom_inv_id := by
ext x
simp
inv_hom_id := by
ext x
simp
variable (k G) in
/-- The group homomorphism `G →* Aut (forget k G)` shown to be an isomorphism. -/
@[simps]
def equivHom : G →* Aut (forget k G) where
toFun g :=
LaxMonoidalFunctor.isoOfComponents (equivApp g) (fun f ↦ (f.comm g).symm) rfl (by intros; rfl)
map_one' := by ext; simp; rfl
map_mul' _ _ := by ext; simp; rfl
/-- The representation on `G → k` induced by multiplication on the right in `G`. -/
def rightRegular : Representation k G (G → k) where
toFun s :=
{ toFun f t := f (t * s)
map_add' _ _ := rfl
map_smul' _ _ := rfl }
map_one' := by
ext
simp
map_mul' _ _ := by
ext
simp [mul_assoc]
@[simp]
lemma rightRegular_apply (s t : G) (f : G → k) : rightRegular s f t = f (t * s) := rfl
/-- The representation on `G → k` induced by multiplication on the left in `G`. -/
def leftRegular : Representation k G (G → k) where
toFun s :=
{ toFun f t := f (s⁻¹ * t)
map_add' _ _ := rfl
map_smul' _ _ := rfl }
map_one' := by
ext
simp
map_mul' _ _ := by
ext
simp [mul_assoc]
@[simp]
lemma leftRegular_apply (s t : G) (f : G → k) : leftRegular s f t = f (s⁻¹ * t) := rfl
/-- The right regular representation `rightRegular` on `G → k` as a `FDRep k G`. -/
@[simp]
def rightFDRep [Finite G] : FDRep k G := FDRep.of rightRegular
end definitions
variable [Finite G]
lemma equivHom_injective [Nontrivial k] : Function.Injective (equivHom k G) := by
intro s t h
classical
apply_fun (fun x ↦ (x.hom.hom.app rightFDRep).hom (single t 1) 1) at h
simp_all [single_apply]
@[deprecated (since := "2025-04-27")]
alias equivHom_inj := equivHom_injective
/-- The `FDRep k G` morphism induced by multiplication on `G → k`. -/
def mulRepHom : rightFDRep (k := k) (G := G) ⊗ rightFDRep ⟶ rightFDRep where
hom := ofHom (LinearMap.mul' k (G → k))
comm := by
intro
ext u
refine TensorProduct.induction_on u rfl (fun _ _ ↦ rfl) (fun _ _ hx hy ↦ ?_)
simp only [map_add, hx, hy]
/-- The `rightFDRep` component of `η : Aut (forget k G)` preserves multiplication -/
lemma map_mul_toRightFDRepComp (η : Aut (forget k G)) (f g : G → k) :
let α : (G → k) →ₗ[k] (G → k) := (η.hom.hom.app rightFDRep).hom
α (f * g) = (α f) * (α g) := by
have nat := η.hom.hom.naturality mulRepHom
have tensor (X Y) : η.hom.hom.app (X ⊗ Y) = (η.hom.hom.app X ⊗ₘ η.hom.hom.app Y) :=
η.hom.isMonoidal.tensor X Y
rw [tensor] at nat
apply_fun (Hom.hom · (f ⊗ₜ[k] g)) at nat
exact nat
/-- The `rightFDRep` component of `η : Aut (forget k G)` gives rise to
an algebra morphism `(G → k) →ₐ[k] (G → k)`. -/
def algHomOfRightFDRepComp (η : Aut (forget k G)) : (G → k) →ₐ[k] (G → k) := by
let α : (G → k) →ₗ[k] (G → k) := (η.hom.hom.app rightFDRep).hom
let α_inv : (G → k) →ₗ[k] (G → k) := (η.inv.hom.app rightFDRep).hom
refine AlgHom.ofLinearMap α ?_ (map_mul_toRightFDRepComp η)
suffices α (α_inv 1) = (1 : G → k) by
have h := this
rwa [← one_mul (α_inv 1), map_mul_toRightFDRepComp, h, mul_one] at this
have := η.inv_hom_id
apply_fun (fun x ↦ (x.hom.app rightFDRep).hom (1 : G → k)) at this
exact this
/-- For `v : X` and `G` a finite group, the `G`-equivariant linear map from the right
regular representation `rightFDRep` to `X` sending `single 1 1` to `v`. -/
@[simps]
def sumSMulInv [Fintype G] {X : FDRep k G} (v : X) : (G → k) →ₗ[k] X where
toFun f := ∑ s : G, (f s) • (X.ρ s⁻¹ v)
map_add' _ _ := by simp [add_smul, sum_add_distrib]
map_smul' _ _ := by simp [smul_sum, smul_smul]
omit [Finite G] in
lemma sumSMulInv_single_id [Fintype G] [DecidableEq G] {X : FDRep k G} (v : X) :
∑ s : G, (single 1 1 : G → k) s • (X.ρ s⁻¹) v = v := by
simp
/-- For `v : X` and `G` a finite group, the representation morphism from the right
regular representation `rightFDRep` to `X` sending `single 1 1` to `v`. -/
@[simps]
def ofRightFDRep [Fintype G] (X : FDRep k G) (v : X) : rightFDRep ⟶ X where
hom := ofHom (sumSMulInv v)
comm t := by
ext f
let φ_term (X : FDRep k G) (f : G → k) v s := (f s) • (X.ρ s⁻¹ v)
have := sum_map univ (mulRightEmbedding t⁻¹) (φ_term X (rightRegular t f) v)
simpa [φ_term] using this
lemma toRightFDRepComp_injective {η₁ η₂ : Aut (forget k G)}
(h : η₁.hom.hom.app rightFDRep = η₂.hom.hom.app rightFDRep) : η₁ = η₂ := by
have := Fintype.ofFinite G
classical
ext X v
have h1 := η₁.hom.hom.naturality (ofRightFDRep X v)
have h2 := η₂.hom.hom.naturality (ofRightFDRep X v)
rw [h, ← h2] at h1
simpa using congr(($h1).hom (single 1 1))
/-- `leftRegular` as a morphism `rightFDRep k G ⟶ rightFDRep k G` in `FDRep k G`. -/
def leftRegularFDRepHom (s : G) : End (rightFDRep : FDRep k G) where
hom := ofHom (leftRegular s)
comm _ := by
ext f
funext _
apply congrArg f
exact mul_assoc ..
lemma toRightFDRepComp_in_rightRegular [IsDomain k] (η : Aut (forget k G)) :
∃ (s : G), (η.hom.hom.app rightFDRep).hom = rightRegular s := by
classical
obtain ⟨s, hs⟩ := ((evalAlgHom _ _ 1).comp (algHomOfRightFDRepComp η)).eq_piEvalAlgHom
refine ⟨s, (basisFun k G).ext fun u ↦ ?_⟩
simp only [rightFDRep, forget_obj]
ext t
have nat := η.hom.hom.naturality (leftRegularFDRepHom t⁻¹)
calc
_ = leftRegular t⁻¹ ((η.hom.hom.app rightFDRep).hom (single u 1)) 1 := by simp
_ = (η.hom.hom.app rightFDRep).hom (leftRegular t⁻¹ (single u 1)) 1 :=
congrFun congr(($nat.symm).hom (single u 1)) 1
_ = evalAlgHom _ _ s (leftRegular t⁻¹ (single u 1)) :=
congr($hs (leftRegular t⁻¹ (single u 1)))
_ = _ := by by_cases u = t * s <;> simp_all [single_apply]
lemma equivHom_surjective [IsDomain k] : Function.Surjective (equivHom k G) := by
intro η
obtain ⟨s, h⟩ := toRightFDRepComp_in_rightRegular η
exact ⟨s, toRightFDRepComp_injective (hom_ext h.symm)⟩
variable (k G) in
/-- Tannaka duality for finite groups:
A finite group `G` is isomorphic to `Aut (forget k G)`, where `k` is any integral domain,
and `forget k G` is the monoidal forgetful functor `FDRep k G ⥤ FGModuleCat k G`. -/
def equiv [IsDomain k] : G ≃* Aut (forget k G) :=
MulEquiv.ofBijective (equivHom k G) ⟨equivHom_injective, equivHom_surjective⟩
end FiniteGroup
end TannakaDuality
end |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Basic.lean | import Mathlib.LinearAlgebra.Contraction
import Mathlib.Algebra.Group.Equiv.TypeTags
/-!
# Monoid representations
This file introduces monoid representations and their characters and defines a few ways to construct
representations.
## Main definitions
* `Representation`
* `Representation.directSum`
* `Representation.prod`
* `Representation.tprod`
* `Representation.linHom`
* `Representation.dual`
* `Representation.free`
## Implementation notes
Representations of a monoid `G` on a `k`-module `V` are implemented as
homomorphisms `G →* (V →ₗ[k] V)`. We use the abbreviation `Representation` for this hom space.
The theorem `asAlgebraHom_def` constructs a module over the group `k`-algebra of `G` (implemented
as `MonoidAlgebra k G`) corresponding to a representation. If `ρ : Representation k G V`, this
module can be accessed via `ρ.asModule`. Conversely, given a `MonoidAlgebra k G`-module `M`,
`M.ofModule` is the associated representation seen as a homomorphism.
-/
open MonoidAlgebra (lift of)
open LinearMap Module
section
variable (k G V : Type*) [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V]
/-- A representation of `G` on the `k`-module `V` is a homomorphism `G →* (V →ₗ[k] V)`.
-/
abbrev Representation :=
G →* V →ₗ[k] V
end
namespace Representation
section trivial
variable (k G V : Type*) [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V]
/-- The trivial representation of `G` on a `k`-module V.
-/
def trivial : Representation k G V :=
1
variable {G V}
@[simp]
theorem trivial_apply (g : G) (v : V) : trivial k G V g v = v :=
rfl
variable {k}
/-- A predicate for representations that fix every element. -/
class IsTrivial (ρ : Representation k G V) : Prop where
out : ∀ g, ρ g = LinearMap.id := by aesop
instance : IsTrivial (trivial k G V) where
@[simp]
theorem isTrivial_def (ρ : Representation k G V) [IsTrivial ρ] (g : G) :
ρ g = LinearMap.id := IsTrivial.out g
theorem isTrivial_apply (ρ : Representation k G V) [IsTrivial ρ] (g : G) (x : V) :
ρ g x = x := congr($(isTrivial_def ρ g) x)
end trivial
section Group
variable {k G V : Type*} [CommSemiring k] [Group G] [AddCommMonoid V] [Module k V]
(ρ : Representation k G V)
@[simp]
theorem inv_self_apply (g : G) (x : V) :
ρ g⁻¹ (ρ g x) = x := by
simp [← Module.End.mul_apply, ← map_mul]
@[simp]
theorem self_inv_apply (g : G) (x : V) :
ρ g (ρ g⁻¹ x) = x := by
simp [← Module.End.mul_apply, ← map_mul]
lemma apply_bijective (g : G) :
Function.Bijective (ρ g) :=
Equiv.bijective ⟨ρ g, ρ g⁻¹, inv_self_apply ρ g, self_inv_apply ρ g⟩
end Group
section MonoidAlgebra
variable {k G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V]
variable (ρ : Representation k G V)
/-- A `k`-linear representation of `G` on `V` can be thought of as
an algebra map from `MonoidAlgebra k G` into the `k`-linear endomorphisms of `V`.
-/
noncomputable def asAlgebraHom : MonoidAlgebra k G →ₐ[k] Module.End k V :=
(lift k G _) ρ
theorem asAlgebraHom_def : asAlgebraHom ρ = (lift k G _) ρ :=
rfl
@[simp]
theorem asAlgebraHom_single (g : G) (r : k) :
asAlgebraHom ρ (MonoidAlgebra.single g r) = r • ρ g := by
simp only [asAlgebraHom_def, MonoidAlgebra.lift_single]
theorem asAlgebraHom_single_one (g : G) : asAlgebraHom ρ (MonoidAlgebra.single g 1) = ρ g := by simp
theorem asAlgebraHom_of (g : G) : asAlgebraHom ρ (of k G g) = ρ g := by
simp only [MonoidAlgebra.of_apply, asAlgebraHom_single, one_smul]
/-- If `ρ : Representation k G V`, then `ρ.asModule` is a type synonym for `V`,
which we equip with an instance `Module (MonoidAlgebra k G) ρ.asModule`.
You should use `asModuleEquiv : ρ.asModule ≃+ V` to translate terms.
-/
@[nolint unusedArguments]
def asModule (_ : Representation k G V) :=
V
deriving AddCommMonoid, Module k
instance : Inhabited ρ.asModule where
default := 0
/-- A `k`-linear representation of `G` on `V` can be thought of as
a module over `MonoidAlgebra k G`.
-/
noncomputable instance : Module (MonoidAlgebra k G) ρ.asModule :=
Module.compHom V (asAlgebraHom ρ).toRingHom
/-- The additive equivalence from the `Module (MonoidAlgebra k G)` to the original vector space
of the representative.
This is just the identity, but it is helpful for typechecking and keeping track of instances.
-/
def asModuleEquiv : ρ.asModule ≃ₗ[k] V :=
LinearEquiv.refl _ _
@[simp]
theorem asModuleEquiv_map_smul (r : MonoidAlgebra k G) (x : ρ.asModule) :
ρ.asModuleEquiv (r • x) = ρ.asAlgebraHom r (ρ.asModuleEquiv x) :=
rfl
theorem asModuleEquiv_symm_map_smul (r : k) (x : V) :
ρ.asModuleEquiv.symm (r • x) = algebraMap k (MonoidAlgebra k G) r • ρ.asModuleEquiv.symm x := by
rw [LinearEquiv.symm_apply_eq]
simp
@[simp]
theorem asModuleEquiv_symm_map_rho (g : G) (x : V) :
ρ.asModuleEquiv.symm (ρ g x) = MonoidAlgebra.of k G g • ρ.asModuleEquiv.symm x := by
rw [LinearEquiv.symm_apply_eq]
simp
/-- Build a `Representation k G M` from a `[Module (MonoidAlgebra k G) M]`.
This version is not always what we want, as it relies on an existing `[Module k M]`
instance, along with a `[IsScalarTower k (MonoidAlgebra k G) M]` instance.
We remedy this below in `ofModule`
(with the tradeoff that the representation is defined
only on a type synonym of the original module.)
-/
noncomputable def ofModule' (M : Type*) [AddCommMonoid M] [Module k M]
[Module (MonoidAlgebra k G) M] [IsScalarTower k (MonoidAlgebra k G) M] : Representation k G M :=
(MonoidAlgebra.lift k G (M →ₗ[k] M)).symm (Algebra.lsmul k k M)
section
variable (M : Type*) [AddCommMonoid M] [Module (MonoidAlgebra k G) M]
/-- Build a `Representation` from a `[Module (MonoidAlgebra k G) M]`.
Note that the representation is built on `restrictScalars k (MonoidAlgebra k G) M`,
rather than on `M` itself.
-/
noncomputable def ofModule : Representation k G (RestrictScalars k (MonoidAlgebra k G) M) :=
(MonoidAlgebra.lift k G
(RestrictScalars k (MonoidAlgebra k G) M →ₗ[k]
RestrictScalars k (MonoidAlgebra k G) M)).symm
(RestrictScalars.lsmul k (MonoidAlgebra k G) M)
/-!
## `ofModule` and `asModule` are inverses.
This requires a little care in both directions:
this is a categorical equivalence, not an isomorphism.
See `Rep.equivalenceModuleMonoidAlgebra` for the full statement.
Starting with `ρ : Representation k G V`, converting to a module and back again
we have a `Representation k G (restrictScalars k (MonoidAlgebra k G) ρ.asModule)`.
To compare these, we use the composition of `restrictScalarsAddEquiv` and `ρ.asModuleEquiv`.
Similarly, starting with `Module (MonoidAlgebra k G) M`,
after we convert to a representation and back to a module,
we have `Module (MonoidAlgebra k G) (restrictScalars k (MonoidAlgebra k G) M)`.
-/
@[simp]
theorem ofModule_asAlgebraHom_apply_apply (r : MonoidAlgebra k G)
(m : RestrictScalars k (MonoidAlgebra k G) M) :
((ofModule M).asAlgebraHom r) m =
(RestrictScalars.addEquiv _ _ _).symm (r • RestrictScalars.addEquiv _ _ _ m) := by
apply MonoidAlgebra.induction_on r
· intro g
simp only [one_smul, MonoidAlgebra.lift_symm_apply, MonoidAlgebra.of_apply,
Representation.asAlgebraHom_single, Representation.ofModule,
RestrictScalars.lsmul_apply_apply]
· intro f g fw gw
simp only [fw, gw, map_add, add_smul, LinearMap.add_apply]
· intro r f w
simp only [w, map_smul, LinearMap.smul_apply, RestrictScalars.addEquiv_symm_map_smul_smul]
@[simp]
theorem ofModule_asModule_act (g : G) (x : RestrictScalars k (MonoidAlgebra k G) ρ.asModule) :
ofModule ρ.asModule g x =
(RestrictScalars.addEquiv _ _ _).symm
(ρ.asModuleEquiv.symm (ρ g (ρ.asModuleEquiv (RestrictScalars.addEquiv _ _ _ x)))) := by
apply_fun RestrictScalars.addEquiv _ _ ρ.asModule using
(RestrictScalars.addEquiv _ _ ρ.asModule).injective
dsimp [ofModule, RestrictScalars.lsmul_apply_apply]
simp
theorem smul_ofModule_asModule (r : MonoidAlgebra k G) (m : (ofModule M).asModule) :
(RestrictScalars.addEquiv k _ _) ((ofModule M).asModuleEquiv (r • m)) =
r • (RestrictScalars.addEquiv k _ _) ((ofModule M).asModuleEquiv (G := G) m) := by
dsimp
simp only [AddEquiv.apply_symm_apply, ofModule_asAlgebraHom_apply_apply]
end
@[simp]
lemma single_smul (t : k) (g : G) (v : ρ.asModule) :
MonoidAlgebra.single (g : G) t • v = t • ρ g (ρ.asModuleEquiv v) := by
rw [← LinearMap.smul_apply, ← asAlgebraHom_single, ← asModuleEquiv_map_smul]
rfl
instance : IsScalarTower k (MonoidAlgebra k G) ρ.asModule where
smul_assoc t x v := by
revert t
apply x.induction_on
· simp
· intro y z hy hz
simp [add_smul, hy, hz]
· intro s y hy t
rw [← smul_assoc, smul_eq_mul, hy (t * s), ← smul_eq_mul, smul_assoc]
aesop
end MonoidAlgebra
section Norm
variable {k G V : Type*} [CommSemiring k] [Group G] [Fintype G] [AddCommMonoid V] [Module k V]
variable (ρ : Representation k G V)
/-- Given a representation `(V, ρ)` of a finite group `G`, `norm ρ` is the linear map `V →ₗ[k] V`
defined by `x ↦ ∑ ρ g x` for `g` in `G`. -/
def norm : Module.End k V := ∑ g : G, ρ g
@[simp]
lemma norm_comp_self (g : G) : norm ρ ∘ₗ ρ g = norm ρ := by
ext
simpa [norm] using Fintype.sum_bijective (· * g) (Group.mulRight_bijective g) _ _ <| by simp
@[simp]
lemma norm_self_apply (g : G) (x : V) : norm ρ (ρ g x) = norm ρ x :=
LinearMap.ext_iff.1 (norm_comp_self _ _) x
@[simp]
lemma self_comp_norm (g : G) : ρ g ∘ₗ norm ρ = norm ρ := by
ext
simpa [norm] using Fintype.sum_bijective (g * ·) (Group.mulLeft_bijective g) _ _ <| by simp
@[simp]
lemma self_norm_apply (g : G) (x : V) : ρ g (norm ρ x) = norm ρ x :=
LinearMap.ext_iff.1 (self_comp_norm _ _) x
end Norm
section Subrepresentation
variable {k G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V]
(ρ : Representation k G V)
/-- Given a `k`-linear `G`-representation `(V, ρ)`, this is the representation defined by
restricting `ρ` to a `G`-invariant `k`-submodule of `V`. -/
@[simps]
def subrepresentation (W : Submodule k V) (le_comap : ∀ g, W ≤ W.comap (ρ g)) :
Representation k G W where
toFun g := (ρ g).restrict <| le_comap g
map_one' := by ext; simp
map_mul' _ _ := by ext; simp
end Subrepresentation
section Quotient
variable {k G V : Type*} [CommRing k] [Monoid G] [AddCommGroup V] [Module k V]
(ρ : Representation k G V)
/-- Given a `k`-linear `G`-representation `(V, ρ)` and a `G`-invariant `k`-submodule `W ≤ V`, this
is the representation induced on `V ⧸ W` by `ρ`. -/
@[simps]
def quotient (W : Submodule k V) (le_comap : ∀ g, W ≤ W.comap (ρ g)) :
Representation k G (V ⧸ W) where
toFun g := Submodule.mapQ _ _ (ρ g) <| le_comap g
map_one' := by ext; simp
map_mul' _ _ := by ext; simp
end Quotient
section OfQuotient
variable {k G V : Type*} [CommSemiring k] [Group G] [AddCommMonoid V] [Module k V]
variable (ρ : Representation k G V) (S : Subgroup G)
lemma apply_eq_of_coe_eq [IsTrivial (ρ.comp S.subtype)] (g h : G) (hgh : (g : G ⧸ S) = h) :
ρ g = ρ h := by
ext x
apply (ρ.apply_bijective g⁻¹).1
simpa [← Module.End.mul_apply, ← map_mul, -isTrivial_def] using
(congr($(isTrivial_def (ρ.comp S.subtype) ⟨g⁻¹ * h, QuotientGroup.eq.1 hgh⟩) x)).symm
variable [S.Normal]
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` which is trivial on `S` factors
through `G ⧸ S`. -/
def ofQuotient [IsTrivial (ρ.comp S.subtype)] :
Representation k (G ⧸ S) V :=
(QuotientGroup.con S).lift ρ <| by
rintro x y ⟨⟨z, hz⟩, rfl⟩
ext w
change ρ (_ * z.unop) _ = _
exact congr($(apply_eq_of_coe_eq ρ S _ _ (by simp_all)) w)
@[simp]
lemma ofQuotient_coe_apply [IsTrivial (ρ.comp S.subtype)] (g : G) (x : V) :
ofQuotient ρ S (g : G ⧸ S) x = ρ g x :=
rfl
end OfQuotient
section AddCommGroup
variable {k G V : Type*} [CommRing k] [Monoid G] [I : AddCommGroup V] [Module k V]
variable (ρ : Representation k G V)
instance : AddCommGroup ρ.asModule :=
I
/- Given a representation `(V, ρ)` of a monoid `G`, this says
`(ρ(g) - Id)(x + ρ(g)(x) + ... + ρ(gⁿ)(x)) = ρ(gⁿ⁺¹)(x) - x` for all `n : ℕ, g : G` and `x : V`. -/
lemma apply_sub_id_partialSum_eq (n : ℕ) (g : G) (x : V) :
(ρ g - LinearMap.id (R := k) (M := V)) ((Fin.last _).partialSum
(fun (j : Fin (n + 1)) => ρ (g ^ (j : ℕ)) x)) = ρ (g ^ (n + 1)) x - x := by
induction n with
| zero => simp [Fin.partialSum]
| succ n h =>
have : Fin.init (fun (j : Fin (n + 2)) => ρ (g ^ (j : ℕ)) x) =
fun (j : Fin (n + 1)) => ρ (g ^ (j : ℕ)) x := by ext; simp [Fin.init]
rw [← Fin.succ_eq_last_succ.2 rfl, Fin.partialSum_succ, ← Fin.partialSum_init, map_add,
this, h]
simp [pow_succ']
end AddCommGroup
section MulAction
variable (k : Type*) [CommSemiring k] (G : Type*) [Monoid G] (H : Type*) [MulAction G H]
/-- A `G`-action on `H` induces a representation `G →* End(k[H])` in the natural way. -/
noncomputable def ofMulAction : Representation k G (H →₀ k) where
toFun g := Finsupp.lmapDomain k k (g • ·)
map_one' := by
ext x y
simp
map_mul' x y := by
ext z w
simp [mul_smul]
/-- The natural `k`-linear `G`-representation on `k[G]` induced by left multiplication in `G`. -/
noncomputable abbrev leftRegular := ofMulAction k G G
/-- The natural `k`-linear `G`-representation on `k[Gⁿ]` induced by left multiplication in `G`. -/
noncomputable abbrev diagonal (n : ℕ) := ofMulAction k G (Fin n → G)
variable {k G H}
theorem ofMulAction_def (g : G) : ofMulAction k G H g = Finsupp.lmapDomain k k (g • ·) :=
rfl
@[simp]
theorem ofMulAction_single (g : G) (x : H) (r : k) :
ofMulAction k G H g (Finsupp.single x r) = Finsupp.single (g • x) r :=
Finsupp.mapDomain_single
end MulAction
section DistribMulAction
variable (k G A : Type*) [CommSemiring k] [Monoid G] [AddCommMonoid A] [Module k A]
[DistribMulAction G A] [SMulCommClass G k A]
/-- Turns a `k`-module `A` with a compatible `DistribMulAction` of a monoid `G` into a
`k`-linear `G`-representation on `A`. -/
def ofDistribMulAction : Representation k G A where
toFun := fun m =>
{ DistribMulAction.toAddMonoidEnd G A m with
map_smul' := smul_comm _ }
map_one' := by ext; exact one_smul _ _
map_mul' := by intros; ext; exact mul_smul _ _ _
variable {k G A}
@[simp] theorem ofDistribMulAction_apply_apply (g : G) (a : A) :
ofDistribMulAction k G A g a = g • a := rfl
@[simp]
theorem norm_ofDistribMulAction_eq {G : Type*} [Group G] [Fintype G]
[DistribMulAction G A] [SMulCommClass G k A] (x : A) :
(ofDistribMulAction k G A).norm x = ∑ g : G, g • x := by
simp [norm]
end DistribMulAction
section MulDistribMulAction
variable (M G : Type*) [Monoid M] [CommGroup G] [MulDistribMulAction M G]
/-- Turns a `CommGroup` `G` with a `MulDistribMulAction` of a monoid `M` into a
`ℤ`-linear `M`-representation on `Additive G`. -/
def ofMulDistribMulAction : Representation ℤ M (Additive G) :=
(addMonoidEndRingEquivInt (Additive G) : AddMonoid.End (Additive G) →* _).comp
((monoidEndToAdditive G : _ →* _).comp (MulDistribMulAction.toMonoidEnd M G))
@[simp] theorem ofMulDistribMulAction_apply_apply (g : M) (a : Additive G) :
ofMulDistribMulAction M G g a = Additive.ofMul (g • a.toMul) := rfl
@[simp]
theorem norm_ofMulDistribMulAction_eq {G M : Type} [Group G] [Fintype G]
[CommGroup M] [MulDistribMulAction G M] (x : Additive M) :
Additive.toMul ((ofMulDistribMulAction G M).norm x) =
∏ g : G, g • Additive.toMul x := by
simp [norm]
end MulDistribMulAction
section Group
variable {k G V : Type*} [CommSemiring k] [Group G] [AddCommMonoid V] [Module k V]
variable (ρ : Representation k G V)
@[simp]
theorem ofMulAction_apply {H : Type*} [MulAction G H] (g : G) (f : H →₀ k) (h : H) :
ofMulAction k G H g f h = f (g⁻¹ • h) := by
conv_lhs => rw [← smul_inv_smul g h]
let h' := g⁻¹ • h
change ofMulAction k G H g f (g • h') = f h'
have hg : Function.Injective (g • · : H → H) := by
intro h₁ h₂
simp
simp only [ofMulAction_def, Finsupp.lmapDomain_apply, Finsupp.mapDomain_apply, hg]
-- Noncomputable since `MonoidAlgebra.instMul` is now noncomputable
noncomputable instance :
HMul (MonoidAlgebra k G) ((ofMulAction k G G).asModule) (MonoidAlgebra k G) :=
inferInstanceAs <| HMul (MonoidAlgebra k G) (MonoidAlgebra k G) (MonoidAlgebra k G)
theorem ofMulAction_self_smul_eq_mul (x : MonoidAlgebra k G) (y : (ofMulAction k G G).asModule) :
x • y = (x * y : MonoidAlgebra k G) := by
induction x using MonoidAlgebra.induction_on with
| hM g =>
change asAlgebraHom (ofMulAction k G G) _ _ = _
ext
-- Porting note: single_mul_apply not firing in simp without parentheses, probably due to the
-- defeq abuse in `change` above.
simp [(MonoidAlgebra.single_mul_apply)]
| hadd x y hx hy => simp only [hx, hy, add_mul, add_smul]
| hsmul r x hx => simp [← hx]
/-- If we equip `k[G]` with the `k`-linear `G`-representation induced by the left regular action of
`G` on itself, the resulting object is isomorphic as a `k[G]`-module to `k[G]` with its natural
`k[G]`-module structure. -/
@[simps]
noncomputable def ofMulActionSelfAsModuleEquiv :
(ofMulAction k G G).asModule ≃ₗ[MonoidAlgebra k G] MonoidAlgebra k G :=
{ (asModuleEquiv _).toAddEquiv with map_smul' := ofMulAction_self_smul_eq_mul }
/-- When `G` is a group, a `k`-linear representation of `G` on `V` can be thought of as
a group homomorphism from `G` into the invertible `k`-linear endomorphisms of `V`.
-/
def asGroupHom : G →* Units (V →ₗ[k] V) :=
MonoidHom.toHomUnits ρ
theorem asGroupHom_apply (g : G) : ↑(asGroupHom ρ g) = ρ g := by
simp only [asGroupHom, MonoidHom.coe_toHomUnits]
section Finite
variable [Fintype G]
open Finsupp
lemma leftRegular_norm_apply :
(leftRegular k G).norm =
(LinearMap.lsmul k _).flip ((leftRegular k G).norm (single 1 1)) ∘ₗ
linearCombination _ (fun _ => 1) := by
ext i : 2
simpa [Representation.norm] using Finset.sum_bijective _
(Group.mulRight_bijective i) (by simp_all) (by simp_all)
lemma leftRegular_norm_eq_zero_iff (x : G →₀ k) :
(leftRegular k G).norm x = 0 ↔ x.linearCombination k (fun _ => (1 : k)) = 0 := by
rw [leftRegular_norm_apply]
constructor
· intro h
simpa [norm, Representation.norm] using Finsupp.ext_iff.1 h 1
· intro h
ext
simp_all
lemma ker_leftRegular_norm_eq :
LinearMap.ker (leftRegular k G).norm =
LinearMap.ker (linearCombination k (fun _ => (1 : k))) := by
ext
exact leftRegular_norm_eq_zero_iff _
end Finite
section Cyclic
lemma apply_eq_of_leftRegular_eq_of_generator (g : G) (hg : ∀ x, x ∈ Subgroup.zpowers g)
(x : G →₀ k) (hx : leftRegular k G g x = x) (γ : G) :
x γ = x g := by
rcases hg γ with ⟨i, rfl⟩
induction i with
| zero =>
simpa using (Finsupp.ext_iff.1 hx g)
| succ n h =>
simpa [← h, zpow_natCast, zpow_add_one, pow_mul_comm', pow_succ'] using
(Finsupp.ext_iff.1 hx (g ^ (n + 1))).symm
| pred n h =>
simpa [zpow_sub, ← h, ← mul_inv_rev, ← pow_mul_comm']
using Finsupp.ext_iff.1 hx (g ^ (-n : ℤ))
end Cyclic
end Group
section DirectSum
variable {k G : Type*} [CommSemiring k] [Monoid G]
variable {ι : Type*} {V : ι → Type*}
variable [(i : ι) → AddCommMonoid (V i)] [(i : ι) → Module k (V i)]
variable (ρ : (i : ι) → Representation k G (V i))
open DirectSum
/-- Given representations of `G` on a family `V i` indexed by `i`, there is a
natural representation of `G` on their direct sum `⨁ i, V i`.
-/
@[simps]
noncomputable def directSum : Representation k G (⨁ i, V i) where
toFun g := DirectSum.lmap (fun _ => ρ _ g)
map_one' := by ext; simp
map_mul' g h := by ext; simp
end DirectSum
section Prod
variable {k G V W : Type*} [CommSemiring k] [Monoid G]
variable [AddCommMonoid V] [Module k V] [AddCommMonoid W] [Module k W]
variable (ρV : Representation k G V) (ρW : Representation k G W)
/-- Given representations of `G` on `V` and `W`, there is a natural representation of `G` on their
product `V × W`.
-/
@[simps!]
noncomputable def prod : Representation k G (V × W) where
toFun g := (ρV g).prodMap (ρW g)
map_one' := by simp
map_mul' g h := by simp [prodMap_mul]
end Prod
section TensorProduct
variable {k G V W : Type*} [CommSemiring k] [Monoid G]
variable [AddCommMonoid V] [Module k V] [AddCommMonoid W] [Module k W]
variable (ρV : Representation k G V) (ρW : Representation k G W)
open TensorProduct
/-- Given representations of `G` on `V` and `W`, there is a natural representation of `G` on their
tensor product `V ⊗[k] W`.
-/
noncomputable def tprod : Representation k G (V ⊗[k] W) where
toFun g := TensorProduct.map (ρV g) (ρW g)
map_one' := by simp only [map_one, TensorProduct.map_one]
map_mul' g h := by simp only [map_mul, TensorProduct.map_mul]
local notation ρV " ⊗ " ρW => tprod ρV ρW
@[simp]
theorem tprod_apply (g : G) : (ρV ⊗ ρW) g = TensorProduct.map (ρV g) (ρW g) :=
rfl
theorem smul_tprod_one_asModule (r : MonoidAlgebra k G) (x : V) (y : W) :
r • (show (ρV.tprod 1).asModule from x ⊗ₜ y) = (r • show ρV.asModule from x) ⊗ₜ y := by
change asAlgebraHom (ρV ⊗ 1) _ _ = asAlgebraHom ρV _ _ ⊗ₜ _
simp only [asAlgebraHom_def, MonoidAlgebra.lift_apply, tprod_apply, MonoidHom.one_apply,
LinearMap.finsupp_sum_apply, LinearMap.smul_apply, TensorProduct.map_tmul, Module.End.one_apply]
simp only [Finsupp.sum, TensorProduct.sum_tmul]
rfl
theorem smul_one_tprod_asModule (r : MonoidAlgebra k G) (x : V) (y : W) :
r • (show (1 ⊗ ρW).asModule from x ⊗ₜ y) = x ⊗ₜ (r • show ρW.asModule from y) := by
change asAlgebraHom (1 ⊗ ρW) _ _ = _ ⊗ₜ asAlgebraHom ρW _ _
simp only [asAlgebraHom_def, MonoidAlgebra.lift_apply, tprod_apply, MonoidHom.one_apply,
LinearMap.finsupp_sum_apply, LinearMap.smul_apply, TensorProduct.map_tmul, Module.End.one_apply]
simp only [Finsupp.sum, TensorProduct.tmul_sum, TensorProduct.tmul_smul]
end TensorProduct
section LinearHom
variable {k G V W : Type*} [CommSemiring k] [Group G]
variable [AddCommMonoid V] [Module k V] [AddCommMonoid W] [Module k W]
variable (ρV : Representation k G V) (ρW : Representation k G W)
/-- Given representations of `G` on `V` and `W`, there is a natural representation of `G` on the
module `V →ₗ[k] W`, where `G` acts by conjugation.
-/
def linHom : Representation k G (V →ₗ[k] W) where
toFun g :=
{ toFun := fun f => ρW g ∘ₗ f ∘ₗ ρV g⁻¹
map_add' := fun f₁ f₂ => by simp_rw [add_comp, comp_add]
map_smul' := fun r f => by simp_rw [RingHom.id_apply, smul_comp, comp_smul] }
map_one' := ext fun x => by simp [Module.End.one_eq_id]
map_mul' g h := ext fun x => by simp [Module.End.mul_eq_comp, comp_assoc]
@[simp]
theorem linHom_apply (g : G) (f : V →ₗ[k] W) : (linHom ρV ρW) g f = ρW g ∘ₗ f ∘ₗ ρV g⁻¹ :=
rfl
/-- The dual of a representation `ρ` of `G` on a module `V`, given by `(dual ρ) g f = f ∘ₗ (ρ g⁻¹)`,
where `f : Module.Dual k V`.
-/
def dual : Representation k G (Module.Dual k V) where
toFun g :=
{ toFun := fun f => f ∘ₗ ρV g⁻¹
map_add' := fun f₁ f₂ => by simp only [add_comp]
map_smul' := fun r f => by
ext
simp only [coe_comp, Function.comp_apply, smul_apply, RingHom.id_apply] }
map_one' := by ext; simp
map_mul' g h := by ext; simp
@[simp]
theorem dual_apply (g : G) : (dual ρV) g = Module.Dual.transpose (R := k) (ρV g⁻¹) :=
rfl
/-- Given $k$-modules $V, W$, there is a homomorphism $φ : V^* ⊗ W → Hom_k(V, W)$
(implemented by `dualTensorHom` in `Mathlib/LinearAlgebra/Contraction.lean`).
Given representations of $G$ on $V$ and $W$,there are representations of $G$ on $V^* ⊗ W$ and on
$Hom_k(V, W)$.
This lemma says that $φ$ is $G$-linear.
-/
theorem dualTensorHom_comm (g : G) :
dualTensorHom k V W ∘ₗ TensorProduct.map (ρV.dual g) (ρW g) =
(linHom ρV ρW) g ∘ₗ dualTensorHom k V W := by
ext; simp [Module.Dual.transpose_apply]
end LinearHom
section
variable {k G : Type*} [CommSemiring k] [Monoid G] {α A B : Type*}
[AddCommMonoid A] [Module k A] (ρ : Representation k G A)
[AddCommMonoid B] [Module k B] (τ : Representation k G B)
open Finsupp
/-- The representation on `α →₀ A` defined pointwise by a representation on `A`. -/
@[simps -isSimp]
noncomputable def finsupp (α : Type*) :
Representation k G (α →₀ A) where
toFun g := lsum k fun i => (lsingle i).comp (ρ g)
map_one' := lhom_ext (fun _ _ => by simp)
map_mul' _ _ := lhom_ext (fun _ _ => by simp)
@[simp]
lemma finsupp_single (g : G) (x : α) (a : A) :
ρ.finsupp α g (single x a) = single x (ρ g a) := by
simp [finsupp_apply]
/-- The representation on `α →₀ k[G]` defined pointwise by the left regular representation. -/
noncomputable abbrev free (k G : Type*) [CommSemiring k] [Monoid G] (α : Type*) :
Representation k G (α →₀ G →₀ k) :=
finsupp (leftRegular k G) α
noncomputable instance (k G : Type*) [CommRing k] [Monoid G] (α : Type*) :
AddCommGroup (free k G α).asModule :=
Finsupp.instAddCommGroup
lemma free_single_single (g h : G) (i : α) (r : k) :
free k G α g (single i (single h r)) = single i (single (g * h) r) := by
simp
variable (k G) (α : Type*)
/-- The free `k[G]`-module on a type `α` is isomorphic to the representation `free k G α`. -/
noncomputable def finsuppLEquivFreeAsModule :
(α →₀ MonoidAlgebra k G) ≃ₗ[MonoidAlgebra k G] (free k G α).asModule :=
{ AddEquiv.refl _ with
map_smul' _ x := by
simp only [AddEquiv.toEquiv_eq_coe, Equiv.toFun_as_coe, EquivLike.coe_coe,
AddEquiv.refl_apply, RingHom.id_apply]
induction x using Finsupp.induction with
| zero => simp only [smul_zero]
| single_add _ _ _ _ _ h =>
rw [smul_add, h]
change _ + asAlgebraHom _ _ _ = asAlgebraHom _ _ _
simp only [map_add, smul_single, smul_eq_mul, MonoidAlgebra.mul_def,
asAlgebraHom_def, MonoidAlgebra.lift_apply]
simp [free, MonoidAlgebra, asModule, ofMulAction_def, mapDomain, smul_sum, single_sum] }
/-- `α` gives a `k[G]`-basis of the representation `free k G α`. -/
noncomputable def freeAsModuleBasis :
Basis α (MonoidAlgebra k G) (free k G α).asModule where
repr := (finsuppLEquivFreeAsModule k G α).symm
theorem free_asModule_free :
Module.Free (MonoidAlgebra k G) (free k G α).asModule :=
Module.Free.of_basis (freeAsModuleBasis k G α)
end
end Representation |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Rep.lean | import Mathlib.Algebra.Category.ModuleCat.Adjunctions
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric
import Mathlib.Algebra.Category.ModuleCat.Projective
import Mathlib.CategoryTheory.Elementwise
import Mathlib.CategoryTheory.Action.Monoidal
import Mathlib.RepresentationTheory.Basic
/-!
# `Rep k G` is the category of `k`-linear representations of `G`.
If `V : Rep k G`, there is a coercion that allows you to treat `V` as a type,
and this type comes equipped with a `Module k V` instance.
Also `V.ρ` gives the homomorphism `G →* (V →ₗ[k] V)`.
Conversely, given a homomorphism `ρ : G →* (V →ₗ[k] V)`,
you can construct the bundled representation as `Rep.of ρ`.
We construct the categorical equivalence `Rep k G ≌ ModuleCat (MonoidAlgebra k G)`.
We verify that `Rep k G` is a `k`-linear abelian symmetric monoidal category with all (co)limits.
-/
suppress_compilation
universe u
open CategoryTheory
open CategoryTheory.Limits
/-- The category of `k`-linear representations of a monoid `G`. -/
abbrev Rep (k G : Type u) [Ring k] [Monoid G] :=
Action (ModuleCat.{u} k) G
instance (k G : Type u) [CommRing k] [Monoid G] : Linear k (Rep k G) := by infer_instance
namespace Rep
variable {k G : Type u} [CommRing k]
section
variable [Monoid G]
instance : CoeSort (Rep k G) (Type u) :=
⟨fun V => V.V⟩
instance (V : Rep k G) : AddCommGroup V := by
change AddCommGroup ((forget₂ (Rep k G) (ModuleCat k)).obj V); infer_instance
instance (V : Rep k G) : Module k V := by
change Module k ((forget₂ (Rep k G) (ModuleCat k)).obj V)
infer_instance
/-- Specialize the existing `Action.ρ`, changing the type to `Representation k G V`.
-/
def ρ (V : Rep k G) : Representation k G V :=
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11036): was `V.ρ`
(ModuleCat.endRingEquiv V.V).toMonoidHom.comp (Action.ρ V)
/-- Lift an unbundled representation to `Rep`. -/
abbrev of {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) : Rep k G :=
⟨ModuleCat.of k V, (ModuleCat.endRingEquiv _).symm.toMonoidHom.comp ρ⟩
theorem coe_of {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) :
(of ρ : Type u) = V :=
rfl
@[simp]
theorem of_ρ {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) : (of ρ).ρ = ρ :=
rfl
theorem Action_ρ_eq_ρ {A : Rep k G} :
Action.ρ A = (ModuleCat.endRingEquiv _).symm.toMonoidHom.comp A.ρ :=
rfl
@[simp]
lemma ρ_hom {X : Rep k G} (g : G) : (Action.ρ X g).hom = X.ρ g := rfl
@[simp]
lemma ofHom_ρ {X : Rep k G} (g : G) : ModuleCat.ofHom (X.ρ g) = Action.ρ X g := rfl
@[deprecated Representation.inv_self_apply (since := "2025-05-09")]
theorem ρ_inv_self_apply {G : Type u} [Group G] (A : Rep k G) (g : G) (x : A) :
A.ρ g⁻¹ (A.ρ g x) = x :=
show (A.ρ g⁻¹ * A.ρ g) x = x by rw [← map_mul, inv_mul_cancel, map_one, Module.End.one_apply]
@[deprecated Representation.self_inv_apply (since := "2025-05-09")]
theorem ρ_self_inv_apply {G : Type u} [Group G] {A : Rep k G} (g : G) (x : A) :
A.ρ g (A.ρ g⁻¹ x) = x :=
show (A.ρ g * A.ρ g⁻¹) x = x by rw [← map_mul, mul_inv_cancel, map_one, Module.End.one_apply]
theorem hom_comm_apply {A B : Rep k G} (f : A ⟶ B) (g : G) (x : A) :
f.hom (A.ρ g x) = B.ρ g (f.hom x) :=
LinearMap.ext_iff.1 (ModuleCat.hom_ext_iff.mp (f.comm g)) x
variable (k G)
/-- The trivial `k`-linear `G`-representation on a `k`-module `V.` -/
abbrev trivial (V : Type u) [AddCommGroup V] [Module k V] : Rep k G :=
Rep.of (Representation.trivial k G V)
variable {k G}
theorem trivial_def {V : Type u} [AddCommGroup V] [Module k V] (g : G) :
(trivial k G V).ρ g = LinearMap.id :=
rfl
variable (k G) in
/-- The functor equipping a module with the trivial representation. -/
@[simps! obj_V map_hom]
def trivialFunctor : ModuleCat k ⥤ Rep k G where
obj V := trivial k G V
map f := { hom := f, comm := fun _ => rfl }
/-- A predicate for representations that fix every element. -/
abbrev IsTrivial (A : Rep k G) := A.ρ.IsTrivial
instance (X : ModuleCat k) : ((trivialFunctor k G).obj X).IsTrivial where
instance {V : Type u} [AddCommGroup V] [Module k V] :
IsTrivial (Rep.trivial k G V) where
instance {V : Type u} [AddCommGroup V] [Module k V] (ρ : Representation k G V) [ρ.IsTrivial] :
IsTrivial (Rep.of ρ) where
instance {H V : Type u} [Group H] [AddCommGroup V] [Module k V] (ρ : Representation k H V)
(f : G →* H) [Representation.IsTrivial (ρ.comp f)] :
Representation.IsTrivial ((Rep.of ρ).ρ.comp f) := ‹_›
section Commutative
variable {k G : Type u} [CommRing k] [CommMonoid G]
variable (A : Rep k G)
/-- Given a representation `A` of a commutative monoid `G`, the map `ρ_A(g)` is a representation
morphism `A ⟶ A` for any `g : G`. -/
@[simps]
def applyAsHom (g : G) : A ⟶ A where
hom := ModuleCat.ofHom (A.ρ g)
comm _ := by ext; simp [← Module.End.mul_apply, ← map_mul, mul_comm]
@[reassoc, elementwise]
lemma applyAsHom_comm {A B : Rep k G} (f : A ⟶ B) (g : G) :
A.applyAsHom g ≫ f = f ≫ B.applyAsHom g := by
ext
simp [hom_comm_apply]
end Commutative
section
variable {G : Type u} [Group G] (A : Rep k G) (S : Subgroup G)
[S.Normal] [Representation.IsTrivial (A.ρ.comp S.subtype)]
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` which is trivial on `S` factors
through `G ⧸ S`. -/
abbrev ofQuotient : Rep k (G ⧸ S) := Rep.of (A.ρ.ofQuotient S)
/-- A `G`-representation `A` on which a normal subgroup `S ≤ G` acts trivially induces a
`G ⧸ S`-representation on `A`, and composing this with the quotient map `G → G ⧸ S` gives the
original representation by definition. Useful for typechecking. -/
abbrev resOfQuotientIso [Representation.IsTrivial (A.ρ.comp S.subtype)] :
(Action.res _ (QuotientGroup.mk' S)).obj (A.ofQuotient S) ≅ A := Iso.refl _
end
variable (A : Rep k G)
/-- Given a `k`-linear `G`-representation `(V, ρ)`, this is the representation defined by
restricting `ρ` to a `G`-invariant `k`-submodule of `V`. -/
abbrev subrepresentation (W : Submodule k A) (le_comap : ∀ g, W ≤ W.comap (A.ρ g)) :
Rep k G :=
Rep.of (A.ρ.subrepresentation W le_comap)
/-- The natural inclusion of a subrepresentation into the ambient representation. -/
@[simps]
def subtype (W : Submodule k A) (le_comap : ∀ g, W ≤ W.comap (A.ρ g)) :
subrepresentation A W le_comap ⟶ A where
hom := ModuleCat.ofHom W.subtype
comm _ := rfl
/-- Given a `k`-linear `G`-representation `(V, ρ)` and a `G`-invariant `k`-submodule `W ≤ V`, this
is the representation induced on `V ⧸ W` by `ρ`. -/
abbrev quotient (W : Submodule k A) (le_comap : ∀ g, W ≤ W.comap (A.ρ g)) :
Rep k G :=
Rep.of (A.ρ.quotient W le_comap)
/-- The natural projection from a representation to its quotient by a subrepresentation. -/
@[simps]
def mkQ (W : Submodule k A) (le_comap : ∀ g, W ≤ W.comap (A.ρ g)) :
A ⟶ quotient A W le_comap where
hom := ModuleCat.ofHom <| Submodule.mkQ _
comm _ := rfl
instance : PreservesLimits (forget₂ (Rep k G) (ModuleCat.{u} k)) :=
Action.preservesLimits_forget _ _
instance : PreservesColimits (forget₂ (Rep k G) (ModuleCat.{u} k)) :=
Action.preservesColimits_forget _ _
theorem epi_iff_surjective {A B : Rep k G} (f : A ⟶ B) : Epi f ↔ Function.Surjective f.hom :=
⟨fun _ => (ModuleCat.epi_iff_surjective ((forget₂ _ _).map f)).1 inferInstance,
fun h => (forget₂ _ _).epi_of_epi_map ((ModuleCat.epi_iff_surjective <|
(forget₂ _ _).map f).2 h)⟩
theorem mono_iff_injective {A B : Rep k G} (f : A ⟶ B) : Mono f ↔ Function.Injective f.hom :=
⟨fun _ => (ModuleCat.mono_iff_injective ((forget₂ _ _).map f)).1 inferInstance,
fun h => (forget₂ _ _).mono_of_mono_map ((ModuleCat.mono_iff_injective <|
(forget₂ _ _).map f).2 h)⟩
instance {A B : Rep k G} (f : A ⟶ B) [Mono f] : Mono f.hom :=
inferInstanceAs <| Mono ((forget₂ _ _).map f)
instance {A B : Rep k G} (f : A ⟶ B) [Epi f] : Epi f.hom :=
inferInstanceAs <| Epi ((forget₂ _ _).map f)
open MonoidalCategory in
@[simp]
theorem tensor_ρ {A B : Rep k G} : (A ⊗ B).ρ = A.ρ.tprod B.ρ := rfl
@[simp]
lemma res_obj_ρ {H : Type u} [Monoid H] (f : G →* H) (A : Rep k H) :
ρ ((Action.res _ f).obj A) = A.ρ.comp f := rfl
@[simp]
lemma coe_res_obj_ρ {H : Type u} [Monoid H] (f : G →* H) (A : Rep k H) (g : G) :
DFunLike.coe (F := G →* (A →ₗ[k] A)) (ρ ((Action.res _ f).obj A)) g = A.ρ (f g) := rfl
section Linearization
variable (k G)
/-- The monoidal functor sending a type `H` with a `G`-action to the induced `k`-linear
`G`-representation on `k[H].` -/
def linearization : (Action (Type u) G) ⥤ (Rep k G) :=
(ModuleCat.free k).mapAction G
instance : (linearization k G).Monoidal := by
dsimp only [linearization]
infer_instance
variable {k G}
@[simp]
theorem coe_linearization_obj (X : Action (Type u) G) :
(linearization k G).obj X = (X.V →₀ k) := rfl
theorem linearization_obj_ρ (X : Action (Type u) G) (g : G) :
((linearization k G).obj X).ρ g = Finsupp.lmapDomain k k (X.ρ g) :=
rfl
@[simp]
theorem coe_linearization_obj_ρ (X : Action (Type u) G) (g : G) :
@DFunLike.coe (no_index G →* ((X.V →₀ k) →ₗ[k] (X.V →₀ k))) _
(fun _ => (X.V →₀ k) →ₗ[k] (X.V →₀ k)) _
((linearization k G).obj X).ρ g = Finsupp.lmapDomain k k (X.ρ g) := rfl
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): helps fixing `linearizationTrivialIso` since change in behaviour of `ext`.
theorem linearization_single (X : Action (Type u) G) (g : G) (x : X.V) (r : k) :
((linearization k G).obj X).ρ g (Finsupp.single x r) = Finsupp.single (X.ρ g x) r := by
simp
@[deprecated "Use `Rep.linearization_single` instead" (since := "2025-06-02")]
theorem linearization_of (X : Action (Type u) G) (g : G) (x : X.V) :
((linearization k G).obj X).ρ g (Finsupp.single x (1 : k))
= Finsupp.single (X.ρ g x) (1 : k) := by
simp
variable {X Y : Action (Type u) G} (f : X ⟶ Y)
@[simp]
theorem linearization_map_hom : ((linearization k G).map f).hom =
ModuleCat.ofHom (Finsupp.lmapDomain k k f.hom) :=
rfl
theorem linearization_map_hom_single (x : X.V) (r : k) :
((linearization k G).map f).hom (Finsupp.single x r) = Finsupp.single (f.hom x) r :=
Finsupp.mapDomain_single
open Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal
@[simp]
theorem linearization_μ_hom (X Y : Action (Type u) G) :
(μ (linearization k G) X Y).hom =
ModuleCat.ofHom (finsuppTensorFinsupp' k X.V Y.V).toLinearMap :=
rfl
@[simp]
theorem linearization_δ_hom (X Y : Action (Type u) G) :
(δ (linearization k G) X Y).hom =
ModuleCat.ofHom (finsuppTensorFinsupp' k X.V Y.V).symm.toLinearMap :=
rfl
@[simp]
theorem linearization_ε_hom : (ε (linearization k G)).hom =
ModuleCat.ofHom (Finsupp.lsingle PUnit.unit) :=
rfl
theorem linearization_η_hom_apply (r : k) :
(η (linearization k G)).hom (Finsupp.single PUnit.unit r) = r :=
(εIso (linearization k G)).hom_inv_id_apply r
variable (k G)
/-- The linearization of a type `X` on which `G` acts trivially is the trivial `G`-representation
on `k[X]`. -/
@[simps! hom_hom inv_hom]
def linearizationTrivialIso (X : Type u) :
(linearization k G).obj (Action.mk X 1) ≅ trivial k G (X →₀ k) :=
Action.mkIso (Iso.refl _) fun _ => ModuleCat.hom_ext <| Finsupp.lhom_ext' fun _ => LinearMap.ext
fun _ => linearization_single ..
/-- Given a `G`-action on `H`, this is `k[H]` bundled with the natural representation
`G →* End(k[H])` as a term of type `Rep k G`. -/
abbrev ofMulAction (H : Type u) [MulAction G H] : Rep k G :=
of <| Representation.ofMulAction k G H
/-- The `k`-linear `G`-representation on `k[G]`, induced by left multiplication. -/
abbrev leftRegular : Rep k G :=
ofMulAction k G G
/-- The `k`-linear `G`-representation on `k[Gⁿ]`, induced by left multiplication. -/
abbrev diagonal (n : ℕ) : Rep k G :=
ofMulAction k G (Fin n → G)
/-- The natural isomorphism between the representations on `k[G¹]` and `k[G]` induced by left
multiplication in `G`. -/
@[simps! hom_hom inv_hom]
def diagonalOneIsoLeftRegular :
diagonal k G 1 ≅ leftRegular k G :=
Action.mkIso (Finsupp.domLCongr <| Equiv.funUnique (Fin 1) G).toModuleIso fun _ =>
ModuleCat.hom_ext <| Finsupp.lhom_ext fun _ _ => by simp [diagonal, ModuleCat.endRingEquiv]
/-- When `H = {1}`, the `G`-representation on `k[H]` induced by an action of `G` on `H` is
isomorphic to the trivial representation on `k`. -/
@[simps! hom_hom inv_hom]
def ofMulActionSubsingletonIsoTrivial
(H : Type u) [Subsingleton H] [MulOneClass H] [MulAction G H] :
ofMulAction k G H ≅ trivial k G k :=
letI : Unique H := uniqueOfSubsingleton 1
Action.mkIso (Finsupp.LinearEquiv.finsuppUnique _ _ _).toModuleIso fun _ =>
ModuleCat.hom_ext <| Finsupp.lhom_ext fun _ _ => by
simp [Subsingleton.elim _ (1 : H), ModuleCat.endRingEquiv]
/-- The linearization of a type `H` with a `G`-action is definitionally isomorphic to the
`k`-linear `G`-representation on `k[H]` induced by the `G`-action on `H`. -/
def linearizationOfMulActionIso (H : Type u) [MulAction G H] :
(linearization k G).obj (Action.ofMulAction G H) ≅ ofMulAction k G H :=
Iso.refl _
section
variable (k G A : Type u) [CommRing k] [Monoid G] [AddCommGroup A]
[Module k A] [DistribMulAction G A] [SMulCommClass G k A]
/-- Turns a `k`-module `A` with a compatible `DistribMulAction` of a monoid `G` into a
`k`-linear `G`-representation on `A`. -/
def ofDistribMulAction : Rep k G := Rep.of (Representation.ofDistribMulAction k G A)
@[simp] theorem ofDistribMulAction_ρ_apply_apply (g : G) (a : A) :
(ofDistribMulAction k G A).ρ g a = g • a := rfl
/-- Given an `R`-algebra `S`, the `ℤ`-linear representation associated to the natural action of
`S ≃ₐ[R] S` on `S`. -/
@[simp] def ofAlgebraAut (R S : Type) [CommRing R] [CommRing S] [Algebra R S] :
Rep ℤ (S ≃ₐ[R] S) := ofDistribMulAction ℤ (S ≃ₐ[R] S) S
end
section
variable (M G : Type) [Monoid M] [CommGroup G] [MulDistribMulAction M G]
/-- Turns a `CommGroup` `G` with a `MulDistribMulAction` of a monoid `M` into a
`ℤ`-linear `M`-representation on `Additive G`. -/
def ofMulDistribMulAction : Rep ℤ M := Rep.of (Representation.ofMulDistribMulAction M G)
@[simp] theorem ofMulDistribMulAction_ρ_apply_apply (g : M) (a : Additive G) :
(ofMulDistribMulAction M G).ρ g a = Additive.ofMul (g • a.toMul) := rfl
/-- Given an `R`-algebra `S`, the `ℤ`-linear representation associated to the natural action of
`S ≃ₐ[R] S` on `Sˣ`. -/
@[simp] def ofAlgebraAutOnUnits (R S : Type) [CommRing R] [CommRing S] [Algebra R S] :
Rep ℤ (S ≃ₐ[R] S) := Rep.ofMulDistribMulAction (S ≃ₐ[R] S) Sˣ
end
variable {k G}
/-- Given an element `x : A`, there is a natural morphism of representations `k[G] ⟶ A` sending
`g ↦ A.ρ(g)(x).` -/
@[simps]
def leftRegularHom (A : Rep k G) (x : A) : leftRegular k G ⟶ A where
hom := ModuleCat.ofHom <| Finsupp.lift A k G fun g => A.ρ g x
comm _ := by ext; simp [ModuleCat.endRingEquiv]
theorem leftRegularHom_hom_single {A : Rep k G} (g : G) (x : A) (r : k) :
(leftRegularHom A x).hom (Finsupp.single g r) = r • A.ρ g x := by simp
/-- Given a `k`-linear `G`-representation `A`, there is a `k`-linear isomorphism between
representation morphisms `Hom(k[G], A)` and `A`. -/
@[simps]
def leftRegularHomEquiv (A : Rep k G) : (leftRegular k G ⟶ A) ≃ₗ[k] A where
toFun f := f.hom (Finsupp.single 1 1)
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun x := leftRegularHom A x
left_inv f := by ext; simp [← hom_comm_apply f]
right_inv x := by simp
theorem leftRegularHomEquiv_symm_single {A : Rep k G} (x : A) (g : G) :
((leftRegularHomEquiv A).symm x).hom (Finsupp.single g 1) = A.ρ g x := by
simp
end Linearization
section Finsupp
open Finsupp
variable (α : Type u) (A : Rep k G)
/-- The representation on `α →₀ A` defined pointwise by a representation on `A`. -/
abbrev finsupp : Rep k G :=
Rep.of (Representation.finsupp A.ρ α)
variable (k G) in
/-- The representation on `α →₀ k[G]` defined pointwise by the left regular representation on
`k[G]`. -/
abbrev free : Rep k G :=
Rep.of (V := (α →₀ G →₀ k)) (Representation.free k G α)
variable {α} [DecidableEq α]
/-- Given `f : α → A`, the natural representation morphism `(α →₀ k[G]) ⟶ A` sending
`single a (single g r) ↦ r • A.ρ g (f a)`. -/
@[simps]
def freeLift (f : α → A) :
free k G α ⟶ A where
hom := ModuleCat.ofHom <| linearCombination k (fun x => A.ρ x.2 (f x.1)) ∘ₗ
(finsuppProdLEquiv k).symm.toLinearMap
comm _ := by
ext; simp [ModuleCat.endRingEquiv]
variable {A} in
lemma freeLift_hom_single_single (f : α → A) (i : α) (g : G) (r : k) :
(freeLift A f).hom (single i (single g r)) = r • A.ρ g (f i) := by
simp
variable (α) in
/-- The natural linear equivalence between functions `α → A` and representation morphisms
`(α →₀ k[G]) ⟶ A`. -/
@[simps]
def freeLiftLEquiv :
(free k G α ⟶ A) ≃ₗ[k] (α → A) where
toFun f i := f.hom (single i (single 1 1))
invFun := freeLift A
left_inv x := by
ext i j
simpa [← map_smul] using (hom_comm_apply x j (single i (single 1 1))).symm
right_inv _ := by ext; simp
map_add' _ _ := rfl
map_smul' _ _ := rfl
variable {A}
omit [DecidableEq α] in
@[ext]
lemma free_ext (f g : free k G α ⟶ A)
(h : ∀ i : α, f.hom (single i (single 1 1)) = g.hom (single i (single 1 1))) : f = g := by
classical exact (freeLiftLEquiv α A).injective (funext_iff.2 h)
section
open MonoidalCategory
variable (A B : Rep k G) (α : Type u) [DecidableEq α]
open ModuleCat.MonoidalCategory
-- the proof below can be simplified after https://github.com/leanprover-community/mathlib4/issues/24823 is merged
/-- Given representations `A, B` and a type `α`, this is the natural representation isomorphism
`(α →₀ A) ⊗ B ≅ (A ⊗ B) →₀ α` sending `single x a ⊗ₜ b ↦ single x (a ⊗ₜ b)`. -/
@[simps! hom_hom inv_hom]
def finsuppTensorLeft :
A.finsupp α ⊗ B ≅ (A ⊗ B).finsupp α :=
Action.mkIso (TensorProduct.finsuppLeft k A B α).toModuleIso
fun _ => ModuleCat.hom_ext <| TensorProduct.ext <| lhom_ext fun _ _ => by
ext
simp [Action_ρ_eq_ρ, TensorProduct.finsuppLeft_apply_tmul,
tensorObj_carrier, ModuleCat.endRingEquiv]
/-- Given representations `A, B` and a type `α`, this is the natural representation isomorphism
`A ⊗ (α →₀ B) ≅ (A ⊗ B) →₀ α` sending `a ⊗ₜ single x b ↦ single x (a ⊗ₜ b)`. -/
@[simps! hom_hom inv_hom]
def finsuppTensorRight :
A ⊗ B.finsupp α ≅ (A ⊗ B).finsupp α :=
Action.mkIso (TensorProduct.finsuppRight k A B α).toModuleIso fun _ => ModuleCat.hom_ext <|
TensorProduct.ext <| LinearMap.ext fun _ => lhom_ext fun _ _ => by
ext
simp [Action_ρ_eq_ρ, TensorProduct.finsuppRight_apply_tmul, ModuleCat.endRingEquiv,
tensorObj_carrier]
variable (k G) in
/-- The natural isomorphism sending `single g r₁ ⊗ single a r₂ ↦ single a (single g r₁r₂)`. -/
@[simps! -isSimp hom_hom inv_hom]
def leftRegularTensorTrivialIsoFree :
leftRegular k G ⊗ trivial k G (α →₀ k) ≅ free k G α :=
Action.mkIso (finsuppTensorFinsupp' k G α ≪≫ₗ Finsupp.domLCongr (Equiv.prodComm G α) ≪≫ₗ
finsuppProdLEquiv k).toModuleIso fun _ =>
ModuleCat.hom_ext <| TensorProduct.ext <| lhom_ext fun _ _ => lhom_ext fun _ _ => by
ext
simp [Action_ρ_eq_ρ, tensorObj_carrier, ModuleCat.endRingEquiv]
variable {α}
@[simp]
lemma leftRegularTensorTrivialIsoFree_hom_hom_single_tmul_single (i : α) (g : G) (r s : k) :
DFunLike.coe (F := ↑(ModuleCat.of k (G →₀ k) ⊗ ModuleCat.of k (α →₀ k)) →ₗ[k] α →₀ G →₀ k)
(leftRegularTensorTrivialIsoFree k G α).hom.hom.hom (single g r ⊗ₜ[k] single i s) =
single i (single g (r * s)) := by
simp [leftRegularTensorTrivialIsoFree, tensorObj_carrier]
@[simp]
lemma leftRegularTensorTrivialIsoFree_inv_hom_single_single (i : α) (g : G) (r : k) :
DFunLike.coe (F := (α →₀ G →₀ k) →ₗ[k] ↑(ModuleCat.of k (G →₀ k) ⊗ ModuleCat.of k (α →₀ k)))
(leftRegularTensorTrivialIsoFree k G α).inv.hom.hom (single i (single g r)) =
single g r ⊗ₜ[k] single i 1 := by
simp [leftRegularTensorTrivialIsoFree, finsuppTensorFinsupp'_symm_single_eq_tmul_single_one,
tensorObj_carrier]
end
end Finsupp
end
section Group
open Finsupp MonoidalCategory ModuleCat.MonoidalCategory
open Representation (IsTrivial)
variable [Group G] {n : ℕ}
variable (k G n) in
/-- An isomorphism of `k`-linear representations of `G` from `k[Gⁿ⁺¹]` to `k[G] ⊗ₖ k[Gⁿ]` (on
which `G` acts by `ρ(g₁)(g₂ ⊗ x) = (g₁ * g₂) ⊗ x`) sending `(g₀, ..., gₙ)` to
`g₀ ⊗ (g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ)`. The inverse sends `g₀ ⊗ (g₁, ..., gₙ)` to
`(g₀, g₀g₁, ..., g₀g₁...gₙ)`. -/
def diagonalSuccIsoTensorTrivial :
diagonal k G (n + 1) ≅ leftRegular k G ⊗ trivial k G ((Fin n → G) →₀ k) :=
(linearization k G).mapIso (Action.diagonalSuccIsoTensorTrivial G n) ≪≫
(Functor.Monoidal.μIso (linearization k G) _ _).symm ≪≫
tensorIso (Iso.refl _) (linearizationTrivialIso k G (Fin n → G))
@[simp]
theorem diagonalSuccIsoTensorTrivial_hom_hom_single (f : Fin (n + 1) → G) (a : k) :
DFunLike.coe (F := ((Fin (n + 1) → G) →₀ k) →ₗ[k]
↑(ModuleCat.of k (G →₀ k) ⊗ ModuleCat.of k ((Fin n → G) →₀ k)))
(diagonalSuccIsoTensorTrivial k G n).hom.hom.hom (single f a) =
single (f 0) 1 ⊗ₜ single (fun i => (f (Fin.castSucc i))⁻¹ * f i.succ) a := by
simp [diagonalSuccIsoTensorTrivial, whiskerLeft_def, tensorObj_carrier,
types_tensorObj_def, finsuppTensorFinsupp'_symm_single_eq_single_one_tmul,
ModuleCat.hom_id (M := .of _ _), Action.ofMulAction_V]
theorem diagonalSuccIsoTensorTrivial_inv_hom_single_single (g : G) (f : Fin n → G) (a b : k) :
(diagonalSuccIsoTensorTrivial k G n).inv.hom (single g a ⊗ₜ single f b) =
single (g • Fin.partialProd f) (a * b) := by
have := Action.diagonalSuccIsoTensorTrivial_inv_hom_apply (G := G) (n := n)
simp_all [diagonalSuccIsoTensorTrivial, ModuleCat.MonoidalCategory.tensorHom_def,
tensorObj_carrier, types_tensorObj_def, ModuleCat.hom_id (M := .of _ _), Action.ofMulAction_V]
theorem diagonalSuccIsoTensorTrivial_inv_hom_single_left (g : G) (f : (Fin n → G) →₀ k) (r : k) :
(diagonalSuccIsoTensorTrivial k G n).inv.hom (single g r ⊗ₜ f) =
Finsupp.lift ((Fin (n + 1) → G) →₀ k) k (Fin n → G)
(fun f => single (g • Fin.partialProd f) r) f := by
refine f.induction ?_ ?_
· simp only [TensorProduct.tmul_zero, map_zero]
· intro a b x _ _ hx
simpa [-Action.tensorObj_V, TensorProduct.tmul_add, map_add, mul_comm b, hx] using
diagonalSuccIsoTensorTrivial_inv_hom_single_single ..
theorem diagonalSuccIsoTensorTrivial_inv_hom_single_right (g : G →₀ k) (f : Fin n → G) (r : k) :
(diagonalSuccIsoTensorTrivial k G n).inv.hom (g ⊗ₜ single f r) =
Finsupp.lift _ k G (fun a => single (a • Fin.partialProd f) r) g := by
refine g.induction ?_ ?_
· simp only [TensorProduct.zero_tmul, map_zero]
· intro a b x _ _ hx
simpa [-Action.tensorObj_V, map_add, hx, TensorProduct.add_tmul] using
diagonalSuccIsoTensorTrivial_inv_hom_single_single ..
variable [DecidableEq (Fin n → G)]
variable (k G n) in
/-- Representation isomorphism `k[Gⁿ⁺¹] ≅ (Gⁿ →₀ k[G])`, where the right-hand representation is
defined pointwise by the left regular representation on `k[G]`. The map sends
`single (g₀, ..., gₙ) a ↦ single (g₀⁻¹g₁, ..., gₙ₋₁⁻¹gₙ) (single g₀ a)`. -/
def diagonalSuccIsoFree : diagonal k G (n + 1) ≅ free k G (Fin n → G) :=
diagonalSuccIsoTensorTrivial k G n ≪≫ leftRegularTensorTrivialIsoFree k G (Fin n → G)
@[simp]
theorem diagonalSuccIsoFree_hom_hom_single (f : Fin (n + 1) → G) (a : k) :
(diagonalSuccIsoFree k G n).hom.hom (single f a) =
single (fun i => (f i.castSucc)⁻¹ * f i.succ) (single (f 0) a) := by
simp [diagonalSuccIsoFree, leftRegularTensorTrivialIsoFree_hom_hom_single_tmul_single
(k := k)]
@[simp]
theorem diagonalSuccIsoFree_inv_hom_single_single (g : G) (f : Fin n → G) (a : k) :
(diagonalSuccIsoFree k G n).inv.hom (single f (single g a)) =
single (g • Fin.partialProd f) a := by
have := diagonalSuccIsoTensorTrivial_inv_hom_single_single g f a 1
simp_all [diagonalSuccIsoFree, leftRegularTensorTrivialIsoFree_inv_hom_single_single (k := k)]
theorem diagonalSuccIsoFree_inv_hom_single (g : G →₀ k) (f : Fin n → G) :
(diagonalSuccIsoFree k G n).inv.hom (single f g) =
lift _ k G (fun a => single (a • Fin.partialProd f) 1) g :=
g.induction (by simp) fun _ _ _ _ _ _ => by
rw [single_add, map_add, diagonalSuccIsoFree_inv_hom_single_single]
simp_all [sum_add_index']
variable (n) (A : Rep k G)
/-- Given a `k`-linear `G`-representation `A`, the set of representation morphisms
`Hom(k[Gⁿ⁺¹], A)` is `k`-linearly isomorphic to the set of functions `Gⁿ → A`. -/
def diagonalHomEquiv :
(Rep.diagonal k G (n + 1) ⟶ A) ≃ₗ[k] (Fin n → G) → A :=
Linear.homCongr k (diagonalSuccIsoFree k G n) (Iso.refl _) ≪≫ₗ
freeLiftLEquiv (Fin n → G) A
variable {n A}
/-- Given a `k`-linear `G`-representation `A`, `diagonalHomEquiv` is a `k`-linear isomorphism of
the set of representation morphisms `Hom(k[Gⁿ⁺¹], A)` with `Fun(Gⁿ, A)`. This lemma says that this
sends a morphism of representations `f : k[Gⁿ⁺¹] ⟶ A` to the function
`(g₁, ..., gₙ) ↦ f(1, g₁, g₁g₂, ..., g₁g₂...gₙ).` -/
theorem diagonalHomEquiv_apply (f : Rep.diagonal k G (n + 1) ⟶ A) (x : Fin n → G) :
diagonalHomEquiv n A f x = f.hom (Finsupp.single (Fin.partialProd x) 1) := by
simp [diagonalHomEquiv, Linear.homCongr_apply,
diagonalSuccIsoFree_inv_hom_single_single (k := k)]
/-- Given a `k`-linear `G`-representation `A`, `diagonalHomEquiv` is a `k`-linear isomorphism of
the set of representation morphisms `Hom(k[Gⁿ⁺¹], A)` with `Fun(Gⁿ, A)`. This lemma says that the
inverse map sends a function `f : Gⁿ → A` to the representation morphism sending
`(g₀, ... gₙ) ↦ ρ(g₀)(f(g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ))`, where `ρ` is the representation attached
to `A`. -/
theorem diagonalHomEquiv_symm_apply (f : (Fin n → G) → A) (x : Fin (n + 1) → G) :
((diagonalHomEquiv n A).symm f).hom (Finsupp.single x 1) =
A.ρ (x 0) (f fun i : Fin n => (x (Fin.castSucc i))⁻¹ * x i.succ) := by
simp [diagonalHomEquiv, Linear.homCongr_symm_apply, diagonalSuccIsoFree_hom_hom_single (k := k)]
/-- Auxiliary lemma for defining group cohomology, used to show that the isomorphism
`diagonalHomEquiv` commutes with the differentials in two complexes which compute
group cohomology. -/
@[deprecated "We no longer use `diagonalHomEquiv` to define group cohomology"
(since := "2025-06-08")]
theorem diagonalHomEquiv_symm_partialProd_succ (f : (Fin n → G) → A) (g : Fin (n + 1) → G)
(a : Fin (n + 1)) :
((diagonalHomEquiv n A).symm f).hom (Finsupp.single (Fin.partialProd g ∘ a.succ.succAbove) 1)
= f (Fin.contractNth a (· * ·) g) := by
rw [diagonalHomEquiv_symm_apply]
simp only [Function.comp_apply, Fin.succ_succAbove_zero, Fin.partialProd_zero, map_one,
Fin.succ_succAbove_succ, Module.End.one_apply, Fin.partialProd_succ]
congr
ext
rw [← Fin.partialProd_succ, Fin.inv_partialProd_mul_eq_contractNth]
section
variable [Fintype G] (A : Rep k G)
/-- Given a representation `A` of a finite group `G`, `norm A` is the representation morphism
`A ⟶ A` defined by `x ↦ ∑ A.ρ g x` for `g` in `G`. -/
@[simps]
def norm : End A where
hom := ModuleCat.ofHom <| Representation.norm A.ρ
comm g := by ext; simp
@[reassoc, elementwise]
lemma norm_comm {A B : Rep k G} (f : A ⟶ B) : f ≫ norm B = norm A ≫ f := by
ext
simp [Representation.norm, hom_comm_apply]
/-- Given a representation `A` of a finite group `G`, the norm map `A ⟶ A` defined by
`x ↦ ∑ A.ρ g x` for `g` in `G` defines a natural endomorphism of the identity functor. -/
@[simps]
def normNatTrans : End (𝟭 (Rep k G)) where
app := norm
naturality _ _ := norm_comm
end
section MonoidalClosed
open MonoidalCategory Action
variable (A B C : Rep k G)
/-- Given a `k`-linear `G`-representation `(A, ρ₁)`, this is the 'internal Hom' functor sending
`(B, ρ₂)` to the representation `Homₖ(A, B)` that maps `g : G` and `f : A →ₗ[k] B` to
`(ρ₂ g) ∘ₗ f ∘ₗ (ρ₁ g⁻¹)`. -/
@[simps]
protected noncomputable def ihom (A : Rep k G) : Rep k G ⥤ Rep k G where
obj B := Rep.of (Representation.linHom A.ρ B.ρ)
map := fun {X} {Y} f =>
{ hom := ModuleCat.ofHom (LinearMap.llcomp k _ _ _ f.hom.hom)
comm g := by ext; simp [ModuleCat.endRingEquiv, hom_comm_apply] }
map_id := fun _ => by ext; rfl
map_comp := fun _ _ => by ext; rfl
@[simp] theorem ihom_obj_ρ_apply {A B : Rep k G} (g : G) (x : A →ₗ[k] B) :
-- Hint to put this lemma into `simp`-normal form.
DFunLike.coe (F := (Representation k G (↑A.V →ₗ[k] ↑B.V)))
((Rep.ihom A).obj B).ρ g x = B.ρ g ∘ₗ x ∘ₗ A.ρ g⁻¹ :=
rfl
/-- Given a `k`-linear `G`-representation `A`, this is the Hom-set bijection in the adjunction
`A ⊗ - ⊣ ihom(A, -)`. It sends `f : A ⊗ B ⟶ C` to a `Rep k G` morphism defined by currying the
`k`-linear map underlying `f`, giving a map `A →ₗ[k] B →ₗ[k] C`, then flipping the arguments. -/
@[simps]
def homEquiv (A B C : Rep k G) : (A ⊗ B ⟶ C) ≃ (B ⟶ (Rep.ihom A).obj C) where
toFun f :=
{ hom := ModuleCat.ofHom <| (TensorProduct.curry f.hom.hom).flip
comm g := ModuleCat.hom_ext <| LinearMap.ext fun x => LinearMap.ext fun y => by
simpa [tensorObj_carrier, ModuleCat.endRingEquiv] using
hom_comm_apply f g (A.ρ g⁻¹ y ⊗ₜ[k] x) }
invFun f :=
{ hom := ModuleCat.ofHom <| TensorProduct.uncurry (.id k) _ _ _ f.hom.hom.flip
comm g := ModuleCat.hom_ext <| TensorProduct.ext' fun x y => by
simpa using LinearMap.ext_iff.1 (hom_comm_apply f g y) (A.ρ g x) }
left_inv _ := Action.Hom.ext (ModuleCat.hom_ext <| TensorProduct.ext' fun _ _ => rfl)
variable {A B C}
instance : MonoidalClosed (Rep k G) where
closed A :=
{ rightAdj := Rep.ihom A
adj := Adjunction.mkOfHomEquiv (
{ homEquiv := Rep.homEquiv A
homEquiv_naturality_left_symm := fun _ _ => Action.Hom.ext
(ModuleCat.hom_ext (TensorProduct.ext' fun _ _ => rfl))
homEquiv_naturality_right := fun _ _ => Action.Hom.ext (ModuleCat.hom_ext (LinearMap.ext
fun _ => LinearMap.ext fun _ => rfl)) })}
@[simp]
theorem ihom_obj_ρ_def (A B : Rep k G) : ((ihom A).obj B).ρ = ((Rep.ihom A).obj B).ρ :=
rfl
@[simp]
theorem homEquiv_def (A B C : Rep k G) : (ihom.adjunction A).homEquiv B C = Rep.homEquiv A B C :=
congrFun (congrFun (Adjunction.mkOfHomEquiv_homEquiv _) _) _
@[simp]
theorem ihom_ev_app_hom (A B : Rep k G) :
Action.Hom.hom ((ihom.ev A).app B) = ModuleCat.ofHom
(TensorProduct.uncurry (.id k) A (A →ₗ[k] B) B LinearMap.id.flip) := by
ext; rfl
@[simp] theorem ihom_coev_app_hom (A B : Rep k G) :
Action.Hom.hom ((ihom.coev A).app B) = ModuleCat.ofHom (TensorProduct.mk k _ _).flip :=
ModuleCat.hom_ext <| LinearMap.ext fun _ => LinearMap.ext fun _ => rfl
variable (A B C)
/-- There is a `k`-linear isomorphism between the sets of representation morphisms`Hom(A ⊗ B, C)`
and `Hom(B, Homₖ(A, C))`. -/
def MonoidalClosed.linearHomEquiv : (A ⊗ B ⟶ C) ≃ₗ[k] B ⟶ A ⟶[Rep k G] C :=
{ (ihom.adjunction A).homEquiv _ _ with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
/-- There is a `k`-linear isomorphism between the sets of representation morphisms`Hom(A ⊗ B, C)`
and `Hom(A, Homₖ(B, C))`. -/
def MonoidalClosed.linearHomEquivComm : (A ⊗ B ⟶ C) ≃ₗ[k] A ⟶ B ⟶[Rep k G] C :=
Linear.homCongr k (β_ A B) (Iso.refl _) ≪≫ₗ MonoidalClosed.linearHomEquiv _ _ _
variable {A B C}
@[simp]
theorem MonoidalClosed.linearHomEquiv_hom (f : A ⊗ B ⟶ C) :
(MonoidalClosed.linearHomEquiv A B C f).hom =
ModuleCat.ofHom (TensorProduct.curry f.hom.hom).flip :=
rfl
@[simp]
theorem MonoidalClosed.linearHomEquivComm_hom (f : A ⊗ B ⟶ C) :
(MonoidalClosed.linearHomEquivComm A B C f).hom =
ModuleCat.ofHom (TensorProduct.curry f.hom.hom) :=
rfl
theorem MonoidalClosed.linearHomEquiv_symm_hom (f : B ⟶ A ⟶[Rep k G] C) :
((MonoidalClosed.linearHomEquiv A B C).symm f).hom =
ModuleCat.ofHom (TensorProduct.uncurry (.id k) A B C f.hom.hom.flip) := by
simp [linearHomEquiv]
rfl
theorem MonoidalClosed.linearHomEquivComm_symm_hom (f : A ⟶ B ⟶[Rep k G] C) :
((MonoidalClosed.linearHomEquivComm A B C).symm f).hom =
ModuleCat.ofHom (TensorProduct.uncurry (.id k) A B C f.hom.hom) :=
ModuleCat.hom_ext <| TensorProduct.ext' fun _ _ => rfl
end MonoidalClosed
end Group
end Rep
namespace Representation
open MonoidalCategory
variable {k G : Type u} [CommRing k] [Monoid G] {V W : Type u} [AddCommGroup V] [AddCommGroup W]
[Module k V] [Module k W] (ρ : Representation k G V) (τ : Representation k G W)
/-- Tautological isomorphism to help Lean in typechecking. -/
def repOfTprodIso : Rep.of (ρ.tprod τ) ≅ Rep.of ρ ⊗ Rep.of τ :=
Iso.refl _
theorem repOfTprodIso_apply (x : TensorProduct k V W) : (repOfTprodIso ρ τ).hom.hom x = x :=
rfl
theorem repOfTprodIso_inv_apply (x : TensorProduct k V W) : (repOfTprodIso ρ τ).inv.hom x = x :=
rfl
end Representation
/-!
### The categorical equivalence `Rep k G ≌ Module.{u} (MonoidAlgebra k G)`.
-/
namespace Rep
variable {k G : Type u} [CommRing k] [Monoid G]
-- Verify that the symmetric monoidal structure is available.
example : SymmetricCategory (Rep k G) := by infer_instance
example : MonoidalPreadditive (Rep k G) := by infer_instance
example : MonoidalLinear k (Rep k G) := by infer_instance
/-- Auxiliary lemma for `toModuleMonoidAlgebra`. -/
theorem to_Module_monoidAlgebra_map_aux {k G : Type*} [CommRing k] [Monoid G] (V W : Type*)
[AddCommGroup V] [AddCommGroup W] [Module k V] [Module k W] (ρ : G →* V →ₗ[k] V)
(σ : G →* W →ₗ[k] W) (f : V →ₗ[k] W) (w : ∀ g : G, f.comp (ρ g) = (σ g).comp f)
(r : MonoidAlgebra k G) (x : V) :
f ((((MonoidAlgebra.lift k G (V →ₗ[k] V)) ρ) r) x) =
(((MonoidAlgebra.lift k G (W →ₗ[k] W)) σ) r) (f x) := by
apply MonoidAlgebra.induction_on r
· intro g
simp only [one_smul, MonoidAlgebra.lift_single, MonoidAlgebra.of_apply]
exact LinearMap.congr_fun (w g) x
· intro g h gw hw; simp only [map_add, LinearMap.add_apply, hw, gw]
· intro r g w
simp only [map_smul, w, LinearMap.smul_apply]
/-- Auxiliary definition for `toModuleMonoidAlgebra`. -/
def toModuleMonoidAlgebraMap {V W : Rep k G} (f : V ⟶ W) :
ModuleCat.of (MonoidAlgebra k G) V.ρ.asModule ⟶ ModuleCat.of (MonoidAlgebra k G) W.ρ.asModule :=
ModuleCat.ofHom
{ f.hom.hom with
map_smul' := fun r x => to_Module_monoidAlgebra_map_aux V.V W.V V.ρ W.ρ f.hom.hom
(fun g => ModuleCat.hom_ext_iff.mp (f.comm g)) r x }
/-- Functorially convert a representation of `G` into a module over `MonoidAlgebra k G`. -/
def toModuleMonoidAlgebra : Rep k G ⥤ ModuleCat.{u} (MonoidAlgebra k G) where
obj V := ModuleCat.of _ V.ρ.asModule
map f := toModuleMonoidAlgebraMap f
/-- Functorially convert a module over `MonoidAlgebra k G` into a representation of `G`. -/
def ofModuleMonoidAlgebra : ModuleCat.{u} (MonoidAlgebra k G) ⥤ Rep k G where
obj M := Rep.of (Representation.ofModule M)
map f :=
{ hom := ModuleCat.ofHom
{ f.hom with
map_smul' := fun r x => f.hom.map_smul (algebraMap k _ r) x }
comm := fun g => by ext; apply f.hom.map_smul }
theorem ofModuleMonoidAlgebra_obj_coe (M : ModuleCat.{u} (MonoidAlgebra k G)) :
(ofModuleMonoidAlgebra.obj M : Type u) = RestrictScalars k (MonoidAlgebra k G) M :=
rfl
theorem ofModuleMonoidAlgebra_obj_ρ (M : ModuleCat.{u} (MonoidAlgebra k G)) :
(ofModuleMonoidAlgebra.obj M).ρ = Representation.ofModule M :=
rfl
/-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/
def counitIsoAddEquiv {M : ModuleCat.{u} (MonoidAlgebra k G)} :
(ofModuleMonoidAlgebra ⋙ toModuleMonoidAlgebra).obj M ≃+ M := by
dsimp [ofModuleMonoidAlgebra, toModuleMonoidAlgebra]
exact (Representation.ofModule M).asModuleEquiv.toAddEquiv.trans
(RestrictScalars.addEquiv k (MonoidAlgebra k G) _)
/-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/
def unitIsoAddEquiv {V : Rep k G} : V ≃+ (toModuleMonoidAlgebra ⋙ ofModuleMonoidAlgebra).obj V := by
dsimp [ofModuleMonoidAlgebra, toModuleMonoidAlgebra]
exact V.ρ.asModuleEquiv.symm.toAddEquiv.trans (RestrictScalars.addEquiv _ _ _).symm
/-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/
def counitIso (M : ModuleCat.{u} (MonoidAlgebra k G)) :
(ofModuleMonoidAlgebra ⋙ toModuleMonoidAlgebra).obj M ≅ M :=
LinearEquiv.toModuleIso
{ counitIsoAddEquiv with
map_smul' := fun r x => by
dsimp [counitIsoAddEquiv]
simp }
theorem unit_iso_comm (V : Rep k G) (g : G) (x : V) :
unitIsoAddEquiv ((V.ρ g).toFun x) = ((ofModuleMonoidAlgebra.obj
(toModuleMonoidAlgebra.obj V)).ρ g).toFun (unitIsoAddEquiv x) := by
simp [unitIsoAddEquiv, ofModuleMonoidAlgebra, toModuleMonoidAlgebra]
/-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/
def unitIso (V : Rep k G) : V ≅ (toModuleMonoidAlgebra ⋙ ofModuleMonoidAlgebra).obj V :=
Action.mkIso
(LinearEquiv.toModuleIso
{ unitIsoAddEquiv with
map_smul' := fun r x => by
change (RestrictScalars.addEquiv _ _ _).symm (V.ρ.asModuleEquiv.symm (r • x)) = _
simp only [Representation.asModuleEquiv_symm_map_smul]
rfl })
fun g => by ext; apply unit_iso_comm
/-- The categorical equivalence `Rep k G ≌ ModuleCat (MonoidAlgebra k G)`. -/
def equivalenceModuleMonoidAlgebra : Rep k G ≌ ModuleCat.{u} (MonoidAlgebra k G) where
functor := toModuleMonoidAlgebra
inverse := ofModuleMonoidAlgebra
unitIso := NatIso.ofComponents (fun V => unitIso V) (by cat_disch)
counitIso := NatIso.ofComponents (fun M => counitIso M) (by cat_disch)
-- TODO Verify that the equivalence with `ModuleCat (MonoidAlgebra k G)` is a monoidal functor.
instance : EnoughProjectives (Rep k G) :=
equivalenceModuleMonoidAlgebra.enoughProjectives_iff.2 ModuleCat.enoughProjectives.{u}
instance free_projective {G α : Type u} [Group G] :
Projective (free k G α) :=
equivalenceModuleMonoidAlgebra.toAdjunction.projective_of_map_projective _ <|
@ModuleCat.projective_of_free.{u} _ _
(ModuleCat.of (MonoidAlgebra k G) (Representation.free k G α).asModule)
_ (Representation.freeAsModuleBasis k G α)
section
variable {G : Type u} [Group G] {n : ℕ}
instance diagonal_succ_projective :
Projective (diagonal k G (n + 1)) := by
classical
exact Projective.of_iso (diagonalSuccIsoFree k G n).symm inferInstance
instance leftRegular_projective :
Projective (leftRegular k G) :=
Projective.of_iso (diagonalOneIsoLeftRegular k G) inferInstance
instance trivial_projective_of_subsingleton [Subsingleton G] :
Projective (trivial k G k) :=
Projective.of_iso (ofMulActionSubsingletonIsoTrivial _ _ (Fin 1 → G)) diagonal_succ_projective
end
end Rep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/FiniteIndex.lean | import Mathlib.GroupTheory.Index
import Mathlib.RepresentationTheory.Coinduced
import Mathlib.RepresentationTheory.Induced
/-!
# (Co)induced representations of a finite index subgroup
Given a commutative ring `k`, a finite index subgroup `S ≤ G`, and a `k`-linear `S`-representation
`A`, this file defines an isomorphism $Ind_S^G(A) ≅ Coind_S^G(A)$. Given `g : G` and `a : A`, the
forward map sends `⟦g ⊗ₜ[k] a⟧` to the function `G → A`supported at `sg` by `ρ(s)(a)` for `s : S`
and which is 0 elsewhere. Meanwhile, the inverse sends `f : G → A` to `∑ᵢ ⟦gᵢ ⊗ₜ[k] f(gᵢ)⟧` for
`1 ≤ i ≤ n`, where `g₁, ..., gₙ` is a set of right coset representatives of `S`.
## Main definitions
* `Rep.indCoindIso A`: An isomorphism `Ind_S^G(A) ≅ Coind_S^G(A)` for a finite index subgroup
`S ≤ G` and a `k`-linear `S`-representation `A`.
* `Rep.indCoindNatIso k S`: A natural isomorphism between the functors `Ind_S^G` and `Coind_S^G`.
-/
universe u
namespace Rep
open CategoryTheory Finsupp TensorProduct Representation
variable {k G : Type u} [CommRing k] [Group G] {S : Subgroup G}
[DecidableRel (QuotientGroup.rightRel S)] (A : Rep k S)
/-- Let `S ≤ G` be a subgroup and `(A, ρ)` a `k`-linear `S`-representation. Then given `g : G` and
`a : A`, this is the function `G → A` sending `sg` to `ρ(s)(a)` for all `s : S` and everything else
to 0. -/
noncomputable def indToCoindAux (g : G) : A →ₗ[k] (G → A) :=
LinearMap.pi (fun g₁ => if h : (QuotientGroup.rightRel S).r g₁ g then
A.ρ ⟨g₁ * g⁻¹, by rcases h with ⟨s, rfl⟩; exact mul_inv_cancel_right s.1 g ▸ s.2⟩ else 0)
variable {A}
@[simp]
lemma indToCoindAux_self (g : G) (a : A) :
indToCoindAux A g a g = a := by
rw [indToCoindAux, LinearMap.pi_apply, dif_pos]
· simp [← S.1.one_def]
· rfl
lemma indToCoindAux_of_not_rel (g g₁ : G) (a : A) (h : ¬(QuotientGroup.rightRel S).r g₁ g) :
indToCoindAux A g a g₁ = 0 := by
simp [indToCoindAux, dif_neg h]
@[simp]
lemma indToCoindAux_mul_snd (g g₁ : G) (a : A) (s : S) :
indToCoindAux A g a (s * g₁) = A.ρ s (indToCoindAux A g a g₁) := by
rcases em ((QuotientGroup.rightRel S).r g₁ g) with ⟨s₁, rfl⟩ | h
· simp only [indToCoindAux, LinearMap.pi_apply]
rw [dif_pos ⟨s * s₁, mul_assoc ..⟩, dif_pos ⟨s₁, rfl⟩]
simp [S.1.smul_def, mul_assoc, ← S.1.mul_def]
· rw [indToCoindAux_of_not_rel _ _ _ h, indToCoindAux_of_not_rel, map_zero]
exact mt (fun ⟨s₁, hs₁⟩ => ⟨s⁻¹ * s₁, by simp_all [S.1.smul_def, mul_assoc]⟩) h
@[simp]
lemma indToCoindAux_mul_fst (g₁ g₂ : G) (a : A) (s : S) :
indToCoindAux A (s * g₁) (A.ρ s a) g₂ = indToCoindAux A g₁ a g₂ := by
rcases em ((QuotientGroup.rightRel S).r g₂ g₁) with ⟨s₁, rfl⟩ | h
· simp only [indToCoindAux, LinearMap.pi_apply]
rw [dif_pos ⟨s₁ * s⁻¹, by simp [S.1.smul_def, smul_eq_mul, mul_assoc]⟩, dif_pos ⟨s₁, rfl⟩,
← Module.End.mul_apply, ← map_mul]
congr
simp [Subtype.ext_iff, S.1.smul_def, mul_assoc]
· rw [indToCoindAux_of_not_rel (h := h), indToCoindAux_of_not_rel]
exact mt (fun ⟨s₁, hs₁⟩ => ⟨s₁ * s, by simp_all [S.1.smul_def, mul_assoc]⟩) h
@[simp]
lemma indToCoindAux_snd_mul_inv (g₁ g₂ g₃ : G) (a : A) :
indToCoindAux A g₁ a (g₂ * g₃⁻¹) = indToCoindAux A (g₁ * g₃) a g₂ := by
rcases em ((QuotientGroup.rightRel S).r (g₂ * g₃⁻¹) g₁) with ⟨s, hs⟩ | h
· simp [S.1.smul_def, mul_assoc, ← eq_mul_inv_iff_mul_eq.1 hs]
· rw [indToCoindAux_of_not_rel (h := h), indToCoindAux_of_not_rel]
exact mt (fun ⟨s, hs⟩ => ⟨s, by simpa [S.1.smul_def, eq_mul_inv_iff_mul_eq, mul_assoc]⟩) h
@[simp]
lemma indToCoindAux_fst_mul_inv (g₁ g₂ g₃ : G) (a : A) :
indToCoindAux A (g₁ * g₂⁻¹) a g₃ = indToCoindAux A g₁ a (g₃ * g₂) := by
simpa using (indToCoindAux_snd_mul_inv g₁ g₃ g₂⁻¹ a).symm
lemma indToCoindAux_comm {A B : Rep k S} (f : A ⟶ B) (g₁ g₂ : G) (a : A) :
indToCoindAux B g₁ (f.hom a) g₂ = f.hom (indToCoindAux A g₁ a g₂) := by
rcases em ((QuotientGroup.rightRel S).r g₂ g₁) with ⟨s, rfl⟩ | h
· simp [S.1.smul_def, hom_comm_apply]
· simp [indToCoindAux_of_not_rel (h := h)]
variable (A) in
/-- Let `S ≤ G` be a subgroup and `A` a `k`-linear `S`-representation. This is the `k`-linear map
`Ind_S^G(A) →ₗ[k] Coind_S^G(A)` sending `(⟦g ⊗ₜ[k] a⟧, sg) ↦ ρ(s)(a)`. -/
noncomputable abbrev indToCoind :
ind S.subtype A →ₗ[k] coind S.subtype A :=
Representation.Coinvariants.lift _ (TensorProduct.lift <| linearCombination _ fun g =>
LinearMap.codRestrict _ (indToCoindAux A g) fun _ _ _ => by simp) fun _ => by ext; simp
variable [S.FiniteIndex]
attribute [local instance] Subgroup.fintypeQuotientOfFiniteIndex
variable (A) in
/-- Let `S ≤ G` be a finite index subgroup, `g₁, ..., gₙ` a set of right coset representatives of
`S`, and `A` a `k`-linear `S`-representation. This is the `k`-linear map
`Coind_S^G(A) →ₗ[k] Ind_S^G(A)` sending `f : G → A` to `∑ᵢ ⟦gᵢ ⊗ₜ[k] f(gᵢ)⟧` for `1 ≤ i ≤ n`. -/
@[simps]
noncomputable def coindToInd : coind S.subtype A →ₗ[k] ind S.subtype A where
toFun f := ∑ g : Quotient (QuotientGroup.rightRel S), Quotient.liftOn g (fun g =>
IndV.mk S.subtype _ g (f.1 g)) fun g₁ g₂ ⟨s, (hs : _ * _ = _)⟩ =>
(Submodule.Quotient.eq _).2 <| Coinvariants.mem_ker_of_eq s
(single g₂ 1 ⊗ₜ[k] f.1 g₂) _ <| by have := f.2 s g₂; simp_all
map_add' _ _ := by simpa [← Finset.sum_add_distrib, TensorProduct.tmul_add] using
Finset.sum_congr rfl fun z _ => Quotient.inductionOn z fun _ => by simp
map_smul' _ _ := by simpa [Finset.smul_sum] using Finset.sum_congr rfl fun z _ =>
Quotient.inductionOn z fun _ => by simp
omit [DecidableRel (QuotientGroup.rightRel S)] in
lemma coindToInd_of_support_subset_orbit (g : G) (f : coind S.subtype A)
(hx : f.1.support ⊆ MulAction.orbit S g) :
coindToInd A f = IndV.mk S.subtype _ g (f.1 g) := by
rw [coindToInd_apply, Finset.sum_eq_single ⟦g⟧]
· simp
· intro b _ hb
induction b using Quotient.inductionOn with | h b =>
have : f.1 b = 0 := by
simp_all only [Function.support_subset_iff, ne_eq, Quotient.eq]
contrapose! hx
use b, hx, hb
simp_all
· simp
variable (A)
/-- Let `S ≤ G` be a finite index subgroup, `g₁, ..., gₙ` a set of right coset representatives of
`S`, and `A` a `k`-linear `S`-representation. This is an isomorphism `Ind_S^G(A) ≅ Coind_S^G(A)`.
The forward map sends `(⟦g ⊗ₜ[k] a⟧, sg) ↦ ρ(s)(a)`, and the inverse sends `f : G → A` to
`∑ᵢ ⟦gᵢ ⊗ₜ[k] f(gᵢ)⟧` for `1 ≤ i ≤ n`. -/
@[simps! hom_hom_hom inv_hom_hom]
noncomputable def indCoindIso : ind S.subtype A ≅ coind S.subtype A :=
Action.mkIso ({
hom := ModuleCat.ofHom <| indToCoind A
inv := ModuleCat.ofHom <| coindToInd A
hom_inv_id := by
ext g a
simp only [ModuleCat.hom_comp, ModuleCat.hom_ofHom, LinearMap.coe_comp, Function.comp_apply,
TensorProduct.AlgebraTensorModule.curry_apply, TensorProduct.curry_apply,
LinearMap.coe_restrictScalars]
rw [coindToInd_of_support_subset_orbit g]
· simp
· simp only [Function.support_subset_iff]
intro x hx
contrapose! hx
simpa using indToCoindAux_of_not_rel (h := hx) ..
inv_hom_id := by
ext f g
simp only [ModuleCat.hom_comp, ModuleCat.hom_ofHom, LinearMap.coe_comp, Function.comp_apply,
coindToInd_apply A, map_sum, AddSubmonoidClass.coe_finset_sum, Finset.sum_apply]
rw [Finset.sum_eq_single ⟦g⟧]
· simp
· intro b _ hb
induction b using Quotient.inductionOn with | h b =>
simpa using indToCoindAux_of_not_rel b g (f.1 b) (mt Quotient.sound hb.symm)
· simp })
fun _ => by ext; simp [ModuleCat.endRingEquiv]
variable (k S)
/-- Given a finite index subgroup `S ≤ G`, this is a natural isomorphism between the `Ind_S^G` and
`Coind_G^S` functors `Rep k S ⥤ Rep k G`. -/
@[simps! hom_app inv_app]
noncomputable def indCoindNatIso : indFunctor k S.subtype ≅ coindFunctor k S.subtype :=
NatIso.ofComponents (fun _ => indCoindIso _) fun f => by
simp only [indFunctor_obj, coindFunctor_obj]; ext; simp [indToCoindAux_comm]
/-- Given a finite index subgroup `S ≤ G`, `Ind_S^G` is right adjoint to the restriction functor
`Res k G ⥤ Res k S`, since it is naturally isomorphic to `Coind_S^G`. -/
noncomputable def resIndAdjunction : Action.res _ S.subtype ⊣ indFunctor k S.subtype :=
(resCoindAdjunction k S.subtype).ofNatIsoRight (indCoindNatIso k S).symm
noncomputable instance : (indFunctor k S.subtype).IsRightAdjoint :=
(resIndAdjunction k S).isRightAdjoint
variable {k S}
@[simp]
lemma resIndAdjunction_counit_app :
(resIndAdjunction k S).counit.app A = (Action.res _ S.subtype).map (indCoindIso A).hom ≫
(resCoindAdjunction k S.subtype).counit.app A := rfl
@[simp]
lemma resIndAdjunction_unit_app (B : Rep k G) :
(resIndAdjunction k S).unit.app B = (resCoindAdjunction k S.subtype).unit.app B ≫
(indCoindIso ((Action.res _ S.subtype).obj B)).inv := rfl
lemma resIndAdjunction_homEquiv_apply
{B : Rep k G} (f : (Action.res _ S.subtype).obj B ⟶ A) :
(resIndAdjunction k S).homEquiv _ _ f =
resCoindHomEquiv S.subtype B A f ≫ (indCoindIso A).inv := by
simp only [resIndAdjunction, Adjunction.ofNatIsoRight, resCoindAdjunction,
Adjunction.mkOfHomEquiv_homEquiv]
rfl
lemma resIndAdjunction_homEquiv_symm_apply
{B : Rep k G} (f : B ⟶ (indFunctor k S.subtype).obj A) :
((resIndAdjunction k S).homEquiv _ _).symm f =
(resCoindHomEquiv S.subtype B A).symm (f ≫ (indCoindIso A).hom) := by
simp only [resIndAdjunction, Adjunction.ofNatIsoRight, resCoindAdjunction,
Adjunction.mkOfHomEquiv_homEquiv]
rfl
variable (k S) in
/-- Given a finite index subgroup `S ≤ G`, `Coind_S^G` is left adjoint to the restriction functor
`Res k G ⥤ Res k S`, since it is naturally isomorphic to `Ind_S^G`. -/
noncomputable def coindResAdjunction : coindFunctor k S.subtype ⊣ Action.res _ S.subtype :=
(indResAdjunction k S.subtype).ofNatIsoLeft (indCoindNatIso k S)
noncomputable instance : (coindFunctor k S.subtype).IsLeftAdjoint :=
(coindResAdjunction k S).isLeftAdjoint
@[simp]
lemma coindResAdjunction_counit_app (B : Rep k G) :
(coindResAdjunction k S).counit.app B = (indCoindIso <| (Action.res _ S.subtype).obj B).inv ≫
(indResAdjunction k S.subtype).counit.app B := by
simp [coindResAdjunction, Adjunction.ofNatIsoLeft, Adjunction.equivHomsetLeftOfNatIso,
indResAdjunction]
@[simp]
lemma coindResAdjunction_unit_app :
(coindResAdjunction k S).unit.app A = (indResAdjunction k S.subtype).unit.app A ≫
(Action.res _ S.subtype).map (indCoindIso A).hom := by
ext
simp [coindResAdjunction, Adjunction.ofNatIsoLeft, Adjunction.equivHomsetLeftOfNatIso,
indResAdjunction]
lemma coindResAdjunction_homEquiv_apply {B : Rep k G} (f : coind S.subtype A ⟶ B) :
(coindResAdjunction k S).homEquiv _ _ f =
indResHomEquiv S.subtype A B ((indCoindIso A).hom ≫ f) := by
simp only [coindResAdjunction, Adjunction.ofNatIsoLeft, indResAdjunction,
Adjunction.mkOfHomEquiv_homEquiv]
rfl
lemma coindResAdjunction_homEquiv_symm_apply
{B : Rep k G} (f : A ⟶ (Action.res _ S.subtype).obj B) :
((coindResAdjunction k S).homEquiv _ _).symm f =
(indCoindIso A).inv ≫ (indResHomEquiv S.subtype A B).symm f := by
simp only [coindResAdjunction, Adjunction.ofNatIsoLeft, indResAdjunction,
Adjunction.mkOfHomEquiv_homEquiv]
rfl
end Rep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Submodule.lean | import Mathlib.Algebra.Module.Submodule.Invariant
import Mathlib.RepresentationTheory.Basic
/-!
# Invariant submodules of a group representation
-/
variable {k G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V]
(ρ : Representation k G V)
namespace Representation
/-- Given a representation `ρ` of a group, `ρ.invtSubmodule` is the sublattice of all
`ρ`-invariant submodules. -/
def invtSubmodule : Sublattice (Submodule k V) :=
⨅ g, Module.End.invtSubmodule (ρ g)
lemma mem_invtSubmodule {p : Submodule k V} :
p ∈ ρ.invtSubmodule ↔ ∀ g, p ∈ Module.End.invtSubmodule (ρ g) := by
rw [invtSubmodule, Sublattice.mem_iInf]
namespace invtSubmodule
@[simp] protected lemma top_mem : ⊤ ∈ ρ.invtSubmodule := by simp [invtSubmodule]
@[simp] protected lemma bot_mem : ⊥ ∈ ρ.invtSubmodule := by simp [invtSubmodule]
instance : BoundedOrder ρ.invtSubmodule where
top := ⟨⊤, invtSubmodule.top_mem ρ⟩
bot := ⟨⊥, invtSubmodule.bot_mem ρ⟩
le_top := fun ⟨p, hp⟩ ↦ by simp
bot_le := fun ⟨p, hp⟩ ↦ by simp
@[simp] protected lemma coe_top : (↑(⊤ : ρ.invtSubmodule) : Submodule k V) = ⊤ := rfl
@[simp] protected lemma coe_bot : (↑(⊥ : ρ.invtSubmodule) : Submodule k V) = ⊥ := rfl
protected lemma nontrivial_iff : Nontrivial ρ.invtSubmodule ↔ Nontrivial V := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· contrapose! h
infer_instance
· refine ⟨⊥, ⊤, ?_⟩
rw [← Subtype.coe_ne_coe, invtSubmodule.coe_top, invtSubmodule.coe_bot]
exact bot_ne_top
instance [Nontrivial V] : Nontrivial ρ.invtSubmodule :=
(invtSubmodule.nontrivial_iff ρ).mpr inferInstance
end invtSubmodule
lemma asAlgebraHom_mem_of_forall_mem (p : Submodule k V) (hp : ∀ g, ∀ v ∈ p, ρ g v ∈ p)
(v : V) (hv : v ∈ p) (x : MonoidAlgebra k G) :
ρ.asAlgebraHom x v ∈ p := by
apply x.induction_on <;> aesop
/-- The natural order isomorphism between the two ways to represent invariant submodules. -/
noncomputable def mapSubmodule :
ρ.invtSubmodule ≃o Submodule (MonoidAlgebra k G) ρ.asModule where
toFun p :=
{ toAddSubmonoid := (p : Submodule k V).toAddSubmonoid.map ρ.asModuleEquiv.symm
smul_mem' := by
simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup,
AddSubmonoid.mem_map, Submodule.mem_toAddSubmonoid, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
refine fun x v hv ↦ ⟨ρ.asModuleEquiv (x • ρ.asModuleEquiv.symm v), ?_, rfl⟩
simpa using ρ.asAlgebraHom_mem_of_forall_mem p (ρ.mem_invtSubmodule.mp p.property) v hv x }
invFun q := ⟨(Submodule.orderIsoMapComap ρ.asModuleEquiv.symm).symm (q.restrictScalars k), by
rw [invtSubmodule, Sublattice.mem_iInf]
intro g v hv
simp only [Submodule.orderIsoMapComap_symm_apply, Submodule.mem_comap] at hv ⊢
convert q.smul_mem (MonoidAlgebra.of k G g) hv using 1
rw [← asModuleEquiv_symm_map_rho]⟩
left_inv p := by ext; simp
right_inv q := by ext; aesop
map_rel_iff' {p q} :=
⟨fun h x hx ↦ by
suffices ρ.asModuleEquiv.symm x ∈
(q : Submodule k V).toAddSubmonoid.map ρ.asModuleEquiv.symm by simpa using this
exact h <| by simpa using hx,
fun h x hx ↦ by aesop⟩
end Representation |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Invariants.lean | import Mathlib.RepresentationTheory.Basic
import Mathlib.RepresentationTheory.FDRep
/-!
# Subspace of invariants a group representation
This file introduces the subspace of invariants of a group representation
and proves basic results about it.
The main tool used is the average of all elements of the group, seen as an element of
`MonoidAlgebra k G`. The action of this special element gives a projection onto the
subspace of invariants.
In order for the definition of the average element to make sense, we need to assume for most of the
results that the order of `G` is invertible in `k` (e. g. `k` has characteristic `0`).
-/
suppress_compilation
universe u
open MonoidAlgebra
open Representation
namespace GroupAlgebra
variable (k G : Type*) [CommSemiring k] [Group G]
variable [Fintype G] [Invertible (Fintype.card G : k)]
/-- The average of all elements of the group `G`, considered as an element of `MonoidAlgebra k G`.
-/
noncomputable def average : MonoidAlgebra k G :=
⅟(Fintype.card G : k) • ∑ g : G, of k G g
/-- `average k G` is invariant under left multiplication by elements of `G`.
-/
@[simp]
theorem mul_average_left (g : G) : ↑(Finsupp.single g 1) * average k G = average k G := by
simp only [mul_one, Finset.mul_sum, Algebra.mul_smul_comm, average, MonoidAlgebra.of_apply,
MonoidAlgebra.single_mul_single]
set f : G → MonoidAlgebra k G := fun x => Finsupp.single x 1
change ⅟(Fintype.card G : k) • ∑ x : G, f (g * x) = ⅟(Fintype.card G : k) • ∑ x : G, f x
rw [Function.Bijective.sum_comp (Group.mulLeft_bijective g) _]
/-- `average k G` is invariant under right multiplication by elements of `G`.
-/
@[simp]
theorem mul_average_right (g : G) : average k G * ↑(Finsupp.single g 1) = average k G := by
simp only [mul_one, Finset.sum_mul, Algebra.smul_mul_assoc, average, MonoidAlgebra.of_apply,
MonoidAlgebra.single_mul_single]
set f : G → MonoidAlgebra k G := fun x => Finsupp.single x 1
change ⅟(Fintype.card G : k) • ∑ x : G, f (x * g) = ⅟(Fintype.card G : k) • ∑ x : G, f x
rw [Function.Bijective.sum_comp (Group.mulRight_bijective g) _]
end GroupAlgebra
namespace Representation
section Invariants
open GroupAlgebra
variable {k G V : Type*} [CommSemiring k] [Group G] [AddCommMonoid V] [Module k V]
variable (ρ : Representation k G V)
/-- The subspace of invariants, consisting of the vectors fixed by all elements of `G`.
-/
def invariants : Submodule k V where
carrier := setOf fun v => ∀ g : G, ρ g v = v
zero_mem' g := by simp only [map_zero]
add_mem' hv hw g := by simp only [hv g, hw g, map_add]
smul_mem' r v hv g := by simp only [hv g, LinearMap.map_smulₛₗ, RingHom.id_apply]
@[simp]
theorem mem_invariants (v : V) : v ∈ invariants ρ ↔ ∀ g : G, ρ g v = v := by rfl
theorem invariants_eq_inter : (invariants ρ).carrier = ⋂ g : G, Function.fixedPoints (ρ g) := by
ext; simp [Function.IsFixedPt]
theorem invariants_eq_top [ρ.IsTrivial] :
invariants ρ = ⊤ :=
eq_top_iff.2 (fun x _ g => ρ.isTrivial_apply g x)
lemma mem_invariants_iff_of_forall_mem_zpowers
(g : G) (hg : ∀ x, x ∈ Subgroup.zpowers g) (x : V) :
x ∈ ρ.invariants ↔ ρ g x = x :=
⟨fun h => h g, fun hx γ => by
rcases hg γ with ⟨i, rfl⟩
induction i with | zero => simp | succ i _ => simp_all [zpow_add_one] | pred i h => _
simpa [neg_sub_comm _ (1 : ℤ), zpow_sub] using congr(ρ g⁻¹ $(h.trans hx.symm))⟩
section
variable [Fintype G] [Invertible (Fintype.card G : k)]
/-- The action of `average k G` gives a projection map onto the subspace of invariants.
-/
@[simp]
noncomputable def averageMap : V →ₗ[k] V :=
asAlgebraHom ρ (average k G)
/-- The `averageMap` sends elements of `V` to the subspace of invariants.
-/
theorem averageMap_invariant (v : V) : averageMap ρ v ∈ invariants ρ := fun g => by
rw [averageMap, ← asAlgebraHom_single_one, ← Module.End.mul_apply, ← map_mul (asAlgebraHom ρ),
mul_average_left]
/-- The `averageMap` acts as the identity on the subspace of invariants.
-/
theorem averageMap_id (v : V) (hv : v ∈ invariants ρ) : averageMap ρ v = v := by
rw [mem_invariants] at hv
simp [average, map_sum, hv, Finset.card_univ, ← Nat.cast_smul_eq_nsmul k _ v, smul_smul]
theorem isProj_averageMap : LinearMap.IsProj ρ.invariants ρ.averageMap :=
⟨ρ.averageMap_invariant, ρ.averageMap_id⟩
end
section Subgroup
variable {V : Type*} [AddCommMonoid V] [Module k V]
variable (ρ : Representation k G V) (S : Subgroup G) [S.Normal]
lemma le_comap_invariants (g : G) :
(invariants <| ρ.comp S.subtype) ≤
(invariants <| ρ.comp S.subtype).comap (ρ g) :=
fun x hx ⟨s, hs⟩ => by
simpa using congr(ρ g $(hx ⟨(g⁻¹ * s * g), Subgroup.Normal.conj_mem' ‹_› s hs g⟩))
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` restricts to a `G`-representation on
the invariants of `ρ|_S`. -/
abbrev toInvariants :
Representation k G (invariants (ρ.comp S.subtype)) :=
subrepresentation ρ _ <| le_comap_invariants ρ S
instance : IsTrivial ((toInvariants ρ S).comp S.subtype) where
out g := LinearMap.ext fun ⟨x, hx⟩ => Subtype.ext <| by simpa using (hx g)
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` induces a `G ⧸ S`-representation on
the invariants of `ρ|_S`. -/
abbrev quotientToInvariants :
Representation k (G ⧸ S) (invariants (ρ.comp S.subtype)) :=
ofQuotient (toInvariants ρ S) S
end Subgroup
end Invariants
namespace linHom
open CategoryTheory Action
section Rep
variable {k : Type u} [CommRing k] {G : Type u} [Group G]
theorem mem_invariants_iff_comm {X Y : Rep k G} (f : X.V →ₗ[k] Y.V) (g : G) :
(linHom X.ρ Y.ρ) g f = f ↔ f.comp (X.ρ g) = (Y.ρ g).comp f := by
dsimp
rw [← LinearMap.comp_assoc, ← ModuleCat.hom_ofHom (Y.ρ g), ← ModuleCat.hom_ofHom f,
← ModuleCat.hom_comp, ← ModuleCat.hom_ofHom (X.ρ g⁻¹), ← ModuleCat.hom_comp,
Rep.ofHom_ρ, ← ρAut_apply_inv X g, Rep.ofHom_ρ, ← ρAut_apply_hom Y g,
← ModuleCat.hom_ext_iff, Iso.inv_comp_eq, ρAut_apply_hom, ← ModuleCat.hom_ofHom (X.ρ g),
← ModuleCat.hom_comp, ← ModuleCat.hom_ext_iff]
exact comm
/-- The invariants of the representation `linHom X.ρ Y.ρ` correspond to the representation
homomorphisms from `X` to `Y`. -/
@[simps]
def invariantsEquivRepHom (X Y : Rep k G) : (linHom X.ρ Y.ρ).invariants ≃ₗ[k] X ⟶ Y where
toFun f := ⟨ModuleCat.ofHom f.val, fun g =>
ModuleCat.hom_ext ((mem_invariants_iff_comm _ g).1 (f.property g))⟩
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f := ⟨f.hom.hom, fun g =>
(mem_invariants_iff_comm _ g).2 (ModuleCat.hom_ext_iff.mp (f.comm g))⟩
end Rep
section FDRep
variable {k : Type u} [Field k] {G : Type u} [Group G]
/-- The invariants of the representation `linHom X.ρ Y.ρ` correspond to the representation
homomorphisms from `X` to `Y`. -/
def invariantsEquivFDRepHom (X Y : FDRep k G) : (linHom X.ρ Y.ρ).invariants ≃ₗ[k] X ⟶ Y := by
rw [← FDRep.forget₂_ρ, ← FDRep.forget₂_ρ]
-- Porting note: The original version used `linHom.invariantsEquivRepHom _ _ ≪≫ₗ`
exact linHom.invariantsEquivRepHom
((forget₂ (FDRep k G) (Rep k G)).obj X) ((forget₂ (FDRep k G) (Rep k G)).obj Y) ≪≫ₗ
FDRep.forget₂HomLinearEquiv X Y
end FDRep
end linHom
end Representation
namespace Rep
open CategoryTheory
variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) (S : Subgroup G) [S.Normal]
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` restricts to a `G`-representation on
the invariants of `ρ|_S`. -/
abbrev toInvariants : Rep k G := Rep.of <| A.ρ.toInvariants S
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` induces a `G ⧸ S`-representation on
the invariants of `ρ|_S`. -/
abbrev quotientToInvariants : Rep k (G ⧸ S) := Rep.of (A.ρ.quotientToInvariants S)
variable (k G)
/-- The functor sending a representation to its submodule of invariants. -/
@[simps! obj_carrier map_hom]
noncomputable def invariantsFunctor : Rep k G ⥤ ModuleCat k where
obj A := ModuleCat.of k A.ρ.invariants
map {A B} f := ModuleCat.ofHom <| (f.hom.hom ∘ₗ A.ρ.invariants.subtype).codRestrict
B.ρ.invariants fun ⟨c, hc⟩ g => by
have := (hom_comm_apply f g c).symm
simp_all [hc g]
instance : (invariantsFunctor k G).PreservesZeroMorphisms where
instance : (invariantsFunctor k G).Additive where
instance : (invariantsFunctor k G).Linear k where
variable {G} in
/-- Given a normal subgroup S ≤ G, this is the functor sending a `G`-representation `A` to the
`G ⧸ S`-representation it induces on `A^S`. -/
@[simps obj_V map_hom]
noncomputable def quotientToInvariantsFunctor (S : Subgroup G) [S.Normal] :
Rep k G ⥤ Rep k (G ⧸ S) where
obj X := X.quotientToInvariants S
map {X Y} f := {
hom := (invariantsFunctor k S).map ((Action.res _ S.subtype).map f)
comm g := QuotientGroup.induction_on g fun g => by
ext x
simp [ModuleCat.endRingEquiv, Representation.quotientToInvariants,
Representation.toInvariants, invariants, hom_comm_apply] }
/-- The adjunction between the functor equipping a module with the trivial representation, and
the functor sending a representation to its submodule of invariants. -/
@[simps]
noncomputable def invariantsAdjunction : trivialFunctor k G ⊣ invariantsFunctor k G where
unit := { app _ := ModuleCat.ofHom <| LinearMap.id.codRestrict _ <| by simp [trivialFunctor] }
counit := { app X := {
hom := ModuleCat.ofHom <| Submodule.subtype _
comm g := by ext x; exact (x.2 g).symm }}
@[simp]
lemma invariantsAdjunction_homEquiv_apply_hom
{X : ModuleCat k} {Y : Rep k G} (f : (trivialFunctor k G).obj X ⟶ Y) :
((invariantsAdjunction k G).homEquiv _ _ f).hom =
f.hom.hom.codRestrict _ (by intro _ _; exact (hom_comm_apply f _ _).symm) := rfl
@[simp]
lemma invariantsAdjunction_homEquiv_symm_apply_hom
{X : ModuleCat k} {Y : Rep k G} (f : X ⟶ (invariantsFunctor k G).obj Y) :
(((invariantsAdjunction k G).homEquiv _ _).symm f).hom.hom =
Submodule.subtype _ ∘ₗ f.hom := rfl
noncomputable instance : (invariantsFunctor k G).IsRightAdjoint :=
(invariantsAdjunction k G).isRightAdjoint
end Rep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/FinGroupCharZero.lean | import Mathlib.Algebra.Category.FGModuleCat.Abelian
import Mathlib.Algebra.Category.ModuleCat.Injective
import Mathlib.RepresentationTheory.Character
import Mathlib.RepresentationTheory.Maschke
import Mathlib.RingTheory.SimpleModule.InjectiveProjective
/-!
# Applications of Maschke's theorem
This proves some properties of representations that follow from Maschke's
theorem.
We prove that, if `G` is a finite group whose order is invertible in a field `k`,
then every object of `Rep k G` (resp. `FDRep k G`) is injective and projective.
We also give two simpleness criteria for an object `V` of `FDRep k G`, when `k` is
an algebraically closed field in which the order of `G` is invertible:
* `FDRep.simple_iff_end_is_rank_one`: `V` is simple if and only `V ⟶ V` is a `k`-vector
space of dimension `1`.
* `FDRep.simple_iff_char_is_norm_one`: when `k` is characteristic zero, `V` is simple
if and only if `∑ g : G, V.character g * V.character g⁻¹ = Fintype.card G`.
-/
universe u
variable {k : Type u} [Field k] {G : Type u} [Fintype G] [Group G]
open CategoryTheory Limits
namespace Rep
variable [NeZero (Fintype.card G : k)]
/--
If `G` is finite and its order is nonzero in the field `k`, then every object of
`Rep k G` is injective.
-/
instance (V : Rep k G) : Injective V := by
rw [← Rep.equivalenceModuleMonoidAlgebra.map_injective_iff,
← Module.injective_iff_injective_object]
exact Module.injective_of_isSemisimpleRing _ _
/--
If `G` is finite and its order is nonzero in the field `k`, then every object of
`Rep k G` is projective.
-/
-- Will this clash with the previously defined `Projective` instances?
instance (V : Rep k G) : Projective V := by
rw [← Rep.equivalenceModuleMonoidAlgebra.map_projective_iff,
← IsProjective.iff_projective]
exact Module.projective_of_isSemisimpleRing _ _
end Rep
namespace FDRep
/--
If `G` is finite and its order is nonzero in the field `k`, then every object of
`FDRep k G` is injective.
-/
instance [NeZero (Fintype.card G : k)] (V : FDRep k G) : Injective V :=
(forget₂ (FDRep k G) (Rep k G)).injective_of_map_injective inferInstance
/--
If `G` is finite and its order is nonzero in the field `k`, then every object of
`FDRep k G` is projective.
-/
instance [NeZero (Fintype.card G : k)] (V : FDRep k G) : Projective V :=
(forget₂ (FDRep k G) (Rep k G)).projective_of_map_projective inferInstance
variable [IsAlgClosed k]
/--
If `G` is finite and its order is nonzero in an algebraically closed field `k`,
then an object of `FDRep k G` is simple if and only if its space of endomorphisms is
a `k`-vector space of dimension `1`.
-/
lemma simple_iff_end_is_rank_one [NeZero (Fintype.card G : k)] (V : FDRep k G) :
Simple V ↔ Module.finrank k (V ⟶ V) = 1 where
mp h := finrank_endomorphism_simple_eq_one k V
mpr h := by
refine { mono_isIso_iff_nonzero {W} f _ := ⟨fun hf habs ↦ ?_, fun hf ↦ ?_⟩ }
· rw [habs, isIsoZero_iff_source_target_isZero] at hf
obtain ⟨g, hg⟩ : ∃ g : V ⟶ V, g ≠ 0 :=
(Module.finrank_pos_iff_exists_ne_zero (R := k)).mp (by grind)
exact hg (hf.2.eq_zero_of_src g)
· suffices Epi f by exact isIso_of_mono_of_epi f
suffices Epi (Abelian.image.ι f) by
rw [← Abelian.image.fac f]
exact epi_comp _ _
rw [← Abelian.image.fac f] at hf
set ι := Abelian.image.ι f
set φ := Injective.factorThru (𝟙 _) ι
have hφι : φ ≫ ι ≠ 0 := by
intro habs
have hιφ : 𝟙 _ = ι ≫ φ := (Injective.comp_factorThru (𝟙 _) ι).symm
apply_fun (· ≫ ι) at hιφ
simp_all
obtain ⟨c, hc⟩ : ∃ c : k, c • _ = 𝟙 V := (finrank_eq_one_iff_of_nonzero' _ hφι).mp h (𝟙 V)
refine Preadditive.epi_of_cancel_zero _ (fun g hg ↦ ?_)
apply_fun (· ≫ g) at hc
simpa [hg] using hc.symm
/--
If `G` is finite and `k` an algebraically closed field of characteristic `0`,
then an object of `FDRep k G` is simple if and only if its character has norm `1`.
-/
lemma simple_iff_char_is_norm_one [CharZero k] (V : FDRep k G) :
Simple V ↔ ∑ g : G, V.character g * V.character g⁻¹ = Fintype.card G where
mp h := by
have := invertibleOfNonzero (NeZero.ne (Fintype.card G : k))
classical
have : ⅟(Fintype.card G : k) • ∑ g, V.character g * V.character g⁻¹ = 1 := by
simpa only [Nonempty.intro (Iso.refl V), ↓reduceIte] using char_orthonormal V V
apply_fun (· * (Fintype.card G : k)) at this
rwa [mul_comm, ← smul_eq_mul, smul_smul, mul_invOf_self, smul_eq_mul, one_mul, one_mul] at this
mpr h := by
have := invertibleOfNonzero (NeZero.ne (Fintype.card G : k))
have eq := FDRep.scalar_product_char_eq_finrank_equivariant V V
rw [h] at eq
simp only [invOf_eq_inv, smul_eq_mul, inv_mul_cancel_of_invertible] at eq
rw [simple_iff_end_is_rank_one, ← Nat.cast_inj (R := k), ← eq, Nat.cast_one]
end FDRep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Character.lean | import Mathlib.RepresentationTheory.FDRep
import Mathlib.LinearAlgebra.Trace
import Mathlib.RepresentationTheory.Invariants
/-!
# Characters of representations
This file introduces characters of representation and proves basic lemmas about how characters
behave under various operations on representations.
A key result is the orthogonality of characters for irreducible representations of finite group
over an algebraically closed field whose characteristic doesn't divide the order of the group. It
is the theorem `char_orthonormal`
## Implementation notes
Irreducible representations are implemented categorically, using the `CategoryTheory.Simple` class
defined in `Mathlib/CategoryTheory/Simple.lean`
## TODO
* Once we have the monoidal closed structure on `FdRep k G` and a better API for the rigid
structure, `char_dual` and `char_linHom` should probably be stated
in terms of `Vᘁ` and `ihom V W`.
-/
noncomputable section
universe u
open CategoryTheory LinearMap CategoryTheory.MonoidalCategory Representation Module
variable {k : Type u} [Field k]
namespace FDRep
section Monoid
variable {G : Type u} [Monoid G]
/-- The character of a representation `V : FDRep k G` is the function associating to `g : G` the
trace of the linear map `V.ρ g`. -/
def character (V : FDRep k G) (g : G) :=
LinearMap.trace k V (V.ρ g)
theorem char_mul_comm (V : FDRep k G) (g : G) (h : G) :
V.character (h * g) = V.character (g * h) := by simp only [trace_mul_comm, character, map_mul]
@[simp]
theorem char_one (V : FDRep k G) : V.character 1 = Module.finrank k V := by
simp only [character, map_one, trace_one]
/-- The character is multiplicative under the tensor product. -/
@[simp]
theorem char_tensor (V W : FDRep k G) : (V ⊗ W).character = V.character * W.character := by
ext g; convert trace_tensorProduct' (V.ρ g) (W.ρ g)
/-- The character of isomorphic representations is the same. -/
theorem char_iso {V W : FDRep k G} (i : V ≅ W) : V.character = W.character := by
ext g
simp only [character, FDRep.Iso.conj_ρ i]
exact (trace_conj' (V.ρ g) _).symm
end Monoid
section Group
variable {G : Type u} [Group G]
/-- The character of a representation is constant on conjugacy classes. -/
@[simp]
theorem char_conj (V : FDRep k G) (g : G) (h : G) : V.character (h * g * h⁻¹) = V.character g := by
rw [char_mul_comm, inv_mul_cancel_left]
@[simp]
theorem char_dual (V : FDRep k G) (g : G) : (of (dual V.ρ)).character g = V.character g⁻¹ :=
trace_transpose' (V.ρ g⁻¹)
@[simp]
theorem char_linHom (V W : FDRep k G) (g : G) :
(of (linHom V.ρ W.ρ)).character g = V.character g⁻¹ * W.character g := by
rw [← char_iso (dualTensorIsoLinHom _ _), char_tensor, Pi.mul_apply, char_dual]
variable [Fintype G] [Invertible (Fintype.card G : k)]
theorem average_char_eq_finrank_invariants (V : FDRep k G) :
⅟(Fintype.card G : k) • ∑ g : G, V.character g = finrank k (invariants V.ρ) := by
rw [← (isProj_averageMap V.ρ).trace]
simp [character, GroupAlgebra.average, _root_.map_sum]
/--
If `V` are `W` are finite-dimensional representations of a finite group, then the
scalar product of their characters is equal to the dimension of the space of
equivariant maps from `V` to `W`.
-/
theorem scalar_product_char_eq_finrank_equivariant (V W : FDRep k G) :
⅟(Fintype.card G : k) • ∑ g : G, W.character g * V.character g⁻¹ =
Module.finrank k (V ⟶ W) := by
conv_lhs => congr; rfl; congr; rfl; intro _; rw [mul_comm, ← FDRep.char_linHom]
-- The scalar product is the character of `Hom(V, W).`
rw [FDRep.average_char_eq_finrank_invariants, ← LinearEquiv.finrank_eq
(Representation.linHom.invariantsEquivFDRepHom V W), of_ρ']
simp only [FGModuleCat.of_carrier]
-- The average over the group of the character of a representation equals the dimension of the
-- space of invariants, and the space of invariants of `Hom(W, V)` is the subspace of
--`G`-equivariant linear maps, `Hom_G(W, V)`.
end Group
section Orthogonality
variable {G : Type u} [Group G] [IsAlgClosed k]
variable [Fintype G] [Invertible (Fintype.card G : k)]
open scoped Classical in
/-- Orthogonality of characters for irreducible representations of finite group over an
algebraically closed field whose characteristic doesn't divide the order of the group. -/
theorem char_orthonormal (V W : FDRep k G) [Simple V] [Simple W] :
⅟(Fintype.card G : k) • ∑ g : G, V.character g * W.character g⁻¹ =
if Nonempty (V ≅ W) then ↑1 else ↑0 := by
rw [scalar_product_char_eq_finrank_equivariant]
-- The scalar products of the characters is equal to the dimension of the space of
-- equivariant maps `W ⟶ V`.
rw_mod_cast [finrank_hom_simple_simple W V, Iso.nonempty_iso_symm]
-- By Schur's Lemma, the dimension of `Hom_G(W, V)` is `1` is `V ≅ W` and `0` otherwise.
end Orthogonality
end FDRep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Induced.lean | import Mathlib.RepresentationTheory.Coinvariants
/-!
# Induced representations
Given a commutative ring `k`, a group homomorphism `φ : G →* H`, and a `k`-linear
`G`-representation `A`, this file introduces the induced representation $Ind_G^H(A)$ of `A` as
an `H`-representation.
By `ind φ A` we mean the `(k[H] ⊗[k] A)_G` with the `G`-representation on `k[H]` defined by `φ`.
We define a representation of `H` on this submodule by sending `h : H` and `⟦h₁ ⊗ₜ a⟧` to
`⟦h₁h⁻¹ ⊗ₜ a⟧`.
We also prove that the restriction functor `Rep k H ⥤ Rep k G` along `φ` is right adjoint to the
induction functor and hence that the induction functor preserves colimits.
Additionally, we show that the functor `Rep k H ⥤ ModuleCat k` sending `B : Rep k H` to
`(Ind(φ)(A) ⊗ B))_H` is naturally isomorphic to the one sending `B` to `(A ⊗ Res(φ)(B))_G`. This
is used to prove Shapiro's lemma in
`Mathlib/RepresentationTheory/Homological/GroupHomology/Shapiro.lean`.
## Main definitions
* `Representation.ind φ ρ` : given a group homomorphism `φ : G →* H`, this is the induction of a
`G`-representation `(A, ρ)` along `φ`, defined as `(k[H] ⊗[k] A)_G` and with `H`-action given by
`h • ⟦h₁ ⊗ₜ a⟧ := ⟦h₁h⁻¹ ⊗ₜ a⟧` for `h, h₁ : H`, `a : A`.
* `Rep.indResAdjunction k φ`: given a group homomorphism `φ : G →* H`, this is the adjunction
between the induction functor along `φ` and the restriction functor `Rep k H ⥤ Rep k G`
along `φ`.
* `Rep.coinvariantsTensorIndNatIso φ A` : given a group homomorphism `φ : G →* H` and
`A : Rep k G`, this is a natural isomorphism between the functor sending `B : Rep k H` to
`(Ind(φ)(A) ⊗ B))_H` and the one sending `B` to `(A ⊗ Res(φ)(B))_G`. Used to prove Shapiro's
lemma.
-/
universe u
namespace Representation
open Finsupp TensorProduct
variable {k G H : Type*} [CommRing k] [Group G] [Group H] (φ : G →* H) {A B : Type*}
[AddCommGroup A] [Module k A] (ρ : Representation k G A)
[AddCommGroup B] [Module k B] (τ : Representation k G B)
/-- Given a group homomorphism `φ : G →* H` and a `G`-representation `(A, ρ)`, this is the
`k`-module `(k[H] ⊗[k] A)_G` with the `G`-representation on `k[H]` defined by `φ`.
See `Representation.ind` for the induced `H`-representation on `IndV φ ρ`. -/
abbrev IndV := Coinvariants (V := TensorProduct k (H →₀ k) A)
(Representation.tprod ((leftRegular k H).comp φ) ρ)
/-- Given a group homomorphism `φ : G →* H` and a `G`-representation `(A, ρ)`, this is the
`H → A →ₗ[k] (k[H] ⊗[k] A)_G` sending `h, a` to `⟦h ⊗ₜ a⟧`. -/
noncomputable abbrev IndV.mk (h : H) : A →ₗ[k] IndV φ ρ :=
Coinvariants.mk _ ∘ₗ TensorProduct.mk k _ _ (single h 1)
@[ext]
lemma IndV.hom_ext {f g : IndV φ ρ →ₗ[k] B}
(hfg : ∀ h : H, f ∘ₗ IndV.mk φ ρ h = g ∘ₗ IndV.mk φ ρ h) : f = g :=
Coinvariants.hom_ext <| TensorProduct.ext <| Finsupp.lhom_ext' fun h =>
LinearMap.ext_ring <| hfg h
/-- Given a group homomorphism `φ : G →* H` and a `G`-representation `A`, this is
`(k[H] ⊗[k] A)_G` equipped with the `H`-representation defined by sending `h : H` and `⟦h₁ ⊗ₜ a⟧`
to `⟦h₁h⁻¹ ⊗ₜ a⟧`. -/
@[simps]
noncomputable def ind : Representation k H (IndV φ ρ) where
toFun h := Coinvariants.map _ _ ((lmapDomain k k fun x => x * h⁻¹).rTensor _)
fun _ => by ext; simp [mul_assoc]
map_one' := by ext; simp
map_mul' _ _ := by ext; simp [IndV, mul_assoc]
lemma ind_mk (h₁ h₂ : H) (a : A) :
ind φ ρ h₁ (IndV.mk _ _ h₂ a) = IndV.mk _ _ (h₂ * h₁⁻¹) a := by
simp
end Representation
namespace Rep
open CategoryTheory Finsupp
variable {k G H : Type u} [CommRing k] [Group G] [Group H] (φ : G →* H) (A : Rep k G)
section Ind
/-- Given a group homomorphism `φ : G →* H` and a `G`-representation `A`, this is
`(k[H] ⊗[k] A)_G` equipped with the `H`-representation defined by sending `h : H` and `⟦h₁ ⊗ₜ a⟧`
to `⟦h₁h⁻¹ ⊗ₜ a⟧`. -/
noncomputable abbrev ind : Rep k H := Rep.of (A.ρ.ind φ)
/-- Given a group homomorphism `φ : G →* H`, a morphism of `G`-representations `f : A ⟶ B` induces
a morphism of `H`-representations `(k[H] ⊗[k] A)_G ⟶ (k[H] ⊗[k] B)_G`. -/
@[simps]
noncomputable def indMap {A B : Rep k G} (f : A ⟶ B) : ind φ A ⟶ ind φ B where
hom := ModuleCat.ofHom <| Representation.Coinvariants.map _ _
(LinearMap.lTensor (H →₀ k) f.hom.hom) fun g => by ext; simp [hom_comm_apply]
comm _ := by
ext
simp [ModuleCat.endRingEquiv]
variable (k) in
/-- Given a group homomorphism `φ : G →* H`, this is the functor sending a `G`-representation `A`
to the induced `H`-representation `ind φ A`, with action on maps induced by left tensoring. -/
@[simps obj map]
noncomputable def indFunctor : Rep k G ⥤ Rep k H where
obj A := ind φ A
map f := indMap φ f
map_id _ := by ext; rfl
map_comp _ _ := by ext; rfl
end Ind
section Adjunction
open Representation
variable (B : Rep k H)
/-- Given a group homomorphism `φ : G →* H`, an `H`-representation `B`, and a `G`-representation
`A`, there is a `k`-linear equivalence between the `H`-representation morphisms `ind φ A ⟶ B` and
the `G`-representation morphisms `A ⟶ B`. -/
@[simps]
noncomputable def indResHomEquiv :
(ind φ A ⟶ B) ≃ₗ[k] (A ⟶ (Action.res _ φ).obj B) where
toFun f := {
hom := ModuleCat.ofHom (f.hom.hom ∘ₗ IndV.mk φ A.ρ 1)
comm g := by
ext x
have := (hom_comm_apply f (φ g) (IndV.mk φ A.ρ 1 x)).symm
simp_all [← Coinvariants.mk_inv_tmul] }
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f := {
hom := ModuleCat.ofHom <| Representation.Coinvariants.lift _ (TensorProduct.lift <|
lift _ _ _ fun h => B.ρ h⁻¹ ∘ₗ f.hom.hom) fun _ => by ext; have := hom_comm_apply f; simp_all
comm _ := by ext; simp [ModuleCat.endRingEquiv] }
left_inv f := by
ext h a
simpa using (hom_comm_apply f h⁻¹ (IndV.mk φ A.ρ 1 a)).symm
right_inv _ := by ext; simp
variable (k) in
/-- Given a group homomorphism `φ : G →* H`, the induction functor `Rep k G ⥤ Rep k H` is left
adjoint to the restriction functor along `φ`. -/
@[simps! unit_app_hom_hom counit_app_hom_hom]
noncomputable def indResAdjunction : indFunctor k φ ⊣ Action.res _ φ :=
Adjunction.mkOfHomEquiv {
homEquiv A B := (indResHomEquiv φ A B).toEquiv
homEquiv_naturality_left_symm _ _ :=
Action.hom_ext _ _ <| ModuleCat.hom_ext <| IndV.hom_ext _ _ fun _ => by ext; simp
homEquiv_naturality_right := by intros; rfl }
open Finsupp
noncomputable instance : (indFunctor k φ).IsLeftAdjoint :=
(indResAdjunction k φ).isLeftAdjoint
noncomputable instance : (Action.res (ModuleCat.{u} k) φ).IsRightAdjoint :=
(indResAdjunction k φ).isRightAdjoint
end Adjunction
section
variable (B : Rep k H)
open ModuleCat.MonoidalCategory Representation
/-- Given a group hom `φ : G →* H`, `A : Rep k G` and `B : Rep k H`, this is the `k`-linear map
`(Ind(φ)(A) ⊗ B))_H ⟶ (A ⊗ Res(φ)(B))_G` sending `⟦h ⊗ₜ a⟧ ⊗ₜ b` to `⟦a ⊗ ρ(h)(b)⟧` for all
`h : H`, `a : A`, and `b : B`. -/
noncomputable def coinvariantsTensorIndHom :
((coinvariantsTensor k H).obj (ind φ A)).obj B ⟶
((coinvariantsTensor k G).obj A).obj ((Action.res _ φ).obj B) :=
ModuleCat.ofHom <| Coinvariants.lift _ (TensorProduct.lift <|
Coinvariants.lift _ (TensorProduct.lift <| Finsupp.lift _ _ _
fun g => ((coinvariantsTensorMk A ((Action.res _ φ).obj B)).compl₂ (B.ρ g)))
fun s => by ext; simpa [coinvariantsTensorMk, Coinvariants.mk_eq_iff]
using Coinvariants.sub_mem_ker s _)
fun _ => by
simp only [MonoidalCategory.curriedTensor_obj_obj, Action.tensorObj_V, tensorObj_carrier]
ext
simp
variable {A B} in
lemma coinvariantsTensorIndHom_mk_tmul_indVMk (h : H) (x : A) (y : B) :
coinvariantsTensorIndHom φ A B (coinvariantsTensorMk _ _ (IndV.mk φ _ h x) y) =
coinvariantsTensorMk _ _ x (B.ρ h y) := by
simp [tensorObj_carrier, coinvariantsTensorIndHom, coinvariantsTensorMk]
/-- Given a group hom `φ : G →* H`, `A : Rep k G` and `B : Rep k H`, this is the `k`-linear map
`(A ⊗ Res(φ)(B))_G ⟶ (Ind(φ)(A) ⊗ B))_H` sending `⟦a ⊗ₜ b⟧` to `⟦1 ⊗ₜ a⟧ ⊗ₜ b` for all
`a : A`, and `b : B`. -/
noncomputable def coinvariantsTensorIndInv :
((coinvariantsTensor k G).obj A).obj ((Action.res _ φ).obj B) ⟶
((coinvariantsTensor k H).obj (ind φ A)).obj B :=
ModuleCat.ofHom <| Coinvariants.lift _ (TensorProduct.lift <|
(coinvariantsTensorMk (ind φ A) B) ∘ₗ IndV.mk _ _ 1)
fun s => by
simp only [MonoidalCategory.curriedTensor_obj_obj, tensorObj_carrier, Action.tensorObj_V]
ext x y
simpa [Coinvariants.mk_eq_iff, coinvariantsTensorMk] using
Coinvariants.mem_ker_of_eq (φ s) (IndV.mk φ A.ρ (1 : H) x ⊗ₜ[k] y) _
(by simp [← Coinvariants.mk_inv_tmul])
variable {A B} in
lemma coinvariantsTensorIndInv_mk_tmul_indMk (x : A) (y : B) :
coinvariantsTensorIndInv φ A B (Coinvariants.mk
(A.ρ.tprod (Rep.ρ ((Action.res _ φ).obj B))) <| x ⊗ₜ y) =
coinvariantsTensorMk _ _ (IndV.mk φ _ 1 x) y := by
simp [tensorObj_carrier, coinvariantsTensorIndInv, coinvariantsTensorMk]
/-- Given a group hom `φ : G →* H`, `A : Rep k G` and `B : Rep k H`, this is the `k`-linear
isomorphism `(Ind(φ)(A) ⊗ B))_H ⟶ (A ⊗ Res(φ)(B))_G` sending `⟦h ⊗ₜ a⟧ ⊗ₜ b` to `⟦a ⊗ ρ(h)(b)⟧`
for all `h : H`, `a : A`, and `b : B`. -/
@[simps]
noncomputable def coinvariantsTensorIndIso :
((coinvariantsTensor k H).obj (ind φ A)).obj B ≅
((coinvariantsTensor k G).obj A).obj ((Action.res _ φ).obj B) where
hom := coinvariantsTensorIndHom φ A B
inv := coinvariantsTensorIndInv φ A B
hom_inv_id := by
ext h a b
simpa [tensorObj_carrier, coinvariantsTensorIndInv, coinvariantsTensorMk,
coinvariantsTensorIndHom, Coinvariants.mk_eq_iff] using
Coinvariants.mem_ker_of_eq h (IndV.mk φ _ h a ⊗ₜ[k] b) _ <| by simp
inv_hom_id := by
ext
simp [tensorObj_carrier, coinvariantsTensorIndInv, coinvariantsTensorMk,
coinvariantsTensorIndHom]
/-- Given a group hom `φ : G →* H` and `A : Rep k G`, the functor `Rep k H ⥤ ModuleCat k` sending
`B ↦ (Ind(φ)(A) ⊗ B))_H` is naturally isomorphic to the one sending `B ↦ (A ⊗ Res(φ)(B))_G`. -/
@[simps! hom_app inv_app]
noncomputable def coinvariantsTensorIndNatIso :
(coinvariantsTensor k H).obj (ind φ A) ≅ Action.res _ φ ⋙ (coinvariantsTensor k G).obj A :=
NatIso.ofComponents (fun B => coinvariantsTensorIndIso φ A B) fun {X Y} f => by
ext
simp [tensorObj_carrier, coinvariantsTensorIndHom, coinvariantsTensorMk,
whiskerLeft_def, hom_comm_apply]
end
end Rep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/GroupCohomology/Functoriality.lean | import Mathlib.RepresentationTheory.Homological.GroupCohomology.Functoriality
deprecated_module (since := "2025-06-14") |
.lake/packages/mathlib/Mathlib/RepresentationTheory/GroupCohomology/Basic.lean | import Mathlib.RepresentationTheory.Homological.GroupCohomology.Basic
deprecated_module (since := "2025-06-14") |
.lake/packages/mathlib/Mathlib/RepresentationTheory/GroupCohomology/Hilbert90.lean | import Mathlib.RepresentationTheory.Homological.GroupCohomology.Hilbert90
deprecated_module (since := "2025-06-14") |
.lake/packages/mathlib/Mathlib/RepresentationTheory/GroupCohomology/Resolution.lean | import Mathlib.RepresentationTheory.Homological.Resolution
deprecated_module (since := "2025-06-14") |
.lake/packages/mathlib/Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean | import Mathlib.RepresentationTheory.Homological.GroupCohomology.LowDegree
deprecated_module (since := "2025-06-14") |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/FiniteCyclic.lean | import Mathlib.Algebra.Homology.AlternatingConst
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
import Mathlib.CategoryTheory.Preadditive.Projective.Resolution
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.RepresentationTheory.Coinvariants
/-!
# Projective resolution of `k` as a trivial `k`-linear representation of a finite cyclic group
Let `k` be a commutative ring and `G` a finite commutative group. Given `g : G` and `A : Rep k G`,
we can define a periodic chain complex in `Rep k G` given by
`... ⟶ A --N--> A --(ρ(g) - 𝟙)--> A --N--> A --(ρ(g) - 𝟙)--> A ⟶ 0`
where `N` is the norm map sending `a : A` to `∑ ρ(g)(a)` for all `g` in `G`.
When `G` is generated by `g` and `A` is the left regular representation `k[G]`, this chain complex
is a projective resolution of `k` as a trivial representation, which we prove here.
In the file `Mathlib/RepresentationTheory/Homological/GroupHomology/FiniteCyclic.lean`, we use
this resolution to compute the group homology of representations of finite cyclic groups.
## Main definitions
* `Rep.FiniteCyclicGroup.resolution k g hg`: given a finite cyclic group `G` generated by `g : G`,
this is the projective resolution of `k` as a trivial `k`-linear `G`-representation given by
periodic complex
`... ⟶ k[G] --N--> k[G] --(ρ(g) - 𝟙)--> k[G] --N--> k[G] --(ρ(g) - 𝟙)--> k[G] ⟶ 0` where `ρ` is
the left regular representation and `N` is the norm map.
## TODO
* Use this to analyse the group cohomology of representations of finite cyclic groups.
-/
universe v u
open CategoryTheory Finsupp
namespace Representation.FiniteCyclicGroup
variable {k G V : Type*} [CommRing k] [Group G] [Fintype G] {V : Type*} [AddCommGroup V]
[Module k V] (ρ : Representation k G V) (g : G)
lemma coinvariantsKer_eq_range (hg : ∀ x, x ∈ Subgroup.zpowers g) :
Coinvariants.ker ρ = LinearMap.range (ρ g - LinearMap.id) := by
refine le_antisymm (Submodule.span_le.2 ?_) ?_
· rintro a ⟨⟨γ, α⟩, rfl⟩
rcases mem_powers_iff_mem_zpowers.2 (hg γ) with ⟨i, rfl⟩
induction i with | zero => exact ⟨0, by simp⟩ | succ n _ =>
use (Fin.partialSum (fun (j : Fin (n + 1)) => ρ (g ^ (j : ℕ)) α) (Fin.last _))
simpa using ρ.apply_sub_id_partialSum_eq _ _ _
· rintro x ⟨y, rfl⟩
simpa using Coinvariants.sub_mem_ker g y
/-- Given a finite cyclic group `G` generated by `g` and a `G` representation `(V, ρ)`, `V_G` is
isomorphic to `V ⧸ Im(ρ(g - 1))`. -/
noncomputable def coinvariantsEquiv (hg : ∀ x, x ∈ Subgroup.zpowers g) :
ρ.Coinvariants ≃ₗ[k] (_ ⧸ LinearMap.range (ρ g - LinearMap.id)) :=
Submodule.quotEquivOfEq _ _ (coinvariantsKer_eq_range ρ g hg)
lemma coinvariantsKer_leftRegular_eq_ker :
Coinvariants.ker (Representation.leftRegular k G) =
LinearMap.ker (linearCombination k (fun _ => (1 : k))) := by
refine le_antisymm (Submodule.span_le.2 ?_) fun x hx => ?_
· rintro x ⟨⟨g, y⟩, rfl⟩
simpa [linearCombination, sub_eq_zero, sum_fintype]
using Finset.sum_bijective _ (Group.mulLeft_bijective g⁻¹) (by aesop) (by aesop)
· have : x = x.sum (fun g r => single g r - single 1 r) := by
ext g
by_cases hg : g = 1
· simp_all [linearCombination, sum_apply']
· simp_all [sum_apply']
rw [this]
exact Submodule.finsuppSum_mem _ _ _ _ fun g _ =>
Coinvariants.mem_ker_of_eq g (single 1 (x g)) _ (by simp)
end Representation.FiniteCyclicGroup
namespace Rep.FiniteCyclicGroup
variable (k : Type u) {G : Type u} [CommRing k] [CommGroup G] [Fintype G] (A : Rep k G) (g : G)
namespace leftRegular
open Finsupp IsCyclic Representation
lemma range_norm_eq_ker_applyAsHom_sub (hg : ∀ x, x ∈ Subgroup.zpowers g) :
LinearMap.range (leftRegular k G).norm.hom.hom =
LinearMap.ker (applyAsHom (leftRegular k G) g - 𝟙 _).hom.hom :=
le_antisymm (fun _ ⟨_, h⟩ => by simp_all [← h]) fun x hx => ⟨single 1 (x g), by
ext j; simpa [Representation.norm] using (apply_eq_of_leftRegular_eq_of_generator g hg _
(by simpa [sub_eq_zero] using hx) j).symm⟩
lemma range_applyAsHom_sub_eq_ker_linearCombination (hg : ∀ x, x ∈ Subgroup.zpowers g) :
LinearMap.range (applyAsHom (leftRegular k G) g - 𝟙 _).hom.hom =
LinearMap.ker (linearCombination k (fun _ => (1 : k))) := by
simp [← FiniteCyclicGroup.coinvariantsKer_eq_range _ _ hg,
← FiniteCyclicGroup.coinvariantsKer_leftRegular_eq_ker]
lemma range_applyAsHom_sub_eq_ker_norm (hg : ∀ x, x ∈ Subgroup.zpowers g) :
LinearMap.range (applyAsHom (leftRegular k G) g - 𝟙 _).hom.hom =
LinearMap.ker (leftRegular k G).norm.hom.hom := by
simp [ker_leftRegular_norm_eq, ← range_applyAsHom_sub_eq_ker_linearCombination k g hg]
end leftRegular
/-- Given a finite group `G` and `g : G`, this is the functor `Rep k G ⥤ ChainComplex (Rep k G) ℕ`
sending `A : Rep k G` to the periodic chain complex in `Rep k G` given by
`... ⟶ A --N--> A --(ρ(g) - 𝟙)--> A --N--> A --(ρ(g) - 𝟙)--> A ⟶ 0`
where `N` is the norm map. When `G` is generated by `g` and `A` is the left regular representation
`k[G]`, it is a projective resolution of `k` as a trivial representation.
It sends a morphism `f : A ⟶ B` to the chain morphism defined by `f` in every degree. -/
@[simps]
noncomputable def chainComplexFunctor : Rep k G ⥤ ChainComplex (Rep k G) ℕ where
obj A := HomologicalComplex.alternatingConst A (φ := A.norm) (ψ := applyAsHom A g - 𝟙 A)
(by ext; simp) (by ext; simp) fun _ _ => ComplexShape.down_nat_odd_add
map f := {
f i := f
comm' := by
rintro i j ⟨rfl⟩
by_cases hj : Even (j + 1)
· simp [if_pos hj, norm_comm]
· simp [if_neg hj, applyAsHom_comm] }
map_id _ := rfl
map_comp _ _ := rfl
variable {k}
/-- Given a finite cyclic group `G` generated by `g : G` and a `k`-linear `G`-representation `A`,
this is the short complex in `ModuleCat k` given by `A --N--> A --(ρ(g) - 𝟙)--> A`
where `N` is the norm map. Its homology is `Hⁱ(G, A)` for even `i` and `Hᵢ(G, A)` for odd `i`. -/
noncomputable abbrev normHomCompSub : ShortComplex (ModuleCat k) :=
ShortComplex.mk A.norm.hom (applyAsHom A g - 𝟙 A).hom (by ext; simp)
/-- Given a finite cyclic group `G` generated by `g : G` and a `k`-linear `G`-representation `A`,
this is the short complex in `ModuleCat k` given by `A --N--> A --(ρ(g) - 𝟙)--> A`
where `N` is the norm map. Its homology is `Hⁱ(G, A)` for even `i` and `Hᵢ(G, A)` for odd `i`. -/
noncomputable abbrev subCompNormHom : ShortComplex (ModuleCat k) :=
ShortComplex.mk (applyAsHom A g - 𝟙 A).hom A.norm.hom (by ext; simp)
/-- Given a finite cyclic group `G` generated by `g : G` and a `k`-linear `G`-representation `A`,
this is the periodic chain complex in `ModuleCat k` given by
`... ⟶ A --N--> A --(ρ(g) - 𝟙)--> A --N--> A --(ρ(g) - 𝟙)--> A ⟶ 0` where `N` is the norm map.
Its homology is the group homology of `A`. -/
noncomputable abbrev moduleCatChainComplex : ChainComplex (ModuleCat k) ℕ :=
HomologicalComplex.alternatingConst A.V (φ := A.norm.hom) (ψ := (applyAsHom A g - 𝟙 A).hom)
(by ext; simp) (by ext; simp) fun _ _ => ComplexShape.down_nat_odd_add
/-- Given a finite cyclic group `G` generated by `g : G` and a `k`-linear `G`-representation `A`,
this is the periodic chain complex in `Rep k G` given by
`0 ⟶ A --(ρ(g) - 𝟙)--> A --N--> A --(ρ(g) - 𝟙)--> A --N--> A ⟶ ...` where `N` is the norm map.
Its cohomology is the group cohomology of `A`. -/
noncomputable abbrev moduleCatCochainComplex : CochainComplex (ModuleCat k) ℕ :=
HomologicalComplex.alternatingConst A.V (φ := (applyAsHom A g - 𝟙 A).hom) (ψ := A.norm.hom)
(by ext; simp) (by ext; simp) fun _ _ => ComplexShape.up_nat_odd_add
variable (k)
/-- Given a finite cyclic group `G` generated by `g : G`, let `P` denote the periodic chain complex
of `k`-linear `G`-representations given by
`... ⟶ k[G] --N--> k[G] --(ρ(g) - 𝟙)--> k[G] --N--> k[G] --(ρ(g) - 𝟙)--> k[G] ⟶ 0` where `ρ` is
the left regular representation and `N` is the norm map. This is the chain morphism from `P` to
the chain complex concentrated at 0 by the trivial representation `k` used to show `P` is a
projective resolution of `k`. It sends `x : k[G]` to the sum of its coefficients. -/
@[simps!]
noncomputable def resolution.π (g : G) :
(chainComplexFunctor k g).obj (leftRegular k G) ⟶
(ChainComplex.single₀ (Rep k G)).obj (trivial k G k) :=
(((chainComplexFunctor k g).obj (leftRegular k G)).toSingle₀Equiv _).symm
⟨leftRegularHom _ 1, (leftRegularHomEquiv _).injective <| by simp [leftRegularHomEquiv]⟩
lemma resolution_quasiIso (g : G) (hg : ∀ x, x ∈ Subgroup.zpowers g) :
QuasiIso (resolution.π k g) where
quasiIsoAt m := by
induction m with
| zero =>
simp only [resolution.π]
rw [ChainComplex.quasiIsoAt₀_iff, ShortComplex.quasiIso_iff_of_zeros' _ rfl rfl rfl]
constructor
· apply (Action.forget (ModuleCat k) _).reflects_exact_of_faithful
simpa [ShortComplex.moduleCat_exact_iff_range_eq_ker,
HomologicalComplex.alternatingConst, ChainComplex.toSingle₀Equiv] using
leftRegular.range_applyAsHom_sub_eq_ker_linearCombination k g hg
· rw [Rep.epi_iff_surjective]
intro x
use single 1 x
simp [ChainComplex.toSingle₀Equiv]
| succ m _ =>
rw [quasiIsoAt_iff_exactAt' (hL := ChainComplex.exactAt_succ_single_obj ..),
HomologicalComplex.exactAt_iff' _ (m + 2) (m + 1) m (by simp) (by simp)]
apply (Action.forget (ModuleCat k) _).reflects_exact_of_faithful
rw [ShortComplex.moduleCat_exact_iff_range_eq_ker]
by_cases hm : Odd (m + 1)
· simpa [if_pos (Nat.even_add_one.2 (Nat.not_even_iff_odd.2 hm)),
if_neg (Nat.not_even_iff_odd.2 hm)]
using leftRegular.range_norm_eq_ker_applyAsHom_sub k g hg
· simpa [ShortComplex.moduleCat_exact_iff_range_eq_ker, if_pos (Nat.not_odd_iff_even.1 hm),
if_neg (Nat.not_even_iff_odd.2 <| Nat.odd_add_one.2 hm)]
using leftRegular.range_applyAsHom_sub_eq_ker_norm k g hg
/-- Given a finite cyclic group `G` generated by `g : G`, this is the projective resolution of `k`
as a trivial `k`-linear `G`-representation given by periodic complex
`... ⟶ k[G] --N--> k[G] --(ρ(g) - 𝟙)--> k[G] --N--> k[G] --(ρ(g) - 𝟙)--> k[G] ⟶ 0` where `ρ` is
the left regular representation and `N` is the norm map. -/
@[simps]
noncomputable def resolution (g : G) (hg : ∀ x, x ∈ Subgroup.zpowers g) :
ProjectiveResolution (trivial k G k) where
complex := (FiniteCyclicGroup.chainComplexFunctor k g).obj (leftRegular k G)
projective _ := inferInstanceAs <| Projective (leftRegular k G)
π := FiniteCyclicGroup.resolution.π k g
quasiIso := resolution_quasiIso k g hg
end Rep.FiniteCyclicGroup |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/Resolution.lean | import Mathlib.Algebra.Category.ModuleCat.Projective
import Mathlib.AlgebraicTopology.ExtraDegeneracy
import Mathlib.CategoryTheory.Abelian.Ext
import Mathlib.RepresentationTheory.Rep
import Mathlib.CategoryTheory.Functor.ReflectsIso.Balanced
/-!
# The standard and bar resolutions of `k` as a trivial `k`-linear `G`-representation
Given a commutative ring `k` and a group `G`, this file defines two projective resolutions of `k`
as a trivial `k`-linear `G`-representation.
The first one, the standard resolution, has objects `k[Gⁿ⁺¹]` equipped with the diagonal
representation, and differential defined by `(g₀, ..., gₙ) ↦ ∑ (-1)ⁱ • (g₀, ..., ĝᵢ, ..., gₙ)`.
We define this as the alternating face map complex associated to an appropriate simplicial
`k`-linear `G`-representation. This simplicial object is the `linearization` of the simplicial
`G`-set given by the universal cover of the classifying space of `G`, `EG`. We prove this
simplicial `G`-set `EG` is isomorphic to the Čech nerve of the natural arrow of `G`-sets
`G ⟶ {pt}`.
We then use this isomorphism to deduce that as a complex of `k`-modules, the standard resolution
of `k` as a trivial `G`-representation is homotopy equivalent to the complex with `k` at 0 and 0
elsewhere.
Putting this material together allows us to define `Rep.standardResolution`, the
standard projective resolution of `k` as a trivial `k`-linear `G`-representation.
We then construct the bar resolution. The `n`th object in this complex is the representation on
`Gⁿ →₀ k[G]` defined pointwise by the left regular representation on `k[G]`. The differentials are
defined by sending `(g₀, ..., gₙ)` to
`g₀·(g₁, ..., gₙ) + ∑ (-1)ʲ⁺¹·(g₀, ..., gⱼgⱼ₊₁, ..., gₙ) + (-1)ⁿ⁺¹·(g₀, ..., gₙ₋₁)` for
`j = 0, ..., n - 1`.
In `RepresentationTheory.Rep` we define an isomorphism `Rep.diagonalSuccIsoFree` between
`k[Gⁿ⁺¹] ≅ (Gⁿ →₀ k[G])` sending `(g₀, ..., gₙ) ↦ g₀·(g₀⁻¹g₁, ..., gₙ₋₁⁻¹gₙ)`.
We show that this isomorphism defines a commutative square with the bar resolution differential and
the standard resolution differential, and thus conclude that the bar resolution differential
squares to zero and that `Rep.diagonalSuccIsoFree` defines an isomorphism between the two
complexes. We carry the exactness properties across this isomorphism to conclude the bar resolution
is a projective resolution too, in `Rep.barResolution`.
In `RepresentationTheory/Homological/Group(Co)homology/Basic.lean`, we then use
`Rep.barResolution` to define the inhomogeneous (co)chains of a representation, useful for
computing group (co)homology.
## Main definitions
* `groupCohomology.resolution.ofMulActionBasis`
* `classifyingSpaceUniversalCover`
* `Rep.standardComplex.forget₂ToModuleCatHomotopyEquiv`
* `Rep.standardResolution`
-/
suppress_compilation
noncomputable section
universe u v w
variable {k G : Type u} [CommRing k] {n : ℕ}
open CategoryTheory Finsupp
local notation "Gⁿ" => Fin n → G
set_option quotPrecheck false
local notation "Gⁿ⁺¹" => Fin (n + 1) → G
namespace groupCohomology.resolution
open Finsupp hiding lift
open MonoidalCategory
open Fin (partialProd)
section Basis
variable (k G n) [Group G]
open scoped TensorProduct
open Representation
@[deprecated (since := "2025-06-02")]
alias groupCohomology.resolution.actionDiagonalSucc := Action.diagonalSuccIsoTensorTrivial
@[deprecated (since := "2025-06-02")]
alias groupCohomology.resolution.actionDiagonalSucc_hom_apply :=
Action.diagonalSuccIsoTensorTrivial_hom_hom_apply
@[deprecated (since := "2025-06-02")]
alias groupCohomology.resolution.actionDiagonalSucc_inv_apply :=
Action.diagonalSuccIsoTensorTrivial_inv_hom_apply
@[deprecated (since := "2025-06-02")]
alias groupCohomology.resolution.diagonalSucc := Rep.diagonalSuccIsoTensorTrivial
@[deprecated (since := "2025-06-02")]
alias groupCohomology.resolution.diagonalSucc_hom_single :=
Rep.diagonalSuccIsoTensorTrivial_hom_hom_single
@[deprecated (since := "2025-06-02")]
alias groupCohomology.resolution.diagonalSucc_inv_single_single :=
Rep.diagonalSuccIsoTensorTrivial_inv_hom_single_single
@[deprecated (since := "2025-06-02")]
alias groupCohomology.resolution.diagonalSucc_inv_single_left :=
Rep.diagonalSuccIsoTensorTrivial_inv_hom_single_left
@[deprecated (since := "2025-06-02")]
alias groupCohomology.resolution.diagonalSucc_inv_single_right :=
Rep.diagonalSuccIsoTensorTrivial_inv_hom_single_right
/-- The `k[G]`-linear isomorphism `k[G] ⊗ₖ k[Gⁿ] ≃ k[Gⁿ⁺¹]`, where the `k[G]`-module structure on
the left-hand side is `TensorProduct.leftModule`, whilst that of the right-hand side comes from
`Representation.asModule`. Allows us to use `Algebra.TensorProduct.basis` to get a `k[G]`-basis
of the right-hand side. -/
@[deprecated "We now favour `Representation.finsuppLEquivFreeAsModule`" (since := "2025-06-04")]
def ofMulActionBasisAux :
MonoidAlgebra k G ⊗[k] ((Fin n → G) →₀ k) ≃ₗ[MonoidAlgebra k G]
(ofMulAction k G (Fin (n + 1) → G)).asModule :=
haveI e := (Rep.equivalenceModuleMonoidAlgebra.1.mapIso
(Rep.diagonalSuccIsoTensorTrivial k G n).symm).toLinearEquiv
{ e with
map_smul' := fun r x => by
rw [RingHom.id_apply, LinearEquiv.toFun_eq_coe, ← LinearEquiv.map_smul e]
congr 1
refine x.induction_on ?_ (fun x y => ?_) fun y z hy hz => ?_
· simp only [smul_zero]
· rw [TensorProduct.smul_tmul', smul_eq_mul, ← ofMulAction_self_smul_eq_mul]
exact (smul_tprod_one_asModule (Representation.ofMulAction k G G) r x y).symm
· rw [smul_add, hz, hy, smul_add] }
/-- A `k[G]`-basis of `k[Gⁿ⁺¹]`, coming from the `k[G]`-linear isomorphism
`k[G] ⊗ₖ k[Gⁿ] ≃ k[Gⁿ⁺¹].` -/
@[deprecated "We now favour `Representation.freeAsModuleBasis`; the old definition can be derived
from this and `Rep.diagonalSuccIsoFree" (since := "2025-06-05")]
alias ofMulActionBasis := Representation.freeAsModuleBasis
@[deprecated "We now favour `Representation.free_asModule_free`; the old theorem can be derived
from this and `Rep.diagonalSuccIsoFree" (since := "2025-06-05")]
alias ofMulAction_free := Representation.free_asModule_free
end Basis
end groupCohomology.resolution
variable (G)
/-- The simplicial `G`-set sending `[n]` to `Gⁿ⁺¹` equipped with the diagonal action of `G`. -/
@[simps obj map]
def classifyingSpaceUniversalCover [Monoid G] :
SimplicialObject (Action (Type u) G) where
obj n := Action.ofMulAction G (Fin (n.unop.len + 1) → G)
map f :=
{ hom := fun x => x ∘ f.unop.toOrderHom
comm := fun _ => rfl }
map_id _ := rfl
map_comp _ _ := rfl
namespace classifyingSpaceUniversalCover
open CategoryTheory.Limits
variable [Monoid G]
/-- When the category is `G`-Set, `cechNerveTerminalFrom` of `G` with the left regular action is
isomorphic to `EG`, the universal cover of the classifying space of `G` as a simplicial `G`-set. -/
def cechNerveTerminalFromIso :
cechNerveTerminalFrom (Action.ofMulAction G G) ≅ classifyingSpaceUniversalCover G :=
NatIso.ofComponents (fun _ => limit.isoLimitCone (Action.ofMulActionLimitCone _ _)) fun f => by
refine IsLimit.hom_ext (Action.ofMulActionLimitCone.{u, 0} G fun _ => G).2 fun j => ?_
dsimp only [cechNerveTerminalFrom, Pi.lift]
rw [Category.assoc, limit.isoLimitCone_hom_π, limit.lift_π, Category.assoc]
exact (limit.isoLimitCone_hom_π _ _).symm
/-- As a simplicial set, `cechNerveTerminalFrom` of a monoid `G` is isomorphic to the universal
cover of the classifying space of `G` as a simplicial set. -/
def cechNerveTerminalFromIsoCompForget :
cechNerveTerminalFrom G ≅ classifyingSpaceUniversalCover G ⋙ forget _ :=
NatIso.ofComponents (fun _ => Types.productIso _) fun _ =>
Matrix.ext fun _ _ => Types.Limit.lift_π_apply (Discrete.functor fun _ ↦ G) _ _ _
variable (k)
open AlgebraicTopology SimplicialObject.Augmented SimplicialObject CategoryTheory.Arrow
/-- The universal cover of the classifying space of `G` as a simplicial set, augmented by the map
from `Fin 1 → G` to the terminal object in `Type u`. -/
def compForgetAugmented : SimplicialObject.Augmented (Type u) :=
SimplicialObject.augment (classifyingSpaceUniversalCover G ⋙ forget _) (terminal _)
(terminal.from _) fun _ _ _ => Subsingleton.elim _ _
/-- The augmented Čech nerve of the map from `Fin 1 → G` to the terminal object in `Type u` has an
extra degeneracy. -/
def extraDegeneracyAugmentedCechNerve :
ExtraDegeneracy (Arrow.mk <| terminal.from G).augmentedCechNerve :=
AugmentedCechNerve.extraDegeneracy (Arrow.mk <| terminal.from G)
⟨fun _ => (1 : G),
@Subsingleton.elim _ (@Unique.instSubsingleton _ (Limits.uniqueToTerminal _)) _ _⟩
/-- The universal cover of the classifying space of `G` as a simplicial set, augmented by the map
from `Fin 1 → G` to the terminal object in `Type u`, has an extra degeneracy. -/
def extraDegeneracyCompForgetAugmented : ExtraDegeneracy (compForgetAugmented G) := by
refine
ExtraDegeneracy.ofIso (?_ : (Arrow.mk <| terminal.from G).augmentedCechNerve ≅ _)
(extraDegeneracyAugmentedCechNerve G)
exact
Comma.isoMk (CechNerveTerminalFrom.iso G ≪≫ cechNerveTerminalFromIsoCompForget G)
(Iso.refl _) (by ext : 1; exact IsTerminal.hom_ext terminalIsTerminal _ _)
/-- The free functor `Type u ⥤ ModuleCat.{u} k` applied to the universal cover of the classifying
space of `G` as a simplicial set, augmented by the map from `Fin 1 → G` to the terminal object
in `Type u`. -/
def compForgetAugmented.toModule : SimplicialObject.Augmented (ModuleCat.{u} k) :=
((SimplicialObject.Augmented.whiskering _ _).obj (ModuleCat.free k)).obj (compForgetAugmented G)
/-- If we augment the universal cover of the classifying space of `G` as a simplicial set by the
map from `Fin 1 → G` to the terminal object in `Type u`, then apply the free functor
`Type u ⥤ ModuleCat.{u} k`, the resulting augmented simplicial `k`-module has an extra
degeneracy. -/
def extraDegeneracyCompForgetAugmentedToModule :
ExtraDegeneracy (compForgetAugmented.toModule k G) :=
ExtraDegeneracy.map (extraDegeneracyCompForgetAugmented G) (ModuleCat.free k)
end classifyingSpaceUniversalCover
variable (k)
/-- The standard resolution of `k` as a trivial representation, defined as the alternating
face map complex of a simplicial `k`-linear `G`-representation. -/
def Rep.standardComplex [Monoid G] :=
(AlgebraicTopology.alternatingFaceMapComplex (Rep k G)).obj
(classifyingSpaceUniversalCover G ⋙ linearization k G)
@[deprecated (since := "2025-06-06")]
alias groupCohomology.resolution := Rep.standardComplex
namespace Rep.standardComplex
open classifyingSpaceUniversalCover AlgebraicTopology CategoryTheory.Limits
variable [Monoid G]
/-- The `k`-linear map underlying the differential in the standard resolution of `k` as a trivial
`k`-linear `G`-representation. It sends `(g₀, ..., gₙ) ↦ ∑ (-1)ⁱ • (g₀, ..., ĝᵢ, ..., gₙ)`. -/
def d (G : Type u) (n : ℕ) : ((Fin (n + 1) → G) →₀ k) →ₗ[k] (Fin n → G) →₀ k :=
Finsupp.lift ((Fin n → G) →₀ k) k (Fin (n + 1) → G) fun g =>
(@Finset.univ (Fin (n + 1)) _).sum fun p =>
Finsupp.single (g ∘ p.succAbove) ((-1 : k) ^ (p : ℕ))
variable {k G}
@[simp]
theorem d_of {G : Type u} {n : ℕ} (c : Fin (n + 1) → G) :
d k G n (Finsupp.single c 1) =
Finset.univ.sum fun p : Fin (n + 1) =>
Finsupp.single (c ∘ p.succAbove) ((-1 : k) ^ (p : ℕ)) := by
simp [d]
variable (k G)
/-- The `n`th object of the standard resolution of `k` is definitionally isomorphic to `k[Gⁿ⁺¹]`
equipped with the representation induced by the diagonal action of `G`. -/
def xIso (n : ℕ) : (standardComplex k G).X n ≅ Rep.ofMulAction k G (Fin (n + 1) → G) :=
Iso.refl _
instance x_projective (G : Type u) [Group G] (n : ℕ) :
Projective ((standardComplex k G).X n) := by
classical exact inferInstanceAs <| Projective (Rep.diagonal k G (n + 1))
/-- Simpler expression for the differential in the standard resolution of `k` as a
`G`-representation. It sends `(g₀, ..., gₙ₊₁) ↦ ∑ (-1)ⁱ • (g₀, ..., ĝᵢ, ..., gₙ₊₁)`. -/
theorem d_eq (n : ℕ) : ((standardComplex k G).d (n + 1) n).hom =
ModuleCat.ofHom (d k G (n + 1)) := by
refine ModuleCat.hom_ext <| Finsupp.lhom_ext' fun (x : Fin (n + 2) → G) => LinearMap.ext_ring ?_
simp [Action.ofMulAction_V, standardComplex, SimplicialObject.δ,
← Int.cast_smul_eq_zsmul k ((-1) ^ _ : ℤ), SimplexCategory.δ, Fin.succAboveOrderEmb]
section Exactness
/-- The standard resolution of `k` as a trivial representation as a complex of `k`-modules. -/
def forget₂ToModuleCat :=
((forget₂ (Rep k G) (ModuleCat.{u} k)).mapHomologicalComplex _).obj (standardComplex k G)
/-- If we apply the free functor `Type u ⥤ ModuleCat.{u} k` to the universal cover of the
classifying space of `G` as a simplicial set, then take the alternating face map complex, the result
is isomorphic to the standard resolution of the trivial `G`-representation `k` as a complex of
`k`-modules. -/
def compForgetAugmentedIso :
AlternatingFaceMapComplex.obj
(SimplicialObject.Augmented.drop.obj (compForgetAugmented.toModule k G)) ≅
standardComplex.forget₂ToModuleCat k G :=
eqToIso
(Functor.congr_obj (map_alternatingFaceMapComplex (forget₂ (Rep k G) (ModuleCat.{u} k))).symm
(classifyingSpaceUniversalCover G ⋙ linearization k G))
/-- As a complex of `k`-modules, the standard resolution of the trivial `G`-representation `k` is
homotopy equivalent to the complex which is `k` at 0 and 0 elsewhere. -/
def forget₂ToModuleCatHomotopyEquiv :
HomotopyEquiv (standardComplex.forget₂ToModuleCat k G)
((ChainComplex.single₀ (ModuleCat k)).obj ((forget₂ (Rep k G) _).obj <| Rep.trivial k G k)) :=
(HomotopyEquiv.ofIso (compForgetAugmentedIso k G).symm).trans <|
(SimplicialObject.Augmented.ExtraDegeneracy.homotopyEquiv
(extraDegeneracyCompForgetAugmentedToModule k G)).trans
(HomotopyEquiv.ofIso <|
(ChainComplex.single₀ (ModuleCat.{u} k)).mapIso
(@Finsupp.LinearEquiv.finsuppUnique k k _ _ _ (⊤_ Type u)
Types.terminalIso.toEquiv.unique).toModuleIso)
/-- The hom of `k`-linear `G`-representations `k[G¹] → k` sending `∑ nᵢgᵢ ↦ ∑ nᵢ`. -/
def ε : Rep.ofMulAction k G (Fin 1 → G) ⟶ Rep.trivial k G k where
hom := ModuleCat.ofHom <| Finsupp.linearCombination _ fun _ => (1 : k)
comm _ := ModuleCat.hom_ext <| Finsupp.lhom_ext' fun _ => LinearMap.ext_ring
(by simp [ModuleCat.endRingEquiv])
/-- The homotopy equivalence of complexes of `k`-modules between the standard resolution of `k` as
a trivial `G`-representation, and the complex which is `k` at 0 and 0 everywhere else, acts as
`∑ nᵢgᵢ ↦ ∑ nᵢ : k[G¹] → k` at 0. -/
theorem forget₂ToModuleCatHomotopyEquiv_f_0_eq :
(forget₂ToModuleCatHomotopyEquiv k G).1.f 0 = (forget₂ (Rep k G) _).map (ε k G) := by
refine ModuleCat.hom_ext <| Finsupp.lhom_ext fun (x : Fin 1 → G) r => ?_
change mapDomain _ _ _ = Finsupp.linearCombination _ _ _
simp only [HomotopyEquiv.ofIso, Iso.symm_hom, compForgetAugmented, compForgetAugmentedIso,
eqToIso.inv, HomologicalComplex.eqToHom_f]
change mapDomain _ (single x r) _ = _
simp [Unique.eq_default (terminal.from _), single_apply, if_pos (Subsingleton.elim _ _)]
theorem d_comp_ε : (standardComplex k G).d 1 0 ≫ ε k G = 0 := by
ext : 3
have : (forget₂ToModuleCat k G).d 1 0
≫ (forget₂ (Rep k G) (ModuleCat.{u} k)).map (ε k G) = 0 := by
rw [← forget₂ToModuleCatHomotopyEquiv_f_0_eq,
← (forget₂ToModuleCatHomotopyEquiv k G).1.2 1 0 rfl]
exact comp_zero
exact LinearMap.ext_iff.1 (ModuleCat.hom_ext_iff.mp this) _
/-- The chain map from the standard resolution of `k` to `k[0]` given by `∑ nᵢgᵢ ↦ ∑ nᵢ` in
degree zero. -/
def εToSingle₀ :
standardComplex k G ⟶ (ChainComplex.single₀ _).obj (Rep.trivial k G k) :=
((standardComplex k G).toSingle₀Equiv _).symm ⟨ε k G, d_comp_ε k G⟩
theorem εToSingle₀_comp_eq :
((forget₂ _ (ModuleCat.{u} k)).mapHomologicalComplex _).map (εToSingle₀ k G) ≫
(HomologicalComplex.singleMapHomologicalComplex _ _ _).hom.app _ =
(forget₂ToModuleCatHomotopyEquiv k G).hom := by
dsimp
ext1
simpa using (forget₂ToModuleCatHomotopyEquiv_f_0_eq k G).symm
theorem quasiIso_forget₂_εToSingle₀ :
QuasiIso (((forget₂ _ (ModuleCat.{u} k)).mapHomologicalComplex _).map (εToSingle₀ k G)) := by
have h : QuasiIso (forget₂ToModuleCatHomotopyEquiv k G).hom := inferInstance
rw [← εToSingle₀_comp_eq k G] at h
exact quasiIso_of_comp_right (hφφ' := h)
instance : QuasiIso (εToSingle₀ k G) := by
rw [← HomologicalComplex.quasiIso_map_iff_of_preservesHomology _ (forget₂ _ (ModuleCat.{u} k))]
apply quasiIso_forget₂_εToSingle₀
end Exactness
end standardComplex
open HomologicalComplex.Hom standardComplex
variable [Group G]
/-- The standard projective resolution of `k` as a trivial `k`-linear `G`-representation. -/
def standardResolution : ProjectiveResolution (Rep.trivial k G k) where
complex := standardComplex k G
π := εToSingle₀ k G
@[deprecated (since := "2025-06-06")]
alias groupCohomology.projectiveResolution := Rep.standardResolution
/-- Given a `k`-linear `G`-representation `V`, `Extⁿ(k, V)` (where `k` is a trivial `k`-linear
`G`-representation) is isomorphic to the `n`th cohomology group of `Hom(P, V)`, where `P` is the
standard resolution of `k` called `standardComplex k G`. -/
def standardResolution.extIso (V : Rep k G) (n : ℕ) :
((Ext k (Rep k G) n).obj (Opposite.op <| Rep.trivial k G k)).obj V ≅
((standardComplex k G).linearYonedaObj k V).homology n :=
(standardResolution k G).isoExt n V
@[deprecated (since := "2025-06-06")]
alias groupCohomology.extIso := Rep.standardResolution.extIso
namespace barComplex
open Rep Finsupp
variable [DecidableEq G]
variable (n)
/-- The differential from `Gⁿ⁺¹ →₀ k[G]` to `Gⁿ →₀ k[G]` in the bar resolution of `k` as a trivial
`k`-linear `G`-representation. It sends `(g₀, ..., gₙ)` to
`g₀·(g₁, ..., gₙ) + ∑ (-1)ʲ⁺¹·(g₀, ..., gⱼgⱼ₊₁, ..., gₙ) + (-1)ⁿ⁺¹·(g₀, ..., gₙ₋₁)` for
`j = 0, ..., n - 1`. -/
def d : free k G Gⁿ⁺¹ ⟶ free k G Gⁿ :=
freeLift _ fun g => single (fun i => g i.succ) (single (g 0) 1) +
Finset.univ.sum fun j : Fin (n + 1) =>
single (Fin.contractNth j (· * ·) g) (single (1 : G) ((-1 : k) ^ ((j : ℕ) + 1)))
variable {k G} in
lemma d_single (x : Gⁿ⁺¹) :
(d k G n).hom (single x (single 1 1)) = single (fun i => x i.succ) (Finsupp.single (x 0) 1) +
Finset.univ.sum fun j : Fin (n + 1) =>
single (Fin.contractNth j (· * ·) x) (single (1 : G) ((-1 : k) ^ ((j : ℕ) + 1))) := by
simp [d]
lemma d_comp_diagonalSuccIsoFree_inv_eq :
d k G n ≫ (diagonalSuccIsoFree k G n).inv =
(diagonalSuccIsoFree k G (n + 1)).inv ≫ (standardComplex k G).d (n + 1) n :=
free_ext _ _ fun i => by
simpa [diagonalSuccIsoFree_inv_hom_single_single (k := k), d_single (k := k),
standardComplex.d_eq, standardComplex.d_of (k := k) (Fin.partialProd i), Fin.sum_univ_succ,
Fin.partialProd_contractNth] using
congr(single $(by ext j; exact (Fin.partialProd_succ' i j).symm) 1)
end barComplex
open barComplex
variable [DecidableEq G]
/-- The projective resolution of `k` as a trivial `k`-linear `G`-representation with `n`th
differential `(Gⁿ⁺¹ →₀ k[G]) → (Gⁿ →₀ k[G])` sending `(g₀, ..., gₙ)` to
`g₀·(g₁, ..., gₙ) + ∑ (-1)ʲ⁺¹·(g₀, ..., gⱼgⱼ₊₁, ..., gₙ) + (-1)ⁿ⁺¹·(g₀, ..., gₙ₋₁)` for
`j = 0, ..., n - 1`. -/
noncomputable abbrev barComplex : ChainComplex (Rep k G) ℕ :=
ChainComplex.of (fun n => free k G (Fin n → G)) (fun n => d k G n) fun _ => by
ext x
simp [(diagonalSuccIsoFree k G _).comp_inv_eq.1 (d_comp_diagonalSuccIsoFree_inv_eq k G _)]
namespace barComplex
@[simp]
theorem d_def : (barComplex k G).d (n + 1) n = d k G n := ChainComplex.of_d _ _ _ _
/-- Isomorphism between the bar resolution and standard resolution, with `n`th map
`(Gⁿ →₀ k[G]) → k[Gⁿ⁺¹]` sending `(g₁, ..., gₙ) ↦ (1, g₁, g₁g₂, ..., g₁...gₙ)`. -/
def isoStandardComplex : barComplex k G ≅ standardComplex k G :=
HomologicalComplex.Hom.isoOfComponents (fun i => (diagonalSuccIsoFree k G i).symm) fun i j => by
rintro (rfl : j + 1 = i)
simp only [ChainComplex.of_x, Iso.symm_hom, d_def, d_comp_diagonalSuccIsoFree_inv_eq]
end barComplex
/-- The chain complex `barComplex k G` as a projective resolution of `k` as a trivial
`k`-linear `G`-representation. -/
@[simps complex]
def barResolution : ProjectiveResolution (Rep.trivial k G k) where
complex := barComplex k G
projective n := inferInstanceAs <| Projective (free k G (Fin n → G))
π := (isoStandardComplex k G).hom ≫ standardComplex.εToSingle₀ k G
/-- Given a `k`-linear `G`-representation `V`, `Extⁿ(k, V)` (where `k` is the trivial `k`-linear
`G`-representation) is isomorphic to the `n`th cohomology group of `Hom(P, V)`, where `P` is the
bar resolution of `k`. -/
def barResolution.extIso (V : Rep k G) (n : ℕ) :
((Ext k (Rep k G) n).obj (Opposite.op <| Rep.trivial k G k)).obj V ≅
((barComplex k G).linearYonedaObj k V).homology n :=
(barResolution k G).isoExt n V
end Rep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupHomology/LongExactSequence.lean | import Mathlib.Algebra.Homology.ConcreteCategory
import Mathlib.Algebra.Homology.HomologicalComplexAbelian
import Mathlib.RepresentationTheory.Homological.GroupHomology.Functoriality
/-!
# Long exact sequence in group homology
Given a commutative ring `k` and a group `G`, this file shows that a short exact sequence of
`k`-linear `G`-representations `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` induces a short exact sequence of
complexes
`0 ⟶ inhomogeneousChains X₁ ⟶ inhomogeneousChains X₂ ⟶ inhomogeneousChains X₃ ⟶ 0`.
Since the homology of `inhomogeneousChains Xᵢ` is the group homology of `Xᵢ`, this allows us
to specialize API about long exact sequences to group homology.
## Main definitions
* `groupHomology.δ hX i j hij`: the connecting homomorphism `Hᵢ(G, X₃) ⟶ Hⱼ(G, X₁)` associated
to an exact sequence `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of representations.
-/
universe v u
namespace groupHomology
open CategoryTheory ShortComplex Finsupp
variable {k G : Type u} [CommRing k] [Group G] {X : ShortComplex (Rep k G)} (hX : ShortExact X)
include hX
lemma map_chainsFunctor_shortExact :
ShortExact (X.map (chainsFunctor k G)) :=
letI := hX.mono_f
HomologicalComplex.shortExact_of_degreewise_shortExact _ fun i => {
exact := by
have : LinearMap.range X.f.hom.hom = LinearMap.ker X.g.hom.hom :=
(hX.exact.map (forget₂ (Rep k G) (ModuleCat k))).moduleCat_range_eq_ker
simp [moduleCat_exact_iff_range_eq_ker, ker_mapRange, range_mapRange_linearMap X.f.hom.hom
(LinearMap.ker_eq_bot.2 <| (ModuleCat.mono_iff_injective _).1 _), this]
mono_f := chainsMap_id_f_map_mono X.f i
epi_g := letI := hX.epi_g; chainsMap_id_f_map_epi X.g i }
open HomologicalComplex.HomologySequence
/-- The short complex `Hᵢ(G, X₃) ⟶ Hⱼ(G, X₁) ⟶ Hⱼ(G, X₂)` associated to an exact sequence
of representations `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0`. -/
noncomputable abbrev mapShortComplex₁ {i j : ℕ} (hij : j + 1 = i) :=
(snakeInput (map_chainsFunctor_shortExact hX) _ _ hij).L₂'
variable (X) in
/-- The short complex `Hᵢ(G, X₁) ⟶ Hᵢ(G, X₂) ⟶ Hᵢ(G, X₃)` associated to a short complex of
representations `X₁ ⟶ X₂ ⟶ X₃`. -/
noncomputable abbrev mapShortComplex₂ (i : ℕ) := X.map (functor k G i)
/-- The short complex `Hᵢ(G, X₂) ⟶ Hᵢ(G, X₃) ⟶ Hⱼ(G, X₁)` associated to an exact sequence of
representations `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0`. -/
noncomputable abbrev mapShortComplex₃ {i j : ℕ} (hij : j + 1 = i) :=
(snakeInput (map_chainsFunctor_shortExact hX) _ _ hij).L₁'
/-- Exactness of `Hᵢ(G, X₃) ⟶ Hⱼ(G, X₁) ⟶ Hⱼ(G, X₂)`. -/
lemma mapShortComplex₁_exact {i j : ℕ} (hij : j + 1 = i) :
(mapShortComplex₁ hX hij).Exact :=
(map_chainsFunctor_shortExact hX).homology_exact₁ i j hij
/-- Exactness of `Hᵢ(G, X₁) ⟶ Hᵢ(G, X₂) ⟶ Hᵢ(G, X₃)`. -/
lemma mapShortComplex₂_exact (i : ℕ) :
(mapShortComplex₂ X i).Exact :=
(map_chainsFunctor_shortExact hX).homology_exact₂ i
/-- Exactness of `Hᵢ(G, X₂) ⟶ Hᵢ(G, X₃) ⟶ Hⱼ(G, X₁)`. -/
lemma mapShortComplex₃_exact {i j : ℕ} (hij : j + 1 = i) :
(mapShortComplex₃ hX hij).Exact :=
(map_chainsFunctor_shortExact hX).homology_exact₃ i j hij
/-- The connecting homomorphism `Hᵢ(G, X₃) ⟶ Hⱼ(G, X₁)` associated to an exact sequence
`0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of representations. -/
noncomputable abbrev δ (i j : ℕ) (hij : j + 1 = i) :
groupHomology X.X₃ i ⟶ groupHomology X.X₁ j :=
(map_chainsFunctor_shortExact hX).δ i j hij
open Limits
theorem epi_δ_of_isZero (n : ℕ) (h : IsZero (groupHomology X.X₂ n)) :
Epi (δ hX (n + 1) n rfl) := SnakeInput.epi_δ _ h
theorem mono_δ_of_isZero (n : ℕ) (h : IsZero (groupHomology X.X₂ (n + 1))) :
Mono (δ hX (n + 1) n rfl) := SnakeInput.mono_δ _ h
theorem isIso_δ_of_isZero (n : ℕ) (hs : IsZero (groupHomology X.X₂ (n + 1)))
(h : IsZero (groupHomology X.X₂ n)) :
IsIso (δ hX (n + 1) n rfl) := SnakeInput.isIso_δ _ hs h
/-- Given an exact sequence of `G`-representations `0 ⟶ X₁ ⟶f X₂ ⟶g X₃ ⟶ 0`, this expresses an
`n`-chain `x : Gⁿ →₀ X₁` such that `f ∘ x ∈ Bₙ(G, X₂)` as a cycle. Stated for readability of
`δ_apply`. -/
noncomputable abbrev cyclesMkOfCompEqD {i j : ℕ} {y : (Fin i → G) →₀ X.X₂}
{x : (Fin j → G) →₀ X.X₁}
(hx : mapRange.linearMap X.f.hom.hom x = (inhomogeneousChains X.X₂).d i j y) :
cycles X.X₁ j :=
cyclesMk j _ rfl x <| by
simpa using (map_chainsFunctor_shortExact hX).d_eq_zero_of_f_eq_d_apply i j y x
(by simpa using hx) _
theorem δ_apply {i j : ℕ} (hij : j + 1 = i)
-- Let `0 ⟶ X₁ ⟶f X₂ ⟶g X₃ ⟶ 0` be a short exact sequence of `G`-representations.
-- Let `z` be an `j + 1`-cycle for `X₃`
(z : (Fin i → G) →₀ X.X₃) (hz : (inhomogeneousChains X.X₃).d i j z = 0)
-- Let `y` be an `j + 1`-chain for `X₂` such that `g ∘ y = z`
(y : (Fin i → G) →₀ X.X₂) (hy : (chainsMap (MonoidHom.id G) X.g).f i y = z)
-- Let `x` be an `j`-chain for `X₁` such that `f ∘ x = d(y)`
(x : (Fin j → G) →₀ X.X₁)
-- Then `x` is an `j`-cycle and `δ z = x` in `Hⱼ(X₁)`.
(hx : mapRange.linearMap X.f.hom.hom x = (inhomogeneousChains X.X₂).d i j y) :
δ hX i j hij (π X.X₃ i <| cyclesMk i j (by simp [← hij]) z (by simpa using hz)) =
π X.X₁ j (cyclesMkOfCompEqD hX hx) := by
exact (map_chainsFunctor_shortExact hX).δ_apply i j hij z hz y hy x (by simpa using hx) _ rfl
theorem δ₀_apply
-- Let `0 ⟶ X₁ ⟶f X₂ ⟶g X₃ ⟶ 0` be a short exact sequence of `G`-representations.
-- Let `z` by a 1-cycle for `X₃` and `y` a 1-chain for `X₂` such that `g ∘ y = z`.
(z : cycles₁ X.X₃) (y : G →₀ X.X₂) (hy : mapRange.linearMap X.g.hom.hom y = z.1)
-- Let `x : X₁` be such that `f(x) = d(y)`.
(x : X.X₁) (hx : X.f.hom x = d₁₀ X.X₂ y) :
-- Then `δ z = x` in `H₀(X₁)`.
δ hX 1 0 rfl (H1π X.X₃ z) = H0π X.X₁ x := by
simpa only [H1π, ModuleCat.hom_comp, LinearMap.coe_comp, Function.comp_apply, H0π,
← cyclesMk₀_eq X.X₁, ← cyclesMk₁_eq X.X₃]
using δ_apply hX (i := 1) (j := 0) rfl ((chainsIso₁ X.X₃).inv z.1) (by simp)
((chainsIso₁ X.X₂).inv y) (Finsupp.ext fun _ => by simp [chainsIso₁, ← hy])
((chainsIso₀ X.X₁).inv x) (Finsupp.ext fun _ => by simp [chainsIso₀, ← hx])
/-- Stated for readability of `δ₁_apply`. -/
theorem mem_cycles₁_of_comp_eq_d₂₁
{y : G × G →₀ X.X₂} {x : G →₀ X.X₁} (hx : mapRange.linearMap X.f.hom.hom x = d₂₁ X.X₂ y) :
x ∈ cycles₁ X.X₁ := LinearMap.mem_ker.2 <| (Rep.mono_iff_injective X.f).1 hX.2 <| by
have := congr($((mapShortComplexH1 (MonoidHom.id G) X.f).comm₂₃.symm) x)
simp_all [shortComplexH1]
theorem δ₁_apply
-- Let `0 ⟶ X₁ ⟶f X₂ ⟶g X₃ ⟶ 0` be a short exact sequence of `G`-representations.
-- Let `z` by a 2-cycle for `X₃` and `y` a 2-chain for `X₂` such that `g ∘ y = z`.
(z : cycles₂ X.X₃) (y : G × G →₀ X.X₂) (hy : mapRange.linearMap X.g.hom.hom y = z.1)
-- Let `x` be a 1-chain for `X₁` such that `f ∘ x = d(y)`.
(x : G →₀ X.X₁) (hx : mapRange.linearMap X.f.hom.hom x = d₂₁ X.X₂ y) :
-- Then `x` is a 1-cycle and `δ z = x` in `H₁(X₁)`.
δ hX 2 1 rfl (H2π X.X₃ z) = H1π X.X₁ ⟨x, mem_cycles₁_of_comp_eq_d₂₁ hX hx⟩ := by
simpa only [H2π, ModuleCat.hom_comp, LinearMap.coe_comp, Function.comp_apply, H1π,
← cyclesMk₂_eq X.X₃, ← cyclesMk₁_eq X.X₁]
using δ_apply hX (i := 2) (j := 1) rfl ((chainsIso₂ X.X₃).inv z.1) (by simp)
((chainsIso₂ X.X₂).inv y) (Finsupp.ext fun _ => by simp [chainsIso₂, ← hy])
((chainsIso₁ X.X₁).inv x) (Finsupp.ext fun _ => by simp [chainsIso₁, ← hx])
end groupHomology |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupHomology/Functoriality.lean | import Mathlib.RepresentationTheory.Homological.GroupHomology.LowDegree
/-!
# Functoriality of group homology
Given a commutative ring `k`, a group homomorphism `f : G →* H`, a `k`-linear `G`-representation
`A`, a `k`-linear `H`-representation `B`, and a representation morphism `A ⟶ Res(f)(B)`, we get
a chain map `inhomogeneousChains A ⟶ inhomogeneousChains B` and hence maps on homology
`Hₙ(G, A) ⟶ Hₙ(H, B)`.
We also provide extra API for these maps in degrees 0, 1, 2.
## Main definitions
* `groupHomology.chainsMap f φ` is the map `inhomogeneousChains A ⟶ inhomogeneousChains B`
induced by a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`.
* `groupHomology.map f φ n` is the map `Hₙ(G, A) ⟶ Hₙ(H, B)` induced by a group homomorphism
`f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`.
* `groupHomology.coresNatTrans f n`: given a group homomorphism `f : G →* H`, this is a natural
transformation of `n`th group homology functors which sends `A : Rep k H` to the "corestriction"
map `Hₙ(G, Res(f)(A)) ⟶ Hₙ(H, A)` induced by `f` and the identity map on `Res(f)(A)`.
* `groupHomology.coinfNatTrans f n`: given a normal subgroup `S ≤ G`, this is a natural
transformation of `n`th group homology functors which sends `A : Rep k G` to the "coinflation"
map `Hₙ(G, A) ⟶ Hₙ(G ⧸ S, A_S)` induced by the quotient maps `G →* G ⧸ S` and `A →ₗ A_S`.
* `groupHomology.H1CoresCoinf A S` is the (exact) short complex
`H₁(S, A) ⟶ H₁(G, A) ⟶ H₁(G ⧸ S, A_S)` for a normal subgroup `S ≤ G` and a `G`-representation
`A`, defined using the corestriction and coinflation map in degree 1.
-/
universe v u
namespace groupHomology
open CategoryTheory Rep Finsupp Representation
variable {k G H : Type u} [CommRing k] [Group G] [Group H]
{A : Rep k G} {B : Rep k H} (f : G →* H) (φ : A ⟶ (Action.res _ f).obj B) (n : ℕ)
theorem congr {f₁ f₂ : G →* H} (h : f₁ = f₂) {φ : A ⟶ (Action.res _ f₁).obj B} {T : Type*}
(F : (f : G →* H) → (φ : A ⟶ (Action.res _ f).obj B) → T) :
F f₁ φ = F f₂ (h ▸ φ) := by
subst h
rfl
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the chain map sending `∑ aᵢ·gᵢ : Gⁿ →₀ A` to `∑ φ(aᵢ)·(f ∘ gᵢ) : Hⁿ →₀ B`. -/
@[simps! -isSimp f f_hom]
noncomputable def chainsMap :
inhomogeneousChains A ⟶ inhomogeneousChains B where
f i := ModuleCat.ofHom <| mapRange.linearMap φ.hom.hom ∘ₗ lmapDomain A k (f ∘ ·)
comm' i j (hij : _ = _) := by
subst hij
ext
simpa [Fin.comp_contractNth, map_add, inhomogeneousChains.d]
using congr(single _ $((hom_comm_apply φ (_)⁻¹ _).symm))
@[reassoc (attr := simp)]
lemma lsingle_comp_chainsMap_f (n : ℕ) (x : Fin n → G) :
ModuleCat.ofHom (lsingle x) ≫ (chainsMap f φ).f n =
φ.hom ≫ ModuleCat.ofHom (lsingle (f ∘ x)) := by
ext
simp [chainsMap_f]
lemma chainsMap_f_single (n : ℕ) (x : Fin n → G) (a : A) :
(chainsMap f φ).f n (single x a) = single (f ∘ x) (φ.hom a) := by
simp [chainsMap_f]
@[simp]
lemma chainsMap_id :
chainsMap (MonoidHom.id G) (𝟙 A) = 𝟙 (inhomogeneousChains A) :=
HomologicalComplex.hom_ext _ _ fun _ => ModuleCat.hom_ext <| lhom_ext' fun _ =>
ModuleCat.hom_ext_iff.1 <| lsingle_comp_chainsMap_f (k := k) (MonoidHom.id G) ..
@[simp]
lemma chainsMap_id_f_hom_eq_mapRange {A B : Rep k G} (i : ℕ) (φ : A ⟶ B) :
((chainsMap (MonoidHom.id G) φ).f i).hom = mapRange.linearMap φ.hom.hom := by
refine lhom_ext fun _ _ => ?_
simp [chainsMap_f, MonoidHom.coe_id]
lemma chainsMap_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k G} {B : Rep k H} {C : Rep k K}
(f : G →* H) (g : H →* K) (φ : A ⟶ (Action.res _ f).obj B) (ψ : B ⟶ (Action.res _ g).obj C) :
chainsMap (g.comp f) (φ ≫ (Action.res _ f).map ψ) = chainsMap f φ ≫ chainsMap g ψ := by
ext
simp [chainsMap_f, Function.comp_assoc]
lemma chainsMap_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) :
chainsMap (MonoidHom.id G) (φ ≫ ψ) =
chainsMap (MonoidHom.id G) φ ≫ chainsMap (MonoidHom.id G) ψ :=
chainsMap_comp (MonoidHom.id G) (MonoidHom.id G) _ _
@[simp]
lemma chainsMap_zero : chainsMap f (0 : A ⟶ (Action.res _ f).obj B) = 0 := by
ext; simp [chainsMap_f, LinearMap.zero_apply (M₂ := B)]
lemma chainsMap_f_map_mono (hf : Function.Injective f) [Mono φ] (i : ℕ) :
Mono ((chainsMap f φ).f i) := by
simpa [ModuleCat.mono_iff_injective] using
(mapRange_injective φ.hom (map_zero _) <| (Rep.mono_iff_injective φ).1
inferInstance).comp (mapDomain_injective hf.comp_left)
instance chainsMap_id_f_map_mono {A B : Rep k G} (φ : A ⟶ B) [Mono φ] (i : ℕ) :
Mono ((chainsMap (MonoidHom.id G) φ).f i) :=
chainsMap_f_map_mono (MonoidHom.id G) φ (fun _ _ h => h) _
lemma chainsMap_f_map_epi (hf : Function.Surjective f) [Epi φ] (i : ℕ) :
Epi ((chainsMap f φ).f i) := by
simpa [ModuleCat.epi_iff_surjective] using
(mapRange_surjective φ.hom (map_zero _) ((Rep.epi_iff_surjective φ).1 inferInstance)).comp
(mapDomain_surjective hf.comp_left)
instance chainsMap_id_f_map_epi {A B : Rep k G} (φ : A ⟶ B) [Epi φ] (i : ℕ) :
Epi ((chainsMap (MonoidHom.id G) φ).f i) :=
chainsMap_f_map_epi _ _ (fun x => ⟨x, rfl⟩) _
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map `Zₙ(G, A) ⟶ Zₙ(H, B)` sending `∑ aᵢ·gᵢ : Gⁿ →₀ A` to
`∑ φ(aᵢ)·(f ∘ gᵢ) : Hⁿ →₀ B`. -/
noncomputable abbrev cyclesMap (n : ℕ) :
groupHomology.cycles A n ⟶ groupHomology.cycles B n :=
HomologicalComplex.cyclesMap (chainsMap f φ) n
@[simp]
lemma cyclesMap_id : cyclesMap (MonoidHom.id G) (𝟙 A) n = 𝟙 _ := by
simp [cyclesMap]
@[reassoc]
lemma cyclesMap_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k G} {B : Rep k H} {C : Rep k K} (f : G →* H) (g : H →* K)
(φ : A ⟶ (Action.res _ f).obj B) (ψ : B ⟶ (Action.res _ g).obj C) (n : ℕ) :
cyclesMap (g.comp f) (φ ≫ (Action.res _ f).map ψ) n = cyclesMap f φ n ≫ cyclesMap g ψ n := by
simp [cyclesMap, ← HomologicalComplex.cyclesMap_comp, ← chainsMap_comp]
theorem cyclesMap_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) (n : ℕ) :
cyclesMap (MonoidHom.id G) (φ ≫ ψ) n =
cyclesMap (MonoidHom.id G) φ n ≫ cyclesMap (MonoidHom.id G) ψ n := by
simp [cyclesMap, chainsMap_id_comp, HomologicalComplex.cyclesMap_comp]
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map `Hₙ(G, A) ⟶ Hₙ(H, B)` sending `∑ aᵢ·gᵢ : Gⁿ →₀ A` to
`∑ φ(aᵢ)·(f ∘ gᵢ) : Hⁿ →₀ B`. -/
noncomputable abbrev map (n : ℕ) :
groupHomology A n ⟶ groupHomology B n :=
HomologicalComplex.homologyMap (chainsMap f φ) n
@[reassoc, elementwise]
theorem π_map (n : ℕ) :
π A n ≫ map f φ n = cyclesMap f φ n ≫ π B n := by
simp [map, cyclesMap]
@[simp]
lemma map_id : map (MonoidHom.id G) (𝟙 A) n = 𝟙 _ := by
simp [map, groupHomology]
@[reassoc]
lemma map_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k G} {B : Rep k H} {C : Rep k K} (f : G →* H) (g : H →* K)
(φ : A ⟶ (Action.res _ f).obj B) (ψ : B ⟶ (Action.res _ g).obj C) (n : ℕ) :
map (g.comp f) (φ ≫ (Action.res _ f).map ψ) n = map f φ n ≫ map g ψ n := by
simp [map, ← HomologicalComplex.homologyMap_comp, ← chainsMap_comp]
theorem map_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) (n : ℕ) :
map (MonoidHom.id G) (φ ≫ ψ) n =
map (MonoidHom.id G) φ n ≫ map (MonoidHom.id G) ψ n := by
rw [map, chainsMap_id_comp, HomologicalComplex.homologyMap_comp]
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map sending `∑ aᵢ·gᵢ : G →₀ A` to `∑ φ(aᵢ)·f(gᵢ) : H →₀ B`. -/
noncomputable abbrev chainsMap₁ : ModuleCat.of k (G →₀ A) ⟶ ModuleCat.of k (H →₀ B) :=
ModuleCat.ofHom <| mapRange.linearMap φ.hom.hom ∘ₗ lmapDomain A k f
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map sending `∑ aᵢ·(gᵢ₁, gᵢ₂) : G × G →₀ A` to
`∑ φ(aᵢ)·(f(gᵢ₁), f(gᵢ₂)) : H × H →₀ B`. -/
noncomputable abbrev chainsMap₂ : ModuleCat.of k (G × G →₀ A) ⟶ ModuleCat.of k (H × H →₀ B) :=
ModuleCat.ofHom <| mapRange.linearMap φ.hom.hom ∘ₗ lmapDomain A k (Prod.map f f)
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map sending `∑ aᵢ·(gᵢ₁, gᵢ₂, gᵢ₃) : G × G × G →₀ A` to
`∑ φ(aᵢ)·(f(gᵢ₁), f(gᵢ₂), f(gᵢ₃)) : H × H × H →₀ B`. -/
noncomputable abbrev chainsMap₃ :
ModuleCat.of k (G × G × G →₀ A) ⟶ ModuleCat.of k (H × H × H →₀ B) :=
ModuleCat.ofHom <| mapRange.linearMap φ.hom.hom ∘ₗ lmapDomain A k (Prod.map f (Prod.map f f))
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma chainsMap_f_0_comp_chainsIso₀ :
(chainsMap f φ).f 0 ≫ (chainsIso₀ B).hom = (chainsIso₀ A).hom ≫ φ.hom := by
ext
simp [chainsMap_f, Unique.eq_default (α := Fin 0 → G), Unique.eq_default (α := Fin 0 → H),
chainsIso₀]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma chainsMap_f_1_comp_chainsIso₁ :
(chainsMap f φ).f 1 ≫ (chainsIso₁ B).hom = (chainsIso₁ A).hom ≫ chainsMap₁ f φ := by
ext x
simp [chainsMap_f, chainsIso₁]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma chainsMap_f_2_comp_chainsIso₂ :
(chainsMap f φ).f 2 ≫ (chainsIso₂ B).hom = (chainsIso₂ A).hom ≫ chainsMap₂ f φ := by
ext
simp [chainsMap_f, chainsIso₂]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma chainsMap_f_3_comp_chainsIso₃ :
(chainsMap f φ).f 3 ≫ (chainsIso₃ B).hom = (chainsIso₃ A).hom ≫ chainsMap₃ f φ := by
ext
simp [chainsMap_f, chainsIso₃, ← Fin.comp_tail]
open ShortComplex
section H0
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem cyclesMap_comp_cyclesIso₀_hom :
cyclesMap f φ 0 ≫ (cyclesIso₀ B).hom = (cyclesIso₀ A).hom ≫ φ.hom := by
simp [cyclesIso₀]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem cyclesIso₀_inv_comp_cyclesMap :
(cyclesIso₀ A).inv ≫ cyclesMap f φ 0 = φ.hom ≫ (cyclesIso₀ B).inv :=
(CommSq.vert_inv ⟨cyclesMap_comp_cyclesIso₀_hom f φ⟩).w.symm
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem H0π_comp_map :
H0π A ≫ map f φ 0 = φ.hom ≫ H0π B := by
simp [H0π]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem map_id_comp_H0Iso_hom {A B : Rep k G} (f : A ⟶ B) :
map (MonoidHom.id G) f 0 ≫ (H0Iso B).hom =
(H0Iso A).hom ≫ (coinvariantsFunctor k G).map f := by
rw [← cancel_epi (H0π A)]
ext
simp
instance epi_map_0_of_epi {A B : Rep k G} (f : A ⟶ B) [Epi f] :
Epi (map (MonoidHom.id G) f 0) where
left_cancellation g h hgh := by
simp only [← cancel_epi (H0π A)] at hgh
simp_all [cancel_epi]
end H0
section H1
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map from the short complex `(G × G →₀ A) --d₂₁--> (G →₀ A) --d₁₀--> A`
to `(H × H →₀ B) --d₂₁--> (H →₀ B) --d₁₀--> B`. -/
@[simps]
noncomputable def mapShortComplexH1 :
shortComplexH1 A ⟶ shortComplexH1 B where
τ₁ := chainsMap₂ f φ
τ₂ := chainsMap₁ f φ
τ₃ := φ.hom
comm₁₂ := by
simp only [shortComplexH1]
ext : 3
simpa [d₂₁, map_add, map_sub, ← map_inv] using congr(single _ $((hom_comm_apply φ _ _).symm))
comm₂₃ := by
simp only [shortComplexH1]
ext : 3
simpa [← map_inv, d₁₀] using (hom_comm_apply φ _ _).symm
@[simp]
theorem mapShortComplexH1_zero :
mapShortComplexH1 (A := A) (B := B) f 0 = 0 := by
refine ShortComplex.hom_ext _ _ ?_ ?_ rfl
all_goals
{ simp only [shortComplexH1]
ext
simp }
@[simp]
theorem mapShortComplexH1_id : mapShortComplexH1 (MonoidHom.id G) (𝟙 A) = 𝟙 _ := by
simp only [shortComplexH1]
ext <;> simp
theorem mapShortComplexH1_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k G} {B : Rep k H} {C : Rep k K} (f : G →* H) (g : H →* K)
(φ : A ⟶ (Action.res _ f).obj B) (ψ : B ⟶ (Action.res _ g).obj C) :
mapShortComplexH1 (g.comp f) (φ ≫ (Action.res _ f).map ψ) =
(mapShortComplexH1 f φ) ≫ (mapShortComplexH1 g ψ) := by
refine ShortComplex.hom_ext _ _ ?_ ?_ rfl
all_goals
{ simp only [shortComplexH1]
ext
simp [Prod.map] }
theorem mapShortComplexH1_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) :
mapShortComplexH1 (MonoidHom.id G) (φ ≫ ψ) =
mapShortComplexH1 (MonoidHom.id G) φ ≫ mapShortComplexH1 (MonoidHom.id G) ψ :=
mapShortComplexH1_comp (MonoidHom.id G) (MonoidHom.id G) _ _
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map `Z₁(G, A) ⟶ Z₁(H, B)`. -/
noncomputable abbrev mapCycles₁ :
ModuleCat.of k (cycles₁ A) ⟶ ModuleCat.of k (cycles₁ B) :=
ShortComplex.cyclesMap' (mapShortComplexH1 f φ) (shortComplexH1 A).moduleCatLeftHomologyData
(shortComplexH1 B).moduleCatLeftHomologyData
lemma mapCycles₁_hom :
(mapCycles₁ f φ).hom = (chainsMap₁ f φ).hom.restrict (fun x _ => by
have := congr($((mapShortComplexH1 f φ).comm₂₃) x); simp_all [cycles₁, shortComplexH1]) :=
rfl
@[reassoc, elementwise]
lemma mapCycles₁_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k G} {B : Rep k H} {C : Rep k K} (f : G →* H) (g : H →* K)
(φ : A ⟶ (Action.res _ f).obj B) (ψ : B ⟶ (Action.res _ g).obj C) :
mapCycles₁ (g.comp f) (φ ≫ (Action.res _ f).map ψ) =
mapCycles₁ f φ ≫ mapCycles₁ g ψ := by
rw [← cyclesMap'_comp, ← mapShortComplexH1_comp]
@[reassoc, elementwise]
theorem mapCycles₁_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) :
mapCycles₁ (MonoidHom.id G) (φ ≫ ψ) =
mapCycles₁ (MonoidHom.id G) φ ≫ mapCycles₁ (MonoidHom.id G) ψ :=
mapCycles₁_comp (MonoidHom.id G) (MonoidHom.id G) _ _
@[reassoc, elementwise]
lemma mapCycles₁_comp_i :
mapCycles₁ f φ ≫ (shortComplexH1 B).moduleCatLeftHomologyData.i =
(shortComplexH1 A).moduleCatLeftHomologyData.i ≫ chainsMap₁ f φ := by
simp
@[simp]
lemma coe_mapCycles₁ (x) :
(mapCycles₁ f φ x).1 = chainsMap₁ f φ x := rfl
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cyclesMap_comp_isoCycles₁_hom :
cyclesMap f φ 1 ≫ (isoCycles₁ B).hom = (isoCycles₁ A).hom ≫ mapCycles₁ f φ := by
simp [← cancel_mono (moduleCatLeftHomologyData (shortComplexH1 B)).i, mapShortComplexH1,
chainsMap_f_1_comp_chainsIso₁ f]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma H1π_comp_map :
H1π A ≫ map f φ 1 = mapCycles₁ f φ ≫ H1π B := by
simp [H1π, Iso.inv_comp_eq, ← cyclesMap_comp_isoCycles₁_hom_assoc]
@[simp]
lemma map₁_one (φ : A ⟶ (Action.res _ (1 : G →* H)).obj B) :
map (1 : G →* H) φ 1 = 0 := by
simp only [← cancel_epi (H1π A), H1π_comp_map, Limits.comp_zero]
ext x
rw [ModuleCat.hom_comp]
refine (H1π_eq_zero_iff _).2 ?_
simpa [coe_mapCycles₁ _ φ x, mapDomain, map_finsuppSum] using
(boundaries₁ B).finsuppSum_mem k x.1 _ fun _ _ => single_one_mem_boundaries₁ (A := B) _
section CoresCoinf
/-!
### Exactness of the corestriction-coinflation sequence in degree 1
Given a group homomorphism `f : G →* H`, the `n`th corestriction map is the map
`Hₙ(G, Res(f)(A)) ⟶ Hₙ(H, A)` induced by `f` and the identity map on `Res(f)(A)`. Similarly, given
a normal subgroup `S ≤ G`, we define the `n`th coinflation map `Hₙ(G, A) ⟶ Hₙ(G ⧸ S, A_S)` as the
map induced by the quotient maps `G →* G ⧸ S` and `A →ₗ A_S`.
In particular, for `S ≤ G` normal and `A : Rep k G`, the corestriction map
`Hₙ(S, Res(ι)(A)) ⟶ Hₙ(G, A)` and the coinflation map `Hₙ(G, A) ⟶ Hₙ(G ⧸ S, A_S)` form a short
complex, where `ι : S →* G` is the natural inclusion. In this section we define this short complex
for degree 1, `groupHomology.H1CoresCoinf A S`, and prove it is exact.
We do this first when `A` is `S`-trivial, and then extend to the general case.
-/
variable (A) (S : Subgroup G) [S.Normal]
section OfTrivial
variable [IsTrivial (A.ρ.comp S.subtype)]
instance mapCycles₁_quotientGroupMk'_epi :
Epi (mapCycles₁ (QuotientGroup.mk' S) (resOfQuotientIso A S).inv) := by
rw [ModuleCat.epi_iff_surjective]
rintro ⟨x, hx⟩
choose! s hs using QuotientGroup.mk_surjective (s := S)
have hs₁ : QuotientGroup.mk ∘ s = id := funext hs
refine ⟨⟨mapDomain s x, ?_⟩, Subtype.ext <| by
simp [mapCycles₁_hom, ← mapDomain_comp, hs₁]⟩
simpa [mem_cycles₁_iff, ← (mem_cycles₁_iff _).1 hx, sum_mapDomain_index_inj (f := s)
(fun x y h => by rw [← hs x, ← hs y, h])]
using Finsupp.sum_congr fun a b => QuotientGroup.induction_on a fun a => by
simp [← QuotientGroup.mk_inv, apply_eq_of_coe_eq A.ρ S (s a)⁻¹ a⁻¹ (by simp [hs])]
/-- Given a `G`-representation `A` on which a normal subgroup `S ≤ G` acts trivially, this is the
short complex `H₁(S, A) ⟶ H₁(G, A) ⟶ H₁(G ⧸ S, A)`. (This is a simplified expression for the
degree 1 corestriction-coinflation sequence when `A` is `S`-trivial.) -/
@[simps X₁ X₂ X₃ f g]
noncomputable def H1CoresCoinfOfTrivial :
ShortComplex (ModuleCat k) where
X₁ := H1 ((Action.res _ S.subtype).obj A)
X₂ := H1 A
X₃ := H1 (ofQuotient A S)
f := map S.subtype (𝟙 _) 1
g := map (QuotientGroup.mk' S) (resOfQuotientIso A S).inv 1
zero := by rw [← map_comp, congr (QuotientGroup.mk'_comp_subtype S) (map (n := 1)), map₁_one]
instance map₁_quotientGroupMk'_epi :
Epi (map (QuotientGroup.mk' S) (resOfQuotientIso A S).inv 1) := by
convert epi_of_epi (H1π A) _
rw [H1π_comp_map]
exact @epi_comp _ _ _ _ _ _ (mapCycles₁_quotientGroupMk'_epi A S) (H1π _) inferInstance
/-- Given a `G`-representation `A` on which a normal subgroup `S ≤ G` acts trivially, the
induced map `H₁(G, A) ⟶ H₁(G ⧸ S, A)` is an epimorphism. -/
instance H1CoresCoinfOfTrivial_g_epi :
Epi (H1CoresCoinfOfTrivial A S).g :=
inferInstanceAs <| Epi (map _ _ 1)
/-- Given a `G`-representation `A` on which a normal subgroup `S ≤ G` acts trivially, the short
complex `H₁(S, A) ⟶ H₁(G, A) ⟶ H₁(G ⧸ S, A)` is exact. -/
theorem H1CoresCoinfOfTrivial_exact :
(H1CoresCoinfOfTrivial A S).Exact := by
classical
rw [ShortComplex.moduleCat_exact_iff_ker_sub_range]
intro x hx
/- Denote `C(i) : C(S, A) ⟶ C(G, A), C(π) : C(G, A) ⟶ C(G ⧸ S, A)` and let `x : Z₁(G, A)` map to
0 in `H₁(G ⧸ S, A)`. -/
induction x using H1_induction_on with | @h x =>
rcases x with ⟨x, hxc⟩
simp_all only [H1CoresCoinfOfTrivial_X₂, H1CoresCoinfOfTrivial_X₃, H1CoresCoinfOfTrivial_g,
LinearMap.mem_ker, H1π_comp_map_apply (QuotientGroup.mk' S)]
/- Choose `y := ∑ y(σ, τ)·(σ, τ) ∈ C₂(G ⧸ S, A)` such that `C₁(π)(x) = d(y)`. -/
rcases (H1π_eq_zero_iff _).1 hx with ⟨y, hy⟩
/- Let `s : G ⧸ S → G` be a section of the quotient map. -/
choose! s hs using QuotientGroup.mk'_surjective S
have hs₁ : QuotientGroup.mk (s := S) ∘ s = id := funext hs
/- Let `z := ∑ y(σ, τ)·(s(σ), s(τ))`. -/
let z : G × G →₀ A := lmapDomain _ k (Prod.map s s) y
/- We have that `C₂(π)(z) = y`. -/
have hz : lmapDomain _ k (QuotientGroup.mk' S) (d₂₁ A z) = d₂₁ (A.ofQuotient S) y := by
have := congr($((mapShortComplexH1 (QuotientGroup.mk' S)
(resOfQuotientIso A S).inv).comm₁₂.symm) z)
simp_all [shortComplexH1, z, ← mapDomain_comp, Prod.map_comp_map]
let v := x - d₂₁ _ z
/- We have `C₁(s ∘ π)(v) = ∑ v(g)·s(π(g)) = 0`, since `C₁(π)(v) = dC₁(π)(z) - C₁(π)(dz) = 0` by
previous assumptions. -/
have hv : mapDomain (s ∘ QuotientGroup.mk) v = 0 := by
rw [mapDomain_comp]
simp_all [v, mapDomain, sum_sub_index, coe_mapCycles₁ _ _ ⟨x, hxc⟩]
let e : G → G × G := fun (g : G) => (s (g : G ⧸ S), (s (g : G ⧸ S))⁻¹ * g)
have he : e.Injective := fun x y hxy => by
obtain ⟨(h₁ : s _ = s _), (h₂ : _ * _ = _ * _)⟩ := Prod.ext_iff.1 hxy
exact (mul_right_inj _).1 (h₁ ▸ h₂)
/- Let `ve := ∑ v(g)·(s(π(g)), s(π(g))⁻¹g)`. -/
let ve : G × G →₀ A := mapDomain e v
have hS : ((v + d₂₁ _ ve).support : Set G) ⊆ S := by
/- We have `d(ve) = ∑ ρ(s(π(g))⁻¹)(v(g))·s(π(g))⁻¹g - ∑ v(g)·g + ∑ v(g)·s(π(g))`.
The second sum is `v`, so cancels: -/
simp only [d₂₁, ve, ModuleCat.hom_ofHom, coe_lsum, sum_mapDomain_index_inj he, sum_single,
LinearMap.add_apply, LinearMap.sub_apply, LinearMap.coe_comp, Function.comp_apply,
lsingle_apply, sum_add, sum_sub, mul_inv_cancel_left, ← add_assoc, add_sub_cancel, e]
intro w hw
· obtain (hl | hr) := Finset.mem_union.1 (support_add hw)
/- The first sum clearly has support in `S`: -/
· obtain ⟨t, _, ht⟩ := Finset.mem_biUnion.1 (support_sum hl)
apply support_single_subset at ht
simp_all [← QuotientGroup.eq]
/- The third sum is 0, by `hv`. -/
· simp_all [mapDomain]
/- Now `v + d(ve)` has support in `S` and agrees with `x` in `H₁(G, A)`: -/
use H1π _ ⟨comapDomain Subtype.val (v + d₂₁ _ ve) <|
Set.injOn_of_injective Subtype.val_injective, ?_⟩
· simp only [H1CoresCoinfOfTrivial_f, H1CoresCoinfOfTrivial_X₁, H1π_comp_map_apply]
refine (H1π_eq_iff _ _).2 ?_
/- Indeed, `v + d(ve) - x = d(ve - z) ∈ B₁(G, A)`, since `v := x - dz`. -/
use ve - z
have := mapDomain_comapDomain (α := S) Subtype.val Subtype.val_injective
(v + d₂₁ A ve) (fun x hx => ⟨⟨x, hS hx⟩, rfl⟩)
simp_all [mapCycles₁_hom, v, add_sub_assoc, sub_add_sub_cancel']
/- And `v + d(ve) := x - dz + d(ve)` is a 1-cycle because `x` is. -/
· have : v + d₂₁ _ ve ∈ cycles₁ A := Submodule.add_mem _
(Submodule.sub_mem _ hxc <| d₂₁_apply_mem_cycles₁ _) (d₂₁_apply_mem_cycles₁ _)
rw [mem_cycles₁_iff] at this ⊢
rwa [← sum_comapDomain, ← sum_comapDomain (g := fun _ a => a)] at this <;>
exact ⟨Set.mapsTo_preimage _ _, Set.injOn_of_injective Subtype.val_injective,
fun x hx => ⟨⟨x, hS hx⟩, hx, rfl⟩⟩
end OfTrivial
/-- The short complex `H₁(S, A) ⟶ H₁(G, A) ⟶ H₁(G ⧸ S, A_S)`. The first map is the
"corestriction" map induced by the inclusion `ι : S →* G` and the identity on `Res(ι)(A)`, and the
second map is the "coinflation" map induced by the quotient maps `G →* G ⧸ S` and `A →ₗ A_S`. -/
@[simps X₁ X₂ X₃ f g]
noncomputable def H1CoresCoinf :
ShortComplex (ModuleCat k) where
X₁ := H1 ((Action.res _ S.subtype).obj A)
X₂ := H1 A
X₃ := H1 (quotientToCoinvariants A S)
f := map S.subtype (𝟙 _) 1
g := map (QuotientGroup.mk' S) (toCoinvariantsMkQ A S) 1
zero := by rw [← map_comp, congr (QuotientGroup.mk'_comp_subtype S) (map (n := 1)), map₁_one]
/-- Given a `G`-representation `A` and a normal subgroup `S ≤ G`, let `I(S)A` denote the submodule
of `A` spanned by elements of the form `ρ(s)(a) - a` for `s : S, a : A`. Then the image of
`C₁(G, I(S)A)` in `C₁(G, A)⧸B₁(G, A)` is contained in the image of `C₁(S, A)`. -/
theorem comap_coinvariantsKer_pOpcycles_range_subtype_pOpcycles_eq_top :
Submodule.comap ((mapShortComplexH1 (MonoidHom.id G) (coinvariantsShortComplex A S).f).τ₂ ≫
(shortComplexH1 _).pOpcycles).hom (LinearMap.range ((mapShortComplexH1 S.subtype (𝟙 _)).τ₂ ≫
(shortComplexH1 _).pOpcycles).hom) = ⊤ := by
rw [eq_top_iff]
intro x _
rcases mapRange_surjective _ (map_zero _) (chains₁ToCoinvariantsKer_surjective
((Action.res _ S.subtype).obj A)) x with ⟨(X : G →₀ S →₀ A), hX⟩
let Y : S →₀ A := X.sum fun g f =>
mapRange.linearMap (A.ρ g⁻¹) (lmapDomain _ k (fun s => MulAut.conjNormal g⁻¹ s) f) - f
let Z : G × G →₀ A := X.sum fun g f =>
lmapDomain _ k (fun s => (g, g⁻¹ * s.1 * g)) f - lmapDomain _ k (fun s => (s.1, g)) f
use Y
apply (moduleCat_pOpcycles_eq_iff _ _ _).2 ⟨Z, ?_⟩
change d₂₁ A Z = mapRange id rfl (lmapDomain _ k Subtype.val Y) -
mapRange.linearMap (Submodule.subtype _) (mapDomain id x)
simpa [map_finsuppSum, mapDomain, map_sub, ← hX, sum_single_index, finsuppProdLEquiv,
finsuppProdEquiv, Finsupp.uncurry, d₂₁, Y, Z, sum_mapRange_index,
chains₁ToCoinvariantsKer, d₁₀, single_sum, mul_assoc, sub_add_eq_add_sub,
sum_sum_index, add_smul, sub_sub_sub_eq, lsingle, singleAddHom] using add_comm _ _
/-- Given a `G`-representation `A` and a normal subgroup `S ≤ G`, the map
`H₁(G, A) ⟶ H₁(G ⧸ S, A_S)` induced by the quotient maps `G →* G ⧸ S` and `A →ₗ A_S` is an
epimorphism. -/
instance : Epi (H1CoresCoinf A S).g := by
rw [ModuleCat.epi_iff_surjective]
intro x
induction x using H1_induction_on with | @h x =>
/- Let `x : Z₁(G ⧸ S, A_S)`. We know `Z₁(G, A_S) ⟶ Z₁(G ⧸ S, A_S)` is surjective, so pick
`y : Z₁(G, A_S)` in the preimage of `x`. -/
rcases (ModuleCat.epi_iff_surjective _).1
(mapCycles₁_quotientGroupMk'_epi (A.toCoinvariants S) S) x with ⟨y, hy⟩
/- We know `C₁(G, A) ⟶ C₁(G, A_S)` is surjective, so pick `Y` in the preimage of `y`. -/
rcases mapRange_surjective _ (map_zero _)
(Coinvariants.mk_surjective (A.ρ.comp S.subtype)) y.1 with ⟨Y, hY⟩
/- Then `d(Y) ∈ I(S)A,` since `d(y) = 0`. -/
have : d₁₀ _ Y ∈ Coinvariants.ker (A.ρ.comp S.subtype) := by
have h' := congr($((mapShortComplexH1 (B := toCoinvariants A S)
(MonoidHom.id G) (toCoinvariantsMkQ A S)).comm₂₃) Y)
simp_all [shortComplexH1, ← Coinvariants.mk_eq_zero]
/- Thus we can pick a representation of `d(Y)` as a sum `∑ ρ(sᵢ⁻¹)(aᵢ) - aᵢ`, `sᵢ ∈ S, aᵢ ∈ A`,
and `Y - ∑ aᵢ·sᵢ` is a cycle. -/
rcases chains₁ToCoinvariantsKer_surjective
((Action.res _ S.subtype).obj A) ⟨d₁₀ A Y, this⟩ with ⟨(Z : S →₀ A), hZ⟩
have H : d₁₀ A (Y - mapDomain S.subtype Z) = 0 := by
simpa [map_sub, sub_eq_zero, chains₁ToCoinvariantsKer, - LinearMap.sub_apply, d₁₀,
sum_mapDomain_index_inj] using Subtype.ext_iff.1 hZ.symm
use H1π A ⟨Y - mapDomain S.subtype Z, H⟩
simp only [H1CoresCoinf_X₃, H1CoresCoinf_X₂, H1CoresCoinf_g,
Subgroup.coe_subtype, H1π_comp_map_apply]
/- Moreover, the image of `Y - ∑ aᵢ·sᵢ` in `Z₁(G ⧸ S, A_S)` is `x - ∑ aᵢ·1`, and hence differs from
`x` by a boundary, since `aᵢ·1 = d(aᵢ·(1, 1))`. -/
refine (H1π_eq_iff _ _).2 ?_
simpa [← hy, mapCycles₁_hom, map_sub, mapRange_sub, hY, ← mapDomain_comp, ← mapDomain_mapRange,
Function.comp_def, (QuotientGroup.eq_one_iff <| Subtype.val _).2 (Subtype.prop _)]
using Submodule.finsuppSum_mem _ _ _ _ fun _ _ => single_one_mem_boundaries₁ _
/-- Given a `G`-representation `A` and a normal subgroup `S ≤ G`, the degree 1
corestriction-coinflation sequence `H₁(S, A) ⟶ H₁(G, A) ⟶ H₁(G ⧸ S, A_S)` is exact. `simp`s
squeezed for performance. -/
theorem H1CoresCoinf_exact :
(H1CoresCoinf A S).Exact := by
rw [ShortComplex.moduleCat_exact_iff_ker_sub_range]
intro x hx
induction x using H1_induction_on with | @h x =>
simp only [H1CoresCoinf_X₂, H1CoresCoinf_X₃, LinearMap.mem_ker, H1CoresCoinf_g,
H1π_comp_map_apply (QuotientGroup.mk' S)] at hx
/- Let `x : Z₁(G, A)` map to 0 in `H₁(G, ⧸ S, A_S)`. Pick `y : C₂(G ⧸ S, A_S)` such that `d(y)`
equals `Z₁(π, π)(x) : Z₁(G ⧸ S, A_S)`. -/
rcases (H1π_eq_zero_iff _).1 hx with ⟨y, hy⟩
/- Then `Z₁(π, Id)(x) : Z₁(G, A_S)` maps to 0 in `H₁(G ⧸ S, A_S)`. We know
`H₁(S, A_S) ⟶ H₁(G, A_S) ⟶ H₁(G ⧸ S, A_S)` is exact by `H1CoresCoinfOfTrivial_exact`, since
`S` acts trivially on `A_S`. So we can choose `z : Z₁(S, A_S)` with the same homology class as
`Z₁(π, Id)(π)` in `H₁(G, A_S)`. -/
rcases @(ShortComplex.moduleCat_exact_iff_ker_sub_range _).1
(H1CoresCoinfOfTrivial_exact (toCoinvariants A S) S)
(H1π _ <| mapCycles₁ (MonoidHom.id G) (toCoinvariantsMkQ A S) x) (by
simpa only [H1CoresCoinfOfTrivial_X₂, H1CoresCoinfOfTrivial_X₃, H1CoresCoinfOfTrivial_g,
Iso.refl_inv, LinearMap.mem_ker, H1π_comp_map_apply (QuotientGroup.mk' S),
← mapCycles₁_comp_apply (x := x)] using hx) with ⟨z, hz⟩
induction z using H1_induction_on with | @h z =>
simp only [H1CoresCoinfOfTrivial_X₂, H1CoresCoinfOfTrivial_X₁, H1CoresCoinfOfTrivial_f] at hz
rw [H1π_comp_map_apply] at hz
/- Choose `w : C₂(G, A_S)` such that `d(w) = Z₁(i, Id)(z) - Z₁(Id, π)(x)`. -/
rcases (H1π_eq_iff _ _).1 hz with ⟨w, hzw⟩
/- Choose `Z : C₁(S, A)` mapping to `z : C₁(S, A_S)`, and `W : C₂(G, A)` mapping to
`w : C₂(G, A_S)`. -/
rcases mapRange_surjective (Coinvariants.mk _) (map_zero _)
(Coinvariants.mk_surjective _) z.1 with ⟨Z, hZ⟩
rcases mapRange_surjective (Coinvariants.mk _) (map_zero _)
(Coinvariants.mk_surjective _) w with ⟨W, hW⟩
/- Let `b : C₁(G, A)` denote `x + d(W) - C₁(i, Id)(z)`. -/
let b : G →₀ A := (x.1 : G →₀ A) + d₂₁ A W - lmapDomain _ k S.subtype Z
/- Then `b` has coefficients in `I(S)A := ⟨{ρ(s)(a) - a | s ∈ S, a ∈ A}⟩`, since
`C₁(G, I(S)(A)) ⟶ C₁(G, A) ⟶ C₁(G, A_S)` is exact, and `b` is in the kernel of the second map. -/
have hb : ∀ g, b g ∈ Coinvariants.ker (A.ρ.comp S.subtype) :=
fun g => (Coinvariants.mk_eq_iff _).1 <| by
have := Finsupp.ext_iff.1 (congr($((mapShortComplexH1 (B := toCoinvariants A S)
(MonoidHom.id G) (toCoinvariantsMkQ A S)).comm₁₂.symm) W)) g
simp only [shortComplexH1, mapShortComplexH1_τ₂, ModuleCat.ofHom_comp, MonoidHom.coe_id,
lmapDomain_id, ModuleCat.ofHom_id, Action.res_obj_V, toCoinvariantsMkQ_hom,
Category.id_comp, mapShortComplexH1_τ₁, Prod.map_id, ModuleCat.hom_comp,
ModuleCat.hom_ofHom, LinearMap.coe_comp, Function.comp_apply, mapRange.linearMap_apply,
mapRange_apply, hW, hzw, mapCycles₁_hom, Subgroup.coe_subtype, Action.id_hom,
ModuleCat.hom_id, mapRange.linearMap_id, Category.comp_id, LinearMap.restrict_coe_apply,
lmapDomain_apply, coe_sub, Pi.sub_apply, eq_sub_iff_add_eq'] at this
simp only [← mapRange_apply (f := Coinvariants.mk <| A.ρ.comp S.subtype)
(hf := map_zero _) (a := g), ← mapRange.linearMap_apply (R := k)]
simp only [mapRange.linearMap_apply, mapRange_apply, coe_add, Pi.add_apply, map_add, this,
Subgroup.coe_subtype, lmapDomain_apply, implies_true, ← mapDomain_mapRange, hZ,
Action.res_obj_V]
/- Let `β` be `b` considered as an element of `C₁(G, I(S)(A))`, so that `C₁(Id, i)(β) = b`. -/
let β : G →₀ Coinvariants.ker (A.ρ.comp S.subtype) :=
mapRange (Function.invFun <| (Coinvariants.ker (A.ρ.comp S.subtype)).subtype)
(Function.leftInverse_invFun Subtype.val_injective (0 : Coinvariants.ker _)) b
have hβb : mapRange Subtype.val rfl β = b := Finsupp.ext fun g => Subtype.ext_iff.1 <|
Function.leftInverse_invFun Subtype.val_injective ⟨b g, hb g⟩
/- Then, since the image of `C₁(G, I(S)A)` in `C₁(G, A)⧸B₁(G, A)` is contained in the image of
`C₁(S, A)` by `comap_coinvariantsKer_pOpcycles_range_subtype_pOpcycles_eq_top`, we can choose
`α : C₁(S, A)`, `δ : C₂(G, A)` such that `d(δ) = Z₁(i, Id)(α) - Z₁(Id, i)(β)`. -/
rcases eq_top_iff.1 (comap_coinvariantsKer_pOpcycles_range_subtype_pOpcycles_eq_top A S)
(by trivial : β ∈ ⊤) with ⟨(α : S →₀ A), hα⟩
dsimp only [ModuleCat.hom_comp] at hα
rcases (moduleCat_pOpcycles_eq_iff _ _ _).1 hα with ⟨(δ : G × G →₀ A), hβ⟩
/- Then, by assumption, `d(W + δ) = C₁(i, Id)(α + Z) - x`. -/
have hαZ : d₂₁ A (W + δ) = mapDomain Subtype.val (α + Z) - x := by
simp_all only [shortComplexH1, Finsupp.coe_sub, ModuleCat.hom_ofHom, Action.res_obj_V,
Subgroup.coe_subtype, lmapDomain_apply, Finsupp.coe_add, Pi.sub_apply, Pi.add_apply,
mapShortComplexH1_τ₂, ModuleCat.ofHom_comp, Action.id_hom, ModuleCat.hom_id,
mapRange.linearMap_id, ModuleCat.ofHom_id, Category.comp_id, LinearMap.coe_comp,
Function.comp_apply, coinvariantsShortComplex_X₁, Submodule.coe_subtype,
coinvariantsShortComplex_f, MonoidHom.coe_id, lmapDomain_id, subtype_hom, Category.id_comp,
mapRange.linearMap_apply, map_sub, map_add, ← sub_add, ← sub_sub, sub_add_eq_add_sub,
add_sub_cancel, mapDomain_add, b]
/- So we claim that `α + Z` is an element of `Z₁(S, A)` which differs from `x` by a boundary in
`Z₁(G, A)`. -/
use H1π _ ⟨α + Z, ?_⟩
/- Indeed, by `hαZ`, `d(W + δ)` is the desired boundary: -/
· simp only [H1CoresCoinf_X₂, H1CoresCoinf_X₁, H1CoresCoinf_f, H1π_comp_map_apply]
refine (H1π_eq_iff _ _).2 ⟨W + δ, ?_⟩
simp only [hαZ, Action.res_obj_V, mapCycles₁_hom, ModuleCat.ofHom_comp, Subgroup.coe_subtype,
Action.id_hom, ModuleCat.hom_id, mapRange.linearMap_id, ModuleCat.ofHom_id, Category.comp_id,
ModuleCat.hom_ofHom, LinearMap.restrict_coe_apply, lmapDomain_apply]
/- And `α + Z` is a cycle, since `d(W + δ) + x` is. -/
· rw [mem_cycles₁_iff]
have : x + d₂₁ A (W + δ) ∈ cycles₁ A := Submodule.add_mem _ x.2 (d₂₁_apply_mem_cycles₁ _)
rwa [eq_sub_iff_add_eq'.1 hαZ, mem_cycles₁_iff, sum_mapDomain_index_inj
Subtype.val_injective, sum_mapDomain_index_inj Subtype.val_injective] at this
end CoresCoinf
end H1
section H2
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map from the short complex
`(G × G × G →₀ A) --d₃₂--> (G × G →₀ A) --d₂₁--> (G →₀ A)` to
`(H × H × H →₀ B) --d₃₂--> (H × H →₀ B) --d₂₁--> (H →₀ B)`. -/
@[simps]
noncomputable def mapShortComplexH2 :
shortComplexH2 A ⟶ shortComplexH2 B where
τ₁ := chainsMap₃ f φ
τ₂ := chainsMap₂ f φ
τ₃ := chainsMap₁ f φ
comm₁₂ := by
simp only [shortComplexH2]
ext : 3
simpa [d₃₂, map_add, map_sub, ← map_inv]
using congr(Finsupp.single _ $((hom_comm_apply φ _ _).symm))
comm₂₃ := by
simp only [shortComplexH2]
ext : 3
simpa [d₂₁, map_add, map_sub, ← map_inv]
using congr(Finsupp.single _ $((hom_comm_apply φ _ _).symm))
@[simp]
theorem mapShortComplexH2_zero :
mapShortComplexH2 (A := A) (B := B) f 0 = 0 := by
refine ShortComplex.hom_ext _ _ ?_ ?_ ?_
all_goals
{ simp only [shortComplexH2]
ext
simp }
@[simp]
theorem mapShortComplexH2_id : mapShortComplexH2 (MonoidHom.id _) (𝟙 A) = 𝟙 _ := by
refine ShortComplex.hom_ext _ _ ?_ ?_ ?_
all_goals
{ simp only [shortComplexH2]
ext
simp }
theorem mapShortComplexH2_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k G} {B : Rep k H} {C : Rep k K} (f : G →* H) (g : H →* K)
(φ : A ⟶ (Action.res _ f).obj B) (ψ : B ⟶ (Action.res _ g).obj C) :
mapShortComplexH2 (g.comp f) (φ ≫ (Action.res _ f).map ψ) =
(mapShortComplexH2 f φ) ≫ (mapShortComplexH2 g ψ) := by
refine ShortComplex.hom_ext _ _ ?_ ?_ ?_
all_goals
{ simp only [shortComplexH2]
ext
simp [Prod.map] }
theorem mapShortComplexH2_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) :
mapShortComplexH2 (MonoidHom.id G) (φ ≫ ψ) =
mapShortComplexH2 (MonoidHom.id G) φ ≫ mapShortComplexH2 (MonoidHom.id G) ψ :=
mapShortComplexH2_comp (MonoidHom.id G) (MonoidHom.id G) _ _
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : A ⟶ Res(f)(B)`,
this is the induced map `Z₂(G, A) ⟶ Z₂(H, B)`. -/
noncomputable abbrev mapCycles₂ :
ModuleCat.of k (cycles₂ A) ⟶ ModuleCat.of k (cycles₂ B) :=
ShortComplex.cyclesMap' (mapShortComplexH2 f φ) (shortComplexH2 A).moduleCatLeftHomologyData
(shortComplexH2 B).moduleCatLeftHomologyData
lemma mapCycles₂_hom :
(mapCycles₂ f φ).hom = (chainsMap₂ f φ).hom.restrict (fun x _ => by
have := congr($((mapShortComplexH2 f φ).comm₂₃) x); simp_all [cycles₂, shortComplexH2]) :=
rfl
@[reassoc, elementwise]
lemma mapCycles₂_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k G} {B : Rep k H} {C : Rep k K} (f : G →* H) (g : H →* K)
(φ : A ⟶ (Action.res _ f).obj B) (ψ : B ⟶ (Action.res _ g).obj C) :
mapCycles₂ (g.comp f) (φ ≫ (Action.res _ f).map ψ) =
mapCycles₂ f φ ≫ mapCycles₂ g ψ := by
rw [← cyclesMap'_comp, ← mapShortComplexH2_comp]
@[reassoc, elementwise]
theorem mapCycles₂_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) :
mapCycles₂ (MonoidHom.id G) (φ ≫ ψ) =
mapCycles₂ (MonoidHom.id G) φ ≫ mapCycles₂ (MonoidHom.id G) ψ :=
mapCycles₂_comp (MonoidHom.id G) (MonoidHom.id G) _ _
@[reassoc, elementwise]
lemma mapCycles₂_comp_i :
mapCycles₂ f φ ≫ (shortComplexH2 B).moduleCatLeftHomologyData.i =
(shortComplexH2 A).moduleCatLeftHomologyData.i ≫ chainsMap₂ f φ := by
simp
@[simp]
lemma coe_mapCycles₂ (x) :
(mapCycles₂ f φ x).1 = chainsMap₂ f φ x := rfl
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cyclesMap_comp_isoCycles₂_hom :
cyclesMap f φ 2 ≫ (isoCycles₂ B).hom = (isoCycles₂ A).hom ≫ mapCycles₂ f φ := by
simp [← cancel_mono (moduleCatLeftHomologyData (shortComplexH2 B)).i, mapShortComplexH2,
chainsMap_f_2_comp_chainsIso₂ f]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma H2π_comp_map :
H2π A ≫ map f φ 2 = mapCycles₂ f φ ≫ H2π B := by
simp [H2π, Iso.inv_comp_eq, ← cyclesMap_comp_isoCycles₂_hom_assoc]
end H2
variable (k G)
/-- The functor sending a representation to its complex of inhomogeneous chains. -/
@[simps]
noncomputable def chainsFunctor :
Rep k G ⥤ ChainComplex (ModuleCat k) ℕ where
obj A := inhomogeneousChains A
map f := chainsMap (MonoidHom.id _) f
map_id _ := chainsMap_id
map_comp φ ψ := chainsMap_comp (MonoidHom.id G) (MonoidHom.id G) φ ψ
instance : (chainsFunctor k G).PreservesZeroMorphisms where
/-- The functor sending a `G`-representation `A` to `Hₙ(G, A)`. -/
@[simps]
noncomputable def functor (n : ℕ) : Rep k G ⥤ ModuleCat k where
obj A := groupHomology A n
map {A B} φ := map (MonoidHom.id _) φ n
map_id A := by simp [map, groupHomology]
map_comp f g := by
simp only [← HomologicalComplex.homologyMap_comp, ← chainsMap_comp]
rfl
instance (n : ℕ) : (functor k G n).PreservesZeroMorphisms where
map_zero _ _ := by simp [map]
variable {G}
/-- Given a group homomorphism `f : G →* H` this sends `A : Rep k H` to the `n`th
"corestriction" map `Hₙ(G, Res(f)(A)) ⟶ Hₙ(H, A)` induced by `f` and the identity
map on `Res(f)(A)`. -/
@[simps]
noncomputable def coresNatTrans (n : ℕ) :
Action.res (ModuleCat k) f ⋙ functor k G n ⟶ functor k H n where
app X := map f (𝟙 _) n
naturality {X Y} φ := by simp [← cancel_epi (groupHomology.π _ n),
← HomologicalComplex.cyclesMap_comp_assoc, ← chainsMap_comp, congr (MonoidHom.id_comp _)
chainsMap, congr (MonoidHom.comp_id _) chainsMap, Category.id_comp
(X := (Action.res _ _).obj _)]
/-- Given a normal subgroup `S ≤ G`, this sends `A : Rep k G` to the `n`th "coinflation" map
`Hₙ(G, A) ⟶ Hₙ(G ⧸ S, A_S)` induced by the quotient maps `G →* G ⧸ S` and `A →ₗ A_S`. -/
@[simps]
noncomputable def coinfNatTrans (S : Subgroup G) [S.Normal] (n : ℕ) :
functor k G n ⟶ quotientToCoinvariantsFunctor k S ⋙ functor k (G ⧸ S) n where
app A := map (QuotientGroup.mk' S) (mkQ _ _ <| Coinvariants.le_comap_ker A.ρ S) n
naturality {X Y} φ := by
simp only [Functor.comp_map, functor_map, ← cancel_epi (groupHomology.π _ n),
HomologicalComplex.homologyπ_naturality_assoc, HomologicalComplex.homologyπ_naturality,
← HomologicalComplex.cyclesMap_comp_assoc, ← chainsMap_comp]
congr 1
end groupHomology |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupHomology/FiniteCyclic.lean | import Mathlib.RepresentationTheory.Homological.FiniteCyclic
import Mathlib.RepresentationTheory.Homological.GroupHomology.LowDegree
/-!
# Group homology of a finite cyclic group
Let `k` be a commutative ring, `G` a group and `A` a `k`-linear `G`-representation. Given
endomorphisms `φ, ψ : A ⟶ A` such that `φ ∘ ψ = ψ ∘ φ = 0`, denote by `Chains(A, φ, ψ)` the
periodic chain complex `... ⟶ A --φ--> A --ψ--> A --φ--> A --ψ--> A ⟶ 0`.
When `G` is finite and generated by `g : G`, then `P := Chains(k[G], N, ρ(g) - Id)` (with `ρ` the
left regular representation) is a projective resolution of `k` as a trivial representation.
In this file we show that for `A : Rep k G`, `(A ⊗ P)_G` is isomorphic to
`Chains(A, N, ρ_A(g) - Id)` as a complex of `k`-modules, and hence the homology of this complex
computes group homology.
## Main definitions
* `Rep.FiniteCyclicGroup.groupHomologyIso₀ A g hg`: given a finite cyclic group `G` generated by
`g`, and a representation `A : Rep k G`, this is an isomorphism `H₀(G, A) ≅ Coker(ρ_A(g) - Id)`.
* `Rep.FiniteCyclicGroup.groupHomologyIsoOdd A g hg i hi`: given a finite cyclic group `G`
generated by `g`, and a representation `A : Rep k G`, this is an isomorphism between `Hᵢ(G, A)`
and the homology of `A --N--> A --(ρ(g) - Id)--> A` for all odd `i`.
* `Rep.FiniteCyclicGroup.groupHomologyIsoEven A g hg i hi`: given a finite cyclic group `G`
generated by `g`, and a representation `A : Rep k G`, this is an isomorphism between `Hᵢ(G, A)`
and the homology of `A --(ρ(g) - Id)--> A --N--> A` for all positive even `i`.
-/
universe v u
open CategoryTheory Representation Finsupp Limits
namespace Rep.FiniteCyclicGroup
variable {k G : Type u} [CommRing k] [CommGroup G] [Fintype G] (A : Rep k G) (g : G)
open ModuleCat.MonoidalCategory in
/-- Given a finite cyclic group `G` generated by `g : G` and a `k`-linear `G`-representation `A`,
the period chain complex
`... ⟶ (A ⊗ₖ k[G])_G --⟦Id ⊗ N⟧--> (A ⊗ₖ k[G])_G --⟦Id ⊗ (ρ(g⁻¹) - 𝟙)⟧--> (A ⊗ₖ k[G])_G ⟶ 0`
is isomorphic as a complex in `ModuleCat k` to
`... ⟶ A --N--> A --(ρ(g) - 𝟙)--> A --N--> A --(ρ(g) - 𝟙)--> A ⟶ 0`. -/
@[simps!]
noncomputable def coinvariantsTensorResolutionIso (hg : ∀ x, x ∈ Subgroup.zpowers g) :
(resolution k g⁻¹ ((@Subgroup.zpowers_inv G ..).symm ▸ hg)).complex.coinvariantsTensorObj A ≅
moduleCatChainComplex A g :=
HomologicalComplex.Hom.isoOfComponents
(fun _ => (coinvariantsTprodLeftRegularLEquiv A.ρ).toModuleIso) fun i j h =>
coinvariantsTensor_hom_ext (LinearMap.ext fun a => lhom_ext' fun g => LinearMap.ext_ring (by
subst h
by_cases hj : Even (j + 1)
· simpa [hj, whiskerLeft_def, coinvariantsTensorMk,
tensorObj_carrier, ofCoinvariantsTprodLeftRegular, Representation.norm,
← Module.End.mul_apply, ← map_mul, mul_comm g⁻¹]
using Finset.sum_bijective _ (MulEquiv.inv G).bijective (by aesop) (by aesop)
· simp [hj, whiskerLeft_def, coinvariantsTensorMk, tensorObj_carrier,
← Module.End.mul_apply, ← map_mul, mul_comm g⁻¹]))
/-- Given a finite cyclic group `G` generated by `g` and `A : Rep k G`, `H₀(G, A)` is isomorphic
to the cokernel of `ρ(g) - Id(A)`. -/
noncomputable abbrev groupHomologyIso₀ (hg : ∀ x, x ∈ Subgroup.zpowers g) :
groupHomology A 0 ≅ ModuleCat.of k (_ ⧸ (LinearMap.range (applyAsHom A g - 𝟙 A).hom.hom)) :=
groupHomology.H0Iso A ≪≫ (Submodule.quotEquivOfEq _ _ (by
simp [Representation.FiniteCyclicGroup.coinvariantsKer_eq_range A.ρ g hg])).toModuleIso
variable [DecidableEq G]
/-- Given a finite cyclic group `G` generated by `g` and `A : Rep k G`, `Hᵢ(G, A)` is isomorphic
to the homology of the short complex of `k`-modules `A --(ρ(g) - 𝟙)--> A --N--> A` when `i` is
nonzero and even. -/
noncomputable def groupHomologyIsoEven
(hg : ∀ x, x ∈ Subgroup.zpowers g) (i : ℕ) [h₀ : NeZero i] (hi : Even i) :
groupHomology A i ≅ (subCompNormHom A g).homology :=
groupHomologyIso A i (resolution k g⁻¹ <| (@Subgroup.zpowers_inv G ..).symm ▸ hg) ≪≫
(HomologicalComplex.homologyMapIso (coinvariantsTensorResolutionIso A g hg) i) ≪≫
HomologicalComplex.alternatingConstHomologyIsoEven A.V (by ext; simp) (by ext; simp) _ (by aesop)
(by induction i generalizing h₀ with | zero => exact (NeZero.ne 0 rfl).elim | succ n _ => simp)
hi
/-- Given a finite cyclic group `G` generated by `g` and `A : Rep k G`, this is the quotient map
`Ker(N) ⟶ Ker(N)/Im(ρ(g) - Id(A)) ≅ Hᵢ(G, A)` for any nonzero even `i`. -/
noncomputable abbrev groupHomologyπEven
(hg : ∀ x, x ∈ Subgroup.zpowers g) (i : ℕ) [NeZero i] (hi : Even i) :
ModuleCat.of k (LinearMap.ker A.ρ.norm) ⟶ groupHomology A i :=
(ShortComplex.moduleCatCyclesIso <| subCompNormHom A g).inv ≫
ShortComplex.homologyπ _ ≫ (groupHomologyIsoEven A g hg i hi).inv
lemma groupHomologyπEven_eq_zero_iff (hg : ∀ x, x ∈ Subgroup.zpowers g)
(i : ℕ) [NeZero i] (hi : Even i) (x : LinearMap.ker A.ρ.norm) :
groupHomologyπEven A g hg i hi x = 0 ↔
x.1 ∈ LinearMap.range (applyAsHom A g - 𝟙 A).hom.hom := by
simp [groupHomologyπEven, map_eq_zero_iff _ ((ModuleCat.mono_iff_injective _).1 inferInstance),
ShortComplex.moduleCatToCycles, -LinearMap.mem_range, LinearMap.range_codRestrict]
lemma groupHomologyπEven_eq_iff (hg : ∀ x, x ∈ Subgroup.zpowers g)
(i : ℕ) [NeZero i] (hi : Even i) (x y : LinearMap.ker A.ρ.norm) :
groupHomologyπEven A g hg i hi x = groupHomologyπEven A g hg i hi y ↔
x.1 - y.1 ∈ LinearMap.range (applyAsHom A g - 𝟙 A).hom.hom := by
rw [← sub_eq_zero, ← map_sub, groupHomologyπEven_eq_zero_iff, AddSubgroupClass.coe_sub]
/-- Given a finite cyclic group `G` generated by `g` and `A : Rep k G`, `Hⁱ(G, A)` is isomorphic
to the homology of the short complex of `k`-modules `A --N--> A --(ρ(g) - 𝟙)--> A` when `i` is
odd. -/
noncomputable def groupHomologyIsoOdd (hg : ∀ x, x ∈ Subgroup.zpowers g) (i : ℕ) (hi : Odd i) :
groupHomology A i ≅ (normHomCompSub A g).homology :=
groupHomologyIso A i (resolution k g⁻¹ <| (@Subgroup.zpowers_inv G ..).symm ▸ hg) ≪≫
(HomologicalComplex.homologyMapIso (coinvariantsTensorResolutionIso A g hg) i) ≪≫
HomologicalComplex.alternatingConstHomologyIsoOdd A.V (by ext; simp) (by ext; simp) (by aesop)
(by simp) (by rcases hi with ⟨j, rfl⟩; simp) hi
/-- Given a finite cyclic group `G` generated by `g` and `A : Rep k G`, this is the quotient map
`Ker(ρ(g) - Id(A)) ⟶ Ker(ρ(g) - Id(A))/Im(N) ≅ Hᵢ(G, A)` for any odd `i`. -/
noncomputable abbrev groupHomologyπOdd (hg : ∀ x, x ∈ Subgroup.zpowers g) (i : ℕ) (hi : Odd i) :
ModuleCat.of k (LinearMap.ker (applyAsHom A g - 𝟙 A).hom.hom) ⟶ groupHomology A i :=
(ShortComplex.moduleCatCyclesIso <| normHomCompSub A g).inv ≫
ShortComplex.homologyπ _ ≫ (groupHomologyIsoOdd A g hg i hi).inv
lemma groupHomologyπOdd_eq_zero_iff (hg : ∀ x, x ∈ Subgroup.zpowers g)
(i : ℕ) (hi : Odd i) (x : LinearMap.ker (applyAsHom A g - 𝟙 A).hom.hom) :
groupHomologyπOdd A g hg i hi x = 0 ↔ x.1 ∈ LinearMap.range A.ρ.norm := by
simp [groupHomologyπOdd, map_eq_zero_iff _ ((ModuleCat.mono_iff_injective _).1 inferInstance),
ShortComplex.moduleCatToCycles, -LinearMap.mem_range, LinearMap.range_codRestrict]
lemma groupHomologyπOdd_eq_iff (g : G) (hg : ∀ x, x ∈ Subgroup.zpowers g)
(A : Rep k G) (i : ℕ) (hi : Odd i) (x y : LinearMap.ker (applyAsHom A g - 𝟙 A).hom.hom) :
groupHomologyπOdd A g hg i hi x = groupHomologyπOdd A g hg i hi y ↔
x.1 - y.1 ∈ LinearMap.range A.ρ.norm := by
rw [← sub_eq_zero, ← map_sub, groupHomologyπOdd_eq_zero_iff, AddSubgroupClass.coe_sub]
end FiniteCyclicGroup
end Rep |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupHomology/Basic.lean | import Mathlib.Algebra.Homology.ConcreteCategory
import Mathlib.RepresentationTheory.Coinvariants
import Mathlib.RepresentationTheory.Homological.Resolution
import Mathlib.Tactic.CategoryTheory.Slice
import Mathlib.CategoryTheory.Abelian.LeftDerived
/-!
# The group homology of a `k`-linear `G`-representation
Let `k` be a commutative ring and `G` a group. This file defines the group homology of
`A : Rep k G` to be the homology of the complex
$$\dots \to \bigoplus_{G^2} A \to \bigoplus_{G^1} A \to \bigoplus_{G^0} A$$
with differential $d_n$ sending $a\cdot (g_0, \dots, g_n)$ to
$$\rho(g_0^{-1})(a)\cdot (g_1, \dots, g_n)$$
$$+ \sum_{i = 0}^{n - 1}(-1)^{i + 1}a\cdot (g_0, \dots, g_ig_{i + 1}, \dots, g_n)$$
$$+ (-1)^{n + 1}a\cdot (g_0, \dots, g_{n - 1})$$ (where `ρ` is the representation attached to `A`).
We have a `k`-linear isomorphism
$\bigoplus_{G^n} A \cong (A \otimes_k \left(\bigoplus_{G^n} k[G]\right))_G$ given by
`Rep.coinvariantsTensorFreeLEquiv`. If we conjugate the $n$th differential in $(A \otimes_k P)_G$
by this isomorphism, where `P` is the bar resolution of `k` as a trivial `k`-linear
`G`-representation, then the resulting map agrees with the differential $d_n$ defined
above, a fact we prove.
Hence our $d_n$ squares to zero, and we get
$\mathrm{H}_n(G, A) \cong \mathrm{Tor}_n(A, k),$ where $\mathrm{Tor}$ is defined by deriving the
second argument of the functor $(A, B) \mapsto (A \otimes_k B)_G.$
To talk about homology in low degree, the file
`Mathlib/RepresentationTheory/Homological/GroupHomology/LowDegree.lean` provides API specialized to
`H₀`, `H₁`, `H₂`.
## Main definitions
* `Rep.Tor k G n`: the left-derived functors given by deriving the second argument of
$(A, B) \mapsto (A \otimes_k B)_G$.
* `groupHomology.inhomogeneousChains A`: a complex whose objects are
$\bigoplus_{G^n} A$ and whose homology is the group homology $\mathrm{H}_n(G, A).$
* `groupHomology.inhomogeneousChainsIso A`: an isomorphism between the above two complexes.
* `groupHomology A n`: this is $\mathrm{H}_n(G, A),$ defined as the $n$th homology of the
second complex, `inhomogeneousChains A`.
* `groupHomologyIsoTor A n`: an isomorphism $\mathrm{H}_n(G, A) \cong \mathrm{Tor}_n(A, k)$
induced by `inhomogeneousChainsIso A`.
## Implementation notes
Group homology is typically stated for `G`-modules, or equivalently modules over the group ring
`ℤ[G].` However, `ℤ` can be generalized to any commutative ring `k`, which is what we use.
Moreover, we express `k[G]`-module structures on a module `k`-module `A` using the `Rep`
definition. We avoid using instances `Module (MonoidAlgebra k G) A` so that we do not run into
possible scalar action diamonds.
Note that the existing definition of `Tor` in `Mathlib.CategoryTheory.Monoidal.Tor` is for monoidal
categories, and the bifunctor we need to derive here maps to `ModuleCat k`. Hence we define
`Rep.Tor k G n` by instead left-deriving the second argument of `Rep.coinvariantsTensor k G`:
$(A, B) \mapsto (A \otimes_k B)_G$. The functor `Rep.coinvariantsTensor k G` is naturally
isomorphic to the functor sending `A, B` to `A ⊗[k[G]] B`, where we give `A` the `k[G]ᵐᵒᵖ`-module
structure defined by `g • a := A.ρ g⁻¹ a`, but currently mathlib's `TensorProduct` is only defined
for commutative rings.
## TODO
* Upgrading `groupHomologyIsoTor` to an isomorphism of derived functors.
-/
noncomputable section
universe u
open CategoryTheory CategoryTheory.Limits
variable (k G : Type u) [CommRing k] [Group G]
open MonoidalCategory Representation Finsupp
section Tor
variable {k G} in
/-- Given `A : Rep k G` and a chain complex `P` in `Rep k G`, this is the chain complex whose
`n`th object is `(A ⊗ Pₙ)_G`. -/
abbrev HomologicalComplex.coinvariantsTensorObj {α : Type*} [AddRightCancelSemigroup α] [One α]
(A : Rep k G) (P : ChainComplex (Rep k G) α) :
ChainComplex (ModuleCat k) α :=
(((Rep.coinvariantsTensor k G).obj A).mapHomologicalComplex _).obj P
namespace Rep
/-- The left-derived functors given by deriving the second argument of `A, B ↦ (A ⊗[k] B)_G`. -/
@[simps]
def Tor (n : ℕ) : Rep k G ⥤ Rep k G ⥤ ModuleCat k where
obj X := Functor.leftDerived ((coinvariantsTensor k G).obj X) n
map f := NatTrans.leftDerived ((coinvariantsTensor k G).map f) n
variable {k G} (A : Rep k G)
/-- `Tor` can be computed using a projective resolution. -/
abbrev torIso (A : Rep k G) {B : Rep k G} (P : ProjectiveResolution B) (n : ℕ) :
((Rep.Tor k G n).obj A).obj B ≅ (P.complex.coinvariantsTensorObj A).homology n :=
P.isoLeftDerivedObj _ n
/-- The higher `Tor` groups for `X` and `Y` are zero if `Y` is projective. -/
lemma isZero_Tor_succ_of_projective (X Y : Rep k G) [Projective Y] (n : ℕ) :
IsZero (((Tor k G (n + 1)).obj X).obj Y) :=
Functor.isZero_leftDerived_obj_projective_succ ..
/-- Given a `k`-linear `G`-representation `A`, this is the chain complex `(A ⊗[k] P)_G`, where
`P` is the bar resolution of `k` as a trivial representation. -/
@[deprecated "Use `(barComplex k G).coinvariantsTensorObj A` instead." (since := "2025-06-17")]
abbrev coinvariantsTensorBarResolution [DecidableEq G] :=
(((coinvariantsTensor k G).obj A).mapHomologicalComplex _).obj (barComplex k G)
end Rep
end Tor
namespace groupHomology
open Rep Finsupp
variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) (n : ℕ)
namespace inhomogeneousChains
/-- The differential in the complex of inhomogeneous chains used to calculate group homology. -/
def d : ModuleCat.of k ((Fin (n + 1) → G) →₀ A) ⟶ ModuleCat.of k ((Fin n → G) →₀ A) :=
ModuleCat.ofHom <| lsum (R := k) k fun g => lsingle (fun i => g i.succ) ∘ₗ A.ρ (g 0)⁻¹ +
Finset.univ.sum fun j : Fin (n + 1) =>
(-1 : k) ^ ((j : ℕ) + 1) • lsingle (Fin.contractNth j (· * ·) g)
variable {A n} in
@[simp]
theorem d_single (n : ℕ) (g : Fin (n + 1) → G) (a : A) :
d A n (single g a) = single (fun i => g i.succ) (A.ρ (g 0)⁻¹ a) +
Finset.univ.sum fun j : Fin (n + 1) =>
(-1 : k) ^ ((j : ℕ) + 1) • single (Fin.contractNth j (· * ·) g) a := by
simp [d]
open ModuleCat.MonoidalCategory
theorem d_eq [DecidableEq G] :
d A n = (coinvariantsTensorFreeLEquiv A (Fin (n + 1) → G)).toModuleIso.inv ≫
((barComplex k G).coinvariantsTensorObj A).d (n + 1) n ≫
(coinvariantsTensorFreeLEquiv A (Fin n → G)).toModuleIso.hom := by
ext : 3
simp [d_single (k := k), tensorObj_carrier, whiskerLeft_def, TensorProduct.tmul_add,
TensorProduct.tmul_sum, barComplex.d_single (k := k)]
end inhomogeneousChains
/-- Given a `k`-linear `G`-representation `A`, this is the complex of inhomogeneous chains
$$\dots \to \bigoplus_{G^1} A \to \bigoplus_{G^0} A \to 0$$
which calculates the group homology of `A`. -/
noncomputable abbrev inhomogeneousChains :
ChainComplex (ModuleCat k) ℕ :=
ChainComplex.of (fun n => ModuleCat.of k ((Fin n → G) →₀ A))
(fun n => inhomogeneousChains.d A n) fun n => by
classical
simp only [inhomogeneousChains.d_eq]
slice_lhs 3 4 => rw [Iso.hom_inv_id]
slice_lhs 2 4 => rw [Category.id_comp, ((barComplex k G).coinvariantsTensorObj A).d_comp_d]
simp
open inhomogeneousChains
variable {A n} in
@[ext]
theorem inhomogeneousChains.ext {M : ModuleCat k} {x y : (inhomogeneousChains A).X n ⟶ M}
(h : ∀ g, ModuleCat.ofHom (lsingle g) ≫ x = ModuleCat.ofHom (lsingle g) ≫ y) :
x = y := ModuleCat.hom_ext <| lhom_ext' fun g => ModuleCat.hom_ext_iff.1 (h g)
theorem inhomogeneousChains.d_def (n : ℕ) :
(inhomogeneousChains A).d (n + 1) n = d A n := by
simp [inhomogeneousChains]
theorem inhomogeneousChains.d_comp_d :
d A (n + 1) ≫ d A n = 0 := by
simpa [ChainComplex.of] using ((inhomogeneousChains A).d_comp_d (n + 2) (n + 1) n)
/-- Given a `k`-linear `G`-representation `A`, the complex of inhomogeneous chains is isomorphic
to `(A ⊗[k] P)_G`, where `P` is the bar resolution of `k` as a trivial `G`-representation. -/
def inhomogeneousChainsIso [DecidableEq G] :
inhomogeneousChains A ≅ (barComplex k G).coinvariantsTensorObj A := by
refine HomologicalComplex.Hom.isoOfComponents ?_ ?_
· intro i
apply (coinvariantsTensorFreeLEquiv A (Fin i → G)).toModuleIso.symm
rintro i j rfl
simp [d_eq, -LinearEquiv.toModuleIso_hom, -LinearEquiv.toModuleIso_inv]
/-- The `n`-cycles `Zₙ(G, A)` of a `k`-linear `G`-representation `A`, i.e. the kernel of the
differential `Cₙ(G, A) ⟶ Cₙ₋₁(G, A)` in the complex of inhomogeneous chains. -/
abbrev cycles (n : ℕ) : ModuleCat k := (inhomogeneousChains A).cycles n
open HomologicalComplex
variable {A} in
/-- When `m = 0` this makes a term of `cycles A 0` from any element of `A` (or more precisely
any element in the kernel of `d₀,₀ = 0`). When `m` is positive, this makes a term of `cycles A m`
from any element of the kernel of `dₘ,ₘ₋₁`. -/
abbrev cyclesMk (m n : ℕ) (h : (ComplexShape.down ℕ).next m = n) (f : (Fin m → G) →₀ A)
(hf : (inhomogeneousChains A).d m n f = 0) : cycles A m :=
(inhomogeneousChains A).cyclesMk f n h hf
/-- The natural inclusion of the `n`-cycles `Zₙ(G, A)` into the `n`-chains `Cₙ(G, A).` -/
abbrev iCycles (n : ℕ) : cycles A n ⟶ (inhomogeneousChains A).X n :=
(inhomogeneousChains A).iCycles n
variable {A} in
theorem iCycles_mk {m n : ℕ} (h : (ComplexShape.down ℕ).next m = n) (f : (Fin m → G) →₀ A)
(hf : (inhomogeneousChains A).d m n f = 0) :
iCycles A m (cyclesMk m n h f hf) = f := by
exact (inhomogeneousChains A).i_cyclesMk f n h hf
/-- This is the map from `i`-chains to `j`-cycles induced by the differential in the complex of
inhomogeneous chains. -/
abbrev toCycles (i j : ℕ) : (inhomogeneousChains A).X i ⟶ cycles A j :=
(inhomogeneousChains A).toCycles i j
end groupHomology
open groupHomology Rep
variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G)
/-- The group homology of a `k`-linear `G`-representation `A`, as the homology of its complex
of inhomogeneous chains. -/
def groupHomology (n : ℕ) : ModuleCat k :=
(inhomogeneousChains A).homology n
/-- The natural map from `n`-cycles to `n`th group homology for a `k`-linear
`G`-representation `A`. -/
abbrev groupHomology.π (n : ℕ) :
cycles A n ⟶ groupHomology A n :=
(inhomogeneousChains A).homologyπ n
variable {A} in
@[elab_as_elim]
theorem groupHomology_induction_on {n : ℕ}
{C : groupHomology A n → Prop} (x : groupHomology A n)
(h : ∀ x : cycles A n, C (π A n x)) : C x := by
rcases (ModuleCat.epi_iff_surjective (π A n)).1 inferInstance x with ⟨y, rfl⟩
exact h y
/-- The `n`th group homology of a `k`-linear `G`-representation `A` is isomorphic to
`Torₙ(A, k)` (taken in `Rep k G`), where `k` is a trivial `k`-linear `G`-representation. -/
def groupHomologyIsoTor [DecidableEq G] (n : ℕ) :
groupHomology A n ≅ ((Tor k G n).obj A).obj (Rep.trivial k G k) :=
isoOfQuasiIsoAt (HomotopyEquiv.ofIso (inhomogeneousChainsIso A)).hom n ≪≫
(torIso A (barResolution k G) n).symm
/-- The `n`th group homology of a `k`-linear `G`-representation `A` is isomorphic to
`Hₙ((A ⊗ P)_G)`, where `P` is any projective resolution of `k` as a trivial `k`-linear
`G`-representation. -/
def groupHomologyIso [DecidableEq G] (A : Rep k G) (n : ℕ)
(P : ProjectiveResolution (Rep.trivial k G k)) :
groupHomology A n ≅ (P.complex.coinvariantsTensorObj A).homology n :=
groupHomologyIsoTor A n ≪≫ torIso A P n
lemma isZero_groupHomology_succ_of_subsingleton [Subsingleton G] (n : ℕ) :
Limits.IsZero (groupHomology A (n + 1)) :=
(isZero_Tor_succ_of_projective A (Rep.trivial k G k) n).of_iso <| groupHomologyIsoTor _ _
end |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupHomology/Shapiro.lean | import Mathlib.CategoryTheory.Preadditive.Projective.Resolution
import Mathlib.RepresentationTheory.Homological.GroupHomology.Basic
import Mathlib.RepresentationTheory.Coinduced
import Mathlib.RepresentationTheory.Induced
/-!
# Shapiro's lemma for group homology
Given a commutative ring `k` and a subgroup `S ≤ G`,
the file `Mathlib/RepresentationTheory/Coinduced.lean` proves that
the functor `Coind_S^G : Rep k S ⥤ Rep k G` preserves epimorphisms.
Since `Res(S) : Rep k G ⥤ Rep k S` is left adjoint to `Coind_S^G`,
this means `Res(S)` preserves projective objects.
Since `Res(S)` is also exact,
given a projective resolution `P` of `k` as a trivial `k`-linear `G`-representation,
`Res(S)(P)` is a projective resolution of `k` as a trivial `k`-linear `S`-representation.
In `Mathlib/RepresentationTheory/Homological/GroupHomology/Induced.lean`,
given a `G`-representation `X`,
we define a natural isomorphism between the functors `Rep k S ⥤ ModuleCat k` sending `A` to
`(Ind_S^G A ⊗ X)_G` and to `(A ⊗ Res(S)(X))_S`. Hence a projective resolution `P` of `k` as a
trivial `G`-representation induces an isomorphism of complexes
`(Ind_S^G A ⊗ P)_G ≅ (A ⊗ Res(S)(P))_S`, and since the homology of these complexes calculate
group homology, we conclude Shapiro's lemma: `Hₙ(G, Ind_S^G(A)) ≅ Hₙ(S, A)` for all `n`.
## Main definitions
* `groupHomology.indIso A n`: Shapiro's lemma for group homology: an isomorphism
`Hₙ(G, Ind_S^G(A)) ≅ Hₙ(S, A)`, given a subgroup `S ≤ G` and an `S`-representation `A`.
-/
universe u
namespace groupHomology
open CategoryTheory Finsupp TensorProduct Rep Representation
variable {k G : Type u} [CommRing k] [Group G] (S : Subgroup G) (A : Rep k S)
/-- Given a projective resolution `P` of `k` as a `k`-linear `G`-representation, a subgroup
`S ≤ G`, and a `k`-linear `S`-representation `A`, this is an isomorphism of complexes
`(A ⊗ Res(S)(P))_S ≅ (Ind_S^G(A) ⊗ P)_G`. -/
noncomputable abbrev coinvariantsTensorResProjectiveResolutionIso
(P : ProjectiveResolution (Rep.trivial k G k)) :
((Action.res _ S.subtype).mapProjectiveResolution P).complex.coinvariantsTensorObj A ≅
P.complex.coinvariantsTensorObj (ind S.subtype A) :=
(NatIso.mapHomologicalComplex (coinvariantsTensorIndNatIso S.subtype A).symm _).app _
/-- Shapiro's lemma: given a subgroup `S ≤ G` and an `S`-representation `A`, we have
`Hₙ(G, Ind_S^G(A)) ≅ Hₙ(S, A).` -/
noncomputable def indIso [DecidableEq G] (A : Rep k S) (n : ℕ) :
groupHomology (ind S.subtype A) n ≅ groupHomology A n :=
(HomologicalComplex.homologyFunctor _ _ _).mapIso (inhomogeneousChainsIso (ind S.subtype A) ≪≫
(coinvariantsTensorResProjectiveResolutionIso S A (barResolution k G)).symm) ≪≫
(groupHomologyIso A n ((Action.res _ _).mapProjectiveResolution <| barResolution k G)).symm
end groupHomology |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupHomology/LowDegree.lean | import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
import Mathlib.GroupTheory.Abelianization.Defs
import Mathlib.RepresentationTheory.Homological.GroupHomology.Basic
import Mathlib.RepresentationTheory.Invariants
/-!
# The low-degree homology of a `k`-linear `G`-representation
Let `k` be a commutative ring and `G` a group. This file contains specialised API for
the cycles and group homology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2.
In `Mathlib/RepresentationTheory/Homological/GroupHomology/Basic.lean`, we define the `n`th group
homology of `A` to be the homology of a complex `inhomogeneousChains A`, whose objects are
`(Fin n →₀ G) → A`; this is unnecessarily unwieldy in low degree.
Given an additive abelian group `A` with an appropriate scalar action of `G`, we provide support
for turning a finsupp `f : G →₀ A` satisfying the 1-cycle identity into an element of the
`cycles₁` of the representation on `A` corresponding to the scalar action. We also do this for
0-boundaries, 1-boundaries, 2-cycles and 2-boundaries.
The file also contains an identification between the definitions in
`Mathlib/RepresentationTheory/Homological/GroupHomology/Basic.lean`, `groupHomology.cycles A n`, and
the `cyclesₙ` in this file for `n = 1, 2`, as well as an isomorphism
`groupHomology.cycles A 0 ≅ A.V`.
Moreover, we provide API for the natural maps `cyclesₙ A → Hn A` for `n = 1, 2`.
We show that when the representation on `A` is trivial, `H₁(G, A) ≃+ Gᵃᵇ ⊗[ℤ] A`.
## Main definitions
* `groupHomology.H0Iso A`: isomorphism between `H₀(G, A)` and the coinvariants `A_G` of the
`G`-representation on `A`.
* `groupHomology.H1π A`: epimorphism from the 1-cycles (i.e. `Z₁(G, A) := Ker(d₀ : (G →₀ A) → A`)
to `H₁(G, A)`.
* `groupHomology.H2π A`: epimorphism from the 2-cycles
(i.e. `Z₂(G, A) := Ker(d₁ : (G² →₀ A) → (G →₀ A)`) to `H₂(G, A)`.
* `groupHomology.H1AddEquivOfIsTrivial`: an isomorphism `H₁(G, A) ≃+ Gᵃᵇ ⊗[ℤ] A` when the
representation on `A` is trivial.
-/
universe v u
noncomputable section
open CategoryTheory Limits Representation Rep Finsupp
variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G)
namespace groupHomology
section Chains
/-- The 0th object in the complex of inhomogeneous chains of `A : Rep k G` is isomorphic
to `A` as a `k`-module. -/
def chainsIso₀ : (inhomogeneousChains A).X 0 ≅ A.V :=
(LinearEquiv.finsuppUnique _ _ _).toModuleIso
/-- The 1st object in the complex of inhomogeneous chains of `A : Rep k G` is isomorphic
to `G →₀ A` as a `k`-module. -/
def chainsIso₁ : (inhomogeneousChains A).X 1 ≅ ModuleCat.of k (G →₀ A) :=
(Finsupp.domLCongr (Equiv.funUnique (Fin 1) G)).toModuleIso
/-- The 2nd object in the complex of inhomogeneous chains of `A : Rep k G` is isomorphic
to `G² →₀ A` as a `k`-module. -/
def chainsIso₂ : (inhomogeneousChains A).X 2 ≅ ModuleCat.of k (G × G →₀ A) :=
(Finsupp.domLCongr (piFinTwoEquiv fun _ => G)).toModuleIso
/-- The 3rd object in the complex of inhomogeneous chains of `A : Rep k G` is isomorphic
to `G³ → A` as a `k`-module. -/
def chainsIso₃ : (inhomogeneousChains A).X 3 ≅ ModuleCat.of k (G × G × G →₀ A) :=
(Finsupp.domLCongr ((Fin.consEquiv _).symm.trans
((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G)))).toModuleIso
end Chains
section Differentials
/-- The 0th differential in the complex of inhomogeneous chains of `A : Rep k G`, as a
`k`-linear map `(G →₀ A) → A`. It is defined by `single g a ↦ ρ_A(g⁻¹)(a) - a.` -/
def d₁₀ : ModuleCat.of k (G →₀ A) ⟶ A.V :=
ModuleCat.ofHom <| lsum k fun g => A.ρ g⁻¹ - LinearMap.id
@[simp]
theorem d₁₀_single (g : G) (a : A) : d₁₀ A (single g a) = A.ρ g⁻¹ a - a := by
simp [d₁₀]
theorem d₁₀_single_one (a : A) : d₁₀ A (single 1 a) = 0 := by
simp [d₁₀]
theorem d₁₀_single_inv (g : G) (a : A) :
d₁₀ A (single g⁻¹ a) = -d₁₀ A (single g (A.ρ g a)) := by
simp [d₁₀]
theorem range_d₁₀_eq_coinvariantsKer :
LinearMap.range (d₁₀ A).hom = Coinvariants.ker A.ρ := by
symm
apply Submodule.span_eq_of_le
· rintro _ ⟨x, rfl⟩
use single x.1⁻¹ x.2
simp [d₁₀]
· rintro x ⟨y, hy⟩
induction y using Finsupp.induction generalizing x with
| zero => simp [← hy]
| single_add _ _ _ _ _ h =>
simpa [← hy, add_sub_add_comm, sum_add_index, d₁₀_single (G := G)]
using Submodule.add_mem _ (Coinvariants.mem_ker_of_eq _ _ _ rfl) (h rfl)
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma d₁₀_comp_coinvariantsMk : d₁₀ A ≫ (coinvariantsMk k G).app A = 0 := by
ext
simp [d₁₀]
/-- The 0th differential in the complex of inhomogeneous chains of a `G`-representation `A` as a
linear map into the `k`-submodule of `A` spanned by elements of the form
`ρ(g)(x) - x, g ∈ G, x ∈ A`. -/
def chains₁ToCoinvariantsKer :
ModuleCat.of k (G →₀ A) ⟶ ModuleCat.of k (Coinvariants.ker A.ρ) :=
ModuleCat.ofHom <| (d₁₀ A).hom.codRestrict _ <|
range_d₁₀_eq_coinvariantsKer A ▸ LinearMap.mem_range_self _
lemma chains₁ToCoinvariantsKer_surjective :
Function.Surjective (chains₁ToCoinvariantsKer A) := by
rintro ⟨x, hx⟩
rcases range_d₁₀_eq_coinvariantsKer A ▸ hx with ⟨y, hy⟩
use y, Subtype.ext hy
@[simp]
theorem d₁₀_eq_zero_of_isTrivial [A.IsTrivial] : d₁₀ A = 0 := by
ext
simp [d₁₀]
/-- The 1st differential in the complex of inhomogeneous chains of `A : Rep k G`, as a
`k`-linear map `(G² →₀ A) → (G →₀ A)`. It is defined by
`a·(g₁, g₂) ↦ ρ_A(g₁⁻¹)(a)·g₂ - a·g₁g₂ + a·g₁`. -/
def d₂₁ : ModuleCat.of k (G × G →₀ A) ⟶ ModuleCat.of k (G →₀ A) :=
ModuleCat.ofHom <| lsum k fun g => lsingle g.2 ∘ₗ A.ρ g.1⁻¹ - lsingle (g.1 * g.2) + lsingle g.1
variable {A}
@[simp]
lemma d₂₁_single (g : G × G) (a : A) :
d₂₁ A (single g a) = single g.2 (A.ρ g.1⁻¹ a) - single (g.1 * g.2) a + single g.1 a := by
simp [d₂₁]
lemma d₂₁_single_one_fst (g : G) (a : A) :
d₂₁ A (single (1, g) a) = single 1 a := by
simp [d₂₁]
lemma d₂₁_single_one_snd (g : G) (a : A) :
d₂₁ A (single (g, 1) a) = single 1 (A.ρ g⁻¹ a) := by
simp [d₂₁]
lemma d₂₁_single_inv_self_ρ_sub_self_inv (g : G) (a : A) :
d₂₁ A (single (g⁻¹, g) (A.ρ g⁻¹ a) - single (g, g⁻¹) a) =
single 1 a - single 1 (A.ρ g⁻¹ a) := by
simp only [map_sub, d₂₁_single (G := G), inv_inv, self_inv_apply, inv_mul_cancel,
mul_inv_cancel]
abel
lemma d₂₁_single_self_inv_ρ_sub_inv_self (g : G) (a : A) :
d₂₁ A (single (g, g⁻¹) (A.ρ g a) - single (g⁻¹, g) a) =
single 1 a - single 1 (A.ρ g a) := by
simp only [map_sub, d₂₁_single (G := G), inv_self_apply, mul_inv_cancel, inv_inv,
inv_mul_cancel]
abel
lemma d₂₁_single_ρ_add_single_inv_mul (g h : G) (a : A) :
d₂₁ A (single (g, h) (A.ρ g a) + single (g⁻¹, g * h) a) =
single g (A.ρ g a) + single g⁻¹ a := by
simp only [map_add, d₂₁_single (G := G), inv_self_apply, inv_inv, inv_mul_cancel_left]
abel
lemma d₂₁_single_inv_mul_ρ_add_single (g h : G) (a : A) :
d₂₁ A (single (g⁻¹, g * h) (A.ρ g⁻¹ a) + single (g, h) a) =
single g⁻¹ (A.ρ g⁻¹ a) + single g a := by
simp only [map_add, d₂₁_single (G := G), inv_inv, self_inv_apply, inv_mul_cancel_left]
abel
variable (A) in
/-- The 2nd differential in the complex of inhomogeneous chains of `A : Rep k G`, as a
`k`-linear map `(G³ →₀ A) → (G² →₀ A)`. It is defined by
`a·(g₁, g₂, g₃) ↦ ρ_A(g₁⁻¹)(a)·(g₂, g₃) - a·(g₁g₂, g₃) + a·(g₁, g₂g₃) - a·(g₁, g₂)`. -/
def d₃₂ : ModuleCat.of k (G × G × G →₀ A) ⟶ ModuleCat.of k (G × G →₀ A) :=
ModuleCat.ofHom <| lsum k fun g =>
lsingle (g.2.1, g.2.2) ∘ₗ A.ρ g.1⁻¹ - lsingle (g.1 * g.2.1, g.2.2) +
lsingle (g.1, g.2.1 * g.2.2) - lsingle (g.1, g.2.1)
@[simp]
lemma d₃₂_single (g : G × G × G) (a : A) :
d₃₂ A (single g a) = single (g.2.1, g.2.2) (A.ρ g.1⁻¹ a) - single (g.1 * g.2.1, g.2.2) a +
single (g.1, g.2.1 * g.2.2) a - single (g.1, g.2.1) a := by
simp [d₃₂]
lemma d₃₂_single_one_fst (g h : G) (a : A) :
d₃₂ A (single (1, g, h) a) = single (1, g * h) a - single (1, g) a := by
simp [d₃₂]
lemma d₃₂_single_one_snd (g h : G) (a : A) :
d₃₂ A (single (g, 1, h) a) = single (1, h) (A.ρ g⁻¹ a) - single (g, 1) a := by
simp [d₃₂]
lemma d₃₂_single_one_thd (g h : G) (a : A) :
d₃₂ A (single (g, h, 1) a) = single (h, 1) (A.ρ g⁻¹ a) - single (g * h, 1) a := by
simp [d₃₂]
variable (A)
/-- Let `C(G, A)` denote the complex of inhomogeneous chains of `A : Rep k G`. This lemma
says `d₁₀` gives a simpler expression for the 0th differential: that is, the following
square commutes:
```
C₁(G, A) --d 1 0--> C₀(G, A)
| |
| |
| |
v v
(G →₀ A) ----d₁₀----> A
```
where the vertical arrows are `chainsIso₁` and `chainsIso₀` respectively.
-/
theorem comp_d₁₀_eq :
(chainsIso₁ A).hom ≫ d₁₀ A = (inhomogeneousChains A).d 1 0 ≫ (chainsIso₀ A).hom :=
ModuleCat.hom_ext <| lhom_ext fun _ _ => by
simp [inhomogeneousChains.d_def, chainsIso₀, chainsIso₁, d₁₀_single (G := G),
Unique.eq_default (α := Fin 0 → G), sub_eq_add_neg, inhomogeneousChains.d_single (G := G)]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₁₀_comp_inv :
(chainsIso₁ A).inv ≫ (inhomogeneousChains A).d 1 0 = d₁₀ A ≫ (chainsIso₀ A).inv :=
(CommSq.horiz_inv ⟨comp_d₁₀_eq A⟩).w
/-- Let `C(G, A)` denote the complex of inhomogeneous chains of `A : Rep k G`. This lemma
says `d₂₁` gives a simpler expression for the 1st differential: that is, the following
square commutes:
```
C₂(G, A) --d 2 1--> C₁(G, A)
| |
| |
| |
v v
(G² →₀ A) --d₂₁--> (G →₀ A)
```
where the vertical arrows are `chainsIso₂` and `chainsIso₁` respectively.
-/
theorem comp_d₂₁_eq :
(chainsIso₂ A).hom ≫ d₂₁ A = (inhomogeneousChains A).d 2 1 ≫ (chainsIso₁ A).hom :=
ModuleCat.hom_ext <| lhom_ext fun _ _ => by
simp [inhomogeneousChains.d_def, chainsIso₁, add_assoc, chainsIso₂, d₂₁_single (G := G),
-Finsupp.domLCongr_apply, domLCongr_single, sub_eq_add_neg, Fin.contractNth,
inhomogeneousChains.d_single (G := G)]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₂₁_comp_inv :
(chainsIso₂ A).inv ≫ (inhomogeneousChains A).d 2 1 = d₂₁ A ≫ (chainsIso₁ A).inv :=
(CommSq.horiz_inv ⟨comp_d₂₁_eq A⟩).w
/-- Let `C(G, A)` denote the complex of inhomogeneous chains of `A : Rep k G`. This lemma
says `d₃₂` gives a simpler expression for the 2nd differential: that is, the following
square commutes:
```
C₃(G, A) --d 3 2--> C₂(G, A)
| |
| |
| |
v v
(G³ →₀ A) --d₃₂--> (G² →₀ A)
```
where the vertical arrows are `chainsIso₃` and `chainsIso₂` respectively.
-/
theorem comp_d₃₂_eq :
(chainsIso₃ A).hom ≫ d₃₂ A = (inhomogeneousChains A).d 3 2 ≫ (chainsIso₂ A).hom :=
ModuleCat.hom_ext <| lhom_ext fun _ _ => by
simp [inhomogeneousChains.d_def, chainsIso₂, pow_succ, chainsIso₃,
-domLCongr_apply, domLCongr_single, d₃₂, Fin.sum_univ_three,
Fin.contractNth, Fin.tail_def, sub_eq_add_neg, add_assoc,
inhomogeneousChains.d_single (G := G), add_rotate' (-(single (_ * _, _) _)),
add_left_comm (single (_, _ * _) _)]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₃₂_comp_inv :
(chainsIso₃ A).inv ≫ (inhomogeneousChains A).d 3 2 = d₃₂ A ≫ (chainsIso₂ A).inv :=
(CommSq.horiz_inv ⟨comp_d₃₂_eq A⟩).w
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem d₂₁_comp_d₁₀ : d₂₁ A ≫ d₁₀ A = 0 := by
ext x g
simp [d₁₀, d₂₁, sum_add_index', sum_sub_index, sub_sub_sub_comm, add_sub_add_comm]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem d₃₂_comp_d₂₁ : d₃₂ A ≫ d₂₁ A = 0 := by
simp [← cancel_mono (chainsIso₁ A).inv, ← eq_d₂₁_comp_inv, ← eq_d₃₂_comp_inv_assoc]
open ShortComplex
/-- The (exact) short complex `(G →₀ A) ⟶ A ⟶ A.ρ.coinvariants`. -/
@[simps! -isSimp f g]
def shortComplexH0 : ShortComplex (ModuleCat k) :=
mk _ _ (d₁₀_comp_coinvariantsMk A)
/-- The short complex `(G² →₀ A) --d₂₁--> (G →₀ A) --d₁₀--> A`. -/
@[simps! -isSimp f g]
def shortComplexH1 : ShortComplex (ModuleCat k) :=
mk _ _ (d₂₁_comp_d₁₀ A)
/-- The short complex `(G³ →₀ A) --d₃₂--> (G² →₀ A) --d₂₁--> (G →₀ A)`. -/
@[simps! -isSimp f g]
def shortComplexH2 : ShortComplex (ModuleCat k) :=
mk _ _ (d₃₂_comp_d₂₁ A)
end Differentials
section Cycles
/-- The 1-cycles `Z₁(G, A)` of `A : Rep k G`, defined as the kernel of the map
`(G →₀ A) → A` defined by `single g a ↦ ρ_A(g⁻¹)(a) - a`. -/
def cycles₁ : Submodule k (G →₀ A) := LinearMap.ker (d₁₀ A).hom
/-- The 2-cycles `Z₂(G, A)` of `A : Rep k G`, defined as the kernel of the map
`(G² →₀ A) → (G →₀ A)` defined by `a·(g₁, g₂) ↦ ρ_A(g₁⁻¹)(a)·g₂ - a·g₁g₂ + a·g₁`. -/
def cycles₂ : Submodule k (G × G →₀ A) := LinearMap.ker (d₂₁ A).hom
variable {A}
theorem mem_cycles₁_iff (x : G →₀ A) :
x ∈ cycles₁ A ↔ x.sum (fun g a => A.ρ g⁻¹ a) = x.sum (fun _ a => a) := by
change x.sum (fun g a => A.ρ g⁻¹ a - a) = 0 ↔ _
rw [sum_sub, sub_eq_zero]
theorem single_mem_cycles₁_iff (g : G) (a : A) :
single g a ∈ cycles₁ A ↔ A.ρ g a = a := by
simp [mem_cycles₁_iff, ← (A.ρ.apply_bijective g).1.eq_iff (a := A.ρ g⁻¹ a), eq_comm]
theorem single_mem_cycles₁_of_mem_invariants (g : G) (a : A) (ha : a ∈ A.ρ.invariants) :
single g a ∈ cycles₁ A :=
(single_mem_cycles₁_iff g a).2 (ha g)
theorem d₂₁_apply_mem_cycles₁ (x : G × G →₀ A) :
d₂₁ A x ∈ cycles₁ A :=
congr($(d₂₁_comp_d₁₀ A) x)
variable (A) in
theorem cycles₁_eq_top_of_isTrivial [A.IsTrivial] : cycles₁ A = ⊤ := by
rw [cycles₁, d₁₀_eq_zero_of_isTrivial, ModuleCat.hom_zero, LinearMap.ker_zero]
variable (A) in
/-- The natural inclusion `Z₁(G, A) ⟶ C₁(G, A)` is an isomorphism when the representation
on `A` is trivial. -/
def cycles₁IsoOfIsTrivial [A.IsTrivial] :
ModuleCat.of k (cycles₁ A) ≅ ModuleCat.of k (G →₀ A) :=
(LinearEquiv.ofTop _ (cycles₁_eq_top_of_isTrivial A)).toModuleIso
@[simp]
lemma cycles₁IsoOfIsTrivial_hom_apply [A.IsTrivial] (x : cycles₁ A) :
(cycles₁IsoOfIsTrivial A).hom x = x.1 := rfl
@[simp]
lemma cycles₁IsoOfIsTrivial_inv_apply [A.IsTrivial] (x : G →₀ A) :
((cycles₁IsoOfIsTrivial A).inv x).1 = x := rfl
theorem mem_cycles₂_iff (x : G × G →₀ A) :
x ∈ cycles₂ A ↔ x.sum (fun g a => single g.2 (A.ρ g.1⁻¹ a) + single g.1 a) =
x.sum (fun g a => single (g.1 * g.2) a) := by
change x.sum (fun g a => _) = 0 ↔ _
simp [sub_add_eq_add_sub, sub_eq_zero]
theorem single_mem_cycles₂_iff_inv (g : G × G) (a : A) :
single g a ∈ cycles₂ A ↔ single g.2 (A.ρ g.1⁻¹ a) + single g.1 a = single (g.1 * g.2) a := by
simp [mem_cycles₂_iff]
theorem single_mem_cycles₂_iff (g : G × G) (a : A) :
single g a ∈ cycles₂ A ↔
single (g.1 * g.2) (A.ρ g.1 a) = single g.2 a + single g.1 (A.ρ g.1 a) := by
rw [← (mapRange_injective (α := G) _ (map_zero _) (A.ρ.apply_bijective g.1⁻¹).1).eq_iff]
simp [mem_cycles₂_iff, mapRange_add, eq_comm]
theorem d₃₂_apply_mem_cycles₂ (x : G × G × G →₀ A) :
d₃₂ A x ∈ cycles₂ A :=
congr($(d₃₂_comp_d₂₁ A) x)
end Cycles
section Boundaries
/-- The 1-boundaries `B₁(G, A)` of `A : Rep k G`, defined as the image of the map
`(G² →₀ A) → (G →₀ A)` defined by `a·(g₁, g₂) ↦ ρ_A(g₁⁻¹)(a)·g₂ - a·g₁g₂ + a·g₁`. -/
def boundaries₁ : Submodule k (G →₀ A) :=
LinearMap.range (d₂₁ A).hom
/-- The 2-boundaries `B₂(G, A)` of `A : Rep k G`, defined as the image of the map
`(G³ →₀ A) → (G² →₀ A)` defined by
`a·(g₁, g₂, g₃) ↦ ρ_A(g₁⁻¹)(a)·(g₂, g₃) - a·(g₁g₂, g₃) + a·(g₁, g₂g₃) - a·(g₁, g₂)`. -/
def boundaries₂ : Submodule k (G × G →₀ A) :=
LinearMap.range (d₃₂ A).hom
variable {A}
section
lemma mem_cycles₁_of_mem_boundaries₁ (f : G →₀ A) (h : f ∈ boundaries₁ A) :
f ∈ cycles₁ A := by
rcases h with ⟨x, rfl⟩
exact d₂₁_apply_mem_cycles₁ x
variable (A) in
lemma boundaries₁_le_cycles₁ : boundaries₁ A ≤ cycles₁ A :=
mem_cycles₁_of_mem_boundaries₁
variable (A) in
/-- The natural inclusion `B₁(G, A) →ₗ[k] Z₁(G, A)`. -/
abbrev boundariesToCycles₁ : boundaries₁ A →ₗ[k] cycles₁ A :=
Submodule.inclusion (boundaries₁_le_cycles₁ A)
@[simp]
lemma boundariesToCycles₁_apply (x : boundaries₁ A) :
(boundariesToCycles₁ A x).1 = x.1 := rfl
end
theorem single_one_mem_boundaries₁ (a : A) :
single 1 a ∈ boundaries₁ A := by
use single (1, 1) a
simp [d₂₁]
theorem single_ρ_self_add_single_inv_mem_boundaries₁ (g : G) (a : A) :
single g (A.ρ g a) + single g⁻¹ a ∈ boundaries₁ A := by
rw [← d₂₁_single_ρ_add_single_inv_mul g 1]
exact Set.mem_range_self _
theorem single_inv_ρ_self_add_single_mem_boundaries₁ (g : G) (a : A) :
single g⁻¹ (A.ρ g⁻¹ a) + single g a ∈ boundaries₁ A := by
rw [← d₂₁_single_inv_mul_ρ_add_single g 1]
exact Set.mem_range_self _
section
lemma mem_cycles₂_of_mem_boundaries₂ (x : G × G →₀ A) (h : x ∈ boundaries₂ A) :
x ∈ cycles₂ A := by
rcases h with ⟨x, rfl⟩
exact d₃₂_apply_mem_cycles₂ x
variable (A) in
lemma boundaries₂_le_cycles₂ : boundaries₂ A ≤ cycles₂ A :=
mem_cycles₂_of_mem_boundaries₂
variable (A) in
/-- The natural inclusion `B₂(G, A) →ₗ[k] Z₂(G, A)`. -/
abbrev boundariesToCycles₂ : boundaries₂ A →ₗ[k] cycles₂ A :=
Submodule.inclusion (boundaries₂_le_cycles₂ A)
@[simp]
lemma boundariesToCycles₂_apply (x : boundaries₂ A) :
(boundariesToCycles₂ A x).1 = x.1 := rfl
end
lemma single_one_fst_sub_single_one_fst_mem_boundaries₂ (g h : G) (a : A) :
single (1, g * h) a - single (1, g) a ∈ boundaries₂ A := by
use single (1, g, h) a
simp [d₃₂]
lemma single_one_fst_sub_single_one_snd_mem_boundaries₂ (g h : G) (a : A) :
single (1, h) (A.ρ g⁻¹ a) - single (g, 1) a ∈ boundaries₂ A := by
use single (g, 1, h) a
simp [d₃₂]
lemma single_one_snd_sub_single_one_fst_mem_boundaries₂ (g h : G) (a : A) :
single (g, 1) (A.ρ g a) - single (1, h) a ∈ boundaries₂ A := by
use single (g, 1, h) (A.ρ g (-a))
simp [d₃₂_single (G := G)]
lemma single_one_snd_sub_single_one_snd_mem_boundaries₂ (g h : G) (a : A) :
single (h, 1) (A.ρ g⁻¹ a) - single (g * h, 1) a ∈ boundaries₂ A := by
use single (g, h, 1) a
simp [d₃₂]
end Boundaries
section IsCycle
section
variable {G A : Type*} [Mul G] [Inv G] [AddCommGroup A] [SMul G A]
/-- A finsupp `∑ aᵢ·gᵢ : G →₀ A` satisfies the 1-cycle condition if `∑ gᵢ⁻¹ • aᵢ = ∑ aᵢ`. -/
def IsCycle₁ (x : G →₀ A) : Prop := x.sum (fun g a => g⁻¹ • a) = x.sum (fun _ a => a)
/-- A finsupp `∑ aᵢ·(gᵢ, hᵢ) : G × G →₀ A` satisfies the 2-cycle condition if
`∑ (gᵢ⁻¹ • aᵢ)·hᵢ + aᵢ·gᵢ = ∑ aᵢ·gᵢhᵢ`. -/
def IsCycle₂ (x : G × G →₀ A) : Prop :=
x.sum (fun g a => single g.2 (g.1⁻¹ • a) + single g.1 a) =
x.sum (fun g a => single (g.1 * g.2) a)
end
section
variable {G A : Type*} [Group G] [AddCommGroup A] [DistribMulAction G A]
@[simp]
theorem single_isCycle₁_iff (g : G) (a : A) :
IsCycle₁ (single g a) ↔ g • a = a := by
rw [← (MulAction.bijective g⁻¹).1.eq_iff]
simp [IsCycle₁, eq_comm]
theorem single_isCycle₁_of_mem_fixedPoints
(g : G) (a : A) (ha : a ∈ MulAction.fixedPoints G A) :
IsCycle₁ (single g a) := by
simp_all [IsCycle₁]
theorem single_isCycle₂_iff_inv (g : G × G) (a : A) :
IsCycle₂ (single g a) ↔
single g.2 (g.1⁻¹ • a) + single g.1 a = single (g.1 * g.2) a := by
simp [IsCycle₂]
@[simp]
theorem single_isCycle₂_iff (g : G × G) (a : A) :
IsCycle₂ (single g a) ↔
single g.2 a + single g.1 (g.1 • a) = single (g.1 * g.2) (g.1 • a) := by
rw [← (Finsupp.mapRange_injective (α := G) _ (smul_zero _) (MulAction.bijective g.1⁻¹).1).eq_iff]
simp [mapRange_add, IsCycle₂]
end
end IsCycle
section IsBoundary
section
variable {G A : Type*} [Mul G] [Inv G] [AddCommGroup A] [SMul G A]
variable (G) in
/-- A term `x : A` satisfies the 0-boundary condition if there exists a finsupp
`∑ aᵢ·gᵢ : G →₀ A` such that `∑ gᵢ⁻¹ • aᵢ - aᵢ = x`. -/
def IsBoundary₀ (a : A) : Prop :=
∃ (x : G →₀ A), x.sum (fun g z => g⁻¹ • z - z) = a
/-- A finsupp `x : G →₀ A` satisfies the 1-boundary condition if there's a finsupp
`∑ aᵢ·(gᵢ, hᵢ) : G × G →₀ A` such that `∑ (gᵢ⁻¹ • aᵢ)·hᵢ - aᵢ·gᵢhᵢ + aᵢ·gᵢ = x`. -/
def IsBoundary₁ (x : G →₀ A) : Prop :=
∃ y : G × G →₀ A, y.sum
(fun g a => single g.2 (g.1⁻¹ • a) - single (g.1 * g.2) a + single g.1 a) = x
/-- A finsupp `x : G × G →₀ A` satisfies the 2-boundary condition if there's a finsupp
`∑ aᵢ·(gᵢ, hᵢ, jᵢ) : G × G × G →₀ A` such that
`∑ (gᵢ⁻¹ • aᵢ)·(hᵢ, jᵢ) - aᵢ·(gᵢhᵢ, jᵢ) + aᵢ·(gᵢ, hᵢjᵢ) - aᵢ·(gᵢ, hᵢ) = x.` -/
def IsBoundary₂ (x : G × G →₀ A) : Prop :=
∃ y : G × G × G →₀ A, y.sum (fun g a => single (g.2.1, g.2.2) (g.1⁻¹ • a) -
single (g.1 * g.2.1, g.2.2) a + single (g.1, g.2.1 * g.2.2) a - single (g.1, g.2.1) a) = x
end
section
variable {G A : Type*} [Group G] [AddCommGroup A] [DistribMulAction G A]
variable (G) in
theorem isBoundary₀_iff (a : A) :
IsBoundary₀ G a ↔ ∃ x : G →₀ A, x.sum (fun g z => g • z - z) = a := by
constructor
· rintro ⟨x, hx⟩
use x.sum (fun g a => single g (-(g⁻¹ • a)))
simp_all [sum_neg_index, sum_sum_index, neg_add_eq_sub]
· rintro ⟨x, hx⟩
use x.sum (fun g a => single g (-(g • a)))
simp_all [sum_neg_index, sum_sum_index, neg_add_eq_sub]
theorem isBoundary₁_iff (x : G →₀ A) :
IsBoundary₁ x ↔ ∃ y : G × G →₀ A, y.sum
(fun g a => single g.2 a - single (g.1 * g.2) (g.1 • a) + single g.1 (g.1 • a)) = x := by
constructor
· rintro ⟨y, hy⟩
use y.sum (fun g a => single g (g.1⁻¹ • a))
simp_all [sum_sum_index]
· rintro ⟨x, hx⟩
use x.sum (fun g a => single g (g.1 • a))
simp_all [sum_sum_index]
theorem isBoundary₂_iff (x : G × G →₀ A) :
IsBoundary₂ x ↔ ∃ y : G × G × G →₀ A, y.sum
(fun g a => single (g.2.1, g.2.2) a - single (g.1 * g.2.1, g.2.2) (g.1 • a) +
single (g.1, g.2.1 * g.2.2) (g.1 • a) - single (g.1, g.2.1) (g.1 • a)) = x := by
constructor
· rintro ⟨y, hy⟩
use y.sum (fun g a => single g (g.1⁻¹ • a))
simp_all [sum_sum_index]
· rintro ⟨x, hx⟩
use x.sum (fun g a => single g (g.1 • a))
simp_all [sum_sum_index]
end
end IsBoundary
section ofDistribMulAction
variable {k G A : Type u} [CommRing k] [Group G] [AddCommGroup A] [Module k A]
[DistribMulAction G A] [SMulCommClass G k A]
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a term
`x : A` satisfying the 0-boundary condition, this produces an element of the kernel of the quotient
map `A → A_G` for the representation on `A` induced by the `DistribMulAction`. -/
@[simps]
def coinvariantsKerOfIsBoundary₀ (x : A) (hx : IsBoundary₀ G x) :
Coinvariants.ker (Representation.ofDistribMulAction k G A) :=
⟨x, by
rcases (isBoundary₀_iff G x).1 hx with ⟨y, rfl⟩
exact Submodule.finsuppSum_mem _ _ _ _ fun g _ => Coinvariants.mem_ker_of_eq g (y g) _ rfl⟩
theorem isBoundary₀_of_mem_coinvariantsKer
(x : A) (hx : x ∈ Coinvariants.ker (Representation.ofDistribMulAction k G A)) :
IsBoundary₀ G x :=
Submodule.span_induction (fun _ ⟨g, hg⟩ => ⟨single g.1⁻¹ g.2, by simp_all⟩) ⟨0, by simp⟩
(fun _ _ _ _ ⟨X, hX⟩ ⟨Y, hY⟩ => ⟨X + Y, by simp_all [sum_add_index', add_sub_add_comm]⟩)
(fun r _ _ ⟨X, hX⟩ => ⟨r • X, by simp [← hX, sum_smul_index', smul_comm, smul_sub, smul_sum]⟩)
hx
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a finsupp
`x : G →₀ A` satisfying the 1-cycle condition, produces a 1-cycle for the representation on
`A` induced by the `DistribMulAction`. -/
@[simps]
def cyclesOfIsCycle₁ (x : G →₀ A) (hx : IsCycle₁ x) :
cycles₁ (Rep.ofDistribMulAction k G A) :=
⟨x, (mem_cycles₁_iff (A := Rep.ofDistribMulAction k G A) x).2 hx⟩
theorem isCycle₁_of_mem_cycles₁
(x : G →₀ A) (hx : x ∈ cycles₁ (Rep.ofDistribMulAction k G A)) :
IsCycle₁ x := by
simpa using (mem_cycles₁_iff (A := Rep.ofDistribMulAction k G A) x).1 hx
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a finsupp
`x : G →₀ A` satisfying the 1-boundary condition, produces a 1-boundary for the representation
on `A` induced by the `DistribMulAction`. -/
@[simps]
def boundariesOfIsBoundary₁ (x : G →₀ A) (hx : IsBoundary₁ x) :
boundaries₁ (Rep.ofDistribMulAction k G A) :=
⟨x, hx⟩
theorem isBoundary₁_of_mem_boundaries₁
(x : G →₀ A) (hx : x ∈ boundaries₁ (Rep.ofDistribMulAction k G A)) :
IsBoundary₁ x := hx
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a finsupp
`x : G × G →₀ A` satisfying the 2-cycle condition, produces a 2-cycle for the representation on
`A` induced by the `DistribMulAction`. -/
@[simps]
def cyclesOfIsCycle₂ (x : G × G →₀ A) (hx : IsCycle₂ x) :
cycles₂ (Rep.ofDistribMulAction k G A) :=
⟨x, (mem_cycles₂_iff (A := Rep.ofDistribMulAction k G A) x).2 hx⟩
theorem isCycle₂_of_mem_cycles₂
(x : G × G →₀ A) (hx : x ∈ cycles₂ (Rep.ofDistribMulAction k G A)) :
IsCycle₂ x := (mem_cycles₂_iff (A := Rep.ofDistribMulAction k G A) x).1 hx
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a finsupp
`x : G × G →₀ A` satisfying the 2-boundary condition, produces a 2-boundary for the
representation on `A` induced by the `DistribMulAction`. -/
@[simps]
def boundariesOfIsBoundary₂ (x : G × G →₀ A) (hx : IsBoundary₂ x) :
boundaries₂ (Rep.ofDistribMulAction k G A) :=
⟨x, hx⟩
theorem isBoundary₂_of_mem_boundaries₂
(x : G × G →₀ A) (hx : x ∈ boundaries₂ (Rep.ofDistribMulAction k G A)) :
IsBoundary₂ x := hx
end ofDistribMulAction
open ShortComplex
section cyclesIso₀
instance : Epi (shortComplexH0 A).g := inferInstanceAs <| Epi ((coinvariantsMk k G).app A)
lemma shortComplexH0_exact : (shortComplexH0 A).Exact := by
rw [ShortComplex.moduleCat_exact_iff]
intro x (hx : Coinvariants.mk _ _ = 0)
rw [Coinvariants.mk_eq_zero, ← range_d₁₀_eq_coinvariantsKer] at hx
rcases hx with ⟨x, hx, rfl⟩
use x
rfl
/-- The 0-cycles of the complex of inhomogeneous chains of `A` are isomorphic to `A`. -/
def cyclesIso₀ : cycles A 0 ≅ A.V :=
(inhomogeneousChains A).iCyclesIso _ 0 (by aesop) (by aesop) ≪≫ chainsIso₀ A
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cyclesIso₀_inv_comp_iCycles :
(cyclesIso₀ A).inv ≫ iCycles A 0 = (chainsIso₀ A).inv := by
simp [cyclesIso₀]
/-- The arrow `(G →₀ A) --d₁₀--> A` is isomorphic to the differential
`(inhomogeneousChains A).d 1 0` of the complex of inhomogeneous chains of `A`. -/
@[simps! hom_left hom_right inv_left inv_right]
def d₁₀ArrowIso :
Arrow.mk ((inhomogeneousChains A).d 1 0) ≅ Arrow.mk (d₁₀ A) :=
Arrow.isoMk (chainsIso₁ A) (chainsIso₀ A) (comp_d₁₀_eq A)
/-- The 0-cycles of the complex of inhomogeneous chains of `A` are isomorphic to
`A.ρ.coinvariants`, which is a simpler type. -/
def opcyclesIso₀ : (inhomogeneousChains A).opcycles 0 ≅ (coinvariantsFunctor k G).obj A :=
CokernelCofork.mapIsoOfIsColimit
((inhomogeneousChains A).opcyclesIsCokernel 1 0 (by simp)) (shortComplexH0_exact A).gIsCokernel
(d₁₀ArrowIso A)
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma pOpcycles_comp_opcyclesIso_hom :
(inhomogeneousChains A).pOpcycles 0 ≫ (opcyclesIso₀ A).hom =
(chainsIso₀ A).hom ≫ (coinvariantsMk k G).app A :=
CokernelCofork.π_mapOfIsColimit (φ := (d₁₀ArrowIso A).hom) _ _
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma coinvariantsMk_comp_opcyclesIso₀_inv :
(coinvariantsMk k G).app A ≫ (opcyclesIso₀ A).inv =
(chainsIso₀ A).inv ≫ (inhomogeneousChains A).pOpcycles 0 :=
(CommSq.vert_inv ⟨pOpcycles_comp_opcyclesIso_hom A⟩).w
lemma cyclesMk₀_eq (x : A) :
cyclesMk 0 0 (by simp) ((chainsIso₀ A).inv x) (by simp) = (cyclesIso₀ A).inv x :=
(ModuleCat.mono_iff_injective <| iCycles A 0).1 inferInstance <| by rw [iCycles_mk]; simp
end cyclesIso₀
section isoCycles₁
/-- The short complex `(G² →₀ A) --d₂₁--> (G →₀ A) --d₁₀--> A` is isomorphic to the 1st
short complex associated to the complex of inhomogeneous chains of `A`. -/
@[simps! hom inv]
def isoShortComplexH1 : (inhomogeneousChains A).sc 1 ≅ shortComplexH1 A :=
(inhomogeneousChains A).isoSc' 2 1 0 (by simp) (by simp) ≪≫
isoMk (chainsIso₂ A) (chainsIso₁ A) (chainsIso₀ A) (comp_d₂₁_eq A) (comp_d₁₀_eq A)
/-- The 1-cycles of the complex of inhomogeneous chains of `A` are isomorphic to
`cycles₁ A`, which is a simpler type. -/
def isoCycles₁ : cycles A 1 ≅ ModuleCat.of k (cycles₁ A) :=
cyclesMapIso' (isoShortComplexH1 A) ((inhomogeneousChains A).sc 1).leftHomologyData
(shortComplexH1 A).moduleCatLeftHomologyData
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCycles₁_hom_comp_i :
(isoCycles₁ A).hom ≫ (shortComplexH1 A).moduleCatLeftHomologyData.i =
iCycles A 1 ≫ (chainsIso₁ A).hom := by
simp [isoCycles₁, iCycles, HomologicalComplex.iCycles, ShortComplex.iCycles]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCycles₁_inv_comp_iCycles :
(isoCycles₁ A).inv ≫ iCycles A 1 =
(shortComplexH1 A).moduleCatLeftHomologyData.i ≫ (chainsIso₁ A).inv :=
(CommSq.horiz_inv ⟨isoCycles₁_hom_comp_i A⟩).w
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma toCycles_comp_isoCycles₁_hom :
toCycles A 2 1 ≫ (isoCycles₁ A).hom =
(chainsIso₂ A).hom ≫ (shortComplexH1 A).moduleCatLeftHomologyData.f' := by
simp [← cancel_mono (shortComplexH1 A).moduleCatLeftHomologyData.i, comp_d₂₁_eq,
shortComplexH1_f]
lemma cyclesMk₁_eq (x : cycles₁ A) :
cyclesMk 1 0 (by simp) ((chainsIso₁ A).inv x) (by simp) = (isoCycles₁ A).inv x :=
(ModuleCat.mono_iff_injective <| iCycles A 1).1 inferInstance <| by
rw [iCycles_mk]
simp only [ChainComplex.of_x, isoCycles₁_inv_comp_iCycles_apply]
rfl
end isoCycles₁
section isoCycles₂
/-- The short complex `(G³ →₀ A) --d₃₂--> (G² →₀ A) --d₂₁--> (G →₀ A)` is isomorphic to the 2nd
short complex associated to the complex of inhomogeneous chains of `A`. -/
@[simps! hom inv]
def isoShortComplexH2 : (inhomogeneousChains A).sc 2 ≅ shortComplexH2 A :=
(inhomogeneousChains A).isoSc' 3 2 1 (by simp) (by simp) ≪≫
isoMk (chainsIso₃ A) (chainsIso₂ A) (chainsIso₁ A) (comp_d₃₂_eq A) (comp_d₂₁_eq A)
/-- The 2-cycles of the complex of inhomogeneous chains of `A` are isomorphic to
`cycles₂ A`, which is a simpler type. -/
def isoCycles₂ : cycles A 2 ≅ ModuleCat.of k (cycles₂ A) :=
cyclesMapIso' (isoShortComplexH2 A) ((inhomogeneousChains A).sc 2).leftHomologyData
(shortComplexH2 A).moduleCatLeftHomologyData
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCycles₂_hom_comp_i :
(isoCycles₂ A).hom ≫ (shortComplexH2 A).moduleCatLeftHomologyData.i =
iCycles A 2 ≫ (chainsIso₂ A).hom := by
simp [isoCycles₂, iCycles, HomologicalComplex.iCycles, ShortComplex.iCycles]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCycles₂_inv_comp_iCycles :
(isoCycles₂ A).inv ≫ iCycles A 2 =
(shortComplexH2 A).moduleCatLeftHomologyData.i ≫ (chainsIso₂ A).inv :=
(CommSq.horiz_inv ⟨isoCycles₂_hom_comp_i A⟩).w
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma toCycles_comp_isoCycles₂_hom :
toCycles A 3 2 ≫ (isoCycles₂ A).hom =
(chainsIso₃ A).hom ≫ (shortComplexH2 A).moduleCatLeftHomologyData.f' := by
simp [← cancel_mono (shortComplexH2 A).moduleCatLeftHomologyData.i, comp_d₃₂_eq,
shortComplexH2_f]
lemma cyclesMk₂_eq (x : cycles₂ A) :
cyclesMk 2 1 (by simp) ((chainsIso₂ A).inv x) (by simp) = (isoCycles₂ A).inv x :=
(ModuleCat.mono_iff_injective <| iCycles A 2).1 inferInstance <| by
rw [iCycles_mk]
simp only [ChainComplex.of_x, isoCycles₂_inv_comp_iCycles_apply]
rfl
end isoCycles₂
section Homology
section H0
/-- Shorthand for the 0th group homology of a `k`-linear `G`-representation `A`, `H₀(G, A)`,
defined as the 0th homology of the complex of inhomogeneous chains of `A`. -/
abbrev H0 := groupHomology A 0
/-- The 0th group homology of `A`, defined as the 0th homology of the complex of inhomogeneous
chains, is isomorphic to the invariants of the representation on `A`. -/
def H0Iso : H0 A ≅ (coinvariantsFunctor k G).obj A :=
(ChainComplex.isoHomologyι₀ _) ≪≫ opcyclesIso₀ A
/-- The quotient map from `A` to `H₀(G, A)`. -/
def H0π : A.V ⟶ H0 A := (cyclesIso₀ A).inv ≫ π A 0
instance : Epi (H0π A) := by unfold H0π; infer_instance
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H0Iso_hom :
π A 0 ≫ (H0Iso A).hom = (cyclesIso₀ A).hom ≫ (coinvariantsMk k G).app A := by
simp [H0Iso, cyclesIso₀]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma coinvariantsMk_comp_H0Iso_inv :
(coinvariantsMk k G).app A ≫ (H0Iso A).inv = H0π A :=
(CommSq.vert_inv ⟨π_comp_H0Iso_hom A⟩).w
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma H0π_comp_H0Iso_hom :
H0π A ≫ (H0Iso A).hom = (coinvariantsMk k G).app A := by
simp [H0π]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cyclesIso₀_comp_H0π :
(cyclesIso₀ A).hom ≫ H0π A = π A 0 := by
simp [H0π]
@[elab_as_elim]
theorem H0_induction_on {C : H0 A → Prop} (x : H0 A)
(h : ∀ x : A, C (H0π A x)) : C x :=
groupHomology_induction_on x fun y => by simpa using h ((cyclesIso₀ A).hom y)
section IsTrivial
variable [A.IsTrivial]
/-- When the representation on `A` is trivial, then `H₀(G, A)` is all of `A.` -/
def H0IsoOfIsTrivial :
H0 A ≅ A.V :=
((inhomogeneousChains A).isoHomologyπ 1 0 (by simp) <| by
ext; simp [inhomogeneousChains.d_def, inhomogeneousChains.d_single (G := G),
Unique.eq_default (α := Fin 0 → G)]).symm ≪≫ cyclesIso₀ A
@[simp]
theorem H0IsoOfIsTrivial_inv_eq_π :
(H0IsoOfIsTrivial A).inv = H0π A := rfl
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem π_comp_H0IsoOfIsTrivial_hom :
π A 0 ≫ (H0IsoOfIsTrivial A).hom = (cyclesIso₀ A).hom := by
simp [H0IsoOfIsTrivial]
end IsTrivial
end H0
section H1
/-- Shorthand for the 1st group homology of a `k`-linear `G`-representation `A`, `H₁(G, A)`,
defined as the 1st homology of the complex of inhomogeneous chains of `A`. -/
abbrev H1 := groupHomology A 1
/-- The quotient map from the 1-cycles of `A`, as a submodule of `G →₀ A`, to `H₁(G, A)`. -/
def H1π : ModuleCat.of k (cycles₁ A) ⟶ H1 A :=
(isoCycles₁ A).inv ≫ π A 1
instance : Epi (H1π A) := by unfold H1π; infer_instance
variable {A}
lemma H1π_eq_zero_iff (x : cycles₁ A) : H1π A x = 0 ↔ x.1 ∈ boundaries₁ A := by
have h := leftHomologyπ_naturality'_assoc (isoShortComplexH1 A).inv
(shortComplexH1 A).moduleCatLeftHomologyData (leftHomologyData _)
((inhomogeneousChains A).sc 1).leftHomologyIso.hom
simp only [H1π, isoCycles₁, π, HomologicalComplex.homologyπ, homologyπ,
cyclesMapIso'_inv, leftHomologyπ, ← h, ← leftHomologyMapIso'_inv, ModuleCat.hom_comp,
LinearMap.coe_comp, Function.comp_apply, map_eq_zero_iff _
((ModuleCat.mono_iff_injective <| _).1 inferInstance)]
simp [LinearMap.range_codRestrict, boundaries₁, shortComplexH1, cycles₁]
lemma H1π_eq_iff (x y : cycles₁ A) :
H1π A x = H1π A y ↔ x.1 - y.1 ∈ boundaries₁ A := by
rw [← sub_eq_zero, ← map_sub, H1π_eq_zero_iff]
rfl
@[elab_as_elim]
theorem H1_induction_on {C : H1 A → Prop} (x : H1 A) (h : ∀ x : cycles₁ A, C (H1π A x)) :
C x :=
groupHomology_induction_on x fun y => by simpa [H1π] using h ((isoCycles₁ A).hom y)
variable (A)
/-- The 1st group homology of `A`, defined as the 1st homology of the complex of inhomogeneous
chains, is isomorphic to `cycles₁ A ⧸ boundaries₁ A`, which is a simpler type. -/
def H1Iso : H1 A ≅ (shortComplexH1 A).moduleCatLeftHomologyData.H :=
(leftHomologyIso _).symm ≪≫ (leftHomologyMapIso' (isoShortComplexH1 A) _ _)
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H1Iso_hom :
π A 1 ≫ (H1Iso A).hom = (isoCycles₁ A).hom ≫
(shortComplexH1 A).moduleCatLeftHomologyData.π := by
simp [H1Iso, isoCycles₁, π, HomologicalComplex.homologyπ, leftHomologyπ]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H1Iso_inv :
(shortComplexH1 A).moduleCatLeftHomologyData.π ≫ (H1Iso A).inv = H1π A :=
(CommSq.vert_inv ⟨π_comp_H1Iso_hom A⟩).w
section IsTrivial
variable [A.IsTrivial]
open TensorProduct
/-- If a `G`-representation on `A` is trivial, this is the natural map `Gᵃᵇ → A → H₁(G, A)`
sending `⟦g⟧, a` to `⟦single g a⟧`. -/
def mkH1OfIsTrivial : Additive (Abelianization G) →ₗ[ℤ] A →ₗ[ℤ] H1 A :=
AddMonoidHom.toIntLinearMap <| AddMonoidHom.toMultiplicativeRight.symm <| Abelianization.lift {
toFun g := Multiplicative.ofAdd (AddMonoidHom.toIntLinearMap (AddMonoidHomClass.toAddMonoidHom
((H1π A).hom ∘ₗ (cycles₁IsoOfIsTrivial A).inv.hom ∘ₗ lsingle g)))
map_one' := Multiplicative.toAdd.injective <|
LinearMap.ext fun _ => (H1π_eq_zero_iff _).2 <| single_one_mem_boundaries₁ _
map_mul' g h := Multiplicative.toAdd.injective <| LinearMap.ext fun a => by
simpa [← map_add] using ((H1π_eq_iff _ _).2 ⟨single (g, h) a, by
simp [cycles₁IsoOfIsTrivial, sub_add_eq_add_sub, add_comm (single h a),
d₂₁_single (A := A)]⟩).symm }
variable {A} in
@[simp]
lemma mkH1OfIsTrivial_apply (g : G) (a : A) :
mkH1OfIsTrivial A (Additive.ofMul (Abelianization.of g)) a =
H1π A ((cycles₁IsoOfIsTrivial A).inv (single g a)) := rfl
/-- If a `G`-representation on `A` is trivial, this is the natural map `H₁(G, A) → Gᵃᵇ ⊗[ℤ] A`
sending `⟦single g a⟧` to `⟦g⟧ ⊗ₜ a`. -/
def H1ToTensorOfIsTrivial : H1 A →ₗ[ℤ] (Additive <| Abelianization G) ⊗[ℤ] A :=
((QuotientAddGroup.lift _ ((Finsupp.liftAddHom fun g => AddMonoidHomClass.toAddMonoidHom
(TensorProduct.mk ℤ _ _ (Additive.ofMul (Abelianization.of g)))).comp
(cycles₁ A).toAddSubgroup.subtype) fun ⟨y, hy⟩ ⟨z, hz⟩ => AddMonoidHom.mem_ker.2 <| by
simp [← hz, d₂₁, sum_sum_index, sum_add_index', tmul_add, sum_sub_index, tmul_sub,
shortComplexH1]).comp <| AddMonoidHomClass.toAddMonoidHom (H1Iso A).hom.hom).toIntLinearMap
variable {A} in
@[simp]
lemma H1ToTensorOfIsTrivial_H1π_single (g : G) (a : A) :
H1ToTensorOfIsTrivial A (H1π A <| (cycles₁IsoOfIsTrivial A).inv (single g a)) =
Additive.ofMul (Abelianization.of g) ⊗ₜ[ℤ] a := by
simp only [H1ToTensorOfIsTrivial, H1π, AddMonoidHom.coe_toIntLinearMap, AddMonoidHom.coe_comp]
change QuotientAddGroup.lift _ _ _ ((H1Iso A).hom _) = _
simp [π_comp_H1Iso_hom_apply, Submodule.Quotient.mk, QuotientAddGroup.lift, AddCon.lift,
AddCon.liftOn, AddSubgroup.subtype, cycles₁IsoOfIsTrivial]
/-- If a `G`-representation on `A` is trivial, this is the group isomorphism between
`H₁(G, A) ≃+ Gᵃᵇ ⊗[ℤ] A` defined by `⟦single g a⟧ ↦ ⟦g⟧ ⊗ a`. -/
@[simps! -isSimp]
def H1AddEquivOfIsTrivial :
H1 A ≃+ (Additive <| Abelianization G) ⊗[ℤ] A :=
LinearEquiv.toAddEquiv <| LinearEquiv.ofLinear
(H1ToTensorOfIsTrivial A) (lift <| mkH1OfIsTrivial A)
(ext <| LinearMap.toAddMonoidHom_injective <| by
ext g a
simp [TensorProduct.mk_apply, TensorProduct.lift.tmul, mkH1OfIsTrivial_apply,
H1ToTensorOfIsTrivial_H1π_single g a])
(LinearMap.toAddMonoidHom_injective <|
(H1Iso A).symm.toLinearEquiv.toAddEquiv.comp_left_injective <|
QuotientAddGroup.addMonoidHom_ext _ <|
(cycles₁IsoOfIsTrivial A).symm.toLinearEquiv.toAddEquiv.comp_left_injective <| by
ext
simp only [H1ToTensorOfIsTrivial, Iso.toLinearEquiv, AddMonoidHom.coe_comp,
LinearMap.toAddMonoidHom_coe, LinearMap.coe_comp, AddMonoidHom.coe_toIntLinearMap]
change TensorProduct.lift _ (QuotientAddGroup.lift _ _ _ ((H1Iso A).hom _)) = _
simpa [AddSubgroup.subtype, cycles₁IsoOfIsTrivial_inv_apply (A := A),
-π_comp_H1Iso_inv_apply] using (π_comp_H1Iso_inv_apply A _).symm)
@[simp]
lemma H1AddEquivOfIsTrivial_single (g : G) (a : A) :
H1AddEquivOfIsTrivial A (H1π A <| (cycles₁IsoOfIsTrivial A).inv (single g a)) =
Additive.ofMul (Abelianization.of g) ⊗ₜ[ℤ] a := by
rw [H1AddEquivOfIsTrivial_apply, H1ToTensorOfIsTrivial_H1π_single g a]
@[simp]
lemma H1AddEquivOfIsTrivial_symm_tmul (g : G) (a : A) :
(H1AddEquivOfIsTrivial A).symm (Additive.ofMul (Abelianization.of g) ⊗ₜ[ℤ] a) =
H1π A ((cycles₁IsoOfIsTrivial A).inv <| single g a) := by
rfl
end IsTrivial
end H1
section H2
/-- Shorthand for the 2nd group homology of a `k`-linear `G`-representation `A`, `H₂(G, A)`,
defined as the 2nd homology of the complex of inhomogeneous chains of `A`. -/
abbrev H2 := groupHomology A 2
/-- The quotient map from the 2-cycles of `A`, as a submodule of `G × G →₀ A`, to `H₂(G, A)`. -/
def H2π : ModuleCat.of k (cycles₂ A) ⟶ H2 A :=
(isoCycles₂ A).inv ≫ π A 2
instance : Epi (H2π A) := by unfold H2π; infer_instance
variable {A}
lemma H2π_eq_zero_iff (x : cycles₂ A) : H2π A x = 0 ↔ x.1 ∈ boundaries₂ A := by
have h := leftHomologyπ_naturality'_assoc (isoShortComplexH2 A).inv
(shortComplexH2 A).moduleCatLeftHomologyData (leftHomologyData _)
((inhomogeneousChains A).sc 2).leftHomologyIso.hom
simp only [H2π, isoCycles₂, π, HomologicalComplex.homologyπ, homologyπ,
cyclesMapIso'_inv, leftHomologyπ, ← h, ← leftHomologyMapIso'_inv, ModuleCat.hom_comp,
LinearMap.coe_comp, Function.comp_apply, map_eq_zero_iff _
((ModuleCat.mono_iff_injective <| _).1 inferInstance)]
simp [LinearMap.range_codRestrict, boundaries₂, shortComplexH2, cycles₂]
lemma H2π_eq_iff (x y : cycles₂ A) :
H2π A x = H2π A y ↔ x.1 - y.1 ∈ boundaries₂ A := by
rw [← sub_eq_zero, ← map_sub, H2π_eq_zero_iff]
rfl
@[elab_as_elim]
theorem H2_induction_on {C : H2 A → Prop} (x : H2 A) (h : ∀ x : cycles₂ A, C (H2π A x)) :
C x :=
groupHomology_induction_on x (fun y => by simpa [H2π] using h ((isoCycles₂ A).hom y))
variable (A)
/-- The 2nd group homology of `A`, defined as the 2nd homology of the complex of inhomogeneous
chains, is isomorphic to `cycles₂ A ⧸ boundaries₂ A`, which is a simpler type. -/
def H2Iso : H2 A ≅ (shortComplexH2 A).moduleCatLeftHomologyData.H :=
(leftHomologyIso _).symm ≪≫ (leftHomologyMapIso' (isoShortComplexH2 A) _ _)
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H2Iso_hom :
π A 2 ≫ (H2Iso A).hom = (isoCycles₂ A).hom ≫
(shortComplexH2 A).moduleCatLeftHomologyData.π := by
simp [H2Iso, isoCycles₂, π, HomologicalComplex.homologyπ, leftHomologyπ]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H2Iso_inv :
(shortComplexH2 A).moduleCatLeftHomologyData.π ≫ (H2Iso A).inv = H2π A :=
(CommSq.vert_inv ⟨π_comp_H2Iso_hom A⟩).w
end H2
end Homology
end groupHomology |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupCohomology/LongExactSequence.lean | import Mathlib.Algebra.Homology.ConcreteCategory
import Mathlib.Algebra.Homology.HomologicalComplexAbelian
import Mathlib.RepresentationTheory.Homological.GroupCohomology.Functoriality
/-!
# Long exact sequence in group cohomology
Given a commutative ring `k` and a group `G`, this file shows that a short exact sequence of
`k`-linear `G`-representations `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` induces a short exact sequence of
complexes
`0 ⟶ inhomogeneousCochains X₁ ⟶ inhomogeneousCochains X₂ ⟶ inhomogeneousCochains X₃ ⟶ 0`.
Since the cohomology of `inhomogeneousCochains Xᵢ` is the group cohomology of `Xᵢ`, this allows us
to specialize API about long exact sequences to group cohomology.
## Main definitions
* `groupCohomology.δ hX i j hij`: the connecting homomorphism `Hⁱ(G, X₃) ⟶ Hʲ(G, X₁)` associated
to an exact sequence `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of representations.
-/
universe u v
namespace groupCohomology
open CategoryTheory ShortComplex
variable {k G : Type u} [CommRing k] [Group G]
{X : ShortComplex (Rep k G)} (hX : ShortExact X)
include hX
lemma map_cochainsFunctor_shortExact :
ShortExact (X.map (cochainsFunctor k G)) :=
HomologicalComplex.shortExact_of_degreewise_shortExact _ fun i => {
exact := by
have : LinearMap.range X.f.hom.hom = LinearMap.ker X.g.hom.hom :=
(hX.exact.map (forget₂ (Rep k G) (ModuleCat k))).moduleCat_range_eq_ker
simp [moduleCat_exact_iff_range_eq_ker, LinearMap.range_compLeft,
LinearMap.ker_compLeft, this]
mono_f := letI := hX.mono_f; cochainsMap_id_f_map_mono X.f i
epi_g := letI := hX.epi_g; cochainsMap_id_f_map_epi X.g i }
open HomologicalComplex.HomologySequence
/-- The short complex `Hⁱ(G, X₃) ⟶ Hʲ(G, X₁) ⟶ Hʲ(G, X₂)` associated to an exact
sequence of representations `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0`. -/
noncomputable abbrev mapShortComplex₁ {i j : ℕ} (hij : i + 1 = j) :=
(snakeInput (map_cochainsFunctor_shortExact hX) _ _ hij).L₂'
variable (X) in
/-- The short complex `Hⁱ(G, X₁) ⟶ Hⁱ(G, X₂) ⟶ Hⁱ(G, X₃)` associated to a short complex of
representations `X₁ ⟶ X₂ ⟶ X₃`. -/
noncomputable abbrev mapShortComplex₂ (i : ℕ) := X.map (functor k G i)
/-- The short complex `Hⁱ(G, X₂) ⟶ Hⁱ(G, X₃) ⟶ Hʲ(G, X₁)`. -/
noncomputable abbrev mapShortComplex₃ {i j : ℕ} (hij : i + 1 = j) :=
(snakeInput (map_cochainsFunctor_shortExact hX) _ _ hij).L₁'
/-- Exactness of `Hⁱ(G, X₃) ⟶ Hʲ(G, X₁) ⟶ Hʲ(G, X₂)`. -/
lemma mapShortComplex₁_exact {i j : ℕ} (hij : i + 1 = j) :
(mapShortComplex₁ hX hij).Exact :=
(map_cochainsFunctor_shortExact hX).homology_exact₁ i j hij
/-- Exactness of `Hⁱ(G, X₁) ⟶ Hⁱ(G, X₂) ⟶ Hⁱ(G, X₃)`. -/
lemma mapShortComplex₂_exact (i : ℕ) :
(mapShortComplex₂ X i).Exact :=
(map_cochainsFunctor_shortExact hX).homology_exact₂ i
/-- Exactness of `Hⁱ(G, X₂) ⟶ Hⁱ(G, X₃) ⟶ Hʲ(G, X₁)`. -/
lemma mapShortComplex₃_exact {i j : ℕ} (hij : i + 1 = j) :
(mapShortComplex₃ hX hij).Exact :=
(map_cochainsFunctor_shortExact hX).homology_exact₃ i j hij
/-- The connecting homomorphism `Hⁱ(G, X₃) ⟶ Hʲ(G, X₁)` associated to an exact sequence
`0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of representations. -/
noncomputable abbrev δ (i j : ℕ) (hij : i + 1 = j) :
groupCohomology X.X₃ i ⟶ groupCohomology X.X₁ j :=
(map_cochainsFunctor_shortExact hX).δ i j hij
open Limits
theorem epi_δ_of_isZero (n : ℕ) (h : IsZero (groupCohomology X.X₂ (n + 1))) :
Epi (δ hX n (n + 1) rfl) := SnakeInput.epi_δ _ h
theorem mono_δ_of_isZero (n : ℕ) (h : IsZero (groupCohomology X.X₂ n)) :
Mono (δ hX n (n + 1) rfl) := SnakeInput.mono_δ _ h
theorem isIso_δ_of_isZero (n : ℕ) (h : IsZero (groupCohomology X.X₂ n))
(hs : IsZero (groupCohomology X.X₂ (n + 1))) :
IsIso (δ hX n (n + 1) rfl) := SnakeInput.isIso_δ _ h hs
/-- Given an exact sequence of `G`-representations `0 ⟶ X₁ ⟶f X₂ ⟶g X₃ ⟶ 0`, this expresses an
`n + 1`-cochain `x : Gⁿ⁺¹ → X₁` such that `f ∘ x ∈ Bⁿ⁺¹(G, X₂)` as a cocycle.
Stated for readability of `δ_apply`. -/
noncomputable abbrev cocyclesMkOfCompEqD {i j : ℕ} {y : (Fin i → G) → X.X₂}
{x : (Fin j → G) → X.X₁} (hx : X.f.hom ∘ x = (inhomogeneousCochains X.X₂).d i j y) :
cocycles X.X₁ j :=
cocyclesMk x <| by simpa using
((map_cochainsFunctor_shortExact hX).d_eq_zero_of_f_eq_d_apply i j y x
(by simpa using hx) (j + 1))
theorem δ_apply {i j : ℕ} (hij : i + 1 = j)
-- Let `0 ⟶ X₁ ⟶f X₂ ⟶g X₃ ⟶ 0` be a short exact sequence of `G`-representations.
-- Let `z` be an `i`-cocycle for `X₃`
(z : (Fin i → G) → X.X₃) (hz : (inhomogeneousCochains X.X₃).d i j z = 0)
-- Let `y` be an `i`-cochain for `X₂` such that `g ∘ y = z`
(y : (Fin i → G) → X.X₂) (hy : (cochainsMap (MonoidHom.id G) X.g).f i y = z)
-- Let `x` be an `i + 1`-cochain for `X₁` such that `f ∘ x = d(y)`
(x : (Fin j → G) → X.X₁) (hx : X.f.hom ∘ x = (inhomogeneousCochains X.X₂).d i j y) :
-- Then `x` is an `i + 1`-cocycle and `δ z = x` in `Hⁱ⁺¹(X₁)`.
δ hX i j hij (π X.X₃ i <| cocyclesMk z (by subst hij; simpa using hz)) =
π X.X₁ j (cocyclesMkOfCompEqD hX hx) := by
exact (map_cochainsFunctor_shortExact hX).δ_apply i j hij z hz y hy x
(by simpa using hx) (j + 1) (by simp)
/-- Stated for readability of `δ₀_apply`. -/
theorem mem_cocycles₁_of_comp_eq_d₀₁
{y : X.X₂} {x : G → X.X₁} (hx : X.f.hom ∘ x = d₀₁ X.X₂ y) :
x ∈ cocycles₁ X.X₁ := by
apply Function.Injective.comp_left ((Rep.mono_iff_injective X.f).1 hX.2)
have := congr($((mapShortComplexH1 (MonoidHom.id G) X.f).comm₂₃.symm) x)
simp_all [shortComplexH1, LinearMap.compLeft]
@[deprecated (since := "2025-07-02")]
alias mem_oneCocycles_of_comp_eq_dZero := mem_cocycles₁_of_comp_eq_d₀₁
theorem δ₀_apply
-- Let `0 ⟶ X₁ ⟶f X₂ ⟶g X₃ ⟶ 0` be a short exact sequence of `G`-representations.
-- Let `z : X₃ᴳ` and `y : X₂` be such that `g(y) = z`.
(z : X.X₃.ρ.invariants) (y : X.X₂) (hy : X.g.hom y = z)
-- Let `x` be a 1-cochain for `X₁` such that `f ∘ x = d(y)`.
(x : G → X.X₁) (hx : X.f.hom ∘ x = d₀₁ X.X₂ y) :
-- Then `x` is a 1-cocycle and `δ z = x` in `H¹(X₁)`.
δ hX 0 1 rfl ((H0Iso X.X₃).inv z) = H1π X.X₁ ⟨x, mem_cocycles₁_of_comp_eq_d₀₁ hX hx⟩ := by
simpa [H0Iso, H1π, ← cocyclesMk₁_eq X.X₁, ← cocyclesMk₀_eq z] using
δ_apply hX rfl ((cochainsIso₀ X.X₃).inv z.1) (by simp) ((cochainsIso₀ X.X₂).inv y)
(by ext; simp [← hy, cochainsIso₀]) ((cochainsIso₁ X.X₁).inv x) <| by
ext g
simpa [← hx] using congr_fun (congr($((CommSq.vert_inv
⟨cochainsMap_f_1_comp_cochainsIso₁ (MonoidHom.id G) X.f⟩).w) x)) g
/-- Stated for readability of `δ₁_apply`. -/
theorem mem_cocycles₂_of_comp_eq_d₁₂
{y : G → X.X₂} {x : G × G → X.X₁} (hx : X.f.hom ∘ x = d₁₂ X.X₂ y) :
x ∈ cocycles₂ X.X₁ := by
apply Function.Injective.comp_left ((Rep.mono_iff_injective X.f).1 hX.2)
have := congr($((mapShortComplexH2 (MonoidHom.id G) X.f).comm₂₃.symm) x)
simp_all [shortComplexH2, LinearMap.compLeft]
@[deprecated (since := "2025-07-02")]
alias mem_twoCocycles_of_comp_eq_dOne := mem_cocycles₂_of_comp_eq_d₁₂
theorem δ₁_apply
-- Let `0 ⟶ X₁ ⟶f X₂ ⟶g X₃ ⟶ 0` be a short exact sequence of `G`-representations.
-- Let `z` be a 1-cocycle for `X₃` and `y` be a 1-cochain for `X₂` such that `g ∘ y = z`.
(z : cocycles₁ X.X₃) (y : G → X.X₂) (hy : X.g.hom ∘ y = z)
-- Let `x` be a 2-cochain for `X₁` such that `f ∘ x = d(y)`.
(x : G × G → X.X₁) (hx : X.f.hom ∘ x = d₁₂ X.X₂ y) :
-- Then `x` is a 2-cocycle and `δ z = x` in `H²(X₁)`.
δ hX 1 2 rfl (H1π X.X₃ z) = H2π X.X₁ ⟨x, mem_cocycles₂_of_comp_eq_d₁₂ hX hx⟩ := by
simpa [H1π, H2π, ← cocyclesMk₂_eq X.X₁, ← cocyclesMk₁_eq X.X₃] using
δ_apply hX rfl ((cochainsIso₁ X.X₃).inv z) (by simp [cocycles₁.d₁₂_apply z])
((cochainsIso₁ X.X₂).inv y) (by ext; simp [cochainsIso₁, ← hy])
((cochainsIso₂ X.X₁).inv x) <| by
ext g
simpa [← hx] using congr_fun (congr($((CommSq.vert_inv
⟨cochainsMap_f_2_comp_cochainsIso₂ (MonoidHom.id G) X.f⟩).w) x)) g
end groupCohomology |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupCohomology/Functoriality.lean | import Mathlib.RepresentationTheory.Homological.GroupCohomology.Basic
import Mathlib.RepresentationTheory.Homological.GroupCohomology.LowDegree
/-!
# Functoriality of group cohomology
Given a commutative ring `k`, a group homomorphism `f : G →* H`, a `k`-linear `H`-representation
`A`, a `k`-linear `G`-representation `B`, and a representation morphism `Res(f)(A) ⟶ B`, we get
a cochain map `inhomogeneousCochains A ⟶ inhomogeneousCochains B` and hence maps on
cohomology `Hⁿ(H, A) ⟶ Hⁿ(G, B)`.
We also provide extra API for these maps in degrees 0, 1, 2.
## Main definitions
* `groupCohomology.cochainsMap f φ` is the map `inhomogeneousCochains A ⟶ inhomogeneousCochains B`
induced by a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`.
* `groupCohomology.map f φ n` is the map `Hⁿ(H, A) ⟶ Hⁿ(G, B)` induced by a group
homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`.
* `groupCohomology.H1InfRes A S` is the short complex `H¹(G ⧸ S, A^S) ⟶ H¹(G, A) ⟶ H¹(S, A)` for
a normal subgroup `S ≤ G` and a `G`-representation `A`.
-/
universe v u
namespace groupCohomology
open Rep CategoryTheory Representation
variable {k G H : Type u} [CommRing k] [Group G] [Group H]
{A : Rep k H} {B : Rep k G} (f : G →* H) (φ : (Action.res _ f).obj A ⟶ B) (n : ℕ)
section
theorem congr {f₁ f₂ : G →* H} (h : f₁ = f₂) {φ : (Action.res _ f₁).obj A ⟶ B} {T : Type*}
(F : (f : G →* H) → (φ : (Action.res _ f).obj A ⟶ B) → T) :
F f₁ φ = F f₂ (h ▸ φ) := by
subst h
rfl
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is the chain map sending `x : Hⁿ → A` to `(g : Gⁿ) ↦ φ (x (f ∘ g))`. -/
@[simps! -isSimp f f_hom]
noncomputable def cochainsMap :
inhomogeneousCochains A ⟶ inhomogeneousCochains B where
f i := ModuleCat.ofHom <|
φ.hom.hom.compLeft (Fin i → G) ∘ₗ LinearMap.funLeft k A (fun x : Fin i → G => (f ∘ x))
comm' i j (hij : _ = _) := by
subst hij
ext
simpa [inhomogeneousCochains.d_hom_apply, Fin.comp_contractNth]
using (hom_comm_apply φ _ _).symm
@[simp]
lemma cochainsMap_id :
cochainsMap (MonoidHom.id _) (𝟙 A) = 𝟙 (inhomogeneousCochains A) := by
rfl
@[simp]
lemma cochainsMap_id_f_hom_eq_compLeft {A B : Rep k G} (f : A ⟶ B) (i : ℕ) :
((cochainsMap (MonoidHom.id G) f).f i).hom = f.hom.hom.compLeft _ := by
ext
rfl
@[deprecated (since := "2025-06-11")]
alias cochainsMap_id_f_eq_compLeft := cochainsMap_id_f_hom_eq_compLeft
@[reassoc]
lemma cochainsMap_comp {G H K : Type u} [Group G] [Group H]
[Group K] {A : Rep k K} {B : Rep k H} {C : Rep k G} (f : H →* K) (g : G →* H)
(φ : (Action.res _ f).obj A ⟶ B) (ψ : (Action.res _ g).obj B ⟶ C) :
cochainsMap (f.comp g) ((Action.res _ g).map φ ≫ ψ) =
cochainsMap f φ ≫ cochainsMap g ψ := by
rfl
@[reassoc]
lemma cochainsMap_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) :
cochainsMap (MonoidHom.id G) (φ ≫ ψ) =
cochainsMap (MonoidHom.id G) φ ≫ cochainsMap (MonoidHom.id G) ψ := by
rfl
@[simp]
lemma cochainsMap_zero : cochainsMap (A := A) (B := B) f 0 = 0 := by rfl
lemma cochainsMap_f_map_mono (hf : Function.Surjective f) [Mono φ] (i : ℕ) :
Mono ((cochainsMap f φ).f i) := by
simpa [ModuleCat.mono_iff_injective] using
((Rep.mono_iff_injective φ).1 inferInstance).comp_left.comp <|
LinearMap.funLeft_injective_of_surjective k A _ hf.comp_left
instance cochainsMap_id_f_map_mono {A B : Rep k G} (φ : A ⟶ B) [Mono φ] (i : ℕ) :
Mono ((cochainsMap (MonoidHom.id G) φ).f i) :=
cochainsMap_f_map_mono (MonoidHom.id G) φ (fun x => ⟨x, rfl⟩) i
lemma cochainsMap_f_map_epi (hf : Function.Injective f) [Epi φ] (i : ℕ) :
Epi ((cochainsMap f φ).f i) := by
simpa [ModuleCat.epi_iff_surjective] using
((Rep.epi_iff_surjective φ).1 inferInstance).comp_left.comp <|
LinearMap.funLeft_surjective_of_injective k A _ hf.comp_left
instance cochainsMap_id_f_map_epi {A B : Rep k G} (φ : A ⟶ B) [Epi φ] (i : ℕ) :
Epi ((cochainsMap (MonoidHom.id G) φ).f i) :=
cochainsMap_f_map_epi (MonoidHom.id G) φ (fun _ _ h => h) i
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is the induced map `Zⁿ(H, A) ⟶ Zⁿ(G, B)` sending `x : Hⁿ → A` to
`(g : Gⁿ) ↦ φ (x (f ∘ g))`. -/
noncomputable abbrev cocyclesMap (n : ℕ) :
groupCohomology.cocycles A n ⟶ groupCohomology.cocycles B n :=
HomologicalComplex.cyclesMap (cochainsMap f φ) n
@[simp]
lemma cocyclesMap_id : cocyclesMap (MonoidHom.id G) (𝟙 B) n = 𝟙 _ :=
HomologicalComplex.cyclesMap_id _ _
@[reassoc]
lemma cocyclesMap_comp {G H K : Type u} [Group G] [Group H]
[Group K] {A : Rep k K} {B : Rep k H} {C : Rep k G} (f : H →* K) (g : G →* H)
(φ : (Action.res _ f).obj A ⟶ B) (ψ : (Action.res _ g).obj B ⟶ C) (n : ℕ) :
cocyclesMap (f.comp g) ((Action.res _ g).map φ ≫ ψ) n =
cocyclesMap f φ n ≫ cocyclesMap g ψ n := by
simp [cocyclesMap, ← HomologicalComplex.cyclesMap_comp, ← cochainsMap_comp]
@[reassoc]
theorem cocyclesMap_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) (n : ℕ) :
cocyclesMap (MonoidHom.id G) (φ ≫ ψ) n =
cocyclesMap (MonoidHom.id G) φ n ≫ cocyclesMap (MonoidHom.id G) ψ n := by
simp [cocyclesMap, cochainsMap_id_comp, HomologicalComplex.cyclesMap_comp]
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is the induced map `Hⁿ(H, A) ⟶ Hⁿ(G, B)` sending `x : Hⁿ → A` to
`(g : Gⁿ) ↦ φ (x (f ∘ g))`. -/
noncomputable abbrev map (n : ℕ) :
groupCohomology A n ⟶ groupCohomology B n :=
HomologicalComplex.homologyMap (cochainsMap f φ) n
@[reassoc, elementwise]
theorem π_map (n : ℕ) :
π A n ≫ map f φ n = cocyclesMap f φ n ≫ π B n := by
simp [map, cocyclesMap]
@[simp]
lemma map_id : map (MonoidHom.id G) (𝟙 B) n = 𝟙 _ := HomologicalComplex.homologyMap_id _ _
@[reassoc]
lemma map_comp {G H K : Type u} [Group G] [Group H]
[Group K] {A : Rep k K} {B : Rep k H} {C : Rep k G} (f : H →* K) (g : G →* H)
(φ : (Action.res _ f).obj A ⟶ B) (ψ : (Action.res _ g).obj B ⟶ C) (n : ℕ) :
map (f.comp g) ((Action.res _ g).map φ ≫ ψ) n = map f φ n ≫ map g ψ n := by
simp [map, ← HomologicalComplex.homologyMap_comp, ← cochainsMap_comp]
@[reassoc]
theorem map_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) (n : ℕ) :
map (MonoidHom.id G) (φ ≫ ψ) n =
map (MonoidHom.id G) φ n ≫ map (MonoidHom.id G) ψ n := by
rw [map, cochainsMap_id_comp, HomologicalComplex.homologyMap_comp]
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is the induced map sending `x : H → A` to `(g : G) ↦ φ (x (f g))`. -/
noncomputable abbrev cochainsMap₁ :
ModuleCat.of k (H → A) ⟶ ModuleCat.of k (G → B) :=
ModuleCat.ofHom <| φ.hom.hom.compLeft G ∘ₗ LinearMap.funLeft k A f
@[deprecated (since := "2025-07-12")] alias f₁ := cochainsMap₁
@[deprecated (since := "2025-06-25")] noncomputable alias fOne := f₁
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is the induced map sending `x : H × H → A` to `(g₁, g₂ : G × G) ↦ φ (x (f g₁, f g₂))`. -/
noncomputable abbrev cochainsMap₂ :
ModuleCat.of k (H × H → A) ⟶ ModuleCat.of k (G × G → B) :=
ModuleCat.ofHom <| φ.hom.hom.compLeft (G × G) ∘ₗ LinearMap.funLeft k A (Prod.map f f)
@[deprecated (since := "2025-07-12")] alias f₂ := cochainsMap₂
@[deprecated (since := "2025-06-25")] noncomputable alias fTwo := f₂
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is the induced map sending `x : H × H × H → A` to
`(g₁, g₂, g₃ : G × G × G) ↦ φ (x (f g₁, f g₂, f g₃))`. -/
noncomputable abbrev cochainsMap₃ :
ModuleCat.of k (H × H × H → A) ⟶ ModuleCat.of k (G × G × G → B) :=
ModuleCat.ofHom <|
φ.hom.hom.compLeft (G × G × G) ∘ₗ LinearMap.funLeft k A (Prod.map f (Prod.map f f))
@[deprecated (since := "2025-07-12")] alias f₃ := cochainsMap₃
@[deprecated (since := "2025-06-25")] noncomputable alias fThree := f₃
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cochainsMap_f_0_comp_cochainsIso₀ :
(cochainsMap f φ).f 0 ≫ (cochainsIso₀ B).hom = (cochainsIso₀ A).hom ≫ φ.hom := by
ext x
simp only [cochainsMap_f, Unique.eq_default (f ∘ _)]
rfl
@[deprecated (since := "2025-06-25")]
alias cochainsMap_f_0_comp_zeroCochainsIso := cochainsMap_f_0_comp_cochainsIso₀
@[deprecated (since := "2025-05-09")]
alias cochainsMap_f_0_comp_zeroCochainsLequiv := cochainsMap_f_0_comp_cochainsIso₀
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cochainsMap_f_1_comp_cochainsIso₁ :
(cochainsMap f φ).f 1 ≫ (cochainsIso₁ B).hom = (cochainsIso₁ A).hom ≫ cochainsMap₁ f φ := rfl
@[deprecated (since := "2025-06-25")]
alias cochainsMap_f_1_comp_oneCochainsIso := cochainsMap_f_1_comp_cochainsIso₁
@[deprecated (since := "2025-05-09")]
alias cochainsMap_f_1_comp_oneCochainsLequiv := cochainsMap_f_1_comp_oneCochainsIso
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cochainsMap_f_2_comp_cochainsIso₂ :
(cochainsMap f φ).f 2 ≫ (cochainsIso₂ B).hom = (cochainsIso₂ A).hom ≫ cochainsMap₂ f φ := by
ext x g
change φ.hom (x _) = φ.hom (x _)
rcongr x
fin_cases x <;> rfl
@[deprecated (since := "2025-06-25")]
alias cochainsMap_f_2_comp_twoCochainsIso := cochainsMap_f_2_comp_cochainsIso₂
@[deprecated (since := "2025-05-09")]
alias cochainsMap_f_2_comp_twoCochainsLequiv := cochainsMap_f_2_comp_twoCochainsIso
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cochainsMap_f_3_comp_cochainsIso₃ :
(cochainsMap f φ).f 3 ≫ (cochainsIso₃ B).hom = (cochainsIso₃ A).hom ≫ cochainsMap₃ f φ := by
ext x g
change φ.hom (x _) = φ.hom (x _)
rcongr x
fin_cases x <;> rfl
@[deprecated (since := "2025-06-25")]
alias cochainsMap_f_3_comp_threeCochainsIso := cochainsMap_f_3_comp_cochainsIso₃
@[deprecated (since := "2025-05-09")]
alias cochainsMap_f_3_comp_threeCochainsLequiv := cochainsMap_f_3_comp_threeCochainsIso
end
open ShortComplex
section H0
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is induced map `Aᴴ ⟶ Bᴳ`. -/
@[deprecated (since := "2025-06-09")]
alias H0Map := map
@[deprecated (since := "2025-06-09")]
alias H0Map_id := map_id
@[deprecated (since := "2025-06-09")]
alias H0Map_comp := map_comp
@[deprecated (since := "2025-06-09")]
alias H0Map_id_comp := map_id_comp
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem map_H0Iso_hom_f :
map f φ 0 ≫ (H0Iso B).hom ≫ (shortComplexH0 B).f =
(H0Iso A).hom ≫ (shortComplexH0 A).f ≫ φ.hom := by
simp [← cancel_epi (π _ _)]
@[deprecated (since := "2025-06-09")]
alias H0Map_comp_f := map_H0Iso_hom_f
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem map_id_comp_H0Iso_hom {A B : Rep k G} (f : A ⟶ B) :
map (MonoidHom.id G) f 0 ≫ (H0Iso B).hom = (H0Iso A).hom ≫ (invariantsFunctor k G).map f := by
simp only [← cancel_mono (shortComplexH0 B).f, Category.assoc, map_H0Iso_hom_f]
rfl
@[deprecated (since := "2025-06-09")]
alias H0Map_id_eq_invariantsFunctor_map := map_id_comp_H0Iso_hom
instance mono_map_0_of_mono {A B : Rep k G} (f : A ⟶ B) [Mono f] :
Mono (map (MonoidHom.id G) f 0) where
right_cancellation g h hgh := by
simp only [← cancel_mono (H0Iso B).hom, Category.assoc, map_id_comp_H0Iso_hom] at hgh
simp_all [cancel_mono]
@[deprecated (since := "2025-06-09")]
alias mono_H0Map_of_mono := mono_map_0_of_mono
@[reassoc, elementwise]
theorem cocyclesMap_cocyclesIso₀_hom_f :
cocyclesMap f φ 0 ≫ (cocyclesIso₀ B).hom ≫ (shortComplexH0 B).f =
(cocyclesIso₀ A).hom ≫ (shortComplexH0 A).f ≫ φ.hom := by
simp
@[deprecated (since := "2025-07-02")]
alias cocyclesMap_zeroIsoCocycles_hom_f := cocyclesMap_cocyclesIso₀_hom_f
@[deprecated (since := "2025-06-12")]
alias cocyclesMap_comp_isoZeroCocycles_hom := cocyclesMap_zeroIsoCocycles_hom_f
end H0
section H1
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is the induced map from the short complex `A --d₀₁--> Fun(H, A) --d₁₂--> Fun(H × H, A)`
to `B --d₀₁--> Fun(G, B) --d₁₂--> Fun(G × G, B)`. -/
@[simps]
noncomputable def mapShortComplexH1 :
shortComplexH1 A ⟶ shortComplexH1 B where
τ₁ := φ.hom
τ₂ := cochainsMap₁ f φ
τ₃ := cochainsMap₂ f φ
comm₁₂ := by
ext x
funext g
simpa [shortComplexH1, d₀₁, cochainsMap₁] using (hom_comm_apply φ g x).symm
comm₂₃ := by
ext x
funext g
simpa [shortComplexH1, d₁₂, cochainsMap₁, cochainsMap₂] using (hom_comm_apply φ _ _).symm
@[simp]
theorem mapShortComplexH1_zero :
mapShortComplexH1 (A := A) (B := B) f 0 = 0 := by
rfl
@[simp]
theorem mapShortComplexH1_id :
mapShortComplexH1 (MonoidHom.id _) (𝟙 A) = 𝟙 _ := by
rfl
@[reassoc]
theorem mapShortComplexH1_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k K} {B : Rep k H} {C : Rep k G} (f : H →* K) (g : G →* H)
(φ : (Action.res _ f).obj A ⟶ B) (ψ : (Action.res _ g).obj B ⟶ C) :
mapShortComplexH1 (f.comp g) ((Action.res _ g).map φ ≫ ψ) =
mapShortComplexH1 f φ ≫ mapShortComplexH1 g ψ := rfl
@[reassoc]
theorem mapShortComplexH1_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) :
mapShortComplexH1 (MonoidHom.id G) (φ ≫ ψ) =
mapShortComplexH1 (MonoidHom.id G) φ ≫ mapShortComplexH1 (MonoidHom.id G) ψ := rfl
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is induced map `Z¹(H, A) ⟶ Z¹(G, B)`. -/
noncomputable abbrev mapCocycles₁ :
ModuleCat.of k (cocycles₁ A) ⟶ ModuleCat.of k (cocycles₁ B) :=
ShortComplex.cyclesMap' (mapShortComplexH1 f φ) (shortComplexH1 A).moduleCatLeftHomologyData
(shortComplexH1 B).moduleCatLeftHomologyData
@[deprecated (since := "2025-06-25")] alias mapOneCocycles := mapCocycles₁
@[reassoc, elementwise]
lemma mapCocycles₁_comp_i :
mapCocycles₁ f φ ≫ (shortComplexH1 B).moduleCatLeftHomologyData.i =
(shortComplexH1 A).moduleCatLeftHomologyData.i ≫ cochainsMap₁ f φ := by
simp
@[deprecated (since := "2025-06-25")] alias mapOneCocycles_comp_i := mapCocycles₁_comp_i
@[simp]
lemma coe_mapCocycles₁ (x) :
⇑(mapCocycles₁ f φ x) = cochainsMap₁ f φ x := rfl
@[deprecated (since := "2025-06-25")] alias coe_mapOneCocycles := coe_mapCocycles₁
@[deprecated (since := "2025-05-09")]
alias mapOneCocycles_comp_subtype := mapOneCocycles_comp_i
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cocyclesMap_comp_isoCocycles₁_hom :
cocyclesMap f φ 1 ≫ (isoCocycles₁ B).hom = (isoCocycles₁ A).hom ≫ mapCocycles₁ f φ := by
simp [← cancel_mono (moduleCatLeftHomologyData (shortComplexH1 B)).i, mapShortComplexH1,
cochainsMap_f_1_comp_cochainsIso₁ f]
@[deprecated (since := "2025-06-25")]
alias cocyclesMap_comp_isoOneCocycles_hom := cocyclesMap_comp_isoCocycles₁_hom
@[simp]
theorem mapCocycles₁_one (φ : (Action.res _ 1).obj A ⟶ B) :
mapCocycles₁ 1 φ = 0 := by
rw [← cancel_mono (moduleCatLeftHomologyData (shortComplexH1 B)).i, cyclesMap'_i]
refine ModuleCat.hom_ext (LinearMap.ext fun _ ↦ funext fun y => ?_)
simp [mapShortComplexH1, shortComplexH1, Pi.zero_apply y]
@[deprecated (since := "2025-06-25")] alias mapOneCocycles_one := mapCocycles₁_one
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is induced map `H¹(H, A) ⟶ H¹(G, B)`. -/
@[deprecated (since := "2025-06-09")]
alias H1Map := map
@[deprecated (since := "2025-6-09")]
alias H1Map_id := map_id
@[deprecated (since := "2025-06-09")]
alias H1Map_comp := map_comp
@[deprecated (since := "2025-06-09")]
alias H1Map_id_comp := map_id_comp
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma H1π_comp_map :
H1π A ≫ map f φ 1 = mapCocycles₁ f φ ≫ H1π B := by
simp [H1π, Iso.inv_comp_eq, ← cocyclesMap_comp_isoCocycles₁_hom_assoc]
@[deprecated (since := "2025-06-12")]
alias H1π_comp_H1Map := H1π_comp_map
@[simp]
theorem map₁_one (φ : (Action.res _ 1).obj A ⟶ B) :
map 1 φ 1 = 0 := by
simp [← cancel_epi (H1π _)]
@[deprecated (since := "2025-07-31")]
alias map_1_one := map₁_one
@[deprecated (since := "2025-06-09")]
alias H1Map_one := map_1_one
section InfRes
variable (A : Rep k G) (S : Subgroup G) [S.Normal]
/-- The short complex `H¹(G ⧸ S, A^S) ⟶ H¹(G, A) ⟶ H¹(S, A)`. -/
@[simps X₁ X₂ X₃ f g]
noncomputable def H1InfRes :
ShortComplex (ModuleCat k) where
X₁ := groupCohomology (A.quotientToInvariants S) 1
X₂ := groupCohomology A 1
X₃ := groupCohomology ((Action.res _ S.subtype).obj A) 1
f := map (QuotientGroup.mk' S) (subtype _ _ <| le_comap_invariants A.ρ S) 1
g := map S.subtype (𝟙 _) 1
zero := by rw [← map_comp, Category.comp_id, congr (QuotientGroup.mk'_comp_subtype S)
(fun f φ => map f φ 1), map₁_one]
/-- The inflation map `H¹(G ⧸ S, A^S) ⟶ H¹(G, A)` is a monomorphism. -/
instance : Mono (H1InfRes A S).f := by
rw [ModuleCat.mono_iff_injective, injective_iff_map_eq_zero]
intro x hx
induction x using H1_induction_on with | @h x =>
simp_all only [H1InfRes_X₂, H1InfRes_X₁, H1InfRes_f, H1π_comp_map_apply (QuotientGroup.mk' S)]
rcases (H1π_eq_zero_iff _).1 hx with ⟨y, hy⟩
refine (H1π_eq_zero_iff _).2 ⟨⟨y, fun s => ?_⟩, funext fun g => QuotientGroup.induction_on g
fun g => Subtype.ext <| by simpa [-SetLike.coe_eq_coe] using congr_fun hy g⟩
simpa [coe_mapCocycles₁ (x := x), sub_eq_zero, (QuotientGroup.eq_one_iff s.1).2 s.2] using
congr_fun hy s.1
/-- Given a `G`-representation `A` and a normal subgroup `S ≤ G`, the short complex
`H¹(G ⧸ S, A^S) ⟶ H¹(G, A) ⟶ H¹(S, A)` is exact. -/
lemma H1InfRes_exact : (H1InfRes A S).Exact := by
rw [moduleCat_exact_iff_ker_sub_range]
intro x hx
induction x using H1_induction_on with | @h x =>
simp_all only [H1InfRes_X₂, H1InfRes_X₃, H1InfRes_g, H1InfRes_X₁, LinearMap.mem_ker,
H1π_comp_map_apply S.subtype, H1InfRes_f]
rcases (H1π_eq_zero_iff _).1 hx with ⟨(y : A), hy⟩
have h1 := (mem_cocycles₁_iff x).1 x.2
have h2 : ∀ s ∈ S, x s = A.ρ s y - y :=
fun s hs => funext_iff.1 hy.symm ⟨s, hs⟩
refine ⟨H1π _ ⟨fun g => Quotient.liftOn' g (fun g => ⟨x.1 g - A.ρ g y + y, ?_⟩) ?_, ?_⟩, ?_⟩
· intro s
calc
_ = x (s * g) - x s - A.ρ s (A.ρ g y) + (x s + y) := by
simp [add_eq_of_eq_sub (h2 s s.2), sub_eq_of_eq_add (h1 s g)]
_ = x (g * (g⁻¹ * s * g)) - A.ρ g (A.ρ (g⁻¹ * s * g) y - y) - A.ρ g y + y := by
simp only [mul_assoc, mul_inv_cancel_left, map_mul, Module.End.mul_apply, map_sub,
Representation.self_inv_apply]
abel
_ = x g - A.ρ g y + y := by
simp [eq_sub_of_add_eq' (h1 g (g⁻¹ * s * g)).symm,
h2 (g⁻¹ * s * g) (Subgroup.Normal.conj_mem' ‹_› _ s.2 _)]
· intro g h hgh
have := congr(A.ρ g $(h2 (g⁻¹ * h) <| QuotientGroup.leftRel_apply.1 hgh))
simp_all [← sub_eq_add_neg, sub_eq_sub_iff_sub_eq_sub]
· rw [mem_cocycles₁_iff]
intro g h
induction g using QuotientGroup.induction_on with | @H g =>
induction h using QuotientGroup.induction_on with | @H h =>
apply Subtype.ext
simp [← QuotientGroup.mk_mul, h1 g h, sub_add_eq_add_sub, add_assoc]
· symm
simp only [H1π_comp_map_apply, H1π_eq_iff (A := A)]
use y
ext g
simp [coe_mapCocycles₁ (QuotientGroup.mk' S),
cocycles₁.coe_mk (A := A.quotientToInvariants S), ← sub_sub]
end InfRes
end H1
section H2
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is the induced map from the short complex
`Fun(H, A) --d₁₂--> Fun(H × H, A) --d₂₃--> Fun(H × H × H, A)` to
`Fun(G, B) --d₁₂--> Fun(G × G, B) --d₂₃--> Fun(G × G × G, B)`. -/
@[simps]
noncomputable def mapShortComplexH2 :
shortComplexH2 A ⟶ shortComplexH2 B where
τ₁ := cochainsMap₁ f φ
τ₂ := cochainsMap₂ f φ
τ₃ := cochainsMap₃ f φ
comm₁₂ := by
ext x
funext g
simpa [shortComplexH2, d₁₂, cochainsMap₁, cochainsMap₂] using (hom_comm_apply φ _ _).symm
comm₂₃ := by
ext x
funext g
simpa [shortComplexH2, d₂₃, cochainsMap₂, cochainsMap₃] using (hom_comm_apply φ _ _).symm
@[simp]
theorem mapShortComplexH2_zero :
mapShortComplexH2 (A := A) (B := B) f 0 = 0 := rfl
@[simp]
theorem mapShortComplexH2_id :
mapShortComplexH2 (MonoidHom.id _) (𝟙 A) = 𝟙 _ := by
rfl
@[reassoc]
theorem mapShortComplexH2_comp {G H K : Type u} [Group G] [Group H] [Group K]
{A : Rep k K} {B : Rep k H} {C : Rep k G} (f : H →* K) (g : G →* H)
(φ : (Action.res _ f).obj A ⟶ B) (ψ : (Action.res _ g).obj B ⟶ C) :
mapShortComplexH2 (f.comp g) ((Action.res _ g).map φ ≫ ψ) =
mapShortComplexH2 f φ ≫ mapShortComplexH2 g ψ := rfl
@[reassoc]
theorem mapShortComplexH2_id_comp {A B C : Rep k G} (φ : A ⟶ B) (ψ : B ⟶ C) :
mapShortComplexH2 (MonoidHom.id G) (φ ≫ ψ) =
mapShortComplexH2 (MonoidHom.id G) φ ≫ mapShortComplexH2 (MonoidHom.id G) ψ := rfl
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is induced map `Z²(H, A) ⟶ Z²(G, B)`. -/
noncomputable abbrev mapCocycles₂ :
ModuleCat.of k (cocycles₂ A) ⟶ ModuleCat.of k (cocycles₂ B) :=
ShortComplex.cyclesMap' (mapShortComplexH2 f φ) (shortComplexH2 A).moduleCatLeftHomologyData
(shortComplexH2 B).moduleCatLeftHomologyData
@[deprecated (since := "2025-06-25")] alias mapTwoCocycles := mapCocycles₂
@[reassoc, elementwise]
lemma mapCocycles₂_comp_i :
mapCocycles₂ f φ ≫ (shortComplexH2 B).moduleCatLeftHomologyData.i =
(shortComplexH2 A).moduleCatLeftHomologyData.i ≫ cochainsMap₂ f φ := by
simp
@[deprecated (since := "2025-06-25")] alias mapTwoCocycles_comp_i := mapCocycles₂_comp_i
@[simp]
lemma coe_mapCocycles₂ (x) :
⇑(mapCocycles₂ f φ x) = cochainsMap₂ f φ x := rfl
@[deprecated (since := "2025-06-25")] alias coe_mapTwoCocycles := coe_mapCocycles₂
@[deprecated (since := "2025-05-09")]
alias mapTwoCocycles_comp_subtype := mapTwoCocycles_comp_i
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cocyclesMap_comp_isoCocycles₂_hom :
cocyclesMap f φ 2 ≫ (isoCocycles₂ B).hom = (isoCocycles₂ A).hom ≫ mapCocycles₂ f φ := by
simp [← cancel_mono (moduleCatLeftHomologyData (shortComplexH2 B)).i, mapShortComplexH2,
cochainsMap_f_2_comp_cochainsIso₂ f]
@[deprecated (since := "2025-06-25")]
alias cocyclesMap_comp_isoTwoCocycles_hom := cocyclesMap_comp_isoCocycles₂_hom
/-- Given a group homomorphism `f : G →* H` and a representation morphism `φ : Res(f)(A) ⟶ B`,
this is induced map `H²(H, A) ⟶ H²(G, B)`. -/
@[deprecated (since := "2025-06-09")]
alias H2Map := map
@[deprecated (since := "2025-06-09")]
alias H2Map_id := map_id
@[deprecated (since := "2025-06-09")]
alias H2Map_comp := map_comp
@[deprecated (since := "2025-06-09")]
alias H2Map_id_comp := map_id_comp
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma H2π_comp_map :
H2π A ≫ map f φ 2 = mapCocycles₂ f φ ≫ H2π B := by
simp [H2π, Iso.inv_comp_eq, ← cocyclesMap_comp_isoCocycles₂_hom_assoc]
@[deprecated (since := "2025-06-12")]
alias H2π_comp_H2Map := H2π_comp_map
end H2
variable (k G)
/-- The functor sending a representation to its complex of inhomogeneous cochains. -/
@[simps]
noncomputable def cochainsFunctor : Rep k G ⥤ CochainComplex (ModuleCat k) ℕ where
obj A := inhomogeneousCochains A
map f := cochainsMap (MonoidHom.id _) f
map_id _ := cochainsMap_id
map_comp φ ψ := cochainsMap_comp (MonoidHom.id G) (MonoidHom.id G) φ ψ
instance : (cochainsFunctor k G).PreservesZeroMorphisms where
instance : (cochainsFunctor k G).Additive where
/-- The functor sending a `G`-representation `A` to `Hⁿ(G, A)`. -/
@[simps]
noncomputable def functor (n : ℕ) : Rep k G ⥤ ModuleCat k where
obj A := groupCohomology A n
map φ := map (MonoidHom.id _) φ n
map_id _ := HomologicalComplex.homologyMap_id _ _
map_comp _ _ := by
simp only [← HomologicalComplex.homologyMap_comp]
rfl
instance (n : ℕ) : (functor k G n).PreservesZeroMorphisms where
map_zero _ _ := by simp [map]
variable {G}
/-- Given a group homomorphism `f : G →* H`, this is a natural transformation between the functors
sending `A : Rep k H` to `Hⁿ(H, A)` and to `Hⁿ(G, Res(f)(A))`. -/
@[simps]
noncomputable def resNatTrans (n : ℕ) :
functor k H n ⟶ Action.res (ModuleCat k) f ⋙ functor k G n where
app X := map f (𝟙 _) n
naturality {X Y} φ := by simp [← cancel_epi (groupCohomology.π _ n),
← HomologicalComplex.cyclesMap_comp_assoc, ← cochainsMap_comp, congr (MonoidHom.id_comp _)
cochainsMap, congr (MonoidHom.comp_id _) cochainsMap, Category.id_comp
(X := (Action.res _ _).obj _)]
/-- Given a normal subgroup `S ≤ G`, this is a natural transformation between the functors
sending `A : Rep k G` to `Hⁿ(G ⧸ S, A^S)` and to `Hⁿ(G, A)`. -/
@[simps]
noncomputable def infNatTrans (S : Subgroup G) [S.Normal] (n : ℕ) :
quotientToInvariantsFunctor k S ⋙ functor k (G ⧸ S) n ⟶ functor k G n where
app A := map (QuotientGroup.mk' S) (subtype _ _ <| le_comap_invariants A.ρ S) n
naturality {X Y} φ := by
simp only [Functor.comp_map, functor_map, ← cancel_epi (groupCohomology.π _ n),
HomologicalComplex.homologyπ_naturality_assoc, HomologicalComplex.homologyπ_naturality,
← HomologicalComplex.cyclesMap_comp_assoc, ← cochainsMap_comp]
congr 1
end groupCohomology |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupCohomology/Basic.lean | import Mathlib.Algebra.Homology.Opposite
import Mathlib.Algebra.Homology.ConcreteCategory
import Mathlib.RepresentationTheory.Homological.Resolution
import Mathlib.Tactic.CategoryTheory.Slice
/-!
# The group cohomology of a `k`-linear `G`-representation
Let `k` be a commutative ring and `G` a group. This file defines the group cohomology of
`A : Rep k G` to be the cohomology of the complex
$$0 \to \mathrm{Fun}(G^0, A) \to \mathrm{Fun}(G^1, A) \to \mathrm{Fun}(G^2, A) \to \dots$$
with differential $d^n$ sending $f: G^n \to A$ to the function mapping $(g_0, \dots, g_n)$ to
$$\rho(g_0)(f(g_1, \dots, g_n))$$
$$+ \sum_{i = 0}^{n - 1} (-1)^{i + 1}\cdot f(g_0, \dots, g_ig_{i + 1}, \dots, g_n)$$
$$+ (-1)^{n + 1}\cdot f(g_0, \dots, g_{n - 1})$$ (where `ρ` is the representation attached to `A`).
We have a `k`-linear isomorphism
$\mathrm{Fun}(G^n, A) \cong \mathrm{Hom}(\bigoplus_{G^n} k[G], A)$, where
the right-hand side is morphisms in `Rep k G`, and $k[G]$ is equipped with the left regular
representation. If we conjugate the $n$th differential in $\mathrm{Hom}(P, A)$ by this isomorphism,
where `P` is the bar resolution of `k` as a trivial `k`-linear `G`-representation, then the
resulting map agrees with the differential $d^n$ defined above, a fact we prove.
This gives us for free a proof that our $d^n$ squares to zero. It also gives us an isomorphism
$\mathrm{H}^n(G, A) \cong \mathrm{Ext}^n(k, A),$ where $\mathrm{Ext}$ is taken in the category
`Rep k G`.
To talk about cohomology in low degree, please see the file
`Mathlib/RepresentationTheory/Homological/GroupCohomology/LowDegree.lean`, which provides API
specialized to `H⁰`, `H¹`, `H²`.
## Main definitions
* `groupCohomology.inhomogeneousCochains A`: a complex whose objects are
$\mathrm{Fun}(G^n, A)$ and whose cohomology is the group cohomology $\mathrm{H}^n(G, A).$
* `groupCohomology.inhomogeneousCochainsIso A`: an isomorphism between the above complex and the
complex $\mathrm{Hom}(P, A),$ where `P` is the bar resolution of `k` as a trivial resolution.
* `groupCohomology A n`: this is $\mathrm{H}^n(G, A),$ defined as the $n$th cohomology of
`inhomogeneousCochains A`.
* `groupCohomologyIsoExt A n`: an isomorphism $\mathrm{H}^n(G, A) \cong \mathrm{Ext}^n(k, A)$
(where $\mathrm{Ext}$ is taken in the category `Rep k G`) induced by `inhomogeneousCochainsIso A`.
## Implementation notes
Group cohomology is typically stated for `G`-modules, or equivalently modules over the group ring
`ℤ[G].` However, `ℤ` can be generalized to any commutative ring `k`, which is what we use.
Moreover, we express `k[G]`-module structures on a module `k`-module `A` using the `Rep`
definition. We avoid using instances `Module (MonoidAlgebra k G) A` so that we do not run into
possible scalar action diamonds.
## TODO
* Upgrading `groupCohomologyIsoExt` to an isomorphism of derived functors.
* Profinite cohomology.
Longer term:
* The Hochschild-Serre spectral sequence (this is perhaps a good toy example for the theory of
spectral sequences in general).
-/
noncomputable section
universe u
variable {k G : Type u} [CommRing k] {n : ℕ}
open CategoryTheory
namespace groupCohomology
variable [Monoid G]
/-- The complex `Hom(P, A)`, where `P` is the standard resolution of `k` as a trivial `k`-linear
`G`-representation. -/
@[deprecated "We now use `(Rep.barComplex k G).linearYonedaObj k A instead"
(since := "2025-06-08")]
abbrev linearYonedaObjResolution (A : Rep k G) : CochainComplex (ModuleCat.{u} k) ℕ :=
(Rep.standardComplex k G).linearYonedaObj k A
end groupCohomology
namespace inhomogeneousCochains
open Rep groupCohomology
/-- The differential in the complex of inhomogeneous cochains used to
calculate group cohomology. -/
@[simps! -isSimp]
def d [Monoid G] (A : Rep k G) (n : ℕ) :
ModuleCat.of k ((Fin n → G) → A) ⟶ ModuleCat.of k ((Fin (n + 1) → G) → A) :=
ModuleCat.ofHom
{ toFun f g :=
A.ρ (g 0) (f fun i => g i.succ) + Finset.univ.sum fun j : Fin (n + 1) =>
(-1 : k) ^ ((j : ℕ) + 1) • f (Fin.contractNth j (· * ·) g)
map_add' f g := by
ext
simp [Finset.sum_add_distrib, add_add_add_comm]
map_smul' r f := by
ext
simp [Finset.smul_sum, ← smul_assoc, mul_comm r] }
variable [Group G] [DecidableEq G] (A : Rep k G) (n : ℕ)
theorem d_eq :
d A n =
(freeLiftLEquiv (Fin n → G) A).toModuleIso.inv ≫
((barComplex k G).linearYonedaObj k A).d n (n + 1) ≫
(freeLiftLEquiv (Fin (n + 1) → G) A).toModuleIso.hom := by
ext
simp [d_hom_apply, map_add, barComplex.d_single (k := k)]
end inhomogeneousCochains
namespace groupCohomology
variable [Group G] (n) (A : Rep k G)
open inhomogeneousCochains Rep
/-- Given a `k`-linear `G`-representation `A`, this is the complex of inhomogeneous cochains
$$0 \to \mathrm{Fun}(G^0, A) \to \mathrm{Fun}(G^1, A) \to \mathrm{Fun}(G^2, A) \to \dots$$
which calculates the group cohomology of `A`. -/
noncomputable abbrev inhomogeneousCochains : CochainComplex (ModuleCat k) ℕ :=
CochainComplex.of (fun n => ModuleCat.of k ((Fin n → G) → A))
(fun n => inhomogeneousCochains.d A n) fun n => by
classical
simp only [d_eq]
slice_lhs 3 4 => { rw [Iso.hom_inv_id] }
slice_lhs 2 4 => { rw [Category.id_comp, ((barComplex k G).linearYonedaObj k A).d_comp_d] }
simp
variable {A n} in
@[ext]
theorem inhomogeneousCochains.ext {x y : (inhomogeneousCochains A).X n} (h : ∀ g, x g = y g) :
x = y := funext h
theorem inhomogeneousCochains.d_def (n : ℕ) :
(inhomogeneousCochains A).d n (n + 1) = d A n := by
simp
theorem inhomogeneousCochains.d_comp_d :
d A n ≫ d A (n + 1) = 0 := by
simpa [CochainComplex.of] using (inhomogeneousCochains A).d_comp_d n (n + 1) (n + 2)
/-- Given a `k`-linear `G`-representation `A`, the complex of inhomogeneous cochains is isomorphic
to `Hom(P, A)`, where `P` is the bar resolution of `k` as a trivial `G`-representation. -/
def inhomogeneousCochainsIso [DecidableEq G] :
inhomogeneousCochains A ≅ (barComplex k G).linearYonedaObj k A := by
refine HomologicalComplex.Hom.isoOfComponents
(fun i => (Rep.freeLiftLEquiv (Fin i → G) A).toModuleIso.symm) ?_
rintro i j (h : i + 1 = j)
subst h
simp [d_eq, -LinearEquiv.toModuleIso_hom, -LinearEquiv.toModuleIso_inv]
/-- The `n`-cocycles `Zⁿ(G, A)` of a `k`-linear `G`-representation `A`, i.e. the kernel of the
`n`th differential in the complex of inhomogeneous cochains. -/
abbrev cocycles (n : ℕ) : ModuleCat k := (inhomogeneousCochains A).cycles n
variable {A} in
/-- Make an `n`-cocycle out of an element of the kernel of the `n`th differential. -/
abbrev cocyclesMk {n : ℕ} (f : (Fin n → G) → A) (h : inhomogeneousCochains.d A n f = 0) :
cocycles A n :=
(inhomogeneousCochains A).cyclesMk f (n + 1) (by simp) (by simp [h])
/-- The natural inclusion of the `n`-cocycles `Zⁿ(G, A)` into the `n`-cochains `Cⁿ(G, A).` -/
abbrev iCocycles (n : ℕ) : cocycles A n ⟶ (inhomogeneousCochains A).X n :=
(inhomogeneousCochains A).iCycles n
/-- This is the map from `i`-cochains to `j`-cocycles induced by the differential in the complex of
inhomogeneous cochains. -/
abbrev toCocycles (i j : ℕ) : (inhomogeneousCochains A).X i ⟶ cocycles A j :=
(inhomogeneousCochains A).toCycles i j
variable {A} in
theorem iCocycles_mk {n : ℕ} (f : (Fin n → G) → A) (h : inhomogeneousCochains.d A n f = 0) :
iCocycles A n (cocyclesMk f h) = f := by
exact (inhomogeneousCochains A).i_cyclesMk (i := n) f (n + 1) (by simp) (by simp [h])
end groupCohomology
open groupCohomology
/-- The group cohomology of a `k`-linear `G`-representation `A`, as the cohomology of its complex
of inhomogeneous cochains. -/
def groupCohomology [Group G] (A : Rep k G) (n : ℕ) : ModuleCat k :=
(inhomogeneousCochains A).homology n
/-- The natural map from `n`-cocycles to `n`th group cohomology for a `k`-linear
`G`-representation `A`. -/
abbrev groupCohomology.π [Group G] (A : Rep k G) (n : ℕ) :
groupCohomology.cocycles A n ⟶ groupCohomology A n :=
(inhomogeneousCochains A).homologyπ n
@[deprecated (since := "2025-06-11")]
noncomputable alias groupCohomologyπ := groupCohomology.π
@[elab_as_elim]
theorem groupCohomology_induction_on [Group G] {A : Rep k G} {n : ℕ}
{C : groupCohomology A n → Prop} (x : groupCohomology A n)
(h : ∀ x : cocycles A n, C (π A n x)) : C x := by
rcases (ModuleCat.epi_iff_surjective (π A n)).1 inferInstance x with ⟨y, rfl⟩
exact h y
/-- The `n`th group cohomology of a `k`-linear `G`-representation `A` is isomorphic to
`Extⁿ(k, A)` (taken in `Rep k G`), where `k` is a trivial `k`-linear `G`-representation. -/
def groupCohomologyIsoExt [Group G] [DecidableEq G] (A : Rep k G) (n : ℕ) :
groupCohomology A n ≅ ((Ext k (Rep k G) n).obj (Opposite.op <| Rep.trivial k G k)).obj A :=
isoOfQuasiIsoAt (HomotopyEquiv.ofIso (inhomogeneousCochainsIso A)).hom n ≪≫
(Rep.barResolution.extIso k G A n).symm
/-- The `n`th group cohomology of a `k`-linear `G`-representation `A` is isomorphic to
`Hⁿ(Hom(P, A))`, where `P` is any projective resolution of `k` as a trivial `k`-linear
`G`-representation. -/
def groupCohomologyIso [Group G] [DecidableEq G] (A : Rep k G) (n : ℕ)
(P : ProjectiveResolution (Rep.trivial k G k)) :
groupCohomology A n ≅ (P.complex.linearYonedaObj k A).homology n :=
groupCohomologyIsoExt A n ≪≫ P.isoExt _ _
lemma isZero_groupCohomology_succ_of_subsingleton
[Group G] [Subsingleton G] (A : Rep k G) (n : ℕ) :
Limits.IsZero (groupCohomology A (n + 1)) :=
(isZero_Ext_succ_of_projective (Rep.trivial k G k) A n).of_iso <| groupCohomologyIsoExt _ _ |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupCohomology/Hilbert90.lean | import Mathlib.FieldTheory.Fixed
import Mathlib.RepresentationTheory.Homological.GroupCohomology.LowDegree
/-!
# Hilbert's Theorem 90
Let `L/K` be a finite extension of fields. Then this file proves Noether's generalization of
Hilbert's Theorem 90: that the 1st group cohomology $H^1(Aut_K(L), L^\times)$ is trivial. We state
it both in terms of $H^1$ and in terms of cocycles being coboundaries.
Hilbert's original statement was that if $L/K$ is Galois, and $Gal(L/K)$ is cyclic, generated
by an element `σ`, then for every `x : L` such that $N_{L/K}(x) = 1,$ there exists `y : L` such
that $x = y/σ(y).$ This can be deduced from the fact that the function $Gal(L/K) → L^\times$
sending $σ^i \mapsto xσ(x)σ^2(x)...σ^{i-1}(x)$ is a 1-cocycle. Alternatively, we can derive it by
analyzing the cohomology of finite cyclic groups in general.
Noether's generalization also holds for infinite Galois extensions.
## Main statements
* `groupCohomology.isMulCoboundary₁_of_isMulCocycle₁_of_aut_to_units`: Noether's generalization
of Hilbert's Theorem 90: for all $f: Aut_K(L) \to L^\times$ satisfying the 1-cocycle
condition, there exists `β : Lˣ` such that $g(β)/β = f(g)$ for all `g : Aut_K(L)`.
* `groupCohomology.H1ofAutOnUnitsUnique`: Noether's generalization of Hilbert's Theorem 90:
$H^1(Aut_K(L), L^\times)$ is trivial.
## Implementation notes
Given a commutative ring `k` and a group `G`, group cohomology is developed in terms of `k`-linear
`G`-representations on `k`-modules. Therefore stating Noether's generalization of Hilbert 90 in
terms of `H¹` requires us to turn the natural action of `Aut_K(L)` on `Lˣ` into a morphism
`Aut_K(L) →* (Additive Lˣ →ₗ[ℤ] Additive Lˣ)`. Thus we provide the non-`H¹` version too, as its
statement is clearer.
## TODO
* The original Hilbert's Theorem 90, deduced from the cohomology of general finite cyclic groups.
* Develop Galois cohomology to extend Noether's result to infinite Galois extensions.
* "Additive Hilbert 90": let `L/K` be a finite Galois extension. Then $H^n(Gal(L/K), L)$ is trivial
for all $1 ≤ n.$
-/
namespace groupCohomology
namespace Hilbert90
variable {K L : Type*} [Field K] [Field L] [Algebra K L] [FiniteDimensional K L]
/-- Given `f : Aut_K(L) → Lˣ`, the sum `∑ f(φ) • φ` for `φ ∈ Aut_K(L)`, as a function `L → L`. -/
noncomputable def aux (f : Gal(L/K) → Lˣ) : L → L :=
Finsupp.linearCombination L (fun φ : Gal(L/K) ↦ (φ : L → L))
(Finsupp.equivFunOnFinite.symm (fun φ => (f φ : L)))
theorem aux_ne_zero (f : Gal(L/K) → Lˣ) : aux f ≠ 0 :=
/- the set `Aut_K(L)` is linearly independent in the `L`-vector space `L → L`, by Dedekind's
linear independence of characters -/
have : LinearIndependent L (fun (f : Gal(L/K)) => (f : L → L)) :=
LinearIndependent.comp (ι' := Gal(L/K))
(linearIndependent_monoidHom L L) (fun f => f)
(fun x y h => by ext; exact DFunLike.ext_iff.1 h _)
have h := linearIndependent_iff.1 this
(Finsupp.equivFunOnFinite.symm (fun φ => (f φ : L)))
fun H => Units.ne_zero (f 1) (DFunLike.ext_iff.1 (h H) 1)
end Hilbert90
section
open Hilbert90
variable {K L : Type*} [Field K] [Field L] [Algebra K L] [FiniteDimensional K L]
/-- Noether's generalization of Hilbert's Theorem 90: given a finite extension of fields and a
function `f : Aut_K(L) → Lˣ` satisfying `f(gh) = g(f(h)) * f(g)` for all `g, h : Aut_K(L)`, there
exists `β : Lˣ` such that `g(β)/β = f(g)` for all `g : Aut_K(L).` -/
theorem isMulCoboundary₁_of_isMulCocycle₁_of_aut_to_units
(f : Gal(L/K) → Lˣ) (hf : IsMulCocycle₁ f) :
IsMulCoboundary₁ f := by
/- Let `z : L` be such that `∑ f(h) * h(z) ≠ 0`, for `h ∈ Aut_K(L)` -/
obtain ⟨z, hz⟩ : ∃ z, aux f z ≠ 0 :=
not_forall.1 (fun H => aux_ne_zero f <| funext <| fun x => H x)
have : aux f z = ∑ h, f h * h z := by simp [aux, Finsupp.linearCombination, Finsupp.sum_fintype]
/- Let `β = (∑ f(h) * h(z))⁻¹.` -/
use (Units.mk0 (aux f z) hz)⁻¹
intro g
/- Then the equality follows from the hypothesis that `f` is a 1-cocycle. -/
simp only [IsMulCocycle₁, AlgEquiv.smul_units_def,
map_inv, div_inv_eq_mul, inv_mul_eq_iff_eq_mul, Units.ext_iff, this,
Units.val_mul, Units.coe_map, Units.val_mk0, MonoidHom.coe_coe] at hf ⊢
simp_rw [map_sum, map_mul, Finset.sum_mul, mul_assoc, mul_comm _ (f _ : L), ← mul_assoc, ← hf g]
exact eq_comm.1 (Fintype.sum_bijective (fun i => g * i)
(Group.mulLeft_bijective g) _ _ (fun i => rfl))
@[deprecated (since := "2025-06-26")]
alias isMulOneCoboundary_of_isMulOneCocycle_of_aut_to_units :=
isMulCoboundary₁_of_isMulCocycle₁_of_aut_to_units
end
variable (K L : Type) [Field K] [Field L] [Algebra K L] [FiniteDimensional K L]
/-- Noether's generalization of Hilbert's Theorem 90: given a finite extension of fields `L/K`, the
first group cohomology `H¹(Aut_K(L), Lˣ)` is trivial. -/
noncomputable instance H1ofAutOnUnitsUnique : Unique (H1 (Rep.ofAlgebraAutOnUnits K L)) where
default := 0
uniq := fun a => H1_induction_on a fun x => (H1π_eq_zero_iff _).2 <| by
refine (coboundariesOfIsMulCoboundary₁ ?_).2
rcases isMulCoboundary₁_of_isMulCocycle₁_of_aut_to_units x.1
(isMulCocycle₁_of_mem_cocycles₁ _ x.2) with ⟨β, hβ⟩
use β
end groupCohomology |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupCohomology/Shapiro.lean | import Mathlib.CategoryTheory.Preadditive.Projective.Resolution
import Mathlib.RepresentationTheory.Homological.GroupCohomology.Basic
import Mathlib.RepresentationTheory.Coinduced
import Mathlib.RepresentationTheory.Induced
/-!
# Shapiro's lemma for group cohomology
Given a commutative ring `k` and a subgroup `S ≤ G`, the file
`RepresentationTheory/Coinduced.lean` proves that the functor `Coind_S^G : Rep k S ⥤ Rep k G`
preserves epimorphisms. Since `Res(S) : Rep k G ⥤ Rep k S` is left adjoint to `Coind_S^G`, this
means `Res(S)` preserves projective objects. Since `Res(S)` is also exact, given a projective
resolution `P` of `k` as a trivial `k`-linear `G`-representation, `Res(S)(P)` is a projective
resolution of `k` as a trivial `k`-linear `S`-representation.
Since `Hom(Res(S)(P), A) ≅ Hom(P, Coind_S^G(A))` for any `S`-representation `A`, we conclude
Shapiro's lemma for group cohomology: `Hⁿ(G, Coind_S^G(A)) ≅ Hⁿ(S, A)` for all `n`.
## Main definitions
* `groupCohomology.coindIso A n`: Shapiro's lemma for group cohomology: an isomorphism
`Hⁿ(G, Coind_S^G(A)) ≅ Hⁿ(S, A)`, given a subgroup `S ≤ G` and an `S`-representation `A`.
!-/
universe u
namespace groupCohomology
open CategoryTheory Finsupp TensorProduct Rep
variable {k G : Type u} [CommRing k] [Group G] {S : Subgroup G} (A : Rep k S)
/-- Given a projective resolution `P` of `k` as a `k`-linear `G`-representation, a subgroup
`S ≤ G`, and a `k`-linear `S`-representation `A`, this is an isomorphism of complexes
`Hom(Res(S)(P), A) ≅ Hom(P, Coind_S^G(A)).` -/
noncomputable def linearYonedaObjResProjectiveResolutionIso
(P : ProjectiveResolution (trivial k G k)) (A : Rep k S) :
((Action.res _ S.subtype).mapProjectiveResolution P).complex.linearYonedaObj k A ≅
P.complex.linearYonedaObj k (coind S.subtype A) :=
HomologicalComplex.Hom.isoOfComponents
(fun _ => (resCoindHomEquiv _ _ _).toModuleIso) fun _ _ _ =>
ModuleCat.hom_ext (LinearMap.ext fun f => Action.Hom.ext <| by ext; simp [hom_comm_apply])
/-- Shapiro's lemma: given a subgroup `S ≤ G` and an `S`-representation `A`, we have
`Hⁿ(G, Coind_S^G(A)) ≅ Hⁿ(S, A).` -/
noncomputable def coindIso [DecidableEq G] (A : Rep k S) (n : ℕ) :
groupCohomology (coind S.subtype A) n ≅ groupCohomology A n :=
(HomologicalComplex.homologyFunctor _ _ _).mapIso
(inhomogeneousCochainsIso (coind S.subtype A) ≪≫
(linearYonedaObjResProjectiveResolutionIso (barResolution k G) A).symm) ≪≫
(groupCohomologyIso A n ((Action.res _ _).mapProjectiveResolution <| barResolution k G)).symm
end groupCohomology |
.lake/packages/mathlib/Mathlib/RepresentationTheory/Homological/GroupCohomology/LowDegree.lean | import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
import Mathlib.RepresentationTheory.Homological.GroupCohomology.Basic
import Mathlib.RepresentationTheory.Invariants
/-!
# The low-degree cohomology of a `k`-linear `G`-representation
Let `k` be a commutative ring and `G` a group. This file contains specialised API for
the cocycles and group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2.
In `RepresentationTheory/Homological/GroupCohomology/Basic.lean`, we define the `n`th group
cohomology of `A` to be the cohomology of a complex `inhomogeneousCochains A`, whose objects are
`(Fin n → G) → A`; this is unnecessarily unwieldy in low degree. Here, meanwhile, we define the one
and two cocycles and coboundaries as submodules of `Fun(G, A)` and `Fun(G × G, A)`, and provide
maps to `H1` and `H2`.
We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`.
Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`,
we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an
element of the `cocycles₁` of the representation on `A` (or `Additive A`) corresponding to the
scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The
multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case;
unfortunately `@[to_additive]` can't deal with scalar actions.
The file also contains an identification between the definitions in
`RepresentationTheory/Homological/GroupCohomology/Basic.lean`, `groupCohomology.cocycles A n`, and
the `cocyclesₙ` in this file, for `n = 0, 1, 2`.
## Main definitions
* `groupCohomology.H0Iso A`: isomorphism between `H⁰(G, A)` and the invariants `Aᴳ` of the
`G`-representation on `A`.
* `groupCohomology.H1π A`: epimorphism from the 1-cocycles
(i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) to `H¹(G, A)`.
* `groupCohomology.H2π A`: epimorphism from the 2-cocycles
(i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) to `H²(G, A)`.
* `groupCohomology.H1IsoOfIsTrivial`: the isomorphism `H¹(G, A) ≅ Hom(G, A)` when the
representation on `A` is trivial.
## TODO
* The relationship between `H2` and group extensions
* Nonabelian group cohomology
-/
universe v u
noncomputable section
open CategoryTheory Limits Representation
variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G)
namespace groupCohomology
section Cochains
/-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `A` as a `k`-module. -/
def cochainsIso₀ : (inhomogeneousCochains A).X 0 ≅ A.V :=
(LinearEquiv.funUnique (Fin 0 → G) k A).toModuleIso
@[deprecated (since := "2025-06-25")] noncomputable alias zeroCochainsIso := cochainsIso₀
@[deprecated (since := "2025-05-09")] noncomputable alias zeroCochainsLequiv := zeroCochainsIso
/-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G, A)` as a `k`-module. -/
def cochainsIso₁ : (inhomogeneousCochains A).X 1 ≅ ModuleCat.of k (G → A) :=
(LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G)).toModuleIso.symm
@[deprecated (since := "2025-06-25")] noncomputable alias oneCochainsIso := cochainsIso₁
@[deprecated (since := "2025-05-09")] noncomputable alias oneCochainsLequiv := oneCochainsIso
/-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G², A)` as a `k`-module. -/
def cochainsIso₂ : (inhomogeneousCochains A).X 2 ≅ ModuleCat.of k (G × G → A) :=
(LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G)).toModuleIso.symm
@[deprecated (since := "2025-06-25")] noncomputable alias twoCochainsIso := cochainsIso₂
@[deprecated (since := "2025-05-09")] noncomputable alias twoCochainsLequiv := twoCochainsIso
/-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G³, A)` as a `k`-module. -/
def cochainsIso₃ : (inhomogeneousCochains A).X 3 ≅ ModuleCat.of k (G × G × G → A) :=
(LinearEquiv.funCongrLeft k A <| ((Fin.consEquiv _).symm.trans
((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G)))).toModuleIso.symm
@[deprecated (since := "2025-06-25")] noncomputable alias threeCochainsIso := cochainsIso₃
@[deprecated (since := "2025-05-09")] noncomputable alias threeCochainsLequiv := threeCochainsIso
end Cochains
section Differentials
/-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/
@[simps!]
def d₀₁ : A.V ⟶ ModuleCat.of k (G → A) :=
ModuleCat.ofHom
{ toFun m g := A.ρ g m - m
map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl
map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub] }
@[deprecated (since := "2025-06-25")] noncomputable alias dZero := d₀₁
theorem d₀₁_ker_eq_invariants : LinearMap.ker (d₀₁ A).hom = invariants A.ρ := by
ext x
simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, funext_iff]
rfl
@[deprecated (since := "2025-06-25")]
noncomputable alias dZero_ker_eq_invariants := d₀₁_ker_eq_invariants
@[simp] theorem d₀₁_eq_zero [A.IsTrivial] : d₀₁ A = 0 := by
ext
rw [d₀₁_hom_apply, isTrivial_apply, sub_self]
rfl
@[deprecated (since := "2025-06-25")] alias dZero_eq_zero := d₀₁_eq_zero
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma subtype_comp_d₀₁ : ModuleCat.ofHom (A.ρ.invariants.subtype) ≫ d₀₁ A = 0 := by
ext ⟨x, hx⟩ g
replace hx := hx g
rw [← sub_eq_zero] at hx
exact hx
@[deprecated (since := "2025-06-25")] alias subtype_comp_dZero := subtype_comp_d₀₁
/-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends
`(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
@[simps!]
def d₁₂ : ModuleCat.of k (G → A) ⟶ ModuleCat.of k (G × G → A) :=
ModuleCat.ofHom
{ toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1
map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm]
map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub] }
@[deprecated (since := "2025-06-25")] noncomputable alias dOne := d₁₂
/-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends
`(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/
@[simps!]
def d₂₃ : ModuleCat.of k (G × G → A) ⟶ ModuleCat.of k (G × G × G → A) :=
ModuleCat.ofHom
{ toFun f g :=
A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1)
map_add' x y :=
funext fun g => by
dsimp
rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm,
add_sub_assoc, add_sub_assoc]
map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub] }
@[deprecated (since := "2025-06-25")] noncomputable alias dTwo := d₂₃
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `d₀₁` gives a simpler expression for the 0th differential: that is, the following
square commutes:
```
C⁰(G, A) --d 0 1--> C¹(G, A)
| |
| |
| |
v v
A ------d₀₁-----> Fun(G, A)
```
where the vertical arrows are `cochainsIso₀` and `cochainsIso₁` respectively.
-/
theorem comp_d₀₁_eq :
(cochainsIso₀ A).hom ≫ d₀₁ A =
(inhomogeneousCochains A).d 0 1 ≫ (cochainsIso₁ A).hom := by
ext x y
change A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _
simp_rw [Fin.val_eq_zero, zero_add, pow_one, neg_smul, one_smul,
Finset.sum_singleton, sub_eq_add_neg]
rcongr i <;> exact Fin.elim0 i
@[deprecated (since := "2025-06-25")] noncomputable alias comp_dZero_eq := comp_d₀₁_eq
@[deprecated (since := "2025-05-09")] noncomputable alias dZero_comp_eq := comp_dZero_eq
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₀₁_comp_inv :
(cochainsIso₀ A).inv ≫ (inhomogeneousCochains A).d 0 1 =
d₀₁ A ≫ (cochainsIso₁ A).inv :=
(CommSq.horiz_inv ⟨comp_d₀₁_eq A⟩).w
@[deprecated (since := "2025-06-25")] alias eq_dZero_comp_inv := eq_d₀₁_comp_inv
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `d₁₂` gives a simpler expression for the 1st differential: that is, the following
square commutes:
```
C¹(G, A) ---d 1 2---> C²(G, A)
| |
| |
| |
v v
Fun(G, A) --d₁₂--> Fun(G × G, A)
```
where the vertical arrows are `cochainsIso₁` and `cochainsIso₂` respectively.
-/
theorem comp_d₁₂_eq :
(cochainsIso₁ A).hom ≫ d₁₂ A =
(inhomogeneousCochains A).d 1 2 ≫ (cochainsIso₂ A).hom := by
ext x y
change A.ρ y.1 (x _) - x _ + x _ = _ + _
rw [Fin.sum_univ_two]
simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one,
Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc]
rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl
@[deprecated (since := "2025-06-25")] alias comp_dOne_eq := comp_d₁₂_eq
@[deprecated (since := "2025-05-09")] alias dOne_comp_eq := comp_dOne_eq
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₁₂_comp_inv :
(cochainsIso₁ A).inv ≫ (inhomogeneousCochains A).d 1 2 =
d₁₂ A ≫ (cochainsIso₂ A).inv :=
(CommSq.horiz_inv ⟨comp_d₁₂_eq A⟩).w
@[deprecated (since := "2025-06-25")] alias eq_dOne_comp_inv := eq_d₁₂_comp_inv
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `d₂₃` gives a simpler expression for the 2nd differential: that is, the following
square commutes:
```
C²(G, A) ----d 2 3----> C³(G, A)
| |
| |
| |
v v
Fun(G × G, A) --d₂₃--> Fun(G × G × G, A)
```
where the vertical arrows are `cochainsIso₂` and `cochainsIso₃` respectively.
-/
theorem comp_d₂₃_eq :
(cochainsIso₂ A).hom ≫ d₂₃ A =
(inhomogeneousCochains A).d 2 3 ≫ (cochainsIso₃ A).hom := by
ext x y
change A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _
dsimp
rw [Fin.sum_univ_three]
simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul,
one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one]
rcongr i <;> fin_cases i <;> rfl
@[deprecated (since := "2025-06-25")] alias comp_dTwo_eq := comp_d₂₃_eq
@[deprecated (since := "2025-05-09")] alias dTwo_comp_eq := comp_dTwo_eq
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₂₃_comp_inv :
(cochainsIso₂ A).inv ≫ (inhomogeneousCochains A).d 2 3 =
d₂₃ A ≫ (cochainsIso₃ A).inv :=
(CommSq.horiz_inv ⟨comp_d₂₃_eq A⟩).w
@[deprecated (since := "2025-06-25")] alias eq_dTwo_comp_inv := eq_d₂₃_comp_inv
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem d₀₁_comp_d₁₂ : d₀₁ A ≫ d₁₂ A = 0 := by
ext
simp [Pi.zero_apply (M := fun _ => A)]
@[deprecated (since := "2025-06-25")] alias dZero_comp_dOne := d₀₁_comp_d₁₂
@[deprecated (since := "2025-05-14")] alias dOne_comp_dZero := dZero_comp_dOne
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem d₁₂_comp_d₂₃ : d₁₂ A ≫ d₂₃ A = 0 := by
ext f g
simp [mul_assoc, Pi.zero_apply (M := fun _ => A)]
abel
@[deprecated (since := "2025-06-25")] alias dOne_comp_dTwo := d₁₂_comp_d₂₃
@[deprecated (since := "2025-05-14")] alias dTwo_comp_dOne := dOne_comp_dTwo
open ShortComplex
/-- The (exact) short complex `A.ρ.invariants ⟶ A ⟶ (G → A)`. -/
@[simps! -isSimp f g]
def shortComplexH0 : ShortComplex (ModuleCat k) :=
mk _ _ (subtype_comp_d₀₁ A)
/-- The short complex `A --d₀₁--> Fun(G, A) --d₁₂--> Fun(G × G, A)`. -/
@[simps! -isSimp f g]
def shortComplexH1 : ShortComplex (ModuleCat k) :=
mk (d₀₁ A) (d₁₂ A) (d₀₁_comp_d₁₂ A)
/-- The short complex `Fun(G, A) --d₁₂--> Fun(G × G, A) --d₂₃--> Fun(G × G × G, A)`. -/
@[simps! -isSimp f g]
def shortComplexH2 : ShortComplex (ModuleCat k) :=
mk (d₁₂ A) (d₂₃ A) (d₁₂_comp_d₂₃ A)
end Differentials
section Cocycles
/-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map
`Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
def cocycles₁ : Submodule k (G → A) := LinearMap.ker (d₁₂ A).hom
@[deprecated (since := "2025-06-25")] noncomputable alias oneCocycles := cocycles₁
/-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map
`Fun(G × G, A) → Fun(G × G × G, A)` sending
`(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/
def cocycles₂ : Submodule k (G × G → A) := LinearMap.ker (d₂₃ A).hom
@[deprecated (since := "2025-06-25")] noncomputable alias twoCocycles := cocycles₂
variable {A}
instance : FunLike (cocycles₁ A) G A := ⟨Subtype.val, Subtype.val_injective⟩
@[simp]
theorem cocycles₁.coe_mk (f : G → A) (hf) : ((⟨f, hf⟩ : cocycles₁ A) : G → A) = f := rfl
@[deprecated (since := "2025-06-25")] alias oneCocycles.coe_mk := cocycles₁.coe_mk
@[simp]
theorem cocycles₁.val_eq_coe (f : cocycles₁ A) : f.1 = f := rfl
@[deprecated (since := "2025-06-25")] alias oneCocycles.val_eq_coe := cocycles₁.val_eq_coe
@[ext]
theorem cocycles₁_ext {f₁ f₂ : cocycles₁ A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ :=
DFunLike.ext f₁ f₂ h
@[deprecated (since := "2025-06-25")] alias oneCocycles_ext := cocycles₁_ext
theorem mem_cocycles₁_def (f : G → A) :
f ∈ cocycles₁ A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 :=
LinearMap.mem_ker.trans <| by
simp_rw [funext_iff, d₁₂_hom_apply, Prod.forall]
rfl
@[deprecated (since := "2025-06-25")] alias mem_oneCocycles_def := mem_cocycles₁_def
theorem mem_cocycles₁_iff (f : G → A) :
f ∈ cocycles₁ A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by
simp_rw [mem_cocycles₁_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm]
@[deprecated (since := "2025-06-25")] alias mem_oneCocycles_iff := mem_cocycles₁_iff
@[simp] theorem cocycles₁_map_one (f : cocycles₁ A) : f 1 = 0 := by
have := (mem_cocycles₁_def f).1 f.2 1 1
simpa only [map_one, Module.End.one_apply, mul_one, sub_self, zero_add] using this
@[deprecated (since := "2025-06-25")] alias oneCocycles_map_one := cocycles₁_map_one
@[simp] theorem cocycles₁_map_inv (f : cocycles₁ A) (g : G) :
A.ρ g (f g⁻¹) = -f g := by
rw [← add_eq_zero_iff_eq_neg, ← cocycles₁_map_one f, ← mul_inv_cancel g,
(mem_cocycles₁_iff f).1 f.2 g g⁻¹]
@[deprecated (since := "2025-06-25")] alias oneCocycles_map_inv := cocycles₁_map_inv
theorem d₀₁_apply_mem_cocycles₁ (x : A) :
d₀₁ A x ∈ cocycles₁ A :=
d₀₁_comp_d₁₂_apply _ _
@[deprecated (since := "2025-06-25")] alias dZero_apply_mem_oneCocycles := d₀₁_apply_mem_cocycles₁
@[simp]
theorem cocycles₁.d₁₂_apply (x : cocycles₁ A) :
d₁₂ A x = 0 := x.2
@[deprecated (since := "2025-06-25")] alias oneCocycles.dOne_apply := cocycles₁.d₁₂_apply
theorem cocycles₁_map_mul_of_isTrivial [A.IsTrivial] (f : cocycles₁ A) (g h : G) :
f (g * h) = f g + f h := by
rw [(mem_cocycles₁_iff f).1 f.2, isTrivial_apply A.ρ g (f h), add_comm]
@[deprecated (since := "2025-06-25")]
alias oneCocycles_map_mul_of_isTrivial := cocycles₁_map_mul_of_isTrivial
theorem mem_cocycles₁_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) :
f ∘ Additive.ofMul ∈ cocycles₁ A :=
(mem_cocycles₁_iff _).2 fun g h => by
simp only [Function.comp_apply, ofMul_mul, map_add,
isTrivial_apply A.ρ g (f (Additive.ofMul h)), add_comm (f (Additive.ofMul g))]
@[deprecated (since := "2025-06-25")]
alias mem_oneCocycles_of_addMonoidHom := mem_cocycles₁_of_addMonoidHom
variable (A) in
/-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the
group homs `G → A`. -/
@[simps!]
def cocycles₁IsoOfIsTrivial [hA : A.IsTrivial] :
ModuleCat.of k (cocycles₁ A) ≅ ModuleCat.of k (Additive G →+ A) :=
LinearEquiv.toModuleIso
{ toFun f :=
{ toFun := f ∘ Additive.toMul
map_zero' := cocycles₁_map_one f
map_add' := cocycles₁_map_mul_of_isTrivial f }
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f :=
{ val := f
property := mem_cocycles₁_of_addMonoidHom f } }
@[deprecated (since := "2025-06-25")]
noncomputable alias oneCocyclesIsoOfIsTrivial := cocycles₁IsoOfIsTrivial
@[deprecated (since := "2025-05-09")]
noncomputable alias oneCocyclesLequivOfIsTrivial := oneCocyclesIsoOfIsTrivial
instance : FunLike (cocycles₂ A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩
@[simp]
theorem cocycles₂.coe_mk (f : G × G → A) (hf) : ((⟨f, hf⟩ : cocycles₂ A) : G × G → A) = f := rfl
@[deprecated (since := "2025-06-25")] alias twoCocycles.coe_mk := cocycles₂.coe_mk
@[simp]
theorem cocycles₂.val_eq_coe (f : cocycles₂ A) : f.1 = f := rfl
@[deprecated (since := "2025-06-25")] alias twoCocycles.val_eq_coe := cocycles₂.val_eq_coe
@[ext]
theorem cocycles₂_ext {f₁ f₂ : cocycles₂ A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) : f₁ = f₂ :=
DFunLike.ext f₁ f₂ (Prod.forall.mpr h)
@[deprecated (since := "2025-06-25")] alias twoCocycles_ext := cocycles₂_ext
theorem mem_cocycles₂_def (f : G × G → A) :
f ∈ cocycles₂ A ↔ ∀ g h j : G,
A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 :=
LinearMap.mem_ker.trans <| by
simp_rw [funext_iff, d₂₃_hom_apply, Prod.forall]
rfl
@[deprecated (since := "2025-06-25")] alias mem_twoCocycles_def := mem_cocycles₂_def
theorem mem_cocycles₂_iff (f : G × G → A) :
f ∈ cocycles₂ A ↔ ∀ g h j : G,
f (g * h, j) + f (g, h) =
A.ρ g (f (h, j)) + f (g, h * j) := by
simp_rw [mem_cocycles₂_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm,
add_comm (f (_ * _, _))]
@[deprecated (since := "2025-06-25")] alias mem_twoCocycles_iff := mem_cocycles₂_iff
theorem cocycles₂_map_one_fst (f : cocycles₂ A) (g : G) :
f (1, g) = f (1, 1) := by
have := ((mem_cocycles₂_iff f).1 f.2 1 1 g).symm
simpa only [map_one, Module.End.one_apply, one_mul, add_right_inj, this]
@[deprecated (since := "2025-06-25")] alias twoCocycles_map_one_fst := cocycles₂_map_one_fst
theorem cocycles₂_map_one_snd (f : cocycles₂ A) (g : G) :
f (g, 1) = A.ρ g (f (1, 1)) := by
have := (mem_cocycles₂_iff f).1 f.2 g 1 1
simpa only [mul_one, add_left_inj, this]
@[deprecated (since := "2025-06-25")] alias twoCocycles_map_one_snd := cocycles₂_map_one_snd
lemma cocycles₂_ρ_map_inv_sub_map_inv (f : cocycles₂ A) (g : G) :
A.ρ g (f (g⁻¹, g)) - f (g, g⁻¹)
= f (1, 1) - f (g, 1) := by
have := (mem_cocycles₂_iff f).1 f.2 g g⁻¹ g
simp only [mul_inv_cancel, inv_mul_cancel, cocycles₂_map_one_fst _ g]
at this
exact sub_eq_sub_iff_add_eq_add.2 this.symm
@[deprecated (since := "2025-06-25")]
alias twoCocycles_ρ_map_inv_sub_map_inv := cocycles₂_ρ_map_inv_sub_map_inv
theorem d₁₂_apply_mem_cocycles₂ (x : G → A) :
d₁₂ A x ∈ cocycles₂ A :=
d₁₂_comp_d₂₃_apply _ _
@[deprecated (since := "2025-06-25")] alias dOne_apply_mem_twoCocycles := d₁₂_apply_mem_cocycles₂
@[simp]
theorem cocycles₂.d₂₃_apply (x : cocycles₂ A) :
d₂₃ A x = 0 := x.2
@[deprecated (since := "2025-06-25")] alias twoCocycles.dTwo_apply := cocycles₂.d₂₃_apply
end Cocycles
section Coboundaries
/-- The 1-coboundaries `B¹(G, A)` of `A : Rep k G`, defined as the image of the map
`A → Fun(G, A)` sending `(a, g) ↦ ρ_A(g)(a) - a.` -/
def coboundaries₁ : Submodule k (G → A) :=
LinearMap.range (d₀₁ A).hom
@[deprecated (since := "2025-06-25")] noncomputable alias oneCoboundaries := coboundaries₁
/-- The 2-coboundaries `B²(G, A)` of `A : Rep k G`, defined as the image of the map
`Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
def coboundaries₂ : Submodule k (G × G → A) :=
LinearMap.range (d₁₂ A).hom
@[deprecated (since := "2025-06-25")] noncomputable alias twoCoboundaries := coboundaries₂
variable {A}
instance : FunLike (coboundaries₁ A) G A := ⟨Subtype.val, Subtype.val_injective⟩
@[simp]
theorem coboundaries₁.coe_mk (f : G → A) (hf) :
((⟨f, hf⟩ : coboundaries₁ A) : G → A) = f := rfl
@[deprecated (since := "2025-06-25")] alias oneCoboundaries.coe_mk := coboundaries₁.coe_mk
@[simp]
theorem coboundaries₁.val_eq_coe (f : coboundaries₁ A) : f.1 = f := rfl
@[deprecated (since := "2025-06-25")] alias oneCoboundaries.val_eq_coe := coboundaries₁.val_eq_coe
@[ext]
theorem coboundaries₁_ext {f₁ f₂ : coboundaries₁ A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ :=
DFunLike.ext f₁ f₂ h
@[deprecated (since := "2025-06-25")] alias oneCoboundaries_ext := coboundaries₁_ext
variable (A) in
lemma coboundaries₁_le_cocycles₁ : coboundaries₁ A ≤ cocycles₁ A := by
rintro _ ⟨x, rfl⟩
exact d₀₁_apply_mem_cocycles₁ x
@[deprecated (since := "2025-06-25")]
alias oneCoboundaries_le_oneCocycles := coboundaries₁_le_cocycles₁
variable (A) in
/-- Natural inclusion `B¹(G, A) →ₗ[k] Z¹(G, A)`. -/
abbrev coboundariesToCocycles₁ : coboundaries₁ A →ₗ[k] cocycles₁ A :=
Submodule.inclusion (coboundaries₁_le_cocycles₁ A)
@[deprecated (since := "2025-06-25")]
noncomputable alias oneCoboundariesToOneCocycles := coboundariesToCocycles₁
@[simp]
lemma coboundariesToCocycles₁_apply (x : coboundaries₁ A) :
coboundariesToCocycles₁ A x = x.1 := rfl
@[deprecated (since := "2025-06-25")]
alias oneCoboundariesToOneCocycles_apply := coboundariesToCocycles₁_apply
theorem coboundaries₁_eq_bot_of_isTrivial (A : Rep k G) [A.IsTrivial] :
coboundaries₁ A = ⊥ := by
simp_rw [coboundaries₁, d₀₁_eq_zero]
exact LinearMap.range_eq_bot.2 rfl
@[deprecated (since := "2025-06-25")]
alias oneCoboundaries_eq_bot_of_isTrivial := coboundaries₁_eq_bot_of_isTrivial
instance : FunLike (coboundaries₂ A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩
@[simp]
theorem coboundaries₂.coe_mk (f : G × G → A) (hf) :
((⟨f, hf⟩ : coboundaries₂ A) : G × G → A) = f := rfl
@[deprecated (since := "2025-06-25")] alias twoCoboundaries.coe_mk := coboundaries₂.coe_mk
@[simp]
theorem coboundaries₂.val_eq_coe (f : coboundaries₂ A) : f.1 = f := rfl
@[deprecated (since := "2025-06-25")] alias twoCoboundaries.val_eq_coe := coboundaries₂.val_eq_coe
@[ext]
theorem coboundaries₂_ext {f₁ f₂ : coboundaries₂ A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) :
f₁ = f₂ :=
DFunLike.ext f₁ f₂ (Prod.forall.mpr h)
@[deprecated (since := "2025-06-25")] alias twoCoboundaries_ext := coboundaries₂_ext
variable (A) in
lemma coboundaries₂_le_cocycles₂ : coboundaries₂ A ≤ cocycles₂ A := by
rintro _ ⟨x, rfl⟩
exact d₁₂_apply_mem_cocycles₂ x
@[deprecated (since := "2025-06-25")]
alias twoCoboundaries_le_twoCocycles := coboundaries₂_le_cocycles₂
variable (A) in
/-- Natural inclusion `B²(G, A) →ₗ[k] Z²(G, A)`. -/
abbrev coboundariesToCocycles₂ : coboundaries₂ A →ₗ[k] cocycles₂ A :=
Submodule.inclusion (coboundaries₂_le_cocycles₂ A)
@[deprecated (since := "2025-06-25")]
noncomputable alias twoCoboundariesToTwoCocycles := coboundariesToCocycles₂
@[simp]
lemma coboundariesToCocycles₂_apply (x : coboundaries₂ A) :
coboundariesToCocycles₂ A x = x.1 := rfl
@[deprecated (since := "2025-06-25")]
alias twoCoboundariesToTwoCocycles_apply := coboundariesToCocycles₂_apply
end Coboundaries
section IsCocycle
section
variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A]
/-- A function `f : G → A` satisfies the 1-cocycle condition if
`f(gh) = g • f(h) + f(g)` for all `g, h : G`. -/
def IsCocycle₁ (f : G → A) : Prop := ∀ g h : G, f (g * h) = g • f h + f g
@[deprecated (since := "2025-06-25")] alias IsOneCocycle := IsCocycle₁
/-- A function `f : G × G → A` satisfies the 2-cocycle condition if
`f(gh, j) + f(g, h) = g • f(h, j) + f(g, hj)` for all `g, h : G`. -/
def IsCocycle₂ (f : G × G → A) : Prop :=
∀ g h j : G, f (g * h, j) + f (g, h) = g • (f (h, j)) + f (g, h * j)
@[deprecated (since := "2025-06-25")] alias IsTwoCocycle := IsCocycle₂
end
section
variable {G A : Type*} [Monoid G] [AddCommGroup A] [MulAction G A]
theorem map_one_of_isCocycle₁ {f : G → A} (hf : IsCocycle₁ f) :
f 1 = 0 := by
simpa only [mul_one, one_smul, left_eq_add] using hf 1 1
@[deprecated (since := "2025-06-25")] alias map_one_of_isOneCocycle := map_one_of_isCocycle₁
theorem map_one_fst_of_isCocycle₂ {f : G × G → A} (hf : IsCocycle₂ f) (g : G) :
f (1, g) = f (1, 1) := by
simpa only [one_smul, one_mul, mul_one, add_right_inj] using (hf 1 1 g).symm
@[deprecated (since := "2025-06-25")] alias map_one_fst_of_isTwoCocycle := map_one_fst_of_isCocycle₂
theorem map_one_snd_of_isCocycle₂ {f : G × G → A} (hf : IsCocycle₂ f) (g : G) :
f (g, 1) = g • f (1, 1) := by
simpa only [mul_one, add_left_inj] using hf g 1 1
@[deprecated (since := "2025-06-25")] alias map_one_snd_of_isTwoCocycle := map_one_snd_of_isCocycle₂
end
section
variable {G A : Type*} [Group G] [AddCommGroup A] [MulAction G A]
@[scoped simp] theorem map_inv_of_isCocycle₁ {f : G → A} (hf : IsCocycle₁ f) (g : G) :
g • f g⁻¹ = -f g := by
rw [← add_eq_zero_iff_eq_neg, ← map_one_of_isCocycle₁ hf, ← mul_inv_cancel g, hf g g⁻¹]
@[deprecated (since := "2025-06-25")] alias map_inv_of_isOneCocycle := map_inv_of_isCocycle₁
theorem smul_map_inv_sub_map_inv_of_isCocycle₂ {f : G × G → A} (hf : IsCocycle₂ f) (g : G) :
g • f (g⁻¹, g) - f (g, g⁻¹) = f (1, 1) - f (g, 1) := by
have := hf g g⁻¹ g
simp only [mul_inv_cancel, inv_mul_cancel, map_one_fst_of_isCocycle₂ hf g] at this
exact sub_eq_sub_iff_add_eq_add.2 this.symm
@[deprecated (since := "2025-06-25")]
alias smul_map_inv_sub_map_inv_of_isTwoCocycle := smul_map_inv_sub_map_inv_of_isCocycle₂
end
end IsCocycle
section IsCoboundary
variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A]
/-- A function `f : G → A` satisfies the 1-coboundary condition if there's `x : A` such that
`g • x - x = f(g)` for all `g : G`. -/
def IsCoboundary₁ (f : G → A) : Prop := ∃ x : A, ∀ g : G, g • x - x = f g
@[deprecated (since := "2025-06-25")] alias IsOneCoboundary := IsCoboundary₁
/-- A function `f : G × G → A` satisfies the 2-coboundary condition if there's `x : G → A` such
that `g • x(h) - x(gh) + x(g) = f(g, h)` for all `g, h : G`. -/
def IsCoboundary₂ (f : G × G → A) : Prop :=
∃ x : G → A, ∀ g h : G, g • x h - x (g * h) + x g = f (g, h)
@[deprecated (since := "2025-06-25")] alias IsTwoCoboundary := IsCoboundary₂
end IsCoboundary
section ofDistribMulAction
variable {k G A : Type u} [CommRing k] [Group G] [AddCommGroup A] [Module k A]
[DistribMulAction G A] [SMulCommClass G k A]
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function
`f : G → A` satisfying the 1-cocycle condition, produces a 1-cocycle for the representation on
`A` induced by the `DistribMulAction`. -/
@[simps]
def cocyclesOfIsCocycle₁ {f : G → A} (hf : IsCocycle₁ f) :
cocycles₁ (Rep.ofDistribMulAction k G A) :=
⟨f, (mem_cocycles₁_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩
@[deprecated (since := "2025-06-25")] alias oneCocyclesOfIsOneCocycle := cocyclesOfIsCocycle₁
theorem isCocycle₁_of_mem_cocycles₁
(f : G → A) (hf : f ∈ cocycles₁ (Rep.ofDistribMulAction k G A)) :
IsCocycle₁ f :=
fun _ _ => (mem_cocycles₁_iff (A := Rep.ofDistribMulAction k G A) f).1 hf _ _
@[deprecated (since := "2025-07-02")]
alias isOneCocycle_of_mem_oneCocycles := isCocycle₁_of_mem_cocycles₁
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function
`f : G → A` satisfying the 1-coboundary condition, produces a 1-coboundary for the representation
on `A` induced by the `DistribMulAction`. -/
@[simps]
def coboundariesOfIsCoboundary₁ {f : G → A} (hf : IsCoboundary₁ f) :
coboundaries₁ (Rep.ofDistribMulAction k G A) :=
⟨f, hf.choose, funext hf.choose_spec⟩
@[deprecated (since := "2025-06-25")]
alias oneCoboundariesOfIsOneCoboundary := coboundariesOfIsCoboundary₁
theorem isCoboundary₁_of_mem_coboundaries₁
(f : G → A) (hf : f ∈ coboundaries₁ (Rep.ofDistribMulAction k G A)) :
IsCoboundary₁ f := by
rcases hf with ⟨a, rfl⟩
exact ⟨a, fun _ => rfl⟩
@[deprecated (since := "2025-07-02")]
alias isOneCoboundary_of_mem_oneCoboundaries := isCoboundary₁_of_mem_coboundaries₁
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function
`f : G × G → A` satisfying the 2-cocycle condition, produces a 2-cocycle for the representation on
`A` induced by the `DistribMulAction`. -/
@[simps]
def cocyclesOfIsCocycle₂ {f : G × G → A} (hf : IsCocycle₂ f) :
cocycles₂ (Rep.ofDistribMulAction k G A) :=
⟨f, (mem_cocycles₂_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩
@[deprecated (since := "2025-06-25")] alias twoCocyclesOfIsTwoCocycle := cocyclesOfIsCocycle₂
theorem isCocycle₂_of_mem_cocycles₂
(f : G × G → A) (hf : f ∈ cocycles₂ (Rep.ofDistribMulAction k G A)) :
IsCocycle₂ f := (mem_cocycles₂_iff (A := Rep.ofDistribMulAction k G A) f).1 hf
@[deprecated (since := "2025-07-02")]
alias isTwoCocycle_of_mem_twoCocycles := isCocycle₂_of_mem_cocycles₂
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function
`f : G × G → A` satisfying the 2-coboundary condition, produces a 2-coboundary for the
representation on `A` induced by the `DistribMulAction`. -/
@[simps]
def coboundariesOfIsCoboundary₂ {f : G × G → A} (hf : IsCoboundary₂ f) :
coboundaries₂ (Rep.ofDistribMulAction k G A) :=
⟨f, hf.choose,funext fun g ↦ hf.choose_spec g.1 g.2⟩
@[deprecated (since := "2025-06-25")]
alias twoCoboundariesOfIsTwoCoboundary := coboundariesOfIsCoboundary₂
theorem isCoboundary₂_of_mem_coboundaries₂
(f : G × G → A) (hf : f ∈ coboundaries₂ (Rep.ofDistribMulAction k G A)) :
IsCoboundary₂ f := by
rcases hf with ⟨a, rfl⟩
exact ⟨a, fun _ _ => rfl⟩
@[deprecated (since := "2025-07-02")]
alias isTwoCoboundary_of_mem_twoCoboundaries := isCoboundary₂_of_mem_coboundaries₂
end ofDistribMulAction
/-! The next few sections, until the section `CocyclesIso`, are a multiplicative copy of the
previous few sections beginning with `IsCocycle`. Unfortunately `@[to_additive]` doesn't work with
scalar actions. -/
section IsMulCocycle
section
variable {G M : Type*} [Mul G] [CommGroup M] [SMul G M]
/-- A function `f : G → M` satisfies the multiplicative 1-cocycle condition if
`f(gh) = g • f(h) * f(g)` for all `g, h : G`. -/
def IsMulCocycle₁ (f : G → M) : Prop := ∀ g h : G, f (g * h) = g • f h * f g
@[deprecated (since := "2025-06-25")] alias IsMulOneCocycle := IsMulCocycle₁
/-- A function `f : G × G → M` satisfies the multiplicative 2-cocycle condition if
`f(gh, j) * f(g, h) = g • f(h, j) * f(g, hj)` for all `g, h : G`. -/
def IsMulCocycle₂ (f : G × G → M) : Prop :=
∀ g h j : G, f (g * h, j) * f (g, h) = g • (f (h, j)) * f (g, h * j)
@[deprecated (since := "2025-06-25")] alias IsMulTwoCocycle := IsMulCocycle₂
end
section
variable {G M : Type*} [Monoid G] [CommGroup M] [MulAction G M]
theorem map_one_of_isMulCocycle₁ {f : G → M} (hf : IsMulCocycle₁ f) :
f 1 = 1 := by
simpa only [mul_one, one_smul, left_eq_mul] using hf 1 1
@[deprecated (since := "2025-06-25")] alias map_one_of_isMulOneCocycle := map_one_of_isMulCocycle₁
theorem map_one_fst_of_isMulCocycle₂ {f : G × G → M} (hf : IsMulCocycle₂ f) (g : G) :
f (1, g) = f (1, 1) := by
simpa only [one_smul, one_mul, mul_one, mul_right_inj] using (hf 1 1 g).symm
@[deprecated (since := "2025-06-25")]
alias map_one_fst_of_isMulTwoCocycle := map_one_fst_of_isMulCocycle₂
theorem map_one_snd_of_isMulCocycle₂ {f : G × G → M} (hf : IsMulCocycle₂ f) (g : G) :
f (g, 1) = g • f (1, 1) := by
simpa only [mul_one, mul_left_inj] using hf g 1 1
@[deprecated (since := "2025-06-25")]
alias map_one_snd_of_isMulTwoCocycle := map_one_snd_of_isMulCocycle₂
end
section
variable {G M : Type*} [Group G] [CommGroup M] [MulAction G M]
@[scoped simp] theorem map_inv_of_isMulCocycle₁ {f : G → M} (hf : IsMulCocycle₁ f) (g : G) :
g • f g⁻¹ = (f g)⁻¹ := by
rw [← mul_eq_one_iff_eq_inv, ← map_one_of_isMulCocycle₁ hf, ← mul_inv_cancel g, hf g g⁻¹]
@[deprecated (since := "2025-06-25")] alias map_inv_of_isMulOneCocycle := map_inv_of_isMulCocycle₁
theorem smul_map_inv_div_map_inv_of_isMulCocycle₂
{f : G × G → M} (hf : IsMulCocycle₂ f) (g : G) :
g • f (g⁻¹, g) / f (g, g⁻¹) = f (1, 1) / f (g, 1) := by
have := hf g g⁻¹ g
simp only [mul_inv_cancel, inv_mul_cancel, map_one_fst_of_isMulCocycle₂ hf g] at this
exact div_eq_div_iff_mul_eq_mul.2 this.symm
@[deprecated (since := "2025-07-02")]
alias smul_map_inv_div_map_inv_of_isMulTwoCocycle := smul_map_inv_div_map_inv_of_isMulCocycle₂
end
end IsMulCocycle
section IsMulCoboundary
variable {G M : Type*} [Mul G] [CommGroup M] [SMul G M]
/-- A function `f : G → M` satisfies the multiplicative 1-coboundary condition if there's `x : M`
such that `g • x / x = f(g)` for all `g : G`. -/
def IsMulCoboundary₁ (f : G → M) : Prop := ∃ x : M, ∀ g : G, g • x / x = f g
@[deprecated (since := "2025-06-25")] alias IsMulOneCoboundary := IsMulCoboundary₁
/-- A function `f : G × G → M` satisfies the 2-coboundary condition if there's `x : G → M` such
that `g • x(h) / x(gh) * x(g) = f(g, h)` for all `g, h : G`. -/
def IsMulCoboundary₂ (f : G × G → M) : Prop :=
∃ x : G → M, ∀ g h : G, g • x h / x (g * h) * x g = f (g, h)
@[deprecated (since := "2025-06-25")] alias IsMulTwoCoboundary := IsMulCoboundary₂
end IsMulCoboundary
section ofMulDistribMulAction
variable {G M : Type} [Group G] [CommGroup M] [MulDistribMulAction G M]
/-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function
`f : G → M` satisfying the multiplicative 1-cocycle condition, produces a 1-cocycle for the
representation on `Additive M` induced by the `MulDistribMulAction`. -/
@[simps]
def cocyclesOfIsMulCocycle₁ {f : G → M} (hf : IsMulCocycle₁ f) :
cocycles₁ (Rep.ofMulDistribMulAction G M) :=
⟨Additive.ofMul ∘ f, (mem_cocycles₁_iff (A := Rep.ofMulDistribMulAction G M) f).2 hf⟩
@[deprecated (since := "2025-06-25")] alias oneCocyclesOfIsMulOneCocycle := cocyclesOfIsMulCocycle₁
theorem isMulCocycle₁_of_mem_cocycles₁
(f : G → M) (hf : f ∈ cocycles₁ (Rep.ofMulDistribMulAction G M)) :
IsMulCocycle₁ (Additive.toMul ∘ f) :=
(mem_cocycles₁_iff (A := Rep.ofMulDistribMulAction G M) f).1 hf
@[deprecated (since := "2025-07-02")]
alias isMulOneCocycle_of_mem_oneCocycles := isMulCocycle₁_of_mem_cocycles₁
/-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function
`f : G → M` satisfying the multiplicative 1-coboundary condition, produces a
1-coboundary for the representation on `Additive M` induced by the `MulDistribMulAction`. -/
@[simps]
def coboundariesOfIsMulCoboundary₁ {f : G → M} (hf : IsMulCoboundary₁ f) :
coboundaries₁ (Rep.ofMulDistribMulAction G M) :=
⟨f, hf.choose, funext hf.choose_spec⟩
@[deprecated (since := "2025-06-25")]
alias oneCoboundariesOfIsMulOneCoboundary := coboundariesOfIsMulCoboundary₁
theorem isMulCoboundary₁_of_mem_coboundaries₁
(f : G → M) (hf : f ∈ coboundaries₁ (Rep.ofMulDistribMulAction G M)) :
IsMulCoboundary₁ (M := M) (Additive.ofMul ∘ f) := by
rcases hf with ⟨x, rfl⟩
exact ⟨x, fun _ => rfl⟩
@[deprecated (since := "2025-07-02")]
alias isMulOneCoboundary_of_mem_oneCoboundaries := isMulCoboundary₁_of_mem_coboundaries₁
/-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function
`f : G × G → M` satisfying the multiplicative 2-cocycle condition, produces a 2-cocycle for the
representation on `Additive M` induced by the `MulDistribMulAction`. -/
@[simps]
def cocyclesOfIsMulCocycle₂ {f : G × G → M} (hf : IsMulCocycle₂ f) :
cocycles₂ (Rep.ofMulDistribMulAction G M) :=
⟨Additive.ofMul ∘ f, (mem_cocycles₂_iff (A := Rep.ofMulDistribMulAction G M) f).2 hf⟩
@[deprecated (since := "2025-06-25")] alias twoCocyclesOfIsMulTwoCocycle := cocyclesOfIsMulCocycle₂
theorem isMulCocycle₂_of_mem_cocycles₂
(f : G × G → M) (hf : f ∈ cocycles₂ (Rep.ofMulDistribMulAction G M)) :
IsMulCocycle₂ (Additive.toMul ∘ f) :=
(mem_cocycles₂_iff (A := Rep.ofMulDistribMulAction G M) f).1 hf
@[deprecated (since := "2025-07-02")]
alias isMulTwoCocycle_of_mem_twoCocycles := isMulCocycle₂_of_mem_cocycles₂
/-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function
`f : G × G → M` satisfying the multiplicative 2-coboundary condition, produces a
2-coboundary for the representation on `M` induced by the `MulDistribMulAction`. -/
def coboundariesOfIsMulCoboundary₂ {f : G × G → M} (hf : IsMulCoboundary₂ f) :
coboundaries₂ (Rep.ofMulDistribMulAction G M) :=
⟨f, hf.choose, funext fun g ↦ hf.choose_spec g.1 g.2⟩
@[deprecated (since := "2025-06-25")]
alias twoCoboundariesOfIsMulTwoCoboundary := coboundariesOfIsMulCoboundary₂
theorem isMulCoboundary₂_of_mem_coboundaries₂
(f : G × G → M) (hf : f ∈ coboundaries₂ (Rep.ofMulDistribMulAction G M)) :
IsMulCoboundary₂ (M := M) (Additive.toMul ∘ f) := by
rcases hf with ⟨x, rfl⟩
exact ⟨x, fun _ _ => rfl⟩
@[deprecated (since := "2025-07-02")]
alias isMulTwoCoboundary_of_mem_twoCoboundaries := isMulCoboundary₂_of_mem_coboundaries₂
end ofMulDistribMulAction
open ShortComplex
section CocyclesIso
section cocyclesIso₀
instance : Mono (shortComplexH0 A).f := by
rw [ModuleCat.mono_iff_injective]
apply Submodule.injective_subtype
lemma shortComplexH0_exact : (shortComplexH0 A).Exact := by
rw [ShortComplex.moduleCat_exact_iff]
intro (x : A) (hx : d₀₁ _ x = 0)
refine ⟨⟨x, fun g => ?_⟩, rfl⟩
rw [← sub_eq_zero]
exact congr_fun hx g
/-- The arrow `A --d₀₁--> Fun(G, A)` is isomorphic to the differential
`(inhomogeneousCochains A).d 0 1` of the complex of inhomogeneous cochains of `A`. -/
@[simps! hom_left hom_right inv_left inv_right]
def dArrowIso₀₁ :
Arrow.mk ((inhomogeneousCochains A).d 0 1) ≅ Arrow.mk (d₀₁ A) :=
Arrow.isoMk (cochainsIso₀ A) (cochainsIso₁ A) (comp_d₀₁_eq A)
@[deprecated (since := "2025-06-25")] noncomputable alias dZeroArrowIso := dArrowIso₀₁
/-- The 0-cocycles of the complex of inhomogeneous cochains of `A` are isomorphic to
`A.ρ.invariants`, which is a simpler type. -/
def cocyclesIso₀ : cocycles A 0 ≅ ModuleCat.of k A.ρ.invariants :=
KernelFork.mapIsoOfIsLimit
((inhomogeneousCochains A).cyclesIsKernel 0 1 (by simp)) (shortComplexH0_exact A).fIsKernel
(dArrowIso₀₁ A)
@[deprecated (since := "2025-07-02")] noncomputable alias zeroCocyclesIso := cocyclesIso₀
@[deprecated (since := "2025-06-12")]
noncomputable alias isoZeroCocycles := zeroCocyclesIso
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cocyclesIso₀_hom_comp_f :
(cocyclesIso₀ A).hom ≫ (shortComplexH0 A).f = iCocycles A 0 ≫ (cochainsIso₀ A).hom := by
dsimp [cocyclesIso₀]
apply KernelFork.mapOfIsLimit_ι
@[deprecated (since := "2025-07-02")]
noncomputable alias zeroCocyclesIso_hom_comp_f := cocyclesIso₀_hom_comp_f
@[deprecated (since := "2025-06-12")]
alias isoZeroCocycles_hom_comp_subtype := zeroCocyclesIso_hom_comp_f
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cocyclesIso₀_inv_comp_iCocycles :
(cocyclesIso₀ A).inv ≫ iCocycles A 0 =
(shortComplexH0 A).f ≫ (cochainsIso₀ A).inv := by
rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, cocyclesIso₀_hom_comp_f]
@[deprecated (since := "2025-07-02")]
noncomputable alias zeroCocyclesIso_inv_comp_iCocycles := cocyclesIso₀_inv_comp_iCocycles
@[deprecated (since := "2025-06-12")]
alias isoZeroCocycles_inv_comp_iCocycles := zeroCocyclesIso_inv_comp_iCocycles
variable {A} in
lemma cocyclesMk₀_eq (x : A.ρ.invariants) :
cocyclesMk ((cochainsIso₀ A).inv x.1) (by ext g; simp [cochainsIso₀, x.2 (g 0),
inhomogeneousCochains.d, Pi.zero_apply (M := fun _ => A)]) = (cocyclesIso₀ A).inv x :=
(ModuleCat.mono_iff_injective <| iCocycles A 0).1 inferInstance <| by
rw [iCocycles_mk]
exact (cocyclesIso₀_inv_comp_iCocycles_apply A x).symm
@[deprecated (since := "2025-07-02")] alias cocyclesMk_0_eq := cocyclesMk₀_eq
end cocyclesIso₀
section isoCocycles₁
/-- The short complex `A --d₀₁--> Fun(G, A) --d₁₂--> Fun(G × G, A)` is isomorphic to the 1st
short complex associated to the complex of inhomogeneous cochains of `A`. -/
@[simps! hom inv]
def isoShortComplexH1 : (inhomogeneousCochains A).sc 1 ≅ shortComplexH1 A :=
(inhomogeneousCochains A).isoSc' 0 1 2 (by simp) (by simp) ≪≫
isoMk (cochainsIso₀ A) (cochainsIso₁ A) (cochainsIso₂ A)
(comp_d₀₁_eq A) (comp_d₁₂_eq A)
@[deprecated (since := "2025-07-11")] noncomputable alias shortComplexH1Iso := isoShortComplexH1
/-- The 1-cocycles of the complex of inhomogeneous cochains of `A` are isomorphic to
`cocycles₁ A`, which is a simpler type. -/
def isoCocycles₁ : cocycles A 1 ≅ ModuleCat.of k (cocycles₁ A) :=
cyclesMapIso' (isoShortComplexH1 A) _ (shortComplexH1 A).moduleCatLeftHomologyData
@[deprecated (since := "2025-06-25")] noncomputable alias isoOneCocycles := isoCocycles₁
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCocycles₁_hom_comp_i :
(isoCocycles₁ A).hom ≫ (shortComplexH1 A).moduleCatLeftHomologyData.i =
iCocycles A 1 ≫ (cochainsIso₁ A).hom := by
simp [isoCocycles₁, iCocycles, HomologicalComplex.iCycles, iCycles]
@[deprecated (since := "2025-06-25")] alias isoOneCocycles_hom_comp_i := isoCocycles₁_hom_comp_i
@[deprecated (since := "2025-05-09")]
alias isoOneCocycles_hom_comp_subtype := isoOneCocycles_hom_comp_i
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCocycles₁_inv_comp_iCocycles :
(isoCocycles₁ A).inv ≫ iCocycles A 1 =
(shortComplexH1 A).moduleCatLeftHomologyData.i ≫ (cochainsIso₁ A).inv :=
(CommSq.horiz_inv ⟨isoCocycles₁_hom_comp_i A⟩).w
@[deprecated (since := "2025-06-25")]
alias isoOneCocycles_inv_comp_iCocycles := isoCocycles₁_inv_comp_iCocycles
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma toCocycles_comp_isoCocycles₁_hom :
toCocycles A 0 1 ≫ (isoCocycles₁ A).hom =
(cochainsIso₀ A).hom ≫ (shortComplexH1 A).moduleCatLeftHomologyData.f' := by
simp [← cancel_mono (shortComplexH1 A).moduleCatLeftHomologyData.i, comp_d₀₁_eq,
shortComplexH1_f]
@[deprecated (since := "2025-06-25")]
alias toCocycles_comp_isoOneCocycles_hom := toCocycles_comp_isoCocycles₁_hom
lemma cocyclesMk₁_eq (x : cocycles₁ A) :
cocyclesMk ((cochainsIso₁ A).inv x) (by
simp [← inhomogeneousCochains.d_def, cocycles₁.d₁₂_apply x]) =
(isoCocycles₁ A).inv x := by
apply_fun (forget₂ _ Ab).map ((inhomogeneousCochains A).iCycles 1) using
(AddCommGrpCat.mono_iff_injective _).1 <| (forget₂ _ _).map_mono _
simpa only [HomologicalComplex.i_cyclesMk] using
(isoCocycles₁_inv_comp_iCocycles_apply _ x).symm
@[deprecated (since := "2025-07-02")] alias cocyclesMk_1_eq := cocyclesMk₁_eq
end isoCocycles₁
section isoCocycles₂
/-- The short complex `Fun(G, A) --d₁₂--> Fun(G × G, A) --dTwo--> Fun(G × G × G, A)` is
isomorphic to the 2nd short complex associated to the complex of inhomogeneous cochains of `A`. -/
@[simps! hom inv]
def isoShortComplexH2 :
(inhomogeneousCochains A).sc 2 ≅ shortComplexH2 A :=
(inhomogeneousCochains A).isoSc' 1 2 3 (by simp) (by simp) ≪≫
isoMk (cochainsIso₁ A) (cochainsIso₂ A) (cochainsIso₃ A)
(comp_d₁₂_eq A) (comp_d₂₃_eq A)
@[deprecated (since := "2025-07-11")] noncomputable alias shortComplexH2Iso := isoShortComplexH2
/-- The 2-cocycles of the complex of inhomogeneous cochains of `A` are isomorphic to
`cocycles₂ A`, which is a simpler type. -/
def isoCocycles₂ : cocycles A 2 ≅ ModuleCat.of k (cocycles₂ A) :=
cyclesMapIso' (isoShortComplexH2 A) _ (shortComplexH2 A).moduleCatLeftHomologyData
@[deprecated (since := "2025-06-25")] noncomputable alias isoTwoCocycles := isoCocycles₂
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCocycles₂_hom_comp_i :
(isoCocycles₂ A).hom ≫ (shortComplexH2 A).moduleCatLeftHomologyData.i =
iCocycles A 2 ≫ (cochainsIso₂ A).hom := by
simp [isoCocycles₂, iCocycles, HomologicalComplex.iCycles, iCycles]
@[deprecated (since := "2025-06-25")] alias isoTwoCocycles_hom_comp_i := isoCocycles₂_hom_comp_i
@[deprecated (since := "2025-05-09")]
alias isoTwoCocycles_hom_comp_subtype := isoTwoCocycles_hom_comp_i
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCocycles₂_inv_comp_iCocycles :
(isoCocycles₂ A).inv ≫ iCocycles A 2 =
(shortComplexH2 A).moduleCatLeftHomologyData.i ≫ (cochainsIso₂ A).inv :=
(CommSq.horiz_inv ⟨isoCocycles₂_hom_comp_i A⟩).w
@[deprecated (since := "2025-06-25")]
alias isoTwoCocycles_inv_comp_iCocycles := isoCocycles₂_inv_comp_iCocycles
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma toCocycles_comp_isoCocycles₂_hom :
toCocycles A 1 2 ≫ (isoCocycles₂ A).hom =
(cochainsIso₁ A).hom ≫ (shortComplexH2 A).moduleCatLeftHomologyData.f' := by
simp [← cancel_mono (shortComplexH2 A).moduleCatLeftHomologyData.i, comp_d₁₂_eq,
shortComplexH2_f]
@[deprecated (since := "2025-06-25")]
alias toCocycles_comp_isoTwoCocycles_hom := toCocycles_comp_isoCocycles₂_hom
lemma cocyclesMk₂_eq (x : cocycles₂ A) :
cocyclesMk ((cochainsIso₂ A).inv x) (by
simp [← inhomogeneousCochains.d_def, cocycles₂.d₂₃_apply x]) =
(isoCocycles₂ A).inv x := by
apply_fun (forget₂ _ Ab).map ((inhomogeneousCochains A).iCycles 2) using
(AddCommGrpCat.mono_iff_injective _).1 <| (forget₂ _ _).map_mono _
simpa only [HomologicalComplex.i_cyclesMk] using
(isoCocycles₂_inv_comp_iCocycles_apply _ x).symm
@[deprecated (since := "2025-07-02")] alias cocyclesMk_2_eq := cocyclesMk₂_eq
end isoCocycles₂
end CocyclesIso
section Cohomology
section H0
/-- Shorthand for the 0th group cohomology of a `k`-linear `G`-representation `A`, `H⁰(G, A)`,
defined as the 0th cohomology of the complex of inhomogeneous cochains of `A`. -/
abbrev H0 := groupCohomology A 0
/-- The 0th group cohomology of `A`, defined as the 0th cohomology of the complex of inhomogeneous
cochains, is isomorphic to the invariants of the representation on `A`. -/
def H0Iso : H0 A ≅ ModuleCat.of k A.ρ.invariants :=
(CochainComplex.isoHomologyπ₀ _).symm ≪≫ cocyclesIso₀ A
@[deprecated (since := "2025-06-11")]
noncomputable alias isoH0 := H0Iso
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H0Iso_hom :
π A 0 ≫ (H0Iso A).hom = (cocyclesIso₀ A).hom := by
simp [H0Iso]
@[deprecated (since := "2025-06-12")]
alias groupCohomologyπ_comp_isoH0_hom := π_comp_H0Iso_hom
@[elab_as_elim]
theorem H0_induction_on {C : H0 A → Prop} (x : H0 A)
(h : ∀ x : A.ρ.invariants, C ((H0Iso A).inv x)) : C x := by
simpa using h ((H0Iso A).hom x)
section IsTrivial
variable [A.IsTrivial]
/-- When the representation on `A` is trivial, then `H⁰(G, A)` is all of `A.` -/
def H0IsoOfIsTrivial :
H0 A ≅ A.V := H0Iso A ≪≫ (LinearEquiv.ofTop _ (invariants_eq_top A.ρ)).toModuleIso
@[deprecated (since := "2025-05-09")]
noncomputable alias H0LequivOfIsTrivial := H0IsoOfIsTrivial
@[simp, elementwise]
theorem H0IsoOfIsTrivial_hom :
(H0IsoOfIsTrivial A).hom = (H0Iso A).hom ≫ (shortComplexH0 A).f := rfl
@[deprecated (since := "2025-06-11")]
alias H0LequivOfIsTrivial_eq_subtype := H0IsoOfIsTrivial_hom
@[deprecated (since := "2025-05-09")]
alias H0LequivOfIsTrivial_apply := H0IsoOfIsTrivial_hom_apply
@[reassoc, elementwise]
theorem π_comp_H0IsoOfIsTrivial_hom :
π A 0 ≫ (H0IsoOfIsTrivial A).hom = iCocycles A 0 ≫ (cochainsIso₀ A).hom := by
simp
variable {A} in
@[simp]
theorem H0IsoOfIsTrivial_inv_apply (x : A) :
(H0IsoOfIsTrivial A).inv x = (H0Iso A).inv ⟨x, by simp⟩ := rfl
@[deprecated (since := "2025-05-09")]
alias H0LequivOfIsTrivial_symm_apply := H0IsoOfIsTrivial_inv_apply
end IsTrivial
end H0
section H1
/-- Shorthand for the 1st group cohomology of a `k`-linear `G`-representation `A`, `H¹(G, A)`,
defined as the 1st cohomology of the complex of inhomogeneous cochains of `A`. -/
abbrev H1 := groupCohomology A 1
/-- The quotient map from the 1-cocycles of `A`, as a submodule of `G → A`, to `H¹(G, A)`. -/
def H1π : ModuleCat.of k (cocycles₁ A) ⟶ H1 A :=
(isoCocycles₁ A).inv ≫ π A 1
instance : Epi (H1π A) := by unfold H1π; infer_instance
variable {A}
lemma H1π_eq_zero_iff (x : cocycles₁ A) : H1π A x = 0 ↔ ⇑x ∈ coboundaries₁ A := by
have h := leftHomologyπ_naturality'_assoc (isoShortComplexH1 A).inv
(shortComplexH1 A).moduleCatLeftHomologyData (leftHomologyData _)
((inhomogeneousCochains A).sc 1).leftHomologyIso.hom
simp only [H1π, isoCocycles₁, π, HomologicalComplex.homologyπ, homologyπ,
cyclesMapIso'_inv, leftHomologyπ, ← h, ← leftHomologyMapIso'_inv, ModuleCat.hom_comp,
LinearMap.coe_comp, Function.comp_apply, map_eq_zero_iff _
((ModuleCat.mono_iff_injective <| _).1 inferInstance)]
simp [LinearMap.range_codRestrict, coboundaries₁, shortComplexH1, cocycles₁]
lemma H1π_eq_iff (x y : cocycles₁ A) :
H1π A x = H1π A y ↔ ⇑x - ⇑y ∈ coboundaries₁ A := by
rw [← sub_eq_zero, ← map_sub, H1π_eq_zero_iff]
rfl
@[elab_as_elim]
theorem H1_induction_on {C : H1 A → Prop} (x : H1 A) (h : ∀ x : cocycles₁ A, C (H1π A x)) :
C x :=
groupCohomology_induction_on x fun y => by simpa [H1π] using h ((isoCocycles₁ A).hom y)
variable (A)
/-- The 1st group cohomology of `A`, defined as the 1st cohomology of the complex of inhomogeneous
cochains, is isomorphic to `cocycles₁ A ⧸ coboundaries₁ A`, which is a simpler type. -/
def H1Iso : H1 A ≅ (shortComplexH1 A).moduleCatLeftHomologyData.H :=
(leftHomologyIso _).symm ≪≫ (leftHomologyMapIso' (isoShortComplexH1 A) _ _)
@[deprecated (since := "2025-06-11")]
noncomputable alias isoH1 := H1Iso
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H1Iso_hom :
π A 1 ≫ (H1Iso A).hom = (isoCocycles₁ A).hom ≫
(shortComplexH1 A).moduleCatLeftHomologyData.π := by
simp [H1Iso, isoCocycles₁, π, HomologicalComplex.homologyπ, leftHomologyπ]
@[deprecated (since := "2025-06-12")]
alias groupCohomologyπ_comp_isoH1_hom := π_comp_H1Iso_hom
section IsTrivial
variable [A.IsTrivial]
/-- When `A : Rep k G` is a trivial representation of `G`, `H¹(G, A)` is isomorphic to the
group homs `G → A`. -/
def H1IsoOfIsTrivial :
H1 A ≅ ModuleCat.of k (Additive G →+ A) :=
(HomologicalComplex.isoHomologyπ _ 0 1 (CochainComplex.prev_nat_succ 0) <| by
ext; simp [inhomogeneousCochains.d_def, inhomogeneousCochains.d,
Unique.eq_default (α := Fin 0 → G), Pi.zero_apply (M := fun _ => A)]).symm ≪≫
isoCocycles₁ A ≪≫ cocycles₁IsoOfIsTrivial A
@[deprecated (since := "2025-05-09")]
noncomputable alias H1LequivOfIsTrivial := H1IsoOfIsTrivial
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem H1π_comp_H1IsoOfIsTrivial_hom :
H1π A ≫ (H1IsoOfIsTrivial A).hom = (cocycles₁IsoOfIsTrivial A).hom := by
simp [H1IsoOfIsTrivial, H1π]
@[deprecated (since := "2025-05-09")]
alias H1LequivOfIsTrivial_comp_H1π := H1π_comp_H1IsoOfIsTrivial_hom
variable {A}
theorem H1IsoOfIsTrivial_H1π_apply_apply
(f : cocycles₁ A) (x : Additive G) :
(H1IsoOfIsTrivial A).hom (H1π A f) x = f x.toMul := by simp
@[deprecated (since := "2025-05-09")]
alias H1LequivOfIsTrivial_comp_H1_π_apply_apply := H1IsoOfIsTrivial_H1π_apply_apply
theorem H1IsoOfIsTrivial_inv_apply (f : Additive G →+ A) :
(H1IsoOfIsTrivial A).inv f = H1π A ((cocycles₁IsoOfIsTrivial A).inv f) := rfl
@[deprecated (since := "2025-05-09")]
alias H1LequivOfIsTrivial_symm_apply := H1IsoOfIsTrivial_inv_apply
end IsTrivial
end H1
section H2
/-- Shorthand for the 2nd group cohomology of a `k`-linear `G`-representation `A`, `H²(G, A)`,
defined as the 2nd cohomology of the complex of inhomogeneous cochains of `A`. -/
abbrev H2 := groupCohomology A 2
/-- The quotient map from the 2-cocycles of `A`, as a submodule of `G × G → A`, to `H²(G, A)`. -/
def H2π : ModuleCat.of k (cocycles₂ A) ⟶ H2 A :=
(isoCocycles₂ A).inv ≫ π A 2
instance : Epi (H2π A) := by unfold H2π; infer_instance
variable {A}
lemma H2π_eq_zero_iff (x : cocycles₂ A) : H2π A x = 0 ↔ ⇑x ∈ coboundaries₂ A := by
have h := leftHomologyπ_naturality'_assoc (isoShortComplexH2 A).inv
(shortComplexH2 A).moduleCatLeftHomologyData (leftHomologyData _)
((inhomogeneousCochains A).sc 2).leftHomologyIso.hom
simp only [H2π, isoCocycles₂, π, HomologicalComplex.homologyπ, homologyπ,
cyclesMapIso'_inv, leftHomologyπ, ← h, ← leftHomologyMapIso'_inv, ModuleCat.hom_comp,
LinearMap.coe_comp, Function.comp_apply, map_eq_zero_iff _
((ModuleCat.mono_iff_injective <| _).1 inferInstance)]
simp [LinearMap.range_codRestrict, coboundaries₂, shortComplexH2, cocycles₂]
lemma H2π_eq_iff (x y : cocycles₂ A) :
H2π A x = H2π A y ↔ ⇑x - ⇑y ∈ coboundaries₂ A := by
rw [← sub_eq_zero, ← map_sub, H2π_eq_zero_iff]
rfl
@[elab_as_elim]
theorem H2_induction_on {C : H2 A → Prop} (x : H2 A) (h : ∀ x : cocycles₂ A, C (H2π A x)) :
C x :=
groupCohomology_induction_on x fun y => by simpa [H2π] using h ((isoCocycles₂ A).hom y)
variable (A)
/-- The 2nd group cohomology of `A`, defined as the 2nd cohomology of the complex of inhomogeneous
cochains, is isomorphic to `cocycles₂ A ⧸ coboundaries₂ A`, which is a simpler type. -/
def H2Iso : H2 A ≅ (shortComplexH2 A).moduleCatLeftHomologyData.H :=
(leftHomologyIso _).symm ≪≫ (leftHomologyMapIso' (isoShortComplexH2 A) _ _)
@[deprecated (since := "2025-06-11")]
noncomputable alias isoH2 := H2Iso
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H2Iso_hom :
π A 2 ≫ (H2Iso A).hom = (isoCocycles₂ A).hom ≫
(shortComplexH2 A).moduleCatLeftHomologyData.π := by
simp [H2Iso, isoCocycles₂, π, HomologicalComplex.homologyπ, leftHomologyπ]
@[deprecated (since := "2025-06-12")]
alias groupCohomologyπ_comp_isoH2_hom := π_comp_H2Iso_hom
end H2
end Cohomology
end groupCohomology |
.lake/packages/mathlib/Mathlib/Logic/Lemmas.lean | import Mathlib.Logic.Basic
import Mathlib.Tactic.Convert
import Mathlib.Tactic.SplitIfs
import Mathlib.Tactic.Tauto
/-!
# More basic logic properties
A few more logic lemmas. These are in their own file, rather than `Logic.Basic`, because it is
convenient to be able to use the `tauto` or `split_ifs` tactics.
## Implementation notes
We spell those lemmas out with `dite` and `ite` rather than the `if then else` notation because this
would result in less delta-reduced statements.
-/
theorem iff_assoc {a b c : Prop} : ((a ↔ b) ↔ c) ↔ (a ↔ (b ↔ c)) := by tauto
theorem iff_left_comm {a b c : Prop} : (a ↔ (b ↔ c)) ↔ (b ↔ (a ↔ c)) := by tauto
theorem iff_right_comm {a b c : Prop} : ((a ↔ b) ↔ c) ↔ ((a ↔ c) ↔ b) := by tauto
protected alias ⟨HEq.eq, Eq.heq⟩ := heq_iff_eq
variable {α : Sort*} {p q : Prop} [Decidable p] [Decidable q] {a b c : α}
theorem dite_dite_distrib_left {a : p → α} {b : ¬p → q → α} {c : ¬p → ¬q → α} :
(dite p a fun hp ↦ dite q (b hp) (c hp)) =
dite q (fun hq ↦ (dite p a) fun hp ↦ b hp hq) fun hq ↦ (dite p a) fun hp ↦ c hp hq := by
split_ifs <;> rfl
theorem dite_dite_distrib_right {a : p → q → α} {b : p → ¬q → α} {c : ¬p → α} :
dite p (fun hp ↦ dite q (a hp) (b hp)) c =
dite q (fun hq ↦ dite p (fun hp ↦ a hp hq) c) fun hq ↦ dite p (fun hp ↦ b hp hq) c := by
split_ifs <;> rfl
theorem ite_dite_distrib_left {a : α} {b : q → α} {c : ¬q → α} :
ite p a (dite q b c) = dite q (fun hq ↦ ite p a <| b hq) fun hq ↦ ite p a <| c hq :=
dite_dite_distrib_left
theorem ite_dite_distrib_right {a : q → α} {b : ¬q → α} {c : α} :
ite p (dite q a b) c = dite q (fun hq ↦ ite p (a hq) c) fun hq ↦ ite p (b hq) c :=
dite_dite_distrib_right
theorem dite_ite_distrib_left {a : p → α} {b : ¬p → α} {c : ¬p → α} :
(dite p a fun hp ↦ ite q (b hp) (c hp)) = ite q (dite p a b) (dite p a c) :=
dite_dite_distrib_left
theorem dite_ite_distrib_right {a : p → α} {b : p → α} {c : ¬p → α} :
dite p (fun hp ↦ ite q (a hp) (b hp)) c = ite q (dite p a c) (dite p b c) :=
dite_dite_distrib_right
theorem ite_ite_distrib_left : ite p a (ite q b c) = ite q (ite p a b) (ite p a c) :=
dite_dite_distrib_left
theorem ite_ite_distrib_right : ite p (ite q a b) c = ite q (ite p a c) (ite p b c) :=
dite_dite_distrib_right
lemma Prop.forall {f : Prop → Prop} : (∀ p, f p) ↔ f True ∧ f False :=
⟨fun h ↦ ⟨h _, h _⟩, by rintro ⟨h₁, h₀⟩ p; by_cases hp : p <;> simp only [hp] <;> assumption⟩
lemma Prop.exists {f : Prop → Prop} : (∃ p, f p) ↔ f True ∨ f False :=
⟨fun ⟨p, h⟩ ↦ by refine (em p).imp ?_ ?_ <;> intro H <;> convert h <;> simp [H],
by rintro (h | h) <;> exact ⟨_, h⟩⟩ |
.lake/packages/mathlib/Mathlib/Logic/Pairwise.lean | import Mathlib.Logic.Function.Basic
import Mathlib.Data.Set.Defs
/-!
# Relations holding pairwise
This file defines pairwise relations.
## Main declarations
* `Pairwise`: `Pairwise r` states that `r i j` for all `i ≠ j`.
* `Set.Pairwise`: `s.Pairwise r` states that `r i j` for all `i ≠ j` with `i, j ∈ s`.
-/
open Function
variable {α β ι : Type*} {r p : α → α → Prop}
section Pairwise
variable {f : ι → α} {s : Set α} {a b : α}
/-- A relation `r` holds pairwise if `r i j` for all `i ≠ j`. -/
def Pairwise (r : α → α → Prop) :=
∀ ⦃i j⦄, i ≠ j → r i j
theorem Pairwise.mono (hr : Pairwise r) (h : ∀ ⦃i j⦄, r i j → p i j) : Pairwise p :=
fun _i _j hij => h <| hr hij
protected theorem Pairwise.eq (h : Pairwise r) : ¬r a b → a = b :=
not_imp_comm.1 <| @h _ _
@[simp]
protected lemma Subsingleton.pairwise [Subsingleton α] : Pairwise r :=
fun _ _ h ↦ False.elim <| h.elim <| Subsingleton.elim _ _
theorem Function.injective_iff_pairwise_ne : Injective f ↔ Pairwise ((· ≠ ·) on f) :=
forall₂_congr fun _i _j => not_imp_not.symm
alias ⟨Function.Injective.pairwise_ne, _⟩ := Function.injective_iff_pairwise_ne
lemma Pairwise.comp_of_injective (hr : Pairwise r) {f : β → α} (hf : Injective f) :
Pairwise (r on f) :=
fun _ _ h ↦ hr <| hf.ne h
lemma Pairwise.of_comp_of_surjective {f : β → α} (hr : Pairwise (r on f)) (hf : Surjective f) :
Pairwise r := hf.forall₂.2 fun _ _ h ↦ hr <| ne_of_apply_ne f h
lemma Function.Bijective.pairwise_comp_iff {f : β → α} (hf : Bijective f) :
Pairwise (r on f) ↔ Pairwise r :=
⟨fun hr ↦ hr.of_comp_of_surjective hf.surjective, fun hr ↦ hr.comp_of_injective hf.injective⟩
theorem pairwise_fin_succ_iff {n : ℕ} {R : Fin n.succ → Fin n.succ → Prop} :
Pairwise R ↔
(∀ i, R (Fin.succ i) 0) ∧ (∀ j, R 0 (Fin.succ j)) ∧
Pairwise fun i j => R (Fin.succ i) (Fin.succ j) where
mp h := ⟨
fun _ => h (Fin.succ_ne_zero _), fun _ => h (Fin.succ_ne_zero _).symm,
fun _i _j hij => h <| Fin.succ_inj.not.2 hij⟩
mpr
| ⟨hi, hj, h⟩ =>
Fin.cases
(Fin.cases nofun fun j _ => hj j)
(fun i => Fin.cases (fun _ => hi i) fun _j hij => h (ne_of_apply_ne _ hij))
theorem pairwise_fin_succ_iff_of_isSymm {n : ℕ} {R : Fin n.succ → Fin n.succ → Prop} [IsSymm _ R] :
Pairwise R ↔ (∀ j, R 0 (Fin.succ j)) ∧ Pairwise fun i j => R (Fin.succ i) (Fin.succ j) := by
simp only [pairwise_fin_succ_iff, comm (b := 0) (r := R), and_self_left]
namespace Set
/-- The relation `r` holds pairwise on the set `s` if `r x y` for all *distinct* `x y ∈ s`. -/
protected def Pairwise (s : Set α) (r : α → α → Prop) :=
∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → r x y
theorem pairwise_of_forall (s : Set α) (r : α → α → Prop) (h : ∀ a b, r a b) : s.Pairwise r :=
fun a _ b _ _ => h a b
theorem Pairwise.imp_on (h : s.Pairwise r) (hrp : s.Pairwise fun ⦃a b : α⦄ => r a b → p a b) :
s.Pairwise p :=
fun _a ha _b hb hab => hrp ha hb hab <| h ha hb hab
theorem Pairwise.imp (h : s.Pairwise r) (hpq : ∀ ⦃a b : α⦄, r a b → p a b) : s.Pairwise p :=
h.imp_on <| pairwise_of_forall s _ hpq
protected theorem Pairwise.eq (hs : s.Pairwise r) (ha : a ∈ s) (hb : b ∈ s) (h : ¬r a b) : a = b :=
of_not_not fun hab => h <| hs ha hb hab
theorem _root_.Reflexive.set_pairwise_iff (hr : Reflexive r) :
s.Pairwise r ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → r a b :=
forall₄_congr fun a _ _ _ => or_iff_not_imp_left.symm.trans <| or_iff_right_of_imp <| Eq.ndrec <|
hr a
theorem Pairwise.on_injective (hs : s.Pairwise r) (hf : Function.Injective f) (hfs : ∀ x, f x ∈ s) :
Pairwise (r on f) := fun i j hij => hs (hfs i) (hfs j) (hf.ne hij)
end Set
theorem Pairwise.set_pairwise (h : Pairwise r) (s : Set α) : s.Pairwise r := fun _ _ _ _ w => h w
end Pairwise |
.lake/packages/mathlib/Mathlib/Logic/ExistsUnique.lean | import Mathlib.Tactic.TypeStar
import Batteries.Tactic.Alias
/-!
# `ExistsUnique`
This file defines the `ExistsUnique` predicate, notated as `∃!`, and proves some of its
basic properties.
-/
variable {α : Sort*}
/-- For `p : α → Prop`, `ExistsUnique p` means that there exists a unique `x : α` with `p x`. -/
def ExistsUnique (p : α → Prop) := ∃ x, p x ∧ ∀ y, p y → y = x
namespace Mathlib.Notation
open Lean
/-- Checks to see that `xs` has only one binder. -/
def isExplicitBinderSingular (xs : TSyntax ``explicitBinders) : Bool :=
match xs with
| `(explicitBinders| $_:binderIdent $[: $_]?) => true
| `(explicitBinders| ($_:binderIdent : $_)) => true
| _ => false
open TSyntax.Compat in
/--
`∃! x : α, p x` means that there exists a unique `x` in `α` such that `p x`.
This is notation for `ExistsUnique (fun (x : α) ↦ p x)`.
This notation does not allow multiple binders like `∃! (x : α) (y : β), p x y`
as a shorthand for `∃! (x : α), ∃! (y : β), p x y` since it is liable to be misunderstood.
Often, the intended meaning is instead `∃! q : α × β, p q.1 q.2`.
-/
macro "∃!" xs:explicitBinders ", " b:term : term => do
if !isExplicitBinderSingular xs then
Macro.throwErrorAt xs "\
The `ExistsUnique` notation should not be used with more than one binder.\n\
\n\
The reason for this is that `∃! (x : α), ∃! (y : β), p x y` has a completely different \
meaning from `∃! q : α × β, p q.1 q.2`. \
To prevent confusion, this notation requires that you be explicit \
and use one with the correct interpretation."
expandExplicitBinders ``ExistsUnique xs b
/--
Pretty-printing for `ExistsUnique`, following the same pattern as pretty printing for `Exists`.
However, it does *not* merge binders.
-/
@[app_unexpander ExistsUnique] def unexpandExistsUnique : Lean.PrettyPrinter.Unexpander
| `($(_) fun $x:ident ↦ $b) => `(∃! $x:ident, $b)
| `($(_) fun ($x:ident : $t) ↦ $b) => `(∃! $x:ident : $t, $b)
| _ => throw ()
/--
`∃! x ∈ s, p x` means `∃! x, x ∈ s ∧ p x`, which is to say that there exists a unique `x ∈ s`
such that `p x`.
Similarly, notations such as `∃! x ≤ n, p n` are supported,
using any relation defined using the `binder_predicate` command.
-/
syntax "∃! " binderIdent binderPred ", " term : term
macro_rules
| `(∃! $x:ident $p:binderPred, $b) => `(∃! $x:ident, satisfies_binder_pred% $x $p ∧ $b)
| `(∃! _ $p:binderPred, $b) => `(∃! x, satisfies_binder_pred% x $p ∧ $b)
end Mathlib.Notation
-- @[intro] -- TODO
theorem ExistsUnique.intro {p : α → Prop} (w : α)
(h₁ : p w) (h₂ : ∀ y, p y → y = w) : ∃! x, p x := ⟨w, h₁, h₂⟩
theorem ExistsUnique.elim {p : α → Prop} {b : Prop}
(h₂ : ∃! x, p x) (h₁ : ∀ x, p x → (∀ y, p y → y = x) → b) : b :=
Exists.elim h₂ (fun w hw ↦ h₁ w (And.left hw) (And.right hw))
theorem existsUnique_of_exists_of_unique {p : α → Prop}
(hex : ∃ x, p x) (hunique : ∀ y₁ y₂, p y₁ → p y₂ → y₁ = y₂) : ∃! x, p x :=
Exists.elim hex (fun x px ↦ ExistsUnique.intro x px (fun y (h : p y) ↦ hunique y x h px))
theorem ExistsUnique.exists {p : α → Prop} : (∃! x, p x) → ∃ x, p x | ⟨x, h, _⟩ => ⟨x, h⟩
theorem ExistsUnique.unique {p : α → Prop}
(h : ∃! x, p x) {y₁ y₂ : α} (py₁ : p y₁) (py₂ : p y₂) : y₁ = y₂ :=
let ⟨_, _, hy⟩ := h; (hy _ py₁).trans (hy _ py₂).symm
-- TODO
-- attribute [congr] forall_congr'
-- attribute [congr] exists_congr'
-- @[congr]
theorem existsUnique_congr {p q : α → Prop} (h : ∀ a, p a ↔ q a) : (∃! a, p a) ↔ ∃! a, q a :=
exists_congr fun _ ↦ and_congr (h _) <| forall_congr' fun _ ↦ imp_congr_left (h _)
@[simp] theorem existsUnique_iff_exists [Subsingleton α] {p : α → Prop} :
(∃! x, p x) ↔ ∃ x, p x :=
⟨fun h ↦ h.exists, Exists.imp fun x hx ↦ ⟨hx, fun y _ ↦ Subsingleton.elim y x⟩⟩
theorem existsUnique_const {b : Prop} (α : Sort*) [i : Nonempty α] [Subsingleton α] :
(∃! _ : α, b) ↔ b := by simp
@[simp] theorem existsUnique_eq {a' : α} : ∃! a, a = a' := by
simp only [eq_comm, ExistsUnique, and_self, forall_eq', exists_eq']
/-- The difference with `existsUnique_eq` is that the equality is reversed. -/
@[simp] theorem existsUnique_eq' {a' : α} : ∃! a, a' = a := by
simp only [ExistsUnique, and_self, forall_eq', exists_eq']
theorem existsUnique_prop {p q : Prop} : (∃! _ : p, q) ↔ p ∧ q := by simp
@[simp] theorem existsUnique_false : ¬∃! _ : α, False := fun ⟨_, h, _⟩ ↦ h
theorem existsUnique_prop_of_true {p : Prop} {q : p → Prop} (h : p) : (∃! h' : p, q h') ↔ q h :=
@existsUnique_const (q h) p ⟨h⟩ _
theorem ExistsUnique.elim₂ {p : α → Sort*} [∀ x, Subsingleton (p x)]
{q : ∀ (x) (_ : p x), Prop} {b : Prop} (h₂ : ∃! x, ∃! h : p x, q x h)
(h₁ : ∀ (x) (h : p x), q x h → (∀ (y) (hy : p y), q y hy → y = x) → b) : b := by
simp only [existsUnique_iff_exists] at h₂
apply h₂.elim
exact fun x ⟨hxp, hxq⟩ H ↦ h₁ x hxp hxq fun y hyp hyq ↦ H y ⟨hyp, hyq⟩
theorem ExistsUnique.intro₂ {p : α → Sort*} [∀ x, Subsingleton (p x)]
{q : ∀ (x : α) (_ : p x), Prop} (w : α) (hp : p w) (hq : q w hp)
(H : ∀ (y) (hy : p y), q y hy → y = w) : ∃! x, ∃! hx : p x, q x hx := by
simp only [existsUnique_iff_exists]
exact ExistsUnique.intro w ⟨hp, hq⟩ fun y ⟨hyp, hyq⟩ ↦ H y hyp hyq
theorem ExistsUnique.exists₂ {p : α → Sort*} {q : ∀ (x : α) (_ : p x), Prop}
(h : ∃! x, ∃! hx : p x, q x hx) : ∃ (x : _) (hx : p x), q x hx :=
h.exists.imp fun _ hx ↦ hx.exists
theorem ExistsUnique.unique₂ {p : α → Sort*} [∀ x, Subsingleton (p x)]
{q : ∀ (x : α) (_ : p x), Prop} (h : ∃! x, ∃! hx : p x, q x hx) {y₁ y₂ : α}
(hpy₁ : p y₁) (hqy₁ : q y₁ hpy₁) (hpy₂ : p y₂) (hqy₂ : q y₂ hpy₂) : y₁ = y₂ := by
simp only [existsUnique_iff_exists] at h
exact h.unique ⟨hpy₁, hqy₁⟩ ⟨hpy₂, hqy₂⟩
/-- This invokes the two `Decidable` arguments $O(n)$ times. -/
instance List.decidableBExistsUnique {α : Type*} [DecidableEq α] (p : α → Prop) [DecidablePred p] :
(l : List α) → Decidable (∃! x, x ∈ l ∧ p x)
| [] => .isFalse <| by simp
| x :: xs =>
if hx : p x then
decidable_of_iff (∀ y ∈ xs, p y → x = y) (⟨fun h ↦ ⟨x, by grind⟩,
fun ⟨z, h⟩ y hy hp ↦ (h.2 x ⟨mem_cons_self, hx⟩).trans (by grind)⟩)
else
have := List.decidableBExistsUnique p xs
decidable_of_iff (∃! x, x ∈ xs ∧ p x) (by grind) |
.lake/packages/mathlib/Mathlib/Logic/IsEmpty.lean | import Mathlib.Logic.Function.Basic
import Mathlib.Logic.Relator
/-!
# Types that are empty
In this file we define a typeclass `IsEmpty`, which expresses that a type has no elements.
## Main declaration
* `IsEmpty`: a typeclass that expresses that a type is empty.
-/
variable {α β γ : Sort*}
/-- `IsEmpty α` expresses that `α` is empty. -/
class IsEmpty (α : Sort*) : Prop where
protected false : α → False
instance Empty.instIsEmpty : IsEmpty Empty :=
⟨Empty.elim⟩
instance PEmpty.instIsEmpty : IsEmpty PEmpty :=
⟨PEmpty.elim⟩
instance : IsEmpty False :=
⟨id⟩
instance Fin.isEmpty : IsEmpty (Fin 0) :=
⟨fun n ↦ Nat.not_lt_zero n.1 n.2⟩
instance Fin.isEmpty' : IsEmpty (Fin Nat.zero) :=
Fin.isEmpty
protected theorem Function.isEmpty [IsEmpty β] (f : α → β) : IsEmpty α :=
⟨fun x ↦ IsEmpty.false (f x)⟩
theorem Function.Surjective.isEmpty [IsEmpty α] {f : α → β} (hf : f.Surjective) : IsEmpty β :=
⟨fun y ↦ let ⟨x, _⟩ := hf y; IsEmpty.false x⟩
-- See note [instance argument order]
instance {p : α → Sort*} [∀ x, IsEmpty (p x)] [h : Nonempty α] : IsEmpty (∀ x, p x) :=
h.elim fun x ↦ Function.isEmpty <| Function.eval x
instance PProd.isEmpty_left [IsEmpty α] : IsEmpty (PProd α β) :=
Function.isEmpty PProd.fst
instance PProd.isEmpty_right [IsEmpty β] : IsEmpty (PProd α β) :=
Function.isEmpty PProd.snd
instance Prod.isEmpty_left {α β} [IsEmpty α] : IsEmpty (α × β) :=
Function.isEmpty Prod.fst
instance Prod.isEmpty_right {α β} [IsEmpty β] : IsEmpty (α × β) :=
Function.isEmpty Prod.snd
instance Quot.instIsEmpty {α : Sort*} [IsEmpty α] {r : α → α → Prop} : IsEmpty (Quot r) :=
Function.Surjective.isEmpty Quot.exists_rep
instance Quotient.instIsEmpty {α : Sort*} [IsEmpty α] {s : Setoid α} : IsEmpty (Quotient s) :=
Quot.instIsEmpty
instance [IsEmpty α] [IsEmpty β] : IsEmpty (α ⊕' β) :=
⟨fun x ↦ PSum.rec IsEmpty.false IsEmpty.false x⟩
instance instIsEmptySum {α β} [IsEmpty α] [IsEmpty β] : IsEmpty (α ⊕ β) :=
⟨fun x ↦ Sum.rec IsEmpty.false IsEmpty.false x⟩
/-- subtypes of an empty type are empty -/
instance [IsEmpty α] (p : α → Prop) : IsEmpty (Subtype p) :=
⟨fun x ↦ IsEmpty.false x.1⟩
/-- subtypes by an all-false predicate are false. -/
theorem Subtype.isEmpty_of_false {p : α → Prop} (hp : ∀ a, ¬p a) : IsEmpty (Subtype p) :=
⟨fun x ↦ hp _ x.2⟩
/-- subtypes by false are false. -/
instance Subtype.isEmpty_false : IsEmpty { _a : α // False } :=
Subtype.isEmpty_of_false fun _ ↦ id
instance Sigma.isEmpty_left {α} [IsEmpty α] {E : α → Type*} : IsEmpty (Sigma E) :=
Function.isEmpty Sigma.fst
example [h : Nonempty α] [IsEmpty β] : IsEmpty (α → β) := by infer_instance
/-- Eliminate out of a type that `IsEmpty` (without using projection notation). -/
@[elab_as_elim]
def isEmptyElim [IsEmpty α] {p : α → Sort*} (a : α) : p a :=
(IsEmpty.false a).elim
theorem isEmpty_iff : IsEmpty α ↔ α → False :=
⟨@IsEmpty.false α, IsEmpty.mk⟩
namespace IsEmpty
open Function
universe u in
/-- Eliminate out of a type that `IsEmpty` (using projection notation). -/
@[elab_as_elim]
protected def elim {α : Sort u} (_ : IsEmpty α) {p : α → Sort*} (a : α) : p a :=
isEmptyElim a
/-- Non-dependent version of `IsEmpty.elim`. Helpful if the elaborator cannot elaborate `h.elim a`
correctly. -/
protected def elim' {β : Sort*} (h : IsEmpty α) (a : α) : β :=
(h.false a).elim
protected theorem prop_iff {p : Prop} : IsEmpty p ↔ ¬p :=
isEmpty_iff
variable [IsEmpty α]
@[simp]
theorem forall_iff {p : α → Prop} : (∀ a, p a) ↔ True :=
iff_true_intro isEmptyElim
@[simp]
theorem exists_iff {p : α → Prop} : (∃ a, p a) ↔ False :=
iff_false_intro fun ⟨x, _⟩ ↦ IsEmpty.false x
-- see Note [lower instance priority]
instance (priority := 100) : Subsingleton α :=
⟨isEmptyElim⟩
end IsEmpty
@[simp, push]
theorem not_nonempty_iff : ¬Nonempty α ↔ IsEmpty α :=
⟨fun h ↦ ⟨fun x ↦ h ⟨x⟩⟩, fun h1 h2 ↦ h2.elim h1.elim⟩
@[simp, push]
theorem not_isEmpty_iff : ¬IsEmpty α ↔ Nonempty α :=
not_iff_comm.mp not_nonempty_iff
@[simp]
theorem isEmpty_Prop {p : Prop} : IsEmpty p ↔ ¬p := by
simp only [← not_nonempty_iff, nonempty_prop]
@[simp]
theorem isEmpty_pi {π : α → Sort*} : IsEmpty (∀ a, π a) ↔ ∃ a, IsEmpty (π a) := by
simp only [← not_nonempty_iff, Classical.nonempty_pi, not_forall]
theorem isEmpty_fun : IsEmpty (α → β) ↔ Nonempty α ∧ IsEmpty β := by
rw [isEmpty_pi, ← exists_true_iff_nonempty, ← exists_and_right, true_and]
@[simp]
theorem nonempty_fun : Nonempty (α → β) ↔ IsEmpty α ∨ Nonempty β :=
not_iff_not.mp <| by rw [not_or, not_nonempty_iff, not_nonempty_iff, isEmpty_fun, not_isEmpty_iff]
@[simp]
theorem isEmpty_sigma {α} {E : α → Type*} : IsEmpty (Sigma E) ↔ ∀ a, IsEmpty (E a) := by
simp only [← not_nonempty_iff, nonempty_sigma, not_exists]
@[simp]
theorem isEmpty_psigma {α} {E : α → Sort*} : IsEmpty (PSigma E) ↔ ∀ a, IsEmpty (E a) := by
simp only [← not_nonempty_iff, nonempty_psigma, not_exists]
theorem isEmpty_subtype (p : α → Prop) : IsEmpty (Subtype p) ↔ ∀ x, ¬p x := by
simp only [← not_nonempty_iff, nonempty_subtype, not_exists]
@[simp]
theorem isEmpty_prod {α β : Type*} : IsEmpty (α × β) ↔ IsEmpty α ∨ IsEmpty β := by
simp only [← not_nonempty_iff, nonempty_prod, not_and_or]
@[simp]
theorem isEmpty_pprod : IsEmpty (PProd α β) ↔ IsEmpty α ∨ IsEmpty β := by
simp only [← not_nonempty_iff, nonempty_pprod, not_and_or]
@[simp]
theorem isEmpty_sum {α β} : IsEmpty (α ⊕ β) ↔ IsEmpty α ∧ IsEmpty β := by
simp only [← not_nonempty_iff, nonempty_sum, not_or]
@[simp]
theorem isEmpty_psum {α β} : IsEmpty (α ⊕' β) ↔ IsEmpty α ∧ IsEmpty β := by
simp only [← not_nonempty_iff, nonempty_psum, not_or]
@[simp]
theorem isEmpty_ulift {α} : IsEmpty (ULift α) ↔ IsEmpty α := by
simp only [← not_nonempty_iff, nonempty_ulift]
@[simp]
theorem isEmpty_plift {α} : IsEmpty (PLift α) ↔ IsEmpty α := by
simp only [← not_nonempty_iff, nonempty_plift]
theorem wellFounded_of_isEmpty {α} [IsEmpty α] (r : α → α → Prop) : WellFounded r :=
⟨isEmptyElim⟩
variable (α)
theorem isEmpty_or_nonempty : IsEmpty α ∨ Nonempty α :=
(em <| IsEmpty α).elim Or.inl <| Or.inr ∘ not_isEmpty_iff.mp
@[simp]
theorem not_isEmpty_of_nonempty [h : Nonempty α] : ¬IsEmpty α :=
not_isEmpty_iff.mpr h
variable {α}
theorem Function.extend_of_isEmpty [IsEmpty α] (f : α → β) (g : α → γ) (h : β → γ) :
Function.extend f g h = h :=
funext fun _ ↦ (Function.extend_apply' _ _ _) fun ⟨a, _⟩ ↦ isEmptyElim a
open Relator
variable {α β : Type*} (R : α → β → Prop)
@[simp]
theorem leftTotal_empty [IsEmpty α] : LeftTotal R := by
simp only [LeftTotal, IsEmpty.forall_iff]
theorem leftTotal_iff_isEmpty_left [IsEmpty β] : LeftTotal R ↔ IsEmpty α := by
simp only [LeftTotal, IsEmpty.exists_iff, isEmpty_iff]
@[simp]
theorem rightTotal_empty [IsEmpty β] : RightTotal R := by
simp only [RightTotal, IsEmpty.forall_iff]
theorem rightTotal_iff_isEmpty_right [IsEmpty α] : RightTotal R ↔ IsEmpty β := by
simp only [RightTotal, IsEmpty.exists_iff, isEmpty_iff]
@[simp]
theorem biTotal_empty [IsEmpty α] [IsEmpty β] : BiTotal R :=
⟨leftTotal_empty R, rightTotal_empty R⟩
theorem biTotal_iff_isEmpty_right [IsEmpty α] : BiTotal R ↔ IsEmpty β := by
simp only [BiTotal, leftTotal_empty, rightTotal_iff_isEmpty_right, true_and]
theorem biTotal_iff_isEmpty_left [IsEmpty β] : BiTotal R ↔ IsEmpty α := by
simp only [BiTotal, leftTotal_iff_isEmpty_left, rightTotal_empty, and_true]
lemma Function.Bijective.of_isEmpty (f : α → β) [IsEmpty β] : f.Bijective :=
have := f.isEmpty
⟨injective_of_subsingleton _, IsEmpty.elim ‹_›⟩ |
.lake/packages/mathlib/Mathlib/Logic/UnivLE.lean | import Mathlib.Logic.Small.Defs
/-!
# UnivLE
A proposition expressing a universe inequality. `UnivLE.{u, v}` expresses that `u ≤ v`,
in the form `∀ α : Type u, Small.{v} α`.
This API indirectly provides an instance for `Small.{u, max u v}`, which could not be declared
directly due to https://github.com/leanprover/lean4/issues/2297.
See the doc-string for the comparison with an alternative stronger definition.
-/
universe u v w
noncomputable section
/--
A class expressing a universe inequality. `UnivLE.{u, v}` expresses that `u ≤ v`.
There used to be a stronger definition `∀ α : Type max u v, Small.{v} α` that immediately implies
`Small.{v} ((α : Type u) → (β : Type v))` which is essential for proving that `Type v` has
`Type u`-indexed limits when `u ≤ v`. However the current weaker condition
`∀ α : Type u, Small.{v} α` also implies the same, so we switched to use it for
its simplicity and transitivity.
The strong definition easily implies the weaker definition (see below),
but we cannot prove the reverse implication.
This is because in Lean's type theory, while `max u v` is at least at big as `u` and `v`,
it could be bigger than both!
See also `Mathlib/CategoryTheory/UnivLE.lean` for the statement that the stronger definition is
equivalent to `EssSurj (uliftFunctor : Type v ⥤ Type max u v)`.
-/
@[pp_with_univ, mk_iff]
class UnivLE : Prop where
small (α : Type u) : Small.{v} α
attribute [instance] UnivLE.small
/- This is useless as an instance due to https://github.com/leanprover/lean4/issues/2297 -/
theorem univLE_max : UnivLE.{u, max u v} where small α := small_max.{v} α
theorem Small.trans_univLE (α : Type w) [hα : Small.{u} α] [h : UnivLE.{u, v}] :
Small.{v} α :=
let ⟨β, ⟨f⟩⟩ := hα.equiv_small
let ⟨_, ⟨g⟩⟩ := (h.small β).equiv_small
⟨_, ⟨f.trans g⟩⟩
theorem UnivLE.trans [UnivLE.{u, v}] [UnivLE.{v, w}] : UnivLE.{u, w} where
small α := Small.trans_univLE α
instance UnivLE.self : UnivLE.{u, u} := ⟨inferInstance⟩
instance UnivLE.zero : UnivLE.{0, u} := ⟨inferInstance⟩
/-- This is redundant as an instance given the below. -/
theorem UnivLE.succ [UnivLE.{u, v}] : UnivLE.{u, v + 1} := @UnivLE.trans _ ⟨inferInstance⟩
/- This is the crucial instance that subsumes `univLE_max`. -/
instance univLE_of_max [UnivLE.{max u v, v}] : UnivLE.{u, v} := @UnivLE.trans univLE_max ‹_›
-- order doesn't matter
example : UnivLE.{v, max v u} := inferInstance
example : UnivLE.{v, max u v} := inferInstance
example : UnivLE.{u, max v u} := inferInstance
example : UnivLE.{u, max u v} := inferInstance
-- `succ` is implied
example : UnivLE.{u, u + 1} := inferInstance
example : UnivLE.{2, 5} := inferInstance
/- When `small_Pi` from `Mathlib/Logic/Small/Basic.lean` is imported, we have : -/
-- example (α : Type u) (β : Type v) [UnivLE.{u, v}] : Small.{v} (α → β) := inferInstance
example : ¬UnivLE.{u + 1, u} := by
simp only [univLE_iff, small_iff, not_forall, not_exists, not_nonempty_iff]
exact ⟨Type u, fun α => ⟨fun f => Function.not_surjective_Type.{u, u} f.symm f.symm.surjective⟩⟩ |
.lake/packages/mathlib/Mathlib/Logic/Denumerable.lean | import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.List.MinMax
import Mathlib.Data.Nat.Order.Lemmas
import Mathlib.Logic.Encodable.Basic
/-!
# Denumerable types
This file defines denumerable (countably infinite) types as a typeclass extending `Encodable`. This
is used to provide explicit encode/decode functions from and to `ℕ`, with the information that those
functions are inverses of each other.
## Implementation notes
This property already has a name, namely `α ≃ ℕ`, but here we are interested in using it as a
typeclass.
-/
assert_not_exists Monoid
variable {α β : Type*}
/-- A denumerable type is (constructively) bijective with `ℕ`. Typeclass equivalent of `α ≃ ℕ`. -/
class Denumerable (α : Type*) extends Encodable α where
/-- `decode` and `encode` are inverses. -/
decode_inv : ∀ n, ∃ a ∈ decode n, encode a = n
open Finset Nat
namespace Denumerable
section
variable [Denumerable α] [Denumerable β]
open Encodable
theorem decode_isSome (α) [Denumerable α] (n : ℕ) : (decode (α := α) n).isSome :=
Option.isSome_iff_exists.2 <| (decode_inv n).imp fun _ => And.left
/-- Returns the `n`-th element of `α` indexed by the decoding. -/
def ofNat (α) [Denumerable α] (n : ℕ) : α :=
Option.get _ (decode_isSome α n)
@[simp]
theorem decode_eq_ofNat (α) [Denumerable α] (n : ℕ) : decode (α := α) n = some (ofNat α n) :=
Option.eq_some_of_isSome _
theorem ofNat_of_decode {n b} (h : decode (α := α) n = some b) : ofNat (α := α) n = b := by
simpa using h
@[simp]
theorem encode_ofNat (n) : encode (ofNat α n) = n := by
obtain ⟨a, h, e⟩ := decode_inv (α := α) n
rwa [ofNat_of_decode h]
@[simp]
theorem ofNat_encode (a) : ofNat α (encode a) = a :=
ofNat_of_decode (encodek _)
/-- A denumerable type is equivalent to `ℕ`. -/
def eqv (α) [Denumerable α] : α ≃ ℕ :=
⟨encode, ofNat α, ofNat_encode, encode_ofNat⟩
-- See Note [lower instance priority]
instance (priority := 100) : Infinite α :=
Infinite.of_surjective _ (eqv α).surjective
/-- A type equivalent to `ℕ` is denumerable. -/
def mk' {α} (e : α ≃ ℕ) : Denumerable α where
encode := e
decode := some ∘ e.symm
encodek _ := congr_arg some (e.symm_apply_apply _)
decode_inv _ := ⟨_, rfl, e.apply_symm_apply _⟩
/-- Denumerability is conserved by equivalences. This is transitivity of equivalence the denumerable
way. -/
def ofEquiv (α) {β} [Denumerable α] (e : β ≃ α) : Denumerable β :=
{ Encodable.ofEquiv _ e with
decode_inv := fun n => by
simp [decode_ofEquiv, encode_ofEquiv] }
@[simp]
theorem ofEquiv_ofNat (α) {β} [Denumerable α] (e : β ≃ α) (n) :
@ofNat β (ofEquiv _ e) n = e.symm (ofNat α n) := by
letI := ofEquiv _ e
refine ofNat_of_decode ?_
rw [decode_ofEquiv e]
simp
/-- All denumerable types are equivalent. -/
def equiv₂ (α β) [Denumerable α] [Denumerable β] : α ≃ β :=
(eqv α).trans (eqv β).symm
instance nat : Denumerable ℕ :=
⟨fun _ => ⟨_, rfl, rfl⟩⟩
@[simp]
theorem ofNat_nat (n) : ofNat ℕ n = n :=
rfl
/-- If `α` is denumerable, then so is `Option α`. -/
instance option : Denumerable (Option α) :=
⟨fun n => by
cases n with
| zero =>
refine ⟨none, ?_, encode_none⟩
rw [decode_option_zero, Option.mem_def]
| succ n =>
refine ⟨some (ofNat α n), ?_, ?_⟩
· rw [decode_option_succ, decode_eq_ofNat, Option.map_some, Option.mem_def]
rw [encode_some, encode_ofNat]⟩
/-- If `α` and `β` are denumerable, then so is their sum. -/
instance sum : Denumerable (α ⊕ β) :=
⟨fun n => by
suffices ∃ a ∈ @decodeSum α β _ _ n, encodeSum a = bit (bodd n) (div2 n) by
simpa [bit_bodd_div2]
simp only [decodeSum, boddDiv2_eq, decode_eq_ofNat, Option.map_some,
Option.mem_def, Sum.exists]
cases bodd n <;> simp [bit, encodeSum, Nat.two_mul]⟩
section Sigma
variable {γ : α → Type*} [∀ a, Denumerable (γ a)]
/-- A denumerable collection of denumerable types is denumerable. -/
instance sigma : Denumerable (Sigma γ) :=
⟨fun n => by simp⟩
@[simp]
theorem sigma_ofNat_val (n : ℕ) :
ofNat (Sigma γ) n = ⟨ofNat α (unpair n).1, ofNat (γ _) (unpair n).2⟩ :=
Option.some.inj <| by rw [← decode_eq_ofNat, decode_sigma_val]; simp
end Sigma
/-- If `α` and `β` are denumerable, then so is their product. -/
instance prod : Denumerable (α × β) :=
ofEquiv _ (Equiv.sigmaEquivProd α β).symm
theorem prod_ofNat_val (n : ℕ) :
ofNat (α × β) n = (ofNat α (unpair n).1, ofNat β (unpair n).2) := by simp
@[simp]
theorem prod_nat_ofNat : ofNat (ℕ × ℕ) = unpair := by funext; simp
instance int : Denumerable ℤ :=
Denumerable.mk' Equiv.intEquivNat
instance pnat : Denumerable ℕ+ :=
Denumerable.mk' Equiv.pnatEquivNat
/-- The lift of a denumerable type is denumerable. -/
instance ulift : Denumerable (ULift α) :=
ofEquiv _ Equiv.ulift
/-- The lift of a denumerable type is denumerable. -/
instance plift : Denumerable (PLift α) :=
ofEquiv _ Equiv.plift
/-- If `α` is denumerable, then `α × α` and `α` are equivalent. -/
def pair : α × α ≃ α :=
equiv₂ _ _
end
end Denumerable
namespace Nat.Subtype
open Function Encodable
/-! ### Subsets of `ℕ` -/
variable {s : Set ℕ} [Infinite s]
section Classical
theorem exists_succ (x : s) : ∃ n, (x : ℕ) + n + 1 ∈ s := by
by_contra h
have (a : ℕ) (ha : a ∈ s) : a < x + 1 :=
lt_of_not_ge fun hax => h ⟨a - (x + 1), by rwa [Nat.add_right_comm, Nat.add_sub_cancel' hax]⟩
classical
exact Fintype.false
⟨(((Multiset.range (succ x)).filter (· ∈ s)).pmap
(fun (y : ℕ) (hy : y ∈ s) => Subtype.mk y hy) (by simp [-Multiset.range_succ])).toFinset,
by simpa [Subtype.ext_iff, Multiset.mem_filter, -Multiset.range_succ] ⟩
end Classical
variable [DecidablePred (· ∈ s)]
/-- Returns the next natural in a set, according to the usual ordering of `ℕ`. -/
def succ (x : s) : s :=
have h : ∃ m, (x : ℕ) + m + 1 ∈ s := exists_succ x
⟨↑x + Nat.find h + 1, Nat.find_spec h⟩
theorem succ_le_of_lt {x y : s} (h : y < x) : succ y ≤ x :=
have hx : ∃ m, (y : ℕ) + m + 1 ∈ s := exists_succ _
let ⟨k, hk⟩ := Nat.exists_eq_add_of_lt h
have : Nat.find hx ≤ k := Nat.find_min' _ (hk ▸ x.2)
show (y : ℕ) + Nat.find hx + 1 ≤ x by cutsat
theorem le_succ_of_forall_lt_le {x y : s} (h : ∀ z < x, z ≤ y) : x ≤ succ y :=
have hx : ∃ m, (y : ℕ) + m + 1 ∈ s := exists_succ _
show (x : ℕ) ≤ (y : ℕ) + Nat.find hx + 1 from
le_of_not_gt fun hxy =>
(h ⟨_, Nat.find_spec hx⟩ hxy).not_gt <|
(by cutsat : (y : ℕ) < (y : ℕ) + Nat.find hx + 1)
theorem lt_succ_self (x : s) : x < succ x :=
calc
(x : ℕ) ≤ (x + _) := le_add_right ..
_ < (succ x) := Nat.lt_succ_self (x + _)
theorem lt_succ_iff_le {x y : s} : x < succ y ↔ x ≤ y :=
⟨fun h => le_of_not_gt fun h' => not_le_of_gt h (succ_le_of_lt h'), fun h =>
lt_of_le_of_lt h (lt_succ_self _)⟩
/-- Returns the `n`-th element of a set, according to the usual ordering of `ℕ`. -/
def ofNat (s : Set ℕ) [DecidablePred (· ∈ s)] [Infinite s] : ℕ → s
| 0 => ⊥
| n + 1 => succ (ofNat s n)
theorem ofNat_surjective : Surjective (ofNat s)
| ⟨x, hx⟩ => by
set t : List s :=
((List.range x).filter fun y => y ∈ s).pmap
(fun (y : ℕ) (hy : y ∈ s) => ⟨y, hy⟩)
(by intro a ha; simpa using (List.mem_filter.mp ha).2) with ht
have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
simp [List.mem_filter, Subtype.ext_iff, ht]
cases hmax : List.maximum t with
| bot =>
refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (a := (⊥ : s)) ?_)⟩
rwa [← List.maximum_eq_bot.1 hmax, hmt]
| coe m =>
have wf : ↑m < x := by simpa using hmt.mp (List.maximum_mem hmax)
rcases ofNat_surjective m with ⟨a, rfl⟩
refine ⟨a + 1, le_antisymm (succ_le_of_lt wf) ?_⟩
exact le_succ_of_forall_lt_le fun z hz => List.le_maximum_of_mem (hmt.2 hz) hmax
termination_by n => n.val
@[simp]
theorem ofNat_range : Set.range (ofNat s) = Set.univ :=
ofNat_surjective.range_eq
@[simp]
theorem coe_comp_ofNat_range : Set.range ((↑) ∘ ofNat s : ℕ → ℕ) = s := by
rw [Set.range_comp Subtype.val, ofNat_range, Set.image_univ, Subtype.range_coe]
private def toFunAux (x : s) : ℕ :=
(List.range x).countP (· ∈ s)
private theorem toFunAux_eq {s : Set ℕ} [DecidablePred (· ∈ s)] (x : s) :
toFunAux x = #{y ∈ Finset.range x | y ∈ s} := by
rw [toFunAux, List.countP_eq_length_filter]
rfl
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
| 0 => by
rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_notMem]
rintro n hn
rw [mem_filter, ofNat, mem_range] at hn
exact bot_le.not_gt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
| n + 1 => by
have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
have h₁ : (ofNat s n : ℕ) ∉ {x ∈ range (ofNat s n) | x ∈ s} := by simp
have h₂ : {x ∈ range (succ (ofNat s n)) | x ∈ s} =
insert ↑(ofNat s n) {x ∈ range (ofNat s n) | x ∈ s} := by
simp only [Finset.ext_iff, mem_insert, mem_range, mem_filter]
exact fun m =>
⟨fun h => by
simp only [h.2, and_true]
exact Or.symm (lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1)),
fun h =>
h.elim (fun h => h.symm ▸ ⟨lt_succ_self _, (ofNat s n).prop⟩) fun h =>
⟨h.1.trans (lt_succ_self _), h.2⟩⟩
simp only [toFunAux_eq, ofNat] at ih ⊢
conv =>
rhs
rw [← ih, ← card_insert_of_notMem h₁, ← h₂]
/-- Any infinite set of naturals is denumerable. -/
def denumerable (s : Set ℕ) [DecidablePred (· ∈ s)] [Infinite s] : Denumerable s :=
Denumerable.ofEquiv ℕ
{ toFun := toFunAux
invFun := ofNat s
left_inv := leftInverse_of_surjective_of_rightInverse ofNat_surjective right_inverse_aux
right_inv := right_inverse_aux }
end Nat.Subtype
namespace Denumerable
open Encodable
/-- An infinite encodable type is denumerable. -/
def ofEncodableOfInfinite (α : Type*) [Encodable α] [Infinite α] : Denumerable α := by
letI := @decidableRangeEncode α _
letI : Infinite (Set.range (@encode α _)) :=
Infinite.of_injective _ (Equiv.ofInjective _ encode_injective).injective
letI := Nat.Subtype.denumerable (Set.range (@encode α _))
exact Denumerable.ofEquiv (Set.range (@encode α _)) (equivRangeEncode α)
end Denumerable
/-- See also `nonempty_encodable`, `nonempty_fintype`. -/
theorem nonempty_denumerable (α : Type*) [Countable α] [Infinite α] : Nonempty (Denumerable α) :=
(nonempty_encodable α).map fun h => @Denumerable.ofEncodableOfInfinite _ h _
theorem nonempty_denumerable_iff {α : Type*} :
Nonempty (Denumerable α) ↔ Countable α ∧ Infinite α :=
⟨fun ⟨_⟩ ↦ ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ ↦ nonempty_denumerable _⟩
instance nonempty_equiv_of_countable [Countable α] [Infinite α] [Countable β] [Infinite β] :
Nonempty (α ≃ β) := by
cases nonempty_denumerable α
cases nonempty_denumerable β
exact ⟨(Denumerable.eqv _).trans (Denumerable.eqv _).symm⟩ |
.lake/packages/mathlib/Mathlib/Logic/Nonempty.lean | import Mathlib.Tactic.TypeStar
/-!
# Nonempty types
This file proves a few extra facts about `Nonempty`, which is defined in core Lean.
## Main declarations
* `Nonempty.some`: Extracts a witness of nonemptiness using choice. Takes `Nonempty α` explicitly.
* `Classical.arbitrary`: Extracts a witness of nonemptiness using choice. Takes `Nonempty α` as an
instance.
-/
section
variable {α β : Sort*}
@[simp]
theorem Nonempty.forall {α} {p : Nonempty α → Prop} : (∀ h : Nonempty α, p h) ↔ ∀ a, p ⟨a⟩ :=
Iff.intro (fun h _ ↦ h _) fun h ⟨a⟩ ↦ h a
@[simp]
theorem Nonempty.exists {α} {p : Nonempty α → Prop} : (∃ h : Nonempty α, p h) ↔ ∃ a, p ⟨a⟩ :=
Iff.intro (fun ⟨⟨a⟩, h⟩ ↦ ⟨a, h⟩) fun ⟨a, h⟩ ↦ ⟨⟨a⟩, h⟩
-- Note: we set low priority here, to ensure it is not applied before `exists_prop`
-- and `exists_const`.
@[simp low]
theorem exists_const_iff {α : Sort*} {P : Prop} : (∃ _ : α, P) ↔ Nonempty α ∧ P :=
Iff.intro (fun ⟨a, h⟩ ↦ ⟨⟨a⟩, h⟩) fun ⟨⟨a⟩, h⟩ ↦ ⟨a, h⟩
theorem exists_true_iff_nonempty {α : Sort*} : (∃ _ : α, True) ↔ Nonempty α :=
Iff.intro (fun ⟨a, _⟩ ↦ ⟨a⟩) fun ⟨a⟩ ↦ ⟨a, trivial⟩
theorem Nonempty.imp {α} {p : Prop} : (Nonempty α → p) ↔ (α → p) :=
Nonempty.forall
theorem not_nonempty_iff_imp_false {α : Sort*} : ¬Nonempty α ↔ α → False :=
Nonempty.imp
@[simp]
theorem nonempty_psigma {α} {β : α → Sort*} : Nonempty (PSigma β) ↔ ∃ a : α, Nonempty (β a) :=
Iff.intro (fun ⟨⟨a, c⟩⟩ ↦ ⟨a, ⟨c⟩⟩) fun ⟨a, ⟨c⟩⟩ ↦ ⟨⟨a, c⟩⟩
@[simp]
theorem nonempty_subtype {α} {p : α → Prop} : Nonempty (Subtype p) ↔ ∃ a : α, p a :=
Iff.intro (fun ⟨⟨a, h⟩⟩ ↦ ⟨a, h⟩) fun ⟨a, h⟩ ↦ ⟨⟨a, h⟩⟩
@[simp]
theorem nonempty_pprod {α β} : Nonempty (PProd α β) ↔ Nonempty α ∧ Nonempty β :=
Iff.intro (fun ⟨⟨a, b⟩⟩ ↦ ⟨⟨a⟩, ⟨b⟩⟩) fun ⟨⟨a⟩, ⟨b⟩⟩ ↦ ⟨⟨a, b⟩⟩
@[simp]
theorem nonempty_psum {α β} : Nonempty (α ⊕' β) ↔ Nonempty α ∨ Nonempty β :=
Iff.intro
(fun ⟨h⟩ ↦
match h with
| PSum.inl a => Or.inl ⟨a⟩
| PSum.inr b => Or.inr ⟨b⟩)
fun h ↦
match h with
| Or.inl ⟨a⟩ => ⟨PSum.inl a⟩
| Or.inr ⟨b⟩ => ⟨PSum.inr b⟩
@[simp]
theorem nonempty_plift {α} : Nonempty (PLift α) ↔ Nonempty α :=
Iff.intro (fun ⟨⟨a⟩⟩ ↦ ⟨a⟩) fun ⟨a⟩ ↦ ⟨⟨a⟩⟩
/-- Using `Classical.choice`, lifts a (`Prop`-valued) `Nonempty` instance to a (`Type`-valued)
`Inhabited` instance. `Classical.inhabited_of_nonempty` already exists, in `Init/Classical.lean`,
but the assumption is not a type class argument, which makes it unsuitable for some applications. -/
noncomputable def Classical.inhabited_of_nonempty' {α} [h : Nonempty α] : Inhabited α :=
⟨Classical.choice h⟩
/-- Using `Classical.choice`, extracts a term from a `Nonempty` type. -/
protected noncomputable abbrev Nonempty.some {α} (h : Nonempty α) : α :=
Classical.choice h
/-- Using `Classical.choice`, extracts a term from a `Nonempty` type. -/
protected noncomputable abbrev Classical.arbitrary (α) [h : Nonempty α] : α :=
Classical.choice h
/-- Given `f : α → β`, if `α` is nonempty then `β` is also nonempty.
`Nonempty` cannot be a `functor`, because `Functor` is restricted to `Type`. -/
theorem Nonempty.map {α β} (f : α → β) : Nonempty α → Nonempty β
| ⟨h⟩ => ⟨f h⟩
protected theorem Nonempty.map2 {α β γ : Sort*} (f : α → β → γ) :
Nonempty α → Nonempty β → Nonempty γ
| ⟨x⟩, ⟨y⟩ => ⟨f x y⟩
protected theorem Nonempty.congr {α β} (f : α → β) (g : β → α) : Nonempty α ↔ Nonempty β :=
⟨Nonempty.map f, Nonempty.map g⟩
theorem Nonempty.elim_to_inhabited {α : Sort*} [h : Nonempty α] {p : Prop} (f : Inhabited α → p) :
p :=
h.elim <| f ∘ Inhabited.mk
theorem Classical.nonempty_pi {ι} {α : ι → Sort*} : Nonempty (∀ i, α i) ↔ ∀ i, Nonempty (α i) :=
⟨fun ⟨f⟩ a ↦ ⟨f a⟩, @Pi.instNonempty _ _⟩
theorem subsingleton_of_not_nonempty {α : Sort*} (h : ¬Nonempty α) : Subsingleton α :=
⟨fun x ↦ False.elim <| not_nonempty_iff_imp_false.mp h x⟩
theorem Function.Surjective.nonempty [h : Nonempty β] {f : α → β} (hf : Function.Surjective f) :
Nonempty α :=
let ⟨y⟩ := h
let ⟨x, _⟩ := hf y
⟨x⟩
end
section
variable {α β : Type*} {γ : α → Type*}
@[simp]
theorem nonempty_sigma : Nonempty (Σ a : α, γ a) ↔ ∃ a : α, Nonempty (γ a) :=
Iff.intro (fun ⟨⟨a, c⟩⟩ ↦ ⟨a, ⟨c⟩⟩) fun ⟨a, ⟨c⟩⟩ ↦ ⟨⟨a, c⟩⟩
@[simp]
theorem nonempty_sum : Nonempty (α ⊕ β) ↔ Nonempty α ∨ Nonempty β :=
Iff.intro
(fun ⟨h⟩ ↦
match h with
| Sum.inl a => Or.inl ⟨a⟩
| Sum.inr b => Or.inr ⟨b⟩)
fun h ↦
match h with
| Or.inl ⟨a⟩ => ⟨Sum.inl a⟩
| Or.inr ⟨b⟩ => ⟨Sum.inr b⟩
@[simp]
theorem nonempty_prod : Nonempty (α × β) ↔ Nonempty α ∧ Nonempty β :=
Iff.intro (fun ⟨⟨a, b⟩⟩ ↦ ⟨⟨a⟩, ⟨b⟩⟩) fun ⟨⟨a⟩, ⟨b⟩⟩ ↦ ⟨⟨a, b⟩⟩
@[simp]
theorem nonempty_ulift : Nonempty (ULift α) ↔ Nonempty α :=
Iff.intro (fun ⟨⟨a⟩⟩ ↦ ⟨a⟩) fun ⟨a⟩ ↦ ⟨⟨a⟩⟩
end |
.lake/packages/mathlib/Mathlib/Logic/Basic.lean | import Mathlib.Tactic.Attr.Register
import Mathlib.Tactic.AdaptationNote
import Mathlib.Tactic.Basic
import Batteries.Logic
import Batteries.Tactic.Trans
import Batteries.Util.LibraryNote
import Mathlib.Data.Nat.Notation
import Mathlib.Data.Int.Notation
/-!
# Basic logic properties
This file is one of the earliest imports in mathlib.
## Implementation notes
Theorems that require decidability hypotheses are in the namespace `Decidable`.
Classical versions are in the namespace `Classical`.
-/
open Function
section Miscellany
-- attribute [refl] HEq.refl -- FIXME This is still rejected after https://github.com/leanprover-community/mathlib4/pull/857
/-- An identity function with its main argument implicit. This will be printed as `hidden` even
if it is applied to a large term, so it can be used for elision,
as done in the `elide` and `unelide` tactics. -/
abbrev hidden {α : Sort*} {a : α} := a
variable {α : Sort*}
instance (priority := 10) decidableEq_of_subsingleton [Subsingleton α] : DecidableEq α :=
fun a b ↦ isTrue (Subsingleton.elim a b)
instance [Subsingleton α] (p : α → Prop) : Subsingleton (Subtype p) :=
⟨fun ⟨x, _⟩ ⟨y, _⟩ ↦ by cases Subsingleton.elim x y; rfl⟩
theorem congr_heq {α β γ : Sort _} {f : α → γ} {g : β → γ} {x : α} {y : β}
(h₁ : f ≍ g) (h₂ : x ≍ y) : f x = g y := by
cases h₂; cases h₁; rfl
theorem congr_arg_heq {β : α → Sort*} (f : ∀ a, β a) :
∀ {a₁ a₂ : α}, a₁ = a₂ → f a₁ ≍ f a₂
| _, _, rfl => HEq.rfl
theorem dcongr_heq.{u, v}
{α₁ α₂ : Sort u}
{β₁ : α₁ → Sort v} {β₂ : α₂ → Sort v}
{f₁ : ∀ a, β₁ a} {f₂ : ∀ a, β₂ a}
{a₁ : α₁} {a₂ : α₂}
(hargs : a₁ ≍ a₂)
(ht : ∀ t₁ t₂, t₁ ≍ t₂ → β₁ t₁ = β₂ t₂)
(hf : α₁ = α₂ → β₁ ≍ β₂ → f₁ ≍ f₂) :
f₁ a₁ ≍ f₂ a₂ := by
cases hargs
cases funext fun v => ht v v .rfl
cases hf rfl .rfl
rfl
@[simp] theorem eq_iff_eq_cancel_left {b c : α} : (∀ {a}, a = b ↔ a = c) ↔ b = c :=
⟨fun h ↦ by rw [← h], fun h a ↦ by rw [h]⟩
@[simp] theorem eq_iff_eq_cancel_right {a b : α} : (∀ {c}, a = c ↔ b = c) ↔ a = b :=
⟨fun h ↦ by rw [h], fun h a ↦ by rw [h]⟩
lemma ne_and_eq_iff_right {a b c : α} (h : b ≠ c) : a ≠ b ∧ a = c ↔ a = c :=
and_iff_right_of_imp (fun h2 => h2.symm ▸ h.symm)
/-- Wrapper for adding elementary propositions to the type class systems.
Warning: this can easily be abused. See the rest of this docstring for details.
Certain propositions should not be treated as a class globally,
but sometimes it is very convenient to be able to use the type class system
in specific circumstances.
For example, `ZMod p` is a field if and only if `p` is a prime number.
In order to be able to find this field instance automatically by type class search,
we have to turn `p.prime` into an instance implicit assumption.
On the other hand, making `Nat.prime` a class would require a major refactoring of the library,
and it is questionable whether making `Nat.prime` a class is desirable at all.
The compromise is to add the assumption `[Fact p.prime]` to `ZMod.field`.
In particular, this class is not intended for turning the type class system
into an automated theorem prover for first-order logic. -/
class Fact (p : Prop) : Prop where
/-- `Fact.out` contains the unwrapped witness for the fact represented by the instance of
`Fact p`. -/
out : p
library_note2 «fact non-instances» /--
In most cases, we should not have global instances of `Fact`; typeclass search is not an
advanced proof search engine, and adding any such instance has the potential to cause
slowdowns everywhere. We instead declare them as lemmata and make them local instances as required.
-/
theorem Fact.elim {p : Prop} (h : Fact p) : p := h.1
theorem fact_iff {p : Prop} : Fact p ↔ p := ⟨fun h ↦ h.1, fun h ↦ ⟨h⟩⟩
instance {p : Prop} [Decidable p] : Decidable (Fact p) :=
decidable_of_iff _ fact_iff.symm
/-- Swaps two pairs of arguments to a function. -/
abbrev Function.swap₂ {ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*}
{φ : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Sort*} (f : ∀ i₁ j₁ i₂ j₂, φ i₁ j₁ i₂ j₂)
(i₂ j₂ i₁ j₁) : φ i₁ j₁ i₂ j₂ := f i₁ j₁ i₂ j₂
end Miscellany
/-!
### Declarations about propositional connectives
-/
section Propositional
/-! ### Declarations about `implies` -/
alias Iff.imp := imp_congr
-- This is a duplicate of `Classical.imp_iff_right_iff`. Deprecate?
theorem imp_iff_right_iff {a b : Prop} : (a → b ↔ b) ↔ a ∨ b :=
open scoped Classical in Decidable.imp_iff_right_iff
-- This is a duplicate of `Classical.and_or_imp`. Deprecate?
theorem and_or_imp {a b c : Prop} : a ∧ b ∨ (a → c) ↔ a → b ∨ c :=
open scoped Classical in Decidable.and_or_imp
/-- Provide modus tollens (`mt`) as dot notation for implications. -/
protected theorem Function.mt {a b : Prop} : (a → b) → ¬b → ¬a := mt
/-! ### Declarations about `not` -/
alias dec_em := Decidable.em
theorem dec_em' (p : Prop) [Decidable p] : ¬p ∨ p := (dec_em p).symm
alias em := Classical.em
theorem em' (p : Prop) : ¬p ∨ p := (em p).symm
theorem or_not {p : Prop} : p ∨ ¬p := em _
theorem Decidable.eq_or_ne {α : Sort*} (x y : α) [Decidable (x = y)] : x = y ∨ x ≠ y :=
dec_em <| x = y
theorem Decidable.ne_or_eq {α : Sort*} (x y : α) [Decidable (x = y)] : x ≠ y ∨ x = y :=
dec_em' <| x = y
theorem eq_or_ne {α : Sort*} (x y : α) : x = y ∨ x ≠ y := em <| x = y
theorem ne_or_eq {α : Sort*} (x y : α) : x ≠ y ∨ x = y := em' <| x = y
theorem by_contradiction {p : Prop} : (¬p → False) → p :=
open scoped Classical in Decidable.byContradiction
theorem by_cases {p q : Prop} (hpq : p → q) (hnpq : ¬p → q) : q :=
open scoped Classical in if hp : p then hpq hp else hnpq hp
alias by_contra := by_contradiction
library_note2 «decidable namespace» /--
In most of mathlib, we use the law of excluded middle (LEM) and the axiom of choice (AC) freely.
The `Decidable` namespace contains versions of lemmas from the root namespace that explicitly
attempt to avoid the axiom of choice, usually by adding decidability assumptions on the inputs.
You can check if a lemma uses the axiom of choice by using `#print axioms foo` and seeing if
`Classical.choice` appears in the list.
-/
library_note2 «decidable arguments» /--
As mathlib is primarily classical,
if the type signature of a `def` or `lemma` does not require any `Decidable` instances to state,
it is preferable not to introduce any `Decidable` instances that are needed in the proof
as arguments, but rather to use the `classical` tactic as needed.
In the other direction, when `Decidable` instances do appear in the type signature,
it is better to use explicitly introduced ones rather than allowing Lean to automatically infer
classical ones, as these may cause instance mismatch errors later.
-/
export Classical (not_not)
attribute [simp] not_not
variable {a b : Prop}
theorem of_not_not {a : Prop} : ¬¬a → a := by_contra
theorem not_ne_iff {α : Sort*} {a b : α} : ¬a ≠ b ↔ a = b := not_not
theorem of_not_imp : ¬(a → b) → a := open scoped Classical in Decidable.of_not_imp
alias Not.decidable_imp_symm := Decidable.not_imp_symm
theorem Not.imp_symm : (¬a → b) → ¬b → a := open scoped Classical in Not.decidable_imp_symm
theorem not_imp_comm : ¬a → b ↔ ¬b → a := open scoped Classical in Decidable.not_imp_comm
@[simp] theorem not_imp_self : ¬a → a ↔ a := open scoped Classical in Decidable.not_imp_self
theorem Imp.swap {a b : Sort*} {c : Prop} : a → b → c ↔ b → a → c :=
⟨fun h x y ↦ h y x, fun h x y ↦ h y x⟩
alias Iff.not := not_congr
theorem Iff.not_left (h : a ↔ ¬b) : ¬a ↔ b := h.not.trans not_not
theorem Iff.not_right (h : ¬a ↔ b) : a ↔ ¬b := not_not.symm.trans h.not
protected lemma Iff.ne {α β : Sort*} {a b : α} {c d : β} : (a = b ↔ c = d) → (a ≠ b ↔ c ≠ d) :=
Iff.not
lemma Iff.ne_left {α β : Sort*} {a b : α} {c d : β} : (a = b ↔ c ≠ d) → (a ≠ b ↔ c = d) :=
Iff.not_left
lemma Iff.ne_right {α β : Sort*} {a b : α} {c d : β} : (a ≠ b ↔ c = d) → (a = b ↔ c ≠ d) :=
Iff.not_right
/-! ### Declarations about `Xor'` -/
#adaptation_note
/--
2025-07-31. Upstream `Xor` has been renamed to `XorOp`.
2025-09-16. The deprecation for `Xor` has been removed.
Anytime after v4.25.0-rc1 lands we rename this back to `Xor`.
-/
/-- `Xor' a b` is the exclusive-or of propositions. -/
def Xor' (a b : Prop) := (a ∧ ¬b) ∨ (b ∧ ¬a)
@[grind =] theorem xor_def {a b : Prop} : Xor' a b ↔ (a ∧ ¬b) ∨ (b ∧ ¬a) := Iff.rfl
instance [Decidable a] [Decidable b] : Decidable (Xor' a b) := inferInstanceAs (Decidable (Or ..))
@[simp] theorem xor_true : Xor' True = Not := by grind
@[simp] theorem xor_false : Xor' False = id := by grind
theorem xor_comm (a b : Prop) : Xor' a b = Xor' b a := by grind
instance : Std.Commutative Xor' := ⟨xor_comm⟩
@[simp] theorem xor_self (a : Prop) : Xor' a a = False := by grind
@[simp] theorem xor_not_left : Xor' (¬a) b ↔ (a ↔ b) := by grind
@[simp] theorem xor_not_right : Xor' a (¬b) ↔ (a ↔ b) := by grind
theorem xor_not_not : Xor' (¬a) (¬b) ↔ Xor' a b := by grind
protected theorem Xor'.or (h : Xor' a b) : a ∨ b := by grind
/-! ### Declarations about `and` -/
alias Iff.and := and_congr
alias ⟨And.rotate, _⟩ := and_rotate
theorem and_symm_right {α : Sort*} (a b : α) (p : Prop) : p ∧ a = b ↔ p ∧ b = a := by simp [eq_comm]
theorem and_symm_left {α : Sort*} (a b : α) (p : Prop) : a = b ∧ p ↔ b = a ∧ p := by simp [eq_comm]
/-! ### Declarations about `or` -/
alias Iff.or := or_congr
alias ⟨Or.rotate, _⟩ := or_rotate
theorem Or.elim3 {c d : Prop} (h : a ∨ b ∨ c) (ha : a → d) (hb : b → d) (hc : c → d) : d :=
Or.elim h ha fun h₂ ↦ Or.elim h₂ hb hc
theorem Or.imp3 {d e c f : Prop} (had : a → d) (hbe : b → e) (hcf : c → f) :
a ∨ b ∨ c → d ∨ e ∨ f :=
Or.imp had <| Or.imp hbe hcf
export Classical (or_iff_not_imp_left or_iff_not_imp_right)
theorem not_or_of_imp : (a → b) → ¬a ∨ b := open scoped Classical in Decidable.not_or_of_imp
-- See Note [decidable namespace]
protected theorem Decidable.or_not_of_imp [Decidable a] (h : a → b) : b ∨ ¬a :=
dite _ (Or.inl ∘ h) Or.inr
theorem or_not_of_imp : (a → b) → b ∨ ¬a := open scoped Classical in Decidable.or_not_of_imp
theorem imp_iff_not_or : a → b ↔ ¬a ∨ b := open scoped Classical in Decidable.imp_iff_not_or
theorem imp_iff_or_not {b a : Prop} : b → a ↔ a ∨ ¬b :=
open scoped Classical in Decidable.imp_iff_or_not
theorem not_imp_not : ¬a → ¬b ↔ b → a := open scoped Classical in Decidable.not_imp_not
theorem imp_and_neg_imp_iff (p q : Prop) : (p → q) ∧ (¬p → q) ↔ q := by simp
/-- Provide the reverse of modus tollens (`mt`) as dot notation for implications. -/
protected theorem Function.mtr : (¬a → ¬b) → b → a := not_imp_not.mp
theorem or_congr_left' {c a b : Prop} (h : ¬c → (a ↔ b)) : a ∨ c ↔ b ∨ c :=
open scoped Classical in Decidable.or_congr_left' h
theorem or_congr_right' {c : Prop} (h : ¬a → (b ↔ c)) : a ∨ b ↔ a ∨ c :=
open scoped Classical in Decidable.or_congr_right' h
/-! ### Declarations about distributivity -/
/-! Declarations about `iff` -/
alias Iff.iff := iff_congr
-- @[simp] -- FIXME simp ignores proof rewrites
theorem iff_mpr_iff_true_intro {P : Prop} (h : P) : Iff.mpr (iff_true_intro h) True.intro = h := rfl
theorem imp_or {a b c : Prop} : a → b ∨ c ↔ (a → b) ∨ (a → c) :=
open scoped Classical in Decidable.imp_or
theorem imp_or' {a : Sort*} {b c : Prop} : a → b ∨ c ↔ (a → b) ∨ (a → c) :=
open scoped Classical in Decidable.imp_or'
theorem not_imp : ¬(a → b) ↔ a ∧ ¬b := open scoped Classical in Decidable.not_imp_iff_and_not
theorem peirce (a b : Prop) : ((a → b) → a) → a := open scoped Classical in Decidable.peirce _ _
theorem not_iff_not : (¬a ↔ ¬b) ↔ (a ↔ b) := open scoped Classical in Decidable.not_iff_not
theorem not_iff_comm : (¬a ↔ b) ↔ (¬b ↔ a) := open scoped Classical in Decidable.not_iff_comm
theorem not_iff : ¬(a ↔ b) ↔ (¬a ↔ b) := open scoped Classical in Decidable.not_iff
theorem iff_not_comm : (a ↔ ¬b) ↔ (b ↔ ¬a) := open scoped Classical in Decidable.iff_not_comm
theorem iff_iff_and_or_not_and_not : (a ↔ b) ↔ a ∧ b ∨ ¬a ∧ ¬b :=
open scoped Classical in Decidable.iff_iff_and_or_not_and_not
theorem iff_iff_not_or_and_or_not : (a ↔ b) ↔ (¬a ∨ b) ∧ (a ∨ ¬b) :=
open scoped Classical in Decidable.iff_iff_not_or_and_or_not
theorem not_and_not_right : ¬(a ∧ ¬b) ↔ a → b :=
open scoped Classical in Decidable.not_and_not_right
/-! ### De Morgan's laws -/
/-- One of **de Morgan's laws**: the negation of a conjunction is logically equivalent to the
disjunction of the negations. -/
theorem not_and_or : ¬(a ∧ b) ↔ ¬a ∨ ¬b := open scoped Classical in Decidable.not_and_iff_not_or_not
theorem or_iff_not_and_not : a ∨ b ↔ ¬(¬a ∧ ¬b) :=
open scoped Classical in Decidable.or_iff_not_not_and_not
theorem and_iff_not_or_not : a ∧ b ↔ ¬(¬a ∨ ¬b) :=
open scoped Classical in Decidable.and_iff_not_not_or_not
@[simp] theorem not_xor (P Q : Prop) : ¬Xor' P Q ↔ (P ↔ Q) := by
simp only [not_and, Xor', not_or, not_not, ← iff_iff_implies_and_implies]
theorem xor_iff_not_iff (P Q : Prop) : Xor' P Q ↔ ¬(P ↔ Q) := (not_xor P Q).not_right
theorem xor_iff_iff_not : Xor' a b ↔ (a ↔ ¬b) := by simp only [← @xor_not_right a, not_not]
theorem xor_iff_not_iff' : Xor' a b ↔ (¬a ↔ b) := by simp only [← @xor_not_left _ b, not_not]
theorem xor_iff_or_and_not_and (a b : Prop) : Xor' a b ↔ (a ∨ b) ∧ (¬(a ∧ b)) := by
rw [Xor', or_and_right, not_and_or, and_or_left, and_not_self_iff, false_or,
and_or_left, and_not_self_iff, or_false]
end Propositional
/-! ### Declarations about equality -/
section Equality
-- todo: change name
theorem forall_cond_comm {α} {s : α → Prop} {p : α → α → Prop} :
(∀ a, s a → ∀ b, s b → p a b) ↔ ∀ a b, s a → s b → p a b :=
⟨fun h a b ha hb ↦ h a ha b hb, fun h a ha b hb ↦ h a b ha hb⟩
theorem forall_mem_comm {α β} [Membership α β] {s : β} {p : α → α → Prop} :
(∀ a (_ : a ∈ s) b (_ : b ∈ s), p a b) ↔ ∀ a b, a ∈ s → b ∈ s → p a b :=
forall_cond_comm
lemma ne_of_eq_of_ne {α : Sort*} {a b c : α} (h₁ : a = b) (h₂ : b ≠ c) : a ≠ c := h₁.symm ▸ h₂
lemma ne_of_ne_of_eq {α : Sort*} {a b c : α} (h₁ : a ≠ b) (h₂ : b = c) : a ≠ c := h₂ ▸ h₁
alias Eq.trans_ne := ne_of_eq_of_ne
alias Ne.trans_eq := ne_of_ne_of_eq
theorem eq_equivalence {α : Sort*} : Equivalence (@Eq α) :=
⟨Eq.refl, @Eq.symm _, @Eq.trans _⟩
-- These were migrated to Batteries but the `@[simp]` attributes were (mysteriously?) removed.
attribute [simp] eq_mp_eq_cast eq_mpr_eq_cast
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_refl_left {α β : Sort*} (f : α → β) {a b : α} (h : a = b) :
congr (Eq.refl f) h = congr_arg f h := rfl
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_refl_right {α β : Sort*} {f g : α → β} (h : f = g) (a : α) :
congr h (Eq.refl a) = congr_fun h a := rfl
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_arg_refl {α β : Sort*} (f : α → β) (a : α) :
congr_arg f (Eq.refl a) = Eq.refl (f a) :=
rfl
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_fun_rfl {α β : Sort*} (f : α → β) (a : α) : congr_fun (Eq.refl f) a = Eq.refl (f a) :=
rfl
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_fun_congr_arg {α β γ : Sort*} (f : α → β → γ) {a a' : α} (p : a = a') (b : β) :
congr_fun (congr_arg f p) b = congr_arg (fun a ↦ f a b) p := rfl
@[deprecated (since := "2025-09-16")] alias Eq.rec_eq_cast := eqRec_eq_cast
@[deprecated (since := "2025-09-16")] alias eqRec_heq' := eqRec_heq_self
theorem rec_heq_of_heq {α β : Sort _} {a b : α} {C : α → Sort*} {x : C a} {y : β}
(e : a = b) (h : x ≍ y) : e ▸ x ≍ y :=
eqRec_heq_iff_heq.mpr h
@[deprecated (since := "2025-09-16")] alias rec_heq_iff_heq := eqRec_heq_iff_heq
@[deprecated (since := "2025-09-16")] alias heq_rec_iff_heq := heq_eqRec_iff_heq
@[simp]
theorem cast_heq_iff_heq {α β γ : Sort _} (e : α = β) (a : α) (c : γ) :
cast e a ≍ c ↔ a ≍ c := by subst e; rfl
@[simp]
theorem heq_cast_iff_heq {α β γ : Sort _} (e : β = γ) (a : α) (b : β) :
a ≍ cast e b ↔ a ≍ b := by subst e; rfl
universe u
variable {α β : Sort u} {e : β = α} {a : α} {b : β}
lemma heq_of_eq_cast (e : β = α) : a = cast e b → a ≍ b := by rintro rfl; simp
lemma eq_cast_iff_heq : a = cast e b ↔ a ≍ b := ⟨heq_of_eq_cast _, fun h ↦ by cases h; rfl⟩
lemma heq_iff_exists_eq_cast :
a ≍ b ↔ ∃ (h : β = α), a = cast h b :=
⟨fun h ↦ ⟨type_eq_of_heq h.symm, eq_cast_iff_heq.mpr h⟩,
by rintro ⟨rfl, h⟩; rw [h, cast_eq]⟩
lemma heq_iff_exists_cast_eq :
a ≍ b ↔ ∃ (h : α = β), cast h a = b := by
simp only [heq_comm (a := a), heq_iff_exists_eq_cast, eq_comm]
end Equality
/-! ### Declarations about quantifiers -/
section Quantifiers
section Dependent
variable {α : Sort*} {β : α → Sort*} {γ : ∀ a, β a → Sort*}
theorem forall₂_imp {p q : ∀ a, β a → Prop} (h : ∀ a b, p a b → q a b) :
(∀ a b, p a b) → ∀ a b, q a b :=
forall_imp fun i ↦ forall_imp <| h i
theorem forall₃_imp {p q : ∀ a b, γ a b → Prop} (h : ∀ a b c, p a b c → q a b c) :
(∀ a b c, p a b c) → ∀ a b c, q a b c :=
forall_imp fun a ↦ forall₂_imp <| h a
theorem Exists₂.imp {p q : ∀ a, β a → Prop} (h : ∀ a b, p a b → q a b) :
(∃ a b, p a b) → ∃ a b, q a b :=
Exists.imp fun a ↦ Exists.imp <| h a
theorem Exists₃.imp {p q : ∀ a b, γ a b → Prop} (h : ∀ a b c, p a b c → q a b c) :
(∃ a b c, p a b c) → ∃ a b c, q a b c :=
Exists.imp fun a ↦ Exists₂.imp <| h a
end Dependent
variable {α β : Sort*} {p : α → Prop}
theorem forall_swap {p : α → β → Prop} : (∀ x y, p x y) ↔ ∀ y x, p x y :=
⟨fun f x y ↦ f y x, fun f x y ↦ f y x⟩
theorem forall₂_swap
{ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*} {p : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Prop} :
(∀ i₁ j₁ i₂ j₂, p i₁ j₁ i₂ j₂) ↔ ∀ i₂ j₂ i₁ j₁, p i₁ j₁ i₂ j₂ := ⟨swap₂, swap₂⟩
/-- We intentionally restrict the type of `α` in this lemma so that this is a safer to use in simp
than `forall_swap`. -/
theorem imp_forall_iff {α : Type*} {p : Prop} {q : α → Prop} : (p → ∀ x, q x) ↔ ∀ x, p → q x :=
forall_swap
lemma imp_forall_iff_forall (A : Prop) (B : A → Prop) : (A → ∀ h : A, B h) ↔ ∀ h : A, B h := by
by_cases h : A <;> simp [h]
theorem exists_swap {p : α → β → Prop} : (∃ x y, p x y) ↔ ∃ y x, p x y :=
⟨fun ⟨x, y, h⟩ ↦ ⟨y, x, h⟩, fun ⟨y, x, h⟩ ↦ ⟨x, y, h⟩⟩
theorem exists_and_exists_comm {P : α → Prop} {Q : β → Prop} :
(∃ a, P a) ∧ (∃ b, Q b) ↔ ∃ a b, P a ∧ Q b :=
⟨fun ⟨⟨a, ha⟩, ⟨b, hb⟩⟩ ↦ ⟨a, b, ⟨ha, hb⟩⟩, fun ⟨a, b, ⟨ha, hb⟩⟩ ↦ ⟨⟨a, ha⟩, ⟨b, hb⟩⟩⟩
export Classical (not_forall)
theorem not_forall_not : (¬∀ x, ¬p x) ↔ ∃ x, p x :=
open scoped Classical in Decidable.not_forall_not
export Classical (not_exists_not)
lemma forall_or_exists_not (P : α → Prop) : (∀ a, P a) ∨ ∃ a, ¬P a := by
rw [← not_forall]; exact em _
lemma exists_or_forall_not (P : α → Prop) : (∃ a, P a) ∨ ∀ a, ¬P a := by
rw [← not_exists]; exact em _
theorem forall_imp_iff_exists_imp {α : Sort*} {p : α → Prop} {b : Prop} [ha : Nonempty α] :
(∀ x, p x) → b ↔ ∃ x, p x → b := by
classical
let ⟨a⟩ := ha
refine ⟨fun h ↦ not_forall_not.1 fun h' ↦ ?_, fun ⟨x, hx⟩ h ↦ hx (h x)⟩
exact if hb : b then h' a fun _ ↦ hb else hb <| h fun x ↦ (_root_.not_imp.1 (h' x)).1
@[mfld_simps]
theorem forall_true_iff : (α → True) ↔ True := imp_true_iff _
-- Unfortunately this causes simp to loop sometimes, so we
-- add the 2 and 3 cases as simp lemmas instead
theorem forall_true_iff' (h : ∀ a, p a ↔ True) : (∀ a, p a) ↔ True :=
iff_true_intro fun _ ↦ of_iff_true (h _)
-- This is not marked `@[simp]` because `implies_true : (α → True) = True` works
theorem forall₂_true_iff {β : α → Sort*} : (∀ a, β a → True) ↔ True := by simp
-- This is not marked `@[simp]` because `implies_true : (α → True) = True` works
theorem forall₃_true_iff {β : α → Sort*} {γ : ∀ a, β a → Sort*} :
(∀ (a) (b : β a), γ a b → True) ↔ True := by simp
theorem Decidable.and_forall_ne [DecidableEq α] (a : α) {p : α → Prop} :
(p a ∧ ∀ b, b ≠ a → p b) ↔ ∀ b, p b := by
simp only [← @forall_eq _ p a, ← forall_and, ← or_imp, Decidable.em, forall_const]
theorem and_forall_ne (a : α) : (p a ∧ ∀ b, b ≠ a → p b) ↔ ∀ b, p b :=
open scoped Classical in Decidable.and_forall_ne a
theorem Ne.ne_or_ne {x y : α} (z : α) (h : x ≠ y) : x ≠ z ∨ y ≠ z :=
not_and_or.1 <| mt (and_imp.2 (· ▸ ·)) h.symm
@[simp]
theorem exists_apply_eq_apply' (f : α → β) (a' : α) : ∃ a, f a' = f a := ⟨a', rfl⟩
@[simp]
lemma exists_apply_eq_apply2 {α β γ} {f : α → β → γ} {a : α} {b : β} : ∃ x y, f x y = f a b :=
⟨a, b, rfl⟩
@[simp]
lemma exists_apply_eq_apply2' {α β γ} {f : α → β → γ} {a : α} {b : β} : ∃ x y, f a b = f x y :=
⟨a, b, rfl⟩
@[simp]
lemma exists_apply_eq_apply3 {α β γ δ} {f : α → β → γ → δ} {a : α} {b : β} {c : γ} :
∃ x y z, f x y z = f a b c :=
⟨a, b, c, rfl⟩
@[simp]
lemma exists_apply_eq_apply3' {α β γ δ} {f : α → β → γ → δ} {a : α} {b : β} {c : γ} :
∃ x y z, f a b c = f x y z :=
⟨a, b, c, rfl⟩
/--
The constant function witnesses that
there exists a function sending a given term to a given term.
This is sometimes useful in `simp` to discharge side conditions.
-/
theorem exists_apply_eq (a : α) (b : β) : ∃ f : α → β, f a = b := ⟨fun _ ↦ b, rfl⟩
@[simp] theorem exists_exists_and_eq_and {f : α → β} {p : α → Prop} {q : β → Prop} :
(∃ b, (∃ a, p a ∧ f a = b) ∧ q b) ↔ ∃ a, p a ∧ q (f a) :=
⟨fun ⟨_, ⟨a, ha, hab⟩, hb⟩ ↦ ⟨a, ha, hab.symm ▸ hb⟩, fun ⟨a, hp, hq⟩ ↦ ⟨f a, ⟨a, hp, rfl⟩, hq⟩⟩
@[simp] theorem exists_exists_eq_and {f : α → β} {p : β → Prop} :
(∃ b, (∃ a, f a = b) ∧ p b) ↔ ∃ a, p (f a) :=
⟨fun ⟨_, ⟨a, ha⟩, hb⟩ ↦ ⟨a, ha.symm ▸ hb⟩, fun ⟨a, ha⟩ ↦ ⟨f a, ⟨a, rfl⟩, ha⟩⟩
@[simp] theorem exists_exists_and_exists_and_eq_and {α β γ : Type*}
{f : α → β → γ} {p : α → Prop} {q : β → Prop} {r : γ → Prop} :
(∃ c, (∃ a, p a ∧ ∃ b, q b ∧ f a b = c) ∧ r c) ↔ ∃ a, p a ∧ ∃ b, q b ∧ r (f a b) :=
⟨fun ⟨_, ⟨a, ha, b, hb, hab⟩, hc⟩ ↦ ⟨a, ha, b, hb, hab.symm ▸ hc⟩,
fun ⟨a, ha, b, hb, hab⟩ ↦ ⟨f a b, ⟨a, ha, b, hb, rfl⟩, hab⟩⟩
@[simp] theorem exists_exists_exists_and_eq {α β γ : Type*}
{f : α → β → γ} {p : γ → Prop} :
(∃ c, (∃ a, ∃ b, f a b = c) ∧ p c) ↔ ∃ a, ∃ b, p (f a b) :=
⟨fun ⟨_, ⟨a, b, hab⟩, hc⟩ ↦ ⟨a, b, hab.symm ▸ hc⟩,
fun ⟨a, b, hab⟩ ↦ ⟨f a b, ⟨a, b, rfl⟩, hab⟩⟩
theorem forall_apply_eq_imp_iff' {f : α → β} {p : β → Prop} :
(∀ a b, f a = b → p b) ↔ ∀ a, p (f a) := by simp
theorem forall_eq_apply_imp_iff' {f : α → β} {p : β → Prop} :
(∀ a b, b = f a → p b) ↔ ∀ a, p (f a) := by simp
theorem exists₂_comm
{ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*} {p : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Prop} :
(∃ i₁ j₁ i₂ j₂, p i₁ j₁ i₂ j₂) ↔ ∃ i₂ j₂ i₁ j₁, p i₁ j₁ i₂ j₂ := by
simp only [@exists_comm (κ₁ _), @exists_comm ι₁]
theorem And.exists {p q : Prop} {f : p ∧ q → Prop} : (∃ h, f h) ↔ ∃ hp hq, f ⟨hp, hq⟩ :=
⟨fun ⟨h, H⟩ ↦ ⟨h.1, h.2, H⟩, fun ⟨hp, hq, H⟩ ↦ ⟨⟨hp, hq⟩, H⟩⟩
theorem forall_or_of_or_forall {α : Sort*} {p : α → Prop} {b : Prop} (h : b ∨ ∀ x, p x) (x : α) :
b ∨ p x :=
h.imp_right fun h₂ ↦ h₂ x
-- See Note [decidable namespace]
protected theorem Decidable.forall_or_left {q : Prop} {p : α → Prop} [Decidable q] :
(∀ x, q ∨ p x) ↔ q ∨ ∀ x, p x :=
⟨fun h ↦ if hq : q then Or.inl hq else
Or.inr fun x ↦ (h x).resolve_left hq, forall_or_of_or_forall⟩
theorem forall_or_left {q} {p : α → Prop} : (∀ x, q ∨ p x) ↔ q ∨ ∀ x, p x :=
open scoped Classical in Decidable.forall_or_left
-- See Note [decidable namespace]
protected theorem Decidable.forall_or_right {q} {p : α → Prop} [Decidable q] :
(∀ x, p x ∨ q) ↔ (∀ x, p x) ∨ q := by simp [or_comm, Decidable.forall_or_left]
theorem forall_or_right {q} {p : α → Prop} : (∀ x, p x ∨ q) ↔ (∀ x, p x) ∨ q :=
open scoped Classical in Decidable.forall_or_right
@[simp]
theorem forall_and_index {p q : Prop} {r : p ∧ q → Prop} :
(∀ h : p ∧ q, r h) ↔ ∀ (hp : p) (hq : q), r ⟨hp, hq⟩ :=
⟨fun h hp hq ↦ h ⟨hp, hq⟩, fun h h1 ↦ h h1.1 h1.2⟩
theorem forall_and_index' {p q : Prop} {r : p → q → Prop} :
(∀ (hp : p) (hq : q), r hp hq) ↔ ∀ h : p ∧ q, r h.1 h.2 :=
(forall_and_index (r := fun h => r h.1 h.2)).symm
theorem Exists.fst {b : Prop} {p : b → Prop} : Exists p → b
| ⟨h, _⟩ => h
theorem Exists.snd {b : Prop} {p : b → Prop} : ∀ h : Exists p, p h.fst
| ⟨_, h⟩ => h
theorem Prop.exists_iff {p : Prop → Prop} : (∃ h, p h) ↔ p False ∨ p True :=
⟨fun ⟨h₁, h₂⟩ ↦ by_cases (fun H : h₁ ↦ .inr <| by simpa only [H] using h₂)
(fun H ↦ .inl <| by simpa only [H] using h₂), fun h ↦ h.elim (.intro _) (.intro _)⟩
theorem Prop.forall_iff {p : Prop → Prop} : (∀ h, p h) ↔ p False ∧ p True :=
⟨fun H ↦ ⟨H _, H _⟩, fun ⟨h₁, h₂⟩ h ↦ by by_cases H : h <;> simpa only [H]⟩
theorem exists_iff_of_forall {p : Prop} {q : p → Prop} (h : ∀ h, q h) : (∃ h, q h) ↔ p :=
⟨Exists.fst, fun H ↦ ⟨H, h H⟩⟩
theorem exists_prop_of_false {p : Prop} {q : p → Prop} : ¬p → ¬∃ h' : p, q h' :=
mt Exists.fst
/- See `IsEmpty.exists_iff` for the `False` version of `exists_true_left`. -/
theorem forall_prop_congr {p p' : Prop} {q q' : p → Prop} (hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') :
(∀ h, q h) ↔ ∀ h : p', q' (hp.2 h) :=
⟨fun h1 h2 ↦ (hq _).1 (h1 (hp.2 h2)), fun h1 h2 ↦ (hq _).2 (h1 (hp.1 h2))⟩
theorem forall_prop_congr' {p p' : Prop} {q q' : p → Prop} (hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') :
(∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
propext (forall_prop_congr hq hp)
lemma imp_congr_eq {a b c d : Prop} (h₁ : a = c) (h₂ : b = d) : (a → b) = (c → d) :=
propext (imp_congr h₁.to_iff h₂.to_iff)
lemma imp_congr_ctx_eq {a b c d : Prop} (h₁ : a = c) (h₂ : c → b = d) : (a → b) = (c → d) :=
propext (imp_congr_ctx h₁.to_iff fun hc ↦ (h₂ hc).to_iff)
lemma eq_true_intro {a : Prop} (h : a) : a = True := propext (iff_true_intro h)
lemma eq_false_intro {a : Prop} (h : ¬a) : a = False := propext (iff_false_intro h)
-- FIXME: `alias` creates `def Iff.eq := propext` instead of `lemma Iff.eq := propext`
@[nolint defLemma] alias Iff.eq := propext
lemma iff_eq_eq {a b : Prop} : (a ↔ b) = (a = b) := propext ⟨propext, Eq.to_iff⟩
-- They were not used in Lean 3 and there are already lemmas with those names in Lean 4
/-- See `IsEmpty.forall_iff` for the `False` version. -/
@[simp] theorem forall_true_left (p : True → Prop) : (∀ x, p x) ↔ p True.intro :=
forall_prop_of_true _
end Quantifiers
/-! ### Classical lemmas -/
namespace Classical
-- use shortened names to avoid conflict when classical namespace is open.
/-- Any prop `p` is decidable classically. A shorthand for `Classical.propDecidable`. -/
noncomputable def dec (p : Prop) : Decidable p := by infer_instance
variable {α : Sort*}
/-- Any predicate `p` is decidable classically. -/
noncomputable def decPred (p : α → Prop) : DecidablePred p := by infer_instance
/-- Any relation `p` is decidable classically. -/
noncomputable def decRel (p : α → α → Prop) : DecidableRel p := by infer_instance
/-- Any type `α` has decidable equality classically. -/
noncomputable def decEq (α : Sort*) : DecidableEq α := by infer_instance
/-- Construct a function from a default value `H0`, and a function to use if there exists a value
satisfying the predicate. -/
noncomputable def existsCases {α C : Sort*} {p : α → Prop} (H0 : C) (H : ∀ a, p a → C) : C :=
if h : ∃ a, p a then H (Classical.choose h) (Classical.choose_spec h) else H0
theorem some_spec₂ {α : Sort*} {p : α → Prop} {h : ∃ a, p a} (q : α → Prop)
(hpq : ∀ a, p a → q a) : q (choose h) := hpq _ <| choose_spec _
/-- A version of `byContradiction` that uses types instead of propositions. -/
protected noncomputable def byContradiction' {α : Sort*} (H : ¬(α → False)) : α :=
Classical.choice <| (peirce _ False) fun h ↦ (H fun a ↦ h ⟨a⟩).elim
/-- `Classical.byContradiction'` is equivalent to lean's axiom `Classical.choice`. -/
def choice_of_byContradiction' {α : Sort*} (contra : ¬(α → False) → α) : Nonempty α → α :=
fun H ↦ contra H.elim
@[simp] lemma choose_eq (a : α) : @Exists.choose _ (· = a) ⟨a, rfl⟩ = a := @choose_spec _ (· = a) _
@[simp]
lemma choose_eq' (a : α) : @Exists.choose _ (a = ·) ⟨a, rfl⟩ = a :=
(@choose_spec _ (a = ·) _).symm
alias axiom_of_choice := axiomOfChoice -- TODO: remove? rename in core?
alias by_cases := byCases -- TODO: remove? rename in core?
alias by_contradiction := byContradiction -- TODO: remove? rename in core?
-- The remaining theorems in this section were ported from Lean 3,
-- but are currently unused in Mathlib, so have been deprecated.
-- If any are being used downstream, please remove the deprecation.
alias prop_complete := propComplete -- TODO: remove? rename in core?
end Classical
/-- This function has the same type as `Exists.recOn`, and can be used to case on an equality,
but `Exists.recOn` can only eliminate into Prop, while this version eliminates into any universe
using the axiom of choice. -/
noncomputable def Exists.classicalRecOn {α : Sort*} {p : α → Prop} (h : ∃ a, p a)
{C : Sort*} (H : ∀ a, p a → C) : C :=
H (Classical.choose h) (Classical.choose_spec h)
/-! ### Declarations about bounded quantifiers -/
section BoundedQuantifiers
variable {α : Sort*} {r p q : α → Prop} {P Q : ∀ x, p x → Prop}
theorem bex_def : (∃ (x : _) (_ : p x), q x) ↔ ∃ x, p x ∧ q x :=
⟨fun ⟨x, px, qx⟩ ↦ ⟨x, px, qx⟩, fun ⟨x, px, qx⟩ ↦ ⟨x, px, qx⟩⟩
theorem BEx.elim {b : Prop} : (∃ x h, P x h) → (∀ a h, P a h → b) → b
| ⟨a, h₁, h₂⟩, h' => h' a h₁ h₂
theorem BEx.intro (a : α) (h₁ : p a) (h₂ : P a h₁) : ∃ (x : _) (h : p x), P x h :=
⟨a, h₁, h₂⟩
theorem BAll.imp_right (H : ∀ x h, P x h → Q x h) (h₁ : ∀ x h, P x h) (x h) : Q x h :=
H _ _ <| h₁ _ _
theorem BEx.imp_right (H : ∀ x h, P x h → Q x h) : (∃ x h, P x h) → ∃ x h, Q x h
| ⟨_, _, h'⟩ => ⟨_, _, H _ _ h'⟩
theorem BAll.imp_left (H : ∀ x, p x → q x) (h₁ : ∀ x, q x → r x) (x) (h : p x) : r x :=
h₁ _ <| H _ h
theorem BEx.imp_left (H : ∀ x, p x → q x) : (∃ (x : _) (_ : p x), r x) → ∃ (x : _) (_ : q x), r x
| ⟨x, hp, hr⟩ => ⟨x, H _ hp, hr⟩
theorem exists_mem_of_exists (H : ∀ x, p x) : (∃ x, q x) → ∃ (x : _) (_ : p x), q x
| ⟨x, hq⟩ => ⟨x, H x, hq⟩
theorem exists_of_exists_mem : (∃ (x : _) (_ : p x), q x) → ∃ x, q x
| ⟨x, _, hq⟩ => ⟨x, hq⟩
theorem not_exists_mem : (¬∃ x h, P x h) ↔ ∀ x h, ¬P x h := exists₂_imp
theorem not_forall₂_of_exists₂_not : (∃ x h, ¬P x h) → ¬∀ x h, P x h
| ⟨x, h, hp⟩, al => hp <| al x h
-- See Note [decidable namespace]
protected theorem Decidable.not_forall₂ [Decidable (∃ x h, ¬P x h)] [∀ x h, Decidable (P x h)] :
(¬∀ x h, P x h) ↔ ∃ x h, ¬P x h :=
⟨Not.decidable_imp_symm fun nx x h ↦ nx.decidable_imp_symm
fun h' ↦ ⟨x, h, h'⟩, not_forall₂_of_exists₂_not⟩
theorem not_forall₂ : (¬∀ x h, P x h) ↔ ∃ x h, ¬P x h :=
open scoped Classical in Decidable.not_forall₂
theorem forall₂_and : (∀ x h, P x h ∧ Q x h) ↔ (∀ x h, P x h) ∧ ∀ x h, Q x h :=
Iff.trans (forall_congr' fun _ ↦ forall_and) forall_and
theorem forall_and_left [Nonempty α] (q : Prop) (p : α → Prop) :
(∀ x, q ∧ p x) ↔ (q ∧ ∀ x, p x) := by rw [forall_and, forall_const]
theorem forall_and_right [Nonempty α] (p : α → Prop) (q : Prop) :
(∀ x, p x ∧ q) ↔ (∀ x, p x) ∧ q := by rw [forall_and, forall_const]
theorem exists_mem_or : (∃ x h, P x h ∨ Q x h) ↔ (∃ x h, P x h) ∨ ∃ x h, Q x h :=
Iff.trans (exists_congr fun _ ↦ exists_or) exists_or
theorem forall₂_or_left : (∀ x, p x ∨ q x → r x) ↔ (∀ x, p x → r x) ∧ ∀ x, q x → r x :=
Iff.trans (forall_congr' fun _ ↦ or_imp) forall_and
theorem exists_mem_or_left :
(∃ (x : _) (_ : p x ∨ q x), r x) ↔ (∃ (x : _) (_ : p x), r x) ∨ ∃ (x : _) (_ : q x), r x := by
simp only [exists_prop]
exact Iff.trans (exists_congr fun x ↦ or_and_right) exists_or
end BoundedQuantifiers
section ite
variable {α : Sort*} {σ : α → Sort*} {P Q R : Prop} [Decidable P]
{a b c : α} {A : P → α} {B : ¬P → α}
theorem dite_eq_iff : dite P A B = c ↔ (∃ h, A h = c) ∨ ∃ h, B h = c := by
by_cases P <;> simp [*, exists_prop_of_true, exists_prop_of_false]
theorem ite_eq_iff : ite P a b = c ↔ P ∧ a = c ∨ ¬P ∧ b = c :=
dite_eq_iff.trans <| by rw [exists_prop, exists_prop]
theorem eq_ite_iff : a = ite P b c ↔ P ∧ a = b ∨ ¬P ∧ a = c :=
eq_comm.trans <| ite_eq_iff.trans <| (Iff.rfl.and eq_comm).or (Iff.rfl.and eq_comm)
theorem dite_eq_iff' : dite P A B = c ↔ (∀ h, A h = c) ∧ ∀ h, B h = c :=
⟨fun he ↦ ⟨fun h ↦ (dif_pos h).symm.trans he, fun h ↦ (dif_neg h).symm.trans he⟩, fun he ↦
(em P).elim (fun h ↦ (dif_pos h).trans <| he.1 h) fun h ↦ (dif_neg h).trans <| he.2 h⟩
theorem ite_eq_iff' : ite P a b = c ↔ (P → a = c) ∧ (¬P → b = c) := dite_eq_iff'
theorem dite_ne_left_iff : dite P (fun _ ↦ a) B ≠ a ↔ ∃ h, a ≠ B h := by
grind
theorem dite_ne_right_iff : (dite P A fun _ ↦ b) ≠ b ↔ ∃ h, A h ≠ b := by
simp only [Ne, dite_eq_right_iff, not_forall]
theorem ite_ne_left_iff : ite P a b ≠ a ↔ ¬P ∧ a ≠ b :=
dite_ne_left_iff.trans <| by rw [exists_prop]
theorem ite_ne_right_iff : ite P a b ≠ b ↔ P ∧ a ≠ b :=
dite_ne_right_iff.trans <| by rw [exists_prop]
protected theorem Ne.dite_eq_left_iff (h : ∀ h, a ≠ B h) : dite P (fun _ ↦ a) B = a ↔ P :=
dite_eq_left_iff.trans ⟨fun H ↦ of_not_not fun h' ↦ h h' (H h').symm, fun h H ↦ (H h).elim⟩
protected theorem Ne.dite_eq_right_iff (h : ∀ h, A h ≠ b) : (dite P A fun _ ↦ b) = b ↔ ¬P :=
dite_eq_right_iff.trans ⟨fun H h' ↦ h h' (H h'), fun h' H ↦ (h' H).elim⟩
protected theorem Ne.ite_eq_left_iff (h : a ≠ b) : ite P a b = a ↔ P :=
Ne.dite_eq_left_iff fun _ ↦ h
protected theorem Ne.ite_eq_right_iff (h : a ≠ b) : ite P a b = b ↔ ¬P :=
Ne.dite_eq_right_iff fun _ ↦ h
protected theorem Ne.dite_ne_left_iff (h : ∀ h, a ≠ B h) : dite P (fun _ ↦ a) B ≠ a ↔ ¬P :=
dite_ne_left_iff.trans <| exists_iff_of_forall h
protected theorem Ne.dite_ne_right_iff (h : ∀ h, A h ≠ b) : (dite P A fun _ ↦ b) ≠ b ↔ P :=
dite_ne_right_iff.trans <| exists_iff_of_forall h
protected theorem Ne.ite_ne_left_iff (h : a ≠ b) : ite P a b ≠ a ↔ ¬P :=
Ne.dite_ne_left_iff fun _ ↦ h
protected theorem Ne.ite_ne_right_iff (h : a ≠ b) : ite P a b ≠ b ↔ P :=
Ne.dite_ne_right_iff fun _ ↦ h
variable (P Q a b)
theorem dite_eq_or_eq : (∃ h, dite P A B = A h) ∨ ∃ h, dite P A B = B h :=
if h : _ then .inl ⟨h, dif_pos h⟩ else .inr ⟨h, dif_neg h⟩
theorem ite_eq_or_eq : ite P a b = a ∨ ite P a b = b :=
if h : _ then .inl (if_pos h) else .inr (if_neg h)
/-- A two-argument function applied to two `dite`s is a `dite` of that two-argument function
applied to each of the branches. -/
theorem apply_dite₂ {α β γ : Sort*} (f : α → β → γ) (P : Prop) [Decidable P]
(a : P → α) (b : ¬P → α) (c : P → β) (d : ¬P → β) :
f (dite P a b) (dite P c d) = dite P (fun h ↦ f (a h) (c h)) fun h ↦ f (b h) (d h) := by
by_cases h : P <;> simp [h]
/-- A two-argument function applied to two `ite`s is a `ite` of that two-argument function
applied to each of the branches. -/
theorem apply_ite₂ {α β γ : Sort*} (f : α → β → γ) (P : Prop) [Decidable P] (a b : α) (c d : β) :
f (ite P a b) (ite P c d) = ite P (f a c) (f b d) :=
apply_dite₂ f P (fun _ ↦ a) (fun _ ↦ b) (fun _ ↦ c) fun _ ↦ d
/-- A 'dite' producing a `Pi` type `Π a, σ a`, applied to a value `a : α` is a `dite` that applies
either branch to `a`. -/
theorem dite_apply (f : P → ∀ a, σ a) (g : ¬P → ∀ a, σ a) (a : α) :
(dite P f g) a = dite P (fun h ↦ f h a) fun h ↦ g h a := by by_cases h : P <;> simp [h]
/-- A 'ite' producing a `Pi` type `Π a, σ a`, applied to a value `a : α` is a `ite` that applies
either branch to `a`. -/
theorem ite_apply (f g : ∀ a, σ a) (a : α) : (ite P f g) a = ite P (f a) (g a) :=
dite_apply P (fun _ ↦ f) (fun _ ↦ g) a
section
variable [Decidable Q]
theorem ite_and : ite (P ∧ Q) a b = ite P (ite Q a b) b := by
by_cases hp : P <;> by_cases hq : Q <;> simp [hp, hq]
theorem ite_or : ite (P ∨ Q) a b = ite P a (ite Q a b) := by
by_cases hp : P <;> by_cases hq : Q <;> simp [hp, hq]
theorem dite_dite_comm {B : Q → α} {C : ¬P → ¬Q → α} (h : P → ¬Q) :
(if p : P then A p else if q : Q then B q else C p q) =
if q : Q then B q else if p : P then A p else C p q := by
grind
theorem ite_ite_comm (h : P → ¬Q) :
(if P then a else if Q then b else c) =
if Q then b else if P then a else c :=
dite_dite_comm P Q h
end
variable {P Q}
theorem ite_prop_iff_or : (if P then Q else R) ↔ (P ∧ Q ∨ ¬P ∧ R) := by
by_cases p : P <;> simp [p]
theorem dite_prop_iff_or {Q : P → Prop} {R : ¬P → Prop} :
dite P Q R ↔ (∃ p, Q p) ∨ (∃ p, R p) := by
by_cases h : P <;> simp [h, exists_prop_of_false, exists_prop_of_true]
-- TODO make this a simp lemma in a future PR
theorem ite_prop_iff_and : (if P then Q else R) ↔ ((P → Q) ∧ (¬P → R)) := by
by_cases p : P <;> simp [p]
theorem dite_prop_iff_and {Q : P → Prop} {R : ¬P → Prop} :
dite P Q R ↔ (∀ h, Q h) ∧ (∀ h, R h) := by
by_cases h : P <;> simp [h, forall_prop_of_false, forall_prop_of_true]
section congr
variable [Decidable Q] {x y u v : α}
theorem if_ctx_congr (h_c : P ↔ Q) (h_t : Q → x = u) (h_e : ¬Q → y = v) : ite P x y = ite Q u v :=
ite_congr h_c.eq h_t h_e
theorem if_congr (h_c : P ↔ Q) (h_t : x = u) (h_e : y = v) : ite P x y = ite Q u v :=
if_ctx_congr h_c (fun _ ↦ h_t) (fun _ ↦ h_e)
end congr
end ite
/-! ### Membership -/
alias Membership.mem.ne_of_notMem := ne_of_mem_of_not_mem
alias Membership.mem.ne_of_notMem' := ne_of_mem_of_not_mem'
@[deprecated (since := "2025-05-23")]
alias Membership.mem.ne_of_not_mem := Membership.mem.ne_of_notMem
@[deprecated (since := "2025-05-23")]
alias Membership.mem.ne_of_not_mem' := Membership.mem.ne_of_notMem'
section Membership
variable {α β : Type*} [Membership α β] {p : Prop} [Decidable p]
theorem mem_dite {a : α} {s : p → β} {t : ¬p → β} :
(a ∈ if h : p then s h else t h) ↔ (∀ h, a ∈ s h) ∧ (∀ h, a ∈ t h) := by
by_cases h : p <;> simp [h]
theorem dite_mem {a : p → α} {b : ¬p → α} {s : β} :
(if h : p then a h else b h) ∈ s ↔ (∀ h, a h ∈ s) ∧ (∀ h, b h ∈ s) := by
by_cases h : p <;> simp [h]
theorem mem_ite {a : α} {s t : β} : (a ∈ if p then s else t) ↔ (p → a ∈ s) ∧ (¬p → a ∈ t) :=
mem_dite
theorem ite_mem {a b : α} {s : β} : (if p then a else b) ∈ s ↔ (p → a ∈ s) ∧ (¬p → b ∈ s) :=
dite_mem
end Membership
theorem not_beq_of_ne {α : Type*} [BEq α] [LawfulBEq α] {a b : α} (ne : a ≠ b) : ¬(a == b) :=
fun h => ne (eq_of_beq h)
alias beq_eq_decide := Bool.beq_eq_decide_eq
@[simp] lemma beq_eq_beq {α β : Type*} [BEq α] [LawfulBEq α] [BEq β] [LawfulBEq β] {a₁ a₂ : α}
{b₁ b₂ : β} : (a₁ == a₂) = (b₁ == b₂) ↔ (a₁ = a₂ ↔ b₁ = b₂) := by rw [Bool.eq_iff_iff]; simp
@[ext]
theorem beq_ext {α : Type*} (inst1 : BEq α) (inst2 : BEq α)
(h : ∀ x y, @BEq.beq _ inst1 x y = @BEq.beq _ inst2 x y) :
inst1 = inst2 := by
have ⟨beq1⟩ := inst1
congr
funext x y
exact h x y
theorem lawful_beq_subsingleton {α : Type*} (inst1 : BEq α) (inst2 : BEq α)
[@LawfulBEq α inst1] [@LawfulBEq α inst2] :
inst1 = inst2 := by
ext
simp |
.lake/packages/mathlib/Mathlib/Logic/Unique.lean | import Mathlib.Logic.IsEmpty
import Mathlib.Tactic.Inhabit
import Mathlib.Tactic.Push.Attr
/-!
# Types with a unique term
In this file we define a typeclass `Unique`,
which expresses that a type has a unique term.
In other words, a type that is `Inhabited` and a `Subsingleton`.
## Main declaration
* `Unique`: a typeclass that expresses that a type has a unique term.
## Main statements
* `Unique.mk'`: an inhabited subsingleton type is `Unique`. This cannot be an instance because it
would lead to loops in typeclass inference.
* `Function.Surjective.unique`: if the domain of a surjective function is `Unique`, then its
codomain is `Unique` as well.
* `Function.Injective.subsingleton`: if the codomain of an injective function is `Subsingleton`,
then its domain is `Subsingleton` as well.
* `Function.Injective.unique`: if the codomain of an injective function is `Subsingleton` and its
domain is `Inhabited`, then its domain is `Unique`.
## Implementation details
The typeclass `Unique α` is implemented as a type,
rather than a `Prop`-valued predicate,
for good definitional properties of the default term.
-/
universe u v w
-- Don't generate injectivity lemmas, which the `simpNF` linter will complain about.
set_option genInjectivity false in
/-- `Unique α` expresses that `α` is a type with a unique term `default`.
This is implemented as a type, rather than a `Prop`-valued predicate,
for good definitional properties of the default term. -/
@[ext]
structure Unique (α : Sort u) extends Inhabited α where
/-- In a `Unique` type, every term is equal to the default element (from `Inhabited`). -/
uniq : ∀ a : α, a = default
attribute [class] Unique
theorem unique_iff_existsUnique (α : Sort u) : Nonempty (Unique α) ↔ ∃! _ : α, True :=
⟨fun ⟨u⟩ ↦ ⟨u.default, trivial, fun a _ ↦ u.uniq a⟩,
fun ⟨a, _, h⟩ ↦ ⟨⟨⟨a⟩, fun _ ↦ h _ trivial⟩⟩⟩
theorem unique_subtype_iff_existsUnique {α} (p : α → Prop) :
Nonempty (Unique (Subtype p)) ↔ ∃! a, p a :=
⟨fun ⟨u⟩ ↦ ⟨u.default.1, u.default.2, fun a h ↦ congr_arg Subtype.val (u.uniq ⟨a, h⟩)⟩,
fun ⟨a, ha, he⟩ ↦ ⟨⟨⟨⟨a, ha⟩⟩, fun ⟨b, hb⟩ ↦ by
congr
exact he b hb⟩⟩⟩
/-- Given an explicit `a : α` with `Subsingleton α`, we can construct
a `Unique α` instance. This is a def because the typeclass search cannot
arbitrarily invent the `a : α` term. Nevertheless, these instances are all
equivalent by `Unique.Subsingleton.unique`.
See note [reducible non-instances]. -/
abbrev uniqueOfSubsingleton {α : Sort*} [Subsingleton α] (a : α) : Unique α where
default := a
uniq _ := Subsingleton.elim _ _
instance PUnit.instUnique : Unique PUnit.{u} where
default := PUnit.unit
uniq x := subsingleton x _
@[simp]
theorem PUnit.default_eq_unit : (default : PUnit) = PUnit.unit :=
rfl
/-- Every provable proposition is unique, as all proofs are equal. -/
def uniqueProp {p : Prop} (h : p) : Unique.{0} p where
default := h
uniq _ := rfl
instance : Unique True :=
uniqueProp trivial
namespace Unique
open Function
section
variable {α : Sort*} [Unique α]
-- see Note [lower instance priority]
instance (priority := 100) : Inhabited α :=
toInhabited ‹Unique α›
theorem eq_default (a : α) : a = default :=
uniq _ a
theorem default_eq (a : α) : default = a :=
(uniq _ a).symm
-- see Note [lower instance priority]
instance (priority := 100) instSubsingleton : Subsingleton α :=
subsingleton_of_forall_eq _ eq_default
theorem forall_iff {p : α → Prop} : (∀ a, p a) ↔ p default :=
⟨fun h ↦ h _, fun h x ↦ by rwa [Unique.eq_default x]⟩
theorem exists_iff {p : α → Prop} : Exists p ↔ p default :=
⟨fun ⟨a, ha⟩ ↦ eq_default a ▸ ha, Exists.intro default⟩
end
variable {α : Sort*}
@[ext]
protected theorem subsingleton_unique' : ∀ h₁ h₂ : Unique α, h₁ = h₂
| ⟨⟨x⟩, h⟩, ⟨⟨y⟩, _⟩ => by congr; rw [h x, h y]
instance subsingleton_unique : Subsingleton (Unique α) :=
⟨Unique.subsingleton_unique'⟩
/-- Construct `Unique` from `Inhabited` and `Subsingleton`. Making this an instance would create
a loop in the class inheritance graph. -/
abbrev mk' (α : Sort u) [h₁ : Inhabited α] [Subsingleton α] : Unique α :=
{ h₁ with uniq := fun _ ↦ Subsingleton.elim _ _ }
end Unique
theorem nonempty_unique (α : Sort u) [Subsingleton α] [Nonempty α] : Nonempty (Unique α) := by
inhabit α
exact ⟨Unique.mk' α⟩
theorem unique_iff_subsingleton_and_nonempty (α : Sort u) :
Nonempty (Unique α) ↔ Subsingleton α ∧ Nonempty α :=
⟨fun ⟨u⟩ ↦ by constructor <;> exact inferInstance,
fun ⟨hs, hn⟩ ↦ nonempty_unique α⟩
variable {α : Sort*}
@[simp, push ←]
theorem Pi.default_def {β : α → Sort v} [∀ a, Inhabited (β a)] :
@default (∀ a, β a) _ = fun a : α ↦ @default (β a) _ :=
rfl
theorem Pi.default_apply {β : α → Sort v} [∀ a, Inhabited (β a)] (a : α) :
@default (∀ a, β a) _ a = default :=
rfl
instance Pi.unique {β : α → Sort v} [∀ a, Unique (β a)] : Unique (∀ a, β a) where
uniq := fun _ ↦ funext fun _ ↦ Unique.eq_default _
/-- There is a unique function on an empty domain. -/
instance Pi.uniqueOfIsEmpty [IsEmpty α] (β : α → Sort v) : Unique (∀ a, β a) where
default := isEmptyElim
uniq _ := funext isEmptyElim
theorem eq_const_of_subsingleton {β : Sort*} [Subsingleton α] (f : α → β) (a : α) :
f = Function.const α (f a) :=
funext fun x ↦ Subsingleton.elim x a ▸ rfl
theorem eq_const_of_unique {β : Sort*} [Unique α] (f : α → β) : f = Function.const α (f default) :=
eq_const_of_subsingleton ..
theorem heq_const_of_unique [Unique α] {β : α → Sort v} (f : ∀ a, β a) :
f ≍ Function.const α (f default) :=
(Function.hfunext rfl) fun i _ _ ↦ by rw [Subsingleton.elim i default]; rfl
namespace Function
variable {β : Sort*} {f : α → β}
/-- If the codomain of an injective function is a subsingleton, then the domain
is a subsingleton as well. -/
protected theorem Injective.subsingleton (hf : Injective f) [Subsingleton β] : Subsingleton α :=
⟨fun _ _ ↦ hf <| Subsingleton.elim _ _⟩
/-- If the domain of a surjective function is a subsingleton, then the codomain is a subsingleton as
well. -/
protected theorem Surjective.subsingleton [Subsingleton α] (hf : Surjective f) : Subsingleton β :=
⟨hf.forall₂.2 fun x y ↦ congr_arg f <| Subsingleton.elim x y⟩
/-- If the domain of a surjective function is a singleton,
then the codomain is a singleton as well. -/
protected def Surjective.unique {α : Sort u} (f : α → β) (hf : Surjective f) [Unique.{u} α] :
Unique β :=
@Unique.mk' _ ⟨f default⟩ hf.subsingleton
/-- If `α` is inhabited and admits an injective map to a subsingleton type, then `α` is `Unique`. -/
protected def Injective.unique [Inhabited α] [Subsingleton β] (hf : Injective f) : Unique α :=
@Unique.mk' _ _ hf.subsingleton
/-- If a constant function is surjective, then the codomain is a singleton. -/
def Surjective.uniqueOfSurjectiveConst (α : Type*) {β : Type*} (b : β)
(h : Function.Surjective (Function.const α b)) : Unique β :=
@uniqueOfSubsingleton _ (subsingleton_of_forall_eq b <| h.forall.mpr fun _ ↦ rfl) b
end Function
section Pi
variable {ι : Sort*} {α : ι → Sort*}
/-- Given one value over a unique, we get a dependent function. -/
def uniqueElim [Unique ι] (x : α (default : ι)) (i : ι) : α i := by
rw [Unique.eq_default i]
exact x
@[simp]
theorem uniqueElim_default {_ : Unique ι} (x : α (default : ι)) : uniqueElim x (default : ι) = x :=
rfl
@[simp]
theorem uniqueElim_const {β : Sort*} {_ : Unique ι} (x : β) (i : ι) :
uniqueElim (α := fun _ ↦ β) x i = x :=
rfl
end Pi
-- TODO: Mario turned this off as a simp lemma in Batteries, wanting to profile it.
attribute [local simp] eq_iff_true_of_subsingleton in
theorem Unique.bijective {A B} [Unique A] [Unique B] {f : A → B} : Function.Bijective f := by
rw [Function.bijective_iff_has_inverse]
refine ⟨default, ?_, ?_⟩ <;> intro x <;> simp
namespace Option
/-- `Option α` is a `Subsingleton` if and only if `α` is empty. -/
theorem subsingleton_iff_isEmpty {α : Type u} : Subsingleton (Option α) ↔ IsEmpty α :=
⟨fun h ↦ ⟨fun x ↦ Option.noConfusion <| @Subsingleton.elim _ h x none⟩,
fun h ↦ ⟨fun x y ↦
Option.casesOn x (Option.casesOn y rfl fun x ↦ h.elim x) fun x ↦ h.elim x⟩⟩
instance {α} [IsEmpty α] : Unique (Option α) :=
@Unique.mk' _ _ (subsingleton_iff_isEmpty.2 ‹_›)
end Option
section Subtype
instance Unique.subtypeEq (y : α) : Unique { x // x = y } where
default := ⟨y, rfl⟩
uniq := fun ⟨x, hx⟩ ↦ by congr
instance Unique.subtypeEq' (y : α) : Unique { x // y = x } where
default := ⟨y, rfl⟩
uniq := fun ⟨x, hx⟩ ↦ by subst hx; congr
end Subtype
instance Fin.instUnique : Unique (Fin 1) where uniq _ := Subsingleton.elim _ _ |
.lake/packages/mathlib/Mathlib/Logic/Relation.lean | import Mathlib.Logic.Relator
import Mathlib.Tactic.Use
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Tactic.SimpRw
import Mathlib.Logic.Basic
import Mathlib.Order.Defs.Unbundled
/-!
# Relation closures
This file defines the reflexive, transitive, reflexive transitive and equivalence closures
of relations and proves some basic results on them.
Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For
the bundled version, see `Rel`.
## Definitions
* `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all
`a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`.
* `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related
transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`.
* `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything
`r` related transitively, plus for all `a` it relates `a` with itself. So
`ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as
the reflexive closure of the transitive closure, or the transitive closure of the reflexive
closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of
rewrites.
* `Relation.EqvGen`: Equivalence closure. `EqvGen r` relates everything `ReflTransGen r` relates,
plus for all related pairs it relates them in the opposite order.
* `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and
`s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to
both.
* `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`,
`g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b`
related by `r`.
* `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In
terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term.
-/
open Function
variable {α β γ δ ε ζ : Type*}
section NeImp
variable {r : α → α → Prop}
theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x
/-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`,
it suffices to show it holds when `x ≠ y`. -/
theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by
grind [Reflexive]
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. -/
theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y :=
⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/
theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y :=
IsRefl.reflexive.ne_imp_iff
theorem reflexive_iff_subrelation_eq : Reflexive r ↔ Subrelation Eq r := by
grind [Reflexive, Subrelation]
theorem irreflexive_iff_subrelation_ne : Irreflexive r ↔ Subrelation r Ne := by
grind [Irreflexive, Subrelation]
protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x :=
⟨fun h ↦ H h, fun h ↦ H h⟩
theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r :=
funext₂ fun _ _ ↦ propext <| h.iff _ _
theorem Symmetric.swap_eq : Symmetric r → swap r = r :=
Symmetric.flip_eq
theorem flip_eq_iff : flip r = r ↔ Symmetric r :=
⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩
theorem swap_eq_iff : swap r = r ↔ Symmetric r :=
flip_eq_iff
end NeImp
section Comap
variable {r : β → β → Prop}
theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a)
theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab
theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) :=
fun _ _ _ hab hbc ↦ h hab hbc
theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) :=
⟨fun a ↦ h.refl (f a), h.symm, h.trans⟩
end Comap
namespace Relation
section Comp
variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop}
/-- The composition of two relations, yielding a new relation. The result
relates a term of `α` and a term of `γ` if there is an intermediate
term of `β` related to both.
-/
def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop :=
∃ b, r a b ∧ p b c
@[inherit_doc]
local infixr:80 " ∘r " => Relation.Comp
@[simp]
theorem comp_eq_fun (f : γ → β) : r ∘r (· = f ·) = (r · <| f ·) := by
ext x y
simp [Comp]
@[simp]
theorem comp_eq : r ∘r (· = ·) = r := comp_eq_fun ..
@[simp]
theorem fun_eq_comp (f : γ → α) : (f · = ·) ∘r r = (r <| f ·) := by
ext x y
simp [Comp]
@[simp]
theorem eq_comp : (· = ·) ∘r r = r := fun_eq_comp ..
@[simp]
theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by
grind [eq_comp]
@[simp]
theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by
grind [comp_eq]
theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by
funext a d
apply propext
constructor
· exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩
· exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩
theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by
funext c a
apply propext
constructor
· exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩
· exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩
end Comp
section Fibration
variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β)
/-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all
`a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image
of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/
def Fibration :=
∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b
variable {rα rβ}
/-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is
accessible under `rα`, then `f a` is accessible under `rβ`. -/
theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by
induction ha with | intro a _ ih => ?_
refine Acc.intro (f a) fun b hr ↦ ?_
obtain ⟨a', hr', rfl⟩ := fib hr
exact ih a' hr'
theorem _root_.Acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → ∃ c, f c = b) (a : α)
(ha : Acc (InvImage rβ f) a) : Acc rβ (f a) :=
ha.of_fibration f fun a _ h ↦
let ⟨a', he⟩ := dc h
⟨a', by simp_all [InvImage], he⟩
end Fibration
section Map
variable {r : α → β → Prop} {f : α → γ} {g : β → δ} {c : γ} {d : δ}
/-- The map of a relation `r` through a pair of functions pushes the
relation to the codomains of the functions. The resulting relation is
defined by having pairs of terms related if they have preimages
related by `r`.
-/
protected def Map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop := fun c d ↦
∃ a b, r a b ∧ f a = c ∧ g b = d
lemma map_apply : Relation.Map r f g c d ↔ ∃ a b, r a b ∧ f a = c ∧ g b = d := Iff.rfl
@[simp] lemma map_map (r : α → β → Prop) (f₁ : α → γ) (g₁ : β → δ) (f₂ : γ → ε) (g₂ : δ → ζ) :
Relation.Map (Relation.Map r f₁ g₁) f₂ g₂ = Relation.Map r (f₂ ∘ f₁) (g₂ ∘ g₁) := by
grind [Relation.Map]
@[simp]
lemma map_apply_apply (hf : Injective f) (hg : Injective g) (r : α → β → Prop) (a : α) (b : β) :
Relation.Map r f g (f a) (g b) ↔ r a b := by simp [Relation.Map, hf.eq_iff, hg.eq_iff]
@[simp] lemma map_id_id (r : α → β → Prop) : Relation.Map r id id = r := by ext; simp [Relation.Map]
instance [Decidable (∃ a b, r a b ∧ f a = c ∧ g b = d)] : Decidable (Relation.Map r f g c d) :=
‹Decidable _›
lemma map_reflexive {r : α → α → Prop} (hr : Reflexive r) {f : α → β} (hf : f.Surjective) :
Reflexive (Relation.Map r f f) := by
intro x
obtain ⟨y, rfl⟩ := hf x
exact ⟨y, y, hr y, rfl, rfl⟩
lemma map_symmetric {r : α → α → Prop} (hr : Symmetric r) (f : α → β) :
Symmetric (Relation.Map r f f) := by
rintro _ _ ⟨x, y, hxy, rfl, rfl⟩; exact ⟨_, _, hr hxy, rfl, rfl⟩
lemma map_transitive {r : α → α → Prop} (hr : Transitive r) {f : α → β}
(hf : ∀ x y, f x = f y → r x y) :
Transitive (Relation.Map r f f) := by
rintro _ _ _ ⟨x, y, hxy, rfl, rfl⟩ ⟨y', z, hyz, hy, rfl⟩
exact ⟨x, z, hr hxy <| hr (hf _ _ hy.symm) hyz, rfl, rfl⟩
lemma map_equivalence {r : α → α → Prop} (hr : Equivalence r) (f : α → β)
(hf : f.Surjective) (hf_ker : ∀ x y, f x = f y → r x y) :
Equivalence (Relation.Map r f f) where
refl := map_reflexive hr.reflexive hf
symm := @(map_symmetric hr.symmetric _)
trans := @(map_transitive hr.transitive hf_ker)
-- TODO: state this using `≤`, after adjusting imports.
lemma map_mono {r s : α → β → Prop} {f : α → γ} {g : β → δ} (h : ∀ x y, r x y → s x y) :
∀ x y, Relation.Map r f g x y → Relation.Map s f g x y :=
fun _ _ ⟨x, y, hxy, hx, hy⟩ => ⟨x, y, h _ _ hxy, hx, hy⟩
end Map
variable {r : α → α → Prop} {a b c : α}
/-- `ReflTransGen r`: reflexive transitive closure of `r` -/
@[mk_iff ReflTransGen.cases_tail_iff]
inductive ReflTransGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflTransGen r a a
| tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c
attribute [refl] ReflTransGen.refl
/-- `ReflGen r`: reflexive closure of `r` -/
@[mk_iff]
inductive ReflGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflGen r a a
| single {b} : r a b → ReflGen r a b
variable (r) in
/-- `EqvGen r`: equivalence closure of `r`. -/
@[mk_iff]
inductive EqvGen : α → α → Prop
| rel x y : r x y → EqvGen x y
| refl x : EqvGen x x
| symm x y : EqvGen x y → EqvGen y x
| trans x y z : EqvGen x y → EqvGen y z → EqvGen x z
attribute [mk_iff] TransGen
attribute [refl] ReflGen.refl
namespace ReflGen
theorem to_reflTransGen : ∀ {a b}, ReflGen r a b → ReflTransGen r a b
| a, _, refl => by rfl
| _, _, single h => ReflTransGen.tail ReflTransGen.refl h
theorem mono {p : α → α → Prop} (hp : ∀ a b, r a b → p a b) : ∀ {a b}, ReflGen r a b → ReflGen p a b
| a, _, ReflGen.refl => by rfl
| a, b, single h => single (hp a b h)
instance : IsRefl α (ReflGen r) :=
⟨@refl α r⟩
end ReflGen
namespace ReflTransGen
@[trans]
theorem trans (hab : ReflTransGen r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
theorem single (hab : r a b) : ReflTransGen r a b :=
refl.tail hab
theorem head (hab : r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => exact refl.tail hab
| tail _ hcd hac => exact hac.tail hcd
theorem symmetric (h : Symmetric r) : Symmetric (ReflTransGen r) := by
intro x y h
induction h with
| refl => rfl
| tail _ b c => apply Relation.ReflTransGen.head (h b) c
theorem cases_tail : ReflTransGen r a b → b = a ∨ ∃ c, ReflTransGen r a c ∧ r c b :=
(cases_tail_iff r a b).1
@[elab_as_elim]
theorem head_induction_on {motive : ∀ a : α, ReflTransGen r a b → Prop} {a : α}
(h : ReflTransGen r a b) (refl : motive b refl)
(head : ∀ {a c} (h' : r a c) (h : ReflTransGen r c b), motive c h → motive a (h.head h')) :
motive a h := by
induction h with
| refl => exact refl
| @tail b c _ hbc ih =>
apply ih
· exact head hbc _ refl
· exact fun h1 h2 ↦ head h1 (h2.tail hbc)
@[elab_as_elim]
theorem trans_induction_on {motive : ∀ {a b : α}, ReflTransGen r a b → Prop} {a b : α}
(h : ReflTransGen r a b) (refl : ∀ a, @motive a a refl)
(single : ∀ {a b} (h : r a b), motive (single h))
(trans : ∀ {a b c} (h₁ : ReflTransGen r a b) (h₂ : ReflTransGen r b c), motive h₁ → motive h₂ →
motive (h₁.trans h₂)) : motive h := by
induction h with
| refl => exact refl a
| tail hab hbc ih => exact trans hab (.single hbc) ih (single hbc)
theorem cases_head (h : ReflTransGen r a b) : a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by
induction h using Relation.ReflTransGen.head_induction_on <;> grind
theorem cases_head_iff : ReflTransGen r a b ↔ a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by
use cases_head
rintro (rfl | ⟨c, hac, hcb⟩)
· rfl
· exact head hac hcb
theorem total_of_right_unique (U : Relator.RightUnique r) (ab : ReflTransGen r a b)
(ac : ReflTransGen r a c) : ReflTransGen r b c ∨ ReflTransGen r c b := by
induction ab with
| refl => exact Or.inl ac
| tail _ bd IH =>
rcases IH with (IH | IH)
· rcases cases_head IH with (rfl | ⟨e, be, ec⟩)
· exact Or.inr (single bd)
· cases U bd be
exact Or.inl ec
· exact Or.inr (IH.tail bd)
end ReflTransGen
namespace TransGen
theorem to_reflTransGen {a b} (h : TransGen r a b) : ReflTransGen r a b := by
induction h with
| single h => exact ReflTransGen.single h
| tail _ bc ab => exact ReflTransGen.tail ab bc
theorem trans_left (hab : TransGen r a b) (hbc : ReflTransGen r b c) : TransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
attribute [trans] trans
theorem head' (hab : r a b) (hbc : ReflTransGen r b c) : TransGen r a c :=
trans_left (single hab) hbc
theorem tail' (hab : ReflTransGen r a b) (hbc : r b c) : TransGen r a c := by
induction hab generalizing c with
| refl => exact single hbc
| tail _ hdb IH => exact tail (IH hdb) hbc
theorem head (hab : r a b) (hbc : TransGen r b c) : TransGen r a c :=
head' hab hbc.to_reflTransGen
@[elab_as_elim]
theorem head_induction_on {motive : ∀ a : α, TransGen r a b → Prop} {a : α} (h : TransGen r a b)
(single : ∀ {a} (h : r a b), motive a (single h))
(head : ∀ {a c} (h' : r a c) (h : TransGen r c b), motive c h → motive a (h.head h')) :
motive a h := by
induction h with
| single h => exact single h
| @tail b c _ hbc h_ih =>
apply h_ih
· exact fun h ↦ head h (.single hbc) (single hbc)
· exact fun hab hbc ↦ head hab _
@[elab_as_elim]
theorem trans_induction_on {motive : ∀ {a b : α}, TransGen r a b → Prop} {a b : α}
(h : TransGen r a b) (single : ∀ {a b} (h : r a b), motive (single h))
(trans : ∀ {a b c} (h₁ : TransGen r a b) (h₂ : TransGen r b c), motive h₁ → motive h₂ →
motive (h₁.trans h₂)) :
motive h := by
induction h with
| single h => exact single h
| tail hab hbc h_ih => exact trans hab (.single hbc) h_ih (single hbc)
theorem trans_right (hab : ReflTransGen r a b) (hbc : TransGen r b c) : TransGen r a c := by
induction hbc with
| single hbc => exact tail' hab hbc
| tail _ hcd hac => exact hac.tail hcd
theorem tail'_iff : TransGen r a c ↔ ∃ b, ReflTransGen r a b ∧ r b c := by
refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ tail' hab hbc⟩
cases h with
| single hac => exact ⟨_, by rfl, hac⟩
| tail hab hbc => exact ⟨_, hab.to_reflTransGen, hbc⟩
theorem head'_iff : TransGen r a c ↔ ∃ b, r a b ∧ ReflTransGen r b c := by
refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ head' hab hbc⟩
induction h with
| single hac => exact ⟨_, hac, by rfl⟩
| tail _ hbc IH =>
rcases IH with ⟨d, had, hdb⟩
exact ⟨_, had, hdb.tail hbc⟩
end TransGen
section reflGen
lemma reflGen_eq_self (hr : Reflexive r) : ReflGen r = r := by
ext x y
simpa only [reflGen_iff, or_iff_right_iff_imp] using fun h ↦ h ▸ hr y
lemma reflexive_reflGen : Reflexive (ReflGen r) := fun _ ↦ .refl
lemma reflGen_minimal {r' : α → α → Prop} (hr' : Reflexive r') (h : ∀ x y, r x y → r' x y) {x y : α}
(hxy : ReflGen r x y) : r' x y := by
simpa [reflGen_eq_self hr'] using ReflGen.mono h hxy
end reflGen
section TransGen
instance : IsTrans α (TransGen r) :=
⟨@TransGen.trans α r⟩
instance : Trans (TransGen r) r (TransGen r) :=
⟨TransGen.tail⟩
instance : Trans r (TransGen r) (TransGen r) :=
⟨TransGen.head⟩
instance : Trans (TransGen r) (ReflTransGen r) (TransGen r) :=
⟨TransGen.trans_left⟩
instance : Trans (ReflTransGen r) (TransGen r) (TransGen r) :=
⟨TransGen.trans_right⟩
theorem transGen_eq_self (trans : Transitive r) : TransGen r = r :=
funext fun a ↦ funext fun b ↦ propext <|
⟨fun h ↦ by
induction h with
| single hc => exact hc
| tail _ hcd hac => exact trans hac hcd, TransGen.single⟩
theorem transitive_transGen : Transitive (TransGen r) := fun _ _ _ ↦ TransGen.trans
theorem transGen_idem : TransGen (TransGen r) = TransGen r :=
transGen_eq_self transitive_transGen
theorem TransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b))
(hab : TransGen r a b) : TransGen p (f a) (f b) := by
induction hab with
| single hac => exact TransGen.single (h a _ hac)
| tail _ hcd hac => exact TransGen.tail hac (h _ _ hcd)
theorem TransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → TransGen p (f a) (f b)) (hab : TransGen r a b) :
TransGen p (f a) (f b) := by
simpa [transGen_idem] using hab.lift f h
theorem TransGen.closed {p : α → α → Prop} :
(∀ a b, r a b → TransGen p a b) → TransGen r a b → TransGen p a b :=
TransGen.lift' id
lemma TransGen.closed' {P : α → Prop} (dc : ∀ {a b}, r a b → P b → P a)
{a b : α} (h : TransGen r a b) : P b → P a :=
h.head_induction_on dc fun hr _ hi ↦ dc hr ∘ hi
theorem TransGen.mono {p : α → α → Prop} :
(∀ a b, r a b → p a b) → TransGen r a b → TransGen p a b :=
TransGen.lift id
lemma transGen_minimal {r' : α → α → Prop} (hr' : Transitive r') (h : ∀ x y, r x y → r' x y)
{x y : α} (hxy : TransGen r x y) : r' x y := by
simpa [transGen_eq_self hr'] using TransGen.mono h hxy
theorem TransGen.swap (h : TransGen r b a) : TransGen (swap r) a b := by
induction h with
| single h => exact TransGen.single h
| tail _ hbc ih => exact ih.head hbc
theorem transGen_swap : TransGen (swap r) a b ↔ TransGen r b a :=
⟨TransGen.swap, TransGen.swap⟩
end TransGen
section ReflTransGen
open ReflTransGen
theorem reflTransGen_iff_eq (h : ∀ b, ¬r a b) : ReflTransGen r a b ↔ b = a := by
rw [cases_head_iff]; simp [h, eq_comm]
theorem reflTransGen_iff_eq_or_transGen : ReflTransGen r a b ↔ b = a ∨ TransGen r a b := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· cases h with
| refl => exact Or.inl rfl
| tail hac hcb => exact Or.inr (TransGen.tail' hac hcb)
· rcases h with (rfl | h)
· rfl
· exact h.to_reflTransGen
theorem ReflTransGen.lift {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) :=
ReflTransGen.trans_induction_on hab (fun _ ↦ refl) (ReflTransGen.single ∘ h _ _) fun _ _ ↦ trans
theorem ReflTransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) →
ReflTransGen r a b → ReflTransGen p a b :=
ReflTransGen.lift id
theorem reflTransGen_eq_self (refl : Reflexive r) (trans : Transitive r) : ReflTransGen r = r :=
funext fun a ↦ funext fun b ↦ propext <|
⟨fun h ↦ by
induction h with
| refl => apply refl
| tail _ h₂ IH => exact trans IH h₂, single⟩
lemma reflTransGen_minimal {r' : α → α → Prop} (hr₁ : Reflexive r') (hr₂ : Transitive r')
(h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflTransGen r x y) : r' x y := by
simpa [reflTransGen_eq_self hr₁ hr₂] using ReflTransGen.mono h hxy
theorem reflexive_reflTransGen : Reflexive (ReflTransGen r) := fun _ ↦ refl
theorem transitive_reflTransGen : Transitive (ReflTransGen r) := fun _ _ _ ↦ trans
instance : Trans r (ReflTransGen r) (ReflTransGen r) :=
⟨head⟩
instance : Trans (ReflTransGen r) r (ReflTransGen r) :=
⟨tail⟩
instance : IsRefl α (ReflTransGen r) :=
⟨@ReflTransGen.refl α r⟩
instance : IsTrans α (ReflTransGen r) :=
⟨@ReflTransGen.trans α r⟩
theorem reflTransGen_idem : ReflTransGen (ReflTransGen r) = ReflTransGen r :=
reflTransGen_eq_self reflexive_reflTransGen transitive_reflTransGen
theorem ReflTransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → ReflTransGen p (f a) (f b))
(hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := by
simpa [reflTransGen_idem] using hab.lift f h
theorem reflTransGen_closed {p : α → α → Prop} :
(∀ a b, r a b → ReflTransGen p a b) → ReflTransGen r a b → ReflTransGen p a b :=
ReflTransGen.lift' id
theorem ReflTransGen.swap (h : ReflTransGen r b a) : ReflTransGen (swap r) a b := by
induction h with
| refl => rfl
| tail _ hbc ih => exact ih.head hbc
theorem reflTransGen_swap : ReflTransGen (swap r) a b ↔ ReflTransGen r b a :=
⟨ReflTransGen.swap, ReflTransGen.swap⟩
@[simp] lemma reflGen_transGen : ReflGen (TransGen r) = ReflTransGen r := by
ext x y
simp_rw [reflTransGen_iff_eq_or_transGen, reflGen_iff]
@[simp] lemma transGen_reflGen : TransGen (ReflGen r) = ReflTransGen r := by
ext x y
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simpa [reflTransGen_idem]
using TransGen.to_reflTransGen <| TransGen.mono (fun _ _ ↦ ReflGen.to_reflTransGen) h
· obtain (rfl | h) := reflTransGen_iff_eq_or_transGen.mp h
· exact .single .refl
· exact TransGen.mono (fun _ _ ↦ .single) h
@[simp] lemma reflTransGen_reflGen : ReflTransGen (ReflGen r) = ReflTransGen r := by
simp only [← transGen_reflGen, reflGen_eq_self reflexive_reflGen]
@[simp] lemma reflTransGen_transGen : ReflTransGen (TransGen r) = ReflTransGen r := by
simp only [← reflGen_transGen, transGen_idem]
lemma reflTransGen_eq_transGen (hr : Reflexive r) :
ReflTransGen r = TransGen r := by
rw [← transGen_reflGen, reflGen_eq_self hr]
lemma reflTransGen_eq_reflGen (hr : Transitive r) :
ReflTransGen r = ReflGen r := by
rw [← reflGen_transGen, transGen_eq_self hr]
end ReflTransGen
namespace EqvGen
variable (r)
theorem is_equivalence : Equivalence (@EqvGen α r) :=
Equivalence.mk EqvGen.refl (EqvGen.symm _ _) (EqvGen.trans _ _ _)
/-- `EqvGen.setoid r` is the setoid generated by a relation `r`.
The motivation for this definition is that `Quot r` behaves like `Quotient (EqvGen.setoid r)`,
see for example `Quot.eqvGen_exact` and `Quot.eqvGen_sound`. -/
def setoid : Setoid α :=
Setoid.mk _ (EqvGen.is_equivalence r)
theorem mono {r p : α → α → Prop} (hrp : ∀ a b, r a b → p a b) (h : EqvGen r a b) :
EqvGen p a b := by
induction h with
| rel a b h => exact EqvGen.rel _ _ (hrp _ _ h)
| refl => exact EqvGen.refl _
| symm a b _ ih => exact EqvGen.symm _ _ ih
| trans a b c _ _ hab hbc => exact EqvGen.trans _ _ _ hab hbc
end EqvGen
/-- The join of a relation on a single type is a new relation for which
pairs of terms are related if there is a third term they are both
related to. For example, if `r` is a relation representing rewrites
in a term rewriting system, then *confluence* is the property that if
`a` rewrites to both `b` and `c`, then `join r` relates `b` and `c`
(see `Relation.church_rosser`).
-/
def Join (r : α → α → Prop) : α → α → Prop := fun a b ↦ ∃ c, r a c ∧ r b c
section Join
open ReflTransGen ReflGen
/-- A sufficient condition for the Church-Rosser property. -/
theorem church_rosser (h : ∀ a b c, r a b → r a c → ∃ d, ReflGen r b d ∧ ReflTransGen r c d)
(hab : ReflTransGen r a b) (hac : ReflTransGen r a c) : Join (ReflTransGen r) b c := by
induction hab with
| refl => exact ⟨c, hac, refl⟩
| @tail d e _ hde ih =>
rcases ih with ⟨b, hdb, hcb⟩
have : ∃ a, ReflTransGen r e a ∧ ReflGen r b a := by
clear hcb
induction hdb with
| refl => exact ⟨e, refl, ReflGen.single hde⟩
| @tail f b _ hfb ih =>
rcases ih with ⟨a, hea, hfa⟩
cases hfa with
| refl => exact ⟨b, hea.tail hfb, ReflGen.refl⟩
| single hfa =>
rcases h _ _ _ hfb hfa with ⟨c, hbc, hac⟩
exact ⟨c, hea.trans hac, hbc⟩
rcases this with ⟨a, hea, hba⟩
cases hba with
| refl => exact ⟨b, hea, hcb⟩
| single hba => exact ⟨a, hea, hcb.tail hba⟩
theorem join_of_single (h : Reflexive r) (hab : r a b) : Join r a b :=
⟨b, hab, h b⟩
theorem symmetric_join : Symmetric (Join r) := fun _ _ ⟨c, hac, hcb⟩ ↦ ⟨c, hcb, hac⟩
theorem reflexive_join (h : Reflexive r) : Reflexive (Join r) := fun a ↦ ⟨a, h a, h a⟩
theorem transitive_join (ht : Transitive r) (h : ∀ a b c, r a b → r a c → Join r b c) :
Transitive (Join r) :=
fun _ b _ ⟨x, hax, hbx⟩ ⟨y, hby, hcy⟩ ↦
let ⟨z, hxz, hyz⟩ := h b x y hbx hby
⟨z, ht hax hxz, ht hcy hyz⟩
theorem equivalence_join (hr : Reflexive r) (ht : Transitive r)
(h : ∀ a b c, r a b → r a c → Join r b c) : Equivalence (Join r) :=
⟨reflexive_join hr, @symmetric_join _ _, @transitive_join _ _ ht h⟩
theorem equivalence_join_reflTransGen
(h : ∀ a b c, r a b → r a c → ∃ d, ReflGen r b d ∧ ReflTransGen r c d) :
Equivalence (Join (ReflTransGen r)) :=
equivalence_join reflexive_reflTransGen transitive_reflTransGen fun _ _ _ ↦ church_rosser h
theorem join_of_equivalence {r' : α → α → Prop} (hr : Equivalence r) (h : ∀ a b, r' a b → r a b) :
Join r' a b → r a b
| ⟨_, hac, hbc⟩ => hr.trans (h _ _ hac) (hr.symm <| h _ _ hbc)
theorem reflTransGen_of_transitive_reflexive {r' : α → α → Prop} (hr : Reflexive r)
(ht : Transitive r) (h : ∀ a b, r' a b → r a b) (h' : ReflTransGen r' a b) : r a b := by
induction h' with
| refl => exact hr _
| tail _ hbc ih => exact ht ih (h _ _ hbc)
theorem reflTransGen_of_equivalence {r' : α → α → Prop} (hr : Equivalence r) :
(∀ a b, r' a b → r a b) → ReflTransGen r' a b → r a b :=
reflTransGen_of_transitive_reflexive hr.1 (fun _ _ _ ↦ hr.trans)
end Join
end Relation
section EqvGen
open Relation
variable {r : α → α → Prop} {a b : α}
theorem Quot.eqvGen_exact (H : Quot.mk r a = Quot.mk r b) : EqvGen r a b :=
@Quotient.exact _ (EqvGen.setoid r) a b (congrArg
(Quot.lift (Quotient.mk (EqvGen.setoid r)) (fun x y h ↦ Quot.sound (EqvGen.rel x y h))) H)
theorem Quot.eqvGen_sound (H : EqvGen r a b) : Quot.mk r a = Quot.mk r b :=
EqvGen.rec
(fun _ _ h ↦ Quot.sound h)
(fun _ ↦ rfl)
(fun _ _ _ IH ↦ Eq.symm IH)
(fun _ _ _ _ _ IH₁ IH₂ ↦ Eq.trans IH₁ IH₂)
H
theorem Equivalence.eqvGen_iff (h : Equivalence r) : EqvGen r a b ↔ r a b :=
Iff.intro
(by
intro h
induction h with
| rel => assumption
| refl => exact h.1 _
| symm => apply h.symm; assumption
| trans _ _ _ _ _ hab hbc => exact h.trans hab hbc)
(EqvGen.rel a b)
theorem Equivalence.eqvGen_eq (h : Equivalence r) : EqvGen r = r :=
funext fun _ ↦ funext fun _ ↦ propext <| h.eqvGen_iff
end EqvGen |
.lake/packages/mathlib/Mathlib/Logic/OpClass.lean | import Mathlib.Init
/-!
# Typeclasses for commuting heterogeneous operations
The three classes in this file are for two-argument functions where one input is of type `α`,
the output is of type `β` and the other input is of type `α` or `β`.
They express the property that permuting arguments of type `α` does not change the result.
## Main definitions
* `IsSymmOp`: for `op : α → α → β`, `op a b = op b a`.
* `LeftCommutative`: for `op : α → β → β`, `op a₁ (op a₂ b) = op a₂ (op a₁ b)`.
* `RightCommutative`: for `op : β → α → β`, `op (op b a₁) a₂ = op (op b a₂) a₁`.
-/
universe u v
variable {α : Sort u} {β : Sort v}
/-- `IsSymmOp op` where `op : α → α → β` says that `op` is a symmetric operation,
i.e. `op a b = op b a`.
It is the natural generalisation of `Std.Commutative` (`β = α`) and `IsSymm` (`β = Prop`). -/
class IsSymmOp (op : α → α → β) : Prop where
/-- A symmetric operation satisfies `op a b = op b a`. -/
symm_op : ∀ a b, op a b = op b a
/-- `LeftCommutative op` where `op : α → β → β` says that `op` is a left-commutative operation,
i.e. `op a₁ (op a₂ b) = op a₂ (op a₁ b)`. -/
class LeftCommutative (op : α → β → β) : Prop where
/-- A left-commutative operation satisfies `op a₁ (op a₂ b) = op a₂ (op a₁ b)`. -/
left_comm : (a₁ a₂ : α) → (b : β) → op a₁ (op a₂ b) = op a₂ (op a₁ b)
/-- `RightCommutative op` where `op : β → α → β` says that `op` is a right-commutative operation,
i.e. `op (op b a₁) a₂ = op (op b a₂) a₁`. -/
class RightCommutative (op : β → α → β) : Prop where
/-- A right-commutative operation satisfies `op (op b a₁) a₂ = op (op b a₂) a₁`. -/
right_comm : (b : β) → (a₁ a₂ : α) → op (op b a₁) a₂ = op (op b a₂) a₁
instance (priority := 100) isSymmOp_of_isCommutative (α : Sort u) (op : α → α → α)
[Std.Commutative op] : IsSymmOp op where symm_op := Std.Commutative.comm
theorem IsSymmOp.flip_eq (op : α → α → β) [IsSymmOp op] : flip op = op :=
funext fun a ↦ funext fun b ↦ (IsSymmOp.symm_op a b).symm
instance {f : α → β → β} [h : LeftCommutative f] : RightCommutative (fun x y ↦ f y x) :=
⟨fun _ _ _ ↦ (h.left_comm _ _ _).symm⟩
instance {f : β → α → β} [h : RightCommutative f] : LeftCommutative (fun x y ↦ f y x) :=
⟨fun _ _ _ ↦ (h.right_comm _ _ _).symm⟩
instance {f : α → α → α} [hc : Std.Commutative f] [ha : Std.Associative f] : LeftCommutative f :=
⟨fun a b c ↦ by rw [← ha.assoc, hc.comm a, ha.assoc]⟩
instance {f : α → α → α} [hc : Std.Commutative f] [ha : Std.Associative f] : RightCommutative f :=
⟨fun a b c ↦ by rw [ha.assoc, hc.comm b, ha.assoc]⟩ |
.lake/packages/mathlib/Mathlib/Logic/Hydra.lean | import Mathlib.Data.Finsupp.Lex
import Mathlib.Data.Finsupp.Multiset
import Mathlib.Order.GameAdd
/-!
# Termination of a hydra game
This file deals with the following version of the hydra game: each head of the hydra is
labelled by an element in a type `α`, and when you cut off one head with label `a`, it
grows back an arbitrary but finite number of heads, all labelled by elements smaller than
`a` with respect to a well-founded relation `r` on `α`. We show that no matter how (in
what order) you choose cut off the heads, the game always terminates, i.e. all heads will
eventually be cut off (but of course it can last arbitrarily long, i.e. takes an
arbitrary finite number of steps).
This result is stated as the well-foundedness of the `CutExpand` relation defined in
this file: we model the heads of the hydra as a multiset of elements of `α`, and the
valid "moves" of the game are modelled by the relation `CutExpand r` on `Multiset α`:
`CutExpand r s' s` is true iff `s'` is obtained by removing one head `a ∈ s` and
adding back an arbitrary multiset `t` of heads such that all `a' ∈ t` satisfy `r a' a`.
We follow the proof by Peter LeFanu Lumsdaine at https://mathoverflow.net/a/229084/3332.
TODO: formalize the relations corresponding to more powerful (e.g. Kirby–Paris and Buchholz)
hydras, and prove their well-foundedness.
-/
namespace Relation
open Multiset Prod
variable {α : Type*}
/-- The relation that specifies valid moves in our hydra game. `CutExpand r s' s`
means that `s'` is obtained by removing one head `a ∈ s` and adding back an arbitrary
multiset `t` of heads such that all `a' ∈ t` satisfy `r a' a`.
This is most directly translated into `s' = s.erase a + t`, but `Multiset.erase` requires
`DecidableEq α`, so we use the equivalent condition `s' + {a} = s + t` instead, which
is also easier to verify for explicit multisets `s'`, `s` and `t`.
We also don't include the condition `a ∈ s` because `s' + {a} = s + t` already
guarantees `a ∈ s + t`, and if `r` is irreflexive then `a ∉ t`, which is the
case when `r` is well-founded, the case we are primarily interested in.
The lemma `Relation.cutExpand_iff` below converts between this convenient definition
and the direct translation when `r` is irreflexive. -/
def CutExpand (r : α → α → Prop) (s' s : Multiset α) : Prop :=
∃ (t : Multiset α) (a : α), (∀ a' ∈ t, r a' a) ∧ s' + {a} = s + t
variable {r : α → α → Prop}
theorem cutExpand_le_invImage_lex [DecidableEq α] [IsIrrefl α r] :
CutExpand r ≤ InvImage (Finsupp.Lex (rᶜ ⊓ (· ≠ ·)) (· < ·)) toFinsupp := by
rintro s t ⟨u, a, hr, he⟩
replace hr := fun a' ↦ mt (hr a')
classical
refine ⟨a, fun b h ↦ ?_, ?_⟩ <;> simp_rw [toFinsupp_apply]
· apply_fun count b at he
simpa only [count_add, count_singleton, if_neg h.2, add_zero, count_eq_zero.2 (hr b h.1)]
using he
· apply_fun count a at he
simp only [count_add, count_singleton_self, count_eq_zero.2 (hr _ (irrefl_of r a)),
add_zero] at he
exact he ▸ Nat.lt_succ_self _
theorem cutExpand_singleton {s x} (h : ∀ x' ∈ s, r x' x) : CutExpand r s {x} :=
⟨s, x, h, add_comm s _⟩
theorem cutExpand_singleton_singleton {x' x} (h : r x' x) : CutExpand r {x'} {x} :=
cutExpand_singleton fun a h ↦ by rwa [mem_singleton.1 h]
theorem cutExpand_add_left {t u} (s) : CutExpand r (s + t) (s + u) ↔ CutExpand r t u :=
exists₂_congr fun _ _ ↦ and_congr Iff.rfl <| by rw [add_assoc, add_assoc, add_left_cancel_iff]
lemma cutExpand_add_right {s' s} (t) : CutExpand r (s' + t) (s + t) ↔ CutExpand r s' s := by
convert cutExpand_add_left t using 2 <;> apply add_comm
theorem cutExpand_add_single {a' a : α} (s : Multiset α) (h : r a' a) :
CutExpand r (s + {a'}) (s + {a}) :=
(cutExpand_add_left s).2 <| cutExpand_singleton_singleton h
theorem cutExpand_single_add {a' a : α} (h : r a' a) (s : Multiset α) :
CutExpand r ({a'} + s) ({a} + s) :=
(cutExpand_add_right s).2 <| cutExpand_singleton_singleton h
theorem cutExpand_iff [DecidableEq α] [IsIrrefl α r] {s' s : Multiset α} :
CutExpand r s' s ↔
∃ (t : Multiset α) (a : α), (∀ a' ∈ t, r a' a) ∧ a ∈ s ∧ s' = s.erase a + t := by
simp_rw [CutExpand, add_singleton_eq_iff]
refine exists₂_congr fun t a ↦ ⟨?_, ?_⟩
· rintro ⟨ht, ha, rfl⟩
obtain h | h := mem_add.1 ha
exacts [⟨ht, h, erase_add_left_pos t h⟩, (@irrefl α r _ a (ht a h)).elim]
· rintro ⟨ht, h, rfl⟩
exact ⟨ht, mem_add.2 (Or.inl h), (erase_add_left_pos t h).symm⟩
theorem not_cutExpand_zero [IsIrrefl α r] (s) : ¬CutExpand r s 0 := by
classical
rw [cutExpand_iff]
rintro ⟨_, _, _, ⟨⟩, _⟩
lemma cutExpand_zero {x} : CutExpand r 0 {x} := ⟨0, x, nofun, add_comm 0 _⟩
/-- For any relation `r` on `α`, multiset addition `Multiset α × Multiset α → Multiset α` is a
fibration between the game sum of `CutExpand r` with itself and `CutExpand r` itself. -/
theorem cutExpand_fibration (r : α → α → Prop) :
Fibration (GameAdd (CutExpand r) (CutExpand r)) (CutExpand r) fun s ↦ s.1 + s.2 := by
rintro ⟨s₁, s₂⟩ s ⟨t, a, hr, he⟩; dsimp at he ⊢
classical
obtain ⟨ha, rfl⟩ := add_singleton_eq_iff.1 he
rw [add_assoc, mem_add] at ha
obtain h | h := ha
· refine ⟨(s₁.erase a + t, s₂), GameAdd.fst ⟨t, a, hr, ?_⟩, ?_⟩
· rw [add_comm, ← add_assoc, singleton_add, cons_erase h]
· rw [add_assoc s₁, erase_add_left_pos _ h, add_right_comm, add_assoc]
· refine ⟨(s₁, (s₂ + t).erase a), GameAdd.snd ⟨t, a, hr, ?_⟩, ?_⟩
· rw [add_comm, singleton_add, cons_erase h]
· rw [add_assoc, erase_add_right_pos _ h]
/-- `CutExpand` preserves leftward-closedness under a relation. -/
lemma cutExpand_closed [IsIrrefl α r] (p : α → Prop)
(h : ∀ {a' a}, r a' a → p a → p a') {s' s : Multiset α} :
CutExpand r s' s → (∀ a ∈ s, p a) → ∀ a ∈ s', p a := by
classical
rw [cutExpand_iff]
rintro ⟨t, a, hr, ha, rfl⟩ hsp a' h'
obtain (h' | h') := mem_add.1 h'
exacts [hsp a' (mem_of_mem_erase h'), h (hr a' h') (hsp a ha)]
lemma cutExpand_double {a a₁ a₂} (h₁ : r a₁ a) (h₂ : r a₂ a) : CutExpand r {a₁, a₂} {a} :=
cutExpand_singleton <| by
simp only [insert_eq_cons, mem_cons, mem_singleton, forall_eq_or_imp, forall_eq]
tauto
lemma cutExpand_pair_left {a' a b} (hr : r a' a) : CutExpand r {a', b} {a, b} :=
(cutExpand_add_right {b}).2 (cutExpand_singleton_singleton hr)
lemma cutExpand_pair_right {a b' b} (hr : r b' b) : CutExpand r {a, b'} {a, b} :=
(cutExpand_add_left {a}).2 (cutExpand_singleton_singleton hr)
lemma cutExpand_double_left {a a₁ a₂ b} (h₁ : r a₁ a) (h₂ : r a₂ a) :
CutExpand r {a₁, a₂, b} {a, b} :=
(cutExpand_add_right {b}).2 (cutExpand_double h₁ h₂)
/-- A multiset is accessible under `CutExpand` if all its singleton subsets are,
assuming `r` is irreflexive. -/
theorem acc_of_singleton [IsIrrefl α r] {s : Multiset α} (hs : ∀ a ∈ s, Acc (CutExpand r) {a}) :
Acc (CutExpand r) s := by
induction s using Multiset.induction with
| empty => exact Acc.intro 0 fun s h ↦ (not_cutExpand_zero s h).elim
| cons a s ihs =>
rw [← s.singleton_add a]
rw [forall_mem_cons] at hs
exact (hs.1.prod_gameAdd <| ihs fun a ha ↦ hs.2 a ha).of_fibration _ (cutExpand_fibration r)
/-- A singleton `{a}` is accessible under `CutExpand r` if `a` is accessible under `r`,
assuming `r` is irreflexive. -/
theorem _root_.Acc.cutExpand [IsIrrefl α r] {a : α} (hacc : Acc r a) : Acc (CutExpand r) {a} := by
induction hacc with | _ a h ih
refine Acc.intro _ fun s ↦ ?_
classical
simp only [cutExpand_iff, mem_singleton]
rintro ⟨t, a, hr, rfl, rfl⟩
refine acc_of_singleton fun a' ↦ ?_
rw [erase_singleton, zero_add]
exact ih a' ∘ hr a'
/-- `CutExpand r` is well-founded when `r` is. -/
theorem _root_.WellFounded.cutExpand (hr : WellFounded r) : WellFounded (CutExpand r) :=
⟨have := hr.isIrrefl; fun _ ↦ acc_of_singleton fun a _ ↦ (hr.apply a).cutExpand⟩
instance [h : IsWellFounded α r] : IsWellFounded _ (CutExpand r) :=
⟨h.wf.cutExpand⟩
end Relation |
.lake/packages/mathlib/Mathlib/Logic/Relator.lean | import Mathlib.Logic.Function.Defs
/-!
# Relator for functions, pairs, sums, and lists.
-/
namespace Relator
universe u₁ u₂ v₁ v₂
/- TODO(johoelzl):
* should we introduce relators of datatypes as recursive function or as inductive
predicate? For now we stick to the recursor approach.
* relation lift for datatypes, Π, Σ, set, and subtype types
* proof composition and identity laws
* implement method to derive relators from datatype
-/
section
variable {α : Sort u₁} {β : Sort u₂} {γ : Sort v₁} {δ : Sort v₂}
variable (R : α → β → Prop) (S : γ → δ → Prop)
/-- The binary relations `R : α → β → Prop` and `S : γ → δ → Prop` induce a binary
relation on functions `LiftFun : (α → γ) → (β → δ) → Prop`. -/
def LiftFun (f : α → γ) (g : β → δ) : Prop :=
∀ ⦃a b⦄, R a b → S (f a) (g b)
/-- `(R ⇒ S) f g` means `LiftFun R S f g`. -/
scoped infixr:40 " ⇒ " => LiftFun
end
section
variable {α : Type u₁} {β : Type u₂} (R : α → β → Prop)
/-- A relation is "right total" if every element appears on the right. -/
def RightTotal : Prop := ∀ b, ∃ a, R a b
/-- A relation is "left total" if every element appears on the left. -/
def LeftTotal : Prop := ∀ a, ∃ b, R a b
/-- A relation is "bi-total" if it is both right total and left total. -/
def BiTotal : Prop := LeftTotal R ∧ RightTotal R
/-- A relation is "left unique" if every element on the right is paired with at
most one element on the left. -/
def LeftUnique : Prop := ∀ ⦃a b c⦄, R a c → R b c → a = b
/-- A relation is "right unique" if every element on the left is paired with at
most one element on the right. -/
def RightUnique : Prop := ∀ ⦃a b c⦄, R a b → R a c → b = c
/-- A relation is "bi-unique" if it is both left unique and right unique. -/
def BiUnique : Prop := LeftUnique R ∧ RightUnique R
variable {R}
lemma RightTotal.rel_forall (h : RightTotal R) :
((R ⇒ (· → ·)) ⇒ (· → ·)) (fun p => ∀ i, p i) (fun q => ∀ i, q i) :=
fun _ _ Hrel H b => Exists.elim (h b) (fun _ Rab => Hrel Rab (H _))
lemma LeftTotal.rel_exists (h : LeftTotal R) :
((R ⇒ (· → ·)) ⇒ (· → ·)) (fun p => ∃ i, p i) (fun q => ∃ i, q i) :=
fun _ _ Hrel ⟨a, pa⟩ => (h a).imp fun _ Rab => Hrel Rab pa
lemma BiTotal.rel_forall (h : BiTotal R) :
((R ⇒ Iff) ⇒ Iff) (fun p => ∀ i, p i) (fun q => ∀ i, q i) :=
fun _ _ Hrel =>
⟨fun H b => Exists.elim (h.right b) (fun _ Rab => (Hrel Rab).mp (H _)),
fun H a => Exists.elim (h.left a) (fun _ Rab => (Hrel Rab).mpr (H _))⟩
lemma BiTotal.rel_exists (h : BiTotal R) :
((R ⇒ Iff) ⇒ Iff) (fun p => ∃ i, p i) (fun q => ∃ i, q i) :=
fun _ _ Hrel =>
⟨fun ⟨a, pa⟩ => (h.left a).imp fun _ Rab => (Hrel Rab).1 pa,
fun ⟨b, qb⟩ => (h.right b).imp fun _ Rab => (Hrel Rab).2 qb⟩
lemma left_unique_of_rel_eq {eq' : β → β → Prop} (he : (R ⇒ (R ⇒ Iff)) Eq eq') : LeftUnique R :=
fun a b c (ac : R a c) (bc : R b c) => (he ac bc).mpr ((he bc bc).mp rfl)
end
lemma rel_imp : (Iff ⇒ (Iff ⇒ Iff)) (· → ·) (· → ·) :=
fun _ _ h _ _ l => imp_congr h l
lemma rel_not : (Iff ⇒ Iff) Not Not :=
fun _ _ h => not_congr h
lemma bi_total_eq {α : Type u₁} : Relator.BiTotal (@Eq α) :=
{ left := fun a => ⟨a, rfl⟩, right := fun a => ⟨a, rfl⟩ }
variable {α : Type*} {β : Type*} {γ : Type*}
variable {r : α → β → Prop}
lemma LeftUnique.flip (h : LeftUnique r) : RightUnique (flip r) :=
fun _ _ _ h₁ h₂ => h h₁ h₂
lemma rel_and : ((· ↔ ·) ⇒ (· ↔ ·) ⇒ (· ↔ ·)) (· ∧ ·) (· ∧ ·) :=
fun _ _ h₁ _ _ h₂ => and_congr h₁ h₂
lemma rel_or : ((· ↔ ·) ⇒ (· ↔ ·) ⇒ (· ↔ ·)) (· ∨ ·) (· ∨ ·) :=
fun _ _ h₁ _ _ h₂ => or_congr h₁ h₂
lemma rel_iff : ((· ↔ ·) ⇒ (· ↔ ·) ⇒ (· ↔ ·)) (· ↔ ·) (· ↔ ·) :=
fun _ _ h₁ _ _ h₂ => iff_congr h₁ h₂
lemma rel_eq {r : α → β → Prop} (hr : BiUnique r) : (r ⇒ r ⇒ (· ↔ ·)) (· = ·) (· = ·) :=
fun _ _ h₁ _ _ h₂ => ⟨fun h => hr.right h₁ <| h.symm ▸ h₂, fun h => hr.left h₁ <| h.symm ▸ h₂⟩
open Function
variable {r₁₁ : α → α → Prop} {r₁₂ : α → β → Prop} {r₂₁ : β → α → Prop}
{r₂₃ : β → γ → Prop} {r₁₃ : α → γ → Prop}
namespace LeftTotal
protected lemma refl (hr : ∀ a : α, r₁₁ a a) :
LeftTotal r₁₁ :=
fun a ↦ ⟨a, hr _⟩
protected lemma symm (hr : ∀ (a : α) (b : β), r₁₂ a b → r₂₁ b a) :
LeftTotal r₁₂ → RightTotal r₂₁ :=
fun h a ↦ (h a).imp (fun _ ↦ hr _ _)
protected lemma trans (hr : ∀ (a : α) (b : β) (c : γ), r₁₂ a b → r₂₃ b c → r₁₃ a c) :
LeftTotal r₁₂ → LeftTotal r₂₃ → LeftTotal r₁₃ :=
fun h₁ h₂ a ↦ let ⟨b, hab⟩ := h₁ a; let ⟨c, hbc⟩ := h₂ b; ⟨c, hr _ _ _ hab hbc⟩
end LeftTotal
namespace RightTotal
protected lemma refl (hr : ∀ a : α, r₁₁ a a) : RightTotal r₁₁ :=
LeftTotal.refl hr
protected lemma symm (hr : ∀ (a : α) (b : β), r₁₂ a b → r₂₁ b a) :
RightTotal r₁₂ → LeftTotal r₂₁ :=
LeftTotal.symm (fun _ _ ↦ hr _ _)
protected lemma trans (hr : ∀ (a : α) (b : β) (c : γ), r₁₂ a b → r₂₃ b c → r₁₃ a c) :
RightTotal r₁₂ → RightTotal r₂₃ → RightTotal r₁₃ :=
swap <| LeftTotal.trans (fun _ _ _ ↦ swap <| hr _ _ _)
end RightTotal
namespace BiTotal
protected lemma refl (hr : ∀ a : α, r₁₁ a a) :
BiTotal r₁₁ :=
⟨LeftTotal.refl hr, RightTotal.refl hr⟩
protected lemma symm (hr : ∀ (a : α) (b : β), r₁₂ a b → r₂₁ b a) :
BiTotal r₁₂ → BiTotal r₂₁ :=
fun h ↦ ⟨h.2.symm hr, h.1.symm hr⟩
protected lemma trans (hr : ∀ (a : α) (b : β) (c : γ), r₁₂ a b → r₂₃ b c → r₁₃ a c) :
BiTotal r₁₂ → BiTotal r₂₃ → BiTotal r₁₃ :=
fun h₁ h₂ ↦ ⟨h₁.1.trans hr h₂.1, h₁.2.trans hr h₂.2⟩
end BiTotal
end Relator |
.lake/packages/mathlib/Mathlib/Logic/Nontrivial/Basic.lean | import Mathlib.Data.Prod.Basic
import Mathlib.Logic.Function.Basic
import Mathlib.Logic.Nontrivial.Defs
import Mathlib.Logic.Unique
import Mathlib.Order.Defs.LinearOrder
import Mathlib.Tactic.Attr.Register
/-!
# Nontrivial types
Results about `Nontrivial`.
-/
variable {α : Type*} {β : Type*}
-- `x` and `y` are explicit here, as they are often needed to guide typechecking of `h`.
theorem nontrivial_of_lt [Preorder α] (x y : α) (h : x < y) : Nontrivial α :=
⟨⟨x, y, ne_of_lt h⟩⟩
theorem exists_pair_lt (α : Type*) [Nontrivial α] [LinearOrder α] : ∃ x y : α, x < y := by
rcases exists_pair_ne α with ⟨x, y, hxy⟩
cases lt_or_gt_of_ne hxy <;> exact ⟨_, _, ‹_›⟩
theorem nontrivial_iff_lt [LinearOrder α] : Nontrivial α ↔ ∃ x y : α, x < y :=
⟨fun h ↦ @exists_pair_lt α h _, fun ⟨x, y, h⟩ ↦ nontrivial_of_lt x y h⟩
theorem Subtype.nontrivial_iff_exists_ne (p : α → Prop) (x : Subtype p) :
Nontrivial (Subtype p) ↔ ∃ (y : α) (_ : p y), y ≠ x := by
simp only [_root_.nontrivial_iff_exists_ne x, Subtype.exists, Ne, Subtype.ext_iff]
open Classical in
/-- An inhabited type is either nontrivial, or has a unique element. -/
noncomputable def nontrivialPSumUnique (α : Type*) [Inhabited α] :
Nontrivial α ⊕' Unique α :=
if h : Nontrivial α then PSum.inl h
else
PSum.inr
{ default := default,
uniq := fun x : α ↦ by
by_contra H
exact h ⟨_, _, H⟩ }
instance Option.nontrivial [Nonempty α] : Nontrivial (Option α) := by
inhabit α
exact ⟨none, some default, nofun⟩
/-- Pushforward a `Nontrivial` instance along an injective function. -/
protected theorem Function.Injective.nontrivial [Nontrivial α] {f : α → β}
(hf : Function.Injective f) : Nontrivial β :=
let ⟨x, y, h⟩ := exists_pair_ne α
⟨⟨f x, f y, hf.ne h⟩⟩
/-- An injective function from a nontrivial type has an argument at
which it does not take a given value. -/
protected theorem Function.Injective.exists_ne [Nontrivial α] {f : α → β}
(hf : Function.Injective f) (y : β) : ∃ x, f x ≠ y := by
rcases exists_pair_ne α with ⟨x₁, x₂, hx⟩
by_cases h : f x₂ = y
· exact ⟨x₁, (hf.ne_iff' h).2 hx⟩
· exact ⟨x₂, h⟩
instance nontrivial_prod_right [Nonempty α] [Nontrivial β] : Nontrivial (α × β) :=
Prod.snd_surjective.nontrivial
instance nontrivial_prod_left [Nontrivial α] [Nonempty β] : Nontrivial (α × β) :=
Prod.fst_surjective.nontrivial
namespace Pi
variable {I : Type*} {f : I → Type*}
open Classical in
/-- A pi type is nontrivial if it's nonempty everywhere and nontrivial somewhere. -/
theorem nontrivial_at (i' : I) [inst : ∀ i, Nonempty (f i)] [Nontrivial (f i')] :
Nontrivial (∀ i : I, f i) := by
letI := Classical.decEq (∀ i : I, f i)
exact (Function.update_injective (fun i ↦ Classical.choice (inst i)) i').nontrivial
/-- As a convenience, provide an instance automatically if `(f default)` is nontrivial.
If a different index has the non-trivial type, then use `haveI := nontrivial_at that_index`.
-/
instance nontrivial [Inhabited I] [∀ i, Nonempty (f i)] [Nontrivial (f default)] :
Nontrivial (∀ i : I, f i) :=
nontrivial_at default
end Pi
instance Function.nontrivial [h : Nonempty α] [Nontrivial β] : Nontrivial (α → β) :=
h.elim fun a ↦ Pi.nontrivial_at a
@[nontriviality]
protected theorem Subsingleton.le [Preorder α] [Subsingleton α] (x y : α) : x ≤ y :=
le_of_eq (Subsingleton.elim x y) |
.lake/packages/mathlib/Mathlib/Logic/Nontrivial/Defs.lean | import Mathlib.Tactic.TypeStar
import Mathlib.Tactic.Lemma
import Mathlib.Tactic.Push.Attr
/-!
# Nontrivial types
A type is *nontrivial* if it contains at least two elements. This is useful in particular for rings
(where it is equivalent to the fact that zero is different from one) and for vector spaces
(where it is equivalent to the fact that the dimension is positive).
We introduce a typeclass `Nontrivial` formalizing this property.
Basic results about nontrivial types are in `Mathlib/Logic/Nontrivial/Basic.lean`.
-/
variable {α : Type*} {β : Type*}
/-- Predicate typeclass for expressing that a type is not reduced to a single element. In rings,
this is equivalent to `0 ≠ 1`. In vector spaces, this is equivalent to positive dimension. -/
class Nontrivial (α : Type*) : Prop where
/-- In a nontrivial type, there exists a pair of distinct terms. -/
exists_pair_ne : ∃ x y : α, x ≠ y
theorem nontrivial_iff : Nontrivial α ↔ ∃ x y : α, x ≠ y :=
⟨fun h ↦ h.exists_pair_ne, fun h ↦ ⟨h⟩⟩
theorem exists_pair_ne (α : Type*) [Nontrivial α] : ∃ x y : α, x ≠ y :=
Nontrivial.exists_pair_ne
-- See Note [decidable namespace]
protected theorem Decidable.exists_ne [Nontrivial α] [DecidableEq α] (x : α) : ∃ y, y ≠ x := by
rcases exists_pair_ne α with ⟨y, y', h⟩
by_cases hx : x = y
· rw [← hx] at h
exact ⟨y', h.symm⟩
· exact ⟨y, Ne.symm hx⟩
open Classical in
theorem exists_ne [Nontrivial α] (x : α) : ∃ y, y ≠ x := Decidable.exists_ne x
-- `x` and `y` are explicit here, as they are often needed to guide typechecking of `h`.
theorem nontrivial_of_ne (x y : α) (h : x ≠ y) : Nontrivial α :=
⟨⟨x, y, h⟩⟩
theorem nontrivial_iff_exists_ne (x : α) : Nontrivial α ↔ ∃ y, y ≠ x :=
⟨fun h ↦ @exists_ne α h x, fun ⟨_, hy⟩ ↦ nontrivial_of_ne _ _ hy⟩
instance : Nontrivial Prop :=
⟨⟨True, False, true_ne_false⟩⟩
/-- See Note [lower instance priority]
Note that since this and `instNonemptyOfInhabited` are the most "obvious" way to find a nonempty
instance if no direct instance can be found, we give this a higher priority than the usual `100`.
-/
instance (priority := 500) Nontrivial.to_nonempty [Nontrivial α] : Nonempty α :=
let ⟨x, _⟩ := _root_.exists_pair_ne α
⟨x⟩
theorem subsingleton_iff : Subsingleton α ↔ ∀ x y : α, x = y :=
⟨by
intro h
exact Subsingleton.elim, fun h ↦ ⟨h⟩⟩
@[push]
theorem not_nontrivial_iff_subsingleton : ¬Nontrivial α ↔ Subsingleton α := by
simp only [nontrivial_iff, subsingleton_iff, not_exists, Classical.not_not]
theorem not_nontrivial (α) [Subsingleton α] : ¬Nontrivial α :=
fun ⟨⟨x, y, h⟩⟩ ↦ h <| Subsingleton.elim x y
theorem not_subsingleton (α) [Nontrivial α] : ¬Subsingleton α :=
fun _ => not_nontrivial _ ‹_›
@[push]
lemma not_subsingleton_iff_nontrivial : ¬Subsingleton α ↔ Nontrivial α := by
rw [← not_nontrivial_iff_subsingleton, Classical.not_not]
/-- A type is either a subsingleton or nontrivial. -/
theorem subsingleton_or_nontrivial (α : Type*) : Subsingleton α ∨ Nontrivial α := by
rw [← not_nontrivial_iff_subsingleton, or_comm]
exact Classical.em _
theorem false_of_nontrivial_of_subsingleton (α : Type*) [Nontrivial α] [Subsingleton α] : False :=
not_nontrivial _ ‹_›
/-- Pullback a `Nontrivial` instance along a surjective function. -/
protected theorem Function.Surjective.nontrivial [Nontrivial β] {f : α → β}
(hf : Function.Surjective f) : Nontrivial α := by
rcases exists_pair_ne β with ⟨x, y, h⟩
rcases hf x with ⟨x', hx'⟩
rcases hf y with ⟨y', hy'⟩
have : x' ≠ y' := by
refine fun H ↦ h ?_
rw [← hx', ← hy', H]
exact ⟨⟨x', y', this⟩⟩
namespace Bool
instance : Nontrivial Bool :=
⟨⟨true, false, nofun⟩⟩
end Bool |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Sum.lean | import Mathlib.Data.Option.Defs
import Mathlib.Data.Sigma.Basic
import Mathlib.Logic.Equiv.Prod
import Mathlib.Tactic.Coe
/-!
# Equivalence between sum types
In this file we continue the work on equivalences begun in `Mathlib/Logic/Equiv/Defs.lean`, defining
* canonical isomorphisms between various types: e.g.,
- `Equiv.sumEquivSigmaBool` is the canonical equivalence between the sum of two types `α ⊕ β`
and the sigma-type `Σ b, bif b then β else α`;
- `Equiv.prodSumDistrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)` shows that type product and type sum
satisfy the distributive law up to a canonical equivalence;
More definitions of this kind can be found in other files.
E.g., `Mathlib/Algebra/Equiv/TransferInstance.lean` does it for many algebraic type classes like
`Group`, `Module`, etc.
## Tags
equivalence, congruence, bijective map
-/
universe u v w z
open Function
-- Unless required to be `Type*`, all variables in this file are `Sort*`
variable {α α₁ α₂ β β₁ β₂ γ δ : Sort*}
namespace Equiv
section
open Sum
/-- `PSum` is equivalent to `Sum`. -/
def psumEquivSum (α β) : α ⊕' β ≃ α ⊕ β where
toFun s := PSum.casesOn s inl inr
invFun := Sum.elim PSum.inl PSum.inr
left_inv s := by cases s <;> rfl
right_inv s := by cases s <;> rfl
/-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. This is `Sum.map` as an equivalence. -/
@[simps (attr := grind =) apply]
def sumCongr {α₁ α₂ β₁ β₂} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ ⊕ β₁ ≃ α₂ ⊕ β₂ :=
⟨Sum.map ea eb, Sum.map ea.symm eb.symm, fun x => by simp, fun x => by simp⟩
@[simp, grind =]
theorem sumCongr_trans {α₁ α₂ β₁ β₂ γ₁ γ₂} (e : α₁ ≃ β₁) (f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂) :
(Equiv.sumCongr e f).trans (Equiv.sumCongr g h) = Equiv.sumCongr (e.trans g) (f.trans h) := by
ext i
cases i <;> rfl
@[simp]
theorem sumCongr_symm {α β γ δ} (e : α ≃ β) (f : γ ≃ δ) :
(Equiv.sumCongr e f).symm = Equiv.sumCongr e.symm f.symm :=
rfl
@[simp]
theorem sumCongr_refl {α β} :
Equiv.sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α ⊕ β) := by
ext i
cases i <;> rfl
/-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕' β ≃ α' ⊕' β'`. -/
def psumCongr (e₁ : α ≃ β) (e₂ : γ ≃ δ) : α ⊕' γ ≃ β ⊕' δ where
toFun x := PSum.casesOn x (PSum.inl ∘ e₁) (PSum.inr ∘ e₂)
invFun x := PSum.casesOn x (PSum.inl ∘ e₁.symm) (PSum.inr ∘ e₂.symm)
left_inv := by rintro (x | x) <;> simp
right_inv := by rintro (x | x) <;> simp
/-- Combine two `Equiv`s using `PSum` in the domain and `Sum` in the codomain. -/
def psumSum {α₂ β₂} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) :
α₁ ⊕' β₁ ≃ α₂ ⊕ β₂ :=
(ea.psumCongr eb).trans (psumEquivSum _ _)
/-- Combine two `Equiv`s using `Sum` in the domain and `PSum` in the codomain. -/
def sumPSum {α₁ β₁} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) :
α₁ ⊕ β₁ ≃ α₂ ⊕' β₂ :=
(ea.symm.psumSum eb.symm).symm
/-- A subtype of a sum is equivalent to a sum of subtypes. -/
def subtypeSum {α β} {p : α ⊕ β → Prop} :
{c // p c} ≃ {a // p (Sum.inl a)} ⊕ {b // p (Sum.inr b)} where
toFun
| ⟨.inl a, h⟩ => .inl ⟨a, h⟩
| ⟨.inr b, h⟩ => .inr ⟨b, h⟩
invFun
| .inl a => ⟨.inl a, a.2⟩
| .inr b => ⟨.inr b, b.2⟩
left_inv := by rintro ⟨a | b, h⟩ <;> rfl
right_inv := by rintro (a | b) <;> rfl
namespace Perm
/-- Combine a permutation of `α` and of `β` into a permutation of `α ⊕ β`. -/
abbrev sumCongr {α β} (ea : Equiv.Perm α) (eb : Equiv.Perm β) : Equiv.Perm (α ⊕ β) :=
Equiv.sumCongr ea eb
@[simp]
theorem sumCongr_apply {α β} (ea : Equiv.Perm α) (eb : Equiv.Perm β) (x : α ⊕ β) :
sumCongr ea eb x = Sum.map (⇑ea) (⇑eb) x := rfl
theorem sumCongr_trans {α β} (e : Equiv.Perm α) (f : Equiv.Perm β) (g : Equiv.Perm α)
(h : Equiv.Perm β) : (sumCongr e f).trans (sumCongr g h) = sumCongr (e.trans g) (f.trans h) :=
Equiv.sumCongr_trans e f g h
theorem sumCongr_symm {α β} (e : Equiv.Perm α) (f : Equiv.Perm β) :
(sumCongr e f).symm = sumCongr e.symm f.symm :=
Equiv.sumCongr_symm e f
theorem sumCongr_refl {α β} : sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α ⊕ β) :=
Equiv.sumCongr_refl
end Perm
/-- `Bool` is equivalent the sum of two `PUnit`s. -/
def boolEquivPUnitSumPUnit : Bool ≃ PUnit.{u + 1} ⊕ PUnit.{v + 1} :=
⟨fun b => b.casesOn (inl PUnit.unit) (inr PUnit.unit), Sum.elim (fun _ => false) fun _ => true,
fun b => by cases b <;> rfl, fun s => by rcases s with (⟨⟨⟩⟩ | ⟨⟨⟩⟩) <;> rfl⟩
/-- Sum of types is commutative up to an equivalence. This is `Sum.swap` as an equivalence. -/
@[simps -fullyApplied apply]
def sumComm (α β) : α ⊕ β ≃ β ⊕ α :=
⟨Sum.swap, Sum.swap, Sum.swap_swap, Sum.swap_swap⟩
@[simp]
theorem sumComm_symm (α β) : (sumComm α β).symm = sumComm β α :=
rfl
/-- Sum of types is associative up to an equivalence. -/
def sumAssoc (α β γ) : (α ⊕ β) ⊕ γ ≃ α ⊕ (β ⊕ γ) :=
⟨Sum.elim (Sum.elim Sum.inl (Sum.inr ∘ Sum.inl)) (Sum.inr ∘ Sum.inr),
Sum.elim (Sum.inl ∘ Sum.inl) <| Sum.elim (Sum.inl ∘ Sum.inr) Sum.inr,
by rintro (⟨_ | _⟩ | _) <;> rfl, by
rintro (_ | ⟨_ | _⟩) <;> rfl⟩
@[simp]
theorem sumAssoc_apply_inl_inl {α β γ} (a) : sumAssoc α β γ (inl (inl a)) = inl a :=
rfl
@[simp]
theorem sumAssoc_apply_inl_inr {α β γ} (b) : sumAssoc α β γ (inl (inr b)) = inr (inl b) :=
rfl
@[simp]
theorem sumAssoc_apply_inr {α β γ} (c) : sumAssoc α β γ (inr c) = inr (inr c) :=
rfl
@[simp]
theorem sumAssoc_symm_apply_inl {α β γ} (a) : (sumAssoc α β γ).symm (inl a) = inl (inl a) :=
rfl
@[simp]
theorem sumAssoc_symm_apply_inr_inl {α β γ} (b) :
(sumAssoc α β γ).symm (inr (inl b)) = inl (inr b) :=
rfl
@[simp]
theorem sumAssoc_symm_apply_inr_inr {α β γ} (c) : (sumAssoc α β γ).symm (inr (inr c)) = inr c :=
rfl
/-- Four-way commutativity of `sum`. The name matches `add_add_add_comm`. -/
@[simps apply]
def sumSumSumComm (α β γ δ) : (α ⊕ β) ⊕ γ ⊕ δ ≃ (α ⊕ γ) ⊕ β ⊕ δ where
toFun :=
(sumAssoc (α ⊕ γ) β δ) ∘ (Sum.map (sumAssoc α γ β).symm (@id δ))
∘ (Sum.map (Sum.map (@id α) (sumComm β γ)) (@id δ))
∘ (Sum.map (sumAssoc α β γ) (@id δ))
∘ (sumAssoc (α ⊕ β) γ δ).symm
invFun :=
(sumAssoc (α ⊕ β) γ δ) ∘ (Sum.map (sumAssoc α β γ).symm (@id δ))
∘ (Sum.map (Sum.map (@id α) (sumComm β γ).symm) (@id δ))
∘ (Sum.map (sumAssoc α γ β) (@id δ))
∘ (sumAssoc (α ⊕ γ) β δ).symm
left_inv x := by rcases x with ((a | b) | (c | d)) <;> simp
right_inv x := by rcases x with ((a | c) | (b | d)) <;> simp
@[simp]
theorem sumSumSumComm_symm (α β γ δ) : (sumSumSumComm α β γ δ).symm = sumSumSumComm α γ β δ :=
rfl
/-- Sum with `IsEmpty` is equivalent to the original type. -/
@[simps symm_apply]
def sumEmpty (α β) [IsEmpty β] : α ⊕ β ≃ α where
toFun := Sum.elim id isEmptyElim
invFun := inl
left_inv s := by
rcases s with (_ | x)
· rfl
· exact isEmptyElim x
@[simp]
theorem sumEmpty_apply_inl {α β} [IsEmpty β] (a : α) : sumEmpty α β (Sum.inl a) = a :=
rfl
/-- The sum of `IsEmpty` with any type is equivalent to that type. -/
@[simps! symm_apply]
def emptySum (α β) [IsEmpty α] : α ⊕ β ≃ β :=
(sumComm _ _).trans <| sumEmpty _ _
@[simp]
theorem emptySum_apply_inr {α β} [IsEmpty α] (b : β) : emptySum α β (Sum.inr b) = b :=
rfl
/-- `α ⊕ β` is equivalent to a `Sigma`-type over `Bool`. Note that this definition assumes `α` and
`β` to be types from the same universe, so it cannot be used directly to transfer theorems about
sigma types to theorems about sum types. In many cases one can use `ULift` to work around this
difficulty. -/
def sumEquivSigmaBool (α β) : α ⊕ β ≃ Σ b, bif b then β else α :=
⟨fun s => s.elim (fun x => ⟨false, x⟩) fun x => ⟨true, x⟩, fun s =>
match s with
| ⟨false, a⟩ => inl a
| ⟨true, b⟩ => inr b,
fun s => by cases s <;> rfl, fun s => by rcases s with ⟨_ | _, _⟩ <;> rfl⟩
-- See also `Equiv.sigmaPreimageEquiv`.
/-- `sigmaFiberEquiv f` for `f : α → β` is the natural equivalence between
the type of all fibres of `f` and the total space `α`. -/
@[simps]
def sigmaFiberEquiv {α β : Type*} (f : α → β) : (Σ y : β, { x // f x = y }) ≃ α :=
⟨fun x => ↑x.2, fun x => ⟨f x, x, rfl⟩, fun ⟨_, _, rfl⟩ => rfl, fun _ => rfl⟩
/-- Inhabited types are equivalent to `Option β` for some `β` by identifying `default` with `none`.
-/
def sigmaEquivOptionOfInhabited (α : Type u) [Inhabited α] [DecidableEq α] :
Σ β : Type u, α ≃ Option β where
fst := {a // a ≠ default}
snd.toFun a := if h : a = default then none else some ⟨a, h⟩
snd.invFun := Option.elim' default (↑)
snd.left_inv a := by dsimp only; split_ifs <;> simp [*]
snd.right_inv
| none => by simp
| some ⟨_, ha⟩ => dif_neg ha
end
section sumCompl
/-- For any predicate `p` on `α`,
the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}`
is naturally equivalent to `α`.
See `subtypeOrEquiv` for sum types over subtypes `{x // p x}` and `{x // q x}`
that are not necessarily `IsCompl p q`. See also `Equiv.Set.sumCompl` for a version on sets. -/
def sumCompl {α : Type*} (p : α → Prop) [DecidablePred p] :
{ a // p a } ⊕ { a // ¬p a } ≃ α where
toFun := Sum.elim Subtype.val Subtype.val
invFun a := if h : p a then Sum.inl ⟨a, h⟩ else Sum.inr ⟨a, h⟩
left_inv := by
rintro (⟨x, hx⟩ | ⟨x, hx⟩) <;> dsimp
· rw [dif_pos]
· rw [dif_neg]
right_inv a := by
dsimp
split_ifs <;> rfl
@[simp]
theorem sumCompl_apply_inl {α} {p : α → Prop} [DecidablePred p] (x : { a // p a }) :
sumCompl p (Sum.inl x) = x :=
rfl
@[simp]
theorem sumCompl_apply_inr {α} {p : α → Prop} [DecidablePred p] (x : { a // ¬p a }) :
sumCompl p (Sum.inr x) = x :=
rfl
@[simp]
theorem sumCompl_symm_apply_of_pos {α} {p : α → Prop} [DecidablePred p] {a : α} (h : p a) :
(sumCompl p).symm a = Sum.inl ⟨a, h⟩ :=
dif_pos h
@[simp]
theorem sumCompl_symm_apply_of_neg {α} {p : α → Prop} [DecidablePred p] {a : α} (h : ¬p a) :
(sumCompl p).symm a = Sum.inr ⟨a, h⟩ :=
dif_neg h
@[deprecated (since := "2025-10-28")]
alias sumCompl_apply_symm_of_pos := sumCompl_symm_apply_of_pos
@[deprecated (since := "2025-10-28")]
alias sumCompl_apply_symm_of_neg := sumCompl_symm_apply_of_neg
@[simp]
theorem sumCompl_symm_apply_pos {α} {p : α → Prop} [DecidablePred p] (x : {x // p x}) :
(sumCompl p).symm x = Sum.inl x :=
sumCompl_symm_apply_of_pos x.2
@[simp]
theorem sumCompl_symm_apply_neg {α} {p : α → Prop} [DecidablePred p] (x : {x // ¬ p x}) :
(sumCompl p).symm x = Sum.inr x :=
sumCompl_symm_apply_of_neg x.2
end sumCompl
section
open Sum
/-- Type product is left distributive with respect to type sum up to an equivalence. -/
def prodSumDistrib (α β γ) : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ) :=
calc
α × (β ⊕ γ) ≃ (β ⊕ γ) × α := prodComm _ _
_ ≃ (β × α) ⊕ (γ × α) := sumProdDistrib _ _ _
_ ≃ (α × β) ⊕ (α × γ) := sumCongr (prodComm _ _) (prodComm _ _)
@[simp]
theorem prodSumDistrib_apply_left {α β γ} (a : α) (b : β) :
prodSumDistrib α β γ (a, Sum.inl b) = Sum.inl (a, b) :=
rfl
@[simp]
theorem prodSumDistrib_apply_right {α β γ} (a : α) (c : γ) :
prodSumDistrib α β γ (a, Sum.inr c) = Sum.inr (a, c) :=
rfl
@[simp]
theorem prodSumDistrib_symm_apply_left {α β γ} (a : α × β) :
(prodSumDistrib α β γ).symm (inl a) = (a.1, inl a.2) :=
rfl
@[simp]
theorem prodSumDistrib_symm_apply_right {α β γ} (a : α × γ) :
(prodSumDistrib α β γ).symm (inr a) = (a.1, inr a.2) :=
rfl
/-- An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. Compare
with `Equiv.sumSigmaDistrib` which is indexed by sums. -/
@[simps]
def sigmaSumDistrib {ι} (α β : ι → Type*) :
(Σ i, α i ⊕ β i) ≃ (Σ i, α i) ⊕ (Σ i, β i) :=
⟨fun p => p.2.map (Sigma.mk p.1) (Sigma.mk p.1),
Sum.elim (Sigma.map id fun _ => Sum.inl) (Sigma.map id fun _ => Sum.inr), fun p => by
rcases p with ⟨i, a | b⟩ <;> rfl, fun p => by rcases p with (⟨i, a⟩ | ⟨i, b⟩) <;> rfl⟩
/-- A type indexed by disjoint sums of types is equivalent to the sum of the sums. Compare with
`Equiv.sigmaSumDistrib` which has the sums as the output type. -/
@[simps]
def sumSigmaDistrib {α β} (t : α ⊕ β → Type*) :
(Σ i, t i) ≃ (Σ i, t (.inl i)) ⊕ (Σ i, t (.inr i)) :=
⟨(match · with
| .mk (.inl x) y => .inl ⟨x, y⟩
| .mk (.inr x) y => .inr ⟨x, y⟩),
Sum.elim (fun a ↦ ⟨.inl a.1, a.2⟩) (fun b ↦ ⟨.inr b.1, b.2⟩),
by rintro ⟨x|x,y⟩ <;> simp,
by rintro (⟨x,y⟩|⟨x,y⟩) <;> simp⟩
end
end Equiv |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Fintype.lean | import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.Fintype.Inv
/-! # Equivalence between fintypes
This file contains some basic results on equivalences where one or both
sides of the equivalence are `Fintype`s.
## Main definitions
- `Function.Embedding.toEquivRange`: computably turn an embedding of a
fintype into an `Equiv` of the domain to its range
- `Equiv.Perm.viaFintypeEmbedding : Perm α → (α ↪ β) → Perm β` extends the domain of
a permutation, fixing everything outside the range of the embedding
## Implementation details
- `Function.Embedding.toEquivRange` uses a computable inverse, but one that has poor
computational performance, since it operates by exhaustive search over the input `Fintype`s.
-/
assert_not_exists Equiv.Perm.sign
section Fintype
variable {α β : Type*} [Fintype α] [DecidableEq β] (e : Equiv.Perm α) (f : α ↪ β)
/-- Computably turn an embedding `f : α ↪ β` into an equiv `α ≃ Set.range f`,
if `α` is a `Fintype`. Has poor computational performance, due to exhaustive searching in
constructed inverse. When a better inverse is known, use `Equiv.ofLeftInverse'` or
`Equiv.ofLeftInverse` instead. This is the computable version of `Equiv.ofInjective`.
-/
def Function.Embedding.toEquivRange : α ≃ Set.range f where
toFun := fun a => ⟨f a, Set.mem_range_self a⟩
invFun := f.invOfMemRange
left_inv := fun _ => by simp
right_inv := fun _ => by simp
@[simp]
theorem Function.Embedding.toEquivRange_apply (a : α) :
f.toEquivRange a = ⟨f a, Set.mem_range_self a⟩ :=
rfl
@[simp]
theorem Function.Embedding.toEquivRange_symm_apply_self (a : α) :
f.toEquivRange.symm ⟨f a, Set.mem_range_self a⟩ = a := by simp [Equiv.symm_apply_eq]
theorem Function.Embedding.toEquivRange_eq_ofInjective :
f.toEquivRange = Equiv.ofInjective f f.injective := by
ext
simp
/-- Extend the domain of `e : Equiv.Perm α`, mapping it through `f : α ↪ β`.
Everything outside of `Set.range f` is kept fixed. Has poor computational performance,
due to exhaustive searching in constructed inverse due to using `Function.Embedding.toEquivRange`.
When a better `α ≃ Set.range f` is known, use `Equiv.Perm.viaSetRange`.
When `[Fintype α]` is not available, a noncomputable version is available as
`Equiv.Perm.viaEmbedding`.
-/
def Equiv.Perm.viaFintypeEmbedding : Equiv.Perm β :=
e.extendDomain f.toEquivRange
@[simp]
theorem Equiv.Perm.viaFintypeEmbedding_apply_image (a : α) :
e.viaFintypeEmbedding f (f a) = f (e a) := by
rw [Equiv.Perm.viaFintypeEmbedding]
convert Equiv.Perm.extendDomain_apply_image e (Function.Embedding.toEquivRange f) a
theorem Equiv.Perm.viaFintypeEmbedding_apply_mem_range {b : β} (h : b ∈ Set.range f) :
e.viaFintypeEmbedding f b = f (e (f.invOfMemRange ⟨b, h⟩)) := by
simp only [viaFintypeEmbedding, Function.Embedding.invOfMemRange]
rw [Equiv.Perm.extendDomain_apply_subtype _ _ h]
congr
theorem Equiv.Perm.viaFintypeEmbedding_apply_notMem_range {b : β} (h : b ∉ Set.range f) :
e.viaFintypeEmbedding f b = b := by
rwa [Equiv.Perm.viaFintypeEmbedding, Equiv.Perm.extendDomain_apply_not_subtype]
@[deprecated (since := "2025-05-23")]
alias Equiv.Perm.viaFintypeEmbedding_apply_not_mem_range :=
Equiv.Perm.viaFintypeEmbedding_apply_notMem_range
end Fintype
namespace Equiv
variable {α β : Type*} [Finite α]
/-- If `e` is an equivalence between two subtypes of a finite type `α`, `e.toCompl`
is an equivalence between the complement of those subtypes.
See also `Equiv.compl`, for a computable version when a term of type
`{e' : α ≃ α // ∀ x : {x // p x}, e' x = e x}` is known. -/
noncomputable def toCompl {p q : α → Prop} (e : { x // p x } ≃ { x // q x }) :
{ x // ¬p x } ≃ { x // ¬q x } := by
apply Classical.choice
cases nonempty_fintype α
classical
exact Fintype.card_eq.mp <| Fintype.card_compl_eq_card_compl _ _ <| Fintype.card_congr e
variable {p q : α → Prop} [DecidablePred p] [DecidablePred q]
/-- If `e` is an equivalence between two subtypes of a fintype `α`, `e.extendSubtype`
is a permutation of `α` acting like `e` on the subtypes and doing something arbitrary outside.
Note that when `p = q`, `Equiv.Perm.subtypeCongr e (Equiv.refl _)` can be used instead. -/
noncomputable abbrev extendSubtype (e : { x // p x } ≃ { x // q x }) : Perm α :=
subtypeCongr e e.toCompl
theorem extendSubtype_apply_of_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) :
e.extendSubtype x = e ⟨x, hx⟩ := by
dsimp only [extendSubtype]
simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply]
rw [sumCompl_symm_apply_of_pos hx, Sum.map_inl, sumCompl_apply_inl]
theorem extendSubtype_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : p x) :
q (e.extendSubtype x) := by
convert (e ⟨x, hx⟩).2
rw [e.extendSubtype_apply_of_mem _ hx]
theorem extendSubtype_apply_of_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) :
e.extendSubtype x = e.toCompl ⟨x, hx⟩ := by
dsimp only [extendSubtype]
simp only [subtypeCongr, Equiv.trans_apply, Equiv.sumCongr_apply]
rw [sumCompl_symm_apply_of_neg hx, Sum.map_inr, sumCompl_apply_inr]
theorem extendSubtype_not_mem (e : { x // p x } ≃ { x // q x }) (x) (hx : ¬p x) :
¬q (e.extendSubtype x) := by
convert (e.toCompl ⟨x, hx⟩).2
rw [e.extendSubtype_apply_of_not_mem _ hx]
end Equiv |
.lake/packages/mathlib/Mathlib/Logic/Equiv/PartialEquiv.lean | import Mathlib.Data.Set.Piecewise
import Mathlib.Logic.Equiv.Defs
import Mathlib.Tactic.Core
import Mathlib.Tactic.Attr.Core
/-!
# Partial equivalences
This file defines equivalences between subsets of given types.
An element `e` of `PartialEquiv α β` is made of two maps `e.toFun` and `e.invFun` respectively
from α to β and from β to α (just like equivs), which are inverse to each other on the subsets
`e.source` and `e.target` of respectively α and β.
They are designed in particular to define charts on manifolds.
The main functionality is `e.trans f`, which composes the two partial equivalences by restricting
the source and target to the maximal set where the composition makes sense.
As for equivs, we register a coercion to functions and use it in our simp normal form: we write
`e x` and `e.symm y` instead of `e.toFun x` and `e.invFun y`.
## Main definitions
* `Equiv.toPartialEquiv`: associating a partial equiv to an equiv, with source = target = univ
* `PartialEquiv.symm`: the inverse of a partial equivalence
* `PartialEquiv.trans`: the composition of two partial equivalences
* `PartialEquiv.refl`: the identity partial equivalence
* `PartialEquiv.ofSet`: the identity on a set `s`
* `EqOnSource`: equivalence relation describing the "right" notion of equality for partial
equivalences (see below in implementation notes)
## Implementation notes
There are at least three possible implementations of partial equivalences:
* equivs on subtypes
* pairs of functions taking values in `Option α` and `Option β`, equal to none where the partial
equivalence is not defined
* pairs of functions defined everywhere, keeping the source and target as additional data
Each of these implementations has pros and cons.
* When dealing with subtypes, one still need to define additional API for composition and
restriction of domains. Checking that one always belongs to the right subtype makes things very
tedious, and leads quickly to DTT hell (as the subtype `u ∩ v` is not the "same" as `v ∩ u`, for
instance).
* With option-valued functions, the composition is very neat (it is just the usual composition, and
the domain is restricted automatically). These are implemented in `PEquiv.lean`. For manifolds,
where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of
overhead as one would need to extend all classes of smoothness to option-valued maps.
* The `PartialEquiv` version as explained above is easier to use for manifolds. The drawback is that
there is extra useless data (the values of `toFun` and `invFun` outside of `source` and `target`).
In particular, the equality notion between partial equivs is not "the right one", i.e., coinciding
source and target and equality there. Moreover, there are no partial equivs in this sense between
an empty type and a nonempty type. Since empty types are not that useful, and since one almost
never needs to talk about equal partial equivs, this is not an issue in practice.
Still, we introduce an equivalence relation `EqOnSource` that captures this right notion of
equality, and show that many properties are invariant under this equivalence relation.
### Local coding conventions
If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`,
then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`.
-/
open Lean Meta Elab Tactic
/-! Implementation of the `mfld_set_tac` tactic for working with the domains of partially-defined
functions (`PartialEquiv`, `OpenPartialHomeomorph`, etc).
This is in a separate file from `Mathlib/Logic/Equiv/MfldSimpsAttr.lean` because attributes need a
new file to become functional.
-/
/-- Common `@[simps]` configuration options used for manifold-related declarations. -/
@[deprecated "Use `@[simps (attr := mfld_simps) -fullyApplied]` instead" (since := "2025-09-23")]
def mfld_cfg : Simps.Config where
fullyApplied := false
namespace Tactic.MfldSetTac
/-- A very basic tactic to show that sets showing up in manifolds coincide or are included
in one another. -/
elab (name := mfldSetTac) "mfld_set_tac" : tactic => withMainContext do
let g ← getMainGoal
let goalTy := (← instantiateMVars (← g.getDecl).type).getAppFnArgs
match goalTy with
| (``Eq, #[_ty, _e₁, _e₂]) =>
evalTactic (← `(tactic| (
apply Set.ext; intro my_y
constructor <;>
· intro h_my_y
try simp only [*, mfld_simps] at h_my_y
try simp only [*, mfld_simps])))
| (``Subset, #[_ty, _inst, _e₁, _e₂]) =>
evalTactic (← `(tactic| (
intro my_y h_my_y
try simp only [*, mfld_simps] at h_my_y
try simp only [*, mfld_simps])))
| _ => throwError "goal should be an equality or an inclusion"
attribute [mfld_simps] and_true eq_self_iff_true Function.comp_apply
end Tactic.MfldSetTac
open Function Set
variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- Local equivalence between subsets `source` and `target` of `α` and `β` respectively. The
(global) maps `toFun : α → β` and `invFun : β → α` map `source` to `target` and conversely, and are
inverse to each other there. The values of `toFun` outside of `source` and of `invFun` outside of
`target` are irrelevant. -/
structure PartialEquiv (α : Type*) (β : Type*) where
/-- The global function which has a partial inverse. Its value outside of the `source` subset is
irrelevant. -/
toFun : α → β
/-- The partial inverse to `toFun`. Its value outside of the `target` subset is irrelevant. -/
invFun : β → α
/-- The domain of the partial equivalence. -/
source : Set α
/-- The codomain of the partial equivalence. -/
target : Set β
/-- The proposition that elements of `source` are mapped to elements of `target`. -/
map_source' : ∀ ⦃x⦄, x ∈ source → toFun x ∈ target
/-- The proposition that elements of `target` are mapped to elements of `source`. -/
map_target' : ∀ ⦃x⦄, x ∈ target → invFun x ∈ source
/-- The proposition that `invFun` is a left-inverse of `toFun` on `source`. -/
left_inv' : ∀ ⦃x⦄, x ∈ source → invFun (toFun x) = x
/-- The proposition that `invFun` is a right-inverse of `toFun` on `target`. -/
right_inv' : ∀ ⦃x⦄, x ∈ target → toFun (invFun x) = x
attribute [coe] PartialEquiv.toFun
namespace PartialEquiv
variable (e : PartialEquiv α β) (e' : PartialEquiv β γ)
instance [Inhabited α] [Inhabited β] : Inhabited (PartialEquiv α β) :=
⟨⟨const α default, const β default, ∅, ∅, mapsTo_empty _ _, mapsTo_empty _ _, eqOn_empty _ _,
eqOn_empty _ _⟩⟩
/-- The inverse of a partial equivalence -/
@[symm]
protected def symm : PartialEquiv β α where
toFun := e.invFun
invFun := e.toFun
source := e.target
target := e.source
map_source' := e.map_target'
map_target' := e.map_source'
left_inv' := e.right_inv'
right_inv' := e.left_inv'
instance : CoeFun (PartialEquiv α β) fun _ => α → β :=
⟨PartialEquiv.toFun⟩
/-- See Note [custom simps projection] -/
def Simps.symm_apply (e : PartialEquiv α β) : β → α :=
e.symm
initialize_simps_projections PartialEquiv (toFun → apply, invFun → symm_apply)
theorem coe_mk (f : α → β) (g s t ml mr il ir) :
(PartialEquiv.mk f g s t ml mr il ir : α → β) = f := rfl
@[simp, mfld_simps]
theorem coe_symm_mk (f : α → β) (g s t ml mr il ir) :
((PartialEquiv.mk f g s t ml mr il ir).symm : β → α) = g :=
rfl
@[simp, mfld_simps]
theorem invFun_as_coe : e.invFun = e.symm :=
rfl
@[simp, mfld_simps]
theorem map_source {x : α} (h : x ∈ e.source) : e x ∈ e.target :=
e.map_source' h
/-- Variant of `e.map_source` and `map_source'`, stated for images of subsets of `source`. -/
lemma map_source'' : e '' e.source ⊆ e.target :=
fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx)
@[simp, mfld_simps]
theorem map_target {x : β} (h : x ∈ e.target) : e.symm x ∈ e.source :=
e.map_target' h
@[simp, mfld_simps]
theorem left_inv {x : α} (h : x ∈ e.source) : e.symm (e x) = x :=
e.left_inv' h
@[simp, mfld_simps]
theorem right_inv {x : β} (h : x ∈ e.target) : e (e.symm x) = x :=
e.right_inv' h
theorem target_subset_range : e.target ⊆ range e :=
fun x hx ↦ ⟨e.symm x, right_inv e hx⟩
theorem eq_symm_apply {x : α} {y : β} (hx : x ∈ e.source) (hy : y ∈ e.target) :
x = e.symm y ↔ e x = y :=
⟨fun h => by rw [← e.right_inv hy, h], fun h => by rw [← e.left_inv hx, h]⟩
protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source
theorem symm_mapsTo : MapsTo e.symm e.target e.source :=
e.symm.mapsTo
protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv
protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv
protected theorem invOn : InvOn e.symm e e.source e.target :=
⟨e.leftInvOn, e.rightInvOn⟩
protected theorem injOn : InjOn e e.source :=
e.leftInvOn.injOn
protected theorem bijOn : BijOn e e.source e.target :=
e.invOn.bijOn e.mapsTo e.symm_mapsTo
protected theorem surjOn : SurjOn e e.source e.target :=
e.bijOn.surjOn
/-- Interpret an `Equiv` as a `PartialEquiv` by restricting it to `s` in the domain
and to `t` in the codomain. -/
@[simps -fullyApplied]
def _root_.Equiv.toPartialEquivOfImageEq (e : α ≃ β) (s : Set α) (t : Set β) (h : e '' s = t) :
PartialEquiv α β where
toFun := e
invFun := e.symm
source := s
target := t
map_source' _ hx := h ▸ mem_image_of_mem _ hx
map_target' x hx := by
subst t
rcases hx with ⟨x, hx, rfl⟩
rwa [e.symm_apply_apply]
left_inv' x _ := e.symm_apply_apply x
right_inv' x _ := e.apply_symm_apply x
/-- Associate a `PartialEquiv` to an `Equiv`. -/
@[simps! (attr := mfld_simps) -fullyApplied]
def _root_.Equiv.toPartialEquiv (e : α ≃ β) : PartialEquiv α β :=
e.toPartialEquivOfImageEq univ univ <| by rw [image_univ, e.surjective.range_eq]
instance inhabitedOfEmpty [IsEmpty α] [IsEmpty β] : Inhabited (PartialEquiv α β) :=
⟨((Equiv.equivEmpty α).trans (Equiv.equivEmpty β).symm).toPartialEquiv⟩
/-- Create a copy of a `PartialEquiv` providing better definitional equalities. -/
@[simps -fullyApplied]
def copy (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α)
(hs : e.source = s) (t : Set β) (ht : e.target = t) :
PartialEquiv α β where
toFun := f
invFun := g
source := s
target := t
map_source' _ := ht ▸ hs ▸ hf ▸ e.map_source
map_target' _ := hs ▸ ht ▸ hg ▸ e.map_target
left_inv' _ := hs ▸ hf ▸ hg ▸ e.left_inv
right_inv' _ := ht ▸ hf ▸ hg ▸ e.right_inv
theorem copy_eq (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g)
(s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) :
e.copy f hf g hg s hs t ht = e := by
substs f g s t
cases e
rfl
/-- Associate to a `PartialEquiv` an `Equiv` between the source and the target. -/
protected def toEquiv : e.source ≃ e.target where
toFun x := ⟨e x, e.map_source x.mem⟩
invFun y := ⟨e.symm y, e.map_target y.mem⟩
left_inv := fun ⟨_, hx⟩ => Subtype.eq <| e.left_inv hx
right_inv := fun ⟨_, hy⟩ => Subtype.eq <| e.right_inv hy
@[simp, mfld_simps]
theorem symm_source : e.symm.source = e.target :=
rfl
@[simp, mfld_simps]
theorem symm_target : e.symm.target = e.source :=
rfl
@[simp, mfld_simps]
theorem symm_symm : e.symm.symm = e := rfl
theorem symm_bijective :
Function.Bijective (PartialEquiv.symm : PartialEquiv α β → PartialEquiv β α) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
theorem image_source_eq_target : e '' e.source = e.target :=
e.bijOn.image_eq
theorem forall_mem_target {p : β → Prop} : (∀ y ∈ e.target, p y) ↔ ∀ x ∈ e.source, p (e x) := by
rw [← image_source_eq_target, forall_mem_image]
theorem exists_mem_target {p : β → Prop} : (∃ y ∈ e.target, p y) ↔ ∃ x ∈ e.source, p (e x) := by
rw [← image_source_eq_target, exists_mem_image]
/-- We say that `t : Set β` is an image of `s : Set α` under a partial equivalence if
any of the following equivalent conditions hold:
* `e '' (e.source ∩ s) = e.target ∩ t`;
* `e.source ∩ e ⁻¹ t = e.source ∩ s`;
* `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition).
-/
def IsImage (s : Set α) (t : Set β) : Prop :=
∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s)
namespace IsImage
variable {e} {s : Set α} {t : Set β} {x : α}
theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s :=
h hx
theorem symm_apply_mem_iff (h : e.IsImage s t) : ∀ ⦃y⦄, y ∈ e.target → (e.symm y ∈ s ↔ y ∈ t) :=
e.forall_mem_target.mpr fun x hx => by rw [e.left_inv hx, h hx]
protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s :=
h.symm_apply_mem_iff
@[simp]
theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t :=
⟨fun h => h.symm, fun h => h.symm⟩
protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) :=
fun _ hx => ⟨e.mapsTo hx.1, (h hx.1).2 hx.2⟩
theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) :=
h.symm.mapsTo
/-- Restrict a `PartialEquiv` to a pair of corresponding sets. -/
@[simps -fullyApplied]
def restr (h : e.IsImage s t) : PartialEquiv α β where
toFun := e
invFun := e.symm
source := e.source ∩ s
target := e.target ∩ t
map_source' := h.mapsTo
map_target' := h.symm_mapsTo
left_inv' := e.leftInvOn.mono inter_subset_left
right_inv' := e.rightInvOn.mono inter_subset_left
theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t :=
h.restr.image_source_eq_target
theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s :=
h.symm.image_eq
theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s := by
simp only [IsImage, Set.ext_iff, mem_inter_iff, mem_preimage, and_congr_right_iff]
alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq
theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t :=
symm_iff.symm.trans iff_preimage_eq
alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq
theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t :=
of_symm_preimage_eq <| Eq.trans (of_symm_preimage_eq rfl).image_eq.symm h
theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t :=
of_preimage_eq <| Eq.trans (iff_preimage_eq.2 rfl).symm_image_eq.symm h
protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => not_congr (h hx)
protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => and_congr (h hx) (h' hx)
protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => or_congr (h hx) (h' hx)
protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s \ s') (t \ t') :=
h.inter h'.compl
theorem leftInvOn_piecewise {e' : PartialEquiv α β} [∀ i, Decidable (i ∈ s)]
[∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) :
LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) := by
rintro x (⟨he, hs⟩ | ⟨he, hs : x ∉ s⟩)
· rw [piecewise_eq_of_mem _ _ _ hs, piecewise_eq_of_mem _ _ _ ((h he).2 hs), e.left_inv he]
· rw [piecewise_eq_of_notMem _ _ _ hs, piecewise_eq_of_notMem _ _ _ ((h'.compl he).2 hs),
e'.left_inv he]
theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t)
(h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) :
e.target ∩ t = e'.target ∩ t := by rw [← h.image_eq, ← h'.image_eq, ← hs, heq.image_eq]
theorem symm_eq_on_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t)
(hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) :
EqOn e.symm e'.symm (e.target ∩ t) := by
rw [← h.image_eq]
rintro y ⟨x, hx, rfl⟩
have hx' := hx; rw [hs] at hx'
rw [e.left_inv hx.1, heq hx, e'.left_inv hx'.1]
end IsImage
theorem isImage_source_target : e.IsImage e.source e.target := fun x hx => by simp [hx]
theorem isImage_source_target_of_disjoint (e' : PartialEquiv α β) (hs : Disjoint e.source e'.source)
(ht : Disjoint e.target e'.target) : e.IsImage e'.source e'.target :=
IsImage.of_image_eq <| by rw [hs.inter_eq, ht.inter_eq, image_empty]
theorem image_source_inter_eq' (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := by
rw [inter_comm, e.leftInvOn.image_inter', image_source_eq_target, inter_comm]
theorem image_source_inter_eq (s : Set α) :
e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := by
rw [inter_comm, e.leftInvOn.image_inter, image_source_eq_target, inter_comm]
theorem image_eq_target_inter_inv_preimage {s : Set α} (h : s ⊆ e.source) :
e '' s = e.target ∩ e.symm ⁻¹' s := by
rw [← e.image_source_inter_eq', inter_eq_self_of_subset_right h]
theorem symm_image_eq_source_inter_preimage {s : Set β} (h : s ⊆ e.target) :
e.symm '' s = e.source ∩ e ⁻¹' s :=
e.symm.image_eq_target_inter_inv_preimage h
theorem symm_image_target_inter_eq (s : Set β) :
e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) :=
e.symm.image_source_inter_eq _
theorem symm_image_target_inter_eq' (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' s :=
e.symm.image_source_inter_eq' _
theorem source_inter_preimage_inv_preimage (s : Set α) :
e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s :=
Set.ext fun x => and_congr_right_iff.2 fun hx =>
by simp only [mem_preimage, e.left_inv hx]
theorem source_inter_preimage_target_inter (s : Set β) :
e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s :=
ext fun _ => ⟨fun hx => ⟨hx.1, hx.2.2⟩, fun hx => ⟨hx.1, e.map_source hx.1, hx.2⟩⟩
theorem target_inter_inv_preimage_preimage (s : Set β) :
e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s :=
e.symm.source_inter_preimage_inv_preimage _
theorem symm_image_image_of_subset_source {s : Set α} (h : s ⊆ e.source) : e.symm '' (e '' s) = s :=
(e.leftInvOn.mono h).image_image
theorem image_symm_image_of_subset_target {s : Set β} (h : s ⊆ e.target) : e '' (e.symm '' s) = s :=
e.symm.symm_image_image_of_subset_source h
theorem source_subset_preimage_target : e.source ⊆ e ⁻¹' e.target :=
e.mapsTo
theorem symm_image_target_eq_source : e.symm '' e.target = e.source :=
e.symm.image_source_eq_target
theorem target_subset_preimage_source : e.target ⊆ e.symm ⁻¹' e.source :=
e.symm_mapsTo
/-- Two partial equivs that have the same `source`, same `toFun` and same `invFun`, coincide. -/
@[ext]
protected theorem ext {e e' : PartialEquiv α β} (h : ∀ x, e x = e' x)
(hsymm : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := by
have A : (e : α → β) = e' := by
ext x
exact h x
have B : (e.symm : β → α) = e'.symm := by
ext x
exact hsymm x
have I : e '' e.source = e.target := e.image_source_eq_target
have I' : e' '' e'.source = e'.target := e'.image_source_eq_target
rw [A, hs, I'] at I
cases e; cases e'
simp_all
/-- Restricting a partial equivalence to `e.source ∩ s` -/
protected def restr (s : Set α) : PartialEquiv α β :=
(@IsImage.of_symm_preimage_eq α β e s (e.symm ⁻¹' s) rfl).restr
@[simp, mfld_simps]
theorem restr_coe (s : Set α) : (e.restr s : α → β) = e :=
rfl
@[simp, mfld_simps]
theorem restr_coe_symm (s : Set α) : ((e.restr s).symm : β → α) = e.symm :=
rfl
@[simp, mfld_simps]
theorem restr_source (s : Set α) : (e.restr s).source = e.source ∩ s :=
rfl
theorem source_restr_subset_source (s : Set α) : (e.restr s).source ⊆ e.source := inter_subset_left
@[simp, mfld_simps]
theorem restr_target (s : Set α) : (e.restr s).target = e.target ∩ e.symm ⁻¹' s :=
rfl
theorem restr_eq_of_source_subset {e : PartialEquiv α β} {s : Set α} (h : e.source ⊆ s) :
e.restr s = e :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [inter_eq_self_of_subset_left h])
@[simp, mfld_simps]
theorem restr_univ {e : PartialEquiv α β} : e.restr univ = e :=
restr_eq_of_source_subset (subset_univ _)
/-- The identity partial equiv -/
protected def refl (α : Type*) : PartialEquiv α α :=
(Equiv.refl α).toPartialEquiv
@[simp, mfld_simps]
theorem refl_source : (PartialEquiv.refl α).source = univ :=
rfl
@[simp, mfld_simps]
theorem refl_target : (PartialEquiv.refl α).target = univ :=
rfl
@[simp, mfld_simps]
theorem refl_coe : (PartialEquiv.refl α : α → α) = id :=
rfl
@[simp, mfld_simps]
theorem refl_symm : (PartialEquiv.refl α).symm = PartialEquiv.refl α :=
rfl
@[mfld_simps]
theorem refl_restr_source (s : Set α) : ((PartialEquiv.refl α).restr s).source = s := by simp
@[mfld_simps]
theorem refl_restr_target (s : Set α) : ((PartialEquiv.refl α).restr s).target = s := by simp
/-- The identity partial equivalence on a set `s` -/
def ofSet (s : Set α) : PartialEquiv α α where
toFun := id
invFun := id
source := s
target := s
map_source' _ hx := hx
map_target' _ hx := hx
left_inv' _ _ := rfl
right_inv' _ _ := rfl
@[simp, mfld_simps]
theorem ofSet_source (s : Set α) : (PartialEquiv.ofSet s).source = s :=
rfl
@[simp, mfld_simps]
theorem ofSet_target (s : Set α) : (PartialEquiv.ofSet s).target = s :=
rfl
@[simp, mfld_simps]
theorem ofSet_coe (s : Set α) : (PartialEquiv.ofSet s : α → α) = id :=
rfl
@[simp, mfld_simps]
theorem ofSet_symm (s : Set α) : (PartialEquiv.ofSet s).symm = PartialEquiv.ofSet s :=
rfl
/-- `Function.const` as a `PartialEquiv`.
It consists of two constant maps in opposite directions. -/
@[simps]
def single (a : α) (b : β) : PartialEquiv α β where
toFun := Function.const α b
invFun := Function.const β a
source := {a}
target := {b}
map_source' _ _ := rfl
map_target' _ _ := rfl
left_inv' a' ha' := by rw [eq_of_mem_singleton ha', const_apply]
right_inv' b' hb' := by rw [eq_of_mem_singleton hb', const_apply]
/-- Composing two partial equivs if the target of the first coincides with the source of the
second. -/
@[simps]
protected def trans' (e' : PartialEquiv β γ) (h : e.target = e'.source) : PartialEquiv α γ where
toFun := e' ∘ e
invFun := e.symm ∘ e'.symm
source := e.source
target := e'.target
map_source' x hx := by simp [← h, hx]
map_target' y hy := by simp [h, hy]
left_inv' x hx := by simp [hx, ← h]
right_inv' y hy := by simp [hy, h]
/-- Composing two partial equivs, by restricting to the maximal domain where their composition
is well defined.
Within the `Manifold` namespace, there is the notation `e ≫ f` for this.
-/
@[trans]
protected def trans : PartialEquiv α γ :=
PartialEquiv.trans' (e.symm.restr e'.source).symm (e'.restr e.target) (inter_comm _ _)
@[simp, mfld_simps]
theorem coe_trans : (e.trans e' : α → γ) = e' ∘ e :=
rfl
@[simp, mfld_simps]
theorem coe_trans_symm : ((e.trans e').symm : γ → α) = e.symm ∘ e'.symm :=
rfl
theorem trans_apply {x : α} : (e.trans e') x = e' (e x) :=
rfl
theorem trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm := rfl
@[simp, mfld_simps]
theorem trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source :=
rfl
theorem trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) := by
mfld_set_tac
theorem trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) := by
rw [e.trans_source', e.symm_image_target_inter_eq]
theorem image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source :=
(e.symm.restr e'.source).symm.image_source_eq_target
@[simp, mfld_simps]
theorem trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target :=
rfl
theorem trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) :=
trans_source' e'.symm e.symm
theorem trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) :=
trans_source'' e'.symm e.symm
theorem inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target :=
image_trans_source e'.symm e.symm
theorem trans_assoc (e'' : PartialEquiv γ δ) : (e.trans e').trans e'' = e.trans (e'.trans e'') :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl)
(by simp [trans_source, @preimage_comp α β γ, inter_assoc])
@[simp, mfld_simps]
theorem trans_refl : e.trans (PartialEquiv.refl β) = e :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source])
@[simp, mfld_simps]
theorem refl_trans : (PartialEquiv.refl α).trans e = e :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source, preimage_id])
theorem trans_ofSet (s : Set β) : e.trans (ofSet s) = e.restr (e ⁻¹' s) :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) rfl
theorem trans_refl_restr (s : Set β) :
e.trans ((PartialEquiv.refl β).restr s) = e.restr (e ⁻¹' s) :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source])
theorem trans_refl_restr' (s : Set β) :
e.trans ((PartialEquiv.refl β).restr s) = e.restr (e.source ∩ e ⁻¹' s) :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) <| by
simp only [trans_source, restr_source, refl_source, univ_inter]
rw [← inter_assoc, inter_self]
theorem restr_trans (s : Set α) : (e.restr s).trans e' = (e.trans e').restr s :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) <| by
simp [trans_source, inter_comm, inter_assoc]
/-- A lemma commonly useful when `e` and `e'` are charts of a manifold. -/
theorem mem_symm_trans_source {e' : PartialEquiv α γ} {x : α} (he : x ∈ e.source)
(he' : x ∈ e'.source) : e x ∈ (e.symm.trans e').source :=
⟨e.mapsTo he, by rwa [mem_preimage, PartialEquiv.symm_symm, e.left_inv he]⟩
/-- `EqOnSource e e'` means that `e` and `e'` have the same source, and coincide there. Then `e`
and `e'` should really be considered the same partial equiv. -/
def EqOnSource (e e' : PartialEquiv α β) : Prop :=
e.source = e'.source ∧ e.source.EqOn e e'
/-- `EqOnSource` is an equivalence relation. This instance provides the `≈` notation between two
`PartialEquiv`s. -/
instance eqOnSourceSetoid : Setoid (PartialEquiv α β) where
r := EqOnSource
iseqv := by constructor <;> simp only [EqOnSource, EqOn] <;> aesop
theorem eqOnSource_refl : e ≈ e :=
Setoid.refl _
/-- Two equivalent partial equivs have the same source. -/
theorem EqOnSource.source_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.source = e'.source :=
h.1
/-- Two equivalent partial equivs coincide on the source. -/
theorem EqOnSource.eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : e.source.EqOn e e' :=
h.2
/-- Two equivalent partial equivs have the same target. -/
theorem EqOnSource.target_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.target = e'.target := by
simp only [← image_source_eq_target, ← source_eq h, h.2.image_eq]
/-- If two partial equivs are equivalent, so are their inverses. -/
theorem EqOnSource.symm' {e e' : PartialEquiv α β} (h : e ≈ e') : e.symm ≈ e'.symm := by
refine ⟨target_eq h, eqOn_of_leftInvOn_of_rightInvOn e.leftInvOn ?_ ?_⟩ <;>
simp only [symm_source, target_eq h, source_eq h, e'.symm_mapsTo]
exact e'.rightInvOn.congr_right e'.symm_mapsTo (source_eq h ▸ h.eqOn.symm)
/-- Two equivalent partial equivs have coinciding inverses on the target. -/
theorem EqOnSource.symm_eqOn {e e' : PartialEquiv α β} (h : e ≈ e') :
EqOn e.symm e'.symm e.target :=
eqOn h.symm'
/-- Composition of partial equivs respects equivalence. -/
theorem EqOnSource.trans' {e e' : PartialEquiv α β} {f f' : PartialEquiv β γ} (he : e ≈ e')
(hf : f ≈ f') : e.trans f ≈ e'.trans f' := by
constructor
· rw [trans_source'', trans_source'', ← target_eq he, ← hf.1]
exact (he.symm'.eqOn.mono inter_subset_left).image_eq
· intro x hx
rw [trans_source] at hx
simp [Function.comp_apply, PartialEquiv.coe_trans, (he.2 hx.1).symm, hf.2 hx.2]
/-- Restriction of partial equivs respects equivalence. -/
theorem EqOnSource.restr {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set α) :
e.restr s ≈ e'.restr s := by
constructor
· simp [he.1]
· intro x hx
simp only [mem_inter_iff, restr_source] at hx
exact he.2 hx.1
/-- Preimages are respected by equivalence. -/
theorem EqOnSource.source_inter_preimage_eq {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set β) :
e.source ∩ e ⁻¹' s = e'.source ∩ e' ⁻¹' s := by rw [he.eqOn.inter_preimage_eq, source_eq he]
/-- Composition of a partial equivalence and its inverse is equivalent to
the restriction of the identity to the source. -/
theorem self_trans_symm : e.trans e.symm ≈ ofSet e.source := by
have A : (e.trans e.symm).source = e.source := by mfld_set_tac
refine ⟨by rw [A, ofSet_source], fun x hx => ?_⟩
rw [A] at hx
simp only [hx, mfld_simps]
/-- Composition of the inverse of a partial equivalence and this partial equivalence is equivalent
to the restriction of the identity to the target. -/
theorem symm_trans_self : e.symm.trans e ≈ ofSet e.target :=
self_trans_symm e.symm
/-- Two equivalent partial equivs are equal when the source and target are `univ`. -/
theorem eq_of_eqOnSource_univ (e e' : PartialEquiv α β) (h : e ≈ e') (s : e.source = univ)
(t : e.target = univ) : e = e' := by
refine PartialEquiv.ext (fun x => ?_) (fun x => ?_) h.1
· apply h.2
rw [s]
exact mem_univ _
· apply h.symm'.2
rw [symm_source, t]
exact mem_univ _
section Prod
/-- The product of two partial equivalences, as a partial equivalence on the product. -/
def prod (e : PartialEquiv α β) (e' : PartialEquiv γ δ) : PartialEquiv (α × γ) (β × δ) where
source := e.source ×ˢ e'.source
target := e.target ×ˢ e'.target
toFun p := (e p.1, e' p.2)
invFun p := (e.symm p.1, e'.symm p.2)
map_source' p hp := by simp_all
map_target' p hp := by simp_all
left_inv' p hp := by simp_all
right_inv' p hp := by simp_all
@[simp, mfld_simps]
theorem prod_source (e : PartialEquiv α β) (e' : PartialEquiv γ δ) :
(e.prod e').source = e.source ×ˢ e'.source :=
rfl
@[simp, mfld_simps]
theorem prod_target (e : PartialEquiv α β) (e' : PartialEquiv γ δ) :
(e.prod e').target = e.target ×ˢ e'.target :=
rfl
@[simp, mfld_simps]
theorem prod_coe (e : PartialEquiv α β) (e' : PartialEquiv γ δ) :
(e.prod e' : α × γ → β × δ) = fun p => (e p.1, e' p.2) :=
rfl
theorem prod_coe_symm (e : PartialEquiv α β) (e' : PartialEquiv γ δ) :
((e.prod e').symm : β × δ → α × γ) = fun p => (e.symm p.1, e'.symm p.2) :=
rfl
@[simp, mfld_simps]
theorem prod_symm (e : PartialEquiv α β) (e' : PartialEquiv γ δ) :
(e.prod e').symm = e.symm.prod e'.symm := by
ext x <;> simp [prod_coe_symm]
@[simp, mfld_simps]
theorem refl_prod_refl :
(PartialEquiv.refl α).prod (PartialEquiv.refl β) = PartialEquiv.refl (α × β) := by
ext ⟨x, y⟩ <;> simp
@[simp, mfld_simps]
theorem prod_trans {η : Type*} {ε : Type*} (e : PartialEquiv α β) (f : PartialEquiv β γ)
(e' : PartialEquiv δ η) (f' : PartialEquiv η ε) :
(e.prod e').trans (f.prod f') = (e.trans f).prod (e'.trans f') := by
ext ⟨x, y⟩ <;> simp; tauto
end Prod
/-- Combine two `PartialEquiv`s using `Set.piecewise`. The source of the new `PartialEquiv` is
`s.ite e.source e'.source = e.source ∩ s ∪ e'.source \ s`, and similarly for target. The function
sends `e.source ∩ s` to `e.target ∩ t` using `e` and `e'.source \ s` to `e'.target \ t` using `e'`,
and similarly for the inverse function. The definition assumes `e.isImage s t` and
`e'.isImage s t`. -/
@[simps -fullyApplied]
def piecewise (e e' : PartialEquiv α β) (s : Set α) (t : Set β) [∀ x, Decidable (x ∈ s)]
[∀ y, Decidable (y ∈ t)] (H : e.IsImage s t) (H' : e'.IsImage s t) :
PartialEquiv α β where
toFun := s.piecewise e e'
invFun := t.piecewise e.symm e'.symm
source := s.ite e.source e'.source
target := t.ite e.target e'.target
map_source' := H.mapsTo.piecewise_ite H'.compl.mapsTo
map_target' := H.symm.mapsTo.piecewise_ite H'.symm.compl.mapsTo
left_inv' := H.leftInvOn_piecewise H'
right_inv' := H.symm.leftInvOn_piecewise H'.symm
theorem symm_piecewise (e e' : PartialEquiv α β) {s : Set α} {t : Set β} [∀ x, Decidable (x ∈ s)]
[∀ y, Decidable (y ∈ t)] (H : e.IsImage s t) (H' : e'.IsImage s t) :
(e.piecewise e' s t H H').symm = e.symm.piecewise e'.symm t s H.symm H'.symm :=
rfl
/-- Combine two `PartialEquiv`s with disjoint sources and disjoint targets. We reuse
`PartialEquiv.piecewise`, then override `source` and `target` to ensure better definitional
equalities. -/
@[simps! -fullyApplied]
def disjointUnion (e e' : PartialEquiv α β) (hs : Disjoint e.source e'.source)
(ht : Disjoint e.target e'.target) [∀ x, Decidable (x ∈ e.source)]
[∀ y, Decidable (y ∈ e.target)] : PartialEquiv α β :=
(e.piecewise e' e.source e.target e.isImage_source_target <|
e'.isImage_source_target_of_disjoint _ hs.symm ht.symm).copy
_ rfl _ rfl (e.source ∪ e'.source) (ite_left _ _) (e.target ∪ e'.target) (ite_left _ _)
theorem disjointUnion_eq_piecewise (e e' : PartialEquiv α β) (hs : Disjoint e.source e'.source)
(ht : Disjoint e.target e'.target) [∀ x, Decidable (x ∈ e.source)]
[∀ y, Decidable (y ∈ e.target)] :
e.disjointUnion e' hs ht =
e.piecewise e' e.source e.target e.isImage_source_target
(e'.isImage_source_target_of_disjoint _ hs.symm ht.symm) :=
copy_eq ..
section Pi
variable {ι : Type*} {αi βi γi : ι → Type*}
/-- The product of a family of partial equivalences, as a partial equivalence on the pi type. -/
@[simps (attr := mfld_simps) -fullyApplied apply source target]
protected def pi (ei : ∀ i, PartialEquiv (αi i) (βi i)) : PartialEquiv (∀ i, αi i) (∀ i, βi i) where
toFun := Pi.map fun i ↦ ei i
invFun := Pi.map fun i ↦ (ei i).symm
source := pi univ fun i => (ei i).source
target := pi univ fun i => (ei i).target
map_source' _ hf i hi := (ei i).map_source (hf i hi)
map_target' _ hf i hi := (ei i).map_target (hf i hi)
left_inv' _ hf := funext fun i => (ei i).left_inv (hf i trivial)
right_inv' _ hf := funext fun i => (ei i).right_inv (hf i trivial)
@[simp, mfld_simps]
theorem pi_symm (ei : ∀ i, PartialEquiv (αi i) (βi i)) :
(PartialEquiv.pi ei).symm = .pi fun i ↦ (ei i).symm :=
rfl
theorem pi_symm_apply (ei : ∀ i, PartialEquiv (αi i) (βi i)) :
⇑(PartialEquiv.pi ei).symm = fun f i ↦ (ei i).symm (f i) :=
rfl
@[simp, mfld_simps]
theorem pi_refl : (PartialEquiv.pi fun i ↦ PartialEquiv.refl (αi i)) = .refl (∀ i, αi i) := by
ext <;> simp
@[simp, mfld_simps]
theorem pi_trans (ei : ∀ i, PartialEquiv (αi i) (βi i)) (ei' : ∀ i, PartialEquiv (βi i) (γi i)) :
(PartialEquiv.pi ei).trans (PartialEquiv.pi ei') = .pi fun i ↦ (ei i).trans (ei' i) := by
ext <;> simp [forall_and]
end Pi
lemma surjective_of_target_eq_univ (h : e.target = univ) :
Surjective e :=
surjOn_univ.mp <| e.surjOn.mono (by simp) (by simp [h])
lemma injective_of_source_eq_univ (h : e.source = univ) : Injective e := by simpa [h] using e.injOn
lemma injective_symm_of_target_eq_univ (h : e.target = univ) :
Injective e.symm :=
e.symm.injective_of_source_eq_univ h
lemma surjective_symm_of_source_eq_univ (h : e.source = univ) :
Surjective e.symm :=
e.symm.surjective_of_target_eq_univ h
end PartialEquiv
namespace Set
-- All arguments are explicit to avoid missing information in the pretty printer output
/-- A bijection between two sets `s : Set α` and `t : Set β` provides a partial equivalence
between `α` and `β`. -/
@[simps -fullyApplied]
noncomputable def BijOn.toPartialEquiv [Nonempty α] (f : α → β) (s : Set α) (t : Set β)
(hf : BijOn f s t) : PartialEquiv α β where
toFun := f
invFun := invFunOn f s
source := s
target := t
map_source' := hf.mapsTo
map_target' := hf.surjOn.mapsTo_invFunOn
left_inv' := hf.invOn_invFunOn.1
right_inv' := hf.invOn_invFunOn.2
/-- A map injective on a subset of its domain provides a partial equivalence. -/
@[simp, mfld_simps]
noncomputable def InjOn.toPartialEquiv [Nonempty α] (f : α → β) (s : Set α) (hf : InjOn f s) :
PartialEquiv α β :=
hf.bijOn_image.toPartialEquiv f s (f '' s)
end Set
namespace Equiv
/- `Equiv`s give rise to `PartialEquiv`s. We set up simp lemmas to reduce most properties of the
`PartialEquiv` to that of the `Equiv`. -/
variable (e : α ≃ β) (e' : β ≃ γ)
@[simp, mfld_simps]
theorem refl_toPartialEquiv : (Equiv.refl α).toPartialEquiv = PartialEquiv.refl α :=
rfl
@[simp, mfld_simps]
theorem symm_toPartialEquiv : e.symm.toPartialEquiv = e.toPartialEquiv.symm :=
rfl
@[simp, mfld_simps]
theorem trans_toPartialEquiv :
(e.trans e').toPartialEquiv = e.toPartialEquiv.trans e'.toPartialEquiv :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl)
(by simp [PartialEquiv.trans_source, Equiv.toPartialEquiv])
/-- Precompose a partial equivalence with an equivalence.
We modify the source and target to have better definitional behavior. -/
@[simps!]
def transPartialEquiv (e : α ≃ β) (f' : PartialEquiv β γ) : PartialEquiv α γ :=
(e.toPartialEquiv.trans f').copy _ rfl _ rfl (e ⁻¹' f'.source) (univ_inter _) f'.target
(inter_univ _)
theorem transPartialEquiv_eq_trans (e : α ≃ β) (f' : PartialEquiv β γ) :
e.transPartialEquiv f' = e.toPartialEquiv.trans f' :=
PartialEquiv.copy_eq ..
@[simp, mfld_simps]
theorem transPartialEquiv_trans (e : α ≃ β) (f' : PartialEquiv β γ) (f'' : PartialEquiv γ δ) :
(e.transPartialEquiv f').trans f'' = e.transPartialEquiv (f'.trans f'') := by
simp only [transPartialEquiv_eq_trans, PartialEquiv.trans_assoc]
@[simp, mfld_simps]
theorem trans_transPartialEquiv (e : α ≃ β) (e' : β ≃ γ) (f'' : PartialEquiv γ δ) :
(e.trans e').transPartialEquiv f'' = e.transPartialEquiv (e'.transPartialEquiv f'') := by
simp only [transPartialEquiv_eq_trans, PartialEquiv.trans_assoc, trans_toPartialEquiv]
end Equiv
namespace PartialEquiv
/-- Postcompose a partial equivalence with an equivalence.
We modify the source and target to have better definitional behavior. -/
@[simps!]
def transEquiv (e : PartialEquiv α β) (f' : β ≃ γ) : PartialEquiv α γ :=
(e.trans f'.toPartialEquiv).copy _ rfl _ rfl e.source (inter_univ _) (f'.symm ⁻¹' e.target)
(univ_inter _)
theorem transEquiv_eq_trans (e : PartialEquiv α β) (e' : β ≃ γ) :
e.transEquiv e' = e.trans e'.toPartialEquiv :=
copy_eq ..
@[simp, mfld_simps]
theorem transEquiv_transEquiv (e : PartialEquiv α β) (f' : β ≃ γ) (f'' : γ ≃ δ) :
(e.transEquiv f').transEquiv f'' = e.transEquiv (f'.trans f'') := by
simp only [transEquiv_eq_trans, trans_assoc, Equiv.trans_toPartialEquiv]
@[simp, mfld_simps]
theorem trans_transEquiv (e : PartialEquiv α β) (e' : PartialEquiv β γ) (f'' : γ ≃ δ) :
(e.trans e').transEquiv f'' = e.trans (e'.transEquiv f'') := by
simp only [transEquiv_eq_trans, trans_assoc]
end PartialEquiv |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Option.lean | import Mathlib.Control.EquivFunctor
import Mathlib.Data.Option.Basic
import Mathlib.Data.Subtype
import Mathlib.Logic.Equiv.Defs
/-!
# Equivalences for `Option α`
We define
* `Equiv.optionCongr`: the `Option α ≃ Option β` constructed from `e : α ≃ β` by sending `none` to
`none`, and applying `e` elsewhere.
* `Equiv.removeNone`: the `α ≃ β` constructed from `Option α ≃ Option β` by removing `none` from
both sides.
-/
universe u
namespace Equiv
open Option
variable {α β γ : Type*}
section OptionCongr
/-- A universe-polymorphic version of `EquivFunctor.mapEquiv Option e`. -/
@[simps (attr := grind =) apply]
def optionCongr (e : α ≃ β) : Option α ≃ Option β where
toFun := Option.map e
invFun := Option.map e.symm
left_inv x := (Option.map_map _ _ _).trans <| e.symm_comp_self.symm ▸ congr_fun Option.map_id x
right_inv x := (Option.map_map _ _ _).trans <| e.self_comp_symm.symm ▸ congr_fun Option.map_id x
@[simp]
theorem optionCongr_refl : optionCongr (Equiv.refl α) = Equiv.refl _ :=
ext <| congr_fun Option.map_id
@[simp, grind =]
theorem optionCongr_symm (e : α ≃ β) : optionCongr e.symm = (optionCongr e).symm :=
rfl
@[simp]
theorem optionCongr_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) :
optionCongr (e₁.trans e₂) = (optionCongr e₁).trans (optionCongr e₂) := by
ext x : 1
symm
apply Option.map_map
/-- When `α` and `β` are in the same universe, this is the same as the result of
`EquivFunctor.mapEquiv`. -/
theorem optionCongr_eq_equivFunctor_mapEquiv {α β : Type u} (e : α ≃ β) :
optionCongr e = EquivFunctor.mapEquiv Option e :=
rfl
end OptionCongr
section RemoveNone
variable (e : Option α ≃ Option β)
/-- If we have a value on one side of an `Equiv` of `Option`
we also have a value on the other side of the equivalence
-/
def removeNone_aux (x : α) : β :=
if h : (e (some x)).isSome then Option.get _ h
else
Option.get _ <|
show (e none).isSome by
rw [← Option.ne_none_iff_isSome]
intro hn
rw [Option.not_isSome_iff_eq_none, ← hn] at h
exact Option.some_ne_none _ (e.injective h)
theorem removeNone_aux_some {x : α} (h : ∃ x', e (some x) = some x') :
some (removeNone_aux e x) = e (some x) := by
simp [removeNone_aux, Option.isSome_iff_exists.mpr h]
theorem removeNone_aux_none {x : α} (h : e (some x) = none) :
some (removeNone_aux e x) = e none := by
simp [removeNone_aux, Option.not_isSome_iff_eq_none.mpr h]
theorem removeNone_aux_inv (x : α) : removeNone_aux e.symm (removeNone_aux e x) = x :=
Option.some_injective _
(by
cases h1 : e.symm (some (removeNone_aux e x)) <;> cases h2 : e (some x)
· rw [removeNone_aux_none _ h1]
exact (e.eq_symm_apply.mpr h2).symm
· rw [removeNone_aux_some _ ⟨_, h2⟩] at h1
simp at h1
· rw [removeNone_aux_none _ h2] at h1
simp at h1
· rw [removeNone_aux_some _ ⟨_, h1⟩]
rw [removeNone_aux_some _ ⟨_, h2⟩]
simp)
/-- Given an equivalence between two `Option` types, eliminate `none` from that equivalence by
mapping `e.symm none` to `e none`. -/
def removeNone : α ≃ β where
toFun := removeNone_aux e
invFun := removeNone_aux e.symm
left_inv := removeNone_aux_inv e
right_inv := removeNone_aux_inv e.symm
@[simp]
theorem removeNone_symm : (removeNone e).symm = removeNone e.symm :=
rfl
theorem removeNone_some {x : α} (h : ∃ x', e (some x) = some x') :
some (removeNone e x) = e (some x) :=
removeNone_aux_some e h
theorem removeNone_none {x : α} (h : e (some x) = none) : some (removeNone e x) = e none :=
removeNone_aux_none e h
@[simp]
theorem option_symm_apply_none_iff : e.symm none = none ↔ e none = none :=
⟨fun h => by simpa using (congr_arg e h).symm, fun h => by simpa using (congr_arg e.symm h).symm⟩
theorem some_removeNone_iff {x : α} : some (removeNone e x) = e none ↔ e.symm none = some x := by
rcases h : e (some x) with a | a
· rw [removeNone_none _ h]
simpa using (congr_arg e.symm h).symm
· rw [removeNone_some _ ⟨a, h⟩]
have h1 := congr_arg e.symm h
rw [symm_apply_apply] at h1
simp only [apply_eq_iff_eq, reduceCtorEq]
simp [h1]
@[simp]
theorem removeNone_optionCongr (e : α ≃ β) : removeNone e.optionCongr = e :=
Equiv.ext fun x => Option.some_injective _ <| removeNone_some _ ⟨e x, by simp⟩
end RemoveNone
theorem optionCongr_injective : Function.Injective (optionCongr : α ≃ β → Option α ≃ Option β) :=
Function.LeftInverse.injective removeNone_optionCongr
/-- Equivalences between `Option α` and `β` that send `none` to `x` are equivalent to
equivalences between `α` and `{y : β // y ≠ x}`. -/
def optionSubtype [DecidableEq β] (x : β) :
{ e : Option α ≃ β // e none = x } ≃ (α ≃ { y : β // y ≠ x }) where
toFun e :=
{ toFun := fun a =>
⟨(e : Option α ≃ β) a, ((EquivLike.injective _).ne_iff' e.property).2 (some_ne_none _)⟩,
invFun := fun b =>
get _
(ne_none_iff_isSome.1
(((EquivLike.injective _).ne_iff'
((apply_eq_iff_eq_symm_apply _).1 e.property).symm).2 b.property)),
left_inv := fun a => by
rw [← some_inj, some_get]
exact symm_apply_apply (e : Option α ≃ β) a,
right_inv := fun b => by
ext
simp }
invFun e :=
⟨{ toFun := fun a => casesOn' a x (Subtype.val ∘ e),
invFun := fun b => if h : b = x then none else e.symm ⟨b, h⟩,
left_inv := fun a => by
cases a with
| none => simp
| some a =>
simp only [casesOn'_some, Function.comp_apply, Subtype.coe_eta,
symm_apply_apply, dite_eq_ite]
exact if_neg (e a).property,
right_inv := fun b => by
by_cases h : b = x <;> simp [h] },
rfl⟩
left_inv e := by
ext a
cases a
· simpa using e.property.symm
· simp
right_inv e := by
ext a
rfl
@[simp]
theorem optionSubtype_apply_apply
[DecidableEq β] (x : β)
(e : { e : Option α ≃ β // e none = x })
(a : α)
(h) : optionSubtype x e a = ⟨(e : Option α ≃ β) a, h⟩ := rfl
@[simp]
theorem coe_optionSubtype_apply_apply
[DecidableEq β] (x : β)
(e : { e : Option α ≃ β // e none = x })
(a : α) : ↑(optionSubtype x e a) = (e : Option α ≃ β) a := rfl
@[simp]
theorem optionSubtype_apply_symm_apply
[DecidableEq β] (x : β)
(e : { e : Option α ≃ β // e none = x })
(b : { y : β // y ≠ x }) : ↑((optionSubtype x e).symm b) = (e : Option α ≃ β).symm b := by
dsimp only [optionSubtype]
simp
@[simp]
theorem optionSubtype_symm_apply_apply_coe [DecidableEq β] (x : β) (e : α ≃ { y : β // y ≠ x })
(a : α) : ((optionSubtype x).symm e : Option α ≃ β) a = e a :=
rfl
@[simp]
theorem optionSubtype_symm_apply_apply_some
[DecidableEq β]
(x : β)
(e : α ≃ { y : β // y ≠ x })
(a : α) : ((optionSubtype x).symm e : Option α ≃ β) (some a) = e a :=
rfl
@[simp]
theorem optionSubtype_symm_apply_apply_none
[DecidableEq β]
(x : β)
(e : α ≃ { y : β // y ≠ x }) : ((optionSubtype x).symm e : Option α ≃ β) none = x :=
rfl
@[simp]
theorem optionSubtype_symm_apply_symm_apply [DecidableEq β] (x : β) (e : α ≃ { y : β // y ≠ x })
(b : { y : β // y ≠ x }) : ((optionSubtype x).symm e : Option α ≃ β).symm b = e.symm b := by
simp only [optionSubtype, coe_fn_symm_mk, Subtype.coe_mk,
Subtype.coe_eta, dite_eq_ite, ite_eq_right_iff]
exact fun h => False.elim (b.property h)
variable [DecidableEq α] {a b : α}
/-- Any type with a distinguished element is equivalent to an `Option` type on the subtype excluding
that element. -/
@[simps!]
def optionSubtypeNe (a : α) : Option {b // b ≠ a} ≃ α := optionSubtype a |>.symm (.refl _) |>.1
lemma optionSubtypeNe_symm_self (a : α) : (optionSubtypeNe a).symm a = none := by simp
lemma optionSubtypeNe_symm_of_ne (hba : b ≠ a) : (optionSubtypeNe a).symm b = some ⟨b, hba⟩ := by
simp [hba]
@[simp] lemma optionSubtypeNe_none (a : α) : optionSubtypeNe a none = a := rfl
@[simp] lemma optionSubtypeNe_some (a : α) (b) : optionSubtypeNe a (some b) = b := rfl
open Sum
/-- `Option α` is equivalent to `α ⊕ PUnit` -/
def optionEquivSumPUnit.{v, w} (α : Type w) : Option α ≃ α ⊕ PUnit.{v + 1} :=
⟨fun o => o.elim (inr PUnit.unit) inl, fun s => s.elim some fun _ => none,
fun o => by cases o <;> rfl,
fun s => by rcases s with (_ | ⟨⟨⟩⟩) <;> rfl⟩
@[simp]
theorem optionEquivSumPUnit_none {α} : optionEquivSumPUnit α none = Sum.inr PUnit.unit :=
rfl
@[simp]
theorem optionEquivSumPUnit_some {α} (a) : optionEquivSumPUnit α (some a) = Sum.inl a :=
rfl
@[simp]
theorem optionEquivSumPUnit_coe {α} (a : α) : optionEquivSumPUnit α a = Sum.inl a :=
rfl
@[simp]
theorem optionEquivSumPUnit_symm_inl {α} (a) : (optionEquivSumPUnit α).symm (Sum.inl a) = a :=
rfl
@[simp]
theorem optionEquivSumPUnit_symm_inr {α} (a) : (optionEquivSumPUnit α).symm (Sum.inr a) = none :=
rfl
/-- The set of `x : Option α` such that `isSome x` is equivalent to `α`. -/
@[simps]
def optionIsSomeEquiv (α) : { x : Option α // x.isSome } ≃ α where
toFun o := Option.get _ o.2
invFun x := ⟨some x, rfl⟩
left_inv _ := Subtype.eq <| Option.some_get _
right_inv _ := Option.get_some _ _
end Equiv |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Pairwise.lean | import Mathlib.Data.FunLike.Equiv
import Mathlib.Logic.Pairwise
/-!
# Interaction of equivalences with `Pairwise`
-/
open scoped Function -- required for scoped `on` notation
lemma EmbeddingLike.pairwise_comp {X : Type*} {Y : Type*} {F} [FunLike F Y X] [EmbeddingLike F Y X]
(f : F) {p : X → X → Prop} (h : Pairwise p) : Pairwise (p on f) :=
h.comp_of_injective <| EmbeddingLike.injective f
lemma EquivLike.pairwise_comp_iff {X : Type*} {Y : Type*} {F} [EquivLike F Y X]
(f : F) (p : X → X → Prop) : Pairwise (p on f) ↔ Pairwise p :=
(EquivLike.bijective f).pairwise_comp_iff |
.lake/packages/mathlib/Mathlib/Logic/Equiv/List.lean | import Mathlib.Logic.Denumerable
/-!
# Equivalences involving `List`-like types
This file defines some additional constructive equivalences using `Encodable` and the pairing
function on `ℕ`.
-/
assert_not_exists Monoid Multiset.sort
open List
open Nat
namespace Equiv
/-- An equivalence between `α` and `β` generates an equivalence between `List α` and `List β`. -/
def listEquivOfEquiv {α β} (e : α ≃ β) : List α ≃ List β where
toFun := List.map e
invFun := List.map e.symm
left_inv l := by rw [List.map_map, e.symm_comp_self, List.map_id]
right_inv l := by rw [List.map_map, e.self_comp_symm, List.map_id]
end Equiv
namespace Encodable
variable {α : Type*}
section List
variable [Encodable α]
/-- Explicit encoding function for `List α` -/
def encodeList : List α → ℕ
| [] => 0
| a :: l => succ (pair (encode a) (encodeList l))
/-- Explicit decoding function for `List α` -/
def decodeList : ℕ → Option (List α)
| 0 => some []
| succ v =>
match unpair v, unpair_right_le v with
| (v₁, v₂), h =>
have : v₂ < succ v := lt_succ_of_le h
(· :: ·) <$> decode (α := α) v₁ <*> decodeList v₂
@[simp]
theorem decodeList_encodeList_eq_self (l : List α) : decodeList (encodeList l) = some l := by
induction l <;> simp [encodeList, decodeList, unpair_pair, encodek, *]
/-- If `α` is encodable, then so is `List α`. This uses the `pair` and `unpair` functions from
`Data.Nat.Pairing`. -/
instance _root_.List.encodable : Encodable (List α) :=
⟨encodeList, decodeList, decodeList_encodeList_eq_self⟩
instance _root_.List.countable {α : Type*} [Countable α] : Countable (List α) := by
haveI := Encodable.ofCountable α
infer_instance
@[simp]
theorem encode_list_nil : encode (@nil α) = 0 :=
rfl
@[simp]
theorem encode_list_cons (a : α) (l : List α) :
encode (a :: l) = succ (pair (encode a) (encode l)) :=
rfl
@[simp]
theorem decode_list_zero : decode (α := List α) 0 = some [] :=
show decodeList 0 = some [] by rw [decodeList]
@[simp]
theorem decode_list_succ (v : ℕ) :
decode (α := List α) (succ v) =
(· :: ·) <$> decode (α := α) v.unpair.1 <*> decode (α := List α) v.unpair.2 :=
show decodeList (succ v) = _ by
rcases e : unpair v with ⟨v₁, v₂⟩
simp [decodeList, e]; rfl
theorem length_le_encode : ∀ l : List α, length l ≤ encode l
| [] => Nat.zero_le _
| _ :: l => succ_le_succ <| (length_le_encode l).trans (right_le_pair _ _)
end List
/-! These two lemmas are not about lists, but are convenient to keep here and don't
require `Finset.sort`. -/
/-- If `α` is countable, then so is `Multiset α`. -/
instance _root_.Multiset.countable [Countable α] : Countable (Multiset α) :=
Quotient.countable
/-- If `α` is countable, then so is `Finset α`. -/
instance _root_.Finset.countable [Countable α] : Countable (Finset α) :=
Finset.val_injective.countable
/-- A listable type with decidable equality is encodable. -/
def encodableOfList [DecidableEq α] (l : List α) (H : ∀ x, x ∈ l) : Encodable α :=
⟨fun a => idxOf a l, (l[·]?), fun _ => getElem?_idxOf (H _)⟩
/-- A finite type is encodable. Because the encoding is not unique, we wrap it in `Trunc` to
preserve computability. -/
def _root_.Fintype.truncEncodable (α : Type*) [DecidableEq α] [Fintype α] : Trunc (Encodable α) :=
@Quot.recOnSubsingleton _ _ (fun s : Multiset α => (∀ x : α, x ∈ s) → Trunc (Encodable α)) _
Finset.univ.1 (fun l H => Trunc.mk <| encodableOfList l H) Finset.mem_univ
/-- A noncomputable way to arbitrarily choose an ordering on a finite type.
It is not made into a global instance, since it involves an arbitrary choice.
This can be locally made into an instance with `attribute [local instance] Fintype.toEncodable`. -/
noncomputable def _root_.Fintype.toEncodable (α : Type*) [Fintype α] : Encodable α := by
classical exact (Fintype.truncEncodable α).out
end Encodable
namespace Denumerable
variable {α : Type*} {β : Type*} [Denumerable α] [Denumerable β]
open Encodable
section List
theorem denumerable_list_aux : ∀ n : ℕ, ∃ a ∈ @decodeList α _ n, encodeList a = n
| 0 => by rw [decodeList]; exact ⟨_, rfl, rfl⟩
| succ v => by
rcases e : unpair v with ⟨v₁, v₂⟩
have h := unpair_right_le v
rw [e] at h
rcases have : v₂ < succ v := lt_succ_of_le h
denumerable_list_aux v₂ with
⟨a, h₁, h₂⟩
rw [Option.mem_def] at h₁
use ofNat α v₁ :: a
simp [decodeList, e, h₂, h₁, encodeList, pair_eq_of_unpair_eq e]
/-- If `α` is denumerable, then so is `List α`. -/
instance denumerableList : Denumerable (List α) :=
⟨denumerable_list_aux⟩
@[simp]
theorem list_ofNat_zero : ofNat (List α) 0 = [] := by rw [← @encode_list_nil α, ofNat_encode]
@[simp]
theorem list_ofNat_succ (v : ℕ) :
ofNat (List α) (succ v) = ofNat α v.unpair.1 :: ofNat (List α) v.unpair.2 :=
ofNat_of_decode <|
show decodeList (succ v) = _ by
rcases e : unpair v with ⟨v₁, v₂⟩
simp [decodeList, e]
rw [show decodeList v₂ = decode (α := List α) v₂ from rfl, decode_eq_ofNat, Option.seq_some]
end List
end Denumerable
namespace Equiv
/-- A list on a unique type is equivalent to ℕ by sending each list to its length. -/
@[simps!]
def listUniqueEquiv (α : Type*) [Unique α] : List α ≃ ℕ where
toFun := List.length
invFun n := List.replicate n default
left_inv u := List.length_injective (by simp)
right_inv n := List.length_replicate
/-- `List ℕ` is equivalent to `ℕ`. -/
def listNatEquivNat : List ℕ ≃ ℕ :=
Denumerable.eqv _
/-- If `α` is equivalent to `ℕ`, then `List α` is equivalent to `α`. -/
def listEquivSelfOfEquivNat {α : Type*} (e : α ≃ ℕ) : List α ≃ α :=
calc
List α ≃ List ℕ := listEquivOfEquiv e
_ ≃ ℕ := listNatEquivNat
_ ≃ α := e.symm
end Equiv |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Prod.lean | import Mathlib.Logic.Equiv.Defs
import Mathlib.Tactic.Contrapose
import Mathlib.Data.Prod.PProd
/-!
# Equivalence between product types
In this file we continue the work on equivalences begun in `Mathlib/Logic/Equiv/Defs.lean`,
focusing on product types.
## Main definitions
- `Equiv.prodCongr ea eb : α₁ × β₁ ≃ α₂ × β₂`: combine two equivalences `ea : α₁ ≃ α₂` and
`eb : β₁ ≃ β₂` using `Prod.map`.
## Tags
equivalence, congruence, bijective map
-/
open Function
universe u
-- Unless required to be `Type*`, all variables in this file are `Sort*`
variable {α α₁ α₂ β β₁ β₂ γ δ : Sort*}
namespace Equiv
/-- `PProd α β` is equivalent to `α × β` -/
@[simps (attr := grind =) apply symm_apply]
def pprodEquivProd {α β} : PProd α β ≃ α × β where
toFun x := (x.1, x.2)
invFun x := ⟨x.1, x.2⟩
/-- Product of two equivalences, in terms of `PProd`. If `α ≃ β` and `γ ≃ δ`, then
`PProd α γ ≃ PProd β δ`. -/
@[simps (attr := grind =) apply symm_apply]
def pprodCongr (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PProd α γ ≃ PProd β δ where
toFun x := ⟨e₁ x.1, e₂ x.2⟩
invFun x := ⟨e₁.symm x.1, e₂.symm x.2⟩
left_inv := by grind
right_inv := by grind
/-- Combine two equivalences using `PProd` in the domain and `Prod` in the codomain. -/
@[simps! (attr := grind =) apply symm_apply]
def pprodProd {α₂ β₂} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) :
PProd α₁ β₁ ≃ α₂ × β₂ :=
(ea.pprodCongr eb).trans pprodEquivProd
/-- Combine two equivalences using `PProd` in the codomain and `Prod` in the domain. -/
@[simps! (attr := grind =) apply symm_apply]
def prodPProd {α₁ β₁} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) :
α₁ × β₁ ≃ PProd α₂ β₂ :=
(ea.symm.pprodProd eb.symm).symm
/-- `PProd α β` is equivalent to `PLift α × PLift β` -/
@[simps! (attr := grind =) apply symm_apply]
def pprodEquivProdPLift : PProd α β ≃ PLift α × PLift β :=
Equiv.plift.symm.pprodProd Equiv.plift.symm
/-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. This is
`Prod.map` as an equivalence. -/
@[simps (attr := grind =) -fullyApplied apply]
def prodCongr {α₁ α₂ β₁ β₂} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ :=
⟨Prod.map e₁ e₂, Prod.map e₁.symm e₂.symm, fun ⟨a, b⟩ => by simp, fun ⟨a, b⟩ => by simp⟩
@[simp, grind =]
theorem prodCongr_symm {α₁ α₂ β₁ β₂} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(prodCongr e₁ e₂).symm = prodCongr e₁.symm e₂.symm :=
rfl
/-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. This is `Prod.swap` as an
equivalence. -/
def prodComm (α β) : α × β ≃ β × α where
toFun := Prod.swap
invFun := Prod.swap
@[simp]
theorem coe_prodComm (α β) : (⇑(prodComm α β) : α × β → β × α) = Prod.swap :=
rfl
@[simp, grind =]
theorem prodComm_apply {α β} (x : α × β) : prodComm α β x = x.swap :=
rfl
@[simp, grind =]
theorem prodComm_symm (α β) : (prodComm α β).symm = prodComm β α :=
rfl
/-- Type product is associative up to an equivalence. -/
@[simps (attr := grind =)]
def prodAssoc (α β γ) : (α × β) × γ ≃ α × β × γ :=
⟨fun p => (p.1.1, p.1.2, p.2), fun p => ((p.1, p.2.1), p.2.2), fun ⟨⟨_, _⟩, _⟩ => rfl,
fun ⟨_, ⟨_, _⟩⟩ => rfl⟩
/-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/
@[simps (attr := grind =) apply]
def prodProdProdComm (α β γ δ) : (α × β) × γ × δ ≃ (α × γ) × β × δ where
toFun abcd := ((abcd.1.1, abcd.2.1), (abcd.1.2, abcd.2.2))
invFun acbd := ((acbd.1.1, acbd.2.1), (acbd.1.2, acbd.2.2))
@[simp, grind =]
theorem prodProdProdComm_symm (α β γ δ) :
(prodProdProdComm α β γ δ).symm = prodProdProdComm α γ β δ :=
rfl
/-- `γ`-valued functions on `α × β` are equivalent to functions `α → β → γ`. -/
@[simps (attr := grind =) -fullyApplied]
def curry (α β γ) : (α × β → γ) ≃ (α → β → γ) where
toFun := Function.curry
invFun := uncurry
left_inv := uncurry_curry
right_inv := curry_uncurry
section
/-- `PUnit` is a right identity for type product up to an equivalence. -/
@[simps (attr := grind =)]
def prodPUnit (α) : α × PUnit ≃ α where
toFun := fun p => p.1
invFun := fun a => (a, PUnit.unit)
/-- `PUnit` is a left identity for type product up to an equivalence. -/
@[simps! (attr := grind =)]
def punitProd (α) : PUnit × α ≃ α :=
calc
PUnit × α ≃ α × PUnit := prodComm _ _
_ ≃ α := prodPUnit _
/-- `PUnit` is a right identity for dependent type product up to an equivalence. -/
@[simps (attr := grind =)]
def sigmaPUnit (α) : (_ : α) × PUnit ≃ α where
toFun := fun p => p.1
invFun := fun a => ⟨a, PUnit.unit⟩
/-- Any `Unique` type is a right identity for type product up to equivalence. -/
def prodUnique (α β) [Unique β] : α × β ≃ α :=
((Equiv.refl α).prodCongr <| equivPUnit.{_, 1} β).trans <| prodPUnit α
@[simp]
theorem coe_prodUnique {α β} [Unique β] : (⇑(prodUnique α β) : α × β → α) = Prod.fst :=
rfl
theorem prodUnique_apply {α β} [Unique β] (x : α × β) : prodUnique α β x = x.1 :=
rfl
@[simp]
theorem prodUnique_symm_apply {α β} [Unique β] (x : α) : (prodUnique α β).symm x = (x, default) :=
rfl
/-- Any `Unique` type is a left identity for type product up to equivalence. -/
def uniqueProd (α β) [Unique β] : β × α ≃ α :=
((equivPUnit.{_, 1} β).prodCongr <| Equiv.refl α).trans <| punitProd α
@[simp]
theorem coe_uniqueProd {α β} [Unique β] : (⇑(uniqueProd α β) : β × α → α) = Prod.snd :=
rfl
theorem uniqueProd_apply {α β} [Unique β] (x : β × α) : uniqueProd α β x = x.2 :=
rfl
@[simp]
theorem uniqueProd_symm_apply {α β} [Unique β] (x : α) :
(uniqueProd α β).symm x = (default, x) :=
rfl
/-- Any family of `Unique` types is a right identity for dependent type product up to
equivalence. -/
def sigmaUnique (α) (β : α → Type*) [∀ a, Unique (β a)] : (a : α) × (β a) ≃ α :=
(Equiv.sigmaCongrRight fun a ↦ equivPUnit.{_, 1} (β a)).trans <| sigmaPUnit α
@[simp]
theorem coe_sigmaUnique {α} {β : α → Type*} [∀ a, Unique (β a)] :
(⇑(sigmaUnique α β) : (a : α) × (β a) → α) = Sigma.fst :=
rfl
theorem sigmaUnique_apply {α} {β : α → Type*} [∀ a, Unique (β a)] (x : (a : α) × β a) :
sigmaUnique α β x = x.1 :=
rfl
@[simp]
theorem sigmaUnique_symm_apply {α} {β : α → Type*} [∀ a, Unique (β a)] (x : α) :
(sigmaUnique α β).symm x = ⟨x, default⟩ :=
rfl
/-- Any `Unique` type is a left identity for type sigma up to equivalence. Compare with `uniqueProd`
which is non-dependent. -/
def uniqueSigma {α} (β : α → Type*) [Unique α] : (i : α) × β i ≃ β default where
toFun := fun p ↦ (Unique.eq_default _).rec p.2
invFun := fun b ↦ ⟨default, b⟩
left_inv := fun _ ↦ Sigma.ext (Unique.default_eq _) (eqRec_heq _ _)
theorem uniqueSigma_apply {α} {β : α → Type*} [Unique α] (x : (a : α) × β a) :
uniqueSigma β x = (Unique.eq_default _).rec x.2 :=
rfl
@[simp]
theorem uniqueSigma_symm_apply {α} {β : α → Type*} [Unique α] (y : β default) :
(uniqueSigma β).symm y = ⟨default, y⟩ :=
rfl
/-- `Empty` type is a right absorbing element for type product up to an equivalence. -/
def prodEmpty (α) : α × Empty ≃ Empty :=
equivEmpty _
/-- `Empty` type is a left absorbing element for type product up to an equivalence. -/
def emptyProd (α) : Empty × α ≃ Empty :=
equivEmpty _
/-- `PEmpty` type is a right absorbing element for type product up to an equivalence. -/
def prodPEmpty (α) : α × PEmpty ≃ PEmpty :=
equivPEmpty _
/-- `PEmpty` type is a left absorbing element for type product up to an equivalence. -/
def pemptyProd (α) : PEmpty × α ≃ PEmpty :=
equivPEmpty _
end
section prodCongr
variable {α₁ α₂ β₁ β₂ : Type*} (e : α₁ → β₁ ≃ β₂)
/-- A family of equivalences `∀ (a : α₁), β₁ ≃ β₂` generates an equivalence
between `β₁ × α₁` and `β₂ × α₁`. -/
def prodCongrLeft : β₁ × α₁ ≃ β₂ × α₁ where
toFun ab := ⟨e ab.2 ab.1, ab.2⟩
invFun ab := ⟨(e ab.2).symm ab.1, ab.2⟩
left_inv := by grind
right_inv := by grind
@[simp]
theorem prodCongrLeft_apply (b : β₁) (a : α₁) : prodCongrLeft e (b, a) = (e a b, a) :=
rfl
theorem prodCongr_refl_right (e : β₁ ≃ β₂) :
prodCongr e (Equiv.refl α₁) = prodCongrLeft fun _ => e := by
ext ⟨a, b⟩ : 1
simp
/-- A family of equivalences `∀ (a : α₁), β₁ ≃ β₂` generates an equivalence
between `α₁ × β₁` and `α₁ × β₂`. -/
def prodCongrRight : α₁ × β₁ ≃ α₁ × β₂ where
toFun ab := ⟨ab.1, e ab.1 ab.2⟩
invFun ab := ⟨ab.1, (e ab.1).symm ab.2⟩
left_inv := by grind
right_inv := by grind
@[simp]
theorem prodCongrRight_apply (a : α₁) (b : β₁) : prodCongrRight e (a, b) = (a, e a b) :=
rfl
theorem prodCongr_refl_left (e : β₁ ≃ β₂) :
prodCongr (Equiv.refl α₁) e = prodCongrRight fun _ => e := by
ext ⟨a, b⟩ : 1
simp
@[simp]
theorem prodCongrLeft_trans_prodComm :
(prodCongrLeft e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrRight e) := by
ext ⟨a, b⟩ : 1
simp
@[simp]
theorem prodCongrRight_trans_prodComm :
(prodCongrRight e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrLeft e) := by
ext ⟨a, b⟩ : 1
simp
theorem sigmaCongrRight_sigmaEquivProd :
(sigmaCongrRight e).trans (sigmaEquivProd α₁ β₂)
= (sigmaEquivProd α₁ β₁).trans (prodCongrRight e) := by
ext ⟨a, b⟩ : 1
simp
theorem sigmaEquivProd_sigmaCongrRight :
(sigmaEquivProd α₁ β₁).symm.trans (sigmaCongrRight e)
= (prodCongrRight e).trans (sigmaEquivProd α₁ β₂).symm := by
ext ⟨a, b⟩ : 1
simp only [trans_apply, sigmaCongrRight_apply, prodCongrRight_apply]
rfl
/-- A variation on `Equiv.prodCongr` where the equivalence in the second component can depend
on the first component. A typical example is a shear mapping, explaining the name of this
declaration. -/
@[simps -fullyApplied]
def prodShear (e₁ : α₁ ≃ α₂) (e₂ : α₁ → β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ where
toFun := fun x : α₁ × β₁ => (e₁ x.1, e₂ x.1 x.2)
invFun := fun y : α₂ × β₂ => (e₁.symm y.1, (e₂ <| e₁.symm y.1).symm y.2)
left_inv := by grind
right_inv := by grind
end prodCongr
namespace Perm
variable {α₁ β₁ : Type*} [DecidableEq α₁] (a : α₁) (e : Perm β₁)
/-- `prodExtendRight a e` extends `e : Perm β` to `Perm (α × β)` by sending `(a, b)` to
`(a, e b)` and keeping the other `(a', b)` fixed. -/
def prodExtendRight : Perm (α₁ × β₁) where
toFun ab := if ab.fst = a then (a, e ab.snd) else ab
invFun ab := if ab.fst = a then (a, e.symm ab.snd) else ab
left_inv := by grind
right_inv := by grind
@[simp]
theorem prodExtendRight_apply_eq (b : β₁) : prodExtendRight a e (a, b) = (a, e b) :=
if_pos rfl
theorem prodExtendRight_apply_ne {a a' : α₁} (h : a' ≠ a) (b : β₁) :
prodExtendRight a e (a', b) = (a', b) :=
if_neg h
theorem eq_of_prodExtendRight_ne {e : Perm β₁} {a a' : α₁} {b : β₁}
(h : prodExtendRight a e (a', b) ≠ (a', b)) : a' = a := by
contrapose! h
exact prodExtendRight_apply_ne _ h _
@[simp]
theorem fst_prodExtendRight (ab : α₁ × β₁) : (prodExtendRight a e ab).fst = ab.fst := by
grind [prodExtendRight]
end Perm
section
/-- The type of functions to a product `β × γ` is equivalent to the type of pairs of functions
`α → β` and `β → γ`. -/
@[simps]
def arrowProdEquivProdArrow (α : Type*) (β γ : α → Type*) :
((i : α) → β i × γ i) ≃ ((i : α) → β i) × ((i : α) → γ i) where
toFun := fun f => (fun c => (f c).1, fun c => (f c).2)
invFun := fun p c => (p.1 c, p.2 c)
open Sum
/-- The type of dependent functions on a sum type `ι ⊕ ι'` is equivalent to the type of pairs of
functions on `ι` and on `ι'`. This is a dependent version of `Equiv.sumArrowEquivProdArrow`. -/
@[simps (attr := grind =)]
def sumPiEquivProdPi {ι ι'} (π : ι ⊕ ι' → Type*) :
(∀ i, π i) ≃ (∀ i, π (inl i)) × ∀ i', π (inr i') where
toFun f := ⟨fun i => f (inl i), fun i' => f (inr i')⟩
invFun g := Sum.rec g.1 g.2
left_inv f := by ext (i | i) <;> rfl
/-- The equivalence between a product of two dependent functions types and a single dependent
function type. Basically a symmetric version of `Equiv.sumPiEquivProdPi`. -/
@[simps! (attr := grind =)]
def prodPiEquivSumPi {ι ι'} (π : ι → Type u) (π' : ι' → Type u) :
((∀ i, π i) × ∀ i', π' i') ≃ ∀ i, Sum.elim π π' i :=
sumPiEquivProdPi (Sum.elim π π') |>.symm
/-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions
on `α` and on `β`. -/
def sumArrowEquivProdArrow (α β γ : Type*) : (α ⊕ β → γ) ≃ (α → γ) × (β → γ) :=
⟨fun f => (f ∘ inl, f ∘ inr), fun p => Sum.elim p.1 p.2, fun f => by ext ⟨⟩ <;> rfl, fun p => by
cases p
rfl⟩
@[simp, grind =]
theorem sumArrowEquivProdArrow_apply_fst {α β γ} (f : α ⊕ β → γ) (a : α) :
(sumArrowEquivProdArrow α β γ f).1 a = f (inl a) :=
rfl
@[simp, grind =]
theorem sumArrowEquivProdArrow_apply_snd {α β γ} (f : α ⊕ β → γ) (b : β) :
(sumArrowEquivProdArrow α β γ f).2 b = f (inr b) :=
rfl
@[simp, grind =]
theorem sumArrowEquivProdArrow_symm_apply_inl {α β γ} (f : α → γ) (g : β → γ) (a : α) :
((sumArrowEquivProdArrow α β γ).symm (f, g)) (inl a) = f a :=
rfl
@[simp, grind =]
theorem sumArrowEquivProdArrow_symm_apply_inr {α β γ} (f : α → γ) (g : β → γ) (b : β) :
((sumArrowEquivProdArrow α β γ).symm (f, g)) (inr b) = g b :=
rfl
/-- Type product is right distributive with respect to type sum up to an equivalence. -/
def sumProdDistrib (α β γ) : (α ⊕ β) × γ ≃ α × γ ⊕ β × γ :=
⟨fun p => p.1.map (fun x => (x, p.2)) fun x => (x, p.2),
fun s => s.elim (Prod.map inl id) (Prod.map inr id), by
rintro ⟨_ | _, _⟩ <;> rfl, by rintro (⟨_, _⟩ | ⟨_, _⟩) <;> rfl⟩
@[simp, grind =]
theorem sumProdDistrib_apply_left {α β γ} (a : α) (c : γ) :
sumProdDistrib α β γ (Sum.inl a, c) = Sum.inl (a, c) :=
rfl
@[simp, grind =]
theorem sumProdDistrib_apply_right {α β γ} (b : β) (c : γ) :
sumProdDistrib α β γ (Sum.inr b, c) = Sum.inr (b, c) :=
rfl
@[simp, grind =]
theorem sumProdDistrib_symm_apply_left {α β γ} (a : α × γ) :
(sumProdDistrib α β γ).symm (inl a) = (inl a.1, a.2) :=
rfl
@[simp, grind =]
theorem sumProdDistrib_symm_apply_right {α β γ} (b : β × γ) :
(sumProdDistrib α β γ).symm (inr b) = (inr b.1, b.2) :=
rfl
/-- The product of an indexed sum of types (formally, a `Sigma`-type `Σ i, α i`) by a type `β` is
equivalent to the sum of products `Σ i, (α i × β)`. -/
@[simps (attr := grind =) apply symm_apply]
def sigmaProdDistrib {ι : Type*} (α : ι → Type*) (β : Type*) : (Σ i, α i) × β ≃ Σ i, α i × β :=
⟨fun p => ⟨p.1.1, (p.1.2, p.2)⟩, fun p => (⟨p.1, p.2.1⟩, p.2.2), by grind, by grind⟩
/-- The product `Bool × α` is equivalent to `α ⊕ α`. -/
@[simps (attr := grind =)]
def boolProdEquivSum (α) : Bool × α ≃ α ⊕ α where
toFun p := if p.1 then (inr p.2) else (inl p.2)
invFun := Sum.elim (Prod.mk false) (Prod.mk true)
left_inv := by rintro ⟨_ | _, _⟩ <;> rfl
right_inv := by rintro (_ | _) <;> rfl
/-- The function type `Bool → α` is equivalent to `α × α`. -/
@[simps (attr := grind =)]
def boolArrowEquivProd (α : Type*) : (Bool → α) ≃ α × α where
toFun f := (f false, f true)
invFun p b := if b then p.2 else p.1
left_inv _ := by grind
end
section
open Subtype
/-- A subtype of a product defined by componentwise conditions
is equivalent to a product of subtypes. -/
def subtypeProdEquivProd {α β} {p : α → Prop} {q : β → Prop} :
{ c : α × β // p c.1 ∧ q c.2 } ≃ { a // p a } × { b // q b } where
toFun := fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩
invFun := fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩
/-- A subtype of a `Prod` that depends only on the first component is equivalent to the
corresponding subtype of the first type times the second type. -/
def prodSubtypeFstEquivSubtypeProd {α β} {p : α → Prop} :
{s : α × β // p s.1} ≃ {a // p a} × β where
toFun x := ⟨⟨x.1.1, x.2⟩, x.1.2⟩
invFun x := ⟨⟨x.1.1, x.2⟩, x.1.2⟩
/-- A subtype of a `Prod` is equivalent to a sigma type whose fibers are subtypes. -/
def subtypeProdEquivSigmaSubtype {α β} (p : α → β → Prop) :
{ x : α × β // p x.1 x.2 } ≃ Σ a, { b : β // p a b } where
toFun x := ⟨x.1.1, x.1.2, x.property⟩
invFun x := ⟨⟨x.1, x.2⟩, x.2.property⟩
/-- The type `∀ (i : α), β i` can be split as a product by separating the indices in `α`
depending on whether they satisfy a predicate `p` or not. -/
@[simps]
def piEquivPiSubtypeProd {α : Type*} (p : α → Prop) (β : α → Type*) [DecidablePred p] :
(∀ i : α, β i) ≃ (∀ i : { x // p x }, β i) × ∀ i : { x // ¬p x }, β i where
toFun f := (fun x => f x, fun x => f x)
invFun f x := if h : p x then f.1 ⟨x, h⟩ else f.2 ⟨x, h⟩
right_inv := by
rintro ⟨f, g⟩
ext1 <;> grind
left_inv f := by grind
/-- A product of types can be split as the binary product of one of the types and the product
of all the remaining types. -/
@[simps]
def piSplitAt {α : Type*} [DecidableEq α] (i : α) (β : α → Type*) :
(∀ j, β j) ≃ β i × ∀ j : { j // j ≠ i }, β j where
toFun f := ⟨f i, fun j => f j⟩
invFun f j := if h : j = i then h.symm.rec f.1 else f.2 ⟨j, h⟩
right_inv f := by ext x <;> grind
left_inv f := by grind
/-- A product of copies of a type can be split as the binary product of one copy and the product
of all the remaining copies. -/
@[simps!]
def funSplitAt {α : Type*} [DecidableEq α] (i : α) (β : Type*) :
(α → β) ≃ β × ({ j // j ≠ i } → β) :=
piSplitAt i _
end
end Equiv
/-- If `α` is a subsingleton, then it is equivalent to `α × α`. -/
def subsingletonProdSelfEquiv {α} [Subsingleton α] : α × α ≃ α where
toFun p := p.1
invFun a := (a, a)
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _ |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Nat.lean | import Mathlib.Data.Nat.Bits
import Mathlib.Data.Nat.Pairing
/-!
# Equivalences involving `ℕ`
This file defines some additional constructive equivalences using `Encodable` and the pairing
function on `ℕ`.
-/
assert_not_exists Monoid
open Nat Function
namespace Equiv
variable {α : Type*}
/-- An equivalence between `Bool × ℕ` and `ℕ`, by mapping `(true, x)` to `2 * x + 1` and
`(false, x)` to `2 * x`. -/
@[simps]
def boolProdNatEquivNat : Bool × ℕ ≃ ℕ where
toFun := uncurry bit
invFun := boddDiv2
left_inv := fun ⟨b, n⟩ => by simp
right_inv n := by simp
/-- An equivalence between `ℕ ⊕ ℕ` and `ℕ`, by mapping `(Sum.inl x)` to `2 * x` and `(Sum.inr x)` to
`2 * x + 1`.
-/
@[simps! symm_apply]
def natSumNatEquivNat : ℕ ⊕ ℕ ≃ ℕ :=
(boolProdEquivSum ℕ).symm.trans boolProdNatEquivNat
@[simp]
theorem natSumNatEquivNat_apply : ⇑natSumNatEquivNat = Sum.elim (2 * ·) (2 * · + 1) := by
ext (x | x) <;> rfl
/-- An equivalence between `ℤ` and `ℕ`, through `ℤ ≃ ℕ ⊕ ℕ` and `ℕ ⊕ ℕ ≃ ℕ`.
-/
def intEquivNat : ℤ ≃ ℕ :=
intEquivNatSumNat.trans natSumNatEquivNat
/-- An equivalence between `α × α` and `α`, given that there is an equivalence between `α` and `ℕ`.
-/
def prodEquivOfEquivNat (e : α ≃ ℕ) : α × α ≃ α :=
calc
α × α ≃ ℕ × ℕ := prodCongr e e
_ ≃ ℕ := pairEquiv
_ ≃ α := e.symm
end Equiv |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Finset.lean | import Mathlib.Data.Finset.Sort
import Mathlib.Logic.Equiv.Multiset
/-!
# `Encodable` and `Denumerable` instances for `Finset`
-/
variable {α}
open Encodable
/-- If `α` is encodable, then so is `Finset α`. -/
instance Finset.encodable [Encodable α] : Encodable (Finset α) :=
haveI := decidableEqOfEncodable α
ofEquiv { s : Multiset α // s.Nodup }
{ toFun := fun ⟨a, b⟩ => ⟨a, b⟩
invFun := fun ⟨a, b⟩ => ⟨a, b⟩ }
namespace Encodable
/-- The elements of a `Fintype` as a sorted list. -/
def sortedUniv (α) [Fintype α] [Encodable α] : List α :=
Finset.univ.sort (Encodable.encode' α ⁻¹'o (· ≤ ·))
@[simp]
theorem mem_sortedUniv {α} [Fintype α] [Encodable α] (x : α) : x ∈ sortedUniv α :=
(Finset.mem_sort _).2 (Finset.mem_univ _)
@[simp]
theorem length_sortedUniv (α) [Fintype α] [Encodable α] : (sortedUniv α).length = Fintype.card α :=
Finset.length_sort _
@[simp]
theorem sortedUniv_nodup (α) [Fintype α] [Encodable α] : (sortedUniv α).Nodup :=
Finset.sort_nodup _ _
@[simp]
theorem sortedUniv_toFinset (α) [Fintype α] [Encodable α] [DecidableEq α] :
(sortedUniv α).toFinset = Finset.univ :=
Finset.sort_toFinset _ _
/-- An encodable `Fintype` is equivalent to the same size `Fin`. -/
def fintypeEquivFin {α} [Fintype α] [Encodable α] : α ≃ Fin (Fintype.card α) :=
haveI : DecidableEq α := Encodable.decidableEqOfEncodable _
((sortedUniv_nodup α).getEquivOfForallMemList _ mem_sortedUniv).symm.trans <|
Equiv.cast (congr_arg _ (length_sortedUniv α))
end Encodable
namespace Denumerable
variable [Denumerable α]
/-- Outputs the list of differences minus one of the input list, that is
`lower' [a₁, a₂, a₃, ...] n = [a₁ - n, a₂ - a₁ - 1, a₃ - a₂ - 1, ...]`. -/
def lower' : List ℕ → ℕ → List ℕ
| [], _ => []
| m :: l, n => (m - n) :: lower' l (m + 1)
/-- Outputs the list of partial sums plus one of the input list, that is
`raise [a₁, a₂, a₃, ...] n = [n + a₁, n + a₁ + a₂ + 1, n + a₁ + a₂ + a₃ + 2, ...]`. Adding one each
time ensures the elements are distinct. -/
def raise' : List ℕ → ℕ → List ℕ
| [], _ => []
| m :: l, n => (m + n) :: raise' l (m + n + 1)
theorem lower_raise' : ∀ l n, lower' (raise' l n) n = l
| [], _ => rfl
| m :: l, n => by simp [raise', lower', lower_raise']
theorem raise_lower' : ∀ {l n}, (∀ m ∈ l, n ≤ m) → List.Sorted (· < ·) l → raise' (lower' l n) n = l
| [], _, _, _ => rfl
| m :: l, n, h₁, h₂ => by
have : n ≤ m := h₁ _ List.mem_cons_self
simp [raise', lower', Nat.sub_add_cancel this,
raise_lower' (List.rel_of_sorted_cons h₂ : ∀ a ∈ l, m < a) h₂.of_cons]
theorem isChain_raise' : ∀ (l) (n), List.IsChain (· < ·) (raise' l n)
| [], _ => .nil
| [_], _ => .singleton _
| _ :: _ :: _, _ => .cons_cons (by omega) (isChain_raise' (_ :: _) _)
theorem isChain_cons_raise' (l m) : List.IsChain (· < ·) (m :: raise' l (m + 1)) :=
isChain_raise' (m :: l) 0
theorem isChain_cons_raise'_of_lt (l) {m n} (h : m < n) :
List.IsChain (· < ·) (m :: raise' l n) := by
unfold raise'; cases l with grind [isChain_cons_raise']
@[deprecated (since := "2025-09-19")]
alias raise'_chain := isChain_cons_raise'_of_lt
/-- `raise' l n` is a strictly increasing sequence. -/
theorem raise'_sorted (l n) : List.Sorted (· < ·) (raise' l n) := (isChain_raise' _ _).pairwise
/-- Makes `raise' l n` into a finset. Elements are distinct thanks to `raise'_sorted`. -/
def raise'Finset (l : List ℕ) (n : ℕ) : Finset ℕ :=
⟨raise' l n, (raise'_sorted _ _).imp (@ne_of_lt _ _)⟩
/-- If `α` is denumerable, then so is `Finset α`. Warning: this is *not* the same encoding as used
in `Finset.encodable`. -/
instance finset : Denumerable (Finset α) :=
mk'
⟨fun s : Finset α => encode <| lower' (s.map (eqv α).toEmbedding).sort 0, fun n =>
Finset.map (eqv α).symm.toEmbedding (raise'Finset (ofNat (List ℕ) n) 0), fun s =>
Finset.eq_of_veq <| by
simp [-Multiset.map_coe, raise'Finset,
raise_lower' (fun n _ => Nat.zero_le n) (Finset.sort_sorted_lt _)],
fun n => by
simp [-Multiset.map_coe, Finset.map, raise'Finset, Finset.sort,
List.mergeSort_eq_self _ (raise'_sorted _ _).le_of_lt, lower_raise']⟩
end Denumerable |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Basic.lean | import Mathlib.Logic.Equiv.Option
import Mathlib.Logic.Equiv.Sum
import Mathlib.Logic.Function.Conjugate
import Mathlib.Tactic.Lift
/-!
# Equivalence between types
In this file we continue the work on equivalences begun in `Mathlib/Logic/Equiv/Defs.lean`, defining
a lot of equivalences between various types and operations on these equivalences.
More definitions of this kind can be found in other files.
E.g., `Mathlib/Algebra/Equiv/TransferInstance.lean` does it for many algebraic type classes like
`Group`, `Module`, etc.
## Tags
equivalence, congruence, bijective map
-/
universe u v w z
open Function
-- Unless required to be `Type*`, all variables in this file are `Sort*`
variable {α α₁ α₂ β β₁ β₂ γ δ : Sort*}
namespace Equiv
/-- The product over `Option α` of `β a` is the binary product of the
product over `α` of `β (some α)` and `β none` -/
@[simps]
def piOptionEquivProd {α} {β : Option α → Type*} :
(∀ a : Option α, β a) ≃ β none × ∀ a : α, β (some a) where
toFun f := (f none, fun a => f (some a))
invFun x a := Option.casesOn a x.fst x.snd
left_inv f := funext fun a => by cases a <;> rfl
section subtypeCongr
/-- Combines an `Equiv` between two subtypes with an `Equiv` between their complements to form a
permutation. -/
def subtypeCongr {α} {p q : α → Prop} [DecidablePred p] [DecidablePred q]
(e : { x // p x } ≃ { x // q x }) (f : { x // ¬p x } ≃ { x // ¬q x }) : Perm α :=
(sumCompl p).symm.trans ((sumCongr e f).trans (sumCompl q))
variable {ε : Type*} {p : ε → Prop} [DecidablePred p]
variable (ep ep' : Perm { a // p a }) (en en' : Perm { a // ¬p a })
/-- Combining permutations on `ε` that permute only inside or outside the subtype
split induced by `p : ε → Prop` constructs a permutation on `ε`. -/
def Perm.subtypeCongr : Equiv.Perm ε :=
permCongr (sumCompl p) (sumCongr ep en)
theorem Perm.subtypeCongr.apply (a : ε) : ep.subtypeCongr en a =
if h : p a then (ep ⟨a, h⟩ : ε) else en ⟨a, h⟩ := by
by_cases h : p a <;> simp [Perm.subtypeCongr, h]
@[simp]
theorem Perm.subtypeCongr.left_apply {a : ε} (h : p a) : ep.subtypeCongr en a = ep ⟨a, h⟩ := by
simp [Perm.subtypeCongr.apply, h]
@[simp]
theorem Perm.subtypeCongr.left_apply_subtype (a : { a // p a }) : ep.subtypeCongr en a = ep a :=
Perm.subtypeCongr.left_apply ep en a.property
@[simp]
theorem Perm.subtypeCongr.right_apply {a : ε} (h : ¬p a) : ep.subtypeCongr en a = en ⟨a, h⟩ := by
simp [Perm.subtypeCongr.apply, h]
@[simp]
theorem Perm.subtypeCongr.right_apply_subtype (a : { a // ¬p a }) : ep.subtypeCongr en a = en a :=
Perm.subtypeCongr.right_apply ep en a.property
@[simp]
theorem Perm.subtypeCongr.refl :
Perm.subtypeCongr (Equiv.refl { a // p a }) (Equiv.refl { a // ¬p a }) = Equiv.refl ε := by
ext x
by_cases h : p x <;> simp [h]
@[simp]
theorem Perm.subtypeCongr.symm : (ep.subtypeCongr en).symm = Perm.subtypeCongr ep.symm en.symm :=
rfl
@[simp]
theorem Perm.subtypeCongr.trans :
(ep.subtypeCongr en).trans (ep'.subtypeCongr en')
= Perm.subtypeCongr (ep.trans ep') (en.trans en') := by
ext x
by_cases h : p x
· have : p (ep ⟨x, h⟩) := Subtype.property _
simp [h, this]
· have : ¬p (en ⟨x, h⟩) := Subtype.property (en _)
simp [h, this]
end subtypeCongr
section subtypePreimage
variable (p : α → Prop) [DecidablePred p] (x₀ : { a // p a } → β)
/-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`,
the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}`
is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/
@[simps]
def subtypePreimage : { x : α → β // x ∘ Subtype.val = x₀ } ≃ ({ a // ¬p a } → β) where
toFun (x : { x : α → β // x ∘ Subtype.val = x₀ }) a := (x : α → β) a
invFun x := ⟨fun a => if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩, funext fun ⟨_, h⟩ => dif_pos h⟩
left_inv := fun ⟨x, hx⟩ =>
Subtype.val_injective <|
funext fun a => by
dsimp only
split_ifs
· rw [← hx]; rfl
· rfl
right_inv x :=
funext fun ⟨a, h⟩ =>
show dite (p a) _ _ = _ by
dsimp only
rw [dif_neg h]
theorem subtypePreimage_symm_apply_coe_pos (x : { a // ¬p a } → β) (a : α) (h : p a) :
((subtypePreimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ :=
dif_pos h
theorem subtypePreimage_symm_apply_coe_neg (x : { a // ¬p a } → β) (a : α) (h : ¬p a) :
((subtypePreimage p x₀).symm x : α → β) a = x ⟨a, h⟩ :=
dif_neg h
end subtypePreimage
section
/-- A family of equivalences `∀ a, β₁ a ≃ β₂ a` generates an equivalence between `∀ a, β₁ a` and
`∀ a, β₂ a`. -/
@[simps (attr := grind =)]
def piCongrRight {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (∀ a, β₁ a) ≃ (∀ a, β₂ a) :=
⟨Pi.map fun a ↦ F a, Pi.map fun a ↦ (F a).symm, fun H => funext <| by simp,
fun H => funext <| by simp⟩
@[simp]
lemma piCongrRight_refl {β : α → Sort*} : piCongrRight (fun a ↦ .refl (β a)) = .refl (∀ a, β a) :=
rfl
/-- Given `φ : α → β → Sort*`, we have an equivalence between `∀ a b, φ a b` and `∀ b a, φ a b`.
This is `Function.swap` as an `Equiv`. -/
@[simps apply]
def piComm (φ : α → β → Sort*) : (∀ a b, φ a b) ≃ ∀ b a, φ a b :=
⟨swap, swap, fun _ => rfl, fun _ => rfl⟩
@[simp]
theorem piComm_symm {φ : α → β → Sort*} : (piComm φ).symm = (piComm <| swap φ) :=
rfl
/-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent
to the type of dependent functions of two arguments (i.e., functions to the space of functions).
This is `Sigma.curry` and `Sigma.uncurry` together as an equiv. -/
def piCurry {α} {β : α → Type*} (γ : ∀ a, β a → Type*) :
(∀ x : Σ i, β i, γ x.1 x.2) ≃ ∀ a b, γ a b where
toFun := Sigma.curry
invFun := Sigma.uncurry
left_inv := Sigma.uncurry_curry
right_inv := Sigma.curry_uncurry
-- `simps` overapplies these but `simps -fullyApplied` under-applies them
@[simp] theorem piCurry_apply {α} {β : α → Type*} (γ : ∀ a, β a → Type*)
(f : ∀ x : Σ i, β i, γ x.1 x.2) :
piCurry γ f = Sigma.curry f :=
rfl
@[simp] theorem piCurry_symm_apply {α} {β : α → Type*} (γ : ∀ a, β a → Type*) (f : ∀ a b, γ a b) :
(piCurry γ).symm f = Sigma.uncurry f :=
rfl
end
section prodCongr
variable {α₁ α₂ β₁ β₂ : Type*} (e : α₁ → β₁ ≃ β₂)
-- See also `Equiv.ofPreimageEquiv`.
/-- A family of equivalences between fibers gives an equivalence between domains. -/
@[simps!]
def ofFiberEquiv {α β γ} {f : α → γ} {g : β → γ}
(e : ∀ c, { a // f a = c } ≃ { b // g b = c }) : α ≃ β :=
(sigmaFiberEquiv f).symm.trans <| (Equiv.sigmaCongrRight e).trans (sigmaFiberEquiv g)
theorem ofFiberEquiv_map {α β γ} {f : α → γ} {g : β → γ}
(e : ∀ c, { a // f a = c } ≃ { b // g b = c }) (a : α) : g (ofFiberEquiv e a) = f a :=
(_ : { b // g b = _ }).property
end prodCongr
section
open Sum
/-- An equivalence that separates out the 0th fiber of `(Σ (n : ℕ), f n)`. -/
def sigmaNatSucc (f : ℕ → Type u) : (Σ n, f n) ≃ f 0 ⊕ Σ n, f (n + 1) :=
⟨fun x =>
@Sigma.casesOn ℕ f (fun _ => f 0 ⊕ Σ n, f (n + 1)) x fun n =>
@Nat.casesOn (fun i => f i → f 0 ⊕ Σ n : ℕ, f (n + 1)) n (fun x : f 0 => Sum.inl x)
fun (n : ℕ) (x : f n.succ) => Sum.inr ⟨n, x⟩,
Sum.elim (Sigma.mk 0) (Sigma.map Nat.succ fun _ => id), by rintro ⟨n | n, x⟩ <;> rfl, by
rintro (x | ⟨n, x⟩) <;> rfl⟩
end
section
open Sum Nat
/-- The set of natural numbers is equivalent to `ℕ ⊕ PUnit`. -/
def natEquivNatSumPUnit : ℕ ≃ ℕ ⊕ PUnit where
toFun n := Nat.casesOn n (inr PUnit.unit) inl
invFun := Sum.elim Nat.succ fun _ => 0
left_inv n := by cases n <;> rfl
right_inv := by rintro (_ | _) <;> rfl
/-- `ℕ ⊕ PUnit` is equivalent to `ℕ`. -/
def natSumPUnitEquivNat : ℕ ⊕ PUnit ≃ ℕ :=
natEquivNatSumPUnit.symm
/-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/
def intEquivNatSumNat : ℤ ≃ ℕ ⊕ ℕ where
toFun z := Int.casesOn z inl inr
invFun := Sum.elim Int.ofNat Int.negSucc
left_inv := by rintro (m | n) <;> rfl
right_inv := by rintro (m | n) <;> rfl
end
/-- If `α` is equivalent to `β`, then `Unique α` is equivalent to `Unique β`. -/
def uniqueCongr (e : α ≃ β) : Unique α ≃ Unique β where
toFun h := @Equiv.unique _ _ h e.symm
invFun h := @Equiv.unique _ _ h e
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- If `α` is equivalent to `β`, then `IsEmpty α` is equivalent to `IsEmpty β`. -/
theorem isEmpty_congr (e : α ≃ β) : IsEmpty α ↔ IsEmpty β :=
⟨fun h => @Function.isEmpty _ _ h e.symm, fun h => @Function.isEmpty _ _ h e⟩
protected theorem isEmpty (e : α ≃ β) [IsEmpty β] : IsEmpty α :=
e.isEmpty_congr.mpr ‹_›
section
open Subtype
/-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent
at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`.
For the statement where `α = β`, that is, `e : perm α`, see `Perm.subtypePerm`. -/
@[simps apply]
def subtypeEquiv {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) :
{ a : α // p a } ≃ { b : β // q b } where
toFun a := ⟨e a, (h _).mp a.property⟩
invFun b := ⟨e.symm b, (h _).mpr ((e.apply_symm_apply b).symm ▸ b.property)⟩
left_inv a := Subtype.ext <| by simp
right_inv b := Subtype.ext <| by simp
lemma coe_subtypeEquiv_eq_map {X Y} {p : X → Prop} {q : Y → Prop} (e : X ≃ Y)
(h : ∀ x, p x ↔ q (e x)) : ⇑(e.subtypeEquiv h) = Subtype.map e (h · |>.mp) :=
rfl
@[simp]
theorem subtypeEquiv_refl {p : α → Prop} (h : ∀ a, p a ↔ p (Equiv.refl _ a) := fun _ => Iff.rfl) :
(Equiv.refl α).subtypeEquiv h = Equiv.refl { a : α // p a } := by
ext
rfl
-- We use `as_aux_lemma` here to avoid creating large proof terms when using `simp`
@[simp]
theorem subtypeEquiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) :
(e.subtypeEquiv h).symm = e.symm.subtypeEquiv (by as_aux_lemma => grind) :=
rfl
@[simp]
theorem subtypeEquiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop} (e : α ≃ β) (f : β ≃ γ)
(h : ∀ a : α, p a ↔ q (e a)) (h' : ∀ b : β, q b ↔ r (f b)) :
(e.subtypeEquiv h).trans (f.subtypeEquiv h')
= (e.trans f).subtypeEquiv (by as_aux_lemma => exact fun a => (h a).trans (h' <| e a)) :=
rfl
/-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to
`{x // q x}`. -/
@[simps!]
def subtypeEquivRight {p q : α → Prop} (e : ∀ x, p x ↔ q x) : { x // p x } ≃ { x // q x } :=
subtypeEquiv (Equiv.refl _) e
lemma subtypeEquivRight_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x)
(z : { x // p x }) : subtypeEquivRight e z = ⟨z, (e z.1).mp z.2⟩ := rfl
lemma subtypeEquivRight_symm_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x)
(z : { x // q x }) : (subtypeEquivRight e).symm z = ⟨z, (e z.1).mpr z.2⟩ := rfl
/-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent
to the subtype `{b // p b}`. -/
def subtypeEquivOfSubtype {p : β → Prop} (e : α ≃ β) : { a : α // p (e a) } ≃ { b : β // p b } :=
subtypeEquiv e <| by simp
/-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent
to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/
def subtypeEquivOfSubtype' {p : α → Prop} (e : α ≃ β) :
{ a : α // p a } ≃ { b : β // p (e.symm b) } :=
e.symm.subtypeEquivOfSubtype.symm
/-- If two predicates are equal, then the corresponding subtypes are equivalent. -/
def subtypeEquivProp {p q : α → Prop} (h : p = q) : Subtype p ≃ Subtype q :=
subtypeEquiv (Equiv.refl α) fun _ => h ▸ Iff.rfl
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This
version allows the “inner” predicate to depend on `h : p a`. -/
@[simps]
def subtypeSubtypeEquivSubtypeExists (p : α → Prop) (q : Subtype p → Prop) :
Subtype q ≃ { a : α // ∃ h : p a, q ⟨a, h⟩ } :=
⟨fun a =>
⟨a.1, a.1.2, by
rcases a with ⟨⟨a, hap⟩, haq⟩
exact haq⟩,
fun a => ⟨⟨a, a.2.fst⟩, a.2.snd⟩, fun ⟨⟨_, _⟩, _⟩ => rfl, fun ⟨_, _, _⟩ => rfl⟩
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/
@[simps!]
def subtypeSubtypeEquivSubtypeInter {α : Type u} (p q : α → Prop) :
{ x : Subtype p // q x.1 } ≃ Subtype fun x => p x ∧ q x :=
(subtypeSubtypeEquivSubtypeExists p _).trans <|
subtypeEquivRight fun x => @exists_prop (q x) (p x)
/-- If the outer subtype has more restrictive predicate than the inner one,
then we can drop the latter. -/
@[simps!]
def subtypeSubtypeEquivSubtype {α} {p q : α → Prop} (h : ∀ {x}, q x → p x) :
{ x : Subtype p // q x.1 } ≃ Subtype q :=
(subtypeSubtypeEquivSubtypeInter p _).trans <| subtypeEquivRight fun _ => and_iff_right_of_imp h
/-- If a proposition holds for all elements, then the subtype is
equivalent to the original type. -/
@[simps apply symm_apply]
def subtypeUnivEquiv {α} {p : α → Prop} (h : ∀ x, p x) : Subtype p ≃ α :=
⟨fun x => x, fun x => ⟨x, h x⟩, fun _ => Subtype.eq rfl, fun _ => rfl⟩
/-- A subtype of a sigma-type is a sigma-type over a subtype. -/
def subtypeSigmaEquiv {α} (p : α → Type v) (q : α → Prop) : { y : Sigma p // q y.1 } ≃ Σ x :
Subtype q, p x.1 :=
⟨fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun _ => rfl,
fun _ => rfl⟩
/-- A sigma type over a subtype is equivalent to the sigma set over the original type,
if the fiber is empty outside of the subset -/
def sigmaSubtypeEquivOfSubset {α} (p : α → Type v) (q : α → Prop) (h : ∀ x, p x → q x) :
(Σ x : Subtype q, p x) ≃ Σ x : α, p x :=
(subtypeSigmaEquiv p q).symm.trans <| subtypeUnivEquiv fun x => h x.1 x.2
/-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then
`Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/
def sigmaSubtypeFiberEquiv {α β : Type*} (f : α → β) (p : β → Prop) (h : ∀ x, p (f x)) :
(Σ y : Subtype p, { x : α // f x = y }) ≃ α :=
calc
_ ≃ Σ y : β, { x : α // f x = y } := sigmaSubtypeEquivOfSubset _ p fun _ ⟨x, h'⟩ => h' ▸ h x
_ ≃ α := sigmaFiberEquiv f
/-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent
to `{x // p x}`. -/
def sigmaSubtypeFiberEquivSubtype {α β : Type*} (f : α → β) {p : α → Prop} {q : β → Prop}
(h : ∀ x, p x ↔ q (f x)) : (Σ y : Subtype q, { x : α // f x = y }) ≃ Subtype p :=
calc
(Σ y : Subtype q, { x : α // f x = y }) ≃ Σ y :
Subtype q, { x : Subtype p // Subtype.mk (f x) ((h x).1 x.2) = y } := by {
apply sigmaCongrRight
intro y
apply Equiv.symm
refine (subtypeSubtypeEquivSubtypeExists _ _).trans (subtypeEquivRight ?_)
intro x
exact ⟨fun ⟨hp, h'⟩ => congr_arg Subtype.val h', fun h' => ⟨(h x).2 (h'.symm ▸ y.2),
Subtype.eq h'⟩⟩ }
_ ≃ Subtype p := sigmaFiberEquiv fun x : Subtype p => (⟨f x, (h x).1 x.property⟩ : Subtype q)
/-- A sigma type over an `Option` is equivalent to the sigma set over the original type,
if the fiber is empty at none. -/
def sigmaOptionEquivOfSome {α} (p : Option α → Type v) (h : p none → False) :
(Σ x : Option α, p x) ≃ Σ x : α, p (some x) :=
haveI h' : ∀ x, p x → x.isSome := by
intro x
cases x
· intro n
exfalso
exact h n
· intro _
exact rfl
(sigmaSubtypeEquivOfSubset _ _ h').symm.trans (sigmaCongrLeft' (optionIsSomeEquiv α))
/-- The `Pi`-type `∀ i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the
`Sigma` type such that for all `i` we have `(f i).fst = i`. -/
def piEquivSubtypeSigma (ι) (π : ι → Type*) :
(∀ i, π i) ≃ { f : ι → Σ i, π i // ∀ i, (f i).1 = i } where
toFun := fun f => ⟨fun i => ⟨i, f i⟩, fun _ => rfl⟩
invFun := fun f i => by rw [← f.2 i]; exact (f.1 i).2
right_inv := fun ⟨f, hf⟩ =>
Subtype.eq <| funext fun i =>
Sigma.eq (hf i).symm <| eq_of_heq <| rec_heq_of_heq _ <| by simp
/-- The type of functions `f : ∀ a, β a` such that for all `a` we have `p a (f a)` is equivalent
to the type of functions `∀ a, {b : β a // p a b}`. -/
def subtypePiEquivPi {β : α → Sort v} {p : ∀ a, β a → Prop} :
{ f : ∀ a, β a // ∀ a, p a (f a) } ≃ ∀ a, { b : β a // p a b } where
toFun := fun f a => ⟨f.1 a, f.2 a⟩
invFun := fun f => ⟨fun a => (f a).1, fun a => (f a).2⟩
left_inv := by
rintro ⟨f, h⟩
rfl
right_inv := by
rintro f
funext a
exact Subtype.ext rfl
/-- A sigma of a sigma whose second base does not depend on the first is equivalent
to a sigma whose base is a product. -/
@[simps!]
def sigmaAssocProd {α β : Type*} {γ : α → β → Type*} :
(ab : α × β) × γ ab.1 ab.2 ≃ (a : α) × (b : β) × γ a b :=
sigmaCongrLeft' (sigmaEquivProd _ _).symm |>.trans <| sigmaAssoc γ
/-- A subtype of a sigma which pins down the base of the sigma is equivalent to
the respective fiber. -/
@[simps]
def sigmaSubtype {α : Type*} {β : α → Type*} (a : α) :
{s : Sigma β // s.1 = a} ≃ β a where
toFun := fun ⟨⟨_, b⟩, h⟩ => h ▸ b
invFun b := ⟨⟨a, b⟩, rfl⟩
left_inv := fun ⟨a, h⟩ ↦ by cases h; simp
right_inv b := by simp
section
attribute [local simp] Trans.trans sigmaAssoc subtypeSigmaEquiv uniqueSigma eqRec_eq_cast
/-- A subtype of a dependent triple which pins down both bases is equivalent to the
respective fiber. -/
@[simps! +simpRhs apply]
def sigmaSigmaSubtype {α : Type*} {β : α → Type*} {γ : (a : α) → β a → Type*}
(p : (a : α) × β a → Prop) [uniq : Unique {ab // p ab}] {a : α} {b : β a} (h : p ⟨a, b⟩) :
{s : (a : α) × (b : β a) × γ a b // p ⟨s.1, s.2.1⟩} ≃ γ a b :=
calc {s : (a : α) × (b : β a) × γ a b // p ⟨s.1, s.2.1⟩}
_ ≃ _ := subtypeEquiv (p := fun ⟨a, b, c⟩ ↦ p ⟨a, b⟩) (q := (p ·.1))
(sigmaAssoc γ).symm fun s ↦ by simp [sigmaAssoc]
_ ≃ _ := subtypeSigmaEquiv _ _
_ ≃ _ := uniqueSigma (fun ab ↦ γ (Sigma.fst <| Subtype.val ab) (Sigma.snd <| Subtype.val ab))
_ ≃ γ a b := Equiv.cast <| by rw [← show ⟨⟨a, b⟩, h⟩ = uniq.default from uniq.uniq _]
@[simp]
lemma sigmaSigmaSubtype_symm_apply {α : Type*} {β : α → Type*} {γ : (a : α) → β a → Type*}
(p : (a : α) × β a → Prop) [uniq : Unique {ab // p ab}]
{a : α} {b : β a} (c : γ a b) (h : p ⟨a, b⟩) :
(sigmaSigmaSubtype p h).symm c = ⟨⟨a, ⟨b, c⟩⟩, h⟩ := by
rw [Equiv.symm_apply_eq]; simp
/-- A specialization of `sigmaSigmaSubtype` to the case where the second base
does not depend on the first, and the property being checked for is simple
equality. Useful e.g. when `γ` is `Hom` inside a category. -/
def sigmaSigmaSubtypeEq {α β : Type*} {γ : α → β → Type*} (a : α) (b : β) :
{s : (a : α) × (b : β) × γ a b // s.1 = a ∧ s.2.1 = b} ≃ γ a b :=
have : Unique (@Subtype ((_ : α) × β) (fun ⟨a', b'⟩ ↦ a' = a ∧ b' = b)) := {
default := ⟨⟨a, b⟩, ⟨rfl, rfl⟩⟩
uniq := by rintro ⟨⟨a', b'⟩, ⟨rfl, rfl⟩⟩; rfl }
sigmaSigmaSubtype (fun ⟨a', b'⟩ ↦ a' = a ∧ b' = b) ⟨rfl, rfl⟩
@[simp]
lemma sigmaSigmaSubtypeEq_apply {α β : Type*} {γ : α → β → Type*} {a : α} {b : β}
(s : {s : (a : α) × (b : β) × γ a b // s.1 = a ∧ s.2.1 = b}) :
sigmaSigmaSubtypeEq a b s = cast (congrArg₂ γ s.2.1 s.2.2) s.1.2.2 := by
simp [sigmaSigmaSubtypeEq]
@[simp]
lemma sigmaSigmaSubtypeEq_symm_apply {α β : Type*} {γ : α → β → Type*} {a : α} {b : β} (c : γ a b) :
(sigmaSigmaSubtypeEq a b).symm c = ⟨⟨a, ⟨b, c⟩⟩, ⟨rfl, rfl⟩⟩ := by
simp [sigmaSigmaSubtypeEq]
end
end
section subtypeEquivCodomain
variable {X Y : Sort*} [DecidableEq X] {x : X}
/-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x`
is equivalent to the codomain `Y`. -/
def subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) :
{ g : X → Y // g ∘ (↑) = f } ≃ Y :=
(subtypePreimage _ f).trans <|
@funUnique { x' // ¬x' ≠ x } _ <|
show Unique { x' // ¬x' ≠ x } from
@Equiv.unique _ _
(show Unique { x' // x' = x } from {
default := ⟨x, rfl⟩, uniq := fun ⟨_, h⟩ => Subtype.val_injective h })
(subtypeEquivRight fun _ => not_not)
@[simp]
theorem coe_subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) :
(subtypeEquivCodomain f : _ → Y) =
fun g : { g : X → Y // g ∘ (↑) = f } => (g : X → Y) x :=
rfl
@[simp]
theorem subtypeEquivCodomain_apply (f : { x' // x' ≠ x } → Y) (g) :
subtypeEquivCodomain f g = (g : X → Y) x :=
rfl
theorem coe_subtypeEquivCodomain_symm (f : { x' // x' ≠ x } → Y) :
((subtypeEquivCodomain f).symm : Y → _) = fun y =>
⟨fun x' => if h : x' ≠ x then f ⟨x', h⟩ else y, by grind⟩ :=
rfl
@[simp]
theorem subtypeEquivCodomain_symm_apply (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) :
((subtypeEquivCodomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y :=
rfl
theorem subtypeEquivCodomain_symm_apply_eq (f : { x' // x' ≠ x } → Y) (y : Y) :
((subtypeEquivCodomain f).symm y : X → Y) x = y :=
dif_neg (not_not.mpr rfl)
theorem subtypeEquivCodomain_symm_apply_ne
(f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) (h : x' ≠ x) :
((subtypeEquivCodomain f).symm y : X → Y) x' = f ⟨x', h⟩ :=
dif_pos h
end subtypeEquivCodomain
instance : CanLift (α → β) (α ≃ β) (↑) Bijective where prf f hf := ⟨ofBijective f hf, rfl⟩
section
variable {α' β' : Type*} (e : Perm α') {p : β' → Prop} [DecidablePred p] (f : α' ≃ Subtype p)
/-- Extend the domain of `e : Equiv.Perm α` to one that is over `β` via `f : α → Subtype p`,
where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`.
This can be used to extend the domain across a function `f : α → β`,
keeping everything outside of `Set.range f` fixed. For this use-case `Equiv` given by `f` can
be constructed by `Equiv.of_leftInverse'` or `Equiv.of_leftInverse` when there is a known
inverse, or `Equiv.ofInjective` in the general case.
-/
def Perm.extendDomain : Perm β' :=
(permCongr f e).subtypeCongr (Equiv.refl _)
@[simp]
theorem Perm.extendDomain_apply_image (a : α') : e.extendDomain f (f a) = f (e a) := by
simp [Perm.extendDomain]
theorem Perm.extendDomain_apply_subtype {b : β'} (h : p b) :
e.extendDomain f b = f (e (f.symm ⟨b, h⟩)) := by
simp [Perm.extendDomain, h]
theorem Perm.extendDomain_apply_not_subtype {b : β'} (h : ¬p b) : e.extendDomain f b = b := by
simp [Perm.extendDomain, h]
@[simp]
theorem Perm.extendDomain_refl : Perm.extendDomain (Equiv.refl _) f = Equiv.refl _ := by
simp [Perm.extendDomain]
@[simp]
theorem Perm.extendDomain_symm : (e.extendDomain f).symm = Perm.extendDomain e.symm f :=
rfl
theorem Perm.extendDomain_trans (e e' : Perm α') :
(e.extendDomain f).trans (e'.extendDomain f) = Perm.extendDomain (e.trans e') f := by
simp [Perm.extendDomain, permCongr_trans]
end
/-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with
equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift
of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`.
Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/
def subtypeQuotientEquivQuotientSubtype (p₁ : α → Prop) {s₁ : Setoid α} {s₂ : Setoid (Subtype p₁)}
(p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : Subtype p₁, s₂.r x y ↔ s₁.r x y) : {x // p₂ x} ≃ Quotient s₂ where
toFun a :=
Quotient.hrecOn a.1 (fun a h => ⟦⟨a, (hp₂ _).2 h⟩⟧)
(fun a b hab => hfunext (by rw [Quotient.sound hab]) fun _ _ _ =>
heq_of_eq (Quotient.sound ((h _ _).2 hab)))
a.2
invFun a :=
Quotient.liftOn a (fun a => (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : { x // p₂ x })) fun _ _ hab =>
Subtype.ext (Quotient.sound ((h _ _).1 hab))
left_inv := by exact fun ⟨a, ha⟩ => Quotient.inductionOn a (fun b hb => rfl) ha
right_inv a := by exact Quotient.inductionOn a fun ⟨a, ha⟩ => rfl
@[simp]
theorem subtypeQuotientEquivQuotientSubtype_mk (p₁ : α → Prop)
[s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : Subtype p₁, s₂ x y ↔ (x : α) ≈ y)
(x hx) : subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h ⟨⟦x⟧, hx⟩ = ⟦⟨x, (hp₂ _).2 hx⟩⟧ :=
rfl
@[simp]
theorem subtypeQuotientEquivQuotientSubtype_symm_mk (p₁ : α → Prop)
[s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : Subtype p₁, s₂ x y ↔ (x : α) ≈ y) (x) :
(subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h).symm ⟦x⟧ = ⟨⟦x⟧, (hp₂ _).1 x.property⟩ :=
rfl
section Swap
variable [DecidableEq α]
/-- A helper function for `Equiv.swap`. -/
def swapCore (a b r : α) : α :=
if r = a then b else if r = b then a else r
theorem swapCore_self (r a : α) : swapCore a a r = r := by
unfold swapCore
split_ifs <;> simp [*]
theorem swapCore_swapCore (r a b : α) : swapCore a b (swapCore a b r) = r := by
unfold swapCore; split_ifs <;> grind
theorem swapCore_comm (r a b : α) : swapCore a b r = swapCore b a r := by
unfold swapCore; split_ifs <;> grind
/-- `swap a b` is the permutation that swaps `a` and `b` and
leaves other values as is. -/
def swap (a b : α) : Perm α :=
⟨swapCore a b, swapCore a b, fun r => swapCore_swapCore r a b,
fun r => swapCore_swapCore r a b⟩
@[simp]
theorem swap_self (a : α) : swap a a = Equiv.refl _ :=
ext fun r => swapCore_self r a
theorem swap_comm (a b : α) : swap a b = swap b a :=
ext fun r => swapCore_comm r _ _
@[aesop simp, grind =]
theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x :=
rfl
@[simp]
theorem swap_apply_left (a b : α) : swap a b a = b :=
if_pos rfl
@[simp]
theorem swap_apply_right (a b : α) : swap a b b = a := by
grind
theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x := by
grind
theorem eq_or_eq_of_swap_apply_ne_self {a b x : α} (h : swap a b x ≠ x) : x = a ∨ x = b := by
contrapose! h
exact swap_apply_of_ne_of_ne h.1 h.2
@[simp]
theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = Equiv.refl _ :=
ext fun _ => swapCore_swapCore _ _ _
@[simp]
theorem symm_swap (a b : α) : (swap a b).symm = swap a b :=
rfl
@[simp]
theorem swap_eq_refl_iff {x y : α} : swap x y = Equiv.refl _ ↔ x = y :=
⟨fun h => (Equiv.refl _).injective (by grind), by grind⟩
theorem swap_comp_apply {a b x : α} (π : Perm α) :
π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x := by
cases π
rfl
theorem swap_eq_update (i j : α) : (Equiv.swap i j : α → α) = update (update id j i) i j := by
grind
theorem comp_swap_eq_update (i j : α) (f : α → β) :
f ∘ Equiv.swap i j = update (update f j (f i)) i (f j) := by
grind
@[simp]
theorem symm_trans_swap_trans [DecidableEq β] (a b : α) (e : α ≃ β) :
(e.symm.trans (swap a b)).trans e = swap (e a) (e b) := by
grind
@[simp]
theorem trans_swap_trans_symm [DecidableEq β] (a b : β) (e : α ≃ β) :
(e.trans (swap a b)).trans e.symm = swap (e.symm a) (e.symm b) :=
symm_trans_swap_trans a b e.symm
@[simp]
theorem swap_apply_self (i j a : α) : swap i j (swap i j a) = a := by
grind
/-- A function is invariant to a swap if it is equal at both elements -/
theorem apply_swap_eq_self {v : α → β} {i j : α} (hv : v i = v j) (k : α) :
v (swap i j k) = v k := by
grind
theorem swap_apply_eq_iff {x y z w : α} : swap x y z = w ↔ z = swap x y w := by
grind
theorem swap_apply_ne_self_iff {a b x : α} : swap a b x ≠ x ↔ a ≠ b ∧ (x = a ∨ x = b) := by
grind
namespace Perm
@[simp]
theorem sumCongr_swap_refl {α β : Sort _} [DecidableEq α] [DecidableEq β] (i j : α) :
Equiv.Perm.sumCongr (Equiv.swap i j) (Equiv.refl β) = Equiv.swap (Sum.inl i) (Sum.inl j) := by
aesop
@[simp]
theorem sumCongr_refl_swap {α β : Sort _} [DecidableEq α] [DecidableEq β] (i j : β) :
Equiv.Perm.sumCongr (Equiv.refl α) (Equiv.swap i j) = Equiv.swap (Sum.inr i) (Sum.inr j) := by
aesop
end Perm
/-- Augment an equivalence with a prescribed mapping `f a = b` -/
def setValue (f : α ≃ β) (a : α) (b : β) : α ≃ β :=
(swap a (f.symm b)).trans f
@[simp]
theorem setValue_eq (f : α ≃ β) (a : α) (b : β) : setValue f a b a = b := by
simp [setValue, swap_apply_left]
end Swap
end Equiv
namespace Function.Involutive
/-- Convert an involutive function `f` to a permutation with `toFun = invFun = f`. -/
def toPerm (f : α → α) (h : Involutive f) : Equiv.Perm α :=
⟨f, f, h.leftInverse, h.rightInverse⟩
@[simp]
theorem coe_toPerm {f : α → α} (h : Involutive f) : (h.toPerm f : α → α) = f :=
rfl
@[simp]
theorem toPerm_symm {f : α → α} (h : Involutive f) : (h.toPerm f).symm = h.toPerm f :=
rfl
theorem toPerm_involutive {f : α → α} (h : Involutive f) : Involutive (h.toPerm f) :=
h
theorem symm_eq_self_of_involutive (f : Equiv.Perm α) (h : Involutive f) : f.symm = f :=
DFunLike.coe_injective (h.leftInverse_iff.mp f.left_inv)
end Function.Involutive
theorem PLift.eq_up_iff_down_eq {x : PLift α} {y : α} : x = PLift.up y ↔ x.down = y :=
Equiv.plift.eq_symm_apply
theorem Function.Injective.map_swap [DecidableEq α] [DecidableEq β] {f : α → β}
(hf : Function.Injective f) (x y z : α) :
f (Equiv.swap x y z) = Equiv.swap (f x) (f y) (f z) := by
conv_rhs => rw [Equiv.swap_apply_def]
split_ifs with h₁ h₂
· -- We can't yet use `grind` here because of https://github.com/leanprover/lean4/issues/11088
rw [hf h₁, Equiv.swap_apply_left]
· rw [hf h₂, Equiv.swap_apply_right]
· grind
namespace Equiv
section
/-- Transport dependent functions through an equivalence of the base space.
-/
@[simps apply, simps -isSimp symm_apply]
def piCongrLeft' (P : α → Sort*) (e : α ≃ β) : (∀ a, P a) ≃ ∀ b, P (e.symm b) where
toFun f x := f (e.symm x)
invFun f x := (e.symm_apply_apply x).ndrec (f (e x))
left_inv f := by grind
right_inv f := by grind
/-- Note: the "obvious" statement `(piCongrLeft' P e).symm g a = g (e a)` doesn't typecheck: the
LHS would have type `P a` while the RHS would have type `P (e.symm (e a))`. For that reason,
we have to explicitly substitute along `e.symm (e a) = a` in the statement of this lemma. -/
add_decl_doc Equiv.piCongrLeft'_symm_apply
/-- This lemma is impractical to state in the dependent case. -/
@[simp]
theorem piCongrLeft'_symm (P : Sort*) (e : α ≃ β) :
(piCongrLeft' (fun _ => P) e).symm = piCongrLeft' _ e.symm := by ext; simp [piCongrLeft']
/-- Note: the "obvious" statement `(piCongrLeft' P e).symm g a = g (e a)` doesn't typecheck: the
LHS would have type `P a` while the RHS would have type `P (e.symm (e a))`. This lemma is a way
around it in the case where `a` is of the form `e.symm b`, so we can use `g b` instead of
`g (e (e.symm b))`. -/
@[simp]
lemma piCongrLeft'_symm_apply_apply (P : α → Sort*) (e : α ≃ β) (g : ∀ b, P (e.symm b)) (b : β) :
(piCongrLeft' P e).symm g (e.symm b) = g b := by
rw [piCongrLeft'_symm_apply, ← heq_iff_eq, eqRec_heq_iff_heq]
exact congr_arg_heq _ (e.apply_symm_apply _)
@[simp]
lemma piCongrLeft'_refl (P : α → Sort*) : piCongrLeft' P (.refl α) = .refl (∀ a, P a) := rfl
end
section
variable (P : β → Sort w) (e : α ≃ β)
/-- Transporting dependent functions through an equivalence of the base,
expressed as a "simplification".
-/
def piCongrLeft : (∀ a, P (e a)) ≃ ∀ b, P b :=
(piCongrLeft' P e.symm).symm
/-- Note: the "obvious" statement `(piCongrLeft P e) f b = f (e.symm b)` doesn't typecheck: the
LHS would have type `P b` while the RHS would have type `P (e (e.symm b))`. For that reason,
we have to explicitly substitute along `e (e.symm b) = b` in the statement of this lemma. -/
lemma piCongrLeft_apply (f : ∀ a, P (e a)) (b : β) :
(piCongrLeft P e) f b = e.apply_symm_apply b ▸ f (e.symm b) :=
rfl
@[simp, grind =]
lemma piCongrLeft_symm_apply (g : ∀ b, P b) (a : α) :
(piCongrLeft P e).symm g a = g (e a) :=
piCongrLeft'_apply P e.symm g a
@[simp]
lemma piCongrLeft_refl (P : α → Sort*) : piCongrLeft P (.refl α) = .refl (∀ a, P a) :=
rfl
/-- Note: the "obvious" statement `(piCongrLeft P e) f b = f (e.symm b)` doesn't typecheck: the
LHS would have type `P b` while the RHS would have type `P (e (e.symm b))`. This lemma is a way
around it in the case where `b` is of the form `e a`, so we can use `f a` instead of
`f (e.symm (e a))`. -/
@[simp, grind =]
lemma piCongrLeft_apply_apply (f : ∀ a, P (e a)) (a : α) :
(piCongrLeft P e) f (e a) = f a :=
piCongrLeft'_symm_apply_apply P e.symm f a
open Sum
lemma piCongrLeft_apply_eq_cast {P : β → Sort v} {e : α ≃ β}
(f : (a : α) → P (e a)) (b : β) :
piCongrLeft P e f b = cast (congr_arg P (e.apply_symm_apply b)) (f (e.symm b)) :=
eqRec_eq_cast _ _
theorem piCongrLeft_sumInl {ι ι' ι''} (π : ι'' → Type*) (e : ι ⊕ ι' ≃ ι'') (f : ∀ i, π (e (inl i)))
(g : ∀ i, π (e (inr i))) (i : ι) :
piCongrLeft π e (sumPiEquivProdPi (fun x => π (e x)) |>.symm (f, g)) (e (inl i)) = f i := by
grind
theorem piCongrLeft_sumInr {ι ι' ι''} (π : ι'' → Type*) (e : ι ⊕ ι' ≃ ι'') (f : ∀ i, π (e (inl i)))
(g : ∀ i, π (e (inr i))) (j : ι') :
piCongrLeft π e (sumPiEquivProdPi (fun x => π (e x)) |>.symm (f, g)) (e (inr j)) = g j := by
grind
end
section
variable {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : ∀ a : α, W a ≃ Z (h₁ a))
/-- Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibers.
-/
def piCongr : (∀ a, W a) ≃ ∀ b, Z b :=
(Equiv.piCongrRight h₂).trans (Equiv.piCongrLeft _ h₁)
@[simp]
theorem coe_piCongr_symm :
((h₁.piCongr h₂).symm : (∀ b, Z b) → ∀ a, W a) = fun f a => (h₂ a).symm (f (h₁ a)) :=
rfl
@[simp, grind =]
theorem piCongr_symm_apply (f : ∀ b, Z b) :
(h₁.piCongr h₂).symm f = fun a => (h₂ a).symm (f (h₁ a)) :=
rfl
@[simp, grind =]
theorem piCongr_apply_apply (f : ∀ a, W a) (a : α) : h₁.piCongr h₂ f (h₁ a) = h₂ a (f a) := by
rw [piCongr, trans_apply, piCongrLeft_apply_apply, piCongrRight_apply, Pi.map_apply]
end
section
variable {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : ∀ b : β, W (h₁.symm b) ≃ Z b)
/-- Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibres.
-/
def piCongr' : (∀ a, W a) ≃ ∀ b, Z b :=
(piCongr h₁.symm fun b => (h₂ b).symm).symm
@[simp]
theorem coe_piCongr' :
(h₁.piCongr' h₂ : (∀ a, W a) → ∀ b, Z b) = fun f b => h₂ b <| f <| h₁.symm b :=
rfl
theorem piCongr'_apply (f : ∀ a, W a) : h₁.piCongr' h₂ f = fun b => h₂ b <| f <| h₁.symm b :=
rfl
@[simp]
theorem piCongr'_symm_apply_symm_apply (f : ∀ b, Z b) (b : β) :
(h₁.piCongr' h₂).symm f (h₁.symm b) = (h₂ b).symm (f b) := by
simp [piCongr', piCongr_apply_apply]
end
/-- Transport dependent functions through an equality of sets. -/
@[simps!] def piCongrSet {α} {W : α → Sort w} {s t : Set α} (h : s = t) :
(∀ i : {i // i ∈ s}, W i) ≃ (∀ i : {i // i ∈ t}, W i) where
toFun f i := f ⟨i, h ▸ i.2⟩
invFun f i := f ⟨i, h.symm ▸ i.2⟩
lemma eq_conj {α α' β β' : Sort*} (ε₁ : α ≃ α') (ε₂ : β' ≃ β)
(f : α → β) (f' : α' → β') : ε₂.symm ∘ f ∘ ε₁.symm = f' ↔ f = ε₂ ∘ f' ∘ ε₁ := by
rw [Equiv.symm_comp_eq, Equiv.comp_symm_eq, Function.comp_assoc]
section BinaryOp
variable {α₁ β₁ : Type*} (e : α₁ ≃ β₁) (f : α₁ → α₁ → α₁)
theorem semiconj_conj (f : α₁ → α₁) : Semiconj e f (e.conj f) := fun x => by simp
theorem semiconj₂_conj : Semiconj₂ e f (e.arrowCongr e.conj f) := fun x y => by simp [arrowCongr]
instance [Std.Associative f] : Std.Associative (e.arrowCongr (e.arrowCongr e) f) :=
(e.semiconj₂_conj f).isAssociative_right e.surjective
instance [Std.IdempotentOp f] : Std.IdempotentOp (e.arrowCongr (e.arrowCongr e) f) :=
(e.semiconj₂_conj f).isIdempotent_right e.surjective
end BinaryOp
section ULift
@[simp]
theorem ulift_symm_down {α} (x : α) : (Equiv.ulift.{u, v}.symm x).down = x :=
rfl
end ULift
end Equiv
theorem Function.Injective.swap_apply
[DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y z : α) :
Equiv.swap (f x) (f y) (f z) = f (Equiv.swap x y z) :=
Eq.symm (map_swap hf x y z)
theorem Function.Injective.swap_comp
[DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y : α) :
Equiv.swap (f x) (f y) ∘ f = f ∘ Equiv.swap x y :=
funext fun _ => hf.swap_apply _ _ _
/-- To give an equivalence between two subsingleton types, it is sufficient to give any two
functions between them. -/
def equivOfSubsingletonOfSubsingleton [Subsingleton α] [Subsingleton β] (f : α → β) (g : β → α) :
α ≃ β where
toFun := f
invFun := g
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- A nonempty subsingleton type is (noncomputably) equivalent to `PUnit`. -/
noncomputable def Equiv.punitOfNonemptyOfSubsingleton [h : Nonempty α] [Subsingleton α] :
α ≃ PUnit :=
equivOfSubsingletonOfSubsingleton (fun _ => PUnit.unit) fun _ => h.some
/-- `Unique (Unique α)` is equivalent to `Unique α`. -/
def uniqueUniqueEquiv : Unique (Unique α) ≃ Unique α :=
equivOfSubsingletonOfSubsingleton (fun h => h.default) fun h =>
{ default := h, uniq := fun _ => Subsingleton.elim _ _ }
/-- If `Unique β`, then `Unique α` is equivalent to `α ≃ β`. -/
def uniqueEquivEquivUnique (α : Sort u) (β : Sort v) [Unique β] : Unique α ≃ (α ≃ β) :=
equivOfSubsingletonOfSubsingleton (fun _ => Equiv.ofUnique _ _) Equiv.unique
namespace Function
variable {α' : Sort*}
theorem update_comp_equiv [DecidableEq α'] [DecidableEq α] (f : α → β)
(g : α' ≃ α) (a : α) (v : β) :
update f a v ∘ g = update (f ∘ g) (g.symm a) v := by
rw [← update_comp_eq_of_injective _ g.injective, g.apply_symm_apply]
theorem update_apply_equiv_apply [DecidableEq α'] [DecidableEq α] (f : α → β)
(g : α' ≃ α) (a : α) (v : β) (a' : α') : update f a v (g a') = update (f ∘ g) (g.symm a) v a' :=
congr_fun (update_comp_equiv f g a v) a'
theorem piCongrLeft'_update [DecidableEq α] [DecidableEq β] (P : α → Sort*) (e : α ≃ β)
(f : ∀ a, P a) (b : β) (x : P (e.symm b)) :
e.piCongrLeft' P (update f (e.symm b) x) = update (e.piCongrLeft' P f) b x := by
ext b'
rcases eq_or_ne b' b with (rfl | h) <;> simp_all
theorem piCongrLeft'_symm_update [DecidableEq α] [DecidableEq β] (P : α → Sort*) (e : α ≃ β)
(f : ∀ b, P (e.symm b)) (b : β) (x : P (e.symm b)) :
(e.piCongrLeft' P).symm (update f b x) = update ((e.piCongrLeft' P).symm f) (e.symm b) x := by
simp [(e.piCongrLeft' P).symm_apply_eq, piCongrLeft'_update]
end Function |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Multiset.lean | import Mathlib.Data.Multiset.Sort
import Mathlib.Logic.Equiv.List
/-!
# `Encodable` and `Denumerable` instances for `Multiset`
-/
variable {α : Type*}
open Encodable
section Finset
variable [Encodable α]
private def enle : α → α → Prop :=
encode ⁻¹'o (· ≤ ·)
private theorem enle.isLinearOrder : IsLinearOrder α enle :=
(RelEmbedding.preimage ⟨encode, encode_injective⟩ (· ≤ ·)).isLinearOrder
private def decidable_enle (a b : α) : Decidable (enle a b) := by
unfold enle Order.Preimage
infer_instance
attribute [local instance] enle.isLinearOrder decidable_enle
/-- Explicit encoding function for `Multiset α` -/
def encodeMultiset (s : Multiset α) : ℕ :=
encode (s.sort enle)
/-- Explicit decoding function for `Multiset α` -/
def decodeMultiset (n : ℕ) : Option (Multiset α) :=
((↑) : List α → Multiset α) <$> decode (α := List α) n
/-- If `α` is encodable, then so is `Multiset α`. -/
instance _root_.Multiset.encodable : Encodable (Multiset α) :=
⟨encodeMultiset, decodeMultiset, fun s => by simp [encodeMultiset, decodeMultiset, encodek]⟩
end Finset
namespace Denumerable
variable [Denumerable α]
section Multiset
/-- Outputs the list of differences of the input list, that is
`lower [a₁, a₂, ...] n = [a₁ - n, a₂ - a₁, ...]` -/
def lower : List ℕ → ℕ → List ℕ
| [], _ => []
| m :: l, n => (m - n) :: lower l m
/-- Outputs the list of partial sums of the input list, that is
`raise [a₁, a₂, ...] n = [n + a₁, n + a₁ + a₂, ...]` -/
def raise : List ℕ → ℕ → List ℕ
| [], _ => []
| m :: l, n => (m + n) :: raise l (m + n)
theorem lower_raise : ∀ l n, lower (raise l n) n = l
| [], _ => rfl
| m :: l, n => by rw [raise, lower, Nat.add_sub_cancel_right, lower_raise l]
theorem raise_lower : ∀ {l n}, List.Sorted (· ≤ ·) (n :: l) → raise (lower l n) n = l
| [], _, _ => rfl
| m :: l, n, h => by
have : n ≤ m := List.rel_of_sorted_cons h _ List.mem_cons_self
simp [raise, lower, Nat.sub_add_cancel this, raise_lower h.of_cons]
theorem isChain_raise : ∀ l n, List.IsChain (· ≤ ·) (raise l n)
| [], _ => .nil
| [_], _ => .singleton _
| _ :: _ :: _, _ => .cons_cons (Nat.le_add_left _ _) (isChain_raise (_ :: _) _)
theorem isChain_cons_raise (l n) : List.IsChain (· ≤ ·) (n :: raise l n) :=
isChain_raise (n :: l) 0
@[deprecated (since := "2025-09-19")]
alias raise_chain := isChain_cons_raise
/-- `raise l n` is a non-decreasing sequence. -/
theorem raise_sorted (l n) : List.Sorted (· ≤ ·) (raise l n) := (isChain_raise _ _).pairwise
/-- If `α` is denumerable, then so is `Multiset α`. Warning: this is *not* the same encoding as used
in `Multiset.encodable`. -/
instance multiset : Denumerable (Multiset α) :=
mk'
⟨fun s : Multiset α => encode <| lower (s.map encode).sort 0,
fun n =>
Multiset.map (ofNat α) (raise (ofNat (List ℕ) n) 0),
fun s => by
have :=
raise_lower (List.sorted_cons.2 ⟨fun n _ => Nat.zero_le n, (s.map encode).sort_sorted _⟩)
simp [-Multiset.map_coe, this],
fun n => by
simp [-Multiset.map_coe, List.mergeSort_eq_self _ (raise_sorted _ _), lower_raise]⟩
end Multiset
end Denumerable |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Defs.lean | import Mathlib.Data.FunLike.Equiv
import Mathlib.Data.Quot
import Mathlib.Data.Subtype
import Mathlib.Logic.Unique
import Mathlib.Tactic.Conv
import Mathlib.Tactic.Simps.Basic
import Mathlib.Tactic.Substs
/-!
# Equivalence between types
In this file we define two types:
* `Equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and
not equality!) to express that various `Type`s or `Sort`s are equivalent.
* `Equiv.Perm α`: the group of permutations `α ≃ α`. More lemmas about `Equiv.Perm` can be found in
`Mathlib/GroupTheory/Perm.lean`.
Then we define
* canonical isomorphisms between various types: e.g.,
- `Equiv.refl α` is the identity map interpreted as `α ≃ α`;
* operations on equivalences: e.g.,
- `Equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`;
- `Equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order
of the arguments!);
* definitions that transfer some instances along an equivalence. By convention, we transfer
instances from right to left.
- `Equiv.inhabited` takes `e : α ≃ β` and `[Inhabited β]` and returns `Inhabited α`;
- `Equiv.unique` takes `e : α ≃ β` and `[Unique β]` and returns `Unique α`;
- `Equiv.decidableEq` takes `e : α ≃ β` and `[DecidableEq β]` and returns `DecidableEq α`.
More definitions of this kind can be found in other files.
E.g., `Mathlib/Algebra/Equiv/TransferInstance.lean` does it for many algebraic type classes like
`Group`, `Module`, etc.
Many more such isomorphisms and operations are defined in `Mathlib/Logic/Equiv/Basic.lean`.
## Tags
equivalence, congruence, bijective map
-/
open Function
universe u v w z
variable {α : Sort u} {β : Sort v} {γ : Sort w}
/-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/
structure Equiv (α : Sort*) (β : Sort _) where
/-- The forward map of an equivalence.
Do NOT use directly. Use the coercion instead. -/
protected toFun : α → β
/-- The backward map of an equivalence.
Do NOT use `e.invFun` directly. Use the coercion of `e.symm` instead. -/
protected invFun : β → α
protected left_inv : LeftInverse invFun toFun := by intro; first | rfl | ext <;> rfl
protected right_inv : RightInverse invFun toFun := by intro; first | rfl | ext <;> rfl
@[inherit_doc]
infixl:25 " ≃ " => Equiv
/-- Turn an element of a type `F` satisfying `EquivLike F α β` into an actual
`Equiv`. This is declared as the default coercion from `F` to `α ≃ β`. -/
@[coe]
def EquivLike.toEquiv {F} [EquivLike F α β] (f : F) : α ≃ β where
toFun := f
invFun := EquivLike.inv f
left_inv := EquivLike.left_inv f
right_inv := EquivLike.right_inv f
/-- Any type satisfying `EquivLike` can be cast into `Equiv` via `EquivLike.toEquiv`. -/
instance {F} [EquivLike F α β] : CoeTC F (α ≃ β) :=
⟨EquivLike.toEquiv⟩
/-- `Perm α` is the type of bijections from `α` to itself. -/
abbrev Equiv.Perm (α : Sort*) :=
Equiv α α
namespace Equiv
instance : EquivLike (α ≃ β) α β where
coe := Equiv.toFun
inv := Equiv.invFun
left_inv := Equiv.left_inv
right_inv := Equiv.right_inv
coe_injective' e₁ e₂ h₁ h₂ := by cases e₁; cases e₂; congr
/-- Deprecated helper instance for when inference gets stuck on following the normal chain
`EquivLike → FunLike`. -/
@[deprecated EquivLike.toFunLike (since := "2025-06-20")]
def instFunLike : FunLike (α ≃ β) α β where
coe := Equiv.toFun
coe_injective' := DFunLike.coe_injective
@[simp, norm_cast]
lemma _root_.EquivLike.coe_coe {F} [EquivLike F α β] (e : F) :
((e : α ≃ β) : α → β) = e := rfl
@[simp, grind =] theorem coe_fn_mk (f : α → β) (g l r) : (Equiv.mk f g l r : α → β) = f :=
rfl
/-- The map `(r ≃ s) → (r → s)` is injective. -/
theorem coe_fn_injective : @Function.Injective (α ≃ β) (α → β) (fun e => e) :=
DFunLike.coe_injective'
protected theorem coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ :=
@DFunLike.coe_fn_eq _ _ _ _ e₁ e₂
@[ext, grind ext] theorem ext {f g : Equiv α β} (H : ∀ x, f x = g x) : f = g := DFunLike.ext f g H
protected theorem congr_arg {f : Equiv α β} {x x' : α} : x = x' → f x = f x' :=
DFunLike.congr_arg f
protected theorem congr_fun {f g : Equiv α β} (h : f = g) (x : α) : f x = g x :=
DFunLike.congr_fun h x
@[ext] theorem Perm.ext {σ τ : Equiv.Perm α} (H : ∀ x, σ x = τ x) : σ = τ := Equiv.ext H
protected theorem Perm.congr_arg {f : Equiv.Perm α} {x x' : α} : x = x' → f x = f x' :=
Equiv.congr_arg
protected theorem Perm.congr_fun {f g : Equiv.Perm α} (h : f = g) (x : α) : f x = g x :=
Equiv.congr_fun h x
/-- Any type is equivalent to itself. -/
@[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, fun _ => rfl, fun _ => rfl⟩
instance inhabited' : Inhabited (α ≃ α) := ⟨Equiv.refl α⟩
/-- Inverse of an equivalence `e : α ≃ β`. -/
@[symm]
protected def symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun, e.right_inv, e.left_inv⟩
/-- See Note [custom simps projection] -/
def Simps.symm_apply (e : α ≃ β) : β → α := e.symm
initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply)
/-- Restatement of `Equiv.left_inv` in terms of `Function.LeftInverse`. -/
theorem left_inv' (e : α ≃ β) : Function.LeftInverse e.symm e := e.left_inv
/-- Restatement of `Equiv.right_inv` in terms of `Function.RightInverse`. -/
theorem right_inv' (e : α ≃ β) : Function.RightInverse e.symm e := e.right_inv
/-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/
@[trans]
protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ :=
⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm, e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩
@[simps]
instance : Trans Equiv Equiv Equiv where
trans := Equiv.trans
/-- `Equiv.symm` defines an equivalence between `α ≃ β` and `β ≃ α`. -/
@[simps! (attr := grind =)]
def symmEquiv (α β : Sort*) : (α ≃ β) ≃ (β ≃ α) where
toFun := .symm
invFun := .symm
@[simp, mfld_simps] theorem toFun_as_coe (e : α ≃ β) : e.toFun = e := rfl
@[simp, mfld_simps] theorem invFun_as_coe (e : α ≃ β) : e.invFun = e.symm := rfl
protected theorem injective (e : α ≃ β) : Injective e := EquivLike.injective e
protected theorem surjective (e : α ≃ β) : Surjective e := EquivLike.surjective e
protected theorem bijective (e : α ≃ β) : Bijective e := EquivLike.bijective e
protected theorem subsingleton (e : α ≃ β) [Subsingleton β] : Subsingleton α :=
e.injective.subsingleton
protected theorem subsingleton.symm (e : α ≃ β) [Subsingleton α] : Subsingleton β :=
e.symm.injective.subsingleton
theorem subsingleton_congr (e : α ≃ β) : Subsingleton α ↔ Subsingleton β :=
⟨fun _ => e.symm.subsingleton, fun _ => e.subsingleton⟩
instance equiv_subsingleton_cod [Subsingleton β] : Subsingleton (α ≃ β) :=
⟨fun _ _ => Equiv.ext fun _ => Subsingleton.elim _ _⟩
instance equiv_subsingleton_dom [Subsingleton α] : Subsingleton (α ≃ β) :=
⟨fun f _ => Equiv.ext fun _ => @Subsingleton.elim _ (Equiv.subsingleton.symm f) _ _⟩
instance permUnique [Subsingleton α] : Unique (Perm α) :=
uniqueOfSubsingleton (Equiv.refl α)
theorem Perm.subsingleton_eq_refl [Subsingleton α] (e : Perm α) : e = Equiv.refl α :=
Subsingleton.elim _ _
protected theorem nontrivial {α β} (e : α ≃ β) [Nontrivial β] : Nontrivial α :=
e.surjective.nontrivial
theorem nontrivial_congr {α β} (e : α ≃ β) : Nontrivial α ↔ Nontrivial β :=
⟨fun _ ↦ e.symm.nontrivial, fun _ ↦ e.nontrivial⟩
/-- Transfer `DecidableEq` across an equivalence. -/
protected abbrev decidableEq (e : α ≃ β) [DecidableEq β] : DecidableEq α :=
e.injective.decidableEq
theorem nonempty_congr (e : α ≃ β) : Nonempty α ↔ Nonempty β := Nonempty.congr e e.symm
protected theorem nonempty (e : α ≃ β) [Nonempty β] : Nonempty α := e.nonempty_congr.mpr ‹_›
/-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/
protected abbrev inhabited [Inhabited β] (e : α ≃ β) : Inhabited α := ⟨e.symm default⟩
/-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/
protected abbrev unique [Unique β] (e : α ≃ β) : Unique α := e.symm.surjective.unique
/-- Equivalence between equal types. -/
protected def cast {α β : Sort _} (h : α = β) : α ≃ β where
toFun := cast h
invFun := cast h.symm
left_inv := by grind
right_inv := by grind
@[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((Equiv.mk f g l r).symm : β → α) = g := rfl
@[simp] theorem coe_refl : (Equiv.refl α : α → α) = id := rfl
/-- This cannot be a `simp` lemmas as it incorrectly matches against `e : α ≃ synonym α`, when
`synonym α` is semireducible. This makes a mess of `Multiplicative.ofAdd` etc. -/
theorem Perm.coe_subsingleton {α : Type*} [Subsingleton α] (e : Perm α) : (e : α → α) = id := by
rw [Perm.subsingleton_eq_refl e, coe_refl]
@[simp, grind =] theorem refl_apply (x : α) : Equiv.refl α x = x := rfl
@[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : (f.trans g : α → γ) = g ∘ f := rfl
@[simp, grind =] theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) :
(f.trans g) a = g (f a) := rfl
@[simp, grind =] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x := e.right_inv x
@[simp, grind =] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x := e.left_inv x
@[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply
@[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply
@[simp] lemma _root_.EquivLike.apply_coe_symm_apply {F} [EquivLike F α β] (e : F) (x : β) :
e ((e : α ≃ β).symm x) = x :=
(e : α ≃ β).apply_symm_apply x
@[simp] lemma _root_.EquivLike.coe_symm_apply_apply {F} [EquivLike F α β] (e : F) (x : α) :
(e : α ≃ β).symm (e x) = x :=
(e : α ≃ β).symm_apply_apply x
@[simp] lemma _root_.EquivLike.coe_symm_comp_self {F} [EquivLike F α β] (e : F) :
(e : α ≃ β).symm ∘ e = id :=
(e : α ≃ β).symm_comp_self
@[simp] lemma _root_.EquivLike.self_comp_coe_symm {F} [EquivLike F α β] (e : F) :
e ∘ (e : α ≃ β).symm = id :=
(e : α ≃ β).self_comp_symm
@[simp, grind =] theorem symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) :
(f.trans g).symm a = f.symm (g.symm a) := rfl
theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl
theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y := EquivLike.apply_eq_iff_eq f
theorem apply_eq_iff_eq_symm_apply {x : α} {y : β} (f : α ≃ β) : f x = y ↔ x = f.symm y := by grind
@[simp] theorem cast_apply {α β} (h : α = β) (x : α) : Equiv.cast h x = cast h x := rfl
@[simp] theorem cast_symm {α β} (h : α = β) : (Equiv.cast h).symm = Equiv.cast h.symm := rfl
@[simp] theorem cast_refl {α} (h : α = α := rfl) : Equiv.cast h = Equiv.refl α := rfl
@[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) :
(Equiv.cast h).trans (Equiv.cast h2) = Equiv.cast (h.trans h2) :=
ext fun x => by substs h h2; rfl
theorem cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : Equiv.cast h a = b ↔ a ≍ b := by
subst h; simp
theorem symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y := by grind
theorem eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x := by grind
@[simp, grind =] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := rfl
theorem symm_bijective : Function.Bijective (Equiv.symm : (α ≃ β) → β ≃ α) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[simp] theorem trans_refl (e : α ≃ β) : e.trans (Equiv.refl β) = e := by grind
@[simp, grind =] theorem refl_symm : (Equiv.refl α).symm = Equiv.refl α := rfl
@[simp] theorem refl_trans (e : α ≃ β) : (Equiv.refl α).trans e = e := by cases e; rfl
@[simp] theorem symm_trans_self (e : α ≃ β) : e.symm.trans e = Equiv.refl β := by grind
@[simp] theorem self_trans_symm (e : α ≃ β) : e.trans e.symm = Equiv.refl α := by grind
theorem trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) :
(ab.trans bc).trans cd = ab.trans (bc.trans cd) := by grind
theorem trans_cancel_left (e : α ≃ β) (f : β ≃ γ) (g : α ≃ γ) :
e.trans f = g ↔ f = e.symm.trans g := by
grind
theorem trans_cancel_right (e : α ≃ β) (f : β ≃ γ) (g : α ≃ γ) :
e.trans f = g ↔ e = g.trans f.symm := by
grind
theorem leftInverse_symm (f : α ≃ β) : LeftInverse f.symm f := f.left_inv
theorem rightInverse_symm (f : α ≃ β) : Function.RightInverse f.symm f := f.right_inv
theorem injective_comp (e : α ≃ β) (f : β → γ) : Injective (f ∘ e) ↔ Injective f :=
EquivLike.injective_comp e f
theorem comp_injective (f : α → β) (e : β ≃ γ) : Injective (e ∘ f) ↔ Injective f :=
EquivLike.comp_injective f e
theorem surjective_comp (e : α ≃ β) (f : β → γ) : Surjective (f ∘ e) ↔ Surjective f :=
EquivLike.surjective_comp e f
theorem comp_surjective (f : α → β) (e : β ≃ γ) : Surjective (e ∘ f) ↔ Surjective f :=
EquivLike.comp_surjective f e
theorem bijective_comp (e : α ≃ β) (f : β → γ) : Bijective (f ∘ e) ↔ Bijective f :=
EquivLike.bijective_comp e f
theorem comp_bijective (f : α → β) (e : β ≃ γ) : Bijective (e ∘ f) ↔ Bijective f :=
EquivLike.comp_bijective f e
@[simp]
theorem extend_apply {f : α ≃ β} (g : α → γ) (e' : β → γ) (b : β) :
extend f g e' b = g (f.symm b) := by
rw [← f.apply_symm_apply b, f.injective.extend_apply, apply_symm_apply]
/-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ`
is equivalent to the type of equivalences `β ≃ δ`. -/
def equivCongr {δ : Sort*} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) where
toFun ac := (ab.symm.trans ac).trans cd
invFun bd := ab.trans <| bd.trans <| cd.symm
left_inv ac := by grind
right_inv ac := by grind
@[simp, grind =] theorem equivCongr_apply_apply {δ} (ab : α ≃ β) (cd : γ ≃ δ) (e : α ≃ γ) (x) :
ab.equivCongr cd e x = cd (e (ab.symm x)) := rfl
@[simp, grind =] theorem equivCongr_symm {δ} (ab : α ≃ β) (cd : γ ≃ δ) :
(ab.equivCongr cd).symm = ab.symm.equivCongr cd.symm := by ext; rfl
@[simp] theorem equivCongr_refl {α β} :
(Equiv.refl α).equivCongr (Equiv.refl β) = Equiv.refl (α ≃ β) := by grind
@[simp] theorem equivCongr_trans {δ ε ζ} (ab : α ≃ β) (de : δ ≃ ε) (bc : β ≃ γ) (ef : ε ≃ ζ) :
(ab.equivCongr de).trans (bc.equivCongr ef) = (ab.trans bc).equivCongr (de.trans ef) := by
grind
@[simp] theorem equivCongr_refl_left {α β γ} (bg : β ≃ γ) (e : α ≃ β) :
(Equiv.refl α).equivCongr bg e = e.trans bg := rfl
@[simp] theorem equivCongr_refl_right {α β} (ab e : α ≃ β) :
ab.equivCongr (Equiv.refl β) e = ab.symm.trans e := rfl
section permCongr
variable {α' β' : Type*} (e : α' ≃ β')
/-- If `α` is equivalent to `β`, then `Perm α` is equivalent to `Perm β`. -/
def permCongr : Perm α' ≃ Perm β' := equivCongr e e
theorem permCongr_def (p : Equiv.Perm α') : e.permCongr p = (e.symm.trans p).trans e := rfl
@[simp] theorem permCongr_refl : e.permCongr (Equiv.refl _) = Equiv.refl _ := by
simp [permCongr_def]
@[simp, grind =] theorem permCongr_symm : e.permCongr.symm = e.symm.permCongr := rfl
@[simp, grind =] theorem permCongr_apply (p : Equiv.Perm α') (x) :
e.permCongr p x = e (p (e.symm x)) := rfl
theorem permCongr_symm_apply (p : Equiv.Perm β') (x) :
e.permCongr.symm p x = e.symm (p (e x)) := rfl
theorem permCongr_trans (p p' : Equiv.Perm α') :
(e.permCongr p).trans (e.permCongr p') = e.permCongr (p.trans p') := by grind
end permCongr
/-- Two empty types are equivalent. -/
def equivOfIsEmpty (α β : Sort*) [IsEmpty α] [IsEmpty β] : α ≃ β :=
⟨isEmptyElim, isEmptyElim, isEmptyElim, isEmptyElim⟩
/-- If `α` is an empty type, then it is equivalent to the `Empty` type. -/
def equivEmpty (α : Sort u) [IsEmpty α] : α ≃ Empty := equivOfIsEmpty α _
/-- If `α` is an empty type, then it is equivalent to the `PEmpty` type in any universe. -/
def equivPEmpty (α : Sort v) [IsEmpty α] : α ≃ PEmpty.{u} := equivOfIsEmpty α _
/-- `α` is equivalent to an empty type iff `α` is empty. -/
def equivEmptyEquiv (α : Sort u) : α ≃ Empty ≃ IsEmpty α :=
⟨fun e => Function.isEmpty e, @equivEmpty α, fun e => ext fun x => (e x).elim, fun _ => rfl⟩
/-- The `Sort` of proofs of a false proposition is equivalent to `PEmpty`. -/
def propEquivPEmpty {p : Prop} (h : ¬p) : p ≃ PEmpty := @equivPEmpty p <| IsEmpty.prop_iff.2 h
/-- If both `α` and `β` have a unique element, then `α ≃ β`. -/
@[simps (attr := grind =)]
def ofUnique (α β : Sort _) [Unique.{u} α] [Unique.{v} β] : α ≃ β where
toFun := default
invFun := default
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- If `α` has a unique element, then it is equivalent to any `PUnit`. -/
@[simps! (attr := grind =)]
def equivPUnit (α : Sort u) [Unique α] : α ≃ PUnit.{v} := ofUnique α _
/-- The `Sort` of proofs of a true proposition is equivalent to `PUnit`. -/
def propEquivPUnit {p : Prop} (h : p) : p ≃ PUnit.{0} := @equivPUnit p <| uniqueProp h
/-- `ULift α` is equivalent to `α`. -/
@[simps (attr := grind =) -fullyApplied apply symm_apply]
protected def ulift {α : Type v} : ULift.{u} α ≃ α :=
⟨ULift.down, ULift.up, ULift.up_down, ULift.down_up.{v, u}⟩
/-- `PLift α` is equivalent to `α`. -/
@[simps (attr := grind =) -fullyApplied apply symm_apply]
protected def plift : PLift α ≃ α := ⟨PLift.down, PLift.up, PLift.up_down, PLift.down_up⟩
/-- equivalence of propositions is the same as iff -/
def ofIff {P Q : Prop} (h : P ↔ Q) : P ≃ Q := ⟨h.mp, h.mpr, fun _ => rfl, fun _ => rfl⟩
/-- If `α₁` is equivalent to `α₂` and `β₁` is equivalent to `β₂`, then the type of maps `α₁ → β₁`
is equivalent to the type of maps `α₂ → β₂`. -/
@[simps (attr := grind =) apply]
def arrowCongr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) where
toFun f := e₂ ∘ f ∘ e₁.symm
invFun f := e₂.symm ∘ f ∘ e₁
left_inv f := by grind
right_inv f := by grind
theorem arrowCongr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂)
(f : α₁ → β₁) (g : β₁ → γ₁) :
arrowCongr ea ec (g ∘ f) = arrowCongr eb ec g ∘ arrowCongr ea eb f := by grind
@[simp] theorem arrowCongr_refl {α β : Sort*} :
arrowCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α → β) := rfl
@[simp] theorem arrowCongr_trans {α₁ α₂ α₃ β₁ β₂ β₃ : Sort*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrowCongr (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr e₁ e₁').trans (arrowCongr e₂ e₂') := rfl
@[simp, grind =] theorem arrowCongr_symm {α₁ α₂ β₁ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrowCongr e₁ e₂).symm = arrowCongr e₁.symm e₂.symm := rfl
/-- A version of `Equiv.arrowCongr` in `Type`, rather than `Sort`.
The `equiv_rw` tactic is not able to use the default `Sort` level `Equiv.arrowCongr`,
because Lean's universe rules will not unify `?l_1` with `imax (1 ?m_1)`.
-/
@[simps! (attr := grind =) apply]
def arrowCongr' {α₁ β₁ α₂ β₂ : Type*} (hα : α₁ ≃ α₂) (hβ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) :=
Equiv.arrowCongr hα hβ
@[simp] theorem arrowCongr'_refl {α β : Type*} :
arrowCongr' (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α → β) := rfl
@[simp] theorem arrowCongr'_trans {α₁ α₂ β₁ β₂ α₃ β₃ : Type*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrowCongr' (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr' e₁ e₁').trans (arrowCongr' e₂ e₂') :=
rfl
@[simp, grind =] theorem arrowCongr'_symm {α₁ α₂ β₁ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrowCongr' e₁ e₂).symm = arrowCongr' e₁.symm e₂.symm := rfl
/-- Conjugate a map `f : α → α` by an equivalence `α ≃ β`. -/
@[simps! (attr := grind =) apply] def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrowCongr e e
@[simp] theorem conj_refl : conj (Equiv.refl α) = Equiv.refl (α → α) := rfl
@[simp, grind =] theorem conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl
@[simp] theorem conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) :
(e₁.trans e₂).conj = e₁.conj.trans e₂.conj := rfl
-- This should not be a simp lemma as long as `(∘)` is reducible:
-- when `(∘)` is reducible, Lean can unify `f₁ ∘ f₂` with any `g` using
-- `f₁ := g` and `f₂ := fun x ↦ x`. This causes nontermination.
theorem conj_comp (e : α ≃ β) (f₁ f₂ : α → α) : e.conj (f₁ ∘ f₂) = e.conj f₁ ∘ e.conj f₂ := by
apply arrowCongr_comp
theorem eq_comp_symm {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : f = g ∘ e.symm ↔ f ∘ e = g :=
(e.arrowCongr (Equiv.refl γ)).symm_apply_eq.symm
theorem comp_symm_eq {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : g ∘ e.symm = f ↔ g = f ∘ e :=
(e.arrowCongr (Equiv.refl γ)).eq_symm_apply.symm
theorem eq_symm_comp {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : f = e.symm ∘ g ↔ e ∘ f = g :=
((Equiv.refl γ).arrowCongr e).eq_symm_apply
theorem symm_comp_eq {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : e.symm ∘ g = f ↔ g = e ∘ f :=
((Equiv.refl γ).arrowCongr e).symm_apply_eq
theorem trans_eq_refl_iff_eq_symm {f : α ≃ β} {g : β ≃ α} :
f.trans g = Equiv.refl α ↔ f = g.symm := by
rw [← Equiv.coe_inj, coe_trans, coe_refl, ← eq_symm_comp, comp_id, Equiv.coe_inj]
theorem trans_eq_refl_iff_symm_eq {f : α ≃ β} {g : β ≃ α} :
f.trans g = Equiv.refl α ↔ f.symm = g := by
rw [trans_eq_refl_iff_eq_symm]
exact ⟨fun h ↦ h ▸ rfl, fun h ↦ h ▸ rfl⟩
theorem eq_symm_iff_trans_eq_refl {f : α ≃ β} {g : β ≃ α} :
f = g.symm ↔ f.trans g = Equiv.refl α :=
trans_eq_refl_iff_eq_symm.symm
theorem symm_eq_iff_trans_eq_refl {f : α ≃ β} {g : β ≃ α} :
f.symm = g ↔ f.trans g = Equiv.refl α :=
trans_eq_refl_iff_symm_eq.symm
/-- `PUnit` sorts in any two universes are equivalent. -/
def punitEquivPUnit : PUnit.{v} ≃ PUnit.{w} where
toFun _ := .unit
invFun _ := .unit
/-- `Prop` is noncomputably equivalent to `Bool`. -/
noncomputable def propEquivBool : Prop ≃ Bool where
toFun p := @decide p (Classical.propDecidable _)
invFun b := b
left_inv p := by simp
right_inv b := by simp
section
/-- The sort of maps to `PUnit.{v}` is equivalent to `PUnit.{w}`. -/
def arrowPUnitEquivPUnit (α : Sort*) : (α → PUnit.{v}) ≃ PUnit.{w} where
toFun _ := .unit
invFun _ _ := .unit
/-- The equivalence `(∀ i, β i) ≃ β ⋆` when the domain of `β` only contains `⋆` -/
@[simps (attr := grind =) -fullyApplied]
def piUnique [Unique α] (β : α → Sort*) : (∀ i, β i) ≃ β default where
toFun f := f default
invFun := uniqueElim
left_inv f := by ext i; cases Unique.eq_default i; rfl
/-- If `α` has a unique term, then the type of function `α → β` is equivalent to `β`. -/
@[simps! (attr := grind =) -fullyApplied apply symm_apply]
def funUnique (α β) [Unique.{u} α] : (α → β) ≃ β := piUnique _
/-- The sort of maps from `PUnit` is equivalent to the codomain. -/
def punitArrowEquiv (α : Sort*) : (PUnit.{u} → α) ≃ α := funUnique PUnit.{u} α
/-- The sort of maps from `True` is equivalent to the codomain. -/
def trueArrowEquiv (α : Sort*) : (True → α) ≃ α := funUnique _ _
/-- The sort of maps from a type that `IsEmpty` is equivalent to `PUnit`. -/
def arrowPUnitOfIsEmpty (α β : Sort*) [IsEmpty α] : (α → β) ≃ PUnit.{u} where
toFun _ := PUnit.unit
invFun _ := isEmptyElim
left_inv _ := funext isEmptyElim
/-- The sort of maps from `Empty` is equivalent to `PUnit`. -/
def emptyArrowEquivPUnit (α : Sort*) : (Empty → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _
/-- The sort of maps from `PEmpty` is equivalent to `PUnit`. -/
def pemptyArrowEquivPUnit (α : Sort*) : (PEmpty → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _
/-- The sort of maps from `False` is equivalent to `PUnit`. -/
def falseArrowEquivPUnit (α : Sort*) : (False → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _
end
section
/-- A `PSigma`-type is equivalent to the corresponding `Sigma`-type. -/
@[simps (attr := grind =) apply symm_apply]
def psigmaEquivSigma {α} (β : α → Type*) : (Σ' i, β i) ≃ Σ i, β i where
toFun a := ⟨a.1, a.2⟩
invFun a := ⟨a.1, a.2⟩
/-- A `PSigma`-type is equivalent to the corresponding `Sigma`-type. -/
@[simps (attr := grind =) apply symm_apply]
def psigmaEquivSigmaPLift {α} (β : α → Sort*) : (Σ' i, β i) ≃ Σ i : PLift α, PLift (β i.down) where
toFun a := ⟨PLift.up a.1, PLift.up a.2⟩
invFun a := ⟨a.1.down, a.2.down⟩
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ' a, β₁ a` and
`Σ' a, β₂ a`. -/
@[simps (attr := grind =) apply]
def psigmaCongrRight {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (Σ' a, β₁ a) ≃ Σ' a, β₂ a where
toFun a := ⟨a.1, F a.1 a.2⟩
invFun a := ⟨a.1, (F a.1).symm a.2⟩
left_inv := by grind
right_inv := by grind
theorem psigmaCongrRight_trans {α} {β₁ β₂ β₃ : α → Sort*}
(F : ∀ a, β₁ a ≃ β₂ a) (G : ∀ a, β₂ a ≃ β₃ a) :
(psigmaCongrRight F).trans (psigmaCongrRight G) =
psigmaCongrRight fun a => (F a).trans (G a) := rfl
@[grind =]
theorem psigmaCongrRight_symm {α} {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) :
(psigmaCongrRight F).symm = psigmaCongrRight fun a => (F a).symm := rfl
@[simp]
theorem psigmaCongrRight_refl {α} {β : α → Sort*} :
(psigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ' a, β a) := rfl
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ a, β₁ a` and
`Σ a, β₂ a`. -/
@[simps (attr := grind =) apply]
def sigmaCongrRight {α} {β₁ β₂ : α → Type*} (F : ∀ a, β₁ a ≃ β₂ a) : (Σ a, β₁ a) ≃ Σ a, β₂ a where
toFun a := ⟨a.1, F a.1 a.2⟩
invFun a := ⟨a.1, (F a.1).symm a.2⟩
left_inv := by grind
right_inv := by grind
theorem sigmaCongrRight_trans {α} {β₁ β₂ β₃ : α → Type*}
(F : ∀ a, β₁ a ≃ β₂ a) (G : ∀ a, β₂ a ≃ β₃ a) :
(sigmaCongrRight F).trans (sigmaCongrRight G) =
sigmaCongrRight fun a => (F a).trans (G a) := rfl
@[grind =]
theorem sigmaCongrRight_symm {α} {β₁ β₂ : α → Type*} (F : ∀ a, β₁ a ≃ β₂ a) :
(sigmaCongrRight F).symm = sigmaCongrRight fun a => (F a).symm := rfl
@[simp]
theorem sigmaCongrRight_refl {α} {β : α → Type*} :
(sigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ a, β a) := rfl
/-- A `PSigma` with `Prop` fibers is equivalent to the subtype. -/
def psigmaEquivSubtype {α : Type v} (P : α → Prop) : (Σ' i, P i) ≃ Subtype P where
toFun x := ⟨x.1, x.2⟩
invFun x := ⟨x.1, x.2⟩
/-- A `Sigma` with `PLift` fibers is equivalent to the subtype. -/
def sigmaPLiftEquivSubtype {α : Type v} (P : α → Prop) : (Σ i, PLift (P i)) ≃ Subtype P :=
((psigmaEquivSigma _).symm.trans
(psigmaCongrRight fun _ => Equiv.plift)).trans (psigmaEquivSubtype P)
/-- A `Sigma` with `fun i ↦ ULift (PLift (P i))` fibers is equivalent to `{ x // P x }`.
Variant of `sigmaPLiftEquivSubtype`.
-/
def sigmaULiftPLiftEquivSubtype {α : Type v} (P : α → Prop) :
(Σ i, ULift (PLift (P i))) ≃ Subtype P :=
(sigmaCongrRight fun _ => Equiv.ulift).trans (sigmaPLiftEquivSubtype P)
namespace Perm
/-- A family of permutations `Π a, Perm (β a)` generates a permutation `Perm (Σ a, β₁ a)`. -/
abbrev sigmaCongrRight {α} {β : α → Sort _} (F : ∀ a, Perm (β a)) : Perm (Σ a, β a) :=
Equiv.sigmaCongrRight F
@[simp] theorem sigmaCongrRight_trans {α} {β : α → Sort _}
(F : ∀ a, Perm (β a)) (G : ∀ a, Perm (β a)) :
(sigmaCongrRight F).trans (sigmaCongrRight G) = sigmaCongrRight fun a => (F a).trans (G a) :=
rfl
@[simp] theorem sigmaCongrRight_symm {α} {β : α → Sort _} (F : ∀ a, Perm (β a)) :
(sigmaCongrRight F).symm = sigmaCongrRight fun a => (F a).symm :=
rfl
@[simp] theorem sigmaCongrRight_refl {α} {β : α → Sort _} :
(sigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ a, β a) :=
rfl
end Perm
/-- `Function.swap` as an equivalence. -/
@[simps (attr := grind =) -fullyApplied]
def functionSwap (α β : Sort*) (γ : α → β → Sort*) :
((a : α) → (b : β) → γ a b) ≃ ((b : β) → (a : α) → γ a b) where
toFun := Function.swap
invFun := Function.swap
theorem _root_.Function.swap_bijective {α β : Sort*} {γ : α → β → Sort*} :
Function.Bijective (@Function.swap _ _ γ) :=
functionSwap _ _ _ |>.bijective
/-- An equivalence `f : α₁ ≃ α₂` generates an equivalence between `Σ a, β (f a)` and `Σ a, β a`. -/
@[simps (attr := grind =) apply]
def sigmaCongrLeft {α₁ α₂ : Type*} {β : α₂ → Sort _} (e : α₁ ≃ α₂) :
(Σ a : α₁, β (e a)) ≃ Σ a : α₂, β a where
toFun a := ⟨e a.1, a.2⟩
invFun a := ⟨e.symm a.1, (e.right_inv' a.1).symm ▸ a.2⟩
left_inv := fun ⟨a, b⟩ => by simp
right_inv := fun ⟨a, b⟩ => by simp
/-- Transporting a sigma type through an equivalence of the base -/
def sigmaCongrLeft' {α₁ α₂} {β : α₁ → Sort _} (f : α₁ ≃ α₂) :
(Σ a : α₁, β a) ≃ Σ a : α₂, β (f.symm a) := (sigmaCongrLeft f.symm).symm
/-- Transporting a sigma type through an equivalence of the base and a family of equivalences
of matching fibers -/
def sigmaCongr {α₁ α₂} {β₁ : α₁ → Sort _} {β₂ : α₂ → Sort _} (f : α₁ ≃ α₂)
(F : ∀ a, β₁ a ≃ β₂ (f a)) : Sigma β₁ ≃ Sigma β₂ :=
(sigmaCongrRight F).trans (sigmaCongrLeft f)
/-- `Sigma` type with a constant fiber is equivalent to the product. -/
@[simps (attr := mfld_simps, grind =) apply symm_apply]
def sigmaEquivProd (α β : Type*) : (Σ _ : α, β) ≃ α × β where
toFun a := ⟨a.1, a.2⟩
invFun a := ⟨a.1, a.2⟩
/-- If each fiber of a `Sigma` type is equivalent to a fixed type, then the sigma type
is equivalent to the product. -/
def sigmaEquivProdOfEquiv {α β} {β₁ : α → Sort _} (F : ∀ a, β₁ a ≃ β) : Sigma β₁ ≃ α × β :=
(sigmaCongrRight F).trans (sigmaEquivProd α β)
/-- The dependent product of types is associative up to an equivalence. -/
def sigmaAssoc {α : Type*} {β : α → Type*} (γ : ∀ a : α, β a → Type*) :
(Σ ab : Σ a : α, β a, γ ab.1 ab.2) ≃ Σ a : α, Σ b : β a, γ a b where
toFun x := ⟨x.1.1, ⟨x.1.2, x.2⟩⟩
invFun x := ⟨⟨x.1, x.2.1⟩, x.2.2⟩
/-- The dependent product of sorts is associative up to an equivalence. -/
def pSigmaAssoc {α : Sort*} {β : α → Sort*} (γ : ∀ a : α, β a → Sort*) :
(Σ' ab : Σ' a : α, β a, γ ab.1 ab.2) ≃ Σ' a : α, Σ' b : β a, γ a b where
toFun x := ⟨x.1.1, ⟨x.1.2, x.2⟩⟩
invFun x := ⟨⟨x.1, x.2.1⟩, x.2.2⟩
end
variable {p : α → Prop} {q : β → Prop} (e : α ≃ β)
protected lemma forall_congr_right : (∀ a, q (e a)) ↔ ∀ b, q b :=
⟨fun h a ↦ by simpa using h (e.symm a), fun h _ ↦ h _⟩
protected lemma forall_congr_left : (∀ a, p a) ↔ ∀ b, p (e.symm b) :=
e.symm.forall_congr_right.symm
protected lemma forall_congr (h : ∀ a, p a ↔ q (e a)) : (∀ a, p a) ↔ ∀ b, q b :=
e.forall_congr_left.trans (by simp [h])
protected lemma forall_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∀ a, p a) ↔ ∀ b, q b :=
e.forall_congr_left.trans (by simp [h])
protected lemma exists_congr_right : (∃ a, q (e a)) ↔ ∃ b, q b :=
⟨fun ⟨_, h⟩ ↦ ⟨_, h⟩, fun ⟨a, h⟩ ↦ ⟨e.symm a, by simpa using h⟩⟩
protected lemma exists_congr_left : (∃ a, p a) ↔ ∃ b, p (e.symm b) :=
e.symm.exists_congr_right.symm
protected lemma exists_congr (h : ∀ a, p a ↔ q (e a)) : (∃ a, p a) ↔ ∃ b, q b :=
e.exists_congr_left.trans <| by simp [h]
protected lemma exists_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∃ a, p a) ↔ ∃ b, q b :=
e.exists_congr_left.trans <| by simp [h]
protected lemma exists_subtype_congr (e : {a // p a} ≃ {b // q b}) : (∃ a, p a) ↔ ∃ b, q b := by
simp [← nonempty_subtype, nonempty_congr e]
protected lemma existsUnique_congr_right : (∃! a, q (e a)) ↔ ∃! b, q b :=
e.exists_congr <| by simpa using fun _ _ ↦ e.forall_congr (by simp)
protected lemma existsUnique_congr_left : (∃! a, p a) ↔ ∃! b, p (e.symm b) :=
e.symm.existsUnique_congr_right.symm
protected lemma existsUnique_congr (h : ∀ a, p a ↔ q (e a)) : (∃! a, p a) ↔ ∃! b, q b :=
e.existsUnique_congr_left.trans <| by simp [h]
protected lemma existsUnique_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∃! a, p a) ↔ ∃! b, q b :=
e.existsUnique_congr_left.trans <| by simp [h]
protected lemma existsUnique_subtype_congr (e : {a // p a} ≃ {b // q b}) :
(∃! a, p a) ↔ ∃! b, q b := by
simp [← unique_subtype_iff_existsUnique, unique_iff_subsingleton_and_nonempty,
nonempty_congr e, subsingleton_congr e]
-- We next build some higher arity versions of `Equiv.forall_congr`.
-- Although they appear to just be repeated applications of `Equiv.forall_congr`,
-- unification of metavariables works better with these versions.
-- In particular, they are necessary in `equiv_rw`.
-- (Stopping at ternary functions seems reasonable: at least in 1-categorical mathematics,
-- it's rare to have axioms involving more than 3 elements at once.)
protected theorem forall₂_congr {α₁ α₂ β₁ β₂ : Sort*} {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀ {x y}, p x y ↔ q (eα x) (eβ y)) :
(∀ x y, p x y) ↔ ∀ x y, q x y :=
eα.forall_congr fun _ ↦ eβ.forall_congr <| @h _
protected theorem forall₂_congr' {α₁ α₂ β₁ β₂ : Sort*} {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀ {x y}, p (eα.symm x) (eβ.symm y) ↔ q x y) :
(∀ x y, p x y) ↔ ∀ x y, q x y := (Equiv.forall₂_congr eα.symm eβ.symm h.symm).symm
protected theorem forall₃_congr
{α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*} {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂) (h : ∀ {x y z}, p x y z ↔ q (eα x) (eβ y) (eγ z)) :
(∀ x y z, p x y z) ↔ ∀ x y z, q x y z :=
Equiv.forall₂_congr _ _ <| Equiv.forall_congr _ <| @h _ _
protected theorem forall₃_congr'
{α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*} {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂)
(h : ∀ {x y z}, p (eα.symm x) (eβ.symm y) (eγ.symm z) ↔ q x y z) :
(∀ x y z, p x y z) ↔ ∀ x y z, q x y z :=
(Equiv.forall₃_congr eα.symm eβ.symm eγ.symm h.symm).symm
/-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/
@[simps (attr := grind =) apply]
noncomputable def ofBijective (f : α → β) (hf : Bijective f) : α ≃ β where
toFun := f
invFun := surjInv hf.surjective
left_inv := leftInverse_surjInv hf
right_inv := rightInverse_surjInv _
lemma ofBijective_apply_symm_apply (f : α → β) (hf : Bijective f) (x : β) :
f ((ofBijective f hf).symm x) = x :=
(ofBijective f hf).apply_symm_apply x
@[simp]
lemma ofBijective_symm_apply_apply (f : α → β) (hf : Bijective f) (x : α) :
(ofBijective f hf).symm (f x) = x :=
(ofBijective f hf).symm_apply_apply x
end Equiv
namespace Quot
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂)`. -/
protected def congr {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β)
(eq : ∀ a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) : Quot ra ≃ Quot rb where
toFun := Quot.map e fun a₁ a₂ => (eq a₁ a₂).1
invFun := Quot.map e.symm fun b₁ b₂ h =>
(eq (e.symm b₁) (e.symm b₂)).2
((e.apply_symm_apply b₁).symm ▸ (e.apply_symm_apply b₂).symm ▸ h)
left_inv := by rintro ⟨a⟩; simp only [Quot.map, Equiv.symm_apply_apply]
right_inv := by rintro ⟨a⟩; simp only [Quot.map, Equiv.apply_symm_apply]
@[simp] theorem congr_mk {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β)
(eq : ∀ a₁ a₂ : α, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) :
Quot.congr e eq (Quot.mk ra a) = Quot.mk rb (e a) := rfl
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congrRight {r r' : α → α → Prop} (eq : ∀ a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) :
Quot r ≃ Quot r' := Quot.congr (Equiv.refl α) eq
/-- An equivalence `e : α ≃ β` generates an equivalence between the quotient space of `α`
by a relation `ra` and the quotient space of `β` by the image of this relation under `e`. -/
protected def congrLeft {r : α → α → Prop} (e : α ≃ β) :
Quot r ≃ Quot fun b b' => r (e.symm b) (e.symm b') :=
Quot.congr e fun _ _ => by simp only [e.symm_apply_apply]
end Quot
namespace Quotient
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂)`. -/
protected def congr {ra : Setoid α} {rb : Setoid β} (e : α ≃ β)
(eq : ∀ a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) :
Quotient ra ≃ Quotient rb := Quot.congr e eq
@[simp] theorem congr_mk {ra : Setoid α} {rb : Setoid β} (e : α ≃ β)
(eq : ∀ a₁ a₂ : α, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) :
Quotient.congr e eq (Quotient.mk ra a) = Quotient.mk rb (e a) := rfl
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congrRight {r r' : Setoid α}
(eq : ∀ a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) : Quotient r ≃ Quotient r' :=
Quot.congrRight eq
end Quotient
/-- Equivalence between `Fin 0` and `Empty`. -/
def finZeroEquiv : Fin 0 ≃ Empty := .equivEmpty _
/-- Equivalence between `Fin 0` and `PEmpty`. -/
def finZeroEquiv' : Fin 0 ≃ PEmpty.{u} := .equivPEmpty _
/-- Equivalence between `Fin 1` and `Unit`. -/
def finOneEquiv : Fin 1 ≃ Unit := .equivPUnit _
/-- Equivalence between `Fin 2` and `Bool`. -/
def finTwoEquiv : Fin 2 ≃ Bool where
toFun i := i == 1
invFun b := bif b then 1 else 0
left_inv i := by grind
right_inv b := by grind
namespace Equiv
variable {α β : Type*}
/-- The left summand of `α ⊕ β` is equivalent to `α`. -/
@[simps (attr := grind =)]
def sumIsLeft : {x : α ⊕ β // x.isLeft} ≃ α where
toFun x := x.1.getLeft x.2
invFun a := ⟨.inl a, Sum.isLeft_inl⟩
left_inv | ⟨.inl _a, _⟩ => rfl
/-- The right summand of `α ⊕ β` is equivalent to `β`. -/
@[simps (attr := grind =)]
def sumIsRight : {x : α ⊕ β // x.isRight} ≃ β where
toFun x := x.1.getRight x.2
invFun b := ⟨.inr b, Sum.isRight_inr⟩
left_inv | ⟨.inr _b, _⟩ => rfl
end Equiv |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Set.lean | import Mathlib.Data.Set.Function
import Mathlib.Logic.Equiv.Defs
import Mathlib.Tactic.Says
/-!
# Equivalences and sets
In this file we provide lemmas linking equivalences to sets.
Some notable definitions are:
* `Equiv.ofInjective`: an injective function is (noncomputably) equivalent to its range.
* `Equiv.setCongr`: two equal sets are equivalent as types.
* `Equiv.Set.union`: a disjoint union of sets is equivalent to their `Sum`.
This file is separate from `Equiv/Basic` such that we do not require the full lattice structure
on sets before defining what an equivalence is.
-/
open Function Set
universe u v w z
variable {α : Sort u} {β : Sort v} {γ : Sort w}
namespace EquivLike
@[simp]
theorem range_eq_univ {α : Type*} {β : Type*} {E : Type*} [EquivLike E α β] (e : E) :
range e = univ :=
eq_univ_of_forall (EquivLike.toEquiv e).surjective
end EquivLike
namespace Equiv
variable {α β : Type*}
theorem range_eq_univ (e : α ≃ β) : range e = univ := EquivLike.range_eq_univ e
lemma image_symm_eq_preimage (e : α ≃ β) (s : Set β) : e.symm '' s = e ⁻¹' s := by
ext; exact mem_image_iff_of_inverse e.right_inv e.left_inv
lemma image_eq_preimage_symm (e : α ≃ β) (s : Set α) : e '' s = e.symm ⁻¹' s :=
e.symm.image_symm_eq_preimage _
@[deprecated (since := "2025-11-05")]
protected alias image_eq_preimage := image_eq_preimage_symm
@[simp 1001]
theorem _root_.Set.mem_image_equiv {α β} {S : Set α} {f : α ≃ β} {x : β} :
x ∈ f '' S ↔ f.symm x ∈ S :=
Set.ext_iff.mp (image_eq_preimage_symm ..) x
@[deprecated image_eq_preimage_symm (since := "2025-10-31")]
theorem _root_.Set.image_equiv_eq_preimage_symm {α β} (S : Set α) (f : α ≃ β) :
f '' S = f.symm ⁻¹' S := image_eq_preimage_symm ..
@[deprecated Equiv.image_symm_eq_preimage (since := "2025-10-31")]
theorem _root_.Set.preimage_equiv_eq_image_symm {α β} (S : Set α) (f : β ≃ α) :
f ⁻¹' S = f.symm '' S := (f.image_symm_eq_preimage S).symm
-- Increased priority so this fires before `image_subset_iff`
@[simp high]
protected theorem symm_image_subset {α β} (e : α ≃ β) (s : Set α) (t : Set β) :
e.symm '' t ⊆ s ↔ t ⊆ e '' s := by rw [image_subset_iff, image_eq_preimage_symm]
-- Increased priority so this fires before `image_subset_iff`
@[simp high]
protected theorem subset_symm_image {α β} (e : α ≃ β) (s : Set α) (t : Set β) :
s ⊆ e.symm '' t ↔ e '' s ⊆ t :=
calc
s ⊆ e.symm '' t ↔ e.symm.symm '' s ⊆ t := by rw [e.symm.symm_image_subset]
_ ↔ e '' s ⊆ t := by rw [e.symm_symm]
@[simp]
theorem symm_image_image {α β} (e : α ≃ β) (s : Set α) : e.symm '' (e '' s) = s :=
e.leftInverse_symm.image_image s
theorem eq_image_iff_symm_image_eq {α β} (e : α ≃ β) (s : Set α) (t : Set β) :
t = e '' s ↔ e.symm '' t = s :=
(e.symm.injective.image_injective.eq_iff' (e.symm_image_image s)).symm
@[simp]
theorem image_symm_image {α β} (e : α ≃ β) (s : Set β) : e '' (e.symm '' s) = s :=
e.symm.symm_image_image s
@[simp]
theorem image_preimage {α β} (e : α ≃ β) (s : Set β) : e '' (e ⁻¹' s) = s :=
e.surjective.image_preimage s
@[simp]
theorem preimage_image {α β} (e : α ≃ β) (s : Set α) : e ⁻¹' (e '' s) = s :=
e.injective.preimage_image s
protected theorem image_compl {α β} (f : Equiv α β) (s : Set α) : f '' sᶜ = (f '' s)ᶜ :=
image_compl_eq f.bijective
@[simp]
theorem symm_preimage_preimage {α β} (e : α ≃ β) (s : Set β) : e.symm ⁻¹' (e ⁻¹' s) = s :=
e.rightInverse_symm.preimage_preimage s
@[simp]
theorem preimage_symm_preimage {α β} (e : α ≃ β) (s : Set α) : e ⁻¹' (e.symm ⁻¹' s) = s :=
e.leftInverse_symm.preimage_preimage s
theorem preimage_subset {α β} (e : α ≃ β) (s t : Set β) : e ⁻¹' s ⊆ e ⁻¹' t ↔ s ⊆ t :=
e.surjective.preimage_subset_preimage_iff
theorem image_subset {α β} (e : α ≃ β) (s t : Set α) : e '' s ⊆ e '' t ↔ s ⊆ t :=
image_subset_image_iff e.injective
@[simp]
theorem image_eq_iff_eq {α β} (e : α ≃ β) (s t : Set α) : e '' s = e '' t ↔ s = t :=
image_eq_image e.injective
theorem preimage_eq_iff_eq_image {α β} (e : α ≃ β) (s t) : e ⁻¹' s = t ↔ s = e '' t :=
Set.preimage_eq_iff_eq_image e.bijective
theorem eq_preimage_iff_image_eq {α β} (e : α ≃ β) (s t) : s = e ⁻¹' t ↔ e '' s = t :=
Set.eq_preimage_iff_image_eq e.bijective
lemma setOf_apply_symm_eq_image_setOf {α β} (e : α ≃ β) (p : α → Prop) :
{b | p (e.symm b)} = e '' {a | p a} := by
rw [Equiv.image_eq_preimage_symm, preimage_setOf_eq]
@[simp]
theorem prod_assoc_preimage {α β γ} {s : Set α} {t : Set β} {u : Set γ} :
Equiv.prodAssoc α β γ ⁻¹' s ×ˢ t ×ˢ u = (s ×ˢ t) ×ˢ u := by
ext
simp [and_assoc]
@[simp]
theorem prod_assoc_symm_preimage {α β γ} {s : Set α} {t : Set β} {u : Set γ} :
(Equiv.prodAssoc α β γ).symm ⁻¹' (s ×ˢ t) ×ˢ u = s ×ˢ t ×ˢ u := by
ext
simp [and_assoc]
-- `@[simp]` doesn't like these lemmas, as it uses `Set.image_congr'` to turn `Equiv.prodAssoc`
-- into a lambda expression and then unfold it.
theorem prod_assoc_image {α β γ} {s : Set α} {t : Set β} {u : Set γ} :
Equiv.prodAssoc α β γ '' (s ×ˢ t) ×ˢ u = s ×ˢ t ×ˢ u := by
simpa only [Equiv.image_eq_preimage_symm] using prod_assoc_symm_preimage
theorem prod_assoc_symm_image {α β γ} {s : Set α} {t : Set β} {u : Set γ} :
(Equiv.prodAssoc α β γ).symm '' s ×ˢ t ×ˢ u = (s ×ˢ t) ×ˢ u := by
simpa only [Equiv.image_eq_preimage_symm] using prod_assoc_preimage
/-- A set `s` in `α × β` is equivalent to the sigma-type `Σ x, {y | (x, y) ∈ s}`. -/
def setProdEquivSigma {α β : Type*} (s : Set (α × β)) :
s ≃ Σ x : α, { y : β | (x, y) ∈ s } where
toFun x := ⟨x.1.1, x.1.2, by simp⟩
invFun x := ⟨(x.1, x.2.1), x.2.2⟩
/-- The subtypes corresponding to equal sets are equivalent. -/
@[simps! apply symm_apply]
def setCongr {α : Type*} {s t : Set α} (h : s = t) : s ≃ t :=
subtypeEquivProp h
-- We could construct this using `Equiv.Set.image e s e.injective`,
-- but this definition provides an explicit inverse.
/-- A set is equivalent to its image under an equivalence.
-/
@[simps]
def image {α β : Type*} (e : α ≃ β) (s : Set α) :
s ≃ e '' s where
toFun x := ⟨e x.1, by simp⟩
invFun y :=
⟨e.symm y.1, by
rcases y with ⟨-, ⟨a, ⟨m, rfl⟩⟩⟩
simpa using m⟩
left_inv x := by simp
right_inv y := by simp
section order
variable {α β : Type*} [Preorder α] [Preorder β] {e : α ≃ β} (s : Set α)
lemma image_monotone (hs : Monotone e) : Monotone (e.image s) :=
hs.comp (Subtype.mono_coe _)
lemma image_antitone (hs : Antitone e) : Antitone (e.image s) :=
hs.comp_monotone (Subtype.mono_coe _)
lemma image_strictMono (hs : StrictMono e) : StrictMono (e.image s) :=
hs.comp (Subtype.strictMono_coe _)
lemma image_strictAnti (hs : StrictAnti e) : StrictAnti (e.image s) :=
hs.comp_strictMono (Subtype.strictMono_coe _)
end order
namespace Set
/-- `univ α` is equivalent to `α`. -/
@[simps apply symm_apply]
protected def univ (α) : @univ α ≃ α :=
⟨Subtype.val, fun a => ⟨a, trivial⟩, fun ⟨_, _⟩ => rfl, fun _ => rfl⟩
/-- An empty set is equivalent to the `Empty` type. -/
protected def empty (α) : (∅ : Set α) ≃ Empty :=
equivEmpty _
/-- An empty set is equivalent to a `PEmpty` type. -/
protected def pempty (α) : (∅ : Set α) ≃ PEmpty :=
equivPEmpty _
/-- If sets `s` and `t` are separated by a decidable predicate, then `s ∪ t` is equivalent to
`s ⊕ t`. -/
protected def union' {α} {s t : Set α} (p : α → Prop) [DecidablePred p] (hs : ∀ x ∈ s, p x)
(ht : ∀ x ∈ t, ¬p x) : (s ∪ t : Set α) ≃ s ⊕ t where
toFun x :=
if hp : p x then Sum.inl ⟨_, x.2.resolve_right fun xt => ht _ xt hp⟩
else Sum.inr ⟨_, x.2.resolve_left fun xs => hp (hs _ xs)⟩
invFun o :=
match o with
| Sum.inl x => ⟨x, Or.inl x.2⟩
| Sum.inr x => ⟨x, Or.inr x.2⟩
left_inv := fun ⟨x, h'⟩ => by by_cases h : p x <;> simp [h]
right_inv o := by
rcases o with (⟨x, h⟩ | ⟨x, h⟩) <;> [simp [hs _ h]; simp [ht _ h]]
/-- If sets `s` and `t` are disjoint, then `s ∪ t` is equivalent to `s ⊕ t`. -/
protected def union {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : Disjoint s t) :
(s ∪ t : Set α) ≃ s ⊕ t :=
Set.union' (fun x => x ∈ s) (fun _ => id) fun _ xt xs => Set.disjoint_left.mp H xs xt
theorem union_apply_left {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : Disjoint s t)
{a : (s ∪ t : Set α)} (ha : ↑a ∈ s) : Equiv.Set.union H a = Sum.inl ⟨a, ha⟩ :=
dif_pos ha
theorem union_apply_right {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : Disjoint s t)
{a : (s ∪ t : Set α)} (ha : ↑a ∈ t) : Equiv.Set.union H a = Sum.inr ⟨a, ha⟩ :=
dif_neg fun h => Set.disjoint_left.mp H h ha
@[simp]
theorem union_symm_apply_left {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : Disjoint s t)
(a : s) : (Equiv.Set.union H).symm (Sum.inl a) = ⟨a, by simp⟩ :=
rfl
@[simp]
theorem union_symm_apply_right {α} {s t : Set α} [DecidablePred fun x => x ∈ s] (H : Disjoint s t)
(a : t) : (Equiv.Set.union H).symm (Sum.inr a) = ⟨a, by simp⟩ :=
rfl
/-- A singleton set is equivalent to a `PUnit` type. -/
protected def singleton {α} (a : α) : ({a} : Set α) ≃ PUnit.{u} :=
⟨fun _ => PUnit.unit, fun _ => ⟨a, mem_singleton _⟩, fun ⟨x, h⟩ => by
subst x
rfl, fun ⟨⟩ => rfl⟩
lemma Equiv.strictMono_setCongr {α : Type*} [Preorder α] {S T : Set α} (h : S = T) :
StrictMono (setCongr h) := fun _ _ ↦ id
/-- If `a ∉ s`, then `insert a s` is equivalent to `s ⊕ PUnit`. -/
protected def insert {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s) :
(insert a s : Set α) ≃ s ⊕ PUnit.{u + 1} :=
calc
(insert a s : Set α) ≃ ↥(s ∪ {a}) := Equiv.setCongr (by simp)
_ ≃ s ⊕ ({a} : Set α) := Equiv.Set.union <| by simpa
_ ≃ s ⊕ PUnit.{u + 1} := sumCongr (Equiv.refl _) (Equiv.Set.singleton _)
@[simp]
theorem insert_symm_apply_inl {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s)
(b : s) : (Equiv.Set.insert H).symm (Sum.inl b) = ⟨b, Or.inr b.2⟩ :=
rfl
@[simp]
theorem insert_symm_apply_inr {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s)
(b : PUnit.{u + 1}) : (Equiv.Set.insert H).symm (Sum.inr b) = ⟨a, Or.inl rfl⟩ :=
rfl
@[simp]
theorem insert_apply_left {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s) :
Equiv.Set.insert H ⟨a, Or.inl rfl⟩ = Sum.inr PUnit.unit :=
(Equiv.Set.insert H).apply_eq_iff_eq_symm_apply.2 rfl
@[simp]
theorem insert_apply_right {α} {s : Set.{u} α} [DecidablePred (· ∈ s)] {a : α} (H : a ∉ s) (b : s) :
Equiv.Set.insert H ⟨b, Or.inr b.2⟩ = Sum.inl b :=
(Equiv.Set.insert H).apply_eq_iff_eq_symm_apply.2 rfl
/-- If `s : Set α` is a set with decidable membership, then `s ⊕ sᶜ` is equivalent to `α`.
See also `Equiv.sumCompl`. -/
protected def sumCompl {α} (s : Set α) [DecidablePred (· ∈ s)] : s ⊕ (sᶜ : Set α) ≃ α :=
Equiv.sumCompl (· ∈ s)
@[simp]
theorem sumCompl_apply_inl {α : Type u} (s : Set α) [DecidablePred (· ∈ s)] (x : s) :
Equiv.Set.sumCompl s (Sum.inl x) = x :=
rfl
@[simp]
theorem sumCompl_apply_inr {α : Type u} (s : Set α) [DecidablePred (· ∈ s)] (x : (sᶜ : Set α)) :
Equiv.Set.sumCompl s (Sum.inr x) = x :=
rfl
theorem sumCompl_symm_apply_of_mem {α : Type u} {s : Set α} [DecidablePred (· ∈ s)] {x : α}
(hx : x ∈ s) : (Equiv.Set.sumCompl s).symm x = Sum.inl ⟨x, hx⟩ :=
sumCompl_symm_apply_of_pos hx
theorem sumCompl_symm_apply_of_notMem {α : Type u} {s : Set α} [DecidablePred (· ∈ s)] {x : α}
(hx : x ∉ s) : (Equiv.Set.sumCompl s).symm x = Sum.inr ⟨x, hx⟩ :=
sumCompl_symm_apply_of_neg hx
@[deprecated (since := "2025-05-23")]
alias sumCompl_symm_apply_of_not_mem := sumCompl_symm_apply_of_notMem
@[simp]
theorem sumCompl_symm_apply {α : Type*} {s : Set α} [DecidablePred (· ∈ s)] (x : s) :
(Equiv.Set.sumCompl s).symm x = Sum.inl x :=
sumCompl_symm_apply_pos x
@[simp]
theorem sumCompl_symm_apply_compl {α : Type*} {s : Set α} [DecidablePred (· ∈ s)]
(x : (sᶜ : Set α)) : (Equiv.Set.sumCompl s).symm x = Sum.inr x :=
sumCompl_symm_apply_neg x
/-- `sumDiffSubset s t` is the natural equivalence between
`s ⊕ (t \ s)` and `t`, where `s` and `t` are two sets. -/
protected def sumDiffSubset {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)] :
s ⊕ (t \ s : Set α) ≃ t :=
calc
s ⊕ (t \ s : Set α) ≃ (s ∪ t \ s : Set α) :=
(Equiv.Set.union disjoint_sdiff_self_right).symm
_ ≃ t := Equiv.setCongr (by simp [union_diff_self, union_eq_self_of_subset_left h])
@[simp]
theorem sumDiffSubset_apply_inl {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)] (x : s) :
Equiv.Set.sumDiffSubset h (Sum.inl x) = inclusion h x :=
rfl
@[simp]
theorem sumDiffSubset_apply_inr {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)]
(x : (t \ s : Set α)) : Equiv.Set.sumDiffSubset h (Sum.inr x) = inclusion diff_subset x :=
rfl
theorem sumDiffSubset_symm_apply_of_mem {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)]
{x : t} (hx : x.1 ∈ s) : (Equiv.Set.sumDiffSubset h).symm x = Sum.inl ⟨x, hx⟩ := by
apply (Equiv.Set.sumDiffSubset h).injective
simp only [apply_symm_apply, sumDiffSubset_apply_inl, Set.inclusion_mk]
theorem sumDiffSubset_symm_apply_of_notMem {α} {s t : Set α} (h : s ⊆ t) [DecidablePred (· ∈ s)]
{x : t} (hx : x.1 ∉ s) : (Equiv.Set.sumDiffSubset h).symm x = Sum.inr ⟨x, ⟨x.2, hx⟩⟩ := by
apply (Equiv.Set.sumDiffSubset h).injective
simp only [apply_symm_apply, sumDiffSubset_apply_inr, Set.inclusion_mk]
@[deprecated (since := "2025-05-23")]
alias sumDiffSubset_symm_apply_of_not_mem := sumDiffSubset_symm_apply_of_notMem
/-- If `s` is a set with decidable membership, then the sum of `s ∪ t` and `s ∩ t` is equivalent
to `s ⊕ t`. -/
protected def unionSumInter {α : Type u} (s t : Set α) [DecidablePred (· ∈ s)] :
(s ∪ t : Set α) ⊕ (s ∩ t : Set α) ≃ s ⊕ t :=
calc
(s ∪ t : Set α) ⊕ (s ∩ t : Set α)
≃ (s ∪ t \ s : Set α) ⊕ (s ∩ t : Set α) := by rw [union_diff_self]
_ ≃ (s ⊕ (t \ s : Set α)) ⊕ (s ∩ t : Set α) :=
sumCongr (Set.union disjoint_sdiff_self_right) (Equiv.refl _)
_ ≃ s ⊕ ((t \ s : Set α) ⊕ (s ∩ t : Set α)) := sumAssoc _ _ _
_ ≃ s ⊕ (t \ s ∪ s ∩ t : Set α) :=
sumCongr (Equiv.refl _)
(by
refine (Set.union' (· ∉ s) ?_ ?_).symm
exacts [fun x hx => hx.2, fun x hx => not_not_intro hx.1])
_ ≃ s ⊕ t := by
{ rw [(_ : t \ s ∪ s ∩ t = t)]
rw [union_comm, inter_comm, inter_union_diff] }
/-- Given an equivalence `e₀` between sets `s : Set α` and `t : Set β`, the set of equivalences
`e : α ≃ β` such that `e ↑x = ↑(e₀ x)` for each `x : s` is equivalent to the set of equivalences
between `sᶜ` and `tᶜ`. -/
protected def compl {α : Type u} {β : Type v} {s : Set α} {t : Set β} [DecidablePred (· ∈ s)]
[DecidablePred (· ∈ t)] (e₀ : s ≃ t) :
{ e : α ≃ β // ∀ x : s, e x = e₀ x } ≃ ((sᶜ : Set α) ≃ (tᶜ : Set β)) where
toFun e :=
subtypeEquiv e fun _ =>
not_congr <|
Iff.symm <|
MapsTo.mem_iff (mapsTo_iff_exists_map_subtype.2 ⟨e₀, e.2⟩)
(SurjOn.mapsTo_compl
(surjOn_iff_exists_map_subtype.2 ⟨t, e₀, Subset.refl t, e₀.surjective, e.2⟩)
e.1.injective)
invFun e₁ :=
Subtype.mk
(calc
α ≃ s ⊕ (sᶜ : Set α) := (Set.sumCompl s).symm
_ ≃ t ⊕ (tᶜ : Set β) := e₀.sumCongr e₁
_ ≃ β := Set.sumCompl t
)
fun x => by
simp only [Sum.map_inl, trans_apply, sumCongr_apply, Set.sumCompl_apply_inl,
Set.sumCompl_symm_apply, Trans.trans]
left_inv e := by
ext x
by_cases hx : x ∈ s
· simp only [Set.sumCompl_symm_apply_of_mem hx, ← e.prop ⟨x, hx⟩, Sum.map_inl, sumCongr_apply,
trans_apply, Set.sumCompl_apply_inl, Trans.trans]
· simp only [Set.sumCompl_symm_apply_of_notMem hx, Sum.map_inr, subtypeEquiv_apply,
Set.sumCompl_apply_inr, trans_apply, sumCongr_apply, Trans.trans]
right_inv e :=
Equiv.ext fun x => by
simp only [Sum.map_inr, subtypeEquiv_apply, Set.sumCompl_apply_inr, Function.comp_apply,
sumCongr_apply, Equiv.coe_trans, Subtype.coe_eta, Trans.trans,
Set.sumCompl_symm_apply_compl]
/-- The set product of two sets is equivalent to the type product of their coercions to types. -/
protected def prod {α β} (s : Set α) (t : Set β) : ↥(s ×ˢ t) ≃ s × t :=
@subtypeProdEquivProd α β s t
/-- The set `Set.pi Set.univ s` is equivalent to `Π a, s a`. -/
@[simps]
protected def univPi {α : Type*} {β : α → Type*} (s : ∀ a, Set (β a)) :
pi univ s ≃ ∀ a, s a where
toFun f a := ⟨(f : ∀ a, β a) a, f.2 a (mem_univ a)⟩
invFun f := ⟨fun a => f a, fun a _ => (f a).2⟩
/-- If a function `f` is injective on a set `s`, then `s` is equivalent to `f '' s`. -/
protected noncomputable def imageOfInjOn {α β} (f : α → β) (s : Set α) (H : InjOn f s) :
s ≃ f '' s :=
⟨fun p => ⟨f p, mem_image_of_mem f p.2⟩, fun p =>
⟨Classical.choose p.2, (Classical.choose_spec p.2).1⟩, fun ⟨_, h⟩ =>
Subtype.eq
(H (Classical.choose_spec (mem_image_of_mem f h)).1 h
(Classical.choose_spec (mem_image_of_mem f h)).2),
fun ⟨_, h⟩ => Subtype.eq (Classical.choose_spec h).2⟩
/-- If `f` is an injective function, then `s` is equivalent to `f '' s`. -/
@[simps! apply]
protected noncomputable def image {α β} (f : α → β) (s : Set α) (H : Injective f) : s ≃ f '' s :=
Equiv.Set.imageOfInjOn f s H.injOn
@[simp]
protected theorem image_symm_apply {α β} (f : α → β) (s : Set α) (H : Injective f) (x : α)
(h : f x ∈ f '' s) : (Set.image f s H).symm ⟨f x, h⟩ = ⟨x, H.mem_set_image.1 h⟩ :=
(Equiv.symm_apply_eq _).2 rfl
theorem image_symm_preimage {α β} {f : α → β} (hf : Injective f) (u s : Set α) :
(fun x => (Set.image f s hf).symm x : f '' s → α) ⁻¹' u = Subtype.val ⁻¹' (f '' u) := by
ext ⟨b, a, has, rfl⟩
simp [hf.eq_iff]
/-- If `α` is equivalent to `β`, then `Set α` is equivalent to `Set β`. -/
@[simps]
protected def congr {α β : Type*} (e : α ≃ β) : Set α ≃ Set β :=
⟨fun s => e '' s, fun t => e.symm '' t, symm_image_image e, symm_image_image e.symm⟩
/-- The set `{x ∈ s | t x}` is equivalent to the set of `x : s` such that `t x`. -/
protected def sep {α : Type u} (s : Set α) (t : α → Prop) :
({ x ∈ s | t x } : Set α) ≃ { x : s | t x } :=
(Equiv.subtypeSubtypeEquivSubtypeInter s t).symm
/-- The set `𝒫 S := {x | x ⊆ S}` is equivalent to the type `Set S`. -/
protected def powerset {α} (S : Set α) :
𝒫 S ≃ Set S where
toFun := fun x : 𝒫 S => Subtype.val ⁻¹' (x : Set α)
invFun := fun x : Set S => ⟨Subtype.val '' x, by rintro _ ⟨a : S, _, rfl⟩; exact a.2⟩
left_inv x := by ext y; exact ⟨fun ⟨⟨_, _⟩, h, rfl⟩ => h, fun h => ⟨⟨_, x.2 h⟩, h, rfl⟩⟩
right_inv x := by ext; simp
/-- If `s` is a set in `range f`,
then its image under `rangeSplitting f` is in bijection (via `f`) with `s`.
-/
@[simps]
noncomputable def rangeSplittingImageEquiv {α β : Type*} (f : α → β) (s : Set (range f)) :
rangeSplitting f '' s ≃ s where
toFun x :=
⟨⟨f x, by simp⟩, by
rcases x with ⟨x, ⟨y, ⟨m, rfl⟩⟩⟩
simpa [apply_rangeSplitting f] using m⟩
invFun x := ⟨rangeSplitting f x, ⟨x, ⟨x.2, rfl⟩⟩⟩
left_inv x := by
rcases x with ⟨x, ⟨y, ⟨m, rfl⟩⟩⟩
simp [apply_rangeSplitting f]
right_inv x := by simp [apply_rangeSplitting f]
/-- Equivalence between the range of `Sum.inl : α → α ⊕ β` and `α`. -/
@[simps symm_apply_coe]
def rangeInl (α β : Type*) : Set.range (Sum.inl : α → α ⊕ β) ≃ α where
toFun
| ⟨.inl x, _⟩ => x
| ⟨.inr _, h⟩ => False.elim <| by rcases h with ⟨x, h'⟩; cases h'
invFun x := ⟨.inl x, mem_range_self _⟩
left_inv := fun ⟨_, _, rfl⟩ => rfl
@[simp] lemma rangeInl_apply_inl {α : Type*} (β : Type*) (x : α) :
(rangeInl α β) ⟨.inl x, mem_range_self _⟩ = x :=
rfl
/-- Equivalence between the range of `Sum.inr : β → α ⊕ β` and `β`. -/
@[simps symm_apply_coe]
def rangeInr (α β : Type*) : Set.range (Sum.inr : β → α ⊕ β) ≃ β where
toFun
| ⟨.inl _, h⟩ => False.elim <| by rcases h with ⟨x, h'⟩; cases h'
| ⟨.inr x, _⟩ => x
invFun x := ⟨.inr x, mem_range_self _⟩
left_inv := fun ⟨_, _, rfl⟩ => rfl
@[simp] lemma rangeInr_apply_inr (α : Type*) {β : Type*} (x : β) :
(rangeInr α β) ⟨.inr x, mem_range_self _⟩ = x :=
rfl
end Set
/-- If `f : α → β` has a left-inverse when `α` is nonempty, then `α` is computably equivalent to the
range of `f`.
While awkward, the `Nonempty α` hypothesis on `f_inv` and `hf` allows this to be used when `α` is
empty too. This hypothesis is absent on analogous definitions on stronger `Equiv`s like
`LinearEquiv.ofLeftInverse` and `RingEquiv.ofLeftInverse` as their typeclass assumptions
are already sufficient to ensure non-emptiness. -/
@[simps]
def ofLeftInverse {α β : Sort _} (f : α → β) (f_inv : Nonempty α → β → α)
(hf : ∀ h : Nonempty α, LeftInverse (f_inv h) f) :
α ≃ range f where
toFun a := ⟨f a, a, rfl⟩
invFun b := f_inv b.2.nonempty b
left_inv a := hf ⟨a⟩ a
right_inv := fun ⟨b, a, ha⟩ =>
Subtype.eq <| show f (f_inv ⟨a⟩ b) = b from Eq.trans (congr_arg f <| ha ▸ hf _ a) ha
/-- If `f : α → β` has a left-inverse, then `α` is computably equivalent to the range of `f`.
Note that if `α` is empty, no such `f_inv` exists and so this definition can't be used, unlike
the stronger but less convenient `ofLeftInverse`. -/
abbrev ofLeftInverse' {α β : Sort _} (f : α → β) (f_inv : β → α) (hf : LeftInverse f_inv f) :
α ≃ range f :=
ofLeftInverse f (fun _ => f_inv) fun _ => hf
/-- If `f : α → β` is an injective function, then domain `α` is equivalent to the range of `f`. -/
@[simps! apply]
noncomputable def ofInjective {α β} (f : α → β) (hf : Injective f) : α ≃ range f :=
Equiv.ofLeftInverse f (fun _ => Function.invFun f) fun _ => Function.leftInverse_invFun hf
theorem apply_ofInjective_symm {α β} {f : α → β} (hf : Injective f) (b : range f) :
f ((ofInjective f hf).symm b) = b :=
Subtype.ext_iff.1 <| (ofInjective f hf).apply_symm_apply b
@[simp]
theorem ofInjective_symm_apply {α β} {f : α → β} (hf : Injective f) (a : α) :
(ofInjective f hf).symm ⟨f a, ⟨a, rfl⟩⟩ = a := by
apply (ofInjective f hf).injective
simp
theorem coe_ofInjective_symm {α β} {f : α → β} (hf : Injective f) :
((ofInjective f hf).symm : range f → α) = rangeSplitting f := by
ext ⟨y, x, rfl⟩
apply hf
simp [apply_rangeSplitting f]
@[simp]
theorem self_comp_ofInjective_symm {α β} {f : α → β} (hf : Injective f) :
f ∘ (ofInjective f hf).symm = Subtype.val :=
funext fun x => apply_ofInjective_symm hf x
theorem ofLeftInverse_eq_ofInjective {α β : Type*} (f : α → β) (f_inv : Nonempty α → β → α)
(hf : ∀ h : Nonempty α, LeftInverse (f_inv h) f) :
ofLeftInverse f f_inv hf =
ofInjective f ((isEmpty_or_nonempty α).elim (fun _ _ _ _ => Subsingleton.elim _ _)
(fun h => (hf h).injective)) := by
ext
simp
theorem ofLeftInverse'_eq_ofInjective {α β : Type*} (f : α → β) (f_inv : β → α)
(hf : LeftInverse f_inv f) : ofLeftInverse' f f_inv hf = ofInjective f hf.injective := by
ext
simp
protected theorem set_forall_iff {α β} (e : α ≃ β) {p : Set α → Prop} :
(∀ a, p a) ↔ ∀ a, p (e ⁻¹' a) :=
e.injective.preimage_surjective.forall
theorem preimage_piEquivPiSubtypeProd_symm_pi {α : Type*} {β : α → Type*} (p : α → Prop)
[DecidablePred p] (s : ∀ i, Set (β i)) :
(piEquivPiSubtypeProd p β).symm ⁻¹' pi univ s =
(pi univ fun i : { i // p i } => s i) ×ˢ pi univ fun i : { i // ¬p i } => s i := by
ext ⟨f, g⟩
simp only [mem_preimage, mem_univ_pi, prodMk_mem_set_prod_eq, Subtype.forall, ← forall_and]
refine forall_congr' fun i => ?_
dsimp only [Subtype.coe_mk]
by_cases hi : p i <;> simp [hi]
-- See also `Equiv.sigmaFiberEquiv`.
/-- `sigmaPreimageEquiv f` for `f : α → β` is the natural equivalence between
the type of all preimages of points under `f` and the total space `α`. -/
@[simps!]
def sigmaPreimageEquiv {α β} (f : α → β) : (Σ b, f ⁻¹' {b}) ≃ α :=
sigmaFiberEquiv f
-- See also `Equiv.ofFiberEquiv`.
/-- A family of equivalences between preimages of points gives an equivalence between domains. -/
@[simps!]
def ofPreimageEquiv {α β γ} {f : α → γ} {g : β → γ} (e : ∀ c, f ⁻¹' {c} ≃ g ⁻¹' {c}) : α ≃ β :=
Equiv.ofFiberEquiv e
theorem ofPreimageEquiv_map {α β γ} {f : α → γ} {g : β → γ} (e : ∀ c, f ⁻¹' {c} ≃ g ⁻¹' {c})
(a : α) : g (ofPreimageEquiv e a) = f a :=
Equiv.ofFiberEquiv_map e a
end Equiv
/-- If a function is a bijection between two sets `s` and `t`, then it induces an
equivalence between the types `↥s` and `↥t`. -/
noncomputable def Set.BijOn.equiv {α : Type*} {β : Type*} {s : Set α} {t : Set β} (f : α → β)
(h : BijOn f s t) : s ≃ t :=
Equiv.ofBijective _ h.bijective
/-- The composition of an updated function with an equiv on a subtype can be expressed as an
updated function. -/
theorem dite_comp_equiv_update {α : Type*} {β : Sort*} {γ : Sort*} {p : α → Prop}
(e : β ≃ {x // p x})
(v : β → γ) (w : α → γ) (j : β) (x : γ) [DecidableEq β] [DecidableEq α]
[∀ j, Decidable (p j)] :
(fun i : α => if h : p i then (Function.update v j x) (e.symm ⟨i, h⟩) else w i) =
Function.update (fun i : α => if h : p i then v (e.symm ⟨i, h⟩) else w i) (e j) x := by
ext i
by_cases h : p i
· rw [dif_pos h, Function.update_apply_equiv_apply, Equiv.symm_symm,
Function.update_apply, Function.update_apply, dif_pos h]
have h_coe : (⟨i, h⟩ : Subtype p) = e j ↔ i = e j :=
Subtype.ext_iff.trans (by rw [Subtype.coe_mk])
simp [h_coe]
· have : i ≠ e j := by
contrapose! h
have : p (e j : α) := (e j).2
rwa [← h] at this
simp [h, this]
section Swap
variable {α : Type*} [DecidableEq α] {a b : α} {s : Set α}
theorem Equiv.swap_bijOn_self (hs : a ∈ s ↔ b ∈ s) : BijOn (Equiv.swap a b) s s := by
refine ⟨fun x hx ↦ ?_, (Equiv.injective _).injOn, fun x hx ↦ ?_⟩
· obtain (rfl | hxa) := eq_or_ne x a
· rwa [swap_apply_left, ← hs]
obtain (rfl | hxb) := eq_or_ne x b
· rwa [swap_apply_right, hs]
rwa [swap_apply_of_ne_of_ne hxa hxb]
obtain (rfl | hxa) := eq_or_ne x a
· simp [hs.1 hx]
obtain (rfl | hxb) := eq_or_ne x b
· simp [hs.2 hx]
exact ⟨x, hx, swap_apply_of_ne_of_ne hxa hxb⟩
theorem Equiv.swap_bijOn_exchange (ha : a ∈ s) (hb : b ∉ s) :
BijOn (Equiv.swap a b) s (insert b (s \ {a})) := by
refine ⟨fun x hx ↦ ?_, (Equiv.injective _).injOn, fun x hx ↦ ?_⟩
· obtain (rfl | hxa) := eq_or_ne x a
· simp [swap_apply_left]
rw [swap_apply_of_ne_of_ne hxa (by rintro rfl; contradiction)]
exact .inr ⟨hx, hxa⟩
obtain (rfl | hxb) := eq_or_ne x b
· exact ⟨a, ha, by simp⟩
simp only [mem_insert_iff, mem_diff, mem_singleton_iff, or_iff_right hxb] at hx
exact ⟨x, hx.1, swap_apply_of_ne_of_ne hx.2 hxb⟩
end Swap |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Functor.lean | import Mathlib.Control.Bifunctor
import Mathlib.Logic.Equiv.Defs
/-!
# Functor and bifunctors can be applied to `Equiv`s.
We define
```lean
def Functor.mapEquiv (f : Type u → Type v) [Functor f] [LawfulFunctor f] :
α ≃ β → f α ≃ f β
```
and
```lean
def Bifunctor.mapEquiv (F : Type u → Type v → Type w) [Bifunctor F] [LawfulBifunctor F] :
α ≃ β → α' ≃ β' → F α α' ≃ F β β'
```
-/
universe u v w
variable {α β : Type u}
open Equiv
namespace Functor
variable (f : Type u → Type v) [Functor f] [LawfulFunctor f]
/-- Apply a functor to an `Equiv`. -/
def mapEquiv (h : α ≃ β) : f α ≃ f β where
toFun := map h
invFun := map h.symm
left_inv x := by simp [map_map]
right_inv x := by simp [map_map]
@[simp]
theorem mapEquiv_apply (h : α ≃ β) (x : f α) : (mapEquiv f h : f α ≃ f β) x = map h x :=
rfl
@[simp]
theorem mapEquiv_symm_apply (h : α ≃ β) (y : f β) :
(mapEquiv f h : f α ≃ f β).symm y = map h.symm y :=
rfl
@[simp]
theorem mapEquiv_refl : mapEquiv f (Equiv.refl α) = Equiv.refl (f α) := by
ext x
simp only [mapEquiv_apply, refl_apply]
exact LawfulFunctor.id_map x
end Functor
namespace Bifunctor
variable {α' β' : Type v} (F : Type u → Type v → Type w) [Bifunctor F] [LawfulBifunctor F]
/-- Apply a bifunctor to a pair of `Equiv`s. -/
def mapEquiv (h : α ≃ β) (h' : α' ≃ β') : F α α' ≃ F β β' where
toFun := bimap h h'
invFun := bimap h.symm h'.symm
left_inv x := by simp [bimap_bimap, id_bimap]
right_inv x := by simp [bimap_bimap, id_bimap]
@[simp]
theorem mapEquiv_apply (h : α ≃ β) (h' : α' ≃ β') (x : F α α') :
(mapEquiv F h h' : F α α' ≃ F β β') x = bimap h h' x :=
rfl
@[simp]
theorem mapEquiv_symm_apply (h : α ≃ β) (h' : α' ≃ β') (y : F β β') :
(mapEquiv F h h' : F α α' ≃ F β β').symm y = bimap h.symm h'.symm y :=
rfl
@[simp]
theorem mapEquiv_refl_refl : mapEquiv F (Equiv.refl α) (Equiv.refl α') = Equiv.refl (F α α') := by
ext x
simp [id_bimap]
end Bifunctor |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Embedding.lean | import Mathlib.Logic.Embedding.Set
/-!
# Equivalences on embeddings
This file shows some advanced equivalences on embeddings, useful for constructing larger
embeddings from smaller ones.
-/
open Function.Embedding
namespace Equiv
/-- Embeddings from a sum type are equivalent to two separate embeddings with disjoint ranges. -/
def sumEmbeddingEquivProdEmbeddingDisjoint {α β γ : Type*} :
(α ⊕ β ↪ γ) ≃ { f : (α ↪ γ) × (β ↪ γ) // Disjoint (Set.range f.1) (Set.range f.2) } where
toFun f :=
⟨(inl.trans f, inr.trans f), by
rw [Set.disjoint_left]
rintro _ ⟨a, h⟩ ⟨b, rfl⟩
simp only at h
have : Sum.inl a = Sum.inr b := f.injective h
simp only [reduceCtorEq] at this⟩
invFun := fun ⟨⟨f, g⟩, disj⟩ =>
⟨fun x =>
match x with
| Sum.inl a => f a
| Sum.inr b => g b, by
rintro (a₁ | b₁) (a₂ | b₂) f_eq <;>
simp only at f_eq
· rw [f.injective f_eq]
· exfalso
exact disj.le_bot ⟨⟨a₁, f_eq⟩, ⟨b₂, by simp⟩⟩
· exfalso
exact disj.le_bot ⟨⟨a₂, rfl⟩, ⟨b₁, f_eq⟩⟩
· rw [g.injective f_eq]⟩
left_inv f := by
dsimp only
ext x
cases x <;> simp!
right_inv := fun ⟨⟨f, g⟩, _⟩ => by
simp only
rfl
/-- Embeddings whose range lies within a set are equivalent to embeddings to that set.
This is `Function.Embedding.codRestrict` as an equiv. -/
def codRestrict (α : Type*) {β : Type*} (bs : Set β) :
{ f : α ↪ β // ∀ a, f a ∈ bs } ≃
(α ↪ bs) where
toFun f := (f : α ↪ β).codRestrict bs f.prop
invFun f := ⟨f.trans (Function.Embedding.subtype _), fun a => (f a).prop⟩
/-- Pairs of embeddings with disjoint ranges are equivalent to a dependent sum of embeddings,
in which the second embedding cannot take values in the range of the first. -/
def prodEmbeddingDisjointEquivSigmaEmbeddingRestricted {α β γ : Type*} :
{ f : (α ↪ γ) × (β ↪ γ) // Disjoint (Set.range f.1) (Set.range f.2) } ≃
Σ f : α ↪ γ, β ↪ ↥(Set.range f)ᶜ :=
(subtypeProdEquivSigmaSubtype fun (a : α ↪ γ) (b : β ↪ _) =>
Disjoint (Set.range a) (Set.range b)).trans <|
Equiv.sigmaCongrRight fun a =>
(subtypeEquivProp <| by
ext f
rw [← Set.range_subset_iff, Set.subset_compl_iff_disjoint_right, disjoint_comm]).trans
(codRestrict _ _)
/-- A combination of the above results, allowing us to turn one embedding over a sum type
into two dependent embeddings, the second of which avoids any members of the range
of the first. This is helpful for constructing larger embeddings out of smaller ones. -/
def sumEmbeddingEquivSigmaEmbeddingRestricted {α β γ : Type*} :
(α ⊕ β ↪ γ) ≃ Σ f : α ↪ γ, β ↪ ↥(Set.range f)ᶜ :=
Equiv.trans sumEmbeddingEquivProdEmbeddingDisjoint
prodEmbeddingDisjointEquivSigmaEmbeddingRestricted
/-- Embeddings from a single-member type are equivalent to members of the target type. -/
def uniqueEmbeddingEquivResult {α β : Type*} [Unique α] :
(α ↪ β) ≃ β where
toFun f := f default
invFun x := ⟨fun _ => x, fun _ _ _ => Subsingleton.elim _ _⟩
left_inv _ := by
ext x
simp_rw [Function.Embedding.coeFn_mk]
congr 1
exact Subsingleton.elim _ x
right_inv _ := by simp
end Equiv |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Bool.lean | import Mathlib.Logic.Equiv.Basic
import Mathlib.Logic.Function.Basic
/-!
# Equivalences involving `Bool`
This file shows that `not : Bool → Bool` is an equivalence and derives some consequences
-/
/-- The boolean negation function `not : Bool → Bool` is an involution and thus an equivalence. -/
@[simps!]
def Equiv.boolNot : Equiv.Perm Bool := Bool.involutive_not.toPerm
namespace Bool
open Function
theorem not_bijective : Bijective not := Equiv.boolNot.bijective
theorem not_injective : Injective not := Equiv.boolNot.injective
theorem not_surjective : Surjective not := Equiv.boolNot.surjective
theorem not_leftInverse : LeftInverse not not := not_not
theorem not_rightInverse : RightInverse not not := not_not
theorem not_hasLeftInverse : HasLeftInverse not := ⟨not, not_leftInverse⟩
theorem not_hasRightInverse : HasRightInverse not := ⟨not, not_rightInverse⟩
end Bool |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Array.lean | import Mathlib.Data.Vector.Basic
import Mathlib.Logic.Equiv.List
/-!
# Equivalences involving `Array`
-/
namespace Equiv
/-- The natural equivalence between arrays and lists. -/
def arrayEquivList (α : Type*) : Array α ≃ List α where
toFun := Array.toList
invFun := Array.mk
end Equiv
/- Porting note: removed instances for what would be ported as `Traversable (Array α)` and
`LawfulTraversable (Array α)`. These would
1. be implemented directly in terms of `Array` functionality for efficiency, rather than being the
traversal of some other type transported along an equivalence to `Array α` (as the traversable
instance for `array` was)
2. belong in `Mathlib/Control/Traversable/Instances.lean` instead of this file. -/
-- namespace Array'
-- open Function
-- variable {n : ℕ}
-- instance : Traversable (Array' n) :=
-- @Equiv.traversable (flip Vector n) _ (fun α => Equiv.vectorEquivArray α n) _
-- instance : LawfulTraversable (Array' n) :=
-- @Equiv.isLawfulTraversable (flip Vector n) _ (fun α => Equiv.vectorEquivArray α n) _ _
-- end Array'
/-- If `α` is encodable, then so is `Array α`. -/
instance Array.encodable {α} [Encodable α] : Encodable (Array α) :=
Encodable.ofEquiv _ (Equiv.arrayEquivList _)
/-- If `α` is countable, then so is `Array α`. -/
instance Array.countable {α} [Countable α] : Countable (Array α) :=
Countable.of_equiv _ (Equiv.arrayEquivList α).symm |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Fin/Basic.lean | import Mathlib.Data.Fin.VecNotation
import Mathlib.Logic.Embedding.Set
import Mathlib.Logic.Equiv.Option
import Mathlib.Data.Int.Init
import Batteries.Data.Fin.Lemmas
/-!
# Equivalences for `Fin n`
-/
assert_not_exists MonoidWithZero
universe u
variable {m n : ℕ}
/-!
### Miscellaneous
This is currently not very sorted. PRs welcome!
-/
theorem Fin.preimage_apply_01_prod {α : Fin 2 → Type u} (s : Set (α 0)) (t : Set (α 1)) :
(fun f : ∀ i, α i => (f 0, f 1)) ⁻¹' s ×ˢ t =
Set.pi Set.univ (Fin.cons s <| Fin.cons t finZeroElim) := by
ext f
simp [Fin.forall_fin_two]
theorem Fin.preimage_apply_01_prod' {α : Type u} (s t : Set α) :
(fun f : Fin 2 → α => (f 0, f 1)) ⁻¹' s ×ˢ t = Set.pi Set.univ ![s, t] :=
@Fin.preimage_apply_01_prod (fun _ => α) s t
/-- A product space `α × β` is equivalent to the space `Π i : Fin 2, γ i`, where
`γ = Fin.cons α (Fin.cons β finZeroElim)`. See also `piFinTwoEquiv` and
`finTwoArrowEquiv`. -/
@[simps! -fullyApplied]
def prodEquivPiFinTwo (α β : Type u) : α × β ≃ ∀ i : Fin 2, ![α, β] i :=
(piFinTwoEquiv (Fin.cons α (Fin.cons β finZeroElim))).symm
/-- The space of functions `Fin 2 → α` is equivalent to `α × α`. See also `piFinTwoEquiv` and
`prodEquivPiFinTwo`. -/
@[simps -fullyApplied]
def finTwoArrowEquiv (α : Type*) : (Fin 2 → α) ≃ α × α :=
{ piFinTwoEquiv fun _ => α with invFun := fun x => ![x.1, x.2] }
/-- An equivalence that removes `i` and maps it to `none`.
This is a version of `Fin.predAbove` that produces `Option (Fin n)` instead of
mapping both `i.castSucc` and `i.succ` to `i`. -/
def finSuccEquiv' (i : Fin (n + 1)) : Fin (n + 1) ≃ Option (Fin n) where
toFun := i.insertNth none some
invFun x := x.casesOn' i (Fin.succAbove i)
left_inv x := Fin.succAboveCases i (by simp) (fun j => by simp) x
right_inv x := by cases x <;> simp
@[simp]
theorem finSuccEquiv'_at (i : Fin (n + 1)) : (finSuccEquiv' i) i = none := by
simp [finSuccEquiv']
@[simp]
theorem finSuccEquiv'_succAbove (i : Fin (n + 1)) (j : Fin n) :
finSuccEquiv' i (i.succAbove j) = some j :=
@Fin.insertNth_apply_succAbove n (fun _ => Option (Fin n)) i _ _ _
theorem finSuccEquiv'_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) :
(finSuccEquiv' i) (Fin.castSucc m) = m := by
rw [← Fin.succAbove_of_castSucc_lt _ _ h, finSuccEquiv'_succAbove]
theorem finSuccEquiv'_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) :
(finSuccEquiv' i) m.succ = some m := by
rw [← Fin.succAbove_of_le_castSucc _ _ h, finSuccEquiv'_succAbove]
@[simp]
theorem finSuccEquiv'_symm_none (i : Fin (n + 1)) : (finSuccEquiv' i).symm none = i :=
rfl
@[simp]
theorem finSuccEquiv'_symm_some (i : Fin (n + 1)) (j : Fin n) :
(finSuccEquiv' i).symm (some j) = i.succAbove j :=
rfl
@[simp]
theorem finSuccEquiv'_eq_some {i j : Fin (n + 1)} {k : Fin n} :
finSuccEquiv' i j = k ↔ j = i.succAbove k :=
(finSuccEquiv' i).apply_eq_iff_eq_symm_apply
@[simp]
theorem finSuccEquiv'_eq_none {i j : Fin (n + 1)} : finSuccEquiv' i j = none ↔ i = j :=
(finSuccEquiv' i).apply_eq_iff_eq_symm_apply.trans eq_comm
theorem finSuccEquiv'_symm_some_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) :
(finSuccEquiv' i).symm (some m) = Fin.castSucc m :=
Fin.succAbove_of_castSucc_lt i m h
theorem finSuccEquiv'_symm_some_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) :
(finSuccEquiv' i).symm (some m) = m.succ :=
Fin.succAbove_of_le_castSucc i m h
theorem finSuccEquiv'_symm_coe_below {i : Fin (n + 1)} {m : Fin n} (h : Fin.castSucc m < i) :
(finSuccEquiv' i).symm m = Fin.castSucc m :=
finSuccEquiv'_symm_some_below h
theorem finSuccEquiv'_symm_coe_above {i : Fin (n + 1)} {m : Fin n} (h : i ≤ Fin.castSucc m) :
(finSuccEquiv' i).symm m = m.succ :=
finSuccEquiv'_symm_some_above h
/-- Equivalence between `Fin (n + 1)` and `Option (Fin n)`.
This is a version of `Fin.pred` that produces `Option (Fin n)` instead of
requiring a proof that the input is not `0`. -/
def finSuccEquiv (n : ℕ) : Fin (n + 1) ≃ Option (Fin n) :=
finSuccEquiv' 0
@[simp]
theorem finSuccEquiv_zero : (finSuccEquiv n) 0 = none :=
rfl
@[simp]
theorem finSuccEquiv_succ (m : Fin n) : (finSuccEquiv n) m.succ = some m :=
finSuccEquiv'_above (Fin.zero_le _)
@[simp]
theorem finSuccEquiv_symm_none : (finSuccEquiv n).symm none = 0 :=
finSuccEquiv'_symm_none _
@[simp]
theorem finSuccEquiv_symm_some (m : Fin n) : (finSuccEquiv n).symm (some m) = m.succ :=
congr_fun Fin.succAbove_zero m
@[simp]
theorem finSuccEquiv_eq_some {i : Fin (n + 1)} {j : Fin n} :
finSuccEquiv n i = j ↔ i = j.succ :=
(finSuccEquiv n).apply_eq_iff_eq_symm_apply
@[simp]
theorem finSuccEquiv_eq_none {i : Fin (n + 1)} : finSuccEquiv n i = none ↔ i = 0 :=
(finSuccEquiv n).apply_eq_iff_eq_symm_apply
/-- The equiv version of `Fin.predAbove_zero`. -/
theorem finSuccEquiv'_zero : finSuccEquiv' (0 : Fin (n + 1)) = finSuccEquiv n :=
rfl
theorem finSuccEquiv'_last_apply_castSucc (i : Fin n) :
finSuccEquiv' (Fin.last n) (Fin.castSucc i) = i := by
rw [← Fin.succAbove_last, finSuccEquiv'_succAbove]
theorem finSuccEquiv'_last_apply {i : Fin (n + 1)} (h : i ≠ Fin.last n) :
finSuccEquiv' (Fin.last n) i = Fin.castLT i (Fin.val_lt_last h) := by
simp
theorem finSuccEquiv'_ne_last_apply {i j : Fin (n + 1)} (hi : i ≠ Fin.last n) (hj : j ≠ i) :
finSuccEquiv' i j = (i.castLT (Fin.val_lt_last hi)).predAbove j := by
rcases Fin.exists_succAbove_eq hj with ⟨j, rfl⟩
rcases Fin.exists_castSucc_eq.2 hi with ⟨i, rfl⟩
simp
/-- `Fin.succAbove` as an order isomorphism between `Fin n` and `{x : Fin (n + 1) // x ≠ p}`. -/
def finSuccAboveEquiv (p : Fin (n + 1)) : Fin n ≃ { x : Fin (n + 1) // x ≠ p } :=
.optionSubtype p ⟨(finSuccEquiv' p).symm, rfl⟩
theorem finSuccAboveEquiv_apply (p : Fin (n + 1)) (i : Fin n) :
finSuccAboveEquiv p i = ⟨p.succAbove i, p.succAbove_ne i⟩ :=
rfl
theorem finSuccAboveEquiv_symm_apply_last (x : { x : Fin (n + 1) // x ≠ Fin.last n }) :
(finSuccAboveEquiv (Fin.last n)).symm x = Fin.castLT x.1 (Fin.val_lt_last x.2) := by
rw [← Option.some_inj]
simp [finSuccAboveEquiv]
theorem finSuccAboveEquiv_symm_apply_ne_last {p : Fin (n + 1)} (h : p ≠ Fin.last n)
(x : { x : Fin (n + 1) // x ≠ p }) :
(finSuccAboveEquiv p).symm x = (p.castLT (Fin.val_lt_last h)).predAbove x := by
rw [← Option.some_inj]
simpa [finSuccAboveEquiv] using finSuccEquiv'_ne_last_apply h x.property
/-- `Equiv` between `Fin (n + 1)` and `Option (Fin n)` sending `Fin.last n` to `none` -/
def finSuccEquivLast : Fin (n + 1) ≃ Option (Fin n) :=
finSuccEquiv' (Fin.last n)
@[simp]
theorem finSuccEquivLast_castSucc (i : Fin n) : finSuccEquivLast (Fin.castSucc i) = some i :=
finSuccEquiv'_below i.2
@[simp]
theorem finSuccEquivLast_last : finSuccEquivLast (Fin.last n) = none := by
simp [finSuccEquivLast]
@[simp]
theorem finSuccEquivLast_symm_some (i : Fin n) :
finSuccEquivLast.symm (some i) = Fin.castSucc i :=
finSuccEquiv'_symm_some_below i.2
@[simp] theorem finSuccEquivLast_symm_none : finSuccEquivLast.symm none = Fin.last n :=
finSuccEquiv'_symm_none _
/-- An embedding `e : Fin (n+1) ↪ ι` corresponds to an embedding `f : Fin n ↪ ι` (corresponding
the last `n` coordinates of `e`) together with a value not taken by `f` (corresponding to `e 0`). -/
def Equiv.embeddingFinSucc (n : ℕ) (ι : Type*) :
(Fin (n + 1) ↪ ι) ≃ (Σ (e : Fin n ↪ ι), {i // i ∉ Set.range e}) :=
((finSuccEquiv n).embeddingCongr (Equiv.refl ι)).trans
(Function.Embedding.optionEmbeddingEquiv (Fin n) ι)
@[simp] lemma Equiv.embeddingFinSucc_fst {n : ℕ} {ι : Type*} (e : Fin (n + 1) ↪ ι) :
((Equiv.embeddingFinSucc n ι e).1 : Fin n → ι) = e ∘ Fin.succ := rfl
@[simp] lemma Equiv.embeddingFinSucc_snd {n : ℕ} {ι : Type*} (e : Fin (n + 1) ↪ ι) :
((Equiv.embeddingFinSucc n ι e).2 : ι) = e 0 := rfl
@[simp] lemma Equiv.coe_embeddingFinSucc_symm {n : ℕ} {ι : Type*}
(f : Σ (e : Fin n ↪ ι), {i // i ∉ Set.range e}) :
((Equiv.embeddingFinSucc n ι).symm f : Fin (n + 1) → ι) = Fin.cons f.2.1 f.1 := by
ext i
exact Fin.cases rfl (fun j ↦ rfl) i
/-- Equivalence between `Fin m ⊕ Fin n` and `Fin (m + n)` -/
def finSumFinEquiv : Fin m ⊕ Fin n ≃ Fin (m + n) where
toFun := Sum.elim (Fin.castAdd n) (Fin.natAdd m)
invFun i := @Fin.addCases m n (fun _ => Fin m ⊕ Fin n) Sum.inl Sum.inr i
left_inv x := by rcases x with y | y <;> simp
right_inv x := by refine Fin.addCases (fun i => ?_) (fun i => ?_) x <;> simp
@[simp]
theorem finSumFinEquiv_apply_left (i : Fin m) :
(finSumFinEquiv (Sum.inl i) : Fin (m + n)) = Fin.castAdd n i :=
rfl
@[simp]
theorem finSumFinEquiv_apply_right (i : Fin n) :
(finSumFinEquiv (Sum.inr i) : Fin (m + n)) = Fin.natAdd m i :=
rfl
@[simp]
theorem finSumFinEquiv_symm_apply_castAdd (x : Fin m) :
finSumFinEquiv.symm (Fin.castAdd n x) = Sum.inl x :=
finSumFinEquiv.symm_apply_apply (Sum.inl x)
@[simp]
theorem finSumFinEquiv_symm_apply_castSucc (x : Fin m) :
finSumFinEquiv.symm (Fin.castSucc x) = Sum.inl x :=
finSumFinEquiv_symm_apply_castAdd x
@[simp]
theorem finSumFinEquiv_symm_apply_natAdd (x : Fin n) :
finSumFinEquiv.symm (Fin.natAdd m x) = Sum.inr x :=
finSumFinEquiv.symm_apply_apply (Sum.inr x)
@[simp]
theorem finSumFinEquiv_symm_last : finSumFinEquiv.symm (Fin.last n) = Sum.inr 0 :=
finSumFinEquiv_symm_apply_natAdd 0
/-- Equivalence between `Fin n ⊕ ℕ` and `ℕ` that sends `inl (a : Fin n)` to
`(a : ℕ)` and `inr a` to `n + a`. -/
def finSumNatEquiv (n : ℕ) : Fin n ⊕ ℕ ≃ ℕ where
toFun := Sum.elim Fin.val (n + ·)
invFun i := if hi : i < n then .inl ⟨i, hi⟩ else .inr (i - n)
left_inv i := (i.casesOn
(fun _ => dif_pos (Fin.is_lt _))
(fun _ => (dif_neg (Nat.le_add_right _ _).not_gt).trans <|
congrArg _ (Nat.add_sub_cancel_left _ _)))
right_inv i := (apply_dite _ _ _ _).trans <| (i.lt_or_ge n).by_cases
(fun hi => dif_pos hi)
(fun hi => (dif_neg hi.not_gt).trans <| Nat.add_sub_cancel' hi)
@[simp] theorem finSumNatEquiv_apply_left (i : Fin n) :
finSumNatEquiv n (.inl i) = i := rfl
@[simp] theorem finSumNatEquiv_apply_right (i : ℕ) :
finSumNatEquiv n (.inr i) = n + i := rfl
@[simp] theorem finSumNatEquiv_symm_apply_of_lt {i : ℕ} (hi : i < n) :
(finSumNatEquiv n).symm i = .inl ⟨i, hi⟩ := dif_pos hi
@[simp] theorem finSumNatEquiv_symm_apply_of_ge {i : ℕ} (hi : n ≤ i) :
(finSumNatEquiv n).symm i = .inr (i - n) := dif_neg (Nat.not_lt_of_ge hi)
theorem finSumNatEquiv_symm_apply_fin (i : Fin n) :
(finSumNatEquiv n).symm i = .inl i := by simp
theorem finSumNatEquiv_symm_apply_add_left (i : ℕ) :
(finSumNatEquiv n).symm (i + n) = .inr i := by simp
theorem finSumNatEquiv_symm_apply_add_right (i : ℕ) :
(finSumNatEquiv n).symm (n + i) = .inr i := by simp
@[simp] theorem isLeft_finSumNatEquiv_symm_apply (i : ℕ) :
((finSumNatEquiv n).symm i).isLeft = decide (i < n) := by
rcases i.lt_or_ge n with hi | hi
· simp_rw [finSumNatEquiv_symm_apply_of_lt hi, hi, Sum.isLeft_inl, decide_true]
· simp_rw [finSumNatEquiv_symm_apply_of_ge hi, hi.not_gt, Sum.isLeft_inr, decide_false]
@[simp] theorem isRight_finSumNatEquiv_symm_apply (i : ℕ) :
((finSumNatEquiv n).symm i).isRight = decide (n ≤ i) := by
simp_rw [← not_lt, decide_not, ← isLeft_finSumNatEquiv_symm_apply]
cases (finSumNatEquiv n).symm i <;> rfl
/-- The equivalence between `Fin (m + n)` and `Fin (n + m)` which rotates by `n`. -/
def finAddFlip : Fin (m + n) ≃ Fin (n + m) :=
(finSumFinEquiv.symm.trans (Equiv.sumComm _ _)).trans finSumFinEquiv
@[simp]
theorem finAddFlip_apply_castAdd (k : Fin m) (n : ℕ) :
finAddFlip (Fin.castAdd n k) = Fin.natAdd n k := by simp [finAddFlip]
@[simp]
theorem finAddFlip_apply_natAdd (k : Fin n) (m : ℕ) :
finAddFlip (Fin.natAdd m k) = Fin.castAdd m k := by simp [finAddFlip]
@[simp]
theorem finAddFlip_apply_mk_left {k : ℕ} (h : k < m) (hk : k < m + n := Nat.lt_add_right n h)
(hnk : n + k < n + m := Nat.add_lt_add_left h n) :
finAddFlip (⟨k, hk⟩ : Fin (m + n)) = ⟨n + k, hnk⟩ := by
convert finAddFlip_apply_castAdd ⟨k, h⟩ n
@[simp]
theorem finAddFlip_apply_mk_right {k : ℕ} (h₁ : m ≤ k) (h₂ : k < m + n) :
finAddFlip (⟨k, h₂⟩ : Fin (m + n)) = ⟨k - m, by cutsat⟩ := by
convert @finAddFlip_apply_natAdd n ⟨k - m, by cutsat⟩ m
simp [Nat.add_sub_cancel' h₁]
/-- Equivalence between `Fin m × Fin n` and `Fin (m * n)` -/
@[simps]
def finProdFinEquiv : Fin m × Fin n ≃ Fin (m * n) where
toFun x :=
⟨x.2 + n * x.1,
calc
x.2.1 + n * x.1.1 + 1 = x.1.1 * n + x.2.1 + 1 := by ac_rfl
_ ≤ x.1.1 * n + n := Nat.add_le_add_left x.2.2 _
_ = (x.1.1 + 1) * n := Eq.symm <| Nat.succ_mul _ _
_ ≤ m * n := Nat.mul_le_mul_right _ x.1.2
⟩
invFun x := (x.divNat, x.modNat)
left_inv := fun ⟨x, y⟩ =>
have H : 0 < n := Nat.pos_of_ne_zero fun H => Nat.not_lt_zero y.1 <| H ▸ y.2
Prod.ext
(Fin.eq_of_val_eq <|
calc
(y.1 + n * x.1) / n = y.1 / n + x.1 := Nat.add_mul_div_left _ _ H
_ = 0 + x.1 := by rw [Nat.div_eq_of_lt y.2]
_ = x.1 := Nat.zero_add x.1
)
(Fin.eq_of_val_eq <|
calc
(y.1 + n * x.1) % n = y.1 % n := Nat.add_mul_mod_self_left _ _ _
_ = y.1 := Nat.mod_eq_of_lt y.2
)
right_inv _ := Fin.eq_of_val_eq <| Nat.mod_add_div _ _
/-- The equivalence induced by `a ↦ (a / n, a % n)` for nonzero `n`.
This is like `finProdFinEquiv.symm` but with `m` infinite.
See `Nat.div_mod_unique` for a similar propositional statement. -/
@[simps]
def Nat.divModEquiv (n : ℕ) [NeZero n] : ℕ ≃ ℕ × Fin n where
toFun a := (a / n, Fin.ofNat n a)
invFun p := p.1 * n + ↑p.2
-- TODO: is there a canonical order of `*` and `+` here?
left_inv _ := Nat.div_add_mod' _ _
right_inv p := by
refine Prod.ext ?_ (Fin.ext <| Nat.mul_add_mod_of_lt p.2.is_lt)
dsimp only
rw [Nat.add_comm, Nat.add_mul_div_right _ _ n.pos_of_neZero, Nat.div_eq_of_lt p.2.is_lt,
Nat.zero_add]
/-- The equivalence induced by `a ↦ (a / n, a % n)` for nonzero `n`.
See `Int.ediv_emod_unique` for a similar propositional statement. -/
@[simps]
def Int.divModEquiv (n : ℕ) [NeZero n] : ℤ ≃ ℤ × Fin n where
-- TODO: could cast from int directly if we import `Data.ZMod.Defs`, though there are few lemmas
-- about that coercion.
toFun a := (a / n, Fin.ofNat n (a.natMod n))
invFun p := p.1 * n + ↑p.2
left_inv a := by
simp_rw [Fin.val_ofNat, natCast_mod, natMod,
toNat_of_nonneg (emod_nonneg _ <| natCast_eq_zero.not.2 (NeZero.ne n)), emod_emod,
ediv_mul_add_emod]
right_inv := fun ⟨q, r, hrn⟩ => by
simp only [Prod.mk_inj, Fin.ext_iff]
obtain ⟨h1, h2⟩ := Int.natCast_nonneg r, Int.ofNat_lt.2 hrn
rw [Int.add_comm, add_mul_ediv_right _ _ (natCast_eq_zero.not.2 (NeZero.ne n)),
ediv_eq_zero_of_lt h1 h2, natMod, add_mul_emod_self_right, emod_eq_of_lt h1 h2, toNat_natCast]
exact ⟨q.zero_add, Fin.val_cast_of_lt hrn⟩
/-- Promote a `Fin n` into a larger `Fin m`, as a subtype where the underlying
values are retained.
This is the `Equiv` version of `Fin.castLE`. -/
@[simps apply symm_apply]
def Fin.castLEquiv {n m : ℕ} (h : n ≤ m) : Fin n ≃ { i : Fin m // (i : ℕ) < n } where
toFun i := ⟨Fin.castLE h i, by simp⟩
invFun i := ⟨i, i.prop⟩
left_inv _ := by simp
right_inv _ := by simp
@[deprecated Fin.subsingleton_zero (since := "2025-06-03")]
theorem subsingleton_fin_zero : Subsingleton (Fin 0) :=
Fin.subsingleton_zero
@[deprecated Fin.subsingleton_one (since := "2025-06-03")]
theorem subsingleton_fin_one : Subsingleton (Fin 1) :=
Fin.subsingleton_one
/-- The natural `Equiv` between `(Fin m → α) × (Fin n → α)` and `Fin (m + n) → α` -/
@[simps]
def Fin.appendEquiv {α : Type*} (m n : ℕ) :
(Fin m → α) × (Fin n → α) ≃ (Fin (m + n) → α) where
toFun fg := Fin.append fg.1 fg.2
invFun f := ⟨fun i ↦ f (Fin.castAdd n i), fun i ↦ f (Fin.natAdd m i)⟩
left_inv fg := by simp
right_inv f := by simp [Fin.append_castAdd_natAdd]
/-- `Fin (n + 1) → α` and `(Fin n → α) × α` are equivalent. -/
@[simps!]
def Fin.succFunEquiv (α : Type*) (n : ℕ) : (Fin (n + 1) → α) ≃ (Fin n → α) × α :=
(appendEquiv n 1).symm.trans (Equiv.prodCongrRight fun _ ↦ Equiv.funUnique (Fin 1) α) |
.lake/packages/mathlib/Mathlib/Logic/Equiv/Fin/Rotate.lean | import Mathlib.Algebra.Group.Fin.Basic
import Mathlib.Logic.Equiv.Fin.Basic
/-!
# Cyclic permutations on `Fin n`
This file defines
* `finRotate`, which corresponds to the cycle `(1, ..., n)` on `Fin n`
* `finCycle`, the permutation that adds a fixed number to each element of `Fin n`
and proves various lemmas about them.
-/
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 cutsat⟩ = ⟨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
/-- The permutation on `Fin n` that adds `k` to each number. -/
@[simps]
def finCycle (k : Fin n) : Equiv.Perm (Fin n) where
toFun i := i + k
invFun i := i - k
left_inv i := by haveI := NeZero.of_pos k.pos; simp
right_inv i := by haveI := NeZero.of_pos k.pos; simp
lemma finCycle_eq_finRotate_iterate {k : Fin n} : finCycle k = (finRotate n)^[k.1] := by
match n with
| 0 => exact k.elim0
| n + 1 =>
ext i; induction k using Fin.induction with
| zero => simp
| succ k ih =>
rw [Fin.val_eq_val, Fin.coe_castSucc] at ih
rw [Fin.val_succ, Function.iterate_succ', Function.comp_apply, ← ih, finRotate_succ_apply,
finCycle_apply, finCycle_apply, add_assoc, Fin.coeSucc_eq_succ] |
.lake/packages/mathlib/Mathlib/Logic/Embedding/Basic.lean | import Mathlib.Data.Option.Basic
import Mathlib.Data.Prod.Basic
import Mathlib.Data.Prod.PProd
import Mathlib.Data.Sum.Basic
import Mathlib.Logic.Equiv.Basic
/-!
# Injective functions
-/
universe u v w x
namespace Function
/-- `α ↪ β` is a bundled injective function. -/
structure Embedding (α : Sort*) (β : Sort*) where
/-- An embedding as a function. Use coercion instead. -/
toFun : α → β
/-- An embedding is an injective function. Use `Function.Embedding.injective` instead. -/
inj' : Injective toFun
/-- An embedding, a.k.a. a bundled injective function. -/
infixr:25 " ↪ " => Embedding
instance {α : Sort u} {β : Sort v} : FunLike (α ↪ β) α β where
coe := Embedding.toFun
coe_injective' f g h := by { cases f; cases g; congr }
instance {α : Sort u} {β : Sort v} : EmbeddingLike (α ↪ β) α β where
injective' := Embedding.inj'
initialize_simps_projections Embedding (toFun → apply)
instance {α β : Sort*} : CanLift (α → β) (α ↪ β) (↑) Injective where prf f hf := ⟨⟨f, hf⟩, rfl⟩
theorem exists_surjective_iff {α β : Sort*} :
(∃ f : α → β, Surjective f) ↔ Nonempty (α → β) ∧ Nonempty (β ↪ α) :=
⟨fun ⟨f, h⟩ ↦ ⟨⟨f⟩, ⟨⟨_, injective_surjInv h⟩⟩⟩, fun ⟨h, ⟨e⟩⟩ ↦ (nonempty_fun.mp h).elim
(fun _ ↦ ⟨isEmptyElim, (isEmptyElim <| e ·)⟩) fun _ ↦ ⟨_, invFun_surjective e.inj'⟩⟩
end Function
section Equiv
variable {α : Sort u} {β : Sort v} (f : α ≃ β)
/-- Convert an `α ≃ β` to `α ↪ β`.
This is also available as a coercion `Equiv.coeEmbedding`.
The explicit `Equiv.toEmbedding` version is preferred though, since the coercion can have issues
inferring the type of the resulting embedding. For example:
```lean
-- Works:
example (s : Finset (Fin 3)) (f : Equiv.Perm (Fin 3)) : s.map f.toEmbedding = s.map f := by simp
-- Error, `f` has type `Fin 3 ≃ Fin 3` but is expected to have type `Fin 3 ↪ ?m_1 : Type ?`
example (s : Finset (Fin 3)) (f : Equiv.Perm (Fin 3)) : s.map f = s.map f.toEmbedding := by simp
```
-/
protected def Equiv.toEmbedding : α ↪ β :=
⟨f, f.injective⟩
@[simp]
theorem Equiv.coe_toEmbedding : (f.toEmbedding : α → β) = f :=
rfl
theorem Equiv.toEmbedding_apply (a : α) : f.toEmbedding a = f a :=
rfl
theorem Equiv.toEmbedding_injective : Function.Injective (Equiv.toEmbedding : (α ≃ β) → (α ↪ β)) :=
fun _ _ h ↦ by rwa [DFunLike.ext'_iff] at h ⊢
instance Equiv.coeEmbedding : Coe (α ≃ β) (α ↪ β) :=
⟨Equiv.toEmbedding⟩
@[instance] abbrev Equiv.Perm.coeEmbedding : Coe (Equiv.Perm α) (α ↪ α) :=
Equiv.coeEmbedding
end Equiv
namespace Function
namespace Embedding
theorem coe_injective {α β} : @Injective (α ↪ β) (α → β) (fun f ↦ ↑f) :=
DFunLike.coe_injective
@[ext]
theorem ext {α β} {f g : Embedding α β} (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
instance {α β : Sort*} [IsEmpty α] : Unique (α ↪ β) where
default := ⟨isEmptyElim, Function.injective_of_subsingleton _⟩
uniq := by intro; ext v; exact isEmptyElim v
@[simp]
theorem toFun_eq_coe {α β} (f : α ↪ β) : toFun f = f :=
rfl
@[simp]
theorem coeFn_mk {α β} (f : α → β) (i) : (@mk _ _ f i : α → β) = f :=
rfl
@[simp]
theorem mk_coe {α β : Type*} (f : α ↪ β) (inj) : (⟨f, inj⟩ : α ↪ β) = f :=
rfl
protected theorem injective {α β} (f : α ↪ β) : Injective f :=
EmbeddingLike.injective f
theorem apply_eq_iff_eq {α β} (f : α ↪ β) (x y : α) : f x = f y ↔ x = y :=
EmbeddingLike.apply_eq_iff_eq f
/-- The identity map as a `Function.Embedding`. -/
@[refl, simps +simpRhs]
protected def refl (α : Sort*) : α ↪ α :=
⟨id, injective_id⟩
@[norm_cast]
theorem coe_refl (α : Sort*) : ⇑(Embedding.refl α) = id := rfl
/-- Composition of `f : α ↪ β` and `g : β ↪ γ`. -/
@[trans, simps +simpRhs]
protected def trans {α β γ} (f : α ↪ β) (g : β ↪ γ) : α ↪ γ :=
⟨g ∘ f, g.injective.comp f.injective⟩
@[norm_cast]
theorem coe_trans {α β γ} (f : α ↪ β) (g : β ↪ γ) : ⇑(f.trans g) = ⇑g ∘ ⇑f := rfl
instance : Trans Embedding Embedding Embedding := ⟨Embedding.trans⟩
@[simp] lemma mk_id {α} : mk id injective_id = .refl α := rfl
@[simp] lemma mk_trans_mk {α β γ} (f : α → β) (g : β → γ) (hf hg) :
(mk f hf).trans (mk g hg) = mk (g ∘ f) (hg.comp hf) := rfl
@[simp]
theorem equiv_toEmbedding_trans_symm_toEmbedding {α β : Sort*} (e : α ≃ β) :
e.toEmbedding.trans e.symm.toEmbedding = Embedding.refl _ := by
ext
simp
@[simp]
theorem equiv_symm_toEmbedding_trans_toEmbedding {α β : Sort*} (e : α ≃ β) :
e.symm.toEmbedding.trans e.toEmbedding = Embedding.refl _ := by
ext
simp
/-- Transfer an embedding along a pair of equivalences. -/
@[simps! -fullyApplied +simpRhs]
protected def congr {α : Sort u} {β : Sort v} {γ : Sort w} {δ : Sort x} (e₁ : α ≃ β) (e₂ : γ ≃ δ)
(f : α ↪ γ) : β ↪ δ :=
(Equiv.toEmbedding e₁.symm).trans (f.trans e₂.toEmbedding)
/-- A right inverse `surjInv` of a surjective function as an `Embedding`. -/
protected noncomputable def ofSurjective {α β} (f : β → α) (hf : Surjective f) : α ↪ β :=
⟨surjInv hf, injective_surjInv _⟩
/-- Convert a surjective `Embedding` to an `Equiv` -/
protected noncomputable def equivOfSurjective {α β} (f : α ↪ β) (hf : Surjective f) : α ≃ β :=
Equiv.ofBijective f ⟨f.injective, hf⟩
/-- There is always an embedding from an empty type. -/
protected def ofIsEmpty {α β} [IsEmpty α] : α ↪ β :=
⟨isEmptyElim, isEmptyElim⟩
/-- Change the value of an embedding `f` at one point. If the prescribed image
is already occupied by some `f a'`, then swap the values at these two points. -/
def setValue {α β : Sort*} (f : α ↪ β) (a : α) (b : β) [∀ a', Decidable (a' = a)]
[∀ a', Decidable (f a' = b)] : α ↪ β :=
⟨fun a' => if a' = a then b else if f a' = b then f a else f a', by
intro x y h
simp only at h
split_ifs at h <;> (try subst b) <;> (try simp only [f.injective.eq_iff] at *) <;> grind⟩
@[simp]
theorem setValue_eq {α β} (f : α ↪ β) (a : α) (b : β) [∀ a', Decidable (a' = a)]
[∀ a', Decidable (f a' = b)] : setValue f a b a = b := by
simp [setValue]
@[simp]
theorem setValue_eq_iff {α β} (f : α ↪ β) {a a' : α} {b : β} [∀ a', Decidable (a' = a)]
[∀ a', Decidable (f a' = b)] : setValue f a b a' = b ↔ a' = a :=
(setValue f a b).injective.eq_iff' <| setValue_eq ..
lemma setValue_eq_of_ne {α β} {f : α ↪ β} {a : α} {b : β} {c : α} [∀ a', Decidable (a' = a)]
[∀ a', Decidable (f a' = b)] (hc : c ≠ a) (hb : f c ≠ b) : setValue f a b c = f c := by
simp [setValue, hc, hb]
@[simp]
lemma setValue_right_apply_eq {α β} (f : α ↪ β) (a c : α) [∀ a', Decidable (a' = a)]
[∀ a', Decidable (f a' = f c)] : setValue f a (f c) c = f a := by
simp [setValue]
/-- Embedding into `Option α` using `some`. -/
@[simps -fullyApplied]
protected def some {α} : α ↪ Option α :=
⟨some, Option.some_injective α⟩
/-- A version of `Option.map` for `Function.Embedding`s. -/
@[simps -fullyApplied]
def optionMap {α β} (f : α ↪ β) : Option α ↪ Option β :=
⟨Option.map f, Option.map_injective f.injective⟩
/-- Embedding of a `Subtype`. -/
def subtype {α} (p : α → Prop) : Subtype p ↪ α :=
⟨Subtype.val, fun _ _ => Subtype.ext⟩
@[simp]
theorem subtype_apply {α} {p : α → Prop} (x : Subtype p) : subtype p x = x :=
rfl
theorem subtype_injective {α} (p : α → Prop) : Function.Injective (subtype p) :=
Subtype.coe_injective
@[simp]
theorem coe_subtype {α} (p : α → Prop) : ↑(subtype p) = Subtype.val :=
rfl
/-- `Quotient.out` as an embedding. -/
noncomputable def quotientOut (α) [s : Setoid α] : Quotient s ↪ α :=
⟨_, Quotient.out_injective⟩
@[simp]
theorem coe_quotientOut (α) [Setoid α] : ↑(quotientOut α) = Quotient.out :=
rfl
/-- Choosing an element `b : β` gives an embedding of `PUnit` into `β`. -/
def punit {β : Sort*} (b : β) : PUnit ↪ β :=
⟨fun _ => b, by
rintro ⟨⟩ ⟨⟩ _
rfl⟩
/-- The equivalence `one ↪ α` with `α`, for `Unique one`. -/
def oneEmbeddingEquiv {one α : Type*} [Unique one] : (one ↪ α) ≃ α where
toFun f := f default
invFun a := {
toFun := fun _ ↦ a
inj' x y h := by simp [Unique.uniq inferInstance] }
left_inv f := by ext; simp [Unique.uniq]
/-- Fixing an element `b : β` gives an embedding `α ↪ α × β`. -/
@[simps]
def sectL (α : Sort _) {β : Sort _} (b : β) : α ↪ α × β :=
⟨fun a => (a, b), fun _ _ h => congr_arg Prod.fst h⟩
/-- Fixing an element `a : α` gives an embedding `β ↪ α × β`. -/
@[simps]
def sectR {α : Sort _} (a : α) (β : Sort _) : β ↪ α × β :=
⟨fun b => (a, b), fun _ _ h => congr_arg Prod.snd h⟩
/-- If `e₁` and `e₂` are embeddings, then so is `Prod.map e₁ e₂ : (a, b) ↦ (e₁ a, e₂ b)`. -/
def prodMap {α β γ δ : Type*} (e₁ : α ↪ β) (e₂ : γ ↪ δ) : α × γ ↪ β × δ :=
⟨Prod.map e₁ e₂, e₁.injective.prodMap e₂.injective⟩
@[simp]
theorem coe_prodMap {α β γ δ : Type*} (e₁ : α ↪ β) (e₂ : γ ↪ δ) :
e₁.prodMap e₂ = Prod.map e₁ e₂ :=
rfl
/-- If `e₁` and `e₂` are embeddings,
then so is `fun ⟨a, b⟩ ↦ ⟨e₁ a, e₂ b⟩ : PProd α γ → PProd β δ`. -/
def pprodMap {α β γ δ : Sort*} (e₁ : α ↪ β) (e₂ : γ ↪ δ) : PProd α γ ↪ PProd β δ :=
⟨fun x => ⟨e₁ x.1, e₂ x.2⟩, e₁.injective.pprod_map e₂.injective⟩
section Sum
open Sum
/-- If `e₁` and `e₂` are embeddings, then so is `Sum.map e₁ e₂`. -/
def sumMap {α β γ δ : Type*} (e₁ : α ↪ β) (e₂ : γ ↪ δ) : α ⊕ γ ↪ β ⊕ δ :=
⟨Sum.map e₁ e₂, e₁.injective.sumMap e₂.injective⟩
@[simp]
theorem coe_sumMap {α β γ δ} (e₁ : α ↪ β) (e₂ : γ ↪ δ) : sumMap e₁ e₂ = Sum.map e₁ e₂ :=
rfl
/-- The embedding of `α` into the sum `α ⊕ β`. -/
@[simps]
def inl {α β : Type*} : α ↪ α ⊕ β :=
⟨Sum.inl, fun _ _ => Sum.inl.inj⟩
/-- The embedding of `β` into the sum `α ⊕ β`. -/
@[simps]
def inr {α β : Type*} : β ↪ α ⊕ β :=
⟨Sum.inr, fun _ _ => Sum.inr.inj⟩
end Sum
section Sigma
variable {α α' : Type*} {β : α → Type*} {β' : α' → Type*}
/-- `Sigma.mk` as a `Function.Embedding`. -/
@[simps apply]
def sigmaMk (a : α) : β a ↪ Σ x, β x :=
⟨Sigma.mk a, sigma_mk_injective⟩
attribute [grind =] sigmaMk_apply
/-- If `f : α ↪ α'` is an embedding and `g : Π a, β α ↪ β' (f α)` is a family
of embeddings, then `Sigma.map f g` is an embedding. -/
@[simps apply]
def sigmaMap (f : α ↪ α') (g : ∀ a, β a ↪ β' (f a)) : (Σ a, β a) ↪ Σ a', β' a' :=
⟨Sigma.map f fun a => g a, f.injective.sigma_map fun a => (g a).injective⟩
end Sigma
/-- Define an embedding `(Π a : α, β a) ↪ (Π a : α, γ a)` from a family of embeddings
`e : Π a, (β a ↪ γ a)`. This embedding sends `f` to `fun a ↦ e a (f a)`. -/
@[simps]
def piCongrRight {α : Sort*} {β γ : α → Sort*} (e : ∀ a, β a ↪ γ a) : (∀ a, β a) ↪ ∀ a, γ a :=
⟨fun f a => e a (f a), fun _ _ h => funext fun a => (e a).injective (congr_fun h a)⟩
/-- An embedding `e : α ↪ β` defines an embedding `(γ → α) ↪ (γ → β)` that sends each `f`
to `e ∘ f`. -/
def arrowCongrRight {α : Sort u} {β : Sort v} {γ : Sort w} (e : α ↪ β) : (γ → α) ↪ γ → β :=
piCongrRight fun _ => e
@[simp]
theorem arrowCongrRight_apply {α : Sort u} {β : Sort v} {γ : Sort w} (e : α ↪ β) (f : γ → α) :
arrowCongrRight e f = e ∘ f :=
rfl
/-- An embedding `e : α ↪ β` defines an embedding `(α → γ) ↪ (β → γ)` for any inhabited type `γ`.
This embedding sends each `f : α → γ` to a function `g : β → γ` such that `g ∘ e = f` and
`g y = default` whenever `y ∉ range e`. -/
noncomputable def arrowCongrLeft {α : Sort u} {β : Sort v} {γ : Sort w} [Inhabited γ] (e : α ↪ β) :
(α → γ) ↪ β → γ :=
⟨fun f => extend e f default, fun f₁ f₂ h =>
funext fun x => by simpa only [e.injective.extend_apply] using congr_fun h (e x)⟩
-- `simps` would generate this over-applied
@[simp]
theorem arrowCongrLeft_apply {α : Sort u} {β : Sort v} {γ : Sort w} [Inhabited γ] (e : α ↪ β)
(f : α → γ) :
arrowCongrLeft e f = extend e f default :=
rfl
@[simp]
theorem arrowCongrLeft_refl {α : Sort u} {γ : Sort w} [Inhabited γ] :
(Function.Embedding.refl α).arrowCongrLeft (γ := γ) = .refl _ := by
ext
simp [coe_refl]
@[simp]
theorem trans_arrowCongrLeft {α₁ : Sort u} {α₂ : Sort v} {α₃ : Sort x} {γ : Sort w}
[Inhabited γ] (e₁₂ : α₁ ↪ α₂) (e₂₃ : α₂ ↪ α₃) :
e₁₂.arrowCongrLeft.trans e₂₃.arrowCongrLeft = (e₁₂.trans e₂₃).arrowCongrLeft (γ := γ) := by
ext f a
simp only [trans_apply, arrowCongrLeft_apply, Pi.default_def, coe_trans]
rw [e₁₂.injective.extend_comp e₂₃.injective, Function.comp_def]
/-- Restrict both domain and codomain of an embedding. -/
protected def subtypeMap {α β} {p : α → Prop} {q : β → Prop} (f : α ↪ β)
(h : ∀ ⦃x⦄, p x → q (f x)) :
{ x : α // p x } ↪ { y : β // q y } :=
⟨Subtype.map f h, Subtype.map_injective h f.2⟩
open Set
theorem swap_apply {α β : Type*} [DecidableEq α] [DecidableEq β] (f : α ↪ β) (x y z : α) :
Equiv.swap (f x) (f y) (f z) = f (Equiv.swap x y z) :=
f.injective.swap_apply x y z
theorem swap_comp {α β : Type*} [DecidableEq α] [DecidableEq β] (f : α ↪ β) (x y : α) :
Equiv.swap (f x) (f y) ∘ f = f ∘ Equiv.swap x y :=
f.injective.swap_comp x y
end Embedding
end Function
namespace Equiv
open Function Embedding
/-- Given an equivalence to a subtype, produce an embedding to the elements of the corresponding
set. -/
@[simps!]
def asEmbedding {β α : Sort*} {p : β → Prop} (e : α ≃ Subtype p) : α ↪ β :=
e.toEmbedding.trans (subtype p)
/-- The type of embeddings `α ↪ β` is equivalent to
the subtype of all injective functions `α → β`. -/
def subtypeInjectiveEquivEmbedding (α β : Sort*) :
{ f : α → β // Injective f } ≃ (α ↪ β) where
toFun f := ⟨f.val, f.property⟩
invFun f := ⟨f, f.injective⟩
/-- If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then the type of embeddings `α₁ ↪ β₁`
is equivalent to the type of embeddings `α₂ ↪ β₂`. -/
@[simps apply]
def embeddingCongr {α β γ δ : Sort*} (h : α ≃ β) (h' : γ ≃ δ) : (α ↪ γ) ≃ (β ↪ δ) where
toFun f := f.congr h h'
invFun f := f.congr h.symm h'.symm
left_inv x := by
ext
simp
right_inv x := by
ext
simp
@[simp]
theorem embeddingCongr_refl {α β : Sort*} :
embeddingCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α ↪ β) :=
rfl
@[simp]
theorem embeddingCongr_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Sort*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂)
(e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
embeddingCongr (e₁.trans e₂) (e₁'.trans e₂') =
(embeddingCongr e₁ e₁').trans (embeddingCongr e₂ e₂') :=
rfl
@[simp]
theorem embeddingCongr_symm {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(embeddingCongr e₁ e₂).symm = embeddingCongr e₁.symm e₂.symm :=
rfl
theorem embeddingCongr_apply_trans {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂)
(ec : γ₁ ≃ γ₂) (f : α₁ ↪ β₁) (g : β₁ ↪ γ₁) :
Equiv.embeddingCongr ea ec (f.trans g) =
(Equiv.embeddingCongr ea eb f).trans (Equiv.embeddingCongr eb ec g) := by
ext
simp
@[simp]
theorem refl_toEmbedding {α : Type*} : (Equiv.refl α).toEmbedding = Embedding.refl α :=
rfl
@[simp]
theorem trans_toEmbedding {α β γ : Type*} (e : α ≃ β) (f : β ≃ γ) :
(e.trans f).toEmbedding = e.toEmbedding.trans f.toEmbedding :=
rfl
end Equiv
section Subtype
variable {α : Type*}
/-- A subtype `{x // p x ∨ q x}` over a disjunction of `p q : α → Prop` can be injectively split
into a sum of subtypes `{x // p x} ⊕ {x // q x}` such that `¬ p x` is sent to the right. -/
def subtypeOrLeftEmbedding (p q : α → Prop) [DecidablePred p] :
{ x // p x ∨ q x } ↪ { x // p x } ⊕ { x // q x } :=
⟨fun x => if h : p x then Sum.inl ⟨x, h⟩ else Sum.inr ⟨x, x.prop.resolve_left h⟩, by
intro x y
dsimp only
split_ifs <;> simp [Subtype.ext_iff]⟩
@[simp]
theorem subtypeOrLeftEmbedding_apply_left {p q : α → Prop} [DecidablePred p]
(x : { x // p x ∨ q x }) (hx : p x) :
subtypeOrLeftEmbedding p q x = Sum.inl ⟨x, hx⟩ :=
dif_pos hx
@[simp]
theorem subtypeOrLeftEmbedding_apply_right {p q : α → Prop} [DecidablePred p]
(x : { x // p x ∨ q x }) (hx : ¬p x) :
subtypeOrLeftEmbedding p q x = Sum.inr ⟨x, x.prop.resolve_left hx⟩ :=
dif_neg hx
@[grind =]
theorem subtypeOrLeftEmbedding_apply {p q : α → Prop} [DecidablePred p]
(x : { x // p x ∨ q x }) :
subtypeOrLeftEmbedding p q x =
if h : p x then Sum.inl ⟨x, h⟩ else Sum.inr ⟨x, x.prop.resolve_left h⟩ :=
rfl
/-- A subtype `{x // p x}` can be injectively sent to into a subtype `{x // q x}`,
if `p x → q x` for all `x : α`. -/
@[simps (attr := grind =)]
def Subtype.impEmbedding (p q : α → Prop) (h : ∀ x, p x → q x) : { x // p x } ↪ { x // q x } :=
⟨fun x => ⟨x, h x x.prop⟩, fun x y => by simp [Subtype.ext_iff]⟩
end Subtype |
.lake/packages/mathlib/Mathlib/Logic/Embedding/Set.lean | import Mathlib.Data.Set.Notation
import Mathlib.Order.SetNotation
import Mathlib.Logic.Embedding.Basic
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.Image
/-!
# Interactions between embeddings and sets.
-/
assert_not_exists WithTop
universe u v w x
open Set Set.Notation
section Equiv
variable {α : Sort u} {β : Sort v} (f : α ≃ β)
@[simp]
theorem Equiv.asEmbedding_range {α β : Sort _} {p : β → Prop} (e : α ≃ Subtype p) :
Set.range e.asEmbedding = setOf p :=
Set.ext fun x ↦ ⟨fun ⟨y, h⟩ ↦ h ▸ Subtype.coe_prop (e y), fun hs ↦ ⟨e.symm ⟨x, hs⟩, by simp⟩⟩
end Equiv
namespace Function
namespace Embedding
/-- Given an embedding `f : α ↪ β` and a point outside of `Set.range f`, construct an embedding
`Option α ↪ β`. -/
@[simps]
def optionElim {α β} (f : α ↪ β) (x : β) (h : x ∉ Set.range f) : Option α ↪ β :=
⟨Option.elim' x f, Option.injective_iff.2 ⟨f.2, h⟩⟩
/-- Equivalence between embeddings of `Option α` and a sigma type over the embeddings of `α`. -/
@[simps]
def optionEmbeddingEquiv (α β) : (Option α ↪ β) ≃ Σ f : α ↪ β, ↥(Set.range f)ᶜ where
toFun f := ⟨Embedding.some.trans f, f none, fun ⟨x, hx⟩ ↦ Option.some_ne_none x <| f.injective hx⟩
invFun f := f.1.optionElim f.2 f.2.2
left_inv f := ext <| by rintro (_ | _) <;> simp
right_inv := fun ⟨f, y, hy⟩ ↦ by ext <;> simp
/-- Restrict the codomain of an embedding. -/
def codRestrict {α β} (p : Set β) (f : α ↪ β) (H : ∀ a, f a ∈ p) : α ↪ p :=
⟨fun a ↦ ⟨f a, H a⟩, fun _ _ h ↦ f.injective (congr_arg Subtype.val h)⟩
@[simp]
theorem codRestrict_apply {α β} (p) (f : α ↪ β) (H a) : codRestrict p f H a = ⟨f a, H a⟩ :=
rfl
/-- `Set.image` as an embedding `Set α ↪ Set β`. -/
@[simps apply]
protected def image {α β} (f : α ↪ β) : Set α ↪ Set β :=
⟨image f, f.2.image_injective⟩
end Embedding
end Function
namespace Set
/-- The injection map is an embedding between subsets. -/
@[simps apply_coe]
def embeddingOfSubset {α} (s t : Set α) (h : s ⊆ t) : s ↪ t :=
⟨fun x ↦ ⟨x.1, h x.2⟩, fun ⟨x, hx⟩ ⟨y, hy⟩ h ↦ by
congr
injection h⟩
end Set
section Subtype
variable {α : Type*}
/-- A subtype `{x // p x ∨ q x}` over a disjunction of `p q : α → Prop` is equivalent to a sum of
subtypes `{x // p x} ⊕ {x // q x}` such that `¬ p x` is sent to the right, when
`Disjoint p q`.
See also `Equiv.sumCompl`, for when `IsCompl p q`. -/
@[simps (attr := grind =) apply]
def subtypeOrEquiv (p q : α → Prop) [DecidablePred p] (h : Disjoint p q) :
{ x // p x ∨ q x } ≃ { x // p x } ⊕ { x // q x } where
toFun := subtypeOrLeftEmbedding p q
invFun :=
Sum.elim (Subtype.impEmbedding _ _ fun x hx ↦ (Or.inl hx : p x ∨ q x))
(Subtype.impEmbedding _ _ fun x hx ↦ (Or.inr hx : p x ∨ q x))
left_inv x := by grind
right_inv x := by
cases x with
| inl x => grind
| inr x =>
simp only [Sum.elim_inr]
rw [subtypeOrLeftEmbedding_apply_right]
· grind
· suffices ¬p x by simpa
intro hp
simpa using h.le_bot x ⟨hp, x.prop⟩
@[simp, grind =]
theorem subtypeOrEquiv_symm_inl (p q : α → Prop) [DecidablePred p] (h : Disjoint p q)
(x : { x // p x }) : (subtypeOrEquiv p q h).symm (Sum.inl x) = ⟨x, Or.inl x.prop⟩ :=
rfl
@[simp, grind =]
theorem subtypeOrEquiv_symm_inr (p q : α → Prop) [DecidablePred p] (h : Disjoint p q)
(x : { x // q x }) : (subtypeOrEquiv p q h).symm (Sum.inr x) = ⟨x, Or.inr x.prop⟩ :=
rfl
end Subtype
section Disjoint
variable {α ι : Type*} {s t r : Set α}
/-- For disjoint `s t : Set α`, the natural injection from `↑s ⊕ ↑t` to `α`. -/
@[simps] def Function.Embedding.sumSet (h : Disjoint s t) : s ⊕ t ↪ α where
toFun := Sum.elim (↑) (↑)
inj' := by
rintro (⟨a, ha⟩ | ⟨a, ha⟩) (⟨b, hb⟩ | ⟨b, hb⟩)
· simp
· simpa using h.ne_of_mem ha hb
· simpa using h.symm.ne_of_mem ha hb
simp
@[norm_cast] lemma Function.Embedding.coe_sumSet (h : Disjoint s t) :
(Function.Embedding.sumSet h : s ⊕ t → α) = Sum.elim (↑) (↑) := rfl
@[simp] theorem Function.Embedding.sumSet_preimage_inl (h : Disjoint s t) :
.inl ⁻¹' (Function.Embedding.sumSet h ⁻¹' r) = r ∩ s := by
simp [Set.ext_iff]
@[simp] theorem Function.Embedding.sumSet_preimage_inr (h : Disjoint s t) :
.inr ⁻¹' (Function.Embedding.sumSet h ⁻¹' r) = r ∩ t := by
simp [Set.ext_iff]
@[simp] theorem Function.Embedding.sumSet_range {s t : Set α} (h : Disjoint s t) :
range (Function.Embedding.sumSet h) = s ∪ t := by
simp [Set.ext_iff]
open scoped Function -- required for scoped `on` notation
/-- For an indexed family `s : ι → Set α` of disjoint sets,
the natural injection from the sigma-type `(i : ι) × ↑(s i)` to `α`. -/
@[simps] def Function.Embedding.sigmaSet {s : ι → Set α} (h : Pairwise (Disjoint on s)) :
(i : ι) × s i ↪ α where
toFun x := x.2.1
inj' := by
rintro ⟨i, x, hx⟩ ⟨j, -, hx'⟩ rfl
obtain rfl : i = j := h.eq (not_disjoint_iff.2 ⟨_, hx, hx'⟩)
rfl
@[norm_cast] lemma Function.Embedding.coe_sigmaSet {s : ι → Set α} (h) :
(Function.Embedding.sigmaSet h : ((i : ι) × s i) → α) = fun x ↦ x.2.1 := rfl
@[simp] theorem Function.Embedding.sigmaSet_preimage {s : ι → Set α}
(h : Pairwise (Disjoint on s)) (i : ι) (r : Set α) :
Sigma.mk i ⁻¹' (Function.Embedding.sigmaSet h ⁻¹' r) = r ∩ s i := by
simp [Set.ext_iff]
@[simp] theorem Function.Embedding.sigmaSet_range {s : ι → Set α}
(h : Pairwise (Disjoint on s)) : Set.range (Function.Embedding.sigmaSet h) = ⋃ i, s i := by
simp [Set.ext_iff]
end Disjoint |
.lake/packages/mathlib/Mathlib/Logic/Function/Iterate.lean | import Mathlib.Logic.Function.Conjugate
/-!
# Iterations of a function
In this file we prove simple properties of `Nat.iterate f n` a.k.a. `f^[n]`:
* `iterate_zero`, `iterate_succ`, `iterate_succ'`, `iterate_add`, `iterate_mul`:
formulas for `f^[0]`, `f^[n+1]` (two versions), `f^[n+m]`, and `f^[n*m]`;
* `iterate_id` : `id^[n]=id`;
* `Injective.iterate`, `Surjective.iterate`, `Bijective.iterate` :
iterates of an injective/surjective/bijective function belong to the same class;
* `LeftInverse.iterate`, `RightInverse.iterate`, `Commute.iterate_left`, `Commute.iterate_right`,
`Commute.iterate_iterate`:
some properties of pairs of functions survive under iterations
* `iterate_fixed`, `Function.Semiconj.iterate_*`, `Function.Semiconj₂.iterate`:
if `f` fixes a point (resp., semiconjugates unary/binary operations), then so does `f^[n]`.
-/
universe u v
variable {α : Type u} {β : Type v}
/-- Iterate a function. -/
def Nat.iterate {α : Sort u} (op : α → α) : ℕ → α → α
| 0, a => a
| succ k, a => iterate op k (op a)
@[inherit_doc Nat.iterate]
notation:max f "^[" n "]" => Nat.iterate f n
namespace Function
open Function (Commute)
variable (f : α → α)
@[simp]
theorem iterate_zero : f^[0] = id :=
rfl
theorem iterate_zero_apply (x : α) : f^[0] x = x :=
rfl
@[simp]
theorem iterate_succ (n : ℕ) : f^[n.succ] = f^[n] ∘ f :=
rfl
theorem iterate_succ_apply (n : ℕ) (x : α) : f^[n.succ] x = f^[n] (f x) :=
rfl
@[simp]
theorem iterate_id (n : ℕ) : (id : α → α)^[n] = id :=
Nat.recOn n rfl fun n ihn ↦ by rw [iterate_succ, ihn, id_comp]
theorem iterate_add (m : ℕ) : ∀ n : ℕ, f^[m + n] = f^[m] ∘ f^[n]
| 0 => rfl
| Nat.succ n => by rw [Nat.add_succ, iterate_succ, iterate_succ, iterate_add m n]; rfl
theorem iterate_add_apply (m n : ℕ) (x : α) : f^[m + n] x = f^[m] (f^[n] x) := by
rw [iterate_add f m n]
rfl
-- can be proved by simp but this is shorter and more natural
@[simp high]
theorem iterate_one : f^[1] = f :=
funext fun _ ↦ rfl
theorem iterate_mul (m : ℕ) : ∀ n, f^[m * n] = f^[m]^[n]
| 0 => by simp only [Nat.mul_zero, iterate_zero]
| n + 1 => by simp only [Nat.mul_succ, iterate_one, iterate_add, iterate_mul m n]
variable {f}
theorem iterate_fixed {x} (h : f x = x) (n : ℕ) : f^[n] x = x :=
Nat.recOn n rfl fun n ihn ↦ by rw [iterate_succ_apply, h, ihn]
/-- If a function `g` is invariant under composition with a function `f` (i.e., `g ∘ f = g`), then
`g` is invariant under composition with any iterate of `f`. -/
theorem iterate_invariant {g : α → β} (h : g ∘ f = g) (n : ℕ) : g ∘ f^[n] = g := match n with
| 0 => by rw [iterate_zero, comp_id]
| m + 1 => by rwa [iterate_succ, ← comp_assoc, iterate_invariant h m]
theorem Injective.iterate (Hinj : Injective f) (n : ℕ) : Injective f^[n] :=
Nat.recOn n injective_id fun _ ihn ↦ ihn.comp Hinj
theorem Surjective.iterate (Hsurj : Surjective f) (n : ℕ) : Surjective f^[n] :=
Nat.recOn n surjective_id fun _ ihn ↦ ihn.comp Hsurj
theorem Bijective.iterate (Hbij : Bijective f) (n : ℕ) : Bijective f^[n] :=
⟨Hbij.1.iterate n, Hbij.2.iterate n⟩
namespace Semiconj
theorem iterate_right {f : α → β} {ga : α → α} {gb : β → β} (h : Semiconj f ga gb) (n : ℕ) :
Semiconj f ga^[n] gb^[n] :=
Nat.recOn n id_right fun _ ihn ↦ ihn.comp_right h
theorem iterate_left {g : ℕ → α → α} (H : ∀ n, Semiconj f (g n) (g <| n + 1)) (n k : ℕ) :
Semiconj f^[n] (g k) (g <| n + k) := by
induction n generalizing k with
| zero =>
rw [Nat.zero_add]
exact id_left
| succ n ihn =>
rw [Nat.add_right_comm, Nat.add_assoc]
exact (H k).trans (ihn (k + 1))
end Semiconj
namespace Commute
variable {g : α → α}
theorem iterate_right (h : Commute f g) (n : ℕ) : Commute f g^[n] :=
Semiconj.iterate_right h n
theorem iterate_left (h : Commute f g) (n : ℕ) : Commute f^[n] g :=
(h.symm.iterate_right n).symm
theorem iterate_iterate (h : Commute f g) (m n : ℕ) : Commute f^[m] g^[n] :=
(h.iterate_left m).iterate_right n
theorem iterate_eq_of_map_eq (h : Commute f g) (n : ℕ) {x} (hx : f x = g x) :
f^[n] x = g^[n] x :=
Nat.recOn n rfl fun n ihn ↦ by
simp only [iterate_succ_apply, hx, (h.iterate_left n).eq, ihn, ((refl g).iterate_right n).eq]
theorem comp_iterate (h : Commute f g) (n : ℕ) : (f ∘ g)^[n] = f^[n] ∘ g^[n] := by
induction n with
| zero => rfl
| succ n ihn =>
funext x
simp only [ihn, (h.iterate_right n).eq, iterate_succ, comp_apply]
variable (f)
theorem iterate_self (n : ℕ) : Commute f^[n] f :=
(refl f).iterate_left n
theorem self_iterate (n : ℕ) : Commute f f^[n] :=
(refl f).iterate_right n
theorem iterate_iterate_self (m n : ℕ) : Commute f^[m] f^[n] :=
(refl f).iterate_iterate m n
end Commute
theorem Semiconj₂.iterate {f : α → α} {op : α → α → α} (hf : Semiconj₂ f op op) (n : ℕ) :
Semiconj₂ f^[n] op op :=
Nat.recOn n (Semiconj₂.id_left op) fun _ ihn ↦ ihn.comp hf
variable (f)
theorem iterate_succ' (n : ℕ) : f^[n.succ] = f ∘ f^[n] := by
rw [iterate_succ, (Commute.self_iterate f n).comp_eq]
theorem iterate_succ_apply' (n : ℕ) (x : α) : f^[n.succ] x = f (f^[n] x) := by
rw [iterate_succ']
rfl
theorem iterate_pred_comp_of_pos {n : ℕ} (hn : 0 < n) : f^[n.pred] ∘ f = f^[n] := by
rw [← iterate_succ, Nat.succ_pred_eq_of_pos hn]
theorem comp_iterate_pred_of_pos {n : ℕ} (hn : 0 < n) : f ∘ f^[n.pred] = f^[n] := by
rw [← iterate_succ', Nat.succ_pred_eq_of_pos hn]
/-- A recursor for the iterate of a function. -/
@[elab_as_elim]
def Iterate.rec (motive : α → Sort*) {a : α} (arg : motive a)
{f : α → α} (app : ∀ a, motive a → motive (f a)) (n : ℕ) : motive (f^[n] a) :=
match n with
| 0 => arg
| m + 1 => Iterate.rec motive (app _ arg) app m
theorem Iterate.rec_zero (motive : α → Sort*) {f : α → α} (app : ∀ a, motive a → motive (f a))
{a : α} (arg : motive a) : Iterate.rec motive arg app 0 = arg :=
rfl
variable {f} {m n : ℕ} {a : α}
theorem LeftInverse.iterate {g : α → α} (hg : LeftInverse g f) (n : ℕ) :
LeftInverse g^[n] f^[n] :=
Nat.recOn n (fun _ ↦ rfl) fun n ihn ↦ by
rw [iterate_succ', iterate_succ]
exact ihn.comp hg
theorem RightInverse.iterate {g : α → α} (hg : RightInverse g f) (n : ℕ) :
RightInverse g^[n] f^[n] :=
LeftInverse.iterate hg n
theorem iterate_comm (f : α → α) (m n : ℕ) : f^[n]^[m] = f^[m]^[n] :=
(iterate_mul _ _ _).symm.trans (Eq.trans (by rw [Nat.mul_comm]) (iterate_mul _ _ _))
theorem iterate_commute (m n : ℕ) : Commute (fun f : α → α ↦ f^[m]) fun f ↦ f^[n] :=
fun f ↦ iterate_comm f m n
lemma iterate_add_eq_iterate (hf : Injective f) : f^[m + n] a = f^[n] a ↔ f^[m] a = a :=
Iff.trans (by rw [← iterate_add_apply, Nat.add_comm]) (hf.iterate n).eq_iff
alias ⟨iterate_cancel_of_add, _⟩ := iterate_add_eq_iterate
lemma iterate_cancel (hf : Injective f) (ha : f^[m] a = f^[n] a) : f^[m - n] a = a := by
obtain h | h := Nat.le_total m n
{ simp [Nat.sub_eq_zero_of_le h] }
{ exact iterate_cancel_of_add hf (by rwa [Nat.sub_add_cancel h]) }
theorem involutive_iff_iter_2_eq_id {α} {f : α → α} : Involutive f ↔ f^[2] = id :=
funext_iff.symm
end Function
namespace List
open Function
theorem foldl_const (f : α → α) (a : α) (l : List β) :
l.foldl (fun b _ ↦ f b) a = f^[l.length] a := by
induction l generalizing a with
| nil => rfl
| cons b l H => rw [length_cons, foldl, iterate_succ_apply, H]
theorem foldr_const (f : β → β) (b : β) : ∀ l : List α, l.foldr (fun _ ↦ f) b = f^[l.length] b
| [] => rfl
| a :: l => by rw [length_cons, foldr, foldr_const f b l, iterate_succ_apply']
end List
namespace Pi
variable {ι : Type*}
@[simp]
theorem map_iterate {α : ι → Type*} (f : ∀ i, α i → α i) (n : ℕ) :
(Pi.map f)^[n] = Pi.map fun i => (f i)^[n] := by
induction n <;> simp [*, map_comp_map]
end Pi |
.lake/packages/mathlib/Mathlib/Logic/Function/Conjugate.lean | import Mathlib.Logic.Function.Basic
/-!
# Semiconjugate and commuting maps
We define the following predicates:
* `Function.Semiconj`: `f : α → β` semiconjugates `ga : α → α` to `gb : β → β` if `f ∘ ga = gb ∘ f`;
* `Function.Semiconj₂`: `f : α → β` semiconjugates a binary operation `ga : α → α → α`
to `gb : β → β → β` if `f (ga x y) = gb (f x) (f y)`;
* `Function.Commute`: `f : α → α` commutes with `g : α → α` if `f ∘ g = g ∘ f`,
or equivalently `Semiconj f g g`.
-/
namespace Function
variable {α : Type*} {β : Type*} {γ : Type*}
/--
We say that `f : α → β` semiconjugates `ga : α → α` to `gb : β → β` if `f ∘ ga = gb ∘ f`.
We use `∀ x, f (ga x) = gb (f x)` as the definition, so given `h : Function.Semiconj f ga gb` and
`a : α`, we have `h a : f (ga a) = gb (f a)` and `h.comp_eq : f ∘ ga = gb ∘ f`.
-/
def Semiconj (f : α → β) (ga : α → α) (gb : β → β) : Prop :=
∀ x, f (ga x) = gb (f x)
namespace Semiconj
variable {f fab : α → β} {fbc : β → γ} {ga ga' : α → α} {gb gb' : β → β} {gc : γ → γ}
/-- Definition of `Function.Semiconj` in terms of functional equality. -/
lemma _root_.Function.semiconj_iff_comp_eq : Semiconj f ga gb ↔ f ∘ ga = gb ∘ f := funext_iff.symm
protected alias ⟨comp_eq, _⟩ := semiconj_iff_comp_eq
protected theorem eq (h : Semiconj f ga gb) (x : α) : f (ga x) = gb (f x) :=
h x
/-- If `f` semiconjugates `ga` to `gb` and `ga'` to `gb'`,
then it semiconjugates `ga ∘ ga'` to `gb ∘ gb'`. -/
theorem comp_right (h : Semiconj f ga gb) (h' : Semiconj f ga' gb') :
Semiconj f (ga ∘ ga') (gb ∘ gb') := fun x ↦ by
simp only [comp_apply, h.eq, h'.eq]
/-- If `fab : α → β` semiconjugates `ga` to `gb` and `fbc : β → γ` semiconjugates `gb` to `gc`,
then `fbc ∘ fab` semiconjugates `ga` to `gc`.
See also `Function.Semiconj.comp_left` for a version with reversed arguments. -/
protected theorem trans (hab : Semiconj fab ga gb) (hbc : Semiconj fbc gb gc) :
Semiconj (fbc ∘ fab) ga gc := fun x ↦ by
simp only [comp_apply, hab.eq, hbc.eq]
/-- If `fbc : β → γ` semiconjugates `gb` to `gc` and `fab : α → β` semiconjugates `ga` to `gb`,
then `fbc ∘ fab` semiconjugates `ga` to `gc`.
See also `Function.Semiconj.trans` for a version with reversed arguments.
**Backward compatibility note:** before 2024-01-13,
this lemma used to have the same order of arguments that `Function.Semiconj.trans` has now. -/
theorem comp_left (hbc : Semiconj fbc gb gc) (hab : Semiconj fab ga gb) :
Semiconj (fbc ∘ fab) ga gc :=
hab.trans hbc
/-- Any function semiconjugates the identity function to the identity function. -/
theorem id_right : Semiconj f id id := fun _ ↦ rfl
/-- The identity function semiconjugates any function to itself. -/
theorem id_left : Semiconj id ga ga := fun _ ↦ rfl
/-- If `f : α → β` semiconjugates `ga : α → α` to `gb : β → β`,
`ga'` is a right inverse of `ga`, and `gb'` is a left inverse of `gb`,
then `f` semiconjugates `ga'` to `gb'` as well. -/
theorem inverses_right (h : Semiconj f ga gb) (ha : RightInverse ga' ga) (hb : LeftInverse gb' gb) :
Semiconj f ga' gb' := fun x ↦ by
rw [← hb (f (ga' x)), ← h.eq, ha x]
/-- If `f` semiconjugates `ga` to `gb` and `f'` is both a left and a right inverse of `f`,
then `f'` semiconjugates `gb` to `ga`. -/
lemma inverse_left {f' : β → α} (h : Semiconj f ga gb)
(hf₁ : LeftInverse f' f) (hf₂ : RightInverse f' f) : Semiconj f' gb ga := fun x ↦ by
rw [← hf₁.injective.eq_iff, h, hf₂, hf₂]
/-- If `f : α → β` semiconjugates `ga : α → α` to `gb : β → β`,
then `Option.map f` semiconjugates `Option.map ga` to `Option.map gb`. -/
theorem option_map {f : α → β} {ga : α → α} {gb : β → β} (h : Semiconj f ga gb) :
Semiconj (Option.map f) (Option.map ga) (Option.map gb)
| none => rfl
| some _ => congr_arg some <| h _
end Semiconj
/--
Two maps `f g : α → α` commute if `f (g x) = g (f x)` for all `x : α`.
Given `h : Function.commute f g` and `a : α`, we have `h a : f (g a) = g (f a)` and
`h.comp_eq : f ∘ g = g ∘ f`.
-/
protected def Commute (f g : α → α) : Prop :=
Semiconj f g g
open Function (Commute)
/-- Reinterpret `Function.Semiconj f g g` as `Function.Commute f g`. These two predicates are
definitionally equal but have different dot-notation lemmas. -/
theorem Semiconj.commute {f g : α → α} (h : Semiconj f g g) : Commute f g := h
namespace Commute
variable {f f' g g' : α → α}
/-- Reinterpret `Function.Commute f g` as `Function.Semiconj f g g`. These two predicates are
definitionally equal but have different dot-notation lemmas. -/
theorem semiconj (h : Commute f g) : Semiconj f g g := h
@[refl]
theorem refl (f : α → α) : Commute f f := fun _ ↦ Eq.refl _
@[symm]
theorem symm (h : Commute f g) : Commute g f := fun x ↦ (h x).symm
/-- If `f` commutes with `g` and `g'`, then it commutes with `g ∘ g'`. -/
theorem comp_right (h : Commute f g) (h' : Commute f g') : Commute f (g ∘ g') :=
Semiconj.comp_right h h'
/-- If `f` and `f'` commute with `g`, then `f ∘ f'` commutes with `g` as well. -/
nonrec theorem comp_left (h : Commute f g) (h' : Commute f' g) : Commute (f ∘ f') g :=
h.comp_left h'
/-- Any self-map commutes with the identity map. -/
theorem id_right : Commute f id := Semiconj.id_right
/-- The identity map commutes with any self-map. -/
theorem id_left : Commute id f :=
Semiconj.id_left
/-- If `f` commutes with `g`, then `Option.map f` commutes with `Option.map g`. -/
nonrec theorem option_map {f g : α → α} (h : Commute f g) : Commute (Option.map f) (Option.map g) :=
h.option_map
end Commute
/--
A map `f` semiconjugates a binary operation `ga` to a binary operation `gb` if
for all `x`, `y` we have `f (ga x y) = gb (f x) (f y)`. E.g., a `MonoidHom`
semiconjugates `(*)` to `(*)`.
-/
def Semiconj₂ (f : α → β) (ga : α → α → α) (gb : β → β → β) : Prop :=
∀ x y, f (ga x y) = gb (f x) (f y)
namespace Semiconj₂
variable {f : α → β} {ga : α → α → α} {gb : β → β → β}
protected theorem eq (h : Semiconj₂ f ga gb) (x y : α) : f (ga x y) = gb (f x) (f y) :=
h x y
protected theorem comp_eq (h : Semiconj₂ f ga gb) : bicompr f ga = bicompl gb f f :=
funext fun x ↦ funext <| h x
theorem id_left (op : α → α → α) : Semiconj₂ id op op := fun _ _ ↦ rfl
theorem comp {f' : β → γ} {gc : γ → γ → γ} (hf' : Semiconj₂ f' gb gc) (hf : Semiconj₂ f ga gb) :
Semiconj₂ (f' ∘ f) ga gc := fun x y ↦ by simp only [hf'.eq, hf.eq, comp_apply]
theorem isAssociative_right [Std.Associative ga] (h : Semiconj₂ f ga gb) (h_surj : Surjective f) :
Std.Associative gb :=
⟨h_surj.forall₃.2 fun x₁ x₂ x₃ ↦ by simp only [← h.eq, Std.Associative.assoc (op := ga)]⟩
theorem isAssociative_left [Std.Associative gb] (h : Semiconj₂ f ga gb) (h_inj : Injective f) :
Std.Associative ga :=
⟨fun x₁ x₂ x₃ ↦ h_inj <| by simp only [h.eq, Std.Associative.assoc (op := gb)]⟩
theorem isIdempotent_right [Std.IdempotentOp ga] (h : Semiconj₂ f ga gb) (h_surj : Surjective f) :
Std.IdempotentOp gb :=
⟨h_surj.forall.2 fun x ↦ by simp only [← h.eq, Std.IdempotentOp.idempotent (op := ga)]⟩
theorem isIdempotent_left [Std.IdempotentOp gb] (h : Semiconj₂ f ga gb) (h_inj : Injective f) :
Std.IdempotentOp ga :=
⟨fun x ↦ h_inj <| by rw [h.eq, Std.IdempotentOp.idempotent (op := gb)]⟩
end Semiconj₂
end Function |
.lake/packages/mathlib/Mathlib/Logic/Function/FiberPartition.lean | import Mathlib.Data.Set.Insert
/-!
This file defines the type `f.Fiber` of fibers of a function `f : Y → Z`, and provides some API
to work with and construct terms of this type.
Note: this API is designed to be useful when defining the counit of the adjunction between
the functor which takes a set to the condensed set corresponding to locally constant maps to that
set, and the forgetful functor from the category of condensed sets to the category of sets
(see PR https://github.com/leanprover-community/mathlib4/pull/14027).
-/
assert_not_exists RelIso
variable {X Y Z : Type*}
namespace Function
/-- The indexing set of the partition. -/
def Fiber (f : Y → Z) : Type _ := Set.range (fun (x : Set.range f) ↦ f ⁻¹' {x.val})
namespace Fiber
/--
Any `a : Fiber f` is of the form `f ⁻¹' {x}` for some `x` in the image of `f`. We define `a.image`
as an arbitrary such `x`.
-/
noncomputable def image (f : Y → Z) (a : Fiber f) : Z := a.2.choose.1
lemma eq_fiber_image (f : Y → Z) (a : Fiber f) : a.1 = f ⁻¹' {a.image} := a.2.choose_spec.symm
/--
Given `y : Y`, `Fiber.mk f y` is the fiber of `f` that `y` belongs to, as an element of `Fiber f`.
-/
def mk (f : Y → Z) (y : Y) : Fiber f := ⟨f ⁻¹' {f y}, by simp⟩
/-- `y : Y` as a term of the type `Fiber.mk f y` -/
def mkSelf (f : Y → Z) (y : Y) : (mk f y).val := ⟨y, rfl⟩
lemma map_eq_image (f : Y → Z) (a : Fiber f) (x : a.1) : f x = a.image := by
have := a.2.choose_spec
rw [← Set.mem_singleton_iff, ← Set.mem_preimage]
convert x.prop
lemma mk_image (f : Y → Z) (y : Y) : (Fiber.mk f y).image = f y :=
(map_eq_image (x := mkSelf f y)).symm
lemma mem_iff_eq_image (f : Y → Z) (y : Y) (a : Fiber f) : y ∈ a.val ↔ f y = a.image :=
⟨fun h ↦ a.map_eq_image _ ⟨y, h⟩, fun h ↦ by rw [a.eq_fiber_image]; exact h⟩
/-- An arbitrary element of `a : Fiber f`. -/
noncomputable def preimage (f : Y → Z) (a : Fiber f) : Y := a.2.choose.2.choose
lemma map_preimage_eq_image (f : Y → Z) (a : Fiber f) : f a.preimage = a.image :=
a.2.choose.2.choose_spec
lemma fiber_nonempty (f : Y → Z) (a : Fiber f) : Set.Nonempty a.val := by
refine ⟨preimage f a, ?_⟩
rw [mem_iff_eq_image, ← map_preimage_eq_image]
lemma map_preimage_eq_image_map {W : Type*} (f : Y → Z) (g : Z → W) (a : Fiber (g ∘ f)) :
g (f a.preimage) = a.image := by rw [← map_preimage_eq_image, comp_apply]
lemma image_eq_image_mk (f : Y → Z) (g : X → Y) (a : Fiber (f ∘ g)) :
a.image = (Fiber.mk f (g (a.preimage _))).image := by
rw [← map_preimage_eq_image_map _ _ a, mk_image]
end Function.Fiber |
.lake/packages/mathlib/Mathlib/Logic/Function/DependsOn.lean | import Mathlib.Data.Set.Restrict
/-!
# Functions depending only on some variables
When dealing with a function `f : Π i, α i` depending on many variables, some operations
may get rid of the dependency on some variables (see `Function.updateFinset` or
`MeasureTheory.lmarginal` for example). However considering this new function
as having a different domain with fewer points is not comfortable in Lean, as it requires the use
of subtypes and can lead to tedious writing.
On the other hand one wants to be able for example to describe some function as constant
with respect to some variables, and be able to deduce this when applying transformations
mentioned above. This is why we introduce the predicate `DependsOn f s`, which states that
if `x` and `y` coincide over the set `s`, then `f x = f y`.
This is equivalent to `Function.FactorsThrough f s.restrict`.
## Main definition
* `DependsOn f s`: If `x` and `y` coincide over the set `s`, then `f x` equals `f y`.
## Main statement
* `dependsOn_iff_factorsThrough`: A function `f` depends on `s` if and only if it factors
through `s.restrict`.
## Implementation notes
When we write `DependsOn f s`, i.e. `f` only depends on `s`, it should be interpreted as
"`f` _potentially_ depends only on variables in `s`". However it might be the case
that `f` does not depend at all on variables in `s`, for example if `f` is constant.
As a consequence, `DependsOn f univ` is always true, see `dependsOn_univ`.
The predicate `DependsOn f s` can also be interpreted as saying that `f` is independent of all
the variables which are not in `s`. Although this phrasing might seem more natural, we choose to go
with `DependsOn` because writing mathematically "independent of variables in `s`" would boil down to
`∀ x y, (∀ i ∉ s, x i = y i) → f x = f y`, which is the same as `DependsOn f sᶜ`.
## Tags
depends on
-/
open Function Set
variable {ι : Type*} {α : ι → Type*} {β : Type*}
/-- A function `f` depends on `s` if, whenever `x` and `y` coincide over `s`, `f x = f y`.
It should be interpreted as "`f` _potentially_ depends only on variables in `s`".
However it might be the case that `f` does not depend at all on variables in `s`,
for example if `f` is constant. As a consequence, `DependsOn f univ` is always true,
see `dependsOn_univ`. -/
def DependsOn (f : (Π i, α i) → β) (s : Set ι) : Prop :=
∀ ⦃x y⦄, (∀ i ∈ s, x i = y i) → f x = f y
lemma dependsOn_iff_factorsThrough {f : (Π i, α i) → β} {s : Set ι} :
DependsOn f s ↔ FactorsThrough f s.restrict := by
rw [DependsOn, FactorsThrough]
simp [funext_iff]
lemma dependsOn_iff_exists_comp [Nonempty β] {f : (Π i, α i) → β} {s : Set ι} :
DependsOn f s ↔ ∃ g : (Π i : s, α i) → β, f = g ∘ s.restrict := by
rw [dependsOn_iff_factorsThrough, factorsThrough_iff]
lemma dependsOn_univ (f : (Π i, α i) → β) : DependsOn f univ :=
fun _ _ h ↦ congrArg _ <| funext fun i ↦ h i trivial
variable {f : (Π i, α i) → β}
/-- A constant function does not depend on any variable. -/
lemma dependsOn_const (b : β) : DependsOn (fun _ : Π i, α i ↦ b) ∅ := by simp [DependsOn]
lemma DependsOn.mono {s t : Set ι} (hst : s ⊆ t) (hf : DependsOn f s) : DependsOn f t :=
fun _ _ h ↦ hf fun i hi ↦ h i (hst hi)
/-- A function which depends on the empty set is constant. -/
lemma DependsOn.empty (hf : DependsOn f ∅) (x y : Π i, α i) : f x = f y := hf (by simp)
lemma Set.dependsOn_restrict (s : Set ι) : DependsOn (s.restrict (π := α)) s :=
fun _ _ h ↦ funext fun i ↦ h i.1 i.2 |
.lake/packages/mathlib/Mathlib/Logic/Function/FromTypes.lean | import Mathlib.Data.Fin.VecNotation
/-! # Function types of a given heterogeneous arity
This provides `Function.FromTypes`, such that `FromTypes ![α, β] τ = α → β → τ`.
Note that it is often preferable to use `((i : Fin n) → p i) → τ` in place of `FromTypes p τ`.
## Main definitions
* `Function.FromTypes p τ`: `n`-ary function `p 0 → p 1 → ... → p (n - 1) → β`.
-/
universe u
namespace Function
open Matrix (vecCons vecHead vecTail vecEmpty)
/-- The type of `n`-ary functions `p 0 → p 1 → ... → p (n - 1) → τ`. -/
def FromTypes : {n : ℕ} → (Fin n → Type u) → Type u → Type u
| 0 , _, τ => τ
| n + 1, p, τ => vecHead p → @FromTypes n (vecTail p) τ
theorem fromTypes_zero (p : Fin 0 → Type u) (τ : Type u) : FromTypes p τ = τ := rfl
theorem fromTypes_nil (τ : Type u) : FromTypes ![] τ = τ := fromTypes_zero ![] τ
-- prefer `fromTypes_cons` when it (syntactically) applies
theorem fromTypes_succ {n} (p : Fin (n + 1) → Type u) (τ : Type u) :
FromTypes p τ = (vecHead p → FromTypes (vecTail p) τ) := rfl
theorem fromTypes_cons {n} (α : Type u) (p : Fin n → Type u) (τ : Type u) :
FromTypes (vecCons α p) τ = (α → FromTypes p τ) := fromTypes_succ _ τ
/-- The definitional equality between `0`-ary heterogeneous functions into `τ` and `τ`. -/
@[simps!]
def fromTypes_zero_equiv (p : Fin 0 → Type u) (τ : Type u) :
FromTypes p τ ≃ τ := Equiv.refl _
/-- The definitional equality between `![]`-ary heterogeneous functions into `τ` and `τ`. -/
@[simps!]
def fromTypes_nil_equiv (τ : Type u) : FromTypes ![] τ ≃ τ :=
fromTypes_zero_equiv ![] τ
/-- The definitional equality between `p`-ary heterogeneous functions into `τ`
and function from `vecHead p` to `(vecTail p)`-ary heterogeneous functions into `τ`. -/
@[simps!]
def fromTypes_succ_equiv {n} (p : Fin (n + 1) → Type u) (τ : Type u) :
FromTypes p τ ≃ (vecHead p → FromTypes (vecTail p) τ) := Equiv.refl _
/-- The definitional equality between `(vecCons α p)`-ary heterogeneous functions into `τ`
and function from `α` to `p`-ary heterogeneous functions into `τ`. -/
@[simps!]
def fromTypes_cons_equiv {n} (α : Type u) (p : Fin n → Type u) (τ : Type u) :
FromTypes (vecCons α p) τ ≃ (α → FromTypes p τ) := fromTypes_succ_equiv _ _
namespace FromTypes
/-- Constant `n`-ary function with value `t`. -/
def const : {n : ℕ} → (p : Fin n → Type u) → {τ : Type u} → (t : τ) → FromTypes p τ
| 0, _, _, t => t
| n + 1, p, τ, t => fun _ => @const n (vecTail p) τ t
@[simp]
theorem const_zero (p : Fin 0 → Type u) {τ : Type u} (t : τ) : const p t = t :=
rfl
@[simp]
theorem const_succ {n} (p : Fin (n + 1) → Type u) {τ : Type u} (t : τ) :
const p t = fun _ => const (vecTail p) t := rfl
theorem const_succ_apply {n} (p : Fin (n + 1) → Type u) {τ : Type u} (t : τ)
(x : p 0) : const p t x = const (vecTail p) t := rfl
instance inhabited {n} {p : Fin n → Type u} {τ} [Inhabited τ] :
Inhabited (FromTypes p τ) := ⟨const p default⟩
end FromTypes
end Function |
.lake/packages/mathlib/Mathlib/Logic/Function/Basic.lean | import Mathlib.Data.Set.Defs
import Mathlib.Logic.Basic
import Mathlib.Logic.Function.Defs
import Mathlib.Logic.ExistsUnique
import Mathlib.Logic.Nonempty
import Mathlib.Logic.Nontrivial.Defs
import Batteries.Tactic.Init
import Mathlib.Order.Defs.Unbundled
/-!
# Miscellaneous function constructions and lemmas
-/
open Function
universe u v w x
namespace Function
section
variable {α β γ : Sort*} {f : α → β}
/-- Evaluate a function at an argument. Useful if you want to talk about the partially applied
`Function.eval x : (∀ x, β x) → β x`. -/
@[reducible, simp] def eval {β : α → Sort*} (x : α) (f : ∀ x, β x) : β x := f x
theorem eval_apply {β : α → Sort*} (x : α) (f : ∀ x, β x) : eval x f = f x :=
rfl
theorem const_def {y : β} : (fun _ : α ↦ y) = const α y :=
rfl
theorem const_injective [Nonempty α] : Injective (const α : β → α → β) := fun _ _ h ↦
let ⟨x⟩ := ‹Nonempty α›
congr_fun h x
@[simp]
theorem const_inj [Nonempty α] {y₁ y₂ : β} : const α y₁ = const α y₂ ↔ y₁ = y₂ :=
⟨fun h ↦ const_injective h, fun h ↦ h ▸ rfl⟩
theorem onFun_apply (f : β → β → γ) (g : α → β) (a b : α) : onFun f g a b = f (g a) (g b) :=
rfl
lemma hfunext {α α' : Sort u} {β : α → Sort v} {β' : α' → Sort v} {f : ∀ a, β a} {f' : ∀ a, β' a}
(hα : α = α') (h : ∀ a a', a ≍ a' → f a ≍ f' a') : f ≍ f' := by
subst hα
have : ∀ a, f a ≍ f' a := fun a ↦ h a a (HEq.refl a)
have : β = β' := by funext a; exact type_eq_of_heq (this a)
subst this
grind
theorem ne_iff {β : α → Sort*} {f₁ f₂ : ∀ a, β a} : f₁ ≠ f₂ ↔ ∃ a, f₁ a ≠ f₂ a :=
funext_iff.not.trans not_forall
lemma funext_iff_of_subsingleton [Subsingleton α] {g : α → β} (x y : α) :
f x = g y ↔ f = g := by
refine ⟨fun h ↦ funext fun z ↦ ?_, fun h ↦ ?_⟩
· rwa [Subsingleton.elim x z, Subsingleton.elim y z] at h
· rw [h, Subsingleton.elim x y]
theorem swap_lt {α} [LT α] : swap (· < · : α → α → _) = (· > ·) := rfl
theorem swap_le {α} [LE α] : swap (· ≤ · : α → α → _) = (· ≥ ·) := rfl
theorem swap_gt {α} [LT α] : swap (· > · : α → α → _) = (· < ·) := rfl
theorem swap_ge {α} [LE α] : swap (· ≥ · : α → α → _) = (· ≤ ·) := rfl
protected theorem Bijective.injective {f : α → β} (hf : Bijective f) : Injective f := hf.1
protected theorem Bijective.surjective {f : α → β} (hf : Bijective f) : Surjective f := hf.2
theorem not_injective_iff : ¬ Injective f ↔ ∃ a b, f a = f b ∧ a ≠ b := by
simp only [Injective, not_forall, exists_prop]
/-- If the co-domain `β` of an injective function `f : α → β` has decidable equality, then
the domain `α` also has decidable equality. -/
protected def Injective.decidableEq [DecidableEq β] (I : Injective f) : DecidableEq α :=
fun _ _ ↦ decidable_of_iff _ I.eq_iff
theorem Injective.of_comp {g : γ → α} (I : Injective (f ∘ g)) : Injective g :=
fun _ _ h ↦ I <| congr_arg f h
@[simp]
theorem Injective.of_comp_iff (hf : Injective f) (g : γ → α) :
Injective (f ∘ g) ↔ Injective g :=
⟨Injective.of_comp, hf.comp⟩
theorem Injective.of_comp_right {g : γ → α} (I : Injective (f ∘ g)) (hg : Surjective g) :
Injective f := fun x y h ↦ by
obtain ⟨x, rfl⟩ := hg x
obtain ⟨y, rfl⟩ := hg y
exact congr_arg g (I h)
theorem Surjective.bijective₂_of_injective {g : γ → α} (hf : Surjective f) (hg : Surjective g)
(I : Injective (f ∘ g)) : Bijective f ∧ Bijective g :=
⟨⟨I.of_comp_right hg, hf⟩, I.of_comp, hg⟩
@[simp]
theorem Injective.of_comp_iff' (f : α → β) {g : γ → α} (hg : Bijective g) :
Injective (f ∘ g) ↔ Injective f :=
⟨fun I ↦ I.of_comp_right hg.2, fun h ↦ h.comp hg.injective⟩
theorem Injective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i}
(hf : ∀ i, Injective (f i)) : Injective (Pi.map f) := fun _ _ h ↦
funext fun i ↦ hf i <| congrFun h _
/-- Composition by an injective function on the left is itself injective. -/
theorem Injective.comp_left {g : β → γ} (hg : Injective g) : Injective (g ∘ · : (α → β) → α → γ) :=
.piMap fun _ ↦ hg
theorem injective_comp_left_iff [Nonempty α] {g : β → γ} :
Injective (g ∘ · : (α → β) → α → γ) ↔ Injective g :=
⟨fun h b₁ b₂ eq ↦ Nonempty.elim ‹_›
(congr_fun <| h (a₁ := fun _ ↦ b₁) (a₂ := fun _ ↦ b₂) <| funext fun _ ↦ eq), (·.comp_left)⟩
@[nontriviality] theorem injective_of_subsingleton [Subsingleton α] (f : α → β) : Injective f :=
fun _ _ _ ↦ Subsingleton.elim _ _
@[nontriviality] theorem bijective_of_subsingleton [Subsingleton α] (f : α → α) : Bijective f :=
⟨injective_of_subsingleton f, fun a ↦ ⟨a, Subsingleton.elim ..⟩⟩
lemma Injective.dite (p : α → Prop) [DecidablePred p]
{f : {a : α // p a} → β} {f' : {a : α // ¬ p a} → β}
(hf : Injective f) (hf' : Injective f')
(im_disj : ∀ {x x' : α} {hx : p x} {hx' : ¬ p x'}, f ⟨x, hx⟩ ≠ f' ⟨x', hx'⟩) :
Function.Injective (fun x ↦ if h : p x then f ⟨x, h⟩ else f' ⟨x, h⟩) := fun x₁ x₂ h => by
dsimp only at h
by_cases h₁ : p x₁ <;> by_cases h₂ : p x₂
· rw [dif_pos h₁, dif_pos h₂] at h; injection (hf h)
· rw [dif_pos h₁, dif_neg h₂] at h; exact (im_disj h).elim
· rw [dif_neg h₁, dif_pos h₂] at h; exact (im_disj h.symm).elim
· rw [dif_neg h₁, dif_neg h₂] at h; injection (hf' h)
theorem Surjective.of_comp {g : γ → α} (S : Surjective (f ∘ g)) : Surjective f := fun y ↦
let ⟨x, h⟩ := S y
⟨g x, h⟩
@[simp]
theorem Surjective.of_comp_iff (f : α → β) {g : γ → α} (hg : Surjective g) :
Surjective (f ∘ g) ↔ Surjective f :=
⟨Surjective.of_comp, fun h ↦ h.comp hg⟩
theorem Surjective.of_comp_left {g : γ → α} (S : Surjective (f ∘ g)) (hf : Injective f) :
Surjective g := fun a ↦ let ⟨c, hc⟩ := S (f a); ⟨c, hf hc⟩
theorem Injective.bijective₂_of_surjective {g : γ → α} (hf : Injective f) (hg : Injective g)
(S : Surjective (f ∘ g)) : Bijective f ∧ Bijective g :=
⟨⟨hf, S.of_comp⟩, hg, S.of_comp_left hf⟩
@[simp]
theorem Surjective.of_comp_iff' (hf : Bijective f) (g : γ → α) :
Surjective (f ∘ g) ↔ Surjective g :=
⟨fun S ↦ S.of_comp_left hf.1, hf.surjective.comp⟩
instance decidableEqPFun (p : Prop) [Decidable p] (α : p → Type*) [∀ hp, DecidableEq (α hp)] :
DecidableEq (∀ hp, α hp)
| f, g => decidable_of_iff (∀ hp, f hp = g hp) funext_iff.symm
protected theorem Surjective.forall (hf : Surjective f) {p : β → Prop} :
(∀ y, p y) ↔ ∀ x, p (f x) :=
⟨fun h x ↦ h (f x), fun h y ↦
let ⟨x, hx⟩ := hf y
hx ▸ h x⟩
protected theorem Surjective.forall₂ (hf : Surjective f) {p : β → β → Prop} :
(∀ y₁ y₂, p y₁ y₂) ↔ ∀ x₁ x₂, p (f x₁) (f x₂) :=
hf.forall.trans <| forall_congr' fun _ ↦ hf.forall
protected theorem Surjective.forall₃ (hf : Surjective f) {p : β → β → β → Prop} :
(∀ y₁ y₂ y₃, p y₁ y₂ y₃) ↔ ∀ x₁ x₂ x₃, p (f x₁) (f x₂) (f x₃) :=
hf.forall.trans <| forall_congr' fun _ ↦ hf.forall₂
protected theorem Surjective.exists (hf : Surjective f) {p : β → Prop} :
(∃ y, p y) ↔ ∃ x, p (f x) :=
⟨fun ⟨y, hy⟩ ↦
let ⟨x, hx⟩ := hf y
⟨x, hx.symm ▸ hy⟩,
fun ⟨x, hx⟩ ↦ ⟨f x, hx⟩⟩
protected theorem Surjective.exists₂ (hf : Surjective f) {p : β → β → Prop} :
(∃ y₁ y₂, p y₁ y₂) ↔ ∃ x₁ x₂, p (f x₁) (f x₂) :=
hf.exists.trans <| exists_congr fun _ ↦ hf.exists
protected theorem Surjective.exists₃ (hf : Surjective f) {p : β → β → β → Prop} :
(∃ y₁ y₂ y₃, p y₁ y₂ y₃) ↔ ∃ x₁ x₂ x₃, p (f x₁) (f x₂) (f x₃) :=
hf.exists.trans <| exists_congr fun _ ↦ hf.exists₂
theorem Surjective.injective_comp_right (hf : Surjective f) : Injective fun g : β → γ ↦ g ∘ f :=
fun _ _ h ↦ funext <| hf.forall.2 <| congr_fun h
theorem injective_comp_right_iff_surjective {γ : Type*} [Nontrivial γ] :
Injective (fun g : β → γ ↦ g ∘ f) ↔ Surjective f := by
refine ⟨not_imp_not.mp fun not_surj inj ↦ not_subsingleton γ ⟨fun c c' ↦ ?_⟩,
(·.injective_comp_right)⟩
have ⟨b₀, hb⟩ := not_forall.mp not_surj
classical have := inj (a₁ := fun _ ↦ c) (a₂ := (if · = b₀ then c' else c)) ?_
· simpa using congr_fun this b₀
ext a; simp only [comp_apply, if_neg fun h ↦ hb ⟨a, h⟩]
protected theorem Surjective.right_cancellable (hf : Surjective f) {g₁ g₂ : β → γ} :
g₁ ∘ f = g₂ ∘ f ↔ g₁ = g₂ :=
hf.injective_comp_right.eq_iff
theorem surjective_of_right_cancellable_Prop (h : ∀ g₁ g₂ : β → Prop, g₁ ∘ f = g₂ ∘ f → g₁ = g₂) :
Surjective f :=
injective_comp_right_iff_surjective.mp h
theorem bijective_iff_existsUnique (f : α → β) : Bijective f ↔ ∀ b : β, ∃! a : α, f a = b :=
⟨fun hf b ↦
let ⟨a, ha⟩ := hf.surjective b
⟨a, ha, fun _ ha' ↦ hf.injective (ha'.trans ha.symm)⟩,
fun he ↦ ⟨fun {_a a'} h ↦ (he (f a')).unique h rfl, fun b ↦ (he b).exists⟩⟩
/-- Shorthand for using projection notation with `Function.bijective_iff_existsUnique`. -/
protected theorem Bijective.existsUnique {f : α → β} (hf : Bijective f) (b : β) :
∃! a : α, f a = b :=
(bijective_iff_existsUnique f).mp hf b
theorem Bijective.existsUnique_iff {f : α → β} (hf : Bijective f) {p : β → Prop} :
(∃! y, p y) ↔ ∃! x, p (f x) :=
⟨fun ⟨y, hpy, hy⟩ ↦
let ⟨x, hx⟩ := hf.surjective y
⟨x, by simpa [hx], fun z (hz : p (f z)) ↦ hf.injective <| hx.symm ▸ hy _ hz⟩,
fun ⟨x, hpx, hx⟩ ↦
⟨f x, hpx, fun y hy ↦
let ⟨z, hz⟩ := hf.surjective y
hz ▸ congr_arg f (hx _ (by simpa [hz]))⟩⟩
theorem Bijective.of_comp_iff (f : α → β) {g : γ → α} (hg : Bijective g) :
Bijective (f ∘ g) ↔ Bijective f :=
and_congr (Injective.of_comp_iff' _ hg) (Surjective.of_comp_iff _ hg.surjective)
theorem Bijective.of_comp_iff' {f : α → β} (hf : Bijective f) (g : γ → α) :
Function.Bijective (f ∘ g) ↔ Function.Bijective g :=
and_congr (Injective.of_comp_iff hf.injective _) (Surjective.of_comp_iff' hf _)
/-- **Cantor's diagonal argument** implies that there are no surjective functions from `α`
to `Set α`. -/
theorem cantor_surjective {α} (f : α → Set α) : ¬Surjective f
| h => let ⟨D, e⟩ := h {a | ¬ f a a}
@iff_not_self (D ∈ f D) <| iff_of_eq <| congr_arg (D ∈ ·) e
/-- **Cantor's diagonal argument** implies that there are no injective functions from `Set α`
to `α`. -/
theorem cantor_injective {α : Type*} (f : Set α → α) : ¬Injective f
| i => cantor_surjective (fun a ↦ {b | ∀ U, a = f U → U b}) <|
RightInverse.surjective (fun U ↦ Set.ext fun _ ↦ ⟨fun h ↦ h U rfl, fun h _ e ↦ i e ▸ h⟩)
/-- There is no surjection from `α : Type u` into `Type (max u v)`. This theorem
demonstrates why `Type : Type` would be inconsistent in Lean. -/
theorem not_surjective_Type {α : Type u} (f : α → Type max u v) : ¬Surjective f := by
intro hf
let T : Type max u v := Sigma f
cases hf (Set T) with | intro U hU =>
let g : Set T → T := fun s ↦ ⟨U, cast hU.symm s⟩
have hg : Injective g := by
intro s t h
suffices cast hU (g s).2 = cast hU (g t).2 by
simp only [g, cast_cast, cast_eq] at this
assumption
· congr
exact cantor_injective g hg
/-- `g` is a partial inverse to `f` (an injective but not necessarily
surjective function) if `g y = some x` implies `f x = y`, and `g y = none`
implies that `y` is not in the range of `f`. -/
def IsPartialInv {α β} (f : α → β) (g : β → Option α) : Prop :=
∀ x y, g y = some x ↔ f x = y
theorem isPartialInv_left {α β} {f : α → β} {g} (H : IsPartialInv f g) (x) : g (f x) = some x :=
(H _ _).2 rfl
theorem injective_of_isPartialInv {α β} {f : α → β} {g} (H : IsPartialInv f g) :
Injective f := fun _ _ h ↦
Option.some.inj <| ((H _ _).2 h).symm.trans ((H _ _).2 rfl)
theorem injective_of_isPartialInv_right {α β} {f : α → β} {g} (H : IsPartialInv f g) (x y b)
(h₁ : b ∈ g x) (h₂ : b ∈ g y) : x = y :=
((H _ _).1 h₁).symm.trans ((H _ _).1 h₂)
theorem LeftInverse.comp_eq_id {f : α → β} {g : β → α} (h : LeftInverse f g) : f ∘ g = id :=
funext h
theorem leftInverse_iff_comp {f : α → β} {g : β → α} : LeftInverse f g ↔ f ∘ g = id :=
⟨LeftInverse.comp_eq_id, congr_fun⟩
theorem RightInverse.comp_eq_id {f : α → β} {g : β → α} (h : RightInverse f g) : g ∘ f = id :=
funext h
theorem rightInverse_iff_comp {f : α → β} {g : β → α} : RightInverse f g ↔ g ∘ f = id :=
⟨RightInverse.comp_eq_id, congr_fun⟩
theorem LeftInverse.comp {f : α → β} {g : β → α} {h : β → γ} {i : γ → β} (hf : LeftInverse f g)
(hh : LeftInverse h i) : LeftInverse (h ∘ f) (g ∘ i) :=
fun a ↦ show h (f (g (i a))) = a by rw [hf (i a), hh a]
theorem RightInverse.comp {f : α → β} {g : β → α} {h : β → γ} {i : γ → β} (hf : RightInverse f g)
(hh : RightInverse h i) : RightInverse (h ∘ f) (g ∘ i) :=
LeftInverse.comp hh hf
theorem LeftInverse.rightInverse {f : α → β} {g : β → α} (h : LeftInverse g f) : RightInverse f g :=
h
theorem RightInverse.leftInverse {f : α → β} {g : β → α} (h : RightInverse g f) : LeftInverse f g :=
h
theorem LeftInverse.surjective {f : α → β} {g : β → α} (h : LeftInverse f g) : Surjective f :=
h.rightInverse.surjective
theorem RightInverse.injective {f : α → β} {g : β → α} (h : RightInverse f g) : Injective f :=
h.leftInverse.injective
theorem LeftInverse.rightInverse_of_injective {f : α → β} {g : β → α} (h : LeftInverse f g)
(hf : Injective f) : RightInverse f g :=
fun x ↦ hf <| h (f x)
theorem LeftInverse.rightInverse_of_surjective {f : α → β} {g : β → α} (h : LeftInverse f g)
(hg : Surjective g) : RightInverse f g :=
fun x ↦ let ⟨y, hy⟩ := hg x; hy ▸ congr_arg g (h y)
theorem RightInverse.leftInverse_of_surjective {f : α → β} {g : β → α} :
RightInverse f g → Surjective f → LeftInverse f g :=
LeftInverse.rightInverse_of_surjective
theorem RightInverse.leftInverse_of_injective {f : α → β} {g : β → α} :
RightInverse f g → Injective g → LeftInverse f g :=
LeftInverse.rightInverse_of_injective
theorem LeftInverse.eq_rightInverse {f : α → β} {g₁ g₂ : β → α} (h₁ : LeftInverse g₁ f)
(h₂ : RightInverse g₂ f) : g₁ = g₂ :=
calc
g₁ = g₁ ∘ f ∘ g₂ := by rw [h₂.comp_eq_id, comp_id]
_ = g₂ := by rw [← comp_assoc, h₁.comp_eq_id, id_comp]
/-- We can use choice to construct explicitly a partial inverse for
a given injective function `f`. -/
noncomputable def partialInv {α β} (f : α → β) (b : β) : Option α :=
open scoped Classical in
if h : ∃ a, f a = b then some (Classical.choose h) else none
theorem partialInv_of_injective {α β} {f : α → β} (I : Injective f) : IsPartialInv f (partialInv f)
| a, b =>
⟨fun h =>
open scoped Classical in
have hpi : partialInv f b = if h : ∃ a, f a = b then some (Classical.choose h) else none :=
rfl
if h' : ∃ a, f a = b
then by rw [hpi, dif_pos h'] at h
injection h with h
subst h
apply Classical.choose_spec h'
else by rw [hpi, dif_neg h'] at h; contradiction,
fun e => e ▸ have h : ∃ a', f a' = f a := ⟨_, rfl⟩
(dif_pos h).trans (congr_arg _ (I <| Classical.choose_spec h))⟩
theorem partialInv_left {α β} {f : α → β} (I : Injective f) : ∀ x, partialInv f (f x) = some x :=
isPartialInv_left (partialInv_of_injective I)
end
section InvFun
variable {α β : Sort*} [Nonempty α] {f : α → β} {b : β}
/-- The inverse of a function (which is a left inverse if `f` is injective
and a right inverse if `f` is surjective). -/
-- Explicit Sort so that `α` isn't inferred to be Prop via `exists_prop_decidable`
noncomputable def invFun {α : Sort u} {β} [Nonempty α] (f : α → β) : β → α :=
open scoped Classical in
fun y ↦ if h : (∃ x, f x = y) then h.choose else Classical.arbitrary α
theorem invFun_eq (h : ∃ a, f a = b) : f (invFun f b) = b := by
simp only [invFun, dif_pos h, h.choose_spec]
theorem apply_invFun_apply {α β : Type*} {f : α → β} {a : α} :
f (@invFun _ _ ⟨a⟩ f (f a)) = f a :=
@invFun_eq _ _ ⟨a⟩ _ _ ⟨_, rfl⟩
theorem invFun_neg (h : ¬∃ a, f a = b) : invFun f b = Classical.choice ‹_› :=
dif_neg h
theorem invFun_eq_of_injective_of_rightInverse {g : β → α} (hf : Injective f)
(hg : RightInverse g f) : invFun f = g :=
funext fun b ↦
hf
(by
rw [hg b]
exact invFun_eq ⟨g b, hg b⟩)
theorem rightInverse_invFun (hf : Surjective f) : RightInverse (invFun f) f :=
fun b ↦ invFun_eq <| hf b
theorem leftInverse_invFun (hf : Injective f) : LeftInverse (invFun f) f :=
fun b ↦ hf <| invFun_eq ⟨b, rfl⟩
theorem invFun_surjective (hf : Injective f) : Surjective (invFun f) :=
(leftInverse_invFun hf).surjective
theorem invFun_comp (hf : Injective f) : invFun f ∘ f = id :=
funext <| leftInverse_invFun hf
theorem Injective.hasLeftInverse (hf : Injective f) : HasLeftInverse f :=
⟨invFun f, leftInverse_invFun hf⟩
theorem injective_iff_hasLeftInverse : Injective f ↔ HasLeftInverse f :=
⟨Injective.hasLeftInverse, HasLeftInverse.injective⟩
end InvFun
section SurjInv
variable {α : Sort u} {β : Sort v} {γ : Sort w} {f : α → β}
/-- The inverse of a surjective function. (Unlike `invFun`, this does not require
`α` to be inhabited.) -/
noncomputable def surjInv {f : α → β} (h : Surjective f) (b : β) : α :=
Classical.choose (h b)
theorem surjInv_eq (h : Surjective f) (b) : f (surjInv h b) = b :=
Classical.choose_spec (h b)
@[simp]
lemma comp_surjInv (hf : f.Surjective) : f ∘ f.surjInv hf = id :=
funext (Function.surjInv_eq _)
theorem rightInverse_surjInv (hf : Surjective f) : RightInverse (surjInv hf) f :=
surjInv_eq hf
theorem leftInverse_surjInv (hf : Bijective f) : LeftInverse (surjInv hf.2) f :=
rightInverse_of_injective_of_leftInverse hf.1 (rightInverse_surjInv hf.2)
theorem Surjective.hasRightInverse (hf : Surjective f) : HasRightInverse f :=
⟨_, rightInverse_surjInv hf⟩
theorem surjective_iff_hasRightInverse : Surjective f ↔ HasRightInverse f :=
⟨Surjective.hasRightInverse, HasRightInverse.surjective⟩
theorem bijective_iff_has_inverse : Bijective f ↔ ∃ g, LeftInverse g f ∧ RightInverse g f :=
⟨fun hf ↦ ⟨_, leftInverse_surjInv hf, rightInverse_surjInv hf.2⟩, fun ⟨_, gl, gr⟩ ↦
⟨gl.injective, gr.surjective⟩⟩
theorem injective_surjInv (h : Surjective f) : Injective (surjInv h) :=
(rightInverse_surjInv h).injective
theorem surjective_to_subsingleton [na : Nonempty α] [Subsingleton β] (f : α → β) :
Surjective f :=
fun _ ↦ let ⟨a⟩ := na; ⟨a, Subsingleton.elim _ _⟩
theorem Surjective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i}
(hf : ∀ i, Surjective (f i)) : Surjective (Pi.map f) := fun g ↦
⟨fun i ↦ surjInv (hf i) (g i), funext fun _ ↦ rightInverse_surjInv _ _⟩
/-- Composition by a surjective function on the left is itself surjective. -/
theorem Surjective.comp_left {g : β → γ} (hg : Surjective g) :
Surjective (g ∘ · : (α → β) → α → γ) :=
.piMap fun _ ↦ hg
theorem surjective_comp_left_iff [Nonempty α] {g : β → γ} :
Surjective (g ∘ · : (α → β) → α → γ) ↔ Surjective g := by
refine ⟨fun h c ↦ Nonempty.elim ‹_› fun a ↦ ?_, (·.comp_left)⟩
have ⟨f, hf⟩ := h fun _ ↦ c
exact ⟨f a, congr_fun hf _⟩
theorem Bijective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i}
(hf : ∀ i, Bijective (f i)) : Bijective (Pi.map f) :=
⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2⟩
/-- Composition by a bijective function on the left is itself bijective. -/
theorem Bijective.comp_left {g : β → γ} (hg : Bijective g) :
Bijective (g ∘ · : (α → β) → α → γ) :=
⟨hg.injective.comp_left, hg.surjective.comp_left⟩
end SurjInv
section Update
variable {α : Sort u} {β : α → Sort v} {α' : Sort w} [DecidableEq α]
{f : (a : α) → β a} {a : α} {b : β a}
/-- Replacing the value of a function at a given point by a given value. -/
@[grind]
def update (f : ∀ a, β a) (a' : α) (v : β a') (a : α) : β a :=
if h : a = a' then Eq.ndrec v h.symm else f a
@[simp]
theorem update_self (a : α) (v : β a) (f : ∀ a, β a) : update f a v a = v :=
dif_pos rfl
@[simp]
theorem update_of_ne {a a' : α} (h : a ≠ a') (v : β a') (f : ∀ a, β a) : update f a' v a = f a :=
dif_neg h
/-- On non-dependent functions, `Function.update` can be expressed as an `ite` -/
theorem update_apply {β : Sort*} (f : α → β) (a' : α) (b : β) (a : α) :
update f a' b a = if a = a' then b else f a := by
rcases Decidable.eq_or_ne a a' with rfl | hne <;> simp [*]
@[nontriviality]
theorem update_eq_const_of_subsingleton [Subsingleton α] (a : α) (v : α') (f : α → α') :
update f a v = const α v :=
funext fun a' ↦ Subsingleton.elim a a' ▸ update_self ..
theorem surjective_eval {α : Sort u} {β : α → Sort v} [h : ∀ a, Nonempty (β a)] (a : α) :
Surjective (eval a : (∀ a, β a) → β a) := fun b ↦
⟨@update _ _ (Classical.decEq α) (fun a ↦ (h a).some) a b,
@update_self _ _ (Classical.decEq α) _ _ _⟩
theorem update_injective (f : ∀ a, β a) (a' : α) : Injective (update f a') := fun v v' h ↦ by
have := congr_fun h a'
rwa [update_self, update_self] at this
lemma forall_update_iff (f : ∀ a, β a) {a : α} {b : β a} (p : ∀ a, β a → Prop) :
(∀ x, p x (update f a b x)) ↔ p a b ∧ ∀ x, x ≠ a → p x (f x) := by
rw [← and_forall_ne a, update_self]
simp +contextual
theorem exists_update_iff (f : ∀ a, β a) {a : α} {b : β a} (p : ∀ a, β a → Prop) :
(∃ x, p x (update f a b x)) ↔ p a b ∨ ∃ x ≠ a, p x (f x) := by
rw [← not_forall_not, forall_update_iff f fun a b ↦ ¬p a b]
simp [-not_and, not_and_or]
theorem update_eq_iff {a : α} {b : β a} {f g : ∀ a, β a} :
update f a b = g ↔ b = g a ∧ ∀ x ≠ a, f x = g x :=
funext_iff.trans <| forall_update_iff _ fun x y ↦ y = g x
theorem eq_update_iff {a : α} {b : β a} {f g : ∀ a, β a} :
g = update f a b ↔ g a = b ∧ ∀ x ≠ a, g x = f x :=
funext_iff.trans <| forall_update_iff _ fun x y ↦ g x = y
@[simp] lemma update_eq_self_iff : update f a b = f ↔ b = f a := by simp [update_eq_iff]
@[simp] lemma eq_update_self_iff : f = update f a b ↔ f a = b := by simp [eq_update_iff]
lemma ne_update_self_iff : f ≠ update f a b ↔ f a ≠ b := eq_update_self_iff.not
lemma update_ne_self_iff : update f a b ≠ f ↔ b ≠ f a := update_eq_self_iff.not
@[simp]
theorem update_eq_self (a : α) (f : ∀ a, β a) : update f a (f a) = f :=
update_eq_iff.2 ⟨rfl, fun _ _ ↦ rfl⟩
theorem update_comp_eq_of_forall_ne' {α'} (g : ∀ a, β a) {f : α' → α} {i : α} (a : β i)
(h : ∀ x, f x ≠ i) : (fun j ↦ (update g i a) (f j)) = fun j ↦ g (f j) :=
funext fun _ ↦ update_of_ne (h _) _ _
variable [DecidableEq α']
/-- Non-dependent version of `Function.update_comp_eq_of_forall_ne'` -/
theorem update_comp_eq_of_forall_ne {α β : Sort*} (g : α' → β) {f : α → α'} {i : α'} (a : β)
(h : ∀ x, f x ≠ i) : update g i a ∘ f = g ∘ f :=
update_comp_eq_of_forall_ne' g a h
theorem update_comp_eq_of_injective' (g : ∀ a, β a) {f : α' → α} (hf : Function.Injective f)
(i : α') (a : β (f i)) : (fun j ↦ update g (f i) a (f j)) = update (fun i ↦ g (f i)) i a :=
eq_update_iff.2 ⟨update_self .., fun _ hj ↦ update_of_ne (hf.ne hj) _ _⟩
theorem update_apply_of_injective
(g : ∀ a, β a) {f : α' → α} (hf : Function.Injective f)
(i : α') (a : β (f i)) (j : α') :
update g (f i) a (f j) = update (fun i ↦ g (f i)) i a j :=
congr_fun (update_comp_eq_of_injective' g hf i a) j
/-- Non-dependent version of `Function.update_comp_eq_of_injective'` -/
theorem update_comp_eq_of_injective {β : Sort*} (g : α' → β) {f : α → α'}
(hf : Function.Injective f) (i : α) (a : β) :
Function.update g (f i) a ∘ f = Function.update (g ∘ f) i a :=
update_comp_eq_of_injective' g hf i a
/-- Recursors can be pushed inside `Function.update`.
The `ctor` argument should be a one-argument constructor like `Sum.inl`,
and `recursor` should be an inductive recursor partially applied in all but that constructor,
such as `(Sum.rec · g)`.
In future, we should build some automation to generate applications like `Option.rec_update` for all
inductive types. -/
lemma rec_update {ι κ : Sort*} {α : κ → Sort*} [DecidableEq ι] [DecidableEq κ]
{ctor : ι → κ} (hctor : Function.Injective ctor)
(recursor : ((i : ι) → α (ctor i)) → ((i : κ) → α i))
(h : ∀ f i, recursor f (ctor i) = f i)
(h2 : ∀ f₁ f₂ k, (∀ i, ctor i ≠ k) → recursor f₁ k = recursor f₂ k)
(f : (i : ι) → α (ctor i)) (i : ι) (x : α (ctor i)) :
recursor (update f i x) = update (recursor f) (ctor i) x := by
ext k
by_cases h : ∃ i, ctor i = k
· obtain ⟨i', rfl⟩ := h
obtain rfl | hi := eq_or_ne i' i
· simp [h]
· have hk := hctor.ne hi
simp [h, hi, hk, Function.update_of_ne]
· rw [not_exists] at h
rw [h2 _ f _ h]
rw [Function.update_of_ne (Ne.symm <| h i)]
@[simp]
lemma _root_.Option.rec_update {α : Type*} {β : Option α → Sort*} [DecidableEq α]
(f : β none) (g : ∀ a, β (.some a)) (a : α) (x : β (.some a)) :
Option.rec f (update g a x) = update (Option.rec f g) (.some a) x :=
Function.rec_update (@Option.some.inj _) (Option.rec f) (fun _ _ => rfl) (fun
| _, _, some _, h => (h _ rfl).elim
| _, _, none, _ => rfl) _ _ _
theorem apply_update {ι : Sort*} [DecidableEq ι] {α β : ι → Sort*} (f : ∀ i, α i → β i)
(g : ∀ i, α i) (i : ι) (v : α i) (j : ι) :
f j (update g i v j) = update (fun k ↦ f k (g k)) i (f i v) j := by
by_cases h : j = i
· subst j
simp
· simp [h]
theorem apply_update₂ {ι : Sort*} [DecidableEq ι] {α β γ : ι → Sort*} (f : ∀ i, α i → β i → γ i)
(g : ∀ i, α i) (h : ∀ i, β i) (i : ι) (v : α i) (w : β i) (j : ι) :
f j (update g i v j) (update h i w j) = update (fun k ↦ f k (g k) (h k)) i (f i v w) j := by
by_cases h : j = i
· subst j
simp
· simp [h]
theorem pred_update (P : ∀ ⦃a⦄, β a → Prop) (f : ∀ a, β a) (a' : α) (v : β a') (a : α) :
P (update f a' v a) ↔ a = a' ∧ P v ∨ a ≠ a' ∧ P (f a) := by
rw [apply_update P, update_apply, ite_prop_iff_or]
theorem comp_update {α' : Sort*} {β : Sort*} (f : α' → β) (g : α → α') (i : α) (v : α') :
f ∘ update g i v = update (f ∘ g) i (f v) :=
funext <| apply_update _ _ _ _
theorem update_comm {α} [DecidableEq α] {β : α → Sort*} {a b : α} (h : a ≠ b) (v : β a) (w : β b)
(f : ∀ a, β a) : update (update f a v) b w = update (update f b w) a v := by
funext c
simp only [update]
by_cases h₁ : c = b <;> by_cases h₂ : c = a
· rw [dif_pos h₁, dif_pos h₂]
cases h (h₂.symm.trans h₁)
· rw [dif_pos h₁, dif_pos h₁, dif_neg h₂]
· rw [dif_neg h₁, dif_neg h₁]
· rw [dif_neg h₁, dif_neg h₁]
@[simp]
theorem update_idem {α} [DecidableEq α] {β : α → Sort*} {a : α} (v w : β a) (f : ∀ a, β a) :
update (update f a v) a w = update f a w := by
funext b
by_cases h : b = a <;> simp [update, h]
@[simp]
theorem _root_.Pi.map_update {ι : Sort*} [DecidableEq ι] {α β : ι → Sort*}
{f : ∀ i, α i → β i}
(g : ∀ i, α i) (i : ι) (a : α i) :
Pi.map f (Function.update g i a) = Function.update (Pi.map f g) i (f i a) := by
ext j
obtain rfl | hij := eq_or_ne j i <;> simp [*]
@[simp]
theorem _root_.Pi.map_injective
{ι : Sort*} {α β : ι → Sort*} [∀ i, Nonempty (α i)] {f : ∀ i, α i → β i} :
Injective (Pi.map f) ↔ ∀ i, Injective (f i) where
mp h i x y hxy := by
classical
have : Inhabited (∀ i, α i) := ⟨fun _ => Classical.choice inferInstance⟩
replace h := @h (Function.update default i x) (Function.update default i y) ?_
· simpa using congrFun h i
rw [Pi.map_update, Pi.map_update, hxy]
mpr := .piMap
end Update
noncomputable section Extend
variable {α β γ : Sort*} {f : α → β}
/-- Extension of a function `g : α → γ` along a function `f : α → β`.
For every `a : α`, `f a` is sent to `g a`. `f` might not be surjective, so we use an auxiliary
function `j : β → γ` by sending `b : β` not in the range of `f` to `j b`. If you do not care about
the behavior outside the range, `j` can be used as a junk value by setting it to be `0` or
`Classical.arbitrary` (assuming `γ` is nonempty).
This definition is mathematically meaningful only when `f a₁ = f a₂ → g a₁ = g a₂` (spelled
`g.FactorsThrough f`). In particular this holds if `f` is injective.
A typical use case is extending a function from a subtype to the entire type. If you wish to extend
`g : {b : β // p b} → γ` to a function `β → γ`, you should use `Function.extend Subtype.val g j`. -/
def extend (f : α → β) (g : α → γ) (j : β → γ) : β → γ := fun b ↦
open scoped Classical in
if h : ∃ a, f a = b then g (Classical.choose h) else j b
/-- g factors through f : `f a = f b → g a = g b` -/
def FactorsThrough (g : α → γ) (f : α → β) : Prop :=
∀ ⦃a b⦄, f a = f b → g a = g b
theorem extend_def (f : α → β) (g : α → γ) (e' : β → γ) (b : β) [Decidable (∃ a, f a = b)] :
extend f g e' b = if h : ∃ a, f a = b then g (Classical.choose h) else e' b := by
unfold extend
congr
lemma Injective.factorsThrough (hf : Injective f) (g : α → γ) : g.FactorsThrough f :=
fun _ _ h => congr_arg g (hf h)
lemma FactorsThrough.extend_apply {g : α → γ} (hf : g.FactorsThrough f) (e' : β → γ) (a : α) :
extend f g e' (f a) = g a := by
classical
simp only [extend_def, dif_pos, exists_apply_eq_apply]
exact hf (Classical.choose_spec (exists_apply_eq_apply f a))
@[simp]
theorem Injective.extend_apply (hf : Injective f) (g : α → γ) (e' : β → γ) (a : α) :
extend f g e' (f a) = g a :=
(hf.factorsThrough g).extend_apply e' a
@[simp]
theorem extend_apply' (g : α → γ) (e' : β → γ) (b : β) (hb : ¬∃ a, f a = b) :
extend f g e' b = e' b := by
classical
simp [Function.extend_def, hb]
@[simp]
theorem extend_id (g : α → γ) (e' : α → γ) :
extend id g e' = g :=
funext <| injective_id.extend_apply g _
theorem Injective.extend_comp {α₁ α₂ α₃ : Sort*} {f₁₂ : α₁ → α₂} (h₁₂ : Function.Injective f₁₂)
{f₂₃ : α₂ → α₃} (h₂₃ : Function.Injective f₂₃) (g : α₁ → γ) (e' : α₃ → γ) :
extend (f₂₃ ∘ f₁₂) g e' = extend f₂₃ (extend f₁₂ g (e' ∘ f₂₃)) e' := by
ext a
by_cases h₃ : ∃ b, f₂₃ b = a
· obtain ⟨b, rfl⟩ := h₃
rw [Injective.extend_apply h₂₃]
by_cases h₂ : ∃ c, f₁₂ c = b
· obtain ⟨c, rfl⟩ := h₂
rw [h₁₂.extend_apply]
exact (h₂₃.comp h₁₂).extend_apply _ _ _
· rw [extend_apply' _ _ _ h₂, extend_apply', comp_apply]
exact fun h ↦ h₂ (Exists.casesOn h fun c hc ↦ Exists.intro c (h₂₃ hc))
· rw [extend_apply' _ _ _ h₃, extend_apply']
exact fun h ↦ h₃ (Exists.casesOn h fun c hc ↦ Exists.intro (f₁₂ c) (hc))
lemma factorsThrough_iff (g : α → γ) [Nonempty γ] : g.FactorsThrough f ↔ ∃ (e : β → γ), g = e ∘ f :=
⟨fun hf => ⟨extend f g (const β (Classical.arbitrary γ)),
funext (fun x => by simp only [comp_apply, hf.extend_apply])⟩,
fun h _ _ hf => by rw [Classical.choose_spec h, comp_apply, comp_apply, hf]⟩
lemma apply_extend {δ} {g : α → γ} (F : γ → δ) (f : α → β) (e' : β → γ) (b : β) :
F (extend f g e' b) = extend f (F ∘ g) (F ∘ e') b :=
open scoped Classical in apply_dite F _ _ _
theorem extend_injective (hf : Injective f) (e' : β → γ) : Injective fun g ↦ extend f g e' := by
intro g₁ g₂ hg
refine funext fun x ↦ ?_
have H := congr_fun hg (f x)
simp only [hf.extend_apply] at H
exact H
lemma FactorsThrough.extend_comp {g : α → γ} (e' : β → γ) (hf : FactorsThrough g f) :
extend f g e' ∘ f = g :=
funext fun a => hf.extend_apply e' a
@[simp]
lemma extend_const (f : α → β) (c : γ) : extend f (fun _ ↦ c) (fun _ ↦ c) = fun _ ↦ c :=
funext fun _ ↦ open scoped Classical in ite_id _
@[simp]
theorem extend_comp (hf : Injective f) (g : α → γ) (e' : β → γ) : extend f g e' ∘ f = g :=
funext fun a ↦ hf.extend_apply g e' a
theorem Injective.surjective_comp_right' (hf : Injective f) (g₀ : β → γ) :
Surjective fun g : β → γ ↦ g ∘ f :=
fun g ↦ ⟨extend f g g₀, Function.extend_comp hf _ _⟩
theorem Injective.surjective_comp_right [Nonempty γ] (hf : Injective f) :
Surjective fun g : β → γ ↦ g ∘ f :=
hf.surjective_comp_right' fun _ ↦ Classical.choice ‹_›
theorem surjective_comp_right_iff_injective {γ : Type*} [Nontrivial γ] :
Surjective (fun g : β → γ ↦ g ∘ f) ↔ Injective f := by
classical
refine ⟨not_imp_not.mp fun not_inj surj ↦ not_subsingleton γ ⟨fun c c' ↦ ?_⟩,
(·.surjective_comp_right)⟩
simp only [Injective, not_forall] at not_inj
have ⟨a₁, a₂, eq, ne⟩ := not_inj
have ⟨f, hf⟩ := surj (if · = a₂ then c else c')
have h₁ := congr_fun hf a₁
have h₂ := congr_fun hf a₂
simp only [comp_apply, if_neg ne, reduceIte] at h₁ h₂
rw [← h₁, eq, h₂]
theorem Bijective.comp_right (hf : Bijective f) : Bijective fun g : β → γ ↦ g ∘ f :=
⟨hf.surjective.injective_comp_right, fun g ↦
⟨g ∘ surjInv hf.surjective,
by simp only [comp_assoc g _ f, (leftInverse_surjInv hf).comp_eq_id, comp_id]⟩⟩
end Extend
namespace FactorsThrough
protected theorem rfl {α β : Sort*} {f : α → β} : FactorsThrough f f := fun _ _ ↦ id
theorem comp_left {α β γ δ : Sort*} {f : α → β} {g : α → γ} (h : FactorsThrough g f) (g' : γ → δ) :
FactorsThrough (g' ∘ g) f := fun _x _y hxy ↦
congr_arg g' (h hxy)
theorem comp_right {α β γ δ : Sort*} {f : α → β} {g : α → γ} (h : FactorsThrough g f) (g' : δ → α) :
FactorsThrough (g ∘ g') (f ∘ g') := fun _x _y hxy ↦
h hxy
end FactorsThrough
section CurryAndUncurry
theorem uncurry_def {α β γ} (f : α → β → γ) : uncurry f = fun p ↦ f p.1 p.2 :=
rfl
theorem uncurry_injective {α β γ} : Function.Injective (uncurry : (α → β → γ) → _) :=
LeftInverse.injective curry_uncurry
theorem curry_injective {α β γ} : Function.Injective (curry : (α × β → γ) → _) :=
LeftInverse.injective uncurry_curry
theorem uncurry_flip {α β γ} (f : α → β → γ) : uncurry (flip f) = uncurry f ∘ Prod.swap :=
rfl
theorem flip_curry {α β γ} (f : α × β → γ) : flip (curry f) = curry (f ∘ Prod.swap) :=
rfl
theorem curry_update {α α' β : Type*} [DecidableEq α] [DecidableEq α']
(f : α × α' → β) (aa' : α × α') (b : β) :
curry (Function.update f aa' b) =
Function.update (curry f) aa'.1 (Function.update (curry f aa'.1) aa'.2 b) := by
ext a a'
let ⟨a₂, a₂'⟩ := aa'
obtain rfl | ha := eq_or_ne a a₂ <;> obtain rfl | ha' := eq_or_ne a' a₂' <;> simp [*]
theorem uncurry_update_update {α α' β : Type*} [DecidableEq α] [DecidableEq α']
(f : α → α' → β) (a : α) (a' : α') (b : β) :
uncurry (Function.update f a (Function.update (f a) a' b)) =
Function.update (uncurry f) (a, a') b := by
apply curry_injective
simp [curry_update]
end CurryAndUncurry
section Bicomp
variable {α β γ δ ε : Type*}
/-- Compose a binary function `f` with a pair of unary functions `g` and `h`.
If both arguments of `f` have the same type and `g = h`, then `bicompl f g g = f on g`. -/
def bicompl (f : γ → δ → ε) (g : α → γ) (h : β → δ) (a b) :=
f (g a) (h b)
/-- Compose a unary function `f` with a binary function `g`. -/
def bicompr (f : γ → δ) (g : α → β → γ) (a b) :=
f (g a b)
-- Suggested local notation:
local notation f " ∘₂ " g => bicompr f g
theorem uncurry_bicompr (f : α → β → γ) (g : γ → δ) : uncurry (g ∘₂ f) = g ∘ uncurry f :=
rfl
theorem uncurry_bicompl (f : γ → δ → ε) (g : α → γ) (h : β → δ) :
uncurry (bicompl f g h) = uncurry f ∘ Prod.map g h :=
rfl
end Bicomp
section Uncurry
variable {α β γ δ : Type*}
/-- Records a way to turn an element of `α` into a function from `β` to `γ`. The most generic use
is to recursively uncurry. For instance `f : α → β → γ → δ` will be turned into
`↿f : α × β × γ → δ`. One can also add instances for bundled maps. -/
class HasUncurry (α : Type*) (β : outParam Type*) (γ : outParam Type*) where
/-- Uncurrying operator. The most generic use is to recursively uncurry. For instance
`f : α → β → γ → δ` will be turned into `↿f : α × β × γ → δ`. One can also add instances
for bundled maps. -/
uncurry : α → β → γ
@[inherit_doc] prefix:max "↿" => HasUncurry.uncurry
instance hasUncurryBase : HasUncurry (α → β) α β :=
⟨id⟩
instance hasUncurryInduction [HasUncurry β γ δ] : HasUncurry (α → β) (α × γ) δ :=
⟨fun f p ↦ ↿(f p.1) p.2⟩
end Uncurry
/-- A function is involutive, if `f ∘ f = id`. -/
def Involutive {α} (f : α → α) : Prop :=
∀ x, f (f x) = x
theorem _root_.Bool.involutive_not : Involutive not :=
Bool.not_not
namespace Involutive
variable {α : Sort u} {f : α → α} (h : Involutive f)
include h
@[simp]
theorem comp_self : f ∘ f = id :=
funext h
protected theorem leftInverse : LeftInverse f f := h
theorem leftInverse_iff {g : α → α} :
g.LeftInverse f ↔ g = f :=
⟨fun hg ↦ funext fun x ↦ by rw [← h x, hg, h], fun he ↦ he ▸ h.leftInverse⟩
protected theorem rightInverse : RightInverse f f := h
protected theorem injective : Injective f := h.leftInverse.injective
protected theorem surjective : Surjective f := fun x ↦ ⟨f x, h x⟩
protected theorem bijective : Bijective f := ⟨h.injective, h.surjective⟩
/-- Involuting an `ite` of an involuted value `x : α` negates the `Prop` condition in the `ite`. -/
protected theorem ite_not (P : Prop) [Decidable P] (x : α) :
f (ite P x (f x)) = ite (¬P) x (f x) := by rw [apply_ite f, h, ite_not]
/-- An involution commutes across an equality. Compare to `Function.Injective.eq_iff`. -/
protected theorem eq_iff {x y : α} : f x = y ↔ x = f y :=
h.injective.eq_iff' (h y)
end Involutive
lemma not_involutive : Involutive Not := fun _ ↦ propext not_not
lemma not_injective : Injective Not := not_involutive.injective
lemma not_surjective : Surjective Not := not_involutive.surjective
lemma not_bijective : Bijective Not := not_involutive.bijective
@[simp]
lemma symmetric_apply_eq_iff {α : Sort*} {f : α → α} : Symmetric (f · = ·) ↔ Involutive f := by
simp [Symmetric, Involutive]
/-- The property of a binary function `f : α → β → γ` being injective.
Mathematically this should be thought of as the corresponding function `α × β → γ` being injective.
-/
def Injective2 {α β γ : Sort*} (f : α → β → γ) : Prop :=
∀ ⦃a₁ a₂ b₁ b₂⦄, f a₁ b₁ = f a₂ b₂ → a₁ = a₂ ∧ b₁ = b₂
namespace Injective2
variable {α β γ : Sort*} {f : α → β → γ}
/-- A binary injective function is injective when only the left argument varies. -/
protected theorem left (hf : Injective2 f) (b : β) : Function.Injective fun a ↦ f a b :=
fun _ _ h ↦ (hf h).left
/-- A binary injective function is injective when only the right argument varies. -/
protected theorem right (hf : Injective2 f) (a : α) : Function.Injective (f a) :=
fun _ _ h ↦ (hf h).right
protected theorem uncurry {α β γ : Type*} {f : α → β → γ} (hf : Injective2 f) :
Function.Injective (uncurry f) :=
fun ⟨_, _⟩ ⟨_, _⟩ h ↦ (hf h).elim (congr_arg₂ _)
/-- As a map from the left argument to a unary function, `f` is injective. -/
theorem left' (hf : Injective2 f) [Nonempty β] : Function.Injective f := fun _ _ h ↦
let ⟨b⟩ := ‹Nonempty β›
hf.left b <| (congr_fun h b :)
/-- As a map from the right argument to a unary function, `f` is injective. -/
theorem right' (hf : Injective2 f) [Nonempty α] : Function.Injective fun b a ↦ f a b :=
fun _ _ h ↦
let ⟨a⟩ := ‹Nonempty α›
hf.right a <| (congr_fun h a :)
theorem eq_iff (hf : Injective2 f) {a₁ a₂ b₁ b₂} : f a₁ b₁ = f a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ :=
⟨fun h ↦ hf h, fun ⟨h1, h2⟩ ↦ congr_arg₂ f h1 h2⟩
end Injective2
section Sometimes
/-- `sometimes f` evaluates to some value of `f`, if it exists. This function is especially
interesting in the case where `α` is a proposition, in which case `f` is necessarily a
constant function, so that `sometimes f = f a` for all `a`. -/
noncomputable def sometimes {α β} [Nonempty β] (f : α → β) : β :=
open scoped Classical in
if h : Nonempty α then f (Classical.choice h) else Classical.choice ‹_›
theorem sometimes_eq {p : Prop} {α} [Nonempty α] (f : p → α) (a : p) : sometimes f = f a :=
dif_pos ⟨a⟩
theorem sometimes_spec {p : Prop} {α} [Nonempty α] (P : α → Prop) (f : p → α) (a : p)
(h : P (f a)) : P (sometimes f) := by
rwa [sometimes_eq]
end Sometimes
end Function
variable {α β : Sort*}
/-- A relation `r : α → β → Prop` is "function-like"
(for each `a` there exists a unique `b` such that `r a b`)
if and only if it is `(f · = ·)` for some function `f`. -/
lemma forall_existsUnique_iff {r : α → β → Prop} :
(∀ a, ∃! b, r a b) ↔ ∃ f : α → β, ∀ {a b}, r a b ↔ f a = b := by
refine ⟨fun h ↦ ?_, ?_⟩
· refine ⟨fun a ↦ (h a).choose, fun hr ↦ ?_, fun h' ↦ h' ▸ ?_⟩
exacts [((h _).choose_spec.2 _ hr).symm, (h _).choose_spec.1]
· rintro ⟨f, hf⟩
simp [hf]
/-- A relation `r : α → β → Prop` is "function-like"
(for each `a` there exists a unique `b` such that `r a b`)
if and only if it is `(f · = ·)` for some function `f`. -/
lemma forall_existsUnique_iff' {r : α → β → Prop} :
(∀ a, ∃! b, r a b) ↔ ∃ f : α → β, r = (f · = ·) := by
simp [forall_existsUnique_iff, funext_iff]
/-- A symmetric relation `r : α → α → Prop` is "function-like"
(for each `a` there exists a unique `b` such that `r a b`)
if and only if it is `(f · = ·)` for some involutive function `f`. -/
protected lemma Symmetric.forall_existsUnique_iff' {r : α → α → Prop} (hr : Symmetric r) :
(∀ a, ∃! b, r a b) ↔ ∃ f : α → α, Involutive f ∧ r = (f · = ·) := by
refine ⟨fun h ↦ ?_, fun ⟨f, _, hf⟩ ↦ forall_existsUnique_iff'.2 ⟨f, hf⟩⟩
rcases forall_existsUnique_iff'.1 h with ⟨f, rfl : r = _⟩
exact ⟨f, symmetric_apply_eq_iff.1 hr, rfl⟩
/-- A symmetric relation `r : α → α → Prop` is "function-like"
(for each `a` there exists a unique `b` such that `r a b`)
if and only if it is `(f · = ·)` for some involutive function `f`. -/
protected lemma Symmetric.forall_existsUnique_iff {r : α → α → Prop} (hr : Symmetric r) :
(∀ a, ∃! b, r a b) ↔ ∃ f : α → α, Involutive f ∧ ∀ {a b}, r a b ↔ f a = b := by
simp [hr.forall_existsUnique_iff', funext_iff]
/-- `s.piecewise f g` is the function equal to `f` on the set `s`, and to `g` on its complement. -/
def Set.piecewise {α : Type u} {β : α → Sort v} (s : Set α) (f g : ∀ i, β i)
[∀ j, Decidable (j ∈ s)] : ∀ i, β i :=
fun i ↦ if i ∈ s then f i else g i
/-! ### Bijectivity of `Eq.rec`, `Eq.mp`, `Eq.mpr`, and `cast` -/
theorem eq_rec_on_bijective {C : α → Sort*} :
∀ {a a' : α} (h : a = a'), Function.Bijective (@Eq.ndrec _ _ C · _ h)
| _, _, rfl => ⟨fun _ _ ↦ id, fun x ↦ ⟨x, rfl⟩⟩
theorem eq_mp_bijective {α β : Sort _} (h : α = β) : Function.Bijective (Eq.mp h) := by
-- TODO: mathlib3 uses `eq_rec_on_bijective`, difference in elaboration here
-- due to `@[macro_inline]` possibly?
cases h
exact ⟨fun _ _ ↦ id, fun x ↦ ⟨x, rfl⟩⟩
theorem eq_mpr_bijective {α β : Sort _} (h : α = β) : Function.Bijective (Eq.mpr h) := by
cases h
exact ⟨fun _ _ ↦ id, fun x ↦ ⟨x, rfl⟩⟩
theorem cast_bijective {α β : Sort _} (h : α = β) : Function.Bijective (cast h) := by
cases h
exact ⟨fun _ _ ↦ id, fun x ↦ ⟨x, rfl⟩⟩
/-! Note these lemmas apply to `Type*` not `Sort*`, as the latter interferes with `simp`, and
is trivial anyway. -/
@[simp]
theorem eq_rec_inj {a a' : α} (h : a = a') {C : α → Type*} (x y : C a) :
(Eq.ndrec x h : C a') = Eq.ndrec y h ↔ x = y :=
(eq_rec_on_bijective h).injective.eq_iff
@[simp]
theorem cast_inj {α β : Type u} (h : α = β) {x y : α} : cast h x = cast h y ↔ x = y :=
(cast_bijective h).injective.eq_iff
theorem Function.LeftInverse.eq_rec_eq {γ : β → Sort v} {f : α → β} {g : β → α}
(h : Function.LeftInverse g f) (C : ∀ a : α, γ (f a)) (a : α) :
-- TODO: mathlib3 uses `(congr_arg f (h a)).rec (C (g (f a)))` for LHS
@Eq.rec β (f (g (f a))) (fun x _ ↦ γ x) (C (g (f a))) (f a) (congr_arg f (h a)) = C a :=
eq_of_heq <| (eqRec_heq _ _).trans <| by rw [h]
theorem Function.LeftInverse.eq_rec_on_eq {γ : β → Sort v} {f : α → β} {g : β → α}
(h : Function.LeftInverse g f) (C : ∀ a : α, γ (f a)) (a : α) :
-- TODO: mathlib3 uses `(congr_arg f (h a)).recOn (C (g (f a)))` for LHS
@Eq.recOn β (f (g (f a))) (fun x _ ↦ γ x) (f a) (congr_arg f (h a)) (C (g (f a))) = C a :=
h.eq_rec_eq _ _
theorem Function.LeftInverse.cast_eq {γ : β → Sort v} {f : α → β} {g : β → α}
(h : Function.LeftInverse g f) (C : ∀ a : α, γ (f a)) (a : α) :
cast (congr_arg (fun a ↦ γ (f a)) (h a)) (C (g (f a))) = C a := by
rw [cast_eq_iff_heq, h]
/-- A set of functions "separates points"
if for each pair of distinct points there is a function taking different values on them. -/
def Set.SeparatesPoints {α β : Type*} (A : Set (α → β)) : Prop :=
∀ ⦃x y : α⦄, x ≠ y → ∃ f ∈ A, (f x : β) ≠ f y
theorem InvImage.equivalence {α : Sort u} {β : Sort v} (r : β → β → Prop) (f : α → β)
(h : Equivalence r) : Equivalence (InvImage r f) :=
⟨fun _ ↦ h.1 _, h.symm, h.trans⟩
instance {α β : Type*} {r : α → β → Prop} {x : α × β} [Decidable (r x.1 x.2)] :
Decidable (uncurry r x) :=
‹Decidable _›
instance {α β : Type*} {r : α × β → Prop} {a : α} {b : β} [Decidable (r (a, b))] :
Decidable (curry r a b) :=
‹Decidable _›
namespace Pi
variable {ι : Type*}
@[simp] theorem map_id {α : ι → Type*} : Pi.map (fun i => @id (α i)) = id := rfl
@[simp] theorem map_id' {α : ι → Type*} : Pi.map (fun i (a : α i) => a) = fun x ↦ x := rfl
theorem map_comp_map {α β γ : ι → Type*} (f : ∀ i, α i → β i) (g : ∀ i, β i → γ i) :
Pi.map g ∘ Pi.map f = Pi.map fun i => g i ∘ f i :=
rfl
end Pi |
.lake/packages/mathlib/Mathlib/Logic/Function/ULift.lean | import Mathlib.Tactic.TypeStar
/-!
# `ULift` and `PLift`
-/
theorem ULift.down_injective {α : Type*} : Function.Injective (@ULift.down α)
| ⟨a⟩, ⟨b⟩, _ => by congr
@[simp] theorem ULift.down_inj {α : Type*} {a b : ULift α} : a.down = b.down ↔ a = b :=
⟨fun h ↦ ULift.down_injective h, fun h ↦ by rw [h]⟩
variable {α : Sort*}
theorem PLift.down_injective : Function.Injective (@PLift.down α)
| ⟨a⟩, ⟨b⟩, _ => by congr
@[simp] theorem PLift.down_inj {a b : PLift α} : a.down = b.down ↔ a = b :=
⟨fun h ↦ PLift.down_injective h, fun h ↦ by rw [h]⟩ |
.lake/packages/mathlib/Mathlib/Logic/Function/Defs.lean | import Mathlib.Tactic.AdaptationNote
import Mathlib.Tactic.Attr.Register
import Mathlib.Tactic.Lemma
import Mathlib.Tactic.Eqns
import Mathlib.Tactic.TypeStar
/-!
# General operations on functions
-/
universe u₁ u₂ u₃ u₄ u₅
namespace Function
variable {α : Sort u₁} {β : Sort u₂} {φ : Sort u₃} {δ : Sort u₄} {ζ : Sort u₅}
lemma flip_def {f : α → β → φ} : flip f = fun b a => f a b := rfl
/-- Composition of dependent functions: `(f ∘' g) x = f (g x)`, where type of `g x` depends on `x`
and type of `f (g x)` depends on `x` and `g x`. -/
@[inline, reducible]
def dcomp {β : α → Sort u₂} {φ : ∀ {x : α}, β x → Sort u₃} (f : ∀ {x : α} (y : β x), φ y)
(g : ∀ x, β x) : ∀ x, φ (g x) := fun x => f (g x)
@[inherit_doc] infixr:80 " ∘' " => Function.dcomp
/-- Given functions `f : β → β → φ` and `g : α → β`, produce a function `α → α → φ` that evaluates
`g` on each argument, then applies `f` to the results. Can be used, e.g., to transfer a relation
from `β` to `α`. -/
abbrev onFun (f : β → β → φ) (g : α → β) : α → α → φ := fun x y => f (g x) (g y)
@[inherit_doc onFun]
scoped infixl:2 " on " => onFun
/-- For a two-argument function `f`, `swap f` is the same function but taking the arguments
in the reverse order. `swap f y x = f x y`. -/
abbrev swap {φ : α → β → Sort u₃} (f : ∀ x y, φ x y) : ∀ y x, φ x y := fun y x => f x y
theorem swap_def {φ : α → β → Sort u₃} (f : ∀ x y, φ x y) : swap f = fun y x => f x y := rfl
attribute [mfld_simps] id_comp comp_id
theorem comp_assoc (f : φ → δ) (g : β → φ) (h : α → β) : (f ∘ g) ∘ h = f ∘ g ∘ h :=
rfl
/-- A function is called bijective if it is both injective and surjective. -/
def Bijective (f : α → β) :=
Injective f ∧ Surjective f
theorem Bijective.comp {g : β → φ} {f : α → β} : Bijective g → Bijective f → Bijective (g ∘ f)
| ⟨h_ginj, h_gsurj⟩, ⟨h_finj, h_fsurj⟩ => ⟨h_ginj.comp h_finj, h_gsurj.comp h_fsurj⟩
theorem bijective_id : Bijective (@id α) :=
⟨injective_id, surjective_id⟩
variable {f : α → β}
theorem Injective.beq_eq {α β : Type*} [BEq α] [LawfulBEq α] [BEq β] [LawfulBEq β] {f : α → β}
(I : Injective f) {a b : α} : (f a == f b) = (a == b) := by
by_cases h : a == b <;> simp [h] <;> simpa [I.eq_iff] using h
end Function
namespace Function
variable {α : Type u₁} {β : Type u₂}
/-- A point `x` is a fixed point of `f : α → α` if `f x = x`. -/
def IsFixedPt (f : α → α) (x : α) := f x = x
@[nontriviality]
theorem IsFixedPt.of_subsingleton [Subsingleton α] (f : α → α) (x : α) : IsFixedPt f x :=
Subsingleton.elim _ _
end Function
namespace Pi
variable {ι : Sort*} {α β : ι → Sort*}
/-- Sends a dependent function `a : ∀ i, α i` to a dependent function `Pi.map f a : ∀ i, β i`
by applying `f i` to `i`-th component. -/
protected def map (f : ∀ i, α i → β i) : (∀ i, α i) → (∀ i, β i) := fun a i ↦ f i (a i)
@[simp]
lemma map_apply (f : ∀ i, α i → β i) (a : ∀ i, α i) (i : ι) : Pi.map f a i = f i (a i) := rfl
end Pi |
.lake/packages/mathlib/Mathlib/Logic/Function/OfArity.lean | import Mathlib.Logic.Function.FromTypes
/-! # Function types of a given arity
This provides `Function.OfArity`, such that `OfArity α β 2 = α → α → β`.
Note that it is often preferable to use `(Fin n → α) → β` in place of `OfArity n α β`.
## Main definitions
* `Function.OfArity α β n`: `n`-ary function `α → α → ... → β`. Defined inductively.
* `Function.OfArity.const α b n`: `n`-ary constant function equal to `b`.
-/
universe u
namespace Function
/-- The type of `n`-ary functions `α → α → ... → β`.
Note that this is not universe polymorphic, as this would require that when `n=0` we produce either
`Unit → β` or `ULift β`. -/
abbrev OfArity (α β : Type u) (n : ℕ) : Type u := FromTypes (fun (_ : Fin n) => α) β
@[simp]
theorem ofArity_zero (α β : Type u) : OfArity α β 0 = β := fromTypes_zero _ _
@[simp]
theorem ofArity_succ (α β : Type u) (n : ℕ) :
OfArity α β n.succ = (α → OfArity α β n) := fromTypes_succ _ _
namespace OfArity
/-- Constant `n`-ary function with value `b`. -/
def const (α : Type u) {β : Type u} (b : β) (n : ℕ) : OfArity α β n :=
FromTypes.const (fun _ => α) b
@[simp]
theorem const_zero (α : Type u) {β : Type u} (b : β) : const α b 0 = b :=
FromTypes.const_zero (fun _ => α) b
@[simp]
theorem const_succ (α : Type u) {β : Type u} (b : β) (n : ℕ) :
const α b n.succ = fun _ => const _ b n :=
FromTypes.const_succ (fun _ => α) b
theorem const_succ_apply (α : Type u) {β : Type u} (b : β) (n : ℕ) (x : α) :
const α b n.succ x = const _ b n := FromTypes.const_succ_apply _ b x
instance inhabited {α β n} [Inhabited β] : Inhabited (OfArity α β n) :=
inferInstanceAs (Inhabited (FromTypes (fun _ => α) β))
end OfArity
namespace FromTypes
lemma fromTypes_fin_const (α β : Type u) (n : ℕ) :
FromTypes (fun (_ : Fin n) => α) β = OfArity α β n := rfl
/-- The definitional equality between heterogeneous functions with constant
domain and `n`-ary functions with that domain. -/
def fromTypes_fin_const_equiv (α β : Type u) (n : ℕ) :
FromTypes (fun (_ : Fin n) => α) β ≃ OfArity α β n := .refl _
end FromTypes
end Function |
.lake/packages/mathlib/Mathlib/Logic/Function/Coequalizer.lean | import Mathlib.Tactic.TypeStar
import Mathlib.Tactic.Lemma
/-!
# Coequalizer of a pair of functions
The coequalizer of two functions `f g : α → β` is the pair (`μ`, `p : β → μ`) that
satisfies the following universal property: Every function `u : β → γ`
with `u ∘ f = u ∘ g` factors uniquely via `p`.
In this file we define the coequalizer and provide the basic API.
-/
universe v
namespace Function
/-- The relation generating the equivalence relation used for defining `Function.coequalizer`. -/
inductive Coequalizer.Rel {α β : Type*} (f g : α → β) : β → β → Prop where
| intro (x : α) : Rel f g (f x) (g x)
/-- The coequalizer of two functions `f g : α → β` is the pair (`μ`, `p : β → μ`) that
satisfies the following universal property: Every function `u : β → γ`
with `u ∘ f = u ∘ g` factors uniquely via `p`. -/
def Coequalizer {α : Type*} {β : Type v} (f g : α → β) : Type v :=
Quot (Function.Coequalizer.Rel f g)
namespace Coequalizer
variable {α β : Type*} (f g : α → β)
/-- The canonical projection to the coequalizer. -/
def mk (x : β) : Coequalizer f g :=
Quot.mk _ x
lemma condition (x : α) : mk f g (f x) = mk f g (g x) :=
Quot.sound (.intro x)
lemma mk_surjective : Function.Surjective (mk f g) :=
Quot.exists_rep
/-- Any map `u : β → γ` with `u ∘ f = u ∘ g` factors via `Function.Coequalizer.mk`. -/
def desc {γ : Type*} (u : β → γ) (hu : u ∘ f = u ∘ g) : Coequalizer f g → γ :=
Quot.lift u (fun _ _ (.intro e) ↦ congrFun hu e)
@[simp] lemma desc_mk {γ : Type*} (u : β → γ) (hu : u ∘ f = u ∘ g) (x : β) :
desc f g u hu (mk f g x) = u x :=
rfl
end Function.Coequalizer |
.lake/packages/mathlib/Mathlib/Logic/Function/CompTypeclasses.lean | import Mathlib.Tactic.TypeStar
import Mathlib.Tactic.Lemma
/-!
# Propositional typeclasses on several maps
This file contains typeclasses that are used in the definition of
equivariant maps in the spirit what was initially developed
by Frédéric Dupuis and Heather Macbeth for linear maps.
* `CompTriple φ ψ χ`, which expresses that `ψ.comp φ = χ`
* `CompTriple.IsId φ`, which expresses that `φ = id`
TODO :
* align with RingHomCompTriple
-/
section CompTriple
/-- Class of composing triples -/
class CompTriple {M N P : Type*} (φ : M → N) (ψ : N → P) (χ : outParam (M → P)) : Prop where
/-- The maps form a commuting triangle -/
comp_eq : ψ.comp φ = χ
attribute [simp] CompTriple.comp_eq
namespace CompTriple
/-- Class of Id maps -/
class IsId {M : Type*} (σ : M → M) : Prop where
eq_id : σ = id
instance {M : Type*} : IsId (@id M) where
eq_id := rfl
instance instComp_id {N P : Type*} {φ : N → N} [IsId φ] {ψ : N → P} :
CompTriple φ ψ ψ where
comp_eq := by simp only [IsId.eq_id, Function.comp_id]
instance instId_comp {M N : Type*} {φ : M → N} {ψ : N → N} [IsId ψ] :
CompTriple φ ψ φ where
comp_eq := by simp only [IsId.eq_id, Function.id_comp]
/-- `φ`, `ψ` and `ψ ∘ φ` for a `CompTriple`. -/
theorem comp {M N P : Type*}
{φ : M → N} {ψ : N → P} :
CompTriple φ ψ (ψ.comp φ) where
comp_eq := rfl
lemma comp_inv {M N : Type*} {φ : M → N} {ψ : N → M}
(h : Function.RightInverse φ ψ) {χ : M → M} [IsId χ] :
CompTriple φ ψ χ where
comp_eq := by simp only [IsId.eq_id, h.id]
lemma comp_apply {M N P : Type*}
{φ : M → N} {ψ : N → P} {χ : M → P} (h : CompTriple φ ψ χ) (x : M) :
ψ (φ x) = χ x := by
rw [← h.comp_eq, Function.comp_apply]
end CompTriple
end CompTriple |
.lake/packages/mathlib/Mathlib/Logic/Encodable/Pi.lean | import Mathlib.Data.Vector.Basic
import Mathlib.Logic.Equiv.Finset
/-!
# Encodability of Pi types
This file provides instances of `Encodable` for types of vectors and (dependent) functions:
* `Encodable.List.Vector.encodable`: vectors of length `n` (represented by lists) are encodable
* `Encodable.finArrow`: vectors of length `n` (represented by `Fin`-indexed functions) are encodable
* `Encodable.fintypeArrow`, `Encodable.fintypePi`: (dependent) functions with
finite domain and countable codomain are encodable
-/
open List (Vector)
open Nat List
namespace Encodable
variable {α : Type*}
/-- If `α` is encodable, then so is `Vector α n`. -/
instance List.Vector.encodable [Encodable α] {n} : Encodable (List.Vector α n) :=
Subtype.encodable
/-- If `α` is countable, then so is `Vector α n`. -/
instance List.Vector.countable [Countable α] {n} : Countable (List.Vector α n) :=
Subtype.countable
/-- If `α` is encodable, then so is `Fin n → α`. -/
instance finArrow [Encodable α] {n} : Encodable (Fin n → α) :=
ofEquiv _ (Equiv.vectorEquivFin _ _).symm
instance finPi (n) (π : Fin n → Type*) [∀ i, Encodable (π i)] : Encodable (∀ i, π i) :=
ofEquiv _ (Equiv.piEquivSubtypeSigma (Fin n) π)
-- TODO: Unify with `fintypePi` and find a better name
/-- When `α` is finite and `β` is encodable, `α → β` is encodable too. Because the encoding is not
unique, we wrap it in `Trunc` to preserve computability. -/
def fintypeArrow (α : Type*) (β : Type*) [DecidableEq α] [Fintype α] [Encodable β] :
Trunc (Encodable (α → β)) :=
(Fintype.truncEquivFin α).map fun f =>
Encodable.ofEquiv (Fin (Fintype.card α) → β) <| Equiv.arrowCongr f (Equiv.refl _)
/-- When `α` is finite and all `π a` are encodable, `Π a, π a` is encodable too. Because the
encoding is not unique, we wrap it in `Trunc` to preserve computability. -/
def fintypePi (α : Type*) (π : α → Type*) [DecidableEq α] [Fintype α] [∀ a, Encodable (π a)] :
Trunc (Encodable (∀ a, π a)) :=
(Fintype.truncEncodable α).bind fun a =>
(@fintypeArrow α (Σ a, π a) _ _ (@Sigma.encodable _ _ a _)).bind fun f =>
Trunc.mk <|
@Encodable.ofEquiv _ _ (@Subtype.encodable _ _ f _)
(Equiv.piEquivSubtypeSigma α π)
/-- If `α` and `β` are encodable and `α` is a fintype, then `α → β` is encodable as well. -/
instance fintypeArrowOfEncodable {α β : Type*} [Encodable α] [Fintype α] [Encodable β] :
Encodable (α → β) :=
ofEquiv (Fin (Fintype.card α) → β) <| Equiv.arrowCongr fintypeEquivFin (Equiv.refl _)
end Encodable |
.lake/packages/mathlib/Mathlib/Logic/Encodable/Basic.lean | import Mathlib.Data.Countable.Defs
import Mathlib.Data.Fin.Basic
import Mathlib.Data.Nat.Find
import Mathlib.Data.PNat.Equiv
import Mathlib.Logic.Equiv.Nat
import Mathlib.Order.Directed
import Mathlib.Order.RelIso.Basic
/-!
# Encodable types
This file defines encodable (constructively countable) types as a typeclass.
This is used to provide explicit encode/decode functions from and to `ℕ`, with the information that
those functions are inverses of each other.
The difference with `Denumerable` is that finite types are encodable. For infinite types,
`Encodable` and `Denumerable` agree.
## Main declarations
* `Encodable α`: States that there exists an explicit encoding function `encode : α → ℕ` with a
partial inverse `decode : ℕ → Option α`.
* `decode₂`: Version of `decode` that is equal to `none` outside of the range of `encode`. Useful as
we do not require this in the definition of `decode`.
* `ULower α`: Any encodable type has an equivalent type living in the lowest universe, namely a
subtype of `ℕ`. `ULower α` finds it.
## Implementation notes
The point of asking for an explicit partial inverse `decode : ℕ → Option α` to `encode : α → ℕ` is
to make the range of `encode` decidable even when the finiteness of `α` is not.
-/
assert_not_exists Monoid
open Option List Nat Function
/-- Constructively countable type. Made from an explicit injection `encode : α → ℕ` and a partial
inverse `decode : ℕ → Option α`. Note that finite types *are* countable. See `Denumerable` if you
wish to enforce infiniteness. -/
class Encodable (α : Type*) where
/-- Encoding from Type α to ℕ -/
encode : α → ℕ
/-- Decoding from ℕ to Option α -/
decode : ℕ → Option α
/-- Invariant relationship between encoding and decoding -/
encodek : ∀ a, decode (encode a) = some a
attribute [simp] Encodable.encodek
namespace Encodable
variable {α : Type*} {β : Type*}
universe u
theorem encode_injective [Encodable α] : Function.Injective (@encode α _)
| x, y, e => Option.some.inj <| by rw [← encodek, e, encodek]
@[simp]
theorem encode_inj [Encodable α] {a b : α} : encode a = encode b ↔ a = b :=
encode_injective.eq_iff
-- The priority of the instance below is less than the priorities of `Subtype.Countable`
-- and `Quotient.Countable`
instance (priority := 400) countable [Encodable α] : Countable α where
exists_injective_nat' := ⟨_,encode_injective⟩
theorem surjective_decode_iget (α : Type*) [Encodable α] [Inhabited α] :
Surjective fun n => ((Encodable.decode n).iget : α) := fun x =>
⟨Encodable.encode x, by simp_rw [Encodable.encodek]⟩
/-- An encodable type has decidable equality. Not set as an instance because this is usually not the
best way to infer decidability. -/
def decidableEqOfEncodable (α) [Encodable α] : DecidableEq α
| _, _ => decidable_of_iff _ encode_inj
/-- If `α` is encodable and there is an injection `f : β → α`, then `β` is encodable as well. -/
def ofLeftInjection [Encodable α] (f : β → α) (finv : α → Option β)
(linv : ∀ b, finv (f b) = some b) : Encodable β :=
⟨fun b => encode (f b), fun n => (decode n).bind finv, fun b => by
simp [Encodable.encodek, linv]⟩
/-- If `α` is encodable and `f : β → α` is invertible, then `β` is encodable as well. -/
def ofLeftInverse [Encodable α] (f : β → α) (finv : α → β) (linv : ∀ b, finv (f b) = b) :
Encodable β :=
ofLeftInjection f (some ∘ finv) fun b => congr_arg some (linv b)
/-- Encodability is preserved by equivalence. -/
def ofEquiv (α) [Encodable α] (e : β ≃ α) : Encodable β :=
ofLeftInverse e e.symm e.left_inv
theorem encode_ofEquiv {α β} [Encodable α] (e : β ≃ α) (b : β) :
@encode _ (ofEquiv _ e) b = encode (e b) :=
rfl
theorem decode_ofEquiv {α β} [Encodable α] (e : β ≃ α) (n : ℕ) :
@decode _ (ofEquiv _ e) n = (decode n).map e.symm :=
show Option.bind _ _ = Option.map _ _
by rw [Option.map_eq_bind]
instance _root_.Nat.encodable : Encodable ℕ :=
⟨id, some, fun _ => rfl⟩
@[simp]
theorem encode_nat (n : ℕ) : encode n = n :=
rfl
@[simp 1100]
theorem decode_nat (n : ℕ) : decode n = some n :=
rfl
instance (priority := 100) _root_.IsEmpty.toEncodable [IsEmpty α] : Encodable α :=
⟨isEmptyElim, fun _ => none, isEmptyElim⟩
instance _root_.PUnit.encodable : Encodable PUnit :=
⟨fun _ => 0, fun n => Nat.casesOn n (some PUnit.unit) fun _ => none, fun _ => by simp⟩
@[simp]
theorem encode_star : encode PUnit.unit = 0 :=
rfl
@[simp]
theorem decode_unit_zero : decode 0 = some PUnit.unit :=
rfl
@[simp]
theorem decode_unit_succ (n) : decode (succ n) = (none : Option PUnit) :=
rfl
/-- If `α` is encodable, then so is `Option α`. -/
instance _root_.Option.encodable {α : Type*} [h : Encodable α] : Encodable (Option α) :=
⟨fun o => Option.casesOn o Nat.zero fun a => succ (encode a), fun n =>
Nat.casesOn n (some none) fun m => (decode m).map some, fun o => by
cases o <;> simp [encodek]⟩
@[simp]
theorem encode_none [Encodable α] : encode (@none α) = 0 :=
rfl
@[simp]
theorem encode_some [Encodable α] (a : α) : encode (some a) = succ (encode a) :=
rfl
@[simp]
theorem decode_option_zero [Encodable α] : (decode 0 : Option (Option α)) = some none :=
rfl
@[simp]
theorem decode_option_succ [Encodable α] (n) :
(decode (succ n) : Option (Option α)) = (decode n).map some :=
rfl
/-- Failsafe variant of `decode`. `decode₂ α n` returns the preimage of `n` under `encode` if it
exists, and returns `none` if it doesn't. This requirement could be imposed directly on `decode` but
is not to help make the definition easier to use. -/
def decode₂ (α) [Encodable α] (n : ℕ) : Option α :=
(decode n).bind (Option.guard fun a => encode a = n)
theorem mem_decode₂' [Encodable α] {n : ℕ} {a : α} :
a ∈ decode₂ α n ↔ a ∈ decode n ∧ encode a = n := by
simp [decode₂, Option.bind_eq_some_iff]
theorem mem_decode₂ [Encodable α] {n : ℕ} {a : α} : a ∈ decode₂ α n ↔ encode a = n :=
mem_decode₂'.trans (and_iff_right_of_imp fun e => e ▸ encodek _)
theorem decode₂_eq_some [Encodable α] {n : ℕ} {a : α} : decode₂ α n = some a ↔ encode a = n :=
mem_decode₂
@[simp]
theorem decode₂_encode [Encodable α] (a : α) : decode₂ α (encode a) = some a := by
simp [decode₂_eq_some]
theorem decode₂_ne_none_iff [Encodable α] {n : ℕ} :
decode₂ α n ≠ none ↔ n ∈ Set.range (encode : α → ℕ) := by
simp_rw [Set.range, Set.mem_setOf_eq, Ne, Option.eq_none_iff_forall_not_mem,
Encodable.mem_decode₂, not_forall, not_not]
theorem decode₂_is_partial_inv [Encodable α] : IsPartialInv encode (decode₂ α) := fun _ _ =>
mem_decode₂
theorem decode₂_inj [Encodable α] {n : ℕ} {a₁ a₂ : α} (h₁ : a₁ ∈ decode₂ α n)
(h₂ : a₂ ∈ decode₂ α n) : a₁ = a₂ :=
encode_injective <| (mem_decode₂.1 h₁).trans (mem_decode₂.1 h₂).symm
theorem encodek₂ [Encodable α] (a : α) : decode₂ α (encode a) = some a :=
mem_decode₂.2 rfl
/-- The encoding function has decidable range. -/
def decidableRangeEncode (α : Type*) [Encodable α] : DecidablePred (· ∈ Set.range (@encode α _)) :=
fun x =>
decidable_of_iff (Option.isSome (decode₂ α x))
⟨fun h => ⟨Option.get _ h, by rw [← decode₂_is_partial_inv (Option.get _ h), Option.some_get]⟩,
fun ⟨n, hn⟩ => by rw [← hn, encodek₂]; exact rfl⟩
/-- An encodable type is equivalent to the range of its encoding function. -/
def equivRangeEncode (α : Type*) [Encodable α] : α ≃ Set.range (@encode α _) where
toFun := fun a : α => ⟨encode a, Set.mem_range_self _⟩
invFun n :=
Option.get _
(show isSome (decode₂ α n.1) by obtain ⟨x, hx⟩ := n.2; rw [← hx, encodek₂]; exact rfl)
left_inv a := by dsimp; rw [← Option.some_inj, Option.some_get, encodek₂]
right_inv := fun ⟨n, x, hx⟩ => by
apply Subtype.eq
dsimp
conv =>
rhs
rw [← hx]
rw [encode_injective.eq_iff, ← Option.some_inj, Option.some_get, ← hx, encodek₂]
/-- A type with unique element is encodable. This is not an instance to avoid diamonds. -/
def _root_.Unique.encodable [Unique α] : Encodable α :=
⟨fun _ => 0, fun _ => some default, Unique.forall_iff.2 rfl⟩
section Sum
variable [Encodable α] [Encodable β]
/-- Explicit encoding function for the sum of two encodable types. -/
def encodeSum : α ⊕ β → ℕ
| Sum.inl a => 2 * encode a
| Sum.inr b => 2 * encode b + 1
/-- Explicit decoding function for the sum of two encodable types. -/
def decodeSum (n : ℕ) : Option (α ⊕ β) :=
match boddDiv2 n with
| (false, m) => (decode m : Option α).map Sum.inl
| (_, m) => (decode m : Option β).map Sum.inr
/-- If `α` and `β` are encodable, then so is their sum. -/
instance _root_.Sum.encodable : Encodable (α ⊕ β) :=
⟨encodeSum, decodeSum, fun s => by cases s <;> simp [encodeSum, div2_val, decodeSum, encodek]⟩
@[simp]
theorem encode_inl (a : α) : @encode (α ⊕ β) _ (Sum.inl a) = 2 * (encode a) :=
rfl
@[simp]
theorem encode_inr (b : β) : @encode (α ⊕ β) _ (Sum.inr b) = 2 * (encode b) + 1 :=
rfl
@[simp]
theorem decode_sum_val (n : ℕ) : (decode n : Option (α ⊕ β)) = decodeSum n :=
rfl
end Sum
instance _root_.Bool.encodable : Encodable Bool :=
ofEquiv (Unit ⊕ Unit) Equiv.boolEquivPUnitSumPUnit
@[simp]
theorem encode_true : encode true = 1 :=
rfl
@[simp]
theorem encode_false : encode false = 0 :=
rfl
@[simp]
theorem decode_zero : (decode 0 : Option Bool) = some false :=
rfl
@[simp]
theorem decode_one : (decode 1 : Option Bool) = some true :=
rfl
theorem decode_ge_two (n) (h : 2 ≤ n) : (decode n : Option Bool) = none := by
suffices decodeSum n = none by
change (decodeSum n).bind _ = none
rw [this]
rfl
have : 1 ≤ n / 2 := by
rw [Nat.le_div_iff_mul_le]
exacts [h, by decide]
obtain ⟨m, e⟩ := exists_eq_succ_of_ne_zero (_root_.ne_of_gt this)
simp only [decodeSum, boddDiv2_eq, div2_val]; cases bodd n <;> simp [e]
noncomputable instance _root_.Prop.encodable : Encodable Prop :=
ofEquiv Bool Equiv.propEquivBool
section Sigma
variable {γ : α → Type*} [Encodable α] [∀ a, Encodable (γ a)]
/-- Explicit encoding function for `Sigma γ` -/
def encodeSigma : Sigma γ → ℕ
| ⟨a, b⟩ => pair (encode a) (encode b)
/-- Explicit decoding function for `Sigma γ` -/
def decodeSigma (n : ℕ) : Option (Sigma γ) :=
let (n₁, n₂) := unpair n
(decode n₁).bind fun a => (decode n₂).map <| Sigma.mk a
instance _root_.Sigma.encodable : Encodable (Sigma γ) :=
⟨encodeSigma, decodeSigma, fun ⟨a, b⟩ => by
simp [encodeSigma, decodeSigma, unpair_pair, encodek]⟩
@[simp]
theorem decode_sigma_val (n : ℕ) :
(decode n : Option (Sigma γ)) =
(decode n.unpair.1).bind fun a => (decode n.unpair.2).map <| Sigma.mk a :=
rfl
@[simp]
theorem encode_sigma_val (a b) : @encode (Sigma γ) _ ⟨a, b⟩ = pair (encode a) (encode b) :=
rfl
end Sigma
section Prod
variable [Encodable α] [Encodable β]
/-- If `α` and `β` are encodable, then so is their product. -/
instance Prod.encodable : Encodable (α × β) :=
ofEquiv _ (Equiv.sigmaEquivProd α β).symm
@[simp]
theorem decode_prod_val (n : ℕ) :
(@decode (α × β) _ n : Option (α × β))
= (decode n.unpair.1).bind fun a => (decode n.unpair.2).map <| Prod.mk a := by
simp only [decode_ofEquiv, Equiv.symm_symm, decode_sigma_val]
cases (decode n.unpair.1 : Option α) <;> cases (decode n.unpair.2 : Option β)
<;> rfl
@[simp]
theorem encode_prod_val (a b) : @encode (α × β) _ (a, b) = pair (encode a) (encode b) :=
rfl
end Prod
section Subtype
open Subtype Decidable
variable {P : α → Prop} [encA : Encodable α] [decP : DecidablePred P]
/-- Explicit encoding function for a decidable subtype of an encodable type -/
def encodeSubtype : { a : α // P a } → ℕ
| ⟨v,_⟩ => encode v
/-- Explicit decoding function for a decidable subtype of an encodable type -/
def decodeSubtype (v : ℕ) : Option { a : α // P a } :=
(decode v).bind fun a => if h : P a then some ⟨a, h⟩ else none
/-- A decidable subtype of an encodable type is encodable. -/
instance _root_.Subtype.encodable : Encodable { a : α // P a } :=
⟨encodeSubtype, decodeSubtype, fun ⟨v, h⟩ => by simp [encodeSubtype, decodeSubtype, encodek, h]⟩
theorem Subtype.encode_eq (a : Subtype P) : encode a = encode a.val := by cases a; rfl
end Subtype
instance _root_.Fin.encodable (n) : Encodable (Fin n) :=
ofEquiv _ Fin.equivSubtype
instance _root_.Int.encodable : Encodable ℤ :=
ofEquiv _ Equiv.intEquivNat
instance _root_.PNat.encodable : Encodable ℕ+ :=
ofEquiv _ Equiv.pnatEquivNat
/-- The lift of an encodable type is encodable -/
instance _root_.ULift.encodable [Encodable α] : Encodable (ULift α) :=
ofEquiv _ Equiv.ulift
/-- The lift of an encodable type is encodable. -/
instance _root_.PLift.encodable [Encodable α] : Encodable (PLift α) :=
ofEquiv _ Equiv.plift
/-- If `β` is encodable and there is an injection `f : α → β`, then `α` is encodable as well. -/
noncomputable def ofInj [Encodable β] (f : α → β) (hf : Injective f) : Encodable α :=
ofLeftInjection f (partialInv f) fun _ => (partialInv_of_injective hf _ _).2 rfl
/-- If `α` is countable, then it has a (non-canonical) `Encodable` structure. -/
noncomputable def ofCountable (α : Type*) [Countable α] : Encodable α :=
Nonempty.some <|
let ⟨f, hf⟩ := exists_injective_nat α
⟨ofInj f hf⟩
@[simp]
theorem nonempty_encodable : Nonempty (Encodable α) ↔ Countable α :=
⟨fun ⟨h⟩ => @Encodable.countable α h, fun h => ⟨@ofCountable _ h⟩⟩
end Encodable
/-- See also `nonempty_fintype`, `nonempty_denumerable`. -/
theorem nonempty_encodable (α : Type*) [Countable α] : Nonempty (Encodable α) :=
⟨Encodable.ofCountable _⟩
instance : Countable ℕ+ := by delta PNat; infer_instance
-- short-circuit instance search
section ULower
attribute [local instance] Encodable.decidableRangeEncode
/-- `ULower α : Type` is an equivalent type in the lowest universe, given `Encodable α`. -/
def ULower (α : Type*) [Encodable α] : Type :=
Set.range (Encodable.encode : α → ℕ)
instance {α : Type*} [Encodable α] : DecidableEq (ULower α) := by
delta ULower; exact Encodable.decidableEqOfEncodable _
instance {α : Type*} [Encodable α] : Encodable (ULower α) := by
delta ULower; infer_instance
end ULower
namespace ULower
variable (α : Type*) [Encodable α]
/-- The equivalence between the encodable type `α` and `ULower α : Type`. -/
def equiv : α ≃ ULower α :=
Encodable.equivRangeEncode α
variable {α}
/-- Lowers an `a : α` into `ULower α`. -/
def down (a : α) : ULower α :=
equiv α a
instance [Inhabited α] : Inhabited (ULower α) :=
⟨down default⟩
/-- Lifts an `a : ULower α` into `α`. -/
def up (a : ULower α) : α :=
(equiv α).symm a
@[simp]
theorem down_up {a : ULower α} : down a.up = a :=
Equiv.right_inv _ _
@[simp]
theorem up_down {a : α} : (down a).up = a := by
simp [up, down, Equiv.symm_apply_apply]
@[simp]
theorem up_eq_up {a b : ULower α} : a.up = b.up ↔ a = b :=
Equiv.apply_eq_iff_eq _
@[simp]
theorem down_eq_down {a b : α} : down a = down b ↔ a = b :=
Equiv.apply_eq_iff_eq _
@[ext]
protected theorem ext {a b : ULower α} : a.up = b.up → a = b :=
up_eq_up.1
end ULower
/-
Choice function for encodable types and decidable predicates.
We provide the following API
choose {α : Type*} {p : α → Prop} [c : encodable α] [d : decidable_pred p] : (∃ x, p x) → α :=
choose_spec {α : Type*} {p : α → Prop} [c : encodable α] [d : decidable_pred p] (ex : ∃ x, p x) :
p (choose ex) :=
-/
namespace Encodable
section FindA
variable {α : Type*} (p : α → Prop) [Encodable α] [DecidablePred p]
private def good : Option α → Prop
| some a => p a
| none => False
private def decidable_good : DecidablePred (good p) :=
fun n => by
cases n <;> unfold good <;> dsimp <;> infer_instance
attribute [local instance] decidable_good
open Encodable
variable {p}
/-- Constructive choice function for a decidable subtype of an encodable type. -/
def chooseX (h : ∃ x, p x) : { a : α // p a } :=
have : ∃ n, good p (decode n) :=
let ⟨w, pw⟩ := h
⟨encode w, by simp [good, encodek, pw]⟩
match (motive := ∀ o, good p o → { a // p a }) _, Nat.find_spec this with
| some a, h => ⟨a, h⟩
/-- Constructive choice function for a decidable predicate over an encodable type. -/
def choose (h : ∃ x, p x) : α :=
(chooseX h).1
theorem choose_spec (h : ∃ x, p x) : p (choose h) :=
(chooseX h).2
end FindA
/-- A constructive version of `Classical.axiom_of_choice` for `Encodable` types. -/
theorem axiom_of_choice {α : Type*} {β : α → Type*} {R : ∀ x, β x → Prop} [∀ a, Encodable (β a)]
[∀ x y, Decidable (R x y)] (H : ∀ x, ∃ y, R x y) : ∃ f : ∀ a, β a, ∀ x, R x (f x) :=
⟨fun x => choose (H x), fun x => choose_spec (H x)⟩
/-- A constructive version of `Classical.skolem` for `Encodable` types. -/
theorem skolem {α : Type*} {β : α → Type*} {P : ∀ x, β x → Prop} [∀ a, Encodable (β a)]
[∀ x y, Decidable (P x y)] : (∀ x, ∃ y, P x y) ↔ ∃ f : ∀ a, β a, ∀ x, P x (f x) :=
⟨axiom_of_choice, fun ⟨_, H⟩ x => ⟨_, H x⟩⟩
/-
There is a total ordering on the elements of an encodable type, induced by the map to ℕ.
-/
/-- The `encode` function, viewed as an embedding. -/
def encode' (α) [Encodable α] : α ↪ ℕ :=
⟨Encodable.encode, Encodable.encode_injective⟩
instance {α} [Encodable α] : IsAntisymm _ (Encodable.encode' α ⁻¹'o (· ≤ ·)) :=
(RelEmbedding.preimage _ _).isAntisymm
instance {α} [Encodable α] : IsTotal _ (Encodable.encode' α ⁻¹'o (· ≤ ·)) :=
(RelEmbedding.preimage _ _).isTotal
end Encodable
namespace Directed
open Encodable
variable {α : Type*} {β : Type*} [Encodable α] [Inhabited α]
/-- Given a `Directed r` function `f : α → β` defined on an encodable inhabited type,
construct a noncomputable sequence such that `r (f (x n)) (f (x (n + 1)))`
and `r (f a) (f (x (encode a + 1))`. -/
protected noncomputable def sequence {r : β → β → Prop} (f : α → β) (hf : Directed r f) : ℕ → α
| 0 => default
| n + 1 =>
let p := Directed.sequence f hf n
match (decode n : Option α) with
| none => Classical.choose (hf p p)
| some a => Classical.choose (hf p a)
theorem sequence_mono_nat {r : β → β → Prop} {f : α → β} (hf : Directed r f) (n : ℕ) :
r (f (hf.sequence f n)) (f (hf.sequence f (n + 1))) := by
dsimp [Directed.sequence]
generalize hf.sequence f n = p
rcases (decode n : Option α) with - | a
· exact (Classical.choose_spec (hf p p)).1
· exact (Classical.choose_spec (hf p a)).1
theorem rel_sequence {r : β → β → Prop} {f : α → β} (hf : Directed r f) (a : α) :
r (f a) (f (hf.sequence f (encode a + 1))) := by
simp only [Directed.sequence, encodek]
exact (Classical.choose_spec (hf _ a)).2
variable [Preorder β] {f : α → β}
section
variable (hf : Directed (· ≤ ·) f)
theorem sequence_mono : Monotone (f ∘ hf.sequence f) :=
monotone_nat_of_le_succ <| hf.sequence_mono_nat
theorem le_sequence (a : α) : f a ≤ f (hf.sequence f (encode a + 1)) :=
hf.rel_sequence a
end
section
variable (hf : Directed (· ≥ ·) f)
theorem sequence_anti : Antitone (f ∘ hf.sequence f) :=
antitone_nat_of_succ_le <| hf.sequence_mono_nat
theorem sequence_le (a : α) : f (hf.sequence f (Encodable.encode a + 1)) ≤ f a :=
hf.rel_sequence a
end
end Directed
section Quotient
open Encodable Quotient
variable {α : Type*} {s : Setoid α} [DecidableRel (α := α) (· ≈ ·)] [Encodable α]
/-- Representative of an equivalence class. This is a computable version of `Quot.out` for a setoid
on an encodable type. -/
def Quotient.rep (q : Quotient s) : α :=
choose (exists_rep q)
theorem Quotient.rep_spec (q : Quotient s) : ⟦q.rep⟧ = q :=
choose_spec (exists_rep q)
/-- The quotient of an encodable space by a decidable equivalence relation is encodable. -/
def encodableQuotient : Encodable (Quotient s) :=
⟨fun q => encode q.rep, fun n => Quotient.mk'' <$> decode n, by
rintro ⟨l⟩; dsimp; rw [encodek]; exact congr_arg some ⟦l⟧.rep_spec⟩
end Quotient |
.lake/packages/mathlib/Mathlib/Logic/Encodable/Lattice.lean | import Mathlib.Logic.Encodable.Basic
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.Subsingleton
/-!
# Lattice operations on encodable types
Lemmas about lattice and set operations on encodable types
## Implementation Notes
This is a separate file, to avoid unnecessary imports in basic files.
Previously some of these results were in the `MeasureTheory` folder.
-/
open Set
namespace Encodable
variable {α : Type*} {β : Type*} [Encodable β]
theorem iSup_decode₂ [CompleteLattice α] (f : β → α) :
⨆ (i : ℕ) (b ∈ decode₂ β i), f b = (⨆ b, f b) := by
rw [iSup_comm]
simp only [mem_decode₂, iSup_iSup_eq_right]
theorem iUnion_decode₂ (f : β → Set α) : ⋃ (i : ℕ) (b ∈ decode₂ β i), f b = ⋃ b, f b :=
iSup_decode₂ f
@[elab_as_elim]
theorem iUnion_decode₂_cases {f : β → Set α} {C : Set α → Prop} (H0 : C ∅) (H1 : ∀ b, C (f b)) {n} :
C (⋃ b ∈ decode₂ β n, f b) :=
match decode₂ β n with
| none => by
simp only [Option.mem_def, iUnion_of_empty, iUnion_empty, reduceCtorEq]
apply H0
| some b => by
convert H1 b
simp
open scoped Function in -- required for scoped `on` notation
theorem iUnion_decode₂_disjoint_on {f : β → Set α} (hd : Pairwise (Disjoint on f)) :
Pairwise (Disjoint on fun i => ⋃ b ∈ decode₂ β i, f b) := by
rintro i j ij
refine disjoint_left.mpr fun x => ?_
suffices ∀ a, encode a = i → x ∈ f a → ∀ b, encode b = j → x ∉ f b by simpa [decode₂_eq_some]
rintro a rfl ha b rfl hb
exact (hd (mt (congr_arg encode) ij)).le_bot ⟨ha, hb⟩
end Encodable |
.lake/packages/mathlib/Mathlib/Logic/Small/List.lean | import Mathlib.Logic.Small.Basic
import Mathlib.Data.Vector.Basic
/-!
# Instances for `Small (List α)` and `Small (Vector α)`.
These must not be in `Logic.Small.Basic` as this is very low in the import hierarchy,
and is used by category theory files which do not need everything imported by `Data.Vector.Basic`.
-/
universe u v
open Mathlib
instance smallVector {α : Type v} {n : ℕ} [Small.{u} α] : Small.{u} (List.Vector α n) :=
small_of_injective (Equiv.vectorEquivFin α n).injective
instance smallList {α : Type v} [Small.{u} α] : Small.{u} (List α) := by
let e : (Σ n, List.Vector α n) ≃ List α := Equiv.sigmaFiberEquiv List.length
exact small_of_surjective e.surjective |
.lake/packages/mathlib/Mathlib/Logic/Small/Basic.lean | import Mathlib.Logic.Small.Defs
import Mathlib.Logic.Equiv.Set
/-!
# Instances and theorems for `Small`.
In particular we prove `small_of_injective` and `small_of_surjective`.
-/
assert_not_exists Countable
universe u w v v'
-- TODO(timotree3): lower the priority on this instance?
-- This instance applies to every synthesis problem of the form `Small ↥s` for some set `s`,
-- but we have lots of instances of `Small` for specific set constructions.
instance small_subtype (α : Type v) [Small.{w} α] (P : α → Prop) : Small.{w} { x // P x } :=
small_map (equivShrink α).subtypeEquivOfSubtype'
theorem small_of_injective {α : Type v} {β : Type w} [Small.{u} β] {f : α → β}
(hf : Function.Injective f) : Small.{u} α :=
small_map (Equiv.ofInjective f hf)
theorem small_of_surjective {α : Type v} {β : Type w} [Small.{u} α] {f : α → β}
(hf : Function.Surjective f) : Small.{u} β :=
small_of_injective (Function.injective_surjInv hf)
instance (priority := 100) small_subsingleton (α : Type v) [Subsingleton α] : Small.{w} α := by
rcases isEmpty_or_nonempty α with ⟨⟩
· apply small_map (Equiv.equivPEmpty α)
· apply small_map Equiv.punitOfNonemptyOfSubsingleton
/-- This can be seen as a version of `small_of_surjective` in which the function `f` doesn't
actually land in `β` but in some larger type `γ` related to `β` via an injective function `g`.
-/
theorem small_of_injective_of_exists {α : Type v} {β : Type w} {γ : Type v'} [Small.{u} α]
(f : α → γ) {g : β → γ} (hg : Function.Injective g) (h : ∀ b : β, ∃ a : α, f a = g b) :
Small.{u} β := by
by_cases hβ : Nonempty β
· refine small_of_surjective (f := Function.invFun g ∘ f) (fun b => ?_)
obtain ⟨a, ha⟩ := h b
exact ⟨a, by rw [Function.comp_apply, ha, Function.leftInverse_invFun hg]⟩
· simp only [not_nonempty_iff] at hβ
infer_instance
/-!
We don't define `Countable.toSmall` in this file, to keep imports to `Logic` to a minimum.
-/
instance small_Pi {α} (β : α → Type*) [Small.{w} α] [∀ a, Small.{w} (β a)] :
Small.{w} (∀ a, β a) :=
⟨⟨∀ a' : Shrink α, Shrink (β ((equivShrink α).symm a')),
⟨Equiv.piCongr (equivShrink α) fun a => by simpa using equivShrink (β a)⟩⟩⟩
instance small_prod {α β} [Small.{w} α] [Small.{w} β] : Small.{w} (α × β) :=
⟨⟨Shrink α × Shrink β, ⟨Equiv.prodCongr (equivShrink α) (equivShrink β)⟩⟩⟩
instance small_sum {α β} [Small.{w} α] [Small.{w} β] : Small.{w} (α ⊕ β) :=
⟨⟨Shrink α ⊕ Shrink β, ⟨Equiv.sumCongr (equivShrink α) (equivShrink β)⟩⟩⟩
instance small_set {α} [Small.{w} α] : Small.{w} (Set α) :=
⟨⟨Set (Shrink α), ⟨Equiv.Set.congr (equivShrink α)⟩⟩⟩
instance small_quot {α : Type u} [Small.{v} α] (r : α → α → Prop) : Small.{v} (Quot r) :=
small_of_surjective Quot.mk_surjective
instance small_quotient {α : Type u} [Small.{v} α] (s : Setoid α) : Small.{v} (Quotient s) :=
small_of_surjective Quotient.mk_surjective |
.lake/packages/mathlib/Mathlib/Logic/Small/Defs.lean | import Mathlib.Logic.Equiv.Defs
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Tactic.PPWithUniv
/-!
# Small types
A type is `w`-small if there exists an equivalence to some `S : Type w`.
We provide a noncomputable model `Shrink α : Type w`, and `equivShrink α : α ≃ Shrink α`.
A subsingleton type is `w`-small for any `w`.
If `α ≃ β`, then `Small.{w} α ↔ Small.{w} β`.
See `Mathlib/Logic/Small/Basic.lean` for further instances and theorems.
-/
universe u w v v'
/-- A type is `Small.{w}` if there exists an equivalence to some `S : Type w`.
-/
@[mk_iff, pp_with_univ]
class Small (α : Type v) : Prop where
/-- If a type is `Small.{w}`, then there exists an equivalence with some `S : Type w` -/
equiv_small : ∃ S : Type w, Nonempty (α ≃ S)
/-- Constructor for `Small α` from an explicit witness type and equivalence.
-/
theorem Small.mk' {α : Type v} {S : Type w} (e : α ≃ S) : Small.{w} α :=
⟨⟨S, ⟨e⟩⟩⟩
/-- An arbitrarily chosen model in `Type w` for a `w`-small type.
-/
@[pp_with_univ]
def Shrink (α : Type v) [Small.{w} α] : Type w :=
Classical.choose (@Small.equiv_small α _)
/-- The noncomputable equivalence between a `w`-small type and a model.
-/
noncomputable def equivShrink (α : Type v) [Small.{w} α] : α ≃ Shrink α :=
Nonempty.some (Classical.choose_spec (@Small.equiv_small α _))
@[ext]
theorem Shrink.ext {α : Type v} [Small.{w} α] {x y : Shrink α}
(w : (equivShrink _).symm x = (equivShrink _).symm y) : x = y := by
simpa using w
-- It would be nice to mark this as `aesop cases` if
-- https://github.com/leanprover-community/aesop/issues/59
-- is resolved.
@[induction_eliminator]
protected noncomputable def Shrink.rec {α : Type*} [Small.{w} α] {F : Shrink α → Sort v}
(h : ∀ X, F (equivShrink _ X)) : ∀ X, F X :=
fun X => ((equivShrink _).apply_symm_apply X) ▸ (h _)
@[simp]
lemma Shrink.rec_equivShrink {α : Type*} [Small.{w} α] {F : Shrink α → Sort v}
{f : (a : α) → F (equivShrink α a)} (a : α) : Shrink.rec f (equivShrink _ a) = f a := by
simp only [Shrink.rec, eqRec_eq_cast, cast_eq_iff_heq]
rw [Equiv.symm_apply_apply]
instance small_self (α : Type v) : Small.{v} α :=
Small.mk' <| Equiv.refl α
theorem small_map {α : Type*} {β : Type*} [hβ : Small.{w} β] (e : α ≃ β) : Small.{w} α :=
let ⟨_, ⟨f⟩⟩ := hβ.equiv_small
Small.mk' (e.trans f)
theorem small_lift (α : Type u) [hα : Small.{v} α] : Small.{max v w} α :=
let ⟨⟨_, ⟨f⟩⟩⟩ := hα
Small.mk' <| f.trans (Equiv.ulift.{w}).symm
/-- Due to https://github.com/leanprover/lean4/issues/2297, this is useless as an instance.
See however `Logic.UnivLE`, whose API is able to indirectly provide this instance. -/
lemma small_max (α : Type v) : Small.{max w v} α :=
small_lift.{v, w} α
instance small_zero (α : Type) : Small.{w} α := small_max α
instance (priority := 100) small_succ (α : Type v) : Small.{v + 1} α :=
small_lift.{v, v + 1} α
instance small_ulift (α : Type u) [Small.{v} α] : Small.{v} (ULift.{w} α) :=
small_map Equiv.ulift
instance small_plift (α : Type u) [Small.{v} α] : Small.{v} (PLift α) :=
small_map Equiv.plift
theorem small_type : Small.{max (u + 1) v} (Type u) :=
small_max.{max (u + 1) v} _
instance {α : Type u} [Small.{v} α] [Nontrivial α] : Nontrivial (Shrink.{v} α) :=
(equivShrink α).symm.nontrivial
section
theorem small_congr {α : Type*} {β : Type*} (e : α ≃ β) : Small.{w} α ↔ Small.{w} β :=
⟨fun h => @small_map _ _ h e.symm, fun h => @small_map _ _ h e⟩
instance small_sigma {α} (β : α → Type*) [Small.{w} α] [∀ a, Small.{w} (β a)] :
Small.{w} (Σ a, β a) :=
⟨⟨Σ a' : Shrink α, Shrink (β ((equivShrink α).symm a')),
⟨Equiv.sigmaCongr (equivShrink α) fun a => by simpa using equivShrink (β a)⟩⟩⟩
theorem not_small_type : ¬Small.{u} (Type max u v)
| ⟨⟨S, ⟨e⟩⟩⟩ =>
@Function.cantor_injective (Σ α, e.symm α) (fun a => ⟨_, cast (e.3 _).symm a⟩) fun a b e => by
dsimp at e
injection e with h₁ h₂
simpa using h₂
end |
.lake/packages/mathlib/Mathlib/Logic/Small/Set.lean | import Mathlib.Data.Set.Lattice
import Mathlib.Logic.Small.Basic
/-!
# Results about `Small` on coerced sets
-/
universe u u1 u2 u3 u4
variable {α : Type u1} {β : Type u2} {γ : Type u3} {ι : Type u4}
theorem small_subset {s t : Set α} (hts : t ⊆ s) [Small.{u} s] : Small.{u} t :=
small_of_injective (Set.inclusion_injective hts)
instance small_powerset (s : Set α) [Small.{u} s] : Small.{u} (𝒫 s) :=
small_map (Equiv.Set.powerset s)
instance small_setProd (s : Set α) (t : Set β) [Small.{u} s] [Small.{u} t] :
Small.{u} (s ×ˢ t : Set (α × β)) :=
small_of_injective (Equiv.Set.prod s t).injective
instance small_setPi {β : α → Type u2} (s : (a : α) → Set (β a))
[Small.{u} α] [∀ a, Small.{u} (s a)] : Small.{u} (Set.pi Set.univ s) :=
small_of_injective (Equiv.Set.univPi s).injective
instance small_range (f : α → β) [Small.{u} α] :
Small.{u} (Set.range f) :=
small_of_surjective Set.rangeFactorization_surjective
instance small_image (f : α → β) (s : Set α) [Small.{u} s] :
Small.{u} (f '' s) :=
small_of_surjective Set.imageFactorization_surjective
instance small_image2 (f : α → β → γ) (s : Set α) (t : Set β) [Small.{u} s] [Small.{u} t] :
Small.{u} (Set.image2 f s t) := by
rw [← Set.image_uncurry_prod]
infer_instance
theorem small_univ_iff : Small.{u} (@Set.univ α) ↔ Small.{u} α :=
small_congr <| Equiv.Set.univ α
instance small_univ [h : Small.{u} α] : Small.{u} (@Set.univ α) :=
small_univ_iff.2 h
instance small_union (s t : Set α) [Small.{u} s] [Small.{u} t] :
Small.{u} (s ∪ t : Set α) := by
rw [← Subtype.range_val (s := s), ← Subtype.range_val (s := t), ← Set.Sum.elim_range]
infer_instance
instance small_iUnion [Small.{u} ι] (s : ι → Set α)
[∀ i, Small.{u} (s i)] : Small.{u} (⋃ i, s i) :=
small_of_surjective <| Set.sigmaToiUnion_surjective _
instance small_sUnion (s : Set (Set α)) [Small.{u} s] [∀ t : s, Small.{u} t] :
Small.{u} (⋃₀ s) :=
Set.sUnion_eq_iUnion ▸ small_iUnion _
instance small_biUnion (s : Set ι) [Small.{u} s]
(f : (i : ι) → i ∈ s → Set α) [∀ i hi, Small.{u} (f i hi)] : Small.{u} (⋃ i, ⋃ hi, f i hi) :=
Set.biUnion_eq_iUnion s f ▸ small_iUnion _
instance small_insert (x : α) (s : Set α) [Small.{u} s] :
Small.{u} (insert x s : Set α) :=
Set.insert_eq x s ▸ small_union.{u} {x} s
instance small_diff (s t : Set α) [Small.{u} s] : Small.{u} (s \ t : Set α) :=
small_subset (Set.diff_subset)
instance small_sep (s : Set α) (P : α → Prop) [Small.{u} s] :
Small.{u} { x | x ∈ s ∧ P x} :=
small_subset (Set.sep_subset s P)
instance small_inter_of_left (s t : Set α) [Small.{u} s] :
Small.{u} (s ∩ t : Set α) :=
small_subset Set.inter_subset_left
instance small_inter_of_right (s t : Set α) [Small.{u} t] :
Small.{u} (s ∩ t : Set α) :=
small_subset Set.inter_subset_right
theorem small_iInter (s : ι → Set α) (i : ι)
[Small.{u} (s i)] : Small.{u} (⋂ i, s i) :=
small_subset (Set.iInter_subset s i)
instance small_iInter' [Nonempty ι] (s : ι → Set α)
[∀ i, Small.{u} (s i)] : Small.{u} (⋂ i, s i) :=
let ⟨i⟩ : Nonempty ι := inferInstance
small_iInter s i
theorem small_sInter {s : Set (Set α)} {t : Set α} (ht : t ∈ s)
[Small.{u} t] : Small.{u} (⋂₀ s) :=
Set.sInter_eq_iInter ▸ small_iInter _ ⟨t, ht⟩
instance small_sInter' {s : Set (Set α)} [Nonempty s]
[∀ t : s, Small.{u} t] : Small.{u} (⋂₀ s) :=
let ⟨t⟩ : Nonempty s := inferInstance
small_sInter t.prop
theorem small_biInter {s : Set ι} {i : ι} (hi : i ∈ s)
(f : (i : ι) → i ∈ s → Set α) [Small.{u} (f i hi)] : Small.{u} (⋂ i, ⋂ hi, f i hi) :=
Set.biInter_eq_iInter s f ▸ small_iInter _ ⟨i, hi⟩
instance small_biInter' (s : Set ι) [Nonempty s]
(f : (i : ι) → i ∈ s → Set α) [∀ i hi, Small.{u} (f i hi)] : Small.{u} (⋂ i, ⋂ hi, f i hi) :=
let ⟨t⟩ : Nonempty s := inferInstance
small_biInter t.prop f
theorem small_empty : Small.{u} (∅ : Set α) :=
inferInstance
theorem small_single (x : α) : Small.{u} ({x} : Set α) :=
inferInstance
theorem small_pair (x y : α) : Small.{u} ({x, y} : Set α) :=
inferInstance |
.lake/packages/mathlib/Mathlib/Logic/Godel/GodelBetaFunction.lean | import Mathlib.Data.Nat.ModEq
import Mathlib.Data.Nat.ChineseRemainder
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.Data.Nat.Pairing
import Mathlib.Order.Fin.Basic
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Nat.Factorial.Basic
/-!
# Gödel's Beta Function Lemma
This file proves Gödel's Beta Function Lemma, used to prove the First Incompleteness Theorem. It
permits quantification over finite sequences of natural numbers in formal theories of arithmetic.
This Beta Function has no connection with the unrelated Beta Function defined in analysis. Note
that `Nat.beta` and `Nat.unbeta` provide similar functionality to `Encodable.encodeList` and
`Encodable.decodeList`. We define these separately, because it is easier to prove that `Nat.beta`
and `Nat.unbeta` are arithmetically definable, and this is hard to prove that for
`Encodable.encodeList` and `Encodable.decodeList` directly. The arithmetic
definability is needed for the proof of the First Incompleteness Theorem.
## Main result
- `beta_unbeta_coe`: Gödel's Beta Function Lemma.
## Implementation note
This code is a step towards eventually including a proof of Gödel's First Incompleteness Theorem
and other key results from the repository https://github.com/iehality/lean4-logic.
## References
* [R. Kaye, *Models of Peano arithmetic*][kaye1991]
* <https://en.wikipedia.org/wiki/G%C3%B6del%27s_%CE%B2_function>
## Tags
Gödel, beta function
-/
namespace Nat
lemma coprime_mul_succ {n m a} (ha : m - n ∣ a) : Coprime (n * a + 1) (m * a + 1) :=
Nat.coprime_of_dvd fun p pp hn hm => by
have : p ∣ (m - n) * a := by
simpa [Nat.succ_sub_succ, ← Nat.mul_sub_right_distrib] using
Nat.dvd_sub hm hn
have : p ∣ a := by
rcases (Nat.Prime.dvd_mul pp).mp this with (hp | hp)
· exact Nat.dvd_trans hp ha
· exact hp
apply pp.ne_one
simpa [Nat.add_sub_cancel_left] using Nat.dvd_sub hn (this.mul_left n)
variable {m : ℕ}
private def supOfSeq (a : Fin m → ℕ) : ℕ := max m (Finset.sup .univ a) + 1
private def coprimes (a : Fin m → ℕ) : Fin m → ℕ := fun i => (i + 1) * (supOfSeq a)! + 1
lemma coprimes_lt (a : Fin m → ℕ) (i) : a i < coprimes a i := by
have h₁ : a i < supOfSeq a :=
Nat.lt_add_one_iff.mpr (le_max_of_le_right <| Finset.le_sup (by simp))
have h₂ : supOfSeq a ≤ (i + 1) * (supOfSeq a)! + 1 :=
le_trans (self_le_factorial _) (le_trans (Nat.le_mul_of_pos_left (supOfSeq a)! (succ_pos i))
(le_add_right _ _))
simpa only [coprimes] using lt_of_lt_of_le h₁ h₂
open scoped Function in -- required for scoped `on` notation
private lemma pairwise_coprime_coprimes (a : Fin m → ℕ) : Pairwise (Coprime on coprimes a) := by
intro i j hij
wlog ltij : i < j
· exact (this a hij.symm (lt_of_le_of_ne (Fin.not_lt.mp ltij) hij.symm)).symm
unfold Function.onFun coprimes
have hja : j < supOfSeq a := lt_of_lt_of_le j.prop (le_step (le_max_left _ _))
exact coprime_mul_succ
(Nat.dvd_factorial (by cutsat)
(by simpa only [Nat.succ_sub_succ] using le_of_lt (lt_of_le_of_lt (sub_le j i) hja)))
/-- Gödel's Beta Function. This is similar to `(Encodable.decodeList)[i]`, but it is easier to
prove that it is arithmetically definable. -/
def beta (n i : ℕ) : ℕ := n.unpair.1 % ((i + 1) * n.unpair.2 + 1)
/-- Inverse of Gödel's Beta Function. This is similar to `Encodable.encodeList`, but it is easier
to prove that it is arithmetically definable. -/
def unbeta (l : List ℕ) : ℕ :=
(chineseRemainderOfFinset (l[·]) (coprimes (l[·])) Finset.univ
(by simp [coprimes])
(by simpa using Set.pairwise_univ.mpr (pairwise_coprime_coprimes _)) : ℕ).pair
(supOfSeq (l[·]))!
/-- **Gödel's Beta Function Lemma** -/
lemma beta_unbeta_coe (l : List ℕ) (i : Fin l.length) : beta (unbeta l) i = l[i] := by
simpa [beta, unbeta, coprimes] using mod_eq_of_modEq
((chineseRemainderOfFinset (l[·]) (coprimes (l[·])) Finset.univ
(by simp [coprimes])
(by simpa using Set.pairwise_univ.mpr (pairwise_coprime_coprimes _))).prop i (by simp))
(coprimes_lt _ _)
end Nat |
.lake/packages/mathlib/Mathlib/Std/Data/HashMap.lean | import Std.Data.HashMap.AdditionalOperations
import Mathlib.Tactic.Linter.DeprecatedModule
deprecated_module (since := "2025-08-18")
/-!
# Convenience functions for hash maps
This is now reimplemented in the Lean standard library.
-/
namespace Std.HashMap
variable {α β γ : Type _} [BEq α] [Hashable α]
/-- Apply a function to the values of a hash map. -/
@[deprecated Std.HashMap.map (since := "2025-08-18")]
def mapVal (f : α → β → γ) (m : HashMap α β) : HashMap α γ :=
m.fold (fun acc k v => acc.insert k (f k v)) ∅
end Std.HashMap |
.lake/packages/mathlib/Mathlib/CategoryTheory/Yoneda.lean | import Mathlib.CategoryTheory.Functor.Hom
import Mathlib.CategoryTheory.Products.Basic
import Mathlib.Data.ULift
import Mathlib.Logic.Function.ULift
/-!
# The Yoneda embedding
The Yoneda embedding as a functor `yoneda : C ⥤ (Cᵒᵖ ⥤ Type v₁)`,
along with an instance that it is `FullyFaithful`.
Also the Yoneda lemma, `yonedaLemma : (yoneda_pairing C) ≅ (yoneda_evaluation C)`.
## References
* [Stacks: Opposite Categories and the Yoneda Lemma](https://stacks.math.columbia.edu/tag/001L)
-/
namespace CategoryTheory
open Opposite Functor
universe w v v₁ v₂ u₁ u₂
-- morphism levels before object levels. See note [category theory universes].
variable {C : Type u₁} [Category.{v₁} C]
/-- The Yoneda embedding, as a functor from `C` into presheaves on `C`. -/
@[simps, stacks 001O]
def yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁ where
obj X :=
{ obj := fun Y => unop Y ⟶ X
map := fun f g => f.unop ≫ g }
map f :=
{ app := fun _ g => g ≫ f }
/-- Variant of the Yoneda embedding which allows a raise in the universe level
for the category of types. -/
@[pp_with_univ, simps!]
def uliftYoneda : C ⥤ Cᵒᵖ ⥤ Type (max w v₁) :=
yoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{w}
/-- If `C` is a category with `[Category.{max w v₁} C]`, this is the isomorphism
`uliftYoneda.{w} (C := C) ≅ yoneda`. -/
@[simps!]
def uliftYonedaIsoYoneda {C : Type u₁} [Category.{max w v₁} C] :
uliftYoneda.{w} (C := C) ≅ yoneda :=
NatIso.ofComponents (fun _ ↦ NatIso.ofComponents (fun _ ↦ Equiv.ulift.toIso))
/-- The co-Yoneda embedding, as a functor from `Cᵒᵖ` into co-presheaves on `C`.
-/
abbrev coyoneda : Cᵒᵖ ⥤ C ⥤ Type v₁ := yoneda.flip
/-- Variant of the Coyoneda embedding which allows a raise in the universe level
for the category of types. -/
@[pp_with_univ]
abbrev uliftCoyoneda : Cᵒᵖ ⥤ C ⥤ Type (max w v₁) := uliftYoneda.{w}.flip
/-- If `C` is a category with `[Category.{max w v₁} C]`, this is the isomorphism
`uliftCoyoneda.{w} (C := C) ≅ coyoneda`. -/
@[simps!]
def uliftCoyonedaIsoCoyoneda {C : Type u₁} [Category.{max w v₁} C] :
uliftCoyoneda.{w} (C := C) ≅ coyoneda :=
NatIso.ofComponents (fun _ ↦ NatIso.ofComponents (fun _ ↦ Equiv.ulift.toIso))
namespace Yoneda
theorem obj_map_id {X Y : C} (f : op X ⟶ op Y) :
(yoneda.obj X).map f (𝟙 X) = (yoneda.map f.unop).app (op Y) (𝟙 Y) := by
simp
@[simp]
theorem naturality {X Y : C} (α : yoneda.obj X ⟶ yoneda.obj Y) {Z Z' : C} (f : Z ⟶ Z')
(h : Z' ⟶ X) : f ≫ α.app (op Z') h = α.app (op Z) (f ≫ h) :=
(FunctorToTypes.naturality _ _ α f.op h).symm
/-- The Yoneda embedding is fully faithful. -/
def fullyFaithful : (yoneda (C := C)).FullyFaithful where
preimage f := f.app _ (𝟙 _)
lemma fullyFaithful_preimage {X Y : C} (f : yoneda.obj X ⟶ yoneda.obj Y) :
fullyFaithful.preimage f = f.app (op X) (𝟙 X) := rfl
/-- The Yoneda embedding is full. -/
@[stacks 001P]
instance yoneda_full : (yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁).Full :=
fullyFaithful.full
/-- The Yoneda embedding is faithful. -/
@[stacks 001P]
instance yoneda_faithful : (yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁).Faithful :=
fullyFaithful.faithful
/-- Extensionality via Yoneda. The typical usage would be
```
-- Goal is `X ≅ Y`
apply Yoneda.ext
-- Goals are now functions `(Z ⟶ X) → (Z ⟶ Y)`, `(Z ⟶ Y) → (Z ⟶ X)`, and the fact that these
-- functions are inverses and natural in `Z`.
```
-/
def ext (X Y : C) (p : ∀ {Z : C}, (Z ⟶ X) → (Z ⟶ Y))
(q : ∀ {Z : C}, (Z ⟶ Y) → (Z ⟶ X))
(h₁ : ∀ {Z : C} (f : Z ⟶ X), q (p f) = f) (h₂ : ∀ {Z : C} (f : Z ⟶ Y), p (q f) = f)
(n : ∀ {Z Z' : C} (f : Z' ⟶ Z) (g : Z ⟶ X), p (f ≫ g) = f ≫ p g) : X ≅ Y :=
fullyFaithful.preimageIso
(NatIso.ofComponents fun Z =>
{ hom := p
inv := q })
/-- If `yoneda.map f` is an isomorphism, so was `f`.
-/
theorem isIso {X Y : C} (f : X ⟶ Y) [IsIso (yoneda.map f)] : IsIso f :=
isIso_of_fully_faithful yoneda f
end Yoneda
namespace ULiftYoneda
variable (C)
/-- When `C` is category such that `Category.{v₁} C`, then
the functor `uliftYoneda.{w} : C ⥤ Cᵒᵖ ⥤ Type max w v₁` is fully faithful. -/
def fullyFaithful : (uliftYoneda.{w} (C := C)).FullyFaithful :=
Yoneda.fullyFaithful.comp (fullyFaithfulULiftFunctor.whiskeringRight _)
instance : (uliftYoneda.{w} (C := C)).Full :=
(fullyFaithful C).full
instance : (uliftYoneda.{w} (C := C)).Faithful :=
(fullyFaithful C).faithful
end ULiftYoneda
namespace Coyoneda
@[simp]
theorem naturality {X Y : Cᵒᵖ} (α : coyoneda.obj X ⟶ coyoneda.obj Y) {Z Z' : C} (f : Z' ⟶ Z)
(h : unop X ⟶ Z') : α.app Z' h ≫ f = α.app Z (h ≫ f) :=
(FunctorToTypes.naturality _ _ α f h).symm
/-- The co-Yoneda embedding is fully faithful. -/
def fullyFaithful : (coyoneda (C := C)).FullyFaithful where
preimage f := (f.app _ (𝟙 _)).op
lemma fullyFaithful_preimage {X Y : Cᵒᵖ} (f : coyoneda.obj X ⟶ coyoneda.obj Y) :
fullyFaithful.preimage f = (f.app X.unop (𝟙 X.unop)).op := rfl
/-- The morphism `X ⟶ Y` corresponding to a natural transformation
`coyoneda.obj X ⟶ coyoneda.obj Y`. -/
def preimage {X Y : Cᵒᵖ} (f : coyoneda.obj X ⟶ coyoneda.obj Y) : X ⟶ Y :=
(f.app _ (𝟙 X.unop)).op
instance coyoneda_full : (coyoneda : Cᵒᵖ ⥤ C ⥤ Type v₁).Full :=
fullyFaithful.full
instance coyoneda_faithful : (coyoneda : Cᵒᵖ ⥤ C ⥤ Type v₁).Faithful :=
fullyFaithful.faithful
/-- Extensionality via Coyoneda. The typical usage would be
```
-- Goal is `X ≅ Y`
apply Coyoneda.ext
-- Goals are now functions `(X ⟶ Z) → (Y ⟶ Z)`, `(Y ⟶ Z) → (X ⟶ Z)`, and the fact that these
-- functions are inverses and natural in `Z`.
```
-/
def ext (X Y : C) (p : ∀ {Z : C}, (X ⟶ Z) → (Y ⟶ Z))
(q : ∀ {Z : C}, (Y ⟶ Z) → (X ⟶ Z))
(h₁ : ∀ {Z : C} (f : X ⟶ Z), q (p f) = f) (h₂ : ∀ {Z : C} (f : Y ⟶ Z), p (q f) = f)
(n : ∀ {Z Z' : C} (f : Y ⟶ Z) (g : Z ⟶ Z'), q (f ≫ g) = q f ≫ g) : X ≅ Y :=
fullyFaithful.preimageIso
(NatIso.ofComponents (fun Z =>
{ hom := q
inv := p })
) |>.unop
/-- If `coyoneda.map f` is an isomorphism, so was `f`.
-/
theorem isIso {X Y : Cᵒᵖ} (f : X ⟶ Y) [IsIso (coyoneda.map f)] : IsIso f :=
isIso_of_fully_faithful coyoneda f
/-- The identity functor on `Type` is isomorphic to the coyoneda functor coming from `PUnit`. -/
def punitIso : coyoneda.obj (Opposite.op PUnit) ≅ 𝟭 (Type v₁) :=
NatIso.ofComponents fun X =>
{ hom := fun f => f ⟨⟩
inv := fun x _ => x }
/-- Taking the `unop` of morphisms is a natural isomorphism. -/
@[simps!]
def objOpOp (X : C) : coyoneda.obj (op (op X)) ≅ yoneda.obj X :=
NatIso.ofComponents fun _ => (opEquiv _ _).toIso
/-- Taking the `unop` of morphisms is a natural isomorphism. -/
def opIso : yoneda ⋙ (whiskeringLeft _ _ _).obj (opOp C) ≅ coyoneda :=
NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun Y ↦ (opEquiv (op Y) X).toIso)
(fun _ ↦ rfl)) (fun _ ↦ rfl)
namespace ULiftCoyoneda
variable (C)
/-- When `C` is category such that `Category.{v₁} C`, then
the functor `uliftCoyoneda.{w} : C ⥤ Cᵒᵖ ⥤ Type max w v₁` is fully faithful. -/
def fullyFaithful : (uliftCoyoneda.{w} (C := C)).FullyFaithful :=
Coyoneda.fullyFaithful.comp (fullyFaithfulULiftFunctor.whiskeringRight _)
instance : (uliftCoyoneda.{w} (C := C)).Full :=
(fullyFaithful C).full
instance : (uliftCoyoneda.{w} (C := C)).Faithful :=
(fullyFaithful C).faithful
end ULiftCoyoneda
end Coyoneda
namespace Functor
/-- The data which expresses that a functor `F : Cᵒᵖ ⥤ Type v` is representable by `Y : C`. -/
structure RepresentableBy (F : Cᵒᵖ ⥤ Type v) (Y : C) where
/-- the natural bijection `(X ⟶ Y) ≃ F.obj (op X)`. -/
homEquiv {X : C} : (X ⟶ Y) ≃ F.obj (op X)
homEquiv_comp {X X' : C} (f : X ⟶ X') (g : X' ⟶ Y) :
homEquiv (f ≫ g) = F.map f.op (homEquiv g)
lemma RepresentableBy.comp_homEquiv_symm {F : Cᵒᵖ ⥤ Type v} {Y : C}
(e : F.RepresentableBy Y) {X X' : C} (x : F.obj (op X')) (f : X ⟶ X') :
f ≫ e.homEquiv.symm x = e.homEquiv.symm (F.map f.op x) :=
e.homEquiv.injective (by simp [homEquiv_comp])
/-- If `F ≅ F'`, and `F` is representable, then `F'` is representable. -/
def RepresentableBy.ofIso {F F' : Cᵒᵖ ⥤ Type v} {Y : C} (e : F.RepresentableBy Y) (e' : F ≅ F') :
F'.RepresentableBy Y where
homEquiv {X} := e.homEquiv.trans (e'.app _).toEquiv
homEquiv_comp {X X'} f g := by
dsimp
rw [e.homEquiv_comp]
apply congr_fun (e'.hom.naturality f.op)
/-- The data which expresses that a functor `F : C ⥤ Type v` is corepresentable by `X : C`. -/
structure CorepresentableBy (F : C ⥤ Type v) (X : C) where
/-- the natural bijection `(X ⟶ Y) ≃ F.obj Y`. -/
homEquiv {Y : C} : (X ⟶ Y) ≃ F.obj Y
homEquiv_comp {Y Y' : C} (g : Y ⟶ Y') (f : X ⟶ Y) :
homEquiv (f ≫ g) = F.map g (homEquiv f)
lemma CorepresentableBy.homEquiv_symm_comp {F : C ⥤ Type v} {X : C}
(e : F.CorepresentableBy X) {Y Y' : C} (y : F.obj Y) (g : Y ⟶ Y') :
e.homEquiv.symm y ≫ g = e.homEquiv.symm (F.map g y) :=
e.homEquiv.injective (by simp [homEquiv_comp])
/-- If `F ≅ F'`, and `F` is corepresentable, then `F'` is corepresentable. -/
def CorepresentableBy.ofIso {F F' : C ⥤ Type v} {X : C} (e : F.CorepresentableBy X)
(e' : F ≅ F') :
F'.CorepresentableBy X where
homEquiv {X} := e.homEquiv.trans (e'.app _).toEquiv
homEquiv_comp {Y Y'} g f := by
dsimp
rw [e.homEquiv_comp]
apply congr_fun (e'.hom.naturality g)
lemma RepresentableBy.homEquiv_eq {F : Cᵒᵖ ⥤ Type v} {Y : C} (e : F.RepresentableBy Y)
{X : C} (f : X ⟶ Y) :
e.homEquiv f = F.map f.op (e.homEquiv (𝟙 Y)) := by
conv_lhs => rw [← Category.comp_id f, e.homEquiv_comp]
lemma CorepresentableBy.homEquiv_eq {F : C ⥤ Type v} {X : C} (e : F.CorepresentableBy X)
{Y : C} (f : X ⟶ Y) :
e.homEquiv f = F.map f (e.homEquiv (𝟙 X)) := by
conv_lhs => rw [← Category.id_comp f, e.homEquiv_comp]
/-- Representing objects are unique up to isomorphism. -/
@[simps!]
def RepresentableBy.uniqueUpToIso {F : Cᵒᵖ ⥤ Type v} {Y Y' : C} (e : F.RepresentableBy Y)
(e' : F.RepresentableBy Y') : Y ≅ Y' :=
let ε {X} := (@e.homEquiv X).trans e'.homEquiv.symm
Yoneda.ext _ _ ε ε.symm (by simp) (by simp)
(by simp [ε, comp_homEquiv_symm, homEquiv_comp])
/-- Corepresenting objects are unique up to isomorphism. -/
@[simps!]
def CorepresentableBy.uniqueUpToIso {F : C ⥤ Type v} {X X' : C} (e : F.CorepresentableBy X)
(e' : F.CorepresentableBy X') : X ≅ X' :=
let ε {Y} := (@e.homEquiv Y).trans e'.homEquiv.symm
Coyoneda.ext _ _ ε ε.symm (by simp) (by simp)
(by simp [ε, homEquiv_symm_comp, homEquiv_comp])
@[ext]
lemma RepresentableBy.ext {F : Cᵒᵖ ⥤ Type v} {Y : C} {e e' : F.RepresentableBy Y}
(h : e.homEquiv (𝟙 Y) = e'.homEquiv (𝟙 Y)) : e = e' := by
have : ∀ {X : C} (f : X ⟶ Y), e.homEquiv f = e'.homEquiv f := fun {X} f ↦ by
rw [e.homEquiv_eq, e'.homEquiv_eq, h]
obtain ⟨e, he⟩ := e
obtain ⟨e', he'⟩ := e'
obtain rfl : @e = @e' := by ext; apply this
rfl
@[ext]
lemma CorepresentableBy.ext {F : C ⥤ Type v} {X : C} {e e' : F.CorepresentableBy X}
(h : e.homEquiv (𝟙 X) = e'.homEquiv (𝟙 X)) : e = e' := by
have : ∀ {Y : C} (f : X ⟶ Y), e.homEquiv f = e'.homEquiv f := fun {X} f ↦ by
rw [e.homEquiv_eq, e'.homEquiv_eq, h]
obtain ⟨e, he⟩ := e
obtain ⟨e', he'⟩ := e'
obtain rfl : @e = @e' := by ext; apply this
rfl
/-- The obvious bijection `F.RepresentableBy Y ≃ (yoneda.obj Y ≅ F)`
when `F : Cᵒᵖ ⥤ Type v₁` and `[Category.{v₁} C]`. -/
def representableByEquiv {F : Cᵒᵖ ⥤ Type v₁} {Y : C} :
F.RepresentableBy Y ≃ (yoneda.obj Y ≅ F) where
toFun r := NatIso.ofComponents (fun _ ↦ r.homEquiv.toIso) (fun {X X'} f ↦ by
ext g
simp [r.homEquiv_comp])
invFun e :=
{ homEquiv := (e.app _).toEquiv
homEquiv_comp := fun {X X'} f g ↦ congr_fun (e.hom.naturality f.op) g }
/-- The isomorphism `yoneda.obj Y ≅ F` induced by `e : F.RepresentableBy Y`. -/
def RepresentableBy.toIso {F : Cᵒᵖ ⥤ Type v₁} {Y : C} (e : F.RepresentableBy Y) :
yoneda.obj Y ≅ F :=
representableByEquiv e
/-- The obvious bijection `F.CorepresentableBy X ≃ (yoneda.obj Y ≅ F)`
when `F : C ⥤ Type v₁` and `[Category.{v₁} C]`. -/
def corepresentableByEquiv {F : C ⥤ Type v₁} {X : C} :
F.CorepresentableBy X ≃ (coyoneda.obj (op X) ≅ F) where
toFun r := NatIso.ofComponents (fun _ ↦ r.homEquiv.toIso) (fun {X X'} f ↦ by
ext g
simp [r.homEquiv_comp])
invFun e :=
{ homEquiv := (e.app _).toEquiv
homEquiv_comp := fun {X X'} f g ↦ congr_fun (e.hom.naturality f) g }
/-- The isomorphism `coyoneda.obj (op X) ≅ F` induced by `e : F.CorepresentableBy X`. -/
def CorepresentableBy.toIso {F : C ⥤ Type v₁} {X : C} (e : F.CorepresentableBy X) :
coyoneda.obj (op X) ≅ F :=
corepresentableByEquiv e
/-- A functor `F : Cᵒᵖ ⥤ Type v` is representable if there is an object `Y` with a structure
`F.RepresentableBy Y`, i.e. there is a natural bijection `(X ⟶ Y) ≃ F.obj (op X)`,
which may also be rephrased as a natural isomorphism `yoneda.obj X ≅ F` when `Category.{v} C`. -/
@[stacks 001Q]
class IsRepresentable (F : Cᵒᵖ ⥤ Type v) : Prop where
has_representation : ∃ (Y : C), Nonempty (F.RepresentableBy Y)
lemma RepresentableBy.isRepresentable {F : Cᵒᵖ ⥤ Type v} {Y : C} (e : F.RepresentableBy Y) :
F.IsRepresentable where
has_representation := ⟨Y, ⟨e⟩⟩
/-- Alternative constructor for `F.IsRepresentable`, which takes as an input an
isomorphism `yoneda.obj X ≅ F`. -/
lemma IsRepresentable.mk' {F : Cᵒᵖ ⥤ Type v₁} {X : C} (e : yoneda.obj X ≅ F) :
F.IsRepresentable :=
(representableByEquiv.symm e).isRepresentable
instance {X : C} : IsRepresentable (yoneda.obj X) :=
IsRepresentable.mk' (Iso.refl _)
/-- A functor `F : C ⥤ Type v₁` is corepresentable if there is object `X` so `F ≅ coyoneda.obj X`.
-/
@[stacks 001Q]
class IsCorepresentable (F : C ⥤ Type v) : Prop where
has_corepresentation : ∃ (X : C), Nonempty (F.CorepresentableBy X)
lemma CorepresentableBy.isCorepresentable {F : C ⥤ Type v} {X : C} (e : F.CorepresentableBy X) :
F.IsCorepresentable where
has_corepresentation := ⟨X, ⟨e⟩⟩
/-- Alternative constructor for `F.IsCorepresentable`, which takes as an input an
isomorphism `coyoneda.obj (op X) ≅ F`. -/
lemma IsCorepresentable.mk' {F : C ⥤ Type v₁} {X : C} (e : coyoneda.obj (op X) ≅ F) :
F.IsCorepresentable :=
(corepresentableByEquiv.symm e).isCorepresentable
instance {X : Cᵒᵖ} : IsCorepresentable (coyoneda.obj X) :=
IsCorepresentable.mk' (Iso.refl _)
-- instance : corepresentable (𝟭 (Type v₁)) :=
-- corepresentable_of_nat_iso (op punit) coyoneda.punit_iso
section Representable
variable (F : Cᵒᵖ ⥤ Type v) [hF : F.IsRepresentable]
/-- The representing object for the representable functor `F`. -/
noncomputable def reprX : C :=
hF.has_representation.choose
/-- A chosen term in `F.RepresentableBy (reprX F)` when `F.IsRepresentable` holds. -/
noncomputable def representableBy : F.RepresentableBy F.reprX :=
hF.has_representation.choose_spec.some
/-- Any representing object for a representable functor `F` is isomorphic to `reprX F`. -/
noncomputable def RepresentableBy.isoReprX {Y : C} (e : F.RepresentableBy Y) :
Y ≅ F.reprX :=
RepresentableBy.uniqueUpToIso e (representableBy F)
/-- The representing element for the representable functor `F`, sometimes called the universal
element of the functor.
-/
noncomputable def reprx : F.obj (op F.reprX) :=
F.representableBy.homEquiv (𝟙 _)
/-- An isomorphism between a representable `F` and a functor of the
form `C(-, F.reprX)`. Note the components `F.reprW.app X`
definitionally have type `(X.unop ⟶ F.reprX) ≅ F.obj X`.
-/
noncomputable def reprW (F : Cᵒᵖ ⥤ Type v₁) [F.IsRepresentable] :
yoneda.obj F.reprX ≅ F := F.representableBy.toIso
theorem reprW_hom_app (F : Cᵒᵖ ⥤ Type v₁) [F.IsRepresentable]
(X : Cᵒᵖ) (f : unop X ⟶ F.reprX) :
F.reprW.hom.app X f = F.map f.op F.reprx := by
apply RepresentableBy.homEquiv_eq
end Representable
section Corepresentable
variable (F : C ⥤ Type v) [hF : F.IsCorepresentable]
/-- The representing object for the corepresentable functor `F`. -/
noncomputable def coreprX : C :=
hF.has_corepresentation.choose
/-- A chosen term in `F.CorepresentableBy (coreprX F)` when `F.IsCorepresentable` holds. -/
noncomputable def corepresentableBy : F.CorepresentableBy F.coreprX :=
hF.has_corepresentation.choose_spec.some
variable {F} in
/-- Any corepresenting object for a corepresentable functor `F` is isomorphic to `coreprX F`. -/
noncomputable def CorepresentableBy.isoCoreprX {Y : C} (e : F.CorepresentableBy Y) :
Y ≅ F.coreprX :=
CorepresentableBy.uniqueUpToIso e (corepresentableBy F)
/-- The representing element for the corepresentable functor `F`, sometimes called the universal
element of the functor.
-/
noncomputable def coreprx : F.obj F.coreprX :=
F.corepresentableBy.homEquiv (𝟙 _)
/-- An isomorphism between a corepresentable `F` and a functor of the form
`C(F.corepr X, -)`. Note the components `F.coreprW.app X`
definitionally have type `F.corepr_X ⟶ X ≅ F.obj X`.
-/
noncomputable def coreprW (F : C ⥤ Type v₁) [F.IsCorepresentable] :
coyoneda.obj (op F.coreprX) ≅ F :=
F.corepresentableBy.toIso
theorem coreprW_hom_app (F : C ⥤ Type v₁) [F.IsCorepresentable] (X : C) (f : F.coreprX ⟶ X) :
F.coreprW.hom.app X f = F.map f F.coreprx := by
apply CorepresentableBy.homEquiv_eq
end Corepresentable
end Functor
theorem isRepresentable_of_natIso (F : Cᵒᵖ ⥤ Type v₁) {G} (i : F ≅ G) [F.IsRepresentable] :
G.IsRepresentable :=
(F.representableBy.ofIso i).isRepresentable
theorem corepresentable_of_natIso (F : C ⥤ Type v₁) {G} (i : F ≅ G) [F.IsCorepresentable] :
G.IsCorepresentable :=
(F.corepresentableBy.ofIso i).isCorepresentable
instance : Functor.IsCorepresentable (𝟭 (Type v₁)) :=
corepresentable_of_natIso (coyoneda.obj (op PUnit)) Coyoneda.punitIso
open Opposite
variable (C)
-- We need to help typeclass inference with some awkward universe levels here.
instance prodCategoryInstance1 : Category ((Cᵒᵖ ⥤ Type v₁) × Cᵒᵖ) :=
CategoryTheory.prod'.{max u₁ v₁, v₁} (Cᵒᵖ ⥤ Type v₁) Cᵒᵖ
instance prodCategoryInstance2 : Category (Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) :=
CategoryTheory.prod'.{v₁, max u₁ v₁} Cᵒᵖ (Cᵒᵖ ⥤ Type v₁)
open Yoneda
section YonedaLemma
variable {C}
/-- We have a type-level equivalence between natural transformations from the yoneda embedding
and elements of `F.obj X`, without any universe switching.
-/
def yonedaEquiv {X : C} {F : Cᵒᵖ ⥤ Type v₁} : (yoneda.obj X ⟶ F) ≃ F.obj (op X) where
toFun η := η.app (op X) (𝟙 X)
invFun ξ := { app := fun _ f ↦ F.map f.op ξ }
left_inv := by
intro η
ext Y f
dsimp
rw [← FunctorToTypes.naturality]
simp
right_inv := by intro ξ; simp
theorem yonedaEquiv_apply {X : C} {F : Cᵒᵖ ⥤ Type v₁} (f : yoneda.obj X ⟶ F) :
yonedaEquiv f = f.app (op X) (𝟙 X) :=
rfl
@[simp]
theorem yonedaEquiv_symm_app_apply {X : C} {F : Cᵒᵖ ⥤ Type v₁} (x : F.obj (op X)) (Y : Cᵒᵖ)
(f : Y.unop ⟶ X) : (yonedaEquiv.symm x).app Y f = F.map f.op x :=
rfl
/-- See also `yonedaEquiv_naturality'` for a more general version. -/
lemma yonedaEquiv_naturality {X Y : C} {F : Cᵒᵖ ⥤ Type v₁} (f : yoneda.obj X ⟶ F)
(g : Y ⟶ X) : F.map g.op (yonedaEquiv f) = yonedaEquiv (yoneda.map g ≫ f) := by
change (f.app (op X) ≫ F.map g.op) (𝟙 X) = f.app (op Y) (𝟙 Y ≫ g)
rw [← f.naturality]
simp
/-- Variant of `yonedaEquiv_naturality` with general `g`. This is technically strictly more general
than `yonedaEquiv_naturality`, but `yonedaEquiv_naturality` is sometimes preferable because it
can avoid the "motive is not type correct" error. -/
lemma yonedaEquiv_naturality' {X Y : Cᵒᵖ} {F : Cᵒᵖ ⥤ Type v₁} (f : yoneda.obj (unop X) ⟶ F)
(g : X ⟶ Y) : F.map g (yonedaEquiv f) = yonedaEquiv (yoneda.map g.unop ≫ f) :=
yonedaEquiv_naturality _ _
lemma yonedaEquiv_comp {X : C} {F G : Cᵒᵖ ⥤ Type v₁} (α : yoneda.obj X ⟶ F) (β : F ⟶ G) :
yonedaEquiv (α ≫ β) = β.app _ (yonedaEquiv α) :=
rfl
lemma yonedaEquiv_yoneda_map {X Y : C} (f : X ⟶ Y) : yonedaEquiv (yoneda.map f) = f := by
rw [yonedaEquiv_apply]
simp
lemma yonedaEquiv_symm_naturality_left {X X' : C} (f : X' ⟶ X) (F : Cᵒᵖ ⥤ Type v₁)
(x : F.obj ⟨X⟩) : yoneda.map f ≫ yonedaEquiv.symm x = yonedaEquiv.symm ((F.map f.op) x) := by
apply yonedaEquiv.injective
simp only [yonedaEquiv_comp, yoneda_obj_obj, yonedaEquiv_symm_app_apply, Equiv.apply_symm_apply]
erw [yonedaEquiv_yoneda_map]
lemma yonedaEquiv_symm_naturality_right (X : C) {F F' : Cᵒᵖ ⥤ Type v₁} (f : F ⟶ F')
(x : F.obj ⟨X⟩) : yonedaEquiv.symm x ≫ f = yonedaEquiv.symm (f.app ⟨X⟩ x) := by
apply yonedaEquiv.injective
simp [yonedaEquiv_comp]
/-- See also `map_yonedaEquiv'` for a more general version. -/
lemma map_yonedaEquiv {X Y : C} {F : Cᵒᵖ ⥤ Type v₁} (f : yoneda.obj X ⟶ F)
(g : Y ⟶ X) : F.map g.op (yonedaEquiv f) = f.app (op Y) g := by
rw [yonedaEquiv_naturality, yonedaEquiv_comp, yonedaEquiv_yoneda_map]
/-- Variant of `map_yonedaEquiv` with general `g`. This is technically strictly more general
than `map_yonedaEquiv`, but `map_yonedaEquiv` is sometimes preferable because it
can avoid the "motive is not type correct" error. -/
lemma map_yonedaEquiv' {X Y : Cᵒᵖ} {F : Cᵒᵖ ⥤ Type v₁} (f : yoneda.obj (unop X) ⟶ F)
(g : X ⟶ Y) : F.map g (yonedaEquiv f) = f.app Y g.unop := by
rw [yonedaEquiv_naturality', yonedaEquiv_comp, yonedaEquiv_yoneda_map]
lemma yonedaEquiv_symm_map {X Y : Cᵒᵖ} (f : X ⟶ Y) {F : Cᵒᵖ ⥤ Type v₁} (t : F.obj X) :
yonedaEquiv.symm (F.map f t) = yoneda.map f.unop ≫ yonedaEquiv.symm t := by
obtain ⟨u, rfl⟩ := yonedaEquiv.surjective t
rw [yonedaEquiv_naturality', Equiv.symm_apply_apply, Equiv.symm_apply_apply]
/-- Two morphisms of presheaves of types `P ⟶ Q` coincide if the precompositions
with morphisms `yoneda.obj X ⟶ P` agree. -/
lemma hom_ext_yoneda {P Q : Cᵒᵖ ⥤ Type v₁} {f g : P ⟶ Q}
(h : ∀ (X : C) (p : yoneda.obj X ⟶ P), p ≫ f = p ≫ g) :
f = g := by
ext X x
simpa only [yonedaEquiv_comp, Equiv.apply_symm_apply]
using congr_arg (yonedaEquiv) (h _ (yonedaEquiv.symm x))
variable (C)
/-- The "Yoneda evaluation" functor, which sends `X : Cᵒᵖ` and `F : Cᵒᵖ ⥤ Type`
to `F.obj X`, functorially in both `X` and `F`.
-/
def yonedaEvaluation : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁) ⥤ Type max u₁ v₁ :=
evaluationUncurried Cᵒᵖ (Type v₁) ⋙ uliftFunctor
@[simp]
theorem yonedaEvaluation_map_down (P Q : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) (α : P ⟶ Q)
(x : (yonedaEvaluation C).obj P) :
((yonedaEvaluation C).map α x).down = α.2.app Q.1 (P.2.map α.1 x.down) :=
rfl
/-- The "Yoneda pairing" functor, which sends `X : Cᵒᵖ` and `F : Cᵒᵖ ⥤ Type`
to `yoneda.op.obj X ⟶ F`, functorially in both `X` and `F`.
-/
def yonedaPairing : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁) ⥤ Type max u₁ v₁ :=
Functor.prod yoneda.op (𝟭 (Cᵒᵖ ⥤ Type v₁)) ⋙ Functor.hom (Cᵒᵖ ⥤ Type v₁)
@[ext]
lemma yonedaPairingExt {X : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)} {x y : (yonedaPairing C).obj X}
(w : ∀ Y, x.app Y = y.app Y) : x = y :=
NatTrans.ext (funext w)
@[simp]
theorem yonedaPairing_map (P Q : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) (α : P ⟶ Q) (β : (yonedaPairing C).obj P) :
(yonedaPairing C).map α β = yoneda.map α.1.unop ≫ β ≫ α.2 :=
rfl
/-- The Yoneda lemma asserts that the Yoneda pairing
`(X : Cᵒᵖ, F : Cᵒᵖ ⥤ Type) ↦ (yoneda.obj (unop X) ⟶ F)`
is naturally isomorphic to the evaluation `(X, F) ↦ F.obj X`. -/
@[stacks 001P]
def yonedaLemma : yonedaPairing C ≅ yonedaEvaluation C :=
NatIso.ofComponents
(fun _ ↦ Equiv.toIso (yonedaEquiv.trans Equiv.ulift.symm))
(by intro (X, F) (Y, G) f
ext (a : yoneda.obj X.unop ⟶ F)
apply ULift.ext
dsimp [yonedaEvaluation, yonedaEquiv]
simp [← FunctorToTypes.naturality])
variable {C}
/- Porting note: this used to be two calls to `tidy` -/
/-- The curried version of yoneda lemma when `C` is small. -/
def curriedYonedaLemma {C : Type u₁} [SmallCategory C] :
(yoneda.op ⋙ coyoneda : Cᵒᵖ ⥤ (Cᵒᵖ ⥤ Type u₁) ⥤ Type u₁) ≅ evaluation Cᵒᵖ (Type u₁) :=
NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun _ ↦ Equiv.toIso yonedaEquiv)) (by
intro X Y f
ext a b
simp [yonedaEquiv, ← FunctorToTypes.naturality])
/-- The curried version of the Yoneda lemma. -/
def largeCurriedYonedaLemma {C : Type u₁} [Category.{v₁} C] :
yoneda.op ⋙ coyoneda ≅
evaluation Cᵒᵖ (Type v₁) ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} :=
NatIso.ofComponents
(fun X => NatIso.ofComponents
(fun _ => Equiv.toIso <| yonedaEquiv.trans Equiv.ulift.symm)
(by
intro Y Z f
ext g
rw [← ULift.down_inj]
simpa using yonedaEquiv_comp _ _))
(by
intro Y Z f
ext F g
rw [← ULift.down_inj]
simpa using (yonedaEquiv_naturality _ _).symm)
/-- Version of the Yoneda lemma where the presheaf is fixed but the argument varies. -/
def yonedaOpCompYonedaObj {C : Type u₁} [Category.{v₁} C] (P : Cᵒᵖ ⥤ Type v₁) :
yoneda.op ⋙ yoneda.obj P ≅ P ⋙ uliftFunctor.{u₁} :=
isoWhiskerRight largeCurriedYonedaLemma ((evaluation _ _).obj P)
/-- The curried version of yoneda lemma when `C` is small. -/
def curriedYonedaLemma' {C : Type u₁} [SmallCategory C] :
yoneda ⋙ (whiskeringLeft Cᵒᵖ (Cᵒᵖ ⥤ Type u₁)ᵒᵖ (Type u₁)).obj yoneda.op
≅ 𝟭 (Cᵒᵖ ⥤ Type u₁) :=
NatIso.ofComponents (fun F ↦ NatIso.ofComponents (fun _ ↦ Equiv.toIso yonedaEquiv) (by
intro X Y f
ext a
dsimp [yonedaEquiv]
simp [← FunctorToTypes.naturality]))
lemma isIso_of_yoneda_map_bijective {X Y : C} (f : X ⟶ Y)
(hf : ∀ (T : C), Function.Bijective (fun (x : T ⟶ X) => x ≫ f)) :
IsIso f := by
obtain ⟨g, hg : g ≫ f = 𝟙 Y⟩ := (hf Y).2 (𝟙 Y)
exact ⟨g, (hf _).1 (by cat_disch), hg⟩
lemma isIso_iff_yoneda_map_bijective {X Y : C} (f : X ⟶ Y) :
IsIso f ↔ (∀ (T : C), Function.Bijective (fun (x : T ⟶ X) => x ≫ f)) := by
refine ⟨fun _ ↦ ?_, fun hf ↦ isIso_of_yoneda_map_bijective f hf⟩
intro T
rw [← isIso_iff_bijective]
exact inferInstanceAs (IsIso ((yoneda.map f).app _))
lemma isIso_iff_isIso_yoneda_map {X Y : C} (f : X ⟶ Y) :
IsIso f ↔ ∀ c : C, IsIso ((yoneda.map f).app ⟨c⟩) := by
rw [isIso_iff_yoneda_map_bijective]
exact forall_congr' fun _ ↦ (isIso_iff_bijective _).symm
/-- Yoneda's lemma as a bijection `(uliftYoneda.{w}.obj X ⟶ F) ≃ F.obj (op X)`
for any presheaf of type `F : Cᵒᵖ ⥤ Type (max w v₁)` for some
auxiliary universe `w`. -/
@[simps! -isSimp]
def uliftYonedaEquiv {X : C} {F : Cᵒᵖ ⥤ Type (max w v₁)} :
(uliftYoneda.{w}.obj X ⟶ F) ≃ F.obj (op X) where
toFun τ := τ.app (op X) (ULift.up (𝟙 _))
invFun x := { app Y y := F.map y.down.op x }
left_inv τ := by
ext ⟨Y⟩ ⟨y⟩
simp [uliftYoneda, ← FunctorToTypes.naturality]
right_inv x := by simp
@[deprecated (since := "2025-08-04")] alias yonedaCompUliftFunctorEquiv :=
uliftYonedaEquiv
attribute [simp] uliftYonedaEquiv_symm_apply_app
lemma uliftYonedaEquiv_naturality {X Y : Cᵒᵖ} {F : Cᵒᵖ ⥤ Type max w v₁}
(f : uliftYoneda.{w}.obj (unop X) ⟶ F) (g : X ⟶ Y) :
F.map g (uliftYonedaEquiv.{w} f) = uliftYonedaEquiv.{w} (uliftYoneda.map g.unop ≫ f) := by
simp [uliftYonedaEquiv, uliftYoneda,
← FunctorToTypes.naturality _ _ f g (ULift.up (𝟙 _))]
lemma uliftYonedaEquiv_comp {X : C} {F G : Cᵒᵖ ⥤ Type max w v₁}
(α : uliftYoneda.{w}.obj X ⟶ F) (β : F ⟶ G) :
uliftYonedaEquiv.{w} (α ≫ β) = β.app _ (uliftYonedaEquiv α) :=
rfl
@[reassoc]
lemma uliftYonedaEquiv_symm_map {X Y : Cᵒᵖ} (f : X ⟶ Y) {F : Cᵒᵖ ⥤ Type max w v₁}
(t : F.obj X) :
uliftYonedaEquiv.{w}.symm (F.map f t) =
uliftYoneda.map f.unop ≫ uliftYonedaEquiv.symm t := by
obtain ⟨u, rfl⟩ := uliftYonedaEquiv.surjective t
rw [uliftYonedaEquiv_naturality]
simp
@[simp]
lemma uliftYonedaEquiv_uliftYoneda_map {X Y : C} (f : X ⟶ Y) :
DFunLike.coe (β := fun _ ↦ ULift.{w} (X ⟶ Y))
uliftYonedaEquiv.{w} (uliftYoneda.map f) = ULift.up f := by
simp [uliftYonedaEquiv, uliftYoneda]
/-- Two morphisms of presheaves of types `P ⟶ Q` coincide if the precompositions
with morphisms `uliftYoneda.obj X ⟶ P` agree. -/
lemma hom_ext_uliftYoneda {P Q : Cᵒᵖ ⥤ Type max w v₁} {f g : P ⟶ Q}
(h : ∀ (X : C) (p : uliftYoneda.{w}.obj X ⟶ P), p ≫ f = p ≫ g) :
f = g := by
ext X x
simpa [uliftYonedaEquiv] using congr_arg uliftYonedaEquiv.{w} (h _ (uliftYonedaEquiv.symm x))
/-- A variant of the curried version of the Yoneda lemma with a raise in the universe level. -/
def uliftYonedaOpCompCoyoneda {C : Type u₁} [Category.{v₁} C] :
uliftYoneda.{w}.op ⋙ coyoneda ≅
evaluation Cᵒᵖ (Type max v₁ w) ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} :=
NatIso.ofComponents
(fun X => NatIso.ofComponents
(fun _ => Equiv.toIso <| uliftYonedaEquiv.trans Equiv.ulift.symm)
(by
intros Y Z f
ext g
rw [← ULift.down_inj]
simpa using uliftYonedaEquiv_comp _ _))
(by
intros Y Z f
ext F g
rw [← ULift.down_inj]
simpa using (uliftYonedaEquiv_naturality _ _).symm)
end YonedaLemma
section CoyonedaLemma
variable {C}
/-- We have a type-level equivalence between natural transformations from the coyoneda embedding
and elements of `F.obj X.unop`, without any universe switching.
-/
def coyonedaEquiv {X : C} {F : C ⥤ Type v₁} : (coyoneda.obj (op X) ⟶ F) ≃ F.obj X where
toFun η := η.app X (𝟙 X)
invFun ξ := { app := fun _ x ↦ F.map x ξ }
left_inv := fun η ↦ by
ext Y (x : X ⟶ Y)
dsimp
rw [← FunctorToTypes.naturality]
simp
right_inv := by intro ξ; simp
theorem coyonedaEquiv_apply {X : C} {F : C ⥤ Type v₁} (f : coyoneda.obj (op X) ⟶ F) :
coyonedaEquiv f = f.app X (𝟙 X) :=
rfl
@[simp]
theorem coyonedaEquiv_symm_app_apply {X : C} {F : C ⥤ Type v₁} (x : F.obj X) (Y : C)
(f : X ⟶ Y) : (coyonedaEquiv.symm x).app Y f = F.map f x :=
rfl
lemma coyonedaEquiv_naturality {X Y : C} {F : C ⥤ Type v₁} (f : coyoneda.obj (op X) ⟶ F)
(g : X ⟶ Y) : F.map g (coyonedaEquiv f) = coyonedaEquiv (coyoneda.map g.op ≫ f) := by
change (f.app X ≫ F.map g) (𝟙 X) = f.app Y (g ≫ 𝟙 Y)
rw [← f.naturality]
simp
lemma coyonedaEquiv_comp {X : C} {F G : C ⥤ Type v₁} (α : coyoneda.obj (op X) ⟶ F) (β : F ⟶ G) :
coyonedaEquiv (α ≫ β) = β.app _ (coyonedaEquiv α) := by
rfl
lemma coyonedaEquiv_coyoneda_map {X Y : C} (f : X ⟶ Y) :
coyonedaEquiv (coyoneda.map f.op) = f := by
rw [coyonedaEquiv_apply]
simp
lemma map_coyonedaEquiv {X Y : C} {F : C ⥤ Type v₁} (f : coyoneda.obj (op X) ⟶ F)
(g : X ⟶ Y) : F.map g (coyonedaEquiv f) = f.app Y g := by
rw [coyonedaEquiv_naturality, coyonedaEquiv_comp, coyonedaEquiv_coyoneda_map]
lemma coyonedaEquiv_symm_map {X Y : C} (f : X ⟶ Y) {F : C ⥤ Type v₁} (t : F.obj X) :
coyonedaEquiv.symm (F.map f t) = coyoneda.map f.op ≫ coyonedaEquiv.symm t := by
obtain ⟨u, rfl⟩ := coyonedaEquiv.surjective t
simp [coyonedaEquiv_naturality u f]
variable (C)
/-- The "Coyoneda evaluation" functor, which sends `X : C` and `F : C ⥤ Type`
to `F.obj X`, functorially in both `X` and `F`.
-/
def coyonedaEvaluation : C × (C ⥤ Type v₁) ⥤ Type max u₁ v₁ :=
evaluationUncurried C (Type v₁) ⋙ uliftFunctor
@[simp]
theorem coyonedaEvaluation_map_down (P Q : C × (C ⥤ Type v₁)) (α : P ⟶ Q)
(x : (coyonedaEvaluation C).obj P) :
((coyonedaEvaluation C).map α x).down = α.2.app Q.1 (P.2.map α.1 x.down) :=
rfl
/-- The "Coyoneda pairing" functor, which sends `X : C` and `F : C ⥤ Type`
to `coyoneda.rightOp.obj X ⟶ F`, functorially in both `X` and `F`.
-/
def coyonedaPairing : C × (C ⥤ Type v₁) ⥤ Type max u₁ v₁ :=
Functor.prod coyoneda.rightOp (𝟭 (C ⥤ Type v₁)) ⋙ Functor.hom (C ⥤ Type v₁)
@[ext]
lemma coyonedaPairingExt {X : C × (C ⥤ Type v₁)} {x y : (coyonedaPairing C).obj X}
(w : ∀ Y, x.app Y = y.app Y) : x = y :=
NatTrans.ext (funext w)
@[simp]
theorem coyonedaPairing_map (P Q : C × (C ⥤ Type v₁)) (α : P ⟶ Q) (β : (coyonedaPairing C).obj P) :
(coyonedaPairing C).map α β = coyoneda.map α.1.op ≫ β ≫ α.2 :=
rfl
/-- The Coyoneda lemma asserts that the Coyoneda pairing
`(X : C, F : C ⥤ Type) ↦ (coyoneda.obj X ⟶ F)`
is naturally isomorphic to the evaluation `(X, F) ↦ F.obj X`. -/
@[stacks 001P]
def coyonedaLemma : coyonedaPairing C ≅ coyonedaEvaluation C :=
NatIso.ofComponents
(fun _ ↦ Equiv.toIso (coyonedaEquiv.trans Equiv.ulift.symm))
(by intro (X, F) (Y, G) f
ext (a : coyoneda.obj (op X) ⟶ F)
apply ULift.ext
dsimp [coyonedaEquiv, coyonedaEvaluation]
simp [← FunctorToTypes.naturality])
variable {C}
/- Porting note: this used to be two calls to `tidy` -/
/-- The curried version of coyoneda lemma when `C` is small. -/
def curriedCoyonedaLemma {C : Type u₁} [SmallCategory C] :
coyoneda.rightOp ⋙ coyoneda ≅ evaluation C (Type u₁) :=
NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun _ ↦ Equiv.toIso coyonedaEquiv)) (by
intro X Y f
ext a b
simp [coyonedaEquiv, ← FunctorToTypes.naturality])
/-- The curried version of the Coyoneda lemma. -/
def largeCurriedCoyonedaLemma {C : Type u₁} [Category.{v₁} C] :
coyoneda.rightOp ⋙ coyoneda ≅
evaluation C (Type v₁) ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} :=
NatIso.ofComponents
(fun X => NatIso.ofComponents
(fun _ => Equiv.toIso <| coyonedaEquiv.trans Equiv.ulift.symm)
(by
intro Y Z f
ext g
rw [← ULift.down_inj]
simpa using coyonedaEquiv_comp _ _))
(by
intro Y Z f
ext F g
rw [← ULift.down_inj]
simpa using (coyonedaEquiv_naturality _ _).symm)
/-- Version of the Coyoneda lemma where the presheaf is fixed but the argument varies. -/
def coyonedaCompYonedaObj {C : Type u₁} [Category.{v₁} C] (P : C ⥤ Type v₁) :
coyoneda.rightOp ⋙ yoneda.obj P ≅ P ⋙ uliftFunctor.{u₁} :=
isoWhiskerRight largeCurriedCoyonedaLemma ((evaluation _ _).obj P)
/-- The curried version of coyoneda lemma when `C` is small. -/
def curriedCoyonedaLemma' {C : Type u₁} [SmallCategory C] :
yoneda ⋙ (whiskeringLeft C (C ⥤ Type u₁)ᵒᵖ (Type u₁)).obj coyoneda.rightOp
≅ 𝟭 (C ⥤ Type u₁) :=
NatIso.ofComponents (fun F ↦ NatIso.ofComponents (fun _ ↦ Equiv.toIso coyonedaEquiv) (by
intro X Y f
ext a
simp [coyonedaEquiv, ← FunctorToTypes.naturality]))
lemma isIso_of_coyoneda_map_bijective {X Y : C} (f : X ⟶ Y)
(hf : ∀ (T : C), Function.Bijective (fun (x : Y ⟶ T) => f ≫ x)) :
IsIso f := by
obtain ⟨g, hg : f ≫ g = 𝟙 X⟩ := (hf X).2 (𝟙 X)
refine ⟨g, hg, (hf _).1 ?_⟩
simp only [Category.comp_id, ← Category.assoc, hg, Category.id_comp]
lemma isIso_iff_coyoneda_map_bijective {X Y : C} (f : X ⟶ Y) :
IsIso f ↔ (∀ (T : C), Function.Bijective (fun (x : Y ⟶ T) => f ≫ x)) := by
refine ⟨fun _ ↦ ?_, fun hf ↦ isIso_of_coyoneda_map_bijective f hf⟩
intro T
rw [← isIso_iff_bijective]
exact inferInstanceAs (IsIso ((coyoneda.map f.op).app _))
lemma isIso_iff_isIso_coyoneda_map {X Y : C} (f : X ⟶ Y) :
IsIso f ↔ ∀ c : C, IsIso ((coyoneda.map f.op).app c) := by
rw [isIso_iff_coyoneda_map_bijective]
exact forall_congr' fun _ ↦ (isIso_iff_bijective _).symm
/-- Coyoneda's lemma as a bijection `(uliftCoyoneda.{w}.obj X ⟶ F) ≃ F.obj (op X)`
for any presheaf of type `F : Cᵒᵖ ⥤ Type (max w v₁)` for some
auxiliary universe `w`. -/
@[simps! -isSimp]
def uliftCoyonedaEquiv {X : Cᵒᵖ} {F : C ⥤ Type (max w v₁)} :
(uliftCoyoneda.{w}.obj X ⟶ F) ≃ F.obj X.unop where
toFun τ := τ.app X.unop (ULift.up (𝟙 _))
invFun x := { app Y y := F.map y.down x }
left_inv τ := by
ext Y ⟨y⟩
simp [uliftYoneda, ← FunctorToTypes.naturality]
right_inv x := by simp
@[deprecated (since := "2025-08-04")] alias coyonedaCompUliftFunctorEquiv :=
uliftCoyonedaEquiv
attribute [simp] uliftCoyonedaEquiv_symm_apply_app
lemma uliftCoyonedaEquiv_naturality {X Y : C} {F : C ⥤ Type max w v₁}
(f : uliftCoyoneda.{w}.obj (op X) ⟶ F) (g : X ⟶ Y) :
F.map g (uliftCoyonedaEquiv.{w} f) = uliftCoyonedaEquiv.{w} (uliftCoyoneda.map g.op ≫ f) := by
simp [uliftCoyonedaEquiv, uliftYoneda,
← FunctorToTypes.naturality _ _ f g (ULift.up (𝟙 _))]
lemma uliftCoyonedaEquiv_comp {X : Cᵒᵖ} {F G : C ⥤ Type max w v₁}
(α : uliftCoyoneda.{w}.obj X ⟶ F) (β : F ⟶ G) :
uliftCoyonedaEquiv.{w} (α ≫ β) = β.app _ (uliftCoyonedaEquiv α) :=
rfl
@[reassoc]
lemma uliftCoyonedaEquiv_symm_map {X Y : C} (f : X ⟶ Y) {F : C ⥤ Type max w v₁}
(t : F.obj X) :
uliftCoyonedaEquiv.{w}.symm (F.map f t) =
uliftCoyoneda.map f.op ≫ uliftCoyonedaEquiv.symm t := by
obtain ⟨u, rfl⟩ := uliftCoyonedaEquiv.surjective t
rw [uliftCoyonedaEquiv_naturality]
simp
@[simp]
lemma uliftCoyonedaEquiv_uliftCoyoneda_map {X Y : Cᵒᵖ} (f : X ⟶ Y) :
DFunLike.coe (β := fun _ ↦ ULift.{w} (Y.unop ⟶ X.unop))
uliftCoyonedaEquiv.{w} (uliftCoyoneda.map f) = ULift.up f.unop := by
simp [uliftCoyonedaEquiv, uliftYoneda]
/-- Two morphisms of presheaves of types `P ⟶ Q` coincide if the precompositions
with morphisms `uliftCoyoneda.obj X ⟶ P` agree. -/
lemma hom_ext_uliftCoyoneda {P Q : C ⥤ Type max w v₁} {f g : P ⟶ Q}
(h : ∀ (X : Cᵒᵖ) (p : uliftCoyoneda.{w}.obj X ⟶ P), p ≫ f = p ≫ g) :
f = g := by
ext X x
simpa [uliftCoyonedaEquiv]
using congr_arg uliftCoyonedaEquiv.{w} (h _ (uliftCoyonedaEquiv.symm x))
/-- A variant of the curried version of the Coyoneda lemma with a raise in the universe level. -/
def uliftCoyonedaRightOpCompCoyoneda {C : Type u₁} [Category.{v₁} C] :
uliftCoyoneda.{w}.rightOp ⋙ coyoneda ≅
evaluation C (Type max v₁ w) ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} :=
NatIso.ofComponents
(fun X => NatIso.ofComponents
(fun _ => Equiv.toIso <| uliftCoyonedaEquiv.trans Equiv.ulift.symm)
(by
intros Y Z f
ext g
rw [← ULift.down_inj]
simpa using uliftCoyonedaEquiv_comp _ _))
(by
intros Y Z f
ext F g
rw [← ULift.down_inj]
simpa using (uliftCoyonedaEquiv_naturality _ _).symm)
end CoyonedaLemma
section
variable {C}
variable {D : Type*} [Category.{v₁} D] (F : C ⥤ D)
/-- The natural transformation `yoneda.obj X ⟶ F.op ⋙ yoneda.obj (F.obj X)`
when `F : C ⥤ D` and `X : C`. -/
def yonedaMap (X : C) : yoneda.obj X ⟶ F.op ⋙ yoneda.obj (F.obj X) where
app _ f := F.map f
@[simp]
lemma yonedaMap_app_apply {Y : C} {X : Cᵒᵖ} (f : X.unop ⟶ Y) :
(yonedaMap F Y).app X f = F.map f := rfl
end
section
variable {C}
variable {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D)
/-- The natural transformation `uliftYoneda.obj X ⟶ F.op ⋙ uliftYoneda.obj (F.obj X)`
when `F : C ⥤ D` and `X : C`. -/
def uliftYonedaMap (X : C) :
uliftYoneda.{max w v₂}.obj X ⟶ F.op ⋙ uliftYoneda.{max w v₁}.obj (F.obj X) where
app _ f := ULift.up (F.map (ULift.down f))
@[simp]
lemma uliftYonedaMap_app_apply {Y : C} {X : Cᵒᵖ} (f : X.unop ⟶ Y) :
(uliftYonedaMap.{w} F Y).app X (ULift.up f) = ULift.up (F.map f) := rfl
end
section
variable {C : Type u₁} [Category.{v₁} C]
/-- A type-level equivalence between sections of a functor and morphisms from a terminal functor
to it. We use the constant functor on a given singleton type here as a specific choice of terminal
functor. -/
@[simps apply_app]
def Functor.sectionsEquivHom (F : C ⥤ Type u₂) (X : Type u₂) [Unique X] :
F.sections ≃ ((const _).obj X ⟶ F) where
toFun s :=
{ app j x := s.1 j
naturality _ _ _ := by ext x; simp }
invFun τ := ⟨fun j ↦ τ.app _ (default : X), fun φ ↦ (congr_fun (τ.naturality φ) _).symm⟩
right_inv τ := by
ext _ (x : X)
rw [Unique.eq_default x]
lemma Functor.sectionsEquivHom_naturality {F G : C ⥤ Type u₂} (f : F ⟶ G) (X : Type u₂) [Unique X]
(x : F.sections) :
(G.sectionsEquivHom X) ((sectionsFunctor C).map f x) = (F.sectionsEquivHom X) x ≫ f := by
rfl
lemma Functor.sectionsEquivHom_naturality_symm {F G : C ⥤ Type u₂} (f : F ⟶ G) (X : Type u₂)
[Unique X] (τ : (const C).obj X ⟶ F) :
(G.sectionsEquivHom X).symm (τ ≫ f) =
(sectionsFunctor C).map f ((F.sectionsEquivHom X).symm τ) := by
rfl
/-- A natural isomorphism between the sections functor `(C ⥤ Type _) ⥤ Type _` and the co-Yoneda
embedding of a terminal functor, specifically a constant functor on a given singleton type `X`. -/
@[simps!]
noncomputable def sectionsFunctorNatIsoCoyoneda (X : Type max u₁ u₂) [Unique X] :
Functor.sectionsFunctor.{v₁, max u₁ u₂} C ≅ coyoneda.obj (op ((Functor.const C).obj X)) :=
NatIso.ofComponents fun F ↦ (F.sectionsEquivHom X).toIso
end
namespace Functor.FullyFaithful
variable {C : Type u₁} [Category.{v₁} C]
/-- `FullyFaithful.homEquiv` as a natural isomorphism. -/
@[simps!]
def homNatIso {D : Type u₂} [Category.{v₂} D] {F : C ⥤ D} (hF : F.FullyFaithful) (X : C) :
F.op ⋙ uliftYoneda.obj.{v₁} (F.obj X) ≅ uliftYoneda.obj.{v₂} X :=
NatIso.ofComponents
(fun Y => Equiv.toIso (Equiv.ulift.trans <| hF.homEquiv.symm.trans Equiv.ulift.symm))
(fun f => by ext; exact Equiv.ulift.injective (hF.map_injective (by simp)))
/-- `FullyFaithful.homEquiv` as a natural isomorphism. -/
@[simps!, deprecated homNatIso (since := "2025-10-28")]
def homNatIsoMaxRight {D : Type u₂} [Category.{max v₁ v₂} D] {F : C ⥤ D} (hF : F.FullyFaithful)
(X : C) : F.op ⋙ yoneda.obj (F.obj X) ≅ uliftYoneda.obj.{v₂} X :=
isoWhiskerLeft F.op (uliftYonedaIsoYoneda.symm.app _) ≪≫ hF.homNatIso _ ≪≫
NatIso.ofComponents (fun _ => Equiv.toIso (Equiv.ulift.trans Equiv.ulift.symm))
/-- `FullyFaithful.homEquiv` as a natural isomorphism. -/
@[simps!]
def compUliftYonedaCompWhiskeringLeft {D : Type u₂} [Category.{v₂} D] {F : C ⥤ D}
(hF : F.FullyFaithful) :
F ⋙ uliftYoneda.{v₁} ⋙ (whiskeringLeft _ _ _).obj F.op ≅ uliftYoneda.{v₂} :=
NatIso.ofComponents (fun X => hF.homNatIso _)
(fun f => by ext; exact Equiv.ulift.injective (hF.map_injective (by simp)))
@[deprecated (since := "2025-10-20")] alias compYonedaCompWhiskeringLeft :=
compUliftYonedaCompWhiskeringLeft
/-- `FullyFaithful.homEquiv` as a natural isomorphism. -/
@[simps!, deprecated compUliftYonedaCompWhiskeringLeft (since := "2025-10-28")]
def compYonedaCompWhiskeringLeftMaxRight {D : Type u₂} [Category.{max v₁ v₂} D] {F : C ⥤ D}
(hF : F.FullyFaithful) : F ⋙ yoneda ⋙ (whiskeringLeft _ _ _).obj F.op ≅ uliftYoneda.{v₂} := by
refine isoWhiskerLeft F (isoWhiskerRight uliftYonedaIsoYoneda.symm.{v₁} _) ≪≫
hF.compUliftYonedaCompWhiskeringLeft ≪≫
NatIso.ofComponents (fun _ => NatIso.ofComponents
(fun _ => Equiv.toIso (Equiv.ulift.trans Equiv.ulift.symm)))
/-- `FullyFaithful.homEquiv` as a natural isomorphism, using coyoneda. -/
@[simps!]
def homNatIso' {D : Type u₂} [Category.{v₂} D] {F : C ⥤ D} (hF : F.FullyFaithful) (X : C) :
F ⋙ uliftCoyoneda.obj.{v₁} (op (F.obj X)) ≅ uliftCoyoneda.obj.{v₂} (op X) :=
NatIso.ofComponents
(fun Y => Equiv.toIso (Equiv.ulift.trans <| hF.homEquiv.symm.trans Equiv.ulift.symm))
(fun f => by ext; exact Equiv.ulift.injective (hF.map_injective (by simp)))
/-- `FullyFaithful.homEquiv` as a natural isomorphism, using coyoneda. -/
@[simps!]
def compUliftCoyonedaCompWhiskeringLeft {D : Type u₂} [Category.{v₂} D] {F : C ⥤ D}
(hF : F.FullyFaithful) :
F.op ⋙ uliftCoyoneda.{v₁} ⋙ (whiskeringLeft _ _ _).obj F ≅ uliftCoyoneda.{v₂} :=
NatIso.ofComponents (fun X => hF.homNatIso' _)
(fun f => by ext; exact Equiv.ulift.injective (hF.map_injective (by simp)))
end Functor.FullyFaithful
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/CatCommSq.lean | import Mathlib.CategoryTheory.Equivalence
/-!
# 2-commutative squares of functors
Similarly as `CommSq.lean` defines the notion of commutative squares,
this file introduces the notion of 2-commutative squares of functors.
If `T : C₁ ⥤ C₂`, `L : C₁ ⥤ C₃`, `R : C₂ ⥤ C₄`, `B : C₃ ⥤ C₄` are functors,
then `[CatCommSq T L R B]` contains the datum of an isomorphism `T ⋙ R ≅ L ⋙ B`.
Future work: using this notion in the development of the localization of categories
(e.g. localization of adjunctions).
-/
namespace CategoryTheory
open Category Functor
variable {C₁ C₂ C₃ C₄ C₅ C₆ : Type*} [Category C₁] [Category C₂] [Category C₃] [Category C₄]
[Category C₅] [Category C₆]
/-- `CatCommSq T L R B` expresses that there is a 2-commutative square of functors, where
the functors `T`, `L`, `R` and `B` are respectively the left, top, right and bottom functors
of the square. -/
@[ext]
class CatCommSq (T : C₁ ⥤ C₂) (L : C₁ ⥤ C₃) (R : C₂ ⥤ C₄) (B : C₃ ⥤ C₄) where
/-- Assuming `[CatCommSq T L R B]`, `iso T L R B` is the isomorphism `T ⋙ R ≅ L ⋙ B`
given by the 2-commutative square. -/
iso (T) (L) (R) (B) : T ⋙ R ≅ L ⋙ B
variable (T : C₁ ⥤ C₂) (L : C₁ ⥤ C₃) (R : C₂ ⥤ C₄) (B : C₃ ⥤ C₄)
namespace CatCommSq
/-- The vertical identity `CatCommSq` -/
@[simps!]
def vId : CatCommSq T (𝟭 C₁) (𝟭 C₂) T where
iso := (Functor.leftUnitor _) ≪≫ (Functor.rightUnitor _).symm
/-- The horizontal identity `CatCommSq` -/
@[simps!]
def hId : CatCommSq (𝟭 C₁) L L (𝟭 C₃) where
iso := (Functor.rightUnitor _) ≪≫ (Functor.leftUnitor _).symm
@[reassoc (attr := simp)]
lemma iso_hom_naturality [h : CatCommSq T L R B] {x y : C₁} (f : x ⟶ y) :
R.map (T.map f) ≫ (iso T L R B).hom.app y = (iso T L R B).hom.app x ≫ B.map (L.map f) :=
(iso T L R B).hom.naturality f
@[reassoc (attr := simp)]
lemma iso_inv_naturality [h : CatCommSq T L R B] {x y : C₁} (f : x ⟶ y) :
B.map (L.map f) ≫ (iso T L R B).inv.app y = (iso T L R B).inv.app x ≫ R.map (T.map f) :=
(iso T L R B).inv.naturality f
/-- Horizontal composition of 2-commutative squares -/
@[simps!]
def hComp (T₁ : C₁ ⥤ C₂) (T₂ : C₂ ⥤ C₃) (V₁ : C₁ ⥤ C₄) (V₂ : C₂ ⥤ C₅) (V₃ : C₃ ⥤ C₆)
(B₁ : C₄ ⥤ C₅) (B₂ : C₅ ⥤ C₆) [CatCommSq T₁ V₁ V₂ B₁] [CatCommSq T₂ V₂ V₃ B₂] :
CatCommSq (T₁ ⋙ T₂) V₁ V₃ (B₁ ⋙ B₂) where
iso := associator _ _ _ ≪≫ isoWhiskerLeft T₁ (iso T₂ V₂ V₃ B₂) ≪≫
(associator _ _ _).symm ≪≫ isoWhiskerRight (iso T₁ V₁ V₂ B₁) B₂ ≪≫
associator _ _ _
/-- A variant of `hComp` where both squares can be explicitly provided. -/
abbrev hComp' {T₁ : C₁ ⥤ C₂} {T₂ : C₂ ⥤ C₃} {V₁ : C₁ ⥤ C₄} {V₂ : C₂ ⥤ C₅} {V₃ : C₃ ⥤ C₆}
{B₁ : C₄ ⥤ C₅} {B₂ : C₅ ⥤ C₆} (S₁ : CatCommSq T₁ V₁ V₂ B₁) (S₂ : CatCommSq T₂ V₂ V₃ B₂) :
CatCommSq (T₁ ⋙ T₂) V₁ V₃ (B₁ ⋙ B₂) :=
letI := S₁
letI := S₂
hComp _ _ _ V₂ _ _ _
/-- Vertical composition of 2-commutative squares -/
@[simps!]
def vComp (L₁ : C₁ ⥤ C₂) (L₂ : C₂ ⥤ C₃) (H₁ : C₁ ⥤ C₄) (H₂ : C₂ ⥤ C₅) (H₃ : C₃ ⥤ C₆)
(R₁ : C₄ ⥤ C₅) (R₂ : C₅ ⥤ C₆) [CatCommSq H₁ L₁ R₁ H₂] [CatCommSq H₂ L₂ R₂ H₃] :
CatCommSq H₁ (L₁ ⋙ L₂) (R₁ ⋙ R₂) H₃ where
iso := (associator _ _ _).symm ≪≫ isoWhiskerRight (iso H₁ L₁ R₁ H₂) R₂ ≪≫
associator _ _ _ ≪≫ isoWhiskerLeft L₁ (iso H₂ L₂ R₂ H₃) ≪≫
(associator _ _ _).symm
/-- A variant of `vComp` where both squares can be explicitly provided. -/
abbrev vComp' {L₁ : C₁ ⥤ C₂} {L₂ : C₂ ⥤ C₃} {H₁ : C₁ ⥤ C₄} {H₂ : C₂ ⥤ C₅} {H₃ : C₃ ⥤ C₆}
{R₁ : C₄ ⥤ C₅} {R₂ : C₅ ⥤ C₆} (S₁ : CatCommSq H₁ L₁ R₁ H₂) (S₂ : CatCommSq H₂ L₂ R₂ H₃) :
CatCommSq H₁ (L₁ ⋙ L₂) (R₁ ⋙ R₂) H₃ :=
letI := S₁
letI := S₂
vComp _ _ _ H₂ _ _ _
section
variable (T : C₁ ≌ C₂) (L : C₁ ⥤ C₃) (R : C₂ ⥤ C₄) (B : C₃ ≌ C₄)
/-- Horizontal inverse of a 2-commutative square -/
@[simps!]
def hInv (_ : CatCommSq T.functor L R B.functor) : CatCommSq T.inverse R L B.inverse where
iso := isoWhiskerLeft _ (L.rightUnitor.symm ≪≫ isoWhiskerLeft L B.unitIso ≪≫
(associator _ _ _).symm ≪≫
isoWhiskerRight (iso T.functor L R B.functor).symm B.inverse ≪≫
associator _ _ _ ) ≪≫ (associator _ _ _).symm ≪≫
isoWhiskerRight T.counitIso _ ≪≫ leftUnitor _
lemma hInv_hInv (h : CatCommSq T.functor L R B.functor) :
hInv T.symm R L B.symm (hInv T L R B h) = h := by
ext X
rw [← cancel_mono (B.functor.map (L.map (T.unitIso.hom.app X)))]
rw [← Functor.comp_map]
erw [← h.iso.hom.naturality (T.unitIso.hom.app X)]
rw [hInv_iso_hom_app]
simp only [Equivalence.symm_functor]
rw [hInv_iso_inv_app]
dsimp
simp only [Functor.comp_obj, assoc, ← Functor.map_comp, Iso.inv_hom_id_app,
Equivalence.counitInv_app_functor, Functor.map_id]
simp only [Functor.map_comp, Equivalence.fun_inv_map, assoc,
Equivalence.counitInv_functor_comp, comp_id, Iso.inv_hom_id_app_assoc]
/-- In a square of categories, when the top and bottom functors are part
of equivalence of categories, it is equivalent to show 2-commutativity for
the functors of these equivalences or for their inverses. -/
def hInvEquiv : CatCommSq T.functor L R B.functor ≃ CatCommSq T.inverse R L B.inverse where
toFun := hInv T L R B
invFun := hInv T.symm R L B.symm
left_inv := hInv_hInv T L R B
right_inv := hInv_hInv T.symm R L B.symm
end
section
variable (T : C₁ ⥤ C₂) (L : C₁ ≌ C₃) (R : C₂ ≌ C₄) (B : C₃ ⥤ C₄)
/-- Vertical inverse of a 2-commutative square -/
@[simps!]
def vInv (_ : CatCommSq T L.functor R.functor B) : CatCommSq B L.inverse R.inverse T where
iso := isoWhiskerRight (B.leftUnitor.symm ≪≫ isoWhiskerRight L.counitIso.symm B ≪≫
associator _ _ _ ≪≫
isoWhiskerLeft L.inverse (iso T L.functor R.functor B).symm) R.inverse ≪≫
associator _ _ _ ≪≫ isoWhiskerLeft _ (associator _ _ _) ≪≫
(associator _ _ _ ).symm ≪≫ isoWhiskerLeft _ R.unitIso.symm ≪≫
rightUnitor _
lemma vInv_vInv (h : CatCommSq T L.functor R.functor B) :
vInv B L.symm R.symm T (vInv T L R B h) = h := by
ext X
rw [vInv_iso_hom_app]
dsimp
rw [vInv_iso_inv_app]
rw [← cancel_mono (B.map (L.functor.map (NatTrans.app L.unitIso.hom X)))]
rw [← Functor.comp_map]
dsimp
simp only [Functor.map_comp, Equivalence.fun_inv_map, Functor.comp_obj,
Functor.id_obj, assoc, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app, comp_id]
rw [← B.map_comp, L.counit_app_functor, ← L.functor.map_comp, ← NatTrans.comp_app,
Iso.inv_hom_id, NatTrans.id_app, L.functor.map_id]
simp only [Functor.comp_obj]
rw [B.map_id]
rw [comp_id, R.counit_app_functor,
← R.functor.map_comp_assoc, ← R.functor.map_comp_assoc, assoc, ← NatTrans.comp_app,
Iso.hom_inv_id, NatTrans.id_app]
simp
/-- In a square of categories, when the left and right functors are part
of equivalence of categories, it is equivalent to show 2-commutativity for
the functors of these equivalences or for their inverses. -/
def vInvEquiv : CatCommSq T L.functor R.functor B ≃ CatCommSq B L.inverse R.inverse T where
toFun := vInv T L R B
invFun := vInv B L.symm R.symm T
left_inv := vInv_vInv T L R B
right_inv := vInv_vInv B L.symm R.symm T
end
end CatCommSq
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Extensive.lean | import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq
import Mathlib.CategoryTheory.Limits.Shapes.StrictInitial
import Mathlib.CategoryTheory.Limits.Types.Coproducts
import Mathlib.CategoryTheory.Limits.Types.Products
import Mathlib.CategoryTheory.Limits.Types.Pullbacks
import Mathlib.Topology.Category.TopCat.Limits.Pullbacks
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic
import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts
import Mathlib.CategoryTheory.Limits.VanKampen
/-!
# Extensive categories
## Main definitions
- `CategoryTheory.FinitaryExtensive`: A category is (finitary) extensive if it has finite
coproducts, and binary coproducts are van Kampen.
## Main Results
- `CategoryTheory.hasStrictInitialObjects_of_finitaryExtensive`: The initial object
in extensive categories is strict.
- `CategoryTheory.FinitaryExtensive.mono_inr_of_isColimit`: Coproduct injections are monic in
extensive categories.
- `CategoryTheory.BinaryCofan.isPullback_initial_to_of_isVanKampen`: In extensive categories,
sums are disjoint, i.e. the pullback of `X ⟶ X ⨿ Y` and `Y ⟶ X ⨿ Y` is the initial object.
- `CategoryTheory.types.finitaryExtensive`: The category of types is extensive.
- `CategoryTheory.FinitaryExtensive_TopCat`:
The category `Top` is extensive.
- `CategoryTheory.FinitaryExtensive_functor`: The category `C ⥤ D` is extensive if `D`
has all pullbacks and is extensive.
- `CategoryTheory.FinitaryExtensive.isVanKampen_finiteCoproducts`: Finite coproducts in a
finitary extensive category are van Kampen.
## TODO
Show that the following are finitary extensive:
- `Scheme`
- `AffineScheme` (`CommRingᵒᵖ`)
## References
- https://ncatlab.org/nlab/show/extensive+category
- [Carboni et al, Introduction to extensive and distributive categories][CARBONI1993145]
-/
open CategoryTheory.Limits Topology
namespace CategoryTheory
universe v' u' v u v'' u''
variable {J : Type v'} [Category.{u'} J] {C : Type u} [Category.{v} C]
variable {D : Type u''} [Category.{v''} D]
section Extensive
variable {X Y : C}
/-- A category has pullback of inclusions if it has all pullbacks along coproduct injections. -/
class HasPullbacksOfInclusions (C : Type u) [Category.{v} C] [HasBinaryCoproducts C] : Prop where
[hasPullbackInl : ∀ {X Y Z : C} (f : Z ⟶ X ⨿ Y), HasPullback coprod.inl f]
attribute [instance] HasPullbacksOfInclusions.hasPullbackInl
/--
A functor preserves pullback of inclusions if it preserves all pullbacks along coproduct injections.
-/
class PreservesPullbacksOfInclusions {C : Type*} [Category C] {D : Type*} [Category D]
(F : C ⥤ D) [HasBinaryCoproducts C] where
[preservesPullbackInl : ∀ {X Y Z : C} (f : Z ⟶ X ⨿ Y), PreservesLimit (cospan coprod.inl f) F]
attribute [instance] PreservesPullbacksOfInclusions.preservesPullbackInl
/-- A category is (finitary) pre-extensive if it has finite coproducts,
and binary coproducts are universal. -/
class FinitaryPreExtensive (C : Type u) [Category.{v} C] : Prop where
[hasFiniteCoproducts : HasFiniteCoproducts C]
[hasPullbacksOfInclusions : HasPullbacksOfInclusions C]
/-- In a finitary extensive category, all coproducts are van Kampen -/
universal' : ∀ {X Y : C} (c : BinaryCofan X Y), IsColimit c → IsUniversalColimit c
attribute [instance] FinitaryPreExtensive.hasFiniteCoproducts
attribute [instance] FinitaryPreExtensive.hasPullbacksOfInclusions
/-- A category is (finitary) extensive if it has finite coproducts,
and binary coproducts are van Kampen. -/
class FinitaryExtensive (C : Type u) [Category.{v} C] : Prop where
[hasFiniteCoproducts : HasFiniteCoproducts C]
[hasPullbacksOfInclusions : HasPullbacksOfInclusions C]
/-- In a finitary extensive category, all coproducts are van Kampen -/
van_kampen' : ∀ {X Y : C} (c : BinaryCofan X Y), IsColimit c → IsVanKampenColimit c
attribute [instance] FinitaryExtensive.hasFiniteCoproducts
attribute [instance] FinitaryExtensive.hasPullbacksOfInclusions
theorem FinitaryExtensive.vanKampen [FinitaryExtensive C] {F : Discrete WalkingPair ⥤ C}
(c : Cocone F) (hc : IsColimit c) : IsVanKampenColimit c := by
let X := F.obj ⟨WalkingPair.left⟩
let Y := F.obj ⟨WalkingPair.right⟩
have : F = pair X Y := by
apply Functor.hext
· rintro ⟨⟨⟩⟩ <;> rfl
· rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ <;> simp [X, Y]
clear_value X Y
subst this
exact FinitaryExtensive.van_kampen' c hc
namespace HasPullbacksOfInclusions
instance (priority := 100) [HasBinaryCoproducts C] [HasPullbacks C] :
HasPullbacksOfInclusions C := ⟨⟩
variable [HasBinaryCoproducts C] [HasPullbacksOfInclusions C] {X Y Z : C} (f : Z ⟶ X ⨿ Y)
instance preservesPullbackInl' :
HasPullback f coprod.inl :=
hasPullback_symmetry _ _
instance hasPullbackInr' :
HasPullback f coprod.inr := by
have : IsPullback (𝟙 _) (f ≫ (coprod.braiding X Y).hom) f (coprod.braiding Y X).hom :=
IsPullback.of_horiz_isIso ⟨by simp⟩
have := (IsPullback.of_hasPullback (f ≫ (coprod.braiding X Y).hom) coprod.inl).paste_horiz this
simp only [coprod.braiding_hom, Category.comp_id, colimit.ι_desc, BinaryCofan.mk_pt,
BinaryCofan.ι_app_left, BinaryCofan.mk_inl] at this
exact ⟨⟨⟨_, this.isLimit⟩⟩⟩
instance hasPullbackInr :
HasPullback coprod.inr f :=
hasPullback_symmetry _ _
end HasPullbacksOfInclusions
namespace PreservesPullbacksOfInclusions
variable {D : Type*} [Category D] [HasBinaryCoproducts C] (F : C ⥤ D)
noncomputable
instance (priority := 100) [PreservesLimitsOfShape WalkingCospan F] :
PreservesPullbacksOfInclusions F := ⟨⟩
variable [PreservesPullbacksOfInclusions F] {X Y Z : C} (f : Z ⟶ X ⨿ Y)
noncomputable
instance preservesPullbackInl' :
PreservesLimit (cospan f coprod.inl) F :=
preservesPullback_symmetry _ _ _
noncomputable
instance preservesPullbackInr' :
PreservesLimit (cospan f coprod.inr) F := by
apply preservesLimit_of_iso_diagram (K₁ := cospan (f ≫ (coprod.braiding X Y).hom) coprod.inl)
apply cospanExt (Iso.refl _) (Iso.refl _) (coprod.braiding X Y).symm <;> simp
noncomputable
instance preservesPullbackInr :
PreservesLimit (cospan coprod.inr f) F :=
preservesPullback_symmetry _ _ _
end PreservesPullbacksOfInclusions
instance (priority := 100) FinitaryExtensive.toFinitaryPreExtensive [FinitaryExtensive C] :
FinitaryPreExtensive C :=
⟨fun c hc ↦ (FinitaryExtensive.van_kampen' c hc).isUniversal⟩
theorem FinitaryExtensive.mono_inr_of_isColimit [FinitaryExtensive C] {c : BinaryCofan X Y}
(hc : IsColimit c) : Mono c.inr :=
BinaryCofan.mono_inr_of_isVanKampen (FinitaryExtensive.vanKampen c hc)
theorem FinitaryExtensive.mono_inl_of_isColimit [FinitaryExtensive C] {c : BinaryCofan X Y}
(hc : IsColimit c) : Mono c.inl :=
FinitaryExtensive.mono_inr_of_isColimit (BinaryCofan.isColimitFlip hc)
instance [FinitaryExtensive C] (X Y : C) : Mono (coprod.inl : X ⟶ X ⨿ Y) :=
(FinitaryExtensive.mono_inl_of_isColimit (coprodIsCoprod X Y) :)
instance [FinitaryExtensive C] (X Y : C) : Mono (coprod.inr : Y ⟶ X ⨿ Y) :=
(FinitaryExtensive.mono_inr_of_isColimit (coprodIsCoprod X Y) :)
theorem FinitaryExtensive.isPullback_initial_to_binaryCofan [FinitaryExtensive C]
{c : BinaryCofan X Y} (hc : IsColimit c) :
IsPullback (initial.to _) (initial.to _) c.inl c.inr :=
BinaryCofan.isPullback_initial_to_of_isVanKampen (FinitaryExtensive.vanKampen c hc)
instance (priority := 100) hasStrictInitialObjects_of_finitaryPreExtensive
[FinitaryPreExtensive C] : HasStrictInitialObjects C :=
hasStrictInitial_of_isUniversal (FinitaryPreExtensive.universal' _
((BinaryCofan.isColimit_iff_isIso_inr initialIsInitial _).mpr (by
dsimp
infer_instance)).some)
theorem finitaryExtensive_iff_of_isTerminal (C : Type u) [Category.{v} C] [HasFiniteCoproducts C]
[HasPullbacksOfInclusions C]
(T : C) (HT : IsTerminal T) (c₀ : BinaryCofan T T) (hc₀ : IsColimit c₀) :
FinitaryExtensive C ↔ IsVanKampenColimit c₀ := by
refine ⟨fun H => H.van_kampen' c₀ hc₀, fun H => ?_⟩
constructor
simp_rw [BinaryCofan.isVanKampen_iff] at H ⊢
intro X Y c hc X' Y' c' αX αY f hX hY
obtain ⟨d, hd, hd'⟩ :=
Limits.BinaryCofan.IsColimit.desc' hc (HT.from _ ≫ c₀.inl) (HT.from _ ≫ c₀.inr)
rw [H c' (αX ≫ HT.from _) (αY ≫ HT.from _) (f ≫ d) (by rw [← reassoc_of% hX, hd, Category.assoc])
(by rw [← reassoc_of% hY, hd', Category.assoc])]
obtain ⟨hl, hr⟩ := (H c (HT.from _) (HT.from _) d hd.symm hd'.symm).mp ⟨hc⟩
rw [hl.paste_vert_iff hX.symm, hr.paste_vert_iff hY.symm]
instance types.finitaryExtensive : FinitaryExtensive (Type u) := by
classical
rw [finitaryExtensive_iff_of_isTerminal (Type u) PUnit Types.isTerminalPunit _
(Types.binaryCoproductColimit _ _)]
apply BinaryCofan.isVanKampen_mk _ _ (fun X Y => Types.binaryCoproductColimit X Y) _
fun f g => (Limits.Types.pullbackLimitCone f g).2
· intro _ _ _ _ f hαX hαY
constructor
· refine ⟨⟨hαX.symm⟩, ⟨PullbackCone.isLimitAux' _ ?_⟩⟩
intro s
have : ∀ x, ∃! y, s.fst x = Sum.inl y := by
intro x
rcases h : s.fst x with val | val
· simp only [Types.binaryCoproductCocone_pt, Functor.const_obj_obj, Sum.inl.injEq,
existsUnique_eq']
· apply_fun f at h
cases ((congr_fun s.condition x).symm.trans h).trans (congr_fun hαY val :).symm
delta ExistsUnique at this
choose l hl hl' using this
exact ⟨l, (funext hl).symm, Types.isTerminalPunit.hom_ext _ _,
fun {l'} h₁ _ => funext fun x => hl' x (l' x) (congr_fun h₁ x).symm⟩
· refine ⟨⟨hαY.symm⟩, ⟨PullbackCone.isLimitAux' _ ?_⟩⟩
intro s
have : ∀ x, ∃! y, s.fst x = Sum.inr y := by
intro x
rcases h : s.fst x with val | val
· apply_fun f at h
cases ((congr_fun s.condition x).symm.trans h).trans (congr_fun hαX val :).symm
· simp only [Types.binaryCoproductCocone_pt, Functor.const_obj_obj, Sum.inr.injEq,
existsUnique_eq']
delta ExistsUnique at this
choose l hl hl' using this
exact ⟨l, (funext hl).symm, Types.isTerminalPunit.hom_ext _ _,
fun {l'} h₁ _ => funext fun x => hl' x (l' x) (congr_fun h₁ x).symm⟩
· intro Z f
dsimp [Limits.Types.binaryCoproductCocone]
delta Types.PullbackObj
have : ∀ x, f x = Sum.inl PUnit.unit ∨ f x = Sum.inr PUnit.unit := by
intro x
rcases f x with (⟨⟨⟩⟩ | ⟨⟨⟩⟩)
exacts [Or.inl rfl, Or.inr rfl]
let eX : { p : Z × PUnit // f p.fst = Sum.inl p.snd } ≃ { x : Z // f x = Sum.inl PUnit.unit } :=
⟨fun p => ⟨p.1.1, by convert p.2⟩, fun x => ⟨⟨_, _⟩, x.2⟩, fun _ => by ext; rfl,
fun _ => by ext; rfl⟩
let eY : { p : Z × PUnit // f p.fst = Sum.inr p.snd } ≃ { x : Z // f x = Sum.inr PUnit.unit } :=
⟨fun p => ⟨p.1.1, p.2.trans (congr_arg Sum.inr <| Subsingleton.elim _ _)⟩,
fun x => ⟨⟨_, _⟩, x.2⟩, fun _ => by ext; rfl, fun _ => by ext; rfl⟩
fapply BinaryCofan.isColimitMk
· exact fun s x => dite _ (fun h => s.inl <| eX.symm ⟨x, h⟩)
fun h => s.inr <| eY.symm ⟨x, (this x).resolve_left h⟩
· intro s
ext ⟨⟨x, ⟨⟩⟩, _⟩
dsimp
split_ifs <;> rfl
· intro s
ext ⟨⟨x, ⟨⟩⟩, hx⟩
dsimp
split_ifs with h
· cases h.symm.trans hx
· rfl
· intro s m e₁ e₂
ext x
split_ifs
· rw [← e₁]
rfl
· rw [← e₂]
rfl
section TopCat
/-- (Implementation) An auxiliary lemma for the proof that `TopCat` is finitary extensive. -/
noncomputable def finitaryExtensiveTopCatAux (Z : TopCat.{u})
(f : Z ⟶ TopCat.of (PUnit.{u + 1} ⊕ PUnit.{u + 1})) :
IsColimit (BinaryCofan.mk
(TopCat.pullbackFst f (TopCat.binaryCofan (TopCat.of PUnit) (TopCat.of PUnit)).inl)
(TopCat.pullbackFst f (TopCat.binaryCofan (TopCat.of PUnit) (TopCat.of PUnit)).inr)) := by
have h₁ : Set.range (TopCat.pullbackFst f (TopCat.binaryCofan (.of PUnit) (.of PUnit)).inl) =
f ⁻¹' Set.range Sum.inl := by
apply le_antisymm
· rintro _ ⟨x, rfl⟩; exact ⟨PUnit.unit, x.2.symm⟩
· rintro x ⟨⟨⟩, hx⟩; refine ⟨⟨⟨x, PUnit.unit⟩, hx.symm⟩, rfl⟩
have h₂ : Set.range (TopCat.pullbackFst f (TopCat.binaryCofan (.of PUnit) (.of PUnit)).inr) =
f ⁻¹' Set.range Sum.inr := by
apply le_antisymm
· rintro _ ⟨x, rfl⟩; exact ⟨PUnit.unit, x.2.symm⟩
· rintro x ⟨⟨⟩, hx⟩; refine ⟨⟨⟨x, PUnit.unit⟩, hx.symm⟩, rfl⟩
refine ((TopCat.binaryCofan_isColimit_iff _).mpr ⟨?_, ?_, ?_⟩).some
· refine ⟨(Homeomorph.prodPUnit Z).isEmbedding.comp .subtypeVal, ?_⟩
convert f.hom.2.1 _ isOpen_range_inl
· refine ⟨(Homeomorph.prodPUnit Z).isEmbedding.comp .subtypeVal, ?_⟩
convert f.hom.2.1 _ isOpen_range_inr
· convert Set.isCompl_range_inl_range_inr.preimage f
instance finitaryExtensive_TopCat : FinitaryExtensive TopCat.{u} := by
rw [finitaryExtensive_iff_of_isTerminal TopCat.{u} _ TopCat.isTerminalPUnit _
(TopCat.binaryCofanIsColimit _ _)]
apply BinaryCofan.isVanKampen_mk _ _ (fun X Y => TopCat.binaryCofanIsColimit X Y) _
fun f g => TopCat.pullbackConeIsLimit f g
· intro X' Y' αX αY f hαX hαY
constructor
· refine ⟨⟨hαX.symm⟩, ⟨PullbackCone.isLimitAux' _ ?_⟩⟩
intro s
have : ∀ x, ∃! y, s.fst x = Sum.inl y := by
intro x
rcases h : s.fst x with val | val
· exact ⟨val, rfl, fun y h => Sum.inl_injective h.symm⟩
· apply_fun f at h
cases ((ConcreteCategory.congr_hom s.condition x).symm.trans h).trans
(ConcreteCategory.congr_hom hαY val :).symm
delta ExistsUnique at this
choose l hl hl' using this
refine ⟨TopCat.ofHom ⟨l, ?_⟩, TopCat.ext fun a => (hl a).symm,
TopCat.isTerminalPUnit.hom_ext _ _,
fun {l'} h₁ _ => TopCat.ext fun x =>
hl' x (l' x) (ConcreteCategory.congr_hom h₁ x).symm⟩
apply (IsEmbedding.inl (X := X') (Y := Y')).isInducing.continuous_iff.mpr
convert s.fst.hom.2 using 1
exact (funext hl).symm
· refine ⟨⟨hαY.symm⟩, ⟨PullbackCone.isLimitAux' _ ?_⟩⟩
intro s
have : ∀ x, ∃! y, s.fst x = Sum.inr y := by
intro x
rcases h : s.fst x with val | val
· apply_fun f at h
cases ((ConcreteCategory.congr_hom s.condition x).symm.trans h).trans
(ConcreteCategory.congr_hom hαX val :).symm
· exact ⟨val, rfl, fun y h => Sum.inr_injective h.symm⟩
delta ExistsUnique at this
choose l hl hl' using this
refine ⟨TopCat.ofHom ⟨l, ?_⟩, TopCat.ext fun a => (hl a).symm,
TopCat.isTerminalPUnit.hom_ext _ _,
fun {l'} h₁ _ =>
TopCat.ext fun x => hl' x (l' x) (ConcreteCategory.congr_hom h₁ x).symm⟩
apply (IsEmbedding.inr (X := X') (Y := Y')).isInducing.continuous_iff.mpr
convert s.fst.hom.2 using 1
exact (funext hl).symm
· intro Z f
exact finitaryExtensiveTopCatAux Z f
end TopCat
section Functor
theorem finitaryExtensive_of_reflective
[HasFiniteCoproducts D] [HasPullbacksOfInclusions D] [FinitaryExtensive C]
{Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful]
[∀ X Y (f : X ⟶ Gl.obj Y), HasPullback (Gr.map f) (adj.unit.app Y)]
[∀ X Y (f : X ⟶ Gl.obj Y), PreservesLimit (cospan (Gr.map f) (adj.unit.app Y)) Gl]
[PreservesPullbacksOfInclusions Gl] :
FinitaryExtensive D := by
have : PreservesColimitsOfSize Gl := adj.leftAdjoint_preservesColimits
constructor
intro X Y c hc
apply (IsVanKampenColimit.precompose_isIso_iff
(Functor.isoWhiskerLeft _ (asIso adj.counit) ≪≫ Functor.rightUnitor _).hom).mp
have : ∀ (Z : C) (i : Discrete WalkingPair) (f : Z ⟶ (colimit.cocone (pair X Y ⋙ Gr)).pt),
PreservesLimit (cospan f ((colimit.cocone (pair X Y ⋙ Gr)).ι.app i)) Gl := by
have : pair X Y ⋙ Gr = pair (Gr.obj X) (Gr.obj Y) := by
apply Functor.hext
· rintro ⟨⟨⟩⟩ <;> rfl
· rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ <;> simp
rw [this]
rintro Z ⟨_ | _⟩ f <;> dsimp <;> infer_instance
refine ((FinitaryExtensive.vanKampen _ (colimit.isColimit <| pair X Y ⋙ _)).map_reflective
adj).of_iso (IsColimit.uniqueUpToIso ?_ ?_)
· exact isColimitOfPreserves Gl (colimit.isColimit _)
· exact (IsColimit.precomposeHomEquiv _ _).symm hc
instance finitaryExtensive_functor [HasPullbacks C] [FinitaryExtensive C] :
FinitaryExtensive (D ⥤ C) :=
haveI : HasFiniteCoproducts (D ⥤ C) := ⟨fun _ => Limits.functorCategoryHasColimitsOfShape⟩
⟨fun c hc => isVanKampenColimit_of_evaluation _ c fun _ =>
FinitaryExtensive.vanKampen _ <| isColimitOfPreserves _ hc⟩
instance {C} [Category C] {D} [Category D] (F : C ⥤ D)
{X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso f] : PreservesLimit (cospan f g) F :=
have := hasPullback_of_left_iso f g
preservesLimit_of_preserves_limit_cone (IsPullback.of_hasPullback f g).isLimit
((isLimitMapConePullbackConeEquiv _ pullback.condition).symm
(IsPullback.of_vert_isIso ⟨by simp only [← F.map_comp, pullback.condition]⟩).isLimit)
instance {C} [Category C] {D} [Category D] (F : C ⥤ D)
{X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso g] : PreservesLimit (cospan f g) F :=
preservesPullback_symmetry _ _ _
theorem finitaryExtensive_of_preserves_and_reflects (F : C ⥤ D) [FinitaryExtensive D]
[HasFiniteCoproducts C] [HasPullbacksOfInclusions C]
[PreservesPullbacksOfInclusions F]
[ReflectsLimitsOfShape WalkingCospan F] [PreservesColimitsOfShape (Discrete WalkingPair) F]
[ReflectsColimitsOfShape (Discrete WalkingPair) F] : FinitaryExtensive C := by
constructor
intro X Y c hc
refine IsVanKampenColimit.of_iso ?_ (hc.uniqueUpToIso (coprodIsCoprod X Y)).symm
have (i : Discrete WalkingPair) (Z : C) (f : Z ⟶ X ⨿ Y) :
PreservesLimit (cospan f ((BinaryCofan.mk coprod.inl coprod.inr).ι.app i)) F := by
rcases i with ⟨_ | _⟩ <;> dsimp <;> infer_instance
refine (FinitaryExtensive.vanKampen _
(isColimitOfPreserves F (coprodIsCoprod X Y))).of_mapCocone F
theorem finitaryExtensive_of_preserves_and_reflects_isomorphism (F : C ⥤ D) [FinitaryExtensive D]
[HasFiniteCoproducts C] [HasPullbacks C] [PreservesLimitsOfShape WalkingCospan F]
[PreservesColimitsOfShape (Discrete WalkingPair) F] [F.ReflectsIsomorphisms] :
FinitaryExtensive C := by
haveI : ReflectsLimitsOfShape WalkingCospan F := reflectsLimitsOfShape_of_reflectsIsomorphisms
haveI : ReflectsColimitsOfShape (Discrete WalkingPair) F :=
reflectsColimitsOfShape_of_reflectsIsomorphisms
exact finitaryExtensive_of_preserves_and_reflects F
end Functor
section FiniteCoproducts
theorem FinitaryPreExtensive.isUniversal_finiteCoproducts_Fin [FinitaryPreExtensive C] {n : ℕ}
{F : Discrete (Fin n) ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsUniversalColimit c := by
let f : Fin n → C := F.obj ∘ Discrete.mk
have : F = Discrete.functor f :=
Functor.hext (fun _ ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f])
clear_value f
subst this
induction n with
| zero => exact (isVanKampenColimit_of_isEmpty _ hc).isUniversal
| succ n IH =>
refine IsUniversalColimit.of_iso (@isUniversalColimit_extendCofan _ _ _ _ _ _
(IH _ (coproductIsCoproduct _)) (FinitaryPreExtensive.universal' _ (coprodIsCoprod _ _)) ?_)
((extendCofanIsColimit f (coproductIsCoproduct _) (coprodIsCoprod _ _)).uniqueUpToIso hc)
· dsimp
infer_instance
theorem FinitaryPreExtensive.isUniversal_finiteCoproducts [FinitaryPreExtensive C] {ι : Type*}
[Finite ι] {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsUniversalColimit c := by
obtain ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin ι
apply (IsUniversalColimit.whiskerEquivalence_iff (Discrete.equivalence e).symm).mp
apply FinitaryPreExtensive.isUniversal_finiteCoproducts_Fin
exact (IsColimit.whiskerEquivalenceEquiv (Discrete.equivalence e).symm) hc
theorem FinitaryExtensive.isVanKampen_finiteCoproducts_Fin [FinitaryExtensive C] {n : ℕ}
{F : Discrete (Fin n) ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsVanKampenColimit c := by
let f : Fin n → C := F.obj ∘ Discrete.mk
have : F = Discrete.functor f :=
Functor.hext (fun _ ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f])
clear_value f
subst this
induction n with
| zero => exact isVanKampenColimit_of_isEmpty _ hc
| succ n IH =>
apply IsVanKampenColimit.of_iso _
((extendCofanIsColimit f (coproductIsCoproduct _) (coprodIsCoprod _ _)).uniqueUpToIso hc)
apply @isVanKampenColimit_extendCofan _ _ _ _ _ _ _ _ ?_
· apply IH
exact coproductIsCoproduct _
· apply FinitaryExtensive.van_kampen'
exact coprodIsCoprod _ _
· dsimp
infer_instance
theorem FinitaryExtensive.isVanKampen_finiteCoproducts [FinitaryExtensive C] {ι : Type*}
[Finite ι] {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsVanKampenColimit c := by
obtain ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin ι
apply (IsVanKampenColimit.whiskerEquivalence_iff (Discrete.equivalence e).symm).mp
apply FinitaryExtensive.isVanKampen_finiteCoproducts_Fin
exact (IsColimit.whiskerEquivalenceEquiv (Discrete.equivalence e).symm) hc
lemma FinitaryPreExtensive.hasPullbacks_of_is_coproduct [FinitaryPreExtensive C] {ι : Type*}
[Finite ι] {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsColimit c) (i : Discrete ι) {X : C}
(g : X ⟶ _) : HasPullback g (c.ι.app i) := by
classical
let f : ι → C := F.obj ∘ Discrete.mk
have : F = Discrete.functor f :=
Functor.hext (fun i ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f])
clear_value f
subst this
change Cofan f at c
obtain ⟨i⟩ := i
let e : ∐ f ≅ f i ⨿ (∐ fun j : ({i}ᶜ : Set ι) ↦ f j) :=
{ hom := Sigma.desc (fun j ↦ if h : j = i then eqToHom (congr_arg f h) ≫ coprod.inl else
Sigma.ι (fun j : ({i}ᶜ : Set ι) ↦ f j) ⟨j, h⟩ ≫ coprod.inr)
inv := coprod.desc (Sigma.ι f i) (Sigma.desc fun j ↦ Sigma.ι f j)
hom_inv_id := by cat_disch
inv_hom_id := by
ext j
· simp
· simp only [coprod.desc_comp, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app,
eqToHom_refl, Category.id_comp, dite_true, BinaryCofan.mk_pt, BinaryCofan.ι_app_right,
BinaryCofan.mk_inr, colimit.ι_desc_assoc, Discrete.functor_obj, Category.comp_id]
exact dif_neg j.prop }
let e' : c.pt ≅ f i ⨿ (∐ fun j : ({i}ᶜ : Set ι) ↦ f j) :=
hc.coconePointUniqueUpToIso (getColimitCocone _).2 ≪≫ e
have : coprod.inl ≫ e'.inv = c.ι.app ⟨i⟩ := by
simp only [e, e', Iso.trans_inv, coprod.desc_comp, colimit.ι_desc, BinaryCofan.mk_pt,
BinaryCofan.ι_app_left, BinaryCofan.mk_inl]
exact colimit.comp_coconePointUniqueUpToIso_inv _ _
clear_value e'
rw [← this]
have : IsPullback (𝟙 _) (g ≫ e'.hom) g e'.inv := IsPullback.of_horiz_isIso ⟨by simp⟩
exact ⟨⟨⟨_, ((IsPullback.of_hasPullback (g ≫ e'.hom) coprod.inl).paste_horiz this).isLimit⟩⟩⟩
lemma FinitaryExtensive.mono_ι [FinitaryExtensive C] {ι : Type*} [Finite ι] {F : Discrete ι ⥤ C}
{c : Cocone F} (hc : IsColimit c) (i : Discrete ι) :
Mono (c.ι.app i) :=
mono_of_cofan_isVanKampen (isVanKampen_finiteCoproducts hc) _
instance [FinitaryExtensive C] {ι : Type*} [Finite ι] (X : ι → C) (i : ι) :
Mono (Sigma.ι X i) :=
FinitaryExtensive.mono_ι (coproductIsCoproduct _) ⟨i⟩
lemma FinitaryExtensive.isPullback_initial_to [FinitaryExtensive C]
{ι : Type*} [Finite ι] {F : Discrete ι ⥤ C}
{c : Cocone F} (hc : IsColimit c) (i j : Discrete ι) (e : i ≠ j) :
IsPullback (initial.to _) (initial.to _) (c.ι.app i) (c.ι.app j) :=
isPullback_initial_to_of_cofan_isVanKampen (isVanKampen_finiteCoproducts hc) i j e
lemma FinitaryExtensive.isPullback_initial_to_sigma_ι [FinitaryExtensive C] {ι : Type*} [Finite ι]
(X : ι → C) (i j : ι) (e : i ≠ j) :
IsPullback (initial.to _) (initial.to _) (Sigma.ι X i) (Sigma.ι X j) :=
FinitaryExtensive.isPullback_initial_to (coproductIsCoproduct _) ⟨i⟩ ⟨j⟩
(ne_of_apply_ne Discrete.as e)
instance FinitaryPreExtensive.hasPullbacks_of_inclusions [FinitaryPreExtensive C] {X Z : C}
{α : Type*} (f : X ⟶ Z) {Y : (a : α) → C} (i : (a : α) → Y a ⟶ Z) [Finite α]
[hi : IsIso (Sigma.desc i)] (a : α) : HasPullback f (i a) := by
apply FinitaryPreExtensive.hasPullbacks_of_is_coproduct (c := Cofan.mk Z i)
exact @IsColimit.ofPointIso (t := Cofan.mk Z i) (P := _) (i := hi)
lemma FinitaryPreExtensive.isIso_sigmaDesc_fst [FinitaryPreExtensive C] {α : Type} [Finite α]
{X : C} {Z : α → C} (π : (a : α) → Z a ⟶ X) {Y : C} (f : Y ⟶ X) (hπ : IsIso (Sigma.desc π)) :
IsIso (Sigma.desc ((fun _ ↦ pullback.fst _ _) : (a : α) → pullback f (π a) ⟶ _)) := by
let c := (Cofan.mk _ ((fun _ ↦ pullback.fst _ _) : (a : α) → pullback f (π a) ⟶ _))
apply c.isColimit_iff_isIso_sigmaDesc.mpr
have hau : IsUniversalColimit (Cofan.mk X π) := FinitaryPreExtensive.isUniversal_finiteCoproducts
((Cofan.isColimit_iff_isIso_sigmaDesc _).mp hπ).some
refine hau.nonempty_isColimit_of_pullbackCone_left _ (𝟙 _) _ _ (fun i ↦ ?_)
(PullbackCone.mk (𝟙 _) f (by simp)) (IsPullback.id_horiz f).isLimit _ (Iso.refl _)
(by simp) (by simp [c]) (by simp [pullback.condition, c])
exact pullback.isLimit _ _
@[deprecated (since := "2025-06-20")]
alias FinitaryPreExtensive.sigma_desc_iso := FinitaryPreExtensive.isIso_sigmaDesc_fst
/-- If `C` has pullbacks and is finitary (pre-)extensive, pullbacks distribute over finite
coproducts, i.e., `∐ (Xᵢ ×[S] Xⱼ) ≅ (∐ Xᵢ) ×[S] (∐ Xⱼ)`.
For an `IsPullback` version, see `FinitaryPreExtensive.isPullback_sigmaDesc`. -/
instance FinitaryPreExtensive.isIso_sigmaDesc_map [HasPullbacks C] [FinitaryPreExtensive C]
{ι ι' : Type*} [Finite ι] [Finite ι'] {S : C} {X : ι → C} {Y : ι' → C}
(f : ∀ i, X i ⟶ S) (g : ∀ i, Y i ⟶ S) :
IsIso (Sigma.desc fun (p : ι × ι') ↦
pullback.map (f p.1) (g p.2) (Sigma.desc f) (Sigma.desc g) (Sigma.ι _ p.1)
(Sigma.ι _ p.2) (𝟙 S) (by simp) (by simp)) := by
let c : Cofan _ := Cofan.mk _ <| fun (p : ι × ι') ↦
pullback.map (f p.1) (g p.2) (Sigma.desc f) (Sigma.desc g) (Sigma.ι _ p.1)
(Sigma.ι _ p.2) (𝟙 S) (by simp) (by simp)
apply c.isColimit_iff_isIso_sigmaDesc.mpr
refine IsUniversalColimit.nonempty_isColimit_prod_of_pullbackCone
(a := Cofan.mk _ <| fun i ↦ Sigma.ι _ i) (b := Cofan.mk _ <| fun i ↦ Sigma.ι _ i)
?_ ?_ f g (Sigma.desc f) (Sigma.desc g) (fun i j ↦ (pullback.cone (f i) (g j)))
(fun i j ↦ pullback.isLimit (f i) (g j)) (pullback.cone _ _) ?_ (Iso.refl _)
· exact FinitaryPreExtensive.isUniversal_finiteCoproducts (coproductIsCoproduct X)
· exact FinitaryPreExtensive.isUniversal_finiteCoproducts (coproductIsCoproduct Y)
· exact pullback.isLimit (Sigma.desc f) (Sigma.desc g)
/-- If `C` has pullbacks and is finitary (pre-)extensive, pullbacks distribute over finite
coproducts, i.e., `∐ (Xᵢ ×[S] Xⱼ) ≅ (∐ Xᵢ) ×[S] (∐ Xⱼ)`.
For a variant, see `FinitaryPreExtensive.isIso_sigmaDesc_map`. -/
lemma FinitaryPreExtensive.isPullback_sigmaDesc [HasPullbacks C] [FinitaryPreExtensive C]
{ι ι' : Type*} [Finite ι] [Finite ι'] {S : C} {X : ι → C} {Y : ι' → C}
(f : ∀ i, X i ⟶ S) (g : ∀ i, Y i ⟶ S) :
IsPullback
(Limits.Sigma.desc fun (p : ι × ι') ↦ pullback.fst (f p.1) (g p.2) ≫ Sigma.ι X p.1)
(Limits.Sigma.desc fun (p : ι × ι') ↦ pullback.snd (f p.1) (g p.2) ≫ Sigma.ι Y p.2)
(Limits.Sigma.desc f) (Limits.Sigma.desc g) := by
let c : Cofan _ := Cofan.mk _ <| fun (p : ι × ι') ↦
pullback.map (f p.1) (g p.2) (Sigma.desc f) (Sigma.desc g) (Sigma.ι _ p.1)
(Sigma.ι _ p.2) (𝟙 S) (by simp) (by simp)
convert IsUniversalColimit.isPullback_prod_of_isColimit
(d := Cofan.mk _ (Sigma.ι fun (p : ι × ι') ↦ pullback (f p.1) (g p.2)))
(hd := coproductIsCoproduct (fun (p : ι × ι') ↦ pullback (f p.1) (g p.2)))
(a := Cofan.mk _ <| fun i ↦ Sigma.ι _ i) (b := Cofan.mk _ <| fun i ↦ Sigma.ι _ i)
?_ ?_ f g (Sigma.desc f) (Sigma.desc g) (fun i j ↦ IsPullback.of_hasPullback (f i) (g j))
· ext
simp [Cofan.IsColimit.desc, Sigma.ι, coproductIsCoproduct]
· ext
simp [Cofan.IsColimit.desc, Sigma.ι, coproductIsCoproduct]
· exact FinitaryPreExtensive.isUniversal_finiteCoproducts (coproductIsCoproduct X)
· exact FinitaryPreExtensive.isUniversal_finiteCoproducts (coproductIsCoproduct Y)
end FiniteCoproducts
end Extensive
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Skeletal.lean | import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.IsomorphismClasses
import Mathlib.CategoryTheory.Thin
/-!
# Skeleton of a category
Define skeletal categories as categories in which any two isomorphic objects are equal.
Construct the skeleton of an arbitrary category by taking isomorphism classes, and show it is a
skeleton of the original category.
In addition, construct the skeleton of a thin category as a partial ordering, and (noncomputably)
show it is a skeleton of the original category. The advantage of this special case being handled
separately is that lemmas and definitions about orderings can be used directly, for example for the
subobject lattice. In addition, some of the commutative diagrams about the functors commute
definitionally on the nose which is convenient in practice.
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
namespace CategoryTheory
open Category
variable (C : Type u₁) [Category.{v₁} C]
variable (D : Type u₂) [Category.{v₂} D]
variable {E : Type u₃} [Category.{v₃} E]
/-- A category is skeletal if isomorphic objects are equal. -/
def Skeletal : Prop :=
∀ ⦃X Y : C⦄, IsIsomorphic X Y → X = Y
/-- `IsSkeletonOf C D F` says that `F : D ⥤ C` exhibits `D` as a skeletal full subcategory of `C`,
in particular `F` is a (strong) equivalence and `D` is skeletal.
-/
structure IsSkeletonOf (F : D ⥤ C) : Prop where
/-- The category `D` has isomorphic objects equal -/
skel : Skeletal D
/-- The functor `F` is an equivalence -/
eqv : F.IsEquivalence := by infer_instance
attribute [local instance] isIsomorphicSetoid
variable {C D}
/-- If `C` is thin and skeletal, then any naturally isomorphic functors to `C` are equal. -/
theorem Functor.eq_of_iso {F₁ F₂ : D ⥤ C} [Quiver.IsThin C] (hC : Skeletal C) (hF : F₁ ≅ F₂) :
F₁ = F₂ :=
Functor.ext (fun X => hC ⟨hF.app X⟩) fun _ _ _ => Subsingleton.elim _ _
/-- If `C` is thin and skeletal, `D ⥤ C` is skeletal.
`CategoryTheory.functor_thin` shows it is thin also.
-/
theorem functor_skeletal [Quiver.IsThin C] (hC : Skeletal C) : Skeletal (D ⥤ C) := fun _ _ h =>
h.elim (Functor.eq_of_iso hC)
variable (C D)
noncomputable section
/-- Construct the skeleton category as the induced category on the isomorphism classes, and derive
its category structure.
-/
def Skeleton : Type u₁ := InducedCategory (C := Quotient (isIsomorphicSetoid C)) C Quotient.out
deriving
Category,
[Inhabited C] → Inhabited _,
(α : Sort _) → [CoeSort C α] → CoeSort _ α
end
/-- The functor from the skeleton of `C` to `C`. -/
@[simps!]
noncomputable def fromSkeleton : Skeleton C ⥤ C :=
inducedFunctor _
-- The `Full, Faithful` instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
-- Note(kmill): `derive Functor.Full, Functor.Faithful` does not create instances
-- that are in terms of `Skeleton`, but rather `InducedCategory`, which can't be applied.
-- With `deriving @Functor.Full (Skeleton C)`, the instance can't be derived, for a similar reason.
noncomputable instance : (fromSkeleton C).Full := by
apply InducedCategory.full
noncomputable instance : (fromSkeleton C).Faithful := by
apply InducedCategory.faithful
instance : (fromSkeleton C).EssSurj where mem_essImage X := ⟨Quotient.mk' X, Quotient.mk_out X⟩
noncomputable instance fromSkeleton.isEquivalence : (fromSkeleton C).IsEquivalence where
variable {C}
/-- The class of an object in the skeleton. -/
abbrev toSkeleton (X : C) : Skeleton C := ⟦X⟧
/-- The isomorphism between `⟦X⟧.out` and `X`. -/
noncomputable def preCounitIso (X : C) : (fromSkeleton C).obj (toSkeleton X) ≅ X :=
Nonempty.some (Quotient.mk_out X)
alias fromSkeletonToSkeletonIso := preCounitIso
variable (C)
/-- An inverse to `fromSkeleton C` that forms an equivalence with it. -/
@[simps] noncomputable def toSkeletonFunctor : C ⥤ Skeleton C where
obj := toSkeleton
map {X Y} f := by apply (preCounitIso X).hom ≫ f ≫ (preCounitIso Y).inv
map_id _ := by aesop
map_comp _ _ := by change _ = CategoryStruct.comp (obj := C) _ _; simp
/-- The equivalence between the skeleton and the category itself. -/
@[simps] noncomputable def skeletonEquivalence : Skeleton C ≌ C where
functor := fromSkeleton C
inverse := toSkeletonFunctor C
unitIso := NatIso.ofComponents
(fun X ↦ InducedCategory.isoMk (Nonempty.some <| Quotient.mk_out X.out).symm)
fun _ ↦ .symm <| Iso.inv_hom_id_assoc _ _
counitIso := NatIso.ofComponents preCounitIso
functor_unitIso_comp _ := Iso.inv_hom_id _
theorem skeleton_skeletal : Skeletal (Skeleton C) := by
rintro X Y ⟨h⟩
have : X.out ≈ Y.out := ⟨(fromSkeleton C).mapIso h⟩
simpa using Quotient.sound this
/-- The `skeleton` of `C` given by choice is a skeleton of `C`. -/
lemma skeleton_isSkeleton : IsSkeletonOf C (Skeleton C) (fromSkeleton C) where
skel := skeleton_skeletal C
eqv := fromSkeleton.isEquivalence C
variable {C D}
lemma toSkeleton_fromSkeleton_obj (X : Skeleton C) : toSkeleton ((fromSkeleton C).obj X) = X :=
Quotient.out_eq _
lemma toSkeleton_eq_toSkeleton_iff {X Y : C} : toSkeleton X = toSkeleton Y ↔ Nonempty (X ≅ Y) :=
Quotient.eq
lemma congr_toSkeleton_of_iso {X Y : C} (e : X ≅ Y) : toSkeleton X = toSkeleton Y :=
Quotient.sound ⟨e⟩
/-- Provides a (noncomputable) isomorphism `X ≅ Y` given that `toSkeleton X = toSkeleton Y`. -/
noncomputable def Skeleton.isoOfEq {X Y : C} (h : toSkeleton X = toSkeleton Y) :
X ≅ Y :=
Quotient.exact h |>.some
lemma toSkeleton_eq_iff {X : C} {Y : Skeleton C} :
toSkeleton X = Y ↔ Nonempty (X ≅ (fromSkeleton C).obj Y) :=
Quotient.mk_eq_iff_out
namespace Functor
/-- From a functor `C ⥤ D`, construct a map of skeletons `Skeleton C → Skeleton D`. -/
noncomputable def mapSkeleton (F : C ⥤ D) : Skeleton C ⥤ Skeleton D :=
(skeletonEquivalence C).functor ⋙ F ⋙ (skeletonEquivalence D).inverse
variable (F : C ⥤ D)
lemma mapSkeleton_obj_toSkeleton (X : C) :
F.mapSkeleton.obj (toSkeleton X) = toSkeleton (F.obj X) :=
congr_toSkeleton_of_iso <| F.mapIso <| preCounitIso X
instance [F.Full] : F.mapSkeleton.Full := by unfold mapSkeleton; infer_instance
instance [F.Faithful] : F.mapSkeleton.Faithful := by unfold mapSkeleton; infer_instance
instance [F.EssSurj] : F.mapSkeleton.EssSurj := by unfold mapSkeleton; infer_instance
/-- A natural isomorphism between `X ↦ ⟦X⟧ ↦ ⟦FX⟧` and `X ↦ FX ↦ ⟦FX⟧`. On the level of
categories, these are `C ⥤ Skeleton C ⥤ Skeleton D` and `C ⥤ D ⥤ Skeleton D`. So this says that
the square formed by these 4 objects and 4 functors commutes. -/
noncomputable def toSkeletonFunctorCompMapSkeletonIso :
toSkeletonFunctor C ⋙ F.mapSkeleton ≅ F ⋙ toSkeletonFunctor D :=
NatIso.ofComponents (fun X ↦ (toSkeletonFunctor D).mapIso <| F.mapIso <| preCounitIso X)
(fun {X Y} f ↦ show (_ ≫ _) ≫ _ = _ ≫ _ by simp [assoc])
lemma mapSkeleton_injective [F.Full] [F.Faithful] : Function.Injective F.mapSkeleton.obj :=
fun _ _ h ↦ skeleton_skeletal C ⟨F.mapSkeleton.preimageIso <| eqToIso h⟩
lemma mapSkeleton_surjective [F.EssSurj] : Function.Surjective F.mapSkeleton.obj :=
fun Y ↦ let ⟨X, h⟩ := EssSurj.mem_essImage Y; ⟨X, skeleton_skeletal D h⟩
end Functor
/-- Two categories which are categorically equivalent have skeletons with equivalent objects.
-/
noncomputable def Equivalence.skeletonEquiv (e : C ≌ D) : Skeleton C ≃ Skeleton D :=
let f := ((skeletonEquivalence C).trans e).trans (skeletonEquivalence D).symm
{ toFun := f.functor.obj
invFun := f.inverse.obj
left_inv := fun X => skeleton_skeletal C ⟨(f.unitIso.app X).symm⟩
right_inv := fun Y => skeleton_skeletal D ⟨f.counitIso.app Y⟩ }
variable (C D)
/-- Construct the skeleton category by taking the quotient of objects. This construction gives a
preorder with nice definitional properties, but is only really appropriate for thin categories.
If your original category is not thin, you probably want to be using `Skeleton` instead of this.
-/
def ThinSkeleton : Type u₁ :=
Quotient (isIsomorphicSetoid C)
variable {C} in
/-- Convenience constructor for `ThinSkeleton`. -/
abbrev ThinSkeleton.mk (c : C) : ThinSkeleton C := Quotient.mk' c
instance inhabitedThinSkeleton [Inhabited C] : Inhabited (ThinSkeleton C) :=
⟨ThinSkeleton.mk default⟩
instance ThinSkeleton.preorder : Preorder (ThinSkeleton C) where
le :=
@Quotient.lift₂ C C _ (isIsomorphicSetoid C) (isIsomorphicSetoid C)
(fun X Y => Nonempty (X ⟶ Y))
(by
rintro _ _ _ _ ⟨i₁⟩ ⟨i₂⟩
exact
propext
⟨Nonempty.map fun f => i₁.inv ≫ f ≫ i₂.hom,
Nonempty.map fun f => i₁.hom ≫ f ≫ i₂.inv⟩)
le_refl := by
refine Quotient.ind fun a => ?_
exact ⟨𝟙 _⟩
le_trans a b c := Quotient.inductionOn₃ a b c fun _ _ _ => Nonempty.map2 (· ≫ ·)
/-- The functor from a category to its thin skeleton. -/
@[simps]
def toThinSkeleton : C ⥤ ThinSkeleton C where
obj := ThinSkeleton.mk
map f := homOfLE (Nonempty.intro f)
/-!
The constructions here are intended to be used when the category `C` is thin, even though
some of the statements can be shown without this assumption.
-/
namespace ThinSkeleton
/-- The thin skeleton is thin. -/
instance thin : Quiver.IsThin (ThinSkeleton C) := fun _ _ =>
⟨by
rintro ⟨⟨f₁⟩⟩ ⟨⟨_⟩⟩
rfl⟩
variable {C} {D}
/-- A functor `C ⥤ D` computably lowers to a functor `ThinSkeleton C ⥤ ThinSkeleton D`. -/
@[simps]
def map (F : C ⥤ D) : ThinSkeleton C ⥤ ThinSkeleton D where
obj := Quotient.map F.obj fun _ _ ⟨hX⟩ => ⟨F.mapIso hX⟩
map {X} {Y} := Quotient.recOnSubsingleton₂ X Y fun _ _ k => homOfLE (k.le.elim fun t => ⟨F.map t⟩)
theorem comp_toThinSkeleton (F : C ⥤ D) : F ⋙ toThinSkeleton D = toThinSkeleton C ⋙ map F :=
rfl
/-- Given a natural transformation `F₁ ⟶ F₂`, induce a natural transformation `map F₁ ⟶ map F₂`. -/
def mapNatTrans {F₁ F₂ : C ⥤ D} (k : F₁ ⟶ F₂) : map F₁ ⟶ map F₂ where
app X := Quotient.recOnSubsingleton X fun x => ⟨⟨⟨k.app x⟩⟩⟩
/- Porting note: `map₂ObjMap`, `map₂Functor`, and `map₂NatTrans` were all extracted
from the original `map₂` proof. Lean needed an extensive amount explicit type
annotations to figure things out. This also translated into repeated deterministic
timeouts. The extracted defs allow for explicit motives for the multiple
descents to the quotients.
It would be better to prove that
`ThinSkeleton (C × D) ≌ ThinSkeleton C × ThinSkeleton D`
which is more immediate from comparing the preorders. Then one could get
`map₂` by currying.
-/
/-- Given a bifunctor, we descend to a function on objects of `ThinSkeleton` -/
def map₂ObjMap (F : C ⥤ D ⥤ E) : ThinSkeleton C → ThinSkeleton D → ThinSkeleton E :=
fun x y =>
@Quotient.map₂ C D (isIsomorphicSetoid C) (isIsomorphicSetoid D) E (isIsomorphicSetoid E)
(fun X Y => (F.obj X).obj Y)
(fun X₁ _ ⟨hX⟩ _ Y₂ ⟨hY⟩ => ⟨(F.obj X₁).mapIso hY ≪≫ (F.mapIso hX).app Y₂⟩) x y
/-- For each `x : ThinSkeleton C`, we promote `map₂ObjMap F x` to a functor -/
def map₂Functor (F : C ⥤ D ⥤ E) : ThinSkeleton C → ThinSkeleton D ⥤ ThinSkeleton E :=
fun x =>
{ obj := fun y => map₂ObjMap F x y
map := fun {y₁} {y₂} => @Quotient.recOnSubsingleton C (isIsomorphicSetoid C)
(fun x => (y₁ ⟶ y₂) → (map₂ObjMap F x y₁ ⟶ map₂ObjMap F x y₂)) _ x fun X
=> Quotient.recOnSubsingleton₂ y₁ y₂ fun _ _ hY =>
homOfLE (hY.le.elim fun g => ⟨(F.obj X).map g⟩) }
/-- This provides natural transformations `map₂Functor F x₁ ⟶ map₂Functor F x₂` given
`x₁ ⟶ x₂` -/
def map₂NatTrans (F : C ⥤ D ⥤ E) : {x₁ x₂ : ThinSkeleton C} → (x₁ ⟶ x₂) →
(map₂Functor F x₁ ⟶ map₂Functor F x₂) := fun {x₁} {x₂} =>
@Quotient.recOnSubsingleton₂ C C (isIsomorphicSetoid C) (isIsomorphicSetoid C)
(fun x x' : ThinSkeleton C => (x ⟶ x') → (map₂Functor F x ⟶ map₂Functor F x')) _ x₁ x₂
(fun X₁ X₂ f => { app := fun y =>
Quotient.recOnSubsingleton y fun Y => homOfLE (f.le.elim fun f' => ⟨(F.map f').app Y⟩) })
-- TODO: state the lemmas about what happens when you compose with `toThinSkeleton`
/-- A functor `C ⥤ D ⥤ E` computably lowers to a functor
`ThinSkeleton C ⥤ ThinSkeleton D ⥤ ThinSkeleton E` -/
@[simps]
def map₂ (F : C ⥤ D ⥤ E) : ThinSkeleton C ⥤ ThinSkeleton D ⥤ ThinSkeleton E where
obj := map₂Functor F
map := map₂NatTrans F
variable (C)
section
variable [Quiver.IsThin C]
instance toThinSkeleton_faithful : (toThinSkeleton C).Faithful where
/-- Use `Quotient.out` to create a functor out of the thin skeleton. -/
@[simps]
noncomputable def fromThinSkeleton : ThinSkeleton C ⥤ C where
obj := Quotient.out
map {x} {y} :=
Quotient.recOnSubsingleton₂ x y fun X Y f =>
(Nonempty.some (Quotient.mk_out X)).hom ≫ f.le.some ≫ (Nonempty.some (Quotient.mk_out Y)).inv
/-- The equivalence between the thin skeleton and the category itself. -/
noncomputable def equivalence : ThinSkeleton C ≌ C where
functor := fromThinSkeleton C
inverse := toThinSkeleton C
counitIso := NatIso.ofComponents fun X => Nonempty.some (Quotient.mk_out X)
unitIso := NatIso.ofComponents fun x => Quotient.recOnSubsingleton x fun X =>
eqToIso (Quotient.sound ⟨(Nonempty.some (Quotient.mk_out X)).symm⟩)
noncomputable instance fromThinSkeleton_isEquivalence : (fromThinSkeleton C).IsEquivalence :=
(equivalence C).isEquivalence_functor
variable {C}
theorem equiv_of_both_ways {X Y : C} (f : X ⟶ Y) (g : Y ⟶ X) : X ≈ Y :=
⟨iso_of_both_ways f g⟩
instance thinSkeletonPartialOrder : PartialOrder (ThinSkeleton C) :=
{ CategoryTheory.ThinSkeleton.preorder C with
le_antisymm :=
Quotient.ind₂
(by
rintro _ _ ⟨f⟩ ⟨g⟩
apply Quotient.sound (equiv_of_both_ways f g)) }
theorem skeletal : Skeletal (ThinSkeleton C) := fun X Y =>
Quotient.inductionOn₂ X Y fun _ _ h => h.elim fun i => i.1.le.antisymm i.2.le
theorem map_comp_eq (F : E ⥤ D) (G : D ⥤ C) : map (F ⋙ G) = map F ⋙ map G :=
Functor.eq_of_iso skeletal <|
NatIso.ofComponents fun X => Quotient.recOnSubsingleton X fun _ => Iso.refl _
theorem map_id_eq : map (𝟭 C) = 𝟭 (ThinSkeleton C) :=
Functor.eq_of_iso skeletal <|
NatIso.ofComponents fun X => Quotient.recOnSubsingleton X fun _ => Iso.refl _
theorem map_iso_eq {F₁ F₂ : D ⥤ C} (h : F₁ ≅ F₂) : map F₁ = map F₂ :=
Functor.eq_of_iso skeletal
{ hom := mapNatTrans h.hom
inv := mapNatTrans h.inv }
/--
Applying `fromThinSkeleton`, `F` and then `toThinSkeleton` is isomorphic to applying `map F`.
-/
noncomputable def fromThinSkeletonCompToThinSkeletonIso (F : C ⥤ D) :
fromThinSkeleton C ⋙ F ⋙ toThinSkeleton D ≅ map F :=
Functor.isoWhiskerLeft (fromThinSkeleton C) (Iso.refl _) ≪≫
Functor.isoWhiskerRight (equivalence C).unitIso.symm (map F) ≪≫
Functor.leftUnitor (map F)
/--
Applying `map F` and then `fromThinSkeleton` is isomorphic to first applying `fromThinSkeleton`
and then applying `F`.
-/
noncomputable def mapCompFromThinSkeletonIso [Quiver.IsThin D] (F : C ⥤ D) :
map F ⋙ fromThinSkeleton D ≅ fromThinSkeleton C ⋙ F :=
Functor.isoWhiskerRight (fromThinSkeletonCompToThinSkeletonIso F).symm _ ≪≫
Functor.isoWhiskerLeft (fromThinSkeleton C ⋙ F) (equivalence D).counitIso ≪≫
Functor.rightUnitor (fromThinSkeleton C ⋙ F)
/-- `fromThinSkeleton C` exhibits the thin skeleton as a skeleton. -/
lemma thinSkeleton_isSkeleton : IsSkeletonOf C (ThinSkeleton C) (fromThinSkeleton C) where
skel := skeletal
instance isSkeletonOfInhabited :
Inhabited (IsSkeletonOf C (ThinSkeleton C) (fromThinSkeleton C)) :=
⟨thinSkeleton_isSkeleton⟩
end
variable {C}
/-- An adjunction between thin categories gives an adjunction between their thin skeletons. -/
def lowerAdjunction (R : D ⥤ C) (L : C ⥤ D) (h : L ⊣ R) :
ThinSkeleton.map L ⊣ ThinSkeleton.map R where
unit :=
{ app := fun X => by
letI := isIsomorphicSetoid C
exact Quotient.recOnSubsingleton X fun x => homOfLE ⟨h.unit.app x⟩ }
-- TODO: make quotient.rec_on_subsingleton' so the letI isn't needed
counit :=
{ app := fun X => by
letI := isIsomorphicSetoid D
exact Quotient.recOnSubsingleton X fun x => homOfLE ⟨h.counit.app x⟩ }
end ThinSkeleton
open ThinSkeleton
section
variable {C} {α : Type*} [PartialOrder α]
/--
When `e : C ≌ α` is a categorical equivalence from a thin category `C` to some partial order `α`,
the `ThinSkeleton C` is order isomorphic to `α`.
-/
noncomputable def Equivalence.thinSkeletonOrderIso [Quiver.IsThin C] (e : C ≌ α) :
ThinSkeleton C ≃o α :=
((ThinSkeleton.equivalence C).trans e).toOrderIso
end
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/EssentiallySmall.lean | import Mathlib.CategoryTheory.Category.ULift
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Skeletal
import Mathlib.CategoryTheory.Comma.Arrow
import Mathlib.Logic.UnivLE
import Mathlib.Logic.Small.Basic
/-!
# Essentially small categories.
A category given by `(C : Type u) [Category.{v} C]` is `w`-essentially small
if there exists a `SmallModel C : Type w` equipped with `[SmallCategory (SmallModel C)]` and an
equivalence `C ≌ SmallModel C`.
A category is `w`-locally small if every hom type is `w`-small.
The main theorem here is that a category is `w`-essentially small iff
the type `Skeleton C` is `w`-small, and `C` is `w`-locally small.
-/
universe w w' v v' u u'
open CategoryTheory
variable (C : Type u) [Category.{v} C]
namespace CategoryTheory
/-- A category is `EssentiallySmall.{w}` if there exists
an equivalence to some `S : Type w` with `[SmallCategory S]`. -/
@[pp_with_univ]
class EssentiallySmall (C : Type u) [Category.{v} C] : Prop where
/-- An essentially small category is equivalent to some small category. -/
equiv_smallCategory : ∃ (S : Type w) (_ : SmallCategory S), Nonempty (C ≌ S)
/-- Constructor for `EssentiallySmall C` from an explicit small category witness. -/
theorem EssentiallySmall.mk' {C : Type u} [Category.{v} C] {S : Type w} [SmallCategory S]
(e : C ≌ S) : EssentiallySmall.{w} C :=
⟨⟨S, _, ⟨e⟩⟩⟩
/-- An arbitrarily chosen small model for an essentially small category.
-/
@[pp_with_univ]
def SmallModel (C : Type u) [Category.{v} C] [EssentiallySmall.{w} C] : Type w :=
Classical.choose (@EssentiallySmall.equiv_smallCategory C _ _)
noncomputable instance smallCategorySmallModel (C : Type u) [Category.{v} C]
[EssentiallySmall.{w} C] : SmallCategory (SmallModel C) :=
Classical.choose (Classical.choose_spec (@EssentiallySmall.equiv_smallCategory C _ _))
/-- The (noncomputable) categorical equivalence between
an essentially small category and its small model.
-/
noncomputable def equivSmallModel (C : Type u) [Category.{v} C] [EssentiallySmall.{w} C] :
C ≌ SmallModel C :=
Nonempty.some
(Classical.choose_spec (Classical.choose_spec (@EssentiallySmall.equiv_smallCategory C _ _)))
instance (C : Type u) [Category.{v} C] [EssentiallySmall.{w} C] : EssentiallySmall.{w} Cᵒᵖ :=
EssentiallySmall.mk' (equivSmallModel C).op
theorem essentiallySmall_congr {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
(e : C ≌ D) : EssentiallySmall.{w} C ↔ EssentiallySmall.{w} D := by
fconstructor
· rintro ⟨S, 𝒮, ⟨f⟩⟩
exact EssentiallySmall.mk' (e.symm.trans f)
· rintro ⟨S, 𝒮, ⟨f⟩⟩
exact EssentiallySmall.mk' (e.trans f)
theorem Discrete.essentiallySmallOfSmall {α : Type u} [Small.{w} α] :
EssentiallySmall.{w} (Discrete α) :=
⟨⟨Discrete (Shrink α), ⟨inferInstance, ⟨Discrete.equivalence (equivShrink _)⟩⟩⟩⟩
theorem essentiallySmallSelf : EssentiallySmall.{max w v u} C :=
EssentiallySmall.mk' (AsSmall.equiv : C ≌ AsSmall.{w} C)
/-- A category is `w`-locally small if every hom set is `w`-small.
See `ShrinkHoms C` for a category instance where every hom set has been replaced by a small model.
-/
@[pp_with_univ]
class LocallySmall (C : Type u) [Category.{v} C] : Prop where
/-- A locally small category has small hom-types. -/
hom_small : ∀ X Y : C, Small.{w} (X ⟶ Y) := by infer_instance
instance (C : Type u) [Category.{v} C] [LocallySmall.{w} C] (X Y : C) : Small.{w, v} (X ⟶ Y) :=
LocallySmall.hom_small X Y
instance (C : Type u) [Category.{v} C] [LocallySmall.{w} C] : LocallySmall.{w} Cᵒᵖ where
hom_small X Y := small_of_injective (opEquiv X Y).injective
theorem locallySmall_of_faithful {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
(F : C ⥤ D) [F.Faithful] [LocallySmall.{w} D] : LocallySmall.{w} C where
hom_small {_ _} := small_of_injective F.map_injective
theorem locallySmall_congr {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
(e : C ≌ D) : LocallySmall.{w} C ↔ LocallySmall.{w} D :=
⟨fun _ => locallySmall_of_faithful e.inverse, fun _ => locallySmall_of_faithful e.functor⟩
instance (priority := 100) locallySmall_self (C : Type u) [Category.{v} C] :
LocallySmall.{v} C where
instance (priority := 100) locallySmall_of_univLE (C : Type u) [Category.{v} C] [UnivLE.{v, w}] :
LocallySmall.{w} C where
theorem locallySmall_max {C : Type u} [Category.{v} C] : LocallySmall.{max v w} C where
hom_small _ _ := small_max.{w} _
instance (priority := 100) locallySmall_of_essentiallySmall (C : Type u) [Category.{v} C]
[EssentiallySmall.{w} C] : LocallySmall.{w} C :=
(locallySmall_congr (equivSmallModel C)).mpr (CategoryTheory.locallySmall_self _)
/-- We define a type alias `ShrinkHoms C` for `C`. When we have `LocallySmall.{w} C`,
we'll put a `Category.{w}` instance on `ShrinkHoms C`.
-/
@[pp_with_univ]
def ShrinkHoms (C : Type u) :=
C
namespace ShrinkHoms
section
variable {C' : Type*}
-- a fresh variable with no category instance attached
/-- Help the typechecker by explicitly translating from `C` to `ShrinkHoms C`. -/
def toShrinkHoms {C' : Type*} (X : C') : ShrinkHoms C' :=
X
/-- Help the typechecker by explicitly translating from `ShrinkHoms C` to `C`. -/
def fromShrinkHoms {C' : Type*} (X : ShrinkHoms C') : C' :=
X
@[simp]
theorem to_from (X : C') : fromShrinkHoms (toShrinkHoms X) = X :=
rfl
@[simp]
theorem from_to (X : ShrinkHoms C') : toShrinkHoms (fromShrinkHoms X) = X :=
rfl
end
variable [LocallySmall.{w} C]
@[simps]
noncomputable instance : Category.{w} (ShrinkHoms C) where
Hom X Y := Shrink (fromShrinkHoms X ⟶ fromShrinkHoms Y)
id X := equivShrink _ (𝟙 (fromShrinkHoms X))
comp f g := equivShrink _ ((equivShrink _).symm f ≫ (equivShrink _).symm g)
/-- Implementation of `ShrinkHoms.equivalence`. -/
@[simps]
noncomputable def functor : C ⥤ ShrinkHoms C where
obj X := toShrinkHoms X
map {X Y} f := equivShrink (X ⟶ Y) f
/-- Implementation of `ShrinkHoms.equivalence`. -/
@[simps]
noncomputable def inverse : ShrinkHoms C ⥤ C where
obj X := fromShrinkHoms X
map {X Y} f := (equivShrink (fromShrinkHoms X ⟶ fromShrinkHoms Y)).symm f
/-- The categorical equivalence between `C` and `ShrinkHoms C`, when `C` is locally small.
-/
@[simps]
noncomputable def equivalence : C ≌ ShrinkHoms C where
functor := functor C
inverse := inverse C
unitIso := NatIso.ofComponents (fun _ ↦ Iso.refl _)
counitIso := NatIso.ofComponents (fun _ ↦ Iso.refl _)
instance : (functor C).IsEquivalence := (equivalence C).isEquivalence_functor
instance : (inverse C).IsEquivalence := (equivalence C).isEquivalence_inverse
instance {T : Type u} [Unique T] : Unique (ShrinkHoms.{u} T) where
default := ShrinkHoms.toShrinkHoms (default : T)
uniq _ := congr_arg ShrinkHoms.fromShrinkHoms (Unique.uniq _ _)
instance {T : Type u} [Category.{v} T] [IsDiscrete T] : IsDiscrete (ShrinkHoms.{u} T) where
subsingleton _ _ := { allEq _ _ := Shrink.ext (Subsingleton.elim _ _) }
eq_of_hom f := IsDiscrete.eq_of_hom (C := T) ((equivShrink _).symm f)
end ShrinkHoms
namespace Shrink
noncomputable instance [Small.{w} C] : Category.{v} (Shrink.{w} C) :=
InducedCategory.category (equivShrink C).symm
/-- The categorical equivalence between `C` and `Shrink C`, when `C` is small. -/
noncomputable def equivalence [Small.{w} C] : C ≌ Shrink.{w} C :=
(Equivalence.induced _).symm
instance [Small.{w'} C] [LocallySmall.{w} C] :
LocallySmall.{w} (Shrink.{w'} C) :=
locallySmall_of_faithful.{w} (equivalence.{w'} C).inverse
end Shrink
/-- A category is essentially small if and only if
the underlying type of its skeleton (i.e. the "set" of isomorphism classes) is small,
and it is locally small.
-/
theorem essentiallySmall_iff (C : Type u) [Category.{v} C] :
EssentiallySmall.{w} C ↔ Small.{w} (Skeleton C) ∧ LocallySmall.{w} C := by
-- This theorem is the only bit of real work in this file.
fconstructor
· intro h
fconstructor
· rcases h with ⟨S, 𝒮, ⟨e⟩⟩
refine ⟨⟨Skeleton S, ⟨?_⟩⟩⟩
exact e.skeletonEquiv
· infer_instance
· rintro ⟨⟨S, ⟨e⟩⟩, L⟩
let e' := (ShrinkHoms.equivalence C).skeletonEquiv.symm
letI : Category S := InducedCategory.category (e'.trans e).symm
refine ⟨⟨S, this, ⟨?_⟩⟩⟩
refine (ShrinkHoms.equivalence C).trans <|
(skeletonEquivalence (ShrinkHoms C)).symm.trans
((inducedFunctor (e'.trans e).symm).asEquivalence.symm)
instance essentiallySmall_of_small_of_locallySmall [Small.{w} C] [LocallySmall.{w} C] :
EssentiallySmall.{w} C :=
(essentiallySmall_iff C).2 ⟨small_of_surjective Quotient.exists_rep, by infer_instance⟩
example (C : Type w) [SmallCategory C] : EssentiallySmall.{w} C := inferInstance
instance small_skeleton_of_essentiallySmall [h : EssentiallySmall.{w} C] : Small.{w} (Skeleton C) :=
essentiallySmall_iff C |>.1 h |>.1
variable {C} in
theorem essentiallySmall_of_fully_faithful {D : Type u'} [Category.{v'} D] (F : C ⥤ D)
[F.Full] [F.Faithful] [EssentiallySmall.{w} D] : EssentiallySmall.{w} C :=
(essentiallySmall_iff C).2 ⟨small_of_injective F.mapSkeleton_injective,
locallySmall_of_faithful F⟩
section FullSubcategory
instance locallySmall_fullSubcategory [LocallySmall.{w} C] (P : ObjectProperty C) :
LocallySmall.{w} P.FullSubcategory :=
locallySmall_of_faithful <| P.ι
instance essentiallySmall_fullSubcategory_mem (s : Set C) [Small.{w} s] [LocallySmall.{w} C] :
EssentiallySmall.{w} (ObjectProperty.FullSubcategory (· ∈ s)) :=
suffices Small.{w} (ObjectProperty.FullSubcategory (· ∈ s)) from
essentiallySmall_of_small_of_locallySmall _
small_of_injective (f := fun x => (⟨x.1, x.2⟩ : s)) (by cat_disch)
end FullSubcategory
/-- Any thin category is locally small.
-/
instance (priority := 100) locallySmall_of_thin {C : Type u} [Category.{v} C] [Quiver.IsThin C] :
LocallySmall.{w} C where
/--
A thin category is essentially small if and only if the underlying type of its skeleton is small.
-/
theorem essentiallySmall_iff_of_thin {C : Type u} [Category.{v} C] [Quiver.IsThin C] :
EssentiallySmall.{w} C ↔ Small.{w} (Skeleton C) := by
simp [essentiallySmall_iff, CategoryTheory.locallySmall_of_thin]
instance [Small.{w} C] : Small.{w} (Discrete C) := small_map discreteEquiv
instance [Small.{w} C] [LocallySmall.{w} C] :
Small.{w} (Arrow C) := by
let φ (f : Arrow C) : Σ (s t : C), s ⟶ t := ⟨_, _, f.hom⟩
refine small_of_injective (f := φ) ?_
rintro ⟨s, t, f⟩ ⟨s', t', f'⟩ h
obtain rfl : s = s' := congr_arg Sigma.fst h
simp only [Functor.id_obj, Sigma.mk.injEq, heq_eq_eq, true_and, φ] at h
obtain rfl : t = t' := h.1
obtain rfl : f = f' := by simpa using h
rfl
instance [Small.{w} C] [LocallySmall.{w} C]
{D : Type u'} [Category.{v'} D] [Small.{w} D] [LocallySmall.{w} D] :
Small.{w} (C ⥤ D) := by
refine small_of_injective (f := fun F (f : Arrow C) ↦ Arrow.mk (F.map f.hom))
(fun F G h ↦ Functor.ext (fun X ↦ ?_) (fun X Y f ↦ ?_))
· exact congr_arg Comma.left (congr_fun h (Arrow.mk (𝟙 X)))
· have : Arrow.mk (F.map f) = Arrow.mk (G.map f) := congr_fun h (Arrow.mk f)
rw [Arrow.mk_eq_mk_iff] at this
tauto
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/Core.lean | import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.Types.Basic
import Mathlib.CategoryTheory.Whiskering
import Mathlib.Control.EquivFunctor
/-!
# The core of a category
The core of a category `C` is the (non-full) subcategory of `C` consisting of all objects,
and all isomorphisms. We construct it as a `CategoryTheory.Groupoid`.
`CategoryTheory.Core.inclusion : Core C ⥤ C` gives the faithful inclusion into the original
category.
Any functor `F` from a groupoid `G` into `C` factors through `CategoryTheory.Core C`,
but this is not functorial with respect to `F`.
-/
namespace CategoryTheory
open Functor
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
-- morphism levels before object levels. See note [category theory universes].
/-- The core of a category C is the groupoid whose morphisms are all the
isomorphisms of C. -/
structure Core (C : Type u₁) where
/-- The object of the base category underlying an object in `Core C`. -/
of : C
variable {C : Type u₁} [Category.{v₁} C]
/-- The hom-type between two objects of `Core C`.
It is defined as a one-field structure to prevent defeq abuses. -/
@[ext]
structure CoreHom (X Y : Core C) where
/-- The isomorphism of objects of `C` underlying a morphism in `Core C`. -/
iso : X.of ≅ Y.of
@[simps!]
instance coreCategory : Groupoid.{v₁} (Core C) where
Hom (X Y : Core C) := CoreHom X Y
id (X : Core C) := .mk <| Iso.refl X.of
comp f g := .mk <| Iso.trans f.iso g.iso
inv {_ _} f := .mk <| Iso.symm f.iso
@[simp]
lemma coreCategory_comp_iso {x y z : Core C} (f : x ⟶ y) (g : y ⟶ z) :
(f ≫ g).iso = f.iso ≪≫ g.iso := rfl
namespace Core
variable (C) in
/-- The core of a category is naturally included in the category. -/
@[simps!]
def inclusion : Core C ⥤ C where
obj := of
map f := f.iso.hom
@[ext]
theorem hom_ext {X Y : Core C} {f g : X ⟶ Y} (h : f.iso.hom = g.iso.hom) :
f = g := by
apply CoreHom.ext
exact Iso.ext h
variable (C)
instance : (inclusion C).Faithful where
variable {C} {G : Type u₂} [Groupoid.{v₂} G]
-- Note that this function is not functorial
-- (consider the two functors from [0] to [1], and the natural transformation between them).
/-- A functor from a groupoid to a category C factors through the core of C. -/
@[simps!]
def functorToCore (F : G ⥤ C) : G ⥤ Core C where
obj X := .mk <| F.obj X
map f := .mk <| { hom := F.map f, inv := F.map (Groupoid.inv f) }
/-- We can functorially associate to any functor from a groupoid to the core of a category `C`,
a functor from the groupoid to `C`, simply by composing with the embedding `Core C ⥤ C`.
-/
@[simps!]
def forgetFunctorToCore : (G ⥤ Core C) ⥤ G ⥤ C :=
(whiskeringRight _ _ _).obj (inclusion C)
end Core
section
namespace Functor
variable {D : Type u₂} [Category.{v₂} D]
/-- A functor `C ⥤ D` induces a functor `Core C ⥤ Core D`. -/
@[simps!]
def core (F : C ⥤ D) : Core C ⥤ Core D := Core.functorToCore (Core.inclusion _ ⋙ F)
variable (C) in
/-- The core of the identity functor is the identity functor on the cores. -/
@[simps!]
def coreId : (𝟭 C).core ≅ 𝟭 (Core C) := Iso.refl _
/-- The core of the composition of F and G is the composition of the cores. -/
@[simps!]
def coreComp {E : Type u₃} [Category.{v₃} E] (F : C ⥤ D) (G : D ⥤ E) :
(F ⋙ G).core ≅ F.core ⋙ G.core := Iso.refl _
/-- The natural isomorphism
```
F.core
Core C ⥤ Core D
inclusion C ‖ ‖ inclusion D
V V
C ⥤ D
F
```
thought of as pseudonaturality of `inclusion`,
when viewing `Core` as a pseudofunctor.
-/
@[simps!]
def coreCompInclusionIso (F : C ⥤ D) :
F.core ⋙ Core.inclusion D ≅ Core.inclusion C ⋙ F :=
Iso.refl _
lemma core_comp_inclusion (F : C ⥤ D) :
F.core ⋙ Core.inclusion D = Core.inclusion C ⋙ F :=
Functor.ext_of_iso (coreCompInclusionIso F) (by cat_disch)
end Functor
namespace Iso
variable {D : Type u₂} [Category.{v₂} D]
/-- A natural isomorphism of functors induces a natural isomorphism between their cores. -/
@[simps!]
def core {F G : C ⥤ D} (α : F ≅ G) : F.core ≅ G.core :=
NatIso.ofComponents
(fun x ↦ Groupoid.isoEquivHom _ _|>.symm <| .mk <| α.app x.of)
@[simp]
lemma coreComp {F G H : C ⥤ D} (α : F ≅ G) (β : G ≅ H) : (α ≪≫ β).core = α.core ≪≫ β.core := rfl
@[simp]
lemma coreId {F : C ⥤ D} : (Iso.refl F).core = Iso.refl F.core := rfl
lemma coreWhiskerLeft {E : Type u₃} [Category.{v₃} E] (F : C ⥤ D) {G H : D ⥤ E} (η : G ≅ H) :
(isoWhiskerLeft F η).core =
F.coreComp G ≪≫ isoWhiskerLeft F.core η.core ≪≫ (F.coreComp H).symm := by
cat_disch
lemma coreWhiskerRight {E : Type u₃} [Category.{v₃} E] {F G : C ⥤ D} (η : F ≅ G) (H : D ⥤ E) :
(isoWhiskerRight η H ).core =
F.coreComp H ≪≫ isoWhiskerRight η.core H.core ≪≫ (G.coreComp H).symm := by
cat_disch
lemma coreLeftUnitor {F : C ⥤ D} :
F.leftUnitor.core =
(𝟭 C).coreComp F ≪≫ isoWhiskerRight (Functor.coreId C) _ ≪≫ F.core.leftUnitor := by
cat_disch
lemma coreRightUnitor {F : C ⥤ D} :
F.rightUnitor.core =
(F).coreComp (𝟭 D) ≪≫ isoWhiskerLeft _ (Functor.coreId D) ≪≫ F.core.rightUnitor := by
cat_disch
lemma coreAssociator {E : Type u₃} [Category.{v₃} E] {E' : Type u₄} [Category.{v₄} E']
(F : C ⥤ D) (G : D ⥤ E) (H : E ⥤ E') :
(Functor.associator F G H).core =
(F ⋙ G).coreComp H ≪≫ isoWhiskerRight (F.coreComp G) H.core ≪≫
Functor.associator F.core G.core H.core ≪≫ (isoWhiskerLeft F.core (G.coreComp H)).symm ≪≫
(F.coreComp (G ⋙ H)).symm := by
cat_disch
end Iso
namespace Core
variable {G : Type u₂} [Groupoid.{v₂} G]
/-- The functor `functorToCore (F ⋙ H)` factors through `functortoCore H`. -/
def functorToCoreCompLeftIso {G' : Type u₃} [Groupoid.{v₃} G'] (H : G ⥤ C) (F : G' ⥤ G) :
functorToCore (F ⋙ H) ≅ F ⋙ functorToCore H :=
NatIso.ofComponents (fun _ ↦ Iso.refl _)
lemma functorToCore_comp_left {G' : Type u₃} [Groupoid.{v₃} G'] (H : G ⥤ C) (F : G' ⥤ G) :
functorToCore (F ⋙ H) = F ⋙ functorToCore H :=
Functor.ext_of_iso (functorToCoreCompLeftIso H F) (by cat_disch)
/-- The functor `functorToCore (H ⋙ F)` factors through `functorToCore H`. -/
def functorToCoreCompRightIso {C' : Type u₄} [Category.{v₄} C'] (H : G ⥤ C) (F : C ⥤ C') :
functorToCore (H ⋙ F) ≅ functorToCore H ⋙ F.core :=
Iso.refl _
lemma functorToCore_comp_right {C' : Type u₄} [Category.{v₄} C'] (H : G ⥤ C) (F : C ⥤ C') :
functorToCore (H ⋙ F) = functorToCore H ⋙ F.core :=
Functor.ext_of_iso (functorToCoreCompRightIso H F) (by cat_disch)
/-- The functor `functorToCore (𝟭 G)` is a section of `inclusion G`. -/
def inclusionCompFunctorToCoreIso : inclusion G ⋙ functorToCore (𝟭 G) ≅ 𝟭 (Core G) :=
NatIso.ofComponents (fun _ ↦ Iso.refl _)
theorem inclusion_comp_functorToCore : inclusion G ⋙ functorToCore (𝟭 G) = 𝟭 (Core G) :=
Functor.ext_of_iso inclusionCompFunctorToCoreIso (by cat_disch)
/-- The functor `functorToCore (inclusion C)` is isomorphic to the identity on `Core C`. -/
def functorToCoreInclusionIso : functorToCore (inclusion C) ≅ 𝟭 (Core C) :=
Iso.refl _
theorem functorToCore_inclusion : functorToCore (inclusion C) = 𝟭 (Core C) :=
Functor.ext_of_iso functorToCoreInclusionIso (by cat_disch)
end Core
variable (D : Type u₂) [Category.{v₂} D]
namespace Equivalence
variable {D} in
/-- Equivalent categories have equivalent cores. -/
@[simps!]
def core (E : C ≌ D) : Core C ≌ Core D where
functor := E.functor.core
inverse := E.inverse.core
unitIso := E.unitIso.core
counitIso := E.counitIso.core
end Equivalence
variable (C) in
/-- Taking the core of a functor is functorial if we discard non-invertible natural
transformations. -/
@[simps!]
def coreFunctor : Core (C ⥤ D) ⥤ Core C ⥤ Core D where
obj F := F.of.core
map η := η.iso.core.hom
end
/-- `ofEquivFunctor m` lifts a type-level `EquivFunctor`
to a categorical functor `Core (Type u₁) ⥤ Core (Type u₂)`.
-/
def ofEquivFunctor (m : Type u₁ → Type u₂) [EquivFunctor m] : Core (Type u₁) ⥤ Core (Type u₂) where
obj x := .mk <| m x.of
map f := .mk <| (EquivFunctor.mapEquiv m f.iso.toEquiv).toIso
map_id α := by ext x; exact congr_fun (EquivFunctor.map_refl' _) x
map_comp f g := by
ext
simp [EquivFunctor.map_trans', Function.comp]
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/LocallyDirected.lean | import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks
/-!
## Locally directed gluing
We say that a diagram of sets 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).
This is the condition needed to show that a colimit (in `TopCat`) of open embeddings is the
gluing of the open sets. See `Mathlib/AlgebraicGeometry/Gluing.lean` for an actual application.
-/
namespace CategoryTheory
open Limits
variable {J : Type*} [Category J]
/--
We say that a functor `F` to `Type*` is locally directed if for every `x ∈ F.obj k`, the
set of `F.obj` containing `x` is (co)directed.
That is, for each diagram
```
x ∈ Fₖ
↗ ↖
xᵢ ∈ Fᵢ xⱼ ∈ Fⱼ
```
there exists
```
xᵢ ∈ Fᵢ xⱼ ∈ Fⱼ
↖ ↗
xₗ ∈ Fₗ
```
that commutes with it.
-/
class Functor.IsLocallyDirected (F : J ⥤ Type*) : Prop where
cond (F) : ∀ {i j k} (fi : i ⟶ k) (fj : j ⟶ k) (xi : F.obj i) (xj : F.obj j),
F.map fi xi = F.map fj xj → ∃ (l : J) (fli : l ⟶ i) (flj : l ⟶ j) (x : _),
F.map fli x = xi ∧ F.map flj x = xj
alias Functor.exists_map_eq_of_isLocallyDirected := Functor.IsLocallyDirected.cond
instance (F : Discrete J ⥤ Type*) : F.IsLocallyDirected := by
constructor
rintro ⟨i⟩ ⟨j⟩ ⟨k⟩ ⟨⟨⟨⟩⟩⟩ ⟨⟨⟨⟩⟩⟩
simp only [Discrete.functor_map_id, types_id_apply, forall_eq']
exact fun x ↦ ⟨⟨i⟩, 𝟙 _, 𝟙 _, x, by simp⟩
instance (F : WidePushoutShape J ⥤ Type*) [∀ i, Mono (F.map (.init i))] :
F.IsLocallyDirected := by
constructor
rintro i j k (_ | i) (_ | j)
· simp only [WidePushoutShape.hom_id, FunctorToTypes.map_id_apply, forall_eq']
exact fun x ↦ ⟨_, 𝟙 _, 𝟙 _, x, by simp⟩
· simp only [WidePushoutShape.hom_id, FunctorToTypes.map_id_apply, forall_comm, forall_eq]
exact fun x ↦ ⟨_, .init _, 𝟙 _, x, by simp⟩
· simp only [WidePushoutShape.hom_id, FunctorToTypes.map_id_apply, forall_eq']
exact fun x ↦ ⟨_, 𝟙 _, .init _, x, by simp⟩
· simp only [((CategoryTheory.mono_iff_injective (F.map (.init i))).mp inferInstance).eq_iff,
forall_eq']
exact fun x ↦ ⟨_, 𝟙 _, 𝟙 _, x, by simp⟩
end CategoryTheory |
.lake/packages/mathlib/Mathlib/CategoryTheory/IsomorphismClasses.lean | import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.Types.Basic
/-!
# Objects of a category up to an isomorphism
`IsIsomorphic X Y := Nonempty (X ≅ Y)` is an equivalence relation on the objects of a category.
The quotient with respect to this relation defines a functor from our category to `Type`.
-/
universe v u
namespace CategoryTheory
section Category
variable {C : Type u} [Category.{v} C]
/-- An object `X` is isomorphic to an object `Y`, if `X ≅ Y` is not empty. -/
def IsIsomorphic : C → C → Prop := fun X Y => Nonempty (X ≅ Y)
variable (C)
/-- `IsIsomorphic` defines a setoid. -/
def isIsomorphicSetoid : Setoid C where
r := IsIsomorphic
iseqv := ⟨fun X => ⟨Iso.refl X⟩, fun ⟨α⟩ => ⟨α.symm⟩, fun ⟨α⟩ ⟨β⟩ => ⟨α.trans β⟩⟩
end Category
/-- The functor that sends each category to the quotient space of its objects up to an isomorphism.
-/
def isomorphismClasses : Cat.{v, u} ⥤ Type u where
obj C := Quotient (isIsomorphicSetoid C.α)
map {_ _} F := Quot.map F.obj fun _ _ ⟨f⟩ => ⟨F.mapIso f⟩
map_id {C} := by -- Porting note: this used to be `tidy`
apply funext; intro x
apply @Quot.recOn _ _ _ x
· intro _ _ p
simp only [types_id_apply]
· intro _
rfl
map_comp {C D E} f g := by -- Porting note(s): idem
apply funext; intro x
apply @Quot.recOn _ _ _ x
· intro _ _ _
simp only
· intro _
rfl
theorem Groupoid.isIsomorphic_iff_nonempty_hom {C : Type u} [Groupoid.{v} C] {X Y : C} :
IsIsomorphic X Y ↔ Nonempty (X ⟶ Y) :=
(Groupoid.isoEquivHom X Y).nonempty_congr
end CategoryTheory |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.