path
stringlengths
11
71
content
stringlengths
75
124k
Algebra\Group\Submonoid\Pointwise.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Order.BigOperators.Group.List import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Order.WellFoundedSet /-! # Pointwise instances on `Submonoid`s and `AddSubmonoid`s This file provides: * `Submonoid.inv` * `AddSubmonoid.neg` and the actions * `Submonoid.pointwiseMulAction` * `AddSubmonoid.pointwiseMulAction` which matches the action of `Set.mulActionSet`. These are all available in the `Pointwise` locale. Additionally, it provides various degrees of monoid structure: * `AddSubmonoid.one` * `AddSubmonoid.mul` * `AddSubmonoid.mulOneClass` * `AddSubmonoid.semigroup` * `AddSubmonoid.monoid` which is available globally to match the monoid structure implied by `Submodule.idemSemiring`. ## Implementation notes Most of the lemmas in this file are direct copies of lemmas from `Algebra/Pointwise.lean`. While the statements of these lemmas are defeq, we repeat them here due to them not being syntactically equal. Before adding new lemmas here, consider if they would also apply to the action on `Set`s. -/ open Set Pointwise variable {α : Type*} {G : Type*} {M : Type*} {R : Type*} {A : Type*} variable [Monoid M] [AddMonoid A] /-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in `GroupTheory.Submonoid.Basic`, but currently we cannot because that file is imported by this. -/ namespace Submonoid variable {s t u : Set M} @[to_additive] theorem mul_subset {S : Submonoid M} (hs : s ⊆ S) (ht : t ⊆ S) : s * t ⊆ S := mul_subset_iff.2 fun _x hx _y hy ↦ mul_mem (hs hx) (ht hy) @[to_additive] theorem mul_subset_closure (hs : s ⊆ u) (ht : t ⊆ u) : s * t ⊆ Submonoid.closure u := mul_subset (Subset.trans hs Submonoid.subset_closure) (Subset.trans ht Submonoid.subset_closure) @[to_additive] theorem coe_mul_self_eq (s : Submonoid M) : (s : Set M) * s = s := by ext x refine ⟨?_, fun h => ⟨x, h, 1, s.one_mem, mul_one x⟩⟩ rintro ⟨a, ha, b, hb, rfl⟩ exact s.mul_mem ha hb @[to_additive] theorem closure_mul_le (S T : Set M) : closure (S * T) ≤ closure S ⊔ closure T := sInf_le fun _x ⟨_s, hs, _t, ht, hx⟩ => hx ▸ (closure S ⊔ closure T).mul_mem (SetLike.le_def.mp le_sup_left <| subset_closure hs) (SetLike.le_def.mp le_sup_right <| subset_closure ht) @[to_additive] theorem sup_eq_closure_mul (H K : Submonoid M) : H ⊔ K = closure ((H : Set M) * (K : Set M)) := le_antisymm (sup_le (fun h hh => subset_closure ⟨h, hh, 1, K.one_mem, mul_one h⟩) fun k hk => subset_closure ⟨1, H.one_mem, k, hk, one_mul k⟩) ((closure_mul_le _ _).trans <| by rw [closure_eq, closure_eq]) @[to_additive] theorem pow_smul_mem_closure_smul {N : Type*} [CommMonoid N] [MulAction M N] [IsScalarTower M N N] (r : M) (s : Set N) {x : N} (hx : x ∈ closure s) : ∃ n : ℕ, r ^ n • x ∈ closure (r • s) := by refine @closure_induction N _ s (fun x : N => ∃ n : ℕ, r ^ n • x ∈ closure (r • s)) _ hx ?_ ?_ ?_ · intro x hx exact ⟨1, subset_closure ⟨_, hx, by rw [pow_one]⟩⟩ · exact ⟨0, by simpa using one_mem _⟩ · rintro x y ⟨nx, hx⟩ ⟨ny, hy⟩ use ny + nx rw [pow_add, mul_smul, ← smul_mul_assoc, mul_comm, ← smul_mul_assoc] exact mul_mem hy hx variable [Group G] /-- The submonoid with every element inverted. -/ @[to_additive " The additive submonoid with every element negated. "] protected def inv : Inv (Submonoid G) where inv S := { carrier := (S : Set G)⁻¹ mul_mem' := fun ha hb => by rw [mem_inv, mul_inv_rev]; exact mul_mem hb ha one_mem' := mem_inv.2 <| by rw [inv_one]; exact S.one_mem' } scoped[Pointwise] attribute [instance] Submonoid.inv AddSubmonoid.neg @[to_additive (attr := simp)] theorem coe_inv (S : Submonoid G) : ↑S⁻¹ = (S : Set G)⁻¹ := rfl @[to_additive (attr := simp)] theorem mem_inv {g : G} {S : Submonoid G} : g ∈ S⁻¹ ↔ g⁻¹ ∈ S := Iff.rfl /-- Inversion is involutive on submonoids. -/ @[to_additive "Inversion is involutive on additive submonoids."] def involutiveInv : InvolutiveInv (Submonoid G) := SetLike.coe_injective.involutiveInv _ fun _ => rfl scoped[Pointwise] attribute [instance] Submonoid.involutiveInv AddSubmonoid.involutiveNeg @[to_additive (attr := simp)] theorem inv_le_inv (S T : Submonoid G) : S⁻¹ ≤ T⁻¹ ↔ S ≤ T := SetLike.coe_subset_coe.symm.trans Set.inv_subset_inv @[to_additive] theorem inv_le (S T : Submonoid G) : S⁻¹ ≤ T ↔ S ≤ T⁻¹ := SetLike.coe_subset_coe.symm.trans Set.inv_subset /-- Pointwise inversion of submonoids as an order isomorphism. -/ @[to_additive (attr := simps!) "Pointwise negation of additive submonoids as an order isomorphism"] def invOrderIso : Submonoid G ≃o Submonoid G where toEquiv := Equiv.inv _ map_rel_iff' := inv_le_inv _ _ @[to_additive] theorem closure_inv (s : Set G) : closure s⁻¹ = (closure s)⁻¹ := by apply le_antisymm · rw [closure_le, coe_inv, ← Set.inv_subset, inv_inv] exact subset_closure · rw [inv_le, closure_le, coe_inv, ← Set.inv_subset] exact subset_closure @[to_additive (attr := simp)] theorem inv_inf (S T : Submonoid G) : (S ⊓ T)⁻¹ = S⁻¹ ⊓ T⁻¹ := SetLike.coe_injective Set.inter_inv @[to_additive (attr := simp)] theorem inv_sup (S T : Submonoid G) : (S ⊔ T)⁻¹ = S⁻¹ ⊔ T⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_sup S T @[to_additive (attr := simp)] theorem inv_bot : (⊥ : Submonoid G)⁻¹ = ⊥ := SetLike.coe_injective <| (Set.inv_singleton 1).trans <| congr_arg _ inv_one @[to_additive (attr := simp)] theorem inv_top : (⊤ : Submonoid G)⁻¹ = ⊤ := SetLike.coe_injective <| Set.inv_univ @[to_additive (attr := simp)] theorem inv_iInf {ι : Sort*} (S : ι → Submonoid G) : (⨅ i, S i)⁻¹ = ⨅ i, (S i)⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_iInf _ @[to_additive (attr := simp)] theorem inv_iSup {ι : Sort*} (S : ι → Submonoid G) : (⨆ i, S i)⁻¹ = ⨆ i, (S i)⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_iSup _ end Submonoid namespace Submonoid section Monoid variable [Monoid α] [MulDistribMulAction α M] -- todo: add `to_additive`? /-- The action on a submonoid corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction α (Submonoid M) where smul a S := S.map (MulDistribMulAction.toMonoidEnd _ M a) one_smul S := by change S.map _ = S simpa only [map_one] using S.map_id mul_smul a₁ a₂ S := (congr_arg (fun f : Monoid.End M => S.map f) (MonoidHom.map_mul _ _ _)).trans (S.map_map _ _).symm scoped[Pointwise] attribute [instance] Submonoid.pointwiseMulAction @[simp] theorem coe_pointwise_smul (a : α) (S : Submonoid M) : ↑(a • S) = a • (S : Set M) := rfl theorem smul_mem_pointwise_smul (m : M) (a : α) (S : Submonoid M) : m ∈ S → a • m ∈ a • S := (Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set M)) instance : CovariantClass α (Submonoid M) HSMul.hSMul LE.le := ⟨fun _ _ => image_subset _⟩ theorem mem_smul_pointwise_iff_exists (m : M) (a : α) (S : Submonoid M) : m ∈ a • S ↔ ∃ s : M, s ∈ S ∧ a • s = m := (Set.mem_smul_set : m ∈ a • (S : Set M) ↔ _) @[simp] theorem smul_bot (a : α) : a • (⊥ : Submonoid M) = ⊥ := map_bot _ theorem smul_sup (a : α) (S T : Submonoid M) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ theorem smul_closure (a : α) (s : Set M) : a • closure s = closure (a • s) := MonoidHom.map_mclosure _ _ lemma pointwise_isCentralScalar [MulDistribMulAction αᵐᵒᵖ M] [IsCentralScalar α M] : IsCentralScalar α (Submonoid M) := ⟨fun _ S => (congr_arg fun f : Monoid.End M => S.map f) <| MonoidHom.ext <| op_smul_eq_smul _⟩ scoped[Pointwise] attribute [instance] Submonoid.pointwise_isCentralScalar end Monoid section Group variable [Group α] [MulDistribMulAction α M] @[simp] theorem smul_mem_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff theorem mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : Submonoid M} {x : M} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem theorem mem_inv_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : α} {S T : Submonoid M} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff theorem pointwise_smul_subset_iff {a : α} {S T : Submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff theorem subset_pointwise_smul_iff {a : α} {S T : Submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff end Group section GroupWithZero variable [GroupWithZero α] [MulDistribMulAction α M] @[simp] theorem smul_mem_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : Submonoid M) (x : M) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set M) x theorem mem_pointwise_smul_iff_inv_smul_mem₀ {a : α} (ha : a ≠ 0) (S : Submonoid M) (x : M) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set M) x theorem mem_inv_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : Submonoid M) (x : M) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set M) x @[simp] theorem pointwise_smul_le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : Submonoid M} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha theorem pointwise_smul_le_iff₀ {a : α} (ha : a ≠ 0) {S T : Submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha theorem le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : Submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha end GroupWithZero @[to_additive] theorem mem_closure_inv {G : Type*} [Group G] (S : Set G) (x : G) : x ∈ Submonoid.closure S⁻¹ ↔ x⁻¹ ∈ Submonoid.closure S := by rw [closure_inv, mem_inv] end Submonoid namespace AddSubmonoid section Monoid variable [Monoid α] [DistribMulAction α A] /-- The action on an additive submonoid corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction α (AddSubmonoid A) where smul a S := S.map (DistribMulAction.toAddMonoidEnd _ A a) one_smul S := (congr_arg (fun f : AddMonoid.End A => S.map f) (MonoidHom.map_one _)).trans S.map_id mul_smul _ _ S := (congr_arg (fun f : AddMonoid.End A => S.map f) (MonoidHom.map_mul _ _ _)).trans (S.map_map _ _).symm scoped[Pointwise] attribute [instance] AddSubmonoid.pointwiseMulAction @[simp] theorem coe_pointwise_smul (a : α) (S : AddSubmonoid A) : ↑(a • S) = a • (S : Set A) := rfl theorem smul_mem_pointwise_smul (m : A) (a : α) (S : AddSubmonoid A) : m ∈ S → a • m ∈ a • S := (Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set A)) theorem mem_smul_pointwise_iff_exists (m : A) (a : α) (S : AddSubmonoid A) : m ∈ a • S ↔ ∃ s : A, s ∈ S ∧ a • s = m := (Set.mem_smul_set : m ∈ a • (S : Set A) ↔ _) @[simp] theorem smul_bot (a : α) : a • (⊥ : AddSubmonoid A) = ⊥ := map_bot _ theorem smul_sup (a : α) (S T : AddSubmonoid A) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ @[simp] theorem smul_closure (a : α) (s : Set A) : a • closure s = closure (a • s) := AddMonoidHom.map_mclosure _ _ lemma pointwise_isCentralScalar [DistribMulAction αᵐᵒᵖ A] [IsCentralScalar α A] : IsCentralScalar α (AddSubmonoid A) := ⟨fun _ S => (congr_arg fun f : AddMonoid.End A => S.map f) <| AddMonoidHom.ext <| op_smul_eq_smul _⟩ scoped[Pointwise] attribute [instance] AddSubmonoid.pointwise_isCentralScalar end Monoid section Group variable [Group α] [DistribMulAction α A] @[simp] theorem smul_mem_pointwise_smul_iff {a : α} {S : AddSubmonoid A} {x : A} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff theorem mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : AddSubmonoid A} {x : A} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem theorem mem_inv_pointwise_smul_iff {a : α} {S : AddSubmonoid A} {x : A} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : α} {S T : AddSubmonoid A} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff theorem pointwise_smul_le_iff {a : α} {S T : AddSubmonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff theorem le_pointwise_smul_iff {a : α} {S T : AddSubmonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff end Group section GroupWithZero variable [GroupWithZero α] [DistribMulAction α A] @[simp] theorem smul_mem_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : AddSubmonoid A) (x : A) : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff₀ ha (S : Set A) x theorem mem_pointwise_smul_iff_inv_smul_mem₀ {a : α} (ha : a ≠ 0) (S : AddSubmonoid A) (x : A) : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem₀ ha (S : Set A) x theorem mem_inv_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) (S : AddSubmonoid A) (x : A) : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff₀ ha (S : Set A) x @[simp] theorem pointwise_smul_le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : AddSubmonoid A} : a • S ≤ a • T ↔ S ≤ T := set_smul_subset_set_smul_iff₀ ha theorem pointwise_smul_le_iff₀ {a : α} (ha : a ≠ 0) {S T : AddSubmonoid A} : a • S ≤ T ↔ S ≤ a⁻¹ • T := set_smul_subset_iff₀ ha theorem le_pointwise_smul_iff₀ {a : α} (ha : a ≠ 0) {S T : AddSubmonoid A} : S ≤ a • T ↔ a⁻¹ • S ≤ T := subset_set_smul_iff₀ ha end GroupWithZero end AddSubmonoid /-! ### Elementwise monoid structure of additive submonoids These definitions are a cut-down versions of the ones around `Submodule.mul`, as that API is usually more useful. -/ namespace AddSubmonoid section AddMonoidWithOne variable [AddMonoidWithOne R] /-- If `R` is an additive monoid with one (e.g., a semiring), then `1 : AddSubmonoid R` is the range of `Nat.cast : ℕ → R`. -/ protected def one : One (AddSubmonoid R) := ⟨AddMonoidHom.mrange (Nat.castAddMonoidHom R)⟩ scoped[Pointwise] attribute [instance] AddSubmonoid.one theorem one_eq_mrange : (1 : AddSubmonoid R) = AddMonoidHom.mrange (Nat.castAddMonoidHom R) := rfl theorem natCast_mem_one (n : ℕ) : (n : R) ∈ (1 : AddSubmonoid R) := ⟨_, rfl⟩ @[simp] theorem mem_one {x : R} : x ∈ (1 : AddSubmonoid R) ↔ ∃ n : ℕ, ↑n = x := Iff.rfl theorem one_eq_closure : (1 : AddSubmonoid R) = closure {1} := by rw [closure_singleton_eq, one_eq_mrange] congr 1 ext simp theorem one_eq_closure_one_set : (1 : AddSubmonoid R) = closure 1 := one_eq_closure end AddMonoidWithOne section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring R] /-- Multiplication of additive submonoids of a semiring R. The additive submonoid `S * T` is the smallest R-submodule of `R` containing the elements `s * t` for `s ∈ S` and `t ∈ T`. -/ protected def mul : Mul (AddSubmonoid R) := ⟨fun M N => ⨆ s : M, N.map (AddMonoidHom.mul s.1)⟩ scoped[Pointwise] attribute [instance] AddSubmonoid.mul theorem mul_mem_mul {M N : AddSubmonoid R} {m n : R} (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := (le_iSup _ ⟨m, hm⟩ : _ ≤ M * N) ⟨n, hn, by rfl⟩ theorem mul_le {M N P : AddSubmonoid R} : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P := ⟨fun H _m hm _n hn => H <| mul_mem_mul hm hn, fun H => iSup_le fun ⟨m, hm⟩ => map_le_iff_le_comap.2 fun n hn => H m hm n hn⟩ @[elab_as_elim] protected theorem mul_induction_on {M N : AddSubmonoid R} {C : R → Prop} {r : R} (hr : r ∈ M * N) (hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := (@mul_le _ _ _ _ ⟨⟨setOf C, ha _ _⟩, by simpa only [zero_mul] using hm _ (zero_mem _) _ (zero_mem _)⟩).2 hm hr -- this proof is copied directly from `Submodule.span_mul_span` -- Porting note: proof rewritten theorem closure_mul_closure (S T : Set R) : closure S * closure T = closure (S * T) := by apply le_antisymm · refine mul_le.2 fun a ha b hb => ?_ rw [← AddMonoidHom.mulRight_apply, ← AddSubmonoid.mem_comap] refine (closure_le.2 fun a' ha' => ?_) ha change b ∈ (closure (S * T)).comap (AddMonoidHom.mulLeft a') refine (closure_le.2 fun b' hb' => ?_) hb change a' * b' ∈ closure (S * T) exact subset_closure (Set.mul_mem_mul ha' hb') · rw [closure_le] rintro _ ⟨a, ha, b, hb, rfl⟩ exact mul_mem_mul (subset_closure ha) (subset_closure hb) theorem mul_eq_closure_mul_set (M N : AddSubmonoid R) : M * N = closure ((M : Set R) * (N : Set R)) := by rw [← closure_mul_closure, closure_eq, closure_eq] @[simp] theorem mul_bot (S : AddSubmonoid R) : S * ⊥ = ⊥ := eq_bot_iff.2 <| mul_le.2 fun m _ n hn => by rw [AddSubmonoid.mem_bot] at hn ⊢; rw [hn, mul_zero] @[simp] theorem bot_mul (S : AddSubmonoid R) : ⊥ * S = ⊥ := eq_bot_iff.2 <| mul_le.2 fun m hm n hn => by rw [AddSubmonoid.mem_bot] at hm ⊢; rw [hm, zero_mul] @[mono] theorem mul_le_mul {M N P Q : AddSubmonoid R} (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q := mul_le.2 fun _m hm _n hn => mul_mem_mul (hmp hm) (hnq hn) theorem mul_le_mul_left {M N P : AddSubmonoid R} (h : M ≤ N) : M * P ≤ N * P := mul_le_mul h (le_refl P) theorem mul_le_mul_right {M N P : AddSubmonoid R} (h : N ≤ P) : M * N ≤ M * P := mul_le_mul (le_refl M) h theorem mul_subset_mul {M N : AddSubmonoid R} : (↑M : Set R) * (↑N : Set R) ⊆ (↑(M * N) : Set R) := mul_subset_iff.2 fun _i hi _j hj ↦ mul_mem_mul hi hj end NonUnitalNonAssocSemiring section NonUnitalNonAssocRing variable [NonUnitalNonAssocRing R] /-- `AddSubmonoid.neg` distributes over multiplication. This is available as an instance in the `Pointwise` locale. -/ protected def hasDistribNeg : HasDistribNeg (AddSubmonoid R) := { AddSubmonoid.involutiveNeg with neg_mul := fun x y => by refine le_antisymm (mul_le.2 fun m hm n hn => ?_) ((AddSubmonoid.neg_le _ _).2 <| mul_le.2 fun m hm n hn => ?_) <;> simp only [AddSubmonoid.mem_neg, ← neg_mul] at * · exact mul_mem_mul hm hn · exact mul_mem_mul (neg_mem_neg.2 hm) hn mul_neg := fun x y => by refine le_antisymm (mul_le.2 fun m hm n hn => ?_) ((AddSubmonoid.neg_le _ _).2 <| mul_le.2 fun m hm n hn => ?_) <;> simp only [AddSubmonoid.mem_neg, ← mul_neg] at * · exact mul_mem_mul hm hn · exact mul_mem_mul hm (neg_mem_neg.2 hn) } scoped[Pointwise] attribute [instance] AddSubmonoid.hasDistribNeg end NonUnitalNonAssocRing section NonAssocSemiring variable [NonAssocSemiring R] /-- A `MulOneClass` structure on additive submonoids of a (possibly, non-associative) semiring. -/ protected def mulOneClass : MulOneClass (AddSubmonoid R) where one := 1 mul := (· * ·) one_mul M := by rw [one_eq_closure_one_set, ← closure_eq M, closure_mul_closure, one_mul] mul_one M := by rw [one_eq_closure_one_set, ← closure_eq M, closure_mul_closure, mul_one] scoped[Pointwise] attribute [instance] AddSubmonoid.mulOneClass end NonAssocSemiring section NonUnitalSemiring variable [NonUnitalSemiring R] /-- Semigroup structure on additive submonoids of a (possibly, non-unital) semiring. -/ protected def semigroup : Semigroup (AddSubmonoid R) where mul := (· * ·) mul_assoc M N P := le_antisymm (mul_le.2 fun _mn hmn p hp => suffices M * N ≤ (M * (N * P)).comap (AddMonoidHom.mulRight p) from this hmn mul_le.2 fun m hm n hn => show m * n * p ∈ M * (N * P) from (mul_assoc m n p).symm ▸ mul_mem_mul hm (mul_mem_mul hn hp)) (mul_le.2 fun m hm _np hnp => suffices N * P ≤ (M * N * P).comap (AddMonoidHom.mulLeft m) from this hnp mul_le.2 fun n hn p hp => show m * (n * p) ∈ M * N * P from mul_assoc m n p ▸ mul_mem_mul (mul_mem_mul hm hn) hp) scoped[Pointwise] attribute [instance] AddSubmonoid.semigroup end NonUnitalSemiring section Semiring variable [Semiring R] /-- Monoid structure on additive submonoids of a semiring. -/ protected def monoid : Monoid (AddSubmonoid R) := { AddSubmonoid.semigroup, AddSubmonoid.mulOneClass with } scoped[Pointwise] attribute [instance] AddSubmonoid.monoid theorem closure_pow (s : Set R) : ∀ n : ℕ, closure s ^ n = closure (s ^ n) | 0 => by rw [pow_zero, pow_zero, one_eq_closure_one_set] | n + 1 => by rw [pow_succ, pow_succ, closure_pow s n, closure_mul_closure] theorem pow_eq_closure_pow_set (s : AddSubmonoid R) (n : ℕ) : s ^ n = closure ((s : Set R) ^ n) := by rw [← closure_pow, closure_eq] theorem pow_subset_pow {s : AddSubmonoid R} {n : ℕ} : (↑s : Set R) ^ n ⊆ ↑(s ^ n) := (pow_eq_closure_pow_set s n).symm ▸ subset_closure end Semiring end AddSubmonoid namespace Set.IsPWO variable [OrderedCancelCommMonoid α] {s : Set α} @[to_additive] theorem submonoid_closure (hpos : ∀ x : α, x ∈ s → 1 ≤ x) (h : s.IsPWO) : IsPWO (Submonoid.closure s : Set α) := by rw [Submonoid.closure_eq_image_prod] refine (h.partiallyWellOrderedOn_sublistForall₂ (· ≤ ·)).image_of_monotone_on ?_ exact fun l1 _ l2 hl2 h12 => h12.prod_le_prod' fun x hx => hpos x <| hl2 x hx end Set.IsPWO
Algebra\Group\Submonoid\Units.lean
/- Copyright (c) 2023 Wrenna Robson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Wrenna Robson -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Group.Submonoid.Pointwise import Mathlib.Algebra.Group.Subgroup.Basic /-! # Submonoid of units Given a submonoid `S` of a monoid `M`, we define the subgroup `S.units` as the units of `S` as a subgroup of `Mˣ`. That is to say, `S.units` contains all members of `S` which have a two-sided inverse within `S`, as terms of type `Mˣ`. We also define, for subgroups `S` of `Mˣ`, `S.ofUnits`, which is `S` considered as a submonoid of `M`. `Submonoid.units` and `Subgroup.ofUnits` form a Galois coinsertion. We also make the equivalent additive definitions. # Implementation details There are a number of other constructions which are multiplicatively equivalent to `S.units` but which have a different type. | Definition | Type | |----------------------|---------------| | `S.units` | `Subgroup Mˣ` | | `Sˣ` | `Type u` | | `IsUnit.submonoid S` | `Submonoid S` | | `S.units.ofUnits` | `Submonoid M` | All of these are distinct from `S.leftInv`, which is the submonoid of `M` which contains every member of `M` with a right inverse in `S`. -/ variable {M : Type*} [Monoid M] open Units open Pointwise in /-- The units of `S`, packaged as a subgroup of `Mˣ`. -/ @[to_additive " The additive units of `S`, packaged as an additive subgroup of `AddUnits M`. "] def Submonoid.units (S : Submonoid M) : Subgroup Mˣ where toSubmonoid := S.comap (coeHom M) ⊓ (S.comap (coeHom M))⁻¹ inv_mem' ha := ⟨ha.2, ha.1⟩ /-- A subgroup of units represented as a submonoid of `M`. -/ @[to_additive " A additive subgroup of additive units represented as a additive submonoid of `M`. "] def Subgroup.ofUnits (S : Subgroup Mˣ) : Submonoid M := S.toSubmonoid.map (coeHom M) @[to_additive] lemma Submonoid.units_mono : Monotone (Submonoid.units (M := M)) := fun _ _ hST _ ⟨h₁, h₂⟩ => ⟨hST h₁, hST h₂⟩ @[to_additive (attr := simp)] lemma Submonoid.ofUnits_units_le (S : Submonoid M) : S.units.ofUnits ≤ S := fun _ ⟨_, hm, he⟩ => he ▸ hm.1 @[to_additive] lemma Subgroup.ofUnits_mono : Monotone (Subgroup.ofUnits (M := M)) := fun _ _ hST _ ⟨x, hx, hy⟩ => ⟨x, hST hx, hy⟩ @[to_additive (attr := simp)] lemma Subgroup.units_ofUnits_eq (S : Subgroup Mˣ) : S.ofUnits.units = S := Subgroup.ext (fun _ => ⟨fun ⟨⟨_, hm, he⟩, _⟩ => (Units.ext he) ▸ hm, fun hm => ⟨⟨_, hm, rfl⟩, _, S.inv_mem hm, rfl⟩⟩) /-- A Galois coinsertion exists between the coercion from a subgroup of units to a submonoid and the reduction from a submonoid to its unit group. -/ @[to_additive " A Galois coinsertion exists between the coercion from a additive subgroup of additive units to a additive submonoid and the reduction from a additive submonoid to its unit group. " ] def ofUnits_units_gci : GaloisCoinsertion (Subgroup.ofUnits (M := M)) (Submonoid.units) := GaloisCoinsertion.monotoneIntro Submonoid.units_mono Subgroup.ofUnits_mono Submonoid.ofUnits_units_le Subgroup.units_ofUnits_eq @[to_additive] lemma ofUnits_units_gc : GaloisConnection (Subgroup.ofUnits (M := M)) (Submonoid.units) := ofUnits_units_gci.gc @[to_additive] lemma ofUnits_le_iff_le_units (S : Submonoid M) (H : Subgroup Mˣ) : H.ofUnits ≤ S ↔ H ≤ S.units := ofUnits_units_gc _ _ namespace Submonoid section Units @[to_additive] lemma mem_units_iff (S : Submonoid M) (x : Mˣ) : x ∈ S.units ↔ ((x : M) ∈ S ∧ ((x⁻¹ : Mˣ) : M) ∈ S) := Iff.rfl @[to_additive] lemma mem_units_of_val_mem_inv_val_mem (S : Submonoid M) {x : Mˣ} (h₁ : (x : M) ∈ S) (h₂ : ((x⁻¹ : Mˣ) : M) ∈ S) : x ∈ S.units := ⟨h₁, h₂⟩ @[to_additive] lemma val_mem_of_mem_units (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) : (x : M) ∈ S := h.1 @[to_additive] lemma inv_val_mem_of_mem_units (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) : ((x⁻¹ : Mˣ) : M) ∈ S := h.2 @[to_additive] lemma coe_inv_val_mul_coe_val (S : Submonoid M) {x : Sˣ} : ((x⁻¹ : Sˣ) : M) * ((x : Sˣ) : M) = 1 := DFunLike.congr_arg S.subtype x.inv_mul @[to_additive] lemma coe_val_mul_coe_inv_val (S : Submonoid M) {x : Sˣ} : ((x : Sˣ) : M) * ((x⁻¹ : Sˣ) : M) = 1 := DFunLike.congr_arg S.subtype x.mul_inv @[to_additive] lemma mk_inv_mul_mk_eq_one (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) : (⟨_, h.2⟩ : S) * ⟨_, h.1⟩ = 1 := Subtype.ext x.inv_mul @[to_additive] lemma mk_mul_mk_inv_eq_one (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) : (⟨_, h.1⟩ : S) * ⟨_, h.2⟩ = 1 := Subtype.ext x.mul_inv @[to_additive] lemma mul_mem_units (S : Submonoid M) {x y : Mˣ} (h₁ : x ∈ S.units) (h₂ : y ∈ S.units) : x * y ∈ S.units := mul_mem h₁ h₂ @[to_additive] lemma inv_mem_units (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) : x⁻¹ ∈ S.units := inv_mem h @[to_additive] lemma inv_mem_units_iff (S : Submonoid M) {x : Mˣ} : x⁻¹ ∈ S.units ↔ x ∈ S.units := inv_mem_iff /-- The equivalence between the subgroup of units of `S` and the type of units of `S`. -/ @[to_additive " The equivalence between the additive subgroup of additive units of `S` and the type of additive units of `S`. "] def unitsEquivUnitsType (S : Submonoid M) : S.units ≃* Sˣ where toFun := fun ⟨_, h⟩ => ⟨⟨_, h.1⟩, ⟨_, h.2⟩, S.mk_mul_mk_inv_eq_one h, S.mk_inv_mul_mk_eq_one h⟩ invFun := fun x => ⟨⟨_, _, S.coe_val_mul_coe_inv_val, S.coe_inv_val_mul_coe_val⟩, ⟨x.1.2, x.2.2⟩⟩ left_inv := fun _ => rfl right_inv := fun _ => rfl map_mul' := fun _ _ => rfl @[to_additive (attr := simp)] lemma units_top : (⊤ : Submonoid M).units = ⊤ := ofUnits_units_gc.u_top @[to_additive] lemma units_inf (S T : Submonoid M) : (S ⊓ T).units = S.units ⊓ T.units := ofUnits_units_gc.u_inf @[to_additive] lemma units_sInf {s : Set (Submonoid M)} : (sInf s).units = ⨅ S ∈ s, S.units := ofUnits_units_gc.u_sInf @[to_additive] lemma units_iInf {ι : Sort*} (f : ι → Submonoid M) : (iInf f).units = ⨅ (i : ι), (f i).units := ofUnits_units_gc.u_iInf @[to_additive] lemma units_iInf₂ {ι : Sort*} {κ : ι → Sort*} (f : (i : ι) → κ i → Submonoid M) : (⨅ (i : ι), ⨅ (j : κ i), f i j).units = ⨅ (i : ι), ⨅ (j : κ i), (f i j).units := ofUnits_units_gc.u_iInf₂ @[to_additive (attr := simp)] lemma units_bot : (⊥ : Submonoid M).units = ⊥ := ofUnits_units_gci.u_bot @[to_additive] lemma units_surjective : Function.Surjective (units (M := M)) := ofUnits_units_gci.u_surjective @[to_additive] lemma units_left_inverse : Function.LeftInverse (units (M := M)) (Subgroup.ofUnits (M := M)) := ofUnits_units_gci.u_l_leftInverse /-- The equivalence between the subgroup of units of `S` and the submonoid of unit elements of `S`. -/ @[to_additive " The equivalence between the additive subgroup of additive units of `S` and the additive submonoid of additive unit elements of `S`. "] noncomputable def unitsEquivIsUnitSubmonoid (S : Submonoid M) : S.units ≃* IsUnit.submonoid S := S.unitsEquivUnitsType.trans unitsTypeEquivIsUnitSubmonoid end Units end Submonoid namespace Subgroup @[to_additive] lemma mem_ofUnits_iff (S : Subgroup Mˣ) (x : M) : x ∈ S.ofUnits ↔ ∃ y ∈ S, y = x := Iff.rfl @[to_additive] lemma mem_ofUnits (S : Subgroup Mˣ) {x : M} {y : Mˣ} (h₁ : y ∈ S) (h₂ : y = x) : x ∈ S.ofUnits := ⟨_, h₁, h₂⟩ @[to_additive] lemma exists_mem_ofUnits_val_eq (S : Subgroup Mˣ) {x : M} (h : x ∈ S.ofUnits) : ∃ y ∈ S, y = x := h @[to_additive] lemma mem_of_mem_val_ofUnits (S : Subgroup Mˣ) {y : Mˣ} (hy : (y : M) ∈ S.ofUnits) : y ∈ S := match hy with | ⟨_, hm, he⟩ => (Units.ext he) ▸ hm @[to_additive] lemma isUnit_of_mem_ofUnits (S : Subgroup Mˣ) {x : M} (hx : x ∈ S.ofUnits) : IsUnit x := match hx with | ⟨_, _, h⟩ => ⟨_, h⟩ /-- Given some `x : M` which is a member of the submonoid of unit elements corresponding to a subgroup of units, produce a unit of `M` whose coercion is equal to `x`. `-/ @[to_additive " Given some `x : M` which is a member of the additive submonoid of additive unit elements corresponding to a subgroup of units, produce a unit of `M` whose coercion is equal to `x`. "] noncomputable def unit_of_mem_ofUnits (S : Subgroup Mˣ) {x : M} (h : x ∈ S.ofUnits) : Mˣ := (Classical.choose h).copy x (Classical.choose_spec h).2.symm _ rfl @[to_additive] lemma unit_of_mem_ofUnits_spec_eq_of_val_mem (S : Subgroup Mˣ) {x : Mˣ} (h : (x : M) ∈ S.ofUnits) : S.unit_of_mem_ofUnits h = x := Units.ext rfl @[to_additive] lemma unit_of_mem_ofUnits_spec_val_eq_of_mem (S : Subgroup Mˣ) {x : M} (h : x ∈ S.ofUnits) : S.unit_of_mem_ofUnits h = x := rfl @[to_additive] lemma unit_of_mem_ofUnits_spec_mem (S : Subgroup Mˣ) {x : M} {h : x ∈ S.ofUnits} : S.unit_of_mem_ofUnits h ∈ S := S.mem_of_mem_val_ofUnits h @[to_additive] lemma unit_eq_unit_of_mem_ofUnits (S : Subgroup Mˣ) {x : M} (h₁ : IsUnit x) (h₂ : x ∈ S.ofUnits) : h₁.unit = S.unit_of_mem_ofUnits h₂ := Units.ext rfl @[to_additive] lemma unit_mem_of_mem_ofUnits (S : Subgroup Mˣ) {x : M} {h₁ : IsUnit x} (h₂ : x ∈ S.ofUnits) : h₁.unit ∈ S := S.unit_eq_unit_of_mem_ofUnits h₁ h₂ ▸ (S.unit_of_mem_ofUnits_spec_mem) @[to_additive] lemma mem_ofUnits_of_isUnit_of_unit_mem (S : Subgroup Mˣ) {x : M} (h₁ : IsUnit x) (h₂ : h₁.unit ∈ S) : x ∈ S.ofUnits := S.mem_ofUnits h₂ h₁.unit_spec @[to_additive] lemma mem_ofUnits_iff_exists_isUnit (S : Subgroup Mˣ) (x : M) : x ∈ S.ofUnits ↔ ∃ h : IsUnit x, h.unit ∈ S := ⟨fun h => ⟨S.isUnit_of_mem_ofUnits h, S.unit_mem_of_mem_ofUnits h⟩, fun ⟨hm, he⟩ => S.mem_ofUnits_of_isUnit_of_unit_mem hm he⟩ /-- The equivalence between the coercion of a subgroup `S` of `Mˣ` to a submonoid of `M` and the subgroup itself as a type. -/ @[to_additive " The equivalence between the coercion of an additive subgroup `S` of `Mˣ` to an additive submonoid of `M` and the additive subgroup itself as a type. "] noncomputable def ofUnitsEquivType (S : Subgroup Mˣ) : S.ofUnits ≃* S where toFun := fun x => ⟨S.unit_of_mem_ofUnits x.2, S.unit_of_mem_ofUnits_spec_mem⟩ invFun := fun x => ⟨x.1, ⟨x.1, x.2, rfl⟩⟩ left_inv := fun _ => rfl right_inv := fun _ => Subtype.ext (Units.ext rfl) map_mul' := fun _ _ => Subtype.ext (Units.ext rfl) @[to_additive (attr := simp)] lemma ofUnits_bot : (⊥ : Subgroup Mˣ).ofUnits = ⊥ := ofUnits_units_gc.l_bot @[to_additive] lemma ofUnits_inf (S T : Subgroup Mˣ) : (S ⊔ T).ofUnits = S.ofUnits ⊔ T.ofUnits := ofUnits_units_gc.l_sup @[to_additive] lemma ofUnits_sSup (s : Set (Subgroup Mˣ)) : (sSup s).ofUnits = ⨆ S ∈ s, S.ofUnits := ofUnits_units_gc.l_sSup @[to_additive] lemma ofUnits_iSup {ι : Sort*} {f : ι → Subgroup Mˣ} : (iSup f).ofUnits = ⨆ (i : ι), (f i).ofUnits := ofUnits_units_gc.l_iSup @[to_additive] lemma ofUnits_iSup₂ {ι : Sort*} {κ : ι → Sort*} (f : (i : ι) → κ i → Subgroup Mˣ) : (⨆ (i : ι), ⨆ (j : κ i), f i j).ofUnits = ⨆ (i : ι), ⨆ (j : κ i), (f i j).ofUnits := ofUnits_units_gc.l_iSup₂ @[to_additive] lemma ofUnits_injective : Function.Injective (ofUnits (M := M)) := ofUnits_units_gci.l_injective @[to_additive (attr := simp)] lemma ofUnits_sup_units (S T : Subgroup Mˣ) : (S.ofUnits ⊔ T.ofUnits).units = S ⊔ T := ofUnits_units_gci.u_sup_l _ _ @[to_additive (attr := simp)] lemma ofUnits_inf_units (S T : Subgroup Mˣ) : (S.ofUnits ⊓ T.ofUnits).units = S ⊓ T := ofUnits_units_gci.u_inf_l _ _ @[to_additive] lemma ofUnits_right_inverse : Function.RightInverse (ofUnits (M := M)) (Submonoid.units (M := M)) := ofUnits_units_gci.u_l_leftInverse @[to_additive] lemma ofUnits_strictMono : StrictMono (ofUnits (M := M)) := ofUnits_units_gci.strictMono_l lemma ofUnits_le_ofUnits_iff {S T : Subgroup Mˣ} : S.ofUnits ≤ T.ofUnits ↔ S ≤ T := ofUnits_units_gci.l_le_l_iff /-- The equivalence between the top subgroup of `Mˣ` coerced to a submonoid `M` and the units of `M`. -/ @[to_additive " The equivalence between the additive subgroup of additive units of `S` and the additive submonoid of additive unit elements of `S`. "] noncomputable def ofUnitsTopEquiv : (⊤ : Subgroup Mˣ).ofUnits ≃* Mˣ := (⊤ : Subgroup Mˣ).ofUnitsEquivType.trans topEquiv variable {G : Type*} [Group G] @[to_additive] lemma mem_units_iff_val_mem (H : Subgroup G) (x : Gˣ) : x ∈ H.units ↔ (x : G) ∈ H := by simp_rw [Submonoid.mem_units_iff, mem_toSubmonoid, val_inv_eq_inv_val, inv_mem_iff, and_self] @[to_additive] lemma mem_ofUnits_iff_toUnits_mem (H : Subgroup Gˣ) (x : G) : x ∈ H.ofUnits ↔ (toUnits x) ∈ H := by simp_rw [mem_ofUnits_iff, toUnits.surjective.exists, val_toUnits_apply, exists_eq_right] @[to_additive (attr := simp)] lemma mem_iff_toUnits_mem_units (H : Subgroup G) (x : G) : toUnits x ∈ H.units ↔ x ∈ H := by simp_rw [mem_units_iff_val_mem, val_toUnits_apply] @[to_additive (attr := simp)] lemma val_mem_ofUnits_iff_mem (H : Subgroup Gˣ) (x : Gˣ) : (x : G) ∈ H.ofUnits ↔ x ∈ H := by simp_rw [mem_ofUnits_iff_toUnits_mem, toUnits_val_apply] /-- The equivalence between the greatest subgroup of units contained within `T` and `T` itself. -/ @[to_additive " The equivalence between the greatest subgroup of additive units contained within `T` and `T` itself. "] def unitsEquivSelf (H : Subgroup G) : H.units ≃* H := H.unitsEquivUnitsType.trans toUnits.symm end Subgroup
Algebra\Group\Subsemigroup\Basic.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov, Yakov Pechersky -/ import Mathlib.Algebra.Group.Hom.Defs import Mathlib.Data.Set.Lattice import Mathlib.Data.SetLike.Basic /-! # Subsemigroups: definition and `CompleteLattice` structure This file defines bundled multiplicative and additive subsemigroups. We also define a `CompleteLattice` structure on `Subsemigroup`s, and define the closure of a set as the minimal subsemigroup that includes this set. ## Main definitions * `Subsemigroup M`: the type of bundled subsemigroup of a magma `M`; the underlying set is given in the `carrier` field of the structure, and should be accessed through coercion as in `(S : Set M)`. * `AddSubsemigroup M` : the type of bundled subsemigroups of an additive magma `M`. For each of the following definitions in the `Subsemigroup` namespace, there is a corresponding definition in the `AddSubsemigroup` namespace. * `Subsemigroup.copy` : copy of a subsemigroup with `carrier` replaced by a set that is equal but possibly not definitionally equal to the carrier of the original `Subsemigroup`. * `Subsemigroup.closure` : semigroup closure of a set, i.e., the least subsemigroup that includes the set. * `Subsemigroup.gi` : `closure : Set M → Subsemigroup M` and coercion `coe : Subsemigroup M → Set M` form a `GaloisInsertion`; ## Implementation notes Subsemigroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subsemigroup's underlying set. Note that `Subsemigroup M` does not actually require `Semigroup M`, instead requiring only the weaker `Mul M`. This file is designed to have very few dependencies. In particular, it should not use natural numbers. ## Tags subsemigroup, subsemigroups -/ assert_not_exists MonoidWithZero -- Only needed for notation variable {M : Type*} {N : Type*} {A : Type*} section NonAssoc variable [Mul M] {s : Set M} variable [Add A] {t : Set A} /-- `MulMemClass S M` says `S` is a type of sets `s : Set M` that are closed under `(*)` -/ class MulMemClass (S : Type*) (M : Type*) [Mul M] [SetLike S M] : Prop where /-- A substructure satisfying `MulMemClass` is closed under multiplication. -/ mul_mem : ∀ {s : S} {a b : M}, a ∈ s → b ∈ s → a * b ∈ s export MulMemClass (mul_mem) /-- `AddMemClass S M` says `S` is a type of sets `s : Set M` that are closed under `(+)` -/ class AddMemClass (S : Type*) (M : Type*) [Add M] [SetLike S M] : Prop where /-- A substructure satisfying `AddMemClass` is closed under addition. -/ add_mem : ∀ {s : S} {a b : M}, a ∈ s → b ∈ s → a + b ∈ s export AddMemClass (add_mem) attribute [to_additive] MulMemClass attribute [aesop safe apply (rule_sets := [SetLike])] mul_mem add_mem /-- A subsemigroup of a magma `M` is a subset closed under multiplication. -/ structure Subsemigroup (M : Type*) [Mul M] where /-- The carrier of a subsemigroup. -/ carrier : Set M /-- The product of two elements of a subsemigroup belongs to the subsemigroup. -/ mul_mem' {a b} : a ∈ carrier → b ∈ carrier → a * b ∈ carrier /-- An additive subsemigroup of an additive magma `M` is a subset closed under addition. -/ structure AddSubsemigroup (M : Type*) [Add M] where /-- The carrier of an additive subsemigroup. -/ carrier : Set M /-- The sum of two elements of an additive subsemigroup belongs to the subsemigroup. -/ add_mem' {a b} : a ∈ carrier → b ∈ carrier → a + b ∈ carrier attribute [to_additive AddSubsemigroup] Subsemigroup namespace Subsemigroup @[to_additive] instance : SetLike (Subsemigroup M) M := ⟨Subsemigroup.carrier, fun p q h => by cases p; cases q; congr⟩ @[to_additive] instance : MulMemClass (Subsemigroup M) M where mul_mem := fun {_ _ _} => Subsemigroup.mul_mem' _ initialize_simps_projections Subsemigroup (carrier → coe) initialize_simps_projections AddSubsemigroup (carrier → coe) @[to_additive (attr := simp)] theorem mem_carrier {s : Subsemigroup M} {x : M} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[to_additive (attr := simp)] theorem mem_mk {s : Set M} {x : M} (h_mul) : x ∈ mk s h_mul ↔ x ∈ s := Iff.rfl @[to_additive (attr := simp, norm_cast)] theorem coe_set_mk {s : Set M} (h_mul) : (mk s h_mul : Set M) = s := rfl @[to_additive (attr := simp)] theorem mk_le_mk {s t : Set M} (h_mul) (h_mul') : mk s h_mul ≤ mk t h_mul' ↔ s ⊆ t := Iff.rfl /-- Two subsemigroups are equal if they have the same elements. -/ @[to_additive (attr := ext) "Two `AddSubsemigroup`s are equal if they have the same elements."] theorem ext {S T : Subsemigroup M} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy a subsemigroup replacing `carrier` with a set that is equal to it. -/ @[to_additive "Copy an additive subsemigroup replacing `carrier` with a set that is equal to it."] protected def copy (S : Subsemigroup M) (s : Set M) (hs : s = S) : Subsemigroup M where carrier := s mul_mem' := hs.symm ▸ S.mul_mem' variable {S : Subsemigroup M} @[to_additive (attr := simp)] theorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s := rfl @[to_additive] theorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S := SetLike.coe_injective hs variable (S) /-- A subsemigroup is closed under multiplication. -/ @[to_additive "An `AddSubsemigroup` is closed under addition."] protected theorem mul_mem {x y : M} : x ∈ S → y ∈ S → x * y ∈ S := Subsemigroup.mul_mem' S /-- The subsemigroup `M` of the magma `M`. -/ @[to_additive "The additive subsemigroup `M` of the magma `M`."] instance : Top (Subsemigroup M) := ⟨{ carrier := Set.univ mul_mem' := fun _ _ => Set.mem_univ _ }⟩ /-- The trivial subsemigroup `∅` of a magma `M`. -/ @[to_additive "The trivial `AddSubsemigroup` `∅` of an additive magma `M`."] instance : Bot (Subsemigroup M) := ⟨{ carrier := ∅ mul_mem' := False.elim }⟩ @[to_additive] instance : Inhabited (Subsemigroup M) := ⟨⊥⟩ @[to_additive] theorem not_mem_bot {x : M} : x ∉ (⊥ : Subsemigroup M) := Set.not_mem_empty x @[to_additive (attr := simp)] theorem mem_top (x : M) : x ∈ (⊤ : Subsemigroup M) := Set.mem_univ x @[to_additive (attr := simp)] theorem coe_top : ((⊤ : Subsemigroup M) : Set M) = Set.univ := rfl @[to_additive (attr := simp)] theorem coe_bot : ((⊥ : Subsemigroup M) : Set M) = ∅ := rfl /-- The inf of two subsemigroups is their intersection. -/ @[to_additive "The inf of two `AddSubsemigroup`s is their intersection."] instance : Inf (Subsemigroup M) := ⟨fun S₁ S₂ => { carrier := S₁ ∩ S₂ mul_mem' := fun ⟨hx, hx'⟩ ⟨hy, hy'⟩ => ⟨S₁.mul_mem hx hy, S₂.mul_mem hx' hy'⟩ }⟩ @[to_additive (attr := simp)] theorem coe_inf (p p' : Subsemigroup M) : ((p ⊓ p' : Subsemigroup M) : Set M) = (p : Set M) ∩ p' := rfl @[to_additive (attr := simp)] theorem mem_inf {p p' : Subsemigroup M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl @[to_additive] instance : InfSet (Subsemigroup M) := ⟨fun s => { carrier := ⋂ t ∈ s, ↑t mul_mem' := fun hx hy => Set.mem_biInter fun i h => i.mul_mem (by apply Set.mem_iInter₂.1 hx i h) (by apply Set.mem_iInter₂.1 hy i h) }⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_sInf (S : Set (Subsemigroup M)) : ((sInf S : Subsemigroup M) : Set M) = ⋂ s ∈ S, ↑s := rfl @[to_additive] theorem mem_sInf {S : Set (Subsemigroup M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ @[to_additive] theorem mem_iInf {ι : Sort*} {S : ι → Subsemigroup M} {x : M} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[to_additive (attr := simp, norm_cast)] theorem coe_iInf {ι : Sort*} {S : ι → Subsemigroup M} : (↑(⨅ i, S i) : Set M) = ⋂ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] /-- subsemigroups of a monoid form a complete lattice. -/ @[to_additive "The `AddSubsemigroup`s of an `AddMonoid` form a complete lattice."] instance : CompleteLattice (Subsemigroup M) := { completeLatticeOfInf (Subsemigroup M) fun _ => IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with le := (· ≤ ·) lt := (· < ·) bot := ⊥ bot_le := fun _ _ hx => (not_mem_bot hx).elim top := ⊤ le_top := fun _ x _ => mem_top x inf := (· ⊓ ·) sInf := InfSet.sInf le_inf := fun _ _ _ ha hb _ hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right } @[to_additive] theorem subsingleton_of_subsingleton [Subsingleton (Subsemigroup M)] : Subsingleton M := by constructor; intro x y have : ∀ a : M, a ∈ (⊥ : Subsemigroup M) := by simp [Subsingleton.elim (⊥ : Subsemigroup M) ⊤] exact absurd (this x) not_mem_bot @[to_additive] instance [hn : Nonempty M] : Nontrivial (Subsemigroup M) := ⟨⟨⊥, ⊤, fun h => by obtain ⟨x⟩ := id hn refine absurd (?_ : x ∈ ⊥) not_mem_bot simp [h]⟩⟩ /-- The `Subsemigroup` generated by a set. -/ @[to_additive "The `AddSubsemigroup` generated by a set"] def closure (s : Set M) : Subsemigroup M := sInf { S | s ⊆ S } @[to_additive] theorem mem_closure {x : M} : x ∈ closure s ↔ ∀ S : Subsemigroup M, s ⊆ S → x ∈ S := mem_sInf /-- The subsemigroup generated by a set includes the set. -/ @[to_additive (attr := simp, aesop safe 20 apply (rule_sets := [SetLike])) "The `AddSubsemigroup` generated by a set includes the set."] theorem subset_closure : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx @[to_additive] theorem not_mem_of_not_mem_closure {P : M} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) variable {S} open Set /-- A subsemigroup `S` includes `closure s` if and only if it includes `s`. -/ @[to_additive (attr := simp) "An additive subsemigroup `S` includes `closure s` if and only if it includes `s`"] theorem closure_le : closure s ≤ S ↔ s ⊆ S := ⟨Subset.trans subset_closure, fun h => sInf_le h⟩ /-- subsemigroup closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`. -/ @[to_additive "Additive subsemigroup closure of a set is monotone in its argument: if `s ⊆ t`, then `closure s ≤ closure t`"] theorem closure_mono ⦃s t : Set M⦄ (h : s ⊆ t) : closure s ≤ closure t := closure_le.2 <| Subset.trans h subset_closure @[to_additive] theorem closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure s) : closure s = S := le_antisymm (closure_le.2 h₁) h₂ variable (S) /-- An induction principle for closure membership. If `p` holds for all elements of `s`, and is preserved under multiplication, then `p` holds for all elements of the closure of `s`. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership. If `p` holds for all elements of `s`, and is preserved under addition, then `p` holds for all elements of the additive closure of `s`."] theorem closure_induction {p : M → Prop} {x} (h : x ∈ closure s) (mem : ∀ x ∈ s, p x) (mul : ∀ x y, p x → p y → p (x * y)) : p x := (@closure_le _ _ _ ⟨p, mul _ _⟩).2 mem h /-- A dependent version of `Subsemigroup.closure_induction`. -/ @[to_additive (attr := elab_as_elim) "A dependent version of `AddSubsemigroup.closure_induction`. "] theorem closure_induction' (s : Set M) {p : ∀ x, x ∈ closure s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_closure h)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {x} (hx : x ∈ closure s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ closure s) (hc : p x hx) => hc exact closure_induction hx (fun x hx => ⟨_, mem x hx⟩) fun x y ⟨hx', hx⟩ ⟨hy', hy⟩ => ⟨_, mul _ _ _ _ hx hy⟩ /-- An induction principle for closure membership for predicates with two arguments. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership for predicates with two arguments."] theorem closure_induction₂ {p : M → M → Prop} {x} {y : M} (hx : x ∈ closure s) (hy : y ∈ closure s) (Hs : ∀ x ∈ s, ∀ y ∈ s, p x y) (Hmul_left : ∀ x y z, p x z → p y z → p (x * y) z) (Hmul_right : ∀ x y z, p z x → p z y → p z (x * y)) : p x y := closure_induction hx (fun x xs => closure_induction hy (Hs x xs) fun z _ h₁ h₂ => Hmul_right z _ _ h₁ h₂) fun _ _ h₁ h₂ => Hmul_left _ _ _ h₁ h₂ /-- If `s` is a dense set in a magma `M`, `Subsemigroup.closure s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, and verify that `p x` and `p y` imply `p (x * y)`. -/ @[to_additive (attr := elab_as_elim) "If `s` is a dense set in an additive monoid `M`, `AddSubsemigroup.closure s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, and verify that `p x` and `p y` imply `p (x + y)`."] theorem dense_induction {p : M → Prop} (x : M) {s : Set M} (hs : closure s = ⊤) (mem : ∀ x ∈ s, p x) (mul : ∀ x y, p x → p y → p (x * y)) : p x := by have : ∀ x ∈ closure s, p x := fun x hx => closure_induction hx mem mul simpa [hs] using this x variable (M) /-- `closure` forms a Galois insertion with the coercion to set. -/ @[to_additive "`closure` forms a Galois insertion with the coercion to set."] protected def gi : GaloisInsertion (@closure M _) SetLike.coe := GaloisConnection.toGaloisInsertion (fun _ _ => closure_le) fun _ => subset_closure variable {M} /-- Closure of a subsemigroup `S` equals `S`. -/ @[to_additive (attr := simp) "Additive closure of an additive subsemigroup `S` equals `S`"] theorem closure_eq : closure (S : Set M) = S := (Subsemigroup.gi M).l_u_eq S @[to_additive (attr := simp)] theorem closure_empty : closure (∅ : Set M) = ⊥ := (Subsemigroup.gi M).gc.l_bot @[to_additive (attr := simp)] theorem closure_univ : closure (univ : Set M) = ⊤ := @coe_top M _ ▸ closure_eq ⊤ @[to_additive] theorem closure_union (s t : Set M) : closure (s ∪ t) = closure s ⊔ closure t := (Subsemigroup.gi M).gc.l_sup @[to_additive] theorem closure_iUnion {ι} (s : ι → Set M) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Subsemigroup.gi M).gc.l_iSup @[to_additive] theorem closure_singleton_le_iff_mem (m : M) (p : Subsemigroup M) : closure {m} ≤ p ↔ m ∈ p := by rw [closure_le, singleton_subset_iff, SetLike.mem_coe] @[to_additive] theorem mem_iSup {ι : Sort*} (p : ι → Subsemigroup M) {m : M} : (m ∈ ⨆ i, p i) ↔ ∀ N, (∀ i, p i ≤ N) → m ∈ N := by rw [← closure_singleton_le_iff_mem, le_iSup_iff] simp only [closure_singleton_le_iff_mem] @[to_additive] theorem iSup_eq_closure {ι : Sort*} (p : ι → Subsemigroup M) : ⨆ i, p i = Subsemigroup.closure (⋃ i, (p i : Set M)) := by simp_rw [Subsemigroup.closure_iUnion, Subsemigroup.closure_eq] end Subsemigroup namespace MulHom variable [Mul N] open Subsemigroup /-- The subsemigroup of elements `x : M` such that `f x = g x` -/ @[to_additive "The additive subsemigroup of elements `x : M` such that `f x = g x`"] def eqLocus (f g : M →ₙ* N) : Subsemigroup M where carrier := { x | f x = g x } mul_mem' (hx : _ = _) (hy : _ = _) := by simp [*] /-- If two mul homomorphisms are equal on a set, then they are equal on its subsemigroup closure. -/ @[to_additive "If two add homomorphisms are equal on a set, then they are equal on its additive subsemigroup closure."] theorem eqOn_closure {f g : M →ₙ* N} {s : Set M} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) := show closure s ≤ f.eqLocus g from closure_le.2 h @[to_additive] theorem eq_of_eqOn_top {f g : M →ₙ* N} (h : Set.EqOn f g (⊤ : Subsemigroup M)) : f = g := ext fun _ => h trivial @[to_additive] theorem eq_of_eqOn_dense {s : Set M} (hs : closure s = ⊤) {f g : M →ₙ* N} (h : s.EqOn f g) : f = g := eq_of_eqOn_top <| hs ▸ eqOn_closure h end MulHom end NonAssoc section Assoc namespace MulHom open Subsemigroup /-- Let `s` be a subset of a semigroup `M` such that the closure of `s` is the whole semigroup. Then `MulHom.ofDense` defines a mul homomorphism from `M` asking for a proof of `f (x * y) = f x * f y` only for `y ∈ s`. -/ @[to_additive] def ofDense {M N} [Semigroup M] [Semigroup N] {s : Set M} (f : M → N) (hs : closure s = ⊤) (hmul : ∀ (x), ∀ y ∈ s, f (x * y) = f x * f y) : M →ₙ* N where toFun := f map_mul' x y := dense_induction y hs (fun y hy x => hmul x y hy) (fun y₁ y₂ h₁ h₂ x => by simp only [← mul_assoc, h₁, h₂]) x /-- Let `s` be a subset of an additive semigroup `M` such that the closure of `s` is the whole semigroup. Then `AddHom.ofDense` defines an additive homomorphism from `M` asking for a proof of `f (x + y) = f x + f y` only for `y ∈ s`. -/ add_decl_doc AddHom.ofDense @[to_additive (attr := simp, norm_cast)] theorem coe_ofDense [Semigroup M] [Semigroup N] {s : Set M} (f : M → N) (hs : closure s = ⊤) (hmul) : (ofDense f hs hmul : M → N) = f := rfl end MulHom end Assoc
Algebra\Group\Subsemigroup\Membership.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Group.Subsemigroup.Basic /-! # Subsemigroups: membership criteria In this file we prove various facts about membership in a subsemigroup. The intent is to mimic `GroupTheory/Submonoid/Membership`, but currently this file is mostly a stub and only provides rudimentary support. * `mem_iSup_of_directed`, `coe_iSup_of_directed`, `mem_sSup_of_directed_on`, `coe_sSup_of_directed_on`: the supremum of a directed collection of subsemigroup is their union. ## TODO * Define the `FreeSemigroup` generated by a set. This might require some rather substantial additions to low-level API. For example, developing the subtype of nonempty lists, then defining a product on nonempty lists, powers where the exponent is a positive natural, et cetera. Another option would be to define the `FreeSemigroup` as the subsemigroup (pushed to be a semigroup) of the `FreeMonoid` consisting of non-identity elements. ## Tags subsemigroup -/ assert_not_exists MonoidWithZero variable {ι : Sort*} {M A B : Type*} section NonAssoc variable [Mul M] open Set namespace Subsemigroup -- TODO: this section can be generalized to `[MulMemClass B M] [CompleteLattice B]` -- such that `complete_lattice.le` coincides with `set_like.le` @[to_additive] theorem mem_iSup_of_directed {S : ι → Subsemigroup M} (hS : Directed (· ≤ ·) S) {x : M} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ suffices x ∈ closure (⋃ i, (S i : Set M)) → ∃ i, x ∈ S i by simpa only [closure_iUnion, closure_eq (S _)] using this refine fun hx ↦ closure_induction hx (fun y hy ↦ mem_iUnion.mp hy) ?_ rintro x y ⟨i, hi⟩ ⟨j, hj⟩ rcases hS i j with ⟨k, hki, hkj⟩ exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ @[to_additive] theorem coe_iSup_of_directed {S : ι → Subsemigroup M} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : Subsemigroup M) : Set M) = ⋃ i, S i := Set.ext fun x => by simp [mem_iSup_of_directed hS] @[to_additive] theorem mem_sSup_of_directed_on {S : Set (Subsemigroup M)} (hS : DirectedOn (· ≤ ·) S) {x : M} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] @[to_additive] theorem coe_sSup_of_directed_on {S : Set (Subsemigroup M)} (hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set M) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directed_on hS] @[to_additive] theorem mem_sup_left {S T : Subsemigroup M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T := by have : S ≤ S ⊔ T := le_sup_left tauto @[to_additive] theorem mem_sup_right {S T : Subsemigroup M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T := by have : T ≤ S ⊔ T := le_sup_right tauto @[to_additive] theorem mul_mem_sup {S T : Subsemigroup M} {x y : M} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := mul_mem (mem_sup_left hx) (mem_sup_right hy) @[to_additive] theorem mem_iSup_of_mem {S : ι → Subsemigroup M} (i : ι) : ∀ {x : M}, x ∈ S i → x ∈ iSup S := by have : S i ≤ iSup S := le_iSup _ _ tauto @[to_additive] theorem mem_sSup_of_mem {S : Set (Subsemigroup M)} {s : Subsemigroup M} (hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ sSup S := by have : s ≤ sSup S := le_sSup hs tauto /-- An induction principle for elements of `⨆ i, S i`. If `C` holds all elements of `S i` for all `i`, and is preserved under multiplication, then it holds for all elements of the supremum of `S`. -/ @[to_additive (attr := elab_as_elim) "An induction principle for elements of `⨆ i, S i`. If `C` holds all elements of `S i` for all `i`, and is preserved under addition, then it holds for all elements of the supremum of `S`."] theorem iSup_induction (S : ι → Subsemigroup M) {C : M → Prop} {x₁ : M} (hx₁ : x₁ ∈ ⨆ i, S i) (mem : ∀ i, ∀ x₂ ∈ S i, C x₂) (mul : ∀ x y, C x → C y → C (x * y)) : C x₁ := by rw [iSup_eq_closure] at hx₁ refine closure_induction hx₁ (fun x₂ hx₂ => ?_) mul obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx₂ exact mem _ _ hi /-- A dependent version of `Subsemigroup.iSup_induction`. -/ @[to_additive (attr := elab_as_elim) "A dependent version of `AddSubsemigroup.iSup_induction`."] theorem iSup_induction' (S : ι → Subsemigroup M) {C : ∀ x, (x ∈ ⨆ i, S i) → Prop} (mem : ∀ (i) (x) (hxS : x ∈ S i), C x (mem_iSup_of_mem i ‹_›)) (mul : ∀ x y hx hy, C x hx → C y hy → C (x * y) (mul_mem ‹_› ‹_›)) {x₁ : M} (hx₁ : x₁ ∈ ⨆ i, S i) : C x₁ hx₁ := by refine Exists.elim ?_ fun (hx₁' : x₁ ∈ ⨆ i, S i) (hc : C x₁ hx₁') => hc refine @iSup_induction _ _ _ S (fun x' => ∃ hx'', C x' hx'') _ hx₁ (fun i x₂ hx₂ => ?_) fun x₃ y => ?_ · exact ⟨_, mem _ _ hx₂⟩ · rintro ⟨_, Cx⟩ ⟨_, Cy⟩ exact ⟨_, mul _ _ _ _ Cx Cy⟩ end Subsemigroup end NonAssoc
Algebra\Group\Subsemigroup\Operations.lean
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov, Yakov Pechersky, Jireh Loreaux -/ import Mathlib.Algebra.Group.Prod import Mathlib.Algebra.Group.Subsemigroup.Basic import Mathlib.Algebra.Group.TypeTags /-! # Operations on `Subsemigroup`s In this file we define various operations on `Subsemigroup`s and `MulHom`s. ## Main definitions ### Conversion between multiplicative and additive definitions * `Subsemigroup.toAddSubsemigroup`, `Subsemigroup.toAddSubsemigroup'`, `AddSubsemigroup.toSubsemigroup`, `AddSubsemigroup.toSubsemigroup'`: convert between multiplicative and additive subsemigroups of `M`, `Multiplicative M`, and `Additive M`. These are stated as `OrderIso`s. ### (Commutative) semigroup structure on a subsemigroup * `Subsemigroup.toSemigroup`, `Subsemigroup.toCommSemigroup`: a subsemigroup inherits a (commutative) semigroup structure. ### Operations on subsemigroups * `Subsemigroup.comap`: preimage of a subsemigroup under a semigroup homomorphism as a subsemigroup of the domain; * `Subsemigroup.map`: image of a subsemigroup under a semigroup homomorphism as a subsemigroup of the codomain; * `Subsemigroup.prod`: product of two subsemigroups `s : Subsemigroup M` and `t : Subsemigroup N` as a subsemigroup of `M × N`; ### Semigroup homomorphisms between subsemigroups * `Subsemigroup.subtype`: embedding of a subsemigroup into the ambient semigroup. * `Subsemigroup.inclusion`: given two subsemigroups `S`, `T` such that `S ≤ T`, `S.inclusion T` is the inclusion of `S` into `T` as a semigroup homomorphism; * `MulEquiv.subsemigroupCongr`: converts a proof of `S = T` into a semigroup isomorphism between `S` and `T`. * `Subsemigroup.prodEquiv`: semigroup isomorphism between `s.prod t` and `s × t`; ### Operations on `MulHom`s * `MulHom.srange`: range of a semigroup homomorphism as a subsemigroup of the codomain; * `MulHom.restrict`: restrict a semigroup homomorphism to a subsemigroup; * `MulHom.codRestrict`: restrict the codomain of a semigroup homomorphism to a subsemigroup; * `MulHom.srangeRestrict`: restrict a semigroup homomorphism to its range; ### Implementation notes This file follows closely `GroupTheory/Submonoid/Operations.lean`, omitting only that which is necessary. ## Tags subsemigroup, range, product, map, comap -/ assert_not_exists MonoidWithZero variable {M N P σ : Type*} /-! ### Conversion to/from `Additive`/`Multiplicative` -/ section variable [Mul M] /-- Subsemigroups of semigroup `M` are isomorphic to additive subsemigroups of `Additive M`. -/ @[simps] def Subsemigroup.toAddSubsemigroup : Subsemigroup M ≃o AddSubsemigroup (Additive M) where toFun S := { carrier := Additive.toMul ⁻¹' S add_mem' := S.mul_mem' } invFun S := { carrier := Additive.ofMul ⁻¹' S mul_mem' := S.add_mem' } left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl /-- Additive subsemigroups of an additive semigroup `Additive M` are isomorphic to subsemigroups of `M`. -/ abbrev AddSubsemigroup.toSubsemigroup' : AddSubsemigroup (Additive M) ≃o Subsemigroup M := Subsemigroup.toAddSubsemigroup.symm theorem Subsemigroup.toAddSubsemigroup_closure (S : Set M) : Subsemigroup.toAddSubsemigroup (Subsemigroup.closure S) = AddSubsemigroup.closure (Additive.toMul ⁻¹' S) := le_antisymm (Subsemigroup.toAddSubsemigroup.le_symm_apply.1 <| Subsemigroup.closure_le.2 (AddSubsemigroup.subset_closure (M := Additive M))) (AddSubsemigroup.closure_le.2 (Subsemigroup.subset_closure (M := M))) theorem AddSubsemigroup.toSubsemigroup'_closure (S : Set (Additive M)) : AddSubsemigroup.toSubsemigroup' (AddSubsemigroup.closure S) = Subsemigroup.closure (Additive.ofMul ⁻¹' S) := le_antisymm (AddSubsemigroup.toSubsemigroup'.le_symm_apply.1 <| AddSubsemigroup.closure_le.2 (Subsemigroup.subset_closure (M := M))) (Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := Additive M)) end section variable {A : Type*} [Add A] /-- Additive subsemigroups of an additive semigroup `A` are isomorphic to multiplicative subsemigroups of `Multiplicative A`. -/ @[simps] def AddSubsemigroup.toSubsemigroup : AddSubsemigroup A ≃o Subsemigroup (Multiplicative A) where toFun S := { carrier := Multiplicative.toAdd ⁻¹' S mul_mem' := S.add_mem' } invFun S := { carrier := Multiplicative.ofAdd ⁻¹' S add_mem' := S.mul_mem' } left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl /-- Subsemigroups of a semigroup `Multiplicative A` are isomorphic to additive subsemigroups of `A`. -/ abbrev Subsemigroup.toAddSubsemigroup' : Subsemigroup (Multiplicative A) ≃o AddSubsemigroup A := AddSubsemigroup.toSubsemigroup.symm theorem AddSubsemigroup.toSubsemigroup_closure (S : Set A) : AddSubsemigroup.toSubsemigroup (AddSubsemigroup.closure S) = Subsemigroup.closure (Multiplicative.toAdd ⁻¹' S) := le_antisymm (AddSubsemigroup.toSubsemigroup.to_galoisConnection.l_le <| AddSubsemigroup.closure_le.2 <| Subsemigroup.subset_closure (M := Multiplicative A)) (Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := A)) theorem Subsemigroup.toAddSubsemigroup'_closure (S : Set (Multiplicative A)) : Subsemigroup.toAddSubsemigroup' (Subsemigroup.closure S) = AddSubsemigroup.closure (Multiplicative.ofAdd ⁻¹' S) := le_antisymm (Subsemigroup.toAddSubsemigroup'.to_galoisConnection.l_le <| Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := A)) (AddSubsemigroup.closure_le.2 <| Subsemigroup.subset_closure (M := Multiplicative A)) end namespace Subsemigroup open Set /-! ### `comap` and `map` -/ variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M) /-- The preimage of a subsemigroup along a semigroup homomorphism is a subsemigroup. -/ @[to_additive "The preimage of an `AddSubsemigroup` along an `AddSemigroup` homomorphism is an `AddSubsemigroup`."] def comap (f : M →ₙ* N) (S : Subsemigroup N) : Subsemigroup M where carrier := f ⁻¹' S mul_mem' ha hb := show f (_ * _) ∈ S by rw [map_mul]; exact mul_mem ha hb @[to_additive (attr := simp)] theorem coe_comap (S : Subsemigroup N) (f : M →ₙ* N) : (S.comap f : Set M) = f ⁻¹' S := rfl @[to_additive (attr := simp)] theorem mem_comap {S : Subsemigroup N} {f : M →ₙ* N} {x : M} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl @[to_additive] theorem comap_comap (S : Subsemigroup P) (g : N →ₙ* P) (f : M →ₙ* N) : (S.comap g).comap f = S.comap (g.comp f) := rfl @[to_additive (attr := simp)] theorem comap_id (S : Subsemigroup P) : S.comap (MulHom.id _) = S := ext (by simp) /-- The image of a subsemigroup along a semigroup homomorphism is a subsemigroup. -/ @[to_additive "The image of an `AddSubsemigroup` along an `AddSemigroup` homomorphism is an `AddSubsemigroup`."] def map (f : M →ₙ* N) (S : Subsemigroup M) : Subsemigroup N where carrier := f '' S mul_mem' := by rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩ exact ⟨x * y, @mul_mem (Subsemigroup M) M _ _ _ _ _ _ hx hy, by rw [map_mul]⟩ @[to_additive (attr := simp)] theorem coe_map (f : M →ₙ* N) (S : Subsemigroup M) : (S.map f : Set N) = f '' S := rfl @[to_additive (attr := simp)] theorem mem_map {f : M →ₙ* N} {S : Subsemigroup M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := mem_image _ _ _ @[to_additive] theorem mem_map_of_mem (f : M →ₙ* N) {S : Subsemigroup M} {x : M} (hx : x ∈ S) : f x ∈ S.map f := mem_image_of_mem f hx @[to_additive] theorem apply_coe_mem_map (f : M →ₙ* N) (S : Subsemigroup M) (x : S) : f x ∈ S.map f := mem_map_of_mem f x.prop @[to_additive] theorem map_map (g : N →ₙ* P) (f : M →ₙ* N) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ -- The simpNF linter says that the LHS can be simplified via `Subsemigroup.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[to_additive (attr := simp, nolint simpNF)] theorem mem_map_iff_mem {f : M →ₙ* N} (hf : Function.Injective f) {S : Subsemigroup M} {x : M} : f x ∈ S.map f ↔ x ∈ S := hf.mem_set_image @[to_additive] theorem map_le_iff_le_comap {f : M →ₙ* N} {S : Subsemigroup M} {T : Subsemigroup N} : S.map f ≤ T ↔ S ≤ T.comap f := image_subset_iff @[to_additive] theorem gc_map_comap (f : M →ₙ* N) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap @[to_additive] theorem map_le_of_le_comap {T : Subsemigroup N} {f : M →ₙ* N} : S ≤ T.comap f → S.map f ≤ T := (gc_map_comap f).l_le @[to_additive] theorem le_comap_of_map_le {T : Subsemigroup N} {f : M →ₙ* N} : S.map f ≤ T → S ≤ T.comap f := (gc_map_comap f).le_u @[to_additive] theorem le_comap_map {f : M →ₙ* N} : S ≤ (S.map f).comap f := (gc_map_comap f).le_u_l _ @[to_additive] theorem map_comap_le {S : Subsemigroup N} {f : M →ₙ* N} : (S.comap f).map f ≤ S := (gc_map_comap f).l_u_le _ @[to_additive] theorem monotone_map {f : M →ₙ* N} : Monotone (map f) := (gc_map_comap f).monotone_l @[to_additive] theorem monotone_comap {f : M →ₙ* N} : Monotone (comap f) := (gc_map_comap f).monotone_u @[to_additive (attr := simp)] theorem map_comap_map {f : M →ₙ* N} : ((S.map f).comap f).map f = S.map f := (gc_map_comap f).l_u_l_eq_l _ @[to_additive (attr := simp)] theorem comap_map_comap {S : Subsemigroup N} {f : M →ₙ* N} : ((S.comap f).map f).comap f = S.comap f := (gc_map_comap f).u_l_u_eq_u _ @[to_additive] theorem map_sup (S T : Subsemigroup M) (f : M →ₙ* N) : (S ⊔ T).map f = S.map f ⊔ T.map f := (gc_map_comap f).l_sup @[to_additive] theorem map_iSup {ι : Sort*} (f : M →ₙ* N) (s : ι → Subsemigroup M) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup @[to_additive] theorem comap_inf (S T : Subsemigroup N) (f : M →ₙ* N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f := (gc_map_comap f).u_inf @[to_additive] theorem comap_iInf {ι : Sort*} (f : M →ₙ* N) (s : ι → Subsemigroup N) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf @[to_additive (attr := simp)] theorem map_bot (f : M →ₙ* N) : (⊥ : Subsemigroup M).map f = ⊥ := (gc_map_comap f).l_bot @[to_additive (attr := simp)] theorem comap_top (f : M →ₙ* N) : (⊤ : Subsemigroup N).comap f = ⊤ := (gc_map_comap f).u_top @[to_additive (attr := simp)] theorem map_id (S : Subsemigroup M) : S.map (MulHom.id M) = S := ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩ section GaloisCoinsertion variable {ι : Type*} {f : M →ₙ* N} /-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/ @[to_additive " `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. "] def gciMapComap (hf : Function.Injective f) : GaloisCoinsertion (map f) (comap f) := (gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff] variable (hf : Function.Injective f) @[to_additive] theorem comap_map_eq_of_injective (S : Subsemigroup M) : (S.map f).comap f = S := (gciMapComap hf).u_l_eq _ @[to_additive] theorem comap_surjective_of_injective : Function.Surjective (comap f) := (gciMapComap hf).u_surjective @[to_additive] theorem map_injective_of_injective : Function.Injective (map f) := (gciMapComap hf).l_injective @[to_additive] theorem comap_inf_map_of_injective (S T : Subsemigroup M) : (S.map f ⊓ T.map f).comap f = S ⊓ T := (gciMapComap hf).u_inf_l _ _ @[to_additive] theorem comap_iInf_map_of_injective (S : ι → Subsemigroup M) : (⨅ i, (S i).map f).comap f = iInf S := (gciMapComap hf).u_iInf_l _ @[to_additive] theorem comap_sup_map_of_injective (S T : Subsemigroup M) : (S.map f ⊔ T.map f).comap f = S ⊔ T := (gciMapComap hf).u_sup_l _ _ @[to_additive] theorem comap_iSup_map_of_injective (S : ι → Subsemigroup M) : (⨆ i, (S i).map f).comap f = iSup S := (gciMapComap hf).u_iSup_l _ @[to_additive] theorem map_le_map_iff_of_injective {S T : Subsemigroup M} : S.map f ≤ T.map f ↔ S ≤ T := (gciMapComap hf).l_le_l_iff @[to_additive] theorem map_strictMono_of_injective : StrictMono (map f) := (gciMapComap hf).strictMono_l end GaloisCoinsertion section GaloisInsertion variable {ι : Type*} {f : M →ₙ* N} (hf : Function.Surjective f) /-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/ @[to_additive " `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. "] def giMapComap : GaloisInsertion (map f) (comap f) := (gc_map_comap f).toGaloisInsertion fun S x h => let ⟨y, hy⟩ := hf x mem_map.2 ⟨y, by simp [hy, h]⟩ @[to_additive] theorem map_comap_eq_of_surjective (S : Subsemigroup N) : (S.comap f).map f = S := (giMapComap hf).l_u_eq _ @[to_additive] theorem map_surjective_of_surjective : Function.Surjective (map f) := (giMapComap hf).l_surjective @[to_additive] theorem comap_injective_of_surjective : Function.Injective (comap f) := (giMapComap hf).u_injective @[to_additive] theorem map_inf_comap_of_surjective (S T : Subsemigroup N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T := (giMapComap hf).l_inf_u _ _ @[to_additive] theorem map_iInf_comap_of_surjective (S : ι → Subsemigroup N) : (⨅ i, (S i).comap f).map f = iInf S := (giMapComap hf).l_iInf_u _ @[to_additive] theorem map_sup_comap_of_surjective (S T : Subsemigroup N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T := (giMapComap hf).l_sup_u _ _ @[to_additive] theorem map_iSup_comap_of_surjective (S : ι → Subsemigroup N) : (⨆ i, (S i).comap f).map f = iSup S := (giMapComap hf).l_iSup_u _ @[to_additive] theorem comap_le_comap_iff_of_surjective {S T : Subsemigroup N} : S.comap f ≤ T.comap f ↔ S ≤ T := (giMapComap hf).u_le_u_iff @[to_additive] theorem comap_strictMono_of_surjective : StrictMono (comap f) := (giMapComap hf).strictMono_u end GaloisInsertion end Subsemigroup namespace MulMemClass variable {A : Type*} [Mul M] [SetLike A M] [hA : MulMemClass A M] (S' : A) -- lower priority so other instances are found first /-- A submagma of a magma inherits a multiplication. -/ @[to_additive "An additive submagma of an additive magma inherits an addition."] instance (priority := 900) mul : Mul S' := ⟨fun a b => ⟨a.1 * b.1, mul_mem a.2 b.2⟩⟩ -- lower priority so later simp lemmas are used first; to appease simp_nf @[to_additive (attr := simp low, norm_cast)] theorem coe_mul (x y : S') : (↑(x * y) : M) = ↑x * ↑y := rfl -- lower priority so later simp lemmas are used first; to appease simp_nf @[to_additive (attr := simp low)] theorem mk_mul_mk (x y : M) (hx : x ∈ S') (hy : y ∈ S') : (⟨x, hx⟩ : S') * ⟨y, hy⟩ = ⟨x * y, mul_mem hx hy⟩ := rfl @[to_additive] theorem mul_def (x y : S') : x * y = ⟨x * y, mul_mem x.2 y.2⟩ := rfl /-- A subsemigroup of a semigroup inherits a semigroup structure. -/ @[to_additive "An `AddSubsemigroup` of an `AddSemigroup` inherits an `AddSemigroup` structure."] instance toSemigroup {M : Type*} [Semigroup M] {A : Type*} [SetLike A M] [MulMemClass A M] (S : A) : Semigroup S := Subtype.coe_injective.semigroup Subtype.val fun _ _ => rfl /-- A subsemigroup of a `CommSemigroup` is a `CommSemigroup`. -/ @[to_additive "An `AddSubsemigroup` of an `AddCommSemigroup` is an `AddCommSemigroup`."] instance toCommSemigroup {M} [CommSemigroup M] {A : Type*} [SetLike A M] [MulMemClass A M] (S : A) : CommSemigroup S := Subtype.coe_injective.commSemigroup Subtype.val fun _ _ => rfl /-- The natural semigroup hom from a subsemigroup of semigroup `M` to `M`. -/ @[to_additive "The natural semigroup hom from an `AddSubsemigroup` of `AddSubsemigroup` `M` to `M`."] def subtype : S' →ₙ* M where toFun := Subtype.val; map_mul' := fun _ _ => rfl @[to_additive (attr := simp)] theorem coe_subtype : (MulMemClass.subtype S' : S' → M) = Subtype.val := rfl end MulMemClass namespace Subsemigroup variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M) /-- The top subsemigroup is isomorphic to the semigroup. -/ @[to_additive (attr := simps) "The top additive subsemigroup is isomorphic to the additive semigroup."] def topEquiv : (⊤ : Subsemigroup M) ≃* M where toFun x := x invFun x := ⟨x, mem_top x⟩ left_inv x := x.eta _ right_inv _ := rfl map_mul' _ _ := rfl @[to_additive (attr := simp)] theorem topEquiv_toMulHom : ((topEquiv : _ ≃* M) : _ →ₙ* M) = MulMemClass.subtype (⊤ : Subsemigroup M) := rfl /-- A subsemigroup is isomorphic to its image under an injective function -/ @[to_additive "An additive subsemigroup is isomorphic to its image under an injective function"] noncomputable def equivMapOfInjective (f : M →ₙ* N) (hf : Function.Injective f) : S ≃* S.map f := { Equiv.Set.image f S hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) } @[to_additive (attr := simp)] theorem coe_equivMapOfInjective_apply (f : M →ₙ* N) (hf : Function.Injective f) (x : S) : (equivMapOfInjective S f hf x : N) = f x := rfl @[to_additive (attr := simp)] theorem closure_closure_coe_preimage {s : Set M} : closure ((Subtype.val : closure s → M) ⁻¹' s) = ⊤ := eq_top_iff.2 fun x => Subtype.recOn x fun _ hx _ => closure_induction' (p := fun y hy ↦ ⟨y, hy⟩ ∈ closure (((↑) : closure s → M) ⁻¹' s)) (fun _ hg => subset_closure hg) (fun _ _ _ _ => Subsemigroup.mul_mem _) hx /-- Given `Subsemigroup`s `s`, `t` of semigroups `M`, `N` respectively, `s × t` as a subsemigroup of `M × N`. -/ @[to_additive prod "Given `AddSubsemigroup`s `s`, `t` of `AddSemigroup`s `A`, `B` respectively, `s × t` as an `AddSubsemigroup` of `A × B`."] def prod (s : Subsemigroup M) (t : Subsemigroup N) : Subsemigroup (M × N) where carrier := s ×ˢ t mul_mem' hp hq := ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩ @[to_additive coe_prod] theorem coe_prod (s : Subsemigroup M) (t : Subsemigroup N) : (s.prod t : Set (M × N)) = (s : Set M) ×ˢ (t : Set N) := rfl @[to_additive mem_prod] theorem mem_prod {s : Subsemigroup M} {t : Subsemigroup N} {p : M × N} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl @[to_additive prod_mono] theorem prod_mono {s₁ s₂ : Subsemigroup M} {t₁ t₂ : Subsemigroup N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ := Set.prod_mono hs ht @[to_additive prod_top] theorem prod_top (s : Subsemigroup M) : s.prod (⊤ : Subsemigroup N) = s.comap (MulHom.fst M N) := ext fun x => by simp [mem_prod, MulHom.coe_fst] @[to_additive top_prod] theorem top_prod (s : Subsemigroup N) : (⊤ : Subsemigroup M).prod s = s.comap (MulHom.snd M N) := ext fun x => by simp [mem_prod, MulHom.coe_snd] @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subsemigroup M).prod (⊤ : Subsemigroup N) = ⊤ := (top_prod _).trans <| comap_top _ @[to_additive bot_prod_bot] theorem bot_prod_bot : (⊥ : Subsemigroup M).prod (⊥ : Subsemigroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod, Prod.one_eq_mk] /-- The product of subsemigroups is isomorphic to their product as semigroups. -/ @[to_additive prodEquiv "The product of additive subsemigroups is isomorphic to their product as additive semigroups"] def prodEquiv (s : Subsemigroup M) (t : Subsemigroup N) : s.prod t ≃* s × t := { (Equiv.Set.prod (s : Set M) (t : Set N)) with map_mul' := fun _ _ => rfl } open MulHom @[to_additive] theorem mem_map_equiv {f : M ≃* N} {K : Subsemigroup M} {x : N} : x ∈ K.map (f : M →ₙ* N) ↔ f.symm x ∈ K := @Set.mem_image_equiv _ _ (K : Set M) f.toEquiv x @[to_additive] theorem map_equiv_eq_comap_symm (f : M ≃* N) (K : Subsemigroup M) : K.map (f : M →ₙ* N) = K.comap (f.symm : N →ₙ* M) := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) @[to_additive] theorem comap_equiv_eq_map_symm (f : N ≃* M) (K : Subsemigroup M) : K.comap (f : N →ₙ* M) = K.map (f.symm : M →ₙ* N) := (map_equiv_eq_comap_symm f.symm K).symm @[to_additive (attr := simp)] theorem map_equiv_top (f : M ≃* N) : (⊤ : Subsemigroup M).map (f : M →ₙ* N) = ⊤ := SetLike.coe_injective <| Set.image_univ.trans f.surjective.range_eq @[to_additive le_prod_iff] theorem le_prod_iff {s : Subsemigroup M} {t : Subsemigroup N} {u : Subsemigroup (M × N)} : u ≤ s.prod t ↔ u.map (fst M N) ≤ s ∧ u.map (snd M N) ≤ t := by constructor · intro h constructor · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).1 · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).2 · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩ end Subsemigroup namespace MulHom open Subsemigroup variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M) /-- The range of a semigroup homomorphism is a subsemigroup. See Note [range copy pattern]. -/ @[to_additive "The range of an `AddHom` is an `AddSubsemigroup`."] def srange (f : M →ₙ* N) : Subsemigroup N := ((⊤ : Subsemigroup M).map f).copy (Set.range f) Set.image_univ.symm @[to_additive (attr := simp)] theorem coe_srange (f : M →ₙ* N) : (f.srange : Set N) = Set.range f := rfl @[to_additive (attr := simp)] theorem mem_srange {f : M →ₙ* N} {y : N} : y ∈ f.srange ↔ ∃ x, f x = y := Iff.rfl @[to_additive] theorem srange_eq_map (f : M →ₙ* N) : f.srange = (⊤ : Subsemigroup M).map f := copy_eq _ @[to_additive] theorem map_srange (g : N →ₙ* P) (f : M →ₙ* N) : f.srange.map g = (g.comp f).srange := by simpa only [srange_eq_map] using (⊤ : Subsemigroup M).map_map g f @[to_additive] theorem srange_top_iff_surjective {N} [Mul N] {f : M →ₙ* N} : f.srange = (⊤ : Subsemigroup N) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_srange, coe_top]) Set.range_iff_surjective /-- The range of a surjective semigroup hom is the whole of the codomain. -/ @[to_additive (attr := simp) "The range of a surjective `AddSemigroup` hom is the whole of the codomain."] theorem srange_top_of_surjective {N} [Mul N] (f : M →ₙ* N) (hf : Function.Surjective f) : f.srange = (⊤ : Subsemigroup N) := srange_top_iff_surjective.2 hf @[to_additive] theorem mclosure_preimage_le (f : M →ₙ* N) (s : Set N) : closure (f ⁻¹' s) ≤ (closure s).comap f := closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx /-- The image under a semigroup hom of the subsemigroup generated by a set equals the subsemigroup generated by the image of the set. -/ @[to_additive "The image under an `AddSemigroup` hom of the `AddSubsemigroup` generated by a set equals the `AddSubsemigroup` generated by the image of the set."] theorem map_mclosure (f : M →ₙ* N) (s : Set M) : (closure s).map f = closure (f '' s) := le_antisymm (map_le_iff_le_comap.2 <| le_trans (closure_mono <| Set.subset_preimage_image _ _) (mclosure_preimage_le _ _)) (closure_le.2 <| Set.image_subset _ subset_closure) /-- Restriction of a semigroup hom to a subsemigroup of the domain. -/ @[to_additive "Restriction of an AddSemigroup hom to an `AddSubsemigroup` of the domain."] def restrict {N : Type*} [Mul N] [SetLike σ M] [MulMemClass σ M] (f : M →ₙ* N) (S : σ) : S →ₙ* N := f.comp (MulMemClass.subtype S) @[to_additive (attr := simp)] theorem restrict_apply {N : Type*} [Mul N] [SetLike σ M] [MulMemClass σ M] (f : M →ₙ* N) {S : σ} (x : S) : f.restrict S x = f x := rfl /-- Restriction of a semigroup hom to a subsemigroup of the codomain. -/ @[to_additive (attr := simps) "Restriction of an `AddSemigroup` hom to an `AddSubsemigroup` of the codomain."] def codRestrict [SetLike σ N] [MulMemClass σ N] (f : M →ₙ* N) (S : σ) (h : ∀ x, f x ∈ S) : M →ₙ* S where toFun n := ⟨f n, h n⟩ map_mul' x y := Subtype.eq (map_mul f x y) /-- Restriction of a semigroup hom to its range interpreted as a subsemigroup. -/ @[to_additive "Restriction of an `AddSemigroup` hom to its range interpreted as a subsemigroup."] def srangeRestrict {N} [Mul N] (f : M →ₙ* N) : M →ₙ* f.srange := (f.codRestrict f.srange) fun x => ⟨x, rfl⟩ @[to_additive (attr := simp)] theorem coe_srangeRestrict {N} [Mul N] (f : M →ₙ* N) (x : M) : (f.srangeRestrict x : N) = f x := rfl @[to_additive] theorem srangeRestrict_surjective (f : M →ₙ* N) : Function.Surjective f.srangeRestrict := fun ⟨_, ⟨x, rfl⟩⟩ => ⟨x, rfl⟩ @[to_additive prod_map_comap_prod'] theorem prod_map_comap_prod' {M' : Type*} {N' : Type*} [Mul M'] [Mul N'] (f : M →ₙ* N) (g : M' →ₙ* N') (S : Subsemigroup N) (S' : Subsemigroup N') : (S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ /-- The `MulHom` from the preimage of a subsemigroup to itself. -/ @[to_additive (attr := simps) "The `AddHom` from the preimage of an additive subsemigroup to itself."] def subsemigroupComap (f : M →ₙ* N) (N' : Subsemigroup N) : N'.comap f →ₙ* N' where toFun x := ⟨f x, x.prop⟩ map_mul' x y := Subtype.eq <| map_mul (M := M) (N := N) f x y /-- The `MulHom` from a subsemigroup to its image. See `MulEquiv.subsemigroupMap` for a variant for `MulEquiv`s. -/ @[to_additive (attr := simps) "the `AddHom` from an additive subsemigroup to its image. See `AddEquiv.addSubsemigroupMap` for a variant for `AddEquiv`s."] def subsemigroupMap (f : M →ₙ* N) (M' : Subsemigroup M) : M' →ₙ* M'.map f where toFun x := ⟨f x, ⟨x, x.prop, rfl⟩⟩ map_mul' x y := Subtype.eq <| map_mul (M := M) (N := N) f x y @[to_additive] theorem subsemigroupMap_surjective (f : M →ₙ* N) (M' : Subsemigroup M) : Function.Surjective (f.subsemigroupMap M') := by rintro ⟨_, x, hx, rfl⟩ exact ⟨⟨x, hx⟩, rfl⟩ end MulHom namespace Subsemigroup open MulHom variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M) @[to_additive (attr := simp)] theorem srange_fst [Nonempty N] : (fst M N).srange = ⊤ := (fst M N).srange_top_of_surjective <| Prod.fst_surjective @[to_additive (attr := simp)] theorem srange_snd [Nonempty M] : (snd M N).srange = ⊤ := (snd M N).srange_top_of_surjective <| Prod.snd_surjective @[to_additive prod_eq_top_iff] theorem prod_eq_top_iff [Nonempty M] [Nonempty N] {s : Subsemigroup M} {t : Subsemigroup N} : s.prod t = ⊤ ↔ s = ⊤ ∧ t = ⊤ := by simp only [eq_top_iff, le_prod_iff, ← (gc_map_comap _).le_iff_le, ← srange_eq_map, srange_fst, srange_snd] /-- The semigroup hom associated to an inclusion of subsemigroups. -/ @[to_additive "The `AddSemigroup` hom associated to an inclusion of subsemigroups."] def inclusion {S T : Subsemigroup M} (h : S ≤ T) : S →ₙ* T := (MulMemClass.subtype S).codRestrict _ fun x => h x.2 @[to_additive (attr := simp)] theorem range_subtype (s : Subsemigroup M) : (MulMemClass.subtype s).srange = s := SetLike.coe_injective <| (coe_srange _).trans <| Subtype.range_coe @[to_additive] theorem eq_top_iff' : S = ⊤ ↔ ∀ x : M, x ∈ S := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ end Subsemigroup namespace MulEquiv variable [Mul M] [Mul N] {S T : Subsemigroup M} /-- Makes the identity isomorphism from a proof that two subsemigroups of a multiplicative semigroup are equal. -/ @[to_additive "Makes the identity additive isomorphism from a proof two subsemigroups of an additive semigroup are equal."] def subsemigroupCongr (h : S = T) : S ≃* T := { Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl } -- this name is primed so that the version to `f.range` instead of `f.srange` can be unprimed. /-- A semigroup homomorphism `f : M →ₙ* N` with a left-inverse `g : N → M` defines a multiplicative equivalence between `M` and `f.srange`. This is a bidirectional version of `MulHom.srangeRestrict`. -/ @[to_additive (attr := simps (config := { simpRhs := true })) "An additive semigroup homomorphism `f : M →+ N` with a left-inverse `g : N → M` defines an additive equivalence between `M` and `f.srange`. This is a bidirectional version of `AddHom.srangeRestrict`. "] def ofLeftInverse (f : M →ₙ* N) {g : N → M} (h : Function.LeftInverse g f) : M ≃* f.srange := { f.srangeRestrict with toFun := f.srangeRestrict invFun := g ∘ MulMemClass.subtype f.srange left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := MulHom.mem_srange.mp x.prop show f (g x) = x by rw [← hx', h x'] } /-- A `MulEquiv` `φ` between two semigroups `M` and `N` induces a `MulEquiv` between a subsemigroup `S ≤ M` and the subsemigroup `φ(S) ≤ N`. See `MulHom.subsemigroupMap` for a variant for `MulHom`s. -/ @[to_additive (attr := simps) "An `AddEquiv` `φ` between two additive semigroups `M` and `N` induces an `AddEquiv` between a subsemigroup `S ≤ M` and the subsemigroup `φ(S) ≤ N`. See `AddHom.addSubsemigroupMap` for a variant for `AddHom`s."] def subsemigroupMap (e : M ≃* N) (S : Subsemigroup M) : S ≃* S.map (e : M →ₙ* N) := { -- we restate this for `simps` to avoid `⇑e.symm.toEquiv x` (e : M →ₙ* N).subsemigroupMap S, (e : M ≃ N).image S with toFun := fun x => ⟨e x, _⟩ invFun := fun x => ⟨e.symm x, _⟩ } end MulEquiv namespace Subsemigroup variable [Mul M] [Mul N] @[to_additive] theorem map_comap_eq (f : M →ₙ* N) (S : Subsemigroup N) : (S.comap f).map f = S ⊓ f.srange := SetLike.coe_injective Set.image_preimage_eq_inter_range @[to_additive] theorem map_comap_eq_self {f : M →ₙ* N} {S : Subsemigroup N} (h : S ≤ f.srange) : (S.comap f).map f = S := by simpa only [inf_of_le_left h] using map_comap_eq f S end Subsemigroup
Algebra\Group\Units\Equiv.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Units.Hom /-! # Multiplicative and additive equivalence acting on units. -/ assert_not_exists MonoidWithZero assert_not_exists DenselyOrdered variable {F α β A B M N P Q G H : Type*} /-- A group is isomorphic to its group of units. -/ @[to_additive (attr := simps apply_val symm_apply) "An additive group is isomorphic to its group of additive units"] def toUnits [Group G] : G ≃* Gˣ where toFun x := ⟨x, x⁻¹, mul_inv_self _, inv_mul_self _⟩ invFun x := x left_inv _ := rfl right_inv _ := Units.ext rfl map_mul' _ _ := Units.ext rfl @[to_additive (attr := simp)] lemma toUnits_val_apply {G : Type*} [Group G] (x : Gˣ) : toUnits (x : G) = x := by simp_rw [MulEquiv.apply_eq_iff_symm_apply, toUnits_symm_apply] namespace Units variable [Monoid M] [Monoid N] [Monoid P] /-- A multiplicative equivalence of monoids defines a multiplicative equivalence of their groups of units. -/ def mapEquiv (h : M ≃* N) : Mˣ ≃* Nˣ := { map h.toMonoidHom with invFun := map h.symm.toMonoidHom, left_inv := fun u => ext <| h.left_inv u, right_inv := fun u => ext <| h.right_inv u } @[simp] theorem mapEquiv_symm (h : M ≃* N) : (mapEquiv h).symm = mapEquiv h.symm := rfl @[simp] theorem coe_mapEquiv (h : M ≃* N) (x : Mˣ) : (mapEquiv h x : N) = h x := rfl /-- Left multiplication by a unit of a monoid is a permutation of the underlying type. -/ @[to_additive (attr := simps (config := .asFn) apply) "Left addition of an additive unit is a permutation of the underlying type."] def mulLeft (u : Mˣ) : Equiv.Perm M where toFun x := u * x invFun x := u⁻¹ * x left_inv := u.inv_mul_cancel_left right_inv := u.mul_inv_cancel_left @[to_additive (attr := simp)] theorem mulLeft_symm (u : Mˣ) : u.mulLeft.symm = u⁻¹.mulLeft := Equiv.ext fun _ => rfl @[to_additive] theorem mulLeft_bijective (a : Mˣ) : Function.Bijective ((a * ·) : M → M) := (mulLeft a).bijective /-- Right multiplication by a unit of a monoid is a permutation of the underlying type. -/ @[to_additive (attr := simps (config := .asFn) apply) "Right addition of an additive unit is a permutation of the underlying type."] def mulRight (u : Mˣ) : Equiv.Perm M where toFun x := x * u invFun x := x * ↑u⁻¹ left_inv x := mul_inv_cancel_right x u right_inv x := inv_mul_cancel_right x u @[to_additive (attr := simp)] theorem mulRight_symm (u : Mˣ) : u.mulRight.symm = u⁻¹.mulRight := Equiv.ext fun _ => rfl @[to_additive] theorem mulRight_bijective (a : Mˣ) : Function.Bijective ((· * a) : M → M) := (mulRight a).bijective end Units namespace Equiv section Group variable [Group G] /-- Left multiplication in a `Group` is a permutation of the underlying type. -/ @[to_additive "Left addition in an `AddGroup` is a permutation of the underlying type."] protected def mulLeft (a : G) : Perm G := (toUnits a).mulLeft @[to_additive (attr := simp)] theorem coe_mulLeft (a : G) : ⇑(Equiv.mulLeft a) = (a * ·) := rfl -- Porting note: we don't put `@[simp]` on the additive version; -- mysteriously simp can already prove that one (although not the multiplicative one)! /-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/ @[to_additive "Extra simp lemma that `dsimp` can use. `simp` will never use this.", simp, nolint simpNF] theorem mulLeft_symm_apply (a : G) : ((Equiv.mulLeft a).symm : G → G) = (a⁻¹ * ·) := rfl @[to_additive (attr := simp)] theorem mulLeft_symm (a : G) : (Equiv.mulLeft a).symm = Equiv.mulLeft a⁻¹ := ext fun _ => rfl @[to_additive] theorem _root_.Group.mulLeft_bijective (a : G) : Function.Bijective (a * ·) := (Equiv.mulLeft a).bijective /-- Right multiplication in a `Group` is a permutation of the underlying type. -/ @[to_additive "Right addition in an `AddGroup` is a permutation of the underlying type."] protected def mulRight (a : G) : Perm G := (toUnits a).mulRight @[to_additive (attr := simp)] theorem coe_mulRight (a : G) : ⇑(Equiv.mulRight a) = fun x => x * a := rfl @[to_additive (attr := simp)] theorem mulRight_symm (a : G) : (Equiv.mulRight a).symm = Equiv.mulRight a⁻¹ := ext fun _ => rfl /-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/ @[to_additive "Extra simp lemma that `dsimp` can use. `simp` will never use this.", simp, nolint simpNF] theorem mulRight_symm_apply (a : G) : ((Equiv.mulRight a).symm : G → G) = fun x => x * a⁻¹ := rfl @[to_additive] theorem _root_.Group.mulRight_bijective (a : G) : Function.Bijective (· * a) := (Equiv.mulRight a).bijective /-- A version of `Equiv.mulLeft a b⁻¹` that is defeq to `a / b`. -/ @[to_additive (attr := simps) " A version of `Equiv.addLeft a (-b)` that is defeq to `a - b`. "] protected def divLeft (a : G) : G ≃ G where toFun b := a / b invFun b := b⁻¹ * a left_inv b := by simp [div_eq_mul_inv] right_inv b := by simp [div_eq_mul_inv] @[to_additive] theorem divLeft_eq_inv_trans_mulLeft (a : G) : Equiv.divLeft a = (Equiv.inv G).trans (Equiv.mulLeft a) := ext fun _ => div_eq_mul_inv _ _ /-- A version of `Equiv.mulRight a⁻¹ b` that is defeq to `b / a`. -/ @[to_additive (attr := simps) " A version of `Equiv.addRight (-a) b` that is defeq to `b - a`. "] protected def divRight (a : G) : G ≃ G where toFun b := b / a invFun b := b * a left_inv b := by simp [div_eq_mul_inv] right_inv b := by simp [div_eq_mul_inv] @[to_additive] theorem divRight_eq_mulRight_inv (a : G) : Equiv.divRight a = Equiv.mulRight a⁻¹ := ext fun _ => div_eq_mul_inv _ _ end Group end Equiv variable (α) in /-- The `αˣ` type is equivalent to a subtype of `α × α`. -/ @[simps] def unitsEquivProdSubtype [Monoid α] : αˣ ≃ {p : α × α // p.1 * p.2 = 1 ∧ p.2 * p.1 = 1} where toFun u := ⟨(u, ↑u⁻¹), u.val_inv, u.inv_val⟩ invFun p := Units.mk (p : α × α).1 (p : α × α).2 p.prop.1 p.prop.2 left_inv _ := Units.ext rfl right_inv _ := Subtype.ext <| Prod.ext rfl rfl -- Porting note: we don't put `@[simp]` on the additive version; -- mysteriously simp can already prove that one (although not the multiplicative one)! -- Porting note: `@[simps apply]` removed because right now it's generating lemmas which -- aren't in simp normal form (they contain a `toFun`) /-- In a `DivisionCommMonoid`, `Equiv.inv` is a `MulEquiv`. There is a variant of this `MulEquiv.inv' G : G ≃* Gᵐᵒᵖ` for the non-commutative case. -/ @[to_additive (attr := simps apply) "When the `AddGroup` is commutative, `Equiv.neg` is an `AddEquiv`."] def MulEquiv.inv (G : Type*) [DivisionCommMonoid G] : G ≃* G := { Equiv.inv G with toFun := Inv.inv, invFun := Inv.inv, map_mul' := mul_inv } @[to_additive (attr := simp)] theorem MulEquiv.inv_symm (G : Type*) [DivisionCommMonoid G] : (MulEquiv.inv G).symm = MulEquiv.inv G := rfl -- Porting note: no `add_equiv.neg_symm` in `mathlib3` @[to_additive] protected theorem MulEquiv.map_isUnit_iff {M N} [Monoid M] [Monoid N] [EquivLike F M N] [MonoidHomClass F M N] (f : F) {m : M} : IsUnit (f m) ↔ IsUnit m := isUnit_map_of_leftInverse (MonoidHom.inverse (f : M →* N) (EquivLike.inv f) (EquivLike.left_inv f) <| EquivLike.right_inv f) (EquivLike.left_inv f)
Algebra\Group\Units\Hom.lean
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Chris Hughes, Kevin Buzzard -/ import Mathlib.Algebra.Group.Hom.Defs import Mathlib.Algebra.Group.Units /-! # Monoid homomorphisms and units This file allows to lift monoid homomorphisms to group homomorphisms of their units subgroups. It also contains unrelated results about `Units` that depend on `MonoidHom`. ## Main declarations * `Units.map`: Turn a homomorphism from `α` to `β` monoids into a homomorphism from `αˣ` to `βˣ`. * `MonoidHom.toHomUnits`: Turn a homomorphism from a group `α` to `β` into a homomorphism from `α` to `βˣ`. -/ assert_not_exists MonoidWithZero assert_not_exists DenselyOrdered open Function universe u v w section MonoidHomClass /-- If two homomorphisms from a division monoid to a monoid are equal at a unit `x`, then they are equal at `x⁻¹`. -/ @[to_additive "If two homomorphisms from a subtraction monoid to an additive monoid are equal at an additive unit `x`, then they are equal at `-x`."] theorem IsUnit.eq_on_inv {F G N} [DivisionMonoid G] [Monoid N] [FunLike F G N] [MonoidHomClass F G N] {x : G} (hx : IsUnit x) (f g : F) (h : f x = g x) : f x⁻¹ = g x⁻¹ := left_inv_eq_right_inv (map_mul_eq_one f hx.inv_mul_cancel) (h.symm ▸ map_mul_eq_one g (hx.mul_inv_cancel)) /-- If two homomorphism from a group to a monoid are equal at `x`, then they are equal at `x⁻¹`. -/ @[to_additive "If two homomorphism from an additive group to an additive monoid are equal at `x`, then they are equal at `-x`."] theorem eq_on_inv {F G M} [Group G] [Monoid M] [FunLike F G M] [MonoidHomClass F G M] (f g : F) {x : G} (h : f x = g x) : f x⁻¹ = g x⁻¹ := (Group.isUnit x).eq_on_inv f g h end MonoidHomClass namespace Units variable {α : Type*} {M : Type u} {N : Type v} {P : Type w} [Monoid M] [Monoid N] [Monoid P] /-- The group homomorphism on units induced by a `MonoidHom`. -/ @[to_additive "The additive homomorphism on `AddUnit`s induced by an `AddMonoidHom`."] def map (f : M →* N) : Mˣ →* Nˣ := MonoidHom.mk' (fun u => ⟨f u.val, f u.inv, by rw [← f.map_mul, u.val_inv, f.map_one], by rw [← f.map_mul, u.inv_val, f.map_one]⟩) fun x y => ext (f.map_mul x y) @[to_additive (attr := simp)] theorem coe_map (f : M →* N) (x : Mˣ) : ↑(map f x) = f x := rfl @[to_additive (attr := simp)] theorem coe_map_inv (f : M →* N) (u : Mˣ) : ↑(map f u)⁻¹ = f ↑u⁻¹ := rfl @[to_additive (attr := simp)] theorem map_comp (f : M →* N) (g : N →* P) : map (g.comp f) = (map g).comp (map f) := rfl @[to_additive] lemma map_injective {f : M →* N} (hf : Function.Injective f) : Function.Injective (map f) := fun _ _ e => ext (hf (congr_arg val e)) variable (M) @[to_additive (attr := simp)] theorem map_id : map (MonoidHom.id M) = MonoidHom.id Mˣ := by ext; rfl /-- Coercion `Mˣ → M` as a monoid homomorphism. -/ @[to_additive "Coercion `AddUnits M → M` as an AddMonoid homomorphism."] def coeHom : Mˣ →* M where toFun := Units.val; map_one' := val_one; map_mul' := val_mul variable {M} @[to_additive (attr := simp)] theorem coeHom_apply (x : Mˣ) : coeHom M x = ↑x := rfl section DivisionMonoid variable [DivisionMonoid α] @[to_additive (attr := simp, norm_cast)] theorem val_zpow_eq_zpow_val : ∀ (u : αˣ) (n : ℤ), ((u ^ n : αˣ) : α) = (u : α) ^ n := (Units.coeHom α).map_zpow @[to_additive (attr := simp)] theorem _root_.map_units_inv {F : Type*} [FunLike F M α] [MonoidHomClass F M α] (f : F) (u : Units M) : f ↑u⁻¹ = (f u)⁻¹ := ((f : M →* α).comp (Units.coeHom M)).map_inv u end DivisionMonoid /-- If a map `g : M → Nˣ` agrees with a homomorphism `f : M →* N`, then this map is a monoid homomorphism too. -/ @[to_additive "If a map `g : M → AddUnits N` agrees with a homomorphism `f : M →+ N`, then this map is an AddMonoid homomorphism too."] def liftRight (f : M →* N) (g : M → Nˣ) (h : ∀ x, ↑(g x) = f x) : M →* Nˣ where toFun := g map_one' := by ext; rw [h 1]; exact f.map_one map_mul' x y := Units.ext <| by simp only [h, val_mul, f.map_mul] @[to_additive (attr := simp)] theorem coe_liftRight {f : M →* N} {g : M → Nˣ} (h : ∀ x, ↑(g x) = f x) (x) : (liftRight f g h x : N) = f x := h x @[to_additive (attr := simp)] theorem mul_liftRight_inv {f : M →* N} {g : M → Nˣ} (h : ∀ x, ↑(g x) = f x) (x) : f x * ↑(liftRight f g h x)⁻¹ = 1 := by rw [Units.mul_inv_eq_iff_eq_mul, one_mul, coe_liftRight] @[to_additive (attr := simp)] theorem liftRight_inv_mul {f : M →* N} {g : M → Nˣ} (h : ∀ x, ↑(g x) = f x) (x) : ↑(liftRight f g h x)⁻¹ * f x = 1 := by rw [Units.inv_mul_eq_iff_eq_mul, mul_one, coe_liftRight] end Units namespace MonoidHom /-- If `f` is a homomorphism from a group `G` to a monoid `M`, then its image lies in the units of `M`, and `f.toHomUnits` is the corresponding monoid homomorphism from `G` to `Mˣ`. -/ @[to_additive "If `f` is a homomorphism from an additive group `G` to an additive monoid `M`, then its image lies in the `AddUnits` of `M`, and `f.toHomUnits` is the corresponding homomorphism from `G` to `AddUnits M`."] def toHomUnits {G M : Type*} [Group G] [Monoid M] (f : G →* M) : G →* Mˣ := Units.liftRight f (fun g => ⟨f g, f g⁻¹, map_mul_eq_one f (mul_inv_self _), map_mul_eq_one f (inv_mul_self _)⟩) fun _ => rfl @[to_additive (attr := simp)] theorem coe_toHomUnits {G M : Type*} [Group G] [Monoid M] (f : G →* M) (g : G) : (f.toHomUnits g : M) = f g := rfl end MonoidHom namespace IsUnit variable {F G α M N : Type*} [FunLike F M N] [FunLike G N M] section Monoid variable [Monoid M] [Monoid N] @[to_additive] theorem map [MonoidHomClass F M N] (f : F) {x : M} (h : IsUnit x) : IsUnit (f x) := by rcases h with ⟨y, rfl⟩; exact (Units.map (f : M →* N) y).isUnit @[to_additive] theorem of_leftInverse [MonoidHomClass G N M] {f : F} {x : M} (g : G) (hfg : Function.LeftInverse g f) (h : IsUnit (f x)) : IsUnit x := by simpa only [hfg x] using h.map g @[to_additive] theorem _root_.isUnit_map_of_leftInverse [MonoidHomClass F M N] [MonoidHomClass G N M] {f : F} {x : M} (g : G) (hfg : Function.LeftInverse g f) : IsUnit (f x) ↔ IsUnit x := ⟨of_leftInverse g hfg, map _⟩ /-- If a homomorphism `f : M →* N` sends each element to an `IsUnit`, then it can be lifted to `f : M →* Nˣ`. See also `Units.liftRight` for a computable version. -/ @[to_additive "If a homomorphism `f : M →+ N` sends each element to an `IsAddUnit`, then it can be lifted to `f : M →+ AddUnits N`. See also `AddUnits.liftRight` for a computable version."] noncomputable def liftRight (f : M →* N) (hf : ∀ x, IsUnit (f x)) : M →* Nˣ := (Units.liftRight f fun x => (hf x).unit) fun _ => rfl @[to_additive] theorem coe_liftRight (f : M →* N) (hf : ∀ x, IsUnit (f x)) (x) : (IsUnit.liftRight f hf x : N) = f x := rfl @[to_additive (attr := simp)] theorem mul_liftRight_inv (f : M →* N) (h : ∀ x, IsUnit (f x)) (x) : f x * ↑(IsUnit.liftRight f h x)⁻¹ = 1 := Units.mul_liftRight_inv (by intro; rfl) x @[to_additive (attr := simp)] theorem liftRight_inv_mul (f : M →* N) (h : ∀ x, IsUnit (f x)) (x) : ↑(IsUnit.liftRight f h x)⁻¹ * f x = 1 := Units.liftRight_inv_mul (by intro; rfl) x end Monoid end IsUnit
Algebra\Group\WithOne\Basic.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johan Commelin -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.WithOne.Defs /-! # More operations on `WithOne` and `WithZero` This file defines various bundled morphisms on `WithOne` and `WithZero` that were not available in `Algebra/Group/WithOne/Defs`. ## Main definitions * `WithOne.lift`, `WithZero.lift` * `WithOne.map`, `WithZero.map` -/ assert_not_exists MonoidWithZero assert_not_exists DenselyOrdered universe u v w variable {α : Type u} {β : Type v} {γ : Type w} namespace WithOne @[to_additive] instance involutiveInv [InvolutiveInv α] : InvolutiveInv (WithOne α) := { WithOne.inv with inv_inv := fun a => (Option.map_map _ _ _).trans <| by simp_rw [inv_comp_inv, Option.map_id, id] } section -- Porting note: the workaround described below doesn't seem to be a problem even with -- semireducible transparency -- workaround: we make `WithOne`/`WithZero` irreducible for this definition, otherwise `simps` -- will unfold it in the statement of the lemma it generates. /-- `WithOne.coe` as a bundled morphism -/ @[to_additive (attr := simps apply) "`WithZero.coe` as a bundled morphism"] def coeMulHom [Mul α] : α →ₙ* WithOne α where toFun := coe map_mul' _ _ := rfl end section lift -- Porting note: these were never marked with `irreducible` when they were defined. -- attribute [local semireducible] WithOne WithZero variable [Mul α] [MulOneClass β] /-- Lift a semigroup homomorphism `f` to a bundled monoid homomorphism. -/ @[to_additive "Lift an add semigroup homomorphism `f` to a bundled add monoid homomorphism."] def lift : (α →ₙ* β) ≃ (WithOne α →* β) where toFun f := { toFun := fun x => Option.casesOn x 1 f, map_one' := rfl, map_mul' := fun x y => WithOne.cases_on x (by rw [one_mul]; exact (one_mul _).symm) (fun x => WithOne.cases_on y (by rw [mul_one]; exact (mul_one _).symm) (fun y => f.map_mul x y)) } invFun F := F.toMulHom.comp coeMulHom left_inv f := MulHom.ext fun x => rfl right_inv F := MonoidHom.ext fun x => WithOne.cases_on x F.map_one.symm (fun x => rfl) -- Porting note: the above proofs were broken because they were parenthesized wrong by mathport? variable (f : α →ₙ* β) @[to_additive (attr := simp)] theorem lift_coe (x : α) : lift f x = f x := rfl -- Porting note (#11119): removed `simp` attribute to appease `simpNF` linter. @[to_additive] theorem lift_one : lift f 1 = 1 := rfl @[to_additive] theorem lift_unique (f : WithOne α →* β) : f = lift (f.toMulHom.comp coeMulHom) := (lift.apply_symm_apply f).symm end lift section Map variable [Mul α] [Mul β] [Mul γ] /-- Given a multiplicative map from `α → β` returns a monoid homomorphism from `WithOne α` to `WithOne β` -/ @[to_additive "Given an additive map from `α → β` returns an add monoid homomorphism from `WithZero α` to `WithZero β`"] def map (f : α →ₙ* β) : WithOne α →* WithOne β := lift (coeMulHom.comp f) @[to_additive (attr := simp)] theorem map_coe (f : α →ₙ* β) (a : α) : map f (a : WithOne α) = f a := rfl @[to_additive (attr := simp)] theorem map_id : map (MulHom.id α) = MonoidHom.id (WithOne α) := by ext x induction x <;> rfl @[to_additive] theorem map_map (f : α →ₙ* β) (g : β →ₙ* γ) (x) : map g (map f x) = map (g.comp f) x := by induction x <;> rfl @[to_additive (attr := simp)] theorem map_comp (f : α →ₙ* β) (g : β →ₙ* γ) : map (g.comp f) = (map g).comp (map f) := MonoidHom.ext fun x => (map_map f g x).symm -- Porting note: this used to have `@[simps apply]` but it was generating lemmas which -- weren't in simp normal form. /-- A version of `Equiv.optionCongr` for `WithOne`. -/ @[to_additive (attr := simps apply) "A version of `Equiv.optionCongr` for `WithZero`."] def _root_.MulEquiv.withOneCongr (e : α ≃* β) : WithOne α ≃* WithOne β := { map e.toMulHom with toFun := map e.toMulHom, invFun := map e.symm.toMulHom, left_inv := (by induction · <;> simp) right_inv := (by induction · <;> simp) } -- Porting note: for this declaration and the two below I added the `to_additive` attribute because -- it seemed to be missing from mathlib3 @[to_additive (attr := simp)] theorem _root_.MulEquiv.withOneCongr_refl : (MulEquiv.refl α).withOneCongr = MulEquiv.refl _ := MulEquiv.toMonoidHom_injective map_id @[to_additive (attr := simp)] theorem _root_.MulEquiv.withOneCongr_symm (e : α ≃* β) : e.withOneCongr.symm = e.symm.withOneCongr := rfl @[to_additive (attr := simp)] theorem _root_.MulEquiv.withOneCongr_trans (e₁ : α ≃* β) (e₂ : β ≃* γ) : e₁.withOneCongr.trans e₂.withOneCongr = (e₁.trans e₂).withOneCongr := MulEquiv.toMonoidHom_injective (map_comp _ _).symm end Map end WithOne
Algebra\Group\WithOne\Defs.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johan Commelin -/ import Mathlib.Algebra.Group.Defs import Mathlib.Data.Option.Defs import Mathlib.Logic.Nontrivial.Basic import Mathlib.Tactic.Common /-! # Adjoining a zero/one to semigroups and related algebraic structures This file contains different results about adjoining an element to an algebraic structure which then behaves like a zero or a one. An example is adjoining a one to a semigroup to obtain a monoid. That this provides an example of an adjunction is proved in `Mathlib.Algebra.Category.MonCat.Adjunctions`. Another result says that adjoining to a group an element `zero` gives a `GroupWithZero`. For more information about these structures (which are not that standard in informal mathematics, see `Mathlib.Algebra.GroupWithZero.Basic`) ## Porting notes In Lean 3, we use `id` here and there to get correct types of proofs. This is required because `WithOne` and `WithZero` are marked as `irreducible` at the end of `Mathlib.Algebra.Group.WithOne.Defs`, so proofs that use `Option α` instead of `WithOne α` no longer typecheck. In Lean 4, both types are plain `def`s, so we don't need these `id`s. ## TODO `WithOne.coe_mul` and `WithZero.coe_mul` have inconsistent use of implicit parameters -/ -- Check that we haven't needed to import all the basic lemmas about groups, -- by asserting a random sample don't exist here: assert_not_exists inv_involutive assert_not_exists div_right_inj assert_not_exists pow_ite assert_not_exists MonoidWithZero assert_not_exists DenselyOrdered universe u v w variable {α : Type u} {β : Type v} {γ : Type w} /-- Add an extra element `1` to a type -/ @[to_additive "Add an extra element `0` to a type"] def WithOne (α) := Option α namespace WithOne instance [Repr α] : Repr (WithZero α) := ⟨fun o _ => match o with | none => "0" | some a => "↑" ++ repr a⟩ @[to_additive] instance [Repr α] : Repr (WithOne α) := ⟨fun o _ => match o with | none => "1" | some a => "↑" ++ repr a⟩ @[to_additive] instance monad : Monad WithOne := instMonadOption @[to_additive] instance one : One (WithOne α) := ⟨none⟩ @[to_additive] instance mul [Mul α] : Mul (WithOne α) := ⟨Option.liftOrGet (· * ·)⟩ @[to_additive] instance inv [Inv α] : Inv (WithOne α) := ⟨fun a => Option.map Inv.inv a⟩ @[to_additive] instance invOneClass [Inv α] : InvOneClass (WithOne α) := { WithOne.one, WithOne.inv with inv_one := rfl } @[to_additive] instance inhabited : Inhabited (WithOne α) := ⟨1⟩ @[to_additive] instance nontrivial [Nonempty α] : Nontrivial (WithOne α) := Option.nontrivial -- Porting note: this new declaration is here to make `((a : α): WithOne α)` have type `WithOne α`; -- otherwise the coercion kicks in and it becomes `Option.some a : WithOne α` which -- becomes `Option.some a : Option α`. /-- The canonical map from `α` into `WithOne α` -/ @[to_additive (attr := coe) "The canonical map from `α` into `WithZero α`"] def coe : α → WithOne α := Option.some @[to_additive] instance coeTC : CoeTC α (WithOne α) := ⟨coe⟩ /-- Recursor for `WithOne` using the preferred forms `1` and `↑a`. -/ @[to_additive (attr := elab_as_elim, induction_eliminator, cases_eliminator) "Recursor for `WithZero` using the preferred forms `0` and `↑a`."] def recOneCoe {C : WithOne α → Sort*} (h₁ : C 1) (h₂ : ∀ a : α, C a) : ∀ n : WithOne α, C n | Option.none => h₁ | Option.some x => h₂ x /-- Deconstruct an `x : WithOne α` to the underlying value in `α`, given a proof that `x ≠ 1`. -/ @[to_additive unzero "Deconstruct an `x : WithZero α` to the underlying value in `α`, given a proof that `x ≠ 0`."] def unone : ∀ {x : WithOne α}, x ≠ 1 → α | (x : α), _ => x @[to_additive (attr := simp) unzero_coe] theorem unone_coe {x : α} (hx : (x : WithOne α) ≠ 1) : unone hx = x := rfl @[to_additive (attr := simp) coe_unzero] lemma coe_unone : ∀ {x : WithOne α} (hx : x ≠ 1), unone hx = x | (x : α), _ => rfl -- Porting note: in Lean 4 the `some_eq_coe` lemmas present in the lean 3 version -- of this file are syntactic tautologies @[to_additive (attr := simp)] theorem coe_ne_one {a : α} : (a : WithOne α) ≠ (1 : WithOne α) := Option.some_ne_none a @[to_additive (attr := simp)] theorem one_ne_coe {a : α} : (1 : WithOne α) ≠ a := coe_ne_one.symm @[to_additive] theorem ne_one_iff_exists {x : WithOne α} : x ≠ 1 ↔ ∃ a : α, ↑a = x := Option.ne_none_iff_exists @[to_additive] instance canLift : CanLift (WithOne α) α (↑) fun a => a ≠ 1 where prf _ := ne_one_iff_exists.1 @[to_additive (attr := simp, norm_cast)] theorem coe_inj {a b : α} : (a : WithOne α) = b ↔ a = b := Option.some_inj @[to_additive (attr := elab_as_elim)] protected theorem cases_on {P : WithOne α → Prop} : ∀ x : WithOne α, P 1 → (∀ a : α, P a) → P x := Option.casesOn @[to_additive] instance mulOneClass [Mul α] : MulOneClass (WithOne α) where mul := (· * ·) one := 1 one_mul := (Option.liftOrGet_isId _).left_id mul_one := (Option.liftOrGet_isId _).right_id @[to_additive (attr := simp, norm_cast)] lemma coe_mul [Mul α] (a b : α) : (↑(a * b) : WithOne α) = a * b := rfl @[to_additive] instance monoid [Semigroup α] : Monoid (WithOne α) where __ := mulOneClass mul_assoc a b c := match a, b, c with | 1, b, c => by simp | (a : α), 1, c => by simp | (a : α), (b : α), 1 => by simp | (a : α), (b : α), (c : α) => by simp_rw [← coe_mul, mul_assoc] @[to_additive] instance commMonoid [CommSemigroup α] : CommMonoid (WithOne α) where mul_comm := fun a b => match a, b with | (a : α), (b : α) => congr_arg some (mul_comm a b) | (_ : α), 1 => rfl | 1, (_ : α) => rfl | 1, 1 => rfl @[to_additive (attr := simp, norm_cast)] theorem coe_inv [Inv α] (a : α) : ((a⁻¹ : α) : WithOne α) = (a : WithOne α)⁻¹ := rfl end WithOne
Algebra\GroupPower\IterateHom.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Action.Opposite import Mathlib.Algebra.Group.Int import Mathlib.Algebra.Group.Nat import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.Common /-! # Iterates of monoid homomorphisms Iterate of a monoid homomorphism is a monoid homomorphism but it has a wrong type, so Lean can't apply lemmas like `MonoidHom.map_one` to `f^[n] 1`. Though it is possible to define a monoid structure on the endomorphisms, quite often we do not want to convert from `M →* M` to `Monoid.End M` and from `f^[n]` to `f^n` just to apply a simple lemma. So, we restate standard `map_*` lemmas under names `iterate_map_*`. We also prove formulas for iterates of add/mul left/right. ## Tags homomorphism, iterate -/ assert_not_exists MonoidWithZero assert_not_exists DenselyOrdered open Function variable {M : Type*} {N : Type*} {G : Type*} {H : Type*} /-- An auxiliary lemma that can be used to prove `⇑(f ^ n) = ⇑f^[n]`. -/ theorem hom_coe_pow {F : Type*} [Monoid F] (c : F → M → M) (h1 : c 1 = id) (hmul : ∀ f g, c (f * g) = c f ∘ c g) (f : F) : ∀ n, c (f ^ n) = (c f)^[n] | 0 => by rw [pow_zero, h1] rfl | n + 1 => by rw [pow_succ, iterate_succ, hmul, hom_coe_pow c h1 hmul f n] @[to_additive (attr := simp)] theorem iterate_map_mul {M F : Type*} [Mul M] [FunLike F M M] [MulHomClass F M M] (f : F) (n : ℕ) (x y : M) : f^[n] (x * y) = f^[n] x * f^[n] y := Function.Semiconj₂.iterate (map_mul f) n x y @[to_additive (attr := simp)] theorem iterate_map_one {M F : Type*} [One M] [FunLike F M M] [OneHomClass F M M] (f : F) (n : ℕ) : f^[n] 1 = 1 := iterate_fixed (map_one f) n @[to_additive (attr := simp)] theorem iterate_map_inv {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M] (f : F) (n : ℕ) (x : M) : f^[n] x⁻¹ = (f^[n] x)⁻¹ := Commute.iterate_left (map_inv f) n x @[to_additive (attr := simp)] theorem iterate_map_div {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M] (f : F) (n : ℕ) (x y : M) : f^[n] (x / y) = f^[n] x / f^[n] y := Semiconj₂.iterate (map_div f) n x y @[to_additive (attr := simp)] theorem iterate_map_pow {M F : Type*} [Monoid M] [FunLike F M M] [MonoidHomClass F M M] (f : F) (n : ℕ) (x : M) (k : ℕ) : f^[n] (x ^ k) = f^[n] x ^ k := Commute.iterate_left (map_pow f · k) n x @[to_additive (attr := simp)] theorem iterate_map_zpow {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M] (f : F) (n : ℕ) (x : M) (k : ℤ) : f^[n] (x ^ k) = f^[n] x ^ k := Commute.iterate_left (map_zpow f · k) n x --what should be the namespace for this section? section Monoid variable [Monoid G] (a : G) (n : ℕ) @[to_additive (attr := simp)] theorem smul_iterate [MulAction G H] : (a • · : H → H)^[n] = (a ^ n • ·) := funext fun b => Nat.recOn n (by rw [iterate_zero, id, pow_zero, one_smul]) fun n ih => by rw [iterate_succ', comp_apply, ih, pow_succ', mul_smul] @[to_additive] lemma smul_iterate_apply [MulAction G H] {b : H} : (a • ·)^[n] b = a ^ n • b := by rw [smul_iterate] @[to_additive (attr := simp)] theorem mul_left_iterate : (a * ·)^[n] = (a ^ n * ·) := smul_iterate a n @[to_additive (attr := simp)] theorem mul_right_iterate : (· * a)^[n] = (· * a ^ n) := smul_iterate (MulOpposite.op a) n @[to_additive] theorem mul_right_iterate_apply_one : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive (attr := simp)] theorem pow_iterate (n : ℕ) (j : ℕ) : (fun x : G => x ^ n)^[j] = fun x : G => x ^ n ^ j := letI : MulAction ℕ G := { smul := fun n g => g ^ n one_smul := pow_one mul_smul := fun m n g => pow_mul' g m n } smul_iterate n j end Monoid section Group variable [Group G] @[to_additive (attr := simp)] theorem zpow_iterate (n : ℤ) (j : ℕ) : (fun x : G => x ^ n)^[j] = fun x => x ^ n ^ j := letI : MulAction ℤ G := { smul := fun n g => g ^ n one_smul := zpow_one mul_smul := fun m n g => zpow_mul' g m n } smul_iterate n j end Group section Semigroup variable [Semigroup G] {a b c : G} -- Porting note(#12129): additional beta reduction needed -- see also https://leanprover.zulipchat.com/#narrow/stream/ -- 287929-mathlib4/topic/dsimp.20before.20rw/near/317063489 @[to_additive] theorem SemiconjBy.function_semiconj_mul_left (h : SemiconjBy a b c) : Function.Semiconj (a * ·) (b * ·) (c * ·) := fun j => by beta_reduce; rw [← mul_assoc, h.eq, mul_assoc] @[to_additive] theorem Commute.function_commute_mul_left (h : Commute a b) : Function.Commute (a * ·) (b * ·) := SemiconjBy.function_semiconj_mul_left h @[to_additive] theorem SemiconjBy.function_semiconj_mul_right_swap (h : SemiconjBy a b c) : Function.Semiconj (· * a) (· * c) (· * b) := fun j => by simp_rw [mul_assoc, ← h.eq] @[to_additive] theorem Commute.function_commute_mul_right (h : Commute a b) : Function.Commute (· * a) (· * b) := SemiconjBy.function_semiconj_mul_right_swap h end Semigroup
Algebra\GroupWithZero\Basic.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.GroupWithZero.NeZero import Mathlib.Logic.Unique /-! # Groups with an adjoined zero element This file describes structures that are not usually studied on their own right in mathematics, namely a special sort of monoid: apart from a distinguished “zero element” they form a group, or in other words, they are groups with an adjoined zero element. Examples are: * division rings; * the value monoid of a multiplicative valuation; * in particular, the non-negative real numbers. ## Main definitions Various lemmas about `GroupWithZero` and `CommGroupWithZero`. To reduce import dependencies, the type-classes themselves are in `Algebra.GroupWithZero.Defs`. ## Implementation details As is usual in mathlib, we extend the inverse function to the zero element, and require `0⁻¹ = 0`. -/ assert_not_exists DenselyOrdered open Function variable {α M₀ G₀ M₀' G₀' F F' : Type*} section section MulZeroClass variable [MulZeroClass M₀] {a b : M₀} theorem left_ne_zero_of_mul : a * b ≠ 0 → a ≠ 0 := mt fun h => mul_eq_zero_of_left h b theorem right_ne_zero_of_mul : a * b ≠ 0 → b ≠ 0 := mt (mul_eq_zero_of_right a) theorem ne_zero_and_ne_zero_of_mul (h : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 := ⟨left_ne_zero_of_mul h, right_ne_zero_of_mul h⟩ theorem mul_eq_zero_of_ne_zero_imp_eq_zero {a b : M₀} (h : a ≠ 0 → b = 0) : a * b = 0 := by have : Decidable (a = 0) := Classical.propDecidable (a = 0) exact if ha : a = 0 then by rw [ha, zero_mul] else by rw [h ha, mul_zero] /-- To match `one_mul_eq_id`. -/ theorem zero_mul_eq_const : ((0 : M₀) * ·) = Function.const _ 0 := funext zero_mul /-- To match `mul_one_eq_id`. -/ theorem mul_zero_eq_const : (· * (0 : M₀)) = Function.const _ 0 := funext mul_zero end MulZeroClass section Mul variable [Mul M₀] [Zero M₀] [NoZeroDivisors M₀] {a b : M₀} theorem eq_zero_of_mul_self_eq_zero (h : a * a = 0) : a = 0 := (eq_zero_or_eq_zero_of_mul_eq_zero h).elim id id @[field_simps] theorem mul_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a * b ≠ 0 := mt eq_zero_or_eq_zero_of_mul_eq_zero <| not_or.mpr ⟨ha, hb⟩ end Mul namespace NeZero instance mul [Zero M₀] [Mul M₀] [NoZeroDivisors M₀] {x y : M₀} [NeZero x] [NeZero y] : NeZero (x * y) := ⟨mul_ne_zero out out⟩ end NeZero end section variable [MulZeroOneClass M₀] /-- In a monoid with zero, if zero equals one, then zero is the only element. -/ theorem eq_zero_of_zero_eq_one (h : (0 : M₀) = 1) (a : M₀) : a = 0 := by rw [← mul_one a, ← h, mul_zero] /-- In a monoid with zero, if zero equals one, then zero is the unique element. Somewhat arbitrarily, we define the default element to be `0`. All other elements will be provably equal to it, but not necessarily definitionally equal. -/ def uniqueOfZeroEqOne (h : (0 : M₀) = 1) : Unique M₀ where default := 0 uniq := eq_zero_of_zero_eq_one h /-- In a monoid with zero, zero equals one if and only if all elements of that semiring are equal. -/ theorem subsingleton_iff_zero_eq_one : (0 : M₀) = 1 ↔ Subsingleton M₀ := ⟨fun h => haveI := uniqueOfZeroEqOne h; inferInstance, fun h => @Subsingleton.elim _ h _ _⟩ alias ⟨subsingleton_of_zero_eq_one, _⟩ := subsingleton_iff_zero_eq_one theorem eq_of_zero_eq_one (h : (0 : M₀) = 1) (a b : M₀) : a = b := @Subsingleton.elim _ (subsingleton_of_zero_eq_one h) a b /-- In a monoid with zero, either zero and one are nonequal, or zero is the only element. -/ theorem zero_ne_one_or_forall_eq_0 : (0 : M₀) ≠ 1 ∨ ∀ a : M₀, a = 0 := not_or_of_imp eq_zero_of_zero_eq_one end section variable [MulZeroOneClass M₀] [Nontrivial M₀] {a b : M₀} theorem left_ne_zero_of_mul_eq_one (h : a * b = 1) : a ≠ 0 := left_ne_zero_of_mul <| ne_zero_of_eq_one h theorem right_ne_zero_of_mul_eq_one (h : a * b = 1) : b ≠ 0 := right_ne_zero_of_mul <| ne_zero_of_eq_one h end section MonoidWithZero variable [MonoidWithZero M₀] {a : M₀} {m n : ℕ} @[simp] lemma zero_pow : ∀ {n : ℕ}, n ≠ 0 → (0 : M₀) ^ n = 0 | n + 1, _ => by rw [pow_succ, mul_zero] lemma zero_pow_eq (n : ℕ) : (0 : M₀) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, pow_zero] · rw [zero_pow h] lemma pow_eq_zero_of_le : ∀ {m n} (hmn : m ≤ n) (ha : a ^ m = 0), a ^ n = 0 | _, _, Nat.le.refl, ha => ha | _, _, Nat.le.step hmn, ha => by rw [pow_succ, pow_eq_zero_of_le hmn ha, zero_mul] lemma ne_zero_pow (hn : n ≠ 0) (ha : a ^ n ≠ 0) : a ≠ 0 := by rintro rfl; exact ha $ zero_pow hn @[simp] lemma zero_pow_eq_zero [Nontrivial M₀] : (0 : M₀) ^ n = 0 ↔ n ≠ 0 := ⟨by rintro h rfl; simp at h, zero_pow⟩ variable [NoZeroDivisors M₀] lemma pow_eq_zero : ∀ {n}, a ^ n = 0 → a = 0 | 0, ha => by simpa using congr_arg (a * ·) ha | n + 1, ha => by rw [pow_succ, mul_eq_zero] at ha; exact ha.elim pow_eq_zero id @[simp] lemma pow_eq_zero_iff (hn : n ≠ 0) : a ^ n = 0 ↔ a = 0 := ⟨pow_eq_zero, by rintro rfl; exact zero_pow hn⟩ lemma pow_ne_zero_iff (hn : n ≠ 0) : a ^ n ≠ 0 ↔ a ≠ 0 := (pow_eq_zero_iff hn).not @[field_simps] lemma pow_ne_zero (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 := mt pow_eq_zero h instance NeZero.pow [NeZero a] : NeZero (a ^ n) := ⟨pow_ne_zero n NeZero.out⟩ lemma sq_eq_zero_iff : a ^ 2 = 0 ↔ a = 0 := pow_eq_zero_iff two_ne_zero @[simp] lemma pow_eq_zero_iff' [Nontrivial M₀] : a ^ n = 0 ↔ a = 0 ∧ n ≠ 0 := by obtain rfl | hn := eq_or_ne n 0 <;> simp [*] end MonoidWithZero section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] {a b c : M₀} -- see Note [lower instance priority] instance (priority := 10) CancelMonoidWithZero.to_noZeroDivisors : NoZeroDivisors M₀ := ⟨fun ab0 => or_iff_not_imp_left.mpr fun ha => mul_left_cancel₀ ha <| ab0.trans (mul_zero _).symm⟩ @[simp] theorem mul_eq_mul_right_iff : a * c = b * c ↔ a = b ∨ c = 0 := by by_cases hc : c = 0 <;> [simp only [hc, mul_zero, or_true]; simp [mul_left_inj', hc]] @[simp] theorem mul_eq_mul_left_iff : a * b = a * c ↔ b = c ∨ a = 0 := by by_cases ha : a = 0 <;> [simp only [ha, zero_mul, or_true]; simp [mul_right_inj', ha]] theorem mul_right_eq_self₀ : a * b = a ↔ b = 1 ∨ a = 0 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 ∨ a = 0 := mul_eq_mul_left_iff theorem mul_left_eq_self₀ : a * b = b ↔ a = 1 ∨ b = 0 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 ∨ b = 0 := mul_eq_mul_right_iff @[simp] theorem mul_eq_left₀ (ha : a ≠ 0) : a * b = a ↔ b = 1 := by rw [Iff.comm, ← mul_right_inj' ha, mul_one] @[simp] theorem mul_eq_right₀ (hb : b ≠ 0) : a * b = b ↔ a = 1 := by rw [Iff.comm, ← mul_left_inj' hb, one_mul] @[simp] theorem left_eq_mul₀ (ha : a ≠ 0) : a = a * b ↔ b = 1 := by rw [eq_comm, mul_eq_left₀ ha] @[simp] theorem right_eq_mul₀ (hb : b ≠ 0) : b = a * b ↔ a = 1 := by rw [eq_comm, mul_eq_right₀ hb] /-- An element of a `CancelMonoidWithZero` fixed by right multiplication by an element other than one must be zero. -/ theorem eq_zero_of_mul_eq_self_right (h₁ : b ≠ 1) (h₂ : a * b = a) : a = 0 := Classical.byContradiction fun ha => h₁ <| mul_left_cancel₀ ha <| h₂.symm ▸ (mul_one a).symm /-- An element of a `CancelMonoidWithZero` fixed by left multiplication by an element other than one must be zero. -/ theorem eq_zero_of_mul_eq_self_left (h₁ : b ≠ 1) (h₂ : b * a = a) : a = 0 := Classical.byContradiction fun ha => h₁ <| mul_right_cancel₀ ha <| h₂.symm ▸ (one_mul a).symm end CancelMonoidWithZero section GroupWithZero variable [GroupWithZero G₀] {a b c g h x : G₀} theorem GroupWithZero.mul_left_injective (h : x ≠ 0) : Function.Injective fun y => x * y := fun y y' w => by simpa only [← mul_assoc, inv_mul_cancel h, one_mul] using congr_arg (fun y => x⁻¹ * y) w theorem GroupWithZero.mul_right_injective (h : x ≠ 0) : Function.Injective fun y => y * x := fun y y' w => by simpa only [mul_assoc, mul_inv_cancel h, mul_one] using congr_arg (fun y => y * x⁻¹) w @[simp] theorem inv_mul_cancel_right₀ (h : b ≠ 0) (a : G₀) : a * b⁻¹ * b = a := calc a * b⁻¹ * b = a * (b⁻¹ * b) := mul_assoc _ _ _ _ = a := by simp [h] @[simp] theorem inv_mul_cancel_left₀ (h : a ≠ 0) (b : G₀) : a⁻¹ * (a * b) = b := calc a⁻¹ * (a * b) = a⁻¹ * a * b := (mul_assoc _ _ _).symm _ = b := by simp [h] private theorem inv_eq_of_mul (h : a * b = 1) : a⁻¹ = b := by rw [← inv_mul_cancel_left₀ (left_ne_zero_of_mul_eq_one h) b, h, mul_one] -- See note [lower instance priority] instance (priority := 100) GroupWithZero.toDivisionMonoid : DivisionMonoid G₀ := { ‹GroupWithZero G₀› with inv := Inv.inv, inv_inv := fun a => by by_cases h : a = 0 · simp [h] · exact left_inv_eq_right_inv (inv_mul_cancel <| inv_ne_zero h) (inv_mul_cancel h) , mul_inv_rev := fun a b => by by_cases ha : a = 0 · simp [ha] by_cases hb : b = 0 · simp [hb] apply inv_eq_of_mul simp [mul_assoc, ha, hb], inv_eq_of_mul := fun _ _ => inv_eq_of_mul } -- see Note [lower instance priority] instance (priority := 10) GroupWithZero.toCancelMonoidWithZero : CancelMonoidWithZero G₀ := { (‹_› : GroupWithZero G₀) with mul_left_cancel_of_ne_zero := @fun x y z hx h => by rw [← inv_mul_cancel_left₀ hx y, h, inv_mul_cancel_left₀ hx z], mul_right_cancel_of_ne_zero := @fun x y z hy h => by rw [← mul_inv_cancel_right₀ hy x, h, mul_inv_cancel_right₀ hy z] } end GroupWithZero section GroupWithZero variable [GroupWithZero G₀] {a b c : G₀} @[simp] theorem zero_div (a : G₀) : 0 / a = 0 := by rw [div_eq_mul_inv, zero_mul] @[simp] theorem div_zero (a : G₀) : a / 0 = 0 := by rw [div_eq_mul_inv, inv_zero, mul_zero] /-- Multiplying `a` by itself and then by its inverse results in `a` (whether or not `a` is zero). -/ @[simp] theorem mul_self_mul_inv (a : G₀) : a * a * a⁻¹ = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [mul_assoc, mul_inv_cancel h, mul_one] /-- Multiplying `a` by its inverse and then by itself results in `a` (whether or not `a` is zero). -/ @[simp] theorem mul_inv_mul_self (a : G₀) : a * a⁻¹ * a = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [mul_inv_cancel h, one_mul] /-- Multiplying `a⁻¹` by `a` twice results in `a` (whether or not `a` is zero). -/ @[simp] theorem inv_mul_mul_self (a : G₀) : a⁻¹ * a * a = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [inv_mul_cancel h, one_mul] /-- Multiplying `a` by itself and then dividing by itself results in `a`, whether or not `a` is zero. -/ @[simp] theorem mul_self_div_self (a : G₀) : a * a / a = a := by rw [div_eq_mul_inv, mul_self_mul_inv a] /-- Dividing `a` by itself and then multiplying by itself results in `a`, whether or not `a` is zero. -/ @[simp] theorem div_self_mul_self (a : G₀) : a / a * a = a := by rw [div_eq_mul_inv, mul_inv_mul_self a] attribute [local simp] div_eq_mul_inv mul_comm mul_assoc mul_left_comm @[simp] theorem div_self_mul_self' (a : G₀) : a / (a * a) = a⁻¹ := calc a / (a * a) = a⁻¹⁻¹ * a⁻¹ * a⁻¹ := by simp [mul_inv_rev] _ = a⁻¹ := inv_mul_mul_self _ theorem one_div_ne_zero {a : G₀} (h : a ≠ 0) : 1 / a ≠ 0 := by simpa only [one_div] using inv_ne_zero h @[simp] theorem inv_eq_zero {a : G₀} : a⁻¹ = 0 ↔ a = 0 := by rw [inv_eq_iff_eq_inv, inv_zero] @[simp] theorem zero_eq_inv {a : G₀} : 0 = a⁻¹ ↔ 0 = a := eq_comm.trans <| inv_eq_zero.trans eq_comm /-- Dividing `a` by the result of dividing `a` by itself results in `a` (whether or not `a` is zero). -/ @[simp] theorem div_div_self (a : G₀) : a / (a / a) = a := by rw [div_div_eq_mul_div] exact mul_self_div_self a theorem ne_zero_of_one_div_ne_zero {a : G₀} (h : 1 / a ≠ 0) : a ≠ 0 := fun ha : a = 0 => by rw [ha, div_zero] at h contradiction theorem eq_zero_of_one_div_eq_zero {a : G₀} (h : 1 / a = 0) : a = 0 := Classical.byCases (fun ha => ha) fun ha => ((one_div_ne_zero ha) h).elim theorem mul_left_surjective₀ {a : G₀} (h : a ≠ 0) : Surjective fun g => a * g := fun g => ⟨a⁻¹ * g, by simp [← mul_assoc, mul_inv_cancel h]⟩ theorem mul_right_surjective₀ {a : G₀} (h : a ≠ 0) : Surjective fun g => g * a := fun g => ⟨g * a⁻¹, by simp [mul_assoc, inv_mul_cancel h]⟩ lemma zero_zpow : ∀ n : ℤ, n ≠ 0 → (0 : G₀) ^ n = 0 | (n : ℕ), h => by rw [zpow_natCast, zero_pow]; simpa [Int.natCast_eq_zero] using h | .negSucc n, _ => by simp lemma zero_zpow_eq (n : ℤ) : (0 : G₀) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, zpow_zero] · rw [zero_zpow _ h] lemma zpow_add_one₀ (ha : a ≠ 0) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a | (n : ℕ) => by simp only [← Int.ofNat_succ, zpow_natCast, pow_succ] | .negSucc 0 => by erw [zpow_zero, zpow_negSucc, pow_one, inv_mul_cancel ha] | .negSucc (n + 1) => by rw [Int.negSucc_eq, zpow_neg, Int.neg_add, Int.neg_add_cancel_right, zpow_neg, ← Int.ofNat_succ, zpow_natCast, zpow_natCast, pow_succ' _ (n + 1), mul_inv_rev, mul_assoc, inv_mul_cancel ha, mul_one] lemma zpow_sub_one₀ (ha : a ≠ 0) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ := calc a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ := by rw [mul_assoc, mul_inv_cancel ha, mul_one] _ = a ^ n * a⁻¹ := by rw [← zpow_add_one₀ ha, Int.sub_add_cancel] lemma zpow_add₀ (ha : a ≠ 0) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by induction' n using Int.induction_on with n ihn n ihn · simp · simp only [← Int.add_assoc, zpow_add_one₀ ha, ihn, mul_assoc] · rw [zpow_sub_one₀ ha, ← mul_assoc, ← ihn, ← zpow_sub_one₀ ha, Int.add_sub_assoc] lemma zpow_add' {m n : ℤ} (h : a ≠ 0 ∨ m + n ≠ 0 ∨ m = 0 ∧ n = 0) : a ^ (m + n) = a ^ m * a ^ n := by by_cases hm : m = 0 · simp [hm] by_cases hn : n = 0 · simp [hn] by_cases ha : a = 0 · subst a simp only [false_or_iff, eq_self_iff_true, not_true, Ne, hm, hn, false_and_iff, or_false_iff] at h rw [zero_zpow _ h, zero_zpow _ hm, zero_mul] · exact zpow_add₀ ha m n lemma zpow_one_add₀ (h : a ≠ 0) (i : ℤ) : a ^ (1 + i) = a * a ^ i := by rw [zpow_add₀ h, zpow_one] end GroupWithZero section CommGroupWithZero variable [CommGroupWithZero G₀] {a b c d : G₀} theorem div_mul_eq_mul_div₀ (a b c : G₀) : a / c * b = a * b / c := by simp_rw [div_eq_mul_inv, mul_assoc, mul_comm c⁻¹] lemma div_sq_cancel (a b : G₀) : a ^ 2 * b / a = a * b := by obtain rfl | ha := eq_or_ne a 0 · simp · rw [sq, mul_assoc, mul_div_cancel_left₀ _ ha] end CommGroupWithZero
Algebra\GroupWithZero\Center.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Jireh Loreaux -/ import Mathlib.Algebra.Group.Center import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Center of a group with zero -/ assert_not_exists Finset assert_not_exists Ring assert_not_exists Subsemigroup variable {M₀ G₀ : Type*} namespace Set section MulZeroClass variable [MulZeroClass M₀] {s : Set M₀} @[simp] lemma zero_mem_center : (0 : M₀) ∈ center M₀ where comm _ := by rw [zero_mul, mul_zero] left_assoc _ _ := by rw [zero_mul, zero_mul, zero_mul] mid_assoc _ _ := by rw [mul_zero, zero_mul, mul_zero] right_assoc _ _ := by rw [mul_zero, mul_zero, mul_zero] @[simp] lemma zero_mem_centralizer : (0 : M₀) ∈ centralizer s := by simp [mem_centralizer_iff] end MulZeroClass section GroupWithZero variable [GroupWithZero G₀] {s : Set G₀} {a b : G₀} lemma center_units_subset : center G₀ˣ ⊆ ((↑) : G₀ˣ → G₀) ⁻¹' center G₀ := by simp_rw [subset_def, mem_preimage, _root_.Semigroup.mem_center_iff] intro u hu a obtain rfl | ha := eq_or_ne a 0 · rw [zero_mul, mul_zero] · exact congr_arg Units.val $ hu $ Units.mk0 a ha /-- In a group with zero, the center of the units is the preimage of the center. -/ lemma center_units_eq : center G₀ˣ = ((↑) : G₀ˣ → G₀) ⁻¹' center G₀ := center_units_subset.antisymm subset_center_units @[simp] lemma inv_mem_centralizer₀ (ha : a ∈ centralizer s) : a⁻¹ ∈ centralizer s := by obtain rfl | ha₀ := eq_or_ne a 0 · rw [inv_zero] exact zero_mem_centralizer · rintro c hc rw [mul_inv_eq_iff_eq_mul₀ ha₀, mul_assoc, eq_inv_mul_iff_mul_eq₀ ha₀, ha c hc] @[simp] lemma div_mem_centralizer₀ (ha : a ∈ centralizer s) (hb : b ∈ centralizer s) : a / b ∈ centralizer s := by simpa only [div_eq_mul_inv] using mul_mem_centralizer ha (inv_mem_centralizer₀ hb) @[deprecated inv_mem_center (since := "2024-06-17")] theorem inv_mem_center₀ (ha : a ∈ Set.center G₀) : a⁻¹ ∈ Set.center G₀ := inv_mem_center ha @[deprecated div_mem_center (since := "2024-06-17")] theorem div_mem_center₀ (ha : a ∈ Set.center G₀) (hb : b ∈ Set.center G₀) : a / b ∈ Set.center G₀ := div_mem_center ha hb end GroupWithZero end Set
Algebra\GroupWithZero\Commute.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.GroupWithZero.Semiconj import Mathlib.Algebra.Group.Commute.Units import Mathlib.Tactic.Nontriviality /-! # Lemmas about commuting elements in a `MonoidWithZero` or a `GroupWithZero`. -/ assert_not_exists DenselyOrdered variable {α M₀ G₀ M₀' G₀' F F' : Type*} variable [MonoidWithZero M₀] namespace Ring theorem mul_inverse_rev' {a b : M₀} (h : Commute a b) : inverse (a * b) = inverse b * inverse a := by by_cases hab : IsUnit (a * b) · obtain ⟨⟨a, rfl⟩, b, rfl⟩ := h.isUnit_mul_iff.mp hab rw [← Units.val_mul, inverse_unit, inverse_unit, inverse_unit, ← Units.val_mul, mul_inv_rev] obtain ha | hb := not_and_or.mp (mt h.isUnit_mul_iff.mpr hab) · rw [inverse_non_unit _ hab, inverse_non_unit _ ha, mul_zero] · rw [inverse_non_unit _ hab, inverse_non_unit _ hb, zero_mul] theorem mul_inverse_rev {M₀} [CommMonoidWithZero M₀] (a b : M₀) : Ring.inverse (a * b) = inverse b * inverse a := mul_inverse_rev' (Commute.all _ _) lemma inverse_pow (r : M₀) : ∀ n : ℕ, Ring.inverse r ^ n = Ring.inverse (r ^ n) | 0 => by rw [pow_zero, pow_zero, Ring.inverse_one] | n + 1 => by rw [pow_succ', pow_succ, Ring.mul_inverse_rev' ((Commute.refl r).pow_left n), Ring.inverse_pow r n] end Ring theorem Commute.ring_inverse_ring_inverse {a b : M₀} (h : Commute a b) : Commute (Ring.inverse a) (Ring.inverse b) := (Ring.mul_inverse_rev' h.symm).symm.trans <| (congr_arg _ h.symm.eq).trans <| Ring.mul_inverse_rev' h namespace Commute @[simp] theorem zero_right [MulZeroClass G₀] (a : G₀) : Commute a 0 := SemiconjBy.zero_right a @[simp] theorem zero_left [MulZeroClass G₀] (a : G₀) : Commute 0 a := SemiconjBy.zero_left a a variable [GroupWithZero G₀] {a b c : G₀} @[simp] theorem inv_left_iff₀ : Commute a⁻¹ b ↔ Commute a b := SemiconjBy.inv_symm_left_iff₀ theorem inv_left₀ (h : Commute a b) : Commute a⁻¹ b := inv_left_iff₀.2 h @[simp] theorem inv_right_iff₀ : Commute a b⁻¹ ↔ Commute a b := SemiconjBy.inv_right_iff₀ theorem inv_right₀ (h : Commute a b) : Commute a b⁻¹ := inv_right_iff₀.2 h @[simp] theorem div_right (hab : Commute a b) (hac : Commute a c) : Commute a (b / c) := SemiconjBy.div_right hab hac @[simp] theorem div_left (hac : Commute a c) (hbc : Commute b c) : Commute (a / b) c := by rw [div_eq_mul_inv] exact hac.mul_left hbc.inv_left₀ end Commute section GroupWithZero variable {G₀ : Type*} [GroupWithZero G₀] {a : G₀} {m n : ℕ} theorem pow_inv_comm₀ (a : G₀) (m n : ℕ) : a⁻¹ ^ m * a ^ n = a ^ n * a⁻¹ ^ m := (Commute.refl a).inv_left₀.pow_pow m n end GroupWithZero
Algebra\GroupWithZero\Conj.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Conjugacy in a group with zero -/ assert_not_exists Multiset -- TODO -- assert_not_exists DenselyOrdered variable {α : Type*} [GroupWithZero α] {a b : α} @[simp] lemma isConj_iff₀ : IsConj a b ↔ ∃ c : α, c ≠ 0 ∧ c * a * c⁻¹ = b := by rw [IsConj, Units.exists_iff_ne_zero (p := (SemiconjBy · a b))] congr! 2 with c exact and_congr_right (mul_inv_eq_iff_eq_mul₀ · |>.symm)
Algebra\GroupWithZero\Defs.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.Defs import Mathlib.Logic.Function.Basic import Mathlib.Logic.Nontrivial.Defs import Mathlib.Tactic.SplitIfs /-! # Typeclasses for groups with an adjoined zero element This file provides just the typeclass definitions, and the projection lemmas that expose their members. ## Main definitions * `GroupWithZero` * `CommGroupWithZero` -/ assert_not_exists DenselyOrdered universe u -- We have to fix the universe of `G₀` here, since the default argument to -- `GroupWithZero.div'` cannot contain a universe metavariable. variable {G₀ : Type u} {M₀ M₀' G₀' : Type*} /-- Typeclass for expressing that a type `M₀` with multiplication and a zero satisfies `0 * a = 0` and `a * 0 = 0` for all `a : M₀`. -/ class MulZeroClass (M₀ : Type u) extends Mul M₀, Zero M₀ where /-- Zero is a left absorbing element for multiplication -/ zero_mul : ∀ a : M₀, 0 * a = 0 /-- Zero is a right absorbing element for multiplication -/ mul_zero : ∀ a : M₀, a * 0 = 0 /-- A mixin for left cancellative multiplication by nonzero elements. -/ class IsLeftCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀] : Prop where /-- Multiplication by a nonzero element is left cancellative. -/ protected mul_left_cancel_of_ne_zero : ∀ {a b c : M₀}, a ≠ 0 → a * b = a * c → b = c section IsLeftCancelMulZero variable [Mul M₀] [Zero M₀] [IsLeftCancelMulZero M₀] {a b c : M₀} theorem mul_left_cancel₀ (ha : a ≠ 0) (h : a * b = a * c) : b = c := IsLeftCancelMulZero.mul_left_cancel_of_ne_zero ha h theorem mul_right_injective₀ (ha : a ≠ 0) : Function.Injective (a * ·) := fun _ _ => mul_left_cancel₀ ha end IsLeftCancelMulZero /-- A mixin for right cancellative multiplication by nonzero elements. -/ class IsRightCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀] : Prop where /-- Multiplicatin by a nonzero element is right cancellative. -/ protected mul_right_cancel_of_ne_zero : ∀ {a b c : M₀}, b ≠ 0 → a * b = c * b → a = c section IsRightCancelMulZero variable [Mul M₀] [Zero M₀] [IsRightCancelMulZero M₀] {a b c : M₀} theorem mul_right_cancel₀ (hb : b ≠ 0) (h : a * b = c * b) : a = c := IsRightCancelMulZero.mul_right_cancel_of_ne_zero hb h theorem mul_left_injective₀ (hb : b ≠ 0) : Function.Injective fun a => a * b := fun _ _ => mul_right_cancel₀ hb end IsRightCancelMulZero /-- A mixin for cancellative multiplication by nonzero elements. -/ class IsCancelMulZero (M₀ : Type u) [Mul M₀] [Zero M₀] extends IsLeftCancelMulZero M₀, IsRightCancelMulZero M₀ : Prop export MulZeroClass (zero_mul mul_zero) attribute [simp] zero_mul mul_zero /-- Predicate typeclass for expressing that `a * b = 0` implies `a = 0` or `b = 0` for all `a` and `b` of type `G₀`. -/ class NoZeroDivisors (M₀ : Type*) [Mul M₀] [Zero M₀] : Prop where /-- For all `a` and `b` of `G₀`, `a * b = 0` implies `a = 0` or `b = 0`. -/ eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : M₀}, a * b = 0 → a = 0 ∨ b = 0 export NoZeroDivisors (eq_zero_or_eq_zero_of_mul_eq_zero) /-- A type `S₀` is a "semigroup with zero” if it is a semigroup with zero element, and `0` is left and right absorbing. -/ class SemigroupWithZero (S₀ : Type u) extends Semigroup S₀, MulZeroClass S₀ /-- A typeclass for non-associative monoids with zero elements. -/ class MulZeroOneClass (M₀ : Type u) extends MulOneClass M₀, MulZeroClass M₀ /-- A type `M₀` is a “monoid with zero” if it is a monoid with zero element, and `0` is left and right absorbing. -/ class MonoidWithZero (M₀ : Type u) extends Monoid M₀, MulZeroOneClass M₀, SemigroupWithZero M₀ /-- A type `M` is a `CancelMonoidWithZero` if it is a monoid with zero element, `0` is left and right absorbing, and left/right multiplication by a non-zero element is injective. -/ class CancelMonoidWithZero (M₀ : Type*) extends MonoidWithZero M₀, IsCancelMulZero M₀ /-- A type `M` is a commutative “monoid with zero” if it is a commutative monoid with zero element, and `0` is left and right absorbing. -/ class CommMonoidWithZero (M₀ : Type*) extends CommMonoid M₀, MonoidWithZero M₀ section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] {a b c : M₀} theorem mul_left_inj' (hc : c ≠ 0) : a * c = b * c ↔ a = b := (mul_left_injective₀ hc).eq_iff theorem mul_right_inj' (ha : a ≠ 0) : a * b = a * c ↔ b = c := (mul_right_injective₀ ha).eq_iff end CancelMonoidWithZero section CommSemigroup variable [CommSemigroup M₀] [Zero M₀] lemma IsLeftCancelMulZero.to_isRightCancelMulZero [IsLeftCancelMulZero M₀] : IsRightCancelMulZero M₀ := { mul_right_cancel_of_ne_zero := fun hb h => mul_left_cancel₀ hb <| (mul_comm _ _).trans (h.trans (mul_comm _ _)) } lemma IsRightCancelMulZero.to_isLeftCancelMulZero [IsRightCancelMulZero M₀] : IsLeftCancelMulZero M₀ := { mul_left_cancel_of_ne_zero := fun hb h => mul_right_cancel₀ hb <| (mul_comm _ _).trans (h.trans (mul_comm _ _)) } lemma IsLeftCancelMulZero.to_isCancelMulZero [IsLeftCancelMulZero M₀] : IsCancelMulZero M₀ := { IsLeftCancelMulZero.to_isRightCancelMulZero with } lemma IsRightCancelMulZero.to_isCancelMulZero [IsRightCancelMulZero M₀] : IsCancelMulZero M₀ := { IsRightCancelMulZero.to_isLeftCancelMulZero with } end CommSemigroup /-- A type `M` is a `CancelCommMonoidWithZero` if it is a commutative monoid with zero element, `0` is left and right absorbing, and left/right multiplication by a non-zero element is injective. -/ class CancelCommMonoidWithZero (M₀ : Type*) extends CommMonoidWithZero M₀, IsLeftCancelMulZero M₀ -- See note [lower cancel priority] attribute [instance 75] CancelCommMonoidWithZero.toCommMonoidWithZero instance (priority := 100) CancelCommMonoidWithZero.toCancelMonoidWithZero [CancelCommMonoidWithZero M₀] : CancelMonoidWithZero M₀ := { IsLeftCancelMulZero.to_isCancelMulZero (M₀ := M₀) with } /-- Prop-valued mixin for a monoid with zero to be equipped with a cancelling division. The obvious use case is groups with zero, but this condition is also satisfied by `ℕ`, `ℤ` and, more generally, any euclidean domain. -/ class MulDivCancelClass (M₀ : Type*) [MonoidWithZero M₀] [Div M₀] : Prop where protected mul_div_cancel (a b : M₀) : b ≠ 0 → a * b / b = a section MulDivCancelClass variable [MonoidWithZero M₀] [Div M₀] [MulDivCancelClass M₀] {a b : M₀} @[simp] lemma mul_div_cancel_right₀ (a : M₀) (hb : b ≠ 0) : a * b / b = a := MulDivCancelClass.mul_div_cancel _ _ hb end MulDivCancelClass section MulDivCancelClass variable [CommMonoidWithZero M₀] [Div M₀] [MulDivCancelClass M₀] {a b : M₀} @[simp] lemma mul_div_cancel_left₀ (b : M₀) (ha : a ≠ 0) : a * b / a = b := by rw [mul_comm, mul_div_cancel_right₀ _ ha] end MulDivCancelClass /-- A type `G₀` is a “group with zero” if it is a monoid with zero element (distinct from `1`) such that every nonzero element is invertible. The type is required to come with an “inverse” function, and the inverse of `0` must be `0`. Examples include division rings and the ordered monoids that are the target of valuations in general valuation theory. -/ class GroupWithZero (G₀ : Type u) extends MonoidWithZero G₀, DivInvMonoid G₀, Nontrivial G₀ where /-- The inverse of `0` in a group with zero is `0`. -/ inv_zero : (0 : G₀)⁻¹ = 0 /-- Every nonzero element of a group with zero is invertible. -/ protected mul_inv_cancel (a : G₀) : a ≠ 0 → a * a⁻¹ = 1 export GroupWithZero (inv_zero) attribute [simp] inv_zero section GroupWithZero variable [GroupWithZero G₀] {a : G₀} @[simp] lemma mul_inv_cancel (h : a ≠ 0) : a * a⁻¹ = 1 := GroupWithZero.mul_inv_cancel a h -- See note [lower instance priority] instance (priority := 100) GroupWithZero.toMulDivCancelClass : MulDivCancelClass G₀ where mul_div_cancel a b hb := by rw [div_eq_mul_inv, mul_assoc, mul_inv_cancel hb, mul_one] end GroupWithZero /-- A type `G₀` is a commutative “group with zero” if it is a commutative monoid with zero element (distinct from `1`) such that every nonzero element is invertible. The type is required to come with an “inverse” function, and the inverse of `0` must be `0`. -/ class CommGroupWithZero (G₀ : Type*) extends CommMonoidWithZero G₀, GroupWithZero G₀ section variable [CancelMonoidWithZero M₀] {x : M₀} lemma eq_zero_or_one_of_sq_eq_self (hx : x ^ 2 = x) : x = 0 ∨ x = 1 := or_iff_not_imp_left.mpr (mul_left_injective₀ · <| by simpa [sq] using hx) end section GroupWithZero variable [GroupWithZero G₀] {a b c g h x : G₀} @[simp] theorem mul_inv_cancel_right₀ (h : b ≠ 0) (a : G₀) : a * b * b⁻¹ = a := calc a * b * b⁻¹ = a * (b * b⁻¹) := mul_assoc _ _ _ _ = a := by simp [h] @[simp] theorem mul_inv_cancel_left₀ (h : a ≠ 0) (b : G₀) : a * (a⁻¹ * b) = b := calc a * (a⁻¹ * b) = a * a⁻¹ * b := (mul_assoc _ _ _).symm _ = b := by simp [h] end GroupWithZero section MulZeroClass variable [MulZeroClass M₀] theorem mul_eq_zero_of_left {a : M₀} (h : a = 0) (b : M₀) : a * b = 0 := h.symm ▸ zero_mul b theorem mul_eq_zero_of_right (a : M₀) {b : M₀} (h : b = 0) : a * b = 0 := h.symm ▸ mul_zero a variable [NoZeroDivisors M₀] {a b : M₀} /-- If `α` has no zero divisors, then the product of two elements equals zero iff one of them equals zero. -/ @[simp] theorem mul_eq_zero : a * b = 0 ↔ a = 0 ∨ b = 0 := ⟨eq_zero_or_eq_zero_of_mul_eq_zero, fun o => o.elim (fun h => mul_eq_zero_of_left h b) (mul_eq_zero_of_right a)⟩ /-- If `α` has no zero divisors, then the product of two elements equals zero iff one of them equals zero. -/ @[simp] theorem zero_eq_mul : 0 = a * b ↔ a = 0 ∨ b = 0 := by rw [eq_comm, mul_eq_zero] /-- If `α` has no zero divisors, then the product of two elements is nonzero iff both of them are nonzero. -/ theorem mul_ne_zero_iff : a * b ≠ 0 ↔ a ≠ 0 ∧ b ≠ 0 := mul_eq_zero.not.trans not_or /-- If `α` has no zero divisors, then for elements `a, b : α`, `a * b` equals zero iff so is `b * a`. -/ theorem mul_eq_zero_comm : a * b = 0 ↔ b * a = 0 := mul_eq_zero.trans <| or_comm.trans mul_eq_zero.symm /-- If `α` has no zero divisors, then for elements `a, b : α`, `a * b` is nonzero iff so is `b * a`. -/ theorem mul_ne_zero_comm : a * b ≠ 0 ↔ b * a ≠ 0 := mul_eq_zero_comm.not theorem mul_self_eq_zero : a * a = 0 ↔ a = 0 := by simp theorem zero_eq_mul_self : 0 = a * a ↔ a = 0 := by simp theorem mul_self_ne_zero : a * a ≠ 0 ↔ a ≠ 0 := mul_self_eq_zero.not theorem zero_ne_mul_self : 0 ≠ a * a ↔ a ≠ 0 := zero_eq_mul_self.not end MulZeroClass
Algebra\GroupWithZero\Divisibility.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov, Neil Strickland, Aaron Anderson -/ import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Divisibility.Units /-! # Divisibility in groups with zero. Lemmas about divisibility in groups and monoids with zero. -/ assert_not_exists DenselyOrdered variable {α : Type*} section SemigroupWithZero variable [SemigroupWithZero α] {a : α} theorem eq_zero_of_zero_dvd (h : 0 ∣ a) : a = 0 := Dvd.elim h fun c H' => H'.trans (zero_mul c) /-- Given an element `a` of a commutative semigroup with zero, there exists another element whose product with zero equals `a` iff `a` equals zero. -/ @[simp] theorem zero_dvd_iff : 0 ∣ a ↔ a = 0 := ⟨eq_zero_of_zero_dvd, fun h => by rw [h] exact ⟨0, by simp⟩⟩ @[simp] theorem dvd_zero (a : α) : a ∣ 0 := Dvd.intro 0 (by simp) end SemigroupWithZero /-- Given two elements `b`, `c` of a `CancelMonoidWithZero` and a nonzero element `a`, `a*b` divides `a*c` iff `b` divides `c`. -/ theorem mul_dvd_mul_iff_left [CancelMonoidWithZero α] {a b c : α} (ha : a ≠ 0) : a * b ∣ a * c ↔ b ∣ c := exists_congr fun d => by rw [mul_assoc, mul_right_inj' ha] /-- Given two elements `a`, `b` of a commutative `CancelMonoidWithZero` and a nonzero element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/ theorem mul_dvd_mul_iff_right [CancelCommMonoidWithZero α] {a b c : α} (hc : c ≠ 0) : a * c ∣ b * c ↔ a ∣ b := exists_congr fun d => by rw [mul_right_comm, mul_left_inj' hc] section CommMonoidWithZero variable [CommMonoidWithZero α] /-- `DvdNotUnit a b` expresses that `a` divides `b` "strictly", i.e. that `b` divided by `a` is not a unit. -/ def DvdNotUnit (a b : α) : Prop := a ≠ 0 ∧ ∃ x, ¬IsUnit x ∧ b = a * x theorem dvdNotUnit_of_dvd_of_not_dvd {a b : α} (hd : a ∣ b) (hnd : ¬b ∣ a) : DvdNotUnit a b := by constructor · rintro rfl exact hnd (dvd_zero _) · rcases hd with ⟨c, rfl⟩ refine ⟨c, ?_, rfl⟩ rintro ⟨u, rfl⟩ simp at hnd variable {x y : α} theorem isRelPrime_zero_left : IsRelPrime 0 x ↔ IsUnit x := ⟨(· (dvd_zero _) dvd_rfl), IsUnit.isRelPrime_right⟩ theorem isRelPrime_zero_right : IsRelPrime x 0 ↔ IsUnit x := isRelPrime_comm.trans isRelPrime_zero_left theorem not_isRelPrime_zero_zero [Nontrivial α] : ¬IsRelPrime (0 : α) 0 := mt isRelPrime_zero_right.mp not_isUnit_zero theorem IsRelPrime.ne_zero_or_ne_zero [Nontrivial α] (h : IsRelPrime x y) : x ≠ 0 ∨ y ≠ 0 := not_or_of_imp <| by rintro rfl rfl; exact not_isRelPrime_zero_zero h end CommMonoidWithZero theorem isRelPrime_of_no_nonunits_factors [MonoidWithZero α] {x y : α} (nonzero : ¬(x = 0 ∧ y = 0)) (H : ∀ z, ¬ IsUnit z → z ≠ 0 → z ∣ x → ¬z ∣ y) : IsRelPrime x y := by refine fun z hx hy ↦ by_contra fun h ↦ H z h ?_ hx hy rintro rfl; exact nonzero ⟨zero_dvd_iff.1 hx, zero_dvd_iff.1 hy⟩ theorem dvd_and_not_dvd_iff [CancelCommMonoidWithZero α] {x y : α} : x ∣ y ∧ ¬y ∣ x ↔ DvdNotUnit x y := ⟨fun ⟨⟨d, hd⟩, hyx⟩ => ⟨fun hx0 => by simp [hx0] at hyx, ⟨d, mt isUnit_iff_dvd_one.1 fun ⟨e, he⟩ => hyx ⟨e, by rw [hd, mul_assoc, ← he, mul_one]⟩, hd⟩⟩, fun ⟨hx0, d, hdu, hdx⟩ => ⟨⟨d, hdx⟩, fun ⟨e, he⟩ => hdu (isUnit_of_dvd_one ⟨e, mul_left_cancel₀ hx0 <| by conv => lhs rw [he, hdx] simp [mul_assoc]⟩)⟩⟩ section MonoidWithZero variable [MonoidWithZero α] theorem ne_zero_of_dvd_ne_zero {p q : α} (h₁ : q ≠ 0) (h₂ : p ∣ q) : p ≠ 0 := by rcases h₂ with ⟨u, rfl⟩ exact left_ne_zero_of_mul h₁ theorem isPrimal_zero : IsPrimal (0 : α) := fun a b h ↦ ⟨a, b, dvd_rfl, dvd_rfl, (zero_dvd_iff.mp h).symm⟩ theorem IsPrimal.mul {α} [CancelCommMonoidWithZero α] {m n : α} (hm : IsPrimal m) (hn : IsPrimal n) : IsPrimal (m * n) := by obtain rfl | h0 := eq_or_ne m 0; · rwa [zero_mul] intro b c h obtain ⟨a₁, a₂, ⟨b, rfl⟩, ⟨c, rfl⟩, rfl⟩ := hm (dvd_of_mul_right_dvd h) rw [mul_mul_mul_comm, mul_dvd_mul_iff_left h0] at h obtain ⟨a₁', a₂', h₁, h₂, rfl⟩ := hn h exact ⟨a₁ * a₁', a₂ * a₂', mul_dvd_mul_left _ h₁, mul_dvd_mul_left _ h₂, mul_mul_mul_comm _ _ _ _⟩ end MonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero α] {a b : α} {m n : ℕ} section Subsingleton variable [Subsingleton αˣ] theorem dvd_antisymm : a ∣ b → b ∣ a → a = b := by rintro ⟨c, rfl⟩ ⟨d, hcd⟩ rw [mul_assoc, eq_comm, mul_right_eq_self₀, mul_eq_one] at hcd obtain ⟨rfl, -⟩ | rfl := hcd <;> simp -- Porting note: `attribute [protected]` is currently unsupported -- attribute [protected] Nat.dvd_antisymm --This lemma is in core, so we protect it here theorem dvd_antisymm' : a ∣ b → b ∣ a → b = a := flip dvd_antisymm alias Dvd.dvd.antisymm := dvd_antisymm alias Dvd.dvd.antisymm' := dvd_antisymm' theorem eq_of_forall_dvd (h : ∀ c, a ∣ c ↔ b ∣ c) : a = b := ((h _).2 dvd_rfl).antisymm <| (h _).1 dvd_rfl theorem eq_of_forall_dvd' (h : ∀ c, c ∣ a ↔ c ∣ b) : a = b := ((h _).1 dvd_rfl).antisymm <| (h _).2 dvd_rfl end Subsingleton lemma pow_dvd_pow_iff (ha₀ : a ≠ 0) (ha : ¬IsUnit a) : a ^ n ∣ a ^ m ↔ n ≤ m := by constructor · intro h rw [← not_lt] intro hmn apply ha have : a ^ m * a ∣ a ^ m * 1 := by rw [← pow_succ, mul_one] exact (pow_dvd_pow _ (Nat.succ_le_of_lt hmn)).trans h rwa [mul_dvd_mul_iff_left, ← isUnit_iff_dvd_one] at this apply pow_ne_zero m ha₀ · apply pow_dvd_pow end CancelCommMonoidWithZero
Algebra\GroupWithZero\Hom.lean
/- Copyright (c) 2020 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Algebra.NeZero /-! # Monoid with zero and group with zero homomorphisms This file defines homomorphisms of monoids with zero. We also define coercion to a function, and usual operations: composition, identity homomorphism, pointwise multiplication and pointwise inversion. ## Notations * `→*₀`: `MonoidWithZeroHom`, the type of bundled `MonoidWithZero` homs. Also use for `GroupWithZero` homs. ## Implementation notes Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the instances can be inferred because they are implicit arguments to the type `MonoidHom`. When they can be inferred from the type it is faster to use this method than to use type class inference. ## Tags monoid homomorphism -/ assert_not_exists DenselyOrdered open Function namespace NeZero variable {F α β : Type*} [Zero α] [Zero β] [FunLike F α β] [ZeroHomClass F α β] {a : α} lemma of_map (f : F) [neZero : NeZero (f a)] : NeZero a := ⟨fun h ↦ ne (f a) <| by rw [h]; exact ZeroHomClass.map_zero f⟩ lemma of_injective {f : F} (hf : Injective f) [NeZero a] : NeZero (f a) := ⟨by rw [← ZeroHomClass.map_zero f]; exact hf.ne NeZero.out⟩ end NeZero variable {F α β γ δ M₀ : Type*} [MulZeroOneClass α] [MulZeroOneClass β] [MulZeroOneClass γ] [MulZeroOneClass δ] /-- `MonoidWithZeroHomClass F α β` states that `F` is a type of `MonoidWithZero`-preserving homomorphisms. You should also extend this typeclass when you extend `MonoidWithZeroHom`. -/ class MonoidWithZeroHomClass (F : Type*) (α β : outParam Type*) [MulZeroOneClass α] [MulZeroOneClass β] [FunLike F α β] extends MonoidHomClass F α β, ZeroHomClass F α β : Prop /-- `α →*₀ β` is the type of functions `α → β` that preserve the `MonoidWithZero` structure. `MonoidWithZeroHom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : α →*₀ β)`, you should parametrize over `(F : Type*) [MonoidWithZeroHomClass F α β] (f : F)`. When you extend this structure, make sure to extend `MonoidWithZeroHomClass`. -/ structure MonoidWithZeroHom (α β : Type*) [MulZeroOneClass α] [MulZeroOneClass β] extends ZeroHom α β, MonoidHom α β /-- `α →*₀ β` denotes the type of zero-preserving monoid homomorphisms from `α` to `β`. -/ infixr:25 " →*₀ " => MonoidWithZeroHom /-- Turn an element of a type `F` satisfying `MonoidWithZeroHomClass F α β` into an actual `MonoidWithZeroHom`. This is declared as the default coercion from `F` to `α →*₀ β`. -/ @[coe] def MonoidWithZeroHomClass.toMonoidWithZeroHom [FunLike F α β] [MonoidWithZeroHomClass F α β] (f : F) : α →*₀ β := { (f : α →* β), (f : ZeroHom α β) with } /-- Any type satisfying `MonoidWithZeroHomClass` can be cast into `MonoidWithZeroHom` via `MonoidWithZeroHomClass.toMonoidWithZeroHom`. -/ instance [FunLike F α β] [MonoidWithZeroHomClass F α β] : CoeTC F (α →*₀ β) := ⟨MonoidWithZeroHomClass.toMonoidWithZeroHom⟩ namespace MonoidWithZeroHom attribute [nolint docBlame] toMonoidHom attribute [nolint docBlame] toZeroHom instance funLike : FunLike (α →*₀ β) α β where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr instance monoidWithZeroHomClass : MonoidWithZeroHomClass (α →*₀ β) α β where map_mul := MonoidWithZeroHom.map_mul' map_one := MonoidWithZeroHom.map_one' map_zero f := f.map_zero' instance [Subsingleton α] : Subsingleton (α →*₀ β) := .of_oneHomClass variable [FunLike F α β] @[simp] lemma coe_coe [MonoidWithZeroHomClass F α β] (f : F) : ((f : α →*₀ β) : α → β) = f := rfl -- Completely uninteresting lemmas about coercion to function, that all homs need section Coes /-! Bundled morphisms can be down-cast to weaker bundlings -/ attribute [coe] toMonoidHom /-- `MonoidWithZeroHom` down-cast to a `MonoidHom`, forgetting the 0-preserving property. -/ instance coeToMonoidHom : Coe (α →*₀ β) (α →* β) := ⟨toMonoidHom⟩ attribute [coe] toZeroHom /-- `MonoidWithZeroHom` down-cast to a `ZeroHom`, forgetting the monoidal property. -/ instance coeToZeroHom : Coe (α →*₀ β) (ZeroHom α β) := ⟨toZeroHom⟩ -- This must come after the coe_toFun definitions initialize_simps_projections MonoidWithZeroHom (toFun → apply) @[simp] lemma coe_mk (f h1 hmul) : (mk f h1 hmul : α → β) = (f : α → β) := rfl @[simp] lemma toZeroHom_coe (f : α →*₀ β) : (f.toZeroHom : α → β) = f := rfl lemma toMonoidHom_coe (f : α →*₀ β) : f.toMonoidHom.toFun = f := rfl @[ext] lemma ext ⦃f g : α →*₀ β⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h @[simp] lemma mk_coe (f : α →*₀ β) (h1 hmul) : mk f h1 hmul = f := ext fun _ ↦ rfl end Coes /-- Copy of a `MonoidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : α →*₀ β) (f' : α → β) (h : f' = f) : α →* β := { f.toZeroHom.copy f' h, f.toMonoidHom.copy f' h with } @[simp] lemma coe_copy (f : α →*₀ β) (f' : α → β) (h) : (f.copy f' h) = f' := rfl lemma copy_eq (f : α →*₀ β) (f' : α → β) (h) : f.copy f' h = f := DFunLike.ext' h protected lemma map_one (f : α →*₀ β) : f 1 = 1 := f.map_one' protected lemma map_zero (f : α →*₀ β) : f 0 = 0 := f.map_zero' protected lemma map_mul (f : α →*₀ β) (a b : α) : f (a * b) = f a * f b := f.map_mul' a b /-- The identity map from a `MonoidWithZero` to itself. -/ @[simps] def id (α : Type*) [MulZeroOneClass α] : α →*₀ α where toFun x := x map_zero' := rfl map_one' := rfl map_mul' _ _ := rfl /-- Composition of `MonoidWithZeroHom`s as a `MonoidWithZeroHom`. -/ def comp (hnp : β →*₀ γ) (hmn : α →*₀ β) : α →*₀ γ where toFun := hnp ∘ hmn map_zero' := by rw [comp_apply, map_zero, map_zero] map_one' := by simp map_mul' := by simp @[simp] lemma coe_comp (g : β →*₀ γ) (f : α →*₀ β) : ↑(g.comp f) = g ∘ f := rfl lemma comp_apply (g : β →*₀ γ) (f : α →*₀ β) (x : α) : g.comp f x = g (f x) := rfl lemma comp_assoc (f : α →*₀ β) (g : β →*₀ γ) (h : γ →*₀ δ) : (h.comp g).comp f = h.comp (g.comp f) := rfl lemma cancel_right {g₁ g₂ : β →*₀ γ} {f : α →*₀ β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h ↦ ext $ hf.forall.2 (DFunLike.ext_iff.1 h), fun h ↦ h ▸ rfl⟩ lemma cancel_left {g : β →*₀ γ} {f₁ f₂ : α →*₀ β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h ↦ ext fun x ↦ hg $ by rw [← comp_apply, h, comp_apply], fun h ↦ h ▸ rfl⟩ lemma toMonoidHom_injective : Injective (toMonoidHom : (α →*₀ β) → α →* β) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective lemma toZeroHom_injective : Injective (toZeroHom : (α →*₀ β) → ZeroHom α β) := Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective @[simp] lemma comp_id (f : α →*₀ β) : f.comp (id α) = f := ext fun _ ↦ rfl @[simp] lemma id_comp (f : α →*₀ β) : (id β).comp f = f := ext fun _ ↦ rfl -- Unlike the other homs, `MonoidWithZeroHom` does not have a `1` or `0` instance : Inhabited (α →*₀ α) := ⟨id α⟩ /-- Given two monoid with zero morphisms `f`, `g` to a commutative monoid with zero, `f * g` is the monoid with zero morphism sending `x` to `f x * g x`. -/ instance {β} [CommMonoidWithZero β] : Mul (α →*₀ β) where mul f g := { (f * g : α →* β) with map_zero' := by dsimp; rw [map_zero, zero_mul] } end MonoidWithZeroHom section CommMonoidWithZero variable [CommMonoidWithZero M₀] {n : ℕ} (hn : n ≠ 0) /-- We define `x ↦ x^n` (for positive `n : ℕ`) as a `MonoidWithZeroHom` -/ def powMonoidWithZeroHom : M₀ →*₀ M₀ := { powMonoidHom n with map_zero' := zero_pow hn } @[simp] lemma coe_powMonoidWithZeroHom : (powMonoidWithZeroHom hn : M₀ → M₀) = fun x ↦ x ^ n := rfl @[simp] lemma powMonoidWithZeroHom_apply (a : M₀) : powMonoidWithZeroHom hn a = a ^ n := rfl end CommMonoidWithZero /-! ### Equivalences -/ namespace MulEquivClass variable {F α β : Type*} [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) toZeroHomClass [MulZeroClass α] [MulZeroClass β] [MulEquivClass F α β] : ZeroHomClass F α β where map_zero f := calc f 0 = f 0 * f (EquivLike.inv f 0) := by rw [← map_mul, zero_mul] _ = 0 := by simp -- See note [lower instance priority] instance (priority := 100) toMonoidWithZeroHomClass [MulZeroOneClass α] [MulZeroOneClass β] [MulEquivClass F α β] : MonoidWithZeroHomClass F α β := { MulEquivClass.instMonoidHomClass F, MulEquivClass.toZeroHomClass with } end MulEquivClass
Algebra\GroupWithZero\Indicator.lean
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Algebra.GroupWithZero.Basic /-! # Indicator functions and support of a function in groups with zero -/ open Set variable {ι κ G₀ M₀ R : Type*} namespace Set section MulZeroClass variable [MulZeroClass M₀] {s t : Set ι} {f g : ι → M₀} {i : ι} lemma indicator_mul (s : Set ι) (f g : ι → M₀) : indicator s (fun i ↦ f i * g i) = fun i ↦ indicator s f i * indicator s g i := by funext simp only [indicator] split_ifs · rfl rw [mul_zero] lemma indicator_mul_left (s : Set ι) (f g : ι → M₀) : indicator s (fun j ↦ f j * g j) i = indicator s f i * g i := by simp only [indicator] split_ifs · rfl · rw [zero_mul] lemma indicator_mul_right (s : Set ι) (f g : ι → M₀) : indicator s (fun j ↦ f j * g j) i = f i * indicator s g i := by simp only [indicator] split_ifs · rfl · rw [mul_zero] lemma inter_indicator_mul (f g : ι → M₀) (i : ι) : (s ∩ t).indicator (fun j ↦ f j * g j) i = s.indicator f i * t.indicator g i := by rw [← Set.indicator_indicator] simp_rw [indicator] split_ifs <;> simp end MulZeroClass section MulZeroOneClass variable [MulZeroOneClass M₀] {s t : Set ι} {i : ι} lemma inter_indicator_one : (s ∩ t).indicator (1 : ι → M₀) = s.indicator 1 * t.indicator 1 := funext fun _ ↦ by simp only [← inter_indicator_mul, Pi.mul_apply, Pi.one_apply, one_mul]; congr lemma indicator_prod_one {t : Set κ} {j : κ} : (s ×ˢ t).indicator (1 : ι × κ → M₀) (i, j) = s.indicator 1 i * t.indicator 1 j := by simp_rw [indicator, mem_prod_eq] split_ifs with h₀ <;> simp only [Pi.one_apply, mul_one, mul_zero] <;> tauto variable (M₀) [Nontrivial M₀] lemma indicator_eq_zero_iff_not_mem : indicator s 1 i = (0 : M₀) ↔ i ∉ s := by classical simp [indicator_apply, imp_false] lemma indicator_eq_one_iff_mem : indicator s 1 i = (1 : M₀) ↔ i ∈ s := by classical simp [indicator_apply, imp_false] lemma indicator_one_inj (h : indicator s (1 : ι → M₀) = indicator t 1) : s = t := by ext; simp_rw [← indicator_eq_one_iff_mem M₀, h] end MulZeroOneClass end Set namespace Function section ZeroOne variable (R) [Zero R] [One R] [NeZero (1 : R)] @[simp] lemma support_one : support (1 : ι → R) = univ := support_const one_ne_zero @[simp] lemma mulSupport_zero : mulSupport (0 : ι → R) = univ := mulSupport_const zero_ne_one end ZeroOne section MulZeroClass variable [MulZeroClass M₀] --@[simp] Porting note: removing simp, bad lemma LHS not in normal form lemma support_mul_subset_left (f g : ι → M₀) : support (fun x ↦ f x * g x) ⊆ support f := fun x hfg hf ↦ hfg <| by simp only [hf, zero_mul] --@[simp] Porting note: removing simp, bad lemma LHS not in normal form lemma support_mul_subset_right (f g : ι → M₀) : support (fun x ↦ f x * g x) ⊆ support g := fun x hfg hg => hfg <| by simp only [hg, mul_zero] variable [NoZeroDivisors M₀] @[simp] lemma support_mul (f g : ι → M₀) : support (fun x ↦ f x * g x) = support f ∩ support g := ext fun x ↦ by simp [not_or] @[simp] lemma support_mul' (f g : ι → M₀) : support (f * g) = support f ∩ support g := support_mul _ _ end MulZeroClass section MonoidWithZero variable [MonoidWithZero M₀] [NoZeroDivisors M₀] {n : ℕ} @[simp] lemma support_pow (f : ι → M₀) (hn : n ≠ 0) : support (fun a ↦ f a ^ n) = support f := by ext; exact (pow_eq_zero_iff hn).not @[simp] lemma support_pow' (f : ι → M₀) (hn : n ≠ 0) : support (f ^ n) = support f := support_pow _ hn end MonoidWithZero section GroupWithZero variable [GroupWithZero G₀] @[simp] lemma support_inv (f : ι → G₀) : support (fun a ↦ (f a)⁻¹) = support f := Set.ext fun _ ↦ not_congr inv_eq_zero @[simp] lemma support_inv' (f : ι → G₀) : support f⁻¹ = support f := support_inv _ @[simp] lemma support_div (f g : ι → G₀) : support (fun a ↦ f a / g a) = support f ∩ support g := by simp [div_eq_mul_inv] @[simp] lemma support_div' (f g : ι → G₀) : support (f / g) = support f ∩ support g := support_div _ _ end GroupWithZero variable [One R] lemma mulSupport_one_add [AddLeftCancelMonoid R] (f : ι → R) : mulSupport (fun x ↦ 1 + f x) = support f := Set.ext fun _ ↦ not_congr add_right_eq_self lemma mulSupport_one_add' [AddLeftCancelMonoid R] (f : ι → R) : mulSupport (1 + f) = support f := mulSupport_one_add f lemma mulSupport_add_one [AddRightCancelMonoid R] (f : ι → R) : mulSupport (fun x ↦ f x + 1) = support f := Set.ext fun _ ↦ not_congr add_left_eq_self lemma mulSupport_add_one' [AddRightCancelMonoid R] (f : ι → R) : mulSupport (f + 1) = support f := mulSupport_add_one f lemma mulSupport_one_sub' [AddGroup R] (f : ι → R) : mulSupport (1 - f) = support f := by rw [sub_eq_add_neg, mulSupport_one_add', support_neg'] lemma mulSupport_one_sub [AddGroup R] (f : ι → R) : mulSupport (fun x ↦ 1 - f x) = support f := mulSupport_one_sub' f end Function
Algebra\GroupWithZero\InjSurj.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.InjSurj import Mathlib.Algebra.GroupWithZero.NeZero /-! # Lifting groups with zero along injective/surjective maps -/ assert_not_exists DenselyOrdered open Function variable {M₀ G₀ M₀' G₀' : Type*} section MulZeroClass variable [MulZeroClass M₀] {a b : M₀} /-- Pull back a `MulZeroClass` instance along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.mulZeroClass [Mul M₀'] [Zero M₀'] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (mul : ∀ a b, f (a * b) = f a * f b) : MulZeroClass M₀' where mul := (· * ·) zero := 0 zero_mul a := hf <| by simp only [mul, zero, zero_mul] mul_zero a := hf <| by simp only [mul, zero, mul_zero] /-- Push forward a `MulZeroClass` instance along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.mulZeroClass [Mul M₀'] [Zero M₀'] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (mul : ∀ a b, f (a * b) = f a * f b) : MulZeroClass M₀' where mul := (· * ·) zero := 0 mul_zero := hf.forall.2 fun x => by simp only [← zero, ← mul, mul_zero] zero_mul := hf.forall.2 fun x => by simp only [← zero, ← mul, zero_mul] end MulZeroClass section NoZeroDivisors variable [Mul M₀] [Zero M₀] [Mul M₀'] [Zero M₀'] (f : M₀ → M₀') (hf : Injective f) (zero : f 0 = 0) (mul : ∀ x y, f (x * y) = f x * f y) /-- Pull back a `NoZeroDivisors` instance along an injective function. -/ protected theorem Function.Injective.noZeroDivisors [NoZeroDivisors M₀'] : NoZeroDivisors M₀ := { eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} H ↦ have : f a * f b = 0 := by rw [← mul, H, zero] (eq_zero_or_eq_zero_of_mul_eq_zero this).imp (fun H => hf <| by rwa [zero]) fun H => hf <| by rwa [zero] } protected theorem Function.Injective.isLeftCancelMulZero [IsLeftCancelMulZero M₀'] : IsLeftCancelMulZero M₀ := { mul_left_cancel_of_ne_zero := fun Hne He => by have := congr_arg f He rw [mul, mul] at this exact hf (mul_left_cancel₀ (fun Hfa => Hne <| hf <| by rw [Hfa, zero]) this) } protected theorem Function.Injective.isRightCancelMulZero [IsRightCancelMulZero M₀'] : IsRightCancelMulZero M₀ := { mul_right_cancel_of_ne_zero := fun Hne He => by have := congr_arg f He rw [mul, mul] at this exact hf (mul_right_cancel₀ (fun Hfa => Hne <| hf <| by rw [Hfa, zero]) this) } end NoZeroDivisors section MulZeroOneClass variable [MulZeroOneClass M₀] /-- Pull back a `MulZeroOneClass` instance along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.mulZeroOneClass [Mul M₀'] [Zero M₀'] [One M₀'] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ a b, f (a * b) = f a * f b) : MulZeroOneClass M₀' := { hf.mulZeroClass f zero mul, hf.mulOneClass f one mul with } /-- Push forward a `MulZeroOneClass` instance along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.mulZeroOneClass [Mul M₀'] [Zero M₀'] [One M₀'] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ a b, f (a * b) = f a * f b) : MulZeroOneClass M₀' := { hf.mulZeroClass f zero mul, hf.mulOneClass f one mul with } end MulZeroOneClass section SemigroupWithZero /-- Pull back a `SemigroupWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.semigroupWithZero [Zero M₀'] [Mul M₀'] [SemigroupWithZero M₀] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (mul : ∀ x y, f (x * y) = f x * f y) : SemigroupWithZero M₀' := { hf.mulZeroClass f zero mul, ‹Zero M₀'›, hf.semigroup f mul with } /-- Push forward a `SemigroupWithZero` along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.semigroupWithZero [SemigroupWithZero M₀] [Zero M₀'] [Mul M₀'] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (mul : ∀ x y, f (x * y) = f x * f y) : SemigroupWithZero M₀' := { hf.mulZeroClass f zero mul, ‹Zero M₀'›, hf.semigroup f mul with } end SemigroupWithZero section MonoidWithZero /-- Pull back a `MonoidWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.monoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] [MonoidWithZero M₀] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : MonoidWithZero M₀' := { hf.monoid f one mul npow, hf.mulZeroClass f zero mul with } /-- Push forward a `MonoidWithZero` along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.monoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] [MonoidWithZero M₀] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : MonoidWithZero M₀' := { hf.monoid f one mul npow, hf.mulZeroClass f zero mul with } /-- Pull back a `CommMonoidWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.commMonoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] [CommMonoidWithZero M₀] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CommMonoidWithZero M₀' := { hf.commMonoid f one mul npow, hf.mulZeroClass f zero mul with } /-- Push forward a `CommMonoidWithZero` along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.commMonoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] [CommMonoidWithZero M₀] (f : M₀ → M₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CommMonoidWithZero M₀' := { hf.commMonoid f one mul npow, hf.mulZeroClass f zero mul with } end MonoidWithZero section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] {a b c : M₀} /-- Pull back a `CancelMonoidWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.cancelMonoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CancelMonoidWithZero M₀' := { hf.monoid f one mul npow, hf.mulZeroClass f zero mul with mul_left_cancel_of_ne_zero := fun hx H => hf <| mul_left_cancel₀ ((hf.ne_iff' zero).2 hx) <| by erw [← mul, ← mul, H], mul_right_cancel_of_ne_zero := fun hx H => hf <| mul_right_cancel₀ ((hf.ne_iff' zero).2 hx) <| by erw [← mul, ← mul, H] } end CancelMonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero M₀] {a b c : M₀} /-- Pull back a `CancelCommMonoidWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.cancelCommMonoidWithZero [Zero M₀'] [Mul M₀'] [One M₀'] [Pow M₀' ℕ] (f : M₀' → M₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) : CancelCommMonoidWithZero M₀' := { hf.commMonoidWithZero f zero one mul npow, hf.cancelMonoidWithZero f zero one mul npow with } end CancelCommMonoidWithZero section GroupWithZero variable [GroupWithZero G₀] {a b c g h x : G₀} /-- Pull back a `GroupWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.groupWithZero [Zero G₀'] [Mul G₀'] [One G₀'] [Inv G₀'] [Div G₀'] [Pow G₀' ℕ] [Pow G₀' ℤ] (f : G₀' → G₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : GroupWithZero G₀' := { hf.monoidWithZero f zero one mul npow, hf.divInvMonoid f one mul inv div npow zpow, pullback_nonzero f zero one with inv_zero := hf <| by erw [inv, zero, inv_zero], mul_inv_cancel := fun x hx => hf <| by erw [one, mul, inv, mul_inv_cancel ((hf.ne_iff' zero).2 hx)] } /-- Push forward a `GroupWithZero` along a surjective function. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.groupWithZero [Zero G₀'] [Mul G₀'] [One G₀'] [Inv G₀'] [Div G₀'] [Pow G₀' ℕ] [Pow G₀' ℤ] (h01 : (0 : G₀') ≠ 1) (f : G₀ → G₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : GroupWithZero G₀' := { hf.monoidWithZero f zero one mul npow, hf.divInvMonoid f one mul inv div npow zpow with inv_zero := by erw [← zero, ← inv, inv_zero], mul_inv_cancel := hf.forall.2 fun x hx => by erw [← inv, ← mul, mul_inv_cancel (mt (congr_arg f) fun h ↦ hx (h.trans zero)), one] exists_pair_ne := ⟨0, 1, h01⟩ } end GroupWithZero section CommGroupWithZero variable [CommGroupWithZero G₀] {a b c d : G₀} /-- Pull back a `CommGroupWithZero` along an injective function. See note [reducible non-instances]. -/ protected abbrev Function.Injective.commGroupWithZero [Zero G₀'] [Mul G₀'] [One G₀'] [Inv G₀'] [Div G₀'] [Pow G₀' ℕ] [Pow G₀' ℤ] (f : G₀' → G₀) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : CommGroupWithZero G₀' := { hf.groupWithZero f zero one mul inv div npow zpow, hf.commSemigroup f mul with } /-- Push forward a `CommGroupWithZero` along a surjective function. See note [reducible non-instances]. -/ protected def Function.Surjective.commGroupWithZero [Zero G₀'] [Mul G₀'] [One G₀'] [Inv G₀'] [Div G₀'] [Pow G₀' ℕ] [Pow G₀' ℤ] (h01 : (0 : G₀') ≠ 1) (f : G₀ → G₀') (hf : Surjective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n) : CommGroupWithZero G₀' := { hf.groupWithZero h01 f zero one mul inv div npow zpow, hf.commSemigroup f mul with } end CommGroupWithZero
Algebra\GroupWithZero\Invertible.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Group.Invertible.Basic import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Theorems about invertible elements in a `GroupWithZero` We intentionally keep imports minimal here as this file is used by `Mathlib.Tactic.NormNum`. -/ assert_not_exists DenselyOrdered universe u variable {α : Type u} theorem nonzero_of_invertible [MulZeroOneClass α] (a : α) [Nontrivial α] [Invertible a] : a ≠ 0 := fun ha => zero_ne_one <| calc 0 = ⅟ a * a := by simp [ha] _ = 1 := invOf_mul_self a instance (priority := 100) Invertible.ne_zero [MulZeroOneClass α] [Nontrivial α] (a : α) [Invertible a] : NeZero a := ⟨nonzero_of_invertible a⟩ section MonoidWithZero variable [MonoidWithZero α] /-- A variant of `Ring.inverse_unit`. -/ @[simp] theorem Ring.inverse_invertible (x : α) [Invertible x] : Ring.inverse x = ⅟ x := Ring.inverse_unit (unitOfInvertible _) end MonoidWithZero section GroupWithZero variable [GroupWithZero α] /-- `a⁻¹` is an inverse of `a` if `a ≠ 0` -/ def invertibleOfNonzero {a : α} (h : a ≠ 0) : Invertible a := ⟨a⁻¹, inv_mul_cancel h, mul_inv_cancel h⟩ @[simp] theorem invOf_eq_inv (a : α) [Invertible a] : ⅟ a = a⁻¹ := invOf_eq_right_inv (mul_inv_cancel (nonzero_of_invertible a)) @[simp] theorem inv_mul_cancel_of_invertible (a : α) [Invertible a] : a⁻¹ * a = 1 := inv_mul_cancel (nonzero_of_invertible a) @[simp] theorem mul_inv_cancel_of_invertible (a : α) [Invertible a] : a * a⁻¹ = 1 := mul_inv_cancel (nonzero_of_invertible a) /-- `a` is the inverse of `a⁻¹` -/ def invertibleInv {a : α} [Invertible a] : Invertible a⁻¹ := ⟨a, by simp, by simp⟩ @[simp] theorem div_mul_cancel_of_invertible (a b : α) [Invertible b] : a / b * b = a := div_mul_cancel₀ a (nonzero_of_invertible b) @[simp] theorem mul_div_cancel_of_invertible (a b : α) [Invertible b] : a * b / b = a := mul_div_cancel_right₀ a (nonzero_of_invertible b) @[simp] theorem div_self_of_invertible (a : α) [Invertible a] : a / a = 1 := div_self (nonzero_of_invertible a) /-- `b / a` is the inverse of `a / b` -/ def invertibleDiv (a b : α) [Invertible a] [Invertible b] : Invertible (a / b) := ⟨b / a, by simp [← mul_div_assoc], by simp [← mul_div_assoc]⟩ -- Porting note (#10618): removed `simp` attribute as `simp` can prove it theorem invOf_div (a b : α) [Invertible a] [Invertible b] [Invertible (a / b)] : ⅟ (a / b) = b / a := invOf_eq_right_inv (by simp [← mul_div_assoc]) end GroupWithZero
Algebra\GroupWithZero\NeZero.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Algebra.NeZero /-! # `NeZero 1` in a nontrivial `MulZeroOneClass`. This file exists to minimize the dependencies of `Mathlib.Algebra.GroupWithZero.Defs`, which is a part of the algebraic hierarchy used by basic tactics. -/ assert_not_exists DenselyOrdered universe u variable {M₀ M₀' : Type*} [MulZeroOneClass M₀] [Nontrivial M₀] /-- In a nontrivial monoid with zero, zero and one are different. -/ instance NeZero.one : NeZero (1 : M₀) := ⟨by intro h rcases exists_pair_ne M₀ with ⟨x, y, hx⟩ apply hx calc x = 1 * x := by rw [one_mul] _ = 0 := by rw [h, zero_mul] _ = 1 * y := by rw [h, zero_mul] _ = y := by rw [one_mul]⟩ /-- Pullback a `Nontrivial` instance along a function sending `0` to `0` and `1` to `1`. -/ theorem pullback_nonzero [Zero M₀'] [One M₀'] (f : M₀' → M₀) (zero : f 0 = 0) (one : f 1 = 1) : Nontrivial M₀' := ⟨⟨0, 1, mt (congr_arg f) <| by rw [zero, one] exact zero_ne_one⟩⟩ section GroupWithZero variable {G₀ : Type*} [GroupWithZero G₀] {a : G₀} -- Porting note: used `simpa` to prove `False` in lean3 theorem inv_ne_zero (h : a ≠ 0) : a⁻¹ ≠ 0 := fun a_eq_0 => by have := mul_inv_cancel h simp only [a_eq_0, mul_zero, zero_ne_one] at this @[simp] theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 := calc a⁻¹ * a = a⁻¹ * a * a⁻¹ * a⁻¹⁻¹ := by simp [inv_ne_zero h] _ = a⁻¹ * a⁻¹⁻¹ := by simp [h] _ = 1 := by simp [inv_ne_zero h] end GroupWithZero
Algebra\GroupWithZero\NonZeroDivisors.lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Devon Tuma, Oliver Nash -/ import Mathlib.Algebra.Associated.Basic import Mathlib.Algebra.Group.Action.Opposite import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.GroupWithZero.Opposite /-! # Non-zero divisors and smul-divisors In this file we define the submonoid `nonZeroDivisors` and `nonZeroSMulDivisors` of a `MonoidWithZero`. We also define `nonZeroDivisorsLeft` and `nonZeroDivisorsRight` for non-commutative monoids. ## Notations This file declares the notations: - `R⁰` for the submonoid of non-zero-divisors of `R`, in the locale `nonZeroDivisors`. - `R⁰[M]` for the submonoid of non-zero smul-divisors of `R` with respect to `M`, in the locale `nonZeroSMulDivisors` Use the statement `open scoped nonZeroDivisors nonZeroSMulDivisors` to access this notation in your own code. -/ section variable (M₀ : Type*) [MonoidWithZero M₀] /-- The collection of elements of a `MonoidWithZero` that are not left zero divisors form a `Submonoid`. -/ def nonZeroDivisorsLeft : Submonoid M₀ where carrier := {x | ∀ y, y * x = 0 → y = 0} one_mem' := by simp mul_mem' {x} {y} hx hy := fun z hz ↦ hx _ <| hy _ (mul_assoc z x y ▸ hz) @[simp] lemma mem_nonZeroDivisorsLeft_iff {x : M₀} : x ∈ nonZeroDivisorsLeft M₀ ↔ ∀ y, y * x = 0 → y = 0 := Iff.rfl lemma nmem_nonZeroDivisorsLeft_iff {r : M₀} : r ∉ nonZeroDivisorsLeft M₀ ↔ {s | s * r = 0 ∧ s ≠ 0}.Nonempty := by simpa [mem_nonZeroDivisorsLeft_iff] using Set.nonempty_def.symm /-- The collection of elements of a `MonoidWithZero` that are not right zero divisors form a `Submonoid`. -/ def nonZeroDivisorsRight : Submonoid M₀ where carrier := {x | ∀ y, x * y = 0 → y = 0} one_mem' := by simp mul_mem' := fun {x} {y} hx hy z hz ↦ hy _ (hx _ ((mul_assoc x y z).symm ▸ hz)) @[simp] lemma mem_nonZeroDivisorsRight_iff {x : M₀} : x ∈ nonZeroDivisorsRight M₀ ↔ ∀ y, x * y = 0 → y = 0 := Iff.rfl lemma nmem_nonZeroDivisorsRight_iff {r : M₀} : r ∉ nonZeroDivisorsRight M₀ ↔ {s | r * s = 0 ∧ s ≠ 0}.Nonempty := by simpa [mem_nonZeroDivisorsRight_iff] using Set.nonempty_def.symm lemma nonZeroDivisorsLeft_eq_right (M₀ : Type*) [CommMonoidWithZero M₀] : nonZeroDivisorsLeft M₀ = nonZeroDivisorsRight M₀ := by ext x; simp [mul_comm x] @[simp] lemma coe_nonZeroDivisorsLeft_eq [NoZeroDivisors M₀] [Nontrivial M₀] : nonZeroDivisorsLeft M₀ = {x : M₀ | x ≠ 0} := by ext x simp only [SetLike.mem_coe, mem_nonZeroDivisorsLeft_iff, mul_eq_zero, forall_eq_or_imp, true_and, Set.mem_setOf_eq] refine ⟨fun h ↦ ?_, fun hx y hx' ↦ by contradiction⟩ contrapose! h exact ⟨1, h, one_ne_zero⟩ @[simp] lemma coe_nonZeroDivisorsRight_eq [NoZeroDivisors M₀] [Nontrivial M₀] : nonZeroDivisorsRight M₀ = {x : M₀ | x ≠ 0} := by ext x simp only [SetLike.mem_coe, mem_nonZeroDivisorsRight_iff, mul_eq_zero, Set.mem_setOf_eq] refine ⟨fun h ↦ ?_, fun hx y hx' ↦ by aesop⟩ contrapose! h exact ⟨1, Or.inl h, one_ne_zero⟩ end /-- The submonoid of non-zero-divisors of a `MonoidWithZero` `R`. -/ def nonZeroDivisors (R : Type*) [MonoidWithZero R] : Submonoid R where carrier := { x | ∀ z, z * x = 0 → z = 0 } one_mem' _ hz := by rwa [mul_one] at hz mul_mem' hx₁ hx₂ _ hz := by rw [← mul_assoc] at hz exact hx₁ _ (hx₂ _ hz) /-- The notation for the submonoid of non-zerodivisors. -/ scoped[nonZeroDivisors] notation:9000 R "⁰" => nonZeroDivisors R /-- Let `R` be a monoid with zero and `M` an additive monoid with an `R`-action, then the collection of non-zero smul-divisors forms a submonoid. These elements are also called `M`-regular. -/ def nonZeroSMulDivisors (R : Type*) [MonoidWithZero R] (M : Type _) [Zero M] [MulAction R M] : Submonoid R where carrier := { r | ∀ m : M, r • m = 0 → m = 0} one_mem' m h := (one_smul R m) ▸ h mul_mem' {r₁ r₂} h₁ h₂ m H := h₂ _ <| h₁ _ <| mul_smul r₁ r₂ m ▸ H /-- The notation for the submonoid of non-zero smul-divisors. -/ scoped[nonZeroSMulDivisors] notation:9000 R "⁰[" M "]" => nonZeroSMulDivisors R M section nonZeroDivisors open nonZeroDivisors variable {M M' M₁ R R' F : Type*} [MonoidWithZero M] [MonoidWithZero M'] [CommMonoidWithZero M₁] [Ring R] [CommRing R'] theorem mem_nonZeroDivisors_iff {r : M} : r ∈ M⁰ ↔ ∀ x, x * r = 0 → x = 0 := Iff.rfl lemma nmem_nonZeroDivisors_iff {r : M} : r ∉ M⁰ ↔ {s | s * r = 0 ∧ s ≠ 0}.Nonempty := by simpa [mem_nonZeroDivisors_iff] using Set.nonempty_def.symm theorem mul_right_mem_nonZeroDivisors_eq_zero_iff {x r : M} (hr : r ∈ M⁰) : x * r = 0 ↔ x = 0 := ⟨hr _, by simp (config := { contextual := true })⟩ @[simp] theorem mul_right_coe_nonZeroDivisors_eq_zero_iff {x : M} {c : M⁰} : x * c = 0 ↔ x = 0 := mul_right_mem_nonZeroDivisors_eq_zero_iff c.prop theorem mul_left_mem_nonZeroDivisors_eq_zero_iff {r x : M₁} (hr : r ∈ M₁⁰) : r * x = 0 ↔ x = 0 := by rw [mul_comm, mul_right_mem_nonZeroDivisors_eq_zero_iff hr] @[simp] theorem mul_left_coe_nonZeroDivisors_eq_zero_iff {c : M₁⁰} {x : M₁} : (c : M₁) * x = 0 ↔ x = 0 := mul_left_mem_nonZeroDivisors_eq_zero_iff c.prop theorem mul_cancel_right_mem_nonZeroDivisors {x y r : R} (hr : r ∈ R⁰) : x * r = y * r ↔ x = y := by refine ⟨fun h ↦ ?_, congrArg (· * r)⟩ rw [← sub_eq_zero, ← mul_right_mem_nonZeroDivisors_eq_zero_iff hr, sub_mul, h, sub_self] theorem mul_cancel_right_coe_nonZeroDivisors {x y : R} {c : R⁰} : x * c = y * c ↔ x = y := mul_cancel_right_mem_nonZeroDivisors c.prop @[simp] theorem mul_cancel_left_mem_nonZeroDivisors {x y r : R'} (hr : r ∈ R'⁰) : r * x = r * y ↔ x = y := by simp_rw [mul_comm r, mul_cancel_right_mem_nonZeroDivisors hr] theorem mul_cancel_left_coe_nonZeroDivisors {x y : R'} {c : R'⁰} : (c : R') * x = c * y ↔ x = y := mul_cancel_left_mem_nonZeroDivisors c.prop theorem dvd_cancel_right_mem_nonZeroDivisors {x y r : R'} (hr : r ∈ R'⁰) : x * r ∣ y * r ↔ x ∣ y := ⟨fun ⟨z, _⟩ ↦ ⟨z, by rwa [← mul_cancel_right_mem_nonZeroDivisors hr, mul_assoc, mul_comm z r, ← mul_assoc]⟩, fun ⟨z, h⟩ ↦ ⟨z, by rw [h, mul_assoc, mul_comm z r, ← mul_assoc]⟩⟩ theorem dvd_cancel_right_coe_nonZeroDivisors {x y : R'} {c : R'⁰} : x * c ∣ y * c ↔ x ∣ y := dvd_cancel_right_mem_nonZeroDivisors c.prop theorem dvd_cancel_left_mem_nonZeroDivisors {x y r : R'} (hr : r ∈ R'⁰) : r * x ∣ r * y ↔ x ∣ y := ⟨fun ⟨z, _⟩ ↦ ⟨z, by rwa [← mul_cancel_left_mem_nonZeroDivisors hr, ← mul_assoc]⟩, fun ⟨z, h⟩ ↦ ⟨z, by rw [h, ← mul_assoc]⟩⟩ theorem dvd_cancel_left_coe_nonZeroDivisors {x y : R'} {c : R'⁰} : c * x ∣ c * y ↔ x ∣ y := dvd_cancel_left_mem_nonZeroDivisors c.prop theorem zero_not_mem_nonZeroDivisors [Nontrivial M] : 0 ∉ M⁰ := fun h ↦ one_ne_zero <| h 1 <| mul_zero _ theorem nonZeroDivisors.ne_zero [Nontrivial M] {x} (hx : x ∈ M⁰) : x ≠ 0 := ne_of_mem_of_not_mem hx zero_not_mem_nonZeroDivisors @[simp] theorem nonZeroDivisors.coe_ne_zero [Nontrivial M] (x : M⁰) : (x : M) ≠ 0 := nonZeroDivisors.ne_zero x.2 theorem mul_mem_nonZeroDivisors {a b : M₁} : a * b ∈ M₁⁰ ↔ a ∈ M₁⁰ ∧ b ∈ M₁⁰ := by constructor · intro h constructor <;> intro x h' <;> apply h · rw [← mul_assoc, h', zero_mul] · rw [mul_comm a b, ← mul_assoc, h', zero_mul] · rintro ⟨ha, hb⟩ x hx apply ha apply hb rw [mul_assoc, hx] theorem isUnit_of_mem_nonZeroDivisors {G₀ : Type*} [GroupWithZero G₀] {x : G₀} (hx : x ∈ nonZeroDivisors G₀) : IsUnit x := ⟨⟨x, x⁻¹, mul_inv_cancel (nonZeroDivisors.ne_zero hx), inv_mul_cancel (nonZeroDivisors.ne_zero hx)⟩, rfl⟩ lemma IsUnit.mem_nonZeroDivisors {a : M} (ha : IsUnit a) : a ∈ M⁰ := fun _ h ↦ ha.mul_left_eq_zero.mp h theorem eq_zero_of_ne_zero_of_mul_right_eq_zero [NoZeroDivisors M] {x y : M} (hnx : x ≠ 0) (hxy : y * x = 0) : y = 0 := Or.resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hnx theorem eq_zero_of_ne_zero_of_mul_left_eq_zero [NoZeroDivisors M] {x y : M} (hnx : x ≠ 0) (hxy : x * y = 0) : y = 0 := Or.resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hnx theorem mem_nonZeroDivisors_of_ne_zero [NoZeroDivisors M] {x : M} (hx : x ≠ 0) : x ∈ M⁰ := fun _ ↦ eq_zero_of_ne_zero_of_mul_right_eq_zero hx theorem mem_nonZeroDivisors_iff_ne_zero [NoZeroDivisors M] [Nontrivial M] {x : M} : x ∈ M⁰ ↔ x ≠ 0 := ⟨nonZeroDivisors.ne_zero, mem_nonZeroDivisors_of_ne_zero⟩ variable [FunLike F M M'] theorem map_ne_zero_of_mem_nonZeroDivisors [Nontrivial M] [ZeroHomClass F M M'] (g : F) (hg : Function.Injective (g : M → M')) {x : M} (h : x ∈ M⁰) : g x ≠ 0 := fun h0 ↦ one_ne_zero (h 1 ((one_mul x).symm ▸ hg (h0.trans (map_zero g).symm))) theorem map_mem_nonZeroDivisors [Nontrivial M] [NoZeroDivisors M'] [ZeroHomClass F M M'] (g : F) (hg : Function.Injective g) {x : M} (h : x ∈ M⁰) : g x ∈ M'⁰ := fun _ hz ↦ eq_zero_of_ne_zero_of_mul_right_eq_zero (map_ne_zero_of_mem_nonZeroDivisors g hg h) hz theorem le_nonZeroDivisors_of_noZeroDivisors [NoZeroDivisors M] {S : Submonoid M} (hS : (0 : M) ∉ S) : S ≤ M⁰ := fun _ hx _ hy ↦ Or.recOn (eq_zero_or_eq_zero_of_mul_eq_zero hy) (fun h ↦ h) fun h ↦ absurd (h ▸ hx : (0 : M) ∈ S) hS theorem powers_le_nonZeroDivisors_of_noZeroDivisors [NoZeroDivisors M] {a : M} (ha : a ≠ 0) : Submonoid.powers a ≤ M⁰ := le_nonZeroDivisors_of_noZeroDivisors fun h ↦ absurd (h.recOn fun _ hn ↦ pow_eq_zero hn) ha theorem map_le_nonZeroDivisors_of_injective [NoZeroDivisors M'] [MonoidWithZeroHomClass F M M'] (f : F) (hf : Function.Injective f) {S : Submonoid M} (hS : S ≤ M⁰) : S.map f ≤ M'⁰ := by cases subsingleton_or_nontrivial M · simp [Subsingleton.elim S ⊥] · exact le_nonZeroDivisors_of_noZeroDivisors fun h ↦ let ⟨x, hx, hx0⟩ := h zero_ne_one (hS (hf (hx0.trans (map_zero f).symm) ▸ hx : 0 ∈ S) 1 (mul_zero 1)).symm theorem nonZeroDivisors_le_comap_nonZeroDivisors_of_injective [NoZeroDivisors M'] [MonoidWithZeroHomClass F M M'] (f : F) (hf : Function.Injective f) : M⁰ ≤ M'⁰.comap f := Submonoid.le_comap_of_map_le _ (map_le_nonZeroDivisors_of_injective _ hf le_rfl) /-- In a finite ring, an element is a unit iff it is a non-zero-divisor. -/ lemma isUnit_iff_mem_nonZeroDivisors_of_finite [Finite R] {a : R} : IsUnit a ↔ a ∈ nonZeroDivisors R := by refine ⟨IsUnit.mem_nonZeroDivisors, fun ha ↦ ?_⟩ rw [IsUnit.isUnit_iff_mulRight_bijective, ← Finite.injective_iff_bijective] intro b c hbc rw [← sub_eq_zero, ← sub_mul] at hbc exact sub_eq_zero.mp (ha _ hbc) end nonZeroDivisors section nonZeroSMulDivisors open nonZeroSMulDivisors nonZeroDivisors variable {R M : Type*} [MonoidWithZero R] [Zero M] [MulAction R M] lemma mem_nonZeroSMulDivisors_iff {x : R} : x ∈ R⁰[M] ↔ ∀ (m : M), x • m = 0 → m = 0 := Iff.rfl variable (R) @[simp] lemma unop_nonZeroSMulDivisors_mulOpposite_eq_nonZeroDivisors : (Rᵐᵒᵖ ⁰[R]).unop = R⁰ := rfl /-- The non-zero `•`-divisors with `•` as right multiplication correspond with the non-zero divisors. Note that the `MulOpposite` is needed because we defined `nonZeroDivisors` with multiplication on the right. -/ lemma nonZeroSMulDivisors_mulOpposite_eq_op_nonZeroDivisors : Rᵐᵒᵖ ⁰[R] = R⁰.op := rfl end nonZeroSMulDivisors open scoped nonZeroDivisors variable {M₀} section MonoidWithZero variable [MonoidWithZero M₀] {a b : M₀⁰} /-- The units of the monoid of non-zero divisors of `M₀` are equivalent to the units of `M₀`. -/ @[simps] def unitsNonZeroDivisorsEquiv : M₀⁰ˣ ≃* M₀ˣ where __ := Units.map M₀⁰.subtype invFun u := ⟨⟨u, u.isUnit.mem_nonZeroDivisors⟩, ⟨(u⁻¹ : M₀ˣ), u⁻¹.isUnit.mem_nonZeroDivisors⟩, by simp, by simp⟩ left_inv _ := rfl right_inv _ := rfl @[simp, norm_cast] lemma nonZeroDivisors.associated_coe : Associated (a : M₀) b ↔ Associated a b := unitsNonZeroDivisorsEquiv.symm.exists_congr_left.trans $ by simp [Associated]; norm_cast end MonoidWithZero section CommMonoidWithZero variable {M₀ : Type*} [CommMonoidWithZero M₀] {a : M₀} theorem mk_mem_nonZeroDivisors_associates : Associates.mk a ∈ (Associates M₀)⁰ ↔ a ∈ M₀⁰ := by rw [mem_nonZeroDivisors_iff, mem_nonZeroDivisors_iff, ← not_iff_not] push_neg constructor · rintro ⟨⟨x⟩, hx₁, hx₂⟩ refine ⟨x, ?_, ?_⟩ · rwa [← Associates.mk_eq_zero, ← Associates.mk_mul_mk, ← Associates.quot_mk_eq_mk] · rwa [← Associates.mk_ne_zero, ← Associates.quot_mk_eq_mk] · refine fun ⟨b, hb₁, hb₂⟩ ↦ ⟨Associates.mk b, ?_, by rwa [Associates.mk_ne_zero]⟩ rw [Associates.mk_mul_mk, hb₁, Associates.mk_zero] /-- The non-zero divisors of associates of a monoid with zero `M₀` are isomorphic to the associates of the non-zero divisors of `M₀` under the map `⟨⟦a⟧, _⟩ ↦ ⟦⟨a, _⟩⟧`. -/ def associatesNonZeroDivisorsEquiv : (Associates M₀)⁰ ≃* Associates M₀⁰ where toEquiv := .subtypeQuotientEquivQuotientSubtype (s₂ := Associated.setoid _) (· ∈ nonZeroDivisors _) (by simp [mem_nonZeroDivisors_iff, Quotient.forall, Associates.mk_mul_mk]) (by simp [Associated.setoid]) map_mul' := by simp [Quotient.forall, Associates.mk_mul_mk] @[simp] lemma associatesNonZeroDivisorsEquiv_mk_mk (a : M₀) (ha) : associatesNonZeroDivisorsEquiv ⟨⟦a⟧, ha⟩ = ⟦⟨a, mk_mem_nonZeroDivisors_associates.1 ha⟩⟧ := rfl @[simp] lemma associatesNonZeroDivisorsEquiv_symm_mk_mk (a : M₀) (ha) : associatesNonZeroDivisorsEquiv.symm ⟦⟨a, ha⟩⟧ = ⟨⟦a⟧, mk_mem_nonZeroDivisors_associates.2 ha⟩ := rfl end CommMonoidWithZero
Algebra\GroupWithZero\Opposite.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.GroupWithZero.Defs /-! # Opposites of groups with zero -/ assert_not_exists Ring variable {α : Type*} namespace MulOpposite instance instMulZeroClass [MulZeroClass α] : MulZeroClass αᵐᵒᵖ where zero_mul _ := unop_injective <| mul_zero _ mul_zero _ := unop_injective <| zero_mul _ instance instMulZeroOneClass [MulZeroOneClass α] : MulZeroOneClass αᵐᵒᵖ where __ := instMulOneClass __ := instMulZeroClass instance instSemigroupWithZero [SemigroupWithZero α] : SemigroupWithZero αᵐᵒᵖ where __ := instSemigroup __ := instMulZeroClass instance instMonoidWithZero [MonoidWithZero α] : MonoidWithZero αᵐᵒᵖ where __ := instMonoid __ := instMulZeroOneClass instance instNoZeroDivisors [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors αᵐᵒᵖ where eq_zero_or_eq_zero_of_mul_eq_zero (H : op (_ * _) = op (0 : α)) := Or.casesOn (eq_zero_or_eq_zero_of_mul_eq_zero <| op_injective H) (fun hy => Or.inr <| unop_injective <| hy) fun hx => Or.inl <| unop_injective <| hx end MulOpposite namespace AddOpposite instance instMulZeroClass [MulZeroClass α] : MulZeroClass αᵃᵒᵖ where zero_mul _ := unop_injective <| zero_mul _ mul_zero _ := unop_injective <| mul_zero _ instance instMulZeroOneClass [MulZeroOneClass α] : MulZeroOneClass αᵃᵒᵖ where __ := instMulOneClass __ := instMulZeroClass instance instSemigroupWithZero [SemigroupWithZero α] : SemigroupWithZero αᵃᵒᵖ where __ := instSemigroup __ := instMulZeroClass instance instMonoidWithZero [MonoidWithZero α] : MonoidWithZero αᵃᵒᵖ where __ := instMonoid __ := instMulZeroOneClass instance instNoZeroDivisors [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors αᵃᵒᵖ where eq_zero_or_eq_zero_of_mul_eq_zero (H : op (_ * _) = op (0 : α)) := Or.imp (fun hx => unop_injective hx) (fun hy => unop_injective hy) (@eq_zero_or_eq_zero_of_mul_eq_zero α _ _ _ _ _ <| op_injective H) instance instGroupWithZero [GroupWithZero α] : GroupWithZero αᵃᵒᵖ where __ := instMonoidWithZero __ := instNontrivial __ := instDivInvMonoid mul_inv_cancel _ hx := unop_injective <| mul_inv_cancel <| unop_injective.ne hx inv_zero := unop_injective inv_zero end AddOpposite
Algebra\GroupWithZero\Pi.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Algebra.Group.Hom.Defs import Mathlib.Algebra.Group.Pi.Basic /-! # Pi instances for groups with zero This file defines monoid with zero, group with zero, and related structure instances for pi types. -/ assert_not_exists DenselyOrdered open Function Pi variable {ι : Type*} {α : ι → Type*} namespace Pi section MulZeroClass variable [∀ i, MulZeroClass (α i)] [DecidableEq ι] {i j : ι} {f : ∀ i, α i} instance mulZeroClass : MulZeroClass (∀ i, α i) where zero_mul := by intros; ext; exact zero_mul _ mul_zero := by intros; ext; exact mul_zero _ /-- The multiplicative homomorphism including a single `MulZeroClass` into a dependent family of `MulZeroClass`es, as functions supported at a point. This is the `MulHom` version of `Pi.single`. -/ @[simps] def _root_.MulHom.single (i : ι) : α i →ₙ* ∀ i, α i where toFun := Pi.single i map_mul' := Pi.single_op₂ (fun _ ↦ (· * ·)) (fun _ ↦ zero_mul _) _ lemma single_mul (i : ι) (x y : α i) : single i (x * y) = single i x * single i y := (MulHom.single _).map_mul _ _ lemma single_mul_left_apply (i j : ι) (a : α i) (f : ∀ i, α i) : single i (a * f i) j = single i a j * f j := (apply_single (fun i ↦ (· * f i)) (fun _ ↦ zero_mul _) _ _ _).symm lemma single_mul_right_apply (i j : ι) (f : ∀ i, α i) (a : α i) : single i (f i * a) j = f j * single i a j := (apply_single (f · * ·) (fun _ ↦ mul_zero _) _ _ _).symm lemma single_mul_left (a : α i) : single i (a * f i) = single i a * f := funext fun _ ↦ single_mul_left_apply _ _ _ _ lemma single_mul_right (a : α i) : single i (f i * a) = f * single i a := funext fun _ ↦ single_mul_right_apply _ _ _ _ end MulZeroClass instance mulZeroOneClass [∀ i, MulZeroOneClass (α i)] : MulZeroOneClass (∀ i, α i) where __ := mulZeroClass __ := mulOneClass instance monoidWithZero [∀ i, MonoidWithZero (α i)] : MonoidWithZero (∀ i, α i) where __ := monoid __ := mulZeroClass instance commMonoidWithZero [∀ i, CommMonoidWithZero (α i)] : CommMonoidWithZero (∀ i, α i) where __ := monoidWithZero __ := commMonoid instance semigroupWithZero [∀ i, SemigroupWithZero (α i)] : SemigroupWithZero (∀ i, α i) where __ := semigroup __ := mulZeroClass end Pi
Algebra\GroupWithZero\Prod.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Yaël Dillies -/ import Mathlib.Algebra.Group.Prod import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Products of monoids with zero, groups with zero In this file we define `MonoidWithZero`, `GroupWithZero`, etc... instances for `M₀ × N₀`. ## Main declarations * `mulMonoidWithZeroHom`: Multiplication bundled as a monoid with zero homomorphism. * `divMonoidWithZeroHom`: Division bundled as a monoid with zero homomorphism. -/ assert_not_exists DenselyOrdered variable {M₀ N₀ : Type*} namespace Prod instance instMulZeroClass [MulZeroClass M₀] [MulZeroClass N₀] : MulZeroClass (M₀ × N₀) where zero_mul := by simp [Prod.mul_def] mul_zero := by simp [Prod.mul_def] instance instSemigroupWithZero [SemigroupWithZero M₀] [SemigroupWithZero N₀] : SemigroupWithZero (M₀ × N₀) where zero_mul := by simp [Prod.mul_def] mul_zero := by simp [Prod.mul_def] instance instMulZeroOneClass [MulZeroOneClass M₀] [MulZeroOneClass N₀] : MulZeroOneClass (M₀ × N₀) where zero_mul := by simp [Prod.mul_def] mul_zero := by simp [Prod.mul_def] instance instMonoidWithZero [MonoidWithZero M₀] [MonoidWithZero N₀] : MonoidWithZero (M₀ × N₀) where zero_mul := by simp [Prod.mul_def] mul_zero := by simp [Prod.mul_def] instance instCommMonoidWithZero [CommMonoidWithZero M₀] [CommMonoidWithZero N₀] : CommMonoidWithZero (M₀ × N₀) where zero_mul := by simp [Prod.mul_def] mul_zero := by simp [Prod.mul_def] end Prod /-! ### Multiplication and division as homomorphisms -/ section BundledMulDiv /-- Multiplication as a multiplicative homomorphism with zero. -/ @[simps] def mulMonoidWithZeroHom [CommMonoidWithZero M₀] : M₀ × M₀ →*₀ M₀ where __ := mulMonoidHom map_zero' := mul_zero _ /-- Division as a multiplicative homomorphism with zero. -/ @[simps] def divMonoidWithZeroHom [CommGroupWithZero M₀] : M₀ × M₀ →*₀ M₀ where __ := divMonoidHom map_zero' := zero_div _ end BundledMulDiv
Algebra\GroupWithZero\Semiconj.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Group.Semiconj.Units import Mathlib.Init.Classical /-! # Lemmas about semiconjugate elements in a `GroupWithZero`. -/ assert_not_exists DenselyOrdered variable {α M₀ G₀ M₀' G₀' F F' : Type*} namespace SemiconjBy @[simp] theorem zero_right [MulZeroClass G₀] (a : G₀) : SemiconjBy a 0 0 := by simp only [SemiconjBy, mul_zero, zero_mul] @[simp] theorem zero_left [MulZeroClass G₀] (x y : G₀) : SemiconjBy 0 x y := by simp only [SemiconjBy, mul_zero, zero_mul] variable [GroupWithZero G₀] {a x y x' y' : G₀} @[simp] theorem inv_symm_left_iff₀ : SemiconjBy a⁻¹ x y ↔ SemiconjBy a y x := Classical.by_cases (fun ha : a = 0 => by simp only [ha, inv_zero, SemiconjBy.zero_left]) fun ha => @units_inv_symm_left_iff _ _ (Units.mk0 a ha) _ _ theorem inv_symm_left₀ (h : SemiconjBy a x y) : SemiconjBy a⁻¹ y x := SemiconjBy.inv_symm_left_iff₀.2 h theorem inv_right₀ (h : SemiconjBy a x y) : SemiconjBy a x⁻¹ y⁻¹ := by by_cases ha : a = 0 · simp only [ha, zero_left] by_cases hx : x = 0 · subst x simp only [SemiconjBy, mul_zero, @eq_comm _ _ (y * a), mul_eq_zero] at h simp [h.resolve_right ha] · have := mul_ne_zero ha hx rw [h.eq, mul_ne_zero_iff] at this exact @units_inv_right _ _ _ (Units.mk0 x hx) (Units.mk0 y this.1) h @[simp] theorem inv_right_iff₀ : SemiconjBy a x⁻¹ y⁻¹ ↔ SemiconjBy a x y := ⟨fun h => inv_inv x ▸ inv_inv y ▸ h.inv_right₀, inv_right₀⟩ theorem div_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x / x') (y / y') := by rw [div_eq_mul_inv, div_eq_mul_inv] exact h.mul_right h'.inv_right₀ lemma zpow_right₀ {a x y : G₀} (h : SemiconjBy a x y) : ∀ m : ℤ, SemiconjBy a (x ^ m) (y ^ m) | (n : ℕ) => by simp [h.pow_right n] | .negSucc n => by simp only [zpow_negSucc, (h.pow_right (n + 1)).inv_right₀] end SemiconjBy namespace Commute variable [GroupWithZero G₀] {a b : G₀} lemma zpow_right₀ (h : Commute a b) : ∀ m : ℤ, Commute a (b ^ m) := SemiconjBy.zpow_right₀ h lemma zpow_left₀ (h : Commute a b) (m : ℤ) : Commute (a ^ m) b := (h.symm.zpow_right₀ m).symm lemma zpow_zpow₀ (h : Commute a b) (m n : ℤ) : Commute (a ^ m) (b ^ n) := (h.zpow_left₀ m).zpow_right₀ n lemma zpow_self₀ (a : G₀) (n : ℤ) : Commute (a ^ n) a := (Commute.refl a).zpow_left₀ n lemma self_zpow₀ (a : G₀) (n : ℤ) : Commute a (a ^ n) := (Commute.refl a).zpow_right₀ n lemma zpow_zpow_self₀ (a : G₀) (m n : ℤ) : Commute (a ^ m) (a ^ n) := (Commute.refl a).zpow_zpow₀ m n end Commute
Algebra\GroupWithZero\ULift.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Group.ULift import Mathlib.Algebra.GroupWithZero.InjSurj /-! # `ULift` instances for groups and monoids with zero This file defines instances for group and monoid with zero and related structures on `ULift` types. (Recall `ULift α` is just a "copy" of a type `α` in a higher universe.) -/ universe u variable {α : Type u} namespace ULift instance mulZeroOneClass [MulZeroOneClass α] : MulZeroOneClass (ULift α) := Equiv.ulift.injective.mulZeroOneClass _ rfl rfl (by intros; rfl) instance monoidWithZero [MonoidWithZero α] : MonoidWithZero (ULift α) := Equiv.ulift.injective.monoidWithZero _ rfl rfl (fun _ _ => rfl) fun _ _ => rfl instance commMonoidWithZero [CommMonoidWithZero α] : CommMonoidWithZero (ULift α) := Equiv.ulift.injective.commMonoidWithZero _ rfl rfl (fun _ _ => rfl) fun _ _ => rfl instance groupWithZero [GroupWithZero α] : GroupWithZero (ULift α) := Equiv.ulift.injective.groupWithZero _ rfl rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl instance commGroupWithZero [CommGroupWithZero α] : CommGroupWithZero (ULift α) := Equiv.ulift.injective.commGroupWithZero _ rfl rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl end ULift
Algebra\GroupWithZero\WithZero.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johan Commelin -/ import Mathlib.Algebra.Group.WithOne.Defs import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Data.Nat.Cast.Defs import Mathlib.Data.Option.Basic import Mathlib.Data.Option.NAry /-! # Adjoining a zero to a group This file proves that one can adjoin a new zero element to a group and get a group with zero. ## Main definitions * `WithZero.map'`: the `MonoidWithZero` homomorphism `WithZero α →* WithZero β` induced by a monoid homomorphism `f : α →* β`. -/ assert_not_exists DenselyOrdered namespace WithZero variable {α β γ : Type*} section One variable [One α] instance one : One (WithZero α) where __ := ‹One α› @[simp, norm_cast] lemma coe_one : ((1 : α) : WithZero α) = 1 := rfl end One section Mul variable [Mul α] instance mulZeroClass : MulZeroClass (WithZero α) where mul := Option.map₂ (· * ·) zero_mul := Option.map₂_none_left (· * ·) mul_zero := Option.map₂_none_right (· * ·) @[simp, norm_cast] lemma coe_mul (a b : α) : (↑(a * b) : WithZero α) = a * b := rfl lemma unzero_mul {x y : WithZero α} (hxy : x * y ≠ 0) : unzero hxy = unzero (left_ne_zero_of_mul hxy) * unzero (right_ne_zero_of_mul hxy) := by simp only [← coe_inj, coe_mul, coe_unzero] instance noZeroDivisors : NoZeroDivisors (WithZero α) := ⟨Option.map₂_eq_none_iff.1⟩ end Mul instance semigroupWithZero [Semigroup α] : SemigroupWithZero (WithZero α) where __ := mulZeroClass mul_assoc _ _ _ := Option.map₂_assoc mul_assoc instance commSemigroup [CommSemigroup α] : CommSemigroup (WithZero α) where __ := semigroupWithZero mul_comm _ _ := Option.map₂_comm mul_comm section MulOneClass variable [MulOneClass α] instance mulZeroOneClass [MulOneClass α] : MulZeroOneClass (WithZero α) where __ := mulZeroClass one_mul := Option.map₂_left_identity one_mul mul_one := Option.map₂_right_identity mul_one /-- Coercion as a monoid hom. -/ @[simps apply] def coeMonoidHom : α →* WithZero α where toFun := (↑) map_one' := rfl map_mul' _ _ := rfl section lift variable [MulZeroOneClass β] -- See note [partially-applied ext lemmas] @[ext high] theorem monoidWithZeroHom_ext ⦃f g : WithZero α →*₀ β⦄ (h : f.toMonoidHom.comp coeMonoidHom = g.toMonoidHom.comp coeMonoidHom) : f = g := DFunLike.ext _ _ fun | 0 => (map_zero f).trans (map_zero g).symm | (g : α) => DFunLike.congr_fun h g /-- The (multiplicative) universal property of `WithZero`. -/ @[simps! symm_apply_apply] noncomputable nonrec def lift' : (α →* β) ≃ (WithZero α →*₀ β) where toFun f := { toFun := fun | 0 => 0 | (a : α) => f a map_zero' := rfl map_one' := map_one f map_mul' := fun | 0, _ => (zero_mul _).symm | (_ : α), 0 => (mul_zero _).symm | (_ : α), (_ : α) => map_mul f _ _ } invFun F := F.toMonoidHom.comp coeMonoidHom left_inv _ := rfl right_inv _ := monoidWithZeroHom_ext rfl lemma lift'_zero (f : α →* β) : lift' f (0 : WithZero α) = 0 := rfl @[simp] lemma lift'_coe (f : α →* β) (x : α) : lift' f (x : WithZero α) = f x := rfl lemma lift'_unique (f : WithZero α →*₀ β) : f = lift' (f.toMonoidHom.comp coeMonoidHom) := (lift'.apply_symm_apply f).symm end lift variable [MulOneClass β] [MulOneClass γ] /-- The `MonoidWithZero` homomorphism `WithZero α →* WithZero β` induced by a monoid homomorphism `f : α →* β`. -/ noncomputable def map' (f : α →* β) : WithZero α →*₀ WithZero β := lift' (coeMonoidHom.comp f) lemma map'_zero (f : α →* β) : map' f 0 = 0 := rfl @[simp] lemma map'_coe (f : α →* β) (x : α) : map' f (x : WithZero α) = f x := rfl @[simp] lemma map'_id : map' (MonoidHom.id β) = MonoidHom.id (WithZero β) := by ext x; induction x <;> rfl lemma map'_map' (f : α →* β) (g : β →* γ) (x) : map' g (map' f x) = map' (g.comp f) x := by induction x <;> rfl @[simp] lemma map'_comp (f : α →* β) (g : β →* γ) : map' (g.comp f) = (map' g).comp (map' f) := MonoidWithZeroHom.ext fun x => (map'_map' f g x).symm end MulOneClass section Pow variable [One α] [Pow α ℕ] instance pow : Pow (WithZero α) ℕ where pow x n := match x, n with | none, 0 => 1 | none, _ + 1 => 0 | some x, n => ↑(x ^ n) @[simp, norm_cast] lemma coe_pow (a : α) (n : ℕ) : (↑(a ^ n) : WithZero α) = a ^ n := rfl end Pow instance monoidWithZero [Monoid α] : MonoidWithZero (WithZero α) where __ := mulZeroOneClass __ := semigroupWithZero npow n a := a ^ n npow_zero a := match a with | none => rfl | some a => congr_arg some (pow_zero _) npow_succ n a := match a with | none => by change 0 ^ (n + 1) = 0 ^ n * 0; simp only [mul_zero]; rfl | some a => congr_arg some <| pow_succ _ _ instance commMonoidWithZero [CommMonoid α] : CommMonoidWithZero (WithZero α) := { WithZero.monoidWithZero, WithZero.commSemigroup with } section Inv variable [Inv α] /-- Extend the inverse operation on `α` to `WithZero α` by sending `0` to `0`. -/ instance inv : Inv (WithZero α) where inv a := Option.map (·⁻¹) a @[simp, norm_cast] lemma coe_inv (a : α) : ((a⁻¹ : α) : WithZero α) = (↑a)⁻¹ := rfl @[simp] protected lemma inv_zero : (0 : WithZero α)⁻¹ = 0 := rfl end Inv instance invOneClass [InvOneClass α] : InvOneClass (WithZero α) where inv_one := show ((1⁻¹ : α) : WithZero α) = 1 by simp section Div variable [Div α] instance div : Div (WithZero α) where div := Option.map₂ (· / ·) @[norm_cast] lemma coe_div (a b : α) : ↑(a / b : α) = (a / b : WithZero α) := rfl end Div section ZPow variable [One α] [Pow α ℤ] instance : Pow (WithZero α) ℤ where pow a n := match a, n with | none, Int.ofNat 0 => 1 | none, Int.ofNat (Nat.succ _) => 0 | none, Int.negSucc _ => 0 | some x, n => ↑(x ^ n) @[simp, norm_cast] lemma coe_zpow (a : α) (n : ℤ) : ↑(a ^ n) = (↑a : WithZero α) ^ n := rfl end ZPow instance divInvMonoid [DivInvMonoid α] : DivInvMonoid (WithZero α) where __ := monoidWithZero div_eq_mul_inv a b := match a, b with | none, _ => rfl | some _, none => rfl | some a, some b => congr_arg some (div_eq_mul_inv a b) zpow n a := a ^ n zpow_zero' a := match a with | none => rfl | some a => congr_arg some (zpow_zero _) zpow_succ' n a := match a with | none => by change 0 ^ _ = 0 ^ _ * 0; simp only [mul_zero]; rfl | some a => congr_arg some (DivInvMonoid.zpow_succ' _ _) zpow_neg' n a := match a with | none => rfl | some a => congr_arg some (DivInvMonoid.zpow_neg' _ _) instance divInvOneMonoid [DivInvOneMonoid α] : DivInvOneMonoid (WithZero α) where __ := divInvMonoid __ := invOneClass instance involutiveInv [InvolutiveInv α] : InvolutiveInv (WithZero α) where inv_inv a := (Option.map_map _ _ _).trans <| by simp [Function.comp] instance divisionMonoid [DivisionMonoid α] : DivisionMonoid (WithZero α) where __ := divInvMonoid __ := involutiveInv mul_inv_rev a b := match a, b with | none, none => rfl | none, some b => rfl | some a, none => rfl | some a, some b => congr_arg some (mul_inv_rev _ _) inv_eq_of_mul a b := match a, b with | none, none => fun _ ↦ rfl | none, some b => fun _ ↦ by contradiction | some a, none => fun _ ↦ by contradiction | some a, some b => fun h ↦ congr_arg some <| inv_eq_of_mul_eq_one_right <| Option.some_injective _ h instance divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (WithZero α) where __ := divisionMonoid __ := commSemigroup section Group variable [Group α] /-- If `α` is a group then `WithZero α` is a group with zero. -/ instance groupWithZero : GroupWithZero (WithZero α) where __ := monoidWithZero __ := divInvMonoid __ := nontrivial inv_zero := WithZero.inv_zero mul_inv_cancel a ha := by lift a to α using ha; norm_cast; apply mul_right_inv /-- Any group is isomorphic to the units of itself adjoined with `0`. -/ def unitsWithZeroEquiv : (WithZero α)ˣ ≃* α where toFun a := unzero a.ne_zero invFun a := Units.mk0 a coe_ne_zero left_inv _ := Units.ext <| by simp only [coe_unzero, Units.mk0_val] right_inv _ := rfl map_mul' _ _ := coe_inj.mp <| by simp only [Units.val_mul, coe_unzero, coe_mul] end Group instance commGroupWithZero [CommGroup α] : CommGroupWithZero (WithZero α) := { WithZero.groupWithZero, WithZero.commMonoidWithZero with } instance addMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (WithZero α) where natCast n := if n = 0 then 0 else (n : α) natCast_zero := rfl natCast_succ n := by cases n with | zero => show (((1 : ℕ) : α) : WithZero α) = 0 + 1; · rw [Nat.cast_one, coe_one, zero_add] | succ n => show (((n + 2 : ℕ) : α) : WithZero α) = ((n + 1 : ℕ) : α) + 1 rw [Nat.cast_succ, coe_add, coe_one] end WithZero
Algebra\GroupWithZero\Action\Defs.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yury Kudryashov -/ import Mathlib.Algebra.Group.Action.Defs import Mathlib.Algebra.Group.Hom.Defs import Mathlib.Algebra.Group.TypeTags import Mathlib.Algebra.Opposites import Mathlib.Logic.Embedding.Basic /-! # Definitions of group actions This file defines a hierarchy of group action type-classes on top of the previously defined notation classes `SMul` and its additive version `VAdd`: * `MulAction M α` and its additive version `AddAction G P` are typeclasses used for actions of multiplicative and additive monoids and groups; they extend notation classes `SMul` and `VAdd` that are defined in `Algebra.Group.Defs`; * `DistribMulAction M A` is a typeclass for an action of a multiplicative monoid on an additive monoid such that `a • (b + c) = a • b + a • c` and `a • 0 = 0`. The hierarchy is extended further by `Module`, defined elsewhere. Also provided are typeclasses for faithful and transitive actions, and typeclasses regarding the interaction of different group actions, * `SMulCommClass M N α` and its additive version `VAddCommClass M N α`; * `IsScalarTower M N α` and its additive version `VAddAssocClass M N α`; * `IsCentralScalar M α` and its additive version `IsCentralVAdd M N α`. ## Notation - `a • b` is used as notation for `SMul.smul a b`. - `a +ᵥ b` is used as notation for `VAdd.vadd a b`. ## Implementation details This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles. More sophisticated lemmas belong in `GroupTheory.GroupAction`. ## Tags group action -/ variable {M N G A B α β γ δ : Type*} open Function (Injective Surjective) /-- Typeclass for scalar multiplication that preserves `0` on the right. -/ class SMulZeroClass (M A : Type*) [Zero A] extends SMul M A where /-- Multiplying `0` by a scalar gives `0` -/ smul_zero : ∀ a : M, a • (0 : A) = 0 section smul_zero variable [Zero A] [SMulZeroClass M A] @[simp] theorem smul_zero (a : M) : a • (0 : A) = 0 := SMulZeroClass.smul_zero _ lemma smul_ite_zero (p : Prop) [Decidable p] (a : M) (b : A) : (a • if p then b else 0) = if p then a • b else 0 := by split_ifs <;> simp lemma smul_eq_zero_of_right (a : M) {b : A} (h : b = 0) : a • b = 0 := h.symm ▸ smul_zero a lemma right_ne_zero_of_smul {a : M} {b : A} : a • b ≠ 0 → b ≠ 0 := mt <| smul_eq_zero_of_right a /-- Pullback a zero-preserving scalar multiplication along an injective zero-preserving map. See note [reducible non-instances]. -/ protected abbrev Function.Injective.smulZeroClass [Zero B] [SMul M B] (f : ZeroHom B A) (hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : SMulZeroClass M B where smul := (· • ·) smul_zero c := hf <| by simp only [smul, map_zero, smul_zero] /-- Pushforward a zero-preserving scalar multiplication along a zero-preserving map. See note [reducible non-instances]. -/ protected abbrev ZeroHom.smulZeroClass [Zero B] [SMul M B] (f : ZeroHom A B) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : SMulZeroClass M B where -- Porting note: `simp` no longer works here. smul_zero c := by rw [← map_zero f, ← smul, smul_zero] /-- Push forward the multiplication of `R` on `M` along a compatible surjective map `f : R → S`. See also `Function.Surjective.distribMulActionLeft`. -/ abbrev Function.Surjective.smulZeroClassLeft {R S M : Type*} [Zero M] [SMulZeroClass R M] [SMul S M] (f : R → S) (hf : Function.Surjective f) (hsmul : ∀ (c) (x : M), f c • x = c • x) : SMulZeroClass S M where smul := (· • ·) smul_zero := hf.forall.mpr fun c => by rw [hsmul, smul_zero] variable (A) /-- Compose a `SMulZeroClass` with a function, with scalar multiplication `f r' • m`. See note [reducible non-instances]. -/ abbrev SMulZeroClass.compFun (f : N → M) : SMulZeroClass N A where smul := SMul.comp.smul f smul_zero x := smul_zero (f x) /-- Each element of the scalars defines a zero-preserving map. -/ @[simps] def SMulZeroClass.toZeroHom (x : M) : ZeroHom A A where toFun := (x • ·) map_zero' := smul_zero x end smul_zero /-- Typeclass for scalar multiplication that preserves `0` and `+` on the right. This is exactly `DistribMulAction` without the `MulAction` part. -/ @[ext] class DistribSMul (M A : Type*) [AddZeroClass A] extends SMulZeroClass M A where /-- Scalar multiplication distributes across addition -/ smul_add : ∀ (a : M) (x y : A), a • (x + y) = a • x + a • y section DistribSMul variable [AddZeroClass A] [DistribSMul M A] theorem smul_add (a : M) (b₁ b₂ : A) : a • (b₁ + b₂) = a • b₁ + a • b₂ := DistribSMul.smul_add _ _ _ instance AddMonoidHom.smulZeroClass [AddZeroClass B] : SMulZeroClass M (B →+ A) where smul r f := { toFun := fun a => r • (f a) map_zero' := by simp only [map_zero, smul_zero] map_add' := fun x y => by simp only [map_add, smul_add] } smul_zero r := ext fun _ => smul_zero _ /-- Pullback a distributive scalar multiplication along an injective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Injective.distribSMul [AddZeroClass B] [SMul M B] (f : B →+ A) (hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : DistribSMul M B := { hf.smulZeroClass f.toZeroHom smul with smul_add := fun c x y => hf <| by simp only [smul, map_add, smul_add] } /-- Pushforward a distributive scalar multiplication along a surjective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.distribSMul [AddZeroClass B] [SMul M B] (f : A →+ B) (hf : Surjective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : DistribSMul M B := { f.toZeroHom.smulZeroClass smul with smul_add := fun c x y => by rcases hf x with ⟨x, rfl⟩ rcases hf y with ⟨y, rfl⟩ simp only [smul_add, ← smul, ← map_add] } /-- Push forward the multiplication of `R` on `M` along a compatible surjective map `f : R → S`. See also `Function.Surjective.distribMulActionLeft`. -/ abbrev Function.Surjective.distribSMulLeft {R S M : Type*} [AddZeroClass M] [DistribSMul R M] [SMul S M] (f : R → S) (hf : Function.Surjective f) (hsmul : ∀ (c) (x : M), f c • x = c • x) : DistribSMul S M := { hf.smulZeroClassLeft f hsmul with smul_add := hf.forall.mpr fun c x y => by simp only [hsmul, smul_add] } variable (A) /-- Compose a `DistribSMul` with a function, with scalar multiplication `f r' • m`. See note [reducible non-instances]. -/ abbrev DistribSMul.compFun (f : N → M) : DistribSMul N A := { SMulZeroClass.compFun A f with smul_add := fun x => smul_add (f x) } /-- Each element of the scalars defines an additive monoid homomorphism. -/ @[simps] def DistribSMul.toAddMonoidHom (x : M) : A →+ A := { SMulZeroClass.toZeroHom A x with toFun := (· • ·) x, map_add' := smul_add x } end DistribSMul /-- Typeclass for multiplicative actions on additive structures. This generalizes group modules. -/ @[ext] class DistribMulAction (M A : Type*) [Monoid M] [AddMonoid A] extends MulAction M A where /-- Multiplying `0` by a scalar gives `0` -/ smul_zero : ∀ a : M, a • (0 : A) = 0 /-- Scalar multiplication distributes across addition -/ smul_add : ∀ (a : M) (x y : A), a • (x + y) = a • x + a • y section variable [Monoid M] [AddMonoid A] [DistribMulAction M A] -- See note [lower instance priority] instance (priority := 100) DistribMulAction.toDistribSMul : DistribSMul M A := { ‹DistribMulAction M A› with } -- Porting note: this probably is no longer relevant. /-! Since Lean 3 does not have definitional eta for structures, we have to make sure that the definition of `DistribMulAction.toDistribSMul` was done correctly, and the two paths from `DistribMulAction` to `SMul` are indeed definitionally equal. -/ example : (DistribMulAction.toMulAction.toSMul : SMul M A) = DistribMulAction.toDistribSMul.toSMul := rfl /-- Pullback a distributive multiplicative action along an injective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Injective.distribMulAction [AddMonoid B] [SMul M B] (f : B →+ A) (hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : DistribMulAction M B := { hf.distribSMul f smul, hf.mulAction f smul with } /-- Pushforward a distributive multiplicative action along a surjective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.distribMulAction [AddMonoid B] [SMul M B] (f : A →+ B) (hf : Surjective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : DistribMulAction M B := { hf.distribSMul f smul, hf.mulAction f smul with } /-- Push forward the action of `R` on `M` along a compatible surjective map `f : R →* S`. See also `Function.Surjective.mulActionLeft` and `Function.Surjective.moduleLeft`. -/ abbrev Function.Surjective.distribMulActionLeft {R S M : Type*} [Monoid R] [AddMonoid M] [DistribMulAction R M] [Monoid S] [SMul S M] (f : R →* S) (hf : Function.Surjective f) (hsmul : ∀ (c) (x : M), f c • x = c • x) : DistribMulAction S M := { hf.distribSMulLeft f hsmul, hf.mulActionLeft f hsmul with } variable (A) /-- Compose a `DistribMulAction` with a `MonoidHom`, with action `f r' • m`. See note [reducible non-instances]. -/ abbrev DistribMulAction.compHom [Monoid N] (f : N →* M) : DistribMulAction N A := { DistribSMul.compFun A f, MulAction.compHom A f with } /-- Each element of the monoid defines an additive monoid homomorphism. -/ @[simps!] def DistribMulAction.toAddMonoidHom (x : M) : A →+ A := DistribSMul.toAddMonoidHom A x variable (M) /-- Each element of the monoid defines an additive monoid homomorphism. -/ @[simps] def DistribMulAction.toAddMonoidEnd : M →* AddMonoid.End A where toFun := DistribMulAction.toAddMonoidHom A map_one' := AddMonoidHom.ext <| one_smul M map_mul' x y := AddMonoidHom.ext <| mul_smul x y instance AddMonoid.nat_smulCommClass : SMulCommClass ℕ M A where smul_comm n x y := ((DistribMulAction.toAddMonoidHom A x).map_nsmul y n).symm -- `SMulCommClass.symm` is not registered as an instance, as it would cause a loop instance AddMonoid.nat_smulCommClass' : SMulCommClass M ℕ A := SMulCommClass.symm _ _ _ end section variable [Monoid M] [AddGroup A] [DistribMulAction M A] instance AddGroup.int_smulCommClass : SMulCommClass ℤ M A where smul_comm n x y := ((DistribMulAction.toAddMonoidHom A x).map_zsmul y n).symm -- `SMulCommClass.symm` is not registered as an instance, as it would cause a loop instance AddGroup.int_smulCommClass' : SMulCommClass M ℤ A := SMulCommClass.symm _ _ _ @[simp] theorem smul_neg (r : M) (x : A) : r • -x = -(r • x) := eq_neg_of_add_eq_zero_left <| by rw [← smul_add, neg_add_self, smul_zero] theorem smul_sub (r : M) (x y : A) : r • (x - y) = r • x - r • y := by rw [sub_eq_add_neg, sub_eq_add_neg, smul_add, smul_neg] end /-- Typeclass for multiplicative actions on multiplicative structures. This generalizes conjugation actions. -/ @[ext] class MulDistribMulAction (M : Type*) (A : Type*) [Monoid M] [Monoid A] extends MulAction M A where /-- Distributivity of `•` across `*` -/ smul_mul : ∀ (r : M) (x y : A), r • (x * y) = r • x * r • y /-- Multiplying `1` by a scalar gives `1` -/ smul_one : ∀ r : M, r • (1 : A) = 1 export MulDistribMulAction (smul_one) section variable [Monoid M] [Monoid A] [MulDistribMulAction M A] theorem smul_mul' (a : M) (b₁ b₂ : A) : a • (b₁ * b₂) = a • b₁ * a • b₂ := MulDistribMulAction.smul_mul _ _ _ /-- Pullback a multiplicative distributive multiplicative action along an injective monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Injective.mulDistribMulAction [Monoid B] [SMul M B] (f : B →* A) (hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : MulDistribMulAction M B := { hf.mulAction f smul with smul_mul := fun c x y => hf <| by simp only [smul, f.map_mul, smul_mul'], smul_one := fun c => hf <| by simp only [smul, f.map_one, smul_one] } /-- Pushforward a multiplicative distributive multiplicative action along a surjective monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.mulDistribMulAction [Monoid B] [SMul M B] (f : A →* B) (hf : Surjective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : MulDistribMulAction M B := { hf.mulAction f smul with smul_mul := fun c x y => by rcases hf x with ⟨x, rfl⟩ rcases hf y with ⟨y, rfl⟩ simp only [smul_mul', ← smul, ← f.map_mul], smul_one := fun c => by rw [← f.map_one, ← smul, smul_one] } variable (A) /-- Compose a `MulDistribMulAction` with a `MonoidHom`, with action `f r' • m`. See note [reducible non-instances]. -/ abbrev MulDistribMulAction.compHom [Monoid N] (f : N →* M) : MulDistribMulAction N A := { MulAction.compHom A f with smul_one := fun x => smul_one (f x), smul_mul := fun x => smul_mul' (f x) } /-- Scalar multiplication by `r` as a `MonoidHom`. -/ def MulDistribMulAction.toMonoidHom (r : M) : A →* A where toFun := (r • ·) map_one' := smul_one r map_mul' := smul_mul' r variable {A} @[simp] theorem MulDistribMulAction.toMonoidHom_apply (r : M) (x : A) : MulDistribMulAction.toMonoidHom A r x = r • x := rfl @[simp] lemma smul_pow' (r : M) (x : A) (n : ℕ) : r • x ^ n = (r • x) ^ n := (MulDistribMulAction.toMonoidHom _ _).map_pow _ _ variable (M A) /-- Each element of the monoid defines a monoid homomorphism. -/ @[simps] def MulDistribMulAction.toMonoidEnd : M →* Monoid.End A where toFun := MulDistribMulAction.toMonoidHom A map_one' := MonoidHom.ext <| one_smul M map_mul' x y := MonoidHom.ext <| mul_smul x y end section variable [Monoid M] [Group A] [MulDistribMulAction M A] @[simp] theorem smul_inv' (r : M) (x : A) : r • x⁻¹ = (r • x)⁻¹ := (MulDistribMulAction.toMonoidHom A r).map_inv x theorem smul_div' (r : M) (x y : A) : r • (x / y) = r • x / r • y := map_div (MulDistribMulAction.toMonoidHom A r) x y end /-- The tautological action by `AddMonoid.End α` on `α`. This generalizes `Function.End.applyMulAction`. -/ instance AddMonoid.End.applyDistribMulAction [AddMonoid α] : DistribMulAction (AddMonoid.End α) α where smul := (· <| ·) smul_zero := AddMonoidHom.map_zero smul_add := AddMonoidHom.map_add one_smul _ := rfl mul_smul _ _ _ := rfl @[simp] theorem AddMonoid.End.smul_def [AddMonoid α] (f : AddMonoid.End α) (a : α) : f • a = f a := rfl /-- `AddMonoid.End.applyDistribMulAction` is faithful. -/ instance AddMonoid.End.applyFaithfulSMul [AddMonoid α] : FaithfulSMul (AddMonoid.End α) α := ⟨fun {_ _ h} => AddMonoidHom.ext h⟩
Algebra\GroupWithZero\Action\Opposite.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.Opposite import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.NeZero /-! # Scalar actions on and by `Mᵐᵒᵖ` This file defines the actions on the opposite type `SMul R Mᵐᵒᵖ`, and actions by the opposite type, `SMul Rᵐᵒᵖ M`. Note that `MulOpposite.smul` is provided in an earlier file as it is needed to provide the `AddMonoid.nsmul` and `AddCommGroup.zsmul` fields. ## Notation With `open scoped RightActions`, this provides: * `r •> m` as an alias for `r • m` * `m <• r` as an alias for `MulOpposite.op r • m` * `v +ᵥ> p` as an alias for `v +ᵥ p` * `p <+ᵥ v` as an alias for `AddOpposite.op v +ᵥ p` -/ variable {R M N α : Type*} /-! ### Actions _on_ the opposite type Actions on the opposite type just act on the underlying type. -/ namespace MulOpposite instance instDistribMulAction [Monoid M] [AddMonoid α] [DistribMulAction M α] : DistribMulAction M αᵐᵒᵖ where smul_add _ _ _ := unop_injective <| smul_add _ _ _ smul_zero _ := unop_injective <| smul_zero _ instance instMulDistribMulAction [Monoid M] [Monoid α] [MulDistribMulAction M α] : MulDistribMulAction M αᵐᵒᵖ where smul_mul _ _ _ := unop_injective <| smul_mul' _ _ _ smul_one _ := unop_injective <| smul_one _ end MulOpposite /-! ### Actions _by_ the opposite type (right actions) In `Mul.toSMul` in another file, we define the left action `a₁ • a₂ = a₁ * a₂`. For the multiplicative opposite, we define `MulOpposite.op a₁ • a₂ = a₂ * a₁`, with the multiplication reversed. -/ open MulOpposite /-- `Monoid.toOppositeMulAction` is faithful on nontrivial cancellative monoids with zero. -/ instance CancelMonoidWithZero.toFaithfulSMul_opposite [CancelMonoidWithZero α] [Nontrivial α] : FaithfulSMul αᵐᵒᵖ α := ⟨fun h => unop_injective <| mul_left_cancel₀ one_ne_zero (h 1)⟩
Algebra\GroupWithZero\Action\Pi.lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Patrick Massot -/ import Mathlib.Algebra.Group.Action.Pi import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Tactic.Common /-! # Pi instances for multiplicative actions with zero This file defines instances for `MulActionWithZero` and related structures on `Pi` types. ## See also * `Algebra.GroupWithZero.Action.Opposite` * `Algebra.GroupWithZero.Action.Prod` * `Algebra.GroupWithZero.Action.Units` -/ universe u v w variable {I : Type u} -- The indexing type variable {f : I → Type v} -- The family of types already equipped with instances variable (x y : ∀ i, f i) (i : I) namespace Pi instance smulZeroClass (α) {n : ∀ i, Zero <| f i} [∀ i, SMulZeroClass α <| f i] : @SMulZeroClass α (∀ i : I, f i) (@Pi.instZero I f n) where smul_zero _ := funext fun _ => smul_zero _ instance smulZeroClass' {g : I → Type*} {n : ∀ i, Zero <| g i} [∀ i, SMulZeroClass (f i) (g i)] : @SMulZeroClass (∀ i, f i) (∀ i : I, g i) (@Pi.instZero I g n) where smul_zero := by intros; ext x; exact smul_zero _ instance distribSMul (α) {n : ∀ i, AddZeroClass <| f i} [∀ i, DistribSMul α <| f i] : @DistribSMul α (∀ i : I, f i) (@Pi.addZeroClass I f n) where smul_zero _ := funext fun _ => smul_zero _ smul_add _ _ _ := funext fun _ => smul_add _ _ _ instance distribSMul' {g : I → Type*} {n : ∀ i, AddZeroClass <| g i} [∀ i, DistribSMul (f i) (g i)] : @DistribSMul (∀ i, f i) (∀ i : I, g i) (@Pi.addZeroClass I g n) where smul_zero := by intros; ext x; exact smul_zero _ smul_add := by intros; ext x; exact smul_add _ _ _ instance distribMulAction (α) {m : Monoid α} {n : ∀ i, AddMonoid <| f i} [∀ i, DistribMulAction α <| f i] : @DistribMulAction α (∀ i : I, f i) m (@Pi.addMonoid I f n) := { Pi.mulAction _, Pi.distribSMul _ with } instance distribMulAction' {g : I → Type*} {m : ∀ i, Monoid (f i)} {n : ∀ i, AddMonoid <| g i} [∀ i, DistribMulAction (f i) (g i)] : @DistribMulAction (∀ i, f i) (∀ i : I, g i) (@Pi.monoid I f m) (@Pi.addMonoid I g n) := { Pi.mulAction', Pi.distribSMul' with } theorem single_smul {α} [Monoid α] [∀ i, AddMonoid <| f i] [∀ i, DistribMulAction α <| f i] [DecidableEq I] (i : I) (r : α) (x : f i) : single i (r • x) = r • single i x := single_op (fun i : I => (r • · : f i → f i)) (fun _ => smul_zero _) _ _ -- Porting note: Lean4 cannot infer the non-dependent function `f := fun _ => β` /-- A version of `Pi.single_smul` for non-dependent functions. It is useful in cases where Lean fails to apply `Pi.single_smul`. -/ theorem single_smul' {α β} [Monoid α] [AddMonoid β] [DistribMulAction α β] [DecidableEq I] (i : I) (r : α) (x : β) : single (f := fun _ => β) i (r • x) = r • single (f := fun _ => β) i x := single_smul (f := fun _ => β) i r x theorem single_smul₀ {g : I → Type*} [∀ i, MonoidWithZero (f i)] [∀ i, AddMonoid (g i)] [∀ i, DistribMulAction (f i) (g i)] [DecidableEq I] (i : I) (r : f i) (x : g i) : single i (r • x) = single i r • single i x := single_op₂ (fun i : I => ((· • ·) : f i → g i → g i)) (fun _ => smul_zero _) _ _ _ instance mulDistribMulAction (α) {m : Monoid α} {n : ∀ i, Monoid <| f i} [∀ i, MulDistribMulAction α <| f i] : @MulDistribMulAction α (∀ i : I, f i) m (@Pi.monoid I f n) := { Pi.mulAction _ with smul_one := fun _ => funext fun _ => smul_one _ smul_mul := fun _ _ _ => funext fun _ => smul_mul' _ _ _ } instance mulDistribMulAction' {g : I → Type*} {m : ∀ i, Monoid (f i)} {n : ∀ i, Monoid <| g i} [∀ i, MulDistribMulAction (f i) (g i)] : @MulDistribMulAction (∀ i, f i) (∀ i : I, g i) (@Pi.monoid I f m) (@Pi.monoid I g n) where smul_mul := by intros ext x apply smul_mul' smul_one := by intros ext x apply smul_one end Pi
Algebra\GroupWithZero\Action\Prod.lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Patrick Massot, Eric Wieser -/ import Mathlib.Algebra.Group.Action.Prod import Mathlib.Algebra.GroupWithZero.Action.Defs /-! # Prod instances for multiplicative actions with zero This file defines instances for `MulActionWithZero` and related structures on `α × β` ## See also * `Algebra.GroupWithZero.Action.Opposite` * `Algebra.GroupWithZero.Action.Pi` * `Algebra.GroupWithZero.Action.Units` -/ assert_not_exists MonoidWithZero variable {M N α β : Type*} namespace Prod section variable [SMul M α] [SMul M β] [SMul N α] [SMul N β] (a : M) (x : α × β) theorem smul_zero_mk {α : Type*} [Monoid M] [AddMonoid α] [DistribMulAction M α] (a : M) (c : β) : a • ((0 : α), c) = (0, a • c) := by rw [Prod.smul_mk, smul_zero] theorem smul_mk_zero {β : Type*} [Monoid M] [AddMonoid β] [DistribMulAction M β] (a : M) (b : α) : a • (b, (0 : β)) = (a • b, 0) := by rw [Prod.smul_mk, smul_zero] end instance smulZeroClass {R M N : Type*} [Zero M] [Zero N] [SMulZeroClass R M] [SMulZeroClass R N] : SMulZeroClass R (M × N) where smul_zero _ := mk.inj_iff.mpr ⟨smul_zero _, smul_zero _⟩ instance distribSMul {R M N : Type*} [AddZeroClass M] [AddZeroClass N] [DistribSMul R M] [DistribSMul R N] : DistribSMul R (M × N) where smul_add _ _ _ := mk.inj_iff.mpr ⟨smul_add _ _ _, smul_add _ _ _⟩ instance distribMulAction {R : Type*} [Monoid R] [AddMonoid M] [AddMonoid N] [DistribMulAction R M] [DistribMulAction R N] : DistribMulAction R (M × N) := { Prod.mulAction, Prod.distribSMul with } instance mulDistribMulAction {R : Type*} [Monoid R] [Monoid M] [Monoid N] [MulDistribMulAction R M] [MulDistribMulAction R N] : MulDistribMulAction R (M × N) where smul_mul _ _ _ := mk.inj_iff.mpr ⟨smul_mul' _ _ _, smul_mul' _ _ _⟩ smul_one _ := mk.inj_iff.mpr ⟨smul_one _, smul_one _⟩ end Prod /-! ### Scalar multiplication as a homomorphism -/ section Action_by_Prod variable (M N α) [Monoid M] [Monoid N] [AddMonoid α] /-- Construct a `DistribMulAction` by a product monoid from `DistribMulAction`s by the factors. -/ abbrev DistribMulAction.prodOfSMulCommClass [DistribMulAction M α] [DistribMulAction N α] [SMulCommClass M N α] : DistribMulAction (M × N) α where __ := MulAction.prodOfSMulCommClass M N α smul_zero mn := by change mn.1 • mn.2 • 0 = (0 : α); rw [smul_zero, smul_zero] smul_add mn a a' := by change mn.1 • mn.2 • _ = (_ : α); rw [smul_add, smul_add]; rfl /-- A `DistribMulAction` by a product monoid is equivalent to commuting `DistribMulAction`s by the factors. -/ def DistribMulAction.prodEquiv : DistribMulAction (M × N) α ≃ Σ' (_ : DistribMulAction M α) (_ : DistribMulAction N α), SMulCommClass M N α where toFun _ := letI instM := DistribMulAction.compHom α (.inl M N) letI instN := DistribMulAction.compHom α (.inr M N) ⟨instM, instN, (MulAction.prodEquiv M N α inferInstance).2.2⟩ invFun _insts := letI := _insts.1; letI := _insts.2.1; have := _insts.2.2 DistribMulAction.prodOfSMulCommClass M N α left_inv _ := by dsimp only; ext ⟨m, n⟩ a change (m, (1 : N)) • ((1 : M), n) • a = _ rw [smul_smul, Prod.mk_mul_mk, mul_one, one_mul]; rfl right_inv := by rintro ⟨_, x, _⟩ dsimp only; congr 1 · ext m a; (conv_rhs => rw [← one_smul N a]); rfl congr 1 · funext i; congr; ext m a; clear i; (conv_rhs => rw [← one_smul N a]); rfl · ext n a; (conv_rhs => rw [← one_smul M (SMul.smul n a)]); rfl · apply heq_prop end Action_by_Prod
Algebra\GroupWithZero\Action\Units.lean
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.Units import Mathlib.Algebra.GroupWithZero.Action.Defs /-! # Multiplicative actions with zero on and by `Mˣ` This file provides the multiplicative actions with zero of a unit on a type `α`, `SMul Mˣ α`, in the presence of `SMulWithZero M α`, with the obvious definition stated in `Units.smul_def`. Additionally, a `MulDistribMulAction G M` for some group `G` satisfying some additional properties admits a `MulDistribMulAction G Mˣ` structure, again with the obvious definition stated in `Units.coe_smul`. This instance uses a primed name. ## See also * `Algebra.GroupWithZero.Action.Opposite` * `Algebra.GroupWithZero.Action.Pi` * `Algebra.GroupWithZero.Action.Prod` -/ variable {G M α : Type*} namespace Units /-! ### Action of the units of `M` on a type `α` -/ @[to_additive] instance [Monoid M] [SMul M α] : SMul Mˣ α where smul m a := (m : M) • a instance instSMulZeroClass [Monoid M] [Zero α] [SMulZeroClass M α] : SMulZeroClass Mˣ α where smul := (· • ·) smul_zero m := smul_zero (m : M) instance instDistribSMulUnits [Monoid M] [AddZeroClass α] [DistribSMul M α] : DistribSMul Mˣ α where smul_add m := smul_add (m : M) instance instDistribMulAction [Monoid M] [AddMonoid α] [DistribMulAction M α] : DistribMulAction Mˣ α where __ := instDistribSMulUnits one_smul := fun b => one_smul M b mul_smul := fun x y b => mul_smul (x : M) y b instance instMulDistribMulAction [Monoid M] [Monoid α] [MulDistribMulAction M α] : MulDistribMulAction Mˣ α where smul_mul m := smul_mul' (m : M) smul_one m := smul_one (m : M) /-! ### Action of a group `G` on units of `M` -/ /-- A stronger form of `Units.mul_action'`. -/ instance mulDistribMulAction' [Group G] [Monoid M] [MulDistribMulAction G M] [SMulCommClass G M M] [IsScalarTower G M M] : MulDistribMulAction G Mˣ := { Units.mulAction' with smul := (· • ·), smul_one := fun _ => Units.ext <| smul_one _, smul_mul := fun _ _ _ => Units.ext <| smul_mul' _ _ _ } end Units
Algebra\GroupWithZero\Units\Basic.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.Units import Mathlib.Algebra.GroupWithZero.Basic import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.Contrapose import Mathlib.Tactic.Nontriviality import Mathlib.Tactic.Spread import Mathlib.Util.AssertExists import Mathlib.Data.Subtype /-! # Lemmas about units in a `MonoidWithZero` or a `GroupWithZero`. We also define `Ring.inverse`, a globally defined function on any ring (in fact any `MonoidWithZero`), which inverts units and sends non-units to zero. -/ -- Guard against import creep assert_not_exists Multiplicative assert_not_exists DenselyOrdered variable {α M₀ G₀ M₀' G₀' F F' : Type*} variable [MonoidWithZero M₀] namespace Units /-- An element of the unit group of a nonzero monoid with zero represented as an element of the monoid is nonzero. -/ @[simp] theorem ne_zero [Nontrivial M₀] (u : M₀ˣ) : (u : M₀) ≠ 0 := left_ne_zero_of_mul_eq_one u.mul_inv -- We can't use `mul_eq_zero` + `Units.ne_zero` in the next two lemmas because we don't assume -- `Nonzero M₀`. @[simp] theorem mul_left_eq_zero (u : M₀ˣ) {a : M₀} : a * u = 0 ↔ a = 0 := ⟨fun h => by simpa using mul_eq_zero_of_left h ↑u⁻¹, fun h => mul_eq_zero_of_left h u⟩ @[simp] theorem mul_right_eq_zero (u : M₀ˣ) {a : M₀} : ↑u * a = 0 ↔ a = 0 := ⟨fun h => by simpa using mul_eq_zero_of_right (↑u⁻¹) h, mul_eq_zero_of_right (u : M₀)⟩ end Units namespace IsUnit theorem ne_zero [Nontrivial M₀] {a : M₀} (ha : IsUnit a) : a ≠ 0 := let ⟨u, hu⟩ := ha hu ▸ u.ne_zero theorem mul_right_eq_zero {a b : M₀} (ha : IsUnit a) : a * b = 0 ↔ b = 0 := let ⟨u, hu⟩ := ha hu ▸ u.mul_right_eq_zero theorem mul_left_eq_zero {a b : M₀} (hb : IsUnit b) : a * b = 0 ↔ a = 0 := let ⟨u, hu⟩ := hb hu ▸ u.mul_left_eq_zero end IsUnit @[simp] theorem isUnit_zero_iff : IsUnit (0 : M₀) ↔ (0 : M₀) = 1 := ⟨fun ⟨⟨_, a, (a0 : 0 * a = 1), _⟩, rfl⟩ => by rwa [zero_mul] at a0, fun h => @isUnit_of_subsingleton _ _ (subsingleton_of_zero_eq_one h) 0⟩ -- Porting note: removed `simp` tag because `simpNF` says it's redundant theorem not_isUnit_zero [Nontrivial M₀] : ¬IsUnit (0 : M₀) := mt isUnit_zero_iff.1 zero_ne_one namespace Ring open Classical in /-- Introduce a function `inverse` on a monoid with zero `M₀`, which sends `x` to `x⁻¹` if `x` is invertible and to `0` otherwise. This definition is somewhat ad hoc, but one needs a fully (rather than partially) defined inverse function for some purposes, including for calculus. Note that while this is in the `Ring` namespace for brevity, it requires the weaker assumption `MonoidWithZero M₀` instead of `Ring M₀`. -/ noncomputable def inverse : M₀ → M₀ := fun x => if h : IsUnit x then ((h.unit⁻¹ : M₀ˣ) : M₀) else 0 /-- By definition, if `x` is invertible then `inverse x = x⁻¹`. -/ @[simp] theorem inverse_unit (u : M₀ˣ) : inverse (u : M₀) = (u⁻¹ : M₀ˣ) := by rw [inverse, dif_pos u.isUnit, IsUnit.unit_of_val_units] /-- By definition, if `x` is not invertible then `inverse x = 0`. -/ @[simp] theorem inverse_non_unit (x : M₀) (h : ¬IsUnit x) : inverse x = 0 := dif_neg h theorem mul_inverse_cancel (x : M₀) (h : IsUnit x) : x * inverse x = 1 := by rcases h with ⟨u, rfl⟩ rw [inverse_unit, Units.mul_inv] theorem inverse_mul_cancel (x : M₀) (h : IsUnit x) : inverse x * x = 1 := by rcases h with ⟨u, rfl⟩ rw [inverse_unit, Units.inv_mul] theorem mul_inverse_cancel_right (x y : M₀) (h : IsUnit x) : y * x * inverse x = y := by rw [mul_assoc, mul_inverse_cancel x h, mul_one] theorem inverse_mul_cancel_right (x y : M₀) (h : IsUnit x) : y * inverse x * x = y := by rw [mul_assoc, inverse_mul_cancel x h, mul_one] theorem mul_inverse_cancel_left (x y : M₀) (h : IsUnit x) : x * (inverse x * y) = y := by rw [← mul_assoc, mul_inverse_cancel x h, one_mul] theorem inverse_mul_cancel_left (x y : M₀) (h : IsUnit x) : inverse x * (x * y) = y := by rw [← mul_assoc, inverse_mul_cancel x h, one_mul] theorem inverse_mul_eq_iff_eq_mul (x y z : M₀) (h : IsUnit x) : inverse x * y = z ↔ y = x * z := ⟨fun h1 => by rw [← h1, mul_inverse_cancel_left _ _ h], fun h1 => by rw [h1, inverse_mul_cancel_left _ _ h]⟩ theorem eq_mul_inverse_iff_mul_eq (x y z : M₀) (h : IsUnit z) : x = y * inverse z ↔ x * z = y := ⟨fun h1 => by rw [h1, inverse_mul_cancel_right _ _ h], fun h1 => by rw [← h1, mul_inverse_cancel_right _ _ h]⟩ variable (M₀) @[simp] theorem inverse_one : inverse (1 : M₀) = 1 := inverse_unit 1 @[simp] theorem inverse_zero : inverse (0 : M₀) = 0 := by nontriviality exact inverse_non_unit _ not_isUnit_zero variable {M₀} end Ring theorem IsUnit.ring_inverse {a : M₀} : IsUnit a → IsUnit (Ring.inverse a) | ⟨u, hu⟩ => hu ▸ ⟨u⁻¹, (Ring.inverse_unit u).symm⟩ @[simp] theorem isUnit_ring_inverse {a : M₀} : IsUnit (Ring.inverse a) ↔ IsUnit a := ⟨fun h => by cases subsingleton_or_nontrivial M₀ · convert h · contrapose h rw [Ring.inverse_non_unit _ h] exact not_isUnit_zero , IsUnit.ring_inverse⟩ namespace Units variable [GroupWithZero G₀] variable {a b : G₀} /-- Embed a non-zero element of a `GroupWithZero` into the unit group. By combining this function with the operations on units, or the `/ₚ` operation, it is possible to write a division as a partial function with three arguments. -/ def mk0 (a : G₀) (ha : a ≠ 0) : G₀ˣ := ⟨a, a⁻¹, mul_inv_cancel ha, inv_mul_cancel ha⟩ @[simp] theorem mk0_one (h := one_ne_zero) : mk0 (1 : G₀) h = 1 := by ext rfl @[simp] theorem val_mk0 {a : G₀} (h : a ≠ 0) : (mk0 a h : G₀) = a := rfl @[simp] theorem mk0_val (u : G₀ˣ) (h : (u : G₀) ≠ 0) : mk0 (u : G₀) h = u := Units.ext rfl -- Porting note: removed `simp` tag because `simpNF` says it's redundant theorem mul_inv' (u : G₀ˣ) : u * (u : G₀)⁻¹ = 1 := mul_inv_cancel u.ne_zero -- Porting note: removed `simp` tag because `simpNF` says it's redundant theorem inv_mul' (u : G₀ˣ) : (u⁻¹ : G₀) * u = 1 := inv_mul_cancel u.ne_zero @[simp] theorem mk0_inj {a b : G₀} (ha : a ≠ 0) (hb : b ≠ 0) : Units.mk0 a ha = Units.mk0 b hb ↔ a = b := ⟨fun h => by injection h, fun h => Units.ext h⟩ /-- In a group with zero, an existential over a unit can be rewritten in terms of `Units.mk0`. -/ theorem exists0 {p : G₀ˣ → Prop} : (∃ g : G₀ˣ, p g) ↔ ∃ (g : G₀) (hg : g ≠ 0), p (Units.mk0 g hg) := ⟨fun ⟨g, pg⟩ => ⟨g, g.ne_zero, (g.mk0_val g.ne_zero).symm ▸ pg⟩, fun ⟨g, hg, pg⟩ => ⟨Units.mk0 g hg, pg⟩⟩ /-- An alternative version of `Units.exists0`. This one is useful if Lean cannot figure out `p` when using `Units.exists0` from right to left. -/ theorem exists0' {p : ∀ g : G₀, g ≠ 0 → Prop} : (∃ (g : G₀) (hg : g ≠ 0), p g hg) ↔ ∃ g : G₀ˣ, p g g.ne_zero := Iff.trans (by simp_rw [val_mk0]) exists0.symm -- Porting note: had to add the `rfl` @[simp] theorem exists_iff_ne_zero {p : G₀ → Prop} : (∃ u : G₀ˣ, p u) ↔ ∃ x ≠ 0, p x := by simp [exists0] theorem _root_.GroupWithZero.eq_zero_or_unit (a : G₀) : a = 0 ∨ ∃ u : G₀ˣ, a = u := by simpa using em _ end Units section GroupWithZero variable [GroupWithZero G₀] {a b c d : G₀} {m n : ℕ} theorem IsUnit.mk0 (x : G₀) (hx : x ≠ 0) : IsUnit x := (Units.mk0 x hx).isUnit @[simp] theorem isUnit_iff_ne_zero : IsUnit a ↔ a ≠ 0 := (Units.exists_iff_ne_zero (p := (· = a))).trans (by simp) alias ⟨_, Ne.isUnit⟩ := isUnit_iff_ne_zero -- Porting note: can't add this attribute? -- https://github.com/leanprover-community/mathlib4/issues/740 -- attribute [protected] Ne.is_unit -- see Note [lower instance priority] instance (priority := 10) GroupWithZero.noZeroDivisors : NoZeroDivisors G₀ := { (‹_› : GroupWithZero G₀) with eq_zero_or_eq_zero_of_mul_eq_zero := @fun a b h => by contrapose! h exact (Units.mk0 a h.1 * Units.mk0 b h.2).ne_zero } -- Can't be put next to the other `mk0` lemmas because it depends on the -- `NoZeroDivisors` instance, which depends on `mk0`. @[simp] theorem Units.mk0_mul (x y : G₀) (hxy) : Units.mk0 (x * y) hxy = Units.mk0 x (mul_ne_zero_iff.mp hxy).1 * Units.mk0 y (mul_ne_zero_iff.mp hxy).2 := by ext; rfl theorem div_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a / b ≠ 0 := by rw [div_eq_mul_inv] exact mul_ne_zero ha (inv_ne_zero hb) @[simp] theorem div_eq_zero_iff : a / b = 0 ↔ a = 0 ∨ b = 0 := by simp [div_eq_mul_inv] theorem div_ne_zero_iff : a / b ≠ 0 ↔ a ≠ 0 ∧ b ≠ 0 := div_eq_zero_iff.not.trans not_or @[simp] lemma div_self (h : a ≠ 0) : a / a = 1 := h.isUnit.div_self lemma eq_mul_inv_iff_mul_eq₀ (hc : c ≠ 0) : a = b * c⁻¹ ↔ a * c = b := hc.isUnit.eq_mul_inv_iff_mul_eq lemma eq_inv_mul_iff_mul_eq₀ (hb : b ≠ 0) : a = b⁻¹ * c ↔ b * a = c := hb.isUnit.eq_inv_mul_iff_mul_eq lemma inv_mul_eq_iff_eq_mul₀ (ha : a ≠ 0) : a⁻¹ * b = c ↔ b = a * c := ha.isUnit.inv_mul_eq_iff_eq_mul lemma mul_inv_eq_iff_eq_mul₀ (hb : b ≠ 0) : a * b⁻¹ = c ↔ a = c * b := hb.isUnit.mul_inv_eq_iff_eq_mul lemma mul_inv_eq_one₀ (hb : b ≠ 0) : a * b⁻¹ = 1 ↔ a = b := hb.isUnit.mul_inv_eq_one lemma inv_mul_eq_one₀ (ha : a ≠ 0) : a⁻¹ * b = 1 ↔ a = b := ha.isUnit.inv_mul_eq_one lemma mul_eq_one_iff_eq_inv₀ (hb : b ≠ 0) : a * b = 1 ↔ a = b⁻¹ := hb.isUnit.mul_eq_one_iff_eq_inv lemma mul_eq_one_iff_inv_eq₀ (ha : a ≠ 0) : a * b = 1 ↔ a⁻¹ = b := ha.isUnit.mul_eq_one_iff_inv_eq /-- A variant of `eq_mul_inv_iff_mul_eq₀` that moves the nonzero hypothesis to another variable. -/ lemma mul_eq_of_eq_mul_inv₀ (ha : a ≠ 0) (h : a = c * b⁻¹) : a * b = c := by rwa [← eq_mul_inv_iff_mul_eq₀]; rintro rfl; simp [ha] at h /-- A variant of `eq_inv_mul_iff_mul_eq₀` that moves the nonzero hypothesis to another variable. -/ lemma mul_eq_of_eq_inv_mul₀ (hb : b ≠ 0) (h : b = a⁻¹ * c) : a * b = c := by rwa [← eq_inv_mul_iff_mul_eq₀]; rintro rfl; simp [hb] at h /-- A variant of `inv_mul_eq_iff_eq_mul₀` that moves the nonzero hypothesis to another variable. -/ lemma eq_mul_of_inv_mul_eq₀ (hc : c ≠ 0) (h : b⁻¹ * a = c) : a = b * c := by rwa [← inv_mul_eq_iff_eq_mul₀]; rintro rfl; simp [hc.symm] at h /-- A variant of `mul_inv_eq_iff_eq_mul₀` that moves the nonzero hypothesis to another variable. -/ lemma eq_mul_of_mul_inv_eq₀ (hb : b ≠ 0) (h : a * c⁻¹ = b) : a = b * c := by rwa [← mul_inv_eq_iff_eq_mul₀]; rintro rfl; simp [hb.symm] at h @[simp] lemma div_mul_cancel₀ (a : G₀) (h : b ≠ 0) : a / b * b = a := h.isUnit.div_mul_cancel _ lemma mul_one_div_cancel (h : a ≠ 0) : a * (1 / a) = 1 := h.isUnit.mul_one_div_cancel lemma one_div_mul_cancel (h : a ≠ 0) : 1 / a * a = 1 := h.isUnit.one_div_mul_cancel lemma div_left_inj' (hc : c ≠ 0) : a / c = b / c ↔ a = b := hc.isUnit.div_left_inj @[field_simps] lemma div_eq_iff (hb : b ≠ 0) : a / b = c ↔ a = c * b := hb.isUnit.div_eq_iff @[field_simps] lemma eq_div_iff (hb : b ≠ 0) : c = a / b ↔ c * b = a := hb.isUnit.eq_div_iff -- TODO: Swap RHS around lemma div_eq_iff_mul_eq (hb : b ≠ 0) : a / b = c ↔ c * b = a := hb.isUnit.div_eq_iff.trans eq_comm lemma eq_div_iff_mul_eq (hc : c ≠ 0) : a = b / c ↔ a * c = b := hc.isUnit.eq_div_iff lemma div_eq_of_eq_mul (hb : b ≠ 0) : a = c * b → a / b = c := hb.isUnit.div_eq_of_eq_mul lemma eq_div_of_mul_eq (hc : c ≠ 0) : a * c = b → a = b / c := hc.isUnit.eq_div_of_mul_eq lemma div_eq_one_iff_eq (hb : b ≠ 0) : a / b = 1 ↔ a = b := hb.isUnit.div_eq_one_iff_eq lemma div_mul_cancel_right₀ (hb : b ≠ 0) (a : G₀) : b / (a * b) = a⁻¹ := hb.isUnit.div_mul_cancel_right _ set_option linter.deprecated false in @[deprecated div_mul_cancel_right₀ (since := "2024-03-20")] lemma div_mul_left (hb : b ≠ 0) : b / (a * b) = 1 / a := hb.isUnit.div_mul_left lemma mul_div_mul_right (a b : G₀) (hc : c ≠ 0) : a * c / (b * c) = a / b := hc.isUnit.mul_div_mul_right _ _ -- TODO: Duplicate of `mul_inv_cancel_right₀` lemma mul_mul_div (a : G₀) (hb : b ≠ 0) : a = a * b * (1 / b) := (hb.isUnit.mul_mul_div _).symm lemma div_div_div_cancel_right (a : G₀) (hc : c ≠ 0) : a / c / (b / c) = a / b := by rw [div_div_eq_mul_div, div_mul_cancel₀ _ hc] lemma div_mul_div_cancel (a : G₀) (hc : c ≠ 0) : a / c * (c / b) = a / b := by rw [← mul_div_assoc, div_mul_cancel₀ _ hc] lemma div_mul_cancel_of_imp (h : b = 0 → a = 0) : a / b * b = a := by obtain rfl | hb := eq_or_ne b 0 <;> simp [*] lemma mul_div_cancel_of_imp (h : b = 0 → a = 0) : a * b / b = a := by obtain rfl | hb := eq_or_ne b 0 <;> simp [*] @[simp] lemma divp_mk0 (a : G₀) (hb : b ≠ 0) : a /ₚ Units.mk0 b hb = a / b := divp_eq_div _ _ lemma pow_sub₀ (a : G₀) (ha : a ≠ 0) (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by have h1 : m - n + n = m := Nat.sub_add_cancel h have h2 : a ^ (m - n) * a ^ n = a ^ m := by rw [← pow_add, h1] simpa only [div_eq_mul_inv] using eq_div_of_mul_eq (pow_ne_zero _ ha) h2 lemma pow_sub_of_lt (a : G₀) (h : n < m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · rw [zero_pow (Nat.ne_of_gt <| Nat.sub_pos_of_lt h), zero_pow (by omega), zero_mul] · exact pow_sub₀ _ ha <| Nat.le_of_lt h lemma inv_pow_sub₀ (ha : a ≠ 0) (h : n ≤ m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by rw [pow_sub₀ _ (inv_ne_zero ha) h, inv_pow, inv_pow, inv_inv] lemma inv_pow_sub_of_lt (a : G₀) (h : n < m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by rw [pow_sub_of_lt a⁻¹ h, inv_pow, inv_pow, inv_inv] lemma zpow_sub₀ (ha : a ≠ 0) (m n : ℤ) : a ^ (m - n) = a ^ m / a ^ n := by rw [Int.sub_eq_add_neg, zpow_add₀ ha, zpow_neg, div_eq_mul_inv] lemma zpow_ne_zero {a : G₀} : ∀ n : ℤ, a ≠ 0 → a ^ n ≠ 0 | (_ : ℕ) => by rw [zpow_natCast]; exact pow_ne_zero _ | .negSucc n => fun ha ↦ by rw [zpow_negSucc]; exact inv_ne_zero (pow_ne_zero _ ha) lemma eq_zero_of_zpow_eq_zero {n : ℤ} : a ^ n = 0 → a = 0 := not_imp_not.1 (zpow_ne_zero _) @[deprecated (since := "2024-05-07")] alias zpow_ne_zero_of_ne_zero := zpow_ne_zero @[deprecated (since := "2024-05-07")] alias zpow_eq_zero := eq_zero_of_zpow_eq_zero lemma zpow_eq_zero_iff {n : ℤ} (hn : n ≠ 0) : a ^ n = 0 ↔ a = 0 := ⟨eq_zero_of_zpow_eq_zero, fun ha => ha.symm ▸ zero_zpow _ hn⟩ lemma zpow_ne_zero_iff {n : ℤ} (hn : n ≠ 0) : a ^ n ≠ 0 ↔ a ≠ 0 := (zpow_eq_zero_iff hn).ne lemma zpow_neg_mul_zpow_self (n : ℤ) (ha : a ≠ 0) : a ^ (-n) * a ^ n = 1 := by rw [zpow_neg]; exact inv_mul_cancel (zpow_ne_zero n ha) theorem Ring.inverse_eq_inv (a : G₀) : Ring.inverse a = a⁻¹ := by obtain rfl | ha := eq_or_ne a 0 · simp · exact Ring.inverse_unit (Units.mk0 a ha) @[simp] theorem Ring.inverse_eq_inv' : (Ring.inverse : G₀ → G₀) = Inv.inv := funext Ring.inverse_eq_inv /-- In a `GroupWithZero` `α`, the unit group `αˣ` is equivalent to the subtype of nonzero elements. -/ @[simps] def unitsEquivNeZero [GroupWithZero α] : αˣ ≃ {a : α // a ≠ 0} where toFun a := ⟨a, a.ne_zero⟩ invFun a := Units.mk0 _ a.prop left_inv _ := Units.ext rfl right_inv _ := rfl end GroupWithZero section CommGroupWithZero -- comm variable [CommGroupWithZero G₀] {a b c d : G₀} -- see Note [lower instance priority] instance (priority := 10) CommGroupWithZero.toCancelCommMonoidWithZero : CancelCommMonoidWithZero G₀ := { GroupWithZero.toCancelMonoidWithZero, CommGroupWithZero.toCommMonoidWithZero with } -- See note [lower instance priority] instance (priority := 100) CommGroupWithZero.toDivisionCommMonoid : DivisionCommMonoid G₀ where __ := ‹CommGroupWithZero G₀› __ := GroupWithZero.toDivisionMonoid lemma div_mul_cancel_left₀ (ha : a ≠ 0) (b : G₀) : a / (a * b) = b⁻¹ := ha.isUnit.div_mul_cancel_left _ set_option linter.deprecated false in @[deprecated div_mul_cancel_left₀ (since := "2024-03-22")] lemma div_mul_right (b : G₀) (ha : a ≠ 0) : a / (a * b) = 1 / b := ha.isUnit.div_mul_right _ lemma mul_div_cancel_left_of_imp (h : a = 0 → b = 0) : a * b / a = b := by rw [mul_comm, mul_div_cancel_of_imp h] lemma mul_div_cancel_of_imp' (h : b = 0 → a = 0) : b * (a / b) = a := by rw [mul_comm, div_mul_cancel_of_imp h] lemma mul_div_cancel₀ (a : G₀) (hb : b ≠ 0) : b * (a / b) = a := hb.isUnit.mul_div_cancel _ lemma mul_div_mul_left (a b : G₀) (hc : c ≠ 0) : c * a / (c * b) = a / b := hc.isUnit.mul_div_mul_left _ _ lemma mul_eq_mul_of_div_eq_div (a c : G₀) (hb : b ≠ 0) (hd : d ≠ 0) (h : a / b = c / d) : a * d = c * b := by rw [← mul_one a, ← div_self hb, ← mul_comm_div, h, div_mul_eq_mul_div, div_mul_cancel₀ _ hd] @[field_simps] lemma div_eq_div_iff (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = c * b := hb.isUnit.div_eq_div_iff hd.isUnit /-- The `CommGroupWithZero` version of `div_eq_div_iff_div_eq_div`. -/ lemma div_eq_div_iff_div_eq_div' (hb : b ≠ 0) (hc : c ≠ 0) : a / b = c / d ↔ a / c = b / d := by conv_lhs => rw [← mul_left_inj' hb, div_mul_cancel₀ _ hb] conv_rhs => rw [← mul_left_inj' hc, div_mul_cancel₀ _ hc] rw [mul_comm _ c, div_mul_eq_mul_div, mul_div_assoc] lemma div_div_cancel' (ha : a ≠ 0) : a / (a / b) = b := ha.isUnit.div_div_cancel lemma div_div_cancel_left' (ha : a ≠ 0) : a / b / a = b⁻¹ := ha.isUnit.div_div_cancel_left lemma div_helper (b : G₀) (h : a ≠ 0) : 1 / (a * b) * a = 1 / b := by rw [div_mul_eq_mul_div, one_mul, div_mul_cancel_left₀ h, one_div] lemma div_div_div_cancel_left' (a b : G₀) (hc : c ≠ 0) : c / a / (c / b) = b / a := by rw [div_div_div_eq, mul_comm, mul_div_mul_right _ _ hc] end CommGroupWithZero section NoncomputableDefs variable {M : Type*} [Nontrivial M] open Classical in /-- Constructs a `GroupWithZero` structure on a `MonoidWithZero` consisting only of units and 0. -/ noncomputable def groupWithZeroOfIsUnitOrEqZero [hM : MonoidWithZero M] (h : ∀ a : M, IsUnit a ∨ a = 0) : GroupWithZero M := { hM with inv := fun a => if h0 : a = 0 then 0 else ↑((h a).resolve_right h0).unit⁻¹, inv_zero := dif_pos rfl, mul_inv_cancel := fun a h0 => by change (a * if h0 : a = 0 then 0 else ↑((h a).resolve_right h0).unit⁻¹) = 1 rw [dif_neg h0, Units.mul_inv_eq_iff_eq_mul, one_mul, IsUnit.unit_spec], exists_pair_ne := Nontrivial.exists_pair_ne } /-- Constructs a `CommGroupWithZero` structure on a `CommMonoidWithZero` consisting only of units and 0. -/ noncomputable def commGroupWithZeroOfIsUnitOrEqZero [hM : CommMonoidWithZero M] (h : ∀ a : M, IsUnit a ∨ a = 0) : CommGroupWithZero M := { groupWithZeroOfIsUnitOrEqZero h, hM with } end NoncomputableDefs @[deprecated (since := "2024-03-20")] alias mul_div_cancel' := mul_div_cancel₀
Algebra\GroupWithZero\Units\Equiv.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov -/ import Mathlib.Algebra.Group.Units.Equiv import Mathlib.Algebra.GroupWithZero.Units.Basic /-! # Multiplication by a nonzero element in a `GroupWithZero` is a permutation. -/ assert_not_exists DenselyOrdered variable {G : Type*} namespace Equiv section GroupWithZero variable [GroupWithZero G] /-- Left multiplication by a nonzero element in a `GroupWithZero` is a permutation of the underlying type. -/ @[simps! (config := .asFn)] protected def mulLeft₀ (a : G) (ha : a ≠ 0) : Perm G := (Units.mk0 a ha).mulLeft theorem _root_.mulLeft_bijective₀ (a : G) (ha : a ≠ 0) : Function.Bijective (a * · : G → G) := (Equiv.mulLeft₀ a ha).bijective /-- Right multiplication by a nonzero element in a `GroupWithZero` is a permutation of the underlying type. -/ @[simps! (config := .asFn)] protected def mulRight₀ (a : G) (ha : a ≠ 0) : Perm G := (Units.mk0 a ha).mulRight theorem _root_.mulRight_bijective₀ (a : G) (ha : a ≠ 0) : Function.Bijective ((· * a) : G → G) := (Equiv.mulRight₀ a ha).bijective end GroupWithZero end Equiv
Algebra\GroupWithZero\Units\Lemmas.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.GroupWithZero.Action.Units import Mathlib.Algebra.GroupWithZero.Commute import Mathlib.Algebra.GroupWithZero.Hom /-! # Further lemmas about units in a `MonoidWithZero` or a `GroupWithZero`. -/ assert_not_exists DenselyOrdered variable {α M₀ G₀ M₀' G₀' F F' : Type*} variable [MonoidWithZero M₀] namespace Commute variable [GroupWithZero G₀] {a b c d : G₀} /-- The `MonoidWithZero` version of `div_eq_div_iff_mul_eq_mul`. -/ protected lemma div_eq_div_iff (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = c * b := hbd.div_eq_div_iff_of_isUnit hb.isUnit hd.isUnit end Commute section MonoidWithZero variable [GroupWithZero G₀] [Nontrivial M₀] [MonoidWithZero M₀'] [FunLike F G₀ M₀] [MonoidWithZeroHomClass F G₀ M₀] [FunLike F' G₀ M₀'] (f : F) {a : G₀} theorem map_ne_zero : f a ≠ 0 ↔ a ≠ 0 := ⟨fun hfa ha => hfa <| ha.symm ▸ map_zero f, fun ha => ((IsUnit.mk0 a ha).map f).ne_zero⟩ @[simp] theorem map_eq_zero : f a = 0 ↔ a = 0 := not_iff_not.1 (map_ne_zero f) theorem eq_on_inv₀ [MonoidWithZeroHomClass F' G₀ M₀'] (f g : F') (h : f a = g a) : f a⁻¹ = g a⁻¹ := by rcases eq_or_ne a 0 with (rfl | ha) · rw [inv_zero, map_zero, map_zero] · exact (IsUnit.mk0 a ha).eq_on_inv f g h end MonoidWithZero section GroupWithZero variable [GroupWithZero G₀] [GroupWithZero G₀'] [FunLike F G₀ G₀'] [MonoidWithZeroHomClass F G₀ G₀'] (f : F) (a b : G₀) /-- A monoid homomorphism between groups with zeros sending `0` to `0` sends `a⁻¹` to `(f a)⁻¹`. -/ @[simp] theorem map_inv₀ : f a⁻¹ = (f a)⁻¹ := by by_cases h : a = 0 · simp [h, map_zero f] · apply eq_inv_of_mul_eq_one_left rw [← map_mul, inv_mul_cancel h, map_one] @[simp] theorem map_div₀ : f (a / b) = f a / f b := map_div' f (map_inv₀ f) a b end GroupWithZero /-- We define the inverse as a `MonoidWithZeroHom` by extending the inverse map by zero on non-units. -/ noncomputable def MonoidWithZero.inverse {M : Type*} [CommMonoidWithZero M] : M →*₀ M where toFun := Ring.inverse map_zero' := Ring.inverse_zero _ map_one' := Ring.inverse_one _ map_mul' x y := (Ring.mul_inverse_rev x y).trans (mul_comm _ _) @[simp] theorem MonoidWithZero.coe_inverse {M : Type*} [CommMonoidWithZero M] : (MonoidWithZero.inverse : M → M) = Ring.inverse := rfl @[simp] theorem MonoidWithZero.inverse_apply {M : Type*} [CommMonoidWithZero M] (a : M) : MonoidWithZero.inverse a = Ring.inverse a := rfl /-- Inversion on a commutative group with zero, considered as a monoid with zero homomorphism. -/ def invMonoidWithZeroHom {G₀ : Type*} [CommGroupWithZero G₀] : G₀ →*₀ G₀ := { invMonoidHom with map_zero' := inv_zero } namespace Units variable [GroupWithZero G₀] variable {a b : G₀} @[simp] theorem smul_mk0 {α : Type*} [SMul G₀ α] {g : G₀} (hg : g ≠ 0) (a : α) : mk0 g hg • a = g • a := rfl end Units /-- If a monoid homomorphism `f` between two `GroupWithZero`s maps `0` to `0`, then it maps `x^n`, `n : ℤ`, to `(f x)^n`. -/ @[simp] theorem map_zpow₀ {F G₀ G₀' : Type*} [GroupWithZero G₀] [GroupWithZero G₀'] [FunLike F G₀ G₀'] [MonoidWithZeroHomClass F G₀ G₀'] (f : F) (x : G₀) (n : ℤ) : f (x ^ n) = f x ^ n := map_zpow' f (map_inv₀ f) x n
Algebra\Homology\Additive.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Homology.Single import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! # Homology is an additive functor When `V` is preadditive, `HomologicalComplex V c` is also preadditive, and `homologyFunctor` is additive. -/ universe v u open CategoryTheory CategoryTheory.Category CategoryTheory.Limits HomologicalComplex variable {ι : Type*} variable {V : Type u} [Category.{v} V] [Preadditive V] variable {W : Type*} [Category W] [Preadditive W] variable {W₁ W₂ : Type*} [Category W₁] [Category W₂] [HasZeroMorphisms W₁] [HasZeroMorphisms W₂] variable {c : ComplexShape ι} {C D E : HomologicalComplex V c} variable (f g : C ⟶ D) (h k : D ⟶ E) (i : ι) namespace HomologicalComplex instance : Zero (C ⟶ D) := ⟨{ f := fun i => 0 }⟩ instance : Add (C ⟶ D) := ⟨fun f g => { f := fun i => f.f i + g.f i }⟩ instance : Neg (C ⟶ D) := ⟨fun f => { f := fun i => -f.f i }⟩ instance : Sub (C ⟶ D) := ⟨fun f g => { f := fun i => f.f i - g.f i }⟩ instance hasNatScalar : SMul ℕ (C ⟶ D) := ⟨fun n f => { f := fun i => n • f.f i comm' := fun i j _ => by simp [Preadditive.nsmul_comp, Preadditive.comp_nsmul] }⟩ instance hasIntScalar : SMul ℤ (C ⟶ D) := ⟨fun n f => { f := fun i => n • f.f i comm' := fun i j _ => by simp [Preadditive.zsmul_comp, Preadditive.comp_zsmul] }⟩ @[simp] theorem zero_f_apply (i : ι) : (0 : C ⟶ D).f i = 0 := rfl @[simp] theorem add_f_apply (f g : C ⟶ D) (i : ι) : (f + g).f i = f.f i + g.f i := rfl @[simp] theorem neg_f_apply (f : C ⟶ D) (i : ι) : (-f).f i = -f.f i := rfl @[simp] theorem sub_f_apply (f g : C ⟶ D) (i : ι) : (f - g).f i = f.f i - g.f i := rfl @[simp] theorem nsmul_f_apply (n : ℕ) (f : C ⟶ D) (i : ι) : (n • f).f i = n • f.f i := rfl @[simp] theorem zsmul_f_apply (n : ℤ) (f : C ⟶ D) (i : ι) : (n • f).f i = n • f.f i := rfl instance : AddCommGroup (C ⟶ D) := Function.Injective.addCommGroup Hom.f HomologicalComplex.hom_f_injective (by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat) -- Porting note: proofs had to be provided here, otherwise Lean tries to apply -- `Preadditive.add_comp/comp_add` to `HomologicalComplex V c` instance : Preadditive (HomologicalComplex V c) where add_comp _ _ _ f f' g := by ext simp only [comp_f, add_f_apply] rw [Preadditive.add_comp] comp_add _ _ _ f g g' := by ext simp only [comp_f, add_f_apply] rw [Preadditive.comp_add] /-- The `i`-th component of a chain map, as an additive map from chain maps to morphisms. -/ @[simps!] def Hom.fAddMonoidHom {C₁ C₂ : HomologicalComplex V c} (i : ι) : (C₁ ⟶ C₂) →+ (C₁.X i ⟶ C₂.X i) := AddMonoidHom.mk' (fun f => Hom.f f i) fun _ _ => rfl instance eval_additive (i : ι) : (eval V c i).Additive where end HomologicalComplex namespace CategoryTheory /-- An additive functor induces a functor between homological complexes. This is sometimes called the "prolongation". -/ @[simps] def Functor.mapHomologicalComplex (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (c : ComplexShape ι) : HomologicalComplex W₁ c ⥤ HomologicalComplex W₂ c where obj C := { X := fun i => F.obj (C.X i) d := fun i j => F.map (C.d i j) shape := fun i j w => by dsimp only rw [C.shape _ _ w, F.map_zero] d_comp_d' := fun i j k _ _ => by rw [← F.map_comp, C.d_comp_d, F.map_zero] } map f := { f := fun i => F.map (f.f i) comm' := fun i j _ => by dsimp rw [← F.map_comp, ← F.map_comp, f.comm] } instance (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (c : ComplexShape ι) : (F.mapHomologicalComplex c).PreservesZeroMorphisms where instance Functor.map_homogical_complex_additive (F : V ⥤ W) [F.Additive] (c : ComplexShape ι) : (F.mapHomologicalComplex c).Additive where variable (W₁) /-- The functor on homological complexes induced by the identity functor is isomorphic to the identity functor. -/ @[simps!] def Functor.mapHomologicalComplexIdIso (c : ComplexShape ι) : (𝟭 W₁).mapHomologicalComplex c ≅ 𝟭 _ := NatIso.ofComponents fun K => Hom.isoOfComponents fun i => Iso.refl _ instance Functor.mapHomologicalComplex_reflects_iso (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] [ReflectsIsomorphisms F] (c : ComplexShape ι) : ReflectsIsomorphisms (F.mapHomologicalComplex c) := ⟨fun f => by intro haveI : ∀ n : ι, IsIso (F.map (f.f n)) := fun n => ((HomologicalComplex.eval W₂ c n).mapIso (asIso ((F.mapHomologicalComplex c).map f))).isIso_hom haveI := fun n => isIso_of_reflects_iso (f.f n) F exact HomologicalComplex.Hom.isIso_of_components f⟩ variable {W₁} /-- A natural transformation between functors induces a natural transformation between those functors applied to homological complexes. -/ @[simps] def NatTrans.mapHomologicalComplex {F G : W₁ ⥤ W₂} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (α : F ⟶ G) (c : ComplexShape ι) : F.mapHomologicalComplex c ⟶ G.mapHomologicalComplex c where app C := { f := fun i => α.app _ } @[simp] theorem NatTrans.mapHomologicalComplex_id (c : ComplexShape ι) (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] : NatTrans.mapHomologicalComplex (𝟙 F) c = 𝟙 (F.mapHomologicalComplex c) := by aesop_cat @[simp] theorem NatTrans.mapHomologicalComplex_comp (c : ComplexShape ι) {F G H : W₁ ⥤ W₂} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] [H.PreservesZeroMorphisms] (α : F ⟶ G) (β : G ⟶ H) : NatTrans.mapHomologicalComplex (α ≫ β) c = NatTrans.mapHomologicalComplex α c ≫ NatTrans.mapHomologicalComplex β c := by aesop_cat @[reassoc (attr := simp 1100)] theorem NatTrans.mapHomologicalComplex_naturality {c : ComplexShape ι} {F G : W₁ ⥤ W₂} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (α : F ⟶ G) {C D : HomologicalComplex W₁ c} (f : C ⟶ D) : (F.mapHomologicalComplex c).map f ≫ (NatTrans.mapHomologicalComplex α c).app D = (NatTrans.mapHomologicalComplex α c).app C ≫ (G.mapHomologicalComplex c).map f := by aesop_cat /-- A natural isomorphism between functors induces a natural isomorphism between those functors applied to homological complexes. -/ @[simps!] def NatIso.mapHomologicalComplex {F G : W₁ ⥤ W₂} [F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (α : F ≅ G) (c : ComplexShape ι) : F.mapHomologicalComplex c ≅ G.mapHomologicalComplex c where hom := NatTrans.mapHomologicalComplex α.hom c inv := NatTrans.mapHomologicalComplex α.inv c hom_inv_id := by simp only [← NatTrans.mapHomologicalComplex_comp, α.hom_inv_id, NatTrans.mapHomologicalComplex_id] inv_hom_id := by simp only [← NatTrans.mapHomologicalComplex_comp, α.inv_hom_id, NatTrans.mapHomologicalComplex_id] /-- An equivalence of categories induces an equivalences between the respective categories of homological complex. -/ @[simps] def Equivalence.mapHomologicalComplex (e : W₁ ≌ W₂) [e.functor.PreservesZeroMorphisms] (c : ComplexShape ι) : HomologicalComplex W₁ c ≌ HomologicalComplex W₂ c where functor := e.functor.mapHomologicalComplex c inverse := e.inverse.mapHomologicalComplex c unitIso := (Functor.mapHomologicalComplexIdIso W₁ c).symm ≪≫ NatIso.mapHomologicalComplex e.unitIso c counitIso := NatIso.mapHomologicalComplex e.counitIso c ≪≫ Functor.mapHomologicalComplexIdIso W₂ c end CategoryTheory namespace ChainComplex variable {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] theorem map_chain_complex_of (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (X : α → W₁) (d : ∀ n, X (n + 1) ⟶ X n) (sq : ∀ n, d (n + 1) ≫ d n = 0) : (F.mapHomologicalComplex _).obj (ChainComplex.of X d sq) = ChainComplex.of (fun n => F.obj (X n)) (fun n => F.map (d n)) fun n => by rw [← F.map_comp, sq n, Functor.map_zero] := by refine HomologicalComplex.ext rfl ?_ rintro i j (rfl : j + 1 = i) simp only [CategoryTheory.Functor.mapHomologicalComplex_obj_d, of_d, eqToHom_refl, comp_id, id_comp] end ChainComplex variable [HasZeroObject W₁] [HasZeroObject W₂] namespace HomologicalComplex instance (W : Type*) [Category W] [Preadditive W] [HasZeroObject W] [DecidableEq ι] (j : ι) : (single W c j).Additive where map_add {_ _ f g} := by ext; simp [single] variable (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (c : ComplexShape ι) [DecidableEq ι] /-- Turning an object into a complex supported at `j` then applying a functor is the same as applying the functor then forming the complex. -/ noncomputable def singleMapHomologicalComplex (j : ι) : single W₁ c j ⋙ F.mapHomologicalComplex _ ≅ F ⋙ single W₂ c j := NatIso.ofComponents (fun X => { hom := { f := fun i => if h : i = j then eqToHom (by simp [h]) else 0 } inv := { f := fun i => if h : i = j then eqToHom (by simp [h]) else 0 } hom_inv_id := by ext i dsimp split_ifs with h · simp [h] · rw [zero_comp, ← F.map_id, (isZero_single_obj_X c j X _ h).eq_of_src (𝟙 _) 0, F.map_zero] inv_hom_id := by ext i dsimp split_ifs with h · simp [h] · apply (isZero_single_obj_X c j _ _ h).eq_of_src }) fun f => by ext i dsimp split_ifs with h · subst h simp [single_map_f_self, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map] · apply (isZero_single_obj_X c j _ _ h).eq_of_tgt @[simp] theorem singleMapHomologicalComplex_hom_app_self (j : ι) (X : W₁) : ((singleMapHomologicalComplex F c j).hom.app X).f j = F.map (singleObjXSelf c j X).hom ≫ (singleObjXSelf c j (F.obj X)).inv := by simp [singleMapHomologicalComplex, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map] @[simp] theorem singleMapHomologicalComplex_hom_app_ne {i j : ι} (h : i ≠ j) (X : W₁) : ((singleMapHomologicalComplex F c j).hom.app X).f i = 0 := by simp [singleMapHomologicalComplex, h] @[simp] theorem singleMapHomologicalComplex_inv_app_self (j : ι) (X : W₁) : ((singleMapHomologicalComplex F c j).inv.app X).f j = (singleObjXSelf c j (F.obj X)).hom ≫ F.map (singleObjXSelf c j X).inv := by simp [singleMapHomologicalComplex, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map] @[simp] theorem singleMapHomologicalComplex_inv_app_ne {i j : ι} (h : i ≠ j) (X : W₁) : ((singleMapHomologicalComplex F c j).inv.app X).f i = 0 := by simp [singleMapHomologicalComplex, h] end HomologicalComplex
Algebra\Homology\Augment.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Homology.Single /-! # Augmentation and truncation of `ℕ`-indexed (co)chain complexes. -/ noncomputable section open CategoryTheory Limits HomologicalComplex universe v u variable {V : Type u} [Category.{v} V] namespace ChainComplex /-- The truncation of an `ℕ`-indexed chain complex, deleting the object at `0` and shifting everything else down. -/ @[simps] def truncate [HasZeroMorphisms V] : ChainComplex V ℕ ⥤ ChainComplex V ℕ where obj C := { X := fun i => C.X (i + 1) d := fun i j => C.d (i + 1) (j + 1) shape := fun i j w => C.shape _ _ <| by simpa } map f := { f := fun i => f.f (i + 1) } /-- There is a canonical chain map from the truncation of a chain map `C` to the "single object" chain complex consisting of the truncated object `C.X 0` in degree 0. The components of this chain map are `C.d 1 0` in degree 0, and zero otherwise. -/ def truncateTo [HasZeroObject V] [HasZeroMorphisms V] (C : ChainComplex V ℕ) : truncate.obj C ⟶ (single₀ V).obj (C.X 0) := (toSingle₀Equiv (truncate.obj C) (C.X 0)).symm ⟨C.d 1 0, by aesop⟩ -- PROJECT when `V` is abelian (but not generally?) -- `[∀ n, Exact (C.d (n+2) (n+1)) (C.d (n+1) n)] [Epi (C.d 1 0)]` iff `QuasiIso (C.truncate_to)` variable [HasZeroMorphisms V] /-- We can "augment" a chain complex by inserting an arbitrary object in degree zero (shifting everything else up), along with a suitable differential. -/ def augment (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) : ChainComplex V ℕ where X | 0 => X | i + 1 => C.X i d | 1, 0 => f | i + 1, j + 1 => C.d i j | _, _ => 0 shape | 1, 0, h => absurd rfl h | i + 2, 0, _ => rfl | 0, _, _ => rfl | i + 1, j + 1, h => by simp only; exact C.shape i j (Nat.succ_ne_succ.1 h) d_comp_d' | _, _, 0, rfl, rfl => w | _, _, k + 1, rfl, rfl => C.d_comp_d _ _ _ @[simp] theorem augment_X_zero (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) : (augment C f w).X 0 = X := rfl @[simp] theorem augment_X_succ (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) : (augment C f w).X (i + 1) = C.X i := rfl @[simp] theorem augment_d_one_zero (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) : (augment C f w).d 1 0 = f := rfl @[simp] theorem augment_d_succ_succ (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i j : ℕ) : (augment C f w).d (i + 1) (j + 1) = C.d i j := by cases i <;> rfl /-- Truncating an augmented chain complex is isomorphic (with components the identity) to the original complex. -/ def truncateAugment (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) : truncate.obj (augment C f w) ≅ C where hom := { f := fun i => 𝟙 _ } inv := { f := fun i => 𝟙 _ comm' := fun i j => by cases j <;> · dsimp simp } hom_inv_id := by ext (_ | i) <;> · dsimp simp inv_hom_id := by ext (_ | i) <;> · dsimp simp @[simp] theorem truncateAugment_hom_f (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) : (truncateAugment C f w).hom.f i = 𝟙 (C.X i) := rfl @[simp] theorem truncateAugment_inv_f (C : ChainComplex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) : (truncateAugment C f w).inv.f i = 𝟙 ((truncate.obj (augment C f w)).X i) := rfl @[simp] theorem chainComplex_d_succ_succ_zero (C : ChainComplex V ℕ) (i : ℕ) : C.d (i + 2) 0 = 0 := by rw [C.shape] exact i.succ_succ_ne_one.symm /-- Augmenting a truncated complex with the original object and morphism is isomorphic (with components the identity) to the original complex. -/ def augmentTruncate (C : ChainComplex V ℕ) : augment (truncate.obj C) (C.d 1 0) (C.d_comp_d _ _ _) ≅ C where hom := { f := fun | 0 => 𝟙 _ | n+1 => 𝟙 _ comm' := fun i j => by -- Porting note: was an rcases n with (_|_|n) but that was causing issues match i with | 0 | 1 | n+2 => cases' j with j <;> dsimp [augment, truncate] <;> simp } inv := { f := fun | 0 => 𝟙 _ | n+1 => 𝟙 _ comm' := fun i j => by -- Porting note: was an rcases n with (_|_|n) but that was causing issues match i with | 0 | 1 | n+2 => cases' j with j <;> dsimp [augment, truncate] <;> simp } hom_inv_id := by ext i cases i <;> · dsimp simp inv_hom_id := by ext i cases i <;> · dsimp simp @[simp] theorem augmentTruncate_hom_f_zero (C : ChainComplex V ℕ) : (augmentTruncate C).hom.f 0 = 𝟙 (C.X 0) := rfl @[simp] theorem augmentTruncate_hom_f_succ (C : ChainComplex V ℕ) (i : ℕ) : (augmentTruncate C).hom.f (i + 1) = 𝟙 (C.X (i + 1)) := rfl @[simp] theorem augmentTruncate_inv_f_zero (C : ChainComplex V ℕ) : (augmentTruncate C).inv.f 0 = 𝟙 (C.X 0) := rfl @[simp] theorem augmentTruncate_inv_f_succ (C : ChainComplex V ℕ) (i : ℕ) : (augmentTruncate C).inv.f (i + 1) = 𝟙 (C.X (i + 1)) := rfl /-- A chain map from a chain complex to a single object chain complex in degree zero can be reinterpreted as a chain complex. This is the inverse construction of `truncateTo`. -/ def toSingle₀AsComplex [HasZeroObject V] (C : ChainComplex V ℕ) (X : V) (f : C ⟶ (single₀ V).obj X) : ChainComplex V ℕ := let ⟨f, w⟩ := toSingle₀Equiv C X f augment C f w end ChainComplex namespace CochainComplex /-- The truncation of an `ℕ`-indexed cochain complex, deleting the object at `0` and shifting everything else down. -/ @[simps] def truncate [HasZeroMorphisms V] : CochainComplex V ℕ ⥤ CochainComplex V ℕ where obj C := { X := fun i => C.X (i + 1) d := fun i j => C.d (i + 1) (j + 1) shape := fun i j w => by apply C.shape simpa } map f := { f := fun i => f.f (i + 1) } /-- There is a canonical chain map from the truncation of a cochain complex `C` to the "single object" cochain complex consisting of the truncated object `C.X 0` in degree 0. The components of this chain map are `C.d 0 1` in degree 0, and zero otherwise. -/ def toTruncate [HasZeroObject V] [HasZeroMorphisms V] (C : CochainComplex V ℕ) : (single₀ V).obj (C.X 0) ⟶ truncate.obj C := (fromSingle₀Equiv (truncate.obj C) (C.X 0)).symm ⟨C.d 0 1, by aesop⟩ variable [HasZeroMorphisms V] /-- We can "augment" a cochain complex by inserting an arbitrary object in degree zero (shifting everything else up), along with a suitable differential. -/ def augment (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) : CochainComplex V ℕ where X | 0 => X | i + 1 => C.X i d | 0, 1 => f | i + 1, j + 1 => C.d i j | _, _ => 0 shape i j s := by simp? at s says simp only [ComplexShape.up_Rel] at s rcases j with (_ | _ | j) <;> cases i <;> try simp · contradiction · rw [C.shape] simp only [ComplexShape.up_Rel] contrapose! s rw [← s] d_comp_d' i j k hij hjk := by rcases k with (_ | _ | k) <;> rcases j with (_ | _ | j) <;> cases i <;> try simp cases k · exact w · rw [C.shape, comp_zero] simp only [Nat.zero_eq, ComplexShape.up_Rel, zero_add] exact (Nat.one_lt_succ_succ _).ne @[simp] theorem augment_X_zero (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) : (augment C f w).X 0 = X := rfl @[simp] theorem augment_X_succ (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) : (augment C f w).X (i + 1) = C.X i := rfl @[simp] theorem augment_d_zero_one (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) : (augment C f w).d 0 1 = f := rfl @[simp] theorem augment_d_succ_succ (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i j : ℕ) : (augment C f w).d (i + 1) (j + 1) = C.d i j := rfl /-- Truncating an augmented cochain complex is isomorphic (with components the identity) to the original complex. -/ def truncateAugment (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) : truncate.obj (augment C f w) ≅ C where hom := { f := fun i => 𝟙 _ } inv := { f := fun i => 𝟙 _ comm' := fun i j => by cases j <;> · dsimp simp } hom_inv_id := by ext i cases i <;> · dsimp simp inv_hom_id := by ext i cases i <;> · dsimp simp @[simp] theorem truncateAugment_hom_f (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) : (truncateAugment C f w).hom.f i = 𝟙 (C.X i) := rfl @[simp] theorem truncateAugment_inv_f (C : CochainComplex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) : (truncateAugment C f w).inv.f i = 𝟙 ((truncate.obj (augment C f w)).X i) := rfl @[simp] theorem cochainComplex_d_succ_succ_zero (C : CochainComplex V ℕ) (i : ℕ) : C.d 0 (i + 2) = 0 := by rw [C.shape] simp only [ComplexShape.up_Rel, zero_add] exact (Nat.one_lt_succ_succ _).ne /-- Augmenting a truncated complex with the original object and morphism is isomorphic (with components the identity) to the original complex. -/ def augmentTruncate (C : CochainComplex V ℕ) : augment (truncate.obj C) (C.d 0 1) (C.d_comp_d _ _ _) ≅ C where hom := { f := fun | 0 => 𝟙 _ | n+1 => 𝟙 _ comm' := fun i j => by rcases j with (_ | _ | j) <;> cases i <;> · dsimp -- Porting note (#10959): simp can't handle this now but aesop does aesop } inv := { f := fun | 0 => 𝟙 _ | n+1 => 𝟙 _ comm' := fun i j => by rcases j with (_ | _ | j) <;> cases' i with i <;> · dsimp -- Porting note (#10959): simp can't handle this now but aesop does aesop } hom_inv_id := by ext i cases i <;> · dsimp simp inv_hom_id := by ext i cases i <;> · dsimp simp @[simp] theorem augmentTruncate_hom_f_zero (C : CochainComplex V ℕ) : (augmentTruncate C).hom.f 0 = 𝟙 (C.X 0) := rfl @[simp] theorem augmentTruncate_hom_f_succ (C : CochainComplex V ℕ) (i : ℕ) : (augmentTruncate C).hom.f (i + 1) = 𝟙 (C.X (i + 1)) := rfl @[simp] theorem augmentTruncate_inv_f_zero (C : CochainComplex V ℕ) : (augmentTruncate C).inv.f 0 = 𝟙 (C.X 0) := rfl @[simp] theorem augmentTruncate_inv_f_succ (C : CochainComplex V ℕ) (i : ℕ) : (augmentTruncate C).inv.f (i + 1) = 𝟙 (C.X (i + 1)) := rfl /-- A chain map from a single object cochain complex in degree zero to a cochain complex can be reinterpreted as a cochain complex. This is the inverse construction of `toTruncate`. -/ def fromSingle₀AsComplex [HasZeroObject V] (C : CochainComplex V ℕ) (X : V) (f : (single₀ V).obj X ⟶ C) : CochainComplex V ℕ := let ⟨f, w⟩ := fromSingle₀Equiv C X f augment C f w end CochainComplex
Algebra\Homology\Bifunctor.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.TotalComplex import Mathlib.CategoryTheory.GradedObject.Bifunctor /-! # The action of a bifunctor on homological complexes Given a bifunctor `F : C₁ ⥤ C₂ ⥤ D` and complexes shapes `c₁ : ComplexShape I₁` and `c₂ : ComplexShape I₂`, we define a bifunctor `mapBifunctorHomologicalComplex F c₁ c₂` of type `HomologicalComplex C₁ c₁ ⥤ HomologicalComplex C₂ c₂ ⥤ HomologicalComplex₂ D c₁ c₂`. Then, when `K₁ : HomologicalComplex C₁ c₁`, `K₂ : HomologicalComplex C₂ c₂` and `c : ComplexShape J` are such that we have `TotalComplexShape c₁ c₂ c`, we introduce a typeclass `HasMapBifunctor K₁ K₂ F c` which allows to define `mapBifunctor K₁ K₂ F c : HomologicalComplex D c` as the total complex of the bicomplex `(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂)`. -/ open CategoryTheory Limits variable {C₁ C₂ D : Type*} [Category C₁] [Category C₂] [Category D] namespace CategoryTheory namespace Functor variable [HasZeroMorphisms C₁] [HasZeroMorphisms C₂] [HasZeroMorphisms D] (F : C₁ ⥤ C₂ ⥤ D) {I₁ I₂ J : Type*} (c₁ : ComplexShape I₁) (c₂ : ComplexShape I₂) [F.PreservesZeroMorphisms] [∀ X₁, (F.obj X₁).PreservesZeroMorphisms] variable {c₁} in /-- Auxiliary definition for `mapBifunctorHomologicalComplex`. -/ @[simps!] def mapBifunctorHomologicalComplexObj (K₁ : HomologicalComplex C₁ c₁) : HomologicalComplex C₂ c₂ ⥤ HomologicalComplex₂ D c₁ c₂ where obj K₂ := HomologicalComplex₂.ofGradedObject c₁ c₂ (((GradedObject.mapBifunctor F I₁ I₂).obj K₁.X).obj K₂.X) (fun i₁ i₁' i₂ => (F.map (K₁.d i₁ i₁')).app (K₂.X i₂)) (fun i₁ i₂ i₂' => (F.obj (K₁.X i₁)).map (K₂.d i₂ i₂')) (fun i₁ i₁' h₁ i₂ => by dsimp rw [K₁.shape _ _ h₁, Functor.map_zero, zero_app]) (fun i₁ i₂ i₂' h₂ => by dsimp rw [K₂.shape _ _ h₂, Functor.map_zero]) (fun i₁ i₁' i₁'' i₂ => by dsimp rw [← NatTrans.comp_app, ← Functor.map_comp, HomologicalComplex.d_comp_d, Functor.map_zero, zero_app]) (fun i₁ i₂ i₂' i₂'' => by dsimp rw [← Functor.map_comp, HomologicalComplex.d_comp_d, Functor.map_zero]) (fun i₁ i₁' i₂ i₂' => by dsimp rw [NatTrans.naturality]) map {K₂ K₂' φ} := HomologicalComplex₂.homMk (((GradedObject.mapBifunctor F I₁ I₂).obj K₁.X).map φ.f) (by dsimp; intros; rw [NatTrans.naturality]) (by dsimp intros simp only [← Functor.map_comp, φ.comm]) map_id K₂ := by dsimp; ext; dsimp; rw [Functor.map_id] map_comp f g := by dsimp; ext; dsimp; rw [Functor.map_comp] /-- Given a functor `F : C₁ ⥤ C₂ ⥤ D`, this is the bifunctor which sends `K₁ : HomologicalComplex C₁ c₁` and `K₂ : HomologicalComplex C₂ c₂` to the bicomplex which is degree `(i₁, i₂)` consists of `(F.obj (K₁.X i₁)).obj (K₂.X i₂)`. -/ @[simps! obj_obj_X_X obj_obj_X_d obj_obj_d_f obj_map_f_f map_app_f_f] def mapBifunctorHomologicalComplex : HomologicalComplex C₁ c₁ ⥤ HomologicalComplex C₂ c₂ ⥤ HomologicalComplex₂ D c₁ c₂ where obj := mapBifunctorHomologicalComplexObj F c₂ map {K₁ K₁'} f := { app := fun K₂ => HomologicalComplex₂.homMk (((GradedObject.mapBifunctor F I₁ I₂).map f.f).app K₂.X) (by intros dsimp simp only [← NatTrans.comp_app, ← F.map_comp, f.comm]) (by simp) } variable {c₁ c₂} @[simp] lemma mapBifunctorHomologicalComplex_obj_obj_toGradedObject (K₁ : HomologicalComplex C₁ c₁) (K₂ : HomologicalComplex C₂ c₂) : (((mapBifunctorHomologicalComplex F c₁ c₂).obj K₁).obj K₂).toGradedObject = ((GradedObject.mapBifunctor F I₁ I₂).obj K₁.X).obj K₂.X := rfl end Functor end CategoryTheory namespace HomologicalComplex variable {I₁ I₂ J : Type*} {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} [HasZeroMorphisms C₁] [HasZeroMorphisms C₂] [Preadditive D] (K₁ L₁ : HomologicalComplex C₁ c₁) (K₂ L₂ : HomologicalComplex C₂ c₂) (f₁ : K₁ ⟶ L₁) (f₂ : K₂ ⟶ L₂) (F : C₁ ⥤ C₂ ⥤ D) [F.PreservesZeroMorphisms] [∀ X₁, (F.obj X₁).PreservesZeroMorphisms] (c : ComplexShape J) [TotalComplexShape c₁ c₂ c] /-- The condition that `((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂` has a total complex. -/ abbrev HasMapBifunctor := (((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).HasTotal c variable [HasMapBifunctor K₁ K₂ F c] [HasMapBifunctor L₁ L₂ F c] [DecidableEq J] /-- Given `K₁ : HomologicalComplex C₁ c₁`, `K₂ : HomologicalComplex C₂ c₂`, a bifunctor `F : C₁ ⥤ C₂ ⥤ D` and a complex shape `ComplexShape J` such that we have `[TotalComplexShape c₁ c₂ c]`, this `mapBifunctor K₁ K₂ F c : HomologicalComplex D c` is the total complex of the bicomplex obtained by applying `F` to `K₁` and `K₂`. -/ noncomputable abbrev mapBifunctor : HomologicalComplex D c := (((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).total c /-- The inclusion of a summand of `(mapBifunctor K₁ K₂ F c).X j`. -/ noncomputable abbrev ιMapBifunctor (i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₁ c₂ c (i₁, i₂) = j) : (F.obj (K₁.X i₁)).obj (K₂.X i₂) ⟶ (mapBifunctor K₁ K₂ F c).X j := (((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).ιTotal c i₁ i₂ j h /-- The inclusion of a summand of `(mapBifunctor K₁ K₂ F c).X j`, or zero. -/ noncomputable abbrev ιMapBifunctorOrZero (i₁ : I₁) (i₂ : I₂) (j : J) : (F.obj (K₁.X i₁)).obj (K₂.X i₂) ⟶ (mapBifunctor K₁ K₂ F c).X j := (((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).ιTotalOrZero c i₁ i₂ j lemma ιMapBifunctorOrZero_eq (i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₁ c₂ c (i₁, i₂) = j) : ιMapBifunctorOrZero K₁ K₂ F c i₁ i₂ j = ιMapBifunctor K₁ K₂ F c i₁ i₂ j h := dif_pos h lemma ιMapBifunctorOrZero_eq_zero (i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₁ c₂ c (i₁, i₂) ≠ j) : ιMapBifunctorOrZero K₁ K₂ F c i₁ i₂ j = 0 := dif_neg h section variable {K₁ K₂ L₁ L₂} /-- The morphism `mapBifunctor K₁ K₂ F c ⟶ mapBifunctor L₁ L₂ F c` induced by morphisms of complexes `K₁ ⟶ L₁` and `K₂ ⟶ L₂`. -/ noncomputable def mapBifunctorMap : mapBifunctor K₁ K₂ F c ⟶ mapBifunctor L₁ L₂ F c := HomologicalComplex₂.total.map (((F.mapBifunctorHomologicalComplex c₁ c₂).map f₁).app K₂ ≫ ((F.mapBifunctorHomologicalComplex c₁ c₂).obj L₁).map f₂) c @[reassoc (attr := simp)] lemma ι_mapBifunctorMap (i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₁ c₂ c (i₁, i₂) = j) : ιMapBifunctor K₁ K₂ F c i₁ i₂ j h ≫ (mapBifunctorMap f₁ f₂ F c).f j = (F.map (f₁.f i₁)).app (K₂.X i₂) ≫ (F.obj (L₁.X i₁)).map (f₂.f i₂) ≫ ιMapBifunctor L₁ L₂ F c i₁ i₂ j h := by simp [mapBifunctorMap] end end HomologicalComplex
Algebra\Homology\BifunctorHomotopy.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Bifunctor import Mathlib.Algebra.Homology.Homotopy /-! # The action of a bifunctor on homological complexes factors through homotopies Given a `TotalComplexShape c₁ c₂ c`, a functor `F : C₁ ⥤ C₂ ⥤ D`, we shall show in this file that up to homotopy the morphism `mapBifunctorMap f₁ f₂ F c` only depends on the homotopy classes of the morphism `f₁` in `HomologicalComplex C c₁` and of the morphism `f₂` in `HomologicalComplex C c₂` (TODO). -/ open CategoryTheory Category Limits variable {C₁ C₂ D I₁ I₂ J : Type*} [Category C₁] [Category C₂] [Category D] [Preadditive C₁] [Preadditive C₂] [Preadditive D] {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} namespace HomologicalComplex variable {K₁ L₁ : HomologicalComplex C₁ c₁} {f₁ f₁' : K₁ ⟶ L₁} (h₁ : Homotopy f₁ f₁') {K₂ L₂ : HomologicalComplex C₂ c₂} (f₂ : K₂ ⟶ L₂) (F : C₁ ⥤ C₂ ⥤ D) [F.Additive] [∀ X₁, (F.obj X₁).Additive] (c : ComplexShape J) [DecidableEq J] [TotalComplexShape c₁ c₂ c] [HasMapBifunctor K₁ K₂ F c] [HasMapBifunctor L₁ L₂ F c] namespace mapBifunctorMapHomotopy /-- Auxiliary definition for `mapBifunctorMapHomotopy₁`. -/ noncomputable def hom₁ (j j' : J) : (mapBifunctor K₁ K₂ F c).X j ⟶ (mapBifunctor L₁ L₂ F c).X j' := HomologicalComplex₂.totalDesc _ (fun i₁ i₂ _ => ComplexShape.ε₁ c₁ c₂ c (c₁.prev i₁, i₂) • (F.map (h₁.hom i₁ (c₁.prev i₁))).app (K₂.X i₂) ≫ (F.obj (L₁.X (c₁.prev i₁))).map (f₂.f i₂) ≫ ιMapBifunctorOrZero L₁ L₂ F c _ _ j') @[reassoc] lemma ιMapBifunctor_hom₁ (i₁ i₁' : I₁) (i₂ : I₂) (j j' : J) (h : ComplexShape.π c₁ c₂ c (i₁', i₂) = j) (h' : c₁.prev i₁' = i₁) : ιMapBifunctor K₁ K₂ F c i₁' i₂ j h ≫ hom₁ h₁ f₂ F c j j' = ComplexShape.ε₁ c₁ c₂ c (i₁, i₂) • (F.map (h₁.hom i₁' i₁)).app (K₂.X i₂) ≫ (F.obj (L₁.X i₁)).map (f₂.f i₂) ≫ ιMapBifunctorOrZero L₁ L₂ F c _ _ j' := by subst h' simp [hom₁] lemma zero₁ (j j' : J) (h : ¬ c.Rel j' j) : hom₁ h₁ f₂ F c j j' = 0 := by ext i₁ i₂ h' dsimp [hom₁] rw [comp_zero, HomologicalComplex₂.ι_totalDesc] by_cases h₃ : c₁.Rel (c₁.prev i₁) i₁ · rw [ιMapBifunctorOrZero_eq_zero, comp_zero, comp_zero, smul_zero] intro h₄ apply h rw [← h', ← h₄] exact ComplexShape.rel_π₁ c₂ c h₃ i₂ · dsimp rw [h₁.zero _ _ h₃, Functor.map_zero, zero_app, zero_comp, smul_zero] lemma comm₁_aux {i₁ i₁' : I₁} (hi₁ : c₁.Rel i₁ i₁') {i₂ i₂' : I₂} (hi₂ : c₂.Rel i₂ i₂') (j : J) (hj : ComplexShape.π c₁ c₂ c (i₁', i₂) = j) : ComplexShape.ε₁ c₁ c₂ c (i₁, i₂) • (F.map (h₁.hom i₁' i₁)).app (K₂.X i₂) ≫ (F.obj (L₁.X i₁)).map (f₂.f i₂) ≫ (((F.mapBifunctorHomologicalComplex c₁ c₂).obj L₁).obj L₂).d₂ c i₁ i₂ j = -(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).d₂ c i₁' i₂ (c.next j) ≫ hom₁ h₁ f₂ F c (c.next j) j := by have hj' : ComplexShape.π c₁ c₂ c ⟨i₁, i₂'⟩ = j := by rw [← hj, ← ComplexShape.next_π₂ c₁ c i₁ hi₂, ComplexShape.next_π₁ c₂ c hi₁ i₂] rw [HomologicalComplex₂.d₂_eq _ _ _ hi₂ _ hj', HomologicalComplex₂.d₂_eq _ _ _ hi₂ _ (by rw [← c.next_eq' (ComplexShape.rel_π₂ c₁ c i₁' hi₂), hj]), Linear.comp_units_smul, Linear.comp_units_smul, Linear.units_smul_comp, assoc, ιMapBifunctor_hom₁ _ _ _ _ _ _ _ _ _ _ (c₁.prev_eq' hi₁), ιMapBifunctorOrZero_eq _ _ _ _ _ _ _ hj', Linear.comp_units_smul, smul_smul, smul_smul, Functor.mapBifunctorHomologicalComplex_obj_obj_X_d, Functor.mapBifunctorHomologicalComplex_obj_obj_X_d, NatTrans.naturality_assoc, ComplexShape.ε₁_ε₂ c hi₁ hi₂, neg_mul, Units.neg_smul, neg_inj, smul_left_cancel_iff, ← Functor.map_comp_assoc, ← Functor.map_comp_assoc, f₂.comm] lemma comm₁ (j : J) : (mapBifunctorMap f₁ f₂ F c).f j = (mapBifunctor K₁ K₂ F c).d j (c.next j) ≫ mapBifunctorMapHomotopy.hom₁ h₁ f₂ F c (c.next j) j + mapBifunctorMapHomotopy.hom₁ h₁ f₂ F c j (c.prev j) ≫ (mapBifunctor L₁ L₂ F c).d (c.prev j) j + (mapBifunctorMap f₁' f₂ F c).f j := by ext i₁ i₂ h simp? [h₁.comm i₁, dFrom, fromNext, toPrev, dTo] says simp only [Functor.mapBifunctorHomologicalComplex_obj_obj_X_X, ι_mapBifunctorMap, h₁.comm i₁, dNext_eq_dFrom_fromNext, dFrom, fromNext, AddMonoidHom.mk'_apply, prevD_eq_toPrev_dTo, toPrev, dTo, Functor.map_add, Functor.map_comp, NatTrans.app_add, NatTrans.comp_app, Preadditive.add_comp, assoc, HomologicalComplex₂.total_d, Functor.mapBifunctorHomologicalComplex_obj_obj_toGradedObject, Preadditive.comp_add, HomologicalComplex₂.ι_D₁_assoc, HomologicalComplex₂.ι_D₂_assoc, add_left_inj] have : ∀ {X Y : D} (a b c d e f : X ⟶ Y), a = c → b = e → f = -d → a + b = c + d + (e + f) := by rintro X Y a b _ d _ _ rfl rfl rfl; abel apply this · by_cases h₃ : c₁.Rel i₁ (c₁.next i₁) · rw [HomologicalComplex₂.d₁_eq _ _ h₃ _ _ (by rw [← h, ComplexShape.next_π₁ c₂ c h₃]), Functor.mapBifunctorHomologicalComplex_obj_obj_d_f, Linear.units_smul_comp, assoc, ιMapBifunctor_hom₁ _ _ _ _ i₁ _ _ _ _ _ (c₁.prev_eq' h₃), Linear.comp_units_smul, smul_smul, Int.units_mul_self, one_smul, ιMapBifunctorOrZero_eq] · rw [K₁.shape _ _ h₃, Functor.map_zero, zero_app, zero_comp, HomologicalComplex₂.d₁_eq_zero _ _ _ _ _ h₃, zero_comp] · rw [ιMapBifunctor_hom₁_assoc _ _ _ _ _ _ _ _ _ _ rfl] by_cases h₃ : c₁.Rel (c₁.prev i₁) i₁ · rw [ιMapBifunctorOrZero_eq _ _ _ _ _ _ _ (by rw [← ComplexShape.prev_π₁ c₂ c h₃, h]), Linear.units_smul_comp, assoc, assoc, HomologicalComplex₂.ι_D₁, HomologicalComplex₂.d₁_eq _ _ h₃ _ _ h, Linear.comp_units_smul, Linear.comp_units_smul, smul_smul, Int.units_mul_self, one_smul, Functor.mapBifunctorHomologicalComplex_obj_obj_d_f, NatTrans.naturality_assoc] · rw [h₁.zero _ _ h₃, Functor.map_zero, zero_app, zero_comp, zero_comp, smul_zero, zero_comp] · rw [ιMapBifunctor_hom₁_assoc _ _ _ _ _ _ _ _ _ _ rfl] by_cases h₃ : c₁.Rel (c₁.prev i₁) i₁ · dsimp rw [Linear.units_smul_comp, assoc, assoc, ιMapBifunctorOrZero_eq _ _ _ _ _ _ _ (by rw [← ComplexShape.prev_π₁ c₂ c h₃, h]), HomologicalComplex₂.ι_D₂] by_cases h₄ : c₂.Rel i₂ (c₂.next i₂) · exact comm₁_aux h₁ f₂ F c h₃ h₄ j h · rw [HomologicalComplex₂.d₂_eq_zero _ _ _ _ _ h₄, comp_zero, comp_zero, smul_zero, HomologicalComplex₂.d₂_eq_zero _ _ _ _ _ h₄, zero_comp, neg_zero] · rw [h₁.zero _ _ h₃, Functor.map_zero, zero_app, zero_comp, smul_zero, zero_comp, zero_eq_neg] by_cases h₄ : c₂.Rel i₂ (c₂.next i₂) · by_cases h₅ : c.Rel j (c.next j) · rw [HomologicalComplex₂.d₂_eq _ _ _ h₄ _ (by rw [← ComplexShape.next_π₂ c₁ c i₁ h₄, h]), Linear.units_smul_comp, assoc, Functor.mapBifunctorHomologicalComplex_obj_obj_X_d, ιMapBifunctor_hom₁ _ _ _ _ _ _ _ _ _ _ rfl, h₁.zero _ _ h₃, Functor.map_zero, zero_app, zero_comp, smul_zero, comp_zero, smul_zero] · rw [zero₁ _ _ _ _ _ _ h₅, comp_zero] · rw [HomologicalComplex₂.d₂_eq_zero _ _ _ _ _ h₄, zero_comp] end mapBifunctorMapHomotopy open mapBifunctorMapHomotopy in /-- The homotopy between `mapBifunctorMap f₁ f₂ F c` and `mapBifunctorMap f₁' f₂ F c` that is induced by an homotopy between `f₁` and `f₁'`. -/ noncomputable def mapBifunctorMapHomotopy₁ : Homotopy (mapBifunctorMap f₁ f₂ F c) (mapBifunctorMap f₁' f₂ F c) where hom := hom₁ h₁ f₂ F c zero := zero₁ h₁ f₂ F c comm := comm₁ h₁ f₂ F c end HomologicalComplex
Algebra\Homology\BifunctorShift.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Bifunctor import Mathlib.Algebra.Homology.TotalComplexShift /-! # Behavior of the action of a bifunctor on cochain complexes with respect to shifts In this file, given cochain complexes `K₁ : CochainComplex C₁ ℤ`, `K₂ : CochainComplex C₂ ℤ` and a functor `F : C₁ ⥤ C₂ ⥤ D`, we define an isomorphism of cochain complexes in `D`: - `CochainComplex.mapBifunctorShift₁Iso K₁ K₂ F x` of type `mapBifunctor (K₁⟦x⟧) K₂ F ≅ (mapBifunctor K₁ K₂ F)⟦x⟧` for `x : ℤ`. - `CochainComplex.mapBifunctorShift₂Iso K₁ K₂ F y` of type `mapBifunctor K₁ (K₂⟦y⟧) F ≅ (mapBifunctor K₁ K₂ F)⟦y⟧` for `y : ℤ`. In the lemma `CochainComplex.mapBifunctorShift₁Iso_trans_mapBifunctorShift₂Iso`, we obtain that the two ways to deduce an isomorphism `mapBifunctor (K₁⟦x⟧) (K₂⟦y⟧) F ≅ (mapBifunctor K₁ K₂ F)⟦x + y⟧` differ by the sign `(x * y).negOnePow`. -/ open CategoryTheory Category Limits variable {C₁ C₂ D : Type*} [Category C₁] [Category C₂] [Category D] namespace CochainComplex section variable [HasZeroMorphisms C₁] [HasZeroMorphisms C₂] (K₁ : CochainComplex C₁ ℤ) (K₂ : CochainComplex C₂ ℤ) [Preadditive D] (F : C₁ ⥤ C₂ ⥤ D) [F.PreservesZeroMorphisms] [∀ (X₁ : C₁), (F.obj X₁).PreservesZeroMorphisms] /-- The condition that `((F.mapBifunctorHomologicalComplex _ _).obj K₁).obj K₂` has a total cochain complex. -/ abbrev HasMapBifunctor := HomologicalComplex.HasMapBifunctor K₁ K₂ F (ComplexShape.up ℤ) /-- Given `K₁ : CochainComplex C₁ ℤ`, `K₂ : CochainComplex C₂ ℤ`, a bifunctor `F : C₁ ⥤ C₂ ⥤ D`, this `mapBifunctor K₁ K₂ F : CochainComplex D ℤ` is the total complex of the bicomplex obtained by applying `F` to `K₁` and `K₂`. -/ noncomputable abbrev mapBifunctor [HasMapBifunctor K₁ K₂ F] : CochainComplex D ℤ := HomologicalComplex.mapBifunctor K₁ K₂ F (ComplexShape.up ℤ) /-- The inclusion of a summand `(F.obj (K₁.X n₁)).obj (K₂.X n₂) ⟶ (mapBifunctor K₁ K₂ F).X n` of the total cochain complex when `n₁ + n₂ = n`. -/ noncomputable abbrev ιMapBifunctor [HasMapBifunctor K₁ K₂ F] (n₁ n₂ n : ℤ) (h : n₁ + n₂ = n) : (F.obj (K₁.X n₁)).obj (K₂.X n₂) ⟶ (mapBifunctor K₁ K₂ F).X n := HomologicalComplex.ιMapBifunctor K₁ K₂ F _ _ _ _ h end section variable [Preadditive C₁] [HasZeroMorphisms C₂] [Preadditive D] (K₁ : CochainComplex C₁ ℤ) (K₂ : CochainComplex C₂ ℤ) (F : C₁ ⥤ C₂ ⥤ D) [F.Additive] [∀ (X₁ : C₁), (F.obj X₁).PreservesZeroMorphisms] (x : ℤ) [HasMapBifunctor K₁ K₂ F] /-- Auxiliary definition for `mapBifunctorShift₁Iso`. -/ @[simps! hom_f_f inv_f_f] def mapBifunctorHomologicalComplexShift₁Iso : ((F.mapBifunctorHomologicalComplex _ _).obj (K₁⟦x⟧)).obj K₂ ≅ (HomologicalComplex₂.shiftFunctor₁ D x).obj (((F.mapBifunctorHomologicalComplex _ _).obj K₁).obj K₂) := HomologicalComplex.Hom.isoOfComponents (fun i₁ => Iso.refl _) instance : HasMapBifunctor (K₁⟦x⟧) K₂ F := HomologicalComplex₂.hasTotal_of_iso (mapBifunctorHomologicalComplexShift₁Iso K₁ K₂ F x).symm _ /-- The canonical isomorphism `mapBifunctor (K₁⟦x⟧) K₂ F ≅ (mapBifunctor K₁ K₂ F)⟦x⟧`. This isomorphism does not involve signs. -/ noncomputable def mapBifunctorShift₁Iso : mapBifunctor (K₁⟦x⟧) K₂ F ≅ (mapBifunctor K₁ K₂ F)⟦x⟧ := HomologicalComplex₂.total.mapIso (mapBifunctorHomologicalComplexShift₁Iso K₁ K₂ F x) _ ≪≫ (((F.mapBifunctorHomologicalComplex _ _).obj K₁).obj K₂).totalShift₁Iso x end section variable [HasZeroMorphisms C₁] [Preadditive C₂] [Preadditive D] (K₁ : CochainComplex C₁ ℤ) (K₂ : CochainComplex C₂ ℤ) (F : C₁ ⥤ C₂ ⥤ D) [F.PreservesZeroMorphisms] [∀ (X₁ : C₁), (F.obj X₁).Additive] (y : ℤ) [HasMapBifunctor K₁ K₂ F] /-- Auxiliary definition for `mapBifunctorShift₂Iso`. -/ @[simps! hom_f_f inv_f_f] def mapBifunctorHomologicalComplexShift₂Iso : ((F.mapBifunctorHomologicalComplex _ _).obj K₁).obj (K₂⟦y⟧) ≅ (HomologicalComplex₂.shiftFunctor₂ D y).obj (((F.mapBifunctorHomologicalComplex _ _).obj K₁).obj K₂) := HomologicalComplex.Hom.isoOfComponents (fun i₁ => HomologicalComplex.Hom.isoOfComponents (fun i₂ => Iso.refl _)) instance : HasMapBifunctor K₁ (K₂⟦y⟧) F := HomologicalComplex₂.hasTotal_of_iso (mapBifunctorHomologicalComplexShift₂Iso K₁ K₂ F y).symm _ /-- The canonical isomorphism `mapBifunctor K₁ (K₂⟦y⟧) F ≅ (mapBifunctor K₁ K₂ F)⟦y⟧`. This isomorphism involves signs: on the summand `(F.obj (K₁.X p)).obj (K₂.X q)`, it is given by the multiplication by `(p * y).negOnePow`. -/ noncomputable def mapBifunctorShift₂Iso : mapBifunctor K₁ (K₂⟦y⟧) F ≅ (mapBifunctor K₁ K₂ F)⟦y⟧ := HomologicalComplex₂.total.mapIso (mapBifunctorHomologicalComplexShift₂Iso K₁ K₂ F y) (ComplexShape.up ℤ) ≪≫ (((F.mapBifunctorHomologicalComplex _ _).obj K₁).obj K₂).totalShift₂Iso y end section variable [Preadditive C₁] [Preadditive C₂] [Preadditive D] (K₁ : CochainComplex C₁ ℤ) (K₂ : CochainComplex C₂ ℤ) (F : C₁ ⥤ C₂ ⥤ D) [F.Additive] [∀ (X₁ : C₁), (F.obj X₁).Additive] (x y : ℤ) [HasMapBifunctor K₁ K₂ F] lemma mapBifunctorShift₁Iso_trans_mapBifunctorShift₂Iso : mapBifunctorShift₁Iso K₁ (K₂⟦y⟧) F x ≪≫ (CategoryTheory.shiftFunctor _ x).mapIso (mapBifunctorShift₂Iso K₁ K₂ F y) = (x * y).negOnePow • (mapBifunctorShift₂Iso (K₁⟦x⟧) K₂ F y ≪≫ (CategoryTheory.shiftFunctor _ y).mapIso (mapBifunctorShift₁Iso K₁ K₂ F x) ≪≫ (shiftFunctorComm (CochainComplex D ℤ) x y).app _) := by ext1 dsimp [mapBifunctorShift₁Iso, mapBifunctorShift₂Iso] rw [Functor.map_comp, Functor.map_comp, assoc, assoc, assoc, ← HomologicalComplex₂.totalShift₁Iso_hom_naturality_assoc, HomologicalComplex₂.totalShift₁Iso_hom_totalShift₂Iso_hom, ← HomologicalComplex₂.totalShift₂Iso_hom_naturality_assoc, Linear.comp_units_smul, Linear.comp_units_smul, smul_left_cancel_iff, ← HomologicalComplex₂.total.map_comp_assoc, ← HomologicalComplex₂.total.map_comp_assoc, ← HomologicalComplex₂.total.map_comp_assoc] congr 2 ext a b dsimp [HomologicalComplex₂.shiftFunctor₁₂CommIso] simp only [id_comp] end end CochainComplex
Algebra\Homology\CommSq.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Preadditive.Biproducts /-! # Relation between pullback/pushout squares and kernel/cokernel sequences Consider a commutative square in a preadditive category: ``` X₁ ⟶ X₂ | | v v X₃ ⟶ X₄ ``` In this file, we show that this is a pushout square iff the object `X₄` identifies to the cokernel of the difference map `X₁ ⟶ X₂ ⊞ X₃` via the obvious map `X₂ ⊞ X₃ ⟶ X₄`. Similarly, it is a pullback square iff the object `X₁` identifies to the kernel of the difference map `X₂ ⊞ X₃ ⟶ X₄` via the obvious map `X₁ ⟶ X₂ ⊞ X₃`. -/ namespace CategoryTheory open Category Limits variable {C : Type*} [Category C] [Preadditive C] {X₁ X₂ X₃ X₄ : C} [HasBinaryBiproduct X₂ X₃] section Pushout variable {f : X₁ ⟶ X₂} {g : X₁ ⟶ X₃} {inl : X₂ ⟶ X₄} {inr : X₃ ⟶ X₄} /-- The cokernel cofork attached to a commutative square in a preadditive category. -/ noncomputable abbrev CommSq.cokernelCofork (sq : CommSq f g inl inr) : CokernelCofork (biprod.lift f (-g)) := CokernelCofork.ofπ (biprod.desc inl inr) (by simp [sq.w]) /-- A commutative square in a preadditive category is a pushout square iff the corresponding diagram `X₁ ⟶ X₂ ⊞ X₃ ⟶ X₄ ⟶ 0` makes `X₄` a cokernel. -/ noncomputable def CommSq.isColimitEquivIsColimitCokernelCofork (sq : CommSq f g inl inr) : IsColimit (PushoutCocone.mk _ _ sq.w) ≃ IsColimit sq.cokernelCofork where toFun h := Cofork.IsColimit.mk _ (fun s ↦ PushoutCocone.IsColimit.desc h (biprod.inl ≫ s.π) (biprod.inr ≫ s.π) (by rw [← sub_eq_zero, ← assoc, ← assoc, ← Preadditive.sub_comp] convert s.condition <;> aesop_cat)) (fun s ↦ by dsimp ext · simp only [biprod.inl_desc_assoc] apply PushoutCocone.IsColimit.inl_desc h · simp only [biprod.inr_desc_assoc] apply PushoutCocone.IsColimit.inr_desc h) (fun s m hm ↦ by apply PushoutCocone.IsColimit.hom_ext h · replace hm := biprod.inl ≫= hm dsimp at hm ⊢ simp only [biprod.inl_desc_assoc] at hm rw [hm] symm apply PushoutCocone.IsColimit.inl_desc h · replace hm := biprod.inr ≫= hm dsimp at hm ⊢ simp only [biprod.inr_desc_assoc] at hm rw [hm] symm apply PushoutCocone.IsColimit.inr_desc h) invFun h := PushoutCocone.IsColimit.mk _ (fun s ↦ h.desc (CokernelCofork.ofπ (biprod.desc s.inl s.inr) (by simp [s.condition]))) (fun s ↦ by simpa using biprod.inl ≫= h.fac (CokernelCofork.ofπ (biprod.desc s.inl s.inr) (by simp [s.condition])) .one) (fun s ↦ by simpa using biprod.inr ≫= h.fac (CokernelCofork.ofπ (biprod.desc s.inl s.inr) (by simp [s.condition])) .one) (fun s m hm₁ hm₂ ↦ by apply Cofork.IsColimit.hom_ext h convert (h.fac (CokernelCofork.ofπ (biprod.desc s.inl s.inr) (by simp [s.condition])) .one).symm aesop_cat) left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- The colimit cokernel cofork attached to a pushout square. -/ noncomputable def IsPushout.isColimitCokernelCofork (h : IsPushout f g inl inr) : IsColimit h.cokernelCofork := h.isColimitEquivIsColimitCokernelCofork h.isColimit end Pushout section Pullback variable {fst : X₁ ⟶ X₂} {snd : X₁ ⟶ X₃} {f : X₂ ⟶ X₄} {g : X₃ ⟶ X₄} /-- The kernel fork attached to a commutative square in a preadditive category. -/ noncomputable abbrev CommSq.kernelFork (sq : CommSq fst snd f g) : KernelFork (biprod.desc f (-g)) := KernelFork.ofι (biprod.lift fst snd) (by simp [sq.w]) /-- A commutative square in a preadditive category is a pullback square iff the corresponding diagram `0 ⟶ X₁ ⟶ X₂ ⊞ X₃ ⟶ X₄ ⟶ 0` makes `X₁` a kernel. -/ noncomputable def CommSq.isLimitEquivIsLimitKernelFork (sq : CommSq fst snd f g) : IsLimit (PullbackCone.mk _ _ sq.w) ≃ IsLimit sq.kernelFork where toFun h := Fork.IsLimit.mk _ (fun s ↦ PullbackCone.IsLimit.lift h (s.ι ≫ biprod.fst) (s.ι ≫ biprod.snd) (by rw [← sub_eq_zero, assoc, assoc, ← Preadditive.comp_sub] convert s.condition <;> aesop_cat)) (fun s ↦ by dsimp ext · simp only [assoc, biprod.lift_fst] apply PullbackCone.IsLimit.lift_fst h · simp only [assoc, biprod.lift_snd] apply PullbackCone.IsLimit.lift_snd h) (fun s m hm ↦ by apply PullbackCone.IsLimit.hom_ext h · replace hm := hm =≫ biprod.fst dsimp at hm ⊢ simp only [assoc, biprod.lift_fst] at hm rw [hm] symm apply PullbackCone.IsLimit.lift_fst h · replace hm := hm =≫ biprod.snd dsimp at hm ⊢ simp only [assoc, biprod.lift_snd] at hm rw [hm] symm apply PullbackCone.IsLimit.lift_snd h) invFun h := PullbackCone.IsLimit.mk _ (fun s ↦ h.lift (KernelFork.ofι (biprod.lift s.fst s.snd) (by simp [s.condition]))) (fun s ↦ by simpa using h.fac (KernelFork.ofι (biprod.lift s.fst s.snd) (by simp [s.condition])) .zero =≫ biprod.fst) (fun s ↦ by simpa using h.fac (KernelFork.ofι (biprod.lift s.fst s.snd) (by simp [s.condition])) .zero =≫ biprod.snd) (fun s m hm₁ hm₂ ↦ by apply Fork.IsLimit.hom_ext h convert (h.fac (KernelFork.ofι (biprod.lift s.fst s.snd) (by simp [s.condition])) .zero).symm aesop_cat) left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- The limit kernel fork attached to a pullback square. -/ noncomputable def IsPullback.isLimitKernelFork (h : IsPullback fst snd f g) : IsLimit h.kernelFork := h.isLimitEquivIsLimitKernelFork h.isLimit end Pullback end CategoryTheory
Algebra\Homology\ComplexShape.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison -/ import Mathlib.Algebra.Group.Defs import Mathlib.Logic.Relation /-! # Shapes of homological complexes We define a structure `ComplexShape ι` for describing the shapes of homological complexes indexed by a type `ι`. This is intended to capture chain complexes and cochain complexes, indexed by either `ℕ` or `ℤ`, as well as more exotic examples. Rather than insisting that the indexing type has a `succ` function specifying where differentials should go, inside `c : ComplexShape` we have `c.Rel : ι → ι → Prop`, and when we define `HomologicalComplex` we only allow nonzero differentials `d i j` from `i` to `j` if `c.Rel i j`. Further, we require that `{ j // c.Rel i j }` and `{ i // c.Rel i j }` are subsingletons. This means that the shape consists of some union of lines, rays, intervals, and circles. Convenience functions `c.next` and `c.prev` provide these related elements when they exist, and return their input otherwise. This design aims to avoid certain problems arising from dependent type theory. In particular we never have to ensure morphisms `d i : X i ⟶ X (succ i)` compose as expected (which would often require rewriting by equations in the indexing type). Instead such identities become separate proof obligations when verifying that a complex we've constructed is of the desired shape. If `α` is an `AddRightCancelSemigroup`, then we define `up α : ComplexShape α`, the shape appropriate for cohomology, so `d : X i ⟶ X j` is nonzero only when `j = i + 1`, as well as `down α : ComplexShape α`, appropriate for homology, so `d : X i ⟶ X j` is nonzero only when `i = j + 1`. (Later we'll introduce `CochainComplex` and `ChainComplex` as abbreviations for `HomologicalComplex` with one of these shapes baked in.) -/ noncomputable section /-- A `c : ComplexShape ι` describes the shape of a chain complex, with chain groups indexed by `ι`. Typically `ι` will be `ℕ`, `ℤ`, or `Fin n`. There is a relation `Rel : ι → ι → Prop`, and we will only allow a non-zero differential from `i` to `j` when `Rel i j`. There are axioms which imply `{ j // c.Rel i j }` and `{ i // c.Rel i j }` are subsingletons. This means that the shape consists of some union of lines, rays, intervals, and circles. Below we define `c.next` and `c.prev` which provide these related elements. -/ @[ext] structure ComplexShape (ι : Type*) where /-- Nonzero differentials `X i ⟶ X j` shall be allowed on homological complexes when `Rel i j` holds. -/ Rel : ι → ι → Prop /-- There is at most one nonzero differential from `X i`. -/ next_eq : ∀ {i j j'}, Rel i j → Rel i j' → j = j' /-- There is at most one nonzero differential to `X j`. -/ prev_eq : ∀ {i i' j}, Rel i j → Rel i' j → i = i' namespace ComplexShape variable {ι : Type*} /-- The complex shape where only differentials from each `X.i` to itself are allowed. This is mostly only useful so we can describe the relation of "related in `k` steps" below. -/ @[simps] def refl (ι : Type*) : ComplexShape ι where Rel i j := i = j next_eq w w' := w.symm.trans w' prev_eq w w' := w.trans w'.symm /-- The reverse of a `ComplexShape`. -/ @[simps] def symm (c : ComplexShape ι) : ComplexShape ι where Rel i j := c.Rel j i next_eq w w' := c.prev_eq w w' prev_eq w w' := c.next_eq w w' @[simp] theorem symm_symm (c : ComplexShape ι) : c.symm.symm = c := by ext simp theorem symm_bijective : Function.Bijective (ComplexShape.symm : ComplexShape ι → ComplexShape ι) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- The "composition" of two `ComplexShape`s. We need this to define "related in k steps" later. -/ @[simp] def trans (c₁ c₂ : ComplexShape ι) : ComplexShape ι where Rel := Relation.Comp c₁.Rel c₂.Rel next_eq w w' := by obtain ⟨k, w₁, w₂⟩ := w obtain ⟨k', w₁', w₂'⟩ := w' rw [c₁.next_eq w₁ w₁'] at w₂ exact c₂.next_eq w₂ w₂' prev_eq w w' := by obtain ⟨k, w₁, w₂⟩ := w obtain ⟨k', w₁', w₂'⟩ := w' rw [c₂.prev_eq w₂ w₂'] at w₁ exact c₁.prev_eq w₁ w₁' instance subsingleton_next (c : ComplexShape ι) (i : ι) : Subsingleton { j // c.Rel i j } := by constructor rintro ⟨j, rij⟩ ⟨k, rik⟩ congr exact c.next_eq rij rik instance subsingleton_prev (c : ComplexShape ι) (j : ι) : Subsingleton { i // c.Rel i j } := by constructor rintro ⟨i, rik⟩ ⟨j, rjk⟩ congr exact c.prev_eq rik rjk open Classical in /-- An arbitrary choice of index `j` such that `Rel i j`, if such exists. Returns `i` otherwise. -/ def next (c : ComplexShape ι) (i : ι) : ι := if h : ∃ j, c.Rel i j then h.choose else i open Classical in /-- An arbitrary choice of index `i` such that `Rel i j`, if such exists. Returns `j` otherwise. -/ def prev (c : ComplexShape ι) (j : ι) : ι := if h : ∃ i, c.Rel i j then h.choose else j theorem next_eq' (c : ComplexShape ι) {i j : ι} (h : c.Rel i j) : c.next i = j := by apply c.next_eq _ h rw [next] rw [dif_pos] exact Exists.choose_spec ⟨j, h⟩ theorem prev_eq' (c : ComplexShape ι) {i j : ι} (h : c.Rel i j) : c.prev j = i := by apply c.prev_eq _ h rw [prev, dif_pos] exact Exists.choose_spec (⟨i, h⟩ : ∃ k, c.Rel k j) lemma next_eq_self' (c : ComplexShape ι) (j : ι) (hj : ∀ k, ¬ c.Rel j k) : c.next j = j := dif_neg (by simpa using hj) lemma prev_eq_self' (c : ComplexShape ι) (j : ι) (hj : ∀ i, ¬ c.Rel i j) : c.prev j = j := dif_neg (by simpa using hj) lemma next_eq_self (c : ComplexShape ι) (j : ι) (hj : ¬ c.Rel j (c.next j)) : c.next j = j := c.next_eq_self' j (fun k hk' => hj (by simpa only [c.next_eq' hk'] using hk')) lemma prev_eq_self (c : ComplexShape ι) (j : ι) (hj : ¬ c.Rel (c.prev j) j) : c.prev j = j := c.prev_eq_self' j (fun k hk' => hj (by simpa only [c.prev_eq' hk'] using hk')) /-- The `ComplexShape` allowing differentials from `X i` to `X (i+a)`. (For example when `a = 1`, a cohomology theory indexed by `ℕ` or `ℤ`) -/ @[simps] def up' {α : Type*} [AddRightCancelSemigroup α] (a : α) : ComplexShape α where Rel i j := i + a = j next_eq hi hj := hi.symm.trans hj prev_eq hi hj := add_right_cancel (hi.trans hj.symm) /-- The `ComplexShape` allowing differentials from `X (j+a)` to `X j`. (For example when `a = 1`, a homology theory indexed by `ℕ` or `ℤ`) -/ @[simps] def down' {α : Type*} [AddRightCancelSemigroup α] (a : α) : ComplexShape α where Rel i j := j + a = i next_eq hi hj := add_right_cancel (hi.trans hj.symm) prev_eq hi hj := hi.symm.trans hj theorem down'_mk {α : Type*} [AddRightCancelSemigroup α] (a : α) (i j : α) (h : j + a = i) : (down' a).Rel i j := h /-- The `ComplexShape` appropriate for cohomology, so `d : X i ⟶ X j` only when `j = i + 1`. -/ @[simps!] def up (α : Type*) [AddRightCancelSemigroup α] [One α] : ComplexShape α := up' 1 /-- The `ComplexShape` appropriate for homology, so `d : X i ⟶ X j` only when `i = j + 1`. -/ @[simps!] def down (α : Type*) [AddRightCancelSemigroup α] [One α] : ComplexShape α := down' 1 theorem down_mk {α : Type*} [AddRightCancelSemigroup α] [One α] (i j : α) (h : j + 1 = i) : (down α).Rel i j := down'_mk (1 : α) i j h end ComplexShape end namespace ComplexShape variable (α : Type*) [AddRightCancelSemigroup α] [DecidableEq α] instance (a : α) : DecidableRel (ComplexShape.up' a).Rel := fun _ _ => by dsimp; infer_instance instance (a : α) : DecidableRel (ComplexShape.down' a).Rel := fun _ _ => by dsimp; infer_instance variable [One α] instance : DecidableRel (ComplexShape.up α).Rel := by dsimp [ComplexShape.up]; infer_instance instance : DecidableRel (ComplexShape.down α).Rel := by dsimp [ComplexShape.down]; infer_instance end ComplexShape
Algebra\Homology\ComplexShapeSigns.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ComplexShape import Mathlib.Algebra.Ring.NegOnePow /-! Signs in constructions on homological complexes In this file, we shall introduce various typeclasses which will allow the construction of the total complex of a bicomplex and of the the monoidal category structure on categories of homological complexes (TODO). The most important definition is that of `TotalComplexShape c₁ c₂ c₁₂` given three complex shapes `c₁`, `c₂`, `c₁₂`: it allows the definition of a total complex functor `HomologicalComplex₂ C c₁ c₂ ⥤ HomologicalComplex C c₁₂` (at least when suitable coproducts exist). In particular, we construct an instance of `TotalComplexShape c c c` when `c : ComplexShape I` and `I` is an additive monoid equipped with a group homomorphism `ε' : Multiplicative I → ℤˣ` satisfying certain properties (see `ComplexShape.TensorSigns`). TODO @joelriou: add more classes for the associativity of the total complex, etc. -/ variable {I₁ I₂ I₁₂ : Type*} (c₁ : ComplexShape I₁) (c₂ : ComplexShape I₂) (c₁₂ : ComplexShape I₁₂) /-- A total complex shape for three complexes shapes `c₁`, `c₂`, `c₁₂` on three types `I₁`, `I₂` and `I₁₂` consists of the data and properties that will allow the construction of a total complex functor `HomologicalComplex₂ C c₁ c₂ ⥤ HomologicalComplex C c₁₂` which sends `K` to a complex which in degree `i₁₂ : I₁₂` consists of the coproduct of the `(K.X i₁).X i₂` such that `π ⟨i₁, i₂⟩ = i₁₂`. -/ class TotalComplexShape where /-- a map on indices -/ π : I₁ × I₂ → I₁₂ /-- the sign of the horizontal differential in the total complex -/ ε₁ : I₁ × I₂ → ℤˣ /-- the sign of the vertical differential in the total complex -/ ε₂ : I₁ × I₂ → ℤˣ rel₁ {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) : c₁₂.Rel (π ⟨i₁, i₂⟩) (π ⟨i₁', i₂⟩) rel₂ (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') : c₁₂.Rel (π ⟨i₁, i₂⟩) (π ⟨i₁, i₂'⟩) ε₂_ε₁ {i₁ i₁' : I₁} {i₂ i₂' : I₂} (h₁ : c₁.Rel i₁ i₁') (h₂ : c₂.Rel i₂ i₂') : ε₂ ⟨i₁, i₂⟩ * ε₁ ⟨i₁, i₂'⟩ = - ε₁ ⟨i₁, i₂⟩ * ε₂ ⟨i₁', i₂⟩ namespace ComplexShape variable [TotalComplexShape c₁ c₂ c₁₂] /-- The map `I₁ × I₂ → I₁₂` on indices given by `TotalComplexShape c₁ c₂ c₁₂`. -/ abbrev π (i : I₁ × I₂) : I₁₂ := TotalComplexShape.π c₁ c₂ c₁₂ i /-- The sign of the horizontal differential in the total complex. -/ abbrev ε₁ (i : I₁ × I₂) : ℤˣ := TotalComplexShape.ε₁ c₁ c₂ c₁₂ i /-- The sign of the vertical differential in the total complex. -/ abbrev ε₂ (i : I₁ × I₂) : ℤˣ := TotalComplexShape.ε₂ c₁ c₂ c₁₂ i variable {c₁} lemma rel_π₁ {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) : c₁₂.Rel (π c₁ c₂ c₁₂ ⟨i₁, i₂⟩) (π c₁ c₂ c₁₂ ⟨i₁', i₂⟩) := TotalComplexShape.rel₁ h i₂ lemma next_π₁ {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) : c₁₂.next (π c₁ c₂ c₁₂ ⟨i₁, i₂⟩) = π c₁ c₂ c₁₂ ⟨i₁', i₂⟩ := c₁₂.next_eq' (rel_π₁ c₂ c₁₂ h i₂) lemma prev_π₁ {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) : c₁₂.prev (π c₁ c₂ c₁₂ ⟨i₁', i₂⟩) = π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ := c₁₂.prev_eq' (rel_π₁ c₂ c₁₂ h i₂) variable (c₁) {c₂} lemma rel_π₂ (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') : c₁₂.Rel (π c₁ c₂ c₁₂ ⟨i₁, i₂⟩) (π c₁ c₂ c₁₂ ⟨i₁, i₂'⟩) := TotalComplexShape.rel₂ i₁ h lemma next_π₂ (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') : c₁₂.next (π c₁ c₂ c₁₂ ⟨i₁, i₂⟩) = π c₁ c₂ c₁₂ ⟨i₁, i₂'⟩ := c₁₂.next_eq' (rel_π₂ c₁ c₁₂ i₁ h) lemma prev_π₂ (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') : c₁₂.prev (π c₁ c₂ c₁₂ ⟨i₁, i₂'⟩) = π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ := c₁₂.prev_eq' (rel_π₂ c₁ c₁₂ i₁ h) variable {c₁} lemma ε₂_ε₁ {i₁ i₁' : I₁} {i₂ i₂' : I₂} (h₁ : c₁.Rel i₁ i₁') (h₂ : c₂.Rel i₂ i₂') : ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ * ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂'⟩ = - ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ * ε₂ c₁ c₂ c₁₂ ⟨i₁', i₂⟩ := TotalComplexShape.ε₂_ε₁ h₁ h₂ lemma ε₁_ε₂ {i₁ i₁' : I₁} {i₂ i₂' : I₂} (h₁ : c₁.Rel i₁ i₁') (h₂ : c₂.Rel i₂ i₂') : ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ * ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = - ε₂ c₁ c₂ c₁₂ ⟨i₁', i₂⟩ * ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂'⟩ := Eq.trans (mul_one _).symm (by rw [← Int.units_mul_self (ComplexShape.ε₁ c₁ c₂ c₁₂ (i₁, i₂')), mul_assoc] conv_lhs => arg 2 rw [← mul_assoc, ε₂_ε₁ c₁₂ h₁ h₂] rw [neg_mul, neg_mul, neg_mul, mul_neg, neg_inj, ← mul_assoc, ← mul_assoc, Int.units_mul_self, one_mul]) section variable {I : Type*} [AddMonoid I] (c : ComplexShape I) /-- If `I` is an additive monoid and `c : ComplexShape I`, `c.TensorSigns` contains the data of map `ε : I → ℤˣ` and properties which allows the construction of a `TotalComplexShape c c c`. -/ class TensorSigns where /-- the signs which appear in the vertical differential of the total complex -/ ε' : Multiplicative I →* ℤˣ rel_add (p q r : I) (hpq : c.Rel p q) : c.Rel (p + r) (q + r) add_rel (p q r : I) (hpq : c.Rel p q) : c.Rel (r + p) (r + q) ε'_succ (p q : I) (hpq : c.Rel p q) : ε' q = - ε' p variable [TensorSigns c] /-- The signs which appear in the vertical differential of the total complex. -/ abbrev ε (i : I) : ℤˣ := TensorSigns.ε' c i lemma rel_add {p q : I} (hpq : c.Rel p q) (r : I) : c.Rel (p + r) (q + r) := TensorSigns.rel_add _ _ _ hpq lemma add_rel (r : I) {p q : I} (hpq : c.Rel p q) : c.Rel (r + p) (r + q) := TensorSigns.add_rel _ _ _ hpq @[simp] lemma ε_zero : c.ε 0 = 1 := by apply MonoidHom.map_one lemma ε_succ {p q : I} (hpq : c.Rel p q) : c.ε q = - c.ε p := TensorSigns.ε'_succ p q hpq lemma ε_add (p q : I) : c.ε (p + q) = c.ε p * c.ε q := by apply MonoidHom.map_mul lemma next_add (p q : I) (hp : c.Rel p (c.next p)) : c.next (p + q) = c.next p + q := c.next_eq' (c.rel_add hp q) lemma next_add' (p q : I) (hq : c.Rel q (c.next q)) : c.next (p + q) = p + c.next q := c.next_eq' (c.add_rel p hq) @[simps] instance : TotalComplexShape c c c where π := fun ⟨p, q⟩ => p + q ε₁ := fun _ => 1 ε₂ := fun ⟨p, _⟩ => c.ε p rel₁ h q := c.rel_add h q rel₂ p _ _ h := c.add_rel p h ε₂_ε₁ h _ := by dsimp rw [neg_mul, one_mul, mul_one, c.ε_succ h, neg_neg] instance : TensorSigns (ComplexShape.down ℕ) where ε' := MonoidHom.mk' (fun (i : ℕ) => (-1 : ℤˣ) ^ i) (pow_add (-1 : ℤˣ)) rel_add p q r (hpq : q + 1 = p) := by dsimp; omega add_rel p q r (hpq : q + 1 = p) := by dsimp; omega ε'_succ := by rintro _ q rfl dsimp rw [pow_add, pow_one, mul_neg, mul_one, neg_neg] @[simp] lemma ε_down_ℕ (n : ℕ) : (ComplexShape.down ℕ).ε n = (-1 : ℤˣ) ^ n := rfl instance : TensorSigns (ComplexShape.up ℤ) where ε' := MonoidHom.mk' Int.negOnePow Int.negOnePow_add rel_add p q r (hpq : p + 1 = q) := by dsimp; omega add_rel p q r (hpq : p + 1 = q) := by dsimp; omega ε'_succ := by rintro p _ rfl dsimp rw [Int.negOnePow_succ] @[simp] lemma ε_up_ℤ (n : ℤ) : (ComplexShape.up ℤ).ε n = n.negOnePow := rfl end end ComplexShape /-- A total complex shape symmetry contains the data and properties which allow the identification of the two total complex functors `HomologicalComplex₂ C c₁ c₂ ⥤ HomologicalComplex C c₁₂` and `HomologicalComplex₂ C c₂ c₁ ⥤ HomologicalComplex C c₁₂` via the flip. -/ class TotalComplexShapeSymmetry [TotalComplexShape c₁ c₂ c₁₂] [TotalComplexShape c₂ c₁ c₁₂] where symm (i₁ : I₁) (i₂ : I₂) : ComplexShape.π c₂ c₁ c₁₂ ⟨i₂, i₁⟩ = ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ /-- the signs involved in the symmetry isomorphism of the total complex -/ σ (i₁ : I₁) (i₂ : I₂) : ℤˣ σ_ε₁ {i₁ i₁' : I₁} (h₁ : c₁.Rel i₁ i₁') (i₂ : I₂) : σ i₁ i₂ * ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = ComplexShape.ε₂ c₂ c₁ c₁₂ ⟨i₂, i₁⟩ * σ i₁' i₂ σ_ε₂ (i₁ : I₁) {i₂ i₂' : I₂} (h₂ : c₂.Rel i₂ i₂') : σ i₁ i₂ * ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = ComplexShape.ε₁ c₂ c₁ c₁₂ ⟨i₂, i₁⟩ * σ i₁ i₂' namespace ComplexShape variable [TotalComplexShape c₁ c₂ c₁₂] [TotalComplexShape c₂ c₁ c₁₂] [TotalComplexShapeSymmetry c₁ c₂ c₁₂] /-- The signs involved in the symmetry isomorphism of the total complex. -/ abbrev σ (i₁ : I₁) (i₂ : I₂) : ℤˣ := TotalComplexShapeSymmetry.σ c₁ c₂ c₁₂ i₁ i₂ lemma π_symm (i₁ : I₁) (i₂ : I₂) : π c₂ c₁ c₁₂ ⟨i₂, i₁⟩ = π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ := by apply TotalComplexShapeSymmetry.symm variable {c₁} lemma σ_ε₁ {i₁ i₁' : I₁} (h₁ : c₁.Rel i₁ i₁') (i₂ : I₂) : σ c₁ c₂ c₁₂ i₁ i₂ * ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = ε₂ c₂ c₁ c₁₂ ⟨i₂, i₁⟩ * σ c₁ c₂ c₁₂ i₁' i₂ := TotalComplexShapeSymmetry.σ_ε₁ h₁ i₂ variable (c₁) {c₂} lemma σ_ε₂ (i₁ : I₁) {i₂ i₂' : I₂} (h₂ : c₂.Rel i₂ i₂') : σ c₁ c₂ c₁₂ i₁ i₂ * ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = ε₁ c₂ c₁ c₁₂ ⟨i₂, i₁⟩ * σ c₁ c₂ c₁₂ i₁ i₂' := TotalComplexShapeSymmetry.σ_ε₂ i₁ h₂ @[simps] instance : TotalComplexShapeSymmetry (up ℤ) (up ℤ) (up ℤ) where symm p q := add_comm q p σ p q := (p * q).negOnePow σ_ε₁ := by rintro p _ rfl q dsimp rw [mul_one, ← Int.negOnePow_add, add_comm q, add_mul, one_mul, Int.negOnePow_add, Int.negOnePow_add, mul_assoc, Int.units_mul_self, mul_one] σ_ε₂ := by rintro p q _ rfl dsimp rw [one_mul, ← Int.negOnePow_add, mul_add, mul_one] end ComplexShape /-- This typeclass expresses that the signs given by `[TotalComplexShapeSymmetry c₁ c₂ c₁₂]` and by `[TotalComplexShapeSymmetry c₂ c₁ c₁₂]` are compatible. -/ class TotalComplexShapeSymmetrySymmetry [TotalComplexShape c₁ c₂ c₁₂] [TotalComplexShape c₂ c₁ c₁₂] [TotalComplexShapeSymmetry c₁ c₂ c₁₂] [TotalComplexShapeSymmetry c₂ c₁ c₁₂] : Prop where σ_symm i₁ i₂ : ComplexShape.σ c₂ c₁ c₁₂ i₂ i₁ = ComplexShape.σ c₁ c₂ c₁₂ i₁ i₂ namespace ComplexShape variable [TotalComplexShape c₁ c₂ c₁₂] [TotalComplexShape c₂ c₁ c₁₂] [TotalComplexShapeSymmetry c₁ c₂ c₁₂] [TotalComplexShapeSymmetry c₂ c₁ c₁₂] [TotalComplexShapeSymmetrySymmetry c₁ c₂ c₁₂] lemma σ_symm (i₁ : I₁) (i₂ : I₂) : σ c₂ c₁ c₁₂ i₂ i₁ = σ c₁ c₂ c₁₂ i₁ i₂ := by apply TotalComplexShapeSymmetrySymmetry.σ_symm end ComplexShape
Algebra\Homology\ConcreteCategory.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomologySequence import Mathlib.Algebra.Homology.ShortComplex.ConcreteCategory /-! # Homology of complexes in concrete categories The homology of short complexes in concrete categories was studied in `Mathlib.Algebra.Homology.ShortComplex.ConcreteCategory`. In this file, we introduce specific definitions and lemmas for the homology of homological complexes in concrete categories. In particular, we give a computation of the connecting homomorphism of the homology sequence in terms of (co)cycles. -/ open CategoryTheory universe v u variable {C : Type u} [Category.{v} C] [ConcreteCategory.{v} C] [HasForget₂ C Ab.{v}] [Abelian C] [(forget₂ C Ab).Additive] [(forget₂ C Ab).PreservesHomology] {ι : Type*} {c : ComplexShape ι} namespace HomologicalComplex variable (K : HomologicalComplex C c) /-- Constructor for cycles of a homological complex in a concrete category. -/ noncomputable def cyclesMk {i : ι} (x : (forget₂ C Ab).obj (K.X i)) (j : ι) (hj : c.next i = j) (hx : ((forget₂ C Ab).map (K.d i j)) x = 0) : (forget₂ C Ab).obj (K.cycles i) := (K.sc i).cyclesMk x (by subst hj; exact hx) @[simp] lemma i_cyclesMk {i : ι} (x : (forget₂ C Ab).obj (K.X i)) (j : ι) (hj : c.next i = j) (hx : ((forget₂ C Ab).map (K.d i j)) x = 0) : ((forget₂ C Ab).map (K.iCycles i)) (K.cyclesMk x j hj hx) = x := by subst hj apply (K.sc i).i_cyclesMk end HomologicalComplex namespace CategoryTheory namespace ShortComplex namespace ShortExact variable {S : ShortComplex (HomologicalComplex C c)} (hS : S.ShortExact) (i j : ι) (hij : c.Rel i j) lemma δ_apply' (x₃ : (forget₂ C Ab).obj (S.X₃.homology i)) (x₂ : (forget₂ C Ab).obj (S.X₂.opcycles i)) (x₁ : (forget₂ C Ab).obj (S.X₁.cycles j)) (h₂ : (forget₂ C Ab).map (HomologicalComplex.opcyclesMap S.g i) x₂ = (forget₂ C Ab).map (S.X₃.homologyι i) x₃) (h₁ : (forget₂ C Ab).map (HomologicalComplex.cyclesMap S.f j) x₁ = (forget₂ C Ab).map (S.X₂.opcyclesToCycles i j) x₂) : (forget₂ C Ab).map (hS.δ i j hij) x₃ = (forget₂ C Ab).map (S.X₁.homologyπ j) x₁ := (HomologicalComplex.HomologySequence.snakeInput hS i j hij).δ_apply' x₃ x₂ x₁ h₂ h₁ lemma δ_apply (x₃ : (forget₂ C Ab).obj (S.X₃.X i)) (hx₃ : (forget₂ C Ab).map (S.X₃.d i j) x₃ = 0) (x₂ : (forget₂ C Ab).obj (S.X₂.X i)) (hx₂ : (forget₂ C Ab).map (S.g.f i) x₂ = x₃) (x₁ : (forget₂ C Ab).obj (S.X₁.X j)) (hx₁ : (forget₂ C Ab).map (S.f.f j) x₁ = (forget₂ C Ab).map (S.X₂.d i j) x₂) (k : ι) (hk : c.next j = k) : (forget₂ C Ab).map (hS.δ i j hij) ((forget₂ C Ab).map (S.X₃.homologyπ i) (S.X₃.cyclesMk x₃ j (c.next_eq' hij) hx₃)) = (forget₂ C Ab).map (S.X₁.homologyπ j) (S.X₁.cyclesMk x₁ k hk (by have := hS.mono_f apply (Preadditive.mono_iff_injective (S.f.f k)).1 inferInstance erw [← forget₂_comp_apply, ← HomologicalComplex.Hom.comm, forget₂_comp_apply, hx₁, ← forget₂_comp_apply, HomologicalComplex.d_comp_d, Functor.map_zero, map_zero, AddMonoidHom.zero_apply])) := by refine hS.δ_apply' i j hij _ ((forget₂ C Ab).map (S.X₂.pOpcycles i) x₂) _ ?_ ?_ · erw [← forget₂_comp_apply, ← forget₂_comp_apply, HomologicalComplex.p_opcyclesMap, Functor.map_comp, comp_apply, HomologicalComplex.homology_π_ι, forget₂_comp_apply, hx₂, HomologicalComplex.i_cyclesMk] · apply (Preadditive.mono_iff_injective (S.X₂.iCycles j)).1 inferInstance conv_lhs => erw [← forget₂_comp_apply, HomologicalComplex.cyclesMap_i, forget₂_comp_apply, HomologicalComplex.i_cyclesMk, hx₁] conv_rhs => erw [← forget₂_comp_apply, ← forget₂_comp_apply, HomologicalComplex.pOpcycles_opcyclesToCycles_assoc, HomologicalComplex.toCycles_i] rfl end ShortExact end ShortComplex end CategoryTheory
Algebra\Homology\DifferentialObject.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Homology.HomologicalComplex import Mathlib.CategoryTheory.DifferentialObject /-! # Homological complexes are differential graded objects. We verify that a `HomologicalComplex` indexed by an `AddCommGroup` is essentially the same thing as a differential graded object. This equivalence is probably not particularly useful in practice; it's here to check that definitions match up as expected. -/ open CategoryTheory CategoryTheory.Limits noncomputable section /-! We first prove some results about differential graded objects. Porting note: after the port, move these to their own file. -/ namespace CategoryTheory.DifferentialObject variable {β : Type*} [AddCommGroup β] {b : β} variable {V : Type*} [Category V] [HasZeroMorphisms V] variable (X : DifferentialObject ℤ (GradedObjectWithShift b V)) /-- Since `eqToHom` only preserves the fact that `X.X i = X.X j` but not `i = j`, this definition is used to aid the simplifier. -/ abbrev objEqToHom {i j : β} (h : i = j) : X.obj i ⟶ X.obj j := eqToHom (congr_arg X.obj h) @[simp] theorem objEqToHom_refl (i : β) : X.objEqToHom (refl i) = 𝟙 _ := rfl @[reassoc (attr := simp)] theorem objEqToHom_d {x y : β} (h : x = y) : X.objEqToHom h ≫ X.d y = X.d x ≫ X.objEqToHom (by cases h; rfl) := by cases h; dsimp; simp @[reassoc (attr := simp)] theorem d_squared_apply {x : β} : X.d x ≫ X.d _ = 0 := congr_fun X.d_squared _ @[reassoc (attr := simp)] theorem eqToHom_f' {X Y : DifferentialObject ℤ (GradedObjectWithShift b V)} (f : X ⟶ Y) {x y : β} (h : x = y) : X.objEqToHom h ≫ f.f y = f.f x ≫ Y.objEqToHom h := by cases h; simp end CategoryTheory.DifferentialObject open CategoryTheory.DifferentialObject namespace HomologicalComplex variable {β : Type*} [AddCommGroup β] (b : β) variable (V : Type*) [Category V] [HasZeroMorphisms V] -- Porting note: this should be moved to an earlier file. -- Porting note: simpNF linter silenced, both `d_eqToHom` and its `_assoc` version -- do not simplify under themselves @[reassoc (attr := simp, nolint simpNF)] theorem d_eqToHom (X : HomologicalComplex V (ComplexShape.up' b)) {x y z : β} (h : y = z) : X.d x y ≫ eqToHom (congr_arg X.X h) = X.d x z := by cases h; simp open Classical in set_option maxHeartbeats 400000 in /-- The functor from differential graded objects to homological complexes. -/ @[simps] def dgoToHomologicalComplex : DifferentialObject ℤ (GradedObjectWithShift b V) ⥤ HomologicalComplex V (ComplexShape.up' b) where obj X := { X := fun i => X.obj i d := fun i j => if h : i + b = j then X.d i ≫ X.objEqToHom (show i + (1 : ℤ) • b = j by simp [h]) else 0 shape := fun i j w => by dsimp at w; convert dif_neg w d_comp_d' := fun i j k hij hjk => by dsimp at hij hjk; substs hij hjk simp } map {X Y} f := { f := f.f comm' := fun i j h => by dsimp at h ⊢ subst h simp only [dite_true, Category.assoc, eqToHom_f'] -- Porting note: this `rw` used to be part of the `simp`. have : f.f i ≫ Y.d i = X.d i ≫ f.f _ := (congr_fun f.comm i).symm rw [reassoc_of% this] } /-- The functor from homological complexes to differential graded objects. -/ @[simps] def homologicalComplexToDGO : HomologicalComplex V (ComplexShape.up' b) ⥤ DifferentialObject ℤ (GradedObjectWithShift b V) where obj X := { obj := fun i => X.X i d := fun i => X.d i _ } map {X Y} f := { f := f.f } /-- The unit isomorphism for `dgoEquivHomologicalComplex`. -/ @[simps!] def dgoEquivHomologicalComplexUnitIso : 𝟭 (DifferentialObject ℤ (GradedObjectWithShift b V)) ≅ dgoToHomologicalComplex b V ⋙ homologicalComplexToDGO b V := NatIso.ofComponents (fun X => { hom := { f := fun i => 𝟙 (X.obj i) } inv := { f := fun i => 𝟙 (X.obj i) } }) /-- The counit isomorphism for `dgoEquivHomologicalComplex`. -/ @[simps!] def dgoEquivHomologicalComplexCounitIso : homologicalComplexToDGO b V ⋙ dgoToHomologicalComplex b V ≅ 𝟭 (HomologicalComplex V (ComplexShape.up' b)) := NatIso.ofComponents (fun X => { hom := { f := fun i => 𝟙 (X.X i) } inv := { f := fun i => 𝟙 (X.X i) } }) /-- The category of differential graded objects in `V` is equivalent to the category of homological complexes in `V`. -/ @[simps] def dgoEquivHomologicalComplex : DifferentialObject ℤ (GradedObjectWithShift b V) ≌ HomologicalComplex V (ComplexShape.up' b) where functor := dgoToHomologicalComplex b V inverse := homologicalComplexToDGO b V unitIso := dgoEquivHomologicalComplexUnitIso b V counitIso := dgoEquivHomologicalComplexCounitIso b V end HomologicalComplex
Algebra\Homology\ExactSequence.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.Exact import Mathlib.CategoryTheory.ComposableArrows /-! # Exact sequences A sequence of `n` composable arrows `S : ComposableArrows C` (i.e. a functor `S : Fin (n + 1) ⥤ C`) is said to be exact (`S.Exact`) if the composition of two consecutive arrows are zero (`S.IsComplex`) and the diagram is exact at each `i` for `1 ≤ i < n`. Together with the inductive construction of composable arrows `ComposableArrows.precomp`, this is useful in order to state that certain finite sequences of morphisms are exact (e.g the snake lemma), even though in the applications it would usually be more convenient to use individual lemmas expressing the exactness at a particular object. This implementation is a refactor of `exact_seq` with appeared in the Liquid Tensor Experiment as a property of lists in `Arrow C`. -/ namespace CategoryTheory open Limits variable {C : Type*} [Category C] [HasZeroMorphisms C] /-- The composable arrows associated to a short complex. -/ @[simps!] def ShortComplex.toComposableArrows (S : ShortComplex C) : ComposableArrows C 2 := ComposableArrows.mk₂ S.f S.g namespace ComposableArrows variable {n : ℕ} (S : ComposableArrows C n) /-- `F : ComposableArrows C n` is a complex if all compositions of two consecutive arrows are zero. -/ structure IsComplex : Prop where /-- the composition of two consecutive arrows is zero -/ zero (i : ℕ) (hi : i + 2 ≤ n := by omega) : S.map' i (i + 1) ≫ S.map' (i + 1) (i + 2) = 0 attribute [reassoc] IsComplex.zero variable {S} @[reassoc] lemma IsComplex.zero' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S.map' i j ≫ S.map' j k = 0 := by subst hij hjk exact hS.zero i hk lemma isComplex_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) : S₂.IsComplex where zero i hi := by rw [← cancel_epi (ComposableArrows.app' e.hom i), comp_zero, ← NatTrans.naturality_assoc, ← NatTrans.naturality, reassoc_of% (h₁.zero i hi), zero_comp] lemma isComplex_iff_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) : S₁.IsComplex ↔ S₂.IsComplex := ⟨isComplex_of_iso e, isComplex_of_iso e.symm⟩ lemma isComplex₀ (S : ComposableArrows C 0) : S.IsComplex where -- See https://github.com/leanprover/lean4/issues/2862 -- Without `decide := true`, simp gets stuck at `hi : autoParam False _auto✝` zero i hi := by simp (config := {decide := true}) at hi lemma isComplex₁ (S : ComposableArrows C 1) : S.IsComplex where zero i hi := by exfalso; omega variable (S) /-- The short complex consisting of maps `S.map' i j` and `S.map' j k` when we know that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/ abbrev sc' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : ShortComplex C := ShortComplex.mk (S.map' i j) (S.map' j k) (hS.zero' i j k) /-- The short complex consisting of maps `S.map' i (i + 1)` and `S.map' (i + 1) (i + 2)` when we know that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/ abbrev sc (hS : S.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : ShortComplex C := S.sc' hS i (i + 1) (i + 2) /-- `F : ComposableArrows C n` is exact if it is a complex and that all short complexes consisting of two consecutive arrows are exact. -/ structure Exact extends S.IsComplex : Prop where exact (i : ℕ) (hi : i + 2 ≤ n := by omega) : (S.sc toIsComplex i).Exact variable {S} lemma Exact.exact' (hS : S.Exact) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : (S.sc' hS.toIsComplex i j k).Exact := by subst hij hjk exact hS.exact i hk /-- Functoriality maps for `ComposableArrows.sc'`. -/ @[simps] def sc'Map {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S₁.sc' h₁ i j k ⟶ S₂.sc' h₂ i j k where τ₁ := φ.app _ τ₂ := φ.app _ τ₃ := φ.app _ /-- Functoriality maps for `ComposableArrows.sc`. -/ @[simps!] def scMap {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : S₁.sc h₁ i ⟶ S₂.sc h₂ i := sc'Map φ h₁ h₂ i (i + 1) (i + 2) /-- The isomorphism `S₁.sc' _ i j k ≅ S₂.sc' _ i j k` induced by an isomorphism `S₁ ≅ S₂` in `ComposableArrows C n`. -/ @[simps] def sc'MapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega) (hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) : S₁.sc' h₁ i j k ≅ S₂.sc' h₂ i j k where hom := sc'Map e.hom h₁ h₂ i j k inv := sc'Map e.inv h₂ h₁ i j k hom_inv_id := by ext <;> dsimp <;> simp inv_hom_id := by ext <;> dsimp <;> simp /-- The isomorphism `S₁.sc _ i ≅ S₂.sc _ i` induced by an isomorphism `S₁ ≅ S₂` in `ComposableArrows C n`. -/ @[simps] def scMapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) : S₁.sc h₁ i ≅ S₂.sc h₂ i where hom := scMap e.hom h₁ h₂ i inv := scMap e.inv h₂ h₁ i hom_inv_id := by ext <;> dsimp <;> simp inv_hom_id := by ext <;> dsimp <;> simp lemma exact_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.Exact) : S₂.Exact where toIsComplex := isComplex_of_iso e h₁.toIsComplex exact i hi := ShortComplex.exact_of_iso (scMapIso e h₁.toIsComplex (isComplex_of_iso e h₁.toIsComplex) i) (h₁.exact i hi) lemma exact_iff_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) : S₁.Exact ↔ S₂.Exact := ⟨exact_of_iso e, exact_of_iso e.symm⟩ lemma exact₀ (S : ComposableArrows C 0) : S.Exact where toIsComplex := S.isComplex₀ -- See https://github.com/leanprover/lean4/issues/2862 exact i hi := by simp [autoParam] at hi lemma exact₁ (S : ComposableArrows C 1) : S.Exact where toIsComplex := S.isComplex₁ exact i hi := by exfalso; omega lemma isComplex₂_iff (S : ComposableArrows C 2) : S.IsComplex ↔ S.map' 0 1 ≫ S.map' 1 2 = 0 := by constructor · intro h exact h.zero 0 (by omega) · intro h refine IsComplex.mk (fun i hi => ?_) obtain rfl : i = 0 := by omega exact h lemma isComplex₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0) : S.IsComplex := S.isComplex₂_iff.2 w #adaptation_note /-- nightly-2024-03-11 We turn off simprocs here. Ideally someone will investigate whether `simp` lemmas can be rearranged so that this works without the `set_option`, *or* come up with a proposal regarding finer control of disabling simprocs. -/ set_option simprocs false in lemma _root_.CategoryTheory.ShortComplex.isComplex_toComposableArrows (S : ShortComplex C) : S.toComposableArrows.IsComplex := isComplex₂_mk _ (by simp) lemma exact₂_iff (S : ComposableArrows C 2) (hS : S.IsComplex) : S.Exact ↔ (S.sc' hS 0 1 2).Exact := by constructor · intro h exact h.exact 0 (by omega) · intro h refine Exact.mk hS (fun i hi => ?_) obtain rfl : i = 0 := by omega exact h lemma exact₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0) (h : (ShortComplex.mk _ _ w).Exact) : S.Exact := (S.exact₂_iff (S.isComplex₂_mk w)).2 h lemma _root_.CategoryTheory.ShortComplex.Exact.exact_toComposableArrows {S : ShortComplex C} (hS : S.Exact) : S.toComposableArrows.Exact := exact₂_mk _ _ hS lemma _root_.CategoryTheory.ShortComplex.exact_iff_exact_toComposableArrows (S : ShortComplex C) : S.Exact ↔ S.toComposableArrows.Exact := (S.toComposableArrows.exact₂_iff S.isComplex_toComposableArrows).symm lemma exact_iff_δ₀ (S : ComposableArrows C (n + 2)) : S.Exact ↔ (mk₂ (S.map' 0 1) (S.map' 1 2)).Exact ∧ S.δ₀.Exact := by constructor · intro h constructor · rw [exact₂_iff]; swap · rw [isComplex₂_iff] exact h.toIsComplex.zero 0 exact h.exact 0 (by omega) · exact Exact.mk (IsComplex.mk (fun i hi => h.toIsComplex.zero (i + 1))) (fun i hi => h.exact (i + 1)) · rintro ⟨h, h₀⟩ refine Exact.mk (IsComplex.mk (fun i hi => ?_)) (fun i hi => ?_) · obtain _ | i := i · exact h.toIsComplex.zero 0 · exact h₀.toIsComplex.zero i · obtain _ | i := i · exact h.exact 0 · exact h₀.exact i lemma Exact.δ₀ {S : ComposableArrows C (n + 2)} (hS : S.Exact) : S.δ₀.Exact := by rw [exact_iff_δ₀] at hS exact hS.2 /-- If `S : ComposableArrows C (n + 2)` is such that the first two arrows form an exact sequence and that the tail `S.δ₀` is exact, then `S` is also exact. See `ShortComplex.SnakeInput.snake_lemma` in `Algebra.Homology.ShortComplex.SnakeLemma` for a use of this lemma. -/ lemma exact_of_δ₀ {S : ComposableArrows C (n + 2)} (h : (mk₂ (S.map' 0 1) (S.map' 1 2)).Exact) (h₀ : S.δ₀.Exact) : S.Exact := by rw [exact_iff_δ₀] constructor <;> assumption lemma exact_iff_δlast {n : ℕ} (S : ComposableArrows C (n + 2)) : S.Exact ↔ S.δlast.Exact ∧ (mk₂ (S.map' n (n + 1)) (S.map' (n + 1) (n + 2))).Exact := by constructor · intro h constructor · exact Exact.mk (IsComplex.mk (fun i hi => h.toIsComplex.zero i)) (fun i hi => h.exact i) · rw [exact₂_iff]; swap · rw [isComplex₂_iff] exact h.toIsComplex.zero n exact h.exact n (by omega) · rintro ⟨h, h'⟩ refine Exact.mk (IsComplex.mk (fun i hi => ?_)) (fun i hi => ?_) · simp only [Nat.add_le_add_iff_right] at hi obtain hi | rfl := hi.lt_or_eq · exact h.toIsComplex.zero i · exact h'.toIsComplex.zero 0 · simp only [Nat.add_le_add_iff_right] at hi obtain hi | rfl := hi.lt_or_eq · exact h.exact i · exact h'.exact 0 lemma Exact.δlast {S : ComposableArrows C (n + 2)} (hS : S.Exact) : S.δlast.Exact := by rw [exact_iff_δlast] at hS exact hS.1 lemma exact_of_δlast {n : ℕ} (S : ComposableArrows C (n + 2)) (h₁ : S.δlast.Exact) (h₂ : (mk₂ (S.map' n (n + 1)) (S.map' (n + 1) (n + 2))).Exact) : S.Exact := by rw [exact_iff_δlast] constructor <;> assumption end ComposableArrows end CategoryTheory
Algebra\Homology\Functor.lean
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Homology.HomologicalComplex /-! # Complexes in functor categories We can view a complex valued in a functor category `T ⥤ V` as a functor from `T` to complexes valued in `V`. ## Future work In fact this is an equivalence of categories. -/ universe v u open CategoryTheory open CategoryTheory.Limits namespace HomologicalComplex variable {V : Type u} [Category.{v} V] [HasZeroMorphisms V] variable {ι : Type*} {c : ComplexShape ι} /-- A complex of functors gives a functor to complexes. -/ @[simps obj map] def asFunctor {T : Type*} [Category T] (C : HomologicalComplex (T ⥤ V) c) : T ⥤ HomologicalComplex V c where obj t := { X := fun i => (C.X i).obj t d := fun i j => (C.d i j).app t d_comp_d' := fun i j k _ _ => by have := C.d_comp_d i j k rw [NatTrans.ext_iff, Function.funext_iff] at this exact this t shape := fun i j h => by have := C.shape _ _ h rw [NatTrans.ext_iff, Function.funext_iff] at this exact this t } map h := { f := fun i => (C.X i).map h comm' := fun i j _ => NatTrans.naturality _ _ } map_id t := by ext i dsimp rw [(C.X i).map_id] map_comp h₁ h₂ := by ext i dsimp rw [Functor.map_comp] -- TODO in fact, this is an equivalence of categories. /-- The functorial version of `HomologicalComplex.asFunctor`. -/ @[simps] def complexOfFunctorsToFunctorToComplex {T : Type*} [Category T] : HomologicalComplex (T ⥤ V) c ⥤ T ⥤ HomologicalComplex V c where obj C := C.asFunctor map f := { app := fun t => { f := fun i => (f.f i).app t comm' := fun i j _ => NatTrans.congr_app (f.comm i j) t } naturality := fun t t' g => by ext i exact (f.f i).naturality g } end HomologicalComplex
Algebra\Homology\HomologicalBicomplex.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Joël Riou -/ import Mathlib.Algebra.Homology.HomologicalComplex /-! # Bicomplexes Given a category `C` with zero morphisms and two complex shapes `c₁ : ComplexShape I₁` and `c₂ : ComplexShape I₂`, we define the type of bicomplexes `HomologicalComplex₂ C c₁ c₂` as an abbreviation for `HomologicalComplex (HomologicalComplex C c₂) c₁`. In particular, if `K : HomologicalComplex₂ C c₁ c₂`, then for each `i₁ : I₁`, `K.X i₁` is a column of `K`. In this file, we obtain the equivalence of categories `HomologicalComplex₂.flipEquivalence : HomologicalComplex₂ C c₁ c₂ ≌ HomologicalComplex₂ C c₂ c₁` which is obtained by exchanging the horizontal and vertical directions. -/ open CategoryTheory Limits variable (C : Type*) [Category C] [HasZeroMorphisms C] {I₁ I₂ : Type*} (c₁ : ComplexShape I₁) (c₂ : ComplexShape I₂) /-- Given a category `C` and two complex shapes `c₁` and `c₂` on types `I₁` and `I₂`, the associated type of bicomplexes `HomologicalComplex₂ C c₁ c₂` is `K : HomologicalComplex (HomologicalComplex C c₂) c₁`. Then, the object in position `⟨i₁, i₂⟩` can be obtained as `(K.X i₁).X i₂`. -/ abbrev HomologicalComplex₂ := HomologicalComplex (HomologicalComplex C c₂) c₁ namespace HomologicalComplex₂ open HomologicalComplex variable {C c₁ c₂} /-- The graded object indexed by `I₁ × I₂` induced by a bicomplex. -/ def toGradedObject (K : HomologicalComplex₂ C c₁ c₂) : GradedObject (I₁ × I₂) C := fun ⟨i₁, i₂⟩ => (K.X i₁).X i₂ /-- The morphism of graded objects induced by a morphism of bicomplexes. -/ def toGradedObjectMap {K L : HomologicalComplex₂ C c₁ c₂} (φ : K ⟶ L) : K.toGradedObject ⟶ L.toGradedObject := fun ⟨i₁, i₂⟩ => (φ.f i₁).f i₂ @[simp] lemma toGradedObjectMap_apply {K L : HomologicalComplex₂ C c₁ c₂} (φ : K ⟶ L) (i₁ : I₁) (i₂ : I₂) : toGradedObjectMap φ ⟨i₁, i₂⟩ = (φ.f i₁).f i₂ := rfl variable (C c₁ c₂) in /-- The functor which sends a bicomplex to its associated graded object. -/ @[simps] def toGradedObjectFunctor : HomologicalComplex₂ C c₁ c₂ ⥤ GradedObject (I₁ × I₂) C where obj K := K.toGradedObject map φ := toGradedObjectMap φ instance : (toGradedObjectFunctor C c₁ c₂).Faithful where map_injective {_ _ φ₁ φ₂} h := by ext i₁ i₂ exact congr_fun h ⟨i₁, i₂⟩ section OfGradedObject variable (c₁ c₂) variable (X : GradedObject (I₁ × I₂) C) (d₁ : ∀ (i₁ i₁' : I₁) (i₂ : I₂), X ⟨i₁, i₂⟩ ⟶ X ⟨i₁', i₂⟩) (d₂ : ∀ (i₁ : I₁) (i₂ i₂' : I₂), X ⟨i₁, i₂⟩ ⟶ X ⟨i₁, i₂'⟩) (shape₁ : ∀ (i₁ i₁' : I₁) (_ : ¬c₁.Rel i₁ i₁') (i₂ : I₂), d₁ i₁ i₁' i₂ = 0) (shape₂ : ∀ (i₁ : I₁) (i₂ i₂' : I₂) (_ : ¬c₂.Rel i₂ i₂'), d₂ i₁ i₂ i₂' = 0) (d₁_comp_d₁ : ∀ (i₁ i₁' i₁'' : I₁) (i₂ : I₂), d₁ i₁ i₁' i₂ ≫ d₁ i₁' i₁'' i₂ = 0) (d₂_comp_d₂ : ∀ (i₁ : I₁) (i₂ i₂' i₂'' : I₂), d₂ i₁ i₂ i₂' ≫ d₂ i₁ i₂' i₂'' = 0) (comm : ∀ (i₁ i₁' : I₁) (i₂ i₂' : I₂), d₁ i₁ i₁' i₂ ≫ d₂ i₁' i₂ i₂' = d₂ i₁ i₂ i₂' ≫ d₁ i₁ i₁' i₂') /-- Constructor for bicomplexes taking as inputs a graded object, horizontal differentials and vertical differentials satisfying suitable relations. -/ @[simps] def ofGradedObject : HomologicalComplex₂ C c₁ c₂ where X i₁ := { X := fun i₂ => X ⟨i₁, i₂⟩ d := fun i₂ i₂' => d₂ i₁ i₂ i₂' shape := shape₂ i₁ d_comp_d' := by intros; apply d₂_comp_d₂ } d i₁ i₁' := { f := fun i₂ => d₁ i₁ i₁' i₂ comm' := by intros; apply comm } shape i₁ i₁' h := by ext i₂ exact shape₁ i₁ i₁' h i₂ d_comp_d' i₁ i₁' i₁'' _ _ := by ext i₂; apply d₁_comp_d₁ @[simp] lemma ofGradedObject_toGradedObject : (ofGradedObject c₁ c₂ X d₁ d₂ shape₁ shape₂ d₁_comp_d₁ d₂_comp_d₂ comm).toGradedObject = X := rfl end OfGradedObject /-- Constructor for a morphism `K ⟶ L` in the category `HomologicalComplex₂ C c₁ c₂` which takes as inputs a morphism `f : K.toGradedObject ⟶ L.toGradedObject` and the compatibilites with both horizontal and vertical differentials. -/ @[simps!] def homMk {K L : HomologicalComplex₂ C c₁ c₂} (f : K.toGradedObject ⟶ L.toGradedObject) (comm₁ : ∀ i₁ i₁' i₂, c₁.Rel i₁ i₁' → f ⟨i₁, i₂⟩ ≫ (L.d i₁ i₁').f i₂ = (K.d i₁ i₁').f i₂ ≫ f ⟨i₁', i₂⟩) (comm₂ : ∀ i₁ i₂ i₂', c₂.Rel i₂ i₂' → f ⟨i₁, i₂⟩ ≫ (L.X i₁).d i₂ i₂' = (K.X i₁).d i₂ i₂' ≫ f ⟨i₁, i₂'⟩) : K ⟶ L where f i₁ := { f := fun i₂ => f ⟨i₁, i₂⟩ comm' := comm₂ i₁ } comm' i₁ i₁' h₁ := by ext i₂ exact comm₁ i₁ i₁' i₂ h₁ lemma shape_f (K : HomologicalComplex₂ C c₁ c₂) (i₁ i₁' : I₁) (h : ¬ c₁.Rel i₁ i₁') (i₂ : I₂) : (K.d i₁ i₁').f i₂ = 0 := by rw [K.shape _ _ h, zero_f] @[reassoc (attr := simp)] lemma d_f_comp_d_f (K : HomologicalComplex₂ C c₁ c₂) (i₁ i₁' i₁'' : I₁) (i₂ : I₂) : (K.d i₁ i₁').f i₂ ≫ (K.d i₁' i₁'').f i₂ = 0 := by rw [← comp_f, d_comp_d, zero_f] @[reassoc] lemma d_comm (K : HomologicalComplex₂ C c₁ c₂) (i₁ i₁' : I₁) (i₂ i₂' : I₂) : (K.d i₁ i₁').f i₂ ≫ (K.X i₁').d i₂ i₂' = (K.X i₁).d i₂ i₂' ≫ (K.d i₁ i₁').f i₂' := by simp @[reassoc (attr := simp)] lemma comm_f {K L : HomologicalComplex₂ C c₁ c₂} (f : K ⟶ L) (i₁ i₁' : I₁) (i₂ : I₂) : (f.f i₁).f i₂ ≫ (L.d i₁ i₁').f i₂ = (K.d i₁ i₁').f i₂ ≫ (f.f i₁').f i₂ := congr_hom (f.comm i₁ i₁') i₂ /-- Flip a complex of complexes over the diagonal, exchanging the horizontal and vertical directions. -/ @[simps] def flip (K : HomologicalComplex₂ C c₁ c₂) : HomologicalComplex₂ C c₂ c₁ where X i := { X := fun j => (K.X j).X i d := fun j j' => (K.d j j').f i shape := fun j j' w => K.shape_f _ _ w i } d i i' := { f := fun j => (K.X j).d i i' } shape i i' w := by ext j exact (K.X j).shape i i' w @[simp] lemma flip_flip (K : HomologicalComplex₂ C c₁ c₂) : K.flip.flip = K := rfl variable (C c₁ c₂) /-- Flipping a complex of complexes over the diagonal, as a functor. -/ @[simps] def flipFunctor : HomologicalComplex₂ C c₁ c₂ ⥤ HomologicalComplex₂ C c₂ c₁ where obj K := K.flip map {K L} f := { f := fun i => { f := fun j => (f.f j).f i comm' := by intros; simp } comm' := by intros; ext; simp } /-- Auxiliary definition for `HomologicalComplex₂.flipEquivalence`. -/ @[simps!] def flipEquivalenceUnitIso : 𝟭 (HomologicalComplex₂ C c₁ c₂) ≅ flipFunctor C c₁ c₂ ⋙ flipFunctor C c₂ c₁ := NatIso.ofComponents (fun K => HomologicalComplex.Hom.isoOfComponents (fun i₁ => HomologicalComplex.Hom.isoOfComponents (fun i₂ => Iso.refl _) (by aesop_cat)) (by aesop_cat)) (by aesop_cat) /-- Auxiliary definition for `HomologicalComplex₂.flipEquivalence`. -/ @[simps!] def flipEquivalenceCounitIso : flipFunctor C c₂ c₁ ⋙ flipFunctor C c₁ c₂ ≅ 𝟭 (HomologicalComplex₂ C c₂ c₁) := NatIso.ofComponents (fun K => HomologicalComplex.Hom.isoOfComponents (fun i₂ => HomologicalComplex.Hom.isoOfComponents (fun i₁ => Iso.refl _) (by aesop_cat)) (by aesop_cat)) (by aesop_cat) /-- Flipping a complex of complexes over the diagonal, as an equivalence of categories. -/ @[simps] def flipEquivalence : HomologicalComplex₂ C c₁ c₂ ≌ HomologicalComplex₂ C c₂ c₁ where functor := flipFunctor C c₁ c₂ inverse := flipFunctor C c₂ c₁ unitIso := flipEquivalenceUnitIso C c₁ c₂ counitIso := flipEquivalenceCounitIso C c₁ c₂ variable (K : HomologicalComplex₂ C c₁ c₂) /-- The obvious isomorphism `(K.X x₁).X x₂ ≅ (K.X y₁).X y₂` when `x₁ = y₁` and `x₂ = y₂`. -/ def XXIsoOfEq {x₁ y₁ : I₁} (h₁ : x₁ = y₁) {x₂ y₂ : I₂} (h₂ : x₂ = y₂) : (K.X x₁).X x₂ ≅ (K.X y₁).X y₂ := eqToIso (by subst h₁ h₂; rfl) @[simp] lemma XXIsoOfEq_rfl (i₁ : I₁) (i₂ : I₂) : K.XXIsoOfEq (rfl : i₁ = i₁) (rfl : i₂ = i₂) = Iso.refl _ := rfl end HomologicalComplex₂
Algebra\Homology\HomologicalComplex.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison -/ import Mathlib.Algebra.Homology.ComplexShape import Mathlib.CategoryTheory.Subobject.Limits import Mathlib.CategoryTheory.GradedObject import Mathlib.Algebra.Homology.ShortComplex.Basic /-! # Homological complexes. A `HomologicalComplex V c` with a "shape" controlled by `c : ComplexShape ι` has chain groups `X i` (objects in `V`) indexed by `i : ι`, and a differential `d i j` whenever `c.Rel i j`. We in fact ask for differentials `d i j` for all `i j : ι`, but have a field `shape` requiring that these are zero when not allowed by `c`. This avoids a lot of dependent type theory hell! The composite of any two differentials `d i j ≫ d j k` must be zero. We provide `ChainComplex V α` for `α`-indexed chain complexes in which `d i j ≠ 0` only if `j + 1 = i`, and similarly `CochainComplex V α`, with `i = j + 1`. There is a category structure, where morphisms are chain maps. For `C : HomologicalComplex V c`, we define `C.xNext i`, which is either `C.X j` for some arbitrarily chosen `j` such that `c.r i j`, or `C.X i` if there is no such `j`. Similarly we have `C.xPrev j`. Defined in terms of these we have `C.dFrom i : C.X i ⟶ C.xNext i` and `C.dTo j : C.xPrev j ⟶ C.X j`, which are either defined as `C.d i j`, or zero, as needed. -/ universe v u open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {ι : Type*} variable (V : Type u) [Category.{v} V] [HasZeroMorphisms V] /-- A `HomologicalComplex V c` with a "shape" controlled by `c : ComplexShape ι` has chain groups `X i` (objects in `V`) indexed by `i : ι`, and a differential `d i j` whenever `c.Rel i j`. We in fact ask for differentials `d i j` for all `i j : ι`, but have a field `shape` requiring that these are zero when not allowed by `c`. This avoids a lot of dependent type theory hell! The composite of any two differentials `d i j ≫ d j k` must be zero. -/ structure HomologicalComplex (c : ComplexShape ι) where X : ι → V d : ∀ i j, X i ⟶ X j shape : ∀ i j, ¬c.Rel i j → d i j = 0 := by aesop_cat d_comp_d' : ∀ i j k, c.Rel i j → c.Rel j k → d i j ≫ d j k = 0 := by aesop_cat namespace HomologicalComplex attribute [simp] shape variable {V} {c : ComplexShape ι} @[reassoc (attr := simp)] theorem d_comp_d (C : HomologicalComplex V c) (i j k : ι) : C.d i j ≫ C.d j k = 0 := by by_cases hij : c.Rel i j · by_cases hjk : c.Rel j k · exact C.d_comp_d' i j k hij hjk · rw [C.shape j k hjk, comp_zero] · rw [C.shape i j hij, zero_comp] theorem ext {C₁ C₂ : HomologicalComplex V c} (h_X : C₁.X = C₂.X) (h_d : ∀ i j : ι, c.Rel i j → C₁.d i j ≫ eqToHom (congr_fun h_X j) = eqToHom (congr_fun h_X i) ≫ C₂.d i j) : C₁ = C₂ := by obtain ⟨X₁, d₁, s₁, h₁⟩ := C₁ obtain ⟨X₂, d₂, s₂, h₂⟩ := C₂ dsimp at h_X subst h_X simp only [mk.injEq, heq_eq_eq, true_and] ext i j by_cases hij : c.Rel i j · simpa only [comp_id, id_comp, eqToHom_refl] using h_d i j hij · rw [s₁ i j hij, s₂ i j hij] /-- The obvious isomorphism `K.X p ≅ K.X q` when `p = q`. -/ def XIsoOfEq (K : HomologicalComplex V c) {p q : ι} (h : p = q) : K.X p ≅ K.X q := eqToIso (by rw [h]) @[simp] lemma XIsoOfEq_rfl (K : HomologicalComplex V c) (p : ι) : K.XIsoOfEq (rfl : p = p) = Iso.refl _ := rfl @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₁₂ : p₁ = p₂) (h₂₃ : p₂ = p₃) : (K.XIsoOfEq h₁₂).hom ≫ (K.XIsoOfEq h₂₃).hom = (K.XIsoOfEq (h₁₂.trans h₂₃)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₁₂ : p₁ = p₂) (h₃₂ : p₃ = p₂) : (K.XIsoOfEq h₁₂).hom ≫ (K.XIsoOfEq h₃₂).inv = (K.XIsoOfEq (h₁₂.trans h₃₂.symm)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₂₁ : p₂ = p₁) (h₂₃ : p₂ = p₃) : (K.XIsoOfEq h₂₁).inv ≫ (K.XIsoOfEq h₂₃).hom = (K.XIsoOfEq (h₂₁.symm.trans h₂₃)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₂₁ : p₂ = p₁) (h₃₂ : p₃ = p₂) : (K.XIsoOfEq h₂₁).inv ≫ (K.XIsoOfEq h₃₂).inv = (K.XIsoOfEq (h₃₂.trans h₂₁).symm).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_d (K : HomologicalComplex V c) {p₁ p₂ : ι} (h : p₁ = p₂) (p₃ : ι) : (K.XIsoOfEq h).hom ≫ K.d p₂ p₃ = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_d (K : HomologicalComplex V c) {p₂ p₁ : ι} (h : p₂ = p₁) (p₃ : ι) : (K.XIsoOfEq h).inv ≫ K.d p₂ p₃ = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma d_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₂ p₃ : ι} (h : p₂ = p₃) (p₁ : ι) : K.d p₁ p₂ ≫ (K.XIsoOfEq h).hom = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma d_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₂ p₃ : ι} (h : p₃ = p₂) (p₁ : ι) : K.d p₁ p₂ ≫ (K.XIsoOfEq h).inv = K.d p₁ p₃ := by subst h; simp end HomologicalComplex /-- An `α`-indexed chain complex is a `HomologicalComplex` in which `d i j ≠ 0` only if `j + 1 = i`. -/ abbrev ChainComplex (α : Type*) [AddRightCancelSemigroup α] [One α] : Type _ := HomologicalComplex V (ComplexShape.down α) /-- An `α`-indexed cochain complex is a `HomologicalComplex` in which `d i j ≠ 0` only if `i + 1 = j`. -/ abbrev CochainComplex (α : Type*) [AddRightCancelSemigroup α] [One α] : Type _ := HomologicalComplex V (ComplexShape.up α) namespace ChainComplex @[simp] theorem prev (α : Type*) [AddRightCancelSemigroup α] [One α] (i : α) : (ComplexShape.down α).prev i = i + 1 := (ComplexShape.down α).prev_eq' rfl @[simp] theorem next (α : Type*) [AddGroup α] [One α] (i : α) : (ComplexShape.down α).next i = i - 1 := (ComplexShape.down α).next_eq' <| sub_add_cancel _ _ @[simp] theorem next_nat_zero : (ComplexShape.down ℕ).next 0 = 0 := by classical refine dif_neg ?_ push_neg intro apply Nat.noConfusion @[simp] theorem next_nat_succ (i : ℕ) : (ComplexShape.down ℕ).next (i + 1) = i := (ComplexShape.down ℕ).next_eq' rfl end ChainComplex namespace CochainComplex @[simp] theorem prev (α : Type*) [AddGroup α] [One α] (i : α) : (ComplexShape.up α).prev i = i - 1 := (ComplexShape.up α).prev_eq' <| sub_add_cancel _ _ @[simp] theorem next (α : Type*) [AddRightCancelSemigroup α] [One α] (i : α) : (ComplexShape.up α).next i = i + 1 := (ComplexShape.up α).next_eq' rfl @[simp] theorem prev_nat_zero : (ComplexShape.up ℕ).prev 0 = 0 := by classical refine dif_neg ?_ push_neg intro apply Nat.noConfusion @[simp] theorem prev_nat_succ (i : ℕ) : (ComplexShape.up ℕ).prev (i + 1) = i := (ComplexShape.up ℕ).prev_eq' rfl end CochainComplex namespace HomologicalComplex variable {V} variable {c : ComplexShape ι} (C : HomologicalComplex V c) /-- A morphism of homological complexes consists of maps between the chain groups, commuting with the differentials. -/ @[ext] structure Hom (A B : HomologicalComplex V c) where f : ∀ i, A.X i ⟶ B.X i comm' : ∀ i j, c.Rel i j → f i ≫ B.d i j = A.d i j ≫ f j := by aesop_cat @[reassoc (attr := simp)] theorem Hom.comm {A B : HomologicalComplex V c} (f : A.Hom B) (i j : ι) : f.f i ≫ B.d i j = A.d i j ≫ f.f j := by by_cases hij : c.Rel i j · exact f.comm' i j hij · rw [A.shape i j hij, B.shape i j hij, comp_zero, zero_comp] instance (A B : HomologicalComplex V c) : Inhabited (Hom A B) := ⟨{ f := fun i => 0 }⟩ /-- Identity chain map. -/ def id (A : HomologicalComplex V c) : Hom A A where f _ := 𝟙 _ /-- Composition of chain maps. -/ def comp (A B C : HomologicalComplex V c) (φ : Hom A B) (ψ : Hom B C) : Hom A C where f i := φ.f i ≫ ψ.f i section attribute [local simp] id comp instance : Category (HomologicalComplex V c) where Hom := Hom id := id comp := comp _ _ _ end -- Porting note: added because `Hom.ext` is not triggered automatically @[ext] lemma hom_ext {C D : HomologicalComplex V c} (f g : C ⟶ D) (h : ∀ i, f.f i = g.f i) : f = g := by apply Hom.ext funext apply h @[simp] theorem id_f (C : HomologicalComplex V c) (i : ι) : Hom.f (𝟙 C) i = 𝟙 (C.X i) := rfl @[simp, reassoc] theorem comp_f {C₁ C₂ C₃ : HomologicalComplex V c} (f : C₁ ⟶ C₂) (g : C₂ ⟶ C₃) (i : ι) : (f ≫ g).f i = f.f i ≫ g.f i := rfl @[simp] theorem eqToHom_f {C₁ C₂ : HomologicalComplex V c} (h : C₁ = C₂) (n : ι) : HomologicalComplex.Hom.f (eqToHom h) n = eqToHom (congr_fun (congr_arg HomologicalComplex.X h) n) := by subst h rfl -- We'll use this later to show that `HomologicalComplex V c` is preadditive when `V` is. theorem hom_f_injective {C₁ C₂ : HomologicalComplex V c} : Function.Injective fun f : Hom C₁ C₂ => f.f := by aesop_cat instance (X Y : HomologicalComplex V c) : Zero (X ⟶ Y) := ⟨{ f := fun i => 0}⟩ @[simp] theorem zero_f (C D : HomologicalComplex V c) (i : ι) : (0 : C ⟶ D).f i = 0 := rfl instance : HasZeroMorphisms (HomologicalComplex V c) where open ZeroObject /-- The zero complex -/ noncomputable def zero [HasZeroObject V] : HomologicalComplex V c where X _ := 0 d _ _ := 0 theorem isZero_zero [HasZeroObject V] : IsZero (zero : HomologicalComplex V c) := by refine ⟨fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩⟩ all_goals ext dsimp only [zero] subsingleton instance [HasZeroObject V] : HasZeroObject (HomologicalComplex V c) := ⟨⟨zero, isZero_zero⟩⟩ noncomputable instance [HasZeroObject V] : Inhabited (HomologicalComplex V c) := ⟨zero⟩ theorem congr_hom {C D : HomologicalComplex V c} {f g : C ⟶ D} (w : f = g) (i : ι) : f.f i = g.f i := congr_fun (congr_arg Hom.f w) i lemma mono_of_mono_f {K L : HomologicalComplex V c} (φ : K ⟶ L) (hφ : ∀ i, Mono (φ.f i)) : Mono φ where right_cancellation g h eq := by ext i rw [← cancel_mono (φ.f i)] exact congr_hom eq i lemma epi_of_epi_f {K L : HomologicalComplex V c} (φ : K ⟶ L) (hφ : ∀ i, Epi (φ.f i)) : Epi φ where left_cancellation g h eq := by ext i rw [← cancel_epi (φ.f i)] exact congr_hom eq i section variable (V c) /-- The functor picking out the `i`-th object of a complex. -/ @[simps] def eval (i : ι) : HomologicalComplex V c ⥤ V where obj C := C.X i map f := f.f i instance (i : ι) : (eval V c i).PreservesZeroMorphisms where /-- The functor forgetting the differential in a complex, obtaining a graded object. -/ @[simps] def forget : HomologicalComplex V c ⥤ GradedObject ι V where obj C := C.X map f := f.f instance : (forget V c).Faithful where map_injective h := by ext i exact congr_fun h i /-- Forgetting the differentials than picking out the `i`-th object is the same as just picking out the `i`-th object. -/ @[simps!] def forgetEval (i : ι) : forget V c ⋙ GradedObject.eval i ≅ eval V c i := NatIso.ofComponents fun X => Iso.refl _ end noncomputable section @[reassoc] lemma XIsoOfEq_hom_naturality {K L : HomologicalComplex V c} (φ : K ⟶ L) {n n' : ι} (h : n = n') : φ.f n ≫ (L.XIsoOfEq h).hom = (K.XIsoOfEq h).hom ≫ φ.f n' := by subst h; simp @[reassoc] lemma XIsoOfEq_inv_naturality {K L : HomologicalComplex V c} (φ : K ⟶ L) {n n' : ι} (h : n = n') : φ.f n' ≫ (L.XIsoOfEq h).inv = (K.XIsoOfEq h).inv ≫ φ.f n := by subst h; simp -- Porting note: removed @[simp] as the linter complained /-- If `C.d i j` and `C.d i j'` are both allowed, then we must have `j = j'`, and so the differentials only differ by an `eqToHom`. -/ theorem d_comp_eqToHom {i j j' : ι} (rij : c.Rel i j) (rij' : c.Rel i j') : C.d i j' ≫ eqToHom (congr_arg C.X (c.next_eq rij' rij)) = C.d i j := by obtain rfl := c.next_eq rij rij' simp only [eqToHom_refl, comp_id] -- Porting note: removed @[simp] as the linter complained /-- If `C.d i j` and `C.d i' j` are both allowed, then we must have `i = i'`, and so the differentials only differ by an `eqToHom`. -/ theorem eqToHom_comp_d {i i' j : ι} (rij : c.Rel i j) (rij' : c.Rel i' j) : eqToHom (congr_arg C.X (c.prev_eq rij rij')) ≫ C.d i' j = C.d i j := by obtain rfl := c.prev_eq rij rij' simp only [eqToHom_refl, id_comp] theorem kernel_eq_kernel [HasKernels V] {i j j' : ι} (r : c.Rel i j) (r' : c.Rel i j') : kernelSubobject (C.d i j) = kernelSubobject (C.d i j') := by rw [← d_comp_eqToHom C r r'] apply kernelSubobject_comp_mono theorem image_eq_image [HasImages V] [HasEqualizers V] {i i' j : ι} (r : c.Rel i j) (r' : c.Rel i' j) : imageSubobject (C.d i j) = imageSubobject (C.d i' j) := by rw [← eqToHom_comp_d C r r'] apply imageSubobject_iso_comp section /-- Either `C.X i`, if there is some `i` with `c.Rel i j`, or `C.X j`. -/ abbrev xPrev (j : ι) : V := C.X (c.prev j) /-- If `c.Rel i j`, then `C.xPrev j` is isomorphic to `C.X i`. -/ def xPrevIso {i j : ι} (r : c.Rel i j) : C.xPrev j ≅ C.X i := eqToIso <| by rw [← c.prev_eq' r] /-- If there is no `i` so `c.Rel i j`, then `C.xPrev j` is isomorphic to `C.X j`. -/ def xPrevIsoSelf {j : ι} (h : ¬c.Rel (c.prev j) j) : C.xPrev j ≅ C.X j := eqToIso <| congr_arg C.X (by dsimp [ComplexShape.prev] rw [dif_neg] push_neg; intro i hi have : c.prev j = i := c.prev_eq' hi rw [this] at h; contradiction) /-- Either `C.X j`, if there is some `j` with `c.rel i j`, or `C.X i`. -/ abbrev xNext (i : ι) : V := C.X (c.next i) /-- If `c.Rel i j`, then `C.xNext i` is isomorphic to `C.X j`. -/ def xNextIso {i j : ι} (r : c.Rel i j) : C.xNext i ≅ C.X j := eqToIso <| by rw [← c.next_eq' r] /-- If there is no `j` so `c.Rel i j`, then `C.xNext i` is isomorphic to `C.X i`. -/ def xNextIsoSelf {i : ι} (h : ¬c.Rel i (c.next i)) : C.xNext i ≅ C.X i := eqToIso <| congr_arg C.X (by dsimp [ComplexShape.next] rw [dif_neg]; rintro ⟨j, hj⟩ have : c.next i = j := c.next_eq' hj rw [this] at h; contradiction) /-- The differential mapping into `C.X j`, or zero if there isn't one. -/ abbrev dTo (j : ι) : C.xPrev j ⟶ C.X j := C.d (c.prev j) j /-- The differential mapping out of `C.X i`, or zero if there isn't one. -/ abbrev dFrom (i : ι) : C.X i ⟶ C.xNext i := C.d i (c.next i) theorem dTo_eq {i j : ι} (r : c.Rel i j) : C.dTo j = (C.xPrevIso r).hom ≫ C.d i j := by obtain rfl := c.prev_eq' r exact (Category.id_comp _).symm @[simp] theorem dTo_eq_zero {j : ι} (h : ¬c.Rel (c.prev j) j) : C.dTo j = 0 := C.shape _ _ h theorem dFrom_eq {i j : ι} (r : c.Rel i j) : C.dFrom i = C.d i j ≫ (C.xNextIso r).inv := by obtain rfl := c.next_eq' r exact (Category.comp_id _).symm @[simp] theorem dFrom_eq_zero {i : ι} (h : ¬c.Rel i (c.next i)) : C.dFrom i = 0 := C.shape _ _ h @[reassoc (attr := simp)] theorem xPrevIso_comp_dTo {i j : ι} (r : c.Rel i j) : (C.xPrevIso r).inv ≫ C.dTo j = C.d i j := by simp [C.dTo_eq r] @[reassoc (attr := simp)] theorem xPrevIsoSelf_comp_dTo {j : ι} (h : ¬c.Rel (c.prev j) j) : (C.xPrevIsoSelf h).inv ≫ C.dTo j = 0 := by simp [h] @[reassoc (attr := simp)] theorem dFrom_comp_xNextIso {i j : ι} (r : c.Rel i j) : C.dFrom i ≫ (C.xNextIso r).hom = C.d i j := by simp [C.dFrom_eq r] @[reassoc (attr := simp)] theorem dFrom_comp_xNextIsoSelf {i : ι} (h : ¬c.Rel i (c.next i)) : C.dFrom i ≫ (C.xNextIsoSelf h).hom = 0 := by simp [h] @[simp 1100] theorem dTo_comp_dFrom (j : ι) : C.dTo j ≫ C.dFrom j = 0 := C.d_comp_d _ _ _ theorem kernel_from_eq_kernel [HasKernels V] {i j : ι} (r : c.Rel i j) : kernelSubobject (C.dFrom i) = kernelSubobject (C.d i j) := by rw [C.dFrom_eq r] apply kernelSubobject_comp_mono theorem image_to_eq_image [HasImages V] [HasEqualizers V] {i j : ι} (r : c.Rel i j) : imageSubobject (C.dTo j) = imageSubobject (C.d i j) := by rw [C.dTo_eq r] apply imageSubobject_iso_comp end namespace Hom variable {C₁ C₂ C₃ : HomologicalComplex V c} /-- The `i`-th component of an isomorphism of chain complexes. -/ @[simps!] def isoApp (f : C₁ ≅ C₂) (i : ι) : C₁.X i ≅ C₂.X i := (eval V c i).mapIso f /-- Construct an isomorphism of chain complexes from isomorphism of the objects which commute with the differentials. -/ @[simps] def isoOfComponents (f : ∀ i, C₁.X i ≅ C₂.X i) (hf : ∀ i j, c.Rel i j → (f i).hom ≫ C₂.d i j = C₁.d i j ≫ (f j).hom := by aesop_cat) : C₁ ≅ C₂ where hom := { f := fun i => (f i).hom comm' := hf } inv := { f := fun i => (f i).inv comm' := fun i j hij => calc (f i).inv ≫ C₁.d i j = (f i).inv ≫ (C₁.d i j ≫ (f j).hom) ≫ (f j).inv := by simp _ = (f i).inv ≫ ((f i).hom ≫ C₂.d i j) ≫ (f j).inv := by rw [hf i j hij] _ = C₂.d i j ≫ (f j).inv := by simp } hom_inv_id := by ext i exact (f i).hom_inv_id inv_hom_id := by ext i exact (f i).inv_hom_id @[simp] theorem isoOfComponents_app (f : ∀ i, C₁.X i ≅ C₂.X i) (hf : ∀ i j, c.Rel i j → (f i).hom ≫ C₂.d i j = C₁.d i j ≫ (f j).hom) (i : ι) : isoApp (isoOfComponents f hf) i = f i := by ext simp theorem isIso_of_components (f : C₁ ⟶ C₂) [∀ n : ι, IsIso (f.f n)] : IsIso f := (HomologicalComplex.Hom.isoOfComponents fun n => asIso (f.f n)).isIso_hom /-! Lemmas relating chain maps and `dTo`/`dFrom`. -/ /-- `f.prev j` is `f.f i` if there is some `r i j`, and `f.f j` otherwise. -/ abbrev prev (f : Hom C₁ C₂) (j : ι) : C₁.xPrev j ⟶ C₂.xPrev j := f.f _ theorem prev_eq (f : Hom C₁ C₂) {i j : ι} (w : c.Rel i j) : f.prev j = (C₁.xPrevIso w).hom ≫ f.f i ≫ (C₂.xPrevIso w).inv := by obtain rfl := c.prev_eq' w simp only [xPrevIso, eqToIso_refl, Iso.refl_hom, Iso.refl_inv, comp_id, id_comp] /-- `f.next i` is `f.f j` if there is some `r i j`, and `f.f j` otherwise. -/ abbrev next (f : Hom C₁ C₂) (i : ι) : C₁.xNext i ⟶ C₂.xNext i := f.f _ theorem next_eq (f : Hom C₁ C₂) {i j : ι} (w : c.Rel i j) : f.next i = (C₁.xNextIso w).hom ≫ f.f j ≫ (C₂.xNextIso w).inv := by obtain rfl := c.next_eq' w simp only [xNextIso, eqToIso_refl, Iso.refl_hom, Iso.refl_inv, comp_id, id_comp] @[reassoc, elementwise] -- @[simp] -- Porting note (#10618): simp can prove this theorem comm_from (f : Hom C₁ C₂) (i : ι) : f.f i ≫ C₂.dFrom i = C₁.dFrom i ≫ f.next i := f.comm _ _ attribute [simp 1100] comm_from_assoc attribute [simp] comm_from_apply @[reassoc, elementwise] -- @[simp] -- Porting note (#10618): simp can prove this theorem comm_to (f : Hom C₁ C₂) (j : ι) : f.prev j ≫ C₂.dTo j = C₁.dTo j ≫ f.f j := f.comm _ _ attribute [simp 1100] comm_to_assoc attribute [simp] comm_to_apply /-- A morphism of chain complexes induces a morphism of arrows of the differentials out of each object. -/ def sqFrom (f : Hom C₁ C₂) (i : ι) : Arrow.mk (C₁.dFrom i) ⟶ Arrow.mk (C₂.dFrom i) := Arrow.homMk (f.comm_from i) @[simp] theorem sqFrom_left (f : Hom C₁ C₂) (i : ι) : (f.sqFrom i).left = f.f i := rfl @[simp] theorem sqFrom_right (f : Hom C₁ C₂) (i : ι) : (f.sqFrom i).right = f.next i := rfl @[simp] theorem sqFrom_id (C₁ : HomologicalComplex V c) (i : ι) : sqFrom (𝟙 C₁) i = 𝟙 _ := rfl @[simp] theorem sqFrom_comp (f : C₁ ⟶ C₂) (g : C₂ ⟶ C₃) (i : ι) : sqFrom (f ≫ g) i = sqFrom f i ≫ sqFrom g i := rfl /-- A morphism of chain complexes induces a morphism of arrows of the differentials into each object. -/ def sqTo (f : Hom C₁ C₂) (j : ι) : Arrow.mk (C₁.dTo j) ⟶ Arrow.mk (C₂.dTo j) := Arrow.homMk (f.comm_to j) @[simp] theorem sqTo_left (f : Hom C₁ C₂) (j : ι) : (f.sqTo j).left = f.prev j := rfl @[simp] theorem sqTo_right (f : Hom C₁ C₂) (j : ι) : (f.sqTo j).right = f.f j := rfl end Hom end end HomologicalComplex namespace ChainComplex section Of variable {V} {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] /-- Construct an `α`-indexed chain complex from a dependently-typed differential. -/ def of (X : α → V) (d : ∀ n, X (n + 1) ⟶ X n) (sq : ∀ n, d (n + 1) ≫ d n = 0) : ChainComplex V α := { X := X d := fun i j => if h : i = j + 1 then eqToHom (by rw [h]) ≫ d j else 0 shape := fun i j w => by dsimp rw [dif_neg (Ne.symm w)] d_comp_d' := fun i j k hij hjk => by dsimp at hij hjk substs hij hjk simp only [eqToHom_refl, id_comp, dite_eq_ite, ite_true, sq] } variable (X : α → V) (d : ∀ n, X (n + 1) ⟶ X n) (sq : ∀ n, d (n + 1) ≫ d n = 0) @[simp] theorem of_x (n : α) : (of X d sq).X n = X n := rfl @[simp] theorem of_d (j : α) : (of X d sq).d (j + 1) j = d j := by dsimp [of] rw [if_pos rfl, Category.id_comp] theorem of_d_ne {i j : α} (h : i ≠ j + 1) : (of X d sq).d i j = 0 := by dsimp [of] rw [dif_neg h] end Of section OfHom variable {V} {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] variable (X : α → V) (d_X : ∀ n, X (n + 1) ⟶ X n) (sq_X : ∀ n, d_X (n + 1) ≫ d_X n = 0) (Y : α → V) (d_Y : ∀ n, Y (n + 1) ⟶ Y n) (sq_Y : ∀ n, d_Y (n + 1) ≫ d_Y n = 0) /-- A constructor for chain maps between `α`-indexed chain complexes built using `ChainComplex.of`, from a dependently typed collection of morphisms. -/ @[simps] def ofHom (f : ∀ i : α, X i ⟶ Y i) (comm : ∀ i : α, f (i + 1) ≫ d_Y i = d_X i ≫ f i) : of X d_X sq_X ⟶ of Y d_Y sq_Y := { f comm' := fun n m => by by_cases h : n = m + 1 · subst h simpa using comm m · rw [of_d_ne X _ _ h, of_d_ne Y _ _ h] simp } end OfHom section Mk variable {V} variable (X₀ X₁ X₂ : V) (d₀ : X₁ ⟶ X₀) (d₁ : X₂ ⟶ X₁) (s : d₁ ≫ d₀ = 0) (succ : ∀ (S : ShortComplex V), Σ' (X₃ : V) (d₂ : X₃ ⟶ S.X₁), d₂ ≫ S.f = 0) /-- Auxiliary definition for `mk`. -/ def mkAux : ℕ → ShortComplex V | 0 => ShortComplex.mk _ _ s | n + 1 => ShortComplex.mk _ _ (succ (mkAux n)).2.2 /-- An inductive constructor for `ℕ`-indexed chain complexes. You provide explicitly the first two differentials, then a function which takes two differentials and the fact they compose to zero, and returns the next object, its differential, and the fact it composes appropriately to zero. See also `mk'`, which only sees the previous differential in the inductive step. -/ def mk : ChainComplex V ℕ := of (fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).X₃) (fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).g) fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).zero @[simp] theorem mk_X_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 0 = X₀ := rfl @[simp] theorem mk_X_1 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 1 = X₁ := rfl @[simp] theorem mk_X_2 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 2 = X₂ := rfl @[simp] theorem mk_d_1_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 1 0 = d₀ := by change ite (1 = 0 + 1) (𝟙 X₁ ≫ d₀) 0 = d₀ rw [if_pos rfl, Category.id_comp] @[simp] theorem mk_d_2_1 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 2 1 = d₁ := by change ite (2 = 1 + 1) (𝟙 X₂ ≫ d₁) 0 = d₁ rw [if_pos rfl, Category.id_comp] -- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed. /-- A simpler inductive constructor for `ℕ`-indexed chain complexes. You provide explicitly the first differential, then a function which takes a differential, and returns the next object, its differential, and the fact it composes appropriately to zero. -/ def mk' (X₀ X₁ : V) (d : X₁ ⟶ X₀) (succ' : ∀ {X₀ X₁ : V} (f : X₁ ⟶ X₀), Σ' (X₂ : V) (d : X₂ ⟶ X₁), d ≫ f = 0) : ChainComplex V ℕ := mk _ _ _ _ _ (succ' d).2.2 (fun S => succ' S.f) variable (succ' : ∀ {X₀ X₁ : V} (f : X₁ ⟶ X₀), Σ' (X₂ : V) (d : X₂ ⟶ X₁), d ≫ f = 0) @[simp] theorem mk'_X_0 : (mk' X₀ X₁ d₀ succ').X 0 = X₀ := rfl @[simp] theorem mk'_X_1 : (mk' X₀ X₁ d₀ succ').X 1 = X₁ := rfl @[simp] theorem mk'_d_1_0 : (mk' X₀ X₁ d₀ succ').d 1 0 = d₀ := by change ite (1 = 0 + 1) (𝟙 X₁ ≫ d₀) 0 = d₀ rw [if_pos rfl, Category.id_comp] /- Porting note: Downstream constructions using `mk'` (e.g. in `CategoryTheory.Abelian.Projective`) have very slow proofs, because of bad simp lemmas. It would be better to write good lemmas here if possible, such as ``` theorem mk'_X_succ (j : ℕ) : (mk' X₀ X₁ d₀ succ').X (j + 2) = (succ' ⟨_, _, (mk' X₀ X₁ d₀ succ').d (j + 1) j⟩).1 := by sorry theorem mk'_d_succ {i j : ℕ} : (mk' X₀ X₁ d₀ succ').d (j + 2) (j + 1) = eqToHom (mk'_X_succ X₀ X₁ d₀ succ' j) ≫ (succ' ⟨_, _, (mk' X₀ X₁ d₀ succ').d (j + 1) j⟩).2.1 := sorry ``` These are already tricky, and it may be better to write analogous lemmas for `mk` first. -/ end Mk section MkHom variable {V} variable (P Q : ChainComplex V ℕ) (zero : P.X 0 ⟶ Q.X 0) (one : P.X 1 ⟶ Q.X 1) (one_zero_comm : one ≫ Q.d 1 0 = P.d 1 0 ≫ zero) (succ : ∀ (n : ℕ) (p : Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n + 1) ⟶ Q.X (n + 1)), f' ≫ Q.d (n + 1) n = P.d (n + 1) n ≫ f), Σ'f'' : P.X (n + 2) ⟶ Q.X (n + 2), f'' ≫ Q.d (n + 2) (n + 1) = P.d (n + 2) (n + 1) ≫ p.2.1) /-- An auxiliary construction for `mkHom`. Here we build by induction a family of commutative squares, but don't require at the type level that these successive commutative squares actually agree. They do in fact agree, and we then capture that at the type level (i.e. by constructing a chain map) in `mkHom`. -/ def mkHomAux : ∀ n, Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n + 1) ⟶ Q.X (n + 1)), f' ≫ Q.d (n + 1) n = P.d (n + 1) n ≫ f | 0 => ⟨zero, one, one_zero_comm⟩ | n + 1 => ⟨(mkHomAux n).2.1, (succ n (mkHomAux n)).1, (succ n (mkHomAux n)).2⟩ /-- A constructor for chain maps between `ℕ`-indexed chain complexes, working by induction on commutative squares. You need to provide the components of the chain map in degrees 0 and 1, show that these form a commutative square, and then give a construction of each component, and the fact that it forms a commutative square with the previous component, using as an inductive hypothesis the data (and commutativity) of the previous two components. -/ def mkHom : P ⟶ Q where f n := (mkHomAux P Q zero one one_zero_comm succ n).1 comm' n m := by rintro (rfl : m + 1 = n) exact (mkHomAux P Q zero one one_zero_comm succ m).2.2 @[simp] theorem mkHom_f_0 : (mkHom P Q zero one one_zero_comm succ).f 0 = zero := rfl @[simp] theorem mkHom_f_1 : (mkHom P Q zero one one_zero_comm succ).f 1 = one := rfl @[simp] theorem mkHom_f_succ_succ (n : ℕ) : (mkHom P Q zero one one_zero_comm succ).f (n + 2) = (succ n ⟨(mkHom P Q zero one one_zero_comm succ).f n, (mkHom P Q zero one one_zero_comm succ).f (n + 1), (mkHom P Q zero one one_zero_comm succ).comm (n + 1) n⟩).1 := by dsimp [mkHom, mkHomAux] end MkHom end ChainComplex namespace CochainComplex section Of variable {V} {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] /-- Construct an `α`-indexed cochain complex from a dependently-typed differential. -/ def of (X : α → V) (d : ∀ n, X n ⟶ X (n + 1)) (sq : ∀ n, d n ≫ d (n + 1) = 0) : CochainComplex V α := { X := X d := fun i j => if h : i + 1 = j then d _ ≫ eqToHom (by rw [h]) else 0 shape := fun i j w => by dsimp rw [dif_neg] exact w d_comp_d' := fun i j k => by dsimp split_ifs with h h' h' · substs h h' simp [sq] all_goals simp } variable (X : α → V) (d : ∀ n, X n ⟶ X (n + 1)) (sq : ∀ n, d n ≫ d (n + 1) = 0) @[simp] theorem of_x (n : α) : (of X d sq).X n = X n := rfl @[simp] theorem of_d (j : α) : (of X d sq).d j (j + 1) = d j := by dsimp [of] rw [if_pos rfl, Category.comp_id] theorem of_d_ne {i j : α} (h : i + 1 ≠ j) : (of X d sq).d i j = 0 := by dsimp [of] rw [dif_neg h] end Of section OfHom variable {V} {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] variable (X : α → V) (d_X : ∀ n, X n ⟶ X (n + 1)) (sq_X : ∀ n, d_X n ≫ d_X (n + 1) = 0) (Y : α → V) (d_Y : ∀ n, Y n ⟶ Y (n + 1)) (sq_Y : ∀ n, d_Y n ≫ d_Y (n + 1) = 0) /-- A constructor for chain maps between `α`-indexed cochain complexes built using `CochainComplex.of`, from a dependently typed collection of morphisms. -/ @[simps] def ofHom (f : ∀ i : α, X i ⟶ Y i) (comm : ∀ i : α, f i ≫ d_Y i = d_X i ≫ f (i + 1)) : of X d_X sq_X ⟶ of Y d_Y sq_Y := { f comm' := fun n m => by by_cases h : n + 1 = m · subst h simpa using comm n · rw [of_d_ne X _ _ h, of_d_ne Y _ _ h] simp } end OfHom section Mk variable {V} variable (X₀ X₁ X₂ : V) (d₀ : X₀ ⟶ X₁) (d₁ : X₁ ⟶ X₂) (s : d₀ ≫ d₁ = 0) (succ : ∀ (S : ShortComplex V), Σ' (X₄ : V) (d₂ : S.X₃ ⟶ X₄), S.g ≫ d₂ = 0) /-- Auxiliary definition for `mk`. -/ def mkAux : ℕ → ShortComplex V | 0 => ShortComplex.mk _ _ s | n + 1 => ShortComplex.mk _ _ (succ (mkAux n)).2.2 /-- An inductive constructor for `ℕ`-indexed cochain complexes. You provide explicitly the first two differentials, then a function which takes two differentials and the fact they compose to zero, and returns the next object, its differential, and the fact it composes appropriately to zero. See also `mk'`, which only sees the previous differential in the inductive step. -/ def mk : CochainComplex V ℕ := of (fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).X₁) (fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).f) fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).zero @[simp] theorem mk_X_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 0 = X₀ := rfl @[simp] theorem mk_X_1 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 1 = X₁ := rfl @[simp] theorem mk_X_2 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 2 = X₂ := rfl @[simp] theorem mk_d_1_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 0 1 = d₀ := by change ite (1 = 0 + 1) (d₀ ≫ 𝟙 X₁) 0 = d₀ rw [if_pos rfl, Category.comp_id] @[simp] theorem mk_d_2_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 1 2 = d₁ := by change ite (2 = 1 + 1) (d₁ ≫ 𝟙 X₂) 0 = d₁ rw [if_pos rfl, Category.comp_id] -- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed. /-- A simpler inductive constructor for `ℕ`-indexed cochain complexes. You provide explicitly the first differential, then a function which takes a differential, and returns the next object, its differential, and the fact it composes appropriately to zero. -/ def mk' (X₀ X₁ : V) (d : X₀ ⟶ X₁) -- (succ' : ∀ : ΣX₀ X₁ : V, X₀ ⟶ X₁, Σ' (X₂ : V) (d : t.2.1 ⟶ X₂), t.2.2 ≫ d = 0) : (succ' : ∀ {X₀ X₁ : V} (f : X₀ ⟶ X₁), Σ' (X₂ : V) (d : X₁ ⟶ X₂), f ≫ d = 0) : CochainComplex V ℕ := mk _ _ _ _ _ (succ' d).2.2 (fun S => succ' S.g) variable (succ' : ∀ {X₀ X₁ : V} (f : X₀ ⟶ X₁), Σ' (X₂ : V) (d : X₁ ⟶ X₂), f ≫ d = 0) @[simp] theorem mk'_X_0 : (mk' X₀ X₁ d₀ succ').X 0 = X₀ := rfl @[simp] theorem mk'_X_1 : (mk' X₀ X₁ d₀ succ').X 1 = X₁ := rfl @[simp] theorem mk'_d_1_0 : (mk' X₀ X₁ d₀ succ').d 0 1 = d₀ := by change ite (1 = 0 + 1) (d₀ ≫ 𝟙 X₁) 0 = d₀ rw [if_pos rfl, Category.comp_id] -- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed. end Mk section MkHom variable {V} variable (P Q : CochainComplex V ℕ) (zero : P.X 0 ⟶ Q.X 0) (one : P.X 1 ⟶ Q.X 1) (one_zero_comm : zero ≫ Q.d 0 1 = P.d 0 1 ≫ one) (succ : ∀ (n : ℕ) (p : Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n + 1) ⟶ Q.X (n + 1)), f ≫ Q.d n (n + 1) = P.d n (n + 1) ≫ f'), Σ' f'' : P.X (n + 2) ⟶ Q.X (n + 2), p.2.1 ≫ Q.d (n + 1) (n + 2) = P.d (n + 1) (n + 2) ≫ f'') /-- An auxiliary construction for `mkHom`. Here we build by induction a family of commutative squares, but don't require at the type level that these successive commutative squares actually agree. They do in fact agree, and we then capture that at the type level (i.e. by constructing a chain map) in `mkHom`. -/ def mkHomAux : ∀ n, Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n + 1) ⟶ Q.X (n + 1)), f ≫ Q.d n (n + 1) = P.d n (n + 1) ≫ f' | 0 => ⟨zero, one, one_zero_comm⟩ | n + 1 => ⟨(mkHomAux n).2.1, (succ n (mkHomAux n)).1, (succ n (mkHomAux n)).2⟩ /-- A constructor for chain maps between `ℕ`-indexed cochain complexes, working by induction on commutative squares. You need to provide the components of the chain map in degrees 0 and 1, show that these form a commutative square, and then give a construction of each component, and the fact that it forms a commutative square with the previous component, using as an inductive hypothesis the data (and commutativity) of the previous two components. -/ def mkHom : P ⟶ Q where f n := (mkHomAux P Q zero one one_zero_comm succ n).1 comm' n m := by rintro (rfl : n + 1 = m) exact (mkHomAux P Q zero one one_zero_comm succ n).2.2 @[simp] theorem mkHom_f_0 : (mkHom P Q zero one one_zero_comm succ).f 0 = zero := rfl @[simp] theorem mkHom_f_1 : (mkHom P Q zero one one_zero_comm succ).f 1 = one := rfl @[simp] theorem mkHom_f_succ_succ (n : ℕ) : (mkHom P Q zero one one_zero_comm succ).f (n + 2) = (succ n ⟨(mkHom P Q zero one one_zero_comm succ).f n, (mkHom P Q zero one one_zero_comm succ).f (n + 1), (mkHom P Q zero one one_zero_comm succ).comm n (n + 1)⟩).1 := by dsimp [mkHom, mkHomAux] end MkHom end CochainComplex
Algebra\Homology\HomologicalComplexAbelian.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Additive import Mathlib.Algebra.Homology.HomologicalComplexLimits import Mathlib.Algebra.Homology.ShortComplex.ShortExact /-! # THe category of homological complexes is abelian If `C` is an abelian category, then `HomologicalComplex C c` is an abelian category for any complex shape `c : ComplexShape ι`. We also obtain that a short complex in `HomologicalComplex C c` is exact (resp. short exact) iff degreewise it is so. -/ open CategoryTheory Category Limits namespace HomologicalComplex variable {C ι : Type*} {c : ComplexShape ι} [Category C] [Abelian C] noncomputable instance : NormalEpiCategory (HomologicalComplex C c) := ⟨fun p _ => NormalEpi.mk _ (kernel.ι p) (kernel.condition _) (isColimitOfEval _ _ (fun _ => Abelian.isColimitMapCoconeOfCokernelCoforkOfπ _ _))⟩ noncomputable instance : NormalMonoCategory (HomologicalComplex C c) := ⟨fun p _ => NormalMono.mk _ (cokernel.π p) (cokernel.condition _) (isLimitOfEval _ _ (fun _ => Abelian.isLimitMapConeOfKernelForkOfι _ _))⟩ noncomputable instance : Abelian (HomologicalComplex C c) where variable (S : ShortComplex (HomologicalComplex C c)) lemma exact_of_degreewise_exact (hS : ∀ (i : ι), (S.map (eval C c i)).Exact) : S.Exact := by simp only [ShortComplex.exact_iff_isZero_homology] at hS ⊢ rw [IsZero.iff_id_eq_zero] ext i apply (IsZero.of_iso (hS i) (S.mapHomologyIso (eval C c i)).symm).eq_of_src lemma shortExact_of_degreewise_shortExact (hS : ∀ (i : ι), (S.map (eval C c i)).ShortExact) : S.ShortExact where mono_f := mono_of_mono_f _ (fun i => (hS i).mono_f) epi_g := epi_of_epi_f _ (fun i => (hS i).epi_g) exact := exact_of_degreewise_exact S (fun i => (hS i).exact) lemma exact_iff_degreewise_exact : S.Exact ↔ ∀ (i : ι), (S.map (eval C c i)).Exact := by constructor · intro hS i exact hS.map (eval C c i) · exact exact_of_degreewise_exact S lemma shortExact_iff_degreewise_shortExact : S.ShortExact ↔ ∀ (i : ι), (S.map (eval C c i)).ShortExact := by constructor · intro hS i have := hS.mono_f have := hS.epi_g exact hS.map (eval C c i) · exact shortExact_of_degreewise_shortExact S end HomologicalComplex
Algebra\Homology\HomologicalComplexBiprod.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomologicalComplexLimits import Mathlib.Algebra.Homology.Additive /-! Binary biproducts of homological complexes In this file, it is shown that if two homological complex `K` and `L` in a preadditive category are such that for all `i : ι`, the binary biproduct `K.X i ⊞ L.X i` exists, then `K ⊞ L` exists, and there is an isomorphism `biprodXIso K L i : (K ⊞ L).X i ≅ (K.X i) ⊞ (L.X i)`. -/ open CategoryTheory Limits namespace HomologicalComplex variable {C ι : Type*} [Category C] [Preadditive C] {c : ComplexShape ι} (K L : HomologicalComplex C c) [∀ i, HasBinaryBiproduct (K.X i) (L.X i)] instance (i : ι) : HasBinaryBiproduct ((eval C c i).obj K) ((eval C c i).obj L) := by dsimp [eval] infer_instance instance (i : ι) : HasLimit ((pair K L) ⋙ (eval C c i)) := by have e : _ ≅ pair (K.X i) (L.X i) := diagramIsoPair (pair K L ⋙ eval C c i) exact hasLimitOfIso e.symm instance (i : ι) : HasColimit ((pair K L) ⋙ (eval C c i)) := by have e : _ ≅ pair (K.X i) (L.X i) := diagramIsoPair (pair K L ⋙ eval C c i) exact hasColimitOfIso e instance : HasBinaryBiproduct K L := HasBinaryBiproduct.of_hasBinaryProduct _ _ instance (i : ι) : PreservesBinaryBiproduct K L (eval C c i) := preservesBinaryBiproductOfPreservesBinaryProduct _ /-- The canonical isomorphism `(K ⊞ L).X i ≅ (K.X i) ⊞ (L.X i)`. -/ noncomputable def biprodXIso (i : ι) : (K ⊞ L).X i ≅ (K.X i) ⊞ (L.X i) := (eval C c i).mapBiprod K L @[reassoc (attr := simp)] lemma inl_biprodXIso_inv (i : ι) : biprod.inl ≫ (biprodXIso K L i).inv = (biprod.inl : K ⟶ K ⊞ L).f i := by simp [biprodXIso] @[reassoc (attr := simp)] lemma inr_biprodXIso_inv (i : ι) : biprod.inr ≫ (biprodXIso K L i).inv = (biprod.inr : L ⟶ K ⊞ L).f i := by simp [biprodXIso] @[reassoc (attr := simp)] lemma biprodXIso_hom_fst (i : ι) : (biprodXIso K L i).hom ≫ biprod.fst = (biprod.fst : K ⊞ L ⟶ K).f i := by simp [biprodXIso] @[reassoc (attr := simp)] lemma biprodXIso_hom_snd (i : ι) : (biprodXIso K L i).hom ≫ biprod.snd = (biprod.snd : K ⊞ L ⟶ L).f i := by simp [biprodXIso] @[reassoc (attr := simp)] lemma biprod_inl_fst_f (i : ι) : (biprod.inl : K ⟶ K ⊞ L).f i ≫ (biprod.fst : K ⊞ L ⟶ K).f i = 𝟙 _ := by rw [← comp_f, biprod.inl_fst, id_f] @[reassoc (attr := simp)] lemma biprod_inl_snd_f (i : ι) : (biprod.inl : K ⟶ K ⊞ L).f i ≫ (biprod.snd : K ⊞ L ⟶ L).f i = 0 := by rw [← comp_f, biprod.inl_snd, zero_f] @[reassoc (attr := simp)] lemma biprod_inr_fst_f (i : ι) : (biprod.inr : L ⟶ K ⊞ L).f i ≫ (biprod.fst : K ⊞ L ⟶ K).f i = 0 := by rw [← comp_f, biprod.inr_fst, zero_f] @[reassoc (attr := simp)] lemma biprod_inr_snd_f (i : ι) : (biprod.inr : L ⟶ K ⊞ L).f i ≫ (biprod.snd : K ⊞ L ⟶ L).f i = 𝟙 _ := by rw [← comp_f, biprod.inr_snd, id_f] variable {K L} variable {M : HomologicalComplex C c} @[reassoc (attr := simp)] lemma biprod_inl_desc_f (α : K ⟶ M) (β : L ⟶ M) (i : ι) : (biprod.inl : K ⟶ K ⊞ L).f i ≫ (biprod.desc α β).f i = α.f i := by rw [← comp_f, biprod.inl_desc] @[reassoc (attr := simp)] lemma biprod_inr_desc_f (α : K ⟶ M) (β : L ⟶ M) (i : ι) : (biprod.inr : L ⟶ K ⊞ L).f i ≫ (biprod.desc α β).f i = β.f i := by rw [← comp_f, biprod.inr_desc] @[reassoc (attr := simp)] lemma biprod_lift_fst_f (α : M ⟶ K) (β : M ⟶ L) (i : ι) : (biprod.lift α β).f i ≫ (biprod.fst : K ⊞ L ⟶ K).f i = α.f i := by rw [← comp_f, biprod.lift_fst] @[reassoc (attr := simp)] lemma biprod_lift_snd_f (α : M ⟶ K) (β : M ⟶ L) (i : ι) : (biprod.lift α β).f i ≫ (biprod.snd : K ⊞ L ⟶ L).f i = β.f i := by rw [← comp_f, biprod.lift_snd] end HomologicalComplex
Algebra\Homology\HomologicalComplexLimits.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Single import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits import Mathlib.CategoryTheory.Limits.Preserves.Finite import Mathlib.CategoryTheory.Limits.Constructions.EpiMono /-! # Limits and colimits in the category of homological complexes In this file, it is shown that if a category `C` has (co)limits of shape `J`, then it is also the case of the categories `HomologicalComplex C c`, and the evaluation functors `eval C c i : HomologicalComplex C c ⥤ C` commute to these. -/ open CategoryTheory Category Limits namespace HomologicalComplex variable {C ι J : Type*} [Category C] [Category J] {c : ComplexShape ι} [HasZeroMorphisms C] section variable (F : J ⥤ HomologicalComplex C c) /-- A cone in `HomologicalComplex C c` is limit if the induced cones obtained by applying `eval C c i : HomologicalComplex C c ⥤ C` for all `i` are limit. -/ def isLimitOfEval (s : Cone F) (hs : ∀ (i : ι), IsLimit ((eval C c i).mapCone s)) : IsLimit s where lift t := { f := fun i => (hs i).lift ((eval C c i).mapCone t) comm' := fun i i' _ => by apply IsLimit.hom_ext (hs i') intro j have eq := fun k => (hs k).fac ((eval C c k).mapCone t) simp only [Functor.mapCone_π_app, eval_map] at eq simp only [Functor.mapCone_π_app, eval_map, assoc] rw [eq i', ← Hom.comm, reassoc_of% (eq i), Hom.comm] } fac t j := by ext i apply (hs i).fac uniq t m hm := by ext i apply (hs i).uniq ((eval C c i).mapCone t) intro j dsimp simp only [← comp_f, hm] variable [∀ (n : ι), HasLimit (F ⋙ eval C c n)] /-- A cone for a functor `F : J ⥤ HomologicalComplex C c` which is given in degree `n` by the limit `F ⋙ eval C c n`. -/ @[simps] noncomputable def coneOfHasLimitEval : Cone F where pt := { X := fun n => limit (F ⋙ eval C c n) d := fun n m => limMap { app := fun j => (F.obj j).d n m } shape := fun {n m} h => by ext j rw [limMap_π] dsimp rw [(F.obj j).shape _ _ h, comp_zero, zero_comp] } π := { app := fun j => { f := fun n => limit.π _ j } naturality := fun i j φ => by ext n dsimp erw [limit.w, id_comp] } /-- The cone `coneOfHasLimitEval F` is limit. -/ noncomputable def isLimitConeOfHasLimitEval : IsLimit (coneOfHasLimitEval F) := isLimitOfEval _ _ (fun _ => limit.isLimit _) instance : HasLimit F := ⟨⟨⟨_, isLimitConeOfHasLimitEval F⟩⟩⟩ noncomputable instance (n : ι) : PreservesLimit F (eval C c n) := preservesLimitOfPreservesLimitCone (isLimitConeOfHasLimitEval F) (limit.isLimit _) end instance [HasLimitsOfShape J C] : HasLimitsOfShape J (HomologicalComplex C c) := ⟨inferInstance⟩ noncomputable instance [HasLimitsOfShape J C] (n : ι) : PreservesLimitsOfShape J (eval C c n) := ⟨inferInstance⟩ instance [HasFiniteLimits C] : HasFiniteLimits (HomologicalComplex C c) := ⟨fun _ _ => inferInstance⟩ noncomputable instance [HasFiniteLimits C] (n : ι) : PreservesFiniteLimits (eval C c n) := ⟨fun _ _ _ => inferInstance⟩ instance [HasFiniteLimits C] {K L : HomologicalComplex C c} (φ : K ⟶ L) [Mono φ] (n : ι) : Mono (φ.f n) := by change Mono ((HomologicalComplex.eval C c n).map φ) infer_instance section variable (F : J ⥤ HomologicalComplex C c) /-- A cocone in `HomologicalComplex C c` is colimit if the induced cocones obtained by applying `eval C c i : HomologicalComplex C c ⥤ C` for all `i` are colimit. -/ def isColimitOfEval (s : Cocone F) (hs : ∀ (i : ι), IsColimit ((eval C c i).mapCocone s)) : IsColimit s where desc t := { f := fun i => (hs i).desc ((eval C c i).mapCocone t) comm' := fun i i' _ => by apply IsColimit.hom_ext (hs i) intro j have eq := fun k => (hs k).fac ((eval C c k).mapCocone t) simp only [Functor.mapCocone_ι_app, eval_map] at eq simp only [Functor.mapCocone_ι_app, eval_map, assoc] rw [reassoc_of% (eq i), Hom.comm_assoc, eq i', Hom.comm] } fac t j := by ext i apply (hs i).fac uniq t m hm := by ext i apply (hs i).uniq ((eval C c i).mapCocone t) intro j dsimp simp only [← comp_f, hm] variable [∀ (n : ι), HasColimit (F ⋙ HomologicalComplex.eval C c n)] /-- A cocone for a functor `F : J ⥤ HomologicalComplex C c` which is given in degree `n` by the colimit of `F ⋙ eval C c n`. -/ @[simps] noncomputable def coconeOfHasColimitEval : Cocone F where pt := { X := fun n => colimit (F ⋙ eval C c n) d := fun n m => colimMap { app := fun j => (F.obj j).d n m } shape := fun {n m} h => by ext j rw [ι_colimMap] dsimp rw [(F.obj j).shape _ _ h, zero_comp, comp_zero] } ι := { app := fun j => { f := fun n => colimit.ι (F ⋙ eval C c n) j } naturality := fun i j φ => by ext n dsimp erw [colimit.w (F ⋙ eval C c n) φ, comp_id] } /-- The cocone `coconeOfHasLimitEval F` is colimit. -/ noncomputable def isColimitCoconeOfHasColimitEval : IsColimit (coconeOfHasColimitEval F) := isColimitOfEval _ _ (fun _ => colimit.isColimit _) instance : HasColimit F := ⟨⟨⟨_, isColimitCoconeOfHasColimitEval F⟩⟩⟩ noncomputable instance (n : ι) : PreservesColimit F (eval C c n) := preservesColimitOfPreservesColimitCocone (isColimitCoconeOfHasColimitEval F) (colimit.isColimit _) end instance [HasColimitsOfShape J C] : HasColimitsOfShape J (HomologicalComplex C c) := ⟨inferInstance⟩ noncomputable instance [HasColimitsOfShape J C] (n : ι) : PreservesColimitsOfShape J (eval C c n) := ⟨inferInstance⟩ instance [HasFiniteColimits C] : HasFiniteColimits (HomologicalComplex C c) := ⟨fun _ _ => inferInstance⟩ noncomputable instance [HasFiniteColimits C] (n : ι) : PreservesFiniteColimits (eval C c n) := ⟨fun _ _ _ => inferInstance⟩ instance [HasFiniteColimits C] {K L : HomologicalComplex C c} (φ : K ⟶ L) [Epi φ] (n : ι) : Epi (φ.f n) := by change Epi ((HomologicalComplex.eval C c n).map φ) infer_instance /-- A functor `D ⥤ HomologicalComplex C c` preserves limits of shape `J` if for any `i`, `G ⋙ eval C c i` does. -/ def preservesLimitsOfShapeOfEval {D : Type*} [Category D] (G : D ⥤ HomologicalComplex C c) (_ : ∀ (i : ι), PreservesLimitsOfShape J (G ⋙ eval C c i)) : PreservesLimitsOfShape J G := ⟨fun {_} => ⟨fun hs ↦ isLimitOfEval _ _ (fun i => isLimitOfPreserves (G ⋙ eval C c i) hs)⟩⟩ /-- A functor `D ⥤ HomologicalComplex C c` preserves colimits of shape `J` if for any `i`, `G ⋙ eval C c i` does. -/ def preservesColimitsOfShapeOfEval {D : Type*} [Category D] (G : D ⥤ HomologicalComplex C c) (_ : ∀ (i : ι), PreservesColimitsOfShape J (G ⋙ eval C c i)) : PreservesColimitsOfShape J G := ⟨fun {_} => ⟨fun hs ↦ isColimitOfEval _ _ (fun i => isColimitOfPreserves (G ⋙ eval C c i) hs)⟩⟩ section variable [HasZeroObject C] [DecidableEq ι] (i : ι) noncomputable instance : PreservesLimitsOfShape J (single C c i) := preservesLimitsOfShapeOfEval _ (fun j => by by_cases h : j = i · subst h exact preservesLimitsOfShapeOfNatIso (singleCompEvalIsoSelf C c j).symm · exact Functor.preservesLimitsOfShapeOfIsZero _ (isZero_single_comp_eval C c _ _ h) _) noncomputable instance : PreservesColimitsOfShape J (single C c i) := preservesColimitsOfShapeOfEval _ (fun j => by by_cases h : j = i · subst h exact preservesColimitsOfShapeOfNatIso (singleCompEvalIsoSelf C c j).symm · exact Functor.preservesColimitsOfShapeOfIsZero _ (isZero_single_comp_eval C c _ _ h) _) noncomputable instance : PreservesFiniteLimits (single C c i) := ⟨by intros; infer_instance⟩ noncomputable instance : PreservesFiniteColimits (single C c i) := ⟨by intros; infer_instance⟩ end end HomologicalComplex
Algebra\Homology\HomologySequence.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex import Mathlib.Algebra.Homology.ShortComplex.SnakeLemma import Mathlib.Algebra.Homology.ShortComplex.ShortExact import Mathlib.Algebra.Homology.HomologicalComplexLimits /-! # The homology sequence If `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` is a short exact sequence in a category of complexes `HomologicalComplex C c` in an abelian category (i.e. `S` is a short complex in that category and satisfies `hS : S.ShortExact`), then whenever `i` and `j` are degrees such that `hij : c.Rel i j`, then there is a long exact sequence : `... ⟶ S.X₁.homology i ⟶ S.X₂.homology i ⟶ S.X₃.homology i ⟶ S.X₁.homology j ⟶ ...`. The connecting homomorphism `S.X₃.homology i ⟶ S.X₁.homology j` is `hS.δ i j hij`, and the exactness is asserted as lemmas `hS.homology_exact₁`, `hS.homology_exact₂` and `hS.homology_exact₃`. The proof is based on the snake lemma, similarly as it was originally done in the Liquid Tensor Experiment. ## References * https://stacks.math.columbia.edu/tag/0111 -/ open CategoryTheory Category Limits namespace HomologicalComplex section HasZeroMorphisms variable {C ι : Type*} [Category C] [HasZeroMorphisms C] {c : ComplexShape ι} (K L : HomologicalComplex C c) (φ : K ⟶ L) (i j : ι) [K.HasHomology i] [K.HasHomology j] [L.HasHomology i] [L.HasHomology j] /-- The morphism `K.opcycles i ⟶ K.cycles j` that is induced by `K.d i j`. -/ noncomputable def opcyclesToCycles [K.HasHomology i] [K.HasHomology j] : K.opcycles i ⟶ K.cycles j := K.liftCycles (K.fromOpcycles i j) _ rfl (by simp) @[reassoc (attr := simp)] lemma opcyclesToCycles_iCycles : K.opcyclesToCycles i j ≫ K.iCycles j = K.fromOpcycles i j := by dsimp only [opcyclesToCycles] simp @[reassoc] lemma pOpcycles_opcyclesToCycles_iCycles : K.pOpcycles i ≫ K.opcyclesToCycles i j ≫ K.iCycles j = K.d i j := by simp [opcyclesToCycles] @[reassoc (attr := simp)] lemma pOpcycles_opcyclesToCycles : K.pOpcycles i ≫ K.opcyclesToCycles i j = K.toCycles i j := by simp only [← cancel_mono (K.iCycles j), assoc, opcyclesToCycles_iCycles, p_fromOpcycles, toCycles_i] @[reassoc (attr := simp)] lemma homologyι_opcyclesToCycles : K.homologyι i ≫ K.opcyclesToCycles i j = 0 := by simp only [← cancel_mono (K.iCycles j), assoc, opcyclesToCycles_iCycles, homologyι_comp_fromOpcycles, zero_comp] @[reassoc (attr := simp)] lemma opcyclesToCycles_homologyπ : K.opcyclesToCycles i j ≫ K.homologyπ j = 0 := by simp only [← cancel_epi (K.pOpcycles i), pOpcycles_opcyclesToCycles_assoc, toCycles_comp_homologyπ, comp_zero] variable {K L} @[reassoc (attr := simp)] lemma opcyclesToCycles_naturality : opcyclesMap φ i ≫ opcyclesToCycles L i j = opcyclesToCycles K i j ≫ cyclesMap φ j := by simp only [← cancel_mono (L.iCycles j), ← cancel_epi (K.pOpcycles i), assoc, p_opcyclesMap_assoc, pOpcycles_opcyclesToCycles_iCycles, Hom.comm, cyclesMap_i, pOpcycles_opcyclesToCycles_iCycles_assoc] variable (C c) /-- The natural transformation `K.opcyclesToCycles i j : K.opcycles i ⟶ K.cycles j` for all `K : HomologicalComplex C c`. -/ @[simps] noncomputable def natTransOpCyclesToCycles [CategoryWithHomology C] : opcyclesFunctor C c i ⟶ cyclesFunctor C c j where app K := K.opcyclesToCycles i j end HasZeroMorphisms section Preadditive variable {C ι : Type*} [Category C] [Preadditive C] {c : ComplexShape ι} (K : HomologicalComplex C c) (i j : ι) (hij : c.Rel i j) namespace HomologySequence /-- The diagram `K.homology i ⟶ K.opcycles i ⟶ K.cycles j ⟶ K.homology j`. -/ @[simp] noncomputable def composableArrows₃ [K.HasHomology i] [K.HasHomology j] : ComposableArrows C 3 := ComposableArrows.mk₃ (K.homologyι i) (K.opcyclesToCycles i j) (K.homologyπ j) instance [K.HasHomology i] [K.HasHomology j] : Mono ((composableArrows₃ K i j).map' 0 1) := by dsimp infer_instance #adaptation_note /-- nightly-2024-03-11 We turn off simprocs here. Ideally someone will investigate whether `simp` lemmas can be rearranged so that this works without the `set_option`, *or* come up with a proposal regarding finer control of disabling simprocs. -/ set_option simprocs false in instance [K.HasHomology i] [K.HasHomology j] : Epi ((composableArrows₃ K i j).map' 2 3) := by dsimp infer_instance /-- The diagram `K.homology i ⟶ K.opcycles i ⟶ K.cycles j ⟶ K.homology j` is exact when `c.Rel i j`. -/ lemma composableArrows₃_exact [CategoryWithHomology C] : (composableArrows₃ K i j).Exact := by let S := ShortComplex.mk (K.homologyι i) (K.opcyclesToCycles i j) (by simp) let S' := ShortComplex.mk (K.homologyι i) (K.fromOpcycles i j) (by simp) let ι : S ⟶ S' := { τ₁ := 𝟙 _ τ₂ := 𝟙 _ τ₃ := K.iCycles j } have hS : S.Exact := by rw [ShortComplex.exact_iff_of_epi_of_isIso_of_mono ι] exact S'.exact_of_f_is_kernel (K.homologyIsKernel i j (c.next_eq' hij)) let T := ShortComplex.mk (K.opcyclesToCycles i j) (K.homologyπ j) (by simp) let T' := ShortComplex.mk (K.toCycles i j) (K.homologyπ j) (by simp) let π : T' ⟶ T := { τ₁ := K.pOpcycles i τ₂ := 𝟙 _ τ₃ := 𝟙 _ } have hT : T.Exact := by rw [← ShortComplex.exact_iff_of_epi_of_isIso_of_mono π] exact T'.exact_of_g_is_cokernel (K.homologyIsCokernel i j (c.prev_eq' hij)) apply ComposableArrows.exact_of_δ₀ · exact hS.exact_toComposableArrows · exact hT.exact_toComposableArrows variable (C) attribute [local simp] homologyMap_comp cyclesMap_comp opcyclesMap_comp #adaptation_note /-- nightly-2024-03-11 We turn off simprocs here. Ideally someone will investigate whether `simp` lemmas can be rearranged so that this works without the `set_option`, *or* come up with a proposal regarding finer control of disabling simprocs. -/ set_option simprocs false in /-- The functor `HomologicalComplex C c ⥤ ComposableArrows C 3` that maps `K` to the diagram `K.homology i ⟶ K.opcycles i ⟶ K.cycles j ⟶ K.homology j`. -/ @[simps] noncomputable def composableArrows₃Functor [CategoryWithHomology C] : HomologicalComplex C c ⥤ ComposableArrows C 3 where obj K := composableArrows₃ K i j map {K L} φ := ComposableArrows.homMk₃ (homologyMap φ i) (opcyclesMap φ i) (cyclesMap φ j) (homologyMap φ j) (by aesop_cat) (by aesop_cat) (by aesop_cat) end HomologySequence end Preadditive section Abelian variable {C ι : Type*} [Category C] [Abelian C] {c : ComplexShape ι} /-- If `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` is an exact sequence of homological complexes, then `X₁.opcycles i ⟶ X₂.opcycles i ⟶ X₃.opcycles i ⟶ 0` is exact. This lemma states the exactness at `X₂.opcycles i`, while the fact that `X₂.opcycles i ⟶ X₃.opcycles i` is an epi is an instance. -/ lemma opcycles_right_exact (S : ShortComplex (HomologicalComplex C c)) (hS : S.Exact) [Epi S.g] (i : ι) [S.X₁.HasHomology i] [S.X₂.HasHomology i] [S.X₃.HasHomology i] : (ShortComplex.mk (opcyclesMap S.f i) (opcyclesMap S.g i) (by rw [← opcyclesMap_comp, S.zero, opcyclesMap_zero])).Exact := by have : Epi (ShortComplex.map S (eval C c i)).g := by dsimp; infer_instance have hj := (hS.map (HomologicalComplex.eval C c i)).gIsCokernel apply ShortComplex.exact_of_g_is_cokernel refine CokernelCofork.IsColimit.ofπ' _ _ (fun {A} k hk => by dsimp at k hk ⊢ have H := CokernelCofork.IsColimit.desc' hj (S.X₂.pOpcycles i ≫ k) (by dsimp rw [← p_opcyclesMap_assoc, hk, comp_zero]) dsimp at H refine ⟨S.X₃.descOpcycles H.1 _ rfl ?_, ?_⟩ · rw [← cancel_epi (S.g.f (c.prev i)), comp_zero, Hom.comm_assoc, H.2, d_pOpcycles_assoc, zero_comp] · rw [← cancel_epi (S.X₂.pOpcycles i), opcyclesMap_comp_descOpcycles, p_descOpcycles, H.2]) /-- If `0 ⟶ X₁ ⟶ X₂ ⟶ X₃` is an exact sequence of homological complex, then `0 ⟶ X₁.cycles i ⟶ X₂.cycles i ⟶ X₃.cycles i` is exact. This lemma states the exactness at `X₂.cycles i`, while the fact that `X₁.cycles i ⟶ X₂.cycles i` is a mono is an instance. -/ lemma cycles_left_exact (S : ShortComplex (HomologicalComplex C c)) (hS : S.Exact) [Mono S.f] (i : ι) [S.X₁.HasHomology i] [S.X₂.HasHomology i] [S.X₃.HasHomology i] : (ShortComplex.mk (cyclesMap S.f i) (cyclesMap S.g i) (by rw [← cyclesMap_comp, S.zero, cyclesMap_zero])).Exact := by have : Mono (ShortComplex.map S (eval C c i)).f := by dsimp; infer_instance have hi := (hS.map (HomologicalComplex.eval C c i)).fIsKernel apply ShortComplex.exact_of_f_is_kernel exact KernelFork.IsLimit.ofι' _ _ (fun {A} k hk => by dsimp at k hk ⊢ have H := KernelFork.IsLimit.lift' hi (k ≫ S.X₂.iCycles i) (by dsimp rw [assoc, ← cyclesMap_i, reassoc_of% hk, zero_comp]) dsimp at H refine ⟨S.X₁.liftCycles H.1 _ rfl ?_, ?_⟩ · rw [← cancel_mono (S.f.f _), assoc, zero_comp, ← Hom.comm, reassoc_of% H.2, iCycles_d, comp_zero] · rw [← cancel_mono (S.X₂.iCycles i), liftCycles_comp_cyclesMap, liftCycles_i, H.2]) variable {S : ShortComplex (HomologicalComplex C c)} (hS : S.ShortExact) (i j : ι) (hij : c.Rel i j) namespace HomologySequence /-- Given a short exact short complex `S : HomologicalComplex C c`, and degrees `i` and `j` such that `c.Rel i j`, this is the snake diagram whose four lines are respectively obtained by applying the functors `homologyFunctor C c i`, `opcyclesFunctor C c i`, `cyclesFunctor C c j`, `homologyFunctor C c j` to `S`. Applying the snake lemma to this gives the homology sequence of `S`. -/ @[simps] noncomputable def snakeInput : ShortComplex.SnakeInput C where L₀ := (homologyFunctor C c i).mapShortComplex.obj S L₁ := (opcyclesFunctor C c i).mapShortComplex.obj S L₂ := (cyclesFunctor C c j).mapShortComplex.obj S L₃ := (homologyFunctor C c j).mapShortComplex.obj S v₀₁ := S.mapNatTrans (natTransHomologyι C c i) v₁₂ := S.mapNatTrans (natTransOpCyclesToCycles C c i j) v₂₃ := S.mapNatTrans (natTransHomologyπ C c j) h₀ := by apply ShortComplex.isLimitOfIsLimitπ all_goals exact (KernelFork.isLimitMapConeEquiv _ _).symm ((composableArrows₃_exact _ i j hij).exact 0).fIsKernel h₃ := by apply ShortComplex.isColimitOfIsColimitπ all_goals exact (CokernelCofork.isColimitMapCoconeEquiv _ _).symm ((composableArrows₃_exact _ i j hij).exact 1).gIsCokernel L₁_exact := by have := hS.epi_g exact opcycles_right_exact S hS.exact i L₂_exact := by have := hS.mono_f exact cycles_left_exact S hS.exact j epi_L₁_g := by have := hS.epi_g dsimp infer_instance mono_L₂_f := by have := hS.mono_f dsimp infer_instance end HomologySequence end Abelian end HomologicalComplex namespace CategoryTheory open HomologicalComplex HomologySequence variable {C ι : Type*} [Category C] [Abelian C] {c : ComplexShape ι} {S : ShortComplex (HomologicalComplex C c)} (hS : S.ShortExact) (i j : ι) (hij : c.Rel i j) namespace ShortComplex namespace ShortExact /-- The connecting homoomorphism `S.X₃.homology i ⟶ S.X₁.homology j` for a short exact short complex `S`. -/ noncomputable def δ : S.X₃.homology i ⟶ S.X₁.homology j := (snakeInput hS i j hij).δ @[reassoc (attr := simp)] lemma δ_comp : hS.δ i j hij ≫ HomologicalComplex.homologyMap S.f j = 0 := (snakeInput hS i j hij).δ_L₃_f @[reassoc (attr := simp)] lemma comp_δ : HomologicalComplex.homologyMap S.g i ≫ hS.δ i j hij = 0 := (snakeInput hS i j hij).L₀_g_δ /-- Exactness of `S.X₃.homology i ⟶ S.X₁.homology j ⟶ S.X₂.homology j`. -/ lemma homology_exact₁ : (ShortComplex.mk _ _ (δ_comp hS i j hij)).Exact := (snakeInput hS i j hij).L₂'_exact /-- Exactness of `S.X₁.homology i ⟶ S.X₂.homology i ⟶ S.X₃.homology i`. -/ lemma homology_exact₂ : (ShortComplex.mk (HomologicalComplex.homologyMap S.f i) (HomologicalComplex.homologyMap S.g i) (by rw [← HomologicalComplex.homologyMap_comp, S.zero, HomologicalComplex.homologyMap_zero])).Exact := by by_cases h : c.Rel i (c.next i) · exact (snakeInput hS i _ h).L₀_exact · have := hS.epi_g have : ∀ (K : HomologicalComplex C c), IsIso (K.homologyι i) := fun K => ShortComplex.isIso_homologyι (K.sc i) (K.shape _ _ h) have e : S.map (HomologicalComplex.homologyFunctor C c i) ≅ S.map (HomologicalComplex.opcyclesFunctor C c i) := ShortComplex.isoMk (asIso (S.X₁.homologyι i)) (asIso (S.X₂.homologyι i)) (asIso (S.X₃.homologyι i)) (by aesop_cat) (by aesop_cat) exact ShortComplex.exact_of_iso e.symm (opcycles_right_exact S hS.exact i) /-- Exactness of `S.X₂.homology i ⟶ S.X₃.homology i ⟶ S.X₁.homology j`. -/ lemma homology_exact₃ : (ShortComplex.mk _ _ (comp_δ hS i j hij)).Exact := (snakeInput hS i j hij).L₁'_exact lemma δ_eq' {A : C} (x₃ : A ⟶ S.X₃.homology i) (x₂ : A ⟶ S.X₂.opcycles i) (x₁ : A ⟶ S.X₁.cycles j) (h₂ : x₂ ≫ HomologicalComplex.opcyclesMap S.g i = x₃ ≫ S.X₃.homologyι i) (h₁ : x₁ ≫ HomologicalComplex.cyclesMap S.f j = x₂ ≫ S.X₂.opcyclesToCycles i j) : x₃ ≫ hS.δ i j hij = x₁ ≫ S.X₁.homologyπ j := (snakeInput hS i j hij).δ_eq x₃ x₂ x₁ h₂ h₁ lemma δ_eq {A : C} (x₃ : A ⟶ S.X₃.X i) (hx₃ : x₃ ≫ S.X₃.d i j = 0) (x₂ : A ⟶ S.X₂.X i) (hx₂ : x₂ ≫ S.g.f i = x₃) (x₁ : A ⟶ S.X₁.X j) (hx₁ : x₁ ≫ S.f.f j = x₂ ≫ S.X₂.d i j) (k : ι) (hk : c.next j = k) : S.X₃.liftCycles x₃ j (c.next_eq' hij) hx₃ ≫ S.X₃.homologyπ i ≫ hS.δ i j hij = S.X₁.liftCycles x₁ k hk (by have := hS.mono_f rw [← cancel_mono (S.f.f k), assoc, ← S.f.comm, reassoc_of% hx₁, d_comp_d, comp_zero, zero_comp]) ≫ S.X₁.homologyπ j := by simpa only [assoc] using hS.δ_eq' i j hij (S.X₃.liftCycles x₃ j (c.next_eq' hij) hx₃ ≫ S.X₃.homologyπ i) (x₂ ≫ S.X₂.pOpcycles i) (S.X₁.liftCycles x₁ k hk _) (by simp only [assoc, HomologicalComplex.p_opcyclesMap, HomologicalComplex.homology_π_ι, HomologicalComplex.liftCycles_i_assoc, reassoc_of% hx₂]) (by rw [← cancel_mono (S.X₂.iCycles j), HomologicalComplex.liftCycles_comp_cyclesMap, HomologicalComplex.liftCycles_i, assoc, assoc, opcyclesToCycles_iCycles, HomologicalComplex.p_fromOpcycles, hx₁]) end ShortExact end ShortComplex end CategoryTheory
Algebra\Homology\HomologySequenceLemmas.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomologySequence import Mathlib.Algebra.Homology.QuasiIso import Mathlib.CategoryTheory.Abelian.DiagramLemmas.Four /-! # Consequences of the homology sequence Given a morphism `φ : S₁ ⟶ S₂` between two short exact sequences of homological complexes in an abelian category, we show the naturality of the homology sequence of `S₁` and `S₂` with respect to `φ` (see `HomologicalComplex.HomologySequence.δ_naturality`). Then, we shall show in this file that if two out of the three maps `φ.τ₁`, `φ.τ₂`, `φ.τ₃` are quasi-isomorphisms, then the third is. We also obtain more specific separate lemmas which gives sufficient condition for one of these three morphisms to induce a mono/epi/iso in a given degree in terms of properties of the two others in the same or neighboring degrees. So far, we state only four lemmas for `φ.τ₃`. Eight more similar lemmas for `φ.τ₁` and `φ.τ₂` shall be also obtained (TODO). -/ open CategoryTheory ComposableArrows Abelian namespace HomologicalComplex variable {C ι : Type*} [Category C] [Abelian C] {c : ComplexShape ι} {S S₁ S₂ : ShortComplex (HomologicalComplex C c)} (φ : S₁ ⟶ S₂) (hS₁ : S₁.ShortExact) (hS₂ : S₂.ShortExact) namespace HomologySequence /-- The morphism `snakeInput hS₁ i j hij ⟶ snakeInput hS₂ i j hij` induced by a morphism `φ : S₁ ⟶ S₂` of short complexes of homological complexes, that are short exact (`hS₁ : S₁.ShortExact` and `hS₂ : S₁.ShortExact`). -/ @[simps] noncomputable def mapSnakeInput (i j : ι) (hij : c.Rel i j) : snakeInput hS₁ i j hij ⟶ snakeInput hS₂ i j hij where f₀ := (homologyFunctor C c i).mapShortComplex.map φ f₁ := (opcyclesFunctor C c i).mapShortComplex.map φ f₂ := (cyclesFunctor C c j).mapShortComplex.map φ f₃ := (homologyFunctor C c j).mapShortComplex.map φ @[reassoc] lemma δ_naturality (i j : ι) (hij : c.Rel i j) : hS₁.δ i j hij ≫ HomologicalComplex.homologyMap φ.τ₁ _ = HomologicalComplex.homologyMap φ.τ₃ _ ≫ hS₂.δ i j hij := ShortComplex.SnakeInput.naturality_δ (mapSnakeInput φ hS₁ hS₂ i j hij) variable (S) /-- The (exact) sequence `S.X₁.homology i ⟶ S.X₂.homology i ⟶ S.X₃.homology i` -/ @[simp] noncomputable def composableArrows₂ (i : ι) : ComposableArrows C 2 := mk₂ (homologyMap S.f i) (homologyMap S.g i) lemma composableArrows₂_exact (i : ι) : (composableArrows₂ S₁ i).Exact := (hS₁.homology_exact₂ i).exact_toComposableArrows /-- The (exact) sequence `H_i(S.X₁) ⟶ H_i(S.X₂) ⟶ H_i(S.X₃) ⟶ H_j(S.X₁) ⟶ H_j(S.X₂) ⟶ H_j(S.X₃)` when `c.Rel i j` and `S` is a short exact short complex of homological complexes in an abelian category. -/ @[simp] noncomputable def composableArrows₅ (i j : ι) (hij : c.Rel i j) : ComposableArrows C 5 := mk₅ (homologyMap S₁.f i) (homologyMap S₁.g i) (hS₁.δ i j hij) (homologyMap S₁.f j) (homologyMap S₁.g j) lemma composableArrows₅_exact (i j : ι) (hij : c.Rel i j) : (composableArrows₅ hS₁ i j hij).Exact := exact_of_δ₀ (hS₁.homology_exact₂ i).exact_toComposableArrows (exact_of_δ₀ (hS₁.homology_exact₃ i j hij).exact_toComposableArrows (exact_of_δ₀ (hS₁.homology_exact₁ i j hij).exact_toComposableArrows (hS₁.homology_exact₂ j).exact_toComposableArrows)) /-- The map between the exact sequences `S₁.X₁.homology i ⟶ S₁.X₂.homology i ⟶ S₁.X₃.homology i` and `S₂.X₁.homology i ⟶ S₂.X₂.homology i ⟶ S₂.X₃.homology i` that is induced by `φ : S₁ ⟶ S₂`. -/ @[simp] noncomputable def mapComposableArrows₂ (i : ι) : composableArrows₂ S₁ i ⟶ composableArrows₂ S₂ i := homMk₂ (homologyMap φ.τ₁ i) (homologyMap φ.τ₂ i) (homologyMap φ.τ₃ i) (by dsimp simp only [← homologyMap_comp, φ.comm₁₂]) (by dsimp [Precomp.map] simp only [← homologyMap_comp, φ.comm₂₃]) /-- The map `composableArrows₅ hS₁ i j hij ⟶ composableArrows₅ hS₂ i j hij` of exact sequences induced by a morphism `φ : S₁ ⟶ S₂` between short exact short complexes of homological complexes. -/ @[simp] noncomputable def mapComposableArrows₅ (i j : ι) (hij : c.Rel i j) : composableArrows₅ hS₁ i j hij ⟶ composableArrows₅ hS₂ i j hij := homMk₅ (homologyMap φ.τ₁ i) (homologyMap φ.τ₂ i) (homologyMap φ.τ₃ i) (homologyMap φ.τ₁ j) (homologyMap φ.τ₂ j) (homologyMap φ.τ₃ j) (naturality' (mapComposableArrows₂ φ i) 0 1) (naturality' (mapComposableArrows₂ φ i) 1 2) (δ_naturality φ hS₁ hS₂ i j hij) (naturality' (mapComposableArrows₂ φ j) 0 1) (naturality' (mapComposableArrows₂ φ j) 1 2) attribute [local instance] epi_comp lemma mono_homologyMap_τ₃ (i : ι) (h₁ : Epi (homologyMap φ.τ₁ i)) (h₂ : Mono (homologyMap φ.τ₂ i)) (h₃ : ∀ j, c.Rel i j → Mono (homologyMap φ.τ₁ j)) : Mono (homologyMap φ.τ₃ i) := by by_cases hi : ∃ j, c.Rel i j · obtain ⟨j, hij⟩ := hi apply mono_of_epi_of_mono_of_mono ((δlastFunctor ⋙ δlastFunctor).map (mapComposableArrows₅ φ hS₁ hS₂ i j hij)) · exact (composableArrows₅_exact hS₁ i j hij).δlast.δlast · exact (composableArrows₅_exact hS₂ i j hij).δlast.δlast · exact h₁ · exact h₂ · exact h₃ _ hij · refine mono_of_epi_of_epi_of_mono (mapComposableArrows₂ φ i) (composableArrows₂_exact hS₁ i) (composableArrows₂_exact hS₂ i) ?_ h₁ h₂ have := hS₁.epi_g apply epi_homologyMap_of_epi_of_not_rel simpa using hi lemma epi_homologyMap_τ₃ (i : ι) (h₁ : Epi (homologyMap φ.τ₂ i)) (h₂ : ∀ j, c.Rel i j → Epi (homologyMap φ.τ₁ j)) (h₃ : ∀ j, c.Rel i j → Mono (homologyMap φ.τ₂ j)) : Epi (homologyMap φ.τ₃ i) := by by_cases hi : ∃ j, c.Rel i j · obtain ⟨j, hij⟩ := hi apply epi_of_epi_of_epi_of_mono ((δ₀Functor ⋙ δlastFunctor).map (mapComposableArrows₅ φ hS₁ hS₂ i j hij)) · exact (composableArrows₅_exact hS₁ i j hij).δ₀.δlast · exact (composableArrows₅_exact hS₂ i j hij).δ₀.δlast · exact h₁ · exact h₂ j hij · exact h₃ j hij · have := hS₂.epi_g have eq := (homologyFunctor C _ i).congr_map φ.comm₂₃ dsimp at eq simp only [homologyMap_comp] at eq have := epi_homologyMap_of_epi_of_not_rel S₂.g i (by simpa using hi) exact epi_of_epi_fac eq.symm lemma isIso_homologyMap_τ₃ (i : ι) (h₁ : Epi (homologyMap φ.τ₁ i)) (h₂ : IsIso (homologyMap φ.τ₂ i)) (h₃ : ∀ j, c.Rel i j → IsIso (homologyMap φ.τ₁ j)) (h₄ : ∀ j, c.Rel i j → Mono (homologyMap φ.τ₂ j)) : IsIso (homologyMap φ.τ₃ i) := by have := mono_homologyMap_τ₃ φ hS₁ hS₂ i h₁ (IsIso.mono_of_iso _) (fun j hij => by have := h₃ j hij infer_instance) have := epi_homologyMap_τ₃ φ hS₁ hS₂ i inferInstance (fun j hij => by have := h₃ j hij infer_instance) h₄ apply isIso_of_mono_of_epi lemma quasiIso_τ₃ (h₁ : QuasiIso φ.τ₁) (h₂ : QuasiIso φ.τ₂) : QuasiIso φ.τ₃ := by rw [quasiIso_iff] intro i rw [quasiIsoAt_iff_isIso_homologyMap] apply isIso_homologyMap_τ₃ φ hS₁ hS₂ all_goals infer_instance end HomologySequence end HomologicalComplex
Algebra\Homology\Homotopy.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Homology.Linear import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex import Mathlib.Tactic.Abel /-! # Chain homotopies We define chain homotopies, and prove that homotopic chain maps induce the same map on homology. -/ universe v u noncomputable section open CategoryTheory Category Limits HomologicalComplex variable {ι : Type*} variable {V : Type u} [Category.{v} V] [Preadditive V] variable {c : ComplexShape ι} {C D E : HomologicalComplex V c} variable (f g : C ⟶ D) (h k : D ⟶ E) (i : ι) section /-- The composition of `C.d i (c.next i) ≫ f (c.next i) i`. -/ def dNext (i : ι) : (∀ i j, C.X i ⟶ D.X j) →+ (C.X i ⟶ D.X i) := AddMonoidHom.mk' (fun f => C.d i (c.next i) ≫ f (c.next i) i) fun _ _ => Preadditive.comp_add _ _ _ _ _ _ /-- `f (c.next i) i`. -/ def fromNext (i : ι) : (∀ i j, C.X i ⟶ D.X j) →+ (C.xNext i ⟶ D.X i) := AddMonoidHom.mk' (fun f => f (c.next i) i) fun _ _ => rfl @[simp] theorem dNext_eq_dFrom_fromNext (f : ∀ i j, C.X i ⟶ D.X j) (i : ι) : dNext i f = C.dFrom i ≫ fromNext i f := rfl theorem dNext_eq (f : ∀ i j, C.X i ⟶ D.X j) {i i' : ι} (w : c.Rel i i') : dNext i f = C.d i i' ≫ f i' i := by obtain rfl := c.next_eq' w rfl lemma dNext_eq_zero (f : ∀ i j, C.X i ⟶ D.X j) (i : ι) (hi : ¬ c.Rel i (c.next i)) : dNext i f = 0 := by dsimp [dNext] rw [shape _ _ _ hi, zero_comp] @[simp 1100] theorem dNext_comp_left (f : C ⟶ D) (g : ∀ i j, D.X i ⟶ E.X j) (i : ι) : (dNext i fun i j => f.f i ≫ g i j) = f.f i ≫ dNext i g := (f.comm_assoc _ _ _).symm @[simp 1100] theorem dNext_comp_right (f : ∀ i j, C.X i ⟶ D.X j) (g : D ⟶ E) (i : ι) : (dNext i fun i j => f i j ≫ g.f j) = dNext i f ≫ g.f i := (assoc _ _ _).symm /-- The composition `f j (c.prev j) ≫ D.d (c.prev j) j`. -/ def prevD (j : ι) : (∀ i j, C.X i ⟶ D.X j) →+ (C.X j ⟶ D.X j) := AddMonoidHom.mk' (fun f => f j (c.prev j) ≫ D.d (c.prev j) j) fun _ _ => Preadditive.add_comp _ _ _ _ _ _ lemma prevD_eq_zero (f : ∀ i j, C.X i ⟶ D.X j) (i : ι) (hi : ¬ c.Rel (c.prev i) i) : prevD i f = 0 := by dsimp [prevD] rw [shape _ _ _ hi, comp_zero] /-- `f j (c.prev j)`. -/ def toPrev (j : ι) : (∀ i j, C.X i ⟶ D.X j) →+ (C.X j ⟶ D.xPrev j) := AddMonoidHom.mk' (fun f => f j (c.prev j)) fun _ _ => rfl @[simp] theorem prevD_eq_toPrev_dTo (f : ∀ i j, C.X i ⟶ D.X j) (j : ι) : prevD j f = toPrev j f ≫ D.dTo j := rfl theorem prevD_eq (f : ∀ i j, C.X i ⟶ D.X j) {j j' : ι} (w : c.Rel j' j) : prevD j f = f j j' ≫ D.d j' j := by obtain rfl := c.prev_eq' w rfl @[simp 1100] theorem prevD_comp_left (f : C ⟶ D) (g : ∀ i j, D.X i ⟶ E.X j) (j : ι) : (prevD j fun i j => f.f i ≫ g i j) = f.f j ≫ prevD j g := assoc _ _ _ @[simp 1100] theorem prevD_comp_right (f : ∀ i j, C.X i ⟶ D.X j) (g : D ⟶ E) (j : ι) : (prevD j fun i j => f i j ≫ g.f j) = prevD j f ≫ g.f j := by dsimp [prevD] simp only [assoc, g.comm] theorem dNext_nat (C D : ChainComplex V ℕ) (i : ℕ) (f : ∀ i j, C.X i ⟶ D.X j) : dNext i f = C.d i (i - 1) ≫ f (i - 1) i := by dsimp [dNext] cases i · simp only [shape, ChainComplex.next_nat_zero, ComplexShape.down_Rel, Nat.one_ne_zero, not_false_iff, zero_comp] · congr <;> simp theorem prevD_nat (C D : CochainComplex V ℕ) (i : ℕ) (f : ∀ i j, C.X i ⟶ D.X j) : prevD i f = f i (i - 1) ≫ D.d (i - 1) i := by dsimp [prevD] cases i · simp only [shape, CochainComplex.prev_nat_zero, ComplexShape.up_Rel, Nat.one_ne_zero, not_false_iff, comp_zero] · congr <;> simp -- Porting note(#5171): removed @[has_nonempty_instance] /-- A homotopy `h` between chain maps `f` and `g` consists of components `h i j : C.X i ⟶ D.X j` which are zero unless `c.Rel j i`, satisfying the homotopy condition. -/ @[ext] structure Homotopy (f g : C ⟶ D) where hom : ∀ i j, C.X i ⟶ D.X j zero : ∀ i j, ¬c.Rel j i → hom i j = 0 := by aesop_cat comm : ∀ i, f.f i = dNext i hom + prevD i hom + g.f i := by aesop_cat variable {f g} namespace Homotopy /-- `f` is homotopic to `g` iff `f - g` is homotopic to `0`. -/ def equivSubZero : Homotopy f g ≃ Homotopy (f - g) 0 where toFun h := { hom := fun i j => h.hom i j zero := fun i j w => h.zero _ _ w comm := fun i => by simp [h.comm] } invFun h := { hom := fun i j => h.hom i j zero := fun i j w => h.zero _ _ w comm := fun i => by simpa [sub_eq_iff_eq_add] using h.comm i } left_inv := by aesop_cat right_inv := by aesop_cat /-- Equal chain maps are homotopic. -/ @[simps] def ofEq (h : f = g) : Homotopy f g where hom := 0 zero _ _ _ := rfl /-- Every chain map is homotopic to itself. -/ @[simps!, refl] def refl (f : C ⟶ D) : Homotopy f f := ofEq (rfl : f = f) /-- `f` is homotopic to `g` iff `g` is homotopic to `f`. -/ @[simps!, symm] def symm {f g : C ⟶ D} (h : Homotopy f g) : Homotopy g f where hom := -h.hom zero i j w := by rw [Pi.neg_apply, Pi.neg_apply, h.zero i j w, neg_zero] comm i := by rw [AddMonoidHom.map_neg, AddMonoidHom.map_neg, h.comm, ← neg_add, ← add_assoc, neg_add_self, zero_add] /-- homotopy is a transitive relation. -/ @[simps!, trans] def trans {e f g : C ⟶ D} (h : Homotopy e f) (k : Homotopy f g) : Homotopy e g where hom := h.hom + k.hom zero i j w := by rw [Pi.add_apply, Pi.add_apply, h.zero i j w, k.zero i j w, zero_add] comm i := by rw [AddMonoidHom.map_add, AddMonoidHom.map_add, h.comm, k.comm] abel /-- the sum of two homotopies is a homotopy between the sum of the respective morphisms. -/ @[simps!] def add {f₁ g₁ f₂ g₂ : C ⟶ D} (h₁ : Homotopy f₁ g₁) (h₂ : Homotopy f₂ g₂) : Homotopy (f₁ + f₂) (g₁ + g₂) where hom := h₁.hom + h₂.hom zero i j hij := by rw [Pi.add_apply, Pi.add_apply, h₁.zero i j hij, h₂.zero i j hij, add_zero] comm i := by simp only [HomologicalComplex.add_f_apply, h₁.comm, h₂.comm, AddMonoidHom.map_add] abel /-- the scalar multiplication of an homotopy -/ @[simps!] def smul {R : Type*} [Semiring R] [Linear R V] (h : Homotopy f g) (a : R) : Homotopy (a • f) (a • g) where hom i j := a • h.hom i j zero i j hij := by dsimp rw [h.zero i j hij, smul_zero] comm i := by dsimp rw [h.comm] dsimp [fromNext, toPrev] simp only [smul_add, Linear.comp_smul, Linear.smul_comp] /-- homotopy is closed under composition (on the right) -/ @[simps] def compRight {e f : C ⟶ D} (h : Homotopy e f) (g : D ⟶ E) : Homotopy (e ≫ g) (f ≫ g) where hom i j := h.hom i j ≫ g.f j zero i j w := by dsimp; rw [h.zero i j w, zero_comp] comm i := by rw [comp_f, h.comm i, dNext_comp_right, prevD_comp_right, Preadditive.add_comp, comp_f, Preadditive.add_comp] /-- homotopy is closed under composition (on the left) -/ @[simps] def compLeft {f g : D ⟶ E} (h : Homotopy f g) (e : C ⟶ D) : Homotopy (e ≫ f) (e ≫ g) where hom i j := e.f i ≫ h.hom i j zero i j w := by dsimp; rw [h.zero i j w, comp_zero] comm i := by rw [comp_f, h.comm i, dNext_comp_left, prevD_comp_left, comp_f, Preadditive.comp_add, Preadditive.comp_add] /-- homotopy is closed under composition -/ @[simps!] def comp {C₁ C₂ C₃ : HomologicalComplex V c} {f₁ g₁ : C₁ ⟶ C₂} {f₂ g₂ : C₂ ⟶ C₃} (h₁ : Homotopy f₁ g₁) (h₂ : Homotopy f₂ g₂) : Homotopy (f₁ ≫ f₂) (g₁ ≫ g₂) := (h₁.compRight _).trans (h₂.compLeft _) /-- a variant of `Homotopy.compRight` useful for dealing with homotopy equivalences. -/ @[simps!] def compRightId {f : C ⟶ C} (h : Homotopy f (𝟙 C)) (g : C ⟶ D) : Homotopy (f ≫ g) g := (h.compRight g).trans (ofEq <| id_comp _) /-- a variant of `Homotopy.compLeft` useful for dealing with homotopy equivalences. -/ @[simps!] def compLeftId {f : D ⟶ D} (h : Homotopy f (𝟙 D)) (g : C ⟶ D) : Homotopy (g ≫ f) g := (h.compLeft g).trans (ofEq <| comp_id _) /-! Null homotopic maps can be constructed using the formula `hd+dh`. We show that these morphisms are homotopic to `0` and provide some convenient simplification lemmas that give a degreewise description of `hd+dh`, depending on whether we have two differentials going to and from a certain degree, only one, or none. -/ /-- The null homotopic map associated to a family `hom` of morphisms `C_i ⟶ D_j`. This is the same datum as for the field `hom` in the structure `Homotopy`. For this definition, we do not need the field `zero` of that structure as this definition uses only the maps `C_i ⟶ C_j` when `c.Rel j i`. -/ def nullHomotopicMap (hom : ∀ i j, C.X i ⟶ D.X j) : C ⟶ D where f i := dNext i hom + prevD i hom comm' i j hij := by have eq1 : prevD i hom ≫ D.d i j = 0 := by simp only [prevD, AddMonoidHom.mk'_apply, assoc, d_comp_d, comp_zero] have eq2 : C.d i j ≫ dNext j hom = 0 := by simp only [dNext, AddMonoidHom.mk'_apply, d_comp_d_assoc, zero_comp] dsimp only rw [dNext_eq hom hij, prevD_eq hom hij, Preadditive.comp_add, Preadditive.add_comp, eq1, eq2, add_zero, zero_add, assoc] open Classical in /-- Variant of `nullHomotopicMap` where the input consists only of the relevant maps `C_i ⟶ D_j` such that `c.Rel j i`. -/ def nullHomotopicMap' (h : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) : C ⟶ D := nullHomotopicMap fun i j => dite (c.Rel j i) (h i j) fun _ => 0 /-- Compatibility of `nullHomotopicMap` with the postcomposition by a morphism of complexes. -/ theorem nullHomotopicMap_comp (hom : ∀ i j, C.X i ⟶ D.X j) (g : D ⟶ E) : nullHomotopicMap hom ≫ g = nullHomotopicMap fun i j => hom i j ≫ g.f j := by ext n dsimp [nullHomotopicMap, fromNext, toPrev, AddMonoidHom.mk'_apply] simp only [Preadditive.add_comp, assoc, g.comm] /-- Compatibility of `nullHomotopicMap'` with the postcomposition by a morphism of complexes. -/ theorem nullHomotopicMap'_comp (hom : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) (g : D ⟶ E) : nullHomotopicMap' hom ≫ g = nullHomotopicMap' fun i j hij => hom i j hij ≫ g.f j := by ext n erw [nullHomotopicMap_comp] congr ext i j split_ifs · rfl · rw [zero_comp] /-- Compatibility of `nullHomotopicMap` with the precomposition by a morphism of complexes. -/ theorem comp_nullHomotopicMap (f : C ⟶ D) (hom : ∀ i j, D.X i ⟶ E.X j) : f ≫ nullHomotopicMap hom = nullHomotopicMap fun i j => f.f i ≫ hom i j := by ext n dsimp [nullHomotopicMap, fromNext, toPrev, AddMonoidHom.mk'_apply] simp only [Preadditive.comp_add, assoc, f.comm_assoc] /-- Compatibility of `nullHomotopicMap'` with the precomposition by a morphism of complexes. -/ theorem comp_nullHomotopicMap' (f : C ⟶ D) (hom : ∀ i j, c.Rel j i → (D.X i ⟶ E.X j)) : f ≫ nullHomotopicMap' hom = nullHomotopicMap' fun i j hij => f.f i ≫ hom i j hij := by ext n erw [comp_nullHomotopicMap] congr ext i j split_ifs · rfl · rw [comp_zero] /-- Compatibility of `nullHomotopicMap` with the application of additive functors -/ theorem map_nullHomotopicMap {W : Type*} [Category W] [Preadditive W] (G : V ⥤ W) [G.Additive] (hom : ∀ i j, C.X i ⟶ D.X j) : (G.mapHomologicalComplex c).map (nullHomotopicMap hom) = nullHomotopicMap (fun i j => by exact G.map (hom i j)) := by ext i dsimp [nullHomotopicMap, dNext, prevD] simp only [G.map_comp, Functor.map_add] /-- Compatibility of `nullHomotopicMap'` with the application of additive functors -/ theorem map_nullHomotopicMap' {W : Type*} [Category W] [Preadditive W] (G : V ⥤ W) [G.Additive] (hom : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) : (G.mapHomologicalComplex c).map (nullHomotopicMap' hom) = nullHomotopicMap' fun i j hij => by exact G.map (hom i j hij) := by ext n erw [map_nullHomotopicMap] congr ext i j split_ifs · rfl · rw [G.map_zero] /-- Tautological construction of the `Homotopy` to zero for maps constructed by `nullHomotopicMap`, at least when we have the `zero` condition. -/ @[simps] def nullHomotopy (hom : ∀ i j, C.X i ⟶ D.X j) (zero : ∀ i j, ¬c.Rel j i → hom i j = 0) : Homotopy (nullHomotopicMap hom) 0 := { hom := hom zero := zero comm := by intro i rw [HomologicalComplex.zero_f_apply, add_zero] rfl } open Classical in /-- Homotopy to zero for maps constructed with `nullHomotopicMap'` -/ @[simps!] def nullHomotopy' (h : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) : Homotopy (nullHomotopicMap' h) 0 := by apply nullHomotopy fun i j => dite (c.Rel j i) (h i j) fun _ => 0 intro i j hij rw [dite_eq_right_iff] intro hij' exfalso exact hij hij' /-! This lemma and the following ones can be used in order to compute the degreewise morphisms induced by the null homotopic maps constructed with `nullHomotopicMap` or `nullHomotopicMap'` -/ @[simp] theorem nullHomotopicMap_f {k₂ k₁ k₀ : ι} (r₂₁ : c.Rel k₂ k₁) (r₁₀ : c.Rel k₁ k₀) (hom : ∀ i j, C.X i ⟶ D.X j) : (nullHomotopicMap hom).f k₁ = C.d k₁ k₀ ≫ hom k₀ k₁ + hom k₁ k₂ ≫ D.d k₂ k₁ := by dsimp only [nullHomotopicMap] rw [dNext_eq hom r₁₀, prevD_eq hom r₂₁] @[simp] theorem nullHomotopicMap'_f {k₂ k₁ k₀ : ι} (r₂₁ : c.Rel k₂ k₁) (r₁₀ : c.Rel k₁ k₀) (h : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) : (nullHomotopicMap' h).f k₁ = C.d k₁ k₀ ≫ h k₀ k₁ r₁₀ + h k₁ k₂ r₂₁ ≫ D.d k₂ k₁ := by simp only [nullHomotopicMap'] rw [nullHomotopicMap_f r₂₁ r₁₀] split_ifs rfl @[simp] theorem nullHomotopicMap_f_of_not_rel_left {k₁ k₀ : ι} (r₁₀ : c.Rel k₁ k₀) (hk₀ : ∀ l : ι, ¬c.Rel k₀ l) (hom : ∀ i j, C.X i ⟶ D.X j) : (nullHomotopicMap hom).f k₀ = hom k₀ k₁ ≫ D.d k₁ k₀ := by dsimp only [nullHomotopicMap] rw [prevD_eq hom r₁₀, dNext, AddMonoidHom.mk'_apply, C.shape, zero_comp, zero_add] exact hk₀ _ @[simp] theorem nullHomotopicMap'_f_of_not_rel_left {k₁ k₀ : ι} (r₁₀ : c.Rel k₁ k₀) (hk₀ : ∀ l : ι, ¬c.Rel k₀ l) (h : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) : (nullHomotopicMap' h).f k₀ = h k₀ k₁ r₁₀ ≫ D.d k₁ k₀ := by simp only [nullHomotopicMap'] rw [nullHomotopicMap_f_of_not_rel_left r₁₀ hk₀] split_ifs rfl @[simp] theorem nullHomotopicMap_f_of_not_rel_right {k₁ k₀ : ι} (r₁₀ : c.Rel k₁ k₀) (hk₁ : ∀ l : ι, ¬c.Rel l k₁) (hom : ∀ i j, C.X i ⟶ D.X j) : (nullHomotopicMap hom).f k₁ = C.d k₁ k₀ ≫ hom k₀ k₁ := by dsimp only [nullHomotopicMap] rw [dNext_eq hom r₁₀, prevD, AddMonoidHom.mk'_apply, D.shape, comp_zero, add_zero] exact hk₁ _ @[simp] theorem nullHomotopicMap'_f_of_not_rel_right {k₁ k₀ : ι} (r₁₀ : c.Rel k₁ k₀) (hk₁ : ∀ l : ι, ¬c.Rel l k₁) (h : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) : (nullHomotopicMap' h).f k₁ = C.d k₁ k₀ ≫ h k₀ k₁ r₁₀ := by simp only [nullHomotopicMap'] rw [nullHomotopicMap_f_of_not_rel_right r₁₀ hk₁] split_ifs rfl @[simp] theorem nullHomotopicMap_f_eq_zero {k₀ : ι} (hk₀ : ∀ l : ι, ¬c.Rel k₀ l) (hk₀' : ∀ l : ι, ¬c.Rel l k₀) (hom : ∀ i j, C.X i ⟶ D.X j) : (nullHomotopicMap hom).f k₀ = 0 := by dsimp [nullHomotopicMap, dNext, prevD] rw [C.shape, D.shape, zero_comp, comp_zero, add_zero] <;> apply_assumption @[simp] theorem nullHomotopicMap'_f_eq_zero {k₀ : ι} (hk₀ : ∀ l : ι, ¬c.Rel k₀ l) (hk₀' : ∀ l : ι, ¬c.Rel l k₀) (h : ∀ i j, c.Rel j i → (C.X i ⟶ D.X j)) : (nullHomotopicMap' h).f k₀ = 0 := by simp only [nullHomotopicMap'] apply nullHomotopicMap_f_eq_zero hk₀ hk₀' /-! `Homotopy.mkInductive` allows us to build a homotopy of chain complexes inductively, so that as we construct each component, we have available the previous two components, and the fact that they satisfy the homotopy condition. To simplify the situation, we only construct homotopies of the form `Homotopy e 0`. `Homotopy.equivSubZero` can provide the general case. Notice however, that this construction does not have particularly good definitional properties: we have to insert `eqToHom` in several places. Hopefully this is okay in most applications, where we only need to have the existence of some homotopy. -/ section MkInductive variable {P Q : ChainComplex V ℕ} @[simp 1100] theorem prevD_chainComplex (f : ∀ i j, P.X i ⟶ Q.X j) (j : ℕ) : prevD j f = f j (j + 1) ≫ Q.d _ _ := by dsimp [prevD] have : (ComplexShape.down ℕ).prev j = j + 1 := ChainComplex.prev ℕ j congr 2 @[simp 1100] theorem dNext_succ_chainComplex (f : ∀ i j, P.X i ⟶ Q.X j) (i : ℕ) : dNext (i + 1) f = P.d _ _ ≫ f i (i + 1) := by dsimp [dNext] have : (ComplexShape.down ℕ).next (i + 1) = i := ChainComplex.next_nat_succ _ congr 2 @[simp 1100] theorem dNext_zero_chainComplex (f : ∀ i j, P.X i ⟶ Q.X j) : dNext 0 f = 0 := by dsimp [dNext] rw [P.shape, zero_comp] rw [ChainComplex.next_nat_zero]; dsimp; decide variable (e : P ⟶ Q) (zero : P.X 0 ⟶ Q.X 1) (comm_zero : e.f 0 = zero ≫ Q.d 1 0) (one : P.X 1 ⟶ Q.X 2) (comm_one : e.f 1 = P.d 1 0 ≫ zero + one ≫ Q.d 2 1) (succ : ∀ (n : ℕ) (p : Σ' (f : P.X n ⟶ Q.X (n + 1)) (f' : P.X (n + 1) ⟶ Q.X (n + 2)), e.f (n + 1) = P.d (n + 1) n ≫ f + f' ≫ Q.d (n + 2) (n + 1)), Σ' f'' : P.X (n + 2) ⟶ Q.X (n + 3), e.f (n + 2) = P.d (n + 2) (n + 1) ≫ p.2.1 + f'' ≫ Q.d (n + 3) (n + 2)) /-- An auxiliary construction for `mkInductive`. Here we build by induction a family of diagrams, but don't require at the type level that these successive diagrams actually agree. They do in fact agree, and we then capture that at the type level (i.e. by constructing a homotopy) in `mkInductive`. At this stage, we don't check the homotopy condition in degree 0, because it "falls off the end", and is easier to treat using `xNext` and `xPrev`, which we do in `mkInductiveAux₂`. -/ @[simp, nolint unusedArguments] def mkInductiveAux₁ : ∀ n, Σ' (f : P.X n ⟶ Q.X (n + 1)) (f' : P.X (n + 1) ⟶ Q.X (n + 2)), e.f (n + 1) = P.d (n + 1) n ≫ f + f' ≫ Q.d (n + 2) (n + 1) | 0 => ⟨zero, one, comm_one⟩ | 1 => ⟨one, (succ 0 ⟨zero, one, comm_one⟩).1, (succ 0 ⟨zero, one, comm_one⟩).2⟩ | n + 2 => ⟨(mkInductiveAux₁ (n + 1)).2.1, (succ (n + 1) (mkInductiveAux₁ (n + 1))).1, (succ (n + 1) (mkInductiveAux₁ (n + 1))).2⟩ section /-- An auxiliary construction for `mkInductive`. -/ def mkInductiveAux₂ : ∀ n, Σ' (f : P.xNext n ⟶ Q.X n) (f' : P.X n ⟶ Q.xPrev n), e.f n = P.dFrom n ≫ f + f' ≫ Q.dTo n | 0 => ⟨0, zero ≫ (Q.xPrevIso rfl).inv, by simpa using comm_zero⟩ | n + 1 => let I := mkInductiveAux₁ e zero --comm_zero one comm_one succ n ⟨(P.xNextIso rfl).hom ≫ I.1, I.2.1 ≫ (Q.xPrevIso rfl).inv, by simpa using I.2.2⟩ -- Porting note(#11647): during the port we marked these lemmas -- with `@[eqns]` to emulate the old Lean 3 behaviour. @[simp] theorem mkInductiveAux₂_zero : mkInductiveAux₂ e zero comm_zero one comm_one succ 0 = ⟨0, zero ≫ (Q.xPrevIso rfl).inv, mkInductiveAux₂.proof_2 e zero comm_zero⟩ := rfl @[simp] theorem mkInductiveAux₂_add_one (n) : mkInductiveAux₂ e zero comm_zero one comm_one succ (n + 1) = let I := mkInductiveAux₁ e zero one comm_one succ n ⟨(P.xNextIso rfl).hom ≫ I.1, I.2.1 ≫ (Q.xPrevIso rfl).inv, mkInductiveAux₂.proof_5 e zero one comm_one succ n⟩ := rfl theorem mkInductiveAux₃ (i j : ℕ) (h : i + 1 = j) : (mkInductiveAux₂ e zero comm_zero one comm_one succ i).2.1 ≫ (Q.xPrevIso h).hom = (P.xNextIso h).inv ≫ (mkInductiveAux₂ e zero comm_zero one comm_one succ j).1 := by subst j rcases i with (_ | _ | i) <;> simp [mkInductiveAux₂] /-- A constructor for a `Homotopy e 0`, for `e` a chain map between `ℕ`-indexed chain complexes, working by induction. You need to provide the components of the homotopy in degrees 0 and 1, show that these satisfy the homotopy condition, and then give a construction of each component, and the fact that it satisfies the homotopy condition, using as an inductive hypothesis the data and homotopy condition for the previous two components. -/ def mkInductive : Homotopy e 0 where hom i j := if h : i + 1 = j then (mkInductiveAux₂ e zero comm_zero one comm_one succ i).2.1 ≫ (Q.xPrevIso h).hom else 0 zero i j w := by dsimp; rw [dif_neg]; exact w comm i := by dsimp simp only [add_zero] refine (mkInductiveAux₂ e zero comm_zero one comm_one succ i).2.2.trans ?_ congr · cases i · dsimp [fromNext, mkInductiveAux₂] · dsimp [fromNext] simp only [ChainComplex.next_nat_succ, dite_true] rw [mkInductiveAux₃ e zero comm_zero one comm_one succ] dsimp [xNextIso] rw [id_comp] · dsimp [toPrev] erw [dif_pos, comp_id] simp only [ChainComplex.prev] end end MkInductive /-! `Homotopy.mkCoinductive` allows us to build a homotopy of cochain complexes inductively, so that as we construct each component, we have available the previous two components, and the fact that they satisfy the homotopy condition. -/ section MkCoinductive variable {P Q : CochainComplex V ℕ} @[simp 1100] theorem dNext_cochainComplex (f : ∀ i j, P.X i ⟶ Q.X j) (j : ℕ) : dNext j f = P.d _ _ ≫ f (j + 1) j := by dsimp [dNext] have : (ComplexShape.up ℕ).next j = j + 1 := CochainComplex.next ℕ j congr 2 @[simp 1100] theorem prevD_succ_cochainComplex (f : ∀ i j, P.X i ⟶ Q.X j) (i : ℕ) : prevD (i + 1) f = f (i + 1) _ ≫ Q.d i (i + 1) := by dsimp [prevD] have : (ComplexShape.up ℕ).prev (i + 1) = i := CochainComplex.prev_nat_succ i congr 2 @[simp 1100] theorem prevD_zero_cochainComplex (f : ∀ i j, P.X i ⟶ Q.X j) : prevD 0 f = 0 := by dsimp [prevD] rw [Q.shape, comp_zero] rw [CochainComplex.prev_nat_zero]; dsimp; decide variable (e : P ⟶ Q) (zero : P.X 1 ⟶ Q.X 0) (comm_zero : e.f 0 = P.d 0 1 ≫ zero) (one : P.X 2 ⟶ Q.X 1) (comm_one : e.f 1 = zero ≫ Q.d 0 1 + P.d 1 2 ≫ one) (succ : ∀ (n : ℕ) (p : Σ' (f : P.X (n + 1) ⟶ Q.X n) (f' : P.X (n + 2) ⟶ Q.X (n + 1)), e.f (n + 1) = f ≫ Q.d n (n + 1) + P.d (n + 1) (n + 2) ≫ f'), Σ' f'' : P.X (n + 3) ⟶ Q.X (n + 2), e.f (n + 2) = p.2.1 ≫ Q.d (n + 1) (n + 2) + P.d (n + 2) (n + 3) ≫ f'') /-- An auxiliary construction for `mkCoinductive`. Here we build by induction a family of diagrams, but don't require at the type level that these successive diagrams actually agree. They do in fact agree, and we then capture that at the type level (i.e. by constructing a homotopy) in `mkCoinductive`. At this stage, we don't check the homotopy condition in degree 0, because it "falls off the end", and is easier to treat using `xNext` and `xPrev`, which we do in `mkInductiveAux₂`. -/ @[simp] def mkCoinductiveAux₁ : ∀ n, Σ' (f : P.X (n + 1) ⟶ Q.X n) (f' : P.X (n + 2) ⟶ Q.X (n + 1)), e.f (n + 1) = f ≫ Q.d n (n + 1) + P.d (n + 1) (n + 2) ≫ f' | 0 => ⟨zero, one, comm_one⟩ | 1 => ⟨one, (succ 0 ⟨zero, one, comm_one⟩).1, (succ 0 ⟨zero, one, comm_one⟩).2⟩ | n + 2 => ⟨(mkCoinductiveAux₁ (n + 1)).2.1, (succ (n + 1) (mkCoinductiveAux₁ (n + 1))).1, (succ (n + 1) (mkCoinductiveAux₁ (n + 1))).2⟩ section /-- An auxiliary construction for `mkInductive`. -/ def mkCoinductiveAux₂ : ∀ n, Σ' (f : P.X n ⟶ Q.xPrev n) (f' : P.xNext n ⟶ Q.X n), e.f n = f ≫ Q.dTo n + P.dFrom n ≫ f' | 0 => ⟨0, (P.xNextIso rfl).hom ≫ zero, by simpa using comm_zero⟩ | n + 1 => let I := mkCoinductiveAux₁ e zero one comm_one succ n ⟨I.1 ≫ (Q.xPrevIso rfl).inv, (P.xNextIso rfl).hom ≫ I.2.1, by simpa using I.2.2⟩ -- Porting note (#11647): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. @[simp] theorem mkCoinductiveAux₂_zero : mkCoinductiveAux₂ e zero comm_zero one comm_one succ 0 = ⟨0, (P.xNextIso rfl).hom ≫ zero, mkCoinductiveAux₂.proof_2 e zero comm_zero⟩ := rfl @[simp] theorem mkCoinductiveAux₂_add_one (n) : mkCoinductiveAux₂ e zero comm_zero one comm_one succ (n + 1) = let I := mkCoinductiveAux₁ e zero one comm_one succ n ⟨I.1 ≫ (Q.xPrevIso rfl).inv, (P.xNextIso rfl).hom ≫ I.2.1, mkCoinductiveAux₂.proof_5 e zero one comm_one succ n⟩ := rfl theorem mkCoinductiveAux₃ (i j : ℕ) (h : i + 1 = j) : (P.xNextIso h).inv ≫ (mkCoinductiveAux₂ e zero comm_zero one comm_one succ i).2.1 = (mkCoinductiveAux₂ e zero comm_zero one comm_one succ j).1 ≫ (Q.xPrevIso h).hom := by subst j rcases i with (_ | _ | i) <;> simp [mkCoinductiveAux₂] /-- A constructor for a `Homotopy e 0`, for `e` a chain map between `ℕ`-indexed cochain complexes, working by induction. You need to provide the components of the homotopy in degrees 0 and 1, show that these satisfy the homotopy condition, and then give a construction of each component, and the fact that it satisfies the homotopy condition, using as an inductive hypothesis the data and homotopy condition for the previous two components. -/ def mkCoinductive : Homotopy e 0 where hom i j := if h : j + 1 = i then (P.xNextIso h).inv ≫ (mkCoinductiveAux₂ e zero comm_zero one comm_one succ j).2.1 else 0 zero i j w := by dsimp; rw [dif_neg]; exact w comm i := by dsimp simp only [add_zero] rw [add_comm] refine (mkCoinductiveAux₂ e zero comm_zero one comm_one succ i).2.2.trans ?_ congr · cases i · dsimp [toPrev, mkCoinductiveAux₂] · dsimp [toPrev] simp only [CochainComplex.prev_nat_succ, dite_true] rw [mkCoinductiveAux₃ e zero comm_zero one comm_one succ] dsimp [xPrevIso] rw [comp_id] · dsimp [fromNext] erw [dif_pos, id_comp] simp only [CochainComplex.next] end end MkCoinductive end Homotopy /-- A homotopy equivalence between two chain complexes consists of a chain map each way, and homotopies from the compositions to the identity chain maps. Note that this contains data; arguably it might be more useful for many applications if we truncated it to a Prop. -/ structure HomotopyEquiv (C D : HomologicalComplex V c) where hom : C ⟶ D inv : D ⟶ C homotopyHomInvId : Homotopy (hom ≫ inv) (𝟙 C) homotopyInvHomId : Homotopy (inv ≫ hom) (𝟙 D) variable (V c) in /-- The morphism property on `HomologicalComplex V c` given by homotopy equivalences. -/ def HomologicalComplex.homotopyEquivalences : MorphismProperty (HomologicalComplex V c) := fun X Y f => ∃ (e : HomotopyEquiv X Y), e.hom = f namespace HomotopyEquiv /-- Any complex is homotopy equivalent to itself. -/ @[refl] def refl (C : HomologicalComplex V c) : HomotopyEquiv C C where hom := 𝟙 C inv := 𝟙 C homotopyHomInvId := Homotopy.ofEq (by simp) homotopyInvHomId := Homotopy.ofEq (by simp) instance : Inhabited (HomotopyEquiv C C) := ⟨refl C⟩ /-- Being homotopy equivalent is a symmetric relation. -/ @[symm] def symm {C D : HomologicalComplex V c} (f : HomotopyEquiv C D) : HomotopyEquiv D C where hom := f.inv inv := f.hom homotopyHomInvId := f.homotopyInvHomId homotopyInvHomId := f.homotopyHomInvId /-- Homotopy equivalence is a transitive relation. -/ @[trans] def trans {C D E : HomologicalComplex V c} (f : HomotopyEquiv C D) (g : HomotopyEquiv D E) : HomotopyEquiv C E where hom := f.hom ≫ g.hom inv := g.inv ≫ f.inv homotopyHomInvId := by simpa using ((g.homotopyHomInvId.compRightId f.inv).compLeft f.hom).trans f.homotopyHomInvId homotopyInvHomId := by simpa using ((f.homotopyInvHomId.compRightId g.hom).compLeft g.inv).trans g.homotopyInvHomId /-- An isomorphism of complexes induces a homotopy equivalence. -/ def ofIso {ι : Type*} {V : Type u} [Category.{v} V] [Preadditive V] {c : ComplexShape ι} {C D : HomologicalComplex V c} (f : C ≅ D) : HomotopyEquiv C D := ⟨f.hom, f.inv, Homotopy.ofEq f.3, Homotopy.ofEq f.4⟩ end HomotopyEquiv end namespace CategoryTheory variable {W : Type*} [Category W] [Preadditive W] /-- An additive functor takes homotopies to homotopies. -/ @[simps] def Functor.mapHomotopy (F : V ⥤ W) [F.Additive] {f g : C ⟶ D} (h : Homotopy f g) : Homotopy ((F.mapHomologicalComplex c).map f) ((F.mapHomologicalComplex c).map g) where hom i j := F.map (h.hom i j) zero i j w := by dsimp; rw [h.zero i j w, F.map_zero] comm i := by have H := h.comm i dsimp [dNext, prevD] at H ⊢ simp [H] /-- An additive functor preserves homotopy equivalences. -/ @[simps] def Functor.mapHomotopyEquiv (F : V ⥤ W) [F.Additive] (h : HomotopyEquiv C D) : HomotopyEquiv ((F.mapHomologicalComplex c).obj C) ((F.mapHomologicalComplex c).obj D) where hom := (F.mapHomologicalComplex c).map h.hom inv := (F.mapHomologicalComplex c).map h.inv homotopyHomInvId := by rw [← (F.mapHomologicalComplex c).map_comp, ← (F.mapHomologicalComplex c).map_id] exact F.mapHomotopy h.homotopyHomInvId homotopyInvHomId := by rw [← (F.mapHomologicalComplex c).map_comp, ← (F.mapHomologicalComplex c).map_id] exact F.mapHomotopy h.homotopyInvHomId end CategoryTheory section open HomologicalComplex CategoryTheory variable {C : Type*} [Category C] [Preadditive C] {ι : Type _} {c : ComplexShape ι} [DecidableRel c.Rel] {K L : HomologicalComplex C c} {f g : K ⟶ L} /-- A homotopy between morphisms of homological complexes `K ⟶ L` induces a homotopy between morphisms of short complexes `K.sc i ⟶ L.sc i`. -/ noncomputable def Homotopy.toShortComplex (ho : Homotopy f g) (i : ι) : ShortComplex.Homotopy ((shortComplexFunctor C c i).map f) ((shortComplexFunctor C c i).map g) where h₀ := if c.Rel (c.prev i) i then ho.hom _ (c.prev (c.prev i)) ≫ L.d _ _ else f.f _ - g.f _ - K.d _ i ≫ ho.hom i _ h₁ := ho.hom _ _ h₂ := ho.hom _ _ h₃ := if c.Rel i (c.next i) then K.d _ _ ≫ ho.hom (c.next (c.next i)) _ else f.f _ - g.f _ - ho.hom _ i ≫ L.d _ _ h₀_f := by split_ifs with h · dsimp simp only [assoc, d_comp_d, comp_zero] · dsimp rw [L.shape _ _ h, comp_zero] g_h₃ := by split_ifs with h · dsimp simp · dsimp rw [K.shape _ _ h, zero_comp] comm₁ := by dsimp split_ifs with h · rw [ho.comm (c.prev i)] dsimp [dFrom, dTo, fromNext, toPrev] rw [congr_arg (fun j => d K (c.prev i) j ≫ ho.hom j (c.prev i)) (c.next_eq' h)] · abel comm₂ := ho.comm i comm₃ := by dsimp split_ifs with h · rw [ho.comm (c.next i)] dsimp [dFrom, dTo, fromNext, toPrev] rw [congr_arg (fun j => ho.hom (c.next i) j ≫ L.d j (c.next i)) (c.prev_eq' h)] · abel lemma Homotopy.homologyMap_eq (ho : Homotopy f g) (i : ι) [K.HasHomology i] [L.HasHomology i] : homologyMap f i = homologyMap g i := ShortComplex.Homotopy.homologyMap_congr (ho.toShortComplex i) /-- The isomorphism in homology induced by an homotopy equivalence. -/ noncomputable def HomotopyEquiv.toHomologyIso (h : HomotopyEquiv K L) (i : ι) [K.HasHomology i] [L.HasHomology i] : K.homology i ≅ L.homology i where hom := homologyMap h.hom i inv := homologyMap h.inv i hom_inv_id := by rw [← homologyMap_comp, h.homotopyHomInvId.homologyMap_eq, homologyMap_id] inv_hom_id := by rw [← homologyMap_comp, h.homotopyInvHomId.homologyMap_eq, homologyMap_id] end
Algebra\Homology\HomotopyCategory.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Homology.Homotopy import Mathlib.Algebra.Homology.Linear import Mathlib.CategoryTheory.MorphismProperty.IsInvertedBy import Mathlib.CategoryTheory.Quotient.Linear import Mathlib.CategoryTheory.Quotient.Preadditive /-! # The homotopy category `HomotopyCategory V c` gives the category of chain complexes of shape `c` in `V`, with chain maps identified when they are homotopic. -/ universe v u noncomputable section open CategoryTheory CategoryTheory.Limits HomologicalComplex variable {R : Type*} [Semiring R] {ι : Type*} (V : Type u) [Category.{v} V] [Preadditive V] (c : ComplexShape ι) /-- The congruence on `HomologicalComplex V c` given by the existence of a homotopy. -/ def homotopic : HomRel (HomologicalComplex V c) := fun _ _ f g => Nonempty (Homotopy f g) instance homotopy_congruence : Congruence (homotopic V c) where equivalence := { refl := fun C => ⟨Homotopy.refl C⟩ symm := fun ⟨w⟩ => ⟨w.symm⟩ trans := fun ⟨w₁⟩ ⟨w₂⟩ => ⟨w₁.trans w₂⟩ } compLeft := fun _ _ _ ⟨i⟩ => ⟨i.compLeft _⟩ compRight := fun _ ⟨i⟩ => ⟨i.compRight _⟩ /-- `HomotopyCategory V c` is the category of chain complexes of shape `c` in `V`, with chain maps identified when they are homotopic. -/ def HomotopyCategory := CategoryTheory.Quotient (homotopic V c) instance : Category (HomotopyCategory V c) := by dsimp only [HomotopyCategory] infer_instance -- TODO the homotopy_category is preadditive namespace HomotopyCategory instance : Preadditive (HomotopyCategory V c) := Quotient.preadditive _ (by rintro _ _ _ _ _ _ ⟨h⟩ ⟨h'⟩ exact ⟨Homotopy.add h h'⟩) /-- The quotient functor from complexes to the homotopy category. -/ def quotient : HomologicalComplex V c ⥤ HomotopyCategory V c := CategoryTheory.Quotient.functor _ instance : (quotient V c).Full := Quotient.full_functor _ instance : (quotient V c).EssSurj := Quotient.essSurj_functor _ instance : (quotient V c).Additive where instance : Preadditive (CategoryTheory.Quotient (homotopic V c)) := (inferInstance : Preadditive (HomotopyCategory V c)) instance : Functor.Additive (Quotient.functor (homotopic V c)) where instance [Linear R V] : Linear R (HomotopyCategory V c) := Quotient.linear R (homotopic V c) (fun _ _ _ _ _ h => ⟨h.some.smul _⟩) instance [Linear R V] : Functor.Linear R (HomotopyCategory.quotient V c) := Quotient.linear_functor _ _ _ open ZeroObject instance [HasZeroObject V] : Inhabited (HomotopyCategory V c) := ⟨(quotient V c).obj 0⟩ instance [HasZeroObject V] : HasZeroObject (HomotopyCategory V c) := ⟨(quotient V c).obj 0, by rw [IsZero.iff_id_eq_zero, ← (quotient V c).map_id, id_zero, Functor.map_zero]⟩ instance {D : Type*} [Category D] : ((whiskeringLeft _ _ D).obj (quotient V c)).Full := Quotient.full_whiskeringLeft_functor _ _ instance {D : Type*} [Category D] : ((whiskeringLeft _ _ D).obj (quotient V c)).Faithful := Quotient.faithful_whiskeringLeft_functor _ _ variable {V c} -- Porting note: removed @[simp] attribute because it hinders the automatic application of the -- more useful `quotient_map_out` theorem quotient_obj_as (C : HomologicalComplex V c) : ((quotient V c).obj C).as = C := rfl @[simp] theorem quotient_map_out {C D : HomotopyCategory V c} (f : C ⟶ D) : (quotient V c).map f.out = f := Quot.out_eq _ -- Porting note: added to ease the port theorem quot_mk_eq_quotient_map {C D : HomologicalComplex V c} (f : C ⟶ D) : Quot.mk _ f = (quotient V c).map f := rfl theorem eq_of_homotopy {C D : HomologicalComplex V c} (f g : C ⟶ D) (h : Homotopy f g) : (quotient V c).map f = (quotient V c).map g := CategoryTheory.Quotient.sound _ ⟨h⟩ /-- If two chain maps become equal in the homotopy category, then they are homotopic. -/ def homotopyOfEq {C D : HomologicalComplex V c} (f g : C ⟶ D) (w : (quotient V c).map f = (quotient V c).map g) : Homotopy f g := ((Quotient.functor_map_eq_iff _ _ _).mp w).some /-- An arbitrarily chosen representation of the image of a chain map in the homotopy category is homotopic to the original chain map. -/ def homotopyOutMap {C D : HomologicalComplex V c} (f : C ⟶ D) : Homotopy ((quotient V c).map f).out f := by apply homotopyOfEq simp @[simp 1100] theorem quotient_map_out_comp_out {C D E : HomotopyCategory V c} (f : C ⟶ D) (g : D ⟶ E) : (quotient V c).map (Quot.out f ≫ Quot.out g) = f ≫ g := by simp /-- Homotopy equivalent complexes become isomorphic in the homotopy category. -/ @[simps] def isoOfHomotopyEquiv {C D : HomologicalComplex V c} (f : HomotopyEquiv C D) : (quotient V c).obj C ≅ (quotient V c).obj D where hom := (quotient V c).map f.hom inv := (quotient V c).map f.inv hom_inv_id := by rw [← (quotient V c).map_comp, ← (quotient V c).map_id] exact eq_of_homotopy _ _ f.homotopyHomInvId inv_hom_id := by rw [← (quotient V c).map_comp, ← (quotient V c).map_id] exact eq_of_homotopy _ _ f.homotopyInvHomId /-- If two complexes become isomorphic in the homotopy category, then they were homotopy equivalent. -/ def homotopyEquivOfIso {C D : HomologicalComplex V c} (i : (quotient V c).obj C ≅ (quotient V c).obj D) : HomotopyEquiv C D where hom := Quot.out i.hom inv := Quot.out i.inv homotopyHomInvId := homotopyOfEq _ _ (by rw [quotient_map_out_comp_out, i.hom_inv_id, (quotient V c).map_id]) homotopyInvHomId := homotopyOfEq _ _ (by rw [quotient_map_out_comp_out, i.inv_hom_id, (quotient V c).map_id]) variable (V c) in lemma quotient_inverts_homotopyEquivalences : (HomologicalComplex.homotopyEquivalences V c).IsInvertedBy (quotient V c) := by rintro K L _ ⟨e, rfl⟩ change IsIso (isoOfHomotopyEquiv e).hom infer_instance lemma isZero_quotient_obj_iff (C : HomologicalComplex V c) : IsZero ((quotient _ _).obj C) ↔ Nonempty (Homotopy (𝟙 C) 0) := by rw [IsZero.iff_id_eq_zero] constructor · intro h exact ⟨(homotopyOfEq _ _ (by simp [h]))⟩ · rintro ⟨h⟩ simpa using (eq_of_homotopy _ _ h) variable (V c) section variable [CategoryWithHomology V] open Classical in /-- The `i`-th homology, as a functor from the homotopy category. -/ noncomputable def homologyFunctor (i : ι) : HomotopyCategory V c ⥤ V := CategoryTheory.Quotient.lift _ (HomologicalComplex.homologyFunctor V c i) (by rintro K L f g ⟨h⟩ exact h.homologyMap_eq i) /-- The homology functor on the homotopy category is induced by the homology functor on homological complexes. -/ noncomputable def homologyFunctorFactors (i : ι) : quotient V c ⋙ homologyFunctor V c i ≅ HomologicalComplex.homologyFunctor V c i := Quotient.lift.isLift _ _ _ -- this is to prevent any abuse of defeq attribute [irreducible] homologyFunctor homologyFunctorFactors instance (i : ι) : (homologyFunctor V c i).Additive := by have := Functor.additive_of_iso (homologyFunctorFactors V c i).symm exact Functor.additive_of_full_essSurj_comp (quotient V c) _ end end HomotopyCategory namespace CategoryTheory variable {V} {W : Type*} [Category W] [Preadditive W] -- Porting note: given a simpler definition of this functor /-- An additive functor induces a functor between homotopy categories. -/ @[simps! obj] def Functor.mapHomotopyCategory (F : V ⥤ W) [F.Additive] (c : ComplexShape ι) : HomotopyCategory V c ⥤ HomotopyCategory W c := CategoryTheory.Quotient.lift _ (F.mapHomologicalComplex c ⋙ HomotopyCategory.quotient W c) (fun _ _ _ _ ⟨h⟩ => HomotopyCategory.eq_of_homotopy _ _ (F.mapHomotopy h)) @[simp] lemma Functor.mapHomotopyCategory_map (F : V ⥤ W) [F.Additive] {c : ComplexShape ι} {K L : HomologicalComplex V c} (f : K ⟶ L) : (F.mapHomotopyCategory c).map ((HomotopyCategory.quotient V c).map f) = (HomotopyCategory.quotient W c).map ((F.mapHomologicalComplex c).map f) := rfl /-- The obvious isomorphism between `HomotopyCategory.quotient V c ⋙ F.mapHomotopyCategory c` and `F.mapHomologicalComplex c ⋙ HomotopyCategory.quotient W c` when `F : V ⥤ W` is an additive functor. -/ def Functor.mapHomotopyCategoryFactors (F : V ⥤ W) [F.Additive] (c : ComplexShape ι) : HomotopyCategory.quotient V c ⋙ F.mapHomotopyCategory c ≅ F.mapHomologicalComplex c ⋙ HomotopyCategory.quotient W c := CategoryTheory.Quotient.lift.isLift _ _ _ -- TODO `F.mapHomotopyCategory c` is additive (and linear when `F` is linear). -- TODO develop lifting of natural transformations for general quotient categories so that -- `NatTrans.mapHomotopyCategory` become a particular case of it /-- A natural transformation induces a natural transformation between the induced functors on the homotopy category. -/ @[simps] def NatTrans.mapHomotopyCategory {F G : V ⥤ W} [F.Additive] [G.Additive] (α : F ⟶ G) (c : ComplexShape ι) : F.mapHomotopyCategory c ⟶ G.mapHomotopyCategory c where app C := (HomotopyCategory.quotient W c).map ((NatTrans.mapHomologicalComplex α c).app C.as) naturality := by rintro ⟨C⟩ ⟨D⟩ ⟨f : C ⟶ D⟩ simp only [HomotopyCategory.quot_mk_eq_quotient_map, Functor.mapHomotopyCategory_map, ← Functor.map_comp, NatTrans.naturality] @[simp] theorem NatTrans.mapHomotopyCategory_id (c : ComplexShape ι) (F : V ⥤ W) [F.Additive] : NatTrans.mapHomotopyCategory (𝟙 F) c = 𝟙 (F.mapHomotopyCategory c) := by aesop_cat @[simp] theorem NatTrans.mapHomotopyCategory_comp (c : ComplexShape ι) {F G H : V ⥤ W} [F.Additive] [G.Additive] [H.Additive] (α : F ⟶ G) (β : G ⟶ H) : NatTrans.mapHomotopyCategory (α ≫ β) c = NatTrans.mapHomotopyCategory α c ≫ NatTrans.mapHomotopyCategory β c := by aesop_cat end CategoryTheory
Algebra\Homology\HomotopyCofiber.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomologicalComplexBiprod import Mathlib.Algebra.Homology.Homotopy import Mathlib.CategoryTheory.MorphismProperty.IsInvertedBy /-! The homotopy cofiber of a morphism of homological complexes In this file, we construct the homotopy cofiber of a morphism `φ : F ⟶ G` between homological complexes in `HomologicalComplex C c`. In degree `i`, it is isomorphic to `(F.X j) ⊞ (G.X i)` if there is a `j` such that `c.Rel i j`, and `G.X i` otherwise. (This is also known as the mapping cone of `φ`. Under the name `CochainComplex.mappingCone`, a specific API shall be developed for the case of cochain complexes indexed by `ℤ`.) When we assume `hc : ∀ j, ∃ i, c.Rel i j` (which holds in the case of chain complexes, or cochain complexes indexed by `ℤ`), then for any homological complex `K`, there is a bijection `HomologicalComplex.homotopyCofiber.descEquiv φ K hc` between `homotopyCofiber φ ⟶ K` and the tuples `(α, hα)` with `α : G ⟶ K` and `hα : Homotopy (φ ≫ α) 0`. We shall also study the cylinder of a homological complex `K`: this is the homotopy cofiber of the morphism `biprod.lift (𝟙 K) (-𝟙 K) : K ⟶ K ⊞ K`. Then, a morphism `K.cylinder ⟶ M` is determined by the data of two morphisms `φ₀ φ₁ : K ⟶ M` and a homotopy `h : Homotopy φ₀ φ₁`, see `cylinder.desc`. There is also a homotopy equivalence `cylinder.homotopyEquiv K : HomotopyEquiv K.cylinder K`. From the construction of the cylinder, we deduce the lemma `Homotopy.map_eq_of_inverts_homotopyEquivalences` which assert that if a functor inverts homotopy equivalences, then the image of two homotopic maps are equal. -/ open CategoryTheory Category Limits Preadditive variable {C : Type*} [Category C] [Preadditive C] namespace HomologicalComplex variable {ι : Type*} {c : ComplexShape ι} {F G K : HomologicalComplex C c} (φ : F ⟶ G) /-- A morphism of homological complexes `φ : F ⟶ G` has a homotopy cofiber if for all indices `i` and `j` such that `c.Rel i j`, the binary biproduct `F.X j ⊞ G.X i` exists. -/ class HasHomotopyCofiber (φ : F ⟶ G) : Prop where hasBinaryBiproduct (i j : ι) (hij : c.Rel i j) : HasBinaryBiproduct (F.X j) (G.X i) instance [HasBinaryBiproducts C] : HasHomotopyCofiber φ where hasBinaryBiproduct _ _ _ := inferInstance variable [HasHomotopyCofiber φ] [DecidableRel c.Rel] namespace homotopyCofiber /-- The `X` field of the homological complex `homotopyCofiber φ`. -/ noncomputable def X (i : ι) : C := if hi : c.Rel i (c.next i) then haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hi (F.X (c.next i)) ⊞ (G.X i) else G.X i /-- The canonical isomorphism `(homotopyCofiber φ).X i ≅ F.X j ⊞ G.X i` when `c.Rel i j`. -/ noncomputable def XIsoBiprod (i j : ι) (hij : c.Rel i j) [HasBinaryBiproduct (F.X j) (G.X i)] : X φ i ≅ F.X j ⊞ G.X i := eqToIso (by obtain rfl := c.next_eq' hij apply dif_pos hij) /-- The canonical isomorphism `(homotopyCofiber φ).X i ≅ G.X i` when `¬ c.Rel i (c.next i)`. -/ noncomputable def XIso (i : ι) (hi : ¬ c.Rel i (c.next i)) : X φ i ≅ G.X i := eqToIso (dif_neg hi) /-- The second projection `(homotopyCofiber φ).X i ⟶ G.X i`. -/ noncomputable def sndX (i : ι) : X φ i ⟶ G.X i := if hi : c.Rel i (c.next i) then haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hi (XIsoBiprod φ _ _ hi).hom ≫ biprod.snd else (XIso φ i hi).hom /-- The right inclusion `G.X i ⟶ (homotopyCofiber φ).X i`. -/ noncomputable def inrX (i : ι) : G.X i ⟶ X φ i := if hi : c.Rel i (c.next i) then haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hi biprod.inr ≫ (XIsoBiprod φ _ _ hi).inv else (XIso φ i hi).inv @[reassoc (attr := simp)] lemma inrX_sndX (i : ι) : inrX φ i ≫ sndX φ i = 𝟙 _ := by dsimp [sndX, inrX] split_ifs with hi <;> simp @[reassoc] lemma sndX_inrX (i : ι) (hi : ¬ c.Rel i (c.next i)) : sndX φ i ≫ inrX φ i = 𝟙 _ := by dsimp [sndX, inrX] simp only [dif_neg hi, Iso.hom_inv_id] /-- The first projection `(homotopyCofiber φ).X i ⟶ F.X j` when `c.Rel i j`. -/ noncomputable def fstX (i j : ι) (hij : c.Rel i j) : X φ i ⟶ F.X j := haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hij (XIsoBiprod φ i j hij).hom ≫ biprod.fst /-- The left inclusion `F.X i ⟶ (homotopyCofiber φ).X j` when `c.Rel j i`. -/ noncomputable def inlX (i j : ι) (hij : c.Rel j i) : F.X i ⟶ X φ j := haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hij biprod.inl ≫ (XIsoBiprod φ j i hij).inv @[reassoc (attr := simp)] lemma inlX_fstX (i j : ι ) (hij : c.Rel j i) : inlX φ i j hij ≫ fstX φ j i hij = 𝟙 _ := by simp [inlX, fstX] @[reassoc (attr := simp)] lemma inlX_sndX (i j : ι) (hij : c.Rel j i) : inlX φ i j hij ≫ sndX φ j = 0 := by obtain rfl := c.next_eq' hij simp [inlX, sndX, dif_pos hij] @[reassoc (attr := simp)] lemma inrX_fstX (i j : ι) (hij : c.Rel i j) : inrX φ i ≫ fstX φ i j hij = 0 := by obtain rfl := c.next_eq' hij simp [inrX, fstX, dif_pos hij] /-- The `d` field of the homological complex `homotopyCofiber φ`. -/ noncomputable def d (i j : ι) : X φ i ⟶ X φ j := if hij : c.Rel i j then (if hj : c.Rel j (c.next j) then -fstX φ i j hij ≫ F.d _ _ ≫ inlX φ _ _ hj else 0) + fstX φ i j hij ≫ φ.f j ≫ inrX φ j + sndX φ i ≫ G.d i j ≫ inrX φ j else 0 lemma ext_to_X (i j : ι) (hij : c.Rel i j) {A : C} {f g : A ⟶ X φ i} (h₁ : f ≫ fstX φ i j hij = g ≫ fstX φ i j hij) (h₂ : f ≫ sndX φ i = g ≫ sndX φ i) : f = g := by haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hij rw [← cancel_mono (XIsoBiprod φ i j hij).hom] apply biprod.hom_ext · simpa using h₁ · obtain rfl := c.next_eq' hij simpa [sndX, dif_pos hij] using h₂ lemma ext_to_X' (i : ι) (hi : ¬ c.Rel i (c.next i)) {A : C} {f g : A ⟶ X φ i} (h : f ≫ sndX φ i = g ≫ sndX φ i) : f = g := by rw [← cancel_mono (XIso φ i hi).hom] simpa only [sndX, dif_neg hi] using h lemma ext_from_X (i j : ι) (hij : c.Rel j i) {A : C} {f g : X φ j ⟶ A} (h₁ : inlX φ i j hij ≫ f = inlX φ i j hij ≫ g) (h₂ : inrX φ j ≫ f = inrX φ j ≫ g) : f = g := by haveI := HasHomotopyCofiber.hasBinaryBiproduct φ _ _ hij rw [← cancel_epi (XIsoBiprod φ j i hij).inv] apply biprod.hom_ext' · simpa [inlX] using h₁ · obtain rfl := c.next_eq' hij simpa [inrX, dif_pos hij] using h₂ lemma ext_from_X' (i : ι) (hi : ¬ c.Rel i (c.next i)) {A : C} {f g : X φ i ⟶ A} (h : inrX φ i ≫ f = inrX φ i ≫ g) : f = g := by rw [← cancel_epi (XIso φ i hi).inv] simpa only [inrX, dif_neg hi] using h @[reassoc] lemma d_fstX (i j k : ι) (hij : c.Rel i j) (hjk : c.Rel j k) : d φ i j ≫ fstX φ j k hjk = -fstX φ i j hij ≫ F.d j k := by obtain rfl := c.next_eq' hjk simp [d, dif_pos hij, dif_pos hjk] @[reassoc] lemma d_sndX (i j : ι) (hij : c.Rel i j) : d φ i j ≫ sndX φ j = fstX φ i j hij ≫ φ.f j + sndX φ i ≫ G.d i j := by dsimp [d] split_ifs with hij <;> simp @[reassoc] lemma inlX_d (i j k : ι) (hij : c.Rel i j) (hjk : c.Rel j k) : inlX φ j i hij ≫ d φ i j = -F.d j k ≫ inlX φ k j hjk + φ.f j ≫ inrX φ j := by apply ext_to_X φ j k hjk · dsimp simp [d_fstX φ _ _ _ hij hjk] · simp [d_sndX φ _ _ hij] @[reassoc] lemma inlX_d' (i j : ι) (hij : c.Rel i j) (hj : ¬ c.Rel j (c.next j)) : inlX φ j i hij ≫ d φ i j = φ.f j ≫ inrX φ j := by apply ext_to_X' _ _ hj simp [d_sndX φ i j hij] lemma shape (i j : ι) (hij : ¬ c.Rel i j) : d φ i j = 0 := dif_neg hij @[reassoc (attr := simp)] lemma inrX_d (i j : ι) : inrX φ i ≫ d φ i j = G.d i j ≫ inrX φ j := by by_cases hij : c.Rel i j · by_cases hj : c.Rel j (c.next j) · apply ext_to_X _ _ _ hj · simp [d_fstX φ _ _ _ hij] · simp [d_sndX φ _ _ hij] · apply ext_to_X' _ _ hj simp [d_sndX φ _ _ hij] · rw [shape φ _ _ hij, G.shape _ _ hij, zero_comp, comp_zero] end homotopyCofiber /-- The homotopy cofiber of a morphism of homological complexes, also known as the mapping cone. -/ @[simps] noncomputable def homotopyCofiber : HomologicalComplex C c where X i := homotopyCofiber.X φ i d i j := homotopyCofiber.d φ i j shape i j hij := homotopyCofiber.shape φ i j hij d_comp_d' i j k hij hjk := by apply homotopyCofiber.ext_from_X φ j i hij · dsimp simp only [comp_zero, homotopyCofiber.inlX_d_assoc φ i j k hij hjk, add_comp, assoc, homotopyCofiber.inrX_d, Hom.comm_assoc, neg_comp] by_cases hk : c.Rel k (c.next k) · simp [homotopyCofiber.inlX_d φ j k _ hjk hk] · simp [homotopyCofiber.inlX_d' φ j k hjk hk] · simp namespace homotopyCofiber /-- The right inclusion `G ⟶ homotopyCofiber φ`. -/ @[simps!] noncomputable def inr : G ⟶ homotopyCofiber φ where f i := inrX φ i section variable (hc : ∀ j, ∃ i, c.Rel i j) /-- The composition `φ ≫ mappingCone.inr φ` is homotopic to `0`. -/ noncomputable def inrCompHomotopy : Homotopy (φ ≫ inr φ) 0 where hom i j := if hij : c.Rel j i then inlX φ i j hij else 0 zero i j hij := dif_neg hij comm j := by obtain ⟨i, hij⟩ := hc j rw [prevD_eq _ hij, dif_pos hij] by_cases hj : c.Rel j (c.next j) · simp only [comp_f, homotopyCofiber_d, zero_f, add_zero, inlX_d φ i j _ hij hj, dNext_eq _ hj, dif_pos hj, add_neg_cancel_left, inr_f] · rw [dNext_eq_zero _ _ hj, zero_add, zero_f, add_zero, homotopyCofiber_d, inlX_d' _ _ _ _ hj, comp_f, inr_f] lemma inrCompHomotopy_hom (i j : ι) (hij : c.Rel j i) : (inrCompHomotopy φ hc).hom i j = inlX φ i j hij := dif_pos hij lemma inrCompHomotopy_hom_eq_zero (i j : ι) (hij : ¬ c.Rel j i) : (inrCompHomotopy φ hc).hom i j = 0 := dif_neg hij end section variable (α : G ⟶ K) (hα : Homotopy (φ ≫ α) 0) /-- The morphism `homotopyCofiber φ ⟶ K` that is induced by a morphism `α : G ⟶ K` and a homotopy `hα : Homotopy (φ ≫ α) 0`. -/ noncomputable def desc : homotopyCofiber φ ⟶ K where f j := if hj : c.Rel j (c.next j) then fstX φ j _ hj ≫ hα.hom _ j + sndX φ j ≫ α.f j else sndX φ j ≫ α.f j comm' j k hjk := by obtain rfl := c.next_eq' hjk dsimp simp [dif_pos hjk] have H := hα.comm (c.next j) simp only [comp_f, zero_f, add_zero, prevD_eq _ hjk] at H split_ifs with hj · simp only [comp_add, d_sndX_assoc _ _ _ hjk, add_comp, assoc, H, d_fstX_assoc _ _ _ _ hjk, neg_comp, dNext, AddMonoidHom.mk'_apply] abel · simp only [d_sndX_assoc _ _ _ hjk, add_comp, assoc, add_left_inj, H, dNext_eq_zero _ _ hj, zero_add] lemma desc_f (j k : ι) (hjk : c.Rel j k) : (desc φ α hα).f j = fstX φ j _ hjk ≫ hα.hom _ j + sndX φ j ≫ α.f j := by obtain rfl := c.next_eq' hjk apply dif_pos hjk lemma desc_f' (j : ι) (hj : ¬ c.Rel j (c.next j)) : (desc φ α hα).f j = sndX φ j ≫ α.f j := by apply dif_neg hj @[reassoc (attr := simp)] lemma inlX_desc_f (i j : ι) (hjk : c.Rel j i) : inlX φ i j hjk ≫ (desc φ α hα).f j = hα.hom i j := by obtain rfl := c.next_eq' hjk dsimp [desc] rw [dif_pos hjk, comp_add, inlX_fstX_assoc, inlX_sndX_assoc, zero_comp, add_zero] @[reassoc (attr := simp)] lemma inrX_desc_f (i : ι) : inrX φ i ≫ (desc φ α hα).f i = α.f i := by dsimp [desc] split_ifs <;> simp @[reassoc (attr := simp)] lemma inr_desc : inr φ ≫ desc φ α hα = α := by aesop_cat @[reassoc (attr := simp)] lemma inrCompHomotopy_hom_desc_hom (hc : ∀ j, ∃ i, c.Rel i j) (i j : ι) : (inrCompHomotopy φ hc).hom i j ≫ (desc φ α hα).f j = hα.hom i j := by by_cases hij : c.Rel j i · dsimp simp only [inrCompHomotopy_hom φ hc i j hij, desc_f φ α hα _ _ hij, comp_add, inlX_fstX_assoc, inlX_sndX_assoc, zero_comp, add_zero] · simp only [Homotopy.zero _ _ _ hij, zero_comp] lemma eq_desc (f : homotopyCofiber φ ⟶ K) (hc : ∀ j, ∃ i, c.Rel i j) : f = desc φ (inr φ ≫ f) (Homotopy.trans (Homotopy.ofEq (by simp)) (((inrCompHomotopy φ hc).compRight f).trans (Homotopy.ofEq (by simp)))) := by ext j by_cases hj : c.Rel j (c.next j) · apply ext_from_X φ _ _ hj · simp [inrCompHomotopy_hom _ _ _ _ hj] · simp · apply ext_from_X' φ _ hj simp end lemma descSigma_ext_iff {φ : F ⟶ G} {K : HomologicalComplex C c} (x y : Σ (α : G ⟶ K), Homotopy (φ ≫ α) 0) : x = y ↔ x.1 = y.1 ∧ (∀ (i j : ι) (_ : c.Rel j i), x.2.hom i j = y.2.hom i j) := by constructor · rintro rfl tauto · obtain ⟨x₁, x₂⟩ := x obtain ⟨y₁, y₂⟩ := y rintro ⟨rfl, h⟩ simp only [Sigma.mk.inj_iff, heq_eq_eq, true_and] ext i j by_cases hij : c.Rel j i · exact h _ _ hij · simp only [Homotopy.zero _ _ _ hij] /-- Morphisms `homotopyCofiber φ ⟶ K` are uniquely determined by a morphism `α : G ⟶ K` and a homotopy from `φ ≫ α` to `0`. -/ noncomputable def descEquiv (K : HomologicalComplex C c) (hc : ∀ j, ∃ i, c.Rel i j) : (Σ (α : G ⟶ K), Homotopy (φ ≫ α) 0) ≃ (homotopyCofiber φ ⟶ K) where toFun := fun ⟨α, hα⟩ => desc φ α hα invFun f := ⟨inr φ ≫ f, Homotopy.trans (Homotopy.ofEq (by simp)) (((inrCompHomotopy φ hc).compRight f).trans (Homotopy.ofEq (by simp)))⟩ right_inv f := (eq_desc φ f hc).symm left_inv := fun ⟨α, hα⟩ => by rw [descSigma_ext_iff] aesop_cat end homotopyCofiber section variable (K) variable [∀ i, HasBinaryBiproduct (K.X i) (K.X i)] [HasHomotopyCofiber (biprod.lift (𝟙 K) (-𝟙 K))] /-- The cylinder object of a homological complex `K` is the homotopy cofiber of the morphism `biprod.lift (𝟙 K) (-𝟙 K) : K ⟶ K ⊞ K`. -/ noncomputable abbrev cylinder := homotopyCofiber (biprod.lift (𝟙 K) (-𝟙 K)) namespace cylinder /-- The left inclusion `K ⟶ K.cylinder`. -/ noncomputable def ι₀ : K ⟶ K.cylinder := biprod.inl ≫ homotopyCofiber.inr _ /-- The right inclusion `K ⟶ K.cylinder`. -/ noncomputable def ι₁ : K ⟶ K.cylinder := biprod.inr ≫ homotopyCofiber.inr _ variable {K} section variable (φ₀ φ₁ : K ⟶ F) (h : Homotopy φ₀ φ₁) /-- The morphism `K.cylinder ⟶ F` that is induced by two morphisms `φ₀ φ₁ : K ⟶ F` and a homotopy `h : Homotopy φ₀ φ₁`. -/ noncomputable def desc : K.cylinder ⟶ F := homotopyCofiber.desc _ (biprod.desc φ₀ φ₁) (Homotopy.trans (Homotopy.ofEq (by simp only [biprod.lift_desc, id_comp, neg_comp, sub_eq_add_neg])) ((Homotopy.equivSubZero h))) @[reassoc (attr := simp)] lemma ι₀_desc : ι₀ K ≫ desc φ₀ φ₁ h = φ₀ := by simp [ι₀, desc] @[reassoc (attr := simp)] lemma ι₁_desc : ι₁ K ≫ desc φ₀ φ₁ h = φ₁ := by simp [ι₁, desc] end variable (K) /-- The projection `π : K.cylinder ⟶ K`. -/ noncomputable def π : K.cylinder ⟶ K := desc (𝟙 K) (𝟙 K) (Homotopy.refl _) @[reassoc (attr := simp)] lemma ι₀_π : ι₀ K ≫ π K = 𝟙 K := by simp [π] @[reassoc (attr := simp)] lemma ι₁_π : ι₁ K ≫ π K = 𝟙 K := by simp [π] /-- The left inclusion `K.X i ⟶ K.cylinder.X j` when `c.Rel j i`. -/ noncomputable abbrev inlX (i j : ι) (hij : c.Rel j i) : K.X i ⟶ K.cylinder.X j := homotopyCofiber.inlX (biprod.lift (𝟙 K) (-𝟙 K)) i j hij /-- The right inclusion `(K ⊞ K).X i ⟶ K.cylinder.X i`. -/ noncomputable abbrev inrX (i : ι) : (K ⊞ K).X i ⟶ K.cylinder.X i := homotopyCofiber.inrX (biprod.lift (𝟙 K) (-𝟙 K)) i @[reassoc (attr := simp)] lemma inlX_π (i j : ι) (hij : c.Rel j i) : inlX K i j hij ≫ (π K).f j = 0 := by erw [homotopyCofiber.inlX_desc_f] simp [Homotopy.equivSubZero] @[reassoc (attr := simp)] lemma inrX_π (i : ι) : inrX K i ≫ (π K).f i = (biprod.desc (𝟙 _) (𝟙 K)).f i := homotopyCofiber.inrX_desc_f _ _ _ _ section variable (hc : ∀ j, ∃ i, c.Rel i j) namespace πCompι₀Homotopy /-- A null homotopic map `K.cylinder ⟶ K.cylinder` which identifies to `π K ≫ ι₀ K - 𝟙 _`, see `nullHomotopicMap_eq`. -/ noncomputable def nullHomotopicMap : K.cylinder ⟶ K.cylinder := Homotopy.nullHomotopicMap' (fun i j hij => homotopyCofiber.sndX (biprod.lift (𝟙 K) (-𝟙 K)) i ≫ (biprod.snd : K ⊞ K ⟶ K).f i ≫ inlX K i j hij) /-- The obvious homotopy from `nullHomotopicMap K` to zero. -/ noncomputable def nullHomotopy : Homotopy (nullHomotopicMap K) 0 := Homotopy.nullHomotopy' _ lemma inlX_nullHomotopy_f (i j : ι) (hij : c.Rel j i) : inlX K i j hij ≫ (nullHomotopicMap K).f j = inlX K i j hij ≫ (π K ≫ ι₀ K - 𝟙 _).f j := by dsimp [nullHomotopicMap] by_cases hj : ∃ (k : ι), c.Rel k j · obtain ⟨k, hjk⟩ := hj simp only [assoc, Homotopy.nullHomotopicMap'_f hjk hij, homotopyCofiber_X, homotopyCofiber_d, homotopyCofiber.d_sndX_assoc _ _ _ hij, add_comp, comp_add, homotopyCofiber.inlX_fstX_assoc, homotopyCofiber.inlX_sndX_assoc, zero_comp, add_zero, comp_sub, inlX_π_assoc, comp_id, zero_sub, ← HomologicalComplex.comp_f_assoc, biprod.lift_snd, neg_f_apply, id_f, neg_comp, id_comp] · simp only [not_exists] at hj simp only [Homotopy.nullHomotopicMap'_f_of_not_rel_right hij hj, homotopyCofiber_X, homotopyCofiber_d, assoc, comp_sub, comp_id, homotopyCofiber.d_sndX_assoc _ _ _ hij, add_comp, comp_add, zero_comp, add_zero, homotopyCofiber.inlX_fstX_assoc, homotopyCofiber.inlX_sndX_assoc, ← HomologicalComplex.comp_f_assoc, biprod.lift_snd, neg_f_apply, id_f, neg_comp, id_comp, inlX_π_assoc, zero_sub] lemma biprod_lift_id_sub_id : biprod.lift (𝟙 K) (-𝟙 K) = biprod.inl - biprod.inr := biprod.hom_ext _ _ (by simp) (by simp) lemma inrX_nullHomotopy_f (j : ι) : inrX K j ≫ (nullHomotopicMap K).f j = inrX K j ≫ (π K ≫ ι₀ K - 𝟙 _).f j := by obtain ⟨i, hij⟩ := hc j dsimp [nullHomotopicMap] by_cases hj : ∃ (k : ι), c.Rel j k · obtain ⟨k, hjk⟩ := hj simp only [Homotopy.nullHomotopicMap'_f hij hjk, homotopyCofiber_X, homotopyCofiber_d, assoc, comp_add, homotopyCofiber.inrX_d_assoc, homotopyCofiber.inrX_sndX_assoc, comp_sub, inrX_π_assoc, comp_id, ← Hom.comm_assoc, homotopyCofiber.inlX_d _ _ _ _ _ hjk, comp_neg, add_neg_cancel_left] rw [← cancel_epi (biprodXIso K K j).inv] ext · simp [ι₀] · dsimp simp only [inr_biprodXIso_inv_assoc, biprod_inr_snd_f_assoc, comp_sub, biprod_inr_desc_f_assoc, id_f, id_comp, ι₀, comp_f, biprod_lift_id_sub_id, sub_f_apply, sub_comp, homotopyCofiber_X, homotopyCofiber.inr_f] · simp only [not_exists] at hj simp only [assoc, Homotopy.nullHomotopicMap'_f_of_not_rel_left hij hj, homotopyCofiber_X, homotopyCofiber_d, homotopyCofiber.inlX_d' _ _ _ _ (hj _), homotopyCofiber.inrX_sndX_assoc, comp_sub, inrX_π_assoc, comp_id, ι₀, comp_f, homotopyCofiber.inr_f] rw [← cancel_epi (biprodXIso K K j).inv] ext · simp · simp [biprod_lift_id_sub_id] lemma nullHomotopicMap_eq : nullHomotopicMap K = π K ≫ ι₀ K - 𝟙 _ := by ext i by_cases hi : c.Rel i (c.next i) · exact homotopyCofiber.ext_from_X (biprod.lift (𝟙 K) (-𝟙 K)) (c.next i) i hi (inlX_nullHomotopy_f _ _ _ _) (inrX_nullHomotopy_f _ hc _) · exact homotopyCofiber.ext_from_X' (biprod.lift (𝟙 K) (-𝟙 K)) _ hi (inrX_nullHomotopy_f _ hc _) end πCompι₀Homotopy /-- The homotopy between `π K ≫ ι₀ K` and `𝟙 K.cylinder`. -/ noncomputable def πCompι₀Homotopy : Homotopy (π K ≫ ι₀ K) (𝟙 K.cylinder) := Homotopy.equivSubZero.symm ((Homotopy.ofEq (πCompι₀Homotopy.nullHomotopicMap_eq K hc).symm).trans (πCompι₀Homotopy.nullHomotopy K)) /-- The homotopy equivalence between `K.cylinder` and `K`. -/ noncomputable def homotopyEquiv : HomotopyEquiv K.cylinder K where hom := π K inv := ι₀ K homotopyHomInvId := πCompι₀Homotopy K hc homotopyInvHomId := Homotopy.ofEq (by simp) /-- The homotopy between `cylinder.ι₀ K` and `cylinder.ι₁ K`. -/ noncomputable def homotopy₀₁ : Homotopy (ι₀ K) (ι₁ K) := (Homotopy.ofEq (by simp)).trans (((πCompι₀Homotopy K hc).compLeft (ι₁ K)).trans (Homotopy.ofEq (by simp))) lemma map_ι₀_eq_map_ι₁ {D : Type*} [Category D] (H : HomologicalComplex C c ⥤ D) (hH : (homotopyEquivalences C c).IsInvertedBy H) : H.map (ι₀ K) = H.map (ι₁ K) := by have : IsIso (H.map (cylinder.π K)) := hH _ ⟨homotopyEquiv K hc, rfl⟩ simp only [← cancel_mono (H.map (cylinder.π K)), ← H.map_comp, ι₀_π, H.map_id, ι₁_π] end end cylinder /-- If a functor inverts homotopy equivalences, it sends homotopic maps to the same map. -/ lemma _root_.Homotopy.map_eq_of_inverts_homotopyEquivalences {φ₀ φ₁ : F ⟶ G} (h : Homotopy φ₀ φ₁) (hc : ∀ j, ∃ i, c.Rel i j) [∀ i, HasBinaryBiproduct (F.X i) (F.X i)] [HasHomotopyCofiber (biprod.lift (𝟙 F) (-𝟙 F))] {D : Type*} [Category D] (H : HomologicalComplex C c ⥤ D) (hH : (homotopyEquivalences C c).IsInvertedBy H) : H.map φ₀ = H.map φ₁ := by simp only [← cylinder.ι₀_desc _ _ h, ← cylinder.ι₁_desc _ _ h, H.map_comp, cylinder.map_ι₀_eq_map_ι₁ _ hc _ hH] end end HomologicalComplex
Algebra\Homology\ImageToKernel.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Subobject.Limits /-! # Image-to-kernel comparison maps Whenever `f : A ⟶ B` and `g : B ⟶ C` satisfy `w : f ≫ g = 0`, we have `image_le_kernel f g w : imageSubobject f ≤ kernelSubobject g` (assuming the appropriate images and kernels exist). `imageToKernel f g w` is the corresponding morphism between objects in `C`. -/ universe v u w open CategoryTheory CategoryTheory.Limits variable {ι : Type*} variable {V : Type u} [Category.{v} V] [HasZeroMorphisms V] noncomputable section section variable {A B C : V} (f : A ⟶ B) [HasImage f] (g : B ⟶ C) [HasKernel g] theorem image_le_kernel (w : f ≫ g = 0) : imageSubobject f ≤ kernelSubobject g := imageSubobject_le_mk _ _ (kernel.lift _ _ w) (by simp) /-- The canonical morphism `imageSubobject f ⟶ kernelSubobject g` when `f ≫ g = 0`. -/ def imageToKernel (w : f ≫ g = 0) : (imageSubobject f : V) ⟶ (kernelSubobject g : V) := Subobject.ofLE _ _ (image_le_kernel _ _ w) instance (w : f ≫ g = 0) : Mono (imageToKernel f g w) := by dsimp only [imageToKernel] infer_instance /-- Prefer `imageToKernel`. -/ @[simp] theorem subobject_ofLE_as_imageToKernel (w : f ≫ g = 0) (h) : Subobject.ofLE (imageSubobject f) (kernelSubobject g) h = imageToKernel f g w := rfl attribute [local instance] ConcreteCategory.instFunLike -- Porting note: removed elementwise attribute which does not seem to be helpful here -- a more suitable lemma is added below @[reassoc (attr := simp)] theorem imageToKernel_arrow (w : f ≫ g = 0) : imageToKernel f g w ≫ (kernelSubobject g).arrow = (imageSubobject f).arrow := by simp [imageToKernel] @[simp] lemma imageToKernel_arrow_apply [ConcreteCategory V] (w : f ≫ g = 0) (x : (forget V).obj (Subobject.underlying.obj (imageSubobject f))) : (kernelSubobject g).arrow (imageToKernel f g w x) = (imageSubobject f).arrow x := by rw [← comp_apply, imageToKernel_arrow] -- This is less useful as a `simp` lemma than it initially appears, -- as it "loses" the information the morphism factors through the image. theorem factorThruImageSubobject_comp_imageToKernel (w : f ≫ g = 0) : factorThruImageSubobject f ≫ imageToKernel f g w = factorThruKernelSubobject g f w := by ext simp end section variable {A B C : V} (f : A ⟶ B) (g : B ⟶ C) @[simp] theorem imageToKernel_zero_left [HasKernels V] [HasZeroObject V] {w} : imageToKernel (0 : A ⟶ B) g w = 0 := by ext simp theorem imageToKernel_zero_right [HasImages V] {w} : imageToKernel f (0 : B ⟶ C) w = (imageSubobject f).arrow ≫ inv (kernelSubobject (0 : B ⟶ C)).arrow := by ext simp section variable [HasKernels V] [HasImages V] theorem imageToKernel_comp_right {D : V} (h : C ⟶ D) (w : f ≫ g = 0) : imageToKernel f (g ≫ h) (by simp [reassoc_of% w]) = imageToKernel f g w ≫ Subobject.ofLE _ _ (kernelSubobject_comp_le g h) := by ext simp theorem imageToKernel_comp_left {Z : V} (h : Z ⟶ A) (w : f ≫ g = 0) : imageToKernel (h ≫ f) g (by simp [w]) = Subobject.ofLE _ _ (imageSubobject_comp_le h f) ≫ imageToKernel f g w := by ext simp @[simp] theorem imageToKernel_comp_mono {D : V} (h : C ⟶ D) [Mono h] (w) : imageToKernel f (g ≫ h) w = imageToKernel f g ((cancel_mono h).mp (by simpa using w : (f ≫ g) ≫ h = 0 ≫ h)) ≫ (Subobject.isoOfEq _ _ (kernelSubobject_comp_mono g h)).inv := by ext simp @[simp] theorem imageToKernel_epi_comp {Z : V} (h : Z ⟶ A) [Epi h] (w) : imageToKernel (h ≫ f) g w = Subobject.ofLE _ _ (imageSubobject_comp_le h f) ≫ imageToKernel f g ((cancel_epi h).mp (by simpa using w : h ≫ f ≫ g = h ≫ 0)) := by ext simp end @[simp] theorem imageToKernel_comp_hom_inv_comp [HasEqualizers V] [HasImages V] {Z : V} {i : B ≅ Z} (w) : imageToKernel (f ≫ i.hom) (i.inv ≫ g) w = (imageSubobjectCompIso _ _).hom ≫ imageToKernel f g (by simpa using w) ≫ (kernelSubobjectIsoComp i.inv g).inv := by ext simp open ZeroObject /-- `imageToKernel` for `A --0--> B --g--> C`, where `g` is a mono is itself an epi (i.e. the sequence is exact at `B`). -/ instance imageToKernel_epi_of_zero_of_mono [HasKernels V] [HasZeroObject V] [Mono g] : Epi (imageToKernel (0 : A ⟶ B) g (by simp)) := epi_of_target_iso_zero _ (kernelSubobjectIso g ≪≫ kernel.ofMono g) /-- `imageToKernel` for `A --f--> B --0--> C`, where `g` is an epi is itself an epi (i.e. the sequence is exact at `B`). -/ instance imageToKernel_epi_of_epi_of_zero [HasImages V] [Epi f] : Epi (imageToKernel f (0 : B ⟶ C) (by simp)) := by simp only [imageToKernel_zero_right] haveI := epi_image_of_epi f rw [← imageSubobject_arrow] exact @epi_comp _ _ _ _ _ _ (epi_comp _ _) _ _ end section imageToKernel' /-! We provide a variant `imageToKernel' : image f ⟶ kernel g`, and use this to give alternative formulas for `homology f g w`. -/ variable {A B C : V} (f : A ⟶ B) (g : B ⟶ C) (w : f ≫ g = 0) [HasKernels V] [HasImages V] /-- While `imageToKernel f g w` provides a morphism `imageSubobject f ⟶ kernelSubobject g` in terms of the subobject API, this variant provides a morphism `image f ⟶ kernel g`, which is sometimes more convenient. -/ def imageToKernel' (w : f ≫ g = 0) : image f ⟶ kernel g := kernel.lift g (image.ι f) <| by ext simpa using w @[simp] theorem imageSubobjectIso_imageToKernel' (w : f ≫ g = 0) : (imageSubobjectIso f).hom ≫ imageToKernel' f g w = imageToKernel f g w ≫ (kernelSubobjectIso g).hom := by ext simp [imageToKernel'] @[simp] theorem imageToKernel'_kernelSubobjectIso (w : f ≫ g = 0) : imageToKernel' f g w ≫ (kernelSubobjectIso g).inv = (imageSubobjectIso f).inv ≫ imageToKernel f g w := by ext simp [imageToKernel'] end imageToKernel' end
Algebra\Homology\Linear.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Additive import Mathlib.CategoryTheory.Linear.LinearFunctor /-! # The category of homological complexes is linear In this file, we define the instance `Linear R (HomologicalComplex C c)` when the category `C` is `R`-linear. ## TODO - show lemmas like `HomologicalComplex.homologyMap_smul` (after doing the same for short complexes in `Mathlib.Algebra.Homology.ShortComplex.Linear`) -/ open CategoryTheory variable {R : Type*} [Semiring R] {C D : Type*} [Category C] [Preadditive C] [Category D] [Preadditive D] [CategoryTheory.Linear R C] [CategoryTheory.Linear R D] {ι : Type*} {c : ComplexShape ι} namespace HomologicalComplex variable {X Y : HomologicalComplex C c} instance : SMul R (X ⟶ Y) where smul r f := { f := fun n => r • f.f n } @[simp] lemma smul_f_apply (r : R) (f : X ⟶ Y) (n : ι) : (r • f).f n = r • f.f n := rfl @[simp] lemma units_smul_f_apply (r : Rˣ) (f : X ⟶ Y) (n : ι) : (r • f).f n = r • f.f n := rfl instance (X Y : HomologicalComplex C c) : Module R (X ⟶ Y) where one_smul a := by aesop_cat smul_zero := by aesop_cat smul_add := by aesop_cat zero_smul := by aesop_cat add_smul _ _ _ := by ext; apply add_smul mul_smul _ _ _ := by ext; apply mul_smul instance : Linear R (HomologicalComplex C c) where end HomologicalComplex instance CategoryTheory.Functor.mapHomologicalComplex_linear (F : C ⥤ D) [F.Additive] [Functor.Linear R F] (c : ComplexShape ι) : Functor.Linear R (F.mapHomologicalComplex c) where
Algebra\Homology\LocalCohomology.lean
/- Copyright (c) 2023 Emily Witt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Emily Witt, Scott Morrison, Jake Levinson, Sam van Gool -/ import Mathlib.RingTheory.Ideal.Basic import Mathlib.Algebra.Category.ModuleCat.Colimits import Mathlib.Algebra.Category.ModuleCat.Projective import Mathlib.CategoryTheory.Abelian.Ext import Mathlib.RingTheory.Finiteness import Mathlib.CategoryTheory.Limits.Final import Mathlib.RingTheory.Noetherian /-! # Local cohomology. This file defines the `i`-th local cohomology module of an `R`-module `M` with support in an ideal `I` of `R`, where `R` is a commutative ring, as the direct limit of Ext modules: Given a collection of ideals cofinal with the powers of `I`, consider the directed system of quotients of `R` by these ideals, and take the direct limit of the system induced on the `i`-th Ext into `M`. One can, of course, take the collection to simply be the integral powers of `I`. ## References * [M. Hochster, *Local cohomology*][hochsterunpublished] <https://dept.math.lsa.umich.edu/~hochster/615W22/lcc.pdf> * [R. Hartshorne, *Local cohomology: A seminar given by A. Grothendieck*][hartshorne61] * [M. Brodmann and R. Sharp, *Local cohomology: An algebraic introduction with geometric applications*][brodmannsharp13] * [S. Iyengar, G. Leuschke, A. Leykin, Anton, C. Miller, E. Miller, A. Singh, U. Walther, *Twenty-four hours of local cohomology*][iyengaretal13] ## Tags local cohomology, local cohomology modules ## Future work * Prove that this definition is equivalent to: * the right-derived functor definition * the characterization as the limit of Koszul homology * the characterization as the cohomology of a Cech-like complex * Establish long exact sequence(s) in local cohomology -/ open Opposite open CategoryTheory open CategoryTheory.Limits noncomputable section universe u v v' namespace localCohomology -- We define local cohomology, implemented as a direct limit of `Ext(R/J, -)`. section variable {R : Type u} [CommRing R] {D : Type v} [SmallCategory D] /-- The directed system of `R`-modules of the form `R/J`, where `J` is an ideal of `R`, determined by the functor `I` -/ def ringModIdeals (I : D ⥤ Ideal R) : D ⥤ ModuleCat.{u} R where obj t := ModuleCat.of R <| R ⧸ I.obj t map w := Submodule.mapQ _ _ LinearMap.id (I.map w).down.down -- Porting note: was 'obviously' map_comp f g := by apply Submodule.linearMap_qext; rfl -- Porting note (#11215): TODO: Once this file is ported, move this instance to the right location. instance moduleCat_enoughProjectives' : EnoughProjectives (ModuleCat.{u} R) := ModuleCat.moduleCat_enoughProjectives.{u} /-- The diagram we will take the colimit of to define local cohomology, corresponding to the directed system determined by the functor `I` -/ def diagram (I : D ⥤ Ideal R) (i : ℕ) : Dᵒᵖ ⥤ ModuleCat.{u} R ⥤ ModuleCat.{u} R := (ringModIdeals I).op ⋙ Ext R (ModuleCat.{u} R) i end section -- We momentarily need to work with a type inequality, as later we will take colimits -- along diagrams either in Type, or in the same universe as the ring, and we need to cover both. variable {R : Type max u v} [CommRing R] {D : Type v} [SmallCategory D] lemma hasColimitDiagram (I : D ⥤ Ideal R) (i : ℕ) : HasColimit (diagram I i) := by have : HasColimitsOfShape Dᵒᵖ (AddCommGrpMax.{u, v}) := inferInstance infer_instance /- In this definition we do not assume any special property of the diagram `I`, but the relevant case will be where `I` is (cofinal with) the diagram of powers of a single given ideal. Below, we give two equivalent definitions of the usual local cohomology with support in an ideal `J`, `localCohomology` and `localCohomology.ofSelfLERadical`. -/ /-- `localCohomology.ofDiagram I i` is the functor sending a module `M` over a commutative ring `R` to the direct limit of `Ext^i(R/J, M)`, where `J` ranges over a collection of ideals of `R`, represented as a functor `I`. -/ def ofDiagram (I : D ⥤ Ideal R) (i : ℕ) : ModuleCatMax.{u, v} R ⥤ ModuleCatMax.{u, v} R := have := hasColimitDiagram.{u, v} I i colimit (diagram I i) end section variable {R : Type max u v v'} [CommRing R] {D : Type v} [SmallCategory D] variable {E : Type v'} [SmallCategory E] (I' : E ⥤ D) (I : D ⥤ Ideal R) /-- Local cohomology along a composition of diagrams. -/ def diagramComp (i : ℕ) : diagram (I' ⋙ I) i ≅ I'.op ⋙ diagram I i := Iso.refl _ /-- Local cohomology agrees along precomposition with a cofinal diagram. -/ @[nolint unusedHavesSuffices] def isoOfFinal [Functor.Initial I'] (i : ℕ) : ofDiagram.{max u v, v'} (I' ⋙ I) i ≅ ofDiagram.{max u v', v} I i := have := hasColimitDiagram.{max u v', v} I i have := hasColimitDiagram.{max u v, v'} (I' ⋙ I) i HasColimit.isoOfNatIso (diagramComp.{u} I' I i) ≪≫ Functor.Final.colimitIso _ _ end section Diagrams variable {R : Type u} [CommRing R] /-- The functor sending a natural number `i` to the `i`-th power of the ideal `J` -/ def idealPowersDiagram (J : Ideal R) : ℕᵒᵖ ⥤ Ideal R where obj t := J ^ unop t map w := ⟨⟨Ideal.pow_le_pow_right w.unop.down.down⟩⟩ /-- The full subcategory of all ideals with radical containing `J` -/ def SelfLERadical (J : Ideal R) : Type u := FullSubcategory fun J' : Ideal R => J ≤ J'.radical -- Porting note: `deriving Category` is not able to derive this instance -- https://github.com/leanprover-community/mathlib4/issues/5020 instance (J : Ideal R) : Category (SelfLERadical J) := (FullSubcategory.category _) instance SelfLERadical.inhabited (J : Ideal R) : Inhabited (SelfLERadical J) where default := ⟨J, Ideal.le_radical⟩ /-- The diagram of all ideals with radical containing `J`, represented as a functor. This is the "largest" diagram that computes local cohomology with support in `J`. -/ def selfLERadicalDiagram (J : Ideal R) : SelfLERadical J ⥤ Ideal R := fullSubcategoryInclusion _ end Diagrams end localCohomology /-! We give two models for the local cohomology with support in an ideal `J`: first in terms of the powers of `J` (`localCohomology`), then in terms of *all* ideals with radical containing `J` (`localCohomology.ofSelfLERadical`). -/ section ModelsForLocalCohomology open localCohomology variable {R : Type u} [CommRing R] /-- `localCohomology J i` is `i`-th the local cohomology module of a module `M` over a commutative ring `R` with support in the ideal `J` of `R`, defined as the direct limit of `Ext^i(R/J^t, M)` over all powers `t : ℕ`. -/ def localCohomology (J : Ideal R) (i : ℕ) : ModuleCat.{u} R ⥤ ModuleCat.{u} R := ofDiagram (idealPowersDiagram J) i /-- Local cohomology as the direct limit of `Ext^i(R/J', M)` over *all* ideals `J'` with radical containing `J`. -/ def localCohomology.ofSelfLERadical (J : Ideal R) (i : ℕ) : ModuleCat.{u} R ⥤ ModuleCat.{u} R := ofDiagram.{u} (selfLERadicalDiagram.{u} J) i end ModelsForLocalCohomology namespace localCohomology /-! Showing equivalence of different definitions of local cohomology. * `localCohomology.isoSelfLERadical` gives the isomorphism `localCohomology J i ≅ localCohomology.ofSelfLERadical J i` * `localCohomology.isoOfSameRadical` gives the isomorphism `localCohomology J i ≅ localCohomology K i` when `J.radical = K.radical`. -/ section LocalCohomologyEquiv variable {R : Type u} [CommRing R] /-- Lifting `idealPowersDiagram J` from a diagram valued in `ideals R` to a diagram valued in `SelfLERadical J`. -/ def idealPowersToSelfLERadical (J : Ideal R) : ℕᵒᵖ ⥤ SelfLERadical J := FullSubcategory.lift _ (idealPowersDiagram J) fun k => by change _ ≤ (J ^ unop k).radical cases' unop k with n · simp [Ideal.radical_top, pow_zero, Ideal.one_eq_top, le_top, Nat.zero_eq] · simp only [J.radical_pow n.succ_ne_zero, Ideal.le_radical] variable {I J K : Ideal R} /-- The lemma below essentially says that `idealPowersToSelfLERadical I` is initial in `selfLERadicalDiagram I`. Porting note: This lemma should probably be moved to `Mathlib/RingTheory/Finiteness` to be near `Ideal.exists_radical_pow_le_of_fg`, which it generalizes. -/ theorem Ideal.exists_pow_le_of_le_radical_of_fG (hIJ : I ≤ J.radical) (hJ : J.radical.FG) : ∃ k : ℕ, I ^ k ≤ J := by obtain ⟨k, hk⟩ := J.exists_radical_pow_le_of_fg hJ use k calc I ^ k ≤ J.radical ^ k := Ideal.pow_right_mono hIJ _ _ ≤ J := hk /-- The diagram of powers of `J` is initial in the diagram of all ideals with radical containing `J`. This uses noetherianness. -/ instance ideal_powers_initial [hR : IsNoetherian R R] : Functor.Initial (idealPowersToSelfLERadical J) where out J' := by apply (config := {allowSynthFailures := true }) zigzag_isConnected · obtain ⟨k, hk⟩ := Ideal.exists_pow_le_of_le_radical_of_fG J'.2 (isNoetherian_def.mp hR _) exact ⟨CostructuredArrow.mk (⟨⟨hk⟩⟩ : (idealPowersToSelfLERadical J).obj (op k) ⟶ J')⟩ · intro j1 j2 apply Relation.ReflTransGen.single -- The inclusions `J^n1 ≤ J'` and `J^n2 ≤ J'` always form a triangle, based on -- which exponent is larger. rcases le_total (unop j1.left) (unop j2.left) with h | h · right; exact ⟨CostructuredArrow.homMk (homOfLE h).op (AsTrue.get trivial)⟩ · left; exact ⟨CostructuredArrow.homMk (homOfLE h).op (AsTrue.get trivial)⟩ example : HasColimitsOfSize.{0, 0, u, u + 1} (ModuleCat.{u, u} R) := inferInstance /-- Local cohomology (defined in terms of powers of `J`) agrees with local cohomology computed over all ideals with radical containing `J`. -/ def isoSelfLERadical (J : Ideal.{u} R) [IsNoetherian.{u,u} R R] (i : ℕ) : localCohomology.ofSelfLERadical.{u} J i ≅ localCohomology.{u} J i := (localCohomology.isoOfFinal.{u, u, 0} (idealPowersToSelfLERadical.{u} J) (selfLERadicalDiagram.{u} J) i).symm ≪≫ HasColimit.isoOfNatIso.{0,0,u+1,u+1} (Iso.refl.{u+1,u+1} _) /-- Casting from the full subcategory of ideals with radical containing `J` to the full subcategory of ideals with radical containing `K`. -/ def SelfLERadical.cast (hJK : J.radical = K.radical) : SelfLERadical J ⥤ SelfLERadical K := FullSubcategory.map fun L hL => by rw [← Ideal.radical_le_radical_iff] at hL ⊢ exact hJK.symm.trans_le hL -- TODO generalize this to the equivalence of full categories for any `iff`. /-- The equivalence of categories `SelfLERadical J ≌ SelfLERadical K` when `J.radical = K.radical`. -/ def SelfLERadical.castEquivalence (hJK : J.radical = K.radical) : SelfLERadical J ≌ SelfLERadical K where functor := SelfLERadical.cast hJK inverse := SelfLERadical.cast hJK.symm unitIso := Iso.refl _ counitIso := Iso.refl _ instance SelfLERadical.cast_isEquivalence (hJK : J.radical = K.radical) : (SelfLERadical.cast hJK).IsEquivalence := (castEquivalence hJK).isEquivalence_functor /-- The natural isomorphism between local cohomology defined using the `of_self_le_radical` diagram, assuming `J.radical = K.radical`. -/ def SelfLERadical.isoOfSameRadical (hJK : J.radical = K.radical) (i : ℕ) : ofSelfLERadical J i ≅ ofSelfLERadical K i := (isoOfFinal.{u, u, u} (SelfLERadical.cast hJK.symm) _ _).symm /-- Local cohomology agrees on ideals with the same radical. -/ def isoOfSameRadical [IsNoetherian R R] (hJK : J.radical = K.radical) (i : ℕ) : localCohomology J i ≅ localCohomology K i := (isoSelfLERadical J i).symm ≪≫ SelfLERadical.isoOfSameRadical hJK i ≪≫ isoSelfLERadical K i end LocalCohomologyEquiv end localCohomology
Algebra\Homology\Localization.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCofiber import Mathlib.Algebra.Homology.HomotopyCategory import Mathlib.Algebra.Homology.QuasiIso import Mathlib.CategoryTheory.Localization.Composition import Mathlib.CategoryTheory.Localization.HasLocalization /-! The category of homological complexes up to quasi-isomorphisms Given a category `C` with homology and any complex shape `c`, we define the category `HomologicalComplexUpToQuasiIso C c` which is the localized category of `HomologicalComplex C c` with respect to quasi-isomorphisms. When `C` is abelian, this will be the derived category of `C` in the particular case of the complex shape `ComplexShape.up ℤ`. Under suitable assumptions on `c` (e.g. chain complexes, or cochain complexes indexed by `ℤ`), we shall show that `HomologicalComplexUpToQuasiIso C c` is also the localized category of `HomotopyCategory C c` with respect to the class of quasi-isomorphisms. -/ open CategoryTheory Limits section variable (C : Type*) [Category C] {ι : Type*} (c : ComplexShape ι) [HasZeroMorphisms C] [CategoryWithHomology C] [(HomologicalComplex.quasiIso C c).HasLocalization] /-- The category of homological complexes up to quasi-isomorphisms. -/ abbrev HomologicalComplexUpToQuasiIso := (HomologicalComplex.quasiIso C c).Localization' variable {C c} /-- The localization functor `HomologicalComplex C c ⥤ HomologicalComplexUpToQuasiIso C c`. -/ abbrev HomologicalComplexUpToQuasiIso.Q : HomologicalComplex C c ⥤ HomologicalComplexUpToQuasiIso C c := (HomologicalComplex.quasiIso C c).Q' variable (C c) lemma HomologicalComplex.homologyFunctor_inverts_quasiIso (i : ι) : (quasiIso C c).IsInvertedBy (homologyFunctor C c i) := fun _ _ _ hf => by rw [mem_quasiIso_iff] at hf dsimp infer_instance namespace HomologicalComplexUpToQuasiIso /-- The homology functor `HomologicalComplexUpToQuasiIso C c ⥤ C` for each `i : ι`. -/ noncomputable def homologyFunctor (i : ι) : HomologicalComplexUpToQuasiIso C c ⥤ C := Localization.lift _ (HomologicalComplex.homologyFunctor_inverts_quasiIso C c i) Q /-- The homology functor on `HomologicalComplexUpToQuasiIso C c` is induced by the homology functor on `HomologicalComplex C c`. -/ noncomputable def homologyFunctorFactors (i : ι) : Q ⋙ homologyFunctor C c i ≅ HomologicalComplex.homologyFunctor C c i := Localization.fac _ (HomologicalComplex.homologyFunctor_inverts_quasiIso C c i) Q variable {C c} lemma isIso_Q_map_iff_mem_quasiIso {K L : HomologicalComplex C c} (f : K ⟶ L) : IsIso (Q.map f) ↔ HomologicalComplex.quasiIso C c f := by constructor · intro h rw [HomologicalComplex.mem_quasiIso_iff, quasiIso_iff] intro i rw [quasiIsoAt_iff_isIso_homologyMap] refine (NatIso.isIso_map_iff (homologyFunctorFactors C c i) f).1 ?_ dsimp infer_instance · intro h exact Localization.inverts Q (HomologicalComplex.quasiIso C c) _ h end HomologicalComplexUpToQuasiIso end section variable (C : Type*) [Category C] {ι : Type*} (c : ComplexShape ι) [Preadditive C] [CategoryWithHomology C] [(HomologicalComplex.quasiIso C c).HasLocalization] lemma HomologicalComplexUpToQuasiIso.Q_inverts_homotopyEquivalences : (HomologicalComplex.homotopyEquivalences C c).IsInvertedBy HomologicalComplexUpToQuasiIso.Q := MorphismProperty.IsInvertedBy.of_le _ _ _ (Localization.inverts Q (HomologicalComplex.quasiIso C c)) (homotopyEquivalences_le_quasiIso C c) namespace HomotopyCategory /-- The class of quasi-isomorphisms in the homotopy category. -/ def quasiIso : MorphismProperty (HomotopyCategory C c) := fun _ _ f => ∀ (i : ι), IsIso ((homologyFunctor C c i).map f) variable {C c} lemma mem_quasiIso_iff {X Y : HomotopyCategory C c} (f : X ⟶ Y) : quasiIso C c f ↔ ∀ (n : ι), IsIso ((homologyFunctor _ _ n).map f) := by rfl lemma quotient_map_mem_quasiIso_iff {K L : HomologicalComplex C c} (f : K ⟶ L) : quasiIso C c ((quotient C c).map f) ↔ HomologicalComplex.quasiIso C c f := by have eq := fun (i : ι) => NatIso.isIso_map_iff (homologyFunctorFactors C c i) f dsimp at eq simp only [HomologicalComplex.mem_quasiIso_iff, mem_quasiIso_iff, quasiIso_iff, quasiIsoAt_iff_isIso_homologyMap, eq] variable (C c) instance respectsIso_quasiIso : (quasiIso C c).RespectsIso := by apply MorphismProperty.RespectsIso.of_respects_arrow_iso intro f g e hf i exact ((MorphismProperty.isomorphisms C).arrow_mk_iso_iff ((homologyFunctor C c i).mapArrow.mapIso e)).1 (hf i) lemma homologyFunctor_inverts_quasiIso (i : ι) : (quasiIso C c).IsInvertedBy (homologyFunctor C c i) := fun _ _ _ hf => hf i lemma quasiIso_eq_quasiIso_map_quotient : quasiIso C c = (HomologicalComplex.quasiIso C c).map (quotient C c) := by ext ⟨K⟩ ⟨L⟩ f obtain ⟨f, rfl⟩ := (HomotopyCategory.quotient C c).map_surjective f constructor · intro hf rw [quotient_map_mem_quasiIso_iff] at hf exact MorphismProperty.map_mem_map _ _ _ hf · rintro ⟨K', L', g, h, ⟨e⟩⟩ rw [← quotient_map_mem_quasiIso_iff] at h exact ((quasiIso C c).arrow_mk_iso_iff e).1 h end HomotopyCategory /-- The condition on a complex shape `c` saying that homotopic maps become equal in the localized category with respect to quasi-isomorphisms. -/ class ComplexShape.QFactorsThroughHomotopy {ι : Type*} (c : ComplexShape ι) (C : Type*) [Category C] [Preadditive C] [CategoryWithHomology C] : Prop where areEqualizedByLocalization {K L : HomologicalComplex C c} {f g : K ⟶ L} (h : Homotopy f g) : AreEqualizedByLocalization (HomologicalComplex.quasiIso C c) f g namespace HomologicalComplexUpToQuasiIso variable {C c} variable [c.QFactorsThroughHomotopy C] lemma Q_map_eq_of_homotopy {K L : HomologicalComplex C c} {f g : K ⟶ L} (h : Homotopy f g) : Q.map f = Q.map g := (ComplexShape.QFactorsThroughHomotopy.areEqualizedByLocalization h).map_eq Q /-- The functor `HomotopyCategory C c ⥤ HomologicalComplexUpToQuasiIso C c` from the homotopy category to the localized category with respect to quasi-isomorphisms. -/ def Qh : HomotopyCategory C c ⥤ HomologicalComplexUpToQuasiIso C c := CategoryTheory.Quotient.lift _ HomologicalComplexUpToQuasiIso.Q (by intro K L f g ⟨h⟩ exact Q_map_eq_of_homotopy h) variable (C c) /-- The canonical isomorphism `HomotopyCategory.quotient C c ⋙ Qh ≅ Q`. -/ def quotientCompQhIso : HomotopyCategory.quotient C c ⋙ Qh ≅ Q := by apply Quotient.lift.isLift lemma Qh_inverts_quasiIso : (HomotopyCategory.quasiIso C c).IsInvertedBy Qh := by rintro ⟨K⟩ ⟨L⟩ φ obtain ⟨φ, rfl⟩ := (HomotopyCategory.quotient C c).map_surjective φ rw [HomotopyCategory.quotient_map_mem_quasiIso_iff φ, ← HomologicalComplexUpToQuasiIso.isIso_Q_map_iff_mem_quasiIso] exact (NatIso.isIso_map_iff (quotientCompQhIso C c) φ).2 instance : (HomotopyCategory.quotient C c ⋙ Qh).IsLocalization (HomologicalComplex.quasiIso C c) := Functor.IsLocalization.of_iso _ (quotientCompQhIso C c).symm /-- The homology functor on `HomologicalComplexUpToQuasiIso C c` is induced by the homology functor on `HomotopyCategory C c`. -/ noncomputable def homologyFunctorFactorsh (i : ι ) : Qh ⋙ homologyFunctor C c i ≅ HomotopyCategory.homologyFunctor C c i := Quotient.natIsoLift _ ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (quotientCompQhIso C c) _ ≪≫ homologyFunctorFactors C c i ≪≫ (HomotopyCategory.homologyFunctorFactors C c i).symm) section variable [(HomotopyCategory.quotient C c).IsLocalization (HomologicalComplex.homotopyEquivalences C c)] /-- The category `HomologicalComplexUpToQuasiIso C c` which was defined as a localization of `HomologicalComplex C c` with respect to quasi-isomorphisms also identify to a localization of the homotopy category with respect ot quasi-isomorphisms. -/ instance : HomologicalComplexUpToQuasiIso.Qh.IsLocalization (HomotopyCategory.quasiIso C c) := Functor.IsLocalization.of_comp (HomotopyCategory.quotient C c) Qh (HomologicalComplex.homotopyEquivalences C c) (HomotopyCategory.quasiIso C c) (HomologicalComplex.quasiIso C c) (homotopyEquivalences_le_quasiIso C c) (HomotopyCategory.quasiIso_eq_quasiIso_map_quotient C c) end end HomologicalComplexUpToQuasiIso end section Cylinder variable {ι : Type*} (c : ComplexShape ι) (hc : ∀ j, ∃ i, c.Rel i j) (C : Type*) [Category C] [Preadditive C] [HasBinaryBiproducts C] /-- The homotopy category satisfies the universal property of the localized category with respect to homotopy equivalences. -/ def ComplexShape.strictUniversalPropertyFixedTargetQuotient (E : Type*) [Category E] : Localization.StrictUniversalPropertyFixedTarget (HomotopyCategory.quotient C c) (HomologicalComplex.homotopyEquivalences C c) E where inverts := HomotopyCategory.quotient_inverts_homotopyEquivalences C c lift F hF := CategoryTheory.Quotient.lift _ F (by intro K L f g ⟨h⟩ have : DecidableRel c.Rel := by classical infer_instance exact h.map_eq_of_inverts_homotopyEquivalences hc F hF) fac F hF := rfl uniq F₁ F₂ h := Quotient.lift_unique' _ _ _ h lemma ComplexShape.quotient_isLocalization : (HomotopyCategory.quotient C c).IsLocalization (HomologicalComplex.homotopyEquivalences _ _) := by apply Functor.IsLocalization.mk' all_goals apply c.strictUniversalPropertyFixedTargetQuotient hc lemma ComplexShape.QFactorsThroughHomotopy_of_exists_prev [CategoryWithHomology C] : c.QFactorsThroughHomotopy C where areEqualizedByLocalization {K L f g} h := by have : DecidableRel c.Rel := by classical infer_instance exact h.map_eq_of_inverts_homotopyEquivalences hc _ (MorphismProperty.IsInvertedBy.of_le _ _ _ (Localization.inverts _ (HomologicalComplex.quasiIso C _)) (homotopyEquivalences_le_quasiIso C _)) end Cylinder section ChainComplex variable (C : Type*) [Category C] {ι : Type*} [Preadditive C] [AddRightCancelSemigroup ι] [One ι] [HasBinaryBiproducts C] instance : (HomotopyCategory.quotient C (ComplexShape.down ι)).IsLocalization (HomologicalComplex.homotopyEquivalences _ _) := (ComplexShape.down ι).quotient_isLocalization (fun _ => ⟨_, rfl⟩) C variable [CategoryWithHomology C] instance : (ComplexShape.down ι).QFactorsThroughHomotopy C := (ComplexShape.down ι).QFactorsThroughHomotopy_of_exists_prev (fun _ => ⟨_, rfl⟩) C example [(HomologicalComplex.quasiIso C (ComplexShape.down ι)).HasLocalization] : HomologicalComplexUpToQuasiIso.Qh.IsLocalization (HomotopyCategory.quasiIso C (ComplexShape.down ι)) := inferInstance /- By duality, the results obtained here for chain complexes could be dualized in order to obtain similar results for general cochain complexes. However, the case of interest for the construction of the derived category (cochain complexes indexed by `ℤ`) can also be obtained directly, which is done below. -/ end ChainComplex section CochainComplex variable (C : Type*) [Category C] {ι : Type*} [Preadditive C] [HasBinaryBiproducts C] instance : (HomotopyCategory.quotient C (ComplexShape.up ℤ)).IsLocalization (HomologicalComplex.homotopyEquivalences _ _) := (ComplexShape.up ℤ).quotient_isLocalization (fun n => ⟨n - 1, by simp⟩) C variable [CategoryWithHomology C] instance : (ComplexShape.up ℤ).QFactorsThroughHomotopy C := (ComplexShape.up ℤ).QFactorsThroughHomotopy_of_exists_prev (fun n => ⟨n - 1, by simp⟩) C /-- When we define the derived category as `HomologicalComplexUpToQuasiIso C (ComplexShape.up ℤ)`, i.e. as the localization of cochain complexes with respect to quasi-isomorphisms, this example shall say that the derived category is also the localization of the homotopy category with respect to quasi-isomorphisms. -/ example [(HomologicalComplex.quasiIso C (ComplexShape.up ℤ)).HasLocalization] : HomologicalComplexUpToQuasiIso.Qh.IsLocalization (HomotopyCategory.quasiIso C (ComplexShape.up ℤ)) := inferInstance end CochainComplex namespace CategoryTheory.Functor variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) {ι : Type*} (c : ComplexShape ι) section variable [Preadditive C] [Preadditive D] [CategoryWithHomology C] [CategoryWithHomology D] [(HomologicalComplex.quasiIso C c).HasLocalization] [(HomologicalComplex.quasiIso D c).HasLocalization] [F.Additive] [F.PreservesHomology] /-- The localizer morphism which expresses that `F.mapHomologicalComplex c` preserves quasi-isomorphisms. -/ @[simps] def mapHomologicalComplexUpToQuasiIsoLocalizerMorphism : LocalizerMorphism (HomologicalComplex.quasiIso C c) (HomologicalComplex.quasiIso D c) where functor := F.mapHomologicalComplex c map _ _ f (_ : QuasiIso f) := HomologicalComplex.quasiIso_map_of_preservesHomology _ _ lemma mapHomologicalComplex_upToQuasiIso_Q_inverts_quasiIso : (HomologicalComplex.quasiIso C c).IsInvertedBy (F.mapHomologicalComplex c ⋙ HomologicalComplexUpToQuasiIso.Q) := by apply (F.mapHomologicalComplexUpToQuasiIsoLocalizerMorphism c).inverts /-- The functor `HomologicalComplexUpToQuasiIso C c ⥤ HomologicalComplexUpToQuasiIso D c` induced by a functor `F : C ⥤ D` which preserves homology. -/ noncomputable def mapHomologicalComplexUpToQuasiIso : HomologicalComplexUpToQuasiIso C c ⥤ HomologicalComplexUpToQuasiIso D c := (F.mapHomologicalComplexUpToQuasiIsoLocalizerMorphism c).localizedFunctor HomologicalComplexUpToQuasiIso.Q HomologicalComplexUpToQuasiIso.Q noncomputable instance : Localization.Lifting HomologicalComplexUpToQuasiIso.Q (HomologicalComplex.quasiIso C c) (F.mapHomologicalComplex c ⋙ HomologicalComplexUpToQuasiIso.Q) (F.mapHomologicalComplexUpToQuasiIso c) := (F.mapHomologicalComplexUpToQuasiIsoLocalizerMorphism c).liftingLocalizedFunctor _ _ /-- The functor `F.mapHomologicalComplexUpToQuasiIso c` is induced by `F.mapHomologicalComplex c`. -/ noncomputable def mapHomologicalComplexUpToQuasiIsoFactors : HomologicalComplexUpToQuasiIso.Q ⋙ F.mapHomologicalComplexUpToQuasiIso c ≅ F.mapHomologicalComplex c ⋙ HomologicalComplexUpToQuasiIso.Q := Localization.Lifting.iso HomologicalComplexUpToQuasiIso.Q (HomologicalComplex.quasiIso C c) _ _ variable [c.QFactorsThroughHomotopy C] [c.QFactorsThroughHomotopy D] [(HomotopyCategory.quotient C c).IsLocalization (HomologicalComplex.homotopyEquivalences C c)] /-- The functor `F.mapHomologicalComplexUpToQuasiIso c` is induced by `F.mapHomotopyCategory c`. -/ noncomputable def mapHomologicalComplexUpToQuasiIsoFactorsh : HomologicalComplexUpToQuasiIso.Qh ⋙ F.mapHomologicalComplexUpToQuasiIso c ≅ F.mapHomotopyCategory c ⋙ HomologicalComplexUpToQuasiIso.Qh := Localization.liftNatIso (HomotopyCategory.quotient C c) (HomologicalComplex.homotopyEquivalences C c) (HomotopyCategory.quotient C c ⋙ HomologicalComplexUpToQuasiIso.Qh ⋙ F.mapHomologicalComplexUpToQuasiIso c) (HomotopyCategory.quotient C c ⋙ F.mapHomotopyCategory c ⋙ HomologicalComplexUpToQuasiIso.Qh) _ _ (F.mapHomologicalComplexUpToQuasiIsoFactors c) noncomputable instance : Localization.Lifting HomologicalComplexUpToQuasiIso.Qh (HomotopyCategory.quasiIso C c) (F.mapHomotopyCategory c ⋙ HomologicalComplexUpToQuasiIso.Qh) (F.mapHomologicalComplexUpToQuasiIso c) := ⟨F.mapHomologicalComplexUpToQuasiIsoFactorsh c⟩ variable {c} @[reassoc] lemma mapHomologicalComplexUpToQuasiIsoFactorsh_hom_app (K : HomologicalComplex C c) : (F.mapHomologicalComplexUpToQuasiIsoFactorsh c).hom.app ((HomotopyCategory.quotient _ _).obj K) = (F.mapHomologicalComplexUpToQuasiIso c).map ((HomologicalComplexUpToQuasiIso.quotientCompQhIso C c).hom.app K) ≫ (F.mapHomologicalComplexUpToQuasiIsoFactors c).hom.app K ≫ (HomologicalComplexUpToQuasiIso.quotientCompQhIso D c).inv.app _ ≫ HomologicalComplexUpToQuasiIso.Qh.map ((F.mapHomotopyCategoryFactors c).inv.app K) := by dsimp [mapHomologicalComplexUpToQuasiIsoFactorsh] rw [Localization.liftNatTrans_app] dsimp simp only [Category.comp_id, Category.id_comp] change _ = (F.mapHomologicalComplexUpToQuasiIso c).map (𝟙 _) ≫ _ ≫ 𝟙 _ ≫ HomologicalComplexUpToQuasiIso.Qh.map (𝟙 _) simp only [map_id, Category.comp_id, Category.id_comp] end end CategoryTheory.Functor
Algebra\Homology\Opposite.lean
/- Copyright (c) 2022 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Amelia Livingston, Joël Riou -/ import Mathlib.CategoryTheory.Abelian.Opposite import Mathlib.Algebra.Homology.Additive import Mathlib.Algebra.Homology.ImageToKernel import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex /-! # Opposite categories of complexes Given a preadditive category `V`, the opposite of its category of chain complexes is equivalent to the category of cochain complexes of objects in `Vᵒᵖ`. We define this equivalence, and another analogous equivalence (for a general category of homological complexes with a general complex shape). We then show that when `V` is abelian, if `C` is a homological complex, then the homology of `op(C)` is isomorphic to `op` of the homology of `C` (and the analogous result for `unop`). ## Implementation notes It is convenient to define both `op` and `opSymm`; this is because given a complex shape `c`, `c.symm.symm` is not defeq to `c`. ## Tags opposite, chain complex, cochain complex, homology, cohomology, homological complex -/ noncomputable section open Opposite CategoryTheory CategoryTheory.Limits section variable {V : Type*} [Category V] [Abelian V] theorem imageToKernel_op {X Y Z : V} (f : X ⟶ Y) (g : Y ⟶ Z) (w : f ≫ g = 0) : imageToKernel g.op f.op (by rw [← op_comp, w, op_zero]) = (imageSubobjectIso _ ≪≫ (imageOpOp _).symm).hom ≫ (cokernel.desc f (factorThruImage g) (by rw [← cancel_mono (image.ι g), Category.assoc, image.fac, w, zero_comp])).op ≫ (kernelSubobjectIso _ ≪≫ kernelOpOp _).inv := by ext simp only [Iso.trans_hom, Iso.symm_hom, Iso.trans_inv, kernelOpOp_inv, Category.assoc, imageToKernel_arrow, kernelSubobject_arrow', kernel.lift_ι, ← op_comp, cokernel.π_desc, ← imageSubobject_arrow, ← imageUnopOp_inv_comp_op_factorThruImage g.op] rfl theorem imageToKernel_unop {X Y Z : Vᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) (w : f ≫ g = 0) : imageToKernel g.unop f.unop (by rw [← unop_comp, w, unop_zero]) = (imageSubobjectIso _ ≪≫ (imageUnopUnop _).symm).hom ≫ (cokernel.desc f (factorThruImage g) (by rw [← cancel_mono (image.ι g), Category.assoc, image.fac, w, zero_comp])).unop ≫ (kernelSubobjectIso _ ≪≫ kernelUnopUnop _).inv := by ext dsimp only [imageUnopUnop] simp only [Iso.trans_hom, Iso.symm_hom, Iso.trans_inv, kernelUnopUnop_inv, Category.assoc, imageToKernel_arrow, kernelSubobject_arrow', kernel.lift_ι, cokernel.π_desc, Iso.unop_inv, ← unop_comp, factorThruImage_comp_imageUnopOp_inv, Quiver.Hom.unop_op, imageSubobject_arrow] end namespace HomologicalComplex variable {ι V : Type*} [Category V] {c : ComplexShape ι} section variable [HasZeroMorphisms V] /-- Sends a complex `X` with objects in `V` to the corresponding complex with objects in `Vᵒᵖ`. -/ @[simps] protected def op (X : HomologicalComplex V c) : HomologicalComplex Vᵒᵖ c.symm where X i := op (X.X i) d i j := (X.d j i).op shape i j hij := by simp only; rw [X.shape j i hij, op_zero] d_comp_d' _ _ _ _ _ := by rw [← op_comp, X.d_comp_d, op_zero] /-- Sends a complex `X` with objects in `V` to the corresponding complex with objects in `Vᵒᵖ`. -/ @[simps] protected def opSymm (X : HomologicalComplex V c.symm) : HomologicalComplex Vᵒᵖ c where X i := op (X.X i) d i j := (X.d j i).op shape i j hij := by simp only; rw [X.shape j i hij, op_zero] d_comp_d' _ _ _ _ _ := by rw [← op_comp, X.d_comp_d, op_zero] /-- Sends a complex `X` with objects in `Vᵒᵖ` to the corresponding complex with objects in `V`. -/ @[simps] protected def unop (X : HomologicalComplex Vᵒᵖ c) : HomologicalComplex V c.symm where X i := unop (X.X i) d i j := (X.d j i).unop shape i j hij := by simp only; rw [X.shape j i hij, unop_zero] d_comp_d' _ _ _ _ _ := by rw [← unop_comp, X.d_comp_d, unop_zero] /-- Sends a complex `X` with objects in `Vᵒᵖ` to the corresponding complex with objects in `V`. -/ @[simps] protected def unopSymm (X : HomologicalComplex Vᵒᵖ c.symm) : HomologicalComplex V c where X i := unop (X.X i) d i j := (X.d j i).unop shape i j hij := by simp only; rw [X.shape j i hij, unop_zero] d_comp_d' _ _ _ _ _ := by rw [← unop_comp, X.d_comp_d, unop_zero] variable (V c) /-- Auxiliary definition for `opEquivalence`. -/ @[simps] def opFunctor : (HomologicalComplex V c)ᵒᵖ ⥤ HomologicalComplex Vᵒᵖ c.symm where obj X := (unop X).op map f := { f := fun i => (f.unop.f i).op comm' := fun i j _ => by simp only [op_d, ← op_comp, f.unop.comm] } /-- Auxiliary definition for `opEquivalence`. -/ @[simps] def opInverse : HomologicalComplex Vᵒᵖ c.symm ⥤ (HomologicalComplex V c)ᵒᵖ where obj X := op X.unopSymm map f := Quiver.Hom.op { f := fun i => (f.f i).unop comm' := fun i j _ => by simp only [unopSymm_d, ← unop_comp, f.comm] } /-- Auxiliary definition for `opEquivalence`. -/ def opUnitIso : 𝟭 (HomologicalComplex V c)ᵒᵖ ≅ opFunctor V c ⋙ opInverse V c := NatIso.ofComponents (fun X => (HomologicalComplex.Hom.isoOfComponents (fun i => Iso.refl _) fun i j _ => by simp only [Iso.refl_hom, Category.id_comp, unopSymm_d, op_d, Quiver.Hom.unop_op, Category.comp_id] : (Opposite.unop X).op.unopSymm ≅ unop X).op) (by intro X Y f refine Quiver.Hom.unop_inj ?_ ext x simp only [Quiver.Hom.unop_op, Functor.id_map, Iso.op_hom, Functor.comp_map, unop_comp, comp_f, Hom.isoOfComponents_hom_f] erw [Category.id_comp, Category.comp_id (f.unop.f x)]) /-- Auxiliary definition for `opEquivalence`. -/ def opCounitIso : opInverse V c ⋙ opFunctor V c ≅ 𝟭 (HomologicalComplex Vᵒᵖ c.symm) := NatIso.ofComponents fun X => HomologicalComplex.Hom.isoOfComponents fun i => Iso.refl _ /-- Given a category of complexes with objects in `V`, there is a natural equivalence between its opposite category and a category of complexes with objects in `Vᵒᵖ`. -/ @[simps] def opEquivalence : (HomologicalComplex V c)ᵒᵖ ≌ HomologicalComplex Vᵒᵖ c.symm where functor := opFunctor V c inverse := opInverse V c unitIso := opUnitIso V c counitIso := opCounitIso V c functor_unitIso_comp X := by ext simp only [opUnitIso, opCounitIso, NatIso.ofComponents_hom_app, Iso.op_hom, comp_f, opFunctor_map_f, Quiver.Hom.unop_op, Hom.isoOfComponents_hom_f] exact Category.comp_id _ /-- Auxiliary definition for `unopEquivalence`. -/ @[simps] def unopFunctor : (HomologicalComplex Vᵒᵖ c)ᵒᵖ ⥤ HomologicalComplex V c.symm where obj X := (unop X).unop map f := { f := fun i => (f.unop.f i).unop comm' := fun i j _ => by simp only [unop_d, ← unop_comp, f.unop.comm] } /-- Auxiliary definition for `unopEquivalence`. -/ @[simps] def unopInverse : HomologicalComplex V c.symm ⥤ (HomologicalComplex Vᵒᵖ c)ᵒᵖ where obj X := op X.opSymm map f := Quiver.Hom.op { f := fun i => (f.f i).op comm' := fun i j _ => by simp only [opSymm_d, ← op_comp, f.comm] } /-- Auxiliary definition for `unopEquivalence`. -/ def unopUnitIso : 𝟭 (HomologicalComplex Vᵒᵖ c)ᵒᵖ ≅ unopFunctor V c ⋙ unopInverse V c := NatIso.ofComponents (fun X => (HomologicalComplex.Hom.isoOfComponents (fun i => Iso.refl _) fun i j _ => by simp only [Iso.refl_hom, Category.id_comp, unopSymm_d, op_d, Quiver.Hom.unop_op, Category.comp_id] : (Opposite.unop X).op.unopSymm ≅ unop X).op) (by intro X Y f refine Quiver.Hom.unop_inj ?_ ext x simp only [Quiver.Hom.unop_op, Functor.id_map, Iso.op_hom, Functor.comp_map, unop_comp, comp_f, Hom.isoOfComponents_hom_f] erw [Category.id_comp, Category.comp_id (f.unop.f x)]) /-- Auxiliary definition for `unopEquivalence`. -/ def unopCounitIso : unopInverse V c ⋙ unopFunctor V c ≅ 𝟭 (HomologicalComplex V c.symm) := NatIso.ofComponents fun X => HomologicalComplex.Hom.isoOfComponents fun i => Iso.refl _ /-- Given a category of complexes with objects in `Vᵒᵖ`, there is a natural equivalence between its opposite category and a category of complexes with objects in `V`. -/ @[simps] def unopEquivalence : (HomologicalComplex Vᵒᵖ c)ᵒᵖ ≌ HomologicalComplex V c.symm where functor := unopFunctor V c inverse := unopInverse V c unitIso := unopUnitIso V c counitIso := unopCounitIso V c functor_unitIso_comp X := by ext simp only [opUnitIso, opCounitIso, NatIso.ofComponents_hom_app, Iso.op_hom, comp_f, opFunctor_map_f, Quiver.Hom.unop_op, Hom.isoOfComponents_hom_f] exact Category.comp_id _ instance (K : HomologicalComplex V c) (i : ι) [K.HasHomology i] : K.op.HasHomology i := (inferInstance : (K.sc i).op.HasHomology) instance (K : HomologicalComplex Vᵒᵖ c) (i : ι) [K.HasHomology i] : K.unop.HasHomology i := (inferInstance : (K.sc i).unop.HasHomology) variable {V c} /-- If `K` is a homological complex, then the homology of `K.op` identifies to the opposite of the homology of `K`. -/ def homologyOp (K : HomologicalComplex V c) (i : ι) [K.HasHomology i] : K.op.homology i ≅ op (K.homology i) := (K.sc i).homologyOpIso /-- If `K` is a homological complex in the opposite category, then the homology of `K.unop` identifies to the opposite of the homology of `K`. -/ def homologyUnop (K : HomologicalComplex Vᵒᵖ c) (i : ι) [K.HasHomology i] : K.unop.homology i ≅ unop (K.homology i) := (K.unop.homologyOp i).unop end section variable [Preadditive V] instance opFunctor_additive : (@opFunctor ι V _ c _).Additive where instance unopFunctor_additive : (@unopFunctor ι V _ c _).Additive where end end HomologicalComplex
Algebra\Homology\QuasiIso.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Joël Riou -/ import Mathlib.Algebra.Homology.Homotopy /-! # Quasi-isomorphisms A chain map is a quasi-isomorphism if it induces isomorphisms on homology. -/ open CategoryTheory Limits universe v u open HomologicalComplex section variable {ι : Type*} {C : Type u} [Category.{v} C] [HasZeroMorphisms C] {c : ComplexShape ι} {K L M K' L' : HomologicalComplex C c} /-- A morphism of homological complexes `f : K ⟶ L` is a quasi-isomorphism in degree `i` when it induces a quasi-isomorphism of short complexes `K.sc i ⟶ L.sc i`. -/ class QuasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : Prop where quasiIso : ShortComplex.QuasiIso ((shortComplexFunctor C c i).map f) lemma quasiIsoAt_iff (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i ↔ ShortComplex.QuasiIso ((shortComplexFunctor C c i).map f) := by constructor · intro h exact h.quasiIso · intro h exact ⟨h⟩ instance quasiIsoAt_of_isIso (f : K ⟶ L) [IsIso f] (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i := by rw [quasiIsoAt_iff] infer_instance lemma quasiIsoAt_iff' (f : K ⟶ L) (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) [K.HasHomology j] [L.HasHomology j] [(K.sc' i j k).HasHomology] [(L.sc' i j k).HasHomology] : QuasiIsoAt f j ↔ ShortComplex.QuasiIso ((shortComplexFunctor' C c i j k).map f) := by rw [quasiIsoAt_iff] exact ShortComplex.quasiIso_iff_of_arrow_mk_iso _ _ (Arrow.isoOfNatIso (natIsoSc' C c i j k hi hk) (Arrow.mk f)) lemma quasiIsoAt_iff_isIso_homologyMap (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i ↔ IsIso (homologyMap f i) := by rw [quasiIsoAt_iff, ShortComplex.quasiIso_iff] rfl lemma quasiIsoAt_iff_exactAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] (hK : K.ExactAt i) : QuasiIsoAt f i ↔ L.ExactAt i := by simp only [quasiIsoAt_iff, ShortComplex.quasiIso_iff, exactAt_iff, ShortComplex.exact_iff_isZero_homology] at hK ⊢ constructor · intro h exact IsZero.of_iso hK (@asIso _ _ _ _ _ h).symm · intro hL exact ⟨⟨0, IsZero.eq_of_src hK _ _, IsZero.eq_of_tgt hL _ _⟩⟩ lemma quasiIsoAt_iff_exactAt' (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] (hL : L.ExactAt i) : QuasiIsoAt f i ↔ K.ExactAt i := by simp only [quasiIsoAt_iff, ShortComplex.quasiIso_iff, exactAt_iff, ShortComplex.exact_iff_isZero_homology] at hL ⊢ constructor · intro h exact IsZero.of_iso hL (@asIso _ _ _ _ _ h) · intro hK exact ⟨⟨0, IsZero.eq_of_src hK _ _, IsZero.eq_of_tgt hL _ _⟩⟩ instance (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [hf : QuasiIsoAt f i] : IsIso (homologyMap f i) := by simpa only [quasiIsoAt_iff, ShortComplex.quasiIso_iff] using hf /-- The isomorphism `K.homology i ≅ L.homology i` induced by a morphism `f : K ⟶ L` such that `[QuasiIsoAt f i]` holds. -/ @[simps! hom] noncomputable def isoOfQuasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : K.homology i ≅ L.homology i := asIso (homologyMap f i) @[reassoc (attr := simp)] lemma isoOfQuasiIsoAt_hom_inv_id (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : homologyMap f i ≫ (isoOfQuasiIsoAt f i).inv = 𝟙 _ := (isoOfQuasiIsoAt f i).hom_inv_id @[reassoc (attr := simp)] lemma isoOfQuasiIsoAt_inv_hom_id (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : (isoOfQuasiIsoAt f i).inv ≫ homologyMap f i = 𝟙 _ := (isoOfQuasiIsoAt f i).inv_hom_id lemma CochainComplex.quasiIsoAt₀_iff {K L : CochainComplex C ℕ} (f : K ⟶ L) [K.HasHomology 0] [L.HasHomology 0] [(K.sc' 0 0 1).HasHomology] [(L.sc' 0 0 1).HasHomology] : QuasiIsoAt f 0 ↔ ShortComplex.QuasiIso ((HomologicalComplex.shortComplexFunctor' C _ 0 0 1).map f) := quasiIsoAt_iff' _ _ _ _ (by simp) (by simp) lemma ChainComplex.quasiIsoAt₀_iff {K L : ChainComplex C ℕ} (f : K ⟶ L) [K.HasHomology 0] [L.HasHomology 0] [(K.sc' 1 0 0).HasHomology] [(L.sc' 1 0 0).HasHomology] : QuasiIsoAt f 0 ↔ ShortComplex.QuasiIso ((HomologicalComplex.shortComplexFunctor' C _ 1 0 0).map f) := quasiIsoAt_iff' _ _ _ _ (by simp) (by simp) /-- A morphism of homological complexes `f : K ⟶ L` is a quasi-isomorphism when it is so in every degree, i.e. when the induced maps `homologyMap f i : K.homology i ⟶ L.homology i` are all isomorphisms (see `quasiIso_iff` and `quasiIsoAt_iff_isIso_homologyMap`). -/ class QuasiIso (f : K ⟶ L) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] : Prop where quasiIsoAt : ∀ i, QuasiIsoAt f i := by infer_instance lemma quasiIso_iff (f : K ⟶ L) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] : QuasiIso f ↔ ∀ i, QuasiIsoAt f i := ⟨fun h => h.quasiIsoAt, fun h => ⟨h⟩⟩ attribute [instance] QuasiIso.quasiIsoAt instance quasiIso_of_isIso (f : K ⟶ L) [IsIso f] [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] : QuasiIso f where instance quasiIsoAt_comp (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i] [L.HasHomology i] [M.HasHomology i] [hφ : QuasiIsoAt φ i] [hφ' : QuasiIsoAt φ' i] : QuasiIsoAt (φ ≫ φ') i := by rw [quasiIsoAt_iff] at hφ hφ' ⊢ rw [Functor.map_comp] exact ShortComplex.quasiIso_comp _ _ instance quasiIso_comp (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, M.HasHomology i] [hφ : QuasiIso φ] [hφ' : QuasiIso φ'] : QuasiIso (φ ≫ φ') where lemma quasiIsoAt_of_comp_left (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i] [L.HasHomology i] [M.HasHomology i] [hφ : QuasiIsoAt φ i] [hφφ' : QuasiIsoAt (φ ≫ φ') i] : QuasiIsoAt φ' i := by rw [quasiIsoAt_iff_isIso_homologyMap] at hφ hφφ' ⊢ rw [homologyMap_comp] at hφφ' exact IsIso.of_isIso_comp_left (homologyMap φ i) (homologyMap φ' i) lemma quasiIsoAt_iff_comp_left (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i] [L.HasHomology i] [M.HasHomology i] [hφ : QuasiIsoAt φ i] : QuasiIsoAt (φ ≫ φ') i ↔ QuasiIsoAt φ' i := by constructor · intro exact quasiIsoAt_of_comp_left φ φ' i · intro infer_instance lemma quasiIso_iff_comp_left (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, M.HasHomology i] [hφ : QuasiIso φ] : QuasiIso (φ ≫ φ') ↔ QuasiIso φ' := by simp only [quasiIso_iff, quasiIsoAt_iff_comp_left φ φ'] lemma quasiIso_of_comp_left (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, M.HasHomology i] [hφ : QuasiIso φ] [hφφ' : QuasiIso (φ ≫ φ')] : QuasiIso φ' := by rw [← quasiIso_iff_comp_left φ φ'] infer_instance lemma quasiIsoAt_of_comp_right (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i] [L.HasHomology i] [M.HasHomology i] [hφ' : QuasiIsoAt φ' i] [hφφ' : QuasiIsoAt (φ ≫ φ') i] : QuasiIsoAt φ i := by rw [quasiIsoAt_iff_isIso_homologyMap] at hφ' hφφ' ⊢ rw [homologyMap_comp] at hφφ' exact IsIso.of_isIso_comp_right (homologyMap φ i) (homologyMap φ' i) lemma quasiIsoAt_iff_comp_right (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i] [L.HasHomology i] [M.HasHomology i] [hφ' : QuasiIsoAt φ' i] : QuasiIsoAt (φ ≫ φ') i ↔ QuasiIsoAt φ i := by constructor · intro exact quasiIsoAt_of_comp_right φ φ' i · intro infer_instance lemma quasiIso_iff_comp_right (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, M.HasHomology i] [hφ' : QuasiIso φ'] : QuasiIso (φ ≫ φ') ↔ QuasiIso φ := by simp only [quasiIso_iff, quasiIsoAt_iff_comp_right φ φ'] lemma quasiIso_of_comp_right (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, M.HasHomology i] [hφ : QuasiIso φ'] [hφφ' : QuasiIso (φ ≫ φ')] : QuasiIso φ := by rw [← quasiIso_iff_comp_right φ φ'] infer_instance lemma quasiIso_iff_of_arrow_mk_iso (φ : K ⟶ L) (φ' : K' ⟶ L') (e : Arrow.mk φ ≅ Arrow.mk φ') [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, K'.HasHomology i] [∀ i, L'.HasHomology i] : QuasiIso φ ↔ QuasiIso φ' := by rw [← quasiIso_iff_comp_left (show K' ⟶ K from e.inv.left) φ, ← quasiIso_iff_comp_right φ' (show L' ⟶ L from e.inv.right)] erw [Arrow.w e.inv] rfl lemma quasiIso_of_arrow_mk_iso (φ : K ⟶ L) (φ' : K' ⟶ L') (e : Arrow.mk φ ≅ Arrow.mk φ') [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, K'.HasHomology i] [∀ i, L'.HasHomology i] [hφ : QuasiIso φ] : QuasiIso φ' := by simpa only [← quasiIso_iff_of_arrow_mk_iso φ φ' e] namespace HomologicalComplex section PreservesHomology variable {C₁ C₂ : Type*} [Category C₁] [Category C₂] [Preadditive C₁] [Preadditive C₂] {K L : HomologicalComplex C₁ c} (φ : K ⟶ L) (F : C₁ ⥤ C₂) [F.Additive] [F.PreservesHomology] section variable (i : ι) [K.HasHomology i] [L.HasHomology i] [((F.mapHomologicalComplex c).obj K).HasHomology i] [((F.mapHomologicalComplex c).obj L).HasHomology i] instance quasiIsoAt_map_of_preservesHomology [hφ : QuasiIsoAt φ i] : QuasiIsoAt ((F.mapHomologicalComplex c).map φ) i := by rw [quasiIsoAt_iff] at hφ ⊢ exact ShortComplex.quasiIso_map_of_preservesLeftHomology F ((shortComplexFunctor C₁ c i).map φ) lemma quasiIsoAt_map_iff_of_preservesHomology [F.ReflectsIsomorphisms] : QuasiIsoAt ((F.mapHomologicalComplex c).map φ) i ↔ QuasiIsoAt φ i := by simp only [quasiIsoAt_iff] exact ShortComplex.quasiIso_map_iff_of_preservesLeftHomology F ((shortComplexFunctor C₁ c i).map φ) end section variable [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, ((F.mapHomologicalComplex c).obj K).HasHomology i] [∀ i, ((F.mapHomologicalComplex c).obj L).HasHomology i] instance quasiIso_map_of_preservesHomology [hφ : QuasiIso φ] : QuasiIso ((F.mapHomologicalComplex c).map φ) where lemma quasiIso_map_iff_of_preservesHomology [F.ReflectsIsomorphisms] : QuasiIso ((F.mapHomologicalComplex c).map φ) ↔ QuasiIso φ := by simp only [quasiIso_iff, quasiIsoAt_map_iff_of_preservesHomology φ F] end end PreservesHomology variable (C c) /-- The morphism property on `HomologicalComplex C c` given by quasi-isomorphisms. -/ def quasiIso [CategoryWithHomology C] : MorphismProperty (HomologicalComplex C c) := fun _ _ f => QuasiIso f variable {C c} @[simp] lemma mem_quasiIso_iff [CategoryWithHomology C] (f : K ⟶ L) : quasiIso C c f ↔ QuasiIso f := by rfl end HomologicalComplex end section variable {ι : Type*} {C : Type u} [Category.{v} C] [Preadditive C] {c : ComplexShape ι} {K L : HomologicalComplex C c} (e : HomotopyEquiv K L) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] instance : QuasiIso e.hom where quasiIsoAt n := by classical rw [quasiIsoAt_iff_isIso_homologyMap] exact (e.toHomologyIso n).isIso_hom instance : QuasiIso e.inv := (inferInstance : QuasiIso e.symm.hom) variable (C c) lemma homotopyEquivalences_le_quasiIso [CategoryWithHomology C] : homotopyEquivalences C c ≤ quasiIso C c := by rintro K L _ ⟨e, rfl⟩ simp only [HomologicalComplex.mem_quasiIso_iff] infer_instance end
Algebra\Homology\Refinements.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Abelian.Refinements import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex /-! # Refinements This file contains lemmas about "refinements" that are specific to the study of the homology of `HomologicalComplex`. General lemmas about refinements and the case of `ShortComplex` appear in the file `CategoryTheory.Abelian.Refinements`. -/ open CategoryTheory variable {C ι : Type*} [Category C] [Abelian C] {c : ComplexShape ι} (K : HomologicalComplex C c) namespace HomologicalComplex lemma eq_liftCycles_homologyπ_up_to_refinements {A : C} {i : ι} (γ : A ⟶ K.homology i) (j : ι) (hj : c.next i = j) : ∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (z : A' ⟶ K.X i) (hz : z ≫ K.d i j = 0), π ≫ γ = K.liftCycles z j hj hz ≫ K.homologyπ i := by subst hj exact (K.sc i).eq_liftCycles_homologyπ_up_to_refinements γ end HomologicalComplex
Algebra\Homology\Single.lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Homology.HomologicalComplex /-! # Homological complexes supported in a single degree We define `single V j c : V ⥤ HomologicalComplex V c`, which constructs complexes in `V` of shape `c`, supported in degree `j`. In `ChainComplex.toSingle₀Equiv` we characterize chain maps to an `ℕ`-indexed complex concentrated in degree 0; they are equivalent to `{ f : C.X 0 ⟶ X // C.d 1 0 ≫ f = 0 }`. (This is useful translating between a projective resolution and an augmented exact complex of projectives.) -/ open CategoryTheory Category Limits ZeroObject universe v u variable (V : Type u) [Category.{v} V] [HasZeroMorphisms V] [HasZeroObject V] namespace HomologicalComplex variable {ι : Type*} [DecidableEq ι] (c : ComplexShape ι) /-- The functor `V ⥤ HomologicalComplex V c` creating a chain complex supported in a single degree. -/ noncomputable def single (j : ι) : V ⥤ HomologicalComplex V c where obj A := { X := fun i => if i = j then A else 0 d := fun i j => 0 } map f := { f := fun i => if h : i = j then eqToHom (by dsimp; rw [if_pos h]) ≫ f ≫ eqToHom (by dsimp; rw [if_pos h]) else 0 } map_id A := by ext dsimp split_ifs with h · subst h simp · #adaptation_note /-- after nightly-2024-03-07, the previous sensible proof `rw [if_neg h]; simp` fails with "motive not type correct". The following is horrible. -/ convert (id_zero (C := V)).symm all_goals simp [if_neg h] map_comp f g := by ext dsimp split_ifs with h · subst h simp · simp variable {V} @[simp] lemma single_obj_X_self (j : ι) (A : V) : ((single V c j).obj A).X j = A := if_pos rfl lemma isZero_single_obj_X (j : ι) (A : V) (i : ι) (hi : i ≠ j) : IsZero (((single V c j).obj A).X i) := by dsimp [single] rw [if_neg hi] exact Limits.isZero_zero V /-- The object in degree `i` of `(single V c h).obj A` is just `A` when `i = j`. -/ noncomputable def singleObjXIsoOfEq (j : ι) (A : V) (i : ι) (hi : i = j) : ((single V c j).obj A).X i ≅ A := eqToIso (by subst hi; simp [single]) /-- The object in degree `j` of `(single V c h).obj A` is just `A`. -/ noncomputable def singleObjXSelf (j : ι) (A : V) : ((single V c j).obj A).X j ≅ A := singleObjXIsoOfEq c j A j rfl @[simp] lemma single_obj_d (j : ι) (A : V) (k l : ι) : ((single V c j).obj A).d k l = 0 := rfl @[reassoc] theorem single_map_f_self (j : ι) {A B : V} (f : A ⟶ B) : ((single V c j).map f).f j = (singleObjXSelf c j A).hom ≫ f ≫ (singleObjXSelf c j B).inv := by dsimp [single] rw [dif_pos rfl] rfl variable (V) /-- The natural isomorphism `single V c j ⋙ eval V c j ≅ 𝟭 V`. -/ @[simps!] noncomputable def singleCompEvalIsoSelf (j : ι) : single V c j ⋙ eval V c j ≅ 𝟭 V := NatIso.ofComponents (singleObjXSelf c j) (fun {A B} f => by simp [single_map_f_self]) lemma isZero_single_comp_eval (j i : ι) (hi : i ≠ j) : IsZero (single V c j ⋙ eval V c i) := Functor.isZero _ (fun _ ↦ isZero_single_obj_X c _ _ _ hi) variable {V c} @[ext] lemma from_single_hom_ext {K : HomologicalComplex V c} {j : ι} {A : V} {f g : (single V c j).obj A ⟶ K} (hfg : f.f j = g.f j) : f = g := by ext i by_cases h : i = j · subst h exact hfg · apply (isZero_single_obj_X c j A i h).eq_of_src @[ext] lemma to_single_hom_ext {K : HomologicalComplex V c} {j : ι} {A : V} {f g : K ⟶ (single V c j).obj A} (hfg : f.f j = g.f j) : f = g := by ext i by_cases h : i = j · subst h exact hfg · apply (isZero_single_obj_X c j A i h).eq_of_tgt instance (j : ι) : (single V c j).Faithful where map_injective {A B f g} w := by rw [← cancel_mono (singleObjXSelf c j B).inv, ← cancel_epi (singleObjXSelf c j A).hom, ← single_map_f_self, ← single_map_f_self, w] instance (j : ι) : (single V c j).Full where map_surjective {A B} f := ⟨(singleObjXSelf c j A).inv ≫ f.f j ≫ (singleObjXSelf c j B).hom, by ext simp [single_map_f_self]⟩ /-- Constructor for morphisms to a single homological complex. -/ noncomputable def mkHomToSingle {K : HomologicalComplex V c} {j : ι} {A : V} (φ : K.X j ⟶ A) (hφ : ∀ (i : ι), c.Rel i j → K.d i j ≫ φ = 0) : K ⟶ (single V c j).obj A where f i := if hi : i = j then (K.XIsoOfEq hi).hom ≫ φ ≫ (singleObjXIsoOfEq c j A i hi).inv else 0 comm' i k hik := by dsimp rw [comp_zero] split_ifs with hk · subst hk simp only [XIsoOfEq_rfl, Iso.refl_hom, id_comp, reassoc_of% hφ i hik, zero_comp] · apply (isZero_single_obj_X c j A k hk).eq_of_tgt @[simp] lemma mkHomToSingle_f {K : HomologicalComplex V c} {j : ι} {A : V} (φ : K.X j ⟶ A) (hφ : ∀ (i : ι), c.Rel i j → K.d i j ≫ φ = 0) : (mkHomToSingle φ hφ).f j = φ ≫ (singleObjXSelf c j A).inv := by dsimp [mkHomToSingle] rw [dif_pos rfl, id_comp] rfl /-- Constructor for morphisms from a single homological complex. -/ noncomputable def mkHomFromSingle {K : HomologicalComplex V c} {j : ι} {A : V} (φ : A ⟶ K.X j) (hφ : ∀ (k : ι), c.Rel j k → φ ≫ K.d j k = 0) : (single V c j).obj A ⟶ K where f i := if hi : i = j then (singleObjXIsoOfEq c j A i hi).hom ≫ φ ≫ (K.XIsoOfEq hi).inv else 0 comm' i k hik := by dsimp rw [zero_comp] split_ifs with hi · subst hi simp only [XIsoOfEq_rfl, Iso.refl_inv, comp_id, assoc, hφ k hik, comp_zero] · apply (isZero_single_obj_X c j A i hi).eq_of_src @[simp] lemma mkHomFromSingle_f {K : HomologicalComplex V c} {j : ι} {A : V} (φ : A ⟶ K.X j) (hφ : ∀ (k : ι), c.Rel j k → φ ≫ K.d j k = 0) : (mkHomFromSingle φ hφ).f j = (singleObjXSelf c j A).hom ≫ φ := by dsimp [mkHomFromSingle] rw [dif_pos rfl, comp_id] rfl instance (j : ι) : (single V c j).PreservesZeroMorphisms where end HomologicalComplex namespace ChainComplex /-- The functor `V ⥤ ChainComplex V ℕ` creating a chain complex supported in degree zero. -/ noncomputable abbrev single₀ : V ⥤ ChainComplex V ℕ := HomologicalComplex.single V (ComplexShape.down ℕ) 0 variable {V} @[simp] lemma single₀_obj_zero (A : V) : ((single₀ V).obj A).X 0 = A := rfl @[simp] lemma single₀_map_f_zero {A B : V} (f : A ⟶ B) : ((single₀ V).map f).f 0 = f := by rw [HomologicalComplex.single_map_f_self] dsimp [HomologicalComplex.singleObjXSelf, HomologicalComplex.singleObjXIsoOfEq] erw [comp_id, id_comp] @[simp] lemma single₀ObjXSelf (X : V) : HomologicalComplex.singleObjXSelf (ComplexShape.down ℕ) 0 X = Iso.refl _ := rfl /-- Morphisms from an `ℕ`-indexed chain complex `C` to a single object chain complex with `X` concentrated in degree 0 are the same as morphisms `f : C.X 0 ⟶ X` such that `C.d 1 0 ≫ f = 0`. -/ @[simps apply_coe] noncomputable def toSingle₀Equiv (C : ChainComplex V ℕ) (X : V) : (C ⟶ (single₀ V).obj X) ≃ { f : C.X 0 ⟶ X // C.d 1 0 ≫ f = 0 } where toFun φ := ⟨φ.f 0, by rw [← φ.comm 1 0, HomologicalComplex.single_obj_d, comp_zero]⟩ invFun f := HomologicalComplex.mkHomToSingle f.1 (fun i hi => by obtain rfl : i = 1 := by simpa using hi.symm exact f.2) left_inv φ := by aesop_cat right_inv f := by aesop_cat @[simp] lemma toSingle₀Equiv_symm_apply_f_zero {C : ChainComplex V ℕ} {X : V} (f : C.X 0 ⟶ X) (hf : C.d 1 0 ≫ f = 0) : ((toSingle₀Equiv C X).symm ⟨f, hf⟩).f 0 = f := by simp [toSingle₀Equiv] /-- Morphisms from a single object chain complex with `X` concentrated in degree 0 to an `ℕ`-indexed chain complex `C` are the same as morphisms `f : X → C.X 0`. -/ @[simps apply] noncomputable def fromSingle₀Equiv (C : ChainComplex V ℕ) (X : V) : ((single₀ V).obj X ⟶ C) ≃ (X ⟶ C.X 0) where toFun f := f.f 0 invFun f := HomologicalComplex.mkHomFromSingle f (fun i hi => by simp at hi) left_inv := by aesop_cat right_inv := by aesop_cat @[simp] lemma fromSingle₀Equiv_symm_apply_f_zero {C : ChainComplex V ℕ} {X : V} (f : X ⟶ C.X 0) : ((fromSingle₀Equiv C X).symm f).f 0 = f := by simp [fromSingle₀Equiv] @[simp] lemma fromSingle₀Equiv_symm_apply_f_succ {C : ChainComplex V ℕ} {X : V} (f : X ⟶ C.X 0) (n : ℕ) : ((fromSingle₀Equiv C X).symm f).f (n + 1) = 0 := rfl end ChainComplex namespace CochainComplex /-- The functor `V ⥤ CochainComplex V ℕ` creating a cochain complex supported in degree zero. -/ noncomputable abbrev single₀ : V ⥤ CochainComplex V ℕ := HomologicalComplex.single V (ComplexShape.up ℕ) 0 variable {V} @[simp] lemma single₀_obj_zero (A : V) : ((single₀ V).obj A).X 0 = A := rfl @[simp] lemma single₀_map_f_zero {A B : V} (f : A ⟶ B) : ((single₀ V).map f).f 0 = f := by rw [HomologicalComplex.single_map_f_self] dsimp [HomologicalComplex.singleObjXSelf, HomologicalComplex.singleObjXIsoOfEq] erw [comp_id, id_comp] @[simp] lemma single₀ObjXSelf (X : V) : HomologicalComplex.singleObjXSelf (ComplexShape.up ℕ) 0 X = Iso.refl _ := rfl /-- Morphisms from a single object cochain complex with `X` concentrated in degree 0 to an `ℕ`-indexed cochain complex `C` are the same as morphisms `f : X ⟶ C.X 0` such that `f ≫ C.d 0 1 = 0`. -/ @[simps apply_coe] noncomputable def fromSingle₀Equiv (C : CochainComplex V ℕ) (X : V) : ((single₀ V).obj X ⟶ C) ≃ { f : X ⟶ C.X 0 // f ≫ C.d 0 1 = 0 } where toFun φ := ⟨φ.f 0, by rw [φ.comm 0 1, HomologicalComplex.single_obj_d, zero_comp]⟩ invFun f := HomologicalComplex.mkHomFromSingle f.1 (fun i hi => by obtain rfl : i = 1 := by simpa using hi.symm exact f.2) left_inv φ := by aesop_cat right_inv := by aesop_cat @[simp] lemma fromSingle₀Equiv_symm_apply_f_zero {C : CochainComplex V ℕ} {X : V} (f : X ⟶ C.X 0) (hf : f ≫ C.d 0 1 = 0) : ((fromSingle₀Equiv C X).symm ⟨f, hf⟩).f 0 = f := by simp [fromSingle₀Equiv] /-- Morphisms to a single object cochain complex with `X` concentrated in degree 0 to an `ℕ`-indexed cochain complex `C` are the same as morphisms `f : C.X 0 ⟶ X`. -/ @[simps apply] noncomputable def toSingle₀Equiv (C : CochainComplex V ℕ) (X : V) : (C ⟶ (single₀ V).obj X) ≃ (C.X 0 ⟶ X) where toFun f := f.f 0 invFun f := HomologicalComplex.mkHomToSingle f (fun i hi => by simp at hi) left_inv := by aesop_cat right_inv := by aesop_cat @[simp] lemma toSingle₀Equiv_symm_apply_f_zero {C : CochainComplex V ℕ} {X : V} (f : C.X 0 ⟶ X) : ((toSingle₀Equiv C X).symm f).f 0 = f := by simp [toSingle₀Equiv] @[simp] lemma toSingle₀Equiv_symm_apply_f_succ {C : CochainComplex V ℕ} {X : V} (f : C.X 0 ⟶ X) (n : ℕ) : ((toSingle₀Equiv C X).symm f).f (n + 1) = 0 := by rfl end CochainComplex
Algebra\Homology\SingleHomology.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Single import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex /-! # The homology of single complexes The main definition in this file is `HomologicalComplex.homologyFunctorSingleIso` which is a natural isomorphism `single C c j ⋙ homologyFunctor C c j ≅ 𝟭 C`. -/ universe v u open CategoryTheory Category Limits ZeroObject variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasZeroObject C] {ι : Type*} [DecidableEq ι] (c : ComplexShape ι) (j : ι) namespace HomologicalComplex variable (A : C) instance (i : ι) : ((single C c j).obj A).HasHomology i := by apply ShortComplex.hasHomology_of_zeros lemma exactAt_single_obj (A : C) (i : ι) (hi : i ≠ j) : ExactAt ((single C c j).obj A) i := ShortComplex.exact_of_isZero_X₂ _ (isZero_single_obj_X c _ _ _ hi) lemma isZero_single_obj_homology (A : C) (i : ι) (hi : i ≠ j) : IsZero (((single C c j).obj A).homology i) := by simpa only [← exactAt_iff_isZero_homology] using exactAt_single_obj c j A i hi /-- The canonical isomorphism `((single C c j).obj A).cycles j ≅ A` -/ noncomputable def singleObjCyclesSelfIso : ((single C c j).obj A).cycles j ≅ A := ((single C c j).obj A).iCyclesIso j _ rfl rfl ≪≫ singleObjXSelf c j A @[reassoc] lemma singleObjCyclesSelfIso_hom : (singleObjCyclesSelfIso c j A).hom = ((single C c j).obj A).iCycles j ≫ (singleObjXSelf c j A).hom := rfl /-- The canonical isomorphism `((single C c j).obj A).opcycles j ≅ A` -/ noncomputable def singleObjOpcyclesSelfIso : A ≅ ((single C c j).obj A).opcycles j := (singleObjXSelf c j A).symm ≪≫ ((single C c j).obj A).pOpcyclesIso _ j rfl rfl @[reassoc] lemma singleObjOpcyclesSelfIso_hom : (singleObjOpcyclesSelfIso c j A).hom = (singleObjXSelf c j A).inv ≫ ((single C c j).obj A).pOpcycles j := rfl /-- The canonical isomorphism `((single C c j).obj A).homology j ≅ A` -/ noncomputable def singleObjHomologySelfIso : ((single C c j).obj A).homology j ≅ A := (((single C c j).obj A).isoHomologyπ _ j rfl rfl).symm ≪≫ singleObjCyclesSelfIso c j A @[reassoc (attr := simp)] lemma singleObjCyclesSelfIso_inv_iCycles : (singleObjCyclesSelfIso _ _ _).inv ≫ ((single C c j).obj A).iCycles j = (singleObjXSelf c j A).inv := by simp [singleObjCyclesSelfIso] @[reassoc (attr := simp)] lemma homologyπ_singleObjHomologySelfIso_hom : ((single C c j).obj A).homologyπ j ≫ (singleObjHomologySelfIso _ _ _).hom = (singleObjCyclesSelfIso _ _ _).hom := by simp [singleObjCyclesSelfIso, singleObjHomologySelfIso] @[reassoc (attr := simp)] lemma singleObjHomologySelfIso_hom_singleObjHomologySelfIso_inv : (singleObjCyclesSelfIso c j A).hom ≫ (singleObjHomologySelfIso c j A).inv = ((single C c j).obj A).homologyπ j := by simp only [← cancel_mono (singleObjHomologySelfIso _ _ _).hom, assoc, Iso.inv_hom_id, comp_id, homologyπ_singleObjHomologySelfIso_hom] @[reassoc (attr := simp)] lemma singleObjCyclesSelfIso_hom_singleObjOpcyclesSelfIso_hom : (singleObjCyclesSelfIso c j A).hom ≫ (singleObjOpcyclesSelfIso c j A).hom = ((single C c j).obj A).iCycles j ≫ ((single C c j).obj A).pOpcycles j := by simp [singleObjCyclesSelfIso, singleObjOpcyclesSelfIso] @[reassoc (attr := simp)] lemma singleObjCyclesSelfIso_inv_homologyπ : (singleObjCyclesSelfIso _ _ _).inv ≫ ((single C c j).obj A).homologyπ j = (singleObjHomologySelfIso _ _ _).inv := by simp [singleObjCyclesSelfIso, singleObjHomologySelfIso] @[reassoc (attr := simp)] lemma singleObjHomologySelfIso_inv_homologyι : (singleObjHomologySelfIso _ _ _).inv ≫ ((single C c j).obj A).homologyι j = (singleObjOpcyclesSelfIso _ _ _).hom := by rw [← cancel_epi (singleObjCyclesSelfIso c j A).hom, singleObjHomologySelfIso_hom_singleObjHomologySelfIso_inv_assoc, homology_π_ι, singleObjCyclesSelfIso_hom_singleObjOpcyclesSelfIso_hom] @[reassoc (attr := simp)] lemma homologyι_singleObjOpcyclesSelfIso_inv : ((single C c j).obj A).homologyι j ≫ (singleObjOpcyclesSelfIso _ _ _).inv = (singleObjHomologySelfIso _ _ _).hom := by rw [← cancel_epi (singleObjHomologySelfIso _ _ _).inv, singleObjHomologySelfIso_inv_homologyι_assoc, Iso.hom_inv_id, Iso.inv_hom_id] @[reassoc (attr := simp)] lemma singleObjHomologySelfIso_hom_singleObjOpcyclesSelfIso_hom : (singleObjHomologySelfIso _ _ _).hom ≫ (singleObjOpcyclesSelfIso _ _ _).hom = ((single C c j).obj A).homologyι j := by rw [← cancel_epi (singleObjHomologySelfIso _ _ _).inv, Iso.inv_hom_id_assoc, singleObjHomologySelfIso_inv_homologyι] variable {A} variable {B : C} (f : A ⟶ B) @[reassoc (attr := simp)] lemma singleObjCyclesSelfIso_hom_naturality : cyclesMap ((single C c j).map f) j ≫ (singleObjCyclesSelfIso c j B).hom = (singleObjCyclesSelfIso c j A).hom ≫ f := by rw [← cancel_mono (singleObjCyclesSelfIso c j B).inv, assoc, assoc, Iso.hom_inv_id, comp_id, ← cancel_mono (iCycles _ _)] simp only [cyclesMap_i, singleObjCyclesSelfIso, Iso.trans_hom, iCyclesIso_hom, Iso.trans_inv, assoc, iCyclesIso_inv_hom_id, comp_id, single_map_f_self] @[reassoc (attr := simp)] lemma singleObjCyclesSelfIso_inv_naturality : (singleObjCyclesSelfIso c j A).inv ≫ cyclesMap ((single C c j).map f) j = f ≫ (singleObjCyclesSelfIso c j B).inv := by rw [← cancel_epi (singleObjCyclesSelfIso c j A).hom, Iso.hom_inv_id_assoc, ← singleObjCyclesSelfIso_hom_naturality_assoc, Iso.hom_inv_id, comp_id] @[reassoc (attr := simp)] lemma singleObjHomologySelfIso_hom_naturality : homologyMap ((single C c j).map f) j ≫ (singleObjHomologySelfIso c j B).hom = (singleObjHomologySelfIso c j A).hom ≫ f := by rw [← cancel_epi (((single C c j).obj A).homologyπ j), homologyπ_naturality_assoc, homologyπ_singleObjHomologySelfIso_hom, singleObjCyclesSelfIso_hom_naturality, homologyπ_singleObjHomologySelfIso_hom_assoc] @[reassoc (attr := simp)] lemma singleObjHomologySelfIso_inv_naturality : (singleObjHomologySelfIso c j A).inv ≫ homologyMap ((single C c j).map f) j = f ≫ (singleObjHomologySelfIso c j B).inv := by rw [← cancel_mono (singleObjHomologySelfIso c j B).hom, assoc, assoc, singleObjHomologySelfIso_hom_naturality, Iso.inv_hom_id_assoc, Iso.inv_hom_id, comp_id] @[reassoc (attr := simp)] lemma singleObjOpcyclesSelfIso_hom_naturality : (singleObjOpcyclesSelfIso c j A).hom ≫ opcyclesMap ((single C c j).map f) j = f ≫ (singleObjOpcyclesSelfIso c j B).hom := by rw [← cancel_epi (singleObjCyclesSelfIso c j A).hom, singleObjCyclesSelfIso_hom_singleObjOpcyclesSelfIso_hom_assoc, p_opcyclesMap, single_map_f_self, assoc, assoc, singleObjCyclesSelfIso_hom, singleObjOpcyclesSelfIso_hom, assoc] @[reassoc (attr := simp)] lemma singleObjOpcyclesSelfIso_inv_naturality : opcyclesMap ((single C c j).map f) j ≫ (singleObjOpcyclesSelfIso c j B).inv = (singleObjOpcyclesSelfIso c j A).inv ≫ f := by rw [← cancel_mono (singleObjOpcyclesSelfIso c j B).hom, assoc, assoc, Iso.inv_hom_id, comp_id, ← singleObjOpcyclesSelfIso_hom_naturality, Iso.inv_hom_id_assoc] variable (C) /-- The computation of the homology of single complexes, as a natural isomorphism `single C c j ⋙ homologyFunctor C c j ≅ 𝟭 C`. -/ @[simps!] noncomputable def homologyFunctorSingleIso [CategoryWithHomology C] : single C c j ⋙ homologyFunctor C c j ≅ 𝟭 _ := NatIso.ofComponents (fun A => (singleObjHomologySelfIso c j A)) (fun f => singleObjHomologySelfIso_hom_naturality c j f) end HomologicalComplex open HomologicalComplex lemma ChainComplex.exactAt_succ_single_obj (A : C) (n : ℕ) : ExactAt ((single₀ C).obj A) (n + 1) := exactAt_single_obj _ _ _ _ (by simp) lemma CochainComplex.exactAt_succ_single_obj (A : C) (n : ℕ) : ExactAt ((single₀ C).obj A) (n + 1) := exactAt_single_obj _ _ _ _ (by simp)
Algebra\Homology\TotalComplex.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Linear.Basic import Mathlib.Algebra.Homology.ComplexShapeSigns import Mathlib.Algebra.Homology.HomologicalBicomplex /-! # The total complex of a bicomplex Given a preadditive category `C`, two complex shapes `c₁ : ComplexShape I₁`, `c₂ : ComplexShape I₂`, a bicomplex `K : HomologicalComplex₂ C c₁ c₂`, and a third complex shape `c₁₂ : ComplexShape I₁₂` equipped with `[TotalComplexShape c₁ c₂ c₁₂]`, we construct the total complex `K.total c₁₂ : HomologicalComplex C c₁₂`. In particular, if `c := ComplexShape.up ℤ` and `K : HomologicalComplex₂ c c`, then for any `n : ℤ`, `(K.total c).X n` identifies to the coproduct of the `(K.X p).X q` such that `p + q = n`, and the differential on `(K.total c).X n` is induced by the sum of horizontal differentials `(K.X p).X q ⟶ (K.X (p + 1)).X q` and `(-1) ^ p` times the vertical differentials `(K.X p).X q ⟶ (K.X p).X (q + 1)`. -/ open CategoryTheory Category Limits Preadditive namespace HomologicalComplex₂ variable {C : Type*} [Category C] [Preadditive C] {I₁ I₂ I₁₂ : Type*} {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} (K L M : HomologicalComplex₂ C c₁ c₂) (φ : K ⟶ L) (e : K ≅ L) (ψ : L ⟶ M) (c₁₂ : ComplexShape I₁₂) [DecidableEq I₁₂] [TotalComplexShape c₁ c₂ c₁₂] /-- A bicomplex has a total bicomplex if for any `i₁₂ : I₁₂`, the coproduct of the objects `(K.X i₁).X i₂` such that `ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = i₁₂` exists. -/ abbrev HasTotal := K.toGradedObject.HasMap (ComplexShape.π c₁ c₂ c₁₂) variable {K L} in lemma hasTotal_of_iso [K.HasTotal c₁₂] : L.HasTotal c₁₂ := GradedObject.hasMap_of_iso (GradedObject.isoMk K.toGradedObject L.toGradedObject (fun ⟨i₁, i₂⟩ => (HomologicalComplex.eval _ _ i₁ ⋙ HomologicalComplex.eval _ _ i₂).mapIso e)) _ variable [K.HasTotal c₁₂] section variable (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) /-- The horizontal differential in the total complex on a given summand. -/ noncomputable def d₁ : (K.X i₁).X i₂ ⟶ (K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂)) i₁₂ := ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.d i₁ (c₁.next i₁)).f i₂ ≫ K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨_, i₂⟩ i₁₂) /-- The vertical differential in the total complex on a given summand. -/ noncomputable def d₂ : (K.X i₁).X i₂ ⟶ (K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂)) i₁₂ := ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.X i₁).d i₂ (c₂.next i₂) ≫ K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁, _⟩ i₁₂) lemma d₁_eq_zero (h : ¬ c₁.Rel i₁ (c₁.next i₁)) : K.d₁ c₁₂ i₁ i₂ i₁₂ = 0 := by dsimp [d₁] rw [K.shape_f _ _ h, zero_comp, smul_zero] lemma d₂_eq_zero (h : ¬ c₂.Rel i₂ (c₂.next i₂)) : K.d₂ c₁₂ i₁ i₂ i₁₂ = 0 := by dsimp [d₂] rw [HomologicalComplex.shape _ _ _ h, zero_comp, smul_zero] end namespace totalAux /-! Lemmas in the `totalAux` namespace should be used only in the internals of the construction of the total complex `HomologicalComplex₂.total`. Once that definition is done, similar lemmas shall be restated, but with terms like `K.toGradedObject.ιMapObj` replaced by `K.ιTotal`. This is done in order to prevent API leakage from definitions involving graded objects. -/ lemma d₁_eq' {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (i₁₂ : I₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.d i₁ i₁').f i₂ ≫ K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁', i₂⟩ i₁₂) := by obtain rfl := c₁.next_eq' h rfl lemma d₁_eq {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁', i₂⟩ = i₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.d i₁ i₁').f i₂ ≫ K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁', i₂⟩ i₁₂ h') := by rw [d₁_eq' K c₁₂ h i₂ i₁₂, K.toGradedObject.ιMapObjOrZero_eq] lemma d₂_eq' (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (i₁₂ : I₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.X i₁).d i₂ i₂' ≫ K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁, i₂'⟩ i₁₂) := by obtain rfl := c₂.next_eq' h rfl lemma d₂_eq (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂'⟩ = i₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.X i₁).d i₂ i₂' ≫ K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁, i₂'⟩ i₁₂ h') := by rw [d₂_eq' K c₁₂ i₁ h i₁₂, K.toGradedObject.ιMapObjOrZero_eq] end totalAux lemma d₁_eq_zero' {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁', i₂⟩ ≠ i₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ = 0 := by rw [totalAux.d₁_eq' K c₁₂ h i₂ i₁₂, K.toGradedObject.ιMapObjOrZero_eq_zero, comp_zero, smul_zero] exact h' lemma d₂_eq_zero' (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂'⟩ ≠ i₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ = 0 := by rw [totalAux.d₂_eq' K c₁₂ i₁ h i₁₂, K.toGradedObject.ιMapObjOrZero_eq_zero, comp_zero, smul_zero] exact h' /-- The horizontal differential in the total complex. -/ noncomputable def D₁ (i₁₂ i₁₂' : I₁₂) : K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) i₁₂ ⟶ K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) i₁₂' := GradedObject.descMapObj _ (ComplexShape.π c₁ c₂ c₁₂) (fun ⟨i₁, i₂⟩ _ => K.d₁ c₁₂ i₁ i₂ i₁₂') /-- The vertical differential in the total complex. -/ noncomputable def D₂ (i₁₂ i₁₂' : I₁₂) : K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) i₁₂ ⟶ K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) i₁₂' := GradedObject.descMapObj _ (ComplexShape.π c₁ c₂ c₁₂) (fun ⟨i₁, i₂⟩ _ => K.d₂ c₁₂ i₁ i₂ i₁₂') namespace totalAux @[reassoc (attr := simp)] lemma ιMapObj_D₁ (i₁₂ i₁₂' : I₁₂) (i : I₁ × I₂) (h : ComplexShape.π c₁ c₂ c₁₂ i = i₁₂) : K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) i i₁₂ h ≫ K.D₁ c₁₂ i₁₂ i₁₂' = K.d₁ c₁₂ i.1 i.2 i₁₂' := by simp [D₁] @[reassoc (attr := simp)] lemma ιMapObj_D₂ (i₁₂ i₁₂' : I₁₂) (i : I₁ × I₂) (h : ComplexShape.π c₁ c₂ c₁₂ i = i₁₂) : K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) i i₁₂ h ≫ K.D₂ c₁₂ i₁₂ i₁₂' = K.d₂ c₁₂ i.1 i.2 i₁₂' := by simp [D₂] end totalAux lemma D₁_shape (i₁₂ i₁₂' : I₁₂) (h₁₂ : ¬ c₁₂.Rel i₁₂ i₁₂') : K.D₁ c₁₂ i₁₂ i₁₂' = 0 := by ext ⟨i₁, i₂⟩ h simp only [totalAux.ιMapObj_D₁, comp_zero] by_cases h₁ : c₁.Rel i₁ (c₁.next i₁) · rw [K.d₁_eq_zero' c₁₂ h₁ i₂ i₁₂'] intro h₂ exact h₁₂ (by simpa only [← h, ← h₂] using ComplexShape.rel_π₁ c₂ c₁₂ h₁ i₂) · exact d₁_eq_zero _ _ _ _ _ h₁ lemma D₂_shape (i₁₂ i₁₂' : I₁₂) (h₁₂ : ¬ c₁₂.Rel i₁₂ i₁₂') : K.D₂ c₁₂ i₁₂ i₁₂' = 0 := by ext ⟨i₁, i₂⟩ h simp only [totalAux.ιMapObj_D₂, comp_zero] by_cases h₂ : c₂.Rel i₂ (c₂.next i₂) · rw [K.d₂_eq_zero' c₁₂ i₁ h₂ i₁₂'] intro h₁ exact h₁₂ (by simpa only [← h, ← h₁] using ComplexShape.rel_π₂ c₁ c₁₂ i₁ h₂) · exact d₂_eq_zero _ _ _ _ _ h₂ @[reassoc (attr := simp)] lemma D₁_D₁ (i₁₂ i₁₂' i₁₂'' : I₁₂) : K.D₁ c₁₂ i₁₂ i₁₂' ≫ K.D₁ c₁₂ i₁₂' i₁₂'' = 0 := by by_cases h₁ : c₁₂.Rel i₁₂ i₁₂' · by_cases h₂ : c₁₂.Rel i₁₂' i₁₂'' · ext ⟨i₁, i₂⟩ h simp only [totalAux.ιMapObj_D₁_assoc, comp_zero] by_cases h₃ : c₁.Rel i₁ (c₁.next i₁) · rw [totalAux.d₁_eq K c₁₂ h₃ i₂ i₁₂']; swap · rw [← ComplexShape.next_π₁ c₂ c₁₂ h₃ i₂, ← c₁₂.next_eq' h₁, h] simp only [Linear.units_smul_comp, assoc, totalAux.ιMapObj_D₁] by_cases h₄ : c₁.Rel (c₁.next i₁) (c₁.next (c₁.next i₁)) · rw [totalAux.d₁_eq K c₁₂ h₄ i₂ i₁₂'', Linear.comp_units_smul, d_f_comp_d_f_assoc, zero_comp, smul_zero, smul_zero] rw [← ComplexShape.next_π₁ c₂ c₁₂ h₄, ← ComplexShape.next_π₁ c₂ c₁₂ h₃, h, c₁₂.next_eq' h₁, c₁₂.next_eq' h₂] · rw [K.d₁_eq_zero _ _ _ _ h₄, comp_zero, smul_zero] · rw [K.d₁_eq_zero c₁₂ _ _ _ h₃, zero_comp] · rw [K.D₁_shape c₁₂ _ _ h₂, comp_zero] · rw [K.D₁_shape c₁₂ _ _ h₁, zero_comp] @[reassoc (attr := simp)] lemma D₂_D₂ (i₁₂ i₁₂' i₁₂'' : I₁₂) : K.D₂ c₁₂ i₁₂ i₁₂' ≫ K.D₂ c₁₂ i₁₂' i₁₂'' = 0 := by by_cases h₁ : c₁₂.Rel i₁₂ i₁₂' · by_cases h₂ : c₁₂.Rel i₁₂' i₁₂'' · ext ⟨i₁, i₂⟩ h simp only [totalAux.ιMapObj_D₂_assoc, comp_zero] by_cases h₃ : c₂.Rel i₂ (c₂.next i₂) · rw [totalAux.d₂_eq K c₁₂ i₁ h₃ i₁₂']; swap · rw [← ComplexShape.next_π₂ c₁ c₁₂ i₁ h₃, ← c₁₂.next_eq' h₁, h] simp only [Linear.units_smul_comp, assoc, totalAux.ιMapObj_D₂] by_cases h₄ : c₂.Rel (c₂.next i₂) (c₂.next (c₂.next i₂)) · rw [totalAux.d₂_eq K c₁₂ i₁ h₄ i₁₂'', Linear.comp_units_smul, HomologicalComplex.d_comp_d_assoc, zero_comp, smul_zero, smul_zero] rw [← ComplexShape.next_π₂ c₁ c₁₂ i₁ h₄, ← ComplexShape.next_π₂ c₁ c₁₂ i₁ h₃, h, c₁₂.next_eq' h₁, c₁₂.next_eq' h₂] · rw [K.d₂_eq_zero c₁₂ _ _ _ h₄, comp_zero, smul_zero] · rw [K.d₂_eq_zero c₁₂ _ _ _ h₃, zero_comp] · rw [K.D₂_shape c₁₂ _ _ h₂, comp_zero] · rw [K.D₂_shape c₁₂ _ _ h₁, zero_comp] @[reassoc (attr := simp)] lemma D₂_D₁ (i₁₂ i₁₂' i₁₂'' : I₁₂) : K.D₂ c₁₂ i₁₂ i₁₂' ≫ K.D₁ c₁₂ i₁₂' i₁₂'' = - K.D₁ c₁₂ i₁₂ i₁₂' ≫ K.D₂ c₁₂ i₁₂' i₁₂'' := by by_cases h₁ : c₁₂.Rel i₁₂ i₁₂' · by_cases h₂ : c₁₂.Rel i₁₂' i₁₂'' · ext ⟨i₁, i₂⟩ h simp only [totalAux.ιMapObj_D₂_assoc, comp_neg, totalAux.ιMapObj_D₁_assoc] by_cases h₃ : c₁.Rel i₁ (c₁.next i₁) · rw [totalAux.d₁_eq K c₁₂ h₃ i₂ i₁₂']; swap · rw [← ComplexShape.next_π₁ c₂ c₁₂ h₃ i₂, ← c₁₂.next_eq' h₁, h] simp only [Linear.units_smul_comp, assoc, totalAux.ιMapObj_D₂] by_cases h₄ : c₂.Rel i₂ (c₂.next i₂) · have h₅ : ComplexShape.π c₁ c₂ c₁₂ (i₁, c₂.next i₂) = i₁₂' := by rw [← c₁₂.next_eq' h₁, ← h, ComplexShape.next_π₂ c₁ c₁₂ i₁ h₄] have h₆ : ComplexShape.π c₁ c₂ c₁₂ (c₁.next i₁, c₂.next i₂) = i₁₂'' := by rw [← c₁₂.next_eq' h₂, ← ComplexShape.next_π₁ c₂ c₁₂ h₃, h₅] simp only [totalAux.d₂_eq K c₁₂ _ h₄ _ h₅, totalAux.d₂_eq K c₁₂ _ h₄ _ h₆, Linear.units_smul_comp, assoc, totalAux.ιMapObj_D₁, Linear.comp_units_smul, totalAux.d₁_eq K c₁₂ h₃ _ _ h₆, HomologicalComplex.Hom.comm_assoc, smul_smul, ComplexShape.ε₂_ε₁ c₁₂ h₃ h₄, neg_mul, Units.neg_smul] · simp only [K.d₂_eq_zero c₁₂ _ _ _ h₄, zero_comp, comp_zero, smul_zero, neg_zero] · rw [K.d₁_eq_zero c₁₂ _ _ _ h₃, zero_comp, neg_zero] by_cases h₄ : c₂.Rel i₂ (c₂.next i₂) · rw [totalAux.d₂_eq K c₁₂ i₁ h₄ i₁₂']; swap · rw [← ComplexShape.next_π₂ c₁ c₁₂ i₁ h₄, ← c₁₂.next_eq' h₁, h] simp only [Linear.units_smul_comp, assoc, totalAux.ιMapObj_D₁] rw [K.d₁_eq_zero c₁₂ _ _ _ h₃, comp_zero, smul_zero] · rw [K.d₂_eq_zero c₁₂ _ _ _ h₄, zero_comp] · rw [K.D₁_shape c₁₂ _ _ h₂, K.D₂_shape c₁₂ _ _ h₂, comp_zero, comp_zero, neg_zero] · rw [K.D₁_shape c₁₂ _ _ h₁, K.D₂_shape c₁₂ _ _ h₁, zero_comp, zero_comp, neg_zero] @[reassoc] lemma D₁_D₂ (i₁₂ i₁₂' i₁₂'' : I₁₂) : K.D₁ c₁₂ i₁₂ i₁₂' ≫ K.D₂ c₁₂ i₁₂' i₁₂'' = - K.D₂ c₁₂ i₁₂ i₁₂' ≫ K.D₁ c₁₂ i₁₂' i₁₂'' := by simp /-- The total complex of a bicomplex. -/ @[simps d] noncomputable def total : HomologicalComplex C c₁₂ where X := K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) d i₁₂ i₁₂' := K.D₁ c₁₂ i₁₂ i₁₂' + K.D₂ c₁₂ i₁₂ i₁₂' shape i₁₂ i₁₂' h₁₂ := by dsimp rw [K.D₁_shape c₁₂ _ _ h₁₂, K.D₂_shape c₁₂ _ _ h₁₂, zero_add] /-- The inclusion of a summand in the total complex. -/ noncomputable def ιTotal (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) (h : ComplexShape.π c₁ c₂ c₁₂ (i₁, i₂) = i₁₂) : (K.X i₁).X i₂ ⟶ (K.total c₁₂).X i₁₂ := K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁, i₂⟩ i₁₂ h @[reassoc (attr := simp)] lemma XXIsoOfEq_hom_ιTotal {x₁ y₁ : I₁} (h₁ : x₁ = y₁) {x₂ y₂ : I₂} (h₂ : x₂ = y₂) (i₁₂ : I₁₂) (h : ComplexShape.π c₁ c₂ c₁₂ (y₁, y₂) = i₁₂) : (K.XXIsoOfEq h₁ h₂).hom ≫ K.ιTotal c₁₂ y₁ y₂ i₁₂ h = K.ιTotal c₁₂ x₁ x₂ i₁₂ (by rw [h₁, h₂, h]) := by subst h₁ h₂ simp @[reassoc (attr := simp)] lemma XXIsoOfEq_inv_ιTotal {x₁ y₁ : I₁} (h₁ : x₁ = y₁) {x₂ y₂ : I₂} (h₂ : x₂ = y₂) (i₁₂ : I₁₂) (h : ComplexShape.π c₁ c₂ c₁₂ (x₁, x₂) = i₁₂) : (K.XXIsoOfEq h₁ h₂).inv ≫ K.ιTotal c₁₂ x₁ x₂ i₁₂ h = K.ιTotal c₁₂ y₁ y₂ i₁₂ (by rw [← h, h₁, h₂]) := by subst h₁ h₂ simp /-- The inclusion of a summand in the total complex, or zero if the degrees do not match. -/ noncomputable def ιTotalOrZero (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) : (K.X i₁).X i₂ ⟶ (K.total c₁₂).X i₁₂ := K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁, i₂⟩ i₁₂ lemma ιTotalOrZero_eq (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) (h : ComplexShape.π c₁ c₂ c₁₂ (i₁, i₂) = i₁₂) : K.ιTotalOrZero c₁₂ i₁ i₂ i₁₂ = K.ιTotal c₁₂ i₁ i₂ i₁₂ h := dif_pos h lemma ιTotalOrZero_eq_zero (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) (h : ComplexShape.π c₁ c₂ c₁₂ (i₁, i₂) ≠ i₁₂) : K.ιTotalOrZero c₁₂ i₁ i₂ i₁₂ = 0 := dif_neg h @[reassoc (attr := simp)] lemma ι_D₁ (i₁₂ i₁₂' : I₁₂) (i₁ : I₁) (i₂ : I₂) (h : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = i₁₂) : K.ιTotal c₁₂ i₁ i₂ i₁₂ h ≫ K.D₁ c₁₂ i₁₂ i₁₂' = K.d₁ c₁₂ i₁ i₂ i₁₂' := by apply totalAux.ιMapObj_D₁ @[reassoc (attr := simp)] lemma ι_D₂ (i₁₂ i₁₂' : I₁₂) (i₁ : I₁) (i₂ : I₂) (h : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = i₁₂) : K.ιTotal c₁₂ i₁ i₂ i₁₂ h ≫ K.D₂ c₁₂ i₁₂ i₁₂' = K.d₂ c₁₂ i₁ i₂ i₁₂' := by apply totalAux.ιMapObj_D₂ lemma d₁_eq' {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (i₁₂ : I₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.d i₁ i₁').f i₂ ≫ K.ιTotalOrZero c₁₂ i₁' i₂ i₁₂) := totalAux.d₁_eq' _ _ h _ _ lemma d₁_eq {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁', i₂⟩ = i₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.d i₁ i₁').f i₂ ≫ K.ιTotal c₁₂ i₁' i₂ i₁₂ h') := totalAux.d₁_eq _ _ h _ _ _ lemma d₂_eq' (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (i₁₂ : I₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.X i₁).d i₂ i₂' ≫ K.ιTotalOrZero c₁₂ i₁ i₂' i₁₂) := totalAux.d₂_eq' _ _ _ h _ lemma d₂_eq (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂'⟩ = i₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.X i₁).d i₂ i₂' ≫ K.ιTotal c₁₂ i₁ i₂' i₁₂ h') := totalAux.d₂_eq _ _ _ h _ _ section variable {c₁₂} variable {A : C} {i₁₂ : I₁₂} (f : ∀ (i₁ : I₁) (i₂ : I₂) (_ : ComplexShape.π c₁ c₂ c₁₂ (i₁, i₂) = i₁₂), (K.X i₁).X i₂ ⟶ A) /-- Given a bicomplex `K`, this is a constructor for morphisms from `(K.total c₁₂).X i₁₂`. -/ noncomputable def totalDesc : (K.total c₁₂).X i₁₂ ⟶ A := K.toGradedObject.descMapObj _ (fun ⟨i₁, i₂⟩ hi => f i₁ i₂ hi) @[reassoc (attr := simp)] lemma ι_totalDesc (i₁ : I₁) (i₂ : I₂) (hi : ComplexShape.π c₁ c₂ c₁₂ (i₁, i₂) = i₁₂) : K.ιTotal c₁₂ i₁ i₂ i₁₂ hi ≫ K.totalDesc f = f i₁ i₂ hi := by simp [totalDesc, ιTotal] end namespace total variable {K L M} @[ext] lemma hom_ext {A : C} {i₁₂ : I₁₂} {f g : (K.total c₁₂).X i₁₂ ⟶ A} (h : ∀ (i₁ : I₁) (i₂ : I₂) (hi : ComplexShape.π c₁ c₂ c₁₂ (i₁, i₂) = i₁₂), K.ιTotal c₁₂ i₁ i₂ i₁₂ hi ≫ f = K.ιTotal c₁₂ i₁ i₂ i₁₂ hi ≫ g) : f = g := by apply GradedObject.mapObj_ext rintro ⟨i₁, i₂⟩ hi exact h i₁ i₂ hi variable [L.HasTotal c₁₂] namespace mapAux @[reassoc (attr := simp)] lemma d₁_mapMap (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ ≫ GradedObject.mapMap (toGradedObjectMap φ) _ i₁₂ = (φ.f i₁).f i₂ ≫ L.d₁ c₁₂ i₁ i₂ i₁₂ := by by_cases h : c₁.Rel i₁ (c₁.next i₁) · simp [totalAux.d₁_eq' _ c₁₂ h] · simp [d₁_eq_zero _ c₁₂ i₁ i₂ i₁₂ h] @[reassoc (attr := simp)] lemma d₂_mapMap (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ ≫ GradedObject.mapMap (toGradedObjectMap φ) _ i₁₂ = (φ.f i₁).f i₂ ≫ L.d₂ c₁₂ i₁ i₂ i₁₂ := by by_cases h : c₂.Rel i₂ (c₂.next i₂) · simp [totalAux.d₂_eq' _ c₁₂ i₁ h] · simp [d₂_eq_zero _ c₁₂ i₁ i₂ i₁₂ h] @[reassoc] lemma mapMap_D₁ (i₁₂ i₁₂' : I₁₂) : GradedObject.mapMap (toGradedObjectMap φ) _ i₁₂ ≫ L.D₁ c₁₂ i₁₂ i₁₂' = K.D₁ c₁₂ i₁₂ i₁₂' ≫ GradedObject.mapMap (toGradedObjectMap φ) _ i₁₂' := by aesop_cat @[reassoc] lemma mapMap_D₂ (i₁₂ i₁₂' : I₁₂) : GradedObject.mapMap (toGradedObjectMap φ) _ i₁₂ ≫ L.D₂ c₁₂ i₁₂ i₁₂' = K.D₂ c₁₂ i₁₂ i₁₂' ≫ GradedObject.mapMap (toGradedObjectMap φ) _ i₁₂' := by aesop_cat end mapAux /-- The morphism `K.total c₁₂ ⟶ L.total c₁₂` of homological complexes induced by a morphism of bicomplexes `K ⟶ L`. -/ noncomputable def map : K.total c₁₂ ⟶ L.total c₁₂ where f := GradedObject.mapMap (toGradedObjectMap φ) _ comm' i₁₂ i₁₂' _ := by dsimp [total] rw [comp_add, add_comp, mapAux.mapMap_D₁, mapAux.mapMap_D₂] @[simp] lemma forget_map : (HomologicalComplex.forget C c₁₂).map (map φ c₁₂) = GradedObject.mapMap (toGradedObjectMap φ) _ := rfl variable (K) in @[simp] lemma map_id : map (𝟙 K) c₁₂ = 𝟙 _ := by apply (HomologicalComplex.forget _ _).map_injective apply GradedObject.mapMap_id variable [M.HasTotal c₁₂] @[simp, reassoc] lemma map_comp : map (φ ≫ ψ) c₁₂ = map φ c₁₂ ≫ map ψ c₁₂ := by apply (HomologicalComplex.forget _ _).map_injective exact GradedObject.mapMap_comp (toGradedObjectMap φ) (toGradedObjectMap ψ) _ /-- The isomorphism `K.total c₁₂ ≅ L.total c₁₂` of homological complexes induced by an isomorphism of bicomplexes `K ≅ L`. -/ @[simps] noncomputable def mapIso : K.total c₁₂ ≅ L.total c₁₂ where hom := map e.hom _ inv := map e.inv _ hom_inv_id := by rw [← map_comp, e.hom_inv_id, map_id] inv_hom_id := by rw [← map_comp, e.inv_hom_id, map_id] end total section variable [L.HasTotal c₁₂] @[reassoc (attr := simp)] lemma ιTotal_map (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) (h : ComplexShape.π c₁ c₂ c₁₂ (i₁, i₂) = i₁₂) : K.ιTotal c₁₂ i₁ i₂ i₁₂ h ≫ (total.map φ c₁₂).f i₁₂ = (φ.f i₁).f i₂ ≫ L.ιTotal c₁₂ i₁ i₂ i₁₂ h := by simp [total.map, ιTotal] @[reassoc (attr := simp)] lemma ιTotalOrZero_map (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) : K.ιTotalOrZero c₁₂ i₁ i₂ i₁₂ ≫ (total.map φ c₁₂).f i₁₂ = (φ.f i₁).f i₂ ≫ L.ιTotalOrZero c₁₂ i₁ i₂ i₁₂ := by simp [total.map, ιTotalOrZero] end variable (C c₁ c₂) variable [∀ (K : HomologicalComplex₂ C c₁ c₂), K.HasTotal c₁₂] /-- The functor which sends a bicomplex to its total complex. -/ @[simps] noncomputable def totalFunctor : HomologicalComplex₂ C c₁ c₂ ⥤ HomologicalComplex C c₁₂ where obj K := K.total c₁₂ map φ := total.map φ c₁₂ end HomologicalComplex₂
Algebra\Homology\TotalComplexShift.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory.Shift import Mathlib.Algebra.Homology.TotalComplex /-! # Behaviour of the total complex with respect to shifts There are two ways to shift objects in `HomologicalComplex₂ C (up ℤ) (up ℤ)`: * by shifting the first indices (and changing signs of horizontal differentials), which corresponds to the shift by `ℤ` on `CochainComplex (CochainComplex C ℤ) ℤ`. * by shifting the second indices (and changing signs of vertical differentials). These two sorts of shift functors shall be abbreviated as `HomologicalComplex₂.shiftFunctor₁ C x` and `HomologicalComplex₂.shiftFunctor₂ C y`. In this file, for any `K : HomologicalComplex₂ C (up ℤ) (up ℤ)`, we define an isomorphism `K.totalShift₁Iso x : ((shiftFunctor₁ C x).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦x⟧` for any `x : ℤ` (which does not involve signs) and an isomorphism `K.totalShift₂Iso y : ((shiftFunctor₂ C y).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦y⟧` for any `y : ℤ` (which is given by the multiplication by `(p * y).negOnePow` on the summand in bidegree `(p, q)` of `K`). Depending on the order of the "composition" of the two isomorphisms `totalShift₁Iso` and `totalShift₂Iso`, we get two ways to identify `((shiftFunctor₁ C x).obj ((shiftFunctor₂ C y).obj K)).total (up ℤ)` and `(K.total (up ℤ))⟦x + y⟧`. The lemma `totalShift₁Iso_trans_totalShift₂Iso` shows that these two compositions of isomorphisms differ by the sign `(x * y).negOnePow`. -/ open CategoryTheory Category ComplexShape Limits namespace HomologicalComplex₂ variable (C : Type*) [Category C] [Preadditive C] /-- The shift on bicomplexes obtained by shifting the first indices (and changing the sign of differentials). -/ abbrev shiftFunctor₁ (x : ℤ) : HomologicalComplex₂ C (up ℤ) (up ℤ) ⥤ HomologicalComplex₂ C (up ℤ) (up ℤ) := shiftFunctor _ x /-- The shift on bicomplexes obtained by shifting the second indices (and changing the sign of differentials). -/ abbrev shiftFunctor₂ (y : ℤ) : HomologicalComplex₂ C (up ℤ) (up ℤ) ⥤ HomologicalComplex₂ C (up ℤ) (up ℤ) := (shiftFunctor _ y).mapHomologicalComplex _ variable {C} variable (K L : HomologicalComplex₂ C (up ℤ) (up ℤ)) (f : K ⟶ L) /-- The isomorphism `(((shiftFunctor₁ C x).obj K).X a).X b ≅ (K.X a').X b` when `a' = a + x`. -/ def shiftFunctor₁XXIso (a x a' : ℤ) (h : a' = a + x) (b : ℤ) : (((shiftFunctor₁ C x).obj K).X a).X b ≅ (K.X a').X b := eqToIso (by subst h; rfl) /-- The isomorphism `(((shiftFunctor₂ C y).obj K).X a).X b ≅ (K.X a).X b'` when `b' = b + y`. -/ def shiftFunctor₂XXIso (a b y b' : ℤ) (h : b' = b + y) : (((shiftFunctor₂ C y).obj K).X a).X b ≅ (K.X a).X b' := eqToIso (by subst h; rfl) @[simp] lemma shiftFunctor₁XXIso_refl (a b x : ℤ) : K.shiftFunctor₁XXIso a x (a + x) rfl b = Iso.refl _ := rfl @[simp] lemma shiftFunctor₂XXIso_refl (a b y : ℤ) : K.shiftFunctor₂XXIso a b y (b + y) rfl = Iso.refl _ := rfl variable (x y : ℤ) [K.HasTotal (up ℤ)] instance : ((shiftFunctor₁ C x).obj K).HasTotal (up ℤ) := fun n => hasCoproduct_of_equiv_of_iso (K.toGradedObject.mapObjFun (π (up ℤ) (up ℤ) (up ℤ)) (n + x)) _ { toFun := fun ⟨⟨a, b⟩, h⟩ => ⟨⟨a + x, b⟩, by simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢ omega⟩ invFun := fun ⟨⟨a, b⟩, h⟩ => ⟨(a - x, b), by simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢ omega⟩ left_inv := by rintro ⟨⟨a, b⟩, h⟩ ext · dsimp omega · rfl right_inv := by intro ⟨⟨a, b⟩, h⟩ ext · dsimp omega · rfl } (fun _ => Iso.refl _) instance : ((shiftFunctor₂ C y).obj K).HasTotal (up ℤ) := fun n => hasCoproduct_of_equiv_of_iso (K.toGradedObject.mapObjFun (π (up ℤ) (up ℤ) (up ℤ)) (n + y)) _ { toFun := fun ⟨⟨a, b⟩, h⟩ => ⟨⟨a, b + y⟩, by simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢ omega⟩ invFun := fun ⟨⟨a, b⟩, h⟩ => ⟨(a, b - y), by simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢ omega⟩ left_inv := by rintro ⟨⟨a, b⟩, h⟩ ext · rfl · dsimp omega right_inv := by intro ⟨⟨a, b⟩, h⟩ ext · rfl · dsimp omega } (fun _ => Iso.refl _) instance : ((shiftFunctor₂ C y ⋙ shiftFunctor₁ C x).obj K).HasTotal (up ℤ) := by dsimp infer_instance instance : ((shiftFunctor₁ C x ⋙ shiftFunctor₂ C y).obj K).HasTotal (up ℤ) := by dsimp infer_instance /-- Auxiliary definition for `totalShift₁Iso`. -/ noncomputable def totalShift₁XIso (n n' : ℤ) (h : n + x = n') : (((shiftFunctor₁ C x).obj K).total (up ℤ)).X n ≅ (K.total (up ℤ)).X n' where hom := totalDesc _ (fun p q hpq => K.ιTotal (up ℤ) (p + x) q n' (by dsimp at hpq ⊢; omega)) inv := totalDesc _ (fun p q hpq => (K.XXIsoOfEq (Int.sub_add_cancel p x) rfl).inv ≫ ((shiftFunctor₁ C x).obj K).ιTotal (up ℤ) (p - x) q n (by dsimp at hpq ⊢; omega)) hom_inv_id := by ext p q h dsimp simp only [ι_totalDesc_assoc, CochainComplex.shiftFunctor_obj_X', ι_totalDesc, comp_id] exact ((shiftFunctor₁ C x).obj K).XXIsoOfEq_inv_ιTotal _ (by omega) rfl _ _ @[reassoc] lemma D₁_totalShift₁XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + x = n₀') (h₁ : n₁ + x = n₁') : ((shiftFunctor₁ C x).obj K).D₁ (up ℤ) n₀ n₁ ≫ (K.totalShift₁XIso x n₁ n₁' h₁).hom = x.negOnePow • ((K.totalShift₁XIso x n₀ n₀' h₀).hom ≫ K.D₁ (up ℤ) n₀' n₁') := by by_cases h : (up ℤ).Rel n₀ n₁ · apply total.hom_ext intro p q hpq dsimp at h hpq dsimp [totalShift₁XIso] rw [ι_D₁_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, ι_D₁, ((shiftFunctor₁ C x).obj K).d₁_eq _ rfl _ _ (by dsimp; omega), K.d₁_eq _ (show p + x + 1 = p + 1 + x by omega) _ _ (by dsimp; omega)] dsimp rw [one_smul, assoc, ι_totalDesc, one_smul, Linear.units_smul_comp] · rw [D₁_shape _ _ _ _ h, zero_comp, D₁_shape, comp_zero, smul_zero] intro h' apply h dsimp at h' ⊢ omega @[reassoc] lemma D₂_totalShift₁XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + x = n₀') (h₁ : n₁ + x = n₁') : ((shiftFunctor₁ C x).obj K).D₂ (up ℤ) n₀ n₁ ≫ (K.totalShift₁XIso x n₁ n₁' h₁).hom = x.negOnePow • ((K.totalShift₁XIso x n₀ n₀' h₀).hom ≫ K.D₂ (up ℤ) n₀' n₁') := by by_cases h : (up ℤ).Rel n₀ n₁ · apply total.hom_ext intro p q hpq dsimp at h hpq dsimp [totalShift₁XIso] rw [ι_D₂_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, ι_D₂, ((shiftFunctor₁ C x).obj K).d₂_eq _ _ rfl _ (by dsimp; omega), K.d₂_eq _ _ rfl _ (by dsimp; omega), smul_smul, Linear.units_smul_comp, assoc, ι_totalDesc] dsimp congr 1 rw [add_comm p, Int.negOnePow_add, ← mul_assoc, Int.units_mul_self, one_mul] · rw [D₂_shape _ _ _ _ h, zero_comp, D₂_shape, comp_zero, smul_zero] intro h' apply h dsimp at h' ⊢ omega /-- The isomorphism `((shiftFunctor₁ C x).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦x⟧` expressing the compatibility of the total complex with the shift on the first indices. This isomorphism does not involve signs. -/ noncomputable def totalShift₁Iso : ((shiftFunctor₁ C x).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦x⟧ := HomologicalComplex.Hom.isoOfComponents (fun n => K.totalShift₁XIso x n (n + x) rfl) (fun n n' _ => by dsimp simp only [Preadditive.add_comp, Preadditive.comp_add, smul_add, Linear.comp_units_smul, K.D₁_totalShift₁XIso_hom x n n' _ _ rfl rfl, K.D₂_totalShift₁XIso_hom x n n' _ _ rfl rfl]) @[reassoc] lemma ι_totalShift₁Iso_hom_f (a b n : ℤ) (h : a + b = n) (a' : ℤ) (ha' : a' = a + x) (n' : ℤ) (hn' : n' = n + x) : ((shiftFunctor₁ C x).obj K).ιTotal (up ℤ) a b n h ≫ (K.totalShift₁Iso x).hom.f n = (K.shiftFunctor₁XXIso a x a' ha' b).hom ≫ K.ιTotal (up ℤ) a' b n' (by dsimp; omega) ≫ (CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) x n n' hn').inv := by subst ha' hn' simp [totalShift₁Iso, totalShift₁XIso] @[reassoc] lemma ι_totalShift₁Iso_inv_f (a b n : ℤ) (h : a + b = n) (a' n' : ℤ) (ha' : a' + b = n') (hn' : n' = n + x) : K.ιTotal (up ℤ) a' b n' ha' ≫ (CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) x n n' hn').inv ≫ (K.totalShift₁Iso x).inv.f n = (K.shiftFunctor₁XXIso a x a' (by omega) b).inv ≫ ((shiftFunctor₁ C x).obj K).ιTotal (up ℤ) a b n h := by subst hn' obtain rfl : a = a' - x := by omega dsimp [totalShift₁Iso, totalShift₁XIso, shiftFunctor₁XXIso, XXIsoOfEq] simp only [id_comp, ι_totalDesc] variable {K L} in @[reassoc] lemma totalShift₁Iso_hom_naturality [L.HasTotal (up ℤ)] : total.map ((shiftFunctor₁ C x).map f) (up ℤ) ≫ (L.totalShift₁Iso x).hom = (K.totalShift₁Iso x).hom ≫ (total.map f (up ℤ))⟦x⟧' := by ext n i₁ i₂ h dsimp at h dsimp rw [ιTotal_map_assoc, L.ι_totalShift₁Iso_hom_f x i₁ i₂ n h _ rfl _ rfl, K.ι_totalShift₁Iso_hom_f_assoc x i₁ i₂ n h _ rfl _ rfl] dsimp rw [id_comp, id_comp, id_comp, comp_id, ιTotal_map] attribute [local simp] smul_smul /-- Auxiliary definition for `totalShift₂Iso`. -/ noncomputable def totalShift₂XIso (n n' : ℤ) (h : n + y = n') : (((shiftFunctor₂ C y).obj K).total (up ℤ)).X n ≅ (K.total (up ℤ)).X n' where hom := totalDesc _ (fun p q hpq => (p * y).negOnePow • K.ιTotal (up ℤ) p (q + y) n' (by dsimp at hpq ⊢; omega)) inv := totalDesc _ (fun p q hpq => (p * y).negOnePow • (K.XXIsoOfEq rfl (Int.sub_add_cancel q y)).inv ≫ ((shiftFunctor₂ C y).obj K).ιTotal (up ℤ) p (q - y) n (by dsimp at hpq ⊢; omega)) hom_inv_id := by ext p q h dsimp simp only [ι_totalDesc_assoc, Linear.units_smul_comp, ι_totalDesc, smul_smul, Int.units_mul_self, one_smul, comp_id] exact ((shiftFunctor₂ C y).obj K).XXIsoOfEq_inv_ιTotal _ rfl (by omega) _ _ @[reassoc] lemma D₁_totalShift₂XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + y = n₀') (h₁ : n₁ + y = n₁') : ((shiftFunctor₂ C y).obj K).D₁ (up ℤ) n₀ n₁ ≫ (K.totalShift₂XIso y n₁ n₁' h₁).hom = y.negOnePow • ((K.totalShift₂XIso y n₀ n₀' h₀).hom ≫ K.D₁ (up ℤ) n₀' n₁') := by by_cases h : (up ℤ).Rel n₀ n₁ · apply total.hom_ext intro p q hpq dsimp at h hpq dsimp [totalShift₂XIso] rw [ι_D₁_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, Linear.units_smul_comp, ι_D₁, smul_smul, ((shiftFunctor₂ C y).obj K).d₁_eq _ rfl _ _ (by dsimp; omega), K.d₁_eq _ rfl _ _ (by dsimp; omega)] dsimp rw [one_smul, one_smul, assoc, ι_totalDesc, Linear.comp_units_smul, ← Int.negOnePow_add] congr 2 linarith · rw [D₁_shape _ _ _ _ h, zero_comp, D₁_shape, comp_zero, smul_zero] intro h' apply h dsimp at h' ⊢ omega @[reassoc] lemma D₂_totalShift₂XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + y = n₀') (h₁ : n₁ + y = n₁') : ((shiftFunctor₂ C y).obj K).D₂ (up ℤ) n₀ n₁ ≫ (K.totalShift₂XIso y n₁ n₁' h₁).hom = y.negOnePow • ((K.totalShift₂XIso y n₀ n₀' h₀).hom ≫ K.D₂ (up ℤ) n₀' n₁') := by by_cases h : (up ℤ).Rel n₀ n₁ · apply total.hom_ext intro p q hpq dsimp at h hpq dsimp [totalShift₂XIso] rw [ι_D₂_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, Linear.units_smul_comp, smul_smul, ι_D₂, ((shiftFunctor₂ C y).obj K).d₂_eq _ _ rfl _ (by dsimp; omega), K.d₂_eq _ _ (show q + y + 1 = q + 1 + y by omega) _ (by dsimp; omega), Linear.units_smul_comp, assoc, smul_smul, ι_totalDesc] dsimp rw [Linear.units_smul_comp, Linear.comp_units_smul, smul_smul, smul_smul, ← Int.negOnePow_add, ← Int.negOnePow_add, ← Int.negOnePow_add, ← Int.negOnePow_add] congr 2 omega · rw [D₂_shape _ _ _ _ h, zero_comp, D₂_shape, comp_zero, smul_zero] intro h' apply h dsimp at h' ⊢ omega /-- The isomorphism `((shiftFunctor₂ C y).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦y⟧` expressing the compatibility of the total complex with the shift on the second indices. This isomorphism involves signs: on the summand in degree `(p, q)` of `K`, it is given by the multiplication by `(p * y).negOnePow`. -/ noncomputable def totalShift₂Iso : ((shiftFunctor₂ C y).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦y⟧ := HomologicalComplex.Hom.isoOfComponents (fun n => K.totalShift₂XIso y n (n + y) rfl) (fun n n' _ => by dsimp simp only [Preadditive.add_comp, Preadditive.comp_add, smul_add, Linear.comp_units_smul, K.D₁_totalShift₂XIso_hom y n n' _ _ rfl rfl, K.D₂_totalShift₂XIso_hom y n n' _ _ rfl rfl]) @[reassoc] lemma ι_totalShift₂Iso_hom_f (a b n : ℤ) (h : a + b = n) (b' : ℤ) (hb' : b' = b + y) (n' : ℤ) (hn' : n' = n + y) : ((shiftFunctor₂ C y).obj K).ιTotal (up ℤ) a b n h ≫ (K.totalShift₂Iso y).hom.f n = (a * y).negOnePow • (K.shiftFunctor₂XXIso a b y b' hb').hom ≫ K.ιTotal (up ℤ) a b' n' (by dsimp; omega) ≫ (CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) y n n' hn').inv := by subst hb' hn' simp [totalShift₂Iso, totalShift₂XIso] @[reassoc] lemma ι_totalShift₂Iso_inv_f (a b n : ℤ) (h : a + b = n) (b' n' : ℤ) (hb' : a + b' = n') (hn' : n' = n + y) : K.ιTotal (up ℤ) a b' n' hb' ≫ (CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) y n n' hn').inv ≫ (K.totalShift₂Iso y).inv.f n = (a * y).negOnePow • (K.shiftFunctor₂XXIso a b y b' (by omega)).inv ≫ ((shiftFunctor₂ C y).obj K).ιTotal (up ℤ) a b n h := by subst hn' obtain rfl : b = b' - y := by omega dsimp [totalShift₂Iso, totalShift₂XIso, shiftFunctor₂XXIso, XXIsoOfEq] simp only [id_comp, ι_totalDesc] variable {K L} in @[reassoc] lemma totalShift₂Iso_hom_naturality [L.HasTotal (up ℤ)] : total.map ((shiftFunctor₂ C y).map f) (up ℤ) ≫ (L.totalShift₂Iso y).hom = (K.totalShift₂Iso y).hom ≫ (total.map f (up ℤ))⟦y⟧' := by ext n i₁ i₂ h dsimp at h dsimp rw [ιTotal_map_assoc, L.ι_totalShift₂Iso_hom_f y i₁ i₂ n h _ rfl _ rfl, K.ι_totalShift₂Iso_hom_f_assoc y i₁ i₂ n h _ rfl _ rfl] dsimp rw [id_comp, id_comp, comp_id, comp_id, Linear.comp_units_smul, Linear.units_smul_comp, ιTotal_map] variable (C) in /-- The shift functors `shiftFunctor₁ C x` and `shiftFunctor₂ C y` on bicomplexes with respect to both variables commute. -/ def shiftFunctor₁₂CommIso (x y : ℤ) : shiftFunctor₂ C y ⋙ shiftFunctor₁ C x ≅ shiftFunctor₁ C x ⋙ shiftFunctor₂ C y := Iso.refl _ /-- The compatibility isomorphisms of the total complex with the shifts in both variables "commute" only up to a sign `(x * y).negOnePow`. -/ lemma totalShift₁Iso_trans_totalShift₂Iso : ((shiftFunctor₂ C y).obj K).totalShift₁Iso x ≪≫ (shiftFunctor (CochainComplex C ℤ) x).mapIso (K.totalShift₂Iso y) = (x * y).negOnePow • (total.mapIso ((shiftFunctor₁₂CommIso C x y).app K) (up ℤ)) ≪≫ ((shiftFunctor₁ C x).obj K).totalShift₂Iso y ≪≫ (shiftFunctor _ y).mapIso (K.totalShift₁Iso x) ≪≫ (shiftFunctorComm (CochainComplex C ℤ) x y).app _ := by ext n n₁ n₂ h dsimp at h ⊢ rw [Linear.comp_units_smul,ι_totalShift₁Iso_hom_f_assoc _ x n₁ n₂ n h _ rfl _ rfl, ιTotal_map_assoc, ι_totalShift₂Iso_hom_f_assoc _ y n₁ n₂ n h _ rfl _ rfl, Linear.units_smul_comp, Linear.comp_units_smul] dsimp [shiftFunctor₁₂CommIso] rw [id_comp, id_comp, id_comp, id_comp, comp_id, ι_totalShift₂Iso_hom_f _ y (n₁ + x) n₂ (n + x) (by omega) _ rfl _ rfl, smul_smul, ← Int.negOnePow_add, add_mul, add_comm (x * y)] dsimp rw [id_comp, comp_id, ι_totalShift₁Iso_hom_f_assoc _ x n₁ (n₂ + y) (n + y) (by omega) _ rfl (n + x + y) (by omega), CochainComplex.shiftFunctorComm_hom_app_f] dsimp rw [Iso.inv_hom_id, comp_id, id_comp] /-- The compatibility isomorphisms of the total complex with the shifts in both variables "commute" only up to a sign `(x * y).negOnePow`. -/ @[reassoc] lemma totalShift₁Iso_hom_totalShift₂Iso_hom : (((shiftFunctor₂ C y).obj K).totalShift₁Iso x).hom ≫ (K.totalShift₂Iso y).hom⟦x⟧' = (x * y).negOnePow • (total.map ((shiftFunctor₁₂CommIso C x y).hom.app K) (up ℤ) ≫ (((shiftFunctor₁ C x).obj K).totalShift₂Iso y).hom ≫ (K.totalShift₁Iso x).hom⟦y⟧' ≫ (shiftFunctorComm (CochainComplex C ℤ) x y).hom.app _) := congr_arg Iso.hom (totalShift₁Iso_trans_totalShift₂Iso K x y) end HomologicalComplex₂
Algebra\Homology\TotalComplexSymmetry.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.TotalComplex /-! The symmetry of the total complex of a bicomplex Let `K : HomologicalComplex₂ C c₁ c₂` be a bicomplex. If we assume both `[TotalComplexShape c₁ c₂ c]` and `[TotalComplexShape c₂ c₁ c]`, we may form the total complex `K.total c` and `K.flip.total c`. In this file, we show that if we assume `[TotalComplexShapeSymmetry c₁ c₂ c]`, then there is an isomorphism `K.totalFlipIso c : K.flip.total c ≅ K.total c`. Moreover, if we also have `[TotalComplexShapeSymmetry c₂ c₁ c]` and that the signs are compatible `[TotalComplexShapeSymmetrySymmetry c₁ c₂ c]`, then the isomorphisms `K.totalFlipIso c` and `K.flip.totalFlipIso c` are inverse to each other. -/ open CategoryTheory Category Limits namespace HomologicalComplex₂ variable {C I₁ I₂ J : Type*} [Category C] [Preadditive C] {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} (K : HomologicalComplex₂ C c₁ c₂) (c : ComplexShape J) [TotalComplexShape c₁ c₂ c] [TotalComplexShape c₂ c₁ c] [TotalComplexShapeSymmetry c₁ c₂ c] [K.HasTotal c] [K.flip.HasTotal c] [DecidableEq J] attribute [local simp] smul_smul /-- Auxiliary definition for `totalFlipIso`. -/ noncomputable def totalFlipIsoX (j : J) : (K.flip.total c).X j ≅ (K.total c).X j where hom := K.flip.totalDesc (fun i₂ i₁ h => ComplexShape.σ c₁ c₂ c i₁ i₂ • K.ιTotal c i₁ i₂ j (by rw [← ComplexShape.π_symm c₁ c₂ c i₁ i₂, h])) inv := K.totalDesc (fun i₁ i₂ h => ComplexShape.σ c₁ c₂ c i₁ i₂ • K.flip.ιTotal c i₂ i₁ j (by rw [ComplexShape.π_symm c₁ c₂ c i₁ i₂, h])) hom_inv_id := by ext; simp inv_hom_id := by ext; simp @[reassoc] lemma totalFlipIsoX_hom_D₁ (j j' : J) : (K.totalFlipIsoX c j).hom ≫ K.D₁ c j j' = K.flip.D₂ c j j' ≫ (K.totalFlipIsoX c j').hom := by by_cases h₀ : c.Rel j j' · ext i₂ i₁ h₁ dsimp [totalFlipIsoX] rw [ι_totalDesc_assoc, Linear.units_smul_comp, ι_D₁, ι_D₂_assoc] dsimp by_cases h₂ : c₁.Rel i₁ (c₁.next i₁) · have h₃ : ComplexShape.π c₂ c₁ c ⟨i₂, c₁.next i₁⟩ = j' := by rw [← ComplexShape.next_π₂ c₂ c i₂ h₂, h₁, c.next_eq' h₀] have h₄ : ComplexShape.π c₁ c₂ c ⟨c₁.next i₁, i₂⟩ = j' := by rw [← h₃, ComplexShape.π_symm c₁ c₂ c] rw [K.d₁_eq _ h₂ _ _ h₄, K.flip.d₂_eq _ _ h₂ _ h₃, Linear.units_smul_comp, assoc, ι_totalDesc, Linear.comp_units_smul, smul_smul, smul_smul, ComplexShape.σ_ε₁ c₂ c h₂ i₂] dsimp only [flip_X_X, flip_X_d] · rw [K.d₁_eq_zero _ _ _ _ h₂, K.flip.d₂_eq_zero _ _ _ _ h₂, smul_zero, zero_comp] · rw [K.D₁_shape _ _ _ h₀, K.flip.D₂_shape c _ _ h₀, zero_comp, comp_zero] @[reassoc] lemma totalFlipIsoX_hom_D₂ (j j' : J) : (K.totalFlipIsoX c j).hom ≫ K.D₂ c j j' = K.flip.D₁ c j j' ≫ (K.totalFlipIsoX c j').hom := by by_cases h₀ : c.Rel j j' · ext i₂ i₁ h₁ dsimp [totalFlipIsoX] rw [ι_totalDesc_assoc, Linear.units_smul_comp, ι_D₂, ι_D₁_assoc] dsimp by_cases h₂ : c₂.Rel i₂ (c₂.next i₂) · have h₃ : ComplexShape.π c₂ c₁ c (ComplexShape.next c₂ i₂, i₁) = j' := by rw [← ComplexShape.next_π₁ c₁ c h₂ i₁, h₁, c.next_eq' h₀] have h₄ : ComplexShape.π c₁ c₂ c (i₁, ComplexShape.next c₂ i₂) = j' := by rw [← h₃, ComplexShape.π_symm c₁ c₂ c] rw [K.d₂_eq _ _ h₂ _ h₄, K.flip.d₁_eq _ h₂ _ _ h₃, Linear.units_smul_comp, assoc, ι_totalDesc, Linear.comp_units_smul, smul_smul, smul_smul, ComplexShape.σ_ε₂ c₁ c i₁ h₂] rfl · rw [K.d₂_eq_zero _ _ _ _ h₂, K.flip.d₁_eq_zero _ _ _ _ h₂, smul_zero, zero_comp] · rw [K.D₂_shape _ _ _ h₀, K.flip.D₁_shape c _ _ h₀, zero_comp, comp_zero] /-- The symmetry isomorphism `K.flip.total c ≅ K.total c` of the total complex of a bicomplex when we have `[TotalComplexShapeSymmetry c₁ c₂ c]`. -/ noncomputable def totalFlipIso : K.flip.total c ≅ K.total c := HomologicalComplex.Hom.isoOfComponents (K.totalFlipIsoX c) (fun j j' _ => by dsimp simp only [Preadditive.comp_add, totalFlipIsoX_hom_D₁, totalFlipIsoX_hom_D₂, Preadditive.add_comp] rw [add_comm]) @[reassoc] lemma totalFlipIso_hom_f_D₁ (j j' : J) : (K.totalFlipIso c).hom.f j ≫ K.D₁ c j j' = K.flip.D₂ c j j' ≫ (K.totalFlipIso c).hom.f j' := by apply totalFlipIsoX_hom_D₁ @[reassoc] lemma totalFlipIso_hom_f_D₂ (j j' : J) : (K.totalFlipIso c).hom.f j ≫ K.D₂ c j j' = K.flip.D₁ c j j' ≫ (K.totalFlipIso c).hom.f j' := by apply totalFlipIsoX_hom_D₂ @[reassoc (attr := simp)] lemma ιTotal_totalFlipIso_f_hom (i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₂ c₁ c (i₂, i₁) = j) : K.flip.ιTotal c i₂ i₁ j h ≫ (K.totalFlipIso c).hom.f j = ComplexShape.σ c₁ c₂ c i₁ i₂ • K.ιTotal c i₁ i₂ j (by rw [← ComplexShape.π_symm c₁ c₂ c i₁ i₂, h]) := by simp [totalFlipIso, totalFlipIsoX] @[reassoc (attr := simp)] lemma ιTotal_totalFlipIso_f_inv (i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₁ c₂ c (i₁, i₂) = j) : K.ιTotal c i₁ i₂ j h ≫ (K.totalFlipIso c).inv.f j = ComplexShape.σ c₁ c₂ c i₁ i₂ • K.flip.ιTotal c i₂ i₁ j (by rw [ComplexShape.π_symm c₁ c₂ c i₁ i₂, h]) := by simp [totalFlipIso, totalFlipIsoX] instance : K.flip.flip.HasTotal c := (inferInstance : K.HasTotal c) section variable [TotalComplexShapeSymmetry c₂ c₁ c] [TotalComplexShapeSymmetrySymmetry c₁ c₂ c] lemma flip_totalFlipIso : K.flip.totalFlipIso c = (K.totalFlipIso c).symm := by ext j i₁ i₂ h rw [Iso.symm_hom, ιTotal_totalFlipIso_f_hom] dsimp only [flip_flip] rw [ιTotal_totalFlipIso_f_inv, ComplexShape.σ_symm] end end HomologicalComplex₂
Algebra\Homology\DerivedCategory\Basic.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.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`. - refactor the definition of Ext groups using morphisms in the derived category (which may be shrunk to the universe `v` at least when `C` has enough projectives or enough injectives). ## 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] -/ 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 : Triangulated.Subcategory (HomotopyCategory C (ComplexShape.up ℤ)) := (homologyFunctor C (ComplexShape.up ℤ) 0).homologicalKernel instance : ClosedUnderIsomorphisms (subcategoryAcyclic C).P := by dsimp [subcategoryAcyclic] infer_instance variable {C} lemma mem_subcategoryAcyclic_iff (X : HomotopyCategory C (ComplexShape.up ℤ)) : (subcategoryAcyclic C).P X ↔ ∀ (n : ℤ), IsZero ((homologyFunctor _ _ n).obj X) := Functor.mem_homologicalKernel_iff _ X lemma quotient_obj_mem_subcategoryAcyclic_iff_exactAt (K : CochainComplex C ℤ) : (subcategoryAcyclic C).P ((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).W := by ext K L f exact ((homologyFunctor C (ComplexShape.up ℤ) 0).mem_homologicalKernel_W_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).W := by rw [← HomotopyCategory.quasiIso_eq_subcategoryAcyclic_W] infer_instance noncomputable instance : Preadditive (DerivedCategory C) := Localization.preadditive Qh (HomotopyCategory.subcategoryAcyclic C).W instance : (Qh (C := C)).Additive := Localization.functor_additive Qh (HomotopyCategory.subcategoryAcyclic C).W 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).W ℤ noncomputable instance : (Qh (C := C)).CommShift ℤ := Functor.CommShift.localized Qh (HomotopyCategory.subcategoryAcyclic C).W ℤ 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).W] exact Functor.additive_of_iso (Qh.commShiftIso n) noncomputable instance : Pretriangulated (DerivedCategory C) := Triangulated.Localization.pretriangulated Qh (HomotopyCategory.subcategoryAcyclic C).W instance : (Qh (C := C)).IsTriangulated := Triangulated.Localization.isTriangulated_functor Qh (HomotopyCategory.subcategoryAcyclic C).W noncomputable instance : IsTriangulated (DerivedCategory C) := Triangulated.Localization.isTriangulated Qh (HomotopyCategory.subcategoryAcyclic C).W instance : (Qh (C := C)).mapArrow.EssSurj := Localization.essSurj_mapArrow _ (HomotopyCategory.subcategoryAcyclic C).W instance {D : Type*} [Category D] : ((whiskeringLeft _ _ D).obj (Qh (C := C))).Full := inferInstanceAs (Localization.whiskeringLeftFunctor' _ (HomotopyCategory.quasiIso _ _) D).Full instance {D : Type*} [Category D] : ((whiskeringLeft _ _ D).obj (Qh (C := C))).Faithful := inferInstanceAs (Localization.whiskeringLeftFunctor' _ (HomotopyCategory.quasiIso _ _) D).Faithful 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 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) end DerivedCategory
Algebra\Homology\DerivedCategory\ExactFunctor.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.DerivedCategory.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₂`. -/ 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
Algebra\Homology\DerivedCategory\Ext.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.DerivedCategory.Basic 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 (TODO). 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 AddCommGroupCat.{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 AddCommGroupCat.{u}` shall be in `Type (u + 1)`, these types are going to be `u`-small. Then, for `C := Sheaf X.etale AddCommGroupCat.{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`. ## TODO * compute `Ext X Y 0` * define the class in `Ext S.X₃ S.X₁ 1` of a short exact short complex `S` * construct the long exact sequences of `Ext`. -/ universe w' w v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] [Abelian C] open Localization Limits ZeroObject /-- 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) -- TODO: when the canonical t-structure is formalized, replace `n : ℤ` by `n : ℕ` lemma hasExt_iff [HasDerivedCategory.{w'} C] : HasExt.{w} C ↔ ∀ (X Y : C) (n : ℤ), Small.{w} ((DerivedCategory.singleFunctor C 0).obj X ⟶ (((DerivedCategory.singleFunctor C 0).obj Y)⟦n⟧)) := by dsimp [HasExt] simp only [hasSmallLocalizedShiftedHom_iff _ _ DerivedCategory.Q] constructor · intro h X Y n exact (small_congr ((shiftFunctorZero _ ℤ).app ((DerivedCategory.singleFunctor C 0).obj X)).homFromEquiv).1 (h X Y 0 n) · intro h X Y a b refine (small_congr ?_).1 (h X Y (b - a)) exact (Functor.FullyFaithful.ofFullyFaithful (shiftFunctor _ a)).homEquiv.trans ((shiftFunctorAdd' _ _ _ _ (Int.sub_add_cancel b a)).symm.app _).homToEquiv lemma hasExt_of_hasDerivedCategory [HasDerivedCategory.{w} C] : HasExt.{w} C := by rw [hasExt_iff.{w}] infer_instance 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 omega) 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 omega) = α.comp (β.comp γ h₂₃) (by omega) := SmallShiftedHom.comp_assoc _ _ _ _ _ _ (by omega) 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 ((DerivedCategory.singleFunctor C 0).obj X) ((DerivedCategory.singleFunctor C 0).obj Y) (n : ℤ) := SmallShiftedHom.equiv (HomologicalComplex.quasiIso C (ComplexShape.up ℤ)) DerivedCategory.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 ((DerivedCategory.singleFunctor C 0).obj X) ((DerivedCategory.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 omega) := 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) ((DerivedCategory.singleFunctor C 0).map f) := by apply SmallShiftedHom.equiv_mk₀ @[simp 1100] 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 1100] 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] omega 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 ((DerivedCategory.singleFunctor C 0).obj X) ((DerivedCategory.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 [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 [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 [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 [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 [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 [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'] section 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] attribute [local instance] preservesBinaryBiproductsOfPreservesBiproducts 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 (DerivedCategory.singleFunctor C 0) (BinaryBiproduct.isBilimit X₁ X₂)).isColimit all_goals assumption @[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_right_neg, add_right_neg, 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 ((DerivedCategory.singleFunctor C 0).obj X) ((DerivedCategory.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 ⥤ AddCommGrp.{w} where obj Y := AddCommGrp.of (Ext X Y n) map f := AddCommGrp.ofHom ((Ext.mk₀ f).postcomp _ (add_zero n)) map_comp f f' := by ext α dsimp [AddCommGrp.ofHom] rw [← Ext.mk₀_comp_mk₀] symm apply Ext.comp_assoc omega /-- The functor `Cᵒᵖ ⥤ C ⥤ AddCommGrp` which sends `X : C` and `Y : C` to `Ext X Y n`. -/ @[simps] noncomputable def extFunctor (n : ℕ) : Cᵒᵖ ⥤ C ⥤ AddCommGrp.{w} where obj X := extFunctorObj X.unop n map {X₁ X₂} f := { app := fun Y ↦ AddCommGrp.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 α dsimp rw [← Ext.mk₀_comp_mk₀] apply Ext.comp_assoc all_goals omega end Abelian end CategoryTheory
Algebra\Homology\DerivedCategory\HomologySequence.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.DerivedCategory.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. -/ 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 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 compatiblities with shifts. -/ noncomputable instance : (homologyFunctor C 0).ShiftSequence ℤ := Functor.ShiftSequence.induced (homologyFunctorFactorsh C 0) ℤ (homologyFunctor C) (homologyFunctorFactorsh C) variable {C} namespace HomologySequence variable (T : Triangle (DerivedCategory C)) (hT : T ∈ distTriang _) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) /-- The connecting homomorphism on the homology sequence attached to a distinguished triangle in the derived category. -/ noncomputable def δ : (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]) @[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
Algebra\Homology\DerivedCategory\ShortExact.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.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`.) -/ 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
Algebra\Homology\DerivedCategory\SingleTriangle.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.DerivedCategory.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 -/ 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₃) ?_ ?_ ?_ · aesop_cat · aesop_cat · dsimp [singleδ, e] rw [Category.assoc, Category.assoc, ← Functor.map_comp, SingleFunctors.inv_hom_id_hom_app] erw [Functor.map_id, comp_id] /-- 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
Algebra\Homology\Embedding\Basic.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ComplexShape import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Algebra.Ring.Int /-! # Embeddings of complex shapes Given two complex shapes `c : ComplexShape ι` and `c' : ComplexShape ι'`, an embedding from `c` to `c'` (`e : c.Embedding c'`) consists of the data of an injective map `f : ι → ι'` such that for all `i₁ i₂ : ι`, `c.Rel i₁ i₂` implies `c'.Rel (e.f i₁) (e.f i₂)`. We define a type class `e.IsRelIff` to express that this implication is an equivalence. Other type classes `e.IsTruncLE` and `e.IsTruncGE` are introduced in order to formalize truncation functors. This notion first appeared in the Liquid Tensor Experiment, and was developed there mostly by Johan Commelin, Adam Topaz and Joël Riou. It shall be used in order to relate the categories `CochainComplex C ℕ` and `ChainComplex C ℕ` to `CochainComplex C ℤ`. It shall also be used in the construction of the canonical t-structure on the derived category of an abelian category (TODO). ## TODO Define the following: - the extension functor `e.extendFunctor C : HomologicalComplex C c ⥤ HomologicalComplex C c'` (extending by the zero object outside of the image of `e.f`); - assuming `e.IsRelIff`, the restriction functor `e.restrictionFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c`; - the stupid truncation functor `e.stupidTruncFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c'` which is the composition of the two previous functors. - assuming `e.IsTruncGE`, truncation functors `e.truncGE'Functor C : HomologicalComplex C c' ⥤ HomologicalComplex C c` and `e.truncGEFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c'`, and a natural transformation `e.πTruncGENatTrans : 𝟭 _ ⟶ e.truncGEFunctor C` which is a quasi-isomorphism in degrees in the image of `e.f`; - assuming `e.IsTruncLE`, truncation functors `e.truncLE'Functor C : HomologicalComplex C c' ⥤ HomologicalComplex C c` and `e.truncLEFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c'`, and a natural transformation `e.ιTruncLENatTrans : e.truncGEFunctor C ⟶ 𝟭 _` which is a quasi-isomorphism in degrees in the image of `e.f`; -/ variable {ι ι' : Type*} (c : ComplexShape ι) (c' : ComplexShape ι') namespace ComplexShape /-- An embedding of a complex shape `c : ComplexShape ι` into a complex shape `c' : ComplexShape ι'` consists of a injective map `f : ι → ι'` which satisfies a compatiblity with respect to the relations `c.Rel` and `c'.Rel`. -/ structure Embedding where /-- the map between the underlying types of indices -/ f : ι → ι' injective_f : Function.Injective f rel {i₁ i₂ : ι} (h : c.Rel i₁ i₂) : c'.Rel (f i₁) (f i₂) namespace Embedding variable {c c'} variable (e : Embedding c c') /-- The opposite embedding in `Embedding c.symm c'.symm` of `e : Embedding c c'`. -/ @[simps] def op : Embedding c.symm c'.symm where f := e.f injective_f := e.injective_f rel h := e.rel h /-- An embedding of complex shapes `e` satisfies `e.IsRelIff` if the implication `e.rel` is an equivalence. -/ class IsRelIff : Prop where rel' (i₁ i₂ : ι) (h : c'.Rel (e.f i₁) (e.f i₂)) : c.Rel i₁ i₂ lemma rel_iff [e.IsRelIff] (i₁ i₂ : ι) : c'.Rel (e.f i₁) (e.f i₂) ↔ c.Rel i₁ i₂ := by constructor · apply IsRelIff.rel' · exact e.rel section variable (c c') variable (f : ι → ι') (hf : Function.Injective f) (iff : ∀ (i₁ i₂ : ι), c.Rel i₁ i₂ ↔ c'.Rel (f i₁) (f i₂)) /-- Constructor for embeddings between complex shapes when we have an equivalence `∀ (i₁ i₂ : ι), c.Rel i₁ i₂ ↔ c'.Rel (f i₁) (f i₂)`. -/ @[simps] def mk' : Embedding c c' where f := f injective_f := hf rel h := (iff _ _).1 h instance : (mk' c c' f hf iff).IsRelIff where rel' _ _ h := (iff _ _).2 h end /-- The condition that the image of the map `e.f` of an embedding of complex shapes `e : Embedding c c'` is stable by `c'.next`. -/ class IsTruncGE extends e.IsRelIff : Prop where mem_next {j : ι} {k' : ι'} (h : c'.Rel (e.f j) k') : ∃ k, e.f k = k' lemma mem_next [e.IsTruncGE] {j : ι} {k' : ι'} (h : c'.Rel (e.f j) k') : ∃ k, e.f k = k' := IsTruncGE.mem_next h /-- The condition that the image of the map `e.f` of an embedding of complex shapes `e : Embedding c c'` is stable by `c'.prev`. -/ class IsTruncLE extends e.IsRelIff : Prop where mem_prev {i' : ι'} {j : ι} (h : c'.Rel i' (e.f j)) : ∃ i, e.f i = i' lemma mem_prev [e.IsTruncLE] {i' : ι'} {j : ι} (h : c'.Rel i' (e.f j)) : ∃ i, e.f i = i' := IsTruncLE.mem_prev h open Classical in /-- The map `ι' → Option ι` which sends `e.f i` to `some i` and the other elements to `none`. -/ noncomputable def r (i' : ι') : Option ι := if h : ∃ (i : ι), e.f i = i' then some h.choose else none lemma r_eq_some {i : ι} {i' : ι'} (hi : e.f i = i') : e.r i' = some i := by have h : ∃ (i : ι), e.f i = i' := ⟨i, hi⟩ have : h.choose = i := e.injective_f (h.choose_spec.trans (hi.symm)) dsimp [r] rw [dif_pos ⟨i, hi⟩, this] lemma r_eq_none (i' : ι') (hi : ∀ i, e.f i ≠ i') : e.r i' = none := dif_neg (by rintro ⟨i, hi'⟩ exact hi i hi') @[simp] lemma r_f (i : ι) : e.r (e.f i) = some i := r_eq_some _ rfl lemma f_eq_of_r_eq_some {i : ι} {i' : ι'} (hi : e.r i' = some i) : e.f i = i' := by by_cases h : ∃ (k : ι), e.f k = i' · obtain ⟨k, rfl⟩ := h rw [r_f] at hi congr 1 simpa using hi.symm · simp [e.r_eq_none i' (by simpa using h)] at hi end Embedding /-- The obvious embedding from `up ℕ` to `up ℤ`. -/ @[simps!] def embeddingUpNat : Embedding (up ℕ) (up ℤ) := Embedding.mk' _ _ (fun n => n) (fun _ _ h => by simpa using h) (by dsimp; omega) instance : embeddingUpNat.IsRelIff := by dsimp [embeddingUpNat]; infer_instance instance : embeddingUpNat.IsTruncGE where mem_next {j _} h := ⟨j + 1, h⟩ /-- The embedding from `down ℕ` to `up ℤ` with sends `n` to `-n`. -/ @[simps!] def embeddingDownNat : Embedding (down ℕ) (up ℤ) := Embedding.mk' _ _ (fun n => -n) (fun _ _ h => by simpa using h) (by dsimp; omega) instance : embeddingDownNat.IsRelIff := by dsimp [embeddingDownNat]; infer_instance instance : embeddingDownNat.IsTruncLE where mem_prev {i j} h := ⟨j + 1, by dsimp at h ⊢; omega⟩ variable (p : ℤ) /-- The embedding from `up ℕ` to `up ℤ` which sends `n : ℕ` to `p + n`. -/ @[simps!] def embeddingUpIntGE : Embedding (up ℕ) (up ℤ) := Embedding.mk' _ _ (fun n => p + n) (fun _ _ h => by dsimp at h; omega) (by dsimp; omega) instance : (embeddingUpIntGE p).IsRelIff := by dsimp [embeddingUpIntGE]; infer_instance instance : (embeddingUpIntGE p).IsTruncGE where mem_next {j _} h := ⟨j + 1, by dsimp at h ⊢; omega⟩ /-- The embedding from `down ℕ` to `up ℤ` which sends `n : ℕ` to `p - n`. -/ @[simps!] def embeddingUpIntLE : Embedding (down ℕ) (up ℤ) := Embedding.mk' _ _ (fun n => p - n) (fun _ _ h => by dsimp at h; omega) (by dsimp; omega) instance : (embeddingUpIntLE p).IsRelIff := by dsimp [embeddingUpIntLE]; infer_instance instance : (embeddingUpIntLE p).IsTruncLE where mem_prev {_ k} h := ⟨k + 1, by dsimp at h ⊢; omega⟩ end ComplexShape
Algebra\Homology\Embedding\Boundary.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Embedding.Basic import Mathlib.Algebra.Homology.HomologicalComplex /-! # Boundary of an embedding of complex shapes In the file `Mathlib.Algebra.Homology.Embedding.Basic`, given `p : ℤ`, we have defined an embedding `embeddingUpIntGE p` of `ComplexShape.up ℕ` in `ComplexShape.up ℤ` which sends `n : ℕ` to `p + n`. The (canonical) truncation (`≥ p`) of `K : CochainComplex C ℤ` shall be defined as the extension to `ℤ` (see `Mathlib.Algebra.Homology.Embedding.Extend`) of a certain cochain complex indexed by `ℕ`: `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`). In this case, we see that the degree `0 : ℕ` needs a particular attention when constructing the truncation. In this file, more generally, for `e : Embedding c c'`, we define a predicate `ι → Prop` named `e.BoundaryGE` which shall be relevant when constructing the truncation `K.truncGE e` when `e.IsTruncGE`. In the case of `embeddingUpIntGE p`, we show that `0 : ℕ` is the only element in this lower boundary. Similarly, we define `Embedding.BoundaryLE`. -/ namespace ComplexShape namespace Embedding variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} (e : Embedding c c') /-- The lower boundary of an embedding `e : Embedding c c'`, as a predicate on `ι`. It is satisfied by `j : ι` when there exists `i' : ι'` not in the image of `e.f` such that `c'.Rel i' (e.f j)`. -/ def BoundaryGE (j : ι) : Prop := c'.Rel (c'.prev (e.f j)) (e.f j) ∧ ∀ i, ¬c'.Rel (e.f i) (e.f j) lemma boundaryGE {i' : ι'} {j : ι} (hj : c'.Rel i' (e.f j)) (hi' : ∀ i, e.f i ≠ i') : e.BoundaryGE j := by constructor · simpa only [c'.prev_eq' hj] using hj · intro i hi apply hi' i rw [← c'.prev_eq' hj, c'.prev_eq' hi] lemma not_boundaryGE_next [e.IsRelIff] {j k : ι} (hk : c.Rel j k) : ¬ e.BoundaryGE k := by dsimp [BoundaryGE] simp only [not_and, not_forall, not_not] intro exact ⟨j, by simpa only [e.rel_iff] using hk⟩ lemma not_boundaryGE_next' [e.IsRelIff] {j k : ι} (hj : ¬ e.BoundaryGE j) (hk : c.next j = k) : ¬ e.BoundaryGE k := by by_cases hjk : c.Rel j k · exact e.not_boundaryGE_next hjk · subst hk simpa only [c.next_eq_self j hjk] using hj variable {e} in lemma BoundaryGE.not_mem {j : ι} (hj : e.BoundaryGE j) {i' : ι'} (hi' : c'.Rel i' (e.f j)) (a : ι) : e.f a ≠ i' := fun ha => hj.2 a (by simpa only [ha] using hi') lemma prev_f_of_not_boundaryGE [e.IsRelIff] {i j : ι} (hij : c.prev j = i) (hj : ¬ e.BoundaryGE j) : c'.prev (e.f j) = e.f i := by by_cases hij' : c.Rel i j · exact c'.prev_eq' (by simpa only [e.rel_iff] using hij') · obtain rfl : j = i := by simpa only [c.prev_eq_self j (by simpa only [hij] using hij')] using hij apply c'.prev_eq_self intro hj' simp only [BoundaryGE, not_and, not_forall, not_not] at hj obtain ⟨i, hi⟩ := hj hj' rw [e.rel_iff] at hi rw [c.prev_eq' hi] at hij exact hij' (by simpa only [hij] using hi) variable {e} in lemma BoundaryGE.false_of_isTruncLE {j : ι} (hj : e.BoundaryGE j) [e.IsTruncLE] : False := by obtain ⟨i, hi⟩ := e.mem_prev hj.1 exact hj.2 i (by simpa only [hi] using hj.1) /-- The upper boundary of an embedding `e : Embedding c c'`, as a predicate on `ι`. It is satisfied by `j : ι` when there exists `k' : ι'` not in the image of `e.f` such that `c'.Rel (e.f j) k'`. -/ def BoundaryLE (j : ι) : Prop := c'.Rel (e.f j) (c'.next (e.f j)) ∧ ∀ k, ¬c'.Rel (e.f j) (e.f k) lemma boundaryLE {k' : ι'} {j : ι} (hj : c'.Rel (e.f j) k') (hk' : ∀ i, e.f i ≠ k') : e.BoundaryLE j := by constructor · simpa only [c'.next_eq' hj] using hj · intro k hk apply hk' k rw [← c'.next_eq' hj, c'.next_eq' hk] lemma not_boundaryLE_prev [e.IsRelIff] {i j : ι} (hi : c.Rel i j) : ¬ e.BoundaryLE i := by dsimp [BoundaryLE] simp only [not_and, not_forall, not_not] intro exact ⟨j, by simpa only [e.rel_iff] using hi⟩ lemma not_boundaryLE_prev' [e.IsRelIff] {i j : ι} (hj : ¬ e.BoundaryLE j) (hk : c.prev j = i) : ¬ e.BoundaryLE i := by by_cases hij : c.Rel i j · exact e.not_boundaryLE_prev hij · subst hk simpa only [c.prev_eq_self j hij] using hj variable {e} in lemma BoundaryLE.not_mem {j : ι} (hj : e.BoundaryLE j) {k' : ι'} (hk' : c'.Rel (e.f j) k') (a : ι) : e.f a ≠ k' := fun ha => hj.2 a (by simpa only [ha] using hk') lemma next_f_of_not_boundaryLE [e.IsRelIff] {j k : ι} (hjk : c.next j = k) (hj : ¬ e.BoundaryLE j) : c'.next (e.f j) = e.f k := by by_cases hjk' : c.Rel j k · exact c'.next_eq' (by simpa only [e.rel_iff] using hjk') · obtain rfl : j = k := by simpa only [c.next_eq_self j (by simpa only [hjk] using hjk')] using hjk apply c'.next_eq_self intro hj' simp only [BoundaryLE, not_and, not_forall, not_not] at hj obtain ⟨k, hk⟩ := hj hj' rw [e.rel_iff] at hk rw [c.next_eq' hk] at hjk exact hjk' (by simpa only [hjk] using hk) variable {e} in lemma BoundaryLE.false_of_isTruncGE {j : ι} (hj : e.BoundaryLE j) [e.IsTruncGE] : False := by obtain ⟨k, hk⟩ := e.mem_next hj.1 exact hj.2 k (by simpa only [hk] using hj.1) end Embedding lemma boundaryGE_embeddingUpIntGE_iff (p : ℤ) (n : ℕ) : (embeddingUpIntGE p).BoundaryGE n ↔ n = 0 := by constructor · intro h obtain _|n := n · rfl · have := h.2 n dsimp at this omega · rintro rfl constructor · simp · intro i hi dsimp at hi omega lemma boundaryLE_embeddingUpIntLE_iff (p : ℤ) (n : ℕ) : (embeddingUpIntGE p).BoundaryGE n ↔ n = 0 := by constructor · intro h obtain _|n := n · rfl · have := h.2 n dsimp at this omega · rintro rfl constructor · simp · intro i hi dsimp at hi omega end ComplexShape
Algebra\Homology\Embedding\Extend.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Embedding.Basic import Mathlib.Algebra.Homology.HomologicalComplex /-! # 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'`. 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] [HasZeroMorphisms C] (K : HomologicalComplex C c) (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 _ /-- 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 dsimp [XIso, d] erw [id_comp, comp_id] 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 dsimp 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 dsimp 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' (by obtain hi'|⟨i, hi⟩ := (e.r i').eq_none_or_eq_some · exact hi' · exfalso exact hi' _ (e.f_eq_of_r_eq_some 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 end HomologicalComplex
Algebra\Homology\Embedding\IsSupported.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Embedding.Basic import Mathlib.Algebra.Homology.Opposite import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex /-! # Support of homological complexes Given an embedding `e : c.Embedding c'` of complex shapes, we say that `K : HomologicalComplex C c'` is supported (resp. strictly supported) on `e` if `K` is exact in degree `i'` (resp. `K.X i'` is zero) whenever `i'` is not of the form `e.f i`. This defines two typeclasses `K.IsSupported e` and `K.IsStrictlySupported e`. We also define predicates `K.IsSupportedOutside e` and `K.IsStrictlySupportedOutside e` when the conditions above are satisfied for those `i'` that are of the form `e.f i`. (These two predicates are not made typeclasses because in most practical applications, they are equivalent to `K.IsSupported e'` or `K.IsStrictlySupported e'` for a complementary embedding `e'`.) -/ open CategoryTheory Limits ZeroObject variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} namespace HomologicalComplex section variable {C : Type*} [Category C] [HasZeroMorphisms C] (K L : HomologicalComplex C c') (e' : K ≅ L) (e : c.Embedding c') /-- If `K : HomologicalComplex C c'`, then `K.IsStrictlySupported e` holds for an embedding `e : c.Embedding c'` of complex shapes if `K.X i'` is zero wheneverm `i'` is not of the form `e.f i` for some `i`.-/ class IsStrictlySupported : Prop where isZero (i' : ι') (hi' : ∀ i, e.f i ≠ i') : IsZero (K.X i') lemma isZero_X_of_isStrictlySupported [K.IsStrictlySupported e] (i' : ι') (hi' : ∀ i, e.f i ≠ i') : IsZero (K.X i') := IsStrictlySupported.isZero i' hi' variable {K L} in lemma isStrictlySupported_of_iso [K.IsStrictlySupported e] : L.IsStrictlySupported e where isZero i' hi' := (K.isZero_X_of_isStrictlySupported e i' hi').of_iso ((eval _ _ i').mapIso e'.symm) /-- If `K : HomologicalComplex C c'`, then `K.IsStrictlySupported e` holds for an embedding `e : c.Embedding c'` of complex shapes if `K` is exact at `i'` whenever `i'` is not of the form `e.f i` for some `i`.-/ class IsSupported : Prop where exactAt (i' : ι') (hi' : ∀ i, e.f i ≠ i') : K.ExactAt i' lemma exactAt_of_isSupported [K.IsSupported e] (i' : ι') (hi' : ∀ i, e.f i ≠ i') : K.ExactAt i' := IsSupported.exactAt i' hi' variable {K L} in lemma isSupported_of_iso [K.IsSupported e] : L.IsSupported e where exactAt i' hi' := (K.exactAt_of_isSupported e i' hi').of_iso e' instance [K.IsStrictlySupported e] : K.IsSupported e where exactAt i' hi' := by rw [exactAt_iff] exact ShortComplex.exact_of_isZero_X₂ _ (K.isZero_X_of_isStrictlySupported e i' hi') /-- If `K : HomologicalComplex C c'`, then `K.IsStrictlySupportedOutside e` holds for an embedding `e : c.Embedding c'` of complex shapes if `K.X (e.f i)` is zero for all `i`. -/ structure IsStrictlySupportedOutside : Prop where isZero (i : ι) : IsZero (K.X (e.f i)) /-- If `K : HomologicalComplex C c'`, then `K.IsSupportedOutside e` holds for an embedding `e : c.Embedding c'` of complex shapes if `K` is exact at `e.f i` for all `i`. -/ structure IsSupportedOutside : Prop where exactAt (i : ι) : K.ExactAt (e.f i) variable {K e} in lemma IsStrictlySupportedOutside.isSupportedOutside (h : K.IsStrictlySupportedOutside e) : K.IsSupportedOutside e where exactAt i := by rw [exactAt_iff] exact ShortComplex.exact_of_isZero_X₂ _ (h.isZero i) instance [HasZeroObject C] : (0 : HomologicalComplex C c').IsStrictlySupported e where isZero i _ := (eval _ _ i).map_isZero (Limits.isZero_zero _) lemma isZero_iff_isStrictlySupported_and_isStrictlySupportedOutside : IsZero K ↔ K.IsStrictlySupported e ∧ K.IsStrictlySupportedOutside e := by constructor · intro hK constructor all_goals constructor intros exact (eval _ _ _).map_isZero hK · rintro ⟨h₁, h₂⟩ rw [IsZero.iff_id_eq_zero] ext n apply IsZero.eq_of_src by_cases hn : ∃ i, e.f i = n · obtain ⟨i, rfl⟩ := hn exact h₂.isZero i · exact K.isZero_X_of_isStrictlySupported e _ (by simpa using hn) instance [K.IsStrictlySupported e] : K.op.IsStrictlySupported e.op where isZero j hj' := (K.isZero_X_of_isStrictlySupported e j hj').op end section variable {C D : Type*} [Category C] [Category D] [HasZeroMorphisms C] [HasZeroMorphisms D] (K : HomologicalComplex C c') (F : C ⥤ D) [F.PreservesZeroMorphisms] (e : c.Embedding c') instance map_isStrictlySupported [K.IsStrictlySupported e] : ((F.mapHomologicalComplex c').obj K).IsStrictlySupported e where isZero i' hi' := by rw [IsZero.iff_id_eq_zero] dsimp rw [← F.map_id, (K.isZero_X_of_isStrictlySupported e i' hi').eq_of_src (𝟙 _) 0, F.map_zero] end end HomologicalComplex
Algebra\Homology\Embedding\Restriction.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Embedding.Basic import Mathlib.Algebra.Homology.Additive /-! # The restriction functor of an embedding of complex shapes Given `c` and `c'` complex shapes on two types, and `e : c.Embedding c'` (satisfying `[e.IsRelIff]`), we define the restriction functor `e.restrictionFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c`. -/ open CategoryTheory Category Limits ZeroObject variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} namespace HomologicalComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (K L M : HomologicalComplex C c') (φ : K ⟶ L) (φ' : L ⟶ M) (e : c.Embedding c') [e.IsRelIff] /-- Given `K : HomologicalComplex C c'` and `e : c.Embedding c'` (satisfying `[e.IsRelIff]`), this is the homological complex in `HomologicalComplex C c` obtained by restriction. -/ @[simps] def restriction : HomologicalComplex C c where X i := K.X (e.f i) d _ _ := K.d _ _ shape i j hij := K.shape _ _ (by simpa only [← e.rel_iff] using hij) /-- The isomorphism `(K.restriction e).X i ≅ K.X i'` when `e.f i = i'`. -/ def restrictionXIso {i : ι} {i' : ι'} (h : e.f i = i') : (K.restriction e).X i ≅ K.X i' := eqToIso (h ▸ rfl) @[reassoc] lemma restriction_d_eq {i j : ι} {i' j' : ι'} (hi : e.f i = i') (hj : e.f j = j') : (K.restriction e).d i j = (K.restrictionXIso e hi).hom ≫ K.d i' j' ≫ (K.restrictionXIso e hj).inv := by subst hi hj simp [restrictionXIso] variable {K L} /-- The morphism `K.restriction e ⟶ L.restriction e` induced by a morphism `φ : K ⟶ L`. -/ @[simps] def restrictionMap : K.restriction e ⟶ L.restriction e where f i := φ.f (e.f i) @[reassoc] lemma restrictionMap_f' {i : ι} {i' : ι'} (hi : e.f i = i') : (restrictionMap φ e).f i = (K.restrictionXIso e hi).hom ≫ φ.f i' ≫ (L.restrictionXIso e hi).inv := by subst hi simp [restrictionXIso] variable (K) @[simp] lemma restrictionMap_id : restrictionMap (𝟙 K) e = 𝟙 _ := rfl @[simp, reassoc] lemma restrictionMap_comp : restrictionMap (φ ≫ φ') e = restrictionMap φ e ≫ restrictionMap φ' e := rfl end HomologicalComplex namespace ComplexShape.Embedding variable (e : Embedding c c') (C : Type*) [Category C] [HasZeroObject C] [e.IsRelIff] /-- Given `e : ComplexShape.Embedding c c'`, this is the restriction functor `HomologicalComplex C c' ⥤ HomologicalComplex C c`. -/ @[simps] noncomputable def restrictionFunctor [HasZeroMorphisms C] : HomologicalComplex C c' ⥤ HomologicalComplex C c where obj K := K.restriction e map φ := HomologicalComplex.restrictionMap φ e instance [HasZeroMorphisms C] : (e.restrictionFunctor C).PreservesZeroMorphisms where instance [Preadditive C] : (e.restrictionFunctor C).Additive where end ComplexShape.Embedding
Algebra\Homology\Embedding\TruncGE.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Embedding.Boundary import Mathlib.Algebra.Homology.Embedding.Extend 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`. ## TODO * construct a morphism `K.πTruncGE e : K ⟶ K.truncGE e` and show that it 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] 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 HomologicalComplex
Algebra\Homology\Factorizations\Basic.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.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
Algebra\Homology\HomotopyCategory\DegreewiseSplit.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory.Pretriangulated /-! 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. -/ open CategoryTheory Category Limits Pretriangulated Preadditive variable {C : Type*} [Category 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 omega) (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 omega) _ p (p + 2) (by omega) (p + 1) (p + 1) (by omega) (by omega), 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, add_left_neg]) /-- 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] set_option tactic.skipAssignedInstances false in /-- 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 ⊢ simp? [mappingCone.ext_from_iff _ (p + 1) _ rfl, reassoc_of% f_r, reassoc_of% s_g] says 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_left_eq_self, 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 set_option backward.isDefEq.lazyWhnfCore false in -- See https://github.com/leanprover-community/mathlib4/issues/12534 /-- 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 set_option tactic.skipAssignedInstances false in simp [mappingConeHomOfDegreewiseSplitXIso, mappingCone.ext_from_iff _ _ _ rfl, mappingCone.inl_v_d_assoc _ (p + 1) _ (p + 1 + 1) (by linarith) (by linarith), cocycleOfDegreewiseSplit, r_f] rw [← S.g.comm_assoc, reassoc_of% s_g] 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 simp [mappingConeHomOfDegreewiseSplitXIso] /-- 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 aesop_cat) (by aesop_cat) (by aesop_cat) /-- 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 aesop_cat) (by aesop_cat) (by aesop_cat) /-- 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
Algebra\Homology\HomotopyCategory\HomComplex.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Homotopy import Mathlib.Algebra.Ring.NegOnePow import Mathlib.Algebra.Category.Grp.Preadditive import Mathlib.Tactic.Linarith import Mathlib.CategoryTheory.Linear.LinearFunctor /-! 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] -/ 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 p q hpq obtain rfl : q = p := by rw [← hpq, add_zero] exact h q @[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 aesop_cat @[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 aesop_cat @[simp] lemma ofHom_sub (φ₁ φ₂ : F ⟶ G) : Cochain.ofHom (φ₁ - φ₂) = Cochain.ofHom φ₁ - Cochain.ofHom φ₂ := by aesop_cat @[simp] lemma ofHom_neg (φ : F ⟶ G) : Cochain.ofHom (-φ) = -Cochain.ofHom φ := by aesop_cat /-- 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 omega)) /-! 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 omega), comp_v z₁ z₂ rfl p (p + n₁) (p + n₁ + n₂) (by omega) (by omega), comp_v z₁ (z₂.comp z₃ rfl) (add_assoc n₁ n₂ n₃).symm p (p + n₁) q (by omega) (by omega), comp_v z₂ z₃ rfl (p + n₁) (p + n₁ + n₂) q (by omega) (by omega), 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 omega) @[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 omega) @[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 omega) @[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_self, add_zero]) = z₁.comp (z₂.comp z₃ (neg_add_self n₂)) (add_zero n₁) := comp_assoc _ _ _ _ _ (by omega) @[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 omega), 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 omega), 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 omega), 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 omega), 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 omega), 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 omega), 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 omega), 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 omega), 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 omega), 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 omega), 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 aesop_cat @[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 omega obtain rfl : q₂ = p + m - n := by omega 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 omega) 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, add_right_inj, 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 omega) (q-2) _ (by omega) rfl, δ_v n₀ n₁ h₀₁ z (p+1) q (by omega) _ (p+2) rfl (by omega), ← 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_right_neg, 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 omega), Cochain.comp_v _ _ (show n₁ + 1 + n₂ = n₁ + n₂ + 1 by omega) p (p+n₁+1) q (by linarith) (by omega), δ_v (n₁ + n₂) _ rfl (z₁.comp z₂ rfl) p q hpq (p + n₁ + n₂) _ (by omega) rfl, z₁.comp_v z₂ rfl p _ _ rfl rfl, z₁.comp_v z₂ rfl (p+1) (p+n₁+1) q (by omega) (by omega), δ_v n₂ (n₂+1) rfl z₂ (p+n₁) q (by omega) (p+n₁+n₂) _ (by omega) rfl, δ_v n₁ (n₁+1) rfl z₁ p (p+n₁+1) (by omega) (p+n₁) _ (by omega) 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 omega) hpq, zero_add, 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] intro exact h (by omega) @[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_self 1) _ p p (add_zero p) (p-1) (p+1) rfl rfl] simp only [Cochain.mk_v, add_left_neg, 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_self 1) _ p p (add_zero p) (p-1) (p+1) rfl rfl] simp only [neg_add_self, 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`. -/ -- We also constructed the `d_apply` lemma using `@[simps]` -- until we made `AddCommGrp.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] @[simps! X] def HomComplex : CochainComplex AddCommGrp ℤ where X i := AddCommGrp.of (Cochain F G i) d i j := AddCommGrp.ofHom (δ_hom ℤ F G i j) shape _ _ hij := by ext; apply δ_shape _ _ hij d_comp_d' _ _ _ _ _ := by ext; apply δ_δ 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 aesop_cat @[simp] lemma ofHom_homOf_eq_self (z : Cocycle F G 0) : ofHom (homOf z) = z := by aesop_cat @[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 aesop_cat 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] lemma map_add : (z + z').map Φ = z.map Φ + z'.map Φ := by aesop_cat @[simp] lemma map_neg : (-z).map Φ = -z.map Φ := by aesop_cat @[simp] lemma map_sub : (z - z').map Φ = z.map Φ - z'.map Φ := by aesop_cat variable (K L n) @[simp] lemma map_zero : (0 : Cochain K L n).map Φ = 0 := by aesop_cat @[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 omega), Φ.map_comp] @[simp] lemma map_ofHom : (Cochain.ofHom f).map Φ = Cochain.ofHom ((Φ.mapHomologicalComplex _).map f) := by aesop_cat 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
Algebra\Homology\HomotopyCategory\HomComplexShift.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory.HomComplex import Mathlib.Algebra.Homology.HomotopyCategory.Shift /-! 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`. 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] -/ 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 omega)).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 omega)) 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 omega 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 linarith)).inv ≫ γ.v (p-a) q (by omega)) 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 omega)).inv ≫ γ.v p' q (by omega) := by obtain rfl : p' = p - a := by omega 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 omega) ≫ (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 omega) := 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 omega), γ.leftShift_v a n' hn' (q-n') q (by omega) 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 omega), γ.leftUnshift_v n hn' (q-n) q (by omega) 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 omega), add_v, comp_add, smul_add] @[simp] lemma shift_add (a : ℤ) : (γ₁ + γ₂).shift a = γ₁.shift a + γ₂.shift a := by ext p q hpq simp [shift_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 right_inv γ := by simp map_add' γ γ' := by simp /-- 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 right_inv γ := by simp map_add' γ γ' := by simp /-- 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 simp) 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 _root_.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 _root_.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 _root_.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 _root_.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 _root_.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 _root_.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 _root_.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 _root_.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 _root_.map_neg @[simp] lemma shift_neg (a : ℤ) : (-γ).shift a = -γ.shift a := by change shiftAddHom K L n a (-γ) = _ apply _root_.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 _root_.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 _root_.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 omega), 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 simp [shift_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 simp) /-- 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 simp) /-- 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 simp 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 simp [shift_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 omega) := by ext p q hpq rw [(γ.comp γ' hnm).rightUnshift_v nm' hnm' p q hpq (p + n + m) (by omega), γ.comp_v γ' hnm p (p + n) (p + n + m) rfl rfl, comp_v _ _ (show n + m' = nm' by omega) p (p + n) q (by omega) (by omega), γ'.rightUnshift_v m' hm' (p + n) q (by omega) (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 linarith dsimp simp only [Cochain.comp_v _ _ h' p (p + n') q rfl (by omega), γ.leftShift_v a n' hn' p (p + n') rfl (p + a) (by omega), (γ.comp γ' h).leftShift_v a t' (by omega) p q hpq (p + a) (by omega), smul_smul, Linear.units_smul_comp, assoc, Int.negOnePow_add, ← mul_assoc, ← h', comp_v _ _ h (p + a) (p + n') q (by omega) (by omega)] 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 omega) rfl, δ_v n' m' hnm' _ p q hpq (p+n') (p+1) (by omega) rfl, γ.rightShift_v a n' hn' p (p+n') rfl (p+n) rfl, γ.rightShift_v a n' hn' (p+1) q _ (p+m) (by omega)] 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] congr 1 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 omega) 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 omega), δ_v n m hnm _ (p+a) q (by omega) (p+n') (p+1+a) (by omega) (by omega), δ_v n' m' hnm' _ p q hpq (p+n') (p+1) (by omega) rfl, γ.leftShift_v a n' hn' p (p+n') rfl (p+a) (by omega), γ.leftShift_v a n' hn' (p+1) q (by omega) (p+1+a) (by omega)] 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 omega) 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', sub_add_cancel, 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 omega) (q - 1 + a) (p + 1 + a) (by omega) (by omega), 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 omega), rightShift_v _ a n' hn' (p + a) q (by omega) (q + a) (by omega), 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 omega), leftShift_v _ a n' hn' p (q + a) (by omega) (p + a) (by omega), 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 omega), δ_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 omega), δ_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 omega), δ_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) end Cocycle end CochainComplex.HomComplex
Algebra\Homology\HomotopyCategory\HomologicalFunctor.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.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 of a short exact sequences of homological complexes. -/ 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
Algebra\Homology\HomotopyCategory\MappingCone.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory.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`. -/ open CategoryTheory Limits variable {C D : Type*} [Category C] [Category 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; omega)) /-- 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 omega) (by ext p _ rfl simp [δ_v 1 2 (by omega) _ p (p + 2) (by omega) (p + 1) (p + 1) (by omega) 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_self 1) = Cochain.ofHom (𝟙 F) := by ext p simp [Cochain.comp_v _ _ (neg_add_self 1) p (p-1) p rfl (by omega)] @[simp] lemma inl_snd : (inl φ).comp (snd φ) (add_zero (-1)) = 0 := by ext p q hpq simp [Cochain.comp_v _ _ (add_zero (-1)) p q q (by omega) (by omega)] @[simp] lemma inr_fst : (Cochain.ofHom (inr φ)).comp (fst φ).1 (zero_add 1) = 0 := by ext p q hpq simp [Cochain.comp_v _ _ (zero_add 1) p p q (by omega) (by omega)] @[simp] lemma inr_snd : (Cochain.ofHom (inr φ)).comp (snd φ) (zero_add 0) = Cochain.ofHom (𝟙 G) := by aesop_cat /-! 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_self 1) (by omega) (by omega), 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 omega 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 omega 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 omega 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 omega) ≫ f = (inl φ).v i j (by omega) ≫ 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 omega) ≫ f = (inl φ).v i j (by omega) ≫ 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 omega) + 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 omega) ≫ 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 omega) 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 omega) = (inl φ).comp γ₂ (by omega) ∧ (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 omega) replace h₂ := Cochain.congr_v h₂ p q (by omega) simp only [Cochain.comp_v (inl φ) _ _ (p + 1) p q (by omega) 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_self 1) + (snd φ).comp (Cochain.ofHom (inr φ)) (add_zero 0) = Cochain.ofHom (𝟙 _) := by simp [ext_cochain_from_iff φ (-1) 0 (neg_add_self 1)] lemma id_X (p q : ℤ) (hpq : p + 1 = q) : (fst φ).1.v p q hpq ≫ (inl φ).v q p (by omega) + (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_self 1) p q p hpq (by omega)] 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; omega) (by dsimp; omega)] abel @[reassoc (attr := simp 1100)] lemma inr_f_d (n₁ n₂ : ℤ) : (inr φ).f n₁ ≫ (mappingCone φ).d n₁ n₂ = G.d n₁ n₂ ≫ (inr φ).f n₂ := by apply Hom.comm @[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 omega) ≫ F.d i j := d_fst_v φ (i - 1) i j (by omega) 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 omega) ≫ φ.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_self 1) (inl φ) p p (add_zero p) _ _ rfl rfl, inl_v_d φ p (p - 1) (p + 1) (by omega) (by omega)] @[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 : ℤ} (α : Cochain F K m) (β : Cochain G K n) (h : m + 1 = n) /-- 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 (mappingCone φ) K n := (fst φ).1.comp α (by rw [← h, add_comm]) + (snd φ).comp β (zero_add n) @[simp] lemma inl_descCochain : (inl φ).comp (descCochain φ α β h) (by omega) = α := 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 omega) p₁ p₂ p₃ (by omega) (by omega)] using Cochain.congr_v (inl_descCochain φ α β h) p₁ p₃ (by omega) @[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 omega) 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 omega) + (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 omega) (by omega), 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 ℤ} (α : Cochain F K (-1)) (β : G ⟶ K) (eq : δ (-1) 0 α = Cochain.ofHom (φ ≫ β)) /-- 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 : mappingCone φ ⟶ K := Cocycle.homOf (descCocycle φ α (Cocycle.ofHom β) (neg_add_self 1) (by simp [eq])) @[simp] lemma ofHom_desc : Cochain.ofHom (desc φ α β eq) = descCochain φ α (Cochain.ofHom β) (neg_add_self 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 aesop_cat lemma desc_f (p q : ℤ) (hpq : p + 1 = q) : (desc φ α β eq).f p = (fst φ).1.v p q hpq ≫ α.v q p (by omega) + (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 norm_num), by simp only [Cochain.ofHom_comp] at h₂ simp [ext_cochain_from_iff _ _ _ (neg_add_self 1), δ_descCochain _ _ _ _ _ (neg_add_self 1), h₁, h₂]⟩ section variable {K : CochainComplex C ℤ} {n m : ℤ} (α : Cochain K F m) (β : Cochain K G n) (h : n + 1 = 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 (mappingCone φ) n := α.comp (inl φ) (by omega) + β.comp (Cochain.ofHom (inr φ)) (add_zero n) @[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 omega) := by simpa only [Cochain.comp_v _ _ h p₁ p₂ p₃ h₁₂ h₂₃] using Cochain.congr_v (liftCochain_fst φ α β h) p₁ p₃ (by omega) @[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 omega) lemma δ_liftCochain (m' : ℤ) (hm' : m + 1 = m') : δ n m (liftCochain φ α β h) = -(δ m m' α).comp (inl φ) (by omega) + (δ 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_self 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 omega 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_self 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 omega) + β.comp β' (by omega) := by simp [liftCochain, descCochain, Cochain.comp_assoc α (inl φ) _ _ (show -1 + n' = m' by omega) (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 omega) + β.v p₁ p₂ h₁₂ ≫ β'.v p₂ p₃ h₂₃ := by have eq := Cochain.congr_v (liftCochain_descCochain φ α β α' β' h h' p hp) p₁ p₃ (by omega) simpa only [Cochain.comp_v _ _ hp p₁ p₂ p₃ h₁₂ h₂₃, Cochain.add_v, Cochain.comp_v _ _ _ _ _ _ hq (show q + m' = p₃ by omega)] 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_self 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 omega), 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 omega), mapHomologicalComplexXIso'_hom, mapHomologicalComplexXIso'_hom] constructor · dsimp simp only [Functor.mapHomologicalComplex_obj_X, Functor.mapHomologicalComplex_obj_d, comp_neg, add_comp, assoc, inl_v_fst_v_assoc, inr_f_fst_v_assoc, zero_comp, comp_zero, add_zero, comp_add, inl_v_fst_v, comp_id, inr_f_fst_v, ← H.map_comp, d_fst_v φ n (n + 1) (n + 2) rfl (by omega), 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
Algebra\Homology\HomotopyCategory\Pretriangulated.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory.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 -/ 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 simp [triangle, Cochain.rightShift_v _ 1 0 (zero_add 1) q q (add_zero q) p (by omega)] @[reassoc (attr := simp)] lemma inr_f_triangle_mor₃_f (p : ℤ) : (inr φ).f p ≫ (triangle φ).mor₃.f p = 0 := by simp [triangle, Cochain.rightShift_v _ 1 0 _ p p (add_zero p) (p+1) rfl] @[reassoc (attr := simp)] lemma inr_triangleδ : inr φ ≫ (triangle φ).mor₃ = 0 := by aesop_cat /-- 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) /-- The mapping cone of the identity is contractible. -/ noncomputable def homotopyToZeroOfId : Homotopy (𝟙 (mappingCone (𝟙 K))) 0 := descHomotopy (𝟙 K) _ _ 0 (inl _) (by simp) (by simp) variable {K} 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 simp [ext_from_iff _ _ _ rfl, triangle, mapOfHomotopy, Cochain.rightShift_v _ 1 0 _ p p _ (p + 1) rfl] /-- 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] erw [← NatTrans.naturality] rfl 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₂) (comm : φ₁ ≫ b = a ≫ φ₂) (a' : K₂ ⟶ K₃) (b' : L₂ ⟶ L₃) (comm' : φ₂ ≫ b' = a' ≫ φ₃) /-- The morphism `mappingCone φ₁ ⟶ mappingCone φ₂` that is induced by a commutative square. -/ noncomputable def map : mappingCone φ₁ ⟶ mappingCone φ₂ := desc φ₁ ((Cochain.ofHom a).comp (inl φ₂) (zero_add _)) (b ≫ inr φ₂) (by simp [reassoc_of% comm]) 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] @[reassoc] lemma map_comp : 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 /- As the number of simp lemmas that are required in the proofs below is huge, we use the `simp? ... says` syntax: it is meant to ease the maintenance of this code as it gives a minimal list of lemmas with which `simp` is able to finish the proof. The `set_option maxHeartbeats` are necessary only when this code is compiled with `set_option says.verify true` (e.g. during CI). -/ section Rotate set_option maxHeartbeats 400000 in /-- 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_self 1)) (by simp? [Cochain.δ_leftShift _ 1 0 1 (neg_add_self 1) 0 (zero_add 1)] says simp only [Int.reduceNeg, δ_neg, Cochain.δ_leftShift _ 1 0 1 (neg_add_self 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_right_neg]) inv := desc (inr φ) 0 (triangle φ).mor₃ (by simp only [δ_zero, inr_triangleδ, Cochain.ofHom_zero]) homotopyHomInvId := Homotopy.ofEq (by ext n simp? [lift_desc_f _ _ _ _ _ _ _ _ _ rfl, (inl φ).leftShift_v 1 0 _ _ n _ (n + 1) (by simp only [add_neg_cancel_right])] says 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 simp? [ext_to_iff _ _ (n + 1) rfl, ext_from_iff _ (n + 1) _ rfl, δ_zero_cochain_comp _ _ _ (neg_add_self 1), (inl φ).leftShift_v 1 0 (neg_add_self 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_self 1) n (n + 1) n rfl (by omega)] says 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_self 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_self 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_self 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, add_left_neg]⟩ /-- 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] simp [ext_from_iff _ _ _ rfl, ext_to_iff _ _ _ rfl, (inl φ).leftShift_v 1 0 (neg_add_self 1) p p (add_zero p) (p + 1) (by omega), δ_zero_cochain_comp _ _ _ (neg_add_self 1), Cochain.comp_v _ _ (add_neg_self 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)]⟩ @[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] simp [lift_f _ _ _ _ _ (p + 1) rfl, (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by omega)] /-- 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 aesop_cat) (by aesop_cat) (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', add_left_neg]) 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) ?_ ?_ ?_ · simp only [Triangle.shiftFunctor_obj, triangle_obj₁, triangle_obj₂, triangle_obj₃, triangle_mor₁, Units.smul_def, triangle_mor₂, Functor.comp_obj, Triangle.mk_obj₁, Triangle.mk_obj₂, Triangle.mk_mor₁, Preadditive.smul_iso_hom, Iso.refl_hom, Linear.comp_smul, comp_id, smul_smul, Int.units_coe_mul_self, one_smul, id_comp] · ext p set_option tactic.skipAssignedInstances false in 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] rw [smul_zero] · 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 omega), 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 omega) n n (by omega) (n + 1) (by omega)] simp /-- 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) (by aesop_cat) ?_ ?_ · 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 ⟨X⟩ := X obtain ⟨Y⟩ := Y 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) 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 ≫ CochainComplex.mappingCone.trianglehMapOfHomotopy H ≫ e₂.inv have comm₂ := γ.comm₂ have comm₃ := γ.comm₃ dsimp [γ] at comm₂ comm₃ simp only [ha', hb'] at comm₂ comm₃ exact ⟨γ.hom₃, by simpa [γ] using comm₂, by simpa [γ] using comm₃⟩ end Pretriangulated variable [HasZeroObject C] 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
Algebra\Homology\HomotopyCategory\Shift.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory 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 `ℤ`. -/ 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 i j => 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 dsimp rw [K.shape, smul_zero] intro hij' apply hij dsimp at hij' ⊢ omega } map φ := { f := fun i => φ.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 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 omega)) (fun _ _ _ => by simp [h])) (by aesop_cat) /-- 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 omega)) (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 aesop_cat) 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) 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 have : IsIso (((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n) := by rw [shiftFunctorAdd_inv_app_f] infer_instance rw [← cancel_mono (((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n), ← comp_f, Iso.hom_inv_id_app, id_f, shiftFunctorAdd_inv_app_f] simp only [XIsoOfEq, eqToIso.hom, eqToHom_trans, eqToHom_refl] 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 have : IsIso (((shiftFunctorZero (CochainComplex C ℤ) ℤ).inv.app K).f n) := by rw [shiftFunctorZero_inv_app_f] infer_instance rw [← cancel_mono (((shiftFunctorZero (CochainComplex C ℤ) ℤ).inv.app K).f n), ← comp_f, Iso.hom_inv_id_app, id_f, shiftFunctorZero_inv_app_f] simp only [XIsoOfEq, eqToIso.hom, eqToHom_trans, eqToHom_refl] 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])) 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 aesop_cat)) (fun _ => by ext; dsimp; rw [id_comp, comp_id]) instance commShiftMapCochainComplex : (F.mapHomologicalComplex (ComplexShape.up ℤ)).CommShift ℤ where iso := F.mapCochainComplexShiftIso zero := by ext rw [CommShift.isoZero_hom_app] dsimp simp only [mapCochainComplexShiftIso_hom_app_f, CochainComplex.shiftFunctorZero_inv_app_f, CochainComplex.shiftFunctorZero_hom_app_f, HomologicalComplex.XIsoOfEq, eqToIso, eqToHom_map, eqToHom_trans, eqToHom_refl] add := fun a b => by ext rw [CommShift.isoAdd_hom_app] dsimp erw [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 i j := 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 _ _ ) 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
Algebra\Homology\HomotopyCategory\ShiftSequence.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.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 files 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. -/ open CategoryTheory Category ComplexShape Limits variable (C : Type*) [Category C] [Preadditive C] namespace CochainComplex open HomologicalComplex attribute [local simp] XIsoOfEq_hom_naturality smul_smul set_option backward.isDefEq.lazyWhnfCore false in -- See https://github.com/leanprover-community/mathlib4/issues/12534 /-- 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 => by dsimp [shortComplexFunctor'] exact 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))) /-- 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]; omega) hi (by simp only [next]; omega) 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 <;> dsimp <;> 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' := isoWhiskerLeft _ (homologyFunctorIso C (ComplexShape.up ℤ) a) ≪≫ (Functor.associator _ _ _).symm ≪≫ 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] erw [id_comp, id_comp, 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] erw [id_comp, comp_id, 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 omega⟩ 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 omega)).hom) j' hj' (by simp only [next] at hj hj' obtain rfl : i' = i + n := by omega obtain rfl : j' = j + n := by omega 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
Algebra\Homology\HomotopyCategory\ShortExact.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.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`. -/ 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 omega) ≫ (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 omega) (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 set_option simprocs false 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] dsimp rw [← HomologicalComplex.homologyMap_comp, inr_descShortComplex]) (by dsimp 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
Algebra\Homology\HomotopyCategory\SingleFunctors.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.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 ℤ)) ℤ`. -/ 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 dsimp [CategoryTheory.shiftFunctor, shiftMonoidalFunctor, single] by_cases h : i = a · subst h simp only [ite_true] · rw [if_neg h, if_neg (fun h' => h (by omega))])) (by simp)) (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 /-- 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 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 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
Algebra\Homology\HomotopyCategory\Triangulated.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory.Pretriangulated import Mathlib.CategoryTheory.Triangulated.Triangulated import Mathlib.CategoryTheory.ComposableArrows /-! The triangulated structure on the homotopy category of complexes In this file, we show that for any additive category `C`, the pretriangulated category `HomotopyCategory C (ComplexShape.up ℤ)` is triangulated. -/ open CategoryTheory Category Limits Pretriangulated ComposableArrows variable {C : Type*} [Category 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 simp [ext_from_iff _ (n + 1) _ rfl, map] 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 dsimp; simp)) (descCochain _ 0 (Cochain.ofHom (inr (f ≫ g))) (neg_add_self 1)) (by ext p _ rfl simp [mappingConeCompTriangle, map, ext_from_iff _ _ _ rfl, inl_v_d_assoc _ (p+1) p (p+2) (by linarith) (by linarith)]) /-- 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_self 1) p (p+1) p (by linarith) (by linarith)]) @[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] set_option maxHeartbeats 400000 in /-- 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 linarith)) (show 1 + (-2) = -1 by linarith)) (zero_add (-1))), by rw [δ_neg, δ_zero_cochain_comp _ _ _ (neg_add_self 1), Int.negOnePow_neg, Int.negOnePow_one, Units.neg_smul, one_smul, δ_comp _ _ (show 1 + (-2) = -1 by linarith) 2 (-1) 0 (by linarith) (by linarith) (by linarith), δ_comp _ _ (show (-1) + (-1) = -2 by linarith) 0 0 (-1) (by linarith) (by linarith) (by linarith), Int.negOnePow_neg, Int.negOnePow_neg, Int.negOnePow_even 2 ⟨1, by linarith⟩, 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 linarith)] simp? [hom, inv, ext_to_iff _ n (n + 1) rfl, map, Cochain.comp_v _ _ (add_neg_self 1) n (n + 1) n (by linarith) (by linarith), Cochain.comp_v _ _ (show 1 + -2 = -1 by linarith) (n + 1) (n + 2) n (by linarith) (by linarith), Cochain.comp_v _ _ (show (-1) + -1 = -2 by linarith) (n + 2) (n + 1) n (by linarith) (by linarith)] says simp only [mappingConeCompTriangle_obj₁, mappingConeCompTriangle_obj₂, mappingConeCompTriangle_mor₁, map, Int.reduceNeg, inv, hom, Cochain.ofHom_comp, ofHom_desc, ofHom_lift, descCocycle_coe, AddSubmonoid.coe_zero, Cochain.comp_zero_cochain_v, inl_v_descCochain_v_assoc, Cochain.zero_cochain_comp_v, assoc, inl_v_snd_v_assoc, zero_comp, Cochain.id_comp, Cochain.comp_assoc_of_first_is_zero_cochain, Cochain.comp_add, Cochain.comp_neg, Cochain.comp_assoc_of_second_is_zero_cochain, neg_add_rev, neg_neg, Cochain.add_v, Cochain.neg_v, Cochain.comp_v _ _ (add_neg_self 1) n (n + 1) n (by linarith) (by linarith), Cochain.comp_v _ _ (show 1 + -2 = -1 by linarith) (n + 1) (n + 2) n (by linarith) (by linarith), Cochain.comp_v _ _ (show (-1) + -1 = -2 by linarith) (n + 2) (n + 1) n (by linarith) (by linarith), Cochain.ofHom_v, HomologicalComplex.id_f, Preadditive.comp_add, Preadditive.comp_neg, inl_v_fst_v_assoc, neg_zero, add_zero, comp_id, add_left_neg, inr_f_snd_v_assoc, inr_f_descCochain_v_assoc, inr_f_fst_v_assoc, comp_zero, zero_add, ext_to_iff _ n (n + 1) rfl, liftCochain_v_fst_v, inl_v_descCochain_v, inl_v_fst_v, liftCochain_v_snd_v, Cochain.zero_v, inl_v_snd_v, and_self, neg_add_cancel_right, inr_f_descCochain_v, inr_f_fst_v, inr_f_snd_v]⟩ 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 variable [HasZeroObject C] lemma mappingConeCompTriangleh_distinguished : (CochainComplex.mappingConeCompTriangleh f g) ∈ distTriang (HomotopyCategory C (ComplexShape.up ℤ)) := by refine ⟨_, _, (CochainComplex.mappingConeCompTriangle f g).mor₁, ⟨?_⟩⟩ refine Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (isoOfHomotopyEquiv (CochainComplex.mappingConeCompHomotopyEquiv f g)) (by aesop_cat) (by simp) ?_ dsimp [CochainComplex.mappingConeCompTriangleh] rw [CategoryTheory.Functor.map_id, comp_id, ← Functor.map_comp_assoc] congr 2 exact (CochainComplex.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 α := CochainComplex.mappingCone.triangleMap u₁₂ (u₁₂ ≫ u₂₃) (𝟙 X₁) u₂₃ (by rw [id_comp]) let β := CochainComplex.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 simp [α]) · exact ((quotient _ _).mapTriangle.map β).comm₂.trans (by simp [β]) · exact ((quotient _ _).mapTriangle.map β).comm₃ · refine isomorphic_distinguished _ (mappingConeCompTriangleh_distinguished u₁₂ u₂₃) _ ?_ exact Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (Iso.refl _) (by aesop_cat) (by aesop_cat) (by simp [CochainComplex.mappingConeCompTriangleh])) end HomotopyCategory
Algebra\Homology\ShortComplex\Ab.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.ShortExact import Mathlib.Algebra.Category.Grp.Abelian import Mathlib.Algebra.Category.Grp.Kernels import Mathlib.Algebra.Exact /-! # 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 erw [← 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 := 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 := AddCommGrp.of (AddMonoidHom.ker S.g) H := AddCommGrp.of ((AddMonoidHom.ker S.g) ⧸ AddMonoidHom.range S.abToCycles) i := (AddMonoidHom.ker S.g).subtype π := QuotientAddGroup.mk' _ wi := by ext ⟨_, hx⟩ exact hx hi := AddCommGrp.kernelIsLimit _ wπ := by ext (x : S.X₁) erw [QuotientAddGroup.eq_zero_iff] rw [AddMonoidHom.mem_range] apply exists_apply_eq_apply hπ := AddCommGrp.cokernelIsColimit (AddCommGrp.ofHom S.abToCycles) @[simp] lemma abLeftHomologyData_f' : S.abLeftHomologyData.f' = 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 ≅ AddCommGrp.of (AddMonoidHom.ker S.g) := S.abLeftHomologyData.cyclesIso -- This was a simp lemma until we made `AddCommGrp.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) : S.iCycles (S.abCyclesIso.inv x) = x := by dsimp only [abCyclesIso] erw [← 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 ≅ AddCommGrp.of ((AddMonoidHom.ker S.g) ⧸ 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', AddCommGrp.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_ker_le_range : S.Exact ↔ S.g.ker ≤ S.f.range := S.ab_exact_iff lemma ab_exact_iff_range_eq_ker : S.Exact ↔ S.f.range = S.g.ker := by rw [ab_exact_iff_ker_le_range] constructor · intro h refine le_antisymm ?_ h rintro _ ⟨x₁, rfl⟩ erw [AddMonoidHom.mem_ker, ← comp_apply, S.zero] rfl · intro h rw [h] variable {S} lemma ShortExact.ab_injective_f (hS : S.ShortExact) : Function.Injective S.f := (AddCommGrp.mono_iff_injective _).1 hS.mono_f lemma ShortExact.ab_surjective_g (hS : S.ShortExact) : Function.Surjective S.g := (AddCommGrp.epi_iff_surjective _).1 hS.epi_g variable (S) lemma ShortExact.ab_exact_iff_function_exact : S.Exact ↔ Function.Exact S.f S.g := by rw [ab_exact_iff_range_eq_ker, AddMonoidHom.exact_iff] tauto end ShortComplex end CategoryTheory
Algebra\Homology\ShortComplex\Abelian.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.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 (attr := simp 1100)] lemma abelianImageToKernel_comp_kernel_ι_comp_cokernel_π : S.abelianImageToKernel ≫ kernel.ι S.g ≫ cokernel.π S.f = 0 := by simp only [abelianImageToKernel_comp_kernel_ι_assoc, kernel.condition] /-- `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
Algebra\Homology\ShortComplex\Basic.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.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 : Type*) [Category C] [Category D] /-- 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 [HasZeroMorphisms C] 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 variable {C} variable [HasZeroMorphisms C] /-- 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 aesop_cat /-- the right commutative square of a morphism in `ShortComplex` -/ comm₂₃ : τ₂ ≫ S₂.g = S₁.g ≫ τ₃ := by aesop_cat 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 aesop_cat variable {D} variable [HasZeroMorphisms D] /-- 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]) /-- 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 aesop_cat) (comm₂₃ : e₂.hom ≫ S₂.g = S₁.g ≫ e₃.hom := by aesop_cat) : 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 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
Algebra\Homology\ShortComplex\ConcreteCategory.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.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] [ConcreteCategory.{w} C] [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 erw [← 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 [← AddCommGrp.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 ((forget C).map 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 [← AddCommGrp.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 ((forget C).map 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_concreteCategory [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] erw [← comp_apply, S.mapCyclesIso_hom_iCycles (forget₂ C Ab), ← comp_apply, abCyclesIso_inv_apply_iCycles ] end ShortComplex end preadditive end section abelian variable {C : Type u} [Category.{v} C] [ConcreteCategory.{v} C] [HasForget₂ C Ab] [Abelian C] [(forget₂ C Ab).Additive] [(forget₂ C Ab).PreservesHomology] attribute [local instance] ConcreteCategory.instFunLike ConcreteCategory.hasCoeToSort 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₃ : D.L₀.X₃) (x₂ : D.L₁.X₂) (x₁ : 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).preservesFiniteLimitsOfPreservesHomology have : PreservesFiniteLimits (forget C) := by have : forget₂ C Ab ⋙ forget Ab = forget C := HasForget₂.forget_comp simpa only [← this] using compPreservesFiniteLimits _ _ have eq := congr_fun ((forget C).congr_map 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₂ dsimp [DFunLike.coe] at eq₁ eq₂ rw [Functor.map_comp, types_comp_apply, FunctorToTypes.map_comp_apply] at eq rw [eq₂] at eq refine eq.trans (congr_arg ((forget C).map D.v₂₃.τ₁) ?_) apply (Preadditive.mono_iff_injective' D.L₂.f).1 inferInstance rw [← FunctorToTypes.map_comp_apply, φ₁_L₂_f] dsimp [φ₂] rw [Functor.map_comp, types_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_hom (e.hom.naturality D.L₁.g) x₂).symm.trans ?_).trans (congr_hom (e.hom.naturality D.v₀₁.τ₃) x₃) dsimp rw [comp_apply, comp_apply] erw [h₂] rfl · refine ((congr_hom (e.hom.naturality D.L₂.f) x₁).symm.trans ?_).trans (congr_hom (e.hom.naturality D.v₁₂.τ₂) x₂) dsimp rw [comp_apply, comp_apply] erw [h₁] rfl end SnakeInput end ShortComplex end abelian end CategoryTheory
Algebra\Homology\ShortComplex\Exact.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.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 /-! # 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 aesop_cat) 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 aesop_cat) 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 aesop_cat /-- the condition that `s` is a section of `S.g` -/ s_g : s ≫ S.g = 𝟙 _ := by aesop_cat /-- the compatibility between the given section and retraction -/ id : r ≫ S.f + S.g ≫ s = 𝟙 _ := by aesop_cat 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 cases s' obtain rfl := eq obtain rfl := h rfl 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 cases s' obtain rfl := eq obtain rfl := h rfl /-- 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 apply Fork.IsLimit.hom_ext hi dsimp erw [Fork.IsLimit.lift_ι hi] simp only [Fork.ι_ofι, id_comp] 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 have := hS.mono_fromOpcycles 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 have := hS.epi_toCycles dsimp [liftFromProjective] rw [← toCycles_i, Projective.factorThru_comp_assoc, liftCycles_i] @[deprecated (since := "2024-07-09")] alias _root_.CategoryTheory.Exact.lift := Exact.liftFromProjective @[deprecated (since := "2024-07-09")] alias _root_.CategoryTheory.Exact.lift_comp := Exact.liftFromProjective_comp @[deprecated (since := "2024-07-09")] alias _root_.CategoryTheory.Injective.Exact.desc := Exact.descToInjective @[deprecated (since := "2024-07-09")] alias _root_.CategoryTheory.Injective.Exact.comp_desc := Exact.comp_descToInjective 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)).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)).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
Algebra\Homology\ShortComplex\ExactFunctor.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Jujian Zhang -/ 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.preservesFiniteLimitsOfPreservesHomology`: if `F` preserves homology, then `F` preserves finite limits. - `Functor.preservesFiniteColimitsOfPreservesHomology`: 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. -/ noncomputable def preservesFiniteLimitsOfPreservesHomology [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 preservesFiniteLimitsOfPreservesKernels F /-- An additive which preserves homology preserves finite colimits. -/ noncomputable def preservesFiniteColimitsOfPreservesHomology [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 preservesFiniteColimitsOfPreservesCokernels 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 addivite 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), Nonempty $ PreservesLimit (parallelPair f 0) F, Nonempty $ PreservesFiniteLimits F ] := by tfae_have 1 → 2 · rintro hF S ⟨hS, hf⟩ 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 · intro hF X Y f refine ⟨preservesLimitOfPreservesLimitCone (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 · intro hF have := fun X Y (f : X ⟶ Y) ↦ (hF f).some exact ⟨preservesFiniteLimitsOfPreservesKernels F⟩ tfae_have 4 → 1 · rintro ⟨_⟩ S hS exact (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 addivite 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), Nonempty $ PreservesColimit (parallelPair f 0) F, Nonempty $ PreservesFiniteColimits F ] := by tfae_have 1 → 2 · rintro hF S ⟨hS, hf⟩ 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 · intro hF X Y f refine ⟨preservesColimitOfPreservesColimitCocone (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 · intro hF have := fun X Y (f : X ⟶ Y) ↦ (hF f).some exact ⟨preservesFiniteColimitsOfPreservesCokernels F⟩ tfae_have 4 → 1 · rintro ⟨_⟩ S hS exact (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, Nonempty (PreservesHomology F), Nonempty (PreservesFiniteLimits F) ∧ Nonempty (PreservesFiniteColimits F) ] := by tfae_have 1 → 3 · intro hF 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 |>.some · 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 |>.some tfae_have 2 → 1 · intro hF S hS 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 · rintro ⟨h⟩ exact ⟨⟨preservesFiniteLimitsOfPreservesHomology F⟩, ⟨preservesFiniteColimitsOfPreservesHomology F⟩⟩ tfae_have 4 → 2 · rintro ⟨⟨h1⟩, ⟨h2⟩⟩ exact fun _ h ↦ h.map F tfae_finish end end Functor end CategoryTheory