/- Copyright 2026 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This file has been modified. -/ import OAI.Algebra.Homology.LinearDual import Mathlib.LinearAlgebra.Dual.Lemmas /-! # Linear Dual Homotopy -/ namespace OAI.Algebra.Homology.LinearDualHomotopy noncomputable section open _root_.CategoryTheory open _root_.CategoryTheory.ShortComplex open _root_.HomologicalComplex /-! # Constructions used only in proofs -/ open Limits universe u namespace CategoryTheory.ShortComplex variable {R : Type u} [CommRing R] /-- Dualising a splitting of a short complex of modules gives a splitting of the reversed dual short complex: the retraction and the section swap roles. -/ def Splitting.linearDual {S : ShortComplex (ModuleCat.{u} R)} (h : S.Splitting) : (LinearDual.CategoryTheory.ShortComplex.linearDual S).Splitting where r := ModuleCat.ofHom h.s.hom.dualMap s := ModuleCat.ofHom h.r.hom.dualMap f_r := by apply ModuleCat.hom_ext apply LinearMap.ext intro φ change Module.Dual R S.X₃ at φ exact LinearMap.ext fun x => congrArg φ (ConcreteCategory.congr_hom h.s_g x) s_g := by apply ModuleCat.hom_ext apply LinearMap.ext intro φ change Module.Dual R S.X₁ at φ exact LinearMap.ext fun x => congrArg φ (ConcreteCategory.congr_hom h.f_r x) id := by apply ModuleCat.hom_ext apply LinearMap.ext intro φ change Module.Dual R S.X₂ at φ refine LinearMap.ext fun x => ?_ change φ (h.s.hom (S.g.hom x)) + φ (S.f.hom (h.r.hom x)) = φ x rw [← map_add] refine congrArg φ ?_ have hx := ConcreteCategory.congr_hom h.id x change S.f.hom (h.r.hom x) + h.s.hom (S.g.hom x) = x at hx rw [add_comm] exact hx end CategoryTheory.ShortComplex namespace HomologicalComplex variable {R : Type u} [CommRing R] attribute [simp] LinearDual.HomologicalComplex.linearDualCochainComplex_X attribute [local implicit_reducible] shortComplexFunctor' shortComplexFunctor variable {K L M : ChainComplex (ModuleCat.{u} R) ℕ} lemma ModuleCat.ofHom_sub.{v} {R : Type*} [Ring R] {M N : Type v} [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (f g : M →ₗ[R] N) : ModuleCat.ofHom (f - g) = ModuleCat.ofHom f - ModuleCat.ofHom g := rfl open Homotopy in /-- Algebraic duality sends a chain homotopy contravariantly to a cochain homotopy. -/ def linearDualHomotopy {f g : K ⟶ L} (h : Homotopy f g) : Homotopy (LinearDual.HomologicalComplex.linearDualMap f) (LinearDual.HomologicalComplex.linearDualMap g) where hom i j := ModuleCat.ofHom (h.hom j i).hom.dualMap zero i j hij := by simp [h.zero j i hij] comm i := by cases i with | zero => rw [dNext_cochainComplex, prevD_zero_cochainComplex, LinearDual.HomologicalComplex.linearDualCochainComplex_d_succ] have h' : f.f 0 - g.f 0 = h.hom 0 1 ≫ L.d 1 0 := by simpa [dNext_zero_chainComplex _, prevD_chainComplex _, ← sub_eq_iff_eq_add] using h.comm 0 simp [← ModuleCat.ofHom_comp, LinearMap.dualMap_comp_dualMap, ← ModuleCat.hom_comp, ← h', OAI.LinearAlgebra.Foundations.DualDefs.LinearMap.dualMap_sub, HomologicalComplex.ModuleCat.ofHom_sub] | succ n => rw [Homotopy.dNext_cochainComplex, Homotopy.prevD_succ_cochainComplex] have h': f.f (n + 1) - g.f (n + 1) = h.hom (n + 1) (n + 1 + 1) ≫ L.d (n + 1 + 1) (n + 1) + K.d (n + 1) n ≫ h.hom n (n + 1) := by simpa [dNext_succ_chainComplex _, prevD_chainComplex _, ← sub_eq_iff_eq_add, add_comm (K.d _ _ ≫ _)] using h.comm (n + 1) simp [← ModuleCat.ofHom_comp, ← ModuleCat.ofHom_add, LinearMap.dualMap_comp_dualMap, ← ModuleCat.hom_comp, ← OAI.LinearAlgebra.Foundations.DualDefs.LinearMap.dualMap_add, ← ModuleCat.hom_add, ← h'] /-- Algebraic duality sends a chain-homotopy equivalence contravariantly to a cochain-homotopy equivalence. -/ def linearDualHomotopyEquiv (e : HomotopyEquiv K L) : HomotopyEquiv (LinearDual.HomologicalComplex.linearDualCochainComplex L) (LinearDual.HomologicalComplex.linearDualCochainComplex K) where hom := LinearDual.HomologicalComplex.linearDualMap e.hom inv := LinearDual.HomologicalComplex.linearDualMap e.inv homotopyHomInvId := (Homotopy.ofEq (LinearDual.HomologicalComplex.linearDualMap_comp e.inv e.hom).symm).trans <| (linearDualHomotopy e.homotopyInvHomId).trans <| Homotopy.ofEq (LinearDual.HomologicalComplex.linearDualMap_id L) homotopyInvHomId := (Homotopy.ofEq (LinearDual.HomologicalComplex.linearDualMap_comp e.hom e.inv).symm).trans <| (linearDualHomotopy e.homotopyHomInvId).trans <| Homotopy.ofEq (LinearDual.HomologicalComplex.linearDualMap_id K) end HomologicalComplex end end OAI.Algebra.Homology.LinearDualHomotopy