source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/Extend.lean
import Mathlib.Algebra.Homology.Embedding.IsSupported import Mathlib.Algebra.Homology.Additive import Mathlib.Algebra.Homology.Opposite /-! # The extension of a homological complex by an embedding of complex shapes Given an embedding `e : Embedding c c'` of complex shapes, and `K : HomologicalComplex C c`, we define `K.extend e : HomologicalComplex C c'`, and this leads to a functor `e.extendFunctor C : HomologicalComplex C c ⥤ HomologicalComplex C c'`. This construction first appeared in the Liquid Tensor Experiment. -/ open CategoryTheory Category Limits ZeroObject variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} namespace HomologicalComplex variable {C : Type*} [Category C] [HasZeroObject C] section variable [HasZeroMorphisms C] (K L M : HomologicalComplex C c) (φ : K ⟶ L) (φ' : L ⟶ M) (e : c.Embedding c') namespace extend /-- Auxiliary definition for the `X` field of `HomologicalComplex.extend`. -/ noncomputable def X : Option ι → C | some x => K.X x | none => 0 /-- The isomorphism `X K i ≅ K.X j` when `i = some j`. -/ noncomputable def XIso {i : Option ι} {j : ι} (hj : i = some j) : X K i ≅ K.X j := eqToIso (by subst hj; rfl) lemma isZero_X {i : Option ι} (hi : i = none) : IsZero (X K i) := by subst hi exact Limits.isZero_zero _ /-- The canonical isomorphism `X K.op i ≅ Opposite.op (X K i)`. -/ noncomputable def XOpIso (i : Option ι) : X K.op i ≅ Opposite.op (X K i) := match i with | some _ => Iso.refl _ | none => IsZero.iso (isZero_X _ rfl) (isZero_X K rfl).op /-- Auxiliary definition for the `d` field of `HomologicalComplex.extend`. -/ noncomputable def d : ∀ (i j : Option ι), extend.X K i ⟶ extend.X K j | none, _ => 0 | some i, some j => K.d i j | some _, none => 0 lemma d_none_eq_zero (i j : Option ι) (hi : i = none) : d K i j = 0 := by subst hi; rfl lemma d_none_eq_zero' (i j : Option ι) (hj : j = none) : d K i j = 0 := by subst hj; cases i <;> rfl lemma d_eq {i j : Option ι} {a b : ι} (hi : i = some a) (hj : j = some b) : d K i j = (XIso K hi).hom ≫ K.d a b ≫ (XIso K hj).inv := by subst hi hj simp [XIso, X, d] @[reassoc] lemma XOpIso_hom_d_op (i j : Option ι) : (XOpIso K i).hom ≫ (d K j i).op = d K.op i j ≫ (XOpIso K j).hom := match i, j with | none, _ => by simp only [d_none_eq_zero, d_none_eq_zero', comp_zero, zero_comp, op_zero] | some i, some j => by dsimp [XOpIso] simp only [d_eq _ rfl rfl, op_comp, assoc, id_comp, comp_id] rfl | some _, none => by simp only [d_none_eq_zero, d_none_eq_zero', comp_zero, zero_comp, op_zero] variable {K L} /-- Auxiliary definition for `HomologicalComplex.extendMap`. -/ noncomputable def mapX : ∀ (i : Option ι), X K i ⟶ X L i | some i => φ.f i | none => 0 lemma mapX_some {i : Option ι} {a : ι} (hi : i = some a) : mapX φ i = (XIso K hi).hom ≫ φ.f a ≫ (XIso L hi).inv := by subst hi dsimp [XIso, X] rw [id_comp, comp_id] rfl lemma mapX_none {i : Option ι} (hi : i = none) : mapX φ i = 0 := by subst hi; rfl end extend /-- Given `K : HomologicalComplex C c` and `e : c.Embedding c'`, this is the extension of `K` in `HomologicalComplex C c'`: it is zero in the degrees that are not in the image of `e.f`. -/ noncomputable def extend : HomologicalComplex C c' where X i' := extend.X K (e.r i') d i' j' := extend.d K (e.r i') (e.r j') shape i' j' h := by obtain hi'|⟨i, hi⟩ := (e.r i').eq_none_or_eq_some · rw [extend.d_none_eq_zero K _ _ hi'] · obtain hj'|⟨j, hj⟩ := (e.r j').eq_none_or_eq_some · rw [extend.d_none_eq_zero' K _ _ hj'] · rw [extend.d_eq K hi hj,K.shape, zero_comp, comp_zero] obtain rfl := e.f_eq_of_r_eq_some hi obtain rfl := e.f_eq_of_r_eq_some hj intro hij exact h (e.rel hij) d_comp_d' i' j' k' _ _ := by obtain hi'|⟨i, hi⟩ := (e.r i').eq_none_or_eq_some · rw [extend.d_none_eq_zero K _ _ hi', zero_comp] · obtain hj'|⟨j, hj⟩ := (e.r j').eq_none_or_eq_some · rw [extend.d_none_eq_zero K _ _ hj', comp_zero] · obtain hk'|⟨k, hk⟩ := (e.r k').eq_none_or_eq_some · rw [extend.d_none_eq_zero' K _ _ hk', comp_zero] · rw [extend.d_eq K hi hj, extend.d_eq K hj hk, assoc, assoc, Iso.inv_hom_id_assoc, K.d_comp_d_assoc, zero_comp, comp_zero] /-- The isomorphism `(K.extend e).X i' ≅ K.X i` when `e.f i = i'`. -/ noncomputable def extendXIso {i' : ι'} {i : ι} (h : e.f i = i') : (K.extend e).X i' ≅ K.X i := extend.XIso K (e.r_eq_some h) lemma isZero_extend_X' (i' : ι') (hi' : e.r i' = none) : IsZero ((K.extend e).X i') := extend.isZero_X K hi' lemma isZero_extend_X (i' : ι') (hi' : ∀ i, e.f i ≠ i') : IsZero ((K.extend e).X i') := K.isZero_extend_X' e i' (ComplexShape.Embedding.r_eq_none e i' hi') instance : (K.extend e).IsStrictlySupported e where isZero i' hi' := K.isZero_extend_X e i' hi' lemma extend_d_eq {i' j' : ι'} {i j : ι} (hi : e.f i = i') (hj : e.f j = j') : (K.extend e).d i' j' = (K.extendXIso e hi).hom ≫ K.d i j ≫ (K.extendXIso e hj).inv := by apply extend.d_eq lemma extend_d_from_eq_zero (i' j' : ι') (i : ι) (hi : e.f i = i') (hi' : ¬ c.Rel i (c.next i)) : (K.extend e).d i' j' = 0 := by obtain hj'|⟨j, hj⟩ := (e.r j').eq_none_or_eq_some · exact extend.d_none_eq_zero' _ _ _ hj' · rw [extend_d_eq K e hi (e.f_eq_of_r_eq_some hj), K.shape, zero_comp, comp_zero] intro hij obtain rfl := c.next_eq' hij exact hi' hij lemma extend_d_to_eq_zero (i' j' : ι') (j : ι) (hj : e.f j = j') (hj' : ¬ c.Rel (c.prev j) j) : (K.extend e).d i' j' = 0 := by obtain hi'|⟨i, hi⟩ := (e.r i').eq_none_or_eq_some · exact extend.d_none_eq_zero _ _ _ hi' · rw [extend_d_eq K e (e.f_eq_of_r_eq_some hi) hj, K.shape, zero_comp, comp_zero] intro hij obtain rfl := c.prev_eq' hij exact hj' hij variable {K L M} /-- Given an embedding `e : c.Embedding c'` of complexes shapes, this is the morphism `K.extend e ⟶ L.extend e` induced by a morphism `K ⟶ L` in `HomologicalComplex C c`. -/ noncomputable def extendMap : K.extend e ⟶ L.extend e where f _ := extend.mapX φ _ comm' i' j' _ := by by_cases hi : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi by_cases hj : ∃ j, e.f j = j' · obtain ⟨j, hj⟩ := hj rw [K.extend_d_eq e hi hj, L.extend_d_eq e hi hj, extend.mapX_some φ (e.r_eq_some hi), extend.mapX_some φ (e.r_eq_some hj)] simp only [extendXIso, assoc, Iso.inv_hom_id_assoc, Hom.comm_assoc] · have hj' := e.r_eq_none j' (fun j'' hj'' => hj ⟨j'', hj''⟩) dsimp [extend] rw [extend.d_none_eq_zero' _ _ _ hj', extend.d_none_eq_zero' _ _ _ hj', comp_zero, zero_comp] · have hi' := e.r_eq_none i' (fun i'' hi'' => hi ⟨i'', hi''⟩) dsimp [extend] rw [extend.d_none_eq_zero _ _ _ hi', extend.d_none_eq_zero _ _ _ hi', comp_zero, zero_comp] lemma extendMap_f {i : ι} {i' : ι'} (h : e.f i = i') : (extendMap φ e).f i' = (extendXIso K e h).hom ≫ φ.f i ≫ (extendXIso L e h).inv := by dsimp [extendMap] rw [extend.mapX_some φ (e.r_eq_some h)] rfl lemma extendMap_f_eq_zero (i' : ι') (hi' : ∀ i, e.f i ≠ i') : (extendMap φ e).f i' = 0 := by dsimp [extendMap] rw [extend.mapX_none φ (e.r_eq_none i' hi')] @[reassoc, simp] lemma extendMap_comp : extendMap (φ ≫ φ') e = extendMap φ e ≫ extendMap φ' e := by ext i' by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · simp [extendMap_f_eq_zero _ e i' (fun i hi => hi' ⟨i, hi⟩)] variable (K L M) lemma extendMap_id_f (i' : ι') : (extendMap (𝟙 K) e).f i' = 𝟙 _ := by by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · apply (K.isZero_extend_X e i' (fun i hi => hi' ⟨i, hi⟩)).eq_of_src @[simp] lemma extendMap_id : extendMap (𝟙 K) e = 𝟙 _ := by ext i' by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · apply (K.isZero_extend_X e i' (fun i hi => hi' ⟨i, hi⟩)).eq_of_src @[simp] lemma extendMap_zero : extendMap (0 : K ⟶ L) e = 0 := by ext i' by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · apply (K.isZero_extend_X e i' (fun i hi => hi' ⟨i, hi⟩)).eq_of_src /-- The canonical isomorphism `K.op.extend e.op ≅ (K.extend e).op`. -/ noncomputable def extendOpIso : K.op.extend e.op ≅ (K.extend e).op := Hom.isoOfComponents (fun _ ↦ extend.XOpIso _ _) (fun _ _ _ ↦ extend.XOpIso_hom_d_op _ _ _) @[reassoc] lemma extend_op_d (i' j' : ι') : (K.op.extend e.op).d i' j' = (K.extendOpIso e).hom.f i' ≫ ((K.extend e).d j' i').op ≫ (K.extendOpIso e).inv.f j' := by have := (K.extendOpIso e).inv.comm i' j' dsimp at this rw [← this, ← comp_f_assoc, Iso.hom_inv_id, id_f, id_comp] end @[simp] lemma extendMap_add [Preadditive C] {K L : HomologicalComplex C c} (φ φ' : K ⟶ L) (e : c.Embedding c') : extendMap (φ + φ' : K ⟶ L) e = extendMap φ e + extendMap φ' e := by ext i' by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' simp [extendMap_f _ e hi] · apply (K.isZero_extend_X e i' (fun i hi => hi' ⟨i, hi⟩)).eq_of_src end HomologicalComplex namespace ComplexShape.Embedding variable (e : Embedding c c') (C : Type*) [Category C] [HasZeroObject C] /-- Given an embedding `e : c.Embedding c'` of complex shapes, this is the functor `HomologicalComplex C c ⥤ HomologicalComplex C c'` which extend complexes along `e`: the extended complexes are zero in the degrees that are not in the image of `e.f`. -/ @[simps] noncomputable def extendFunctor [HasZeroMorphisms C] : HomologicalComplex C c ⥤ HomologicalComplex C c' where obj K := K.extend e map φ := HomologicalComplex.extendMap φ e instance [HasZeroMorphisms C] : (e.extendFunctor C).PreservesZeroMorphisms where instance [Preadditive C] : (e.extendFunctor C).Additive where end ComplexShape.Embedding
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/RestrictionHomology.lean
import Mathlib.Algebra.Homology.Embedding.Restriction import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex /-! # The homology of a restriction Under favourable circumstances, we may relate the homology of `K : HomologicalComplex C c'` in degree `j'` and that of `K.restriction e` in degree `j` when `e : Embedding c c'` is an embedding of complex shapes. See `restriction.sc'Iso` and `restriction.hasHomology`. -/ open CategoryTheory Category Limits ZeroObject variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} namespace HomologicalComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (K : HomologicalComplex C c') (e : c.Embedding c') [e.IsRelIff] namespace restriction variable (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) {i' j' k' : ι'} (hi' : e.f i = i') (hj' : e.f j = j') (hk' : e.f k = k') (hi'' : c'.prev j' = i') (hk'' : c'.next j' = k') /-- The isomorphism `(K.restriction e).sc' i j k ≅ K.sc' i' j' k'` when `e` is an embedding of complex shapes, `i'`, `j`, `k`' are the respective images of `i`, `j`, `k` by `e.f`, `j` is the previous index of `i`, etc. -/ @[simps!] def sc'Iso : (K.restriction e).sc' i j k ≅ K.sc' i' j' k' := ShortComplex.isoMk (K.restrictionXIso e hi') (K.restrictionXIso e hj') (K.restrictionXIso e hk') (by subst hi' hj'; simp [restrictionXIso]) (by subst hj' hk'; simp [restrictionXIso]) include hi hk hi' hj' hk' hi'' hk'' in lemma hasHomology [K.HasHomology j'] : (K.restriction e).HasHomology j := ShortComplex.hasHomology_of_iso (K.isoSc' i' j' k' hi'' hk'' ≪≫ (sc'Iso K e i j k hi' hj' hk' hi'' hk'').symm ≪≫ ((K.restriction e).isoSc' i j k hi hk).symm) end restriction variable (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) {i' j' k' : ι'} (hi' : e.f i = i') (hj' : e.f j = j') (hk' : e.f k = k') (hi'' : c'.prev j' = i') (hk'' : c'.next j' = k') [K.HasHomology j'] [(K.restriction e).HasHomology j] /-- The isomorphism `(K.restriction e).cycles j ≅ K.cycles j'` when `e.f j = j'` and the successors `k` and `k'` of `j` and `j'` satisfy `e.f k = k'`. -/ noncomputable def restrictionCyclesIso : (K.restriction e).cycles j ≅ K.cycles j' where hom := K.liftCycles ((K.restriction e).iCycles j ≫ (K.restrictionXIso e hj').hom) _ hk'' (by rw [assoc, ← cancel_mono (K.restrictionXIso e hk').inv, assoc, assoc, ← restriction_d_eq, iCycles_d, zero_comp]) inv := (K.restriction e).liftCycles (K.iCycles j' ≫ (K.restrictionXIso e hj').inv) _ hk (by rw [assoc, restriction_d_eq _ _ hj' hk', Iso.inv_hom_id_assoc, iCycles_d_assoc, zero_comp]) hom_inv_id := by simp [← cancel_mono ((K.restriction e).iCycles j)] inv_hom_id := by simp [← cancel_mono (K.iCycles j')] @[reassoc (attr := simp)] lemma restrictionCyclesIso_hom_iCycles : (K.restrictionCyclesIso e j k hk hj' hk' hk'').hom ≫ K.iCycles j' = (K.restriction e).iCycles j ≫ (K.restrictionXIso e hj').hom := by simp [restrictionCyclesIso] @[reassoc (attr := simp)] lemma restrictionCyclesIso_inv_iCycles : (K.restrictionCyclesIso e j k hk hj' hk' hk'').inv ≫ (K.restriction e).iCycles j = K.iCycles j' ≫ (K.restrictionXIso e hj').inv := by simp [restrictionCyclesIso] /-- The isomorphism `(K.restriction e).opcycles j ≅ K.opcycles j'` when `e.f j = j'` and the predecessors `i` and `i'` of `j` and `j'` satisfy `e.f i = i'`. -/ noncomputable def restrictionOpcyclesIso : (K.restriction e).opcycles j ≅ K.opcycles j' where hom := (K.restriction e).descOpcycles ((K.restrictionXIso e hj').hom ≫ K.pOpcycles j') _ hi (by rw [restriction_d_eq _ _ hi' hj', assoc, assoc, Iso.inv_hom_id_assoc, d_pOpcycles, comp_zero]) inv := K.descOpcycles ((K.restrictionXIso e hj').inv ≫ (K.restriction e).pOpcycles j) _ hi'' (by rw [← cancel_epi (K.restrictionXIso e hi').hom, ← restriction_d_eq_assoc, comp_zero, d_pOpcycles]) hom_inv_id := by simp [← cancel_epi ((K.restriction e).pOpcycles j)] inv_hom_id := by simp [← cancel_epi (K.pOpcycles j')] @[reassoc (attr := simp)] lemma pOpcycles_restrictionOpcyclesIso_hom : (K.restriction e).pOpcycles j ≫ (K.restrictionOpcyclesIso e i j hi hi' hj' hi'').hom = (K.restrictionXIso e hj').hom ≫ K.pOpcycles j' := by simp [restrictionOpcyclesIso] @[reassoc (attr := simp)] lemma pOpcycles_restrictionOpcyclesIso_inv : K.pOpcycles j' ≫ (K.restrictionOpcyclesIso e i j hi hi' hj' hi'').inv = (K.restrictionXIso e hj').inv ≫ (K.restriction e).pOpcycles j := by simp [restrictionOpcyclesIso] /-- The isomorphism `(K.restriction e).homology j ≅ K.homology j'` when `e.f j = j'`, the predecessors `i` and `i'` of `j` and `j'` satisfy `e.f i = i'`, and the successors `k` and `k'` of `j` and `j'` satisfy `e.f k = k'` -/ noncomputable def restrictionHomologyIso : (K.restriction e).homology j ≅ K.homology j' := have : ((K.restriction e).sc' i j k).HasHomology := by subst hi hk; assumption have : (K.sc' i' j' k').HasHomology := by subst hi'' hk''; assumption (K.restriction e).homologyIsoSc' i j k hi hk ≪≫ ShortComplex.homologyMapIso (restriction.sc'Iso K e i j k hi' hj' hk' hi'' hk'') ≪≫ (K.homologyIsoSc' i' j' k' hi'' hk'').symm @[reassoc (attr := simp, nolint unusedHavesSuffices)] lemma homologyπ_restrictionHomologyIso_hom : (K.restriction e).homologyπ j ≫ (K.restrictionHomologyIso e i j k hi hk hi' hj' hk' hi'' hk'').hom = (K.restrictionCyclesIso e j k hk hj' hk' hk'').hom ≫ K.homologyπ j' := by have : ((K.restriction e).sc' i j k).HasHomology := by subst hi hk; assumption have : (K.sc' i' j' k').HasHomology := by subst hi'' hk''; assumption dsimp [restrictionHomologyIso, homologyIsoSc'] rw [← ShortComplex.homologyMap_comp, ← ShortComplex.homologyMap_comp, ← cancel_mono (K.sc j').homologyι, assoc, assoc] apply (ShortComplex.π_homologyMap_ι _).trans dsimp rw [comp_id, id_comp] apply (K.restrictionCyclesIso_hom_iCycles_assoc e j k hk hj' hk' hk'' _).symm.trans congr 1 symm apply ShortComplex.homology_π_ι @[reassoc] lemma homologyπ_restrictionHomologyIso_inv : K.homologyπ j' ≫ (K.restrictionHomologyIso e i j k hi hk hi' hj' hk' hi'' hk'').inv = (K.restrictionCyclesIso e j k hk hj' hk' hk'').inv ≫ (K.restriction e).homologyπ j := by rw [← cancel_mono (K.restrictionHomologyIso e i j k hi hk hi' hj' hk' hi'' hk'').hom, assoc, assoc, Iso.inv_hom_id, homologyπ_restrictionHomologyIso_hom, comp_id, Iso.inv_hom_id_assoc] @[reassoc (attr := simp, nolint unusedHavesSuffices)] lemma restrictionHomologyIso_inv_homologyι : (K.restrictionHomologyIso e i j k hi hk hi' hj' hk' hi'' hk'').inv ≫ (K.restriction e).homologyι j = K.homologyι j' ≫ (K.restrictionOpcyclesIso e i j hi hi' hj' hi'').inv := by have : ((K.restriction e).sc' i j k).HasHomology := by subst hi hk; assumption have : (K.sc' i' j' k').HasHomology := by subst hi'' hk''; assumption dsimp [restrictionHomologyIso, homologyIsoSc'] rw [← ShortComplex.homologyMap_comp, ← ShortComplex.homologyMap_comp, assoc, ← cancel_epi (K.sc j').homologyπ] apply (ShortComplex.π_homologyMap_ι _).trans dsimp rw [comp_id, id_comp] refine ((ShortComplex.homology_π_ι_assoc _ _).trans ?_).symm congr 1 apply pOpcycles_restrictionOpcyclesIso_inv @[reassoc (attr := simp)] lemma restrictionHomologyIso_hom_homologyι : (K.restrictionHomologyIso e i j k hi hk hi' hj' hk' hi'' hk'').hom ≫ K.homologyι j' = (K.restriction e).homologyι j ≫ (K.restrictionOpcyclesIso e i j hi hi' hj' hi'').hom := by rw [← cancel_epi (K.restrictionHomologyIso e i j k hi hk hi' hj' hk' hi'' hk'').inv, Iso.inv_hom_id_assoc, restrictionHomologyIso_inv_homologyι_assoc, Iso.inv_hom_id, comp_id] end HomologicalComplex
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/StupidTrunc.lean
import Mathlib.Algebra.Homology.Embedding.Extend import Mathlib.Algebra.Homology.Embedding.IsSupported import Mathlib.Algebra.Homology.Embedding.Restriction /-! # The stupid truncation of homological complexes Given an embedding `e : c.Embedding c'` of complex shapes, we define a functor `stupidTruncFunctor : HomologicalComplex C c' ⥤ HomologicalComplex C c'` which sends `K` to `K.stupidTrunc e` which is defined as `(K.restriction e).extend e`. ## TODO (@joelriou) * define the inclusion `e.stupidTruncFunctor C ⟶ 𝟭 _` when `[e.IsTruncGE]`; * define the projection `𝟭 _ ⟶ e.stupidTruncFunctor C` when `[e.IsTruncLE]`. -/ open CategoryTheory Category Limits ZeroObject variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} namespace HomologicalComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] [HasZeroObject C] variable (K L M : HomologicalComplex C c') (φ : K ⟶ L) (φ' : L ⟶ M) (e : c.Embedding c') [e.IsRelIff] /-- The stupid truncation of a complex `K : HomologicalComplex C c'` relatively to an embedding `e : c.Embedding c'` of complex shapes. -/ noncomputable def stupidTrunc : HomologicalComplex C c' := ((K.restriction e).extend e) instance : IsStrictlySupported (K.stupidTrunc e) e := by dsimp [stupidTrunc] infer_instance /-- The isomorphism `(K.stupidTrunc e).X i' ≅ K.X i'` when `i` is in the image of `e.f`. -/ noncomputable def stupidTruncXIso {i : ι} {i' : ι'} (hi' : e.f i = i') : (K.stupidTrunc e).X i' ≅ K.X i' := (K.restriction e).extendXIso e hi' ≪≫ eqToIso (by subst hi'; rfl) lemma isZero_stupidTrunc_X (i' : ι') (hi' : ∀ i, e.f i ≠ i') : IsZero ((K.stupidTrunc e).X i') := isZero_extend_X _ _ _ hi' instance {ι'' : Type*} {c'' : ComplexShape ι''} (e' : c''.Embedding c') [K.IsStrictlySupported e'] : IsStrictlySupported (K.stupidTrunc e) e' where isZero i' hi' := by by_cases hi'' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi'' exact (K.isZero_X_of_isStrictlySupported e' i' hi').of_iso (K.stupidTruncXIso e hi) · apply isZero_stupidTrunc_X simpa using hi'' lemma isZero_stupidTrunc_iff : IsZero (K.stupidTrunc e) ↔ K.IsStrictlySupportedOutside e := by constructor · exact fun h ↦ ⟨fun i ↦ ((eval _ _ (e.f i)).map_isZero h).of_iso (K.stupidTruncXIso e rfl).symm⟩ · intro h rw [isZero_iff_isStrictlySupported_and_isStrictlySupportedOutside _ e] constructor · infer_instance · exact ⟨fun i ↦ (h.isZero i).of_iso (K.stupidTruncXIso e rfl)⟩ variable {K L M} /-- The morphism `K.stupidTrunc e ⟶ L.stupidTrunc e` induced by a morphism `K ⟶ L`. -/ noncomputable def stupidTruncMap : K.stupidTrunc e ⟶ L.stupidTrunc e := extendMap (restrictionMap φ e) e variable (K) in @[simp] lemma stupidTruncMap_id : stupidTruncMap (𝟙 K) e = 𝟙 _ := by simp [stupidTruncMap, stupidTrunc] @[simp, reassoc] lemma stupidTruncMap_comp : stupidTruncMap (φ ≫ φ') e = stupidTruncMap φ e ≫ stupidTruncMap φ' e := by simp [stupidTruncMap, stupidTrunc] @[reassoc (attr := simp)] lemma stupidTruncMap_stupidTruncXIso_hom {i : ι} {i' : ι'} (hi : e.f i = i') : (stupidTruncMap φ e).f i' ≫ (L.stupidTruncXIso e hi).hom = (K.stupidTruncXIso e hi).hom ≫ φ.f i' := by subst hi simp [stupidTruncMap, stupidTruncXIso, extendMap_f _ _ rfl] end HomologicalComplex namespace ComplexShape.Embedding variable (e : Embedding c c') (C : Type*) [Category C] [HasZeroMorphisms C] [HasZeroObject C] /-- The stupid truncation functor `HomologicalComplex C c' ⥤ HomologicalComplex C c'` given by an embedding `e : Embedding c c'` of complex shapes. -/ @[simps] noncomputable def stupidTruncFunctor [e.IsRelIff] : HomologicalComplex C c' ⥤ HomologicalComplex C c' where obj K := K.stupidTrunc e map φ := HomologicalComplex.stupidTruncMap φ e end ComplexShape.Embedding
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/TruncGE.lean
import Mathlib.Algebra.Homology.Embedding.HomEquiv import Mathlib.Algebra.Homology.Embedding.IsSupported import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex /-! # The canonical truncation Given an embedding `e : Embedding c c'` of complex shapes which satisfies `e.IsTruncGE` and `K : HomologicalComplex C c'`, we define `K.truncGE' e : HomologicalComplex C c` and `K.truncGE e : HomologicalComplex C c'` which are the canonical truncations of `K` relative to `e`. For example, if `e` is the embedding `embeddingUpIntGE p` of `ComplexShape.up ℕ` in `ComplexShape.up ℤ` which sends `n : ℕ` to `p + n` and `K : CochainComplex C ℤ`, then `K.truncGE' e : CochainComplex C ℕ` is the following complex: `Q ⟶ K.X (p + 1) ⟶ K.X (p + 2) ⟶ K.X (p + 3) ⟶ ...` where in degree `0`, the object `Q` identifies to the cokernel of `K.X (p - 1) ⟶ K.X p` (this is `K.opcycles p`). Then, the cochain complex `K.truncGE e` is indexed by `ℤ`, and has the following shape: `... ⟶ 0 ⟶ 0 ⟶ 0 ⟶ Q ⟶ K.X (p + 1) ⟶ K.X (p + 2) ⟶ K.X (p + 3) ⟶ ...` where `Q` is in degree `p`. We also construct the canonical epimorphism `K.πTruncGE e : K ⟶ K.truncGE e`. ## TODO * show that `K.πTruncGE e : K ⟶ K.truncGE e` induces an isomorphism in homology in degrees in the image of `e.f`. -/ open CategoryTheory Limits ZeroObject Category variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} {C : Type*} [Category C] [HasZeroMorphisms C] namespace HomologicalComplex variable (K L M : HomologicalComplex C c') (φ : K ⟶ L) (φ' : L ⟶ M) (e : c.Embedding c') [e.IsTruncGE] [∀ i', K.HasHomology i'] [∀ i', L.HasHomology i'] [∀ i', M.HasHomology i'] namespace truncGE' open Classical in /-- The `X` field of `truncGE'`. -/ noncomputable def X (i : ι) : C := if e.BoundaryGE i then K.opcycles (e.f i) else K.X (e.f i) /-- The isomorphism `truncGE'.X K e i ≅ K.opcycles (e.f i)` when `e.BoundaryGE i` holds. -/ noncomputable def XIsoOpcycles {i : ι} (hi : e.BoundaryGE i) : X K e i ≅ K.opcycles (e.f i) := eqToIso (if_pos hi) /-- The isomorphism `truncGE'.X K e i ≅ K.X (e.f i)` when `e.BoundaryGE i` does not hold. -/ noncomputable def XIso {i : ι} (hi : ¬ e.BoundaryGE i) : X K e i ≅ K.X (e.f i) := eqToIso (if_neg hi) open Classical in /-- The `d` field of `truncGE'`. -/ noncomputable def d (i j : ι) : X K e i ⟶ X K e j := if hij : c.Rel i j then if hi : e.BoundaryGE i then (truncGE'.XIsoOpcycles K e hi).hom ≫ K.fromOpcycles (e.f i) (e.f j) ≫ (XIso K e (e.not_boundaryGE_next hij)).inv else (XIso K e hi).hom ≫ K.d (e.f i) (e.f j) ≫ (XIso K e (e.not_boundaryGE_next hij)).inv else 0 @[reassoc (attr := simp)] lemma d_comp_d (i j k : ι) : d K e i j ≫ d K e j k = 0 := by dsimp [d] by_cases hij : c.Rel i j · by_cases hjk : c.Rel j k · rw [dif_pos hij, dif_pos hjk, dif_neg (e.not_boundaryGE_next hij)] split_ifs <;> simp · rw [dif_neg hjk, comp_zero] · rw [dif_neg hij, zero_comp] end truncGE' /-- The canonical truncation of a homological complex relative to an embedding of complex shapes `e` which satisfies `e.IsTruncGE`. -/ noncomputable def truncGE' : HomologicalComplex C c where X := truncGE'.X K e d := truncGE'.d K e shape _ _ h := dif_neg h /-- The isomorphism `(K.truncGE' e).X i ≅ K.X i'` when `e.f i = i'` and `e.BoundaryGE i` does not hold. -/ noncomputable def truncGE'XIso {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : ¬ e.BoundaryGE i) : (K.truncGE' e).X i ≅ K.X i' := (truncGE'.XIso K e hi) ≪≫ eqToIso (by subst hi'; rfl) /-- The isomorphism `(K.truncGE' e).X i ≅ K.opcycles i'` when `e.f i = i'` and `e.BoundaryGE i` holds. -/ noncomputable def truncGE'XIsoOpcycles {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : e.BoundaryGE i) : (K.truncGE' e).X i ≅ K.opcycles i' := (truncGE'.XIsoOpcycles K e hi) ≪≫ eqToIso (by subst hi'; rfl) lemma truncGE'_d_eq {i j : ι} (hij : c.Rel i j) {i' j' : ι'} (hi' : e.f i = i') (hj' : e.f j = j') (hi : ¬ e.BoundaryGE i) : (K.truncGE' e).d i j = (K.truncGE'XIso e hi' hi).hom ≫ K.d i' j' ≫ (K.truncGE'XIso e hj' (e.not_boundaryGE_next hij)).inv := by dsimp [truncGE', truncGE'.d] rw [dif_pos hij, dif_neg hi] subst hi' hj' simp [truncGE'XIso] lemma truncGE'_d_eq_fromOpcycles {i j : ι} (hij : c.Rel i j) {i' j' : ι'} (hi' : e.f i = i') (hj' : e.f j = j') (hi : e.BoundaryGE i) : (K.truncGE' e).d i j = (K.truncGE'XIsoOpcycles e hi' hi).hom ≫ K.fromOpcycles i' j' ≫ (K.truncGE'XIso e hj' (e.not_boundaryGE_next hij)).inv := by dsimp [truncGE', truncGE'.d] rw [dif_pos hij, dif_pos hi] subst hi' hj' simp [truncGE'XIso, truncGE'XIsoOpcycles] section variable [HasZeroObject C] /-- The canonical truncation of a homological complex relative to an embedding of complex shapes `e` which satisfies `e.IsTruncGE`. -/ noncomputable def truncGE : HomologicalComplex C c' := (K.truncGE' e).extend e /-- The isomorphism `(K.truncGE e).X i' ≅ K.X i'` when `e.f i = i'` and `e.BoundaryGE i` does not hold. -/ noncomputable def truncGEXIso {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : ¬ e.BoundaryGE i) : (K.truncGE e).X i' ≅ K.X i' := (K.truncGE' e).extendXIso e hi' ≪≫ K.truncGE'XIso e hi' hi /-- The isomorphism `(K.truncGE e).X i' ≅ K.opcycles i'` when `e.f i = i'` and `e.BoundaryGE i` holds. -/ noncomputable def truncGEXIsoOpcycles {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : e.BoundaryGE i) : (K.truncGE e).X i' ≅ K.opcycles i' := (K.truncGE' e).extendXIso e hi' ≪≫ K.truncGE'XIsoOpcycles e hi' hi end section variable {K L M} open Classical in /-- The morphism `K.truncGE' e ⟶ L.truncGE' e` induced by a morphism `K ⟶ L`. -/ noncomputable def truncGE'Map : K.truncGE' e ⟶ L.truncGE' e where f i := if hi : e.BoundaryGE i then (K.truncGE'XIsoOpcycles e rfl hi).hom ≫ opcyclesMap φ (e.f i) ≫ (L.truncGE'XIsoOpcycles e rfl hi).inv else (K.truncGE'XIso e rfl hi).hom ≫ φ.f (e.f i) ≫ (L.truncGE'XIso e rfl hi).inv comm' i j hij := by rw [dif_neg (e.not_boundaryGE_next hij)] by_cases hi : e.BoundaryGE i · rw [dif_pos hi] simp [truncGE'_d_eq_fromOpcycles _ e hij rfl rfl hi, ← cancel_epi (K.pOpcycles (e.f i))] · rw [dif_neg hi] simp [truncGE'_d_eq _ e hij rfl rfl hi] lemma truncGE'Map_f_eq_opcyclesMap {i : ι} (hi : e.BoundaryGE i) {i' : ι'} (h : e.f i = i') : (truncGE'Map φ e).f i = (K.truncGE'XIsoOpcycles e h hi).hom ≫ opcyclesMap φ i' ≫ (L.truncGE'XIsoOpcycles e h hi).inv := by subst h exact dif_pos hi lemma truncGE'Map_f_eq {i : ι} (hi : ¬ e.BoundaryGE i) {i' : ι'} (h : e.f i = i') : (truncGE'Map φ e).f i = (K.truncGE'XIso e h hi).hom ≫ φ.f i' ≫ (L.truncGE'XIso e h hi).inv := by subst h exact dif_neg hi variable (K) in @[simp] lemma truncGE'Map_id : truncGE'Map (𝟙 K) e = 𝟙 _ := by ext i by_cases hi : e.BoundaryGE i · simp [truncGE'Map_f_eq_opcyclesMap _ _ hi rfl] · simp [truncGE'Map_f_eq _ _ hi rfl] @[reassoc, simp] lemma truncGE'Map_comp : truncGE'Map (φ ≫ φ') e = truncGE'Map φ e ≫ truncGE'Map φ' e := by ext i by_cases hi : e.BoundaryGE i · simp [truncGE'Map_f_eq_opcyclesMap _ _ hi rfl, opcyclesMap_comp] · simp [truncGE'Map_f_eq _ _ hi rfl] variable [HasZeroObject C] /-- The morphism `K.truncGE e ⟶ L.truncGE e` induced by a morphism `K ⟶ L`. -/ noncomputable def truncGEMap : K.truncGE e ⟶ L.truncGE e := (e.extendFunctor C).map (truncGE'Map φ e) variable (K) in @[simp] lemma truncGEMap_id : truncGEMap (𝟙 K) e = 𝟙 _ := by simp [truncGEMap, truncGE] @[reassoc, simp] lemma truncGEMap_comp : truncGEMap (φ ≫ φ') e = truncGEMap φ e ≫ truncGEMap φ' e := by simp [truncGEMap, truncGE] end namespace restrictionToTruncGE' open Classical in /-- Auxiliary definition for `HomologicalComplex.restrictionToTruncGE'`. -/ noncomputable def f (i : ι) : (K.restriction e).X i ⟶ (K.truncGE' e).X i := if hi : e.BoundaryGE i then K.pOpcycles _ ≫ (K.truncGE'XIsoOpcycles e rfl hi).inv else (K.truncGE'XIso e rfl hi).inv lemma f_eq_iso_hom_pOpcycles_iso_inv {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : e.BoundaryGE i) : f K e i = (K.restrictionXIso e hi').hom ≫ K.pOpcycles i' ≫ (K.truncGE'XIsoOpcycles e hi' hi).inv := by dsimp [f] rw [dif_pos hi] subst hi' simp [restrictionXIso] lemma f_eq_iso_hom_iso_inv {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : ¬ e.BoundaryGE i) : f K e i = (K.restrictionXIso e hi').hom ≫ (K.truncGE'XIso e hi' hi).inv := by dsimp [f] rw [dif_neg hi] subst hi' simp [restrictionXIso] @[reassoc (attr := simp)] lemma comm (i j : ι) : f K e i ≫ (K.truncGE' e).d i j = (K.restriction e).d i j ≫ f K e j := by by_cases hij : c.Rel i j · by_cases hi : e.BoundaryGE i · rw [f_eq_iso_hom_pOpcycles_iso_inv K e rfl hi, f_eq_iso_hom_iso_inv K e rfl (e.not_boundaryGE_next hij), K.truncGE'_d_eq_fromOpcycles e hij rfl rfl hi] simp [restrictionXIso] · rw [f_eq_iso_hom_iso_inv K e rfl hi, f_eq_iso_hom_iso_inv K e rfl (e.not_boundaryGE_next hij), K.truncGE'_d_eq e hij rfl rfl hi] simp [restrictionXIso] · simp [HomologicalComplex.shape _ _ _ hij] end restrictionToTruncGE' /-- The canonical morphism `K.restriction e ⟶ K.truncGE' e`. -/ noncomputable def restrictionToTruncGE' : K.restriction e ⟶ K.truncGE' e where f := restrictionToTruncGE'.f K e lemma restrictionToTruncGE'_hasLift : e.HasLift (K.restrictionToTruncGE' e) := by intro j hj i' _ dsimp [restrictionToTruncGE'] rw [restrictionToTruncGE'.f_eq_iso_hom_pOpcycles_iso_inv K e rfl hj] simp [restrictionXIso] lemma restrictionToTruncGE'_f_eq_iso_hom_pOpcycles_iso_inv {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : e.BoundaryGE i) : (K.restrictionToTruncGE' e).f i = (K.restrictionXIso e hi').hom ≫ K.pOpcycles i' ≫ (K.truncGE'XIsoOpcycles e hi' hi).inv := by apply restrictionToTruncGE'.f_eq_iso_hom_pOpcycles_iso_inv lemma restrictionToTruncGE'_f_eq_iso_hom_iso_inv {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : ¬ e.BoundaryGE i) : (K.restrictionToTruncGE' e).f i = (K.restrictionXIso e hi').hom ≫ (K.truncGE'XIso e hi' hi).inv := by apply restrictionToTruncGE'.f_eq_iso_hom_iso_inv /-- `K.restrictionToTruncGE' e).f i` is an isomorphism when `¬ e.BoundaryGE i`. -/ lemma isIso_restrictionToTruncGE' (i : ι) (hi : ¬ e.BoundaryGE i) : IsIso ((K.restrictionToTruncGE' e).f i) := by rw [K.restrictionToTruncGE'_f_eq_iso_hom_iso_inv e rfl hi] infer_instance variable {K L} in @[reassoc (attr := simp)] lemma restrictionToTruncGE'_naturality : K.restrictionToTruncGE' e ≫ truncGE'Map φ e = restrictionMap φ e ≫ L.restrictionToTruncGE' e := by ext i by_cases hi : e.BoundaryGE i · simp [restrictionToTruncGE'_f_eq_iso_hom_pOpcycles_iso_inv _ e rfl hi, truncGE'Map_f_eq_opcyclesMap φ e hi rfl, restrictionXIso] · simp [restrictionToTruncGE'_f_eq_iso_hom_iso_inv _ e rfl hi, truncGE'Map_f_eq φ e hi rfl, restrictionXIso] attribute [local instance] epi_comp in instance (i : ι) : Epi ((K.restrictionToTruncGE' e).f i) := by by_cases hi : e.BoundaryGE i · rw [K.restrictionToTruncGE'_f_eq_iso_hom_pOpcycles_iso_inv e rfl hi] infer_instance · have := K.isIso_restrictionToTruncGE' e i hi infer_instance instance [K.IsStrictlySupported e] (i : ι) : IsIso ((K.restrictionToTruncGE' e).f i) := by by_cases hi : e.BoundaryGE i · rw [K.restrictionToTruncGE'_f_eq_iso_hom_pOpcycles_iso_inv e rfl hi] have : IsIso (K.pOpcycles (e.f i)) := K.isIso_pOpcycles _ _ rfl (by obtain ⟨hi₁, hi₂⟩ := hi apply IsZero.eq_of_src (K.isZero_X_of_isStrictlySupported e _ (fun j hj ↦ hi₂ j (by simpa only [hj] using hi₁)))) infer_instance · rw [K.restrictionToTruncGE'_f_eq_iso_hom_iso_inv e rfl hi] infer_instance section variable [HasZeroObject C] /-- The canonical morphism `K ⟶ K.truncGE e` when `e` is an embedding of complex shapes which satisfy `e.IsTruncGE`. -/ noncomputable def πTruncGE : K ⟶ K.truncGE e := e.liftExtend (K.restrictionToTruncGE' e) (K.restrictionToTruncGE'_hasLift e) instance (i' : ι') : Epi ((K.πTruncGE e).f i') := by by_cases hi' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi' dsimp [πTruncGE] rw [e.epi_liftExtend_f_iff _ _ hi] infer_instance · apply (isZero_extend_X _ _ _ (by simpa using hi')).epi instance : Epi (K.πTruncGE e) := epi_of_epi_f _ (fun _ => inferInstance) instance : (K.truncGE e).IsStrictlySupported e := by dsimp [truncGE] infer_instance variable {K L} in @[reassoc (attr := simp)] lemma πTruncGE_naturality : K.πTruncGE e ≫ truncGEMap φ e = φ ≫ L.πTruncGE e := by apply (e.homEquiv _ _).injective ext1 dsimp [truncGEMap, πTruncGE] rw [e.homRestrict_comp_extendMap, e.homRestrict_liftExtend, e.homRestrict_precomp, e.homRestrict_liftExtend, restrictionToTruncGE'_naturality] instance {ι'' : Type*} {c'' : ComplexShape ι''} (e' : c''.Embedding c') [K.IsStrictlySupported e'] : (K.truncGE e).IsStrictlySupported e' where isZero := by intro i' hi' by_cases hi'' : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hi'' by_cases hi''' : e.BoundaryGE i · rw [IsZero.iff_id_eq_zero, ← cancel_epi ((K.truncGE' e).extendXIso e hi ≪≫ K.truncGE'XIsoOpcycles e hi hi''').inv, ← cancel_epi (HomologicalComplex.pOpcycles _ _)] apply (K.isZero_X_of_isStrictlySupported e' i' hi').eq_of_src · exact (K.isZero_X_of_isStrictlySupported e' i' hi').of_iso ((K.truncGE' e).extendXIso e hi ≪≫ K.truncGE'XIso e hi hi''') · exact (K.truncGE e).isZero_X_of_isStrictlySupported e _ (by simpa using hi'') instance [K.IsStrictlySupported e] : IsIso (K.πTruncGE e) := by suffices ∀ (i' : ι'), IsIso ((K.πTruncGE e).f i') by apply Hom.isIso_of_components intro i' by_cases! hn : ∃ i, e.f i = i' · obtain ⟨i, hi⟩ := hn dsimp [πTruncGE] rw [e.isIso_liftExtend_f_iff _ _ hi] infer_instance · refine ⟨0, ?_, ?_⟩ all_goals apply (isZero_X_of_isStrictlySupported _ e i' hn).eq_of_src lemma isIso_πTruncGE_iff : IsIso (K.πTruncGE e) ↔ K.IsStrictlySupported e := ⟨fun _ ↦ isStrictlySupported_of_iso (asIso (K.πTruncGE e)).symm e, fun _ ↦ inferInstance⟩ end end HomologicalComplex namespace ComplexShape.Embedding variable (e : Embedding c c') [e.IsTruncGE] (C : Type*) [Category C] [HasZeroMorphisms C] [HasZeroObject C] [CategoryWithHomology C] /-- Given an embedding `e : Embedding c c'` of complex shapes which satisfy `e.IsTruncGE`, this is the (canonical) truncation functor `HomologicalComplex C c' ⥤ HomologicalComplex C c`. -/ @[simps] noncomputable def truncGE'Functor : HomologicalComplex C c' ⥤ HomologicalComplex C c where obj K := K.truncGE' e map φ := HomologicalComplex.truncGE'Map φ e /-- The natural transformation `K.restriction e ⟶ K.truncGE' e` for all `K`. -/ @[simps] noncomputable def restrictionToTruncGE'NatTrans : e.restrictionFunctor C ⟶ e.truncGE'Functor C where app K := K.restrictionToTruncGE' e /-- Given an embedding `e : Embedding c c'` of complex shapes which satisfy `e.IsTruncGE`, this is the (canonical) truncation functor `HomologicalComplex C c' ⥤ HomologicalComplex C c'`. -/ @[simps] noncomputable def truncGEFunctor : HomologicalComplex C c' ⥤ HomologicalComplex C c' where obj K := K.truncGE e map φ := HomologicalComplex.truncGEMap φ e /-- The natural transformation `K.πTruncGE e : K ⟶ K.truncGE e` for all `K`. -/ @[simps] noncomputable def πTruncGENatTrans : 𝟭 _ ⟶ e.truncGEFunctor C where app K := K.πTruncGE e end ComplexShape.Embedding
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/TruncLEHomology.lean
import Mathlib.Algebra.Homology.Embedding.TruncGEHomology import Mathlib.Algebra.Homology.Embedding.TruncLE import Mathlib.Algebra.Homology.HomologySequence import Mathlib.Algebra.Homology.ShortComplex.Abelian import Mathlib.Algebra.Homology.HomologicalComplexAbelian /-! # The homology of a canonical truncation Given an embedding of complex shapes `e : Embedding c c'`, we relate the homology of `K : HomologicalComplex C c'` and of `K.truncLE e : HomologicalComplex C c'`. The main result is that `K.ιTruncLE e : K.truncLE e ⟶ K` induces a quasi-isomorphism in degree `e.f i` for all `i`. (Note that the complex `K.truncLE e` is exact in degrees that are not in the image of `e.f`.) All the results are obtained by dualising the results in the file `Embedding.TruncGEHomology`. Moreover, if `C` is an abelian category, we introduce the cokernel sequence `K.shortComplexTruncLE e` of the monomorphism `K.ιTruncLE e`. -/ open CategoryTheory Category Limits namespace HomologicalComplex variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} {C : Type*} [Category C] section variable [HasZeroMorphisms C] (K L : HomologicalComplex C c') (φ : K ⟶ L) (e : c.Embedding c') [e.IsTruncLE] [∀ i', K.HasHomology i'] [∀ i', L.HasHomology i'] namespace truncLE' /-- `K.truncLE'ToRestriction e` is a quasi-isomorphism in degrees that are not at the boundary. -/ lemma quasiIsoAt_truncLE'ToRestriction (j : ι) (hj : ¬ e.BoundaryLE j) [(K.restriction e).HasHomology j] [(K.truncLE' e).HasHomology j] : QuasiIsoAt (K.truncLE'ToRestriction e) j := by dsimp only [truncLE'ToRestriction] have : (K.op.restriction e.op).HasHomology j := inferInstanceAs ((K.restriction e).op.HasHomology j) rw [quasiIsoAt_unopFunctor_map_iff] exact truncGE'.quasiIsoAt_restrictionToTruncGE' K.op e.op j (by simpa) instance truncLE'_hasHomology (i : ι) : (K.truncLE' e).HasHomology i := inferInstanceAs ((K.op.truncGE' e.op).unop.HasHomology i) end truncLE' variable [HasZeroObject C] instance (i' : ι') : (K.truncLE e).HasHomology i' := inferInstanceAs ((K.op.truncGE e.op).unop.HasHomology i') lemma quasiIsoAt_ιTruncLE {j : ι} {j' : ι'} (hj' : e.f j = j') : QuasiIsoAt (K.ιTruncLE e) j' := by have := K.op.quasiIsoAt_πTruncGE e.op hj' exact inferInstanceAs (QuasiIsoAt ((unopFunctor _ _ ).map (K.op.πTruncGE e.op).op) j') instance (i : ι) : QuasiIsoAt (K.ιTruncLE e) (e.f i) := K.quasiIsoAt_ιTruncLE e rfl lemma quasiIso_ιTruncLE_iff_isSupported : QuasiIso (K.ιTruncLE e) ↔ K.IsSupported e := by rw [← quasiIso_opFunctor_map_iff, ← isSupported_op_iff] exact K.op.quasiIso_πTruncGE_iff_isSupported e.op lemma acyclic_truncLE_iff_isSupportedOutside : (K.truncLE e).Acyclic ↔ K.IsSupportedOutside e := by rw [← acyclic_op_iff, ← isSupportedOutside_op_iff] exact K.op.acyclic_truncGE_iff_isSupportedOutside e.op variable {K L} lemma quasiIso_truncLEMap_iff : QuasiIso (truncLEMap φ e) ↔ ∀ (i : ι) (i' : ι') (_ : e.f i = i'), QuasiIsoAt φ i' := by rw [← quasiIso_opFunctor_map_iff] simp only [← quasiIsoAt_opFunctor_map_iff φ] apply quasiIso_truncGEMap_iff end section variable [Abelian C] (K : HomologicalComplex C c') (e : c.Embedding c') [e.IsTruncLE] /-- The cokernel sequence of the monomorphism `K.ιTruncLE e`. -/ @[simps X₁ X₂ f] noncomputable def shortComplexTruncLE : ShortComplex (HomologicalComplex C c') := ShortComplex.mk (K.ιTruncLE e) _ (cokernel.condition _) instance : Mono (K.shortComplexTruncLE e).f := by dsimp [shortComplexTruncLE] infer_instance instance : Epi (K.shortComplexTruncLE e).g := by dsimp [shortComplexTruncLE] infer_instance lemma shortComplexTruncLE_shortExact : (K.shortComplexTruncLE e).ShortExact where exact := ShortComplex.exact_of_g_is_cokernel _ (cokernelIsCokernel _) lemma mono_homologyMap_shortComplexTruncLE_g (i' : ι') (hi' : ∀ i, e.f i ≠ i') : Mono (homologyMap (K.shortComplexTruncLE e).g i') := ((K.shortComplexTruncLE_shortExact e).homology_exact₂ i').mono_g (by apply ((K.truncLE e).exactAt_of_isSupported e i' hi').isZero_homology.eq_of_src) @[simp] lemma shortComplexTruncLE_shortExact_δ_eq_zero (i' j' : ι') (hij' : c'.Rel i' j') : (K.shortComplexTruncLE_shortExact e).δ i' j' hij' = 0 := by by_cases hj : ∃ j, e.f j = j' · obtain ⟨j, rfl⟩ := hj rw [← cancel_mono (homologyMap (K.ιTruncLE e) (e.f j)), zero_comp] exact (K.shortComplexTruncLE_shortExact e).δ_comp i' _ hij' · apply ((K.truncLE e).exactAt_of_isSupported e j' (by simpa using hj)).isZero_homology.eq_of_tgt instance epi_homologyMap_shortComplexTruncLE_g (i' : ι') : Epi (homologyMap (K.shortComplexTruncLE e).g i') := by by_cases hi' : ∃ j', c'.Rel i' j' · obtain ⟨j', hj'⟩ := hi' exact ((K.shortComplexTruncLE_shortExact e).homology_exact₃ i' j' hj').epi_f (by simp) · exact epi_homologyMap_of_epi_of_not_rel _ _ (by simpa using hi') lemma isIso_homologyMap_shortComplexTruncLE_g (i' : ι') (hi' : ∀ i, e.f i ≠ i') : IsIso (homologyMap (K.shortComplexTruncLE e).g i') := by have := K.mono_homologyMap_shortComplexTruncLE_g e i' hi' apply isIso_of_mono_of_epi lemma quasiIsoAt_shortComplexTruncLE_g (i' : ι') (hi' : ∀ i, e.f i ≠ i') : QuasiIsoAt (K.shortComplexTruncLE e).g i' := by rw [quasiIsoAt_iff_isIso_homologyMap] exact K.isIso_homologyMap_shortComplexTruncLE_g e i' hi' lemma shortComplexTruncLE_X₃_isSupportedOutside : (K.shortComplexTruncLE e).X₃.IsSupportedOutside e where exactAt i := by rw [exactAt_iff_isZero_homology] by_cases hi : ∃ j', c'.Rel (e.f i) j' · obtain ⟨j', hj'⟩ := hi apply ((K.shortComplexTruncLE_shortExact e).homology_exact₃ (e.f i) j' hj').isZero_X₂ · rw [← cancel_epi (homologyMap (K.ιTruncLE e) (e.f i)), comp_zero] dsimp [shortComplexTruncLE] rw [← homologyMap_comp, cokernel.condition, homologyMap_zero] · simp · have : IsIso (homologyMap (K.shortComplexTruncLE e).f (e.f i)) := by dsimp; infer_instance rw [IsZero.iff_id_eq_zero, ← cancel_epi (homologyMap (K.shortComplexTruncLE e).g (e.f i)), comp_id, comp_zero, ← cancel_epi (homologyMap (K.shortComplexTruncLE e).f (e.f i)), comp_zero, ← homologyMap_comp, ShortComplex.zero, homologyMap_zero] end end HomologicalComplex
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/PreservesHomology.lean
import Mathlib.Algebra.Homology.ShortComplex.QuasiIso import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels /-! # Functors which preserves homology If `F : C ⥤ D` is a functor between categories with zero morphisms, we shall say that `F` preserves homology when `F` preserves both kernels and cokernels. This typeclass is named `[F.PreservesHomology]`, and is automatically satisfied when `F` preserves both finite limits and finite colimits. If `S : ShortComplex C` and `[F.PreservesHomology]`, then there is an isomorphism `S.mapHomologyIso F : (S.map F).homology ≅ F.obj S.homology`, which is part of the natural isomorphism `homologyFunctorIso F` between the functors `F.mapShortComplex ⋙ homologyFunctor D` and `homologyFunctor C ⋙ F`. -/ namespace CategoryTheory open Category Limits variable {C D : Type*} [Category C] [Category D] [HasZeroMorphisms C] [HasZeroMorphisms D] namespace Functor variable (F : C ⥤ D) /-- A functor preserves homology when it preserves both kernels and cokernels. -/ class PreservesHomology (F : C ⥤ D) [PreservesZeroMorphisms F] : Prop where /-- the functor preserves kernels -/ preservesKernels ⦃X Y : C⦄ (f : X ⟶ Y) : PreservesLimit (parallelPair f 0) F := by infer_instance /-- the functor preserves cokernels -/ preservesCokernels ⦃X Y : C⦄ (f : X ⟶ Y) : PreservesColimit (parallelPair f 0) F := by infer_instance variable [PreservesZeroMorphisms F] /-- A functor which preserves homology preserves kernels. -/ lemma PreservesHomology.preservesKernel [F.PreservesHomology] {X Y : C} (f : X ⟶ Y) : PreservesLimit (parallelPair f 0) F := PreservesHomology.preservesKernels _ /-- A functor which preserves homology preserves cokernels. -/ lemma PreservesHomology.preservesCokernel [F.PreservesHomology] {X Y : C} (f : X ⟶ Y) : PreservesColimit (parallelPair f 0) F := PreservesHomology.preservesCokernels _ noncomputable instance preservesHomologyOfExact [PreservesFiniteLimits F] [PreservesFiniteColimits F] : F.PreservesHomology where end Functor namespace ShortComplex variable {S S₁ S₂ : ShortComplex C} namespace LeftHomologyData variable (h : S.LeftHomologyData) (F : C ⥤ D) /-- A left homology data `h` of a short complex `S` is preserved by a functor `F` is `F` preserves the kernel of `S.g : S.X₂ ⟶ S.X₃` and the cokernel of `h.f' : S.X₁ ⟶ h.K`. -/ class IsPreservedBy [F.PreservesZeroMorphisms] : Prop where /-- the functor preserves the kernel of `S.g : S.X₂ ⟶ S.X₃`. -/ g : PreservesLimit (parallelPair S.g 0) F /-- the functor preserves the cokernel of `h.f' : S.X₁ ⟶ h.K`. -/ f' : PreservesColimit (parallelPair h.f' 0) F variable [F.PreservesZeroMorphisms] noncomputable instance isPreservedBy_of_preservesHomology [F.PreservesHomology] : h.IsPreservedBy F where g := Functor.PreservesHomology.preservesKernel _ _ f' := Functor.PreservesHomology.preservesCokernel _ _ variable [h.IsPreservedBy F] include h in /-- When a left homology data is preserved by a functor `F`, this functor preserves the kernel of `S.g : S.X₂ ⟶ S.X₃`. -/ lemma IsPreservedBy.hg : PreservesLimit (parallelPair S.g 0) F := @IsPreservedBy.g _ _ _ _ _ _ _ h F _ _ /-- When a left homology data `h` is preserved by a functor `F`, this functor preserves the cokernel of `h.f' : S.X₁ ⟶ h.K`. -/ lemma IsPreservedBy.hf' : PreservesColimit (parallelPair h.f' 0) F := IsPreservedBy.f' /-- When a left homology data `h` of a short complex `S` is preserved by a functor `F`, this is the induced left homology data `h.map F` for the short complex `S.map F`. -/ @[simps] noncomputable def map : (S.map F).LeftHomologyData := by have := IsPreservedBy.hg h F have := IsPreservedBy.hf' h F have wi : F.map h.i ≫ F.map S.g = 0 := by rw [← F.map_comp, h.wi, F.map_zero] have hi := KernelFork.mapIsLimit _ h.hi F let f' : F.obj S.X₁ ⟶ F.obj h.K := hi.lift (KernelFork.ofι (S.map F).f (S.map F).zero) have hf' : f' = F.map h.f' := Fork.IsLimit.hom_ext hi (by rw [Fork.IsLimit.lift_ι hi] simp only [KernelFork.map_ι, Fork.ι_ofι, map_f, ← F.map_comp, f'_i]) have wπ : f' ≫ F.map h.π = 0 := by rw [hf', ← F.map_comp, f'_π, F.map_zero] have hπ : IsColimit (CokernelCofork.ofπ (F.map h.π) wπ) := by let e : parallelPair f' 0 ≅ parallelPair (F.map h.f') 0 := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simpa using hf') (by simp) refine IsColimit.precomposeInvEquiv e _ (IsColimit.ofIsoColimit (CokernelCofork.mapIsColimit _ h.hπ' F) ?_) exact Cofork.ext (Iso.refl _) (by simp [e]) exact { K := F.obj h.K H := F.obj h.H i := F.map h.i π := F.map h.π wi := wi hi := hi wπ := wπ hπ := hπ } @[simp] lemma map_f' : (h.map F).f' = F.map h.f' := by rw [← cancel_mono (h.map F).i, f'_i, map_f, map_i, ← F.map_comp, f'_i] end LeftHomologyData /-- Given a left homology map data `ψ : LeftHomologyMapData φ h₁ h₂` such that both left homology data `h₁` and `h₂` are preserved by a functor `F`, this is the induced left homology map data for the morphism `F.mapShortComplex.map φ`. -/ @[simps] noncomputable def LeftHomologyMapData.map {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (ψ : LeftHomologyMapData φ h₁ h₂) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h₁.IsPreservedBy F] [h₂.IsPreservedBy F] : LeftHomologyMapData (F.mapShortComplex.map φ) (h₁.map F) (h₂.map F) where φK := F.map ψ.φK φH := F.map ψ.φH commi := by simpa only [F.map_comp] using F.congr_map ψ.commi commf' := by simpa only [LeftHomologyData.map_f', F.map_comp] using F.congr_map ψ.commf' commπ := by simpa only [F.map_comp] using F.congr_map ψ.commπ namespace RightHomologyData variable (h : S.RightHomologyData) (F : C ⥤ D) /-- A right homology data `h` of a short complex `S` is preserved by a functor `F` is `F` preserves the cokernel of `S.f : S.X₁ ⟶ S.X₂` and the kernel of `h.g' : h.Q ⟶ S.X₃`. -/ class IsPreservedBy [F.PreservesZeroMorphisms] : Prop where /-- the functor preserves the cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ f : PreservesColimit (parallelPair S.f 0) F /-- the functor preserves the kernel of `h.g' : h.Q ⟶ S.X₃`. -/ g' : PreservesLimit (parallelPair h.g' 0) F variable [F.PreservesZeroMorphisms] noncomputable instance isPreservedBy_of_preservesHomology [F.PreservesHomology] : h.IsPreservedBy F where f := Functor.PreservesHomology.preservesCokernel F _ g' := Functor.PreservesHomology.preservesKernel F _ variable [h.IsPreservedBy F] include h in /-- When a right homology data is preserved by a functor `F`, this functor preserves the cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ lemma IsPreservedBy.hf : PreservesColimit (parallelPair S.f 0) F := @IsPreservedBy.f _ _ _ _ _ _ _ h F _ _ /-- When a right homology data `h` is preserved by a functor `F`, this functor preserves the kernel of `h.g' : h.Q ⟶ S.X₃`. -/ lemma IsPreservedBy.hg' : PreservesLimit (parallelPair h.g' 0) F := @IsPreservedBy.g' _ _ _ _ _ _ _ h F _ _ /-- When a right homology data `h` of a short complex `S` is preserved by a functor `F`, this is the induced right homology data `h.map F` for the short complex `S.map F`. -/ @[simps] noncomputable def map : (S.map F).RightHomologyData := by have := IsPreservedBy.hf h F have := IsPreservedBy.hg' h F have wp : F.map S.f ≫ F.map h.p = 0 := by rw [← F.map_comp, h.wp, F.map_zero] have hp := CokernelCofork.mapIsColimit _ h.hp F let g' : F.obj h.Q ⟶ F.obj S.X₃ := hp.desc (CokernelCofork.ofπ (S.map F).g (S.map F).zero) have hg' : g' = F.map h.g' := by apply Cofork.IsColimit.hom_ext hp rw [Cofork.IsColimit.π_desc hp] simp only [Cofork.π_ofπ, CokernelCofork.map_π, map_g, ← F.map_comp, p_g'] have wι : F.map h.ι ≫ g' = 0 := by rw [hg', ← F.map_comp, ι_g', F.map_zero] have hι : IsLimit (KernelFork.ofι (F.map h.ι) wι) := by let e : parallelPair g' 0 ≅ parallelPair (F.map h.g') 0 := parallelPair.ext (Iso.refl _) (Iso.refl _) (by simpa using hg') (by simp) refine IsLimit.postcomposeHomEquiv e _ (IsLimit.ofIsoLimit (KernelFork.mapIsLimit _ h.hι' F) ?_) exact Fork.ext (Iso.refl _) (by simp [e]) exact { Q := F.obj h.Q H := F.obj h.H p := F.map h.p ι := F.map h.ι wp := wp hp := hp wι := wι hι := hι } @[simp] lemma map_g' : (h.map F).g' = F.map h.g' := by rw [← cancel_epi (h.map F).p, p_g', map_g, map_p, ← F.map_comp, p_g'] end RightHomologyData /-- Given a right homology map data `ψ : RightHomologyMapData φ h₁ h₂` such that both right homology data `h₁` and `h₂` are preserved by a functor `F`, this is the induced right homology map data for the morphism `F.mapShortComplex.map φ`. -/ @[simps] noncomputable def RightHomologyMapData.map {φ : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (ψ : RightHomologyMapData φ h₁ h₂) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h₁.IsPreservedBy F] [h₂.IsPreservedBy F] : RightHomologyMapData (F.mapShortComplex.map φ) (h₁.map F) (h₂.map F) where φQ := F.map ψ.φQ φH := F.map ψ.φH commp := by simpa only [F.map_comp] using F.congr_map ψ.commp commg' := by simpa only [RightHomologyData.map_g', F.map_comp] using F.congr_map ψ.commg' commι := by simpa only [F.map_comp] using F.congr_map ψ.commι /-- When a homology data `h` of a short complex `S` is such that both `h.left` and `h.right` are preserved by a functor `F`, this is the induced homology data `h.map F` for the short complex `S.map F`. -/ @[simps] noncomputable def HomologyData.map (h : S.HomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h.left.IsPreservedBy F] [h.right.IsPreservedBy F] : (S.map F).HomologyData where left := h.left.map F right := h.right.map F iso := F.mapIso h.iso comm := by simpa only [F.map_comp] using F.congr_map h.comm /-- Given a homology map data `ψ : HomologyMapData φ h₁ h₂` such that `h₁.left`, `h₁.right`, `h₂.left` and `h₂.right` are all preserved by a functor `F`, this is the induced homology map data for the morphism `F.mapShortComplex.map φ`. -/ @[simps] noncomputable def HomologyMapData.map {φ : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} (ψ : HomologyMapData φ h₁ h₂) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h₁.left.IsPreservedBy F] [h₁.right.IsPreservedBy F] [h₂.left.IsPreservedBy F] [h₂.right.IsPreservedBy F] : HomologyMapData (F.mapShortComplex.map φ) (h₁.map F) (h₂.map F) where left := ψ.left.map F right := ψ.right.map F lemma map_leftRightHomologyComparison' (F : C ⥤ D) [F.PreservesZeroMorphisms] (hₗ : S.LeftHomologyData) (hᵣ : S.RightHomologyData) [hₗ.IsPreservedBy F] [hᵣ.IsPreservedBy F] : F.map (leftRightHomologyComparison' hₗ hᵣ) = leftRightHomologyComparison' (hₗ.map F) (hᵣ.map F) := by apply Cofork.IsColimit.hom_ext (hₗ.map F).hπ apply Fork.IsLimit.hom_ext (hᵣ.map F).hι trans F.map (hₗ.i ≫ hᵣ.p) · simp [← Functor.map_comp] trans (hₗ.map F).π ≫ ShortComplex.leftRightHomologyComparison' (hₗ.map F) (hᵣ.map F) ≫ (hᵣ.map F).ι · rw [ShortComplex.π_leftRightHomologyComparison'_ι]; simp · simp end ShortComplex namespace Functor variable (F : C ⥤ D) [PreservesZeroMorphisms F] (S : ShortComplex C) {S₁ S₂ : ShortComplex C} /-- A functor preserves the left homology of a short complex `S` if it preserves all the left homology data of `S`. -/ class PreservesLeftHomologyOf : Prop where /-- the functor preserves all the left homology data of the short complex -/ isPreservedBy : ∀ (h : S.LeftHomologyData), h.IsPreservedBy F /-- A functor preserves the right homology of a short complex `S` if it preserves all the right homology data of `S`. -/ class PreservesRightHomologyOf : Prop where /-- the functor preserves all the right homology data of the short complex -/ isPreservedBy : ∀ (h : S.RightHomologyData), h.IsPreservedBy F instance PreservesHomology.preservesLeftHomologyOf [F.PreservesHomology] : F.PreservesLeftHomologyOf S := ⟨inferInstance⟩ instance PreservesHomology.preservesRightHomologyOf [F.PreservesHomology] : F.PreservesRightHomologyOf S := ⟨inferInstance⟩ variable {S} /-- If a functor preserves a certain left homology data of a short complex `S`, then it preserves the left homology of `S`. -/ lemma PreservesLeftHomologyOf.mk' (h : S.LeftHomologyData) [h.IsPreservedBy F] : F.PreservesLeftHomologyOf S where isPreservedBy h' := { g := ShortComplex.LeftHomologyData.IsPreservedBy.hg h F f' := by have := ShortComplex.LeftHomologyData.IsPreservedBy.hf' h F let e : parallelPair h.f' 0 ≅ parallelPair h'.f' 0 := parallelPair.ext (Iso.refl _) (ShortComplex.cyclesMapIso' (Iso.refl S) h h') (by simp) (by simp) exact preservesColimit_of_iso_diagram F e } /-- If a functor preserves a certain right homology data of a short complex `S`, then it preserves the right homology of `S`. -/ lemma PreservesRightHomologyOf.mk' (h : S.RightHomologyData) [h.IsPreservedBy F] : F.PreservesRightHomologyOf S where isPreservedBy h' := { f := ShortComplex.RightHomologyData.IsPreservedBy.hf h F g' := by have := ShortComplex.RightHomologyData.IsPreservedBy.hg' h F let e : parallelPair h.g' 0 ≅ parallelPair h'.g' 0 := parallelPair.ext (ShortComplex.opcyclesMapIso' (Iso.refl S) h h') (Iso.refl _) (by simp) (by simp) exact preservesLimit_of_iso_diagram F e } end Functor namespace ShortComplex variable {S : ShortComplex C} (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] instance LeftHomologyData.isPreservedBy_of_preserves [F.PreservesLeftHomologyOf S] : h₁.IsPreservedBy F := Functor.PreservesLeftHomologyOf.isPreservedBy _ instance RightHomologyData.isPreservedBy_of_preserves [F.PreservesRightHomologyOf S] : h₂.IsPreservedBy F := Functor.PreservesRightHomologyOf.isPreservedBy _ variable (S) instance hasLeftHomology_of_preserves [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (S.map F).HasLeftHomology := HasLeftHomology.mk' (S.leftHomologyData.map F) instance hasLeftHomology_of_preserves' [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (F.mapShortComplex.obj S).HasLeftHomology := by dsimp; infer_instance instance hasRightHomology_of_preserves [S.HasRightHomology] [F.PreservesRightHomologyOf S] : (S.map F).HasRightHomology := HasRightHomology.mk' (S.rightHomologyData.map F) instance hasRightHomology_of_preserves' [S.HasRightHomology] [F.PreservesRightHomologyOf S] : (F.mapShortComplex.obj S).HasRightHomology := by dsimp; infer_instance instance hasHomology_of_preserves [S.HasHomology] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] : (S.map F).HasHomology := HasHomology.mk' (S.homologyData.map F) instance hasHomology_of_preserves' [S.HasHomology] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] : (F.mapShortComplex.obj S).HasHomology := by dsimp; infer_instance section variable (hl : S.LeftHomologyData) (hr : S.RightHomologyData) {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) (hl₁ : S₁.LeftHomologyData) (hr₁ : S₁.RightHomologyData) (hl₂ : S₂.LeftHomologyData) (hr₂ : S₂.RightHomologyData) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] namespace LeftHomologyData variable [hl₁.IsPreservedBy F] [hl₂.IsPreservedBy F] lemma map_cyclesMap' : F.map (ShortComplex.cyclesMap' φ hl₁ hl₂) = ShortComplex.cyclesMap' (F.mapShortComplex.map φ) (hl₁.map F) (hl₂.map F) := by have γ : ShortComplex.LeftHomologyMapData φ hl₁ hl₂ := default rw [γ.cyclesMap'_eq, (γ.map F).cyclesMap'_eq, ShortComplex.LeftHomologyMapData.map_φK] lemma map_leftHomologyMap' : F.map (ShortComplex.leftHomologyMap' φ hl₁ hl₂) = ShortComplex.leftHomologyMap' (F.mapShortComplex.map φ) (hl₁.map F) (hl₂.map F) := by have γ : ShortComplex.LeftHomologyMapData φ hl₁ hl₂ := default rw [γ.leftHomologyMap'_eq, (γ.map F).leftHomologyMap'_eq, ShortComplex.LeftHomologyMapData.map_φH] end LeftHomologyData namespace RightHomologyData variable [hr₁.IsPreservedBy F] [hr₂.IsPreservedBy F] lemma map_opcyclesMap' : F.map (ShortComplex.opcyclesMap' φ hr₁ hr₂) = ShortComplex.opcyclesMap' (F.mapShortComplex.map φ) (hr₁.map F) (hr₂.map F) := by have γ : ShortComplex.RightHomologyMapData φ hr₁ hr₂ := default rw [γ.opcyclesMap'_eq, (γ.map F).opcyclesMap'_eq, ShortComplex.RightHomologyMapData.map_φQ] lemma map_rightHomologyMap' : F.map (ShortComplex.rightHomologyMap' φ hr₁ hr₂) = ShortComplex.rightHomologyMap' (F.mapShortComplex.map φ) (hr₁.map F) (hr₂.map F) := by have γ : ShortComplex.RightHomologyMapData φ hr₁ hr₂ := default rw [γ.rightHomologyMap'_eq, (γ.map F).rightHomologyMap'_eq, ShortComplex.RightHomologyMapData.map_φH] end RightHomologyData lemma HomologyData.map_homologyMap' [h₁.left.IsPreservedBy F] [h₁.right.IsPreservedBy F] [h₂.left.IsPreservedBy F] [h₂.right.IsPreservedBy F] : F.map (ShortComplex.homologyMap' φ h₁ h₂) = ShortComplex.homologyMap' (F.mapShortComplex.map φ) (h₁.map F) (h₂.map F) := LeftHomologyData.map_leftHomologyMap' _ _ _ _ /-- When a functor `F` preserves the left homology of a short complex `S`, this is the canonical isomorphism `(S.map F).cycles ≅ F.obj S.cycles`. -/ noncomputable def mapCyclesIso [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (S.map F).cycles ≅ F.obj S.cycles := (S.leftHomologyData.map F).cyclesIso @[reassoc (attr := simp)] lemma mapCyclesIso_hom_iCycles [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (S.mapCyclesIso F).hom ≫ F.map S.iCycles = (S.map F).iCycles := by apply LeftHomologyData.cyclesIso_hom_comp_i /-- When a functor `F` preserves the left homology of a short complex `S`, this is the canonical isomorphism `(S.map F).leftHomology ≅ F.obj S.leftHomology`. -/ noncomputable def mapLeftHomologyIso [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : (S.map F).leftHomology ≅ F.obj S.leftHomology := (S.leftHomologyData.map F).leftHomologyIso /-- When a functor `F` preserves the right homology of a short complex `S`, this is the canonical isomorphism `(S.map F).opcycles ≅ F.obj S.opcycles`. -/ noncomputable def mapOpcyclesIso [S.HasRightHomology] [F.PreservesRightHomologyOf S] : (S.map F).opcycles ≅ F.obj S.opcycles := (S.rightHomologyData.map F).opcyclesIso /-- When a functor `F` preserves the right homology of a short complex `S`, this is the canonical isomorphism `(S.map F).rightHomology ≅ F.obj S.rightHomology`. -/ noncomputable def mapRightHomologyIso [S.HasRightHomology] [F.PreservesRightHomologyOf S] : (S.map F).rightHomology ≅ F.obj S.rightHomology := (S.rightHomologyData.map F).rightHomologyIso /-- When a functor `F` preserves the left homology of a short complex `S`, this is the canonical isomorphism `(S.map F).homology ≅ F.obj S.homology`. -/ noncomputable def mapHomologyIso [S.HasHomology] [(S.map F).HasHomology] [F.PreservesLeftHomologyOf S] : (S.map F).homology ≅ F.obj S.homology := (S.homologyData.left.map F).homologyIso /-- When a functor `F` preserves the right homology of a short complex `S`, this is the canonical isomorphism `(S.map F).homology ≅ F.obj S.homology`. -/ noncomputable def mapHomologyIso' [S.HasHomology] [(S.map F).HasHomology] [F.PreservesRightHomologyOf S] : (S.map F).homology ≅ F.obj S.homology := (S.homologyData.right.map F).homologyIso ≪≫ F.mapIso S.homologyData.right.homologyIso.symm variable {S} lemma LeftHomologyData.mapCyclesIso_eq [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : S.mapCyclesIso F = (hl.map F).cyclesIso ≪≫ F.mapIso hl.cyclesIso.symm := by ext dsimp [mapCyclesIso, cyclesIso] simp only [map_cyclesMap', ← cyclesMap'_comp, Functor.map_id, comp_id, Functor.mapShortComplex_obj] lemma LeftHomologyData.mapLeftHomologyIso_eq [S.HasLeftHomology] [F.PreservesLeftHomologyOf S] : S.mapLeftHomologyIso F = (hl.map F).leftHomologyIso ≪≫ F.mapIso hl.leftHomologyIso.symm := by ext dsimp [mapLeftHomologyIso, leftHomologyIso] simp only [map_leftHomologyMap', ← leftHomologyMap'_comp, Functor.map_id, comp_id, Functor.mapShortComplex_obj] lemma RightHomologyData.mapOpcyclesIso_eq [S.HasRightHomology] [F.PreservesRightHomologyOf S] : S.mapOpcyclesIso F = (hr.map F).opcyclesIso ≪≫ F.mapIso hr.opcyclesIso.symm := by ext dsimp [mapOpcyclesIso, opcyclesIso] simp only [map_opcyclesMap', ← opcyclesMap'_comp, Functor.map_id, comp_id, Functor.mapShortComplex_obj] lemma RightHomologyData.mapRightHomologyIso_eq [S.HasRightHomology] [F.PreservesRightHomologyOf S] : S.mapRightHomologyIso F = (hr.map F).rightHomologyIso ≪≫ F.mapIso hr.rightHomologyIso.symm := by ext dsimp [mapRightHomologyIso, rightHomologyIso] simp only [map_rightHomologyMap', ← rightHomologyMap'_comp, Functor.map_id, comp_id, Functor.mapShortComplex_obj] lemma LeftHomologyData.mapHomologyIso_eq [S.HasHomology] [(S.map F).HasHomology] [F.PreservesLeftHomologyOf S] : S.mapHomologyIso F = (hl.map F).homologyIso ≪≫ F.mapIso hl.homologyIso.symm := by ext dsimp only [mapHomologyIso, homologyIso, ShortComplex.leftHomologyIso, leftHomologyMapIso', leftHomologyIso, Functor.mapIso, Iso.symm, Iso.trans, Iso.refl] simp only [map_leftHomologyMap', ← leftHomologyMap'_comp, comp_id, Functor.map_id, Functor.mapShortComplex_obj] lemma RightHomologyData.mapHomologyIso'_eq [S.HasHomology] [(S.map F).HasHomology] [F.PreservesRightHomologyOf S] : S.mapHomologyIso' F = (hr.map F).homologyIso ≪≫ F.mapIso hr.homologyIso.symm := by ext dsimp only [Iso.trans, Iso.symm, Iso.refl, Functor.mapIso, mapHomologyIso', homologyIso, rightHomologyIso, rightHomologyMapIso', ShortComplex.rightHomologyIso] simp only [assoc, F.map_comp, map_rightHomologyMap', ← rightHomologyMap'_comp_assoc] @[reassoc] lemma mapCyclesIso_hom_naturality [S₁.HasLeftHomology] [S₂.HasLeftHomology] [F.PreservesLeftHomologyOf S₁] [F.PreservesLeftHomologyOf S₂] : cyclesMap (F.mapShortComplex.map φ) ≫ (S₂.mapCyclesIso F).hom = (S₁.mapCyclesIso F).hom ≫ F.map (cyclesMap φ) := by dsimp only [cyclesMap, mapCyclesIso, LeftHomologyData.cyclesIso, cyclesMapIso', Iso.refl] simp only [LeftHomologyData.map_cyclesMap', Functor.mapShortComplex_obj, ← cyclesMap'_comp, comp_id, id_comp] @[reassoc] lemma mapCyclesIso_inv_naturality [S₁.HasLeftHomology] [S₂.HasLeftHomology] [F.PreservesLeftHomologyOf S₁] [F.PreservesLeftHomologyOf S₂] : F.map (cyclesMap φ) ≫ (S₂.mapCyclesIso F).inv = (S₁.mapCyclesIso F).inv ≫ cyclesMap (F.mapShortComplex.map φ) := by rw [← cancel_epi (S₁.mapCyclesIso F).hom, ← mapCyclesIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id, Iso.hom_inv_id_assoc] @[reassoc] lemma mapLeftHomologyIso_hom_naturality [S₁.HasLeftHomology] [S₂.HasLeftHomology] [F.PreservesLeftHomologyOf S₁] [F.PreservesLeftHomologyOf S₂] : leftHomologyMap (F.mapShortComplex.map φ) ≫ (S₂.mapLeftHomologyIso F).hom = (S₁.mapLeftHomologyIso F).hom ≫ F.map (leftHomologyMap φ) := by dsimp only [leftHomologyMap, mapLeftHomologyIso, LeftHomologyData.leftHomologyIso, leftHomologyMapIso', Iso.refl] simp only [LeftHomologyData.map_leftHomologyMap', Functor.mapShortComplex_obj, ← leftHomologyMap'_comp, comp_id, id_comp] @[reassoc] lemma mapLeftHomologyIso_inv_naturality [S₁.HasLeftHomology] [S₂.HasLeftHomology] [F.PreservesLeftHomologyOf S₁] [F.PreservesLeftHomologyOf S₂] : F.map (leftHomologyMap φ) ≫ (S₂.mapLeftHomologyIso F).inv = (S₁.mapLeftHomologyIso F).inv ≫ leftHomologyMap (F.mapShortComplex.map φ) := by rw [← cancel_epi (S₁.mapLeftHomologyIso F).hom, ← mapLeftHomologyIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id, Iso.hom_inv_id_assoc] @[reassoc] lemma mapOpcyclesIso_hom_naturality [S₁.HasRightHomology] [S₂.HasRightHomology] [F.PreservesRightHomologyOf S₁] [F.PreservesRightHomologyOf S₂] : opcyclesMap (F.mapShortComplex.map φ) ≫ (S₂.mapOpcyclesIso F).hom = (S₁.mapOpcyclesIso F).hom ≫ F.map (opcyclesMap φ) := by dsimp only [opcyclesMap, mapOpcyclesIso, RightHomologyData.opcyclesIso, opcyclesMapIso', Iso.refl] simp only [RightHomologyData.map_opcyclesMap', Functor.mapShortComplex_obj, ← opcyclesMap'_comp, comp_id, id_comp] @[reassoc] lemma mapOpcyclesIso_inv_naturality [S₁.HasRightHomology] [S₂.HasRightHomology] [F.PreservesRightHomologyOf S₁] [F.PreservesRightHomologyOf S₂] : F.map (opcyclesMap φ) ≫ (S₂.mapOpcyclesIso F).inv = (S₁.mapOpcyclesIso F).inv ≫ opcyclesMap (F.mapShortComplex.map φ) := by rw [← cancel_epi (S₁.mapOpcyclesIso F).hom, ← mapOpcyclesIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id, Iso.hom_inv_id_assoc] @[reassoc] lemma mapRightHomologyIso_hom_naturality [S₁.HasRightHomology] [S₂.HasRightHomology] [F.PreservesRightHomologyOf S₁] [F.PreservesRightHomologyOf S₂] : rightHomologyMap (F.mapShortComplex.map φ) ≫ (S₂.mapRightHomologyIso F).hom = (S₁.mapRightHomologyIso F).hom ≫ F.map (rightHomologyMap φ) := by dsimp only [rightHomologyMap, mapRightHomologyIso, RightHomologyData.rightHomologyIso, rightHomologyMapIso', Iso.refl] simp only [RightHomologyData.map_rightHomologyMap', Functor.mapShortComplex_obj, ← rightHomologyMap'_comp, comp_id, id_comp] @[reassoc] lemma mapRightHomologyIso_inv_naturality [S₁.HasRightHomology] [S₂.HasRightHomology] [F.PreservesRightHomologyOf S₁] [F.PreservesRightHomologyOf S₂] : F.map (rightHomologyMap φ) ≫ (S₂.mapRightHomologyIso F).inv = (S₁.mapRightHomologyIso F).inv ≫ rightHomologyMap (F.mapShortComplex.map φ) := by rw [← cancel_epi (S₁.mapRightHomologyIso F).hom, ← mapRightHomologyIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id, Iso.hom_inv_id_assoc] @[reassoc] lemma mapHomologyIso_hom_naturality [S₁.HasHomology] [S₂.HasHomology] [(S₁.map F).HasHomology] [(S₂.map F).HasHomology] [F.PreservesLeftHomologyOf S₁] [F.PreservesLeftHomologyOf S₂] : @homologyMap _ _ _ (S₁.map F) (S₂.map F) (F.mapShortComplex.map φ) _ _ ≫ (S₂.mapHomologyIso F).hom = (S₁.mapHomologyIso F).hom ≫ F.map (homologyMap φ) := by dsimp only [homologyMap, homologyMap', mapHomologyIso, LeftHomologyData.homologyIso, LeftHomologyData.leftHomologyIso, leftHomologyMapIso', leftHomologyIso, Iso.symm, Iso.trans, Iso.refl] simp only [LeftHomologyData.map_leftHomologyMap', ← leftHomologyMap'_comp, comp_id, id_comp] @[reassoc] lemma mapHomologyIso_inv_naturality [S₁.HasHomology] [S₂.HasHomology] [(S₁.map F).HasHomology] [(S₂.map F).HasHomology] [F.PreservesLeftHomologyOf S₁] [F.PreservesLeftHomologyOf S₂] : F.map (homologyMap φ) ≫ (S₂.mapHomologyIso F).inv = (S₁.mapHomologyIso F).inv ≫ @homologyMap _ _ _ (S₁.map F) (S₂.map F) (F.mapShortComplex.map φ) _ _ := by rw [← cancel_epi (S₁.mapHomologyIso F).hom, ← mapHomologyIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id, Iso.hom_inv_id_assoc] @[reassoc] lemma mapHomologyIso'_hom_naturality [S₁.HasHomology] [S₂.HasHomology] [(S₁.map F).HasHomology] [(S₂.map F).HasHomology] [F.PreservesRightHomologyOf S₁] [F.PreservesRightHomologyOf S₂] : @homologyMap _ _ _ (S₁.map F) (S₂.map F) (F.mapShortComplex.map φ) _ _ ≫ (S₂.mapHomologyIso' F).hom = (S₁.mapHomologyIso' F).hom ≫ F.map (homologyMap φ) := by dsimp only [Iso.trans, Iso.symm, Functor.mapIso, mapHomologyIso'] simp only [← RightHomologyData.rightHomologyIso_hom_naturality_assoc _ ((homologyData S₁).right.map F) ((homologyData S₂).right.map F), assoc, ← RightHomologyData.map_rightHomologyMap', ← F.map_comp, RightHomologyData.rightHomologyIso_inv_naturality _ (homologyData S₁).right (homologyData S₂).right] @[reassoc] lemma mapHomologyIso'_inv_naturality [S₁.HasHomology] [S₂.HasHomology] [(S₁.map F).HasHomology] [(S₂.map F).HasHomology] [F.PreservesRightHomologyOf S₁] [F.PreservesRightHomologyOf S₂] : F.map (homologyMap φ) ≫ (S₂.mapHomologyIso' F).inv = (S₁.mapHomologyIso' F).inv ≫ @homologyMap _ _ _ (S₁.map F) (S₂.map F) (F.mapShortComplex.map φ) _ _ := by rw [← cancel_epi (S₁.mapHomologyIso' F).hom, ← mapHomologyIso'_hom_naturality_assoc, Iso.hom_inv_id, comp_id, Iso.hom_inv_id_assoc] variable (S) lemma mapHomologyIso'_eq_mapHomologyIso [S.HasHomology] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] : S.mapHomologyIso' F = S.mapHomologyIso F := by ext rw [S.homologyData.left.mapHomologyIso_eq F, S.homologyData.right.mapHomologyIso'_eq F] dsimp only [Iso.trans, Iso.symm, Iso.refl, Functor.mapIso, RightHomologyData.homologyIso, rightHomologyIso, RightHomologyData.rightHomologyIso, LeftHomologyData.homologyIso, leftHomologyIso, LeftHomologyData.leftHomologyIso] simp only [RightHomologyData.map_H, rightHomologyMapIso'_inv, rightHomologyMapIso'_hom, assoc, Functor.map_comp, RightHomologyData.map_rightHomologyMap', Functor.mapShortComplex_obj, Functor.map_id, LeftHomologyData.map_H, leftHomologyMapIso'_inv, leftHomologyMapIso'_hom, LeftHomologyData.map_leftHomologyMap', ← rightHomologyMap'_comp_assoc, ← leftHomologyMap'_comp, id_comp] have γ : HomologyMapData (𝟙 (S.map F)) (map S F).homologyData (S.homologyData.map F) := default have eq := γ.comm rw [← γ.left.leftHomologyMap'_eq, ← γ.right.rightHomologyMap'_eq] at eq dsimp at eq simp only [← reassoc_of% eq, ← F.map_comp, Iso.hom_inv_id, F.map_id, comp_id] end section variable {S} {F G : C ⥤ D} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [G.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] [G.PreservesRightHomologyOf S] /-- Given a natural transformation `τ : F ⟶ G` between functors `C ⥤ D` which preserve the left homology of a short complex `S`, and a left homology data for `S`, this is the left homology map data for the morphism `S.mapNatTrans τ` obtained by evaluating `τ`. -/ @[simps] noncomputable def LeftHomologyMapData.natTransApp (h : LeftHomologyData S) (τ : F ⟶ G) : LeftHomologyMapData (S.mapNatTrans τ) (h.map F) (h.map G) where φK := τ.app h.K φH := τ.app h.H /-- Given a natural transformation `τ : F ⟶ G` between functors `C ⥤ D` which preserve the right homology of a short complex `S`, and a right homology data for `S`, this is the right homology map data for the morphism `S.mapNatTrans τ` obtained by evaluating `τ`. -/ @[simps] noncomputable def RightHomologyMapData.natTransApp (h : RightHomologyData S) (τ : F ⟶ G) : RightHomologyMapData (S.mapNatTrans τ) (h.map F) (h.map G) where φQ := τ.app h.Q φH := τ.app h.H /-- Given a natural transformation `τ : F ⟶ G` between functors `C ⥤ D` which preserve the homology of a short complex `S`, and a homology data for `S`, this is the homology map data for the morphism `S.mapNatTrans τ` obtained by evaluating `τ`. -/ @[simps] noncomputable def HomologyMapData.natTransApp (h : HomologyData S) (τ : F ⟶ G) : HomologyMapData (S.mapNatTrans τ) (h.map F) (h.map G) where left := LeftHomologyMapData.natTransApp h.left τ right := RightHomologyMapData.natTransApp h.right τ variable (S) lemma homologyMap_mapNatTrans [S.HasHomology] (τ : F ⟶ G) : homologyMap (S.mapNatTrans τ) = (S.mapHomologyIso F).hom ≫ τ.app S.homology ≫ (S.mapHomologyIso G).inv := (LeftHomologyMapData.natTransApp S.homologyData.left τ).homologyMap_eq end section variable [HasKernels C] [HasCokernels C] [HasKernels D] [HasCokernels D] /-- The natural isomorphism `F.mapShortComplex ⋙ cyclesFunctor D ≅ cyclesFunctor C ⋙ F` for a functor `F : C ⥤ D` which preserves homology. -/ noncomputable def cyclesFunctorIso [F.PreservesHomology] : F.mapShortComplex ⋙ ShortComplex.cyclesFunctor D ≅ ShortComplex.cyclesFunctor C ⋙ F := NatIso.ofComponents (fun S => S.mapCyclesIso F) (fun f => ShortComplex.mapCyclesIso_hom_naturality f F) /-- The natural isomorphism `F.mapShortComplex ⋙ leftHomologyFunctor D ≅ leftHomologyFunctor C ⋙ F` for a functor `F : C ⥤ D` which preserves homology. -/ noncomputable def leftHomologyFunctorIso [F.PreservesHomology] : F.mapShortComplex ⋙ ShortComplex.leftHomologyFunctor D ≅ ShortComplex.leftHomologyFunctor C ⋙ F := NatIso.ofComponents (fun S => S.mapLeftHomologyIso F) (fun f => ShortComplex.mapLeftHomologyIso_hom_naturality f F) /-- The natural isomorphism `F.mapShortComplex ⋙ opcyclesFunctor D ≅ opcyclesFunctor C ⋙ F` for a functor `F : C ⥤ D` which preserves homology. -/ noncomputable def opcyclesFunctorIso [F.PreservesHomology] : F.mapShortComplex ⋙ ShortComplex.opcyclesFunctor D ≅ ShortComplex.opcyclesFunctor C ⋙ F := NatIso.ofComponents (fun S => S.mapOpcyclesIso F) (fun f => ShortComplex.mapOpcyclesIso_hom_naturality f F) /-- The natural isomorphism `F.mapShortComplex ⋙ rightHomologyFunctor D ≅ rightHomologyFunctor C ⋙ F` for a functor `F : C ⥤ D` which preserves homology. -/ noncomputable def rightHomologyFunctorIso [F.PreservesHomology] : F.mapShortComplex ⋙ ShortComplex.rightHomologyFunctor D ≅ ShortComplex.rightHomologyFunctor C ⋙ F := NatIso.ofComponents (fun S => S.mapRightHomologyIso F) (fun f => ShortComplex.mapRightHomologyIso_hom_naturality f F) end /-- The natural isomorphism `F.mapShortComplex ⋙ homologyFunctor D ≅ homologyFunctor C ⋙ F` for a functor `F : C ⥤ D` which preserves homology. -/ noncomputable def homologyFunctorIso [CategoryWithHomology C] [CategoryWithHomology D] [F.PreservesHomology] : F.mapShortComplex ⋙ ShortComplex.homologyFunctor D ≅ ShortComplex.homologyFunctor C ⋙ F := NatIso.ofComponents (fun S => S.mapHomologyIso F) (fun f => ShortComplex.mapHomologyIso_hom_naturality f F) section variable {S₁ S₂ : ShortComplex C} {φ : S₁ ⟶ S₂} {hl₁ : S₁.LeftHomologyData} {hr₁ : S₁.RightHomologyData} {hl₂ : S₂.LeftHomologyData} {hr₂ : S₂.RightHomologyData} (ψl : LeftHomologyMapData φ hl₁ hl₂) (ψr : RightHomologyMapData φ hr₁ hr₂) lemma LeftHomologyMapData.quasiIso_map_iff [(F.mapShortComplex.obj S₁).HasHomology] [(F.mapShortComplex.obj S₂).HasHomology] [hl₁.IsPreservedBy F] [hl₂.IsPreservedBy F] : QuasiIso (F.mapShortComplex.map φ) ↔ IsIso (F.map ψl.φH) := (ψl.map F).quasiIso_iff lemma RightHomologyMapData.quasiIso_map_iff [(F.mapShortComplex.obj S₁).HasHomology] [(F.mapShortComplex.obj S₂).HasHomology] [hr₁.IsPreservedBy F] [hr₂.IsPreservedBy F] : QuasiIso (F.mapShortComplex.map φ) ↔ IsIso (F.map ψr.φH) := (ψr.map F).quasiIso_iff variable (φ) [S₁.HasHomology] [S₂.HasHomology] [(F.mapShortComplex.obj S₁).HasHomology] [(F.mapShortComplex.obj S₂).HasHomology] instance quasiIso_map_of_preservesLeftHomology [F.PreservesLeftHomologyOf S₁] [F.PreservesLeftHomologyOf S₂] [QuasiIso φ] : QuasiIso (F.mapShortComplex.map φ) := by have γ : LeftHomologyMapData φ S₁.leftHomologyData S₂.leftHomologyData := default have : IsIso γ.φH := by rw [← γ.quasiIso_iff] infer_instance rw [(γ.map F).quasiIso_iff, LeftHomologyMapData.map_φH] infer_instance lemma quasiIso_map_iff_of_preservesLeftHomology [F.PreservesLeftHomologyOf S₁] [F.PreservesLeftHomologyOf S₂] [F.ReflectsIsomorphisms] : QuasiIso (F.mapShortComplex.map φ) ↔ QuasiIso φ := by have γ : LeftHomologyMapData φ S₁.leftHomologyData S₂.leftHomologyData := default rw [γ.quasiIso_iff, (γ.map F).quasiIso_iff, LeftHomologyMapData.map_φH] constructor · intro exact isIso_of_reflects_iso _ F · intro infer_instance instance quasiIso_map_of_preservesRightHomology [F.PreservesRightHomologyOf S₁] [F.PreservesRightHomologyOf S₂] [QuasiIso φ] : QuasiIso (F.mapShortComplex.map φ) := by have γ : RightHomologyMapData φ S₁.rightHomologyData S₂.rightHomologyData := default have : IsIso γ.φH := by rw [← γ.quasiIso_iff] infer_instance rw [(γ.map F).quasiIso_iff, RightHomologyMapData.map_φH] infer_instance lemma quasiIso_map_iff_of_preservesRightHomology [F.PreservesRightHomologyOf S₁] [F.PreservesRightHomologyOf S₂] [F.ReflectsIsomorphisms] : QuasiIso (F.mapShortComplex.map φ) ↔ QuasiIso φ := by have γ : RightHomologyMapData φ S₁.rightHomologyData S₂.rightHomologyData := default rw [γ.quasiIso_iff, (γ.map F).quasiIso_iff, RightHomologyMapData.map_φH] constructor · intro exact isIso_of_reflects_iso _ F · intro infer_instance end end ShortComplex namespace Functor variable (F : C ⥤ D) [F.PreservesZeroMorphisms] (S : ShortComplex C) /-- If a short complex `S` is such that `S.f = 0` and that the kernel of `S.g` is preserved by a functor `F`, then `F` preserves the left homology of `S`. -/ lemma preservesLeftHomology_of_zero_f (hf : S.f = 0) [PreservesLimit (parallelPair S.g 0) F] : F.PreservesLeftHomologyOf S := ⟨fun h => { g := by infer_instance f' := Limits.preservesCokernel_zero' _ _ (by rw [← cancel_mono h.i, h.f'_i, zero_comp, hf]) }⟩ /-- If a short complex `S` is such that `S.g = 0` and that the cokernel of `S.f` is preserved by a functor `F`, then `F` preserves the right homology of `S`. -/ lemma preservesRightHomology_of_zero_g (hg : S.g = 0) [PreservesColimit (parallelPair S.f 0) F] : F.PreservesRightHomologyOf S := ⟨fun h => { f := by infer_instance g' := Limits.preservesKernel_zero' _ _ (by rw [← cancel_epi h.p, h.p_g', comp_zero, hg]) }⟩ /-- If a short complex `S` is such that `S.g = 0` and that the cokernel of `S.f` is preserved by a functor `F`, then `F` preserves the left homology of `S`. -/ lemma preservesLeftHomology_of_zero_g (hg : S.g = 0) [PreservesColimit (parallelPair S.f 0) F] : F.PreservesLeftHomologyOf S := ⟨fun h => { g := by rw [hg] infer_instance f' := by have := h.isIso_i hg let e : parallelPair h.f' 0 ≅ parallelPair S.f 0 := parallelPair.ext (Iso.refl _) (asIso h.i) (by simp) (by simp) exact Limits.preservesColimit_of_iso_diagram F e.symm}⟩ /-- If a short complex `S` is such that `S.f = 0` and that the kernel of `S.g` is preserved by a functor `F`, then `F` preserves the right homology of `S`. -/ lemma preservesRightHomology_of_zero_f (hf : S.f = 0) [PreservesLimit (parallelPair S.g 0) F] : F.PreservesRightHomologyOf S := ⟨fun h => { f := by rw [hf] infer_instance g' := by have := h.isIso_p hf let e : parallelPair S.g 0 ≅ parallelPair h.g' 0 := parallelPair.ext (asIso h.p) (Iso.refl _) (by simp) (by simp) exact Limits.preservesLimit_of_iso_diagram F e }⟩ end Functor lemma NatTrans.app_homology {F G : C ⥤ D} (τ : F ⟶ G) (S : ShortComplex C) [S.HasHomology] [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [G.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] [G.PreservesRightHomologyOf S] : τ.app S.homology = (S.mapHomologyIso F).inv ≫ ShortComplex.homologyMap (S.mapNatTrans τ) ≫ (S.mapHomologyIso G).hom := by rw [ShortComplex.homologyMap_mapNatTrans, assoc, assoc, Iso.inv_hom_id, comp_id, Iso.inv_hom_id_assoc] end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Retract.lean
import Mathlib.Algebra.Homology.ShortComplex.QuasiIso import Mathlib.CategoryTheory.MorphismProperty.Retract /-! # Quasi-isomorphisms of short complexes are stable under retracts -/ namespace CategoryTheory open Limits namespace ShortComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] {S₁ T₁ S₂ T₂ : ShortComplex C} [S₁.HasHomology] [T₁.HasHomology] [S₂.HasHomology] [T₂.HasHomology] {f₁ : S₁ ⟶ T₁} {f₂ : S₂ ⟶ T₂} lemma quasiIso_of_retract (h : RetractArrow f₁ f₂) [hf₂ : QuasiIso f₂] : QuasiIso f₁ := by rw [quasiIso_iff] at hf₂ ⊢ have h : RetractArrow (homologyMap f₁) (homologyMap f₂) := { i := Arrow.homMk (u := homologyMap (show S₁ ⟶ S₂ from h.i.left)) (v := homologyMap (show T₁ ⟶ T₂ from h.i.right)) (by simp [← homologyMap_comp]) r := Arrow.homMk (u := homologyMap (show S₂ ⟶ S₁ from h.r.left)) (v := homologyMap (show T₂ ⟶ T₁ from h.r.right)) (by simp [← homologyMap_comp]) retract := by ext <;> simp [← homologyMap_comp] } exact (MorphismProperty.isomorphisms C).of_retract h hf₂ end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/QuasiIso.lean
import Mathlib.Algebra.Homology.ShortComplex.Homology /-! # Quasi-isomorphisms of short complexes This file introduces the typeclass `QuasiIso φ` for a morphism `φ : S₁ ⟶ S₂` of short complexes (which have homology): the condition is that the induced morphism `homologyMap φ` in homology is an isomorphism. -/ namespace CategoryTheory open Category Limits namespace ShortComplex variable {C : Type _} [Category C] [HasZeroMorphisms C] {S₁ S₂ S₃ S₄ : ShortComplex C} [S₁.HasHomology] [S₂.HasHomology] [S₃.HasHomology] [S₄.HasHomology] /-- A morphism `φ : S₁ ⟶ S₂` of short complexes that have homology is a quasi-isomorphism if the induced map `homologyMap φ : S₁.homology ⟶ S₂.homology` is an isomorphism. -/ class QuasiIso (φ : S₁ ⟶ S₂) : Prop where /-- the homology map is an isomorphism -/ isIso' : IsIso (homologyMap φ) instance QuasiIso.isIso (φ : S₁ ⟶ S₂) [QuasiIso φ] : IsIso (homologyMap φ) := QuasiIso.isIso' lemma quasiIso_iff (φ : S₁ ⟶ S₂) : QuasiIso φ ↔ IsIso (homologyMap φ) := by constructor · intro h infer_instance · intro h exact ⟨h⟩ instance quasiIso_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ] : QuasiIso φ := ⟨(homologyMapIso (asIso φ)).isIso_hom⟩ instance quasiIso_comp (φ : S₁ ⟶ S₂) (φ' : S₂ ⟶ S₃) [hφ : QuasiIso φ] [hφ' : QuasiIso φ'] : QuasiIso (φ ≫ φ') := by rw [quasiIso_iff] at hφ hφ' ⊢ rw [homologyMap_comp] infer_instance lemma quasiIso_of_comp_left (φ : S₁ ⟶ S₂) (φ' : S₂ ⟶ S₃) [hφ : QuasiIso φ] [hφφ' : QuasiIso (φ ≫ φ')] : QuasiIso φ' := by rw [quasiIso_iff] at hφ hφφ' ⊢ rw [homologyMap_comp] at hφφ' exact IsIso.of_isIso_comp_left (homologyMap φ) (homologyMap φ') lemma quasiIso_iff_comp_left (φ : S₁ ⟶ S₂) (φ' : S₂ ⟶ S₃) [hφ : QuasiIso φ] : QuasiIso (φ ≫ φ') ↔ QuasiIso φ' := by constructor · intro exact quasiIso_of_comp_left φ φ' · intro exact quasiIso_comp φ φ' lemma quasiIso_of_comp_right (φ : S₁ ⟶ S₂) (φ' : S₂ ⟶ S₃) [hφ' : QuasiIso φ'] [hφφ' : QuasiIso (φ ≫ φ')] : QuasiIso φ := by rw [quasiIso_iff] at hφ' hφφ' ⊢ rw [homologyMap_comp] at hφφ' exact IsIso.of_isIso_comp_right (homologyMap φ) (homologyMap φ') lemma quasiIso_iff_comp_right (φ : S₁ ⟶ S₂) (φ' : S₂ ⟶ S₃) [hφ' : QuasiIso φ'] : QuasiIso (φ ≫ φ') ↔ QuasiIso φ := by constructor · intro exact quasiIso_of_comp_right φ φ' · intro exact quasiIso_comp φ φ' lemma quasiIso_of_arrow_mk_iso (φ : S₁ ⟶ S₂) (φ' : S₃ ⟶ S₄) (e : Arrow.mk φ ≅ Arrow.mk φ') [hφ : QuasiIso φ] : QuasiIso φ' := by let α : S₃ ⟶ S₁ := e.inv.left let β : S₂ ⟶ S₄ := e.hom.right suffices φ' = α ≫ φ ≫ β by rw [this] infer_instance simp only [α, β, Arrow.w_mk_right_assoc, Arrow.mk_left, Arrow.mk_right, Arrow.mk_hom, ← Arrow.comp_right, e.inv_hom_id, Arrow.id_right, comp_id] lemma quasiIso_iff_of_arrow_mk_iso (φ : S₁ ⟶ S₂) (φ' : S₃ ⟶ S₄) (e : Arrow.mk φ ≅ Arrow.mk φ') : QuasiIso φ ↔ QuasiIso φ' := ⟨fun _ => quasiIso_of_arrow_mk_iso φ φ' e, fun _ => quasiIso_of_arrow_mk_iso φ' φ e.symm⟩ lemma LeftHomologyMapData.quasiIso_iff {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (γ : LeftHomologyMapData φ h₁ h₂) : QuasiIso φ ↔ IsIso γ.φH := by rw [ShortComplex.quasiIso_iff, γ.homologyMap_eq] constructor · intro h haveI : IsIso (γ.φH ≫ (LeftHomologyData.homologyIso h₂).inv) := IsIso.of_isIso_comp_left (LeftHomologyData.homologyIso h₁).hom _ exact IsIso.of_isIso_comp_right _ (LeftHomologyData.homologyIso h₂).inv · intro h infer_instance lemma RightHomologyMapData.quasiIso_iff {φ : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (γ : RightHomologyMapData φ h₁ h₂) : QuasiIso φ ↔ IsIso γ.φH := by rw [ShortComplex.quasiIso_iff, γ.homologyMap_eq] constructor · intro h haveI : IsIso (γ.φH ≫ (RightHomologyData.homologyIso h₂).inv) := IsIso.of_isIso_comp_left (RightHomologyData.homologyIso h₁).hom _ exact IsIso.of_isIso_comp_right _ (RightHomologyData.homologyIso h₂).inv · intro h infer_instance lemma quasiIso_iff_isIso_leftHomologyMap' (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : QuasiIso φ ↔ IsIso (leftHomologyMap' φ h₁ h₂) := by have γ : LeftHomologyMapData φ h₁ h₂ := default rw [γ.quasiIso_iff, γ.leftHomologyMap'_eq] lemma quasiIso_iff_isIso_rightHomologyMap' (φ : S₁ ⟶ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : QuasiIso φ ↔ IsIso (rightHomologyMap' φ h₁ h₂) := by have γ : RightHomologyMapData φ h₁ h₂ := default rw [γ.quasiIso_iff, γ.rightHomologyMap'_eq] lemma quasiIso_iff_isIso_homologyMap' (φ : S₁ ⟶ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : QuasiIso φ ↔ IsIso (homologyMap' φ h₁ h₂) := quasiIso_iff_isIso_leftHomologyMap' _ _ _ lemma quasiIso_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : QuasiIso φ := by rw [((LeftHomologyMapData.ofEpiOfIsIsoOfMono φ) S₁.leftHomologyData).quasiIso_iff] dsimp infer_instance lemma quasiIso_opMap_iff (φ : S₁ ⟶ S₂) : QuasiIso (opMap φ) ↔ QuasiIso φ := by have γ : HomologyMapData φ S₁.homologyData S₂.homologyData := default rw [γ.left.quasiIso_iff, γ.op.right.quasiIso_iff] dsimp constructor · intro h apply isIso_of_op · intro h infer_instance lemma quasiIso_opMap (φ : S₁ ⟶ S₂) [QuasiIso φ] : QuasiIso (opMap φ) := by rw [quasiIso_opMap_iff] infer_instance lemma quasiIso_unopMap {S₁ S₂ : ShortComplex Cᵒᵖ} [S₁.HasHomology] [S₂.HasHomology] [S₁.unop.HasHomology] [S₂.unop.HasHomology] (φ : S₁ ⟶ S₂) [QuasiIso φ] : QuasiIso (unopMap φ) := by rw [← quasiIso_opMap_iff] change QuasiIso φ infer_instance lemma quasiIso_iff_isIso_liftCycles (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) : QuasiIso φ ↔ IsIso (S₂.liftCycles φ.τ₂ (by rw [φ.comm₂₃, hg₁, zero_comp])) := by let H : LeftHomologyMapData φ (LeftHomologyData.ofZeros S₁ hf₁ hg₁) (LeftHomologyData.ofIsLimitKernelFork S₂ hf₂ _ S₂.cyclesIsKernel) := { φK := S₂.liftCycles φ.τ₂ (by rw [φ.comm₂₃, hg₁, zero_comp]) φH := S₂.liftCycles φ.τ₂ (by rw [φ.comm₂₃, hg₁, zero_comp]) } exact H.quasiIso_iff lemma quasiIso_iff_isIso_descOpcycles (φ : S₁ ⟶ S₂) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) (hg₂ : S₂.g = 0) : QuasiIso φ ↔ IsIso (S₁.descOpcycles φ.τ₂ (by rw [← φ.comm₁₂, hf₂, comp_zero])) := by let H : RightHomologyMapData φ (RightHomologyData.ofIsColimitCokernelCofork S₁ hg₁ _ S₁.opcyclesIsCokernel) (RightHomologyData.ofZeros S₂ hf₂ hg₂) := { φQ := S₁.descOpcycles φ.τ₂ (by rw [← φ.comm₁₂, hf₂, comp_zero]) φH := S₁.descOpcycles φ.τ₂ (by rw [← φ.comm₁₂, hf₂, comp_zero]) } exact H.quasiIso_iff end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/HomologicalComplex.lean
import Mathlib.Algebra.Homology.Additive import Mathlib.Algebra.Homology.ShortComplex.Exact import Mathlib.Algebra.Homology.ShortComplex.Preadditive import Mathlib.Tactic.Linarith /-! # The short complexes attached to homological complexes In this file, we define a functor `shortComplexFunctor C c i : HomologicalComplex C c ⥤ ShortComplex C`. By definition, the image of a homological complex `K` by this functor is the short complex `K.X (c.prev i) ⟶ K.X i ⟶ K.X (c.next i)`. The homology `K.homology i` of a homological complex `K` in degree `i` is defined as the homology of the short complex `(shortComplexFunctor C c i).obj K`, which can be abbreviated as `K.sc i`. -/ open CategoryTheory Category Limits namespace HomologicalComplex variable (C : Type*) [Category C] [HasZeroMorphisms C] {ι : Type*} (c : ComplexShape ι) /-- The functor `HomologicalComplex C c ⥤ ShortComplex C` which sends a homological complex `K` to the short complex `K.X i ⟶ K.X j ⟶ K.X k` for arbitrary indices `i`, `j` and `k`. -/ @[simps] def shortComplexFunctor' (i j k : ι) : HomologicalComplex C c ⥤ ShortComplex C where obj K := ShortComplex.mk (K.d i j) (K.d j k) (K.d_comp_d i j k) map f := { τ₁ := f.f i τ₂ := f.f j τ₃ := f.f k } /-- The functor `HomologicalComplex C c ⥤ ShortComplex C` which sends a homological complex `K` to the short complex `K.X (c.prev i) ⟶ K.X i ⟶ K.X (c.next i)`. -/ @[simps!] noncomputable def shortComplexFunctor (i : ι) := shortComplexFunctor' C c (c.prev i) i (c.next i) /-- The natural isomorphism `shortComplexFunctor C c j ≅ shortComplexFunctor' C c i j k` when `c.prev j = i` and `c.next j = k`. -/ @[simps!] noncomputable def natIsoSc' (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) : shortComplexFunctor C c j ≅ shortComplexFunctor' C c i j k := NatIso.ofComponents (fun K => ShortComplex.isoMk (K.XIsoOfEq hi) (Iso.refl _) (K.XIsoOfEq hk) (by simp) (by simp)) (by cat_disch) variable {C c} variable (K L M : HomologicalComplex C c) (φ : K ⟶ L) (iso : K ≅ L) (ψ : L ⟶ M) (i j k : ι) /-- The short complex `K.X i ⟶ K.X j ⟶ K.X k` for arbitrary indices `i`, `j` and `k`. -/ abbrev sc' := (shortComplexFunctor' C c i j k).obj K /-- The short complex `K.X (c.prev i) ⟶ K.X i ⟶ K.X (c.next i)`. -/ noncomputable abbrev sc := (shortComplexFunctor C c i).obj K /-- The canonical isomorphism `K.sc j ≅ K.sc' i j k` when `c.prev j = i` and `c.next j = k`. -/ noncomputable abbrev isoSc' (hi : c.prev j = i) (hk : c.next j = k) : K.sc j ≅ K.sc' i j k := (natIsoSc' C c i j k hi hk).app K /-- A homological complex `K` has homology in degree `i` if the associated short complex `K.sc i` has. -/ abbrev HasHomology := (K.sc i).HasHomology variable {K L} in include iso in lemma hasHomology_of_iso [K.HasHomology i] : L.HasHomology i := ShortComplex.hasHomology_of_iso ((shortComplexFunctor _ _ i).mapIso iso : K.sc i ≅ L.sc i) section variable [K.HasHomology i] /-- The homology in degree `i` of a homological complex. -/ noncomputable def homology := (K.sc i).homology /-- The cycles in degree `i` of a homological complex. -/ noncomputable def cycles := (K.sc i).cycles /-- The inclusion of the cycles of a homological complex. -/ noncomputable def iCycles : K.cycles i ⟶ K.X i := (K.sc i).iCycles /-- The homology class map from cycles to the homology of a homological complex. -/ noncomputable def homologyπ : K.cycles i ⟶ K.homology i := (K.sc i).homologyπ variable {i} /-- The morphism to `K.cycles i` that is induced by a "cycle", i.e. a morphism to `K.X i` whose postcomposition with the differential is zero. -/ noncomputable def liftCycles {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j) (hk : k ≫ K.d i j = 0) : A ⟶ K.cycles i := (K.sc i).liftCycles k (by subst hj; exact hk) /-- The morphism to `K.cycles i` that is induced by a "cycle", i.e. a morphism to `K.X i` whose postcomposition with the differential is zero. -/ noncomputable abbrev liftCycles' {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.Rel i j) (hk : k ≫ K.d i j = 0) : A ⟶ K.cycles i := K.liftCycles k j (c.next_eq' hj) hk @[reassoc (attr := simp)] lemma liftCycles_i {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j) (hk : k ≫ K.d i j = 0) : K.liftCycles k j hj hk ≫ K.iCycles i = k := by dsimp [liftCycles, iCycles] simp variable (i) /-- The map `K.X i ⟶ K.cycles j` induced by the differential `K.d i j`. -/ noncomputable def toCycles [K.HasHomology j] : K.X i ⟶ K.cycles j := K.liftCycles (K.d i j) (c.next j) rfl (K.d_comp_d _ _ _) @[reassoc (attr := simp)] lemma iCycles_d : K.iCycles i ≫ K.d i j = 0 := by by_cases hij : c.Rel i j · obtain rfl := c.next_eq' hij exact (K.sc i).iCycles_g · rw [K.shape _ _ hij, comp_zero] /-- `K.cycles i` is the kernel of `K.d i j` when `c.next i = j`. -/ noncomputable def cyclesIsKernel (hj : c.next i = j) : IsLimit (KernelFork.ofι (K.iCycles i) (K.iCycles_d i j)) := by obtain rfl := hj exact (K.sc i).cyclesIsKernel end @[reassoc (attr := simp)] lemma toCycles_i [K.HasHomology j] : K.toCycles i j ≫ K.iCycles j = K.d i j := liftCycles_i _ _ _ _ _ section variable [K.HasHomology i] instance : Mono (K.iCycles i) := by dsimp only [iCycles] infer_instance instance : Epi (K.homologyπ i) := by dsimp only [homologyπ] infer_instance end @[reassoc (attr := simp)] lemma d_toCycles [K.HasHomology k] : K.d i j ≫ K.toCycles j k = 0 := by simp only [← cancel_mono (K.iCycles k), assoc, toCycles_i, d_comp_d, zero_comp] variable {i j} in lemma toCycles_eq_zero [K.HasHomology j] (hij : ¬ c.Rel i j) : K.toCycles i j = 0 := by rw [← cancel_mono (K.iCycles j), toCycles_i, zero_comp, K.shape _ _ hij] variable {i} section variable [K.HasHomology i] @[reassoc] lemma comp_liftCycles {A' A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j) (hk : k ≫ K.d i j = 0) (α : A' ⟶ A) : α ≫ K.liftCycles k j hj hk = K.liftCycles (α ≫ k) j hj (by rw [assoc, hk, comp_zero]) := by simp only [← cancel_mono (K.iCycles i), assoc, liftCycles_i] @[reassoc] lemma liftCycles_homologyπ_eq_zero_of_boundary {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j) {i' : ι} (x : A ⟶ K.X i') (hx : k = x ≫ K.d i' i) : K.liftCycles k j hj (by rw [hx, assoc, K.d_comp_d, comp_zero]) ≫ K.homologyπ i = 0 := by by_cases h : c.Rel i' i · obtain rfl := c.prev_eq' h exact (K.sc i).liftCycles_homologyπ_eq_zero_of_boundary _ x hx · have : liftCycles K k j hj (by rw [hx, assoc, K.d_comp_d, comp_zero]) = 0 := by rw [K.shape _ _ h, comp_zero] at hx rw [← cancel_mono (K.iCycles i), zero_comp, liftCycles_i, hx] rw [this, zero_comp] end variable (i) @[reassoc (attr := simp)] lemma toCycles_comp_homologyπ [K.HasHomology j] : K.toCycles i j ≫ K.homologyπ j = 0 := K.liftCycles_homologyπ_eq_zero_of_boundary (K.d i j) (c.next j) rfl (𝟙 _) (by simp) /-- `K.homology j` is the cokernel of `K.toCycles i j : K.X i ⟶ K.cycles j` when `c.prev j = i`. -/ noncomputable def homologyIsCokernel (hi : c.prev j = i) [K.HasHomology j] : IsColimit (CokernelCofork.ofπ (K.homologyπ j) (K.toCycles_comp_homologyπ i j)) := by subst hi exact (K.sc j).homologyIsCokernel section variable [K.HasHomology i] /-- The opcycles in degree `i` of a homological complex. -/ noncomputable def opcycles := (K.sc i).opcycles /-- The projection to the opcycles of a homological complex. -/ noncomputable def pOpcycles : K.X i ⟶ K.opcycles i := (K.sc i).pOpcycles /-- The inclusion map of the homology of a homological complex into its opcycles. -/ noncomputable def homologyι : K.homology i ⟶ K.opcycles i := (K.sc i).homologyι variable {i} /-- The morphism from `K.opcycles i` that is induced by an "opcycle", i.e. a morphism from `K.X i` whose precomposition with the differential is zero. -/ noncomputable def descOpcycles {A : C} (k : K.X i ⟶ A) (j : ι) (hj : c.prev i = j) (hk : K.d j i ≫ k = 0) : K.opcycles i ⟶ A := (K.sc i).descOpcycles k (by subst hj; exact hk) /-- The morphism from `K.opcycles i` that is induced by an "opcycle", i.e. a morphism from `K.X i` whose precomposition with the differential is zero. -/ noncomputable abbrev descOpcycles' {A : C} (k : K.X i ⟶ A) (j : ι) (hj : c.Rel j i) (hk : K.d j i ≫ k = 0) : K.opcycles i ⟶ A := K.descOpcycles k j (c.prev_eq' hj) hk @[reassoc (attr := simp)] lemma p_descOpcycles {A : C} (k : K.X i ⟶ A) (j : ι) (hj : c.prev i = j) (hk : K.d j i ≫ k = 0) : K.pOpcycles i ≫ K.descOpcycles k j hj hk = k := by dsimp [descOpcycles, pOpcycles] simp variable (i) /-- The map `K.opcycles i ⟶ K.X j` induced by the differential `K.d i j`. -/ noncomputable def fromOpcycles : K.opcycles i ⟶ K.X j := K.descOpcycles (K.d i j) (c.prev i) rfl (K.d_comp_d _ _ _) omit [K.HasHomology i] in @[reassoc (attr := simp)] lemma d_pOpcycles [K.HasHomology j] : K.d i j ≫ K.pOpcycles j = 0 := by by_cases hij : c.Rel i j · obtain rfl := c.prev_eq' hij exact (K.sc j).f_pOpcycles · rw [K.shape _ _ hij, zero_comp] /-- `K.opcycles j` is the cokernel of `K.d i j` when `c.prev j = i`. -/ noncomputable def opcyclesIsCokernel (hi : c.prev j = i) [K.HasHomology j] : IsColimit (CokernelCofork.ofπ (K.pOpcycles j) (K.d_pOpcycles i j)) := by obtain rfl := hi exact (K.sc j).opcyclesIsCokernel @[reassoc (attr := simp)] lemma p_fromOpcycles : K.pOpcycles i ≫ K.fromOpcycles i j = K.d i j := p_descOpcycles _ _ _ _ _ instance : Epi (K.pOpcycles i) := by dsimp only [pOpcycles] infer_instance instance : Mono (K.homologyι i) := by dsimp only [homologyι] infer_instance @[reassoc (attr := simp)] lemma fromOpcycles_d : K.fromOpcycles i j ≫ K.d j k = 0 := by simp only [← cancel_epi (K.pOpcycles i), p_fromOpcycles_assoc, d_comp_d, comp_zero] variable {i j} in lemma fromOpcycles_eq_zero (hij : ¬ c.Rel i j) : K.fromOpcycles i j = 0 := by rw [← cancel_epi (K.pOpcycles i), p_fromOpcycles, comp_zero, K.shape _ _ hij] variable {i} @[reassoc] lemma descOpcycles_comp {A A' : C} (k : K.X i ⟶ A) (j : ι) (hj : c.prev i = j) (hk : K.d j i ≫ k = 0) (α : A ⟶ A') : K.descOpcycles k j hj hk ≫ α = K.descOpcycles (k ≫ α) j hj (by rw [reassoc_of% hk, zero_comp]) := by simp only [← cancel_epi (K.pOpcycles i), p_descOpcycles_assoc, p_descOpcycles] @[reassoc] lemma homologyι_descOpcycles_eq_zero_of_boundary {A : C} (k : K.X i ⟶ A) (j : ι) (hj : c.prev i = j) {i' : ι} (x : K.X i' ⟶ A) (hx : k = K.d i i' ≫ x) : K.homologyι i ≫ K.descOpcycles k j hj (by rw [hx, K.d_comp_d_assoc, zero_comp]) = 0 := by by_cases h : c.Rel i i' · obtain rfl := c.next_eq' h exact (K.sc i).homologyι_descOpcycles_eq_zero_of_boundary _ x hx · have : K.descOpcycles k j hj (by rw [hx, K.d_comp_d_assoc, zero_comp]) = 0 := by rw [K.shape _ _ h, zero_comp] at hx rw [← cancel_epi (K.pOpcycles i), comp_zero, p_descOpcycles, hx] rw [this, comp_zero] variable (i) @[reassoc (attr := simp)] lemma homologyι_comp_fromOpcycles : K.homologyι i ≫ K.fromOpcycles i j = 0 := K.homologyι_descOpcycles_eq_zero_of_boundary (K.d i j) _ rfl (𝟙 _) (by simp) /-- `K.homology i` is the kernel of `K.fromOpcycles i j : K.opcycles i ⟶ K.X j` when `c.next i = j`. -/ noncomputable def homologyIsKernel (hi : c.next i = j) : IsLimit (KernelFork.ofι (K.homologyι i) (K.homologyι_comp_fromOpcycles i j)) := by subst hi exact (K.sc i).homologyIsKernel variable {K L M} variable [L.HasHomology i] [M.HasHomology i] /-- The map `K.homology i ⟶ L.homology i` induced by a morphism in `HomologicalComplex`. -/ noncomputable def homologyMap : K.homology i ⟶ L.homology i := ShortComplex.homologyMap ((shortComplexFunctor C c i).map φ) /-- The map `K.cycles i ⟶ L.cycles i` induced by a morphism in `HomologicalComplex`. -/ noncomputable def cyclesMap : K.cycles i ⟶ L.cycles i := ShortComplex.cyclesMap ((shortComplexFunctor C c i).map φ) /-- The map `K.opcycles i ⟶ L.opcycles i` induced by a morphism in `HomologicalComplex`. -/ noncomputable def opcyclesMap : K.opcycles i ⟶ L.opcycles i := ShortComplex.opcyclesMap ((shortComplexFunctor C c i).map φ) @[reassoc (attr := simp)] lemma cyclesMap_i : cyclesMap φ i ≫ L.iCycles i = K.iCycles i ≫ φ.f i := ShortComplex.cyclesMap_i _ @[reassoc (attr := simp)] lemma p_opcyclesMap : K.pOpcycles i ≫ opcyclesMap φ i = φ.f i ≫ L.pOpcycles i := ShortComplex.p_opcyclesMap _ instance [Mono (φ.f i)] : Mono (cyclesMap φ i) := mono_of_mono_fac (cyclesMap_i φ i) instance [Epi (φ.f i)] : Epi (opcyclesMap φ i) := epi_of_epi_fac (p_opcyclesMap φ i) variable (K) @[simp] lemma homologyMap_id : homologyMap (𝟙 K) i = 𝟙 _ := ShortComplex.homologyMap_id _ @[simp] lemma cyclesMap_id : cyclesMap (𝟙 K) i = 𝟙 _ := ShortComplex.cyclesMap_id _ @[simp] lemma opcyclesMap_id : opcyclesMap (𝟙 K) i = 𝟙 _ := ShortComplex.opcyclesMap_id _ variable {K} @[reassoc] lemma homologyMap_comp : homologyMap (φ ≫ ψ) i = homologyMap φ i ≫ homologyMap ψ i := by dsimp [homologyMap] rw [Functor.map_comp, ShortComplex.homologyMap_comp] @[reassoc] lemma cyclesMap_comp : cyclesMap (φ ≫ ψ) i = cyclesMap φ i ≫ cyclesMap ψ i := by dsimp [cyclesMap] rw [Functor.map_comp, ShortComplex.cyclesMap_comp] @[reassoc] lemma opcyclesMap_comp : opcyclesMap (φ ≫ ψ) i = opcyclesMap φ i ≫ opcyclesMap ψ i := by dsimp [opcyclesMap] rw [Functor.map_comp, ShortComplex.opcyclesMap_comp] variable (K L) @[simp] lemma homologyMap_zero : homologyMap (0 : K ⟶ L) i = 0 := ShortComplex.homologyMap_zero _ _ @[simp] lemma cyclesMap_zero : cyclesMap (0 : K ⟶ L) i = 0 := ShortComplex.cyclesMap_zero _ _ @[simp] lemma opcyclesMap_zero : opcyclesMap (0 : K ⟶ L) i = 0 := ShortComplex.opcyclesMap_zero _ _ variable {K L} @[reassoc (attr := simp)] lemma homologyπ_naturality : K.homologyπ i ≫ homologyMap φ i = cyclesMap φ i ≫ L.homologyπ i := ShortComplex.homologyπ_naturality _ @[reassoc (attr := simp)] lemma homologyι_naturality : homologyMap φ i ≫ L.homologyι i = K.homologyι i ≫ opcyclesMap φ i := ShortComplex.homologyι_naturality _ @[reassoc (attr := simp)] lemma homology_π_ι : K.homologyπ i ≫ K.homologyι i = K.iCycles i ≫ K.pOpcycles i := (K.sc i).homology_π_ι /-- The isomorphism `K.homology i ≅ L.homology i` induced by an isomorphism in `HomologicalComplex`. -/ @[simps] noncomputable def homologyMapIso : K.homology i ≅ L.homology i where hom := homologyMap iso.hom i inv := homologyMap iso.inv i hom_inv_id := by simp [← homologyMap_comp] inv_hom_id := by simp [← homologyMap_comp] /-- The isomorphism `K.cycles i ≅ L.cycles i` induced by an isomorphism in `HomologicalComplex`. -/ @[simps] noncomputable def cyclesMapIso : K.cycles i ≅ L.cycles i where hom := cyclesMap iso.hom i inv := cyclesMap iso.inv i hom_inv_id := by simp [← cyclesMap_comp] inv_hom_id := by simp [← cyclesMap_comp] /-- The isomorphism `K.opcycles i ≅ L.opcycles i` induced by an isomorphism in `HomologicalComplex`. -/ @[simps] noncomputable def opcyclesMapIso : K.opcycles i ≅ L.opcycles i where hom := opcyclesMap iso.hom i inv := opcyclesMap iso.inv i hom_inv_id := by simp [← opcyclesMap_comp] inv_hom_id := by simp [← opcyclesMap_comp] variable {i} @[reassoc (attr := simp)] lemma opcyclesMap_comp_descOpcycles {A : C} (k : L.X i ⟶ A) (j : ι) (hj : c.prev i = j) (hk : L.d j i ≫ k = 0) (φ : K ⟶ L) : opcyclesMap φ i ≫ L.descOpcycles k j hj hk = K.descOpcycles (φ.f i ≫ k) j hj (by rw [← φ.comm_assoc, hk, comp_zero]) := by simp only [← cancel_epi (K.pOpcycles i), p_opcyclesMap_assoc, p_descOpcycles] @[reassoc (attr := simp)] lemma liftCycles_comp_cyclesMap {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j) (hk : k ≫ K.d i j = 0) (φ : K ⟶ L) : K.liftCycles k j hj hk ≫ cyclesMap φ i = L.liftCycles (k ≫ φ.f i) j hj (by rw [assoc, φ.comm, reassoc_of% hk, zero_comp]) := by simp only [← cancel_mono (L.iCycles i), assoc, cyclesMap_i, liftCycles_i_assoc, liftCycles_i] section variable (C c i) attribute [local simp] homologyMap_comp cyclesMap_comp opcyclesMap_comp /-- The `i`th homology functor `HomologicalComplex C c ⥤ C`. -/ @[simps] noncomputable def homologyFunctor [CategoryWithHomology C] : HomologicalComplex C c ⥤ C where obj K := K.homology i map f := homologyMap f i /-- The homology functor to graded objects. -/ @[simps] noncomputable def gradedHomologyFunctor [CategoryWithHomology C] : HomologicalComplex C c ⥤ GradedObject ι C where obj K i := K.homology i map f i := homologyMap f i /-- The `i`th cycles functor `HomologicalComplex C c ⥤ C`. -/ @[simps] noncomputable def cyclesFunctor [CategoryWithHomology C] : HomologicalComplex C c ⥤ C where obj K := K.cycles i map f := cyclesMap f i /-- The `i`th opcycles functor `HomologicalComplex C c ⥤ C`. -/ @[simps] noncomputable def opcyclesFunctor [CategoryWithHomology C] : HomologicalComplex C c ⥤ C where obj K := K.opcycles i map f := opcyclesMap f i /-- The natural transformation `K.homologyπ i : K.cycles i ⟶ K.homology i` for all `K : HomologicalComplex C c`. -/ @[simps] noncomputable def natTransHomologyπ [CategoryWithHomology C] : cyclesFunctor C c i ⟶ homologyFunctor C c i where app K := K.homologyπ i /-- The natural transformation `K.homologyι i : K.homology i ⟶ K.opcycles i` for all `K : HomologicalComplex C c`. -/ @[simps] noncomputable def natTransHomologyι [CategoryWithHomology C] : homologyFunctor C c i ⟶ opcyclesFunctor C c i where app K := K.homologyι i /-- The natural isomorphism `K.homology i ≅ (K.sc i).homology` for all homological complexes `K`. -/ @[simps!] noncomputable def homologyFunctorIso [CategoryWithHomology C] : homologyFunctor C c i ≅ shortComplexFunctor C c i ⋙ ShortComplex.homologyFunctor C := Iso.refl _ /-- The natural isomorphism `K.homology j ≅ (K.sc' i j k).homology` for all homological complexes `K` when `c.prev j = i` and `c.next j = k`. -/ noncomputable def homologyFunctorIso' [CategoryWithHomology C] (hi : c.prev j = i) (hk : c.next j = k) : homologyFunctor C c j ≅ shortComplexFunctor' C c i j k ⋙ ShortComplex.homologyFunctor C := homologyFunctorIso C c j ≪≫ Functor.isoWhiskerRight (natIsoSc' C c i j k hi hk) _ instance [CategoryWithHomology C] : (homologyFunctor C c i).PreservesZeroMorphisms where instance [CategoryWithHomology C] : (opcyclesFunctor C c i).PreservesZeroMorphisms where instance [CategoryWithHomology C] : (cyclesFunctor C c i).PreservesZeroMorphisms where end end section variable (hj : c.next i = j) (h : K.d i j = 0) [K.HasHomology i] include hj h lemma isIso_iCycles : IsIso (K.iCycles i) := by subst hj exact ShortComplex.isIso_iCycles _ h /-- The canonical isomorphism `K.cycles i ≅ K.X i` when the differential from `i` is zero. -/ @[simps! hom] noncomputable def iCyclesIso : K.cycles i ≅ K.X i := have := K.isIso_iCycles i j hj h asIso (K.iCycles i) @[reassoc (attr := simp)] lemma iCyclesIso_hom_inv_id : K.iCycles i ≫ (K.iCyclesIso i j hj h).inv = 𝟙 _ := (K.iCyclesIso i j hj h).hom_inv_id @[reassoc (attr := simp)] lemma iCyclesIso_inv_hom_id : (K.iCyclesIso i j hj h).inv ≫ K.iCycles i = 𝟙 _ := (K.iCyclesIso i j hj h).inv_hom_id lemma isIso_homologyι : IsIso (K.homologyι i) := ShortComplex.isIso_homologyι _ (by cat_disch) /-- The canonical isomorphism `K.homology i ≅ K.opcycles i` when the differential from `i` is zero. -/ @[simps! hom] noncomputable def isoHomologyι : K.homology i ≅ K.opcycles i := have := K.isIso_homologyι i j hj h asIso (K.homologyι i) @[reassoc (attr := simp)] lemma isoHomologyι_hom_inv_id : K.homologyι i ≫ (K.isoHomologyι i j hj h).inv = 𝟙 _ := (K.isoHomologyι i j hj h).hom_inv_id @[reassoc (attr := simp)] lemma isoHomologyι_inv_hom_id : (K.isoHomologyι i j hj h).inv ≫ K.homologyι i = 𝟙 _ := (K.isoHomologyι i j hj h).inv_hom_id end section variable (hi : c.prev j = i) (h : K.d i j = 0) [K.HasHomology j] include hi h lemma isIso_pOpcycles : IsIso (K.pOpcycles j) := by obtain rfl := hi exact ShortComplex.isIso_pOpcycles _ h /-- The canonical isomorphism `K.X j ≅ K.opCycles j` when the differential to `j` is zero. -/ @[simps! hom] noncomputable def pOpcyclesIso : K.X j ≅ K.opcycles j := have := K.isIso_pOpcycles i j hi h asIso (K.pOpcycles j) @[reassoc (attr := simp)] lemma pOpcyclesIso_hom_inv_id : K.pOpcycles j ≫ (K.pOpcyclesIso i j hi h).inv = 𝟙 _ := (K.pOpcyclesIso i j hi h).hom_inv_id @[reassoc (attr := simp)] lemma pOpcyclesIso_inv_hom_id : (K.pOpcyclesIso i j hi h).inv ≫ K.pOpcycles j = 𝟙 _ := (K.pOpcyclesIso i j hi h).inv_hom_id lemma isIso_homologyπ : IsIso (K.homologyπ j) := ShortComplex.isIso_homologyπ _ (by cat_disch) /-- The canonical isomorphism `K.cycles j ≅ K.homology j` when the differential to `j` is zero. -/ @[simps! hom] noncomputable def isoHomologyπ : K.cycles j ≅ K.homology j := have := K.isIso_homologyπ i j hi h asIso (K.homologyπ j) @[reassoc (attr := simp)] lemma isoHomologyπ_hom_inv_id : K.homologyπ j ≫ (K.isoHomologyπ i j hi h).inv = 𝟙 _ := (K.isoHomologyπ i j hi h).hom_inv_id @[reassoc (attr := simp)] lemma isoHomologyπ_inv_hom_id : (K.isoHomologyπ i j hi h).inv ≫ K.homologyπ j = 𝟙 _ := (K.isoHomologyπ i j hi h).inv_hom_id end section variable {K L} lemma epi_homologyMap_of_epi_of_not_rel (φ : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [Epi (φ.f i)] (hi : ∀ j, ¬ c.Rel i j) : Epi (homologyMap φ i) := ((MorphismProperty.epimorphisms C).arrow_mk_iso_iff (Arrow.isoMk (K.isoHomologyι i _ rfl (shape _ _ _ (by tauto))) (L.isoHomologyι i _ rfl (shape _ _ _ (by tauto))))).2 (MorphismProperty.epimorphisms.infer_property (opcyclesMap φ i)) lemma mono_homologyMap_of_mono_of_not_rel (φ : K ⟶ L) (j : ι) [K.HasHomology j] [L.HasHomology j] [Mono (φ.f j)] (hj : ∀ i, ¬ c.Rel i j) : Mono (homologyMap φ j) := ((MorphismProperty.monomorphisms C).arrow_mk_iso_iff (Arrow.isoMk (K.isoHomologyπ _ j rfl (shape _ _ _ (by tauto))) (L.isoHomologyπ _ j rfl (shape _ _ _ (by tauto))))).1 (MorphismProperty.monomorphisms.infer_property (cyclesMap φ j)) end /-- A homological complex `K` is exact at `i` if the short complex `K.sc i` is exact. -/ def ExactAt := (K.sc i).Exact lemma exactAt_iff : K.ExactAt i ↔ (K.sc i).Exact := by rfl variable {K i} in lemma ExactAt.of_iso (hK : K.ExactAt i) {L : HomologicalComplex C c} (e : K ≅ L) : L.ExactAt i := by rw [exactAt_iff] at hK ⊢ exact ShortComplex.exact_of_iso ((shortComplexFunctor C c i).mapIso e) hK lemma exactAt_iff' (hi : c.prev j = i) (hk : c.next j = k) : K.ExactAt j ↔ (K.sc' i j k).Exact := ShortComplex.exact_iff_of_iso (K.isoSc' i j k hi hk) lemma exactAt_iff_isZero_homology [K.HasHomology i] : K.ExactAt i ↔ IsZero (K.homology i) := by dsimp [homology] rw [exactAt_iff, ShortComplex.exact_iff_isZero_homology] variable {K i} in lemma ExactAt.isZero_homology [K.HasHomology i] (h : K.ExactAt i) : IsZero (K.homology i) := by rwa [← exactAt_iff_isZero_homology] /-- A homological complex `K` is acyclic if it is exact at `i` for any `i`. -/ def Acyclic := ∀ i, K.ExactAt i lemma acyclic_iff : K.Acyclic ↔ ∀ i, K.ExactAt i := by rfl lemma acyclic_of_isZero (hK : IsZero K) : K.Acyclic := by rw [acyclic_iff] intro i apply ShortComplex.exact_of_isZero_X₂ exact (eval _ _ i).map_isZero hK end HomologicalComplex namespace ChainComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (K L : ChainComplex C ℕ) (φ : K ⟶ L) [K.HasHomology 0] instance isIso_homologyι₀ : IsIso (K.homologyι 0) := K.isIso_homologyι 0 _ rfl (by simp) /-- The canonical isomorphism `K.homology 0 ≅ K.opcycles 0` for a chain complex `K` indexed by `ℕ`. -/ noncomputable abbrev isoHomologyι₀ : K.homology 0 ≅ K.opcycles 0 := K.isoHomologyι 0 _ rfl (by simp) variable {K L} @[reassoc (attr := simp)] lemma isoHomologyι₀_inv_naturality [L.HasHomology 0] : K.isoHomologyι₀.inv ≫ HomologicalComplex.homologyMap φ 0 = HomologicalComplex.opcyclesMap φ 0 ≫ L.isoHomologyι₀.inv := by simp only [assoc, ← cancel_mono (L.homologyι 0), HomologicalComplex.homologyι_naturality, HomologicalComplex.isoHomologyι_inv_hom_id_assoc, HomologicalComplex.isoHomologyι_inv_hom_id, comp_id] end ChainComplex namespace CochainComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (K L : CochainComplex C ℕ) (φ : K ⟶ L) [K.HasHomology 0] instance isIso_homologyπ₀ : IsIso (K.homologyπ 0) := K.isIso_homologyπ _ 0 rfl (by simp) /-- The canonical isomorphism `K.cycles 0 ≅ K.homology 0` for a cochain complex `K` indexed by `ℕ`. -/ noncomputable abbrev isoHomologyπ₀ : K.cycles 0 ≅ K.homology 0 := K.isoHomologyπ _ 0 rfl (by simp) variable {K L} @[reassoc (attr := simp)] lemma isoHomologyπ₀_inv_naturality [L.HasHomology 0] : HomologicalComplex.homologyMap φ 0 ≫ L.isoHomologyπ₀.inv = K.isoHomologyπ₀.inv ≫ HomologicalComplex.cyclesMap φ 0 := by simp only [← cancel_epi (K.homologyπ 0), HomologicalComplex.homologyπ_naturality_assoc, HomologicalComplex.isoHomologyπ_hom_inv_id, comp_id, HomologicalComplex.isoHomologyπ_hom_inv_id_assoc] end CochainComplex namespace HomologicalComplex variable {C ι : Type*} [Category C] [Preadditive C] {c : ComplexShape ι} {K L : HomologicalComplex C c} {f g : K ⟶ L} variable (φ ψ : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] @[simp] lemma homologyMap_neg : homologyMap (-φ) i = -homologyMap φ i := by dsimp [homologyMap] rw [← ShortComplex.homologyMap_neg] rfl @[simp] lemma homologyMap_add : homologyMap (φ + ψ) i = homologyMap φ i + homologyMap ψ i := by dsimp [homologyMap] rw [← ShortComplex.homologyMap_add] rfl @[simp] lemma homologyMap_sub : homologyMap (φ - ψ) i = homologyMap φ i - homologyMap ψ i := by dsimp [homologyMap] rw [← ShortComplex.homologyMap_sub] rfl instance [CategoryWithHomology C] : (homologyFunctor C c i).Additive where end HomologicalComplex namespace CochainComplex variable {C : Type*} [Category C] [Abelian C] lemma isIso_liftCycles_iff (K : CochainComplex C ℕ) {X : C} (φ : X ⟶ K.X 0) [K.HasHomology 0] (hφ : φ ≫ K.d 0 1 = 0) : IsIso (K.liftCycles φ 1 (by simp) hφ) ↔ (ShortComplex.mk _ _ hφ).Exact ∧ Mono φ := by suffices ∀ (i : ℕ) (hx : (ComplexShape.up ℕ).next 0 = i) (hφ : φ ≫ K.d 0 i = 0), IsIso (K.liftCycles φ i hx hφ) ↔ (ShortComplex.mk _ _ hφ).Exact ∧ Mono φ from this 1 (by simp) hφ rintro _ rfl hφ let α : ShortComplex.mk (0 : X ⟶ X) (0 : X ⟶ X) (by simp) ⟶ K.sc 0 := { τ₁ := 0 τ₂ := φ τ₃ := 0 } exact (ShortComplex.quasiIso_iff_isIso_liftCycles α rfl rfl (by simp)).symm.trans (ShortComplex.quasiIso_iff_of_zeros α rfl rfl (by simp)) end CochainComplex namespace ChainComplex variable {C : Type*} [Category C] [Abelian C] lemma isIso_descOpcycles_iff (K : ChainComplex C ℕ) {X : C} (φ : K.X 0 ⟶ X) [K.HasHomology 0] (hφ : K.d 1 0 ≫ φ = 0) : IsIso (K.descOpcycles φ 1 (by simp) hφ) ↔ (ShortComplex.mk _ _ hφ).Exact ∧ Epi φ := by suffices ∀ (i : ℕ) (hx : (ComplexShape.down ℕ).prev 0 = i) (hφ : K.d i 0 ≫ φ = 0), IsIso (K.descOpcycles φ i hx hφ) ↔ (ShortComplex.mk _ _ hφ).Exact ∧ Epi φ from this 1 (by simp) hφ rintro _ rfl hφ let α : K.sc 0 ⟶ ShortComplex.mk (0 : X ⟶ X) (0 : X ⟶ X) (by simp) := { τ₁ := 0 τ₂ := φ τ₃ := 0 } exact (ShortComplex.quasiIso_iff_isIso_descOpcycles α (by simp) rfl rfl).symm.trans (ShortComplex.quasiIso_iff_of_zeros' α (by simp) rfl rfl) end ChainComplex namespace HomologicalComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] {ι : Type*} {c : ComplexShape ι} (K : HomologicalComplex C c) (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) [K.HasHomology j] [(K.sc' i j k).HasHomology] /-- The cycles of a homological complex in degree `j` can be computed by specifying a choice of `c.prev j` and `c.next j`. -/ noncomputable def cyclesIsoSc' : K.cycles j ≅ (K.sc' i j k).cycles := ShortComplex.cyclesMapIso (K.isoSc' i j k hi hk) @[reassoc (attr := simp)] lemma cyclesIsoSc'_hom_iCycles : (K.cyclesIsoSc' i j k hi hk).hom ≫ (K.sc' i j k).iCycles = K.iCycles j := by dsimp [cyclesIsoSc'] simp only [ShortComplex.cyclesMap_i, shortComplexFunctor_obj_X₂, shortComplexFunctor'_obj_X₂, natIsoSc'_hom_app_τ₂, comp_id] rfl @[reassoc (attr := simp)] lemma cyclesIsoSc'_inv_iCycles : (K.cyclesIsoSc' i j k hi hk).inv ≫ K.iCycles j = (K.sc' i j k).iCycles := by dsimp [cyclesIsoSc'] erw [ShortComplex.cyclesMap_i] apply comp_id @[reassoc (attr := simp)] lemma toCycles_cyclesIsoSc'_hom : K.toCycles i j ≫ (K.cyclesIsoSc' i j k hi hk).hom = (K.sc' i j k).toCycles := by simp only [← cancel_mono (K.sc' i j k).iCycles, assoc, cyclesIsoSc'_hom_iCycles, toCycles_i, ShortComplex.toCycles_i, shortComplexFunctor'_obj_f] /-- The homology of a homological complex in degree `j` can be computed by specifying a choice of `c.prev j` and `c.next j`. -/ noncomputable def opcyclesIsoSc' : K.opcycles j ≅ (K.sc' i j k).opcycles := ShortComplex.opcyclesMapIso (K.isoSc' i j k hi hk) @[reassoc (attr := simp)] lemma pOpcycles_opcyclesIsoSc'_inv : (K.sc' i j k).pOpcycles ≫ (K.opcyclesIsoSc' i j k hi hk).inv = K.pOpcycles j := by dsimp [opcyclesIsoSc'] simp only [ShortComplex.p_opcyclesMap, shortComplexFunctor'_obj_X₂, shortComplexFunctor_obj_X₂, natIsoSc'_inv_app_τ₂, id_comp] rfl @[reassoc (attr := simp)] lemma pOpcycles_opcyclesIsoSc'_hom : K.pOpcycles j ≫ (K.opcyclesIsoSc' i j k hi hk).hom = (K.sc' i j k).pOpcycles := by dsimp [opcyclesIsoSc'] erw [ShortComplex.p_opcyclesMap] apply id_comp @[reassoc (attr := simp)] lemma opcyclesIsoSc'_inv_fromOpcycles : (K.opcyclesIsoSc' i j k hi hk).inv ≫ K.fromOpcycles j k = (K.sc' i j k).fromOpcycles := by simp only [← cancel_epi (K.sc' i j k).pOpcycles, pOpcycles_opcyclesIsoSc'_inv_assoc, p_fromOpcycles, ShortComplex.p_fromOpcycles, shortComplexFunctor'_obj_g] /-- The opcycles of a homological complex in degree `j` can be computed by specifying a choice of `c.prev j` and `c.next j`. -/ noncomputable def homologyIsoSc' : K.homology j ≅ (K.sc' i j k).homology := ShortComplex.homologyMapIso (K.isoSc' i j k hi hk) @[reassoc (attr := simp)] lemma π_homologyIsoSc'_hom : K.homologyπ j ≫ (K.homologyIsoSc' i j k hi hk).hom = (K.cyclesIsoSc' i j k hi hk).hom ≫ (K.sc' i j k).homologyπ := by apply ShortComplex.homologyπ_naturality @[reassoc (attr := simp)] lemma π_homologyIsoSc'_inv : (K.sc' i j k).homologyπ ≫ (K.homologyIsoSc' i j k hi hk).inv = (K.cyclesIsoSc' i j k hi hk).inv ≫ K.homologyπ j := by apply ShortComplex.homologyπ_naturality @[reassoc (attr := simp)] lemma homologyIsoSc'_hom_ι : (K.homologyIsoSc' i j k hi hk).hom ≫ (K.sc' i j k).homologyι = K.homologyι j ≫ (K.opcyclesIsoSc' i j k hi hk).hom := by apply ShortComplex.homologyι_naturality @[reassoc (attr := simp)] lemma homologyIsoSc'_inv_ι : (K.homologyIsoSc' i j k hi hk).inv ≫ K.homologyι j = (K.sc' i j k).homologyι ≫ (K.opcyclesIsoSc' i j k hi hk).inv := by apply ShortComplex.homologyι_naturality end HomologicalComplex
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/FunctorEquivalence.lean
import Mathlib.Algebra.Homology.ShortComplex.Basic /-! # Short complexes in functor categories In this file, it is shown that if `J` and `C` are two categories (such that `C` has zero morphisms), then there is an equivalence of categories `ShortComplex.functorEquivalence J C : ShortComplex (J ⥤ C) ≌ J ⥤ ShortComplex C`. -/ namespace CategoryTheory open Limits Functor variable (J C : Type*) [Category J] [Category C] [HasZeroMorphisms C] namespace ShortComplex namespace FunctorEquivalence attribute [local simp] ShortComplex.Hom.comm₁₂ ShortComplex.Hom.comm₂₃ /-- The obvious functor `ShortComplex (J ⥤ C) ⥤ J ⥤ ShortComplex C`. -/ @[simps] def functor : ShortComplex (J ⥤ C) ⥤ J ⥤ ShortComplex C where obj S := { obj := fun j => S.map ((evaluation J C).obj j) map := fun f => S.mapNatTrans ((evaluation J C).map f) } map φ := { app := fun j => ((evaluation J C).obj j).mapShortComplex.map φ } /-- The obvious functor `(J ⥤ ShortComplex C) ⥤ ShortComplex (J ⥤ C)`. -/ @[simps] def inverse : (J ⥤ ShortComplex C) ⥤ ShortComplex (J ⥤ C) where obj F := { f := whiskerLeft F π₁Toπ₂ g := whiskerLeft F π₂Toπ₃ zero := by cat_disch } map φ := Hom.mk (whiskerRight φ π₁) (whiskerRight φ π₂) (whiskerRight φ π₃) (by cat_disch) (by cat_disch) /-- The unit isomorphism of the equivalence `ShortComplex.functorEquivalence : ShortComplex (J ⥤ C) ≌ J ⥤ ShortComplex C`. -/ @[simps!] def unitIso : 𝟭 _ ≅ functor J C ⋙ inverse J C := NatIso.ofComponents (fun _ => isoMk (NatIso.ofComponents (fun _ => Iso.refl _) (by simp)) (NatIso.ofComponents (fun _ => Iso.refl _) (by simp)) (NatIso.ofComponents (fun _ => Iso.refl _) (by simp)) (by cat_disch) (by cat_disch)) (by cat_disch) /-- The counit isomorphism of the equivalence `ShortComplex.functorEquivalence : ShortComplex (J ⥤ C) ≌ J ⥤ ShortComplex C`. -/ @[simps!] def counitIso : inverse J C ⋙ functor J C ≅ 𝟭 _ := NatIso.ofComponents (fun _ => NatIso.ofComponents (fun _ => isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _) (by simp) (by simp)) (by cat_disch)) (by cat_disch) end FunctorEquivalence /-- The obvious equivalence `ShortComplex (J ⥤ C) ≌ J ⥤ ShortComplex C`. -/ @[simps] def functorEquivalence : ShortComplex (J ⥤ C) ≌ J ⥤ ShortComplex C where functor := FunctorEquivalence.functor J C inverse := FunctorEquivalence.inverse J C unitIso := FunctorEquivalence.unitIso J C counitIso := FunctorEquivalence.counitIso J C end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Abelian.lean
import Mathlib.Algebra.Homology.ShortComplex.Homology import Mathlib.CategoryTheory.Abelian.Basic /-! # Abelian categories have homology In this file, it is shown that all short complexes `S` in abelian categories have terms of type `S.HomologyData`. The strategy of the proof is to study the morphism `kernel.ι S.g ≫ cokernel.π S.f`. We show that there is a `LeftHomologyData` for `S` for which the `H` field consists of the coimage of `kernel.ι S.g ≫ cokernel.π S.f`, while there is a `RightHomologyData` for which the `H` is the image of `kernel.ι S.g ≫ cokernel.π S.f`. The fact that these left and right homology data are compatible (i.e. provide a `HomologyData`) is obtained by using the coimage-image isomorphism in abelian categories. -/ universe v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] [Abelian C] (S : ShortComplex C) namespace ShortComplex /-- The canonical morphism `Abelian.image S.f ⟶ kernel S.g` for a short complex `S` in an abelian category. -/ noncomputable def abelianImageToKernel : Abelian.image S.f ⟶ kernel S.g := kernel.lift S.g (Abelian.image.ι S.f) (by simp only [← cancel_epi (Abelian.factorThruImage S.f), kernel.lift_ι_assoc, zero, comp_zero]) @[reassoc (attr := simp)] lemma abelianImageToKernel_comp_kernel_ι : S.abelianImageToKernel ≫ kernel.ι S.g = Abelian.image.ι S.f := kernel.lift_ι _ _ _ instance : Mono S.abelianImageToKernel := mono_of_mono_fac S.abelianImageToKernel_comp_kernel_ι @[reassoc] lemma abelianImageToKernel_comp_kernel_ι_comp_cokernel_π : S.abelianImageToKernel ≫ kernel.ι S.g ≫ cokernel.π S.f = 0 := by simp /-- `Abelian.image S.f` is the kernel of `kernel.ι S.g ≫ cokernel.π S.f` -/ noncomputable def abelianImageToKernelIsKernel : IsLimit (KernelFork.ofι S.abelianImageToKernel S.abelianImageToKernel_comp_kernel_ι_comp_cokernel_π) := KernelFork.IsLimit.ofι _ _ (fun k hk => kernel.lift _ (k ≫ kernel.ι S.g) (by rw [assoc, hk])) (fun k hk => by simp only [← cancel_mono (kernel.ι S.g), assoc, abelianImageToKernel_comp_kernel_ι, kernel.lift_ι]) (fun k hk b hb => by simp only [← cancel_mono S.abelianImageToKernel, ← cancel_mono (kernel.ι S.g), hb, assoc, abelianImageToKernel_comp_kernel_ι, kernel.lift_ι]) namespace LeftHomologyData /-- The canonical `LeftHomologyData` of a short complex `S` in an abelian category, for which the `H` field is `Abelian.coimage (kernel.ι S.g ≫ cokernel.π S.f)`. -/ @[simps] noncomputable def ofAbelian : S.LeftHomologyData := by let γ := kernel.ι S.g ≫ cokernel.π S.f let f' := kernel.lift S.g S.f S.zero have hf' : f' = kernel.lift γ f' (by simp [γ, f']) ≫ kernel.ι γ := by rw [kernel.lift_ι] have wπ : f' ≫ cokernel.π (kernel.ι γ) = 0 := by rw [hf'] simp only [assoc, cokernel.condition, comp_zero] let e : Abelian.image S.f ≅ kernel γ := IsLimit.conePointUniqueUpToIso S.abelianImageToKernelIsKernel (limit.isLimit _) have he : e.hom ≫ kernel.ι γ = S.abelianImageToKernel := IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingParallelPair.zero have fac : f' = Abelian.factorThruImage S.f ≫ e.hom ≫ kernel.ι γ := by rw [hf', he] simp only [γ, f', kernel.lift_ι, abelianImageToKernel, ← cancel_mono (kernel.ι S.g), assoc] have hπ : IsColimit (CokernelCofork.ofπ _ wπ) := CokernelCofork.IsColimit.ofπ _ _ (fun x hx => cokernel.desc _ x (by simpa only [← cancel_epi e.hom, ← cancel_epi (Abelian.factorThruImage S.f), comp_zero, fac, assoc] using hx)) (fun x hx => cokernel.π_desc _ _ _) (fun x hx b hb => coequalizer.hom_ext (by simp only [hb, cokernel.π_desc])) exact { K := kernel S.g, H := Abelian.coimage (kernel.ι S.g ≫ cokernel.π S.f) i := kernel.ι _, π := cokernel.π _ wi := kernel.condition _ hi := kernelIsKernel _ wπ := wπ hπ := hπ } end LeftHomologyData /-- The canonical morphism `cokernel S.f ⟶ Abelian.coimage S.g` for a short complex `S` in an abelian category. -/ noncomputable def cokernelToAbelianCoimage : cokernel S.f ⟶ Abelian.coimage S.g := cokernel.desc S.f (Abelian.coimage.π S.g) (by simp only [← cancel_mono (Abelian.factorThruCoimage S.g), assoc, cokernel.π_desc, zero, zero_comp]) @[reassoc (attr := simp)] lemma cokernel_π_comp_cokernelToAbelianCoimage : cokernel.π S.f ≫ S.cokernelToAbelianCoimage = Abelian.coimage.π S.g := cokernel.π_desc _ _ _ instance : Epi S.cokernelToAbelianCoimage := epi_of_epi_fac S.cokernel_π_comp_cokernelToAbelianCoimage lemma kernel_ι_comp_cokernel_π_comp_cokernelToAbelianCoimage : (kernel.ι S.g ≫ cokernel.π S.f) ≫ S.cokernelToAbelianCoimage = 0 := by simp /-- `Abelian.coimage S.g` is the cokernel of `kernel.ι S.g ≫ cokernel.π S.f` -/ noncomputable def cokernelToAbelianCoimageIsCokernel : IsColimit (CokernelCofork.ofπ S.cokernelToAbelianCoimage S.kernel_ι_comp_cokernel_π_comp_cokernelToAbelianCoimage) := CokernelCofork.IsColimit.ofπ _ _ (fun k hk => cokernel.desc _ (cokernel.π S.f ≫ k) (by simpa only [assoc] using hk)) (fun k hk => by simp only [← cancel_epi (cokernel.π S.f), cokernel_π_comp_cokernelToAbelianCoimage_assoc, cokernel.π_desc]) (fun k hk b hb => by simp only [← cancel_epi S.cokernelToAbelianCoimage, ← cancel_epi (cokernel.π S.f), hb, cokernel_π_comp_cokernelToAbelianCoimage_assoc, cokernel.π_desc]) namespace RightHomologyData /-- The canonical `RightHomologyData` of a short complex `S` in an abelian category, for which the `H` field is `Abelian.image (kernel.ι S.g ≫ cokernel.π S.f)`. -/ @[simps] noncomputable def ofAbelian : S.RightHomologyData := by let γ := kernel.ι S.g ≫ cokernel.π S.f let g' := cokernel.desc S.f S.g S.zero have hg' : g' = cokernel.π γ ≫ cokernel.desc γ g' (by simp [γ, g']) := by rw [cokernel.π_desc] have wι : kernel.ι (cokernel.π γ) ≫ g' = 0 := by rw [hg', kernel.condition_assoc, zero_comp] let e : cokernel γ ≅ Abelian.coimage S.g := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) S.cokernelToAbelianCoimageIsCokernel have he : cokernel.π γ ≫ e.hom = S.cokernelToAbelianCoimage := IsColimit.comp_coconePointUniqueUpToIso_hom _ _ WalkingParallelPair.one have fac : g' = cokernel.π γ ≫ e.hom ≫ Abelian.factorThruCoimage S.g := by rw [hg', reassoc_of% he] simp only [γ, g', cokernel.π_desc, ← cancel_epi (cokernel.π S.f), cokernel_π_comp_cokernelToAbelianCoimage_assoc] have hι : IsLimit (KernelFork.ofι _ wι) := KernelFork.IsLimit.ofι _ _ (fun x hx => kernel.lift _ x (by simpa only [← cancel_mono e.hom, ← cancel_mono (Abelian.factorThruCoimage S.g), assoc, zero_comp, fac] using hx)) (fun x hx => kernel.lift_ι _ _ _) (fun x hx b hb => equalizer.hom_ext (by simp only [hb, kernel.lift_ι])) exact { Q := cokernel S.f, H := Abelian.image (kernel.ι S.g ≫ cokernel.π S.f) p := cokernel.π _ ι := kernel.ι _ wp := cokernel.condition _ hp := cokernelIsCokernel _ wι := wι hι := hι } end RightHomologyData /-- The canonical `HomologyData` of a short complex `S` in an abelian category. -/ noncomputable def HomologyData.ofAbelian : S.HomologyData where left := LeftHomologyData.ofAbelian S right := RightHomologyData.ofAbelian S iso := Abelian.coimageIsoImage (kernel.ι S.g ≫ cokernel.π S.f) instance _root_.CategoryTheory.categoryWithHomology_of_abelian : CategoryWithHomology C where hasHomology S := HasHomology.mk' (HomologyData.ofAbelian S) end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/RightHomology.lean
import Mathlib.Algebra.Homology.ShortComplex.LeftHomology import Mathlib.CategoryTheory.Limits.Shapes.Opposites.Kernels /-! # Right Homology of short complexes In this file, we define the dual notions to those defined in `Algebra.Homology.ShortComplex.LeftHomology`. In particular, if `S : ShortComplex C` is a short complex consisting of two composable maps `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` such that `f ≫ g = 0`, we define `h : S.RightHomologyData` to be the datum of morphisms `p : X₂ ⟶ Q` and `ι : H ⟶ Q` such that `Q` identifies to the cokernel of `f` and `H` to the kernel of the induced map `g' : Q ⟶ X₃`. When such a `S.RightHomologyData` exists, we shall say that `[S.HasRightHomology]` and we define `S.rightHomology` to be the `H` field of a chosen right homology data. Similarly, we define `S.opcycles` to be the `Q` field. In `Homology.lean`, when `S` has two compatible left and right homology data (i.e. they give the same `H` up to a canonical isomorphism), we shall define `[S.HasHomology]` and `S.homology`. -/ namespace CategoryTheory open Category Limits namespace ShortComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (S : ShortComplex C) {S₁ S₂ S₃ : ShortComplex C} /-- A right homology data for a short complex `S` consists of morphisms `p : S.X₂ ⟶ Q` and `ι : H ⟶ Q` such that `p` identifies `Q` with the cokernel of `f : S.X₁ ⟶ S.X₂`, and that `ι` identifies `H` with the kernel of the induced map `g' : Q ⟶ S.X₃` -/ structure RightHomologyData where /-- a choice of cokernel of `S.f : S.X₁ ⟶ S.X₂` -/ Q : C /-- a choice of kernel of the induced morphism `S.g' : S.Q ⟶ X₃` -/ H : C /-- the projection from `S.X₂` -/ p : S.X₂ ⟶ Q /-- the inclusion of the (right) homology in the chosen cokernel of `S.f` -/ ι : H ⟶ Q /-- the cokernel condition for `p` -/ wp : S.f ≫ p = 0 /-- `p : S.X₂ ⟶ Q` is a cokernel of `S.f : S.X₁ ⟶ S.X₂` -/ hp : IsColimit (CokernelCofork.ofπ p wp) /-- the kernel condition for `ι` -/ wι : ι ≫ hp.desc (CokernelCofork.ofπ _ S.zero) = 0 /-- `ι : H ⟶ Q` is a kernel of `S.g' : Q ⟶ S.X₃` -/ hι : IsLimit (KernelFork.ofι ι wι) initialize_simps_projections RightHomologyData (-hp, -hι) namespace RightHomologyData /-- The chosen cokernels and kernels of the limits API give a `RightHomologyData` -/ @[simps] noncomputable def ofHasCokernelOfHasKernel [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.RightHomologyData := { Q := cokernel S.f, H := kernel (cokernel.desc S.f S.g S.zero), p := cokernel.π _, ι := kernel.ι _, wp := cokernel.condition _, hp := cokernelIsCokernel _, wι := kernel.condition _, hι := kernelIsKernel _, } attribute [reassoc (attr := simp)] wp wι variable {S} variable (h : S.RightHomologyData) {A : C} instance : Epi h.p := ⟨fun _ _ => Cofork.IsColimit.hom_ext h.hp⟩ instance : Mono h.ι := ⟨fun _ _ => Fork.IsLimit.hom_ext h.hι⟩ /-- Any morphism `k : S.X₂ ⟶ A` such that `S.f ≫ k = 0` descends to a morphism `Q ⟶ A` -/ def descQ (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.Q ⟶ A := h.hp.desc (CokernelCofork.ofπ k hk) @[reassoc (attr := simp)] lemma p_descQ (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.p ≫ h.descQ k hk = k := h.hp.fac _ WalkingParallelPair.one /-- The morphism from the (right) homology attached to a morphism `k : S.X₂ ⟶ A` such that `S.f ≫ k = 0`. -/ @[simp] def descH (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.H ⟶ A := h.ι ≫ h.descQ k hk /-- The morphism `h.Q ⟶ S.X₃` induced by `S.g : S.X₂ ⟶ S.X₃` and the fact that `h.Q` is a cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ def g' : h.Q ⟶ S.X₃ := h.descQ S.g S.zero @[reassoc (attr := simp)] lemma p_g' : h.p ≫ h.g' = S.g := p_descQ _ _ _ @[reassoc (attr := simp)] lemma ι_g' : h.ι ≫ h.g' = 0 := h.wι @[reassoc] lemma ι_descQ_eq_zero_of_boundary (k : S.X₂ ⟶ A) (x : S.X₃ ⟶ A) (hx : k = S.g ≫ x) : h.ι ≫ h.descQ k (by rw [hx, S.zero_assoc, zero_comp]) = 0 := by rw [show 0 = h.ι ≫ h.g' ≫ x by simp] congr 1 simp only [← cancel_epi h.p, hx, p_descQ, p_g'_assoc] /-- For `h : S.RightHomologyData`, this is a restatement of `h.hι`, saying that `ι : h.H ⟶ h.Q` is a kernel of `h.g' : h.Q ⟶ S.X₃`. -/ def hι' : IsLimit (KernelFork.ofι h.ι h.ι_g') := h.hι /-- The morphism `A ⟶ H` induced by a morphism `k : A ⟶ Q` such that `k ≫ g' = 0` -/ def liftH (k : A ⟶ h.Q) (hk : k ≫ h.g' = 0) : A ⟶ h.H := h.hι.lift (KernelFork.ofι k hk) @[reassoc (attr := simp)] lemma liftH_ι (k : A ⟶ h.Q) (hk : k ≫ h.g' = 0) : h.liftH k hk ≫ h.ι = k := h.hι.fac (KernelFork.ofι k hk) WalkingParallelPair.zero lemma isIso_p (hf : S.f = 0) : IsIso h.p := ⟨h.descQ (𝟙 S.X₂) (by rw [hf, comp_id]), p_descQ _ _ _, by simp only [← cancel_epi h.p, p_descQ_assoc, id_comp, comp_id]⟩ lemma isIso_ι (hg : S.g = 0) : IsIso h.ι := by have ⟨φ, hφ⟩ := KernelFork.IsLimit.lift' h.hι' (𝟙 _) (by rw [← cancel_epi h.p, id_comp, p_g', comp_zero, hg]) dsimp at hφ exact ⟨φ, by rw [← cancel_mono h.ι, assoc, hφ, comp_id, id_comp], hφ⟩ variable (S) /-- When the first map `S.f` is zero, this is the right homology data on `S` given by any limit kernel fork of `S.g` -/ @[simps] def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : S.RightHomologyData where Q := S.X₂ H := c.pt p := 𝟙 _ ι := c.ι wp := by rw [comp_id, hf] hp := CokernelCofork.IsColimit.ofId _ hf wι := KernelFork.condition _ hι := IsLimit.ofIsoLimit hc (Fork.ext (Iso.refl _) (by simp)) @[simp] lemma ofIsLimitKernelFork_g' (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : (ofIsLimitKernelFork S hf c hc).g' = S.g := by rw [← cancel_epi (ofIsLimitKernelFork S hf c hc).p, p_g', ofIsLimitKernelFork_p, id_comp] /-- When the first map `S.f` is zero, this is the right homology data on `S` given by the chosen `kernel S.g` -/ @[simps!] noncomputable def ofHasKernel [HasKernel S.g] (hf : S.f = 0) : S.RightHomologyData := ofIsLimitKernelFork S hf _ (kernelIsKernel _) /-- When the second map `S.g` is zero, this is the right homology data on `S` given by any colimit cokernel cofork of `S.g` -/ @[simps] def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : S.RightHomologyData where Q := c.pt H := c.pt p := c.π ι := 𝟙 _ wp := CokernelCofork.condition _ hp := IsColimit.ofIsoColimit hc (Cofork.ext (Iso.refl _) (by simp)) wι := Cofork.IsColimit.hom_ext hc (by simp [hg]) hι := KernelFork.IsLimit.ofId _ (Cofork.IsColimit.hom_ext hc (by simp [hg])) @[simp] lemma ofIsColimitCokernelCofork_g' (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : (ofIsColimitCokernelCofork S hg c hc).g' = 0 := by rw [← cancel_epi (ofIsColimitCokernelCofork S hg c hc).p, p_g', hg, comp_zero] /-- When the second map `S.g` is zero, this is the right homology data on `S` given by the chosen `cokernel S.f` -/ @[simp] noncomputable def ofHasCokernel [HasCokernel S.f] (hg : S.g = 0) : S.RightHomologyData := ofIsColimitCokernelCofork S hg _ (cokernelIsCokernel _) /-- When both `S.f` and `S.g` are zero, the middle object `S.X₂` gives a right homology data on S -/ @[simps] def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.RightHomologyData where Q := S.X₂ H := S.X₂ p := 𝟙 _ ι := 𝟙 _ wp := by rw [comp_id, hf] hp := CokernelCofork.IsColimit.ofId _ hf wι := by change 𝟙 _ ≫ S.g = 0 simp only [hg, comp_zero] hι := KernelFork.IsLimit.ofId _ hg @[simp] lemma ofZeros_g' (hf : S.f = 0) (hg : S.g = 0) : (ofZeros S hf hg).g' = 0 := by rw [← cancel_epi ((ofZeros S hf hg).p), comp_zero, p_g', hg] variable {S} in /-- Given a right homology data `h` of a short complex `S`, we can construct another right homology data by choosing another cokernel and kernel that are isomorphic to the ones in `h`. -/ @[simps] def copy {Q' H' : C} (eQ : Q' ≅ h.Q) (eH : H' ≅ h.H) : S.RightHomologyData where Q := Q' H := H' p := h.p ≫ eQ.inv ι := eH.hom ≫ h.ι ≫ eQ.inv wp := by rw [← assoc, h.wp, zero_comp] hp := IsCokernel.cokernelIso _ _ h.hp eQ.symm (by simp) wι := by simp [IsCokernel.cokernelIso] hι := IsLimit.equivOfNatIsoOfIso (parallelPair.ext eQ.symm (Iso.refl S.X₃) (by simp [IsCokernel.cokernelIso]) (by simp)) _ _ (Cones.ext (by exact eH.symm) (by rintro (_ | _) <;> simp [IsCokernel.cokernelIso])) h.hι end RightHomologyData /-- A short complex `S` has right homology when there exists a `S.RightHomologyData` -/ class HasRightHomology : Prop where condition : Nonempty S.RightHomologyData /-- A chosen `S.RightHomologyData` for a short complex `S` that has right homology -/ noncomputable def rightHomologyData [HasRightHomology S] : S.RightHomologyData := HasRightHomology.condition.some variable {S} namespace HasRightHomology lemma mk' (h : S.RightHomologyData) : HasRightHomology S := ⟨Nonempty.intro h⟩ instance of_hasCokernel_of_hasKernel [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasCokernelOfHasKernel S) instance of_hasKernel {Y Z : C} (g : Y ⟶ Z) (X : C) [HasKernel g] : (ShortComplex.mk (0 : X ⟶ Y) g zero_comp).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasKernel _ rfl) instance of_hasCokernel {X Y : C} (f : X ⟶ Y) (Z : C) [HasCokernel f] : (ShortComplex.mk f (0 : Y ⟶ Z) comp_zero).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasCokernel _ rfl) instance of_zeros (X Y Z : C) : (ShortComplex.mk (0 : X ⟶ Y) (0 : Y ⟶ Z) zero_comp).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofZeros _ rfl rfl) end HasRightHomology namespace RightHomologyData /-- A right homology data for a short complex `S` induces a left homology data for `S.op`. -/ @[simps] def op (h : S.RightHomologyData) : S.op.LeftHomologyData where K := Opposite.op h.Q H := Opposite.op h.H i := h.p.op π := h.ι.op wi := Quiver.Hom.unop_inj h.wp hi := CokernelCofork.IsColimit.ofπOp _ _ h.hp wπ := Quiver.Hom.unop_inj h.wι hπ := KernelFork.IsLimit.ofιOp _ _ h.hι @[simp] lemma op_f' (h : S.RightHomologyData) : h.op.f' = h.g'.op := rfl /-- A right homology data for a short complex `S` in the opposite category induces a left homology data for `S.unop`. -/ @[simps] def unop {S : ShortComplex Cᵒᵖ} (h : S.RightHomologyData) : S.unop.LeftHomologyData where K := Opposite.unop h.Q H := Opposite.unop h.H i := h.p.unop π := h.ι.unop wi := Quiver.Hom.op_inj h.wp hi := CokernelCofork.IsColimit.ofπUnop _ _ h.hp wπ := Quiver.Hom.op_inj h.wι hπ := KernelFork.IsLimit.ofιUnop _ _ h.hι @[simp] lemma unop_f' {S : ShortComplex Cᵒᵖ} (h : S.RightHomologyData) : h.unop.f' = h.g'.unop := rfl end RightHomologyData namespace LeftHomologyData /-- A left homology data for a short complex `S` induces a right homology data for `S.op`. -/ @[simps] def op (h : S.LeftHomologyData) : S.op.RightHomologyData where Q := Opposite.op h.K H := Opposite.op h.H p := h.i.op ι := h.π.op wp := Quiver.Hom.unop_inj h.wi hp := KernelFork.IsLimit.ofιOp _ _ h.hi wι := Quiver.Hom.unop_inj h.wπ hι := CokernelCofork.IsColimit.ofπOp _ _ h.hπ @[simp] lemma op_g' (h : S.LeftHomologyData) : h.op.g' = h.f'.op := rfl /-- A left homology data for a short complex `S` in the opposite category induces a right homology data for `S.unop`. -/ @[simps] def unop {S : ShortComplex Cᵒᵖ} (h : S.LeftHomologyData) : S.unop.RightHomologyData where Q := Opposite.unop h.K H := Opposite.unop h.H p := h.i.unop ι := h.π.unop wp := Quiver.Hom.op_inj h.wi hp := KernelFork.IsLimit.ofιUnop _ _ h.hi wι := Quiver.Hom.op_inj h.wπ hι := CokernelCofork.IsColimit.ofπUnop _ _ h.hπ @[simp] lemma unop_g' {S : ShortComplex Cᵒᵖ} (h : S.LeftHomologyData) : h.unop.g' = h.f'.unop := rfl end LeftHomologyData instance [S.HasLeftHomology] : HasRightHomology S.op := HasRightHomology.mk' S.leftHomologyData.op instance [S.HasRightHomology] : HasLeftHomology S.op := HasLeftHomology.mk' S.rightHomologyData.op lemma hasLeftHomology_iff_op (S : ShortComplex C) : S.HasLeftHomology ↔ S.op.HasRightHomology := ⟨fun _ => inferInstance, fun _ => HasLeftHomology.mk' S.op.rightHomologyData.unop⟩ lemma hasRightHomology_iff_op (S : ShortComplex C) : S.HasRightHomology ↔ S.op.HasLeftHomology := ⟨fun _ => inferInstance, fun _ => HasRightHomology.mk' S.op.leftHomologyData.unop⟩ lemma hasLeftHomology_iff_unop (S : ShortComplex Cᵒᵖ) : S.HasLeftHomology ↔ S.unop.HasRightHomology := S.unop.hasRightHomology_iff_op.symm lemma hasRightHomology_iff_unop (S : ShortComplex Cᵒᵖ) : S.HasRightHomology ↔ S.unop.HasLeftHomology := S.unop.hasLeftHomology_iff_op.symm section variable (φ : S₁ ⟶ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) /-- Given right homology data `h₁` and `h₂` for two short complexes `S₁` and `S₂`, a `RightHomologyMapData` for a morphism `φ : S₁ ⟶ S₂` consists of a description of the induced morphisms on the `Q` (opcycles) and `H` (right homology) fields of `h₁` and `h₂`. -/ structure RightHomologyMapData where /-- the induced map on opcycles -/ φQ : h₁.Q ⟶ h₂.Q /-- the induced map on right homology -/ φH : h₁.H ⟶ h₂.H /-- commutation with `p` -/ commp : h₁.p ≫ φQ = φ.τ₂ ≫ h₂.p := by cat_disch /-- commutation with `g'` -/ commg' : φQ ≫ h₂.g' = h₁.g' ≫ φ.τ₃ := by cat_disch /-- commutation with `ι` -/ commι : φH ≫ h₂.ι = h₁.ι ≫ φQ := by cat_disch namespace RightHomologyMapData attribute [reassoc (attr := simp)] commp commg' commι /-- The right homology map data associated to the zero morphism between two short complexes. -/ @[simps] def zero (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : RightHomologyMapData 0 h₁ h₂ where φQ := 0 φH := 0 /-- The right homology map data associated to the identity morphism of a short complex. -/ @[simps] def id (h : S.RightHomologyData) : RightHomologyMapData (𝟙 S) h h where φQ := 𝟙 _ φH := 𝟙 _ /-- The composition of right homology map data. -/ @[simps] def comp {φ : S₁ ⟶ S₂} {φ' : S₂ ⟶ S₃} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} {h₃ : S₃.RightHomologyData} (ψ : RightHomologyMapData φ h₁ h₂) (ψ' : RightHomologyMapData φ' h₂ h₃) : RightHomologyMapData (φ ≫ φ') h₁ h₃ where φQ := ψ.φQ ≫ ψ'.φQ φH := ψ.φH ≫ ψ'.φH instance : Subsingleton (RightHomologyMapData φ h₁ h₂) := ⟨fun ψ₁ ψ₂ => by have hQ : ψ₁.φQ = ψ₂.φQ := by rw [← cancel_epi h₁.p, commp, commp] have hH : ψ₁.φH = ψ₂.φH := by rw [← cancel_mono h₂.ι, commι, commι, hQ] cases ψ₁ cases ψ₂ congr⟩ instance : Inhabited (RightHomologyMapData φ h₁ h₂) := ⟨by let φQ : h₁.Q ⟶ h₂.Q := h₁.descQ (φ.τ₂ ≫ h₂.p) (by rw [← φ.comm₁₂_assoc, h₂.wp, comp_zero]) have commg' : φQ ≫ h₂.g' = h₁.g' ≫ φ.τ₃ := by rw [← cancel_epi h₁.p, RightHomologyData.p_descQ_assoc, assoc, RightHomologyData.p_g', φ.comm₂₃, RightHomologyData.p_g'_assoc] let φH : h₁.H ⟶ h₂.H := h₂.liftH (h₁.ι ≫ φQ) (by rw [assoc, commg', RightHomologyData.ι_g'_assoc, zero_comp]) exact ⟨φQ, φH, by simp [φQ], commg', by simp [φH]⟩⟩ instance : Unique (RightHomologyMapData φ h₁ h₂) := Unique.mk' _ variable {φ h₁ h₂} lemma congr_φH {γ₁ γ₂ : RightHomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.φH = γ₂.φH := by rw [eq] lemma congr_φQ {γ₁ γ₂ : RightHomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.φQ = γ₂.φQ := by rw [eq] /-- When `S₁.f`, `S₁.g`, `S₂.f` and `S₂.g` are all zero, the action on right homology of a morphism `φ : S₁ ⟶ S₂` is given by the action `φ.τ₂` on the middle objects. -/ @[simps] def ofZeros (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) (hg₂ : S₂.g = 0) : RightHomologyMapData φ (RightHomologyData.ofZeros S₁ hf₁ hg₁) (RightHomologyData.ofZeros S₂ hf₂ hg₂) where φQ := φ.τ₂ φH := φ.τ₂ /-- When `S₁.f` and `S₂.f` are zero and we have chosen limit kernel forks `c₁` and `c₂` for `S₁.g` and `S₂.g` respectively, the action on right homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι`. -/ @[simps] def ofIsLimitKernelFork (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (c₁ : KernelFork S₁.g) (hc₁ : IsLimit c₁) (hf₂ : S₂.f = 0) (c₂ : KernelFork S₂.g) (hc₂ : IsLimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι) : RightHomologyMapData φ (RightHomologyData.ofIsLimitKernelFork S₁ hf₁ c₁ hc₁) (RightHomologyData.ofIsLimitKernelFork S₂ hf₂ c₂ hc₂) where φQ := φ.τ₂ φH := f commg' := by simp only [RightHomologyData.ofIsLimitKernelFork_g', φ.comm₂₃] commι := comm.symm /-- When `S₁.g` and `S₂.g` are zero and we have chosen colimit cokernel coforks `c₁` and `c₂` for `S₁.f` and `S₂.f` respectively, the action on right homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `φ.τ₂ ≫ c₂.π = c₁.π ≫ f`. -/ @[simps] def ofIsColimitCokernelCofork (φ : S₁ ⟶ S₂) (hg₁ : S₁.g = 0) (c₁ : CokernelCofork S₁.f) (hc₁ : IsColimit c₁) (hg₂ : S₂.g = 0) (c₂ : CokernelCofork S₂.f) (hc₂ : IsColimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : φ.τ₂ ≫ c₂.π = c₁.π ≫ f) : RightHomologyMapData φ (RightHomologyData.ofIsColimitCokernelCofork S₁ hg₁ c₁ hc₁) (RightHomologyData.ofIsColimitCokernelCofork S₂ hg₂ c₂ hc₂) where φQ := f φH := f commp := comm.symm variable (S) /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the right homology map data (for the identity of `S`) which relates the right homology data `RightHomologyData.ofIsLimitKernelFork` and `ofZeros` . -/ @[simps] def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0) (c : KernelFork S.g) (hc : IsLimit c) : RightHomologyMapData (𝟙 S) (RightHomologyData.ofIsLimitKernelFork S hf c hc) (RightHomologyData.ofZeros S hf hg) where φQ := 𝟙 _ φH := c.ι /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the right homology map data (for the identity of `S`) which relates the right homology data `ofZeros` and `ofIsColimitCokernelCofork`. -/ @[simps] def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : RightHomologyMapData (𝟙 S) (RightHomologyData.ofZeros S hf hg) (RightHomologyData.ofIsColimitCokernelCofork S hg c hc) where φQ := c.π φH := c.π end RightHomologyMapData end section variable (S) variable [S.HasRightHomology] /-- The right homology of a short complex, given by the `H` field of a chosen right homology data. -/ noncomputable def rightHomology : C := S.rightHomologyData.H -- `S.rightHomology` is the simp normal form. @[simp] lemma rightHomologyData_H : S.rightHomologyData.H = S.rightHomology := rfl /-- The "opcycles" of a short complex, given by the `Q` field of a chosen right homology data. This is the dual notion to cycles. -/ noncomputable def opcycles : C := S.rightHomologyData.Q /-- The canonical map `S.rightHomology ⟶ S.opcycles`. -/ noncomputable def rightHomologyι : S.rightHomology ⟶ S.opcycles := S.rightHomologyData.ι /-- The projection `S.X₂ ⟶ S.opcycles`. -/ noncomputable def pOpcycles : S.X₂ ⟶ S.opcycles := S.rightHomologyData.p /-- The canonical map `S.opcycles ⟶ X₃`. -/ noncomputable def fromOpcycles : S.opcycles ⟶ S.X₃ := S.rightHomologyData.g' @[reassoc (attr := simp)] lemma f_pOpcycles : S.f ≫ S.pOpcycles = 0 := S.rightHomologyData.wp @[reassoc (attr := simp)] lemma p_fromOpcycles : S.pOpcycles ≫ S.fromOpcycles = S.g := S.rightHomologyData.p_g' instance : Epi S.pOpcycles := by dsimp only [pOpcycles] infer_instance instance : Mono S.rightHomologyι := by dsimp only [rightHomologyι] infer_instance lemma rightHomology_ext_iff {A : C} (f₁ f₂ : A ⟶ S.rightHomology) : f₁ = f₂ ↔ f₁ ≫ S.rightHomologyι = f₂ ≫ S.rightHomologyι := by rw [cancel_mono] @[ext] lemma rightHomology_ext {A : C} (f₁ f₂ : A ⟶ S.rightHomology) (h : f₁ ≫ S.rightHomologyι = f₂ ≫ S.rightHomologyι) : f₁ = f₂ := by simpa only [rightHomology_ext_iff] lemma opcycles_ext_iff {A : C} (f₁ f₂ : S.opcycles ⟶ A) : f₁ = f₂ ↔ S.pOpcycles ≫ f₁ = S.pOpcycles ≫ f₂ := by rw [cancel_epi] @[ext] lemma opcycles_ext {A : C} (f₁ f₂ : S.opcycles ⟶ A) (h : S.pOpcycles ≫ f₁ = S.pOpcycles ≫ f₂) : f₁ = f₂ := by simpa only [opcycles_ext_iff] lemma isIso_pOpcycles (hf : S.f = 0) : IsIso S.pOpcycles := RightHomologyData.isIso_p _ hf /-- When `S.f = 0`, this is the canonical isomorphism `S.opcycles ≅ S.X₂` induced by `S.pOpcycles`. -/ @[simps! inv] noncomputable def opcyclesIsoX₂ (hf : S.f = 0) : S.opcycles ≅ S.X₂ := by have := S.isIso_pOpcycles hf exact (asIso S.pOpcycles).symm @[reassoc (attr := simp)] lemma opcyclesIsoX₂_inv_hom_id (hf : S.f = 0) : S.pOpcycles ≫ (S.opcyclesIsoX₂ hf).hom = 𝟙 _ := (S.opcyclesIsoX₂ hf).inv_hom_id @[reassoc (attr := simp)] lemma opcyclesIsoX₂_hom_inv_id (hf : S.f = 0) : (S.opcyclesIsoX₂ hf).hom ≫ S.pOpcycles = 𝟙 _ := (S.opcyclesIsoX₂ hf).hom_inv_id lemma isIso_rightHomologyι (hg : S.g = 0) : IsIso S.rightHomologyι := RightHomologyData.isIso_ι _ hg /-- When `S.g = 0`, this is the canonical isomorphism `S.opcycles ≅ S.rightHomology` induced by `S.rightHomologyι`. -/ @[simps! inv] noncomputable def opcyclesIsoRightHomology (hg : S.g = 0) : S.opcycles ≅ S.rightHomology := by have := S.isIso_rightHomologyι hg exact (asIso S.rightHomologyι).symm @[reassoc (attr := simp)] lemma opcyclesIsoRightHomology_inv_hom_id (hg : S.g = 0) : S.rightHomologyι ≫ (S.opcyclesIsoRightHomology hg).hom = 𝟙 _ := (S.opcyclesIsoRightHomology hg).inv_hom_id @[reassoc (attr := simp)] lemma opcyclesIsoRightHomology_hom_inv_id (hg : S.g = 0) : (S.opcyclesIsoRightHomology hg).hom ≫ S.rightHomologyι = 𝟙 _ := (S.opcyclesIsoRightHomology hg).hom_inv_id end section variable (φ : S₁ ⟶ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) /-- The (unique) right homology map data associated to a morphism of short complexes that are both equipped with right homology data. -/ def rightHomologyMapData : RightHomologyMapData φ h₁ h₂ := default /-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and right homology data `h₁` and `h₂` for `S₁` and `S₂` respectively, this is the induced right homology map `h₁.H ⟶ h₁.H`. -/ def rightHomologyMap' : h₁.H ⟶ h₂.H := (rightHomologyMapData φ _ _).φH /-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and right homology data `h₁` and `h₂` for `S₁` and `S₂` respectively, this is the induced morphism `h₁.K ⟶ h₁.K` on opcycles. -/ def opcyclesMap' : h₁.Q ⟶ h₂.Q := (rightHomologyMapData φ _ _).φQ @[reassoc (attr := simp)] lemma p_opcyclesMap' : h₁.p ≫ opcyclesMap' φ h₁ h₂ = φ.τ₂ ≫ h₂.p := RightHomologyMapData.commp _ @[reassoc (attr := simp)] lemma opcyclesMap'_g' : opcyclesMap' φ h₁ h₂ ≫ h₂.g' = h₁.g' ≫ φ.τ₃ := by simp only [← cancel_epi h₁.p, φ.comm₂₃, p_opcyclesMap'_assoc, RightHomologyData.p_g'_assoc, RightHomologyData.p_g'] @[reassoc (attr := simp)] lemma rightHomologyι_naturality' : rightHomologyMap' φ h₁ h₂ ≫ h₂.ι = h₁.ι ≫ opcyclesMap' φ h₁ h₂ := RightHomologyMapData.commι _ end section variable [HasRightHomology S₁] [HasRightHomology S₂] (φ : S₁ ⟶ S₂) /-- The (right) homology map `S₁.rightHomology ⟶ S₂.rightHomology` induced by a morphism `S₁ ⟶ S₂` of short complexes. -/ noncomputable def rightHomologyMap : S₁.rightHomology ⟶ S₂.rightHomology := rightHomologyMap' φ _ _ /-- The morphism `S₁.opcycles ⟶ S₂.opcycles` induced by a morphism `S₁ ⟶ S₂` of short complexes. -/ noncomputable def opcyclesMap : S₁.opcycles ⟶ S₂.opcycles := opcyclesMap' φ _ _ @[reassoc (attr := simp)] lemma p_opcyclesMap : S₁.pOpcycles ≫ opcyclesMap φ = φ.τ₂ ≫ S₂.pOpcycles := p_opcyclesMap' _ _ _ @[reassoc (attr := simp)] lemma fromOpcycles_naturality : opcyclesMap φ ≫ S₂.fromOpcycles = S₁.fromOpcycles ≫ φ.τ₃ := opcyclesMap'_g' _ _ _ @[reassoc (attr := simp)] lemma rightHomologyι_naturality : rightHomologyMap φ ≫ S₂.rightHomologyι = S₁.rightHomologyι ≫ opcyclesMap φ := rightHomologyι_naturality' _ _ _ end namespace RightHomologyMapData variable {φ : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (γ : RightHomologyMapData φ h₁ h₂) lemma rightHomologyMap'_eq : rightHomologyMap' φ h₁ h₂ = γ.φH := RightHomologyMapData.congr_φH (Subsingleton.elim _ _) lemma opcyclesMap'_eq : opcyclesMap' φ h₁ h₂ = γ.φQ := RightHomologyMapData.congr_φQ (Subsingleton.elim _ _) end RightHomologyMapData @[simp] lemma rightHomologyMap'_id (h : S.RightHomologyData) : rightHomologyMap' (𝟙 S) h h = 𝟙 _ := (RightHomologyMapData.id h).rightHomologyMap'_eq @[simp] lemma opcyclesMap'_id (h : S.RightHomologyData) : opcyclesMap' (𝟙 S) h h = 𝟙 _ := (RightHomologyMapData.id h).opcyclesMap'_eq variable (S) @[simp] lemma rightHomologyMap_id [HasRightHomology S] : rightHomologyMap (𝟙 S) = 𝟙 _ := rightHomologyMap'_id _ @[simp] lemma opcyclesMap_id [HasRightHomology S] : opcyclesMap (𝟙 S) = 𝟙 _ := opcyclesMap'_id _ @[simp] lemma rightHomologyMap'_zero (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : rightHomologyMap' 0 h₁ h₂ = 0 := (RightHomologyMapData.zero h₁ h₂).rightHomologyMap'_eq @[simp] lemma opcyclesMap'_zero (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : opcyclesMap' 0 h₁ h₂ = 0 := (RightHomologyMapData.zero h₁ h₂).opcyclesMap'_eq variable (S₁ S₂) @[simp] lemma rightHomologyMap_zero [HasRightHomology S₁] [HasRightHomology S₂] : rightHomologyMap (0 : S₁ ⟶ S₂) = 0 := rightHomologyMap'_zero _ _ @[simp] lemma opcyclesMap_zero [HasRightHomology S₁] [HasRightHomology S₂] : opcyclesMap (0 : S₁ ⟶ S₂) = 0 := opcyclesMap'_zero _ _ variable {S₁ S₂} @[reassoc] lemma rightHomologyMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) (h₃ : S₃.RightHomologyData) : rightHomologyMap' (φ₁ ≫ φ₂) h₁ h₃ = rightHomologyMap' φ₁ h₁ h₂ ≫ rightHomologyMap' φ₂ h₂ h₃ := by let γ₁ := rightHomologyMapData φ₁ h₁ h₂ let γ₂ := rightHomologyMapData φ₂ h₂ h₃ rw [γ₁.rightHomologyMap'_eq, γ₂.rightHomologyMap'_eq, (γ₁.comp γ₂).rightHomologyMap'_eq, RightHomologyMapData.comp_φH] @[reassoc] lemma opcyclesMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) (h₃ : S₃.RightHomologyData) : opcyclesMap' (φ₁ ≫ φ₂) h₁ h₃ = opcyclesMap' φ₁ h₁ h₂ ≫ opcyclesMap' φ₂ h₂ h₃ := by let γ₁ := rightHomologyMapData φ₁ h₁ h₂ let γ₂ := rightHomologyMapData φ₂ h₂ h₃ rw [γ₁.opcyclesMap'_eq, γ₂.opcyclesMap'_eq, (γ₁.comp γ₂).opcyclesMap'_eq, RightHomologyMapData.comp_φQ] @[simp] lemma rightHomologyMap_comp [HasRightHomology S₁] [HasRightHomology S₂] [HasRightHomology S₃] (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) : rightHomologyMap (φ₁ ≫ φ₂) = rightHomologyMap φ₁ ≫ rightHomologyMap φ₂ := rightHomologyMap'_comp _ _ _ _ _ @[simp] lemma opcyclesMap_comp [HasRightHomology S₁] [HasRightHomology S₂] [HasRightHomology S₃] (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) : opcyclesMap (φ₁ ≫ φ₂) = opcyclesMap φ₁ ≫ opcyclesMap φ₂ := opcyclesMap'_comp _ _ _ _ _ attribute [simp] rightHomologyMap_comp opcyclesMap_comp /-- An isomorphism of short complexes `S₁ ≅ S₂` induces an isomorphism on the `H` fields of right homology data of `S₁` and `S₂`. -/ @[simps] def rightHomologyMapIso' (e : S₁ ≅ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : h₁.H ≅ h₂.H where hom := rightHomologyMap' e.hom h₁ h₂ inv := rightHomologyMap' e.inv h₂ h₁ hom_inv_id := by rw [← rightHomologyMap'_comp, e.hom_inv_id, rightHomologyMap'_id] inv_hom_id := by rw [← rightHomologyMap'_comp, e.inv_hom_id, rightHomologyMap'_id] instance isIso_rightHomologyMap'_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ] (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : IsIso (rightHomologyMap' φ h₁ h₂) := (inferInstance : IsIso (rightHomologyMapIso' (asIso φ) h₁ h₂).hom) /-- An isomorphism of short complexes `S₁ ≅ S₂` induces an isomorphism on the `Q` fields of right homology data of `S₁` and `S₂`. -/ @[simps] def opcyclesMapIso' (e : S₁ ≅ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : h₁.Q ≅ h₂.Q where hom := opcyclesMap' e.hom h₁ h₂ inv := opcyclesMap' e.inv h₂ h₁ hom_inv_id := by rw [← opcyclesMap'_comp, e.hom_inv_id, opcyclesMap'_id] inv_hom_id := by rw [← opcyclesMap'_comp, e.inv_hom_id, opcyclesMap'_id] instance isIso_opcyclesMap'_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ] (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : IsIso (opcyclesMap' φ h₁ h₂) := (inferInstance : IsIso (opcyclesMapIso' (asIso φ) h₁ h₂).hom) /-- The isomorphism `S₁.rightHomology ≅ S₂.rightHomology` induced by an isomorphism of short complexes `S₁ ≅ S₂`. -/ @[simps] noncomputable def rightHomologyMapIso (e : S₁ ≅ S₂) [S₁.HasRightHomology] [S₂.HasRightHomology] : S₁.rightHomology ≅ S₂.rightHomology where hom := rightHomologyMap e.hom inv := rightHomologyMap e.inv hom_inv_id := by rw [← rightHomologyMap_comp, e.hom_inv_id, rightHomologyMap_id] inv_hom_id := by rw [← rightHomologyMap_comp, e.inv_hom_id, rightHomologyMap_id] instance isIso_rightHomologyMap_of_iso (φ : S₁ ⟶ S₂) [IsIso φ] [S₁.HasRightHomology] [S₂.HasRightHomology] : IsIso (rightHomologyMap φ) := (inferInstance : IsIso (rightHomologyMapIso (asIso φ)).hom) /-- The isomorphism `S₁.opcycles ≅ S₂.opcycles` induced by an isomorphism of short complexes `S₁ ≅ S₂`. -/ @[simps] noncomputable def opcyclesMapIso (e : S₁ ≅ S₂) [S₁.HasRightHomology] [S₂.HasRightHomology] : S₁.opcycles ≅ S₂.opcycles where hom := opcyclesMap e.hom inv := opcyclesMap e.inv hom_inv_id := by rw [← opcyclesMap_comp, e.hom_inv_id, opcyclesMap_id] inv_hom_id := by rw [← opcyclesMap_comp, e.inv_hom_id, opcyclesMap_id] instance isIso_opcyclesMap_of_iso (φ : S₁ ⟶ S₂) [IsIso φ] [S₁.HasRightHomology] [S₂.HasRightHomology] : IsIso (opcyclesMap φ) := (inferInstance : IsIso (opcyclesMapIso (asIso φ)).hom) variable {S} namespace RightHomologyData variable (h : S.RightHomologyData) [S.HasRightHomology] /-- The isomorphism `S.rightHomology ≅ h.H` induced by a right homology data `h` for a short complex `S`. -/ noncomputable def rightHomologyIso : S.rightHomology ≅ h.H := rightHomologyMapIso' (Iso.refl _) _ _ /-- The isomorphism `S.opcycles ≅ h.Q` induced by a right homology data `h` for a short complex `S`. -/ noncomputable def opcyclesIso : S.opcycles ≅ h.Q := opcyclesMapIso' (Iso.refl _) _ _ @[reassoc (attr := simp)] lemma p_comp_opcyclesIso_inv : h.p ≫ h.opcyclesIso.inv = S.pOpcycles := by dsimp [pOpcycles, RightHomologyData.opcyclesIso] simp only [p_opcyclesMap', id_τ₂, id_comp] @[reassoc (attr := simp)] lemma pOpcycles_comp_opcyclesIso_hom : S.pOpcycles ≫ h.opcyclesIso.hom = h.p := by simp only [← h.p_comp_opcyclesIso_inv, assoc, Iso.inv_hom_id, comp_id] @[reassoc (attr := simp)] lemma rightHomologyIso_inv_comp_rightHomologyι : h.rightHomologyIso.inv ≫ S.rightHomologyι = h.ι ≫ h.opcyclesIso.inv := by dsimp only [rightHomologyι, rightHomologyIso, opcyclesIso, rightHomologyMapIso', opcyclesMapIso', Iso.refl] rw [rightHomologyι_naturality'] @[reassoc (attr := simp)] lemma rightHomologyIso_hom_comp_ι : h.rightHomologyIso.hom ≫ h.ι = S.rightHomologyι ≫ h.opcyclesIso.hom := by simp only [← cancel_mono h.opcyclesIso.inv, ← cancel_epi h.rightHomologyIso.inv, assoc, Iso.inv_hom_id_assoc, Iso.hom_inv_id, comp_id, rightHomologyIso_inv_comp_rightHomologyι] end RightHomologyData namespace RightHomologyMapData variable {φ : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (γ : RightHomologyMapData φ h₁ h₂) lemma rightHomologyMap_eq [S₁.HasRightHomology] [S₂.HasRightHomology] : rightHomologyMap φ = h₁.rightHomologyIso.hom ≫ γ.φH ≫ h₂.rightHomologyIso.inv := by dsimp [RightHomologyData.rightHomologyIso, rightHomologyMapIso'] rw [← γ.rightHomologyMap'_eq, ← rightHomologyMap'_comp, ← rightHomologyMap'_comp, id_comp, comp_id] rfl lemma opcyclesMap_eq [S₁.HasRightHomology] [S₂.HasRightHomology] : opcyclesMap φ = h₁.opcyclesIso.hom ≫ γ.φQ ≫ h₂.opcyclesIso.inv := by dsimp [RightHomologyData.opcyclesIso, cyclesMapIso'] rw [← γ.opcyclesMap'_eq, ← opcyclesMap'_comp, ← opcyclesMap'_comp, id_comp, comp_id] rfl lemma rightHomologyMap_comm [S₁.HasRightHomology] [S₂.HasRightHomology] : rightHomologyMap φ ≫ h₂.rightHomologyIso.hom = h₁.rightHomologyIso.hom ≫ γ.φH := by simp only [γ.rightHomologyMap_eq, assoc, Iso.inv_hom_id, comp_id] lemma opcyclesMap_comm [S₁.HasRightHomology] [S₂.HasRightHomology] : opcyclesMap φ ≫ h₂.opcyclesIso.hom = h₁.opcyclesIso.hom ≫ γ.φQ := by simp only [γ.opcyclesMap_eq, assoc, Iso.inv_hom_id, comp_id] end RightHomologyMapData section variable (C) variable [HasKernels C] [HasCokernels C] /-- The right homology functor `ShortComplex C ⥤ C`, where the right homology of a short complex `S` is understood as a kernel of the obvious map `S.fromOpcycles : S.opcycles ⟶ S.X₃` where `S.opcycles` is a cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ @[simps] noncomputable def rightHomologyFunctor : ShortComplex C ⥤ C where obj S := S.rightHomology map := rightHomologyMap /-- The opcycles functor `ShortComplex C ⥤ C` which sends a short complex `S` to `S.opcycles` which is a cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ @[simps] noncomputable def opcyclesFunctor : ShortComplex C ⥤ C where obj S := S.opcycles map := opcyclesMap /-- The natural transformation `S.rightHomology ⟶ S.opcycles` for all short complexes `S`. -/ @[simps] noncomputable def rightHomologyιNatTrans : rightHomologyFunctor C ⟶ opcyclesFunctor C where app S := rightHomologyι S naturality := fun _ _ φ => rightHomologyι_naturality φ /-- The natural transformation `S.X₂ ⟶ S.opcycles` for all short complexes `S`. -/ @[simps] noncomputable def pOpcyclesNatTrans : ShortComplex.π₂ ⟶ opcyclesFunctor C where app S := S.pOpcycles /-- The natural transformation `S.opcycles ⟶ S.X₃` for all short complexes `S`. -/ @[simps] noncomputable def fromOpcyclesNatTrans : opcyclesFunctor C ⟶ π₃ where app S := S.fromOpcycles naturality := fun _ _ φ => fromOpcycles_naturality φ end /-- A left homology map data for a morphism of short complexes induces a right homology map data in the opposite category. -/ @[simps] def LeftHomologyMapData.op {S₁ S₂ : ShortComplex C} {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (ψ : LeftHomologyMapData φ h₁ h₂) : RightHomologyMapData (opMap φ) h₂.op h₁.op where φQ := ψ.φK.op φH := ψ.φH.op commp := Quiver.Hom.unop_inj (by simp) commg' := Quiver.Hom.unop_inj (by simp) commι := Quiver.Hom.unop_inj (by simp) /-- A left homology map data for a morphism of short complexes in the opposite category induces a right homology map data in the original category. -/ @[simps] def LeftHomologyMapData.unop {S₁ S₂ : ShortComplex Cᵒᵖ} {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (ψ : LeftHomologyMapData φ h₁ h₂) : RightHomologyMapData (unopMap φ) h₂.unop h₁.unop where φQ := ψ.φK.unop φH := ψ.φH.unop commp := Quiver.Hom.op_inj (by simp) commg' := Quiver.Hom.op_inj (by simp) commι := Quiver.Hom.op_inj (by simp) /-- A right homology map data for a morphism of short complexes induces a left homology map data in the opposite category. -/ @[simps] def RightHomologyMapData.op {S₁ S₂ : ShortComplex C} {φ : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (ψ : RightHomologyMapData φ h₁ h₂) : LeftHomologyMapData (opMap φ) h₂.op h₁.op where φK := ψ.φQ.op φH := ψ.φH.op commi := Quiver.Hom.unop_inj (by simp) commf' := Quiver.Hom.unop_inj (by simp) commπ := Quiver.Hom.unop_inj (by simp) /-- A right homology map data for a morphism of short complexes in the opposite category induces a left homology map data in the original category. -/ @[simps] def RightHomologyMapData.unop {S₁ S₂ : ShortComplex Cᵒᵖ} {φ : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (ψ : RightHomologyMapData φ h₁ h₂) : LeftHomologyMapData (unopMap φ) h₂.unop h₁.unop where φK := ψ.φQ.unop φH := ψ.φH.unop commi := Quiver.Hom.op_inj (by simp) commf' := Quiver.Hom.op_inj (by simp) commπ := Quiver.Hom.op_inj (by simp) variable (S) /-- The right homology in the opposite category of the opposite of a short complex identifies to the left homology of this short complex. -/ noncomputable def rightHomologyOpIso [S.HasLeftHomology] : S.op.rightHomology ≅ Opposite.op S.leftHomology := S.leftHomologyData.op.rightHomologyIso /-- The left homology in the opposite category of the opposite of a short complex identifies to the right homology of this short complex. -/ noncomputable def leftHomologyOpIso [S.HasRightHomology] : S.op.leftHomology ≅ Opposite.op S.rightHomology := S.rightHomologyData.op.leftHomologyIso /-- The opcycles in the opposite category of the opposite of a short complex identifies to the cycles of this short complex. -/ noncomputable def opcyclesOpIso [S.HasLeftHomology] : S.op.opcycles ≅ Opposite.op S.cycles := S.leftHomologyData.op.opcyclesIso /-- The cycles in the opposite category of the opposite of a short complex identifies to the opcycles of this short complex. -/ noncomputable def cyclesOpIso [S.HasRightHomology] : S.op.cycles ≅ Opposite.op S.opcycles := S.rightHomologyData.op.cyclesIso @[reassoc (attr := simp)] lemma opcyclesOpIso_hom_toCycles_op [S.HasLeftHomology] : S.opcyclesOpIso.hom ≫ S.toCycles.op = S.op.fromOpcycles := by dsimp [opcyclesOpIso, toCycles] rw [← cancel_epi S.op.pOpcycles, p_fromOpcycles, RightHomologyData.pOpcycles_comp_opcyclesIso_hom_assoc, LeftHomologyData.op_p, ← op_comp, LeftHomologyData.f'_i, op_g] @[reassoc (attr := simp)] lemma fromOpcycles_op_cyclesOpIso_inv [S.HasRightHomology] : S.fromOpcycles.op ≫ S.cyclesOpIso.inv = S.op.toCycles := by dsimp [cyclesOpIso, fromOpcycles] rw [← cancel_mono S.op.iCycles, assoc, toCycles_i, LeftHomologyData.cyclesIso_inv_comp_iCycles, RightHomologyData.op_i, ← op_comp, RightHomologyData.p_g', op_f] @[reassoc (attr := simp)] lemma op_pOpcycles_opcyclesOpIso_hom [S.HasLeftHomology] : S.op.pOpcycles ≫ S.opcyclesOpIso.hom = S.iCycles.op := by dsimp [opcyclesOpIso] rw [← S.leftHomologyData.op.p_comp_opcyclesIso_inv, assoc, Iso.inv_hom_id, comp_id] rfl @[reassoc (attr := simp)] lemma cyclesOpIso_inv_op_iCycles [S.HasRightHomology] : S.cyclesOpIso.inv ≫ S.op.iCycles = S.pOpcycles.op := by dsimp [cyclesOpIso] rw [← S.rightHomologyData.op.cyclesIso_hom_comp_i, Iso.inv_hom_id_assoc] rfl @[reassoc] lemma opcyclesOpIso_hom_naturality (φ : S₁ ⟶ S₂) [S₁.HasLeftHomology] [S₂.HasLeftHomology] : opcyclesMap (opMap φ) ≫ (S₁.opcyclesOpIso).hom = S₂.opcyclesOpIso.hom ≫ (cyclesMap φ).op := by rw [← cancel_epi S₂.op.pOpcycles, p_opcyclesMap_assoc, opMap_τ₂, op_pOpcycles_opcyclesOpIso_hom, op_pOpcycles_opcyclesOpIso_hom_assoc, ← op_comp, ← op_comp, cyclesMap_i] @[reassoc] lemma opcyclesOpIso_inv_naturality (φ : S₁ ⟶ S₂) [S₁.HasLeftHomology] [S₂.HasLeftHomology] : (cyclesMap φ).op ≫ (S₁.opcyclesOpIso).inv = S₂.opcyclesOpIso.inv ≫ opcyclesMap (opMap φ) := by rw [← cancel_epi (S₂.opcyclesOpIso.hom), Iso.hom_inv_id_assoc, ← opcyclesOpIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id] @[reassoc] lemma cyclesOpIso_inv_naturality (φ : S₁ ⟶ S₂) [S₁.HasRightHomology] [S₂.HasRightHomology] : (opcyclesMap φ).op ≫ (S₁.cyclesOpIso).inv = S₂.cyclesOpIso.inv ≫ cyclesMap (opMap φ) := by rw [← cancel_mono S₁.op.iCycles, assoc, assoc, cyclesOpIso_inv_op_iCycles, cyclesMap_i, cyclesOpIso_inv_op_iCycles_assoc, ← op_comp, p_opcyclesMap, op_comp, opMap_τ₂] @[reassoc] lemma cyclesOpIso_hom_naturality (φ : S₁ ⟶ S₂) [S₁.HasRightHomology] [S₂.HasRightHomology] : cyclesMap (opMap φ) ≫ (S₁.cyclesOpIso).hom = S₂.cyclesOpIso.hom ≫ (opcyclesMap φ).op := by rw [← cancel_mono (S₁.cyclesOpIso).inv, assoc, assoc, Iso.hom_inv_id, comp_id, cyclesOpIso_inv_naturality, Iso.hom_inv_id_assoc] @[simp] lemma leftHomologyMap'_op (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : (leftHomologyMap' φ h₁ h₂).op = rightHomologyMap' (opMap φ) h₂.op h₁.op := by let γ : LeftHomologyMapData φ h₁ h₂ := leftHomologyMapData φ h₁ h₂ simp only [γ.leftHomologyMap'_eq, γ.op.rightHomologyMap'_eq, LeftHomologyMapData.op_φH] lemma leftHomologyMap_op (φ : S₁ ⟶ S₂) [S₁.HasLeftHomology] [S₂.HasLeftHomology] : (leftHomologyMap φ).op = S₂.rightHomologyOpIso.inv ≫ rightHomologyMap (opMap φ) ≫ S₁.rightHomologyOpIso.hom := by dsimp [rightHomologyOpIso, RightHomologyData.rightHomologyIso, rightHomologyMap, leftHomologyMap] simp only [← rightHomologyMap'_comp, comp_id, id_comp, leftHomologyMap'_op] @[simp] lemma rightHomologyMap'_op (φ : S₁ ⟶ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : (rightHomologyMap' φ h₁ h₂).op = leftHomologyMap' (opMap φ) h₂.op h₁.op := by let γ : RightHomologyMapData φ h₁ h₂ := rightHomologyMapData φ h₁ h₂ simp only [γ.rightHomologyMap'_eq, γ.op.leftHomologyMap'_eq, RightHomologyMapData.op_φH] lemma rightHomologyMap_op (φ : S₁ ⟶ S₂) [S₁.HasRightHomology] [S₂.HasRightHomology] : (rightHomologyMap φ).op = S₂.leftHomologyOpIso.inv ≫ leftHomologyMap (opMap φ) ≫ S₁.leftHomologyOpIso.hom := by dsimp [leftHomologyOpIso, LeftHomologyData.leftHomologyIso, leftHomologyMap, rightHomologyMap] simp only [← leftHomologyMap'_comp, comp_id, id_comp, rightHomologyMap'_op] namespace RightHomologyData section variable (φ : S₁ ⟶ S₂) (h : RightHomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] /-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso and `φ.τ₃` is mono, then a right homology data for `S₁` induces a right homology data for `S₂` with the same `Q` and `H` fields. This is obtained by dualising `LeftHomologyData.ofEpiOfIsIsoOfMono'`. The inverse construction is `ofEpiOfIsIsoOfMono'`. -/ noncomputable def ofEpiOfIsIsoOfMono : RightHomologyData S₂ := by haveI : Epi (opMap φ).τ₁ := by dsimp; infer_instance haveI : IsIso (opMap φ).τ₂ := by dsimp; infer_instance haveI : Mono (opMap φ).τ₃ := by dsimp; infer_instance exact (LeftHomologyData.ofEpiOfIsIsoOfMono' (opMap φ) h.op).unop @[simp] lemma ofEpiOfIsIsoOfMono_Q : (ofEpiOfIsIsoOfMono φ h).Q = h.Q := rfl @[simp] lemma ofEpiOfIsIsoOfMono_H : (ofEpiOfIsIsoOfMono φ h).H = h.H := rfl @[simp] lemma ofEpiOfIsIsoOfMono_p : (ofEpiOfIsIsoOfMono φ h).p = inv φ.τ₂ ≫ h.p := by simp [ofEpiOfIsIsoOfMono, opMap] @[simp] lemma ofEpiOfIsIsoOfMono_ι : (ofEpiOfIsIsoOfMono φ h).ι = h.ι := rfl @[simp] lemma ofEpiOfIsIsoOfMono_g' : (ofEpiOfIsIsoOfMono φ h).g' = h.g' ≫ φ.τ₃ := by simp [ofEpiOfIsIsoOfMono, opMap] end section variable (φ : S₁ ⟶ S₂) (h : RightHomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] /-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso and `φ.τ₃` is mono, then a right homology data for `S₂` induces a right homology data for `S₁` with the same `Q` and `H` fields. This is obtained by dualising `LeftHomologyData.ofEpiOfIsIsoOfMono`. The inverse construction is `ofEpiOfIsIsoOfMono`. -/ noncomputable def ofEpiOfIsIsoOfMono' : RightHomologyData S₁ := by haveI : Epi (opMap φ).τ₁ := by dsimp; infer_instance haveI : IsIso (opMap φ).τ₂ := by dsimp; infer_instance haveI : Mono (opMap φ).τ₃ := by dsimp; infer_instance exact (LeftHomologyData.ofEpiOfIsIsoOfMono (opMap φ) h.op).unop @[simp] lemma ofEpiOfIsIsoOfMono'_Q : (ofEpiOfIsIsoOfMono' φ h).Q = h.Q := rfl @[simp] lemma ofEpiOfIsIsoOfMono'_H : (ofEpiOfIsIsoOfMono' φ h).H = h.H := rfl @[simp] lemma ofEpiOfIsIsoOfMono'_p : (ofEpiOfIsIsoOfMono' φ h).p = φ.τ₂ ≫ h.p := by simp [ofEpiOfIsIsoOfMono', opMap] @[simp] lemma ofEpiOfIsIsoOfMono'_ι : (ofEpiOfIsIsoOfMono' φ h).ι = h.ι := rfl @[simp] lemma ofEpiOfIsIsoOfMono'_g'_τ₃ : (ofEpiOfIsIsoOfMono' φ h).g' ≫ φ.τ₃ = h.g' := by rw [← cancel_epi (ofEpiOfIsIsoOfMono' φ h).p, p_g'_assoc, ofEpiOfIsIsoOfMono'_p, assoc, p_g', φ.comm₂₃] end /-- If `e : S₁ ≅ S₂` is an isomorphism of short complexes and `h₁ : RightHomologyData S₁`, this is the right homology data for `S₂` deduced from the isomorphism. -/ noncomputable def ofIso (e : S₁ ≅ S₂) (h₁ : RightHomologyData S₁) : RightHomologyData S₂ := h₁.ofEpiOfIsIsoOfMono e.hom end RightHomologyData lemma hasRightHomology_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [HasRightHomology S₁] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasRightHomology S₂ := HasRightHomology.mk' (RightHomologyData.ofEpiOfIsIsoOfMono φ S₁.rightHomologyData) lemma hasRightHomology_of_epi_of_isIso_of_mono' (φ : S₁ ⟶ S₂) [HasRightHomology S₂] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasRightHomology S₁ := HasRightHomology.mk' (RightHomologyData.ofEpiOfIsIsoOfMono' φ S₂.rightHomologyData) lemma hasRightHomology_of_iso {S₁ S₂ : ShortComplex C} (e : S₁ ≅ S₂) [HasRightHomology S₁] : HasRightHomology S₂ := hasRightHomology_of_epi_of_isIso_of_mono e.hom namespace RightHomologyMapData /-- This right homology map data expresses compatibilities of the right homology data constructed by `RightHomologyData.ofEpiOfIsIsoOfMono` -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : RightHomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : RightHomologyMapData φ h (RightHomologyData.ofEpiOfIsIsoOfMono φ h) where φQ := 𝟙 _ φH := 𝟙 _ /-- This right homology map data expresses compatibilities of the right homology data constructed by `RightHomologyData.ofEpiOfIsIsoOfMono'` -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : RightHomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : RightHomologyMapData φ (RightHomologyData.ofEpiOfIsIsoOfMono' φ h) h where φQ := 𝟙 _ φH := 𝟙 _ end RightHomologyMapData instance (φ : S₁ ⟶ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso (rightHomologyMap' φ h₁ h₂) := by let h₂' := RightHomologyData.ofEpiOfIsIsoOfMono φ h₁ haveI : IsIso (rightHomologyMap' φ h₁ h₂') := by rw [(RightHomologyMapData.ofEpiOfIsIsoOfMono φ h₁).rightHomologyMap'_eq] dsimp infer_instance have eq := rightHomologyMap'_comp φ (𝟙 S₂) h₁ h₂' h₂ rw [comp_id] at eq rw [eq] infer_instance /-- If a morphism of short complexes `φ : S₁ ⟶ S₂` is such that `φ.τ₁` is epi, `φ.τ₂` is an iso, and `φ.τ₃` is mono, then the induced morphism on right homology is an isomorphism. -/ instance (φ : S₁ ⟶ S₂) [S₁.HasRightHomology] [S₂.HasRightHomology] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso (rightHomologyMap φ) := by dsimp only [rightHomologyMap] infer_instance variable (C) section variable [HasKernels C] [HasCokernels C] [HasKernels Cᵒᵖ] [HasCokernels Cᵒᵖ] /-- The opposite of the right homology functor is the left homology functor. -/ @[simps!] noncomputable def rightHomologyFunctorOpNatIso : (rightHomologyFunctor C).op ≅ opFunctor C ⋙ leftHomologyFunctor Cᵒᵖ := NatIso.ofComponents (fun S => (leftHomologyOpIso S.unop).symm) (by simp [rightHomologyMap_op]) /-- The opposite of the left homology functor is the right homology functor. -/ @[simps!] noncomputable def leftHomologyFunctorOpNatIso : (leftHomologyFunctor C).op ≅ opFunctor C ⋙ rightHomologyFunctor Cᵒᵖ := NatIso.ofComponents (fun S => (rightHomologyOpIso S.unop).symm) (by simp [leftHomologyMap_op]) end section variable {C} variable (h : RightHomologyData S) {A : C} (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) [HasRightHomology S] /-- A morphism `k : S.X₂ ⟶ A` such that `S.f ≫ k = 0` descends to a morphism `S.opcycles ⟶ A`. -/ noncomputable def descOpcycles : S.opcycles ⟶ A := S.rightHomologyData.descQ k hk @[reassoc (attr := simp)] lemma p_descOpcycles : S.pOpcycles ≫ S.descOpcycles k hk = k := RightHomologyData.p_descQ _ k hk @[reassoc] lemma descOpcycles_comp {A' : C} (α : A ⟶ A') : S.descOpcycles k hk ≫ α = S.descOpcycles (k ≫ α) (by rw [reassoc_of% hk, zero_comp]) := by simp only [← cancel_epi S.pOpcycles, p_descOpcycles_assoc, p_descOpcycles] /-- Via `S.pOpcycles : S.X₂ ⟶ S.opcycles`, the object `S.opcycles` identifies to the cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ noncomputable def opcyclesIsCokernel : IsColimit (CokernelCofork.ofπ S.pOpcycles S.f_pOpcycles) := S.rightHomologyData.hp /-- The canonical isomorphism `S.opcycles ≅ cokernel S.f`. -/ @[simps] noncomputable def opcyclesIsoCokernel [HasCokernel S.f] : S.opcycles ≅ cokernel S.f where hom := S.descOpcycles (cokernel.π S.f) (by simp) inv := cokernel.desc S.f S.pOpcycles (by simp) /-- The morphism `S.rightHomology ⟶ A` obtained from a morphism `k : S.X₂ ⟶ A` such that `S.f ≫ k = 0.` -/ @[simp] noncomputable def descRightHomology : S.rightHomology ⟶ A := S.rightHomologyι ≫ S.descOpcycles k hk @[reassoc] lemma rightHomologyι_descOpcycles_π_eq_zero_of_boundary (x : S.X₃ ⟶ A) (hx : k = S.g ≫ x) : S.rightHomologyι ≫ S.descOpcycles k (by rw [hx, S.zero_assoc, zero_comp]) = 0 := RightHomologyData.ι_descQ_eq_zero_of_boundary _ k x hx @[reassoc (attr := simp)] lemma rightHomologyι_comp_fromOpcycles : S.rightHomologyι ≫ S.fromOpcycles = 0 := S.rightHomologyι_descOpcycles_π_eq_zero_of_boundary S.g (𝟙 _) (by rw [comp_id]) /-- Via `S.rightHomologyι : S.rightHomology ⟶ S.opcycles`, the object `S.rightHomology` identifies to the kernel of `S.fromOpcycles : S.opcycles ⟶ S.X₃`. -/ noncomputable def rightHomologyIsKernel : IsLimit (KernelFork.ofι S.rightHomologyι S.rightHomologyι_comp_fromOpcycles) := S.rightHomologyData.hι variable {S} @[reassoc (attr := simp)] lemma opcyclesMap_comp_descOpcycles (φ : S₁ ⟶ S) [S₁.HasRightHomology] : opcyclesMap φ ≫ S.descOpcycles k hk = S₁.descOpcycles (φ.τ₂ ≫ k) (by rw [← φ.comm₁₂_assoc, hk, comp_zero]) := by simp only [← cancel_epi (S₁.pOpcycles), p_opcyclesMap_assoc, p_descOpcycles] @[reassoc (attr := simp)] lemma RightHomologyData.opcyclesIso_inv_comp_descOpcycles : h.opcyclesIso.inv ≫ S.descOpcycles k hk = h.descQ k hk := by simp only [← cancel_epi h.p, p_comp_opcyclesIso_inv_assoc, p_descOpcycles, p_descQ] @[simp] lemma RightHomologyData.opcyclesIso_hom_comp_descQ : h.opcyclesIso.hom ≫ h.descQ k hk = S.descOpcycles k hk := by rw [← h.opcyclesIso_inv_comp_descOpcycles, Iso.hom_inv_id_assoc] end variable {C} namespace HasRightHomology lemma hasCokernel [S.HasRightHomology] : HasCokernel S.f := ⟨⟨⟨_, S.rightHomologyData.hp⟩⟩⟩ lemma hasKernel [S.HasRightHomology] [HasCokernel S.f] : HasKernel (cokernel.desc S.f S.g S.zero) := by let h := S.rightHomologyData haveI : HasLimit (parallelPair h.g' 0) := ⟨⟨⟨_, h.hι'⟩⟩⟩ let e : parallelPair (cokernel.desc S.f S.g S.zero) 0 ≅ parallelPair h.g' 0 := parallelPair.ext (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) h.hp) (Iso.refl _) (coequalizer.hom_ext (by simp)) (by simp) exact hasLimit_of_iso e.symm end HasRightHomology /-- The right homology of a short complex `S` identifies to the kernel of the canonical morphism `cokernel S.f ⟶ S.X₃`. -/ noncomputable def rightHomologyIsoKernelDesc [S.HasRightHomology] [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.rightHomology ≅ kernel (cokernel.desc S.f S.g S.zero) := (RightHomologyData.ofHasCokernelOfHasKernel S).rightHomologyIso /-! The following lemmas and instance gives a sufficient condition for a morphism of short complexes to induce an isomorphism on opcycles. -/ lemma isIso_opcyclesMap'_of_isIso_of_epi (φ : S₁ ⟶ S₂) (h₂ : IsIso φ.τ₂) (h₁ : Epi φ.τ₁) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : IsIso (opcyclesMap' φ h₁ h₂) := by refine ⟨h₂.descQ (inv φ.τ₂ ≫ h₁.p) ?_, ?_, ?_⟩ · simp only [← cancel_epi φ.τ₁, comp_zero, φ.comm₁₂_assoc, IsIso.hom_inv_id_assoc, h₁.wp] · simp only [← cancel_epi h₁.p, p_opcyclesMap'_assoc, h₂.p_descQ, IsIso.hom_inv_id_assoc, comp_id] · simp only [← cancel_epi h₂.p, h₂.p_descQ_assoc, assoc, p_opcyclesMap', IsIso.inv_hom_id_assoc, comp_id] lemma isIso_opcyclesMap_of_isIso_of_epi' (φ : S₁ ⟶ S₂) (h₂ : IsIso φ.τ₂) (h₁ : Epi φ.τ₁) [S₁.HasRightHomology] [S₂.HasRightHomology] : IsIso (opcyclesMap φ) := isIso_opcyclesMap'_of_isIso_of_epi φ h₂ h₁ _ _ instance isIso_opcyclesMap_of_isIso_of_epi (φ : S₁ ⟶ S₂) [IsIso φ.τ₂] [Epi φ.τ₁] [S₁.HasRightHomology] [S₂.HasRightHomology] : IsIso (opcyclesMap φ) := isIso_opcyclesMap_of_isIso_of_epi' φ inferInstance inferInstance end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Linear.lean
import Mathlib.Algebra.Homology.ShortComplex.Preadditive import Mathlib.CategoryTheory.Linear.LinearFunctor /-! # Homology of linear categories In this file, it is shown that if `C` is a `R`-linear category, then `ShortComplex C` is a `R`-linear category. Various homological notions are also shown to be linear. -/ namespace CategoryTheory open Category Limits variable {R C : Type*} [Semiring R] [Category C] [Preadditive C] [Linear R C] namespace ShortComplex variable {S₁ S₂ : ShortComplex C} attribute [local simp] Hom.comm₁₂ Hom.comm₂₃ mul_smul add_smul instance : SMul R (S₁ ⟶ S₂) where smul a φ := { τ₁ := a • φ.τ₁ τ₂ := a • φ.τ₂ τ₃ := a • φ.τ₃ } @[simp] lemma smul_τ₁ (a : R) (φ : S₁ ⟶ S₂) : (a • φ).τ₁ = a • φ.τ₁ := rfl @[simp] lemma smul_τ₂ (a : R) (φ : S₁ ⟶ S₂) : (a • φ).τ₂ = a • φ.τ₂ := rfl @[simp] lemma smul_τ₃ (a : R) (φ : S₁ ⟶ S₂) : (a • φ).τ₃ = a • φ.τ₃ := rfl instance : Module R (S₁ ⟶ S₂) where zero_smul := by cat_disch one_smul := by cat_disch smul_zero := by cat_disch smul_add := by cat_disch add_smul := by cat_disch mul_smul := by cat_disch instance : Linear R (ShortComplex C) where section LeftHomology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} namespace LeftHomologyMapData variable (γ : LeftHomologyMapData φ h₁ h₂) /-- Given a left homology map data for morphism `φ`, this is the induced left homology map data for `a • φ`. -/ @[simps] def smul (a : R) : LeftHomologyMapData (a • φ) h₁ h₂ where φK := a • γ.φK φH := a • γ.φH end LeftHomologyMapData variable (h₁ h₂ φ) variable (a : R) @[simp] lemma leftHomologyMap'_smul : leftHomologyMap' (a • φ) h₁ h₂ = a • leftHomologyMap' φ h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default simp only [(γ.smul a).leftHomologyMap'_eq, LeftHomologyMapData.smul_φH, γ.leftHomologyMap'_eq] @[simp] lemma cyclesMap'_smul : cyclesMap' (a • φ) h₁ h₂ = a • cyclesMap' φ h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default simp only [(γ.smul a).cyclesMap'_eq, LeftHomologyMapData.smul_φK, γ.cyclesMap'_eq] section variable [S₁.HasLeftHomology] [S₂.HasLeftHomology] @[simp] lemma leftHomologyMap_smul : leftHomologyMap (a • φ) = a • leftHomologyMap φ := leftHomologyMap'_smul _ _ _ _ @[simp] lemma cyclesMap_smul : cyclesMap (a • φ) = a • cyclesMap φ := cyclesMap'_smul _ _ _ _ end instance leftHomologyFunctor_linear [HasKernels C] [HasCokernels C] : Functor.Linear R (leftHomologyFunctor C) where instance cyclesFunctor_linear [HasKernels C] [HasCokernels C] : Functor.Linear R (cyclesFunctor C) where end LeftHomology section RightHomology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} namespace RightHomologyMapData variable (γ : RightHomologyMapData φ h₁ h₂) /-- Given a right homology map data for morphism `φ`, this is the induced right homology map data for `a • φ`. -/ @[simps] def smul (a : R) : RightHomologyMapData (a • φ) h₁ h₂ where φQ := a • γ.φQ φH := a • γ.φH end RightHomologyMapData variable (h₁ h₂ φ) variable (a : R) @[simp] lemma rightHomologyMap'_smul : rightHomologyMap' (a • φ) h₁ h₂ = a • rightHomologyMap' φ h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default simp only [(γ.smul a).rightHomologyMap'_eq, RightHomologyMapData.smul_φH, γ.rightHomologyMap'_eq] @[simp] lemma opcyclesMap'_smul : opcyclesMap' (a • φ) h₁ h₂ = a • opcyclesMap' φ h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default simp only [(γ.smul a).opcyclesMap'_eq, RightHomologyMapData.smul_φQ, γ.opcyclesMap'_eq] section variable [S₁.HasRightHomology] [S₂.HasRightHomology] @[simp] lemma rightHomologyMap_smul : rightHomologyMap (a • φ) = a • rightHomologyMap φ := rightHomologyMap'_smul _ _ _ _ @[simp] lemma opcyclesMap_smul : opcyclesMap (a • φ) = a • opcyclesMap φ := opcyclesMap'_smul _ _ _ _ end instance rightHomologyFunctor_linear [HasKernels C] [HasCokernels C] : Functor.Linear R (rightHomologyFunctor C) where instance opcyclesFunctor_linear [HasKernels C] [HasCokernels C] : Functor.Linear R (opcyclesFunctor C) where end RightHomology section Homology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} namespace HomologyMapData variable (γ : HomologyMapData φ h₁ h₂) (γ' : HomologyMapData φ' h₁ h₂) /-- Given a homology map data for a morphism `φ`, this is the induced homology map data for `a • φ`. -/ @[simps] def smul (a : R) : HomologyMapData (a • φ) h₁ h₂ where left := γ.left.smul a right := γ.right.smul a end HomologyMapData variable (h₁ h₂) variable (a : R) @[simp] lemma homologyMap'_smul : homologyMap' (a • φ) h₁ h₂ = a • homologyMap' φ h₁ h₂ := leftHomologyMap'_smul _ _ _ _ variable (φ φ') @[simp] lemma homologyMap_smul [S₁.HasHomology] [S₂.HasHomology] : homologyMap (a • φ) = a • homologyMap φ := homologyMap'_smul _ _ _ instance homologyFunctor_linear [CategoryWithHomology C] : Functor.Linear R (homologyFunctor C) where end Homology /-- Homotopy between morphisms of short complexes is compatible with the scalar multiplication. -/ @[simps] def Homotopy.smul {φ₁ φ₂ : S₁ ⟶ S₂} (h : Homotopy φ₁ φ₂) (a : R) : Homotopy (a • φ₁) (a • φ₂) where h₀ := a • h.h₀ h₁ := a • h.h₁ h₂ := a • h.h₂ h₃ := a • h.h₃ comm₁ := by dsimp rw [h.comm₁] simp only [smul_add, Linear.comp_smul] comm₂ := by dsimp rw [h.comm₂] simp only [smul_add, Linear.comp_smul, Linear.smul_comp] comm₃ := by dsimp rw [h.comm₃] simp only [smul_add, Linear.smul_comp] end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Preadditive.lean
import Mathlib.Algebra.Homology.ShortComplex.Homology import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Preadditive.Opposite /-! # Homology of preadditive categories In this file, it is shown that if `C` is a preadditive category, then `ShortComplex C` is a preadditive category. -/ namespace CategoryTheory open Category Limits Preadditive variable {C : Type*} [Category C] [Preadditive C] namespace ShortComplex variable {S₁ S₂ S₃ : ShortComplex C} attribute [local simp] Hom.comm₁₂ Hom.comm₂₃ instance : Add (S₁ ⟶ S₂) where add φ φ' := { τ₁ := φ.τ₁ + φ'.τ₁ τ₂ := φ.τ₂ + φ'.τ₂ τ₃ := φ.τ₃ + φ'.τ₃ } instance : Sub (S₁ ⟶ S₂) where sub φ φ' := { τ₁ := φ.τ₁ - φ'.τ₁ τ₂ := φ.τ₂ - φ'.τ₂ τ₃ := φ.τ₃ - φ'.τ₃ } instance : Neg (S₁ ⟶ S₂) where neg φ := { τ₁ := -φ.τ₁ τ₂ := -φ.τ₂ τ₃ := -φ.τ₃ } instance : AddCommGroup (S₁ ⟶ S₂) where add_assoc := fun a b c => by ext <;> apply add_assoc add_zero := fun a => by ext <;> apply add_zero zero_add := fun a => by ext <;> apply zero_add neg_add_cancel := fun a => by ext <;> apply neg_add_cancel add_comm := fun a b => by ext <;> apply add_comm sub_eq_add_neg := fun a b => by ext <;> apply sub_eq_add_neg nsmul := nsmulRec zsmul := zsmulRec @[simp] lemma add_τ₁ (φ φ' : S₁ ⟶ S₂) : (φ + φ').τ₁ = φ.τ₁ + φ'.τ₁ := rfl @[simp] lemma add_τ₂ (φ φ' : S₁ ⟶ S₂) : (φ + φ').τ₂ = φ.τ₂ + φ'.τ₂ := rfl @[simp] lemma add_τ₃ (φ φ' : S₁ ⟶ S₂) : (φ + φ').τ₃ = φ.τ₃ + φ'.τ₃ := rfl @[simp] lemma sub_τ₁ (φ φ' : S₁ ⟶ S₂) : (φ - φ').τ₁ = φ.τ₁ - φ'.τ₁ := rfl @[simp] lemma sub_τ₂ (φ φ' : S₁ ⟶ S₂) : (φ - φ').τ₂ = φ.τ₂ - φ'.τ₂ := rfl @[simp] lemma sub_τ₃ (φ φ' : S₁ ⟶ S₂) : (φ - φ').τ₃ = φ.τ₃ - φ'.τ₃ := rfl @[simp] lemma neg_τ₁ (φ : S₁ ⟶ S₂) : (-φ).τ₁ = -φ.τ₁ := rfl @[simp] lemma neg_τ₂ (φ : S₁ ⟶ S₂) : (-φ).τ₂ = -φ.τ₂ := rfl @[simp] lemma neg_τ₃ (φ : S₁ ⟶ S₂) : (-φ).τ₃ = -φ.τ₃ := rfl instance : Preadditive (ShortComplex C) where section LeftHomology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} namespace LeftHomologyMapData variable (γ : LeftHomologyMapData φ h₁ h₂) (γ' : LeftHomologyMapData φ' h₁ h₂) /-- Given a left homology map data for morphism `φ`, this is the induced left homology map data for `-φ`. -/ @[simps] def neg : LeftHomologyMapData (-φ) h₁ h₂ where φK := -γ.φK φH := -γ.φH /-- Given left homology map data for morphisms `φ` and `φ'`, this is the induced left homology map data for `φ + φ'`. -/ @[simps] def add : LeftHomologyMapData (φ + φ') h₁ h₂ where φK := γ.φK + γ'.φK φH := γ.φH + γ'.φH end LeftHomologyMapData variable (h₁ h₂) @[simp] lemma leftHomologyMap'_neg : leftHomologyMap' (-φ) h₁ h₂ = -leftHomologyMap' φ h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default simp only [γ.leftHomologyMap'_eq, γ.neg.leftHomologyMap'_eq, LeftHomologyMapData.neg_φH] @[simp] lemma cyclesMap'_neg : cyclesMap' (-φ) h₁ h₂ = -cyclesMap' φ h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default simp only [γ.cyclesMap'_eq, γ.neg.cyclesMap'_eq, LeftHomologyMapData.neg_φK] @[simp] lemma leftHomologyMap'_add : leftHomologyMap' (φ + φ') h₁ h₂ = leftHomologyMap' φ h₁ h₂ + leftHomologyMap' φ' h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default have γ' : LeftHomologyMapData φ' h₁ h₂ := default simp only [γ.leftHomologyMap'_eq, γ'.leftHomologyMap'_eq, (γ.add γ').leftHomologyMap'_eq, LeftHomologyMapData.add_φH] @[simp] lemma cyclesMap'_add : cyclesMap' (φ + φ') h₁ h₂ = cyclesMap' φ h₁ h₂ + cyclesMap' φ' h₁ h₂ := by have γ : LeftHomologyMapData φ h₁ h₂ := default have γ' : LeftHomologyMapData φ' h₁ h₂ := default simp only [γ.cyclesMap'_eq, γ'.cyclesMap'_eq, (γ.add γ').cyclesMap'_eq, LeftHomologyMapData.add_φK] @[simp] lemma leftHomologyMap'_sub : leftHomologyMap' (φ - φ') h₁ h₂ = leftHomologyMap' φ h₁ h₂ - leftHomologyMap' φ' h₁ h₂ := by simp only [sub_eq_add_neg, leftHomologyMap'_add, leftHomologyMap'_neg] @[simp] lemma cyclesMap'_sub : cyclesMap' (φ - φ') h₁ h₂ = cyclesMap' φ h₁ h₂ - cyclesMap' φ' h₁ h₂ := by simp only [sub_eq_add_neg, cyclesMap'_add, cyclesMap'_neg] variable (φ φ') section variable [S₁.HasLeftHomology] [S₂.HasLeftHomology] @[simp] lemma leftHomologyMap_neg : leftHomologyMap (-φ) = -leftHomologyMap φ := leftHomologyMap'_neg _ _ @[simp] lemma cyclesMap_neg : cyclesMap (-φ) = -cyclesMap φ := cyclesMap'_neg _ _ @[simp] lemma leftHomologyMap_add : leftHomologyMap (φ + φ') = leftHomologyMap φ + leftHomologyMap φ' := leftHomologyMap'_add _ _ @[simp] lemma cyclesMap_add : cyclesMap (φ + φ') = cyclesMap φ + cyclesMap φ' := cyclesMap'_add _ _ @[simp] lemma leftHomologyMap_sub : leftHomologyMap (φ - φ') = leftHomologyMap φ - leftHomologyMap φ' := leftHomologyMap'_sub _ _ @[simp] lemma cyclesMap_sub : cyclesMap (φ - φ') = cyclesMap φ - cyclesMap φ' := cyclesMap'_sub _ _ end instance leftHomologyFunctor_additive [HasKernels C] [HasCokernels C] : (leftHomologyFunctor C).Additive where instance cyclesFunctor_additive [HasKernels C] [HasCokernels C] : (cyclesFunctor C).Additive where end LeftHomology section RightHomology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} namespace RightHomologyMapData variable (γ : RightHomologyMapData φ h₁ h₂) (γ' : RightHomologyMapData φ' h₁ h₂) /-- Given a right homology map data for morphism `φ`, this is the induced right homology map data for `-φ`. -/ @[simps] def neg : RightHomologyMapData (-φ) h₁ h₂ where φQ := -γ.φQ φH := -γ.φH /-- Given right homology map data for morphisms `φ` and `φ'`, this is the induced right homology map data for `φ + φ'`. -/ @[simps] def add : RightHomologyMapData (φ + φ') h₁ h₂ where φQ := γ.φQ + γ'.φQ φH := γ.φH + γ'.φH end RightHomologyMapData variable (h₁ h₂) @[simp] lemma rightHomologyMap'_neg : rightHomologyMap' (-φ) h₁ h₂ = -rightHomologyMap' φ h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default simp only [γ.rightHomologyMap'_eq, γ.neg.rightHomologyMap'_eq, RightHomologyMapData.neg_φH] @[simp] lemma opcyclesMap'_neg : opcyclesMap' (-φ) h₁ h₂ = -opcyclesMap' φ h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default simp only [γ.opcyclesMap'_eq, γ.neg.opcyclesMap'_eq, RightHomologyMapData.neg_φQ] @[simp] lemma rightHomologyMap'_add : rightHomologyMap' (φ + φ') h₁ h₂ = rightHomologyMap' φ h₁ h₂ + rightHomologyMap' φ' h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default have γ' : RightHomologyMapData φ' h₁ h₂ := default simp only [γ.rightHomologyMap'_eq, γ'.rightHomologyMap'_eq, (γ.add γ').rightHomologyMap'_eq, RightHomologyMapData.add_φH] @[simp] lemma opcyclesMap'_add : opcyclesMap' (φ + φ') h₁ h₂ = opcyclesMap' φ h₁ h₂ + opcyclesMap' φ' h₁ h₂ := by have γ : RightHomologyMapData φ h₁ h₂ := default have γ' : RightHomologyMapData φ' h₁ h₂ := default simp only [γ.opcyclesMap'_eq, γ'.opcyclesMap'_eq, (γ.add γ').opcyclesMap'_eq, RightHomologyMapData.add_φQ] @[simp] lemma rightHomologyMap'_sub : rightHomologyMap' (φ - φ') h₁ h₂ = rightHomologyMap' φ h₁ h₂ - rightHomologyMap' φ' h₁ h₂ := by simp only [sub_eq_add_neg, rightHomologyMap'_add, rightHomologyMap'_neg] @[simp] lemma opcyclesMap'_sub : opcyclesMap' (φ - φ') h₁ h₂ = opcyclesMap' φ h₁ h₂ - opcyclesMap' φ' h₁ h₂ := by simp only [sub_eq_add_neg, opcyclesMap'_add, opcyclesMap'_neg] variable (φ φ') section variable [S₁.HasRightHomology] [S₂.HasRightHomology] @[simp] lemma rightHomologyMap_neg : rightHomologyMap (-φ) = -rightHomologyMap φ := rightHomologyMap'_neg _ _ @[simp] lemma opcyclesMap_neg : opcyclesMap (-φ) = -opcyclesMap φ := opcyclesMap'_neg _ _ @[simp] lemma rightHomologyMap_add : rightHomologyMap (φ + φ') = rightHomologyMap φ + rightHomologyMap φ' := rightHomologyMap'_add _ _ @[simp] lemma opcyclesMap_add : opcyclesMap (φ + φ') = opcyclesMap φ + opcyclesMap φ' := opcyclesMap'_add _ _ @[simp] lemma rightHomologyMap_sub : rightHomologyMap (φ - φ') = rightHomologyMap φ - rightHomologyMap φ' := rightHomologyMap'_sub _ _ @[simp] lemma opcyclesMap_sub : opcyclesMap (φ - φ') = opcyclesMap φ - opcyclesMap φ' := opcyclesMap'_sub _ _ end instance rightHomologyFunctor_additive [HasKernels C] [HasCokernels C] : (rightHomologyFunctor C).Additive where instance opcyclesFunctor_additive [HasKernels C] [HasCokernels C] : (opcyclesFunctor C).Additive where end RightHomology section Homology variable {φ φ' : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} namespace HomologyMapData variable (γ : HomologyMapData φ h₁ h₂) (γ' : HomologyMapData φ' h₁ h₂) /-- Given a homology map data for a morphism `φ`, this is the induced homology map data for `-φ`. -/ @[simps] def neg : HomologyMapData (-φ) h₁ h₂ where left := γ.left.neg right := γ.right.neg /-- Given homology map data for morphisms `φ` and `φ'`, this is the induced homology map data for `φ + φ'`. -/ @[simps] def add : HomologyMapData (φ + φ') h₁ h₂ where left := γ.left.add γ'.left right := γ.right.add γ'.right end HomologyMapData variable (h₁ h₂) @[simp] lemma homologyMap'_neg : homologyMap' (-φ) h₁ h₂ = -homologyMap' φ h₁ h₂ := leftHomologyMap'_neg _ _ @[simp] lemma homologyMap'_add : homologyMap' (φ + φ') h₁ h₂ = homologyMap' φ h₁ h₂ + homologyMap' φ' h₁ h₂ := leftHomologyMap'_add _ _ @[simp] lemma homologyMap'_sub : homologyMap' (φ - φ') h₁ h₂ = homologyMap' φ h₁ h₂ - homologyMap' φ' h₁ h₂ := leftHomologyMap'_sub _ _ variable (φ φ') section variable [S₁.HasHomology] [S₂.HasHomology] @[simp] lemma homologyMap_neg : homologyMap (-φ) = -homologyMap φ := homologyMap'_neg _ _ @[simp] lemma homologyMap_add : homologyMap (φ + φ') = homologyMap φ + homologyMap φ' := homologyMap'_add _ _ @[simp] lemma homologyMap_sub : homologyMap (φ - φ') = homologyMap φ - homologyMap φ' := homologyMap'_sub _ _ end instance homologyFunctor_additive [CategoryWithHomology C] : (homologyFunctor C).Additive where end Homology section Homotopy variable (φ₁ φ₂ φ₃ φ₄ : S₁ ⟶ S₂) /-- A homotopy between two morphisms of short complexes `S₁ ⟶ S₂` consists of various maps and conditions which will be sufficient to show that they induce the same morphism in homology. -/ @[ext] structure Homotopy where /-- a morphism `S₁.X₁ ⟶ S₂.X₁` -/ h₀ : S₁.X₁ ⟶ S₂.X₁ h₀_f : h₀ ≫ S₂.f = 0 := by cat_disch /-- a morphism `S₁.X₂ ⟶ S₂.X₁` -/ h₁ : S₁.X₂ ⟶ S₂.X₁ /-- a morphism `S₁.X₃ ⟶ S₂.X₂` -/ h₂ : S₁.X₃ ⟶ S₂.X₂ /-- a morphism `S₁.X₃ ⟶ S₂.X₃` -/ h₃ : S₁.X₃ ⟶ S₂.X₃ g_h₃ : S₁.g ≫ h₃ = 0 := by cat_disch comm₁ : φ₁.τ₁ = S₁.f ≫ h₁ + h₀ + φ₂.τ₁ := by cat_disch comm₂ : φ₁.τ₂ = S₁.g ≫ h₂ + h₁ ≫ S₂.f + φ₂.τ₂ := by cat_disch comm₃ : φ₁.τ₃ = h₃ + h₂ ≫ S₂.g + φ₂.τ₃ := by cat_disch attribute [reassoc (attr := simp)] Homotopy.h₀_f Homotopy.g_h₃ variable (S₁ S₂) /-- Constructor for null homotopic morphisms, see also `Homotopy.ofNullHomotopic` and `Homotopy.eq_add_nullHomotopic`. -/ @[simps] def nullHomotopic (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : S₁ ⟶ S₂ where τ₁ := h₀ + S₁.f ≫ h₁ τ₂ := h₁ ≫ S₂.f + S₁.g ≫ h₂ τ₃ := h₂ ≫ S₂.g + h₃ namespace Homotopy attribute [local simp] neg_comp variable {S₁ S₂ φ₁ φ₂ φ₃ φ₄} /-- The obvious homotopy between two equal morphisms of short complexes. -/ @[simps] def ofEq (h : φ₁ = φ₂) : Homotopy φ₁ φ₂ where h₀ := 0 h₁ := 0 h₂ := 0 h₃ := 0 /-- The obvious homotopy between a morphism of short complexes and itself. -/ @[simps!] def refl (φ : S₁ ⟶ S₂) : Homotopy φ φ := ofEq rfl /-- The symmetry of homotopy between morphisms of short complexes. -/ @[simps] def symm (h : Homotopy φ₁ φ₂) : Homotopy φ₂ φ₁ where h₀ := -h.h₀ h₁ := -h.h₁ h₂ := -h.h₂ h₃ := -h.h₃ comm₁ := by rw [h.comm₁, comp_neg]; abel comm₂ := by rw [h.comm₂, comp_neg, neg_comp]; abel comm₃ := by rw [h.comm₃, neg_comp]; abel /-- If two maps of short complexes are homotopic, their opposites also are. -/ @[simps] def neg (h : Homotopy φ₁ φ₂) : Homotopy (-φ₁) (-φ₂) where h₀ := -h.h₀ h₁ := -h.h₁ h₂ := -h.h₂ h₃ := -h.h₃ comm₁ := by rw [neg_τ₁, neg_τ₁, h.comm₁, neg_add_rev, comp_neg]; abel comm₂ := by rw [neg_τ₂, neg_τ₂, h.comm₂, neg_add_rev, comp_neg, neg_comp]; abel comm₃ := by rw [neg_τ₃, neg_τ₃, h.comm₃, neg_comp]; abel /-- The transitivity of homotopy between morphisms of short complexes. -/ @[simps] def trans (h₁₂ : Homotopy φ₁ φ₂) (h₂₃ : Homotopy φ₂ φ₃) : Homotopy φ₁ φ₃ where h₀ := h₁₂.h₀ + h₂₃.h₀ h₁ := h₁₂.h₁ + h₂₃.h₁ h₂ := h₁₂.h₂ + h₂₃.h₂ h₃ := h₁₂.h₃ + h₂₃.h₃ comm₁ := by rw [h₁₂.comm₁, h₂₃.comm₁, comp_add]; abel comm₂ := by rw [h₁₂.comm₂, h₂₃.comm₂, comp_add, add_comp]; abel comm₃ := by rw [h₁₂.comm₃, h₂₃.comm₃, add_comp]; abel /-- Homotopy between morphisms of short complexes is compatible with addition. -/ @[simps] def add (h : Homotopy φ₁ φ₂) (h' : Homotopy φ₃ φ₄) : Homotopy (φ₁ + φ₃) (φ₂ + φ₄) where h₀ := h.h₀ + h'.h₀ h₁ := h.h₁ + h'.h₁ h₂ := h.h₂ + h'.h₂ h₃ := h.h₃ + h'.h₃ comm₁ := by rw [add_τ₁, add_τ₁, h.comm₁, h'.comm₁, comp_add]; abel comm₂ := by rw [add_τ₂, add_τ₂, h.comm₂, h'.comm₂, comp_add, add_comp]; abel comm₃ := by rw [add_τ₃, add_τ₃, h.comm₃, h'.comm₃, add_comp]; abel /-- Homotopy between morphisms of short complexes is compatible with subtraction. -/ @[simps] def sub (h : Homotopy φ₁ φ₂) (h' : Homotopy φ₃ φ₄) : Homotopy (φ₁ - φ₃) (φ₂ - φ₄) where h₀ := h.h₀ - h'.h₀ h₁ := h.h₁ - h'.h₁ h₂ := h.h₂ - h'.h₂ h₃ := h.h₃ - h'.h₃ comm₁ := by rw [sub_τ₁, sub_τ₁, h.comm₁, h'.comm₁, comp_sub]; abel comm₂ := by rw [sub_τ₂, sub_τ₂, h.comm₂, h'.comm₂, comp_sub, sub_comp]; abel comm₃ := by rw [sub_τ₃, sub_τ₃, h.comm₃, h'.comm₃, sub_comp]; abel /-- Homotopy between morphisms of short complexes is compatible with precomposition. -/ @[simps] def compLeft (h : Homotopy φ₁ φ₂) (ψ : S₃ ⟶ S₁) : Homotopy (ψ ≫ φ₁) (ψ ≫ φ₂) where h₀ := ψ.τ₁ ≫ h.h₀ h₁ := ψ.τ₂ ≫ h.h₁ h₂ := ψ.τ₃ ≫ h.h₂ h₃ := ψ.τ₃ ≫ h.h₃ g_h₃ := by rw [← ψ.comm₂₃_assoc, h.g_h₃, comp_zero] comm₁ := by rw [comp_τ₁, comp_τ₁, h.comm₁, comp_add, comp_add, add_left_inj, ψ.comm₁₂_assoc] comm₂ := by rw [comp_τ₂, comp_τ₂, h.comm₂, comp_add, comp_add, assoc, ψ.comm₂₃_assoc] comm₃ := by rw [comp_τ₃, comp_τ₃, h.comm₃, comp_add, comp_add, assoc] /-- Homotopy between morphisms of short complexes is compatible with postcomposition. -/ @[simps] def compRight (h : Homotopy φ₁ φ₂) (ψ : S₂ ⟶ S₃) : Homotopy (φ₁ ≫ ψ) (φ₂ ≫ ψ) where h₀ := h.h₀ ≫ ψ.τ₁ h₁ := h.h₁ ≫ ψ.τ₁ h₂ := h.h₂ ≫ ψ.τ₂ h₃ := h.h₃ ≫ ψ.τ₃ comm₁ := by rw [comp_τ₁, comp_τ₁, h.comm₁, add_comp, add_comp, assoc] comm₂ := by rw [comp_τ₂, comp_τ₂, h.comm₂, add_comp, add_comp, assoc, assoc, assoc, ψ.comm₁₂] comm₃ := by rw [comp_τ₃, comp_τ₃, h.comm₃, add_comp, add_comp, assoc, assoc, ψ.comm₂₃] /-- Homotopy between morphisms of short complexes is compatible with composition. -/ @[simps!] def comp (h : Homotopy φ₁ φ₂) {ψ₁ ψ₂ : S₂ ⟶ S₃} (h' : Homotopy ψ₁ ψ₂) : Homotopy (φ₁ ≫ ψ₁) (φ₂ ≫ ψ₂) := (h.compRight ψ₁).trans (h'.compLeft φ₂) /-- The homotopy between morphisms in `ShortComplex Cᵒᵖ` that is induced by a homotopy between morphisms in `ShortComplex C`. -/ @[simps] def op (h : Homotopy φ₁ φ₂) : Homotopy (opMap φ₁) (opMap φ₂) where h₀ := h.h₃.op h₁ := h.h₂.op h₂ := h.h₁.op h₃ := h.h₀.op h₀_f := Quiver.Hom.unop_inj h.g_h₃ g_h₃ := Quiver.Hom.unop_inj h.h₀_f comm₁ := Quiver.Hom.unop_inj (by dsimp; rw [h.comm₃]; abel) comm₂ := Quiver.Hom.unop_inj (by dsimp; rw [h.comm₂]; abel) comm₃ := Quiver.Hom.unop_inj (by dsimp; rw [h.comm₁]; abel) /-- The homotopy between morphisms in `ShortComplex C` that is induced by a homotopy between morphisms in `ShortComplex Cᵒᵖ`. -/ @[simps] def unop {S₁ S₂ : ShortComplex Cᵒᵖ} {φ₁ φ₂ : S₁ ⟶ S₂} (h : Homotopy φ₁ φ₂) : Homotopy (unopMap φ₁) (unopMap φ₂) where h₀ := h.h₃.unop h₁ := h.h₂.unop h₂ := h.h₁.unop h₃ := h.h₀.unop h₀_f := Quiver.Hom.op_inj h.g_h₃ g_h₃ := Quiver.Hom.op_inj h.h₀_f comm₁ := Quiver.Hom.op_inj (by dsimp; rw [h.comm₃]; abel) comm₂ := Quiver.Hom.op_inj (by dsimp; rw [h.comm₂]; abel) comm₃ := Quiver.Hom.op_inj (by dsimp; rw [h.comm₁]; abel) variable (φ₁ φ₂) /-- Equivalence expressing that two morphisms are homotopic iff their difference is homotopic to zero. -/ @[simps] def equivSubZero : Homotopy φ₁ φ₂ ≃ Homotopy (φ₁ - φ₂) 0 where toFun h := (h.sub (refl φ₂)).trans (ofEq (sub_self φ₂)) invFun h := ((ofEq (sub_add_cancel φ₁ φ₂).symm).trans (h.add (refl φ₂))).trans (ofEq (zero_add φ₂)) left_inv := by cat_disch right_inv := by cat_disch variable {φ₁ φ₂} lemma eq_add_nullHomotopic (h : Homotopy φ₁ φ₂) : φ₁ = φ₂ + nullHomotopic _ _ h.h₀ h.h₀_f h.h₁ h.h₂ h.h₃ h.g_h₃ := by ext · dsimp; rw [h.comm₁]; abel · dsimp; rw [h.comm₂]; abel · dsimp; rw [h.comm₃]; abel variable (S₁ S₂) /-- A morphism constructed with `nullHomotopic` is homotopic to zero. -/ @[simps] def ofNullHomotopic (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : Homotopy (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) 0 where h₀ := h₀ h₁ := h₁ h₂ := h₂ h₃ := h₃ h₀_f := h₀_f g_h₃ := g_h₃ comm₁ := by rw [nullHomotopic_τ₁, zero_τ₁, add_zero]; abel comm₂ := by rw [nullHomotopic_τ₂, zero_τ₂, add_zero]; abel comm₃ := by rw [nullHomotopic_τ₃, zero_τ₃, add_zero]; abel end Homotopy variable {S₁ S₂} /-- The left homology map data expressing that null homotopic maps induce the zero morphism in left homology. -/ def LeftHomologyMapData.ofNullHomotopic (H₁ : S₁.LeftHomologyData) (H₂ : S₂.LeftHomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : LeftHomologyMapData (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ where φK := H₂.liftK (H₁.i ≫ h₁ ≫ S₂.f) (by simp) φH := 0 commf' := by rw [← cancel_mono H₂.i, assoc, LeftHomologyData.liftK_i, LeftHomologyData.f'_i_assoc, nullHomotopic_τ₁, add_comp, add_comp, assoc, assoc, assoc, LeftHomologyData.f'_i, right_eq_add, h₀_f] commπ := by rw [H₂.liftK_π_eq_zero_of_boundary (H₁.i ≫ h₁ ≫ S₂.f) (H₁.i ≫ h₁) (by rw [assoc]), comp_zero] /-- The right homology map data expressing that null homotopic maps induce the zero morphism in right homology. -/ def RightHomologyMapData.ofNullHomotopic (H₁ : S₁.RightHomologyData) (H₂ : S₂.RightHomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : RightHomologyMapData (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ where φQ := H₁.descQ (S₁.g ≫ h₂ ≫ H₂.p) (by simp) φH := 0 commg' := by rw [← cancel_epi H₁.p, RightHomologyData.p_descQ_assoc, RightHomologyData.p_g'_assoc, nullHomotopic_τ₃, comp_add, assoc, assoc, RightHomologyData.p_g', g_h₃, add_zero] commι := by rw [H₁.ι_descQ_eq_zero_of_boundary (S₁.g ≫ h₂ ≫ H₂.p) (h₂ ≫ H₂.p) rfl, zero_comp] @[simp] lemma leftHomologyMap'_nullHomotopic (H₁ : S₁.LeftHomologyData) (H₂ : S₂.LeftHomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : leftHomologyMap' (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ = 0 := (LeftHomologyMapData.ofNullHomotopic H₁ H₂ h₀ h₀_f h₁ h₂ h₃ g_h₃).leftHomologyMap'_eq @[simp] lemma rightHomologyMap'_nullHomotopic (H₁ : S₁.RightHomologyData) (H₂ : S₂.RightHomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : rightHomologyMap' (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ = 0 := (RightHomologyMapData.ofNullHomotopic H₁ H₂ h₀ h₀_f h₁ h₂ h₃ g_h₃).rightHomologyMap'_eq @[simp] lemma homologyMap'_nullHomotopic (H₁ : S₁.HomologyData) (H₂ : S₂.HomologyData) (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : homologyMap' (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) H₁ H₂ = 0 := by apply leftHomologyMap'_nullHomotopic variable (S₁ S₂) @[simp] lemma leftHomologyMap_nullHomotopic [S₁.HasLeftHomology] [S₂.HasLeftHomology] (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : leftHomologyMap (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) = 0 := by apply leftHomologyMap'_nullHomotopic @[simp] lemma rightHomologyMap_nullHomotopic [S₁.HasRightHomology] [S₂.HasRightHomology] (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : rightHomologyMap (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) = 0 := by apply rightHomologyMap'_nullHomotopic @[simp] lemma homologyMap_nullHomotopic [S₁.HasHomology] [S₂.HasHomology] (h₀ : S₁.X₁ ⟶ S₂.X₁) (h₀_f : h₀ ≫ S₂.f = 0) (h₁ : S₁.X₂ ⟶ S₂.X₁) (h₂ : S₁.X₃ ⟶ S₂.X₂) (h₃ : S₁.X₃ ⟶ S₂.X₃) (g_h₃ : S₁.g ≫ h₃ = 0) : homologyMap (nullHomotopic _ _ h₀ h₀_f h₁ h₂ h₃ g_h₃) = 0 := by apply homologyMap'_nullHomotopic namespace Homotopy variable {φ₁ φ₂ S₁ S₂} lemma leftHomologyMap'_congr (h : Homotopy φ₁ φ₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : leftHomologyMap' φ₁ h₁ h₂ = leftHomologyMap' φ₂ h₁ h₂ := by rw [h.eq_add_nullHomotopic, leftHomologyMap'_add, leftHomologyMap'_nullHomotopic, add_zero] lemma rightHomologyMap'_congr (h : Homotopy φ₁ φ₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : rightHomologyMap' φ₁ h₁ h₂ = rightHomologyMap' φ₂ h₁ h₂ := by rw [h.eq_add_nullHomotopic, rightHomologyMap'_add, rightHomologyMap'_nullHomotopic, add_zero] lemma homologyMap'_congr (h : Homotopy φ₁ φ₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : homologyMap' φ₁ h₁ h₂ = homologyMap' φ₂ h₁ h₂ := by rw [h.eq_add_nullHomotopic, homologyMap'_add, homologyMap'_nullHomotopic, add_zero] lemma leftHomologyMap_congr (h : Homotopy φ₁ φ₂) [S₁.HasLeftHomology] [S₂.HasLeftHomology] : leftHomologyMap φ₁ = leftHomologyMap φ₂ := h.leftHomologyMap'_congr _ _ lemma rightHomologyMap_congr (h : Homotopy φ₁ φ₂) [S₁.HasRightHomology] [S₂.HasRightHomology] : rightHomologyMap φ₁ = rightHomologyMap φ₂ := h.rightHomologyMap'_congr _ _ lemma homologyMap_congr (h : Homotopy φ₁ φ₂) [S₁.HasHomology] [S₂.HasHomology] : homologyMap φ₁ = homologyMap φ₂ := h.homologyMap'_congr _ _ end Homotopy /-- An homotopy equivalence between two short complexes `S₁` and `S₂` consists of morphisms `hom : S₁ ⟶ S₂` and `inv : S₂ ⟶ S₁` such that both compositions `hom ≫ inv` and `inv ≫ hom` are homotopic to the identity. -/ @[ext] structure HomotopyEquiv where /-- the forward direction of a homotopy equivalence. -/ hom : S₁ ⟶ S₂ /-- the backwards direction of a homotopy equivalence. -/ inv : S₂ ⟶ S₁ /-- the composition of the two directions of a homotopy equivalence is homotopic to the identity of the source -/ homotopyHomInvId : Homotopy (hom ≫ inv) (𝟙 S₁) /-- the composition of the two directions of a homotopy equivalence is homotopic to the identity of the target -/ homotopyInvHomId : Homotopy (inv ≫ hom) (𝟙 S₂) namespace HomotopyEquiv variable {S₁ S₂} /-- The homotopy equivalence from a short complex to itself that is induced by the identity. -/ @[simps] def refl (S : ShortComplex C) : HomotopyEquiv S S where hom := 𝟙 S inv := 𝟙 S homotopyHomInvId := Homotopy.ofEq (by simp) homotopyInvHomId := Homotopy.ofEq (by simp) /-- The inverse of a homotopy equivalence. -/ @[simps] def symm (e : HomotopyEquiv S₁ S₂) : HomotopyEquiv S₂ S₁ where hom := e.inv inv := e.hom homotopyHomInvId := e.homotopyInvHomId homotopyInvHomId := e.homotopyHomInvId /-- The composition of homotopy equivalences. -/ @[simps] def trans (e : HomotopyEquiv S₁ S₂) (e' : HomotopyEquiv S₂ S₃) : HomotopyEquiv S₁ S₃ where hom := e.hom ≫ e'.hom inv := e'.inv ≫ e.inv homotopyHomInvId := (Homotopy.ofEq (by simp)).trans (((e'.homotopyHomInvId.compRight e.inv).compLeft e.hom).trans ((Homotopy.ofEq (by simp)).trans e.homotopyHomInvId)) homotopyInvHomId := (Homotopy.ofEq (by simp)).trans (((e.homotopyInvHomId.compRight e'.hom).compLeft e'.inv).trans ((Homotopy.ofEq (by simp)).trans e'.homotopyInvHomId)) end HomotopyEquiv end Homotopy end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Basic.lean
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero /-! # Short complexes This file defines the category `ShortComplex C` of diagrams `X₁ ⟶ X₂ ⟶ X₃` such that the composition is zero. Note: This structure `ShortComplex C` was first introduced in the Liquid Tensor Experiment. -/ namespace CategoryTheory open Category Limits variable {C D E : Type*} [Category C] [Category D] [Category E] [HasZeroMorphisms C] [HasZeroMorphisms D] [HasZeroMorphisms E] variable (C) in /-- A short complex in a category `C` with zero morphisms is the datum of two composable morphisms `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` such that `f ≫ g = 0`. -/ structure ShortComplex where /-- the first (left) object of a `ShortComplex` -/ {X₁ : C} /-- the second (middle) object of a `ShortComplex` -/ {X₂ : C} /-- the third (right) object of a `ShortComplex` -/ {X₃ : C} /-- the first morphism of a `ShortComplex` -/ f : X₁ ⟶ X₂ /-- the second morphism of a `ShortComplex` -/ g : X₂ ⟶ X₃ /-- the composition of the two given morphisms is zero -/ zero : f ≫ g = 0 namespace ShortComplex attribute [reassoc (attr := simp)] ShortComplex.zero /-- Morphisms of short complexes are the commutative diagrams of the obvious shape. -/ @[ext] structure Hom (S₁ S₂ : ShortComplex C) where /-- the morphism on the left objects -/ τ₁ : S₁.X₁ ⟶ S₂.X₁ /-- the morphism on the middle objects -/ τ₂ : S₁.X₂ ⟶ S₂.X₂ /-- the morphism on the right objects -/ τ₃ : S₁.X₃ ⟶ S₂.X₃ /-- the left commutative square of a morphism in `ShortComplex` -/ comm₁₂ : τ₁ ≫ S₂.f = S₁.f ≫ τ₂ := by cat_disch /-- the right commutative square of a morphism in `ShortComplex` -/ comm₂₃ : τ₂ ≫ S₂.g = S₁.g ≫ τ₃ := by cat_disch attribute [reassoc] Hom.comm₁₂ Hom.comm₂₃ attribute [local simp] Hom.comm₁₂ Hom.comm₂₃ Hom.comm₁₂_assoc Hom.comm₂₃_assoc variable (S : ShortComplex C) {S₁ S₂ S₃ : ShortComplex C} /-- The identity morphism of a short complex. -/ @[simps] def Hom.id : Hom S S where τ₁ := 𝟙 _ τ₂ := 𝟙 _ τ₃ := 𝟙 _ /-- The composition of morphisms of short complexes. -/ @[simps] def Hom.comp (φ₁₂ : Hom S₁ S₂) (φ₂₃ : Hom S₂ S₃) : Hom S₁ S₃ where τ₁ := φ₁₂.τ₁ ≫ φ₂₃.τ₁ τ₂ := φ₁₂.τ₂ ≫ φ₂₃.τ₂ τ₃ := φ₁₂.τ₃ ≫ φ₂₃.τ₃ instance : Category (ShortComplex C) where Hom := Hom id := Hom.id comp := Hom.comp @[ext] lemma hom_ext (f g : S₁ ⟶ S₂) (h₁ : f.τ₁ = g.τ₁) (h₂ : f.τ₂ = g.τ₂) (h₃ : f.τ₃ = g.τ₃) : f = g := Hom.ext h₁ h₂ h₃ /-- A constructor for morphisms in `ShortComplex C` when the commutativity conditions are not obvious. -/ @[simps] def homMk {S₁ S₂ : ShortComplex C} (τ₁ : S₁.X₁ ⟶ S₂.X₁) (τ₂ : S₁.X₂ ⟶ S₂.X₂) (τ₃ : S₁.X₃ ⟶ S₂.X₃) (comm₁₂ : τ₁ ≫ S₂.f = S₁.f ≫ τ₂) (comm₂₃ : τ₂ ≫ S₂.g = S₁.g ≫ τ₃) : S₁ ⟶ S₂ := ⟨τ₁, τ₂, τ₃, comm₁₂, comm₂₃⟩ @[simp] lemma id_τ₁ : Hom.τ₁ (𝟙 S) = 𝟙 _ := rfl @[simp] lemma id_τ₂ : Hom.τ₂ (𝟙 S) = 𝟙 _ := rfl @[simp] lemma id_τ₃ : Hom.τ₃ (𝟙 S) = 𝟙 _ := rfl @[reassoc] lemma comp_τ₁ (φ₁₂ : S₁ ⟶ S₂) (φ₂₃ : S₂ ⟶ S₃) : (φ₁₂ ≫ φ₂₃).τ₁ = φ₁₂.τ₁ ≫ φ₂₃.τ₁ := rfl @[reassoc] lemma comp_τ₂ (φ₁₂ : S₁ ⟶ S₂) (φ₂₃ : S₂ ⟶ S₃) : (φ₁₂ ≫ φ₂₃).τ₂ = φ₁₂.τ₂ ≫ φ₂₃.τ₂ := rfl @[reassoc] lemma comp_τ₃ (φ₁₂ : S₁ ⟶ S₂) (φ₂₃ : S₂ ⟶ S₃) : (φ₁₂ ≫ φ₂₃).τ₃ = φ₁₂.τ₃ ≫ φ₂₃.τ₃ := rfl attribute [simp] comp_τ₁ comp_τ₂ comp_τ₃ instance : Zero (S₁ ⟶ S₂) := ⟨{ τ₁ := 0, τ₂ := 0, τ₃ := 0 }⟩ variable (S₁ S₂) @[simp] lemma zero_τ₁ : Hom.τ₁ (0 : S₁ ⟶ S₂) = 0 := rfl @[simp] lemma zero_τ₂ : Hom.τ₂ (0 : S₁ ⟶ S₂) = 0 := rfl @[simp] lemma zero_τ₃ : Hom.τ₃ (0 : S₁ ⟶ S₂) = 0 := rfl variable {S₁ S₂} instance : HasZeroMorphisms (ShortComplex C) where /-- The first projection functor `ShortComplex C ⥤ C`. -/ @[simps] def π₁ : ShortComplex C ⥤ C where obj S := S.X₁ map f := f.τ₁ /-- The second projection functor `ShortComplex C ⥤ C`. -/ @[simps] def π₂ : ShortComplex C ⥤ C where obj S := S.X₂ map f := f.τ₂ /-- The third projection functor `ShortComplex C ⥤ C`. -/ @[simps] def π₃ : ShortComplex C ⥤ C where obj S := S.X₃ map f := f.τ₃ instance preservesZeroMorphisms_π₁ : Functor.PreservesZeroMorphisms (π₁ : _ ⥤ C) where instance preservesZeroMorphisms_π₂ : Functor.PreservesZeroMorphisms (π₂ : _ ⥤ C) where instance preservesZeroMorphisms_π₃ : Functor.PreservesZeroMorphisms (π₃ : _ ⥤ C) where instance (f : S₁ ⟶ S₂) [IsIso f] : IsIso f.τ₁ := (inferInstance : IsIso (π₁.mapIso (asIso f)).hom) instance (f : S₁ ⟶ S₂) [IsIso f] : IsIso f.τ₂ := (inferInstance : IsIso (π₂.mapIso (asIso f)).hom) instance (f : S₁ ⟶ S₂) [IsIso f] : IsIso f.τ₃ := (inferInstance : IsIso (π₃.mapIso (asIso f)).hom) /-- The natural transformation `π₁ ⟶ π₂` induced by `S.f` for all `S : ShortComplex C`. -/ @[simps] def π₁Toπ₂ : (π₁ : _ ⥤ C) ⟶ π₂ where app S := S.f /-- The natural transformation `π₂ ⟶ π₃` induced by `S.g` for all `S : ShortComplex C`. -/ @[simps] def π₂Toπ₃ : (π₂ : _ ⥤ C) ⟶ π₃ where app S := S.g @[reassoc (attr := simp)] lemma π₁Toπ₂_comp_π₂Toπ₃ : (π₁Toπ₂ : (_ : _ ⥤ C) ⟶ _) ≫ π₂Toπ₃ = 0 := by cat_disch /-- The short complex in `D` obtained by applying a functor `F : C ⥤ D` to a short complex in `C`, assuming that `F` preserves zero morphisms. -/ @[simps] def map (F : C ⥤ D) [F.PreservesZeroMorphisms] : ShortComplex D := ShortComplex.mk (F.map S.f) (F.map S.g) (by rw [← F.map_comp, S.zero, F.map_zero]) @[simp] lemma map_id (S : ShortComplex C) : S.map (𝟭 C) = S := rfl @[simp] lemma map_comp (S : ShortComplex C) (F : C ⥤ D) [F.PreservesZeroMorphisms] (G : D ⥤ E) [G.PreservesZeroMorphisms] : S.map (F ⋙ G) = (S.map F).map G := rfl /-- The morphism of short complexes `S.map F ⟶ S.map G` induced by a natural transformation `F ⟶ G`. -/ @[simps] def mapNatTrans {F G : C ⥤ D} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (τ : F ⟶ G) : S.map F ⟶ S.map G where τ₁ := τ.app _ τ₂ := τ.app _ τ₃ := τ.app _ /-- The isomorphism of short complexes `S.map F ≅ S.map G` induced by a natural isomorphism `F ≅ G`. -/ @[simps] def mapNatIso {F G : C ⥤ D} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (τ : F ≅ G) : S.map F ≅ S.map G where hom := S.mapNatTrans τ.hom inv := S.mapNatTrans τ.inv /-- The functor `ShortComplex C ⥤ ShortComplex D` induced by a functor `C ⥤ D` which preserves zero morphisms. -/ @[simps] def _root_.CategoryTheory.Functor.mapShortComplex (F : C ⥤ D) [F.PreservesZeroMorphisms] : ShortComplex C ⥤ ShortComplex D where obj S := S.map F map φ := { τ₁ := F.map φ.τ₁ τ₂ := F.map φ.τ₂ τ₃ := F.map φ.τ₃ comm₁₂ := by dsimp simp only [← F.map_comp, φ.comm₁₂] comm₂₃ := by dsimp simp only [← F.map_comp, φ.comm₂₃] } /-- A constructor for isomorphisms in the category `ShortComplex C` -/ @[simps] def isoMk (e₁ : S₁.X₁ ≅ S₂.X₁) (e₂ : S₁.X₂ ≅ S₂.X₂) (e₃ : S₁.X₃ ≅ S₂.X₃) (comm₁₂ : e₁.hom ≫ S₂.f = S₁.f ≫ e₂.hom := by cat_disch) (comm₂₃ : e₂.hom ≫ S₂.g = S₁.g ≫ e₃.hom := by cat_disch) : S₁ ≅ S₂ where hom := ⟨e₁.hom, e₂.hom, e₃.hom, comm₁₂, comm₂₃⟩ inv := homMk e₁.inv e₂.inv e₃.inv (by rw [← cancel_mono e₂.hom, assoc, assoc, e₂.inv_hom_id, comp_id, ← comm₁₂, e₁.inv_hom_id_assoc]) (by rw [← cancel_mono e₃.hom, assoc, assoc, e₃.inv_hom_id, comp_id, ← comm₂₃, e₂.inv_hom_id_assoc]) lemma isIso_of_isIso (f : S₁ ⟶ S₂) [IsIso f.τ₁] [IsIso f.τ₂] [IsIso f.τ₃] : IsIso f := (isoMk (asIso f.τ₁) (asIso f.τ₂) (asIso f.τ₃)).isIso_hom /-- The first map of a short complex, as a functor. -/ @[simps] def fFunctor : ShortComplex C ⥤ Arrow C where obj S := .mk S.f map {S T} f := Arrow.homMk f.τ₁ f.τ₂ f.comm₁₂ /-- The second map of a short complex, as a functor. -/ @[simps] def gFunctor : ShortComplex C ⥤ Arrow C where obj S := .mk S.g map {S T} f := Arrow.homMk f.τ₂ f.τ₃ f.comm₂₃ /-- The opposite `ShortComplex` in `Cᵒᵖ` associated to a short complex in `C`. -/ @[simps] def op : ShortComplex Cᵒᵖ := mk S.g.op S.f.op (by simp only [← op_comp, S.zero]; rfl) /-- The opposite morphism in `ShortComplex Cᵒᵖ` associated to a morphism in `ShortComplex C` -/ @[simps] def opMap (φ : S₁ ⟶ S₂) : S₂.op ⟶ S₁.op where τ₁ := φ.τ₃.op τ₂ := φ.τ₂.op τ₃ := φ.τ₁.op comm₁₂ := by dsimp simp only [← op_comp, φ.comm₂₃] comm₂₃ := by dsimp simp only [← op_comp, φ.comm₁₂] @[simp] lemma opMap_id : opMap (𝟙 S) = 𝟙 S.op := rfl /-- The `ShortComplex` in `C` associated to a short complex in `Cᵒᵖ`. -/ @[simps] def unop (S : ShortComplex Cᵒᵖ) : ShortComplex C := mk S.g.unop S.f.unop (by simp only [← unop_comp, S.zero]; rfl) /-- The morphism in `ShortComplex C` associated to a morphism in `ShortComplex Cᵒᵖ` -/ @[simps] def unopMap {S₁ S₂ : ShortComplex Cᵒᵖ} (φ : S₁ ⟶ S₂) : S₂.unop ⟶ S₁.unop where τ₁ := φ.τ₃.unop τ₂ := φ.τ₂.unop τ₃ := φ.τ₁.unop comm₁₂ := by dsimp simp only [← unop_comp, φ.comm₂₃] comm₂₃ := by dsimp simp only [← unop_comp, φ.comm₁₂] @[simp] lemma unopMap_id (S : ShortComplex Cᵒᵖ) : unopMap (𝟙 S) = 𝟙 S.unop := rfl variable (C) /-- The obvious functor `(ShortComplex C)ᵒᵖ ⥤ ShortComplex Cᵒᵖ`. -/ @[simps] def opFunctor : (ShortComplex C)ᵒᵖ ⥤ ShortComplex Cᵒᵖ where obj S := (Opposite.unop S).op map φ := opMap φ.unop /-- The obvious functor `ShortComplex Cᵒᵖ ⥤ (ShortComplex C)ᵒᵖ`. -/ @[simps] def unopFunctor : ShortComplex Cᵒᵖ ⥤ (ShortComplex C)ᵒᵖ where obj S := Opposite.op (S.unop) map φ := (unopMap φ).op /-- The obvious equivalence of categories `(ShortComplex C)ᵒᵖ ≌ ShortComplex Cᵒᵖ`. -/ @[simps] def opEquiv : (ShortComplex C)ᵒᵖ ≌ ShortComplex Cᵒᵖ where functor := opFunctor C inverse := unopFunctor C unitIso := Iso.refl _ counitIso := Iso.refl _ variable {C} /-- The canonical isomorphism `S.unop.op ≅ S` for a short complex `S` in `Cᵒᵖ` -/ abbrev unopOp (S : ShortComplex Cᵒᵖ) : S.unop.op ≅ S := (opEquiv C).counitIso.app S /-- The canonical isomorphism `S.op.unop ≅ S` for a short complex `S` -/ abbrev opUnop (S : ShortComplex C) : S.op.unop ≅ S := Iso.unop ((opEquiv C).unitIso.app (Opposite.op S)) end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/ExactFunctor.lean
import Mathlib.Algebra.Homology.ShortComplex.PreservesHomology import Mathlib.Algebra.Homology.ShortComplex.ShortExact import Mathlib.Algebra.Homology.ShortComplex.Abelian import Mathlib.CategoryTheory.Preadditive.LeftExact import Mathlib.CategoryTheory.Abelian.Exact /-! # Exact functors In this file, it is shown that additive functors which preserves homology also preserves finite limits and finite colimits. ## Main results Let `F : C ⥤ D` be an additive functor: - `Functor.preservesFiniteLimits_of_preservesHomology`: if `F` preserves homology, then `F` preserves finite limits. - `Functor.preservesFiniteColimits_of_preservesHomology`: if `F` preserves homology, then `F` preserves finite colimits. If we further assume that `C` and `D` are abelian categories, then we have: - `Functor.preservesFiniteLimits_tfae`: the following are equivalent: 1. for every short exact sequence `0 ⟶ A ⟶ B ⟶ C ⟶ 0`, `0 ⟶ F(A) ⟶ F(B) ⟶ F(C) ⟶ 0` is exact. 2. for every exact sequence `A ⟶ B ⟶ C` where `A ⟶ B` is mono, `F(A) ⟶ F(B) ⟶ F(C)` is exact and `F(A) ⟶ F(B)` is mono. 3. `F` preserves kernels. 4. `F` preserves finite limits. - `Functor.preservesFiniteColimits_tfae`: the following are equivalent: 1. for every short exact sequence `0 ⟶ A ⟶ B ⟶ C ⟶ 0`, `F(A) ⟶ F(B) ⟶ F(C) ⟶ 0` is exact. 2. for every exact sequence `A ⟶ B ⟶ C` where `B ⟶ C` is epi, `F(A) ⟶ F(B) ⟶ F(C)` is exact and `F(B) ⟶ F(C)` is epi. 3. `F` preserves cokernels. 4. `F` preserves finite colimits. - `Functor.exact_tfae`: the following are equivalent: 1. for every short exact sequence `0 ⟶ A ⟶ B ⟶ C ⟶ 0`, `0 ⟶ F(A) ⟶ F(B) ⟶ F(C) ⟶ 0` is exact. 2. for every exact sequence `A ⟶ B ⟶ C`, `F(A) ⟶ F(B) ⟶ F(C)` is exact. 3. `F` preserves homology. 4. `F` preserves both finite limits and finite colimits. -/ namespace CategoryTheory open Limits ZeroObject ShortComplex namespace Functor section variable {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D] (F : C ⥤ D) [F.Additive] [F.PreservesHomology] [HasZeroObject C] /-- An additive functor which preserves homology preserves finite limits. -/ lemma preservesFiniteLimits_of_preservesHomology [HasFiniteProducts C] [HasKernels C] : PreservesFiniteLimits F := by have := fun {X Y : C} (f : X ⟶ Y) ↦ PreservesHomology.preservesKernel F f have : HasBinaryBiproducts C := HasBinaryBiproducts.of_hasBinaryProducts have : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels have : HasZeroObject D := ⟨F.obj 0, by rw [IsZero.iff_id_eq_zero, ← F.map_id, id_zero, F.map_zero]⟩ exact preservesFiniteLimits_of_preservesKernels F /-- An additive which preserves homology preserves finite colimits. -/ lemma preservesFiniteColimits_of_preservesHomology [HasFiniteCoproducts C] [HasCokernels C] : PreservesFiniteColimits F := by have := fun {X Y : C} (f : X ⟶ Y) ↦ PreservesHomology.preservesCokernel F f have : HasBinaryBiproducts C := HasBinaryBiproducts.of_hasBinaryCoproducts have : HasCoequalizers C := Preadditive.hasCoequalizers_of_hasCokernels have : HasZeroObject D := ⟨F.obj 0, by rw [IsZero.iff_id_eq_zero, ← F.map_id, id_zero, F.map_zero]⟩ exact preservesFiniteColimits_of_preservesCokernels F end section variable {C D : Type*} [Category C] [Category D] [Abelian C] [Abelian D] variable (F : C ⥤ D) [F.Additive] /-- If a functor `F : C ⥤ D` preserves short exact sequences on the left-hand side, (i.e. if `0 ⟶ A ⟶ B ⟶ C ⟶ 0` is exact then `0 ⟶ F(A) ⟶ F(B) ⟶ F(C)` is exact) then it preserves monomorphism. -/ lemma preservesMonomorphisms_of_preserves_shortExact_left (h : ∀ (S : ShortComplex C), S.ShortExact → (S.map F).Exact ∧ Mono (F.map S.f)) : F.PreservesMonomorphisms where preserves f := h _ { exact := exact_cokernel f } |>.2 /-- For an additive functor `F : C ⥤ D` between abelian categories, the following are equivalent: - `F` preserves short exact sequences on the left-hand side, i.e. if `0 ⟶ A ⟶ B ⟶ C ⟶ 0` is exact then `0 ⟶ F(A) ⟶ F(B) ⟶ F(C)` is exact. - `F` preserves exact sequences on the left-hand side, i.e. if `A ⟶ B ⟶ C` is exact where `A ⟶ B` is mono, then `F(A) ⟶ F(B) ⟶ F(C)` is exact and `F(A) ⟶ F(B)` is mono as well. - `F` preserves kernels. - `F` preserves finite limits. -/ lemma preservesFiniteLimits_tfae : List.TFAE [ ∀ (S : ShortComplex C), S.ShortExact → (S.map F).Exact ∧ Mono (F.map S.f), ∀ (S : ShortComplex C), S.Exact ∧ Mono S.f → (S.map F).Exact ∧ Mono (F.map S.f), ∀ ⦃X Y : C⦄ (f : X ⟶ Y), PreservesLimit (parallelPair f 0) F, PreservesFiniteLimits F ] := by tfae_have 1 → 2 | hF, S, ⟨hS, hf⟩ => by have := preservesMonomorphisms_of_preserves_shortExact_left F hF refine ⟨?_, inferInstance⟩ let T := ShortComplex.mk S.f (Abelian.coimage.π S.g) (Abelian.comp_coimage_π_eq_zero S.zero) let φ : T.map F ⟶ S.map F := { τ₁ := 𝟙 _ τ₂ := 𝟙 _ τ₃ := F.map <| Abelian.factorThruCoimage S.g comm₂₃ := show 𝟙 _ ≫ F.map _ = F.map (cokernel.π _) ≫ _ by rw [Category.id_comp, ← F.map_comp, cokernel.π_desc] } exact (exact_iff_of_epi_of_isIso_of_mono φ).1 (hF T ⟨(S.exact_iff_exact_coimage_π).1 hS⟩).1 tfae_have 2 → 3 | hF, X, Y, f => by refine preservesLimit_of_preserves_limit_cone (kernelIsKernel f) ?_ apply (KernelFork.isLimitMapConeEquiv _ F).2 let S := ShortComplex.mk _ _ (kernel.condition f) let hS := hF S ⟨exact_kernel f, inferInstance⟩ have : Mono (S.map F).f := hS.2 exact hS.1.fIsKernel tfae_have 3 → 4 | hF => by exact preservesFiniteLimits_of_preservesKernels F tfae_have 4 → 1 | ⟨_⟩, S, hS => (S.map F).exact_and_mono_f_iff_f_is_kernel |>.2 ⟨KernelFork.mapIsLimit _ hS.fIsKernel F⟩ tfae_finish /-- If a functor `F : C ⥤ D` preserves exact sequences on the right-hand side (i.e. if `0 ⟶ A ⟶ B ⟶ C ⟶ 0` is exact then `F(A) ⟶ F(B) ⟶ F(C) ⟶ 0` is exact), then it preserves epimorphisms. -/ lemma preservesEpimorphisms_of_preserves_shortExact_right (h : ∀ (S : ShortComplex C), S.ShortExact → (S.map F).Exact ∧ Epi (F.map S.g)) : F.PreservesEpimorphisms where preserves f := h _ { exact := exact_kernel f } |>.2 /-- For an additive functor `F : C ⥤ D` between abelian categories, the following are equivalent: - `F` preserves short exact sequences on the right-hand side, i.e. if `0 ⟶ A ⟶ B ⟶ C ⟶ 0` is exact then `F(A) ⟶ F(B) ⟶ F(C) ⟶ 0` is exact. - `F` preserves exact sequences on the right-hand side, i.e. if `A ⟶ B ⟶ C` is exact where `B ⟶ C` is epi, then `F(A) ⟶ F(B) ⟶ F(C) ⟶ 0` is exact and `F(B) ⟶ F(C)` is epi as well. - `F` preserves cokernels. - `F` preserves finite colimits. -/ lemma preservesFiniteColimits_tfae : List.TFAE [ ∀ (S : ShortComplex C), S.ShortExact → (S.map F).Exact ∧ Epi (F.map S.g), ∀ (S : ShortComplex C), S.Exact ∧ Epi S.g → (S.map F).Exact ∧ Epi (F.map S.g), ∀ ⦃X Y : C⦄ (f : X ⟶ Y), PreservesColimit (parallelPair f 0) F, PreservesFiniteColimits F ] := by tfae_have 1 → 2 | hF, S, ⟨hS, hf⟩ => by have := preservesEpimorphisms_of_preserves_shortExact_right F hF refine ⟨?_, inferInstance⟩ let T := ShortComplex.mk (Abelian.image.ι S.f) S.g (Abelian.image_ι_comp_eq_zero S.zero) let φ : S.map F ⟶ T.map F := { τ₁ := F.map <| Abelian.factorThruImage S.f τ₂ := 𝟙 _ τ₃ := 𝟙 _ comm₁₂ := show _ ≫ F.map (kernel.ι _) = F.map _ ≫ 𝟙 _ by rw [← F.map_comp, Abelian.image.fac, Category.comp_id] } exact (exact_iff_of_epi_of_isIso_of_mono φ).2 (hF T ⟨(S.exact_iff_exact_image_ι).1 hS⟩).1 tfae_have 2 → 3 | hF, X, Y, f => by refine preservesColimit_of_preserves_colimit_cocone (cokernelIsCokernel f) ?_ apply (CokernelCofork.isColimitMapCoconeEquiv _ F).2 let S := ShortComplex.mk _ _ (cokernel.condition f) let hS := hF S ⟨exact_cokernel f, inferInstance⟩ have : Epi (S.map F).g := hS.2 exact hS.1.gIsCokernel tfae_have 3 → 4 | hF => by exact preservesFiniteColimits_of_preservesCokernels F tfae_have 4 → 1 | ⟨_⟩, S, hS => (S.map F).exact_and_epi_g_iff_g_is_cokernel |>.2 ⟨CokernelCofork.mapIsColimit _ hS.gIsCokernel F⟩ tfae_finish /-- For an additive functor `F : C ⥤ D` between abelian categories, the following are equivalent: - `F` preserves short exact sequences, i.e. if `0 ⟶ A ⟶ B ⟶ C ⟶ 0` is exact then `0 ⟶ F(A) ⟶ F(B) ⟶ F(C) ⟶ 0` is exact. - `F` preserves exact sequences, i.e. if `A ⟶ B ⟶ C` is exact then `F(A) ⟶ F(B) ⟶ F(C)` is exact. - `F` preserves homology. - `F` preserves both finite limits and finite colimits. -/ lemma exact_tfae : List.TFAE [ ∀ (S : ShortComplex C), S.ShortExact → (S.map F).ShortExact, ∀ (S : ShortComplex C), S.Exact → (S.map F).Exact, PreservesHomology F, PreservesFiniteLimits F ∧ PreservesFiniteColimits F ] := by tfae_have 1 → 3 | hF => by refine ⟨fun {X Y} f ↦ ?_, fun {X Y} f ↦ ?_⟩ · have h := (preservesFiniteLimits_tfae F |>.out 0 2 |>.1 fun S hS ↦ And.intro (hF S hS).exact (hF S hS).mono_f) exact h f · have h := (preservesFiniteColimits_tfae F |>.out 0 2 |>.1 fun S hS ↦ And.intro (hF S hS).exact (hF S hS).epi_g) exact h f tfae_have 2 → 1 | hF, S, hS => by have : Mono (S.map F).f := exact_iff_mono _ (by simp) |>.1 <| hF (.mk (0 : 0 ⟶ S.X₁) S.f <| by simp) (exact_iff_mono _ (by simp) |>.2 hS.mono_f) have : Epi (S.map F).g := exact_iff_epi _ (by simp) |>.1 <| hF (.mk S.g (0 : S.X₃ ⟶ 0) <| by simp) (exact_iff_epi _ (by simp) |>.2 hS.epi_g) exact ⟨hF S hS.exact⟩ tfae_have 3 → 4 | h => ⟨preservesFiniteLimits_of_preservesHomology F, preservesFiniteColimits_of_preservesHomology F⟩ tfae_have 4 → 2 | ⟨h1, h2⟩, _, h => h.map F tfae_finish end end Functor end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/ShortExact.lean
import Mathlib.Algebra.Homology.ShortComplex.Exact import Mathlib.CategoryTheory.Preadditive.Injective.Basic /-! # Short exact short complexes A short complex `S : ShortComplex C` is short exact (`S.ShortExact`) when it is exact, `S.f` is a mono and `S.g` is an epi. -/ namespace CategoryTheory open Category Limits ZeroObject variable {C D : Type*} [Category C] [Category D] namespace ShortComplex section variable [HasZeroMorphisms C] [HasZeroMorphisms D] (S : ShortComplex C) {S₁ S₂ : ShortComplex C} /-- A short complex `S` is short exact if it is exact, `S.f` is a mono and `S.g` is an epi. -/ structure ShortExact : Prop where exact : S.Exact [mono_f : Mono S.f] [epi_g : Epi S.g] variable {S} lemma ShortExact.mk' (h : S.Exact) (_ : Mono S.f) (_ : Epi S.g) : S.ShortExact where exact := h lemma shortExact_of_iso (e : S₁ ≅ S₂) (h : S₁.ShortExact) : S₂.ShortExact where exact := exact_of_iso e h.exact mono_f := by suffices Mono (S₂.f ≫ e.inv.τ₂) by exact mono_of_mono _ e.inv.τ₂ have := h.mono_f rw [← e.inv.comm₁₂] apply mono_comp epi_g := by suffices Epi (e.hom.τ₂ ≫ S₂.g) by exact epi_of_epi e.hom.τ₂ _ have := h.epi_g rw [e.hom.comm₂₃] apply epi_comp lemma shortExact_iff_of_iso (e : S₁ ≅ S₂) : S₁.ShortExact ↔ S₂.ShortExact := by constructor · exact shortExact_of_iso e · exact shortExact_of_iso e.symm lemma ShortExact.op (h : S.ShortExact) : S.op.ShortExact where exact := h.exact.op mono_f := by have := h.epi_g dsimp infer_instance epi_g := by have := h.mono_f dsimp infer_instance lemma ShortExact.unop {S : ShortComplex Cᵒᵖ} (h : S.ShortExact) : S.unop.ShortExact where exact := h.exact.unop mono_f := by have := h.epi_g dsimp infer_instance epi_g := by have := h.mono_f dsimp infer_instance variable (S) lemma shortExact_iff_op : S.ShortExact ↔ S.op.ShortExact := ⟨ShortExact.op, ShortExact.unop⟩ lemma shortExact_iff_unop (S : ShortComplex Cᵒᵖ) : S.ShortExact ↔ S.unop.ShortExact := S.unop.shortExact_iff_op.symm variable {S} lemma ShortExact.map (h : S.ShortExact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] [Mono (F.map S.f)] [Epi (F.map S.g)] : (S.map F).ShortExact where exact := h.exact.map F mono_f := (inferInstance : Mono (F.map S.f)) epi_g := (inferInstance : Epi (F.map S.g)) lemma ShortExact.map_of_exact (hS : S.ShortExact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [PreservesFiniteLimits F] [PreservesFiniteColimits F] : (S.map F).ShortExact := by have := hS.mono_f have := hS.epi_g exact hS.map F end section Preadditive variable [Preadditive C] lemma ShortExact.isIso_f_iff {S : ShortComplex C} (hS : S.ShortExact) [Balanced C] : IsIso S.f ↔ IsZero S.X₃ := by have := hS.exact.hasZeroObject have := hS.mono_f have := hS.epi_g constructor · intro hf simp only [IsZero.iff_id_eq_zero, ← cancel_epi S.g, ← cancel_epi S.f, S.zero_assoc, zero_comp] · intro hX₃ have : Epi S.f := (S.exact_iff_epi (hX₃.eq_of_tgt _ _)).1 hS.exact apply isIso_of_mono_of_epi lemma ShortExact.isIso_g_iff {S : ShortComplex C} (hS : S.ShortExact) [Balanced C] : IsIso S.g ↔ IsZero S.X₁ := by have := hS.exact.hasZeroObject have := hS.mono_f have := hS.epi_g constructor · intro hf simp only [IsZero.iff_id_eq_zero, ← cancel_mono S.f, ← cancel_mono S.g, S.zero, zero_comp, assoc, comp_zero] · intro hX₁ have : Mono S.g := (S.exact_iff_mono (hX₁.eq_of_src _ _)).1 hS.exact apply isIso_of_mono_of_epi lemma isIso₂_of_shortExact_of_isIso₁₃ [Balanced C] {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) (h₁ : S₁.ShortExact) (h₂ : S₂.ShortExact) [IsIso φ.τ₁] [IsIso φ.τ₃] : IsIso φ.τ₂ := by have := h₁.mono_f have := h₂.mono_f have := h₁.epi_g have := h₂.epi_g have := mono_τ₂_of_exact_of_mono φ h₁.exact have := epi_τ₂_of_exact_of_epi φ h₂.exact apply isIso_of_mono_of_epi lemma isIso₂_of_shortExact_of_isIso₁₃' [Balanced C] {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) (h₁ : S₁.ShortExact) (h₂ : S₂.ShortExact) (_ : IsIso φ.τ₁) (_ : IsIso φ.τ₃) : IsIso φ.τ₂ := isIso₂_of_shortExact_of_isIso₁₃ φ h₁ h₂ /-- If `S` is a short exact short complex in a balanced category, then `S.X₁` is the kernel of `S.g`. -/ noncomputable def ShortExact.fIsKernel [Balanced C] {S : ShortComplex C} (hS : S.ShortExact) : IsLimit (KernelFork.ofι S.f S.zero) := by have := hS.mono_f exact hS.exact.fIsKernel /-- If `S` is a short exact short complex in a balanced category, then `S.X₃` is the cokernel of `S.f`. -/ noncomputable def ShortExact.gIsCokernel [Balanced C] {S : ShortComplex C} (hS : S.ShortExact) : IsColimit (CokernelCofork.ofπ S.g S.zero) := by have := hS.epi_g exact hS.exact.gIsCokernel /-- Is `S` is an exact short complex and `h : S.HomologyData`, there is a short exact sequence `0 ⟶ h.left.K ⟶ S.X₂ ⟶ h.right.Q ⟶ 0`. -/ lemma Exact.shortExact {S : ShortComplex C} (hS : S.Exact) (h : S.HomologyData) : (ShortComplex.mk _ _ (h.exact_iff_i_p_zero.1 hS)).ShortExact where exact := by have := hS.epi_f' h.left have := hS.mono_g' h.right let S' := ShortComplex.mk h.left.i S.g (by simp) let S'' := ShortComplex.mk _ _ (h.exact_iff_i_p_zero.1 hS) let a : S ⟶ S' := { τ₁ := h.left.f' τ₂ := 𝟙 _ τ₃ := 𝟙 _ } let b : S'' ⟶ S' := { τ₁ := 𝟙 _ τ₂ := 𝟙 _ τ₃ := h.right.g' } rwa [ShortComplex.exact_iff_of_epi_of_isIso_of_mono b, ← ShortComplex.exact_iff_of_epi_of_isIso_of_mono a] /-- A split short complex is short exact. -/ lemma Splitting.shortExact {S : ShortComplex C} [HasZeroObject C] (s : S.Splitting) : S.ShortExact where exact := s.exact mono_f := s.mono_f epi_g := s.epi_g namespace ShortExact /-- A choice of splitting for a short exact short complex `S` in a balanced category such that `S.X₁` is injective. -/ noncomputable def splittingOfInjective {S : ShortComplex C} (hS : S.ShortExact) [Injective S.X₁] [Balanced C] : S.Splitting := have := hS.mono_f Splitting.ofExactOfRetraction S hS.exact (Injective.factorThru (𝟙 S.X₁) S.f) (by simp) hS.epi_g /-- A choice of splitting for a short exact short complex `S` in a balanced category such that `S.X₃` is projective. -/ noncomputable def splittingOfProjective {S : ShortComplex C} (hS : S.ShortExact) [Projective S.X₃] [Balanced C] : S.Splitting := have := hS.epi_g Splitting.ofExactOfSection S hS.exact (Projective.factorThru (𝟙 S.X₃) S.g) (by simp) hS.mono_f end ShortExact end Preadditive end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Exact.lean
import Mathlib.Algebra.Homology.ShortComplex.PreservesHomology import Mathlib.Algebra.Homology.ShortComplex.Abelian import Mathlib.Algebra.Homology.ShortComplex.QuasiIso import Mathlib.CategoryTheory.Abelian.Opposite import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Preadditive.Injective.Basic /-! # Exact short complexes When `S : ShortComplex C`, this file defines a structure `S.Exact` which expresses the exactness of `S`, i.e. there exists a homology data `h : S.HomologyData` such that `h.left.H` is zero. When `[S.HasHomology]`, it is equivalent to the assertion `IsZero S.homology`. Almost by construction, this notion of exactness is self dual, see `Exact.op` and `Exact.unop`. -/ namespace CategoryTheory open Category Limits ZeroObject Preadditive variable {C D : Type*} [Category C] [Category D] namespace ShortComplex section variable [HasZeroMorphisms C] [HasZeroMorphisms D] (S : ShortComplex C) {S₁ S₂ : ShortComplex C} /-- The assertion that the short complex `S : ShortComplex C` is exact. -/ structure Exact : Prop where /-- the condition that there exists an homology data whose `left.H` field is zero -/ condition : ∃ (h : S.HomologyData), IsZero h.left.H variable {S} lemma Exact.hasHomology (h : S.Exact) : S.HasHomology := HasHomology.mk' h.condition.choose lemma Exact.hasZeroObject (h : S.Exact) : HasZeroObject C := ⟨h.condition.choose.left.H, h.condition.choose_spec⟩ variable (S) lemma exact_iff_isZero_homology [S.HasHomology] : S.Exact ↔ IsZero S.homology := by constructor · rintro ⟨⟨h', z⟩⟩ exact IsZero.of_iso z h'.left.homologyIso · intro h exact ⟨⟨_, h⟩⟩ variable {S} lemma LeftHomologyData.exact_iff [S.HasHomology] (h : S.LeftHomologyData) : S.Exact ↔ IsZero h.H := by rw [S.exact_iff_isZero_homology] exact Iso.isZero_iff h.homologyIso lemma RightHomologyData.exact_iff [S.HasHomology] (h : S.RightHomologyData) : S.Exact ↔ IsZero h.H := by rw [S.exact_iff_isZero_homology] exact Iso.isZero_iff h.homologyIso variable (S) lemma exact_iff_isZero_leftHomology [S.HasHomology] : S.Exact ↔ IsZero S.leftHomology := LeftHomologyData.exact_iff _ lemma exact_iff_isZero_rightHomology [S.HasHomology] : S.Exact ↔ IsZero S.rightHomology := RightHomologyData.exact_iff _ variable {S} lemma HomologyData.exact_iff (h : S.HomologyData) : S.Exact ↔ IsZero h.left.H := by haveI := HasHomology.mk' h exact LeftHomologyData.exact_iff h.left lemma HomologyData.exact_iff' (h : S.HomologyData) : S.Exact ↔ IsZero h.right.H := by haveI := HasHomology.mk' h exact RightHomologyData.exact_iff h.right variable (S) lemma exact_iff_homology_iso_zero [S.HasHomology] [HasZeroObject C] : S.Exact ↔ Nonempty (S.homology ≅ 0) := by rw [exact_iff_isZero_homology] constructor · intro h exact ⟨h.isoZero⟩ · rintro ⟨e⟩ exact IsZero.of_iso (isZero_zero C) e lemma exact_of_iso (e : S₁ ≅ S₂) (h : S₁.Exact) : S₂.Exact := by obtain ⟨⟨h, z⟩⟩ := h exact ⟨⟨HomologyData.ofIso e h, z⟩⟩ lemma exact_iff_of_iso (e : S₁ ≅ S₂) : S₁.Exact ↔ S₂.Exact := ⟨exact_of_iso e, exact_of_iso e.symm⟩ lemma exact_and_mono_f_iff_of_iso (e : S₁ ≅ S₂) : S₁.Exact ∧ Mono S₁.f ↔ S₂.Exact ∧ Mono S₂.f := by have : Mono S₁.f ↔ Mono S₂.f := (MorphismProperty.monomorphisms C).arrow_mk_iso_iff (Arrow.isoMk (ShortComplex.π₁.mapIso e) (ShortComplex.π₂.mapIso e) e.hom.comm₁₂) rw [exact_iff_of_iso e, this] lemma exact_and_epi_g_iff_of_iso (e : S₁ ≅ S₂) : S₁.Exact ∧ Epi S₁.g ↔ S₂.Exact ∧ Epi S₂.g := by have : Epi S₁.g ↔ Epi S₂.g := (MorphismProperty.epimorphisms C).arrow_mk_iso_iff (Arrow.isoMk (ShortComplex.π₂.mapIso e) (ShortComplex.π₃.mapIso e) e.hom.comm₂₃) rw [exact_iff_of_iso e, this] lemma exact_of_isZero_X₂ (h : IsZero S.X₂) : S.Exact := by rw [(HomologyData.ofZeros S (IsZero.eq_of_tgt h _ _) (IsZero.eq_of_src h _ _)).exact_iff] exact h lemma exact_iff_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : S₁.Exact ↔ S₂.Exact := by constructor · rintro ⟨h₁, z₁⟩ exact ⟨HomologyData.ofEpiOfIsIsoOfMono φ h₁, z₁⟩ · rintro ⟨h₂, z₂⟩ exact ⟨HomologyData.ofEpiOfIsIsoOfMono' φ h₂, z₂⟩ variable {S} lemma HomologyData.exact_iff_i_p_zero (h : S.HomologyData) : S.Exact ↔ h.left.i ≫ h.right.p = 0 := by haveI := HasHomology.mk' h rw [h.left.exact_iff, ← h.comm] constructor · intro z rw [IsZero.eq_of_src z h.iso.hom 0, zero_comp, comp_zero] · intro eq simp only [IsZero.iff_id_eq_zero, ← cancel_mono h.iso.hom, id_comp, ← cancel_mono h.right.ι, ← cancel_epi h.left.π, eq, zero_comp, comp_zero] variable (S) lemma exact_iff_i_p_zero [S.HasHomology] (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) : S.Exact ↔ h₁.i ≫ h₂.p = 0 := (HomologyData.ofIsIsoLeftRightHomologyComparison' h₁ h₂).exact_iff_i_p_zero lemma exact_iff_iCycles_pOpcycles_zero [S.HasHomology] : S.Exact ↔ S.iCycles ≫ S.pOpcycles = 0 := S.exact_iff_i_p_zero _ _ lemma exact_iff_kernel_ι_comp_cokernel_π_zero [S.HasHomology] [HasKernel S.g] [HasCokernel S.f] : S.Exact ↔ kernel.ι S.g ≫ cokernel.π S.f = 0 := by haveI := HasLeftHomology.hasCokernel S haveI := HasRightHomology.hasKernel S exact S.exact_iff_i_p_zero (LeftHomologyData.ofHasKernelOfHasCokernel S) (RightHomologyData.ofHasCokernelOfHasKernel S) variable {S} lemma Exact.op (h : S.Exact) : S.op.Exact := by obtain ⟨h, z⟩ := h exact ⟨⟨h.op, (IsZero.of_iso z h.iso.symm).op⟩⟩ lemma Exact.unop {S : ShortComplex Cᵒᵖ} (h : S.Exact) : S.unop.Exact := by obtain ⟨h, z⟩ := h exact ⟨⟨h.unop, (IsZero.of_iso z h.iso.symm).unop⟩⟩ variable (S) @[simp] lemma exact_op_iff : S.op.Exact ↔ S.Exact := ⟨Exact.unop, Exact.op⟩ @[simp] lemma exact_unop_iff (S : ShortComplex Cᵒᵖ) : S.unop.Exact ↔ S.Exact := S.unop.exact_op_iff.symm variable {S} lemma LeftHomologyData.exact_map_iff (h : S.LeftHomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h.IsPreservedBy F] [(S.map F).HasHomology] : (S.map F).Exact ↔ IsZero (F.obj h.H) := (h.map F).exact_iff lemma RightHomologyData.exact_map_iff (h : S.RightHomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h.IsPreservedBy F] [(S.map F).HasHomology] : (S.map F).Exact ↔ IsZero (F.obj h.H) := (h.map F).exact_iff lemma Exact.map_of_preservesLeftHomologyOf (h : S.Exact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [(S.map F).HasHomology] : (S.map F).Exact := by have := h.hasHomology rw [S.leftHomologyData.exact_iff, IsZero.iff_id_eq_zero] at h rw [S.leftHomologyData.exact_map_iff F, IsZero.iff_id_eq_zero, ← F.map_id, h, F.map_zero] lemma Exact.map_of_preservesRightHomologyOf (h : S.Exact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesRightHomologyOf S] [(S.map F).HasHomology] : (S.map F).Exact := by have : S.HasHomology := h.hasHomology rw [S.rightHomologyData.exact_iff, IsZero.iff_id_eq_zero] at h rw [S.rightHomologyData.exact_map_iff F, IsZero.iff_id_eq_zero, ← F.map_id, h, F.map_zero] lemma Exact.map (h : S.Exact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] : (S.map F).Exact := by have := h.hasHomology exact h.map_of_preservesLeftHomologyOf F variable (S) lemma exact_map_iff_of_faithful [S.HasHomology] (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] [F.Faithful] : (S.map F).Exact ↔ S.Exact := by constructor · intro h rw [S.leftHomologyData.exact_iff, IsZero.iff_id_eq_zero] rw [(S.leftHomologyData.map F).exact_iff, IsZero.iff_id_eq_zero, LeftHomologyData.map_H] at h apply F.map_injective rw [F.map_id, F.map_zero, h] · intro h exact h.map F variable {S} @[reassoc] lemma Exact.comp_eq_zero (h : S.Exact) {X Y : C} {a : X ⟶ S.X₂} (ha : a ≫ S.g = 0) {b : S.X₂ ⟶ Y} (hb : S.f ≫ b = 0) : a ≫ b = 0 := by have := h.hasHomology have eq := h rw [exact_iff_iCycles_pOpcycles_zero] at eq rw [← S.liftCycles_i a ha, ← S.p_descOpcycles b hb, assoc, reassoc_of% eq, zero_comp, comp_zero] lemma Exact.isZero_of_both_zeros (ex : S.Exact) (hf : S.f = 0) (hg : S.g = 0) : IsZero S.X₂ := (ShortComplex.HomologyData.ofZeros S hf hg).exact_iff.1 ex end section Preadditive variable [Preadditive C] [Preadditive D] (S : ShortComplex C) lemma exact_iff_mono [HasZeroObject C] (hf : S.f = 0) : S.Exact ↔ Mono S.g := by constructor · intro h have := h.hasHomology simp only [exact_iff_isZero_homology] at h have := S.isIso_pOpcycles hf have := mono_of_isZero_kernel' _ S.homologyIsKernel h rw [← S.p_fromOpcycles] apply mono_comp · intro rw [(HomologyData.ofIsLimitKernelFork S hf _ (KernelFork.IsLimit.ofMonoOfIsZero (KernelFork.ofι (0 : 0 ⟶ S.X₂) zero_comp) inferInstance (isZero_zero C))).exact_iff] exact isZero_zero C lemma exact_iff_epi [HasZeroObject C] (hg : S.g = 0) : S.Exact ↔ Epi S.f := by constructor · intro h have := h.hasHomology simp only [exact_iff_isZero_homology] at h haveI := S.isIso_iCycles hg haveI : Epi S.toCycles := epi_of_isZero_cokernel' _ S.homologyIsCokernel h rw [← S.toCycles_i] apply epi_comp · intro rw [(HomologyData.ofIsColimitCokernelCofork S hg _ (CokernelCofork.IsColimit.ofEpiOfIsZero (CokernelCofork.ofπ (0 : S.X₂ ⟶ 0) comp_zero) inferInstance (isZero_zero C))).exact_iff] exact isZero_zero C variable {S} lemma Exact.epi_f' (hS : S.Exact) (h : LeftHomologyData S) : Epi h.f' := epi_of_isZero_cokernel' _ h.hπ (by haveI := hS.hasHomology dsimp simpa only [← h.exact_iff] using hS) lemma Exact.mono_g' (hS : S.Exact) (h : RightHomologyData S) : Mono h.g' := mono_of_isZero_kernel' _ h.hι (by haveI := hS.hasHomology dsimp simpa only [← h.exact_iff] using hS) lemma Exact.epi_toCycles (hS : S.Exact) [S.HasLeftHomology] : Epi S.toCycles := hS.epi_f' _ lemma Exact.mono_fromOpcycles (hS : S.Exact) [S.HasRightHomology] : Mono S.fromOpcycles := hS.mono_g' _ lemma LeftHomologyData.exact_iff_epi_f' [S.HasHomology] (h : LeftHomologyData S) : S.Exact ↔ Epi h.f' := by constructor · intro hS exact hS.epi_f' h · intro simp only [h.exact_iff, IsZero.iff_id_eq_zero, ← cancel_epi h.π, ← cancel_epi h.f', comp_id, h.f'_π, comp_zero] lemma RightHomologyData.exact_iff_mono_g' [S.HasHomology] (h : RightHomologyData S) : S.Exact ↔ Mono h.g' := by constructor · intro hS exact hS.mono_g' h · intro simp only [h.exact_iff, IsZero.iff_id_eq_zero, ← cancel_mono h.ι, ← cancel_mono h.g', id_comp, h.ι_g', zero_comp] /-- Given an exact short complex `S` and a limit kernel fork `kf` for `S.g`, this is the left homology data for `S` with `K := kf.pt` and `H := 0`. -/ @[simps] noncomputable def Exact.leftHomologyDataOfIsLimitKernelFork (hS : S.Exact) [HasZeroObject C] (kf : KernelFork S.g) (hkf : IsLimit kf) : S.LeftHomologyData where K := kf.pt H := 0 i := kf.ι π := 0 wi := kf.condition hi := IsLimit.ofIsoLimit hkf (Fork.ext (Iso.refl _) (by simp)) wπ := comp_zero hπ := CokernelCofork.IsColimit.ofEpiOfIsZero _ (by have := hS.hasHomology refine ((MorphismProperty.epimorphisms C).arrow_mk_iso_iff ?_).1 hS.epi_toCycles refine Arrow.isoMk (Iso.refl _) (IsLimit.conePointUniqueUpToIso S.cyclesIsKernel hkf) ?_ apply Fork.IsLimit.hom_ext hkf simp [IsLimit.conePointUniqueUpToIso]) (isZero_zero C) /-- Given an exact short complex `S` and a colimit cokernel cofork `cc` for `S.f`, this is the right homology data for `S` with `Q := cc.pt` and `H := 0`. -/ @[simps] noncomputable def Exact.rightHomologyDataOfIsColimitCokernelCofork (hS : S.Exact) [HasZeroObject C] (cc : CokernelCofork S.f) (hcc : IsColimit cc) : S.RightHomologyData where Q := cc.pt H := 0 p := cc.π ι := 0 wp := cc.condition hp := IsColimit.ofIsoColimit hcc (Cofork.ext (Iso.refl _) (by simp)) wι := zero_comp hι := KernelFork.IsLimit.ofMonoOfIsZero _ (by have := hS.hasHomology refine ((MorphismProperty.monomorphisms C).arrow_mk_iso_iff ?_).2 hS.mono_fromOpcycles refine Arrow.isoMk (IsColimit.coconePointUniqueUpToIso hcc S.opcyclesIsCokernel) (Iso.refl _) ?_ apply Cofork.IsColimit.hom_ext hcc simp [IsColimit.coconePointUniqueUpToIso]) (isZero_zero C) variable (S) lemma exact_iff_epi_toCycles [S.HasHomology] : S.Exact ↔ Epi S.toCycles := S.leftHomologyData.exact_iff_epi_f' lemma exact_iff_mono_fromOpcycles [S.HasHomology] : S.Exact ↔ Mono S.fromOpcycles := S.rightHomologyData.exact_iff_mono_g' lemma exact_iff_epi_kernel_lift [S.HasHomology] [HasKernel S.g] : S.Exact ↔ Epi (kernel.lift S.g S.f S.zero) := by rw [exact_iff_epi_toCycles] apply (MorphismProperty.epimorphisms C).arrow_mk_iso_iff exact Arrow.isoMk (Iso.refl _) S.cyclesIsoKernel (by cat_disch) lemma exact_iff_mono_cokernel_desc [S.HasHomology] [HasCokernel S.f] : S.Exact ↔ Mono (cokernel.desc S.f S.g S.zero) := by rw [exact_iff_mono_fromOpcycles] refine (MorphismProperty.monomorphisms C).arrow_mk_iso_iff (Iso.symm ?_) exact Arrow.isoMk S.opcyclesIsoCokernel.symm (Iso.refl _) (by cat_disch) lemma QuasiIso.exact_iff {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] [QuasiIso φ] : S₁.Exact ↔ S₂.Exact := by simp only [exact_iff_isZero_homology] exact Iso.isZero_iff (asIso (homologyMap φ)) lemma exact_of_f_is_kernel (hS : IsLimit (KernelFork.ofι S.f S.zero)) [S.HasHomology] : S.Exact := by rw [exact_iff_epi_toCycles] have : IsSplitEpi S.toCycles := ⟨⟨{ section_ := hS.lift (KernelFork.ofι S.iCycles S.iCycles_g) id := by rw [← cancel_mono S.iCycles, assoc, toCycles_i, id_comp] exact Fork.IsLimit.lift_ι hS }⟩⟩ infer_instance lemma exact_of_g_is_cokernel (hS : IsColimit (CokernelCofork.ofπ S.g S.zero)) [S.HasHomology] : S.Exact := by rw [exact_iff_mono_fromOpcycles] have : IsSplitMono S.fromOpcycles := ⟨⟨{ retraction := hS.desc (CokernelCofork.ofπ S.pOpcycles S.f_pOpcycles) id := by rw [← cancel_epi S.pOpcycles, p_fromOpcycles_assoc, comp_id] exact Cofork.IsColimit.π_desc hS }⟩⟩ infer_instance variable {S} lemma Exact.mono_g (hS : S.Exact) (hf : S.f = 0) : Mono S.g := by have := hS.hasHomology have := hS.epi_toCycles have : S.iCycles = 0 := by rw [← cancel_epi S.toCycles, comp_zero, toCycles_i, hf] apply Preadditive.mono_of_cancel_zero intro A x₂ hx₂ rw [← S.liftCycles_i x₂ hx₂, this, comp_zero] lemma Exact.epi_f (hS : S.Exact) (hg : S.g = 0) : Epi S.f := by have := hS.hasHomology have := hS.mono_fromOpcycles have : S.pOpcycles = 0 := by rw [← cancel_mono S.fromOpcycles, zero_comp, p_fromOpcycles, hg] apply Preadditive.epi_of_cancel_zero intro A x₂ hx₂ rw [← S.p_descOpcycles x₂ hx₂, this, zero_comp] lemma Exact.mono_g_iff (hS : S.Exact) : Mono S.g ↔ S.f = 0 := by constructor · intro rw [← cancel_mono S.g, zero, zero_comp] · exact hS.mono_g lemma Exact.epi_f_iff (hS : S.Exact) : Epi S.f ↔ S.g = 0 := by constructor · intro rw [← cancel_epi S.f, zero, comp_zero] · exact hS.epi_f lemma Exact.isZero_X₂ (hS : S.Exact) (hf : S.f = 0) (hg : S.g = 0) : IsZero S.X₂ := by have := hS.mono_g hf rw [IsZero.iff_id_eq_zero, ← cancel_mono S.g, hg, comp_zero, comp_zero] lemma Exact.isZero_X₂_iff (hS : S.Exact) : IsZero S.X₂ ↔ S.f = 0 ∧ S.g = 0 := by constructor · intro h exact ⟨h.eq_of_tgt _ _, h.eq_of_src _ _⟩ · rintro ⟨hf, hg⟩ exact hS.isZero_X₂ hf hg variable (S) /-- A splitting for a short complex `S` consists of the data of a retraction `r : X₂ ⟶ X₁` of `S.f` and section `s : X₃ ⟶ X₂` of `S.g` which satisfy `r ≫ S.f + S.g ≫ s = 𝟙 _` -/ structure Splitting (S : ShortComplex C) where /-- a retraction of `S.f` -/ r : S.X₂ ⟶ S.X₁ /-- a section of `S.g` -/ s : S.X₃ ⟶ S.X₂ /-- the condition that `r` is a retraction of `S.f` -/ f_r : S.f ≫ r = 𝟙 _ := by cat_disch /-- the condition that `s` is a section of `S.g` -/ s_g : s ≫ S.g = 𝟙 _ := by cat_disch /-- the compatibility between the given section and retraction -/ id : r ≫ S.f + S.g ≫ s = 𝟙 _ := by cat_disch namespace Splitting attribute [reassoc (attr := simp)] f_r s_g variable {S} @[reassoc] lemma r_f (s : S.Splitting) : s.r ≫ S.f = 𝟙 _ - S.g ≫ s.s := by rw [← s.id, add_sub_cancel_right] @[reassoc] lemma g_s (s : S.Splitting) : S.g ≫ s.s = 𝟙 _ - s.r ≫ S.f := by rw [← s.id, add_sub_cancel_left] /-- Given a splitting of a short complex `S`, this shows that `S.f` is a split monomorphism. -/ @[simps] def splitMono_f (s : S.Splitting) : SplitMono S.f := ⟨s.r, s.f_r⟩ lemma isSplitMono_f (s : S.Splitting) : IsSplitMono S.f := ⟨⟨s.splitMono_f⟩⟩ lemma mono_f (s : S.Splitting) : Mono S.f := by have := s.isSplitMono_f infer_instance /-- Given a splitting of a short complex `S`, this shows that `S.g` is a split epimorphism. -/ @[simps] def splitEpi_g (s : S.Splitting) : SplitEpi S.g := ⟨s.s, s.s_g⟩ lemma isSplitEpi_g (s : S.Splitting) : IsSplitEpi S.g := ⟨⟨s.splitEpi_g⟩⟩ lemma epi_g (s : S.Splitting) : Epi S.g := by have := s.isSplitEpi_g infer_instance @[reassoc (attr := simp)] lemma s_r (s : S.Splitting) : s.s ≫ s.r = 0 := by have := s.epi_g simp only [← cancel_epi S.g, comp_zero, g_s_assoc, sub_comp, id_comp, assoc, f_r, comp_id, sub_self] lemma ext_r (s s' : S.Splitting) (h : s.r = s'.r) : s = s' := by have := s.epi_g have eq := s.id rw [← s'.id, h, add_right_inj, cancel_epi S.g] at eq cases s congr lemma ext_s (s s' : S.Splitting) (h : s.s = s'.s) : s = s' := by have := s.mono_f have eq := s.id rw [← s'.id, h, add_left_inj, cancel_mono S.f] at eq cases s congr /-- The left homology data on a short complex equipped with a splitting. -/ @[simps] noncomputable def leftHomologyData [HasZeroObject C] (s : S.Splitting) : LeftHomologyData S := by have hi := KernelFork.IsLimit.ofι S.f S.zero (fun x _ => x ≫ s.r) (fun x hx => by simp only [assoc, s.r_f, comp_sub, comp_id, sub_eq_self, reassoc_of% hx, zero_comp]) (fun x _ b hb => by simp only [← hb, assoc, f_r, comp_id]) let f' := hi.lift (KernelFork.ofι S.f S.zero) have hf' : f' = 𝟙 _ := by simp [f'] have wπ : f' ≫ (0 : S.X₁ ⟶ 0) = 0 := comp_zero have hπ : IsColimit (CokernelCofork.ofπ 0 wπ) := CokernelCofork.IsColimit.ofEpiOfIsZero _ (by rw [hf']; infer_instance) (isZero_zero _) exact { K := S.X₁ H := 0 i := S.f wi := S.zero hi := hi π := 0 wπ := wπ hπ := hπ } /-- The right homology data on a short complex equipped with a splitting. -/ @[simps] noncomputable def rightHomologyData [HasZeroObject C] (s : S.Splitting) : RightHomologyData S := by have hp := CokernelCofork.IsColimit.ofπ S.g S.zero (fun x _ => s.s ≫ x) (fun x hx => by simp only [s.g_s_assoc, sub_comp, id_comp, sub_eq_self, assoc, hx, comp_zero]) (fun x _ b hb => by simp only [← hb, s.s_g_assoc]) let g' := hp.desc (CokernelCofork.ofπ S.g S.zero) have hg' : g' = 𝟙 _ := by apply Cofork.IsColimit.hom_ext hp dsimp erw [Cofork.IsColimit.π_desc hp] simp only [Cofork.π_ofπ, comp_id] have wι : (0 : 0 ⟶ S.X₃) ≫ g' = 0 := zero_comp have hι : IsLimit (KernelFork.ofι 0 wι) := KernelFork.IsLimit.ofMonoOfIsZero _ (by rw [hg']; dsimp; infer_instance) (isZero_zero _) exact { Q := S.X₃ H := 0 p := S.g wp := S.zero hp := hp ι := 0 wι := wι hι := hι } /-- The homology data on a short complex equipped with a splitting. -/ @[simps] noncomputable def homologyData [HasZeroObject C] (s : S.Splitting) : S.HomologyData where left := s.leftHomologyData right := s.rightHomologyData iso := Iso.refl 0 /-- A short complex equipped with a splitting is exact. -/ lemma exact [HasZeroObject C] (s : S.Splitting) : S.Exact := ⟨s.homologyData, isZero_zero _⟩ /-- If a short complex `S` is equipped with a splitting, then `S.X₁` is the kernel of `S.g`. -/ noncomputable def fIsKernel [HasZeroObject C] (s : S.Splitting) : IsLimit (KernelFork.ofι S.f S.zero) := s.homologyData.left.hi /-- If a short complex `S` is equipped with a splitting, then `S.X₃` is the cokernel of `S.f`. -/ noncomputable def gIsCokernel [HasZeroObject C] (s : S.Splitting) : IsColimit (CokernelCofork.ofπ S.g S.zero) := s.homologyData.right.hp /-- If a short complex `S` has a splitting and `F` is an additive functor, then `S.map F` also has a splitting. -/ @[simps] def map (s : S.Splitting) (F : C ⥤ D) [F.Additive] : (S.map F).Splitting where r := F.map s.r s := F.map s.s f_r := by dsimp [ShortComplex.map] rw [← F.map_comp, f_r, F.map_id] s_g := by dsimp [ShortComplex.map] simp only [← F.map_comp, s_g, F.map_id] id := by dsimp [ShortComplex.map] simp only [← F.map_id, ← s.id, Functor.map_comp, Functor.map_add] /-- A splitting on a short complex induces splittings on isomorphic short complexes. -/ @[simps] def ofIso {S₁ S₂ : ShortComplex C} (s : S₁.Splitting) (e : S₁ ≅ S₂) : S₂.Splitting where r := e.inv.τ₂ ≫ s.r ≫ e.hom.τ₁ s := e.inv.τ₃ ≫ s.s ≫ e.hom.τ₂ f_r := by rw [← e.inv.comm₁₂_assoc, s.f_r_assoc, ← comp_τ₁, e.inv_hom_id, id_τ₁] s_g := by rw [assoc, assoc, e.hom.comm₂₃, s.s_g_assoc, ← comp_τ₃, e.inv_hom_id, id_τ₃] id := by have eq := e.inv.τ₂ ≫= s.id =≫ e.hom.τ₂ rw [id_comp, ← comp_τ₂, e.inv_hom_id, id_τ₂] at eq rw [← eq, assoc, assoc, add_comp, assoc, assoc, comp_add, e.hom.comm₁₂, e.inv.comm₂₃_assoc] /-- The obvious splitting of the short complex `X₁ ⟶ X₁ ⊞ X₂ ⟶ X₂`. -/ noncomputable def ofHasBinaryBiproduct (X₁ X₂ : C) [HasBinaryBiproduct X₁ X₂] : Splitting (ShortComplex.mk (biprod.inl : X₁ ⟶ _) (biprod.snd : _ ⟶ X₂) (by simp)) where r := biprod.fst s := biprod.inr variable (S) /-- The obvious splitting of a short complex when `S.X₁` is zero and `S.g` is an isomorphism. -/ noncomputable def ofIsZeroOfIsIso (hf : IsZero S.X₁) (hg : IsIso S.g) : Splitting S where r := 0 s := inv S.g f_r := hf.eq_of_src _ _ /-- The obvious splitting of a short complex when `S.f` is an isomorphism and `S.X₃` is zero. -/ noncomputable def ofIsIsoOfIsZero (hf : IsIso S.f) (hg : IsZero S.X₃) : Splitting S where r := inv S.f s := 0 s_g := hg.eq_of_src _ _ variable {S} /-- The splitting of the short complex `S.op` deduced from a splitting of `S`. -/ @[simps] def op (h : Splitting S) : Splitting S.op where r := h.s.op s := h.r.op f_r := Quiver.Hom.unop_inj (by simp) s_g := Quiver.Hom.unop_inj (by simp) id := Quiver.Hom.unop_inj (by simp only [op_X₂, Opposite.unop_op, op_X₁, op_f, op_X₃, op_g, unop_add, unop_comp, Quiver.Hom.unop_op, unop_id, ← h.id] abel) /-- The splitting of the short complex `S.unop` deduced from a splitting of `S`. -/ @[simps] def unop {S : ShortComplex Cᵒᵖ} (h : Splitting S) : Splitting S.unop where r := h.s.unop s := h.r.unop f_r := Quiver.Hom.op_inj (by simp) s_g := Quiver.Hom.op_inj (by simp) id := Quiver.Hom.op_inj (by simp only [unop_X₂, Opposite.op_unop, unop_X₁, unop_f, unop_X₃, unop_g, op_add, op_comp, Quiver.Hom.op_unop, op_id, ← h.id] abel) /-- The isomorphism `S.X₂ ≅ S.X₁ ⊞ S.X₃` induced by a splitting of the short complex `S`. -/ @[simps] noncomputable def isoBinaryBiproduct (h : Splitting S) [HasBinaryBiproduct S.X₁ S.X₃] : S.X₂ ≅ S.X₁ ⊞ S.X₃ where hom := biprod.lift h.r S.g inv := biprod.desc S.f h.s hom_inv_id := by simp [h.id] end Splitting section Balanced variable {S} variable [Balanced C] namespace Exact lemma isIso_f' (hS : S.Exact) (h : S.LeftHomologyData) [Mono S.f] : IsIso h.f' := by have := hS.epi_f' h have := mono_of_mono_fac h.f'_i exact isIso_of_mono_of_epi h.f' lemma isIso_toCycles (hS : S.Exact) [Mono S.f] [S.HasLeftHomology] : IsIso S.toCycles := hS.isIso_f' _ lemma isIso_g' (hS : S.Exact) (h : S.RightHomologyData) [Epi S.g] : IsIso h.g' := by have := hS.mono_g' h have := epi_of_epi_fac h.p_g' exact isIso_of_mono_of_epi h.g' lemma isIso_fromOpcycles (hS : S.Exact) [Epi S.g] [S.HasRightHomology] : IsIso S.fromOpcycles := hS.isIso_g' _ /-- In a balanced category, if a short complex `S` is exact and `S.f` is a mono, then `S.X₁` is the kernel of `S.g`. -/ noncomputable def fIsKernel (hS : S.Exact) [Mono S.f] : IsLimit (KernelFork.ofι S.f S.zero) := by have := hS.hasHomology have := hS.isIso_toCycles exact IsLimit.ofIsoLimit S.cyclesIsKernel (Fork.ext (asIso S.toCycles).symm (by simp)) lemma map_of_mono_of_preservesKernel (hS : S.Exact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [(S.map F).HasHomology] (_ : Mono S.f) (_ : PreservesLimit (parallelPair S.g 0) F) : (S.map F).Exact := exact_of_f_is_kernel _ (KernelFork.mapIsLimit _ hS.fIsKernel F) /-- In a balanced category, if a short complex `S` is exact and `S.g` is an epi, then `S.X₃` is the cokernel of `S.g`. -/ noncomputable def gIsCokernel (hS : S.Exact) [Epi S.g] : IsColimit (CokernelCofork.ofπ S.g S.zero) := by have := hS.hasHomology have := hS.isIso_fromOpcycles exact IsColimit.ofIsoColimit S.opcyclesIsCokernel (Cofork.ext (asIso S.fromOpcycles) (by simp)) lemma map_of_epi_of_preservesCokernel (hS : S.Exact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [(S.map F).HasHomology] (_ : Epi S.g) (_ : PreservesColimit (parallelPair S.f 0) F) : (S.map F).Exact := exact_of_g_is_cokernel _ (CokernelCofork.mapIsColimit _ hS.gIsCokernel F) /-- If a short complex `S` in a balanced category is exact and such that `S.f` is a mono, then a morphism `k : A ⟶ S.X₂` such that `k ≫ S.g = 0` lifts to a morphism `A ⟶ S.X₁`. -/ noncomputable def lift (hS : S.Exact) {A : C} (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) [Mono S.f] : A ⟶ S.X₁ := hS.fIsKernel.lift (KernelFork.ofι k hk) @[reassoc (attr := simp)] lemma lift_f (hS : S.Exact) {A : C} (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) [Mono S.f] : hS.lift k hk ≫ S.f = k := Fork.IsLimit.lift_ι _ lemma lift' (hS : S.Exact) {A : C} (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) [Mono S.f] : ∃ (l : A ⟶ S.X₁), l ≫ S.f = k := ⟨hS.lift k hk, by simp⟩ /-- If a short complex `S` in a balanced category is exact and such that `S.g` is an epi, then a morphism `k : S.X₂ ⟶ A` such that `S.f ≫ k = 0` descends to a morphism `S.X₃ ⟶ A`. -/ noncomputable def desc (hS : S.Exact) {A : C} (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) [Epi S.g] : S.X₃ ⟶ A := hS.gIsCokernel.desc (CokernelCofork.ofπ k hk) @[reassoc (attr := simp)] lemma g_desc (hS : S.Exact) {A : C} (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) [Epi S.g] : S.g ≫ hS.desc k hk = k := Cofork.IsColimit.π_desc (hS.gIsCokernel) lemma desc' (hS : S.Exact) {A : C} (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) [Epi S.g] : ∃ (l : S.X₃ ⟶ A), S.g ≫ l = k := ⟨hS.desc k hk, by simp⟩ end Exact lemma mono_τ₂_of_exact_of_mono {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) (h₁ : S₁.Exact) [Mono S₁.f] [Mono S₂.f] [Mono φ.τ₁] [Mono φ.τ₃] : Mono φ.τ₂ := by rw [mono_iff_cancel_zero] intro A x₂ hx₂ obtain ⟨x₁, hx₁⟩ : ∃ x₁, x₁ ≫ S₁.f = x₂ := ⟨_, h₁.lift_f x₂ (by simp only [← cancel_mono φ.τ₃, assoc, zero_comp, ← φ.comm₂₃, reassoc_of% hx₂])⟩ suffices x₁ = 0 by rw [← hx₁, this, zero_comp] simp only [← cancel_mono φ.τ₁, ← cancel_mono S₂.f, assoc, φ.comm₁₂, zero_comp, reassoc_of% hx₁, hx₂] attribute [local instance] balanced_opposite lemma epi_τ₂_of_exact_of_epi {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) (h₂ : S₂.Exact) [Epi S₁.g] [Epi S₂.g] [Epi φ.τ₁] [Epi φ.τ₃] : Epi φ.τ₂ := by have : Mono S₁.op.f := by dsimp; infer_instance have : Mono S₂.op.f := by dsimp; infer_instance have : Mono (opMap φ).τ₁ := by dsimp; infer_instance have : Mono (opMap φ).τ₃ := by dsimp; infer_instance have := mono_τ₂_of_exact_of_mono (opMap φ) h₂.op exact unop_epi_of_mono (opMap φ).τ₂ variable (S) lemma exact_and_mono_f_iff_f_is_kernel [S.HasHomology] : S.Exact ∧ Mono S.f ↔ Nonempty (IsLimit (KernelFork.ofι S.f S.zero)) := by constructor · intro ⟨hS, _⟩ exact ⟨hS.fIsKernel⟩ · intro ⟨hS⟩ exact ⟨S.exact_of_f_is_kernel hS, mono_of_isLimit_fork hS⟩ lemma exact_and_epi_g_iff_g_is_cokernel [S.HasHomology] : S.Exact ∧ Epi S.g ↔ Nonempty (IsColimit (CokernelCofork.ofπ S.g S.zero)) := by constructor · intro ⟨hS, _⟩ exact ⟨hS.gIsCokernel⟩ · intro ⟨hS⟩ exact ⟨S.exact_of_g_is_cokernel hS, epi_of_isColimit_cofork hS⟩ end Balanced end Preadditive section Abelian variable [Abelian C] /-- Given a morphism of short complexes `φ : S₁ ⟶ S₂` in an abelian category, if `S₁.f` and `S₁.g` are zero (e.g. when `S₁` is of the form `0 ⟶ S₁.X₂ ⟶ 0`) and `S₂.f = 0` (e.g when `S₂` is of the form `0 ⟶ S₂.X₂ ⟶ S₂.X₃`), then `φ` is a quasi-isomorphism iff the obvious short complex `S₁.X₂ ⟶ S₂.X₂ ⟶ S₂.X₃` is exact and `φ.τ₂` is a mono). -/ lemma quasiIso_iff_of_zeros {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) : QuasiIso φ ↔ (ShortComplex.mk φ.τ₂ S₂.g (by rw [φ.comm₂₃, hg₁, zero_comp])).Exact ∧ Mono φ.τ₂ := by have w : φ.τ₂ ≫ S₂.g = 0 := by rw [φ.comm₂₃, hg₁, zero_comp] rw [quasiIso_iff_isIso_liftCycles φ hf₁ hg₁ hf₂] constructor · intro h have : Mono φ.τ₂ := by rw [← S₂.liftCycles_i φ.τ₂ w] apply mono_comp refine ⟨?_, this⟩ apply exact_of_f_is_kernel exact IsLimit.ofIsoLimit S₂.cyclesIsKernel (Fork.ext (asIso (S₂.liftCycles φ.τ₂ w)).symm (by simp)) · rintro ⟨h₁, h₂⟩ refine ⟨⟨h₁.lift S₂.iCycles (by simp), ?_, ?_⟩⟩ · rw [← cancel_mono φ.τ₂, assoc, h₁.lift_f, liftCycles_i, id_comp] · rw [← cancel_mono S₂.iCycles, assoc, liftCycles_i, h₁.lift_f, id_comp] /-- Given a morphism of short complexes `φ : S₁ ⟶ S₂` in an abelian category, if `S₁.g = 0` (e.g when `S₁` is of the form `S₁.X₁ ⟶ S₁.X₂ ⟶ 0`) and both `S₂.f` and `S₂.g` are zero (e.g when `S₂` is of the form `0 ⟶ S₂.X₂ ⟶ 0`), then `φ` is a quasi-isomorphism iff the obvious short complex `S₁.X₂ ⟶ S₁.X₂ ⟶ S₂.X₂` is exact and `φ.τ₂` is an epi). -/ lemma quasiIso_iff_of_zeros' {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) (hg₂ : S₂.g = 0) : QuasiIso φ ↔ (ShortComplex.mk S₁.f φ.τ₂ (by rw [← φ.comm₁₂, hf₂, comp_zero])).Exact ∧ Epi φ.τ₂ := by rw [← quasiIso_opMap_iff, quasiIso_iff_of_zeros] rotate_left · dsimp rw [hg₂, op_zero] · dsimp rw [hf₂, op_zero] · dsimp rw [hg₁, op_zero] rw [← exact_unop_iff] have : Mono φ.τ₂.op ↔ Epi φ.τ₂ := ⟨fun _ => unop_epi_of_mono φ.τ₂.op, fun _ => op_mono_of_epi _⟩ tauto variable {S : ShortComplex C} /-- If `S` is an exact short complex and `f : S.X₂ ⟶ J` is a morphism to an injective object `J` such that `S.f ≫ f = 0`, this is a morphism `φ : S.X₃ ⟶ J` such that `S.g ≫ φ = f`. -/ noncomputable def Exact.descToInjective (hS : S.Exact) {J : C} (f : S.X₂ ⟶ J) [Injective J] (hf : S.f ≫ f = 0) : S.X₃ ⟶ J := by have := hS.mono_fromOpcycles exact Injective.factorThru (S.descOpcycles f hf) S.fromOpcycles @[reassoc (attr := simp, nolint unusedHavesSuffices)] lemma Exact.comp_descToInjective (hS : S.Exact) {J : C} (f : S.X₂ ⟶ J) [Injective J] (hf : S.f ≫ f = 0) : S.g ≫ hS.descToInjective f hf = f := by dsimp [descToInjective] simp only [← p_fromOpcycles, assoc, Injective.comp_factorThru, p_descOpcycles] /-- If `S` is an exact short complex and `f : P ⟶ S.X₂` is a morphism from a projective object `P` such that `f ≫ S.g = 0`, this is a morphism `φ : P ⟶ S.X₁` such that `φ ≫ S.f = f`. -/ noncomputable def Exact.liftFromProjective (hS : S.Exact) {P : C} (f : P ⟶ S.X₂) [Projective P] (hf : f ≫ S.g = 0) : P ⟶ S.X₁ := by have := hS.epi_toCycles exact Projective.factorThru (S.liftCycles f hf) S.toCycles @[reassoc (attr := simp, nolint unusedHavesSuffices)] lemma Exact.liftFromProjective_comp (hS : S.Exact) {P : C} (f : P ⟶ S.X₂) [Projective P] (hf : f ≫ S.g = 0) : hS.liftFromProjective f hf ≫ S.f = f := by dsimp [liftFromProjective] rw [← toCycles_i, Projective.factorThru_comp_assoc, liftCycles_i] end Abelian end ShortComplex namespace Functor variable (F : C ⥤ D) [Preadditive C] [Preadditive D] [HasZeroObject C] [HasZeroObject D] [F.PreservesZeroMorphisms] [F.PreservesHomology] instance : F.PreservesMonomorphisms where preserves {X Y} f hf := by let S := ShortComplex.mk (0 : X ⟶ X) f zero_comp exact ((S.map F).exact_iff_mono (by simp [S])).1 (((S.exact_iff_mono rfl).2 hf).map F) instance : F.PreservesEpimorphisms where preserves {X Y} f hf := by let S := ShortComplex.mk f (0 : Y ⟶ Y) comp_zero exact ((S.map F).exact_iff_epi (by simp [S])).1 (((S.exact_iff_epi rfl).2 hf).map F) end Functor namespace ShortComplex namespace Splitting variable [Preadditive C] [Balanced C] /-- This is the splitting of a short complex `S` in a balanced category induced by a section of the morphism `S.g : S.X₂ ⟶ S.X₃` -/ noncomputable def ofExactOfSection (S : ShortComplex C) (hS : S.Exact) (s : S.X₃ ⟶ S.X₂) (s_g : s ≫ S.g = 𝟙 S.X₃) (hf : Mono S.f) : S.Splitting where r := hS.lift (𝟙 S.X₂ - S.g ≫ s) (by simp [s_g]) s := s f_r := by rw [← cancel_mono S.f, assoc, Exact.lift_f, comp_sub, comp_id, zero_assoc, zero_comp, sub_zero, id_comp] s_g := s_g /-- This is the splitting of a short complex `S` in a balanced category induced by a retraction of the morphism `S.f : S.X₁ ⟶ S.X₂` -/ noncomputable def ofExactOfRetraction (S : ShortComplex C) (hS : S.Exact) (r : S.X₂ ⟶ S.X₁) (f_r : S.f ≫ r = 𝟙 S.X₁) (hg : Epi S.g) : S.Splitting where r := r s := hS.desc (𝟙 S.X₂ - r ≫ S.f) (by simp [reassoc_of% f_r]) f_r := f_r s_g := by rw [← cancel_epi S.g, Exact.g_desc_assoc, sub_comp, id_comp, assoc, zero, comp_zero, sub_zero, comp_id] end Splitting end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Ab.lean
import Mathlib.Algebra.Category.Grp.Abelian import Mathlib.Algebra.Category.Grp.Kernels import Mathlib.Algebra.Exact import Mathlib.Algebra.Homology.ShortComplex.ShortExact import Mathlib.GroupTheory.QuotientGroup.Finite /-! # Homology and exactness of short complexes of abelian groups In this file, the homology of a short complex `S` of abelian groups is identified with the quotient of `AddMonoidHom.ker S.g` by the image of the morphism `S.abToCycles : S.X₁ →+ AddMonoidHom.ker S.g` induced by `S.f`. The definitions are made in the `ShortComplex` namespace so as to enable dot notation. The names contain the prefix `ab` in order to allow similar constructions for other categories like `ModuleCat`. ## Main definitions - `ShortComplex.abHomologyIso` identifies the homology of a short complex of abelian groups to an explicit quotient. - `ShortComplex.ab_exact_iff` expresses that a short complex of abelian groups `S` is exact iff any element in the kernel of `S.g` belongs to the image of `S.f`. -/ universe u namespace CategoryTheory namespace ShortComplex variable (S : ShortComplex Ab.{u}) @[simp] lemma ab_zero_apply (x : S.X₁) : S.g (S.f x) = 0 := by rw [← ConcreteCategory.comp_apply, S.zero] rfl /-- The canonical additive morphism `S.X₁ →+ AddMonoidHom.ker S.g` induced by `S.f`. -/ @[simps!] def abToCycles : S.X₁ →+ AddMonoidHom.ker S.g.hom := AddMonoidHom.mk' (fun x => ⟨S.f x, S.ab_zero_apply x⟩) (by aesop) /-- The explicit left homology data of a short complex of abelian group that is given by a kernel and a quotient given by the `AddMonoidHom` API. -/ @[simps] def abLeftHomologyData : S.LeftHomologyData where K := AddCommGrpCat.of (AddMonoidHom.ker S.g.hom) H := AddCommGrpCat.of ((AddMonoidHom.ker S.g.hom) ⧸ AddMonoidHom.range S.abToCycles) i := AddCommGrpCat.ofHom <| (AddMonoidHom.ker S.g.hom).subtype π := AddCommGrpCat.ofHom <| QuotientAddGroup.mk' _ wi := by ext ⟨_, hx⟩ exact hx hi := AddCommGrpCat.kernelIsLimit _ wπ := by ext (x : S.X₁) dsimp rw [QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range] apply exists_apply_eq_apply hπ := AddCommGrpCat.cokernelIsColimit (AddCommGrpCat.ofHom S.abToCycles) @[simp] lemma abLeftHomologyData_f' : S.abLeftHomologyData.f' = AddCommGrpCat.ofHom S.abToCycles := rfl /-- Given a short complex `S` of abelian groups, this is the isomorphism between the abstract `S.cycles` of the homology API and the more concrete description as `AddMonoidHom.ker S.g`. -/ noncomputable def abCyclesIso : S.cycles ≅ AddCommGrpCat.of (AddMonoidHom.ker S.g.hom) := S.abLeftHomologyData.cyclesIso -- This was a simp lemma until we made `AddCommGrpCat.coe_of` a simp lemma, -- after which the simp normal form linter complains. -- It was not used a simp lemma in Mathlib. -- Possible solution: higher priority function coercions that remove the `of`? -- @[simp] lemma abCyclesIso_inv_apply_iCycles (x : AddMonoidHom.ker S.g.hom) : S.iCycles (S.abCyclesIso.inv x) = x := by dsimp only [abCyclesIso] rw [← ConcreteCategory.comp_apply, S.abLeftHomologyData.cyclesIso_inv_comp_iCycles] rfl /-- Given a short complex `S` of abelian groups, this is the isomorphism between the abstract `S.homology` of the homology API and the more explicit quotient of `AddMonoidHom.ker S.g` by the image of `S.abToCycles : S.X₁ →+ AddMonoidHom.ker S.g`. -/ noncomputable def abHomologyIso : S.homology ≅ AddCommGrpCat.of ((AddMonoidHom.ker S.g.hom) ⧸ AddMonoidHom.range S.abToCycles) := S.abLeftHomologyData.homologyIso lemma exact_iff_surjective_abToCycles : S.Exact ↔ Function.Surjective S.abToCycles := by rw [S.abLeftHomologyData.exact_iff_epi_f', abLeftHomologyData_f', AddCommGrpCat.epi_iff_surjective] rfl lemma ab_exact_iff : S.Exact ↔ ∀ (x₂ : S.X₂) (_ : S.g x₂ = 0), ∃ (x₁ : S.X₁), S.f x₁ = x₂ := by rw [exact_iff_surjective_abToCycles] constructor · intro h x₂ hx₂ obtain ⟨x₁, hx₁⟩ := h ⟨x₂, hx₂⟩ exact ⟨x₁, by simpa only [Subtype.ext_iff, abToCycles_apply_coe] using hx₁⟩ · rintro h ⟨x₂, hx₂⟩ obtain ⟨x₁, rfl⟩ := h x₂ hx₂ exact ⟨x₁, rfl⟩ lemma ab_exact_iff_function_exact : S.Exact ↔ Function.Exact S.f S.g := by rw [S.ab_exact_iff] apply forall_congr' intro x₂ constructor · intro h refine ⟨h, ?_⟩ rintro ⟨x₁, rfl⟩ simp only [ab_zero_apply] · tauto variable {S} lemma ab_exact_iff_ker_le_range : S.Exact ↔ S.g.hom.ker ≤ S.f.hom.range := S.ab_exact_iff lemma ab_exact_iff_range_eq_ker : S.Exact ↔ S.f.hom.range = S.g.hom.ker := by rw [ab_exact_iff_ker_le_range] constructor · intro h refine le_antisymm ?_ h rintro _ ⟨x₁, rfl⟩ rw [AddMonoidHom.mem_ker, ← ConcreteCategory.comp_apply, S.zero] rfl · intro h rw [h] alias ⟨Exact.ab_range_eq_ker, _⟩ := ab_exact_iff_range_eq_ker /-- In an exact sequence of abelian groups, if the first and last groups are finite, then so is the middle one. -/ lemma Exact.ab_finite {S : ShortComplex Ab.{u}} (hS : S.Exact) [Finite S.X₁] [Finite S.X₃] : Finite S.X₂ := by have : Finite S.f.hom.range := Set.finite_range _ have : Finite (S.X₂ ⧸ S.f.hom.range) := by rw [hS.ab_range_eq_ker] exact .of_equiv _ (QuotientAddGroup.quotientKerEquivRange _).toEquiv.symm exact .of_addSubgroup_quotient (H := S.f.hom.range) lemma ShortExact.ab_injective_f (hS : S.ShortExact) : Function.Injective S.f := (AddCommGrpCat.mono_iff_injective _).1 hS.mono_f lemma ShortExact.ab_surjective_g (hS : S.ShortExact) : Function.Surjective S.g := (AddCommGrpCat.epi_iff_surjective _).1 hS.epi_g /-- In a short exact sequence of abelian groups, the middle group is finite iff the first and last are. -/ lemma ShortExact.ab_finite_iff {S : ShortComplex Ab.{u}} (hS : S.ShortExact) : Finite S.X₂ ↔ Finite S.X₁ ∧ Finite S.X₃ where mp _ := ⟨.of_injective _ hS.ab_injective_f, .of_surjective _ hS.ab_surjective_g⟩ mpr | ⟨_, _⟩ => hS.exact.ab_finite @[deprecated (since := "2025-11-03")] protected alias ShortExact.ab_exact_iff_function_exact := ab_exact_iff_function_exact end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Limits.lean
import Mathlib.Algebra.Homology.ShortComplex.Basic import Mathlib.CategoryTheory.Limits.Constructions.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.Preserves.Finite /-! # Limits and colimits in the category of short complexes In this file, it is shown if a category `C` with zero morphisms has limits of a certain shape `J`, then it is also the case of the category `ShortComplex C`. -/ namespace CategoryTheory open Category Limits Functor variable {J C : Type*} [Category J] [Category C] [HasZeroMorphisms C] {F : J ⥤ ShortComplex C} namespace ShortComplex /-- If a cone with values in `ShortComplex C` is such that it becomes limit when we apply the three projections `ShortComplex C ⥤ C`, then it is limit. -/ def isLimitOfIsLimitπ (c : Cone F) (h₁ : IsLimit (π₁.mapCone c)) (h₂ : IsLimit (π₂.mapCone c)) (h₃ : IsLimit (π₃.mapCone c)) : IsLimit c where lift s := { τ₁ := h₁.lift (π₁.mapCone s) τ₂ := h₂.lift (π₂.mapCone s) τ₃ := h₃.lift (π₃.mapCone s) comm₁₂ := h₂.hom_ext (fun j => by have eq₁ := h₁.fac (π₁.mapCone s) have eq₂ := h₂.fac (π₂.mapCone s) have eq₁₂ := fun j => (c.π.app j).comm₁₂ have eq₁₂' := fun j => (s.π.app j).comm₁₂ dsimp at eq₁ eq₂ eq₁₂ eq₁₂' ⊢ rw [assoc, assoc, ← eq₁₂, reassoc_of% eq₁, eq₂, eq₁₂']) comm₂₃ := h₃.hom_ext (fun j => by have eq₂ := h₂.fac (π₂.mapCone s) have eq₃ := h₃.fac (π₃.mapCone s) have eq₂₃ := fun j => (c.π.app j).comm₂₃ have eq₂₃' := fun j => (s.π.app j).comm₂₃ dsimp at eq₂ eq₃ eq₂₃ eq₂₃' ⊢ rw [assoc, assoc, ← eq₂₃, reassoc_of% eq₂, eq₃, eq₂₃']) } fac s j := by ext <;> apply IsLimit.fac uniq s m hm := by ext · exact h₁.uniq (π₁.mapCone s) _ (fun j => π₁.congr_map (hm j)) · exact h₂.uniq (π₂.mapCone s) _ (fun j => π₂.congr_map (hm j)) · exact h₃.uniq (π₃.mapCone s) _ (fun j => π₃.congr_map (hm j)) section variable (F) variable [HasLimit (F ⋙ π₁)] [HasLimit (F ⋙ π₂)] [HasLimit (F ⋙ π₃)] /-- Construction of a limit cone for a functor `J ⥤ ShortComplex C` using the limits of the three components `J ⥤ C`. -/ noncomputable def limitCone : Cone F := Cone.mk (ShortComplex.mk (limMap (whiskerLeft F π₁Toπ₂)) (limMap (whiskerLeft F π₂Toπ₃)) (by cat_disch)) { app := fun j => Hom.mk (limit.π _ _) (limit.π _ _) (limit.π _ _) (by simp) (by simp) naturality := fun _ _ f => by ext <;> simp [← limit.w _ f] } /-- `limitCone F` becomes limit after the application of `π₁ : ShortComplex C ⥤ C`. -/ noncomputable def isLimitπ₁MapConeLimitCone : IsLimit (π₁.mapCone (limitCone F)) := (IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext (Iso.refl _) (by cat_disch))) /-- `limitCone F` becomes limit after the application of `π₂ : ShortComplex C ⥤ C`. -/ noncomputable def isLimitπ₂MapConeLimitCone : IsLimit (π₂.mapCone (limitCone F)) := (IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext (Iso.refl _) (by cat_disch))) /-- `limitCone F` becomes limit after the application of `π₃ : ShortComplex C ⥤ C`. -/ noncomputable def isLimitπ₃MapConeLimitCone : IsLimit (π₃.mapCone (limitCone F)) := (IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext (Iso.refl _) (by cat_disch))) /-- `limitCone F` is limit. -/ noncomputable def isLimitLimitCone : IsLimit (limitCone F) := isLimitOfIsLimitπ _ (isLimitπ₁MapConeLimitCone F) (isLimitπ₂MapConeLimitCone F) (isLimitπ₃MapConeLimitCone F) instance hasLimit_of_hasLimitπ : HasLimit F := ⟨⟨⟨_, isLimitLimitCone _⟩⟩⟩ noncomputable instance : PreservesLimit F π₁ := preservesLimit_of_preserves_limit_cone (isLimitLimitCone F) (isLimitπ₁MapConeLimitCone F) noncomputable instance : PreservesLimit F π₂ := preservesLimit_of_preserves_limit_cone (isLimitLimitCone F) (isLimitπ₂MapConeLimitCone F) noncomputable instance : PreservesLimit F π₃ := preservesLimit_of_preserves_limit_cone (isLimitLimitCone F) (isLimitπ₃MapConeLimitCone F) end section variable [HasLimitsOfShape J C] instance hasLimitsOfShape : HasLimitsOfShape J (ShortComplex C) where noncomputable instance : PreservesLimitsOfShape J (π₁ : _ ⥤ C) where noncomputable instance : PreservesLimitsOfShape J (π₂ : _ ⥤ C) where noncomputable instance : PreservesLimitsOfShape J (π₃ : _ ⥤ C) where end section variable [HasFiniteLimits C] instance hasFiniteLimits : HasFiniteLimits (ShortComplex C) := ⟨fun _ _ _ => inferInstance⟩ noncomputable instance : PreservesFiniteLimits (π₁ : _ ⥤ C) := ⟨fun _ _ _ => inferInstance⟩ noncomputable instance : PreservesFiniteLimits (π₂ : _ ⥤ C) := ⟨fun _ _ _ => inferInstance⟩ noncomputable instance : PreservesFiniteLimits (π₃ : _ ⥤ C) := ⟨fun _ _ _ => inferInstance⟩ end section variable [HasLimitsOfShape WalkingCospan C] instance preservesMonomorphisms_π₁ : Functor.PreservesMonomorphisms (π₁ : _ ⥤ C) := CategoryTheory.preservesMonomorphisms_of_preservesLimitsOfShape _ instance preservesMonomorphisms_π₂ : Functor.PreservesMonomorphisms (π₂ : _ ⥤ C) := CategoryTheory.preservesMonomorphisms_of_preservesLimitsOfShape _ instance preservesMonomorphisms_π₃ : Functor.PreservesMonomorphisms (π₃ : _ ⥤ C) := CategoryTheory.preservesMonomorphisms_of_preservesLimitsOfShape _ end /-- If a cocone with values in `ShortComplex C` is such that it becomes colimit when we apply the three projections `ShortComplex C ⥤ C`, then it is colimit. -/ def isColimitOfIsColimitπ (c : Cocone F) (h₁ : IsColimit (π₁.mapCocone c)) (h₂ : IsColimit (π₂.mapCocone c)) (h₃ : IsColimit (π₃.mapCocone c)) : IsColimit c where desc s := { τ₁ := h₁.desc (π₁.mapCocone s) τ₂ := h₂.desc (π₂.mapCocone s) τ₃ := h₃.desc (π₃.mapCocone s) comm₁₂ := h₁.hom_ext (fun j => by have eq₁ := h₁.fac (π₁.mapCocone s) have eq₂ := h₂.fac (π₂.mapCocone s) have eq₁₂ := fun j => (c.ι.app j).comm₁₂ have eq₁₂' := fun j => (s.ι.app j).comm₁₂ dsimp at eq₁ eq₂ eq₁₂ eq₁₂' ⊢ rw [reassoc_of% (eq₁ j), eq₁₂', reassoc_of% eq₁₂, eq₂]) comm₂₃ := h₂.hom_ext (fun j => by have eq₂ := h₂.fac (π₂.mapCocone s) have eq₃ := h₃.fac (π₃.mapCocone s) have eq₂₃ := fun j => (c.ι.app j).comm₂₃ have eq₂₃' := fun j => (s.ι.app j).comm₂₃ dsimp at eq₂ eq₃ eq₂₃ eq₂₃' ⊢ rw [reassoc_of% (eq₂ j), eq₂₃', reassoc_of% eq₂₃, eq₃]) } fac s j := by ext · apply IsColimit.fac h₁ · apply IsColimit.fac h₂ · apply IsColimit.fac h₃ uniq s m hm := by ext · exact h₁.uniq (π₁.mapCocone s) _ (fun j => π₁.congr_map (hm j)) · exact h₂.uniq (π₂.mapCocone s) _ (fun j => π₂.congr_map (hm j)) · exact h₃.uniq (π₃.mapCocone s) _ (fun j => π₃.congr_map (hm j)) section variable (F) variable [HasColimit (F ⋙ π₁)] [HasColimit (F ⋙ π₂)] [HasColimit (F ⋙ π₃)] /-- Construction of a colimit cocone for a functor `J ⥤ ShortComplex C` using the colimits of the three components `J ⥤ C`. -/ noncomputable def colimitCocone : Cocone F := Cocone.mk (ShortComplex.mk (colimMap (whiskerLeft F π₁Toπ₂)) (colimMap (whiskerLeft F π₂Toπ₃)) (by cat_disch)) { app := fun j => Hom.mk (colimit.ι (F ⋙ π₁) _) (colimit.ι (F ⋙ π₂) _) (colimit.ι (F ⋙ π₃) _) (by simp) (by simp) naturality := fun _ _ f => by ext · simp [← colimit.w (F ⋙ π₁) f] · simp [← colimit.w (F ⋙ π₂) f] · simp [← colimit.w (F ⋙ π₃) f] } /-- `colimitCocone F` becomes colimit after the application of `π₁ : ShortComplex C ⥤ C`. -/ noncomputable def isColimitπ₁MapCoconeColimitCocone : IsColimit (π₁.mapCocone (colimitCocone F)) := (IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (Iso.refl _) (by cat_disch))) /-- `colimitCocone F` becomes colimit after the application of `π₂ : ShortComplex C ⥤ C`. -/ noncomputable def isColimitπ₂MapCoconeColimitCocone : IsColimit (π₂.mapCocone (colimitCocone F)) := (IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (Iso.refl _) (by cat_disch))) /-- `colimitCocone F` becomes colimit after the application of `π₃ : ShortComplex C ⥤ C`. -/ noncomputable def isColimitπ₃MapCoconeColimitCocone : IsColimit (π₃.mapCocone (colimitCocone F)) := (IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (Iso.refl _) (by cat_disch))) /-- `colimitCocone F` is colimit. -/ noncomputable def isColimitColimitCocone : IsColimit (colimitCocone F) := isColimitOfIsColimitπ _ (isColimitπ₁MapCoconeColimitCocone F) (isColimitπ₂MapCoconeColimitCocone F) (isColimitπ₃MapCoconeColimitCocone F) instance hasColimit_of_hasColimitπ : HasColimit F := ⟨⟨⟨_, isColimitColimitCocone _⟩⟩⟩ noncomputable instance : PreservesColimit F π₁ := preservesColimit_of_preserves_colimit_cocone (isColimitColimitCocone F) (isColimitπ₁MapCoconeColimitCocone F) noncomputable instance : PreservesColimit F π₂ := preservesColimit_of_preserves_colimit_cocone (isColimitColimitCocone F) (isColimitπ₂MapCoconeColimitCocone F) noncomputable instance : PreservesColimit F π₃ := preservesColimit_of_preserves_colimit_cocone (isColimitColimitCocone F) (isColimitπ₃MapCoconeColimitCocone F) end section variable [HasColimitsOfShape J C] instance hasColimitsOfShape : HasColimitsOfShape J (ShortComplex C) where noncomputable instance : PreservesColimitsOfShape J (π₁ : _ ⥤ C) where noncomputable instance : PreservesColimitsOfShape J (π₂ : _ ⥤ C) where noncomputable instance : PreservesColimitsOfShape J (π₃ : _ ⥤ C) where end section variable [HasFiniteColimits C] instance hasFiniteColimits : HasFiniteColimits (ShortComplex C) := ⟨fun _ _ _ => inferInstance⟩ noncomputable instance : PreservesFiniteColimits (π₁ : _ ⥤ C) := ⟨fun _ _ _ => inferInstance⟩ noncomputable instance : PreservesFiniteColimits (π₂ : _ ⥤ C) := ⟨fun _ _ _ => inferInstance⟩ noncomputable instance : PreservesFiniteColimits (π₃ : _ ⥤ C) := ⟨fun _ _ _ => inferInstance⟩ end section variable [HasColimitsOfShape WalkingSpan C] instance preservesEpimorphisms_π₁ : Functor.PreservesEpimorphisms (π₁ : _ ⥤ C) := CategoryTheory.preservesEpimorphisms_of_preservesColimitsOfShape _ instance preservesEpimorphisms_π₂ : Functor.PreservesEpimorphisms (π₂ : _ ⥤ C) := CategoryTheory.preservesEpimorphisms_of_preservesColimitsOfShape _ instance preservesEpimorphisms_π₃ : Functor.PreservesEpimorphisms (π₃ : _ ⥤ C) := CategoryTheory.preservesEpimorphisms_of_preservesColimitsOfShape _ end end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/Homology.lean
import Mathlib.Algebra.Homology.ShortComplex.RightHomology /-! # Homology of short complexes In this file, we shall define the homology of short complexes `S`, i.e. diagrams `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` such that `f ≫ g = 0`. We shall say that `[S.HasHomology]` when there exists `h : S.HomologyData`. A homology data for `S` consists of compatible left/right homology data `left` and `right`. The left homology data `left` involves an object `left.H` that is a cokernel of the canonical map `S.X₁ ⟶ K` where `K` is a kernel of `g`. On the other hand, the dual notion `right.H` is a kernel of the canonical morphism `Q ⟶ S.X₃` when `Q` is a cokernel of `f`. The compatibility that is required involves an isomorphism `left.H ≅ right.H` which makes a certain pentagon commute. When such a homology data exists, `S.homology` shall be defined as `h.left.H` for a chosen `h : S.HomologyData`. This definition requires very little assumption on the category (only the existence of zero morphisms). We shall prove that in abelian categories, all short complexes have homology data. Note: This definition arose by the end of the Liquid Tensor Experiment which contained a structure `has_homology` which is quite similar to `S.HomologyData`. After the category `ShortComplex C` was introduced by J. Riou, A. Topaz suggested such a structure could be used as a basis for the *definition* of homology. -/ universe v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] (S : ShortComplex C) {S₁ S₂ S₃ S₄ : ShortComplex C} namespace ShortComplex /-- A homology data for a short complex consists of two compatible left and right homology data -/ structure HomologyData where /-- a left homology data -/ left : S.LeftHomologyData /-- a right homology data -/ right : S.RightHomologyData /-- the compatibility isomorphism relating the two dual notions of `LeftHomologyData` and `RightHomologyData` -/ iso : left.H ≅ right.H /-- the pentagon relation expressing the compatibility of the left and right homology data -/ comm : left.π ≫ iso.hom ≫ right.ι = left.i ≫ right.p := by cat_disch attribute [reassoc (attr := simp)] HomologyData.comm variable (φ : S₁ ⟶ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) /-- A homology map data for a morphism `φ : S₁ ⟶ S₂` where both `S₁` and `S₂` are equipped with homology data consists of left and right homology map data. -/ structure HomologyMapData where /-- a left homology map data -/ left : LeftHomologyMapData φ h₁.left h₂.left /-- a right homology map data -/ right : RightHomologyMapData φ h₁.right h₂.right namespace HomologyMapData variable {φ h₁ h₂} @[reassoc] lemma comm (h : HomologyMapData φ h₁ h₂) : h.left.φH ≫ h₂.iso.hom = h₁.iso.hom ≫ h.right.φH := by simp only [← cancel_epi h₁.left.π, ← cancel_mono h₂.right.ι, assoc, LeftHomologyMapData.commπ_assoc, HomologyData.comm, LeftHomologyMapData.commi_assoc, RightHomologyMapData.commι, HomologyData.comm_assoc, RightHomologyMapData.commp] instance : Subsingleton (HomologyMapData φ h₁ h₂) := ⟨by rintro ⟨left₁, right₁⟩ ⟨left₂, right₂⟩ simp only [mk.injEq, eq_iff_true_of_subsingleton, and_self]⟩ instance : Inhabited (HomologyMapData φ h₁ h₂) := ⟨⟨default, default⟩⟩ instance : Unique (HomologyMapData φ h₁ h₂) := Unique.mk' _ variable (φ h₁ h₂) /-- A choice of the (unique) homology map data associated with a morphism `φ : S₁ ⟶ S₂` where both short complexes `S₁` and `S₂` are equipped with homology data. -/ def homologyMapData : HomologyMapData φ h₁ h₂ := default variable {φ h₁ h₂} lemma congr_left_φH {γ₁ γ₂ : HomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.left.φH = γ₂.left.φH := by rw [eq] end HomologyMapData namespace HomologyData /-- When the first map `S.f` is zero, this is the homology data on `S` given by any limit kernel fork of `S.g` -/ @[simps] def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : S.HomologyData where left := LeftHomologyData.ofIsLimitKernelFork S hf c hc right := RightHomologyData.ofIsLimitKernelFork S hf c hc iso := Iso.refl _ /-- When the first map `S.f` is zero, this is the homology data on `S` given by the chosen `kernel S.g` -/ @[simps] noncomputable def ofHasKernel (hf : S.f = 0) [HasKernel S.g] : S.HomologyData where left := LeftHomologyData.ofHasKernel S hf right := RightHomologyData.ofHasKernel S hf iso := Iso.refl _ /-- When the second map `S.g` is zero, this is the homology data on `S` given by any colimit cokernel cofork of `S.f` -/ @[simps] def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : S.HomologyData where left := LeftHomologyData.ofIsColimitCokernelCofork S hg c hc right := RightHomologyData.ofIsColimitCokernelCofork S hg c hc iso := Iso.refl _ /-- When the second map `S.g` is zero, this is the homology data on `S` given by the chosen `cokernel S.f` -/ @[simps] noncomputable def ofHasCokernel (hg : S.g = 0) [HasCokernel S.f] : S.HomologyData where left := LeftHomologyData.ofHasCokernel S hg right := RightHomologyData.ofHasCokernel S hg iso := Iso.refl _ /-- When both `S.f` and `S.g` are zero, the middle object `S.X₂` gives a homology data on S -/ @[simps] noncomputable def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.HomologyData where left := LeftHomologyData.ofZeros S hf hg right := RightHomologyData.ofZeros S hf hg iso := Iso.refl _ /-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso and `φ.τ₃` is mono, then a homology data for `S₁` induces a homology data for `S₂`. The inverse construction is `ofEpiOfIsIsoOfMono'`. -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : HomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HomologyData S₂ where left := LeftHomologyData.ofEpiOfIsIsoOfMono φ h.left right := RightHomologyData.ofEpiOfIsIsoOfMono φ h.right iso := h.iso /-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso and `φ.τ₃` is mono, then a homology data for `S₂` induces a homology data for `S₁`. The inverse construction is `ofEpiOfIsIsoOfMono`. -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : HomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HomologyData S₁ where left := LeftHomologyData.ofEpiOfIsIsoOfMono' φ h.left right := RightHomologyData.ofEpiOfIsIsoOfMono' φ h.right iso := h.iso /-- If `e : S₁ ≅ S₂` is an isomorphism of short complexes and `h₁ : HomologyData S₁`, this is the homology data for `S₂` deduced from the isomorphism. -/ @[simps!] noncomputable def ofIso (e : S₁ ≅ S₂) (h : HomologyData S₁) := h.ofEpiOfIsIsoOfMono e.hom variable {S} /-- A homology data for a short complex `S` induces a homology data for `S.op`. -/ @[simps] def op (h : S.HomologyData) : S.op.HomologyData where left := h.right.op right := h.left.op iso := h.iso.op comm := Quiver.Hom.unop_inj (by simp) /-- A homology data for a short complex `S` in the opposite category induces a homology data for `S.unop`. -/ @[simps] def unop {S : ShortComplex Cᵒᵖ} (h : S.HomologyData) : S.unop.HomologyData where left := h.right.unop right := h.left.unop iso := h.iso.unop comm := Quiver.Hom.op_inj (by simp) end HomologyData /-- A short complex `S` has homology when there exists a `S.HomologyData` -/ class HasHomology : Prop where /-- the condition that there exists a homology data -/ condition : Nonempty S.HomologyData /-- A chosen `S.HomologyData` for a short complex `S` that has homology -/ noncomputable def homologyData [HasHomology S] : S.HomologyData := HasHomology.condition.some variable {S} lemma HasHomology.mk' (h : S.HomologyData) : HasHomology S := ⟨Nonempty.intro h⟩ instance [HasHomology S] : HasHomology S.op := HasHomology.mk' S.homologyData.op instance (S : ShortComplex Cᵒᵖ) [HasHomology S] : HasHomology S.unop := HasHomology.mk' S.homologyData.unop instance hasLeftHomology_of_hasHomology [S.HasHomology] : S.HasLeftHomology := HasLeftHomology.mk' S.homologyData.left instance hasRightHomology_of_hasHomology [S.HasHomology] : S.HasRightHomology := HasRightHomology.mk' S.homologyData.right instance hasHomology_of_hasCokernel {X Y : C} (f : X ⟶ Y) (Z : C) [HasCokernel f] : (ShortComplex.mk f (0 : Y ⟶ Z) comp_zero).HasHomology := HasHomology.mk' (HomologyData.ofHasCokernel _ rfl) instance hasHomology_of_hasKernel {Y Z : C} (g : Y ⟶ Z) (X : C) [HasKernel g] : (ShortComplex.mk (0 : X ⟶ Y) g zero_comp).HasHomology := HasHomology.mk' (HomologyData.ofHasKernel _ rfl) instance hasHomology_of_zeros (X Y Z : C) : (ShortComplex.mk (0 : X ⟶ Y) (0 : Y ⟶ Z) zero_comp).HasHomology := HasHomology.mk' (HomologyData.ofZeros _ rfl rfl) lemma hasHomology_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [HasHomology S₁] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasHomology S₂ := HasHomology.mk' (HomologyData.ofEpiOfIsIsoOfMono φ S₁.homologyData) lemma hasHomology_of_epi_of_isIso_of_mono' (φ : S₁ ⟶ S₂) [HasHomology S₂] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasHomology S₁ := HasHomology.mk' (HomologyData.ofEpiOfIsIsoOfMono' φ S₂.homologyData) lemma hasHomology_of_iso (e : S₁ ≅ S₂) [HasHomology S₁] : HasHomology S₂ := HasHomology.mk' (HomologyData.ofIso e S₁.homologyData) namespace HomologyMapData /-- The homology map data associated to the identity morphism of a short complex. -/ @[simps] def id (h : S.HomologyData) : HomologyMapData (𝟙 S) h h where left := LeftHomologyMapData.id h.left right := RightHomologyMapData.id h.right /-- The homology map data associated to the zero morphism between two short complexes. -/ @[simps] def zero (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : HomologyMapData 0 h₁ h₂ where left := LeftHomologyMapData.zero h₁.left h₂.left right := RightHomologyMapData.zero h₁.right h₂.right /-- The composition of homology map data. -/ @[simps] def comp {φ : S₁ ⟶ S₂} {φ' : S₂ ⟶ S₃} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} {h₃ : S₃.HomologyData} (ψ : HomologyMapData φ h₁ h₂) (ψ' : HomologyMapData φ' h₂ h₃) : HomologyMapData (φ ≫ φ') h₁ h₃ where left := ψ.left.comp ψ'.left right := ψ.right.comp ψ'.right /-- A homology map data for a morphism of short complexes induces a homology map data in the opposite category. -/ @[simps] def op {φ : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} (ψ : HomologyMapData φ h₁ h₂) : HomologyMapData (opMap φ) h₂.op h₁.op where left := ψ.right.op right := ψ.left.op /-- A homology map data for a morphism of short complexes in the opposite category induces a homology map data in the original category. -/ @[simps] def unop {S₁ S₂ : ShortComplex Cᵒᵖ} {φ : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} (ψ : HomologyMapData φ h₁ h₂) : HomologyMapData (unopMap φ) h₂.unop h₁.unop where left := ψ.right.unop right := ψ.left.unop /-- When `S₁.f`, `S₁.g`, `S₂.f` and `S₂.g` are all zero, the action on homology of a morphism `φ : S₁ ⟶ S₂` is given by the action `φ.τ₂` on the middle objects. -/ @[simps] noncomputable def ofZeros (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) (hg₂ : S₂.g = 0) : HomologyMapData φ (HomologyData.ofZeros S₁ hf₁ hg₁) (HomologyData.ofZeros S₂ hf₂ hg₂) where left := LeftHomologyMapData.ofZeros φ hf₁ hg₁ hf₂ hg₂ right := RightHomologyMapData.ofZeros φ hf₁ hg₁ hf₂ hg₂ /-- When `S₁.g` and `S₂.g` are zero and we have chosen colimit cokernel coforks `c₁` and `c₂` for `S₁.f` and `S₂.f` respectively, the action on homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `φ.τ₂ ≫ c₂.π = c₁.π ≫ f`. -/ @[simps] def ofIsColimitCokernelCofork (φ : S₁ ⟶ S₂) (hg₁ : S₁.g = 0) (c₁ : CokernelCofork S₁.f) (hc₁ : IsColimit c₁) (hg₂ : S₂.g = 0) (c₂ : CokernelCofork S₂.f) (hc₂ : IsColimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : φ.τ₂ ≫ c₂.π = c₁.π ≫ f) : HomologyMapData φ (HomologyData.ofIsColimitCokernelCofork S₁ hg₁ c₁ hc₁) (HomologyData.ofIsColimitCokernelCofork S₂ hg₂ c₂ hc₂) where left := LeftHomologyMapData.ofIsColimitCokernelCofork φ hg₁ c₁ hc₁ hg₂ c₂ hc₂ f comm right := RightHomologyMapData.ofIsColimitCokernelCofork φ hg₁ c₁ hc₁ hg₂ c₂ hc₂ f comm /-- When `S₁.f` and `S₂.f` are zero and we have chosen limit kernel forks `c₁` and `c₂` for `S₁.g` and `S₂.g` respectively, the action on homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι`. -/ @[simps] def ofIsLimitKernelFork (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (c₁ : KernelFork S₁.g) (hc₁ : IsLimit c₁) (hf₂ : S₂.f = 0) (c₂ : KernelFork S₂.g) (hc₂ : IsLimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι) : HomologyMapData φ (HomologyData.ofIsLimitKernelFork S₁ hf₁ c₁ hc₁) (HomologyData.ofIsLimitKernelFork S₂ hf₂ c₂ hc₂) where left := LeftHomologyMapData.ofIsLimitKernelFork φ hf₁ c₁ hc₁ hf₂ c₂ hc₂ f comm right := RightHomologyMapData.ofIsLimitKernelFork φ hf₁ c₁ hc₁ hf₂ c₂ hc₂ f comm /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the homology map data (for the identity of `S`) which relates the homology data `ofZeros` and `ofIsColimitCokernelCofork`. -/ noncomputable def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : HomologyMapData (𝟙 S) (HomologyData.ofZeros S hf hg) (HomologyData.ofIsColimitCokernelCofork S hg c hc) where left := LeftHomologyMapData.compatibilityOfZerosOfIsColimitCokernelCofork S hf hg c hc right := RightHomologyMapData.compatibilityOfZerosOfIsColimitCokernelCofork S hf hg c hc /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the homology map data (for the identity of `S`) which relates the homology data `HomologyData.ofIsLimitKernelFork` and `ofZeros` . -/ @[simps] noncomputable def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0) (c : KernelFork S.g) (hc : IsLimit c) : HomologyMapData (𝟙 S) (HomologyData.ofIsLimitKernelFork S hf c hc) (HomologyData.ofZeros S hf hg) where left := LeftHomologyMapData.compatibilityOfZerosOfIsLimitKernelFork S hf hg c hc right := RightHomologyMapData.compatibilityOfZerosOfIsLimitKernelFork S hf hg c hc /-- This homology map data expresses compatibilities of the homology data constructed by `HomologyData.ofEpiOfIsIsoOfMono` -/ noncomputable def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : HomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HomologyMapData φ h (HomologyData.ofEpiOfIsIsoOfMono φ h) where left := LeftHomologyMapData.ofEpiOfIsIsoOfMono φ h.left right := RightHomologyMapData.ofEpiOfIsIsoOfMono φ h.right /-- This homology map data expresses compatibilities of the homology data constructed by `HomologyData.ofEpiOfIsIsoOfMono'` -/ noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : HomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HomologyMapData φ (HomologyData.ofEpiOfIsIsoOfMono' φ h) h where left := LeftHomologyMapData.ofEpiOfIsIsoOfMono' φ h.left right := RightHomologyMapData.ofEpiOfIsIsoOfMono' φ h.right end HomologyMapData variable (S) /-- The homology of a short complex is the `left.H` field of a chosen homology data. -/ noncomputable def homology [HasHomology S] : C := S.homologyData.left.H /-- When a short complex has homology, this is the canonical isomorphism `S.leftHomology ≅ S.homology`. -/ noncomputable def leftHomologyIso [S.HasHomology] : S.leftHomology ≅ S.homology := leftHomologyMapIso' (Iso.refl _) _ _ /-- When a short complex has homology, this is the canonical isomorphism `S.rightHomology ≅ S.homology`. -/ noncomputable def rightHomologyIso [S.HasHomology] : S.rightHomology ≅ S.homology := rightHomologyMapIso' (Iso.refl _) _ _ ≪≫ S.homologyData.iso.symm variable {S} /-- When a short complex has homology, its homology can be computed using any left homology data. -/ noncomputable def LeftHomologyData.homologyIso (h : S.LeftHomologyData) [S.HasHomology] : S.homology ≅ h.H := S.leftHomologyIso.symm ≪≫ h.leftHomologyIso /-- When a short complex has homology, its homology can be computed using any right homology data. -/ noncomputable def RightHomologyData.homologyIso (h : S.RightHomologyData) [S.HasHomology] : S.homology ≅ h.H := S.rightHomologyIso.symm ≪≫ h.rightHomologyIso variable (S) @[simp] lemma LeftHomologyData.homologyIso_leftHomologyData [S.HasHomology] : S.leftHomologyData.homologyIso = S.leftHomologyIso.symm := by ext dsimp [homologyIso, leftHomologyIso, ShortComplex.leftHomologyIso] rw [← leftHomologyMap'_comp, comp_id] @[simp] lemma RightHomologyData.homologyIso_rightHomologyData [S.HasHomology] : S.rightHomologyData.homologyIso = S.rightHomologyIso.symm := by ext simp [homologyIso, rightHomologyIso] variable {S} /-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and homology data `h₁` and `h₂` for `S₁` and `S₂` respectively, this is the induced homology map `h₁.left.H ⟶ h₁.left.H`. -/ def homologyMap' (φ : S₁ ⟶ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : h₁.left.H ⟶ h₂.left.H := leftHomologyMap' φ _ _ /-- The homology map `S₁.homology ⟶ S₂.homology` induced by a morphism `S₁ ⟶ S₂` of short complexes. -/ noncomputable def homologyMap (φ : S₁ ⟶ S₂) [HasHomology S₁] [HasHomology S₂] : S₁.homology ⟶ S₂.homology := homologyMap' φ _ _ namespace HomologyMapData variable {φ : S₁ ⟶ S₂} {h₁ : S₁.HomologyData} {h₂ : S₂.HomologyData} (γ : HomologyMapData φ h₁ h₂) lemma homologyMap'_eq : homologyMap' φ h₁ h₂ = γ.left.φH := LeftHomologyMapData.congr_φH (Subsingleton.elim _ _) lemma cyclesMap'_eq : cyclesMap' φ h₁.left h₂.left = γ.left.φK := LeftHomologyMapData.congr_φK (Subsingleton.elim _ _) lemma opcyclesMap'_eq : opcyclesMap' φ h₁.right h₂.right = γ.right.φQ := RightHomologyMapData.congr_φQ (Subsingleton.elim _ _) end HomologyMapData namespace LeftHomologyMapData variable {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (γ : LeftHomologyMapData φ h₁ h₂) [S₁.HasHomology] [S₂.HasHomology] lemma homologyMap_eq : homologyMap φ = h₁.homologyIso.hom ≫ γ.φH ≫ h₂.homologyIso.inv := by dsimp [homologyMap, LeftHomologyData.homologyIso, leftHomologyIso, LeftHomologyData.leftHomologyIso, homologyMap'] simp only [← γ.leftHomologyMap'_eq, ← leftHomologyMap'_comp, id_comp, comp_id] lemma homologyMap_comm : homologyMap φ ≫ h₂.homologyIso.hom = h₁.homologyIso.hom ≫ γ.φH := by simp only [γ.homologyMap_eq, assoc, Iso.inv_hom_id, comp_id] end LeftHomologyMapData namespace RightHomologyMapData variable {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} (γ : RightHomologyMapData φ h₁ h₂) [S₁.HasHomology] [S₂.HasHomology] lemma homologyMap_eq : homologyMap φ = h₁.homologyIso.hom ≫ γ.φH ≫ h₂.homologyIso.inv := by dsimp [homologyMap, homologyMap', RightHomologyData.homologyIso, rightHomologyIso, RightHomologyData.rightHomologyIso] have γ' : HomologyMapData φ S₁.homologyData S₂.homologyData := default simp only [← γ.rightHomologyMap'_eq, assoc, ← rightHomologyMap'_comp_assoc, id_comp, comp_id, γ'.left.leftHomologyMap'_eq, γ'.right.rightHomologyMap'_eq, ← γ'.comm_assoc, Iso.hom_inv_id] lemma homologyMap_comm : homologyMap φ ≫ h₂.homologyIso.hom = h₁.homologyIso.hom ≫ γ.φH := by simp only [γ.homologyMap_eq, assoc, Iso.inv_hom_id, comp_id] end RightHomologyMapData @[simp] lemma homologyMap'_id (h : S.HomologyData) : homologyMap' (𝟙 S) h h = 𝟙 _ := (HomologyMapData.id h).homologyMap'_eq variable (S) @[simp] lemma homologyMap_id [HasHomology S] : homologyMap (𝟙 S) = 𝟙 _ := homologyMap'_id _ @[simp] lemma homologyMap'_zero (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : homologyMap' 0 h₁ h₂ = 0 := (HomologyMapData.zero h₁ h₂).homologyMap'_eq variable (S₁ S₂) @[simp] lemma homologyMap_zero [S₁.HasHomology] [S₂.HasHomology] : homologyMap (0 : S₁ ⟶ S₂) = 0 := homologyMap'_zero _ _ variable {S₁ S₂} lemma homologyMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) (h₃ : S₃.HomologyData) : homologyMap' (φ₁ ≫ φ₂) h₁ h₃ = homologyMap' φ₁ h₁ h₂ ≫ homologyMap' φ₂ h₂ h₃ := leftHomologyMap'_comp _ _ _ _ _ @[simp] lemma homologyMap_comp [HasHomology S₁] [HasHomology S₂] [HasHomology S₃] (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) : homologyMap (φ₁ ≫ φ₂) = homologyMap φ₁ ≫ homologyMap φ₂ := homologyMap'_comp _ _ _ _ _ /-- Given an isomorphism `S₁ ≅ S₂` of short complexes and homology data `h₁` and `h₂` for `S₁` and `S₂` respectively, this is the induced homology isomorphism `h₁.left.H ≅ h₁.left.H`. -/ @[simps] def homologyMapIso' (e : S₁ ≅ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : h₁.left.H ≅ h₂.left.H where hom := homologyMap' e.hom h₁ h₂ inv := homologyMap' e.inv h₂ h₁ hom_inv_id := by rw [← homologyMap'_comp, e.hom_inv_id, homologyMap'_id] inv_hom_id := by rw [← homologyMap'_comp, e.inv_hom_id, homologyMap'_id] instance isIso_homologyMap'_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ] (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) : IsIso (homologyMap' φ h₁ h₂) := (inferInstance : IsIso (homologyMapIso' (asIso φ) h₁ h₂).hom) /-- The homology isomorphism `S₁.homology ⟶ S₂.homology` induced by an isomorphism `S₁ ≅ S₂` of short complexes. -/ @[simps] noncomputable def homologyMapIso (e : S₁ ≅ S₂) [S₁.HasHomology] [S₂.HasHomology] : S₁.homology ≅ S₂.homology where hom := homologyMap e.hom inv := homologyMap e.inv hom_inv_id := by rw [← homologyMap_comp, e.hom_inv_id, homologyMap_id] inv_hom_id := by rw [← homologyMap_comp, e.inv_hom_id, homologyMap_id] instance isIso_homologyMap_of_iso (φ : S₁ ⟶ S₂) [IsIso φ] [S₁.HasHomology] [S₂.HasHomology] : IsIso (homologyMap φ) := (inferInstance : IsIso (homologyMapIso (asIso φ)).hom) variable {S} section variable (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) /-- If a short complex `S` has both a left homology data `h₁` and a right homology data `h₂`, this is the canonical morphism `h₁.H ⟶ h₂.H`. -/ def leftRightHomologyComparison' : h₁.H ⟶ h₂.H := h₂.liftH (h₁.descH (h₁.i ≫ h₂.p) (by simp)) (by rw [← cancel_epi h₁.π, LeftHomologyData.π_descH_assoc, assoc, RightHomologyData.p_g', LeftHomologyData.wi, comp_zero]) lemma leftRightHomologyComparison'_eq_liftH : leftRightHomologyComparison' h₁ h₂ = h₂.liftH (h₁.descH (h₁.i ≫ h₂.p) (by simp)) (by rw [← cancel_epi h₁.π, LeftHomologyData.π_descH_assoc, assoc, RightHomologyData.p_g', LeftHomologyData.wi, comp_zero]) := rfl @[reassoc (attr := simp)] lemma π_leftRightHomologyComparison'_ι : h₁.π ≫ leftRightHomologyComparison' h₁ h₂ ≫ h₂.ι = h₁.i ≫ h₂.p := by simp only [leftRightHomologyComparison'_eq_liftH, RightHomologyData.liftH_ι, LeftHomologyData.π_descH] lemma leftRightHomologyComparison'_eq_descH : leftRightHomologyComparison' h₁ h₂ = h₁.descH (h₂.liftH (h₁.i ≫ h₂.p) (by simp)) (by rw [← cancel_mono h₂.ι, assoc, RightHomologyData.liftH_ι, LeftHomologyData.f'_i_assoc, RightHomologyData.wp, zero_comp]) := by simp only [← cancel_mono h₂.ι, ← cancel_epi h₁.π, π_leftRightHomologyComparison'_ι, LeftHomologyData.π_descH_assoc, RightHomologyData.liftH_ι] end variable (S) /-- If a short complex `S` has both a left and right homology, this is the canonical morphism `S.leftHomology ⟶ S.rightHomology`. -/ noncomputable def leftRightHomologyComparison [S.HasLeftHomology] [S.HasRightHomology] : S.leftHomology ⟶ S.rightHomology := leftRightHomologyComparison' _ _ @[reassoc (attr := simp)] lemma π_leftRightHomologyComparison_ι [S.HasLeftHomology] [S.HasRightHomology] : S.leftHomologyπ ≫ S.leftRightHomologyComparison ≫ S.rightHomologyι = S.iCycles ≫ S.pOpcycles := π_leftRightHomologyComparison'_ι _ _ @[reassoc] lemma leftRightHomologyComparison'_naturality (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₁.RightHomologyData) (h₁' : S₂.LeftHomologyData) (h₂' : S₂.RightHomologyData) : leftHomologyMap' φ h₁ h₁' ≫ leftRightHomologyComparison' h₁' h₂' = leftRightHomologyComparison' h₁ h₂ ≫ rightHomologyMap' φ h₂ h₂' := by simp only [← cancel_epi h₁.π, ← cancel_mono h₂'.ι, assoc, leftHomologyπ_naturality'_assoc, rightHomologyι_naturality', π_leftRightHomologyComparison'_ι, π_leftRightHomologyComparison'_ι_assoc, cyclesMap'_i_assoc, p_opcyclesMap'] variable {S} lemma leftRightHomologyComparison'_compatibility (h₁ h₁' : S.LeftHomologyData) (h₂ h₂' : S.RightHomologyData) : leftRightHomologyComparison' h₁ h₂ = leftHomologyMap' (𝟙 S) h₁ h₁' ≫ leftRightHomologyComparison' h₁' h₂' ≫ rightHomologyMap' (𝟙 S) _ _ := by rw [leftRightHomologyComparison'_naturality_assoc (𝟙 S) h₁ h₂ h₁' h₂', ← rightHomologyMap'_comp, comp_id, rightHomologyMap'_id, comp_id] lemma leftRightHomologyComparison_eq [S.HasLeftHomology] [S.HasRightHomology] (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) : S.leftRightHomologyComparison = h₁.leftHomologyIso.hom ≫ leftRightHomologyComparison' h₁ h₂ ≫ h₂.rightHomologyIso.inv := leftRightHomologyComparison'_compatibility _ _ _ _ @[simp] lemma HomologyData.leftRightHomologyComparison'_eq (h : S.HomologyData) : leftRightHomologyComparison' h.left h.right = h.iso.hom := by simp only [← cancel_epi h.left.π, ← cancel_mono h.right.ι, assoc, π_leftRightHomologyComparison'_ι, comm] instance isIso_leftRightHomologyComparison'_of_homologyData (h : S.HomologyData) : IsIso (leftRightHomologyComparison' h.left h.right) := by rw [h.leftRightHomologyComparison'_eq] infer_instance instance isIso_leftRightHomologyComparison' [S.HasHomology] (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) : IsIso (leftRightHomologyComparison' h₁ h₂) := by rw [leftRightHomologyComparison'_compatibility h₁ S.homologyData.left h₂ S.homologyData.right] infer_instance instance isIso_leftRightHomologyComparison [S.HasHomology] : IsIso S.leftRightHomologyComparison := by dsimp only [leftRightHomologyComparison] infer_instance namespace HomologyData /-- This is the homology data for a short complex `S` that is obtained from a left homology data `h₁` and a right homology data `h₂` when the comparison morphism `leftRightHomologyComparison' h₁ h₂ : h₁.H ⟶ h₂.H` is an isomorphism. -/ @[simps] noncomputable def ofIsIsoLeftRightHomologyComparison' (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) [IsIso (leftRightHomologyComparison' h₁ h₂)] : S.HomologyData where left := h₁ right := h₂ iso := asIso (leftRightHomologyComparison' h₁ h₂) end HomologyData lemma leftRightHomologyComparison'_eq_leftHomologpMap'_comp_iso_hom_comp_rightHomologyMap' (h : S.HomologyData) (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) : leftRightHomologyComparison' h₁ h₂ = leftHomologyMap' (𝟙 S) h₁ h.left ≫ h.iso.hom ≫ rightHomologyMap' (𝟙 S) h.right h₂ := by simpa only [h.leftRightHomologyComparison'_eq] using leftRightHomologyComparison'_compatibility h₁ h.left h₂ h.right @[reassoc] lemma leftRightHomologyComparison'_fac (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) [S.HasHomology] : leftRightHomologyComparison' h₁ h₂ = h₁.homologyIso.inv ≫ h₂.homologyIso.hom := by rw [leftRightHomologyComparison'_eq_leftHomologpMap'_comp_iso_hom_comp_rightHomologyMap' S.homologyData h₁ h₂] dsimp only [LeftHomologyData.homologyIso, LeftHomologyData.leftHomologyIso, Iso.symm, Iso.trans, Iso.refl, leftHomologyMapIso', leftHomologyIso, RightHomologyData.homologyIso, RightHomologyData.rightHomologyIso, rightHomologyMapIso', rightHomologyIso] simp only [assoc, ← leftHomologyMap'_comp_assoc, id_comp, ← rightHomologyMap'_comp] variable (S) @[reassoc] lemma leftRightHomologyComparison_fac [S.HasHomology] : S.leftRightHomologyComparison = S.leftHomologyIso.hom ≫ S.rightHomologyIso.inv := by simpa only [LeftHomologyData.homologyIso_leftHomologyData, Iso.symm_inv, RightHomologyData.homologyIso_rightHomologyData, Iso.symm_hom] using leftRightHomologyComparison'_fac S.leftHomologyData S.rightHomologyData variable {S} lemma HomologyData.right_homologyIso_eq_left_homologyIso_trans_iso (h : S.HomologyData) [S.HasHomology] : h.right.homologyIso = h.left.homologyIso ≪≫ h.iso := by suffices h.iso = h.left.homologyIso.symm ≪≫ h.right.homologyIso by rw [this, Iso.self_symm_id_assoc] ext dsimp rw [← leftRightHomologyComparison'_fac, leftRightHomologyComparison'_eq] lemma hasHomology_of_isIso_leftRightHomologyComparison' (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) [IsIso (leftRightHomologyComparison' h₁ h₂)] : S.HasHomology := HasHomology.mk' (HomologyData.ofIsIsoLeftRightHomologyComparison' h₁ h₂) lemma hasHomology_of_isIsoLeftRightHomologyComparison [S.HasLeftHomology] [S.HasRightHomology] [h : IsIso S.leftRightHomologyComparison] : S.HasHomology := by haveI : IsIso (leftRightHomologyComparison' S.leftHomologyData S.rightHomologyData) := h exact hasHomology_of_isIso_leftRightHomologyComparison' S.leftHomologyData S.rightHomologyData section variable [S₁.HasHomology] [S₂.HasHomology] (φ : S₁ ⟶ S₂) @[reassoc] lemma LeftHomologyData.leftHomologyIso_hom_naturality (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : h₁.homologyIso.hom ≫ leftHomologyMap' φ h₁ h₂ = homologyMap φ ≫ h₂.homologyIso.hom := by dsimp [homologyIso, ShortComplex.leftHomologyIso, homologyMap, homologyMap', leftHomologyIso] simp only [← leftHomologyMap'_comp, id_comp, comp_id] @[reassoc] lemma LeftHomologyData.leftHomologyIso_inv_naturality (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : h₁.homologyIso.inv ≫ homologyMap φ = leftHomologyMap' φ h₁ h₂ ≫ h₂.homologyIso.inv := by dsimp [homologyIso, ShortComplex.leftHomologyIso, homologyMap, homologyMap', leftHomologyIso] simp only [← leftHomologyMap'_comp, id_comp, comp_id] @[reassoc] lemma leftHomologyIso_hom_naturality : S₁.leftHomologyIso.hom ≫ homologyMap φ = leftHomologyMap φ ≫ S₂.leftHomologyIso.hom := by simpa only [LeftHomologyData.homologyIso_leftHomologyData, Iso.symm_inv] using LeftHomologyData.leftHomologyIso_inv_naturality φ S₁.leftHomologyData S₂.leftHomologyData @[reassoc] lemma leftHomologyIso_inv_naturality : S₁.leftHomologyIso.inv ≫ leftHomologyMap φ = homologyMap φ ≫ S₂.leftHomologyIso.inv := by simpa only [LeftHomologyData.homologyIso_leftHomologyData, Iso.symm_inv] using LeftHomologyData.leftHomologyIso_hom_naturality φ S₁.leftHomologyData S₂.leftHomologyData @[reassoc] lemma RightHomologyData.rightHomologyIso_hom_naturality (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : h₁.homologyIso.hom ≫ rightHomologyMap' φ h₁ h₂ = homologyMap φ ≫ h₂.homologyIso.hom := by rw [← cancel_epi h₁.homologyIso.inv, Iso.inv_hom_id_assoc, ← cancel_epi (leftRightHomologyComparison' S₁.leftHomologyData h₁), ← leftRightHomologyComparison'_naturality φ S₁.leftHomologyData h₁ S₂.leftHomologyData h₂, ← cancel_epi (S₁.leftHomologyData.homologyIso.hom), LeftHomologyData.leftHomologyIso_hom_naturality_assoc, leftRightHomologyComparison'_fac, leftRightHomologyComparison'_fac, assoc, Iso.hom_inv_id_assoc, Iso.hom_inv_id_assoc, Iso.hom_inv_id_assoc] @[reassoc] lemma RightHomologyData.rightHomologyIso_inv_naturality (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : h₁.homologyIso.inv ≫ homologyMap φ = rightHomologyMap' φ h₁ h₂ ≫ h₂.homologyIso.inv := by simp only [← cancel_mono h₂.homologyIso.hom, assoc, Iso.inv_hom_id_assoc, comp_id, ← RightHomologyData.rightHomologyIso_hom_naturality φ h₁ h₂, Iso.inv_hom_id] @[reassoc] lemma rightHomologyIso_hom_naturality : S₁.rightHomologyIso.hom ≫ homologyMap φ = rightHomologyMap φ ≫ S₂.rightHomologyIso.hom := by simpa only [RightHomologyData.homologyIso_rightHomologyData, Iso.symm_inv] using RightHomologyData.rightHomologyIso_inv_naturality φ S₁.rightHomologyData S₂.rightHomologyData @[reassoc] lemma rightHomologyIso_inv_naturality : S₁.rightHomologyIso.inv ≫ rightHomologyMap φ = homologyMap φ ≫ S₂.rightHomologyIso.inv := by simpa only [RightHomologyData.homologyIso_rightHomologyData, Iso.symm_inv] using RightHomologyData.rightHomologyIso_hom_naturality φ S₁.rightHomologyData S₂.rightHomologyData end variable (C) /-- We shall say that a category `C` is a category with homology when all short complexes have homology. -/ class _root_.CategoryTheory.CategoryWithHomology : Prop where hasHomology : ∀ (S : ShortComplex C), S.HasHomology attribute [instance] CategoryWithHomology.hasHomology instance [CategoryWithHomology C] : CategoryWithHomology Cᵒᵖ := ⟨fun S => HasHomology.mk' S.unop.homologyData.op⟩ /-- The homology functor `ShortComplex C ⥤ C` for a category `C` with homology. -/ @[simps] noncomputable def homologyFunctor [CategoryWithHomology C] : ShortComplex C ⥤ C where obj S := S.homology map f := homologyMap f variable {C} instance isIso_homologyMap'_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) (h₁ : S₁.HomologyData) (h₂ : S₂.HomologyData) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso (homologyMap' φ h₁ h₂) := by dsimp only [homologyMap'] infer_instance lemma isIso_homologyMap_of_epi_of_isIso_of_mono' (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] (h₁ : Epi φ.τ₁) (h₂ : IsIso φ.τ₂) (h₃ : Mono φ.τ₃) : IsIso (homologyMap φ) := by dsimp only [homologyMap] infer_instance instance isIso_homologyMap_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso (homologyMap φ) := isIso_homologyMap_of_epi_of_isIso_of_mono' φ inferInstance inferInstance inferInstance instance isIso_homologyFunctor_map_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [CategoryWithHomology C] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso ((homologyFunctor C).map φ) := (inferInstance : IsIso (homologyMap φ)) instance isIso_homologyMap_of_isIso (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] [IsIso φ] : IsIso (homologyMap φ) := by dsimp only [homologyMap, homologyMap'] infer_instance section variable (S) {A : C} variable [HasHomology S] /-- The canonical morphism `S.cycles ⟶ S.homology` for a short complex `S` that has homology. -/ noncomputable def homologyπ : S.cycles ⟶ S.homology := S.leftHomologyπ ≫ S.leftHomologyIso.hom /-- The canonical morphism `S.homology ⟶ S.opcycles` for a short complex `S` that has homology. -/ noncomputable def homologyι : S.homology ⟶ S.opcycles := S.rightHomologyIso.inv ≫ S.rightHomologyι @[reassoc (attr := simp)] lemma homologyπ_comp_leftHomologyIso_inv : S.homologyπ ≫ S.leftHomologyIso.inv = S.leftHomologyπ := by dsimp only [homologyπ] simp only [assoc, Iso.hom_inv_id, comp_id] @[reassoc (attr := simp)] lemma rightHomologyIso_hom_comp_homologyι : S.rightHomologyIso.hom ≫ S.homologyι = S.rightHomologyι := by dsimp only [homologyι] simp only [Iso.hom_inv_id_assoc] @[reassoc (attr := simp)] lemma toCycles_comp_homologyπ : S.toCycles ≫ S.homologyπ = 0 := by dsimp only [homologyπ] simp only [toCycles_comp_leftHomologyπ_assoc, zero_comp] @[reassoc (attr := simp)] lemma homologyι_comp_fromOpcycles : S.homologyι ≫ S.fromOpcycles = 0 := by dsimp only [homologyι] simp only [assoc, rightHomologyι_comp_fromOpcycles, comp_zero] /-- The homology `S.homology` of a short complex is the cokernel of the morphism `S.toCycles : S.X₁ ⟶ S.cycles`. -/ noncomputable def homologyIsCokernel : IsColimit (CokernelCofork.ofπ S.homologyπ S.toCycles_comp_homologyπ) := IsColimit.ofIsoColimit S.leftHomologyIsCokernel (Cofork.ext S.leftHomologyIso rfl) /-- The homology `S.homology` of a short complex is the kernel of the morphism `S.fromOpcycles : S.opcycles ⟶ S.X₃`. -/ noncomputable def homologyIsKernel : IsLimit (KernelFork.ofι S.homologyι S.homologyι_comp_fromOpcycles) := IsLimit.ofIsoLimit S.rightHomologyIsKernel (Fork.ext S.rightHomologyIso (by simp)) instance : Epi S.homologyπ := Limits.epi_of_isColimit_cofork (S.homologyIsCokernel) instance : Mono S.homologyι := Limits.mono_of_isLimit_fork (S.homologyIsKernel) /-- Given a morphism `k : S.cycles ⟶ A` such that `S.toCycles ≫ k = 0`, this is the induced morphism `S.homology ⟶ A`. -/ noncomputable def descHomology (k : S.cycles ⟶ A) (hk : S.toCycles ≫ k = 0) : S.homology ⟶ A := S.homologyIsCokernel.desc (CokernelCofork.ofπ k hk) /-- Given a morphism `k : A ⟶ S.opcycles` such that `k ≫ S.fromOpcycles = 0`, this is the induced morphism `A ⟶ S.homology`. -/ noncomputable def liftHomology (k : A ⟶ S.opcycles) (hk : k ≫ S.fromOpcycles = 0) : A ⟶ S.homology := S.homologyIsKernel.lift (KernelFork.ofι k hk) @[reassoc (attr := simp)] lemma π_descHomology (k : S.cycles ⟶ A) (hk : S.toCycles ≫ k = 0) : S.homologyπ ≫ S.descHomology k hk = k := Cofork.IsColimit.π_desc S.homologyIsCokernel @[reassoc (attr := simp)] lemma liftHomology_ι (k : A ⟶ S.opcycles) (hk : k ≫ S.fromOpcycles = 0) : S.liftHomology k hk ≫ S.homologyι = k := Fork.IsLimit.lift_ι S.homologyIsKernel @[reassoc (attr := simp)] lemma homologyπ_naturality (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] : S₁.homologyπ ≫ homologyMap φ = cyclesMap φ ≫ S₂.homologyπ := by simp only [← cancel_mono S₂.leftHomologyIso.inv, assoc, ← leftHomologyIso_inv_naturality φ, homologyπ_comp_leftHomologyIso_inv] simp only [homologyπ, assoc, Iso.hom_inv_id_assoc, leftHomologyπ_naturality] @[reassoc (attr := simp)] lemma homologyι_naturality (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] : homologyMap φ ≫ S₂.homologyι = S₁.homologyι ≫ S₁.opcyclesMap φ := by simp only [← cancel_epi S₁.rightHomologyIso.hom, rightHomologyIso_hom_naturality_assoc φ, rightHomologyIso_hom_comp_homologyι, rightHomologyι_naturality] simp only [homologyι, assoc, Iso.hom_inv_id_assoc] @[reassoc (attr := simp)] lemma homology_π_ι : S.homologyπ ≫ S.homologyι = S.iCycles ≫ S.pOpcycles := by dsimp only [homologyπ, homologyι] simpa only [assoc, S.leftRightHomologyComparison_fac] using S.π_leftRightHomologyComparison_ι /-- The homology of a short complex `S` identifies to the kernel of the induced morphism `cokernel S.f ⟶ S.X₃`. -/ noncomputable def homologyIsoKernelDesc [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.homology ≅ kernel (cokernel.desc S.f S.g S.zero) := S.rightHomologyIso.symm ≪≫ S.rightHomologyIsoKernelDesc /-- The homology of a short complex `S` identifies to the cokernel of the induced morphism `S.X₁ ⟶ kernel S.g`. -/ noncomputable def homologyIsoCokernelLift [HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] : S.homology ≅ cokernel (kernel.lift S.g S.f S.zero) := S.leftHomologyIso.symm ≪≫ S.leftHomologyIsoCokernelLift @[reassoc (attr := simp)] lemma LeftHomologyData.homologyπ_comp_homologyIso_hom (h : S.LeftHomologyData) : S.homologyπ ≫ h.homologyIso.hom = h.cyclesIso.hom ≫ h.π := by dsimp only [homologyπ, homologyIso] simp only [Iso.trans_hom, Iso.symm_hom, assoc, Iso.hom_inv_id_assoc, leftHomologyπ_comp_leftHomologyIso_hom] @[reassoc (attr := simp)] lemma LeftHomologyData.π_comp_homologyIso_inv (h : S.LeftHomologyData) : h.π ≫ h.homologyIso.inv = h.cyclesIso.inv ≫ S.homologyπ := by dsimp only [homologyπ, homologyIso] simp only [Iso.trans_inv, Iso.symm_inv, π_comp_leftHomologyIso_inv_assoc] @[reassoc (attr := simp)] lemma RightHomologyData.homologyIso_inv_comp_homologyι (h : S.RightHomologyData) : h.homologyIso.inv ≫ S.homologyι = h.ι ≫ h.opcyclesIso.inv := by dsimp only [homologyι, homologyIso] simp only [Iso.trans_inv, Iso.symm_inv, assoc, Iso.hom_inv_id_assoc, rightHomologyIso_inv_comp_rightHomologyι] @[reassoc (attr := simp)] lemma RightHomologyData.homologyIso_hom_comp_ι (h : S.RightHomologyData) : h.homologyIso.hom ≫ h.ι = S.homologyι ≫ h.opcyclesIso.hom := by dsimp only [homologyι, homologyIso] simp only [Iso.trans_hom, Iso.symm_hom, assoc, rightHomologyIso_hom_comp_ι] @[reassoc (attr := simp)] lemma LeftHomologyData.homologyIso_hom_comp_leftHomologyIso_inv (h : S.LeftHomologyData) : h.homologyIso.hom ≫ h.leftHomologyIso.inv = S.leftHomologyIso.inv := by dsimp only [homologyIso] simp only [Iso.trans_hom, Iso.symm_hom, assoc, Iso.hom_inv_id, comp_id] @[reassoc (attr := simp)] lemma LeftHomologyData.leftHomologyIso_hom_comp_homologyIso_inv (h : S.LeftHomologyData) : h.leftHomologyIso.hom ≫ h.homologyIso.inv = S.leftHomologyIso.hom := by dsimp only [homologyIso] simp only [Iso.trans_inv, Iso.symm_inv, Iso.hom_inv_id_assoc] @[reassoc (attr := simp)] lemma RightHomologyData.homologyIso_hom_comp_rightHomologyIso_inv (h : S.RightHomologyData) : h.homologyIso.hom ≫ h.rightHomologyIso.inv = S.rightHomologyIso.inv := by dsimp only [homologyIso] simp only [Iso.trans_hom, Iso.symm_hom, assoc, Iso.hom_inv_id, comp_id] @[reassoc (attr := simp)] lemma RightHomologyData.rightHomologyIso_hom_comp_homologyIso_inv (h : S.RightHomologyData) : h.rightHomologyIso.hom ≫ h.homologyIso.inv = S.rightHomologyIso.hom := by dsimp only [homologyIso] simp only [Iso.trans_inv, Iso.symm_inv, Iso.hom_inv_id_assoc] @[reassoc] lemma comp_homologyMap_comp [S₁.HasHomology] [S₂.HasHomology] (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.RightHomologyData) : h₁.π ≫ h₁.homologyIso.inv ≫ homologyMap φ ≫ h₂.homologyIso.hom ≫ h₂.ι = h₁.i ≫ φ.τ₂ ≫ h₂.p := by dsimp only [LeftHomologyData.homologyIso, RightHomologyData.homologyIso, Iso.symm, Iso.trans, Iso.refl, leftHomologyIso, rightHomologyIso, leftHomologyMapIso', rightHomologyMapIso', LeftHomologyData.cyclesIso, RightHomologyData.opcyclesIso, LeftHomologyData.leftHomologyIso, RightHomologyData.rightHomologyIso, homologyMap, homologyMap'] simp only [assoc, rightHomologyι_naturality', rightHomologyι_naturality'_assoc, leftHomologyπ_naturality'_assoc, HomologyData.comm_assoc, p_opcyclesMap'_assoc, id_τ₂, p_opcyclesMap', id_comp, cyclesMap'_i_assoc] @[reassoc] lemma π_homologyMap_ι [S₁.HasHomology] [S₂.HasHomology] (φ : S₁ ⟶ S₂) : S₁.homologyπ ≫ homologyMap φ ≫ S₂.homologyι = S₁.iCycles ≫ φ.τ₂ ≫ S₂.pOpcycles := by simp only [homologyι_naturality, homology_π_ι_assoc, p_opcyclesMap] end variable (S) /-- The canonical isomorphism `S.op.homology ≅ Opposite.op S.homology` when a short complex `S` has homology. -/ noncomputable def homologyOpIso [S.HasHomology] : S.op.homology ≅ Opposite.op S.homology := S.op.leftHomologyIso.symm ≪≫ S.leftHomologyOpIso ≪≫ S.rightHomologyIso.symm.op lemma homologyMap'_op : (homologyMap' φ h₁ h₂).op = h₂.iso.inv.op ≫ homologyMap' (opMap φ) h₂.op h₁.op ≫ h₁.iso.hom.op := Quiver.Hom.unop_inj (by dsimp have γ : HomologyMapData φ h₁ h₂ := default simp only [γ.homologyMap'_eq, γ.op.homologyMap'_eq, HomologyData.op_left, HomologyMapData.op_left, RightHomologyMapData.op_φH, Quiver.Hom.unop_op, assoc, ← γ.comm_assoc, Iso.hom_inv_id, comp_id]) lemma homologyMap_op [HasHomology S₁] [HasHomology S₂] : (homologyMap φ).op = (S₂.homologyOpIso).inv ≫ homologyMap (opMap φ) ≫ (S₁.homologyOpIso).hom := by dsimp only [homologyMap, homologyOpIso] rw [homologyMap'_op] dsimp only [Iso.symm, Iso.trans, Iso.op, Iso.refl, rightHomologyIso, leftHomologyIso, leftHomologyOpIso, leftHomologyMapIso', rightHomologyMapIso', LeftHomologyData.leftHomologyIso, homologyMap'] simp only [assoc, rightHomologyMap'_op, op_comp, ← leftHomologyMap'_comp_assoc, id_comp, opMap_id, comp_id, HomologyData.op_left] @[reassoc] lemma homologyOpIso_hom_naturality [S₁.HasHomology] [S₂.HasHomology] : homologyMap (opMap φ) ≫ (S₁.homologyOpIso).hom = S₂.homologyOpIso.hom ≫ (homologyMap φ).op := by simp [homologyMap_op] @[reassoc] lemma homologyOpIso_inv_naturality [S₁.HasHomology] [S₂.HasHomology] : (homologyMap φ).op ≫ (S₁.homologyOpIso).inv = S₂.homologyOpIso.inv ≫ homologyMap (opMap φ) := by simp [homologyMap_op] variable (C) /-- The natural isomorphism `(homologyFunctor C).op ≅ opFunctor C ⋙ homologyFunctor Cᵒᵖ` which relates the homology in `C` and in `Cᵒᵖ`. -/ noncomputable def homologyFunctorOpNatIso [CategoryWithHomology C] : (homologyFunctor C).op ≅ opFunctor C ⋙ homologyFunctor Cᵒᵖ := NatIso.ofComponents (fun S => S.unop.homologyOpIso.symm) (fun _ ↦ homologyOpIso_inv_naturality _) variable {C} {A : C} lemma liftCycles_homologyπ_eq_zero_of_boundary [S.HasHomology] (k : A ⟶ S.X₂) (x : A ⟶ S.X₁) (hx : k = x ≫ S.f) : S.liftCycles k (by rw [hx, assoc, S.zero, comp_zero]) ≫ S.homologyπ = 0 := by dsimp only [homologyπ] rw [S.liftCycles_leftHomologyπ_eq_zero_of_boundary_assoc k x hx, zero_comp] @[reassoc] lemma homologyι_descOpcycles_eq_zero_of_boundary [S.HasHomology] (k : S.X₂ ⟶ A) (x : S.X₃ ⟶ A) (hx : k = S.g ≫ x) : S.homologyι ≫ S.descOpcycles k (by rw [hx, S.zero_assoc, zero_comp]) = 0 := by dsimp only [homologyι] rw [assoc, S.rightHomologyι_descOpcycles_π_eq_zero_of_boundary k x hx, comp_zero] lemma isIso_homologyMap_of_isIso_cyclesMap_of_epi {φ : S₁ ⟶ S₂} [S₁.HasHomology] [S₂.HasHomology] (h₁ : IsIso (cyclesMap φ)) (h₂ : Epi φ.τ₁) : IsIso (homologyMap φ) := by have h : S₂.toCycles ≫ inv (cyclesMap φ) ≫ S₁.homologyπ = 0 := by simp only [← cancel_epi φ.τ₁, ← toCycles_naturality_assoc, IsIso.hom_inv_id_assoc, toCycles_comp_homologyπ, comp_zero] have ⟨z, hz⟩ := CokernelCofork.IsColimit.desc' S₂.homologyIsCokernel _ h dsimp at hz refine ⟨⟨z, ?_, ?_⟩⟩ · rw [← cancel_epi S₁.homologyπ, homologyπ_naturality_assoc, hz, IsIso.hom_inv_id_assoc, comp_id] · rw [← cancel_epi S₂.homologyπ, reassoc_of% hz, homologyπ_naturality, IsIso.inv_hom_id_assoc, comp_id] lemma isIso_homologyMap_of_isIso_opcyclesMap_of_mono {φ : S₁ ⟶ S₂} [S₁.HasHomology] [S₂.HasHomology] (h₁ : IsIso (opcyclesMap φ)) (h₂ : Mono φ.τ₃) : IsIso (homologyMap φ) := by have h : (S₂.homologyι ≫ inv (opcyclesMap φ)) ≫ S₁.fromOpcycles = 0 := by simp only [← cancel_mono φ.τ₃, zero_comp, assoc, ← fromOpcycles_naturality, IsIso.inv_hom_id_assoc, homologyι_comp_fromOpcycles] have ⟨z, hz⟩ := KernelFork.IsLimit.lift' S₁.homologyIsKernel _ h dsimp at hz refine ⟨⟨z, ?_, ?_⟩⟩ · rw [← cancel_mono S₁.homologyι, id_comp, assoc, hz, homologyι_naturality_assoc, IsIso.hom_inv_id, comp_id] · rw [← cancel_mono S₂.homologyι, assoc, homologyι_naturality, reassoc_of% hz, IsIso.inv_hom_id, comp_id, id_comp] lemma isZero_homology_of_isZero_X₂ (hS : IsZero S.X₂) [S.HasHomology] : IsZero S.homology := IsZero.of_iso hS (HomologyData.ofZeros S (hS.eq_of_tgt _ _) (hS.eq_of_src _ _)).left.homologyIso lemma isIso_homologyπ (hf : S.f = 0) [S.HasHomology] : IsIso S.homologyπ := by have := S.isIso_leftHomologyπ hf dsimp only [homologyπ] infer_instance lemma isIso_homologyι (hg : S.g = 0) [S.HasHomology] : IsIso S.homologyι := by have := S.isIso_rightHomologyι hg dsimp only [homologyι] infer_instance /-- The canonical isomorphism `S.cycles ≅ S.homology` when `S.f = 0`. -/ @[simps! hom] noncomputable def asIsoHomologyπ (hf : S.f = 0) [S.HasHomology] : S.cycles ≅ S.homology := by have := S.isIso_homologyπ hf exact asIso S.homologyπ @[reassoc (attr := simp)] lemma asIsoHomologyπ_inv_comp_homologyπ (hf : S.f = 0) [S.HasHomology] : (S.asIsoHomologyπ hf).inv ≫ S.homologyπ = 𝟙 _ := Iso.inv_hom_id _ @[reassoc (attr := simp)] lemma homologyπ_comp_asIsoHomologyπ_inv (hf : S.f = 0) [S.HasHomology] : S.homologyπ ≫ (S.asIsoHomologyπ hf).inv = 𝟙 _ := (S.asIsoHomologyπ hf).hom_inv_id /-- The canonical isomorphism `S.homology ≅ S.opcycles` when `S.g = 0`. -/ @[simps! hom] noncomputable def asIsoHomologyι (hg : S.g = 0) [S.HasHomology] : S.homology ≅ S.opcycles := by have := S.isIso_homologyι hg exact asIso S.homologyι @[reassoc (attr := simp)] lemma asIsoHomologyι_inv_comp_homologyι (hg : S.g = 0) [S.HasHomology] : (S.asIsoHomologyι hg).inv ≫ S.homologyι = 𝟙 _ := Iso.inv_hom_id _ @[reassoc (attr := simp)] lemma homologyι_comp_asIsoHomologyι_inv (hg : S.g = 0) [S.HasHomology] : S.homologyι ≫ (S.asIsoHomologyι hg).inv = 𝟙 _ := (S.asIsoHomologyι hg).hom_inv_id lemma mono_homologyMap_of_mono_opcyclesMap' [S₁.HasHomology] [S₂.HasHomology] (h : Mono (opcyclesMap φ)) : Mono (homologyMap φ) := by have : Mono (homologyMap φ ≫ S₂.homologyι) := by rw [homologyι_naturality φ] apply mono_comp exact mono_of_mono (homologyMap φ) S₂.homologyι instance mono_homologyMap_of_mono_opcyclesMap [S₁.HasHomology] [S₂.HasHomology] [Mono (opcyclesMap φ)] : Mono (homologyMap φ) := mono_homologyMap_of_mono_opcyclesMap' φ inferInstance lemma epi_homologyMap_of_epi_cyclesMap' [S₁.HasHomology] [S₂.HasHomology] (h : Epi (cyclesMap φ)) : Epi (homologyMap φ) := by have : Epi (S₁.homologyπ ≫ homologyMap φ) := by rw [homologyπ_naturality φ] apply epi_comp exact epi_of_epi S₁.homologyπ (homologyMap φ) instance epi_homologyMap_of_epi_cyclesMap [S₁.HasHomology] [S₂.HasHomology] [Epi (cyclesMap φ)] : Epi (homologyMap φ) := epi_homologyMap_of_epi_cyclesMap' φ inferInstance /-- Given a short complex `S` such that `S.HasHomology`, this is the canonical left homology data for `S` whose `K` and `H` fields are respectively `S.cycles` and `S.homology`. -/ @[simps!] noncomputable def LeftHomologyData.canonical [S.HasHomology] : S.LeftHomologyData where K := S.cycles H := S.homology i := S.iCycles π := S.homologyπ wi := by simp hi := S.cyclesIsKernel wπ := S.toCycles_comp_homologyπ hπ := S.homologyIsCokernel /-- Computation of the `f'` field of `LeftHomologyData.canonical`. -/ @[simp] lemma LeftHomologyData.canonical_f' [S.HasHomology] : (LeftHomologyData.canonical S).f' = S.toCycles := rfl /-- Given a short complex `S` such that `S.HasHomology`, this is the canonical right homology data for `S` whose `Q` and `H` fields are respectively `S.opcycles` and `S.homology`. -/ @[simps!] noncomputable def RightHomologyData.canonical [S.HasHomology] : S.RightHomologyData where Q := S.opcycles H := S.homology p := S.pOpcycles ι := S.homologyι wp := by simp hp := S.opcyclesIsCokernel wι := S.homologyι_comp_fromOpcycles hι := S.homologyIsKernel /-- Computation of the `g'` field of `RightHomologyData.canonical`. -/ @[simp] lemma RightHomologyData.canonical_g' [S.HasHomology] : (RightHomologyData.canonical S).g' = S.fromOpcycles := rfl /-- Given a short complex `S` such that `S.HasHomology`, this is the canonical homology data for `S` whose `left.K`, `left/right.H` and `right.Q` fields are respectively `S.cycles`, `S.homology` and `S.opcycles`. -/ @[simps!] noncomputable def HomologyData.canonical [S.HasHomology] : S.HomologyData where left := LeftHomologyData.canonical S right := RightHomologyData.canonical S iso := Iso.refl _ end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/SnakeLemma.lean
import Mathlib.Algebra.Homology.ExactSequence import Mathlib.Algebra.Homology.ShortComplex.Limits import Mathlib.CategoryTheory.Abelian.Refinements /-! # The snake lemma The snake lemma is a standard tool in homological algebra. The basic situation is when we have a diagram as follows in an abelian category `C`, with exact rows: L₁.X₁ ⟶ L₁.X₂ ⟶ L₁.X₃ ⟶ 0 | | | |v₁₂.τ₁ |v₁₂.τ₂ |v₁₂.τ₃ v v v 0 ⟶ L₂.X₁ ⟶ L₂.X₂ ⟶ L₂.X₃ We shall think of this diagram as the datum of a morphism `v₁₂ : L₁ ⟶ L₂` in the category `ShortComplex C` such that both `L₁` and `L₂` are exact, and `L₁.g` is epi and `L₂.f` is a mono (which is equivalent to saying that `L₁.X₃` is the cokernel of `L₁.f` and `L₂.X₁` is the kernel of `L₂.g`). Then, we may introduce the kernels and cokernels of the vertical maps. In other words, we may introduce short complexes `L₀` and `L₃` that are respectively the kernel and the cokernel of `v₁₂`. All these data constitute a `SnakeInput C`. Given such a `S : SnakeInput C`, we define a connecting homomorphism `S.δ : L₀.X₃ ⟶ L₃.X₁` and show that it is part of an exact sequence `L₀.X₁ ⟶ L₀.X₂ ⟶ L₀.X₃ ⟶ L₃.X₁ ⟶ L₃.X₂ ⟶ L₃.X₃`. Each of the four exactness statement is first stated separately as lemmas `L₀_exact`, `L₁'_exact`, `L₂'_exact` and `L₃_exact` and the full 6-term exact sequence is stated as `snake_lemma`. This sequence can even be extended with an extra `0` on the left (see `mono_L₀_f`) if `L₁.X₁ ⟶ L₁.X₂` is a mono (i.e. `L₁` is short exact), and similarly an extra `0` can be added on the right (`epi_L₃_g`) if `L₂.X₂ ⟶ L₂.X₃` is an epi (i.e. `L₂` is short exact). These results were also obtained in the Liquid Tensor Experiment. The code and the proof here are slightly easier because of the use of the category `ShortComplex C`, the use of duality (which allows to construct only half of the sequence, and deducing the other half by arguing in the opposite category), and the use of "refinements" (see `CategoryTheory.Abelian.Refinements`) instead of a weak form of pseudo-elements. -/ namespace CategoryTheory open Category Limits Preadditive variable (C : Type*) [Category C] [Abelian C] namespace ShortComplex /-- A snake input in an abelian category `C` consists of morphisms of short complexes `L₀ ⟶ L₁ ⟶ L₂ ⟶ L₃` (which should be visualized vertically) such that `L₀` and `L₃` are respectively the kernel and the cokernel of `L₁ ⟶ L₂`, `L₁` and `L₂` are exact, `L₁.g` is epi and `L₂.f` is mono. -/ structure SnakeInput where /-- the zeroth row -/ L₀ : ShortComplex C /-- the first row -/ L₁ : ShortComplex C /-- the second row -/ L₂ : ShortComplex C /-- the third row -/ L₃ : ShortComplex C /-- the morphism from the zeroth row to the first row -/ v₀₁ : L₀ ⟶ L₁ /-- the morphism from the first row to the second row -/ v₁₂ : L₁ ⟶ L₂ /-- the morphism from the second row to the third row -/ v₂₃ : L₂ ⟶ L₃ w₀₂ : v₀₁ ≫ v₁₂ = 0 := by cat_disch w₁₃ : v₁₂ ≫ v₂₃ = 0 := by cat_disch /-- `L₀` is the kernel of `v₁₂ : L₁ ⟶ L₂`. -/ h₀ : IsLimit (KernelFork.ofι _ w₀₂) /-- `L₃` is the cokernel of `v₁₂ : L₁ ⟶ L₂`. -/ h₃ : IsColimit (CokernelCofork.ofπ _ w₁₃) L₁_exact : L₁.Exact epi_L₁_g : Epi L₁.g L₂_exact : L₂.Exact mono_L₂_f : Mono L₂.f initialize_simps_projections SnakeInput (-h₀, -h₃) namespace SnakeInput attribute [reassoc (attr := simp)] w₀₂ w₁₃ attribute [instance] epi_L₁_g attribute [instance] mono_L₂_f variable {C} variable (S : SnakeInput C) /-- The snake input in the opposite category that is deduced from a snake input. -/ @[simps] noncomputable def op : SnakeInput Cᵒᵖ where L₀ := S.L₃.op L₁ := S.L₂.op L₂ := S.L₁.op L₃ := S.L₀.op epi_L₁_g := by dsimp; infer_instance mono_L₂_f := by dsimp; infer_instance v₀₁ := opMap S.v₂₃ v₁₂ := opMap S.v₁₂ v₂₃ := opMap S.v₀₁ w₀₂ := congr_arg opMap S.w₁₃ w₁₃ := congr_arg opMap S.w₀₂ h₀ := isLimitForkMapOfIsLimit' (ShortComplex.opEquiv C).functor _ (CokernelCofork.IsColimit.ofπOp _ _ S.h₃) h₃ := isColimitCoforkMapOfIsColimit' (ShortComplex.opEquiv C).functor _ (KernelFork.IsLimit.ofιOp _ _ S.h₀) L₁_exact := S.L₂_exact.op L₂_exact := S.L₁_exact.op @[reassoc (attr := simp)] lemma w₀₂_τ₁ : S.v₀₁.τ₁ ≫ S.v₁₂.τ₁ = 0 := by rw [← comp_τ₁, S.w₀₂, zero_τ₁] @[reassoc (attr := simp)] lemma w₀₂_τ₂ : S.v₀₁.τ₂ ≫ S.v₁₂.τ₂ = 0 := by rw [← comp_τ₂, S.w₀₂, zero_τ₂] @[reassoc (attr := simp)] lemma w₀₂_τ₃ : S.v₀₁.τ₃ ≫ S.v₁₂.τ₃ = 0 := by rw [← comp_τ₃, S.w₀₂, zero_τ₃] @[reassoc (attr := simp)] lemma w₁₃_τ₁ : S.v₁₂.τ₁ ≫ S.v₂₃.τ₁ = 0 := by rw [← comp_τ₁, S.w₁₃, zero_τ₁] @[reassoc (attr := simp)] lemma w₁₃_τ₂ : S.v₁₂.τ₂ ≫ S.v₂₃.τ₂ = 0 := by rw [← comp_τ₂, S.w₁₃, zero_τ₂] @[reassoc (attr := simp)] lemma w₁₃_τ₃ : S.v₁₂.τ₃ ≫ S.v₂₃.τ₃ = 0 := by rw [← comp_τ₃, S.w₁₃, zero_τ₃] /-- `L₀.X₁` is the kernel of `v₁₂.τ₁ : L₁.X₁ ⟶ L₂.X₁`. -/ noncomputable def h₀τ₁ : IsLimit (KernelFork.ofι S.v₀₁.τ₁ S.w₀₂_τ₁) := isLimitForkMapOfIsLimit' π₁ S.w₀₂ S.h₀ /-- `L₀.X₂` is the kernel of `v₁₂.τ₂ : L₁.X₂ ⟶ L₂.X₂`. -/ noncomputable def h₀τ₂ : IsLimit (KernelFork.ofι S.v₀₁.τ₂ S.w₀₂_τ₂) := isLimitForkMapOfIsLimit' π₂ S.w₀₂ S.h₀ /-- `L₀.X₃` is the kernel of `v₁₂.τ₃ : L₁.X₃ ⟶ L₂.X₃`. -/ noncomputable def h₀τ₃ : IsLimit (KernelFork.ofι S.v₀₁.τ₃ S.w₀₂_τ₃) := isLimitForkMapOfIsLimit' π₃ S.w₀₂ S.h₀ instance mono_v₀₁_τ₁ : Mono S.v₀₁.τ₁ := mono_of_isLimit_fork S.h₀τ₁ instance mono_v₀₁_τ₂ : Mono S.v₀₁.τ₂ := mono_of_isLimit_fork S.h₀τ₂ instance mono_v₀₁_τ₃ : Mono S.v₀₁.τ₃ := mono_of_isLimit_fork S.h₀τ₃ /-- The upper part of the first column of the snake diagram is exact. -/ lemma exact_C₁_up : (ShortComplex.mk S.v₀₁.τ₁ S.v₁₂.τ₁ (by rw [← comp_τ₁, S.w₀₂, zero_τ₁])).Exact := exact_of_f_is_kernel _ S.h₀τ₁ /-- The upper part of the second column of the snake diagram is exact. -/ lemma exact_C₂_up : (ShortComplex.mk S.v₀₁.τ₂ S.v₁₂.τ₂ (by rw [← comp_τ₂, S.w₀₂, zero_τ₂])).Exact := exact_of_f_is_kernel _ S.h₀τ₂ /-- The upper part of the third column of the snake diagram is exact. -/ lemma exact_C₃_up : (ShortComplex.mk S.v₀₁.τ₃ S.v₁₂.τ₃ (by rw [← comp_τ₃, S.w₀₂, zero_τ₃])).Exact := exact_of_f_is_kernel _ S.h₀τ₃ instance mono_L₀_f [Mono S.L₁.f] : Mono S.L₀.f := by have : Mono (S.L₀.f ≫ S.v₀₁.τ₂) := by rw [← S.v₀₁.comm₁₂] apply mono_comp exact mono_of_mono _ S.v₀₁.τ₂ /-- `L₃.X₁` is the cokernel of `v₁₂.τ₁ : L₁.X₁ ⟶ L₂.X₁`. -/ noncomputable def h₃τ₁ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₁ S.w₁₃_τ₁) := isColimitCoforkMapOfIsColimit' π₁ S.w₁₃ S.h₃ /-- `L₃.X₂` is the cokernel of `v₁₂.τ₂ : L₁.X₂ ⟶ L₂.X₂`. -/ noncomputable def h₃τ₂ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₂ S.w₁₃_τ₂) := isColimitCoforkMapOfIsColimit' π₂ S.w₁₃ S.h₃ /-- `L₃.X₃` is the cokernel of `v₁₂.τ₃ : L₁.X₃ ⟶ L₂.X₃`. -/ noncomputable def h₃τ₃ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₃ S.w₁₃_τ₃) := isColimitCoforkMapOfIsColimit' π₃ S.w₁₃ S.h₃ instance epi_v₂₃_τ₁ : Epi S.v₂₃.τ₁ := epi_of_isColimit_cofork S.h₃τ₁ instance epi_v₂₃_τ₂ : Epi S.v₂₃.τ₂ := epi_of_isColimit_cofork S.h₃τ₂ instance epi_v₂₃_τ₃ : Epi S.v₂₃.τ₃ := epi_of_isColimit_cofork S.h₃τ₃ /-- The lower part of the first column of the snake diagram is exact. -/ lemma exact_C₁_down : (ShortComplex.mk S.v₁₂.τ₁ S.v₂₃.τ₁ (by rw [← comp_τ₁, S.w₁₃, zero_τ₁])).Exact := exact_of_g_is_cokernel _ S.h₃τ₁ /-- The lower part of the second column of the snake diagram is exact. -/ lemma exact_C₂_down : (ShortComplex.mk S.v₁₂.τ₂ S.v₂₃.τ₂ (by rw [← comp_τ₂, S.w₁₃, zero_τ₂])).Exact := exact_of_g_is_cokernel _ S.h₃τ₂ /-- The lower part of the third column of the snake diagram is exact. -/ lemma exact_C₃_down : (ShortComplex.mk S.v₁₂.τ₃ S.v₂₃.τ₃ (by rw [← comp_τ₃, S.w₁₃, zero_τ₃])).Exact := exact_of_g_is_cokernel _ S.h₃τ₃ instance epi_L₃_g [Epi S.L₂.g] : Epi S.L₃.g := by have : Epi (S.v₂₃.τ₂ ≫ S.L₃.g) := by rw [S.v₂₃.comm₂₃] apply epi_comp exact epi_of_epi S.v₂₃.τ₂ _ lemma L₀_exact : S.L₀.Exact := by rw [ShortComplex.exact_iff_exact_up_to_refinements] intro A x₂ hx₂ obtain ⟨A₁, π₁, hπ₁, y₁, hy₁⟩ := S.L₁_exact.exact_up_to_refinements (x₂ ≫ S.v₀₁.τ₂) (by rw [assoc, S.v₀₁.comm₂₃, reassoc_of% hx₂, zero_comp]) have hy₁' : y₁ ≫ S.v₁₂.τ₁ = 0 := by simp only [← cancel_mono S.L₂.f, assoc, zero_comp, S.v₁₂.comm₁₂, ← reassoc_of% hy₁, w₀₂_τ₂, comp_zero] obtain ⟨x₁, hx₁⟩ : ∃ x₁, x₁ ≫ S.v₀₁.τ₁ = y₁ := ⟨_, S.exact_C₁_up.lift_f y₁ hy₁'⟩ refine ⟨A₁, π₁, hπ₁, x₁, ?_⟩ simp only [← cancel_mono S.v₀₁.τ₂, assoc, ← S.v₀₁.comm₁₂, reassoc_of% hx₁, hy₁] lemma L₃_exact : S.L₃.Exact := S.op.L₀_exact.unop /-- The fiber product of `L₁.X₂` and `L₀.X₃` over `L₁.X₃`. This is an auxiliary object in the construction of the morphism `δ : L₀.X₃ ⟶ L₃.X₁`. -/ noncomputable def P := pullback S.L₁.g S.v₀₁.τ₃ /-- The canonical map `P ⟶ L₂.X₂`. -/ noncomputable def φ₂ : S.P ⟶ S.L₂.X₂ := pullback.fst _ _ ≫ S.v₁₂.τ₂ @[reassoc (attr := simp)] lemma lift_φ₂ {A : C} (a : A ⟶ S.L₁.X₂) (b : A ⟶ S.L₀.X₃) (h : a ≫ S.L₁.g = b ≫ S.v₀₁.τ₃) : pullback.lift a b h ≫ S.φ₂ = a ≫ S.v₁₂.τ₂ := by simp [φ₂] /-- The canonical map `P ⟶ L₂.X₁`. -/ noncomputable def φ₁ : S.P ⟶ S.L₂.X₁ := S.L₂_exact.lift S.φ₂ (by simp only [φ₂, assoc, S.v₁₂.comm₂₃, pullback.condition_assoc, w₀₂_τ₃, comp_zero]) @[reassoc (attr := simp)] lemma φ₁_L₂_f : S.φ₁ ≫ S.L₂.f = S.φ₂ := S.L₂_exact.lift_f _ _ /-- The short complex that is part of an exact sequence `L₁.X₁ ⟶ P ⟶ L₀.X₃ ⟶ 0`. -/ noncomputable def L₀' : ShortComplex C where X₁ := S.L₁.X₁ X₂ := S.P X₃ := S.L₀.X₃ f := pullback.lift S.L₁.f 0 (by simp) g := pullback.snd _ _ zero := by simp @[reassoc (attr := simp)] lemma L₁_f_φ₁ : S.L₀'.f ≫ S.φ₁ = S.v₁₂.τ₁ := by dsimp only [L₀'] simp only [← cancel_mono S.L₂.f, assoc, φ₁_L₂_f, φ₂, pullback.lift_fst_assoc, S.v₁₂.comm₁₂] instance : Epi S.L₀'.g := by dsimp only [L₀']; infer_instance instance [Mono S.L₁.f] : Mono S.L₀'.f := mono_of_mono_fac (show S.L₀'.f ≫ pullback.fst _ _ = S.L₁.f by simp [L₀']) lemma L₀'_exact : S.L₀'.Exact := by rw [ShortComplex.exact_iff_exact_up_to_refinements] intro A x₂ hx₂ dsimp [L₀'] at x₂ hx₂ obtain ⟨A', π, hπ, x₁, fac⟩ := S.L₁_exact.exact_up_to_refinements (x₂ ≫ pullback.fst _ _) (by rw [assoc, pullback.condition, reassoc_of% hx₂, zero_comp]) exact ⟨A', π, hπ, x₁, pullback.hom_ext (by simpa [L₀'] using fac) (by simp [L₀', hx₂])⟩ /-- The connecting homomorphism `δ : L₀.X₃ ⟶ L₃.X₁`. -/ noncomputable def δ : S.L₀.X₃ ⟶ S.L₃.X₁ := S.L₀'_exact.desc (S.φ₁ ≫ S.v₂₃.τ₁) (by simp only [L₁_f_φ₁_assoc, w₁₃_τ₁]) @[reassoc (attr := simp)] lemma snd_δ : (pullback.snd _ _ : S.P ⟶ _) ≫ S.δ = S.φ₁ ≫ S.v₂₃.τ₁ := S.L₀'_exact.g_desc _ _ /-- The pushout of `L₂.X₂` and `L₃.X₁` along `L₂.X₁`. -/ noncomputable def P' := pushout S.L₂.f S.v₂₃.τ₁ lemma snd_δ_inr : (pullback.snd _ _ : S.P ⟶ _) ≫ S.δ ≫ (pushout.inr _ _ : _ ⟶ S.P') = pullback.fst _ _ ≫ S.v₁₂.τ₂ ≫ pushout.inl _ _ := by simp only [snd_δ_assoc, ← pushout.condition, φ₂, φ₁_L₂_f_assoc, assoc] /-- The canonical morphism `L₀.X₂ ⟶ P`. -/ @[simp] noncomputable def L₀X₂ToP : S.L₀.X₂ ⟶ S.P := pullback.lift S.v₀₁.τ₂ S.L₀.g S.v₀₁.comm₂₃ @[reassoc] lemma L₀X₂ToP_comp_pullback_snd : S.L₀X₂ToP ≫ pullback.snd _ _ = S.L₀.g := by simp @[reassoc] lemma L₀X₂ToP_comp_φ₁ : S.L₀X₂ToP ≫ S.φ₁ = 0 := by simp only [← cancel_mono S.L₂.f, L₀X₂ToP, assoc, φ₂, φ₁_L₂_f, pullback.lift_fst_assoc, w₀₂_τ₂, zero_comp] lemma L₀_g_δ : S.L₀.g ≫ S.δ = 0 := by rw [← L₀X₂ToP_comp_pullback_snd, assoc] erw [S.L₀'_exact.g_desc] rw [L₀X₂ToP_comp_φ₁_assoc, zero_comp] lemma δ_L₃_f : S.δ ≫ S.L₃.f = 0 := by rw [← cancel_epi S.L₀'.g] erw [S.L₀'_exact.g_desc_assoc] simp [S.v₂₃.comm₁₂, φ₂] /-- The short complex `L₀.X₂ ⟶ L₀.X₃ ⟶ L₃.X₁`. -/ @[simps] noncomputable def L₁' : ShortComplex C := ShortComplex.mk _ _ S.L₀_g_δ /-- The short complex `L₀.X₃ ⟶ L₃.X₁ ⟶ L₃.X₂`. -/ @[simps] noncomputable def L₂' : ShortComplex C := ShortComplex.mk _ _ S.δ_L₃_f /-- Exactness of `L₀.X₂ ⟶ L₀.X₃ ⟶ L₃.X₁`. -/ lemma L₁'_exact : S.L₁'.Exact := by rw [ShortComplex.exact_iff_exact_up_to_refinements] intro A₀ x₃ hx₃ dsimp at x₃ hx₃ obtain ⟨A₁, π₁, hπ₁, p, hp⟩ := surjective_up_to_refinements_of_epi S.L₀'.g x₃ dsimp [L₀'] at p hp have hp' : (p ≫ S.φ₁) ≫ S.v₂₃.τ₁ = 0 := by rw [assoc, ← S.snd_δ, ← reassoc_of% hp, hx₃, comp_zero] obtain ⟨A₂, π₂, hπ₂, x₁, hx₁⟩ := S.exact_C₁_down.exact_up_to_refinements (p ≫ S.φ₁) hp' dsimp at x₁ hx₁ let x₂' := x₁ ≫ S.L₁.f let x₂ := π₂ ≫ p ≫ pullback.fst _ _ have hx₂' : (x₂ - x₂') ≫ S.v₁₂.τ₂ = 0 := by simp only [x₂, x₂', sub_comp, assoc, ← S.v₁₂.comm₁₂, ← reassoc_of% hx₁, φ₂, φ₁_L₂_f, sub_self] let k₂ : A₂ ⟶ S.L₀.X₂ := S.exact_C₂_up.lift _ hx₂' have hk₂ : k₂ ≫ S.v₀₁.τ₂ = x₂ - x₂' := S.exact_C₂_up.lift_f _ _ have hk₂' : k₂ ≫ S.L₀.g = π₂ ≫ p ≫ pullback.snd _ _ := by simp only [x₂, x₂', ← cancel_mono S.v₀₁.τ₃, assoc, ← S.v₀₁.comm₂₃, reassoc_of% hk₂, sub_comp, S.L₁.zero, comp_zero, sub_zero, pullback.condition] exact ⟨A₂, π₂ ≫ π₁, epi_comp _ _, k₂, by simp only [assoc, L₁'_f, ← hk₂', hp]⟩ /-- The duality isomorphism `S.P ≅ Opposite.unop S.op.P'`. -/ noncomputable def PIsoUnopOpP' : S.P ≅ Opposite.unop S.op.P' := pullbackIsoUnopPushout _ _ /-- The duality isomorphism `S.P' ≅ Opposite.unop S.op.P`. -/ noncomputable def P'IsoUnopOpP : S.P' ≅ Opposite.unop S.op.P := pushoutIsoUnopPullback _ _ lemma op_δ : S.op.δ = S.δ.op := Quiver.Hom.unop_inj (by rw [Quiver.Hom.unop_op, ← cancel_mono (pushout.inr _ _ : _ ⟶ S.P'), ← cancel_epi (pullback.snd _ _ : S.P ⟶ _), S.snd_δ_inr, ← cancel_mono S.P'IsoUnopOpP.hom, ← cancel_epi S.PIsoUnopOpP'.inv, P'IsoUnopOpP, PIsoUnopOpP', assoc, assoc, assoc, assoc, pushoutIsoUnopPullback_inr_hom, pullbackIsoUnopPushout_inv_snd_assoc, pushoutIsoUnopPullback_inl_hom, pullbackIsoUnopPushout_inv_fst_assoc] apply Quiver.Hom.op_inj simpa only [op_comp, Quiver.Hom.op_unop, assoc] using S.op.snd_δ_inr) /-- The duality isomorphism `S.L₂'.op ≅ S.op.L₁'`. -/ noncomputable def L₂'OpIso : S.L₂'.op ≅ S.op.L₁' := ShortComplex.isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _) (by simp) (by dsimp; simp only [id_comp, comp_id, S.op_δ]) /-- Exactness of `L₀.X₃ ⟶ L₃.X₁ ⟶ L₃.X₂`. -/ lemma L₂'_exact : S.L₂'.Exact := by rw [← exact_op_iff, exact_iff_of_iso S.L₂'OpIso] exact S.op.L₁'_exact /-- The diagram `S.L₀.X₁ ⟶ S.L₀.X₂ ⟶ S.L₀.X₃ ⟶ S.L₃.X₁ ⟶ S.L₃.X₂ ⟶ S.L₃.X₃` for any `S : SnakeInput C`. -/ noncomputable abbrev composableArrows : ComposableArrows C 5 := ComposableArrows.mk₅ S.L₀.f S.L₀.g S.δ S.L₃.f S.L₃.g open ComposableArrows in /-- The diagram `S.L₀.X₁ ⟶ S.L₀.X₂ ⟶ S.L₀.X₃ ⟶ S.L₃.X₁ ⟶ S.L₃.X₂ ⟶ S.L₃.X₃` is exact for any `S : SnakeInput C`. -/ lemma snake_lemma : S.composableArrows.Exact := exact_of_δ₀ S.L₀_exact.exact_toComposableArrows (exact_of_δ₀ S.L₁'_exact.exact_toComposableArrows (exact_of_δ₀ S.L₂'_exact.exact_toComposableArrows S.L₃_exact.exact_toComposableArrows)) lemma δ_eq {A : C} (x₃ : A ⟶ S.L₀.X₃) (x₂ : A ⟶ S.L₁.X₂) (x₁ : A ⟶ S.L₂.X₁) (h₂ : x₂ ≫ S.L₁.g = x₃ ≫ S.v₀₁.τ₃) (h₁ : x₁ ≫ S.L₂.f = x₂ ≫ S.v₁₂.τ₂) : x₃ ≫ S.δ = x₁ ≫ S.v₂₃.τ₁ := by have H := (pullback.lift x₂ x₃ h₂) ≫= S.snd_δ rw [pullback.lift_snd_assoc] at H rw [H, ← assoc] congr 1 simp only [← cancel_mono S.L₂.f, assoc, φ₁_L₂_f, lift_φ₂, h₁] theorem mono_δ (h₀ : IsZero S.L₀.X₂) : Mono S.δ := (S.L₁'.exact_iff_mono (IsZero.eq_zero_of_src h₀ S.L₁'.f)).1 S.L₁'_exact theorem epi_δ (h₃ : IsZero S.L₃.X₂) : Epi S.δ := (S.L₂'.exact_iff_epi (IsZero.eq_zero_of_tgt h₃ S.L₂'.g)).1 S.L₂'_exact theorem isIso_δ (h₀ : IsZero S.L₀.X₂) (h₃ : IsZero S.L₃.X₂) : IsIso S.δ := @Balanced.isIso_of_mono_of_epi _ _ _ _ _ S.δ (S.mono_δ h₀) (S.epi_δ h₃) /-- When `L₀₂` and `L₃₂` are trivial, `δ` defines an isomorphism `L₀₃ ≅ L₃₁`. -/ noncomputable def δIso (h₀ : IsZero S.L₀.X₂) (h₃ : IsZero S.L₃.X₂) : S.L₀.X₃ ≅ S.L₃.X₁ := @asIso _ _ _ _ S.δ (SnakeInput.isIso_δ S h₀ h₃) variable (S₁ S₂ S₃ : SnakeInput C) /-- A morphism of snake inputs involve four morphisms of short complexes which make the obvious diagram commute. -/ @[ext] structure Hom where /-- a morphism between the zeroth lines -/ f₀ : S₁.L₀ ⟶ S₂.L₀ /-- a morphism between the first lines -/ f₁ : S₁.L₁ ⟶ S₂.L₁ /-- a morphism between the second lines -/ f₂ : S₁.L₂ ⟶ S₂.L₂ /-- a morphism between the third lines -/ f₃ : S₁.L₃ ⟶ S₂.L₃ comm₀₁ : f₀ ≫ S₂.v₀₁ = S₁.v₀₁ ≫ f₁ := by cat_disch comm₁₂ : f₁ ≫ S₂.v₁₂ = S₁.v₁₂ ≫ f₂ := by cat_disch comm₂₃ : f₂ ≫ S₂.v₂₃ = S₁.v₂₃ ≫ f₃ := by cat_disch namespace Hom attribute [reassoc] comm₀₁ comm₁₂ comm₂₃ /-- The identity morphism of a snake input. -/ @[simps] def id : Hom S S where f₀ := 𝟙 _ f₁ := 𝟙 _ f₂ := 𝟙 _ f₃ := 𝟙 _ variable {S₁ S₂ S₃} /-- The composition of morphisms of snake inputs. -/ @[simps] def comp (f : Hom S₁ S₂) (g : Hom S₂ S₃) : Hom S₁ S₃ where f₀ := f.f₀ ≫ g.f₀ f₁ := f.f₁ ≫ g.f₁ f₂ := f.f₂ ≫ g.f₂ f₃ := f.f₃ ≫ g.f₃ comm₀₁ := by simp only [assoc, comm₀₁, comm₀₁_assoc] comm₁₂ := by simp only [assoc, comm₁₂, comm₁₂_assoc] comm₂₃ := by simp only [assoc, comm₂₃, comm₂₃_assoc] end Hom instance : Category (SnakeInput C) where Hom := Hom id := Hom.id comp := Hom.comp variable {S₁ S₂ S₃} @[simp] lemma id_f₀ : Hom.f₀ (𝟙 S) = 𝟙 _ := rfl @[simp] lemma id_f₁ : Hom.f₁ (𝟙 S) = 𝟙 _ := rfl @[simp] lemma id_f₂ : Hom.f₂ (𝟙 S) = 𝟙 _ := rfl @[simp] lemma id_f₃ : Hom.f₃ (𝟙 S) = 𝟙 _ := rfl section variable (f : S₁ ⟶ S₂) (g : S₂ ⟶ S₃) @[simp, reassoc] lemma comp_f₀ : (f ≫ g).f₀ = f.f₀ ≫ g.f₀ := rfl @[simp, reassoc] lemma comp_f₁ : (f ≫ g).f₁ = f.f₁ ≫ g.f₁ := rfl @[simp, reassoc] lemma comp_f₂ : (f ≫ g).f₂ = f.f₂ ≫ g.f₂ := rfl @[simp, reassoc] lemma comp_f₃ : (f ≫ g).f₃ = f.f₃ ≫ g.f₃ := rfl end /-- The functor which sends `S : SnakeInput C` to its zeroth line `S.L₀`. -/ @[simps] def functorL₀ : SnakeInput C ⥤ ShortComplex C where obj S := S.L₀ map f := f.f₀ /-- The functor which sends `S : SnakeInput C` to its zeroth line `S.L₁`. -/ @[simps] def functorL₁ : SnakeInput C ⥤ ShortComplex C where obj S := S.L₁ map f := f.f₁ /-- The functor which sends `S : SnakeInput C` to its second line `S.L₂`. -/ @[simps] def functorL₂ : SnakeInput C ⥤ ShortComplex C where obj S := S.L₂ map f := f.f₂ /-- The functor which sends `S : SnakeInput C` to its third line `S.L₃`. -/ @[simps] def functorL₃ : SnakeInput C ⥤ ShortComplex C where obj S := S.L₃ map f := f.f₃ /-- The functor which sends `S : SnakeInput C` to the auxiliary object `S.P`, which is `pullback S.L₁.g S.v₀₁.τ₃`. -/ @[simps] noncomputable def functorP : SnakeInput C ⥤ C where obj S := S.P map f := pullback.map _ _ _ _ f.f₁.τ₂ f.f₀.τ₃ f.f₁.τ₃ f.f₁.comm₂₃.symm (congr_arg ShortComplex.Hom.τ₃ f.comm₀₁.symm) map_id _ := by dsimp [P]; simp map_comp _ _ := by dsimp [P]; cat_disch @[reassoc] lemma naturality_φ₂ (f : S₁ ⟶ S₂) : S₁.φ₂ ≫ f.f₂.τ₂ = functorP.map f ≫ S₂.φ₂ := by dsimp [φ₂] simp only [assoc, pullback.lift_fst_assoc, ← comp_τ₂, f.comm₁₂] @[reassoc] lemma naturality_φ₁ (f : S₁ ⟶ S₂) : S₁.φ₁ ≫ f.f₂.τ₁ = functorP.map f ≫ S₂.φ₁ := by simp only [← cancel_mono S₂.L₂.f, assoc, φ₁_L₂_f, ← naturality_φ₂, f.f₂.comm₁₂, φ₁_L₂_f_assoc] @[reassoc] lemma naturality_δ (f : S₁ ⟶ S₂) : S₁.δ ≫ f.f₃.τ₁ = f.f₀.τ₃ ≫ S₂.δ := by rw [← cancel_epi (pullback.snd _ _ : S₁.P ⟶ _), S₁.snd_δ_assoc, ← comp_τ₁, ← f.comm₂₃, comp_τ₁, naturality_φ₁_assoc, ← S₂.snd_δ, functorP_map, pullback.lift_snd_assoc, assoc] /-- The functor which sends `S : SnakeInput C` to `S.L₁'` which is `S.L₀.X₂ ⟶ S.L₀.X₃ ⟶ S.L₃.X₁`. -/ @[simps] noncomputable def functorL₁' : SnakeInput C ⥤ ShortComplex C where obj S := S.L₁' map f := { τ₁ := f.f₀.τ₂ τ₂ := f.f₀.τ₃ τ₃ := f.f₃.τ₁ comm₁₂ := f.f₀.comm₂₃ comm₂₃ := (naturality_δ f).symm } /-- The functor which sends `S : SnakeInput C` to `S.L₂'` which is `S.L₀.X₃ ⟶ S.L₃.X₁ ⟶ S.L₃.X₂`. -/ @[simps] noncomputable def functorL₂' : SnakeInput C ⥤ ShortComplex C where obj S := S.L₂' map f := { τ₁ := f.f₀.τ₃ τ₂ := f.f₃.τ₁ τ₃ := f.f₃.τ₂ comm₁₂ := (naturality_δ f).symm comm₂₃ := f.f₃.comm₁₂ } /-- The functor which maps `S : SnakeInput C` to the diagram `S.L₀.X₁ ⟶ S.L₀.X₂ ⟶ S.L₀.X₃ ⟶ S.L₃.X₁ ⟶ S.L₃.X₂ ⟶ S.L₃.X₃`. -/ @[simps] noncomputable def composableArrowsFunctor : SnakeInput C ⥤ ComposableArrows C 5 where obj S := S.composableArrows map f := ComposableArrows.homMk₅ f.f₀.τ₁ f.f₀.τ₂ f.f₀.τ₃ f.f₃.τ₁ f.f₃.τ₂ f.f₃.τ₃ f.f₀.comm₁₂.symm f.f₀.comm₂₃.symm (naturality_δ f) f.f₃.comm₁₂.symm f.f₃.comm₂₃.symm end SnakeInput end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/ConcreteCategory.lean
import Mathlib.Algebra.Homology.ShortComplex.Ab import Mathlib.Algebra.Homology.ShortComplex.ExactFunctor import Mathlib.Algebra.Homology.ShortComplex.SnakeLemma import Mathlib.CategoryTheory.Limits.Shapes.ConcreteCategory /-! # Exactness of short complexes in concrete abelian categories If an additive concrete category `C` has an additive forgetful functor to `Ab` which preserves homology, then a short complex `S` in `C` is exact if and only if it is so after applying the functor `forget₂ C Ab`. -/ universe w v u namespace CategoryTheory open Limits section variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] [HasForget₂ C Ab] @[simp] lemma ShortComplex.zero_apply [Limits.HasZeroMorphisms C] [(forget₂ C Ab).PreservesZeroMorphisms] (S : ShortComplex C) (x : (forget₂ C Ab).obj S.X₁) : ((forget₂ C Ab).map S.g) (((forget₂ C Ab).map S.f) x) = 0 := by rw [← ConcreteCategory.comp_apply, ← Functor.map_comp, S.zero, Functor.map_zero] rfl section preadditive variable [Preadditive C] [(forget₂ C Ab).Additive] [(forget₂ C Ab).PreservesHomology] (S : ShortComplex C) section variable [HasZeroObject C] lemma Preadditive.mono_iff_injective {X Y : C} (f : X ⟶ Y) : Mono f ↔ Function.Injective ((forget₂ C Ab).map f) := by rw [← AddCommGrpCat.mono_iff_injective] constructor · intro infer_instance · apply Functor.mono_of_mono_map lemma Preadditive.mono_iff_injective' {X Y : C} (f : X ⟶ Y) : Mono f ↔ Function.Injective f := by simp only [mono_iff_injective, ← CategoryTheory.mono_iff_injective] apply (MorphismProperty.monomorphisms (Type w)).arrow_mk_iso_iff have e : forget₂ C Ab ⋙ forget Ab ≅ forget C := eqToIso (HasForget₂.forget_comp) exact Arrow.isoOfNatIso e (Arrow.mk f) lemma Preadditive.epi_iff_surjective {X Y : C} (f : X ⟶ Y) : Epi f ↔ Function.Surjective ((forget₂ C Ab).map f) := by rw [← AddCommGrpCat.epi_iff_surjective] constructor · intro infer_instance · apply Functor.epi_of_epi_map lemma Preadditive.epi_iff_surjective' {X Y : C} (f : X ⟶ Y) : Epi f ↔ Function.Surjective f := by simp only [epi_iff_surjective, ← CategoryTheory.epi_iff_surjective] apply (MorphismProperty.epimorphisms (Type w)).arrow_mk_iso_iff have e : forget₂ C Ab ⋙ forget Ab ≅ forget C := eqToIso (HasForget₂.forget_comp) exact Arrow.isoOfNatIso e (Arrow.mk f) end namespace ShortComplex lemma exact_iff_exact_map_forget₂ [S.HasHomology] : S.Exact ↔ (S.map (forget₂ C Ab)).Exact := (S.exact_map_iff_of_faithful (forget₂ C Ab)).symm lemma exact_iff_of_hasForget [S.HasHomology] : S.Exact ↔ ∀ (x₂ : (forget₂ C Ab).obj S.X₂) (_ : ((forget₂ C Ab).map S.g) x₂ = 0), ∃ (x₁ : (forget₂ C Ab).obj S.X₁), ((forget₂ C Ab).map S.f) x₁ = x₂ := by rw [S.exact_iff_exact_map_forget₂, ab_exact_iff] rfl variable {S} lemma ShortExact.injective_f [HasZeroObject C] (hS : S.ShortExact) : Function.Injective ((forget₂ C Ab).map S.f) := by rw [← Preadditive.mono_iff_injective] exact hS.mono_f lemma ShortExact.surjective_g [HasZeroObject C] (hS : S.ShortExact) : Function.Surjective ((forget₂ C Ab).map S.g) := by rw [← Preadditive.epi_iff_surjective] exact hS.epi_g variable (S) /-- Constructor for cycles of short complexes in a concrete category. -/ noncomputable def cyclesMk [S.HasHomology] (x₂ : (forget₂ C Ab).obj S.X₂) (hx₂ : ((forget₂ C Ab).map S.g) x₂ = 0) : (forget₂ C Ab).obj S.cycles := (S.mapCyclesIso (forget₂ C Ab)).hom ((ShortComplex.abCyclesIso _).inv ⟨x₂, hx₂⟩) @[simp] lemma i_cyclesMk [S.HasHomology] (x₂ : (forget₂ C Ab).obj S.X₂) (hx₂ : ((forget₂ C Ab).map S.g) x₂ = 0) : (forget₂ C Ab).map S.iCycles (S.cyclesMk x₂ hx₂) = x₂ := by dsimp [cyclesMk] -- `abCyclesIso_inv_apply_iCycles` is not in `simp`-normal form, so we first -- have to simplify it. have := abCyclesIso_inv_apply_iCycles (S.map (forget₂ C Ab)) ⟨x₂, hx₂⟩ simp only [map_X₂, map_X₃, map_g] at this rw [← ConcreteCategory.comp_apply, S.mapCyclesIso_hom_iCycles (forget₂ C Ab), this] end ShortComplex end preadditive end section abelian variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type v} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{v} C FC] [HasForget₂ C Ab] [Abelian C] [(forget₂ C Ab).Additive] [(forget₂ C Ab).PreservesHomology] namespace ShortComplex namespace SnakeInput variable (D : SnakeInput C) /-- This lemma allows the computation of the connecting homomorphism `D.δ` when `D : SnakeInput C` and `C` is a concrete category. -/ lemma δ_apply (x₃ : ToType (D.L₀.X₃)) (x₂ : ToType (D.L₁.X₂)) (x₁ : ToType (D.L₂.X₁)) (h₂ : D.L₁.g x₂ = D.v₀₁.τ₃ x₃) (h₁ : D.L₂.f x₁ = D.v₁₂.τ₂ x₂) : D.δ x₃ = D.v₂₃.τ₁ x₁ := by have := (forget₂ C Ab).preservesFiniteLimits_of_preservesHomology have : PreservesFiniteLimits (forget C) := by have : forget₂ C Ab ⋙ forget Ab = forget C := HasForget₂.forget_comp simpa only [← this] using comp_preservesFiniteLimits _ _ have eq := CategoryTheory.congr_fun (D.snd_δ) (Limits.Concrete.pullbackMk D.L₁.g D.v₀₁.τ₃ x₂ x₃ h₂) have eq₁ := Concrete.pullbackMk_fst D.L₁.g D.v₀₁.τ₃ x₂ x₃ h₂ have eq₂ := Concrete.pullbackMk_snd D.L₁.g D.v₀₁.τ₃ x₂ x₃ h₂ rw [ConcreteCategory.comp_apply, ConcreteCategory.comp_apply] at eq rw [eq₂] at eq refine eq.trans (CategoryTheory.congr_arg (D.v₂₃.τ₁) ?_) apply (Preadditive.mono_iff_injective' D.L₂.f).1 inferInstance rw [← ConcreteCategory.comp_apply, φ₁_L₂_f] dsimp [φ₂] rw [ConcreteCategory.comp_apply, eq₁] exact h₁.symm /-- This lemma allows the computation of the connecting homomorphism `D.δ` when `D : SnakeInput C` and `C` is a concrete category. -/ lemma δ_apply' (x₃ : (forget₂ C Ab).obj D.L₀.X₃) (x₂ : (forget₂ C Ab).obj D.L₁.X₂) (x₁ : (forget₂ C Ab).obj D.L₂.X₁) (h₂ : (forget₂ C Ab).map D.L₁.g x₂ = (forget₂ C Ab).map D.v₀₁.τ₃ x₃) (h₁ : (forget₂ C Ab).map D.L₂.f x₁ = (forget₂ C Ab).map D.v₁₂.τ₂ x₂) : (forget₂ C Ab).map D.δ x₃ = (forget₂ C Ab).map D.v₂₃.τ₁ x₁ := by have e : forget₂ C Ab ⋙ forget Ab ≅ forget C := eqToIso (HasForget₂.forget_comp) apply (mono_iff_injective (e.hom.app _)).1 inferInstance refine (congr_hom (e.hom.naturality D.δ) x₃).trans ((D.δ_apply (e.hom.app _ x₃) (e.hom.app _ x₂) (e.hom.app _ x₁) ?_ ?_ ).trans (congr_hom (e.hom.naturality D.v₂₃.τ₁).symm x₁)) · refine ((congr_fun (e.hom.naturality D.L₁.g) x₂).symm.trans ?_).trans (congr_fun (e.hom.naturality D.v₀₁.τ₃) x₃) dsimp rw [h₂] · refine ((congr_fun (e.hom.naturality D.L₂.f) x₁).symm.trans ?_).trans (congr_fun (e.hom.naturality D.v₁₂.τ₂) x₂) dsimp rw [h₁] end SnakeInput end ShortComplex end abelian end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/LeftHomology.lean
import Mathlib.Algebra.Homology.ShortComplex.Basic import Mathlib.CategoryTheory.Limits.Shapes.Kernels /-! # Left Homology of short complexes Given a short complex `S : ShortComplex C`, which consists of two composable maps `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` such that `f ≫ g = 0`, we shall define here the "left homology" `S.leftHomology` of `S`. For this, we introduce the notion of "left homology data". Such an `h : S.LeftHomologyData` consists of the data of morphisms `i : K ⟶ X₂` and `π : K ⟶ H` such that `i` identifies `K` with the kernel of `g : X₂ ⟶ X₃`, and that `π` identifies `H` with the cokernel of the induced map `f' : X₁ ⟶ K`. When such a `S.LeftHomologyData` exists, we shall say that `[S.HasLeftHomology]` and we define `S.leftHomology` to be the `H` field of a chosen left homology data. Similarly, we define `S.cycles` to be the `K` field. The dual notion is defined in `RightHomologyData.lean`. In `Homology.lean`, when `S` has two compatible left and right homology data (i.e. they give the same `H` up to a canonical isomorphism), we shall define `[S.HasHomology]` and `S.homology`. -/ namespace CategoryTheory open Category Limits namespace ShortComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (S : ShortComplex C) {S₁ S₂ S₃ : ShortComplex C} /-- A left homology data for a short complex `S` consists of morphisms `i : K ⟶ S.X₂` and `π : K ⟶ H` such that `i` identifies `K` to the kernel of `g : S.X₂ ⟶ S.X₃`, and that `π` identifies `H` to the cokernel of the induced map `f' : S.X₁ ⟶ K` -/ structure LeftHomologyData where /-- a choice of kernel of `S.g : S.X₂ ⟶ S.X₃` -/ K : C /-- a choice of cokernel of the induced morphism `S.f' : S.X₁ ⟶ K` -/ H : C /-- the inclusion of cycles in `S.X₂` -/ i : K ⟶ S.X₂ /-- the projection from cycles to the (left) homology -/ π : K ⟶ H /-- the kernel condition for `i` -/ wi : i ≫ S.g = 0 /-- `i : K ⟶ S.X₂` is a kernel of `g : S.X₂ ⟶ S.X₃` -/ hi : IsLimit (KernelFork.ofι i wi) /-- the cokernel condition for `π` -/ wπ : hi.lift (KernelFork.ofι _ S.zero) ≫ π = 0 /-- `π : K ⟶ H` is a cokernel of the induced morphism `S.f' : S.X₁ ⟶ K` -/ hπ : IsColimit (CokernelCofork.ofπ π wπ) initialize_simps_projections LeftHomologyData (-hi, -hπ) namespace LeftHomologyData /-- The chosen kernels and cokernels of the limits API give a `LeftHomologyData` -/ @[simps] noncomputable def ofHasKernelOfHasCokernel [HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] : S.LeftHomologyData where K := kernel S.g H := cokernel (kernel.lift S.g S.f S.zero) i := kernel.ι _ π := cokernel.π _ wi := kernel.condition _ hi := kernelIsKernel _ wπ := cokernel.condition _ hπ := cokernelIsCokernel _ attribute [reassoc (attr := simp)] wi wπ variable {S} variable (h : S.LeftHomologyData) {A : C} instance : Mono h.i := ⟨fun _ _ => Fork.IsLimit.hom_ext h.hi⟩ instance : Epi h.π := ⟨fun _ _ => Cofork.IsColimit.hom_ext h.hπ⟩ /-- Any morphism `k : A ⟶ S.X₂` that is a cycle (i.e. `k ≫ S.g = 0`) lifts to a morphism `A ⟶ K` -/ def liftK (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) : A ⟶ h.K := h.hi.lift (KernelFork.ofι k hk) @[reassoc (attr := simp)] lemma liftK_i (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) : h.liftK k hk ≫ h.i = k := h.hi.fac _ WalkingParallelPair.zero /-- The (left) homology class `A ⟶ H` attached to a cycle `k : A ⟶ S.X₂` -/ @[simp] def liftH (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) : A ⟶ h.H := h.liftK k hk ≫ h.π /-- Given `h : LeftHomologyData S`, this is morphism `S.X₁ ⟶ h.K` induced by `S.f : S.X₁ ⟶ S.X₂` and the fact that `h.K` is a kernel of `S.g : S.X₂ ⟶ S.X₃`. -/ def f' : S.X₁ ⟶ h.K := h.liftK S.f S.zero @[reassoc (attr := simp)] lemma f'_i : h.f' ≫ h.i = S.f := liftK_i _ _ _ @[reassoc (attr := simp)] lemma f'_π : h.f' ≫ h.π = 0 := h.wπ @[reassoc] lemma liftK_π_eq_zero_of_boundary (k : A ⟶ S.X₂) (x : A ⟶ S.X₁) (hx : k = x ≫ S.f) : h.liftK k (by rw [hx, assoc, S.zero, comp_zero]) ≫ h.π = 0 := by rw [show 0 = (x ≫ h.f') ≫ h.π by simp] congr 1 simp only [← cancel_mono h.i, hx, liftK_i, assoc, f'_i] /-- For `h : S.LeftHomologyData`, this is a restatement of `h.hπ`, saying that `π : h.K ⟶ h.H` is a cokernel of `h.f' : S.X₁ ⟶ h.K`. -/ def hπ' : IsColimit (CokernelCofork.ofπ h.π h.f'_π) := h.hπ /-- The morphism `H ⟶ A` induced by a morphism `k : K ⟶ A` such that `f' ≫ k = 0` -/ def descH (k : h.K ⟶ A) (hk : h.f' ≫ k = 0) : h.H ⟶ A := h.hπ.desc (CokernelCofork.ofπ k hk) @[reassoc (attr := simp)] lemma π_descH (k : h.K ⟶ A) (hk : h.f' ≫ k = 0) : h.π ≫ h.descH k hk = k := h.hπ.fac (CokernelCofork.ofπ k hk) WalkingParallelPair.one lemma isIso_i (hg : S.g = 0) : IsIso h.i := ⟨h.liftK (𝟙 S.X₂) (by rw [hg, id_comp]), by simp only [← cancel_mono h.i, id_comp, assoc, liftK_i, comp_id], liftK_i _ _ _⟩ lemma isIso_π (hf : S.f = 0) : IsIso h.π := by have ⟨φ, hφ⟩ := CokernelCofork.IsColimit.desc' h.hπ' (𝟙 _) (by rw [← cancel_mono h.i, comp_id, f'_i, zero_comp, hf]) dsimp at hφ exact ⟨φ, hφ, by rw [← cancel_epi h.π, reassoc_of% hφ, comp_id]⟩ variable (S) /-- When the second map `S.g` is zero, this is the left homology data on `S` given by any colimit cokernel cofork of `S.f` -/ @[simps] def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : S.LeftHomologyData where K := S.X₂ H := c.pt i := 𝟙 _ π := c.π wi := by rw [id_comp, hg] hi := KernelFork.IsLimit.ofId _ hg wπ := CokernelCofork.condition _ hπ := IsColimit.ofIsoColimit hc (Cofork.ext (Iso.refl _)) @[simp] lemma ofIsColimitCokernelCofork_f' (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : (ofIsColimitCokernelCofork S hg c hc).f' = S.f := by rfl /-- When the second map `S.g` is zero, this is the left homology data on `S` given by the chosen `cokernel S.f` -/ @[simps!] noncomputable def ofHasCokernel [HasCokernel S.f] (hg : S.g = 0) : S.LeftHomologyData := ofIsColimitCokernelCofork S hg _ (cokernelIsCokernel _) /-- When the first map `S.f` is zero, this is the left homology data on `S` given by any limit kernel fork of `S.g` -/ @[simps] def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : S.LeftHomologyData where K := c.pt H := c.pt i := c.ι π := 𝟙 _ wi := KernelFork.condition _ hi := IsLimit.ofIsoLimit hc (Fork.ext (Iso.refl _)) wπ := Fork.IsLimit.hom_ext hc (by dsimp simp only [comp_id, zero_comp, Fork.IsLimit.lift_ι, Fork.ι_ofι, hf]) hπ := CokernelCofork.IsColimit.ofId _ (Fork.IsLimit.hom_ext hc (by dsimp simp only [comp_id, zero_comp, Fork.IsLimit.lift_ι, Fork.ι_ofι, hf])) @[simp] lemma ofIsLimitKernelFork_f' (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : (ofIsLimitKernelFork S hf c hc).f' = 0 := by rw [← cancel_mono (ofIsLimitKernelFork S hf c hc).i, f'_i, hf, zero_comp] /-- When the first map `S.f` is zero, this is the left homology data on `S` given by the chosen `kernel S.g` -/ @[simp] noncomputable def ofHasKernel [HasKernel S.g] (hf : S.f = 0) : S.LeftHomologyData := ofIsLimitKernelFork S hf _ (kernelIsKernel _) /-- When both `S.f` and `S.g` are zero, the middle object `S.X₂` gives a left homology data on S -/ @[simps] def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.LeftHomologyData where K := S.X₂ H := S.X₂ i := 𝟙 _ π := 𝟙 _ wi := by rw [id_comp, hg] hi := KernelFork.IsLimit.ofId _ hg wπ := by change S.f ≫ 𝟙 _ = 0 simp only [hf, zero_comp] hπ := CokernelCofork.IsColimit.ofId _ hf @[simp] lemma ofZeros_f' (hf : S.f = 0) (hg : S.g = 0) : (ofZeros S hf hg).f' = 0 := by rw [← cancel_mono ((ofZeros S hf hg).i), zero_comp, f'_i, hf] variable {S} in /-- Given a left homology data `h` of a short complex `S`, we can construct another left homology data by choosing another kernel and cokernel that are isomorphic to the ones in `h`. -/ @[simps] def copy {K' H' : C} (eK : K' ≅ h.K) (eH : H' ≅ h.H) : S.LeftHomologyData where K := K' H := H' i := eK.hom ≫ h.i π := eK.hom ≫ h.π ≫ eH.inv wi := by rw [assoc, h.wi, comp_zero] hi := IsKernel.isoKernel _ _ h.hi eK (by simp) wπ := by simp [IsKernel.isoKernel] hπ := IsColimit.equivOfNatIsoOfIso (parallelPair.ext (Iso.refl S.X₁) eK.symm (by simp [IsKernel.isoKernel]) (by simp)) _ _ (Cocones.ext (by exact eH.symm) (by rintro (_ | _) <;> simp [IsKernel.isoKernel])) h.hπ end LeftHomologyData /-- A short complex `S` has left homology when there exists a `S.LeftHomologyData` -/ class HasLeftHomology : Prop where condition : Nonempty S.LeftHomologyData /-- A chosen `S.LeftHomologyData` for a short complex `S` that has left homology -/ noncomputable def leftHomologyData [S.HasLeftHomology] : S.LeftHomologyData := HasLeftHomology.condition.some variable {S} namespace HasLeftHomology lemma mk' (h : S.LeftHomologyData) : HasLeftHomology S := ⟨Nonempty.intro h⟩ instance of_hasKernel_of_hasCokernel [HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] : S.HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofHasKernelOfHasCokernel S) instance of_hasCokernel {X Y : C} (f : X ⟶ Y) (Z : C) [HasCokernel f] : (ShortComplex.mk f (0 : Y ⟶ Z) comp_zero).HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofHasCokernel _ rfl) instance of_hasKernel {Y Z : C} (g : Y ⟶ Z) (X : C) [HasKernel g] : (ShortComplex.mk (0 : X ⟶ Y) g zero_comp).HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofHasKernel _ rfl) instance of_zeros (X Y Z : C) : (ShortComplex.mk (0 : X ⟶ Y) (0 : Y ⟶ Z) zero_comp).HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofZeros _ rfl rfl) end HasLeftHomology section variable (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) /-- Given left homology data `h₁` and `h₂` for two short complexes `S₁` and `S₂`, a `LeftHomologyMapData` for a morphism `φ : S₁ ⟶ S₂` consists of a description of the induced morphisms on the `K` (cycles) and `H` (left homology) fields of `h₁` and `h₂`. -/ structure LeftHomologyMapData where /-- the induced map on cycles -/ φK : h₁.K ⟶ h₂.K /-- the induced map on left homology -/ φH : h₁.H ⟶ h₂.H /-- commutation with `i` -/ commi : φK ≫ h₂.i = h₁.i ≫ φ.τ₂ := by cat_disch /-- commutation with `f'` -/ commf' : h₁.f' ≫ φK = φ.τ₁ ≫ h₂.f' := by cat_disch /-- commutation with `π` -/ commπ : h₁.π ≫ φH = φK ≫ h₂.π := by cat_disch namespace LeftHomologyMapData attribute [reassoc (attr := simp)] commi commf' commπ /-- The left homology map data associated to the zero morphism between two short complexes. -/ @[simps] def zero (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : LeftHomologyMapData 0 h₁ h₂ where φK := 0 φH := 0 /-- The left homology map data associated to the identity morphism of a short complex. -/ @[simps] def id (h : S.LeftHomologyData) : LeftHomologyMapData (𝟙 S) h h where φK := 𝟙 _ φH := 𝟙 _ /-- The composition of left homology map data. -/ @[simps] def comp {φ : S₁ ⟶ S₂} {φ' : S₂ ⟶ S₃} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} {h₃ : S₃.LeftHomologyData} (ψ : LeftHomologyMapData φ h₁ h₂) (ψ' : LeftHomologyMapData φ' h₂ h₃) : LeftHomologyMapData (φ ≫ φ') h₁ h₃ where φK := ψ.φK ≫ ψ'.φK φH := ψ.φH ≫ ψ'.φH instance : Subsingleton (LeftHomologyMapData φ h₁ h₂) := ⟨fun ψ₁ ψ₂ => by have hK : ψ₁.φK = ψ₂.φK := by rw [← cancel_mono h₂.i, commi, commi] have hH : ψ₁.φH = ψ₂.φH := by rw [← cancel_epi h₁.π, commπ, commπ, hK] cases ψ₁ cases ψ₂ congr⟩ instance : Inhabited (LeftHomologyMapData φ h₁ h₂) := ⟨by let φK : h₁.K ⟶ h₂.K := h₂.liftK (h₁.i ≫ φ.τ₂) (by rw [assoc, φ.comm₂₃, h₁.wi_assoc, zero_comp]) have commf' : h₁.f' ≫ φK = φ.τ₁ ≫ h₂.f' := by rw [← cancel_mono h₂.i, assoc, assoc, LeftHomologyData.liftK_i, LeftHomologyData.f'_i_assoc, LeftHomologyData.f'_i, φ.comm₁₂] let φH : h₁.H ⟶ h₂.H := h₁.descH (φK ≫ h₂.π) (by rw [reassoc_of% commf', h₂.f'_π, comp_zero]) exact ⟨φK, φH, by simp [φK], commf', by simp [φH]⟩⟩ instance : Unique (LeftHomologyMapData φ h₁ h₂) := Unique.mk' _ variable {φ h₁ h₂} lemma congr_φH {γ₁ γ₂ : LeftHomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.φH = γ₂.φH := by rw [eq] lemma congr_φK {γ₁ γ₂ : LeftHomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.φK = γ₂.φK := by rw [eq] /-- When `S₁.f`, `S₁.g`, `S₂.f` and `S₂.g` are all zero, the action on left homology of a morphism `φ : S₁ ⟶ S₂` is given by the action `φ.τ₂` on the middle objects. -/ @[simps] def ofZeros (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) (hg₂ : S₂.g = 0) : LeftHomologyMapData φ (LeftHomologyData.ofZeros S₁ hf₁ hg₁) (LeftHomologyData.ofZeros S₂ hf₂ hg₂) where φK := φ.τ₂ φH := φ.τ₂ /-- When `S₁.g` and `S₂.g` are zero and we have chosen colimit cokernel coforks `c₁` and `c₂` for `S₁.f` and `S₂.f` respectively, the action on left homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `φ.τ₂ ≫ c₂.π = c₁.π ≫ f`. -/ @[simps] def ofIsColimitCokernelCofork (φ : S₁ ⟶ S₂) (hg₁ : S₁.g = 0) (c₁ : CokernelCofork S₁.f) (hc₁ : IsColimit c₁) (hg₂ : S₂.g = 0) (c₂ : CokernelCofork S₂.f) (hc₂ : IsColimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : φ.τ₂ ≫ c₂.π = c₁.π ≫ f) : LeftHomologyMapData φ (LeftHomologyData.ofIsColimitCokernelCofork S₁ hg₁ c₁ hc₁) (LeftHomologyData.ofIsColimitCokernelCofork S₂ hg₂ c₂ hc₂) where φK := φ.τ₂ φH := f commπ := comm.symm commf' := by simp only [LeftHomologyData.ofIsColimitCokernelCofork_f', φ.comm₁₂] /-- When `S₁.f` and `S₂.f` are zero and we have chosen limit kernel forks `c₁` and `c₂` for `S₁.g` and `S₂.g` respectively, the action on left homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι`. -/ @[simps] def ofIsLimitKernelFork (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (c₁ : KernelFork S₁.g) (hc₁ : IsLimit c₁) (hf₂ : S₂.f = 0) (c₂ : KernelFork S₂.g) (hc₂ : IsLimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι) : LeftHomologyMapData φ (LeftHomologyData.ofIsLimitKernelFork S₁ hf₁ c₁ hc₁) (LeftHomologyData.ofIsLimitKernelFork S₂ hf₂ c₂ hc₂) where φK := f φH := f commi := comm.symm variable (S) /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the left homology map data (for the identity of `S`) which relates the left homology data `ofZeros` and `ofIsColimitCokernelCofork`. -/ @[simps] def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : LeftHomologyMapData (𝟙 S) (LeftHomologyData.ofZeros S hf hg) (LeftHomologyData.ofIsColimitCokernelCofork S hg c hc) where φK := 𝟙 _ φH := c.π /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the left homology map data (for the identity of `S`) which relates the left homology data `LeftHomologyData.ofIsLimitKernelFork` and `ofZeros` . -/ @[simps] def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0) (c : KernelFork S.g) (hc : IsLimit c) : LeftHomologyMapData (𝟙 S) (LeftHomologyData.ofIsLimitKernelFork S hf c hc) (LeftHomologyData.ofZeros S hf hg) where φK := c.ι φH := c.ι end LeftHomologyMapData end section variable (S) variable [S.HasLeftHomology] /-- The left homology of a short complex, given by the `H` field of a chosen left homology data. -/ noncomputable def leftHomology : C := S.leftHomologyData.H -- `S.leftHomology` is the simp normal form. @[simp] lemma leftHomologyData_H : S.leftHomologyData.H = S.leftHomology := rfl /-- The cycles of a short complex, given by the `K` field of a chosen left homology data. -/ noncomputable def cycles : C := S.leftHomologyData.K /-- The "homology class" map `S.cycles ⟶ S.leftHomology`. -/ noncomputable def leftHomologyπ : S.cycles ⟶ S.leftHomology := S.leftHomologyData.π /-- The inclusion `S.cycles ⟶ S.X₂`. -/ noncomputable def iCycles : S.cycles ⟶ S.X₂ := S.leftHomologyData.i /-- The "boundaries" map `S.X₁ ⟶ S.cycles`. (Note that in this homology API, we make no use of the "image" of this morphism, which under some categorical assumptions would be a subobject of `S.X₂` contained in `S.cycles`.) -/ noncomputable def toCycles : S.X₁ ⟶ S.cycles := S.leftHomologyData.f' @[reassoc (attr := simp)] lemma iCycles_g : S.iCycles ≫ S.g = 0 := S.leftHomologyData.wi @[reassoc (attr := simp)] lemma toCycles_i : S.toCycles ≫ S.iCycles = S.f := S.leftHomologyData.f'_i instance : Mono S.iCycles := by dsimp only [iCycles] infer_instance instance : Epi S.leftHomologyπ := by dsimp only [leftHomologyπ] infer_instance lemma leftHomology_ext_iff {A : C} (f₁ f₂ : S.leftHomology ⟶ A) : f₁ = f₂ ↔ S.leftHomologyπ ≫ f₁ = S.leftHomologyπ ≫ f₂ := by rw [cancel_epi] @[ext] lemma leftHomology_ext {A : C} (f₁ f₂ : S.leftHomology ⟶ A) (h : S.leftHomologyπ ≫ f₁ = S.leftHomologyπ ≫ f₂) : f₁ = f₂ := by simpa only [leftHomology_ext_iff] using h lemma cycles_ext_iff {A : C} (f₁ f₂ : A ⟶ S.cycles) : f₁ = f₂ ↔ f₁ ≫ S.iCycles = f₂ ≫ S.iCycles := by rw [cancel_mono] @[ext] lemma cycles_ext {A : C} (f₁ f₂ : A ⟶ S.cycles) (h : f₁ ≫ S.iCycles = f₂ ≫ S.iCycles) : f₁ = f₂ := by simpa only [cycles_ext_iff] using h lemma isIso_iCycles (hg : S.g = 0) : IsIso S.iCycles := LeftHomologyData.isIso_i _ hg /-- When `S.g = 0`, this is the canonical isomorphism `S.cycles ≅ S.X₂` induced by `S.iCycles`. -/ @[simps! hom] noncomputable def cyclesIsoX₂ (hg : S.g = 0) : S.cycles ≅ S.X₂ := by have := S.isIso_iCycles hg exact asIso S.iCycles @[reassoc (attr := simp)] lemma cyclesIsoX₂_hom_inv_id (hg : S.g = 0) : S.iCycles ≫ (S.cyclesIsoX₂ hg).inv = 𝟙 _ := (S.cyclesIsoX₂ hg).hom_inv_id @[reassoc (attr := simp)] lemma cyclesIsoX₂_inv_hom_id (hg : S.g = 0) : (S.cyclesIsoX₂ hg).inv ≫ S.iCycles = 𝟙 _ := (S.cyclesIsoX₂ hg).inv_hom_id lemma isIso_leftHomologyπ (hf : S.f = 0) : IsIso S.leftHomologyπ := LeftHomologyData.isIso_π _ hf /-- When `S.f = 0`, this is the canonical isomorphism `S.cycles ≅ S.leftHomology` induced by `S.leftHomologyπ`. -/ @[simps! hom] noncomputable def cyclesIsoLeftHomology (hf : S.f = 0) : S.cycles ≅ S.leftHomology := by have := S.isIso_leftHomologyπ hf exact asIso S.leftHomologyπ @[reassoc (attr := simp)] lemma cyclesIsoLeftHomology_hom_inv_id (hf : S.f = 0) : S.leftHomologyπ ≫ (S.cyclesIsoLeftHomology hf).inv = 𝟙 _ := (S.cyclesIsoLeftHomology hf).hom_inv_id @[reassoc (attr := simp)] lemma cyclesIsoLeftHomology_inv_hom_id (hf : S.f = 0) : (S.cyclesIsoLeftHomology hf).inv ≫ S.leftHomologyπ = 𝟙 _ := (S.cyclesIsoLeftHomology hf).inv_hom_id end section variable (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) /-- The (unique) left homology map data associated to a morphism of short complexes that are both equipped with left homology data. -/ def leftHomologyMapData : LeftHomologyMapData φ h₁ h₂ := default /-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and left homology data `h₁` and `h₂` for `S₁` and `S₂` respectively, this is the induced left homology map `h₁.H ⟶ h₁.H`. -/ def leftHomologyMap' : h₁.H ⟶ h₂.H := (leftHomologyMapData φ _ _).φH /-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and left homology data `h₁` and `h₂` for `S₁` and `S₂` respectively, this is the induced morphism `h₁.K ⟶ h₁.K` on cycles. -/ def cyclesMap' : h₁.K ⟶ h₂.K := (leftHomologyMapData φ _ _).φK @[reassoc (attr := simp)] lemma cyclesMap'_i : cyclesMap' φ h₁ h₂ ≫ h₂.i = h₁.i ≫ φ.τ₂ := LeftHomologyMapData.commi _ @[reassoc (attr := simp)] lemma f'_cyclesMap' : h₁.f' ≫ cyclesMap' φ h₁ h₂ = φ.τ₁ ≫ h₂.f' := by simp only [← cancel_mono h₂.i, assoc, φ.comm₁₂, cyclesMap'_i, LeftHomologyData.f'_i_assoc, LeftHomologyData.f'_i] @[reassoc (attr := simp)] lemma leftHomologyπ_naturality' : h₁.π ≫ leftHomologyMap' φ h₁ h₂ = cyclesMap' φ h₁ h₂ ≫ h₂.π := LeftHomologyMapData.commπ _ end section variable [HasLeftHomology S₁] [HasLeftHomology S₂] (φ : S₁ ⟶ S₂) /-- The (left) homology map `S₁.leftHomology ⟶ S₂.leftHomology` induced by a morphism `S₁ ⟶ S₂` of short complexes. -/ noncomputable def leftHomologyMap : S₁.leftHomology ⟶ S₂.leftHomology := leftHomologyMap' φ _ _ /-- The morphism `S₁.cycles ⟶ S₂.cycles` induced by a morphism `S₁ ⟶ S₂` of short complexes. -/ noncomputable def cyclesMap : S₁.cycles ⟶ S₂.cycles := cyclesMap' φ _ _ @[reassoc (attr := simp)] lemma cyclesMap_i : cyclesMap φ ≫ S₂.iCycles = S₁.iCycles ≫ φ.τ₂ := cyclesMap'_i _ _ _ @[reassoc (attr := simp)] lemma toCycles_naturality : S₁.toCycles ≫ cyclesMap φ = φ.τ₁ ≫ S₂.toCycles := f'_cyclesMap' _ _ _ @[reassoc (attr := simp)] lemma leftHomologyπ_naturality : S₁.leftHomologyπ ≫ leftHomologyMap φ = cyclesMap φ ≫ S₂.leftHomologyπ := leftHomologyπ_naturality' _ _ _ end namespace LeftHomologyMapData variable {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (γ : LeftHomologyMapData φ h₁ h₂) lemma leftHomologyMap'_eq : leftHomologyMap' φ h₁ h₂ = γ.φH := LeftHomologyMapData.congr_φH (Subsingleton.elim _ _) lemma cyclesMap'_eq : cyclesMap' φ h₁ h₂ = γ.φK := LeftHomologyMapData.congr_φK (Subsingleton.elim _ _) end LeftHomologyMapData @[simp] lemma leftHomologyMap'_id (h : S.LeftHomologyData) : leftHomologyMap' (𝟙 S) h h = 𝟙 _ := (LeftHomologyMapData.id h).leftHomologyMap'_eq @[simp] lemma cyclesMap'_id (h : S.LeftHomologyData) : cyclesMap' (𝟙 S) h h = 𝟙 _ := (LeftHomologyMapData.id h).cyclesMap'_eq variable (S) @[simp] lemma leftHomologyMap_id [HasLeftHomology S] : leftHomologyMap (𝟙 S) = 𝟙 _ := leftHomologyMap'_id _ @[simp] lemma cyclesMap_id [HasLeftHomology S] : cyclesMap (𝟙 S) = 𝟙 _ := cyclesMap'_id _ @[simp] lemma leftHomologyMap'_zero (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : leftHomologyMap' 0 h₁ h₂ = 0 := (LeftHomologyMapData.zero h₁ h₂).leftHomologyMap'_eq @[simp] lemma cyclesMap'_zero (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : cyclesMap' 0 h₁ h₂ = 0 := (LeftHomologyMapData.zero h₁ h₂).cyclesMap'_eq variable (S₁ S₂) @[simp] lemma leftHomologyMap_zero [HasLeftHomology S₁] [HasLeftHomology S₂] : leftHomologyMap (0 : S₁ ⟶ S₂) = 0 := leftHomologyMap'_zero _ _ @[simp] lemma cyclesMap_zero [HasLeftHomology S₁] [HasLeftHomology S₂] : cyclesMap (0 : S₁ ⟶ S₂) = 0 := cyclesMap'_zero _ _ variable {S₁ S₂} @[reassoc] lemma leftHomologyMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) (h₃ : S₃.LeftHomologyData) : leftHomologyMap' (φ₁ ≫ φ₂) h₁ h₃ = leftHomologyMap' φ₁ h₁ h₂ ≫ leftHomologyMap' φ₂ h₂ h₃ := by let γ₁ := leftHomologyMapData φ₁ h₁ h₂ let γ₂ := leftHomologyMapData φ₂ h₂ h₃ rw [γ₁.leftHomologyMap'_eq, γ₂.leftHomologyMap'_eq, (γ₁.comp γ₂).leftHomologyMap'_eq, LeftHomologyMapData.comp_φH] @[reassoc] lemma cyclesMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) (h₃ : S₃.LeftHomologyData) : cyclesMap' (φ₁ ≫ φ₂) h₁ h₃ = cyclesMap' φ₁ h₁ h₂ ≫ cyclesMap' φ₂ h₂ h₃ := by let γ₁ := leftHomologyMapData φ₁ h₁ h₂ let γ₂ := leftHomologyMapData φ₂ h₂ h₃ rw [γ₁.cyclesMap'_eq, γ₂.cyclesMap'_eq, (γ₁.comp γ₂).cyclesMap'_eq, LeftHomologyMapData.comp_φK] @[reassoc] lemma leftHomologyMap_comp [HasLeftHomology S₁] [HasLeftHomology S₂] [HasLeftHomology S₃] (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) : leftHomologyMap (φ₁ ≫ φ₂) = leftHomologyMap φ₁ ≫ leftHomologyMap φ₂ := leftHomologyMap'_comp _ _ _ _ _ @[reassoc] lemma cyclesMap_comp [HasLeftHomology S₁] [HasLeftHomology S₂] [HasLeftHomology S₃] (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) : cyclesMap (φ₁ ≫ φ₂) = cyclesMap φ₁ ≫ cyclesMap φ₂ := cyclesMap'_comp _ _ _ _ _ attribute [simp] leftHomologyMap_comp cyclesMap_comp /-- An isomorphism of short complexes `S₁ ≅ S₂` induces an isomorphism on the `H` fields of left homology data of `S₁` and `S₂`. -/ @[simps] def leftHomologyMapIso' (e : S₁ ≅ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : h₁.H ≅ h₂.H where hom := leftHomologyMap' e.hom h₁ h₂ inv := leftHomologyMap' e.inv h₂ h₁ hom_inv_id := by rw [← leftHomologyMap'_comp, e.hom_inv_id, leftHomologyMap'_id] inv_hom_id := by rw [← leftHomologyMap'_comp, e.inv_hom_id, leftHomologyMap'_id] instance isIso_leftHomologyMap'_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ] (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : IsIso (leftHomologyMap' φ h₁ h₂) := (inferInstance : IsIso (leftHomologyMapIso' (asIso φ) h₁ h₂).hom) /-- An isomorphism of short complexes `S₁ ≅ S₂` induces an isomorphism on the `K` fields of left homology data of `S₁` and `S₂`. -/ @[simps] def cyclesMapIso' (e : S₁ ≅ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : h₁.K ≅ h₂.K where hom := cyclesMap' e.hom h₁ h₂ inv := cyclesMap' e.inv h₂ h₁ hom_inv_id := by rw [← cyclesMap'_comp, e.hom_inv_id, cyclesMap'_id] inv_hom_id := by rw [← cyclesMap'_comp, e.inv_hom_id, cyclesMap'_id] instance isIso_cyclesMap'_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ] (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : IsIso (cyclesMap' φ h₁ h₂) := (inferInstance : IsIso (cyclesMapIso' (asIso φ) h₁ h₂).hom) /-- The isomorphism `S₁.leftHomology ≅ S₂.leftHomology` induced by an isomorphism of short complexes `S₁ ≅ S₂`. -/ @[simps] noncomputable def leftHomologyMapIso (e : S₁ ≅ S₂) [S₁.HasLeftHomology] [S₂.HasLeftHomology] : S₁.leftHomology ≅ S₂.leftHomology where hom := leftHomologyMap e.hom inv := leftHomologyMap e.inv hom_inv_id := by rw [← leftHomologyMap_comp, e.hom_inv_id, leftHomologyMap_id] inv_hom_id := by rw [← leftHomologyMap_comp, e.inv_hom_id, leftHomologyMap_id] instance isIso_leftHomologyMap_of_iso (φ : S₁ ⟶ S₂) [IsIso φ] [S₁.HasLeftHomology] [S₂.HasLeftHomology] : IsIso (leftHomologyMap φ) := (inferInstance : IsIso (leftHomologyMapIso (asIso φ)).hom) /-- The isomorphism `S₁.cycles ≅ S₂.cycles` induced by an isomorphism of short complexes `S₁ ≅ S₂`. -/ @[simps] noncomputable def cyclesMapIso (e : S₁ ≅ S₂) [S₁.HasLeftHomology] [S₂.HasLeftHomology] : S₁.cycles ≅ S₂.cycles where hom := cyclesMap e.hom inv := cyclesMap e.inv hom_inv_id := by rw [← cyclesMap_comp, e.hom_inv_id, cyclesMap_id] inv_hom_id := by rw [← cyclesMap_comp, e.inv_hom_id, cyclesMap_id] instance isIso_cyclesMap_of_iso (φ : S₁ ⟶ S₂) [IsIso φ] [S₁.HasLeftHomology] [S₂.HasLeftHomology] : IsIso (cyclesMap φ) := (inferInstance : IsIso (cyclesMapIso (asIso φ)).hom) variable {S} namespace LeftHomologyData variable (h : S.LeftHomologyData) [S.HasLeftHomology] /-- The isomorphism `S.leftHomology ≅ h.H` induced by a left homology data `h` for a short complex `S`. -/ noncomputable def leftHomologyIso : S.leftHomology ≅ h.H := leftHomologyMapIso' (Iso.refl _) _ _ /-- The isomorphism `S.cycles ≅ h.K` induced by a left homology data `h` for a short complex `S`. -/ noncomputable def cyclesIso : S.cycles ≅ h.K := cyclesMapIso' (Iso.refl _) _ _ @[reassoc (attr := simp)] lemma cyclesIso_hom_comp_i : h.cyclesIso.hom ≫ h.i = S.iCycles := by dsimp [iCycles, LeftHomologyData.cyclesIso] simp only [cyclesMap'_i, id_τ₂, comp_id] @[reassoc (attr := simp)] lemma cyclesIso_inv_comp_iCycles : h.cyclesIso.inv ≫ S.iCycles = h.i := by simp only [← h.cyclesIso_hom_comp_i, Iso.inv_hom_id_assoc] @[reassoc (attr := simp)] lemma leftHomologyπ_comp_leftHomologyIso_hom : S.leftHomologyπ ≫ h.leftHomologyIso.hom = h.cyclesIso.hom ≫ h.π := by dsimp only [leftHomologyπ, leftHomologyIso, cyclesIso, leftHomologyMapIso', cyclesMapIso', Iso.refl] rw [← leftHomologyπ_naturality'] @[reassoc (attr := simp)] lemma π_comp_leftHomologyIso_inv : h.π ≫ h.leftHomologyIso.inv = h.cyclesIso.inv ≫ S.leftHomologyπ := by simp only [← cancel_epi h.cyclesIso.hom, ← cancel_mono h.leftHomologyIso.hom, assoc, Iso.inv_hom_id, comp_id, Iso.hom_inv_id_assoc, LeftHomologyData.leftHomologyπ_comp_leftHomologyIso_hom] end LeftHomologyData namespace LeftHomologyMapData variable {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} (γ : LeftHomologyMapData φ h₁ h₂) lemma leftHomologyMap_eq [S₁.HasLeftHomology] [S₂.HasLeftHomology] : leftHomologyMap φ = h₁.leftHomologyIso.hom ≫ γ.φH ≫ h₂.leftHomologyIso.inv := by dsimp [LeftHomologyData.leftHomologyIso, leftHomologyMapIso'] rw [← γ.leftHomologyMap'_eq, ← leftHomologyMap'_comp, ← leftHomologyMap'_comp, id_comp, comp_id] rfl lemma cyclesMap_eq [S₁.HasLeftHomology] [S₂.HasLeftHomology] : cyclesMap φ = h₁.cyclesIso.hom ≫ γ.φK ≫ h₂.cyclesIso.inv := by dsimp [LeftHomologyData.cyclesIso, cyclesMapIso'] rw [← γ.cyclesMap'_eq, ← cyclesMap'_comp, ← cyclesMap'_comp, id_comp, comp_id] rfl lemma leftHomologyMap_comm [S₁.HasLeftHomology] [S₂.HasLeftHomology] : leftHomologyMap φ ≫ h₂.leftHomologyIso.hom = h₁.leftHomologyIso.hom ≫ γ.φH := by simp only [γ.leftHomologyMap_eq, assoc, Iso.inv_hom_id, comp_id] lemma cyclesMap_comm [S₁.HasLeftHomology] [S₂.HasLeftHomology] : cyclesMap φ ≫ h₂.cyclesIso.hom = h₁.cyclesIso.hom ≫ γ.φK := by simp only [γ.cyclesMap_eq, assoc, Iso.inv_hom_id, comp_id] end LeftHomologyMapData section variable (C) variable [HasKernels C] [HasCokernels C] /-- The left homology functor `ShortComplex C ⥤ C`, where the left homology of a short complex `S` is understood as a cokernel of the obvious map `S.toCycles : S.X₁ ⟶ S.cycles` where `S.cycles` is a kernel of `S.g : S.X₂ ⟶ S.X₃`. -/ @[simps] noncomputable def leftHomologyFunctor : ShortComplex C ⥤ C where obj S := S.leftHomology map := leftHomologyMap /-- The cycles functor `ShortComplex C ⥤ C` which sends a short complex `S` to `S.cycles` which is a kernel of `S.g : S.X₂ ⟶ S.X₃`. -/ @[simps] noncomputable def cyclesFunctor : ShortComplex C ⥤ C where obj S := S.cycles map := cyclesMap /-- The natural transformation `S.cycles ⟶ S.leftHomology` for all short complexes `S`. -/ @[simps] noncomputable def leftHomologyπNatTrans : cyclesFunctor C ⟶ leftHomologyFunctor C where app S := leftHomologyπ S naturality := fun _ _ φ => (leftHomologyπ_naturality φ).symm /-- The natural transformation `S.cycles ⟶ S.X₂` for all short complexes `S`. -/ @[simps] noncomputable def iCyclesNatTrans : cyclesFunctor C ⟶ ShortComplex.π₂ where app S := S.iCycles /-- The natural transformation `S.X₁ ⟶ S.cycles` for all short complexes `S`. -/ @[simps] noncomputable def toCyclesNatTrans : π₁ ⟶ cyclesFunctor C where app S := S.toCycles naturality := fun _ _ φ => (toCycles_naturality φ).symm end namespace LeftHomologyData /-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso and `φ.τ₃` is mono, then a left homology data for `S₁` induces a left homology data for `S₂` with the same `K` and `H` fields. The inverse construction is `ofEpiOfIsIsoOfMono'`. -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : LeftHomologyData S₂ := by let i : h.K ⟶ S₂.X₂ := h.i ≫ φ.τ₂ have wi : i ≫ S₂.g = 0 := by simp only [i, assoc, φ.comm₂₃, h.wi_assoc, zero_comp] have hi : IsLimit (KernelFork.ofι i wi) := KernelFork.IsLimit.ofι _ _ (fun x hx => h.liftK (x ≫ inv φ.τ₂) (by rw [assoc, ← cancel_mono φ.τ₃, assoc, assoc, ← φ.comm₂₃, IsIso.inv_hom_id_assoc, hx, zero_comp])) (fun x hx => by simp [i]) (fun x hx b hb => by dsimp rw [← cancel_mono h.i, ← cancel_mono φ.τ₂, assoc, assoc, liftK_i_assoc, assoc, IsIso.inv_hom_id, comp_id, hb]) let f' := hi.lift (KernelFork.ofι S₂.f S₂.zero) have hf' : φ.τ₁ ≫ f' = h.f' := by have eq := @Fork.IsLimit.lift_ι _ _ _ _ _ _ _ ((KernelFork.ofι S₂.f S₂.zero)) hi simp only [Fork.ι_ofι] at eq rw [← cancel_mono h.i, ← cancel_mono φ.τ₂, assoc, assoc, eq, f'_i, φ.comm₁₂] have wπ : f' ≫ h.π = 0 := by rw [← cancel_epi φ.τ₁, comp_zero, reassoc_of% hf', h.f'_π] have hπ : IsColimit (CokernelCofork.ofπ h.π wπ) := CokernelCofork.IsColimit.ofπ _ _ (fun x hx => h.descH x (by rw [← hf', assoc, hx, comp_zero])) (fun x hx => by simp) (fun x hx b hb => by rw [← cancel_epi h.π, π_descH, hb]) exact ⟨h.K, h.H, i, h.π, wi, hi, wπ, hπ⟩ @[simp] lemma τ₁_ofEpiOfIsIsoOfMono_f' (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : φ.τ₁ ≫ (ofEpiOfIsIsoOfMono φ h).f' = h.f' := by rw [← cancel_mono (ofEpiOfIsIsoOfMono φ h).i, assoc, f'_i, ofEpiOfIsIsoOfMono_i, f'_i_assoc, φ.comm₁₂] /-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso and `φ.τ₃` is mono, then a left homology data for `S₂` induces a left homology data for `S₁` with the same `K` and `H` fields. The inverse construction is `ofEpiOfIsIsoOfMono`. -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : LeftHomologyData S₁ := by let i : h.K ⟶ S₁.X₂ := h.i ≫ inv φ.τ₂ have wi : i ≫ S₁.g = 0 := by rw [assoc, ← cancel_mono φ.τ₃, zero_comp, assoc, assoc, ← φ.comm₂₃, IsIso.inv_hom_id_assoc, h.wi] have hi : IsLimit (KernelFork.ofι i wi) := KernelFork.IsLimit.ofι _ _ (fun x hx => h.liftK (x ≫ φ.τ₂) (by rw [assoc, φ.comm₂₃, reassoc_of% hx, zero_comp])) (fun x hx => by simp [i]) (fun x hx b hb => by rw [← cancel_mono h.i, ← cancel_mono (inv φ.τ₂), assoc, assoc, hb, liftK_i_assoc, assoc, IsIso.hom_inv_id, comp_id]) let f' := hi.lift (KernelFork.ofι S₁.f S₁.zero) have hf' : f' ≫ i = S₁.f := Fork.IsLimit.lift_ι _ have hf'' : f' = φ.τ₁ ≫ h.f' := by rw [← cancel_mono h.i, ← cancel_mono (inv φ.τ₂), assoc, assoc, assoc, hf', f'_i_assoc, φ.comm₁₂_assoc, IsIso.hom_inv_id, comp_id] have wπ : f' ≫ h.π = 0 := by simp only [hf'', assoc, f'_π, comp_zero] have hπ : IsColimit (CokernelCofork.ofπ h.π wπ) := CokernelCofork.IsColimit.ofπ _ _ (fun x hx => h.descH x (by rw [← cancel_epi φ.τ₁, ← reassoc_of% hf'', hx, comp_zero])) (fun x hx => π_descH _ _ _) (fun x hx b hx => by rw [← cancel_epi h.π, π_descH, hx]) exact ⟨h.K, h.H, i, h.π, wi, hi, wπ, hπ⟩ @[simp] lemma ofEpiOfIsIsoOfMono'_f' (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : (ofEpiOfIsIsoOfMono' φ h).f' = φ.τ₁ ≫ h.f' := by rw [← cancel_mono (ofEpiOfIsIsoOfMono' φ h).i, f'_i, ofEpiOfIsIsoOfMono'_i, assoc, f'_i_assoc, φ.comm₁₂_assoc, IsIso.hom_inv_id, comp_id] /-- If `e : S₁ ≅ S₂` is an isomorphism of short complexes and `h₁ : LeftHomologyData S₁`, this is the left homology data for `S₂` deduced from the isomorphism. -/ noncomputable def ofIso (e : S₁ ≅ S₂) (h₁ : LeftHomologyData S₁) : LeftHomologyData S₂ := h₁.ofEpiOfIsIsoOfMono e.hom end LeftHomologyData lemma hasLeftHomology_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [HasLeftHomology S₁] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasLeftHomology S₂ := HasLeftHomology.mk' (LeftHomologyData.ofEpiOfIsIsoOfMono φ S₁.leftHomologyData) lemma hasLeftHomology_of_epi_of_isIso_of_mono' (φ : S₁ ⟶ S₂) [HasLeftHomology S₂] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasLeftHomology S₁ := HasLeftHomology.mk' (LeftHomologyData.ofEpiOfIsIsoOfMono' φ S₂.leftHomologyData) lemma hasLeftHomology_of_iso {S₁ S₂ : ShortComplex C} (e : S₁ ≅ S₂) [HasLeftHomology S₁] : HasLeftHomology S₂ := hasLeftHomology_of_epi_of_isIso_of_mono e.hom namespace LeftHomologyMapData /-- This left homology map data expresses compatibilities of the left homology data constructed by `LeftHomologyData.ofEpiOfIsIsoOfMono` -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₁) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : LeftHomologyMapData φ h (LeftHomologyData.ofEpiOfIsIsoOfMono φ h) where φK := 𝟙 _ φH := 𝟙 _ /-- This left homology map data expresses compatibilities of the left homology data constructed by `LeftHomologyData.ofEpiOfIsIsoOfMono'` -/ @[simps] noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : LeftHomologyMapData φ (LeftHomologyData.ofEpiOfIsIsoOfMono' φ h) h where φK := 𝟙 _ φH := 𝟙 _ end LeftHomologyMapData instance (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso (leftHomologyMap' φ h₁ h₂) := by let h₂' := LeftHomologyData.ofEpiOfIsIsoOfMono φ h₁ have : IsIso (leftHomologyMap' φ h₁ h₂') := by rw [(LeftHomologyMapData.ofEpiOfIsIsoOfMono φ h₁).leftHomologyMap'_eq] dsimp infer_instance have eq := leftHomologyMap'_comp φ (𝟙 S₂) h₁ h₂' h₂ rw [comp_id] at eq rw [eq] infer_instance /-- If a morphism of short complexes `φ : S₁ ⟶ S₂` is such that `φ.τ₁` is epi, `φ.τ₂` is an iso, and `φ.τ₃` is mono, then the induced morphism on left homology is an isomorphism. -/ instance (φ : S₁ ⟶ S₂) [S₁.HasLeftHomology] [S₂.HasLeftHomology] [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : IsIso (leftHomologyMap φ) := by dsimp only [leftHomologyMap] infer_instance section variable (S) (h : LeftHomologyData S) {A : C} (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) [HasLeftHomology S] /-- A morphism `k : A ⟶ S.X₂` such that `k ≫ S.g = 0` lifts to a morphism `A ⟶ S.cycles`. -/ noncomputable def liftCycles : A ⟶ S.cycles := S.leftHomologyData.liftK k hk @[reassoc (attr := simp)] lemma liftCycles_i : S.liftCycles k hk ≫ S.iCycles = k := LeftHomologyData.liftK_i _ k hk @[reassoc] lemma comp_liftCycles {A' : C} (α : A' ⟶ A) : α ≫ S.liftCycles k hk = S.liftCycles (α ≫ k) (by rw [assoc, hk, comp_zero]) := by cat_disch /-- Via `S.iCycles : S.cycles ⟶ S.X₂`, the object `S.cycles` identifies to the kernel of `S.g : S.X₂ ⟶ S.X₃`. -/ noncomputable def cyclesIsKernel : IsLimit (KernelFork.ofι S.iCycles S.iCycles_g) := S.leftHomologyData.hi /-- The canonical isomorphism `S.cycles ≅ kernel S.g`. -/ @[simps] noncomputable def cyclesIsoKernel [HasKernel S.g] : S.cycles ≅ kernel S.g where hom := kernel.lift S.g S.iCycles (by simp) inv := S.liftCycles (kernel.ι S.g) (by simp) /-- The morphism `A ⟶ S.leftHomology` obtained from a morphism `k : A ⟶ S.X₂` such that `k ≫ S.g = 0.` -/ @[simp] noncomputable def liftLeftHomology : A ⟶ S.leftHomology := S.liftCycles k hk ≫ S.leftHomologyπ @[reassoc] lemma liftCycles_leftHomologyπ_eq_zero_of_boundary (x : A ⟶ S.X₁) (hx : k = x ≫ S.f) : S.liftCycles k (by rw [hx, assoc, S.zero, comp_zero]) ≫ S.leftHomologyπ = 0 := LeftHomologyData.liftK_π_eq_zero_of_boundary _ k x hx @[reassoc (attr := simp)] lemma toCycles_comp_leftHomologyπ : S.toCycles ≫ S.leftHomologyπ = 0 := S.liftCycles_leftHomologyπ_eq_zero_of_boundary S.f (𝟙 _) (by rw [id_comp]) /-- Via `S.leftHomologyπ : S.cycles ⟶ S.leftHomology`, the object `S.leftHomology` identifies to the cokernel of `S.toCycles : S.X₁ ⟶ S.cycles`. -/ noncomputable def leftHomologyIsCokernel : IsColimit (CokernelCofork.ofπ S.leftHomologyπ S.toCycles_comp_leftHomologyπ) := S.leftHomologyData.hπ @[reassoc (attr := simp)] lemma liftCycles_comp_cyclesMap (φ : S ⟶ S₁) [S₁.HasLeftHomology] : S.liftCycles k hk ≫ cyclesMap φ = S₁.liftCycles (k ≫ φ.τ₂) (by rw [assoc, φ.comm₂₃, reassoc_of% hk, zero_comp]) := by cat_disch variable {S} @[reassoc (attr := simp)] lemma LeftHomologyData.liftCycles_comp_cyclesIso_hom : S.liftCycles k hk ≫ h.cyclesIso.hom = h.liftK k hk := by simp only [← cancel_mono h.i, assoc, LeftHomologyData.cyclesIso_hom_comp_i, liftCycles_i, LeftHomologyData.liftK_i] @[reassoc (attr := simp)] lemma LeftHomologyData.lift_K_comp_cyclesIso_inv : h.liftK k hk ≫ h.cyclesIso.inv = S.liftCycles k hk := by rw [← h.liftCycles_comp_cyclesIso_hom, assoc, Iso.hom_inv_id, comp_id] end namespace HasLeftHomology variable (S) lemma hasKernel [S.HasLeftHomology] : HasKernel S.g := ⟨⟨⟨_, S.leftHomologyData.hi⟩⟩⟩ lemma hasCokernel [S.HasLeftHomology] [HasKernel S.g] : HasCokernel (kernel.lift S.g S.f S.zero) := by let h := S.leftHomologyData haveI : HasColimit (parallelPair h.f' 0) := ⟨⟨⟨_, h.hπ'⟩⟩⟩ let e : parallelPair (kernel.lift S.g S.f S.zero) 0 ≅ parallelPair h.f' 0 := parallelPair.ext (Iso.refl _) (IsLimit.conePointUniqueUpToIso (kernelIsKernel S.g) h.hi) (by cat_disch) (by simp) exact hasColimit_of_iso e end HasLeftHomology /-- The left homology of a short complex `S` identifies to the cokernel of the canonical morphism `S.X₁ ⟶ kernel S.g`. -/ noncomputable def leftHomologyIsoCokernelLift [S.HasLeftHomology] [HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] : S.leftHomology ≅ cokernel (kernel.lift S.g S.f S.zero) := (LeftHomologyData.ofHasKernelOfHasCokernel S).leftHomologyIso /-! The following lemmas and instance gives a sufficient condition for a morphism of short complexes to induce an isomorphism on cycles. -/ lemma isIso_cyclesMap'_of_isIso_of_mono (φ : S₁ ⟶ S₂) (h₂ : IsIso φ.τ₂) (h₃ : Mono φ.τ₃) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) : IsIso (cyclesMap' φ h₁ h₂) := by refine ⟨h₁.liftK (h₂.i ≫ inv φ.τ₂) ?_, ?_, ?_⟩ · simp only [assoc, ← cancel_mono φ.τ₃, zero_comp, ← φ.comm₂₃, IsIso.inv_hom_id_assoc, h₂.wi] · simp only [← cancel_mono h₁.i, assoc, h₁.liftK_i, cyclesMap'_i_assoc, IsIso.hom_inv_id, comp_id, id_comp] · simp only [← cancel_mono h₂.i, assoc, cyclesMap'_i, h₁.liftK_i_assoc, IsIso.inv_hom_id, comp_id, id_comp] lemma isIso_cyclesMap_of_isIso_of_mono' (φ : S₁ ⟶ S₂) (h₂ : IsIso φ.τ₂) (h₃ : Mono φ.τ₃) [S₁.HasLeftHomology] [S₂.HasLeftHomology] : IsIso (cyclesMap φ) := isIso_cyclesMap'_of_isIso_of_mono φ h₂ h₃ _ _ instance isIso_cyclesMap_of_isIso_of_mono (φ : S₁ ⟶ S₂) [IsIso φ.τ₂] [Mono φ.τ₃] [S₁.HasLeftHomology] [S₂.HasLeftHomology] : IsIso (cyclesMap φ) := isIso_cyclesMap_of_isIso_of_mono' φ inferInstance inferInstance end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/ShortComplex/ModuleCat.lean
import Mathlib.Algebra.Homology.ShortComplex.ConcreteCategory import Mathlib.Algebra.Category.ModuleCat.Colimits /-! # Homology and exactness of short complexes of modules In this file, the homology of a short complex `S` of abelian groups is identified with the quotient of `LinearMap.ker S.g` by the image of the morphism `S.moduleCatToCycles : S.X₁ →ₗ[R] LinearMap.ker S.g` induced by `S.f`. -/ universe v u variable {R : Type u} [Ring R] namespace CategoryTheory open Limits namespace ShortComplex noncomputable instance : (forget₂ (ModuleCat.{v} R) Ab).PreservesHomology where /-- Constructor for short complexes in `ModuleCat.{v} R` taking as inputs linear maps `f` and `g` and the vanishing of their composition. -/ @[simps] def moduleCatMk {X₁ X₂ X₃ : Type v} [AddCommGroup X₁] [AddCommGroup X₂] [AddCommGroup X₃] [Module R X₁] [Module R X₂] [Module R X₃] (f : X₁ →ₗ[R] X₂) (g : X₂ →ₗ[R] X₃) (hfg : g.comp f = 0) : ShortComplex (ModuleCat.{v} R) := ShortComplex.mk (ModuleCat.ofHom f) (ModuleCat.ofHom g) (ModuleCat.hom_ext hfg) variable (S : ShortComplex (ModuleCat.{v} R)) @[simp] lemma moduleCat_zero_apply (x : S.X₁) : S.g (S.f x) = 0 := S.zero_apply x lemma moduleCat_exact_iff : S.Exact ↔ ∀ (x₂ : S.X₂) (_ : S.g x₂ = 0), ∃ (x₁ : S.X₁), S.f x₁ = x₂ := S.exact_iff_of_hasForget lemma moduleCat_exact_iff_ker_sub_range : S.Exact ↔ LinearMap.ker S.g.hom ≤ LinearMap.range S.f.hom := by rw [moduleCat_exact_iff] aesop lemma moduleCat_exact_iff_range_eq_ker : S.Exact ↔ LinearMap.range S.f.hom = LinearMap.ker S.g.hom := by rw [moduleCat_exact_iff_ker_sub_range] aesop variable {S} lemma Exact.moduleCat_range_eq_ker (hS : S.Exact) : LinearMap.range S.f.hom = LinearMap.ker S.g.hom := by simpa only [moduleCat_exact_iff_range_eq_ker] using hS lemma ShortExact.moduleCat_injective_f (hS : S.ShortExact) : Function.Injective S.f := hS.injective_f lemma ShortExact.moduleCat_surjective_g (hS : S.ShortExact) : Function.Surjective S.g := hS.surjective_g variable (S) lemma ShortExact.moduleCat_exact_iff_function_exact : S.Exact ↔ Function.Exact S.f S.g := by rw [moduleCat_exact_iff_range_eq_ker, LinearMap.exact_iff] tauto /-- Constructor for short complexes in `ModuleCat.{v} R` taking as inputs morphisms `f` and `g` and the assumption `LinearMap.range f ≤ LinearMap.ker g`. -/ @[simps] def moduleCatMkOfKerLERange {X₁ X₂ X₃ : ModuleCat.{v} R} (f : X₁ ⟶ X₂) (g : X₂ ⟶ X₃) (hfg : LinearMap.range f.hom ≤ LinearMap.ker g.hom) : ShortComplex (ModuleCat.{v} R) := ShortComplex.mk f g (by aesop) lemma Exact.moduleCat_of_range_eq_ker {X₁ X₂ X₃ : ModuleCat.{v} R} (f : X₁ ⟶ X₂) (g : X₂ ⟶ X₃) (hfg : LinearMap.range f.hom = LinearMap.ker g.hom) : (moduleCatMkOfKerLERange f g (by rw [hfg])).Exact := by simpa only [moduleCat_exact_iff_range_eq_ker] using hfg /-- The canonical linear map `S.X₁ →ₗ[R] LinearMap.ker S.g` induced by `S.f`. -/ abbrev moduleCatToCycles : S.X₁ →ₗ[R] LinearMap.ker S.g.hom := S.f.hom.codRestrict _ <| S.moduleCat_zero_apply /-- The explicit left homology data of a short complex of modules that is given by a kernel and a quotient given by the `LinearMap` API. The projections to `K` and `H` are not simp lemmas because the generic lemmas about `LeftHomologyData` are more useful here. -/ @[simps! K H i_hom π_hom] def moduleCatLeftHomologyData : S.LeftHomologyData where K := ModuleCat.of R (LinearMap.ker S.g.hom) H := ModuleCat.of R (LinearMap.ker S.g.hom ⧸ LinearMap.range S.moduleCatToCycles) i := ModuleCat.ofHom (LinearMap.ker S.g.hom).subtype π := ModuleCat.ofHom (LinearMap.range S.moduleCatToCycles).mkQ wi := by aesop hi := ModuleCat.kernelIsLimit _ wπ := by aesop hπ := ModuleCat.cokernelIsColimit (ModuleCat.ofHom S.moduleCatToCycles) /-- The homology of a short complex of modules as a concrete quotient. -/ @[deprecated "This abbreviation is now inlined" (since := "2025-05-14")] abbrev moduleCatHomology := S.moduleCatLeftHomologyData.H /-- The natural projection map to the homology of a short complex of modules as a concrete quotient. -/ @[deprecated "This abbreviation is now inlined" (since := "2025-05-14")] abbrev moduleCatHomologyπ := S.moduleCatLeftHomologyData.π @[deprecated (since := "2025-05-09")] alias moduleCatLeftHomologyData_i := moduleCatLeftHomologyData_i_hom @[deprecated (since := "2025-05-09")] alias moduleCatLeftHomologyData_π := moduleCatLeftHomologyData_π_hom @[simp] lemma moduleCatLeftHomologyData_f'_hom : S.moduleCatLeftHomologyData.f'.hom = S.moduleCatToCycles := rfl @[deprecated (since := "2025-05-09")] alias moduleCatLeftHomologyData_f' := moduleCatLeftHomologyData_f'_hom @[simp] lemma moduleCatLeftHomologyData_descH_hom {M : ModuleCat R} (φ : S.moduleCatLeftHomologyData.K ⟶ M) (h : S.moduleCatLeftHomologyData.f' ≫ φ = 0) : (S.moduleCatLeftHomologyData.descH φ h).hom = (LinearMap.range <| ModuleCat.Hom.hom _).liftQ φ.hom (LinearMap.range_le_ker_iff.2 <| ModuleCat.hom_ext_iff.1 h) := rfl @[simp] lemma moduleCatLeftHomologyData_liftK_hom {M : ModuleCat R} (φ : M ⟶ S.X₂) (h : φ ≫ S.g = 0) : (S.moduleCatLeftHomologyData.liftK φ h).hom = φ.hom.codRestrict (LinearMap.ker S.g.hom) (fun m => congr($h m)) := rfl /-- Given a short complex `S` of modules, this is the isomorphism between the abstract `S.cycles` of the homology API and the more concrete description as `LinearMap.ker S.g`. -/ noncomputable def moduleCatCyclesIso : S.cycles ≅ S.moduleCatLeftHomologyData.K := S.moduleCatLeftHomologyData.cyclesIso @[reassoc (attr := simp, elementwise)] lemma moduleCatCyclesIso_hom_i : S.moduleCatCyclesIso.hom ≫ S.moduleCatLeftHomologyData.i = S.iCycles := S.moduleCatLeftHomologyData.cyclesIso_hom_comp_i @[deprecated (since := "2025-05-09")] alias moduleCatCyclesIso_hom_subtype := moduleCatCyclesIso_hom_i @[reassoc (attr := simp, elementwise)] lemma moduleCatCyclesIso_inv_iCycles : S.moduleCatCyclesIso.inv ≫ S.iCycles = S.moduleCatLeftHomologyData.i := S.moduleCatLeftHomologyData.cyclesIso_inv_comp_iCycles @[reassoc (attr := simp, elementwise)] lemma toCycles_moduleCatCyclesIso_hom : S.toCycles ≫ S.moduleCatCyclesIso.hom = S.moduleCatLeftHomologyData.f' := by simp [← cancel_mono S.moduleCatLeftHomologyData.i] /-- Given a short complex `S` of modules, this is the isomorphism between the abstract `S.opcycles` of the homology API and the more concrete description as `S.X₂ ⧸ LinearMap.range S.f.hom`. -/ noncomputable def moduleCatOpcyclesIso : S.opcycles ≅ ModuleCat.of R (S.X₂ ⧸ LinearMap.range S.f.hom) := S.opcyclesIsoCokernel ≪≫ ModuleCat.cokernelIsoRangeQuotient _ @[reassoc (attr := simp), elementwise (attr := simp)] theorem pOpcycles_comp_moduleCatOpcyclesIso_hom : S.pOpcycles ≫ S.moduleCatOpcyclesIso.hom = ModuleCat.ofHom (Submodule.mkQ _) := by simp [moduleCatOpcyclesIso] theorem moduleCat_pOpcycles_eq_iff (x y : S.X₂) : S.pOpcycles x = S.pOpcycles y ↔ x - y ∈ LinearMap.range S.f.hom := Iff.trans ⟨fun h => by simpa using congr(S.moduleCatOpcyclesIso.hom $h), fun h => (ModuleCat.mono_iff_injective S.moduleCatOpcyclesIso.hom).1 inferInstance (by simpa)⟩ (Submodule.Quotient.eq _) theorem moduleCat_pOpcycles_eq_zero_iff (x : S.X₂) : S.pOpcycles x = 0 ↔ x ∈ LinearMap.range S.f.hom := by simpa using moduleCat_pOpcycles_eq_iff _ x 0 /-- Given a short complex `S` of modules, this is the isomorphism between the abstract `S.homology` of the homology API and the more explicit quotient of `LinearMap.ker S.g` by the image of `S.moduleCatToCycles : S.X₁ →ₗ[R] LinearMap.ker S.g`. -/ noncomputable def moduleCatHomologyIso : S.homology ≅ S.moduleCatLeftHomologyData.H := S.moduleCatLeftHomologyData.homologyIso @[reassoc (attr := simp, elementwise)] lemma π_moduleCatCyclesIso_hom : S.homologyπ ≫ S.moduleCatHomologyIso.hom = S.moduleCatCyclesIso.hom ≫ S.moduleCatLeftHomologyData.π := S.moduleCatLeftHomologyData.homologyπ_comp_homologyIso_hom @[reassoc (attr := simp, elementwise)] lemma moduleCatCyclesIso_inv_π : S.moduleCatCyclesIso.inv ≫ S.homologyπ = S.moduleCatLeftHomologyData.π ≫ S.moduleCatHomologyIso.inv := S.moduleCatLeftHomologyData.π_comp_homologyIso_inv lemma exact_iff_surjective_moduleCatToCycles : S.Exact ↔ Function.Surjective S.moduleCatToCycles := by simp [S.moduleCatLeftHomologyData.exact_iff_epi_f', ModuleCat.epi_iff_surjective, moduleCatLeftHomologyData_K] end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/SingleTriangle.lean
import Mathlib.Algebra.Homology.DerivedCategory.ShortExact /-! # The distinguished triangle of a short exact sequence in an abelian category Given a short exact short complex `S` in an abelian category, we construct the associated distinguished triangle in the derived category: `(singleFunctor C 0).obj S.X₁ ⟶ (singleFunctor C 0).obj S.X₂ ⟶ (singleFunctor C 0).obj S.X₃ ⟶ ...` ## TODO * when the canonical t-structure on the derived category is formalized, refactor this definition to make it a particular case of the triangle induced by a short exact sequence in the heart of a t-structure -/ assert_not_exists TwoSidedIdeal universe w v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Abelian C] [HasDerivedCategory.{w} C] open Category DerivedCategory Pretriangulated namespace ShortComplex variable {S : ShortComplex C} (hS : S.ShortExact) namespace ShortExact /-- The connecting homomorphism `(singleFunctor C 0).obj S.X₃ ⟶ ((singleFunctor C 0).obj S.X₁)⟦(1 : ℤ)⟧` in the derived category of `C` when `S` is a short exact short complex in `C`. -/ noncomputable def singleδ : (singleFunctor C 0).obj S.X₃ ⟶ ((singleFunctor C 0).obj S.X₁)⟦(1 : ℤ)⟧ := (((SingleFunctors.evaluation _ _ 0).mapIso (singleFunctorsPostcompQIso C)).hom.app S.X₃) ≫ triangleOfSESδ (hS.map_of_exact (HomologicalComplex.single C (ComplexShape.up ℤ) 0)) ≫ (((SingleFunctors.evaluation _ _ 0).mapIso (singleFunctorsPostcompQIso C)).inv.app S.X₁)⟦(1 : ℤ)⟧' /-- The (distinguished) triangle in the derived category of `C` given by a short exact short complex in `C`. -/ @[simps!] noncomputable def singleTriangle : Triangle (DerivedCategory C) := Triangle.mk ((singleFunctor C 0).map S.f) ((singleFunctor C 0).map S.g) hS.singleδ /-- Given a short exact complex `S` in `C` that is short exact (`hS`), this is the canonical isomorphism between the triangle `hS.singleTriangle` in the derived category and the triangle attached to the corresponding short exact sequence of cochain complexes after the application of the single functor. -/ @[simps!] noncomputable def singleTriangleIso : hS.singleTriangle ≅ triangleOfSES (hS.map_of_exact (HomologicalComplex.single C (ComplexShape.up ℤ) 0)) := by let e := (SingleFunctors.evaluation _ _ 0).mapIso (singleFunctorsPostcompQIso C) refine Triangle.isoMk _ _ (e.app S.X₁) (e.app S.X₂) (e.app S.X₃) ?_ ?_ ?_ · cat_disch · cat_disch · simp [singleδ, e, ← Functor.map_comp, CochainComplex.singleFunctors] /-- The distinguished triangle in the derived category of `C` given by a short exact short complex in `C`. -/ lemma singleTriangle_distinguished : hS.singleTriangle ∈ distTriang (DerivedCategory C) := isomorphic_distinguished _ (triangleOfSES_distinguished (hS.map_of_exact (HomologicalComplex.single C (ComplexShape.up ℤ) 0))) _ (singleTriangleIso hS) end ShortExact end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Linear.lean
import Mathlib.Algebra.Homology.DerivedCategory.Basic import Mathlib.Algebra.Homology.Linear import Mathlib.CategoryTheory.Localization.Linear import Mathlib.CategoryTheory.Shift.Linear /-! # The derived category of a linear abelian category is linear -/ open CategoryTheory Category Limits Pretriangulated ZeroObject Preadditive universe t w v u variable (R : Type t) [Ring R] (C : Type u) [Category.{v} C] [Abelian C] [Linear R C] [HasDerivedCategory.{w} C] namespace DerivedCategory noncomputable instance : Linear R (DerivedCategory C) := Localization.linear R (DerivedCategory.Qh : _ ⥤ DerivedCategory C) (HomotopyCategory.quasiIso C _) instance : Functor.Linear R (DerivedCategory.Qh : _ ⥤ DerivedCategory C) := Localization.functor_linear _ _ _ instance : Functor.Linear R (DerivedCategory.Q : _ ⥤ DerivedCategory C) := Functor.linear_of_iso _ (quotientCompQhIso C) instance (n : ℤ) : (shiftFunctor (DerivedCategory C) n).Linear R := Shift.linear_of_localization R Qh (HomotopyCategory.subcategoryAcyclic C).trW _ instance (n : ℤ) : Functor.Linear R (DerivedCategory.singleFunctor C n) := inferInstanceAs (Functor.Linear R (HomotopyCategory.singleFunctor C n ⋙ Qh)) end DerivedCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/TStructure.lean
import Mathlib.Algebra.Homology.DerivedCategory.Fractions import Mathlib.Algebra.Homology.DerivedCategory.ShortExact import Mathlib.Algebra.Homology.Embedding.CochainComplex import Mathlib.CategoryTheory.Triangulated.TStructure.Basic /-! # The canonical t-structure on the derived category In this file, we introduce the canonical t-structure on the derived category of an abelian category. -/ open CategoryTheory Category Pretriangulated Triangulated Limits Preadditive universe w v u namespace DerivedCategory variable {C : Type u} [Category.{v} C] [Abelian C] [HasDerivedCategory.{w} C] /-- The canonical t-structure on `DerivedCategory C`. -/ def TStructure.t : TStructure (DerivedCategory C) where le n X := ∃ (K : CochainComplex C ℤ) (_ : X ≅ DerivedCategory.Q.obj K), K.IsStrictlyLE n ge n X := ∃ (K : CochainComplex C ℤ) (_ : X ≅ DerivedCategory.Q.obj K), K.IsStrictlyGE n le_isClosedUnderIsomorphisms n := { of_iso := by rintro X Y e ⟨K, e', _⟩ exact ⟨K, e.symm ≪≫ e', inferInstance⟩ } ge_isClosedUnderIsomorphisms n := { of_iso := by rintro X Y e ⟨K, e', _⟩ exact ⟨K, e.symm ≪≫ e', inferInstance⟩ } le_shift := by rintro n a n' h X ⟨K, e, _⟩ exact ⟨(shiftFunctor (CochainComplex C ℤ) a).obj K, (shiftFunctor (DerivedCategory C) a).mapIso e ≪≫ (Q.commShiftIso a).symm.app K, K.isStrictlyLE_shift n a n' h⟩ ge_shift := by rintro n a n' h X ⟨K, e, _⟩ exact ⟨(shiftFunctor (CochainComplex C ℤ) a).obj K, (shiftFunctor (DerivedCategory C) a).mapIso e ≪≫ (Q.commShiftIso a).symm.app K, K.isStrictlyGE_shift n a n' h⟩ zero' X Y f := by rintro ⟨K, e₁, _⟩ ⟨L, e₂, _⟩ rw [← cancel_epi e₁.inv, ← cancel_mono e₂.hom, comp_zero, zero_comp] apply (subsingleton_hom_of_isStrictlyLE_of_isStrictlyGE K L 0 1 (by simp)).elim le_zero_le := by rintro X ⟨K, e, _⟩ exact ⟨K, e, K.isStrictlyLE_of_le 0 1 (by omega)⟩ ge_one_le := by rintro X ⟨K, e, _⟩ exact ⟨K, e, K.isStrictlyGE_of_ge 0 1 (by omega)⟩ exists_triangle_zero_one X := by obtain ⟨K, ⟨e₂⟩⟩ : ∃ K, Nonempty (Q.obj K ≅ X) := ⟨_, ⟨Q.objObjPreimageIso X⟩⟩ have h := K.shortComplexTruncLE_shortExact 0 refine ⟨Q.obj (K.truncLE 0), Q.obj (K.truncGE 1), ⟨_, Iso.refl _, inferInstance⟩, ⟨_, Iso.refl _, inferInstance⟩, Q.map (K.ιTruncLE 0) ≫ e₂.hom, e₂.inv ≫ Q.map (K.πTruncGE 1), inv (Q.map (K.shortComplexTruncLEX₃ToTruncGE 0 1 (by omega))) ≫ (triangleOfSES h).mor₃, isomorphic_distinguished _ (triangleOfSES_distinguished h) _ (Iso.symm ?_)⟩ refine Triangle.isoMk _ _ (Iso.refl _) e₂ (asIso (Q.map (K.shortComplexTruncLEX₃ToTruncGE 0 1 (by omega)))) ?_ ?_ (by simp) · dsimp rw [id_comp] rfl · dsimp rw [← Q.map_comp, CochainComplex.g_shortComplexTruncLEX₃ToTruncGE, Iso.hom_inv_id_assoc] /-- Given `X : DerivedCategory C` and `n : ℤ`, this property means that `X` is `≤ n` for the canonical t-structure. -/ abbrev IsLE (X : DerivedCategory C) (n : ℤ) : Prop := TStructure.t.IsLE X n /-- Given `X : DerivedCategory C` and `n : ℤ`, this property means that `X` is `≥ n` for the canonical t-structure. -/ abbrev IsGE (X : DerivedCategory C) (n : ℤ) : Prop := TStructure.t.IsGE X n lemma isGE_iff (X : DerivedCategory C) (n : ℤ) : X.IsGE n ↔ ∀ (i : ℤ) (_ : i < n), IsZero ((homologyFunctor C i).obj X) := by constructor · rintro ⟨K, e, _⟩ i hi apply ((K.exactAt_of_isGE n i hi).isZero_homology).of_iso exact (homologyFunctor C i).mapIso e ≪≫ (homologyFunctorFactors C i).app K · intro hX have : (Q.objPreimage X).IsGE n := by rw [CochainComplex.isGE_iff] intro i hi rw [HomologicalComplex.exactAt_iff_isZero_homology] apply (hX i hi).of_iso exact (homologyFunctorFactors C i).symm.app _ ≪≫ (homologyFunctor C i).mapIso (Q.objObjPreimageIso X) exact ⟨(Q.objPreimage X).truncGE n, (Q.objObjPreimageIso X).symm ≪≫ asIso (Q.map ((Q.objPreimage X).πTruncGE n)), inferInstance⟩ lemma isLE_iff (X : DerivedCategory C) (n : ℤ) : X.IsLE n ↔ ∀ (i : ℤ) (_ : n < i), IsZero ((homologyFunctor C i).obj X) := by constructor · rintro ⟨K, e, _⟩ i hi apply ((K.exactAt_of_isLE n i hi).isZero_homology).of_iso exact (homologyFunctor C i).mapIso e ≪≫ (homologyFunctorFactors C i).app K · intro hX have : (Q.objPreimage X).IsLE n := by rw [CochainComplex.isLE_iff] intro i hi rw [HomologicalComplex.exactAt_iff_isZero_homology] apply (hX i hi).of_iso exact (homologyFunctorFactors C i).symm.app _ ≪≫ (homologyFunctor C i).mapIso (Q.objObjPreimageIso X) exact ⟨(Q.objPreimage X).truncLE n, (Q.objObjPreimageIso X).symm ≪≫ (asIso (Q.map ((Q.objPreimage X).ιTruncLE n))).symm, inferInstance⟩ lemma isZero_of_isGE (X : DerivedCategory C) (n i : ℤ) (hi : i < n) [hX : X.IsGE n] : IsZero ((homologyFunctor _ i).obj X) := by rw [isGE_iff] at hX exact hX i hi lemma isZero_of_isLE (X : DerivedCategory C) (n i : ℤ) (hi : n < i) [hX : X.IsLE n] : IsZero ((homologyFunctor _ i).obj X) := by rw [isLE_iff] at hX exact hX i hi lemma isGE_Q_obj_iff (K : CochainComplex C ℤ) (n : ℤ) : (Q.obj K).IsGE n ↔ K.IsGE n := by have eq := fun i ↦ ((homologyFunctorFactors C i).app K).isZero_iff simp only [Functor.comp_obj, HomologicalComplex.homologyFunctor_obj] at eq simp only [isGE_iff, CochainComplex.isGE_iff, HomologicalComplex.exactAt_iff_isZero_homology, eq] lemma isLE_Q_obj_iff (K : CochainComplex C ℤ) (n : ℤ) : (Q.obj K).IsLE n ↔ K.IsLE n := by have eq := fun i ↦ ((homologyFunctorFactors C i).app K).isZero_iff simp only [Functor.comp_obj, HomologicalComplex.homologyFunctor_obj] at eq simp only [isLE_iff, CochainComplex.isLE_iff, HomologicalComplex.exactAt_iff_isZero_homology, eq] instance (K : CochainComplex C ℤ) (n : ℤ) [K.IsGE n] : (Q.obj K).IsGE n := by rw [isGE_Q_obj_iff] infer_instance instance (K : CochainComplex C ℤ) (n : ℤ) [K.IsLE n] : (Q.obj K).IsLE n := by rw [isLE_Q_obj_iff] infer_instance instance (X : C) (n : ℤ) : ((singleFunctor C n).obj X).IsGE n := by let e := (singleFunctorIsoCompQ C n).app X dsimp only [Functor.comp_obj] at e exact TStructure.t.isGE_of_iso e.symm n instance (X : C) (n : ℤ) : ((singleFunctor C n).obj X).IsLE n := by let e := (singleFunctorIsoCompQ C n).app X dsimp only [Functor.comp_obj] at e exact TStructure.t.isLE_of_iso e.symm n lemma exists_iso_Q_obj_of_isLE (X : DerivedCategory C) (n : ℤ) [hX : X.IsLE n] : ∃ (K : CochainComplex C ℤ) (_ : K.IsStrictlyLE n), Nonempty (X ≅ Q.obj K) := by obtain ⟨K, e, _⟩ := hX exact ⟨K, inferInstance, ⟨e⟩⟩ lemma exists_iso_Q_obj_of_isGE (X : DerivedCategory C) (n : ℤ) [hX : X.IsGE n] : ∃ (K : CochainComplex C ℤ) (_ : K.IsStrictlyGE n), Nonempty (X ≅ Q.obj K) := by obtain ⟨K, e, _⟩ := hX exact ⟨K, inferInstance, ⟨e⟩⟩ lemma exists_iso_Q_obj_of_isGE_of_isLE (X : DerivedCategory C) (a b : ℤ) [X.IsGE a] [X.IsLE b] : ∃ (K : CochainComplex C ℤ) (_ : K.IsStrictlyGE a) (_ : K.IsStrictlyLE b), Nonempty (X ≅ Q.obj K) := by obtain ⟨K, hK, ⟨e⟩⟩ := X.exists_iso_Q_obj_of_isLE b have : K.IsGE a := by rw [← isGE_Q_obj_iff] exact TStructure.t.isGE_of_iso e a exact ⟨K.truncGE a, inferInstance, inferInstance, ⟨e ≪≫ asIso (Q.map (K.πTruncGE a))⟩⟩ end DerivedCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Basic.lean
import Mathlib.Algebra.Homology.HomotopyCategory.HomologicalFunctor import Mathlib.Algebra.Homology.HomotopyCategory.ShiftSequence import Mathlib.Algebra.Homology.HomotopyCategory.SingleFunctors import Mathlib.Algebra.Homology.HomotopyCategory.Triangulated import Mathlib.Algebra.Homology.Localization /-! # The derived category of an abelian category In this file, we construct the derived category `DerivedCategory C` of an abelian category `C`. It is equipped with a triangulated structure. The derived category is defined here as the localization of cochain complexes indexed by `ℤ` with respect to quasi-isomorphisms: it is a type synonym of `HomologicalComplexUpToQuasiIso C (ComplexShape.up ℤ)`. Then, we have a localization functor `DerivedCategory.Q : CochainComplex C ℤ ⥤ DerivedCategory C`. It was already shown in the file `Algebra.Homology.Localization` that the induced functor `DerivedCategory.Qh : HomotopyCategory C (ComplexShape.up ℤ) ⥤ DerivedCategory C` is a localization functor with respect to the class of morphisms `HomotopyCategory.quasiIso C (ComplexShape.up ℤ)`. In the lemma `HomotopyCategory.quasiIso_eq_subcategoryAcyclic_W` we obtain that this class of morphisms consists of morphisms whose cone belongs to the triangulated subcategory `HomotopyCategory.subcategoryAcyclic C` of acyclic complexes. Then, the triangulated structure on `DerivedCategory C` is deduced from the triangulated structure on the homotopy category (see file `Algebra.Homology.HomotopyCategory.Triangulated`) using the localization theorem for triangulated categories which was obtained in the file `CategoryTheory.Localization.Triangulated`. ## Implementation notes If `C : Type u` and `Category.{v} C`, the constructed localized category of cochain complexes with respect to quasi-isomorphisms has morphisms in `Type (max u v)`. However, in certain circumstances, it shall be possible to prove that they are `v`-small (when `C` is a Grothendieck abelian category (e.g. the category of modules over a ring), it should be so by a theorem of Hovey.). Then, when working with derived categories in mathlib, the user should add the variable `[HasDerivedCategory.{w} C]` which is the assumption that there is a chosen derived category with morphisms in `Type w`. When derived categories are used in order to prove statements which do not involve derived categories, the `HasDerivedCategory.{max u v}` instance should be obtained at the beginning of the proof, using the term `HasDerivedCategory.standard C`. ## TODO (@joelriou) - construct the distinguished triangle associated to a short exact sequence of cochain complexes (done), and compare the associated connecting homomorphism with the one defined in `Algebra.Homology.HomologySequence`. ## References * [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996] * [Mark Hovey, *Model category structures on chain complexes of sheaves*][hovey-2001] -/ assert_not_exists TwoSidedIdeal universe w v u open CategoryTheory Limits Pretriangulated variable (C : Type u) [Category.{v} C] [Abelian C] namespace HomotopyCategory /-- The triangulated subcategory of `HomotopyCategory C (ComplexShape.up ℤ)` consisting of acyclic complexes. -/ def subcategoryAcyclic : ObjectProperty (HomotopyCategory C (ComplexShape.up ℤ)) := (homologyFunctor C (ComplexShape.up ℤ) 0).homologicalKernel instance : (subcategoryAcyclic C).IsTriangulated := by dsimp [subcategoryAcyclic] infer_instance instance : (subcategoryAcyclic C).IsClosedUnderIsomorphisms := by dsimp [subcategoryAcyclic] infer_instance variable {C} lemma mem_subcategoryAcyclic_iff (X : HomotopyCategory C (ComplexShape.up ℤ)) : subcategoryAcyclic C X ↔ ∀ (n : ℤ), IsZero ((homologyFunctor _ _ n).obj X) := Functor.mem_homologicalKernel_iff _ X lemma quotient_obj_mem_subcategoryAcyclic_iff_exactAt (K : CochainComplex C ℤ) : subcategoryAcyclic C ((quotient _ _).obj K) ↔ ∀ (n : ℤ), K.ExactAt n := by rw [mem_subcategoryAcyclic_iff] refine forall_congr' (fun n => ?_) simp only [HomologicalComplex.exactAt_iff_isZero_homology] exact ((homologyFunctorFactors C (ComplexShape.up ℤ) n).app K).isZero_iff variable (C) lemma quasiIso_eq_subcategoryAcyclic_W : quasiIso C (ComplexShape.up ℤ) = (subcategoryAcyclic C).trW := by ext K L f exact ((homologyFunctor C (ComplexShape.up ℤ) 0).mem_homologicalKernel_trW_iff f).symm end HomotopyCategory /-- The assumption that a localized category for `(HomologicalComplex.quasiIso C (ComplexShape.up ℤ))` has been chosen, and that the morphisms in this chosen category are in `Type w`. -/ abbrev HasDerivedCategory := MorphismProperty.HasLocalization.{w} (HomologicalComplex.quasiIso C (ComplexShape.up ℤ)) /-- The derived category obtained using the constructed localized category of cochain complexes with respect to quasi-isomorphisms. This should be used only while proving statements which do not involve the derived category. -/ def HasDerivedCategory.standard : HasDerivedCategory.{max u v} C := MorphismProperty.HasLocalization.standard _ variable [HasDerivedCategory.{w} C] /-- The derived category of an abelian category. -/ def DerivedCategory : Type (max u v) := HomologicalComplexUpToQuasiIso C (ComplexShape.up ℤ) namespace DerivedCategory instance : Category.{w} (DerivedCategory C) := by dsimp [DerivedCategory] infer_instance variable {C} /-- The localization functor `CochainComplex C ℤ ⥤ DerivedCategory C`. -/ def Q : CochainComplex C ℤ ⥤ DerivedCategory C := HomologicalComplexUpToQuasiIso.Q instance : (Q (C := C)).IsLocalization (HomologicalComplex.quasiIso C (ComplexShape.up ℤ)) := by dsimp only [Q, DerivedCategory] infer_instance instance {K L : CochainComplex C ℤ} (f : K ⟶ L) [QuasiIso f] : IsIso (Q.map f) := Localization.inverts Q (HomologicalComplex.quasiIso C (ComplexShape.up ℤ)) _ (inferInstanceAs (QuasiIso f)) /-- The localization functor `HomotopyCategory C (ComplexShape.up ℤ) ⥤ DerivedCategory C`. -/ def Qh : HomotopyCategory C (ComplexShape.up ℤ) ⥤ DerivedCategory C := HomologicalComplexUpToQuasiIso.Qh variable (C) /-- The natural isomorphism `HomotopyCategory.quotient C (ComplexShape.up ℤ) ⋙ Qh ≅ Q`. -/ def quotientCompQhIso : HomotopyCategory.quotient C (ComplexShape.up ℤ) ⋙ Qh ≅ Q := HomologicalComplexUpToQuasiIso.quotientCompQhIso C (ComplexShape.up ℤ) instance : Qh.IsLocalization (HomotopyCategory.quasiIso C (ComplexShape.up ℤ)) := by dsimp [Qh, DerivedCategory] infer_instance instance : Qh.IsLocalization (HomotopyCategory.subcategoryAcyclic C).trW := by rw [← HomotopyCategory.quasiIso_eq_subcategoryAcyclic_W] infer_instance noncomputable instance : Preadditive (DerivedCategory C) := Localization.preadditive Qh (HomotopyCategory.subcategoryAcyclic C).trW instance : (Qh (C := C)).Additive := Localization.functor_additive Qh (HomotopyCategory.subcategoryAcyclic C).trW instance : (Q (C := C)).Additive := Functor.additive_of_iso (quotientCompQhIso C) noncomputable instance : HasZeroObject (DerivedCategory C) := Q.hasZeroObject_of_additive noncomputable instance : HasShift (DerivedCategory C) ℤ := HasShift.localized Qh (HomotopyCategory.subcategoryAcyclic C).trW ℤ noncomputable instance : (Qh (C := C)).CommShift ℤ := Functor.CommShift.localized Qh (HomotopyCategory.subcategoryAcyclic C).trW ℤ noncomputable instance : (Q (C := C)).CommShift ℤ := Functor.CommShift.ofIso (quotientCompQhIso C) ℤ instance : NatTrans.CommShift (quotientCompQhIso C).hom ℤ := Functor.CommShift.ofIso_compatibility (quotientCompQhIso C) ℤ instance (n : ℤ) : (shiftFunctor (DerivedCategory C) n).Additive := by rw [Localization.functor_additive_iff Qh (HomotopyCategory.subcategoryAcyclic C).trW] exact Functor.additive_of_iso (Qh.commShiftIso n) noncomputable instance : Pretriangulated (DerivedCategory C) := Triangulated.Localization.pretriangulated Qh (HomotopyCategory.subcategoryAcyclic C).trW instance : (Qh (C := C)).IsTriangulated := Triangulated.Localization.isTriangulated_functor Qh (HomotopyCategory.subcategoryAcyclic C).trW noncomputable instance : IsTriangulated (DerivedCategory C) := Triangulated.Localization.isTriangulated Qh (HomotopyCategory.subcategoryAcyclic C).trW instance : (Qh (C := C)).mapArrow.EssSurj := Localization.essSurj_mapArrow _ (HomotopyCategory.subcategoryAcyclic C).trW instance {D : Type*} [Category D] : ((Functor.whiskeringLeft _ _ D).obj (Qh (C := C))).Full := inferInstanceAs (Localization.whiskeringLeftFunctor' _ (HomotopyCategory.quasiIso _ _) D).Full instance {D : Type*} [Category D] : ((Functor.whiskeringLeft _ _ D).obj (Qh (C := C))).Faithful := inferInstanceAs (Localization.whiskeringLeftFunctor' _ (HomotopyCategory.quasiIso _ _) D).Faithful instance : (Qh : _ ⥤ DerivedCategory C).EssSurj := Localization.essSurj _ (HomotopyCategory.quasiIso _ _) instance : (Q : _ ⥤ DerivedCategory C).EssSurj := Localization.essSurj _ (HomologicalComplex.quasiIso _ _) variable {C} in lemma mem_distTriang_iff (T : Triangle (DerivedCategory C)) : (T ∈ distTriang (DerivedCategory C)) ↔ ∃ (X Y : CochainComplex C ℤ) (f : X ⟶ Y), Nonempty (T ≅ Q.mapTriangle.obj (CochainComplex.mappingCone.triangle f)) := by constructor · rintro ⟨T', e, ⟨X, Y, f, ⟨e'⟩⟩⟩ refine ⟨_, _, f, ⟨?_⟩⟩ exact e ≪≫ Qh.mapTriangle.mapIso e' ≪≫ (Functor.mapTriangleCompIso (HomotopyCategory.quotient C _) Qh).symm.app _ ≪≫ (Functor.mapTriangleIso (quotientCompQhIso C)).app _ · rintro ⟨X, Y, f, ⟨e⟩⟩ refine isomorphic_distinguished _ (Qh.map_distinguished _ ?_) _ (e ≪≫ (Functor.mapTriangleIso (quotientCompQhIso C)).symm.app _ ≪≫ (Functor.mapTriangleCompIso (HomotopyCategory.quotient C _) Qh).app _) exact ⟨_, _, f, ⟨Iso.refl _⟩⟩ /-- The single functors `C ⥤ DerivedCategory C` for all `n : ℤ` along with their compatibilities with shifts. -/ noncomputable def singleFunctors : SingleFunctors C (DerivedCategory C) ℤ := (HomotopyCategory.singleFunctors C).postcomp Qh /-- The shift functor `C ⥤ DerivedCategory C` which sends `X : C` to the single cochain complex with `X` sitting in degree `n : ℤ`. -/ noncomputable abbrev singleFunctor (n : ℤ) := (singleFunctors C).functor n instance (n : ℤ) : (singleFunctor C n).Additive := by dsimp [singleFunctor, singleFunctors] infer_instance -- The object level definitional equality underlying `singleFunctorsPostcompQhIso`. @[simp] theorem Qh_obj_singleFunctors_obj (n : ℤ) (X : C) : Qh.obj (((HomotopyCategory.singleFunctors C).functor n).obj X) = (singleFunctor C n).obj X := by rfl /-- The isomorphism `DerivedCategory.singleFunctors C ≅ (HomotopyCategory.singleFunctors C).postcomp Qh` given by the definition of `DerivedCategory.singleFunctors`. -/ noncomputable def singleFunctorsPostcompQhIso : singleFunctors C ≅ (HomotopyCategory.singleFunctors C).postcomp Qh := Iso.refl _ /-- The isomorphism `DerivedCategory.singleFunctors C ≅ (CochainComplex.singleFunctors C).postcomp Q`. -/ noncomputable def singleFunctorsPostcompQIso : singleFunctors C ≅ (CochainComplex.singleFunctors C).postcomp Q := (SingleFunctors.postcompFunctor C ℤ (Qh : _ ⥤ DerivedCategory C)).mapIso (HomotopyCategory.singleFunctorsPostcompQuotientIso C) ≪≫ (CochainComplex.singleFunctors C).postcompPostcompIso (HomotopyCategory.quotient _ _) Qh ≪≫ SingleFunctors.postcompIsoOfIso (CochainComplex.singleFunctors C) (quotientCompQhIso C) lemma singleFunctorsPostcompQIso_hom_hom (n : ℤ) : (singleFunctorsPostcompQIso C).hom.hom n = 𝟙 _ := by ext X dsimp [singleFunctorsPostcompQIso, HomotopyCategory.singleFunctorsPostcompQuotientIso, quotientCompQhIso, HomologicalComplexUpToQuasiIso.quotientCompQhIso] rw [CategoryTheory.Functor.map_id, Category.id_comp] erw [Category.id_comp] rfl lemma singleFunctorsPostcompQIso_inv_hom (n : ℤ) : (singleFunctorsPostcompQIso C).inv.hom n = 𝟙 _ := by ext X simp [singleFunctorsPostcompQIso, HomotopyCategory.singleFunctorsPostcompQuotientIso] rfl /-- The isomorphism `singleFunctor C n ≅ CochainComplex.singleFunctor C n ⋙ Q`. -/ noncomputable def singleFunctorIsoCompQ (n : ℤ) : singleFunctor C n ≅ CochainComplex.singleFunctor C n ⋙ Q := Iso.refl _ lemma isIso_Q_map_iff_quasiIso {K L : CochainComplex C ℤ} (φ : K ⟶ L) : IsIso (Q.map φ) ↔ QuasiIso φ := by apply HomologicalComplexUpToQuasiIso.isIso_Q_map_iff_mem_quasiIso end DerivedCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/ExactFunctor.lean
import Mathlib.Algebra.Homology.DerivedCategory.Basic /-! # An exact functor induces a functor on derived categories In this file, we show that if `F : C₁ ⥤ C₂` is an exact functor between abelian categories, then there is an induced triangulated functor `F.mapDerivedCategory : DerivedCategory C₁ ⥤ DerivedCategory C₂`. -/ assert_not_exists TwoSidedIdeal universe w₁ w₂ v₁ v₂ u₁ u₂ open CategoryTheory Category Limits variable {C₁ : Type u₁} [Category.{v₁} C₁] [Abelian C₁] [HasDerivedCategory.{w₁} C₁] {C₂ : Type u₂} [Category.{v₂} C₂] [Abelian C₂] [HasDerivedCategory.{w₂} C₂] (F : C₁ ⥤ C₂) [F.Additive] [PreservesFiniteLimits F] [PreservesFiniteColimits F] namespace CategoryTheory.Functor /-- The functor `DerivedCategory C₁ ⥤ DerivedCategory C₂` induced by an exact functor `F : C₁ ⥤ C₂` between abelian categories. -/ noncomputable def mapDerivedCategory : DerivedCategory C₁ ⥤ DerivedCategory C₂ := F.mapHomologicalComplexUpToQuasiIso (ComplexShape.up ℤ) /-- The functor `F.mapDerivedCategory` is induced by `F.mapHomologicalComplex (ComplexShape.up ℤ)`. -/ noncomputable def mapDerivedCategoryFactors : DerivedCategory.Q ⋙ F.mapDerivedCategory ≅ F.mapHomologicalComplex (ComplexShape.up ℤ) ⋙ DerivedCategory.Q := F.mapHomologicalComplexUpToQuasiIsoFactors _ noncomputable instance : Localization.Lifting DerivedCategory.Q (HomologicalComplex.quasiIso C₁ (ComplexShape.up ℤ)) (F.mapHomologicalComplex _ ⋙ DerivedCategory.Q) F.mapDerivedCategory := ⟨F.mapDerivedCategoryFactors⟩ /-- The functor `F.mapDerivedCategory` is induced by `F.mapHomotopyCategory (ComplexShape.up ℤ)`. -/ noncomputable def mapDerivedCategoryFactorsh : DerivedCategory.Qh ⋙ F.mapDerivedCategory ≅ F.mapHomotopyCategory (ComplexShape.up ℤ) ⋙ DerivedCategory.Qh := F.mapHomologicalComplexUpToQuasiIsoFactorsh _ lemma mapDerivedCategoryFactorsh_hom_app (K : CochainComplex C₁ ℤ) : F.mapDerivedCategoryFactorsh.hom.app ((HomotopyCategory.quotient _ _).obj K) = F.mapDerivedCategory.map ((DerivedCategory.quotientCompQhIso C₁).hom.app K) ≫ F.mapDerivedCategoryFactors.hom.app K ≫ (DerivedCategory.quotientCompQhIso C₂).inv.app _ ≫ DerivedCategory.Qh.map ((F.mapHomotopyCategoryFactors (ComplexShape.up ℤ)).inv.app K) := F.mapHomologicalComplexUpToQuasiIsoFactorsh_hom_app K noncomputable instance : Localization.Lifting DerivedCategory.Qh (HomotopyCategory.quasiIso C₁ (ComplexShape.up ℤ)) (F.mapHomotopyCategory _ ⋙ DerivedCategory.Qh) F.mapDerivedCategory := ⟨F.mapDerivedCategoryFactorsh⟩ noncomputable instance : F.mapDerivedCategory.CommShift ℤ := Functor.commShiftOfLocalization DerivedCategory.Qh (HomotopyCategory.quasiIso C₁ (ComplexShape.up ℤ)) ℤ (F.mapHomotopyCategory _ ⋙ DerivedCategory.Qh) F.mapDerivedCategory instance : NatTrans.CommShift F.mapDerivedCategoryFactorsh.hom ℤ := inferInstanceAs (NatTrans.CommShift (Localization.Lifting.iso DerivedCategory.Qh (HomotopyCategory.quasiIso C₁ (ComplexShape.up ℤ)) (F.mapHomotopyCategory _ ⋙ DerivedCategory.Qh) F.mapDerivedCategory).hom ℤ) instance : NatTrans.CommShift F.mapDerivedCategoryFactors.hom ℤ := NatTrans.CommShift.verticalComposition (DerivedCategory.quotientCompQhIso C₁).inv (DerivedCategory.quotientCompQhIso C₂).hom (F.mapHomotopyCategoryFactors (ComplexShape.up ℤ)).hom F.mapDerivedCategoryFactorsh.hom F.mapDerivedCategoryFactors.hom ℤ (by ext K dsimp simp only [id_comp, mapDerivedCategoryFactorsh_hom_app, assoc, comp_id, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, map_id, comp_obj]) instance : F.mapDerivedCategory.IsTriangulated := Functor.isTriangulated_of_precomp_iso F.mapDerivedCategoryFactorsh end CategoryTheory.Functor
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/ShortExact.lean
import Mathlib.Algebra.Homology.HomotopyCategory.ShortExact import Mathlib.Algebra.Homology.DerivedCategory.Basic /-! # The distinguished triangle attached to a short exact sequence of cochain complexes Given a short exact short complex `S` in the category `CochainComplex C ℤ`, we construct a distinguished triangle `Q.obj S.X₁ ⟶ Q.obj S.X₂ ⟶ Q.obj S.X₃ ⟶ (Q.obj S.X₃)⟦1⟧` in the derived category of `C`. (See `triangleOfSES` and `triangleOfSES_distinguished`.) -/ assert_not_exists TwoSidedIdeal universe w v u open CategoryTheory Category Pretriangulated namespace DerivedCategory variable {C : Type u} [Category.{v} C] [Abelian C] [HasDerivedCategory.{w} C] {S : ShortComplex (CochainComplex C ℤ)} (hS : S.ShortExact) /-- The connecting homomorphism `Q.obj (S.X₃) ⟶ (Q.obj S.X₁)⟦(1 : ℤ)⟧` in the derived category when `S` is a short exact short complex of cochain complexes in an abelian category. -/ noncomputable def triangleOfSESδ : Q.obj (S.X₃) ⟶ (Q.obj S.X₁)⟦(1 : ℤ)⟧ := have := CochainComplex.mappingCone.quasiIso_descShortComplex hS inv (Q.map (CochainComplex.mappingCone.descShortComplex S)) ≫ Q.map (CochainComplex.mappingCone.triangle S.f).mor₃ ≫ (Q.commShiftIso (1 : ℤ)).hom.app S.X₁ /-- The distinguished triangle in the derived category associated to a short exact sequence of cochain complexes. -/ @[simps!] noncomputable def triangleOfSES : Triangle (DerivedCategory C) := Triangle.mk (Q.map S.f) (Q.map S.g) (triangleOfSESδ hS) /-- The triangle `triangleOfSES` attached to a short exact sequence `S` of cochain complexes is isomorphism to the standard distinguished triangle associated to the morphism `S.f`. -/ noncomputable def triangleOfSESIso : triangleOfSES hS ≅ Q.mapTriangle.obj (CochainComplex.mappingCone.triangle S.f) := by have := CochainComplex.mappingCone.quasiIso_descShortComplex hS refine Iso.symm (Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (asIso (Q.map (CochainComplex.mappingCone.descShortComplex S))) ?_ ?_ ?_) · dsimp [triangleOfSES] simp only [comp_id, id_comp] · dsimp simp only [← Q.map_comp, CochainComplex.mappingCone.inr_descShortComplex, id_comp] · dsimp [triangleOfSESδ] rw [CategoryTheory.Functor.map_id, comp_id, IsIso.hom_inv_id_assoc] lemma triangleOfSES_distinguished : triangleOfSES hS ∈ distTriang (DerivedCategory C) := by rw [mem_distTriang_iff] exact ⟨_, _, S.f, ⟨triangleOfSESIso hS⟩⟩ end DerivedCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/HomologySequence.lean
import Mathlib.Algebra.Homology.DerivedCategory.Basic /-! # The homology sequence In this file, we construct `homologyFunctor C n : DerivedCategory C ⥤ C` for all `n : ℤ`, show that they are homological functors which form a shift sequence, and construct the long exact homology sequences associated to distinguished triangles in the derived category. -/ assert_not_exists TwoSidedIdeal universe w v u open CategoryTheory Pretriangulated variable (C : Type u) [Category.{v} C] [Abelian C] [HasDerivedCategory.{w} C] namespace DerivedCategory /-- The homology functor `DerivedCategory C ⥤ C` in degree `n : ℤ`. -/ noncomputable def homologyFunctor (n : ℤ) : DerivedCategory C ⥤ C := HomologicalComplexUpToQuasiIso.homologyFunctor C (ComplexShape.up ℤ) n /-- The homology functor on the derived category is induced by the homology functor on the category of cochain complexes. -/ noncomputable def homologyFunctorFactors (n : ℤ) : Q ⋙ homologyFunctor C n ≅ HomologicalComplex.homologyFunctor _ _ n := HomologicalComplexUpToQuasiIso.homologyFunctorFactors C (ComplexShape.up ℤ) n /-- The homology functor on the derived category is induced by the homology functor on the homotopy category of cochain complexes. -/ noncomputable def homologyFunctorFactorsh (n : ℤ) : Qh ⋙ homologyFunctor C n ≅ HomotopyCategory.homologyFunctor _ _ n := HomologicalComplexUpToQuasiIso.homologyFunctorFactorsh C (ComplexShape.up ℤ) n variable {C} in lemma isIso_Qh_map_iff {X Y : HomotopyCategory C (ComplexShape.up ℤ)} (f : X ⟶ Y) : IsIso (Qh.map f) ↔ HomotopyCategory.quasiIso C _ f := by constructor · intro hf rw [HomotopyCategory.mem_quasiIso_iff] intro n rw [← NatIso.isIso_map_iff (homologyFunctorFactorsh C n) f] dsimp infer_instance · exact Localization.inverts Qh (HomotopyCategory.quasiIso _ _) _ instance (n : ℤ) : (homologyFunctor C n).IsHomological := Functor.isHomological_of_localization Qh (homologyFunctor C n) _ (homologyFunctorFactorsh C n) /-- The functors `homologyFunctor C n : DerivedCategory C ⥤ C` for all `n : ℤ` are part of a "shift sequence", i.e. they satisfy compatibilities with shifts. -/ noncomputable instance : (homologyFunctor C 0).ShiftSequence ℤ := Functor.ShiftSequence.induced (homologyFunctorFactorsh C 0) ℤ (homologyFunctor C) (homologyFunctorFactorsh C) variable {C} namespace HomologySequence /-- The connecting homomorphism on the homology sequence attached to a distinguished triangle in the derived category. -/ noncomputable def δ (T : Triangle (DerivedCategory C)) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) : (homologyFunctor C n₀).obj T.obj₃ ⟶ (homologyFunctor C n₁).obj T.obj₁ := (homologyFunctor C 0).shiftMap T.mor₃ n₀ n₁ (by rw [add_comm 1, h]) variable (T : Triangle (DerivedCategory C)) (hT : T ∈ distTriang _) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) include hT @[reassoc (attr := simp)] lemma comp_δ : (homologyFunctor C n₀).map T.mor₂ ≫ δ T n₀ n₁ h = 0 := (homologyFunctor C 0).comp_homologySequenceδ _ hT _ _ h @[reassoc (attr := simp)] lemma δ_comp : δ T n₀ n₁ h ≫ (homologyFunctor C n₁).map T.mor₁ = 0 := (homologyFunctor C 0).homologySequenceδ_comp _ hT _ _ h lemma exact₂ : (ShortComplex.mk ((homologyFunctor C n₀).map T.mor₁) ((homologyFunctor C n₀).map T.mor₂) (by simp only [← Functor.map_comp, comp_distTriang_mor_zero₁₂ _ hT, Functor.map_zero])).Exact := (homologyFunctor C 0).homologySequence_exact₂ _ hT _ lemma exact₃ : (ShortComplex.mk _ _ (comp_δ T hT n₀ n₁ h)).Exact := (homologyFunctor C 0).homologySequence_exact₃ _ hT _ _ h lemma exact₁ : (ShortComplex.mk _ _ (δ_comp T hT n₀ n₁ h)).Exact := (homologyFunctor C 0).homologySequence_exact₁ _ hT _ _ h lemma epi_homologyMap_mor₁_iff : Epi ((homologyFunctor C n₀).map T.mor₁) ↔ (homologyFunctor C n₀).map T.mor₂ = 0 := (homologyFunctor C 0).homologySequence_epi_shift_map_mor₁_iff _ hT _ lemma mono_homologyMap_mor₁_iff : Mono ((homologyFunctor C n₁).map T.mor₁) ↔ δ T n₀ n₁ h = 0 := (homologyFunctor C 0).homologySequence_mono_shift_map_mor₁_iff _ hT _ _ h lemma epi_homologyMap_mor₂_iff : Epi ((homologyFunctor C n₀).map T.mor₂) ↔ δ T n₀ n₁ h = 0 := (homologyFunctor C 0).homologySequence_epi_shift_map_mor₂_iff _ hT _ _ h lemma mono_homologyMap_mor₂_iff : Mono ((homologyFunctor C n₀).map T.mor₂) ↔ (homologyFunctor C n₀).map T.mor₁ = 0 := (homologyFunctor C 0).homologySequence_mono_shift_map_mor₂_iff _ hT n₀ end HomologySequence end DerivedCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/FullyFaithful.lean
import Mathlib.Algebra.Homology.DerivedCategory.Fractions import Mathlib.Algebra.Homology.SingleHomology /-! # The fully faithful embedding of the abelian category in its derived category In this file, we show that for any `n : ℤ`, the functor `singleFunctor C n : C ⥤ DerivedCategory C` is fully faithful. -/ universe w v u open CategoryTheory namespace DerivedCategory variable (C : Type u) [Category.{v} C] [Abelian C] [HasDerivedCategory.{w} C] /-- The canonical isomorphism `DerivedCategory.singleFunctor C n ⋙ DerivedCategory.homologyFunctor C n ≅ 𝟭 C` -/ noncomputable def singleFunctorCompHomologyFunctorIso (n : ℤ) : singleFunctor C n ⋙ homologyFunctor C n ≅ 𝟭 C := Functor.isoWhiskerRight ((SingleFunctors.evaluation _ _ n).mapIso (singleFunctorsPostcompQIso C)) _ ≪≫ Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft _ (homologyFunctorFactors C n) ≪≫ (HomologicalComplex.homologyFunctorSingleIso _ _ _) instance (n : ℤ) : (singleFunctor C n).Faithful where map_injective {_ _ f₁ f₂} h := by have eq₁ := NatIso.naturality_1 (singleFunctorCompHomologyFunctorIso C n) f₁ have eq₂ := NatIso.naturality_1 (singleFunctorCompHomologyFunctorIso C n) f₂ dsimp at eq₁ eq₂ rw [← eq₁, ← eq₂, h] instance (n : ℤ) : (singleFunctor C n).Full where map_surjective {A B} f := by change Q.obj ((CochainComplex.singleFunctor C n).obj A) ⟶ Q.obj ((CochainComplex.singleFunctor C n).obj B) at f suffices ∃ f', f = Q.map f' by obtain ⟨f', rfl⟩ := this obtain ⟨g, rfl⟩ := (CochainComplex.singleFunctor C n).map_surjective f' exact ⟨g, rfl⟩ obtain ⟨X, _, _, s, _, g, rfl⟩ := right_fac_of_isStrictlyLE_of_isStrictlyGE n n f obtain ⟨A₀, ⟨e⟩⟩ := X.exists_iso_single n have ⟨φ, hφ⟩ := (CochainComplex.singleFunctor C n).map_surjective (e.inv ≫ s) have : IsIso ((singleFunctor C n).map φ) := by change IsIso (Q.map ((CochainComplex.singleFunctor C n).map φ)) rw [hφ, Functor.map_comp] infer_instance have : IsIso φ := (NatIso.isIso_map_iff (singleFunctorCompHomologyFunctorIso C n) φ).1 (by dsimp; infer_instance) have : IsIso (e.inv ≫ s) := by rw [← hφ]; infer_instance have : IsIso s := IsIso.of_isIso_comp_left e.inv s exact ⟨inv s ≫ g, by simp⟩ end DerivedCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Fractions.lean
import Mathlib.Algebra.Homology.DerivedCategory.HomologySequence import Mathlib.Algebra.Homology.Embedding.CochainComplex /-! # Calculus of fractions in the derived category We obtain various consequences of the calculus of left and right fractions for `HomotopyCategory.quasiIso C (ComplexShape.up ℤ)` as lemmas about factorizations of morphisms `f : Q.obj X ⟶ Q.obj Y` (where `X` and `Y` are cochain complexes). These `f` can be factored as a right fraction `inv (Q.map s) ≫ Q.map g` or as a left fraction `Q.map g ≫ inv (Q.map s)`, with `s` a quasi-isomorphism (to `X` or from `Y`). When strict bounds are known on `X` or `Y`, certain bounds may also be ensured on the auxiliary object appearing in the fraction. -/ universe w v u open CategoryTheory Category Limits namespace DerivedCategory variable {C : Type u} [Category.{v} C] [Abelian C] [HasDerivedCategory.{w} C] instance : (HomotopyCategory.quasiIso C (ComplexShape.up ℤ)).HasLeftCalculusOfFractions := by rw [HomotopyCategory.quasiIso_eq_subcategoryAcyclic_W] infer_instance instance : (HomotopyCategory.quasiIso C (ComplexShape.up ℤ)).HasRightCalculusOfFractions := by rw [HomotopyCategory.quasiIso_eq_subcategoryAcyclic_W] infer_instance /-- Any morphism `f : Q.obj X ⟶ Q.obj Y` in the derived category can be written as `f = inv (Q.map s) ≫ Q.map g` with `s : X' ⟶ X` a quasi-isomorphism and `g : X' ⟶ Y`. -/ lemma right_fac {X Y : CochainComplex C ℤ} (f : Q.obj X ⟶ Q.obj Y) : ∃ (X' : CochainComplex C ℤ) (s : X' ⟶ X) (_ : IsIso (Q.map s)) (g : X' ⟶ Y), f = inv (Q.map s) ≫ Q.map g := by have ⟨φ, hφ⟩ := Localization.exists_rightFraction Qh (HomotopyCategory.quasiIso C _) f obtain ⟨X', s, hs, g, rfl⟩ := φ.cases obtain ⟨X', rfl⟩ := HomotopyCategory.quotient_obj_surjective X' obtain ⟨s, rfl⟩ := (HomotopyCategory.quotient _ _).map_surjective s obtain ⟨g, rfl⟩ := (HomotopyCategory.quotient _ _).map_surjective g rw [← isIso_Qh_map_iff] at hs exact ⟨X', s, hs, g, hφ⟩ /-- Any morphism `f : Q.obj X ⟶ Q.obj Y` in the derived category can be written as `f = Q.map g ≫ inv (Q.map s)` with `g : X ⟶ Y'` and `s : Y ⟶ Y'` a quasi-isomorphism. -/ lemma left_fac {X Y : CochainComplex C ℤ} (f : Q.obj X ⟶ Q.obj Y) : ∃ (Y' : CochainComplex C ℤ) (g : X ⟶ Y') (s : Y ⟶ Y') (_ : IsIso (Q.map s)), f = Q.map g ≫ inv (Q.map s) := by have ⟨φ, hφ⟩ := Localization.exists_leftFraction Qh (HomotopyCategory.quasiIso C _) f obtain ⟨X', g, s, hs, rfl⟩ := φ.cases obtain ⟨X', rfl⟩ := HomotopyCategory.quotient_obj_surjective X' obtain ⟨s, rfl⟩ := (HomotopyCategory.quotient _ _).map_surjective s obtain ⟨g, rfl⟩ := (HomotopyCategory.quotient _ _).map_surjective g rw [← isIso_Qh_map_iff] at hs exact ⟨X', g, s, hs, hφ⟩ /-- Any morphism `f : Q.obj X ⟶ Q.obj Y` in the derived category with `X` strictly `≤ n` can be written as `f = inv (Q.map s) ≫ Q.map g` with `s : X' ⟶ X` a quasi-isomorphism with `X'` strictly `≤ n` and `g : X' ⟶ Y`. -/ lemma right_fac_of_isStrictlyLE {X Y : CochainComplex C ℤ} (f : Q.obj X ⟶ Q.obj Y) (n : ℤ) [X.IsStrictlyLE n] : ∃ (X' : CochainComplex C ℤ) (_ : X'.IsStrictlyLE n) (s : X' ⟶ X) (_ : IsIso (Q.map s)) (g : X' ⟶ Y), f = inv (Q.map s) ≫ Q.map g := by obtain ⟨X', s, hs, g, rfl⟩ := right_fac f have : IsIso (Q.map (CochainComplex.truncLEMap s n)) := by rw [isIso_Q_map_iff_quasiIso, CochainComplex.quasiIso_truncLEMap_iff] rw [isIso_Q_map_iff_quasiIso] at hs infer_instance refine ⟨X'.truncLE n, inferInstance, CochainComplex.truncLEMap s n ≫ X.ιTruncLE n, ?_, CochainComplex.truncLEMap g n ≫ Y.ιTruncLE n, ?_⟩ · rw [Q.map_comp] infer_instance · simp /-- Any morphism `f : Q.obj X ⟶ Q.obj Y` in the derived category with `Y` strictly `≥ n` can be written as `f = Q.map g ≫ inv (Q.map s)` with `g : X ⟶ Y'` and `s : Y ⟶ Y'` a quasi-isomorphism with `Y'` strictly `≥ n`. -/ lemma left_fac_of_isStrictlyGE {X Y : CochainComplex C ℤ} (f : Q.obj X ⟶ Q.obj Y) (n : ℤ) [Y.IsStrictlyGE n] : ∃ (Y' : CochainComplex C ℤ) (_ : Y'.IsStrictlyGE n) (g : X ⟶ Y') (s : Y ⟶ Y') (_ : IsIso (Q.map s)), f = Q.map g ≫ inv (Q.map s) := by obtain ⟨Y', g, s, hs, rfl⟩ := left_fac f have : IsIso (Q.map (CochainComplex.truncGEMap s n)) := by rw [isIso_Q_map_iff_quasiIso, CochainComplex.quasiIso_truncGEMap_iff] rw [isIso_Q_map_iff_quasiIso] at hs infer_instance refine ⟨Y'.truncGE n, inferInstance, X.πTruncGE n ≫ CochainComplex.truncGEMap g n, Y.πTruncGE n ≫ CochainComplex.truncGEMap s n, ?_, ?_⟩ · rw [Q.map_comp] infer_instance · have eq := Q.congr_map (CochainComplex.πTruncGE_naturality s n) have eq' := Q.congr_map (CochainComplex.πTruncGE_naturality g n) simp only [Functor.map_comp] at eq eq' simp only [Functor.map_comp, ← cancel_mono (Q.map (CochainComplex.πTruncGE Y n) ≫ Q.map (CochainComplex.truncGEMap s n)), assoc, IsIso.inv_hom_id, comp_id] simp only [eq, IsIso.inv_hom_id_assoc, eq'] /-- Any morphism `f : Q.obj X ⟶ Q.obj Y` in the derived category with `X` strictly `≥ a` and `≤ b`, and `Y` strictly `≥ a` can be written as `f = inv (Q.map s) ≫ Q.map g` with `s : X' ⟶ X` a quasi-isomorphism with `X'` strictly `≥ a` and `≤ b`, and `g : X' ⟶ Y`. -/ lemma right_fac_of_isStrictlyLE_of_isStrictlyGE {X Y : CochainComplex C ℤ} (a b : ℤ) [X.IsStrictlyGE a] [X.IsStrictlyLE b] [Y.IsStrictlyGE a] (f : Q.obj X ⟶ Q.obj Y) : ∃ (X' : CochainComplex C ℤ) ( _ : X'.IsStrictlyGE a) (_ : X'.IsStrictlyLE b) (s : X' ⟶ X) (_ : IsIso (Q.map s)) (g : X' ⟶ Y), f = inv (Q.map s) ≫ Q.map g := by obtain ⟨X', hX', s, hs, g, fac⟩ := right_fac_of_isStrictlyLE f b have : IsIso (Q.map (CochainComplex.truncGEMap s a)) := by rw [isIso_Q_map_iff_quasiIso] at hs rw [isIso_Q_map_iff_quasiIso, CochainComplex.quasiIso_truncGEMap_iff] infer_instance refine ⟨X'.truncGE a, inferInstance, inferInstance, CochainComplex.truncGEMap s a ≫ inv (X.πTruncGE a), ?_, CochainComplex.truncGEMap g a ≫ inv (Y.πTruncGE a), ?_⟩ · rw [Q.map_comp] infer_instance · simp only [Functor.map_comp, Functor.map_inv, IsIso.inv_comp, IsIso.inv_inv, assoc, fac, ← cancel_epi (Q.map s), IsIso.hom_inv_id_assoc] rw [← Functor.map_comp_assoc, ← CochainComplex.πTruncGE_naturality s a, Functor.map_comp, assoc, IsIso.hom_inv_id_assoc, ← Functor.map_comp_assoc, CochainComplex.πTruncGE_naturality g a, Functor.map_comp, assoc, IsIso.hom_inv_id, comp_id] /-- Any morphism `f : Q.obj X ⟶ Q.obj Y` in the derived category with `X` strictly `≤ b`, and `Y` strictly `≥ a` and `≤ b` can be written as `f = Q.map g ≫ inv (Q.map s)` with `g : X ⟶ Y'` and `s : Y ⟶ Y'` a quasi-isomorphism with `Y'` strictly `≥ a` and `≤ b`. -/ lemma left_fac_of_isStrictlyLE_of_isStrictlyGE {X Y : CochainComplex C ℤ} (a b : ℤ) [X.IsStrictlyLE b] [Y.IsStrictlyGE a] [Y.IsStrictlyLE b] (f : Q.obj X ⟶ Q.obj Y) : ∃ (Y' : CochainComplex C ℤ) ( _ : Y'.IsStrictlyGE a) (_ : Y'.IsStrictlyLE b) (g : X ⟶ Y') (s : Y ⟶ Y') (_ : IsIso (Q.map s)), f = Q.map g ≫ inv (Q.map s) := by obtain ⟨Y', hY', g, s, hs, fac⟩ := left_fac_of_isStrictlyGE f a have : IsIso (Q.map (CochainComplex.truncLEMap s b)) := by rw [isIso_Q_map_iff_quasiIso] at hs rw [isIso_Q_map_iff_quasiIso, CochainComplex.quasiIso_truncLEMap_iff] infer_instance refine ⟨Y'.truncLE b, inferInstance, inferInstance, inv (X.ιTruncLE b) ≫ CochainComplex.truncLEMap g b, inv (Y.ιTruncLE b) ≫ CochainComplex.truncLEMap s b, ?_, ?_⟩ · rw [Q.map_comp] infer_instance · simp only [Functor.map_comp, Functor.map_inv, IsIso.inv_comp, IsIso.inv_inv, assoc, fac, ← cancel_mono (Q.map s), IsIso.inv_hom_id, comp_id] rw [← Functor.map_comp, ← CochainComplex.ιTruncLE_naturality s b, Functor.map_comp, IsIso.inv_hom_id_assoc, ← Functor.map_comp, CochainComplex.ιTruncLE_naturality g b, Functor.map_comp, IsIso.inv_hom_id_assoc] lemma subsingleton_hom_of_isStrictlyLE_of_isStrictlyGE (X Y : CochainComplex C ℤ) (a b : ℤ) (h : a < b) [X.IsStrictlyLE a] [Y.IsStrictlyGE b] : Subsingleton (Q.obj X ⟶ Q.obj Y) := by suffices ∀ (f : Q.obj X ⟶ Q.obj Y), f = 0 from ⟨by simp [this]⟩ intro f obtain ⟨X', _, s, _, g, rfl⟩ := right_fac_of_isStrictlyLE f a have : g = 0 := by ext i by_cases hi : a < i · apply (X'.isZero_of_isStrictlyLE a i hi).eq_of_src · apply (Y.isZero_of_isStrictlyGE b i (by cutsat)).eq_of_tgt rw [this, Q.map_zero, comp_zero] end DerivedCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Ext/ExtClass.lean
import Mathlib.Algebra.Homology.DerivedCategory.Ext.Basic import Mathlib.Algebra.Homology.DerivedCategory.SingleTriangle /-! # The Ext class of a short exact sequence In this file, given a short exact short complex `S : ShortComplex C` in an abelian category, we construct the associated class in `Ext S.X₃ S.X₁ 1`. -/ assert_not_exists TwoSidedIdeal universe w' w v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Abelian C] [HasExt.{w} C] open Localization Limits ZeroObject DerivedCategory Pretriangulated open Abelian namespace ShortComplex variable (S : ShortComplex C) lemma ext_mk₀_f_comp_ext_mk₀_g : (Ext.mk₀ S.f).comp (Ext.mk₀ S.g) (zero_add 0) = 0 := by simp namespace ShortExact variable {S} variable (hS : S.ShortExact) section local notation "W" => HomologicalComplex.quasiIso C (ComplexShape.up ℤ) local notation "S'" => S.map (CochainComplex.singleFunctor C 0) local notation "hS'" => hS.map_of_exact (HomologicalComplex.single _ _ _) local notation "K" => CochainComplex.mappingCone (ShortComplex.f S') local notation "qis" => CochainComplex.mappingCone.descShortComplex S' local notation "hqis" => CochainComplex.mappingCone.quasiIso_descShortComplex hS' local notation "δ" => Triangle.mor₃ (CochainComplex.mappingCone.triangle (ShortComplex.f S')) instance : HasSmallLocalizedShiftedHom.{w} W ℤ (S').X₃ (S').X₁ := by dsimp infer_instance include hS in private lemma hasSmallLocalizedHom_S'_X₃_K : HasSmallLocalizedHom.{w} W (S').X₃ K := by rw [Localization.hasSmallLocalizedHom_iff_target W (S').X₃ qis hqis] dsimp apply Localization.hasSmallLocalizedHom_of_hasSmallLocalizedShiftedHom₀ (M := ℤ) include hS in private lemma hasSmallLocalizedShiftedHom_K_S'_X₁ : HasSmallLocalizedShiftedHom.{w} W ℤ K (S').X₁ := by rw [Localization.hasSmallLocalizedShiftedHom_iff_source.{w} W ℤ qis hqis (S').X₁] infer_instance /-- The class in `Ext S.X₃ S.X₁ 1` that is attached to a short exact short complex `S` in an abelian category. -/ noncomputable def extClass : Ext.{w} S.X₃ S.X₁ 1 := by have := hS.hasSmallLocalizedHom_S'_X₃_K have := hS.hasSmallLocalizedShiftedHom_K_S'_X₁ change SmallHom W (S').X₃ ((S').X₁⟦(1 : ℤ)⟧) exact (SmallHom.mkInv qis hqis).comp (SmallHom.mk W δ) @[simp] lemma extClass_hom [HasDerivedCategory.{w'} C] : hS.extClass.hom = hS.singleδ := by change SmallShiftedHom.equiv W Q hS.extClass = _ dsimp [extClass, SmallShiftedHom.equiv] erw [SmallHom.equiv_comp, Iso.homToEquiv_apply] rw [SmallHom.equiv_mkInv, SmallHom.equiv_mk] dsimp [singleδ, triangleOfSESδ] rw [Category.assoc, Category.assoc, Category.assoc, singleFunctorsPostcompQIso_hom_hom, singleFunctorsPostcompQIso_inv_hom, NatTrans.id_app, Category.id_comp, NatTrans.id_app] simp only [SingleFunctors.postcomp, Functor.comp_obj] unfold CochainComplex.singleFunctors rw [Functor.map_id, Category.comp_id] rfl end @[simp] lemma comp_extClass : (Ext.mk₀ S.g).comp hS.extClass (zero_add 1) = 0 := by letI := HasDerivedCategory.standard C ext simp only [Ext.comp_hom, Ext.mk₀_hom, extClass_hom, Ext.zero_hom, ShiftedHom.mk₀_comp] exact comp_distTriang_mor_zero₂₃ _ hS.singleTriangle_distinguished @[simp] lemma comp_extClass_assoc {Y : C} {n : ℕ} (γ : Ext S.X₁ Y n) {n' : ℕ} (h : 1 + n = n') : (Ext.mk₀ S.g).comp (hS.extClass.comp γ h) (zero_add n') = 0 := by rw [← Ext.comp_assoc (a₁₂ := 1) _ _ _ (by cutsat) (by cutsat) (by cutsat), comp_extClass, Ext.zero_comp] @[simp] lemma extClass_comp : hS.extClass.comp (Ext.mk₀ S.f) (add_zero 1) = 0 := by letI := HasDerivedCategory.standard C ext simp only [Ext.comp_hom, Ext.mk₀_hom, extClass_hom, Ext.zero_hom, ShiftedHom.comp_mk₀] exact comp_distTriang_mor_zero₃₁ _ hS.singleTriangle_distinguished @[simp] lemma extClass_comp_assoc {Y : C} {n : ℕ} (γ : Ext S.X₂ Y n) {n' : ℕ} {h : 1 + n = n'} : hS.extClass.comp ((Ext.mk₀ S.f).comp γ (zero_add n)) h = 0 := by rw [← Ext.comp_assoc (a₁₂ := 1) _ _ _ (by cutsat) (by cutsat) (by cutsat), extClass_comp, Ext.zero_comp] end ShortExact end ShortComplex end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Ext/ExactSequences.lean
import Mathlib.Algebra.Homology.DerivedCategory.Ext.ExtClass import Mathlib.CategoryTheory.Triangulated.Yoneda /-! # Long exact sequences of `Ext`-groups In this file, we obtain the covariant long exact sequence of `Ext` when `n₀ + 1 = n₁`: `Ext X S.X₁ n₀ → Ext X S.X₂ n₀ → Ext X S.X₃ n₀ → Ext X S.X₁ n₁ → Ext X S.X₂ n₁ → Ext X S.X₃ n₁` when `S` is a short exact short complex in an abelian category `C`, `n₀ + 1 = n₁` and `X : C`. Similarly, if `Y : C`, there is a contravariant long exact sequence : `Ext S.X₃ Y n₀ → Ext S.X₂ Y n₀ → Ext S.X₁ Y n₀ → Ext S.X₃ Y n₁ → Ext S.X₂ Y n₁ → Ext S.X₁ Y n₁`. -/ assert_not_exists TwoSidedIdeal universe w' w v u namespace CategoryTheory open Opposite DerivedCategory Pretriangulated Pretriangulated.Opposite variable {C : Type u} [Category.{v} C] [Abelian C] [HasExt.{w} C] namespace Abelian namespace Ext section CovariantSequence lemma hom_comp_singleFunctor_map_shift [HasDerivedCategory.{w'} C] {X Y Z : C} {n : ℕ} (x : Ext X Y n) (f : Y ⟶ Z) : x.hom ≫ ((DerivedCategory.singleFunctor C 0).map f)⟦(n : ℤ)⟧' = (x.comp (mk₀ f) (add_zero n)).hom := by simp only [comp_hom, mk₀_hom, ShiftedHom.comp_mk₀] variable {X : C} {S : ShortComplex C} (hS : S.ShortExact) lemma preadditiveCoyoneda_homologySequenceδ_singleTriangle_apply [HasDerivedCategory.{w'} C] {X : C} {n₀ : ℕ} (x : Ext X S.X₃ n₀) {n₁ : ℕ} (h : n₀ + 1 = n₁) : (preadditiveCoyoneda.obj (op ((singleFunctor C 0).obj X))).homologySequenceδ hS.singleTriangle n₀ n₁ (by cutsat) x.hom = (x.comp hS.extClass h).hom := by rw [Pretriangulated.preadditiveCoyoneda_homologySequenceδ_apply, comp_hom, hS.extClass_hom, ShiftedHom.comp] rfl variable (X) include hS in /-- Alternative formulation of `covariant_sequence_exact₂` -/ lemma covariant_sequence_exact₂' (n : ℕ) : (ShortComplex.mk (AddCommGrpCat.ofHom ((mk₀ S.f).postcomp X (add_zero n))) (AddCommGrpCat.ofHom ((mk₀ S.g).postcomp X (add_zero n))) (by ext x dsimp simp only [comp_assoc_of_third_deg_zero, mk₀_comp_mk₀, ShortComplex.zero, mk₀_zero, comp_zero])).Exact := by letI := HasDerivedCategory.standard C have := (preadditiveCoyoneda.obj (op ((singleFunctor C 0).obj X))).homologySequence_exact₂ _ (hS.singleTriangle_distinguished) n rw [ShortComplex.ab_exact_iff_function_exact] at this ⊢ apply Function.Exact.of_ladder_addEquiv_of_exact' (e₁ := Ext.homAddEquiv) (e₂ := Ext.homAddEquiv) (e₃ := Ext.homAddEquiv) (H := this) all_goals ext x; apply hom_comp_singleFunctor_map_shift (C := C) section variable (n₀ n₁ : ℕ) (h : n₀ + 1 = n₁) /-- Alternative formulation of `covariant_sequence_exact₃` -/ lemma covariant_sequence_exact₃' : (ShortComplex.mk (AddCommGrpCat.ofHom ((mk₀ S.g).postcomp X (add_zero n₀))) (AddCommGrpCat.ofHom (hS.extClass.postcomp X h)) (by ext x dsimp simp only [comp_assoc_of_second_deg_zero, ShortComplex.ShortExact.comp_extClass, comp_zero])).Exact := by letI := HasDerivedCategory.standard C have := (preadditiveCoyoneda.obj (op ((singleFunctor C 0).obj X))).homologySequence_exact₃ _ (hS.singleTriangle_distinguished) n₀ n₁ (by cutsat) rw [ShortComplex.ab_exact_iff_function_exact] at this ⊢ apply Function.Exact.of_ladder_addEquiv_of_exact' (e₁ := Ext.homAddEquiv) (e₂ := Ext.homAddEquiv) (e₃ := Ext.homAddEquiv) (H := this) · ext x; apply hom_comp_singleFunctor_map_shift (C := C) · ext x exact preadditiveCoyoneda_homologySequenceδ_singleTriangle_apply hS x h /-- Alternative formulation of `covariant_sequence_exact₁` -/ lemma covariant_sequence_exact₁' : (ShortComplex.mk (AddCommGrpCat.ofHom (hS.extClass.postcomp X h)) (AddCommGrpCat.ofHom ((mk₀ S.f).postcomp X (add_zero n₁))) (by ext x dsimp simp only [comp_assoc_of_third_deg_zero, ShortComplex.ShortExact.extClass_comp, comp_zero])).Exact := by letI := HasDerivedCategory.standard C have := (preadditiveCoyoneda.obj (op ((singleFunctor C 0).obj X))).homologySequence_exact₁ _ (hS.singleTriangle_distinguished) n₀ n₁ (by cutsat) rw [ShortComplex.ab_exact_iff_function_exact] at this ⊢ apply Function.Exact.of_ladder_addEquiv_of_exact' (e₁ := Ext.homAddEquiv) (e₂ := Ext.homAddEquiv) (e₃ := Ext.homAddEquiv) (H := this) · ext x exact preadditiveCoyoneda_homologySequenceδ_singleTriangle_apply hS x h · ext x; apply hom_comp_singleFunctor_map_shift (C := C) open ComposableArrows /-- Given a short exact short complex `S` in an abelian category `C` and an object `X : C`, this is the long exact sequence `Ext X S.X₁ n₀ → Ext X S.X₂ n₀ → Ext X S.X₃ n₀ → Ext X S.X₁ n₁ → Ext X S.X₂ n₁ → Ext X S.X₃ n₁` when `n₀ + 1 = n₁` -/ noncomputable def covariantSequence : ComposableArrows AddCommGrpCat.{w} 5 := mk₅ (AddCommGrpCat.ofHom ((mk₀ S.f).postcomp X (add_zero n₀))) (AddCommGrpCat.ofHom ((mk₀ S.g).postcomp X (add_zero n₀))) (AddCommGrpCat.ofHom (hS.extClass.postcomp X h)) (AddCommGrpCat.ofHom ((mk₀ S.f).postcomp X (add_zero n₁))) (AddCommGrpCat.ofHom ((mk₀ S.g).postcomp X (add_zero n₁))) lemma covariantSequence_exact : (covariantSequence X hS n₀ n₁ h).Exact := exact_of_δ₀ (covariant_sequence_exact₂' X hS n₀).exact_toComposableArrows (exact_of_δ₀ (covariant_sequence_exact₃' X hS n₀ n₁ h).exact_toComposableArrows (exact_of_δ₀ (covariant_sequence_exact₁' X hS n₀ n₁ h).exact_toComposableArrows (covariant_sequence_exact₂' X hS n₁).exact_toComposableArrows)) end lemma covariant_sequence_exact₁ {n₁ : ℕ} (x₁ : Ext X S.X₁ n₁) (hx₁ : x₁.comp (mk₀ S.f) (add_zero n₁) = 0) {n₀ : ℕ} (hn₀ : n₀ + 1 = n₁) : ∃ (x₃ : Ext X S.X₃ n₀), x₃.comp hS.extClass hn₀ = x₁ := by have := covariant_sequence_exact₁' X hS n₀ n₁ hn₀ rw [ShortComplex.ab_exact_iff] at this exact this x₁ hx₁ include hS in lemma covariant_sequence_exact₂ {n : ℕ} (x₂ : Ext X S.X₂ n) (hx₂ : x₂.comp (mk₀ S.g) (add_zero n) = 0) : ∃ (x₁ : Ext X S.X₁ n), x₁.comp (mk₀ S.f) (add_zero n) = x₂ := by have := covariant_sequence_exact₂' X hS n rw [ShortComplex.ab_exact_iff] at this exact this x₂ hx₂ lemma covariant_sequence_exact₃ {n₀ : ℕ} (x₃ : Ext X S.X₃ n₀) {n₁ : ℕ} (hn₁ : n₀ + 1 = n₁) (hx₃ : x₃.comp hS.extClass hn₁ = 0) : ∃ (x₂ : Ext X S.X₂ n₀), x₂.comp (mk₀ S.g) (add_zero n₀) = x₃ := by have := covariant_sequence_exact₃' X hS n₀ n₁ hn₁ rw [ShortComplex.ab_exact_iff] at this exact this x₃ hx₃ end CovariantSequence section ContravariantSequence variable {S : ShortComplex C} (hS : S.ShortExact) (Y : C) lemma singleFunctor_map_comp_hom [HasDerivedCategory.{w'} C] {X Y Z : C} (f : X ⟶ Y) {n : ℕ} (x : Ext Y Z n) : (DerivedCategory.singleFunctor C 0).map f ≫ x.hom = ((mk₀ f).comp x (zero_add n)).hom := by simp only [comp_hom, mk₀_hom, ShiftedHom.mk₀_comp] lemma preadditiveYoneda_homologySequenceδ_singleTriangle_apply [HasDerivedCategory.{w'} C] {Y : C} {n₀ : ℕ} (x : Ext S.X₁ Y n₀) {n₁ : ℕ} (h : 1 + n₀ = n₁) : (preadditiveYoneda.obj ((singleFunctor C 0).obj Y)).homologySequenceδ ((triangleOpEquivalence _).functor.obj (op hS.singleTriangle)) n₀ n₁ (by cutsat) x.hom = (hS.extClass.comp x h).hom := by rw [preadditiveYoneda_homologySequenceδ_apply, comp_hom, hS.extClass_hom, ShiftedHom.comp] rfl include hS in /-- Alternative formulation of `contravariant_sequence_exact₂` -/ lemma contravariant_sequence_exact₂' (n : ℕ) : (ShortComplex.mk (AddCommGrpCat.ofHom ((mk₀ S.g).precomp Y (zero_add n))) (AddCommGrpCat.ofHom ((mk₀ S.f).precomp Y (zero_add n))) (by ext dsimp simp only [mk₀_comp_mk₀_assoc, ShortComplex.zero, mk₀_zero, zero_comp])).Exact := by letI := HasDerivedCategory.standard C have := (preadditiveYoneda.obj ((singleFunctor C 0).obj Y)).homologySequence_exact₂ _ (op_distinguished _ hS.singleTriangle_distinguished) n rw [ShortComplex.ab_exact_iff_function_exact] at this ⊢ apply Function.Exact.of_ladder_addEquiv_of_exact' (e₁ := Ext.homAddEquiv) (e₂ := Ext.homAddEquiv) (e₃ := Ext.homAddEquiv) (H := this) all_goals ext; apply singleFunctor_map_comp_hom (C := C) section variable (n₀ n₁ : ℕ) (h : 1 + n₀ = n₁) /-- Alternative formulation of `contravariant_sequence_exact₁` -/ lemma contravariant_sequence_exact₁' : (ShortComplex.mk (AddCommGrpCat.ofHom (((mk₀ S.f).precomp Y (zero_add n₀)))) (AddCommGrpCat.ofHom (hS.extClass.precomp Y h)) (by ext dsimp simp only [ShortComplex.ShortExact.extClass_comp_assoc])).Exact := by letI := HasDerivedCategory.standard C have := (preadditiveYoneda.obj ((singleFunctor C 0).obj Y)).homologySequence_exact₃ _ (op_distinguished _ hS.singleTriangle_distinguished) n₀ n₁ (by cutsat) rw [ShortComplex.ab_exact_iff_function_exact] at this ⊢ apply Function.Exact.of_ladder_addEquiv_of_exact' (e₁ := Ext.homAddEquiv) (e₂ := Ext.homAddEquiv) (e₃ := Ext.homAddEquiv) (H := this) · ext; apply singleFunctor_map_comp_hom (C := C) · ext; dsimp; apply preadditiveYoneda_homologySequenceδ_singleTriangle_apply /-- Alternative formulation of `contravariant_sequence_exact₃` -/ lemma contravariant_sequence_exact₃' : (ShortComplex.mk (AddCommGrpCat.ofHom (hS.extClass.precomp Y h)) (AddCommGrpCat.ofHom (((mk₀ S.g).precomp Y (zero_add n₁)))) (by ext dsimp simp only [ShortComplex.ShortExact.comp_extClass_assoc])).Exact := by letI := HasDerivedCategory.standard C have := (preadditiveYoneda.obj ((singleFunctor C 0).obj Y)).homologySequence_exact₁ _ (op_distinguished _ hS.singleTriangle_distinguished) n₀ n₁ (by cutsat) rw [ShortComplex.ab_exact_iff_function_exact] at this ⊢ apply Function.Exact.of_ladder_addEquiv_of_exact' (e₁ := Ext.homAddEquiv) (e₂ := Ext.homAddEquiv) (e₃ := Ext.homAddEquiv) (H := this) · ext; dsimp; apply preadditiveYoneda_homologySequenceδ_singleTriangle_apply · ext; apply singleFunctor_map_comp_hom (C := C) open ComposableArrows /-- Given a short exact short complex `S` in an abelian category `C` and an object `Y : C`, this is the long exact sequence `Ext S.X₃ Y n₀ → Ext S.X₂ Y n₀ → Ext S.X₁ Y n₀ → Ext S.X₃ Y n₁ → Ext S.X₂ Y n₁ → Ext S.X₁ Y n₁` when `1 + n₀ = n₁`. -/ noncomputable def contravariantSequence : ComposableArrows AddCommGrpCat.{w} 5 := mk₅ (AddCommGrpCat.ofHom ((mk₀ S.g).precomp Y (zero_add n₀))) (AddCommGrpCat.ofHom ((mk₀ S.f).precomp Y (zero_add n₀))) (AddCommGrpCat.ofHom (hS.extClass.precomp Y h)) (AddCommGrpCat.ofHom ((mk₀ S.g).precomp Y (zero_add n₁))) (AddCommGrpCat.ofHom ((mk₀ S.f).precomp Y (zero_add n₁))) lemma contravariantSequence_exact : (contravariantSequence hS Y n₀ n₁ h).Exact := exact_of_δ₀ (contravariant_sequence_exact₂' hS Y n₀).exact_toComposableArrows (exact_of_δ₀ (contravariant_sequence_exact₁' hS Y n₀ n₁ h).exact_toComposableArrows (exact_of_δ₀ (contravariant_sequence_exact₃' hS Y n₀ n₁ h).exact_toComposableArrows (contravariant_sequence_exact₂' hS Y n₁).exact_toComposableArrows)) end lemma contravariant_sequence_exact₁ {n₀ : ℕ} (x₁ : Ext S.X₁ Y n₀) {n₁ : ℕ} (hn₁ : 1 + n₀ = n₁) (hx₁ : hS.extClass.comp x₁ hn₁ = 0) : ∃ (x₂ : Ext S.X₂ Y n₀), (mk₀ S.f).comp x₂ (zero_add n₀) = x₁ := by have := contravariant_sequence_exact₁' hS Y n₀ n₁ hn₁ rw [ShortComplex.ab_exact_iff] at this exact this x₁ hx₁ include hS in lemma contravariant_sequence_exact₂ {n : ℕ} (x₂ : Ext S.X₂ Y n) (hx₂ : (mk₀ S.f).comp x₂ (zero_add n) = 0) : ∃ (x₁ : Ext S.X₃ Y n), (mk₀ S.g).comp x₁ (zero_add n) = x₂ := by have := contravariant_sequence_exact₂' hS Y n rw [ShortComplex.ab_exact_iff] at this exact this x₂ hx₂ lemma contravariant_sequence_exact₃ {n₁ : ℕ} (x₃ : Ext S.X₃ Y n₁) (hx₃ : (mk₀ S.g).comp x₃ (zero_add n₁) = 0) {n₀ : ℕ} (hn₀ : 1 + n₀ = n₁) : ∃ (x₁ : Ext S.X₁ Y n₀), hS.extClass.comp x₁ hn₀ = x₃ := by have := contravariant_sequence_exact₃' hS Y n₀ n₁ hn₀ rw [ShortComplex.ab_exact_iff] at this exact this x₃ hx₃ end ContravariantSequence end Ext end Abelian end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Ext/EnoughInjectives.lean
import Mathlib.Algebra.Homology.DerivedCategory.Ext.ExactSequences /-! # Smallness of Ext-groups from the existence of enough injectives Let `C : Type u` be an abelian category (`Category.{v} C`) that has enough injectives. If `C` is locally `w`-small, i.e. the type of morphisms in `C` are `Small.{w}`, then we show that the condition `HasExt.{w}` holds, which means that for `X` and `Y` in `C`, and `n : ℕ`, we may define `Ext X Y n : Type w`. In particular, this holds for `w = v`. However, the main lemma `hasExt_of_enoughInjectives` is not made an instance: for a given category `C`, there may be different reasonable choices for the universe `w`, and if we have two `HasExt.{w₁}` and `HasExt.{w₂}` instances, we would have to specify the universe explicitly almost everywhere, which would be an inconvenience. Then, we must be very selective regarding `HasExt` instances. Note: this file dualizes the results in `HasEnoughProjectives.lean`. -/ universe w v u open CategoryTheory Category variable {C : Type u} [Category.{v} C] [Abelian C] namespace CochainComplex open HomologicalComplex lemma isSplitMono_from_singleFunctor_obj_of_injective {I : C} [Injective I] {L : CochainComplex C ℤ} {i : ℤ} (ι : (CochainComplex.singleFunctor C i).obj I ⟶ L) [L.IsStrictlyGE i] [QuasiIsoAt ι i] : IsSplitMono ι := by let e := L.pOpcyclesIso (i - 1) i (by simp) ((L.isZero_of_isStrictlyGE i (i - 1) (by simp)).eq_of_src _ _) let α := (singleObjHomologySelfIso _ _ _).inv ≫ homologyMap ι i ≫ L.homologyι i ≫ e.inv have : ι.f i = (singleObjXSelf (ComplexShape.up ℤ) i I).hom ≫ α := by rw [← cancel_mono e.hom] dsimp [α, e] rw [assoc, assoc, assoc, assoc, pOpcyclesIso_inv_hom_id, comp_id, homologyι_naturality] dsimp [singleFunctor, singleFunctors] rw [singleObjHomologySelfIso_inv_homologyι_assoc, ← pOpcycles_singleObjOpcyclesSelfIso_inv_assoc, Iso.inv_hom_id_assoc, p_opcyclesMap] exact ⟨⟨{ retraction := mkHomToSingle (Injective.factorThru (𝟙 I) α) (by rintro j rfl apply (L.isZero_of_isStrictlyGE (j + 1) j (by simp)).eq_of_src) id := by apply HomologicalComplex.to_single_hom_ext rw [comp_f, mkHomToSingle_f, id_f, this, assoc, Injective.comp_factorThru_assoc, id_comp, Iso.hom_inv_id] }⟩⟩ end CochainComplex namespace DerivedCategory variable [HasDerivedCategory.{w} C] lemma to_singleFunctor_obj_eq_zero_of_injective {I : C} [Injective I] {K : CochainComplex C ℤ} {i : ℤ} (φ : Q.obj K ⟶ Q.obj ((CochainComplex.singleFunctor C i).obj I)) (n : ℤ) (hn : i < n) [K.IsStrictlyGE n] : φ = 0 := by obtain ⟨L, _, g, ι, h, rfl⟩ := left_fac_of_isStrictlyGE φ i have hπ : IsSplitMono ι := by rw [isIso_Q_map_iff_quasiIso] at h exact CochainComplex.isSplitMono_from_singleFunctor_obj_of_injective ι have h₁ : inv (Q.map ι) = Q.map (retraction ι) := by rw [← cancel_epi (Q.map ι), IsIso.hom_inv_id, ← Q.map_comp, IsSplitMono.id, Q.map_id] have h₂ : g ≫ retraction ι = 0 := by apply HomologicalComplex.to_single_hom_ext apply (K.isZero_of_isStrictlyGE n i hn).eq_of_src rw [h₁, ← Q.map_comp, h₂, Q.map_zero] end DerivedCategory namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] [Abelian C] namespace Abelian.Ext open DerivedCategory lemma eq_zero_of_injective [HasExt.{w} C] {X I : C} {n : ℕ} [Injective I] (e : Ext X I (n + 1)) : e = 0 := by let K := (CochainComplex.singleFunctor C 0).obj X have := K.isStrictlyGE_of_ge (-n) 0 (by cutsat) letI := HasDerivedCategory.standard C apply homEquiv.injective simp only [← cancel_mono (((singleFunctors C).shiftIso (n + 1) (-(n + 1)) 0 (by cutsat)).hom.app _), zero_hom, Limits.zero_comp] exact to_singleFunctor_obj_eq_zero_of_injective (K := K) (n := -n) _ (by cutsat) end Abelian.Ext variable (C) open Abelian /-- If `C` is a locally `w`-small abelian category with enough injectives, then `HasExt.{w} C` holds. We do not make this an instance though: for a given category `C`, there may be different reasonable choices for the universe `w`, and if we have two `HasExt.{w₁} C` and `HasExt.{w₂} C` instances, we would have to specify the universe explicitly almost everywhere, which would be an inconvenience. Then, we must be very selective regarding `HasExt` instances. -/ lemma hasExt_of_enoughInjectives [LocallySmall.{w} C] [EnoughInjectives C] : HasExt.{w} C := by letI := HasDerivedCategory.standard C have := hasExt_of_hasDerivedCategory C rw [hasExt_iff_small_ext.{w}] intro X Y n induction n generalizing X Y with | zero => rw [small_congr Ext.homEquiv₀] infer_instance | succ n hn => let S := ShortComplex.mk _ _ (cokernel.condition (Injective.ι Y)) have hS : S.ShortExact := { exact := ShortComplex.exact_of_g_is_cokernel _ (cokernelIsCokernel S.f) } have : Function.Surjective (Ext.postcomp hS.extClass X (rfl : n + 1 = _)) := fun y₁ ↦ Ext.covariant_sequence_exact₁ X hS y₁ (Ext.eq_zero_of_injective _) rfl exact small_of_surjective.{w} this end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Ext/Linear.lean
import Mathlib.Algebra.Homology.DerivedCategory.Ext.Basic import Mathlib.Algebra.Homology.DerivedCategory.Linear import Mathlib.Algebra.Module.TransferInstance import Mathlib.LinearAlgebra.BilinearMap /-! # Ext-modules in linear categories In this file, we show that if `C` is a `R`-linear abelian category, then there is a `R`-module structure on the groups `Ext X Y n` for `X` and `Y` in `C` and `n : ℕ`. -/ universe w' w t v u namespace CategoryTheory namespace Abelian namespace Ext section Ring variable {R : Type t} [Ring R] {C : Type u} [Category.{v} C] [Abelian C] [Linear R C] [HasExt.{w} C] variable {X Y : C} {n : ℕ} noncomputable instance : Module R (Ext X Y n) := letI := HasDerivedCategory.standard C Equiv.module R homEquiv lemma smul_eq_comp_mk₀ (x : Ext X Y n) (r : R) : r • x = x.comp (mk₀ (r • 𝟙 Y)) (add_zero _) := by let := HasDerivedCategory.standard C ext apply ((Equiv.linearEquiv R homEquiv).map_smul r x).trans change r • homEquiv x = (x.comp (mk₀ (r • 𝟙 Y)) (add_zero _)).hom rw [comp_hom, mk₀_hom, Functor.map_smul, Functor.map_id, ShiftedHom.mk₀_smul, ShiftedHom.comp_smul, ShiftedHom.comp_mk₀_id] @[simp] lemma smul_hom (x : Ext X Y n) (r : R) [HasDerivedCategory C] : (r • x).hom = r • x.hom := by simp [smul_eq_comp_mk₀] @[simp] lemma comp_smul {X Y Z : C} {a b : ℕ} (α : Ext X Y a) (β : Ext Y Z b) {c : ℕ} (h : a + b = c) (r : R) : α.comp (r • β) h = r • α.comp β h := by let := HasDerivedCategory.standard C aesop @[simp] lemma smul_comp {X Y Z : C} {a b : ℕ} (α : Ext X Y a) (β : Ext Y Z b) {c : ℕ} (h : a + b = c) (r : R) : (r • α).comp β h = r • α.comp β h := by let := HasDerivedCategory.standard C aesop open DerivedCategory in /-- When an instance of `[HasDerivedCategory.{w'} C]` is available, this is the `R`-linear equivalence between `Ext.{w} X Y n` and a type of morphisms in the derived category of the `R`-linear abelian category `C`. -/ @[simps] noncomputable def homLinearEquiv [HasDerivedCategory.{w'} C] : Ext X Y n ≃ₗ[R] ShiftedHom ((singleFunctor C 0).obj X) ((singleFunctor C 0).obj Y) (n : ℤ) where __ := homAddEquiv map_smul' := by simp lemma mk₀_smul (r : R) (f : X ⟶ Y) : mk₀ (r • f) = r • mk₀ f := by let := HasDerivedCategory.standard C aesop /-- The linear equivalence `Ext X Y 0 ≃ₜ[R] (X ⟶ Y)`. -/ @[simps! symm_apply] noncomputable def linearEquiv₀ : Ext X Y 0 ≃ₗ[R] (X ⟶ Y) where toAddEquiv := addEquiv₀ map_smul' m x := homEquiv₀.symm.injective (by simp [mk₀_smul]) @[simp] lemma mk₀_linearEquiv₀_apply (f : Ext X Y 0) : mk₀ (linearEquiv₀ (R := R) f) = f := addEquiv₀.left_inv f end Ring section CommRing variable {C : Type u} [Category.{v} C] [Abelian C] [HasExt.{w} C] /-- The composition of `Ext`, as a bilinear map. -/ @[simps!] noncomputable def bilinearCompOfLinear (R : Type t) [CommRing R] [Linear R C] (X Y Z : C) (a b c : ℕ) (h : a + b = c) : Ext X Y a →ₗ[R] Ext Y Z b →ₗ[R] Ext X Z c where toFun α := { toFun β := α.comp β h map_add' := by simp map_smul' := by simp } map_add' := by aesop map_smul' := by aesop /-- The postcomposition `Ext X Y a →ₗ[R] Ext X Z b` with `β : Ext Y Z n` when `a + n = b`. -/ noncomputable abbrev postcompOfLinear {Y Z : C} {n : ℕ} (β : Ext Y Z n) (R : Type t) [CommRing R] [Linear R C] (X : C) {a b : ℕ} (h : a + n = b) : Ext X Y a →ₗ[R] Ext X Z b := (bilinearCompOfLinear R X Y Z a n b h).flip β /-- The precomposition `Ext Y Z a →ₗ[R] Ext X Z b` with `α : Ext X Y n` when `n + a = b`. -/ noncomputable abbrev precompOfLinear {X Y : C} {n : ℕ} (α : Ext X Y n) (R : Type t) [CommRing R] [Linear R C] (Z : C) {a b : ℕ} (h : n + a = b) : Ext Y Z a →ₗ[R] Ext X Z b := bilinearCompOfLinear R X Y Z n a b h α end CommRing end Ext end Abelian end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Ext/Basic.lean
import Mathlib.Algebra.Homology.DerivedCategory.FullyFaithful import Mathlib.CategoryTheory.Localization.SmallShiftedHom /-! # Ext groups in abelian categories Let `C` be an abelian category (with `C : Type u` and `Category.{v} C`). In this file, we introduce the assumption `HasExt.{w} C` which asserts that morphisms between single complexes in arbitrary degrees in the derived category of `C` are `w`-small. Under this assumption, we define `Ext.{w} X Y n : Type w` as shrunk versions of suitable types of morphisms in the derived category. In particular, when `C` has enough projectives or enough injectives, the property `HasExt.{v} C` shall hold. Note: in certain situations, `w := v` shall be the preferred choice of universe (e.g. if `C := ModuleCat.{v} R` with `R : Type v`). However, in the development of the API for Ext-groups, it is important to keep a larger degree of generality for universes, as `w < v` may happen in certain situations. Indeed, if `X : Scheme.{u}`, then the underlying category of the étale site of `X` shall be a large category. However, the category `Sheaf X.Etale AddCommGrpCat.{u}` shall have good properties (because there is a small category of affine schemes with the same category of sheaves), and even though the type of morphisms in `Sheaf X.Etale AddCommGrpCat.{u}` shall be in `Type (u + 1)`, these types are going to be `u`-small. Then, for `C := Sheaf X.etale AddCommGrpCat.{u}`, we will have `Category.{u + 1} C`, but `HasExt.{u} C` will hold (as `C` has enough injectives). Then, the `Ext` groups between étale sheaves over `X` shall be in `Type u`. -/ assert_not_exists TwoSidedIdeal universe w'' w' w v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] [Abelian C] open Localization Limits ZeroObject DerivedCategory Pretriangulated /-- The property that morphisms between single complexes in arbitrary degrees are `w`-small in the derived category. -/ abbrev HasExt : Prop := ∀ (X Y : C), HasSmallLocalizedShiftedHom.{w} (HomologicalComplex.quasiIso C (ComplexShape.up ℤ)) ℤ ((CochainComplex.singleFunctor C 0).obj X) ((CochainComplex.singleFunctor C 0).obj Y) lemma hasExt_iff [HasDerivedCategory.{w'} C] : HasExt.{w} C ↔ ∀ (X Y : C) (n : ℤ) (_ : 0 ≤ n), Small.{w} ((singleFunctor C 0).obj X ⟶ (((singleFunctor C 0).obj Y)⟦n⟧)) := by dsimp [HasExt] simp only [hasSmallLocalizedShiftedHom_iff _ _ Q] constructor · intro h X Y n hn exact (small_congr ((shiftFunctorZero _ ℤ).app ((singleFunctor C 0).obj X)).homFromEquiv).1 (h X Y 0 n) · intro h X Y a b obtain hab | hab := le_or_gt a b · refine (small_congr ?_).1 (h X Y (b - a) (by simpa)) exact (Functor.FullyFaithful.ofFullyFaithful (shiftFunctor _ a)).homEquiv.trans ((shiftFunctorAdd' _ _ _ _ (Int.sub_add_cancel b a)).symm.app _).homToEquiv · suffices Subsingleton ((Q.obj ((CochainComplex.singleFunctor C 0).obj X))⟦a⟧ ⟶ (Q.obj ((CochainComplex.singleFunctor C 0).obj Y))⟦b⟧) from inferInstance constructor intro x y rw [← cancel_mono ((Q.commShiftIso b).inv.app _), ← cancel_epi ((Q.commShiftIso a).hom.app _)] have : (((CochainComplex.singleFunctor C 0).obj X)⟦a⟧).IsStrictlyLE (-a) := CochainComplex.isStrictlyLE_shift _ 0 _ _ (by cutsat) have : (((CochainComplex.singleFunctor C 0).obj Y)⟦b⟧).IsStrictlyGE (-b) := CochainComplex.isStrictlyGE_shift _ 0 _ _ (by cutsat) apply (subsingleton_hom_of_isStrictlyLE_of_isStrictlyGE _ _ (-a) (-b) (by cutsat)).elim lemma hasExt_of_hasDerivedCategory [HasDerivedCategory.{w} C] : HasExt.{w} C := by rw [hasExt_iff.{w}] infer_instance lemma HasExt.standard : HasExt.{max u v} C := by letI := HasDerivedCategory.standard exact hasExt_of_hasDerivedCategory _ variable {C} variable [HasExt.{w} C] namespace Abelian /-- A Ext-group in an abelian category `C`, defined as a `Type w` when `[HasExt.{w} C]`. -/ def Ext (X Y : C) (n : ℕ) : Type w := SmallShiftedHom.{w} (HomologicalComplex.quasiIso C (ComplexShape.up ℤ)) ((CochainComplex.singleFunctor C 0).obj X) ((CochainComplex.singleFunctor C 0).obj Y) (n : ℤ) namespace Ext variable {X Y Z T : C} /-- The composition of `Ext`. -/ noncomputable def comp {a b : ℕ} (α : Ext X Y a) (β : Ext Y Z b) {c : ℕ} (h : a + b = c) : Ext X Z c := SmallShiftedHom.comp α β (by cutsat) lemma comp_assoc {a₁ a₂ a₃ a₁₂ a₂₃ a : ℕ} (α : Ext X Y a₁) (β : Ext Y Z a₂) (γ : Ext Z T a₃) (h₁₂ : a₁ + a₂ = a₁₂) (h₂₃ : a₂ + a₃ = a₂₃) (h : a₁ + a₂ + a₃ = a) : (α.comp β h₁₂).comp γ (show a₁₂ + a₃ = a by cutsat) = α.comp (β.comp γ h₂₃) (by cutsat) := SmallShiftedHom.comp_assoc _ _ _ _ _ _ (by cutsat) @[simp] lemma comp_assoc_of_second_deg_zero {a₁ a₃ a₁₃ : ℕ} (α : Ext X Y a₁) (β : Ext Y Z 0) (γ : Ext Z T a₃) (h₁₃ : a₁ + a₃ = a₁₃) : (α.comp β (add_zero _)).comp γ h₁₃ = α.comp (β.comp γ (zero_add _)) h₁₃ := by apply comp_assoc cutsat @[simp] lemma comp_assoc_of_third_deg_zero {a₁ a₂ a₁₂ : ℕ} (α : Ext X Y a₁) (β : Ext Y Z a₂) (γ : Ext Z T 0) (h₁₂ : a₁ + a₂ = a₁₂) : (α.comp β h₁₂).comp γ (add_zero _) = α.comp (β.comp γ (add_zero _)) h₁₂ := by apply comp_assoc cutsat section variable [HasDerivedCategory.{w'} C] /-- When an instance of `[HasDerivedCategory.{w'} C]` is available, this is the bijection between `Ext.{w} X Y n` and a type of morphisms in the derived category. -/ noncomputable def homEquiv {n : ℕ} : Ext.{w} X Y n ≃ ShiftedHom ((singleFunctor C 0).obj X) ((singleFunctor C 0).obj Y) (n : ℤ) := SmallShiftedHom.equiv (HomologicalComplex.quasiIso C (ComplexShape.up ℤ)) Q /-- The morphism in the derived category which corresponds to an element in `Ext X Y a`. -/ noncomputable abbrev hom {a : ℕ} (α : Ext X Y a) : ShiftedHom ((singleFunctor C 0).obj X) ((singleFunctor C 0).obj Y) (a : ℤ) := homEquiv α @[simp] lemma comp_hom {a b : ℕ} (α : Ext X Y a) (β : Ext Y Z b) {c : ℕ} (h : a + b = c) : (α.comp β h).hom = α.hom.comp β.hom (by cutsat) := by apply SmallShiftedHom.equiv_comp @[ext] lemma ext {n : ℕ} {α β : Ext X Y n} (h : α.hom = β.hom) : α = β := homEquiv.injective h end /-- The canonical map `(X ⟶ Y) → Ext X Y 0`. -/ noncomputable def mk₀ (f : X ⟶ Y) : Ext X Y 0 := SmallShiftedHom.mk₀ _ _ (by simp) ((CochainComplex.singleFunctor C 0).map f) @[simp] lemma mk₀_hom [HasDerivedCategory.{w'} C] (f : X ⟶ Y) : (mk₀ f).hom = ShiftedHom.mk₀ _ (by simp) ((singleFunctor C 0).map f) := by apply SmallShiftedHom.equiv_mk₀ @[simp] lemma mk₀_comp_mk₀ (f : X ⟶ Y) (g : Y ⟶ Z) : (mk₀ f).comp (mk₀ g) (zero_add 0) = mk₀ (f ≫ g) := by letI := HasDerivedCategory.standard C; ext; simp @[simp] lemma mk₀_comp_mk₀_assoc (f : X ⟶ Y) (g : Y ⟶ Z) {n : ℕ} (α : Ext Z T n) : (mk₀ f).comp ((mk₀ g).comp α (zero_add n)) (zero_add n) = (mk₀ (f ≫ g)).comp α (zero_add n) := by rw [← mk₀_comp_mk₀, comp_assoc] cutsat variable (X Y) in lemma mk₀_bijective : Function.Bijective (mk₀ (X := X) (Y := Y)) := by letI := HasDerivedCategory.standard C have h : (singleFunctor C 0).FullyFaithful := Functor.FullyFaithful.ofFullyFaithful _ let e : (X ⟶ Y) ≃ Ext X Y 0 := (h.homEquiv.trans (ShiftedHom.homEquiv _ (by simp))).trans homEquiv.symm have he : e.toFun = mk₀ := by ext f : 1 dsimp [e] apply homEquiv.injective apply (Equiv.apply_symm_apply _ _).trans symm apply SmallShiftedHom.equiv_mk₀ rw [← he] exact e.bijective /-- The bijection `Ext X Y 0 ≃ (X ⟶ Y)`. -/ @[simps! symm_apply] noncomputable def homEquiv₀ : Ext X Y 0 ≃ (X ⟶ Y) := (Equiv.ofBijective _ (mk₀_bijective X Y)).symm @[simp] lemma mk₀_homEquiv₀_apply (f : Ext X Y 0) : mk₀ (homEquiv₀ f) = f := homEquiv₀.left_inv f variable {n : ℕ} /-! The abelian group structure on `Ext X Y n` is defined by transporting the abelian group structure on the constructed derived category (given by `HasDerivedCategory.standard`). This constructed derived category is used in order to obtain most of the compatibilities satisfied by this abelian group structure. It is then shown that the bijection `homEquiv` between `Ext X Y n` and Hom-types in the derived category can be promoted to an additive equivalence for any `[HasDerivedCategory C]` instance. -/ noncomputable instance : AddCommGroup (Ext X Y n) := letI := HasDerivedCategory.standard C homEquiv.addCommGroup /-- The map from `Ext X Y n` to a `ShiftedHom` type in the *constructed* derived category given by `HasDerivedCategory.standard`: this definition is introduced only in order to prove properties of the abelian group structure on `Ext`-groups. Do not use this definition: use the more general `hom` instead. -/ noncomputable abbrev hom' (α : Ext X Y n) : letI := HasDerivedCategory.standard C ShiftedHom ((singleFunctor C 0).obj X) ((singleFunctor C 0).obj Y) (n : ℤ) := letI := HasDerivedCategory.standard C α.hom private lemma add_hom' (α β : Ext X Y n) : (α + β).hom' = α.hom' + β.hom' := letI := HasDerivedCategory.standard C homEquiv.symm.injective (Equiv.symm_apply_apply _ _) private lemma neg_hom' (α : Ext X Y n) : (-α).hom' = -α.hom' := letI := HasDerivedCategory.standard C homEquiv.symm.injective (Equiv.symm_apply_apply _ _) variable (X Y n) in private lemma zero_hom' : (0 : Ext X Y n).hom' = 0 := letI := HasDerivedCategory.standard C homEquiv.symm.injective (Equiv.symm_apply_apply _ _) @[simp] lemma add_comp (α₁ α₂ : Ext X Y n) {m : ℕ} (β : Ext Y Z m) {p : ℕ} (h : n + m = p) : (α₁ + α₂).comp β h = α₁.comp β h + α₂.comp β h := by letI := HasDerivedCategory.standard C; ext; simp [this, add_hom'] @[simp] lemma comp_add (α : Ext X Y n) {m : ℕ} (β₁ β₂ : Ext Y Z m) {p : ℕ} (h : n + m = p) : α.comp (β₁ + β₂) h = α.comp β₁ h + α.comp β₂ h := by letI := HasDerivedCategory.standard C; ext; simp [this, add_hom'] @[simp] lemma neg_comp (α : Ext X Y n) {m : ℕ} (β : Ext Y Z m) {p : ℕ} (h : n + m = p) : (-α).comp β h = -α.comp β h := by letI := HasDerivedCategory.standard C; ext; simp [this, neg_hom'] @[simp] lemma comp_neg (α : Ext X Y n) {m : ℕ} (β : Ext Y Z m) {p : ℕ} (h : n + m = p) : α.comp (-β) h = -α.comp β h := by letI := HasDerivedCategory.standard C; ext; simp [this, neg_hom'] variable (X n) in @[simp] lemma zero_comp {m : ℕ} (β : Ext Y Z m) (p : ℕ) (h : n + m = p) : (0 : Ext X Y n).comp β h = 0 := by letI := HasDerivedCategory.standard C; ext; simp [this, zero_hom'] @[simp] lemma comp_zero (α : Ext X Y n) (Z : C) (m : ℕ) (p : ℕ) (h : n + m = p) : α.comp (0 : Ext Y Z m) h = 0 := by letI := HasDerivedCategory.standard C; ext; simp [this, zero_hom'] @[simp] lemma mk₀_id_comp (α : Ext X Y n) : (mk₀ (𝟙 X)).comp α (zero_add n) = α := by letI := HasDerivedCategory.standard C; ext; simp @[simp] lemma comp_mk₀_id (α : Ext X Y n) : α.comp (mk₀ (𝟙 Y)) (add_zero n) = α := by letI := HasDerivedCategory.standard C; ext; simp variable (X Y) in @[simp] lemma mk₀_zero : mk₀ (0 : X ⟶ Y) = 0 := by letI := HasDerivedCategory.standard C; ext; simp [zero_hom'] lemma mk₀_add (f g : X ⟶ Y) : mk₀ (f + g) = mk₀ f + mk₀ g := by letI := HasDerivedCategory.standard C; ext; simp [add_hom', ShiftedHom.mk₀] /-- The additive bijection `Ext X Y 0 ≃+ (X ⟶ Y)`. -/ @[simps! symm_apply] noncomputable def addEquiv₀ : Ext X Y 0 ≃+ (X ⟶ Y) where toEquiv := homEquiv₀ map_add' x y := homEquiv₀.symm.injective (by simp [mk₀_add]) @[simp] lemma mk₀_addEquiv₀_apply (f : Ext X Y 0) : mk₀ (addEquiv₀ f) = f := addEquiv₀.left_inv f section attribute [local instance] preservesBinaryBiproducts_of_preservesBiproducts in lemma biprod_ext {X₁ X₂ : C} {α β : Ext (X₁ ⊞ X₂) Y n} (h₁ : (mk₀ biprod.inl).comp α (zero_add n) = (mk₀ biprod.inl).comp β (zero_add n)) (h₂ : (mk₀ biprod.inr).comp α (zero_add n) = (mk₀ biprod.inr).comp β (zero_add n)) : α = β := by letI := HasDerivedCategory.standard C rw [Ext.ext_iff] at h₁ h₂ ⊢ simp only [comp_hom, mk₀_hom, ShiftedHom.mk₀_comp] at h₁ h₂ apply BinaryCofan.IsColimit.hom_ext (isBinaryBilimitOfPreserves (singleFunctor C 0) (BinaryBiproduct.isBilimit X₁ X₂)).isColimit all_goals assumption variable [HasDerivedCategory.{w'} C] variable (X Y n) in @[simp] lemma zero_hom : (0 : Ext X Y n).hom = 0 := by let β : Ext 0 Y n := 0 have hβ : β.hom = 0 := by apply (Functor.map_isZero _ (isZero_zero C)).eq_of_src have : (0 : Ext X Y n) = (0 : Ext X 0 0).comp β (zero_add n) := by simp [β] rw [this, comp_hom, hβ, ShiftedHom.comp_zero] @[simp] lemma add_hom (α β : Ext X Y n) : (α + β).hom = α.hom + β.hom := by let α' : Ext (X ⊞ X) Y n := (mk₀ biprod.fst).comp α (zero_add n) let β' : Ext (X ⊞ X) Y n := (mk₀ biprod.snd).comp β (zero_add n) have eq₁ : α + β = (mk₀ (biprod.lift (𝟙 X) (𝟙 X))).comp (α' + β') (zero_add n) := by simp [α', β'] have eq₂ : α' + β' = homEquiv.symm (α'.hom + β'.hom) := by apply biprod_ext all_goals ext; simp [α', β', ← Functor.map_comp] simp only [eq₁, eq₂, comp_hom, Equiv.apply_symm_apply, ShiftedHom.comp_add] congr · dsimp [α'] rw [comp_hom, mk₀_hom, mk₀_hom] dsimp rw [ShiftedHom.mk₀_comp_mk₀_assoc, ← Functor.map_comp, biprod.lift_fst, Functor.map_id, ShiftedHom.mk₀_id_comp] · dsimp [β'] rw [comp_hom, mk₀_hom, mk₀_hom] dsimp rw [ShiftedHom.mk₀_comp_mk₀_assoc, ← Functor.map_comp, biprod.lift_snd, Functor.map_id, ShiftedHom.mk₀_id_comp] lemma neg_hom (α : Ext X Y n) : (-α).hom = -α.hom := by rw [← add_right_inj α.hom, ← add_hom, add_neg_cancel, add_neg_cancel, zero_hom] /-- When an instance of `[HasDerivedCategory.{w'} C]` is available, this is the additive bijection between `Ext.{w} X Y n` and a type of morphisms in the derived category. -/ noncomputable def homAddEquiv {n : ℕ} : Ext.{w} X Y n ≃+ ShiftedHom ((singleFunctor C 0).obj X) ((singleFunctor C 0).obj Y) (n : ℤ) where toEquiv := homEquiv map_add' := by simp @[simp] lemma homAddEquiv_apply (α : Ext X Y n) : homAddEquiv α = α.hom := rfl end variable (X Y Z) in /-- The composition of `Ext`, as a bilinear map. -/ @[simps!] noncomputable def bilinearComp (a b c : ℕ) (h : a + b = c) : Ext X Y a →+ Ext Y Z b →+ Ext X Z c := AddMonoidHom.mk' (fun α ↦ AddMonoidHom.mk' (fun β ↦ α.comp β h) (by simp)) (by aesop) /-- The postcomposition `Ext X Y a →+ Ext X Z b` with `β : Ext Y Z n` when `a + n = b`. -/ noncomputable abbrev postcomp (β : Ext Y Z n) (X : C) {a b : ℕ} (h : a + n = b) : Ext X Y a →+ Ext X Z b := (bilinearComp X Y Z a n b h).flip β /-- The precomposition `Ext Y Z a →+ Ext X Z b` with `α : Ext X Y n` when `n + a = b`. -/ noncomputable abbrev precomp (α : Ext X Y n) (Z : C) {a b : ℕ} (h : n + a = b) : Ext Y Z a →+ Ext X Z b := bilinearComp X Y Z n a b h α end Ext /-- Auxiliary definition for `extFunctor`. -/ @[simps] noncomputable def extFunctorObj (X : C) (n : ℕ) : C ⥤ AddCommGrpCat.{w} where obj Y := AddCommGrpCat.of (Ext X Y n) map f := AddCommGrpCat.ofHom ((Ext.mk₀ f).postcomp _ (add_zero n)) map_comp f f' := by ext α dsimp [AddCommGrpCat.ofHom] rw [← Ext.mk₀_comp_mk₀] symm apply Ext.comp_assoc omega /-- The functor `Cᵒᵖ ⥤ C ⥤ AddCommGrpCat` which sends `X : C` and `Y : C` to `Ext X Y n`. -/ @[simps] noncomputable def extFunctor (n : ℕ) : Cᵒᵖ ⥤ C ⥤ AddCommGrpCat.{w} where obj X := extFunctorObj X.unop n map {X₁ X₂} f := { app := fun Y ↦ AddCommGrpCat.ofHom (AddMonoidHom.mk' (fun α ↦ (Ext.mk₀ f.unop).comp α (zero_add _)) (by simp)) naturality := fun {Y₁ Y₂} g ↦ by ext α dsimp symm apply Ext.comp_assoc all_goals omega } map_comp {X₁ X₂ X₃} f f' := by ext Y α simp section biproduct attribute [local simp] Ext.mk₀_add instance (X : C) (n : ℕ) : (extFunctorObj X n).Additive where instance (n : ℕ) : (extFunctor (C := C) n).Additive where lemma Ext.comp_sum {X Y Z : C} {p : ℕ} (α : Ext X Y p) {ι : Type*} [Fintype ι] {q : ℕ} (β : ι → Ext Y Z q) {n : ℕ} (h : p + q = n) : α.comp (∑ i, β i) h = ∑ i, α.comp (β i) h := map_sum (α.precomp Z h) _ _ lemma Ext.sum_comp {X Y Z : C} {p : ℕ} {ι : Type*} [Fintype ι] (α : ι → Ext X Y p) {q : ℕ} (β : Ext Y Z q) {n : ℕ} (h : p + q = n) : (∑ i, α i).comp β h = ∑ i, (α i).comp β h := map_sum (β.postcomp X h) _ _ lemma Ext.mk₀_sum {X Y : C} {ι : Type*} [Fintype ι] (f : ι → (X ⟶ Y)) : mk₀ (∑ i, f i) = ∑ i, mk₀ (f i) := map_sum addEquiv₀.symm _ _ /-- `Ext` commutes with biproducts in its first variable. -/ noncomputable def Ext.biproductAddEquiv {J : Type*} [Fintype J] {X : J → C} {c : Bicone X} (hc : c.IsBilimit) (Y : C) (n : ℕ) : Ext c.pt Y n ≃+ Π i, Ext (X i) Y n where toFun e i := (Ext.mk₀ (c.ι i)).comp e (zero_add n) invFun e := ∑ (i : J), (Ext.mk₀ (c.π i)).comp (e i) (zero_add n) left_inv x := by simp only [← comp_assoc_of_second_deg_zero, mk₀_comp_mk₀] rw [← Ext.sum_comp, ← Ext.mk₀_sum, IsBilimit.total hc, mk₀_id_comp] right_inv _ := by ext i simp only [Ext.comp_sum, ← comp_assoc_of_second_deg_zero, mk₀_comp_mk₀] rw [Finset.sum_eq_single i _ (by simp), bicone_ι_π_self, mk₀_id_comp] intro _ _ hij rw [c.ι_π, dif_neg hij.symm, mk₀_zero, zero_comp] map_add' _ _ := by simp only [comp_add, Pi.add_def] /-- `Ext` commutes with biproducts in its second variable. -/ noncomputable def Ext.addEquivBiproduct (X : C) {J : Type*} [Fintype J] {Y : J → C} {c : Bicone Y} (hc : c.IsBilimit) (n : ℕ) : Ext X c.pt n ≃+ Π i, Ext X (Y i) n where toFun e i := e.comp (Ext.mk₀ (c.π i)) (add_zero n) invFun e := ∑ (i : J), (e i).comp (Ext.mk₀ (c.ι i)) (add_zero n) left_inv _ := by simp only [comp_assoc_of_second_deg_zero, mk₀_comp_mk₀, ← Ext.comp_sum, ← Ext.mk₀_sum, IsBilimit.total hc, comp_mk₀_id] right_inv _ := by ext i simp only [Ext.sum_comp, comp_assoc_of_second_deg_zero, mk₀_comp_mk₀] rw [Finset.sum_eq_single i _ (by simp), bicone_ι_π_self, comp_mk₀_id] intro _ _ hij rw [c.ι_π, dif_neg hij, mk₀_zero, comp_zero] map_add' _ _ := by simp only [add_comp, Pi.add_def] end biproduct section ChangeOfUniverse namespace Ext variable [HasExt.{w'} C] {X Y : C} {n : ℕ} /-- Up to an equivalence, the type `Ext.{w} X Y n` does not depend on the universe `w`. -/ noncomputable def chgUniv : Ext.{w} X Y n ≃ Ext.{w'} X Y n := SmallShiftedHom.chgUniv.{w', w} lemma homEquiv_chgUniv [HasDerivedCategory.{w''} C] (e : Ext.{w} X Y n) : homEquiv.{w'', w'} (chgUniv.{w'} e) = homEquiv.{w'', w} e := by apply SmallShiftedHom.equiv_chgUniv end Ext end ChangeOfUniverse end Abelian open Abelian variable (C) in lemma hasExt_iff_small_ext : HasExt.{w'} C ↔ ∀ (X Y : C) (n : ℕ), Small.{w'} (Ext.{w} X Y n) := by letI := HasDerivedCategory.standard C simp only [hasExt_iff, small_congr Ext.homEquiv] constructor · intro h X Y n exact h X Y n (by simp) · intro h X Y n hn lift n to ℕ using hn exact h X Y n end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/DerivedCategory/Ext/EnoughProjectives.lean
import Mathlib.Algebra.Homology.DerivedCategory.Ext.ExactSequences /-! # Smallness of Ext-groups from the existence of enough projectives Let `C : Type u` be an abelian category (`Category.{v} C`) that has enough projectives. If `C` is locally `w`-small, i.e. the type of morphisms in `C` are `Small.{w}`, then we show that the condition `HasExt.{w}` holds, which means that for `X` and `Y` in `C`, and `n : ℕ`, we may define `Ext X Y n : Type w`. In particular, this holds for `w = v`. However, the main lemma `hasExt_of_enoughProjectives` is not made an instance: for a given category `C`, there may be different reasonable choices for the universe `w`, and if we have two `HasExt.{w₁}` and `HasExt.{w₂}` instances, we would have to specify the universe explicitly almost everywhere, which would be an inconvenience. So we must be very selective regarding `HasExt` instances. -/ universe w v u open CategoryTheory Category variable {C : Type u} [Category.{v} C] [Abelian C] namespace CochainComplex open HomologicalComplex lemma isSplitEpi_to_singleFunctor_obj_of_projective {P : C} [Projective P] {K : CochainComplex C ℤ} {i : ℤ} (π : K ⟶ (CochainComplex.singleFunctor C i).obj P) [K.IsStrictlyLE i] [QuasiIsoAt π i] : IsSplitEpi π := by let e := K.iCyclesIso i (i + 1) (by simp) ((K.isZero_of_isStrictlyLE i (i + 1) (by simp)).eq_of_tgt _ _) let α := e.inv ≫ K.homologyπ i ≫ homologyMap π i ≫ (singleObjHomologySelfIso _ _ _).hom have : π.f i = α ≫ (singleObjXSelf (ComplexShape.up ℤ) i P).inv := by rw [← cancel_epi e.hom] dsimp [α, e] rw [assoc, assoc, assoc, iCyclesIso_hom_inv_id_assoc, homologyπ_naturality_assoc] dsimp [singleFunctor, singleFunctors] rw [homologyπ_singleObjHomologySelfIso_hom_assoc, ← singleObjCyclesSelfIso_inv_iCycles, Iso.hom_inv_id_assoc, ← cyclesMap_i] exact ⟨⟨{ section_ := mkHomFromSingle (Projective.factorThru (𝟙 P) α) (by rintro _ rfl apply (K.isZero_of_isStrictlyLE i (i + 1) (by simp)).eq_of_tgt) id := by apply HomologicalComplex.from_single_hom_ext rw [comp_f, mkHomFromSingle_f, assoc, id_f, this, Projective.factorThru_comp_assoc, id_comp, Iso.hom_inv_id] rfl }⟩⟩ end CochainComplex namespace DerivedCategory variable [HasDerivedCategory.{w} C] lemma from_singleFunctor_obj_eq_zero_of_projective {P : C} [Projective P] {L : CochainComplex C ℤ} {i : ℤ} (φ : Q.obj ((CochainComplex.singleFunctor C i).obj P) ⟶ Q.obj L) (n : ℤ) (hn : n < i) [L.IsStrictlyLE n] : φ = 0 := by obtain ⟨K, _, π, h, g, rfl⟩:= right_fac_of_isStrictlyLE φ i have hπ : IsSplitEpi π := by rw [isIso_Q_map_iff_quasiIso] at h exact CochainComplex.isSplitEpi_to_singleFunctor_obj_of_projective π have h₁ : inv (Q.map π) = Q.map (section_ π) := by rw [← cancel_mono (Q.map π), IsIso.inv_hom_id, ← Q.map_comp, IsSplitEpi.id, Q.map_id] have h₂ : section_ π ≫ g = 0 := by apply HomologicalComplex.from_single_hom_ext apply (L.isZero_of_isStrictlyLE n i hn).eq_of_tgt rw [h₁, ← Q.map_comp, h₂, Q.map_zero] end DerivedCategory namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] [Abelian C] namespace Abelian.Ext open DerivedCategory lemma eq_zero_of_projective [HasExt.{w} C] {P Y : C} {n : ℕ} [Projective P] (e : Ext P Y (n + 1)) : e = 0 := by letI := HasDerivedCategory.standard C apply homEquiv.injective simp only [← cancel_mono (((singleFunctors C).shiftIso (n + 1) (- (n + 1)) 0 (by cutsat)).hom.app _), zero_hom, Limits.zero_comp] apply from_singleFunctor_obj_eq_zero_of_projective (L := (CochainComplex.singleFunctor C (-(n + 1))).obj Y) (n := - (n + 1)) _ (by cutsat) end Abelian.Ext variable (C) open Abelian /-- If `C` is a locally `w`-small abelian category with enough projectives, then `HasExt.{w} C` holds. We do not make this an instance though: for a given category `C`, there may be different reasonable choices for the universe `w`, and if we have two `HasExt.{w₁} C` and `HasExt.{w₂} C` instances, we would have to specify the universe explicitly almost everywhere, which would be an inconvenience. Then, we must be very selective regarding `HasExt` instances. -/ lemma hasExt_of_enoughProjectives [LocallySmall.{w} C] [EnoughProjectives C] : HasExt.{w} C := by letI := HasDerivedCategory.standard C have := hasExt_of_hasDerivedCategory C rw [hasExt_iff_small_ext.{w}] intro X Y n induction n generalizing X Y with | zero => rw [small_congr Ext.homEquiv₀] infer_instance | succ n hn => let S := ShortComplex.mk _ _ (kernel.condition (Projective.π X)) have hS : S.ShortExact := { exact := ShortComplex.exact_of_f_is_kernel _ (kernelIsKernel S.g) } have : Function.Surjective (Ext.precomp hS.extClass Y (add_comm 1 n)) := fun x₃ ↦ Ext.contravariant_sequence_exact₃ hS Y x₃ (Ext.eq_zero_of_projective _) (by cutsat) exact small_of_surjective.{w} this end CategoryTheory
.lake/packages/mathlib/Mathlib/Algebra/Homology/Factorizations/Basic.lean
import Mathlib.Algebra.Homology.HomologicalComplex import Mathlib.CategoryTheory.Abelian.EpiWithInjectiveKernel /-! # Basic definitions for factorizations lemmas We define the class of morphisms `degreewiseEpiWithInjectiveKernel : MorphismProperty (CochainComplex C ℤ)` in the category of cochain complexes in an abelian category `C`. When restricted to the full subcategory of bounded below cochain complexes in an abelian category `C` that has enough injectives, this is the class of fibrations for a model category structure on the bounded below category of cochain complexes in `C`. In this folder, we intend to prove two factorization lemmas in the category of bounded below cochain complexes (TODO): * CM5a: any morphism `K ⟶ L` can be factored as `K ⟶ K' ⟶ L` where `i : K ⟶ K'` is a trivial cofibration (a mono that is also a quasi-isomorphisms) and `p : K' ⟶ L` is a fibration. * CM5b: any morphism `K ⟶ L` can be factored as `K ⟶ L' ⟶ L` where `i : K ⟶ L'` is a cofibration (i.e. a mono) and `p : L' ⟶ L` is a trivial fibration (i.e. a quasi-isomorphism which is also a fibration) The difficult part is CM5a (whose proof uses CM5b). These lemmas shall be essential ingredients in the proof that the bounded below derived category of an abelian category `C` with enough injectives identifies to the bounded below homotopy category of complexes of injective objects in `C`. This will be used in the construction of total derived functors (and a refactor of the sequence of derived functors). -/ open CategoryTheory Abelian variable {C : Type*} [Category C] [Abelian C] namespace CochainComplex /-- A morphism of cochain complexes `φ` in an abelian category satisfies `degreewiseEpiWithInjectiveKernel φ` if for any `i : ℤ`, the morphism `φ.f i` is an epimorphism with an injective kernel. -/ def degreewiseEpiWithInjectiveKernel : MorphismProperty (CochainComplex C ℤ) := fun _ _ φ => ∀ (i : ℤ), epiWithInjectiveKernel (φ.f i) instance : (degreewiseEpiWithInjectiveKernel (C := C)).IsMultiplicative where id_mem _ _ := MorphismProperty.id_mem _ _ comp_mem _ _ hf hg n := MorphismProperty.comp_mem _ _ _ (hf n) (hg n) end CochainComplex
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/MappingCone.lean
import Mathlib.Algebra.Homology.HomotopyCategory.HomComplex import Mathlib.Algebra.Homology.HomotopyCofiber /-! # The mapping cone of a morphism of cochain complexes In this file, we study the homotopy cofiber `HomologicalComplex.homotopyCofiber` of a morphism `φ : F ⟶ G` of cochain complexes indexed by `ℤ`. In this case, we redefine it as `CochainComplex.mappingCone φ`. The API involves definitions - `mappingCone.inl φ : Cochain F (mappingCone φ) (-1)`, - `mappingCone.inr φ : G ⟶ mappingCone φ`, - `mappingCone.fst φ : Cocycle (mappingCone φ) F 1` and - `mappingCone.snd φ : Cochain (mappingCone φ) G 0`. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Limits -- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737 universe v v' variable {C D : Type*} [Category.{v} C] [Category.{v'} D] [Preadditive C] [Preadditive D] namespace CochainComplex open HomologicalComplex section variable {ι : Type*} [AddRightCancelSemigroup ι] [One ι] {F G : CochainComplex C ι} (φ : F ⟶ G) instance [∀ p, HasBinaryBiproduct (F.X (p + 1)) (G.X p)] : HasHomotopyCofiber φ where hasBinaryBiproduct := by rintro i _ rfl infer_instance end variable {F G : CochainComplex C ℤ} (φ : F ⟶ G) variable [HasHomotopyCofiber φ] /-- The mapping cone of a morphism of cochain complexes indexed by `ℤ`. -/ noncomputable def mappingCone := homotopyCofiber φ namespace mappingCone open HomComplex /-- The left inclusion in the mapping cone, as a cochain of degree `-1`. -/ noncomputable def inl : Cochain F (mappingCone φ) (-1) := Cochain.mk (fun p q hpq => homotopyCofiber.inlX φ p q (by dsimp; cutsat)) /-- The right inclusion in the mapping cone. -/ noncomputable def inr : G ⟶ mappingCone φ := homotopyCofiber.inr φ /-- The first projection from the mapping cone, as a cocyle of degree `1`. -/ noncomputable def fst : Cocycle (mappingCone φ) F 1 := Cocycle.mk (Cochain.mk (fun p q hpq => homotopyCofiber.fstX φ p q hpq)) 2 (by cutsat) (by ext p _ rfl simp [δ_v 1 2 (by cutsat) _ p (p + 2) (by cutsat) (p + 1) (p + 1) (by cutsat) rfl, homotopyCofiber.d_fstX φ p (p + 1) (p + 2) rfl, mappingCone, show Int.negOnePow 2 = 1 by rfl]) /-- The second projection from the mapping cone, as a cochain of degree `0`. -/ noncomputable def snd : Cochain (mappingCone φ) G 0 := Cochain.ofHoms (homotopyCofiber.sndX φ) @[reassoc (attr := simp)] lemma inl_v_fst_v (p q : ℤ) (hpq : q + 1 = p) : (inl φ).v p q (by rw [← hpq, add_neg_cancel_right]) ≫ (fst φ : Cochain (mappingCone φ) F 1).v q p hpq = 𝟙 _ := by simp [inl, fst] @[reassoc (attr := simp)] lemma inl_v_snd_v (p q : ℤ) (hpq : p + (-1) = q) : (inl φ).v p q hpq ≫ (snd φ).v q q (add_zero q) = 0 := by simp [inl, snd] @[reassoc (attr := simp)] lemma inr_f_fst_v (p q : ℤ) (hpq : p + 1 = q) : (inr φ).f p ≫ (fst φ).1.v p q hpq = 0 := by simp [inr, fst] @[reassoc (attr := simp)] lemma inr_f_snd_v (p : ℤ) : (inr φ).f p ≫ (snd φ).v p p (add_zero p) = 𝟙 _ := by simp [inr, snd] @[simp] lemma inl_fst : (inl φ).comp (fst φ).1 (neg_add_cancel 1) = Cochain.ofHom (𝟙 F) := by ext p simp [Cochain.comp_v _ _ (neg_add_cancel 1) p (p-1) p rfl (by cutsat)] @[simp] lemma inl_snd : (inl φ).comp (snd φ) (add_zero (-1)) = 0 := by ext simp @[simp] lemma inr_fst : (Cochain.ofHom (inr φ)).comp (fst φ).1 (zero_add 1) = 0 := by ext simp @[simp] lemma inr_snd : (Cochain.ofHom (inr φ)).comp (snd φ) (zero_add 0) = Cochain.ofHom (𝟙 G) := by cat_disch /-! In order to obtain identities of cochains involving `inl`, `inr`, `fst` and `snd`, it is often convenient to use an `ext` lemma, and use simp lemmas like `inl_v_f_fst_v`, but it is sometimes possible to get identities of cochains by using rewrites of identities of cochains like `inl_fst`. Then, similarly as in category theory, if we associate the compositions of cochains to the right as much as possible, it is also interesting to have `reassoc` variants of lemmas, like `inl_fst_assoc`. -/ @[simp] lemma inl_fst_assoc {K : CochainComplex C ℤ} {d e : ℤ} (γ : Cochain F K d) (he : 1 + d = e) : (inl φ).comp ((fst φ).1.comp γ he) (by rw [← he, neg_add_cancel_left]) = γ := by rw [← Cochain.comp_assoc _ _ _ (neg_add_cancel 1) (by cutsat) (by cutsat), inl_fst, Cochain.id_comp] @[simp] lemma inl_snd_assoc {K : CochainComplex C ℤ} {d e f : ℤ} (γ : Cochain G K d) (he : 0 + d = e) (hf : -1 + e = f) : (inl φ).comp ((snd φ).comp γ he) hf = 0 := by obtain rfl : e = d := by cutsat rw [← Cochain.comp_assoc_of_second_is_zero_cochain, inl_snd, Cochain.zero_comp] @[simp] lemma inr_fst_assoc {K : CochainComplex C ℤ} {d e f : ℤ} (γ : Cochain F K d) (he : 1 + d = e) (hf : 0 + e = f) : (Cochain.ofHom (inr φ)).comp ((fst φ).1.comp γ he) hf = 0 := by obtain rfl : e = f := by cutsat rw [← Cochain.comp_assoc_of_first_is_zero_cochain, inr_fst, Cochain.zero_comp] @[simp] lemma inr_snd_assoc {K : CochainComplex C ℤ} {d e : ℤ} (γ : Cochain G K d) (he : 0 + d = e) : (Cochain.ofHom (inr φ)).comp ((snd φ).comp γ he) (by simp only [← he, zero_add]) = γ := by obtain rfl : d = e := by cutsat rw [← Cochain.comp_assoc_of_first_is_zero_cochain, inr_snd, Cochain.id_comp] lemma ext_to (i j : ℤ) (hij : i + 1 = j) {A : C} {f g : A ⟶ (mappingCone φ).X i} (h₁ : f ≫ (fst φ).1.v i j hij = g ≫ (fst φ).1.v i j hij) (h₂ : f ≫ (snd φ).v i i (add_zero i) = g ≫ (snd φ).v i i (add_zero i)) : f = g := homotopyCofiber.ext_to_X φ i j hij h₁ (by simpa [snd] using h₂) lemma ext_to_iff (i j : ℤ) (hij : i + 1 = j) {A : C} (f g : A ⟶ (mappingCone φ).X i) : f = g ↔ f ≫ (fst φ).1.v i j hij = g ≫ (fst φ).1.v i j hij ∧ f ≫ (snd φ).v i i (add_zero i) = g ≫ (snd φ).v i i (add_zero i) := by constructor · rintro rfl tauto · rintro ⟨h₁, h₂⟩ exact ext_to φ i j hij h₁ h₂ lemma ext_from (i j : ℤ) (hij : j + 1 = i) {A : C} {f g : (mappingCone φ).X j ⟶ A} (h₁ : (inl φ).v i j (by cutsat) ≫ f = (inl φ).v i j (by cutsat) ≫ g) (h₂ : (inr φ).f j ≫ f = (inr φ).f j ≫ g) : f = g := homotopyCofiber.ext_from_X φ i j hij h₁ h₂ lemma ext_from_iff (i j : ℤ) (hij : j + 1 = i) {A : C} (f g : (mappingCone φ).X j ⟶ A) : f = g ↔ (inl φ).v i j (by cutsat) ≫ f = (inl φ).v i j (by cutsat) ≫ g ∧ (inr φ).f j ≫ f = (inr φ).f j ≫ g := by constructor · rintro rfl tauto · rintro ⟨h₁, h₂⟩ exact ext_from φ i j hij h₁ h₂ lemma decomp_to {i : ℤ} {A : C} (f : A ⟶ (mappingCone φ).X i) (j : ℤ) (hij : i + 1 = j) : ∃ (a : A ⟶ F.X j) (b : A ⟶ G.X i), f = a ≫ (inl φ).v j i (by cutsat) + b ≫ (inr φ).f i := ⟨f ≫ (fst φ).1.v i j hij, f ≫ (snd φ).v i i (add_zero i), by apply ext_to φ i j hij <;> simp⟩ lemma decomp_from {j : ℤ} {A : C} (f : (mappingCone φ).X j ⟶ A) (i : ℤ) (hij : j + 1 = i) : ∃ (a : F.X i ⟶ A) (b : G.X j ⟶ A), f = (fst φ).1.v j i hij ≫ a + (snd φ).v j j (add_zero j) ≫ b := ⟨(inl φ).v i j (by cutsat) ≫ f, (inr φ).f j ≫ f, by apply ext_from φ i j hij <;> simp⟩ lemma ext_cochain_to_iff (i j : ℤ) (hij : i + 1 = j) {K : CochainComplex C ℤ} {γ₁ γ₂ : Cochain K (mappingCone φ) i} : γ₁ = γ₂ ↔ γ₁.comp (fst φ).1 hij = γ₂.comp (fst φ).1 hij ∧ γ₁.comp (snd φ) (add_zero i) = γ₂.comp (snd φ) (add_zero i) := by constructor · rintro rfl tauto · rintro ⟨h₁, h₂⟩ ext p q hpq rw [ext_to_iff φ q (q + 1) rfl] replace h₁ := Cochain.congr_v h₁ p (q + 1) (by cutsat) replace h₂ := Cochain.congr_v h₂ p q hpq simp only [Cochain.comp_v _ _ _ p q (q + 1) hpq rfl] at h₁ simp only [Cochain.comp_zero_cochain_v] at h₂ exact ⟨h₁, h₂⟩ lemma ext_cochain_from_iff (i j : ℤ) (hij : i + 1 = j) {K : CochainComplex C ℤ} {γ₁ γ₂ : Cochain (mappingCone φ) K j} : γ₁ = γ₂ ↔ (inl φ).comp γ₁ (show _ = i by cutsat) = (inl φ).comp γ₂ (by cutsat) ∧ (Cochain.ofHom (inr φ)).comp γ₁ (zero_add j) = (Cochain.ofHom (inr φ)).comp γ₂ (zero_add j) := by constructor · rintro rfl tauto · rintro ⟨h₁, h₂⟩ ext p q hpq rw [ext_from_iff φ (p + 1) p rfl] replace h₁ := Cochain.congr_v h₁ (p + 1) q (by cutsat) replace h₂ := Cochain.congr_v h₂ p q (by cutsat) simp only [Cochain.comp_v (inl φ) _ _ (p + 1) p q (by cutsat) hpq] at h₁ simp only [Cochain.zero_cochain_comp_v, Cochain.ofHom_v] at h₂ exact ⟨h₁, h₂⟩ lemma id : (fst φ).1.comp (inl φ) (add_neg_cancel 1) + (snd φ).comp (Cochain.ofHom (inr φ)) (add_zero 0) = Cochain.ofHom (𝟙 _) := by simp [ext_cochain_from_iff φ (-1) 0 (neg_add_cancel 1)] lemma id_X (p q : ℤ) (hpq : p + 1 = q) : (fst φ).1.v p q hpq ≫ (inl φ).v q p (by cutsat) + (snd φ).v p p (add_zero p) ≫ (inr φ).f p = 𝟙 ((mappingCone φ).X p) := by simpa only [Cochain.add_v, Cochain.comp_zero_cochain_v, Cochain.ofHom_v, id_f, Cochain.comp_v _ _ (add_neg_cancel 1) p q p hpq (by cutsat)] using Cochain.congr_v (id φ) p p (add_zero p) @[reassoc] lemma inl_v_d (i j k : ℤ) (hij : i + (-1) = j) (hik : k + (-1) = i) : (inl φ).v i j hij ≫ (mappingCone φ).d j i = φ.f i ≫ (inr φ).f i - F.d i k ≫ (inl φ).v _ _ hik := by dsimp [mappingCone, inl, inr] rw [homotopyCofiber.inlX_d φ j i k (by dsimp; cutsat) (by dsimp; cutsat)] abel @[reassoc] lemma inr_f_d (n₁ n₂ : ℤ) : (inr φ).f n₁ ≫ (mappingCone φ).d n₁ n₂ = G.d n₁ n₂ ≫ (inr φ).f n₂ := by simp @[reassoc] lemma d_fst_v (i j k : ℤ) (hij : i + 1 = j) (hjk : j + 1 = k) : (mappingCone φ).d i j ≫ (fst φ).1.v j k hjk = -(fst φ).1.v i j hij ≫ F.d j k := by apply homotopyCofiber.d_fstX @[reassoc (attr := simp)] lemma d_fst_v' (i j : ℤ) (hij : i + 1 = j) : (mappingCone φ).d (i - 1) i ≫ (fst φ).1.v i j hij = -(fst φ).1.v (i - 1) i (by cutsat) ≫ F.d i j := d_fst_v φ (i - 1) i j (by cutsat) hij @[reassoc] lemma d_snd_v (i j : ℤ) (hij : i + 1 = j) : (mappingCone φ).d i j ≫ (snd φ).v j j (add_zero _) = (fst φ).1.v i j hij ≫ φ.f j + (snd φ).v i i (add_zero i) ≫ G.d i j := by dsimp [mappingCone, snd, fst] simp only [Cochain.ofHoms_v] apply homotopyCofiber.d_sndX @[reassoc (attr := simp)] lemma d_snd_v' (n : ℤ) : (mappingCone φ).d (n - 1) n ≫ (snd φ).v n n (add_zero n) = (fst φ : Cochain (mappingCone φ) F 1).v (n - 1) n (by cutsat) ≫ φ.f n + (snd φ).v (n - 1) (n - 1) (add_zero _) ≫ G.d (n - 1) n := by apply d_snd_v @[simp] lemma δ_inl : δ (-1) 0 (inl φ) = Cochain.ofHom (φ ≫ inr φ) := by ext p simp [δ_v (-1) 0 (neg_add_cancel 1) (inl φ) p p (add_zero p) _ _ rfl rfl, inl_v_d φ p (p - 1) (p + 1) (by cutsat) (by cutsat)] @[simp] lemma δ_snd : δ 0 1 (snd φ) = -(fst φ).1.comp (Cochain.ofHom φ) (add_zero 1) := by ext p q hpq simp [d_snd_v φ p q hpq] section variable {K : CochainComplex C ℤ} {n m : ℤ} /-- Given `φ : F ⟶ G`, this is the cochain in `Cochain (mappingCone φ) K n` that is constructed from two cochains `α : Cochain F K m` (with `m + 1 = n`) and `β : Cochain F K n`. -/ noncomputable def descCochain (α : Cochain F K m) (β : Cochain G K n) (h : m + 1 = n) : Cochain (mappingCone φ) K n := (fst φ).1.comp α (by rw [← h, add_comm]) + (snd φ).comp β (zero_add n) variable (α : Cochain F K m) (β : Cochain G K n) (h : m + 1 = n) @[simp] lemma inl_descCochain : (inl φ).comp (descCochain φ α β h) (by cutsat) = α := by simp [descCochain] @[simp] lemma inr_descCochain : (Cochain.ofHom (inr φ)).comp (descCochain φ α β h) (zero_add n) = β := by simp [descCochain] @[reassoc (attr := simp)] lemma inl_v_descCochain_v (p₁ p₂ p₃ : ℤ) (h₁₂ : p₁ + (-1) = p₂) (h₂₃ : p₂ + n = p₃) : (inl φ).v p₁ p₂ h₁₂ ≫ (descCochain φ α β h).v p₂ p₃ h₂₃ = α.v p₁ p₃ (by rw [← h₂₃, ← h₁₂, ← h, add_comm m, add_assoc, neg_add_cancel_left]) := by simpa only [Cochain.comp_v _ _ (show -1 + n = m by cutsat) p₁ p₂ p₃ (by cutsat) (by cutsat)] using Cochain.congr_v (inl_descCochain φ α β h) p₁ p₃ (by cutsat) @[reassoc (attr := simp)] lemma inr_f_descCochain_v (p₁ p₂ : ℤ) (h₁₂ : p₁ + n = p₂) : (inr φ).f p₁ ≫ (descCochain φ α β h).v p₁ p₂ h₁₂ = β.v p₁ p₂ h₁₂ := by simpa only [Cochain.comp_v _ _ (zero_add n) p₁ p₁ p₂ (add_zero p₁) h₁₂, Cochain.ofHom_v] using Cochain.congr_v (inr_descCochain φ α β h) p₁ p₂ (by cutsat) lemma δ_descCochain (n' : ℤ) (hn' : n + 1 = n') : δ n n' (descCochain φ α β h) = (fst φ).1.comp (δ m n α + n'.negOnePow • (Cochain.ofHom φ).comp β (zero_add n)) (by cutsat) + (snd φ).comp (δ n n' β) (zero_add n') := by dsimp only [descCochain] simp only [δ_add, Cochain.comp_add, δ_comp (fst φ).1 α _ 2 n n' hn' (by cutsat) (by cutsat), Cocycle.δ_eq_zero, Cochain.zero_comp, smul_zero, add_zero, δ_comp (snd φ) β (zero_add n) 1 n' n' hn' (zero_add 1) hn', δ_snd, Cochain.neg_comp, smul_neg, Cochain.comp_assoc_of_second_is_zero_cochain, Cochain.comp_units_smul, ← hn', Int.negOnePow_succ, Units.neg_smul, Cochain.comp_neg] abel end /-- Given `φ : F ⟶ G`, this is the cocycle in `Cocycle (mappingCone φ) K n` that is constructed from `α : Cochain F K m` (with `m + 1 = n`) and `β : Cocycle F K n`, when a suitable cocycle relation is satisfied. -/ @[simps!] noncomputable def descCocycle {K : CochainComplex C ℤ} {n m : ℤ} (α : Cochain F K m) (β : Cocycle G K n) (h : m + 1 = n) (eq : δ m n α = n.negOnePow • (Cochain.ofHom φ).comp β.1 (zero_add n)) : Cocycle (mappingCone φ) K n := Cocycle.mk (descCochain φ α β.1 h) (n + 1) rfl (by simp [δ_descCochain _ _ _ _ _ rfl, eq, Int.negOnePow_succ]) section variable {K : CochainComplex C ℤ} /-- Given `φ : F ⟶ G`, this is the morphism `mappingCone φ ⟶ K` that is constructed from a cochain `α : Cochain F K (-1)` and a morphism `β : G ⟶ K` such that `δ (-1) 0 α = Cochain.ofHom (φ ≫ β)`. -/ noncomputable def desc (α : Cochain F K (-1)) (β : G ⟶ K) (eq : δ (-1) 0 α = Cochain.ofHom (φ ≫ β)) : mappingCone φ ⟶ K := Cocycle.homOf (descCocycle φ α (Cocycle.ofHom β) (neg_add_cancel 1) (by simp [eq])) variable (α : Cochain F K (-1)) (β : G ⟶ K) (eq : δ (-1) 0 α = Cochain.ofHom (φ ≫ β)) @[simp] lemma ofHom_desc : Cochain.ofHom (desc φ α β eq) = descCochain φ α (Cochain.ofHom β) (neg_add_cancel 1) := by simp [desc] @[reassoc (attr := simp)] lemma inl_v_desc_f (p q : ℤ) (h : p + (-1) = q) : (inl φ).v p q h ≫ (desc φ α β eq).f q = α.v p q h := by simp [desc] lemma inl_desc : (inl φ).comp (Cochain.ofHom (desc φ α β eq)) (add_zero _) = α := by simp @[reassoc (attr := simp)] lemma inr_f_desc_f (p : ℤ) : (inr φ).f p ≫ (desc φ α β eq).f p = β.f p := by simp [desc] @[reassoc (attr := simp)] lemma inr_desc : inr φ ≫ desc φ α β eq = β := by cat_disch lemma desc_f (p q : ℤ) (hpq : p + 1 = q) : (desc φ α β eq).f p = (fst φ).1.v p q hpq ≫ α.v q p (by cutsat) + (snd φ).v p p (add_zero p) ≫ β.f p := by simp [ext_from_iff _ _ _ hpq] end /-- Constructor for homotopies between morphisms from a mapping cone. -/ noncomputable def descHomotopy {K : CochainComplex C ℤ} (f₁ f₂ : mappingCone φ ⟶ K) (γ₁ : Cochain F K (-2)) (γ₂ : Cochain G K (-1)) (h₁ : (inl φ).comp (Cochain.ofHom f₁) (add_zero (-1)) = δ (-2) (-1) γ₁ + (Cochain.ofHom φ).comp γ₂ (zero_add (-1)) + (inl φ).comp (Cochain.ofHom f₂) (add_zero (-1))) (h₂ : Cochain.ofHom (inr φ ≫ f₁) = δ (-1) 0 γ₂ + Cochain.ofHom (inr φ ≫ f₂)) : Homotopy f₁ f₂ := (Cochain.equivHomotopy f₁ f₂).symm ⟨descCochain φ γ₁ γ₂ (by simp), by simp only [Cochain.ofHom_comp] at h₂ simp [ext_cochain_from_iff _ _ _ (neg_add_cancel 1), δ_descCochain _ _ _ _ _ (neg_add_cancel 1), h₁, h₂]⟩ section variable {K : CochainComplex C ℤ} {n m : ℤ} /-- Given `φ : F ⟶ G`, this is the cochain in `Cochain (mappingCone φ) K n` that is constructed from two cochains `α : Cochain F K m` (with `m + 1 = n`) and `β : Cochain F K n`. -/ noncomputable def liftCochain (α : Cochain K F m) (β : Cochain K G n) (h : n + 1 = m) : Cochain K (mappingCone φ) n := α.comp (inl φ) (by cutsat) + β.comp (Cochain.ofHom (inr φ)) (add_zero n) variable (α : Cochain K F m) (β : Cochain K G n) (h : n + 1 = m) @[simp] lemma liftCochain_fst : (liftCochain φ α β h).comp (fst φ).1 h = α := by simp [liftCochain] @[simp] lemma liftCochain_snd : (liftCochain φ α β h).comp (snd φ) (add_zero n) = β := by simp [liftCochain] @[reassoc (attr := simp)] lemma liftCochain_v_fst_v (p₁ p₂ p₃ : ℤ) (h₁₂ : p₁ + n = p₂) (h₂₃ : p₂ + 1 = p₃) : (liftCochain φ α β h).v p₁ p₂ h₁₂ ≫ (fst φ).1.v p₂ p₃ h₂₃ = α.v p₁ p₃ (by cutsat) := by simpa only [Cochain.comp_v _ _ h p₁ p₂ p₃ h₁₂ h₂₃] using Cochain.congr_v (liftCochain_fst φ α β h) p₁ p₃ (by cutsat) @[reassoc (attr := simp)] lemma liftCochain_v_snd_v (p₁ p₂ : ℤ) (h₁₂ : p₁ + n = p₂) : (liftCochain φ α β h).v p₁ p₂ h₁₂ ≫ (snd φ).v p₂ p₂ (add_zero p₂) = β.v p₁ p₂ h₁₂ := by simpa only [Cochain.comp_v _ _ (add_zero n) p₁ p₂ p₂ h₁₂ (add_zero p₂)] using Cochain.congr_v (liftCochain_snd φ α β h) p₁ p₂ (by cutsat) lemma δ_liftCochain (m' : ℤ) (hm' : m + 1 = m') : δ n m (liftCochain φ α β h) = -(δ m m' α).comp (inl φ) (by cutsat) + (δ n m β + α.comp (Cochain.ofHom φ) (add_zero m)).comp (Cochain.ofHom (inr φ)) (add_zero m) := by dsimp only [liftCochain] simp only [δ_add, δ_comp α (inl φ) _ m' _ _ h hm' (neg_add_cancel 1), δ_comp_zero_cochain _ _ _ h, δ_inl, Cochain.ofHom_comp, Int.negOnePow_neg, Int.negOnePow_one, Units.neg_smul, one_smul, δ_ofHom, Cochain.comp_zero, zero_add, Cochain.add_comp, Cochain.comp_assoc_of_second_is_zero_cochain] abel end /-- Given `φ : F ⟶ G`, this is the cocycle in `Cocycle K (mappingCone φ) n` that is constructed from `α : Cochain K F m` (with `n + 1 = m`) and `β : Cocycle K G n`, when a suitable cocycle relation is satisfied. -/ @[simps!] noncomputable def liftCocycle {K : CochainComplex C ℤ} {n m : ℤ} (α : Cocycle K F m) (β : Cochain K G n) (h : n + 1 = m) (eq : δ n m β + α.1.comp (Cochain.ofHom φ) (add_zero m) = 0) : Cocycle K (mappingCone φ) n := Cocycle.mk (liftCochain φ α β h) m h (by simp only [δ_liftCochain φ α β h (m+1) rfl, eq, Cocycle.δ_eq_zero, Cochain.zero_comp, neg_zero, add_zero]) section variable {K : CochainComplex C ℤ} (α : Cocycle K F 1) (β : Cochain K G 0) (eq : δ 0 1 β + α.1.comp (Cochain.ofHom φ) (add_zero 1) = 0) /-- Given `φ : F ⟶ G`, this is the morphism `K ⟶ mappingCone φ` that is constructed from a cocycle `α : Cochain K F 1` and a cochain `β : Cochain K G 0` when a suitable cocycle relation is satisfied. -/ noncomputable def lift : K ⟶ mappingCone φ := Cocycle.homOf (liftCocycle φ α β (zero_add 1) eq) @[simp] lemma ofHom_lift : Cochain.ofHom (lift φ α β eq) = liftCochain φ α β (zero_add 1) := by simp only [lift, Cocycle.cochain_ofHom_homOf_eq_coe, liftCocycle_coe] @[reassoc (attr := simp)] lemma lift_f_fst_v (p q : ℤ) (hpq : p + 1 = q) : (lift φ α β eq).f p ≫ (fst φ).1.v p q hpq = α.1.v p q hpq := by simp [lift] lemma lift_fst : (Cochain.ofHom (lift φ α β eq)).comp (fst φ).1 (zero_add 1) = α.1 := by simp @[reassoc (attr := simp)] lemma lift_f_snd_v (p q : ℤ) (hpq : p + 0 = q) : (lift φ α β eq).f p ≫ (snd φ).v p q hpq = β.v p q hpq := by obtain rfl : q = p := by cutsat simp [lift] lemma lift_snd : (Cochain.ofHom (lift φ α β eq)).comp (snd φ) (zero_add 0) = β := by simp lemma lift_f (p q : ℤ) (hpq : p + 1 = q) : (lift φ α β eq).f p = α.1.v p q hpq ≫ (inl φ).v q p (by omega) + β.v p p (add_zero p) ≫ (inr φ).f p := by simp [ext_to_iff _ _ _ hpq] end /-- Constructor for homotopies between morphisms to a mapping cone. -/ noncomputable def liftHomotopy {K : CochainComplex C ℤ} (f₁ f₂ : K ⟶ mappingCone φ) (α : Cochain K F 0) (β : Cochain K G (-1)) (h₁ : (Cochain.ofHom f₁).comp (fst φ).1 (zero_add 1) = -δ 0 1 α + (Cochain.ofHom f₂).comp (fst φ).1 (zero_add 1)) (h₂ : (Cochain.ofHom f₁).comp (snd φ) (zero_add 0) = δ (-1) 0 β + α.comp (Cochain.ofHom φ) (zero_add 0) + (Cochain.ofHom f₂).comp (snd φ) (zero_add 0)) : Homotopy f₁ f₂ := (Cochain.equivHomotopy f₁ f₂).symm ⟨liftCochain φ α β (neg_add_cancel 1), by simp [δ_liftCochain _ _ _ _ _ (zero_add 1), ext_cochain_to_iff _ _ _ (zero_add 1), h₁, h₂]⟩ section variable {K L : CochainComplex C ℤ} {n m : ℤ} (α : Cochain K F m) (β : Cochain K G n) {n' m' : ℤ} (α' : Cochain F L m') (β' : Cochain G L n') (h : n + 1 = m) (h' : m' + 1 = n') (p : ℤ) (hp : n + n' = p) @[simp] lemma liftCochain_descCochain : (liftCochain φ α β h).comp (descCochain φ α' β' h') hp = α.comp α' (by cutsat) + β.comp β' (by cutsat) := by simp [liftCochain, descCochain, Cochain.comp_assoc α (inl φ) _ _ (show -1 + n' = m' by cutsat) (by linarith)] lemma liftCochain_v_descCochain_v (p₁ p₂ p₃ : ℤ) (h₁₂ : p₁ + n = p₂) (h₂₃ : p₂ + n' = p₃) (q : ℤ) (hq : p₁ + m = q) : (liftCochain φ α β h).v p₁ p₂ h₁₂ ≫ (descCochain φ α' β' h').v p₂ p₃ h₂₃ = α.v p₁ q hq ≫ α'.v q p₃ (by cutsat) + β.v p₁ p₂ h₁₂ ≫ β'.v p₂ p₃ h₂₃ := by have eq := Cochain.congr_v (liftCochain_descCochain φ α β α' β' h h' p hp) p₁ p₃ (by cutsat) simpa only [Cochain.comp_v _ _ hp p₁ p₂ p₃ h₁₂ h₂₃, Cochain.add_v, Cochain.comp_v _ _ _ _ _ _ hq (show q + m' = p₃ by cutsat)] using eq end lemma lift_desc_f {K L : CochainComplex C ℤ} (α : Cocycle K F 1) (β : Cochain K G 0) (eq : δ 0 1 β + α.1.comp (Cochain.ofHom φ) (add_zero 1) = 0) (α' : Cochain F L (-1)) (β' : G ⟶ L) (eq' : δ (-1) 0 α' = Cochain.ofHom (φ ≫ β')) (n n' : ℤ) (hnn' : n + 1 = n') : (lift φ α β eq).f n ≫ (desc φ α' β' eq').f n = α.1.v n n' hnn' ≫ α'.v n' n (by omega) + β.v n n (add_zero n) ≫ β'.f n := by simp only [lift, desc, Cocycle.homOf_f, liftCocycle_coe, descCocycle_coe, Cocycle.ofHom_coe, liftCochain_v_descCochain_v φ α.1 β α' (Cochain.ofHom β') (zero_add 1) (neg_add_cancel 1) 0 (add_zero 0) n n n (add_zero n) (add_zero n) n' hnn', Cochain.ofHom_v] section open Preadditive Category variable (H : C ⥤ D) [H.Additive] [HasHomotopyCofiber ((H.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)] /-- If `H : C ⥤ D` is an additive functor and `φ` is a morphism of cochain complexes in `C`, this is the comparison isomorphism (in each degree `n`) between the image by `H` of `mappingCone φ` and the mapping cone of the image by `H` of `φ`. It is an auxiliary definition for `mapHomologicalComplexXIso` and `mapHomologicalComplexIso`. This definition takes an extra parameter `m : ℤ` such that `n + 1 = m` which may help getting better definitional properties. See also the equational lemma `mapHomologicalComplexXIso_eq`. -/ @[simps] noncomputable def mapHomologicalComplexXIso' (n m : ℤ) (hnm : n + 1 = m) : ((H.mapHomologicalComplex (ComplexShape.up ℤ)).obj (mappingCone φ)).X n ≅ (mappingCone ((H.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)).X n where hom := H.map ((fst φ).1.v n m (by omega)) ≫ (inl ((H.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)).v m n (by omega) + H.map ((snd φ).v n n (add_zero n)) ≫ (inr ((H.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)).f n inv := (fst ((H.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)).1.v n m (by omega) ≫ H.map ((inl φ).v m n (by omega)) + (snd ((H.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)).v n n (add_zero n) ≫ H.map ((inr φ).f n) hom_inv_id := by simp only [Functor.mapHomologicalComplex_obj_X, comp_add, add_comp, assoc, inl_v_fst_v_assoc, inr_f_fst_v_assoc, zero_comp, comp_zero, add_zero, inl_v_snd_v_assoc, inr_f_snd_v_assoc, zero_add, ← Functor.map_comp, ← Functor.map_add] rw [← H.map_id] congr 1 simp [ext_from_iff _ _ _ hnm] inv_hom_id := by simp only [Functor.mapHomologicalComplex_obj_X, comp_add, add_comp, assoc, ← H.map_comp_assoc, inl_v_fst_v, CategoryTheory.Functor.map_id, id_comp, inr_f_fst_v, inl_v_snd_v, inr_f_snd_v] simp [ext_from_iff _ _ _ hnm] /-- If `H : C ⥤ D` is an additive functor and `φ` is a morphism of cochain complexes in `C`, this is the comparison isomorphism (in each degree) between the image by `H` of `mappingCone φ` and the mapping cone of the image by `H` of `φ`. -/ noncomputable def mapHomologicalComplexXIso (n : ℤ) : ((H.mapHomologicalComplex (ComplexShape.up ℤ)).obj (mappingCone φ)).X n ≅ (mappingCone ((H.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)).X n := mapHomologicalComplexXIso' φ H n (n + 1) rfl lemma mapHomologicalComplexXIso_eq (n m : ℤ) (hnm : n + 1 = m) : mapHomologicalComplexXIso φ H n = mapHomologicalComplexXIso' φ H n m hnm := by subst hnm rfl /-- If `H : C ⥤ D` is an additive functor and `φ` is a morphism of cochain complexes in `C`, this is the comparison isomorphism between the image by `H` of `mappingCone φ` and the mapping cone of the image by `H` of `φ`. -/ noncomputable def mapHomologicalComplexIso : (H.mapHomologicalComplex _).obj (mappingCone φ) ≅ mappingCone ((H.mapHomologicalComplex _).map φ) := HomologicalComplex.Hom.isoOfComponents (mapHomologicalComplexXIso φ H) (by rintro n _ rfl rw [ext_to_iff _ _ (n + 2) (by cutsat), assoc, assoc, d_fst_v _ _ _ _ rfl, assoc, assoc, d_snd_v _ _ _ rfl] simp only [mapHomologicalComplexXIso_eq φ H n (n + 1) rfl, mapHomologicalComplexXIso_eq φ H (n + 1) (n + 2) (by cutsat), mapHomologicalComplexXIso'_hom, mapHomologicalComplexXIso'_hom] constructor · dsimp simp only [Functor.mapHomologicalComplex_obj_X, comp_neg, add_comp, assoc, inl_v_fst_v_assoc, inr_f_fst_v_assoc, zero_comp, comp_zero, add_zero, inl_v_fst_v, comp_id, inr_f_fst_v, ← H.map_comp, d_fst_v φ n (n + 1) (n + 2) rfl (by cutsat), Functor.map_neg] · dsimp simp only [comp_add, add_comp, assoc, inl_v_fst_v_assoc, inr_f_fst_v_assoc, Functor.mapHomologicalComplex_obj_X, zero_comp, comp_zero, add_zero, inl_v_snd_v_assoc, inr_f_snd_v_assoc, zero_add, inl_v_snd_v, inr_f_snd_v, comp_id, ← H.map_comp, d_snd_v φ n (n + 1) rfl, Functor.map_add]) lemma map_inr : (H.mapHomologicalComplex (ComplexShape.up ℤ)).map (inr φ) ≫ (mapHomologicalComplexIso φ H).hom = inr ((Functor.mapHomologicalComplex H (ComplexShape.up ℤ)).map φ) := by ext n dsimp [mapHomologicalComplexIso] simp only [mapHomologicalComplexXIso_eq φ H n (n + 1) rfl, mappingCone.ext_to_iff _ _ _ rfl, Functor.mapHomologicalComplex_obj_X, mapHomologicalComplexXIso'_hom, comp_add, add_comp, assoc, inl_v_fst_v, comp_id, inr_f_fst_v, comp_zero, add_zero, inl_v_snd_v, inr_f_snd_v, zero_add, ← H.map_comp, H.map_zero, H.map_id, and_self] end end mappingCone end CochainComplex
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/HomologicalFunctor.lean
import Mathlib.Algebra.Homology.HomologicalComplexAbelian import Mathlib.Algebra.Homology.HomotopyCategory.DegreewiseSplit import Mathlib.Algebra.Homology.HomologySequence import Mathlib.CategoryTheory.Triangulated.HomologicalFunctor /-! The homological functor In this file, it is shown that if `C` is an abelian category, then `homologyFunctor C (ComplexShape.up ℤ) n` is a homological functor `HomotopyCategory C (ComplexShape.up ℤ) ⥤ C`. As distinguished triangles in the homotopy category can be characterized in terms of degreewise split short exact sequences of cochain complexes, this follows from the homology sequence associated to a short exact sequence of homological complexes. -/ assert_not_exists TwoSidedIdeal open CategoryTheory variable {C : Type*} [Category C] [Abelian C] namespace HomotopyCategory instance (n : ℤ) : (homologyFunctor C (ComplexShape.up ℤ) n).IsHomological := Functor.IsHomological.mk' _ (fun T hT => by rw [distinguished_iff_iso_trianglehOfDegreewiseSplit] at hT obtain ⟨S, σ, ⟨e⟩⟩ := hT have hS := HomologicalComplex.shortExact_of_degreewise_shortExact S (fun n => (σ n).shortExact) exact ⟨_, e, (ShortComplex.exact_iff_of_iso (S.mapNatIso (homologyFunctorFactors C (ComplexShape.up ℤ) n))).2 (hS.homology_exact₂ n)⟩) end HomotopyCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/SingleFunctors.lean
import Mathlib.Algebra.Homology.HomotopyCategory.Shift import Mathlib.CategoryTheory.Shift.SingleFunctors /-! # Single functors from the homotopy category Let `C` be a preadditive category with a zero object. In this file, we put together all the single functors `C ⥤ CochainComplex C ℤ` along with their compatibilities with shifts into the definition `CochainComplex.singleFunctors C : SingleFunctors C (CochainComplex C ℤ) ℤ`. Similarly, we define `HomotopyCategory.singleFunctors C : SingleFunctors C (HomotopyCategory C (ComplexShape.up ℤ)) ℤ`. -/ assert_not_exists TwoSidedIdeal universe v' u' v u open CategoryTheory Category Limits variable (C : Type u) [Category.{v} C] [Preadditive C] [HasZeroObject C] namespace CochainComplex open HomologicalComplex /-- The collection of all single functors `C ⥤ CochainComplex C ℤ` along with their compatibilites with shifts. (This definition has purposely no `simps` attribute, as the generated lemmas would not be very useful.) -/ noncomputable def singleFunctors : SingleFunctors C (CochainComplex C ℤ) ℤ where functor n := single _ _ n shiftIso n a a' ha' := NatIso.ofComponents (fun X => Hom.isoOfComponents (fun i => eqToIso (by obtain rfl : a' = a + n := by omega by_cases h : i = a · subst h simp only [Functor.comp_obj, shiftFunctor_obj_X', single_obj_X_self] · dsimp [single] rw [if_neg h, if_neg (fun h' => h (by omega))]))) (fun {X Y} f => by obtain rfl : a' = a + n := by omega ext simp [single]) shiftIso_zero a := by ext dsimp simp only [single, shiftFunctorZero_eq, shiftFunctorZero'_hom_app_f, XIsoOfEq, eqToIso.hom] shiftIso_add n m a a' a'' ha' ha'' := by ext dsimp simp only [shiftFunctorAdd_eq, shiftFunctorAdd'_hom_app_f, XIsoOfEq, eqToIso.hom, eqToHom_trans, id_comp] instance (n : ℤ) : ((singleFunctors C).functor n).Additive := by dsimp only [singleFunctors] infer_instance instance (R : Type*) [Ring R] (n : ℤ) [Linear R C] : Functor.Linear R ((singleFunctors C).functor n) where map_smul f r := by dsimp [CochainComplex.singleFunctors, HomologicalComplex.single] aesop /-- The single functor `C ⥤ CochainComplex C ℤ` which sends `X` to the complex consisting of `X` in degree `n : ℤ` and zero otherwise. (This is definitionally equal to `HomologicalComplex.single C (up ℤ) n`, but `singleFunctor C n` is the preferred term when interactions with shifts are relevant.) -/ noncomputable abbrev singleFunctor (n : ℤ) := (singleFunctors C).functor n instance (n : ℤ) : (singleFunctor C n).Full := inferInstanceAs (single _ _ _).Full instance (n : ℤ) : (singleFunctor C n).Faithful := inferInstanceAs (single _ _ _).Faithful end CochainComplex namespace HomotopyCategory /-- The collection of all single functors `C ⥤ HomotopyCategory C (ComplexShape.up ℤ))` for `n : ℤ` along with their compatibilites with shifts. -/ noncomputable def singleFunctors : SingleFunctors C (HomotopyCategory C (ComplexShape.up ℤ)) ℤ := (CochainComplex.singleFunctors C).postcomp (HomotopyCategory.quotient _ _) /-- The single functor `C ⥤ HomotopyCategory C (ComplexShape.up ℤ)` which sends `X` to the complex consisting of `X` in degree `n : ℤ` and zero otherwise. -/ noncomputable abbrev singleFunctor (n : ℤ) : C ⥤ HomotopyCategory C (ComplexShape.up ℤ) := (singleFunctors C).functor n instance (n : ℤ) : (singleFunctor C n).Additive := by dsimp only [singleFunctor, singleFunctors, SingleFunctors.postcomp] infer_instance -- The object level definitional equality underlying `singleFunctorsPostcompQuotientIso`. @[simp] theorem quotient_obj_singleFunctors_obj (n : ℤ) (X : C) : (HomotopyCategory.quotient C (ComplexShape.up ℤ)).obj ((CochainComplex.singleFunctor C n).obj X) = (HomotopyCategory.singleFunctor C n).obj X := rfl instance (R : Type*) [Ring R] [Linear R C] (n : ℤ) : Functor.Linear R (HomotopyCategory.singleFunctor C n) := inferInstanceAs (Functor.Linear R (CochainComplex.singleFunctor C n ⋙ HomotopyCategory.quotient _ _)) /-- The isomorphism given by the very definition of `singleFunctors C`. -/ noncomputable def singleFunctorsPostcompQuotientIso : singleFunctors C ≅ (CochainComplex.singleFunctors C).postcomp (HomotopyCategory.quotient _ _) := Iso.refl _ /-- `HomotopyCategory.singleFunctor C n` is induced by `CochainComplex.singleFunctor C n`. -/ noncomputable def singleFunctorPostcompQuotientIso (n : ℤ) : singleFunctor C n ≅ CochainComplex.singleFunctor C n ⋙ quotient _ _ := (SingleFunctors.evaluation _ _ n).mapIso (singleFunctorsPostcompQuotientIso C) end HomotopyCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/Triangulated.lean
import Mathlib.Algebra.Homology.HomotopyCategory.Pretriangulated import Mathlib.CategoryTheory.Triangulated.Triangulated import Mathlib.CategoryTheory.ComposableArrows.Basic /-! The triangulated structure on the homotopy category of complexes In this file, we show that for any additive category `C`, the pretriangulated category `HomotopyCategory C (ComplexShape.up ℤ)` is triangulated. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits Pretriangulated ComposableArrows -- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737 universe v variable {C : Type*} [Category.{v} C] [Preadditive C] [HasBinaryBiproducts C] {X₁ X₂ X₃ : CochainComplex C ℤ} (f : X₁ ⟶ X₂) (g : X₂ ⟶ X₃) namespace CochainComplex open HomComplex mappingCone /-- Given two composable morphisms `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` in the category of cochain complexes, this is the canonical triangle `mappingCone f ⟶ mappingCone (f ≫ g) ⟶ mappingCone g ⟶ (mappingCone f)⟦1⟧`. -/ @[simps! mor₁ mor₂ mor₃ obj₁ obj₂ obj₃] noncomputable def mappingConeCompTriangle : Triangle (CochainComplex C ℤ) := Triangle.mk (map f (f ≫ g) (𝟙 X₁) g (by rw [id_comp])) (map (f ≫ g) g f (𝟙 X₃) (by rw [comp_id])) ((triangle g).mor₃ ≫ (inr f)⟦1⟧') /-- Given two composable morphisms `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` in the category of cochain complexes, this is the canonical triangle `mappingCone f ⟶ mappingCone (f ≫ g) ⟶ mappingCone g ⟶ (mappingCone f)⟦1⟧` in the homotopy category. It is a distinguished triangle, see `HomotopyCategory.mappingConeCompTriangleh_distinguished`. -/ noncomputable def mappingConeCompTriangleh : Triangle (HomotopyCategory C (ComplexShape.up ℤ)) := (HomotopyCategory.quotient _ _).mapTriangle.obj (mappingConeCompTriangle f g) @[reassoc] lemma mappingConeCompTriangle_mor₃_naturality {Y₁ Y₂ Y₃ : CochainComplex C ℤ} (f' : Y₁ ⟶ Y₂) (g' : Y₂ ⟶ Y₃) (φ : mk₂ f g ⟶ mk₂ f' g') : map g g' (φ.app 1) (φ.app 2) (naturality' φ 1 2) ≫ (mappingConeCompTriangle f' g').mor₃ = (mappingConeCompTriangle f g).mor₃ ≫ (map f f' (φ.app 0) (φ.app 1) (naturality' φ 0 1))⟦1⟧' := by ext n dsimp [map] -- the following list of lemmas was obtained by doing simp? [ext_from_iff _ (n + 1) _ rfl] simp only [Int.reduceNeg, Fin.isValue, assoc, inr_f_desc_f, HomologicalComplex.comp_f, ext_from_iff _ (n + 1) _ rfl, inl_v_desc_f_assoc, Cochain.zero_cochain_comp_v, Cochain.ofHom_v, inl_v_triangle_mor₃_f_assoc, triangle_obj₁, shiftFunctor_obj_X', shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, Preadditive.neg_comp, id_comp, Preadditive.comp_neg, inr_f_desc_f_assoc, inr_f_triangle_mor₃_f_assoc, zero_comp, comp_zero, and_self] namespace MappingConeCompHomotopyEquiv /-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this is the canonical morphism (which is an homotopy equivalence) from `mappingCone g` to the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)`. -/ noncomputable def hom : mappingCone g ⟶ mappingCone (mappingConeCompTriangle f g).mor₁ := lift _ (descCocycle g (Cochain.ofHom (inr f)) 0 (zero_add 1) (by simp)) (descCochain _ 0 (Cochain.ofHom (inr (f ≫ g))) (neg_add_cancel 1)) (by ext p _ rfl dsimp [mappingConeCompTriangle, map] simp [ext_from_iff _ _ _ rfl, inl_v_d_assoc _ (p+1) p (p+2) (by cutsat) (by cutsat)]) /-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this is the canonical morphism (which is an homotopy equivalence) from the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)` to `mappingCone g`. -/ noncomputable def inv : mappingCone (mappingConeCompTriangle f g).mor₁ ⟶ mappingCone g := desc _ ((snd f).comp (inl g) (zero_add (-1))) (desc _ ((Cochain.ofHom f).comp (inl g) (zero_add (-1))) (inr g) (by simp)) (by ext p rw [ext_from_iff _ (p + 1) _ rfl, ext_to_iff _ _ (p + 1) rfl] simp [map, δ_zero_cochain_comp, Cochain.comp_v _ _ (add_neg_cancel 1) p (p+1) p (by cutsat) (by cutsat)]) @[reassoc (attr := simp)] lemma hom_inv_id : hom f g ≫ inv f g = 𝟙 _ := by ext n simp [hom, inv, lift_desc_f _ _ _ _ _ _ _ n (n + 1) rfl, ext_from_iff _ (n + 1) _ rfl] /-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this is the `homotopyInvHomId` field of the homotopy equivalence `mappingConeCompHomotopyEquiv f g` between `mappingCone g` and the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)`. -/ noncomputable def homotopyInvHomId : Homotopy (inv f g ≫ hom f g) (𝟙 _) := (Cochain.equivHomotopy _ _).symm ⟨-((snd _).comp ((fst (f ≫ g)).1.comp ((inl f).comp (inl _) (by decide)) (show 1 + (-2) = -1 by decide)) (zero_add (-1))), by rw [δ_neg, δ_zero_cochain_comp _ _ _ (neg_add_cancel 1), Int.negOnePow_neg, Int.negOnePow_one, Units.neg_smul, one_smul, δ_comp _ _ (show 1 + (-2) = -1 by decide) 2 (-1) 0 (by decide) (by decide) (by decide), δ_comp _ _ (show (-1) + (-1) = -2 by decide) 0 0 (-1) (by decide) (by decide) (by decide), Int.negOnePow_neg, Int.negOnePow_neg, Int.negOnePow_even 2 ⟨1, by decide⟩, Int.negOnePow_one, Units.neg_smul, one_smul, one_smul, δ_inl, δ_inl, δ_snd, Cocycle.δ_eq_zero, Cochain.zero_comp, add_zero, Cochain.neg_comp, neg_neg] ext n rw [ext_from_iff _ (n + 1) n rfl, ext_from_iff _ (n + 1) n rfl, ext_from_iff _ (n + 2) (n + 1) (by cutsat)] dsimp [hom, inv] simp [ext_to_iff _ n (n + 1) rfl, map, Cochain.comp_v _ _ (add_neg_cancel 1) n (n + 1) n (by cutsat) (by cutsat), Cochain.comp_v _ _ (show 1 + -2 = -1 by decide) (n + 1) (n + 2) n (by cutsat) (by cutsat), Cochain.comp_v _ _ (show (-1) + -1 = -2 by decide) (n + 2) (n + 1) n (by cutsat) (by cutsat)]⟩ end MappingConeCompHomotopyEquiv /-- Given two composable morphisms `f` and `g` in the category of cochain complexes, this is the homotopy equivalence `mappingConeCompHomotopyEquiv f g` between `mappingCone g` and the mapping cone of the morphism `mappingCone f ⟶ mappingCone (f ≫ g)`. -/ noncomputable def mappingConeCompHomotopyEquiv : HomotopyEquiv (mappingCone g) (mappingCone (mappingConeCompTriangle f g).mor₁) where hom := MappingConeCompHomotopyEquiv.hom f g inv := MappingConeCompHomotopyEquiv.inv f g homotopyHomInvId := Homotopy.ofEq (by simp) homotopyInvHomId := MappingConeCompHomotopyEquiv.homotopyInvHomId f g @[reassoc (attr := simp)] lemma mappingConeCompHomotopyEquiv_hom_inv_id : (mappingConeCompHomotopyEquiv f g).hom ≫ (mappingConeCompHomotopyEquiv f g).inv = 𝟙 _ := by simp [mappingConeCompHomotopyEquiv] @[reassoc] lemma mappingConeCompHomotopyEquiv_comm₁ : inr (map f (f ≫ g) (𝟙 X₁) g (by rw [id_comp])) ≫ (mappingConeCompHomotopyEquiv f g).inv = (mappingConeCompTriangle f g).mor₂ := by simp [map, mappingConeCompHomotopyEquiv, MappingConeCompHomotopyEquiv.inv] @[reassoc] lemma mappingConeCompHomotopyEquiv_comm₂ : (mappingConeCompHomotopyEquiv f g).hom ≫ (triangle (mappingConeCompTriangle f g).mor₁).mor₃ = (mappingConeCompTriangle f g).mor₃ := by ext n simp [map, mappingConeCompHomotopyEquiv, MappingConeCompHomotopyEquiv.hom, lift_f _ _ _ _ _ (n + 1) rfl, ext_from_iff _ (n + 1) _ rfl] @[reassoc (attr := simp)] lemma mappingConeCompTriangleh_comm₁ : (mappingConeCompTriangleh f g).mor₂ ≫ (HomotopyCategory.quotient _ _).map (mappingConeCompHomotopyEquiv f g).hom = (HomotopyCategory.quotient _ _).map (mappingCone.inr _) := by rw [← cancel_mono (HomotopyCategory.isoOfHomotopyEquiv (mappingConeCompHomotopyEquiv f g)).inv, assoc] dsimp [mappingConeCompTriangleh] rw [← Functor.map_comp, ← Functor.map_comp, ← Functor.map_comp, mappingConeCompHomotopyEquiv_hom_inv_id, comp_id, mappingConeCompHomotopyEquiv_comm₁ f g, mappingConeCompTriangle_mor₂] end CochainComplex namespace HomotopyCategory open CochainComplex variable [HasZeroObject C] lemma mappingConeCompTriangleh_distinguished : (mappingConeCompTriangleh f g) ∈ distTriang (HomotopyCategory C (ComplexShape.up ℤ)) := by refine ⟨_, _, (mappingConeCompTriangle f g).mor₁, ⟨?_⟩⟩ refine Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (isoOfHomotopyEquiv (mappingConeCompHomotopyEquiv f g)) (by cat_disch) (by simp) ?_ dsimp [mappingConeCompTriangleh] rw [CategoryTheory.Functor.map_id, comp_id, ← Functor.map_comp_assoc] congr 2 exact (mappingConeCompHomotopyEquiv_comm₂ f g).symm noncomputable instance : IsTriangulated (HomotopyCategory C (ComplexShape.up ℤ)) := IsTriangulated.mk' (by rintro ⟨X₁ : CochainComplex C ℤ⟩ ⟨X₂ : CochainComplex C ℤ⟩ ⟨X₃ : CochainComplex C ℤ⟩ u₁₂' u₂₃' obtain ⟨u₁₂, rfl⟩ := (HomotopyCategory.quotient C (ComplexShape.up ℤ)).map_surjective u₁₂' obtain ⟨u₂₃, rfl⟩ := (HomotopyCategory.quotient C (ComplexShape.up ℤ)).map_surjective u₂₃' refine ⟨_, _, _, _, _, _, _, _, Iso.refl _, Iso.refl _, Iso.refl _, by simp, by simp, _, _, mappingCone_triangleh_distinguished u₁₂, _, _, mappingCone_triangleh_distinguished u₂₃, _, _, mappingCone_triangleh_distinguished (u₁₂ ≫ u₂₃), ⟨?_⟩⟩ let α := mappingCone.triangleMap u₁₂ (u₁₂ ≫ u₂₃) (𝟙 X₁) u₂₃ (by rw [id_comp]) let β := mappingCone.triangleMap (u₁₂ ≫ u₂₃) u₂₃ u₁₂ (𝟙 X₃) (by rw [comp_id]) refine Triangulated.Octahedron.mk ((HomotopyCategory.quotient _ _).map α.hom₃) ((HomotopyCategory.quotient _ _).map β.hom₃) ?_ ?_ ?_ ?_ ?_ · exact ((quotient _ _).mapTriangle.map α).comm₂ · exact ((quotient _ _).mapTriangle.map α).comm₃.symm.trans (by dsimp [α]; simp) · exact ((quotient _ _).mapTriangle.map β).comm₂.trans (by dsimp [β]; simp) · exact ((quotient _ _).mapTriangle.map β).comm₃ · refine isomorphic_distinguished _ (mappingConeCompTriangleh_distinguished u₁₂ u₂₃) _ ?_ exact Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (Iso.refl _) (by dsimp [α, mappingConeCompTriangleh]; simp) (by dsimp [β, mappingConeCompTriangleh]; simp) (by dsimp [mappingConeCompTriangleh]; simp)) end HomotopyCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/DegreewiseSplit.lean
import Mathlib.Algebra.Homology.HomotopyCategory.Pretriangulated /-! # Degreewise split exact sequences of cochain complexes The main result of this file is the lemma `HomotopyCategory.distinguished_iff_iso_trianglehOfDegreewiseSplit` which asserts that a triangle in `HomotopyCategory C (ComplexShape.up ℤ)` is distinguished iff it is isomorphic to the triangle attached to a degreewise split short exact sequence of cochain complexes. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits Pretriangulated Preadditive -- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737 universe v variable {C : Type*} [Category.{v} C] [Preadditive C] namespace CochainComplex open HomologicalComplex HomComplex variable (S : ShortComplex (CochainComplex C ℤ)) (σ : ∀ n, (S.map (eval C _ n)).Splitting) /-- The `1`-cocycle attached to a degreewise split short exact sequence of cochain complexes. -/ def cocycleOfDegreewiseSplit : Cocycle S.X₃ S.X₁ 1 := Cocycle.mk (Cochain.mk (fun p q _ => (σ p).s ≫ S.X₂.d p q ≫ (σ q).r)) 2 (by cutsat) (by ext p _ rfl have := mono_of_mono_fac (σ (p + 2)).f_r have r_f := fun n => (σ n).r_f have s_g := fun n => (σ n).s_g dsimp at this r_f s_g ⊢ rw [δ_v 1 2 (by cutsat) _ p (p + 2) (by cutsat) (p + 1) (p + 1) (by cutsat) (by cutsat), Cochain.mk_v, Cochain.mk_v, show Int.negOnePow 2 = 1 by rfl, one_smul, assoc, assoc, ← cancel_mono (S.f.f (p + 2)), add_comp, assoc, assoc, assoc, assoc, assoc, assoc, zero_comp, ← S.f.comm, reassoc_of% (r_f (p + 1)), sub_comp, comp_sub, comp_sub, assoc, id_comp, d_comp_d, comp_zero, zero_sub, ← S.g.comm_assoc, reassoc_of% (s_g p), r_f (p + 2), comp_sub, comp_sub, comp_id, comp_sub, ← S.g.comm_assoc, reassoc_of% (s_g (p + 1)), d_comp_d_assoc, zero_comp, sub_zero, neg_add_cancel]) /-- The canonical morphism `S.X₃ ⟶ S.X₁⟦(1 : ℤ)⟧` attached to a degreewise split short exact sequence of cochain complexes. -/ def homOfDegreewiseSplit : S.X₃ ⟶ S.X₁⟦(1 : ℤ)⟧ := ((Cocycle.equivHom _ _).symm ((cocycleOfDegreewiseSplit S σ).rightShift 1 0 (zero_add 1))) @[simp] lemma homOfDegreewiseSplit_f (n : ℤ) : (homOfDegreewiseSplit S σ).f n = (cocycleOfDegreewiseSplit S σ).1.v n (n + 1) rfl := by simp [homOfDegreewiseSplit, Cochain.rightShift_v _ _ _ _ _ _ _ _ rfl] /-- The triangle in `CochainComplex C ℤ` attached to a degreewise split short exact sequence of cochain complexes. -/ @[simps! obj₁ obj₂ obj₃ mor₁ mor₂ mor₃] def triangleOfDegreewiseSplit : Triangle (CochainComplex C ℤ) := Triangle.mk S.f S.g (homOfDegreewiseSplit S σ) /-- The (distinguished) triangle in `HomotopyCategory C (ComplexShape.up ℤ)` attached to a degreewise split short exact sequence of cochain complexes. -/ noncomputable abbrev trianglehOfDegreewiseSplit : Triangle (HomotopyCategory C (ComplexShape.up ℤ)) := (HomotopyCategory.quotient C (ComplexShape.up ℤ)).mapTriangle.obj (triangleOfDegreewiseSplit S σ) variable [HasBinaryBiproducts C] /-- The canonical isomorphism `(mappingCone (homOfDegreewiseSplit S σ)).X p ≅ S.X₂.X q` when `p + 1 = q`. -/ noncomputable def mappingConeHomOfDegreewiseSplitXIso (p q : ℤ) (hpq : p + 1 = q) : (mappingCone (homOfDegreewiseSplit S σ)).X p ≅ S.X₂.X q where hom := (mappingCone.fst (homOfDegreewiseSplit S σ)).1.v p q hpq ≫ (σ q).s - (mappingCone.snd (homOfDegreewiseSplit S σ)).v p p (add_zero p) ≫ by exact (Cochain.ofHom S.f).v (p + 1) q (by omega) inv := S.g.f q ≫ (mappingCone.inl (homOfDegreewiseSplit S σ)).v q p (by omega) - by exact (σ q).r ≫ (S.X₁.XIsoOfEq hpq.symm).hom ≫ (mappingCone.inr (homOfDegreewiseSplit S σ)).f p hom_inv_id := by subst hpq have s_g := (σ (p + 1)).s_g have f_r := (σ (p + 1)).f_r dsimp at s_g f_r ⊢ -- the following list of lemmas was obtained by doing -- simp? [mappingCone.ext_from_iff _ (p + 1) _ rfl, reassoc_of% f_r, reassoc_of% s_g] -- which may require increasing maximum heart beats simp only [Cochain.ofHom_v, Int.reduceNeg, id_comp, comp_sub, sub_comp, assoc, reassoc_of% s_g, ShortComplex.Splitting.s_r_assoc, ShortComplex.map_X₃, eval_obj, ShortComplex.map_X₁, zero_comp, comp_zero, reassoc_of% f_r, zero_sub, sub_neg_eq_add, mappingCone.ext_from_iff _ (p + 1) _ rfl, comp_add, mappingCone.inl_v_fst_v_assoc, mappingCone.inl_v_snd_v_assoc, shiftFunctor_obj_X', sub_zero, add_zero, comp_id, mappingCone.inr_f_fst_v_assoc, mappingCone.inr_f_snd_v_assoc, add_eq_right, neg_eq_zero, true_and] rw [← comp_f_assoc, S.zero, zero_f, zero_comp] inv_hom_id := by subst hpq have h := (σ (p + 1)).id dsimp at h ⊢ simp only [id_comp, Cochain.ofHom_v, comp_sub, sub_comp, assoc, mappingCone.inl_v_fst_v_assoc, mappingCone.inr_f_fst_v_assoc, shiftFunctor_obj_X', zero_comp, comp_zero, sub_zero, mappingCone.inl_v_snd_v_assoc, mappingCone.inr_f_snd_v_assoc, zero_sub, sub_neg_eq_add, ← h] abel /-- The canonical isomorphism `mappingCone (homOfDegreewiseSplit S σ) ≅ S.X₂⟦(1 : ℤ)⟧`. -/ @[simps!] noncomputable def mappingConeHomOfDegreewiseSplitIso : mappingCone (homOfDegreewiseSplit S σ) ≅ S.X₂⟦(1 : ℤ)⟧ := Hom.isoOfComponents (fun p => mappingConeHomOfDegreewiseSplitXIso S σ p _ rfl) (by rintro p _ rfl have r_f := (σ (p + 1 + 1)).r_f have s_g := (σ (p + 1)).s_g dsimp at r_f s_g ⊢ simp only [mappingConeHomOfDegreewiseSplitXIso, mappingCone.ext_from_iff _ _ _ rfl, mappingCone.inl_v_d_assoc _ (p + 1) _ (p + 1 + 1) (by linarith) (by cutsat), cocycleOfDegreewiseSplit, r_f, Int.reduceNeg, Cochain.ofHom_v, sub_comp, assoc, Hom.comm, comp_sub, mappingCone.inl_v_fst_v_assoc, mappingCone.inl_v_snd_v_assoc, shiftFunctor_obj_X', zero_comp, sub_zero, homOfDegreewiseSplit_f, mappingCone.inr_f_fst_v_assoc, comp_zero, zero_sub, mappingCone.inr_f_snd_v_assoc, neg_neg, mappingCone.inr_f_d_assoc, shiftFunctor_obj_d', Int.negOnePow_one, neg_comp, sub_neg_eq_add, zero_add, and_true, Units.neg_smul, one_smul, comp_neg, ShortComplex.map_X₂, eval_obj, Cocycle.mk_coe, Cochain.mk_v] simp only [← S.g.comm_assoc, reassoc_of% s_g, comp_id] abel) @[reassoc (attr := simp)] lemma shift_f_comp_mappingConeHomOfDegreewiseSplitIso_inv : S.f⟦(1 : ℤ)⟧' ≫ (mappingConeHomOfDegreewiseSplitIso S σ).inv = -mappingCone.inr _ := by ext n have h := (σ (n + 1)).f_r dsimp at h dsimp [mappingConeHomOfDegreewiseSplitXIso] rw [id_comp, comp_sub, ← comp_f_assoc, S.zero, zero_f, zero_comp, zero_sub, reassoc_of% h] @[reassoc (attr := simp)] lemma mappingConeHomOfDegreewiseSplitIso_inv_comp_triangle_mor₃ : (mappingConeHomOfDegreewiseSplitIso S σ).inv ≫ (mappingCone.triangle (homOfDegreewiseSplit S σ)).mor₃ = -S.g⟦(1 : ℤ)⟧' := by ext n dsimp [mappingConeHomOfDegreewiseSplitXIso] simp only [Int.reduceNeg, id_comp, sub_comp, assoc, mappingCone.inl_v_triangle_mor₃_f, shiftFunctor_obj_X, shiftFunctorObjXIso, XIsoOfEq_rfl, Iso.refl_inv, comp_neg, comp_id, mappingCone.inr_f_triangle_mor₃_f, comp_zero, sub_zero] /-- The canonical isomorphism of triangles `(triangleOfDegreewiseSplit S σ).rotate.rotate ≅ mappingCone.triangle (homOfDegreewiseSplit S σ)` when `S` is a degreewise split short exact sequence of cochain complexes. -/ noncomputable def triangleOfDegreewiseSplitRotateRotateIso : (triangleOfDegreewiseSplit S σ).rotate.rotate ≅ mappingCone.triangle (homOfDegreewiseSplit S σ) := Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (mappingConeHomOfDegreewiseSplitIso S σ).symm (by dsimp; simp only [comp_id, id_comp]) (by dsimp; simp only [neg_comp, shift_f_comp_mappingConeHomOfDegreewiseSplitIso_inv, neg_neg, id_comp]) (by dsimp; simp only [CategoryTheory.Functor.map_id, comp_id, mappingConeHomOfDegreewiseSplitIso_inv_comp_triangle_mor₃]) /-- The canonical isomorphism between `(trianglehOfDegreewiseSplit S σ).rotate.rotate` and `mappingCone.triangleh (homOfDegreewiseSplit S σ)` when `S` is a degreewise split short exact sequence of cochain complexes. -/ noncomputable def trianglehOfDegreewiseSplitRotateRotateIso : (trianglehOfDegreewiseSplit S σ).rotate.rotate ≅ mappingCone.triangleh (homOfDegreewiseSplit S σ) := (rotate _).mapIso ((HomotopyCategory.quotient _ _).mapTriangleRotateIso.app _) ≪≫ (HomotopyCategory.quotient _ _).mapTriangleRotateIso.app _ ≪≫ (HomotopyCategory.quotient _ _).mapTriangle.mapIso (triangleOfDegreewiseSplitRotateRotateIso S σ) namespace mappingCone variable {K L : CochainComplex C ℤ} (φ : K ⟶ L) /-- Given a morphism of cochain complexes `φ`, this is the short complex given by `(triangle φ).rotate`. -/ @[simps] noncomputable def triangleRotateShortComplex : ShortComplex (CochainComplex C ℤ) := ShortComplex.mk (triangle φ).rotate.mor₁ (triangle φ).rotate.mor₂ (by simp) /-- `triangleRotateShortComplex φ` is a degreewise split short exact sequence of cochain complexes. -/ @[simps] noncomputable def triangleRotateShortComplexSplitting (n : ℤ) : ((triangleRotateShortComplex φ).map (eval _ _ n)).Splitting where s := -(inl φ).v (n + 1) n (by omega) r := (snd φ).v n n (add_zero n) id := by simp [ext_from_iff φ _ _ rfl] @[simp] lemma cocycleOfDegreewiseSplit_triangleRotateShortComplexSplitting_v (p : ℤ) : (cocycleOfDegreewiseSplit _ (triangleRotateShortComplexSplitting φ)).1.v p _ rfl = -φ.f _ := by simp [cocycleOfDegreewiseSplit, d_snd_v φ p (p + 1) rfl] /-- The triangle `(triangle φ).rotate` is isomorphic to a triangle attached to a degreewise split short exact sequence of cochain complexes. -/ noncomputable def triangleRotateIsoTriangleOfDegreewiseSplit : (triangle φ).rotate ≅ triangleOfDegreewiseSplit _ (triangleRotateShortComplexSplitting φ) := Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (Iso.refl _) (by simp) (by simp) (by ext; simp) /-- The triangle `(triangleh φ).rotate` is isomorphic to a triangle attached to a degreewise split short exact sequence of cochain complexes. -/ noncomputable def trianglehRotateIsoTrianglehOfDegreewiseSplit : (triangleh φ).rotate ≅ trianglehOfDegreewiseSplit _ (triangleRotateShortComplexSplitting φ) := (HomotopyCategory.quotient _ _).mapTriangleRotateIso.app _ ≪≫ (HomotopyCategory.quotient _ _).mapTriangle.mapIso (triangleRotateIsoTriangleOfDegreewiseSplit φ) end mappingCone end CochainComplex namespace HomotopyCategory variable [HasZeroObject C] [HasBinaryBiproducts C] lemma distinguished_iff_iso_trianglehOfDegreewiseSplit (T : Triangle (HomotopyCategory C (ComplexShape.up ℤ))) : (T ∈ distTriang _) ↔ ∃ (S : ShortComplex (CochainComplex C ℤ)) (σ : ∀ n, (S.map (HomologicalComplex.eval C _ n)).Splitting), Nonempty (T ≅ CochainComplex.trianglehOfDegreewiseSplit S σ) := by constructor · intro hT obtain ⟨K, L, φ, ⟨e⟩⟩ := inv_rot_of_distTriang _ hT exact ⟨_, _, ⟨(triangleRotation _).counitIso.symm.app _ ≪≫ (rotate _).mapIso e ≪≫ CochainComplex.mappingCone.trianglehRotateIsoTrianglehOfDegreewiseSplit φ⟩⟩ · rintro ⟨S, σ, ⟨e⟩⟩ rw [rotate_distinguished_triangle, rotate_distinguished_triangle] refine isomorphic_distinguished _ ?_ _ ((rotate _ ⋙ rotate _).mapIso e ≪≫ CochainComplex.trianglehOfDegreewiseSplitRotateRotateIso S σ) exact ⟨_, _, _, ⟨Iso.refl _⟩⟩ end HomotopyCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/ShiftSequence.lean
import Mathlib.CategoryTheory.Shift.InducedShiftSequence import Mathlib.CategoryTheory.Shift.Localization import Mathlib.Algebra.Homology.HomotopyCategory.Shift import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex import Mathlib.Algebra.Homology.QuasiIso /-! # Compatibilities of the homology functor with the shift This file studies how homology of cochain complexes behaves with respect to the shift: there is a natural isomorphism `(K⟦n⟧).homology a ≅ K.homology a` when `n + a = a'`. This is summarized by instances `(homologyFunctor C (ComplexShape.up ℤ) 0).ShiftSequence ℤ` in the `CochainComplex` and `HomotopyCategory` namespaces. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category ComplexShape Limits variable (C : Type*) [Category C] [Preadditive C] namespace CochainComplex open HomologicalComplex attribute [local simp] XIsoOfEq_hom_naturality smul_smul /-- The natural isomorphism `(K⟦n⟧).sc' i j k ≅ K.sc' i' j' k'` when `n + i = i'`, `n + j = j'` and `n + k = k'`. -/ @[simps!] def shiftShortComplexFunctor' (n i j k i' j' k' : ℤ) (hi : n + i = i') (hj : n + j = j') (hk : n + k = k') : (CategoryTheory.shiftFunctor (CochainComplex C ℤ) n) ⋙ shortComplexFunctor' C _ i j k ≅ shortComplexFunctor' C _ i' j' k' := NatIso.ofComponents (fun K => ShortComplex.isoMk (n.negOnePow • ((shiftEval C n i i' hi).app K)) ((shiftEval C n j j' hj).app K) (n.negOnePow • ((shiftEval C n k k' hk).app K)) (by simp) (by simp)) (fun f ↦ by ext <;> simp) /-- The natural isomorphism `(K⟦n⟧).sc i ≅ K.sc i'` when `n + i = i'`. -/ @[simps!] noncomputable def shiftShortComplexFunctorIso (n i i' : ℤ) (hi : n + i = i') : shiftFunctor C n ⋙ shortComplexFunctor C _ i ≅ shortComplexFunctor C _ i' := shiftShortComplexFunctor' C n _ i _ _ i' _ (by simp only [prev]; cutsat) hi (by simp only [next]; cutsat) variable {C} lemma shiftShortComplexFunctorIso_zero_add_hom_app (a : ℤ) (K : CochainComplex C ℤ) : (shiftShortComplexFunctorIso C 0 a a (zero_add a)).hom.app K = (shortComplexFunctor C (ComplexShape.up ℤ) a).map ((shiftFunctorZero (CochainComplex C ℤ) ℤ).hom.app K) := by ext <;> simp [one_smul, shiftFunctorZero_hom_app_f] lemma shiftShortComplexFunctorIso_add'_hom_app (n m mn : ℤ) (hmn : m + n = mn) (a a' a'' : ℤ) (ha' : n + a = a') (ha'' : m + a' = a'') (K : CochainComplex C ℤ) : (shiftShortComplexFunctorIso C mn a a'' (by rw [← ha'', ← ha', ← add_assoc, hmn])).hom.app K = (shortComplexFunctor C (ComplexShape.up ℤ) a).map ((CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) m n mn hmn).hom.app K) ≫ (shiftShortComplexFunctorIso C n a a' ha').hom.app (K⟦m⟧) ≫ (shiftShortComplexFunctorIso C m a' a'' ha'' ).hom.app K := by ext <;> dsimp <;> simp only [← hmn, Int.negOnePow_add, shiftFunctorAdd'_hom_app_f', XIsoOfEq_shift, Linear.comp_units_smul, Linear.units_smul_comp, XIsoOfEq_hom_comp_XIsoOfEq_hom, smul_smul] variable [CategoryWithHomology C] namespace ShiftSequence variable (C) in /-- The natural isomorphism `(K⟦n⟧).homology a ≅ K.homology a'` when `n + a = a'`. -/ noncomputable def shiftIso (n a a' : ℤ) (ha' : n + a = a') : (CategoryTheory.shiftFunctor _ n) ⋙ homologyFunctor C (ComplexShape.up ℤ) a ≅ homologyFunctor C (ComplexShape.up ℤ) a' := Functor.isoWhiskerLeft _ (homologyFunctorIso C (ComplexShape.up ℤ) a) ≪≫ (Functor.associator _ _ _).symm ≪≫ Functor.isoWhiskerRight (shiftShortComplexFunctorIso C n a a' ha') (ShortComplex.homologyFunctor C) ≪≫ (homologyFunctorIso C (ComplexShape.up ℤ) a').symm lemma shiftIso_hom_app (n a a' : ℤ) (ha' : n + a = a') (K : CochainComplex C ℤ) : (shiftIso C n a a' ha').hom.app K = ShortComplex.homologyMap ((shiftShortComplexFunctorIso C n a a' ha').hom.app K) := by dsimp [shiftIso] rw [id_comp, id_comp] -- This `erw` is required to bridge the gap between -- `((shortComplexFunctor C (up ℤ) a').obj K).homology` -- (the target of the first morphism) -- and -- `homology K a'` -- (the source of the identity morphism). erw [comp_id] lemma shiftIso_inv_app (n a a' : ℤ) (ha' : n + a = a') (K : CochainComplex C ℤ) : (shiftIso C n a a' ha').inv.app K = ShortComplex.homologyMap ((shiftShortComplexFunctorIso C n a a' ha').inv.app K) := by dsimp [shiftIso] rw [id_comp, comp_id] -- This `erw` is required as above in `shiftIso_hom_app`. erw [comp_id] end ShiftSequence noncomputable instance : (homologyFunctor C (ComplexShape.up ℤ) 0).ShiftSequence ℤ where sequence n := homologyFunctor C (ComplexShape.up ℤ) n isoZero := Iso.refl _ shiftIso n a a' ha' := ShiftSequence.shiftIso C n a a' ha' shiftIso_zero a := by ext K dsimp [homologyMap] simp only [ShiftSequence.shiftIso_hom_app, comp_id, shiftShortComplexFunctorIso_zero_add_hom_app] shiftIso_add n m a a' a'' ha' ha'' := by ext K dsimp [homologyMap] simp only [ShiftSequence.shiftIso_hom_app, id_comp, ← ShortComplex.homologyMap_comp, shiftFunctorAdd'_eq_shiftFunctorAdd, shiftShortComplexFunctorIso_add'_hom_app n m _ rfl a a' a'' ha' ha'' K] lemma quasiIsoAt_shift_iff {K L : CochainComplex C ℤ} (φ : K ⟶ L) (n i j : ℤ) (h : n + i = j) : QuasiIsoAt (φ⟦n⟧') i ↔ QuasiIsoAt φ j := by simp only [quasiIsoAt_iff_isIso_homologyMap] exact (NatIso.isIso_map_iff ((homologyFunctor C (ComplexShape.up ℤ) 0).shiftIso n i j h) φ) lemma quasiIso_shift_iff {K L : CochainComplex C ℤ} (φ : K ⟶ L) (n : ℤ) : QuasiIso (φ⟦n⟧') ↔ QuasiIso φ := by simp only [quasiIso_iff, fun i ↦ quasiIsoAt_shift_iff φ n i _ rfl] constructor · intro h j obtain ⟨i, rfl⟩ : ∃ i, j = n + i := ⟨j - n, by cutsat⟩ exact h i · intro h i exact h (n + i) instance {K L : CochainComplex C ℤ} (φ : K ⟶ L) (n : ℤ) [QuasiIso φ] : QuasiIso (φ⟦n⟧') := by rw [quasiIso_shift_iff] infer_instance instance : (HomologicalComplex.quasiIso C (ComplexShape.up ℤ)).IsCompatibleWithShift ℤ where condition n := by ext; apply quasiIso_shift_iff variable (C) in lemma homologyFunctor_shift (n : ℤ) : (homologyFunctor C (ComplexShape.up ℤ) 0).shift n = homologyFunctor C (ComplexShape.up ℤ) n := rfl @[reassoc] lemma liftCycles_shift_homologyπ (K : CochainComplex C ℤ) {A : C} {n i : ℤ} (f : A ⟶ (K⟦n⟧).X i) (j : ℤ) (hj : (up ℤ).next i = j) (hf : f ≫ (K⟦n⟧).d i j = 0) (i' : ℤ) (hi' : n + i = i') (j' : ℤ) (hj' : (up ℤ).next i' = j') : (K⟦n⟧).liftCycles f j hj hf ≫ (K⟦n⟧).homologyπ i = K.liftCycles (f ≫ (K.shiftFunctorObjXIso n i i' (by cutsat)).hom) j' hj' (by simp only [next] at hj hj' obtain rfl : i' = i + n := by cutsat obtain rfl : j' = j + n := by cutsat dsimp at hf ⊢ simp only [Linear.comp_units_smul] at hf apply (one_smul (M := ℤˣ) _).symm.trans _ rw [← Int.units_mul_self n.negOnePow, mul_smul, comp_id, hf, smul_zero]) ≫ K.homologyπ i' ≫ ((HomologicalComplex.homologyFunctor C (up ℤ) 0).shiftIso n i i' hi').inv.app K := by simp only [liftCycles, homologyπ, shiftFunctorObjXIso, Functor.shiftIso, Functor.ShiftSequence.shiftIso, ShiftSequence.shiftIso_inv_app, ShortComplex.homologyπ_naturality, ShortComplex.liftCycles_comp_cyclesMap_assoc, shiftShortComplexFunctorIso_inv_app_τ₂, assoc, Iso.hom_inv_id, comp_id] rfl end CochainComplex namespace HomotopyCategory variable [CategoryWithHomology C] noncomputable instance : (homologyFunctor C (ComplexShape.up ℤ) 0).ShiftSequence ℤ := Functor.ShiftSequence.induced (homologyFunctorFactors C (ComplexShape.up ℤ) 0) ℤ (homologyFunctor C (ComplexShape.up ℤ)) (homologyFunctorFactors C (ComplexShape.up ℤ)) variable {C} lemma homologyShiftIso_hom_app (n a a' : ℤ) (ha' : n + a = a') (K : CochainComplex C ℤ) : ((homologyFunctor C (ComplexShape.up ℤ) 0).shiftIso n a a' ha').hom.app ((quotient _ _).obj K) = (homologyFunctor _ _ a).map (((quotient _ _).commShiftIso n).inv.app K) ≫ (homologyFunctorFactors _ _ a).hom.app (K⟦n⟧) ≫ ((HomologicalComplex.homologyFunctor _ _ 0).shiftIso n a a' ha').hom.app K ≫ (homologyFunctorFactors _ _ a').inv.app K := by apply Functor.ShiftSequence.induced_shiftIso_hom_app_obj @[reassoc] lemma homologyFunctor_shiftMap {K L : CochainComplex C ℤ} {n : ℤ} (f : K ⟶ L⟦n⟧) (a a' : ℤ) (h : n + a = a') : (homologyFunctor C (ComplexShape.up ℤ) 0).shiftMap ((quotient _ _).map f ≫ ((quotient _ _).commShiftIso n).hom.app _) a a' h = (homologyFunctorFactors _ _ a).hom.app K ≫ (HomologicalComplex.homologyFunctor C (ComplexShape.up ℤ) 0).shiftMap f a a' h ≫ (homologyFunctorFactors _ _ a').inv.app L := by apply Functor.ShiftSequence.induced_shiftMap end HomotopyCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/HomComplexShift.lean
import Mathlib.Algebra.Homology.HomotopyCategory.HomComplex import Mathlib.Algebra.Homology.HomotopyCategory.Shift import Mathlib.Algebra.Module.Equiv.Basic /-! Shifting cochains Let `C` be a preadditive category. Given two cochain complexes (indexed by `ℤ`), the type of cochains `HomComplex.Cochain K L n` of degree `n` was introduced in `Mathlib/Algebra/Homology/HomotopyCategory/HomComplex.lean`. In this file, we study how these cochains behave with respect to the shift on the complexes `K` and `L`. When `n`, `a`, `n'` are integers such that `h : n' + a = n`, we obtain `rightShiftAddEquiv K L n a n' h : Cochain K L n ≃+ Cochain K (L⟦a⟧) n'`. This definition does not involve signs, but the analogous definition of `leftShiftAddEquiv K L n a n' h' : Cochain K L n ≃+ Cochain (K⟦a⟧) L n'` when `h' : n + a = n'` does involve signs, as we follow the conventions appearing in the introduction of [Brian Conrad's book *Grothendieck duality and base change*][conrad2000]. ## References * [Brian Conrad, Grothendieck duality and base change][conrad2000] -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits Preadditive universe v u variable {C : Type u} [Category.{v} C] [Preadditive C] {R : Type*} [Ring R] [Linear R C] {K L M : CochainComplex C ℤ} {n : ℤ} namespace CochainComplex.HomComplex namespace Cochain variable (γ γ₁ γ₂ : Cochain K L n) /-- The map `Cochain K L n → Cochain K (L⟦a⟧) n'` when `n' + a = n`. -/ def rightShift (a n' : ℤ) (hn' : n' + a = n) : Cochain K (L⟦a⟧) n' := Cochain.mk (fun p q hpq => γ.v p (p + n) rfl ≫ (L.shiftFunctorObjXIso a q (p + n) (by cutsat)).inv) lemma rightShift_v (a n' : ℤ) (hn' : n' + a = n) (p q : ℤ) (hpq : p + n' = q) (p' : ℤ) (hp' : p + n = p') : (γ.rightShift a n' hn').v p q hpq = γ.v p p' hp' ≫ (L.shiftFunctorObjXIso a q p' (by rw [← hp', ← hpq, ← hn', add_assoc])).inv := by subst hp' dsimp only [rightShift] simp only [mk_v] /-- The map `Cochain K L n → Cochain (K⟦a⟧) L n'` when `n + a = n'`. -/ def leftShift (a n' : ℤ) (hn' : n + a = n') : Cochain (K⟦a⟧) L n' := Cochain.mk (fun p q hpq => (a * n' + ((a * (a-1))/2)).negOnePow • (K.shiftFunctorObjXIso a p (p + a) rfl).hom ≫ γ.v (p+a) q (by cutsat)) lemma leftShift_v (a n' : ℤ) (hn' : n + a = n') (p q : ℤ) (hpq : p + n' = q) (p' : ℤ) (hp' : p' + n = q) : (γ.leftShift a n' hn').v p q hpq = (a * n' + ((a * (a - 1)) / 2)).negOnePow • (K.shiftFunctorObjXIso a p p' (by rw [← add_left_inj n, hp', add_assoc, add_comm a, hn', hpq])).hom ≫ γ.v p' q hp' := by obtain rfl : p' = p + a := by cutsat dsimp only [leftShift] simp only [mk_v] /-- The map `Cochain K (L⟦a⟧) n' → Cochain K L n` when `n' + a = n`. -/ def rightUnshift {n' a : ℤ} (γ : Cochain K (L⟦a⟧) n') (n : ℤ) (hn : n' + a = n) : Cochain K L n := Cochain.mk (fun p q hpq => γ.v p (p + n') rfl ≫ (L.shiftFunctorObjXIso a (p + n') q (by rw [← hpq, add_assoc, hn])).hom) lemma rightUnshift_v {n' a : ℤ} (γ : Cochain K (L⟦a⟧) n') (n : ℤ) (hn : n' + a = n) (p q : ℤ) (hpq : p + n = q) (p' : ℤ) (hp' : p + n' = p') : (γ.rightUnshift n hn).v p q hpq = γ.v p p' hp' ≫ (L.shiftFunctorObjXIso a p' q (by rw [← hpq, ← hn, ← add_assoc, hp'])).hom := by subst hp' dsimp only [rightUnshift] simp only [mk_v] /-- The map `Cochain (K⟦a⟧) L n' → Cochain K L n` when `n + a = n'`. -/ def leftUnshift {n' a : ℤ} (γ : Cochain (K⟦a⟧) L n') (n : ℤ) (hn : n + a = n') : Cochain K L n := Cochain.mk (fun p q hpq => (a * n' + ((a * (a-1))/2)).negOnePow • (K.shiftFunctorObjXIso a (p - a) p (by cutsat)).inv ≫ γ.v (p-a) q (by cutsat)) lemma leftUnshift_v {n' a : ℤ} (γ : Cochain (K⟦a⟧) L n') (n : ℤ) (hn : n + a = n') (p q : ℤ) (hpq : p + n = q) (p' : ℤ) (hp' : p' + n' = q) : (γ.leftUnshift n hn).v p q hpq = (a * n' + ((a * (a-1))/2)).negOnePow • (K.shiftFunctorObjXIso a p' p (by cutsat)).inv ≫ γ.v p' q (by cutsat) := by obtain rfl : p' = p - a := by cutsat rfl /-- The map `Cochain K L n → Cochain (K⟦a⟧) (L⟦a⟧) n`. -/ def shift (a : ℤ) : Cochain (K⟦a⟧) (L⟦a⟧) n := Cochain.mk (fun p q hpq => (K.shiftFunctorObjXIso a p _ rfl).hom ≫ γ.v (p + a) (q + a) (by cutsat) ≫ (L.shiftFunctorObjXIso a q _ rfl).inv) lemma shift_v (a : ℤ) (p q : ℤ) (hpq : p + n = q) (p' q' : ℤ) (hp' : p' = p + a) (hq' : q' = q + a) : (γ.shift a).v p q hpq = (K.shiftFunctorObjXIso a p p' hp').hom ≫ γ.v p' q' (by rw [hp', hq', ← hpq, add_assoc, add_comm a, add_assoc]) ≫ (L.shiftFunctorObjXIso a q q' hq').inv := by subst hp' hq' rfl lemma shift_v' (a : ℤ) (p q : ℤ) (hpq : p + n = q) : (γ.shift a).v p q hpq = γ.v (p + a) (q + a) (by cutsat) := by simp only [shift_v γ a p q hpq _ _ rfl rfl, shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, Iso.refl_inv, comp_id, id_comp] @[simp] lemma rightUnshift_rightShift (a n' : ℤ) (hn' : n' + a = n) : (γ.rightShift a n' hn').rightUnshift n hn' = γ := by ext p q hpq simp only [rightUnshift_v _ n hn' p q hpq (p + n') rfl, γ.rightShift_v _ _ hn' p (p + n') rfl q hpq, shiftFunctorObjXIso, assoc, Iso.inv_hom_id, comp_id] @[simp] lemma rightShift_rightUnshift {a n' : ℤ} (γ : Cochain K (L⟦a⟧) n') (n : ℤ) (hn' : n' + a = n) : (γ.rightUnshift n hn').rightShift a n' hn' = γ := by ext p q hpq simp only [(γ.rightUnshift n hn').rightShift_v a n' hn' p q hpq (p + n) rfl, γ.rightUnshift_v n hn' p (p + n) rfl q hpq, shiftFunctorObjXIso, assoc, Iso.hom_inv_id, comp_id] @[simp] lemma leftUnshift_leftShift (a n' : ℤ) (hn' : n + a = n') : (γ.leftShift a n' hn').leftUnshift n hn' = γ := by ext p q hpq rw [(γ.leftShift a n' hn').leftUnshift_v n hn' p q hpq (q-n') (by cutsat), γ.leftShift_v a n' hn' (q-n') q (by cutsat) p hpq, Linear.comp_units_smul, Iso.inv_hom_id_assoc, smul_smul, Int.units_mul_self, one_smul] @[simp] lemma leftShift_leftUnshift {a n' : ℤ} (γ : Cochain (K⟦a⟧) L n') (n : ℤ) (hn' : n + a = n') : (γ.leftUnshift n hn').leftShift a n' hn' = γ := by ext p q hpq rw [(γ.leftUnshift n hn').leftShift_v a n' hn' p q hpq (q-n) (by cutsat), γ.leftUnshift_v n hn' (q-n) q (by cutsat) p hpq, Linear.comp_units_smul, smul_smul, Iso.hom_inv_id_assoc, Int.units_mul_self, one_smul] @[simp] lemma rightShift_add (a n' : ℤ) (hn' : n' + a = n) : (γ₁ + γ₂).rightShift a n' hn' = γ₁.rightShift a n' hn' + γ₂.rightShift a n' hn' := by ext p q hpq dsimp simp only [rightShift_v _ a n' hn' p q hpq _ rfl, add_v, add_comp] @[simp] lemma leftShift_add (a n' : ℤ) (hn' : n + a = n') : (γ₁ + γ₂).leftShift a n' hn' = γ₁.leftShift a n' hn' + γ₂.leftShift a n' hn' := by ext p q hpq dsimp simp only [leftShift_v _ a n' hn' p q hpq (p + a) (by cutsat), add_v, comp_add, smul_add] @[simp] lemma shift_add (a : ℤ) : (γ₁ + γ₂).shift a = γ₁.shift a + γ₂.shift a := by ext p q hpq dsimp simp only [shift_v', add_v] variable (K L) /-- The additive equivalence `Cochain K L n ≃+ Cochain K L⟦a⟧ n'` when `n' + a = n`. -/ @[simps] def rightShiftAddEquiv (n a n' : ℤ) (hn' : n' + a = n) : Cochain K L n ≃+ Cochain K (L⟦a⟧) n' where toFun γ := γ.rightShift a n' hn' invFun γ := γ.rightUnshift n hn' left_inv γ := by simp only [rightUnshift_rightShift] right_inv γ := by simp only [rightShift_rightUnshift] map_add' γ γ' := by simp only [rightShift_add] /-- The additive equivalence `Cochain K L n ≃+ Cochain (K⟦a⟧) L n'` when `n + a = n'`. -/ @[simps] def leftShiftAddEquiv (n a n' : ℤ) (hn' : n + a = n') : Cochain K L n ≃+ Cochain (K⟦a⟧) L n' where toFun γ := γ.leftShift a n' hn' invFun γ := γ.leftUnshift n hn' left_inv γ := by simp only [leftUnshift_leftShift] right_inv γ := by simp only [leftShift_leftUnshift] map_add' γ γ' := by simp only [leftShift_add] /-- The additive map `Cochain K L n →+ Cochain (K⟦a⟧) (L⟦a⟧) n`. -/ @[simps!] def shiftAddHom (n a : ℤ) : Cochain K L n →+ Cochain (K⟦a⟧) (L⟦a⟧) n := AddMonoidHom.mk' (fun γ => γ.shift a) (by intros; dsimp; simp only [shift_add]) variable (n) @[simp] lemma rightShift_zero (a n' : ℤ) (hn' : n' + a = n) : (0 : Cochain K L n).rightShift a n' hn' = 0 := by change rightShiftAddEquiv K L n a n' hn' 0 = 0 apply map_zero @[simp] lemma rightUnshift_zero (a n' : ℤ) (hn' : n' + a = n) : (0 : Cochain K (L⟦a⟧) n').rightUnshift n hn' = 0 := by change (rightShiftAddEquiv K L n a n' hn').symm 0 = 0 apply map_zero @[simp] lemma leftShift_zero (a n' : ℤ) (hn' : n + a = n') : (0 : Cochain K L n).leftShift a n' hn' = 0 := by change leftShiftAddEquiv K L n a n' hn' 0 = 0 apply map_zero @[simp] lemma leftUnshift_zero (a n' : ℤ) (hn' : n + a = n') : (0 : Cochain (K⟦a⟧) L n').leftUnshift n hn' = 0 := by change (leftShiftAddEquiv K L n a n' hn').symm 0 = 0 apply map_zero @[simp] lemma shift_zero (a : ℤ) : (0 : Cochain K L n).shift a = 0 := by change shiftAddHom K L n a 0 = 0 apply map_zero variable {K L n} @[simp] lemma rightShift_neg (a n' : ℤ) (hn' : n' + a = n) : (-γ).rightShift a n' hn' = -γ.rightShift a n' hn' := by change rightShiftAddEquiv K L n a n' hn' (-γ) = _ apply map_neg @[simp] lemma rightUnshift_neg {n' a : ℤ} (γ : Cochain K (L⟦a⟧) n') (n : ℤ) (hn : n' + a = n) : (-γ).rightUnshift n hn = -γ.rightUnshift n hn := by change (rightShiftAddEquiv K L n a n' hn).symm (-γ) = _ apply map_neg @[simp] lemma leftShift_neg (a n' : ℤ) (hn' : n + a = n') : (-γ).leftShift a n' hn' = -γ.leftShift a n' hn' := by change leftShiftAddEquiv K L n a n' hn' (-γ) = _ apply map_neg @[simp] lemma leftUnshift_neg {n' a : ℤ} (γ : Cochain (K⟦a⟧) L n') (n : ℤ) (hn : n + a = n') : (-γ).leftUnshift n hn = -γ.leftUnshift n hn := by change (leftShiftAddEquiv K L n a n' hn).symm (-γ) = _ apply map_neg @[simp] lemma shift_neg (a : ℤ) : (-γ).shift a = -γ.shift a := by change shiftAddHom K L n a (-γ) = _ apply map_neg @[simp] lemma rightUnshift_add {n' a : ℤ} (γ₁ γ₂ : Cochain K (L⟦a⟧) n') (n : ℤ) (hn : n' + a = n) : (γ₁ + γ₂).rightUnshift n hn = γ₁.rightUnshift n hn + γ₂.rightUnshift n hn := by change (rightShiftAddEquiv K L n a n' hn).symm (γ₁ + γ₂) = _ apply map_add @[simp] lemma leftUnshift_add {n' a : ℤ} (γ₁ γ₂ : Cochain (K⟦a⟧) L n') (n : ℤ) (hn : n + a = n') : (γ₁ + γ₂).leftUnshift n hn = γ₁.leftUnshift n hn + γ₂.leftUnshift n hn := by change (leftShiftAddEquiv K L n a n' hn).symm (γ₁ + γ₂) = _ apply map_add @[simp] lemma rightShift_smul (a n' : ℤ) (hn' : n' + a = n) (x : R) : (x • γ).rightShift a n' hn' = x • γ.rightShift a n' hn' := by ext p q hpq dsimp simp only [rightShift_v _ a n' hn' p q hpq _ rfl, smul_v, Linear.smul_comp] @[simp] lemma leftShift_smul (a n' : ℤ) (hn' : n + a = n') (x : R) : (x • γ).leftShift a n' hn' = x • γ.leftShift a n' hn' := by ext p q hpq dsimp simp only [leftShift_v _ a n' hn' p q hpq (p + a) (by cutsat), smul_v, Linear.comp_smul, smul_comm x] @[simp] lemma shift_smul (a : ℤ) (x : R) : (x • γ).shift a = x • (γ.shift a) := by ext p q hpq dsimp simp only [shift_v', smul_v] variable (K L R) /-- The linear equivalence `Cochain K L n ≃+ Cochain K L⟦a⟧ n'` when `n' + a = n` and the category is `R`-linear. -/ @[simps!] def rightShiftLinearEquiv (n a n' : ℤ) (hn' : n' + a = n) : Cochain K L n ≃ₗ[R] Cochain K (L⟦a⟧) n' := (rightShiftAddEquiv K L n a n' hn').toLinearEquiv (fun x γ => by dsimp; simp only [rightShift_smul]) /-- The additive equivalence `Cochain K L n ≃+ Cochain (K⟦a⟧) L n'` when `n + a = n'` and the category is `R`-linear. -/ @[simps!] def leftShiftLinearEquiv (n a n' : ℤ) (hn : n + a = n') : Cochain K L n ≃ₗ[R] Cochain (K⟦a⟧) L n' := (leftShiftAddEquiv K L n a n' hn).toLinearEquiv (fun x γ => by dsimp; simp only [leftShift_smul]) /-- The linear map `Cochain K L n ≃+ Cochain (K⟦a⟧) (L⟦a⟧) n` when the category is `R`-linear. -/ @[simps!] def shiftLinearMap (n a : ℤ) : Cochain K L n →ₗ[R] Cochain (K⟦a⟧) (L⟦a⟧) n where toAddHom := shiftAddHom K L n a map_smul' _ _ := by dsimp; simp only [shift_smul] variable {K L R} @[simp] lemma rightShift_units_smul (a n' : ℤ) (hn' : n' + a = n) (x : Rˣ) : (x • γ).rightShift a n' hn' = x • γ.rightShift a n' hn' := by apply rightShift_smul @[simp] lemma leftShift_units_smul (a n' : ℤ) (hn' : n + a = n') (x : Rˣ) : (x • γ).leftShift a n' hn' = x • γ.leftShift a n' hn' := by apply leftShift_smul @[simp] lemma shift_units_smul (a : ℤ) (x : Rˣ) : (x • γ).shift a = x • (γ.shift a) := by ext p q hpq dsimp simp only [shift_v', units_smul_v] @[simp] lemma rightUnshift_smul {n' a : ℤ} (γ : Cochain K (L⟦a⟧) n') (n : ℤ) (hn : n' + a = n) (x : R) : (x • γ).rightUnshift n hn = x • γ.rightUnshift n hn := by change (rightShiftLinearEquiv R K L n a n' hn).symm (x • γ) = _ apply map_smul @[simp] lemma rightUnshift_units_smul {n' a : ℤ} (γ : Cochain K (L⟦a⟧) n') (n : ℤ) (hn : n' + a = n) (x : Rˣ) : (x • γ).rightUnshift n hn = x • γ.rightUnshift n hn := by apply rightUnshift_smul @[simp] lemma leftUnshift_smul {n' a : ℤ} (γ : Cochain (K⟦a⟧) L n') (n : ℤ) (hn : n + a = n') (x : R) : (x • γ).leftUnshift n hn = x • γ.leftUnshift n hn := by change (leftShiftLinearEquiv R K L n a n' hn).symm (x • γ) = _ apply map_smul @[simp] lemma leftUnshift_units_smul {n' a : ℤ} (γ : Cochain (K⟦a⟧) L n') (n : ℤ) (hn : n + a = n') (x : Rˣ) : (x • γ).leftUnshift n hn = x • γ.leftUnshift n hn := by apply leftUnshift_smul lemma rightUnshift_comp {m : ℤ} {a : ℤ} (γ' : Cochain L (M⟦a⟧) m) {nm : ℤ} (hnm : n + m = nm) (nm' : ℤ) (hnm' : nm + a = nm') (m' : ℤ) (hm' : m + a = m') : (γ.comp γ' hnm).rightUnshift nm' hnm' = γ.comp (γ'.rightUnshift m' hm') (by cutsat) := by ext p q hpq rw [(γ.comp γ' hnm).rightUnshift_v nm' hnm' p q hpq (p + n + m) (by cutsat), γ.comp_v γ' hnm p (p + n) (p + n + m) rfl rfl, comp_v _ _ (show n + m' = nm' by cutsat) p (p + n) q (by cutsat) (by cutsat), γ'.rightUnshift_v m' hm' (p + n) q (by cutsat) (p + n + m) rfl, assoc] lemma leftShift_comp (a n' : ℤ) (hn' : n + a = n') {m t t' : ℤ} (γ' : Cochain L M m) (h : n + m = t) (ht' : t + a = t') : (γ.comp γ' h).leftShift a t' ht' = (a * m).negOnePow • (γ.leftShift a n' hn').comp γ' (by rw [← ht', ← h, ← hn', add_assoc, add_comm a, add_assoc]) := by ext p q hpq have h' : n' + m = t' := by omega dsimp simp only [Cochain.comp_v _ _ h' p (p + n') q rfl (by cutsat), γ.leftShift_v a n' hn' p (p + n') rfl (p + a) (by cutsat), (γ.comp γ' h).leftShift_v a t' (by cutsat) p q hpq (p + a) (by cutsat), smul_smul, Linear.units_smul_comp, assoc, Int.negOnePow_add, ← mul_assoc, ← h', comp_v _ _ h (p + a) (p + n') q (by cutsat) (by cutsat)] congr 2 rw [add_comm n', mul_add, Int.negOnePow_add] @[simp] lemma leftShift_comp_zero_cochain (a n' : ℤ) (hn' : n + a = n') (γ' : Cochain L M 0) : (γ.comp γ' (add_zero n)).leftShift a n' hn' = (γ.leftShift a n' hn').comp γ' (add_zero n') := by rw [leftShift_comp γ a n' hn' γ' (add_zero _) hn', mul_zero, Int.negOnePow_zero, one_smul] lemma δ_rightShift (a n' m' : ℤ) (hn' : n' + a = n) (m : ℤ) (hm' : m' + a = m) : δ n' m' (γ.rightShift a n' hn') = a.negOnePow • (δ n m γ).rightShift a m' hm' := by by_cases hnm : n + 1 = m · have hnm' : n' + 1 = m' := by omega ext p q hpq dsimp rw [(δ n m γ).rightShift_v a m' hm' p q hpq _ rfl, δ_v n m hnm _ p (p+m) rfl (p+n) (p+1) (by cutsat) rfl, δ_v n' m' hnm' _ p q hpq (p+n') (p+1) (by cutsat) rfl, γ.rightShift_v a n' hn' p (p+n') rfl (p+n) rfl, γ.rightShift_v a n' hn' (p+1) q _ (p+m) (by cutsat)] simp only [shiftFunctorObjXIso, shiftFunctor_obj_d', Linear.comp_units_smul, assoc, HomologicalComplex.XIsoOfEq_inv_comp_d, add_comp, HomologicalComplex.d_comp_XIsoOfEq_inv, Linear.units_smul_comp, smul_add, add_right_inj, smul_smul] simp only [← hm', add_comm m', Int.negOnePow_add, ← mul_assoc, Int.units_mul_self, one_mul] · have hnm' : ¬ n' + 1 = m' := fun _ => hnm (by cutsat) rw [δ_shape _ _ hnm', δ_shape _ _ hnm, rightShift_zero, smul_zero] lemma δ_rightUnshift {a n' : ℤ} (γ : Cochain K (L⟦a⟧) n') (n : ℤ) (hn : n' + a = n) (m m' : ℤ) (hm' : m' + a = m) : δ n m (γ.rightUnshift n hn) = a.negOnePow • (δ n' m' γ).rightUnshift m hm' := by obtain ⟨γ', rfl⟩ := (rightShiftAddEquiv K L n a n' hn).surjective γ dsimp simp only [rightUnshift_rightShift, γ'.δ_rightShift a n' m' hn m hm', rightUnshift_units_smul, smul_smul, Int.units_mul_self, one_smul] lemma δ_leftShift (a n' m' : ℤ) (hn' : n + a = n') (m : ℤ) (hm' : m + a = m') : δ n' m' (γ.leftShift a n' hn') = a.negOnePow • (δ n m γ).leftShift a m' hm' := by by_cases hnm : n + 1 = m · have hnm' : n' + 1 = m' := by omega ext p q hpq dsimp rw [(δ n m γ).leftShift_v a m' hm' p q hpq (p+a) (by cutsat), δ_v n m hnm _ (p+a) q (by cutsat) (p+n') (p+1+a) (by cutsat) (by cutsat), δ_v n' m' hnm' _ p q hpq (p+n') (p+1) (by cutsat) rfl, γ.leftShift_v a n' hn' p (p+n') rfl (p+a) (by cutsat), γ.leftShift_v a n' hn' (p+1) q (by cutsat) (p+1+a) (by cutsat)] simp only [shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, id_comp, Linear.units_smul_comp, shiftFunctor_obj_d', Linear.comp_units_smul, smul_add, smul_smul] congr 2 · rw [← hnm', add_comm n', mul_add, mul_one] simp only [Int.negOnePow_add, ← mul_assoc, Int.units_mul_self, one_mul] · simp only [← Int.negOnePow_add, ← hn', ← hm', ← hnm] congr 1 linarith · have hnm' : ¬ n' + 1 = m' := fun _ => hnm (by cutsat) rw [δ_shape _ _ hnm', δ_shape _ _ hnm, leftShift_zero, smul_zero] lemma δ_leftUnshift {a n' : ℤ} (γ : Cochain (K⟦a⟧) L n') (n : ℤ) (hn : n + a = n') (m m' : ℤ) (hm' : m + a = m') : δ n m (γ.leftUnshift n hn) = a.negOnePow • (δ n' m' γ).leftUnshift m hm' := by obtain ⟨γ', rfl⟩ := (leftShiftAddEquiv K L n a n' hn).surjective γ dsimp simp only [leftUnshift_leftShift, γ'.δ_leftShift a n' m' hn m hm', leftUnshift_units_smul, smul_smul, Int.units_mul_self, one_smul] @[simp] lemma δ_shift (a m : ℤ) : δ n m (γ.shift a) = a.negOnePow • (δ n m γ).shift a := by by_cases hnm : n + 1 = m · ext p q hpq dsimp simp only [shift_v', shiftFunctor_obj_d', δ_v n m hnm _ p q hpq (q - 1) (p + 1) rfl rfl, δ_v n m hnm _ (p + a) (q + a) (by cutsat) (q - 1 + a) (p + 1 + a) (by cutsat) (by cutsat), smul_add, Linear.units_smul_comp, Linear.comp_units_smul, add_right_inj] rw [smul_comm] · rw [δ_shape _ _ hnm, δ_shape _ _ hnm, shift_zero, smul_zero] lemma leftShift_rightShift (a n' : ℤ) (hn' : n' + a = n) : (γ.rightShift a n' hn').leftShift a n hn' = (a * n + (a * (a - 1)) / 2).negOnePow • γ.shift a := by ext p q hpq simp only [leftShift_v _ a n hn' p q hpq (p + a) (by cutsat), rightShift_v _ a n' hn' (p + a) q (by cutsat) (q + a) (by cutsat), units_smul_v, shift_v'] dsimp rw [id_comp, comp_id] lemma rightShift_leftShift (a n' : ℤ) (hn' : n + a = n') : (γ.leftShift a n' hn').rightShift a n hn' = (a * n' + (a * (a - 1)) / 2).negOnePow • γ.shift a := by ext p q hpq simp only [rightShift_v _ a n hn' p q hpq (q + a) (by cutsat), leftShift_v _ a n' hn' p (q + a) (by cutsat) (p + a) (by cutsat), units_smul_v, shift_v'] dsimp rw [id_comp, comp_id] /-- The left and right shift of cochains commute only up to a sign. -/ lemma leftShift_rightShift_eq_negOnePow_rightShift_leftShift (a n' n'' : ℤ) (hn' : n' + a = n) (hn'' : n + a = n'') : (γ.rightShift a n' hn').leftShift a n hn' = a.negOnePow • (γ.leftShift a n'' hn'').rightShift a n hn'' := by rw [leftShift_rightShift, rightShift_leftShift, smul_smul, ← hn'', add_comm n a, mul_add, Int.negOnePow_add, Int.negOnePow_add, Int.negOnePow_add, Int.negOnePow_mul_self, ← mul_assoc, ← mul_assoc, Int.units_mul_self, one_mul] end Cochain namespace Cocycle /-- The map `Cocycle K L n → Cocycle K (L⟦a⟧) n'` when `n' + a = n`. -/ @[simps!] def rightShift (γ : Cocycle K L n) (a n' : ℤ) (hn' : n' + a = n) : Cocycle K (L⟦a⟧) n' := Cocycle.mk (γ.1.rightShift a n' hn') _ rfl (by simp only [Cochain.δ_rightShift _ a n' (n' + 1) hn' (n + 1) (by cutsat), δ_eq_zero, Cochain.rightShift_zero, smul_zero]) /-- The map `Cocycle K (L⟦a⟧) n' → Cocycle K L n` when `n' + a = n`. -/ @[simps!] def rightUnshift {n' a : ℤ} (γ : Cocycle K (L⟦a⟧) n') (n : ℤ) (hn : n' + a = n) : Cocycle K L n := Cocycle.mk (γ.1.rightUnshift n hn) _ rfl (by rw [Cochain.δ_rightUnshift _ n hn (n + 1) (n + 1 - a) (by cutsat), δ_eq_zero, Cochain.rightUnshift_zero, smul_zero]) /-- The map `Cocycle K L n → Cocycle (K⟦a⟧) L n'` when `n + a = n'`. -/ @[simps!] def leftShift (γ : Cocycle K L n) (a n' : ℤ) (hn' : n + a = n') : Cocycle (K⟦a⟧) L n' := Cocycle.mk (γ.1.leftShift a n' hn') _ rfl (by simp only [Cochain.δ_leftShift _ a n' (n' + 1) hn' (n + 1) (by cutsat), δ_eq_zero, Cochain.leftShift_zero, smul_zero]) /-- The map `Cocycle (K⟦a⟧) L n' → Cocycle K L n` when `n + a = n'`. -/ @[simps!] def leftUnshift {n' a : ℤ} (γ : Cocycle (K⟦a⟧) L n') (n : ℤ) (hn : n + a = n') : Cocycle K L n := Cocycle.mk (γ.1.leftUnshift n hn) _ rfl (by rw [Cochain.δ_leftUnshift _ n hn (n + 1) (n + 1 + a) rfl, δ_eq_zero, Cochain.leftUnshift_zero, smul_zero]) /-- The map `Cocycle K L n → Cocycle (K⟦a⟧) (L⟦a⟧) n`. -/ @[simps!] def shift (γ : Cocycle K L n) (a : ℤ) : Cocycle (K⟦a⟧) (L⟦a⟧) n := Cocycle.mk (γ.1.shift a) _ rfl (by simp only [Cochain.δ_shift, δ_eq_zero, Cochain.shift_zero, smul_zero]) end Cocycle end CochainComplex.HomComplex
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/ShortExact.lean
import Mathlib.Algebra.Homology.HomotopyCategory.HomologicalFunctor import Mathlib.Algebra.Homology.HomotopyCategory.ShiftSequence import Mathlib.Algebra.Homology.HomologySequenceLemmas import Mathlib.Algebra.Homology.Refinements /-! # The mapping cone of a monomorphism, up to a quasi-isomophism If `S` is a short exact short complex of cochain complexes in an abelian category, we construct a quasi-isomorphism `descShortComplex S : mappingCone S.f ⟶ S.X₃`. We obtain this by comparing the homology sequence of `S` and the homology sequence of the homology functor on the homotopy category, applied to the distinguished triangle attached to the mapping cone of `S.f`. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category ComplexShape HomotopyCategory Limits HomologicalComplex.HomologySequence Pretriangulated Preadditive variable {C : Type*} [Category C] [Abelian C] namespace CochainComplex @[reassoc] lemma homologySequenceδ_quotient_mapTriangle_obj (T : Triangle (CochainComplex C ℤ)) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) : (homologyFunctor C (up ℤ) 0).homologySequenceδ ((quotient C (up ℤ)).mapTriangle.obj T) n₀ n₁ h = (homologyFunctorFactors C (up ℤ) n₀).hom.app _ ≫ (HomologicalComplex.homologyFunctor C (up ℤ) 0).shiftMap T.mor₃ n₀ n₁ (by cutsat) ≫ (homologyFunctorFactors C (up ℤ) n₁).inv.app _ := by apply homologyFunctor_shiftMap namespace mappingCone variable (S : ShortComplex (CochainComplex C ℤ)) (hS : S.ShortExact) /-- The canonical morphism `mappingCone S.f ⟶ S.X₃` when `S` is a short complex of cochain complexes. -/ noncomputable def descShortComplex : mappingCone S.f ⟶ S.X₃ := desc S.f 0 S.g (by simp) @[reassoc (attr := simp)] lemma inr_descShortComplex : inr S.f ≫ descShortComplex S = S.g := by simp [descShortComplex] @[reassoc (attr := simp)] lemma inr_f_descShortComplex_f (n : ℤ) : (inr S.f).f n ≫ (descShortComplex S).f n = S.g.f n := by simp [descShortComplex] @[reassoc (attr := simp)] lemma inl_v_descShortComplex_f (i j : ℤ) (h : i + (-1) = j) : (inl S.f).v i j h ≫ (descShortComplex S).f j = 0 := by simp [descShortComplex] variable {S} lemma homologySequenceδ_triangleh (n₀ : ℤ) (n₁ : ℤ) (h : n₀ + 1 = n₁) : (homologyFunctor C (up ℤ) 0).homologySequenceδ (triangleh S.f) n₀ n₁ h = (homologyFunctorFactors C (up ℤ) n₀).hom.app _ ≫ HomologicalComplex.homologyMap (descShortComplex S) n₀ ≫ hS.δ n₀ n₁ h ≫ (homologyFunctorFactors C (up ℤ) n₁).inv.app _ := by /- We proceed by diagram chase. We test the identity on cocycles `x' : A' ⟶ (mappingCone S.f).X n₀` -/ dsimp rw [← cancel_mono ((homologyFunctorFactors C (up ℤ) n₁).hom.app _), assoc, assoc, assoc, Iso.inv_hom_id_app, ← cancel_epi ((homologyFunctorFactors C (up ℤ) n₀).inv.app _), Iso.inv_hom_id_app_assoc] apply yoneda.map_injective ext ⟨A⟩ (x : A ⟶ _) obtain ⟨A', π, _, x', w, hx'⟩ := (mappingCone S.f).eq_liftCycles_homologyπ_up_to_refinements x n₁ (by simpa using h) erw [homologySequenceδ_quotient_mapTriangle_obj_assoc _ _ _ h] dsimp rw [comp_id, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app] erw [comp_id] rw [← cancel_epi π, reassoc_of% hx', reassoc_of% hx', HomologicalComplex.homologyπ_naturality_assoc, HomologicalComplex.liftCycles_comp_cyclesMap_assoc] /- We decompose the cocycle `x'` into two morphisms `a : A' ⟶ S.X₁.X n₁` and `b : A' ⟶ S.X₂.X n₀` satisfying certain relations. -/ obtain ⟨a, b, hab⟩ := decomp_to _ x' n₁ h rw [hab, ext_to_iff _ n₁ (n₁ + 1) rfl, add_comp, assoc, assoc, inr_f_d, add_comp, assoc, assoc, assoc, assoc, inr_f_fst_v, comp_zero, comp_zero, add_zero, zero_comp, d_fst_v _ _ _ _ h, comp_neg, inl_v_fst_v_assoc, comp_neg, neg_eq_zero, add_comp, assoc, assoc, assoc, assoc, inr_f_snd_v, comp_id, zero_comp, d_snd_v _ _ _ h, comp_add, inl_v_fst_v_assoc, inl_v_snd_v_assoc, zero_comp, add_zero] at w /- We simplify the RHS. -/ conv_rhs => simp only [hab, add_comp, assoc, inr_f_descShortComplex_f, inl_v_descShortComplex_f, comp_zero, zero_add] rw [hS.δ_eq n₀ n₁ (by simpa using h) (b ≫ S.g.f n₀) _ b rfl (-a) (by simp only [neg_comp, neg_eq_iff_add_eq_zero, w.2]) (n₁ + 1) (by simp)] /- We simplify the LHS. -/ dsimp [Functor.shiftMap, homologyFunctor_shift] rw [HomologicalComplex.homologyπ_naturality_assoc, HomologicalComplex.liftCycles_comp_cyclesMap_assoc, S.X₁.liftCycles_shift_homologyπ_assoc _ _ _ _ n₁ (by cutsat) (n₁ + 1) (by simp), Iso.inv_hom_id_app] dsimp [homologyFunctor_shift] simp only [hab, add_comp, assoc, inl_v_triangle_mor₃_f_assoc, shiftFunctorObjXIso, neg_comp, Iso.inv_hom_id, comp_neg, comp_id, inr_f_triangle_mor₃_f_assoc, zero_comp, comp_zero, add_zero] open ComposableArrows include hS in lemma quasiIso_descShortComplex : QuasiIso (descShortComplex S) where quasiIsoAt n := by rw [quasiIsoAt_iff_isIso_homologyMap] let φ : ((homologyFunctor C (up ℤ) 0).homologySequenceComposableArrows₅ (triangleh S.f) n _ rfl).δlast ⟶ (composableArrows₅ hS n _ rfl).δlast := homMk₄ ((homologyFunctorFactors C (up ℤ) _).hom.app _) ((homologyFunctorFactors C (up ℤ) _).hom.app _) ((homologyFunctorFactors C (up ℤ) _).hom.app _ ≫ HomologicalComplex.homologyMap (descShortComplex S) n) ((homologyFunctorFactors C (up ℤ) _).hom.app _) ((homologyFunctorFactors C (up ℤ) _).hom.app _) ((homologyFunctorFactors C (up ℤ) _).hom.naturality S.f) (by erw [(homologyFunctorFactors C (up ℤ) n).hom.naturality_assoc] -- Disable `Fin.reduceFinMk`, otherwise `Precomp.obj_succ` does not fire. (https://github.com/leanprover-community/mathlib4/issues/27382) dsimp [-Fin.reduceFinMk] rw [← HomologicalComplex.homologyMap_comp, inr_descShortComplex]) (by -- Disable `Fin.reduceFinMk`, otherwise `Precomp.obj_succ` does not fire. (https://github.com/leanprover-community/mathlib4/issues/27382) dsimp [-Fin.reduceFinMk] erw [homologySequenceδ_triangleh hS] simp only [Functor.comp_obj, HomologicalComplex.homologyFunctor_obj, assoc, Iso.inv_hom_id_app, comp_id]) ((homologyFunctorFactors C (up ℤ) _).hom.naturality S.f) have : IsIso ((homologyFunctorFactors C (up ℤ) n).hom.app (mappingCone S.f) ≫ HomologicalComplex.homologyMap (descShortComplex S) n) := by apply Abelian.isIso_of_epi_of_isIso_of_isIso_of_mono ((homologyFunctor C (up ℤ) 0).homologySequenceComposableArrows₅_exact _ (mappingCone_triangleh_distinguished S.f) n _ rfl).δlast (composableArrows₅_exact hS n _ rfl).δlast φ all_goals dsimp [φ]; infer_instance apply IsIso.of_isIso_comp_left ((homologyFunctorFactors C (up ℤ) n).hom.app (mappingCone S.f)) end mappingCone end CochainComplex
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/HomComplex.lean
import Mathlib.Algebra.Category.Grp.Preadditive import Mathlib.Algebra.Homology.Homotopy import Mathlib.Algebra.Module.Pi import Mathlib.Algebra.Ring.NegOnePow import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.Tactic.Linarith /-! The cochain complex of homomorphisms between cochain complexes If `F` and `G` are cochain complexes (indexed by `ℤ`) in a preadditive category, there is a cochain complex of abelian groups whose `0`-cocycles identify to morphisms `F ⟶ G`. Informally, in degree `n`, this complex shall consist of cochains of degree `n` from `F` to `G`, i.e. arbitrary families for morphisms `F.X p ⟶ G.X (p + n)`. This complex shall be denoted `HomComplex F G`. In order to avoid type-theoretic issues, a cochain of degree `n : ℤ` (i.e. a term of type of `Cochain F G n`) shall be defined here as the data of a morphism `F.X p ⟶ G.X q` for all triplets `⟨p, q, hpq⟩` where `p` and `q` are integers and `hpq : p + n = q`. If `α : Cochain F G n`, we shall define `α.v p q hpq : F.X p ⟶ G.X q`. We follow the signs conventions appearing in the introduction of [Brian Conrad's book *Grothendieck duality and base change*][conrad2000]. ## References * [Brian Conrad, Grothendieck duality and base change][conrad2000] -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits Preadditive universe v u variable {C : Type u} [Category.{v} C] [Preadditive C] {R : Type*} [Ring R] [Linear R C] namespace CochainComplex variable {F G K L : CochainComplex C ℤ} (n m : ℤ) namespace HomComplex /-- A term of type `HomComplex.Triplet n` consists of two integers `p` and `q` such that `p + n = q`. (This type is introduced so that the instance `AddCommGroup (Cochain F G n)` defined below can be found automatically.) -/ structure Triplet (n : ℤ) where /-- a first integer -/ p : ℤ /-- a second integer -/ q : ℤ /-- the condition on the two integers -/ hpq : p + n = q variable (F G) /-- A cochain of degree `n : ℤ` between to cochain complexes `F` and `G` consists of a family of morphisms `F.X p ⟶ G.X q` whenever `p + n = q`, i.e. for all triplets in `HomComplex.Triplet n`. -/ def Cochain := ∀ (T : Triplet n), F.X T.p ⟶ G.X T.q instance : AddCommGroup (Cochain F G n) := by dsimp only [Cochain] infer_instance instance : Module R (Cochain F G n) := by dsimp only [Cochain] infer_instance namespace Cochain variable {F G n} /-- A practical constructor for cochains. -/ def mk (v : ∀ (p q : ℤ) (_ : p + n = q), F.X p ⟶ G.X q) : Cochain F G n := fun ⟨p, q, hpq⟩ => v p q hpq /-- The value of a cochain on a triplet `⟨p, q, hpq⟩`. -/ def v (γ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : F.X p ⟶ G.X q := γ ⟨p, q, hpq⟩ @[simp] lemma mk_v (v : ∀ (p q : ℤ) (_ : p + n = q), F.X p ⟶ G.X q) (p q : ℤ) (hpq : p + n = q) : (Cochain.mk v).v p q hpq = v p q hpq := rfl lemma congr_v {z₁ z₂ : Cochain F G n} (h : z₁ = z₂) (p q : ℤ) (hpq : p + n = q) : z₁.v p q hpq = z₂.v p q hpq := by subst h; rfl @[ext] lemma ext (z₁ z₂ : Cochain F G n) (h : ∀ (p q hpq), z₁.v p q hpq = z₂.v p q hpq) : z₁ = z₂ := by funext ⟨p, q, hpq⟩ apply h @[ext 1100] lemma ext₀ (z₁ z₂ : Cochain F G 0) (h : ∀ (p : ℤ), z₁.v p p (add_zero p) = z₂.v p p (add_zero p)) : z₁ = z₂ := by ext grind @[simp] lemma zero_v {n : ℤ} (p q : ℤ) (hpq : p + n = q) : (0 : Cochain F G n).v p q hpq = 0 := rfl @[simp] lemma add_v {n : ℤ} (z₁ z₂ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (z₁ + z₂).v p q hpq = z₁.v p q hpq + z₂.v p q hpq := rfl @[simp] lemma sub_v {n : ℤ} (z₁ z₂ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (z₁ - z₂).v p q hpq = z₁.v p q hpq - z₂.v p q hpq := rfl @[simp] lemma neg_v {n : ℤ} (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (-z).v p q hpq = -(z.v p q hpq) := rfl @[simp] lemma smul_v {n : ℤ} (k : R) (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (k • z).v p q hpq = k • (z.v p q hpq) := rfl @[simp] lemma units_smul_v {n : ℤ} (k : Rˣ) (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) : (k • z).v p q hpq = k • (z.v p q hpq) := rfl /-- A cochain of degree `0` from `F` to `G` can be constructed from a family of morphisms `F.X p ⟶ G.X p` for all `p : ℤ`. -/ def ofHoms (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) : Cochain F G 0 := Cochain.mk (fun p q hpq => ψ p ≫ eqToHom (by rw [← hpq, add_zero])) @[simp] lemma ofHoms_v (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p : ℤ) : (ofHoms ψ).v p p (add_zero p) = ψ p := by simp only [ofHoms, mk_v, eqToHom_refl, comp_id] @[simp] lemma ofHoms_zero : ofHoms (fun p => (0 : F.X p ⟶ G.X p)) = 0 := by cat_disch @[simp] lemma ofHoms_v_comp_d (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p q q' : ℤ) (hpq : p + 0 = q) : (ofHoms ψ).v p q hpq ≫ G.d q q' = ψ p ≫ G.d p q' := by rw [add_zero] at hpq subst hpq rw [ofHoms_v] @[simp] lemma d_comp_ofHoms_v (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p' p q : ℤ) (hpq : p + 0 = q) : F.d p' p ≫ (ofHoms ψ).v p q hpq = F.d p' q ≫ ψ q := by rw [add_zero] at hpq subst hpq rw [ofHoms_v] /-- The `0`-cochain attached to a morphism of cochain complexes. -/ def ofHom (φ : F ⟶ G) : Cochain F G 0 := ofHoms (fun p => φ.f p) variable (F G) @[simp] lemma ofHom_zero : ofHom (0 : F ⟶ G) = 0 := by simp only [ofHom, HomologicalComplex.zero_f_apply, ofHoms_zero] variable {F G} @[simp] lemma ofHom_v (φ : F ⟶ G) (p : ℤ) : (ofHom φ).v p p (add_zero p) = φ.f p := by simp only [ofHom, ofHoms_v] @[simp] lemma ofHom_v_comp_d (φ : F ⟶ G) (p q q' : ℤ) (hpq : p + 0 = q) : (ofHom φ).v p q hpq ≫ G.d q q' = φ.f p ≫ G.d p q' := by simp only [ofHom, ofHoms_v_comp_d] @[simp] lemma d_comp_ofHom_v (φ : F ⟶ G) (p' p q : ℤ) (hpq : p + 0 = q) : F.d p' p ≫ (ofHom φ).v p q hpq = F.d p' q ≫ φ.f q := by simp only [ofHom, d_comp_ofHoms_v] @[simp] lemma ofHom_add (φ₁ φ₂ : F ⟶ G) : Cochain.ofHom (φ₁ + φ₂) = Cochain.ofHom φ₁ + Cochain.ofHom φ₂ := by cat_disch @[simp] lemma ofHom_sub (φ₁ φ₂ : F ⟶ G) : Cochain.ofHom (φ₁ - φ₂) = Cochain.ofHom φ₁ - Cochain.ofHom φ₂ := by cat_disch @[simp] lemma ofHom_neg (φ : F ⟶ G) : Cochain.ofHom (-φ) = -Cochain.ofHom φ := by cat_disch /-- The cochain of degree `-1` given by an homotopy between two morphism of complexes. -/ def ofHomotopy {φ₁ φ₂ : F ⟶ G} (ho : Homotopy φ₁ φ₂) : Cochain F G (-1) := Cochain.mk (fun p q _ => ho.hom p q) @[simp] lemma ofHomotopy_ofEq {φ₁ φ₂ : F ⟶ G} (h : φ₁ = φ₂) : ofHomotopy (Homotopy.ofEq h) = 0 := rfl @[simp] lemma ofHomotopy_refl (φ : F ⟶ G) : ofHomotopy (Homotopy.refl φ) = 0 := rfl @[reassoc] lemma v_comp_XIsoOfEq_hom (γ : Cochain F G n) (p q q' : ℤ) (hpq : p + n = q) (hq' : q = q') : γ.v p q hpq ≫ (HomologicalComplex.XIsoOfEq G hq').hom = γ.v p q' (by rw [← hq', hpq]) := by subst hq' simp only [HomologicalComplex.XIsoOfEq, eqToIso_refl, Iso.refl_hom, comp_id] @[reassoc] lemma v_comp_XIsoOfEq_inv (γ : Cochain F G n) (p q q' : ℤ) (hpq : p + n = q) (hq' : q' = q) : γ.v p q hpq ≫ (HomologicalComplex.XIsoOfEq G hq').inv = γ.v p q' (by rw [hq', hpq]) := by subst hq' simp only [HomologicalComplex.XIsoOfEq, eqToIso_refl, Iso.refl_inv, comp_id] /-- The composition of cochains. -/ def comp {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : Cochain F K n₁₂ := Cochain.mk (fun p q hpq => z₁.v p (p + n₁) rfl ≫ z₂.v (p + n₁) q (by cutsat)) /-! If `z₁` is a cochain of degree `n₁` and `z₂` is a cochain of degree `n₂`, and that we have a relation `h : n₁ + n₂ = n₁₂`, then `z₁.comp z₂ h` is a cochain of degree `n₁₂`. The following lemma `comp_v` computes the value of this composition `z₁.comp z₂ h` on a triplet `⟨p₁, p₃, _⟩` (with `p₁ + n₁₂ = p₃`). In order to use this lemma, we need to provide an intermediate integer `p₂` such that `p₁ + n₁ = p₂`. It is advisable to use a `p₂` that has good definitional properties (i.e. `p₁ + n₁` is not always the best choice.) When `z₁` or `z₂` is a `0`-cochain, there is a better choice of `p₂`, and this leads to the two simplification lemmas `comp_zero_cochain_v` and `zero_cochain_comp_v`. -/ lemma comp_v {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) (p₁ p₂ p₃ : ℤ) (h₁ : p₁ + n₁ = p₂) (h₂ : p₂ + n₂ = p₃) : (z₁.comp z₂ h).v p₁ p₃ (by rw [← h₂, ← h₁, ← h, add_assoc]) = z₁.v p₁ p₂ h₁ ≫ z₂.v p₂ p₃ h₂ := by subst h₁; rfl @[simp] lemma comp_zero_cochain_v (z₁ : Cochain F G n) (z₂ : Cochain G K 0) (p q : ℤ) (hpq : p + n = q) : (z₁.comp z₂ (add_zero n)).v p q hpq = z₁.v p q hpq ≫ z₂.v q q (add_zero q) := comp_v z₁ z₂ (add_zero n) p q q hpq (add_zero q) @[simp] lemma zero_cochain_comp_v (z₁ : Cochain F G 0) (z₂ : Cochain G K n) (p q : ℤ) (hpq : p + n = q) : (z₁.comp z₂ (zero_add n)).v p q hpq = z₁.v p p (add_zero p) ≫ z₂.v p q hpq := comp_v z₁ z₂ (zero_add n) p p q (add_zero p) hpq /-- The associativity of the composition of cochains. -/ lemma comp_assoc {n₁ n₂ n₃ n₁₂ n₂₃ n₁₂₃ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (z₃ : Cochain K L n₃) (h₁₂ : n₁ + n₂ = n₁₂) (h₂₃ : n₂ + n₃ = n₂₃) (h₁₂₃ : n₁ + n₂ + n₃ = n₁₂₃) : (z₁.comp z₂ h₁₂).comp z₃ (show n₁₂ + n₃ = n₁₂₃ by rw [← h₁₂, h₁₂₃]) = z₁.comp (z₂.comp z₃ h₂₃) (by rw [← h₂₃, ← h₁₂₃, add_assoc]) := by substs h₁₂ h₂₃ h₁₂₃ ext p q hpq rw [comp_v _ _ rfl p (p + n₁ + n₂) q (add_assoc _ _ _).symm (by cutsat), comp_v z₁ z₂ rfl p (p + n₁) (p + n₁ + n₂) (by cutsat) (by cutsat), comp_v z₁ (z₂.comp z₃ rfl) (add_assoc n₁ n₂ n₃).symm p (p + n₁) q (by cutsat) (by cutsat), comp_v z₂ z₃ rfl (p + n₁) (p + n₁ + n₂) q (by cutsat) (by cutsat), assoc] /-! The formulation of the associativity of the composition of cochains given by the lemma `comp_assoc` often requires a careful selection of degrees with good definitional properties. In a few cases, like when one of the three cochains is a `0`-cochain, there are better choices, which provides the following simplification lemmas. -/ @[simp] lemma comp_assoc_of_first_is_zero_cochain {n₂ n₃ n₂₃ : ℤ} (z₁ : Cochain F G 0) (z₂ : Cochain G K n₂) (z₃ : Cochain K L n₃) (h₂₃ : n₂ + n₃ = n₂₃) : (z₁.comp z₂ (zero_add n₂)).comp z₃ h₂₃ = z₁.comp (z₂.comp z₃ h₂₃) (zero_add n₂₃) := comp_assoc _ _ _ _ _ (by cutsat) @[simp] lemma comp_assoc_of_second_is_zero_cochain {n₁ n₃ n₁₃ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K 0) (z₃ : Cochain K L n₃) (h₁₃ : n₁ + n₃ = n₁₃) : (z₁.comp z₂ (add_zero n₁)).comp z₃ h₁₃ = z₁.comp (z₂.comp z₃ (zero_add n₃)) h₁₃ := comp_assoc _ _ _ _ _ (by cutsat) @[simp] lemma comp_assoc_of_third_is_zero_cochain {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (z₃ : Cochain K L 0) (h₁₂ : n₁ + n₂ = n₁₂) : (z₁.comp z₂ h₁₂).comp z₃ (add_zero n₁₂) = z₁.comp (z₂.comp z₃ (add_zero n₂)) h₁₂ := comp_assoc _ _ _ _ _ (by cutsat) @[simp] lemma comp_assoc_of_second_degree_eq_neg_third_degree {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K (-n₂)) (z₃ : Cochain K L n₂) (h₁₂ : n₁ + (-n₂) = n₁₂) : (z₁.comp z₂ h₁₂).comp z₃ (show n₁₂ + n₂ = n₁ by rw [← h₁₂, add_assoc, neg_add_cancel, add_zero]) = z₁.comp (z₂.comp z₃ (neg_add_cancel n₂)) (add_zero n₁) := comp_assoc _ _ _ _ _ (by cutsat) @[simp] protected lemma zero_comp {n₁ n₂ n₁₂ : ℤ} (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : (0 : Cochain F G n₁).comp z₂ h = 0 := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), zero_v, zero_comp] @[simp] protected lemma add_comp {n₁ n₂ n₁₂ : ℤ} (z₁ z₁' : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : (z₁ + z₁').comp z₂ h = z₁.comp z₂ h + z₁'.comp z₂ h := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), add_v, add_comp] @[simp] protected lemma sub_comp {n₁ n₂ n₁₂ : ℤ} (z₁ z₁' : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : (z₁ - z₁').comp z₂ h = z₁.comp z₂ h - z₁'.comp z₂ h := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), sub_v, sub_comp] @[simp] protected lemma neg_comp {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : (-z₁).comp z₂ h = -z₁.comp z₂ h := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), neg_v, neg_comp] @[simp] protected lemma smul_comp {n₁ n₂ n₁₂ : ℤ} (k : R) (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : (k • z₁).comp z₂ h = k • (z₁.comp z₂ h) := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), smul_v, Linear.smul_comp] @[simp] lemma units_smul_comp {n₁ n₂ n₁₂ : ℤ} (k : Rˣ) (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : (k • z₁).comp z₂ h = k • (z₁.comp z₂ h) := by apply Cochain.smul_comp @[simp] protected lemma id_comp {n : ℤ} (z₂ : Cochain F G n) : (Cochain.ofHom (𝟙 F)).comp z₂ (zero_add n) = z₂ := by ext p q hpq simp only [zero_cochain_comp_v, ofHom_v, HomologicalComplex.id_f, id_comp] @[simp] protected lemma comp_zero {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (h : n₁ + n₂ = n₁₂) : z₁.comp (0 : Cochain G K n₂) h = 0 := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), zero_v, comp_zero] @[simp] protected lemma comp_add {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ z₂' : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : z₁.comp (z₂ + z₂') h = z₁.comp z₂ h + z₁.comp z₂' h := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), add_v, comp_add] @[simp] protected lemma comp_sub {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ z₂' : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : z₁.comp (z₂ - z₂') h = z₁.comp z₂ h - z₁.comp z₂' h := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), sub_v, comp_sub] @[simp] protected lemma comp_neg {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : z₁.comp (-z₂) h = -z₁.comp z₂ h := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), neg_v, comp_neg] @[simp] protected lemma comp_smul {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (k : R) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : z₁.comp (k • z₂) h = k • (z₁.comp z₂ h) := by ext p q hpq simp only [comp_v _ _ h p _ q rfl (by cutsat), smul_v, Linear.comp_smul] @[simp] lemma comp_units_smul {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (k : Rˣ) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) : z₁.comp (k • z₂) h = k • (z₁.comp z₂ h) := by apply Cochain.comp_smul @[simp] protected lemma comp_id {n : ℤ} (z₁ : Cochain F G n) : z₁.comp (Cochain.ofHom (𝟙 G)) (add_zero n) = z₁ := by ext p q hpq simp only [comp_zero_cochain_v, ofHom_v, HomologicalComplex.id_f, comp_id] @[simp] lemma ofHoms_comp (φ : ∀ (p : ℤ), F.X p ⟶ G.X p) (ψ : ∀ (p : ℤ), G.X p ⟶ K.X p) : (ofHoms φ).comp (ofHoms ψ) (zero_add 0) = ofHoms (fun p => φ p ≫ ψ p) := by cat_disch @[simp] lemma ofHom_comp (f : F ⟶ G) (g : G ⟶ K) : ofHom (f ≫ g) = (ofHom f).comp (ofHom g) (zero_add 0) := by simp only [ofHom, HomologicalComplex.comp_f, ofHoms_comp] variable (K) /-- The differential on a cochain complex, as a cochain of degree `1`. -/ def diff : Cochain K K 1 := Cochain.mk (fun p q _ => K.d p q) @[simp] lemma diff_v (p q : ℤ) (hpq : p + 1 = q) : (diff K).v p q hpq = K.d p q := rfl end Cochain variable {F G} /-- The differential on the complex of morphisms between cochain complexes. -/ def δ (z : Cochain F G n) : Cochain F G m := Cochain.mk (fun p q hpq => z.v p (p + n) rfl ≫ G.d (p + n) q + m.negOnePow • F.d p (p + m - n) ≫ z.v (p + m - n) q (by rw [hpq, sub_add_cancel])) /-! Similarly as for the composition of cochains, if `z : Cochain F G n`, we usually need to carefully select intermediate indices with good definitional properties in order to obtain a suitable expansion of the morphisms which constitute `δ n m z : Cochain F G m` (when `n + 1 = m`, otherwise it shall be zero). The basic equational lemma is `δ_v` below. -/ lemma δ_v (hnm : n + 1 = m) (z : Cochain F G n) (p q : ℤ) (hpq : p + m = q) (q₁ q₂ : ℤ) (hq₁ : q₁ = q - 1) (hq₂ : p + 1 = q₂) : (δ n m z).v p q hpq = z.v p q₁ (by rw [hq₁, ← hpq, ← hnm, ← add_assoc, add_sub_cancel_right]) ≫ G.d q₁ q + m.negOnePow • F.d p q₂ ≫ z.v q₂ q (by rw [← hq₂, add_assoc, add_comm 1, hnm, hpq]) := by obtain rfl : q₁ = p + n := by cutsat obtain rfl : q₂ = p + m - n := by cutsat rfl lemma δ_shape (hnm : ¬ n + 1 = m) (z : Cochain F G n) : δ n m z = 0 := by ext p q hpq dsimp only [δ] rw [Cochain.mk_v, Cochain.zero_v, F.shape, G.shape, comp_zero, zero_add, zero_comp, smul_zero] all_goals simp only [ComplexShape.up_Rel] exact fun _ => hnm (by cutsat) variable (F G) (R) /-- The differential on the complex of morphisms between cochain complexes, as a linear map. -/ @[simps!] def δ_hom : Cochain F G n →ₗ[R] Cochain F G m where toFun := δ n m map_add' α β := by by_cases h : n + 1 = m · ext p q hpq dsimp simp only [δ_v n m h _ p q hpq _ _ rfl rfl, Cochain.add_v, add_comp, comp_add, smul_add] abel · simp only [δ_shape _ _ h, add_zero] map_smul' r a := by by_cases h : n + 1 = m · ext p q hpq dsimp simp only [δ_v n m h _ p q hpq _ _ rfl rfl, Cochain.smul_v, Linear.comp_smul, Linear.smul_comp, smul_add, smul_comm m.negOnePow r] · simp only [δ_shape _ _ h, smul_zero] variable {F G R} @[simp] lemma δ_add (z₁ z₂ : Cochain F G n) : δ n m (z₁ + z₂) = δ n m z₁ + δ n m z₂ := (δ_hom ℤ F G n m).map_add z₁ z₂ @[simp] lemma δ_sub (z₁ z₂ : Cochain F G n) : δ n m (z₁ - z₂) = δ n m z₁ - δ n m z₂ := (δ_hom ℤ F G n m).map_sub z₁ z₂ @[simp] lemma δ_zero : δ n m (0 : Cochain F G n) = 0 := (δ_hom ℤ F G n m).map_zero @[simp] lemma δ_neg (z : Cochain F G n) : δ n m (-z) = -δ n m z := (δ_hom ℤ F G n m).map_neg z @[simp] lemma δ_smul (k : R) (z : Cochain F G n) : δ n m (k • z) = k • δ n m z := (δ_hom R F G n m).map_smul k z @[simp] lemma δ_units_smul (k : Rˣ) (z : Cochain F G n) : δ n m (k • z) = k • δ n m z := δ_smul .. lemma δ_δ (n₀ n₁ n₂ : ℤ) (z : Cochain F G n₀) : δ n₁ n₂ (δ n₀ n₁ z) = 0 := by by_cases h₁₂ : n₁ + 1 = n₂; swap · rw [δ_shape _ _ h₁₂] by_cases h₀₁ : n₀ + 1 = n₁; swap · rw [δ_shape _ _ h₀₁, δ_zero] ext p q hpq dsimp simp only [δ_v n₁ n₂ h₁₂ _ p q hpq _ _ rfl rfl, δ_v n₀ n₁ h₀₁ z p (q - 1) (by cutsat) (q - 2) _ (by cutsat) rfl, δ_v n₀ n₁ h₀₁ z (p + 1) q (by cutsat) _ (p + 2) rfl (by cutsat), ← h₁₂, Int.negOnePow_succ, add_comp, assoc, HomologicalComplex.d_comp_d, comp_zero, zero_add, comp_add, HomologicalComplex.d_comp_d_assoc, zero_comp, smul_zero, add_zero, add_neg_cancel, Units.neg_smul, Linear.units_smul_comp, Linear.comp_units_smul] lemma δ_comp {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) (m₁ m₂ m₁₂ : ℤ) (h₁₂ : n₁₂ + 1 = m₁₂) (h₁ : n₁ + 1 = m₁) (h₂ : n₂ + 1 = m₂) : δ n₁₂ m₁₂ (z₁.comp z₂ h) = z₁.comp (δ n₂ m₂ z₂) (by rw [← h₁₂, ← h₂, ← h, add_assoc]) + n₂.negOnePow • (δ n₁ m₁ z₁).comp z₂ (by rw [← h₁₂, ← h₁, ← h, add_assoc, add_comm 1, add_assoc]) := by subst h₁₂ h₁ h₂ h ext p q hpq dsimp rw [z₁.comp_v _ (add_assoc n₁ n₂ 1).symm p _ q rfl (by cutsat), Cochain.comp_v _ _ (show n₁ + 1 + n₂ = n₁ + n₂ + 1 by cutsat) p (p + n₁ + 1) q (by cutsat) (by cutsat), δ_v (n₁ + n₂) _ rfl (z₁.comp z₂ rfl) p q hpq (p + n₁ + n₂) _ (by cutsat) rfl, z₁.comp_v z₂ rfl p _ _ rfl rfl, z₁.comp_v z₂ rfl (p + 1) (p + n₁ + 1) q (by cutsat) (by cutsat), δ_v n₂ (n₂ + 1) rfl z₂ (p + n₁) q (by cutsat) (p + n₁ + n₂) _ (by cutsat) rfl, δ_v n₁ (n₁ + 1) rfl z₁ p (p + n₁ + 1) (by cutsat) (p + n₁) _ (by cutsat) rfl] simp only [assoc, comp_add, add_comp, Int.negOnePow_succ, Int.negOnePow_add n₁ n₂, Units.neg_smul, comp_neg, neg_comp, smul_neg, smul_smul, Linear.units_smul_comp, mul_comm n₁.negOnePow n₂.negOnePow, Linear.comp_units_smul, smul_add] abel lemma δ_zero_cochain_comp {n₂ : ℤ} (z₁ : Cochain F G 0) (z₂ : Cochain G K n₂) (m₂ : ℤ) (h₂ : n₂ + 1 = m₂) : δ n₂ m₂ (z₁.comp z₂ (zero_add n₂)) = z₁.comp (δ n₂ m₂ z₂) (zero_add m₂) + n₂.negOnePow • ((δ 0 1 z₁).comp z₂ (by rw [add_comm, h₂])) := δ_comp z₁ z₂ (zero_add n₂) 1 m₂ m₂ h₂ (zero_add 1) h₂ lemma δ_comp_zero_cochain {n₁ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K 0) (m₁ : ℤ) (h₁ : n₁ + 1 = m₁) : δ n₁ m₁ (z₁.comp z₂ (add_zero n₁)) = z₁.comp (δ 0 1 z₂) h₁ + (δ n₁ m₁ z₁).comp z₂ (add_zero m₁) := by simp only [δ_comp z₁ z₂ (add_zero n₁) m₁ 1 m₁ h₁ h₁ (zero_add 1), one_smul, Int.negOnePow_zero] @[simp] lemma δ_zero_cochain_v (z : Cochain F G 0) (p q : ℤ) (hpq : p + 1 = q) : (δ 0 1 z).v p q hpq = z.v p p (add_zero p) ≫ G.d p q - F.d p q ≫ z.v q q (add_zero q) := by simp only [δ_v 0 1 (zero_add 1) z p q hpq p q (by cutsat) hpq, Int.negOnePow_one, Units.neg_smul, one_smul, sub_eq_add_neg] @[simp] lemma δ_ofHom {p : ℤ} (φ : F ⟶ G) : δ 0 p (Cochain.ofHom φ) = 0 := by by_cases h : p = 1 · subst h ext simp · rw [δ_shape] cutsat @[simp] lemma δ_ofHomotopy {φ₁ φ₂ : F ⟶ G} (h : Homotopy φ₁ φ₂) : δ (-1) 0 (Cochain.ofHomotopy h) = Cochain.ofHom φ₁ - Cochain.ofHom φ₂ := by ext p have eq := h.comm p rw [dNext_eq h.hom (show (ComplexShape.up ℤ).Rel p (p + 1) by simp), prevD_eq h.hom (show (ComplexShape.up ℤ).Rel (p - 1) p by simp)] at eq rw [Cochain.ofHomotopy, δ_v (-1) 0 (neg_add_cancel 1) _ p p (add_zero p) (p - 1) (p + 1) rfl rfl] simp only [Cochain.mk_v, one_smul, Int.negOnePow_zero, Cochain.sub_v, Cochain.ofHom_v, eq] abel lemma δ_neg_one_cochain (z : Cochain F G (-1)) : δ (-1) 0 z = Cochain.ofHom (Homotopy.nullHomotopicMap' (fun i j hij => z.v i j (by dsimp at hij; rw [← hij, add_neg_cancel_right]))) := by ext p rw [δ_v (-1) 0 (neg_add_cancel 1) _ p p (add_zero p) (p - 1) (p + 1) rfl rfl] simp only [one_smul, Cochain.ofHom_v, Int.negOnePow_zero] rw [Homotopy.nullHomotopicMap'_f (show (ComplexShape.up ℤ).Rel (p - 1) p by simp) (show (ComplexShape.up ℤ).Rel p (p + 1) by simp)] abel end HomComplex variable (F G) open HomComplex /-- The cochain complex of homomorphisms between two cochain complexes `F` and `G`. In degree `n : ℤ`, it consists of the abelian group `HomComplex.Cochain F G n`. -/ @[simps! X d_hom_apply] def HomComplex : CochainComplex AddCommGrpCat ℤ where X i := AddCommGrpCat.of (Cochain F G i) d i j := AddCommGrpCat.ofHom (δ_hom ℤ F G i j) shape _ _ hij := by ext; simp [δ_shape _ _ hij] d_comp_d' _ _ _ _ _ := by ext; simp [δ_δ] namespace HomComplex /-- The subgroup of cocycles in `Cochain F G n`. -/ def cocycle : AddSubgroup (Cochain F G n) := AddMonoidHom.ker (δ_hom ℤ F G n (n + 1)).toAddMonoidHom /-- The type of `n`-cocycles, as a subtype of `Cochain F G n`. -/ def Cocycle : Type v := cocycle F G n instance : AddCommGroup (Cocycle F G n) := by dsimp only [Cocycle] infer_instance namespace Cocycle variable {F G} lemma mem_iff (hnm : n + 1 = m) (z : Cochain F G n) : z ∈ cocycle F G n ↔ δ n m z = 0 := by subst hnm; rfl variable {n} instance : Coe (Cocycle F G n) (Cochain F G n) where coe x := x.1 @[ext] lemma ext (z₁ z₂ : Cocycle F G n) (h : (z₁ : Cochain F G n) = z₂) : z₁ = z₂ := Subtype.ext h instance : SMul R (Cocycle F G n) where smul r z := ⟨r • z.1, by have hz := z.2 rw [mem_iff n (n + 1) rfl] at hz ⊢ simp only [δ_smul, hz, smul_zero]⟩ variable (F G n) @[simp] lemma coe_zero : (↑(0 : Cocycle F G n) : Cochain F G n) = 0 := by rfl variable {F G n} @[simp] lemma coe_add (z₁ z₂ : Cocycle F G n) : (↑(z₁ + z₂) : Cochain F G n) = (z₁ : Cochain F G n) + (z₂ : Cochain F G n) := rfl @[simp] lemma coe_neg (z : Cocycle F G n) : (↑(-z) : Cochain F G n) = -(z : Cochain F G n) := rfl @[simp] lemma coe_smul (z : Cocycle F G n) (x : R) : (↑(x • z) : Cochain F G n) = x • (z : Cochain F G n) := rfl @[simp] lemma coe_units_smul (z : Cocycle F G n) (x : Rˣ) : (↑(x • z) : Cochain F G n) = x • (z : Cochain F G n) := rfl @[simp] lemma coe_sub (z₁ z₂ : Cocycle F G n) : (↑(z₁ - z₂) : Cochain F G n) = (z₁ : Cochain F G n) - (z₂ : Cochain F G n) := rfl instance : Module R (Cocycle F G n) where one_smul _ := by aesop mul_smul _ _ _ := by ext; dsimp; rw [smul_smul] smul_zero _ := by aesop smul_add _ _ _ := by aesop add_smul _ _ _ := by ext; dsimp; rw [add_smul] zero_smul := by aesop /-- Constructor for `Cocycle F G n`, taking as inputs `z : Cochain F G n`, an integer `m : ℤ` such that `n + 1 = m`, and the relation `δ n m z = 0`. -/ @[simps] def mk (z : Cochain F G n) (m : ℤ) (hnm : n + 1 = m) (h : δ n m z = 0) : Cocycle F G n := ⟨z, by simpa only [mem_iff n m hnm z] using h⟩ @[simp] lemma δ_eq_zero {n : ℤ} (z : Cocycle F G n) (m : ℤ) : δ n m (z : Cochain F G n) = 0 := by by_cases h : n + 1 = m · rw [← mem_iff n m h] exact z.2 · exact δ_shape n m h _ /-- The `0`-cocycle associated to a morphism in `CochainComplex C ℤ`. -/ @[simps!] def ofHom (φ : F ⟶ G) : Cocycle F G 0 := mk (Cochain.ofHom φ) 1 (zero_add 1) (by simp) /-- The morphism in `CochainComplex C ℤ` associated to a `0`-cocycle. -/ @[simps] def homOf (z : Cocycle F G 0) : F ⟶ G where f i := (z : Cochain _ _ _).v i i (add_zero i) comm' := by rintro i j rfl rcases z with ⟨z, hz⟩ dsimp rw [mem_iff 0 1 (zero_add 1)] at hz simpa only [δ_zero_cochain_v, Cochain.zero_v, sub_eq_zero] using Cochain.congr_v hz i (i + 1) rfl @[simp] lemma homOf_ofHom_eq_self (φ : F ⟶ G) : homOf (ofHom φ) = φ := by cat_disch @[simp] lemma ofHom_homOf_eq_self (z : Cocycle F G 0) : ofHom (homOf z) = z := by cat_disch @[simp] lemma cochain_ofHom_homOf_eq_coe (z : Cocycle F G 0) : Cochain.ofHom (homOf z) = (z : Cochain F G 0) := by simpa only [Cocycle.ext_iff] using ofHom_homOf_eq_self z variable (F G) /-- The additive equivalence between morphisms in `CochainComplex C ℤ` and `0`-cocycles. -/ @[simps] def equivHom : (F ⟶ G) ≃+ Cocycle F G 0 where toFun := ofHom invFun := homOf left_inv := homOf_ofHom_eq_self right_inv := ofHom_homOf_eq_self map_add' := by cat_disch variable (K) /-- The `1`-cocycle given by the differential on a cochain complex. -/ @[simps!] def diff : Cocycle K K 1 := Cocycle.mk (Cochain.diff K) 2 rfl (by ext p q hpq simp only [Cochain.zero_v, δ_v 1 2 rfl _ p q hpq _ _ rfl rfl, Cochain.diff_v, HomologicalComplex.d_comp_d, smul_zero, add_zero]) end Cocycle variable {F G} @[simp] lemma δ_comp_zero_cocycle {n : ℤ} (z₁ : Cochain F G n) (z₂ : Cocycle G K 0) (m : ℤ) : δ n m (z₁.comp z₂.1 (add_zero n)) = (δ n m z₁).comp z₂.1 (add_zero m) := by by_cases hnm : n + 1 = m · simp [δ_comp_zero_cochain _ _ _ hnm] · simp [δ_shape _ _ hnm] @[simp] lemma δ_comp_ofHom {n : ℤ} (z₁ : Cochain F G n) (f : G ⟶ K) (m : ℤ) : δ n m (z₁.comp (Cochain.ofHom f) (add_zero n)) = (δ n m z₁).comp (Cochain.ofHom f) (add_zero m) := by rw [← Cocycle.ofHom_coe, δ_comp_zero_cocycle] @[simp] lemma δ_zero_cocycle_comp {n : ℤ} (z₁ : Cocycle F G 0) (z₂ : Cochain G K n) (m : ℤ) : δ n m (z₁.1.comp z₂ (zero_add n)) = z₁.1.comp (δ n m z₂) (zero_add m) := by by_cases hnm : n + 1 = m · simp [δ_zero_cochain_comp _ _ _ hnm] · simp [δ_shape _ _ hnm] @[simp] lemma δ_ofHom_comp {n : ℤ} (f : F ⟶ G) (z : Cochain G K n) (m : ℤ) : δ n m ((Cochain.ofHom f).comp z (zero_add n)) = (Cochain.ofHom f).comp (δ n m z) (zero_add m) := by rw [← Cocycle.ofHom_coe, δ_zero_cocycle_comp] namespace Cochain /-- Given two morphisms of complexes `φ₁ φ₂ : F ⟶ G`, the datum of an homotopy between `φ₁` and `φ₂` is equivalent to the datum of a `1`-cochain `z` such that `δ (-1) 0 z` is the difference of the zero cochains associated to `φ₂` and `φ₁`. -/ @[simps] def equivHomotopy (φ₁ φ₂ : F ⟶ G) : Homotopy φ₁ φ₂ ≃ { z : Cochain F G (-1) // Cochain.ofHom φ₁ = δ (-1) 0 z + Cochain.ofHom φ₂ } where toFun ho := ⟨Cochain.ofHomotopy ho, by simp only [δ_ofHomotopy, sub_add_cancel]⟩ invFun z := { hom := fun i j => if hij : i + (-1) = j then z.1.v i j hij else 0 zero := fun i j (hij : j + 1 ≠ i) => dif_neg (fun _ => hij (by omega)) comm := fun p => by have eq := Cochain.congr_v z.2 p p (add_zero p) have h₁ : (ComplexShape.up ℤ).Rel (p - 1) p := by simp have h₂ : (ComplexShape.up ℤ).Rel p (p + 1) := by simp simp only [δ_neg_one_cochain, Cochain.ofHom_v, ComplexShape.up_Rel, Cochain.add_v, Homotopy.nullHomotopicMap'_f h₁ h₂] at eq rw [dNext_eq _ h₂, prevD_eq _ h₁, eq, dif_pos, dif_pos] } left_inv := fun ho => by ext i j dsimp split_ifs with h · rfl · rw [ho.zero i j (fun h' => h (by dsimp at h'; omega))] right_inv := fun z => by ext p q hpq dsimp [Cochain.ofHomotopy] rw [dif_pos hpq] @[simp] lemma equivHomotopy_apply_of_eq {φ₁ φ₂ : F ⟶ G} (h : φ₁ = φ₂) : (equivHomotopy _ _ (Homotopy.ofEq h)).1 = 0 := rfl lemma ofHom_injective {f₁ f₂ : F ⟶ G} (h : ofHom f₁ = ofHom f₂) : f₁ = f₂ := (Cocycle.equivHom F G).injective (by ext1; exact h) end Cochain section variable {n} {D : Type*} [Category D] [Preadditive D] (z z' : Cochain K L n) (f : K ⟶ L) (Φ : C ⥤ D) [Φ.Additive] namespace Cochain /-- If `Φ : C ⥤ D` is an additive functor, a cochain `z : Cochain K L n` between cochain complexes in `C` can be mapped to a cochain between the cochain complexes in `D` obtained by applying the functor `Φ.mapHomologicalComplex _ : CochainComplex C ℤ ⥤ CochainComplex D ℤ`. -/ def map : Cochain ((Φ.mapHomologicalComplex _).obj K) ((Φ.mapHomologicalComplex _).obj L) n := Cochain.mk (fun p q hpq => Φ.map (z.v p q hpq)) @[simp] lemma map_v (p q : ℤ) (hpq : p + n = q) : (z.map Φ).v p q hpq = Φ.map (z.v p q hpq) := rfl @[simp] protected lemma map_add : (z + z').map Φ = z.map Φ + z'.map Φ := by cat_disch @[simp] protected lemma map_neg : (-z).map Φ = -z.map Φ := by cat_disch @[simp] protected lemma map_sub : (z - z').map Φ = z.map Φ - z'.map Φ := by cat_disch variable (K L n) @[simp] protected lemma map_zero : (0 : Cochain K L n).map Φ = 0 := by cat_disch @[simp] lemma map_comp {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) (Φ : C ⥤ D) [Φ.Additive] : (Cochain.comp z₁ z₂ h).map Φ = Cochain.comp (z₁.map Φ) (z₂.map Φ) h := by ext p q hpq dsimp simp only [map_v, comp_v _ _ h p _ q rfl (by cutsat), Φ.map_comp] @[simp] lemma map_ofHom : (Cochain.ofHom f).map Φ = Cochain.ofHom ((Φ.mapHomologicalComplex _).map f) := by cat_disch end Cochain variable (n) @[simp] lemma δ_map : δ n m (z.map Φ) = (δ n m z).map Φ := by by_cases hnm : n + 1 = m · ext p q hpq dsimp simp only [δ_v n m hnm _ p q hpq (q - 1) (p + 1) rfl rfl, Functor.map_add, Functor.map_comp, Functor.map_units_smul, Cochain.map_v, Functor.mapHomologicalComplex_obj_d] · simp only [δ_shape _ _ hnm, Cochain.map_zero] end end HomComplex end CochainComplex
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/Shift.lean
import Mathlib.Algebra.Homology.HomotopyCategory import Mathlib.Algebra.Ring.NegOnePow import Mathlib.CategoryTheory.Shift.Quotient import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.Tactic.Linarith /-! # The shift on cochain complexes and on the homotopy category In this file, we show that for any preadditive category `C`, the categories `CochainComplex C ℤ` and `HomotopyCategory C (ComplexShape.up ℤ)` are equipped with a shift by `ℤ`. We also show that if `F : C ⥤ D` is an additive functor, then the functors `F.mapHomologicalComplex (ComplexShape.up ℤ)` and `F.mapHomotopyCategory (ComplexShape.up ℤ)` commute with the shift by `ℤ`. -/ assert_not_exists TwoSidedIdeal universe v v' u u' open CategoryTheory variable (C : Type u) [Category.{v} C] [Preadditive C] {D : Type u'} [Category.{v'} D] [Preadditive D] namespace CochainComplex open HomologicalComplex /-- The shift functor by `n : ℤ` on `CochainComplex C ℤ` which sends a cochain complex `K` to the complex which is `K.X (i + n)` in degree `i`, and which multiplies the differentials by `(-1)^n`. -/ @[simps] def shiftFunctor (n : ℤ) : CochainComplex C ℤ ⥤ CochainComplex C ℤ where obj K := { X := fun i => K.X (i + n) d := fun _ _ => n.negOnePow • K.d _ _ d_comp_d' := by intros simp only [Linear.comp_units_smul, Linear.units_smul_comp, d_comp_d, smul_zero] shape := fun i j hij => by rw [K.shape, smul_zero] intro hij' apply hij dsimp at hij' ⊢ omega } map φ := { f := fun _ => φ.f _ comm' := by intros dsimp simp only [Linear.comp_units_smul, Hom.comm, Linear.units_smul_comp] } map_id := by intros; rfl map_comp := by intros; rfl instance (n : ℤ) : (shiftFunctor C n).Additive where instance (n : ℤ) {R : Type*} [Ring R] [Linear R C] : Functor.Linear R (shiftFunctor C n) where variable {C} /-- The canonical isomorphism `((shiftFunctor C n).obj K).X i ≅ K.X m` when `m = i + n`. -/ @[simp] def shiftFunctorObjXIso (K : CochainComplex C ℤ) (n i m : ℤ) (hm : m = i + n) : ((shiftFunctor C n).obj K).X i ≅ K.X m := K.XIsoOfEq hm.symm section variable (C) attribute [local simp] XIsoOfEq_hom_naturality /-- The shift functor by `n` on `CochainComplex C ℤ` identifies to the identity functor when `n = 0`. -/ @[simps!] def shiftFunctorZero' (n : ℤ) (h : n = 0) : shiftFunctor C n ≅ 𝟭 _ := NatIso.ofComponents (fun K => Hom.isoOfComponents (fun i => K.shiftFunctorObjXIso _ _ _ (by cutsat)) (fun _ _ _ => by simp [h])) (fun _ ↦ by ext; simp) /-- The compatibility of the shift functors on `CochainComplex C ℤ` with respect to the addition of integers. -/ @[simps!] def shiftFunctorAdd' (n₁ n₂ n₁₂ : ℤ) (h : n₁ + n₂ = n₁₂) : shiftFunctor C n₁₂ ≅ shiftFunctor C n₁ ⋙ shiftFunctor C n₂ := NatIso.ofComponents (fun K => Hom.isoOfComponents (fun i => K.shiftFunctorObjXIso _ _ _ (by cutsat)) (fun _ _ _ => by subst h dsimp simp only [add_comm n₁ n₂, Int.negOnePow_add, Linear.units_smul_comp, Linear.comp_units_smul, d_comp_XIsoOfEq_hom, smul_smul, XIsoOfEq_hom_comp_d])) (by intros; ext; simp) attribute [local simp] XIsoOfEq instance : HasShift (CochainComplex C ℤ) ℤ := hasShiftMk _ _ { F := shiftFunctor C zero := shiftFunctorZero' C _ rfl add := fun n₁ n₂ => shiftFunctorAdd' C n₁ n₂ _ rfl } instance (n : ℤ) : (CategoryTheory.shiftFunctor (HomologicalComplex C (ComplexShape.up ℤ)) n).Additive := (inferInstance : (CochainComplex.shiftFunctor C n).Additive) instance (n : ℤ) {R : Type*} [Ring R] [Linear R C] : Functor.Linear R (CategoryTheory.shiftFunctor (HomologicalComplex C (ComplexShape.up ℤ)) n) where end @[simp] lemma shiftFunctor_obj_X' (K : CochainComplex C ℤ) (n p : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).obj K).X p = K.X (p + n) := rfl @[simp] lemma shiftFunctor_map_f' {K L : CochainComplex C ℤ} (φ : K ⟶ L) (n p : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).map φ).f p = φ.f (p + n) := rfl @[simp] lemma shiftFunctor_obj_d' (K : CochainComplex C ℤ) (n i j : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).obj K).d i j = n.negOnePow • K.d _ _ := rfl lemma shiftFunctorAdd_inv_app_f (K : CochainComplex C ℤ) (a b n : ℤ) : ((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := rfl lemma shiftFunctorAdd_hom_app_f (K : CochainComplex C ℤ) (a b n : ℤ) : ((shiftFunctorAdd (CochainComplex C ℤ) a b).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := by tauto lemma shiftFunctorAdd'_inv_app_f' (K : CochainComplex C ℤ) (a b ab : ℤ) (h : a + b = ab) (n : ℤ) : ((CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) a b ab h).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [← h, add_assoc, add_comm a])).hom := by subst h rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd_inv_app_f] lemma shiftFunctorAdd'_hom_app_f' (K : CochainComplex C ℤ) (a b ab : ℤ) (h : a + b = ab) (n : ℤ) : ((CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) a b ab h).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [← h, add_assoc, add_comm a])).hom := by subst h rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd_hom_app_f] lemma shiftFunctorZero_inv_app_f (K : CochainComplex C ℤ) (n : ℤ) : ((CategoryTheory.shiftFunctorZero (CochainComplex C ℤ) ℤ).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_zero])).hom := rfl lemma shiftFunctorZero_hom_app_f (K : CochainComplex C ℤ) (n : ℤ) : ((CategoryTheory.shiftFunctorZero (CochainComplex C ℤ) ℤ).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_zero])).hom := by tauto lemma XIsoOfEq_shift (K : CochainComplex C ℤ) (n : ℤ) {p q : ℤ} (hpq : p = q) : (K⟦n⟧).XIsoOfEq hpq = K.XIsoOfEq (show p + n = q + n by rw [hpq]) := rfl variable (C) lemma shiftFunctorAdd'_eq (a b c : ℤ) (h : a + b = c) : CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) a b c h = shiftFunctorAdd' C a b c h := by ext simp only [shiftFunctorAdd'_hom_app_f', XIsoOfEq, eqToIso.hom, shiftFunctorAdd'_hom_app_f] lemma shiftFunctorAdd_eq (a b : ℤ) : CategoryTheory.shiftFunctorAdd (CochainComplex C ℤ) a b = shiftFunctorAdd' C a b _ rfl := by rw [← CategoryTheory.shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd'_eq] lemma shiftFunctorZero_eq : CategoryTheory.shiftFunctorZero (CochainComplex C ℤ) ℤ = shiftFunctorZero' C 0 rfl := by ext rw [shiftFunctorZero_hom_app_f, shiftFunctorZero'_hom_app_f] variable {C} lemma shiftFunctorComm_hom_app_f (K : CochainComplex C ℤ) (a b p : ℤ) : ((shiftFunctorComm (CochainComplex C ℤ) a b).hom.app K).f p = (K.XIsoOfEq (show p + b + a = p + a + b by rw [add_assoc, add_comm b, add_assoc])).hom := by rw [shiftFunctorComm_eq _ _ _ _ rfl] dsimp rw [shiftFunctorAdd'_inv_app_f', shiftFunctorAdd'_hom_app_f'] simp only [XIsoOfEq, eqToIso.hom, eqToHom_trans] variable (C) attribute [local simp] XIsoOfEq_hom_naturality /-- Shifting cochain complexes by `n` and evaluating in a degree `i` identifies to the evaluation in degree `i'` when `n + i = i'`. -/ @[simps!] def shiftEval (n i i' : ℤ) (hi : n + i = i') : (CategoryTheory.shiftFunctor (CochainComplex C ℤ) n) ⋙ HomologicalComplex.eval C (ComplexShape.up ℤ) i ≅ HomologicalComplex.eval C (ComplexShape.up ℤ) i' := NatIso.ofComponents (fun K => K.XIsoOfEq (by dsimp; rw [← hi, add_comm i])) (by simp) end CochainComplex namespace CategoryTheory open Category namespace Functor variable {C} variable (F : C ⥤ D) [F.Additive] attribute [local simp] Functor.map_zsmul /-- The commutation with the shift isomorphism for the functor on cochain complexes induced by an additive functor between preadditive categories. -/ @[simps!] def mapCochainComplexShiftIso (n : ℤ) : shiftFunctor _ n ⋙ F.mapHomologicalComplex (ComplexShape.up ℤ) ≅ F.mapHomologicalComplex (ComplexShape.up ℤ) ⋙ shiftFunctor _ n := NatIso.ofComponents (fun K => HomologicalComplex.Hom.isoOfComponents (fun _ => Iso.refl _) (by simp)) (fun _ => by ext; dsimp; rw [id_comp, comp_id]) instance commShiftMapCochainComplex : (F.mapHomologicalComplex (ComplexShape.up ℤ)).CommShift ℤ where commShiftIso := F.mapCochainComplexShiftIso commShiftIso_zero := by ext rw [CommShift.isoZero_hom_app] dsimp simp only [CochainComplex.shiftFunctorZero_inv_app_f, CochainComplex.shiftFunctorZero_hom_app_f, HomologicalComplex.XIsoOfEq, eqToIso, eqToHom_map, eqToHom_trans, eqToHom_refl] commShiftIso_add := fun a b => by ext rw [CommShift.isoAdd_hom_app] dsimp rw [id_comp, id_comp] simp only [CochainComplex.shiftFunctorAdd_hom_app_f, CochainComplex.shiftFunctorAdd_inv_app_f, HomologicalComplex.XIsoOfEq, eqToIso, eqToHom_map, eqToHom_trans, eqToHom_refl] lemma mapHomologicalComplex_commShiftIso_eq (n : ℤ) : (F.mapHomologicalComplex (ComplexShape.up ℤ)).commShiftIso n = F.mapCochainComplexShiftIso n := rfl @[simp] lemma mapHomologicalComplex_commShiftIso_hom_app_f (K : CochainComplex C ℤ) (n i : ℤ) : (((F.mapHomologicalComplex (ComplexShape.up ℤ)).commShiftIso n).hom.app K).f i = 𝟙 _ := rfl @[simp] lemma mapHomologicalComplex_commShiftIso_inv_app_f (K : CochainComplex C ℤ) (n i : ℤ) : (((F.mapHomologicalComplex (ComplexShape.up ℤ)).commShiftIso n).inv.app K).f i = 𝟙 _ := rfl end Functor end CategoryTheory namespace Homotopy variable {C} /-- If `h : Homotopy φ₁ φ₂` and `n : ℤ`, this is the induced homotopy between `φ₁⟦n⟧'` and `φ₂⟦n⟧'`. -/ def shift {K L : CochainComplex C ℤ} {φ₁ φ₂ : K ⟶ L} (h : Homotopy φ₁ φ₂) (n : ℤ) : Homotopy (φ₁⟦n⟧') (φ₂⟦n⟧') where hom _ _ := n.negOnePow • h.hom _ _ zero i j hij := by dsimp rw [h.zero, smul_zero] intro hij' dsimp at hij hij' omega comm := fun i => by rw [dNext_eq _ (show (ComplexShape.up ℤ).Rel i (i + 1) by simp), prevD_eq _ (show (ComplexShape.up ℤ).Rel (i - 1) i by simp)] dsimp simpa only [Linear.units_smul_comp, Linear.comp_units_smul, smul_smul, Int.units_mul_self, one_smul, dNext_eq _ (show (ComplexShape.up ℤ).Rel (i + n) (i + 1 + n) by dsimp; omega), prevD_eq _ (show (ComplexShape.up ℤ).Rel (i - 1 + n) (i + n) by dsimp; omega)] using h.comm (i + n) end Homotopy namespace HomotopyCategory instance : (homotopic C (ComplexShape.up ℤ)).IsCompatibleWithShift ℤ := ⟨fun n _ _ _ _ ⟨h⟩ => ⟨h.shift n⟩⟩ noncomputable instance hasShift : HasShift (HomotopyCategory C (ComplexShape.up ℤ)) ℤ := by dsimp only [HomotopyCategory] infer_instance noncomputable instance commShiftQuotient : (HomotopyCategory.quotient C (ComplexShape.up ℤ)).CommShift ℤ := Quotient.functor_commShift (homotopic C (ComplexShape.up ℤ)) ℤ instance (n : ℤ) : (shiftFunctor (HomotopyCategory C (ComplexShape.up ℤ)) n).Additive := by have : ((quotient C (ComplexShape.up ℤ) ⋙ shiftFunctor _ n)).Additive := Functor.additive_of_iso ((quotient C (ComplexShape.up ℤ)).commShiftIso n) apply Functor.additive_of_full_essSurj_comp (quotient _ _ ) instance {R : Type*} [Ring R] [CategoryTheory.Linear R C] (n : ℤ) : (CategoryTheory.shiftFunctor (HomotopyCategory C (ComplexShape.up ℤ)) n).Linear R where map_smul := by rintro ⟨X⟩ ⟨Y⟩ f r obtain ⟨f, rfl⟩ := (HomotopyCategory.quotient C (ComplexShape.up ℤ)).map_surjective f have h₁ := NatIso.naturality_1 ((HomotopyCategory.quotient _ _).commShiftIso n) f have h₂ := NatIso.naturality_1 ((HomotopyCategory.quotient _ _).commShiftIso n) (r • f) dsimp at h₁ h₂ rw [← Functor.map_smul, ← h₁, ← h₂] simp section variable {C} variable (F : C ⥤ D) [F.Additive] noncomputable instance : (F.mapHomotopyCategory (ComplexShape.up ℤ)).CommShift ℤ := Quotient.liftCommShift _ _ _ _ instance : NatTrans.CommShift (F.mapHomotopyCategoryFactors (ComplexShape.up ℤ)).hom ℤ := Quotient.liftCommShift_compatibility _ _ _ _ end end HomotopyCategory
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory/Pretriangulated.lean
import Mathlib.Algebra.Homology.HomotopyCategory.MappingCone import Mathlib.Algebra.Homology.HomotopyCategory.HomComplexShift import Mathlib.CategoryTheory.Triangulated.Functor /-! The pretriangulated structure on the homotopy category of complexes In this file, we define the pretriangulated structure on the homotopy category `HomotopyCategory C (ComplexShape.up ℤ)` of an additive category `C`. The distinguished triangles are the triangles that are isomorphic to the image in the homotopy category of the standard triangle `K ⟶ L ⟶ mappingCone φ ⟶ K⟦(1 : ℤ)⟧` for some morphism of cochain complexes `φ : K ⟶ L`. This result first appeared in the Liquid Tensor Experiment. In the LTE, the formalization followed the Stacks Project: in particular, the distinguished triangles were defined using degreewise-split short exact sequences of cochain complexes. Here, we follow the original definitions in [Verdiers's thesis, I.3][verdier1996] (with the better sign conventions from the introduction of [Brian Conrad's book *Grothendieck duality and base change*][conrad2000]). ## References * [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996] * [Brian Conrad, Grothendieck duality and base change][conrad2000] * https://stacks.math.columbia.edu/tag/014P -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits CochainComplex.HomComplex Pretriangulated variable {C D : Type*} [Category C] [Category D] [Preadditive C] [HasBinaryBiproducts C] [Preadditive D] [HasBinaryBiproducts D] {K L : CochainComplex C ℤ} (φ : K ⟶ L) namespace CochainComplex namespace mappingCone /-- The standard triangle `K ⟶ L ⟶ mappingCone φ ⟶ K⟦(1 : ℤ)⟧` in `CochainComplex C ℤ` attached to a morphism `φ : K ⟶ L`. It involves `φ`, `inr φ : L ⟶ mappingCone φ` and the morphism induced by the `1`-cocycle `-mappingCone.fst φ`. -/ @[simps! obj₁ obj₂ obj₃ mor₁ mor₂] noncomputable def triangle : Triangle (CochainComplex C ℤ) := Triangle.mk φ (inr φ) (Cocycle.homOf ((-fst φ).rightShift 1 0 (zero_add 1))) @[reassoc (attr := simp)] lemma inl_v_triangle_mor₃_f (p q : ℤ) (hpq : p + (-1) = q) : (inl φ).v p q hpq ≫ (triangle φ).mor₃.f q = -(K.shiftFunctorObjXIso 1 q p (by rw [← hpq, neg_add_cancel_right])).inv := by dsimp [triangle] -- the following list of lemmas was obtained by doing -- simp? [Cochain.rightShift_v _ 1 0 (zero_add 1) q q (add_zero q) p (by omega)] simp only [Int.reduceNeg, Cochain.rightShift_neg, Cochain.neg_v, shiftFunctor_obj_X', Cochain.rightShift_v _ 1 0 (zero_add 1) q q (add_zero q) p (by cutsat), shiftFunctor_obj_X, shiftFunctorObjXIso, Preadditive.comp_neg, inl_v_fst_v_assoc] @[reassoc (attr := simp)] lemma inr_f_triangle_mor₃_f (p : ℤ) : (inr φ).f p ≫ (triangle φ).mor₃.f p = 0 := by dsimp [triangle] -- the following list of lemmas was obtained by doing -- simp? [Cochain.rightShift_v _ 1 0 _ p p (add_zero p) (p+1) rfl] simp only [Cochain.rightShift_neg, Cochain.neg_v, shiftFunctor_obj_X', Cochain.rightShift_v _ 1 0 _ p p (add_zero p) (p + 1) rfl, shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, comp_id, Preadditive.comp_neg, inr_f_fst_v, neg_zero] @[reassoc (attr := simp)] lemma inr_triangleδ : inr φ ≫ (triangle φ).mor₃ = 0 := by ext; simp /-- The (distinguished) triangle in the homotopy category that is associated to a morphism `φ : K ⟶ L` in the category `CochainComplex C ℤ`. -/ noncomputable abbrev triangleh : Triangle (HomotopyCategory C (ComplexShape.up ℤ)) := (HomotopyCategory.quotient _ _).mapTriangle.obj (triangle φ) variable (K) in /-- The mapping cone of the identity is contractible. -/ noncomputable def homotopyToZeroOfId : Homotopy (𝟙 (mappingCone (𝟙 K))) 0 := descHomotopy (𝟙 K) _ _ 0 (inl _) (by simp) (by simp) section mapOfHomotopy variable {K₁ L₁ K₂ L₂ K₃ L₃ : CochainComplex C ℤ} {φ₁ : K₁ ⟶ L₁} {φ₂ : K₂ ⟶ L₂} {a : K₁ ⟶ K₂} {b : L₁ ⟶ L₂} (H : Homotopy (φ₁ ≫ b) (a ≫ φ₂)) /-- The morphism `mappingCone φ₁ ⟶ mappingCone φ₂` that is induced by a square that is commutative up to homotopy. -/ noncomputable def mapOfHomotopy : mappingCone φ₁ ⟶ mappingCone φ₂ := desc φ₁ ((Cochain.ofHom a).comp (inl φ₂) (zero_add _) + ((Cochain.equivHomotopy _ _) H).1.comp (Cochain.ofHom (inr φ₂)) (add_zero _)) (b ≫ inr φ₂) (by simp) @[reassoc] lemma triangleMapOfHomotopy_comm₂ : inr φ₁ ≫ mapOfHomotopy H = b ≫ inr φ₂ := by simp [mapOfHomotopy] @[reassoc] lemma triangleMapOfHomotopy_comm₃ : mapOfHomotopy H ≫ (triangle φ₂).mor₃ = (triangle φ₁).mor₃ ≫ a⟦1⟧' := by ext p dsimp [mapOfHomotopy, triangle] -- the following list of lemmas as been obtained by doing -- simp? [ext_from_iff _ _ _ rfl, Cochain.rightShift_v _ 1 0 _ p p _ (p + 1) rfl] simp only [Int.reduceNeg, Cochain.rightShift_neg, Cochain.neg_v, shiftFunctor_obj_X', Cochain.rightShift_v _ 1 0 _ p p _ (p + 1) rfl, shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, comp_id, Preadditive.comp_neg, Preadditive.neg_comp, ext_from_iff _ _ _ rfl, inl_v_desc_f_assoc, Cochain.add_v, Cochain.zero_cochain_comp_v, Cochain.ofHom_v, Cochain.comp_zero_cochain_v, Preadditive.add_comp, assoc, inl_v_fst_v, inr_f_fst_v, comp_zero, add_zero, inl_v_fst_v_assoc, inr_f_desc_f_assoc, HomologicalComplex.comp_f, neg_zero, inr_f_fst_v_assoc, zero_comp, and_self] /-- The morphism `triangleh φ₁ ⟶ triangleh φ₂` that is induced by a square that is commutative up to homotopy. -/ @[simps] noncomputable def trianglehMapOfHomotopy : triangleh φ₁ ⟶ triangleh φ₂ where hom₁ := (HomotopyCategory.quotient _ _).map a hom₂ := (HomotopyCategory.quotient _ _).map b hom₃ := (HomotopyCategory.quotient _ _).map (mapOfHomotopy H) comm₁ := by dsimp simp only [← Functor.map_comp] exact HomotopyCategory.eq_of_homotopy _ _ H comm₂ := by dsimp simp only [← Functor.map_comp, triangleMapOfHomotopy_comm₂] comm₃ := by dsimp rw [← Functor.map_comp_assoc, triangleMapOfHomotopy_comm₃, Functor.map_comp, assoc, assoc] simp end mapOfHomotopy section map variable {K₁ L₁ K₂ L₂ K₃ L₃ : CochainComplex C ℤ} (φ₁ : K₁ ⟶ L₁) (φ₂ : K₂ ⟶ L₂) (φ₃ : K₃ ⟶ L₃) (a : K₁ ⟶ K₂) (b : L₁ ⟶ L₂) /-- The morphism `mappingCone φ₁ ⟶ mappingCone φ₂` that is induced by a commutative square. -/ noncomputable def map (comm : φ₁ ≫ b = a ≫ φ₂) : mappingCone φ₁ ⟶ mappingCone φ₂ := desc φ₁ ((Cochain.ofHom a).comp (inl φ₂) (zero_add _)) (b ≫ inr φ₂) (by simp [reassoc_of% comm]) variable (comm : φ₁ ≫ b = a ≫ φ₂) lemma map_eq_mapOfHomotopy : map φ₁ φ₂ a b comm = mapOfHomotopy (Homotopy.ofEq comm) := by simp [map, mapOfHomotopy] lemma map_id : map φ φ (𝟙 _) (𝟙 _) (by rw [id_comp, comp_id]) = 𝟙 _ := by ext n simp [ext_from_iff _ (n + 1) n rfl, map] variable (a' : K₂ ⟶ K₃) (b' : L₂ ⟶ L₃) @[reassoc] lemma map_comp (comm' : φ₂ ≫ b' = a' ≫ φ₃) : map φ₁ φ₃ (a ≫ a') (b ≫ b') (by rw [reassoc_of% comm, comm', assoc]) = map φ₁ φ₂ a b comm ≫ map φ₂ φ₃ a' b' comm' := by ext n simp [ext_from_iff _ (n + 1) n rfl, map] /-- The morphism `triangle φ₁ ⟶ triangle φ₂` that is induced by a commutative square. -/ @[simps] noncomputable def triangleMap : triangle φ₁ ⟶ triangle φ₂ where hom₁ := a hom₂ := b hom₃ := map φ₁ φ₂ a b comm comm₁ := comm comm₂ := by dsimp rw [map_eq_mapOfHomotopy, triangleMapOfHomotopy_comm₂] comm₃ := by dsimp rw [map_eq_mapOfHomotopy, triangleMapOfHomotopy_comm₃] end map section Rotate /-- Given `φ : K ⟶ L`, `K⟦(1 : ℤ)⟧` is homotopy equivalent to the mapping cone of `inr φ : L ⟶ mappingCone φ`. -/ noncomputable def rotateHomotopyEquiv : HomotopyEquiv (K⟦(1 : ℤ)⟧) (mappingCone (inr φ)) where hom := lift (inr φ) (-(Cocycle.ofHom φ).leftShift 1 1 (zero_add 1)) (-(inl φ).leftShift 1 0 (neg_add_cancel 1)) (by -- the following list of lemmas has been obtained by doing -- simp? [Cochain.δ_leftShift _ 1 0 1 (neg_add_cancel 1) 0 (zero_add 1)] simp only [Int.reduceNeg, δ_neg, Cochain.δ_leftShift _ 1 0 1 (neg_add_cancel 1) 0 (zero_add 1), Int.negOnePow_one, δ_inl, Cochain.ofHom_comp, Cochain.leftShift_comp_zero_cochain, Units.neg_smul, one_smul, neg_neg, Cocycle.coe_neg, Cocycle.leftShift_coe, Cocycle.ofHom_coe, Cochain.neg_comp, add_neg_cancel]) inv := desc (inr φ) 0 (triangle φ).mor₃ (by simp only [δ_zero, inr_triangleδ, Cochain.ofHom_zero]) homotopyHomInvId := Homotopy.ofEq (by ext n -- the following list of lemmas has been obtained by doing -- simp? [lift_desc_f _ _ _ _ _ _ _ _ _ rfl, -- (inl φ).leftShift_v 1 0 _ _ n _ (n + 1) (by simp only [add_neg_cancel_right])] simp only [shiftFunctor_obj_X', Int.reduceNeg, HomologicalComplex.comp_f, lift_desc_f _ _ _ _ _ _ _ _ _ rfl, Cocycle.coe_neg, Cocycle.leftShift_coe, Cocycle.ofHom_coe, Cochain.neg_v, Cochain.zero_v, comp_zero, (inl φ).leftShift_v 1 0 _ _ n _ (n + 1) (by simp only [add_neg_cancel_right]), shiftFunctor_obj_X, mul_zero, sub_self, Int.zero_ediv, add_zero, Int.negOnePow_zero, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, id_comp, one_smul, Preadditive.neg_comp, inl_v_triangle_mor₃_f, Iso.refl_inv, neg_neg, zero_add, HomologicalComplex.id_f]) homotopyInvHomId := (Cochain.equivHomotopy _ _).symm ⟨-(snd (inr φ)).comp ((snd φ).comp (inl (inr φ)) (zero_add (-1))) (zero_add (-1)), by ext n -- the following list of lemmas has been obtained by doing -- simp? [ext_to_iff _ _ (n + 1) rfl, ext_from_iff _ (n + 1) _ rfl, -- δ_zero_cochain_comp _ _ _ (neg_add_cancel 1), -- (inl φ).leftShift_v 1 0 (neg_add_cancel 1) n n (add_zero n) (n + 1) (by omega), -- (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) n (n + 1) rfl (n + 1) (by omega), -- Cochain.comp_v _ _ (add_neg_cancel 1) n (n + 1) n rfl (by omega)] simp only [Int.reduceNeg, Cochain.ofHom_comp, ofHom_desc, ofHom_lift, Cocycle.coe_neg, Cocycle.leftShift_coe, Cocycle.ofHom_coe, Cochain.comp_zero_cochain_v, shiftFunctor_obj_X', δ_neg, δ_zero_cochain_comp _ _ _ (neg_add_cancel 1), δ_inl, Int.negOnePow_neg, Int.negOnePow_one, δ_snd, Cochain.neg_comp, Cochain.comp_assoc_of_second_is_zero_cochain, smul_neg, Units.neg_smul, one_smul, neg_neg, Cochain.comp_add, inr_snd_assoc, neg_add_rev, Cochain.add_v, Cochain.neg_v, Cochain.comp_v _ _ (add_neg_cancel 1) n (n + 1) n rfl (by omega), Cochain.zero_cochain_comp_v, Cochain.ofHom_v, HomologicalComplex.id_f, ext_to_iff _ _ (n + 1) rfl, assoc, liftCochain_v_fst_v, (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) n (n + 1) rfl (n + 1) (by omega), shiftFunctor_obj_X, mul_one, sub_self, mul_zero, Int.zero_ediv, add_zero, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, id_comp, Preadditive.add_comp, Preadditive.neg_comp, inl_v_fst_v, comp_id, inr_f_fst_v, comp_zero, neg_zero, neg_add_cancel_comm, ext_from_iff _ (n + 1) _ rfl, inl_v_descCochain_v_assoc, Cochain.zero_v, zero_comp, Preadditive.comp_neg, inl_v_snd_v_assoc, inr_f_descCochain_v_assoc, inr_f_snd_v_assoc, inl_v_triangle_mor₃_f_assoc, triangle_obj₁, Iso.refl_inv, inl_v_fst_v_assoc, inr_f_triangle_mor₃_f_assoc, inr_f_fst_v_assoc, and_self, liftCochain_v_snd_v, (inl φ).leftShift_v 1 0 (neg_add_cancel 1) n n (add_zero n) (n + 1) (by omega), Int.negOnePow_zero, inl_v_snd_v, inr_f_snd_v, zero_add, inl_v_descCochain_v, inr_f_descCochain_v, inl_v_triangle_mor₃_f, inr_f_triangle_mor₃_f, neg_add_cancel]⟩ /-- Auxiliary definition for `rotateTrianglehIso`. -/ noncomputable def rotateHomotopyEquivComm₂Homotopy : Homotopy ((triangle φ).mor₃ ≫ (rotateHomotopyEquiv φ).hom) (inr (CochainComplex.mappingCone.inr φ)) := (Cochain.equivHomotopy _ _).symm ⟨-(snd φ).comp (inl (inr φ)) (zero_add (-1)), by ext p dsimp [rotateHomotopyEquiv] -- the following list of lemmas has been obtained by doing -- simp? [ext_from_iff _ _ _ rfl, ext_to_iff _ _ _ rfl, -- (inl φ).leftShift_v 1 0 (neg_add_cancel 1) p p (add_zero p) (p + 1) (by omega), -- δ_zero_cochain_comp _ _ _ (neg_add_cancel 1), -- Cochain.comp_v _ _ (add_neg_cancel 1) p (p + 1) p rfl (by omega), -- (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by omega)]⟩ simp only [Int.reduceNeg, Cochain.ofHom_comp, ofHom_lift, Cocycle.coe_neg, Cocycle.leftShift_coe, Cocycle.ofHom_coe, Cochain.comp_zero_cochain_v, shiftFunctor_obj_X', Cochain.ofHom_v, δ_neg, δ_zero_cochain_comp _ _ _ (neg_add_cancel 1), δ_inl, Int.negOnePow_neg, Int.negOnePow_one, δ_snd, Cochain.neg_comp, Cochain.comp_assoc_of_second_is_zero_cochain, smul_neg, Units.neg_smul, one_smul, neg_neg, neg_add_rev, Cochain.add_v, Cochain.neg_v, Cochain.comp_v _ _ (add_neg_cancel 1) p (p + 1) p rfl (by cutsat), Cochain.zero_cochain_comp_v, ext_from_iff _ _ _ rfl, inl_v_triangle_mor₃_f_assoc, triangle_obj₁, shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, Preadditive.neg_comp, id_comp, Preadditive.comp_add, Preadditive.comp_neg, inl_v_fst_v_assoc, inl_v_snd_v_assoc, zero_comp, neg_zero, add_zero, ext_to_iff _ _ _ rfl, liftCochain_v_fst_v, (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by cutsat), mul_one, sub_self, mul_zero, Int.zero_ediv, Iso.refl_hom, Preadditive.add_comp, assoc, inl_v_fst_v, comp_id, inr_f_fst_v, comp_zero, liftCochain_v_snd_v, (inl φ).leftShift_v 1 0 (neg_add_cancel 1) p p (add_zero p) (p + 1) (by cutsat), Int.negOnePow_zero, inl_v_snd_v, inr_f_snd_v, zero_add, and_self, inr_f_triangle_mor₃_f_assoc, inr_f_fst_v_assoc, inr_f_snd_v_assoc, neg_add_cancel]⟩ @[reassoc (attr := simp)] lemma rotateHomotopyEquiv_comm₂ : (HomotopyCategory.quotient _ _ ).map (triangle φ).mor₃ ≫ (HomotopyCategory.quotient _ _ ).map (rotateHomotopyEquiv φ).hom = (HomotopyCategory.quotient _ _ ).map (inr (inr φ)) := by simpa only [Functor.map_comp] using HomotopyCategory.eq_of_homotopy _ _ (rotateHomotopyEquivComm₂Homotopy φ) @[reassoc (attr := simp)] lemma rotateHomotopyEquiv_comm₃ : (rotateHomotopyEquiv φ).hom ≫ (triangle (inr φ)).mor₃ = -φ⟦1⟧' := by ext p dsimp [rotateHomotopyEquiv] -- the following list of lemmas has been obtained by doing -- simp? [lift_f _ _ _ _ _ (p + 1) rfl, -- (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by omega)] simp only [Int.reduceNeg, lift_f _ _ _ _ _ (p + 1) rfl, shiftFunctor_obj_X', Cocycle.coe_neg, Cocycle.leftShift_coe, Cocycle.ofHom_coe, Cochain.neg_v, (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by cutsat), shiftFunctor_obj_X, mul_one, sub_self, mul_zero, Int.zero_ediv, add_zero, Int.negOnePow_one, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, Cochain.ofHom_v, id_comp, Units.neg_smul, one_smul, neg_neg, Preadditive.neg_comp, Preadditive.add_comp, assoc, inl_v_triangle_mor₃_f, Iso.refl_inv, Preadditive.comp_neg, comp_id, inr_f_triangle_mor₃_f, comp_zero, neg_zero] /-- The canonical isomorphism of triangles `(triangleh φ).rotate ≅ (triangleh (inr φ))`. -/ noncomputable def rotateTrianglehIso : (triangleh φ).rotate ≅ (triangleh (inr φ)) := Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (((HomotopyCategory.quotient C (ComplexShape.up ℤ)).commShiftIso (1 : ℤ)).symm.app K ≪≫ HomotopyCategory.isoOfHomotopyEquiv (rotateHomotopyEquiv φ)) (by simp) (by simp) (by dsimp rw [CategoryTheory.Functor.map_id, comp_id, assoc, ← Functor.map_comp_assoc, rotateHomotopyEquiv_comm₃, Functor.map_neg, Preadditive.neg_comp, Functor.commShiftIso_hom_naturality, Preadditive.comp_neg, Iso.inv_hom_id_app_assoc]) end Rotate section Shift /-- The canonical isomorphism `(mappingCone φ)⟦n⟧ ≅ mappingCone (φ⟦n⟧')`. -/ noncomputable def shiftIso (n : ℤ) : (mappingCone φ)⟦n⟧ ≅ mappingCone (φ⟦n⟧') where hom := lift _ (n.negOnePow • (fst φ).shift n) ((snd φ).shift n) (by ext p q hpq dsimp simp only [Cochain.δ_shift, δ_snd, Cochain.shift_neg, smul_neg, Cochain.neg_v, shiftFunctor_obj_X', Cochain.units_smul_v, Cochain.shift_v', Cochain.comp_zero_cochain_v, Cochain.ofHom_v, Cochain.units_smul_comp, shiftFunctor_map_f', neg_add_cancel]) inv := desc _ (n.negOnePow • (inl φ).shift n) ((inr φ)⟦n⟧') (by ext p dsimp simp only [Int.reduceNeg, δ_units_smul, Cochain.δ_shift, δ_inl, Cochain.ofHom_comp, smul_smul, Int.units_mul_self, one_smul, Cochain.shift_v', Cochain.comp_zero_cochain_v, Cochain.ofHom_v, shiftFunctor_obj_X', shiftFunctor_map_f']) hom_inv_id := by ext p dsimp simp only [Int.reduceNeg, lift_desc_f _ _ _ _ _ _ _ _ (p + 1) rfl, shiftFunctor_obj_X', Cocycle.coe_units_smul, Cocycle.shift_coe, Cochain.units_smul_v, Cochain.shift_v', Linear.comp_units_smul, Linear.units_smul_comp, smul_smul, Int.units_mul_self, one_smul, shiftFunctor_map_f', id_X] inv_hom_id := by ext p dsimp simp only [Int.reduceNeg, ext_from_iff _ (p + 1) _ rfl, shiftFunctor_obj_X', inl_v_desc_f_assoc, Cochain.units_smul_v, Cochain.shift_v', Linear.units_smul_comp, comp_id, ext_to_iff _ _ (p + 1) rfl, assoc, lift_f_fst_v, Cocycle.coe_units_smul, Cocycle.shift_coe, Linear.comp_units_smul, inl_v_fst_v, smul_smul, Int.units_mul_self, one_smul, lift_f_snd_v, inl_v_snd_v, smul_zero, and_self, inr_f_desc_f_assoc, shiftFunctor_map_f', inr_f_fst_v, inr_f_snd_v] /-- The canonical isomorphism `(triangle φ)⟦n⟧ ≅ triangle (φ⟦n⟧')`. -/ noncomputable def shiftTriangleIso (n : ℤ) : (Triangle.shiftFunctor _ n).obj (triangle φ) ≅ triangle (φ⟦n⟧') := by refine Triangle.isoMk _ _ (Iso.refl _) (n.negOnePow • Iso.refl _) (shiftIso φ n) ?_ ?_ ?_ · dsimp simp only [Linear.comp_units_smul, comp_id, id_comp, smul_smul, Int.units_mul_self, one_smul] · ext p dsimp simp only [Units.smul_def, shiftIso, Int.reduceNeg, Linear.smul_comp, id_comp, ext_to_iff _ _ (p + 1) rfl, shiftFunctor_obj_X', assoc, lift_f_fst_v, Cocycle.coe_smul, Cocycle.shift_coe, Cochain.smul_v, Cochain.shift_v', Linear.comp_smul, inr_f_fst_v, smul_zero, lift_f_snd_v, inr_f_snd_v, and_true] · ext p dsimp simp only [triangle, Triangle.mk_mor₃, Cocycle.homOf_f, Cocycle.rightShift_coe, Cocycle.coe_neg, Cochain.rightShift_neg, Cochain.neg_v, shiftFunctor_obj_X', (fst φ).1.rightShift_v 1 0 (zero_add 1) (p + n) (p + n) (add_zero (p + n)) (p + 1 + n) (by cutsat), shiftFunctor_obj_X, shiftFunctorObjXIso, shiftFunctorComm_hom_app_f, Preadditive.neg_comp, assoc, Iso.inv_hom_id, comp_id, smul_neg, Units.smul_def, shiftIso, Int.reduceNeg, (fst (φ⟦n⟧')).1.rightShift_v 1 0 (zero_add 1) p p (add_zero p) (p + 1) rfl, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, Preadditive.comp_neg, lift_f_fst_v, Cocycle.coe_smul, Cocycle.shift_coe, Cochain.smul_v, Cochain.shift_v'] /-- The canonical isomorphism `(triangleh φ)⟦n⟧ ≅ triangleh (φ⟦n⟧')`. -/ noncomputable def shiftTrianglehIso (n : ℤ) : (Triangle.shiftFunctor _ n).obj (triangleh φ) ≅ triangleh (φ⟦n⟧') := ((HomotopyCategory.quotient _ _).mapTriangle.commShiftIso n).symm.app _ ≪≫ (HomotopyCategory.quotient _ _).mapTriangle.mapIso (shiftTriangleIso φ n) end Shift section open Preadditive variable (G : C ⥤ D) [G.Additive] lemma map_δ : (G.mapHomologicalComplex (ComplexShape.up ℤ)).map (triangle φ).mor₃ ≫ NatTrans.app ((Functor.mapHomologicalComplex G (ComplexShape.up ℤ)).commShiftIso 1).hom K = (mapHomologicalComplexIso φ G).hom ≫ (triangle ((G.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)).mor₃ := by ext n dsimp [mapHomologicalComplexIso] rw [mapHomologicalComplexXIso_eq φ G n (n + 1) rfl, mapHomologicalComplexXIso'_hom] simp only [Functor.mapHomologicalComplex_obj_X, add_comp, assoc, inl_v_triangle_mor₃_f, shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, comp_neg, comp_id, inr_f_triangle_mor₃_f, comp_zero, add_zero] dsimp [triangle] rw [Cochain.rightShift_v _ 1 0 (by cutsat) n n (by cutsat) (n + 1) (by cutsat)] simp only [shiftFunctor_obj_X, Cochain.neg_v, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, comp_id, Functor.map_neg] /-- If `φ : K ⟶ L` is a morphism of cochain complexes in `C` and `G : C ⥤ D` is an additive functor, then the image by `G` of the triangle `triangle φ` identifies to the triangle associated to the image of `φ` by `G`. -/ noncomputable def mapTriangleIso : (G.mapHomologicalComplex (ComplexShape.up ℤ)).mapTriangle.obj (triangle φ) ≅ triangle ((G.mapHomologicalComplex (ComplexShape.up ℤ)).map φ) := by refine Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (mapHomologicalComplexIso φ G) ?_ ?_ ?_ · dsimp simp only [comp_id, id_comp] · dsimp rw [map_inr, id_comp] · dsimp simp only [CategoryTheory.Functor.map_id, comp_id, map_δ] /-- If `φ : K ⟶ L` is a morphism of cochain complexes in `C` and `G : C ⥤ D` is an additive functor, then the image by `G` of the triangle `triangleh φ` identifies to the triangle associated to the image of `φ` by `G`. -/ noncomputable def mapTrianglehIso : (G.mapHomotopyCategory (ComplexShape.up ℤ)).mapTriangle.obj (triangleh φ) ≅ triangleh ((G.mapHomologicalComplex (ComplexShape.up ℤ)).map φ) := (Functor.mapTriangleCompIso _ _).symm.app _ ≪≫ (Functor.mapTriangleIso (G.mapHomotopyCategoryFactors (ComplexShape.up ℤ))).app _ ≪≫ (Functor.mapTriangleCompIso _ _).app _ ≪≫ (HomotopyCategory.quotient D (ComplexShape.up ℤ)).mapTriangle.mapIso (CochainComplex.mappingCone.mapTriangleIso φ G) end end mappingCone end CochainComplex namespace HomotopyCategory variable (C) namespace Pretriangulated /-- A triangle in `HomotopyCategory C (ComplexShape.up ℤ)` is distinguished if it is isomorphic to the triangle `CochainComplex.mappingCone.triangleh φ` for some morphism of cochain complexes `φ`. -/ def distinguishedTriangles : Set (Triangle (HomotopyCategory C (ComplexShape.up ℤ))) := fun T => ∃ (X Y : CochainComplex C ℤ) (φ : X ⟶ Y), Nonempty (T ≅ CochainComplex.mappingCone.triangleh φ) variable {C} lemma isomorphic_distinguished (T₁ : Triangle (HomotopyCategory C (ComplexShape.up ℤ))) (hT₁ : T₁ ∈ distinguishedTriangles C) (T₂ : Triangle (HomotopyCategory C (ComplexShape.up ℤ))) (e : T₂ ≅ T₁) : T₂ ∈ distinguishedTriangles C := by obtain ⟨X, Y, f, ⟨e'⟩⟩ := hT₁ exact ⟨X, Y, f, ⟨e ≪≫ e'⟩⟩ variable [HasZeroObject C] in lemma contractible_distinguished (X : HomotopyCategory C (ComplexShape.up ℤ)) : Pretriangulated.contractibleTriangle X ∈ distinguishedTriangles C := by obtain ⟨X⟩ := X refine ⟨_, _, 𝟙 X, ⟨?_⟩⟩ have h := (isZero_quotient_obj_iff _).2 ⟨CochainComplex.mappingCone.homotopyToZeroOfId X⟩ exact Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) h.isoZero.symm (by simp) (h.eq_of_tgt _ _) (by dsimp; ext) lemma distinguished_cocone_triangle {X Y : HomotopyCategory C (ComplexShape.up ℤ)} (f : X ⟶ Y) : ∃ (Z : HomotopyCategory C (ComplexShape.up ℤ)) (g : Y ⟶ Z) (h : Z ⟶ X⟦1⟧), Triangle.mk f g h ∈ distinguishedTriangles C := by obtain ⟨f, rfl⟩ := (quotient _ _).map_surjective f exact ⟨_, _, _, ⟨_, _, f, ⟨Iso.refl _⟩⟩⟩ lemma rotate_distinguished_triangle' (T : Triangle (HomotopyCategory C (ComplexShape.up ℤ))) (hT : T ∈ distinguishedTriangles C) : T.rotate ∈ distinguishedTriangles C := by obtain ⟨K, L, φ, ⟨e⟩⟩ := hT exact ⟨_, _, _, ⟨(rotate _).mapIso e ≪≫ CochainComplex.mappingCone.rotateTrianglehIso φ⟩⟩ lemma shift_distinguished_triangle (T : Triangle (HomotopyCategory C (ComplexShape.up ℤ))) (hT : T ∈ distinguishedTriangles C) (n : ℤ) : (Triangle.shiftFunctor _ n).obj T ∈ distinguishedTriangles C := by obtain ⟨K, L, φ, ⟨e⟩⟩ := hT exact ⟨_, _, _, ⟨Functor.mapIso _ e ≪≫ CochainComplex.mappingCone.shiftTrianglehIso φ n⟩⟩ lemma invRotate_distinguished_triangle' (T : Triangle (HomotopyCategory C (ComplexShape.up ℤ))) (hT : T ∈ distinguishedTriangles C) : T.invRotate ∈ distinguishedTriangles C := isomorphic_distinguished _ (shift_distinguished_triangle _ (rotate_distinguished_triangle' _ (rotate_distinguished_triangle' _ hT)) _) _ ((invRotateIsoRotateRotateShiftFunctorNegOne _).app T) lemma rotate_distinguished_triangle (T : Triangle (HomotopyCategory C (ComplexShape.up ℤ))) : T ∈ distinguishedTriangles C ↔ T.rotate ∈ distinguishedTriangles C := by constructor · exact rotate_distinguished_triangle' T · intro hT exact isomorphic_distinguished _ (invRotate_distinguished_triangle' T.rotate hT) _ ((triangleRotation _).unitIso.app T) open CochainComplex.mappingCone in lemma complete_distinguished_triangle_morphism (T₁ T₂ : Triangle (HomotopyCategory C (ComplexShape.up ℤ))) (hT₁ : T₁ ∈ distinguishedTriangles C) (hT₂ : T₂ ∈ distinguishedTriangles C) (a : T₁.obj₁ ⟶ T₂.obj₁) (b : T₁.obj₂ ⟶ T₂.obj₂) (fac : T₁.mor₁ ≫ b = a ≫ T₂.mor₁) : ∃ (c : T₁.obj₃ ⟶ T₂.obj₃), T₁.mor₂ ≫ c = b ≫ T₂.mor₂ ∧ T₁.mor₃ ≫ a⟦(1 : ℤ)⟧' = c ≫ T₂.mor₃ := by obtain ⟨K₁, L₁, φ₁, ⟨e₁⟩⟩ := hT₁ obtain ⟨K₂, L₂, φ₂, ⟨e₂⟩⟩ := hT₂ obtain ⟨a', ha'⟩ : ∃ (a' : (quotient _ _).obj K₁ ⟶ (quotient _ _).obj K₂), a' = e₁.inv.hom₁ ≫ a ≫ e₂.hom.hom₁ := ⟨_, rfl⟩ obtain ⟨b', hb'⟩ : ∃ (b' : (quotient _ _).obj L₁ ⟶ (quotient _ _).obj L₂), b' = e₁.inv.hom₂ ≫ b ≫ e₂.hom.hom₂ := ⟨_, rfl⟩ obtain ⟨a'', rfl⟩ := (quotient _ _).map_surjective a' obtain ⟨b'', rfl⟩ := (quotient _ _).map_surjective b' have H : Homotopy (φ₁ ≫ b'') (a'' ≫ φ₂) := homotopyOfEq _ _ (by have comm₁₁ := e₁.inv.comm₁ have comm₁₂ := e₂.hom.comm₁ dsimp at comm₁₁ comm₁₂ simp only [Functor.map_comp, ha', hb', reassoc_of% comm₁₁, reassoc_of% fac, comm₁₂, assoc]) let γ := e₁.hom ≫ trianglehMapOfHomotopy H ≫ e₂.inv have comm₂ := γ.comm₂ have comm₃ := γ.comm₃ dsimp [γ] at comm₂ comm₃ simp only [ha', hb'] at comm₂ comm₃ refine ⟨γ.hom₃, ?_, ?_⟩ -- the following list of lemmas was obtained by doing simpa? [γ] using comm₂ · simpa only [triangleCategory_comp, Functor.mapTriangle_obj, triangle_obj₁, triangle_obj₂, triangle_obj₃, triangle_mor₁, triangle_mor₂, TriangleMorphism.comp_hom₃, Triangle.mk_obj₃, trianglehMapOfHomotopy_hom₃, TriangleMorphism.comm₂_assoc, Triangle.mk_obj₂, Triangle.mk_mor₂, assoc, Iso.hom_inv_id_triangle_hom₂, comp_id, Iso.hom_inv_id_triangle_hom₂_assoc, γ] using comm₂ -- the following list of lemmas was obtained by doing simpa? [γ] using comm₃ · simpa only [triangleCategory_comp, Functor.mapTriangle_obj, triangle_obj₁, triangle_obj₂, triangle_obj₃, triangle_mor₁, triangle_mor₂, TriangleMorphism.comp_hom₃, Triangle.mk_obj₃, trianglehMapOfHomotopy_hom₃, assoc, Triangle.mk_obj₁, Iso.hom_inv_id_triangle_hom₁, comp_id, Iso.hom_inv_id_triangle_hom₁_assoc, γ] using comm₃ end Pretriangulated variable [HasZeroObject C] noncomputable instance : Pretriangulated (HomotopyCategory C (ComplexShape.up ℤ)) where distinguishedTriangles := Pretriangulated.distinguishedTriangles C isomorphic_distinguished := Pretriangulated.isomorphic_distinguished contractible_distinguished := Pretriangulated.contractible_distinguished distinguished_cocone_triangle := Pretriangulated.distinguished_cocone_triangle rotate_distinguished_triangle := Pretriangulated.rotate_distinguished_triangle complete_distinguished_triangle_morphism := Pretriangulated.complete_distinguished_triangle_morphism variable {C} lemma mappingCone_triangleh_distinguished {X Y : CochainComplex C ℤ} (f : X ⟶ Y) : CochainComplex.mappingCone.triangleh f ∈ distTriang (HomotopyCategory _ _) := ⟨_, _, f, ⟨Iso.refl _⟩⟩ variable [HasZeroObject D] instance (G : C ⥤ D) [G.Additive] : (G.mapHomotopyCategory (ComplexShape.up ℤ)).IsTriangulated where map_distinguished := by rintro T ⟨K, L, f, ⟨e⟩⟩ exact ⟨_, _, _, ⟨(G.mapHomotopyCategory (ComplexShape.up ℤ)).mapTriangle.mapIso e ≪≫ CochainComplex.mappingCone.mapTrianglehIso f G⟩⟩ end HomotopyCategory
.lake/packages/mathlib/Mathlib/Algebra/Jordan/Basic.lean
import Mathlib.Algebra.Lie.OfAssociative /-! # Jordan rings Let `A` be a non-unital, non-associative ring. Then `A` is said to be a (commutative, linear) Jordan ring if the multiplication is commutative and satisfies a weak associativity law known as the Jordan Identity: for all `a` and `b` in `A`, ``` (a * b) * a^2 = a * (b * a^2) ``` i.e. the operators of multiplication by `a` and `a^2` commute. A more general concept of a (non-commutative) Jordan ring can also be defined, as a (non-commutative, non-associative) ring `A` where, for each `a` in `A`, the operators of left and right multiplication by `a` and `a^2` commute. Every associative algebra can be equipped with a symmetrized multiplication (characterized by `SymAlg.sym_mul_sym`) making it into a commutative Jordan algebra (`IsCommJordan`). Jordan algebras arising this way are said to be special. A real Jordan algebra `A` can be introduced by ```lean variable {A : Type*} [NonUnitalNonAssocCommRing A] [Module ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] [IsCommJordan A] ``` ## Main results - `two_nsmul_lie_lmul_lmul_add_add_eq_zero` : Linearisation of the commutative Jordan axiom ## Implementation notes We shall primarily be interested in linear Jordan algebras (i.e. over rings of characteristic not two) leaving quadratic algebras to those better versed in that theory. The conventional way to linearise the Jordan axiom is to equate coefficients (more formally, assume that the axiom holds in all field extensions). For simplicity we use brute force algebraic expansion and substitution instead. ## Motivation Every Jordan algebra `A` has a triple product defined, for `a` `b` and `c` in `A` by $$ {a\,b\,c} = (a * b) * c - (a * c) * b + a * (b * c). $$ Via this triple product Jordan algebras are related to a number of other mathematical structures: Jordan triples, partial Jordan triples, Jordan pairs and quadratic Jordan algebras. In addition to their considerable algebraic interest ([mccrimmon2004]) these structures have been shown to have deep connections to mathematical physics, functional analysis and differential geometry. For more information about these connections the interested reader is referred to [alfsenshultz2003], [chu2012], [friedmanscarr2005], [iordanescu2003] and [upmeier1987]. There are also exceptional Jordan algebras which can be shown not to be the symmetrization of any associative algebra. The 3x3 matrices of octonions is the canonical example. Non-commutative Jordan algebras have connections to the Vidav-Palmer theorem [cabreragarciarodriguezpalacios2014]. ## References * [Cabrera García and Rodríguez Palacios, Non-associative normed algebras. Volume 1] [cabreragarciarodriguezpalacios2014] * [Hanche-Olsen and Størmer, Jordan Operator Algebras][hancheolsenstormer1984] * [McCrimmon, A taste of Jordan algebras][mccrimmon2004] -/ variable (A : Type*) /-- A (non-commutative) Jordan multiplication. -/ class IsJordan [Mul A] : Prop where lmul_comm_rmul : ∀ a b : A, a * b * a = a * (b * a) lmul_lmul_comm_lmul : ∀ a b : A, a * a * (a * b) = a * (a * a * b) lmul_lmul_comm_rmul : ∀ a b : A, a * a * (b * a) = a * a * b * a lmul_comm_rmul_rmul : ∀ a b : A, a * b * (a * a) = a * (b * (a * a)) rmul_comm_rmul_rmul : ∀ a b : A, b * a * (a * a) = b * (a * a) * a /-- A commutative Jordan multiplication -/ class IsCommJordan [CommMagma A] : Prop where lmul_comm_rmul_rmul : ∀ a b : A, a * b * (a * a) = a * (b * (a * a)) -- see Note [lower instance priority] /-- A (commutative) Jordan multiplication is also a Jordan multiplication -/ instance (priority := 100) IsCommJordan.toIsJordan [CommMagma A] [IsCommJordan A] : IsJordan A where lmul_comm_rmul a b := by rw [mul_comm, mul_comm a b] lmul_lmul_comm_lmul a b := by rw [mul_comm (a * a) (a * b), IsCommJordan.lmul_comm_rmul_rmul, mul_comm b (a * a)] lmul_comm_rmul_rmul := IsCommJordan.lmul_comm_rmul_rmul lmul_lmul_comm_rmul a b := by rw [mul_comm (a * a) (b * a), mul_comm b a, IsCommJordan.lmul_comm_rmul_rmul, mul_comm, mul_comm b (a * a)] rmul_comm_rmul_rmul a b := by rw [mul_comm b a, IsCommJordan.lmul_comm_rmul_rmul, mul_comm] -- see Note [lower instance priority] /-- Semigroup multiplication satisfies the (non-commutative) Jordan axioms -/ instance (priority := 100) Semigroup.isJordan [Semigroup A] : IsJordan A where lmul_comm_rmul a b := by rw [mul_assoc] lmul_lmul_comm_lmul a b := by rw [mul_assoc, mul_assoc] lmul_comm_rmul_rmul a b := by rw [mul_assoc] lmul_lmul_comm_rmul a b := by rw [← mul_assoc] rmul_comm_rmul_rmul a b := by rw [← mul_assoc, ← mul_assoc] -- see Note [lower instance priority] instance (priority := 100) CommSemigroup.isCommJordan [CommSemigroup A] : IsCommJordan A where lmul_comm_rmul_rmul _ _ := mul_assoc _ _ _ local notation "L" => AddMonoid.End.mulLeft local notation "R" => AddMonoid.End.mulRight /-! The Jordan axioms can be expressed in terms of commuting multiplication operators. -/ section Commute variable {A} [NonUnitalNonAssocRing A] [IsJordan A] @[simp] theorem commute_lmul_rmul (a : A) : Commute (L a) (R a) := AddMonoidHom.ext fun _ => (IsJordan.lmul_comm_rmul _ _).symm @[simp] theorem commute_lmul_lmul_sq (a : A) : Commute (L a) (L (a * a)) := AddMonoidHom.ext fun _ => (IsJordan.lmul_lmul_comm_lmul _ _).symm @[simp] theorem commute_lmul_rmul_sq (a : A) : Commute (L a) (R (a * a)) := AddMonoidHom.ext fun _ => (IsJordan.lmul_comm_rmul_rmul _ _).symm @[simp] theorem commute_lmul_sq_rmul (a : A) : Commute (L (a * a)) (R a) := AddMonoidHom.ext fun _ => IsJordan.lmul_lmul_comm_rmul _ _ @[simp] theorem commute_rmul_rmul_sq (a : A) : Commute (R a) (R (a * a)) := AddMonoidHom.ext fun _ => (IsJordan.rmul_comm_rmul_rmul _ _).symm end Commute variable {A} [NonUnitalNonAssocCommRing A] /-! The endomorphisms on an additive monoid `AddMonoid.End` form a `Ring`, and this may be equipped with a Lie Bracket via `Ring.bracket`. -/ theorem two_nsmul_lie_lmul_lmul_add_eq_lie_lmul_lmul_add [IsCommJordan A] (a b : A) : 2 • (⁅L a, L (a * b)⁆ + ⁅L b, L (b * a)⁆) = ⁅L (a * a), L b⁆ + ⁅L (b * b), L a⁆ := by suffices 2 • ⁅L a, L (a * b)⁆ + 2 • ⁅L b, L (b * a)⁆ + ⁅L b, L (a * a)⁆ + ⁅L a, L (b * b)⁆ = 0 by rwa [← sub_eq_zero, ← sub_sub, sub_eq_add_neg, sub_eq_add_neg, lie_skew, lie_skew, nsmul_add] convert (commute_lmul_lmul_sq (a + b)).lie_eq using 1 simp only [add_mul, mul_add, map_add, lie_add, add_lie, mul_comm b a, (commute_lmul_lmul_sq a).lie_eq, (commute_lmul_lmul_sq b).lie_eq, zero_add, add_zero, two_smul] abel -- Porting note: the monolithic `calc`-based proof of `two_nsmul_lie_lmul_lmul_add_add_eq_zero` -- has had four auxiliary parts `aux{0,1,2,3}` split off from it. private theorem aux0 {a b c : A} : ⁅L (a + b + c), L ((a + b + c) * (a + b + c))⁆ = ⁅L a + L b + L c, L (a * a) + L (b * b) + L (c * c) + 2 • L (a * b) + 2 • L (c * a) + 2 • L (b * c)⁆ := by rw [add_mul, add_mul] iterate 6 rw [mul_add] iterate 10 rw [map_add] rw [mul_comm b a, mul_comm c a, mul_comm c b] iterate 3 rw [two_smul] simp only [lie_add, add_lie] abel private theorem aux1 {a b c : A} : ⁅L a + L b + L c, L (a * a) + L (b * b) + L (c * c) + 2 • L (a * b) + 2 • L (c * a) + 2 • L (b * c)⁆ = ⁅L a, L (a * a)⁆ + ⁅L a, L (b * b)⁆ + ⁅L a, L (c * c)⁆ + ⁅L a, 2 • L (a * b)⁆ + ⁅L a, 2 • L (c * a)⁆ + ⁅L a, 2 • L (b * c)⁆ + (⁅L b, L (a * a)⁆ + ⁅L b, L (b * b)⁆ + ⁅L b, L (c * c)⁆ + ⁅L b, 2 • L (a * b)⁆ + ⁅L b, 2 • L (c * a)⁆ + ⁅L b, 2 • L (b * c)⁆) + (⁅L c, L (a * a)⁆ + ⁅L c, L (b * b)⁆ + ⁅L c, L (c * c)⁆ + ⁅L c, 2 • L (a * b)⁆ + ⁅L c, 2 • L (c * a)⁆ + ⁅L c, 2 • L (b * c)⁆) := by rw [add_lie, add_lie] iterate 15 rw [lie_add] variable [IsCommJordan A] private theorem aux2 {a b c : A} : ⁅L a, L (a * a)⁆ + ⁅L a, L (b * b)⁆ + ⁅L a, L (c * c)⁆ + ⁅L a, 2 • L (a * b)⁆ + ⁅L a, 2 • L (c * a)⁆ + ⁅L a, 2 • L (b * c)⁆ + (⁅L b, L (a * a)⁆ + ⁅L b, L (b * b)⁆ + ⁅L b, L (c * c)⁆ + ⁅L b, 2 • L (a * b)⁆ + ⁅L b, 2 • L (c * a)⁆ + ⁅L b, 2 • L (b * c)⁆) + (⁅L c, L (a * a)⁆ + ⁅L c, L (b * b)⁆ + ⁅L c, L (c * c)⁆ + ⁅L c, 2 • L (a * b)⁆ + ⁅L c, 2 • L (c * a)⁆ + ⁅L c, 2 • L (b * c)⁆) = ⁅L a, L (b * b)⁆ + ⁅L b, L (a * a)⁆ + 2 • (⁅L a, L (a * b)⁆ + ⁅L b, L (a * b)⁆) + (⁅L a, L (c * c)⁆ + ⁅L c, L (a * a)⁆ + 2 • (⁅L a, L (c * a)⁆ + ⁅L c, L (c * a)⁆)) + (⁅L b, L (c * c)⁆ + ⁅L c, L (b * b)⁆ + 2 • (⁅L b, L (b * c)⁆ + ⁅L c, L (b * c)⁆)) + (2 • ⁅L a, L (b * c)⁆ + 2 • ⁅L b, L (c * a)⁆ + 2 • ⁅L c, L (a * b)⁆) := by rw [(commute_lmul_lmul_sq a).lie_eq, (commute_lmul_lmul_sq b).lie_eq, (commute_lmul_lmul_sq c).lie_eq, zero_add, add_zero, add_zero] simp only [lie_nsmul] abel private theorem aux3 {a b c : A} : ⁅L a, L (b * b)⁆ + ⁅L b, L (a * a)⁆ + 2 • (⁅L a, L (a * b)⁆ + ⁅L b, L (a * b)⁆) + (⁅L a, L (c * c)⁆ + ⁅L c, L (a * a)⁆ + 2 • (⁅L a, L (c * a)⁆ + ⁅L c, L (c * a)⁆)) + (⁅L b, L (c * c)⁆ + ⁅L c, L (b * b)⁆ + 2 • (⁅L b, L (b * c)⁆ + ⁅L c, L (b * c)⁆)) + (2 • ⁅L a, L (b * c)⁆ + 2 • ⁅L b, L (c * a)⁆ + 2 • ⁅L c, L (a * b)⁆) = 2 • ⁅L a, L (b * c)⁆ + 2 • ⁅L b, L (c * a)⁆ + 2 • ⁅L c, L (a * b)⁆ := by rw [add_eq_right] nth_rw 2 [mul_comm a b] nth_rw 1 [mul_comm c a] nth_rw 2 [mul_comm b c] iterate 3 rw [two_nsmul_lie_lmul_lmul_add_eq_lie_lmul_lmul_add] iterate 2 rw [← lie_skew (L (a * a)), ← lie_skew (L (b * b)), ← lie_skew (L (c * c))] abel theorem two_nsmul_lie_lmul_lmul_add_add_eq_zero (a b c : A) : 2 • (⁅L a, L (b * c)⁆ + ⁅L b, L (c * a)⁆ + ⁅L c, L (a * b)⁆) = 0 := by symm calc 0 = ⁅L (a + b + c), L ((a + b + c) * (a + b + c))⁆ := by rw [(commute_lmul_lmul_sq (a + b + c)).lie_eq] _ = _ := by rw [aux0, aux1, aux2, aux3, nsmul_add, nsmul_add]
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Opposite.lean
import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Module.Opposite import Mathlib.Algebra.Ring.Opposite /-! # Algebra structures on the multiplicative opposite ## Main definitions * `MulOpposite.instAlgebra`: the algebra on `Aᵐᵒᵖ` * `AlgHom.op`/`AlgHom.unop`: simultaneously convert the domain and codomain of a morphism to the opposite algebra. * `AlgHom.opComm`: swap which side of a morphism lies in the opposite algebra. * `AlgEquiv.op`/`AlgEquiv.unop`: simultaneously convert the source and target of an isomorphism to the opposite algebra. * `AlgEquiv.opOp`: any algebra is isomorphic to the opposite of its opposite. * `AlgEquiv.toOpposite`: in a commutative algebra, the opposite algebra is isomorphic to the original algebra. * `AlgEquiv.opComm`: swap which side of an isomorphism lies in the opposite algebra. -/ variable {R S A B : Type*} open MulOpposite section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra R B] [Algebra S A] [SMulCommClass R S A] variable [IsScalarTower R S A] namespace MulOpposite instance instAlgebra : Algebra R Aᵐᵒᵖ where algebraMap := (algebraMap R A).toOpposite fun _ _ => Algebra.commutes _ _ smul_def' c x := unop_injective <| by simp only [unop_smul, RingHom.toOpposite_apply, Function.comp_apply, unop_mul, Algebra.smul_def, Algebra.commutes, unop_op] commutes' r := MulOpposite.rec' fun x => by simp only [RingHom.toOpposite_apply, Function.comp_apply, ← op_mul, Algebra.commutes] @[simp] theorem algebraMap_apply (c : R) : algebraMap R Aᵐᵒᵖ c = op (algebraMap R A c) := rfl end MulOpposite namespace AlgEquiv variable (R A) /-- An algebra is isomorphic to the opposite of its opposite. -/ @[simps!] def opOp : A ≃ₐ[R] Aᵐᵒᵖᵐᵒᵖ where __ := RingEquiv.opOp A commutes' _ := rfl @[simp] theorem toRingEquiv_opOp : (opOp R A : A ≃+* Aᵐᵒᵖᵐᵒᵖ) = RingEquiv.opOp A := rfl end AlgEquiv namespace AlgHom /-- An algebra homomorphism `f : A →ₐ[R] B` such that `f x` commutes with `f y` for all `x, y` defines an algebra homomorphism from `Aᵐᵒᵖ`. -/ @[simps -fullyApplied] def fromOpposite (f : A →ₐ[R] B) (hf : ∀ x y, Commute (f x) (f y)) : Aᵐᵒᵖ →ₐ[R] B := { f.toRingHom.fromOpposite hf with toFun := f ∘ unop commutes' := fun r => f.commutes r } @[simp] theorem toLinearMap_fromOpposite (f : A →ₐ[R] B) (hf : ∀ x y, Commute (f x) (f y)) : (f.fromOpposite hf).toLinearMap = f.toLinearMap ∘ₗ (opLinearEquiv R (M := A)).symm := rfl @[simp] theorem toRingHom_fromOpposite (f : A →ₐ[R] B) (hf : ∀ x y, Commute (f x) (f y)) : (f.fromOpposite hf : Aᵐᵒᵖ →+* B) = (f : A →+* B).fromOpposite hf := rfl /-- An algebra homomorphism `f : A →ₐ[R] B` such that `f x` commutes with `f y` for all `x, y` defines an algebra homomorphism to `Bᵐᵒᵖ`. -/ @[simps -fullyApplied] def toOpposite (f : A →ₐ[R] B) (hf : ∀ x y, Commute (f x) (f y)) : A →ₐ[R] Bᵐᵒᵖ := { f.toRingHom.toOpposite hf with toFun := op ∘ f commutes' := fun r => unop_injective <| f.commutes r } @[simp] theorem toLinearMap_toOpposite (f : A →ₐ[R] B) (hf : ∀ x y, Commute (f x) (f y)) : (f.toOpposite hf).toLinearMap = (opLinearEquiv R : B ≃ₗ[R] Bᵐᵒᵖ) ∘ₗ f.toLinearMap := rfl @[simp] theorem toRingHom_toOpposite (f : A →ₐ[R] B) (hf : ∀ x y, Commute (f x) (f y)) : (f.toOpposite hf : A →+* Bᵐᵒᵖ) = (f : A →+* B).toOpposite hf := rfl /-- An algebra hom `A →ₐ[R] B` can equivalently be viewed as an algebra hom `Aᵐᵒᵖ →ₐ[R] Bᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/ @[simps!] protected def op : (A →ₐ[R] B) ≃ (Aᵐᵒᵖ →ₐ[R] Bᵐᵒᵖ) where toFun f := { RingHom.op f.toRingHom with commutes' := fun r => unop_injective <| f.commutes r } invFun f := { RingHom.unop f.toRingHom with commutes' := fun r => op_injective <| f.commutes r } theorem toRingHom_op (f : A →ₐ[R] B) : f.op.toRingHom = RingHom.op f.toRingHom := rfl /-- The 'unopposite' of an algebra hom `Aᵐᵒᵖ →ₐ[R] Bᵐᵒᵖ`. Inverse to `RingHom.op`. -/ abbrev unop : (Aᵐᵒᵖ →ₐ[R] Bᵐᵒᵖ) ≃ (A →ₐ[R] B) := AlgHom.op.symm theorem toRingHom_unop (f : Aᵐᵒᵖ →ₐ[R] Bᵐᵒᵖ) : f.unop.toRingHom = RingHom.unop f.toRingHom := rfl /-- Swap the `ᵐᵒᵖ` on an algebra hom to the opposite side. -/ @[simps!] def opComm : (A →ₐ[R] Bᵐᵒᵖ) ≃ (Aᵐᵒᵖ →ₐ[R] B) := AlgHom.op.trans <| AlgEquiv.refl.arrowCongr (AlgEquiv.opOp R B).symm end AlgHom namespace AlgEquiv /-- An algebra iso `A ≃ₐ[R] B` can equivalently be viewed as an algebra iso `Aᵐᵒᵖ ≃ₐ[R] Bᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/ @[simps!] def op : (A ≃ₐ[R] B) ≃ Aᵐᵒᵖ ≃ₐ[R] Bᵐᵒᵖ where toFun f := { RingEquiv.op f.toRingEquiv with commutes' := fun r => MulOpposite.unop_injective <| f.commutes r } invFun f := { RingEquiv.unop f.toRingEquiv with commutes' := fun r => MulOpposite.op_injective <| f.commutes r } theorem toAlgHom_op (f : A ≃ₐ[R] B) : (AlgEquiv.op f).toAlgHom = AlgHom.op f.toAlgHom := rfl theorem toRingEquiv_op (f : A ≃ₐ[R] B) : (AlgEquiv.op f).toRingEquiv = RingEquiv.op f.toRingEquiv := rfl /-- The 'unopposite' of an algebra iso `Aᵐᵒᵖ ≃ₐ[R] Bᵐᵒᵖ`. Inverse to `AlgEquiv.op`. -/ abbrev unop : (Aᵐᵒᵖ ≃ₐ[R] Bᵐᵒᵖ) ≃ A ≃ₐ[R] B := AlgEquiv.op.symm theorem toAlgHom_unop (f : Aᵐᵒᵖ ≃ₐ[R] Bᵐᵒᵖ) : f.unop.toAlgHom = AlgHom.unop f.toAlgHom := rfl theorem toRingEquiv_unop (f : Aᵐᵒᵖ ≃ₐ[R] Bᵐᵒᵖ) : (AlgEquiv.unop f).toRingEquiv = RingEquiv.unop f.toRingEquiv := rfl /-- Swap the `ᵐᵒᵖ` on an algebra isomorphism to the opposite side. -/ @[simps!] def opComm : (A ≃ₐ[R] Bᵐᵒᵖ) ≃ (Aᵐᵒᵖ ≃ₐ[R] B) := AlgEquiv.op.trans <| AlgEquiv.refl.equivCongr (opOp R B).symm variable (R S) /-- The canonical algebra isomorphism from `Aᵐᵒᵖ` to `Module.End A A` induced by the right multiplication. -/ @[simps!] def moduleEndSelf : Aᵐᵒᵖ ≃ₐ[R] Module.End A A where __ := RingEquiv.moduleEndSelf A commutes' _ := by ext; simp [Algebra.algebraMap_eq_smul_one] /-- The canonical algebra isomorphism from `A` to `Module.End Aᵐᵒᵖ A` induced by the left multiplication. -/ @[simps!] def moduleEndSelfOp : A ≃ₐ[R] Module.End Aᵐᵒᵖ A where __ := RingEquiv.moduleEndSelfOp A commutes' _ := by ext; simp [Algebra.algebraMap_eq_smul_one] end AlgEquiv end Semiring section CommSemiring variable (R A) [CommSemiring R] [CommSemiring A] [Algebra R A] namespace AlgEquiv /-- A commutative algebra is isomorphic to its opposite. -/ @[simps!] def toOpposite : A ≃ₐ[R] Aᵐᵒᵖ where __ := RingEquiv.toOpposite A commutes' _r := rfl @[simp] lemma toRingEquiv_toOpposite : (toOpposite R A : A ≃+* Aᵐᵒᵖ) = RingEquiv.toOpposite A := rfl @[simp] lemma toLinearEquiv_toOpposite : toLinearEquiv (toOpposite R A) = opLinearEquiv R := rfl end AlgEquiv end CommSemiring
.lake/packages/mathlib/Mathlib/Algebra/Algebra/RestrictScalars.lean
import Mathlib.Algebra.Algebra.Tower /-! # The `RestrictScalars` type alias See the documentation attached to the `RestrictScalars` definition for advice on how and when to use this type alias. As described there, it is often a better choice to use the `IsScalarTower` typeclass instead. ## Main definitions * `RestrictScalars R S M`: the `S`-module `M` viewed as an `R` module when `S` is an `R`-algebra. Note that by default we do *not* have a `Module S (RestrictScalars R S M)` instance for the original action. This is available as a def `RestrictScalars.moduleOrig` if really needed. * `RestrictScalars.addEquiv : RestrictScalars R S M ≃+ M`: the additive equivalence between the restricted and original space (in fact, they are definitionally equal, but sometimes it is helpful to avoid using this fact, to keep instances from leaking). * `RestrictScalars.ringEquiv : RestrictScalars R S A ≃+* A`: the ring equivalence between the restricted and original space when the module is an algebra. ## See also There are many similarly-named definitions elsewhere which do not refer to this type alias. These refer to restricting the scalar type in a bundled type, such as from `A →ₗ[R] B` to `A →ₗ[S] B`: * `LinearMap.restrictScalars` * `LinearEquiv.restrictScalars` * `AlgHom.restrictScalars` * `AlgEquiv.restrictScalars` * `Submodule.restrictScalars` * `Subalgebra.restrictScalars` -/ variable (R S M A : Type*) /-- If we put an `R`-algebra structure on a semiring `S`, we get a natural equivalence from the category of `S`-modules to the category of representations of the algebra `S` (over `R`). The type synonym `RestrictScalars` is essentially this equivalence. Warning: use this type synonym judiciously! Consider an example where we want to construct an `R`-linear map from `M` to `S`, given: ```lean variable (R S M : Type*) variable [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module S M] ``` With the assumptions above we can't directly state our map as we have no `Module R M` structure, but `RestrictScalars` permits it to be written as: ```lean -- an `R`-module structure on `M` is provided by `RestrictScalars` which is compatible example : RestrictScalars R S M →ₗ[R] S := sorry ``` However, it is usually better just to add this extra structure as an argument: ```lean -- an `R`-module structure on `M` and proof of its compatibility is provided by the user example [Module R M] [IsScalarTower R S M] : M →ₗ[R] S := sorry ``` The advantage of the second approach is that it defers the duty of providing the missing typeclasses `[Module R M] [IsScalarTower R S M]`. If some concrete `M` naturally carries these (as is often the case) then we have avoided `RestrictScalars` entirely. If not, we can pass `RestrictScalars R S M` later on instead of `M`. Note that this means we almost always want to state definitions and lemmas in the language of `IsScalarTower` rather than `RestrictScalars`. An example of when one might want to use `RestrictScalars` would be if one has a vector space over a field of characteristic zero and wishes to make use of the `ℚ`-algebra structure. -/ @[nolint unusedArguments] def RestrictScalars (_R _S M : Type*) : Type _ := M instance [I : Inhabited M] : Inhabited (RestrictScalars R S M) := I instance [I : AddCommMonoid M] : AddCommMonoid (RestrictScalars R S M) := I instance [I : AddCommGroup M] : AddCommGroup (RestrictScalars R S M) := I section Module section variable [Semiring S] [AddCommMonoid M] /-- We temporarily install an action of the original ring on `RestrictScalars R S M`. -/ def RestrictScalars.moduleOrig [I : Module S M] : Module S (RestrictScalars R S M) := I variable [CommSemiring R] [Algebra R S] section attribute [local instance] RestrictScalars.moduleOrig /-- When `M` is a module over a ring `S`, and `S` is an algebra over `R`, then `M` inherits a module structure over `R`. The preferred way of setting this up is `[Module R M] [Module S M] [IsScalarTower R S M]`. -/ instance RestrictScalars.module [Module S M] : Module R (RestrictScalars R S M) := Module.compHom M (algebraMap R S) /-- This instance is only relevant when `RestrictScalars.moduleOrig` is available as an instance. -/ instance RestrictScalars.isScalarTower [Module S M] : IsScalarTower R S (RestrictScalars R S M) := ⟨fun r S M ↦ by rw [Algebra.smul_def, mul_smul] rfl⟩ end /-- When `M` is a right-module over a ring `S`, and `S` is an algebra over `R`, then `M` inherits a right-module structure over `R`. The preferred way of setting this up is `[Module Rᵐᵒᵖ M] [Module Sᵐᵒᵖ M] [IsScalarTower Rᵐᵒᵖ Sᵐᵒᵖ M]`. -/ instance RestrictScalars.opModule [Module Sᵐᵒᵖ M] : Module Rᵐᵒᵖ (RestrictScalars R S M) := letI : Module Sᵐᵒᵖ (RestrictScalars R S M) := ‹Module Sᵐᵒᵖ M› Module.compHom M (RingHom.op <| algebraMap R S) instance RestrictScalars.isCentralScalar [Module S M] [Module Sᵐᵒᵖ M] [IsCentralScalar S M] : IsCentralScalar R (RestrictScalars R S M) where op_smul_eq_smul r _x := (op_smul_eq_smul (algebraMap R S r) (_ : M) :) /-- The `R`-algebra homomorphism from the original coefficient algebra `S` to endomorphisms of `RestrictScalars R S M`. -/ def RestrictScalars.lsmul [Module S M] : S →ₐ[R] Module.End R (RestrictScalars R S M) := -- We use `RestrictScalars.moduleOrig` in the implementation, -- but not in the type. letI : Module S (RestrictScalars R S M) := RestrictScalars.moduleOrig R S M Algebra.lsmul R R (RestrictScalars R S M) end variable [AddCommMonoid M] /-- `RestrictScalars.addEquiv` is the additive equivalence with the original module. -/ def RestrictScalars.addEquiv : RestrictScalars R S M ≃+ M := AddEquiv.refl M variable [CommSemiring R] [Semiring S] [Algebra R S] [Module S M] theorem RestrictScalars.smul_def (c : R) (x : RestrictScalars R S M) : c • x = (RestrictScalars.addEquiv R S M).symm (algebraMap R S c • RestrictScalars.addEquiv R S M x) := rfl @[simp] theorem RestrictScalars.addEquiv_map_smul (c : R) (x : RestrictScalars R S M) : RestrictScalars.addEquiv R S M (c • x) = algebraMap R S c • RestrictScalars.addEquiv R S M x := rfl theorem RestrictScalars.addEquiv_symm_map_algebraMap_smul (r : R) (x : M) : (RestrictScalars.addEquiv R S M).symm (algebraMap R S r • x) = r • (RestrictScalars.addEquiv R S M).symm x := rfl theorem RestrictScalars.addEquiv_symm_map_smul_smul (r : R) (s : S) (x : M) : (RestrictScalars.addEquiv R S M).symm ((r • s) • x) = r • (RestrictScalars.addEquiv R S M).symm (s • x) := by rw [Algebra.smul_def, mul_smul] rfl theorem RestrictScalars.lsmul_apply_apply (s : S) (x : RestrictScalars R S M) : RestrictScalars.lsmul R S M s x = (RestrictScalars.addEquiv R S M).symm (s • RestrictScalars.addEquiv R S M x) := rfl end Module section Algebra instance [I : Semiring A] : Semiring (RestrictScalars R S A) := I instance [I : Ring A] : Ring (RestrictScalars R S A) := I instance [I : CommSemiring A] : CommSemiring (RestrictScalars R S A) := I instance [I : CommRing A] : CommRing (RestrictScalars R S A) := I variable [Semiring A] /-- Tautological ring isomorphism `RestrictScalars R S A ≃+* A`. -/ def RestrictScalars.ringEquiv : RestrictScalars R S A ≃+* A := RingEquiv.refl _ variable [CommSemiring S] [Algebra S A] [CommSemiring R] [Algebra R S] @[simp] theorem RestrictScalars.ringEquiv_map_smul (r : R) (x : RestrictScalars R S A) : RestrictScalars.ringEquiv R S A (r • x) = algebraMap R S r • RestrictScalars.ringEquiv R S A x := rfl /-- `R ⟶ S` induces `S-Alg ⥤ R-Alg` -/ instance RestrictScalars.algebra : Algebra R (RestrictScalars R S A) where algebraMap := (algebraMap S A).comp (algebraMap R S) commutes' := fun _ _ ↦ Algebra.commutes' (A := A) _ _ smul_def' := fun _ _ ↦ Algebra.smul_def' (A := A) _ _ @[simp] theorem RestrictScalars.ringEquiv_algebraMap (r : R) : RestrictScalars.ringEquiv R S A (algebraMap R (RestrictScalars R S A) r) = algebraMap S A (algebraMap R S r) := rfl end Algebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Bilinear.lean
import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # Facts about algebras involving bilinear maps and tensor products We move a few basic statements about algebras out of `Algebra.Algebra.Basic`, in order to avoid importing `LinearAlgebra.BilinearMap` and `LinearAlgebra.TensorProduct` unnecessarily. -/ open TensorProduct Module variable {R A B : Type*} namespace LinearMap section NonUnitalNonAssoc section one_side variable [Semiring R] [NonUnitalNonAssocSemiring A] [Module R A] section left variable (R) [SMulCommClass R A A] /-- The multiplication on the left in an algebra is a linear map. Note that this only assumes `SMulCommClass R A A`, so that it also works for `R := Aᵐᵒᵖ`. When `A` is unital and associative, this is the same as `DistribMulAction.toLinearMap R A a` -/ def mulLeft (a : A) : A →ₗ[R] A where toFun := (a * ·) map_add' := mul_add _ map_smul' _ := mul_smul_comm _ _ @[simp] theorem mulLeft_apply (a b : A) : mulLeft R a b = a * b := rfl @[simp] theorem mulLeft_toAddMonoidHom (a : A) : (mulLeft R a : A →+ A) = AddMonoidHom.mulLeft a := rfl variable (A) in @[simp] theorem mulLeft_zero_eq_zero : mulLeft R (0 : A) = 0 := ext fun _ => zero_mul _ end left section right variable (R) [IsScalarTower R A A] /-- The multiplication on the right in an algebra is a linear map. Note that this only assumes `IsScalarTower R A A`, so that it also works for `R := A`. When `A` is unital and associative, this is the same as `DistribMulAction.toLinearMap R A (MulOpposite.op b)`. -/ def mulRight (b : A) : A →ₗ[R] A where toFun := (· * b) map_add' _ _ := add_mul _ _ _ map_smul' _ _ := smul_mul_assoc _ _ _ @[simp] theorem mulRight_apply (a b : A) : mulRight R a b = b * a := rfl @[simp] theorem mulRight_toAddMonoidHom (a : A) : (mulRight R a : A →+ A) = AddMonoidHom.mulRight a := rfl variable (A) in @[simp] theorem mulRight_zero_eq_zero : mulRight R (0 : A) = 0 := ext fun _ => mul_zero _ end right end one_side variable (R A) [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] variable [SMulCommClass R A A] [IsScalarTower R A A] /-- The multiplication in a non-unital non-associative algebra is a bilinear map. A weaker version of this for semirings exists as `AddMonoidHom.mul`. -/ @[simps!] def mul : A →ₗ[R] A →ₗ[R] A := LinearMap.mk₂ R (· * ·) add_mul smul_mul_assoc mul_add mul_smul_comm /-- The multiplication map on a non-unital algebra, as an `R`-linear map from `A ⊗[R] A` to `A`. -/ -- TODO: upgrade to A-linear map if A is a semiring. def mul' : A ⊗[R] A →ₗ[R] A := TensorProduct.lift (mul R A) @[inherit_doc] scoped[RingTheory.LinearMap] notation "μ" => LinearMap.mul' _ _ @[inherit_doc] scoped[RingTheory.LinearMap] notation "μ[" R "]" => LinearMap.mul' R _ variable {A} /-- Simultaneous multiplication on the left and right is a linear map. -/ def mulLeftRight (ab : A × A) : A →ₗ[R] A := (mulRight R ab.snd).comp (mulLeft R ab.fst) variable {R} @[simp] theorem mul_apply' (a b : A) : mul R A a b = a * b := rfl @[simp] theorem mulLeftRight_apply (a b x : A) : mulLeftRight R (a, b) x = a * x * b := rfl @[simp] theorem mul'_apply {a b : A} : mul' R A (a ⊗ₜ b) = a * b := rfl variable {M : Type*} [AddCommMonoid M] [Module R M] theorem lift_lsmul_mul_eq_lsmul_lift_lsmul {r : R} : lift (lsmul R M ∘ₗ mul R R r) = lsmul R M r ∘ₗ lift (lsmul R M) := by apply TensorProduct.ext' intro x a simp [← mul_smul, mul_comm] end NonUnitalNonAssoc section NonUnital section one_side variable (R A) [Semiring R] [NonUnitalSemiring A] [NonUnitalSemiring B] [Module R B] [Module R A] @[simp] theorem mulLeft_mul [SMulCommClass R A A] (a b : A) : mulLeft R (a * b) = (mulLeft R a).comp (mulLeft R b) := by ext simp only [mulLeft_apply, comp_apply, mul_assoc] @[simp] theorem mulRight_mul [IsScalarTower R A A] (a b : A) : mulRight R (a * b) = (mulRight R b).comp (mulRight R a) := by ext simp only [mulRight_apply, comp_apply, mul_assoc] end one_side variable [CommSemiring R] [NonUnitalSemiring A] [NonUnitalSemiring B] [Module R B] [Module R A] variable [SMulCommClass R A A] [IsScalarTower R A A] variable [SMulCommClass R B B] [IsScalarTower R B B] variable (R A) in /-- The multiplication in a non-unital algebra is a bilinear map. A weaker version of this for non-unital non-associative algebras exists as `LinearMap.mul`. -/ def _root_.NonUnitalAlgHom.lmul : A →ₙₐ[R] End R A where __ := mul R A map_mul' := mulLeft_mul _ _ map_zero' := mulLeft_zero_eq_zero _ _ @[simp] theorem _root_.NonUnitalAlgHom.coe_lmul_eq_mul : ⇑(NonUnitalAlgHom.lmul R A) = mul R A := rfl theorem commute_mulLeft_right (a b : A) : Commute (mulLeft R a) (mulRight R b) := by ext c exact (mul_assoc a c b).symm /-- A `LinearMap` preserves multiplication if pre- and post- composition with `LinearMap.mul` are equivalent. By converting the statement into an equality of `LinearMap`s, this lemma allows various specialized `ext` lemmas about `→ₗ[R]` to then be applied. This is the `LinearMap` version of `AddMonoidHom.map_mul_iff`. -/ theorem map_mul_iff (f : A →ₗ[R] B) : (∀ x y, f (x * y) = f x * f y) ↔ (LinearMap.mul R A).compr₂ f = (LinearMap.mul R B ∘ₗ f).compl₂ f := Iff.symm LinearMap.ext_iff₂ end NonUnital section Injective variable {R A : Type*} [Semiring R] [NonAssocSemiring A] [Module R A] @[simp] lemma mulLeft_inj [SMulCommClass R A A] {a b : A} : mulLeft R a = mulLeft R b ↔ a = b := ⟨fun h => by simpa using LinearMap.ext_iff.mp h 1, fun h => h ▸ rfl⟩ @[simp] lemma mulRight_inj [IsScalarTower R A A] {a b : A} : mulRight R a = mulRight R b ↔ a = b := ⟨fun h => by simpa using LinearMap.ext_iff.mp h 1, fun h => h ▸ rfl⟩ end Injective section Semiring variable (R A) section one_side variable [Semiring R] [Semiring A] section left variable [Module R A] [SMulCommClass R A A] @[simp] theorem mulLeft_one : mulLeft R (1 : A) = LinearMap.id := ext fun _ => one_mul _ @[simp] theorem mulLeft_eq_zero_iff (a : A) : mulLeft R a = 0 ↔ a = 0 := mulLeft_zero_eq_zero R A ▸ mulLeft_inj @[simp] theorem pow_mulLeft (a : A) (n : ℕ) : mulLeft R a ^ n = mulLeft R (a ^ n) := match n with | 0 => by rw [pow_zero, pow_zero, mulLeft_one, Module.End.one_eq_id] | (n + 1) => by rw [pow_succ, pow_succ, mulLeft_mul, Module.End.mul_eq_comp, pow_mulLeft] end left section right variable [Module R A] [IsScalarTower R A A] @[simp] theorem mulRight_one : mulRight R (1 : A) = LinearMap.id := ext fun _ => mul_one _ @[simp] theorem mulRight_eq_zero_iff (a : A) : mulRight R a = 0 ↔ a = 0 := mulRight_zero_eq_zero R A ▸ mulRight_inj @[simp] theorem pow_mulRight (a : A) (n : ℕ) : mulRight R a ^ n = mulRight R (a ^ n) := match n with | 0 => by rw [pow_zero, pow_zero, mulRight_one, Module.End.one_eq_id] | (n + 1) => by rw [pow_succ, pow_succ', mulRight_mul, Module.End.mul_eq_comp, pow_mulRight] end right end one_side variable [CommSemiring R] [Semiring A] [Algebra R A] /-- The multiplication in an algebra is an algebra homomorphism into the endomorphisms on the algebra. A weaker version of this for non-unital algebras exists as `NonUnitalAlgHom.lmul`. -/ def _root_.Algebra.lmul : A →ₐ[R] End R A where __ := NonUnitalAlgHom.lmul R A map_one' := mulLeft_one _ _ commutes' r := ext fun a => (Algebra.smul_def r a).symm variable {R A} @[simp] theorem _root_.Algebra.coe_lmul_eq_mul : ⇑(Algebra.lmul R A) = mul R A := rfl theorem _root_.Algebra.lmul_injective : Function.Injective (Algebra.lmul R A) := fun a₁ a₂ h ↦ by simpa using DFunLike.congr_fun h 1 theorem _root_.Algebra.lmul_isUnit_iff {x : A} : IsUnit (Algebra.lmul R A x) ↔ IsUnit x := by rw [Module.End.isUnit_iff, Iff.comm] exact IsUnit.isUnit_iff_mulLeft_bijective theorem toSpanSingleton_eq_algebra_linearMap : toSpanSingleton R A 1 = Algebra.linearMap R A := by ext; simp end Semiring section CommSemiring -- TODO: Generalise to `NonUnitalNonAssocCommSemiring`. This can't currently be done -- because there is no instance **to** `NonUnitalNonAssocCommSemiring`. variable [CommSemiring R] [NonUnitalCommSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] @[simp] lemma flip_mul : (mul R A).flip = mul R A := by ext; simp [mul_comm] lemma mul'_comp_comm : mul' R A ∘ₗ TensorProduct.comm R A A = mul' R A := by simp [mul', lift_comp_comm_eq] lemma mul'_comm (x : A ⊗[R] A) : mul' R A (TensorProduct.comm R A A x) = mul' R A x := congr($mul'_comp_comm _) end CommSemiring end LinearMap open scoped RingTheory.LinearMap namespace NonUnitalAlgHom variable [CommSemiring R] [NonUnitalSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [NonUnitalNonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] lemma comp_mul' (f : A →ₙₐ[R] B) : (f : A →ₗ[R] B) ∘ₗ μ = μ[R] ∘ₗ (f ⊗ₘ f) := TensorProduct.ext' <| by simp end NonUnitalAlgHom namespace AlgHom variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] lemma comp_mul' (f : A →ₐ B) : f.toLinearMap ∘ₗ μ = μ[R] ∘ₗ (f.toLinearMap ⊗ₘ f.toLinearMap) := TensorProduct.ext' <| by simp end AlgHom
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Rat.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Data.Rat.Cast.CharZero /-! # Further basic results about `Algebra`'s over `ℚ`. This file could usefully be split further. -/ assert_not_exists Subgroup variable {F R S : Type*} namespace RingHom @[simp] theorem map_rat_algebraMap [Semiring R] [Semiring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S) (r : ℚ) : f (algebraMap ℚ R r) = algebraMap ℚ S r := RingHom.ext_iff.1 (Subsingleton.elim (f.comp (algebraMap ℚ R)) (algebraMap ℚ S)) r end RingHom namespace NNRat variable [DivisionSemiring R] [CharZero R] [DivisionSemiring S] [CharZero S] instance _root_.DivisionSemiring.toNNRatAlgebra : Algebra ℚ≥0 R where smul_def' := smul_def algebraMap := castHom _ commutes' := cast_commute instance _root_.RingHomClass.toLinearMapClassNNRat [FunLike F R S] [RingHomClass F R S] : LinearMapClass F ℚ≥0 R S where map_smulₛₗ f q a := by simp [smul_def, cast_id] variable [SMul R S] instance instSMulCommClass [SMulCommClass R S S] : SMulCommClass ℚ≥0 R S where smul_comm q a b := by simp [smul_def, mul_smul_comm] instance instSMulCommClass' [SMulCommClass S R S] : SMulCommClass R ℚ≥0 S := have := SMulCommClass.symm S R S; SMulCommClass.symm _ _ _ end NNRat namespace Rat variable [DivisionRing R] [CharZero R] [DivisionRing S] [CharZero S] instance _root_.DivisionRing.toRatAlgebra : Algebra ℚ R where smul_def' := smul_def algebraMap := castHom _ commutes' := cast_commute instance _root_.RingHomClass.toLinearMapClassRat [FunLike F R S] [RingHomClass F R S] : LinearMapClass F ℚ R S where map_smulₛₗ f q a := by simp [smul_def, cast_id] instance _root_.RingEquivClass.toLinearEquivClassRat [EquivLike F R S] [RingEquivClass F R S] : LinearEquivClass F ℚ R S where map_smulₛₗ f c x := by simp [Algebra.smul_def] variable [SMul R S] instance instSMulCommClass [SMulCommClass R S S] : SMulCommClass ℚ R S where smul_comm q a b := by simp [smul_def, mul_smul_comm] instance instSMulCommClass' [SMulCommClass S R S] : SMulCommClass R ℚ S := have := SMulCommClass.symm S R S; SMulCommClass.symm _ _ _ instance algebra_rat_subsingleton {R} [Semiring R] : Subsingleton (Algebra ℚ R) := ⟨fun x y => Algebra.algebra_ext x y <| RingHom.congr_fun <| Subsingleton.elim _ _⟩ end Rat
.lake/packages/mathlib/Mathlib/Algebra/Algebra/TransferInstance.lean
import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Ring.TransferInstance /-! # Transfer algebraic structures across `Equiv`s This continues the pattern set in `Mathlib/Algebra/Group/TransferInstance.lean`. -/ universe v variable {R α β : Type*} [CommSemiring R] namespace Equiv variable (e : α ≃ β) variable (R) in /-- Transfer `Algebra` across an `Equiv` -/ protected abbrev algebra (e : α ≃ β) [Semiring β] : let _ := Equiv.semiring e ∀ [Algebra R β], Algebra R α := fast_instance% letI := Equiv.semiring e letI := e.smul R { algebraMap := { toFun r := e.symm (algebraMap R β r) __ := e.ringEquiv.symm.toRingHom.comp (algebraMap R β) } commutes' r x := show e.symm ((e (e.symm (algebraMap R β r)) * e x)) = e.symm (e x * e (e.symm (algebraMap R β r))) by simp [Algebra.commutes] smul_def' r x := show e.symm (r • e x) = e.symm (e (e.symm (algebraMap R β r)) * e x) by simp [Algebra.smul_def] } lemma algebraMap_def (e : α ≃ β) [Semiring β] [Algebra R β] (r : R) : letI := Equiv.semiring e letI := Equiv.algebra R e algebraMap R α r = e.symm (algebraMap R β r) := rfl variable (R) in /-- An equivalence `e : α ≃ β` gives an algebra equivalence `α ≃ₐ[R] β` where the `R`-algebra structure on `α` is the one obtained by transporting an `R`-algebra structure on `β` back along `e`. -/ def algEquiv (e : α ≃ β) [Semiring β] [Algebra R β] : by let semiring := Equiv.semiring e let algebra := Equiv.algebra R e exact α ≃ₐ[R] β := by intros exact { Equiv.ringEquiv e with commutes' := fun r => by apply e.symm.injective simp only [RingEquiv.toEquiv_eq_coe, toFun_as_coe, EquivLike.coe_coe, ringEquiv_apply, symm_apply_apply, algebraMap_def] } @[simp] theorem algEquiv_apply (e : α ≃ β) [Semiring β] [Algebra R β] (a : α) : (algEquiv R e) a = e a := rfl theorem algEquiv_symm_apply (e : α ≃ β) [Semiring β] [Algebra R β] (b : β) : by letI := Equiv.semiring e letI := Equiv.algebra R e exact (algEquiv R e).symm b = e.symm b := rfl end Equiv
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Prod.lean
import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.Hom import Mathlib.Algebra.Module.Prod /-! # The R-algebra structure on products of R-algebras The R-algebra structure on `(i : I) → A i` when each `A i` is an R-algebra. ## Main definitions * `Prod.algebra` * `AlgHom.fst` * `AlgHom.snd` * `AlgHom.prod` * `AlgEquiv.prodUnique` and `AlgEquiv.uniqueProd` -/ variable {R A B C : Type*} variable [CommSemiring R] variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C] namespace Prod variable (R A B) open Algebra instance algebra : Algebra R (A × B) where algebraMap := RingHom.prod (algebraMap R A) (algebraMap R B) commutes' := by rintro r ⟨a, b⟩ dsimp rw [commutes r a, commutes r b] smul_def' := by rintro r ⟨a, b⟩ dsimp rw [Algebra.smul_def r a, Algebra.smul_def r b] variable {R A B} @[simp] theorem algebraMap_apply (r : R) : algebraMap R (A × B) r = (algebraMap R A r, algebraMap R B r) := rfl end Prod namespace AlgHom variable (R A B) /-- First projection as `AlgHom`. -/ def fst : A × B →ₐ[R] A := { RingHom.fst A B with commutes' := fun _r => rfl } /-- Second projection as `AlgHom`. -/ def snd : A × B →ₐ[R] B := { RingHom.snd A B with commutes' := fun _r => rfl } variable {A B} @[simp] theorem fst_apply (a) : fst R A B a = a.1 := rfl @[simp] theorem snd_apply (a) : snd R A B a = a.2 := rfl variable {R} /-- The `Pi.prod` of two morphisms is a morphism. -/ @[simps!] def prod (f : A →ₐ[R] B) (g : A →ₐ[R] C) : A →ₐ[R] B × C := { f.toRingHom.prod g.toRingHom with commutes' := fun r => by simp only [toRingHom_eq_coe, RingHom.toFun_eq_coe, RingHom.prod_apply, coe_toRingHom, commutes, Prod.algebraMap_apply] } theorem coe_prod (f : A →ₐ[R] B) (g : A →ₐ[R] C) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : A →ₐ[R] B) (g : A →ₐ[R] C) : (fst R B C).comp (prod f g) = f := by ext; rfl @[simp] theorem snd_prod (f : A →ₐ[R] B) (g : A →ₐ[R] C) : (snd R B C).comp (prod f g) = g := by ext; rfl @[simp] theorem prod_fst_snd : prod (fst R A B) (snd R A B) = AlgHom.id R _ := rfl theorem prod_comp {C' : Type*} [Semiring C'] [Algebra R C'] (f : A →ₐ[R] B) (g : B →ₐ[R] C) (g' : B →ₐ[R] C') : (g.prod g').comp f = (g.comp f).prod (g'.comp f) := rfl /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. -/ @[simps] def prodEquiv : (A →ₐ[R] B) × (A →ₐ[R] C) ≃ (A →ₐ[R] B × C) where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) /-- `Prod.map` of two algebra homomorphisms. -/ def prodMap {D : Type*} [Semiring D] [Algebra R D] (f : A →ₐ[R] B) (g : C →ₐ[R] D) : A × C →ₐ[R] B × D := { toRingHom := f.toRingHom.prodMap g.toRingHom commutes' := fun r => by simp [commutes] } end AlgHom namespace AlgEquiv section variable {S T A B : Type*} [Semiring A] [Semiring B] [Semiring S] [Semiring T] [Algebra R S] [Algebra R T] [Algebra R A] [Algebra R B] /-- Product of algebra isomorphisms. -/ def prodCongr (l : S ≃ₐ[R] A) (r : T ≃ₐ[R] B) : (S × T) ≃ₐ[R] A × B := .ofRingEquiv (f := RingEquiv.prodCongr l r) <| by simp variable (l : S ≃ₐ[R] A) (r : T ≃ₐ[R] B) -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma prodCongr_apply (x : S × T) : prodCongr l r x = Equiv.prodCongr l r x := rfl -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma prodCongr_symm_apply (x : A × B) : (prodCongr l r).symm x = (Equiv.prodCongr l r).symm x := rfl end /-- Multiplying by the trivial algebra from the right does not change the structure. This is the `AlgEquiv` version of `LinearEquiv.prodUnique` and `RingEquiv.prodZeroRing.symm`. -/ @[simps!] def prodUnique [Unique B] : (A × B) ≃ₐ[R] A where toFun := Prod.fst invFun x := (x, 0) __ := (RingEquiv.prodZeroRing A B).symm commutes' _ := rfl /-- Multiplying by the trivial algebra from the left does not change the structure. This is the `AlgEquiv` version of `LinearEquiv.uniqueProd` and `RingEquiv.zeroRingProd.symm`. -/ @[simps!] def uniqueProd [Unique B] : (B × A) ≃ₐ[R] A where toFun := Prod.snd invFun x := (0, x) __ := (RingEquiv.zeroRingProd A B).symm commutes' _ := rfl end AlgEquiv
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Tower.lean
import Mathlib.Algebra.Algebra.Equiv import Mathlib.LinearAlgebra.Span.Basic /-! # Towers of algebras In this file we prove basic facts about towers of algebras. An algebra tower A/S/R is expressed by having instances of `Algebra A S`, `Algebra R S`, `Algebra R A` and `IsScalarTower R S A`, the latter asserting the compatibility condition `(r • s) • a = r • (s • a)`. An important definition is `toAlgHom R S A`, the canonical `R`-algebra homomorphism `S →ₐ[R] A`. -/ open Pointwise universe u v w u₁ v₁ variable (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) (M : Type v₁) namespace Algebra variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] variable [AddCommMonoid M] [Module R M] [Module A M] [Module B M] variable [IsScalarTower R A M] [IsScalarTower R B M] [SMulCommClass A B M] variable {A} /-- The `R`-algebra morphism `A → End (M)` corresponding to the representation of the algebra `A` on the `B`-module `M`. This is a stronger version of `DistribMulAction.toLinearMap`, and could also have been called `Algebra.toModuleEnd`. The typeclasses correspond to the situation where the types act on each other as ``` R ----→ B | ⟍ | | ⟍ | ↓ ↘ ↓ A ----→ M ``` where the diagram commutes, the action by `R` commutes with everything, and the action by `A` and `B` on `M` commute. Typically this is most useful with `B = R` as `Algebra.lsmul R R A : A →ₐ[R] Module.End R M`. However this can be used to get the fact that left-multiplication by `A` is right `A`-linear, and vice versa, as ```lean example : A →ₐ[R] Module.End Aᵐᵒᵖ A := Algebra.lsmul R Aᵐᵒᵖ A example : Aᵐᵒᵖ →ₐ[R] Module.End A A := Algebra.lsmul R A A ``` respectively; though `LinearMap.mulLeft` and `LinearMap.mulRight` can also be used here. -/ def lsmul : A →ₐ[R] Module.End B M where toFun := DistribMulAction.toLinearMap B M map_one' := LinearMap.ext fun _ => one_smul A _ map_mul' a b := LinearMap.ext <| smul_assoc a b map_zero' := LinearMap.ext fun _ => zero_smul A _ map_add' _a _b := LinearMap.ext fun _ => add_smul _ _ _ commutes' r := LinearMap.ext <| algebraMap_smul A r @[simp] theorem lsmul_coe (a : A) : (lsmul R B M a : M → M) = (a • ·) := rfl end Algebra namespace IsScalarTower section Module variable [CommSemiring R] [Semiring A] [Algebra R A] variable [MulAction A M] variable {R} {M} theorem algebraMap_smul [SMul R M] [IsScalarTower R A M] (r : R) (x : M) : algebraMap R A r • x = r • x := by rw [Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul] variable {A} in theorem of_algebraMap_smul [SMul R M] (h : ∀ (r : R) (x : M), algebraMap R A r • x = r • x) : IsScalarTower R A M where smul_assoc r a x := by rw [Algebra.smul_def, mul_smul, h] variable (R M) in theorem of_compHom : letI := MulAction.compHom M (algebraMap R A : R →* A); IsScalarTower R A M := letI := MulAction.compHom M (algebraMap R A : R →* A); of_algebraMap_smul fun _ _ ↦ rfl end Module section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra S A] [Algebra S B] variable {R S A} theorem of_algebraMap_eq [Algebra R A] (h : ∀ x, algebraMap R A x = algebraMap S A (algebraMap R S x)) : IsScalarTower R S A := ⟨fun x y z => by simp_rw [Algebra.smul_def, RingHom.map_mul, mul_assoc, h]⟩ /-- See note [partially-applied ext lemmas]. -/ theorem of_algebraMap_eq' [Algebra R A] (h : algebraMap R A = (algebraMap S A).comp (algebraMap R S)) : IsScalarTower R S A := of_algebraMap_eq <| RingHom.ext_iff.1 h variable (R S A) variable [Algebra R A] [Algebra R B] variable [IsScalarTower R S A] [IsScalarTower R S B] theorem algebraMap_eq : algebraMap R A = (algebraMap S A).comp (algebraMap R S) := RingHom.ext fun x => by simp_rw [RingHom.comp_apply, Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul] theorem algebraMap_apply (x : R) : algebraMap R A x = algebraMap S A (algebraMap R S x) := by rw [algebraMap_eq R S A, RingHom.comp_apply] @[ext] theorem Algebra.ext {S : Type u} {A : Type v} [CommSemiring S] [Semiring A] (h1 h2 : Algebra S A) (h : ∀ (r : S) (x : A), (by have I := h1; exact r • x) = r • x) : h1 = h2 := Algebra.algebra_ext _ _ fun r => by simpa only [@Algebra.smul_def _ _ _ _ h1, @Algebra.smul_def _ _ _ _ h2, mul_one] using h r 1 /-- In a tower, the canonical map from the middle element to the top element is an algebra homomorphism over the bottom element. -/ def toAlgHom : S →ₐ[R] A := { algebraMap S A with commutes' := fun _ => (algebraMap_apply _ _ _ _).symm } theorem toAlgHom_apply (y : S) : toAlgHom R S A y = algebraMap S A y := rfl @[simp] theorem coe_toAlgHom : ↑(toAlgHom R S A) = algebraMap S A := RingHom.ext fun _ => rfl @[simp] theorem coe_toAlgHom' : (toAlgHom R S A : S → A) = algebraMap S A := rfl variable {R S A B} @[simp] theorem _root_.AlgHom.map_algebraMap (f : A →ₐ[S] B) (r : R) : f (algebraMap R A r) = algebraMap R B r := by rw [algebraMap_apply R S A r, f.commutes, ← algebraMap_apply R S B] variable (R) @[simp] theorem _root_.AlgHom.comp_algebraMap_of_tower (f : A →ₐ[S] B) : (f : A →+* B).comp (algebraMap R A) = algebraMap R B := RingHom.ext (AlgHom.map_algebraMap f) -- conflicts with IsScalarTower.Subalgebra instance (priority := 999) subsemiring (U : Subsemiring S) : IsScalarTower U S A := of_algebraMap_eq fun _x => rfl -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12096): removed @[nolint instance_priority], linter not ported yet instance (priority := 999) of_algHom {R A B : Type*} [CommSemiring R] [CommSemiring A] [CommSemiring B] [Algebra R A] [Algebra R B] (f : A →ₐ[R] B) : @IsScalarTower R A B _ f.toRingHom.toAlgebra.toSMul _ := letI := (f : A →+* B).toAlgebra of_algebraMap_eq fun x => (f.commutes x).symm end Semiring end IsScalarTower section Homs variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra S A] [Algebra S B] variable [Algebra R A] [Algebra R B] variable [IsScalarTower R S A] [IsScalarTower R S B] variable {A S B} open IsScalarTower namespace AlgHom /-- R ⟶ S induces S-Alg ⥤ R-Alg -/ def restrictScalars (f : A →ₐ[S] B) : A →ₐ[R] B := { (f : A →+* B) with commutes' := fun r => by rw [algebraMap_apply R S A, algebraMap_apply R S B] exact f.commutes (algebraMap R S r) } theorem restrictScalars_apply (f : A →ₐ[S] B) (x : A) : f.restrictScalars R x = f x := rfl @[simp] theorem coe_restrictScalars (f : A →ₐ[S] B) : (f.restrictScalars R : A →+* B) = f := rfl @[simp] theorem coe_restrictScalars' (f : A →ₐ[S] B) : (restrictScalars R f : A → B) = f := rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : (A →ₐ[S] B) → A →ₐ[R] B) := fun _ _ h => AlgHom.ext (AlgHom.congr_fun h :) section variable {R} /-- Any `f : A →ₐ[R] B` is also an `R ⧸ I`-algebra homomorphism if the `R`-algebra structure on `A` and `B` factors via `R ⧸ I`. -/ @[simps! apply] def extendScalarsOfSurjective (h : Function.Surjective (algebraMap R S)) (f : A →ₐ[R] B) : A →ₐ[S] B where toRingHom := f commutes' := by simp [h.forall, ← IsScalarTower.algebraMap_apply] @[simp] lemma restrictScalars_extendScalarsOfSurjective (h : Function.Surjective (algebraMap R S)) (f : A →ₐ[R] B) : (f.extendScalarsOfSurjective h).restrictScalars R = f := rfl end end AlgHom namespace AlgEquiv /-- R ⟶ S induces S-Alg ⥤ R-Alg -/ def restrictScalars (f : A ≃ₐ[S] B) : A ≃ₐ[R] B := { (f : A ≃+* B) with commutes' := fun r => by rw [algebraMap_apply R S A, algebraMap_apply R S B] exact f.commutes (algebraMap R S r) } theorem restrictScalars_apply (f : A ≃ₐ[S] B) (x : A) : f.restrictScalars R x = f x := rfl @[simp] theorem coe_restrictScalars (f : A ≃ₐ[S] B) : (f.restrictScalars R : A ≃+* B) = f := rfl @[simp] theorem coe_restrictScalars' (f : A ≃ₐ[S] B) : (restrictScalars R f : A → B) = f := rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : (A ≃ₐ[S] B) → A ≃ₐ[R] B) := fun _ _ h => AlgEquiv.ext (AlgEquiv.congr_fun h :) lemma restrictScalars_symm_apply (f : A ≃ₐ[S] B) (x : B) : (f.restrictScalars R).symm x = f.symm x := rfl @[simp] lemma coe_restrictScalars_symm (f : A ≃ₐ[S] B) : ((f.restrictScalars R).symm : B ≃+* A) = f.symm := rfl @[simp] lemma coe_restrictScalars_symm' (f : A ≃ₐ[S] B) : ((restrictScalars R f).symm : B → A) = f.symm := rfl section variable {R} /-- Any `f : A ≃ₐ[R] B` is also an `R ⧸ I`-algebra isomorphism if the `R`-algebra structure on `A` and `B` factors via `R ⧸ I`. -/ @[simps! apply] def extendScalarsOfSurjective (h : Function.Surjective (algebraMap R S)) (f : A ≃ₐ[R] B) : A ≃ₐ[S] B where toRingEquiv := f commutes' := (f.toAlgHom.extendScalarsOfSurjective h).commutes' @[simp] lemma restrictScalars_extendScalarsOfSurjective (h : Function.Surjective (algebraMap R S)) (f : A ≃ₐ[R] B) : (f.extendScalarsOfSurjective h).restrictScalars R = f := rfl @[simp] lemma extendScalarsOfSurjective_symm (h : Function.Surjective (algebraMap R S)) (f : A ≃ₐ[R] B) : (f.extendScalarsOfSurjective h).symm = f.symm.extendScalarsOfSurjective h := rfl end end AlgEquiv end Homs namespace Submodule variable {M} variable [CommSemiring R] [Semiring A] [Algebra R A] [AddCommMonoid M] variable [Module R M] [Module A M] [IsScalarTower R A M] /-- If `A` is an `R`-algebra such that the induced morphism `R →+* A` is surjective, then the `R`-module generated by a set `X` equals the `A`-module generated by `X`. -/ theorem restrictScalars_span (hsur : Function.Surjective (algebraMap R A)) (X : Set M) : restrictScalars R (span A X) = span R X := by refine ((span_le_restrictScalars R A X).antisymm fun m hm => ?_).symm refine span_induction subset_span (zero_mem _) (fun _ _ _ _ => add_mem) (fun a m _ hm => ?_) hm obtain ⟨r, rfl⟩ := hsur a simpa [algebraMap_smul] using smul_mem _ r hm theorem coe_span_eq_span_of_surjective (h : Function.Surjective (algebraMap R A)) (s : Set M) : (Submodule.span A s : Set M) = Submodule.span R s := congr_arg ((↑) : Submodule R M → Set M) (Submodule.restrictScalars_span R A h s) end Submodule section Semiring variable {R S A} namespace Submodule section Module variable [Semiring R] [Semiring S] [AddCommMonoid A] variable [Module R S] [Module S A] [Module R A] [IsScalarTower R S A] open IsScalarTower theorem smul_mem_span_smul_of_mem {s : Set S} {t : Set A} {k : S} (hks : k ∈ span R s) {x : A} (hx : x ∈ t) : k • x ∈ span R (s • t) := span_induction (fun _ hc => subset_span <| Set.smul_mem_smul hc hx) (by rw [zero_smul]; exact zero_mem _) (fun c₁ c₂ _ _ ih₁ ih₂ => by rw [add_smul]; exact add_mem ih₁ ih₂) (fun b c _ hc => by rw [IsScalarTower.smul_assoc]; exact smul_mem _ _ hc) hks theorem span_smul_of_span_eq_top {s : Set S} (hs : span R s = ⊤) (t : Set A) : span R (s • t) = (span S t).restrictScalars R := le_antisymm (span_le.2 fun _x ⟨p, _hps, _q, hqt, hpqx⟩ ↦ hpqx ▸ (span S t).smul_mem p (subset_span hqt)) fun _ hp ↦ closure_induction (hx := hp) (zero_mem _) (fun _ _ _ _ ↦ add_mem) fun s0 y hy ↦ by refine span_induction (fun x hx ↦ subset_span <| by exact ⟨x, hx, y, hy, rfl⟩) ?_ ?_ ?_ (hs ▸ mem_top : s0 ∈ span R s) · rw [zero_smul]; apply zero_mem · intro _ _ _ _; rw [add_smul]; apply add_mem · intro r s0 _ hy; rw [IsScalarTower.smul_assoc]; exact smul_mem _ r hy -- The following two lemmas were originally used to prove `span_smul_of_span_eq_top` -- but are now not needed. theorem smul_mem_span_smul' {s : Set S} (hs : span R s = ⊤) {t : Set A} {k : S} {x : A} (hx : x ∈ span R (s • t)) : k • x ∈ span R (s • t) := by rw [span_smul_of_span_eq_top hs] at hx ⊢; exact (span S t).smul_mem k hx theorem smul_mem_span_smul {s : Set S} (hs : span R s = ⊤) {t : Set A} {k : S} {x : A} (hx : x ∈ span R t) : k • x ∈ span R (s • t) := by rw [span_smul_of_span_eq_top hs] exact (span S t).smul_mem k (span_le_restrictScalars R S t hx) end Module section Algebra variable [CommSemiring R] [Semiring S] [AddCommMonoid A] variable [Algebra R S] [Module S A] [Module R A] [IsScalarTower R S A] /-- A variant of `Submodule.span_image` for `algebraMap`. -/ theorem span_algebraMap_image (a : Set R) : Submodule.span R (algebraMap R S '' a) = (Submodule.span R a).map (Algebra.linearMap R S) := (Submodule.span_image <| Algebra.linearMap R S).trans rfl theorem span_algebraMap_image_of_tower {S T : Type*} [CommSemiring S] [Semiring T] [Module R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] (a : Set S) : Submodule.span R (algebraMap S T '' a) = (Submodule.span R a).map ((Algebra.linearMap S T).restrictScalars R) := (Submodule.span_image <| (Algebra.linearMap S T).restrictScalars R).trans rfl theorem map_mem_span_algebraMap_image {S T : Type*} [CommSemiring S] [Semiring T] [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] (x : S) (a : Set S) (hx : x ∈ Submodule.span R a) : algebraMap S T x ∈ Submodule.span R (algebraMap S T '' a) := by rw [span_algebraMap_image_of_tower, mem_map] exact ⟨x, hx, rfl⟩ end Algebra end Submodule end Semiring section Ring namespace Algebra variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] variable [AddCommGroup M] [Module R M] [Module A M] [Module B M] variable [IsScalarTower R A M] [IsScalarTower R B M] [SMulCommClass A B M] theorem lsmul_injective [NoZeroSMulDivisors A M] {x : A} (hx : x ≠ 0) : Function.Injective (lsmul R B M x) := smul_right_injective M hx end Algebra end Ring section Algebra.algebraMapSubmonoid @[simp] theorem Algebra.algebraMapSubmonoid_map_map {R A B : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (M : Submonoid R) [CommRing B] [Algebra R B] [Algebra A B] [IsScalarTower R A B] : algebraMapSubmonoid B (algebraMapSubmonoid A M) = algebraMapSubmonoid B M := algebraMapSubmonoid_map_eq _ (IsScalarTower.toAlgHom R A B) end Algebra.algebraMapSubmonoid
.lake/packages/mathlib/Mathlib/Algebra/Algebra/IsSimpleRing.lean
import Mathlib.Algebra.Algebra.Basic import Mathlib.RingTheory.SimpleRing.Basic /-! # Facts about algebras when the coefficient ring is a simple ring -/ variable (R A : Type*) [CommRing R] [Semiring A] [Algebra R A] [IsSimpleRing R] [Nontrivial A] instance : FaithfulSMul R A := faithfulSMul_iff_algebraMap_injective R A |>.2 <| RingHom.injective _
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Pi.lean
import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Algebra.Prod /-! # The R-algebra structure on families of R-algebras The R-algebra structure on `Π i : I, A i` when each `A i` is an R-algebra. ## Main definitions * `Pi.algebra` * `Pi.evalAlgHom` * `Pi.constAlgHom` -/ namespace Pi -- The indexing type variable (ι : Type*) -- The scalar type variable {R : Type*} -- The family of types already equipped with instances variable (A : ι → Type*) variable [CommSemiring R] [∀ i, Semiring (A i)] [∀ i, Algebra R (A i)] instance algebra : Algebra R (Π i, A i) where algebraMap := Pi.ringHom fun i ↦ algebraMap R (A i) commutes' := fun a f ↦ by ext; simp [Algebra.commutes] smul_def' := fun a f ↦ by ext; simp [Algebra.smul_def] @[push ←] theorem algebraMap_def (a : R) : algebraMap R (Π i, A i) a = fun i ↦ algebraMap R (A i) a := rfl @[simp] theorem algebraMap_apply (a : R) (i : ι) : algebraMap R (Π i, A i) a i = algebraMap R (A i) a := rfl variable {ι} (R) /-- A family of algebra homomorphisms `g i : B →ₐ[R] A i` defines a ring homomorphism `Pi.algHom g : B →ₐ[R] Π i, A i` given by `Pi.algHom g x i = g i x`. -/ @[simps!] def algHom {B : Type*} [Semiring B] [Algebra R B] (g : ∀ i, B →ₐ[R] A i) : B →ₐ[R] Π i, A i where __ := Pi.ringHom fun i ↦ (g i).toRingHom commutes' r := by ext; simp /-- `Function.eval` as an `AlgHom`. The name matches `Pi.evalRingHom`, `Pi.evalMonoidHom`, etc. -/ @[simps] def evalAlgHom (i : ι) : (Π i, A i) →ₐ[R] A i := { Pi.evalRingHom A i with toFun := fun f ↦ f i commutes' := fun _ ↦ rfl } @[simp] theorem algHom_evalAlgHom : algHom R A (evalAlgHom R A) = AlgHom.id R (Π i, A i) := rfl /-- `Pi.algHom` commutes with composition. -/ theorem algHom_comp {B C : Type*} [Semiring B] [Algebra R B] [Semiring C] [Algebra R C] (g : ∀ i, C →ₐ[R] A i) (h : B →ₐ[R] C) : (algHom R A g).comp h = algHom R A (fun i ↦ (g i).comp h) := rfl variable (S : ι → Type*) [∀ i, CommSemiring (S i)] instance [∀ i, Algebra (S i) (A i)] : Algebra (Π i, S i) (Π i, A i) where algebraMap := Pi.ringHom fun _ ↦ (algebraMap _ _).comp (Pi.evalRingHom S _) commutes' _ _ := funext fun _ ↦ Algebra.commutes _ _ smul_def' _ _ := funext fun _ ↦ Algebra.smul_def _ _ example : Pi.instAlgebraForall S S = Algebra.id _ := rfl variable (A B : Type*) [Semiring B] [Algebra R B] /-- `Function.const` as an `AlgHom`. The name matches `Pi.constRingHom`, `Pi.constMonoidHom`, etc. -/ @[simps] def constAlgHom : B →ₐ[R] A → B := { Pi.constRingHom A B with toFun := Function.const _ commutes' := fun _ ↦ rfl } /-- When `R` is commutative and permits an `algebraMap`, `Pi.constRingHom` is equal to that map. -/ @[simp] theorem constRingHom_eq_algebraMap : constRingHom A R = algebraMap R (A → R) := rfl @[simp] theorem constAlgHom_eq_algebra_ofId : constAlgHom R A R = Algebra.ofId R (A → R) := rfl end Pi /-- A special case of `Pi.algebra` for non-dependent types. Lean struggles to elaborate definitions elsewhere in the library without this. -/ instance Function.algebra {R : Type*} (ι : Type*) (A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] : Algebra R (ι → A) := Pi.algebra _ _ namespace AlgHom variable {R A B : Type*} variable [CommSemiring R] [Semiring A] [Semiring B] variable [Algebra R A] [Algebra R B] /-- `R`-algebra homomorphism between the function spaces `ι → A` and `ι → B`, induced by an `R`-algebra homomorphism `f` between `A` and `B`. -/ @[simps] protected def compLeft (f : A →ₐ[R] B) (ι : Type*) : (ι → A) →ₐ[R] ι → B := { f.toRingHom.compLeft ι with toFun := fun h ↦ f ∘ h commutes' := fun c ↦ by ext exact f.commutes' c } end AlgHom namespace AlgEquiv variable {α β R ι : Type*} {A₁ A₂ A₃ : ι → Type*} variable [CommSemiring R] [∀ i, Semiring (A₁ i)] [∀ i, Semiring (A₂ i)] [∀ i, Semiring (A₃ i)] variable [∀ i, Algebra R (A₁ i)] [∀ i, Algebra R (A₂ i)] [∀ i, Algebra R (A₃ i)] /-- A family of algebra equivalences `∀ i, (A₁ i ≃ₐ A₂ i)` generates a multiplicative equivalence between `Π i, A₁ i` and `Π i, A₂ i`. This is the `AlgEquiv` version of `Equiv.piCongrRight`, and the dependent version of `AlgEquiv.arrowCongr`. -/ @[simps apply] def piCongrRight (e : ∀ i, A₁ i ≃ₐ[R] A₂ i) : (Π i, A₁ i) ≃ₐ[R] Π i, A₂ i := { @RingEquiv.piCongrRight ι A₁ A₂ _ _ fun i ↦ (e i).toRingEquiv with toFun := fun x j ↦ e j (x j) invFun := fun x j ↦ (e j).symm (x j) commutes' := fun r ↦ by ext i simp } @[simp] theorem piCongrRight_refl : (piCongrRight fun i ↦ (AlgEquiv.refl : A₁ i ≃ₐ[R] A₁ i)) = AlgEquiv.refl := rfl @[simp] theorem piCongrRight_symm (e : ∀ i, A₁ i ≃ₐ[R] A₂ i) : (piCongrRight e).symm = piCongrRight fun i ↦ (e i).symm := rfl @[simp] theorem piCongrRight_trans (e₁ : ∀ i, A₁ i ≃ₐ[R] A₂ i) (e₂ : ∀ i, A₂ i ≃ₐ[R] A₃ i) : (piCongrRight e₁).trans (piCongrRight e₂) = piCongrRight fun i ↦ (e₁ i).trans (e₂ i) := rfl variable (R A₁) in /-- The opposite of a direct product is isomorphic to the direct product of the opposites as algebras. -/ def piMulOpposite : (Π i, A₁ i)ᵐᵒᵖ ≃ₐ[R] Π i, (A₁ i)ᵐᵒᵖ where __ := RingEquiv.piMulOpposite A₁ commutes' _ := rfl variable (R A₁) in /-- Transport dependent functions through an equivalence of the base space. This is `Equiv.piCongrLeft'` as an `AlgEquiv`. -/ def piCongrLeft' {ι' : Type*} (e : ι ≃ ι') : (Π i, A₁ i) ≃ₐ[R] Π i, A₁ (e.symm i) where __ := RingEquiv.piCongrLeft' A₁ e commutes' _ := rfl -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma piCongrLeft'_apply {ι' : Type*} (e : ι ≃ ι') (x : (Π i, A₁ i)) : piCongrLeft' R A₁ e x = Equiv.piCongrLeft' _ _ x := rfl -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma piCongrLeft'_symm_apply {ι' : Type*} (e : ι ≃ ι') (x : Π i, A₁ (e.symm i)) : (piCongrLeft' R A₁ e).symm x = (Equiv.piCongrLeft' _ _).symm x := rfl variable (R A₁) in /-- Transport dependent functions through an equivalence of the base space, expressed as "simplification". This is `Equiv.piCongrLeft` as an `AlgEquiv`. -/ def piCongrLeft {ι' : Type*} (e : ι' ≃ ι) : (Π i, A₁ (e i)) ≃ₐ[R] Π i, A₁ i := (AlgEquiv.piCongrLeft' R A₁ e.symm).symm -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma piCongrLeft_apply {ι' : Type*} (e : ι' ≃ ι) (x : Π i, A₁ (e i)) : piCongrLeft R A₁ e x = Equiv.piCongrLeft _ _ x := rfl -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma piCongrLeft_symm_apply {ι' : Type*} (e : ι' ≃ ι) (x : Π i, A₁ i) : (piCongrLeft R A₁ e).symm x = (Equiv.piCongrLeft _ _).symm x := rfl section variable (S : Type*) [Semiring S] [Algebra R S] variable (ι R) in /-- If `ι` has a unique element, then `ι → S` is isomorphic to `S` as an `R`-algebra. -/ def funUnique [Unique ι] : (ι → S) ≃ₐ[R] S := .ofRingEquiv (f := .piUnique (fun i : ι ↦ S)) (by simp) -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma funUnique_apply [Unique ι] (x : ι → S) : funUnique R ι S x = Equiv.funUnique ι S x := rfl -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma funUnique_symm_apply [Unique ι] (x : S) : (funUnique R ι S).symm x = (Equiv.funUnique ι S).symm x := rfl variable (α β R) in /-- `Equiv.sumArrowEquivProdArrow` as an algebra equivalence. -/ def sumArrowEquivProdArrow : (α ⊕ β → S) ≃ₐ[R] (α → S) × (β → S) := .ofRingEquiv (f := .sumArrowEquivProdArrow α β S) (by intro; ext <;> simp) -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma sumArrowEquivProdArrow_apply (x : α ⊕ β → S) : sumArrowEquivProdArrow α β R S x = Equiv.sumArrowEquivProdArrow α β S x := rfl -- Priority `low` to ensure generic `map_{add, mul, zero, one}` lemmas are applied first @[simp low] lemma sumArrowEquivProdArrow_symm_apply_inr (x : (α → S) × (β → S)) : (sumArrowEquivProdArrow α β R S).symm x = (Equiv.sumArrowEquivProdArrow α β S).symm x := rfl end end AlgEquiv
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Basic.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Algebra.Module.Submodule.Ker import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Algebra.Module.ULift import Mathlib.Algebra.Ring.CharZero import Mathlib.Algebra.Ring.Subring.Basic import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Data.Int.CharZero /-! # Further basic results about `Algebra`. This file could usefully be split further. -/ universe u v w u₁ v₁ open Function namespace Algebra variable {R : Type u} {A : Type w} section Semiring variable [CommSemiring R] variable [Semiring A] [Algebra R A] section PUnit instance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where algebraMap := { toFun _ := PUnit.unit map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl } commutes' _ _ := rfl smul_def' _ _ := rfl @[simp] theorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit := rfl end PUnit section ULift instance _root_.ULift.algebra : Algebra R (ULift A) := { ULift.module' with algebraMap := { (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with toFun := fun r => ULift.up (algebraMap R A r) } commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down } theorem _root_.ULift.algebraMap_eq (r : R) : algebraMap R (ULift A) r = ULift.up (algebraMap R A r) := rfl @[simp] theorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r := rfl end ULift /-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/ instance ofSubsemiring (S : Subsemiring R) : Algebra S A where algebraMap := (algebraMap R A).comp S.subtype commutes' r x := Algebra.commutes (r : R) x smul_def' r x := Algebra.smul_def (r : R) x theorem algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S →+* R) = Subsemiring.subtype S := rfl theorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val := rfl theorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x := rfl /-- Algebra over a subring. This builds upon `Subring.module`. -/ instance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) : Algebra S A where algebraMap := (algebraMap R A).comp S.subtype commutes' r x := Algebra.commutes (r : R) x smul_def' r x := Algebra.smul_def (r : R) x theorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) : (algebraMap S R : S →+* R) = Subring.subtype S := rfl theorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) : (algebraMap S R : S → R) = Subtype.val := rfl theorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) : algebraMap S R x = x := rfl /-- Explicit characterization of the submonoid map in the case of an algebra. `S` is made explicit to help with type inference -/ def algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S := M.map (algebraMap R S) theorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R} (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M := Set.mem_image_of_mem (algebraMap R S) x.2 @[simp] lemma algebraMapSubmonoid_self (M : Submonoid R) : Algebra.algebraMapSubmonoid R M = M := Submonoid.map_id M @[simp] lemma algebraMapSubmonoid_powers {S : Type*} [Semiring S] [Algebra R S] (r : R) : Algebra.algebraMapSubmonoid S (.powers r) = Submonoid.powers (algebraMap R S r) := by simp [Algebra.algebraMapSubmonoid] end Semiring section CommSemiring variable [CommSemiring R] theorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) : x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul] theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) : x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by induction n with | zero => simp | succ n ih => rw [pow_succ', ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc] end CommSemiring section Ring /-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure. See note [reducible non-instances]. -/ abbrev semiringToRing (R : Type*) [CommRing R] [Semiring A] [Algebra R A] : Ring A := { __ := (inferInstance : Semiring A) __ := Module.addCommMonoidToAddCommGroup R intCast := fun z => algebraMap R A z intCast_ofNat := fun z => by simp only [Int.cast_natCast, map_natCast] intCast_negSucc := fun z => by simp } instance {R : Type*} [Ring R] : Algebra (Subring.center R) R where algebraMap := { toFun := Subtype.val map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl } commutes' r x := (Subring.mem_center_iff.1 r.2 x).symm smul_def' _ _ := rfl end Ring end Algebra open scoped Algebra namespace Module variable (R : Type u) (S : Type v) (M : Type w) variable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M] variable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M] instance End.instAlgebra : Algebra R (Module.End S M) := Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm -- to prove this is a special case of the above example : Algebra R (Module.End R M) := End.instAlgebra _ _ _ theorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id := rfl @[simp] theorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m := rfl @[simp] theorem ker_algebraMap_end (K : Type u) (V : Type v) [Semifield K] [AddCommMonoid V] [Module K V] (a : K) (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ := LinearMap.ker_smul _ _ ha section variable {R M} theorem End.algebraMap_isUnit_inv_apply_eq_iff {x : R} (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) : (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' where mp H := H ▸ (isUnit_apply_inv_apply_of_isUnit h m).symm mpr H := H.symm ▸ by apply_fun ⇑h.unit.val using ((isUnit_iff _).mp h).injective simpa using Module.End.isUnit_apply_inv_apply_of_isUnit h (x • m') @[deprecated (since := "2025-04-28")] alias End_algebraMap_isUnit_inv_apply_eq_iff := End.algebraMap_isUnit_inv_apply_eq_iff theorem End.algebraMap_isUnit_inv_apply_eq_iff' {x : R} (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) : m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' where mp H := H ▸ (isUnit_apply_inv_apply_of_isUnit h m).symm mpr H := H.symm ▸ by apply_fun (↑h.unit : M → M) using ((isUnit_iff _).mp h).injective simpa using isUnit_apply_inv_apply_of_isUnit h (x • m') |>.symm @[deprecated (since := "2025-04-28")] alias End_algebraMap_isUnit_inv_apply_eq_iff' := End.algebraMap_isUnit_inv_apply_eq_iff' end end Module namespace LinearMap variable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] /-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to work with than `•`. -/ theorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) : f (algebraMap R A r * a) = algebraMap R B r * f a := by rw [← Algebra.smul_def, ← Algebra.smul_def, map_smul] theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) : f (a * algebraMap R A r) = f a * algebraMap R B r := by rw [← Algebra.commutes, ← Algebra.commutes, map_algebraMap_mul] end LinearMap section Nat variable {R : Type*} [Semiring R] -- Lower the priority so that `Algebra.id` is picked most of the time when working with -- `ℕ`-algebras. -- TODO: is this still needed? /-- Semiring ⥤ ℕ-Alg -/ instance (priority := 99) Semiring.toNatAlgebra : Algebra ℕ R where commutes' := Nat.cast_commute smul_def' _ _ := nsmul_eq_mul _ _ algebraMap := Nat.castRingHom R instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) := ⟨fun P Q => by ext; simp⟩ @[simp] lemma algebraMap_comp_natCast (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] : algebraMap R A ∘ Nat.cast = Nat.cast := by ext; simp end Nat section Int variable (R : Type*) [Ring R] -- Lower the priority so that `Algebra.id` is picked most of the time when working with -- `ℤ`-algebras. -- TODO: is this still needed? /-- Ring ⥤ ℤ-Alg -/ instance (priority := 99) Ring.toIntAlgebra : Algebra ℤ R where commutes' := Int.cast_commute smul_def' _ _ := zsmul_eq_mul _ _ algebraMap := Int.castRingHom R /-- A special case of `eq_intCast'` that happens to be true definitionally -/ @[simp] theorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R := rfl variable {R} instance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) := ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩ @[simp] lemma algebraMap_comp_intCast (R A : Type*) [CommRing R] [Ring A] [Algebra R A] : algebraMap R A ∘ Int.cast = Int.cast := by ext; simp end Int section FaithfulSMul theorem _root_.NeZero.of_faithfulSMul (R A : Type*) [Semiring R] [Semiring A] [Module R A] [IsScalarTower R A A] [FaithfulSMul R A] (n : ℕ) [NeZero (n : R)] : NeZero (n : A) := NeZero.nat_of_injective (f := ringHomEquivModuleIsScalarTower.symm ⟨_, ‹_›⟩) <| (faithfulSMul_iff_injective_smul_one R A).mp ‹_› variable (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] lemma faithfulSMul_iff_algebraMap_injective : FaithfulSMul R A ↔ Injective (algebraMap R A) := by rw [faithfulSMul_iff_injective_smul_one, Algebra.algebraMap_eq_smul_one'] variable [FaithfulSMul R A] namespace FaithfulSMul lemma algebraMap_injective : Injective (algebraMap R A) := (faithfulSMul_iff_algebraMap_injective R A).mp inferInstance @[simp] lemma algebraMap_eq_zero_iff {r : R} : algebraMap R A r = 0 ↔ r = 0 := map_eq_zero_iff (algebraMap R A) <| algebraMap_injective R A @[simp] lemma algebraMap_eq_one_iff {r : R} : algebraMap R A r = 1 ↔ r = 1 := map_eq_one_iff _ <| FaithfulSMul.algebraMap_injective R A end FaithfulSMul namespace algebraMap @[norm_cast, simp] theorem coe_inj {a b : R} : (↑a : A) = ↑b ↔ a = b := (FaithfulSMul.algebraMap_injective _ _).eq_iff @[norm_cast] theorem coe_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 := FaithfulSMul.algebraMap_eq_zero_iff _ _ @[deprecated coe_eq_zero_iff (since := "29/09/2025")] theorem lift_map_eq_zero_iff (a : R) : (↑a : A) = 0 ↔ a = 0 := coe_eq_zero_iff _ _ _ end algebraMap lemma Algebra.charZero_of_charZero [CharZero R] : CharZero A := have := algebraMap_comp_natCast R A ⟨this ▸ (FaithfulSMul.algebraMap_injective R A).comp CharZero.cast_injective⟩ instance [CharZero R] : FaithfulSMul ℕ R := by simpa only [faithfulSMul_iff_algebraMap_injective] using (algebraMap ℕ R).injective_nat instance (R : Type*) [Ring R] [CharZero R] : FaithfulSMul ℤ R := by simpa only [faithfulSMul_iff_algebraMap_injective] using (algebraMap ℤ R).injective_int end FaithfulSMul namespace NoZeroSMulDivisors -- see Note [lower instance priority] instance (priority := 100) instOfFaithfulSMul {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A] [FaithfulSMul R A] : NoZeroSMulDivisors R A := ⟨fun hcx => (mul_eq_zero.mp ((Algebra.smul_def _ _).symm.trans hcx)).imp_left (map_eq_zero_iff (algebraMap R A) <| FaithfulSMul.algebraMap_injective R A).mp⟩ variable {R A : Type*} [CommRing R] [Ring A] [Algebra R A] instance [Nontrivial A] [NoZeroSMulDivisors R A] : FaithfulSMul R A where eq_of_smul_eq_smul {r₁ r₂} h := by specialize h 1 rw [← sub_eq_zero, ← sub_smul, smul_eq_zero, sub_eq_zero] at h exact h.resolve_right one_ne_zero theorem iff_faithfulSMul [IsDomain A] : NoZeroSMulDivisors R A ↔ FaithfulSMul R A := ⟨fun _ ↦ inferInstance, fun _ ↦ inferInstance⟩ theorem iff_algebraMap_injective [IsDomain A] : NoZeroSMulDivisors R A ↔ Injective (algebraMap R A) := by rw [iff_faithfulSMul] exact faithfulSMul_iff_algebraMap_injective R A end NoZeroSMulDivisors section IsScalarTower variable {R : Type*} [CommSemiring R] variable (A : Type*) [Semiring A] [Algebra R A] variable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M] theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by rw [← one_smul A m, ← smul_assoc, Algebra.smul_def, mul_one, one_smul] @[simp] theorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m := (algebra_compatible_smul A r m).symm /-- If `M` is `A`-torsion free and `algebraMap R A` is injective, `M` is also `R`-torsion free. -/ theorem NoZeroSMulDivisors.trans_faithfulSMul (R A M : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [FaithfulSMul R A] [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M where eq_zero_or_eq_zero_of_smul_eq_zero hx := by rw [← algebraMap_smul (A := A)] at hx simpa only [map_eq_zero_iff _ <| FaithfulSMul.algebraMap_injective R A] using eq_zero_or_eq_zero_of_smul_eq_zero hx variable {A} -- see Note [lower instance priority] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980, as it is a very common path instance (priority := 120) IsScalarTower.to_smulCommClass : SMulCommClass R A M := ⟨fun r a m => by rw [algebra_compatible_smul A r (a • m), smul_smul, Algebra.commutes, mul_smul, ← algebra_compatible_smul]⟩ -- see Note [lower instance priority] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980, as it is a very common path instance (priority := 110) IsScalarTower.to_smulCommClass' : SMulCommClass A R M := SMulCommClass.symm _ _ _ -- see Note [lower instance priority] instance (priority := 200) Algebra.to_smulCommClass {R A} [CommSemiring R] [Semiring A] [Algebra R A] : SMulCommClass R A A := IsScalarTower.to_smulCommClass -- see Note [lower instance priority] instance (priority := 100) {R S A : Type*} [CommSemiring R] [CommSemiring S] [Semiring A] [Algebra R A] [Algebra S A] : SMulCommClass R S A where smul_comm r s a := by rw [Algebra.smul_def, mul_smul_comm, ← Algebra.smul_def] theorem smul_algebra_smul_comm (r : R) (a : A) (m : M) : a • r • m = r • a • m := smul_comm _ _ _ namespace LinearMap variable (R) -- TODO: generalize to `CompatibleSMul` /-- `A`-linearly coerce an `R`-linear map from `M` to `A` to a function, given an algebra `A` over a commutative semiring `R` and `M` a module over `R`. -/ def ltoFun (R : Type u) (M : Type v) (A : Type w) [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring A] [Algebra R A] : (M →ₗ[R] A) →ₗ[A] M → A where toFun f := f.toFun map_add' _ _ := rfl map_smul' _ _ := rfl end LinearMap end IsScalarTower /-! TODO: The following lemmas no longer involve `Algebra` at all, and could be moved closer to `Algebra/Module/Submodule.lean`. Currently this is tricky because `ker`, `range`, `⊤`, and `⊥` are all defined in `LinearAlgebra/Basic.lean`. -/ section Module variable (R : Type*) {S M N : Type*} [Semiring R] [Semiring S] [SMul R S] variable [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] variable [AddCommMonoid N] [Module R N] [Module S N] [IsScalarTower R S N] @[simp] theorem LinearMap.ker_restrictScalars (f : M →ₗ[S] N) : LinearMap.ker (f.restrictScalars R) = (LinearMap.ker f).restrictScalars R := rfl end Module example {R A} [CommSemiring R] [Semiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A := Algebra.ofModule smul_mul_assoc mul_smul_comm section invertibility variable {R A B : Type*} variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] /-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is invertible when `algebraMap R A r` is. -/ abbrev Invertible.algebraMapOfInvertibleAlgebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R} (h : Invertible (algebraMap R A r)) : Invertible (algebraMap R B r) where invOf := f ⅟(algebraMap R A r) invOf_mul_self := by rw [← Algebra.commutes, ← Algebra.smul_def, ← map_smul, Algebra.smul_def, mul_invOf_self, hf] mul_invOf_self := by rw [← Algebra.smul_def, ← map_smul, Algebra.smul_def, mul_invOf_self, hf] /-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is a unit when `algebraMap R A r` is. -/ lemma IsUnit.algebraMap_of_algebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R} (h : IsUnit (algebraMap R A r)) : IsUnit (algebraMap R B r) := let ⟨i⟩ := nonempty_invertible h letI := Invertible.algebraMapOfInvertibleAlgebraMap f hf i isUnit_of_invertible _ end invertibility section algebraMap variable {F E : Type*} [CommSemiring F] [Semiring E] [Algebra F E] (b : F →ₗ[F] E) /-- If `E` is an `F`-algebra, and there exists an injective `F`-linear map from `F` to `E`, then the algebra map from `F` to `E` is also injective. -/ theorem injective_algebraMap_of_linearMap (hb : Injective b) : Injective (algebraMap F E) := fun x y e ↦ hb <| by rw [← mul_one x, ← mul_one y, ← smul_eq_mul, ← smul_eq_mul, map_smul, map_smul, Algebra.smul_def, Algebra.smul_def, e] /-- If `E` is an `F`-algebra, and there exists a surjective `F`-linear map from `F` to `E`, then the algebra map from `F` to `E` is also surjective. -/ theorem surjective_algebraMap_of_linearMap (hb : Surjective b) : Surjective (algebraMap F E) := fun x ↦ by obtain ⟨x, rfl⟩ := hb x obtain ⟨y, hy⟩ := hb (b 1 * b 1) refine ⟨x * y, ?_⟩ obtain ⟨z, hz⟩ := hb 1 apply_fun (x • z • ·) at hy rwa [← map_smul, smul_eq_mul, mul_comm, ← smul_mul_assoc, ← map_smul _ z, smul_eq_mul, mul_one, ← smul_eq_mul, map_smul, hz, one_mul, ← map_smul, smul_eq_mul, mul_one, smul_smul, ← Algebra.algebraMap_eq_smul_one] at hy /-- If `E` is an `F`-algebra, and there exists a bijective `F`-linear map from `F` to `E`, then the algebra map from `F` to `E` is also bijective. NOTE: The same result can also be obtained if there are two `F`-linear maps from `F` to `E`, one is injective, the other one is surjective. In this case, use `injective_algebraMap_of_linearMap` and `surjective_algebraMap_of_linearMap` separately. -/ theorem bijective_algebraMap_of_linearMap (hb : Bijective b) : Bijective (algebraMap F E) := ⟨injective_algebraMap_of_linearMap b hb.1, surjective_algebraMap_of_linearMap b hb.2⟩ /-- If `E` is an `F`-algebra, there exists an `F`-linear isomorphism from `F` to `E` (namely, `E` is a free `F`-module of rank one), then the algebra map from `F` to `E` is bijective. -/ theorem bijective_algebraMap_of_linearEquiv (b : F ≃ₗ[F] E) : Bijective (algebraMap F E) := bijective_algebraMap_of_linearMap _ b.bijective end algebraMap section surjective variable {R S} [CommSemiring R] [Semiring S] [Algebra R S] variable {M N} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module S M] [IsScalarTower R S M] variable [Module R N] [Module S N] [IsScalarTower R S N] /-- If `R →+* S` is surjective, then `S`-linear maps between modules are exactly `R`-linear maps. -/ def LinearMap.extendScalarsOfSurjectiveEquiv (h : Surjective (algebraMap R S)) : (M →ₗ[R] N) ≃ₗ[R] (M →ₗ[S] N) where toFun f := { __ := f, map_smul' := fun r x ↦ by obtain ⟨r, rfl⟩ := h r; simp } map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := f.restrictScalars S /-- If `R →+* S` is surjective, then `R`-linear maps are also `S`-linear. -/ abbrev LinearMap.extendScalarsOfSurjective (h : Surjective (algebraMap R S)) (l : M →ₗ[R] N) : M →ₗ[S] N := extendScalarsOfSurjectiveEquiv h l /-- If `R →+* S` is surjective, then `R`-linear isomorphisms are also `S`-linear. -/ def LinearEquiv.extendScalarsOfSurjective (h : Surjective (algebraMap R S)) (f : M ≃ₗ[R] N) : M ≃ₗ[S] N where __ := f map_smul' r x := by obtain ⟨r, rfl⟩ := h r; simp variable (h : Surjective (algebraMap R S)) @[simp] lemma LinearMap.extendScalarsOfSurjective_apply (l : M →ₗ[R] N) (x) : l.extendScalarsOfSurjective h x = l x := rfl @[simp] lemma LinearEquiv.extendScalarsOfSurjective_apply (f : M ≃ₗ[R] N) (x) : f.extendScalarsOfSurjective h x = f x := rfl @[simp] lemma LinearEquiv.extendScalarsOfSurjective_symm (f : M ≃ₗ[R] N) : (f.extendScalarsOfSurjective h).symm = f.symm.extendScalarsOfSurjective h := rfl end surjective namespace algebraMap section CommSemiringCommSemiring variable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] {ι : Type*} {s : Finset ι} @[norm_cast] theorem coe_prod (a : ι → R) : (↑(∏ i ∈ s, a i : R) : A) = ∏ i ∈ s, (↑(a i) : A) := map_prod (algebraMap R A) a s @[norm_cast] theorem coe_sum (a : ι → R) : ↑(∑ i ∈ s, a i) = ∑ i ∈ s, (↑(a i) : A) := map_sum (algebraMap R A) a s end CommSemiringCommSemiring end algebraMap
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Operations.lean
import Mathlib.Algebra.Algebra.Bilinear import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Group.Pointwise.Finset.Basic import Mathlib.Algebra.Group.Pointwise.Set.BigOperators import Mathlib.Algebra.Module.Submodule.Pointwise import Mathlib.Algebra.Ring.NonZeroDivisors import Mathlib.Algebra.Ring.Submonoid.Pointwise import Mathlib.Data.Set.Semiring import Mathlib.GroupTheory.GroupAction.SubMulAction.Pointwise /-! # Multiplication and division of submodules of an algebra. An interface for multiplication and division of sub-R-modules of an R-algebra A is developed. ## Main definitions Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra. * `1 : Submodule R A` : the R-submodule R of the R-algebra A * `Mul (Submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be the smallest submodule containing all the products `m * n`. * `Div (Submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such that `a • J ⊆ I` It is proved that `Submodule R A` is a semiring, and also an algebra over `Set A`. Additionally, in the `Pointwise` scope we promote `Submodule.pointwiseDistribMulAction` to a `MulSemiringAction` as `Submodule.pointwiseMulSemiringAction`. When `R` is not necessarily commutative, and `A` is merely a `R`-module with a ring structure such that `IsScalarTower R A A` holds (equivalent to the data of a ring homomorphism `R →+* A` by `ringHomEquivModuleIsScalarTower`), we can still define `1 : Submodule R A` and `Mul (Submodule R A)`, but `1` is only a left identity, not necessarily a right one. ## Tags multiplication of submodules, division of submodules, submodule semiring -/ universe uι u v open Algebra Set MulOpposite open Pointwise namespace SubMulAction variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A] theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : SubMulAction R A) := ⟨r, (algebraMap_eq_smul_one r).symm⟩ theorem mem_one' {x : A} : x ∈ (1 : SubMulAction R A) ↔ ∃ y, algebraMap R A y = x := exists_congr fun r => by rw [algebraMap_eq_smul_one] end SubMulAction namespace Submodule section Module variable {R : Type u} [Semiring R] {A : Type v} [Semiring A] [Module R A] -- TODO: Why is this in a file about `Algebra`? -- TODO: potentially change this back to `LinearMap.range (Algebra.linearMap R A)` -- once a version of `Algebra` without the `commutes'` field is introduced. -- See issue https://github.com/leanprover-community/mathlib4/issues/18110. /-- `1 : Submodule R A` is the submodule `R ∙ 1` of `A`. -/ instance one : One (Submodule R A) := ⟨LinearMap.range (LinearMap.toSpanSingleton R A 1)⟩ theorem one_eq_span : (1 : Submodule R A) = R ∙ 1 := (LinearMap.span_singleton_eq_range _ _ _).symm theorem le_one_toAddSubmonoid : 1 ≤ (1 : Submodule R A).toAddSubmonoid := by rintro x ⟨n, rfl⟩ exact ⟨n, show (n : R) • (1 : A) = n by rw [Nat.cast_smul_eq_nsmul, nsmul_one]⟩ @[simp] theorem toSubMulAction_one : (1 : Submodule R A).toSubMulAction = 1 := SetLike.ext fun _ ↦ by rw [one_eq_span, SubMulAction.mem_one]; exact mem_span_singleton theorem one_eq_span_one_set : (1 : Submodule R A) = span R 1 := one_eq_span @[simp] theorem one_le {P : Submodule R A} : (1 : Submodule R A) ≤ P ↔ (1 : A) ∈ P := by simp [one_eq_span] instance : AddCommMonoidWithOne (Submodule R A) where add_comm := sup_comm variable {M : Type*} [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] instance : SMul (Submodule R A) (Submodule R M) where smul A' M' := { __ := A'.toAddSubmonoid • M'.toAddSubmonoid smul_mem' := fun r m hm ↦ AddSubmonoid.smul_induction_on hm (fun a ha m hm ↦ by rw [← smul_assoc]; exact AddSubmonoid.smul_mem_smul (A'.smul_mem r ha) hm) fun m₁ m₂ h₁ h₂ ↦ by rw [smul_add]; exact (A'.1 • M'.1).add_mem h₁ h₂ } section variable {I J : Submodule R A} {N P : Submodule R M} theorem smul_toAddSubmonoid : (I • N).toAddSubmonoid = I.toAddSubmonoid • N.toAddSubmonoid := rfl theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N := AddSubmonoid.smul_mem_smul hr hn theorem smul_le : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P := AddSubmonoid.smul_le @[simp, norm_cast] lemma coe_set_smul : (I : Set A) • N = I • N := set_smul_eq_of_le _ _ _ (fun _ _ hr hx ↦ smul_mem_smul hr hx) (smul_le.mpr fun _ hr _ hx ↦ mem_set_smul_of_mem_mem hr hx) @[elab_as_elim] theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n)) (add : ∀ x y, p x → p y → p (x + y)) : p x := AddSubmonoid.smul_induction_on H smul add /-- Dependent version of `Submodule.smul_induction_on`. -/ @[elab_as_elim] theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop} (smul : ∀ (r : A) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem ‹_› ‹_›)) : p x hx := by refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) ↦ H exact smul_induction_on hx (fun a ha x hx ↦ ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ ↦ ⟨_, add _ _ _ _ hx hy⟩ theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P := AddSubmonoid.smul_le_smul hij hnp theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N := smul_mono h le_rfl instance : CovariantClass (Submodule R A) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => smul_mono le_rfl⟩ variable (I J N P) @[simp] theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ := toAddSubmonoid_injective <| AddSubmonoid.addSubmonoid_smul_bot _ @[simp] theorem bot_smul : (⊥ : Submodule R A) • N = ⊥ := le_bot_iff.mp <| smul_le.mpr <| by rintro _ rfl _ _; rw [zero_smul]; exact zero_mem _ theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P := toAddSubmonoid_injective <| by simp only [smul_toAddSubmonoid, sup_toAddSubmonoid, AddSubmonoid.addSubmonoid_smul_sup] theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N := le_antisymm (smul_le.mpr fun mn hmn p hp ↦ by obtain ⟨m, hm, n, hn, rfl⟩ := mem_sup.mp hmn rw [add_smul]; exact add_mem_sup (smul_mem_smul hm hp) <| smul_mem_smul hn hp) (sup_le (smul_mono_left le_sup_left) <| smul_mono_left le_sup_right) protected theorem smul_assoc {B} [Semiring B] [Module R B] [Module A B] [Module B M] [IsScalarTower R A B] [IsScalarTower R B M] [IsScalarTower A B M] (I : Submodule R A) (J : Submodule R B) (N : Submodule R M) : (I • J) • N = I • J • N := le_antisymm (smul_le.2 fun _ hrsij t htn ↦ smul_induction_on hrsij (fun r hr s hs ↦ smul_assoc r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn)) fun x y ↦ (add_smul x y t).symm ▸ add_mem) (smul_le.2 fun r hr _ hsn ↦ smul_induction_on hsn (fun j hj n hn ↦ (smul_assoc r j n).symm ▸ smul_mem_smul (smul_mem_smul hr hj) hn) fun m₁ m₂ ↦ (smul_add r m₁ m₂) ▸ add_mem) theorem smul_iSup {ι : Sort*} {I : Submodule R A} {t : ι → Submodule R M} : I • (⨆ i, t i)= ⨆ i, I • t i := toAddSubmonoid_injective <| by simp only [smul_toAddSubmonoid, iSup_toAddSubmonoid, AddSubmonoid.smul_iSup] theorem iSup_smul {ι : Sort*} {t : ι → Submodule R A} {N : Submodule R M} : (⨆ i, t i) • N = ⨆ i, t i • N := le_antisymm (smul_le.mpr fun t ht s hs ↦ iSup_induction _ (motive := (· • s ∈ _)) ht (fun i t ht ↦ mem_iSup_of_mem i <| smul_mem_smul ht hs) (by simp_rw [zero_smul]; apply zero_mem) fun x y ↦ by simp_rw [add_smul]; apply add_mem) (iSup_le fun i ↦ Submodule.smul_mono_left <| le_iSup _ i) protected theorem one_smul : (1 : Submodule R A) • N = N := by refine le_antisymm (smul_le.mpr fun r hr m hm ↦ ?_) fun m hm ↦ ?_ · obtain ⟨r, rfl⟩ := hr rw [LinearMap.toSpanSingleton_apply, smul_one_smul]; exact N.smul_mem r hm · rw [← one_smul A m]; exact smul_mem_smul (one_le.mp le_rfl) hm theorem smul_subset_smul : (↑I : Set A) • (↑N : Set M) ⊆ (↑(I • N) : Set M) := AddSubmonoid.smul_subset_smul end variable [IsScalarTower R A A] /-- Multiplication of sub-R-modules of an R-module A that is also a semiring. The submodule `M * N` consists of finite sums of elements `m * n` for `m ∈ M` and `n ∈ N`. -/ instance mul : Mul (Submodule R A) where mul := (· • ·) variable (S T : Set A) {M N P Q : Submodule R A} {m n : A} theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := smul_mem_smul hm hn theorem mul_le : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P := smul_le theorem mul_toAddSubmonoid (M N : Submodule R A) : (M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := rfl @[elab_as_elim] protected theorem mul_induction_on {C : A → Prop} {r : A} (hr : r ∈ M * N) (hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := smul_induction_on hr hm ha /-- A dependent version of `mul_induction_on`. -/ @[elab_as_elim] protected theorem mul_induction_on' {C : ∀ r, r ∈ M * N → Prop} (mem_mul_mem : ∀ m (hm : m ∈ M) n (hn : n ∈ N), C (m * n) (mul_mem_mul hm hn)) (add : ∀ x hx y hy, C x hx → C y hy → C (x + y) (add_mem hx hy)) {r : A} (hr : r ∈ M * N) : C r hr := smul_induction_on' hr mem_mul_mem add variable (M) @[simp] theorem mul_bot : M * ⊥ = ⊥ := smul_bot _ @[simp] theorem bot_mul : ⊥ * M = ⊥ := bot_smul _ protected theorem one_mul : (1 : Submodule R A) * M = M := Submodule.one_smul _ variable {M} instance : MulLeftMono (Submodule R A) where elim _M _N _P hNP := smul_mono_right _ hNP instance : MulRightMono (Submodule R A) where elim _ _ _ := smul_mono_left theorem mul_comm_of_commute (h : ∀ m ∈ M, ∀ n ∈ N, Commute m n) : M * N = N * M := toAddSubmonoid_injective <| AddSubmonoid.mul_comm_of_commute h variable (M N P) theorem mul_sup : M * (N ⊔ P) = M * N ⊔ M * P := smul_sup _ _ _ theorem sup_mul : (M ⊔ N) * P = M * P ⊔ N * P := sup_smul _ _ _ theorem mul_subset_mul : (↑M : Set A) * (↑N : Set A) ⊆ (↑(M * N) : Set A) := smul_subset_smul _ _ lemma restrictScalars_mul {A B C} [Semiring A] [Semiring B] [Semiring C] [SMul A B] [Module A C] [Module B C] [IsScalarTower A C C] [IsScalarTower B C C] [IsScalarTower A B C] {I J : Submodule B C} : (I * J).restrictScalars A = I.restrictScalars A * J.restrictScalars A := rfl variable {ι : Sort uι} theorem iSup_mul (s : ι → Submodule R A) (t : Submodule R A) : (⨆ i, s i) * t = ⨆ i, s i * t := iSup_smul theorem mul_iSup (t : Submodule R A) (s : ι → Submodule R A) : (t * ⨆ i, s i) = ⨆ i, t * s i := smul_iSup /-- Sub-`R`-modules of an `R`-module form an idempotent semiring. -/ instance : NonUnitalSemiring (Submodule R A) where __ := toAddSubmonoid_injective.semigroup _ mul_toAddSubmonoid zero_mul := bot_mul mul_zero := mul_bot left_distrib := mul_sup right_distrib := sup_mul instance : Pow (Submodule R A) ℕ where pow s n := npowRec n s theorem pow_eq_npowRec {n : ℕ} : M ^ n = npowRec n M := rfl protected theorem pow_zero : M ^ 0 = 1 := rfl protected theorem pow_succ {n : ℕ} : M ^ (n + 1) = M ^ n * M := rfl protected theorem pow_add {m n : ℕ} (h : n ≠ 0) : M ^ (m + n) = M ^ m * M ^ n := npowRec_add m n h _ M.one_mul protected theorem pow_one : M ^ 1 = M := by rw [Submodule.pow_succ, Submodule.pow_zero, Submodule.one_mul] /-- `Submodule.pow_succ` with the right-hand side commuted. -/ protected theorem pow_succ' {n : ℕ} (h : n ≠ 0) : M ^ (n + 1) = M * M ^ n := by rw [add_comm, M.pow_add h, Submodule.pow_one] @[simp] theorem bot_pow : ∀ {n : ℕ}, n ≠ 0 → (⊥ : Submodule R A) ^ n = ⊥ | 1, _ => Submodule.pow_one _ | n + 2, _ => by rw [Submodule.pow_succ, bot_pow n.succ_ne_zero, bot_mul] theorem pow_toAddSubmonoid {n : ℕ} (h : n ≠ 0) : (M ^ n).toAddSubmonoid = M.toAddSubmonoid ^ n := by induction n with | zero => exact (h rfl).elim | succ n ih => rw [Submodule.pow_succ, pow_succ, mul_toAddSubmonoid] cases n with | zero => rw [Submodule.pow_zero, pow_zero, one_mul, ← mul_toAddSubmonoid, Submodule.one_mul] | succ n => rw [ih n.succ_ne_zero] theorem le_pow_toAddSubmonoid {n : ℕ} : M.toAddSubmonoid ^ n ≤ (M ^ n).toAddSubmonoid := by obtain rfl | hn := Decidable.eq_or_ne n 0 · rw [Submodule.pow_zero, pow_zero] exact le_one_toAddSubmonoid · exact (pow_toAddSubmonoid M hn).ge theorem pow_subset_pow {n : ℕ} : (↑M : Set A) ^ n ⊆ ↑(M ^ n : Submodule R A) := trans AddSubmonoid.pow_subset_pow (le_pow_toAddSubmonoid M) theorem pow_mem_pow {x : A} (hx : x ∈ M) (n : ℕ) : x ^ n ∈ M ^ n := pow_subset_pow _ <| Set.pow_mem_pow hx lemma restrictScalars_pow {A B C : Type*} [Semiring A] [Semiring B] [Semiring C] [SMul A B] [Module A C] [Module B C] [IsScalarTower A C C] [IsScalarTower B C C] [IsScalarTower A B C] {I : Submodule B C} : ∀ {n : ℕ}, (hn : n ≠ 0) → (I ^ n).restrictScalars A = I.restrictScalars A ^ n | 1, _ => by simp [Submodule.pow_one] | n + 2, _ => by simp [Submodule.pow_succ (n := n + 1), restrictScalars_mul, restrictScalars_pow n.succ_ne_zero] end Module variable {ι : Sort uι} variable {R : Type u} [CommSemiring R] section AlgebraSemiring variable {A : Type v} [Semiring A] [Algebra R A] variable (S T : Set A) {M N P Q : Submodule R A} {m n : A} theorem one_eq_range : (1 : Submodule R A) = LinearMap.range (Algebra.linearMap R A) := by rw [one_eq_span, LinearMap.span_singleton_eq_range, LinearMap.toSpanSingleton_eq_algebra_linearMap] theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : Submodule R A) := by simp [one_eq_range] @[simp] theorem mem_one {x : A} : x ∈ (1 : Submodule R A) ↔ ∃ y, algebraMap R A y = x := by simp [one_eq_range] theorem smul_one_eq_span (x : A) : x • (1 : Submodule R A) = span R {x} := by rw [one_eq_span, smul_span, smul_set_singleton, smul_eq_mul, mul_one] protected theorem map_one {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') : map f.toLinearMap (1 : Submodule R A) = 1 := by ext simp @[simp] theorem map_op_one : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R A) = 1 := by ext x induction x simp @[simp] theorem comap_op_one : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R Aᵐᵒᵖ) = 1 := by ext simp @[simp] theorem map_unop_one : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R Aᵐᵒᵖ) = 1 := by rw [← comap_equiv_eq_map_symm, comap_op_one] @[simp] theorem comap_unop_one : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R A) = 1 := by rw [← map_equiv_eq_comap_symm, map_op_one] theorem mul_eq_map₂ : M * N = map₂ (LinearMap.mul R A) M N := le_antisymm (mul_le.mpr fun _m hm _n ↦ apply_mem_map₂ _ hm) (map₂_le.mpr fun _m hm _n ↦ mul_mem_mul hm) variable (R M N) theorem span_mul_span : span R S * span R T = span R (S * T) := by rw [mul_eq_map₂]; apply map₂_span_span lemma mul_def : M * N = span R (M * N : Set A) := by simp [← span_mul_span] variable {R} (P Q) protected theorem mul_one : M * 1 = M := by conv_lhs => rw [one_eq_span, ← span_eq M] rw [span_mul_span] simp protected theorem map_mul {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') : map f.toLinearMap (M * N) = map f.toLinearMap M * map f.toLinearMap N := calc map f.toLinearMap (M * N) = ⨆ i : M, (N.map (LinearMap.mul R A i)).map f.toLinearMap := by rw [mul_eq_map₂]; apply map_iSup _ = map f.toLinearMap M * map f.toLinearMap N := by rw [mul_eq_map₂] apply congr_arg sSup ext S constructor <;> rintro ⟨y, hy⟩ · use ⟨f y, mem_map.mpr ⟨y.1, y.2, rfl⟩⟩ refine Eq.trans ?_ hy ext simp · obtain ⟨y', hy', fy_eq⟩ := mem_map.mp y.2 use ⟨y', hy'⟩ refine Eq.trans ?_ hy rw [f.toLinearMap_apply] at fy_eq ext simp [fy_eq] theorem map_op_mul : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) = map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N * map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by apply le_antisymm · simp_rw [map_le_iff_le_comap] refine mul_le.2 fun m hm n hn => ?_ rw [mem_comap, map_equiv_eq_comap_symm, map_equiv_eq_comap_symm] change op n * op m ∈ _ exact mul_mem_mul hn hm · refine mul_le.2 (MulOpposite.rec' fun m hm => MulOpposite.rec' fun n hn => ?_) rw [Submodule.mem_map_equiv] at hm hn ⊢ exact mul_mem_mul hn hm theorem comap_unop_mul : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) = comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N * comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := by simp_rw [← map_equiv_eq_comap_symm, map_op_mul] theorem map_unop_mul (M N : Submodule R Aᵐᵒᵖ) : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) = map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N * map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := have : Function.Injective (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) := LinearEquiv.injective _ map_injective_of_injective this <| by rw [← map_comp, map_op_mul, ← map_comp, ← map_comp, LinearEquiv.comp_coe, LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, map_id, map_id, map_id] theorem comap_op_mul (M N : Submodule R Aᵐᵒᵖ) : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) = comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N * comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by simp_rw [comap_equiv_eq_map_symm, map_unop_mul] section variable {α : Type*} [Monoid α] [DistribMulAction α A] [SMulCommClass α R A] instance [IsScalarTower α A A] : IsScalarTower α (Submodule R A) (Submodule R A) where smul_assoc a S T := by rw [← S.span_eq, ← T.span_eq, smul_span, smul_eq_mul, smul_eq_mul, span_mul_span, span_mul_span, smul_span, smul_mul_assoc] instance [SMulCommClass α A A] : SMulCommClass α (Submodule R A) (Submodule R A) where smul_comm a S T := by rw [← S.span_eq, ← T.span_eq, smul_span, smul_eq_mul, smul_eq_mul, span_mul_span, span_mul_span, smul_span, mul_smul_comm] instance [SMulCommClass A α A] : SMulCommClass (Submodule R A) α (Submodule R A) := have := SMulCommClass.symm A α A; .symm .. end section open Pointwise /-- `Submodule.pointwiseNeg` distributes over multiplication. This is available as an instance in the `Pointwise` locale. -/ protected def hasDistribPointwiseNeg {A} [Ring A] [Algebra R A] : HasDistribNeg (Submodule R A) := toAddSubmonoid_injective.hasDistribNeg _ neg_toAddSubmonoid mul_toAddSubmonoid scoped[Pointwise] attribute [instance] Submodule.hasDistribPointwiseNeg end section DecidableEq theorem mem_span_mul_finite_of_mem_span_mul {R A} [Semiring R] [AddCommMonoid A] [Mul A] [Module R A] {S : Set A} {S' : Set A} {x : A} (hx : x ∈ span R (S * S')) : ∃ T T' : Finset A, ↑T ⊆ S ∧ ↑T' ⊆ S' ∧ x ∈ span R (T * T' : Set A) := by classical obtain ⟨U, h, hU⟩ := mem_span_finite_of_mem_span hx obtain ⟨T, T', hS, hS', h⟩ := Finset.subset_mul h use T, T', hS, hS' have h' : (U : Set A) ⊆ T * T' := by assumption_mod_cast have h'' := span_mono h' hU assumption end DecidableEq theorem mul_eq_span_mul_set (s t : Submodule R A) : s * t = span R ((s : Set A) * (t : Set A)) := by rw [mul_eq_map₂]; exact map₂_eq_span_image2 _ s t theorem mem_span_mul_finite_of_mem_mul {P Q : Submodule R A} {x : A} (hx : x ∈ P * Q) : ∃ T T' : Finset A, (T : Set A) ⊆ P ∧ (T' : Set A) ⊆ Q ∧ x ∈ span R (T * T' : Set A) := Submodule.mem_span_mul_finite_of_mem_span_mul (by rwa [← Submodule.span_eq P, ← Submodule.span_eq Q, Submodule.span_mul_span] at hx) variable {M N P} theorem mem_span_singleton_mul {x y : A} : x ∈ span R {y} * P ↔ ∃ z ∈ P, y * z = x := by simp_rw [mul_eq_map₂, map₂_span_singleton_eq_map, mem_map, LinearMap.mul_apply_apply] theorem mem_mul_span_singleton {x y : A} : x ∈ P * span R {y} ↔ ∃ z ∈ P, z * y = x := by simp_rw [mul_eq_map₂, map₂_span_singleton_eq_map_flip, mem_map, LinearMap.flip_apply, LinearMap.mul_apply_apply] lemma span_singleton_mul {x : A} {p : Submodule R A} : Submodule.span R {x} * p = x • p := ext fun _ ↦ mem_span_singleton_mul lemma mem_smul_iff_inv_mul_mem {S} [DivisionSemiring S] [Algebra R S] {x : S} {p : Submodule R S} {y : S} (hx : x ≠ 0) : y ∈ x • p ↔ x⁻¹ * y ∈ p := by constructor · rintro ⟨a, ha : a ∈ p, rfl⟩; simpa [inv_mul_cancel_left₀ hx] · exact fun h ↦ ⟨_, h, by simp [mul_inv_cancel_left₀ hx]⟩ lemma mul_mem_smul_iff {S} [Ring S] [Algebra R S] {x : S} {p : Submodule R S} {y : S} (hx : x ∈ nonZeroDivisors S) : x * y ∈ x • p ↔ y ∈ p := by simp [mem_smul_pointwise_iff_exists, mul_cancel_left_mem_nonZeroDivisors hx] variable (M N) in theorem mul_smul_mul_eq_smul_mul_smul (x y : R) : (x * y) • (M * N) = (x • M) * (y • N) := mul_smul_mul_comm x y M N /-- Sub-R-modules of an R-algebra form an idempotent semiring. -/ instance idemSemiring : IdemSemiring (Submodule R A) where __ := instNonUnitalSemiring one_mul := Submodule.one_mul mul_one := Submodule.mul_one bot_le _ := bot_le instance : IsOrderedRing (Submodule R A) where variable (M) theorem span_pow (s : Set A) : ∀ n : ℕ, span R s ^ n = span R (s ^ n) | 0 => by rw [pow_zero, pow_zero, one_eq_span_one_set] | n + 1 => by rw [pow_succ, pow_succ, span_pow s n, span_mul_span] theorem pow_eq_span_pow_set (n : ℕ) : M ^ n = span R ((M : Set A) ^ n) := by rw [← span_pow, span_eq] /-- Dependent version of `Submodule.pow_induction_on_left`. -/ @[elab_as_elim] protected theorem pow_induction_on_left' {C : ∀ (n : ℕ) (x), x ∈ M ^ n → Prop} (algebraMap : ∀ r : R, C 0 (algebraMap _ _ r) (algebraMap_mem r)) (add : ∀ x y i hx hy, C i x hx → C i y hy → C i (x + y) (add_mem ‹_› ‹_›)) (mem_mul : ∀ m (hm : m ∈ M), ∀ (i x hx), C i x hx → C i.succ (m * x) ((pow_succ' M i).symm ▸ (mul_mem_mul hm hx))) {n : ℕ} {x : A} (hx : x ∈ M ^ n) : C n x hx := by induction n generalizing x with | zero => rw [pow_zero] at hx obtain ⟨r, rfl⟩ := mem_one.mp hx exact algebraMap r | succ n n_ih => revert hx simp_rw [pow_succ'] exact fun hx ↦ Submodule.mul_induction_on' (fun m hm x ih => mem_mul _ hm _ _ _ (n_ih ih)) (fun x hx y hy Cx Cy => add _ _ _ _ _ Cx Cy) hx /-- Dependent version of `Submodule.pow_induction_on_right`. -/ @[elab_as_elim] protected theorem pow_induction_on_right' {C : ∀ (n : ℕ) (x), x ∈ M ^ n → Prop} (algebraMap : ∀ r : R, C 0 (algebraMap _ _ r) (algebraMap_mem r)) (add : ∀ x y i hx hy, C i x hx → C i y hy → C i (x + y) (add_mem ‹_› ‹_›)) (mul_mem : ∀ i x hx, C i x hx → ∀ m (hm : m ∈ M), C i.succ (x * m) (mul_mem_mul hx hm)) {n : ℕ} {x : A} (hx : x ∈ M ^ n) : C n x hx := by induction n generalizing x with | zero => rw [pow_zero] at hx obtain ⟨r, rfl⟩ := mem_one.mp hx exact algebraMap r | succ n n_ih => revert hx simp_rw [pow_succ] exact fun hx ↦ Submodule.mul_induction_on' (fun m hm x ih => mul_mem _ _ hm (n_ih _) _ ih) (fun x hx y hy Cx Cy => add _ _ _ _ _ Cx Cy) hx /-- To show a property on elements of `M ^ n` holds, it suffices to show that it holds for scalars, is closed under addition, and holds for `m * x` where `m ∈ M` and it holds for `x` -/ @[elab_as_elim] protected theorem pow_induction_on_left {C : A → Prop} (hr : ∀ r : R, C (algebraMap _ _ r)) (hadd : ∀ x y, C x → C y → C (x + y)) (hmul : ∀ m ∈ M, ∀ (x), C x → C (m * x)) {x : A} {n : ℕ} (hx : x ∈ M ^ n) : C x := Submodule.pow_induction_on_left' M (C := fun _ a _ => C a) hr (fun x y _i _hx _hy => hadd x y) (fun _m hm _i _x _hx => hmul _ hm _) hx /-- To show a property on elements of `M ^ n` holds, it suffices to show that it holds for scalars, is closed under addition, and holds for `x * m` where `m ∈ M` and it holds for `x` -/ @[elab_as_elim] protected theorem pow_induction_on_right {C : A → Prop} (hr : ∀ r : R, C (algebraMap _ _ r)) (hadd : ∀ x y, C x → C y → C (x + y)) (hmul : ∀ x, C x → ∀ m ∈ M, C (x * m)) {x : A} {n : ℕ} (hx : x ∈ M ^ n) : C x := Submodule.pow_induction_on_right' (M := M) (C := fun _ a _ => C a) hr (fun x y _i _hx _hy => hadd x y) (fun _i _x _hx => hmul _) hx /-- `Submonoid.map` as a `RingHom`, when applied to an `AlgHom`. -/ @[simps] def mapHom {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') : Submodule R A →+* Submodule R A' where toFun := map f.toLinearMap map_zero' := Submodule.map_bot _ map_add' := (Submodule.map_sup · · _) map_one' := Submodule.map_one _ map_mul' := (Submodule.map_mul · · _) theorem mapHom_id : mapHom (.id R A) = .id _ := RingHom.ext map_id /-- The ring of submodules of the opposite algebra is isomorphic to the opposite ring of submodules. -/ @[simps apply symm_apply] def equivOpposite : Submodule R Aᵐᵒᵖ ≃+* (Submodule R A)ᵐᵒᵖ where toFun p := op <| p.comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) invFun p := p.unop.comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) left_inv _ := SetLike.coe_injective <| rfl right_inv _ := unop_injective <| SetLike.coe_injective rfl map_add' p q := by simp [comap_equiv_eq_map_symm, ← op_add] map_mul' _ _ := congr_arg op <| comap_op_mul _ _ protected theorem map_pow {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') (n : ℕ) : map f.toLinearMap (M ^ n) = map f.toLinearMap M ^ n := map_pow (mapHom f) M n theorem comap_unop_pow (n : ℕ) : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M ^ n) = comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M ^ n := (equivOpposite : Submodule R Aᵐᵒᵖ ≃+* _).symm.map_pow (op M) n theorem comap_op_pow (n : ℕ) (M : Submodule R Aᵐᵒᵖ) : comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M ^ n) = comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M ^ n := op_injective <| (equivOpposite : Submodule R Aᵐᵒᵖ ≃+* _).map_pow M n theorem map_op_pow (n : ℕ) : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M ^ n) = map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M ^ n := by rw [map_equiv_eq_comap_symm, map_equiv_eq_comap_symm, comap_unop_pow] theorem map_unop_pow (n : ℕ) (M : Submodule R Aᵐᵒᵖ) : map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M ^ n) = map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M ^ n := by rw [← comap_equiv_eq_map_symm, ← comap_equiv_eq_map_symm, comap_op_pow] /-- `span` is a semiring homomorphism (recall multiplication is pointwise multiplication of subsets on either side). -/ @[simps] noncomputable def span.ringHom : SetSemiring A →+* Submodule R A where toFun s := Submodule.span R (SetSemiring.down s) map_zero' := span_empty map_one' := one_eq_span.symm map_add' := span_union map_mul' s t := by simp_rw [SetSemiring.down_mul, span_mul_span] section variable {α : Type*} [Monoid α] [MulSemiringAction α A] [SMulCommClass α R A] /-- The action on a submodule corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. This is a stronger version of `Submodule.pointwiseDistribMulAction`. -/ protected def pointwiseMulSemiringAction : MulSemiringAction α (Submodule R A) where __ := Submodule.pointwiseDistribMulAction smul_mul r x y := Submodule.map_mul x y <| MulSemiringAction.toAlgHom R A r smul_one r := Submodule.map_one <| MulSemiringAction.toAlgHom R A r scoped[Pointwise] attribute [instance] Submodule.pointwiseMulSemiringAction end end AlgebraSemiring section AlgebraCommSemiring variable {A : Type v} [CommSemiring A] [Algebra R A] variable {M N : Submodule R A} {m n : A} theorem mul_mem_mul_rev (hm : m ∈ M) (hn : n ∈ N) : n * m ∈ M * N := mul_comm m n ▸ mul_mem_mul hm hn variable (M N) protected theorem mul_comm : M * N = N * M := le_antisymm (mul_le.2 fun _r hrm _s hsn => mul_mem_mul_rev hsn hrm) (mul_le.2 fun _r hrn _s hsm => mul_mem_mul_rev hsm hrn) /-- Sub-R-modules of an R-algebra A form a semiring. -/ instance : IdemCommSemiring (Submodule R A) := { Submodule.idemSemiring with mul_comm := Submodule.mul_comm } theorem prod_span {ι : Type*} (s : Finset ι) (M : ι → Set A) : (∏ i ∈ s, Submodule.span R (M i)) = Submodule.span R (∏ i ∈ s, M i) := by letI := Classical.decEq ι refine Finset.induction_on s ?_ ?_ · simp [one_eq_span, Set.singleton_one] · intro _ _ H ih rw [Finset.prod_insert H, Finset.prod_insert H, ih, span_mul_span] theorem prod_span_singleton {ι : Type*} (s : Finset ι) (x : ι → A) : (∏ i ∈ s, span R ({x i} : Set A)) = span R {∏ i ∈ s, x i} := by rw [prod_span, Set.finset_prod_singleton] variable (R A) /-- R-submodules of the R-algebra A are a module over `Set A`. -/ noncomputable instance moduleSet : Module (SetSemiring A) (Submodule R A) where smul s P := span R (SetSemiring.down s) * P smul_add _ _ _ := mul_add _ _ _ add_smul s t P := by simp_rw [HSMul.hSMul, SetSemiring.down_add, span_union, sup_mul, add_eq_sup] mul_smul s t P := by simp_rw [HSMul.hSMul, SetSemiring.down_mul, ← mul_assoc, span_mul_span] one_smul P := by simp_rw [HSMul.hSMul, SetSemiring.down_one, ← one_eq_span_one_set, one_mul] zero_smul P := by simp_rw [HSMul.hSMul, SetSemiring.down_zero, span_empty, bot_mul, bot_eq_zero] smul_zero _ := mul_bot _ variable {R A} theorem setSemiring_smul_def (s : SetSemiring A) (P : Submodule R A) : s • P = span R (SetSemiring.down (α := A) s) * P := rfl theorem smul_le_smul {s t : SetSemiring A} {M N : Submodule R A} (h₁ : SetSemiring.down (α := A) s ⊆ SetSemiring.down (α := A) t) (h₂ : M ≤ N) : s • M ≤ t • N := mul_le_mul' (span_mono h₁) h₂ theorem singleton_smul (a : A) (M : Submodule R A) : Set.up ({a} : Set A) • M = M.map (LinearMap.mulLeft R a) := by conv_lhs => rw [← span_eq M] rw [setSemiring_smul_def, SetSemiring.down_up, span_mul_span, singleton_mul] exact (map (LinearMap.mulLeft R a) M).span_eq section Quotient /-- The elements of `I / J` are the `x` such that `x • J ⊆ I`. In fact, we define `x ∈ I / J` to be `∀ y ∈ J, x * y ∈ I` (see `mem_div_iff_forall_mul_mem`), which is equivalent to `x • J ⊆ I` (see `mem_div_iff_smul_subset`), but nicer to use in proofs. This is the general form of the ideal quotient, traditionally written $I : J$. -/ instance : Div (Submodule R A) := ⟨fun I J => { carrier := { x | ∀ y ∈ J, x * y ∈ I } zero_mem' := fun y _ => by rw [zero_mul] apply Submodule.zero_mem add_mem' := fun ha hb y hy => by rw [add_mul] exact Submodule.add_mem _ (ha _ hy) (hb _ hy) smul_mem' := fun r x hx y hy => by rw [Algebra.smul_mul_assoc] exact Submodule.smul_mem _ _ (hx _ hy) }⟩ theorem mem_div_iff_forall_mul_mem {x : A} {I J : Submodule R A} : x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := Iff.refl _ theorem mem_div_iff_smul_subset {x : A} {I J : Submodule R A} : x ∈ I / J ↔ x • (J : Set A) ⊆ I := ⟨fun h y ⟨y', hy', xy'_eq_y⟩ => by rw [← xy'_eq_y]; exact h _ hy', fun h _ hy => h (Set.smul_mem_smul_set hy)⟩ theorem le_div_iff {I J K : Submodule R A} : I ≤ J / K ↔ ∀ x ∈ I, ∀ z ∈ K, x * z ∈ J := Iff.refl _ theorem le_div_iff_mul_le {I J K : Submodule R A} : I ≤ J / K ↔ I * K ≤ J := by rw [le_div_iff, mul_le] theorem one_le_one_div {I : Submodule R A} : 1 ≤ 1 / I ↔ I ≤ 1 := by rw [le_div_iff_mul_le, one_mul] @[simp] theorem one_mem_div {I J : Submodule R A} : 1 ∈ I / J ↔ J ≤ I := by rw [← one_le, le_div_iff_mul_le, one_mul] theorem le_self_mul_one_div {I : Submodule R A} (hI : I ≤ 1) : I ≤ I * (1 / I) := by simpa using mul_le_mul_left' (one_le_one_div.mpr hI) _ theorem mul_one_div_le_one {I : Submodule R A} : I * (1 / I) ≤ 1 := by rw [Submodule.mul_le] intro m hm n hn rw [Submodule.mem_div_iff_forall_mul_mem] at hn rw [mul_comm] exact hn m hm @[simp] protected theorem map_div {B : Type*} [CommSemiring B] [Algebra R B] (I J : Submodule R A) (h : A ≃ₐ[R] B) : (I / J).map h.toLinearMap = I.map h.toLinearMap / J.map h.toLinearMap := by ext x simp only [mem_map, mem_div_iff_forall_mul_mem, AlgEquiv.toLinearMap_apply] constructor · rintro ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ exact ⟨x * y, hx _ hy, map_mul h x y⟩ · rintro hx refine ⟨h.symm x, fun z hz => ?_, h.apply_symm_apply x⟩ obtain ⟨xz, xz_mem, hxz⟩ := hx (h z) ⟨z, hz, rfl⟩ convert xz_mem apply h.injective rw [map_mul, h.apply_symm_apply, hxz] end Quotient end AlgebraCommSemiring end Submodule
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Defs.lean
import Mathlib.Algebra.Module.LinearMap.Defs /-! # Algebras over commutative semirings In this file we define associative unital `Algebra`s over commutative (semi)rings. * algebra homomorphisms `AlgHom` are defined in `Mathlib/Algebra/Algebra/Hom.lean`; * algebra equivalences `AlgEquiv` are defined in `Mathlib/Algebra/Algebra/Equiv.lean`; * `Subalgebra`s are defined in `Mathlib/Algebra/Algebra/Subalgebra.lean`; * The category `AlgCat R` of `R`-algebras is defined in the file `Mathlib/Algebra/Category/Algebra/Basic.lean`. See the implementation notes for remarks about non-associative and non-unital algebras. ## Main definitions: * `Algebra R A`: the algebra typeclass. * `algebraMap R A : R →+* A`: the canonical map from `R` to `A`, as a `RingHom`. This is the preferred spelling of this map, it is also available as: * `Algebra.linearMap R A : R →ₗ[R] A`, a `LinearMap`. * `Algebra.ofId R A : R →ₐ[R] A`, an `AlgHom` (defined in a later file). ## Implementation notes Given a commutative (semi)ring `R`, there are two ways to define an `R`-algebra structure on a (possibly noncommutative) (semi)ring `A`: * By endowing `A` with a morphism of rings `R →+* A` denoted `algebraMap R A` which lands in the center of `A`. * By requiring `A` be an `R`-module such that the action associates and commutes with multiplication as `r • (a₁ * a₂) = (r • a₁) * a₂ = a₁ * (r • a₂)`. We define `Algebra R A` in a way that subsumes both definitions, by extending `SMul R A` and requiring that this scalar action `r • x` must agree with left multiplication by the image of the structure morphism `algebraMap R A r * x`. As a result, there are two ways to talk about an `R`-algebra `A` when `A` is a semiring: 1. ```lean variable [CommSemiring R] [Semiring A] variable [Algebra R A] ``` 2. ```lean variable [CommSemiring R] [Semiring A] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] ``` The first approach implies the second via typeclass search; so any lemma stated with the second set of arguments will automatically apply to the first set. Typeclass search does not know that the second approach implies the first, but this can be shown with: ```lean example {R A : Type*} [CommSemiring R] [Semiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] : Algebra R A := Algebra.ofModule smul_mul_assoc mul_smul_comm ``` The advantage of the first approach is that `algebraMap R A` is available, and `AlgHom R A B` and `Subalgebra R A` can be used. For concrete `R` and `A`, `algebraMap R A` is often definitionally convenient. The advantage of the second approach is that `CommSemiring R`, `Semiring A`, and `Module R A` can all be relaxed independently; for instance, this allows us to: * Replace `Semiring A` with `NonUnitalNonAssocSemiring A` in order to describe non-unital and/or non-associative algebras. * Replace `CommSemiring R` and `Module R A` with `CommGroup R'` and `DistribMulAction R' A`, which when `R' = Rˣ` lets us talk about the "algebra-like" action of `Rˣ` on an `R`-algebra `A`. While `AlgHom R A B` cannot be used in the second approach, `NonUnitalAlgHom R A B` still can. You should always use the first approach when working with associative unital algebras, and mimic the second approach only when you need to weaken a condition on either `R` or `A`. -/ assert_not_exists Field Finset Module.End universe u v w u₁ v₁ section Prio /-- An associative unital `R`-algebra is a semiring `A` equipped with a map into its center `R → A`. See the implementation notes in this file for discussion of the details of this definition. -/ class Algebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] extends SMul R A where /-- Embedding `R →+* A` given by `Algebra` structure. Use `algebraMap` from the root namespace instead. -/ protected algebraMap : R →+* A commutes' : ∀ r x, algebraMap r * x = x * algebraMap r smul_def' : ∀ r x, r • x = algebraMap r * x end Prio /-- Embedding `R →+* A` given by `Algebra` structure. -/ def algebraMap (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : R →+* A := Algebra.algebraMap theorem Algebra.subsingleton (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] [Subsingleton R] : Subsingleton A := (algebraMap R A).codomain_trivial /-- Coercion from a commutative semiring to an algebra over this semiring. -/ @[coe, reducible] def Algebra.cast {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] : R → A := algebraMap R A namespace algebraMap scoped instance coeHTCT (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] : CoeHTCT R A := ⟨Algebra.cast⟩ section CommSemiringSemiring variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] @[norm_cast] theorem coe_zero : (↑(0 : R) : A) = 0 := map_zero (algebraMap R A) @[norm_cast] theorem coe_one : (↑(1 : R) : A) = 1 := map_one (algebraMap R A) @[norm_cast] theorem coe_natCast (a : ℕ) : (↑(a : R) : A) = a := map_natCast (algebraMap R A) a @[norm_cast] theorem coe_add (a b : R) : (↑(a + b : R) : A) = ↑a + ↑b := map_add (algebraMap R A) a b @[norm_cast] theorem coe_mul (a b : R) : (↑(a * b : R) : A) = ↑a * ↑b := map_mul (algebraMap R A) a b @[norm_cast] theorem coe_pow (a : R) (n : ℕ) : (↑(a ^ n : R) : A) = (a : A) ^ n := map_pow (algebraMap R A) _ _ end CommSemiringSemiring section CommRingRing variable {R A : Type*} [CommRing R] [Ring A] [Algebra R A] @[norm_cast] theorem coe_neg (x : R) : (↑(-x : R) : A) = -↑x := map_neg (algebraMap R A) x @[norm_cast] theorem coe_sub (a b : R) : (↑(a - b : R) : A) = ↑a - ↑b := map_sub (algebraMap R A) a b end CommRingRing end algebraMap /-- Creating an algebra from a morphism to the center of a semiring. See note [reducible non-instances]. *Warning:* In general this should not be used if `S` already has a `SMul R S` instance, since this creates another `SMul R S` instance from the supplied `RingHom` and this will likely create a diamond. -/ abbrev RingHom.toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S) (h : ∀ c x, i c * x = x * i c) : Algebra R S where smul c x := i c * x commutes' := h smul_def' _ _ := rfl algebraMap := i -- just simple lemmas for a declaration that is itself primed, no need for docstrings set_option linter.docPrime false in theorem RingHom.smul_toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S) (h : ∀ c x, i c * x = x * i c) (r : R) (s : S) : let _ := RingHom.toAlgebra' i h r • s = i r * s := rfl set_option linter.docPrime false in theorem RingHom.algebraMap_toAlgebra' {R S} [CommSemiring R] [Semiring S] (i : R →+* S) (h : ∀ c x, i c * x = x * i c) : @algebraMap R S _ _ (i.toAlgebra' h) = i := rfl /-- Creating an algebra from a morphism to a commutative semiring. See note [reducible non-instances]. *Warning:* In general this should not be used if `S` already has a `SMul R S` instance, since this creates another `SMul R S` instance from the supplied `RingHom` and this will likely create a diamond. -/ abbrev RingHom.toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : Algebra R S := i.toAlgebra' fun _ => mul_comm _ theorem RingHom.smul_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) (r : R) (s : S) : let _ := RingHom.toAlgebra i r • s = i r * s := rfl theorem RingHom.algebraMap_toAlgebra {R S} [CommSemiring R] [CommSemiring S] (i : R →+* S) : @algebraMap R S _ _ i.toAlgebra = i := rfl namespace Algebra variable {R : Type u} {S : Type v} {A : Type w} {B : Type*} /-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure. If `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `Algebra` over `R`. See note [reducible non-instances]. -/ abbrev ofModule' [CommSemiring R] [Semiring A] [Module R A] (h₁ : ∀ (r : R) (x : A), r • (1 : A) * x = r • x) (h₂ : ∀ (r : R) (x : A), x * r • (1 : A) = r • x) : Algebra R A where algebraMap := { toFun r := r • (1 : A) map_one' := one_smul _ _ map_mul' r₁ r₂ := by simp only [h₁, mul_smul] map_zero' := zero_smul _ _ map_add' r₁ r₂ := add_smul r₁ r₂ 1 } commutes' r x := by simp [h₁, h₂] smul_def' r x := by simp [h₁] /-- Let `R` be a commutative semiring, let `A` be a semiring with a `Module R` structure. If `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A` is an `Algebra` over `R`. See note [reducible non-instances]. -/ abbrev ofModule [CommSemiring R] [Semiring A] [Module R A] (h₁ : ∀ (r : R) (x y : A), r • x * y = r • (x * y)) (h₂ : ∀ (r : R) (x y : A), x * r • y = r • (x * y)) : Algebra R A := ofModule' (fun r x => by rw [h₁, one_mul]) fun r x => by rw [h₂, mul_one] section Semiring variable [CommSemiring R] [CommSemiring S] variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] -- We'll later use this to show `Algebra ℤ M` is a subsingleton. /-- To prove two algebra structures on a fixed `[CommSemiring R] [Semiring A]` agree, it suffices to check the `algebraMap`s agree. -/ @[ext] theorem algebra_ext {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] (P Q : Algebra R A) (h : ∀ r : R, (haveI := P; algebraMap R A r) = haveI := Q; algebraMap R A r) : P = Q := by replace h : P.algebraMap = Q.algebraMap := DFunLike.ext _ _ h have h' : (haveI := P; (· • ·) : R → A → A) = (haveI := Q; (· • ·) : R → A → A) := by funext r a rw [P.smul_def', Q.smul_def', h] rcases P with @⟨⟨P⟩⟩ congr /-- An auxiliary lemma used to prove theorems of the form `RingHom.X (algebraMap R S) ↔ Algebra.X R S`. -/ lemma _root_.toAlgebra_algebraMap [Algebra R S] : (algebraMap R S).toAlgebra = ‹_› := algebra_ext _ _ fun _ ↦ rfl -- see Note [lower instance priority] instance (priority := 200) toModule {R A} {_ : CommSemiring R} {_ : Semiring A} [Algebra R A] : Module R A where one_smul _ := by simp [smul_def'] mul_smul := by simp [smul_def', mul_assoc] smul_add := by simp [smul_def', mul_add] smul_zero := by simp [smul_def'] add_smul := by simp [smul_def', add_mul] zero_smul := by simp [smul_def'] theorem smul_def (r : R) (x : A) : r • x = algebraMap R A r * x := Algebra.smul_def' r x theorem algebraMap_eq_smul_one (r : R) : algebraMap R A r = r • (1 : A) := calc algebraMap R A r = algebraMap R A r * 1 := (mul_one _).symm _ = r • (1 : A) := (Algebra.smul_def r 1).symm theorem algebraMap_eq_smul_one' : ⇑(algebraMap R A) = fun r => r • (1 : A) := funext algebraMap_eq_smul_one /-- `mul_comm` for `Algebra`s when one element is from the base ring. -/ theorem commutes (r : R) (x : A) : algebraMap R A r * x = x * algebraMap R A r := Algebra.commutes' r x lemma commute_algebraMap_left (r : R) (x : A) : Commute (algebraMap R A r) x := Algebra.commutes r x lemma commute_algebraMap_right (r : R) (x : A) : Commute x (algebraMap R A r) := (Algebra.commutes r x).symm /-- `mul_left_comm` for `Algebra`s when one element is from the base ring. -/ theorem left_comm (x : A) (r : R) (y : A) : x * (algebraMap R A r * y) = algebraMap R A r * (x * y) := by rw [← mul_assoc, ← commutes, mul_assoc] /-- `mul_right_comm` for `Algebra`s when one element is from the base ring. -/ theorem right_comm (x : A) (r : R) (y : A) : x * algebraMap R A r * y = x * y * algebraMap R A r := by rw [mul_assoc, commutes, ← mul_assoc] instance _root_.IsScalarTower.right : IsScalarTower R A A := ⟨fun x y z => by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩ @[simp] theorem _root_.RingHom.smulOneHom_eq_algebraMap : RingHom.smulOneHom = algebraMap R A := RingHom.ext fun r => (algebraMap_eq_smul_one r).symm -- TODO: set up `IsScalarTower.smulCommClass` earlier so that we can actually prove this using -- `mul_smul_comm s x y`. /-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass search (and was here first). -/ @[simp] protected theorem mul_smul_comm (s : R) (x y : A) : x * s • y = s • (x * y) := by rw [smul_def, smul_def, left_comm] /-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass search (and was here first). -/ @[simp] protected theorem smul_mul_assoc (r : R) (x y : A) : r • x * y = r • (x * y) := smul_mul_assoc r x y @[simp] theorem _root_.smul_algebraMap {α : Type*} [Monoid α] [MulDistribMulAction α A] [SMulCommClass α R A] (a : α) (r : R) : a • algebraMap R A r = algebraMap R A r := by rw [algebraMap_eq_smul_one, smul_comm a r (1 : A), smul_one] section compHom variable (A) (f : S →+* R) /-- Compose an `Algebra` with a `RingHom`, with action `f s • m`. This is the algebra version of `Module.compHom`. -/ abbrev compHom : Algebra S A where smul s a := f s • a algebraMap := (algebraMap R A).comp f commutes' _ _ := Algebra.commutes _ _ smul_def' _ _ := Algebra.smul_def _ _ theorem compHom_smul_def (s : S) (x : A) : letI := compHom A f s • x = f s • x := rfl theorem compHom_algebraMap_eq : letI := compHom A f algebraMap S A = (algebraMap R A).comp f := rfl theorem compHom_algebraMap_apply (s : S) : letI := compHom A f algebraMap S A s = (algebraMap R A) (f s) := rfl end compHom variable (R A) /-- The canonical ring homomorphism `algebraMap R A : R →+* A` for any `R`-algebra `A`, packaged as an `R`-linear map. -/ protected def linearMap : R →ₗ[R] A := { algebraMap R A with map_smul' := fun x y => by simp [Algebra.smul_def] } @[inherit_doc] scoped[RingTheory.LinearMap] notation "η" => Algebra.linearMap _ _ @[inherit_doc] scoped[RingTheory.LinearMap] notation "η[" R "]" => Algebra.linearMap R _ @[simp] theorem linearMap_apply (r : R) : Algebra.linearMap R A r = algebraMap R A r := rfl theorem coe_linearMap : ⇑(Algebra.linearMap R A) = algebraMap R A := rfl /-- The identity map inducing an `Algebra` structure. -/ instance (priority := 1100) id : Algebra R R where -- We override `toFun` and `toSMul` because `RingHom.id` is not reducible and cannot -- be made so without a significant performance hit. -- see library note [reducible non-instances]. toSMul := instSMulOfMul __ := ({RingHom.id R with toFun x := x}).toAlgebra @[simp] lemma linearMap_self : Algebra.linearMap R R = .id := rfl variable {R A} @[simp] lemma algebraMap_self : algebraMap R R = .id _ := rfl lemma algebraMap_self_apply (x : R) : algebraMap R R x = x := rfl namespace id @[deprecated algebraMap_self (since := "2025-07-17")] theorem map_eq_id : algebraMap R R = RingHom.id _ := rfl @[deprecated algebraMap_self_apply (since := "2025-07-17")] theorem map_eq_self (x : R) : algebraMap R R x = x := rfl @[simp] theorem smul_eq_mul (x y : R) : x • y = x * y := rfl end id end Semiring end Algebra section algebraMap variable {A B : Type*} (a : A) (b : B) (C : Type*) [SMul A B] [CommSemiring B] [Semiring C] [Algebra B C] @[norm_cast] theorem algebraMap.coe_smul [SMul A C] [IsScalarTower A B C] : (a • b : B) = a • (b : C) := by simp [Algebra.algebraMap_eq_smul_one] @[norm_cast] theorem algebraMap.coe_smul' [Monoid A] [MulDistribMulAction A C] [SMulDistribClass A B C] : (a • b : B) = a • (b : C) := by simp [Algebra.algebraMap_eq_smul_one, smul_distrib_smul] end algebraMap
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Shrink.lean
import Mathlib.Algebra.Algebra.TransferInstance import Mathlib.Algebra.Ring.Shrink /-! # Transfer module and algebra structures from `α` to `Shrink α` -/ noncomputable section universe v variable {R α : Type*} [Small.{v} α] [CommSemiring R] namespace Shrink instance [Semiring α] [Algebra R α] : Algebra R (Shrink.{v} α) := (equivShrink α).symm.algebra _ variable (R α) in /-- Shrinking `α` to a smaller universe preserves algebra structure. -/ @[simps!] def algEquiv [Small.{v} α] [Semiring α] [Algebra R α] : Shrink.{v} α ≃ₐ[R] α := (equivShrink α).symm.algEquiv _ end Shrink /-- A small algebra is algebra equivalent to its small model. -/ @[deprecated Shrink.algEquiv (since := "2025-07-11")] def algEquivShrink (α β) [CommSemiring α] [Semiring β] [Algebra α β] [Small β] : β ≃ₐ[α] Shrink β := ((equivShrink β).symm.algEquiv α).symm
.lake/packages/mathlib/Mathlib/Algebra/Algebra/NonUnitalSubalgebra.lean
import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.Data.Set.UnionLift import Mathlib.LinearAlgebra.Span.Basic import Mathlib.RingTheory.NonUnitalSubring.Basic /-! # Non-unital Subalgebras over Commutative Semirings In this file we define `NonUnitalSubalgebra`s and the usual operations on them (`map`, `comap`). ## TODO * once we have scalar actions by semigroups (as opposed to monoids), implement the action of a non-unital subalgebra on the larger algebra. -/ universe u u' v v' w w' section NonUnitalSubalgebraClass variable {S R A : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] variable [SetLike S A] [NonUnitalSubsemiringClass S A] [hSR : SMulMemClass S R A] (s : S) namespace NonUnitalSubalgebraClass /-- Embedding of a non-unital subalgebra into the non-unital algebra. -/ def subtype (s : S) : s →ₙₐ[R] A := { NonUnitalSubsemiringClass.subtype s, SMulMemClass.subtype s with toFun := (↑) } variable {s} in @[simp] lemma subtype_apply (x : s) : subtype s x = x := rfl lemma subtype_injective : Function.Injective (subtype s) := Subtype.coe_injective @[simp] theorem coe_subtype : (subtype s : s → A) = ((↑) : s → A) := rfl end NonUnitalSubalgebraClass end NonUnitalSubalgebraClass /-- A non-unital subalgebra is a sub(semi)ring that is also a submodule. -/ structure NonUnitalSubalgebra (R : Type u) (A : Type v) [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] : Type v extends NonUnitalSubsemiring A, Submodule R A /-- Reinterpret a `NonUnitalSubalgebra` as a `NonUnitalSubsemiring`. -/ add_decl_doc NonUnitalSubalgebra.toNonUnitalSubsemiring /-- Reinterpret a `NonUnitalSubalgebra` as a `Submodule`. -/ add_decl_doc NonUnitalSubalgebra.toSubmodule namespace NonUnitalSubalgebra variable {F : Type v'} {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'} section NonUnitalNonAssocSemiring variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [NonUnitalNonAssocSemiring C] variable [Module R A] [Module R B] [Module R C] instance : SetLike (NonUnitalSubalgebra R A) A where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h /-- The actual `NonUnitalSubalgebra` obtained from an element of a type satisfying `NonUnitalSubsemiringClass` and `SMulMemClass`. -/ @[simps] def ofClass {S R A : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] [SetLike S A] [NonUnitalSubsemiringClass S A] [SMulMemClass S R A] (s : S) : NonUnitalSubalgebra R A where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem smul_mem' := SMulMemClass.smul_mem instance (priority := 100) : CanLift (Set A) (NonUnitalSubalgebra R A) (↑) (fun s ↦ 0 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ ∀ (r : R) {x}, x ∈ s → r • x ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := h.1 add_mem' := h.2.1 mul_mem' := h.2.2.1 smul_mem' := h.2.2.2 }, rfl ⟩ instance instNonUnitalSubsemiringClass : NonUnitalSubsemiringClass (NonUnitalSubalgebra R A) A where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' zero_mem {s} := s.zero_mem' instance instSMulMemClass : SMulMemClass (NonUnitalSubalgebra R A) R A where smul_mem {s} := s.smul_mem' theorem mem_carrier {s : NonUnitalSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : NonUnitalSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] theorem mem_toNonUnitalSubsemiring {S : NonUnitalSubalgebra R A} {x} : x ∈ S.toNonUnitalSubsemiring ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toNonUnitalSubsemiring (S : NonUnitalSubalgebra R A) : (↑S.toNonUnitalSubsemiring : Set A) = S := rfl theorem toNonUnitalSubsemiring_injective : Function.Injective (toNonUnitalSubsemiring : NonUnitalSubalgebra R A → NonUnitalSubsemiring A) := fun S T h => ext fun x => by rw [← mem_toNonUnitalSubsemiring, ← mem_toNonUnitalSubsemiring, h] theorem toNonUnitalSubsemiring_inj {S U : NonUnitalSubalgebra R A} : S.toNonUnitalSubsemiring = U.toNonUnitalSubsemiring ↔ S = U := toNonUnitalSubsemiring_injective.eq_iff theorem mem_toSubmodule (S : NonUnitalSubalgebra R A) {x} : x ∈ S.toSubmodule ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubmodule (S : NonUnitalSubalgebra R A) : (↑S.toSubmodule : Set A) = S := rfl theorem toSubmodule_injective : Function.Injective (toSubmodule : NonUnitalSubalgebra R A → Submodule R A) := fun S T h => ext fun x => by rw [← mem_toSubmodule, ← mem_toSubmodule, h] theorem toSubmodule_inj {S U : NonUnitalSubalgebra R A} : S.toSubmodule = U.toSubmodule ↔ S = U := toSubmodule_injective.eq_iff /-- Copy of a non-unital subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : NonUnitalSubalgebra R A) (s : Set A) (hs : s = ↑S) : NonUnitalSubalgebra R A := { S.toNonUnitalSubsemiring.copy s hs with smul_mem' r a := by simpa [hs] using S.smul_mem r } @[simp, norm_cast] theorem coe_copy (S : NonUnitalSubalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s := rfl theorem copy_eq (S : NonUnitalSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs instance (S : NonUnitalSubalgebra R A) : Inhabited S := ⟨(0 : S.toNonUnitalSubsemiring)⟩ end NonUnitalNonAssocSemiring section NonUnitalNonAssocRing variable [CommRing R] variable [NonUnitalNonAssocRing A] [NonUnitalNonAssocRing B] [NonUnitalNonAssocRing C] variable [Module R A] [Module R B] [Module R C] instance instNonUnitalSubringClass : NonUnitalSubringClass (NonUnitalSubalgebra R A) A := { NonUnitalSubalgebra.instNonUnitalSubsemiringClass with neg_mem {_ x} hx := neg_one_smul R x ▸ SMulMemClass.smul_mem _ hx } /-- A non-unital subalgebra over a ring is also a `Subring`. -/ def toNonUnitalSubring (S : NonUnitalSubalgebra R A) : NonUnitalSubring A where toNonUnitalSubsemiring := S.toNonUnitalSubsemiring neg_mem' := neg_mem (s := S) @[simp] theorem mem_toNonUnitalSubring {S : NonUnitalSubalgebra R A} {x} : x ∈ S.toNonUnitalSubring ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toNonUnitalSubring (S : NonUnitalSubalgebra R A) : (↑S.toNonUnitalSubring : Set A) = S := rfl theorem toNonUnitalSubring_injective : Function.Injective (toNonUnitalSubring : NonUnitalSubalgebra R A → NonUnitalSubring A) := fun S T h => ext fun x => by rw [← mem_toNonUnitalSubring, ← mem_toNonUnitalSubring, h] theorem toNonUnitalSubring_inj {S U : NonUnitalSubalgebra R A} : S.toNonUnitalSubring = U.toNonUnitalSubring ↔ S = U := toNonUnitalSubring_injective.eq_iff end NonUnitalNonAssocRing section /-! `NonUnitalSubalgebra`s inherit structure from their `NonUnitalSubsemiring` / `Semiring` coercions. -/ instance toNonUnitalNonAssocSemiring [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] (S : NonUnitalSubalgebra R A) : NonUnitalNonAssocSemiring S := inferInstance instance toNonUnitalSemiring [CommSemiring R] [NonUnitalSemiring A] [Module R A] (S : NonUnitalSubalgebra R A) : NonUnitalSemiring S := inferInstance instance toNonUnitalCommSemiring [CommSemiring R] [NonUnitalCommSemiring A] [Module R A] (S : NonUnitalSubalgebra R A) : NonUnitalCommSemiring S := inferInstance instance toNonUnitalNonAssocRing [CommRing R] [NonUnitalNonAssocRing A] [Module R A] (S : NonUnitalSubalgebra R A) : NonUnitalNonAssocRing S := inferInstance instance toNonUnitalRing [CommRing R] [NonUnitalRing A] [Module R A] (S : NonUnitalSubalgebra R A) : NonUnitalRing S := inferInstance instance toNonUnitalCommRing [CommRing R] [NonUnitalCommRing A] [Module R A] (S : NonUnitalSubalgebra R A) : NonUnitalCommRing S := inferInstance end /-- The forgetful map from `NonUnitalSubalgebra` to `Submodule` as an `OrderEmbedding` -/ def toSubmodule' [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] : NonUnitalSubalgebra R A ↪o Submodule R A where toEmbedding := { toFun := fun S => S.toSubmodule inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h } map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe /-- The forgetful map from `NonUnitalSubalgebra` to `NonUnitalSubsemiring` as an `OrderEmbedding` -/ def toNonUnitalSubsemiring' [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] : NonUnitalSubalgebra R A ↪o NonUnitalSubsemiring A where toEmbedding := { toFun := fun S => S.toNonUnitalSubsemiring inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h } map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe /-- The forgetful map from `NonUnitalSubalgebra` to `NonUnitalSubsemiring` as an `OrderEmbedding` -/ def toNonUnitalSubring' [CommRing R] [NonUnitalNonAssocRing A] [Module R A] : NonUnitalSubalgebra R A ↪o NonUnitalSubring A where toEmbedding := { toFun := fun S => S.toNonUnitalSubring inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h } map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [NonUnitalNonAssocSemiring C] variable [Module R A] [Module R B] [Module R C] variable {S : NonUnitalSubalgebra R A} section /-! ### `NonUnitalSubalgebra`s inherit structure from their `Submodule` coercions. -/ instance instModule' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S := SMulMemClass.toModule' _ R' R A S instance instModule : Module R S := S.instModule' instance instIsScalarTower' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S := S.toSubmodule.isScalarTower instance [IsScalarTower R A A] : IsScalarTower R S S where smul_assoc r x y := Subtype.ext <| smul_assoc r (x : A) (y : A) instance instSMulCommClass' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] [SMulCommClass R' R A] : SMulCommClass R' R S where smul_comm r' r s := Subtype.ext <| smul_comm r' r (s : A) instance instSMulCommClass [SMulCommClass R A A] : SMulCommClass R S S where smul_comm r x y := Subtype.ext <| smul_comm r (x : A) (y : A) instance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S := ⟨fun {c x} h => have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg ((↑) : S → A) h) this.imp_right Subtype.ext⟩ end protected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl protected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl protected theorem coe_zero : ((0 : S) : A) = 0 := rfl protected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S : NonUnitalSubalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl protected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S : NonUnitalSubalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl @[simp, norm_cast] theorem coe_smul [SMul R' R] [SMul R' A] [IsScalarTower R' R A] (r : R') (x : S) : ↑(r • x) = r • (x : A) := rfl protected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 := ZeroMemClass.coe_eq_zero @[simp] theorem toNonUnitalSubsemiring_subtype : NonUnitalSubsemiringClass.subtype S = NonUnitalSubalgebraClass.subtype (R := R) S := rfl @[simp] theorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : NonUnitalSubalgebra R A) : NonUnitalSubringClass.subtype S = NonUnitalSubalgebraClass.subtype (R := R) S := rfl /-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal, we define it as a `LinearEquiv` to avoid type equalities. -/ def toSubmoduleEquiv (S : NonUnitalSubalgebra R A) : S.toSubmodule ≃ₗ[R] S := LinearEquiv.ofEq _ _ rfl variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] /-- Transport a non-unital subalgebra via an algebra homomorphism. -/ def map (f : F) (S : NonUnitalSubalgebra R A) : NonUnitalSubalgebra R B := { S.toNonUnitalSubsemiring.map (f : A →ₙ+* B) with smul_mem' := fun r b hb => by rcases hb with ⟨a, ha, rfl⟩ exact map_smulₛₗ f r a ▸ Set.mem_image_of_mem f (S.smul_mem' r ha) } theorem map_mono {S₁ S₂ : NonUnitalSubalgebra R A} {f : F} : S₁ ≤ S₂ → (map f S₁ : NonUnitalSubalgebra R B) ≤ map f S₂ := Set.image_mono theorem map_injective {f : F} (hf : Function.Injective f) : Function.Injective (map f : NonUnitalSubalgebra R A → NonUnitalSubalgebra R B) := fun _S₁ _S₂ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : NonUnitalSubalgebra R A) : map (NonUnitalAlgHom.id R A) S = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : NonUnitalSubalgebra R A) (g : B →ₙₐ[R] C) (f : A →ₙₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : NonUnitalSubalgebra R A} {f : F} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y := NonUnitalSubsemiring.mem_map theorem map_toSubmodule {S : NonUnitalSubalgebra R A} {f : F} : -- TODO: introduce a better coercion from `NonUnitalAlgHomClass` to `LinearMap` (map f S).toSubmodule = Submodule.map (LinearMapClass.linearMap f) S.toSubmodule := SetLike.coe_injective rfl theorem map_toNonUnitalSubsemiring {S : NonUnitalSubalgebra R A} {f : F} : (map f S).toNonUnitalSubsemiring = S.toNonUnitalSubsemiring.map (f : A →ₙ+* B) := SetLike.coe_injective rfl @[simp] theorem coe_map (S : NonUnitalSubalgebra R A) (f : F) : (map f S : Set B) = f '' S := rfl /-- Preimage of a non-unital subalgebra under an algebra homomorphism. -/ def comap (f : F) (S : NonUnitalSubalgebra R B) : NonUnitalSubalgebra R A := { S.toNonUnitalSubsemiring.comap (f : A →ₙ+* B) with smul_mem' := fun r a (ha : f a ∈ S) => show f (r • a) ∈ S from (map_smulₛₗ f r a).symm ▸ SMulMemClass.smul_mem r ha } theorem map_le {S : NonUnitalSubalgebra R A} {f : F} {U : NonUnitalSubalgebra R B} : map f S ≤ U ↔ S ≤ comap f U := Set.image_subset_iff theorem gc_map_comap (f : F) : GaloisConnection (map f : NonUnitalSubalgebra R A → NonUnitalSubalgebra R B) (comap f) := fun _ _ => map_le @[simp] theorem mem_comap (S : NonUnitalSubalgebra R B) (f : F) (x : A) : x ∈ comap f S ↔ f x ∈ S := Iff.rfl @[simp, norm_cast] theorem coe_comap (S : NonUnitalSubalgebra R B) (f : F) : (comap f S : Set A) = f ⁻¹' (S : Set B) := rfl instance noZeroDivisors {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] [NoZeroDivisors A] [Module R A] (S : NonUnitalSubalgebra R A) : NoZeroDivisors S := NonUnitalSubsemiringClass.noZeroDivisors S end NonUnitalSubalgebra namespace Submodule variable {R A : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] /-- A submodule closed under multiplication is a non-unital subalgebra. -/ def toNonUnitalSubalgebra (p : Submodule R A) (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : NonUnitalSubalgebra R A := { p with mul_mem' := h_mul _ _ } @[simp] theorem mem_toNonUnitalSubalgebra {p : Submodule R A} {h_mul} {x} : x ∈ p.toNonUnitalSubalgebra h_mul ↔ x ∈ p := Iff.rfl @[simp] theorem coe_toNonUnitalSubalgebra (p : Submodule R A) (h_mul) : (p.toNonUnitalSubalgebra h_mul : Set A) = p := rfl theorem toNonUnitalSubalgebra_mk (p : Submodule R A) hmul : p.toNonUnitalSubalgebra hmul = NonUnitalSubalgebra.mk ⟨⟨⟨p, p.add_mem⟩, p.zero_mem⟩, hmul _ _⟩ p.smul_mem' := rfl @[simp] theorem toNonUnitalSubalgebra_toSubmodule (p : Submodule R A) (h_mul) : (p.toNonUnitalSubalgebra h_mul).toSubmodule = p := SetLike.coe_injective rfl @[simp] theorem _root_.NonUnitalSubalgebra.toSubmodule_toNonUnitalSubalgebra (S : NonUnitalSubalgebra R A) : (S.toSubmodule.toNonUnitalSubalgebra fun _ _ => mul_mem (s := S)) = S := SetLike.coe_injective rfl end Submodule namespace NonUnitalAlgHom variable {F : Type v'} {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'} variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [Module R A] [NonUnitalNonAssocSemiring B] [Module R B] variable [NonUnitalNonAssocSemiring C] [Module R C] [FunLike F A B] [NonUnitalAlgHomClass F R A B] /-- Range of an `NonUnitalAlgHom` as a non-unital subalgebra. -/ protected def range (φ : F) : NonUnitalSubalgebra R B where toNonUnitalSubsemiring := NonUnitalRingHom.srange (φ : A →ₙ+* B) smul_mem' := fun r a => by rintro ⟨a, rfl⟩; exact ⟨r • a, map_smul φ r a⟩ @[simp] theorem mem_range (φ : F) {y : B} : y ∈ (NonUnitalAlgHom.range φ : NonUnitalSubalgebra R B) ↔ ∃ x : A, φ x = y := NonUnitalRingHom.mem_srange theorem mem_range_self (φ : F) (x : A) : φ x ∈ (NonUnitalAlgHom.range φ : NonUnitalSubalgebra R B) := (NonUnitalAlgHom.mem_range φ).2 ⟨x, rfl⟩ @[simp] theorem coe_range (φ : F) : ((NonUnitalAlgHom.range φ : NonUnitalSubalgebra R B) : Set B) = Set.range (φ : A → B) := by ext rw [SetLike.mem_coe, mem_range, Set.mem_range] theorem range_comp (f : A →ₙₐ[R] B) (g : B →ₙₐ[R] C) : NonUnitalAlgHom.range (g.comp f) = (NonUnitalAlgHom.range f).map g := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range (f : A →ₙₐ[R] B) (g : B →ₙₐ[R] C) : NonUnitalAlgHom.range (g.comp f) ≤ NonUnitalAlgHom.range g := SetLike.coe_mono (Set.range_comp_subset_range f g) /-- Restrict the codomain of a non-unital algebra homomorphism. -/ def codRestrict (f : F) (S : NonUnitalSubalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₙₐ[R] S := { NonUnitalRingHom.codRestrict (f : A →ₙ+* B) S.toNonUnitalSubsemiring hf with map_smul' := fun r a => Subtype.ext <| map_smul f r a } @[simp] theorem subtype_comp_codRestrict (f : F) (S : NonUnitalSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : (NonUnitalSubalgebraClass.subtype S).comp (NonUnitalAlgHom.codRestrict f S hf) = f := rfl @[simp] theorem coe_codRestrict (f : F) (S : NonUnitalSubalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) : ↑(NonUnitalAlgHom.codRestrict f S hf x) = f x := rfl theorem injective_codRestrict (f : F) (S : NonUnitalSubalgebra R B) (hf : ∀ x : A, f x ∈ S) : Function.Injective (NonUnitalAlgHom.codRestrict f S hf) ↔ Function.Injective f := ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy :)⟩ /-- Restrict the codomain of an `NonUnitalAlgHom` `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict (f : F) : A →ₙₐ[R] (NonUnitalAlgHom.range f : NonUnitalSubalgebra R B) := NonUnitalAlgHom.codRestrict f (NonUnitalAlgHom.range f) (NonUnitalAlgHom.mem_range_self f) /-- The equalizer of two non-unital `R`-algebra homomorphisms -/ def equalizer (ϕ ψ : F) : NonUnitalSubalgebra R A where carrier := {a | (ϕ a : B) = ψ a} zero_mem' := by rw [Set.mem_setOf_eq, map_zero, map_zero] add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by rw [Set.mem_setOf_eq, map_add, map_add, hx, hy] mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by rw [Set.mem_setOf_eq, map_mul, map_mul, hx, hy] smul_mem' r x (hx : ϕ x = ψ x) := by rw [Set.mem_setOf_eq, map_smul, map_smul, hx] @[simp] theorem mem_equalizer (φ ψ : F) (x : A) : x ∈ NonUnitalAlgHom.equalizer φ ψ ↔ φ x = ψ x := Iff.rfl /-- The range of a morphism of algebras is a fintype, if the domain is a fintype. Note that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/ instance fintypeRange [Fintype A] [DecidableEq B] (φ : F) : Fintype (NonUnitalAlgHom.range φ) := Set.fintypeRange φ end NonUnitalAlgHom namespace NonUnitalAlgebra variable {F : Type*} (R : Type u) {A : Type v} {B : Type w} variable [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] @[simp] lemma span_eq_toSubmodule (s : NonUnitalSubalgebra R A) : Submodule.span R (s : Set A) = s.toSubmodule := by simp [SetLike.ext'_iff, Submodule.coe_span_eq_self] variable [NonUnitalNonAssocSemiring B] [Module R B] variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] section IsScalarTower variable [IsScalarTower R A A] [SMulCommClass R A A] /-- The minimal non-unital subalgebra that includes `s`. -/ def adjoin (s : Set A) : NonUnitalSubalgebra R A := { Submodule.span R (NonUnitalSubsemiring.closure s : Set A) with mul_mem' := fun {a b} (ha : a ∈ Submodule.span R (NonUnitalSubsemiring.closure s : Set A)) (hb : b ∈ Submodule.span R (NonUnitalSubsemiring.closure s : Set A)) => show a * b ∈ Submodule.span R (NonUnitalSubsemiring.closure s : Set A) by refine Submodule.span_induction ?_ ?_ ?_ ?_ ha · refine Submodule.span_induction ?_ ?_ ?_ ?_ hb · exact fun x (hx : x ∈ NonUnitalSubsemiring.closure s) y (hy : y ∈ NonUnitalSubsemiring.closure s) => Submodule.subset_span (mul_mem hy hx) · exact fun x _hx => (mul_zero x).symm ▸ Submodule.zero_mem _ · exact fun x y _ _ hx hy z hz => (mul_add z x y).symm ▸ add_mem (hx z hz) (hy z hz) · exact fun r x _ hx y hy => (mul_smul_comm r y x).symm ▸ SMulMemClass.smul_mem r (hx y hy) · exact (zero_mul b).symm ▸ Submodule.zero_mem _ · exact fun x y _ _ => (add_mul x y b).symm ▸ add_mem · exact fun r x _ hx => (smul_mul_assoc r x b).symm ▸ SMulMemClass.smul_mem r hx } theorem adjoin_toSubmodule (s : Set A) : (adjoin R s).toSubmodule = Submodule.span R (NonUnitalSubsemiring.closure s : Set A) := rfl @[simp, aesop safe 20 (rule_sets := [SetLike])] theorem subset_adjoin {s : Set A} : s ⊆ adjoin R s := NonUnitalSubsemiring.subset_closure.trans Submodule.subset_span @[aesop 80% (rule_sets := [SetLike])] theorem mem_adjoin_of_mem {s : Set A} {x : A} (hx : x ∈ s) : x ∈ adjoin R s := subset_adjoin R hx theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := NonUnitalAlgebra.subset_adjoin R (Set.mem_singleton x) variable {R} protected theorem gc : GaloisConnection (adjoin R : Set A → NonUnitalSubalgebra R A) (↑) := fun s S => ⟨fun H => (NonUnitalSubsemiring.subset_closure.trans Submodule.subset_span).trans H, fun H => show Submodule.span R _ ≤ S.toSubmodule from Submodule.span_le.mpr <| show NonUnitalSubsemiring.closure s ≤ S.toNonUnitalSubsemiring from NonUnitalSubsemiring.closure_le.2 H⟩ /-- Galois insertion between `adjoin` and `SetLike.coe`. -/ protected def gi : GaloisInsertion (adjoin R : Set A → NonUnitalSubalgebra R A) (↑) where choice s hs := (adjoin R s).copy s <| le_antisymm (NonUnitalAlgebra.gc.le_u_l s) hs gc := NonUnitalAlgebra.gc le_l_u S := (NonUnitalAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl choice_eq _ _ := NonUnitalSubalgebra.copy_eq _ _ _ instance : CompleteLattice (NonUnitalSubalgebra R A) := GaloisInsertion.liftCompleteLattice NonUnitalAlgebra.gi theorem adjoin_le {S : NonUnitalSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S := NonUnitalAlgebra.gc.l_le hs @[simp] theorem adjoin_le_iff {S : NonUnitalSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S := NonUnitalAlgebra.gc _ _ @[gcongr] theorem adjoin_mono {s t : Set A} (H : s ⊆ t) : adjoin R s ≤ adjoin R t := NonUnitalAlgebra.gc.monotone_l H theorem adjoin_union (s t : Set A) : adjoin R (s ∪ t) = adjoin R s ⊔ adjoin R t := (NonUnitalAlgebra.gc : GaloisConnection _ ((↑) : NonUnitalSubalgebra R A → Set A)).l_sup @[simp] lemma adjoin_eq (s : NonUnitalSubalgebra R A) : adjoin R (s : Set A) = s := le_antisymm (adjoin_le le_rfl) (subset_adjoin R) /-- If some predicate holds for all `x ∈ (s : Set A)` and this predicate is closed under the `algebraMap`, addition, multiplication and star operations, then it holds for `a ∈ adjoin R s`. -/ @[elab_as_elim] theorem adjoin_induction {s : Set A} {p : (x : A) → x ∈ adjoin R s → Prop} (mem : ∀ (x) (hx : x ∈ s), p x (subset_adjoin R hx)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (zero : p 0 (zero_mem _)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (smul : ∀ r x hx, p x hx → p (r • x) (SMulMemClass.smul_mem r hx)) {x} (hx : x ∈ adjoin R s) : p x hx := let S : NonUnitalSubalgebra R A := { carrier := { x | ∃ hx, p x hx } mul_mem' := (Exists.elim · fun _ ha ↦ (Exists.elim · fun _ hb ↦ ⟨_, mul _ _ _ _ ha hb⟩)) add_mem' := (Exists.elim · fun _ ha ↦ (Exists.elim · fun _ hb ↦ ⟨_, add _ _ _ _ ha hb⟩)) smul_mem' := fun r ↦ (Exists.elim · fun _ hb ↦ ⟨_, smul r _ _ hb⟩) zero_mem' := ⟨_, zero⟩ } adjoin_le (S := S) (fun y hy ↦ ⟨subset_adjoin R hy, mem y hy⟩) hx |>.elim fun _ ↦ id @[elab_as_elim] theorem adjoin_induction₂ {s : Set A} {p : ∀ x y, x ∈ adjoin R s → y ∈ adjoin R s → Prop} (mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_adjoin R hx) (subset_adjoin R hy)) (zero_left : ∀ x hx, p 0 x (zero_mem _) hx) (zero_right : ∀ x hx, p x 0 hx (zero_mem _)) (add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz) (add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz)) (mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz) (mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz)) (smul_left : ∀ r x y hx hy, p x y hx hy → p (r • x) y (SMulMemClass.smul_mem r hx) hy) (smul_right : ∀ r x y hx hy, p x y hx hy → p x (r • y) hx (SMulMemClass.smul_mem r hy)) {x y : A} (hx : x ∈ adjoin R s) (hy : y ∈ adjoin R s) : p x y hx hy := by induction hy using adjoin_induction with | mem z hz => induction hx using adjoin_induction with | mem _ h => exact mem_mem _ _ h hz | zero => exact zero_left _ _ | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | smul _ _ _ h => exact smul_left _ _ _ _ _ h | zero => exact zero_right x hx | mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂ | smul _ _ _ h => exact smul_right _ _ _ _ _ h open Submodule in lemma adjoin_eq_span (s : Set A) : (adjoin R s).toSubmodule = span R (Subsemigroup.closure s) := by apply le_antisymm · intro x hx induction hx using adjoin_induction with | mem x hx => exact subset_span <| Subsemigroup.subset_closure hx | add x y _ _ hpx hpy => exact add_mem hpx hpy | zero => exact zero_mem _ | mul x y _ _ hpx hpy => apply span_induction₂ ?Hs (by simp) (by simp) ?Hadd_l ?Hadd_r ?Hsmul_l ?Hsmul_r hpx hpy case Hs => exact fun x y hx hy ↦ subset_span <| mul_mem hx hy case Hadd_l => exact fun x y z _ _ _ hxz hyz ↦ by simpa [add_mul] using add_mem hxz hyz case Hadd_r => exact fun x y z _ _ _ hxz hyz ↦ by simpa [mul_add] using add_mem hxz hyz case Hsmul_l => exact fun r x y _ _ hxy ↦ by simpa [smul_mul_assoc] using smul_mem _ _ hxy case Hsmul_r => exact fun r x y _ _ hxy ↦ by simpa [mul_smul_comm] using smul_mem _ _ hxy | smul r x _ hpx => exact smul_mem _ _ hpx · apply span_le.2 _ change Subsemigroup.closure s ≤ (adjoin R s).toSubsemigroup exact Subsemigroup.closure_le.2 (subset_adjoin R) variable (R A) @[simp] theorem adjoin_empty : adjoin R (∅ : Set A) = ⊥ := show adjoin R ⊥ = ⊥ by apply GaloisConnection.l_bot; exact NonUnitalAlgebra.gc @[simp] theorem adjoin_univ : adjoin R (Set.univ : Set A) = ⊤ := eq_top_iff.2 fun _x hx => subset_adjoin R hx open NonUnitalSubalgebra in lemma _root_.NonUnitalAlgHom.map_adjoin [IsScalarTower R B B] [SMulCommClass R B B] (f : F) (s : Set A) : map f (adjoin R s) = adjoin R (f '' s) := Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) NonUnitalAlgebra.gi.gc NonUnitalAlgebra.gi.gc fun _t => rfl open NonUnitalSubalgebra in @[simp] lemma _root_.NonUnitalAlgHom.map_adjoin_singleton [IsScalarTower R B B] [SMulCommClass R B B] (f : F) (x : A) : map f (adjoin R {x}) = adjoin R {f x} := by simp [NonUnitalAlgHom.map_adjoin] variable {R A} @[simp, norm_cast] theorem coe_top : (↑(⊤ : NonUnitalSubalgebra R A) : Set A) = Set.univ := rfl @[simp] theorem mem_top {x : A} : x ∈ (⊤ : NonUnitalSubalgebra R A) := Set.mem_univ x @[simp] theorem top_toSubmodule : (⊤ : NonUnitalSubalgebra R A).toSubmodule = ⊤ := rfl @[simp] theorem top_toNonUnitalSubsemiring : (⊤ : NonUnitalSubalgebra R A).toNonUnitalSubsemiring = ⊤ := rfl @[simp] theorem top_toSubring {R A : Type*} [CommRing R] [NonUnitalNonAssocRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : (⊤ : NonUnitalSubalgebra R A).toNonUnitalSubring = ⊤ := rfl @[simp] theorem toSubmodule_eq_top {S : NonUnitalSubalgebra R A} : S.toSubmodule = ⊤ ↔ S = ⊤ := NonUnitalSubalgebra.toSubmodule'.injective.eq_iff' top_toSubmodule @[simp] theorem toNonUnitalSubsemiring_eq_top {S : NonUnitalSubalgebra R A} : S.toNonUnitalSubsemiring = ⊤ ↔ S = ⊤ := NonUnitalSubalgebra.toNonUnitalSubsemiring_injective.eq_iff' top_toNonUnitalSubsemiring @[simp] theorem to_subring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : NonUnitalSubalgebra R A} : S.toNonUnitalSubring = ⊤ ↔ S = ⊤ := NonUnitalSubalgebra.toNonUnitalSubring_injective.eq_iff' top_toSubring theorem mem_sup_left {S T : NonUnitalSubalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := by rw [← SetLike.le_def] exact le_sup_left theorem mem_sup_right {S T : NonUnitalSubalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := by rw [← SetLike.le_def] exact le_sup_right theorem mul_mem_sup {S T : NonUnitalSubalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := mul_mem (mem_sup_left hx) (mem_sup_right hy) theorem map_sup [IsScalarTower R B B] [SMulCommClass R B B] (f : F) (S T : NonUnitalSubalgebra R A) : ((S ⊔ T).map f : NonUnitalSubalgebra R B) = S.map f ⊔ T.map f := (NonUnitalSubalgebra.gc_map_comap f).l_sup theorem map_inf [IsScalarTower R B B] [SMulCommClass R B B] (f : F) (hf : Function.Injective f) (S T : NonUnitalSubalgebra R A) : ((S ⊓ T).map f : NonUnitalSubalgebra R B) = S.map f ⊓ T.map f := SetLike.coe_injective (Set.image_inter hf) @[simp, norm_cast] theorem coe_inf (S T : NonUnitalSubalgebra R A) : (↑(S ⊓ T) : Set A) = (S : Set A) ∩ T := rfl @[simp] theorem mem_inf {S T : NonUnitalSubalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl @[simp] theorem inf_toSubmodule (S T : NonUnitalSubalgebra R A) : (S ⊓ T).toSubmodule = S.toSubmodule ⊓ T.toSubmodule := rfl @[simp] theorem inf_toNonUnitalSubsemiring (S T : NonUnitalSubalgebra R A) : (S ⊓ T).toNonUnitalSubsemiring = S.toNonUnitalSubsemiring ⊓ T.toNonUnitalSubsemiring := rfl @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalSubalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s := sInf_image theorem mem_sInf {S : Set (NonUnitalSubalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂] @[simp] theorem sInf_toSubmodule (S : Set (NonUnitalSubalgebra R A)) : (sInf S).toSubmodule = sInf (NonUnitalSubalgebra.toSubmodule '' S) := SetLike.coe_injective <| by simp @[simp] theorem sInf_toNonUnitalSubsemiring (S : Set (NonUnitalSubalgebra R A)) : (sInf S).toNonUnitalSubsemiring = sInf (NonUnitalSubalgebra.toNonUnitalSubsemiring '' S) := SetLike.coe_injective <| by simp @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalSubalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by simp [iInf] theorem mem_iInf {ι : Sort*} {S : ι → NonUnitalSubalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] theorem map_iInf {ι : Sort*} [Nonempty ι] [IsScalarTower R B B] [SMulCommClass R B B] (f : F) (hf : Function.Injective f) (S : ι → NonUnitalSubalgebra R A) : ((⨅ i, S i).map f : NonUnitalSubalgebra R B) = ⨅ i, (S i).map f := by apply SetLike.coe_injective simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ S) @[simp] theorem iInf_toSubmodule {ι : Sort*} (S : ι → NonUnitalSubalgebra R A) : (⨅ i, S i).toSubmodule = ⨅ i, (S i).toSubmodule := SetLike.coe_injective <| by simp instance : Inhabited (NonUnitalSubalgebra R A) := ⟨⊥⟩ theorem mem_bot {x : A} : x ∈ (⊥ : NonUnitalSubalgebra R A) ↔ x = 0 := show x ∈ Submodule.span R (NonUnitalSubsemiring.closure (∅ : Set A) : Set A) ↔ x = 0 by rw [NonUnitalSubsemiring.closure_empty, NonUnitalSubsemiring.coe_bot, Submodule.span_zero_singleton, Submodule.mem_bot] theorem toSubmodule_bot : (⊥ : NonUnitalSubalgebra R A).toSubmodule = ⊥ := by ext simp only [mem_bot, NonUnitalSubalgebra.mem_toSubmodule, Submodule.mem_bot] @[simp, norm_cast] theorem coe_bot : ((⊥ : NonUnitalSubalgebra R A) : Set A) = {0} := by simp [Set.ext_iff, NonUnitalAlgebra.mem_bot] theorem eq_top_iff {S : NonUnitalSubalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S := ⟨fun h x => by rw [h]; exact mem_top, fun h => by ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩ @[simp] theorem range_id : NonUnitalAlgHom.range (NonUnitalAlgHom.id R A) = ⊤ := SetLike.coe_injective Set.range_id @[simp] theorem map_top (f : A →ₙₐ[R] B) : (⊤ : NonUnitalSubalgebra R A).map f = NonUnitalAlgHom.range f := SetLike.coe_injective Set.image_univ @[simp] theorem map_bot [IsScalarTower R B B] [SMulCommClass R B B] (f : A →ₙₐ[R] B) : (⊥ : NonUnitalSubalgebra R A).map f = ⊥ := SetLike.coe_injective <| by simp [NonUnitalAlgebra.coe_bot, NonUnitalSubalgebra.coe_map] @[simp] theorem comap_top [IsScalarTower R B B] [SMulCommClass R B B] (f : A →ₙₐ[R] B) : (⊤ : NonUnitalSubalgebra R B).comap f = ⊤ := eq_top_iff.2 fun _ => mem_top /-- `NonUnitalAlgHom` to `⊤ : NonUnitalSubalgebra R A`. -/ def toTop : A →ₙₐ[R] (⊤ : NonUnitalSubalgebra R A) := NonUnitalAlgHom.codRestrict (NonUnitalAlgHom.id R A) ⊤ fun _ => mem_top end IsScalarTower theorem range_eq_top [IsScalarTower R B B] [SMulCommClass R B B] (f : A →ₙₐ[R] B) : NonUnitalAlgHom.range f = (⊤ : NonUnitalSubalgebra R B) ↔ Function.Surjective f := NonUnitalAlgebra.eq_top_iff end NonUnitalAlgebra namespace NonUnitalSubalgebra open NonUnitalAlgebra section NonAssoc variable {R : Type u} {A : Type v} {B : Type w} variable [CommSemiring R] variable [NonUnitalNonAssocSemiring A] [Module R A] variable (S : NonUnitalSubalgebra R A) theorem range_val : NonUnitalAlgHom.range (NonUnitalSubalgebraClass.subtype S) = S := ext <| Set.ext_iff.1 <| (NonUnitalAlgHom.coe_range <| NonUnitalSubalgebraClass.subtype S).trans Subtype.range_val instance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (NonUnitalSubalgebra R A) := ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩ variable [NonUnitalNonAssocSemiring B] [Module R B] section Prod variable (S₁ : NonUnitalSubalgebra R B) /-- The product of two non-unital subalgebras is a non-unital subalgebra. -/ def prod : NonUnitalSubalgebra R (A × B) := { S.toNonUnitalSubsemiring.prod S₁.toNonUnitalSubsemiring with carrier := S ×ˢ S₁ smul_mem' := fun r _x hx => ⟨SMulMemClass.smul_mem r hx.1, SMulMemClass.smul_mem r hx.2⟩ } @[simp, norm_cast] theorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ S₁ := rfl theorem prod_toSubmodule : (S.prod S₁).toSubmodule = S.toSubmodule.prod S₁.toSubmodule := rfl @[simp] theorem mem_prod {S : NonUnitalSubalgebra R A} {S₁ : NonUnitalSubalgebra R B} {x : A × B} : x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod variable [IsScalarTower R A A] [SMulCommClass R A A] [IsScalarTower R B B] [SMulCommClass R B B] @[simp] theorem prod_top : (prod ⊤ ⊤ : NonUnitalSubalgebra R (A × B)) = ⊤ := by ext; simp theorem prod_mono {S T : NonUnitalSubalgebra R A} {S₁ T₁ : NonUnitalSubalgebra R B} : S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ := Set.prod_mono @[simp] theorem prod_inf_prod {S T : NonUnitalSubalgebra R A} {S₁ T₁ : NonUnitalSubalgebra R B} : S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) := SetLike.coe_injective Set.prod_inter_prod end Prod variable [IsScalarTower R A A] [SMulCommClass R A A] instance _root_.NonUnitalAlgHom.subsingleton [Subsingleton (NonUnitalSubalgebra R A)] : Subsingleton (A →ₙₐ[R] B) := ⟨fun f g => NonUnitalAlgHom.ext fun a => have : a ∈ (⊥ : NonUnitalSubalgebra R A) := Subsingleton.elim (⊤ : NonUnitalSubalgebra R A) ⊥ ▸ mem_top (mem_bot.mp this).symm ▸ (map_zero f).trans (map_zero g).symm⟩ /-- The map `S → T` when `S` is a non-unital subalgebra contained in the non-unital subalgebra `T`. This is the non-unital subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/ def inclusion {S T : NonUnitalSubalgebra R A} (h : S ≤ T) : S →ₙₐ[R] T where toFun := Set.inclusion h map_add' _ _ := rfl map_mul' _ _ := rfl map_zero' := rfl map_smul' _ _ := rfl theorem inclusion_injective {S T : NonUnitalSubalgebra R A} (h : S ≤ T) : Function.Injective (inclusion h) := fun _ _ => Subtype.ext ∘ Subtype.mk.inj @[simp] theorem inclusion_self {S : NonUnitalSubalgebra R A} : inclusion (le_refl S) = NonUnitalAlgHom.id R S := rfl @[simp] theorem inclusion_mk {S T : NonUnitalSubalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl theorem inclusion_right {S T : NonUnitalSubalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) : inclusion h ⟨x, m⟩ = x := Subtype.ext rfl @[simp] theorem inclusion_inclusion {S T U : NonUnitalSubalgebra R A} (hst : S ≤ T) (htu : T ≤ U) (x : S) : inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x := Subtype.ext rfl @[simp] theorem coe_inclusion {S T : NonUnitalSubalgebra R A} (h : S ≤ T) (s : S) : (inclusion h s : A) = s := rfl section SuprLift variable {ι : Sort*} theorem coe_iSup_of_directed [Nonempty ι] {S : ι → NonUnitalSubalgebra R A} (dir : Directed (· ≤ ·) S) : ↑(iSup S) = ⋃ i, (S i : Set A) := let K : NonUnitalSubalgebra R A := { __ := NonUnitalSubsemiring.copy _ _ (NonUnitalSubsemiring.coe_iSup_of_directed dir).symm smul_mem' := fun r _x hx ↦ let ⟨i, hi⟩ := Set.mem_iUnion.1 hx Set.mem_iUnion.2 ⟨i, (S i).smul_mem' r hi⟩ } have : iSup S = K := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (S i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup S _) this.symm ▸ rfl /-- Define an algebra homomorphism on a directed supremum of non-unital subalgebras by defining it on each non-unital subalgebra, and proving that it agrees on the intersection of non-unital subalgebras. -/ noncomputable def iSupLift [Nonempty ι] (K : ι → NonUnitalSubalgebra R A) (dir : Directed (· ≤ ·) K) (f : ∀ i, K i →ₙₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)) (T : NonUnitalSubalgebra R A) (hT : T = iSup K) : ↥T →ₙₐ[R] B := by subst hT exact { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x) (fun i j x hxi hxj => by let ⟨k, hik, hjk⟩ := dir i j simp only rw [hf i k hik, hf j k hjk] rfl) _ (by rw [coe_iSup_of_directed dir]) map_zero' := by dsimp exact Set.iUnionLift_const _ (fun i : ι => (0 : K i)) (fun _ => rfl) _ (by simp) map_mul' := by dsimp apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·)) all_goals simp map_add' := by dsimp apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·)) all_goals simp map_smul' := fun r => by dsimp apply Set.iUnionLift_unary (coe_iSup_of_directed dir) _ (fun _ x => r • x) (fun _ _ => rfl) all_goals simp } variable [Nonempty ι] {K : ι → NonUnitalSubalgebra R A} {dir : Directed (· ≤ ·) K} {f : ∀ i, K i →ₙₐ[R] B} {hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)} {T : NonUnitalSubalgebra R A} {hT : T = iSup K} @[simp] theorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) : iSupLift K dir f hf T hT (inclusion h x) = f i x := by subst T dsimp [iSupLift] apply Set.iUnionLift_inclusion exact h @[simp] theorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) : (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext simp only [NonUnitalAlgHom.comp_apply, iSupLift_inclusion] @[simp] theorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) : iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by subst hT dsimp [iSupLift] apply Set.iUnionLift_mk theorem iSupLift_of_mem {i : ι} (x : T) (hx : (x : A) ∈ K i) : iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by subst hT dsimp [iSupLift] apply Set.iUnionLift_of_mem end SuprLift end NonAssoc section Center section NonUnitalNonAssocSemiring variable {R A : Type*} variable [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] variable [IsScalarTower R A A] [SMulCommClass R A A] theorem _root_.Set.smul_mem_center (r : R) {a : A} (ha : a ∈ Set.center A) : r • a ∈ Set.center A where comm b := by rw [commute_iff_eq, mul_smul_comm, smul_mul_assoc, ha.comm] left_assoc b c := by rw [smul_mul_assoc, smul_mul_assoc, smul_mul_assoc, ha.left_assoc] right_assoc b c := by rw [mul_smul_comm, mul_smul_comm, mul_smul_comm, ha.right_assoc] variable (R A) in /-- The center of a non-unital algebra is the set of elements which commute with every element. They form a non-unital subalgebra. -/ def center : NonUnitalSubalgebra R A := { NonUnitalSubsemiring.center A with smul_mem' := Set.smul_mem_center } @[norm_cast] theorem coe_center : (center R A : Set A) = Set.center A := rfl /-- The center of a non-unital algebra is commutative and associative -/ instance center.instNonUnitalCommSemiring : NonUnitalCommSemiring (center R A) := NonUnitalSubsemiring.center.instNonUnitalCommSemiring _ instance center.instNonUnitalCommRing {A : Type*} [NonUnitalNonAssocRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : NonUnitalCommRing (center R A) := NonUnitalSubring.center.instNonUnitalCommRing _ @[simp] theorem center_toNonUnitalSubsemiring : (center R A).toNonUnitalSubsemiring = NonUnitalSubsemiring.center A := rfl @[simp] lemma center_toNonUnitalSubring (R A : Type*) [CommRing R] [NonUnitalNonAssocRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : (center R A).toNonUnitalSubring = NonUnitalSubring.center A := rfl end NonUnitalNonAssocSemiring variable (R A : Type*) [CommSemiring R] [NonUnitalSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] -- no instance diamond, as the `npow` field isn't present in the non-unital case. example : center.instNonUnitalCommSemiring.toNonUnitalSemiring = NonUnitalSubsemiringClass.toNonUnitalSemiring (center R A) := by with_reducible_and_instances rfl @[simp] theorem center_eq_top (A : Type*) [NonUnitalCommSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : center R A = ⊤ := SetLike.coe_injective (Set.center_eq_univ A) variable {R A} theorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b := Subsemigroup.mem_center_iff end Center section Centralizer variable {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] @[simp] theorem _root_.Set.smul_mem_centralizer {s : Set A} (r : R) {a : A} (ha : a ∈ s.centralizer) : r • a ∈ s.centralizer := fun x hx => by rw [mul_smul_comm, smul_mul_assoc, ha x hx] variable (R) /-- The centralizer of a set as a non-unital subalgebra. -/ def centralizer (s : Set A) : NonUnitalSubalgebra R A where toNonUnitalSubsemiring := NonUnitalSubsemiring.centralizer s smul_mem' := Set.smul_mem_centralizer @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer := rfl theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl theorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s := Set.centralizer_subset h @[simp] theorem centralizer_univ : centralizer R Set.univ = center R A := SetLike.ext' (Set.centralizer_univ A) end Centralizer end NonUnitalSubalgebra namespace NonUnitalAlgebra open NonUnitalSubalgebra variable {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] variable (R) in lemma adjoin_le_centralizer_centralizer (s : Set A) : adjoin R s ≤ centralizer R (centralizer R s) := adjoin_le Set.subset_centralizer_centralizer lemma commute_of_mem_adjoin_of_forall_mem_commute {a b : A} {s : Set A} (hb : b ∈ adjoin R s) (h : ∀ b ∈ s, Commute a b) : Commute a b := by have : a ∈ centralizer R s := by simpa only [Commute.symm_iff (a := a)] using h exact adjoin_le_centralizer_centralizer R s hb a this lemma commute_of_mem_adjoin_singleton_of_commute {a b c : A} (hc : c ∈ adjoin R {b}) (h : Commute a b) : Commute a c := commute_of_mem_adjoin_of_forall_mem_commute hc <| by simpa lemma commute_of_mem_adjoin_self {a b : A} (hb : b ∈ adjoin R {a}) : Commute a b := commute_of_mem_adjoin_singleton_of_commute hb rfl variable (R) in /-- If all elements of `s : Set A` commute pairwise, then `adjoin R s` is a non-unital commutative semiring. See note [reducible non-instances]. -/ abbrev adjoinNonUnitalCommSemiringOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : NonUnitalCommSemiring (adjoin R s) := { (adjoin R s).toNonUnitalSemiring with mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦ have := adjoin_le_centralizer_centralizer R s Subtype.ext <| Set.centralizer_centralizer_comm_of_comm hcomm _ (this h₁) _ (this h₂) } /-- If all elements of `s : Set A` commute pairwise, then `adjoin R s` is a non-unital commutative ring. See note [reducible non-instances]. -/ abbrev adjoinNonUnitalCommRingOfComm (R : Type*) {A : Type*} [CommRing R] [NonUnitalRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : NonUnitalCommRing (adjoin R s) := { (adjoin R s).toNonUnitalRing, adjoinNonUnitalCommSemiringOfComm R hcomm with } end NonUnitalAlgebra section Nat variable {R : Type*} [NonUnitalNonAssocSemiring R] /-- A non-unital subsemiring is a non-unital `ℕ`-subalgebra. -/ def nonUnitalSubalgebraOfNonUnitalSubsemiring (S : NonUnitalSubsemiring R) : NonUnitalSubalgebra ℕ R where toNonUnitalSubsemiring := S smul_mem' n _x hx := nsmul_mem (S := S) hx n @[simp] theorem mem_nonUnitalSubalgebraOfNonUnitalSubsemiring {x : R} {S : NonUnitalSubsemiring R} : x ∈ nonUnitalSubalgebraOfNonUnitalSubsemiring S ↔ x ∈ S := Iff.rfl end Nat section Int variable {R : Type*} [NonUnitalNonAssocRing R] /-- A non-unital subring is a non-unital `ℤ`-subalgebra. -/ def nonUnitalSubalgebraOfNonUnitalSubring (S : NonUnitalSubring R) : NonUnitalSubalgebra ℤ R where toNonUnitalSubsemiring := S.toNonUnitalSubsemiring smul_mem' n _x hx := zsmul_mem (K := S) hx n @[simp] theorem mem_nonUnitalSubalgebraOfNonUnitalSubring {x : R} {S : NonUnitalSubring R} : x ∈ nonUnitalSubalgebraOfNonUnitalSubring S ↔ x ∈ S := Iff.rfl end Int
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Equiv.lean
import Mathlib.Algebra.Algebra.Hom import Mathlib.Algebra.Ring.Action.Group /-! # Isomorphisms of `R`-algebras This file defines bundled isomorphisms of `R`-algebras. ## Main definitions * `AlgEquiv R A B`: the type of `R`-algebra isomorphisms between `A` and `B`. ## Notation * `A ≃ₐ[R] B` : `R`-algebra equivalence from `A` to `B`. -/ universe u v w u₁ v₁ /-- An equivalence of algebras (denoted as `A ≃ₐ[R] B`) is an equivalence of rings commuting with the actions of scalars. -/ structure AlgEquiv (R : Type u) (A : Type v) (B : Type w) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] extends A ≃ B, A ≃* B, A ≃+ B, A ≃+* B where /-- An equivalence of algebras commutes with the action of scalars. -/ protected commutes' : ∀ r : R, toFun (algebraMap R A r) = algebraMap R B r attribute [nolint docBlame] AlgEquiv.toRingEquiv attribute [nolint docBlame] AlgEquiv.toEquiv attribute [nolint docBlame] AlgEquiv.toAddEquiv attribute [nolint docBlame] AlgEquiv.toMulEquiv @[inherit_doc] notation:50 A " ≃ₐ[" R "] " A' => AlgEquiv R A A' /-- `AlgEquivClass F R A B` states that `F` is a type of algebra structure preserving equivalences. You should extend this class when you extend `AlgEquiv`. -/ class AlgEquivClass (F : Type*) (R A B : outParam Type*) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [EquivLike F A B] : Prop extends RingEquivClass F A B where /-- An equivalence of algebras commutes with the action of scalars. -/ commutes : ∀ (f : F) (r : R), f (algebraMap R A r) = algebraMap R B r namespace AlgEquivClass -- See note [lower instance priority] instance (priority := 100) toAlgHomClass (F R A B : Type*) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [EquivLike F A B] [h : AlgEquivClass F R A B] : AlgHomClass F R A B := { h with } instance (priority := 100) toLinearEquivClass (F R A B : Type*) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [EquivLike F A B] [h : AlgEquivClass F R A B] : LinearEquivClass F R A B := { h with map_smulₛₗ := fun f => map_smulₛₗ f } /-- Turn an element of a type `F` satisfying `AlgEquivClass F R A B` into an actual `AlgEquiv`. This is declared as the default coercion from `F` to `A ≃ₐ[R] B`. -/ @[coe] def toAlgEquiv {F R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [EquivLike F A B] [AlgEquivClass F R A B] (f : F) : A ≃ₐ[R] B := { (f : A ≃ B), (f : A ≃+* B) with commutes' := commutes f } instance (F R A B : Type*) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [EquivLike F A B] [AlgEquivClass F R A B] : CoeTC F (A ≃ₐ[R] B) := ⟨toAlgEquiv⟩ end AlgEquivClass namespace AlgEquiv universe uR uA₁ uA₂ uA₃ uA₁' uA₂' uA₃' variable {R : Type uR} variable {A₁ : Type uA₁} {A₂ : Type uA₂} {A₃ : Type uA₃} variable {A₁' : Type uA₁'} {A₂' : Type uA₂'} {A₃' : Type uA₃'} section Semiring variable [CommSemiring R] [Semiring A₁] [Semiring A₂] [Semiring A₃] variable [Semiring A₁'] [Semiring A₂'] [Semiring A₃'] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] variable [Algebra R A₁'] [Algebra R A₂'] [Algebra R A₃'] variable (e : A₁ ≃ₐ[R] A₂) section coe instance : EquivLike (A₁ ≃ₐ[R] A₂) A₁ A₂ where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by obtain ⟨⟨f,_⟩,_⟩ := f obtain ⟨⟨g,_⟩,_⟩ := g congr /-- Helper instance since the coercion is not always found. -/ instance : FunLike (A₁ ≃ₐ[R] A₂) A₁ A₂ where coe := DFunLike.coe coe_injective' := DFunLike.coe_injective' instance : AlgEquivClass (A₁ ≃ₐ[R] A₂) R A₁ A₂ where map_add f := f.map_add' map_mul f := f.map_mul' commutes f := f.commutes' @[ext] theorem ext {f g : A₁ ≃ₐ[R] A₂} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h protected theorem congr_arg {f : A₁ ≃ₐ[R] A₂} {x x' : A₁} : x = x' → f x = f x' := DFunLike.congr_arg f protected theorem congr_fun {f g : A₁ ≃ₐ[R] A₂} (h : f = g) (x : A₁) : f x = g x := DFunLike.congr_fun h x @[simp] theorem coe_mk {toEquiv map_mul map_add commutes} : ⇑(⟨toEquiv, map_mul, map_add, commutes⟩ : A₁ ≃ₐ[R] A₂) = toEquiv := rfl @[simp] theorem mk_coe (e : A₁ ≃ₐ[R] A₂) (e' h₁ h₂ h₃ h₄ h₅) : (⟨⟨e, e', h₁, h₂⟩, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂) = e := ext fun _ => rfl @[simp] theorem toEquiv_eq_coe : e.toEquiv = e := rfl @[simp] protected theorem coe_coe {F : Type*} [EquivLike F A₁ A₂] [AlgEquivClass F R A₁ A₂] (f : F) : ⇑(f : A₁ ≃ₐ[R] A₂) = f := rfl theorem coe_fun_injective : @Function.Injective (A₁ ≃ₐ[R] A₂) (A₁ → A₂) fun e => (e : A₁ → A₂) := DFunLike.coe_injective instance hasCoeToRingEquiv : CoeOut (A₁ ≃ₐ[R] A₂) (A₁ ≃+* A₂) := ⟨AlgEquiv.toRingEquiv⟩ @[simp] theorem coe_toEquiv : ((e : A₁ ≃ A₂) : A₁ → A₂) = e := rfl @[simp] theorem toRingEquiv_eq_coe : e.toRingEquiv = e := rfl @[simp, norm_cast] lemma toRingEquiv_toRingHom : ((e : A₁ ≃+* A₂) : A₁ →+* A₂) = e := rfl @[simp, norm_cast] theorem coe_ringEquiv : ((e : A₁ ≃+* A₂) : A₁ → A₂) = e := rfl theorem coe_ringEquiv' : (e.toRingEquiv : A₁ → A₂) = e := rfl theorem coe_ringEquiv_injective : Function.Injective ((↑) : (A₁ ≃ₐ[R] A₂) → A₁ ≃+* A₂) := fun _ _ h => ext <| RingEquiv.congr_fun h /-- Interpret an algebra equivalence as an algebra homomorphism. This definition is included for symmetry with the other `to*Hom` projections. The `simp` normal form is to use the coercion of the `AlgHomClass.coeTC` instance. -/ @[coe] def toAlgHom : A₁ →ₐ[R] A₂ := { e with map_one' := map_one e map_zero' := map_zero e } @[simp] theorem toAlgHom_eq_coe : e.toAlgHom = e := rfl @[simp, norm_cast] theorem coe_algHom : DFunLike.coe (e.toAlgHom) = DFunLike.coe e := rfl theorem coe_algHom_injective : Function.Injective ((↑) : (A₁ ≃ₐ[R] A₂) → A₁ →ₐ[R] A₂) := fun _ _ h => ext <| AlgHom.congr_fun h @[simp, norm_cast] lemma toAlgHom_toRingHom : ((e : A₁ →ₐ[R] A₂) : A₁ →+* A₂) = e := rfl /-- The two paths coercion can take to a `RingHom` are equivalent -/ theorem coe_ringHom_commutes : ((e : A₁ →ₐ[R] A₂) : A₁ →+* A₂) = ((e : A₁ ≃+* A₂) : A₁ →+* A₂) := rfl @[simp] theorem commutes : ∀ r : R, e (algebraMap R A₁ r) = algebraMap R A₂ r := e.commutes' end coe section bijective protected theorem bijective : Function.Bijective e := EquivLike.bijective e protected theorem injective : Function.Injective e := EquivLike.injective e protected theorem surjective : Function.Surjective e := EquivLike.surjective e end bijective section refl /-- Algebra equivalences are reflexive. -/ @[refl] def refl : A₁ ≃ₐ[R] A₁ := { (.refl _ : A₁ ≃+* A₁) with commutes' := fun _ => rfl } instance : Inhabited (A₁ ≃ₐ[R] A₁) := ⟨refl⟩ @[simp, norm_cast] lemma refl_toAlgHom : (refl : A₁ ≃ₐ[R] A₁) = AlgHom.id R A₁ := rfl @[simp, norm_cast] lemma refl_toRingHom : (refl : A₁ ≃ₐ[R] A₁) = RingHom.id A₁ := rfl @[simp] theorem coe_refl : ⇑(refl : A₁ ≃ₐ[R] A₁) = id := rfl end refl section symm /-- Algebra equivalences are symmetric. -/ @[symm] def symm (e : A₁ ≃ₐ[R] A₂) : A₂ ≃ₐ[R] A₁ := { e.toRingEquiv.symm with commutes' := fun r => by rw [← e.toRingEquiv.symm_apply_apply (algebraMap R A₁ r)] congr simp } theorem invFun_eq_symm {e : A₁ ≃ₐ[R] A₂} : e.invFun = e.symm := rfl @[simp] theorem coe_apply_coe_coe_symm_apply {F : Type*} [EquivLike F A₁ A₂] [AlgEquivClass F R A₁ A₂] (f : F) (x : A₂) : f ((f : A₁ ≃ₐ[R] A₂).symm x) = x := EquivLike.right_inv f x @[simp] theorem coe_coe_symm_apply_coe_apply {F : Type*} [EquivLike F A₁ A₂] [AlgEquivClass F R A₁ A₂] (f : F) (x : A₁) : (f : A₁ ≃ₐ[R] A₂).symm (f x) = x := EquivLike.left_inv f x /-- `simp` normal form of `invFun_eq_symm` -/ @[simp] theorem symm_toEquiv_eq_symm {e : A₁ ≃ₐ[R] A₂} : (e : A₁ ≃ A₂).symm = e.symm := rfl @[simp] theorem symm_symm (e : A₁ ≃ₐ[R] A₂) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (symm : (A₁ ≃ₐ[R] A₂) → A₂ ≃ₐ[R] A₁) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem mk_coe' (e : A₁ ≃ₐ[R] A₂) (f h₁ h₂ h₃ h₄ h₅) : (⟨⟨f, e, h₁, h₂⟩, h₃, h₄, h₅⟩ : A₂ ≃ₐ[R] A₁) = e.symm := symm_bijective.injective <| ext fun _ => rfl /-- Auxiliary definition to avoid looping in `dsimp` with `AlgEquiv.symm_mk`. -/ protected def symm_mk.aux (f f') (h₁ h₂ h₃ h₄ h₅) := (⟨⟨f, f', h₁, h₂⟩, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂).symm @[simp] theorem symm_mk (f f') (h₁ h₂ h₃ h₄ h₅) : (⟨⟨f, f', h₁, h₂⟩, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂).symm = { symm_mk.aux f f' h₁ h₂ h₃ h₄ h₅ with toFun := f' invFun := f } := rfl @[simp] theorem refl_symm : (AlgEquiv.refl : A₁ ≃ₐ[R] A₁).symm = AlgEquiv.refl := rfl --this should be a simp lemma but causes a lint timeout theorem toRingEquiv_symm (f : A₁ ≃ₐ[R] A₁) : (f : A₁ ≃+* A₁).symm = f.symm := rfl @[simp] theorem symm_toRingEquiv : (e.symm : A₂ ≃+* A₁) = (e : A₁ ≃+* A₂).symm := rfl @[simp] theorem symm_toAddEquiv : (e.symm : A₂ ≃+ A₁) = (e : A₁ ≃+ A₂).symm := rfl @[simp] theorem symm_toMulEquiv : (e.symm : A₂ ≃* A₁) = (e : A₁ ≃* A₂).symm := rfl @[simp] theorem apply_symm_apply (e : A₁ ≃ₐ[R] A₂) : ∀ x, e (e.symm x) = x := e.toEquiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : A₁ ≃ₐ[R] A₂) : ∀ x, e.symm (e x) = x := e.toEquiv.symm_apply_apply theorem symm_apply_eq (e : A₁ ≃ₐ[R] A₂) {x y} : e.symm x = y ↔ x = e y := e.toEquiv.symm_apply_eq theorem eq_symm_apply (e : A₁ ≃ₐ[R] A₂) {x y} : y = e.symm x ↔ e y = x := e.toEquiv.eq_symm_apply @[simp] theorem comp_symm (e : A₁ ≃ₐ[R] A₂) : AlgHom.comp (e : A₁ →ₐ[R] A₂) ↑e.symm = AlgHom.id R A₂ := by ext simp @[simp] theorem symm_comp (e : A₁ ≃ₐ[R] A₂) : AlgHom.comp ↑e.symm (e : A₁ →ₐ[R] A₂) = AlgHom.id R A₁ := by ext simp theorem leftInverse_symm (e : A₁ ≃ₐ[R] A₂) : Function.LeftInverse e.symm e := e.left_inv theorem rightInverse_symm (e : A₁ ≃ₐ[R] A₂) : Function.RightInverse e.symm e := e.right_inv end symm section simps /-- See Note [custom simps projection] -/ def Simps.apply (e : A₁ ≃ₐ[R] A₂) : A₁ → A₂ := e /-- See Note [custom simps projection] -/ def Simps.toEquiv (e : A₁ ≃ₐ[R] A₂) : A₁ ≃ A₂ := e /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : A₁ ≃ₐ[R] A₂) : A₂ → A₁ := e.symm initialize_simps_projections AlgEquiv (toFun → apply, invFun → symm_apply) end simps section trans /-- Algebra equivalences are transitive. -/ @[trans] def trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) : A₁ ≃ₐ[R] A₃ := { e₁.toRingEquiv.trans e₂.toRingEquiv with commutes' := fun r => show e₂.toFun (e₁.toFun _) = _ by rw [e₁.commutes', e₂.commutes'] } @[simp] theorem coe_trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[simp] theorem trans_apply (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) (x : A₁) : (e₁.trans e₂) x = e₂ (e₁ x) := rfl @[simp] theorem symm_trans_apply (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) (x : A₃) : (e₁.trans e₂).symm x = e₁.symm (e₂.symm x) := rfl @[simp] lemma self_trans_symm (e : A₁ ≃ₐ[R] A₂) : e.trans e.symm = refl := by ext; simp @[simp] lemma symm_trans_self (e : A₁ ≃ₐ[R] A₂) : e.symm.trans e = refl := by ext; simp @[simp, norm_cast] lemma toRingHom_trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) : (e₁.trans e₂ : A₁ →+* A₃) = .comp e₂ (e₁ : A₁ →+* A₂) := rfl end trans /-- `Equiv.cast (congrArg _ h)` as an algebra equiv. Note that unlike `Equiv.cast`, this takes an equality of indices rather than an equality of types, to avoid having to deal with an equality of the algebraic structure itself. -/ @[simps!] protected def cast {ι : Type*} {A : ι → Type*} [∀ i, Semiring (A i)] [∀ i, Algebra R (A i)] {i j : ι} (h : i = j) : A i ≃ₐ[R] A j where __ := RingEquiv.cast h commutes' _ := by cases h; rfl /-- If `A₁` is equivalent to `A₁'` and `A₂` is equivalent to `A₂'`, then the type of maps `A₁ →ₐ[R] A₂` is equivalent to the type of maps `A₁' →ₐ[R] A₂'`. -/ @[simps apply] def arrowCongr (e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂') : (A₁ →ₐ[R] A₂) ≃ (A₁' →ₐ[R] A₂') where toFun f := (e₂.toAlgHom.comp f).comp e₁.symm.toAlgHom invFun f := (e₂.symm.toAlgHom.comp f).comp e₁.toAlgHom left_inv f := by simp only [AlgHom.comp_assoc, toAlgHom_eq_coe, symm_comp] simp only [← AlgHom.comp_assoc, symm_comp, AlgHom.id_comp, AlgHom.comp_id] right_inv f := by simp only [AlgHom.comp_assoc, toAlgHom_eq_coe, comp_symm] simp only [← AlgHom.comp_assoc, comp_symm, AlgHom.id_comp, AlgHom.comp_id] theorem arrowCongr_comp (e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂') (e₃ : A₃ ≃ₐ[R] A₃') (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₃) : arrowCongr e₁ e₃ (g.comp f) = (arrowCongr e₂ e₃ g).comp (arrowCongr e₁ e₂ f) := by ext simp @[simp] theorem arrowCongr_refl : arrowCongr AlgEquiv.refl AlgEquiv.refl = Equiv.refl (A₁ →ₐ[R] A₂) := rfl @[simp] theorem arrowCongr_trans (e₁ : A₁ ≃ₐ[R] A₂) (e₁' : A₁' ≃ₐ[R] A₂') (e₂ : A₂ ≃ₐ[R] A₃) (e₂' : A₂' ≃ₐ[R] A₃') : arrowCongr (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr e₁ e₁').trans (arrowCongr e₂ e₂') := rfl @[simp] theorem arrowCongr_symm (e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂') : (arrowCongr e₁ e₂).symm = arrowCongr e₁.symm e₂.symm := rfl /-- If `A₁` is equivalent to `A₂` and `A₁'` is equivalent to `A₂'`, then the type of maps `A₁ ≃ₐ[R] A₁'` is equivalent to the type of maps `A₂ ≃ₐ[R] A₂'`. This is the `AlgEquiv` version of `AlgEquiv.arrowCongr`. -/ @[simps apply] def equivCongr (e : A₁ ≃ₐ[R] A₂) (e' : A₁' ≃ₐ[R] A₂') : (A₁ ≃ₐ[R] A₁') ≃ A₂ ≃ₐ[R] A₂' where toFun ψ := e.symm.trans (ψ.trans e') invFun ψ := e.trans (ψ.trans e'.symm) left_inv ψ := by ext simp_rw [trans_apply, symm_apply_apply] right_inv ψ := by ext simp_rw [trans_apply, apply_symm_apply] @[simp] theorem equivCongr_refl : equivCongr AlgEquiv.refl AlgEquiv.refl = Equiv.refl (A₁ ≃ₐ[R] A₁') := rfl @[simp] theorem equivCongr_symm (e : A₁ ≃ₐ[R] A₂) (e' : A₁' ≃ₐ[R] A₂') : (equivCongr e e').symm = equivCongr e.symm e'.symm := rfl @[simp] theorem equivCongr_trans (e₁₂ : A₁ ≃ₐ[R] A₂) (e₁₂' : A₁' ≃ₐ[R] A₂') (e₂₃ : A₂ ≃ₐ[R] A₃) (e₂₃' : A₂' ≃ₐ[R] A₃') : (equivCongr e₁₂ e₁₂').trans (equivCongr e₂₃ e₂₃') = equivCongr (e₁₂.trans e₂₃) (e₁₂'.trans e₂₃') := rfl /-- If an algebra morphism has an inverse, it is an algebra isomorphism. -/ @[simps] def ofAlgHom (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ : f.comp g = AlgHom.id R A₂) (h₂ : g.comp f = AlgHom.id R A₁) : A₁ ≃ₐ[R] A₂ := { f with toFun := f invFun := g left_inv := AlgHom.ext_iff.1 h₂ right_inv := AlgHom.ext_iff.1 h₁ } theorem coe_algHom_ofAlgHom (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) : ↑(ofAlgHom f g h₁ h₂) = f := rfl @[simp] theorem ofAlgHom_coe_algHom (f : A₁ ≃ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) : ofAlgHom (↑f) g h₁ h₂ = f := ext fun _ => rfl theorem ofAlgHom_symm (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) : (ofAlgHom f g h₁ h₂).symm = ofAlgHom g f h₂ h₁ := rfl /-- Forgetting the multiplicative structures, an equivalence of algebras is a linear equivalence. -/ @[simps apply] def toLinearEquiv (e : A₁ ≃ₐ[R] A₂) : A₁ ≃ₗ[R] A₂ := { e with toFun := e map_smul' := map_smul e invFun := e.symm } @[simp] theorem toLinearEquiv_refl : (AlgEquiv.refl : A₁ ≃ₐ[R] A₁).toLinearEquiv = LinearEquiv.refl R A₁ := rfl @[simp] theorem toLinearEquiv_symm (e : A₁ ≃ₐ[R] A₂) : e.symm.toLinearEquiv = e.toLinearEquiv.symm := rfl @[simp] theorem coe_toLinearEquiv (e : A₁ ≃ₐ[R] A₂) : ⇑e.toLinearEquiv = e := rfl @[simp] theorem coe_symm_toLinearEquiv (e : A₁ ≃ₐ[R] A₂) : ⇑e.toLinearEquiv.symm = e.symm := rfl @[simp] theorem toLinearEquiv_trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) : (e₁.trans e₂).toLinearEquiv = e₁.toLinearEquiv.trans e₂.toLinearEquiv := rfl theorem toLinearEquiv_injective : Function.Injective (toLinearEquiv : _ → A₁ ≃ₗ[R] A₂) := fun _ _ h => ext <| LinearEquiv.congr_fun h /-- Interpret an algebra equivalence as a linear map. -/ def toLinearMap : A₁ →ₗ[R] A₂ := e.toAlgHom.toLinearMap @[simp] theorem toAlgHom_toLinearMap : (e : A₁ →ₐ[R] A₂).toLinearMap = e.toLinearMap := rfl theorem toLinearMap_ofAlgHom (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) : (ofAlgHom f g h₁ h₂).toLinearMap = f.toLinearMap := LinearMap.ext fun _ => rfl @[simp] theorem toLinearEquiv_toLinearMap : e.toLinearEquiv.toLinearMap = e.toLinearMap := rfl @[simp] theorem toLinearMap_apply (x : A₁) : e.toLinearMap x = e x := rfl theorem toLinearMap_injective : Function.Injective (toLinearMap : _ → A₁ →ₗ[R] A₂) := fun _ _ h => ext <| LinearMap.congr_fun h @[simp] theorem trans_toLinearMap (f : A₁ ≃ₐ[R] A₂) (g : A₂ ≃ₐ[R] A₃) : (f.trans g).toLinearMap = g.toLinearMap.comp f.toLinearMap := rfl /-- Promotes a bijective algebra homomorphism to an algebra equivalence. -/ noncomputable def ofBijective (f : A₁ →ₐ[R] A₂) (hf : Function.Bijective f) : A₁ ≃ₐ[R] A₂ := { RingEquiv.ofBijective (f : A₁ →+* A₂) hf, f with } @[simp] lemma coe_ofBijective (f : A₁ →ₐ[R] A₂) (hf : Function.Bijective f) : (ofBijective f hf : A₁ → A₂) = f := rfl lemma ofBijective_apply (f : A₁ →ₐ[R] A₂) (hf : Function.Bijective f) (a : A₁) : (ofBijective f hf) a = f a := rfl @[simp] lemma toLinearMap_ofBijective (f : A₁ →ₐ[R] A₂) (hf : Function.Bijective f) : (ofBijective f hf).toLinearMap = f := rfl @[simp] lemma toAlgHom_ofBijective (f : A₁ →ₐ[R] A₂) (hf : Function.Bijective f) : AlgHomClass.toAlgHom (ofBijective f hf) = f := rfl lemma ofBijective_apply_symm_apply (f : A₁ →ₐ[R] A₂) (hf : Function.Bijective f) (x : A₂) : f ((ofBijective f hf).symm x) = x := (ofBijective f hf).apply_symm_apply x @[simp] lemma ofBijective_symm_apply_apply (f : A₁ →ₐ[R] A₂) (hf : Function.Bijective f) (x : A₁) : (ofBijective f hf).symm (f x) = x := (ofBijective f hf).symm_apply_apply x section OfLinearEquiv variable (l : A₁ ≃ₗ[R] A₂) (map_one : l 1 = 1) (map_mul : ∀ x y : A₁, l (x * y) = l x * l y) /-- Upgrade a linear equivalence to an algebra equivalence, given that it distributes over multiplication and the identity -/ @[simps apply] def ofLinearEquiv : A₁ ≃ₐ[R] A₂ := { l with toFun := l invFun := l.symm map_mul' := map_mul commutes' := (AlgHom.ofLinearMap l map_one map_mul : A₁ →ₐ[R] A₂).commutes } /-- Auxiliary definition to avoid looping in `dsimp` with `AlgEquiv.ofLinearEquiv_symm`. -/ protected def ofLinearEquiv_symm.aux := (ofLinearEquiv l map_one map_mul).symm @[simp] theorem ofLinearEquiv_symm : (ofLinearEquiv l map_one map_mul).symm = ofLinearEquiv l.symm (_root_.map_one <| ofLinearEquiv_symm.aux l map_one map_mul) (_root_.map_mul <| ofLinearEquiv_symm.aux l map_one map_mul) := rfl @[simp] theorem ofLinearEquiv_toLinearEquiv (map_mul) (map_one) : ofLinearEquiv e.toLinearEquiv map_mul map_one = e := rfl @[simp] theorem toLinearEquiv_ofLinearEquiv : toLinearEquiv (ofLinearEquiv l map_one map_mul) = l := rfl end OfLinearEquiv section OfRingEquiv /-- Promotes a linear `RingEquiv` to an `AlgEquiv`. -/ @[simps apply symm_apply toEquiv] def ofRingEquiv {f : A₁ ≃+* A₂} (hf : ∀ x, f (algebraMap R A₁ x) = algebraMap R A₂ x) : A₁ ≃ₐ[R] A₂ := { f with toFun := f invFun := f.symm commutes' := hf } end OfRingEquiv @[simps -isSimp one mul, stacks 09HR] instance aut : Group (A₁ ≃ₐ[R] A₁) where mul ϕ ψ := ψ.trans ϕ mul_assoc _ _ _ := rfl one := refl one_mul _ := ext fun _ => rfl mul_one _ := ext fun _ => rfl inv := symm inv_mul_cancel ϕ := ext <| symm_apply_apply ϕ @[simp] theorem one_apply (x : A₁) : (1 : A₁ ≃ₐ[R] A₁) x = x := rfl @[simp] theorem mul_apply (e₁ e₂ : A₁ ≃ₐ[R] A₁) (x : A₁) : (e₁ * e₂) x = e₁ (e₂ x) := rfl lemma aut_inv (ϕ : A₁ ≃ₐ[R] A₁) : ϕ⁻¹ = ϕ.symm := rfl @[simp] theorem coe_pow (e : A₁ ≃ₐ[R] A₁) (n : ℕ) : ⇑(e ^ n) = e^[n] := n.rec (by ext; simp) fun _ ih ↦ by ext; simp [pow_succ, ih] /-- An algebra isomorphism induces a group isomorphism between automorphism groups. This is a more bundled version of `AlgEquiv.equivCongr`. -/ @[simps apply] def autCongr (ϕ : A₁ ≃ₐ[R] A₂) : (A₁ ≃ₐ[R] A₁) ≃* A₂ ≃ₐ[R] A₂ where __ := equivCongr ϕ ϕ toFun ψ := ϕ.symm.trans (ψ.trans ϕ) invFun ψ := ϕ.trans (ψ.trans ϕ.symm) map_mul' ψ χ := by ext simp only [mul_apply, trans_apply, symm_apply_apply] @[simp] theorem autCongr_refl : autCongr AlgEquiv.refl = MulEquiv.refl (A₁ ≃ₐ[R] A₁) := rfl @[simp] theorem autCongr_symm (ϕ : A₁ ≃ₐ[R] A₂) : (autCongr ϕ).symm = autCongr ϕ.symm := rfl @[simp] theorem autCongr_trans (ϕ : A₁ ≃ₐ[R] A₂) (ψ : A₂ ≃ₐ[R] A₃) : (autCongr ϕ).trans (autCongr ψ) = autCongr (ϕ.trans ψ) := rfl /-- The tautological action by `A₁ ≃ₐ[R] A₁` on `A₁`. This generalizes `Function.End.applyMulAction`. -/ instance applyMulSemiringAction : MulSemiringAction (A₁ ≃ₐ[R] A₁) A₁ where smul := (· <| ·) smul_zero := map_zero smul_add := map_add smul_one := map_one smul_mul := map_mul one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] protected theorem smul_def (f : A₁ ≃ₐ[R] A₁) (a : A₁) : f • a = f a := rfl instance apply_faithfulSMul : FaithfulSMul (A₁ ≃ₐ[R] A₁) A₁ := ⟨AlgEquiv.ext⟩ instance apply_smulCommClass {S} [SMul S R] [SMul S A₁] [IsScalarTower S R A₁] : SMulCommClass S (A₁ ≃ₐ[R] A₁) A₁ where smul_comm r e a := (e.toLinearEquiv.map_smul_of_tower r a).symm instance apply_smulCommClass' {S} [SMul S R] [SMul S A₁] [IsScalarTower S R A₁] : SMulCommClass (A₁ ≃ₐ[R] A₁) S A₁ := SMulCommClass.symm _ _ _ instance : MulDistribMulAction (A₁ ≃ₐ[R] A₁) A₁ˣ where smul := fun f => Units.map f one_smul := fun x => by ext; rfl mul_smul := fun x y z => by ext; rfl smul_mul := fun x y z => by ext; exact map_mul x _ _ smul_one := fun x => by ext; exact map_one x @[simp] theorem smul_units_def (f : A₁ ≃ₐ[R] A₁) (x : A₁ˣ) : f • x = Units.map f x := rfl @[simp] lemma _root_.MulSemiringAction.toRingEquiv_algEquiv (σ : A₁ ≃ₐ[R] A₁) : MulSemiringAction.toRingEquiv _ A₁ σ = σ := rfl @[simp] theorem algebraMap_eq_apply (e : A₁ ≃ₐ[R] A₂) {y : R} {x : A₁} : algebraMap R A₂ y = e x ↔ algebraMap R A₁ y = x := ⟨fun h => by simpa using e.symm.toAlgHom.algebraMap_eq_apply h, fun h => e.toAlgHom.algebraMap_eq_apply h⟩ /-- `AlgEquiv.toAlgHom` as a `MonoidHom`. -/ @[simps] def toAlgHomHom (R A) [CommSemiring R] [Semiring A] [Algebra R A] : (A ≃ₐ[R] A) →* A →ₐ[R] A where toFun := AlgEquiv.toAlgHom map_one' := rfl map_mul' _ _ := rfl /-- `AlgEquiv.toLinearMap` as a `MonoidHom`. -/ @[simps!] def toLinearMapHom (R A) [CommSemiring R] [Semiring A] [Algebra R A] : (A ≃ₐ[R] A) →* Module.End R A := AlgHom.toEnd.comp (toAlgHomHom R A) lemma pow_toLinearMap (σ : A₁ ≃ₐ[R] A₁) (n : ℕ) : (σ ^ n).toLinearMap = σ.toLinearMap ^ n := (AlgEquiv.toLinearMapHom R A₁).map_pow σ n @[simp] lemma one_toLinearMap : (1 : A₁ ≃ₐ[R] A₁).toLinearMap = 1 := rfl /-- The units group of `S →ₐ[R] S` is `S ≃ₐ[R] S`. See `LinearMap.GeneralLinearGroup.generalLinearEquiv` for the linear map version. -/ @[simps] def algHomUnitsEquiv (R S : Type*) [CommSemiring R] [Semiring S] [Algebra R S] : (S →ₐ[R] S)ˣ ≃* (S ≃ₐ[R] S) where toFun := fun f ↦ { (f : S →ₐ[R] S) with invFun := ↑(f⁻¹) left_inv := (fun x ↦ show (↑(f⁻¹ * f) : S →ₐ[R] S) x = x by rw [inv_mul_cancel]; rfl) right_inv := (fun x ↦ show (↑(f * f⁻¹) : S →ₐ[R] S) x = x by rw [mul_inv_cancel]; rfl) } invFun := fun f ↦ ⟨f, f.symm, f.comp_symm, f.symm_comp⟩ map_mul' := fun _ _ ↦ rfl /-- See also `Finite.algHom` -/ instance _root_.Finite.algEquiv [Finite (A₁ →ₐ[R] A₂)] : Finite (A₁ ≃ₐ[R] A₂) := Finite.of_injective _ AlgEquiv.coe_algHom_injective end Semiring end AlgEquiv namespace MulSemiringAction variable {M G : Type*} (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] section variable [Group G] [MulSemiringAction G A] [SMulCommClass G R A] /-- Each element of the group defines an algebra equivalence. This is a stronger version of `MulSemiringAction.toRingEquiv` and `DistribMulAction.toLinearEquiv`. -/ @[simps! apply symm_apply toEquiv] def toAlgEquiv (g : G) : A ≃ₐ[R] A := { MulSemiringAction.toRingEquiv _ _ g, MulSemiringAction.toAlgHom R A g with } theorem toAlgEquiv_injective [FaithfulSMul G A] : Function.Injective (MulSemiringAction.toAlgEquiv R A : G → A ≃ₐ[R] A) := fun _ _ h => eq_of_smul_eq_smul fun r => AlgEquiv.ext_iff.1 h r variable (G) /-- Each element of the group defines an algebra equivalence. This is a stronger version of `MulSemiringAction.toRingAut` and `DistribMulAction.toModuleEnd`. -/ @[simps] def toAlgAut : G →* A ≃ₐ[R] A where toFun := toAlgEquiv R A map_one' := AlgEquiv.ext <| one_smul _ map_mul' g h := AlgEquiv.ext <| mul_smul g h end end MulSemiringAction section variable {R S T : Type*} [CommSemiring R] [Semiring S] [Semiring T] [Algebra R S] [Algebra R T] instance [Subsingleton S] [Subsingleton T] : Unique (S ≃ₐ[R] T) where default := AlgEquiv.ofAlgHom default default (AlgHom.ext fun _ ↦ Subsingleton.elim _ _) (AlgHom.ext fun _ ↦ Subsingleton.elim _ _) uniq _ := AlgEquiv.ext fun _ ↦ Subsingleton.elim _ _ @[simp] lemma AlgEquiv.default_apply [Subsingleton S] [Subsingleton T] (x : S) : (default : S ≃ₐ[R] T) x = 0 := rfl end /-- The algebra equivalence between `ULift A` and `A`. -/ @[simps! -isSimp apply] def ULift.algEquiv {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A] : ULift.{w} A ≃ₐ[R] A where __ := ULift.ringEquiv commutes' _ := rfl /-- If an `R`-algebra `A` is isomorphic to `R` as `R`-module, then the canonical map `R → A` is an equivalence of `R`-algebras. Note that if `e : R ≃ₗ[R] A` is the linear equivalence, then this is not the same as the equivalence of algebras provided here unless `e 1 = 1`. -/ @[simps] def LinearEquiv.algEquivOfRing {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (e : R ≃ₗ[R] A) : R ≃ₐ[R] A where __ := Algebra.ofId R A invFun x := e.symm (e 1 * x) left_inv x := calc e.symm (e 1 * (algebraMap R A) x) = e.symm (x • e 1) := by rw [Algebra.smul_def, mul_comm] _ = x := by rw [map_smul, e.symm_apply_apply, smul_eq_mul, mul_one] right_inv x := calc (algebraMap R A) (e.symm (e 1 * x)) = (algebraMap R A) (e.symm (e 1 * x)) * e (e.symm 1 • 1) := by rw [smul_eq_mul, mul_one, e.apply_symm_apply, mul_one] _ = x := by rw [map_smul, Algebra.smul_def, mul_left_comm, ← Algebra.smul_def _ (e 1), ← map_smul, smul_eq_mul, mul_one, e.apply_symm_apply, ← mul_assoc, ← Algebra.smul_def, ← map_smul, smul_eq_mul, mul_one, e.apply_symm_apply, one_mul]
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Field.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Data.Rat.Cast.Defs /-! # Facts about `algebraMap` when the coefficient ring is a field. -/ namespace algebraMap universe u v w u₁ v₁ section SemifieldSemidivisionRing variable {R : Type*} (A : Type*) [Semifield R] [DivisionSemiring A] [Algebra R A] @[norm_cast] theorem coe_inv (r : R) : ↑r⁻¹ = ((↑r)⁻¹ : A) := map_inv₀ (algebraMap R A) r @[norm_cast] theorem coe_div (r s : R) : ↑(r / s) = (↑r / ↑s : A) := map_div₀ (algebraMap R A) r s @[norm_cast] theorem coe_zpow (r : R) (z : ℤ) : ↑(r ^ z) = (r : A) ^ z := map_zpow₀ (algebraMap R A) r z end SemifieldSemidivisionRing section FieldDivisionRing variable (R A : Type*) [Field R] [DivisionRing A] [Algebra R A] @[norm_cast] theorem coe_ratCast (q : ℚ) : ↑(q : R) = (q : A) := map_ratCast (algebraMap R A) q end FieldDivisionRing end algebraMap
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Unitization.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.Algebra.Star.Module import Mathlib.Algebra.Star.NonUnitalSubalgebra import Mathlib.LinearAlgebra.Prod import Mathlib.Tactic.Abel /-! # Unitization of a non-unital algebra Given a non-unital `R`-algebra `A` (given via the type classes `[NonUnitalRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]`) we construct the minimal unital `R`-algebra containing `A` as an ideal. This object `Unitization R A` is a type synonym for `R × A` on which we place a different multiplicative structure, namely, `(r₁, a₁) * (r₂, a₂) = (r₁ * r₂, r₁ • a₂ + r₂ • a₁ + a₁ * a₂)` where the multiplicative identity is `(1, 0)`. Note, when `A` is a *unital* `R`-algebra, then `Unitization R A` constructs a new multiplicative identity different from the old one, and so in general `Unitization R A` and `A` will not be isomorphic even in the unital case. This approach actually has nice functorial properties. There is a natural coercion from `A` to `Unitization R A` given by `fun a ↦ (0, a)`, the image of which is a proper ideal (TODO), and when `R` is a field this ideal is maximal. Moreover, this ideal is always an essential ideal (it has nontrivial intersection with every other nontrivial ideal). Every non-unital algebra homomorphism from `A` into a *unital* `R`-algebra `B` has a unique extension to a (unital) algebra homomorphism from `Unitization R A` to `B`. ## Main definitions * `Unitization R A`: the unitization of a non-unital `R`-algebra `A`. * `Unitization.algebra`: the unitization of `A` as a (unital) `R`-algebra. * `Unitization.coeNonUnitalAlgHom`: coercion as a non-unital algebra homomorphism. * `NonUnitalAlgHom.toAlgHom φ`: the extension of a non-unital algebra homomorphism `φ : A → B` into a unital `R`-algebra `B` to an algebra homomorphism `Unitization R A →ₐ[R] B`. * `Unitization.lift`: the universal property of the unitization, the extension `NonUnitalAlgHom.toAlgHom` actually implements an equivalence `(A →ₙₐ[R] B) ≃ (Unitization R A ≃ₐ[R] B)` ## Main results * `AlgHom.ext'`: an extensionality lemma for algebra homomorphisms whose domain is `Unitization R A`; it suffices that they agree on `A`. ## TODO * prove the unitization operation is a functor between the appropriate categories * prove the image of the coercion is an essential ideal, maximal if scalars are a field. -/ /-- The minimal unitization of a non-unital `R`-algebra `A`. This is just a type synonym for `R × A`. -/ def Unitization (R A : Type*) := R × A namespace Unitization section Basic variable {R A : Type*} /-- The canonical inclusion `R → Unitization R A`. -/ def inl [Zero A] (r : R) : Unitization R A := (r, 0) /-- The canonical inclusion `A → Unitization R A`. -/ @[coe] def inr [Zero R] (a : A) : Unitization R A := (0, a) instance [Zero R] : CoeTC A (Unitization R A) where coe := inr /-- The canonical projection `Unitization R A → R`. -/ def fst (x : Unitization R A) : R := x.1 /-- The canonical projection `Unitization R A → A`. -/ def snd (x : Unitization R A) : A := x.2 @[ext] theorem ext {x y : Unitization R A} (h1 : x.fst = y.fst) (h2 : x.snd = y.snd) : x = y := Prod.ext h1 h2 section variable (A) @[simp] theorem fst_inl [Zero A] (r : R) : (inl r : Unitization R A).fst = r := rfl @[simp] theorem snd_inl [Zero A] (r : R) : (inl r : Unitization R A).snd = 0 := rfl end section variable (R) @[simp] theorem fst_inr [Zero R] (a : A) : (a : Unitization R A).fst = 0 := rfl @[simp] theorem snd_inr [Zero R] (a : A) : (a : Unitization R A).snd = a := rfl end theorem inl_injective [Zero A] : Function.Injective (inl : R → Unitization R A) := Function.LeftInverse.injective <| fst_inl _ theorem inr_injective [Zero R] : Function.Injective ((↑) : A → Unitization R A) := Function.LeftInverse.injective <| snd_inr _ instance instNontrivialLeft {𝕜 A} [Nontrivial 𝕜] [Nonempty A] : Nontrivial (Unitization 𝕜 A) := nontrivial_prod_left instance instNontrivialRight {𝕜 A} [Nonempty 𝕜] [Nontrivial A] : Nontrivial (Unitization 𝕜 A) := nontrivial_prod_right end Basic /-! ### Structures inherited from `Prod` Additive operators and scalar multiplication operate elementwise. -/ section Additive variable {T : Type*} {S : Type*} {R : Type*} {A : Type*} instance instCanLift [Zero R] : CanLift (Unitization R A) A inr (fun x ↦ x.fst = 0) where prf x hx := ⟨x.snd, ext (hx ▸ fst_inr R (snd x)) rfl⟩ instance instInhabited [Inhabited R] [Inhabited A] : Inhabited (Unitization R A) := instInhabitedProd instance instZero [Zero R] [Zero A] : Zero (Unitization R A) := Prod.instZero instance instAdd [Add R] [Add A] : Add (Unitization R A) := Prod.instAdd instance instNeg [Neg R] [Neg A] : Neg (Unitization R A) := Prod.instNeg instance instAddSemigroup [AddSemigroup R] [AddSemigroup A] : AddSemigroup (Unitization R A) := Prod.instAddSemigroup instance instAddZeroClass [AddZeroClass R] [AddZeroClass A] : AddZeroClass (Unitization R A) := Prod.instAddZeroClass instance instAddMonoid [AddMonoid R] [AddMonoid A] : AddMonoid (Unitization R A) := Prod.instAddMonoid instance instAddGroup [AddGroup R] [AddGroup A] : AddGroup (Unitization R A) := Prod.instAddGroup instance instAddCommSemigroup [AddCommSemigroup R] [AddCommSemigroup A] : AddCommSemigroup (Unitization R A) := Prod.instAddCommSemigroup instance instAddCommMonoid [AddCommMonoid R] [AddCommMonoid A] : AddCommMonoid (Unitization R A) := Prod.instAddCommMonoid instance instAddCommGroup [AddCommGroup R] [AddCommGroup A] : AddCommGroup (Unitization R A) := Prod.instAddCommGroup instance instSMul [SMul S R] [SMul S A] : SMul S (Unitization R A) := Prod.instSMul instance instIsScalarTower [SMul T R] [SMul T A] [SMul S R] [SMul S A] [SMul T S] [IsScalarTower T S R] [IsScalarTower T S A] : IsScalarTower T S (Unitization R A) := Prod.isScalarTower instance instSMulCommClass [SMul T R] [SMul T A] [SMul S R] [SMul S A] [SMulCommClass T S R] [SMulCommClass T S A] : SMulCommClass T S (Unitization R A) := Prod.smulCommClass instance instIsCentralScalar [SMul S R] [SMul S A] [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ A] [IsCentralScalar S R] [IsCentralScalar S A] : IsCentralScalar S (Unitization R A) := Prod.isCentralScalar instance instMulAction [Monoid S] [MulAction S R] [MulAction S A] : MulAction S (Unitization R A) := Prod.mulAction instance instDistribMulAction [Monoid S] [AddMonoid R] [AddMonoid A] [DistribMulAction S R] [DistribMulAction S A] : DistribMulAction S (Unitization R A) := Prod.distribMulAction instance instModule [Semiring S] [AddCommMonoid R] [AddCommMonoid A] [Module S R] [Module S A] : Module S (Unitization R A) := Prod.instModule variable (R A) in /-- The identity map between `Unitization R A` and `R × A` as an `AddEquiv`. -/ def addEquiv [Add R] [Add A] : Unitization R A ≃+ R × A := AddEquiv.refl _ @[simp] theorem fst_zero [Zero R] [Zero A] : (0 : Unitization R A).fst = 0 := rfl @[simp] theorem snd_zero [Zero R] [Zero A] : (0 : Unitization R A).snd = 0 := rfl @[simp] theorem fst_add [Add R] [Add A] (x₁ x₂ : Unitization R A) : (x₁ + x₂).fst = x₁.fst + x₂.fst := rfl @[simp] theorem snd_add [Add R] [Add A] (x₁ x₂ : Unitization R A) : (x₁ + x₂).snd = x₁.snd + x₂.snd := rfl @[simp] theorem fst_neg [Neg R] [Neg A] (x : Unitization R A) : (-x).fst = -x.fst := rfl @[simp] theorem snd_neg [Neg R] [Neg A] (x : Unitization R A) : (-x).snd = -x.snd := rfl @[simp] theorem fst_smul [SMul S R] [SMul S A] (s : S) (x : Unitization R A) : (s • x).fst = s • x.fst := rfl @[simp] theorem snd_smul [SMul S R] [SMul S A] (s : S) (x : Unitization R A) : (s • x).snd = s • x.snd := rfl section variable (A) @[simp] theorem inl_zero [Zero R] [Zero A] : (inl 0 : Unitization R A) = 0 := rfl @[simp] theorem inl_add [Add R] [AddZeroClass A] (r₁ r₂ : R) : (inl (r₁ + r₂) : Unitization R A) = inl r₁ + inl r₂ := ext rfl (add_zero 0).symm @[simp] theorem inl_neg [Neg R] [SubtractionMonoid A] (r : R) : (inl (-r) : Unitization R A) = -inl r := ext rfl neg_zero.symm @[simp] theorem inl_sub [AddGroup R] [AddGroup A] (r₁ r₂ : R) : (inl (r₁ - r₂) : Unitization R A) = inl r₁ - inl r₂ := ext rfl (sub_zero 0).symm @[simp] theorem inl_smul [Zero A] [SMul S R] [SMulZeroClass S A] (s : S) (r : R) : (inl (s • r) : Unitization R A) = s • inl r := ext rfl (smul_zero s).symm end section variable (R) @[simp] theorem inr_zero [Zero R] [Zero A] : ↑(0 : A) = (0 : Unitization R A) := rfl @[simp] theorem inr_add [AddZeroClass R] [Add A] (m₁ m₂ : A) : (↑(m₁ + m₂) : Unitization R A) = m₁ + m₂ := ext (add_zero 0).symm rfl @[simp] theorem inr_neg [SubtractionMonoid R] [Neg A] (m : A) : (↑(-m) : Unitization R A) = -m := ext neg_zero.symm rfl @[simp] theorem inr_sub [AddGroup R] [AddGroup A] (m₁ m₂ : A) : (↑(m₁ - m₂) : Unitization R A) = m₁ - m₂ := ext (sub_zero 0).symm rfl @[simp] theorem inr_smul [Zero R] [SMulZeroClass S R] [SMul S A] (r : S) (m : A) : (↑(r • m) : Unitization R A) = r • (m : Unitization R A) := ext (smul_zero _).symm rfl end theorem inl_fst_add_inr_snd_eq [AddZeroClass R] [AddZeroClass A] (x : Unitization R A) : inl x.fst + (x.snd : Unitization R A) = x := ext (add_zero x.1) (zero_add x.2) /-- To show a property hold on all `Unitization R A` it suffices to show it holds on terms of the form `inl r + a`. This can be used as `induction x`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] theorem ind {R A} [AddZeroClass R] [AddZeroClass A] {P : Unitization R A → Prop} (inl_add_inr : ∀ (r : R) (a : A), P (inl r + (a : Unitization R A))) (x) : P x := inl_fst_add_inr_snd_eq x ▸ inl_add_inr x.1 x.2 /-- This cannot be marked `@[ext]` as it ends up being used instead of `LinearMap.prod_ext` when working with `R × A`. -/ theorem linearMap_ext {N} [Semiring S] [AddCommMonoid R] [AddCommMonoid A] [AddCommMonoid N] [Module S R] [Module S A] [Module S N] ⦃f g : Unitization R A →ₗ[S] N⦄ (hl : ∀ r, f (inl r) = g (inl r)) (hr : ∀ a : A, f a = g a) : f = g := LinearMap.prod_ext (LinearMap.ext hl) (LinearMap.ext hr) variable (R A) /-- The canonical `R`-linear inclusion `A → Unitization R A`. -/ @[simps apply] def inrHom [Semiring R] [AddCommMonoid A] [Module R A] : A →ₗ[R] Unitization R A := { LinearMap.inr R R A with toFun := (↑) } /-- The canonical `R`-linear projection `Unitization R A → A`. -/ @[simps apply] def sndHom [Semiring R] [AddCommMonoid A] [Module R A] : Unitization R A →ₗ[R] A := { LinearMap.snd _ _ _ with toFun := snd } end Additive /-! ### Multiplicative structure -/ section Mul variable {R A : Type*} instance instOne [One R] [Zero A] : One (Unitization R A) := ⟨(1, 0)⟩ instance instMul [Mul R] [Add A] [Mul A] [SMul R A] : Mul (Unitization R A) := ⟨fun x y => (x.1 * y.1, x.1 • y.2 + y.1 • x.2 + x.2 * y.2)⟩ @[simp] theorem fst_one [One R] [Zero A] : (1 : Unitization R A).fst = 1 := rfl @[simp] theorem snd_one [One R] [Zero A] : (1 : Unitization R A).snd = 0 := rfl @[simp] theorem fst_mul [Mul R] [Add A] [Mul A] [SMul R A] (x₁ x₂ : Unitization R A) : (x₁ * x₂).fst = x₁.fst * x₂.fst := rfl @[simp] theorem snd_mul [Mul R] [Add A] [Mul A] [SMul R A] (x₁ x₂ : Unitization R A) : (x₁ * x₂).snd = x₁.fst • x₂.snd + x₂.fst • x₁.snd + x₁.snd * x₂.snd := rfl section variable (A) @[simp] theorem inl_one [One R] [Zero A] : (inl 1 : Unitization R A) = 1 := rfl @[simp] theorem inl_mul [Mul R] [NonUnitalNonAssocSemiring A] [SMulZeroClass R A] (r₁ r₂ : R) : (inl (r₁ * r₂) : Unitization R A) = inl r₁ * inl r₂ := ext rfl <| show (0 : A) = r₁ • (0 : A) + r₂ • (0 : A) + 0 * 0 by simp only [smul_zero, add_zero, mul_zero] theorem inl_mul_inl [Mul R] [NonUnitalNonAssocSemiring A] [SMulZeroClass R A] (r₁ r₂ : R) : (inl r₁ * inl r₂ : Unitization R A) = inl (r₁ * r₂) := (inl_mul A r₁ r₂).symm end section variable (R) @[simp] theorem inr_mul [MulZeroClass R] [AddZeroClass A] [Mul A] [SMulWithZero R A] (a₁ a₂ : A) : (↑(a₁ * a₂) : Unitization R A) = a₁ * a₂ := ext (mul_zero _).symm <| show a₁ * a₂ = (0 : R) • a₂ + (0 : R) • a₁ + a₁ * a₂ by simp only [zero_smul, zero_add] end theorem inl_mul_inr [MulZeroClass R] [NonUnitalNonAssocSemiring A] [SMulZeroClass R A] (r : R) (a : A) : ((inl r : Unitization R A) * a) = ↑(r • a) := ext (mul_zero r) <| show r • a + (0 : R) • (0 : A) + 0 * a = r • a by rw [smul_zero, add_zero, zero_mul, add_zero] theorem inr_mul_inl [MulZeroClass R] [NonUnitalNonAssocSemiring A] [SMulZeroClass R A] (r : R) (a : A) : a * (inl r : Unitization R A) = ↑(r • a) := ext (zero_mul r) <| show (0 : R) • (0 : A) + r • a + a * 0 = r • a by rw [smul_zero, zero_add, mul_zero, add_zero] instance instMulOneClass [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] : MulOneClass (Unitization R A) := { Unitization.instOne, Unitization.instMul with one_mul := fun x => ext (one_mul x.1) <| show (1 : R) • x.2 + x.1 • (0 : A) + 0 * x.2 = x.2 by rw [one_smul, smul_zero, add_zero, zero_mul, add_zero] mul_one := fun x => ext (mul_one x.1) <| show (x.1 • (0 : A)) + (1 : R) • x.2 + x.2 * (0 : A) = x.2 by rw [smul_zero, zero_add, one_smul, mul_zero, add_zero] } instance instNonAssocSemiring [Semiring R] [NonUnitalNonAssocSemiring A] [Module R A] : NonAssocSemiring (Unitization R A) := { Unitization.instMulOneClass, Unitization.instAddCommMonoid with zero_mul := fun x => ext (zero_mul x.1) <| show (0 : R) • x.2 + x.1 • (0 : A) + 0 * x.2 = 0 by rw [zero_smul, zero_add, smul_zero, zero_mul, add_zero] mul_zero := fun x => ext (mul_zero x.1) <| show x.1 • (0 : A) + (0 : R) • x.2 + x.2 * 0 = 0 by rw [smul_zero, zero_add, zero_smul, mul_zero, add_zero] left_distrib := fun x₁ x₂ x₃ => ext (mul_add x₁.1 x₂.1 x₃.1) <| show x₁.1 • (x₂.2 + x₃.2) + (x₂.1 + x₃.1) • x₁.2 + x₁.2 * (x₂.2 + x₃.2) = x₁.1 • x₂.2 + x₂.1 • x₁.2 + x₁.2 * x₂.2 + (x₁.1 • x₃.2 + x₃.1 • x₁.2 + x₁.2 * x₃.2) by simp only [smul_add, add_smul, mul_add] abel right_distrib := fun x₁ x₂ x₃ => ext (add_mul x₁.1 x₂.1 x₃.1) <| show (x₁.1 + x₂.1) • x₃.2 + x₃.1 • (x₁.2 + x₂.2) + (x₁.2 + x₂.2) * x₃.2 = x₁.1 • x₃.2 + x₃.1 • x₁.2 + x₁.2 * x₃.2 + (x₂.1 • x₃.2 + x₃.1 • x₂.2 + x₂.2 * x₃.2) by simp only [add_smul, smul_add, add_mul] abel } instance instMonoid [CommMonoid R] [NonUnitalSemiring A] [DistribMulAction R A] [IsScalarTower R A A] [SMulCommClass R A A] : Monoid (Unitization R A) := { Unitization.instMulOneClass with mul_assoc := fun x y z => ext (mul_assoc x.1 y.1 z.1) <| show (x.1 * y.1) • z.2 + z.1 • (x.1 • y.2 + y.1 • x.2 + x.2 * y.2) + (x.1 • y.2 + y.1 • x.2 + x.2 * y.2) * z.2 = x.1 • (y.1 • z.2 + z.1 • y.2 + y.2 * z.2) + (y.1 * z.1) • x.2 + x.2 * (y.1 • z.2 + z.1 • y.2 + y.2 * z.2) by simp only [smul_add, mul_add, add_mul, smul_smul, smul_mul_assoc, mul_smul_comm, mul_assoc] rw [mul_comm z.1 x.1] rw [mul_comm z.1 y.1] abel } instance instCommMonoid [CommMonoid R] [NonUnitalCommSemiring A] [DistribMulAction R A] [IsScalarTower R A A] [SMulCommClass R A A] : CommMonoid (Unitization R A) := { Unitization.instMonoid with mul_comm := fun x₁ x₂ => ext (mul_comm x₁.1 x₂.1) <| show x₁.1 • x₂.2 + x₂.1 • x₁.2 + x₁.2 * x₂.2 = x₂.1 • x₁.2 + x₁.1 • x₂.2 + x₂.2 * x₁.2 by rw [add_comm (x₁.1 • x₂.2), mul_comm] } instance instSemiring [CommSemiring R] [NonUnitalSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : Semiring (Unitization R A) := { Unitization.instMonoid, Unitization.instNonAssocSemiring with } instance instCommSemiring [CommSemiring R] [NonUnitalCommSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : CommSemiring (Unitization R A) := { Unitization.instCommMonoid, Unitization.instNonAssocSemiring with } instance instNonAssocRing [CommRing R] [NonUnitalNonAssocRing A] [Module R A] : NonAssocRing (Unitization R A) := { Unitization.instAddCommGroup, Unitization.instNonAssocSemiring with } instance instRing [CommRing R] [NonUnitalRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : Ring (Unitization R A) := { Unitization.instAddCommGroup, Unitization.instSemiring with } instance instCommRing [CommRing R] [NonUnitalCommRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : CommRing (Unitization R A) := { Unitization.instAddCommGroup, Unitization.instCommSemiring with } variable (R A) /-- The canonical inclusion of rings `R →+* Unitization R A`. -/ @[simps apply] def inlRingHom [Semiring R] [NonUnitalSemiring A] [Module R A] : R →+* Unitization R A where toFun := inl map_one' := inl_one A map_mul' := inl_mul A map_zero' := inl_zero A map_add' := inl_add A end Mul /-! ### Star structure -/ section Star variable {R A : Type*} instance instStar [Star R] [Star A] : Star (Unitization R A) := ⟨fun ra => (star ra.fst, star ra.snd)⟩ @[simp] theorem fst_star [Star R] [Star A] (x : Unitization R A) : (star x).fst = star x.fst := rfl @[simp] theorem snd_star [Star R] [Star A] (x : Unitization R A) : (star x).snd = star x.snd := rfl @[simp] theorem inl_star [Star R] [AddMonoid A] [StarAddMonoid A] (r : R) : inl (star r) = star (inl r : Unitization R A) := ext rfl (by simp only [snd_star, star_zero, snd_inl]) @[simp] theorem inr_star [AddMonoid R] [StarAddMonoid R] [Star A] (a : A) : ↑(star a) = star (a : Unitization R A) := ext (by simp only [fst_star, star_zero, fst_inr]) rfl instance instStarAddMonoid [AddMonoid R] [AddMonoid A] [StarAddMonoid R] [StarAddMonoid A] : StarAddMonoid (Unitization R A) where star_involutive x := ext (star_star x.fst) (star_star x.snd) star_add x y := ext (star_add x.fst y.fst) (star_add x.snd y.snd) instance instStarModule [CommSemiring R] [StarRing R] [AddCommMonoid A] [StarAddMonoid A] [Module R A] [StarModule R A] : StarModule R (Unitization R A) where star_smul r x := ext (by simp) (by simp) instance instStarRing [CommSemiring R] [StarRing R] [NonUnitalNonAssocSemiring A] [StarRing A] [Module R A] [StarModule R A] : StarRing (Unitization R A) := { Unitization.instStarAddMonoid with star_mul := fun x y => ext (by simp [-star_mul']) (by simp [-star_mul', add_comm (star x.fst • star y.snd)]) } end Star /-! ### Algebra structure -/ section Algebra variable (S R A : Type*) [CommSemiring S] [CommSemiring R] [NonUnitalSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [Algebra S R] [DistribMulAction S A] [IsScalarTower S R A] instance instAlgebra : Algebra S (Unitization R A) where algebraMap := (Unitization.inlRingHom R A).comp (algebraMap S R) commutes' := fun s x => by induction x with | inl_add_inr => change inl (algebraMap S R s) * _ = _ * inl (algebraMap S R s) rw [mul_add, add_mul, inl_mul_inl, inl_mul_inl, inl_mul_inr, inr_mul_inl, mul_comm] smul_def' := fun s x => by induction x with | inl_add_inr => change _ = inl (algebraMap S R s) * _ rw [mul_add, smul_add,Algebra.algebraMap_eq_smul_one, inl_mul_inl, inl_mul_inr, smul_one_mul, inl_smul, inr_smul, smul_one_smul] theorem algebraMap_eq_inl_comp : ⇑(algebraMap S (Unitization R A)) = inl ∘ algebraMap S R := rfl theorem algebraMap_eq_inlRingHom_comp : algebraMap S (Unitization R A) = (inlRingHom R A).comp (algebraMap S R) := rfl theorem algebraMap_eq_inl : ⇑(algebraMap R (Unitization R A)) = inl := rfl theorem algebraMap_eq_inlRingHom : algebraMap R (Unitization R A) = inlRingHom R A := rfl /-- The canonical `R`-algebra projection `Unitization R A → R`. -/ @[simps] def fstHom : Unitization R A →ₐ[R] R where toFun := fst map_one' := fst_one map_mul' := fst_mul map_zero' := fst_zero (A := A) map_add' := fst_add commutes' := fst_inl A end Algebra section coe /-- The coercion from a non-unital `R`-algebra `A` to its unitization `Unitization R A` realized as a non-unital algebra homomorphism. -/ @[simps] def inrNonUnitalAlgHom (R A : Type*) [CommSemiring R] [NonUnitalSemiring A] [Module R A] : A →ₙₐ[R] Unitization R A where toFun := (↑) map_smul' := inr_smul R map_zero' := inr_zero R map_add' := inr_add R map_mul' := inr_mul R /-- The coercion from a non-unital `R`-algebra `A` to its unitization `Unitization R A` realized as a non-unital star algebra homomorphism. -/ @[simps!] def inrNonUnitalStarAlgHom (R A : Type*) [CommSemiring R] [StarAddMonoid R] [NonUnitalSemiring A] [Star A] [Module R A] : A →⋆ₙₐ[R] Unitization R A where toNonUnitalAlgHom := inrNonUnitalAlgHom R A map_star' := inr_star /-- The star algebra equivalence obtained by restricting `Unitization.inrNonUnitalStarAlgHom` to its range. -/ @[simps!] def inrRangeEquiv (R A : Type*) [CommSemiring R] [StarAddMonoid R] [NonUnitalSemiring A] [Star A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : A ≃⋆ₐ[R] NonUnitalStarAlgHom.range (inrNonUnitalStarAlgHom R A) := StarAlgEquiv.ofLeftInverse' (snd_inr R) end coe section AlgHom variable {S R A : Type*} [CommSemiring S] [CommSemiring R] [NonUnitalSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] {B : Type*} [Semiring B] [Algebra S B] [Algebra S R] [DistribMulAction S A] [IsScalarTower S R A] {C : Type*} [Semiring C] [Algebra R C] theorem algHom_ext {F : Type*} [FunLike F (Unitization R A) B] [AlgHomClass F S (Unitization R A) B] {φ ψ : F} (h : ∀ a : A, φ a = ψ a) (h' : ∀ r, φ (algebraMap R (Unitization R A) r) = ψ (algebraMap R (Unitization R A) r)) : φ = ψ := by refine DFunLike.ext φ ψ (fun x ↦ ?_) induction x simp only [map_add, ← algebraMap_eq_inl, h, h'] lemma algHom_ext'' {F : Type*} [FunLike F (Unitization R A) C] [AlgHomClass F R (Unitization R A) C] {φ ψ : F} (h : ∀ a : A, φ a = ψ a) : φ = ψ := algHom_ext h (fun r => by simp only [AlgHomClass.commutes]) /-- See note [partially-applied ext lemmas] -/ @[ext 1100] theorem algHom_ext' {φ ψ : Unitization R A →ₐ[R] C} (h : φ.toNonUnitalAlgHom.comp (inrNonUnitalAlgHom R A) = ψ.toNonUnitalAlgHom.comp (inrNonUnitalAlgHom R A)) : φ = ψ := algHom_ext'' (NonUnitalAlgHom.congr_fun h) /-- A non-unital algebra homomorphism from `A` into a unital `R`-algebra `C` lifts to a unital algebra homomorphism from the unitization into `C`. This is extended to an `Equiv` in `Unitization.lift` and that should be used instead. This declaration only exists for performance reasons. -/ @[simps] def _root_.NonUnitalAlgHom.toAlgHom (φ : A →ₙₐ[R] C) : Unitization R A →ₐ[R] C where toFun := fun x => algebraMap R C x.fst + φ x.snd map_one' := by simp only [fst_one, map_one, snd_one, φ.map_zero, add_zero] map_mul' := fun x y => by induction x with | inl_add_inr x_r x_a => induction y with | inl_add_inr => simp only [fst_mul, fst_add, fst_inl, fst_inr, snd_mul, snd_add, snd_inl, snd_inr, add_zero, map_mul, zero_add, map_add, map_smul φ] rw [add_mul, mul_add, mul_add] rw [← Algebra.commutes _ (φ x_a)] simp only [Algebra.algebraMap_eq_smul_one, smul_one_mul, add_assoc] map_zero' := by simp only [fst_zero, map_zero, snd_zero, φ.map_zero, add_zero] map_add' := fun x y => by induction x with | inl_add_inr => induction y with | inl_add_inr => simp only [fst_add, fst_inl, fst_inr, add_zero, map_add, snd_add, snd_inl, snd_inr, zero_add, φ.map_add] rw [add_add_add_comm] commutes' := fun r => by simp only [algebraMap_eq_inl, fst_inl, snd_inl, φ.map_zero, add_zero] /-- Non-unital algebra homomorphisms from `A` into a unital `R`-algebra `C` lift uniquely to `Unitization R A →ₐ[R] C`. This is the universal property of the unitization. -/ @[simps! apply symm_apply apply_apply] def lift : (A →ₙₐ[R] C) ≃ (Unitization R A →ₐ[R] C) where toFun := NonUnitalAlgHom.toAlgHom invFun φ := φ.toNonUnitalAlgHom.comp (inrNonUnitalAlgHom R A) left_inv φ := by ext; simp [NonUnitalAlgHomClass.toNonUnitalAlgHom] right_inv φ := by ext; simp [NonUnitalAlgHomClass.toNonUnitalAlgHom] theorem lift_symm_apply_apply (φ : Unitization R A →ₐ[R] C) (a : A) : Unitization.lift.symm φ a = φ a := rfl @[simp] lemma _root_.NonUnitalAlgHom.toAlgHom_zero : ⇑(0 : A →ₙₐ[R] R).toAlgHom = Unitization.fst := by ext simp end AlgHom section StarAlgHom variable {R A C : Type*} [CommSemiring R] [StarRing R] [NonUnitalSemiring A] [StarRing A] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] variable [Semiring C] [Algebra R C] [StarRing C] /-- See note [partially-applied ext lemmas] -/ @[ext] theorem starAlgHom_ext {φ ψ : Unitization R A →⋆ₐ[R] C} (h : (φ : Unitization R A →⋆ₙₐ[R] C).comp (Unitization.inrNonUnitalStarAlgHom R A) = (ψ : Unitization R A →⋆ₙₐ[R] C).comp (Unitization.inrNonUnitalStarAlgHom R A)) : φ = ψ := Unitization.algHom_ext'' <| DFunLike.congr_fun h variable [StarModule R C] /-- Non-unital star algebra homomorphisms from `A` into a unital star `R`-algebra `C` lift uniquely to `Unitization R A →⋆ₐ[R] C`. This is the universal property of the unitization. -/ @[simps! apply symm_apply apply_apply] def starLift : (A →⋆ₙₐ[R] C) ≃ (Unitization R A →⋆ₐ[R] C) := { toFun := fun φ ↦ { toAlgHom := Unitization.lift φ.toNonUnitalAlgHom map_star' := fun x => by simp [map_star] } invFun := fun φ ↦ φ.toNonUnitalStarAlgHom.comp (inrNonUnitalStarAlgHom R A), left_inv := fun φ => by ext; simp, right_inv := fun φ => Unitization.algHom_ext'' <| by simp } @[simp high] theorem starLift_symm_apply_apply (φ : Unitization R A →⋆ₐ[R] C) (a : A) : Unitization.starLift.symm φ a = φ a := rfl end StarAlgHom section StarMap variable {R A B C : Type*} [CommSemiring R] [StarRing R] variable [NonUnitalSemiring A] [StarRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] variable [NonUnitalSemiring B] [StarRing B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B] variable [NonUnitalSemiring C] [StarRing C] [Module R C] [SMulCommClass R C C] [IsScalarTower R C C] variable [StarModule R B] [StarModule R C] /-- The functorial map on morphisms between the category of non-unital C⋆-algebras with non-unital star homomorphisms and unital C⋆-algebras with unital star homomorphisms. This sends `φ : A →⋆ₙₐ[R] B` to a map `Unitization R A →⋆ₐ[R] Unitization R B` given by the formula `(r, a) ↦ (r, φ a)` (or perhaps more precisely, `algebraMap R _ r + ↑a ↦ algebraMap R _ r + ↑(φ a)`). -/ @[simps!] def starMap (φ : A →⋆ₙₐ[R] B) : Unitization R A →⋆ₐ[R] Unitization R B := Unitization.starLift <| (Unitization.inrNonUnitalStarAlgHom R B).comp φ @[simp high] lemma starMap_inr (φ : A →⋆ₙₐ[R] B) (a : A) : starMap φ (inr a) = inr (φ a) := by simp @[simp high] lemma starMap_inl (φ : A →⋆ₙₐ[R] B) (r : R) : starMap φ (inl r) = algebraMap R (Unitization R B) r := by simp /-- If `φ : A →⋆ₙₐ[R] B` is injective, the lift `starMap φ : Unitization R A →⋆ₐ[R] Unitization R B` is also injective. -/ lemma starMap_injective {φ : A →⋆ₙₐ[R] B} (hφ : Function.Injective φ) : Function.Injective (starMap φ) := by intro x y h ext · simpa using congr(fst $(h)) · exact hφ <| by simpa [algebraMap_eq_inl] using congr(snd $(h)) /-- If `φ : A →⋆ₙₐ[R] B` is surjective, the lift `starMap φ : Unitization R A →⋆ₐ[R] Unitization R B` is also surjective. -/ lemma starMap_surjective {φ : A →⋆ₙₐ[R] B} (hφ : Function.Surjective φ) : Function.Surjective (starMap φ) := by intro x induction x using Unitization.ind with | inl_add_inr r b => obtain ⟨a, rfl⟩ := hφ b exact ⟨(r, a), by rfl⟩ /-- `starMap` is functorial: `starMap (ψ.comp φ) = (starMap ψ).comp (starMap φ)`. -/ lemma starMap_comp {φ : A →⋆ₙₐ[R] B} {ψ : B →⋆ₙₐ[R] C} : starMap (ψ.comp φ) = (starMap ψ).comp (starMap φ) := by ext; all_goals simp /-- `starMap` is functorial: `starMap (NonUnitalStarAlgHom.id R B) = StarAlgHom.id R (Unitization R B)`. -/ @[simp] lemma starMap_id : starMap (NonUnitalStarAlgHom.id R B) = StarAlgHom.id R (Unitization R B) := by ext; all_goals simp end StarMap section StarNormal variable {R A : Type*} [Semiring R] variable [StarAddMonoid R] [Star A] {a : A} @[simp] lemma isSelfAdjoint_inr : IsSelfAdjoint (a : Unitization R A) ↔ IsSelfAdjoint a := by simp only [isSelfAdjoint_iff, ← inr_star, inr_injective.eq_iff] alias ⟨_root_.IsSelfAdjoint.of_inr, _⟩ := isSelfAdjoint_inr variable (R) in lemma _root_.IsSelfAdjoint.inr (ha : IsSelfAdjoint a) : IsSelfAdjoint (a : Unitization R A) := isSelfAdjoint_inr.mpr ha variable [AddCommMonoid A] [Mul A] [SMulWithZero R A] @[simp] lemma isStarNormal_inr : IsStarNormal (a : Unitization R A) ↔ IsStarNormal a := by simp only [isStarNormal_iff, commute_iff_eq, ← inr_star, ← inr_mul, inr_injective.eq_iff] alias ⟨_root_.IsStarNormal.of_inr, _⟩ := isStarNormal_inr variable (R a) in instance instIsStarNormal (a : A) [IsStarNormal a] : IsStarNormal (a : Unitization R A) := isStarNormal_inr.mpr ‹_› end StarNormal @[simp] lemma isIdempotentElem_inr_iff (R : Type*) {A : Type*} [MulZeroClass R] [AddZeroClass A] [Mul A] [SMulWithZero R A] {a : A} : IsIdempotentElem (a : Unitization R A) ↔ IsIdempotentElem a := by simp only [IsIdempotentElem, ← inr_mul, inr_injective.eq_iff] alias ⟨_, IsIdempotentElem.inr⟩ := isIdempotentElem_inr_iff end Unitization
.lake/packages/mathlib/Mathlib/Algebra/Algebra/StrictPositivity.lean
import Mathlib.Algebra.Algebra.Spectrum.Quasispectrum import Mathlib.Algebra.Order.Star.Basic import Mathlib.Algebra.Order.Module.Defs import Mathlib.Tactic.ContinuousFunctionalCalculus /-! # Strictly positive elements of an algebra This file introduces strictly positive elements of an algebra (also known as positive definite elements). This is mostly used for C⋆-algebras, but the basic definition makes sense in a more general context. ## Implementation notes Note that, while the current definition is adequate in the unital case, it will eventually be replaced by a definition that makes sense in the non-unital case (an element is strictly positive if the hereditary C⋆-subalgebra generated by that element is the whole algebra). Thus, it is best to avoid unfolding the definition and only use the API provided. ## TODO + Generalize the definition to non-unital algebras. -/ /-- An element of an ordered algebra is *strictly positive* if it is nonnegative and invertible. NOTE: This definition will be generalized to the non-unital case in the future; do not unfold the definition and use the API provided instead to avoid breakage when the refactor happens. -/ def IsStrictlyPositive {A : Type*} [LE A] [Monoid A] [Zero A] (a : A) : Prop := 0 ≤ a ∧ IsUnit a variable {A : Type*} namespace IsStrictlyPositive section basic @[grind =] lemma iff_of_unital [LE A] [Monoid A] [Zero A] {a : A} : IsStrictlyPositive a ↔ 0 ≤ a ∧ IsUnit a := Iff.rfl @[aesop 20% apply (rule_sets := [CStarAlgebra])] protected lemma nonneg [LE A] [Monoid A] [Zero A] {a : A} (ha : IsStrictlyPositive a) : 0 ≤ a := ha.1 @[aesop 20% apply (rule_sets := [CStarAlgebra])] protected lemma isUnit [LE A] [Monoid A] [Zero A] {a : A} (ha : IsStrictlyPositive a) : IsUnit a := ha.2 lemma _root_.IsUnit.isStrictlyPositive [LE A] [Monoid A] [Zero A] {a : A} (ha : IsUnit a) (ha₀ : 0 ≤ a) : IsStrictlyPositive a := iff_of_unital.mpr ⟨ha₀, ha⟩ @[grind →] lemma isSelfAdjoint [Semiring A] [PartialOrder A] [StarRing A] [StarOrderedRing A] {a : A} (ha : IsStrictlyPositive a) : IsSelfAdjoint a := ha.nonneg.isSelfAdjoint @[simp, grind .] lemma _root_.isStrictlyPositive_one [LE A] [Monoid A] [Zero A] [ZeroLEOneClass A] : IsStrictlyPositive (1 : A) := iff_of_unital.mpr ⟨zero_le_one, isUnit_one⟩ end basic section StarOrderedRing variable [Semiring A] [StarRing A] [PartialOrder A] [StarOrderedRing A] lemma _root_.IsUnit.isStrictlyPositive_star_right_conjugate_iff {u a : A} (hu : IsUnit u) : IsStrictlyPositive (u * a * star u) ↔ IsStrictlyPositive a := by simp_rw [IsStrictlyPositive.iff_of_unital, hu.star_right_conjugate_nonneg_iff] lift u to Aˣ using hu rw [← Units.coe_star, Units.isUnit_mul_units, Units.isUnit_units_mul] lemma _root_.IsUnit.isStrictlyPositive_star_left_conjugate_iff {u a : A} (hu : IsUnit u) : IsStrictlyPositive (star u * a * u) ↔ IsStrictlyPositive a := by simpa using hu.star.isStrictlyPositive_star_right_conjugate_iff end StarOrderedRing section Algebra variable {𝕜 : Type*} [Ring A] [PartialOrder A] @[grind ←, aesop safe apply] protected lemma smul [Semifield 𝕜] [PartialOrder 𝕜] [Algebra 𝕜 A] [PosSMulMono 𝕜 A] {c : 𝕜} (hc : 0 < c) {a : A} (ha : IsStrictlyPositive a) : IsStrictlyPositive (c • a) := by have hunit : IsUnit (c • a) := isUnit_iff_exists.mpr ⟨c⁻¹ • ha.isUnit.unit⁻¹, by simp [(ne_of_lt hc).symm]⟩ exact hunit.isStrictlyPositive (smul_nonneg hc.le ha.nonneg) @[grind ←, aesop safe apply] lemma _root_.isStrictlyPositive_algebraMap [ZeroLEOneClass A] [Semifield 𝕜] [PartialOrder 𝕜] [Algebra 𝕜 A] [PosSMulMono 𝕜 A] {c : 𝕜} (hc : 0 < c) : IsStrictlyPositive (algebraMap 𝕜 A c) := by rw [Algebra.algebraMap_eq_smul_one] exact IsStrictlyPositive.smul hc isStrictlyPositive_one lemma spectrum_pos [CommSemiring 𝕜] [PartialOrder 𝕜] [Algebra 𝕜 A] [NonnegSpectrumClass 𝕜 A] {a : A} (ha : IsStrictlyPositive a) {x : 𝕜} (hx : x ∈ spectrum 𝕜 a) : 0 < x := by have h₁ : 0 ≤ x := by grind have h₂ : x ≠ 0 := by grind [= spectrum.zero_notMem_iff] exact lt_of_le_of_ne h₁ h₂.symm grind_pattern IsStrictlyPositive.spectrum_pos => x ∈ spectrum 𝕜 a, IsStrictlyPositive a end Algebra end IsStrictlyPositive
.lake/packages/mathlib/Mathlib/Algebra/Algebra/ZMod.lean
import Mathlib.Algebra.Algebra.Defs import Mathlib.Data.ZMod.Basic /-! # The `ZMod n`-algebra structure on rings whose characteristic divides `n` -/ assert_not_exists TwoSidedIdeal namespace ZMod variable (R : Type*) [Ring R] instance (p : ℕ) : Subsingleton (Algebra (ZMod p) R) := ⟨fun _ _ => Algebra.algebra_ext _ _ <| RingHom.congr_fun <| Subsingleton.elim _ _⟩ section variable {n : ℕ} (m : ℕ) [CharP R m] /-- The `ZMod n`-algebra structure on rings whose characteristic `m` divides `n`. See note [reducible non-instances]. -/ abbrev algebra' (h : m ∣ n) : Algebra (ZMod n) R where algebraMap := ZMod.castHom h R smul := fun a r => cast a * r commutes' := fun a r => show (cast a * r : R) = r * cast a by rcases ZMod.intCast_surjective a with ⟨k, rfl⟩ change ZMod.castHom h R k * r = r * ZMod.castHom h R k rw [map_intCast, Int.cast_comm] smul_def' := fun _ _ => rfl end /-- The `ZMod p`-algebra structure on a ring of characteristic `p`. This is not an instance since it creates a diamond with `Algebra.id`. See note [reducible non-instances]. -/ abbrev algebra (p : ℕ) [CharP R p] : Algebra (ZMod p) R := algebra' R p dvd_rfl end ZMod
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Hom.lean
import Mathlib.Algebra.Algebra.Basic /-! # Homomorphisms of `R`-algebras This file defines bundled homomorphisms of `R`-algebras. ## Main definitions * `AlgHom R A B`: the type of `R`-algebra morphisms from `A` to `B`. * `Algebra.ofId R A : R →ₐ[R] A`: the canonical map from `R` to `A`, as an `AlgHom`. ## Notation * `A →ₐ[R] B` : `R`-algebra homomorphism from `A` to `B`. -/ universe u v w u₁ v₁ /-- Defining the homomorphism in the category R-Alg, denoted `A →ₐ[R] B`. -/ structure AlgHom (R : Type u) (A : Type v) (B : Type w) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] extends RingHom A B where commutes' : ∀ r : R, toFun (algebraMap R A r) = algebraMap R B r /-- Reinterpret an `AlgHom` as a `RingHom` -/ add_decl_doc AlgHom.toRingHom @[inherit_doc AlgHom] infixr:25 " →ₐ " => AlgHom _ @[inherit_doc] notation:25 A " →ₐ[" R "] " B => AlgHom R A B /-- The algebra morphism underlying `algebraMap` -/ def Algebra.algHom (R A B : Type*) [CommSemiring R] [CommSemiring A] [Semiring B] [Algebra R A] [Algebra R B] [Algebra A B] [IsScalarTower R A B] : A →ₐ[R] B where toRingHom := algebraMap A B commutes' r := by simpa [Algebra.smul_def] using smul_assoc r (1 : A) (1 : B) /-- `AlgHomClass F R A B` asserts `F` is a type of bundled algebra homomorphisms from `A` to `B`. -/ class AlgHomClass (F : Type*) (R A B : outParam Type*) [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [FunLike F A B] : Prop extends RingHomClass F A B where commutes : ∀ (f : F) (r : R), f (algebraMap R A r) = algebraMap R B r -- For now, don't replace `AlgHom.commutes` and `AlgHomClass.commutes` with the more generic lemma. -- The file `Mathlib/NumberTheory/NumberField/CanonicalEmbedding/FundamentalCone.lean` slows down by -- 15% if we would do so (see benchmark on PR https://github.com/leanprover-community/mathlib4/pull/18040). -- attribute [simp] AlgHomClass.commutes namespace AlgHomClass variable {R A B F : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [FunLike F A B] -- see Note [lower instance priority] instance (priority := 100) linearMapClass [AlgHomClass F R A B] : LinearMapClass F R A B := { ‹AlgHomClass F R A B› with map_smulₛₗ := fun f r x => by simp only [Algebra.smul_def, map_mul, commutes, RingHom.id_apply] } /-- Turn an element of a type `F` satisfying `AlgHomClass F α β` into an actual `AlgHom`. This is declared as the default coercion from `F` to `α →+* β`. -/ @[coe] def toAlgHom {F : Type*} [FunLike F A B] [AlgHomClass F R A B] (f : F) : A →ₐ[R] B where __ := (f : A →+* B) toFun := f commutes' := AlgHomClass.commutes f instance coeTC {F : Type*} [FunLike F A B] [AlgHomClass F R A B] : CoeTC F (A →ₐ[R] B) := ⟨AlgHomClass.toAlgHom⟩ end AlgHomClass namespace AlgHom variable {R : Type u} {A : Type v} {B : Type w} {C : Type u₁} {D : Type v₁} section Semiring variable [CommSemiring R] [Semiring A] [Semiring B] [Semiring C] [Semiring D] variable [Algebra R A] [Algebra R B] [Algebra R C] [Algebra R D] instance funLike : FunLike (A →ₐ[R] B) A B where coe f := f.toFun coe_injective' f g h := by rcases f with ⟨⟨⟨⟨_, _⟩, _⟩, _, _⟩, _⟩ rcases g with ⟨⟨⟨⟨_, _⟩, _⟩, _, _⟩, _⟩ congr instance algHomClass : AlgHomClass (A →ₐ[R] B) R A B where map_add f := f.map_add' map_zero f := f.map_zero' map_mul f := f.map_mul' map_one f := f.map_one' commutes f := f.commutes' @[simp] lemma _root_.AlgHomClass.toLinearMap_toAlgHom {R A B F : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] [FunLike F A B] [AlgHomClass F R A B] (f : F) : (AlgHomClass.toAlgHom f : A →ₗ[R] B) = f := rfl /-- See Note [custom simps projection] -/ def Simps.apply {R : Type u} {α : Type v} {β : Type w} [CommSemiring R] [Semiring α] [Semiring β] [Algebra R α] [Algebra R β] (f : α →ₐ[R] β) : α → β := f initialize_simps_projections AlgHom (toFun → apply) @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [AlgHomClass F R A B] (f : F) : ⇑(f : A →ₐ[R] B) = f := rfl @[simp] theorem toFun_eq_coe (f : A →ₐ[R] B) : f.toFun = f := rfl /-- Turn an algebra homomorpism into the corresponding multiplicative monoid homomorphism. -/ @[coe] def toMonoidHom' (f : A →ₐ[R] B) : A →* B := (f : A →+* B) instance coeOutMonoidHom : CoeOut (A →ₐ[R] B) (A →* B) := ⟨AlgHom.toMonoidHom'⟩ /-- Turn an algebra homomorphism into the corresponding additive monoid homomorphism. -/ @[coe] def toAddMonoidHom' (f : A →ₐ[R] B) : A →+ B := (f : A →+* B) instance coeOutAddMonoidHom : CoeOut (A →ₐ[R] B) (A →+ B) := ⟨AlgHom.toAddMonoidHom'⟩ @[simp] theorem coe_mk {f : A →+* B} (h) : ((⟨f, h⟩ : A →ₐ[R] B) : A → B) = f := rfl @[norm_cast] theorem coe_mks {f : A → B} (h₁ h₂ h₃ h₄ h₅) : ⇑(⟨⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩, h₅⟩ : A →ₐ[R] B) = f := rfl @[simp, norm_cast] theorem coe_ringHom_mk {f : A →+* B} (h) : ((⟨f, h⟩ : A →ₐ[R] B) : A →+* B) = f := rfl -- make the coercion the simp-normal form @[simp] theorem toRingHom_eq_coe (f : A →ₐ[R] B) : f.toRingHom = f := rfl @[simp, norm_cast] theorem coe_toRingHom (f : A →ₐ[R] B) : ⇑(f : A →+* B) = f := rfl @[simp, norm_cast] theorem coe_toMonoidHom (f : A →ₐ[R] B) : ⇑(f : A →* B) = f := rfl @[simp, norm_cast] theorem coe_toAddMonoidHom (f : A →ₐ[R] B) : ⇑(f : A →+ B) = f := rfl @[simp] theorem toRingHom_toMonoidHom (f : A →ₐ[R] B) : ((f : A →+* B) : A →* B) = f := rfl @[simp] theorem toRingHom_toAddMonoidHom (f : A →ₐ[R] B) : ((f : A →+* B) : A →+ B) = f := rfl variable (φ : A →ₐ[R] B) theorem coe_fn_injective : @Function.Injective (A →ₐ[R] B) (A → B) (↑) := DFunLike.coe_injective theorem coe_fn_inj {φ₁ φ₂ : A →ₐ[R] B} : (φ₁ : A → B) = φ₂ ↔ φ₁ = φ₂ := DFunLike.coe_fn_eq theorem coe_ringHom_injective : Function.Injective ((↑) : (A →ₐ[R] B) → A →+* B) := fun φ₁ φ₂ H => coe_fn_injective <| show ((φ₁ : A →+* B) : A → B) = ((φ₂ : A →+* B) : A → B) from congr_arg _ H theorem coe_monoidHom_injective : Function.Injective ((↑) : (A →ₐ[R] B) → A →* B) := RingHom.coe_monoidHom_injective.comp coe_ringHom_injective theorem coe_addMonoidHom_injective : Function.Injective ((↑) : (A →ₐ[R] B) → A →+ B) := RingHom.coe_addMonoidHom_injective.comp coe_ringHom_injective protected theorem congr_fun {φ₁ φ₂ : A →ₐ[R] B} (H : φ₁ = φ₂) (x : A) : φ₁ x = φ₂ x := DFunLike.congr_fun H x protected theorem congr_arg (φ : A →ₐ[R] B) {x y : A} (h : x = y) : φ x = φ y := DFunLike.congr_arg φ h @[ext] theorem ext {φ₁ φ₂ : A →ₐ[R] B} (H : ∀ x, φ₁ x = φ₂ x) : φ₁ = φ₂ := DFunLike.ext _ _ H @[simp] theorem mk_coe {f : A →ₐ[R] B} (h₁ h₂ h₃ h₄ h₅) : (⟨⟨⟨⟨f, h₁⟩, h₂⟩, h₃, h₄⟩, h₅⟩ : A →ₐ[R] B) = f := rfl @[simp] lemma addHomMk_coe (f : A →ₐ[R] B) : AddHom.mk f (map_add f) = f := rfl @[simp] theorem commutes (r : R) : φ (algebraMap R A r) = algebraMap R B r := φ.commutes' r theorem comp_algebraMap : (φ : A →+* B).comp (algebraMap R A) = algebraMap R B := RingHom.ext <| φ.commutes /-- If a `RingHom` is `R`-linear, then it is an `AlgHom`. -/ def mk' (f : A →+* B) (h : ∀ (c : R) (x), f (c • x) = c • f x) : A →ₐ[R] B := { f with toFun := f commutes' := fun c => by simp only [Algebra.algebraMap_eq_smul_one, h, f.map_one] } @[simp] theorem coe_mk' (f : A →+* B) (h : ∀ (c : R) (x), f (c • x) = c • f x) : ⇑(mk' f h) = f := rfl section variable (R A) /-- Identity map as an `AlgHom`. -/ protected def id : A →ₐ[R] A := { RingHom.id A with commutes' := fun _ => rfl } @[simp, norm_cast] theorem coe_id : ⇑(AlgHom.id R A) = id := rfl @[simp] theorem id_toRingHom : (AlgHom.id R A : A →+* A) = RingHom.id _ := rfl end theorem id_apply (p : A) : AlgHom.id R A p = p := rfl /-- If `φ₁` and `φ₂` are `R`-algebra homomorphisms with the domain of `φ₁` equal to the codomain of `φ₂`, then `φ₁.comp φ₂` is the algebra homomorphism `x ↦ φ₁ (φ₂ x)`. -/ def comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : A →ₐ[R] C := { φ₁.toRingHom.comp ↑φ₂ with commutes' := fun r : R => by rw [← φ₁.commutes, ← φ₂.commutes]; rfl } @[simp] theorem coe_comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : ⇑(φ₁.comp φ₂) = φ₁ ∘ φ₂ := rfl theorem comp_apply (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) (p : A) : φ₁.comp φ₂ p = φ₁ (φ₂ p) := rfl theorem comp_toRingHom (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : (φ₁.comp φ₂ : A →+* C) = (φ₁ : B →+* C).comp ↑φ₂ := rfl @[simp] theorem comp_id : φ.comp (AlgHom.id R A) = φ := rfl @[simp] theorem id_comp : (AlgHom.id R B).comp φ = φ := rfl theorem comp_assoc (φ₁ : C →ₐ[R] D) (φ₂ : B →ₐ[R] C) (φ₃ : A →ₐ[R] B) : (φ₁.comp φ₂).comp φ₃ = φ₁.comp (φ₂.comp φ₃) := rfl /-- R-Alg ⥤ R-Mod -/ def toLinearMap : A →ₗ[R] B where toFun := φ map_add' := map_add _ map_smul' := map_smul _ @[simp] theorem toLinearMap_apply (p : A) : φ.toLinearMap p = φ p := rfl @[simp] lemma coe_toLinearMap : ⇑φ.toLinearMap = φ := rfl theorem toLinearMap_injective : Function.Injective (toLinearMap : _ → A →ₗ[R] B) := fun _φ₁ _φ₂ h => ext <| LinearMap.congr_fun h @[simp] theorem comp_toLinearMap (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).toLinearMap = g.toLinearMap.comp f.toLinearMap := rfl @[simp] theorem toLinearMap_id : toLinearMap (AlgHom.id R A) = LinearMap.id := rfl @[simp] lemma linearMapMk_toAddHom (f : A →ₐ[R] B) : LinearMap.mk f (map_smul f) = f.toLinearMap := rfl /-- Promote a `LinearMap` to an `AlgHom` by supplying proofs about the behavior on `1` and `*`. -/ @[simps] def ofLinearMap (f : A →ₗ[R] B) (map_one : f 1 = 1) (map_mul : ∀ x y, f (x * y) = f x * f y) : A →ₐ[R] B := { f.toAddMonoidHom with toFun := f map_one' := map_one map_mul' := map_mul commutes' c := by simp only [Algebra.algebraMap_eq_smul_one, f.map_smul, map_one] } @[simp] theorem ofLinearMap_toLinearMap (map_one) (map_mul) : ofLinearMap φ.toLinearMap map_one map_mul = φ := rfl @[simp] theorem toLinearMap_ofLinearMap (f : A →ₗ[R] B) (map_one) (map_mul) : toLinearMap (ofLinearMap f map_one map_mul) = f := rfl @[simp] theorem ofLinearMap_id (map_one) (map_mul) : ofLinearMap LinearMap.id map_one map_mul = AlgHom.id R A := rfl theorem map_smul_of_tower {R'} [SMul R' A] [SMul R' B] [LinearMap.CompatibleSMul A B R' R] (r : R') (x : A) : φ (r • x) = r • φ x := φ.toLinearMap.map_smul_of_tower r x @[simps -isSimp toSemigroup_toMul_mul toOne_one] instance End : Monoid (A →ₐ[R] A) where mul := comp mul_assoc _ _ _ := rfl one := AlgHom.id R A one_mul _ := rfl mul_one _ := rfl @[simp] theorem one_apply (x : A) : (1 : A →ₐ[R] A) x = x := rfl @[simp] theorem mul_apply (φ ψ : A →ₐ[R] A) (x : A) : (φ * ψ) x = φ (ψ x) := rfl @[simp] theorem coe_pow (φ : A →ₐ[R] A) (n : ℕ) : ⇑(φ ^ n) = φ^[n] := n.rec (by ext; simp) fun _ ih ↦ by ext; simp [pow_succ, ih] theorem algebraMap_eq_apply (f : A →ₐ[R] B) {y : R} {x : A} (h : algebraMap R A y = x) : algebraMap R B y = f x := h ▸ (f.commutes _).symm lemma cancel_right {g₁ g₂ : B →ₐ[R] C} {f : A →ₐ[R] B} (hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => AlgHom.ext <| hf.forall.2 (AlgHom.ext_iff.1 h), fun h => h ▸ rfl⟩ lemma cancel_left {g₁ g₂ : A →ₐ[R] B} {f : B →ₐ[R] C} (hf : Function.Injective f) : f.comp g₁ = f.comp g₂ ↔ g₁ = g₂ := ⟨fun h => AlgHom.ext <| fun _ ↦ hf.eq_iff.mp <| AlgHom.ext_iff.mp h _, fun h => h ▸ rfl⟩ /-- `AlgHom.toLinearMap` as a `MonoidHom`. -/ @[simps] def toEnd : (A →ₐ[R] A) →* Module.End R A where toFun := toLinearMap map_one' := rfl map_mul' _ _ := rfl end Semiring end AlgHom namespace AlgHomClass @[simp] lemma toRingHom_toAlgHom {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] {F : Type*} [FunLike F A B] [AlgHomClass F R A B] (f : F) : RingHomClass.toRingHom (AlgHomClass.toAlgHom f) = RingHomClass.toRingHom f := rfl end AlgHomClass namespace RingHom variable {R S : Type*} /-- Reinterpret a `RingHom` as an `ℕ`-algebra homomorphism. -/ def toNatAlgHom [Semiring R] [Semiring S] (f : R →+* S) : R →ₐ[ℕ] S := { f with toFun := f commutes' := fun n => by simp } @[simp] lemma toNatAlgHom_coe [Semiring R] [Semiring S] (f : R →+* S) : ⇑f.toNatAlgHom = ⇑f := rfl lemma toNatAlgHom_apply [Semiring R] [Semiring S] (f : R →+* S) (x : R) : f.toNatAlgHom x = f x := rfl /-- Reinterpret a `RingHom` as a `ℤ`-algebra homomorphism. -/ def toIntAlgHom [Ring R] [Ring S] (f : R →+* S) : R →ₐ[ℤ] S := { f with commutes' := fun n => by simp } @[simp] lemma toIntAlgHom_coe [Ring R] [Ring S] (f : R →+* S) : ⇑f.toIntAlgHom = ⇑f := rfl lemma toIntAlgHom_apply [Ring R] [Ring S] (f : R →+* S) (x : R) : f.toIntAlgHom x = f x := rfl lemma toIntAlgHom_injective [Ring R] [Ring S] : Function.Injective (RingHom.toIntAlgHom : (R →+* S) → _) := fun _ _ e ↦ DFunLike.ext _ _ (fun x ↦ DFunLike.congr_fun e x) end RingHom namespace Algebra variable (R : Type u) (A : Type v) (B : Type w) variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] /-- `AlgebraMap` as an `AlgHom`. -/ def ofId : R →ₐ[R] A := { algebraMap R A with commutes' := fun _ => rfl } variable {R} @[simp] lemma ofId_self : ofId R R = .id R R := rfl @[simp] lemma toRingHom_ofId : ofId R A = algebraMap R A := rfl @[simp] theorem ofId_apply (r) : ofId R A r = algebraMap R A r := rfl /-- This is a special case of a more general instance that we define in a later file. -/ instance subsingleton_id : Subsingleton (R →ₐ[R] A) := ⟨fun f g => AlgHom.ext fun _ => (f.commutes _).trans (g.commutes _).symm⟩ /-- This ext lemma closes trivial subgoals created when chaining heterobasic ext lemmas. -/ @[ext high] theorem ext_id (f g : R →ₐ[R] A) : f = g := Subsingleton.elim _ _ @[simp] theorem comp_ofId (φ : A →ₐ[R] B) : φ.comp (Algebra.ofId R A) = Algebra.ofId R B := by ext section MulDistribMulAction instance : MulDistribMulAction (A →ₐ[R] A) Aˣ where smul f := Units.map f one_smul _ := by ext; rfl mul_smul _ _ _ := by ext; rfl smul_mul _ _ _ := by ext; exact map_mul _ _ _ smul_one _ := by ext; exact map_one _ @[simp] theorem smul_units_def (f : A →ₐ[R] A) (x : Aˣ) : f • x = Units.map (f : A →* A) x := rfl end MulDistribMulAction variable (M : Submonoid R) {B : Type w} [Semiring B] [Algebra R B] {A} lemma algebraMapSubmonoid_map_eq (f : A →ₐ[R] B) : (algebraMapSubmonoid A M).map f = algebraMapSubmonoid B M := by ext x constructor · rintro ⟨a, ⟨r, hr, rfl⟩, rfl⟩ simp only [AlgHom.commutes] use r · rintro ⟨r, hr, rfl⟩ simp only [Submonoid.mem_map] use (algebraMap R A r) simp only [AlgHom.commutes, and_true] use r lemma algebraMapSubmonoid_le_comap (f : A →ₐ[R] B) : algebraMapSubmonoid A M ≤ (algebraMapSubmonoid B M).comap f.toRingHom := by rw [← algebraMapSubmonoid_map_eq M f] exact Submonoid.le_comap_map (Algebra.algebraMapSubmonoid A M) end Algebra namespace MulSemiringAction variable {M G : Type*} (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] variable [Monoid M] [MulSemiringAction M A] [SMulCommClass M R A] /-- Each element of the monoid defines an algebra homomorphism. This is a stronger version of `MulSemiringAction.toRingHom` and `DistribMulAction.toLinearMap`. -/ @[simps] def toAlgHom (m : M) : A →ₐ[R] A := { MulSemiringAction.toRingHom _ _ m with toFun := fun a => m • a commutes' := smul_algebraMap _ } theorem toAlgHom_injective [FaithfulSMul M A] : Function.Injective (MulSemiringAction.toAlgHom R A : M → A →ₐ[R] A) := fun _m₁ _m₂ h => eq_of_smul_eq_smul fun r => AlgHom.ext_iff.1 h r end MulSemiringAction section variable {R S T : Type*} [CommSemiring R] [Semiring S] [Semiring T] [Algebra R S] [Algebra R T] [Subsingleton T] instance uniqueOfRight : Unique (S →ₐ[R] T) where default := AlgHom.ofLinearMap default (Subsingleton.elim _ _) (fun _ _ ↦ (Subsingleton.elim _ _)) uniq _ := AlgHom.ext fun _ ↦ Subsingleton.elim _ _ @[simp] lemma AlgHom.default_apply (x : S) : (default : S →ₐ[R] T) x = 0 := rfl end
.lake/packages/mathlib/Mathlib/Algebra/Algebra/NonUnitalHom.lean
import Mathlib.Algebra.Algebra.Hom import Mathlib.Algebra.GroupWithZero.Action.Prod /-! # Morphisms of non-unital algebras This file defines morphisms between two types, each of which carries: * an addition, * an additive zero, * a multiplication, * a scalar action. The multiplications are not assumed to be associative or unital, or even to be compatible with the scalar actions. In a typical application, the operations will satisfy compatibility conditions making them into algebras (albeit possibly non-associative and/or non-unital) but such conditions are not required to make this definition. This notion of morphism should be useful for any category of non-unital algebras. The motivating application at the time it was introduced was to be able to state the adjunction property for magma algebras. These are non-unital, non-associative algebras obtained by applying the group-algebra construction except where we take a type carrying just `Mul` instead of `Group`. For a plausible future application, one could take the non-unital algebra of compactly-supported functions on a non-compact topological space. A proper map between a pair of such spaces (contravariantly) induces a morphism between their algebras of compactly-supported functions which will be a `NonUnitalAlgHom`. TODO: add `NonUnitalAlgEquiv` when needed. ## Main definitions * `NonUnitalAlgHom` * `AlgHom.toNonUnitalAlgHom` ## Tags non-unital, algebra, morphism -/ universe u u₁ v w w₁ w₂ w₃ variable {R : Type u} {S : Type u₁} /-- A morphism respecting addition, multiplication, and scalar multiplication (denoted as `A →ₛₙₐ[φ] B`, or `A →ₙₐ[R] B` when `φ` is the identity on `R`). When these arise from algebra structures, this is the same as a not-necessarily-unital morphism of algebras. -/ structure NonUnitalAlgHom [Monoid R] [Monoid S] (φ : R →* S) (A : Type v) (B : Type w) [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction S B] extends A →ₑ+[φ] B, A →ₙ* B @[inherit_doc NonUnitalAlgHom] infixr:25 " →ₙₐ " => NonUnitalAlgHom _ @[inherit_doc] notation:25 A " →ₛₙₐ[" φ "] " B => NonUnitalAlgHom φ A B @[inherit_doc] notation:25 A " →ₙₐ[" R "] " B => NonUnitalAlgHom (MonoidHom.id R) A B attribute [nolint docBlame] NonUnitalAlgHom.toMulHom /-- `NonUnitalAlgSemiHomClass F φ A B` asserts `F` is a type of bundled algebra homomorphisms from `A` to `B` which are equivariant with respect to `φ`. -/ class NonUnitalAlgSemiHomClass (F : Type*) {R S : outParam Type*} [Monoid R] [Monoid S] (φ : outParam (R →* S)) (A B : outParam Type*) [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [DistribMulAction R A] [DistribMulAction S B] [FunLike F A B] : Prop extends DistribMulActionSemiHomClass F φ A B, MulHomClass F A B /-- `NonUnitalAlgHomClass F R A B` asserts `F` is a type of bundled algebra homomorphisms from `A` to `B` which are `R`-linear. This is an abbreviation to `NonUnitalAlgSemiHomClass F (MonoidHom.id R) A B` -/ abbrev NonUnitalAlgHomClass (F : Type*) (R A B : outParam Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [DistribMulAction R A] [DistribMulAction R B] [FunLike F A B] := NonUnitalAlgSemiHomClass F (MonoidHom.id R) A B namespace NonUnitalAlgHomClass -- See note [lower instance priority] instance (priority := 100) toNonUnitalRingHomClass {F R S A B : Type*} {_ : Monoid R} {_ : Monoid S} {φ : outParam (R →* S)} {_ : NonUnitalNonAssocSemiring A} [DistribMulAction R A] {_ : NonUnitalNonAssocSemiring B} [DistribMulAction S B] [FunLike F A B] [NonUnitalAlgSemiHomClass F φ A B] : NonUnitalRingHomClass F A B := { ‹NonUnitalAlgSemiHomClass F φ A B› with } variable [Semiring R] [Semiring S] {φ : R →+* S} {A B : Type*} [NonUnitalNonAssocSemiring A] [Module R A] [NonUnitalNonAssocSemiring B] [Module S B] -- see Note [lower instance priority] instance (priority := 100) {F R S A B : Type*} {_ : Semiring R} {_ : Semiring S} {φ : R →+* S} {_ : NonUnitalSemiring A} {_ : NonUnitalSemiring B} [Module R A] [Module S B] [FunLike F A B] [NonUnitalAlgSemiHomClass (R := R) (S := S) F φ A B] : SemilinearMapClass F φ A B := { ‹NonUnitalAlgSemiHomClass F φ A B› with map_smulₛₗ := map_smulₛₗ } instance (priority := 100) {F : Type*} [FunLike F A B] [Module R B] [NonUnitalAlgHomClass F R A B] : LinearMapClass F R A B := { ‹NonUnitalAlgHomClass F R A B› with map_smulₛₗ := map_smulₛₗ } /-- Turn an element of a type `F` satisfying `NonUnitalAlgSemiHomClass F φ A B` into an actual `NonUnitalAlgHom`. This is declared as the default coercion from `F` to `A →ₛₙₐ[φ] B`. -/ @[coe] def toNonUnitalAlgSemiHom {F R S : Type*} [Monoid R] [Monoid S] {φ : R →* S} {A B : Type*} [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction S B] [FunLike F A B] [NonUnitalAlgSemiHomClass F φ A B] (f : F) : A →ₛₙₐ[φ] B := { (f : A →ₙ+* B) with toFun := f map_smul' := map_smulₛₗ f } instance {F R S A B : Type*} [Monoid R] [Monoid S] {φ : R →* S} [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction S B] [FunLike F A B] [NonUnitalAlgSemiHomClass F φ A B] : CoeTC F (A →ₛₙₐ[φ] B) := ⟨toNonUnitalAlgSemiHom⟩ /-- Turn an element of a type `F` satisfying `NonUnitalAlgHomClass F R A B` into an actual @[coe] `NonUnitalAlgHom`. This is declared as the default coercion from `F` to `A →ₛₙₐ[R] B`. -/ def toNonUnitalAlgHom {F R : Type*} [Monoid R] {A B : Type*} [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [FunLike F A B] [NonUnitalAlgHomClass F R A B] (f : F) : A →ₙₐ[R] B := { (f : A →ₙ+* B) with toFun := f map_smul' := map_smulₛₗ f } instance {F R : Type*} [Monoid R] {A B : Type*} [NonUnitalNonAssocSemiring A] [DistribMulAction R A] [NonUnitalNonAssocSemiring B] [DistribMulAction R B] [FunLike F A B] [NonUnitalAlgHomClass F R A B] : CoeTC F (A →ₙₐ[R] B) := ⟨toNonUnitalAlgHom⟩ end NonUnitalAlgHomClass namespace NonUnitalAlgHom variable {T : Type*} [Monoid R] [Monoid S] [Monoid T] (φ : R →* S) variable (A : Type v) (B : Type w) (C : Type w₁) variable [NonUnitalNonAssocSemiring A] [DistribMulAction R A] variable [NonUnitalNonAssocSemiring B] [DistribMulAction S B] variable [NonUnitalNonAssocSemiring C] [DistribMulAction T C] instance : FunLike (A →ₛₙₐ[φ] B) A B where coe f := f.toFun coe_injective' := by rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h; congr @[simp] theorem toFun_eq_coe (f : A →ₛₙₐ[φ] B) : f.toFun = ⇑f := rfl /-- See Note [custom simps projection] -/ def Simps.apply (f : A →ₛₙₐ[φ] B) : A → B := f initialize_simps_projections NonUnitalAlgHom (toDistribMulActionHom_toMulActionHom_toFun → apply, -toDistribMulActionHom) variable {φ A B C} @[simp] protected theorem coe_coe {F : Type*} [FunLike F A B] [NonUnitalAlgSemiHomClass F φ A B] (f : F) : ⇑(f : A →ₛₙₐ[φ] B) = f := rfl theorem coe_injective : @Function.Injective (A →ₛₙₐ[φ] B) (A → B) (↑) := by rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h; congr instance : FunLike (A →ₛₙₐ[φ] B) A B where coe f := f.toFun coe_injective' := coe_injective instance : NonUnitalAlgSemiHomClass (A →ₛₙₐ[φ] B) φ A B where map_add f := f.map_add' map_zero f := f.map_zero' map_mul f := f.map_mul' map_smulₛₗ f := f.map_smul' @[ext] theorem ext {f g : A →ₛₙₐ[φ] B} (h : ∀ x, f x = g x) : f = g := coe_injective <| funext h theorem congr_fun {f g : A →ₛₙₐ[φ] B} (h : f = g) (x : A) : f x = g x := h ▸ rfl @[simp] theorem coe_mk (f : A → B) (h₁ h₂ h₃ h₄) : ⇑(⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩ : A →ₛₙₐ[φ] B) = f := rfl @[simp] theorem mk_coe (f : A →ₛₙₐ[φ] B) (h₁ h₂ h₃ h₄) : (⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩ : A →ₛₙₐ[φ] B) = f := by rfl @[simp] lemma addHomMk_coe (f : A →ₛₙₐ[φ] B) : AddHom.mk f (map_add f) = f := rfl @[simp] theorem toDistribMulActionHom_eq_coe (f : A →ₛₙₐ[φ] B) : f.toDistribMulActionHom = ↑f := rfl @[simp] theorem toMulHom_eq_coe (f : A →ₛₙₐ[φ] B) : f.toMulHom = ↑f := rfl @[simp, norm_cast] theorem coe_to_distribMulActionHom (f : A →ₛₙₐ[φ] B) : ⇑(f : A →ₑ+[φ] B) = f := rfl @[simp, norm_cast] theorem coe_to_mulHom (f : A →ₛₙₐ[φ] B) : ⇑(f : A →ₙ* B) = f := rfl theorem to_distribMulActionHom_injective {f g : A →ₛₙₐ[φ] B} (h : (f : A →ₑ+[φ] B) = (g : A →ₑ+[φ] B)) : f = g := by ext a exact DistribMulActionHom.congr_fun h a theorem to_mulHom_injective {f g : A →ₛₙₐ[φ] B} (h : (f : A →ₙ* B) = (g : A →ₙ* B)) : f = g := by ext a exact DFunLike.congr_fun h a @[norm_cast] theorem coe_distribMulActionHom_mk (f : A →ₛₙₐ[φ] B) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩ : A →ₛₙₐ[φ] B) : A →ₑ+[φ] B) = ⟨⟨f, h₁⟩, h₂, h₃⟩ := by rfl @[norm_cast] theorem coe_mulHom_mk (f : A →ₛₙₐ[φ] B) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨f, h₁⟩, h₂, h₃⟩, h₄⟩ : A →ₛₙₐ[φ] B) : A →ₙ* B) = ⟨f, h₄⟩ := by rfl @[simp] -- Marked as `@[simp]` because `MulActionSemiHomClass.map_smulₛₗ` can't be. protected theorem map_smul (f : A →ₛₙₐ[φ] B) (c : R) (x : A) : f (c • x) = (φ c) • f x := map_smulₛₗ _ _ _ protected theorem map_add (f : A →ₛₙₐ[φ] B) (x y : A) : f (x + y) = f x + f y := map_add _ _ _ protected theorem map_mul (f : A →ₛₙₐ[φ] B) (x y : A) : f (x * y) = f x * f y := map_mul _ _ _ protected theorem map_zero (f : A →ₛₙₐ[φ] B) : f 0 = 0 := map_zero _ /-- The identity map as a `NonUnitalAlgHom`. -/ protected def id (R A : Type*) [Monoid R] [NonUnitalNonAssocSemiring A] [DistribMulAction R A] : A →ₙₐ[R] A := { NonUnitalRingHom.id A with toFun := id map_smul' := fun _ _ => rfl } @[simp, norm_cast] theorem coe_id : ⇑(NonUnitalAlgHom.id R A) = id := rfl instance : Zero (A →ₛₙₐ[φ] B) := ⟨{ (0 : A →ₑ+[φ] B) with map_mul' := by simp }⟩ instance : One (A →ₙₐ[R] A) := ⟨NonUnitalAlgHom.id R A⟩ @[simp] theorem coe_zero : ⇑(0 : A →ₛₙₐ[φ] B) = 0 := rfl @[simp] theorem coe_one : ((1 : A →ₙₐ[R] A) : A → A) = id := rfl theorem zero_apply (a : A) : (0 : A →ₛₙₐ[φ] B) a = 0 := rfl theorem one_apply (a : A) : (1 : A →ₙₐ[R] A) a = a := rfl instance : Inhabited (A →ₛₙₐ[φ] B) := ⟨0⟩ variable {φ' : S →* R} {ψ : S →* T} {χ : R →* T} /-- The composition of morphisms is a morphism. -/ def comp (f : B →ₛₙₐ[ψ] C) (g : A →ₛₙₐ[φ] B) [κ : MonoidHom.CompTriple φ ψ χ] : A →ₛₙₐ[χ] C := { (f : B →ₙ* C).comp (g : A →ₙ* B), (f : B →ₑ+[ψ] C).comp (g : A →ₑ+[φ] B) with } @[simp, norm_cast] theorem coe_comp (f : B →ₛₙₐ[ψ] C) (g : A →ₛₙₐ[φ] B) [MonoidHom.CompTriple φ ψ χ] : ⇑(f.comp g) = (⇑f) ∘ (⇑g) := rfl theorem comp_apply (f : B →ₛₙₐ[ψ] C) (g : A →ₛₙₐ[φ] B) [MonoidHom.CompTriple φ ψ χ] (x : A) : f.comp g x = f (g x) := rfl variable {B₁ : Type*} [NonUnitalNonAssocSemiring B₁] [DistribMulAction R B₁] /-- The inverse of a bijective morphism is a morphism. -/ def inverse (f : A →ₙₐ[R] B₁) (g : B₁ → A) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : B₁ →ₙₐ[R] A := { (f : A →ₙ* B₁).inverse g h₁ h₂, (f : A →+[R] B₁).inverse g h₁ h₂ with } @[simp] theorem coe_inverse (f : A →ₙₐ[R] B₁) (g : B₁ → A) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : (inverse f g h₁ h₂ : B₁ → A) = g := rfl /-- The inverse of a bijective morphism is a morphism. -/ def inverse' (f : A →ₛₙₐ[φ] B) (g : B → A) (k : Function.RightInverse φ' φ) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : B →ₛₙₐ[φ'] A := { (f : A →ₙ* B).inverse g h₁ h₂, (f : A →ₑ+[φ] B).inverse' g k h₁ h₂ with map_zero' := by simp only [MulHom.toFun_eq_coe, MulHom.inverse_apply] rw [← f.map_zero, h₁] map_add' := fun x y ↦ by simp only [MulHom.toFun_eq_coe, MulHom.inverse_apply] rw [← h₂ x, ← h₂ y, ← map_add, h₁, h₂, h₂] } @[simp] theorem coe_inverse' (f : A →ₛₙₐ[φ] B) (g : B → A) (k : Function.RightInverse φ' φ) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : (inverse' f g k h₁ h₂ : B → A) = g := rfl /-! ### Operations on the product type Note that much of this is copied from [`LinearAlgebra/Prod`](../../LinearAlgebra/Prod). -/ section Prod variable (R A B) variable [DistribMulAction R B] /-- The first projection of a product is a non-unital algebra homomorphism. -/ @[simps] def fst : A × B →ₙₐ[R] A where toFun := Prod.fst map_zero' := rfl map_add' _ _ := rfl map_smul' _ _ := rfl map_mul' _ _ := rfl /-- The second projection of a product is a non-unital algebra homomorphism. -/ @[simps] def snd : A × B →ₙₐ[R] B where toFun := Prod.snd map_zero' := rfl map_add' _ _ := rfl map_smul' _ _ := rfl map_mul' _ _ := rfl variable {R A B} variable [DistribMulAction R C] /-- The prod of two morphisms is a morphism. -/ @[simps] def prod (f : A →ₙₐ[R] B) (g : A →ₙₐ[R] C) : A →ₙₐ[R] B × C where toFun := Pi.prod f g map_zero' := by simp only [Pi.prod, Prod.mk_zero_zero, map_zero] map_add' x y := by simp only [Pi.prod, Prod.mk_add_mk, map_add] map_mul' x y := by simp only [Pi.prod, Prod.mk_mul_mk, map_mul] map_smul' c x := by simp only [Pi.prod, map_smul, MonoidHom.id_apply, Prod.smul_mk] theorem coe_prod (f : A →ₙₐ[R] B) (g : A →ₙₐ[R] C) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : A →ₙₐ[R] B) (g : A →ₙₐ[R] C) : (fst R B C).comp (prod f g) = f := by rfl @[simp] theorem snd_prod (f : A →ₙₐ[R] B) (g : A →ₙₐ[R] C) : (snd R B C).comp (prod f g) = g := by rfl @[simp] theorem prod_fst_snd : prod (fst R A B) (snd R A B) = 1 := coe_injective Pi.prod_fst_snd /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. -/ @[simps] def prodEquiv : (A →ₙₐ[R] B) × (A →ₙₐ[R] C) ≃ (A →ₙₐ[R] B × C) where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) variable (R A B) /-- The left injection into a product is a non-unital algebra homomorphism. -/ def inl : A →ₙₐ[R] A × B := prod 1 0 /-- The right injection into a product is a non-unital algebra homomorphism. -/ def inr : B →ₙₐ[R] A × B := prod 0 1 variable {R A B} @[simp] theorem coe_inl : (inl R A B : A → A × B) = fun x => (x, 0) := rfl theorem inl_apply (x : A) : inl R A B x = (x, 0) := rfl @[simp] theorem coe_inr : (inr R A B : B → A × B) = Prod.mk 0 := rfl theorem inr_apply (x : B) : inr R A B x = (0, x) := rfl end Prod end NonUnitalAlgHom /-! ### Interaction with `AlgHom` -/ namespace AlgHom variable {F R : Type*} [CommSemiring R] variable {A B : Type*} [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] -- see Note [lower instance priority] instance (priority := 100) [FunLike F A B] [AlgHomClass F R A B] : NonUnitalAlgHomClass F R A B := { ‹AlgHomClass F R A B› with map_smulₛₗ := map_smul } /-- A unital morphism of algebras is a `NonUnitalAlgHom`. -/ @[coe] def toNonUnitalAlgHom (f : A →ₐ[R] B) : A →ₙₐ[R] B := { f with map_smul' := map_smul f } instance NonUnitalAlgHom.hasCoe : CoeOut (A →ₐ[R] B) (A →ₙₐ[R] B) := ⟨toNonUnitalAlgHom⟩ @[simp] theorem toNonUnitalAlgHom_eq_coe (f : A →ₐ[R] B) : f.toNonUnitalAlgHom = f := rfl end AlgHom section RestrictScalars namespace NonUnitalAlgHom variable (R : Type*) {S A B : Type*} [Monoid R] [Monoid S] [NonUnitalNonAssocSemiring A] [NonUnitalNonAssocSemiring B] [MulAction R S] [DistribMulAction S A] [DistribMulAction S B] [DistribMulAction R A] [DistribMulAction R B] [IsScalarTower R S A] [IsScalarTower R S B] /-- If a monoid `R` acts on another monoid `S`, then a non-unital algebra homomorphism over `S` can be viewed as a non-unital algebra homomorphism over `R`. -/ def restrictScalars (f : A →ₙₐ[S] B) : A →ₙₐ[R] B := { (f : A →ₙ+* B) with map_smul' := fun r x ↦ by have := map_smul f (r • 1) x; simpa } @[simp] lemma restrictScalars_apply (f : A →ₙₐ[S] B) (x : A) : f.restrictScalars R x = f x := rfl lemma coe_restrictScalars (f : A →ₙₐ[S] B) : (f.restrictScalars R : A →ₙ+* B) = f := rfl lemma coe_restrictScalars' (f : A →ₙₐ[S] B) : (f.restrictScalars R : A → B) = f := rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : (A →ₙₐ[S] B) → A →ₙₐ[R] B) := fun _ _ h ↦ ext (congr_fun h :) end NonUnitalAlgHom end RestrictScalars
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Hom/Rat.lean
import Mathlib.Algebra.Algebra.Hom import Mathlib.Algebra.Algebra.Rat /-! # Homomorphisms of `ℚ`-algebras -/ namespace RingHom variable {R S : Type*} /-- Reinterpret a `RingHom` as a `ℚ`-algebra homomorphism. This actually yields an equivalence, see `RingHom.equivRatAlgHom`. -/ def toRatAlgHom [Ring R] [Ring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S) : R →ₐ[ℚ] S := { f with commutes' := f.map_rat_algebraMap } @[simp] theorem toRatAlgHom_toRingHom [Ring R] [Ring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S) : ↑f.toRatAlgHom = f := RingHom.ext fun _x => rfl @[simp] theorem toRatAlgHom_apply [Ring R] [Ring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →+* S) (x : R) : f.toRatAlgHom x = f x := rfl end RingHom section variable {R S : Type*} @[simp] theorem AlgHom.toRingHom_toRatAlgHom [Ring R] [Ring S] [Algebra ℚ R] [Algebra ℚ S] (f : R →ₐ[ℚ] S) : (f : R →+* S).toRatAlgHom = f := AlgHom.ext fun _x => rfl /-- The equivalence between `RingHom` and `ℚ`-algebra homomorphisms. -/ @[simps] def RingHom.equivRatAlgHom [Ring R] [Ring S] [Algebra ℚ R] [Algebra ℚ S] : (R →+* S) ≃ (R →ₐ[ℚ] S) where toFun := RingHom.toRatAlgHom invFun := AlgHom.toRingHom left_inv f := RingHom.toRatAlgHom_toRingHom f right_inv f := AlgHom.toRingHom_toRatAlgHom f end
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Matrix.lean
import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Diagonal import Mathlib.Algebra.Algebra.Subalgebra.Basic /-! # Matrix subalgebras In this file we define the subalgebra of square matrices with entries in some subalgebra. ## Main definitions * `Subalgebra.matrix`: the subalgebra of square matrices with entries in some subalgebra. -/ open Matrix open Algebra namespace Subalgebra variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable {n : Type*} [Fintype n] [DecidableEq n] /-- A version of `Set.matrix` for `Subalgebra`s. Given a `Subalgebra` `S`, `S.matrix` is the `Subalgebra` of square matrices `m` all of whose entries `m i j` belong to `S`. -/ @[simps!] def matrix (S : Subalgebra R A) : Subalgebra R (Matrix n n A) where __ := S.toSubsemiring.matrix algebraMap_mem' _ := (diagonal_mem_matrix_iff (Subalgebra.zero_mem _)).mpr (fun _ => Subalgebra.algebraMap_mem _ _) end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/MulOpposite.lean
import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Ring.Subring.MulOpposite /-! # Subalgebras of opposite rings For every ring `A` over a commutative ring `R`, we construct an equivalence between subalgebras of `A / R` and that of `Aᵐᵒᵖ / R`. -/ namespace Subalgebra section Semiring variable {ι : Sort*} {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] /-- Pull a subalgebra back to an opposite subalgebra along `MulOpposite.unop` -/ @[simps! coe toSubsemiring] protected def op (S : Subalgebra R A) : Subalgebra R Aᵐᵒᵖ where toSubsemiring := S.toSubsemiring.op algebraMap_mem' := S.algebraMap_mem attribute [norm_cast] coe_op @[simp] theorem mem_op {x : Aᵐᵒᵖ} {S : Subalgebra R A} : x ∈ S.op ↔ x.unop ∈ S := Iff.rfl /-- Pull a subalgebra back to a subalgebra along `MulOpposite.op` -/ @[simps! coe toSubsemiring] protected def unop (S : Subalgebra R Aᵐᵒᵖ) : Subalgebra R A where toSubsemiring := S.toSubsemiring.unop algebraMap_mem' := S.algebraMap_mem attribute [norm_cast] coe_unop @[simp] theorem mem_unop {x : A} {S : Subalgebra R Aᵐᵒᵖ} : x ∈ S.unop ↔ MulOpposite.op x ∈ S := Iff.rfl @[simp] theorem unop_op (S : Subalgebra R A) : S.op.unop = S := rfl @[simp] theorem op_unop (S : Subalgebra R Aᵐᵒᵖ) : S.unop.op = S := rfl /-! ### Lattice results -/ theorem op_le_iff {S₁ : Subalgebra R A} {S₂ : Subalgebra R Aᵐᵒᵖ} : S₁.op ≤ S₂ ↔ S₁ ≤ S₂.unop := MulOpposite.op_surjective.forall theorem le_op_iff {S₁ : Subalgebra R Aᵐᵒᵖ} {S₂ : Subalgebra R A} : S₁ ≤ S₂.op ↔ S₁.unop ≤ S₂ := MulOpposite.op_surjective.forall @[simp] theorem op_le_op_iff {S₁ S₂ : Subalgebra R A} : S₁.op ≤ S₂.op ↔ S₁ ≤ S₂ := MulOpposite.op_surjective.forall @[simp] theorem unop_le_unop_iff {S₁ S₂ : Subalgebra R Aᵐᵒᵖ} : S₁.unop ≤ S₂.unop ↔ S₁ ≤ S₂ := MulOpposite.unop_surjective.forall /-- A subalgebra `S` of `A / R` determines a subalgebra `S.op` of the opposite ring `Aᵐᵒᵖ / R`. -/ @[simps] def opEquiv : Subalgebra R A ≃o Subalgebra R Aᵐᵒᵖ where toFun := Subalgebra.op invFun := Subalgebra.unop left_inv := unop_op right_inv := op_unop map_rel_iff' := op_le_op_iff @[simp] theorem op_bot : (⊥ : Subalgebra R A).op = ⊥ := opEquiv.map_bot @[simp] theorem unop_bot : (⊥ : Subalgebra R Aᵐᵒᵖ).unop = ⊥ := opEquiv.symm.map_bot @[simp] theorem op_top : (⊤ : Subalgebra R A).op = ⊤ := opEquiv.map_top @[simp] theorem unop_top : (⊤ : Subalgebra R Aᵐᵒᵖ).unop = ⊤ := opEquiv.symm.map_top theorem op_sup (S₁ S₂ : Subalgebra R A) : (S₁ ⊔ S₂).op = S₁.op ⊔ S₂.op := opEquiv.map_sup _ _ theorem unop_sup (S₁ S₂ : Subalgebra R Aᵐᵒᵖ) : (S₁ ⊔ S₂).unop = S₁.unop ⊔ S₂.unop := opEquiv.symm.map_sup _ _ theorem op_inf (S₁ S₂ : Subalgebra R A) : (S₁ ⊓ S₂).op = S₁.op ⊓ S₂.op := opEquiv.map_inf _ _ theorem unop_inf (S₁ S₂ : Subalgebra R Aᵐᵒᵖ) : (S₁ ⊓ S₂).unop = S₁.unop ⊓ S₂.unop := opEquiv.symm.map_inf _ _ theorem op_sSup (S : Set (Subalgebra R A)) : (sSup S).op = sSup (.unop ⁻¹' S) := opEquiv.map_sSup_eq_sSup_symm_preimage _ theorem unop_sSup (S : Set (Subalgebra R Aᵐᵒᵖ)) : (sSup S).unop = sSup (.op ⁻¹' S) := opEquiv.symm.map_sSup_eq_sSup_symm_preimage _ theorem op_sInf (S : Set (Subalgebra R A)) : (sInf S).op = sInf (.unop ⁻¹' S) := opEquiv.map_sInf_eq_sInf_symm_preimage _ theorem unop_sInf (S : Set (Subalgebra R Aᵐᵒᵖ)) : (sInf S).unop = sInf (.op ⁻¹' S) := opEquiv.symm.map_sInf_eq_sInf_symm_preimage _ theorem op_iSup (S : ι → Subalgebra R A) : (iSup S).op = ⨆ i, (S i).op := opEquiv.map_iSup _ theorem unop_iSup (S : ι → Subalgebra R Aᵐᵒᵖ) : (iSup S).unop = ⨆ i, (S i).unop := opEquiv.symm.map_iSup _ theorem op_iInf (S : ι → Subalgebra R A) : (iInf S).op = ⨅ i, (S i).op := opEquiv.map_iInf _ theorem unop_iInf (S : ι → Subalgebra R Aᵐᵒᵖ) : (iInf S).unop = ⨅ i, (S i).unop := opEquiv.symm.map_iInf _ theorem op_adjoin (s : Set A) : (Algebra.adjoin R s).op = Algebra.adjoin R (MulOpposite.unop ⁻¹' s) := by apply toSubsemiring_injective simp_rw [Algebra.adjoin, op_toSubsemiring, Subsemiring.op_closure, Set.preimage_union] congr with x simp_rw [Set.mem_preimage, Set.mem_range, MulOpposite.algebraMap_apply] congr! rw [← MulOpposite.op_injective.eq_iff (b := x.unop), MulOpposite.op_unop] theorem unop_adjoin (s : Set Aᵐᵒᵖ) : (Algebra.adjoin R s).unop = Algebra.adjoin R (MulOpposite.op ⁻¹' s) := by apply toSubsemiring_injective simp_rw [Algebra.adjoin, unop_toSubsemiring, Subsemiring.unop_closure, Set.preimage_union] congr with x simp /-- Bijection between a subalgebra `S` and its opposite. -/ @[simps!] def linearEquivOp (S : Subalgebra R A) : S ≃ₗ[R] S.op where __ := S.toSubsemiring.addEquivOp map_smul' _ _ := rfl /-- Bijection between a subalgebra `S` and `MulOpposite` of its opposite. -/ @[simps!] def algEquivOpMop (S : Subalgebra R A) : S ≃ₐ[R] (S.op)ᵐᵒᵖ where __ := S.toSubsemiring.ringEquivOpMop commutes' _ := rfl /-- Bijection between `MulOpposite` of a subalgebra `S` and its opposite. -/ @[simps!] def mopAlgEquivOp (S : Subalgebra R A) : Sᵐᵒᵖ ≃ₐ[R] S.op where __ := S.toSubsemiring.mopRingEquivOp commutes' _ := rfl end Semiring section Ring variable {R A : Type*} [CommRing R] [Ring A] [Algebra R A] @[simp] theorem op_toSubring (S : Subalgebra R A) : S.op.toSubring = S.toSubring.op := rfl @[simp] theorem unop_toSubring (S : Subalgebra R Aᵐᵒᵖ) : S.unop.toSubring = S.toSubring.unop := rfl end Ring end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Rank.lean
import Mathlib.LinearAlgebra.Dimension.Free import Mathlib.LinearAlgebra.Dimension.Subsingleton import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition /-! # Some results on the ranks of subalgebras This file contains some results on the ranks of subalgebras, which are corollaries of `rank_mul_rank`. Since their proof essentially depends on the fact that a non-trivial commutative ring satisfies the strong rank condition, we put them into a separate file. -/ open Module namespace Subalgebra variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] (A B : Subalgebra R S) section variable [Module.Free R A] [Module.Free A (Algebra.adjoin A (B : Set S))] theorem rank_sup_eq_rank_left_mul_rank_of_free : Module.rank R ↥(A ⊔ B) = Module.rank R A * Module.rank A (Algebra.adjoin A (B : Set S)) := by rcases subsingleton_or_nontrivial R with _ | _ · haveI := Module.subsingleton R S; simp nontriviality S using rank_subsingleton' letI : Algebra A (Algebra.adjoin A (B : Set S)) := Subalgebra.algebra _ letI : SMul A (Algebra.adjoin A (B : Set S)) := Algebra.toSMul haveI : IsScalarTower R A (Algebra.adjoin A (B : Set S)) := IsScalarTower.of_algebraMap_eq (congrFun rfl) rw [rank_mul_rank R A (Algebra.adjoin A (B : Set S))] change _ = Module.rank R ((Algebra.adjoin A (B : Set S)).restrictScalars R) rw [Algebra.restrictScalars_adjoin]; rfl theorem finrank_sup_eq_finrank_left_mul_finrank_of_free : finrank R ↥(A ⊔ B) = finrank R A * finrank A (Algebra.adjoin A (B : Set S)) := by simpa only [map_mul] using congr(Cardinal.toNat $(rank_sup_eq_rank_left_mul_rank_of_free A B)) theorem finrank_left_dvd_finrank_sup_of_free : finrank R A ∣ finrank R ↥(A ⊔ B) := ⟨_, finrank_sup_eq_finrank_left_mul_finrank_of_free A B⟩ end section variable [Module.Free R B] [Module.Free B (Algebra.adjoin B (A : Set S))] theorem rank_sup_eq_rank_right_mul_rank_of_free : Module.rank R ↥(A ⊔ B) = Module.rank R B * Module.rank B (Algebra.adjoin B (A : Set S)) := by rw [sup_comm, rank_sup_eq_rank_left_mul_rank_of_free] theorem finrank_sup_eq_finrank_right_mul_finrank_of_free : finrank R ↥(A ⊔ B) = finrank R B * finrank B (Algebra.adjoin B (A : Set S)) := by rw [sup_comm, finrank_sup_eq_finrank_left_mul_finrank_of_free] theorem finrank_right_dvd_finrank_sup_of_free : finrank R B ∣ finrank R ↥(A ⊔ B) := ⟨_, finrank_sup_eq_finrank_right_mul_finrank_of_free A B⟩ end end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Prod.lean
import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Algebra.Subalgebra.Lattice /-! # Products of subalgebras In this file we define the product of two subalgebras as a subalgebra of the product algebra. ## Main definitions * `Subalgebra.prod`: the product of two subalgebras. -/ namespace Subalgebra open Algebra variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable (S : Subalgebra R A) (S₁ : Subalgebra R B) /-- The product of two subalgebras is a subalgebra. -/ def prod : Subalgebra R (A × B) := { S.toSubsemiring.prod S₁.toSubsemiring with carrier := S ×ˢ S₁ algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ } @[simp, norm_cast] theorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) := rfl open Subalgebra in theorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl @[simp] theorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} : x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod @[simp] theorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp theorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} : S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ := Set.prod_mono @[simp] theorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} : S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) := SetLike.coe_injective Set.prod_inter_prod end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Pointwise.lean
import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Ring.Subring.Pointwise /-! # Pointwise actions on subalgebras. If `R'` acts on an `R`-algebra `A` (so that `R'` and `R` actions commute) then we get an `R'` action on the collection of `R`-subalgebras. -/ namespace Subalgebra section Pointwise variable {R : Type*} {A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] theorem mul_toSubmodule_le (S T : Subalgebra R A) : (Subalgebra.toSubmodule S)* (Subalgebra.toSubmodule T) ≤ Subalgebra.toSubmodule (S ⊔ T) := by rw [Submodule.mul_le] intro y hy z hz change y * z ∈ S ⊔ T exact mul_mem (Algebra.mem_sup_left hy) (Algebra.mem_sup_right hz) /-- As submodules, subalgebras are idempotent. -/ @[simp] theorem isIdempotentElem_toSubmodule (S : Subalgebra R A) : IsIdempotentElem S.toSubmodule := by apply le_antisymm · refine (mul_toSubmodule_le _ _).trans_eq ?_ rw [sup_idem] · intro x hx1 rw [← mul_one x] exact Submodule.mul_mem_mul hx1 (show (1 : A) ∈ S from one_mem S) /-- When `A` is commutative, `Subalgebra.mul_toSubmodule_le` is strict. -/ theorem mul_toSubmodule {R : Type*} {A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (S T : Subalgebra R A) : (Subalgebra.toSubmodule S) * (Subalgebra.toSubmodule T) = Subalgebra.toSubmodule (S ⊔ T) := by refine le_antisymm (mul_toSubmodule_le _ _) ?_ rintro x (hx : x ∈ Algebra.adjoin R (S ∪ T : Set A)) refine Algebra.adjoin_induction (fun x hx => ?_) (fun r => ?_) (fun _ _ _ _ => Submodule.add_mem _) (fun x y _ _ hx hy => ?_) hx · rcases hx with hxS | hxT · rw [← mul_one x] exact Submodule.mul_mem_mul hxS (show (1 : A) ∈ T from one_mem T) · rw [← one_mul x] exact Submodule.mul_mem_mul (show (1 : A) ∈ S from one_mem S) hxT · rw [← one_mul (algebraMap _ _ _)] exact Submodule.mul_mem_mul (show (1 : A) ∈ S from one_mem S) (algebraMap_mem T _) have := Submodule.mul_mem_mul hx hy rwa [mul_assoc, mul_comm _ (Subalgebra.toSubmodule T), ← mul_assoc _ _ (Subalgebra.toSubmodule S), isIdempotentElem_toSubmodule, mul_comm T.toSubmodule, ← mul_assoc, isIdempotentElem_toSubmodule] at this variable {R' : Type*} [Semiring R'] [MulSemiringAction R' A] [SMulCommClass R' R A] /-- The action on a subalgebra corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction R' (Subalgebra R A) where smul a S := S.map (MulSemiringAction.toAlgHom _ _ a) one_smul S := (congr_arg (fun f => S.map f) (AlgHom.ext <| one_smul R')).trans S.map_id mul_smul _a₁ _a₂ S := (congr_arg (fun f => S.map f) (AlgHom.ext <| mul_smul _ _)).trans (S.map_map _ _).symm scoped[Pointwise] attribute [instance] Subalgebra.pointwiseMulAction open Pointwise @[simp, norm_cast] theorem coe_pointwise_smul (m : R') (S : Subalgebra R A) : ↑(m • S) = m • (S : Set A) := rfl @[simp] theorem pointwise_smul_toSubsemiring (m : R') (S : Subalgebra R A) : (m • S).toSubsemiring = m • S.toSubsemiring := rfl @[simp] theorem pointwise_smul_toSubmodule (m : R') (S : Subalgebra R A) : Subalgebra.toSubmodule (m • S) = m • Subalgebra.toSubmodule S := rfl @[simp] theorem pointwise_smul_toSubring {R' R A : Type*} [Semiring R'] [CommRing R] [Ring A] [MulSemiringAction R' A] [Algebra R A] [SMulCommClass R' R A] (m : R') (S : Subalgebra R A) : (m • S).toSubring = m • S.toSubring := rfl theorem smul_mem_pointwise_smul (m : R') (r : A) (S : Subalgebra R A) : r ∈ S → m • r ∈ m • S := (Set.smul_mem_smul_set : _ → _ ∈ m • (S : Set A)) instance : CovariantClass R' (Subalgebra R A) HSMul.hSMul LE.le := ⟨fun _ _ => map_mono⟩ end Pointwise end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Tower.lean
import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower /-! # Subalgebras in towers of algebras In this file we prove facts about subalgebras in towers of algebras. An algebra tower A/S/R is expressed by having instances of `Algebra A S`, `Algebra R S`, `Algebra R A` and `IsScalarTower R S A`, the latter asserting the compatibility condition `(r • s) • a = r • (s • a)`. ## Main results * `IsScalarTower.Subalgebra`: if `A/S/R` is a tower and `S₀` is a subalgebra between `S` and `R`, then `A/S/S₀` is a tower * `IsScalarTower.Subalgebra'`: if `A/S/R` is a tower and `S₀` is a subalgebra between `S` and `R`, then `A/S₀/R` is a tower * `Subalgebra.restrictScalars`: turn an `S`-subalgebra of `A` into an `R`-subalgebra of `A`, given that `A/S/R` is a tower -/ open Pointwise universe u v w u₁ v₁ variable (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) (M : Type v₁) namespace Algebra variable [CommSemiring R] [Semiring A] [Algebra R A] variable [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] variable {A} theorem lmul_algebraMap (x : R) : Algebra.lmul R A (algebraMap R A x) = Algebra.lsmul R R A x := Eq.symm <| LinearMap.ext <| smul_def x end Algebra namespace IsScalarTower section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] variable [Algebra R S] [Algebra S A] instance subalgebra (S₀ : Subalgebra R S) : IsScalarTower S₀ S A := of_algebraMap_eq fun _ ↦ rfl variable [Algebra R A] [IsScalarTower R S A] instance subalgebra' (S₀ : Subalgebra R S) : IsScalarTower R S₀ A := @IsScalarTower.of_algebraMap_eq R S₀ A _ _ _ _ _ _ fun _ ↦ (IsScalarTower.algebraMap_apply R S A _ :) end Semiring end IsScalarTower namespace Subalgebra open IsScalarTower section Semiring variable {S A B} [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra S A] [Algebra R A] [Algebra S B] [Algebra R B] variable [IsScalarTower R S A] [IsScalarTower R S B] /-- Given a tower `A / ↥U / S / R` of algebras, where `U` is an `S`-subalgebra of `A`, reinterpret `U` as an `R`-subalgebra of `A`. -/ def restrictScalars (U : Subalgebra S A) : Subalgebra R A := { U with algebraMap_mem' := fun x ↦ by rw [IsScalarTower.algebraMap_apply R S A] exact U.algebraMap_mem _ } @[simp] theorem coe_restrictScalars {U : Subalgebra S A} : (restrictScalars R U : Set A) = (U : Set A) := rfl @[simp] theorem restrictScalars_top : restrictScalars R (⊤ : Subalgebra S A) = ⊤ := -- Porting note: `by dsimp` used to be `rfl`. This appears to work but causes -- this theorem to timeout in the kernel after minutes of thinking. SetLike.coe_injective <| by dsimp @[simp] theorem restrictScalars_toSubmodule {U : Subalgebra S A} : Subalgebra.toSubmodule (U.restrictScalars R) = U.toSubmodule.restrictScalars R := SetLike.coe_injective rfl @[simp] theorem mem_restrictScalars {U : Subalgebra S A} {x : A} : x ∈ restrictScalars R U ↔ x ∈ U := Iff.rfl theorem restrictScalars_injective : Function.Injective (restrictScalars R : Subalgebra S A → Subalgebra R A) := fun U V H ↦ ext fun x ↦ by rw [← mem_restrictScalars R, H, mem_restrictScalars] /-- Produces an `R`-algebra map from `U.restrictScalars R` given an `S`-algebra map from `U`. This is a special case of `AlgHom.restrictScalars` that can be helpful in elaboration. -/ @[simp] def ofRestrictScalars (U : Subalgebra S A) (f : U →ₐ[S] B) : U.restrictScalars R →ₐ[R] B := f.restrictScalars R end Semiring section CommSemiring @[simp] lemma range_isScalarTower_toAlgHom [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) : LinearMap.range (IsScalarTower.toAlgHom R S A) = Subalgebra.toSubmodule S := by ext simp [algebraMap_eq] end CommSemiring end Subalgebra namespace IsScalarTower open Subalgebra variable [CommSemiring R] [CommSemiring S] [CommSemiring A] variable [Algebra R S] [Algebra S A] [Algebra R A] [IsScalarTower R S A] theorem adjoin_range_toAlgHom (t : Set A) : (Algebra.adjoin (toAlgHom R S A).range t).restrictScalars R = (Algebra.adjoin S t).restrictScalars R := Subalgebra.ext fun z ↦ show z ∈ Subsemiring.closure (Set.range (algebraMap (toAlgHom R S A).range A) ∪ t : Set A) ↔ z ∈ Subsemiring.closure (Set.range (algebraMap S A) ∪ t : Set A) by suffices Set.range (algebraMap (toAlgHom R S A).range A) = Set.range (algebraMap S A) by rw [this] ext z exact ⟨fun ⟨⟨_, y, h1⟩, h2⟩ ↦ ⟨y, h2 ▸ h1⟩, fun ⟨y, hy⟩ ↦ ⟨⟨z, y, hy⟩, rfl⟩⟩ end IsScalarTower
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Order.lean
import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Algebra.Module.Submodule.Order import Mathlib.Algebra.Ring.Subsemiring.Order /-! # Order instances on subalgebras -/ namespace Subalgebra variable {R A : Type*} instance toIsOrderedRing [CommSemiring R] [Semiring A] [PartialOrder A] [IsOrderedRing A] [Algebra R A] (S : Subalgebra R A) : IsOrderedRing S := S.toSubsemiring.toIsOrderedRing instance toIsStrictOrderedRing [CommSemiring R] [Semiring A] [PartialOrder A] [IsStrictOrderedRing A] [Algebra R A] (S : Subalgebra R A) : IsStrictOrderedRing S := S.toSubsemiring.toIsStrictOrderedRing end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Pi.lean
import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.LinearAlgebra.Pi /-! # Products of subalgebras In this file we define the product of subalgebras as a subalgebra of the product algebra. ## Main definitions * `Subalgebra.pi`: the product of subalgebras. -/ open Algebra namespace Subalgebra variable {ι R : Type*} {S : ι → Type*} [CommSemiring R] [∀ i, Semiring (S i)] [∀ i, Algebra R (S i)] {s : Set ι} {t t₁ t₂ : ∀ i, Subalgebra R (S i)} {x : ∀ i, S i} /-- The product of subalgebras as a subalgebra. -/ @[simps coe toSubsemiring] def pi (s : Set ι) (t : ∀ i, Subalgebra R (S i)) : Subalgebra R (Π i, S i) where __ := Submodule.pi s fun i ↦ (t i).toSubmodule mul_mem' hx hy i hi := (t i).mul_mem (hx i hi) (hy i hi) algebraMap_mem' _ i _ := (t i).algebraMap_mem _ @[simp] lemma mem_pi : x ∈ pi s t ↔ ∀ i ∈ s, x i ∈ t i := .rfl open Subalgebra in @[simp] lemma pi_toSubmodule : toSubmodule (pi s t) = .pi s fun i ↦ (t i).toSubmodule := rfl @[simp] lemma pi_top (s : Set ι) : pi s (fun i ↦ (⊤ : Subalgebra R (S i))) = ⊤ := SetLike.coe_injective <| Set.pi_univ _ @[gcongr] lemma pi_mono (h : ∀ i ∈ s, t₁ i ≤ t₂ i) : pi s t₁ ≤ pi s t₂ := Set.pi_mono h end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/IsSimpleOrder.lean
import Mathlib.LinearAlgebra.FiniteDimensional.Basic import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition /-! If `A` is a domain, and a finite-dimensional algebra over a field `F`, with prime dimension, then there are no non-trivial `F`-subalgebras. -/ open Module Submodule theorem Subalgebra.isSimpleOrder_of_finrank_prime (F A) [Field F] [Ring A] [IsDomain A] [Algebra F A] (hp : (finrank F A).Prime) : IsSimpleOrder (Subalgebra F A) := { toNontrivial := ⟨⟨⊥, ⊤, fun he => Nat.not_prime_one ((Subalgebra.bot_eq_top_iff_finrank_eq_one.1 he).subst hp)⟩⟩ eq_bot_or_eq_top := fun K => by haveI : FiniteDimensional _ _ := .of_finrank_pos hp.pos letI := divisionRingOfFiniteDimensional F K refine (hp.eq_one_or_self_of_dvd _ ⟨_, (finrank_mul_finrank F K A).symm⟩).imp ?_ fun h => ?_ · exact fun h' => Subalgebra.eq_bot_of_finrank_one h' · exact Algebra.toSubmodule_eq_top.1 (eq_top_of_finrank_eq <| K.finrank_toSubmodule.trans h) } -- TODO: `IntermediateField` version
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Basic.lean
import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.NonUnitalSubalgebra import Mathlib.RingTheory.SimpleRing.Basic /-! # Subalgebras over Commutative Semiring In this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`). The `Algebra.adjoin` operation and complete lattice structure can be found in `Mathlib/Algebra/Algebra/Subalgebra/Lattice.lean`. -/ universe u u' v w w' /-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/ structure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : Type v extends Subsemiring A where /-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/ algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0 one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1 /-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/ add_decl_doc Subalgebra.toSubsemiring namespace Subalgebra variable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'} variable [CommSemiring R] variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C] instance : SetLike (Subalgebra R A) A where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h initialize_simps_projections Subalgebra (carrier → coe, as_prefix coe) @[simp] theorem coe_mk (s : Subsemiring A) (h) : (Subalgebra.mk (R := R) s h : Set A) = s := rfl @[simp] theorem mem_mk (s : Subsemiring A) (h) (x) : x ∈ Subalgebra.mk (R := R) s h ↔ x ∈ s := .rfl /-- The actual `Subalgebra` obtained from an element of a type satisfying `SubsemiringClass` and `SMulMemClass`. -/ @[simps] def ofClass {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A] [SubsemiringClass S A] [SMulMemClass S R A] (s : S) : Subalgebra R A where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem one_mem' := one_mem _ algebraMap_mem' r := Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s) instance (priority := 100) : CanLift (Set A) (Subalgebra R A) (↑) (fun s ↦ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ ∀ (r : R), algebraMap R A r ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := by simpa using h.2.2 0 add_mem' := h.1 one_mem' := by simpa using h.2.2 1 mul_mem' := h.2.1 algebraMap_mem' := h.2.2 }, rfl ⟩ instance : SubsemiringClass (Subalgebra R A) A where add_mem {s} := add_mem (s := s.toSubsemiring) mul_mem {s} := mul_mem (s := s.toSubsemiring) one_mem {s} := one_mem s.toSubsemiring zero_mem {s} := zero_mem s.toSubsemiring @[simp] theorem mem_toSubsemiring {S : Subalgebra R A} {x} : x ∈ S.toSubsemiring ↔ x ∈ S := Iff.rfl theorem mem_carrier {s : Subalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : Subalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] theorem coe_toSubsemiring (S : Subalgebra R A) : (↑S.toSubsemiring : Set A) = S := rfl theorem toSubsemiring_injective : Function.Injective (toSubsemiring : Subalgebra R A → Subsemiring A) := fun S T h => ext fun x => by rw [← mem_toSubsemiring, ← mem_toSubsemiring, h] theorem toSubsemiring_inj {S U : Subalgebra R A} : S.toSubsemiring = U.toSubsemiring ↔ S = U := toSubsemiring_injective.eq_iff /-- Copy of a subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ @[simps coe toSubsemiring] protected def copy (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : Subalgebra R A := { S.toSubsemiring.copy s hs with carrier := s algebraMap_mem' := hs.symm ▸ S.algebraMap_mem' } theorem copy_eq (S : Subalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs variable (S : Subalgebra R A) instance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx @[simp, aesop safe (rule_sets := [SetLike])] theorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) : algebraMap R A r ∈ s := Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s) protected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S := algebraMap_mem S r theorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubsemiring := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_le : Set.range (algebraMap R A) ≤ S := S.range_subset theorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S := SMulMemClass.smul_mem r hx protected theorem one_mem : (1 : A) ∈ S := one_mem S protected theorem mul_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x * y ∈ S := mul_mem hx hy protected theorem pow_mem {x : A} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S := pow_mem hx n protected theorem zero_mem : (0 : A) ∈ S := zero_mem S protected theorem add_mem {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x + y ∈ S := add_mem hx hy protected theorem nsmul_mem {x : A} (hx : x ∈ S) (n : ℕ) : n • x ∈ S := nsmul_mem hx n protected theorem natCast_mem (n : ℕ) : (n : A) ∈ S := natCast_mem S n protected theorem list_prod_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.prod ∈ S := list_prod_mem h protected theorem list_sum_mem {L : List A} (h : ∀ x ∈ L, x ∈ S) : L.sum ∈ S := list_sum_mem h protected theorem multiset_sum_mem {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.sum ∈ S := multiset_sum_mem m h protected theorem sum_mem {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) : (∑ x ∈ t, f x) ∈ S := sum_mem h protected theorem multiset_prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) {m : Multiset A} (h : ∀ x ∈ m, x ∈ S) : m.prod ∈ S := multiset_prod_mem m h protected theorem prod_mem {R : Type u} {A : Type v} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) {ι : Type w} {t : Finset ι} {f : ι → A} (h : ∀ x ∈ t, f x ∈ S) : (∏ x ∈ t, f x) ∈ S := prod_mem h /-- Turn a `Subalgebra` into a `NonUnitalSubalgebra` by forgetting that it contains `1`. -/ def toNonUnitalSubalgebra (S : Subalgebra R A) : NonUnitalSubalgebra R A where __ := S smul_mem' r _x hx := S.smul_mem hx r lemma one_mem_toNonUnitalSubalgebra (S : Subalgebra R A) : (1 : A) ∈ S.toNonUnitalSubalgebra := S.one_mem instance {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : SubringClass (Subalgebra R A) A := { Subalgebra.instSubsemiringClass with neg_mem := fun {S x} hx => neg_one_smul R x ▸ S.smul_mem hx _ } protected theorem neg_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) {x : A} (hx : x ∈ S) : -x ∈ S := neg_mem hx protected theorem sub_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) {x y : A} (hx : x ∈ S) (hy : y ∈ S) : x - y ∈ S := sub_mem hx hy protected theorem zsmul_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) {x : A} (hx : x ∈ S) (n : ℤ) : n • x ∈ S := zsmul_mem hx n protected theorem intCast_mem {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) (n : ℤ) : (n : A) ∈ S := intCast_mem S n /-- The projection from a subalgebra of `A` to an additive submonoid of `A`. -/ @[simps coe] def toAddSubmonoid {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) : AddSubmonoid A := S.toSubsemiring.toAddSubmonoid /-- A subalgebra over a ring is also a `Subring`. -/ @[simps toSubsemiring] def toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Subring A := { S.toSubsemiring with neg_mem' := S.neg_mem } @[simp] theorem mem_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} {x} : x ∈ S.toSubring ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubring {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : (↑S.toSubring : Set A) = S := rfl theorem toSubring_injective {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] : Function.Injective (toSubring : Subalgebra R A → Subring A) := fun S T h => ext fun x => by rw [← mem_toSubring, ← mem_toSubring, h] theorem toSubring_inj {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S U : Subalgebra R A} : S.toSubring = U.toSubring ↔ S = U := toSubring_injective.eq_iff instance : Inhabited S := ⟨(0 : S.toSubsemiring)⟩ section /-! `Subalgebra`s inherit structure from their `Subsemiring` / `Semiring` coercions. -/ instance toSemiring {R A} [CommSemiring R] [Semiring A] [Algebra R A] (S : Subalgebra R A) : Semiring S := S.toSubsemiring.toSemiring instance toCommSemiring {R A} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) : CommSemiring S := S.toSubsemiring.toCommSemiring instance toRing {R A} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : Ring S := S.toSubring.toRing instance toCommRing {R A} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) : CommRing S := S.toSubring.toCommRing end /-- The forgetful map from `Subalgebra` to `Submodule` as an `OrderEmbedding` -/ def toSubmodule : Subalgebra R A ↪o Submodule R A where toEmbedding := { toFun := fun S => { S with carrier := S smul_mem' := fun c {x} hx ↦ (Algebra.smul_def c x).symm ▸ mul_mem (S.range_le ⟨c, rfl⟩) hx } inj' := fun _ _ h ↦ ext fun x ↦ SetLike.ext_iff.mp h x } map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe /- TODO: bundle other forgetful maps between algebraic substructures, e.g. `toSubsemiring` and `toSubring` in this file. -/ @[simp] theorem mem_toSubmodule {x} : x ∈ (toSubmodule S) ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubmodule (S : Subalgebra R A) : (toSubmodule S : Set A) = S := rfl theorem toSubmodule_injective : Function.Injective (toSubmodule : Subalgebra R A → Submodule R A) := fun _S₁ _S₂ h => SetLike.ext (SetLike.ext_iff.mp h :) section /-! `Subalgebra`s inherit structure from their `Submodule` coercions. -/ instance (priority := low) module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S := S.toSubmodule.module' instance : Module R S := S.module' instance [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : IsScalarTower R' R S := inferInstanceAs (IsScalarTower R' R (toSubmodule S)) /- More general form of `Subalgebra.algebra`. This instance should have low priority since it is slow to fail: before failing, it will cause a search through all `SMul R' R` instances, which can quickly get expensive. -/ instance (priority := 500) algebra' [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] : Algebra R' S where algebraMap := (algebraMap R' A).codRestrict S fun x => by rw [Algebra.algebraMap_eq_smul_one, ← smul_one_smul R x (1 : A), ← Algebra.algebraMap_eq_smul_one] exact algebraMap_mem S _ commutes' := fun _ _ => Subtype.eq <| Algebra.commutes _ _ smul_def' := fun _ _ => Subtype.eq <| Algebra.smul_def _ _ instance algebra : Algebra R S := S.algebra' @[simp] theorem mk_algebraMap {S : Subalgebra R A} (r : R) (hr : algebraMap R A r ∈ S) : ⟨algebraMap R A r, hr⟩ = algebraMap R S r := rfl end instance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S := ⟨fun {c} {x : S} h => have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h) this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩ protected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y := rfl protected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y := rfl protected theorem coe_zero : ((0 : S) : A) = 0 := rfl protected theorem coe_one : ((1 : S) : A) = 1 := rfl protected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} (x : S) : (↑(-x) : A) = -↑x := rfl protected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y := rfl @[simp, norm_cast] theorem coe_smul [SMul R' R] [SMul R' A] [IsScalarTower R' R A] (r : R') (x : S) : (↑(r • x) : A) = r • (x : A) := rfl @[simp, norm_cast] theorem coe_algebraMap [CommSemiring R'] [SMul R' R] [Algebra R' A] [IsScalarTower R' R A] (r : R') : ↑(algebraMap R' S r) = algebraMap R' A r := rfl protected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : A) = (x : A) ^ n := SubmonoidClass.coe_pow x n protected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 := ZeroMemClass.coe_eq_zero protected theorem coe_eq_one {x : S} : (x : A) = 1 ↔ x = 1 := OneMemClass.coe_eq_one -- todo: standardize on the names these morphisms -- compare with submodule.subtype /-- Embedding of a subalgebra into the algebra. -/ def val : S →ₐ[R] A := { toFun := ((↑) : S → A) map_zero' := rfl map_one' := rfl map_add' := fun _ _ ↦ rfl map_mul' := fun _ _ ↦ rfl commutes' := fun _ ↦ rfl } @[simp] theorem coe_val : (S.val : S → A) = ((↑) : S → A) := rfl theorem val_apply (x : S) : S.val x = (x : A) := rfl @[simp] theorem toSubsemiring_subtype : S.toSubsemiring.subtype = (S.val : S →+* A) := rfl @[simp] theorem toSubring_subtype {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subalgebra R A) : S.toSubring.subtype = (S.val : S →+* A) := rfl /-- Linear equivalence between `S : Submodule R A` and `S`. Though these types are equal, we define it as a `LinearEquiv` to avoid type equalities. -/ def toSubmoduleEquiv (S : Subalgebra R A) : toSubmodule S ≃ₗ[R] S := LinearEquiv.ofEq _ _ rfl /-- Transport a subalgebra via an algebra homomorphism. -/ @[simps! coe toSubsemiring] def map (f : A →ₐ[R] B) (S : Subalgebra R A) : Subalgebra R B := { S.toSubsemiring.map (f : A →+* B) with algebraMap_mem' := fun r => f.commutes r ▸ Set.mem_image_of_mem _ (S.algebraMap_mem r) } theorem map_mono {S₁ S₂ : Subalgebra R A} {f : A →ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f := Set.image_mono theorem map_injective {f : A →ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) := fun _S₁ _S₂ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : Subalgebra R A) : S.map (AlgHom.id R A) = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : Subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : Subalgebra R A} {f : A →ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y := Subsemiring.mem_map theorem map_toSubmodule {S : Subalgebra R A} {f : A →ₐ[R] B} : (toSubmodule <| S.map f) = S.toSubmodule.map f.toLinearMap := SetLike.coe_injective rfl /-- Preimage of a subalgebra under an algebra homomorphism. -/ @[simps! coe toSubsemiring] def comap (f : A →ₐ[R] B) (S : Subalgebra R B) : Subalgebra R A := { S.toSubsemiring.comap (f : A →+* B) with algebraMap_mem' := fun r => show f (algebraMap R A r) ∈ S from (f.commutes r).symm ▸ S.algebraMap_mem r } attribute [norm_cast] coe_comap theorem map_le {S : Subalgebra R A} {f : A →ₐ[R] B} {U : Subalgebra R B} : map f S ≤ U ↔ S ≤ comap f U := Set.image_subset_iff theorem gc_map_comap (f : A →ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le @[simp] theorem mem_comap (S : Subalgebra R B) (f : A →ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl instance noZeroDivisors {R A : Type*} [CommSemiring R] [Semiring A] [NoZeroDivisors A] [Algebra R A] (S : Subalgebra R A) : NoZeroDivisors S := inferInstanceAs (NoZeroDivisors S.toSubsemiring) instance isDomain {R A : Type*} [CommRing R] [Ring A] [IsDomain A] [Algebra R A] (S : Subalgebra R A) : IsDomain S := inferInstanceAs (IsDomain S.toSubring) end Subalgebra namespace SubalgebraClass variable {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable [SetLike S A] [SubsemiringClass S A] [hSR : SMulMemClass S R A] (s : S) instance (priority := 75) toAlgebra : Algebra R s where algebraMap := { toFun r := ⟨algebraMap R A r, algebraMap_mem s r⟩ map_one' := Subtype.ext <| by simp map_mul' _ _ := Subtype.ext <| by simp map_zero' := Subtype.ext <| by simp map_add' _ _ := Subtype.ext <| by simp} commutes' r x := Subtype.ext <| Algebra.commutes r (x : A) smul_def' r x := Subtype.ext <| (algebraMap_smul A r (x : A)).symm @[simp, norm_cast] lemma coe_algebraMap (r : R) : (algebraMap R s r : A) = algebraMap R A r := rfl /-- Embedding of a subalgebra into the algebra, as an algebra homomorphism. -/ def val (s : S) : s →ₐ[R] A := { SubsemiringClass.subtype s, SMulMemClass.subtype s with toFun := (↑) commutes' := fun _ ↦ rfl } @[simp] theorem coe_val : (val s : s → A) = ((↑) : s → A) := rfl end SubalgebraClass namespace Submodule variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable (p : Submodule R A) /-- A submodule containing `1` and closed under multiplication is a subalgebra. -/ @[simps coe toSubsemiring] def toSubalgebra (p : Submodule R A) (h_one : (1 : A) ∈ p) (h_mul : ∀ x y, x ∈ p → y ∈ p → x * y ∈ p) : Subalgebra R A := { p with mul_mem' := fun hx hy ↦ h_mul _ _ hx hy one_mem' := h_one algebraMap_mem' := fun r => by rw [Algebra.algebraMap_eq_smul_one] exact p.smul_mem _ h_one } @[simp] theorem mem_toSubalgebra {p : Submodule R A} {h_one h_mul} {x} : x ∈ p.toSubalgebra h_one h_mul ↔ x ∈ p := Iff.rfl theorem toSubalgebra_mk (s : Submodule R A) (h1 hmul) : s.toSubalgebra h1 hmul = Subalgebra.mk ⟨⟨⟨s, @hmul⟩, h1⟩, s.add_mem, s.zero_mem⟩ (by intro r; rw [Algebra.algebraMap_eq_smul_one]; apply s.smul_mem _ h1) := rfl @[simp] theorem toSubalgebra_toSubmodule (p : Submodule R A) (h_one h_mul) : Subalgebra.toSubmodule (p.toSubalgebra h_one h_mul) = p := SetLike.coe_injective rfl @[simp] theorem _root_.Subalgebra.toSubmodule_toSubalgebra (S : Subalgebra R A) : (S.toSubmodule.toSubalgebra S.one_mem fun _ _ => S.mul_mem) = S := SetLike.coe_injective rfl end Submodule namespace AlgHom variable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'} variable [CommSemiring R] variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C] variable (φ : A →ₐ[R] B) /-- Range of an `AlgHom` as a subalgebra. -/ @[simps! coe toSubsemiring] protected def range (φ : A →ₐ[R] B) : Subalgebra R B := { φ.toRingHom.rangeS with algebraMap_mem' := fun r => ⟨algebraMap R A r, φ.commutes r⟩ } @[simp] theorem mem_range (φ : A →ₐ[R] B) {y : B} : y ∈ φ.range ↔ ∃ x, φ x = y := RingHom.mem_rangeS theorem mem_range_self (φ : A →ₐ[R] B) (x : A) : φ x ∈ φ.range := φ.mem_range.2 ⟨x, rfl⟩ theorem range_comp (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range = f.range.map g := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range (f : A →ₐ[R] B) (g : B →ₐ[R] C) : (g.comp f).range ≤ g.range := SetLike.coe_mono (Set.range_comp_subset_range f g) /-- Restrict the codomain of an algebra homomorphism. -/ def codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : A →ₐ[R] S := { RingHom.codRestrict (f : A →+* B) S hf with commutes' := fun r => Subtype.eq <| f.commutes r } @[simp] theorem val_comp_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : S.val.comp (f.codRestrict S hf) = f := AlgHom.ext fun _ => rfl @[simp] theorem coe_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) : ↑(f.codRestrict S hf x) = f x := rfl theorem injective_codRestrict (f : A →ₐ[R] B) (S : Subalgebra R B) (hf : ∀ x, f x ∈ S) : Function.Injective (f.codRestrict S hf) ↔ Function.Injective f := ⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy :)⟩ /-- Restrict the codomain of an `AlgHom` `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict (f : A →ₐ[R] B) : A →ₐ[R] f.range := f.codRestrict f.range f.mem_range_self theorem rangeRestrict_surjective (f : A →ₐ[R] B) : Function.Surjective (f.rangeRestrict) := fun ⟨_y, hy⟩ => let ⟨x, hx⟩ := hy ⟨x, SetCoe.ext hx⟩ /-- The range of a morphism of algebras is a fintype, if the domain is a fintype. Note that this instance can cause a diamond with `Subtype.fintype` if `B` is also a fintype. -/ instance fintypeRange [Fintype A] [DecidableEq B] (φ : A →ₐ[R] B) : Fintype φ.range := Set.fintypeRange φ end AlgHom namespace AlgEquiv variable {R : Type u} {A : Type v} {B : Type w} variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] /-- Restrict an algebra homomorphism with a left inverse to an algebra isomorphism to its range. This is a computable alternative to `AlgEquiv.ofInjective`. -/ def ofLeftInverse {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) : A ≃ₐ[R] f.range := { f.rangeRestrict with toFun := f.rangeRestrict invFun := g ∘ f.range.val left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := f.mem_range.mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverse_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : A) : ↑(ofLeftInverse h x) = f x := rfl @[simp] theorem ofLeftInverse_symm_apply {g : B → A} {f : A →ₐ[R] B} (h : Function.LeftInverse g f) (x : f.range) : (ofLeftInverse h).symm x = g x := rfl /-- Restrict an injective algebra homomorphism to an algebra isomorphism -/ noncomputable def ofInjective (f : A →ₐ[R] B) (hf : Function.Injective f) : A ≃ₐ[R] f.range := ofLeftInverse (Classical.choose_spec hf.hasLeftInverse) @[simp] theorem ofInjective_apply (f : A →ₐ[R] B) (hf : Function.Injective f) (x : A) : ↑(ofInjective f hf x) = f x := rfl /-- Restrict an algebra homomorphism between fields to an algebra isomorphism -/ noncomputable def ofInjectiveField {E F : Type*} [DivisionRing E] [Semiring F] [Nontrivial F] [Algebra R E] [Algebra R F] (f : E →ₐ[R] F) : E ≃ₐ[R] f.range := ofInjective f f.toRingHom.injective /-- Given an equivalence `e : A ≃ₐ[R] B` of `R`-algebras and a subalgebra `S` of `A`, `subalgebraMap` is the induced equivalence between `S` and `S.map e` -/ @[simps!] def subalgebraMap (e : A ≃ₐ[R] B) (S : Subalgebra R A) : S ≃ₐ[R] S.map (e : A →ₐ[R] B) := { e.toRingEquiv.subsemiringMap S.toSubsemiring with commutes' := fun r => by ext; exact e.commutes r } end AlgEquiv namespace Subalgebra open Algebra variable {R : Type u} {A : Type v} {B : Type w} variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable (S T U : Subalgebra R A) instance subsingleton_of_subsingleton [Subsingleton A] : Subsingleton (Subalgebra R A) := ⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩ theorem range_val : S.val.range = S := ext <| Set.ext_iff.1 <| S.val.coe_range.trans Subtype.range_val /-- The map `S → T` when `S` is a subalgebra contained in the subalgebra `T`. This is the subalgebra version of `Submodule.inclusion`, or `Subring.inclusion` -/ def inclusion {S T : Subalgebra R A} (h : S ≤ T) : S →ₐ[R] T where toFun := Set.inclusion h map_one' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl map_zero' := rfl commutes' _ := rfl variable {S T U} (h : S ≤ T) theorem inclusion_injective : Function.Injective (inclusion h) := fun _ _ => Subtype.ext ∘ Subtype.mk.inj @[simp] theorem inclusion_self : inclusion (le_refl S) = AlgHom.id R S := AlgHom.ext fun _x => Subtype.ext rfl @[simp] theorem inclusion_mk (x : A) (hx : x ∈ S) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl theorem inclusion_right (x : T) (m : (x : A) ∈ S) : inclusion h ⟨x, m⟩ = x := Subtype.ext rfl @[simp] theorem inclusion_inclusion (hst : S ≤ T) (htu : T ≤ U) (x : S) : inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x := Subtype.ext rfl @[simp] theorem coe_inclusion (s : S) : (inclusion h s : A) = s := rfl namespace inclusion scoped instance isScalarTower_left (X) [SMul X R] [SMul X A] [IsScalarTower X R A] : letI := (inclusion h).toModule; IsScalarTower X S T := letI := (inclusion h).toModule ⟨fun x s t ↦ Subtype.ext <| by rw [← one_smul R s, ← smul_assoc, one_smul, ← one_smul R (s • t), ← smul_assoc, Algebra.smul_def, Algebra.smul_def] apply mul_assoc⟩ scoped instance isScalarTower_right (X) [MulAction A X] : letI := (inclusion h).toModule; IsScalarTower S T X := letI := (inclusion h).toModule; ⟨fun _ ↦ mul_smul _⟩ scoped instance faithfulSMul : letI := (inclusion h).toModule; FaithfulSMul S T := letI := (inclusion h).toModule ⟨fun {x y} h ↦ Subtype.ext <| by convert Subtype.ext_iff.mp (h 1) using 1 <;> exact (mul_one _).symm⟩ end inclusion variable (S) /-- Two subalgebras that are equal are also equivalent as algebras. This is the `Subalgebra` version of `LinearEquiv.ofEq` and `Equiv.setCongr`. -/ @[simps apply] def equivOfEq (S T : Subalgebra R A) (h : S = T) : S ≃ₐ[R] T where __ := LinearEquiv.ofEq _ _ (congr_arg toSubmodule h) toFun x := ⟨x, h ▸ x.2⟩ invFun x := ⟨x, h.symm ▸ x.2⟩ map_mul' _ _ := rfl commutes' _ := rfl @[simp] theorem equivOfEq_symm (S T : Subalgebra R A) (h : S = T) : (equivOfEq S T h).symm = equivOfEq T S h.symm := rfl @[simp] theorem equivOfEq_rfl (S : Subalgebra R A) : equivOfEq S S rfl = AlgEquiv.refl := by ext; rfl @[simp] theorem equivOfEq_trans (S T U : Subalgebra R A) (hST : S = T) (hTU : T = U) : (equivOfEq S T hST).trans (equivOfEq T U hTU) = equivOfEq S U (hST.trans hTU) := rfl section equivMapOfInjective variable (f : A →ₐ[R] B) theorem range_comp_val : (f.comp S.val).range = S.map f := by rw [AlgHom.range_comp, range_val] /-- An `AlgHom` between two rings restricts to an `AlgHom` from any subalgebra of the domain onto the image of that subalgebra. -/ def _root_.AlgHom.subalgebraMap : S →ₐ[R] S.map f := (f.comp S.val).codRestrict _ fun x ↦ ⟨_, x.2, rfl⟩ variable {S} in @[simp] theorem _root_.AlgHom.subalgebraMap_coe_apply (x : S) : f.subalgebraMap S x = f x := rfl theorem _root_.AlgHom.subalgebraMap_surjective : Function.Surjective (f.subalgebraMap S) := f.toAddMonoidHom.addSubmonoidMap_surjective S.toAddSubmonoid variable (hf : Function.Injective f) /-- A subalgebra is isomorphic to its image under an injective `AlgHom` -/ noncomputable def equivMapOfInjective : S ≃ₐ[R] S.map f := (AlgEquiv.ofInjective (f.comp S.val) (hf.comp Subtype.val_injective)).trans (equivOfEq _ _ (range_comp_val S f)) @[simp] theorem coe_equivMapOfInjective_apply (x : S) : ↑(equivMapOfInjective S f hf x) = f x := rfl end equivMapOfInjective /-! ## Actions by `Subalgebra`s These are just copies of the definitions about `Subsemiring` starting from `Subring.mulAction`. -/ section Actions variable {α β : Type*} /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [SMul A α] (S : Subalgebra R A) : SMul S α := inferInstanceAs (SMul S.toSubsemiring α) theorem smul_def [SMul A α] {S : Subalgebra R A} (g : S) (m : α) : g • m = (g : A) • m := rfl instance smulCommClass_left [SMul A β] [SMul α β] [SMulCommClass A α β] (S : Subalgebra R A) : SMulCommClass S α β := S.toSubsemiring.smulCommClass_left instance smulCommClass_right [SMul α β] [SMul A β] [SMulCommClass α A β] (S : Subalgebra R A) : SMulCommClass α S β := S.toSubsemiring.smulCommClass_right /-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/ instance isScalarTower_left [SMul α β] [SMul A α] [SMul A β] [IsScalarTower A α β] (S : Subalgebra R A) : IsScalarTower S α β := inferInstanceAs (IsScalarTower S.toSubsemiring α β) instance isScalarTower_mid {R S T : Type*} [CommSemiring R] [Semiring S] [AddCommMonoid T] [Algebra R S] [Module R T] [Module S T] [IsScalarTower R S T] (S' : Subalgebra R S) : IsScalarTower R S' T := ⟨fun _x y _z => smul_assoc _ (y : S) _⟩ instance [SMul A α] [FaithfulSMul A α] (S : Subalgebra R A) : FaithfulSMul S α := inferInstanceAs (FaithfulSMul S.toSubsemiring α) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [MulAction A α] (S : Subalgebra R A) : MulAction S α := inferInstanceAs (MulAction S.toSubsemiring α) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [AddMonoid α] [DistribMulAction A α] (S : Subalgebra R A) : DistribMulAction S α := inferInstanceAs (DistribMulAction S.toSubsemiring α) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [Zero α] [SMulWithZero A α] (S : Subalgebra R A) : SMulWithZero S α := inferInstanceAs (SMulWithZero S.toSubsemiring α) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance [Zero α] [MulActionWithZero A α] (S : Subalgebra R A) : MulActionWithZero S α := inferInstanceAs (MulActionWithZero S.toSubsemiring α) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance moduleLeft [AddCommMonoid α] [Module A α] (S : Subalgebra R A) : Module S α := inferInstanceAs (Module S.toSubsemiring α) /-- The action by a subalgebra is the action by the underlying algebra. -/ instance toAlgebra {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A] [Algebra A α] (S : Subalgebra R A) : Algebra S α := Algebra.ofSubsemiring S.toSubsemiring theorem algebraMap_eq {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A] [Algebra A α] (S : Subalgebra R A) : algebraMap S α = (algebraMap A α).comp S.val := rfl theorem algebraMap_def {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A] [Algebra A α] {S : Subalgebra R A} (s : S) : algebraMap S α s = algebraMap A α (s : A) := rfl @[simp] theorem algebraMap_mk {R A : Type*} [CommSemiring R] [CommSemiring A] [Semiring α] [Algebra R A] [Algebra A α] {S : Subalgebra R A} (a : A) (ha : a ∈ S) : algebraMap S α (⟨a, ha⟩ : S) = algebraMap A α a := rfl @[simp] lemma algebraMap_apply {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) (x : S) : algebraMap S A x = x := rfl @[simp] theorem rangeS_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) : (algebraMap S A).rangeS = S.toSubsemiring := by rw [algebraMap_eq, Algebra.algebraMap_self, RingHom.id_comp, ← toSubsemiring_subtype, Subsemiring.rangeS_subtype] @[simp] theorem range_algebraMap {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] (S : Subalgebra R A) : (algebraMap S A).range = S.toSubring := by rw [algebraMap_eq, Algebra.algebraMap_self, RingHom.id_comp, ← toSubring_subtype, Subring.range_subtype] @[simp] lemma setRange_algebraMap {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (S : Subalgebra R A) : Set.range (algebraMap S A) = (S : Set A) := SetLike.ext'_iff.mp S.rangeS_algebraMap instance noZeroSMulDivisors_top [NoZeroDivisors A] (S : Subalgebra R A) : NoZeroSMulDivisors S A := ⟨fun {c} x h => have : (c : A) = 0 ∨ x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h this.imp_left (@Subtype.ext_iff _ _ c 0).mpr⟩ end Actions section Center theorem _root_.Set.algebraMap_mem_center (r : R) : algebraMap R A r ∈ Set.center A := by simp only [Semigroup.mem_center_iff, commutes, forall_const] variable (R A) /-- The center of an algebra is the set of elements which commute with every element. They form a subalgebra. -/ @[simps! coe toSubsemiring] def center : Subalgebra R A := { Subsemiring.center A with algebraMap_mem' := Set.algebraMap_mem_center } @[simp] theorem center_toSubring (R A : Type*) [CommRing R] [Ring A] [Algebra R A] : (center R A).toSubring = Subring.center A := rfl variable {R A} instance : CommSemiring (center R A) := inferInstanceAs (CommSemiring (Subsemiring.center A)) instance {A : Type*} [Ring A] [Algebra R A] : CommRing (center R A) := inferInstanceAs (CommRing (Subring.center A)) theorem mem_center_iff {a : A} : a ∈ center R A ↔ ∀ b : A, b * a = a * b := Subsemigroup.mem_center_iff end Center section Centralizer @[simp] theorem _root_.Set.algebraMap_mem_centralizer {s : Set A} (r : R) : algebraMap R A r ∈ s.centralizer := fun _a _h => (Algebra.commutes _ _).symm variable (R) /-- The centralizer of a set as a subalgebra. -/ def centralizer (s : Set A) : Subalgebra R A := { Subsemiring.centralizer s with algebraMap_mem' := Set.algebraMap_mem_centralizer } @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = s.centralizer := rfl theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g := Iff.rfl theorem center_le_centralizer (s) : center R A ≤ centralizer R s := s.center_subset_centralizer theorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s := Set.centralizer_subset h @[simp] theorem centralizer_univ : centralizer R Set.univ = center R A := SetLike.ext' (Set.centralizer_univ A) lemma le_centralizer_centralizer {s : Subalgebra R A} : s ≤ centralizer R (centralizer R (s : Set A)) := Set.subset_centralizer_centralizer @[simp] lemma centralizer_centralizer_centralizer {s : Set A} : centralizer R s.centralizer.centralizer = centralizer R s := by apply SetLike.coe_injective simp only [coe_centralizer, Set.centralizer_centralizer_centralizer] end Centralizer end Subalgebra section Nat variable {R : Type*} [Semiring R] /-- A subsemiring is an `ℕ`-subalgebra. -/ @[simps toSubsemiring] def subalgebraOfSubsemiring (S : Subsemiring R) : Subalgebra ℕ R := { S with algebraMap_mem' := fun i => natCast_mem S i } @[simp] theorem mem_subalgebraOfSubsemiring {x : R} {S : Subsemiring R} : x ∈ subalgebraOfSubsemiring S ↔ x ∈ S := Iff.rfl end Nat section Int variable {R : Type*} [Ring R] /-- A subring is a `ℤ`-subalgebra. -/ @[simps toSubsemiring] def subalgebraOfSubring (S : Subring R) : Subalgebra ℤ R := { S with algebraMap_mem' := fun i => Int.induction_on i (by simp) (fun i ih => by simpa using S.add_mem ih S.one_mem) fun i ih => show ((-i - 1 : ℤ) : R) ∈ S by rw [Int.cast_sub, Int.cast_one] exact S.sub_mem ih S.one_mem } variable {S : Type*} [Semiring S] @[simp] theorem mem_subalgebraOfSubring {x : R} {S : Subring R} : x ∈ subalgebraOfSubring S ↔ x ∈ S := Iff.rfl end Int section Equalizer namespace AlgHom variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable {F : Type*} /-- The equalizer of two R-algebra homomorphisms -/ @[simps coe toSubsemiring] def equalizer (ϕ ψ : F) [FunLike F A B] [AlgHomClass F R A B] : Subalgebra R A where carrier := { a | ϕ a = ψ a } zero_mem' := by simp only [Set.mem_setOf_eq, map_zero] one_mem' := by simp only [Set.mem_setOf_eq, map_one] add_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by rw [Set.mem_setOf_eq, map_add, map_add, hx, hy] mul_mem' {x y} (hx : ϕ x = ψ x) (hy : ϕ y = ψ y) := by rw [Set.mem_setOf_eq, map_mul, map_mul, hx, hy] algebraMap_mem' x := by simp only [Set.mem_setOf_eq, AlgHomClass.commutes] variable [FunLike F A B] [AlgHomClass F R A B] @[simp] theorem mem_equalizer (φ ψ : F) (x : A) : x ∈ equalizer φ ψ ↔ φ x = ψ x := Iff.rfl theorem equalizer_toSubmodule {φ ψ : F} : Subalgebra.toSubmodule (equalizer φ ψ) = LinearMap.eqLocus φ ψ := rfl theorem le_equalizer {φ ψ : F} {S : Subalgebra R A} : S ≤ equalizer φ ψ ↔ Set.EqOn φ ψ S := Iff.rfl end AlgHom end Equalizer section MapComap namespace Subalgebra variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] theorem comap_map_eq_self_of_injective {f : A →ₐ[R] B} (hf : Function.Injective f) (S : Subalgebra R A) : (S.map f).comap f = S := SetLike.coe_injective (Set.preimage_image_eq _ hf) end Subalgebra end MapComap variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] /-- Turn a non-unital subalgebra containing `1` into a subalgebra. -/ def NonUnitalSubalgebra.toSubalgebra (S : NonUnitalSubalgebra R A) (h1 : (1 : A) ∈ S) : Subalgebra R A := { S with one_mem' := h1 algebraMap_mem' := fun r => (Algebra.algebraMap_eq_smul_one (R := R) (A := A) r).symm ▸ SMulMemClass.smul_mem r h1 } lemma Subalgebra.toNonUnitalSubalgebra_toSubalgebra (S : Subalgebra R A) : S.toNonUnitalSubalgebra.toSubalgebra S.one_mem = S := by cases S; rfl lemma NonUnitalSubalgebra.toSubalgebra_toNonUnitalSubalgebra (S : NonUnitalSubalgebra R A) (h1 : (1 : A) ∈ S) : (NonUnitalSubalgebra.toSubalgebra S h1).toNonUnitalSubalgebra = S := by cases S; rfl
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Operations.lean
import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.RingTheory.Ideal.Maps import Mathlib.Algebra.Ring.Action.Submonoid /-! # More operations on subalgebras In this file we relate the definitions in `Mathlib/RingTheory/Ideal/Operations.lean` to subalgebras. The contents of this file are somewhat random since both `Mathlib/Algebra/Algebra/Subalgebra/Basic.lean` and `Mathlib/RingTheory/Ideal/Operations.lean` are somewhat of a grab-bag of definitions, and this is whatever ends up in the intersection. -/ assert_not_exists Cardinal namespace AlgHom variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] theorem ker_rangeRestrict (f : A →ₐ[R] B) : RingHom.ker f.rangeRestrict = RingHom.ker f := Ideal.ext fun _ ↦ Subtype.ext_iff end AlgHom namespace Subalgebra open Algebra variable {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] variable (S' : Subalgebra R S) /-- Suppose we are given `∑ i, lᵢ * sᵢ = 1` ∈ `S`, and `S'` a subalgebra of `S` that contains `lᵢ` and `sᵢ`. To check that an `x : S` falls in `S'`, we only need to show that `sᵢ ^ n • x ∈ S'` for some `n` for each `sᵢ`. -/ theorem mem_of_finset_sum_eq_one_of_pow_smul_mem {ι : Type*} (ι' : Finset ι) (s : ι → S) (l : ι → S) (e : ∑ i ∈ ι', l i * s i = 1) (hs : ∀ i, s i ∈ S') (hl : ∀ i, l i ∈ S') (x : S) (H : ∀ i, ∃ n : ℕ, (s i ^ n : S) • x ∈ S') : x ∈ S' := by suffices x ∈ Subalgebra.toSubmodule (Algebra.ofId S' S).range by obtain ⟨x, rfl⟩ := this exact x.2 choose n hn using H let s' : ι → S' := fun x => ⟨s x, hs x⟩ let l' : ι → S' := fun x => ⟨l x, hl x⟩ have e' : ∑ i ∈ ι', l' i * s' i = 1 := by ext change S'.subtype (∑ i ∈ ι', l' i * s' i) = 1 simpa only [map_sum, map_mul] using e have : Ideal.span (s' '' ι') = ⊤ := by rw [Ideal.eq_top_iff_one, ← e'] apply sum_mem intro i hi exact Ideal.mul_mem_left _ _ <| Ideal.subset_span <| Set.mem_image_of_mem s' hi let N := ι'.sup n have hN := Ideal.span_pow_eq_top _ this N apply (Algebra.ofId S' S).range.toSubmodule.mem_of_span_top_of_smul_mem _ hN rintro ⟨_, _, ⟨i, hi, rfl⟩, rfl⟩ change s' i ^ N • x ∈ _ rw [← tsub_add_cancel_of_le (show n i ≤ N from Finset.le_sup hi), pow_add, mul_smul] refine Submodule.smul_mem _ (⟨_, pow_mem (hs i) _⟩ : S') ?_ exact ⟨⟨_, hn i⟩, rfl⟩ theorem mem_of_span_eq_top_of_smul_pow_mem (s : Set S) (l : s →₀ S) (hs : Finsupp.linearCombination S ((↑) : s → S) l = 1) (hs' : s ⊆ S') (hl : ∀ i, l i ∈ S') (x : S) (H : ∀ r : s, ∃ n : ℕ, (r : S) ^ n • x ∈ S') : x ∈ S' := mem_of_finset_sum_eq_one_of_pow_smul_mem S' l.support (↑) l hs (fun x => hs' x.2) hl x H end Subalgebra section MulSemiringAction variable (A B : Type*) [CommSemiring A] [Ring B] [Algebra A B] variable (G : Type*) [Monoid G] [MulSemiringAction G B] [SMulCommClass G A B] /-- The set of fixed points under a group action, as a subring. -/ def FixedPoints.subring : Subring B where __ := FixedPoints.addSubgroup G B __ := FixedPoints.submonoid G B /-- The set of fixed points under a group action, as a subalgebra. -/ def FixedPoints.subalgebra : Subalgebra A B where __ := FixedPoints.addSubgroup G B __ := FixedPoints.submonoid G B algebraMap_mem' r := by simp end MulSemiringAction
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Centralizer.lean
import Mathlib.LinearAlgebra.TensorProduct.Basis import Mathlib.RingTheory.TensorProduct.Maps /-! # Properties of centers and centralizers This file contains theorems about the center and centralizer of a subalgebra. ## Main results Let `R` be a commutative ring and `A` and `B` two `R`-algebras. - `Subalgebra.centralizer_sup`: if `S` and `T` are subalgebras of `A`, then the centralizer of `S ⊔ T` is the intersection of the centralizer of `S` and the centralizer of `T`. - `Subalgebra.centralizer_range_includeLeft_eq_center_tensorProduct`: if `B` is free as a module, then the centralizer of `A ⊗ 1` in `A ⊗ B` is `C(A) ⊗ B` where `C(A)` is the center of `A`. - `Subalgebra.centralizer_range_includeRight_eq_center_tensorProduct`: if `A` is free as a module, then the centralizer of `1 ⊗ B` in `A ⊗ B` is `A ⊗ C(B)` where `C(B)` is the center of `B`. -/ namespace Subalgebra open Algebra.TensorProduct section CommSemiring variable {R : Type*} [CommSemiring R] variable {A : Type*} [Semiring A] [Algebra R A] lemma le_centralizer_iff (S T : Subalgebra R A) : S ≤ centralizer R T ↔ T ≤ centralizer R S := ⟨fun h t ht _ hs ↦ (h hs t ht).symm, fun h s hs _ ht ↦ (h ht s hs).symm⟩ lemma centralizer_coe_sup (S T : Subalgebra R A) : centralizer R ((S ⊔ T : Subalgebra R A) : Set A) = centralizer R S ⊓ centralizer R T := eq_of_forall_le_iff fun K ↦ by simp_rw [le_centralizer_iff, sup_le_iff, le_inf_iff, K.le_centralizer_iff] lemma centralizer_coe_iSup {ι : Sort*} (S : ι → Subalgebra R A) : centralizer R ((⨆ i, S i : Subalgebra R A) : Set A) = ⨅ i, centralizer R (S i) := eq_of_forall_le_iff fun K ↦ by simp_rw [le_centralizer_iff, iSup_le_iff, le_iInf_iff, K.le_centralizer_iff] end CommSemiring section Free variable (R : Type*) [CommSemiring R] variable (A : Type*) [Semiring A] [Algebra R A] variable (B : Type*) [Semiring B] [Algebra R B] open Finsupp TensorProduct /-- Let `R` be a commutative ring and `A, B` be `R`-algebras where `B` is free as `R`-module. For any subset `S ⊆ A`, the centralizer of `S ⊗ 1 ⊆ A ⊗ B` is `C_A(S) ⊗ B` where `C_A(S)` is the centralizer of `S` in `A`. -/ lemma centralizer_coe_image_includeLeft_eq_center_tensorProduct (S : Set A) [Module.Free R B] : Subalgebra.centralizer R (Algebra.TensorProduct.includeLeft (S := R) '' S) = (Algebra.TensorProduct.map (Subalgebra.centralizer R (S : Set A)).val (AlgHom.id R B)).range := by classical ext w constructor · intro hw rw [mem_centralizer_iff] at hw let ℬ := Module.Free.chooseBasis R B obtain ⟨b, rfl⟩ := TensorProduct.eq_repr_basis_right ℬ w refine Subalgebra.sum_mem _ fun j hj => ⟨⟨b j, ?_⟩ ⊗ₜ[R] ℬ j, by simp⟩ rw [Subalgebra.mem_centralizer_iff] intro x hx suffices x • b = b.mapRange (· * x) (by simp) from Finsupp.ext_iff.1 this j specialize hw (x ⊗ₜ[R] 1) ⟨x, hx, rfl⟩ simp only [Finsupp.sum, Finset.mul_sum, Algebra.TensorProduct.tmul_mul_tmul, one_mul, Finset.sum_mul, mul_one] at hw refine TensorProduct.sum_tmul_basis_right_injective ℬ ?_ simp only [Finsupp.coe_lsum] rw [sum_of_support_subset (s := b.support) (hs := Finsupp.support_smul) (h := by simp), sum_of_support_subset (s := b.support) (hs := support_mapRange) (h := by simp)] simpa only [Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul, LinearMap.flip_apply, TensorProduct.mk_apply, Finsupp.mapRange_apply] using hw · rintro ⟨w, rfl⟩ rw [Subalgebra.mem_centralizer_iff] rintro _ ⟨x, hx, rfl⟩ induction w using TensorProduct.induction_on with | zero => simp | tmul b c => simp [Subalgebra.mem_centralizer_iff _ |>.1 b.2 x hx] | add y z hy hz => rw [map_add, mul_add, hy, hz, add_mul] /-- Let `R` be a commutative ring and `A, B` be `R`-algebras where `B` is free as `R`-module. For any subset `S ⊆ B`, the centralizer of `1 ⊗ S ⊆ A ⊗ B` is `A ⊗ C_B(S)` where `C_B(S)` is the centralizer of `S` in `B`. -/ lemma centralizer_coe_image_includeRight_eq_center_tensorProduct (S : Set B) [Module.Free R A] : Subalgebra.centralizer R (Algebra.TensorProduct.includeRight '' S) = (Algebra.TensorProduct.map (AlgHom.id R A) (Subalgebra.centralizer R (S : Set B)).val).range := by have eq1 := centralizer_coe_image_includeLeft_eq_center_tensorProduct R B A S apply_fun Subalgebra.comap (Algebra.TensorProduct.comm R A B).toAlgHom at eq1 convert eq1 · ext x simpa [mem_centralizer_iff] using ⟨fun h b hb ↦ (Algebra.TensorProduct.comm R A B).symm.injective <| by aesop, fun h b hb ↦ (Algebra.TensorProduct.comm R A B).injective <| by aesop⟩ · ext x simp only [AlgHom.mem_range, AlgEquiv.toAlgHom_eq_coe, mem_comap, AlgHom.coe_coe] constructor · rintro ⟨x, rfl⟩ exact ⟨(Algebra.TensorProduct.comm R _ _) x, by rw [Algebra.TensorProduct.comm_comp_map_apply]⟩ · rintro ⟨y, hy⟩ refine ⟨(Algebra.TensorProduct.comm R _ _) y, (Algebra.TensorProduct.comm R A B).injective ?_⟩ rw [← hy, comm_comp_map_apply, ← comm_symm, AlgEquiv.symm_apply_apply] /-- Let `R` be a commutative ring and `A, B` be `R`-algebras where `B` is free as `R`-module. For any subalgebra `S` of `A`, the centralizer of `S ⊗ 1 ⊆ A ⊗ B` is `C_A(S) ⊗ B` where `C_A(S)` is the centralizer of `S` in `A`. -/ lemma centralizer_coe_map_includeLeft_eq_center_tensorProduct (S : Subalgebra R A) [Module.Free R B] : Subalgebra.centralizer R (S.map (Algebra.TensorProduct.includeLeft (R := R) (B := B))) = (Algebra.TensorProduct.map (Subalgebra.centralizer R (S : Set A)).val (AlgHom.id R B)).range := centralizer_coe_image_includeLeft_eq_center_tensorProduct R A B S /-- Let `R` be a commutative ring and `A, B` be `R`-algebras where `A` is free as `R`-module. For any subalgebra `S` of `B`, the centralizer of `1 ⊗ S ⊆ A ⊗ B` is `A ⊗ C_B(S)` where `C_B(S)` is the centralizer of `S` in `B`. -/ lemma centralizer_coe_map_includeRight_eq_center_tensorProduct (S : Subalgebra R B) [Module.Free R A] : Subalgebra.centralizer R (S.map (Algebra.TensorProduct.includeRight (R := R) (A := A))) = (Algebra.TensorProduct.map (AlgHom.id R A) (Subalgebra.centralizer R (S : Set B)).val).range := centralizer_coe_image_includeRight_eq_center_tensorProduct R A B S /-- Let `R` be a commutative ring and `A, B` be `R`-algebras where `B` is free as `R`-module. Then the centralizer of `A ⊗ 1 ⊆ A ⊗ B` is `C(A) ⊗ B` where `C(A)` is the center of `A`. -/ lemma centralizer_coe_range_includeLeft_eq_center_tensorProduct [Module.Free R B] : Subalgebra.centralizer R (Algebra.TensorProduct.includeLeft : A →ₐ[R] A ⊗[R] B).range = (Algebra.TensorProduct.map (Subalgebra.center R A).val (AlgHom.id R B)).range := by rw [← centralizer_univ, ← Algebra.coe_top (R := R) (A := A), ← centralizer_coe_map_includeLeft_eq_center_tensorProduct R A B ⊤] ext simp [includeLeft, includeLeftRingHom] /-- Let `R` be a commutative ring and `A, B` be `R`-algebras where `A` is free as `R`-module. Then the centralizer of `1 ⊗ B ⊆ A ⊗ B` is `A ⊗ C(B)` where `C(B)` is the center of `B`. -/ lemma centralizer_range_includeRight_eq_center_tensorProduct [Module.Free R A] : Subalgebra.centralizer R (Algebra.TensorProduct.includeRight : B →ₐ[R] A ⊗[R] B).range = (Algebra.TensorProduct.map (AlgHom.id R A) (center R B).val).range := by rw [← centralizer_univ, ← Algebra.coe_top (R := R) (A := B), ← centralizer_coe_map_includeRight_eq_center_tensorProduct R A B ⊤] ext simp [includeRight] lemma centralizer_tensorProduct_eq_center_tensorProduct_left [Module.Free R B] : Subalgebra.centralizer R (Algebra.TensorProduct.map (AlgHom.id R A) (Algebra.ofId R B)).range = (Algebra.TensorProduct.map (Subalgebra.center R A).val (AlgHom.id R B)).range := by rw [← centralizer_coe_range_includeLeft_eq_center_tensorProduct] simp [Algebra.TensorProduct.map_range] lemma centralizer_tensorProduct_eq_center_tensorProduct_right [Module.Free R A] : Subalgebra.centralizer R (Algebra.TensorProduct.map (Algebra.ofId R A) (AlgHom.id R B)).range = (Algebra.TensorProduct.map (AlgHom.id R A) (center R B).val).range := by rw [← centralizer_range_includeRight_eq_center_tensorProduct] simp [Algebra.TensorProduct.map_range] end Free end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Unitization.lean
import Mathlib.Algebra.Algebra.Unitization import Mathlib.Algebra.Star.Subalgebra import Mathlib.GroupTheory.GroupAction.Ring /-! # Relating unital and non-unital substructures This file relates various algebraic structures and provides maps (generally algebra homomorphisms), from the unitization of a non-unital subobject into the full structure. The range of this map is the unital closure of the non-unital subobject (e.g., `Algebra.adjoin`, `Subring.closure`, `Subsemiring.closure` or `StarAlgebra.adjoin`). When the underlying scalar ring is a field, for this map to be injective it suffices that the range omits `1`. In this setting we provide suitable `AlgEquiv` (or `StarAlgEquiv`) onto the range. ## Main declarations * `NonUnitalSubalgebra.unitization s : Unitization R s →ₐ[R] A`: where `s` is a non-unital subalgebra of a unital `R`-algebra `A`, this is the natural algebra homomorphism sending `(r, a)` to `r • 1 + a`. The range of this map is `Algebra.adjoin R (s : Set A)`. * `NonUnitalSubalgebra.unitizationAlgEquiv s : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A)` when `R` is a field and `1 ∉ s`. This is `NonUnitalSubalgebra.unitization` upgraded to an `AlgEquiv` onto its range. * `NonUnitalSubsemiring.unitization : Unitization ℕ s →ₐ[ℕ] R`: the natural `ℕ`-algebra homomorphism from the unitization of a non-unital subsemiring `s` into the ring containing it. The range of this map is `subalgebraOfSubsemiring (Subsemiring.closure s)`. This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because there is an instance Lean can't find on its own due to `outParam`. * `NonUnitalSubring.unitization : Unitization ℤ s →ₐ[ℤ] R`: the natural `ℤ`-algebra homomorphism from the unitization of a non-unital subring `s` into the ring containing it. The range of this map is `subalgebraOfSubring (Subring.closure s)`. This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because there is an instance Lean can't find on its own due to `outParam`. * `NonUnitalStarSubalgebra s : Unitization R s →⋆ₐ[R] A`: a version of `NonUnitalSubalgebra.unitization` for star algebras. * `NonUnitalStarSubalgebra.unitizationStarAlgEquiv s :` `Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A)`: a version of `NonUnitalSubalgebra.unitizationAlgEquiv` for star algebras. -/ /-! ## Subalgebras -/ namespace Unitization variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [Semiring C] [Algebra R C] theorem lift_range_le {f : A →ₙₐ[R] C} {S : Subalgebra R C} : (lift f).range ≤ S ↔ NonUnitalAlgHom.range f ≤ S.toNonUnitalSubalgebra := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rintro - ⟨x, rfl⟩ exact @h (f x) ⟨x, by simp⟩ · rintro - ⟨x, rfl⟩ induction x with | _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩) theorem lift_range (f : A →ₙₐ[R] C) : (lift f).range = Algebra.adjoin R (NonUnitalAlgHom.range f : Set C) := eq_of_forall_ge_iff fun c ↦ by rw [lift_range_le, Algebra.adjoin_le_iff]; rfl end Unitization namespace NonUnitalSubalgebra section Semiring variable {R S A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A] (s : S) /-- The natural `R`-algebra homomorphism from the unitization of a non-unital subalgebra into the algebra containing it. -/ def unitization : Unitization R s →ₐ[R] A := Unitization.lift (NonUnitalSubalgebraClass.subtype s) @[simp] theorem unitization_apply (x : Unitization R s) : unitization s x = algebraMap R A x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = Algebra.adjoin R (s : Set A) := by rw [unitization, Unitization.lift_range] simp end Semiring /-- A sufficient condition for injectivity of `NonUnitalSubalgebra.unitization` when the scalars are a commutative ring. When the scalars are a field, one should use the more natural `NonUnitalStarSubalgebra.unitization_injective` whose hypothesis is easier to verify. -/ theorem _root_.AlgHomClass.unitization_injective' {F R S A : Type*} [CommRing R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) (h : ∀ r, r ≠ 0 → algebraMap R A r ∉ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A] (f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by refine (injective_iff_map_eq_zero f).mpr fun x hx => ?_ induction x with | inl_add_inr r a => simp_rw [map_add, hf, ← Unitization.algebraMap_eq_inl, AlgHomClass.commutes] at hx rw [add_eq_zero_iff_eq_neg] at hx ⊢ by_cases hr : r = 0 · ext · simp [hr] · simpa [hr] using hx · exact (h r hr <| hx ▸ (neg_mem a.property)).elim /-- This is a generic version which allows us to prove both `NonUnitalSubalgebra.unitization_injective` and `NonUnitalStarSubalgebra.unitization_injective`. -/ theorem _root_.AlgHomClass.unitization_injective {F R S A : Type*} [Field R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) (h1 : 1 ∉ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A] (f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by refine AlgHomClass.unitization_injective' s (fun r hr hr' ↦ ?_) f hf rw [Algebra.algebraMap_eq_smul_one] at hr' exact h1 <| inv_smul_smul₀ hr (1 : A) ▸ SMulMemClass.smul_mem r⁻¹ hr' section Field variable {R S A : Type*} [Field R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) theorem unitization_injective (h1 : (1 : A) ∉ s) : Function.Injective (unitization s) := AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp /-- If a `NonUnitalSubalgebra` over a field does not contain `1`, then its unitization is isomorphic to its `Algebra.adjoin`. -/ @[simps! apply_coe] noncomputable def unitizationAlgEquiv (h1 : (1 : A) ∉ s) : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A) := let algHom : Unitization R s →ₐ[R] Algebra.adjoin R (s : Set A) := ((unitization s).codRestrict _ fun x ↦ (unitization_range s).le <| AlgHom.mem_range_self _ x) AlgEquiv.ofBijective algHom <| by refine ⟨?_, fun x ↦ ?_⟩ · have := AlgHomClass.unitization_injective s h1 ((Subalgebra.val _).comp algHom) fun _ ↦ by simp [algHom] rw [AlgHom.coe_comp] at this exact this.of_comp · obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) := (unitization_range s).ge x.property exact ⟨a, Subtype.ext ha⟩ end Field end NonUnitalSubalgebra /-! ## Subsemirings -/ namespace NonUnitalSubsemiring variable {R S : Type*} [Semiring R] [SetLike S R] [hSR : NonUnitalSubsemiringClass S R] (s : S) /-- The natural `ℕ`-algebra homomorphism from the unitization of a non-unital subsemiring to its `Subsemiring.closure`. -/ def unitization : Unitization ℕ s →ₐ[ℕ] R := NonUnitalSubalgebra.unitization (hSRA := AddSubmonoidClass.nsmulMemClass) s @[simp] theorem unitization_apply (x : Unitization ℕ s) : unitization s x = x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = subalgebraOfSubsemiring (.closure s) := by have := AddSubmonoidClass.nsmulMemClass (S := S) rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_nat] end NonUnitalSubsemiring /-! ## Subrings -/ namespace NonUnitalSubring variable {R S : Type*} [Ring R] [SetLike S R] [hSR : NonUnitalSubringClass S R] (s : S) /-- The natural `ℤ`-algebra homomorphism from the unitization of a non-unital subring to its `Subring.closure`. -/ def unitization : Unitization ℤ s →ₐ[ℤ] R := NonUnitalSubalgebra.unitization (hSRA := AddSubgroupClass.zsmulMemClass) s @[simp] theorem unitization_apply (x : Unitization ℤ s) : unitization s x = x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = subalgebraOfSubring (.closure s) := by have := AddSubgroupClass.zsmulMemClass (S := S) rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_int] end NonUnitalSubring /-! ## Star subalgebras -/ namespace Unitization variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A] [StarRing R] [StarRing A] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [StarModule R A] variable [Semiring C] [StarRing C] [Algebra R C] [StarModule R C] theorem starLift_range_le {f : A →⋆ₙₐ[R] C} {S : StarSubalgebra R C} : (starLift f).range ≤ S ↔ NonUnitalStarAlgHom.range f ≤ S.toNonUnitalStarSubalgebra := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rintro - ⟨x, rfl⟩ exact @h (f x) ⟨x, by simp⟩ · rintro - ⟨x, rfl⟩ induction x with | _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩) theorem starLift_range (f : A →⋆ₙₐ[R] C) : (starLift f).range = StarAlgebra.adjoin R (NonUnitalStarAlgHom.range f : Set C) := eq_of_forall_ge_iff fun c ↦ by rw [starLift_range_le, StarAlgebra.adjoin_le_iff] rfl end Unitization namespace NonUnitalStarSubalgebra section Semiring variable {R S A : Type*} [CommSemiring R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] [SetLike S A] [hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A] [StarMemClass S A] (s : S) /-- The natural star `R`-algebra homomorphism from the unitization of a non-unital star subalgebra to its `StarAlgebra.adjoin`. -/ def unitization : Unitization R s →⋆ₐ[R] A := Unitization.starLift <| NonUnitalStarSubalgebraClass.subtype s @[simp] theorem unitization_apply (x : Unitization R s) : unitization s x = algebraMap R A x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = StarAlgebra.adjoin R s := by rw [unitization, Unitization.starLift_range] simp only [NonUnitalStarAlgHom.coe_range, NonUnitalStarSubalgebraClass.coe_subtype, Subtype.range_coe_subtype] rfl end Semiring section Field variable {R S A : Type*} [Field R] [StarRing R] [Ring A] [StarRing A] [Algebra R A] [StarModule R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] [StarMemClass S A] (s : S) theorem unitization_injective (h1 : (1 : A) ∉ s) : Function.Injective (unitization s) := AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp /-- If a `NonUnitalStarSubalgebra` over a field does not contain `1`, then its unitization is isomorphic to its `StarAlgebra.adjoin`. -/ @[simps! apply_coe] noncomputable def unitizationStarAlgEquiv (h1 : (1 : A) ∉ s) : Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A) := let starAlgHom : Unitization R s →⋆ₐ[R] StarAlgebra.adjoin R (s : Set A) := ((unitization s).codRestrict _ fun x ↦ (unitization_range s).le <| Set.mem_range_self x) StarAlgEquiv.ofBijective starAlgHom <| by refine ⟨?_, fun x ↦ ?_⟩ · have := AlgHomClass.unitization_injective s h1 ((StarSubalgebra.subtype _).comp starAlgHom) fun _ ↦ by simp [starAlgHom] rw [StarAlgHom.coe_comp] at this exact this.of_comp · obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) := (unitization_range s).ge x.property exact ⟨a, Subtype.ext ha⟩ end Field end NonUnitalStarSubalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Directed.lean
import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Data.Set.UnionLift /-! # Subalgebras and directed Unions of sets ## Main results * `Subalgebra.coe_iSup_of_directed`: a directed supremum consists of the union of the algebras * `Subalgebra.iSupLift`: define an algebra homomorphism on a directed supremum of subalgebras by defining it on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/ namespace Subalgebra open Algebra variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable (S : Subalgebra R A) variable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} theorem coe_iSup_of_directed (dir : Directed (· ≤ ·) K) : ↑(iSup K) = ⋃ i, (K i : Set A) := let s : Subalgebra R A := { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2 ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ } have : iSup K = s := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _) this.symm ▸ rfl variable (K) -- TODO: turn `hT` into an assumption `T ≤ iSup K`. That's what `Set.iUnionLift` needs /-- Define an algebra homomorphism on a directed supremum of subalgebras by defining it on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/ noncomputable def iSupLift (dir : Directed (· ≤ ·) K) (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)) (T : Subalgebra R A) (hT : T = iSup K) : ↥T →ₐ[R] B := { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x) (fun i j x hxi hxj => by let ⟨k, hik, hjk⟩ := dir i j dsimp rw [hf i k hik, hf j k hjk] rfl) (T : Set A) (by rw [hT, coe_iSup_of_directed dir]) map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp map_zero' := by apply Set.iUnionLift_const _ (fun _ => 0) <;> simp map_mul' := by subst hT; apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·)) <;> simp map_add' := by subst hT; apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·)) <;> simp commutes' := fun r => by apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp } @[simp] theorem iSupLift_inclusion {dir : Directed (· ≤ ·) K} {f : ∀ i, K i →ₐ[R] B} {hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)} {T : Subalgebra R A} {hT : T = iSup K} {i : ι} (x : K i) (h : K i ≤ T) : iSupLift K dir f hf T hT (inclusion h x) = f i x := by dsimp [iSupLift, inclusion] rw [Set.iUnionLift_inclusion] @[simp] theorem iSupLift_comp_inclusion {dir : Directed (· ≤ ·) K} {f : ∀ i, K i →ₐ[R] B} {hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)} {T : Subalgebra R A} {hT : T = iSup K} {i : ι} (h : K i ≤ T) : (iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp @[simp] theorem iSupLift_mk {dir : Directed (· ≤ ·) K} {f : ∀ i, K i →ₐ[R] B} {hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)} {T : Subalgebra R A} {hT : T = iSup K} {i : ι} (x : K i) (hx : (x : A) ∈ T) : iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by dsimp [iSupLift, inclusion] rw [Set.iUnionLift_mk] theorem iSupLift_of_mem {dir : Directed (· ≤ ·) K} {f : ∀ i, K i →ₐ[R] B} {hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)} {T : Subalgebra R A} {hT : T = iSup K} {i : ι} (x : T) (hx : (x : A) ∈ K i) : iSupLift K dir f hf T hT x = f i ⟨x, hx⟩ := by dsimp [iSupLift, inclusion] rw [Set.iUnionLift_of_mem] end Subalgebra
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Subalgebra/Lattice.lean
import Mathlib.Algebra.Algebra.Operations import Mathlib.Algebra.Algebra.Subalgebra.Basic /-! # Complete lattice structure of subalgebras In this file we define `Algebra.adjoin` and the complete lattice structure on subalgebras. More lemmas about `adjoin` can be found in `Mathlib/RingTheory/Adjoin/Basic.lean`. -/ assert_not_exists Polynomial universe u u' v w w' namespace Algebra variable (R : Type u) {A : Type v} {B : Type w} variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] /-- The minimal subalgebra that includes `s`. -/ @[simps toSubsemiring] def adjoin (s : Set A) : Subalgebra R A := { Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ } variable {R} protected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S => ⟨fun H => le_trans (le_trans Set.subset_union_right Subsemiring.subset_closure) H, fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩ /-- Galois insertion between `adjoin` and `coe`. -/ protected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs gc := Algebra.gc le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl choice_eq _ _ := Subalgebra.copy_eq _ _ _ instance : CompleteLattice (Subalgebra R A) where __ := GaloisInsertion.liftCompleteLattice Algebra.gi bot := (Algebra.ofId R A).range bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _ instance {C : Type*} [CommSemiring C] [Algebra R C] (S₁ S₂ : Subalgebra R C) : Algebra ↑(min S₁ S₂) S₁ := RingHom.toAlgebra (Subalgebra.inclusion inf_le_left).toRingHom instance {C : Type*} [CommSemiring C] [Algebra R C] (S₁ S₂ : Subalgebra R C) : Algebra ↑(S₁ ⊓ S₂) S₂ := RingHom.toAlgebra (Subalgebra.inclusion inf_le_right).toRingHom theorem sup_def (S T : Subalgebra R A) : S ⊔ T = adjoin R (S ∪ T : Set A) := rfl theorem sSup_def (S : Set (Subalgebra R A)) : sSup S = adjoin R (⋃₀ (SetLike.coe '' S)) := rfl @[simp, norm_cast] theorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl @[simp] theorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x @[simp] theorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl @[simp] theorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl @[simp] theorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] : (⊤ : Subalgebra R A).toSubring = ⊤ := rfl @[simp] theorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ := Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule @[simp] theorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ := Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring @[simp] theorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} : S.toSubring = ⊤ ↔ S = ⊤ := Subalgebra.toSubring_injective.eq_iff' top_toSubring theorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := have : S ≤ S ⊔ T := le_sup_left; (this ·) theorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := have : T ≤ S ⊔ T := le_sup_right; (this ·) theorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy) theorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f := (Subalgebra.gc_map_comap f).l_sup theorem map_inf (f : A →ₐ[R] B) (hf : Function.Injective f) (S T : Subalgebra R A) : (S ⊓ T).map f = S.map f ⊓ T.map f := SetLike.coe_injective (Set.image_inter hf) @[simp, norm_cast] theorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl @[simp] theorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl open Subalgebra in @[simp] theorem inf_toSubmodule (S T : Subalgebra R A) : toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl @[simp] theorem inf_toSubsemiring (S T : Subalgebra R A) : (S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring := rfl @[simp] theorem sup_toSubsemiring (S T : Subalgebra R A) : (S ⊔ T).toSubsemiring = S.toSubsemiring ⊔ T.toSubsemiring := by rw [← S.toSubsemiring.closure_eq, ← T.toSubsemiring.closure_eq, ← Subsemiring.closure_union] simp_rw [sup_def, adjoin_toSubsemiring, Subalgebra.coe_toSubsemiring] congr 1 rw [Set.union_eq_right] rintro _ ⟨x, rfl⟩ exact Set.mem_union_left _ (algebraMap_mem S x) @[simp, norm_cast] theorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s := sInf_image theorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂] @[simp] theorem sInf_toSubmodule (S : Set (Subalgebra R A)) : Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) := SetLike.coe_injective <| by simp @[simp] theorem sInf_toSubsemiring (S : Set (Subalgebra R A)) : (sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) := SetLike.coe_injective <| by simp open Subalgebra in @[simp] theorem sSup_toSubsemiring (S : Set (Subalgebra R A)) (hS : S.Nonempty) : (sSup S).toSubsemiring = sSup (toSubsemiring '' S) := by have h : toSubsemiring '' S = Subsemiring.closure '' (SetLike.coe '' S) := by rw [Set.image_image] congr! with x exact x.toSubsemiring.closure_eq.symm rw [h, sSup_image, ← Subsemiring.closure_sUnion, sSup_def, adjoin_toSubsemiring] congr 1 rw [Set.union_eq_right] rintro _ ⟨x, rfl⟩ obtain ⟨y, hy⟩ := hS simp only [Set.mem_sUnion, Set.mem_image, exists_exists_and_eq_and, SetLike.mem_coe] exact ⟨y, hy, algebraMap_mem y x⟩ @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by simp [iInf] theorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] theorem map_iInf {ι : Sort*} [Nonempty ι] (f : A →ₐ[R] B) (hf : Function.Injective f) (s : ι → Subalgebra R A) : (iInf s).map f = ⨅ (i : ι), (s i).map f := by apply SetLike.coe_injective simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s) open Subalgebra in @[simp] theorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) : toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) := SetLike.coe_injective <| by simp @[simp] theorem iInf_toSubsemiring {ι : Sort*} (S : ι → Subalgebra R A) : (iInf S).toSubsemiring = ⨅ i, (S i).toSubsemiring := by simp only [iInf, sInf_toSubsemiring, ← Set.range_comp, Function.comp_def] @[simp] theorem iSup_toSubsemiring {ι : Sort*} [Nonempty ι] (S : ι → Subalgebra R A) : (iSup S).toSubsemiring = ⨆ i, (S i).toSubsemiring := by simp only [iSup, Set.range_nonempty, sSup_toSubsemiring, ← Set.range_comp, Function.comp_def] lemma mem_iSup_of_mem {ι : Sort*} {S : ι → Subalgebra R A} (i : ι) {x : A} (hx : x ∈ S i) : x ∈ iSup S := le_iSup S i hx @[elab_as_elim] lemma iSup_induction {ι : Sort*} (S : ι → Subalgebra R A) {motive : A → Prop} {x : A} (mem : x ∈ ⨆ i, S i) (basic : ∀ i, ∀ a ∈ S i, motive a) (zero : motive 0) (one : motive 1) (add : ∀ a b, motive a → motive b → motive (a + b)) (mul : ∀ a b, motive a → motive b → motive (a * b)) (algebraMap : ∀ r, motive (algebraMap R A r)) : motive x := by let T : Subalgebra R A := { carrier := {x | motive x} mul_mem' {a b} := mul a b one_mem' := one add_mem' {a b} := add a b zero_mem' := zero algebraMap_mem' := algebraMap } suffices iSup S ≤ T from this mem rwa [iSup_le_iff] /-- A dependent version of `Subalgebra.iSup_induction`. -/ @[elab_as_elim] theorem iSup_induction' {ι : Sort*} (S : ι → Subalgebra R A) {motive : ∀ x, (x ∈ ⨆ i, S i) → Prop} {x : A} (mem : x ∈ ⨆ i, S i) (basic : ∀ (i) (x) (hx : x ∈ S i), motive x (mem_iSup_of_mem i hx)) (zero : motive 0 (zero_mem _)) (one : motive 1 (one_mem _)) (add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›)) (mul : ∀ x y hx hy, motive x hx → motive y hy → motive (x * y) (mul_mem ‹_› ‹_›)) (algebraMap : ∀ r, motive (algebraMap R A r) (Subalgebra.algebraMap_mem _ ‹_›)) : motive x mem := by refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, S i) (hc : motive x hx) ↦ hc exact iSup_induction S (motive := fun x' ↦ ∃ h, motive x' h) mem (fun _ _ h ↦ ⟨_, basic _ _ h⟩) ⟨_, zero⟩ ⟨_, one⟩ (fun _ _ h h' ↦ ⟨_, add _ _ _ _ h.2 h'.2⟩) (fun _ _ h h' ↦ ⟨_, mul _ _ _ _ h.2 h'.2⟩) fun _ ↦ ⟨_, algebraMap _⟩ instance : Inhabited (Subalgebra R A) := ⟨⊥⟩ theorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl /-- TODO: change proof to `rfl` when fixing https://github.com/leanprover-community/mathlib4/issues/18110. -/ theorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 := Submodule.one_eq_range.symm @[simp, norm_cast] theorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S := ⟨fun h x => by rw [h]; exact mem_top, fun h => by ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩ theorem _root_.AlgHom.range_eq_top (f : A →ₐ[R] B) : f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f := Algebra.eq_top_iff @[simp] theorem range_ofId : (Algebra.ofId R A).range = ⊥ := rfl @[simp] theorem range_id : (AlgHom.id R A).range = ⊤ := SetLike.coe_injective Set.range_id @[simp] theorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range := SetLike.coe_injective Set.image_univ @[simp] theorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ := Subalgebra.toSubmodule_injective <| by simpa only [Subalgebra.map_toSubmodule, toSubmodule_bot] using Submodule.map_one _ @[simp] theorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ := eq_top_iff.2 fun _x => mem_top /-- `AlgHom` to `⊤ : Subalgebra R A`. -/ def toTop : A →ₐ[R] (⊤ : Subalgebra R A) := (AlgHom.id R A).codRestrict ⊤ fun _ => mem_top theorem surjective_algebraMap_iff : Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ := ⟨fun h => eq_bot_iff.2 fun y _ => let ⟨_x, hx⟩ := h y hx ▸ Subalgebra.algebraMap_mem _ _, fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩ theorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A] [Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ := ⟨fun h => surjective_algebraMap_iff.1 h.2, fun h => ⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩ /-- The bottom subalgebra is isomorphic to the base ring. -/ noncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) : (⊥ : Subalgebra R A) ≃ₐ[R] R := AlgEquiv.symm <| AlgEquiv.ofBijective (Algebra.ofId R _) ⟨fun _x _y hxy => h (congr_arg Subtype.val hxy :), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩ /-- The bottom subalgebra is isomorphic to the field. -/ @[simps! symm_apply] noncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] : (⊥ : Subalgebra F R) ≃ₐ[F] F := botEquivOfInjective (RingHom.injective _) end Algebra namespace Subalgebra open Algebra variable {R : Type u} {A : Type v} {B : Type w} variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable (S : Subalgebra R A) /-- The top subalgebra is isomorphic to the algebra. This is the algebra version of `Submodule.topEquiv`. -/ @[simps!] def topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A := AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl rfl instance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) := ⟨fun f g => AlgHom.ext fun a => have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this) hx ▸ (f.commutes _).trans (g.commutes _).symm⟩ instance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] : Subsingleton (A ≃ₐ[R] B) := ⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩ instance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] : Subsingleton (A ≃ₐ[R] B) := ⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩ instance : Unique (Subalgebra R R) := { inferInstanceAs (Inhabited (Subalgebra R R)) with uniq := by intro S refine le_antisymm ?_ bot_le intro _ _ simp only [Set.mem_range, mem_bot, algebraMap_self_apply, exists_apply_eq_apply, default] } section Center variable (R A) @[simp] theorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ := SetLike.coe_injective (Set.center_eq_univ A) end Center section Centralizer variable (R) @[simp] theorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A := SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset end Centralizer end Subalgebra section Equalizer namespace AlgHom variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable {F : Type*} variable [FunLike F A B] [AlgHomClass F R A B] @[simp] theorem equalizer_eq_top {φ ψ : F} : equalizer φ ψ = ⊤ ↔ φ = ψ := by simp [SetLike.ext_iff, DFunLike.ext_iff] @[simp] theorem equalizer_same (φ : F) : equalizer φ φ = ⊤ := equalizer_eq_top.2 rfl theorem eqOn_sup {φ ψ : F} {S T : Subalgebra R A} (hS : Set.EqOn φ ψ S) (hT : Set.EqOn φ ψ T) : Set.EqOn φ ψ ↑(S ⊔ T) := by rw [← le_equalizer] at hS hT ⊢ exact sup_le hS hT theorem ext_on_codisjoint {φ ψ : F} {S T : Subalgebra R A} (hST : Codisjoint S T) (hS : Set.EqOn φ ψ S) (hT : Set.EqOn φ ψ T) : φ = ψ := DFunLike.ext _ _ fun _ ↦ eqOn_sup hS hT <| hST.eq_top.symm ▸ trivial end AlgHom end Equalizer section MapComap namespace Subalgebra variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] theorem map_comap_eq (f : A →ₐ[R] B) (S : Subalgebra R B) : (S.comap f).map f = S ⊓ f.range := SetLike.coe_injective Set.image_preimage_eq_inter_range theorem map_comap_eq_self {f : A →ₐ[R] B} {S : Subalgebra R B} (h : S ≤ f.range) : (S.comap f).map f = S := by simpa only [inf_of_le_left h] using map_comap_eq f S theorem map_comap_eq_self_of_surjective {f : A →ₐ[R] B} (hf : Function.Surjective f) (S : Subalgebra R B) : (S.comap f).map f = S := map_comap_eq_self <| by simp [(AlgHom.range_eq_top f).2 hf] end Subalgebra end MapComap section Adjoin universe uR uS uA uB open Submodule Subsemiring variable {R : Type uR} {S : Type uS} {A : Type uA} {B : Type uB} namespace Algebra section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra S A] [Algebra R B] [IsScalarTower R S A] variable {s t : Set A} @[simp, aesop safe 20 (rule_sets := [SetLike])] theorem subset_adjoin : s ⊆ adjoin R s := Algebra.gc.le_u_l s @[aesop 80% (rule_sets := [SetLike])] theorem mem_adjoin_of_mem {s : Set A} {x : A} (hx : x ∈ s) : x ∈ adjoin R s := subset_adjoin hx theorem adjoin_le {S : Subalgebra R A} (H : s ⊆ S) : adjoin R s ≤ S := Algebra.gc.l_le H theorem adjoin_singleton_le {S : Subalgebra R A} {a : A} (H : a ∈ S) : adjoin R {a} ≤ S := adjoin_le (Set.singleton_subset_iff.mpr H) theorem adjoin_eq_sInf : adjoin R s = sInf { p : Subalgebra R A | s ⊆ p } := le_antisymm (le_sInf fun _ h => adjoin_le h) (sInf_le subset_adjoin) theorem adjoin_le_iff {S : Subalgebra R A} : adjoin R s ≤ S ↔ s ⊆ S := Algebra.gc _ _ @[gcongr] theorem adjoin_mono (H : s ⊆ t) : adjoin R s ≤ adjoin R t := Algebra.gc.monotone_l H theorem adjoin_eq_of_le (S : Subalgebra R A) (h₁ : s ⊆ S) (h₂ : S ≤ adjoin R s) : adjoin R s = S := le_antisymm (adjoin_le h₁) h₂ theorem adjoin_eq (S : Subalgebra R A) : adjoin R ↑S = S := adjoin_eq_of_le _ (Set.Subset.refl _) subset_adjoin theorem adjoin_iUnion {α : Type*} (s : α → Set A) : adjoin R (Set.iUnion s) = ⨆ i : α, adjoin R (s i) := (@Algebra.gc R A _ _ _).l_iSup theorem adjoin_attach_biUnion [DecidableEq A] {α : Type*} {s : Finset α} (f : s → Finset A) : adjoin R (s.attach.biUnion f : Set A) = ⨆ x, adjoin R (f x) := by simp [adjoin_iUnion] @[elab_as_elim] theorem adjoin_induction {p : (x : A) → x ∈ adjoin R s → Prop} (mem : ∀ (x) (hx : x ∈ s), p x (subset_adjoin hx)) (algebraMap : ∀ r, p (algebraMap R A r) (algebraMap_mem _ r)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {x : A} (hx : x ∈ adjoin R s) : p x hx := let S : Subalgebra R A := { carrier := { x | ∃ hx, p x hx } mul_mem' := by rintro _ _ ⟨_, hpx⟩ ⟨_, hpy⟩; exact ⟨_, mul _ _ _ _ hpx hpy⟩ add_mem' := by rintro _ _ ⟨_, hpx⟩ ⟨_, hpy⟩; exact ⟨_, add _ _ _ _ hpx hpy⟩ algebraMap_mem' := fun r ↦ ⟨_, algebraMap r⟩ } adjoin_le (S := S) (fun y hy ↦ ⟨subset_adjoin hy, mem y hy⟩) hx |>.elim fun _ ↦ _root_.id /-- Induction principle for the algebra generated by a set `s`: show that `p x y` holds for any `x y ∈ adjoin R s` given that it holds for `x y ∈ s` and that it satisfies a number of natural properties. -/ @[elab_as_elim] theorem adjoin_induction₂ {s : Set A} {p : (x y : A) → x ∈ adjoin R s → y ∈ adjoin R s → Prop} (mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_adjoin hx) (subset_adjoin hy)) (algebraMap_both : ∀ r₁ r₂, p (algebraMap R A r₁) (algebraMap R A r₂) (algebraMap_mem _ r₁) (algebraMap_mem _ r₂)) (algebraMap_left : ∀ (r) (x) (hx : x ∈ s), p (algebraMap R A r) x (algebraMap_mem _ r) (subset_adjoin hx)) (algebraMap_right : ∀ (r) (x) (hx : x ∈ s), p x (algebraMap R A r) (subset_adjoin hx) (algebraMap_mem _ r)) (add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz) (add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz)) (mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz) (mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz)) {x y : A} (hx : x ∈ adjoin R s) (hy : y ∈ adjoin R s) : p x y hx hy := by induction hy using adjoin_induction with | mem z hz => induction hx using adjoin_induction with | mem _ h => exact mem_mem _ _ h hz | algebraMap _ => exact algebraMap_left _ _ hz | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | algebraMap r => induction hx using adjoin_induction with | mem _ h => exact algebraMap_right _ _ h | algebraMap _ => exact algebraMap_both _ _ | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂ @[simp] theorem adjoin_adjoin_coe_preimage {s : Set A} : adjoin R (((↑) : adjoin R s → A) ⁻¹' s) = ⊤ := by refine eq_top_iff.2 fun ⟨x, hx⟩ ↦ adjoin_induction (fun a ha ↦ ?_) (fun r ↦ ?_) (fun _ _ _ _ ↦ ?_) (fun _ _ _ _ ↦ ?_) hx · exact subset_adjoin ha · exact Subalgebra.algebraMap_mem _ r · exact Subalgebra.add_mem _ · exact Subalgebra.mul_mem _ theorem adjoin_union (s t : Set A) : adjoin R (s ∪ t) = adjoin R s ⊔ adjoin R t := (Algebra.gc : GaloisConnection _ ((↑) : Subalgebra R A → Set A)).l_sup variable (R A) @[simp] theorem adjoin_empty : adjoin R (∅ : Set A) = ⊥ := Algebra.gc.l_bot @[simp] theorem adjoin_univ : adjoin R (Set.univ : Set A) = ⊤ := Algebra.gi.l_top variable {R} in @[simp] theorem adjoin_singleton_algebraMap (x : R) : adjoin R {algebraMap R A x} = ⊥ := bot_unique <| adjoin_singleton_le <| Subalgebra.algebraMap_mem _ _ @[simp] theorem adjoin_singleton_natCast (n : ℕ) : adjoin R {(n : A)} = ⊥ := by simpa using adjoin_singleton_algebraMap A (n : R) @[simp] theorem adjoin_singleton_zero : adjoin R ({0} : Set A) = ⊥ := mod_cast adjoin_singleton_natCast R A 0 @[simp] theorem adjoin_singleton_one : adjoin R ({1} : Set A) = ⊥ := mod_cast adjoin_singleton_natCast R A 1 variable {A} (s) variable {R} in @[simp] theorem adjoin_insert_algebraMap (x : R) (s : Set A) : adjoin R (insert (algebraMap R A x) s) = adjoin R s := by rw [Set.insert_eq, adjoin_union] simp @[simp] theorem adjoin_insert_natCast (n : ℕ) (s : Set A) : adjoin R (insert (n : A) s) = adjoin R s := mod_cast adjoin_insert_algebraMap (n : R) s @[simp] theorem adjoin_insert_zero (s : Set A) : adjoin R (insert 0 s) = adjoin R s := mod_cast adjoin_insert_natCast R 0 s @[simp] theorem adjoin_insert_one (s : Set A) : adjoin R (insert 1 s) = adjoin R s := mod_cast adjoin_insert_natCast R 1 s theorem adjoin_eq_span : Subalgebra.toSubmodule (adjoin R s) = span R (Submonoid.closure s) := by apply le_antisymm · intro r hr rcases Subsemiring.mem_closure_iff_exists_list.1 hr with ⟨L, HL, rfl⟩ clear hr induction L with | nil => exact zero_mem _ | cons hd tl ih => ?_ rw [List.forall_mem_cons] at HL rw [List.map_cons, List.sum_cons] refine Submodule.add_mem _ ?_ (ih HL.2) replace HL := HL.1 clear ih tl suffices ∃ (z r : _) (_hr : r ∈ Submonoid.closure s), z • r = List.prod hd by rcases this with ⟨z, r, hr, hzr⟩ rw [← hzr] exact smul_mem _ _ (subset_span hr) induction hd with | nil => exact ⟨1, 1, (Submonoid.closure s).one_mem', one_smul _ _⟩ | cons hd tl ih => ?_ rw [List.forall_mem_cons] at HL rcases ih HL.2 with ⟨z, r, hr, hzr⟩ rw [List.prod_cons, ← hzr] rcases HL.1 with (⟨hd, rfl⟩ | hs) · refine ⟨hd * z, r, hr, ?_⟩ rw [Algebra.smul_def, Algebra.smul_def, (algebraMap _ _).map_mul, _root_.mul_assoc] · exact ⟨z, hd * r, Submonoid.mul_mem _ (Submonoid.subset_closure hs) hr, (mul_smul_comm _ _ _).symm⟩ refine span_le.2 ?_ change Submonoid.closure s ≤ (adjoin R s).toSubsemiring.toSubmonoid exact Submonoid.closure_le.2 subset_adjoin theorem span_le_adjoin (s : Set A) : span R s ≤ Subalgebra.toSubmodule (adjoin R s) := span_le.mpr subset_adjoin theorem adjoin_toSubmodule_le {s : Set A} {t : Submodule R A} : Subalgebra.toSubmodule (adjoin R s) ≤ t ↔ ↑(Submonoid.closure s) ⊆ (t : Set A) := by rw [adjoin_eq_span, span_le] theorem adjoin_eq_span_of_subset {s : Set A} (hs : ↑(Submonoid.closure s) ⊆ (span R s : Set A)) : Subalgebra.toSubmodule (adjoin R s) = span R s := le_antisymm ((adjoin_toSubmodule_le R).mpr hs) (span_le_adjoin R s) @[simp] theorem adjoin_span {s : Set A} : adjoin R (Submodule.span R s : Set A) = adjoin R s := le_antisymm (adjoin_le (span_le_adjoin _ _)) (adjoin_mono Submodule.subset_span) theorem adjoin_image (f : A →ₐ[R] B) (s : Set A) : adjoin R (f '' s) = (adjoin R s).map f := le_antisymm (adjoin_le <| Set.image_mono subset_adjoin) <| Subalgebra.map_le.2 <| adjoin_le <| Set.image_subset_iff.1 <| by simp only [Set.image_id', coe_carrier_toSubmonoid, Subalgebra.coe_toSubsemiring, Subalgebra.coe_comap] exact fun x hx => subset_adjoin ⟨x, hx, rfl⟩ @[simp] theorem adjoin_insert_adjoin (x : A) : adjoin R (insert x ↑(adjoin R s)) = adjoin R (insert x s) := le_antisymm (adjoin_le (Set.insert_subset_iff.mpr ⟨subset_adjoin (Set.mem_insert _ _), adjoin_mono (Set.subset_insert _ _)⟩)) (Algebra.adjoin_mono (Set.insert_subset_insert Algebra.subset_adjoin)) theorem mem_adjoin_of_map_mul {s} {x : A} {f : A →ₗ[R] B} (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) (h : x ∈ adjoin R s) : f x ∈ adjoin R (f '' (s ∪ {1})) := by induction h using adjoin_induction with | mem a ha => exact subset_adjoin ⟨a, ⟨Set.subset_union_left ha, rfl⟩⟩ | algebraMap r => have : f 1 ∈ adjoin R (f '' (s ∪ {1})) := subset_adjoin ⟨1, ⟨Set.subset_union_right <| Set.mem_singleton 1, rfl⟩⟩ convert Subalgebra.smul_mem (adjoin R (f '' (s ∪ {1}))) this r rw [algebraMap_eq_smul_one] exact f.map_smul _ _ | add y z _ _ hy hz => simpa [hy, hz] using Subalgebra.add_mem _ hy hz | mul y z _ _ hy hz => simpa [hf, hy, hz] using Subalgebra.mul_mem _ hy hz lemma adjoin_le_centralizer_centralizer (s : Set A) : adjoin R s ≤ Subalgebra.centralizer R (Subalgebra.centralizer R s) := adjoin_le Set.subset_centralizer_centralizer /-- If all elements of `s : Set A` commute pairwise, then `adjoin s` is a commutative semiring. -/ abbrev adjoinCommSemiringOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : CommSemiring (adjoin R s) := { (adjoin R s).toSemiring with mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦ have := adjoin_le_centralizer_centralizer R s Subtype.ext <| Set.centralizer_centralizer_comm_of_comm hcomm _ (this h₁) _ (this h₂) } variable {R} lemma commute_of_mem_adjoin_of_forall_mem_commute {a b : A} {s : Set A} (hb : b ∈ adjoin R s) (h : ∀ b ∈ s, Commute a b) : Commute a b := by induction hb using adjoin_induction with | mem x hx => exact h x hx | algebraMap r => exact commutes r a |>.symm | add y z _ _ hy hz => exact hy.add_right hz | mul y z _ _ hy hz => exact hy.mul_right hz lemma commute_of_mem_adjoin_singleton_of_commute {a b c : A} (hc : c ∈ adjoin R {b}) (h : Commute a b) : Commute a c := commute_of_mem_adjoin_of_forall_mem_commute hc <| by simpa lemma commute_of_mem_adjoin_self {a b : A} (hb : b ∈ adjoin R {a}) : Commute a b := commute_of_mem_adjoin_singleton_of_commute hb rfl variable (R) theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := Algebra.subset_adjoin (Set.mem_singleton_iff.mpr rfl) end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring A] variable [Algebra R A] {s t : Set A} variable (R s t) theorem adjoin_union_coe_submodule : Subalgebra.toSubmodule (adjoin R (s ∪ t)) = Subalgebra.toSubmodule (adjoin R s) * Subalgebra.toSubmodule (adjoin R t) := by rw [adjoin_eq_span, adjoin_eq_span, adjoin_eq_span, span_mul_span] congr 1 with z; simp [Submonoid.closure_union, Submonoid.mem_sup, Set.mem_mul] end CommSemiring section Ring variable [CommRing R] [Ring A] variable [Algebra R A] {s t : Set A} @[simp] theorem adjoin_singleton_intCast (n : ℤ) : adjoin R {(n : A)} = ⊥ := by simpa using adjoin_singleton_algebraMap A (n : R) @[simp] theorem adjoin_insert_intCast (n : ℤ) (s : Set A) : adjoin R (insert (n : A) s) = adjoin R s := by simpa using adjoin_insert_algebraMap (n : R) s theorem adjoin_eq_ring_closure (s : Set A) : (adjoin R s).toSubring = Subring.closure (Set.range (algebraMap R A) ∪ s) := .symm <| Subring.closure_eq_of_le (by simp [adjoin]) fun x hx => Subsemiring.closure_induction Subring.subset_closure (Subring.zero_mem _) (Subring.one_mem _) (fun _ _ _ _ => Subring.add_mem _) (fun _ _ _ _ => Subring.mul_mem _) hx theorem mem_adjoin_iff {s : Set A} {x : A} : x ∈ adjoin R s ↔ x ∈ Subring.closure (Set.range (algebraMap R A) ∪ s) := by rw [← Subalgebra.mem_toSubring, adjoin_eq_ring_closure] variable (R) /-- If all elements of `s : Set A` commute pairwise, then `adjoin R s` is a commutative ring. -/ abbrev adjoinCommRingOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : CommRing (adjoin R s) := { (adjoin R s).toRing, adjoinCommSemiringOfComm R hcomm with } end Ring end Algebra open Algebra Subalgebra namespace AlgHom variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] theorem map_adjoin (φ : A →ₐ[R] B) (s : Set A) : (adjoin R s).map φ = adjoin R (φ '' s) := (adjoin_image _ _ _).symm @[simp] theorem map_adjoin_singleton (e : A →ₐ[R] B) (x : A) : (adjoin R {x}).map e = adjoin R {e x} := by rw [map_adjoin, Set.image_singleton] theorem adjoin_le_equalizer (φ₁ φ₂ : A →ₐ[R] B) {s : Set A} (h : s.EqOn φ₁ φ₂) : adjoin R s ≤ equalizer φ₁ φ₂ := adjoin_le h theorem ext_of_adjoin_eq_top {s : Set A} (h : adjoin R s = ⊤) ⦃φ₁ φ₂ : A →ₐ[R] B⦄ (hs : s.EqOn φ₁ φ₂) : φ₁ = φ₂ := ext fun _x => adjoin_le_equalizer φ₁ φ₂ hs <| h.symm ▸ trivial /-- Two algebra morphisms are equal on `Algebra.span s`iff they are equal on s -/ theorem eqOn_adjoin_iff {φ ψ : A →ₐ[R] B} {s : Set A} : Set.EqOn φ ψ (adjoin R s) ↔ Set.EqOn φ ψ s := by have (S : Set A) : S ≤ equalizer φ ψ ↔ Set.EqOn φ ψ S := Iff.rfl simp only [← this, Set.le_eq_subset, SetLike.coe_subset_coe, adjoin_le_iff] theorem adjoin_ext {s : Set A} ⦃φ₁ φ₂ : adjoin R s →ₐ[R] B⦄ (h : ∀ x hx, φ₁ ⟨x, subset_adjoin hx⟩ = φ₂ ⟨x, subset_adjoin hx⟩) : φ₁ = φ₂ := ext fun ⟨x, hx⟩ ↦ adjoin_induction h (fun _ ↦ φ₂.commutes _ ▸ φ₁.commutes _) (fun _ _ _ _ h₁ h₂ ↦ by convert congr_arg₂ (· + ·) h₁ h₂ <;> rw [← map_add] <;> rfl) (fun _ _ _ _ h₁ h₂ ↦ by convert congr_arg₂ (· * ·) h₁ h₂ <;> rw [← map_mul] <;> rfl) hx theorem ext_of_eq_adjoin {S : Subalgebra R A} {s : Set A} (hS : S = adjoin R s) ⦃φ₁ φ₂ : S →ₐ[R] B⦄ (h : ∀ x hx, φ₁ ⟨x, hS.ge (subset_adjoin hx)⟩ = φ₂ ⟨x, hS.ge (subset_adjoin hx)⟩) : φ₁ = φ₂ := by subst hS; exact adjoin_ext h end AlgHom section NatInt theorem Algebra.adjoin_nat {R : Type*} [Semiring R] (s : Set R) : adjoin ℕ s = subalgebraOfSubsemiring (Subsemiring.closure s) := le_antisymm (adjoin_le Subsemiring.subset_closure) (Subsemiring.closure_le.2 subset_adjoin : Subsemiring.closure s ≤ (adjoin ℕ s).toSubsemiring) theorem Algebra.adjoin_int {R : Type*} [Ring R] (s : Set R) : adjoin ℤ s = subalgebraOfSubring (Subring.closure s) := le_antisymm (adjoin_le Subring.subset_closure) (Subring.closure_le.2 subset_adjoin : Subring.closure s ≤ (adjoin ℤ s).toSubring) /-- The `ℕ`-algebra equivalence between `Subsemiring.closure s` and `Algebra.adjoin ℕ s` given by the identity map. -/ def Subsemiring.closureEquivAdjoinNat {R : Type*} [Semiring R] (s : Set R) : Subsemiring.closure s ≃ₐ[ℕ] Algebra.adjoin ℕ s := Subalgebra.equivOfEq (subalgebraOfSubsemiring <| Subsemiring.closure s) _ (adjoin_nat s).symm /-- The `ℤ`-algebra equivalence between `Subring.closure s` and `Algebra.adjoin ℤ s` given by the identity map. -/ def Subring.closureEquivAdjoinInt {R : Type*} [Ring R] (s : Set R) : Subring.closure s ≃ₐ[ℤ] Algebra.adjoin ℤ s := Subalgebra.equivOfEq (subalgebraOfSubring <| Subring.closure s) _ (adjoin_int s).symm end NatInt section variable (F E : Type*) {K : Type*} [CommSemiring E] [Semiring K] [SMul F E] [Algebra E K] /-- If `K / E / F` is a ring extension tower, `L` is a submonoid of `K / F` which is generated by `S` as an `F`-module, then `E[L]` is generated by `S` as an `E`-module. -/ theorem Submonoid.adjoin_eq_span_of_eq_span [Semiring F] [Module F K] [IsScalarTower F E K] (L : Submonoid K) {S : Set K} (h : (L : Set K) = span F S) : toSubmodule (adjoin E (L : Set K)) = span E S := by rw [adjoin_eq_span, L.closure_eq, h] exact (span_le.mpr <| span_subset_span _ _ _).antisymm (span_mono subset_span) variable [CommSemiring F] [Algebra F K] [IsScalarTower F E K] (L : Subalgebra F K) {F} /-- If `K / E / F` is a ring extension tower, `L` is a subalgebra of `K / F` which is generated by `S` as an `F`-module, then `E[L]` is generated by `S` as an `E`-module. -/ theorem Subalgebra.adjoin_eq_span_of_eq_span {S : Set K} (h : toSubmodule L = span F S) : toSubmodule (adjoin E (L : Set K)) = span E S := L.toSubmonoid.adjoin_eq_span_of_eq_span F E (congr_arg ((↑) : _ → Set K) h) end section CommSemiring variable (R) [CommSemiring R] [Ring A] [Algebra R A] [Ring B] [Algebra R B] lemma NonUnitalAlgebra.adjoin_le_algebra_adjoin (s : Set A) : adjoin R s ≤ (Algebra.adjoin R s).toNonUnitalSubalgebra := adjoin_le Algebra.subset_adjoin lemma Algebra.adjoin_nonUnitalSubalgebra (s : Set A) : adjoin R (NonUnitalAlgebra.adjoin R s : Set A) = adjoin R s := le_antisymm (adjoin_le <| NonUnitalAlgebra.adjoin_le_algebra_adjoin R s) (adjoin_le <| (NonUnitalAlgebra.subset_adjoin R).trans subset_adjoin) end CommSemiring namespace Subalgebra variable [CommSemiring R] [Ring A] [Algebra R A] [Ring B] [Algebra R B] theorem comap_map_eq (f : A →ₐ[R] B) (S : Subalgebra R A) : (S.map f).comap f = S ⊔ Algebra.adjoin R (f ⁻¹' {0}) := by apply le_antisymm · intro x hx rw [mem_comap, mem_map] at hx obtain ⟨y, hy, hxy⟩ := hx replace hxy : x - y ∈ f ⁻¹' {0} := by simp [hxy] rw [← Algebra.adjoin_eq S, ← Algebra.adjoin_union, ← add_sub_cancel y x] exact Subalgebra.add_mem _ (Algebra.subset_adjoin <| Or.inl hy) (Algebra.subset_adjoin <| Or.inr hxy) · rw [← map_le, Algebra.map_sup, f.map_adjoin] apply le_of_eq rw [sup_eq_left, Algebra.adjoin_le_iff] exact (Set.image_preimage_subset f {0}).trans (Set.singleton_subset_iff.2 (S.map f).zero_mem) theorem comap_map_eq_self {f : A →ₐ[R] B} {S : Subalgebra R A} (h : f ⁻¹' {0} ⊆ S) : (S.map f).comap f = S := by convert comap_map_eq f S rwa [left_eq_sup, Algebra.adjoin_le_iff] end Subalgebra end Adjoin
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Spectrum/Quasispectrum.lean
import Mathlib.Algebra.Algebra.Spectrum.Basic import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Algebra.Unitization /-! # Quasiregularity and quasispectrum For a non-unital ring `R`, an element `r : R` is *quasiregular* if it is invertible in the monoid `(R, ∘)` where `x ∘ y := y + x + x * y` with identity `0 : R`. We implement this both as a type synonym `PreQuasiregular` which has an associated `Monoid` instance (note: *not* an `AddMonoid` instance despite the fact that `0 : R` is the identity in this monoid) so that one may access the quasiregular elements of `R` as `(PreQuasiregular R)ˣ`, but also as a predicate `IsQuasiregular`. Quasiregularity is closely tied to invertibility. Indeed, `(PreQuasiregular A)ˣ` is isomorphic to the subgroup of `Unitization R A` whose scalar part is `1`, whenever `A` is a non-unital `R`-algebra, and moreover this isomorphism is implemented by the map `(x : A) ↦ (1 + x : Unitization R A)`. It is because of this isomorphism, and the associated ties with multiplicative invertibility, that we choose a `Monoid` (as opposed to an `AddMonoid`) structure on `PreQuasiregular`. In addition, in unital rings, we even have `IsQuasiregular x ↔ IsUnit (1 + x)`. The *quasispectrum* of `a : A` (with respect to `R`) is defined in terms of quasiregularity, and this is the natural analogue of the `spectrum` for non-unital rings. Indeed, it is true that `quasispectrum R a = spectrum R a ∪ {0}` when `A` is unital. In Mathlib, the quasispectrum is the domain of the continuous functions associated to the *non-unital* continuous functional calculus. ## Main definitions + `PreQuasiregular R`: a structure wrapping `R` that inherits a distinct `Monoid` instance when `R` is a non-unital semiring. + `Unitization.unitsFstOne`: the subgroup with carrier `{ x : (Unitization R A)ˣ | x.fst = 1 }`. + `unitsFstOne_mulEquiv_quasiregular`: the group isomorphism between `Unitization.unitsFstOne` and the units of `PreQuasiregular` (i.e., the quasiregular elements) which sends `(1, x) ↦ x`. + `IsQuasiregular x`: the proposition that `x : R` is a unit with respect to the monoid structure on `PreQuasiregular R`, i.e., there is some `u : (PreQuasiregular R)ˣ` such that `u.val` is identified with `x` (via the natural equivalence between `R` and `PreQuasiregular R`). + `quasispectrum R a`: in an algebra over the semifield `R`, this is the set `{r : R | (hr : IsUnit r) → ¬ IsQuasiregular (-(hr.unit⁻¹ • a))}`, which should be thought of as a version of the `spectrum` which is applicable in non-unital algebras. ## Main theorems + `isQuasiregular_iff_isUnit`: in a unital ring, `x` is quasiregular if and only if `1 + x` is a unit. + `quasispectrum_eq_spectrum_union_zero`: in a unital algebra `A` over a semifield `R`, the quasispectrum of `a : A` is the `spectrum` with zero added. + `Unitization.isQuasiregular_inr_iff`: `a : A` is quasiregular if and only if it is quasiregular in `Unitization R A` (via the coercion `Unitization.inr`). + `Unitization.quasispectrum_eq_spectrum_inr`: the quasispectrum of `a` in a non-unital `R`-algebra `A` is precisely the spectrum of `a` in `Unitization R A` (via the coercion `Unitization.inr`). -/ /-- A type synonym for non-unital rings where an alternative monoid structure is introduced. If `R` is a non-unital semiring, then `PreQuasiregular R` is equipped with the monoid structure with binary operation `fun x y ↦ y + x + x * y` and identity `0`. Elements of `R` which are invertible in this monoid satisfy the predicate `IsQuasiregular`. -/ structure PreQuasiregular (R : Type*) where /-- The value wrapped into a term of `PreQuasiregular`. -/ val : R namespace PreQuasiregular variable {R : Type*} [NonUnitalSemiring R] /-- The identity map between `R` and `PreQuasiregular R`. -/ @[simps] def equiv : R ≃ PreQuasiregular R where toFun := .mk invFun := PreQuasiregular.val instance instOne : One (PreQuasiregular R) where one := equiv 0 @[simp] lemma val_one : (1 : PreQuasiregular R).val = 0 := rfl instance instMul : Mul (PreQuasiregular R) where mul x y := .mk (y.val + x.val + x.val * y.val) @[simp] lemma val_mul (x y : PreQuasiregular R) : (x * y).val = y.val + x.val + x.val * y.val := rfl instance instMonoid : Monoid (PreQuasiregular R) where one := equiv 0 mul x y := .mk (y.val + x.val + x.val * y.val) mul_one _ := equiv.symm.injective <| by simp [-EmbeddingLike.apply_eq_iff_eq] one_mul _ := equiv.symm.injective <| by simp [-EmbeddingLike.apply_eq_iff_eq] mul_assoc x y z := equiv.symm.injective <| by simp [mul_add, add_mul, mul_assoc]; abel @[simp] lemma inv_add_add_mul_eq_zero (u : (PreQuasiregular R)ˣ) : u⁻¹.val.val + u.val.val + u.val.val * u⁻¹.val.val = 0 := by simpa [-Units.mul_inv] using congr($(u.mul_inv).val) @[simp] lemma add_inv_add_mul_eq_zero (u : (PreQuasiregular R)ˣ) : u.val.val + u⁻¹.val.val + u⁻¹.val.val * u.val.val = 0 := by simpa [-Units.inv_mul] using congr($(u.inv_mul).val) end PreQuasiregular namespace Unitization open PreQuasiregular variable {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] variable (R A) in /-- The subgroup of the units of `Unitization R A` whose scalar part is `1`. -/ def unitsFstOne : Subgroup (Unitization R A)ˣ where carrier := {x | x.val.fst = 1} one_mem' := rfl mul_mem' {x} {y} (hx : fst x.val = 1) (hy : fst y.val = 1) := by simp [hx, hy] inv_mem' {x} (hx : fst x.val = 1) := by simpa [-Units.mul_inv, hx] using congr(fstHom R A $(x.mul_inv)) @[simp] lemma mem_unitsFstOne {x : (Unitization R A)ˣ} : x ∈ unitsFstOne R A ↔ x.val.fst = 1 := Iff.rfl @[simp] lemma unitsFstOne_val_val_fst (x : (unitsFstOne R A)) : x.val.val.fst = 1 := mem_unitsFstOne.mp x.property @[simp] lemma unitsFstOne_val_inv_val_fst (x : (unitsFstOne R A)) : x.val⁻¹.val.fst = 1 := mem_unitsFstOne.mp x⁻¹.property variable (R) in /-- If `A` is a non-unital `R`-algebra, then the subgroup of units of `Unitization R A` whose scalar part is `1 : R` (i.e., `Unitization.unitsFstOne`) is isomorphic to the group of units of `PreQuasiregular A`. -/ @[simps] def unitsFstOne_mulEquiv_quasiregular : unitsFstOne R A ≃* (PreQuasiregular A)ˣ where toFun x := { val := equiv x.val.val.snd inv := equiv x⁻¹.val.val.snd val_inv := equiv.symm.injective <| by simpa [-Units.mul_inv] using congr(snd $(x.val.mul_inv)) inv_val := equiv.symm.injective <| by simpa [-Units.inv_mul] using congr(snd $(x.val.inv_mul)) } invFun x := { val := { val := 1 + equiv.symm x.val inv := 1 + equiv.symm x⁻¹.val val_inv := by convert congr((1 + $(inv_add_add_mul_eq_zero x) : Unitization R A)) using 1 · simp only [mul_one, equiv_symm_apply, one_mul, mul_add, add_mul, inr_add, inr_mul] abel · simp only [inr_zero, add_zero] inv_val := by convert congr((1 + $(add_inv_add_mul_eq_zero x) : Unitization R A)) using 1 · simp only [mul_one, equiv_symm_apply, one_mul, mul_add, add_mul, inr_add, inr_mul] abel · simp only [inr_zero, add_zero] } property := by simp } left_inv x := Subtype.ext <| Units.ext <| by simpa using x.val.val.inl_fst_add_inr_snd_eq right_inv x := Units.ext <| by simp [-equiv_symm_apply] map_mul' x y := Units.ext <| equiv.symm.injective <| by simp end Unitization section PreQuasiregular open PreQuasiregular variable {R : Type*} [NonUnitalSemiring R] /-- In a non-unital semiring `R`, an element `x : R` satisfies `IsQuasiregular` if it is a unit under the monoid operation `fun x y ↦ y + x + x * y`. -/ def IsQuasiregular (x : R) : Prop := ∃ u : (PreQuasiregular R)ˣ, equiv.symm u.val = x @[simp] lemma isQuasiregular_zero : IsQuasiregular 0 := ⟨1, rfl⟩ lemma isQuasiregular_iff {x : R} : IsQuasiregular x ↔ ∃ y, y + x + x * y = 0 ∧ x + y + y * x = 0 := by constructor · rintro ⟨u, rfl⟩ exact ⟨equiv.symm u⁻¹.val, by simp⟩ · rintro ⟨y, hy₁, hy₂⟩ refine ⟨⟨equiv x, equiv y, ?_, ?_⟩, rfl⟩ all_goals apply equiv.symm.injective assumption lemma isQuasiregular_iff' {x : R} : IsQuasiregular x ↔ IsUnit (PreQuasiregular.equiv x) := by simp only [IsQuasiregular, IsUnit, Equiv.apply_symm_apply, ← PreQuasiregular.equiv (R := R).injective.eq_iff] end PreQuasiregular lemma IsQuasiregular.map {F R S : Type*} [NonUnitalSemiring R] [NonUnitalSemiring S] [FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) {x : R} (hx : IsQuasiregular x) : IsQuasiregular (f x) := by rw [isQuasiregular_iff] at hx ⊢ obtain ⟨y, hy₁, hy₂⟩ := hx exact ⟨f y, by simpa using And.intro congr(f $(hy₁)) congr(f $(hy₂))⟩ lemma IsQuasiregular.isUnit_one_add {R : Type*} [Semiring R] {x : R} (hx : IsQuasiregular x) : IsUnit (1 + x) := by obtain ⟨y, hy₁, hy₂⟩ := isQuasiregular_iff.mp hx refine ⟨⟨1 + x, 1 + y, ?_, ?_⟩, rfl⟩ · convert congr(1 + $(hy₁)) using 1 <;> [noncomm_ring; simp] · convert congr(1 + $(hy₂)) using 1 <;> [noncomm_ring; simp] lemma isQuasiregular_iff_isUnit {R : Type*} [Ring R] {x : R} : IsQuasiregular x ↔ IsUnit (1 + x) := by refine ⟨IsQuasiregular.isUnit_one_add, fun hx ↦ ?_⟩ rw [isQuasiregular_iff] use hx.unit⁻¹ - 1 constructor case' h.left => have := congr($(hx.mul_val_inv) - 1) case' h.right => have := congr($(hx.val_inv_mul) - 1) all_goals rw [← sub_add_cancel (↑hx.unit⁻¹ : R) 1, sub_self] at this convert this using 1 noncomm_ring -- interestingly, this holds even in the semiring case. lemma isQuasiregular_iff_isUnit' (R : Type*) {A : Type*} [CommSemiring R] [NonUnitalSemiring A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] {x : A} : IsQuasiregular x ↔ IsUnit (1 + x : Unitization R A) := by refine ⟨?_, fun hx ↦ ?_⟩ · rintro ⟨u, rfl⟩ exact (Unitization.unitsFstOne_mulEquiv_quasiregular R).symm u |>.val.isUnit · exact ⟨(Unitization.unitsFstOne_mulEquiv_quasiregular R) ⟨hx.unit, by simp⟩, by simp⟩ variable (R : Type*) {A : Type*} [CommSemiring R] [NonUnitalRing A] [Module R A] /-- If `A` is a non-unital `R`-algebra, the `R`-quasispectrum of `a : A` consists of those `r : R` such that if `r` is invertible (in `R`), then `-(r⁻¹ • a)` is not quasiregular. The quasispectrum is precisely the spectrum in the unitization when `R` is a commutative ring. See `Unitization.quasispectrum_eq_spectrum_inr`. -/ def quasispectrum (a : A) : Set R := {r : R | (hr : IsUnit r) → ¬ IsQuasiregular (-(hr.unit⁻¹ • a))} variable {R} in lemma quasispectrum.not_isUnit_mem (a : A) {r : R} (hr : ¬ IsUnit r) : r ∈ quasispectrum R a := fun hr' ↦ (hr hr').elim @[simp] lemma quasispectrum.zero_mem [Nontrivial R] (a : A) : 0 ∈ quasispectrum R a := quasispectrum.not_isUnit_mem a <| by simp theorem quasispectrum.nonempty [Nontrivial R] (a : A) : (quasispectrum R a).Nonempty := Set.nonempty_of_mem <| quasispectrum.zero_mem R a instance quasispectrum.instZero [Nontrivial R] (a : A) : Zero (quasispectrum R a) where zero := ⟨0, quasispectrum.zero_mem R a⟩ variable {R} /-- A version of `NonUnitalAlgHom.quasispectrum_apply_subset` which allows for `quasispectrum R`, where `R` is a *semi*ring, but `φ` must still function over a scalar ring `S`. In this case, we need `S` to be explicit. The primary use case is, for instance, `R := ℝ≥0` and `S := ℝ` or `S := ℂ`. -/ lemma NonUnitalAlgHom.quasispectrum_apply_subset' {F R : Type*} (S : Type*) {A B : Type*} [CommSemiring R] [Semiring S] [NonUnitalRing A] [NonUnitalRing B] [Module R S] [Module S A] [Module R A] [Module S B] [Module R B] [IsScalarTower R S A] [IsScalarTower R S B] [FunLike F A B] [NonUnitalAlgHomClass F S A B] (φ : F) (a : A) : quasispectrum R (φ a) ⊆ quasispectrum R a := by refine Set.compl_subset_compl.mp fun x ↦ ?_ simp only [quasispectrum, Set.mem_compl_iff, Set.mem_setOf_eq, not_forall, not_not, forall_exists_index] refine fun hx this ↦ ⟨hx, ?_⟩ rw [Units.smul_def, ← smul_one_smul S] at this ⊢ simpa [- smul_assoc] using this.map φ /-- If `φ` is non-unital algebra homomorphism over a scalar ring `R`, then `quasispectrum R (φ a) ⊆ quasispectrum R a`. -/ lemma NonUnitalAlgHom.quasispectrum_apply_subset {F R A B : Type*} [CommRing R] [NonUnitalRing A] [NonUnitalRing B] [Module R A] [Module R B] [FunLike F A B] [NonUnitalAlgHomClass F R A B] (φ : F) (a : A) : quasispectrum R (φ a) ⊆ quasispectrum R a := NonUnitalAlgHom.quasispectrum_apply_subset' R φ a @[simp] lemma quasispectrum.coe_zero [Nontrivial R] (a : A) : (0 : quasispectrum R a) = (0 : R) := rfl lemma quasispectrum.mem_of_not_quasiregular (a : A) {r : Rˣ} (hr : ¬ IsQuasiregular (-(r⁻¹ • a))) : (r : R) ∈ quasispectrum R a := fun _ ↦ by simpa using hr lemma quasispectrum_eq_spectrum_union (R : Type*) {A : Type*} [CommSemiring R] [Ring A] [Algebra R A] (a : A) : quasispectrum R a = spectrum R a ∪ {r : R | ¬ IsUnit r} := by ext r rw [quasispectrum] simp only [Set.mem_setOf_eq, Set.mem_union, ← imp_iff_or_not, spectrum.mem_iff] congr! 1 with hr rw [not_iff_not, isQuasiregular_iff_isUnit, ← sub_eq_add_neg, Algebra.algebraMap_eq_smul_one] exact (IsUnit.smul_sub_iff_sub_inv_smul hr.unit a).symm lemma spectrum_subset_quasispectrum (R : Type*) {A : Type*} [CommSemiring R] [Ring A] [Algebra R A] (a : A) : spectrum R a ⊆ quasispectrum R a := quasispectrum_eq_spectrum_union R a ▸ Set.subset_union_left lemma quasispectrum_eq_spectrum_union_zero (R : Type*) {A : Type*} [Semifield R] [Ring A] [Algebra R A] (a : A) : quasispectrum R a = spectrum R a ∪ {0} := by convert quasispectrum_eq_spectrum_union R a simp lemma mem_quasispectrum_iff {R A : Type*} [Semifield R] [Ring A] [Algebra R A] {a : A} {x : R} : x ∈ quasispectrum R a ↔ x = 0 ∨ x ∈ spectrum R a := by simp [quasispectrum_eq_spectrum_union_zero] namespace Unitization variable [IsScalarTower R A A] [SMulCommClass R A A] lemma isQuasiregular_inr_iff (a : A) : IsQuasiregular (a : Unitization R A) ↔ IsQuasiregular a := by refine ⟨fun ha ↦ ?_, IsQuasiregular.map (inrNonUnitalAlgHom R A)⟩ rw [isQuasiregular_iff] at ha ⊢ obtain ⟨y, hy₁, hy₂⟩ := ha lift y to A using by simpa using congr(fstHom R A $(hy₁)) refine ⟨y, ?_, ?_⟩ <;> exact inr_injective (R := R) <| by simpa lemma zero_mem_spectrum_inr (R S : Type*) {A : Type*} [CommSemiring R] [CommRing S] [Nontrivial S] [NonUnitalRing A] [Algebra R S] [Module S A] [IsScalarTower S A A] [SMulCommClass S A A] [Module R A] [IsScalarTower R S A] (a : A) : 0 ∈ spectrum R (a : Unitization S A) := by rw [spectrum.zero_mem_iff] rintro ⟨u, hu⟩ simpa [-Units.mul_inv, hu] using congr($(u.mul_inv).fst) lemma mem_spectrum_inr_of_not_isUnit {R A : Type*} [CommRing R] [NonUnitalRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] (a : A) (r : R) (hr : ¬ IsUnit r) : r ∈ spectrum R (a : Unitization R A) := fun h ↦ hr <| by simpa [map_sub] using h.map (fstHom R A) lemma quasispectrum_eq_spectrum_inr (R : Type*) {A : Type*} [CommRing R] [NonUnitalRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] (a : A) : quasispectrum R a = spectrum R (a : Unitization R A) := by ext r have : { r | ¬ IsUnit r} ⊆ spectrum R _ := mem_spectrum_inr_of_not_isUnit a rw [← Set.union_eq_left.mpr this, ← quasispectrum_eq_spectrum_union] apply forall_congr' fun hr ↦ ?_ rw [not_iff_not, Units.smul_def, Units.smul_def, ← inr_smul, ← inr_neg, isQuasiregular_inr_iff] lemma quasispectrum_eq_spectrum_inr' (R S : Type*) {A : Type*} [Semifield R] [Field S] [NonUnitalRing A] [Algebra R S] [Module S A] [IsScalarTower S A A] [SMulCommClass S A A] [Module R A] [IsScalarTower R S A] (a : A) : quasispectrum R a = spectrum R (a : Unitization S A) := by ext r have := Set.singleton_subset_iff.mpr (zero_mem_spectrum_inr R S a) rw [← Set.union_eq_self_of_subset_right this, ← quasispectrum_eq_spectrum_union_zero] apply forall_congr' fun x ↦ ?_ rw [not_iff_not, Units.smul_def, Units.smul_def, ← inr_smul, ← inr_neg, isQuasiregular_inr_iff] lemma quasispectrum_inr_eq (R S : Type*) {A : Type*} [Semifield R] [Field S] [NonUnitalRing A] [Algebra R S] [Module S A] [IsScalarTower S A A] [SMulCommClass S A A] [Module R A] [IsScalarTower R S A] (a : A) : quasispectrum R (a : Unitization S A) = quasispectrum R a := by rw [quasispectrum_eq_spectrum_union_zero, quasispectrum_eq_spectrum_inr' R S] simpa using zero_mem_spectrum_inr _ _ _ end Unitization lemma quasispectrum.mul_comm {R A : Type*} [CommRing R] [NonUnitalRing A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] (a b : A) : quasispectrum R (a * b) = quasispectrum R (b * a) := by rw [← Set.inter_union_compl (quasispectrum R (a * b)) {r | IsUnit r}, ← Set.inter_union_compl (quasispectrum R (b * a)) {r | IsUnit r}] congr! 1 · simpa [Set.inter_comm _ {r | IsUnit r}, Unitization.quasispectrum_eq_spectrum_inr, Unitization.inr_mul] using spectrum.setOf_isUnit_inter_mul_comm _ _ · rw [Set.inter_eq_right.mpr, Set.inter_eq_right.mpr] all_goals exact fun _ ↦ quasispectrum.not_isUnit_mem _ /-- A class for `𝕜`-algebras with a partial order where the ordering is compatible with the (quasi)spectrum. -/ class NonnegSpectrumClass (𝕜 A : Type*) [CommSemiring 𝕜] [PartialOrder 𝕜] [NonUnitalRing A] [PartialOrder A] [Module 𝕜 A] : Prop where quasispectrum_nonneg_of_nonneg : ∀ a : A, 0 ≤ a → ∀ x ∈ quasispectrum 𝕜 a, 0 ≤ x export NonnegSpectrumClass (quasispectrum_nonneg_of_nonneg) namespace NonnegSpectrumClass lemma iff_spectrum_nonneg {𝕜 A : Type*} [Semifield 𝕜] [LinearOrder 𝕜] [Ring A] [PartialOrder A] [Algebra 𝕜 A] : NonnegSpectrumClass 𝕜 A ↔ ∀ a : A, 0 ≤ a → ∀ x ∈ spectrum 𝕜 a, 0 ≤ x := by simp [show NonnegSpectrumClass 𝕜 A ↔ _ from ⟨fun ⟨h⟩ ↦ h, (⟨·⟩)⟩, quasispectrum_eq_spectrum_union_zero] alias ⟨_, of_spectrum_nonneg⟩ := iff_spectrum_nonneg lemma nonneg_of_mem_quasispectrum {𝕜 : Type*} [CommSemiring 𝕜] [PartialOrder 𝕜] [PartialOrder A] [Module 𝕜 A] [NonnegSpectrumClass 𝕜 A] {a : A} (ha : 0 ≤ a) {x : 𝕜} (hx : x ∈ quasispectrum 𝕜 a) : 0 ≤ x := quasispectrum_nonneg_of_nonneg a ha x hx grind_pattern nonneg_of_mem_quasispectrum => x ∈ quasispectrum 𝕜 a end NonnegSpectrumClass lemma spectrum_nonneg_of_nonneg {𝕜 A : Type*} [CommSemiring 𝕜] [PartialOrder 𝕜] [Ring A] [PartialOrder A] [Algebra 𝕜 A] [NonnegSpectrumClass 𝕜 A] ⦃a : A⦄ (ha : 0 ≤ a) ⦃x : 𝕜⦄ (hx : x ∈ spectrum 𝕜 a) : 0 ≤ x := NonnegSpectrumClass.quasispectrum_nonneg_of_nonneg a ha x (spectrum_subset_quasispectrum 𝕜 a hx) grind_pattern spectrum_nonneg_of_nonneg => x ∈ spectrum 𝕜 a /-! ### Restriction of the spectrum -/ /-- Given an element `a : A` of an `S`-algebra, where `S` is itself an `R`-algebra, we say that the spectrum of `a` restricts via a function `f : S → R` if `f` is a left inverse of `algebraMap R S`, and `f` is a right inverse of `algebraMap R S` on `spectrum S a`. For example, when `f = Complex.re` (so `S := ℂ` and `R := ℝ`), `SpectrumRestricts a f` means that the `ℂ`-spectrum of `a` is contained within `ℝ`. This arises naturally when `a` is selfadjoint and `A` is a C⋆-algebra. This is the property allows us to restrict a continuous functional calculus over `S` to a continuous functional calculus over `R`. -/ structure QuasispectrumRestricts {R S A : Type*} [CommSemiring R] [CommSemiring S] [NonUnitalRing A] [Module R A] [Module S A] [Algebra R S] (a : A) (f : S → R) : Prop where /-- `f` is a right inverse of `algebraMap R S` when restricted to `quasispectrum S a`. -/ rightInvOn : (quasispectrum S a).RightInvOn f (algebraMap R S) /-- `f` is a left inverse of `algebraMap R S`. -/ left_inv : Function.LeftInverse f (algebraMap R S) lemma quasispectrumRestricts_iff {R S A : Type*} [CommSemiring R] [CommSemiring S] [NonUnitalRing A] [Module R A] [Module S A] [Algebra R S] (a : A) (f : S → R) : QuasispectrumRestricts a f ↔ (quasispectrum S a).RightInvOn f (algebraMap R S) ∧ Function.LeftInverse f (algebraMap R S) := ⟨fun ⟨h₁, h₂⟩ ↦ ⟨h₁, h₂⟩, fun ⟨h₁, h₂⟩ ↦ ⟨h₁, h₂⟩⟩ @[simp] theorem quasispectrum.algebraMap_mem_iff (S : Type*) {R A : Type*} [Semifield R] [Field S] [NonUnitalRing A] [Algebra R S] [Module S A] [IsScalarTower S A A] [SMulCommClass S A A] [Module R A] [IsScalarTower R S A] {a : A} {r : R} : algebraMap R S r ∈ quasispectrum S a ↔ r ∈ quasispectrum R a := by simp_rw [Unitization.quasispectrum_eq_spectrum_inr' _ S a, spectrum.algebraMap_mem_iff] protected alias ⟨quasispectrum.of_algebraMap_mem, quasispectrum.algebraMap_mem⟩ := quasispectrum.algebraMap_mem_iff @[simp] theorem quasispectrum.preimage_algebraMap (S : Type*) {R A : Type*} [Semifield R] [Field S] [NonUnitalRing A] [Algebra R S] [Module S A] [IsScalarTower S A A] [SMulCommClass S A A] [Module R A] [IsScalarTower R S A] {a : A} : algebraMap R S ⁻¹' quasispectrum S a = quasispectrum R a := Set.ext fun _ => quasispectrum.algebraMap_mem_iff _ namespace QuasispectrumRestricts section NonUnital variable {R S A : Type*} [Semifield R] [Field S] [NonUnitalRing A] [Module R A] [Module S A] variable [Algebra R S] {a : A} {f : S → R} protected theorem map_zero (h : QuasispectrumRestricts a f) : f 0 = 0 := by rw [← h.left_inv 0, map_zero (algebraMap R S)] theorem of_subset_range_algebraMap (hf : f.LeftInverse (algebraMap R S)) (h : quasispectrum S a ⊆ Set.range (algebraMap R S)) : QuasispectrumRestricts a f where rightInvOn := fun s hs => by obtain ⟨r, rfl⟩ := h hs; rw [hf r] left_inv := hf lemma of_quasispectrum_eq {a b : A} {f : S → R} (ha : QuasispectrumRestricts a f) (h : quasispectrum S a = quasispectrum S b) : QuasispectrumRestricts b f where rightInvOn := h ▸ ha.rightInvOn left_inv := ha.left_inv variable [IsScalarTower S A A] [SMulCommClass S A A] lemma mul_comm_iff {f : S → R} {a b : A} : QuasispectrumRestricts (a * b) f ↔ QuasispectrumRestricts (b * a) f := by simp only [quasispectrumRestricts_iff, quasispectrum.mul_comm] alias ⟨mul_comm, _⟩ := mul_comm_iff variable [IsScalarTower R S A] theorem algebraMap_image (h : QuasispectrumRestricts a f) : algebraMap R S '' quasispectrum R a = quasispectrum S a := by refine Set.eq_of_subset_of_subset ?_ fun s hs => ⟨f s, ?_⟩ · simpa only [quasispectrum.preimage_algebraMap] using (quasispectrum S a).image_preimage_subset (algebraMap R S) exact ⟨quasispectrum.of_algebraMap_mem S ((h.rightInvOn hs).symm ▸ hs), h.rightInvOn hs⟩ theorem image (h : QuasispectrumRestricts a f) : f '' quasispectrum S a = quasispectrum R a := by simp only [← h.algebraMap_image, Set.image_image, h.left_inv _, Set.image_id'] theorem apply_mem (h : QuasispectrumRestricts a f) {s : S} (hs : s ∈ quasispectrum S a) : f s ∈ quasispectrum R a := h.image ▸ ⟨s, hs, rfl⟩ theorem subset_preimage (h : QuasispectrumRestricts a f) : quasispectrum S a ⊆ f ⁻¹' quasispectrum R a := h.image ▸ (quasispectrum S a).subset_preimage_image f protected lemma comp {R₁ R₂ R₃ A : Type*} [Semifield R₁] [Field R₂] [Field R₃] [NonUnitalRing A] [Module R₁ A] [Module R₂ A] [Module R₃ A] [Algebra R₁ R₂] [Algebra R₂ R₃] [Algebra R₁ R₃] [IsScalarTower R₁ R₂ R₃] [IsScalarTower R₂ R₃ A] [IsScalarTower R₃ A A] [SMulCommClass R₃ A A] {a : A} {f : R₃ → R₂} {g : R₂ → R₁} {e : R₃ → R₁} (hfge : g ∘ f = e) (hf : QuasispectrumRestricts a f) (hg : QuasispectrumRestricts a g) : QuasispectrumRestricts a e where left_inv := by convert hfge ▸ hf.left_inv.comp hg.left_inv congrm(⇑$(IsScalarTower.algebraMap_eq R₁ R₂ R₃)) rightInvOn := by convert hfge ▸ hg.rightInvOn.comp hf.rightInvOn fun _ ↦ hf.apply_mem congrm(⇑$(IsScalarTower.algebraMap_eq R₁ R₂ R₃)) end NonUnital end QuasispectrumRestricts /-- A (reducible) alias of `QuasispectrumRestricts` which enforces stronger type class assumptions on the types involved, as it's really intended for the `spectrum`. The separate definition also allows for dot notation. -/ @[reducible] def SpectrumRestricts {R S A : Type*} [Semifield R] [Semifield S] [Ring A] [Algebra R A] [Algebra S A] [Algebra R S] (a : A) (f : S → R) : Prop := QuasispectrumRestricts a f namespace SpectrumRestricts section Unital variable {R S A : Type*} [Semifield R] [Semifield S] [Ring A] variable [Algebra R S] [Algebra R A] [Algebra S A] {a : A} {f : S → R} theorem rightInvOn (h : SpectrumRestricts a f) : (spectrum S a).RightInvOn f (algebraMap R S) := (QuasispectrumRestricts.rightInvOn h).mono <| spectrum_subset_quasispectrum _ _ theorem of_rightInvOn (h₁ : Function.LeftInverse f (algebraMap R S)) (h₂ : (spectrum S a).RightInvOn f (algebraMap R S)) : SpectrumRestricts a f where rightInvOn x hx := by obtain (rfl | hx) := mem_quasispectrum_iff.mp hx · simpa using h₁ 0 · exact h₂ hx left_inv := h₁ lemma _root_.spectrumRestricts_iff : SpectrumRestricts a f ↔ (spectrum S a).RightInvOn f (algebraMap R S) ∧ Function.LeftInverse f (algebraMap R S) := ⟨fun h ↦ ⟨h.rightInvOn, h.left_inv⟩, fun h ↦ .of_rightInvOn h.2 h.1⟩ theorem of_subset_range_algebraMap (hf : f.LeftInverse (algebraMap R S)) (h : spectrum S a ⊆ Set.range (algebraMap R S)) : SpectrumRestricts a f where rightInvOn := fun s hs => by rw [mem_quasispectrum_iff] at hs obtain (rfl | hs) := hs · simpa using hf 0 · obtain ⟨r, rfl⟩ := h hs rw [hf r] left_inv := hf lemma of_spectrum_eq {a b : A} {f : S → R} (ha : SpectrumRestricts a f) (h : spectrum S a = spectrum S b) : SpectrumRestricts b f where rightInvOn := by rw [quasispectrum_eq_spectrum_union_zero, ← h, ← quasispectrum_eq_spectrum_union_zero] exact QuasispectrumRestricts.rightInvOn ha left_inv := ha.left_inv lemma mul_comm_iff {R S A : Type*} [Semifield R] [Field S] [Ring A] [Algebra R S] [Algebra R A] [Algebra S A] {a b : A} {f : S → R} : SpectrumRestricts (a * b) f ↔ SpectrumRestricts (b * a) f := QuasispectrumRestricts.mul_comm_iff alias ⟨mul_comm, _⟩ := mul_comm_iff variable [IsScalarTower R S A] theorem algebraMap_image (h : SpectrumRestricts a f) : algebraMap R S '' spectrum R a = spectrum S a := by refine Set.eq_of_subset_of_subset ?_ fun s hs => ⟨f s, ?_⟩ · simpa only [spectrum.preimage_algebraMap] using (spectrum S a).image_preimage_subset (algebraMap R S) exact ⟨spectrum.of_algebraMap_mem S ((h.rightInvOn hs).symm ▸ hs), h.rightInvOn hs⟩ theorem image (h : SpectrumRestricts a f) : f '' spectrum S a = spectrum R a := by simp only [← h.algebraMap_image, Set.image_image, h.left_inv _, Set.image_id'] theorem apply_mem (h : SpectrumRestricts a f) {s : S} (hs : s ∈ spectrum S a) : f s ∈ spectrum R a := h.image ▸ ⟨s, hs, rfl⟩ theorem subset_preimage (h : SpectrumRestricts a f) : spectrum S a ⊆ f ⁻¹' spectrum R a := h.image ▸ (spectrum S a).subset_preimage_image f end Unital end SpectrumRestricts theorem quasispectrumRestricts_iff_spectrumRestricts_inr (S : Type*) {R A : Type*} [Semifield R] [Field S] [NonUnitalRing A] [Algebra R S] [Module R A] [Module S A] [IsScalarTower S A A] [SMulCommClass S A A] [IsScalarTower R S A] {a : A} {f : S → R} : QuasispectrumRestricts a f ↔ SpectrumRestricts (a : Unitization S A) f := by rw [quasispectrumRestricts_iff, spectrumRestricts_iff, ← Unitization.quasispectrum_eq_spectrum_inr'] /-- The difference from `quasispectrumRestricts_iff_spectrumRestricts_inr` is that the `Unitization` may be taken with respect to a different scalar field. -/ lemma quasispectrumRestricts_iff_spectrumRestricts_inr' {R S' A : Type*} (S : Type*) [Semifield R] [Semifield S'] [Field S] [NonUnitalRing A] [Module R A] [Module S' A] [Module S A] [IsScalarTower S A A] [SMulCommClass S A A] [Algebra R S'] [Algebra S' S] [Algebra R S] [IsScalarTower S' S A] [IsScalarTower R S A] {a : A} {f : S' → R} : QuasispectrumRestricts a f ↔ SpectrumRestricts (a : Unitization S A) f := by simp only [quasispectrumRestricts_iff, SpectrumRestricts, Unitization.quasispectrum_inr_eq] theorem quasispectrumRestricts_iff_spectrumRestricts {R S A : Type*} [Semifield R] [Semifield S] [Ring A] [Algebra R S] [Algebra R A] [Algebra S A] {a : A} {f : S → R} : QuasispectrumRestricts a f ↔ SpectrumRestricts a f := by rfl
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Spectrum/Pi.lean
import Mathlib.Algebra.Algebra.Spectrum.Quasispectrum import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Group.Pi.Units /-! # Spectrum and quasispectrum of products This file contains results regarding the spectra and quasispectra of (indexed) products of elements of a (non-unital) ring. The main result is that the (quasi)spectrum of a product is the union of the (quasi)spectra. ## Main declarations + `Pi.spectrum_eq`: `spectrum R a = ⋃ i, spectrum R (a i)` for `a : ∀ i, κ i` + `Prod.spectrum_eq`: `spectrum R ⟨a, b⟩ = spectrum R a ∪ spectrum R b` + `Pi.quasispectrum_eq`: `quasispectrum R a = ⋃ i, quasispectrum R (a i)` for `a : ∀ i, κ i` + `Prod.quasispectrum_eq`: `quasispectrum R ⟨a, b⟩ = quasispectrum R a ∪ quasispectrum R b` ## TODO + Apply these results to block matrices. -/ variable {ι A B R : Type*} {κ : ι → Type*} section quasiregular variable (κ) in /-- The equivalence between pre-quasiregular elements of an indexed product and the indexed product of pre-quasiregular elements. -/ def PreQuasiregular.toPi [∀ i, NonUnitalSemiring (κ i)] : PreQuasiregular (∀ i, κ i) ≃* ∀ i, PreQuasiregular (κ i) where toFun := fun x i => .mk <| x.val i invFun := fun x => .mk <| fun i => (x i).val map_mul' _ _ := rfl variable (A B) in /-- The equivalence between pre-quasiregular elements of a product and the product of pre-quasiregular elements. -/ def PreQuasiregular.toProd [NonUnitalSemiring A] [NonUnitalSemiring B] : PreQuasiregular (A × B) ≃* PreQuasiregular A × PreQuasiregular B where toFun := fun p => ⟨.mk p.val.1, .mk p.val.2⟩ invFun := fun ⟨a, b⟩ => .mk ⟨a.val, b.val⟩ map_mul' _ _ := rfl lemma isQuasiregular_pi_iff [∀ i, NonUnitalSemiring (κ i)] (x : ∀ i, κ i) : IsQuasiregular x ↔ ∀ i, IsQuasiregular (x i) := by simp only [isQuasiregular_iff', ← isUnit_map_iff (PreQuasiregular.toPi κ), Pi.isUnit_iff] congr! lemma isQuasiregular_prod_iff [NonUnitalSemiring A] [NonUnitalSemiring B] (a : A) (b : B) : IsQuasiregular (⟨a, b⟩ : A × B) ↔ IsQuasiregular a ∧ IsQuasiregular b := by simp only [isQuasiregular_iff', ← isUnit_map_iff (PreQuasiregular.toProd A B), Prod.isUnit_iff] congr! lemma quasispectrum.mem_iff_of_isUnit [CommSemiring R] [NonUnitalRing A] [Module R A] {a : A} {r : R} (hr : IsUnit r) : r ∈ quasispectrum R a ↔ ¬ IsQuasiregular (-(hr.unit⁻¹ • a)) := ⟨fun h => h hr, fun h _ => h⟩ end quasiregular section spectrum lemma Pi.spectrum_eq [CommSemiring R] [∀ i, Ring (κ i)] [∀ i, Algebra R (κ i)] (a : ∀ i, κ i) : spectrum R a = ⋃ i, spectrum R (a i) := by apply compl_injective simp_rw [spectrum, Set.compl_iUnion, compl_compl, resolventSet, Set.iInter_setOf, Pi.isUnit_iff, sub_apply, algebraMap_apply] lemma Prod.spectrum_eq [CommSemiring R] [Ring A] [Ring B] [Algebra R A] [Algebra R B] (a : A) (b : B) : spectrum R (⟨a, b⟩ : A × B) = spectrum R a ∪ spectrum R b := by apply compl_injective simp_rw [spectrum, Set.compl_union, compl_compl, resolventSet, ← Set.setOf_and, Prod.isUnit_iff, algebraMap_apply, mk_sub_mk] lemma Pi.quasispectrum_eq [Nonempty ι] [CommSemiring R] [∀ i, NonUnitalRing (κ i)] [∀ i, Module R (κ i)] (a : ∀ i, κ i) : quasispectrum R a = ⋃ i, quasispectrum R (a i) := by ext r simp only [quasispectrum, Set.mem_setOf_eq, Set.mem_iUnion] by_cases hr : IsUnit r · lift r to Rˣ using hr with r' hr' simp [isQuasiregular_pi_iff] · simp [hr] lemma Prod.quasispectrum_eq [CommSemiring R] [NonUnitalRing A] [NonUnitalRing B] [Module R A] [Module R B] (a : A) (b : B) : quasispectrum R (⟨a, b⟩ : A × B) = quasispectrum R a ∪ quasispectrum R b := by apply compl_injective ext r simp only [quasispectrum, Set.mem_compl_iff, Set.mem_setOf_eq, not_forall, not_not, Set.mem_union] by_cases hr : IsUnit r · lift r to Rˣ using hr with r' hr' simp [isQuasiregular_prod_iff] · simp [hr] end spectrum
.lake/packages/mathlib/Mathlib/Algebra/Algebra/Spectrum/Basic.lean
import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Algebra.Star.Pointwise import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Ideal.Nonunits import Mathlib.Tactic.NoncommRing /-! # Spectrum of an element in an algebra This file develops the basic theory of the spectrum of an element of an algebra. This theory will serve as the foundation for spectral theory in Banach algebras. ## Main definitions * `resolventSet a : Set R`: the resolvent set of an element `a : A` where `A` is an `R`-algebra. * `spectrum a : Set R`: the spectrum of an element `a : A` where `A` is an `R`-algebra. * `resolvent : R → A`: the resolvent function is `fun r ↦ Ring.inverse (↑ₐ r - a)`, and hence when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐ r - a)`. ## Main statements * `spectrum.unit_smul_eq_smul` and `spectrum.smul_eq_smul`: units in the scalar ring commute (multiplication) with the spectrum, and over a field even `0` commutes with the spectrum. * `spectrum.left_add_coset_eq`: elements of the scalar ring commute (addition) with the spectrum. * `spectrum.unit_mem_mul_comm` and `spectrum.preimage_units_mul_comm`: the units (of `R`) in `σ (a*b)` coincide with those in `σ (b*a)`. * `spectrum.scalar_eq`: in a nontrivial algebra over a field, the spectrum of a scalar is a singleton. ## Notation * `σ a` : `spectrum R a` of `a : A` -/ open Set open scoped Pointwise universe u v section Defs variable (R : Type u) {A : Type v} variable [CommSemiring R] [Ring A] [Algebra R A] local notation "↑ₐ" => algebraMap R A -- definition and basic properties /-- Given a commutative ring `R` and an `R`-algebra `A`, the *resolvent set* of `a : A` is the `Set R` consisting of those `r : R` for which `r•1 - a` is a unit of the algebra `A`. -/ def resolventSet (a : A) : Set R := {r : R | IsUnit (↑ₐ r - a)} /-- Given a commutative ring `R` and an `R`-algebra `A`, the *spectrum* of `a : A` is the `Set R` consisting of those `r : R` for which `r•1 - a` is not a unit of the algebra `A`. The spectrum is simply the complement of the resolvent set. -/ def spectrum (a : A) : Set R := (resolventSet R a)ᶜ variable {R} /-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is a map `R → A` which sends `r : R` to `(algebraMap R A r - a)⁻¹` when `r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/ noncomputable def resolvent (a : A) (r : R) : A := Ring.inverse (↑ₐ r - a) /-- The unit `1 - r⁻¹ • a` constructed from `r • 1 - a` when the latter is a unit. -/ @[simps] noncomputable def IsUnit.subInvSMul {r : Rˣ} {s : R} {a : A} (h : IsUnit <| r • ↑ₐ s - a) : Aˣ where val := ↑ₐ s - r⁻¹ • a inv := r • ↑h.unit⁻¹ val_inv := by rw [mul_smul_comm, ← smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_val_inv] inv_val := by rw [smul_mul_assoc, ← mul_smul_comm, smul_sub, smul_inv_smul, h.val_inv_mul] end Defs namespace spectrum section ScalarSemiring variable {R : Type u} {A : Type v} variable [CommSemiring R] [Ring A] [Algebra R A] local notation "σ" => spectrum R local notation "↑ₐ" => algebraMap R A theorem mem_iff {r : R} {a : A} : r ∈ σ a ↔ ¬IsUnit (↑ₐ r - a) := Iff.rfl theorem notMem_iff {r : R} {a : A} : r ∉ σ a ↔ IsUnit (↑ₐ r - a) := by simp [mem_iff] @[deprecated (since := "2025-05-23")] alias not_mem_iff := notMem_iff variable (R) theorem zero_mem_iff {a : A} : (0 : R) ∈ σ a ↔ ¬IsUnit a := by rw [mem_iff, map_zero, zero_sub, IsUnit.neg_iff] alias ⟨not_isUnit_of_zero_mem, zero_mem⟩ := spectrum.zero_mem_iff theorem zero_notMem_iff {a : A} : (0 : R) ∉ σ a ↔ IsUnit a := by rw [zero_mem_iff, Classical.not_not] @[deprecated (since := "2025-05-23")] alias zero_not_mem_iff := zero_notMem_iff alias ⟨isUnit_of_zero_notMem, zero_notMem⟩ := spectrum.zero_not_mem_iff @[deprecated (since := "2025-05-23")] alias isUnit_of_zero_not_mem := isUnit_of_zero_notMem @[deprecated (since := "2025-05-23")] alias zero_not_mem := zero_notMem @[simp] lemma _root_.Units.zero_notMem_spectrum (a : Aˣ) : 0 ∉ spectrum R (a : A) := spectrum.zero_notMem R a.isUnit @[deprecated (since := "2025-05-23")] alias _root_.Units.zero_not_mem_spectrum := _root_.Units.zero_notMem_spectrum lemma subset_singleton_zero_compl {a : A} (ha : IsUnit a) : spectrum R a ⊆ {0}ᶜ := Set.subset_compl_singleton_iff.mpr <| spectrum.zero_notMem R ha variable {R} theorem mem_resolventSet_of_left_right_inverse {r : R} {a b c : A} (h₁ : (↑ₐ r - a) * b = 1) (h₂ : c * (↑ₐ r - a) = 1) : r ∈ resolventSet R a := Units.isUnit ⟨↑ₐ r - a, b, h₁, by rwa [← left_inv_eq_right_inv h₂ h₁]⟩ theorem mem_resolventSet_iff {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (↑ₐ r - a) := Iff.rfl @[simp] theorem algebraMap_mem_iff (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S] [Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} {r : R} : algebraMap R S r ∈ spectrum S a ↔ r ∈ spectrum R a := by simp only [spectrum.mem_iff, Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul] protected alias ⟨of_algebraMap_mem, algebraMap_mem⟩ := spectrum.algebraMap_mem_iff @[simp] theorem preimage_algebraMap (S : Type*) {R A : Type*} [CommSemiring R] [CommSemiring S] [Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {a : A} : algebraMap R S ⁻¹' spectrum S a = spectrum R a := Set.ext fun _ => spectrum.algebraMap_mem_iff _ @[simp] theorem resolventSet_of_subsingleton [Subsingleton A] (a : A) : resolventSet R a = Set.univ := by simp_rw [resolventSet, Subsingleton.elim (algebraMap R A _ - a) 1, isUnit_one, Set.setOf_true] @[simp] theorem of_subsingleton [Subsingleton A] (a : A) : spectrum R a = ∅ := by rw [spectrum, resolventSet_of_subsingleton, Set.compl_univ] theorem resolvent_eq {a : A} {r : R} (h : r ∈ resolventSet R a) : resolvent a r = ↑h.unit⁻¹ := Ring.inverse_unit h.unit theorem units_smul_resolvent {r : Rˣ} {s : R} {a : A} : r • resolvent a (s : R) = resolvent (r⁻¹ • a) (r⁻¹ • s : R) := by by_cases h : s ∈ spectrum R a · rw [mem_iff] at h simp only [resolvent, Algebra.algebraMap_eq_smul_one] at * rw [smul_assoc, ← smul_sub] have h' : ¬IsUnit (r⁻¹ • (s • (1 : A) - a)) := fun hu => h (by simpa only [smul_inv_smul] using IsUnit.smul r hu) simp only [Ring.inverse_non_unit _ h, Ring.inverse_non_unit _ h', smul_zero] · simp only [resolvent] have h' : IsUnit (r • algebraMap R A (r⁻¹ • s) - a) := by simpa [Algebra.algebraMap_eq_smul_one, smul_assoc] using notMem_iff.mp h rw [← h'.val_subInvSMul, ← (notMem_iff.mp h).unit_spec, Ring.inverse_unit, Ring.inverse_unit, h'.val_inv_subInvSMul] simp only [Algebra.algebraMap_eq_smul_one, smul_assoc, smul_inv_smul] theorem units_smul_resolvent_self {r : Rˣ} {a : A} : r • resolvent a (r : R) = resolvent (r⁻¹ • a) (1 : R) := by simpa only [Units.smul_def, Algebra.id.smul_eq_mul, Units.inv_mul] using @units_smul_resolvent _ _ _ _ _ r r a /-- The resolvent is a unit when the argument is in the resolvent set. -/ theorem isUnit_resolvent {r : R} {a : A} : r ∈ resolventSet R a ↔ IsUnit (resolvent a r) := isUnit_ringInverse.symm theorem inv_mem_resolventSet {r : Rˣ} {a : Aˣ} (h : (r : R) ∈ resolventSet R (a : A)) : (↑r⁻¹ : R) ∈ resolventSet R (↑a⁻¹ : A) := by rw [mem_resolventSet_iff, Algebra.algebraMap_eq_smul_one, ← Units.smul_def] at h ⊢ rw [IsUnit.smul_sub_iff_sub_inv_smul, inv_inv, IsUnit.sub_iff] have h₁ : (a : A) * (r • (↑a⁻¹ : A) - 1) = r • (1 : A) - a := by rw [mul_sub, mul_smul_comm, a.mul_inv, mul_one] have h₂ : (r • (↑a⁻¹ : A) - 1) * a = r • (1 : A) - a := by rw [sub_mul, smul_mul_assoc, a.inv_mul, one_mul] have hcomm : Commute (a : A) (r • (↑a⁻¹ : A) - 1) := by rwa [← h₂] at h₁ exact (hcomm.isUnit_mul_iff.mp (h₁.symm ▸ h)).2 theorem inv_mem_iff {r : Rˣ} {a : Aˣ} : (r : R) ∈ σ (a : A) ↔ (↑r⁻¹ : R) ∈ σ (↑a⁻¹ : A) := not_iff_not.2 <| ⟨inv_mem_resolventSet, inv_mem_resolventSet⟩ theorem zero_mem_resolventSet_of_unit (a : Aˣ) : 0 ∈ resolventSet R (a : A) := by simpa only [mem_resolventSet_iff, ← notMem_iff, zero_notMem_iff] using a.isUnit theorem ne_zero_of_mem_of_unit {a : Aˣ} {r : R} (hr : r ∈ σ (a : A)) : r ≠ 0 := fun hn => (hn ▸ hr) (zero_mem_resolventSet_of_unit a) theorem add_mem_iff {a : A} {r s : R} : r + s ∈ σ a ↔ r ∈ σ (-↑ₐ s + a) := by simp only [mem_iff, sub_neg_eq_add, ← sub_sub, map_add] theorem add_mem_add_iff {a : A} {r s : R} : r + s ∈ σ (↑ₐ s + a) ↔ r ∈ σ a := by rw [add_mem_iff, neg_add_cancel_left] theorem smul_mem_smul_iff {a : A} {s : R} {r : Rˣ} : r • s ∈ σ (r • a) ↔ s ∈ σ a := by simp only [mem_iff, Algebra.algebraMap_eq_smul_one, smul_assoc, ← smul_sub, isUnit_smul_iff] theorem unit_smul_eq_smul (a : A) (r : Rˣ) : σ (r • a) = r • σ a := by ext x have x_eq : x = r • r⁻¹ • x := by simp nth_rw 1 [x_eq] rw [smul_mem_smul_iff] constructor · exact fun h => ⟨r⁻¹ • x, ⟨h, show r • r⁻¹ • x = x by simp⟩⟩ · rintro ⟨w, _, (x'_eq : r • w = x)⟩ simpa [← x'_eq ] -- `r ∈ σ(a*b) ↔ r ∈ σ(b*a)` for any `r : Rˣ` theorem unit_mem_mul_comm {a b : A} {r : Rˣ} : ↑r ∈ σ (a * b) ↔ ↑r ∈ σ (b * a) := by have h₁ : ∀ x y : A, IsUnit (1 - x * y) → IsUnit (1 - y * x) := by refine fun x y h => ⟨⟨1 - y * x, 1 + y * h.unit.inv * x, ?_, ?_⟩, rfl⟩ · calc (1 - y * x) * (1 + y * (IsUnit.unit h).inv * x) = 1 - y * x + y * ((1 - x * y) * h.unit.inv) * x := by noncomm_ring _ = 1 := by simp only [Units.inv_eq_val_inv, IsUnit.mul_val_inv, mul_one, sub_add_cancel] · calc (1 + y * (IsUnit.unit h).inv * x) * (1 - y * x) = 1 - y * x + y * (h.unit.inv * (1 - x * y)) * x := by noncomm_ring _ = 1 := by simp only [Units.inv_eq_val_inv, IsUnit.val_inv_mul, mul_one, sub_add_cancel] have := Iff.intro (h₁ (r⁻¹ • a) b) (h₁ b (r⁻¹ • a)) rw [mul_smul_comm r⁻¹ b a] at this simpa only [mem_iff, not_iff_not, Algebra.algebraMap_eq_smul_one, ← Units.smul_def, IsUnit.smul_sub_iff_sub_inv_smul, smul_mul_assoc] theorem preimage_units_mul_comm (a b : A) : ((↑) : Rˣ → R) ⁻¹' σ (a * b) = (↑) ⁻¹' σ (b * a) := Set.ext fun _ => unit_mem_mul_comm theorem setOf_isUnit_inter_mul_comm (a b : A) : {r | IsUnit r} ∩ σ (a * b) = {r | IsUnit r} ∩ σ (b * a) := by ext r simpa using fun hr : IsUnit r ↦ unit_mem_mul_comm (r := hr.unit) section Star variable [InvolutiveStar R] [StarRing A] [StarModule R A] theorem star_mem_resolventSet_iff {r : R} {a : A} : star r ∈ resolventSet R a ↔ r ∈ resolventSet R (star a) := by refine ⟨fun h => ?_, fun h => ?_⟩ <;> simpa only [mem_resolventSet_iff, Algebra.algebraMap_eq_smul_one, star_sub, star_smul, star_star, star_one] using IsUnit.star h protected theorem map_star (a : A) : σ (star a) = star (σ a) := by ext simpa only [Set.mem_star, mem_iff, not_iff_not] using star_mem_resolventSet_iff.symm end Star end ScalarSemiring section ScalarRing variable {R : Type u} {A : Type v} variable [CommRing R] [Ring A] [Algebra R A] local notation "σ" => spectrum R local notation "↑ₐ" => algebraMap R A theorem subset_subalgebra {S R A : Type*} [CommSemiring R] [Ring A] [Algebra R A] [SetLike S A] [SubringClass S A] [SMulMemClass S R A] {s : S} (a : s) : spectrum R (a : A) ⊆ spectrum R a := Set.compl_subset_compl.mpr fun _ ↦ IsUnit.map (SubalgebraClass.val s) theorem singleton_add_eq (a : A) (r : R) : {r} + σ a = σ (↑ₐ r + a) := ext fun x => by rw [singleton_add, image_add_left, mem_preimage, add_comm, add_mem_iff, map_neg, neg_neg] theorem add_singleton_eq (a : A) (r : R) : σ a + {r} = σ (a + ↑ₐ r) := add_comm {r} (σ a) ▸ add_comm (algebraMap R A r) a ▸ singleton_add_eq a r theorem vadd_eq (a : A) (r : R) : r +ᵥ σ a = σ (↑ₐ r + a) := singleton_add.symm.trans <| singleton_add_eq a r theorem neg_eq (a : A) : -σ a = σ (-a) := Set.ext fun x => by simp only [mem_neg, mem_iff, map_neg, ← neg_add', IsUnit.neg_iff, sub_neg_eq_add] theorem singleton_sub_eq (a : A) (r : R) : {r} - σ a = σ (↑ₐ r - a) := by rw [sub_eq_add_neg, neg_eq, singleton_add_eq, sub_eq_add_neg] theorem sub_singleton_eq (a : A) (r : R) : σ a - {r} = σ (a - ↑ₐ r) := by simpa only [neg_sub, neg_eq] using congr_arg Neg.neg (singleton_sub_eq a r) end ScalarRing section ScalarSemifield variable {R : Type u} {A : Type v} [Semifield R] [Ring A] [Algebra R A] @[simp] lemma inv₀_mem_iff {r : R} {a : Aˣ} : r⁻¹ ∈ spectrum R (a : A) ↔ r ∈ spectrum R (↑a⁻¹ : A) := by obtain (rfl | hr) := eq_or_ne r 0 · simp [zero_mem_iff] · lift r to Rˣ using hr.isUnit simp [inv_mem_iff] lemma inv₀_mem_inv_iff {r : R} {a : Aˣ} : r⁻¹ ∈ spectrum R (↑a⁻¹ : A) ↔ r ∈ spectrum R (a : A) := by simp alias ⟨of_inv₀_mem, inv₀_mem⟩ := inv₀_mem_iff alias ⟨of_inv₀_mem_inv, inv₀_mem_inv⟩ := inv₀_mem_inv_iff end ScalarSemifield section ScalarField variable {𝕜 : Type u} {A : Type v} variable [Field 𝕜] [Ring A] [Algebra 𝕜 A] local notation "σ" => spectrum 𝕜 local notation "↑ₐ" => algebraMap 𝕜 A /-- Without the assumption `Nontrivial A`, then `0 : A` would be invertible. -/ @[simp] theorem zero_eq [Nontrivial A] : σ (0 : A) = {0} := by refine Set.Subset.antisymm ?_ (by simp [Algebra.algebraMap_eq_smul_one, mem_iff]) rw [spectrum, Set.compl_subset_comm] intro k hk rw [Set.mem_compl_singleton_iff] at hk have : IsUnit (Units.mk0 k hk • (1 : A)) := IsUnit.smul (Units.mk0 k hk) isUnit_one simpa [mem_resolventSet_iff, Algebra.algebraMap_eq_smul_one] @[simp] theorem scalar_eq [Nontrivial A] (k : 𝕜) : σ (↑ₐ k) = {k} := by rw [← add_zero (↑ₐ k), ← singleton_add_eq, zero_eq, Set.singleton_add_singleton, add_zero] @[simp] theorem one_eq [Nontrivial A] : σ (1 : A) = {1} := calc σ (1 : A) = σ (↑ₐ 1) := by rw [Algebra.algebraMap_eq_smul_one, one_smul] _ = {1} := scalar_eq 1 /-- the assumption `(σ a).Nonempty` is necessary and cannot be removed without further conditions on the algebra `A` and scalar field `𝕜`. -/ theorem smul_eq_smul [Nontrivial A] (k : 𝕜) (a : A) (ha : (σ a).Nonempty) : σ (k • a) = k • σ a := by rcases eq_or_ne k 0 with (rfl | h) · simpa [ha, zero_smul_set] using (show {(0 : 𝕜)} = (0 : Set 𝕜) from rfl) · exact unit_smul_eq_smul a (Units.mk0 k h) theorem nonzero_mul_comm (a b : A) : σ (a * b) \ {0} = σ (b * a) \ {0} := by suffices h : ∀ x y : A, σ (x * y) \ {0} ⊆ σ (y * x) \ {0} from Set.eq_of_subset_of_subset (h a b) (h b a) rintro _ _ k ⟨k_mem, k_neq⟩ change ((Units.mk0 k k_neq) : 𝕜) ∈ _ at k_mem exact ⟨unit_mem_mul_comm.mp k_mem, k_neq⟩ protected theorem map_inv (a : Aˣ) : (σ (a : A))⁻¹ = σ (↑a⁻¹ : A) := by ext simp end ScalarField end spectrum namespace AlgHom section CommSemiring variable {F R A B : Type*} [CommSemiring R] [Ring A] [Algebra R A] [Ring B] [Algebra R B] variable [FunLike F A B] [AlgHomClass F R A B] local notation "σ" => spectrum R local notation "↑ₐ" => algebraMap R A theorem mem_resolventSet_apply (φ : F) {a : A} {r : R} (h : r ∈ resolventSet R a) : r ∈ resolventSet R ((φ : A → B) a) := by simpa only [map_sub, AlgHomClass.commutes] using h.map φ theorem spectrum_apply_subset (φ : F) (a : A) : σ ((φ : A → B) a) ⊆ σ a := fun _ => mt (mem_resolventSet_apply φ) end CommSemiring section CommRing variable {F R A : Type*} [CommRing R] [Ring A] [Algebra R A] variable [FunLike F A R] [AlgHomClass F R A R] local notation "σ" => spectrum R local notation "↑ₐ" => algebraMap R A theorem apply_mem_spectrum [Nontrivial R] (φ : F) (a : A) : φ a ∈ σ a := by have h : ↑ₐ (φ a) - a ∈ RingHom.ker (φ : A →+* R) := by simp only [RingHom.mem_ker, map_sub, RingHom.coe_coe, AlgHomClass.commutes, Algebra.algebraMap_self, RingHom.id_apply, sub_self] simp only [spectrum.mem_iff, ← mem_nonunits_iff, coe_subset_nonunits (RingHom.ker_ne_top (φ : A →+* R)) h] end CommRing end AlgHom @[simp] theorem AlgEquiv.spectrum_eq {F R A B : Type*} [CommSemiring R] [Ring A] [Ring B] [Algebra R A] [Algebra R B] [EquivLike F A B] [AlgEquivClass F R A B] (f : F) (a : A) : spectrum R (f a) = spectrum R a := Set.Subset.antisymm (AlgHom.spectrum_apply_subset _ _) <| by simpa only [AlgEquiv.coe_algHom, AlgEquiv.coe_coe_symm_apply_coe_apply] using AlgHom.spectrum_apply_subset (f : A ≃ₐ[R] B).symm (f a) section ConjugateUnits variable {R A : Type*} [CommSemiring R] [Ring A] [Algebra R A] /-- Conjugation by a unit preserves the spectrum, inverse on right. -/ @[simp] lemma spectrum.units_conjugate {a : A} {u : Aˣ} : spectrum R (u * a * u⁻¹) = spectrum R a := by suffices ∀ (b : A) (v : Aˣ), spectrum R (v * b * v⁻¹) ⊆ spectrum R b by refine le_antisymm (this a u) ?_ apply le_of_eq_of_le ?_ <| this (u * a * u⁻¹) u⁻¹ simp [mul_assoc] intro a u μ hμ rw [spectrum.mem_iff] at hμ ⊢ contrapose! hμ simpa [mul_sub, sub_mul, Algebra.right_comm] using u.isUnit.mul hμ |>.mul u⁻¹.isUnit /-- Conjugation by a unit preserves the spectrum, inverse on left. -/ @[simp] lemma spectrum.units_conjugate' {a : A} {u : Aˣ} : spectrum R (u⁻¹ * a * u) = spectrum R a := by simpa using spectrum.units_conjugate (u := u⁻¹) end ConjugateUnits
.lake/packages/mathlib/Mathlib/Algebra/ContinuedFractions/Basic.lean
import Mathlib.Data.Seq.Defs import Mathlib.Algebra.Field.Defs /-! # Basic Definitions/Theorems for Continued Fractions ## Summary We define generalised, simple, and regular continued fractions and functions to evaluate their convergents. We follow the naming conventions from Wikipedia and [wall2018analytic], Chapter 1. ## Main definitions 1. Generalised continued fractions (gcfs) 2. Simple continued fractions (scfs) 3. (Regular) continued fractions ((r)cfs) 4. Computation of convergents using the recurrence relation in `convs`. 5. Computation of convergents by directly evaluating the fraction described by the gcf in `convs'`. ## Implementation notes 1. The most commonly used kind of continued fractions in the literature are regular continued fractions. We hence just call them `ContFract` in the library. 2. We use sequences from `Data.Seq` to encode potentially infinite sequences. ## References - <https://en.wikipedia.org/wiki/Generalized_continued_fraction> - [Wall, H.S., *Analytic Theory of Continued Fractions*][wall2018analytic] ## Tags numerics, number theory, approximations, fractions -/ -- Fix a carrier `α`. variable (α : Type*) /-!### Definitions -/ /-- We collect a partial numerator `aᵢ` and partial denominator `bᵢ` in a pair `⟨aᵢ, bᵢ⟩`. -/ structure GenContFract.Pair where /-- Partial numerator -/ a : α /-- Partial denominator -/ b : α deriving Inhabited open GenContFract /-! Interlude: define some expected coercions and instances. -/ namespace GenContFract.Pair variable {α} /-- Make a `GenContFract.Pair` printable. -/ instance [Repr α] : Repr (Pair α) := ⟨fun p _ ↦ "(a : " ++ repr p.a ++ ", b : " ++ repr p.b ++ ")"⟩ /-- Maps a function `f` on both components of a given pair. -/ def map {β : Type*} (f : α → β) (gp : Pair α) : Pair β := ⟨f gp.a, f gp.b⟩ section coe -- Fix another type `β` which we will convert to. variable {β : Type*} [Coe α β] /-- The coercion between numerator-denominator pairs happens componentwise. -/ @[coe] def coeFn : Pair α → Pair β := map (↑) /-- Coerce a pair by elementwise coercion. -/ instance : Coe (Pair α) (Pair β) := ⟨coeFn⟩ @[simp, norm_cast] theorem coe_toPair {a b : α} : (↑(Pair.mk a b) : Pair β) = Pair.mk (a : β) (b : β) := rfl end coe end GenContFract.Pair /-- A *generalised continued fraction* (gcf) is a potentially infinite expression of the form $$ h + \dfrac{a_0} {b_0 + \dfrac{a_1} {b_1 + \dfrac{a_2} {b_2 + \dfrac{a_3} {b_3 + \dots}}}} $$ where `h` is called the *head term* or *integer part*, the `aᵢ` are called the *partial numerators* and the `bᵢ` the *partial denominators* of the gcf. We store the sequence of partial numerators and denominators in a sequence of `GenContFract.Pair`s `s`. For convenience, one often writes `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`. -/ @[ext] structure GenContFract where /-- Head term -/ h : α /-- Sequence of partial numerator and denominator pairs. -/ s : Stream'.Seq <| Pair α variable {α} namespace GenContFract /-- Constructs a generalized continued fraction without fractional part. -/ def ofInteger (a : α) : GenContFract α := ⟨a, Stream'.Seq.nil⟩ instance [Inhabited α] : Inhabited (GenContFract α) := ⟨ofInteger default⟩ /-- Returns the sequence of partial numerators `aᵢ` of `g`. -/ def partNums (g : GenContFract α) : Stream'.Seq α := g.s.map Pair.a /-- Returns the sequence of partial denominators `bᵢ` of `g`. -/ def partDens (g : GenContFract α) : Stream'.Seq α := g.s.map Pair.b /-- A gcf terminated at position `n` if its sequence terminates at position `n`. -/ def TerminatedAt (g : GenContFract α) (n : ℕ) : Prop := g.s.TerminatedAt n /-- It is decidable whether a gcf terminated at a given position. -/ instance terminatedAtDecidable (g : GenContFract α) (n : ℕ) : Decidable (g.TerminatedAt n) := by unfold TerminatedAt infer_instance /-- A gcf terminates if its sequence terminates. -/ def Terminates (g : GenContFract α) : Prop := g.s.Terminates section coe /-! Interlude: define some expected coercions. -/ -- Fix another type `β` which we will convert to. variable {β : Type*} [Coe α β] /-- The coercion between `GenContFract` happens on the head term and all numerator-denominator pairs componentwise. -/ @[coe] def coeFn : GenContFract α → GenContFract β := fun g ↦ ⟨(g.h : β), (g.s.map (↑) : Stream'.Seq <| Pair β)⟩ /-- Coerce a gcf by elementwise coercion. -/ instance : Coe (GenContFract α) (GenContFract β) := ⟨coeFn⟩ @[simp, norm_cast] theorem coe_toGenContFract {g : GenContFract α} : (g : GenContFract β) = ⟨(g.h : β), (g.s.map (↑) : Stream'.Seq <| Pair β)⟩ := rfl end coe end GenContFract /-- A generalized continued fraction is a *simple continued fraction* if all partial numerators are equal to one. $$ h + \dfrac{1} {b_0 + \dfrac{1} {b_1 + \dfrac{1} {b_2 + \dfrac{1} {b_3 + \dots}}}} $$ -/ def GenContFract.IsSimpContFract (g : GenContFract α) [One α] : Prop := ∀ (n : ℕ) (aₙ : α), g.partNums.get? n = some aₙ → aₙ = 1 variable (α) in /-- A *simple continued fraction* (scf) is a generalized continued fraction (gcf) whose partial numerators are equal to one. $$ h + \dfrac{1} {b_0 + \dfrac{1} {b_1 + \dfrac{1} {b_2 + \dfrac{1} {b_3 + \dots}}}} $$ For convenience, one often writes `[h; b₀, b₁, b₂,...]`. It is encoded as the subtype of gcfs that satisfy `GenContFract.IsSimpContFract`. -/ def SimpContFract [One α] := { g : GenContFract α // g.IsSimpContFract } -- Interlude: define some expected coercions. namespace SimpContFract variable [One α] /-- Constructs a simple continued fraction without fractional part. -/ def ofInteger (a : α) : SimpContFract α := ⟨GenContFract.ofInteger a, fun n aₙ h ↦ by cases h⟩ instance : Inhabited (SimpContFract α) := ⟨ofInteger 1⟩ /-- Lift a scf to a gcf using the inclusion map. -/ instance : Coe (SimpContFract α) (GenContFract α) := ⟨Subtype.val⟩ end SimpContFract /-- A simple continued fraction is a *(regular) continued fraction* ((r)cf) if all partial denominators `bᵢ` are positive, i.e. `0 < bᵢ`. -/ def SimpContFract.IsContFract [One α] [Zero α] [LT α] (s : SimpContFract α) : Prop := ∀ (n : ℕ) (bₙ : α), (↑s : GenContFract α).partDens.get? n = some bₙ → 0 < bₙ variable (α) in /-- A *(regular) continued fraction* ((r)cf) is a simple continued fraction (scf) whose partial denominators are all positive. It is the subtype of scfs that satisfy `SimpContFract.IsContFract`. -/ def ContFract [One α] [Zero α] [LT α] := { s : SimpContFract α // s.IsContFract } /-! Interlude: define some expected coercions. -/ namespace ContFract variable [One α] [Zero α] [LT α] /-- Constructs a continued fraction without fractional part. -/ def ofInteger (a : α) : ContFract α := ⟨SimpContFract.ofInteger a, fun n bₙ h ↦ by cases h⟩ instance : Inhabited (ContFract α) := ⟨ofInteger 0⟩ /-- Lift a cf to a scf using the inclusion map. -/ instance : Coe (ContFract α) (SimpContFract α) := ⟨Subtype.val⟩ /-- Lift a cf to a scf using the inclusion map. -/ instance : Coe (ContFract α) (GenContFract α) := ⟨fun c ↦ c.val⟩ end ContFract namespace GenContFract /-! ### Computation of Convergents We now define how to compute the convergents of a gcf. There are two standard ways to do this: directly evaluating the (infinite) fraction described by the gcf or using a recurrence relation. For (r)cfs, these computations are equivalent as shown in `Algebra.ContinuedFractions.ConvergentsEquiv`. -/ -- Fix a division ring for the computations. variable {K : Type*} [DivisionRing K] /-! We start with the definition of the recurrence relation. Given a gcf `g`, for all `n ≥ 1`, we define - `A₋₁ = 1, A₀ = h, Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, and - `B₋₁ = 0, B₀ = 1, Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`. `Aₙ, Bₙ` are called the *nth continuants*, `Aₙ` the *nth numerator*, and `Bₙ` the *nth denominator* of `g`. The *nth convergent* of `g` is given by `Aₙ / Bₙ`. -/ /-- Returns the next numerator `Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, where `predA` is `Aₙ₋₁`, `ppredA` is `Aₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`. -/ def nextNum (a b ppredA predA : K) : K := b * predA + a * ppredA /-- Returns the next denominator `Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`, where `predB` is `Bₙ₋₁` and `ppredB` is `Bₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`. -/ def nextDen (aₙ bₙ ppredB predB : K) : K := bₙ * predB + aₙ * ppredB /-- Returns the next continuants `⟨Aₙ, Bₙ⟩` using `nextNum` and `nextDen`, where `pred` is `⟨Aₙ₋₁, Bₙ₋₁⟩`, `ppred` is `⟨Aₙ₋₂, Bₙ₋₂⟩`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`. -/ def nextConts (a b : K) (ppred pred : Pair K) : Pair K := ⟨nextNum a b ppred.a pred.a, nextDen a b ppred.b pred.b⟩ /-- Returns the continuants `⟨Aₙ₋₁, Bₙ₋₁⟩` of `g`. -/ def contsAux (g : GenContFract K) : Stream' (Pair K) | 0 => ⟨1, 0⟩ | 1 => ⟨g.h, 1⟩ | n + 2 => match g.s.get? n with | none => contsAux g (n + 1) | some gp => nextConts gp.a gp.b (contsAux g n) (contsAux g (n + 1)) /-- Returns the continuants `⟨Aₙ, Bₙ⟩` of `g`. -/ def conts (g : GenContFract K) : Stream' (Pair K) := g.contsAux.tail /-- Returns the numerators `Aₙ` of `g`. -/ def nums (g : GenContFract K) : Stream' K := g.conts.map Pair.a /-- Returns the denominators `Bₙ` of `g`. -/ def dens (g : GenContFract K) : Stream' K := g.conts.map Pair.b /-- Returns the convergents `Aₙ / Bₙ` of `g`, where `Aₙ, Bₙ` are the nth continuants of `g`. -/ def convs (g : GenContFract K) : Stream' K := fun n : ℕ ↦ g.nums n / g.dens n /-- Returns the approximation of the fraction described by the given sequence up to a given position n. For example, `convs'Aux [(1, 2), (3, 4), (5, 6)] 2 = 1 / (2 + 3 / 4)` and `convs'Aux [(1, 2), (3, 4), (5, 6)] 0 = 0`. -/ def convs'Aux : Stream'.Seq (Pair K) → ℕ → K | _, 0 => 0 | s, n + 1 => match s.head with | none => 0 | some gp => gp.a / (gp.b + convs'Aux s.tail n) /-- Returns the convergents of `g` by evaluating the fraction described by `g` up to a given position `n`. For example, `convs' [9; (1, 2), (3, 4), (5, 6)] 2 = 9 + 1 / (2 + 3 / 4)` and `convs' [9; (1, 2), (3, 4), (5, 6)] 0 = 9` -/ def convs' (g : GenContFract K) (n : ℕ) : K := g.h + convs'Aux g.s n end GenContFract
.lake/packages/mathlib/Mathlib/Algebra/ContinuedFractions/ConvergentsEquiv.lean
import Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence import Mathlib.Algebra.ContinuedFractions.TerminatedStable import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Ring /-! # Equivalence of Recursive and Direct Computations of Convergents of Generalized Continued Fractions ## Summary We show the equivalence of two computations of convergents (recurrence relation (`convs`) vs. direct evaluation (`convs'`)) for generalized continued fractions (`GenContFract`s) on linear ordered fields. We follow the proof from [hardy2008introduction], Chapter 10. Here's a sketch: Let `c` be a continued fraction `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`, visually: $$ c = h + \dfrac{a_0} {b_0 + \dfrac{a_1} {b_1 + \dfrac{a_2} {b_2 + \dfrac{a_3} {b_3 + \dots}}}} $$ One can compute the convergents of `c` in two ways: 1. Directly evaluating the fraction described by `c` up to a given `n` (`convs'`) 2. Using the recurrence (`convs`): - `A₋₁ = 1, A₀ = h, Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, and - `B₋₁ = 0, B₀ = 1, Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`. To show the equivalence of the computations in the main theorem of this file `convs_eq_convs'`, we proceed by induction. The case `n = 0` is trivial. For `n + 1`, we first "squash" the `n + 1`th position of `c` into the `n`th position to obtain another continued fraction `c' := [h; (a₀, b₀),..., (aₙ-₁, bₙ-₁), (aₙ, bₙ + aₙ₊₁ / bₙ₊₁), (aₙ₊₁, bₙ₊₁),...]`. This squashing process is formalised in section `Squash`. Note that directly evaluating `c` up to position `n + 1` is equal to evaluating `c'` up to `n`. This is shown in lemma `succ_nth_conv'_eq_squashGCF_nth_conv'`. By the inductive hypothesis, the two computations for the `n`th convergent of `c` coincide. So all that is left to show is that the recurrence relation for `c` at `n + 1` and `c'` at `n` coincide. This can be shown by another induction. The corresponding lemma in this file is `succ_nth_conv_eq_squashGCF_nth_conv`. ## Main Theorems - `GenContFract.convs_eq_convs'` shows the equivalence under a strict positivity restriction on the sequence. - `ContFract.convs_eq_convs'` shows the equivalence for regular continued fractions. ## References - https://en.wikipedia.org/wiki/Generalized_continued_fraction - [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction] ## Tags fractions, recurrence, equivalence -/ variable {K : Type*} {n : ℕ} namespace GenContFract variable {g : GenContFract K} {s : Stream'.Seq <| Pair K} section Squash /-! We will show the equivalence of the computations by induction. To make the induction work, we need to be able to *squash* the nth and (n + 1)th value of a sequence. This squashing itself and the lemmas about it are not very interesting. As a reader, you hence might want to skip this section. -/ section WithDivisionRing variable [DivisionRing K] /-- Given a sequence of `GenContFract.Pair`s `s = [(a₀, b₀), (a₁, b₁), ...]`, `squashSeq s n` combines `⟨aₙ, bₙ⟩` and `⟨aₙ₊₁, bₙ₊₁⟩` at position `n` to `⟨aₙ, bₙ + aₙ₊₁ / bₙ₊₁⟩`. For example, `squashSeq s 0 = [(a₀, b₀ + a₁ / b₁), (a₁, b₁),...]`. If `s.TerminatedAt (n + 1)`, then `squashSeq s n = s`. -/ def squashSeq (s : Stream'.Seq <| Pair K) (n : ℕ) : Stream'.Seq (Pair K) := match Prod.mk (s.get? n) (s.get? (n + 1)) with | ⟨some gp_n, some gp_succ_n⟩ => Stream'.Seq.nats.zipWith -- return the squashed value at position `n`; otherwise, do nothing. (fun n' gp => if n' = n then ⟨gp_n.a, gp_n.b + gp_succ_n.a / gp_succ_n.b⟩ else gp) s | _ => s /-! We now prove some simple lemmas about the squashed sequence -/ /-- If the sequence already terminated at position `n + 1`, nothing gets squashed. -/ theorem squashSeq_eq_self_of_terminated (terminatedAt_succ_n : s.TerminatedAt (n + 1)) : squashSeq s n = s := by change s.get? (n + 1) = none at terminatedAt_succ_n cases s_nth_eq : s.get? n <;> simp only [*, squashSeq] /-- If the sequence has not terminated before position `n + 1`, the value at `n + 1` gets squashed into position `n`. -/ theorem squashSeq_nth_of_not_terminated {gp_n gp_succ_n : Pair K} (s_nth_eq : s.get? n = some gp_n) (s_succ_nth_eq : s.get? (n + 1) = some gp_succ_n) : (squashSeq s n).get? n = some ⟨gp_n.a, gp_n.b + gp_succ_n.a / gp_succ_n.b⟩ := by simp [*, squashSeq] /-- The values before the squashed position stay the same. -/ theorem squashSeq_nth_of_lt {m : ℕ} (m_lt_n : m < n) : (squashSeq s n).get? m = s.get? m := by cases s_succ_nth_eq : s.get? (n + 1) with | none => rw [squashSeq_eq_self_of_terminated s_succ_nth_eq] | some => obtain ⟨gp_n, s_nth_eq⟩ : ∃ gp_n, s.get? n = some gp_n := s.ge_stable n.le_succ s_succ_nth_eq simp [*, squashSeq, m_lt_n.ne] /-- Squashing at position `n + 1` and taking the tail is the same as squashing the tail of the sequence at position `n`. -/ theorem squashSeq_succ_n_tail_eq_squashSeq_tail_n : (squashSeq s (n + 1)).tail = squashSeq s.tail n := by cases s_succ_succ_nth_eq : s.get? (n + 2) with | none => cases s_succ_nth_eq : s.get? (n + 1) <;> simp only [squashSeq, Stream'.Seq.get?_tail, s_succ_nth_eq, s_succ_succ_nth_eq] | some gp_succ_succ_n => obtain ⟨gp_succ_n, s_succ_nth_eq⟩ : ∃ gp_succ_n, s.get? (n + 1) = some gp_succ_n := s.ge_stable (n + 1).le_succ s_succ_succ_nth_eq -- apply extensionality with `m` and continue by cases `m = n`. ext1 m rcases Decidable.em (m = n) with m_eq_n | m_ne_n · simp [*, squashSeq] · cases s_succ_mth_eq : s.get? (m + 1) · simp only [*, squashSeq, Stream'.Seq.get?_tail, Stream'.Seq.get?_zipWith, Option.map₂_none_right] · simp [*, squashSeq] /-- The auxiliary function `convs'Aux` returns the same value for a sequence and the corresponding squashed sequence at the squashed position. -/ theorem succ_succ_nth_conv'Aux_eq_succ_nth_conv'Aux_squashSeq : convs'Aux s (n + 2) = convs'Aux (squashSeq s n) (n + 1) := by cases s_succ_nth_eq : s.get? <| n + 1 with | none => rw [squashSeq_eq_self_of_terminated s_succ_nth_eq, convs'Aux_stable_step_of_terminated s_succ_nth_eq] | some gp_succ_n => induction n generalizing s gp_succ_n with | zero => obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head := s.ge_stable zero_le_one s_succ_nth_eq have : (squashSeq s 0).head = some ⟨gp_head.a, gp_head.b + gp_succ_n.a / gp_succ_n.b⟩ := squashSeq_nth_of_not_terminated s_head_eq s_succ_nth_eq simp_all [convs'Aux, Stream'.Seq.head, Stream'.Seq.get?_tail] | succ m IH => obtain ⟨gp_head, s_head_eq⟩ : ∃ gp_head, s.head = some gp_head := s.ge_stable (m + 2).zero_le s_succ_nth_eq suffices gp_head.a / (gp_head.b + convs'Aux s.tail (m + 2)) = convs'Aux (squashSeq s (m + 1)) (m + 2) by simpa only [convs'Aux, s_head_eq] have : (squashSeq s (m + 1)).head = some gp_head := (squashSeq_nth_of_lt m.succ_pos).trans s_head_eq simp_all [convs'Aux, squashSeq_succ_n_tail_eq_squashSeq_tail_n] /-! Let us now lift the squashing operation to gcfs. -/ /-- Given a gcf `g = [h; (a₀, b₀), (a₁, b₁), ...]`, we have - `squashGCF g 0 = [h + a₀ / b₀; (a₁, b₁), ...]`, - `squashGCF g (n + 1) = ⟨g.h, squashSeq g.s n⟩` -/ def squashGCF (g : GenContFract K) : ℕ → GenContFract K | 0 => match g.s.get? 0 with | none => g | some gp => ⟨g.h + gp.a / gp.b, g.s⟩ | n + 1 => ⟨g.h, squashSeq g.s n⟩ /-! Again, we derive some simple lemmas that are not really of interest. This time for the squashed gcf. -/ /-- If the gcf already terminated at position `n`, nothing gets squashed. -/ theorem squashGCF_eq_self_of_terminated (terminatedAt_n : TerminatedAt g n) : squashGCF g n = g := by cases n with | zero => change g.s.get? 0 = none at terminatedAt_n simp only [squashGCF, terminatedAt_n] | succ => cases g simp only [squashGCF, mk.injEq, true_and] exact squashSeq_eq_self_of_terminated terminatedAt_n /-- The values before the squashed position stay the same. -/ theorem squashGCF_nth_of_lt {m : ℕ} (m_lt_n : m < n) : (squashGCF g (n + 1)).s.get? m = g.s.get? m := by simp only [squashGCF, squashSeq_nth_of_lt m_lt_n] /-- `convs'` returns the same value for a gcf and the corresponding squashed gcf at the squashed position. -/ theorem succ_nth_conv'_eq_squashGCF_nth_conv' : g.convs' (n + 1) = (squashGCF g n).convs' n := by cases n with | zero => cases g_s_head_eq : g.s.get? 0 <;> simp [g_s_head_eq, squashGCF, convs', convs'Aux, Stream'.Seq.head] | succ => simp only [succ_succ_nth_conv'Aux_eq_succ_nth_conv'Aux_squashSeq, convs', squashGCF] /-- The auxiliary continuants before the squashed position stay the same. -/ theorem contsAux_eq_contsAux_squashGCF_of_le {m : ℕ} : m ≤ n → contsAux g m = (squashGCF g n).contsAux m := Nat.strong_induction_on m (by clear m intro m IH m_le_n rcases m with - | m' · rfl · rcases n with - | n' · exact (m'.not_succ_le_zero m_le_n).elim -- 1 ≰ 0 · rcases m' with - | m'' · rfl · -- get some inequalities to instantiate the IH for m'' and m'' + 1 have m'_lt_n : m'' + 1 < n' + 1 := m_le_n have succ_m''th_contsAux_eq := IH (m'' + 1) (lt_add_one (m'' + 1)) m'_lt_n.le have : m'' < m'' + 2 := lt_add_of_pos_right m'' zero_lt_two have m''th_contsAux_eq := IH m'' this (le_trans this.le m_le_n) have : (squashGCF g (n' + 1)).s.get? m'' = g.s.get? m'' := squashGCF_nth_of_lt (Nat.succ_lt_succ_iff.mp m'_lt_n) simp [contsAux, succ_m''th_contsAux_eq, m''th_contsAux_eq, this]) end WithDivisionRing /-- The convergents coincide in the expected way at the squashed position if the partial denominator at the squashed position is not zero. -/ theorem succ_nth_conv_eq_squashGCF_nth_conv [Field K] (nth_partDen_ne_zero : ∀ {b : K}, g.partDens.get? n = some b → b ≠ 0) : g.convs (n + 1) = (squashGCF g n).convs n := by rcases Decidable.em (g.TerminatedAt n) with terminatedAt_n | not_terminatedAt_n · have : squashGCF g n = g := squashGCF_eq_self_of_terminated terminatedAt_n simp only [this, convs_stable_of_terminated n.le_succ terminatedAt_n] · obtain ⟨⟨a, b⟩, s_nth_eq⟩ : ∃ gp_n, g.s.get? n = some gp_n := Option.ne_none_iff_exists'.mp not_terminatedAt_n have b_ne_zero : b ≠ 0 := nth_partDen_ne_zero (partDen_eq_s_b s_nth_eq) cases n with | zero => suffices (b * g.h + a) / b = g.h + a / b by simpa [squashGCF, s_nth_eq, conv_eq_conts_a_div_conts_b, conts_recurrenceAux s_nth_eq zeroth_contAux_eq_one_zero first_contAux_eq_h_one] grind | succ n' => obtain ⟨⟨pa, pb⟩, s_n'th_eq⟩ : ∃ gp_n', g.s.get? n' = some gp_n' := g.s.ge_stable n'.le_succ s_nth_eq -- Notations let g' := squashGCF g (n' + 1) set pred_conts := g.contsAux (n' + 1) with succ_n'th_contsAux_eq set ppred_conts := g.contsAux n' with n'th_contsAux_eq let pA := pred_conts.a let pB := pred_conts.b let ppA := ppred_conts.a let ppB := ppred_conts.b set pred_conts' := g'.contsAux (n' + 1) with succ_n'th_contsAux_eq' set ppred_conts' := g'.contsAux n' with n'th_contsAux_eq' let pA' := pred_conts'.a let pB' := pred_conts'.b let ppA' := ppred_conts'.a let ppB' := ppred_conts'.b -- first compute the convergent of the squashed gcf have : g'.convs (n' + 1) = ((pb + a / b) * pA' + pa * ppA') / ((pb + a / b) * pB' + pa * ppB') := by have : g'.s.get? n' = some ⟨pa, pb + a / b⟩ := squashSeq_nth_of_not_terminated s_n'th_eq s_nth_eq rw [conv_eq_conts_a_div_conts_b, conts_recurrenceAux this n'th_contsAux_eq'.symm succ_n'th_contsAux_eq'.symm] rw [this] -- then compute the convergent of the original gcf by recursively unfolding the continuants -- computation twice have : g.convs (n' + 2) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) := by -- use the recurrence once have : g.contsAux (n' + 2) = ⟨pb * pA + pa * ppA, pb * pB + pa * ppB⟩ := contsAux_recurrence s_n'th_eq n'th_contsAux_eq.symm succ_n'th_contsAux_eq.symm -- and a second time rw [conv_eq_conts_a_div_conts_b, conts_recurrenceAux s_nth_eq succ_n'th_contsAux_eq.symm this] rw [this] suffices ((pb + a / b) * pA + pa * ppA) / ((pb + a / b) * pB + pa * ppB) = (b * (pb * pA + pa * ppA) + a * pA) / (b * (pb * pB + pa * ppB) + a * pB) by obtain ⟨eq1, eq2, eq3, eq4⟩ : pA' = pA ∧ pB' = pB ∧ ppA' = ppA ∧ ppB' = ppB := by simp [*, g', pA, pB, ppA, ppB, pA', pB', ppA', ppB', (contsAux_eq_contsAux_squashGCF_of_le <| le_refl <| n' + 1).symm, (contsAux_eq_contsAux_squashGCF_of_le n'.le_succ).symm] symm simpa only [eq1, eq2, eq3, eq4, mul_div_cancel_right₀ _ b_ne_zero] grind end Squash /-- Shows that the recurrence relation (`convs`) and direct evaluation (`convs'`) of the generalized continued fraction coincide at position `n` if the sequence of fractions contains strictly positive values only. Requiring positivity of all values is just one possible condition to obtain this result. For example, the dual - sequences with strictly negative values only - would also work. In practice, one most commonly deals with regular continued fractions, which satisfy the positivity criterion required here. The analogous result for them (see `ContFract.convs_eq_convs'`) hence follows directly from this theorem. -/ theorem convs_eq_convs' [Field K] [LinearOrder K] [IsStrictOrderedRing K] (s_pos : ∀ {gp : Pair K} {m : ℕ}, m < n → g.s.get? m = some gp → 0 < gp.a ∧ 0 < gp.b) : g.convs n = g.convs' n := by induction n generalizing g with | zero => simp | succ n IH => let g' := squashGCF g n -- first replace the rhs with the squashed computation suffices g.convs (n + 1) = g'.convs' n by rwa [succ_nth_conv'_eq_squashGCF_nth_conv'] rcases Decidable.em (TerminatedAt g n) with terminatedAt_n | not_terminatedAt_n · have g'_eq_g : g' = g := squashGCF_eq_self_of_terminated terminatedAt_n rw [convs_stable_of_terminated n.le_succ terminatedAt_n, g'_eq_g, IH _] intro _ _ m_lt_n s_mth_eq exact s_pos (Nat.lt.step m_lt_n) s_mth_eq · suffices g.convs (n + 1) = g'.convs n by -- invoke the IH for the squashed gcf rwa [← IH] intro gp' m m_lt_n s_mth_eq' -- case distinction on m + 1 = n or m + 1 < n rcases m_lt_n with n | succ_m_lt_n · -- the difficult case at the squashed position: we first obtain the values from -- the sequence obtain ⟨gp_succ_m, s_succ_mth_eq⟩ : ∃ gp_succ_m, g.s.get? (m + 1) = some gp_succ_m := Option.ne_none_iff_exists'.mp not_terminatedAt_n obtain ⟨gp_m, mth_s_eq⟩ : ∃ gp_m, g.s.get? m = some gp_m := g.s.ge_stable m.le_succ s_succ_mth_eq -- we then plug them into the recurrence suffices 0 < gp_m.a ∧ 0 < gp_m.b + gp_succ_m.a / gp_succ_m.b by have ot : g'.s.get? m = some ⟨gp_m.a, gp_m.b + gp_succ_m.a / gp_succ_m.b⟩ := squashSeq_nth_of_not_terminated mth_s_eq s_succ_mth_eq grind have m_lt_n : m < m.succ := Nat.lt_succ_self m refine ⟨(s_pos (Nat.lt.step m_lt_n) mth_s_eq).left, ?_⟩ refine add_pos (s_pos (Nat.lt.step m_lt_n) mth_s_eq).right ?_ have : 0 < gp_succ_m.a ∧ 0 < gp_succ_m.b := s_pos (lt_add_one <| m + 1) s_succ_mth_eq exact div_pos this.left this.right · -- the easy case: before the squashed position, nothing changes refine s_pos (Nat.lt.step <| Nat.lt.step succ_m_lt_n) ?_ exact Eq.trans (squashGCF_nth_of_lt succ_m_lt_n).symm s_mth_eq' -- now the result follows from the fact that the convergents coincide at the squashed position -- as established in `succ_nth_conv_eq_squashGCF_nth_conv`. have : ∀ ⦃b⦄, g.partDens.get? n = some b → b ≠ 0 := by intro b nth_partDen_eq obtain ⟨gp, s_nth_eq, ⟨refl⟩⟩ : ∃ gp, g.s.get? n = some gp ∧ gp.b = b := exists_s_b_of_partDen nth_partDen_eq exact (ne_of_lt (s_pos (lt_add_one n) s_nth_eq).right).symm exact succ_nth_conv_eq_squashGCF_nth_conv @this end GenContFract open GenContFract namespace ContFract /-- Shows that the recurrence relation (`convs`) and direct evaluation (`convs'`) of a (regular) continued fraction coincide. -/ theorem convs_eq_convs' [Field K] [LinearOrder K] [IsStrictOrderedRing K] {c : ContFract K} : (↑c : GenContFract K).convs = (↑c : GenContFract K).convs' := by ext n apply GenContFract.convs_eq_convs' intro gp m _ s_nth_eq exact ⟨zero_lt_one.trans_le ((c : SimpContFract K).property m gp.a (partNum_eq_s_a s_nth_eq)).symm.le, c.property m gp.b <| partDen_eq_s_b s_nth_eq⟩ end ContFract
.lake/packages/mathlib/Mathlib/Algebra/ContinuedFractions/Translations.lean
import Mathlib.Algebra.ContinuedFractions.Basic import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Data.Seq.Basic /-! # Basic Translation Lemmas Between Functions Defined for Continued Fractions ## Summary Some simple translation lemmas between the different definitions of functions defined in `Algebra.ContinuedFractions.Basic`. -/ namespace GenContFract section General /-! ### Translations Between General Access Functions Here we give some basic translations that hold by definition between the various methods that allow us to access the numerators and denominators of a continued fraction. -/ variable {α : Type*} {g : GenContFract α} {n : ℕ} theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq] theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by rw [terminatedAt_iff_s_none, partNum_none_iff_s_none] theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq] theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by rw [terminatedAt_iff_s_none, partDen_none_iff_s_none] theorem partNum_eq_s_a {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) : g.partNums.get? n = some gp.a := by simp [partNums, s_nth_eq] theorem partDen_eq_s_b {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) : g.partDens.get? n = some gp.b := by simp [partDens, s_nth_eq] theorem exists_s_a_of_partNum {a : α} (nth_partNum_eq : g.partNums.get? n = some a) : ∃ gp, g.s.get? n = some gp ∧ gp.a = a := by simpa [partNums, Stream'.Seq.map_get?] using nth_partNum_eq theorem exists_s_b_of_partDen {b : α} (nth_partDen_eq : g.partDens.get? n = some b) : ∃ gp, g.s.get? n = some gp ∧ gp.b = b := by simpa [partDens, Stream'.Seq.map_get?] using nth_partDen_eq end General section WithDivisionRing /-! ### Translations Between Computational Functions Here we give some basic translations that hold by definition for the computational methods of a continued fraction. -/ variable {K : Type*} {g : GenContFract K} {n : ℕ} [DivisionRing K] theorem nth_cont_eq_succ_nth_contAux : g.conts n = g.contsAux (n + 1) := rfl theorem num_eq_conts_a : g.nums n = (g.conts n).a := rfl theorem den_eq_conts_b : g.dens n = (g.conts n).b := rfl theorem conv_eq_num_div_den : g.convs n = g.nums n / g.dens n := rfl theorem conv_eq_conts_a_div_conts_b : g.convs n = (g.conts n).a / (g.conts n).b := rfl theorem exists_conts_a_of_num {A : K} (nth_num_eq : g.nums n = A) : ∃ conts, g.conts n = conts ∧ conts.a = A := by simpa theorem exists_conts_b_of_den {B : K} (nth_denom_eq : g.dens n = B) : ∃ conts, g.conts n = conts ∧ conts.b = B := by simpa @[simp] theorem zeroth_contAux_eq_one_zero : g.contsAux 0 = ⟨1, 0⟩ := rfl @[simp] theorem first_contAux_eq_h_one : g.contsAux 1 = ⟨g.h, 1⟩ := rfl @[simp] theorem zeroth_cont_eq_h_one : g.conts 0 = ⟨g.h, 1⟩ := rfl @[simp] theorem zeroth_num_eq_h : g.nums 0 = g.h := rfl @[simp] theorem zeroth_den_eq_one : g.dens 0 = 1 := rfl @[simp] theorem zeroth_conv_eq_h : g.convs 0 = g.h := by simp [conv_eq_num_div_den, num_eq_conts_a, den_eq_conts_b, div_one] theorem second_contAux_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.contsAux 2 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by simp [zeroth_s_eq, contsAux, nextConts, nextDen, nextNum] theorem first_cont_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.conts 1 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by simp [nth_cont_eq_succ_nth_contAux, second_contAux_eq zeroth_s_eq] theorem first_num_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.nums 1 = gp.b * g.h + gp.a := by simp [num_eq_conts_a, first_cont_eq zeroth_s_eq] theorem first_den_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.dens 1 = gp.b := by simp [den_eq_conts_b, first_cont_eq zeroth_s_eq] @[simp] theorem zeroth_conv'Aux_eq_zero {s : Stream'.Seq <| Pair K} : convs'Aux s 0 = (0 : K) := rfl @[simp] theorem zeroth_conv'_eq_h : g.convs' 0 = g.h := by simp [convs'] theorem convs'Aux_succ_none {s : Stream'.Seq (Pair K)} (h : s.head = none) (n : ℕ) : convs'Aux s (n + 1) = 0 := by simp [convs'Aux, h] theorem convs'Aux_succ_some {s : Stream'.Seq (Pair K)} {p : Pair K} (h : s.head = some p) (n : ℕ) : convs'Aux s (n + 1) = p.a / (p.b + convs'Aux s.tail n) := by simp [convs'Aux, h] end WithDivisionRing end GenContFract
.lake/packages/mathlib/Mathlib/Algebra/ContinuedFractions/ContinuantsRecurrence.lean
import Mathlib.Algebra.ContinuedFractions.Translations /-! # Recurrence Lemmas for the Continuants (`conts`) Function of Continued Fractions ## Summary Given a generalized continued fraction `g`, for all `n ≥ 1`, we prove that the continuants (`conts`) function indeed satisfies the following recurrences: - `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`, and - `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ namespace GenContFract variable {K : Type*} {g : GenContFract K} {n : ℕ} [DivisionRing K] theorem contsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_contsAux_eq : g.contsAux n = ppred) (succ_nth_contsAux_eq : g.contsAux (n + 1) = pred) : g.contsAux (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [*, contsAux, nextConts, nextDen, nextNum] theorem conts_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp) (nth_contsAux_eq : g.contsAux n = ppred) (succ_nth_contsAux_eq : g.contsAux (n + 1) = pred) : g.conts (n + 1) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by simp [nth_cont_eq_succ_nth_contAux, contsAux_recurrence nth_s_eq nth_contsAux_eq succ_nth_contsAux_eq] /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂` and `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem conts_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_conts_eq : g.conts n = ppred) (succ_nth_conts_eq : g.conts (n + 1) = pred) : g.conts (n + 2) = ⟨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.b⟩ := by rw [nth_cont_eq_succ_nth_contAux] at nth_conts_eq succ_nth_conts_eq exact conts_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq /-- Shows that `Aₙ = bₙ * Aₙ₋₁ + aₙ * Aₙ₋₂`. -/ theorem nums_recurrence {gp : Pair K} {ppredA predA : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.nums n = ppredA) (succ_nth_num_eq : g.nums (n + 1) = predA) : g.nums (n + 2) = gp.b * predA + gp.a * ppredA := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.conts n = conts ∧ conts.a = ppredA := exists_conts_a_of_num nth_num_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.conts (n + 1) = conts ∧ conts.a = predA := exists_conts_a_of_num succ_nth_num_eq rw [num_eq_conts_a, conts_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq] /-- Shows that `Bₙ = bₙ * Bₙ₋₁ + aₙ * Bₙ₋₂`. -/ theorem dens_recurrence {gp : Pair K} {ppredB predB : K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_den_eq : g.dens n = ppredB) (succ_nth_den_eq : g.dens (n + 1) = predB) : g.dens (n + 2) = gp.b * predB + gp.a * ppredB := by obtain ⟨ppredConts, nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.conts n = conts ∧ conts.b = ppredB := exists_conts_b_of_den nth_den_eq obtain ⟨predConts, succ_nth_conts_eq, ⟨rfl⟩⟩ : ∃ conts, g.conts (n + 1) = conts ∧ conts.b = predB := exists_conts_b_of_den succ_nth_den_eq rw [den_eq_conts_b, conts_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq] end GenContFract
.lake/packages/mathlib/Mathlib/Algebra/ContinuedFractions/Determinant.lean
import Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence import Mathlib.Algebra.ContinuedFractions.TerminatedStable import Mathlib.Tactic.Ring /-! # Determinant Formula for Simple Continued Fraction ## Summary We derive the so-called *determinant formula* for `SimpContFract`: `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`. ## TODO Generalize this for `GenContFract` version: `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-a₀) * (-a₁) * .. * (-aₙ₊₁)`. ## References - https://en.wikipedia.org/wiki/Generalized_continued_fraction#The_determinant_formula -/ open GenContFract namespace SimpContFract variable {K : Type*} [Field K] {s : SimpContFract K} {n : ℕ} theorem determinant_aux (hyp : n = 0 ∨ ¬(↑s : GenContFract K).TerminatedAt (n - 1)) : ((↑s : GenContFract K).contsAux n).a * ((↑s : GenContFract K).contsAux (n + 1)).b - ((↑s : GenContFract K).contsAux n).b * ((↑s : GenContFract K).contsAux (n + 1)).a = (-1) ^ n := by induction n with | zero => simp [contsAux] | succ n IH => -- set up some shorthand notation let g := (↑s : GenContFract K) let conts := contsAux g (n + 2) set pred_conts := contsAux g (n + 1) with pred_conts_eq set ppred_conts := contsAux g n with ppred_conts_eq let pA := pred_conts.a let pB := pred_conts.b let ppA := ppred_conts.a let ppB := ppred_conts.b -- let's change the goal to something more readable change pA * conts.b - pB * conts.a = (-1) ^ (n + 1) have not_terminated_at_n : ¬TerminatedAt g n := Or.resolve_left hyp n.succ_ne_zero obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp := Option.ne_none_iff_exists'.1 not_terminated_at_n -- unfold the recurrence relation for `conts` once and simplify to derive the following suffices pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1) by simp only [conts, contsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq] have gp_a_eq_one : gp.a = 1 := s.property _ _ (partNum_eq_s_a s_nth_eq) rw [gp_a_eq_one, this.symm] ring suffices ppA * pB - ppB * pA = (-1) ^ n by grind exact IH <| Or.inr <| mt (terminated_stable <| n.sub_le 1) not_terminated_at_n /-- The determinant formula `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`. -/ theorem determinant (not_terminatedAt_n : ¬(↑s : GenContFract K).TerminatedAt n) : (↑s : GenContFract K).nums n * (↑s : GenContFract K).dens (n + 1) - (↑s : GenContFract K).dens n * (↑s : GenContFract K).nums (n + 1) = (-1) ^ (n + 1) := determinant_aux <| Or.inr <| not_terminatedAt_n end SimpContFract
.lake/packages/mathlib/Mathlib/Algebra/ContinuedFractions/TerminatedStable.lean
import Mathlib.Algebra.ContinuedFractions.Translations /-! # Stabilisation of gcf Computations Under Termination ## Summary We show that the continuants and convergents of a gcf stabilise once the gcf terminates. -/ namespace GenContFract variable {K : Type*} {g : GenContFract K} {n m : ℕ} /-- If a gcf terminated at position `n`, it also terminated at `m ≥ n`. -/ theorem terminated_stable (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) : g.TerminatedAt m := g.s.terminated_stable n_le_m terminatedAt_n variable [DivisionRing K] theorem contsAux_stable_step_of_terminated (terminatedAt_n : g.TerminatedAt n) : g.contsAux (n + 2) = g.contsAux (n + 1) := by rw [terminatedAt_iff_s_none] at terminatedAt_n simp only [contsAux, terminatedAt_n] theorem contsAux_stable_of_terminated (n_lt_m : n < m) (terminatedAt_n : g.TerminatedAt n) : g.contsAux m = g.contsAux (n + 1) := by refine Nat.le_induction rfl (fun k hnk hk => ?_) _ n_lt_m rcases Nat.exists_eq_add_of_lt hnk with ⟨k, rfl⟩ refine (contsAux_stable_step_of_terminated ?_).trans hk exact terminated_stable (Nat.le_add_right _ _) terminatedAt_n theorem convs'Aux_stable_step_of_terminated {s : Stream'.Seq <| Pair K} (terminatedAt_n : s.TerminatedAt n) : convs'Aux s (n + 1) = convs'Aux s n := by change s.get? n = none at terminatedAt_n induction n generalizing s with | zero => simp only [convs'Aux, terminatedAt_n, Stream'.Seq.head] | succ n IH => cases s_head_eq : s.head with | none => simp only [convs'Aux, s_head_eq] | some gp_head => have : s.tail.TerminatedAt n := by simp only [Stream'.Seq.TerminatedAt, s.get?_tail, terminatedAt_n] have := IH this rw [convs'Aux] at this simp [this, convs'Aux, s_head_eq] theorem convs'Aux_stable_of_terminated {s : Stream'.Seq <| Pair K} (n_le_m : n ≤ m) (terminatedAt_n : s.TerminatedAt n) : convs'Aux s m = convs'Aux s n := by induction n_le_m with | refl => rfl | step n_le_m IH => refine (convs'Aux_stable_step_of_terminated (?_)).trans IH exact s.terminated_stable n_le_m terminatedAt_n theorem conts_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) : g.conts m = g.conts n := by simp only [nth_cont_eq_succ_nth_contAux, contsAux_stable_of_terminated (Nat.pred_le_iff.mp n_le_m) terminatedAt_n] theorem nums_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) : g.nums m = g.nums n := by simp only [num_eq_conts_a, conts_stable_of_terminated n_le_m terminatedAt_n] theorem dens_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) : g.dens m = g.dens n := by simp only [den_eq_conts_b, conts_stable_of_terminated n_le_m terminatedAt_n] theorem convs_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) : g.convs m = g.convs n := by simp only [convs, dens_stable_of_terminated n_le_m terminatedAt_n, nums_stable_of_terminated n_le_m terminatedAt_n] theorem convs'_stable_of_terminated (n_le_m : n ≤ m) (terminatedAt_n : g.TerminatedAt n) : g.convs' m = g.convs' n := by simp only [convs', convs'Aux_stable_of_terminated n_le_m terminatedAt_n] end GenContFract
.lake/packages/mathlib/Mathlib/Algebra/ContinuedFractions/Computation/Approximations.lean
import Mathlib.Algebra.ContinuedFractions.Determinant import Mathlib.Algebra.ContinuedFractions.Computation.CorrectnessTerminating import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Data.Nat.Fib.Basic import Mathlib.Tactic.Monotonicity import Mathlib.Tactic.GCongr /-! # Approximations for Continued Fraction Computations (`GenContFract.of`) ## Summary This file contains useful approximations for the values involved in the continued fractions computation `GenContFract.of`. In particular, we show that the generalized continued fraction given by `GenContFract.of` in fact is a (regular) continued fraction. Moreover, we derive some upper bounds for the error term when computing a continued fraction up a given position, i.e. bounds for the term `|v - (GenContFract.of v).convs n|`. The derived bounds will show us that the error term indeed gets smaller. As a corollary, we will be able to show that `(GenContFract.of v).convs` converges to `v` in `Algebra.ContinuedFractions.Computation.ApproximationCorollaries`. ## Main Theorems - `GenContFract.of_partNum_eq_one`: shows that all partial numerators `aᵢ` are equal to one. - `GenContFract.exists_int_eq_of_partDen`: shows that all partial denominators `bᵢ` correspond to an integer. - `GenContFract.of_one_le_get?_partDen`: shows that `1 ≤ bᵢ`. - `ContFract.of` returns the regular continued fraction of a value. - `GenContFract.succ_nth_fib_le_of_nthDen`: shows that the `n`th denominator `Bₙ` is greater than or equal to the `n + 1`th fibonacci number `Nat.fib (n + 1)`. - `GenContFract.le_of_succ_get?_den`: shows that `bₙ * Bₙ ≤ Bₙ₊₁`, where `bₙ` is the `n`th partial denominator of the continued fraction. - `GenContFract.abs_sub_convs_le`: shows that `|v - Aₙ / Bₙ| ≤ 1 / (Bₙ * Bₙ₊₁)`, where `Aₙ` is the `n`th partial numerator. ## References - [*Hardy, GH and Wright, EM and Heath-Brown, Roger and Silverman, Joseph*][hardy2008introduction] -/ open GenContFract open GenContFract (of) open Int variable {K : Type*} {v : K} {n : ℕ} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [FloorRing K] namespace GenContFract namespace IntFractPair /-! We begin with some lemmas about the stream of `IntFractPair`s, which presumably are not of great interest for the end user. -/ /-- Shows that the fractional parts of the stream are in `[0,1)`. -/ theorem nth_stream_fr_nonneg_lt_one {ifp_n : IntFractPair K} (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr ∧ ifp_n.fr < 1 := by cases n with | zero => have : IntFractPair.of v = ifp_n := by injection nth_stream_eq rw [← this, IntFractPair.of] exact ⟨fract_nonneg _, fract_lt_one _⟩ | succ => rcases succ_nth_stream_eq_some_iff.1 nth_stream_eq with ⟨_, _, _, ifp_of_eq_ifp_n⟩ rw [← ifp_of_eq_ifp_n, IntFractPair.of] exact ⟨fract_nonneg _, fract_lt_one _⟩ /-- Shows that the fractional parts of the stream are nonnegative. -/ theorem nth_stream_fr_nonneg {ifp_n : IntFractPair K} (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : 0 ≤ ifp_n.fr := (nth_stream_fr_nonneg_lt_one nth_stream_eq).left /-- Shows that the fractional parts of the stream are smaller than one. -/ theorem nth_stream_fr_lt_one {ifp_n : IntFractPair K} (nth_stream_eq : IntFractPair.stream v n = some ifp_n) : ifp_n.fr < 1 := (nth_stream_fr_nonneg_lt_one nth_stream_eq).right /-- Shows that the integer parts of the stream are at least one. -/ theorem one_le_succ_nth_stream_b {ifp_succ_n : IntFractPair K} (succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : 1 ≤ ifp_succ_n.b := by obtain ⟨ifp_n, nth_stream_eq, stream_nth_fr_ne_zero, ⟨-⟩⟩ : ∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq rw [IntFractPair.of, le_floor, cast_one, one_le_inv₀ ((nth_stream_fr_nonneg nth_stream_eq).lt_of_ne' stream_nth_fr_ne_zero)] exact (nth_stream_fr_lt_one nth_stream_eq).le omit [IsStrictOrderedRing K] in /-- Shows that the `n + 1`th integer part `bₙ₊₁` of the stream is smaller or equal than the inverse of the `n`th fractional part `frₙ` of the stream. This result is straight-forward as `bₙ₊₁` is defined as the floor of `1 / frₙ`. -/ theorem succ_nth_stream_b_le_nth_stream_fr_inv {ifp_n ifp_succ_n : IntFractPair K} (nth_stream_eq : IntFractPair.stream v n = some ifp_n) (succ_nth_stream_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) : (ifp_succ_n.b : K) ≤ ifp_n.fr⁻¹ := by suffices (⌊ifp_n.fr⁻¹⌋ : K) ≤ ifp_n.fr⁻¹ by obtain ⟨_, ifp_n_fr⟩ := ifp_n have : ifp_n_fr ≠ 0 := by intro h simp [h, IntFractPair.stream, nth_stream_eq] at succ_nth_stream_eq have : IntFractPair.of ifp_n_fr⁻¹ = ifp_succ_n := by simpa [this, IntFractPair.stream, nth_stream_eq, Option.coe_def] using succ_nth_stream_eq rwa [← this] exact floor_le ifp_n.fr⁻¹ end IntFractPair /-! Next we translate above results about the stream of `IntFractPair`s to the computed continued fraction `GenContFract.of`. -/ /-- Shows that the integer parts of the continued fraction are at least one. -/ theorem of_one_le_get?_partDen {b : K} (nth_partDen_eq : (of v).partDens.get? n = some b) : 1 ≤ b := by obtain ⟨gp_n, nth_s_eq, ⟨-⟩⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b := exists_s_b_of_partDen nth_partDen_eq obtain ⟨ifp_n, succ_nth_stream_eq, ifp_n_b_eq_gp_n_b⟩ : ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ (ifp.b : K) = gp_n.b := IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq rw [← ifp_n_b_eq_gp_n_b] exact mod_cast IntFractPair.one_le_succ_nth_stream_b succ_nth_stream_eq /-- Shows that the partial numerators `aᵢ` of the continued fraction are equal to one and the partial denominators `bᵢ` correspond to integers. -/ theorem of_partNum_eq_one_and_exists_int_partDen_eq {gp : GenContFract.Pair K} (nth_s_eq : (of v).s.get? n = some gp) : gp.a = 1 ∧ ∃ z : ℤ, gp.b = (z : K) := by obtain ⟨ifp, stream_succ_nth_eq, -⟩ : ∃ ifp, IntFractPair.stream v (n + 1) = some ifp ∧ _ := IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some nth_s_eq have : gp = ⟨1, ifp.b⟩ := by have : (of v).s.get? n = some ⟨1, ifp.b⟩ := get?_of_eq_some_of_succ_get?_intFractPair_stream stream_succ_nth_eq have : some gp = some ⟨1, ifp.b⟩ := by rwa [nth_s_eq] at this injection this simp [this] /-- Shows that the partial numerators `aᵢ` are equal to one. -/ theorem of_partNum_eq_one {a : K} (nth_partNum_eq : (of v).partNums.get? n = some a) : a = 1 := by obtain ⟨gp, nth_s_eq, gp_a_eq_a_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.a = a := exists_s_a_of_partNum nth_partNum_eq have : gp.a = 1 := (of_partNum_eq_one_and_exists_int_partDen_eq nth_s_eq).left rwa [gp_a_eq_a_n] at this /-- Shows that the partial denominators `bᵢ` correspond to an integer. -/ theorem exists_int_eq_of_partDen {b : K} (nth_partDen_eq : (of v).partDens.get? n = some b) : ∃ z : ℤ, b = (z : K) := by obtain ⟨gp, nth_s_eq, gp_b_eq_b_n⟩ : ∃ gp, (of v).s.get? n = some gp ∧ gp.b = b := exists_s_b_of_partDen nth_partDen_eq have : ∃ z : ℤ, gp.b = (z : K) := (of_partNum_eq_one_and_exists_int_partDen_eq nth_s_eq).right rwa [gp_b_eq_b_n] at this end GenContFract variable (v) theorem GenContFract.of_isSimpContFract : (of v).IsSimpContFract := fun _ _ nth_partNum_eq => of_partNum_eq_one nth_partNum_eq /-- Creates the simple continued fraction of a value. -/ def SimpContFract.of : SimpContFract K := ⟨GenContFract.of v, GenContFract.of_isSimpContFract v⟩ theorem SimpContFract.of_isContFract : (SimpContFract.of v).IsContFract := fun _ _ nth_partDen_eq => lt_of_lt_of_le zero_lt_one (of_one_le_get?_partDen nth_partDen_eq) /-- Creates the continued fraction of a value. -/ def ContFract.of : ContFract K := ⟨SimpContFract.of v, SimpContFract.of_isContFract v⟩ variable {v} namespace GenContFract /-! One of our next goals is to show that `bₙ * Bₙ ≤ Bₙ₊₁`. For this, we first show that the partial denominators `Bₙ` are bounded from below by the fibonacci sequence `Nat.fib`. This then implies that `0 ≤ Bₙ` and hence `Bₙ₊₂ = bₙ₊₁ * Bₙ₊₁ + Bₙ ≥ bₙ₊₁ * Bₙ₊₁ + 0 = bₙ₊₁ * Bₙ₊₁`. -/ -- open `Nat` as we will make use of fibonacci numbers. open Nat theorem fib_le_of_contsAux_b : n ≤ 1 ∨ ¬(of v).TerminatedAt (n - 2) → (fib n : K) ≤ ((of v).contsAux n).b := Nat.strong_induction_on n (by intro n IH hyp rcases n with (_ | _ | n) · simp [contsAux] -- case n = 0 · simp [contsAux] -- case n = 1 · let g := of v -- case 2 ≤ n have : ¬n + 2 ≤ 1 := by omega have not_terminatedAt_n : ¬g.TerminatedAt n := Or.resolve_left hyp this obtain ⟨gp, s_ppred_nth_eq⟩ : ∃ gp, g.s.get? n = some gp := Option.ne_none_iff_exists'.mp not_terminatedAt_n set pconts := g.contsAux (n + 1) with pconts_eq set ppconts := g.contsAux n with ppconts_eq -- use the recurrence of `contsAux` simp only [Nat.add_assoc, Nat.reduceAdd] suffices (fib n : K) + fib (n + 1) ≤ gp.a * ppconts.b + gp.b * pconts.b by simpa [g, fib_add_two, add_comm, contsAux_recurrence s_ppred_nth_eq ppconts_eq pconts_eq] -- make use of the fact that `gp.a = 1` suffices (fib n : K) + fib (n + 1) ≤ ppconts.b + gp.b * pconts.b by simpa [of_partNum_eq_one <| partNum_eq_s_a s_ppred_nth_eq] have not_terminatedAt_pred_n : ¬g.TerminatedAt (n - 1) := mt (terminated_stable <| Nat.sub_le n 1) not_terminatedAt_n have not_terminatedAt_ppred_n : ¬TerminatedAt g (n - 2) := mt (terminated_stable (n - 1).pred_le) not_terminatedAt_pred_n -- use the IH to get the inequalities for `pconts` and `ppconts` have ppred_nth_fib_le_ppconts_B : (fib n : K) ≤ ppconts.b := IH n (lt_trans (Nat.lt.base n) <| Nat.lt.base <| n + 1) (Or.inr not_terminatedAt_ppred_n) suffices (fib (n + 1) : K) ≤ gp.b * pconts.b by gcongr -- finally use the fact that `1 ≤ gp.b` to solve the goal suffices 1 * (fib (n + 1) : K) ≤ gp.b * pconts.b by rwa [one_mul] at this have one_le_gp_b : (1 : K) ≤ gp.b := of_one_le_get?_partDen (partDen_eq_s_b s_ppred_nth_eq) gcongr grind) /-- Shows that the `n`th denominator is greater than or equal to the `n + 1`th fibonacci number, that is `Nat.fib (n + 1) ≤ Bₙ`. -/ theorem succ_nth_fib_le_of_nth_den (hyp : n = 0 ∨ ¬(of v).TerminatedAt (n - 1)) : (fib (n + 1) : K) ≤ (of v).dens n := by rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux] have : n + 1 ≤ 1 ∨ ¬(of v).TerminatedAt (n - 1) := by cases n with | zero => exact Or.inl <| le_refl 1 | succ n => exact Or.inr (Or.resolve_left hyp n.succ_ne_zero) exact fib_le_of_contsAux_b this /-! As a simple consequence, we can now derive that all denominators are nonnegative. -/ theorem zero_le_of_contsAux_b : 0 ≤ ((of v).contsAux n).b := by let g := of v induction n with | zero => rfl | succ n IH => rcases Decidable.em <| g.TerminatedAt (n - 1) with terminated | not_terminated · -- terminating case rcases n with - | n · simp [zero_le_one] · have : g.contsAux (n + 2) = g.contsAux (n + 1) := contsAux_stable_step_of_terminated terminated simp only [g, this, IH] · -- non-terminating case calc (0 : K) ≤ fib (n + 1) := mod_cast (n + 1).fib.zero_le _ ≤ ((of v).contsAux (n + 1)).b := fib_le_of_contsAux_b (Or.inr not_terminated) /-- Shows that all denominators are nonnegative. -/ theorem zero_le_of_den : 0 ≤ (of v).dens n := by rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux]; exact zero_le_of_contsAux_b theorem le_of_succ_succ_get?_contsAux_b {b : K} (nth_partDen_eq : (of v).partDens.get? n = some b) : b * ((of v).contsAux <| n + 1).b ≤ ((of v).contsAux <| n + 2).b := by obtain ⟨gp_n, nth_s_eq, rfl⟩ : ∃ gp_n, (of v).s.get? n = some gp_n ∧ gp_n.b = b := exists_s_b_of_partDen nth_partDen_eq simp [of_partNum_eq_one (partNum_eq_s_a nth_s_eq), zero_le_of_contsAux_b, GenContFract.contsAux_recurrence nth_s_eq rfl rfl] /-- Shows that `bₙ * Bₙ ≤ Bₙ₊₁`, where `bₙ` is the `n`th partial denominator and `Bₙ₊₁` and `Bₙ` are the `n + 1`th and `n`th denominator of the continued fraction. -/ theorem le_of_succ_get?_den {b : K} (nth_partDenom_eq : (of v).partDens.get? n = some b) : b * (of v).dens n ≤ (of v).dens (n + 1) := by rw [den_eq_conts_b, nth_cont_eq_succ_nth_contAux] exact le_of_succ_succ_get?_contsAux_b nth_partDenom_eq /-- Shows that the sequence of denominators is monotone, that is `Bₙ ≤ Bₙ₊₁`. -/ theorem of_den_mono : (of v).dens n ≤ (of v).dens (n + 1) := by let g := of v rcases Decidable.em <| g.partDens.TerminatedAt n with terminated | not_terminated · have : g.partDens.get? n = none := by rwa [Stream'.Seq.TerminatedAt] at terminated have : g.TerminatedAt n := terminatedAt_iff_partDen_none.2 (by rwa [Stream'.Seq.TerminatedAt] at terminated) have : g.dens (n + 1) = g.dens n := dens_stable_of_terminated n.le_succ this rw [this] · obtain ⟨b, nth_partDen_eq⟩ : ∃ b, g.partDens.get? n = some b := Option.ne_none_iff_exists'.mp not_terminated have : 1 ≤ b := of_one_le_get?_partDen nth_partDen_eq calc g.dens n ≤ b * g.dens n := by simpa using mul_le_mul_of_nonneg_right this zero_le_of_den _ ≤ g.dens (n + 1) := le_of_succ_get?_den nth_partDen_eq section ErrorTerm /-! ### Approximation of Error Term Next we derive some approximations for the error term when computing a continued fraction up a given position, i.e. bounds for the term `|v - (GenContFract.of v).convs n|`. -/ /-- This lemma follows from the finite correctness proof, the determinant equality, and by simplifying the difference. -/ theorem sub_convs_eq {ifp : IntFractPair K} (stream_nth_eq : IntFractPair.stream v n = some ifp) : let g := of v let B := (g.contsAux (n + 1)).b let pB := (g.contsAux n).b v - g.convs n = if ifp.fr = 0 then 0 else (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) := by -- set up some shorthand notation let g := of v let conts := g.contsAux (n + 1) let pred_conts := g.contsAux n have g_finite_correctness : v = GenContFract.compExactValue pred_conts conts ifp.fr := compExactValue_correctness_of_stream_eq_some stream_nth_eq obtain (ifp_fr_eq_zero | ifp_fr_ne_zero) := eq_or_ne ifp.fr 0 · suffices v - g.convs n = 0 by simpa [ifp_fr_eq_zero] replace g_finite_correctness : v = g.convs n := by simpa [GenContFract.compExactValue, ifp_fr_eq_zero] using g_finite_correctness exact sub_eq_zero.2 g_finite_correctness · -- more shorthand notation let A := conts.a let B := conts.b let pA := pred_conts.a let pB := pred_conts.b -- first, let's simplify the goal as `ifp.fr ≠ 0` suffices v - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by simpa [ifp_fr_ne_zero] -- now we can unfold `g.compExactValue` to derive the following equality for `v` replace g_finite_correctness : v = (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) := by simpa [GenContFract.compExactValue, ifp_fr_ne_zero, nextConts, nextNum, nextDen, add_comm] using g_finite_correctness -- let's rewrite this equality for `v` in our goal suffices (pA + ifp.fr⁻¹ * A) / (pB + ifp.fr⁻¹ * B) - A / B = (-1) ^ n / (B * (ifp.fr⁻¹ * B + pB)) by rwa [g_finite_correctness] -- To continue, we need use the determinant equality. So let's derive the needed hypothesis. have n_eq_zero_or_not_terminatedAt_pred_n : n = 0 ∨ ¬g.TerminatedAt (n - 1) := by rcases n with - | n' · simp · have : IntFractPair.stream v (n' + 1) ≠ none := by simp [stream_nth_eq] have : ¬g.TerminatedAt n' := (not_congr of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none).2 this exact Or.inr this have determinant_eq : pA * B - pB * A = (-1) ^ n := (SimpContFract.of v).determinant_aux n_eq_zero_or_not_terminatedAt_pred_n -- now all we got to do is to rewrite this equality in our goal and re-arrange terms; -- however, for this, we first have to derive quite a few tedious inequalities. have pB_ineq : (fib n : K) ≤ pB := haveI : n ≤ 1 ∨ ¬g.TerminatedAt (n - 2) := by rcases n_eq_zero_or_not_terminatedAt_pred_n with n_eq_zero | not_terminatedAt_pred_n · simp [n_eq_zero] · exact Or.inr <| mt (terminated_stable (n - 1).pred_le) not_terminatedAt_pred_n fib_le_of_contsAux_b this have B_ineq : (fib (n + 1) : K) ≤ B := haveI : n + 1 ≤ 1 ∨ ¬g.TerminatedAt (n + 1 - 2) := by rcases n_eq_zero_or_not_terminatedAt_pred_n with n_eq_zero | not_terminatedAt_pred_n · simp [n_eq_zero, le_refl] · exact Or.inr not_terminatedAt_pred_n fib_le_of_contsAux_b this have zero_lt_B : 0 < B := B_ineq.trans_lt' <| cast_pos.2 <| fib_pos.2 n.succ_pos have : 0 ≤ pB := (Nat.cast_nonneg _).trans pB_ineq have : 0 < ifp.fr := ifp_fr_ne_zero.lt_of_le' <| IntFractPair.nth_stream_fr_nonneg stream_nth_eq have : pB + ifp.fr⁻¹ * B ≠ 0 := by positivity grind /-- Shows that `|v - Aₙ / Bₙ| ≤ 1 / (Bₙ * Bₙ₊₁)`. -/ theorem abs_sub_convs_le (not_terminatedAt_n : ¬(of v).TerminatedAt n) : |v - (of v).convs n| ≤ 1 / ((of v).dens n * ((of v).dens <| n + 1)) := by -- shorthand notation let g := of v let nextConts := g.contsAux (n + 2) set conts := contsAux g (n + 1) with conts_eq set pred_conts := contsAux g n with pred_conts_eq -- change the goal to something more readable change |v - convs g n| ≤ 1 / (conts.b * nextConts.b) obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp := Option.ne_none_iff_exists'.1 not_terminatedAt_n have gp_a_eq_one : gp.a = 1 := of_partNum_eq_one (partNum_eq_s_a s_nth_eq) -- unfold the recurrence relation for `nextConts.b` have nextConts_b_eq : nextConts.b = pred_conts.b + gp.b * conts.b := by simp [nextConts, contsAux_recurrence s_nth_eq pred_conts_eq conts_eq, gp_a_eq_one, pred_conts_eq.symm, conts_eq.symm, add_comm] let den := conts.b * (pred_conts.b + gp.b * conts.b) obtain ⟨ifp_succ_n, succ_nth_stream_eq, ifp_succ_n_b_eq_gp_b⟩ : ∃ ifp_succ_n, IntFractPair.stream v (n + 1) = some ifp_succ_n ∧ (ifp_succ_n.b : K) = gp.b := IntFractPair.exists_succ_get?_stream_of_gcf_of_get?_eq_some s_nth_eq obtain ⟨ifp_n, stream_nth_eq, stream_nth_fr_ne_zero, if_of_eq_ifp_succ_n⟩ : ∃ ifp_n, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := IntFractPair.succ_nth_stream_eq_some_iff.1 succ_nth_stream_eq let den' := conts.b * (pred_conts.b + ifp_n.fr⁻¹ * conts.b) -- now we can use `sub_convs_eq` to simplify our goal suffices |(-1) ^ n / den'| ≤ 1 / den by grind [sub_convs_eq] -- derive some tedious inequalities that we need to rewrite our goal have nextConts_b_ineq : (fib (n + 2) : K) ≤ pred_conts.b + gp.b * conts.b := by have : (fib (n + 2) : K) ≤ nextConts.b := fib_le_of_contsAux_b (Or.inr not_terminatedAt_n) rwa [nextConts_b_eq] at this have conts_b_ineq : (fib (n + 1) : K) ≤ conts.b := haveI : ¬g.TerminatedAt (n - 1) := mt (terminated_stable n.pred_le) not_terminatedAt_n fib_le_of_contsAux_b <| Or.inr this have zero_lt_conts_b : 0 < conts.b := conts_b_ineq.trans_lt' <| mod_cast fib_pos.2 n.succ_pos -- `den'` is positive, so we can remove `|⬝|` from our goal suffices 1 / den' ≤ 1 / den by have : |(-1) ^ n / den'| = 1 / den' := by suffices 1 / |den'| = 1 / den' by rwa [abs_div, abs_neg_one_pow n] have : 0 < den' := by have : 0 ≤ pred_conts.b := haveI : (fib n : K) ≤ pred_conts.b := haveI : ¬g.TerminatedAt (n - 2) := mt (terminated_stable (n.sub_le 2)) not_terminatedAt_n fib_le_of_contsAux_b <| Or.inr this le_trans (mod_cast (fib n).zero_le) this have : 0 < ifp_n.fr⁻¹ := haveI zero_le_ifp_n_fract : 0 ≤ ifp_n.fr := IntFractPair.nth_stream_fr_nonneg stream_nth_eq inv_pos.2 (lt_of_le_of_ne zero_le_ifp_n_fract stream_nth_fr_ne_zero.symm) positivity rw [abs_of_pos this] rwa [this] suffices 0 < den ∧ den ≤ den' from div_le_div_of_nonneg_left zero_le_one this.1 this.2 constructor · have : 0 < pred_conts.b + gp.b * conts.b := nextConts_b_ineq.trans_lt' <| mod_cast fib_pos.2 <| succ_pos _ solve_by_elim [mul_pos] · -- we can cancel multiplication by `conts.b` and addition with `pred_conts.b` suffices gp.b * conts.b ≤ ifp_n.fr⁻¹ * conts.b by simp only [den, den']; gcongr suffices (ifp_succ_n.b : K) * conts.b ≤ ifp_n.fr⁻¹ * conts.b by rwa [← ifp_succ_n_b_eq_gp_b] have : (ifp_succ_n.b : K) ≤ ifp_n.fr⁻¹ := IntFractPair.succ_nth_stream_b_le_nth_stream_fr_inv stream_nth_eq succ_nth_stream_eq gcongr /-- Shows that `|v - Aₙ / Bₙ| ≤ 1 / (bₙ * Bₙ * Bₙ)`. This bound is worse than the one shown in `GenContFract.abs_sub_convs_le`, but sometimes it is easier to apply and sufficient for one's use case. -/ theorem abs_sub_convergents_le' {b : K} (nth_partDen_eq : (of v).partDens.get? n = some b) : |v - (of v).convs n| ≤ 1 / (b * (of v).dens n * (of v).dens n) := by have not_terminatedAt_n : ¬(of v).TerminatedAt n := by simp [terminatedAt_iff_partDen_none, nth_partDen_eq] refine (abs_sub_convs_le not_terminatedAt_n).trans ?_ -- One can show that `0 < (GenContFract.of v).dens n` but it's easier -- to consider the case `(GenContFract.of v).dens n = 0`. rcases (zero_le_of_den (K := K)).eq_or_lt' with ((hB : (GenContFract.of v).dens n = 0) | hB) · simp only [hB, mul_zero, zero_mul, div_zero, le_refl] · apply one_div_le_one_div_of_le · have : 0 < b := zero_lt_one.trans_le (of_one_le_get?_partDen nth_partDen_eq) apply_rules [mul_pos] · conv_rhs => rw [mul_comm] gcongr exact le_of_succ_get?_den nth_partDen_eq end ErrorTerm end GenContFract