source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Taylor.lean | import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.Algebra.Polynomial.HasseDeriv
/-!
# Taylor expansions of polynomials
## Main declarations
* `Polynomial.taylor`: the Taylor expansion of the polynomial `f` at `r`
* `Polynomial.taylor_coeff`: the `k`th coefficient of `taylor r f` is
`(Polynomial.hasseDeriv k f).eval r`
* `Polynomial.eq_zero_of_hasseDeriv_eq_zero`:
the identity principle: a polynomial is 0 iff all its Hasse derivatives are zero
-/
noncomputable section
namespace Polynomial
section Semiring
variable {R : Type*} [Semiring R] (r : R) (f : R[X])
/-- The Taylor expansion of a polynomial `f` at `r`. -/
def taylor (r : R) : R[X] →ₗ[R] R[X] where
toFun f := f.comp (X + C r)
map_add' _ _ := add_comp
map_smul' c f := by simp only [smul_eq_C_mul, C_mul_comp, RingHom.id_apply]
theorem taylor_apply : taylor r f = f.comp (X + C r) :=
rfl
@[simp]
theorem taylor_X : taylor r X = X + C r := X_comp
@[simp]
theorem taylor_X_pow (n : ℕ) : taylor r (X ^ n) = (X + C r) ^ n := X_pow_comp
@[simp]
theorem taylor_C (x : R) : taylor r (C x) = C x := C_comp
theorem taylor_zero (f : R[X]) : taylor 0 f = f := by rw [taylor_apply, C_0, add_zero, comp_X]
@[simp]
theorem taylor_zero' : taylor (0 : R) = LinearMap.id := LinearMap.ext taylor_zero
@[simp]
theorem taylor_one : taylor r (1 : R[X]) = C 1 := taylor_C r 1
@[simp]
theorem taylor_monomial (i : ℕ) (k : R) : taylor r (monomial i k) = C k * (X + C r) ^ i := by
simp [taylor_apply]
/-- The `k`th coefficient of `Polynomial.taylor r f` is `(Polynomial.hasseDeriv k f).eval r`. -/
theorem taylor_coeff (n : ℕ) : (taylor r f).coeff n = (hasseDeriv n f).eval r :=
show (lcoeff R n).comp (taylor r) f = (leval r).comp (hasseDeriv n) f by
congr 1; clear! f; ext i
simp only [leval_apply, mul_one, one_mul, eval_monomial, LinearMap.comp_apply, map_sum,
hasseDeriv_monomial, taylor_apply, monomial_comp, C_1, (commute_X (C r)).add_pow i]
simp only [lcoeff_apply, ← C_eq_natCast, mul_assoc, ← C_pow, ← C_mul, coeff_mul_C,
(Nat.cast_commute _ _).eq, coeff_X_pow, boole_mul, Finset.sum_ite_eq, Finset.mem_range]
split_ifs with h; · rfl
push_neg at h; rw [Nat.choose_eq_zero_of_lt h, Nat.cast_zero, mul_zero]
@[simp]
theorem taylor_coeff_zero : (taylor r f).coeff 0 = f.eval r := by
rw [taylor_coeff, hasseDeriv_zero, LinearMap.id_apply]
@[simp]
theorem taylor_coeff_one : (taylor r f).coeff 1 = f.derivative.eval r := by
rw [taylor_coeff, hasseDeriv_one]
@[simp]
theorem coeff_taylor_natDegree : (taylor r f).coeff f.natDegree = f.leadingCoeff := by
by_cases hf : f = 0
· rw [hf, map_zero, coeff_natDegree]
· rw [taylor_coeff, hasseDeriv_natDegree_eq_C, eval_C]
@[simp]
theorem natDegree_taylor (p : R[X]) (r : R) : natDegree (taylor r p) = natDegree p := by
refine map_natDegree_eq_natDegree _ ?_
nontriviality R
intro n c c0
simp [taylor_monomial, natDegree_C_mul_of_mul_ne_zero, natDegree_pow_X_add_C, c0]
@[simp]
theorem leadingCoeff_taylor : (taylor r f).leadingCoeff = f.leadingCoeff := by
rw [leadingCoeff, leadingCoeff, natDegree_taylor, coeff_taylor_natDegree, leadingCoeff]
@[simp]
theorem taylor_eq_zero : taylor r f = 0 ↔ f = 0 := by
rw [← leadingCoeff_eq_zero, ← leadingCoeff_eq_zero, leadingCoeff_taylor]
@[simp]
theorem degree_taylor (p : R[X]) (r : R) : degree (taylor r p) = degree p := by
by_cases hp : p = 0
· rw [hp, map_zero]
· rw [degree_eq_natDegree hp, degree_eq_iff_natDegree_eq ((taylor_eq_zero r p).not.2 hp),
natDegree_taylor]
theorem eq_zero_of_hasseDeriv_eq_zero (f : R[X]) (r : R)
(h : ∀ k, (hasseDeriv k f).eval r = 0) : f = 0 := by
rw [← taylor_eq_zero r]
ext k
rw [taylor_coeff, h, coeff_zero]
end Semiring
section Ring
variable {R : Type*} [Ring R]
theorem taylor_injective (r : R) : Function.Injective (taylor r) :=
(injective_iff_map_eq_zero' _).2 (taylor_eq_zero r)
@[simp] lemma taylor_inj {r : R} {p q : R[X]} :
taylor r p = taylor r q ↔ p = q := (taylor_injective r).eq_iff
end Ring
section CommSemiring
variable {R : Type*} [CommSemiring R] (r : R) (f : R[X])
@[simp]
theorem taylor_mul (p q : R[X]) : taylor r (p * q) = taylor r p * taylor r q := mul_comp ..
/-- `Polynomial.taylor` as an `AlgHom` for commutative semirings -/
@[simps!]
def taylorAlgHom (r : R) : R[X] →ₐ[R] R[X] :=
AlgHom.ofLinearMap (taylor r) (taylor_one r) (taylor_mul r)
@[simp]
theorem taylor_pow (n : ℕ) : taylor r (f ^ n) = taylor r f ^ n :=
(taylorAlgHom r).map_pow ..
@[simp, norm_cast] lemma coe_taylorAlgHom : taylorAlgHom r = taylor r :=
rfl
theorem taylor_taylor (f : R[X]) (r s : R) : taylor r (taylor s f) = taylor (r + s) f := by
simp only [taylor_apply, comp_assoc, map_add, add_comp, X_comp, C_comp, add_assoc]
theorem taylor_eval (r : R) (f : R[X]) (s : R) : (taylor r f).eval s = f.eval (s + r) := by
simp only [taylor_apply, eval_comp, eval_C, eval_X, eval_add]
theorem eval_add_of_sq_eq_zero (p : R[X]) (x y : R) (hy : y ^ 2 = 0) :
p.eval (x + y) = p.eval x + p.derivative.eval x * y := by
rw [add_comm, ← Polynomial.taylor_eval,
Polynomial.eval_eq_sum_range' ((Nat.lt_succ_self _).trans (Nat.lt_succ_self _)),
Finset.sum_range_succ', Finset.sum_range_succ']
simp [pow_succ, mul_assoc, ← pow_two, hy, add_comm (eval x p)]
end CommSemiring
section CommRing
variable {R : Type*} [CommRing R] (r : R) (f : R[X])
/-- `Polynomial.taylor` as an `AlgEquiv` for commutative rings. -/
noncomputable def taylorEquiv (r : R) : R[X] ≃ₐ[R] R[X] where
invFun := taylorAlgHom (-r)
left_inv P := by simp [taylor, comp_assoc]
right_inv P := by simp [taylor, comp_assoc]
__ := taylorAlgHom r
@[simp, norm_cast] lemma toAlgHom_taylorEquiv : taylorEquiv r = taylorAlgHom r := rfl
@[simp, norm_cast] lemma coe_taylorEquiv : taylorEquiv r = taylor r := rfl
@[simp] lemma taylorEquiv_symm : (taylorEquiv r).symm = taylorEquiv (-r) :=
AlgEquiv.ext fun _ ↦ rfl
theorem taylor_eval_sub (s : R) :
(taylor r f).eval (s - r) = f.eval s := by rw [taylor_eval, sub_add_cancel]
/-- Taylor's formula. -/
theorem sum_taylor_eq (f : R[X]) (r : R) :
((taylor r f).sum fun i a => C a * (X - C r) ^ i) = f := by
rw [← comp_eq_sum_left, sub_eq_add_neg, ← C_neg, ← taylor_apply, taylor_taylor, neg_add_cancel,
taylor_zero]
end CommRing
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/RingDivision.lean | import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Div
import Mathlib.RingTheory.Coprime.Basic
/-!
# Theory of univariate polynomials
We prove basic results about univariate polynomials.
-/
assert_not_exists Ideal.map
noncomputable section
open Polynomial
open Finset
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R] {p q : R[X]}
section
variable [Semiring S]
theorem natDegree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S}
(hz : aeval z p = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.natDegree :=
natDegree_pos_of_eval₂_root hp (algebraMap R S) hz inj
theorem degree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S} (hz : aeval z p = 0)
(inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.degree :=
natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_aeval_root hp hz inj)
end
theorem smul_modByMonic (c : R) (p : R[X]) : c • p %ₘ q = c • (p %ₘ q) := by
by_cases hq : q.Monic
· rcases subsingleton_or_nontrivial R with hR | hR
· simp only [eq_iff_true_of_subsingleton]
· exact
(div_modByMonic_unique (c • (p /ₘ q)) (c • (p %ₘ q)) hq
⟨by rw [mul_smul_comm, ← smul_add, modByMonic_add_div p hq],
(degree_smul_le _ _).trans_lt (degree_modByMonic_lt _ hq)⟩).2
· simp_rw [modByMonic_eq_of_not_monic _ hq]
/-- `_ %ₘ q` as an `R`-linear map. -/
@[simps]
def modByMonicHom (q : R[X]) : R[X] →ₗ[R] R[X] where
toFun p := p %ₘ q
map_add' := add_modByMonic
map_smul' := smul_modByMonic
theorem mem_ker_modByMonic (hq : q.Monic) {p : R[X]} :
p ∈ LinearMap.ker (modByMonicHom q) ↔ q ∣ p :=
LinearMap.mem_ker.trans (modByMonic_eq_zero_iff_dvd hq)
section
variable [Ring S]
theorem aeval_modByMonic_eq_self_of_root [Algebra R S] {p q : R[X]} (hq : q.Monic) {x : S}
(hx : aeval x q = 0) : aeval x (p %ₘ q) = aeval x p := by
--`eval₂_modByMonic_eq_self_of_root` doesn't work here as it needs commutativity
rw [modByMonic_eq_sub_mul_div p hq, map_sub, map_mul, hx, zero_mul,
sub_zero]
end
end CommRing
section NoZeroDivisors
variable [Semiring R] [NoZeroDivisors R] {p q : R[X]}
theorem trailingDegree_mul : (p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by
by_cases hp : p = 0
· rw [hp, zero_mul, trailingDegree_zero, top_add]
by_cases hq : q = 0
· rw [hq, mul_zero, trailingDegree_zero, add_top]
· rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq,
trailingDegree_eq_natTrailingDegree (mul_ne_zero hp hq), natTrailingDegree_mul hp hq]
apply WithTop.coe_add
end NoZeroDivisors
section CommRing
variable [CommRing R]
theorem rootMultiplicity_eq_rootMultiplicity {p : R[X]} {t : R} :
p.rootMultiplicity t = (p.comp (X + C t)).rootMultiplicity 0 := by
classical
simp_rw [rootMultiplicity_eq_multiplicity, comp_X_add_C_eq_zero_iff]
congr 1
rw [C_0, sub_zero]
convert (multiplicity_map_eq <| algEquivAevalXAddC t).symm using 2
simp [C_eq_algebraMap]
/-- See `Polynomial.rootMultiplicity_eq_natTrailingDegree'` for the special case of `t = 0`. -/
theorem rootMultiplicity_eq_natTrailingDegree {p : R[X]} {t : R} :
p.rootMultiplicity t = (p.comp (X + C t)).natTrailingDegree :=
rootMultiplicity_eq_rootMultiplicity.trans rootMultiplicity_eq_natTrailingDegree'
section nonZeroDivisors
open scoped nonZeroDivisors
theorem Monic.mem_nonZeroDivisors {p : R[X]} (h : p.Monic) : p ∈ R[X]⁰ :=
mem_nonzeroDivisors_of_coeff_mem _ (h.coeff_natDegree ▸ one_mem R⁰)
theorem mem_nonZeroDivisors_of_leadingCoeff {p : R[X]} (h : p.leadingCoeff ∈ R⁰) : p ∈ R[X]⁰ :=
mem_nonzeroDivisors_of_coeff_mem _ h
theorem mem_nonZeroDivisors_of_trailingCoeff {p : R[X]} (h : p.trailingCoeff ∈ R⁰) : p ∈ R[X]⁰ :=
mem_nonzeroDivisors_of_coeff_mem _ h
end nonZeroDivisors
lemma _root_.Irreducible.aeval_ne_zero_of_natDegree_ne_one [IsDomain R] [Ring S] [Algebra R S]
[FaithfulSMul R S] {p : R[X]} (hp : Irreducible p) (hdeg : p.natDegree ≠ 1) {x : S}
(hx : x ∈ (algebraMap R S).range) : p.aeval x ≠ 0 := by
obtain ⟨_, rfl⟩ := hx
rw [aeval_algebraMap_apply_eq_algebraMap_eval]
exact fun heq ↦ hp.not_isRoot_of_natDegree_ne_one hdeg <|
FaithfulSMul.algebraMap_injective _ _ <| map_zero (algebraMap R S) ▸ heq
theorem natDegree_pos_of_monic_of_aeval_eq_zero [Nontrivial R] [Semiring S] [Algebra R S]
[FaithfulSMul R S] {p : R[X]} (hp : p.Monic) {x : S} (hx : aeval x p = 0) :
0 < p.natDegree :=
natDegree_pos_of_aeval_root (Monic.ne_zero hp) hx
((injective_iff_map_eq_zero (algebraMap R S)).mp (FaithfulSMul.algebraMap_injective R S))
theorem rootMultiplicity_mul_X_sub_C_pow {p : R[X]} {a : R} {n : ℕ} (h : p ≠ 0) :
(p * (X - C a) ^ n).rootMultiplicity a = p.rootMultiplicity a + n := by
have h2 := monic_X_sub_C a |>.pow n |>.mul_left_ne_zero h
refine le_antisymm ?_ ?_
· rw [rootMultiplicity_le_iff h2, add_assoc, add_comm n, ← add_assoc, pow_add,
dvd_cancel_right_mem_nonZeroDivisors (monic_X_sub_C a |>.pow n |>.mem_nonZeroDivisors)]
exact pow_rootMultiplicity_not_dvd h a
· rw [le_rootMultiplicity_iff h2, pow_add]
exact mul_dvd_mul_right (pow_rootMultiplicity_dvd p a) _
/-- The multiplicity of `a` as root of `(X - a) ^ n` is `n`. -/
theorem rootMultiplicity_X_sub_C_pow [Nontrivial R] (a : R) (n : ℕ) :
rootMultiplicity a ((X - C a) ^ n) = n := by
have := rootMultiplicity_mul_X_sub_C_pow (a := a) (n := n) C.map_one_ne_zero
rwa [rootMultiplicity_C, map_one, one_mul, zero_add] at this
theorem rootMultiplicity_X_sub_C_self [Nontrivial R] {x : R} :
rootMultiplicity x (X - C x) = 1 :=
pow_one (X - C x) ▸ rootMultiplicity_X_sub_C_pow x 1
theorem rootMultiplicity_X_sub_C [Nontrivial R] [DecidableEq R] {x y : R} :
rootMultiplicity x (X - C y) = if x = y then 1 else 0 := by
split_ifs with hxy
· rw [hxy]
exact rootMultiplicity_X_sub_C_self
exact rootMultiplicity_eq_zero (mt root_X_sub_C.mp (Ne.symm hxy))
theorem rootMultiplicity_mul' {p q : R[X]} {x : R}
(hpq : (p /ₘ (X - C x) ^ p.rootMultiplicity x).eval x *
(q /ₘ (X - C x) ^ q.rootMultiplicity x).eval x ≠ 0) :
rootMultiplicity x (p * q) = rootMultiplicity x p + rootMultiplicity x q := by
simp_rw [eval_divByMonic_eq_trailingCoeff_comp] at hpq
simp_rw [rootMultiplicity_eq_natTrailingDegree, mul_comp, natTrailingDegree_mul' hpq]
theorem Monic.neg_one_pow_natDegree_mul_comp_neg_X {p : R[X]} (hp : p.Monic) :
((-1) ^ p.natDegree * p.comp (-X)).Monic := by
simp only [Monic]
calc
((-1) ^ p.natDegree * p.comp (-X)).leadingCoeff =
(p.comp (-X) * C ((-1) ^ p.natDegree)).leadingCoeff := by
simp [mul_comm]
_ = 1 := by
apply monic_mul_C_of_leadingCoeff_mul_eq_one
simp [← pow_add, hp]
variable [IsDomain R] {p q : R[X]}
theorem degree_eq_degree_of_associated (h : Associated p q) : degree p = degree q := by
let ⟨u, hu⟩ := h
simp [hu.symm]
theorem prime_X_sub_C (r : R) : Prime (X - C r) :=
⟨X_sub_C_ne_zero r, not_isUnit_X_sub_C r, fun _ _ => by
simp_rw [dvd_iff_isRoot, IsRoot.def, eval_mul, mul_eq_zero]
exact id⟩
theorem prime_X : Prime (X : R[X]) := by
convert prime_X_sub_C (0 : R)
simp
theorem Monic.prime_of_degree_eq_one (hp1 : degree p = 1) (hm : Monic p) : Prime p :=
have : p = X - C (-p.coeff 0) := by simpa [hm.leadingCoeff] using eq_X_add_C_of_degree_eq_one hp1
this.symm ▸ prime_X_sub_C _
theorem irreducible_X_sub_C (r : R) : Irreducible (X - C r) :=
(prime_X_sub_C r).irreducible
theorem irreducible_X : Irreducible (X : R[X]) :=
Prime.irreducible prime_X
theorem Monic.irreducible_of_degree_eq_one (hp1 : degree p = 1) (hm : Monic p) : Irreducible p :=
(hm.prime_of_degree_eq_one hp1).irreducible
lemma aeval_ne_zero_of_isCoprime {R} [CommSemiring R] [Nontrivial S] [Semiring S] [Algebra R S]
{p q : R[X]} (h : IsCoprime p q) (s : S) : aeval s p ≠ 0 ∨ aeval s q ≠ 0 := by
by_contra! hpq
rcases h with ⟨_, _, h⟩
apply_fun aeval s at h
simp only [map_add, map_mul, map_one, hpq.left, hpq.right, mul_zero, add_zero, zero_ne_one] at h
theorem isCoprime_X_sub_C_of_isUnit_sub {R} [CommRing R] {a b : R} (h : IsUnit (a - b)) :
IsCoprime (X - C a) (X - C b) :=
⟨-C h.unit⁻¹.val, C h.unit⁻¹.val, by
rw [neg_mul_comm, ← left_distrib, neg_add_eq_sub, sub_sub_sub_cancel_left, ← C_sub, ← C_mul]
rw [← C_1]
congr
exact h.val_inv_mul⟩
open scoped Function in -- required for scoped `on` notation
theorem pairwise_coprime_X_sub_C {K} [Field K] {I : Type v} {s : I → K} (H : Function.Injective s) :
Pairwise (IsCoprime on fun i : I => X - C (s i)) := fun _ _ hij =>
isCoprime_X_sub_C_of_isUnit_sub (sub_ne_zero_of_ne <| H.ne hij).isUnit
theorem rootMultiplicity_mul {p q : R[X]} {x : R} (hpq : p * q ≠ 0) :
rootMultiplicity x (p * q) = rootMultiplicity x p + rootMultiplicity x q := by
classical
have hp : p ≠ 0 := left_ne_zero_of_mul hpq
have hq : q ≠ 0 := right_ne_zero_of_mul hpq
rw [rootMultiplicity_eq_multiplicity (p * q), if_neg hpq, rootMultiplicity_eq_multiplicity p,
if_neg hp, rootMultiplicity_eq_multiplicity q, if_neg hq,
multiplicity_mul (prime_X_sub_C x) (finiteMultiplicity_X_sub_C _ hpq)]
open Multiset in
theorem exists_multiset_roots [DecidableEq R] :
∀ {p : R[X]} (_ : p ≠ 0), ∃ s : Multiset R,
(Multiset.card s : WithBot ℕ) ≤ degree p ∧ ∀ a, s.count a = rootMultiplicity a p
| p, hp =>
haveI := Classical.propDecidable (∃ x, IsRoot p x)
if h : ∃ x, IsRoot p x then
let ⟨x, hx⟩ := h
have hpd : 0 < degree p := degree_pos_of_root hp hx
have hd0 : p /ₘ (X - C x) ≠ 0 := fun h => by
rw [← mul_divByMonic_eq_iff_isRoot.2 hx, h, mul_zero] at hp; exact hp rfl
have wf : degree (p /ₘ (X - C x)) < degree p :=
degree_divByMonic_lt _ (monic_X_sub_C x) hp ((degree_X_sub_C x).symm ▸ by decide)
let ⟨t, htd, htr⟩ := @exists_multiset_roots _ (p /ₘ (X - C x)) hd0
have hdeg : degree (X - C x) ≤ degree p := by
rw [degree_X_sub_C, degree_eq_natDegree hp]
rw [degree_eq_natDegree hp] at hpd
exact WithBot.coe_le_coe.2 (WithBot.coe_lt_coe.1 hpd)
have hdiv0 : p /ₘ (X - C x) ≠ 0 :=
mt (divByMonic_eq_zero_iff (monic_X_sub_C x)).1 <| not_lt.2 hdeg
⟨x ::ₘ t,
calc
(card (x ::ₘ t) : WithBot ℕ) = Multiset.card t + 1 := by
congr
exact mod_cast Multiset.card_cons _ _
_ ≤ degree p := by
rw [← degree_add_divByMonic (monic_X_sub_C x) hdeg, degree_X_sub_C, add_comm]
exact add_le_add (le_refl (1 : WithBot ℕ)) htd,
by
intro a
conv_rhs => rw [← mul_divByMonic_eq_iff_isRoot.mpr hx]
rw [rootMultiplicity_mul (mul_ne_zero (X_sub_C_ne_zero x) hdiv0),
rootMultiplicity_X_sub_C, ← htr a]
split_ifs with ha
· rw [ha, count_cons_self, add_comm]
· rw [count_cons_of_ne ha, zero_add]⟩
else
⟨0, (degree_eq_natDegree hp).symm ▸ WithBot.coe_le_coe.2 (Nat.zero_le _), by
intro a
rw [count_zero, rootMultiplicity_eq_zero (not_exists.mp h a)]⟩
termination_by p => natDegree p
decreasing_by {
simp_wf
apply (Nat.cast_lt (α := WithBot ℕ)).mp
simp only [degree_eq_natDegree hp, degree_eq_natDegree hd0] at wf
assumption}
end CommRing
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/CancelLeads.lean | import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Tactic.ComputeDegree
/-!
# Cancel the leading terms of two polynomials
## Definition
* `cancelLeads p q`: the polynomial formed by multiplying `p` and `q` by monomials so that they
have the same leading term, and then subtracting.
## Main Results
The degree of `cancelLeads` is less than that of the larger of the two polynomials being cancelled.
Thus it is useful for induction or minimal-degree arguments.
-/
namespace Polynomial
noncomputable section
open Polynomial
variable {R : Type*}
section Ring
variable [Ring R] (p q : R[X])
/-- `cancelLeads p q` is formed by multiplying `p` and `q` by monomials so that they
have the same leading term, and then subtracting. -/
def cancelLeads : R[X] :=
C p.leadingCoeff * X ^ (p.natDegree - q.natDegree) * q -
C q.leadingCoeff * X ^ (q.natDegree - p.natDegree) * p
variable {p q}
@[simp]
theorem neg_cancelLeads : -p.cancelLeads q = q.cancelLeads p :=
neg_sub _ _
theorem natDegree_cancelLeads_lt_of_natDegree_le_natDegree_of_comm
(comm : p.leadingCoeff * q.leadingCoeff = q.leadingCoeff * p.leadingCoeff)
(h : p.natDegree ≤ q.natDegree) (hq : 0 < q.natDegree) :
(p.cancelLeads q).natDegree < q.natDegree := by
by_cases hp : p = 0
· convert hq
simp [hp, cancelLeads]
rw [cancelLeads, sub_eq_add_neg, tsub_eq_zero_iff_le.mpr h, pow_zero, mul_one]
by_cases h0 :
C p.leadingCoeff * q + -(C q.leadingCoeff * X ^ (q.natDegree - p.natDegree) * p) = 0
· exact (le_of_eq (by simp only [h0, natDegree_zero])).trans_lt hq
apply lt_of_le_of_ne
· compute_degree!
rwa [Nat.sub_add_cancel]
· contrapose! h0
rw [← leadingCoeff_eq_zero, leadingCoeff, h0, mul_assoc, X_pow_mul, ← tsub_add_cancel_of_le h,
add_comm _ p.natDegree]
simp only [coeff_mul_X_pow, coeff_neg, coeff_C_mul, add_tsub_cancel_left, coeff_add]
rw [add_comm p.natDegree, tsub_add_cancel_of_le h, ← leadingCoeff, ← leadingCoeff, comm,
add_neg_cancel]
end Ring
section CommRing
variable [CommRing R] {p q : R[X]}
theorem dvd_cancelLeads_of_dvd_of_dvd {r : R[X]} (pq : p ∣ q) (pr : p ∣ r) : p ∣ q.cancelLeads r :=
dvd_sub (pr.trans (Dvd.intro_left _ rfl)) (pq.trans (Dvd.intro_left _ rfl))
theorem natDegree_cancelLeads_lt_of_natDegree_le_natDegree (h : p.natDegree ≤ q.natDegree)
(hq : 0 < q.natDegree) : (p.cancelLeads q).natDegree < q.natDegree :=
natDegree_cancelLeads_lt_of_natDegree_le_natDegree_of_comm (mul_comm _ _) h hq
end CommRing
end
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/BigOperators.lean | import Mathlib.Algebra.Polynomial.Monic
/-!
# Lemmas for the interaction between polynomials and `∑` and `∏`.
Recall that `∑` and `∏` are notation for `Finset.sum` and `Finset.prod` respectively.
## Main results
- `Polynomial.natDegree_prod_of_monic` : the degree of a product of monic polynomials is the
product of degrees. We prove this only for `[CommSemiring R]`,
but it ought to be true for `[Semiring R]` and `List.prod`.
- `Polynomial.natDegree_prod` : for polynomials over an integral domain,
the degree of the product is the sum of degrees.
- `Polynomial.leadingCoeff_prod` : for polynomials over an integral domain,
the leading coefficient is the product of leading coefficients.
- `Polynomial.prod_X_sub_C_coeff_card_pred` carries most of the content for computing
the second coefficient of the characteristic polynomial.
-/
open Finset
open Multiset
open Polynomial
universe u w
variable {R : Type u} {ι : Type w}
namespace Polynomial
variable (s : Finset ι)
section Semiring
variable {S : Type*} [Semiring S]
theorem natDegree_list_sum_le (l : List S[X]) :
natDegree l.sum ≤ (l.map natDegree).foldr max 0 := by
apply List.sum_le_foldr_max natDegree
· simp
· exact natDegree_add_le
theorem natDegree_multiset_sum_le (l : Multiset S[X]) :
natDegree l.sum ≤ (l.map natDegree).foldr max 0 :=
Quotient.inductionOn l (by simpa using natDegree_list_sum_le)
theorem natDegree_sum_le (f : ι → S[X]) :
natDegree (∑ i ∈ s, f i) ≤ s.fold max 0 (natDegree ∘ f) := by
simpa using natDegree_multiset_sum_le (s.val.map f)
lemma natDegree_sum_le_of_forall_le {n : ℕ} (f : ι → S[X]) (h : ∀ i ∈ s, natDegree (f i) ≤ n) :
natDegree (∑ i ∈ s, f i) ≤ n :=
le_trans (natDegree_sum_le s f) <| (Finset.fold_max_le n).mpr <| by simpa
theorem degree_list_sum_le_of_forall_degree_le (l : List S[X])
(n : WithBot ℕ) (hl : ∀ p ∈ l, degree p ≤ n) :
degree l.sum ≤ n := by
induction l with
| nil => simp
| cons hd tl ih =>
simp only [List.mem_cons, forall_eq_or_imp] at hl
rcases hl with ⟨hhd, htl⟩
rw [List.sum_cons]
exact le_trans (degree_add_le hd tl.sum) (max_le hhd (ih htl))
theorem degree_list_sum_le (l : List S[X]) : degree l.sum ≤ (l.map natDegree).maximum := by
apply degree_list_sum_le_of_forall_degree_le
intro p hp
by_cases h : p = 0
· subst h
simp
· rw [degree_eq_natDegree h]
apply List.le_maximum_of_mem'
rw [List.mem_map]
use p
simp [hp]
theorem natDegree_list_prod_le (l : List S[X]) : natDegree l.prod ≤ (l.map natDegree).sum :=
l.apply_prod_le_sum_map _ natDegree_one.le fun _ _ => natDegree_mul_le
theorem degree_list_prod_le (l : List S[X]) : degree l.prod ≤ (l.map degree).sum :=
l.apply_prod_le_sum_map _ degree_one_le degree_mul_le
theorem coeff_list_prod_of_natDegree_le (l : List S[X]) (n : ℕ) (hl : ∀ p ∈ l, natDegree p ≤ n) :
coeff (List.prod l) (l.length * n) = (l.map fun p => coeff p n).prod := by
induction l with
| nil => simp
| cons hd tl IH =>
have hl' : ∀ p ∈ tl, natDegree p ≤ n := fun p hp => hl p (List.mem_cons_of_mem _ hp)
simp only [List.prod_cons, List.map, List.length]
rw [add_mul, one_mul, add_comm, ← IH hl', mul_comm tl.length]
have h : natDegree tl.prod ≤ n * tl.length := by
refine (natDegree_list_prod_le _).trans ?_
rw [← tl.length_map natDegree, mul_comm]
refine List.sum_le_card_nsmul _ _ ?_
simpa using hl'
exact coeff_mul_add_eq_of_natDegree_le (hl _ List.mem_cons_self) h
end Semiring
section CommSemiring
variable [CommSemiring R] (f : ι → R[X]) (t : Multiset R[X])
theorem natDegree_multiset_prod_le : t.prod.natDegree ≤ (t.map natDegree).sum :=
Quotient.inductionOn t (by simpa using natDegree_list_prod_le)
theorem natDegree_prod_le : (∏ i ∈ s, f i).natDegree ≤ ∑ i ∈ s, (f i).natDegree := by
simpa using natDegree_multiset_prod_le (s.1.map f)
/-- The degree of a product of polynomials is at most the sum of the degrees,
where the degree of the zero polynomial is ⊥.
-/
theorem degree_multiset_prod_le : t.prod.degree ≤ (t.map Polynomial.degree).sum :=
Quotient.inductionOn t (by simpa using degree_list_prod_le)
theorem degree_prod_le : (∏ i ∈ s, f i).degree ≤ ∑ i ∈ s, (f i).degree := by
simpa only [Multiset.map_map] using degree_multiset_prod_le (s.1.map f)
/-- The leading coefficient of a product of polynomials is equal to
the product of the leading coefficients, provided that this product is nonzero.
See `Polynomial.leadingCoeff_multiset_prod` (without the `'`) for a version for integral domains,
where this condition is automatically satisfied.
-/
theorem leadingCoeff_multiset_prod' (h : (t.map leadingCoeff).prod ≠ 0) :
t.prod.leadingCoeff = (t.map leadingCoeff).prod := by
induction t using Multiset.induction_on with | empty => simp | cons a t ih => ?_
simp only [Multiset.map_cons, Multiset.prod_cons] at h ⊢
rw [Polynomial.leadingCoeff_mul']
· rw [ih]
simp only [ne_eq]
apply right_ne_zero_of_mul h
· rw [ih]
· exact h
simp only [ne_eq]
apply right_ne_zero_of_mul h
/-- The leading coefficient of a product of polynomials is equal to
the product of the leading coefficients, provided that this product is nonzero.
See `Polynomial.leadingCoeff_prod` (without the `'`) for a version for integral domains,
where this condition is automatically satisfied.
-/
theorem leadingCoeff_prod' (h : (∏ i ∈ s, (f i).leadingCoeff) ≠ 0) :
(∏ i ∈ s, f i).leadingCoeff = ∏ i ∈ s, (f i).leadingCoeff := by
simpa using leadingCoeff_multiset_prod' (s.1.map f) (by simpa using h)
/-- The degree of a product of polynomials is equal to
the sum of the degrees, provided that the product of leading coefficients is nonzero.
See `Polynomial.natDegree_multiset_prod` (without the `'`) for a version for integral domains,
where this condition is automatically satisfied.
-/
theorem natDegree_multiset_prod' (h : (t.map fun f => leadingCoeff f).prod ≠ 0) :
t.prod.natDegree = (t.map fun f => natDegree f).sum := by
revert h
refine Multiset.induction_on t ?_ fun a t ih ht => ?_; · simp
rw [Multiset.map_cons, Multiset.prod_cons] at ht ⊢
rw [Multiset.sum_cons, Polynomial.natDegree_mul', ih]
· apply right_ne_zero_of_mul ht
· rwa [Polynomial.leadingCoeff_multiset_prod']
apply right_ne_zero_of_mul ht
/-- The degree of a product of polynomials is equal to
the sum of the degrees, provided that the product of leading coefficients is nonzero.
See `Polynomial.natDegree_prod` (without the `'`) for a version for integral domains,
where this condition is automatically satisfied.
-/
theorem natDegree_prod' (h : (∏ i ∈ s, (f i).leadingCoeff) ≠ 0) :
(∏ i ∈ s, f i).natDegree = ∑ i ∈ s, (f i).natDegree := by
simpa using natDegree_multiset_prod' (s.1.map f) (by simpa using h)
theorem natDegree_multiset_prod_of_monic (h : ∀ f ∈ t, Monic f) :
t.prod.natDegree = (t.map natDegree).sum := by
nontriviality R
apply natDegree_multiset_prod'
simp_all
theorem degree_multiset_prod_of_monic [Nontrivial R] (h : ∀ f ∈ t, Monic f) :
t.prod.degree = (t.map degree).sum := by
have : t.prod ≠ 0 := Monic.ne_zero <| by simpa using monic_multiset_prod_of_monic _ _ h
rw [degree_eq_natDegree this, natDegree_multiset_prod_of_monic _ h, Nat.cast_multiset_sum,
Multiset.map_map, Function.comp_def,
Multiset.map_congr rfl (fun f hf => (degree_eq_natDegree (h f hf).ne_zero).symm)]
theorem natDegree_prod_of_monic (h : ∀ i ∈ s, (f i).Monic) :
(∏ i ∈ s, f i).natDegree = ∑ i ∈ s, (f i).natDegree := by
simpa using natDegree_multiset_prod_of_monic (s.1.map f) (by simpa using h)
theorem degree_prod_of_monic [Nontrivial R] (h : ∀ i ∈ s, (f i).Monic) :
(∏ i ∈ s, f i).degree = ∑ i ∈ s, (f i).degree := by
simpa using degree_multiset_prod_of_monic (s.1.map f) (by simpa using h)
theorem coeff_multiset_prod_of_natDegree_le (n : ℕ) (hl : ∀ p ∈ t, natDegree p ≤ n) :
coeff t.prod ((Multiset.card t) * n) = (t.map fun p => coeff p n).prod := by
induction t using Quotient.inductionOn
simpa using coeff_list_prod_of_natDegree_le _ _ hl
theorem coeff_prod_of_natDegree_le (f : ι → R[X]) (n : ℕ) (h : ∀ p ∈ s, natDegree (f p) ≤ n) :
coeff (∏ i ∈ s, f i) (#s * n) = ∏ i ∈ s, coeff (f i) n := by
obtain ⟨l, hl⟩ := s
convert coeff_multiset_prod_of_natDegree_le (l.map f) n ?_
· simp
· simp
· simpa using h
theorem coeff_zero_multiset_prod : t.prod.coeff 0 = (t.map fun f => coeff f 0).prod := by
refine Multiset.induction_on t ?_ fun a t ht => ?_; · simp
rw [Multiset.prod_cons, Multiset.map_cons, Multiset.prod_cons, Polynomial.mul_coeff_zero, ht]
theorem coeff_zero_prod : (∏ i ∈ s, f i).coeff 0 = ∏ i ∈ s, (f i).coeff 0 := by
simpa using coeff_zero_multiset_prod (s.1.map f)
end CommSemiring
section CommRing
variable [CommRing R]
open Monic
-- Eventually this can be generalized with Vieta's formulas
-- plus the connection between roots and factorization.
theorem multiset_prod_X_sub_C_nextCoeff (t : Multiset R) :
nextCoeff (t.map fun x => X - C x).prod = -t.sum := by
rw [nextCoeff_multiset_prod]
· simp only [nextCoeff_X_sub_C]
exact t.sum_hom (-AddMonoidHom.id R)
· intros
apply monic_X_sub_C
theorem prod_X_sub_C_nextCoeff {s : Finset ι} (f : ι → R) :
nextCoeff (∏ i ∈ s, (X - C (f i))) = -∑ i ∈ s, f i := by
simpa using multiset_prod_X_sub_C_nextCoeff (s.1.map f)
theorem multiset_prod_X_sub_C_coeff_card_pred (t : Multiset R) (ht : 0 < Multiset.card t) :
(t.map fun x => X - C x).prod.coeff ((Multiset.card t) - 1) = -t.sum := by
nontriviality R
convert multiset_prod_X_sub_C_nextCoeff (by assumption)
rw [nextCoeff, if_neg]
swap
· rw [natDegree_multiset_prod_of_monic]
swap
· simp only [Multiset.mem_map]
rintro _ ⟨_, _, rfl⟩
apply monic_X_sub_C
simp_rw [Multiset.sum_eq_zero_iff, Multiset.mem_map]
obtain ⟨x, hx⟩ := card_pos_iff_exists_mem.mp ht
exact fun h => one_ne_zero <| h 1 ⟨_, ⟨x, hx, rfl⟩, natDegree_X_sub_C _⟩
congr; rw [natDegree_multiset_prod_of_monic] <;> · simp [monic_X_sub_C]
theorem prod_X_sub_C_coeff_card_pred (s : Finset ι) (f : ι → R) (hs : 0 < #s) :
(∏ i ∈ s, (X - C (f i))).coeff (#s - 1) = -∑ i ∈ s, f i := by
simpa using multiset_prod_X_sub_C_coeff_card_pred (s.1.map f) (by simpa using hs)
variable [Nontrivial R]
@[simp]
lemma natDegree_multiset_prod_X_sub_C_eq_card (s : Multiset R) :
(s.map (X - C ·)).prod.natDegree = Multiset.card s := by
rw [natDegree_multiset_prod_of_monic, Multiset.map_map]
· simp only [(· ∘ ·), natDegree_X_sub_C, Multiset.map_const', Multiset.sum_replicate, smul_eq_mul,
mul_one]
· exact Multiset.forall_mem_map_iff.2 fun a _ => monic_X_sub_C a
@[simp] lemma natDegree_finset_prod_X_sub_C_eq_card {α} (s : Finset α) (f : α → R) :
(∏ a ∈ s, (X - C (f a))).natDegree = s.card := by
rw [Finset.prod, ← (X - C ·).comp_def f, ← Multiset.map_map,
natDegree_multiset_prod_X_sub_C_eq_card, Multiset.card_map, Finset.card]
end CommRing
section NoZeroDivisors
section Semiring
variable [Semiring R] [NoZeroDivisors R]
/-- The degree of a product of polynomials is equal to
the sum of the degrees, where the degree of the zero polynomial is ⊥.
`[Nontrivial R]` is needed, otherwise for `l = []` we have `⊥` in the LHS and `0` in the RHS.
-/
theorem degree_list_prod [Nontrivial R] (l : List R[X]) : l.prod.degree = (l.map degree).sum :=
map_list_prod (@degreeMonoidHom R _ _ _) l
end Semiring
section CommSemiring
variable [CommSemiring R] [NoZeroDivisors R] (f : ι → R[X]) (t : Multiset R[X])
/-- The degree of a product of polynomials is equal to
the sum of the degrees.
See `Polynomial.natDegree_prod'` (with a `'`) for a version for commutative semirings,
where additionally, the product of the leading coefficients must be nonzero.
-/
theorem natDegree_prod (h : ∀ i ∈ s, f i ≠ 0) :
(∏ i ∈ s, f i).natDegree = ∑ i ∈ s, (f i).natDegree := by
nontriviality R
apply natDegree_prod'
rw [prod_ne_zero_iff]
intro x hx; simp [h x hx]
theorem natDegree_multiset_prod (h : (0 : R[X]) ∉ t) :
natDegree t.prod = (t.map natDegree).sum := by
nontriviality R
rw [natDegree_multiset_prod']
simp_rw [Ne, Multiset.prod_eq_zero_iff, Multiset.mem_map, leadingCoeff_eq_zero]
rintro ⟨_, h, rfl⟩
contradiction
/-- The degree of a product of polynomials is equal to
the sum of the degrees, where the degree of the zero polynomial is ⊥.
-/
theorem degree_multiset_prod [Nontrivial R] : t.prod.degree = (t.map fun f => degree f).sum :=
map_multiset_prod (@degreeMonoidHom R _ _ _) _
/-- The degree of a product of polynomials is equal to
the sum of the degrees, where the degree of the zero polynomial is ⊥.
-/
theorem degree_prod [Nontrivial R] : (∏ i ∈ s, f i).degree = ∑ i ∈ s, (f i).degree :=
map_prod (@degreeMonoidHom R _ _ _) _ _
/-- The leading coefficient of a product of polynomials is equal to
the product of the leading coefficients.
See `Polynomial.leadingCoeff_multiset_prod'` (with a `'`) for a version for commutative semirings,
where additionally, the product of the leading coefficients must be nonzero.
-/
theorem leadingCoeff_multiset_prod :
t.prod.leadingCoeff = (t.map fun f => leadingCoeff f).prod := by
rw [← leadingCoeffHom_apply, MonoidHom.map_multiset_prod]
simp only [leadingCoeffHom_apply]
/-- The leading coefficient of a product of polynomials is equal to
the product of the leading coefficients.
See `Polynomial.leadingCoeff_prod'` (with a `'`) for a version for commutative semirings,
where additionally, the product of the leading coefficients must be nonzero.
-/
theorem leadingCoeff_prod : (∏ i ∈ s, f i).leadingCoeff = ∏ i ∈ s, (f i).leadingCoeff := by
simpa using leadingCoeff_multiset_prod (s.1.map f)
end CommSemiring
end NoZeroDivisors
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/GroupRingAction.lean | import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Monic
import Mathlib.Algebra.Ring.Action.Basic
import Mathlib.GroupTheory.Coset.Card
import Mathlib.GroupTheory.GroupAction.Hom
import Mathlib.GroupTheory.GroupAction.Quotient
/-!
# Group action on rings applied to polynomials
This file contains instances and definitions relating `MulSemiringAction` to `Polynomial`.
-/
variable (M : Type*) [Monoid M]
open Polynomial
namespace Polynomial
variable (R : Type*) [Semiring R]
variable {M} in
-- In this statement, we use `HSMul.hSMul m` as LHS instead of `(m • ·)`
-- to avoid a spurious lambda-expression that complicates rewriting with this lemma.
theorem smul_eq_map [MulSemiringAction M R] (m : M) :
HSMul.hSMul m = map (MulSemiringAction.toRingHom M R m) := by
ext
simp
noncomputable instance [MulSemiringAction M R] : MulSemiringAction M R[X] :=
{ Polynomial.distribMulAction with
smul_one := fun m ↦
smul_eq_map R m ▸ Polynomial.map_one (MulSemiringAction.toRingHom M R m)
smul_mul := fun m _ _ ↦
smul_eq_map R m ▸ Polynomial.map_mul (MulSemiringAction.toRingHom M R m) }
variable {M R}
variable [MulSemiringAction M R]
@[simp]
theorem smul_X (m : M) : (m • X : R[X]) = X :=
(smul_eq_map R m).symm ▸ map_X _
variable (S : Type*) [CommSemiring S] [MulSemiringAction M S]
theorem smul_eval_smul (m : M) (f : S[X]) (x : S) : (m • f).eval (m • x) = m • f.eval x :=
Polynomial.induction_on f (fun r ↦ by rw [smul_C, eval_C, eval_C])
(fun f g ihf ihg ↦ by rw [smul_add, eval_add, ihf, ihg, eval_add, smul_add]) fun n r _ ↦ by
rw [smul_mul', smul_pow', smul_C, smul_X, eval_mul, eval_C, eval_X_pow, eval_mul, eval_C,
eval_X_pow, smul_mul', smul_pow']
variable (G : Type*) [Group G]
theorem eval_smul' [MulSemiringAction G S] (g : G) (f : S[X]) (x : S) :
f.eval (g • x) = g • (g⁻¹ • f).eval x := by
rw [← smul_eval_smul, smul_inv_smul]
theorem smul_eval [MulSemiringAction G S] (g : G) (f : S[X]) (x : S) :
(g • f).eval x = g • f.eval (g⁻¹ • x) := by
rw [← smul_eval_smul, smul_inv_smul]
end Polynomial
section CommRing
variable (G : Type*) [Group G] [Fintype G]
variable (R : Type*) [CommRing R] [MulSemiringAction G R]
open MulAction
/-- the product of `(X - g • x)` over distinct `g • x`. -/
noncomputable def prodXSubSMul (x : R) : R[X] :=
letI := Classical.decEq R
(Finset.univ : Finset (G ⧸ MulAction.stabilizer G x)).prod fun g ↦
Polynomial.X - Polynomial.C (ofQuotientStabilizer G x g)
theorem prodXSubSMul.monic (x : R) : (prodXSubSMul G R x).Monic :=
Polynomial.monic_prod_of_monic _ _ fun _ _ ↦ Polynomial.monic_X_sub_C _
theorem prodXSubSMul.eval (x : R) : (prodXSubSMul G R x).eval x = 0 :=
letI := Classical.decEq R
(map_prod ((Polynomial.aeval x).toRingHom.toMonoidHom : R[X] →* R) _ _).trans <|
Finset.prod_eq_zero (Finset.mem_univ <| QuotientGroup.mk 1) <| by simp
theorem prodXSubSMul.smul (x : R) (g : G) : g • prodXSubSMul G R x = prodXSubSMul G R x :=
letI := Classical.decEq R
Finset.smul_prod'.trans <|
Fintype.prod_bijective _ (MulAction.bijective g) _ _ fun g' ↦ by
rw [ofQuotientStabilizer_smul, smul_sub, Polynomial.smul_X, Polynomial.smul_C]
theorem prodXSubSMul.coeff (x : R) (g : G) (n : ℕ) :
g • (prodXSubSMul G R x).coeff n = (prodXSubSMul G R x).coeff n := by
rw [← Polynomial.coeff_smul, prodXSubSMul.smul]
end CommRing
namespace MulSemiringActionHom
variable {M}
variable {P : Type*} [CommSemiring P] [MulSemiringAction M P]
variable {Q : Type*} [CommSemiring Q] [MulSemiringAction M Q]
open Polynomial
/-- An equivariant map induces an equivariant map on polynomials. -/
protected noncomputable def polynomial (g : P →+*[M] Q) : P[X] →+*[M] Q[X] where
toFun := map g
map_smul' m p :=
Polynomial.induction_on p
(fun b ↦ by rw [MonoidHom.id_apply, smul_C, map_C, coe_fn_coe, g.map_smul, map_C,
coe_fn_coe, smul_C])
(fun p q ihp ihq ↦ by
rw [smul_add, Polynomial.map_add, ihp, ihq, Polynomial.map_add, smul_add])
fun n b _ ↦ by rw [MonoidHom.id_apply, smul_mul', smul_C, smul_pow', smul_X,
Polynomial.map_mul, map_C, Polynomial.map_pow,
map_X, coe_fn_coe, g.map_smul, Polynomial.map_mul, map_C, Polynomial.map_pow, map_X,
smul_mul', smul_C, smul_pow', smul_X, coe_fn_coe]
map_zero' := Polynomial.map_zero (g : P →+* Q)
map_add' _ _ := Polynomial.map_add (g : P →+* Q)
map_one' := Polynomial.map_one (g : P →+* Q)
map_mul' _ _ := Polynomial.map_mul (g : P →+* Q)
@[simp]
theorem coe_polynomial (g : P →+*[M] Q) : (g.polynomial : P[X] → Q[X]) = map g := rfl
end MulSemiringActionHom |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/PartialFractions.lean | import Mathlib.Algebra.Polynomial.Div
import Mathlib.Logic.Function.Basic
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.LinearCombination
/-!
# Partial fractions
These results were formalised by the Xena Project, at the suggestion
of Patrick Massot.
## The main theorem
* `div_eq_quo_add_sum_rem_div`: General partial fraction decomposition theorem for polynomials over
an integral domain R :
If f, g₁, g₂, ..., gₙ ∈ R[X] and the gᵢs are all monic and pairwise coprime, then ∃ q, r₁, ..., rₙ
∈ R[X] such that f / g₁g₂...gₙ = q + r₁/g₁ + ... + rₙ/gₙ and for all i, deg(rᵢ) < deg(gᵢ).
* The result is formalized here in slightly more generality, using finsets. That is, if ι is an
arbitrary index type, g denotes a map from ι to R[X], and if s is an arbitrary finite subset of ι,
with g i monic for all i ∈ s and for all i,j ∈ s, i ≠ j → g i is coprime to g j, then we have
∃ q ∈ R[X], r : ι → R[X] such that ∀ i ∈ s, deg(r i) < deg(g i) and
f / ∏ g i = q + ∑ (r i) / (g i), where the product and sum are over s.
* The proof is done by proving the two-denominator case and then performing finset induction for an
arbitrary (finite) number of denominators.
## Scope for Expansion
* Proving uniqueness of the decomposition
-/
variable (R : Type*) [CommRing R] [IsDomain R]
open Polynomial
variable (K : Type*) [Field K] [Algebra R[X] K] [IsFractionRing R[X] K]
section TwoDenominators
open scoped algebraMap
/-- Let R be an integral domain and f, g₁, g₂ ∈ R[X]. Let g₁ and g₂ be monic and coprime.
Then, ∃ q, r₁, r₂ ∈ R[X] such that f / g₁g₂ = q + r₁/g₁ + r₂/g₂ and deg(r₁) < deg(g₁) and
deg(r₂) < deg(g₂).
-/
theorem div_eq_quo_add_rem_div_add_rem_div (f : R[X]) {g₁ g₂ : R[X]} (hg₁ : g₁.Monic)
(hg₂ : g₂.Monic) (hcoprime : IsCoprime g₁ g₂) :
∃ q r₁ r₂ : R[X],
r₁.degree < g₁.degree ∧
r₂.degree < g₂.degree ∧ (f : K) / (↑g₁ * ↑g₂) = ↑q + ↑r₁ / ↑g₁ + ↑r₂ / ↑g₂ := by
rcases hcoprime with ⟨c, d, hcd⟩
refine
⟨f * d /ₘ g₁ + f * c /ₘ g₂, f * d %ₘ g₁, f * c %ₘ g₂, degree_modByMonic_lt _ hg₁,
degree_modByMonic_lt _ hg₂, ?_⟩
have hg₁' : (↑g₁ : K) ≠ 0 := by
norm_cast
exact hg₁.ne_zero
have hg₂' : (↑g₂ : K) ≠ 0 := by
norm_cast
exact hg₂.ne_zero
have hfc := modByMonic_add_div (f * c) hg₂
have hfd := modByMonic_add_div (f * d) hg₁
field_simp
norm_cast
linear_combination -1 * f * hcd + -1 * g₁ * hfc + -1 * g₂ * hfd
end TwoDenominators
section NDenominators
open algebraMap
/-- Let R be an integral domain and f ∈ R[X]. Let s be a finite index set.
Then, a fraction of the form f / ∏ (g i) can be rewritten as q + ∑ (r i) / (g i), where
deg(r i) < deg(g i), provided that the g i are monic and pairwise coprime.
-/
theorem div_eq_quo_add_sum_rem_div (f : R[X]) {ι : Type*} {g : ι → R[X]} {s : Finset ι}
(hg : ∀ i ∈ s, (g i).Monic) (hcop : Set.Pairwise ↑s fun i j => IsCoprime (g i) (g j)) :
∃ (q : R[X]) (r : ι → R[X]),
(∀ i ∈ s, (r i).degree < (g i).degree) ∧
((↑f : K) / ∏ i ∈ s, ↑(g i)) = ↑q + ∑ i ∈ s, (r i : K) / (g i : K) := by
classical
induction s using Finset.induction_on generalizing f with
| empty =>
refine ⟨f, fun _ : ι => (0 : R[X]), fun i => ?_, by simp⟩
rintro ⟨⟩
| insert a b hab Hind => ?_
obtain ⟨q₀, r₁, r₂, hdeg₁, _, hf : (↑f : K) / _ = _⟩ :=
div_eq_quo_add_rem_div_add_rem_div R K f
(hg a (b.mem_insert_self a) : Monic (g a))
(monic_prod_of_monic _ _ fun i hi => hg i (Finset.mem_insert_of_mem hi) :
Monic (∏ i ∈ b, g i))
(IsCoprime.prod_right fun i hi =>
hcop (Finset.mem_coe.2 (b.mem_insert_self a))
(Finset.mem_coe.2 (Finset.mem_insert_of_mem hi)) (by rintro rfl; exact hab hi))
obtain ⟨q, r, hrdeg, IH⟩ :=
Hind _ (fun i hi => hg i (Finset.mem_insert_of_mem hi))
(Set.Pairwise.mono (Finset.coe_subset.2 fun i hi => Finset.mem_insert_of_mem hi) hcop)
refine ⟨q₀ + q, fun i => if i = a then r₁ else r i, ?_, ?_⟩
· intro i
dsimp only
split_ifs with h1
· cases h1
intro
exact hdeg₁
· intro hi
exact hrdeg i (Finset.mem_of_mem_insert_of_ne hi h1)
norm_cast at hf IH ⊢
rw [Finset.prod_insert hab, hf, IH, Finset.sum_insert hab, if_pos rfl]
trans (↑(q₀ + q : R[X]) : K) + (↑r₁ / ↑(g a) + ∑ i ∈ b, (r i : K) / (g i : K))
· push_cast
ring
congr 2
refine Finset.sum_congr rfl fun x hxb => ?_
grind
end NDenominators |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Monic.lean | import Mathlib.Algebra.Polynomial.Reverse
import Mathlib.Algebra.Regular.SMul
/-!
# Theory of monic polynomials
We give several tools for proving that polynomials are monic, e.g.
`Monic.mul`, `Monic.map`, `Monic.pow`.
-/
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v y
variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y}
section Semiring
variable [Semiring R] {p q r : R[X]}
theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R :=
subsingleton_iff_zero_eq_one
theorem not_monic_zero_iff : ¬Monic (0 : R[X]) ↔ (0 : R) ≠ 1 :=
(monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not
theorem monic_zero_iff_subsingleton' :
Monic (0 : R[X]) ↔ (∀ f g : R[X], f = g) ∧ ∀ a b : R, a = b :=
Polynomial.monic_zero_iff_subsingleton.trans
⟨by
intro
simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩
theorem Monic.as_sum (hp : p.Monic) :
p = X ^ p.natDegree + ∑ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by
conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm]
suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul]
exact congr_arg C hp
@[deprecated (since := "2025-08-14")] alias ne_zero_of_ne_zero_of_monic :=
Monic.ne_zero_of_polynomial_ne
theorem Monic.map [Semiring S] (f : R →+* S) (hp : Monic p) : Monic (p.map f) :=
subsingleton_or_nontrivial S |>.elim (·.elim ..) fun _ ↦
f.map_one ▸ hp ▸ leadingCoeff_map_eq_of_isUnit_leadingCoeff _ <| hp ▸ isUnit_one
theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) :
Monic (C b * p) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) :
Monic (p * C b) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_X_pow_add {n : ℕ} (H : degree p < n) : Monic (X ^ n + p) :=
monic_of_degree_le n
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero])
variable (a) in
theorem monic_X_pow_add_C {n : ℕ} (h : n ≠ 0) : (X ^ n + C a).Monic :=
monic_X_pow_add <| (lt_of_le_of_lt degree_C_le
(by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true]))
theorem monic_X_add_C (x : R) : Monic (X + C x) :=
pow_one (X : R[X]) ▸ monic_X_pow_add_C x one_ne_zero
theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) :=
letI := Classical.decEq R
if h0 : (0 : R) = 1 then
haveI := subsingleton_of_zero_eq_one h0
Subsingleton.elim _ _
else by
have : p.leadingCoeff * q.leadingCoeff ≠ 0 := by
simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0]
rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul]
theorem Monic.pow (hp : Monic p) : ∀ n : ℕ, Monic (p ^ n)
| 0 => monic_one
| n + 1 => by
rw [pow_succ]
exact (Monic.pow hp n).mul hp
theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by
rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by
rwa [Monic, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by
contrapose! hpq
rw [Monic.def] at hpq ⊢
rwa [leadingCoeff_monic_mul hp]
theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by
contrapose! hpq
rw [Monic.def] at hpq ⊢
rwa [leadingCoeff_mul_monic hq]
namespace Monic
lemma comp (hp : p.Monic) (hq : q.Monic) (h : q.natDegree ≠ 0) : (p.comp q).Monic := by
nontriviality R
have : (p.comp q).natDegree = p.natDegree * q.natDegree :=
natDegree_comp_eq_of_mul_ne_zero <| by simp [hp.leadingCoeff, hq.leadingCoeff]
rw [Monic.def, Polynomial.leadingCoeff, this, coeff_comp_degree_mul_degree h, hp.leadingCoeff,
hq.leadingCoeff, one_pow, mul_one]
lemma comp_X_add_C (hp : p.Monic) (r : R) : (p.comp (X + C r)).Monic := by
nontriviality R
refine hp.comp (monic_X_add_C _) fun ha ↦ ?_
rw [natDegree_X_add_C] at ha
exact one_ne_zero ha
@[deprecated (since := "2025-10-26")] alias natDegree_eq_zero_iff_eq_one := natDegree_eq_zero
@[simp]
theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree ≤ 0 ↔ p = 1 := by
rw [← hp.natDegree_eq_zero, natDegree_eq_zero_iff_degree_le_zero]
theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) :
(p * q).natDegree = p.natDegree + q.natDegree := by
nontriviality R
apply natDegree_mul'
simp [hp.leadingCoeff, hq.leadingCoeff]
theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by
by_cases h : q = 0
· simp [h]
rw [degree_mul', hp.degree_mul]
· exact add_comm _ _
· rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero]
nonrec theorem natDegree_mul' (hp : p.Monic) (hq : q ≠ 0) :
(p * q).natDegree = p.natDegree + q.natDegree := by
rw [natDegree_mul']
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem natDegree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).natDegree = (q * p).natDegree := by
by_cases h : q = 0
· simp [h]
rw [hp.natDegree_mul' h, Polynomial.natDegree_mul', add_comm]
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem _root_.Polynomial.not_isUnit_X_add_C [Nontrivial R] (a : R) : ¬ IsUnit (X + C a) := by
rintro ⟨⟨_, g, hfg, hgf⟩, rfl⟩
have h := (monic_X_add_C a).natDegree_mul' (right_ne_zero_of_mul_eq_one hfg)
rw [hfg, natDegree_one, natDegree_X_add_C] at h
grind
theorem not_dvd_of_natDegree_lt (hp : Monic p) (h0 : q ≠ 0) (hl : natDegree q < natDegree p) :
¬p ∣ q := by
rintro ⟨r, rfl⟩
rw [hp.natDegree_mul' <| right_ne_zero_of_mul h0] at hl
exact hl.not_ge (Nat.le_add_right _ _)
theorem not_dvd_of_degree_lt (hp : Monic p) (h0 : q ≠ 0) (hl : degree q < degree p) : ¬p ∣ q :=
Monic.not_dvd_of_natDegree_lt hp h0 <| natDegree_lt_natDegree h0 hl
theorem nextCoeff_mul (hp : Monic p) (hq : Monic q) :
nextCoeff (p * q) = nextCoeff p + nextCoeff q := by
nontriviality
simp only [← coeff_one_reverse]
rw [reverse_mul] <;> simp [hp.leadingCoeff, hq.leadingCoeff, mul_coeff_one, add_comm]
theorem nextCoeff_pow (hp : p.Monic) (n : ℕ) : (p ^ n).nextCoeff = n • p.nextCoeff := by
induction n with
| zero => rw [pow_zero, zero_smul, ← map_one (f := C), nextCoeff_C_eq_zero]
| succ n ih => rw [pow_succ, (hp.pow n).nextCoeff_mul hp, ih, succ_nsmul]
theorem eq_one_of_map_eq_one {S : Type*} [Semiring S] [Nontrivial S] (f : R →+* S) (hp : p.Monic)
(map_eq : p.map f = 1) : p = 1 := by
nontriviality R
have hdeg : p.degree = 0 := by
rw [← degree_map_eq_of_leadingCoeff_ne_zero f _, map_eq, degree_one]
· rw [hp.leadingCoeff, f.map_one]
exact one_ne_zero
have hndeg : p.natDegree = 0 :=
WithBot.coe_eq_coe.mp ((degree_eq_natDegree hp.ne_zero).symm.trans hdeg)
convert eq_C_of_degree_eq_zero hdeg
rw [← hndeg, ← Polynomial.leadingCoeff, hp.leadingCoeff, C.map_one]
theorem natDegree_pow (hp : p.Monic) (n : ℕ) : (p ^ n).natDegree = n * p.natDegree := by
induction n with
| zero => simp
| succ n hn => rw [pow_succ, (hp.pow n).natDegree_mul hp, hn, Nat.succ_mul, add_comm]
end Monic
@[simp]
theorem natDegree_pow_X_add_C [Nontrivial R] (n : ℕ) (r : R) : ((X + C r) ^ n).natDegree = n := by
rw [(monic_X_add_C r).natDegree_pow, natDegree_X_add_C, mul_one]
theorem Monic.eq_one_of_isUnit (hm : Monic p) (hpu : IsUnit p) : p = 1 := by
nontriviality R
obtain ⟨q, h⟩ := hpu.exists_right_inv
have := hm.natDegree_mul' (right_ne_zero_of_mul_eq_one h)
rw [h, natDegree_one, eq_comm, add_eq_zero] at this
exact hm.natDegree_eq_zero.mp this.1
theorem Monic.isUnit_iff (hm : p.Monic) : IsUnit p ↔ p = 1 :=
⟨hm.eq_one_of_isUnit, fun h => h.symm ▸ isUnit_one⟩
theorem eq_of_monic_of_associated (hp : p.Monic) (hq : q.Monic) (hpq : Associated p q) : p = q := by
obtain ⟨u, rfl⟩ := hpq
rw [(hp.of_mul_monic_left hq).eq_one_of_isUnit u.isUnit, mul_one]
end Semiring
section CommSemiring
variable [CommSemiring R] {p : R[X]}
theorem monic_multiset_prod_of_monic (t : Multiset ι) (f : ι → R[X]) (ht : ∀ i ∈ t, Monic (f i)) :
Monic (t.map f).prod := by
revert ht
refine t.induction_on ?_ ?_; · simp
intro a t ih ht
rw [Multiset.map_cons, Multiset.prod_cons]
exact (ht _ (Multiset.mem_cons_self _ _)).mul (ih fun _ hi => ht _ (Multiset.mem_cons_of_mem hi))
theorem monic_prod_of_monic (s : Finset ι) (f : ι → R[X]) (hs : ∀ i ∈ s, Monic (f i)) :
Monic (∏ i ∈ s, f i) :=
monic_multiset_prod_of_monic s.1 f hs
theorem monic_finprod_of_monic (α : Type*) (f : α → R[X])
(hf : ∀ i ∈ Function.mulSupport f, Monic (f i)) :
Monic (finprod f) := by
classical
rw [finprod_def]
split_ifs
· exact monic_prod_of_monic _ _ fun a ha => hf a ((Set.Finite.mem_toFinset _).mp ha)
· exact monic_one
theorem Monic.nextCoeff_multiset_prod (t : Multiset ι) (f : ι → R[X]) (h : ∀ i ∈ t, Monic (f i)) :
nextCoeff (t.map f).prod = (t.map fun i => nextCoeff (f i)).sum := by
revert h
refine Multiset.induction_on t ?_ fun a t ih ht => ?_
· simp only [Multiset.notMem_zero, forall_prop_of_true, forall_prop_of_false, Multiset.map_zero,
Multiset.prod_zero, Multiset.sum_zero, not_false_iff, forall_true_iff]
rw [← C_1]
rw [nextCoeff_C_eq_zero]
· rw [Multiset.map_cons, Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons,
Monic.nextCoeff_mul, ih]
exacts [fun i hi => ht i (Multiset.mem_cons_of_mem hi), ht a (Multiset.mem_cons_self _ _),
monic_multiset_prod_of_monic _ _ fun b bs => ht _ (Multiset.mem_cons_of_mem bs)]
theorem Monic.nextCoeff_prod (s : Finset ι) (f : ι → R[X]) (h : ∀ i ∈ s, Monic (f i)) :
nextCoeff (∏ i ∈ s, f i) = ∑ i ∈ s, nextCoeff (f i) :=
Monic.nextCoeff_multiset_prod s.1 f h
variable [NoZeroDivisors R] {p q : R[X]}
lemma irreducible_of_monic (hp : p.Monic) (hp1 : p ≠ 1) :
Irreducible p ↔ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f = 1 ∨ g = 1 := by
refine
⟨fun h f g hf hg hp => (h.2 hp.symm).imp hf.eq_one_of_isUnit hg.eq_one_of_isUnit, fun h =>
⟨hp1 ∘ hp.eq_one_of_isUnit, fun f g hfg =>
(h (g * C f.leadingCoeff) (f * C g.leadingCoeff) ?_ ?_ ?_).symm.imp
(.of_mul_eq_one _)
(.of_mul_eq_one _)⟩⟩
· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, mul_comm, ← hfg, ← Monic]
· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, ← hfg, ← Monic]
· rw [mul_mul_mul_comm, ← C_mul, ← leadingCoeff_mul, ← hfg, hp.leadingCoeff, C_1, mul_one,
mul_comm, ← hfg]
lemma Monic.irreducible_iff_natDegree (hp : p.Monic) :
Irreducible p ↔
p ≠ 1 ∧ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f.natDegree = 0 ∨ g.natDegree = 0 := by
by_cases hp1 : p = 1; · simp [hp1]
rw [irreducible_of_monic hp hp1, and_iff_right hp1]
refine forall₄_congr fun a b ha hb => ?_
rw [ha.natDegree_eq_zero, hb.natDegree_eq_zero]
lemma Monic.irreducible_iff_natDegree' (hp : p.Monic) : Irreducible p ↔ p ≠ 1 ∧
∀ f g : R[X], f.Monic → g.Monic → f * g = p → g.natDegree ∉ Ioc 0 (p.natDegree / 2) := by
simp_rw [hp.irreducible_iff_natDegree, mem_Ioc, Nat.le_div_iff_mul_le zero_lt_two, mul_two]
apply and_congr_right'
constructor <;> intro h f g hf hg he <;> subst he
· rw [hf.natDegree_mul hg, add_le_add_iff_right]
exact fun ha => (h f g hf hg rfl).elim (ha.1.trans_le ha.2).ne' ha.1.ne'
· simp_rw [hf.natDegree_mul hg, pos_iff_ne_zero] at h
contrapose! h
obtain hl | hl := le_total f.natDegree g.natDegree
· exact ⟨g, f, hg, hf, mul_comm g f, h.1, by gcongr⟩
· exact ⟨f, g, hf, hg, rfl, h.2, by gcongr⟩
/-- Alternate phrasing of `Polynomial.Monic.irreducible_iff_natDegree'` where we only have to check
one divisor at a time. -/
lemma Monic.irreducible_iff_lt_natDegree_lt {p : R[X]} (hp : p.Monic) (hp1 : p ≠ 1) :
Irreducible p ↔ ∀ q, Monic q → natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) → ¬ q ∣ p := by
rw [hp.irreducible_iff_natDegree', and_iff_right hp1]
constructor
· rintro h g hg hdg ⟨f, rfl⟩
exact h f g (hg.of_mul_monic_left hp) hg (mul_comm f g) hdg
· rintro h f g - hg rfl hdg
exact h g hg hdg (dvd_mul_left g f)
lemma Monic.not_irreducible_iff_exists_add_mul_eq_coeff (hm : p.Monic) (hnd : p.natDegree = 2) :
¬Irreducible p ↔ ∃ c₁ c₂, p.coeff 0 = c₁ * c₂ ∧ p.coeff 1 = c₁ + c₂ := by
cases subsingleton_or_nontrivial R
· simp [natDegree_of_subsingleton] at hnd
rw [hm.irreducible_iff_natDegree', and_iff_right, hnd]
· push_neg
constructor
· rintro ⟨a, b, ha, hb, rfl, hdb⟩
simp only [zero_lt_two, Nat.div_self, Nat.Ioc_succ_singleton, zero_add, mem_singleton] at hdb
have hda := hnd
rw [ha.natDegree_mul hb, hdb] at hda
use a.coeff 0, b.coeff 0, mul_coeff_zero a b
simpa only [nextCoeff, hnd, add_right_cancel hda, hdb] using ha.nextCoeff_mul hb
· rintro ⟨c₁, c₂, hmul, hadd⟩
refine
⟨X + C c₁, X + C c₂, monic_X_add_C _, monic_X_add_C _, ?_, ?_⟩
· rw [p.as_sum_range_C_mul_X_pow, hnd, Finset.sum_range_succ, Finset.sum_range_succ,
Finset.sum_range_one, ← hnd, hm.coeff_natDegree, hnd, hmul, hadd, C_mul, C_add, C_1]
ring
· simp
· rintro rfl
simp [natDegree_one] at hnd
end CommSemiring
section Semiring
variable [Semiring R]
@[simp]
theorem Monic.natDegree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R →+* S) :
(P.map f).natDegree = P.natDegree := by
refine le_antisymm natDegree_map_le (le_natDegree_of_ne_zero ?_)
rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one]
exact one_ne_zero
@[simp]
theorem Monic.degree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R →+* S) :
(P.map f).degree = P.degree := by
simp_all
section Injective
open Function
variable [Semiring S] {f : R →+* S}
@[deprecated (since := "2025-10-26")]
alias leadingCoeff_map' := leadingCoeff_map_of_injective
@[deprecated (since := "2025-10-26")]
alias leadingCoeff_of_injective := leadingCoeff_map_of_injective
theorem monic_of_injective (hf : Injective f) {p : R[X]} (hp : (p.map f).Monic) : p.Monic := by
apply hf
rw [← leadingCoeff_map_of_injective hf, hp.leadingCoeff, f.map_one]
theorem _root_.Function.Injective.monic_map_iff (hf : Injective f) {p : R[X]} :
p.Monic ↔ (p.map f).Monic :=
⟨Monic.map _, Polynomial.monic_of_injective hf⟩
end Injective
end Semiring
section Ring
variable [Ring R] {p : R[X]}
theorem monic_X_sub_C (x : R) : Monic (X - C x) := by
simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)
theorem monic_X_pow_sub {n : ℕ} (H : degree p < n) : Monic (X ^ n - p) := by
simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) < n by rwa [← degree_neg p] at H)
/-- `X ^ n - a` is monic. -/
theorem monic_X_pow_sub_C {R : Type u} [Ring R] (a : R) {n : ℕ} (h : n ≠ 0) :
(X ^ n - C a).Monic := by
simpa only [map_neg, ← sub_eq_add_neg] using monic_X_pow_add_C (-a) h
theorem not_isUnit_X_pow_sub_one (R : Type*) [Ring R] [Nontrivial R] (n : ℕ) :
¬IsUnit (X ^ n - 1 : R[X]) := by
intro h
rcases eq_or_ne n 0 with (rfl | hn)
· simp at h
apply hn
rw [← @natDegree_one R, ← (monic_X_pow_sub_C _ hn).eq_one_of_isUnit h, natDegree_X_pow_sub_C]
lemma Monic.comp_X_sub_C {p : R[X]} (hp : p.Monic) (r : R) : (p.comp (X - C r)).Monic := by
simpa using hp.comp_X_add_C (-r)
theorem Monic.sub_of_left {p q : R[X]} (hp : Monic p) (hpq : degree q < degree p) :
Monic (p - q) := by
rw [sub_eq_add_neg]
apply hp.add_of_left
rwa [degree_neg]
theorem Monic.sub_of_right {p q : R[X]} (hq : q.leadingCoeff = -1) (hpq : degree p < degree q) :
Monic (p - q) := by
have : (-q).coeff (-q).natDegree = 1 := by
rw [natDegree_neg, coeff_neg, show q.coeff q.natDegree = -1 from hq, neg_neg]
rw [sub_eq_add_neg]
apply Monic.add_of_right this
rwa [degree_neg]
end Ring
section NonzeroSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem not_monic_zero : ¬Monic (0 : R[X]) :=
not_monic_zero_iff.mp zero_ne_one
end NonzeroSemiring
section NotZeroDivisor
-- TODO: using gh-8537, rephrase lemmas that involve commutation around `*` using the op-ring
variable [Semiring R] {p : R[X]}
theorem Monic.mul_left_ne_zero (hp : Monic p) {q : R[X]} (hq : q ≠ 0) : q * p ≠ 0 := by
by_cases h : p = 1
· simpa [h]
rw [Ne, ← degree_eq_bot, hp.degree_mul, WithBot.add_eq_bot, not_or, degree_eq_bot]
refine ⟨hq, ?_⟩
rw [← hp.degree_le_zero_iff_eq_one, not_le] at h
refine (lt_trans ?_ h).ne'
simp
theorem Monic.mul_right_ne_zero (hp : Monic p) {q : R[X]} (hq : q ≠ 0) : p * q ≠ 0 := by
by_cases h : p = 1
· simpa [h]
rw [Ne, ← degree_eq_bot, hp.degree_mul_comm, hp.degree_mul, WithBot.add_eq_bot, not_or,
degree_eq_bot]
refine ⟨hq, ?_⟩
rw [← hp.degree_le_zero_iff_eq_one, not_le] at h
refine (lt_trans ?_ h).ne'
simp
theorem Monic.mul_natDegree_lt_iff (h : Monic p) {q : R[X]} :
(p * q).natDegree < p.natDegree ↔ p ≠ 1 ∧ q = 0 := by
by_cases hq : q = 0
· suffices 0 < p.natDegree ↔ p.natDegree ≠ 0 by simpa [hq, ← h.natDegree_eq_zero]
exact ⟨fun h => h.ne', fun h => lt_of_le_of_ne (Nat.zero_le _) h.symm⟩
· simp [h.natDegree_mul', hq]
theorem Monic.mul_right_eq_zero_iff (h : Monic p) {q : R[X]} : p * q = 0 ↔ q = 0 := by
by_cases hq : q = 0 <;> simp [h.mul_right_ne_zero, hq]
theorem Monic.mul_left_eq_zero_iff (h : Monic p) {q : R[X]} : q * p = 0 ↔ q = 0 := by
by_cases hq : q = 0 <;> simp [h.mul_left_ne_zero, hq]
theorem Monic.isRegular {R : Type*} [Ring R] {p : R[X]} (hp : Monic p) : IsRegular p := by
constructor
· intro q r h
dsimp only at h
rw [← sub_eq_zero, ← hp.mul_right_eq_zero_iff, mul_sub, h, sub_self]
· intro q r h
simp only at h
rw [← sub_eq_zero, ← hp.mul_left_eq_zero_iff, sub_mul, h, sub_self]
theorem degree_smul_of_smul_regular {S : Type*} [SMulZeroClass S R] {k : S}
(p : R[X]) (h : IsSMulRegular R k) : (k • p).degree = p.degree := by
refine le_antisymm ?_ ?_
· rw [degree_le_iff_coeff_zero]
intro m hm
rw [degree_lt_iff_coeff_zero] at hm
simp [hm m le_rfl]
· rw [degree_le_iff_coeff_zero]
intro m hm
rw [degree_lt_iff_coeff_zero] at hm
refine h ?_
simpa using hm m le_rfl
theorem natDegree_smul_of_smul_regular {S : Type*} [SMulZeroClass S R] {k : S}
(p : R[X]) (h : IsSMulRegular R k) : (k • p).natDegree = p.natDegree := by
by_cases hp : p = 0
· simp [hp]
rw [← Nat.cast_inj (R := WithBot ℕ), ← degree_eq_natDegree hp, ← degree_eq_natDegree,
degree_smul_of_smul_regular p h]
contrapose! hp
rw [← smul_zero k] at hp
exact h.polynomial hp
theorem leadingCoeff_smul_of_smul_regular {S : Type*} [SMulZeroClass S R] {k : S}
(p : R[X]) (h : IsSMulRegular R k) : (k • p).leadingCoeff = k • p.leadingCoeff := by
rw [Polynomial.leadingCoeff, Polynomial.leadingCoeff, coeff_smul,
natDegree_smul_of_smul_regular p h]
theorem monic_of_isUnit_leadingCoeff_inv_smul (h : IsUnit p.leadingCoeff) :
Monic (h.unit⁻¹ • p) := by
rw [Monic.def, leadingCoeff_smul_of_smul_regular _ (isSMulRegular_of_group _), Units.smul_def]
simp
theorem isUnit_leadingCoeff_mul_right_eq_zero_iff (h : IsUnit p.leadingCoeff) {q : R[X]} :
p * q = 0 ↔ q = 0 := by
constructor
· intro hp
rw [← smul_eq_zero_iff_eq h.unit⁻¹] at hp
have : h.unit⁻¹ • (p * q) = h.unit⁻¹ • p * q := by
ext
simp only [Units.smul_def, coeff_smul, coeff_mul, smul_eq_mul, mul_sum]
refine sum_congr rfl fun x _ => ?_
rw [← mul_assoc]
rwa [this, Monic.mul_right_eq_zero_iff] at hp
exact monic_of_isUnit_leadingCoeff_inv_smul _
· rintro rfl
simp
theorem isUnit_leadingCoeff_mul_left_eq_zero_iff (h : IsUnit p.leadingCoeff) {q : R[X]} :
q * p = 0 ↔ q = 0 := by
constructor
· intro hp
replace hp := congr_arg (· * C ↑h.unit⁻¹) hp
simp only [zero_mul] at hp
rwa [mul_assoc, Monic.mul_left_eq_zero_iff] at hp
refine monic_mul_C_of_leadingCoeff_mul_eq_one ?_
simp
· rintro rfl
rw [zero_mul]
end NotZeroDivisor
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/HasseDeriv.lean | import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Data.Nat.Choose.Cast
import Mathlib.Data.Nat.Choose.Vandermonde
import Mathlib.Tactic.Field
import Mathlib.Tactic.Positivity
/-!
# Hasse derivative of polynomials
The `k`th Hasse derivative of a polynomial `∑ a_i X^i` is `∑ (i.choose k) a_i X^(i-k)`.
It is a variant of the usual derivative, and satisfies `k! * (hasseDeriv k f) = derivative^[k] f`.
The main benefit is that is gives an atomic way of talking about expressions such as
`(derivative^[k] f).eval r / k!`, that occur in Taylor expansions, for example.
## Main declarations
In the following, we write `D k` for the `k`-th Hasse derivative `hasse_deriv k`.
* `Polynomial.hasseDeriv`: the `k`-th Hasse derivative of a polynomial
* `Polynomial.hasseDeriv_zero`: the `0`th Hasse derivative is the identity
* `Polynomial.hasseDeriv_one`: the `1`st Hasse derivative is the usual derivative
* `Polynomial.factorial_smul_hasseDeriv`: the identity `k! • (D k f) = derivative^[k] f`
* `Polynomial.hasseDeriv_comp`: the identity `(D k).comp (D l) = (k+l).choose k • D (k+l)`
* `Polynomial.hasseDeriv_mul`:
the "Leibniz rule" `D k (f * g) = ∑ ij ∈ antidiagonal k, D ij.1 f * D ij.2 g`
For the identity principle, see `Polynomial.eq_zero_of_hasseDeriv_eq_zero`
in `Data/Polynomial/Taylor.lean`.
## Reference
https://math.fontein.de/2009/08/12/the-hasse-derivative/
-/
noncomputable section
namespace Polynomial
open Nat Polynomial
open Function
variable {R : Type*} [Semiring R] (k : ℕ) (f : R[X])
/-- The `k`th Hasse derivative of a polynomial `∑ a_i X^i` is `∑ (i.choose k) a_i X^(i-k)`.
It satisfies `k! * (hasse_deriv k f) = derivative^[k] f`. -/
def hasseDeriv (k : ℕ) : R[X] →ₗ[R] R[X] :=
lsum fun i => monomial (i - k) ∘ₗ DistribMulAction.toLinearMap R R (i.choose k)
theorem hasseDeriv_apply :
hasseDeriv k f = f.sum fun i r => monomial (i - k) (↑(i.choose k) * r) := by
dsimp [hasseDeriv]
simp
theorem hasseDeriv_coeff (n : ℕ) :
(hasseDeriv k f).coeff n = (n + k).choose k * f.coeff (n + k) := by
rw [hasseDeriv_apply, coeff_sum, sum_def, Finset.sum_eq_single (n + k), coeff_monomial]
· simp only [if_true, add_tsub_cancel_right]
· #adaptation_note
/-- Prior to nightly-2025-08-14, this was working as
`grind [coeff_monomial, Nat.choose_eq_zero_of_lt, Nat.cast_zero, zero_mul]` -/
intro i _hi hink
rw [coeff_monomial]
by_cases hik : i < k
· simp only [Nat.choose_eq_zero_of_lt hik, ite_self, Nat.cast_zero, zero_mul]
· grind
· intro h
simp only [notMem_support_iff.mp h, monomial_zero_right, mul_zero, coeff_zero]
theorem hasseDeriv_zero' : hasseDeriv 0 f = f := by
simp only [hasseDeriv_apply, tsub_zero, Nat.choose_zero_right, Nat.cast_one, one_mul,
sum_monomial_eq]
@[simp]
theorem hasseDeriv_zero : @hasseDeriv R _ 0 = LinearMap.id :=
LinearMap.ext <| hasseDeriv_zero'
theorem hasseDeriv_eq_zero_of_lt_natDegree (p : R[X]) (n : ℕ) (h : p.natDegree < n) :
hasseDeriv n p = 0 := by
rw [hasseDeriv_apply, sum_def]
refine Finset.sum_eq_zero fun x hx => ?_
simp [Nat.choose_eq_zero_of_lt ((le_natDegree_of_mem_supp _ hx).trans_lt h)]
theorem hasseDeriv_one' : hasseDeriv 1 f = derivative f := by
simp only [hasseDeriv_apply, derivative_apply, ← C_mul_X_pow_eq_monomial, Nat.choose_one_right,
(Nat.cast_commute _ _).eq]
@[simp]
theorem hasseDeriv_one : @hasseDeriv R _ 1 = derivative :=
LinearMap.ext <| hasseDeriv_one'
@[simp]
theorem hasseDeriv_monomial (n : ℕ) (r : R) :
hasseDeriv k (monomial n r) = monomial (n - k) (↑(n.choose k) * r) := by
ext i
simp only [hasseDeriv_coeff, coeff_monomial]
by_cases hnik : n = i + k
· grind
· rw [if_neg hnik, mul_zero]
by_cases! hkn : k ≤ n
· rw [← tsub_eq_iff_eq_add_of_le hkn] at hnik
rw [if_neg hnik]
· rw [Nat.choose_eq_zero_of_lt hkn, Nat.cast_zero, zero_mul, ite_self]
theorem hasseDeriv_C (r : R) (hk : 0 < k) : hasseDeriv k (C r) = 0 := by
rw [← monomial_zero_left, hasseDeriv_monomial, Nat.choose_eq_zero_of_lt hk, Nat.cast_zero,
zero_mul, monomial_zero_right]
theorem hasseDeriv_apply_one (hk : 0 < k) : hasseDeriv k (1 : R[X]) = 0 := by
rw [← C_1, hasseDeriv_C k _ hk]
theorem hasseDeriv_X (hk : 1 < k) : hasseDeriv k (X : R[X]) = 0 := by
rw [← monomial_one_one_eq_X, hasseDeriv_monomial, Nat.choose_eq_zero_of_lt hk, Nat.cast_zero,
zero_mul, monomial_zero_right]
theorem factorial_smul_hasseDeriv : ⇑(k ! • @hasseDeriv R _ k) = (@derivative R _)^[k] := by
induction k with
| zero => rw [hasseDeriv_zero, factorial_zero, iterate_zero, one_smul, LinearMap.id_coe]
| succ k ih => ?_
ext f n : 2
rw [iterate_succ_apply', ← ih]
simp only [LinearMap.smul_apply, coeff_smul, LinearMap.map_smul_of_tower, coeff_derivative,
hasseDeriv_coeff, ← @choose_symm_add _ k]
simp only [nsmul_eq_mul, factorial_succ, mul_assoc, succ_eq_add_one, ← add_assoc,
add_right_comm n 1 k, ← cast_succ]
rw [← (cast_commute (n + 1) (f.coeff (n + k + 1))).eq]
simp only [← mul_assoc]
norm_cast
congr 2
rw [mul_comm (k+1) _, mul_assoc, mul_assoc]
congr 1
have : n + k + 1 = n + (k + 1) := by apply add_assoc
rw [← choose_symm_of_eq_add this, choose_succ_right_eq, mul_comm]
congr
rw [add_assoc, add_tsub_cancel_left]
theorem hasseDeriv_comp (k l : ℕ) :
(@hasseDeriv R _ k).comp (hasseDeriv l) = (k + l).choose k • hasseDeriv (k + l) := by
ext i : 2
simp only [LinearMap.smul_apply, comp_apply, LinearMap.coe_comp, smul_monomial, hasseDeriv_apply,
mul_one, monomial_eq_zero_iff, sum_monomial_index, mul_zero, ←
tsub_add_eq_tsub_tsub, add_comm l k]
rw_mod_cast [nsmul_eq_mul]
rw [← Nat.cast_mul]
congr 2
by_cases! hikl : i < k + l
· rw [choose_eq_zero_of_lt hikl, mul_zero]
by_cases! hil : i < l
· rw [choose_eq_zero_of_lt hil, mul_zero]
· rw [← tsub_lt_iff_right hil] at hikl
rw [choose_eq_zero_of_lt hikl, zero_mul]
apply @cast_injective ℚ
have h1 : l ≤ i := le_of_add_le_right hikl
have h2 : k ≤ i - l := le_tsub_of_add_le_right hikl
have h3 : k ≤ k + l := le_self_add
push_cast
rw [cast_choose ℚ h1, cast_choose ℚ h2, cast_choose ℚ h3, cast_choose ℚ hikl]
rw [show i - (k + l) = i - l - k by rw [add_comm]; apply tsub_add_eq_tsub_tsub]
simp only [add_tsub_cancel_left]
field
theorem natDegree_hasseDeriv_le (p : R[X]) (n : ℕ) :
natDegree (hasseDeriv n p) ≤ natDegree p - n := by
classical
rw [hasseDeriv_apply, sum_def]
refine (natDegree_sum_le _ _).trans ?_
simp_rw [Function.comp, natDegree_monomial]
rw [Finset.fold_ite, Finset.fold_const]
· simp only [ite_self, max_eq_right, zero_le', Finset.fold_max_le, true_and, and_imp,
tsub_le_iff_right, mem_support_iff, Ne, Finset.mem_filter]
intro x hx hx'
have hxp : x ≤ p.natDegree := le_natDegree_of_ne_zero hx
grind
· simp
theorem hasseDeriv_natDegree_eq_C : f.hasseDeriv f.natDegree = C f.leadingCoeff := by
have : _ ≤ 0 := Nat.sub_self f.natDegree ▸ natDegree_hasseDeriv_le ..
rw [eq_C_of_natDegree_le_zero this, hasseDeriv_coeff, zero_add, Nat.choose_self,
Nat.cast_one, one_mul, leadingCoeff]
theorem natDegree_hasseDeriv [IsAddTorsionFree R] (p : R[X]) (n : ℕ) :
natDegree (hasseDeriv n p) = natDegree p - n := by
classical
refine map_natDegree_eq_sub (fun h => hasseDeriv_eq_zero_of_lt_natDegree _ _) ?_
simp only [Ne, hasseDeriv_monomial, natDegree_monomial, ite_eq_right_iff]
simp +contextual [← nsmul_eq_mul, Nat.choose_eq_zero_iff, le_of_lt]
section
open AddMonoidHom Finset.Nat
open Finset (antidiagonal mem_antidiagonal)
theorem hasseDeriv_mul (f g : R[X]) :
hasseDeriv k (f * g) = ∑ ij ∈ antidiagonal k, hasseDeriv ij.1 f * hasseDeriv ij.2 g := by
let D k := (@hasseDeriv R _ k).toAddMonoidHom
let Φ := @AddMonoidHom.mul R[X] _
change
(compHom (D k)).comp Φ f g =
∑ ij ∈ antidiagonal k, ((compHom.comp ((compHom Φ) (D ij.1))).flip (D ij.2) f) g
simp only [← finset_sum_apply]
congr 2
clear f g
ext m r n s : 4
simp only [Φ, D, finset_sum_apply, coe_mulLeft, coe_comp, flip_apply, Function.comp_apply,
hasseDeriv_monomial, LinearMap.toAddMonoidHom_coe, compHom_apply_apply,
coe_mul, monomial_mul_monomial]
have aux :
∀ x : ℕ × ℕ,
x ∈ antidiagonal k →
monomial (m - x.1 + (n - x.2)) (↑(m.choose x.1) * r * (↑(n.choose x.2) * s)) =
monomial (m + n - k) (↑(m.choose x.1) * ↑(n.choose x.2) * (r * s)) := by
intro x hx
rw [mem_antidiagonal] at hx
subst hx
by_cases! hm : m < x.1
· simp only [Nat.choose_eq_zero_of_lt hm, Nat.cast_zero, zero_mul,
monomial_zero_right]
by_cases! hn : n < x.2
· simp only [Nat.choose_eq_zero_of_lt hn, Nat.cast_zero, zero_mul,
mul_zero, monomial_zero_right]
rw [tsub_add_eq_add_tsub hm, ← add_tsub_assoc_of_le hn, ← tsub_add_eq_tsub_tsub,
add_comm x.2 x.1, mul_assoc, ← mul_assoc r, ← (Nat.cast_commute _ r).eq, mul_assoc, mul_assoc]
rw [Finset.sum_congr rfl aux]
rw [← map_sum, ← Finset.sum_mul]
congr
rw_mod_cast [← Nat.add_choose_eq]
end
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Splits.lean | import Mathlib.Algebra.Polynomial.Factors
import Mathlib.Algebra.Polynomial.Lifts
import Mathlib.RingTheory.Polynomial.Tower
/-!
# Split polynomials
A polynomial `f : K[X]` splits over a field extension `L` of `K` if it is zero or all of its
irreducible factors over `L` have degree `1`.
## Main definitions
* `Polynomial.Splits i f`: A predicate on a homomorphism `i : K →+* L` from a commutative ring to a
field and a polynomial `f` saying that `f.map i` factors in `L`.
-/
noncomputable section
open Polynomial
universe u v w
variable {R : Type*} {F : Type u} {K : Type v} {L : Type w}
namespace Polynomial
section Splits
section CommRing
variable [CommRing K] [Field L] [Field F]
variable (i : K →+* L)
/-- A polynomial `Splits` iff it `Factors` after mapping under a ring homomorphism.
This will eventually be replaced by `Polynomial.Factors`. -/
def Splits (f : K[X]) : Prop :=
Factors (f.map i)
@[simp]
theorem splits_zero : Splits i (0 : K[X]) := by
simp [Splits]
theorem splits_of_map_eq_C {f : K[X]} {a : L} (h : f.map i = C a) : Splits i f := by
simp [Splits, h]
@[simp]
theorem splits_C (a : K) : Splits i (C a) := by
simp [Splits]
theorem splits_of_map_degree_eq_one {f : K[X]} (hf : degree (f.map i) = 1) : Splits i f :=
Factors.of_degree_eq_one hf
theorem splits_of_degree_le_one {f : K[X]} (hf : degree f ≤ 1) : Splits i f :=
Factors.of_degree_le_one (degree_map_le.trans hf)
theorem splits_of_degree_eq_one {f : K[X]} (hf : degree f = 1) : Splits i f :=
splits_of_degree_le_one i hf.le
theorem splits_of_natDegree_le_one {f : K[X]} (hf : natDegree f ≤ 1) : Splits i f :=
splits_of_degree_le_one i (degree_le_of_natDegree_le hf)
theorem splits_of_natDegree_eq_one {f : K[X]} (hf : natDegree f = 1) : Splits i f :=
splits_of_natDegree_le_one i (le_of_eq hf)
theorem splits_mul {f g : K[X]} (hf : Splits i f) (hg : Splits i g) : Splits i (f * g) := by
simp [Splits, hf.mul hg]
theorem splits_of_splits_mul' {f g : K[X]} (hfg : (f * g).map i ≠ 0) (h : Splits i (f * g)) :
Splits i f ∧ Splits i g := by
simp only [Splits, Polynomial.map_mul, mul_ne_zero_iff] at hfg h
exact (factors_mul_iff hfg.1 hfg.2).mp h
theorem splits_map_iff {L : Type*} [CommRing L] (i : K →+* L) (j : L →+* F) {f : K[X]} :
Splits j (f.map i) ↔ Splits (j.comp i) f := by
simp [Splits, Polynomial.map_map]
theorem splits_one : Splits i 1 :=
splits_C i 1
theorem splits_of_isUnit [IsDomain K] {u : K[X]} (hu : IsUnit u) : u.Splits i :=
(isUnit_iff.mp hu).choose_spec.2 ▸ splits_C _ _
theorem splits_X_sub_C {x : K} : (X - C x).Splits i :=
splits_of_degree_le_one _ <| degree_X_sub_C_le _
theorem splits_X : X.Splits i :=
splits_of_degree_le_one _ degree_X_le
theorem splits_prod {ι : Type u} {s : ι → K[X]} {t : Finset ι} :
(∀ j ∈ t, (s j).Splits i) → (∏ x ∈ t, s x).Splits i := by
classical
refine Finset.induction_on t (fun _ => splits_one i) fun a t hat ih ht => ?_
rw [Finset.forall_mem_insert] at ht; rw [Finset.prod_insert hat]
exact splits_mul i ht.1 (ih ht.2)
theorem splits_pow {f : K[X]} (hf : f.Splits i) (n : ℕ) : (f ^ n).Splits i := by
rw [← Finset.card_range n, ← Finset.prod_const]
exact splits_prod i fun j _ => hf
theorem splits_X_pow (n : ℕ) : (X ^ n).Splits i :=
splits_pow i (splits_X i) n
theorem splits_id_iff_splits {f : K[X]} : (f.map i).Splits (RingHom.id L) ↔ f.Splits i := by
rw [splits_map_iff, RingHom.id_comp]
variable {i}
-- TODO: Prove the analogous composition theorems for `Factors`
theorem Splits.comp_of_map_degree_le_one {f : K[X]} {p : K[X]} (hd : (p.map i).degree ≤ 1)
(h : f.Splits i) : (f.comp p).Splits i := by
rw [Splits, factors_iff_splits] at h ⊢
by_cases hzero : map i (f.comp p) = 0
· exact Or.inl hzero
cases h with
| inl h0 =>
exact Or.inl <| map_comp i _ _ ▸ h0.symm ▸ zero_comp
| inr h =>
right
intro g irr dvd
rw [map_comp] at dvd hzero
cases lt_or_eq_of_le hd with
| inl hd =>
rw [eq_C_of_degree_le_zero (Nat.WithBot.lt_one_iff_le_zero.mp hd), comp_C] at dvd hzero
refine False.elim (irr.1 (isUnit_of_dvd_unit dvd ?_))
simpa using hzero
| inr hd =>
let _ := invertibleOfNonzero (leadingCoeff_ne_zero.mpr
(ne_zero_of_degree_gt (n := ⊥) (by rw [hd]; decide)))
rw [eq_X_add_C_of_degree_eq_one hd, dvd_comp_C_mul_X_add_C_iff _ _] at dvd
have := h (irr.map (algEquivCMulXAddC _ _).symm) dvd
rw [degree_eq_natDegree irr.ne_zero]
rwa [algEquivCMulXAddC_symm_apply, ← comp_eq_aeval,
degree_eq_natDegree (fun h => WithBot.bot_ne_one (h ▸ this)),
natDegree_comp, natDegree_C_mul (invertibleInvOf.ne_zero),
natDegree_X_sub_C, mul_one] at this
theorem splits_iff_comp_splits_of_degree_eq_one {f : K[X]} {p : K[X]} (hd : (p.map i).degree = 1) :
f.Splits i ↔ (f.comp p).Splits i := by
rw [← splits_id_iff_splits, ← splits_id_iff_splits (f := f.comp p), map_comp]
refine ⟨fun h => Splits.comp_of_map_degree_le_one
(le_of_eq (map_id (R := L) ▸ hd)) h, fun h => ?_⟩
let _ := invertibleOfNonzero (leadingCoeff_ne_zero.mpr
(ne_zero_of_degree_gt (n := ⊥) (by rw [hd]; decide)))
have : (map i f) = ((map i f).comp (map i p)).comp ((C ⅟(map i p).leadingCoeff *
(X - C ((map i p).coeff 0)))) := by
rw [comp_assoc]
nth_rw 1 [eq_X_add_C_of_degree_eq_one hd]
simp only [coeff_map, invOf_eq_inv, mul_sub, ← C_mul, add_comp, mul_comp, C_comp, X_comp,
← mul_assoc]
simp
refine this ▸ Splits.comp_of_map_degree_le_one ?_ h
simp [degree_C (inv_ne_zero (Invertible.ne_zero (a := (map i p).leadingCoeff)))]
/--
This is a weaker variant of `Splits.comp_of_map_degree_le_one`,
but its conditions are easier to check.
-/
theorem Splits.comp_of_degree_le_one {f : K[X]} {p : K[X]} (hd : p.degree ≤ 1)
(h : f.Splits i) : (f.comp p).Splits i :=
Splits.comp_of_map_degree_le_one (degree_map_le.trans hd) h
theorem Splits.comp_X_sub_C (a : K) {f : K[X]}
(h : f.Splits i) : (f.comp (X - C a)).Splits i :=
Splits.comp_of_degree_le_one (degree_X_sub_C_le _) h
theorem Splits.comp_X_add_C (a : K) {f : K[X]}
(h : f.Splits i) : (f.comp (X + C a)).Splits i :=
Splits.comp_of_degree_le_one (by simpa using degree_X_sub_C_le (-a)) h
theorem Splits.comp_neg_X {f : K[X]} (h : f.Splits i) : (f.comp (-X)).Splits i :=
Splits.comp_of_degree_le_one (by simpa using degree_X_sub_C_le (0 : K)) h
variable (i)
theorem exists_root_of_splits' {f : K[X]} (hs : Splits i f) (hf0 : degree (f.map i) ≠ 0) :
∃ x, eval₂ i x f = 0 := by
simpa only [eval_map] using hs.exists_eval_eq_zero hf0
theorem roots_ne_zero_of_splits' {f : K[X]} (hs : Splits i f) (hf0 : natDegree (f.map i) ≠ 0) :
(f.map i).roots ≠ 0 :=
hs.roots_ne_zero hf0
/-- Pick a root of a polynomial that splits. See `rootOfSplits` for polynomials over a field
which has simpler assumptions. -/
def rootOfSplits' {f : K[X]} (hf : f.Splits i) (hfd : (f.map i).degree ≠ 0) : L :=
Classical.choose <| exists_root_of_splits' i hf hfd
theorem map_rootOfSplits' {f : K[X]} (hf : f.Splits i) (hfd) :
f.eval₂ i (rootOfSplits' i hf hfd) = 0 :=
Classical.choose_spec <| exists_root_of_splits' i hf hfd
theorem natDegree_eq_card_roots' {p : K[X]} {i : K →+* L} (hsplit : Splits i p) :
(p.map i).natDegree = Multiset.card (p.map i).roots :=
hsplit.natDegree_eq_card_roots
theorem degree_eq_card_roots' {p : K[X]} {i : K →+* L} (p_ne_zero : p.map i ≠ 0)
(hsplit : Splits i p) : (p.map i).degree = Multiset.card (p.map i).roots := by
simp [degree_eq_natDegree p_ne_zero, natDegree_eq_card_roots' hsplit]
end CommRing
theorem aeval_root_of_mapAlg_eq_multiset_prod_X_sub_C [CommSemiring R] [CommRing L] [Algebra R L]
(s : Multiset L) {x : L} (hx : x ∈ s) {p : R[X]}
(hp : mapAlg R L p = (Multiset.map (fun a : L ↦ X - C a) s).prod) : aeval x p = 0 := by
rw [← aeval_map_algebraMap L, ← mapAlg_eq_map, hp, map_multiset_prod, Multiset.prod_eq_zero]
rw [Multiset.map_map, Multiset.mem_map]
exact ⟨x, hx, by simp⟩
variable [CommRing R] [Field K] [Field L] [Field F]
variable (i : K →+* L)
/-- This lemma is for polynomials over a field. -/
theorem splits_iff (f : K[X]) :
Splits i f ↔ f = 0 ∨ ∀ {g : L[X]}, Irreducible g → g ∣ f.map i → degree g = 1 := by
rw [Splits, factors_iff_splits, Polynomial.map_eq_zero]
/-- This lemma is for polynomials over a field. -/
theorem Splits.def {i : K →+* L} {f : K[X]} (h : Splits i f) :
f = 0 ∨ ∀ {g : L[X]}, Irreducible g → g ∣ f.map i → degree g = 1 :=
(splits_iff i f).mp h
theorem splits_of_splits_mul {f g : K[X]} (hfg : f * g ≠ 0) (h : Splits i (f * g)) :
Splits i f ∧ Splits i g :=
splits_of_splits_mul' i (map_ne_zero hfg) h
theorem splits_of_splits_of_dvd {f g : K[X]} (hf0 : f ≠ 0) (hf : Splits i f) (hgf : g ∣ f) :
Splits i g := by
obtain ⟨f, rfl⟩ := hgf
exact (splits_of_splits_mul i hf0 hf).1
theorem splits_of_splits_gcd_left [DecidableEq K] {f g : K[X]} (hf0 : f ≠ 0) (hf : Splits i f) :
Splits i (EuclideanDomain.gcd f g) :=
Polynomial.splits_of_splits_of_dvd i hf0 hf (EuclideanDomain.gcd_dvd_left f g)
theorem splits_of_splits_gcd_right [DecidableEq K] {f g : K[X]} (hg0 : g ≠ 0) (hg : Splits i g) :
Splits i (EuclideanDomain.gcd f g) :=
Polynomial.splits_of_splits_of_dvd i hg0 hg (EuclideanDomain.gcd_dvd_right f g)
theorem splits_mul_iff {f g : K[X]} (hf : f ≠ 0) (hg : g ≠ 0) :
(f * g).Splits i ↔ f.Splits i ∧ g.Splits i :=
⟨splits_of_splits_mul i (mul_ne_zero hf hg), fun ⟨hfs, hgs⟩ => splits_mul i hfs hgs⟩
theorem splits_prod_iff {ι : Type u} {s : ι → K[X]} {t : Finset ι} :
(∀ j ∈ t, s j ≠ 0) → ((∏ x ∈ t, s x).Splits i ↔ ∀ j ∈ t, (s j).Splits i) := by
classical
refine
Finset.induction_on t (fun _ =>
⟨fun _ _ h => by simp only [Finset.notMem_empty] at h, fun _ => splits_one i⟩)
fun a t hat ih ht => ?_
rw [Finset.forall_mem_insert] at ht ⊢
rw [Finset.prod_insert hat, splits_mul_iff i ht.1 (Finset.prod_ne_zero_iff.2 ht.2), ih ht.2]
theorem degree_eq_one_of_irreducible_of_splits {p : K[X]} (hp : Irreducible p)
(hp_splits : Splits (RingHom.id K) p) : p.degree = 1 := by
rw [Splits, factors_iff_splits] at hp_splits
rcases hp_splits with ⟨⟩ | hp_splits
· exfalso
simp_all
· apply hp_splits hp
simp
theorem exists_root_of_splits {f : K[X]} (hs : Splits i f) (hf0 : degree f ≠ 0) :
∃ x, eval₂ i x f = 0 :=
exists_root_of_splits' i hs ((f.degree_map i).symm ▸ hf0)
theorem roots_ne_zero_of_splits {f : K[X]} (hs : Splits i f) (hf0 : natDegree f ≠ 0) :
(f.map i).roots ≠ 0 :=
roots_ne_zero_of_splits' i hs (ne_of_eq_of_ne (natDegree_map i) hf0)
/-- Pick a root of a polynomial that splits. This version is for polynomials over a field and has
simpler assumptions. -/
def rootOfSplits {f : K[X]} (hf : f.Splits i) (hfd : f.degree ≠ 0) : L :=
rootOfSplits' i hf ((f.degree_map i).symm ▸ hfd)
/-- `rootOfSplits'` is definitionally equal to `rootOfSplits`. -/
theorem rootOfSplits'_eq_rootOfSplits {f : K[X]} (hf : f.Splits i) (hfd) :
rootOfSplits' i hf hfd = rootOfSplits i hf (f.degree_map i ▸ hfd) :=
rfl
theorem map_rootOfSplits {f : K[X]} (hf : f.Splits i) (hfd) :
f.eval₂ i (rootOfSplits i hf hfd) = 0 :=
map_rootOfSplits' i hf (ne_of_eq_of_ne (degree_map f i) hfd)
theorem natDegree_eq_card_roots {p : K[X]} {i : K →+* L} (hsplit : Splits i p) :
p.natDegree = Multiset.card (p.map i).roots :=
(natDegree_map i).symm.trans <| natDegree_eq_card_roots' hsplit
theorem degree_eq_card_roots {p : K[X]} {i : K →+* L} (p_ne_zero : p ≠ 0) (hsplit : Splits i p) :
p.degree = Multiset.card (p.map i).roots := by
rw [degree_eq_natDegree p_ne_zero, natDegree_eq_card_roots hsplit]
theorem roots_map {f : K[X]} (hf : f.Splits <| RingHom.id K) : (f.map i).roots = f.roots.map i :=
(roots_map_of_injective_of_card_eq_natDegree i.injective <| by
convert (natDegree_eq_card_roots hf).symm
rw [map_id]).symm
theorem Splits.mem_subfield_of_isRoot (F : Subfield K) {f : F[X]} (hnz : f ≠ 0)
(hf : Splits (RingHom.id F) f) {x : K} (hx : (f.map F.subtype).IsRoot x) :
x ∈ F := by
obtain ⟨x, _, rfl⟩ := Multiset.mem_map.mp
(roots_map F.subtype hf ▸ mem_roots'.mpr ⟨Polynomial.map_ne_zero hnz, hx⟩)
exact x.2
theorem image_rootSet [Algebra R K] [Algebra R L] {p : R[X]} (h : p.Splits (algebraMap R K))
(f : K →ₐ[R] L) : f '' p.rootSet K = p.rootSet L := by
classical
rw [rootSet, ← Finset.coe_image, ← Multiset.toFinset_map, ← f.coe_toRingHom,
← roots_map _ ((splits_id_iff_splits (algebraMap R K)).mpr h), map_map, f.comp_algebraMap,
← rootSet]
theorem adjoin_rootSet_eq_range [Algebra R K] [Algebra R L] {p : R[X]}
(h : p.Splits (algebraMap R K)) (f : K →ₐ[R] L) :
Algebra.adjoin R (p.rootSet L) = f.range ↔ Algebra.adjoin R (p.rootSet K) = ⊤ := by
rw [← image_rootSet h f, Algebra.adjoin_image, ← Algebra.map_top]
exact (Subalgebra.map_injective f.toRingHom.injective).eq_iff
theorem eq_prod_roots_of_splits {p : K[X]} {i : K →+* L} (hsplit : Splits i p) :
p.map i = C (i p.leadingCoeff) * ((p.map i).roots.map fun a => X - C a).prod := by
rw [← leadingCoeff_map]; symm
apply C_leadingCoeff_mul_prod_multiset_X_sub_C
rw [natDegree_map]; exact (natDegree_eq_card_roots hsplit).symm
theorem eq_prod_roots_of_splits_id {p : K[X]} (hsplit : Splits (RingHom.id K) p) :
p = C p.leadingCoeff * (p.roots.map fun a => X - C a).prod := by
simpa using eq_prod_roots_of_splits hsplit
theorem Splits.dvd_of_roots_le_roots {p q : K[X]} (hp : p.Splits (RingHom.id _)) (hp0 : p ≠ 0)
(hq : p.roots ≤ q.roots) : p ∣ q := by
rw [eq_prod_roots_of_splits_id hp, C_mul_dvd (leadingCoeff_ne_zero.2 hp0)]
exact dvd_trans
(Multiset.prod_dvd_prod_of_le (Multiset.map_le_map hq))
(prod_multiset_X_sub_C_dvd _)
theorem Splits.dvd_iff_roots_le_roots {p q : K[X]}
(hp : p.Splits (RingHom.id _)) (hp0 : p ≠ 0) (hq0 : q ≠ 0) :
p ∣ q ↔ p.roots ≤ q.roots :=
⟨Polynomial.roots.le_of_dvd hq0, hp.dvd_of_roots_le_roots hp0⟩
theorem aeval_eq_prod_aroots_sub_of_splits [Algebra K L] {p : K[X]}
(hsplit : Splits (algebraMap K L) p) (v : L) :
aeval v p = algebraMap K L p.leadingCoeff * ((p.aroots L).map fun a ↦ v - a).prod := by
rw [← eval_map_algebraMap, eq_prod_roots_of_splits hsplit]
simp [eval_multiset_prod]
theorem eval_eq_prod_roots_sub_of_splits_id {p : K[X]}
(hsplit : Splits (RingHom.id K) p) (v : K) :
eval v p = p.leadingCoeff * (p.roots.map fun a ↦ v - a).prod := by
convert aeval_eq_prod_aroots_sub_of_splits hsplit v
rw [Algebra.algebraMap_self, map_id]
theorem eq_prod_roots_of_monic_of_splits_id {p : K[X]} (m : Monic p)
(hsplit : Splits (RingHom.id K) p) : p = (p.roots.map fun a => X - C a).prod := by
convert eq_prod_roots_of_splits_id hsplit
simp [m]
theorem aeval_eq_prod_aroots_sub_of_monic_of_splits [Algebra K L] {p : K[X]} (m : Monic p)
(hsplit : Splits (algebraMap K L) p) (v : L) :
aeval v p = ((p.aroots L).map fun a ↦ v - a).prod := by
simp [aeval_eq_prod_aroots_sub_of_splits hsplit, m]
theorem eval_eq_prod_roots_sub_of_monic_of_splits_id {p : K[X]} (m : Monic p)
(hsplit : Splits (RingHom.id K) p) (v : K) :
eval v p = (p.roots.map fun a ↦ v - a).prod := by
simp [eval_eq_prod_roots_sub_of_splits_id hsplit, m]
theorem eq_X_sub_C_of_splits_of_single_root {x : K} {h : K[X]} (h_splits : Splits i h)
(h_roots : (h.map i).roots = {i x}) : h = C h.leadingCoeff * (X - C x) := by
apply Polynomial.map_injective _ i.injective
rw [eq_prod_roots_of_splits h_splits, h_roots]
simp
variable (R) in
theorem mem_lift_of_splits_of_roots_mem_range [Algebra R K] {f : K[X]}
(hs : f.Splits (RingHom.id K)) (hm : f.Monic) (hr : ∀ a ∈ f.roots, a ∈ (algebraMap R K).range) :
f ∈ Polynomial.lifts (algebraMap R K) := by
rw [eq_prod_roots_of_monic_of_splits_id hm hs, lifts_iff_liftsRing]
refine Subring.multiset_prod_mem _ _ fun P hP => ?_
obtain ⟨b, hb, rfl⟩ := Multiset.mem_map.1 hP
exact Subring.sub_mem _ (X_mem_lifts _) (C'_mem_lifts (hr _ hb))
/--
A polynomial of degree `2` with a root splits.
-/
theorem splits_of_natDegree_eq_two {f : Polynomial K} {x : L} (h₁ : f.natDegree = 2)
(h₂ : eval₂ i x f = 0) : Splits i f := by
have hf₀ : f ≠ 0 := ne_zero_of_natDegree_gt (h₁ ▸ zero_lt_two)
have h : (map i f /ₘ (X - C x)).natDegree = 1 := by
rw [natDegree_divByMonic _ (monic_X_sub_C x), natDegree_map, h₁, natDegree_X_sub_C]
replace h₂ := (mem_roots'.mp <| (mem_roots_map_of_injective i.injective hf₀).mpr h₂).2
rw [← splits_id_iff_splits, ← mul_divByMonic_eq_iff_isRoot.mpr h₂]
exact (splits_mul_iff _ (X_sub_C_ne_zero x) (by simp [ne_zero_of_natDegree_gt, h])).mpr
⟨splits_X_sub_C _, splits_of_natDegree_le_one (RingHom.id L) (by rw [h])⟩
theorem splits_of_degree_eq_two {f : Polynomial K} {x : L} (h₁ : f.degree = 2)
(h₂ : eval₂ i x f = 0) : Splits i f :=
splits_of_natDegree_eq_two i (natDegree_eq_of_degree_eq_some h₁) h₂
section UFD
attribute [local instance] PrincipalIdealRing.to_uniqueFactorizationMonoid
local infixl:50 " ~ᵤ " => Associated
open UniqueFactorizationMonoid Associates
theorem splits_of_exists_multiset {f : K[X]} {s : Multiset L}
(hs : f.map i = C (i f.leadingCoeff) * (s.map fun a : L => X - C a).prod) : Splits i f :=
factors_iff_exists_multiset.mpr ⟨s, leadingCoeff_map i ▸ hs⟩
theorem splits_of_splits_id {f : K[X]} (h : Splits (RingHom.id K) f) : Splits i f := by
simpa using h.map i
end UFD
theorem splits_iff_exists_multiset {f : K[X]} :
Splits i f ↔
∃ s : Multiset L, f.map i = C (i f.leadingCoeff) * (s.map fun a : L => X - C a).prod :=
⟨fun hf => ⟨(f.map i).roots, eq_prod_roots_of_splits hf⟩, fun ⟨_, hs⟩ =>
splits_of_exists_multiset i hs⟩
theorem splits_of_comp (j : L →+* F) {f : K[X]} (h : Splits (j.comp i) f)
(roots_mem_range : ∀ a ∈ (f.map (j.comp i)).roots, a ∈ j.range) : Splits i f := by
choose lift lift_eq using roots_mem_range
rw [splits_iff_exists_multiset]
refine ⟨(f.map (j.comp i)).roots.pmap lift fun _ ↦ id, map_injective _ j.injective ?_⟩
conv_lhs => rw [Polynomial.map_map, eq_prod_roots_of_splits h]
simp_rw [Polynomial.map_mul, Polynomial.map_multiset_prod, Multiset.map_pmap, Polynomial.map_sub,
map_C, map_X, lift_eq, Multiset.pmap_eq_map]
rfl
theorem splits_id_of_splits {f : K[X]} (h : Splits i f)
(roots_mem_range : ∀ a ∈ (f.map i).roots, a ∈ i.range) : Splits (RingHom.id K) f :=
splits_of_comp (RingHom.id K) i h roots_mem_range
theorem splits_comp_of_splits (i : R →+* K) (j : K →+* L) {f : R[X]} (h : Splits i f) :
Splits (j.comp i) f :=
(splits_map_iff i j).mp (splits_of_splits_id _ <| (splits_map_iff i <| .id K).mpr h)
variable [Algebra R K] [Algebra R L]
theorem splits_of_algHom {f : R[X]} (h : Splits (algebraMap R K) f) (e : K →ₐ[R] L) :
Splits (algebraMap R L) f := by
rw [← e.comp_algebraMap_of_tower R]; exact splits_comp_of_splits _ _ h
variable (L) in
theorem splits_of_isScalarTower {f : R[X]} [Algebra K L] [IsScalarTower R K L]
(h : Splits (algebraMap R K) f) : Splits (algebraMap R L) f :=
splits_of_algHom h (IsScalarTower.toAlgHom R K L)
/-- A polynomial splits if and only if it has as many roots as its degree. -/
theorem splits_iff_card_roots {p : K[X]} :
Splits (RingHom.id K) p ↔ Multiset.card p.roots = p.natDegree := by
constructor
· intro H
rw [natDegree_eq_card_roots H, map_id]
· intro hroots
rw [splits_iff_exists_multiset (RingHom.id K)]
use p.roots
simp only [RingHom.id_apply, map_id]
exact (C_leadingCoeff_mul_prod_multiset_X_sub_C hroots).symm
theorem eval₂_derivative_of_splits [DecidableEq L] {P : K[X]} {f : K →+* L} (hP : P.Splits f)
(x : L) :
eval₂ f x P.derivative = f (P.leadingCoeff) *
((P.map f).roots.map fun a ↦ (((P.map f).roots.erase a).map (x - ·)).prod).sum := by
conv_lhs => rw [← eval_map, ← derivative_map, eq_prod_roots_of_splits hP]
classical
simp [derivative_prod, eval_multisetSum, eval_multiset_prod]
theorem aeval_derivative_of_splits [Algebra K L] [DecidableEq L] {P : K[X]}
(hP : P.Splits (algebraMap K L)) (r : L) :
aeval r P.derivative = algebraMap K L P.leadingCoeff *
((P.aroots L).map fun a ↦ (((P.aroots L).erase a).map (r - ·)).prod).sum :=
eval₂_derivative_of_splits hP r
theorem eval_derivative_of_splits [DecidableEq K] {P : K[X]} (hP : P.Splits (.id K)) (r : K) :
eval r P.derivative = P.leadingCoeff *
(P.roots.map fun a ↦ ((P.roots.erase a).map (r - ·)).prod).sum := by
simpa using eval₂_derivative_of_splits hP r
/-- Let `P` be a monic polynomial over `K` that splits over `L`. Let `r : L` be a root of `P`.
Then $P'(r) = \prod_{a}(r-a)$, where the product in the RHS is taken over all roots of `P` in `L`,
with the multiplicity of `r` reduced by one. -/
theorem aeval_root_derivative_of_splits [Algebra K L] [DecidableEq L] {P : K[X]} (hmo : P.Monic)
(hP : P.Splits (algebraMap K L)) {r : L} (hr : r ∈ P.aroots L) :
aeval r (Polynomial.derivative P) = (((P.aroots L).erase r).map fun a => r - a).prod := by
replace hmo := hmo.map (algebraMap K L)
replace hP := (splits_id_iff_splits (algebraMap K L)).2 hP
rw [aeval_def, ← eval_map, ← derivative_map]
nth_rw 1 [eq_prod_roots_of_monic_of_splits_id hmo hP]
rw [eval_multiset_prod_X_sub_C_derivative hr]
theorem eval_derivative_eq_eval_mul_sum_of_splits {p : K[X]} {x : K}
(h : p.Splits (.id K)) (hx : p.eval x ≠ 0) :
p.derivative.eval x = p.eval x * (p.roots.map fun z ↦ 1 / (x - z)).sum := by
classical
suffices p.roots.map (fun z ↦ p.leadingCoeff * ((p.roots.erase z).map (fun w ↦ x - w) ).prod) =
p.roots.map fun i ↦ p.leadingCoeff * ((x - i)⁻¹ * (p.roots.map (fun z ↦ x - z)).prod) by
nth_rw 2 [p.eq_prod_roots_of_splits_id h]
simp [eval_derivative_of_splits h, ← Multiset.sum_map_mul_left, this, eval_multiset_prod,
mul_comm, mul_left_comm]
refine Multiset.map_congr rfl fun z hz ↦ ?_
rw [← Multiset.prod_map_erase hz, inv_mul_cancel_left₀]
aesop (add simp sub_eq_zero)
theorem eval_derivative_div_eval_of_ne_zero_of_splits {p : K[X]} {x : K}
(h : p.Splits (.id K)) (hx : p.eval x ≠ 0) :
p.derivative.eval x / p.eval x = (p.roots.map fun z ↦ 1 / (x - z)).sum := by
rw [eval_derivative_eq_eval_mul_sum_of_splits h hx]
exact mul_div_cancel_left₀ _ hx
theorem coeff_zero_eq_leadingCoeff_mul_prod_roots_of_splits {P : K[X]} (hP : P.Splits <| .id K) :
P.coeff 0 = (-1) ^ P.natDegree * P.leadingCoeff * P.roots.prod := by
nth_rw 1 [eq_prod_roots_of_splits_id hP]
simp only [coeff_zero_eq_eval_zero, eval_mul, eval_C, eval_multiset_prod, Function.comp_apply,
Multiset.map_map, eval_sub, eval_X, zero_sub, Multiset.prod_map_neg]
grind [splits_iff_card_roots]
/-- If `P` is a monic polynomial that splits, then `coeff P 0` equals the product of the roots. -/
theorem coeff_zero_eq_prod_roots_of_monic_of_splits {P : K[X]} (hmo : P.Monic)
(hP : P.Splits (RingHom.id K)) : coeff P 0 = (-1) ^ P.natDegree * P.roots.prod := by
simp [hmo, coeff_zero_eq_leadingCoeff_mul_prod_roots_of_splits hP]
theorem nextCoeff_eq_neg_sum_roots_mul_leadingCoeff_of_splits {P : K[X]} (hP : P.Splits <| .id K) :
P.nextCoeff = -P.leadingCoeff * P.roots.sum := by
nth_rw 1 [eq_prod_roots_of_splits_id hP]
simp [Multiset.sum_map_neg', monic_X_sub_C, Monic.nextCoeff_multiset_prod]
/-- If `P` is a monic polynomial that splits, then `P.nextCoeff` equals the negative of the sum
of the roots. -/
theorem nextCoeff_eq_neg_sum_roots_of_monic_of_splits {P : K[X]} (hmo : P.Monic)
(hP : P.Splits (RingHom.id K)) : P.nextCoeff = -P.roots.sum := by
simp [hmo, nextCoeff_eq_neg_sum_roots_mul_leadingCoeff_of_splits hP]
@[deprecated (since := "2025-10-08")]
alias prod_roots_eq_coeff_zero_of_monic_of_splits := coeff_zero_eq_prod_roots_of_monic_of_splits
@[deprecated (since := "2025-10-08")]
alias sum_roots_eq_nextCoeff_of_monic_of_split := nextCoeff_eq_neg_sum_roots_of_monic_of_splits
end Splits
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/OfFn.lean | import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Data.List.ToFinsupp
import Mathlib.LinearAlgebra.Pi
/-!
# `Polynomial.ofFn` and `Polynomial.toFn`
In this file we introduce `ofFn` and `toFn`, two functions that associate a polynomial to the vector
of its coefficients and vice versa. We prove some basic APIs for these functions.
## Main definitions
- `Polynomial.toFn n` associates to a polynomial the vector of its first `n` coefficients.
- `Polynomial.ofFn n` associates to a vector of length `n` the polynomial that has the entries of
the vector as coefficients.
-/
namespace Polynomial
section toFn
variable {R : Type*} [Semiring R]
/-- `toFn n f` is the vector of the first `n` coefficients of the polynomial `f`. -/
def toFn (n : ℕ) : R[X] →ₗ[R] Fin n → R := LinearMap.pi (fun i ↦ lcoeff R i)
theorem toFn_zero (n : ℕ) : toFn n (0 : R[X]) = 0 := by simp
end toFn
section ofFn
variable {R : Type*} [Semiring R] [DecidableEq R]
/-- `ofFn n v` is the polynomial whose coefficients are the entries of the vector `v`. -/
def ofFn (n : ℕ) : (Fin n → R) →ₗ[R] R[X] where
toFun v := ⟨(List.ofFn v).toFinsupp⟩
map_add' x y := by
ext i
by_cases h : i < n
· simp [h]
· simp [h]
map_smul' x p := by
ext i
by_cases h : i < n
· simp [h]
· simp [h]
theorem ofFn_zero (n : ℕ) : ofFn n (0 : Fin n → R) = 0 := by simp
@[simp]
theorem ofFn_zero' (v : Fin 0 → R) : ofFn 0 v = 0 := rfl
lemma ne_zero_of_ofFn_ne_zero {n : ℕ} {v : Fin n → R} (h : ofFn n v ≠ 0) : n ≠ 0 := by
contrapose! h
subst h
simp
/-- If `i < n` the `i`-th coefficient of `ofFn n v` is `v i`. -/
@[simp]
theorem ofFn_coeff_eq_val_of_lt {n i : ℕ} (v : Fin n → R) (hi : i < n) :
(ofFn n v).coeff i = v ⟨i, hi⟩ := by
simp [ofFn, hi]
/-- If `n ≤ i` the `i`-th coefficient of `ofFn n v` is `0`. -/
@[simp]
theorem ofFn_coeff_eq_zero_of_ge {n i : ℕ} (v : Fin n → R) (hi : n ≤ i) : (ofFn n v).coeff i = 0 :=
by simp [ofFn, Nat.not_lt_of_ge hi]
/-- `ofFn n v` has `natDegree` smaller than `n`. -/
theorem ofFn_natDegree_lt {n : ℕ} (h : 1 ≤ n) (v : Fin n → R) : (ofFn n v).natDegree < n := by
rw [Nat.lt_iff_le_pred h, natDegree_le_iff_coeff_eq_zero]
exact fun _ h ↦ ofFn_coeff_eq_zero_of_ge _ <| Nat.le_of_pred_lt h
/-- `ofFn n v` has `degree` smaller than `n`. -/
theorem ofFn_degree_lt {n : ℕ} (v : Fin n → R) : (ofFn n v).degree < n := by
by_cases h : ofFn n v = 0
· simp only [h, degree_zero]
exact Batteries.compareOfLessAndEq_eq_lt.mp rfl
· exact (natDegree_lt_iff_degree_lt h).mp
<| ofFn_natDegree_lt (Nat.one_le_iff_ne_zero.mpr <| ne_zero_of_ofFn_ne_zero h) _
theorem ofFn_eq_sum_monomial {n : ℕ} (v : Fin n → R) : ofFn n v =
∑ i : Fin n, monomial i (v i) := by
by_cases h : n = 0
· subst h
simp [ofFn]
· rw [as_sum_range' (ofFn n v) n <| ofFn_natDegree_lt (Nat.one_le_iff_ne_zero.mpr h) v]
simp [Finset.sum_range]
theorem toFn_comp_ofFn_eq_id (n : ℕ) (v : Fin n → R) : toFn n (ofFn n v) = v := by
simp [toFn, ofFn, LinearMap.pi]
theorem injective_ofFn (n : ℕ) : Function.Injective (ofFn (R := R) n) :=
Function.LeftInverse.injective <| toFn_comp_ofFn_eq_id n
omit [DecidableEq R] in
theorem surjective_toFn (n : ℕ) : Function.Surjective (toFn (R := R) n) :=
open Classical in
Function.RightInverse.surjective <| toFn_comp_ofFn_eq_id n
theorem ofFn_comp_toFn_eq_id_of_natDegree_lt {n : ℕ} {p : R[X]} (h_deg : p.natDegree < n) :
ofFn n (toFn n p) = p := by
ext i
by_cases! h : i < n
· simp [h, toFn]
· have : p.coeff i = 0 := coeff_eq_zero_of_natDegree_lt <| by cutsat
simp [*]
end ofFn
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Coeff.lean | import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Algebra.Regular.Basic
import Mathlib.Data.Nat.Choose.Sum
/-!
# Theory of univariate polynomials
The theorems include formulas for computing coefficients, such as
`coeff_add`, `coeff_sum`, `coeff_mul`
-/
noncomputable section
open Finsupp Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
variable [Semiring R] {p q r : R[X]}
section Coeff
@[simp]
theorem coeff_add (p q : R[X]) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := by
rcases p with ⟨⟩
rcases q with ⟨⟩
simp_rw [← ofFinsupp_add, coeff]
exact Finsupp.add_apply _ _ _
@[simp]
theorem coeff_smul [SMulZeroClass S R] (r : S) (p : R[X]) (n : ℕ) :
coeff (r • p) n = r • coeff p n := by
rfl
theorem support_smul [SMulZeroClass S R] (r : S) (p : R[X]) :
support (r • p) ⊆ support p := by
intro i hi
rw [mem_support_iff] at hi ⊢
contrapose! hi
simp [hi]
open scoped Pointwise in
theorem card_support_mul_le : #(p * q).support ≤ #p.support * #q.support := by
calc #(p * q).support
_ = #(p.toFinsupp * q.toFinsupp).support := by rw [← support_toFinsupp, toFinsupp_mul]
_ ≤ #(p.toFinsupp.support + q.toFinsupp.support) :=
Finset.card_le_card (AddMonoidAlgebra.support_mul p.toFinsupp q.toFinsupp)
_ ≤ #p.support * #q.support := Finset.card_image₂_le ..
/-- `Polynomial.sum` as a linear map. -/
@[simps]
def lsum {R A M : Type*} [Semiring R] [Semiring A] [AddCommMonoid M] [Module R A] [Module R M]
(f : ℕ → A →ₗ[R] M) : A[X] →ₗ[R] M where
toFun p := p.sum (f · ·)
map_add' p q := sum_add_index p q _ (fun n => (f n).map_zero) fun n _ _ => (f n).map_add _ _
map_smul' c p := by
rw [sum_eq_of_subset (f · ·) (fun n => (f n).map_zero) (support_smul c p)]
simp only [sum_def, Finset.smul_sum, coeff_smul, LinearMap.map_smul, RingHom.id_apply]
variable (R) in
/-- The nth coefficient, as a linear map. -/
def lcoeff (n : ℕ) : R[X] →ₗ[R] R where
toFun p := coeff p n
map_add' p q := coeff_add p q n
map_smul' r p := coeff_smul r p n
@[simp]
theorem lcoeff_apply (n : ℕ) (f : R[X]) : lcoeff R n f = coeff f n :=
rfl
@[simp]
theorem finset_sum_coeff {ι : Type*} (s : Finset ι) (f : ι → R[X]) (n : ℕ) :
coeff (∑ b ∈ s, f b) n = ∑ b ∈ s, coeff (f b) n :=
map_sum (lcoeff R n) _ _
lemma coeff_list_sum (l : List R[X]) (n : ℕ) :
l.sum.coeff n = (l.map (lcoeff R n)).sum :=
map_list_sum (lcoeff R n) _
lemma coeff_list_sum_map {ι : Type*} (l : List ι) (f : ι → R[X]) (n : ℕ) :
(l.map f).sum.coeff n = (l.map (fun a => (f a).coeff n)).sum := by
simp_rw [coeff_list_sum, List.map_map, Function.comp_def, lcoeff_apply]
@[simp]
theorem coeff_sum [Semiring S] (n : ℕ) (f : ℕ → R → S[X]) :
coeff (p.sum f) n = p.sum fun a b => coeff (f a b) n := by
simp [Polynomial.sum]
/-- Decomposes the coefficient of the product `p * q` as a sum
over `antidiagonal`. A version which sums over `range (n + 1)` can be obtained
by using `Finset.Nat.sum_antidiagonal_eq_sum_range_succ`. -/
theorem coeff_mul (p q : R[X]) (n : ℕ) :
coeff (p * q) n = ∑ x ∈ antidiagonal n, coeff p x.1 * coeff q x.2 := by
rcases p with ⟨p⟩; rcases q with ⟨q⟩
simp_rw [← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.mul_apply_antidiagonal p q n _ Finset.mem_antidiagonal
@[simp]
theorem mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 := by simp [coeff_mul]
theorem mul_coeff_one (p q : R[X]) :
coeff (p * q) 1 = coeff p 0 * coeff q 1 + coeff p 1 * coeff q 0 := by
rw [coeff_mul, Nat.antidiagonal_eq_map]
simp [sum_range_succ]
/-- `constantCoeff p` returns the constant term of the polynomial `p`,
defined as `coeff p 0`. This is a ring homomorphism. -/
@[simps]
def constantCoeff : R[X] →+* R where
toFun p := coeff p 0
map_one' := coeff_one_zero
map_mul' := mul_coeff_zero
map_zero' := coeff_zero 0
map_add' p q := coeff_add p q 0
lemma constantCoeff_surjective : Function.Surjective (constantCoeff (R := R)) :=
fun x ↦ ⟨C x, by simp⟩
theorem isUnit_C {x : R} : IsUnit (C x) ↔ IsUnit x :=
⟨fun h => (congr_arg IsUnit coeff_C_zero).mp (h.map <| @constantCoeff R _), fun h => h.map C⟩
theorem coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp
theorem coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp
theorem coeff_C_mul_X_pow (x : R) (k n : ℕ) :
coeff (C x * X ^ k : R[X]) n = if n = k then x else 0 := by
rw [C_mul_X_pow_eq_monomial, coeff_monomial]
simp [eq_comm]
theorem coeff_C_mul_X (x : R) (n : ℕ) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 := by
rw [← pow_one X, coeff_C_mul_X_pow]
@[simp]
theorem coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n := by
rcases p with ⟨p⟩
simp_rw [← monomial_zero_left, ← ofFinsupp_single, ← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.single_zero_mul_apply p a n
theorem C_mul' (a : R) (f : R[X]) : C a * f = a • f := by
ext
rw [coeff_C_mul, coeff_smul, smul_eq_mul]
@[simp]
theorem coeff_mul_C (p : R[X]) (n : ℕ) (a : R) : coeff (p * C a) n = coeff p n * a := by
rcases p with ⟨p⟩
simp_rw [← monomial_zero_left, ← ofFinsupp_single, ← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.mul_single_zero_apply p a n
@[simp] lemma coeff_mul_natCast {a k : ℕ} :
coeff (p * (a : R[X])) k = coeff p k * (↑a : R) := coeff_mul_C _ _ _
@[simp] lemma coeff_natCast_mul {a k : ℕ} :
coeff ((a : R[X]) * p) k = a * coeff p k := coeff_C_mul _
@[simp] lemma coeff_mul_ofNat {a k : ℕ} [Nat.AtLeastTwo a] :
coeff (p * (ofNat(a) : R[X])) k = coeff p k * ofNat(a) := coeff_mul_C _ _ _
@[simp] lemma coeff_ofNat_mul {a k : ℕ} [Nat.AtLeastTwo a] :
coeff ((ofNat(a) : R[X]) * p) k = ofNat(a) * coeff p k := coeff_C_mul _
@[simp] lemma coeff_mul_intCast [Ring S] {p : S[X]} {a : ℤ} {k : ℕ} :
coeff (p * (a : S[X])) k = coeff p k * (↑a : S) := coeff_mul_C _ _ _
@[simp] lemma coeff_intCast_mul [Ring S] {p : S[X]} {a : ℤ} {k : ℕ} :
coeff ((a : S[X]) * p) k = a * coeff p k := coeff_C_mul _
@[simp]
theorem coeff_X_pow (k n : ℕ) : coeff (X ^ k : R[X]) n = if n = k then 1 else 0 := by
simp only [one_mul, RingHom.map_one, ← coeff_C_mul_X_pow]
theorem coeff_X_pow_self (n : ℕ) : coeff (X ^ n : R[X]) n = 1 := by simp
section Fewnomials
open Finset
theorem support_binomial {k m : ℕ} (hkm : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) :
support (C x * X ^ k + C y * X ^ m) = {k, m} := by
apply subset_antisymm (support_binomial' k m x y)
simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm, mul_zero, zero_add,
add_zero, Ne, hx, hy, not_false_eq_true, and_true]
theorem support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0)
(hy : y ≠ 0) (hz : z ≠ 0) :
support (C x * X ^ k + C y * X ^ m + C z * X ^ n) = {k, m, n} := by
apply subset_antisymm (support_trinomial' k m n x y z)
simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne,
if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne', mul_zero, add_zero,
zero_add, Ne, hx, hy, hz, not_false_eq_true, and_true]
theorem card_support_binomial {k m : ℕ} (h : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) :
#(support (C x * X ^ k + C y * X ^ m)) = 2 := by
rw [support_binomial h hx hy, card_insert_of_notMem (mt mem_singleton.mp h), card_singleton]
theorem card_support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0)
(hy : y ≠ 0) (hz : z ≠ 0) : #(support (C x * X ^ k + C y * X ^ m + C z * X ^ n)) = 3 := by
rw [support_trinomial hkm hmn hx hy hz,
card_insert_of_notMem
(mt mem_insert.mp (not_or_intro hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))),
card_insert_of_notMem (mt mem_singleton.mp hmn.ne), card_singleton]
end Fewnomials
@[simp]
theorem coeff_mul_X_pow (p : R[X]) (n d : ℕ) :
coeff (p * Polynomial.X ^ n) (d + n) = coeff p d := by
rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]
all_goals grind [mem_antidiagonal, coeff_X_pow, mul_zero]
@[simp]
theorem coeff_X_pow_mul (p : R[X]) (n d : ℕ) :
coeff (Polynomial.X ^ n * p) (d + n) = coeff p d := by
rw [(commute_X_pow p n).eq, coeff_mul_X_pow]
theorem coeff_mul_X_pow' (p : R[X]) (n d : ℕ) :
(p * X ^ n).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 := by
split_ifs with h
· rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right]
· refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_)
rw [coeff_X_pow, if_neg, mul_zero]
exact ((le_of_add_le_right (mem_antidiagonal.mp hx).le).trans_lt <| not_le.mp h).ne
theorem coeff_X_pow_mul' (p : R[X]) (n d : ℕ) :
(X ^ n * p).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 := by
rw [(commute_X_pow p n).eq, coeff_mul_X_pow']
@[simp]
theorem coeff_mul_X (p : R[X]) (n : ℕ) : coeff (p * X) (n + 1) = coeff p n := by
simpa only [pow_one] using coeff_mul_X_pow p 1 n
@[simp]
theorem coeff_X_mul (p : R[X]) (n : ℕ) : coeff (X * p) (n + 1) = coeff p n := by
rw [(commute_X p).eq, coeff_mul_X]
theorem coeff_mul_monomial (p : R[X]) (n d : ℕ) (r : R) :
coeff (p * monomial n r) (d + n) = coeff p d * r := by
rw [← C_mul_X_pow_eq_monomial, ← X_pow_mul, ← mul_assoc, coeff_mul_C, coeff_mul_X_pow]
theorem coeff_monomial_mul (p : R[X]) (n d : ℕ) (r : R) :
coeff (monomial n r * p) (d + n) = r * coeff p d := by
rw [← C_mul_X_pow_eq_monomial, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow]
-- This can already be proved by `simp`.
theorem coeff_mul_monomial_zero (p : R[X]) (d : ℕ) (r : R) :
coeff (p * monomial 0 r) d = coeff p d * r :=
coeff_mul_monomial p 0 d r
-- This can already be proved by `simp`.
theorem coeff_monomial_zero_mul (p : R[X]) (d : ℕ) (r : R) :
coeff (monomial 0 r * p) d = r * coeff p d :=
coeff_monomial_mul p 0 d r
theorem mul_X_pow_eq_zero {p : R[X]} {n : ℕ} (H : p * X ^ n = 0) : p = 0 :=
ext fun k => (coeff_mul_X_pow p n k).symm.trans <| ext_iff.1 H (k + n)
theorem isRegular_X_pow (n : ℕ) : IsRegular (X ^ n : R[X]) := by
suffices IsLeftRegular (X^n : R[X]) from
⟨this, this.right_of_commute (fun p => commute_X_pow p n)⟩
intro P Q (hPQ : X^n * P = X^n * Q)
ext i
rw [← coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i]
@[simp] theorem isRegular_X : IsRegular (X : R[X]) := pow_one (X : R[X]) ▸ isRegular_X_pow 1
theorem coeff_X_add_C_pow (r : R) (n k : ℕ) :
((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) := by
rw [(commute_X (C r : R[X])).add_pow, ← lcoeff_apply, map_sum]
simp only [lcoeff_apply, ← C_eq_natCast, ← C_pow, coeff_mul_C]
rw [Finset.sum_eq_single k, coeff_X_pow_self, one_mul]
· intro _ _ h
simp [coeff_X_pow, h.symm]
· simp only [coeff_X_pow_self, one_mul, not_lt, Finset.mem_range]
intro h
rw [Nat.choose_eq_zero_of_lt h, Nat.cast_zero, mul_zero]
theorem coeff_X_add_one_pow (R : Type*) [Semiring R] (n k : ℕ) :
((X + 1) ^ n).coeff k = (n.choose k : R) := by rw [← C_1, coeff_X_add_C_pow, one_pow, one_mul]
theorem coeff_one_add_X_pow (R : Type*) [Semiring R] (n k : ℕ) :
((1 + X) ^ n).coeff k = (n.choose k : R) := by rw [add_comm _ X, coeff_X_add_one_pow]
theorem C_dvd_iff_dvd_coeff (r : R) (φ : R[X]) : C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i := by
constructor
· rintro ⟨φ, rfl⟩ c
rw [coeff_C_mul]
apply dvd_mul_right
· intro h
choose c hc using h
classical
let c' : ℕ → R := fun i => if i ∈ φ.support then c i else 0
let ψ : R[X] := ∑ i ∈ φ.support, monomial i (c' i)
use ψ
ext i
simp only [c', ψ, coeff_C_mul, mem_support_iff, coeff_monomial, finset_sum_coeff,
Finset.sum_ite_eq']
split_ifs with hi
· rw [hc]
· rw [Classical.not_not] at hi
rwa [mul_zero]
theorem smul_eq_C_mul (a : R) : a • p = C a * p := by simp [ext_iff]
theorem update_eq_add_sub_coeff {R : Type*} [Ring R] (p : R[X]) (n : ℕ) (a : R) :
p.update n a = p + Polynomial.C (a - p.coeff n) * Polynomial.X ^ n := by
ext
rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow]
split_ifs with h <;> simp [h]
end Coeff
section cast
theorem natCast_coeff_zero {n : ℕ} {R : Type*} [Semiring R] : (n : R[X]).coeff 0 = n := by
simp only [coeff_natCast_ite, ite_true]
@[norm_cast]
theorem natCast_inj {m n : ℕ} {R : Type*} [Semiring R] [CharZero R] :
(↑m : R[X]) = ↑n ↔ m = n := by
constructor
· intro h
apply_fun fun p => p.coeff 0 at h
simpa using h
· rintro rfl
rfl
@[simp]
theorem intCast_coeff_zero {i : ℤ} {R : Type*} [Ring R] : (i : R[X]).coeff 0 = i := by
cases i <;> simp
@[norm_cast]
theorem intCast_inj {m n : ℤ} {R : Type*} [Ring R] [CharZero R] : (↑m : R[X]) = ↑n ↔ m = n := by
constructor
· intro h
apply_fun fun p => p.coeff 0 at h
simpa using h
· rintro rfl
rfl
end cast
instance charZero [CharZero R] : CharZero R[X] where cast_injective _x _y := natCast_inj.mp
instance charP {p : ℕ} [CharP R p] : CharP R[X] p where
cast_eq_zero_iff n := by
rw [← CharP.cast_eq_zero_iff R, ← C_inj (R := R), map_natCast, C_0]
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Basis.lean | import Mathlib.Algebra.Polynomial.Basic
import Mathlib.LinearAlgebra.Basis.Defs
/-!
# Basis of a polynomial ring
-/
open Module
universe u
variable (R : Type u) [Semiring R]
namespace Polynomial
/-- The monomials form a basis on `R[X]`. To get the rank of a polynomial ring,
use this and `Basis.mk_eq_rank`. -/
def basisMonomials : Basis ℕ R R[X] :=
Basis.ofRepr (toFinsuppIsoLinear R)
@[simp]
theorem coe_basisMonomials : (basisMonomials R : ℕ → R[X]) = fun s => monomial s 1 :=
funext fun _ => ofFinsupp_single _ _
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Identities.lean | import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Tactic.LinearCombination
import Mathlib.Tactic.Ring
/-!
# Theory of univariate polynomials
The main def is `Polynomial.binomExpansion`.
-/
noncomputable section
namespace Polynomial
universe u v w x y z
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type x} {k : Type y} {A : Type z} {a b : R}
{m n : ℕ}
section Identities
/- @TODO: `powAddExpansion` and `powSubPowFactor` are not specific to polynomials.
These belong somewhere else. But not in group_power because they depend on tactic.ring_exp
Maybe use `Data.Nat.Choose` to prove it.
-/
/-- `(x + y)^n` can be expressed as `x^n + n*x^(n-1)*y + k * y^2` for some `k` in the ring.
-/
def powAddExpansion {R : Type*} [CommSemiring R] (x y : R) :
∀ n : ℕ, { k // (x + y) ^ n = x ^ n + n * x ^ (n - 1) * y + k * y ^ 2 }
| 0 => ⟨0, by simp⟩
| 1 => ⟨0, by simp⟩
| n + 2 => by
obtain ⟨z, hz⟩ := (powAddExpansion x y (n + 1))
exists x * z + (n + 1) * x ^ n + z * y
calc
(x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) := by ring
_ = (x + y) * (x ^ (n + 1) + ↑(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) := by rw [hz]
_ = x ^ (n + 2) + ↑(n + 2) * x ^ (n + 1) * y + (x * z + (n + 1) * x ^ n + z * y) * y ^ 2 := by
push_cast
ring!
variable [CommRing R]
private def polyBinomAux1 (x y : R) (e : ℕ) (a : R) :
{ k : R // a * (x + y) ^ e = a * (x ^ e + e * x ^ (e - 1) * y + k * y ^ 2) } := by
exists (powAddExpansion x y e).val
congr
apply (powAddExpansion _ _ _).property
private theorem poly_binom_aux2 (f : R[X]) (x y : R) :
f.eval (x + y) =
f.sum fun e a => a * (x ^ e + e * x ^ (e - 1) * y + (polyBinomAux1 x y e a).val * y ^ 2) := by
unfold eval; rw [eval₂_eq_sum]; congr with (n z)
apply (polyBinomAux1 x y _ _).property
private theorem poly_binom_aux3 (f : R[X]) (x y : R) :
f.eval (x + y) =
((f.sum fun e a => a * x ^ e) + f.sum fun e a => a * e * x ^ (e - 1) * y) +
f.sum fun e a => a * (polyBinomAux1 x y e a).val * y ^ 2 := by
rw [poly_binom_aux2]
simp [left_distrib, sum_add, mul_assoc]
/-- A polynomial `f` evaluated at `x + y` can be expressed as
the evaluation of `f` at `x`, plus `y` times the (polynomial) derivative of `f` at `x`,
plus some element `k : R` times `y^2`.
-/
def binomExpansion (f : R[X]) (x y : R) :
{ k : R // f.eval (x + y) = f.eval x + f.derivative.eval x * y + k * y ^ 2 } := by
exists f.sum fun e a => a * (polyBinomAux1 x y e a).val
rw [poly_binom_aux3]
congr
· rw [← eval_eq_sum]
· rw [derivative_eval]
exact (Finset.sum_mul ..).symm
· exact (Finset.sum_mul ..).symm
/-- `x^n - y^n` can be expressed as `z * (x - y)` for some `z` in the ring.
-/
def powSubPowFactor (x y : R) : ∀ i : ℕ, { z : R // x ^ i - y ^ i = z * (x - y) }
| 0 => ⟨0, by simp⟩
| 1 => ⟨1, by simp⟩
| k + 2 => by
obtain ⟨z, hz⟩ := @powSubPowFactor x y (k + 1)
exists z * x + y ^ (k + 1)
linear_combination (norm := ring) x * hz
/-- For any polynomial `f`, `f.eval x - f.eval y` can be expressed as `z * (x - y)`
for some `z` in the ring.
-/
def evalSubFactor (f : R[X]) (x y : R) : { z : R // f.eval x - f.eval y = z * (x - y) } := by
refine ⟨f.sum fun i r => r * (powSubPowFactor x y i).val, ?_⟩
delta eval; rw [eval₂_eq_sum, eval₂_eq_sum]
simp only [sum, ← Finset.sum_sub_distrib, Finset.sum_mul]
dsimp
congr with i
rw [mul_assoc, ← (powSubPowFactor x y _).prop, mul_sub]
end Identities
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Cardinal.lean | import Mathlib.Algebra.Polynomial.Basic
import Mathlib.SetTheory.Cardinal.Finsupp
/-!
# Cardinality of Polynomial Ring
The result in this file is that the cardinality of `R[X]` is at most the maximum
of `#R` and `ℵ₀`.
-/
universe u
open Cardinal Polynomial
open Cardinal
namespace Polynomial
@[simp]
theorem cardinalMk_eq_max {R : Type u} [Semiring R] [Nontrivial R] : #(R[X]) = max #R ℵ₀ :=
(toFinsuppIso R).toEquiv.cardinal_eq.trans <| by
rw [AddMonoidAlgebra, mk_finsupp_lift_of_infinite, lift_uzero, max_comm]
rfl
theorem cardinalMk_le_max {R : Type u} [Semiring R] : #(R[X]) ≤ max #R ℵ₀ := by
cases subsingleton_or_nontrivial R
· exact (mk_eq_one _).trans_le (le_max_of_le_right one_le_aleph0)
· exact cardinalMk_eq_max.le
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Inductions.lean | import Mathlib.Algebra.MonoidAlgebra.Division
import Mathlib.Algebra.Polynomial.Degree.Operations
import Mathlib.Algebra.Polynomial.EraseLead
import Mathlib.Order.Interval.Finset.Nat
/-!
# Induction on polynomials
This file contains lemmas dealing with different flavours of induction on polynomials.
-/
noncomputable section
open Polynomial
open Finset
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]}
/-- `divX p` returns a polynomial `q` such that `q * X + C (p.coeff 0) = p`.
It can be used in a semiring where the usual division algorithm is not possible -/
def divX (p : R[X]) : R[X] :=
⟨AddMonoidAlgebra.divOf p.toFinsupp 1⟩
@[simp]
theorem coeff_divX : (divX p).coeff n = p.coeff (n + 1) := by
rw [add_comm]; cases p; rfl
theorem divX_mul_X_add (p : R[X]) : divX p * X + C (p.coeff 0) = p :=
ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C, coeff_mul_X]
@[simp]
theorem X_mul_divX_add (p : R[X]) : X * divX p + C (p.coeff 0) = p :=
ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C]
@[simp]
theorem divX_C (a : R) : divX (C a) = 0 :=
ext fun n => by simp [coeff_divX]
theorem divX_eq_zero_iff : divX p = 0 ↔ p = C (p.coeff 0) :=
⟨fun h => by simpa [eq_comm, h] using divX_mul_X_add p, fun h => by rw [h, divX_C]⟩
theorem divX_add : divX (p + q) = divX p + divX q :=
ext <| by simp
@[simp]
theorem divX_zero : divX (0 : R[X]) = 0 := leadingCoeff_eq_zero.mp rfl
@[simp]
theorem divX_one : divX (1 : R[X]) = 0 := by
ext
simpa only [coeff_divX, coeff_zero] using coeff_one
@[simp]
theorem divX_C_mul : divX (C a * p) = C a * divX p := by
ext
simp
theorem divX_X_pow : divX (X ^ n : R[X]) = if (n = 0) then 0 else X ^ (n - 1) := by
cases n
· simp
· ext n
simp [coeff_X_pow]
/-- `divX` as an additive homomorphism. -/
noncomputable
def divX_hom : R[X] →+ R[X] :=
{ toFun := divX
map_zero' := divX_zero
map_add' := fun _ _ => divX_add }
@[simp] theorem divX_hom_toFun : divX_hom p = divX p := rfl
theorem natDegree_divX_eq_natDegree_tsub_one : p.divX.natDegree = p.natDegree - 1 := by
apply map_natDegree_eq_sub (φ := divX_hom)
· intro f
simpa [divX_hom, divX_eq_zero_iff] using eq_C_of_natDegree_eq_zero
· intro n c c0
rw [← C_mul_X_pow_eq_monomial, divX_hom_toFun, divX_C_mul, divX_X_pow]
split_ifs with n0
· simp [n0]
· exact natDegree_C_mul_X_pow (n - 1) c c0
theorem natDegree_divX_le : p.divX.natDegree ≤ p.natDegree :=
natDegree_divX_eq_natDegree_tsub_one.trans_le (Nat.pred_le _)
theorem divX_C_mul_X_pow : divX (C a * X ^ n) = if n = 0 then 0 else C a * X ^ (n - 1) := by
simp only [divX_C_mul, divX_X_pow, mul_ite, mul_zero]
theorem degree_divX_lt (hp0 : p ≠ 0) : (divX p).degree < p.degree := by
haveI := Nontrivial.of_polynomial_ne hp0
calc
degree (divX p) < (divX p * X + C (p.coeff 0)).degree :=
if h : degree p ≤ 0 then by
have h' : C (p.coeff 0) ≠ 0 := by rwa [← eq_C_of_degree_le_zero h]
rw [eq_C_of_degree_le_zero h, divX_C, degree_zero, zero_mul, zero_add]
exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 <| by simpa using h'))
else by
have hXp0 : divX p ≠ 0 := by
simpa [divX_eq_zero_iff, -not_le, degree_le_zero_iff] using h
have : leadingCoeff (divX p) * leadingCoeff X ≠ 0 := by simpa
have : degree (C (p.coeff 0)) < degree (divX p * X) :=
calc
degree (C (p.coeff 0)) ≤ 0 := degree_C_le
_ < 1 := by decide
_ = degree (X : R[X]) := degree_X.symm
_ ≤ degree (divX p * X) := by
rw [← zero_add (degree X), degree_mul' this]
exact add_le_add
(by rw [zero_le_degree_iff, Ne, divX_eq_zero_iff]
exact fun h0 => h (h0.symm ▸ degree_C_le))
le_rfl
rw [degree_add_eq_left_of_degree_lt this]; exact degree_lt_degree_mul_X hXp0
_ = degree p := congr_arg _ (divX_mul_X_add _)
/-- An induction principle for polynomials, valued in Sort* instead of Prop. -/
@[elab_as_elim]
noncomputable def recOnHorner {M : R[X] → Sort*} (p : R[X]) (M0 : M 0)
(MC : ∀ p a, coeff p 0 = 0 → a ≠ 0 → M p → M (p + C a))
(MX : ∀ p, p ≠ 0 → M p → M (p * X)) : M p :=
letI := Classical.decEq R
if hp : p = 0 then hp ▸ M0
else by
have wf : degree (divX p) < degree p := degree_divX_lt hp
rw [← divX_mul_X_add p] at *
exact
if hcp0 : coeff p 0 = 0 then by
rw [hcp0, C_0, add_zero]
exact
MX _ (fun h : divX p = 0 => by simp [h, hcp0] at hp) (recOnHorner (divX p) M0 MC MX)
else
MC _ _ (coeff_mul_X_zero _) hcp0
(if hpX0 : divX p = 0 then show M (divX p * X) by rw [hpX0, zero_mul]; exact M0
else MX (divX p) hpX0 (recOnHorner _ M0 MC MX))
termination_by p.degree
/-- A property holds for all polynomials of positive `degree` with coefficients in a semiring `R`
if it holds for
* `a * X`, with `a ∈ R`,
* `p * X`, with `p ∈ R[X]`,
* `p + a`, with `a ∈ R`, `p ∈ R[X]`,
with appropriate restrictions on each term.
See `natDegree_ne_zero_induction_on` for a similar statement involving no explicit multiplication.
-/
@[elab_as_elim]
theorem degree_pos_induction_on {P : R[X] → Prop} (p : R[X]) (h0 : 0 < degree p)
(hC : ∀ {a}, a ≠ 0 → P (C a * X)) (hX : ∀ {p}, 0 < degree p → P p → P (p * X))
(hadd : ∀ {p} {a}, 0 < degree p → P p → P (p + C a)) : P p :=
recOnHorner p (fun h => by rw [degree_zero] at h; exact absurd h (by decide))
(fun p a heq0 _ ih h0 =>
(have : 0 < degree p :=
(lt_of_not_ge fun h =>
not_lt_of_ge (degree_C_le (a := a)) <|
by rwa [eq_C_of_degree_le_zero h, ← C_add,heq0,zero_add] at h0)
hadd this (ih this)))
(fun p _ ih h0' =>
if h0 : 0 < degree p then hX h0 (ih h0)
else by
rw [eq_C_of_degree_le_zero (le_of_not_gt h0)] at h0' ⊢
exact hC fun h : coeff p 0 = 0 => by simp [h] at h0')
h0
/-- A property holds for all polynomials of non-zero `natDegree` with coefficients in a
semiring `R` if it holds for
* `p + a`, with `a ∈ R`, `p ∈ R[X]`,
* `p + q`, with `p, q ∈ R[X]`,
* monomials with nonzero coefficient and non-zero exponent,
with appropriate restrictions on each term.
Note that multiplication is "hidden" in the assumption on monomials, so there is no explicit
multiplication in the statement.
See `degree_pos_induction_on` for a similar statement involving more explicit multiplications.
-/
@[elab_as_elim]
theorem natDegree_ne_zero_induction_on {M : R[X] → Prop} {f : R[X]} (f0 : f.natDegree ≠ 0)
(h_C_add : ∀ {a p}, M p → M (C a + p)) (h_add : ∀ {p q}, M p → M q → M (p + q))
(h_monomial : ∀ {n : ℕ} {a : R}, a ≠ 0 → n ≠ 0 → M (monomial n a)) : M f := by
suffices f.natDegree = 0 ∨ M f from Or.recOn this (fun h => (f0 h).elim) id
refine Polynomial.induction_on f ?_ ?_ ?_
· exact fun a => Or.inl (natDegree_C _)
· rintro p q (hp | hp) (hq | hq)
· refine Or.inl ?_
rw [eq_C_of_natDegree_eq_zero hp, eq_C_of_natDegree_eq_zero hq, ← C_add, natDegree_C]
· refine Or.inr ?_
rw [eq_C_of_natDegree_eq_zero hp]
exact h_C_add hq
· refine Or.inr ?_
rw [eq_C_of_natDegree_eq_zero hq, add_comm]
exact h_C_add hp
· exact Or.inr (h_add hp hq)
· intro n a _
by_cases a0 : a = 0
· exact Or.inl (by rw [a0, C_0, zero_mul, natDegree_zero])
· refine Or.inr ?_
rw [C_mul_X_pow_eq_monomial]
exact h_monomial a0 n.succ_ne_zero
end Semiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/FieldDivision.lean | import Mathlib.Algebra.Order.Group.Finset
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Theory of univariate polynomials
This file starts looking like the ring theory of $R[X]$
-/
noncomputable section
open Polynomial
open scoped Nat
namespace Polynomial
universe u v w y z
variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R]
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero
(p : R[X]) (t : R) (hnezero : derivative p ≠ 0) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t :=
(le_rootMultiplicity_iff hnezero).2 <|
pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t)
theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors
{p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t)
(hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) :
(derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· simp only [h, map_zero, rootMultiplicity_zero]
obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t
set m := p.rootMultiplicity t
have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt
have hndvd : ¬(X - C t) ^ m ∣ derivative p := by
rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _),
derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc,
dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)]
rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢
rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd]
have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _)
exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm])
(rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero)
theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ}
(hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t :=
dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans
(pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t)
open Finset in
theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} :
(derivative^[p.rootMultiplicity t] p).eval t =
(p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by
set m := p.rootMultiplicity t with hm
conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm]
rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)]
· rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self,
eval_natCast, nsmul_eq_mul]; rfl
· intro b hb hb0
rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow,
Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self,
zero_pow hb0, smul_zero, zero_mul, smul_zero]
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
by_contra! h'
replace hroot := hroot _ h'
simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot
obtain ⟨q, hq⟩ : ((rootMultiplicity t p)! : R) ∣ n ! := by gcongr
rw [hq, mul_mem_nonZeroDivisors] at hnzd
rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot
exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot
clear hroot
induction n with
| zero =>
simp only [Nat.factorial_zero, Nat.cast_one]
exact Submonoid.one_mem _
| succ n ih =>
rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors]
exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩
theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t :=
lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h
(by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _)
theorem one_lt_rootMultiplicity_iff_isRoot
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by
rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h]
refine ⟨fun h ↦ ⟨h 0 (by simp), h 1 (by simp)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩
obtain (_ | _ | m) := m
exacts [h0, h1, by cutsat]
end CommRing
section IsDomain
variable [CommRing R] [IsDomain R]
theorem one_lt_rootMultiplicity_iff_isRoot_gcd
[GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by
simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff]
theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) :
p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· rw [h, map_zero, rootMultiplicity_zero]
exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne'
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := by
by_cases h : p.IsRoot t
· exact (derivative_rootMultiplicity_of_root h).symm.le
· rw [rootMultiplicity_eq_zero h, zero_tsub]
exact zero_le _
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) :
n < p.rootMultiplicity t :=
lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 <| by positivity
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative h hr⟩
/-- A sufficient condition for the set of roots of a nonzero polynomial `f` to be a subset of the
set of roots of `g` is that `f` divides `f.derivative * g`. Over an algebraically closed field of
characteristic zero, this is also a necessary condition.
See `isRoot_of_isRoot_iff_dvd_derivative_mul` -/
theorem isRoot_of_isRoot_of_dvd_derivative_mul [CharZero R] {f g : R[X]} (hf0 : f ≠ 0)
(hfd : f ∣ f.derivative * g) {a : R} (haf : f.IsRoot a) : g.IsRoot a := by
rcases hfd with ⟨r, hr⟩
have hdf0 : derivative f ≠ 0 := by
contrapose! haf
rw [eq_C_of_derivative_eq_zero haf] at hf0 ⊢
exact not_isRoot_C _ _ <| C_ne_zero.mp hf0
by_contra hg
have hdfg0 : f.derivative * g ≠ 0 := mul_ne_zero hdf0 (by rintro rfl; simp at hg)
have hr' := congr_arg (rootMultiplicity a) hr
rw [rootMultiplicity_mul hdfg0, derivative_rootMultiplicity_of_root haf,
rootMultiplicity_eq_zero hg, add_zero, rootMultiplicity_mul (hr ▸ hdfg0), add_comm,
Nat.sub_eq_iff_eq_add (Nat.succ_le_iff.2 ((rootMultiplicity_pos hf0).2 haf))] at hr'
cutsat
section NormalizationMonoid
variable [NormalizationMonoid R]
instance instNormalizationMonoid : NormalizationMonoid R[X] where
normUnit p :=
⟨C ↑(normUnit p.leadingCoeff), C ↑(normUnit p.leadingCoeff)⁻¹, by
rw [← RingHom.map_mul, Units.mul_inv, C_1], by rw [← RingHom.map_mul, Units.inv_mul, C_1]⟩
normUnit_zero := Units.ext (by simp)
normUnit_mul hp0 hq0 :=
Units.ext
(by
dsimp
rw [Ne, ← leadingCoeff_eq_zero] at *
rw [leadingCoeff_mul, normUnit_mul hp0 hq0, Units.val_mul, C_mul])
normUnit_coe_units u :=
Units.ext
(by
dsimp
rw [← mul_one u⁻¹, Units.val_mul, Units.eq_inv_mul_iff_mul_eq]
rcases Polynomial.isUnit_iff.1 ⟨u, rfl⟩ with ⟨_, ⟨w, rfl⟩, h2⟩
rw [← h2, leadingCoeff_C, normUnit_coe_units, ← C_mul, Units.mul_inv, C_1]
rfl)
@[simp]
theorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C ↑(normUnit p.leadingCoeff) := by
simp [normUnit]
@[simp]
theorem leadingCoeff_normalize (p : R[X]) :
leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp [normalize_apply]
theorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by
simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one,
Units.val_one, Polynomial.C.map_one, mul_one]
theorem roots_normalize {p : R[X]} : (normalize p).roots = p.roots := by
rw [normalize_apply, mul_comm, coe_normUnit, roots_C_mul _ (normUnit (leadingCoeff p)).ne_zero]
theorem normUnit_X : normUnit (X : Polynomial R) = 1 := by
have := coe_normUnit (R := R) (p := X)
rwa [leadingCoeff_X, normUnit_one, Units.val_one, map_one, Units.val_eq_one] at this
theorem X_eq_normalize : (X : Polynomial R) = normalize X := by
simp only [normalize_apply, normUnit_X, Units.val_one, mul_one]
end NormalizationMonoid
end IsDomain
section DivisionRing
variable [DivisionRing R] {p q : R[X]}
theorem degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬IsUnit p) : 0 < degree p :=
lt_of_not_ge fun h => by
rw [eq_C_of_degree_le_zero h] at hp0 hp
exact hp (IsUnit.map C (IsUnit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))))
end DivisionRing
section SimpleRing
variable [Ring R] [IsSimpleRing R] [Semiring S] [Nontrivial S] {p q : R[X]}
@[simp]
protected theorem map_eq_zero (f : R →+* S) : p.map f = 0 ↔ p = 0 :=
Polynomial.map_eq_zero_iff f.injective
theorem map_ne_zero {f : R →+* S} (hp : p ≠ 0) : p.map f ≠ 0 :=
mt (Polynomial.map_eq_zero f).1 hp
@[simp]
theorem degree_map (p : R[X]) (f : R →+* S) : (p.map f).degree = p.degree :=
degree_map_eq_of_injective f.injective _
@[simp]
theorem natDegree_map (f : R →+* S) : (p.map f).natDegree = p.natDegree :=
natDegree_map_eq_of_injective f.injective _
@[simp]
theorem leadingCoeff_map (f : R →+* S) : (p.map f).leadingCoeff = f p.leadingCoeff :=
leadingCoeff_map_of_injective f.injective _
theorem nextCoeff_map_eq (p : R[X]) (f : R →+* S) : (p.map f).nextCoeff = f p.nextCoeff :=
nextCoeff_map f.injective _
@[simp] theorem monic_map_iff {f : R →+* S} {p : R[X]} : (p.map f).Monic ↔ p.Monic :=
Function.Injective.monic_map_iff f.injective |>.symm
end SimpleRing
section Field
variable [Field R] {p q : R[X]}
theorem isUnit_iff_degree_eq_zero : IsUnit p ↔ degree p = 0 :=
⟨degree_eq_zero_of_isUnit, fun h =>
have : degree p ≤ 0 := by simp [*, le_refl]
have hc : coeff p 0 ≠ 0 := fun hc => by
rw [eq_C_of_degree_le_zero this, hc] at h; simp only [map_zero] at h; contradiction
isUnit_iff_dvd_one.2
⟨C (coeff p 0)⁻¹, by
conv in p => rw [eq_C_of_degree_le_zero this]
rw [← C_mul, mul_inv_cancel₀ hc, C_1]⟩⟩
/-- Division of polynomials. See `Polynomial.divByMonic` for more details. -/
def div (p q : R[X]) :=
C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹))
/-- Remainder of polynomial division. See `Polynomial.modByMonic` for more details. -/
def mod (p q : R[X]) :=
p %ₘ (q * C (leadingCoeff q)⁻¹)
private theorem quotient_mul_add_remainder_eq_aux (p q : R[X]) : q * div p q + mod p q = p := by
by_cases h : q = 0
· simp only [h, zero_mul, mod, modByMonic_zero, zero_add]
· conv =>
rhs
rw [← modByMonic_add_div p (monic_mul_leadingCoeff_inv h)]
rw [div, mod, add_comm, mul_assoc]
private theorem remainder_lt_aux (p : R[X]) (hq : q ≠ 0) : degree (mod p q) < degree q := by
rw [← degree_mul_leadingCoeff_inv q hq]
exact degree_modByMonic_lt p (monic_mul_leadingCoeff_inv hq)
instance : Div R[X] :=
⟨div⟩
instance : Mod R[X] :=
⟨mod⟩
theorem div_def : p / q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) :=
rfl
theorem mod_def : p % q = p %ₘ (q * C (leadingCoeff q)⁻¹) := rfl
theorem modByMonic_eq_mod (p : R[X]) (hq : Monic q) : p %ₘ q = p % q :=
show p %ₘ q = p %ₘ (q * C (leadingCoeff q)⁻¹) by
simp only [Monic.def.1 hq, inv_one, mul_one, C_1]
theorem divByMonic_eq_div (p : R[X]) (hq : Monic q) : p /ₘ q = p / q :=
show p /ₘ q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) by
simp only [Monic.def.1 hq, inv_one, C_1, one_mul, mul_one]
theorem mod_X_sub_C_eq_C_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) :=
modByMonic_eq_mod p (monic_X_sub_C a) ▸ modByMonic_X_sub_C_eq_C_eval _ _
theorem mul_div_eq_iff_isRoot : (X - C a) * (p / (X - C a)) = p ↔ IsRoot p a :=
divByMonic_eq_div p (monic_X_sub_C a) ▸ mul_divByMonic_eq_iff_isRoot
alias ⟨_, IsRoot.mul_div_eq⟩ := mul_div_eq_iff_isRoot
instance instEuclideanDomain : EuclideanDomain R[X] :=
{ Polynomial.commRing,
Polynomial.nontrivial with
quotient := (· / ·)
quotient_zero := by simp [div_def]
remainder := (· % ·)
r := _
r_wellFounded := degree_lt_wf
quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux
remainder_lt := fun _ _ hq => remainder_lt_aux _ hq
mul_left_not_lt := fun _ _ hq => not_lt_of_ge (degree_le_mul_left _ hq) }
theorem mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q :=
⟨fun h => h ▸ EuclideanDomain.mod_lt _ hq0, fun h => by
classical
have : ¬degree (q * C (leadingCoeff q)⁻¹) ≤ degree p :=
not_le_of_gt <| by rwa [degree_mul_leadingCoeff_inv q hq0]
rw [mod_def, modByMonic, dif_pos (monic_mul_leadingCoeff_inv hq0)]
unfold divModByMonicAux
dsimp
simp only [this, false_and, if_false]⟩
protected theorem div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q :=
⟨fun h => by
have := EuclideanDomain.div_add_mod p q
rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this,
fun h => by
have hlt : degree p < degree (q * C (leadingCoeff q)⁻¹) := by
rwa [degree_mul_leadingCoeff_inv q hq0]
have hm : Monic (q * C (leadingCoeff q)⁻¹) := monic_mul_leadingCoeff_inv hq0
rw [div_def, (divByMonic_eq_zero_iff hm).2 hlt, mul_zero]⟩
theorem degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) :
degree q + degree (p / q) = degree p := by
have : degree (p % q) < degree (q * (p / q)) :=
calc
degree (p % q) < degree q := EuclideanDomain.mod_lt _ hq0
_ ≤ _ := degree_le_mul_left _ (mt (Polynomial.div_eq_zero_iff hq0).1 (not_lt_of_ge hpq))
conv_rhs =>
rw [← EuclideanDomain.div_add_mod p q, degree_add_eq_left_of_degree_lt this, degree_mul]
theorem degree_div_le (p q : R[X]) : degree (p / q) ≤ degree p := by
by_cases hq : q = 0
· simp [hq]
· rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq]; exact degree_divByMonic_le _ _
theorem degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p := by
have hq0 : q ≠ 0 := fun hq0 => by simp [hq0] at hq
rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq0]
exact degree_divByMonic_lt _ (monic_mul_leadingCoeff_inv hq0) hp
(by rw [degree_mul_leadingCoeff_inv _ hq0]; exact hq)
theorem isUnit_map [Field k] (f : R →+* k) : IsUnit (p.map f) ↔ IsUnit p := by
simp_rw [isUnit_iff_degree_eq_zero, degree_map]
theorem map_div [Field k] (f : R →+* k) : (p / q).map f = p.map f / q.map f := by
if hq0 : q = 0 then simp [hq0]
else
rw [div_def, div_def, Polynomial.map_mul, map_divByMonic f (monic_mul_leadingCoeff_inv hq0),
Polynomial.map_mul, map_C, leadingCoeff_map, map_inv₀]
theorem map_mod [Field k] (f : R →+* k) : (p % q).map f = p.map f % q.map f := by
by_cases hq0 : q = 0
· simp [hq0]
· rw [mod_def, mod_def, leadingCoeff_map f, ← map_inv₀ f, ← map_C f, ← Polynomial.map_mul f,
map_modByMonic f (monic_mul_leadingCoeff_inv hq0)]
lemma natDegree_mod_lt [Field k] (p : k[X]) {q : k[X]} (hq : q.natDegree ≠ 0) :
(p % q).natDegree < q.natDegree := by
have hq' : q.leadingCoeff ≠ 0 := by
rw [leadingCoeff_ne_zero]
contrapose! hq
simp [hq]
rw [mod_def]
refine (natDegree_modByMonic_lt p ?_ ?_).trans_le ?_
· refine monic_mul_C_of_leadingCoeff_mul_eq_one ?_
rw [mul_inv_eq_one₀ hq']
· contrapose! hq
rw [← natDegree_mul_C_eq_of_mul_eq_one ((inv_mul_eq_one₀ hq').mpr rfl)]
simp [hq]
· exact natDegree_mul_C_le q q.leadingCoeff⁻¹
section
open EuclideanDomain
theorem gcd_map [Field k] [DecidableEq R] [DecidableEq k] (f : R →+* k) :
gcd (p.map f) (q.map f) = (gcd p q).map f :=
GCD.induction p q (fun x => by simp_rw [Polynomial.map_zero, EuclideanDomain.gcd_zero_left])
fun x y _ ih => by rw [gcd_val, ← map_mod, ih, ← gcd_val]
end
theorem eval₂_gcd_eq_zero [CommSemiring k] [DecidableEq R]
{ϕ : R →+* k} {f g : R[X]} {α : k} (hf : f.eval₂ ϕ α = 0)
(hg : g.eval₂ ϕ α = 0) : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 := by
rw [EuclideanDomain.gcd_eq_gcd_ab f g, Polynomial.eval₂_add, Polynomial.eval₂_mul,
Polynomial.eval₂_mul, hf, hg, zero_mul, zero_mul, zero_add]
theorem eval_gcd_eq_zero [DecidableEq R] {f g : R[X]} {α : R}
(hf : f.eval α = 0) (hg : g.eval α = 0) : (EuclideanDomain.gcd f g).eval α = 0 :=
eval₂_gcd_eq_zero hf hg
theorem root_left_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 := by
obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_left f g
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
theorem root_right_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 := by
obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_right f g
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
theorem root_gcd_iff_root_left_right [CommSemiring k] [DecidableEq R]
{ϕ : R →+* k} {f g : R[X]} {α : k} :
(EuclideanDomain.gcd f g).eval₂ ϕ α = 0 ↔ f.eval₂ ϕ α = 0 ∧ g.eval₂ ϕ α = 0 :=
⟨fun h => ⟨root_left_of_root_gcd h, root_right_of_root_gcd h⟩, fun h => eval₂_gcd_eq_zero h.1 h.2⟩
theorem isRoot_gcd_iff_isRoot_left_right [DecidableEq R] {f g : R[X]} {α : R} :
(EuclideanDomain.gcd f g).IsRoot α ↔ f.IsRoot α ∧ g.IsRoot α :=
root_gcd_iff_root_left_right
theorem isCoprime_map [Field k] (f : R →+* k) : IsCoprime (p.map f) (q.map f) ↔ IsCoprime p q := by
classical
rw [← EuclideanDomain.gcd_isUnit_iff, ← EuclideanDomain.gcd_isUnit_iff, gcd_map, isUnit_map]
theorem mem_roots_map [CommRing k] [IsDomain k] {f : R →+* k} {x : k} (hp : p ≠ 0) :
x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots (map_ne_zero hp), IsRoot, Polynomial.eval_map]
theorem rootSet_monomial [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R}
(ha : a ≠ 0) : (monomial n a).rootSet S = {0} := by
classical
rw [rootSet, aroots_monomial ha,
Multiset.toFinset_nsmul _ _ hn, Multiset.toFinset_singleton, Finset.coe_singleton]
theorem rootSet_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R}
(ha : a ≠ 0) : rootSet (C a * X ^ n) S = {0} := by
rw [C_mul_X_pow_eq_monomial, rootSet_monomial hn ha]
theorem rootSet_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) :
(X ^ n : R[X]).rootSet S = {0} := by
rw [← one_mul (X ^ n : R[X]), ← C_1, rootSet_C_mul_X_pow hn]
exact one_ne_zero
theorem rootSet_prod [CommRing S] [IsDomain S] [Algebra R S] {ι : Type*} (f : ι → R[X])
(s : Finset ι) (h : s.prod f ≠ 0) : (s.prod f).rootSet S = ⋃ i ∈ s, (f i).rootSet S := by
classical
simp only [rootSet, aroots, ← Finset.mem_coe]
rw [Polynomial.map_prod, roots_prod, Finset.bind_toFinset, s.val_toFinset, Finset.coe_biUnion]
rwa [← Polynomial.map_prod, Ne, Polynomial.map_eq_zero]
theorem roots_C_mul_X_sub_C (b : R) (ha : a ≠ 0) : (C a * X - C b).roots = {a⁻¹ * b} := by
simp [roots_C_mul_X_sub_C_of_IsUnit b ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩]
theorem roots_C_mul_X_add_C (b : R) (ha : a ≠ 0) : (C a * X + C b).roots = {-(a⁻¹ * b)} := by
simp [roots_C_mul_X_add_C_of_IsUnit b ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩]
theorem roots_degree_eq_one (h : degree p = 1) : p.roots = {-((p.coeff 1)⁻¹ * p.coeff 0)} := by
rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1 by rw [h])]
have : p.coeff 1 ≠ 0 := coeff_ne_zero_of_eq_degree h
simp [roots_C_mul_X_add_C _ this]
theorem exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, IsRoot p x :=
⟨-((p.coeff 1)⁻¹ * p.coeff 0), by
rw [← mem_roots (by simp [← zero_le_degree_iff, h])]
simp [roots_degree_eq_one h]⟩
theorem coeff_inv_units (u : R[X]ˣ) (n : ℕ) : ((↑u : R[X]).coeff n)⁻¹ = (↑u⁻¹ : R[X]).coeff n := by
rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹),
coeff_C, coeff_C, inv_eq_one_div]
split_ifs
· rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero,
coeff_zero_eq_eval_zero, ← eval_mul, ← Units.val_mul, inv_mul_cancel]
simp
· simp
theorem monic_normalize [DecidableEq R] (hp0 : p ≠ 0) : Monic (normalize p) := by
rw [Ne, ← leadingCoeff_eq_zero, ← Ne, ← isUnit_iff_ne_zero] at hp0
rw [Monic, leadingCoeff_normalize, normalize_eq_one]
apply hp0
theorem normalize_eq_self_iff_monic [DecidableEq R] {p : Polynomial R} (hp : p ≠ 0) :
normalize p = p ↔ p.Monic :=
⟨fun h ↦ h ▸ monic_normalize hp, fun h ↦ Monic.normalize_eq_self h⟩
theorem leadingCoeff_div (hpq : q.degree ≤ p.degree) :
(p / q).leadingCoeff = p.leadingCoeff / q.leadingCoeff := by
by_cases hq : q = 0
· simp [hq]
rw [div_def, leadingCoeff_mul, leadingCoeff_C,
leadingCoeff_divByMonic_of_monic (monic_mul_leadingCoeff_inv hq) _, mul_comm,
div_eq_mul_inv]
rwa [degree_mul_leadingCoeff_inv q hq]
theorem div_C_mul : p / (C a * q) = C a⁻¹ * (p / q) := by
by_cases ha : a = 0
· simp [ha]
simp only [div_def, leadingCoeff_mul, mul_inv, leadingCoeff_C, C.map_mul, mul_assoc]
congr 3
rw [mul_left_comm q, ← mul_assoc, ← C.map_mul, mul_inv_cancel₀ ha, C.map_one, one_mul]
lemma div_C : p / C a = p * C a⁻¹ := by
simpa [mul_comm] using div_C_mul (q := 1)
lemma C_div : C (a / b) = C a / C b := by
rw [div_C, ← C_mul, div_eq_mul_inv]
theorem C_mul_dvd (ha : a ≠ 0) : C a * p ∣ q ↔ p ∣ q :=
⟨fun h => dvd_trans (dvd_mul_left _ _) h, fun ⟨r, hr⟩ =>
⟨C a⁻¹ * r, by
rw [mul_assoc, mul_left_comm p, ← mul_assoc, ← C.map_mul, mul_inv_cancel₀ ha, C.map_one,
one_mul, hr]⟩⟩
theorem dvd_C_mul (ha : a ≠ 0) : p ∣ Polynomial.C a * q ↔ p ∣ q :=
⟨fun ⟨r, hr⟩ =>
⟨C a⁻¹ * r, by
rw [mul_left_comm p, ← hr, ← mul_assoc, ← C.map_mul, inv_mul_cancel₀ ha, C.map_one,
one_mul]⟩,
fun h => dvd_trans h (dvd_mul_left _ _)⟩
theorem coe_normUnit_of_ne_zero [DecidableEq R] (hp : p ≠ 0) :
(normUnit p : R[X]) = C p.leadingCoeff⁻¹ := by
have : p.leadingCoeff ≠ 0 := mt leadingCoeff_eq_zero.mp hp
simp [CommGroupWithZero.coe_normUnit _ this]
theorem map_dvd_map' [Field k] (f : R →+* k) {x y : R[X]} : x.map f ∣ y.map f ↔ x ∣ y := by
by_cases H : x = 0
· rw [H, Polynomial.map_zero, zero_dvd_iff, zero_dvd_iff, Polynomial.map_eq_zero]
· classical
rw [← normalize_dvd_iff, ← @normalize_dvd_iff R[X], normalize_apply, normalize_apply,
coe_normUnit_of_ne_zero H, coe_normUnit_of_ne_zero (mt (Polynomial.map_eq_zero f).1 H),
leadingCoeff_map, ← map_inv₀ f, ← map_C, ← Polynomial.map_mul,
map_dvd_map _ f.injective (monic_mul_leadingCoeff_inv H)]
@[simp]
theorem degree_normalize [DecidableEq R] : degree (normalize p) = degree p := by
simp [normalize_apply]
theorem prime_of_degree_eq_one (hp1 : degree p = 1) : Prime p := by
classical
have : Prime (normalize p) :=
Monic.prime_of_degree_eq_one (hp1 ▸ degree_normalize)
(monic_normalize fun hp0 => absurd hp1 (hp0.symm ▸ by simp [degree_zero]))
exact (normalize_associated _).prime this
theorem irreducible_of_degree_eq_one (hp1 : degree p = 1) : Irreducible p :=
(prime_of_degree_eq_one hp1).irreducible
theorem not_irreducible_C (x : R) : ¬Irreducible (C x) := by
by_cases H : x = 0
· rw [H, C_0]
exact not_irreducible_zero
· exact fun hx => hx.not_isUnit <| isUnit_C.2 <| isUnit_iff_ne_zero.2 H
theorem degree_pos_of_irreducible (hp : Irreducible p) : 0 < p.degree :=
lt_of_not_ge fun hp0 =>
have := eq_C_of_degree_le_zero hp0
not_irreducible_C (p.coeff 0) <| this ▸ hp
theorem X_sub_C_mul_divByMonic_eq_sub_modByMonic {K : Type*} [Ring K] (f : K[X]) (a : K) :
(X - C a) * (f /ₘ (X - C a)) = f - f %ₘ (X - C a) := by
rw [eq_sub_iff_add_eq, ← eq_sub_iff_add_eq', modByMonic_eq_sub_mul_div]
exact monic_X_sub_C a
theorem divByMonic_add_X_sub_C_mul_derivative_divByMonic_eq_derivative
{K : Type*} [CommRing K] (f : K[X]) (a : K) :
f /ₘ (X - C a) + (X - C a) * derivative (f /ₘ (X - C a)) = derivative f := by
have key := by apply congrArg derivative <| X_sub_C_mul_divByMonic_eq_sub_modByMonic f a
simpa only [derivative_mul, derivative_sub, derivative_X, derivative_C, sub_zero, one_mul,
modByMonic_X_sub_C_eq_C_eval] using key
@[deprecated (since := "2025-07-08")]
alias divByMonic_add_X_sub_C_mul_derivate_divByMonic_eq_derivative :=
divByMonic_add_X_sub_C_mul_derivative_divByMonic_eq_derivative
theorem X_sub_C_dvd_derivative_of_X_sub_C_dvd_divByMonic {K : Type*} [Field K] (f : K[X]) {a : K}
(hf : (X - C a) ∣ f /ₘ (X - C a)) : X - C a ∣ derivative f := by
have key := divByMonic_add_X_sub_C_mul_derivative_divByMonic_eq_derivative f a
have ⟨u,hu⟩ := hf
rw [← key, hu, ← mul_add (X - C a) u _]
use (u + derivative ((X - C a) * u))
/-- If `f` is a polynomial over a field, and `a : K` satisfies `f' a ≠ 0`,
then `f / (X - a)` is coprime with `X - a`.
Note that we do not assume `f a = 0`, because `f / (X - a) = (f - f a) / (X - a)`. -/
theorem isCoprime_of_is_root_of_eval_derivative_ne_zero {K : Type*} [Field K] (f : K[X]) (a : K)
(hf' : f.derivative.eval a ≠ 0) : IsCoprime (X - C a : K[X]) (f /ₘ (X - C a)) := by
classical
refine Or.resolve_left
(EuclideanDomain.dvd_or_coprime (X - C a) (f /ₘ (X - C a))
(irreducible_of_degree_eq_one (Polynomial.degree_X_sub_C a))) ?_
contrapose! hf' with h
have : X - C a ∣ derivative f := X_sub_C_dvd_derivative_of_X_sub_C_dvd_divByMonic f h
rw [← modByMonic_eq_zero_iff_dvd (monic_X_sub_C _), modByMonic_X_sub_C_eq_C_eval] at this
rwa [← C_inj, C_0]
/-- To check a polynomial over a field is irreducible, it suffices to check only for
divisors that have smaller degree.
See also: `Polynomial.Monic.irreducible_iff_natDegree`.
-/
theorem irreducible_iff_degree_lt (p : R[X]) (hp0 : p ≠ 0) (hpu : ¬ IsUnit p) :
Irreducible p ↔ ∀ q, q.degree ≤ ↑(natDegree p / 2) → q ∣ p → IsUnit q := by
rw [← irreducible_mul_leadingCoeff_inv,
(monic_mul_leadingCoeff_inv hp0).irreducible_iff_degree_lt]
· simp [hp0, natDegree_mul_leadingCoeff_inv]
· contrapose! hpu
exact .of_mul_eq_one _ hpu
/-- To check a polynomial `p` over a field is irreducible, it suffices to check there are no
divisors of degree `0 < d ≤ degree p / 2`.
See also: `Polynomial.Monic.irreducible_iff_natDegree'`.
-/
theorem irreducible_iff_lt_natDegree_lt {p : R[X]} (hp0 : p ≠ 0) (hpu : ¬ IsUnit p) :
Irreducible p ↔ ∀ q, Monic q → natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) → ¬ q ∣ p := by
have : p * C (leadingCoeff p)⁻¹ ≠ 1 := by
contrapose! hpu
exact .of_mul_eq_one _ hpu
rw [← irreducible_mul_leadingCoeff_inv,
(monic_mul_leadingCoeff_inv hp0).irreducible_iff_lt_natDegree_lt this,
natDegree_mul_leadingCoeff_inv _ hp0]
simp only [IsUnit.dvd_mul_right
(isUnit_C.mpr (IsUnit.mk0 (leadingCoeff p)⁻¹ (inv_ne_zero (leadingCoeff_ne_zero.mpr hp0))))]
open UniqueFactorizationMonoid in
/--
The normalized factors of a polynomial over a field times its leading coefficient give
the polynomial.
-/
theorem leadingCoeff_mul_prod_normalizedFactors [DecidableEq R] (a : R[X]) :
C a.leadingCoeff * (normalizedFactors a).prod = a := by
by_cases ha : a = 0
· simp [ha]
rw [prod_normalizedFactors_eq, normalize_apply, coe_normUnit, CommGroupWithZero.coe_normUnit,
mul_comm, mul_assoc, ← map_mul, inv_mul_cancel₀] <;>
simp_all
open UniqueFactorizationMonoid in
protected theorem mem_normalizedFactors_iff [DecidableEq R] (hq : q ≠ 0) :
p ∈ normalizedFactors q ↔ Irreducible p ∧ p.Monic ∧ p ∣ q := by
by_cases hp : p = 0
· simpa [hp] using zero_notMem_normalizedFactors _
· rw [mem_normalizedFactors_iff' hq, normalize_eq_self_iff_monic hp]
variable (p) in
@[simp]
theorem map_normalize [DecidableEq R] [Field S] [DecidableEq S] (f : R →+* S) :
map f (normalize p) = normalize (map f p) := by
by_cases hp : p = 0
· simp [hp]
· simp [normalize_apply, Polynomial.map_mul, normUnit, hp]
theorem monic_mapAlg_iff [Semiring S] [Nontrivial S] [Algebra R S] {p : R[X]} :
(mapAlg R S p).Monic ↔ p.Monic := by
simp [mapAlg_eq_map, monic_map_iff]
end Field
end Polynomial
namespace Irreducible
variable {F : Type*} [DivisionSemiring F] {f : F[X]}
/-- An irreducible polynomial over a field must have positive degree. -/
theorem natDegree_pos (h : Irreducible f) : 0 < f.natDegree := Nat.pos_of_ne_zero fun H ↦ by
obtain ⟨x, hf⟩ := natDegree_eq_zero.1 H
by_cases hx : x = 0
· rw [← hf, hx, map_zero] at h; exact not_irreducible_zero h
exact h.1 (hf ▸ isUnit_C.2 (Ne.isUnit hx))
/-- An irreducible polynomial over a field must have positive degree. -/
theorem degree_pos (h : Irreducible f) : 0 < f.degree := by
rw [← natDegree_pos_iff_degree_pos]
exact h.natDegree_pos
end Irreducible |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Roots.lean | import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by
by_cases hp0 : p = 0
· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots ≤ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by
classical
rw [← count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem roots_eq_zero_iff_isRoot_eq_bot (hp0 : p ≠ 0) : p.roots = 0 ↔ p.IsRoot = ⊥ := by
refine ⟨fun h ↦ ?_, fun h ↦ eq_zero_of_forall_notMem fun x hx ↦ h ▸ mem_roots hp0 |>.mp hx⟩
ext a
simp only [Pi.bot_apply, Prop.bot_eq_false, mem_roots hp0 |>.not.mp <| by simp [h]]
theorem roots_eq_zero_iff_eq_zero_or_isRoot_eq_bot : p.roots = 0 ↔ p = 0 ∨ p.IsRoot = ⊥ := by
rcases eq_or_ne p 0 with rfl | hp0; · simp
simp [roots_eq_zero_iff_isRoot_eq_bot hp0, hp0]
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S →+* R}
(hf : Function.Injective f) {x : R} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by
rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.algebraMap_self, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) :
#Z ≤ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [← sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by
rintro ⟨k, rfl⟩
exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x ∈ (p - C a).roots ↔ p.eval x = a :=
mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_ge <| hp.symm ▸ degree_C_le
@[simp]
theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by
classical
ext s
rw [count_roots, rootMultiplicity_X_sub_C, count_singleton]
@[simp]
theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r)
@[simp]
theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero]
@[simp]
theorem roots_C (x : R) : (C x).roots = 0 := by
classical exact
if H : x = 0 then by rw [H, C_0, roots_zero]
else
Multiset.ext.mpr fun r => (by
rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)])
@[simp]
theorem roots_one : (1 : R[X]).roots = ∅ :=
roots_C 1
@[simp]
theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by
by_cases hp : p = 0 <;>
simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C,
zero_add, mul_zero]
theorem _root_.Associated.roots_eq {p q : R[X]} (h : Associated p q) : p.roots = q.roots := by
obtain ⟨u, rfl⟩ := h
rw [eq_C_of_degree_eq_zero <| degree_coe_units u, mul_comm,
roots_C_mul _ <| coeff_coe_units_zero_ne_zero u]
@[simp]
theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by
rw [smul_eq_C_mul, roots_C_mul _ ha]
@[simp]
lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by
rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)]
@[simp]
theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X - C b).roots =
{a⁻¹ * b} := by
rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul,
Units.inv_mul, C_1, one_mul]
exact roots_X_sub_C (a⁻¹ * b)
@[simp]
theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X + C b).roots =
{-(a⁻¹ * b)} := by
rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg]
theorem roots_list_prod (L : List R[X]) :
(0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots :=
List.recOn L (fun _ => roots_one) fun hd tl ih H => by
rw [List.mem_cons, not_or] at H
rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ←
Multiset.cons_coe, Multiset.cons_bind, ih H.2]
theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by
rcases m with ⟨L⟩
simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L
theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) :
s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by
rcases s with ⟨m, hm⟩
simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
@[simp]
theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by
induction n with
| zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero]
| succ n ihn =>
rcases eq_or_ne p 0 with (rfl | hp)
· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero]
· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul]
theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by
rw [roots_pow, roots_X]
theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) :
Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by
rw [roots_C_mul _ ha, roots_X_pow]
@[simp]
theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by
rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha]
theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by
apply (roots_prod (fun a => X - C a) s ?_).trans
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a)
@[simp]
theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by
rw [roots_multiset_prod, Multiset.bind_map]
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· rw [Multiset.mem_map]
rintro ⟨a, -, h⟩
exact X_sub_C_ne_zero a h
theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n :=
WithBot.coe_le_coe.1 <|
calc
(Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) :=
card_roots (X_pow_sub_C_ne_zero hn a)
_ = n := degree_X_pow_sub_C hn a
section NthRoots
/-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/
def nthRoots (n : ℕ) (a : R) : Multiset R :=
roots ((X : R[X]) ^ n - C a)
@[simp]
theorem mem_nthRoots {n : ℕ} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by
rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow,
eval_X, sub_eq_zero]
@[simp]
theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by
simp only [pow_zero, nthRoots, ← C_1, ← C_sub, roots_C]
@[simp]
theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : ℕ) :
nthRoots n (0 : R) = Multiset.replicate n 0 := by
rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton]
theorem card_nthRoots (n : ℕ) (a : R) : Multiset.card (nthRoots n a) ≤ n := by
classical exact
(if hn : n = 0 then
if h : (X : R[X]) ^ n - C a = 0 then by
simp [nthRoots, roots, h, empty_eq_zero, Multiset.card_zero]
else
WithBot.coe_le_coe.1
(le_trans (card_roots h)
(by
rw [hn, pow_zero, ← C_1, ← RingHom.map_sub]
exact degree_C_le))
else by
rw [← Nat.cast_le (α := WithBot ℕ)]
rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a]
exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a))
@[simp]
theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ ¬IsSquare r := by
simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_notMem, mem_nthRoots (by simp : 0 < 2),
← not_exists, eq_comm]
/-- The multiset `nthRoots ↑n a` as a Finset. Previously `nthRootsFinset n` was defined to be
`nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/
def nthRootsFinset (n : ℕ) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R :=
haveI := Classical.decEq R
Multiset.toFinset (nthRoots n a)
lemma nthRootsFinset_def (n : ℕ) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] :
nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by
unfold nthRootsFinset
convert rfl
@[simp]
theorem mem_nthRootsFinset {n : ℕ} (h : 0 < n) (a : R) {x : R} :
x ∈ nthRootsFinset n a ↔ x ^ (n : ℕ) = a := by
classical
rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h]
@[simp]
theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = ∅ := by
classical simp [nthRootsFinset_def]
theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[MonoidHomClass F R S] {a : R} {x : R} (hx : x ∈ nthRootsFinset n a) (f : F) :
f x ∈ nthRootsFinset n (f a) := by
by_cases hn : n = 0
· simp [hn] at hx
· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, ← map_pow, (mem_nthRootsFinset
(Nat.pos_of_ne_zero hn) a).1 hx]
theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[RingHomClass F R S] {x : R} (hx : x ∈ nthRootsFinset n 1) (f : F) :
f x ∈ nthRootsFinset n 1 := by
rw [← (map_one f)]
exact map_mem_nthRootsFinset hx _
theorem mul_mem_nthRootsFinset
{η₁ η₂ : R} {a₁ a₂ : R} (hη₁ : η₁ ∈ nthRootsFinset n a₁) (hη₂ : η₂ ∈ nthRootsFinset n a₂) :
η₁ * η₂ ∈ nthRootsFinset n (a₁ * a₂) := by
cases n with
| zero =>
simp only [nthRootsFinset_zero, notMem_empty] at hη₁
| succ n =>
rw [mem_nthRootsFinset n.succ_pos] at hη₁ hη₂ ⊢
rw [mul_pow, hη₁, hη₂]
theorem ne_zero_of_mem_nthRootsFinset {η : R} {a : R} (ha : a ≠ 0) (hη : η ∈ nthRootsFinset n a) :
η ≠ 0 := by
nontriviality R
rintro rfl
cases n with
| zero =>
simp only [nthRootsFinset_zero, notMem_empty] at hη
| succ n =>
rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hη
exact ha hη.symm
theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n (1 : R) := by
rw [mem_nthRootsFinset hn, one_pow]
lemma nthRoots_two_one : Polynomial.nthRoots 2 (1 : R) = {-1,1} := by
have h₁ : (X ^ 2 - C 1 : R[X]) = (X + C 1) * (X - C 1) := by simp [← sq_sub_sq]
have h₂ : (X ^ 2 - C 1 : R[X]) ≠ 0 := fun h ↦ by simpa using congrArg (coeff · 0) h
rw [nthRoots, h₁, roots_mul (h₁ ▸ h₂), roots_X_add_C, roots_X_sub_C]; rfl
end NthRoots
theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 := by
classical
by_contra hp
refine @Fintype.false R _ ?_
exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩
theorem funext [Infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q := by
rw [← sub_eq_zero]
apply zero_of_eval_zero
intro x
rw [eval_sub, sub_eq_zero, ext]
variable [CommRing T]
/-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is
the multiset of roots of `p` regarded as a polynomial over `S`. -/
noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S :=
(p.map (algebraMap T S)).roots
theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
p.aroots S = (p.map (algebraMap T S)).roots :=
rfl
theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} :
a ∈ p.aroots S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by
rw [mem_roots', IsRoot.def, ← eval₂_eq_eval_map, aeval_def]
theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p ≠ 0 ∧ aeval a p = 0 := by
rw [mem_aroots', Polynomial.map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q ≠ 0) :
(p * q).aroots S = p.aroots S + q.aroots S := by
suffices map (algebraMap T S) p * map (algebraMap T S) q ≠ 0 by
rw [aroots_def, Polynomial.map_mul, roots_mul this]
rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff
(FaithfulSMul.algebraMap_injective T S)]
@[simp]
theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S]
(r : T) : aroots (X - C r) S = {algebraMap T S r} := by
rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C]
@[simp]
theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] :
aroots (X : T[X]) S = {0} := by
rw [aroots_def, map_X, roots_X]
@[simp]
theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by
rw [aroots_def, map_C, roots_C]
@[simp]
theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by
rw [← C_0, aroots_C]
@[simp]
theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] :
(1 : T[X]).aroots S = 0 :=
aroots_C 1
@[simp]
theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) :
(-p).aroots S = p.aroots S := by
rw [aroots, Polynomial.map_neg, roots_neg]
@[simp]
theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) :
(C a * p).aroots S = p.aroots S := by
rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul]
rwa [map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
@[simp]
theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) :
(a • p).aroots S = p.aroots S := by
rw [smul_eq_C_mul, aroots_C_mul _ ha]
@[simp]
theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : ℕ) :
(p ^ n).aroots S = n • p.aroots S := by
rw [aroots_def, Polynomial.map_pow, roots_pow]
theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : ℕ) :
(X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by
rw [aroots_pow, aroots_X]
theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) :
(C a * X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by
rw [aroots_C_mul _ ha, aroots_X_pow]
@[simp]
theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) :
(monomial n a).aroots S = n • ({0} : Multiset S) := by
rw [← C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha]
variable (R S) in
@[simp]
theorem aroots_map (p : T[X]) [CommRing S] [Algebra T S] [Algebra S R] [Algebra T R]
[IsScalarTower T S R] :
(p.map (algebraMap T S)).aroots R = p.aroots R := by
rw [aroots_def, aroots_def, map_map, IsScalarTower.algebraMap_eq T S R]
/-- The set of distinct roots of `p` in `S`.
If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset
where multiple roots have the appropriate multiplicity. -/
def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S :=
haveI := Classical.decEq S
(p.aroots S).toFinset
theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] :
p.rootSet S = (p.aroots S).toFinset := by
rw [rootSet]
convert rfl
@[simp]
theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = ∅ := by
classical
rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty]
@[simp]
theorem rootSet_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).rootSet S = ∅ := by
rw [← C_0, rootSet_C]
@[simp]
theorem rootSet_one (S) [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).rootSet S = ∅ := by
rw [← C_1, rootSet_C]
@[simp]
theorem rootSet_neg (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
(-p).rootSet S = p.rootSet S := by
rw [rootSet, aroots_neg, rootSet]
instance rootSetFintype (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
Fintype (p.rootSet S) :=
FinsetCoe.fintype _
theorem rootSet_finite (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
(p.rootSet S).Finite :=
Set.toFinite _
/-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set
is finite. -/
theorem bUnion_roots_finite {R S : Type*} [Semiring R] [CommRing S] [IsDomain S] [DecidableEq S]
(m : R →+* S) (d : ℕ) {U : Set R} (h : U.Finite) :
(⋃ (f : R[X]) (_ : f.natDegree ≤ d ∧ ∀ i, f.coeff i ∈ U),
((f.map m).roots.toFinset : Set S)).Finite :=
Set.Finite.biUnion
(by
-- We prove that the set of polynomials under consideration is finite because its
-- image by the injective map `π` is finite
let π : R[X] → Fin (d + 1) → R := fun f i => f.coeff i
refine ((Set.Finite.pi fun _ => h).subset <| ?_).of_finite_image (?_ : Set.InjOn π _)
· exact Set.image_subset_iff.2 fun f hf i _ => hf.2 i
· refine fun x hx y hy hxy => (ext_iff_natDegree_le hx.1 hy.1).2 fun i hi => ?_
exact id congr_fun hxy ⟨i, Nat.lt_succ_of_le hi⟩)
fun _ _ => Finset.finite_toSet _
/-- A version of `mem_rootSet` that requires the polynomial to be non-zero after mapping
instead of requiring it to be non-zero and `NoZeroSMulDivisors`. -/
theorem mem_rootSet' {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] {a : S} :
a ∈ p.rootSet S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by
classical
rw [rootSet_def, Finset.mem_coe, mem_toFinset, mem_aroots']
/-- A version of `mem_rootSet'` that requires `NoZeroSMulDivisors` and for the polynomial to be
non-zero instead of requiring it to be non-zero after mapping. -/
theorem mem_rootSet {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : S} : a ∈ p.rootSet S ↔ p ≠ 0 ∧ aeval a p = 0 := by
rw [mem_rootSet', Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)]
theorem mem_rootSet_of_ne {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] (hp : p ≠ 0) {a : S} : a ∈ p.rootSet S ↔ aeval a p = 0 :=
mem_rootSet.trans <| and_iff_right hp
theorem rootSet_maps_to' {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] (hp : p.map (algebraMap T S') = 0 → p.map (algebraMap T S) = 0)
(f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := fun x hx => by
rw [mem_rootSet'] at hx ⊢
rw [aeval_algHom, AlgHom.comp_apply, hx.2, _root_.map_zero]
exact ⟨mt hp hx.1, rfl⟩
theorem ne_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(h : a ∈ p.rootSet S) : p ≠ 0 := fun hf => by rwa [hf, rootSet_zero] at h
theorem aeval_eq_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(hx : a ∈ p.rootSet S) : aeval a p = 0 :=
(mem_rootSet'.1 hx).2
theorem rootSet_mapsTo {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] [NoZeroSMulDivisors T S'] (f : S →ₐ[T] S') :
(p.rootSet S).MapsTo f (p.rootSet S') := by
refine rootSet_maps_to' (fun h₀ => ?_) f
obtain rfl : p = 0 :=
map_injective _ (FaithfulSMul.algebraMap_injective T S') (by rwa [Polynomial.map_zero])
exact Polynomial.map_zero _
theorem mem_rootSet_of_injective [CommRing S] {p : S[X]} [Algebra S R]
(h : Function.Injective (algebraMap S R)) {x : R} (hp : p ≠ 0) :
x ∈ p.rootSet R ↔ aeval x p = 0 := by
classical
exact Multiset.mem_toFinset.trans (mem_roots_map_of_injective h hp)
@[simp]
theorem nthRootsFinset_toSet {n : ℕ} (h : 0 < n) (a : R) :
nthRootsFinset n a = {r | r ^ n = a} := by
ext x
simp_all
end Roots
lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero {R} [CommRing R] [IsDomain R]
(p : R[X]) {ι} [Fintype ι] {f : ι → R} (hf : Function.Injective f)
(heval : ∀ i, p.eval (f i) = 0) (hcard : natDegree p < Fintype.card ι) : p = 0 := by
classical
by_contra hp
refine lt_irrefl #p.roots.toFinset ?_
calc
#p.roots.toFinset ≤ Multiset.card p.roots := Multiset.toFinset_card_le _
_ ≤ natDegree p := Polynomial.card_roots' p
_ < Fintype.card ι := hcard
_ = Fintype.card (Set.range f) := (Set.card_range_of_injective hf).symm
_ = #(Finset.univ.image f) := by rw [← Set.toFinset_card, Set.toFinset_range]
_ ≤ #p.roots.toFinset := Finset.card_mono ?_
intro _
simp only [Finset.mem_image, Finset.mem_univ, true_and, Multiset.mem_toFinset, mem_roots', ne_eq,
IsRoot.def, forall_exists_index, hp, not_false_eq_true]
rintro x rfl
exact heval _
lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero' {R} [CommRing R] [IsDomain R]
(p : R[X]) (s : Finset R) (heval : ∀ i ∈ s, p.eval i = 0) (hcard : natDegree p < #s) :
p = 0 :=
eq_zero_of_natDegree_lt_card_of_eval_eq_zero p Subtype.val_injective
(fun i : s ↦ heval i i.prop) (hcard.trans_eq (Fintype.card_coe s).symm)
open Cardinal in
lemma eq_zero_of_forall_eval_zero_of_natDegree_lt_card
(f : R[X]) (hf : ∀ r, f.eval r = 0) (hfR : f.natDegree < #R) : f = 0 := by
obtain hR|hR := finite_or_infinite R
· have := Fintype.ofFinite R
apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero f Function.injective_id hf
simpa only [mk_fintype, Nat.cast_lt] using hfR
· exact zero_of_eval_zero _ hf
open Cardinal in
lemma exists_eval_ne_zero_of_natDegree_lt_card (f : R[X]) (hf : f ≠ 0) (hfR : f.natDegree < #R) :
∃ r, f.eval r ≠ 0 := by
contrapose! hf
exact eq_zero_of_forall_eval_zero_of_natDegree_lt_card f hf hfR
section
omit [IsDomain R]
theorem monic_multisetProd_X_sub_C (s : Multiset R) : Monic (s.map fun a => X - C a).prod :=
monic_multiset_prod_of_monic _ _ fun a _ => monic_X_sub_C a
theorem monic_prod_X_sub_C {α : Type*} (b : α → R) (s : Finset α) :
Monic (∏ a ∈ s, (X - C (b a))) :=
monic_prod_of_monic _ _ fun a _ => monic_X_sub_C (b a)
theorem monic_finprod_X_sub_C {α : Type*} (b : α → R) : Monic (∏ᶠ k, (X - C (b k))) :=
monic_finprod_of_monic _ _ fun a _ => monic_X_sub_C (b a)
end
theorem prod_multiset_root_eq_finset_root [DecidableEq R] :
(p.roots.map fun a => X - C a).prod =
p.roots.toFinset.prod fun a => (X - C a) ^ rootMultiplicity a p := by
simp only [count_roots, Finset.prod_multiset_map_count]
/-- The product `∏ (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/
theorem prod_multiset_X_sub_C_dvd (p : R[X]) : (p.roots.map fun a => X - C a).prod ∣ p := by
classical
rw [← map_dvd_map _ (IsFractionRing.injective R <| FractionRing R)
(monic_multisetProd_X_sub_C p.roots)]
rw [prod_multiset_root_eq_finset_root, Polynomial.map_prod]
refine Finset.prod_dvd_of_coprime (fun a _ b _ h => ?_) fun a _ => ?_
· simp_rw [Polynomial.map_pow, Polynomial.map_sub, map_C, map_X]
exact (pairwise_coprime_X_sub_C (IsFractionRing.injective R <| FractionRing R) h).pow
· exact Polynomial.map_dvd _ (pow_rootMultiplicity_dvd p a)
/-- A Galois connection. -/
theorem _root_.Multiset.prod_X_sub_C_dvd_iff_le_roots {p : R[X]} (hp : p ≠ 0) (s : Multiset R) :
(s.map fun a => X - C a).prod ∣ p ↔ s ≤ p.roots := by
classical exact
⟨fun h =>
Multiset.le_iff_count.2 fun r => by
rw [count_roots, le_rootMultiplicity_iff hp, ← Multiset.prod_replicate, ←
Multiset.map_replicate fun a => X - C a, ← Multiset.filter_eq]
exact (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| s.filter_le _).trans h,
fun h =>
(Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map h).trans p.prod_multiset_X_sub_C_dvd⟩
theorem exists_prod_multiset_X_sub_C_mul (p : R[X]) :
∃ q,
(p.roots.map fun a => X - C a).prod * q = p ∧
Multiset.card p.roots + q.natDegree = p.natDegree ∧ q.roots = 0 := by
obtain ⟨q, he⟩ := p.prod_multiset_X_sub_C_dvd
use q, he.symm
obtain rfl | hq := eq_or_ne q 0
· rw [mul_zero] at he
subst he
simp
constructor
· conv_rhs => rw [he]
rw [(monic_multisetProd_X_sub_C p.roots).natDegree_mul' hq,
natDegree_multiset_prod_X_sub_C_eq_card]
· replace he := congr_arg roots he.symm
rw [roots_mul, roots_multiset_prod_X_sub_C] at he
exacts [add_eq_left.1 he, mul_ne_zero (monic_multisetProd_X_sub_C p.roots).ne_zero hq]
/-- A polynomial `p` that has as many roots as its degree
can be written `p = p.leadingCoeff * ∏(X - a)`, for `a` in `p.roots`. -/
theorem C_leadingCoeff_mul_prod_multiset_X_sub_C (hroots : Multiset.card p.roots = p.natDegree) :
C p.leadingCoeff * (p.roots.map fun a => X - C a).prod = p :=
(eq_leadingCoeff_mul_of_monic_of_dvd_of_natDegree_le (monic_multisetProd_X_sub_C p.roots)
p.prod_multiset_X_sub_C_dvd
((natDegree_multiset_prod_X_sub_C_eq_card _).trans hroots).ge).symm
/-- A monic polynomial `p` that has as many roots as its degree
can be written `p = ∏(X - a)`, for `a` in `p.roots`. -/
theorem prod_multiset_X_sub_C_of_monic_of_roots_card_eq (hp : p.Monic)
(hroots : Multiset.card p.roots = p.natDegree) : (p.roots.map fun a => X - C a).prod = p := by
convert C_leadingCoeff_mul_prod_multiset_X_sub_C hroots
rw [hp.leadingCoeff, C_1, one_mul]
theorem Monic.isUnit_leadingCoeff_of_dvd {a p : R[X]} (hp : Monic p) (hap : a ∣ p) :
IsUnit a.leadingCoeff :=
isUnit_of_dvd_one (by simpa only [hp.leadingCoeff] using leadingCoeff_dvd_leadingCoeff hap)
theorem card_roots_le_one_of_irreducible (hirr : Irreducible p) : p.roots.card ≤ 1 := by
obtain hp | ⟨x, hx⟩ := p.roots.empty_or_exists_mem
· simp [hp]
convert p.card_roots'
exact (natDegree_eq_of_degree_eq_some <| degree_eq_one_of_irreducible_of_root hirr <|
isRoot_of_mem_roots hx).symm
theorem roots_eq_zero_of_irreducible_of_natDegree_ne_one (hirr : Irreducible p)
(hdeg : p.natDegree ≠ 1) : p.roots = 0 := by
by_contra hroots
have ⟨x, hx⟩ := exists_mem_of_ne_zero hroots
exact hdeg <| natDegree_eq_of_degree_eq_some <|
degree_eq_one_of_irreducible_of_root hirr (mem_roots'.mp hx).right
/-- To check a monic polynomial is irreducible, it suffices to check only for
divisors that have smaller degree.
See also: `Polynomial.Monic.irreducible_iff_natDegree`.
-/
theorem Monic.irreducible_iff_degree_lt (p_monic : Monic p) (p_1 : p ≠ 1) :
Irreducible p ↔ ∀ q, degree q ≤ ↑(p.natDegree / 2) → q ∣ p → IsUnit q := by
simp only [p_monic.irreducible_iff_lt_natDegree_lt p_1, Finset.mem_Ioc, and_imp,
natDegree_pos_iff_degree_pos, natDegree_le_iff_degree_le]
constructor
· rintro h q deg_le dvd
by_contra q_unit
have := degree_pos_of_not_isUnit_of_dvd_monic p_monic q_unit dvd
have hu := p_monic.isUnit_leadingCoeff_of_dvd dvd
refine (h _ (monic_of_isUnit_leadingCoeff_inv_smul hu) ?_ ?_ (dvd_trans ?_ dvd)).elim
· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)]
· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)]
· rw [Units.smul_def, Polynomial.smul_eq_C_mul, (isUnit_C.mpr (Units.isUnit _)).mul_left_dvd]
· rintro h q _ deg_pos deg_le dvd
exact deg_pos.ne' <| degree_eq_zero_of_isUnit (h q deg_le dvd)
end CommRing
section
variable {A B : Type*} [CommRing A] [CommRing B]
theorem le_rootMultiplicity_map {p : A[X]} {f : A →+* B} (hmap : map f p ≠ 0) (a : A) :
rootMultiplicity a p ≤ rootMultiplicity (f a) (p.map f) := by
rw [le_rootMultiplicity_iff hmap]
refine _root_.trans ?_ (_root_.map_dvd (mapRingHom f) (pow_rootMultiplicity_dvd p a))
rw [map_pow, map_sub, coe_mapRingHom, map_X, map_C]
theorem eq_rootMultiplicity_map {p : A[X]} {f : A →+* B} (hf : Function.Injective f) (a : A) :
rootMultiplicity a p = rootMultiplicity (f a) (p.map f) := by
by_cases hp0 : p = 0; · simp only [hp0, rootMultiplicity_zero, Polynomial.map_zero]
apply le_antisymm (le_rootMultiplicity_map ((Polynomial.map_ne_zero_iff hf).mpr hp0) a)
rw [le_rootMultiplicity_iff hp0, ← map_dvd_map f hf ((monic_X_sub_C a).pow _),
Polynomial.map_pow, Polynomial.map_sub, map_X, map_C]
apply pow_rootMultiplicity_dvd
theorem count_map_roots [IsDomain A] [DecidableEq B] {p : A[X]} {f : A →+* B} (hmap : map f p ≠ 0)
(b : B) :
(p.roots.map f).count b ≤ rootMultiplicity b (p.map f) := by
rw [le_rootMultiplicity_iff hmap, ← Multiset.prod_replicate, ←
Multiset.map_replicate fun a => X - C a]
rw [← Multiset.filter_eq]
refine
(Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| Multiset.filter_le (Eq b) _).trans ?_
convert Polynomial.map_dvd f p.prod_multiset_X_sub_C_dvd
simp only [Polynomial.map_multiset_prod, Multiset.map_map, Function.comp_apply,
Polynomial.map_sub, map_X, map_C]
theorem count_map_roots_of_injective [IsDomain A] [DecidableEq B] (p : A[X]) {f : A →+* B}
(hf : Function.Injective f) (b : B) :
(p.roots.map f).count b ≤ rootMultiplicity b (p.map f) := by
by_cases hp0 : p = 0
· simp only [hp0, roots_zero, Multiset.map_zero, Multiset.count_zero, Polynomial.map_zero,
rootMultiplicity_zero, le_refl]
· exact count_map_roots ((Polynomial.map_ne_zero_iff hf).mpr hp0) b
theorem map_roots_le [IsDomain A] [IsDomain B] {p : A[X]} {f : A →+* B} (h : p.map f ≠ 0) :
p.roots.map f ≤ (p.map f).roots := by
classical
exact Multiset.le_iff_count.2 fun b => by
rw [count_roots]
apply count_map_roots h
theorem map_roots_le_of_injective [IsDomain A] [IsDomain B] (p : A[X]) {f : A →+* B}
(hf : Function.Injective f) : p.roots.map f ≤ (p.map f).roots := by
by_cases hp0 : p = 0
· simp only [hp0, roots_zero, Multiset.map_zero, Polynomial.map_zero, le_rfl]
exact map_roots_le ((Polynomial.map_ne_zero_iff hf).mpr hp0)
theorem card_roots_map_le_degree {A B : Type*} [Semiring A] [CommRing B] [IsDomain B]
{f : A →+* B} (p : A[X]) (hp0 : p ≠ 0) : (p.map f).roots.card ≤ p.degree := by
by_cases hpm0 : p.map f = 0
· simp [hp0, hpm0, zero_le_degree_iff]
exact card_roots hpm0 |>.trans degree_map_le
theorem card_roots_map_le_natDegree {A B : Type*} [Semiring A] [CommRing B] [IsDomain B]
{f : A →+* B} (p : A[X]) : (p.map f).roots.card ≤ p.natDegree :=
card_roots' _ |>.trans natDegree_map_le
theorem filter_roots_map_range_eq_map_roots [IsDomain A] [IsDomain B] {f : A →+* B}
[DecidableEq A] [DecidableEq B] [DecidablePred (· ∈ f.range)] (hf : Function.Injective f)
(p : A[X]) : (p.map f).roots.filter (· ∈ f.range) = p.roots.map f := by
ext b
rw [Multiset.count_filter]
split_ifs with h
· obtain ⟨a, rfl⟩ := h
simp [hf, Multiset.count_map_eq_count', eq_rootMultiplicity_map hf]
· refine (Multiset.count_eq_zero.mpr fun h' ↦ h ?_).symm
exact Exists.imp (fun _ ↦ And.right) <| Multiset.mem_map.mp h'
theorem card_roots_le_map [IsDomain A] [IsDomain B] {p : A[X]} {f : A →+* B} (h : p.map f ≠ 0) :
Multiset.card p.roots ≤ Multiset.card (p.map f).roots := by
rw [← p.roots.card_map f]
exact Multiset.card_le_card (map_roots_le h)
theorem card_roots_le_map_of_injective [IsDomain A] [IsDomain B] {p : A[X]} {f : A →+* B}
(hf : Function.Injective f) : Multiset.card p.roots ≤ Multiset.card (p.map f).roots := by
by_cases hp0 : p = 0
· simp only [hp0, roots_zero, Polynomial.map_zero, Multiset.card_zero, le_rfl]
exact card_roots_le_map ((Polynomial.map_ne_zero_iff hf).mpr hp0)
theorem roots_map_of_injective_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]}
{f : A →+* B} (hf : Function.Injective f) (hroots : Multiset.card p.roots = p.natDegree) :
p.roots.map f = (p.map f).roots := by
apply Multiset.eq_of_le_of_card_le (map_roots_le_of_injective p hf)
simpa only [Multiset.card_map, hroots] using card_roots_map_le_natDegree p
theorem roots_map_of_map_ne_zero_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]}
(f : A →+* B) (h : p.map f ≠ 0) (hroots : p.roots.card = p.natDegree) :
p.roots.map f = (p.map f).roots :=
eq_of_le_of_card_le (map_roots_le h) <| by
simpa only [Multiset.card_map, hroots] using card_roots_map_le_natDegree p
theorem Monic.roots_map_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]} (hm : p.Monic)
(f : A →+* B) (hroots : p.roots.card = p.natDegree) : p.roots.map f = (p.map f).roots :=
roots_map_of_map_ne_zero_of_card_eq_natDegree f (map_monic_ne_zero hm) hroots
end
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/EraseLead.lean | import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Algebra.Polynomial.Degree.Monomial
/-!
# Erase the leading term of a univariate polynomial
## Definition
* `eraseLead f`: the polynomial `f - leading term of f`
`eraseLead` serves as reduction step in an induction, shaving off one monomial from a polynomial.
The definition is set up so that it does not mention subtraction in the definition,
and thus works for polynomials over semirings as well as rings.
-/
noncomputable section
open Polynomial
open Polynomial Finset
namespace Polynomial
variable {R : Type*} [Semiring R] {f : R[X]}
/-- `eraseLead f` for a polynomial `f` is the polynomial obtained by
subtracting from `f` the leading term of `f`. -/
def eraseLead (f : R[X]) : R[X] :=
Polynomial.erase f.natDegree f
section EraseLead
theorem eraseLead_support (f : R[X]) : f.eraseLead.support = f.support.erase f.natDegree := by
simp only [eraseLead, support_erase]
theorem eraseLead_coeff (i : ℕ) :
f.eraseLead.coeff i = if i = f.natDegree then 0 else f.coeff i := by
simp only [eraseLead, coeff_erase]
@[simp]
theorem eraseLead_coeff_natDegree : f.eraseLead.coeff f.natDegree = 0 := by simp [eraseLead_coeff]
theorem eraseLead_coeff_of_ne (i : ℕ) (hi : i ≠ f.natDegree) : f.eraseLead.coeff i = f.coeff i := by
simp [eraseLead_coeff, hi]
@[simp]
theorem eraseLead_zero : eraseLead (0 : R[X]) = 0 := by simp only [eraseLead, erase_zero]
@[simp]
theorem eraseLead_add_monomial_natDegree_leadingCoeff (f : R[X]) :
f.eraseLead + monomial f.natDegree f.leadingCoeff = f :=
(add_comm _ _).trans (f.monomial_add_erase _)
@[simp]
theorem eraseLead_add_C_mul_X_pow (f : R[X]) :
f.eraseLead + C f.leadingCoeff * X ^ f.natDegree = f := by
rw [C_mul_X_pow_eq_monomial, eraseLead_add_monomial_natDegree_leadingCoeff]
@[simp]
theorem self_sub_monomial_natDegree_leadingCoeff {R : Type*} [Ring R] (f : R[X]) :
f - monomial f.natDegree f.leadingCoeff = f.eraseLead :=
(eq_sub_iff_add_eq.mpr (eraseLead_add_monomial_natDegree_leadingCoeff f)).symm
@[simp]
theorem self_sub_C_mul_X_pow {R : Type*} [Ring R] (f : R[X]) :
f - C f.leadingCoeff * X ^ f.natDegree = f.eraseLead := by
rw [C_mul_X_pow_eq_monomial, self_sub_monomial_natDegree_leadingCoeff]
theorem eraseLead_ne_zero (f0 : 2 ≤ #f.support) : eraseLead f ≠ 0 := by
rw [Ne, ← card_support_eq_zero, eraseLead_support]
exact
(zero_lt_one.trans_le <| (tsub_le_tsub_right f0 1).trans Finset.pred_card_le_card_erase).ne.symm
theorem lt_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :
a < f.natDegree := by
rw [eraseLead_support, mem_erase] at h
exact (le_natDegree_of_mem_supp a h.2).lt_of_ne h.1
theorem ne_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :
a ≠ f.natDegree :=
(lt_natDegree_of_mem_eraseLead_support h).ne
theorem natDegree_notMem_eraseLead_support : f.natDegree ∉ (eraseLead f).support := fun h =>
ne_natDegree_of_mem_eraseLead_support h rfl
@[deprecated (since := "2025-05-23")]
alias natDegree_not_mem_eraseLead_support := natDegree_notMem_eraseLead_support
theorem eraseLead_support_card_lt (h : f ≠ 0) : #(eraseLead f).support < #f.support := by
rw [eraseLead_support]
exact card_lt_card (erase_ssubset <| natDegree_mem_support_of_nonzero h)
theorem card_support_eraseLead_add_one (h : f ≠ 0) : #f.eraseLead.support + 1 = #f.support := by
set c := #f.support with hc
cases h₁ : c
case zero =>
by_contra
exact h (card_support_eq_zero.mp h₁)
case succ =>
rw [eraseLead_support, card_erase_of_mem (natDegree_mem_support_of_nonzero h), ← hc, h₁]
rfl
@[simp]
theorem card_support_eraseLead : #f.eraseLead.support = #f.support - 1 := by
by_cases hf : f = 0
· rw [hf, eraseLead_zero, support_zero, card_empty]
· rw [← card_support_eraseLead_add_one hf, add_tsub_cancel_right]
theorem card_support_eraseLead' {c : ℕ} (fc : #f.support = c + 1) :
#f.eraseLead.support = c := by
rw [card_support_eraseLead, fc, add_tsub_cancel_right]
theorem card_support_eq_one_of_eraseLead_eq_zero (h₀ : f ≠ 0) (h₁ : f.eraseLead = 0) :
#f.support = 1 :=
(card_support_eq_zero.mpr h₁ ▸ card_support_eraseLead_add_one h₀).symm
theorem card_support_le_one_of_eraseLead_eq_zero (h : f.eraseLead = 0) : #f.support ≤ 1 := by
by_cases hpz : f = 0
case pos => simp [hpz]
case neg => exact le_of_eq (card_support_eq_one_of_eraseLead_eq_zero hpz h)
@[simp]
theorem eraseLead_monomial (i : ℕ) (r : R) : eraseLead (monomial i r) = 0 := by
classical
by_cases hr : r = 0
· subst r
simp only [monomial_zero_right, eraseLead_zero]
· rw [eraseLead, natDegree_monomial, if_neg hr, erase_monomial]
@[simp]
theorem eraseLead_C (r : R) : eraseLead (C r) = 0 :=
eraseLead_monomial _ _
@[simp]
theorem eraseLead_X : eraseLead (X : R[X]) = 0 :=
eraseLead_monomial _ _
@[simp]
theorem eraseLead_X_pow (n : ℕ) : eraseLead (X ^ n : R[X]) = 0 := by
rw [X_pow_eq_monomial, eraseLead_monomial]
@[simp]
theorem eraseLead_C_mul_X_pow (r : R) (n : ℕ) : eraseLead (C r * X ^ n) = 0 := by
rw [C_mul_X_pow_eq_monomial, eraseLead_monomial]
@[simp] lemma eraseLead_C_mul_X (r : R) : eraseLead (C r * X) = 0 := by
simpa using eraseLead_C_mul_X_pow _ 1
theorem eraseLead_add_of_degree_lt_left {p q : R[X]} (pq : q.degree < p.degree) :
(p + q).eraseLead = p.eraseLead + q := by
ext n
by_cases nd : n = p.natDegree
· rw [nd, eraseLead_coeff, if_pos (natDegree_add_eq_left_of_degree_lt pq).symm]
simpa using (coeff_eq_zero_of_degree_lt (lt_of_lt_of_le pq degree_le_natDegree)).symm
· rw [eraseLead_coeff, coeff_add, coeff_add, eraseLead_coeff, if_neg, if_neg nd]
rintro rfl
exact nd (natDegree_add_eq_left_of_degree_lt pq)
theorem eraseLead_add_of_natDegree_lt_left {p q : R[X]} (pq : q.natDegree < p.natDegree) :
(p + q).eraseLead = p.eraseLead + q :=
eraseLead_add_of_degree_lt_left (degree_lt_degree pq)
theorem eraseLead_add_of_degree_lt_right {p q : R[X]} (pq : p.degree < q.degree) :
(p + q).eraseLead = p + q.eraseLead := by
ext n
by_cases nd : n = q.natDegree
· rw [nd, eraseLead_coeff, if_pos (natDegree_add_eq_right_of_degree_lt pq).symm]
simpa using (coeff_eq_zero_of_degree_lt (lt_of_lt_of_le pq degree_le_natDegree)).symm
· rw [eraseLead_coeff, coeff_add, coeff_add, eraseLead_coeff, if_neg, if_neg nd]
rintro rfl
exact nd (natDegree_add_eq_right_of_degree_lt pq)
theorem eraseLead_add_of_natDegree_lt_right {p q : R[X]} (pq : p.natDegree < q.natDegree) :
(p + q).eraseLead = p + q.eraseLead :=
eraseLead_add_of_degree_lt_right (degree_lt_degree pq)
theorem eraseLead_degree_le : (eraseLead f).degree ≤ f.degree :=
f.degree_erase_le _
theorem degree_eraseLead_lt (hf : f ≠ 0) : (eraseLead f).degree < f.degree :=
f.degree_erase_lt hf
theorem eraseLead_natDegree_le_aux : (eraseLead f).natDegree ≤ f.natDegree :=
natDegree_le_natDegree eraseLead_degree_le
theorem eraseLead_natDegree_lt (f0 : 2 ≤ #f.support) : (eraseLead f).natDegree < f.natDegree :=
lt_of_le_of_ne eraseLead_natDegree_le_aux <|
ne_natDegree_of_mem_eraseLead_support <|
natDegree_mem_support_of_nonzero <| eraseLead_ne_zero f0
theorem natDegree_pos_of_eraseLead_ne_zero (h : f.eraseLead ≠ 0) : 0 < f.natDegree := by
by_contra h₂
rw [eq_C_of_natDegree_eq_zero (Nat.eq_zero_of_not_pos h₂)] at h
simp at h
theorem eraseLead_natDegree_lt_or_eraseLead_eq_zero (f : R[X]) :
(eraseLead f).natDegree < f.natDegree ∨ f.eraseLead = 0 := by
by_cases! h : #f.support ≤ 1
· right
rw [← C_mul_X_pow_eq_self h]
simp
· left
apply eraseLead_natDegree_lt h
theorem eraseLead_natDegree_le (f : R[X]) : (eraseLead f).natDegree ≤ f.natDegree - 1 := by
rcases f.eraseLead_natDegree_lt_or_eraseLead_eq_zero with (h | h)
· exact Nat.le_sub_one_of_lt h
· simp only [h, natDegree_zero, zero_le]
lemma natDegree_eraseLead (h : f.nextCoeff ≠ 0) : f.eraseLead.natDegree = f.natDegree - 1 := by
have := natDegree_pos_of_nextCoeff_ne_zero h
refine f.eraseLead_natDegree_le.antisymm <| le_natDegree_of_ne_zero ?_
rwa [eraseLead_coeff_of_ne _ (tsub_lt_self _ _).ne, ← nextCoeff_of_natDegree_pos]
all_goals positivity
lemma natDegree_eraseLead_add_one (h : f.nextCoeff ≠ 0) :
f.eraseLead.natDegree + 1 = f.natDegree := by
rw [natDegree_eraseLead h, tsub_add_cancel_of_le]
exact natDegree_pos_of_nextCoeff_ne_zero h
theorem natDegree_eraseLead_le_of_nextCoeff_eq_zero (h : f.nextCoeff = 0) :
f.eraseLead.natDegree ≤ f.natDegree - 2 := by
refine natDegree_le_pred (n := f.natDegree - 1) (eraseLead_natDegree_le f) ?_
rw [nextCoeff_eq_zero, natDegree_eq_zero] at h
obtain ⟨a, rfl⟩ | ⟨hf, h⟩ := h
· simp
rw [eraseLead_coeff_of_ne _ (tsub_lt_self hf zero_lt_one).ne, ← nextCoeff_of_natDegree_pos hf]
simp [nextCoeff_eq_zero, h, eq_zero_or_pos]
lemma two_le_natDegree_of_nextCoeff_eraseLead (hlead : f.eraseLead ≠ 0)
(hnext : f.nextCoeff = 0) : 2 ≤ f.natDegree := by
contrapose! hlead
rw [Nat.lt_succ_iff, Nat.le_one_iff_eq_zero_or_eq_one, natDegree_eq_zero, natDegree_eq_one]
at hlead
obtain ⟨a, rfl⟩ | ⟨a, ha, b, rfl⟩ := hlead
· simp
· rw [nextCoeff_C_mul_X_add_C ha] at hnext
subst b
simp
theorem leadingCoeff_eraseLead_eq_nextCoeff (h : f.nextCoeff ≠ 0) :
f.eraseLead.leadingCoeff = f.nextCoeff := by
have := natDegree_pos_of_nextCoeff_ne_zero h
rw [leadingCoeff, nextCoeff, natDegree_eraseLead h, if_neg,
eraseLead_coeff_of_ne _ (tsub_lt_self _ _).ne]
all_goals positivity
theorem nextCoeff_eq_zero_of_eraseLead_eq_zero (h : f.eraseLead = 0) : f.nextCoeff = 0 := by
by_contra h₂
exact leadingCoeff_ne_zero.mp (leadingCoeff_eraseLead_eq_nextCoeff h₂ ▸ h₂) h
/-- If we erase the leading coefficient of a `Polynomial.coeffList` like [+,0,...], and then
multiply by a linear term, it's equivalent to erasing the first two coefficients of the product. -/
lemma eraseLead_mul_eq_mul_eraseLead_of_nextCoeff_zero {R : Type*} [Ring R] [NoZeroDivisors R]
[Nontrivial R] {x : R} {P : R[X]} (hx : x ≠ 0) (h : P.nextCoeff = 0) :
((X - C x) * P).eraseLead.eraseLead = (X - C x) * P.eraseLead := by
-- if `P = 0` this is trivial
by_cases hp : P = 0
· simp [hp]
-- can assume eraseLead P ≠ 0, otherwise it's a monomial and both sides are zero.
by_cases he : P.eraseLead = 0
· rw [he, mul_zero]
by_cases he₂ : ((X - C x) * P).eraseLead = 0
· simp [he₂]
suffices #((X - C x) * P).support ≤ 2 by
rw [← card_support_eq_zero]
linarith [eraseLead_support_card_lt he₂,
eraseLead_support_card_lt (mul_ne_zero (X_sub_C_ne_zero x) hp)]
have h₂ : #(X - C x).support = 2 := by
simpa [← sub_eq_add_neg] using
card_support_binomial one_ne_zero one_ne_zero (neg_ne_zero.mpr hx)
have hmul := card_support_mul_le (p := X - C x) (q := P)
rw [h₂] at hmul
linarith [card_support_le_one_of_eraseLead_eq_zero he]
have h₁ : ((X - C x) * P).natDegree = P.natDegree + 1 := by
rw [natDegree_mul (X_sub_C_ne_zero x) hp, natDegree_X_sub_C, add_comm]
-- 2 ≤ P.natDegree
obtain ⟨dP, hdP⟩ := Nat.exists_eq_add_of_le' (two_le_natDegree_of_nextCoeff_eraseLead he h)
-- the subleading term of (X - C η) * P is nonzero
have h₂ : ((X - C x) * P).nextCoeff ≠ 0 := by
simp only [nextCoeff, hdP, Nat.succ_ne_zero, ite_false, Nat.add_one_sub_one] at h
rw [nextCoeff, h₁, add_tsub_cancel_right, hdP, coeff_X_sub_C_mul]
simp [h, hx, ← hdP, hp]
-- Prove equality by showing coefficients are equal
ext n
rcases n.lt_or_ge P.natDegree with hn | hn
· --n < P.natDegree
have hd₁ : n < ((X - C x) * P).eraseLead.natDegree := by
linarith [natDegree_eraseLead_add_one h₂]
rw [← self_sub_monomial_natDegree_leadingCoeff, coeff_sub, coeff_monomial, if_neg hd₁.ne']
rw [← self_sub_monomial_natDegree_leadingCoeff, coeff_sub, coeff_monomial, if_neg (by omega)]
rw [← self_sub_monomial_natDegree_leadingCoeff, mul_sub, coeff_sub,
sub_zero, sub_zero, eq_sub_iff_add_eq, add_eq_left]
rcases hn₂ : n
· simpa [coeff_monomial, hp] using fun _ ↦ by omega
· rw [coeff_X_sub_C_mul, coeff_monomial, coeff_monomial, if_neg (by omega),
if_neg (by omega), mul_zero, sub_zero]
· --n ≥ P.natDegree, so all the coefficients are zero.
trans 0 <;> rw [coeff_eq_zero_of_natDegree_lt]
· grw [eraseLead_natDegree_le, eraseLead_natDegree_le]
simpa [h₁, hdP] using hn
· grw [natDegree_mul (X_sub_C_ne_zero x) he, natDegree_eraseLead_le_of_nextCoeff_eq_zero h]
simpa [add_comm, hdP] using hn
end EraseLead
/-- An induction lemma for polynomials. It takes a natural number `N` as a parameter, that is
required to be at least as big as the `natDegree` of the polynomial. This is useful to prove
results where you want to change each term in a polynomial to something else depending on the
`natDegree` of the polynomial itself and not on the specific `natDegree` of each term. -/
theorem induction_with_natDegree_le (motive : R[X] → Prop) (N : ℕ) (zero : motive 0)
(C_mul_pow : ∀ n : ℕ, ∀ r : R, r ≠ 0 → n ≤ N → motive (C r * X ^ n))
(add : ∀ f g : R[X], f.natDegree < g.natDegree → g.natDegree ≤ N →
motive f → motive g → motive (f + g)) (f : R[X]) (df : f.natDegree ≤ N) : motive f := by
induction hf : #f.support generalizing f with
| zero =>
convert zero
simpa [support_eq_empty, card_eq_zero] using hf
| succ c hc =>
rw [← eraseLead_add_C_mul_X_pow f]
cases c
· convert C_mul_pow f.natDegree f.leadingCoeff ?_ df using 1
· convert zero_add (C (leadingCoeff f) * X ^ f.natDegree)
rw [← card_support_eq_zero, card_support_eraseLead' hf]
· rw [leadingCoeff_ne_zero, Ne, ← card_support_eq_zero, hf]
exact zero_ne_one.symm
refine add f.eraseLead _ ?_ ?_ ?_ ?_
· refine (eraseLead_natDegree_lt ?_).trans_le (le_of_eq ?_)
· exact (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _))).trans hf.ge
· rw [natDegree_C_mul_X_pow _ _ (leadingCoeff_ne_zero.mpr _)]
rintro rfl
simp at hf
· exact (natDegree_C_mul_X_pow_le f.leadingCoeff f.natDegree).trans df
· exact hc _ (eraseLead_natDegree_le_aux.trans df) (card_support_eraseLead' hf)
· refine C_mul_pow _ _ ?_ df
rw [Ne, leadingCoeff_eq_zero, ← card_support_eq_zero, hf]
exact Nat.succ_ne_zero _
/-- Let `φ : R[x] → S[x]` be an additive map, `k : ℕ` a bound, and `fu : ℕ → ℕ` a
"sufficiently monotone" map. Assume also that
* `φ` maps to `0` all monomials of degree less than `k`,
* `φ` maps each monomial `m` in `R[x]` to a polynomial `φ m` of degree `fu (deg m)`.
Then, `φ` maps each polynomial `p` in `R[x]` to a polynomial of degree `fu (deg p)`. -/
theorem mono_map_natDegree_eq {S F : Type*} [Semiring S]
[FunLike F R[X] S[X]] [AddMonoidHomClass F R[X] S[X]] {φ : F}
{p : R[X]} (k : ℕ) (fu : ℕ → ℕ) (fu0 : ∀ {n}, n ≤ k → fu n = 0)
(fc : ∀ {n m}, k ≤ n → n < m → fu n < fu m) (φ_k : ∀ {f : R[X]}, f.natDegree < k → φ f = 0)
(φ_mon_nat : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = fu n) :
(φ p).natDegree = fu p.natDegree := by
refine induction_with_natDegree_le (fun p => (φ p).natDegree = fu p.natDegree)
p.natDegree (by simp [fu0]) ?_ ?_ _ rfl.le
· intro n r r0 _
rw [natDegree_C_mul_X_pow _ _ r0, C_mul_X_pow_eq_monomial, φ_mon_nat _ _ r0]
· intro f g fg _ fk gk
rw [natDegree_add_eq_right_of_natDegree_lt fg, map_add]
by_cases! FG : k ≤ f.natDegree
· rw [natDegree_add_eq_right_of_natDegree_lt, gk]
rw [fk, gk]
exact fc FG fg
· cases k
· nomatch FG
· rwa [φ_k FG, zero_add]
theorem map_natDegree_eq_sub {S F : Type*} [Semiring S]
[FunLike F R[X] S[X]] [AddMonoidHomClass F R[X] S[X]] {φ : F}
{p : R[X]} {k : ℕ} (φ_k : ∀ f : R[X], f.natDegree < k → φ f = 0)
(φ_mon : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = n - k) :
(φ p).natDegree = p.natDegree - k :=
mono_map_natDegree_eq k (fun j => j - k) (by simp_all)
(@fun _ _ h => (tsub_lt_tsub_iff_right h).mpr)
(φ_k _) φ_mon
theorem map_natDegree_eq_natDegree {S F : Type*} [Semiring S]
[FunLike F R[X] S[X]] [AddMonoidHomClass F R[X] S[X]]
{φ : F} (p) (φ_mon_nat : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = n) :
(φ p).natDegree = p.natDegree :=
(map_natDegree_eq_sub (fun _ h => (Nat.not_lt_zero _ h).elim) (by simpa)).trans
p.natDegree.sub_zero
theorem card_support_eq' {n : ℕ} (k : Fin n → ℕ) (x : Fin n → R) (hk : Function.Injective k)
(hx : ∀ i, x i ≠ 0) : #(∑ i, C (x i) * X ^ k i).support = n := by
suffices (∑ i, C (x i) * X ^ k i).support = image k univ by
rw [this, univ.card_image_of_injective hk, card_fin]
simp_rw [Finset.ext_iff, mem_support_iff, finset_sum_coeff, coeff_C_mul_X_pow, mem_image,
mem_univ, true_and]
refine fun i => ⟨fun h => ?_, ?_⟩
· obtain ⟨j, _, h⟩ := exists_ne_zero_of_sum_ne_zero h
exact ⟨j, (ite_ne_right_iff.mp h).1.symm⟩
· rintro ⟨j, _, rfl⟩
rw [sum_eq_single_of_mem j (mem_univ j), if_pos rfl]
· exact hx j
· exact fun m _ hmj => if_neg fun h => hmj.symm (hk h)
theorem card_support_eq {n : ℕ} :
#f.support = n ↔
∃ (k : Fin n → ℕ) (x : Fin n → R) (_ : StrictMono k) (_ : ∀ i, x i ≠ 0),
f = ∑ i, C (x i) * X ^ k i := by
refine ⟨?_, fun ⟨k, x, hk, hx, hf⟩ => hf.symm ▸ card_support_eq' k x hk.injective hx⟩
induction n generalizing f with
| zero => exact fun hf => ⟨0, 0, fun x => x.elim0, fun x => x.elim0, card_support_eq_zero.mp hf⟩
| succ n hn =>
intro h
obtain ⟨k, x, hk, hx, hf⟩ := hn (card_support_eraseLead' h)
have H : ¬∃ k : Fin n, Fin.castSucc k = Fin.last n := by
rintro ⟨i, hi⟩
exact i.castSucc_lt_last.ne hi
refine
⟨Function.extend Fin.castSucc k fun _ => f.natDegree,
Function.extend Fin.castSucc x fun _ => f.leadingCoeff, ?_, ?_, ?_⟩
· intro i j hij
have hi : i ∈ Set.range (Fin.castSucc : Fin n → Fin (n + 1)) := by
simp only [Fin.range_castSucc, Nat.succ_eq_add_one, Set.mem_setOf_eq]
exact lt_of_lt_of_le hij (Nat.lt_succ_iff.mp j.2)
obtain ⟨i, rfl⟩ := hi
rw [Fin.strictMono_castSucc.injective.extend_apply]
by_cases hj : ∃ j₀, Fin.castSucc j₀ = j
· obtain ⟨j, rfl⟩ := hj
rwa [Fin.strictMono_castSucc.injective.extend_apply, hk.lt_iff_lt,
← Fin.castSucc_lt_castSucc_iff]
· rw [Function.extend_apply' _ _ _ hj]
apply lt_natDegree_of_mem_eraseLead_support
rw [mem_support_iff, hf, finset_sum_coeff]
rw [sum_eq_single, coeff_C_mul, coeff_X_pow_self, mul_one]
· exact hx i
· intro j _ hji
rw [coeff_C_mul, coeff_X_pow, if_neg (hk.injective.ne hji.symm), mul_zero]
· exact fun hi => (hi (mem_univ i)).elim
· intro i
by_cases hi : ∃ i₀, Fin.castSucc i₀ = i
· obtain ⟨i, rfl⟩ := hi
rw [Fin.strictMono_castSucc.injective.extend_apply]
exact hx i
· rw [Function.extend_apply' _ _ _ hi, Ne, leadingCoeff_eq_zero, ← card_support_eq_zero, h]
exact n.succ_ne_zero
· rw [Fin.sum_univ_castSucc]
simp only [Fin.strictMono_castSucc.injective.extend_apply]
rw [← hf, Function.extend_apply', Function.extend_apply', eraseLead_add_C_mul_X_pow]
all_goals exact H
theorem card_support_eq_one : #f.support = 1 ↔
∃ (k : ℕ) (x : R) (_ : x ≠ 0), f = C x * X ^ k := by
refine ⟨fun h => ?_, ?_⟩
· obtain ⟨k, x, _, hx, rfl⟩ := card_support_eq.mp h
exact ⟨k 0, x 0, hx 0, Fin.sum_univ_one _⟩
· rintro ⟨k, x, hx, rfl⟩
rw [support_C_mul_X_pow k hx, card_singleton]
theorem card_support_eq_two :
#f.support = 2 ↔
∃ (k m : ℕ) (_ : k < m) (x y : R) (_ : x ≠ 0) (_ : y ≠ 0),
f = C x * X ^ k + C y * X ^ m := by
refine ⟨fun h => ?_, ?_⟩
· obtain ⟨k, x, hk, hx, rfl⟩ := card_support_eq.mp h
refine ⟨k 0, k 1, hk Nat.zero_lt_one, x 0, x 1, hx 0, hx 1, ?_⟩
rw [Fin.sum_univ_castSucc, Fin.sum_univ_one]
rfl
· rintro ⟨k, m, hkm, x, y, hx, hy, rfl⟩
exact card_support_binomial hkm.ne hx hy
theorem card_support_eq_three :
#f.support = 3 ↔
∃ (k m n : ℕ) (_ : k < m) (_ : m < n) (x y z : R) (_ : x ≠ 0) (_ : y ≠ 0) (_ : z ≠ 0),
f = C x * X ^ k + C y * X ^ m + C z * X ^ n := by
refine ⟨fun h => ?_, ?_⟩
· obtain ⟨k, x, hk, hx, rfl⟩ := card_support_eq.mp h
refine
⟨k 0, k 1, k 2, hk Nat.zero_lt_one, hk (Nat.lt_succ_self 1), x 0, x 1, x 2, hx 0, hx 1, hx 2,
?_⟩
rw [Fin.sum_univ_castSucc, Fin.sum_univ_castSucc, Fin.sum_univ_one]
rfl
· rintro ⟨k, m, n, hkm, hmn, x, y, z, hx, hy, hz, rfl⟩
exact card_support_trinomial hkm hmn hx hy hz
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/DenomsClearable.lean | import Mathlib.Algebra.Algebra.Basic
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Algebra.Polynomial.EraseLead
/-!
# Denominators of evaluation of polynomials at ratios
Let `i : R → K` be a homomorphism of semirings. Assume that `K` is commutative. If `a` and
`b` are elements of `R` such that `i b ∈ K` is invertible, then for any polynomial
`f ∈ R[X]` the "mathematical" expression `b ^ f.natDegree * f (a / b) ∈ K` is in
the image of the homomorphism `i`.
-/
open Polynomial Finset
open Polynomial
section DenomsClearable
variable {R K : Type*} [Semiring R] [CommSemiring K] {i : R →+* K}
variable {a b : R} {bi : K}
-- TODO: use hypothesis (ub : IsUnit (i b)) to work with localizations.
/-- `denomsClearable` formalizes the property that `b ^ N * f (a / b)`
does not have denominators, if the inequality `f.natDegree ≤ N` holds.
The definition asserts the existence of an element `D` of `R` and an
element `bi = 1 / i b` of `K` such that clearing the denominators of
the fraction equals `i D`.
-/
def DenomsClearable (a b : R) (N : ℕ) (f : R[X]) (i : R →+* K) : Prop :=
∃ (D : R) (bi : K), bi * i b = 1 ∧ i D = i b ^ N * eval (i a * bi) (f.map i)
theorem denomsClearable_zero (N : ℕ) (a : R) (bu : bi * i b = 1) : DenomsClearable a b N 0 i :=
⟨0, bi, bu, by
simp only [eval_zero, RingHom.map_zero, mul_zero, Polynomial.map_zero]⟩
theorem denomsClearable_C_mul_X_pow {N : ℕ} (a : R) (bu : bi * i b = 1) {n : ℕ} (r : R)
(nN : n ≤ N) : DenomsClearable a b N (C r * X ^ n) i := by
refine ⟨r * a ^ n * b ^ (N - n), bi, bu, ?_⟩
rw [C_mul_X_pow_eq_monomial, map_monomial, ← C_mul_X_pow_eq_monomial, eval_mul, eval_pow, eval_C]
rw [RingHom.map_mul, RingHom.map_mul, RingHom.map_pow, RingHom.map_pow, eval_X, mul_comm]
rw [← tsub_add_cancel_of_le nN]
conv_lhs => rw [← mul_one (i a), ← bu]
simp [mul_assoc, mul_comm, mul_left_comm, pow_add, mul_pow]
theorem DenomsClearable.add {N : ℕ} {f g : R[X]} :
DenomsClearable a b N f i → DenomsClearable a b N g i → DenomsClearable a b N (f + g) i :=
fun ⟨Df, bf, bfu, Hf⟩ ⟨Dg, bg, bgu, Hg⟩ =>
⟨Df + Dg, bf, bfu, by
rw [RingHom.map_add, Polynomial.map_add, eval_add, mul_add, Hf, Hg]
congr
refine @inv_unique K _ (i b) bg bf ?_ ?_ <;> rwa [mul_comm]⟩
theorem denomsClearable_of_natDegree_le (N : ℕ) (a : R) (bu : bi * i b = 1) :
∀ f : R[X], f.natDegree ≤ N → DenomsClearable a b N f i :=
induction_with_natDegree_le _ N (denomsClearable_zero N a bu)
(fun _ r _ => denomsClearable_C_mul_X_pow a bu r) fun _ _ _ _ df dg => df.add dg
/-- If `i : R → K` is a ring homomorphism, `f` is a polynomial with coefficients in `R`,
`a, b` are elements of `R`, with `i b` invertible, then there is a `D ∈ R` such that
`b ^ f.natDegree * f (a / b)` equals `i D`. -/
theorem denomsClearable_natDegree (i : R →+* K) (f : R[X]) (a : R) (bu : bi * i b = 1) :
DenomsClearable a b f.natDegree f i :=
denomsClearable_of_natDegree_le f.natDegree a bu f le_rfl
end DenomsClearable
open RingHom
/-- Evaluating a polynomial with integer coefficients at a rational number and clearing
denominators, yields a number greater than or equal to one. The target can be any
`LinearOrderedField K`.
The assumption on `K` could be weakened to `LinearOrderedCommRing` assuming that the
image of the denominator is invertible in `K`. -/
theorem one_le_pow_mul_abs_eval_div {K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
{f : ℤ[X]} {a b : ℤ}
(b0 : 0 < b) (fab : eval ((a : K) / b) (f.map (algebraMap ℤ K)) ≠ 0) :
(1 : K) ≤ (b : K) ^ f.natDegree * |eval ((a : K) / b) (f.map (algebraMap ℤ K))| := by
obtain ⟨ev, bi, bu, hF⟩ :=
denomsClearable_natDegree (b := b) (algebraMap ℤ K) f a
(by
rw [eq_intCast, one_div_mul_cancel]
rw [Int.cast_ne_zero]
exact b0.ne.symm)
obtain Fa := congr_arg abs hF
rw [eq_one_div_of_mul_eq_one_left bu, eq_intCast, eq_intCast, abs_mul] at Fa
rw [abs_of_pos (pow_pos (Int.cast_pos.mpr b0) _ : 0 < (b : K) ^ _), one_div, eq_intCast] at Fa
rw [div_eq_mul_inv, ← Fa, ← Int.cast_abs, ← Int.cast_one, Int.cast_le]
refine Int.le_of_lt_add_one ((lt_add_iff_pos_left 1).mpr (abs_pos.mpr fun F0 => fab ?_))
rw [eq_one_div_of_mul_eq_one_left bu, F0, one_div, eq_intCast, Int.cast_zero, zero_eq_mul] at hF
rcases hF with hF | hF
· exact (not_le.mpr b0 (le_of_eq (Int.cast_eq_zero.mp (eq_zero_of_pow_eq_zero hF)))).elim
· rwa [div_eq_mul_inv] |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Module/TensorProduct.lean | import Mathlib.Algebra.Polynomial.Module.Basic
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# PolynomialModule is isomorphic to a tensor product
For a commutative ring `R` and an `R`-module `M`, we obtain an isomorphism between
`R[X] ⊗[R] M` and `PolynomialModule R M` as `R[X]`-modules; this isomorphism is called
`polynomialTensorProductLEquivPolynomialModule`.
-/
open Polynomial TensorProduct LinearMap
noncomputable section
variable (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M]
namespace PolynomialModule
/-- The `R[X]`-linear equivalence `(R[X] ⊗[R] M) ≃ₗ[R[X]] (PolynomialModule R M)`. -/
def polynomialTensorProductLEquivPolynomialModule :
R[X] ⊗[R] M ≃ₗ[R[X]] PolynomialModule R M :=
let e := liftBaseChange R[X] <| lsingle R (M := M) 0
let inv := (eval X).restrictScalars R ∘ₗ map R[X] (TensorProduct.mk R R[X] M 1)
have left : inv ∘ₗ e = .id := by
ext n x
simp [inv, e, ← monomial_one_right_eq_X_pow, smul_tmul']
have right : e.restrictScalars R ∘ₗ inv = .id := by
ext n x
simp [e, inv, ← monomial_one_right_eq_X_pow]
{ __ := e
invFun := inv
left_inv := (congr($left ·))
right_inv := (congr($right ·)) }
end PolynomialModule |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Module/Basic.lean | import Mathlib.Algebra.Polynomial.Module.AEval
/-!
# Polynomial module
In this file, we define the polynomial module for an `R`-module `M`, i.e. the `R[X]`-module `M[X]`.
This is defined as a type alias `PolynomialModule R M := ℕ →₀ M`, since there might be different
module structures on `ℕ →₀ M` of interest. See the docstring of `PolynomialModule` for details.
-/
universe u v
open Polynomial
/-- The `R[X]`-module `M[X]` for an `R`-module `M`.
This is isomorphic (as an `R`-module) to `M[X]` when `M` is a ring.
We require all the module instances `Module S (PolynomialModule R M)` to factor through `R` except
`Module R[X] (PolynomialModule R M)`.
In this constraint, we have the following instances for example :
- `R` acts on `PolynomialModule R R[X]`
- `R[X]` acts on `PolynomialModule R R[X]` as `R[Y]` acting on `R[X][Y]`
- `R` acts on `PolynomialModule R[X] R[X]`
- `R[X]` acts on `PolynomialModule R[X] R[X]` as `R[X]` acting on `R[X][Y]`
- `R[X][X]` acts on `PolynomialModule R[X] R[X]` as `R[X][Y]` acting on itself
This is also the reason why `R` is included in the alias, or else there will be two different
instances of `Module R[X] (PolynomialModule R[X])`.
See https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2315065.20polynomial.20modules
for the full discussion.
-/
@[nolint unusedArguments]
def PolynomialModule (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M] := ℕ →₀ M
deriving Inhabited, FunLike, CoeFun
noncomputable section
deriving instance AddCommGroup for PolynomialModule
end
variable (R : Type*) {M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R)
variable {S : Type*} [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M]
namespace PolynomialModule
/-- This is required to have the `IsScalarTower S R M` instance to avoid diamonds. -/
@[nolint unusedArguments]
noncomputable instance : Module S (PolynomialModule R M) :=
Finsupp.module ℕ M
theorem zero_apply (i : ℕ) : (0 : PolynomialModule R M) i = 0 :=
Finsupp.zero_apply
theorem add_apply (g₁ g₂ : PolynomialModule R M) (a : ℕ) : (g₁ + g₂) a = g₁ a + g₂ a :=
Finsupp.add_apply g₁ g₂ a
/-- The monomial `m * x ^ i`. This is defeq to `Finsupp.singleAddHom`, and is redefined here
so that it has the desired type signature. -/
noncomputable def single (i : ℕ) : M →+ PolynomialModule R M :=
Finsupp.singleAddHom i
theorem single_apply (i : ℕ) (m : M) (n : ℕ) : single R i m n = ite (i = n) m 0 :=
Finsupp.single_apply
/-- `PolynomialModule.single` as a linear map. -/
noncomputable def lsingle (i : ℕ) : M →ₗ[R] PolynomialModule R M :=
Finsupp.lsingle i
theorem lsingle_apply (i : ℕ) (m : M) (n : ℕ) : lsingle R i m n = ite (i = n) m 0 :=
Finsupp.single_apply
theorem single_smul (i : ℕ) (r : R) (m : M) : single R i (r • m) = r • single R i m :=
(lsingle R i).map_smul r m
variable {R}
@[elab_as_elim]
theorem induction_linear {motive : PolynomialModule R M → Prop} (f : PolynomialModule R M)
(zero : motive 0) (add : ∀ f g, motive f → motive g → motive (f + g))
(single : ∀ a b, motive (single R a b)) : motive f :=
Finsupp.induction_linear f zero add single
noncomputable instance polynomialModule : Module R[X] (PolynomialModule R M) :=
inferInstanceAs (Module R[X] (Module.AEval' (Finsupp.lmapDomain M R Nat.succ)))
lemma smul_def (f : R[X]) (m : PolynomialModule R M) :
f • m = aeval (Finsupp.lmapDomain M R Nat.succ) f m := by
rfl
instance (M : Type u) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower S R M] :
IsScalarTower S R (PolynomialModule R M) :=
Finsupp.isScalarTower _ _
instance isScalarTower' (M : Type u) [AddCommGroup M] [Module R M] [Module S M]
[IsScalarTower S R M] : IsScalarTower S R[X] (PolynomialModule R M) := by
haveI : IsScalarTower R R[X] (PolynomialModule R M) :=
inferInstanceAs <| IsScalarTower R R[X] <| Module.AEval' <| Finsupp.lmapDomain M R Nat.succ
constructor
intro x y z
rw [← @IsScalarTower.algebraMap_smul S R, ← @IsScalarTower.algebraMap_smul S R, smul_assoc]
@[simp]
theorem monomial_smul_single (i : ℕ) (r : R) (j : ℕ) (m : M) :
monomial i r • single R j m = single R (i + j) (r • m) := by
simp only [Module.End.mul_apply, Polynomial.aeval_monomial, Module.End.pow_apply,
Module.algebraMap_end_apply, smul_def]
induction i generalizing r j m with
| zero =>
rw [Function.iterate_zero, zero_add]
exact Finsupp.smul_single r j m
| succ n hn =>
rw [Function.iterate_succ, Function.comp_apply, add_assoc, ← hn]
congr 2
rw [Nat.one_add]
exact Finsupp.mapDomain_single
@[simp]
theorem monomial_smul_lsingle (i : ℕ) (r : R) (j : ℕ) (m : M) :
(monomial i) r • lsingle R j m = lsingle R (i + j) (r • m) :=
monomial_smul_single ..
@[simp]
theorem monomial_smul_apply (i : ℕ) (r : R) (g : PolynomialModule R M) (n : ℕ) :
(monomial i r • g) n = ite (i ≤ n) (r • g (n - i)) 0 := by
induction g using PolynomialModule.induction_linear with
| zero => simp only [smul_zero, zero_apply, ite_self]
| add p q hp hq =>
simp only [smul_add, add_apply, hp, hq]
split_ifs
exacts [rfl, zero_add 0]
| single =>
rw [monomial_smul_single, single_apply, single_apply, smul_ite, smul_zero, ← ite_and]
grind
@[simp]
theorem smul_single_apply (i : ℕ) (f : R[X]) (m : M) (n : ℕ) :
(f • single R i m) n = ite (i ≤ n) (f.coeff (n - i) • m) 0 := by
induction f using Polynomial.induction_on' with
| add p q hp hq =>
rw [add_smul, Finsupp.add_apply, hp, hq, coeff_add, add_smul]
split_ifs
exacts [rfl, zero_add 0]
| monomial => grind [monomial_smul_single, single_apply, coeff_monomial, zero_smul]
theorem smul_apply (f : R[X]) (g : PolynomialModule R M) (n : ℕ) :
(f • g) n = ∑ x ∈ Finset.antidiagonal n, f.coeff x.1 • g x.2 := by
induction f using Polynomial.induction_on' with
| add p q hp hq =>
rw [add_smul, Finsupp.add_apply, hp, hq, ← Finset.sum_add_distrib]
congr
ext
rw [coeff_add, add_smul]
| monomial f_n f_a =>
rw [Finset.Nat.sum_antidiagonal_eq_sum_range_succ fun i j => (monomial f_n f_a).coeff i • g j,
monomial_smul_apply]
simp_rw [Polynomial.coeff_monomial, ← Finset.mem_range_succ_iff]
simp
/-- `PolynomialModule R R` is isomorphic to `R[X]` as an `R[X]` module. -/
noncomputable def equivPolynomialSelf : PolynomialModule R R ≃ₗ[R[X]] R[X] :=
{ (Polynomial.toFinsuppIso R).symm with
map_smul' := fun r x => by
dsimp
rw [← RingEquiv.coe_toEquiv_symm, RingEquiv.coe_toEquiv]
induction x using induction_linear with
| zero => rw [smul_zero, map_zero, mul_zero]
| add _ _ hp hq => rw [smul_add, map_add, map_add, mul_add, hp, hq]
| single n a =>
ext i
simp only [coeff_ofFinsupp, smul_single_apply, toFinsuppIso_symm_apply, coeff_ofFinsupp,
single_apply, smul_eq_mul, Polynomial.coeff_mul, mul_ite, mul_zero]
split_ifs with hn
· rw [Finset.sum_eq_single (i - n, n)]
· simp only [ite_true]
· rintro ⟨p, q⟩ hpq1 hpq2
rw [Finset.mem_antidiagonal] at hpq1
split_ifs with H
· dsimp at H
exfalso
apply hpq2
rw [← hpq1, H]
simp only [add_tsub_cancel_right]
· rfl
· intro H
exfalso
apply H
rw [Finset.mem_antidiagonal, tsub_add_cancel_of_le hn]
· symm
rw [Finset.sum_ite_of_false, Finset.sum_const_zero]
grind [Finset.mem_antidiagonal] }
/-- `PolynomialModule R S` is isomorphic to `S[X]` as an `R` module. -/
noncomputable def equivPolynomial {S : Type*} [CommRing S] [Algebra R S] :
PolynomialModule R S ≃ₗ[R] S[X] :=
{ (Polynomial.toFinsuppIso S).symm with map_smul' := fun _ _ => rfl }
@[simp]
lemma equivPolynomialSelf_apply_eq (p : PolynomialModule R R) :
equivPolynomialSelf p = equivPolynomial p := rfl
@[simp]
lemma equivPolynomial_single {S : Type*} [CommRing S] [Algebra R S] (n : ℕ) (x : S) :
equivPolynomial (single R n x) = monomial n x := rfl
variable (R' : Type*) {M' : Type*} [CommRing R'] [AddCommGroup M'] [Module R' M']
variable [Module R M']
/-- Two `R`-linear maps from `PolynomialModule R M` which are equal
after pre-composition with every `lsingle R a` are equal. -/
@[ext high]
theorem hom_ext {f g : PolynomialModule R M →ₗ[R] M'}
(h : ∀ a, f ∘ₗ lsingle R a = g ∘ₗ lsingle R a) : f = g :=
Finsupp.lhom_ext' h
/-- The image of a polynomial under a linear map. -/
noncomputable def map (f : M →ₗ[R] M') : PolynomialModule R M →ₗ[R] PolynomialModule R' M' :=
Finsupp.mapRange.linearMap f
@[simp]
theorem map_single (f : M →ₗ[R] M') (i : ℕ) (m : M) : map R' f (single R i m) = single R' i (f m) :=
Finsupp.mapRange_single (hf := f.map_zero)
@[simp]
theorem map_lsingle (f : M →ₗ[R] M') (i : ℕ) (m : M) :
map R' f (lsingle R i m) = lsingle R' i (f m) :=
map_single ..
variable [Algebra R R'] [IsScalarTower R R' M']
theorem map_smul (f : M →ₗ[R] M') (p : R[X]) (q : PolynomialModule R M) :
map R' f (p • q) = p.map (algebraMap R R') • map R' f q := by
induction q using induction_linear with
| zero => rw [smul_zero, map_zero, smul_zero]
| add f g e₁ e₂ => rw [smul_add, map_add, e₁, e₂, map_add, smul_add]
| single i m =>
induction p using Polynomial.induction_on' with
| add _ _ e₁ e₂ => rw [add_smul, map_add, e₁, e₂, Polynomial.map_add, add_smul]
| monomial => rw [monomial_smul_single, map_single, Polynomial.map_monomial, map_single,
monomial_smul_single, f.map_smul, algebraMap_smul]
/-- Evaluate a polynomial `p : PolynomialModule R M` at `r : R`. -/
@[simps! -isSimp]
noncomputable def eval (r : R) : PolynomialModule R M →ₗ[R] M where
toFun p := p.sum fun i m => r ^ i • m
map_add' _ _ := Finsupp.sum_add_index' (fun _ => smul_zero _) fun _ _ _ => smul_add _ _ _
map_smul' s m := by
refine (Finsupp.sum_smul_index' ?_).trans ?_
· exact fun i => smul_zero _
· simp_rw [RingHom.id_apply, Finsupp.smul_sum]
congr
ext i c
rw [smul_comm]
@[simp]
theorem eval_single (r : R) (i : ℕ) (m : M) : eval r (single R i m) = r ^ i • m :=
Finsupp.sum_single_index (smul_zero _)
@[simp]
theorem eval_lsingle (r : R) (i : ℕ) (m : M) : eval r (lsingle R i m) = r ^ i • m :=
eval_single r i m
@[simp]
theorem eval_smul (p : R[X]) (q : PolynomialModule R M) (r : R) :
eval r (p • q) = p.eval r • eval r q := by
induction q using induction_linear with
| zero => rw [smul_zero, map_zero, smul_zero]
| add f g e₁ e₂ => rw [smul_add, map_add, e₁, e₂, map_add, smul_add]
| single i m =>
induction p using Polynomial.induction_on' with
| add _ _ e₁ e₂ => rw [add_smul, map_add, Polynomial.eval_add, e₁, e₂, add_smul]
| monomial => simp only [monomial_smul_single, Polynomial.eval_monomial, eval_single]; module
@[simp]
theorem eval_map (f : M →ₗ[R] M') (q : PolynomialModule R M) (r : R) :
eval (algebraMap R R' r) (map R' f q) = f (eval r q) := by
induction q using induction_linear with
| zero => simp_rw [map_zero]
| add f g e₁ e₂ => simp_rw [map_add, e₁, e₂]
| single i m => simp only [map_single, eval_single, f.map_smul]; module
@[simp]
theorem eval_map' (f : M →ₗ[R] M) (q : PolynomialModule R M) (r : R) :
eval r (map R f q) = f (eval r q) :=
eval_map R f q r
@[simp]
lemma aeval_equivPolynomial {S : Type*} [CommRing S] [Algebra S R]
(f : PolynomialModule S S) (x : R) :
aeval x (equivPolynomial f) = eval x (map R (Algebra.linearMap S R) f) := by
induction f using induction_linear with
| zero => simp
| add f g e₁ e₂ => simp_rw [map_add, e₁, e₂]
| single i m => rw [equivPolynomial_single, aeval_monomial, mul_comm, map_single,
Algebra.linearMap_apply, eval_single, smul_eq_mul]
/-- `comp p q` is the composition of `p : R[X]` and `q : M[X]` as `q(p(x))`. -/
@[simps!]
noncomputable def comp (p : R[X]) : PolynomialModule R M →ₗ[R] PolynomialModule R M :=
LinearMap.comp ((eval p).restrictScalars R) (map R[X] (lsingle R 0))
theorem comp_single (p : R[X]) (i : ℕ) (m : M) : comp p (single R i m) = p ^ i • single R 0 m := by
rw [comp_apply, map_single, eval_single]
rfl
theorem comp_eval (p : R[X]) (q : PolynomialModule R M) (r : R) :
eval r (comp p q) = eval (p.eval r) q := by
rw [← LinearMap.comp_apply]
induction q using induction_linear with
| zero => simp_rw [map_zero]
| add _ _ e₁ e₂ => simp_rw [map_add, e₁, e₂]
| single i m =>
rw [LinearMap.comp_apply, comp_single, eval_single, eval_smul, eval_single, eval_pow]
module
theorem comp_smul (p p' : R[X]) (q : PolynomialModule R M) :
comp p (p' • q) = p'.comp p • comp p q := by
rw [comp_apply, map_smul, eval_smul, Polynomial.comp, Polynomial.eval_map, comp_apply]
rfl
end PolynomialModule |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Module/AEval.lean | import Mathlib.Algebra.Module.Submodule.Invariant
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.LinearAlgebra.DFinsupp
import Mathlib.RingTheory.Finiteness.Basic
import Mathlib.RingTheory.Ideal.Maps
/-!
# Action of the polynomial ring on module induced by an algebra element.
Given an element `a` in an `R`-algebra `A` and an `A`-module `M` we define an
`R[X]`-module `Module.AEval R M a`, which is a type synonym of `M` with the
action of a polynomial `f` given by `f • m = Polynomial.aeval a f • m`.
In particular `X • m = a • m`.
In the special case that `A = M →ₗ[R] M` and `φ : M →ₗ[R] M`, the module `Module.AEval R M a` is
abbreviated `Module.AEval' φ`. In this module we have `X • m = ↑φ m`.
-/
open Set Function Polynomial
namespace Module
/--
Suppose `a` is an element of an `R`-algebra `A` and `M` is an `A`-module.
Loosely speaking, `Module.AEval R M a` is the `R[X]`-module with elements `m : M`,
where the action of a polynomial $f$ is given by $f • m = f(a) • m$.
More precisely, `Module.AEval R M a` has elements `Module.AEval.of R M a m` for `m : M`,
and the action of `f` is `f • (of R M a m) = of R M a ((aeval a f) • m)`.
-/
@[nolint unusedArguments]
def AEval (R M : Type*) {A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
[AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M] (_ : A) := M
instance AEval.instAddCommGroup {R A M} [CommSemiring R] [Semiring A] (a : A) [Algebra R A]
[AddCommGroup M] [Module A M] [Module R M] [IsScalarTower R A M] :
AddCommGroup <| AEval R M a := inferInstanceAs (AddCommGroup M)
variable {R A M} [CommSemiring R] [Semiring A] (a : A) [Algebra R A] [AddCommMonoid M] [Module A M]
[Module R M] [IsScalarTower R A M]
namespace AEval
instance instAddCommMonoid : AddCommMonoid <| AEval R M a := inferInstanceAs (AddCommMonoid M)
instance instModuleOrig : Module R <| AEval R M a := inferInstanceAs (Module R M)
instance instFiniteOrig [Module.Finite R M] : Module.Finite R <| AEval R M a :=
‹Module.Finite R M›
instance instModulePolynomial : Module R[X] <| AEval R M a := compHom M (aeval a).toRingHom
variable (R M)
/--
The canonical linear equivalence between `M` and `Module.AEval R M a` as an `R`-module.
-/
def of : M ≃ₗ[R] AEval R M a :=
LinearEquiv.refl _ _
variable {R M}
lemma of_aeval_smul (f : R[X]) (m : M) : of R M a (aeval a f • m) = f • of R M a m := rfl
@[simp] lemma of_symm_smul (f : R[X]) (m : AEval R M a) :
(of R M a).symm (f • m) = aeval a f • (of R M a).symm m := rfl
@[simp] lemma C_smul (t : R) (m : AEval R M a) : C t • m = t • m :=
(of R M a).symm.injective <| by simp
lemma X_smul_of (m : M) : (X : R[X]) • (of R M a m) = of R M a (a • m) := by
rw [← of_aeval_smul, aeval_X]
lemma X_pow_smul_of (m : M) (n : ℕ) : (X ^ n : R[X]) • (of R M a m) = of R M a (a ^ n • m) := by
rw [← of_aeval_smul, aeval_X_pow]
lemma of_symm_X_smul (m : AEval R M a) :
(of R M a).symm ((X : R[X]) • m) = a • (of R M a).symm m := by
rw [of_symm_smul, aeval_X]
instance instIsScalarTowerOrigPolynomial : IsScalarTower R R[X] <| AEval R M a where
smul_assoc r f m := by
apply (of R M a).symm.injective
rw [of_symm_smul, map_smul, smul_assoc, map_smul, of_symm_smul]
instance instFinitePolynomial [Module.Finite R M] : Module.Finite R[X] <| AEval R M a :=
Finite.of_restrictScalars_finite R _ _
/-- Construct an `R[X]`-linear map out of `AEval R M a` from a `R`-linear map out of `M`. -/
def _root_.LinearMap.ofAEval {N} [AddCommMonoid N] [Module R N] [Module R[X] N]
[IsScalarTower R R[X] N] (f : M →ₗ[R] N) (hf : ∀ m : M, f (a • m) = (X : R[X]) • f m) :
AEval R M a →ₗ[R[X]] N where
__ := f ∘ₗ (of R M a).symm
map_smul' p := p.induction_on (fun k m ↦ by simp [C_eq_algebraMap])
(fun p q hp hq m ↦ by simp_all [add_smul]) fun n k h m ↦ by
simp_rw [RingHom.id_apply, AddHom.toFun_eq_coe, LinearMap.coe_toAddHom,
LinearMap.comp_apply, LinearEquiv.coe_toLinearMap] at h ⊢
simp_rw [pow_succ, ← mul_assoc, mul_smul _ X, ← hf, ← of_symm_X_smul, ← h]
/-- Construct an `R[X]`-linear equivalence out of `AEval R M a` from a `R`-linear map out of `M`. -/
def _root_.LinearEquiv.ofAEval {N} [AddCommMonoid N] [Module R N] [Module R[X] N]
[IsScalarTower R R[X] N] (f : M ≃ₗ[R] N) (hf : ∀ m : M, f (a • m) = (X : R[X]) • f m) :
AEval R M a ≃ₗ[R[X]] N where
__ := LinearMap.ofAEval a f hf
invFun := (of R M a) ∘ f.symm
left_inv x := by simp [LinearMap.ofAEval]
right_inv x := by simp [LinearMap.ofAEval]
lemma annihilator_eq_ker_aeval [FaithfulSMul A M] :
annihilator R[X] (AEval R M a) = RingHom.ker (aeval a) := by
ext p
simp_rw [mem_annihilator, RingHom.mem_ker]
change (∀ m : M, aeval a p • m = 0) ↔ _
exact ⟨fun h ↦ eq_of_smul_eq_smul (α := M) <| by simp [h], fun h ↦ by simp [h]⟩
@[simp]
lemma annihilator_top_eq_ker_aeval [FaithfulSMul A M] :
(⊤ : Submodule R[X] <| AEval R M a).annihilator = RingHom.ker (aeval a) := by
ext p
simp only [Submodule.mem_annihilator, Submodule.mem_top, forall_true_left, RingHom.mem_ker]
change (∀ m : M, aeval a p • m = 0) ↔ _
exact ⟨fun h ↦ eq_of_smul_eq_smul (α := M) <| by simp [h], fun h ↦ by simp [h]⟩
section Submodule
variable (R M)
/-- The natural order isomorphism between the two ways to represent invariant submodules. -/
def mapSubmodule :
(Algebra.lsmul R R M a).invtSubmodule ≃o Submodule R[X] (AEval R M a) where
toFun p :=
{ toAddSubmonoid := (p : Submodule R M).toAddSubmonoid.map (of R M a)
smul_mem' := by
rintro f - ⟨m : M, h : m ∈ (p : Submodule R M), rfl⟩
simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup,
AddSubmonoid.mem_map, Submodule.mem_toAddSubmonoid]
exact ⟨aeval a f • m, aeval_apply_smul_mem_of_le_comap' h f a p.2, of_aeval_smul a f m⟩ }
invFun q := ⟨(Submodule.orderIsoMapComap (of R M a)).symm (q.restrictScalars R), fun m hm ↦ by
simpa [← X_smul_of] using q.smul_mem (X : R[X]) hm⟩
left_inv p := by ext; simp
right_inv q := by ext; aesop
map_rel_iff' {p p'} := ⟨fun h x hx ↦ by aesop (rule_sets := [SetLike!]), fun h x hx ↦ by aesop⟩
@[simp] lemma mem_mapSubmodule_apply {p : (Algebra.lsmul R R M a).invtSubmodule} {m : AEval R M a} :
m ∈ mapSubmodule R M a p ↔ (of R M a).symm m ∈ (p : Submodule R M) :=
⟨fun ⟨_, hm, hm'⟩ ↦ hm'.symm ▸ hm, fun hm ↦ ⟨(of R M a).symm m, hm, rfl⟩⟩
@[simp] lemma mem_mapSubmodule_symm_apply {q : Submodule R[X] (AEval R M a)} {m : M} :
m ∈ ((mapSubmodule R M a).symm q : Submodule R M) ↔ of R M a m ∈ q :=
Iff.rfl
variable {R M}
variable (p : Submodule R M) (hp : p ∈ (Algebra.lsmul R R M a).invtSubmodule)
/-- The natural `R`-linear equivalence between the two ways to represent an invariant submodule. -/
def equiv_mapSubmodule :
p ≃ₗ[R] mapSubmodule R M a ⟨p, hp⟩ where
toFun x := ⟨of R M a x, by simp⟩
invFun x := ⟨((of R M _).symm (x : AEval R M a)), by obtain ⟨x, hx⟩ := x; simpa using hx⟩
map_add' x y := rfl
map_smul' t x := rfl
/-- The natural `R[X]`-linear equivalence between the two ways to represent an invariant submodule.
-/
noncomputable def restrict_equiv_mapSubmodule :
(AEval R p <| (Algebra.lsmul R R M a).restrict hp) ≃ₗ[R[X]] mapSubmodule R M a ⟨p, hp⟩ :=
LinearEquiv.ofAEval ((Algebra.lsmul R R M a).restrict hp) (equiv_mapSubmodule a p hp)
(fun x ↦ by simp [equiv_mapSubmodule, X_smul_of])
end Submodule
end AEval
variable (φ : M →ₗ[R] M)
/--
Given and `R`-module `M` and a linear map `φ : M →ₗ[R] M`, `Module.AEval' φ` is loosely speaking
the `R[X]`-module with elements `m : M`, where the action of a polynomial $f$ is given by
$f • m = f(a) • m$.
More precisely, `Module.AEval' φ` has elements `Module.AEval'.of φ m` for `m : M`,
and the action of `f` is `f • (of φ m) = of φ ((aeval φ f) • m)`.
`Module.AEval'` is defined as a special case of `Module.AEval` in which the `R`-algebra is
`M →ₗ[R] M`. Lemmas involving `Module.AEval` may be applied to `Module.AEval'`.
-/
abbrev AEval' := AEval R M φ
/--
The canonical linear equivalence between `M` and `Module.AEval' φ` as an `R`-module,
where `φ : M →ₗ[R] M`.
-/
abbrev AEval'.of : M ≃ₗ[R] AEval' φ := AEval.of R M φ
lemma AEval'_def : AEval' φ = AEval R M φ := rfl
lemma AEval'.X_smul_of (m : M) : (X : R[X]) • AEval'.of φ m = AEval'.of φ (φ m) :=
AEval.X_smul_of _ _
lemma AEval'.X_pow_smul_of (m : M) (n : ℕ) : (X ^ n : R[X]) • AEval'.of φ m = .of φ (φ ^ n • m) :=
AEval.X_pow_smul_of ..
lemma AEval'.of_symm_X_smul (m : AEval' φ) :
(AEval'.of φ).symm ((X : R[X]) • m) = φ ((AEval'.of φ).symm m) := AEval.of_symm_X_smul _ _
instance [Module.Finite R M] : Module.Finite R[X] <| AEval' φ := inferInstance
end Module |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Module/FiniteDimensional.lean | import Mathlib.FieldTheory.Minpoly.Field
import Mathlib.Algebra.Polynomial.Module.AEval
import Mathlib.Algebra.Module.Torsion.Basic
/-!
# Polynomial modules in finite dimensions
This file is a place to collect results about the `R[X]`-module structure induced on an `R`-module
by an `R`-linear endomorphism, which require the concept of finite-dimensionality.
## Main results:
* `Module.AEval.isTorsion_of_finiteDimensional`: if a vector space `M` with coefficients in a field
`K` carries a natural `K`-linear endomorphism which belongs to a finite-dimensional algebra
over `K`, then the induced `K[X]`-module structure on `M` is pure torsion.
-/
open Polynomial
variable {R K M A : Type*} {a : A}
namespace Module.AEval
theorem isTorsion_of_aeval_eq_zero [CommSemiring R] [NoZeroDivisors R] [Semiring A] [Algebra R A]
[AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]
{p : R[X]} (h : aeval a p = 0) (h' : p ≠ 0) :
IsTorsion R[X] (AEval R M a) := by
have hp : p ∈ nonZeroDivisors R[X] := mem_nonZeroDivisors_iff_right.mpr
fun q hq ↦ Or.resolve_right (mul_eq_zero.mp hq) h'
exact fun x ↦ ⟨⟨p, hp⟩, (of R M a).symm.injective <| by simp [h]⟩
variable (K M a)
theorem isTorsion_of_finiteDimensional [Field K] [Ring A] [Algebra K A]
[AddCommGroup M] [Module A M] [Module K M] [IsScalarTower K A M] [FiniteDimensional K A] :
IsTorsion K[X] (AEval K M a) :=
isTorsion_of_aeval_eq_zero (minpoly.aeval K a) (minpoly.ne_zero_of_finite K a)
end Module.AEval |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/TrailingDegree.lean | import Mathlib.Algebra.Polynomial.Degree.Support
import Mathlib.Data.ENat.Basic
/-!
# Trailing degree of univariate polynomials
## Main definitions
* `trailingDegree p`: the multiplicity of `X` in the polynomial `p`
* `natTrailingDegree`: a variant of `trailingDegree` that takes values in the natural numbers
* `trailingCoeff`: the coefficient at index `natTrailingDegree p`
Converts most results about `degree`, `natDegree` and `leadingCoeff` to results about the bottom
end of a polynomial
-/
noncomputable section
open Function Polynomial Finsupp Finset
open scoped Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `trailingDegree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest
`X`-exponent in `p`.
`trailingDegree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears
in `p`, otherwise
`trailingDegree 0 = ⊤`. -/
def trailingDegree (p : R[X]) : ℕ∞ :=
p.support.min
theorem trailingDegree_lt_wf : WellFounded fun p q : R[X] => trailingDegree p < trailingDegree q :=
InvImage.wf trailingDegree wellFounded_lt
/-- `natTrailingDegree p` forces `trailingDegree p` to `ℕ`, by defining
`natTrailingDegree ⊤ = 0`. -/
def natTrailingDegree (p : R[X]) : ℕ :=
ENat.toNat (trailingDegree p)
/-- `trailingCoeff p` gives the coefficient of the smallest power of `X` in `p`. -/
def trailingCoeff (p : R[X]) : R :=
coeff p (natTrailingDegree p)
/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/
def TrailingMonic (p : R[X]) :=
trailingCoeff p = (1 : R)
theorem TrailingMonic.def : TrailingMonic p ↔ trailingCoeff p = 1 :=
Iff.rfl
instance TrailingMonic.decidable [DecidableEq R] : Decidable (TrailingMonic p) :=
inferInstanceAs <| Decidable (trailingCoeff p = (1 : R))
@[simp]
theorem TrailingMonic.trailingCoeff {p : R[X]} (hp : p.TrailingMonic) : trailingCoeff p = 1 :=
hp
@[simp]
theorem trailingDegree_zero : trailingDegree (0 : R[X]) = ⊤ :=
rfl
@[simp]
theorem trailingCoeff_zero : trailingCoeff (0 : R[X]) = 0 :=
rfl
@[simp]
theorem natTrailingDegree_zero : natTrailingDegree (0 : R[X]) = 0 :=
rfl
@[simp]
theorem trailingDegree_eq_top : trailingDegree p = ⊤ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.min_eq_top.1 h), fun h => by simp [h]⟩
theorem trailingDegree_eq_natTrailingDegree (hp : p ≠ 0) :
trailingDegree p = (natTrailingDegree p : ℕ∞) :=
.symm <| ENat.coe_toNat <| mt trailingDegree_eq_top.1 hp
theorem trailingDegree_eq_iff_natTrailingDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.trailingDegree = n ↔ p.natTrailingDegree = n := by
rw [trailingDegree_eq_natTrailingDegree hp, Nat.cast_inj]
theorem trailingDegree_eq_iff_natTrailingDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : n ≠ 0) :
p.trailingDegree = n ↔ p.natTrailingDegree = n := by
rw [natTrailingDegree, ENat.toNat_eq_iff hn]
theorem natTrailingDegree_eq_of_trailingDegree_eq_some {p : R[X]} {n : ℕ}
(h : trailingDegree p = n) : natTrailingDegree p = n := by
simp [natTrailingDegree, h]
@[simp]
theorem natTrailingDegree_le_trailingDegree : ↑(natTrailingDegree p) ≤ trailingDegree p :=
ENat.coe_toNat_le_self _
theorem natTrailingDegree_eq_of_trailingDegree_eq [Semiring S] {q : S[X]}
(h : trailingDegree p = trailingDegree q) : natTrailingDegree p = natTrailingDegree q := by
unfold natTrailingDegree
rw [h]
theorem trailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : trailingDegree p ≤ n :=
min_le (mem_support_iff.2 h)
theorem natTrailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : natTrailingDegree p ≤ n :=
ENat.toNat_le_of_le_coe <| trailingDegree_le_of_ne_zero h
@[simp] lemma coeff_natTrailingDegree_eq_zero : coeff p p.natTrailingDegree = 0 ↔ p = 0 := by
constructor
· rintro h
by_contra hp
obtain ⟨n, hpn, hn⟩ := by simpa using min_mem_image_coe <| support_nonempty.2 hp
obtain rfl := (trailingDegree_eq_iff_natTrailingDegree_eq hp).1 hn.symm
exact hpn h
· rintro rfl
simp
lemma coeff_natTrailingDegree_ne_zero : coeff p p.natTrailingDegree ≠ 0 ↔ p ≠ 0 :=
coeff_natTrailingDegree_eq_zero.not
@[simp]
lemma trailingDegree_eq_zero : trailingDegree p = 0 ↔ coeff p 0 ≠ 0 :=
Finset.min_eq_bot.trans mem_support_iff
@[simp] lemma natTrailingDegree_eq_zero : natTrailingDegree p = 0 ↔ p = 0 ∨ coeff p 0 ≠ 0 := by
simp [natTrailingDegree, or_comm]
lemma natTrailingDegree_ne_zero : natTrailingDegree p ≠ 0 ↔ p ≠ 0 ∧ coeff p 0 = 0 :=
natTrailingDegree_eq_zero.not.trans <| by rw [not_or, not_ne_iff]
lemma trailingDegree_ne_zero : trailingDegree p ≠ 0 ↔ coeff p 0 = 0 :=
trailingDegree_eq_zero.not_left
@[simp] theorem trailingDegree_le_trailingDegree (h : coeff q (natTrailingDegree p) ≠ 0) :
trailingDegree q ≤ trailingDegree p :=
(trailingDegree_le_of_ne_zero h).trans natTrailingDegree_le_trailingDegree
theorem trailingDegree_ne_of_natTrailingDegree_ne {n : ℕ} :
p.natTrailingDegree ≠ n → trailingDegree p ≠ n :=
mt fun h => by rw [natTrailingDegree, h, ENat.toNat_coe]
theorem natTrailingDegree_le_of_trailingDegree_le {n : ℕ} {hp : p ≠ 0}
(H : (n : ℕ∞) ≤ trailingDegree p) : n ≤ natTrailingDegree p := by
rwa [trailingDegree_eq_natTrailingDegree hp, Nat.cast_le] at H
theorem natTrailingDegree_le_natTrailingDegree (hq : q ≠ 0)
(hpq : p.trailingDegree ≤ q.trailingDegree) : p.natTrailingDegree ≤ q.natTrailingDegree :=
ENat.toNat_le_toNat hpq <| by simpa
@[simp]
theorem trailingDegree_monomial (ha : a ≠ 0) : trailingDegree (monomial n a) = n := by
rw [trailingDegree, support_monomial n ha, min_singleton]
rfl
theorem natTrailingDegree_monomial (ha : a ≠ 0) : natTrailingDegree (monomial n a) = n := by
rw [natTrailingDegree, trailingDegree_monomial ha]
rfl
theorem natTrailingDegree_monomial_le : natTrailingDegree (monomial n a) ≤ n :=
letI := Classical.decEq R
if ha : a = 0 then by simp [ha] else (natTrailingDegree_monomial ha).le
theorem le_trailingDegree_monomial : ↑n ≤ trailingDegree (monomial n a) :=
letI := Classical.decEq R
if ha : a = 0 then by simp [ha] else (trailingDegree_monomial ha).ge
@[simp]
theorem trailingDegree_C (ha : a ≠ 0) : trailingDegree (C a) = (0 : ℕ∞) :=
trailingDegree_monomial ha
theorem le_trailingDegree_C : (0 : ℕ∞) ≤ trailingDegree (C a) :=
le_trailingDegree_monomial
theorem trailingDegree_one_le : (0 : ℕ∞) ≤ trailingDegree (1 : R[X]) := by
rw [← C_1]
exact le_trailingDegree_C
@[simp]
theorem natTrailingDegree_C (a : R) : natTrailingDegree (C a) = 0 :=
nonpos_iff_eq_zero.1 natTrailingDegree_monomial_le
@[simp]
theorem natTrailingDegree_one : natTrailingDegree (1 : R[X]) = 0 :=
natTrailingDegree_C 1
@[simp]
theorem natTrailingDegree_natCast (n : ℕ) : natTrailingDegree (n : R[X]) = 0 := by
simp only [← C_eq_natCast, natTrailingDegree_C]
@[simp]
theorem trailingDegree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : trailingDegree (C a * X ^ n) = n := by
rw [C_mul_X_pow_eq_monomial, trailingDegree_monomial ha]
theorem le_trailingDegree_C_mul_X_pow (n : ℕ) (a : R) :
(n : ℕ∞) ≤ trailingDegree (C a * X ^ n) := by
rw [C_mul_X_pow_eq_monomial]
exact le_trailingDegree_monomial
theorem coeff_eq_zero_of_lt_trailingDegree (h : (n : ℕ∞) < trailingDegree p) : coeff p n = 0 :=
Classical.not_not.1 (mt trailingDegree_le_of_ne_zero (not_le_of_gt h))
theorem coeff_eq_zero_of_lt_natTrailingDegree {p : R[X]} {n : ℕ} (h : n < p.natTrailingDegree) :
p.coeff n = 0 := by
apply coeff_eq_zero_of_lt_trailingDegree
by_cases hp : p = 0
· rw [hp, trailingDegree_zero]
exact WithTop.coe_lt_top n
· rw [trailingDegree_eq_natTrailingDegree hp]
exact WithTop.coe_lt_coe.2 h
@[simp]
theorem coeff_natTrailingDegree_pred_eq_zero {p : R[X]} {hp : (0 : ℕ∞) < natTrailingDegree p} :
p.coeff (p.natTrailingDegree - 1) = 0 :=
coeff_eq_zero_of_lt_natTrailingDegree <|
Nat.sub_lt (WithTop.coe_pos.mp hp) Nat.one_pos
theorem le_trailingDegree_X_pow (n : ℕ) : (n : ℕ∞) ≤ trailingDegree (X ^ n : R[X]) := by
simpa only [C_1, one_mul] using le_trailingDegree_C_mul_X_pow n (1 : R)
theorem le_trailingDegree_X : (1 : ℕ∞) ≤ trailingDegree (X : R[X]) :=
le_trailingDegree_monomial
theorem natTrailingDegree_X_le : (X : R[X]).natTrailingDegree ≤ 1 :=
natTrailingDegree_monomial_le
@[simp]
theorem trailingCoeff_eq_zero : trailingCoeff p = 0 ↔ p = 0 :=
⟨fun h =>
_root_.by_contradiction fun hp =>
mt mem_support_iff.1 (Classical.not_not.2 h)
(mem_of_min (trailingDegree_eq_natTrailingDegree hp)),
fun h => h.symm ▸ leadingCoeff_zero⟩
theorem trailingCoeff_nonzero_iff_nonzero : trailingCoeff p ≠ 0 ↔ p ≠ 0 :=
not_congr trailingCoeff_eq_zero
theorem natTrailingDegree_mem_support_of_nonzero : p ≠ 0 → natTrailingDegree p ∈ p.support :=
mem_support_iff.mpr ∘ trailingCoeff_nonzero_iff_nonzero.mpr
theorem natTrailingDegree_le_of_mem_supp (a : ℕ) : a ∈ p.support → natTrailingDegree p ≤ a :=
natTrailingDegree_le_of_ne_zero ∘ mem_support_iff.mp
theorem natTrailingDegree_eq_support_min' (h : p ≠ 0) :
natTrailingDegree p = p.support.min' (nonempty_support_iff.mpr h) := by
rw [natTrailingDegree, trailingDegree, ← Finset.coe_min', ENat.some_eq_coe, ENat.toNat_coe]
theorem le_natTrailingDegree (hp : p ≠ 0) (hn : ∀ m < n, p.coeff m = 0) :
n ≤ p.natTrailingDegree := by
rw [natTrailingDegree_eq_support_min' hp]
exact Finset.le_min' _ _ _ fun m hm => not_lt.1 fun hmn => mem_support_iff.1 hm <| hn _ hmn
theorem natTrailingDegree_le_natDegree (p : R[X]) : p.natTrailingDegree ≤ p.natDegree := by
by_cases hp : p = 0
· rw [hp, natDegree_zero, natTrailingDegree_zero]
· exact le_natDegree_of_ne_zero (mt trailingCoeff_eq_zero.mp hp)
theorem natTrailingDegree_mul_X_pow {p : R[X]} (hp : p ≠ 0) (n : ℕ) :
(p * X ^ n).natTrailingDegree = p.natTrailingDegree + n := by
apply le_antisymm
· refine natTrailingDegree_le_of_ne_zero fun h => mt trailingCoeff_eq_zero.mp hp ?_
rwa [trailingCoeff, ← coeff_mul_X_pow]
· rw [natTrailingDegree_eq_support_min' fun h => hp (mul_X_pow_eq_zero h), Finset.le_min'_iff]
intro y hy
have key : n ≤ y := by
rw [mem_support_iff, coeff_mul_X_pow'] at hy
exact by_contra fun h => hy (if_neg h)
rw [mem_support_iff, coeff_mul_X_pow', if_pos key] at hy
exact (le_tsub_iff_right key).mp (natTrailingDegree_le_of_ne_zero hy)
theorem le_trailingDegree_mul : p.trailingDegree + q.trailingDegree ≤ (p * q).trailingDegree := by
refine Finset.le_min fun n hn => ?_
rw [mem_support_iff, coeff_mul] at hn
obtain ⟨⟨i, j⟩, hij, hpq⟩ := exists_ne_zero_of_sum_ne_zero hn
refine
(add_le_add (min_le (mem_support_iff.mpr (left_ne_zero_of_mul hpq)))
(min_le (mem_support_iff.mpr (right_ne_zero_of_mul hpq)))).trans_eq ?_
rwa [← WithTop.coe_add, WithTop.coe_eq_coe, ← mem_antidiagonal]
theorem le_natTrailingDegree_mul (h : p * q ≠ 0) :
p.natTrailingDegree + q.natTrailingDegree ≤ (p * q).natTrailingDegree := by
have hp : p ≠ 0 := fun hp => h (by rw [hp, zero_mul])
have hq : q ≠ 0 := fun hq => h (by rw [hq, mul_zero])
rw [← WithTop.coe_le_coe, WithTop.coe_add, ← Nat.cast_withTop (natTrailingDegree p),
← Nat.cast_withTop (natTrailingDegree q), ← Nat.cast_withTop (natTrailingDegree (p * q)),
← trailingDegree_eq_natTrailingDegree hp, ← trailingDegree_eq_natTrailingDegree hq,
← trailingDegree_eq_natTrailingDegree h]
exact le_trailingDegree_mul
theorem coeff_mul_natTrailingDegree_add_natTrailingDegree : (p * q).coeff
(p.natTrailingDegree + q.natTrailingDegree) = p.trailingCoeff * q.trailingCoeff := by
rw [coeff_mul]
refine
Finset.sum_eq_single (p.natTrailingDegree, q.natTrailingDegree) ?_ fun h =>
(h (mem_antidiagonal.mpr rfl)).elim
rintro ⟨i, j⟩ h₁ h₂
rw [mem_antidiagonal] at h₁
by_cases! hi : i < p.natTrailingDegree
· rw [coeff_eq_zero_of_lt_natTrailingDegree hi, zero_mul]
by_cases! hj : j < q.natTrailingDegree
· rw [coeff_eq_zero_of_lt_natTrailingDegree hj, mul_zero]
refine (h₂ (Prod.ext_iff.mpr ?_).symm).elim
exact (add_eq_add_iff_eq_and_eq hi hj).mp h₁.symm
theorem trailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff ≠ 0) :
(p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by
have hp : p ≠ 0 := fun hp => h (by rw [hp, trailingCoeff_zero, zero_mul])
have hq : q ≠ 0 := fun hq => h (by rw [hq, trailingCoeff_zero, mul_zero])
refine le_antisymm ?_ le_trailingDegree_mul
rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq, ←
ENat.coe_add]
apply trailingDegree_le_of_ne_zero
rwa [coeff_mul_natTrailingDegree_add_natTrailingDegree]
theorem natTrailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff ≠ 0) :
(p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree := by
have hp : p ≠ 0 := fun hp => h (by rw [hp, trailingCoeff_zero, zero_mul])
have hq : q ≠ 0 := fun hq => h (by rw [hq, trailingCoeff_zero, mul_zero])
apply natTrailingDegree_eq_of_trailingDegree_eq_some
rw [trailingDegree_mul' h, Nat.cast_withTop (natTrailingDegree p + natTrailingDegree q),
WithTop.coe_add, ← Nat.cast_withTop, ← Nat.cast_withTop,
← trailingDegree_eq_natTrailingDegree hp, ← trailingDegree_eq_natTrailingDegree hq]
theorem natTrailingDegree_mul [NoZeroDivisors R] (hp : p ≠ 0) (hq : q ≠ 0) :
(p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree :=
natTrailingDegree_mul'
(mul_ne_zero (mt trailingCoeff_eq_zero.mp hp) (mt trailingCoeff_eq_zero.mp hq))
end Semiring
section NonzeroSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem trailingDegree_one : trailingDegree (1 : R[X]) = (0 : ℕ∞) :=
trailingDegree_C one_ne_zero
@[simp]
theorem trailingDegree_X : trailingDegree (X : R[X]) = 1 :=
trailingDegree_monomial one_ne_zero
@[simp]
theorem natTrailingDegree_X : (X : R[X]).natTrailingDegree = 1 :=
natTrailingDegree_monomial one_ne_zero
@[simp]
lemma trailingDegree_X_pow (n : ℕ) :
(X ^ n : R[X]).trailingDegree = n := by
rw [X_pow_eq_monomial, trailingDegree_monomial one_ne_zero]
@[simp]
lemma natTrailingDegree_X_pow (n : ℕ) :
(X ^ n : R[X]).natTrailingDegree = n := by
rw [X_pow_eq_monomial, natTrailingDegree_monomial one_ne_zero]
end NonzeroSemiring
section Ring
variable [Ring R]
@[simp]
theorem trailingDegree_neg (p : R[X]) : trailingDegree (-p) = trailingDegree p := by
unfold trailingDegree
rw [support_neg]
@[simp]
theorem natTrailingDegree_neg (p : R[X]) : natTrailingDegree (-p) = natTrailingDegree p := by
simp [natTrailingDegree]
@[simp]
theorem natTrailingDegree_intCast (n : ℤ) : natTrailingDegree (n : R[X]) = 0 := by
simp only [← C_eq_intCast, natTrailingDegree_C]
end Ring
section Semiring
variable [Semiring R]
/-- The second-lowest coefficient, or 0 for constants -/
def nextCoeffUp (p : R[X]) : R :=
if p.natTrailingDegree = 0 then 0 else p.coeff (p.natTrailingDegree + 1)
@[simp] lemma nextCoeffUp_zero : nextCoeffUp (0 : R[X]) = 0 := by simp [nextCoeffUp]
@[simp]
theorem nextCoeffUp_C_eq_zero (c : R) : nextCoeffUp (C c) = 0 := by
rw [nextCoeffUp]
simp
theorem nextCoeffUp_of_constantCoeff_eq_zero (p : R[X]) (hp : coeff p 0 = 0) :
nextCoeffUp p = p.coeff (p.natTrailingDegree + 1) := by
obtain rfl | hp₀ := eq_or_ne p 0
· simp
· rw [nextCoeffUp, if_neg (natTrailingDegree_ne_zero.2 ⟨hp₀, hp⟩)]
end Semiring
section Semiring
variable [Semiring R] {p q : R[X]}
theorem coeff_natTrailingDegree_eq_zero_of_trailingDegree_lt
(h : trailingDegree p < trailingDegree q) : coeff q (natTrailingDegree p) = 0 :=
coeff_eq_zero_of_lt_trailingDegree <| natTrailingDegree_le_trailingDegree.trans_lt h
theorem ne_zero_of_trailingDegree_lt {n : ℕ∞} (h : trailingDegree p < n) : p ≠ 0 := fun h₀ =>
h.not_ge (by simp [h₀])
lemma natTrailingDegree_eq_zero_of_constantCoeff_ne_zero (h : constantCoeff p ≠ 0) :
p.natTrailingDegree = 0 :=
le_antisymm (natTrailingDegree_le_of_ne_zero h) zero_le'
namespace Monic
lemma eq_X_pow_iff_natDegree_le_natTrailingDegree (h₁ : p.Monic) :
p = X ^ p.natDegree ↔ p.natDegree ≤ p.natTrailingDegree := by
refine ⟨fun h => ?_, fun h => ?_⟩
· nontriviality R
rw [h, natTrailingDegree_X_pow, ← h]
· ext n
rw [coeff_X_pow]
obtain hn | rfl | hn := lt_trichotomy n p.natDegree
· rw [if_neg hn.ne, coeff_eq_zero_of_lt_natTrailingDegree (hn.trans_le h)]
· simpa only [if_pos rfl] using h₁.leadingCoeff
· rw [if_neg hn.ne', coeff_eq_zero_of_natDegree_lt hn]
lemma eq_X_pow_iff_natTrailingDegree_eq_natDegree (h₁ : p.Monic) :
p = X ^ p.natDegree ↔ p.natTrailingDegree = p.natDegree :=
h₁.eq_X_pow_iff_natDegree_le_natTrailingDegree.trans (natTrailingDegree_le_natDegree p).ge_iff_eq
end Monic
end Semiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/CardPowDegree.lean | import Mathlib.Algebra.Order.AbsoluteValue.Euclidean
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Algebra.Polynomial.FieldDivision
/-!
# Absolute value on polynomials over a finite field.
Let `𝔽_q` be a finite field of cardinality `q`, then the map sending a polynomial `p`
to `q ^ degree p` (where `q ^ degree 0 = 0`) is an absolute value.
## Main definitions
* `Polynomial.cardPowDegree` is an absolute value on `𝔽_q[t]`, the ring of
polynomials over a finite field of cardinality `q`, mapping a polynomial `p`
to `q ^ degree p` (where `q ^ degree 0 = 0`)
## Main results
* `Polynomial.cardPowDegree_isEuclidean`: `cardPowDegree` respects the
Euclidean domain structure on the ring of polynomials
-/
namespace Polynomial
variable {Fq : Type*} [Field Fq] [Fintype Fq]
open AbsoluteValue
open Polynomial
/-- `cardPowDegree` is the absolute value on `𝔽_q[t]` sending `f` to `q ^ degree f`.
`cardPowDegree 0` is defined to be `0`. -/
noncomputable def cardPowDegree : AbsoluteValue Fq[X] ℤ :=
have card_pos : 0 < Fintype.card Fq := Fintype.card_pos_iff.mpr inferInstance
have pow_pos : ∀ n, 0 < (Fintype.card Fq : ℤ) ^ n := fun n =>
pow_pos (Int.natCast_pos.mpr card_pos) n
letI := Classical.decEq Fq
{ toFun := fun p => if p = 0 then 0 else (Fintype.card Fq : ℤ) ^ p.natDegree
nonneg' := fun p => by
split_ifs
· rfl
exact pow_nonneg (Int.ofNat_zero_le _) _
eq_zero' := fun p =>
ite_eq_left_iff.trans
⟨fun h => by
contrapose! h
exact ⟨h, (pow_pos _).ne'⟩, absurd⟩
add_le' := fun p q => by
by_cases hp : p = 0; · simp [hp]
by_cases hq : q = 0; · simp [hq]
by_cases hpq : p + q = 0
· simp only [hpq, hp, hq, if_true, if_false]
exact add_nonneg (pow_pos _).le (pow_pos _).le
simp only [hpq, hp, hq, if_false]
exact le_trans (pow_right_mono₀ (by cutsat) (Polynomial.natDegree_add_le _ _)) (by grind)
map_mul' := fun p q => by
by_cases hp : p = 0; · simp [hp]
by_cases hq : q = 0; · simp [hq]
have hpq : p * q ≠ 0 := mul_ne_zero hp hq
simp only [hpq, hp, hq, if_false, Polynomial.natDegree_mul hp hq, pow_add] }
theorem cardPowDegree_apply [DecidableEq Fq] (p : Fq[X]) :
cardPowDegree p = if p = 0 then 0 else (Fintype.card Fq : ℤ) ^ natDegree p := by
rw [cardPowDegree]
dsimp
convert rfl
@[simp]
theorem cardPowDegree_zero : cardPowDegree (0 : Fq[X]) = 0 := rfl
@[simp]
theorem cardPowDegree_nonzero (p : Fq[X]) (hp : p ≠ 0) :
cardPowDegree p = (Fintype.card Fq : ℤ) ^ p.natDegree :=
if_neg hp
theorem cardPowDegree_isEuclidean : IsEuclidean (cardPowDegree : AbsoluteValue Fq[X] ℤ) :=
have card_pos : 0 < Fintype.card Fq := Fintype.card_pos_iff.mpr inferInstance
have pow_pos : ∀ n, 0 < (Fintype.card Fq : ℤ) ^ n := fun n =>
pow_pos (Int.natCast_pos.mpr card_pos) n
{ map_lt_map_iff' := fun {p q} => by
classical
change cardPowDegree p < cardPowDegree q ↔ degree p < degree q
simp only [cardPowDegree_apply]
split_ifs with hp hq hq
· simp only [hp, hq, lt_self_iff_false]
· simp only [hp, hq, degree_zero, Ne, bot_lt_iff_ne_bot, degree_eq_bot, pow_pos,
not_false_iff]
· simp only [hq, degree_zero, not_lt_bot, (pow_pos _).not_gt]
· rw [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt, pow_lt_pow_iff_right₀]
exact mod_cast @Fintype.one_lt_card Fq _ _ }
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/Lemmas.lean | import Mathlib.Algebra.Polynomial.Eval.Degree
import Mathlib.Algebra.Prime.Lemmas
/-!
# Theory of degrees of polynomials
Some of the main results include
- `natDegree_comp_le` : The degree of the composition is at most the product of degrees
-/
noncomputable section
open Polynomial
open Finsupp Finset
namespace Polynomial
universe u v w
variable {R : Type u} {S : Type v} {ι : Type w} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section Degree
theorem natDegree_comp_le : natDegree (p.comp q) ≤ natDegree p * natDegree q :=
letI := Classical.decEq R
if h0 : p.comp q = 0 then by rw [h0, natDegree_zero]; exact Nat.zero_le _
else
WithBot.coe_le_coe.1 <|
calc
↑(natDegree (p.comp q)) = degree (p.comp q) := (degree_eq_natDegree h0).symm
_ = _ := congr_arg degree comp_eq_sum_left
_ ≤ _ := degree_sum_le _ _
_ ≤ _ :=
Finset.sup_le fun n hn =>
calc
degree (C (coeff p n) * q ^ n) ≤ degree (C (coeff p n)) + degree (q ^ n) :=
degree_mul_le _ _
_ ≤ natDegree (C (coeff p n)) + n • degree q :=
(add_le_add degree_le_natDegree (degree_pow_le _ _))
_ ≤ natDegree (C (coeff p n)) + n • ↑(natDegree q) := by grw [degree_le_natDegree]
_ = (n * natDegree q : ℕ) := by
rw [natDegree_C, Nat.cast_zero, zero_add, nsmul_eq_mul]
simp
_ ≤ (natDegree p * natDegree q : ℕ) :=
WithBot.coe_le_coe.2 <|
mul_le_mul_of_nonneg_right (le_natDegree_of_ne_zero (mem_support_iff.1 hn))
(Nat.zero_le _)
theorem natDegree_comp_eq_of_mul_ne_zero (h : p.leadingCoeff * q.leadingCoeff ^ p.natDegree ≠ 0) :
natDegree (p.comp q) = natDegree p * natDegree q := by
by_cases hq : natDegree q = 0
· exact le_antisymm natDegree_comp_le (by simp [hq])
apply natDegree_eq_of_le_of_coeff_ne_zero natDegree_comp_le
rwa [coeff_comp_degree_mul_degree hq]
theorem degree_pos_of_root {p : R[X]} (hp : p ≠ 0) (h : IsRoot p a) : 0 < degree p :=
lt_of_not_ge fun hlt => by
have := eq_C_of_degree_le_zero hlt
rw [IsRoot, this, eval_C] at h
simp only [h, RingHom.map_zero] at this
exact hp this
theorem natDegree_le_iff_coeff_eq_zero : p.natDegree ≤ n ↔ ∀ N : ℕ, n < N → p.coeff N = 0 := by
simp_rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero, Nat.cast_lt]
theorem natDegree_add_le_iff_left {n : ℕ} (p q : R[X]) (qn : q.natDegree ≤ n) :
(p + q).natDegree ≤ n ↔ p.natDegree ≤ n := by
refine ⟨fun h => ?_, fun h => natDegree_add_le_of_degree_le h qn⟩
refine natDegree_le_iff_coeff_eq_zero.mpr fun m hm => ?_
convert natDegree_le_iff_coeff_eq_zero.mp h m hm using 1
rw [coeff_add, natDegree_le_iff_coeff_eq_zero.mp qn _ hm, add_zero]
theorem natDegree_add_le_iff_right {n : ℕ} (p q : R[X]) (pn : p.natDegree ≤ n) :
(p + q).natDegree ≤ n ↔ q.natDegree ≤ n := by
rw [add_comm]
exact natDegree_add_le_iff_left _ _ pn
-- TODO: Do we really want the following two lemmas? They are straightforward consequences of a
-- more atomic lemma
theorem natDegree_C_mul_le (a : R) (f : R[X]) : (C a * f).natDegree ≤ f.natDegree := by
simpa using natDegree_mul_le (p := C a)
theorem natDegree_mul_C_le (f : R[X]) (a : R) : (f * C a).natDegree ≤ f.natDegree := by
simpa using natDegree_mul_le (q := C a)
theorem eq_natDegree_of_le_mem_support (pn : p.natDegree ≤ n) (ns : n ∈ p.support) :
p.natDegree = n :=
le_antisymm pn (le_natDegree_of_mem_supp _ ns)
theorem natDegree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) :
(C a * p).natDegree = p.natDegree :=
le_antisymm (natDegree_C_mul_le a p)
(calc
p.natDegree = (1 * p).natDegree := by nth_rw 1 [← one_mul p]
_ = (C ai * (C a * p)).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc]
_ ≤ (C a * p).natDegree := natDegree_C_mul_le ai (C a * p))
theorem natDegree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) :
(p * C a).natDegree = p.natDegree :=
le_antisymm (natDegree_mul_C_le p a)
(calc
p.natDegree = (p * 1).natDegree := by nth_rw 1 [← mul_one p]
_ = (p * C a * C ai).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc]
_ ≤ (p * C a).natDegree := natDegree_mul_C_le (p * C a) ai)
/-- Although not explicitly stated, the assumptions of lemma `natDegree_mul_C_eq_of_mul_ne_zero`
force the polynomial `p` to be non-zero, via `p.leadingCoeff ≠ 0`.
-/
theorem natDegree_mul_C_eq_of_mul_ne_zero (h : p.leadingCoeff * a ≠ 0) :
(p * C a).natDegree = p.natDegree := by
refine eq_natDegree_of_le_mem_support (natDegree_mul_C_le p a) ?_
refine mem_support_iff.mpr ?_
rwa [coeff_mul_C]
/-- Although not explicitly stated, the assumptions of lemma `natDegree_C_mul_of_mul_ne_zero`
force the polynomial `p` to be non-zero, via `p.leadingCoeff ≠ 0`.
-/
theorem natDegree_C_mul_of_mul_ne_zero (h : a * p.leadingCoeff ≠ 0) :
(C a * p).natDegree = p.natDegree := by
refine eq_natDegree_of_le_mem_support (natDegree_C_mul_le a p) ?_
refine mem_support_iff.mpr ?_
rwa [coeff_C_mul]
lemma degree_C_mul_of_mul_ne_zero (h : a * p.leadingCoeff ≠ 0) : (C a * p).degree = p.degree := by
rw [degree_mul' (by simpa)]; simp [left_ne_zero_of_mul h]
theorem natDegree_add_coeff_mul (f g : R[X]) :
(f * g).coeff (f.natDegree + g.natDegree) = f.coeff f.natDegree * g.coeff g.natDegree := by
simp only [coeff_natDegree, coeff_mul_degree_add_degree]
theorem natDegree_lt_coeff_mul (h : p.natDegree + q.natDegree < m + n) :
(p * q).coeff (m + n) = 0 :=
coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt h)
@[deprecated (since := "2025-08-14")] alias coeff_mul_of_natDegree_le :=
coeff_mul_add_eq_of_natDegree_le
theorem coeff_pow_of_natDegree_le (pn : p.natDegree ≤ n) :
(p ^ m).coeff (m * n) = p.coeff n ^ m := by
induction m with
| zero => simp
| succ m hm =>
rw [pow_succ, pow_succ, ← hm, Nat.succ_mul, coeff_mul_add_eq_of_natDegree_le _ pn]
refine natDegree_pow_le.trans (le_trans ?_ (le_refl _))
exact mul_le_mul_of_nonneg_left pn m.zero_le
theorem coeff_pow_eq_ite_of_natDegree_le_of_le {o : ℕ}
(pn : natDegree p ≤ n) (mno : m * n ≤ o) :
coeff (p ^ m) o = if o = m * n then (coeff p n) ^ m else 0 := by
rcases eq_or_ne o (m * n) with rfl | h
· simpa only [ite_true] using coeff_pow_of_natDegree_le pn
· simpa only [h, ite_false] using coeff_eq_zero_of_natDegree_lt <|
lt_of_le_of_lt (natDegree_pow_le_of_le m pn) (lt_of_le_of_ne mno h.symm)
theorem coeff_add_eq_left_of_lt (qn : q.natDegree < n) : (p + q).coeff n = p.coeff n :=
(coeff_add _ _ _).trans <|
(congr_arg _ <| coeff_eq_zero_of_natDegree_lt <| qn).trans <| add_zero _
theorem coeff_add_eq_right_of_lt (pn : p.natDegree < n) : (p + q).coeff n = q.coeff n := by
rw [add_comm]
exact coeff_add_eq_left_of_lt pn
open scoped Function -- required for scoped `on` notation
theorem degree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S)
(h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on degree ∘ f)) :
degree (s.sum f) = s.sup fun i => degree (f i) := by
classical
induction s using Finset.induction_on with
| empty => simp
| insert x s hx IH =>
simp only [hx, Finset.sum_insert, not_false_iff, Finset.sup_insert]
specialize IH (h.mono fun _ => by simp +contextual)
rcases lt_trichotomy (degree (f x)) (degree (s.sum f)) with (H | H | H)
· rw [← IH, sup_eq_right.mpr H.le, degree_add_eq_right_of_degree_lt H]
· rcases s.eq_empty_or_nonempty with (rfl | hs)
· simp
obtain ⟨y, hy, hy'⟩ := Finset.exists_mem_eq_sup s hs fun i => degree (f i)
rw [IH, hy'] at H
by_cases hx0 : f x = 0
· simp [hx0, IH]
have hy0 : f y ≠ 0 := by
contrapose! H
simpa [H, degree_eq_bot] using hx0
refine absurd H (h ?_ ?_ fun H => hx ?_)
· simp [hx0]
· simp [hy, hy0]
· exact H.symm ▸ hy
· rw [← IH, sup_eq_left.mpr H.le, degree_add_eq_left_of_degree_lt H]
theorem natDegree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S)
(h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on natDegree ∘ f)) :
natDegree (s.sum f) = s.sup fun i => natDegree (f i) := by
by_cases! H : ∃ x ∈ s, f x ≠ 0
· obtain ⟨x, hx, hx'⟩ := H
have hs : s.Nonempty := ⟨x, hx⟩
refine natDegree_eq_of_degree_eq_some ?_
rw [degree_sum_eq_of_disjoint]
· rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs,
Nat.cast_withBot, Finset.coe_sup' hs, ←
Finset.sup'_eq_sup hs]
refine le_antisymm ?_ ?_
· rw [Finset.sup'_le_iff]
intro b hb
by_cases hb' : f b = 0
· simpa [hb'] using hs
rw [degree_eq_natDegree hb', Nat.cast_withBot]
exact Finset.le_sup' (fun i : S => (natDegree (f i) : WithBot ℕ)) hb
· rw [Finset.sup'_le_iff]
intro b hb
simp only [Finset.le_sup'_iff, Function.comp_apply]
by_cases hb' : f b = 0
· refine ⟨x, hx, ?_⟩
contrapose! hx'
simpa [← Nat.cast_withBot, hb', degree_eq_bot] using hx'
exact ⟨b, hb, (degree_eq_natDegree hb').ge⟩
· exact h.imp fun x y hxy hxy' => hxy (natDegree_eq_of_degree_eq hxy')
· rw [Finset.sum_eq_zero H, natDegree_zero, eq_comm, show 0 = ⊥ from rfl, Finset.sup_eq_bot_iff]
intro x hx
simp [H x hx]
variable [Semiring S]
theorem natDegree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S}
(hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < natDegree p :=
lt_of_not_ge fun hlt => by
have A : p = C (p.coeff 0) := eq_C_of_natDegree_le_zero hlt
rw [A, eval₂_C] at hz
simp only [inj (p.coeff 0) hz, RingHom.map_zero] at A
exact hp A
theorem degree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S}
(hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < degree p :=
natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_eval₂_root hp f hz inj)
@[simp]
theorem coe_lt_degree {p : R[X]} {n : ℕ} : (n : WithBot ℕ) < degree p ↔ n < natDegree p := by
by_cases h : p = 0
· simp [h]
simp [degree_eq_natDegree h, Nat.cast_lt]
@[simp]
theorem degree_map_eq_iff {f : R →+* S} {p : Polynomial R} :
degree (map f p) = degree p ↔ f (leadingCoeff p) ≠ 0 ∨ p = 0 := by
rcases eq_or_ne p 0 with h|h
· simp [h]
simp only [h, or_false]
refine ⟨fun h2 ↦ ?_, degree_map_eq_of_leadingCoeff_ne_zero f⟩
have h3 : natDegree (map f p) = natDegree p := by simp_rw [natDegree, h2]
have h4 : map f p ≠ 0 := by
rwa [ne_eq, ← degree_eq_bot, h2, degree_eq_bot]
rwa [← coeff_natDegree, ← coeff_map, ← h3, coeff_natDegree, ne_eq, leadingCoeff_eq_zero]
@[simp]
theorem natDegree_map_eq_iff {f : R →+* S} {p : Polynomial R} :
natDegree (map f p) = natDegree p ↔ f (p.leadingCoeff) ≠ 0 ∨ natDegree p = 0 := by
rcases eq_or_ne (natDegree p) 0 with h|h
· simp_rw [h, ne_eq, or_true, iff_true, ← Nat.le_zero, ← h, natDegree_map_le]
simp_all [natDegree, WithBot.unbotD_eq_unbotD_iff]
theorem degree_map_eq_of_isUnit_leadingCoeff [Nontrivial S] (f : R →+* S)
(hp : IsUnit p.leadingCoeff) : (p.map f).degree = p.degree :=
degree_map_eq_of_leadingCoeff_ne_zero _ <| f.isUnit_map hp |>.ne_zero
theorem natDegree_map_eq_of_isUnit_leadingCoeff [Nontrivial S] (f : R →+* S)
(hp : IsUnit p.leadingCoeff) : (p.map f).natDegree = p.natDegree :=
natDegree_eq_natDegree <| degree_map_eq_of_isUnit_leadingCoeff _ hp
theorem leadingCoeff_map_eq_of_isUnit_leadingCoeff [Nontrivial S] (f : R →+* S)
(hp : IsUnit p.leadingCoeff) : (p.map f).leadingCoeff = f p.leadingCoeff :=
leadingCoeff_map_of_leadingCoeff_ne_zero _ <| f.isUnit_map hp |>.ne_zero
theorem nextCoeff_map_eq_of_isUnit_leadingCoeff [Nontrivial S] (f : R →+* S)
(hp : IsUnit p.leadingCoeff) : (p.map f).nextCoeff = f p.nextCoeff :=
nextCoeff_map_of_leadingCoeff_ne_zero _ <| f.isUnit_map hp |>.ne_zero
theorem degree_map_eq_of_injective {f : R →+* S} (hf : Function.Injective f) (p : Polynomial R) :
(p.map f).degree = p.degree := by
simp [hf, map_ne_zero_iff, ne_or_eq]
theorem natDegree_map_eq_of_injective {f : R →+* S} (hf : Function.Injective f) (p : Polynomial R) :
(p.map f).natDegree = p.natDegree :=
natDegree_eq_of_degree_eq <| degree_map_eq_of_injective hf _
theorem leadingCoeff_map_of_injective {f : R →+* S} (hf : Function.Injective f)
(p : Polynomial R) : (p.map f).leadingCoeff = f p.leadingCoeff := by
simp only [leadingCoeff, natDegree_map_eq_of_injective hf, coeff_map]
theorem nextCoeff_map {f : R →+* S} (hf : Function.Injective f) (p : Polynomial R) :
(p.map f).nextCoeff = f p.nextCoeff := by
simp only [hf, nextCoeff, natDegree_map_eq_of_injective]
split_ifs <;> simp
theorem natDegree_pos_of_nextCoeff_ne_zero (h : p.nextCoeff ≠ 0) : 0 < p.natDegree := by
grind [nextCoeff]
end Degree
end Semiring
section Ring
variable [Ring R] {p q : R[X]}
theorem natDegree_sub : (p - q).natDegree = (q - p).natDegree := by rw [← natDegree_neg, neg_sub]
theorem natDegree_sub_le_iff_left (qn : q.natDegree ≤ n) :
(p - q).natDegree ≤ n ↔ p.natDegree ≤ n := by
rw [← natDegree_neg] at qn
rw [sub_eq_add_neg, natDegree_add_le_iff_left _ _ qn]
theorem natDegree_sub_le_iff_right (pn : p.natDegree ≤ n) :
(p - q).natDegree ≤ n ↔ q.natDegree ≤ n := by rwa [natDegree_sub, natDegree_sub_le_iff_left]
theorem coeff_sub_eq_left_of_lt (dg : q.natDegree < n) : (p - q).coeff n = p.coeff n := by
rw [← natDegree_neg] at dg
rw [sub_eq_add_neg, coeff_add_eq_left_of_lt dg]
theorem coeff_sub_eq_neg_right_of_lt (df : p.natDegree < n) : (p - q).coeff n = -q.coeff n := by
rwa [sub_eq_add_neg, coeff_add_eq_right_of_lt, coeff_neg]
end Ring
section NoZeroDivisors
variable [Semiring R] {p q : R[X]} {a : R}
@[simp]
lemma nextCoeff_C_mul_X_add_C (ha : a ≠ 0) (c : R) : nextCoeff (C a * X + C c) = c := by
rw [nextCoeff_of_natDegree_pos] <;> simp [ha]
lemma natDegree_eq_one : p.natDegree = 1 ↔ ∃ a ≠ 0, ∃ b, C a * X + C b = p := by
refine ⟨fun hp ↦ ⟨p.coeff 1, fun h ↦ ?_, p.coeff 0, ?_⟩, ?_⟩
· rw [← hp, coeff_natDegree, leadingCoeff_eq_zero] at h
simp_all
· ext n
obtain _ | _ | n := n
· simp
· simp
· simp only [coeff_add, coeff_mul_X, coeff_C_succ, add_zero]
rw [coeff_eq_zero_of_natDegree_lt]
simp [hp]
· rintro ⟨a, ha, b, rfl⟩
simp [ha]
theorem subsingleton_isRoot_of_natDegree_eq_one [IsLeftCancelMulZero R]
(h : p.natDegree = 1) : { x | IsRoot p x }.Subsingleton := by
intro r₁
obtain ⟨r₂, hr₂, r₃, rfl⟩ : ∃ a, a ≠ 0 ∧ ∃ b, C a * X + C b = p := by rwa [natDegree_eq_one] at h
have (x y : R) := mul_left_cancel₀ hr₂ (b := x) (c := y)
grind [IsRoot, eval_add, eval_mul_X, eval_C]
variable [NoZeroDivisors R]
theorem degree_mul_C (a0 : a ≠ 0) : (p * C a).degree = p.degree := by
rw [degree_mul, degree_C a0, add_zero]
theorem degree_C_mul (a0 : a ≠ 0) : (C a * p).degree = p.degree := by
rw [degree_mul, degree_C a0, zero_add]
theorem natDegree_mul_C (a0 : a ≠ 0) : (p * C a).natDegree = p.natDegree := by
simp only [natDegree, degree_mul_C a0]
theorem natDegree_C_mul (a0 : a ≠ 0) : (C a * p).natDegree = p.natDegree := by
simp only [natDegree, degree_C_mul a0]
theorem natDegree_comp : natDegree (p.comp q) = natDegree p * natDegree q := by
by_cases q0 : q.natDegree = 0
· rw [degree_le_zero_iff.mp (natDegree_eq_zero_iff_degree_le_zero.mp q0), comp_C, natDegree_C,
natDegree_C, mul_zero]
· by_cases p0 : p = 0
· simp only [p0, zero_comp, natDegree_zero, zero_mul]
· simp only [Ne, mul_eq_zero, leadingCoeff_eq_zero, p0, natDegree_comp_eq_of_mul_ne_zero,
ne_zero_of_natDegree_gt (Nat.pos_of_ne_zero q0), not_false_eq_true, pow_ne_zero, or_self]
@[simp]
theorem natDegree_iterate_comp (k : ℕ) :
(p.comp^[k] q).natDegree = p.natDegree ^ k * q.natDegree := by
induction k with
| zero => simp
| succ k IH => rw [Function.iterate_succ_apply', natDegree_comp, IH, pow_succ', mul_assoc]
theorem leadingCoeff_comp (hq : natDegree q ≠ 0) :
leadingCoeff (p.comp q) = leadingCoeff p * leadingCoeff q ^ natDegree p := by
rw [← coeff_comp_degree_mul_degree hq, ← natDegree_comp, coeff_natDegree]
@[simp]
theorem nextCoeff_C_mul : (C a * p).nextCoeff = a * p.nextCoeff := by
by_cases h₀ : a = 0 <;> simp [h₀, nextCoeff, natDegree_C_mul]
@[simp]
theorem nextCoeff_mul_C : (p * C a).nextCoeff = p.nextCoeff * a := by
by_cases h₀ : a = 0 <;> simp [h₀, nextCoeff, natDegree_mul_C]
end NoZeroDivisors
@[simp] lemma comp_neg_X_leadingCoeff_eq [Ring R] (p : R[X]) :
(p.comp (-X)).leadingCoeff = (-1) ^ p.natDegree * p.leadingCoeff := by
nontriviality R
by_cases h : p = 0
· simp [h]
rw [Polynomial.leadingCoeff, natDegree_comp_eq_of_mul_ne_zero, coeff_comp_degree_mul_degree] <;>
simp [((Commute.neg_one_left _).pow_left _).eq, h]
lemma comp_eq_zero_iff [Semiring R] [NoZeroDivisors R] {p q : R[X]} :
p.comp q = 0 ↔ p = 0 ∨ p.eval (q.coeff 0) = 0 ∧ q = C (q.coeff 0) := by
refine ⟨fun h ↦ ?_, Or.rec (fun h ↦ by simp [h]) fun h ↦ by rw [h.2, comp_C, h.1, C_0]⟩
have key : p.natDegree = 0 ∨ q.natDegree = 0 := by
rw [← mul_eq_zero, ← natDegree_comp, h, natDegree_zero]
obtain key | key := Or.imp eq_C_of_natDegree_eq_zero eq_C_of_natDegree_eq_zero key
· rw [key, C_comp] at h
exact Or.inl (key.trans h)
· rw [key, comp_C, C_eq_zero] at h
exact Or.inr ⟨h, key⟩
section DivisionRing
variable {K : Type*} [DivisionRing K]
/-! Useful lemmas for the "monicization" of a nonzero polynomial `p`. -/
@[simp]
theorem irreducible_mul_leadingCoeff_inv {p : K[X]} :
Irreducible (p * C (leadingCoeff p)⁻¹) ↔ Irreducible p := by
by_cases hp0 : p = 0
· simp [hp0]
exact irreducible_mul_isUnit
(isUnit_C.mpr (IsUnit.mk0 _ (inv_ne_zero (leadingCoeff_ne_zero.mpr hp0))))
lemma dvd_mul_leadingCoeff_inv {p q : K[X]} (hp0 : p ≠ 0) :
q ∣ p * C (leadingCoeff p)⁻¹ ↔ q ∣ p := by
simp [hp0]
theorem monic_mul_leadingCoeff_inv {p : K[X]} (h : p ≠ 0) : Monic (p * C (leadingCoeff p)⁻¹) := by
rw [Monic, leadingCoeff_mul, leadingCoeff_C,
mul_inv_cancel₀ (show leadingCoeff p ≠ 0 from mt leadingCoeff_eq_zero.1 h)]
-- `simp` normal form of `degree_mul_leadingCoeff_inv`
lemma degree_leadingCoeff_inv {p : K[X]} (hp0 : p ≠ 0) :
degree (C (leadingCoeff p)⁻¹) = 0 := by
simp [hp0]
theorem degree_mul_leadingCoeff_inv (p : K[X]) {q : K[X]} (h : q ≠ 0) :
degree (p * C (leadingCoeff q)⁻¹) = degree p := by
have h₁ : (leadingCoeff q)⁻¹ ≠ 0 := inv_ne_zero (mt leadingCoeff_eq_zero.1 h)
rw [degree_mul_C h₁]
theorem natDegree_mul_leadingCoeff_inv (p : K[X]) {q : K[X]} (h : q ≠ 0) :
natDegree (p * C (leadingCoeff q)⁻¹) = natDegree p :=
natDegree_eq_of_degree_eq (degree_mul_leadingCoeff_inv _ h)
theorem degree_mul_leadingCoeff_self_inv (p : K[X]) :
degree (p * C (leadingCoeff p)⁻¹) = degree p := by
by_cases hp : p = 0
· simp [hp]
exact degree_mul_leadingCoeff_inv _ hp
theorem natDegree_mul_leadingCoeff_self_inv (p : K[X]) :
natDegree (p * C (leadingCoeff p)⁻¹) = natDegree p :=
natDegree_eq_of_degree_eq (degree_mul_leadingCoeff_self_inv _)
-- `simp` normal form of `degree_mul_leadingCoeff_self_inv`
@[simp] lemma degree_add_degree_leadingCoeff_inv (p : K[X]) :
degree p + degree (C (leadingCoeff p)⁻¹) = degree p := by
rw [← degree_mul, degree_mul_leadingCoeff_self_inv]
end DivisionRing
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/Support.lean | import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Algebra.Polynomial.Degree.Operations
/-!
# Degree and support of univariate polynomials
## Main results
* `Polynomial.as_sum_support`: write `p : R[X]` as a sum over its support
* `Polynomial.as_sum_range`: write `p : R[X]` as a sum over `{0, ..., natDegree p}`
* `Polynomial.natDegree_mem_support_of_nonzero`: `natDegree p ∈ support p` if `p ≠ 0`
-/
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
theorem supDegree_eq_natDegree (p : R[X]) : p.toFinsupp.supDegree id = p.natDegree := by
obtain rfl | h := eq_or_ne p 0
· simp
apply WithBot.coe_injective
rw [← AddMonoidAlgebra.supDegree_withBot_some_comp, Function.comp_id, supDegree_eq_degree,
degree_eq_natDegree h, Nat.cast_withBot]
rwa [support_toFinsupp, nonempty_iff_ne_empty, Ne, support_eq_empty]
theorem le_natDegree_of_mem_supp (a : ℕ) : a ∈ p.support → a ≤ natDegree p :=
le_natDegree_of_ne_zero ∘ mem_support_iff.mp
theorem supp_subset_range (h : natDegree p < m) : p.support ⊆ Finset.range m := fun _n hn =>
mem_range.2 <| (le_natDegree_of_mem_supp _ hn).trans_lt h
theorem supp_subset_range_natDegree_succ : p.support ⊆ Finset.range (natDegree p + 1) :=
supp_subset_range (Nat.lt_succ_self _)
theorem as_sum_support (p : R[X]) : p = ∑ i ∈ p.support, monomial i (p.coeff i) :=
(sum_monomial_eq p).symm
theorem as_sum_support_C_mul_X_pow (p : R[X]) : p = ∑ i ∈ p.support, C (p.coeff i) * X ^ i :=
_root_.trans p.as_sum_support <| by simp only [C_mul_X_pow_eq_monomial]
/-- We can reexpress a sum over `p.support` as a sum over `range n`,
for any `n` satisfying `p.natDegree < n`.
-/
theorem sum_over_range' [AddCommMonoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) (n : ℕ)
(hn : p.natDegree < n) : p.sum f = ∑ a ∈ range n, f a (coeff p a) := by
have := supp_subset_range hn
simp only [Polynomial.sum, support, coeff] at this ⊢
exact Finsupp.sum_of_support_subset _ this _ fun n _hn => h n
/-- We can reexpress a sum over `p.support` as a sum over `range (p.natDegree + 1)`.
-/
theorem sum_over_range [AddCommMonoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) :
p.sum f = ∑ a ∈ range (p.natDegree + 1), f a (coeff p a) :=
sum_over_range' p h (p.natDegree + 1) (lt_add_one _)
-- TODO this is essentially a duplicate of `sum_over_range`, and should be removed.
theorem sum_fin [AddCommMonoid S] (f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) {n : ℕ} {p : R[X]}
(hn : p.degree < n) : (∑ i : Fin n, f i (p.coeff i)) = p.sum f := by
by_cases hp : p = 0
· rw [hp, sum_zero_index, Finset.sum_eq_zero]
intro i _
exact hf i
rw [sum_over_range' _ hf n ((natDegree_lt_iff_degree_lt hp).mpr hn),
Fin.sum_univ_eq_sum_range fun i => f i (p.coeff i)]
theorem as_sum_range' (p : R[X]) (n : ℕ) (hn : p.natDegree < n) :
p = ∑ i ∈ range n, monomial i (coeff p i) :=
p.sum_monomial_eq.symm.trans <| p.sum_over_range' monomial_zero_right _ hn
theorem as_sum_range (p : R[X]) : p = ∑ i ∈ range (p.natDegree + 1), monomial i (coeff p i) :=
p.as_sum_range' _ (lt_add_one _)
theorem as_sum_range_C_mul_X_pow' (p : R[X]) {n : ℕ} (hn : p.natDegree < n) :
p = ∑ i ∈ range n, C (coeff p i) * X ^ i :=
(p.as_sum_range' _ hn).trans <| by simp only [C_mul_X_pow_eq_monomial]
theorem as_sum_range_C_mul_X_pow (p : R[X]) :
p = ∑ i ∈ range (p.natDegree + 1), C (coeff p i) * X ^ i :=
p.as_sum_range_C_mul_X_pow' (lt_add_one _)
theorem mem_support_C_mul_X_pow {n a : ℕ} {c : R} (h : a ∈ support (C c * X ^ n)) : a = n :=
mem_singleton.1 <| support_C_mul_X_pow' n c h
theorem card_support_C_mul_X_pow_le_one {c : R} {n : ℕ} : #(support (C c * X ^ n)) ≤ 1 := by
rw [← card_singleton n]
apply card_le_card (support_C_mul_X_pow' n c)
theorem card_supp_le_succ_natDegree (p : R[X]) : #p.support ≤ p.natDegree + 1 := by
rw [← Finset.card_range (p.natDegree + 1)]
exact Finset.card_le_card supp_subset_range_natDegree_succ
theorem le_degree_of_mem_supp (a : ℕ) : a ∈ p.support → ↑a ≤ degree p :=
le_degree_of_ne_zero ∘ mem_support_iff.mp
theorem nonempty_support_iff : p.support.Nonempty ↔ p ≠ 0 := by
rw [Ne, nonempty_iff_ne_empty, Ne, ← support_eq_empty]
end Semiring
section Semiring
variable [Semiring R] {p q : R[X]} {ι : Type*}
theorem natDegree_mem_support_of_nonzero (H : p ≠ 0) : p.natDegree ∈ p.support := by
rw [mem_support_iff]
exact (not_congr leadingCoeff_eq_zero).mpr H
theorem natDegree_eq_support_max' (h : p ≠ 0) :
p.natDegree = p.support.max' (nonempty_support_iff.mpr h) :=
(le_max' _ _ <| natDegree_mem_support_of_nonzero h).antisymm <|
max'_le _ _ _ le_natDegree_of_mem_supp
end Semiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/Definitions.lean | import Mathlib.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.Order.Ring.WithTop
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Data.Nat.Cast.WithTop
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.WithBot
/-!
# Degree of univariate polynomials
## Main definitions
* `Polynomial.degree`: the degree of a polynomial, where `0` has degree `⊥`
* `Polynomial.natDegree`: the degree of a polynomial, where `0` has degree `0`
* `Polynomial.leadingCoeff`: the leading coefficient of a polynomial
* `Polynomial.Monic`: a polynomial is monic if its leading coefficient is 0
* `Polynomial.nextCoeff`: the next coefficient after the leading coefficient
## Main results
* `Polynomial.degree_eq_natDegree`: the degree and natDegree coincide for nonzero polynomials
-/
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : R[X]) : WithBot ℕ :=
p.support.max
/-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/
def natDegree (p : R[X]) : ℕ :=
(degree p).unbotD 0
/-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`. -/
def leadingCoeff (p : R[X]) : R :=
coeff p (natDegree p)
/-- a polynomial is `Monic` if its leading coefficient is 1 -/
def Monic (p : R[X]) :=
leadingCoeff p = (1 : R)
theorem Monic.def : Monic p ↔ leadingCoeff p = 1 :=
Iff.rfl
instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance
@[simp]
theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 :=
hp
theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 :=
hp
@[simp]
theorem degree_zero : degree (0 : R[X]) = ⊥ :=
rfl
@[simp]
theorem natDegree_zero : natDegree (0 : R[X]) = 0 :=
rfl
@[simp]
theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p :=
rfl
@[simp]
theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩
theorem degree_ne_bot : degree p ≠ ⊥ ↔ p ≠ 0 := degree_eq_bot.not
theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by
let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp))
have hn : degree p = some n := Classical.not_not.1 hn
rw [natDegree, hn]; rfl
theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe
theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :
p.degree = n ↔ p.natDegree = n := by
obtain rfl | h := eq_or_ne p 0
· simp [hn.ne]
· exact degree_eq_iff_natDegree_eq h
theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by
rw [natDegree, h, Nat.cast_withBot, WithBot.unbotD_coe]
theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n :=
mt natDegree_eq_of_degree_eq_some
@[simp]
theorem degree_le_natDegree : degree p ≤ natDegree p :=
WithBot.giUnbotDBot.gc.le_u_l _
theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) :
natDegree p = natDegree q := by unfold natDegree; rw [h]
theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by
rw [Nat.cast_withBot]
exact Finset.le_sup (mem_support_iff.2 h)
theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) :
f.degree ≤ g.degree :=
Finset.sup_mono h
theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by
by_cases hp : p = 0
· rw [hp, degree_zero]
exact bot_le
· rw [degree_eq_natDegree hp]
exact le_degree_of_ne_zero h
theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n :=
WithBot.unbotD_le_iff (fun _ ↦ bot_le)
theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n :=
WithBot.unbotD_lt_iff (absurd · (degree_eq_bot.not.mpr hp))
alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le
theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) :
p.natDegree ≤ q.natDegree :=
WithBot.giUnbotDBot.gc.monotone_l hpq
@[simp]
theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by
rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton,
WithBot.coe_zero]
theorem degree_C_le : degree (C a) ≤ 0 := by
by_cases h : a = 0
· rw [h, C_0]
exact bot_le
· rw [degree_C h]
theorem degree_C_lt : degree (C a) < 1 :=
degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one
theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le
@[simp]
theorem natDegree_C (a : R) : natDegree (C a) = 0 := by
by_cases ha : a = 0
· have : C a = 0 := by rw [ha, C_0]
rw [natDegree, degree_eq_bot.2 this, WithBot.unbotD_bot]
· rw [natDegree, degree_C ha, WithBot.unbotD_zero]
@[simp]
theorem natDegree_one : natDegree (1 : R[X]) = 0 :=
natDegree_C 1
@[simp]
theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by
simp only [← C_eq_natCast, natDegree_C]
@[simp]
theorem natDegree_ofNat (n : ℕ) [Nat.AtLeastTwo n] :
natDegree (ofNat(n) : R[X]) = 0 :=
natDegree_natCast _
theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by
rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot]
@[simp]
theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by
rw [C_mul_X_pow_eq_monomial, degree_monomial n ha]
theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by
simpa only [pow_one] using degree_C_mul_X_pow 1 ha
theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=
letI := Classical.decEq R
if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le
else le_of_eq (degree_monomial n h)
theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by
rw [C_mul_X_pow_eq_monomial]
apply degree_monomial_le
theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by
simpa only [pow_one] using degree_C_mul_X_pow_le 1 a
@[simp]
theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)
@[simp]
theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by
simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha
@[simp]
theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) :
natDegree (monomial i r) = if r = 0 then 0 else i := by
split_ifs with hr
· simp [hr]
· rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr]
theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by
classical
rw [Polynomial.natDegree_monomial]
split_ifs
exacts [Nat.zero_le _, le_rfl]
theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i :=
letI := Classical.decEq R
Eq.trans (natDegree_monomial _ _) (if_neg r0)
theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h =>
mem_support_iff.mp (mem_of_max hn) h
theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by
simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R)
theorem degree_X_le : degree (X : R[X]) ≤ 1 :=
degree_monomial_le _ _
theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 :=
natDegree_le_of_degree_le degree_X_le
theorem withBotSucc_degree_eq_natDegree_add_one (h : p ≠ 0) : p.degree.succ = p.natDegree + 1 := by
rw [degree_eq_natDegree h]
exact WithBot.succ_coe p.natDegree
end Semiring
section NonzeroSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) :=
degree_C one_ne_zero
@[simp]
theorem degree_X : degree (X : R[X]) = 1 :=
degree_monomial _ one_ne_zero
@[simp]
theorem natDegree_X : (X : R[X]).natDegree = 1 :=
natDegree_eq_of_degree_eq_some degree_X
end NonzeroSemiring
section Ring
variable [Ring R]
@[simp]
theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg]
theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a :=
p.degree_neg.le.trans hp
@[simp]
theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree]
theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m :=
(natDegree_neg p).le.trans hp
@[simp]
theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by
rw [← C_eq_intCast, natDegree_C]
theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by
rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg]
end Ring
section Semiring
variable [Semiring R] {p : R[X]}
/-- The second-highest coefficient, or 0 for constants -/
def nextCoeff (p : R[X]) : R :=
if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1)
lemma nextCoeff_eq_zero :
p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by
simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; simp_all
lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by
simp [nextCoeff]
@[simp]
theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by
rw [nextCoeff]
simp
theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) :
nextCoeff p = p.coeff (p.natDegree - 1) := by
rw [nextCoeff, if_neg]
contrapose! hp
simpa
variable {p q : R[X]} {ι : Type*}
theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by
simpa only [degree, ← support_toFinsupp, toFinsupp_add]
using AddMonoidAlgebra.sup_support_add_le _ _ _
theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) :
degree (p + q) ≤ n :=
(degree_add_le p q).trans <| max_le hp hq
theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p + q) ≤ max a b :=
(p.degree_add_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by
rcases le_max_iff.1 (degree_add_le p q) with h | h <;> simp [natDegree_le_natDegree h]
theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n)
(hq : natDegree q ≤ n) : natDegree (p + q) ≤ n :=
(natDegree_add_le p q).trans <| max_le hp hq
theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p + q) ≤ max m n :=
(p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_›
@[simp]
theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 :=
rfl
@[simp]
theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 :=
⟨fun h =>
Classical.by_contradiction fun hp =>
mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)),
fun h => h.symm ▸ leadingCoeff_zero⟩
theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero]
theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by
rw [leadingCoeff_eq_zero, degree_eq_bot]
theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n :=
natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _
theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by
simp only [erase_def, degree, support]
apply sup_mono
rw [Finsupp.support_erase]
apply Finset.erase_subset
theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by
apply lt_of_le_of_ne (degree_erase_le _ _)
rw [degree_eq_natDegree hp, degree, support_erase]
exact fun h => notMem_erase _ _ (mem_of_max h)
theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by
classical
rw [degree, support_update]
split_ifs
· exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _)
· rw [max_insert, max_comm]
exact le_rfl
theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) :
degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) :=
Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl])
fun a s has ih =>
calc
degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by
rw [Finset.sum_cons]; exact degree_add_le _ _
_ ≤ _ := by rw [sup_cons]; exact max_le_max le_rfl ih
theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by
simpa [degree, ← support_toFinsupp] using AddMonoidAlgebra.sup_support_mul_le (by simp) ..
theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p * q) ≤ a + b := by grw [degree_mul_le, hp, hq]
theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p
| 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le
| n + 1 => by grw [pow_succ, succ_nsmul, degree_mul_le, degree_pow_le]
theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) :
degree (p ^ b) ≤ b * a := by
induction b with
| zero => simp [degree_one_le]
| succ n hn =>
rw [Nat.cast_succ, add_mul, one_mul, pow_succ]
exact degree_mul_le_of_le hn hp
@[simp]
theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by
classical
by_cases ha : a = 0
· simp only [ha, (monomial n).map_zero, leadingCoeff_zero]
· rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial]
simp
theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by
rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial]
theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by
simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1
@[simp]
theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a :=
leadingCoeff_monomial a 0
theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by
simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n
theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by
simpa only [pow_one] using @leadingCoeff_X_pow R _ 1
@[simp]
theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) :=
leadingCoeff_X_pow n
@[simp]
theorem monic_X : Monic (X : R[X]) :=
leadingCoeff_X
theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 :=
leadingCoeff_C 1
@[simp]
theorem monic_one : Monic (1 : R[X]) :=
leadingCoeff_C _
theorem Monic.ne_zero [Nontrivial R] {p : R[X]} (hp : p.Monic) :
p ≠ 0 := by
rintro rfl
simp [Monic] at hp
theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by
nontriviality R
exact hp.ne_zero
lemma Monic.ne_zero_of_C [Nontrivial R] {c : R} (hc : Monic (C c)) : c ≠ 0 := by
rintro rfl
simp [Monic] at hc
theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 :=
haveI := Nontrivial.of_polynomial_ne hne
hp.ne_zero
theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by
apply natDegree_le_of_degree_le
apply le_trans (degree_mul_le p q)
rw [Nat.cast_add]
apply add_le_add <;> apply degree_le_natDegree
theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) :
natDegree (p * q) ≤ m + n :=
natDegree_mul_le.trans <| add_le_add ‹_› ‹_›
theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by
induction n with
| zero => simp
| succ n ih => grw [pow_succ, Nat.succ_mul, natDegree_mul_le, ih]
theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) :
natDegree (p ^ n) ≤ n * m :=
natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›)
theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by
rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero]
theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl
theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by
simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le,
not_imp_comm, Nat.cast_withBot]
theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) :
degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by
simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff,
WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not]
theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p :=
lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le
end Semiring
section NontrivialSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ)
@[simp]
theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by
rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)]
@[simp]
theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_X_pow n)
end NontrivialSemiring
section Ring
variable [Ring R] {p q : R[X]}
theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by
simpa only [degree_neg q] using degree_add_le p (-q)
theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p - q) ≤ max a b :=
(p.degree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by
simpa only [← natDegree_neg q] using natDegree_add_le p (-q)
theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p - q) ≤ max m n :=
(p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0)
(hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p :=
have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p :=
monomial_add_erase _ _
have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q :=
monomial_add_erase _ _
have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd]
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0)
calc
degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by
conv =>
lhs
rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]
_ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) :=
(degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _)
_ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 :=
(degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one))
theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 :=
natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r
end Ring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/Monomial.lean | import Mathlib.Algebra.Polynomial.Degree.Definitions
import Mathlib.Algebra.Polynomial.Monomial
import Mathlib.Data.Nat.SuccPred
/-!
# Degree of univariate monomials
-/
noncomputable section
open Finsupp Finset Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]} {ι : Type*}
lemma natDegree_le_pred (hf : p.natDegree ≤ n) (hn : p.coeff n = 0) : p.natDegree ≤ n - 1 := by
obtain _ | n := n
· exact hf
· refine (Nat.le_succ_iff_eq_or_le.1 hf).resolve_left fun h ↦ ?_
rw [← Nat.succ_eq_add_one, ← h, coeff_natDegree, leadingCoeff_eq_zero] at hn
simp_all
theorem monomial_natDegree_leadingCoeff_eq_self (h : #p.support ≤ 1) :
monomial p.natDegree p.leadingCoeff = p := by
classical
rcases card_support_le_one_iff_monomial.1 h with ⟨n, a, rfl⟩
by_cases ha : a = 0 <;> simp [ha]
theorem C_mul_X_pow_eq_self (h : #p.support ≤ 1) : C p.leadingCoeff * X ^ p.natDegree = p := by
rw [C_mul_X_pow_eq_monomial, monomial_natDegree_leadingCoeff_eq_self h]
end Semiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/Operations.lean | import Mathlib.Algebra.GroupWithZero.Regular
import Mathlib.Algebra.Polynomial.Coeff
import Mathlib.Algebra.Polynomial.Degree.Definitions
/-!
# Lemmas for calculating the degree of univariate polynomials
## Main results
- `degree_mul` : The degree of the product is the sum of degrees
- `leadingCoeff_add_of_degree_eq` and `leadingCoeff_add_of_degree_lt` :
The leading coefficient of a sum is determined by the leading coefficients and degrees
-/
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] [Semiring S] {p q r : R[X]}
theorem supDegree_eq_degree (p : R[X]) : p.toFinsupp.supDegree WithBot.some = p.degree :=
max_eq_sup_coe
theorem degree_lt_wf : WellFounded fun p q : R[X] => degree p < degree q :=
InvImage.wf degree wellFounded_lt
instance : WellFoundedRelation R[X] :=
⟨_, degree_lt_wf⟩
@[nontriviality]
theorem monic_of_subsingleton [Subsingleton R] (p : R[X]) : Monic p :=
Subsingleton.elim _ _
@[nontriviality]
theorem degree_of_subsingleton [Subsingleton R] : degree p = ⊥ := by
rw [Subsingleton.elim p 0, degree_zero]
@[nontriviality]
theorem natDegree_of_subsingleton [Subsingleton R] : natDegree p = 0 := by
rw [Subsingleton.elim p 0, natDegree_zero]
theorem le_natDegree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ natDegree p := by
rw [← Nat.cast_le (α := WithBot ℕ), ← degree_eq_natDegree]
· exact le_degree_of_ne_zero h
· rintro rfl
exact h rfl
theorem degree_eq_of_le_of_coeff_ne_zero (pn : p.degree ≤ n) (p1 : p.coeff n ≠ 0) : p.degree = n :=
pn.antisymm (le_degree_of_ne_zero p1)
theorem natDegree_eq_of_le_of_coeff_ne_zero (pn : p.natDegree ≤ n) (p1 : p.coeff n ≠ 0) :
p.natDegree = n :=
pn.antisymm (le_natDegree_of_ne_zero p1)
theorem natDegree_lt_natDegree {q : S[X]} (hp : p ≠ 0) (hpq : p.degree < q.degree) :
p.natDegree < q.natDegree := by
by_cases hq : q = 0
· exact (not_lt_bot <| hq ▸ hpq).elim
rwa [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt] at hpq
lemma natDegree_eq_natDegree {q : S[X]} (hpq : p.degree = q.degree) :
p.natDegree = q.natDegree := by simp [natDegree, hpq]
theorem coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 :=
Classical.not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))
theorem coeff_eq_zero_of_natDegree_lt {p : R[X]} {n : ℕ} (h : p.natDegree < n) :
p.coeff n = 0 := by
apply coeff_eq_zero_of_degree_lt
by_cases hp : p = 0
· subst hp
exact WithBot.bot_lt_coe n
· rwa [degree_eq_natDegree hp, Nat.cast_lt]
theorem ext_iff_natDegree_le {p q : R[X]} {n : ℕ} (hp : p.natDegree ≤ n) (hq : q.natDegree ≤ n) :
p = q ↔ ∀ i ≤ n, p.coeff i = q.coeff i := by
refine Iff.trans Polynomial.ext_iff ?_
refine forall_congr' fun i => ⟨fun h _ => h, fun h => ?_⟩
refine (le_or_gt i n).elim h fun k => ?_
exact
(coeff_eq_zero_of_natDegree_lt (hp.trans_lt k)).trans
(coeff_eq_zero_of_natDegree_lt (hq.trans_lt k)).symm
theorem ext_iff_degree_le {p q : R[X]} {n : ℕ} (hp : p.degree ≤ n) (hq : q.degree ≤ n) :
p = q ↔ ∀ i ≤ n, p.coeff i = q.coeff i :=
ext_iff_natDegree_le (natDegree_le_of_degree_le hp) (natDegree_le_of_degree_le hq)
@[simp]
theorem coeff_natDegree_succ_eq_zero {p : R[X]} : p.coeff (p.natDegree + 1) = 0 :=
coeff_eq_zero_of_natDegree_lt (lt_add_one _)
-- We need the explicit `Decidable` argument here because an exotic one shows up in a moment!
theorem ite_le_natDegree_coeff (p : R[X]) (n : ℕ) (I : Decidable (n < 1 + natDegree p)) :
@ite _ (n < 1 + natDegree p) I (coeff p n) 0 = coeff p n := by
split_ifs with h
· rfl
· exact (coeff_eq_zero_of_natDegree_lt (not_le.1 fun w => h (Nat.lt_one_add_iff.2 w))).symm
end Semiring
section Ring
variable [Ring R]
theorem coeff_mul_X_sub_C {p : R[X]} {r : R} {a : ℕ} :
coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r := by simp [mul_sub]
theorem coeff_X_sub_C_mul {p : R[X]} {r : R} {a : ℕ} :
coeff ((X - C r) * p) (a + 1) = coeff p a - r * coeff p (a + 1) := by simp [sub_mul]
end Ring
section Semiring
variable [Semiring R] {p q : R[X]} {ι : Type*}
theorem coeff_natDegree_eq_zero_of_degree_lt (h : degree p < degree q) :
coeff p (natDegree q) = 0 :=
coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_natDegree)
theorem ne_zero_of_degree_gt {n : WithBot ℕ} (h : n < degree p) : p ≠ 0 :=
mt degree_eq_bot.2 h.ne_bot
theorem ne_zero_of_degree_ge_degree (hpq : p.degree ≤ q.degree) (hp : p ≠ 0) : q ≠ 0 :=
Polynomial.ne_zero_of_degree_gt
(lt_of_lt_of_le (bot_lt_iff_ne_bot.mpr (by rwa [Ne, Polynomial.degree_eq_bot])) hpq :
q.degree > ⊥)
theorem ne_zero_of_natDegree_gt {n : ℕ} (h : n < natDegree p) : p ≠ 0 := fun H => by
simp [H] at h
theorem degree_lt_degree (h : natDegree p < natDegree q) : degree p < degree q := by
by_cases hp : p = 0
· simp only [hp, degree_zero]
rw [bot_lt_iff_ne_bot]
intro hq
simp [hp, degree_eq_bot.mp hq] at h
· rwa [degree_eq_natDegree hp, degree_eq_natDegree <| ne_zero_of_natDegree_gt h, Nat.cast_lt]
theorem natDegree_lt_natDegree_iff (hp : p ≠ 0) : natDegree p < natDegree q ↔ degree p < degree q :=
⟨degree_lt_degree, fun h ↦ by
have hq : q ≠ 0 := ne_zero_of_degree_gt h
rwa [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt] at h⟩
theorem eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) := by
ext (_ | n)
· simp
rw [coeff_C, if_neg (Nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt]
exact h.trans_lt (WithBot.coe_lt_coe.2 n.succ_pos)
theorem eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) :=
eq_C_of_degree_le_zero h.le
theorem degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) :=
⟨eq_C_of_degree_le_zero, fun h => h.symm ▸ degree_C_le⟩
theorem degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p :=
le_antisymm (max_eq_left_of_lt h ▸ degree_add_le _ _) <|
degree_le_degree <| by
rw [coeff_add, coeff_natDegree_eq_zero_of_degree_lt h, add_zero]
exact mt leadingCoeff_eq_zero.1 (ne_zero_of_degree_gt h)
theorem degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q := by
rw [add_comm, degree_add_eq_left_of_degree_lt h]
theorem natDegree_add_eq_left_of_degree_lt (h : degree q < degree p) :
natDegree (p + q) = natDegree p :=
natDegree_eq_of_degree_eq (degree_add_eq_left_of_degree_lt h)
theorem natDegree_add_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) :
natDegree (p + q) = natDegree p :=
natDegree_add_eq_left_of_degree_lt (degree_lt_degree h)
theorem natDegree_add_eq_right_of_degree_lt (h : degree p < degree q) :
natDegree (p + q) = natDegree q :=
natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h)
theorem natDegree_add_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) :
natDegree (p + q) = natDegree q :=
natDegree_add_eq_right_of_degree_lt (degree_lt_degree h)
theorem degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p :=
add_comm (C a) p ▸ degree_add_eq_right_of_degree_lt <| lt_of_le_of_lt degree_C_le hp
@[simp] theorem natDegree_add_C {a : R} : (p + C a).natDegree = p.natDegree := by
rcases eq_or_ne p 0 with rfl | hp
· simp
by_cases! hpd : p.degree ≤ 0
· rw [eq_C_of_degree_le_zero hpd, ← C_add, natDegree_C, natDegree_C]
· rw [degree_eq_natDegree hp, Nat.cast_pos, ← natDegree_C a] at hpd
exact natDegree_add_eq_left_of_natDegree_lt hpd
@[simp] theorem natDegree_C_add {a : R} : (C a + p).natDegree = p.natDegree := by
simp [add_comm _ p]
theorem degree_add_eq_of_leadingCoeff_add_ne_zero (h : leadingCoeff p + leadingCoeff q ≠ 0) :
degree (p + q) = max p.degree q.degree :=
le_antisymm (degree_add_le _ _) <|
match lt_trichotomy (degree p) (degree q) with
| Or.inl hlt => by
rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt]
| Or.inr (Or.inl HEq) =>
le_of_not_gt fun hlt : max (degree p) (degree q) > degree (p + q) =>
h <|
show leadingCoeff p + leadingCoeff q = 0 by
rw [HEq, max_self] at hlt
rw [leadingCoeff, leadingCoeff, natDegree_eq_of_degree_eq HEq, ← coeff_add]
exact coeff_natDegree_eq_zero_of_degree_lt hlt
| Or.inr (Or.inr hlt) => by
rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt]
lemma natDegree_eq_of_natDegree_add_lt_left (p q : R[X])
(H : natDegree (p + q) < natDegree p) : natDegree p = natDegree q := by
by_contra h
cases Nat.lt_or_lt_of_ne h with
| inl h => exact lt_asymm h (by rwa [natDegree_add_eq_right_of_natDegree_lt h] at H)
| inr h =>
rw [natDegree_add_eq_left_of_natDegree_lt h] at H
exact LT.lt.false H
lemma natDegree_eq_of_natDegree_add_lt_right (p q : R[X])
(H : natDegree (p + q) < natDegree q) : natDegree p = natDegree q :=
(natDegree_eq_of_natDegree_add_lt_left q p (add_comm p q ▸ H)).symm
lemma natDegree_eq_of_natDegree_add_eq_zero (p q : R[X])
(H : natDegree (p + q) = 0) : natDegree p = natDegree q := by
by_cases h₁ : natDegree p = 0; on_goal 1 => by_cases h₂ : natDegree q = 0
· exact h₁.trans h₂.symm
· apply natDegree_eq_of_natDegree_add_lt_right; rwa [H, Nat.pos_iff_ne_zero]
· apply natDegree_eq_of_natDegree_add_lt_left; rwa [H, Nat.pos_iff_ne_zero]
theorem monic_of_natDegree_le_of_coeff_eq_one (n : ℕ) (pn : p.natDegree ≤ n) (p1 : p.coeff n = 1) :
Monic p := by
unfold Monic
nontriviality
refine (congr_arg _ <| natDegree_eq_of_le_of_coeff_ne_zero pn ?_).trans p1
exact ne_of_eq_of_ne p1 one_ne_zero
theorem monic_of_degree_le (n : ℕ) (pn : p.degree ≤ n) (p1 : p.coeff n = 1) : Monic p :=
monic_of_natDegree_le_of_coeff_eq_one n (natDegree_le_of_degree_le pn) p1
@[deprecated (since := "2025-10-24")]
alias monic_of_degree_le_of_coeff_eq_one := monic_of_degree_le
theorem leadingCoeff_add_of_degree_lt (h : degree p < degree q) :
leadingCoeff (p + q) = leadingCoeff q := by
have : coeff p (natDegree q) = 0 := coeff_natDegree_eq_zero_of_degree_lt h
simp only [leadingCoeff, natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h), this,
coeff_add, zero_add]
theorem leadingCoeff_add_of_degree_lt' (h : degree q < degree p) :
leadingCoeff (p + q) = leadingCoeff p := by
rw [add_comm]
exact leadingCoeff_add_of_degree_lt h
theorem leadingCoeff_add_of_degree_eq (h : degree p = degree q)
(hlc : leadingCoeff p + leadingCoeff q ≠ 0) :
leadingCoeff (p + q) = leadingCoeff p + leadingCoeff q := by
have : natDegree (p + q) = natDegree p := by
apply natDegree_eq_of_degree_eq
rw [degree_add_eq_of_leadingCoeff_add_ne_zero hlc, h, max_self]
simp only [leadingCoeff, this, natDegree_eq_of_degree_eq h, coeff_add]
@[simp]
theorem coeff_mul_degree_add_degree (p q : R[X]) :
coeff (p * q) (natDegree p + natDegree q) = leadingCoeff p * leadingCoeff q :=
calc
coeff (p * q) (natDegree p + natDegree q) =
∑ x ∈ antidiagonal (natDegree p + natDegree q), coeff p x.1 * coeff q x.2 :=
coeff_mul _ _ _
_ = coeff p (natDegree p) * coeff q (natDegree q) := by
refine Finset.sum_eq_single (natDegree p, natDegree q) ?_ ?_
· rintro ⟨i, j⟩ h₁ h₂
rw [mem_antidiagonal] at h₁
by_cases H : natDegree p < i
· rw [coeff_eq_zero_of_degree_lt
(lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 H)),
zero_mul]
· rw [not_lt_iff_eq_or_lt] at H
rcases H with H | H
· simp_all
· suffices natDegree q < j by
rw [coeff_eq_zero_of_degree_lt
(lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 this)),
mul_zero]
by_contra! H'
exact
ne_of_lt (Nat.lt_of_lt_of_le (Nat.add_lt_add_right H j) (Nat.add_le_add_left H' _))
h₁
· intro H
exfalso
apply H
rw [mem_antidiagonal]
theorem degree_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) :
degree (p * q) = degree p + degree q :=
have hp : p ≠ 0 := by refine mt ?_ h; exact fun hp => by rw [hp, leadingCoeff_zero, zero_mul]
have hq : q ≠ 0 := by refine mt ?_ h; exact fun hq => by rw [hq, leadingCoeff_zero, mul_zero]
le_antisymm (degree_mul_le _ _)
(by
rw [degree_eq_natDegree hp, degree_eq_natDegree hq]
refine le_degree_of_ne_zero (n := natDegree p + natDegree q) ?_
rwa [coeff_mul_degree_add_degree])
theorem Monic.degree_mul (hq : Monic q) : degree (p * q) = degree p + degree q :=
letI := Classical.decEq R
if hp : p = 0 then by simp [hp]
else degree_mul' <| by rwa [hq.leadingCoeff, mul_one, Ne, leadingCoeff_eq_zero]
theorem natDegree_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) :
natDegree (p * q) = natDegree p + natDegree q :=
have hp : p ≠ 0 := mt leadingCoeff_eq_zero.2 fun h₁ => h <| by rw [h₁, zero_mul]
have hq : q ≠ 0 := mt leadingCoeff_eq_zero.2 fun h₁ => h <| by rw [h₁, mul_zero]
natDegree_eq_of_degree_eq_some <| by
rw [degree_mul' h, Nat.cast_add, degree_eq_natDegree hp, degree_eq_natDegree hq]
theorem leadingCoeff_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) :
leadingCoeff (p * q) = leadingCoeff p * leadingCoeff q := by
unfold leadingCoeff
rw [natDegree_mul' h, coeff_mul_degree_add_degree]
rfl
theorem leadingCoeff_pow' : leadingCoeff p ^ n ≠ 0 → leadingCoeff (p ^ n) = leadingCoeff p ^ n :=
Nat.recOn n (by simp) fun n ih h => by
have h₁ : leadingCoeff p ^ n ≠ 0 := fun h₁ => h <| by rw [pow_succ, h₁, zero_mul]
have h₂ : leadingCoeff p * leadingCoeff (p ^ n) ≠ 0 := by rwa [pow_succ', ← ih h₁] at h
rw [pow_succ', pow_succ', leadingCoeff_mul' h₂, ih h₁]
theorem degree_pow' : ∀ {n : ℕ}, leadingCoeff p ^ n ≠ 0 → degree (p ^ n) = n • degree p
| 0 => fun h => by rw [pow_zero, ← C_1] at *; rw [degree_C h, zero_nsmul]
| n + 1 => fun h => by
have h₁ : leadingCoeff p ^ n ≠ 0 := fun h₁ => h <| by rw [pow_succ, h₁, zero_mul]
have h₂ : leadingCoeff (p ^ n) * leadingCoeff p ≠ 0 := by
rwa [pow_succ, ← leadingCoeff_pow' h₁] at h
rw [pow_succ, degree_mul' h₂, succ_nsmul, degree_pow' h₁]
theorem natDegree_pow' {n : ℕ} (h : leadingCoeff p ^ n ≠ 0) : natDegree (p ^ n) = n * natDegree p :=
letI := Classical.decEq R
if hp0 : p = 0 then
if hn0 : n = 0 then by simp [*] else by rw [hp0, zero_pow hn0]; simp
else
have hpn : p ^ n ≠ 0 := fun hpn0 => by
have h1 := h
rw [← leadingCoeff_pow' h1, hpn0, leadingCoeff_zero] at h; exact h rfl
Option.some_inj.1 <|
show (natDegree (p ^ n) : WithBot ℕ) = (n * natDegree p : ℕ) by
rw [← degree_eq_natDegree hpn, degree_pow' h, degree_eq_natDegree hp0]; simp
theorem leadingCoeff_monic_mul {p q : R[X]} (hp : Monic p) :
leadingCoeff (p * q) = leadingCoeff q := by
rcases eq_or_ne q 0 with (rfl | H)
· simp
· rw [leadingCoeff_mul', hp.leadingCoeff, one_mul]
rwa [hp.leadingCoeff, one_mul, Ne, leadingCoeff_eq_zero]
theorem leadingCoeff_mul_monic {p q : R[X]} (hq : Monic q) :
leadingCoeff (p * q) = leadingCoeff p :=
letI := Classical.decEq R
Decidable.byCases
(fun H : leadingCoeff p = 0 => by
rw [H, leadingCoeff_eq_zero.1 H, zero_mul, leadingCoeff_zero])
fun H : leadingCoeff p ≠ 0 => by
rw [leadingCoeff_mul', hq.leadingCoeff, mul_one]
rwa [hq.leadingCoeff, mul_one]
lemma degree_C_mul_of_isUnit (ha : IsUnit a) (p : R[X]) : (C a * p).degree = p.degree := by
obtain rfl | hp := eq_or_ne p 0
· simp
nontriviality R
rw [degree_mul', degree_C ha.ne_zero]
· simp
· simpa [ha.mul_right_eq_zero]
lemma degree_mul_C_of_isUnit (ha : IsUnit a) (p : R[X]) : (p * C a).degree = p.degree := by
obtain rfl | hp := eq_or_ne p 0
· simp
nontriviality R
rw [degree_mul', degree_C ha.ne_zero]
· simp
· simpa [ha.mul_left_eq_zero]
lemma natDegree_C_mul_of_isUnit (ha : IsUnit a) (p : R[X]) : (C a * p).natDegree = p.natDegree := by
simp [natDegree, degree_C_mul_of_isUnit ha]
lemma natDegree_mul_C_of_isUnit (ha : IsUnit a) (p : R[X]) : (p * C a).natDegree = p.natDegree := by
simp [natDegree, degree_mul_C_of_isUnit ha]
lemma leadingCoeff_C_mul_of_isUnit (ha : IsUnit a) (p : R[X]) :
(C a * p).leadingCoeff = a * p.leadingCoeff := by
rwa [leadingCoeff, coeff_C_mul, natDegree_C_mul_of_isUnit, leadingCoeff]
lemma leadingCoeff_mul_C_of_isUnit (ha : IsUnit a) (p : R[X]) :
(p * C a).leadingCoeff = p.leadingCoeff * a := by
rwa [leadingCoeff, coeff_mul_C, natDegree_mul_C_of_isUnit, leadingCoeff]
@[simp]
theorem leadingCoeff_mul_X_pow {p : R[X]} {n : ℕ} : leadingCoeff (p * X ^ n) = leadingCoeff p :=
leadingCoeff_mul_monic (monic_X_pow n)
@[simp]
theorem leadingCoeff_mul_X {p : R[X]} : leadingCoeff (p * X) = leadingCoeff p :=
leadingCoeff_mul_monic monic_X
@[simp]
theorem coeff_pow_mul_natDegree (p : R[X]) (n : ℕ) :
(p ^ n).coeff (n * p.natDegree) = p.leadingCoeff ^ n := by
induction n with
| zero => simp
| succ i hi =>
rw [pow_succ, pow_succ, Nat.succ_mul]
by_cases hp1 : p.leadingCoeff ^ i = 0
· rw [hp1, zero_mul]
by_cases hp2 : p ^ i = 0
· rw [hp2, zero_mul, coeff_zero]
· apply coeff_eq_zero_of_natDegree_lt
have h1 : (p ^ i).natDegree < i * p.natDegree := by
refine lt_of_le_of_ne natDegree_pow_le fun h => hp2 ?_
rw [← h, hp1] at hi
exact leadingCoeff_eq_zero.mp hi
calc
(p ^ i * p).natDegree ≤ (p ^ i).natDegree + p.natDegree := natDegree_mul_le
_ < i * p.natDegree + p.natDegree := by gcongr
· rw [← natDegree_pow' hp1, ← leadingCoeff_pow' hp1]
exact coeff_mul_degree_add_degree _ _
theorem coeff_mul_add_eq_of_natDegree_le {df dg : ℕ} {f g : R[X]}
(hdf : natDegree f ≤ df) (hdg : natDegree g ≤ dg) :
(f * g).coeff (df + dg) = f.coeff df * g.coeff dg := by
rw [coeff_mul, Finset.sum_eq_single_of_mem (df, dg)]
· rw [mem_antidiagonal]
rintro ⟨df', dg'⟩ hmem hne
obtain h | hdf' := lt_or_ge df df'
· rw [coeff_eq_zero_of_natDegree_lt (hdf.trans_lt h), zero_mul]
obtain h | hdg' := lt_or_ge dg dg'
· rw [coeff_eq_zero_of_natDegree_lt (hdg.trans_lt h), mul_zero]
obtain ⟨rfl, rfl⟩ :=
(add_eq_add_iff_eq_and_eq hdf' hdg').mp (mem_antidiagonal.1 hmem)
exact (hne rfl).elim
theorem degree_smul_le {S : Type*} [SMulZeroClass S R] (a : S) (p : R[X]) :
degree (a • p) ≤ degree p := by
refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_
rw [degree_lt_iff_coeff_zero] at hm
simp [hm m le_rfl]
theorem natDegree_smul_le {S : Type*} [SMulZeroClass S R] (a : S) (p : R[X]) :
natDegree (a • p) ≤ natDegree p :=
natDegree_le_natDegree (degree_smul_le a p)
theorem degree_smul_of_isRightRegular_leadingCoeff (ha : a ≠ 0)
(hp : IsRightRegular p.leadingCoeff) : (a • p).degree = p.degree := by
refine le_antisymm (degree_smul_le a p) <| degree_le_degree ?_
rw [coeff_smul, coeff_natDegree, smul_eq_mul, ne_eq]
exact hp.mul_right_eq_zero_iff.ne.mpr ha
theorem degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree := by
haveI := Nontrivial.of_polynomial_ne hp
have : leadingCoeff p * leadingCoeff X ≠ 0 := by simpa
rw [degree_mul' this, degree_eq_natDegree hp, degree_X, ← Nat.cast_one, ← Nat.cast_add]
norm_cast
exact Nat.lt_succ_self _
theorem eq_C_of_natDegree_le_zero (h : natDegree p ≤ 0) : p = C (coeff p 0) :=
eq_C_of_degree_le_zero <| degree_le_of_natDegree_le h
theorem eq_C_of_natDegree_eq_zero (h : natDegree p = 0) : p = C (coeff p 0) :=
eq_C_of_natDegree_le_zero h.le
lemma natDegree_eq_zero {p : R[X]} : p.natDegree = 0 ↔ ∃ x, C x = p :=
⟨fun h ↦ ⟨_, (eq_C_of_natDegree_eq_zero h).symm⟩, by aesop⟩
theorem eq_C_coeff_zero_iff_natDegree_eq_zero : p = C (p.coeff 0) ↔ p.natDegree = 0 :=
⟨fun h ↦ by rw [h, natDegree_C], eq_C_of_natDegree_eq_zero⟩
theorem eq_one_of_monic_natDegree_zero (hf : p.Monic) (hfd : p.natDegree = 0) : p = 1 := by
rw [Monic.def, leadingCoeff, hfd] at hf
rw [eq_C_of_natDegree_eq_zero hfd, hf, map_one]
@[simp]
theorem Monic.natDegree_eq_zero (hf : p.Monic) : p.natDegree = 0 ↔ p = 1 :=
⟨eq_one_of_monic_natDegree_zero hf, by rintro rfl; simp⟩
theorem degree_sum_fin_lt {n : ℕ} (f : Fin n → R) :
degree (∑ i : Fin n, C (f i) * X ^ (i : ℕ)) < n :=
(degree_sum_le _ _).trans_lt <|
(Finset.sup_lt_iff <| WithBot.bot_lt_coe n).2 fun k _hk =>
(degree_C_mul_X_pow_le _ _).trans_lt <| WithBot.coe_lt_coe.2 k.is_lt
theorem degree_C_lt_degree_C_mul_X (ha : a ≠ 0) : degree (C b) < degree (C a * X) := by
simpa only [degree_C_mul_X ha] using degree_C_lt
end Semiring
section NontrivialSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ)
@[simp] lemma natDegree_mul_X (hp : p ≠ 0) : natDegree (p * X) = natDegree p + 1 := by
rw [natDegree_mul' (by simpa), natDegree_X]
@[simp] lemma natDegree_X_mul (hp : p ≠ 0) : natDegree (X * p) = natDegree p + 1 := by
rw [commute_X p, natDegree_mul_X hp]
@[simp] lemma natDegree_mul_X_pow (hp : p ≠ 0) : natDegree (p * X ^ n) = natDegree p + n := by
rw [natDegree_mul' (by simpa), natDegree_X_pow]
@[simp] lemma natDegree_X_pow_mul (hp : p ≠ 0) : natDegree (X ^ n * p) = natDegree p + n := by
rw [commute_X_pow, natDegree_mul_X_pow n hp]
-- This lemma explicitly does not require the `Nontrivial R` assumption.
theorem natDegree_X_pow_le {R : Type*} [Semiring R] (n : ℕ) : (X ^ n : R[X]).natDegree ≤ n := by
nontriviality R
rw [Polynomial.natDegree_X_pow]
theorem not_isUnit_X : ¬IsUnit (X : R[X]) := fun ⟨⟨_, g, _hfg, hgf⟩, rfl⟩ =>
zero_ne_one' R <| by
rw [← coeff_one_zero, ← hgf]
simp
@[simp]
theorem degree_mul_X : degree (p * X) = degree p + 1 := by simp [monic_X.degree_mul]
@[simp]
theorem degree_mul_X_pow : degree (p * X ^ n) = degree p + n := by simp [(monic_X_pow n).degree_mul]
end NontrivialSemiring
section Ring
variable [Ring R] {p q : R[X]}
theorem degree_sub_C (hp : 0 < degree p) : degree (p - C a) = degree p := by
rw [sub_eq_add_neg, ← C_neg, degree_add_C hp]
@[simp]
theorem natDegree_sub_C {a : R} : natDegree (p - C a) = natDegree p := by
rw [sub_eq_add_neg, ← C_neg, natDegree_add_C]
theorem leadingCoeff_sub_of_degree_lt (h : Polynomial.degree q < Polynomial.degree p) :
(p - q).leadingCoeff = p.leadingCoeff := by
rw [← q.degree_neg] at h
rw [sub_eq_add_neg, leadingCoeff_add_of_degree_lt' h]
theorem leadingCoeff_sub_of_degree_lt' (h : Polynomial.degree p < Polynomial.degree q) :
(p - q).leadingCoeff = -q.leadingCoeff := by
rw [← q.degree_neg] at h
rw [sub_eq_add_neg, leadingCoeff_add_of_degree_lt h, leadingCoeff_neg]
theorem leadingCoeff_sub_of_degree_eq (h : degree p = degree q)
(hlc : leadingCoeff p ≠ leadingCoeff q) :
leadingCoeff (p - q) = leadingCoeff p - leadingCoeff q := by
replace h : degree p = degree (-q) := by rwa [q.degree_neg]
replace hlc : leadingCoeff p + leadingCoeff (-q) ≠ 0 := by
rwa [← sub_ne_zero, sub_eq_add_neg, ← q.leadingCoeff_neg] at hlc
rw [sub_eq_add_neg, leadingCoeff_add_of_degree_eq h hlc, leadingCoeff_neg, sub_eq_add_neg]
theorem degree_sub_eq_left_of_degree_lt (h : degree q < degree p) : degree (p - q) = degree p := by
rw [← degree_neg q] at h
rw [sub_eq_add_neg, degree_add_eq_left_of_degree_lt h]
theorem degree_sub_eq_right_of_degree_lt (h : degree p < degree q) : degree (p - q) = degree q := by
rw [← degree_neg q] at h
rw [sub_eq_add_neg, degree_add_eq_right_of_degree_lt h, degree_neg]
theorem natDegree_sub_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) :
natDegree (p - q) = natDegree p :=
natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt (degree_lt_degree h))
theorem natDegree_sub_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) :
natDegree (p - q) = natDegree q :=
natDegree_eq_of_degree_eq (degree_sub_eq_right_of_degree_lt (degree_lt_degree h))
end Ring
section NonzeroRing
variable [Nontrivial R]
section Semiring
variable [Semiring R]
@[simp]
theorem degree_X_add_C (a : R) : degree (X + C a) = 1 := by
have : degree (C a) < degree (X : R[X]) :=
calc
degree (C a) ≤ 0 := degree_C_le
_ < 1 := WithBot.coe_lt_coe.mpr zero_lt_one
_ = degree X := degree_X.symm
rw [degree_add_eq_left_of_degree_lt this, degree_X]
theorem natDegree_X_add_C (x : R) : (X + C x).natDegree = 1 :=
natDegree_eq_of_degree_eq_some <| degree_X_add_C x
@[simp]
theorem nextCoeff_X_add_C [Semiring S] (c : S) : nextCoeff (X + C c) = c := by
nontriviality S
simp [nextCoeff_of_natDegree_pos]
theorem degree_X_pow_add_C {n : ℕ} (hn : 0 < n) (a : R) : degree ((X : R[X]) ^ n + C a) = n := by
have : degree (C a) < degree ((X : R[X]) ^ n) := degree_C_le.trans_lt <| by
rwa [degree_X_pow, Nat.cast_pos]
rw [degree_add_eq_left_of_degree_lt this, degree_X_pow]
theorem X_pow_add_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a ≠ 0 :=
mt degree_eq_bot.2
(show degree ((X : R[X]) ^ n + C a) ≠ ⊥ by
rw [degree_X_pow_add_C hn a]; exact WithBot.coe_ne_bot)
theorem X_add_C_ne_zero (r : R) : X + C r ≠ 0 :=
pow_one (X : R[X]) ▸ X_pow_add_C_ne_zero zero_lt_one r
theorem zero_notMem_multiset_map_X_add_C {α : Type*} (m : Multiset α) (f : α → R) :
(0 : R[X]) ∉ m.map fun a => X + C (f a) := fun mem =>
let ⟨_a, _, ha⟩ := Multiset.mem_map.mp mem
X_add_C_ne_zero _ ha
@[deprecated (since := "2025-05-24")]
alias zero_nmem_multiset_map_X_add_C := zero_notMem_multiset_map_X_add_C
theorem natDegree_X_pow_add_C {n : ℕ} {r : R} : (X ^ n + C r).natDegree = n := by
simp
theorem X_pow_add_C_ne_one {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a ≠ 1 := fun h =>
hn.ne' <| by simpa only [natDegree_X_pow_add_C, natDegree_one] using congr_arg natDegree h
theorem X_add_C_ne_one (r : R) : X + C r ≠ 1 :=
pow_one (X : R[X]) ▸ X_pow_add_C_ne_one zero_lt_one r
end Semiring
end NonzeroRing
section Semiring
variable [Semiring R]
@[simp]
theorem leadingCoeff_X_pow_add_C {n : ℕ} (hn : 0 < n) {r : R} :
(X ^ n + C r).leadingCoeff = 1 := by
nontriviality R
rw [leadingCoeff, natDegree_X_pow_add_C, coeff_add, coeff_X_pow_self, coeff_C,
if_neg (pos_iff_ne_zero.mp hn), add_zero]
@[simp]
theorem leadingCoeff_X_add_C [Semiring S] (r : S) : (X + C r).leadingCoeff = 1 := by
rw [← pow_one (X : S[X]), leadingCoeff_X_pow_add_C zero_lt_one]
@[simp]
theorem leadingCoeff_X_pow_add_one {n : ℕ} (hn : 0 < n) : (X ^ n + 1 : R[X]).leadingCoeff = 1 :=
leadingCoeff_X_pow_add_C hn
@[simp]
theorem leadingCoeff_pow_X_add_C (r : R) (i : ℕ) : leadingCoeff ((X + C r) ^ i) = 1 := by
nontriviality
rw [leadingCoeff_pow'] <;> simp
variable [NoZeroDivisors R] {p q : R[X]}
@[simp]
lemma degree_mul : degree (p * q) = degree p + degree q :=
letI := Classical.decEq R
if hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, WithBot.bot_add]
else
if hq0 : q = 0 then by simp only [hq0, degree_zero, mul_zero, WithBot.add_bot]
else degree_mul' <| mul_ne_zero (mt leadingCoeff_eq_zero.1 hp0) (mt leadingCoeff_eq_zero.1 hq0)
/-- `degree` as a monoid homomorphism between `R[X]` and `Multiplicative (WithBot ℕ)`.
This is useful to prove results about multiplication and degree. -/
def degreeMonoidHom [Nontrivial R] : R[X] →* Multiplicative (WithBot ℕ) where
toFun := degree
map_one' := degree_one
map_mul' _ _ := degree_mul
@[simp]
lemma degree_pow [Nontrivial R] (p : R[X]) (n : ℕ) : degree (p ^ n) = n • degree p :=
map_pow (@degreeMonoidHom R _ _ _) _ _
@[simp]
lemma leadingCoeff_mul (p q : R[X]) : leadingCoeff (p * q) = leadingCoeff p * leadingCoeff q := by
by_cases hp : p = 0
· simp only [hp, zero_mul, leadingCoeff_zero]
· by_cases hq : q = 0
· simp only [hq, mul_zero, leadingCoeff_zero]
· rw [leadingCoeff_mul']
exact mul_ne_zero (mt leadingCoeff_eq_zero.1 hp) (mt leadingCoeff_eq_zero.1 hq)
/-- `Polynomial.leadingCoeff` bundled as a `MonoidHom` when `R` has `NoZeroDivisors`, and thus
`leadingCoeff` is multiplicative -/
def leadingCoeffHom : R[X] →* R where
toFun := leadingCoeff
map_one' := by simp
map_mul' := leadingCoeff_mul
@[simp]
lemma leadingCoeffHom_apply (p : R[X]) : leadingCoeffHom p = leadingCoeff p :=
rfl
@[simp]
lemma leadingCoeff_pow (p : R[X]) (n : ℕ) : leadingCoeff (p ^ n) = leadingCoeff p ^ n :=
(leadingCoeffHom : R[X] →* R).map_pow p n
lemma leadingCoeff_dvd_leadingCoeff {a p : R[X]} (hap : a ∣ p) :
a.leadingCoeff ∣ p.leadingCoeff :=
map_dvd leadingCoeffHom hap
lemma degree_le_mul_left (p : R[X]) (hq : q ≠ 0) : degree p ≤ degree (p * q) := by
classical
obtain rfl | hp := eq_or_ne p 0
· simp
· rw [degree_mul, degree_eq_natDegree hp, degree_eq_natDegree hq]
exact WithBot.coe_le_coe.2 (Nat.le_add_right _ _)
end Semiring
section CommSemiring
variable [CommSemiring R] {a p : R[X]} (hp : p.Monic)
include hp
lemma Monic.natDegree_pos : 0 < natDegree p ↔ p ≠ 1 :=
Nat.pos_iff_ne_zero.trans hp.natDegree_eq_zero.not
lemma Monic.degree_pos : 0 < degree p ↔ p ≠ 1 :=
natDegree_pos_iff_degree_pos.symm.trans hp.natDegree_pos
end CommSemiring
section Ring
variable [Ring R]
@[simp]
theorem leadingCoeff_X_pow_sub_C {n : ℕ} (hn : 0 < n) {r : R} :
(X ^ n - C r).leadingCoeff = 1 := by
rw [sub_eq_add_neg, ← map_neg C r, leadingCoeff_X_pow_add_C hn]
@[simp]
theorem leadingCoeff_X_pow_sub_one {n : ℕ} (hn : 0 < n) : (X ^ n - 1 : R[X]).leadingCoeff = 1 :=
leadingCoeff_X_pow_sub_C hn
variable [Nontrivial R]
@[simp]
theorem degree_X_sub_C (a : R) : degree (X - C a) = 1 := by
rw [sub_eq_add_neg, ← map_neg C a, degree_X_add_C]
theorem natDegree_X_sub_C (x : R) : (X - C x).natDegree = 1 := by
rw [natDegree_sub_C, natDegree_X]
@[simp]
theorem nextCoeff_X_sub_C [Ring S] (c : S) : nextCoeff (X - C c) = -c := by
rw [sub_eq_add_neg, ← map_neg C c, nextCoeff_X_add_C]
theorem degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) : degree ((X : R[X]) ^ n - C a) = n := by
rw [sub_eq_add_neg, ← map_neg C a, degree_X_pow_add_C hn]
theorem X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n - C a ≠ 0 := by
rw [sub_eq_add_neg, ← map_neg C a]
exact X_pow_add_C_ne_zero hn _
theorem X_sub_C_ne_zero (r : R) : X - C r ≠ 0 :=
pow_one (X : R[X]) ▸ X_pow_sub_C_ne_zero zero_lt_one r
theorem zero_notMem_multiset_map_X_sub_C {α : Type*} (m : Multiset α) (f : α → R) :
(0 : R[X]) ∉ m.map fun a => X - C (f a) := fun mem =>
let ⟨_a, _, ha⟩ := Multiset.mem_map.mp mem
X_sub_C_ne_zero _ ha
@[deprecated (since := "2025-05-24")]
alias zero_nmem_multiset_map_X_sub_C := zero_notMem_multiset_map_X_sub_C
theorem natDegree_X_pow_sub_C {n : ℕ} {r : R} : (X ^ n - C r).natDegree = n := by
rw [sub_eq_add_neg, ← map_neg C r, natDegree_X_pow_add_C]
@[simp]
theorem leadingCoeff_X_sub_C [Ring S] (r : S) : (X - C r).leadingCoeff = 1 := by
rw [sub_eq_add_neg, ← map_neg C r, leadingCoeff_X_add_C]
end Ring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/IsMonicOfDegree.lean | import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Monic
/-!
# Monic polynomials of given degree
This file defines the predicate `Polynomial.IsMonicOfDegree p n` that states that
the polynomial `p` is monic and has degree `n` (i.e., `p.natDegree = n`.)
We also provide some basic API.
-/
namespace Polynomial
variable {R : Type*}
section Semiring
variable [Semiring R]
/-- This says that `p` has `natDegree` `n` and is monic. -/
@[mk_iff isMonicOfDegree_iff']
structure IsMonicOfDegree (p : R[X]) (n : ℕ) : Prop where
natDegree_eq : p.natDegree = n
monic : p.Monic
@[simp]
lemma isMonicOfDegree_zero_iff {p : R[X]} : IsMonicOfDegree p 0 ↔ p = 1 := by
simp only [isMonicOfDegree_iff']
refine ⟨fun ⟨H₁, H₂⟩ ↦ eq_one_of_monic_natDegree_zero H₂ H₁, fun H ↦ ?_⟩
subst H
simp
lemma IsMonicOfDegree.leadingCoeff_eq {p : R[X]} {n : ℕ} (hp : IsMonicOfDegree p n) :
p.leadingCoeff = 1 :=
Monic.def.mp hp.monic
@[simp]
lemma isMonicOfDegree_iff_of_subsingleton [Subsingleton R] {p : R[X]} {n : ℕ} :
IsMonicOfDegree p n ↔ n = 0 := by
rw [Subsingleton.eq_one p]
refine ⟨fun ⟨H, _⟩ ↦ ?_, fun H ↦ ?_⟩
· rwa [natDegree_one, eq_comm] at H
· rw [H, isMonicOfDegree_zero_iff]
lemma isMonicOfDegree_iff [Nontrivial R] (p : R[X]) (n : ℕ) :
IsMonicOfDegree p n ↔ p.natDegree ≤ n ∧ p.coeff n = 1 := by
simp only [isMonicOfDegree_iff']
refine ⟨fun ⟨H₁, H₂⟩ ↦ ⟨H₁.le, H₁ ▸ Monic.coeff_natDegree H₂⟩, fun ⟨H₁, H₂⟩ ↦ ⟨?_, ?_⟩⟩
· exact natDegree_eq_of_le_of_coeff_ne_zero H₁ <| H₂ ▸ one_ne_zero
· exact monic_of_natDegree_le_of_coeff_eq_one n H₁ H₂
lemma IsMonicOfDegree.exists_natDegree_lt {p : R[X]} {n : ℕ} (hn : n ≠ 0)
(hp : IsMonicOfDegree p n) :
∃ q : R[X], p = X ^ n + q ∧ q.natDegree < n := by
refine ⟨p.eraseLead, ?_, ?_⟩
· nth_rewrite 1 [← p.eraseLead_add_C_mul_X_pow]
rw [add_comm, hp.natDegree_eq, hp.leadingCoeff_eq, map_one, one_mul]
· refine p.eraseLead_natDegree_le.trans_lt ?_
rw [hp.natDegree_eq]
cutsat
lemma IsMonicOfDegree.mul {p q : R[X]} {m n : ℕ} (hp : IsMonicOfDegree p m)
(hq : IsMonicOfDegree q n) :
IsMonicOfDegree (p * q) (m + n) := by
rcases subsingleton_or_nontrivial R with H | H
· simp only [isMonicOfDegree_iff_of_subsingleton, Nat.add_eq_zero] at hp hq ⊢
exact ⟨hp, hq⟩
refine ⟨?_, hp.monic.mul hq.monic⟩
have : p.leadingCoeff * q.leadingCoeff ≠ 0 := by
rw [hp.leadingCoeff_eq, hq.leadingCoeff_eq, one_mul]
exact one_ne_zero
rw [natDegree_mul' this, hp.natDegree_eq, hq.natDegree_eq]
lemma IsMonicOfDegree.pow {p : R[X]} {m : ℕ} (hp : IsMonicOfDegree p m) (n : ℕ) :
IsMonicOfDegree (p ^ n) (m * n) := by
induction n with
| zero => simp
| succ n ih =>
rw [pow_succ, mul_add, mul_one]
exact ih.mul hp
lemma IsMonicOfDegree.coeff_eq {p q : R[X]} {n : ℕ} (hp : IsMonicOfDegree p n)
(hq : IsMonicOfDegree q n) {m : ℕ} (hm : n ≤ m) :
p.coeff m = q.coeff m := by
nontriviality R
rw [isMonicOfDegree_iff] at hp hq
rcases eq_or_lt_of_le hm with rfl | hm
· rw [hp.2, hq.2]
· replace hp : p.natDegree < m := hp.1.trans_lt hm
replace hq : q.natDegree < m := hq.1.trans_lt hm
rw [coeff_eq_zero_of_natDegree_lt hp, coeff_eq_zero_of_natDegree_lt hq]
lemma IsMonicOfDegree.of_mul_left {p q : R[X]} {m n : ℕ} (hp : IsMonicOfDegree p m)
(hpq : IsMonicOfDegree (p * q) (m + n)) :
IsMonicOfDegree q n := by
rcases subsingleton_or_nontrivial R with H | H
· simp only [isMonicOfDegree_iff_of_subsingleton, Nat.add_eq_zero] at hpq ⊢
exact hpq.2
have h₂ : q.Monic := hp.monic.of_mul_monic_left hpq.monic
refine ⟨?_, h₂⟩
have := hpq.natDegree_eq
have h : p.leadingCoeff * q.leadingCoeff ≠ 0 := by
rw [hp.leadingCoeff_eq, h₂.leadingCoeff, one_mul]
exact one_ne_zero
rw [natDegree_mul' h, hp.natDegree_eq] at this
exact (Nat.add_left_cancel this.symm).symm
lemma IsMonicOfDegree.of_mul_right {p q : R[X]} {m n : ℕ} (hq : IsMonicOfDegree q n)
(hpq : IsMonicOfDegree (p * q) (m + n)) :
IsMonicOfDegree p m := by
rcases subsingleton_or_nontrivial R with H | H
· simp only [isMonicOfDegree_iff_of_subsingleton, Nat.add_eq_zero] at hpq ⊢
exact hpq.1
have h₂ : p.Monic := hq.monic.of_mul_monic_right hpq.monic
refine ⟨?_, h₂⟩
have := hpq.natDegree_eq
have h : p.leadingCoeff * q.leadingCoeff ≠ 0 := by
rw [h₂.leadingCoeff, hq.leadingCoeff_eq, one_mul]
exact one_ne_zero
rw [natDegree_mul' h, hq.natDegree_eq] at this
exact (Nat.add_right_cancel this.symm).symm
lemma IsMonicOfDegree.add_right {p q : R[X]} {n : ℕ} (hp : IsMonicOfDegree p n)
(hq : q.natDegree < n) :
IsMonicOfDegree (p + q) n := by
rcases subsingleton_or_nontrivial R with H | H
· simpa using hp
refine (isMonicOfDegree_iff ..).mpr ⟨?_, ?_⟩
· exact natDegree_add_le_of_degree_le hp.natDegree_eq.le hq.le
· rw [coeff_add_eq_left_of_lt hq]
exact ((isMonicOfDegree_iff p n).mp hp).2
lemma IsMonicOfDegree.add_left {p q : R[X]} {n : ℕ} (hp : p.natDegree < n)
(hq : IsMonicOfDegree q n) :
IsMonicOfDegree (p + q) n := by
rw [add_comm]
exact hq.add_right hp
lemma IsMonicOfDegree.comp {p q : R[X]} {m n : ℕ} (hn : n ≠ 0) (hp : IsMonicOfDegree p m)
(hq : IsMonicOfDegree q n) :
IsMonicOfDegree (p.comp q) (m * n) := by
rcases subsingleton_or_nontrivial R with h | h
· simp only [isMonicOfDegree_iff_of_subsingleton, mul_eq_zero] at hp ⊢
exact .inl hp
rw [← hp.natDegree_eq, ← hq.natDegree_eq]
refine (isMonicOfDegree_iff ..).mpr ⟨natDegree_comp_le, ?_⟩
rw [coeff_comp_degree_mul_degree (hq.natDegree_eq ▸ hn), hp.leadingCoeff_eq, hq.leadingCoeff_eq,
one_pow, one_mul]
variable [Nontrivial R]
lemma IsMonicOfDegree.ne_zero {p : R[X]} {n : ℕ} (h : IsMonicOfDegree p n) : p ≠ 0 :=
h.monic.ne_zero
variable (R) in
lemma isMonicOfDegree_X : IsMonicOfDegree (X : R[X]) 1 :=
(isMonicOfDegree_iff ..).mpr ⟨natDegree_X_le, coeff_X_one⟩
variable (R) in
lemma isMonicOfDegree_X_pow (n : ℕ) : IsMonicOfDegree ((X : R[X]) ^ n) n :=
(isMonicOfDegree_iff ..).mpr ⟨natDegree_X_pow_le n, coeff_X_pow_self n⟩
lemma isMonicOfDegree_monomial_one (n : ℕ) : IsMonicOfDegree (monomial n (1 : R)) n := by
simpa only [monomial_one_right_eq_X_pow] using isMonicOfDegree_X_pow R n
lemma isMonicOfDegree_X_add_one (r : R) : IsMonicOfDegree (X + C r) 1 :=
(isMonicOfDegree_X R).add_right (by rw [natDegree_C]; exact zero_lt_one)
lemma isMonicOfDegree_one_iff {f : R[X]} : IsMonicOfDegree f 1 ↔ ∃ r : R, f = X + C r := by
refine ⟨fun H ↦ ?_, fun ⟨r, H⟩ ↦ H ▸ isMonicOfDegree_X_add_one r⟩
refine ⟨f.coeff 0, ?_⟩
ext1 n
rcases n.eq_zero_or_pos with rfl | hn
· simp
· exact H.coeff_eq (isMonicOfDegree_X_add_one _) (by cutsat)
lemma isMonicOfDegree_add_add_two (a b : R) : IsMonicOfDegree (X ^ 2 + C a * X + C b) 2 := by
rw [add_assoc]
exact (isMonicOfDegree_X_pow R 2).add_right <|
calc
_ ≤ max (C a * X).natDegree (C b).natDegree := natDegree_add_le ..
_ = (C a * X).natDegree := by simp
_ < 2 := natDegree_C_mul_le .. |>.trans natDegree_X_le |>.trans_lt one_lt_two
lemma isMonicOfDegree_two_iff {f : R[X]} :
IsMonicOfDegree f 2 ↔ ∃ a b : R, f = X ^ 2 + C a * X + C b := by
refine ⟨fun H ↦ ?_, fun ⟨a, b, h⟩ ↦ h ▸ isMonicOfDegree_add_add_two a b⟩
refine ⟨f.coeff 1, f.coeff 0, ext fun n ↦ ?_⟩
rcases lt_trichotomy n 1 with hn | rfl | hn
· obtain rfl : n = 0 := Nat.lt_one_iff.mp hn
simp
· simp
· exact H.coeff_eq (isMonicOfDegree_add_add_two ..) (by cutsat)
end Semiring
section Ring
variable [Ring R]
lemma IsMonicOfDegree.natDegree_sub_X_pow {p : R[X]} {n : ℕ} (hn : n ≠ 0)
(hp : IsMonicOfDegree p n) :
(p - X ^ n).natDegree < n := by
obtain ⟨q, hq₁, hq₂⟩ := hp.exists_natDegree_lt hn
simpa [hq₁]
lemma IsMonicOfDegree.natDegree_sub_lt {p q : R[X]} {n : ℕ} (hn : n ≠ 0) (hp : IsMonicOfDegree p n)
(hq : IsMonicOfDegree q n) :
(p - q).natDegree < n := by
rw [← sub_sub_sub_cancel_right p q (X ^ n)]
replace hp := hp.natDegree_sub_X_pow hn
replace hq := hq.natDegree_sub_X_pow hn
rw [← Nat.le_sub_one_iff_lt (Nat.zero_lt_of_ne_zero hn)] at hp hq ⊢
exact (natDegree_sub_le_iff_left hq).mpr hp
lemma IsMonicOfDegree.sub {p q : R[X]} {n : ℕ} (hp : IsMonicOfDegree p n) (hq : q.natDegree < n) :
IsMonicOfDegree (p - q) n := by
rw [sub_eq_add_neg]
exact hp.add_right <| (natDegree_neg q) ▸ hq
variable [Nontrivial R]
lemma isMonicOfDegree_X_sub_one (r : R) : IsMonicOfDegree (X - C r) 1 :=
(isMonicOfDegree_X R).sub (by rw [natDegree_C]; exact zero_lt_one)
lemma isMonicOfDegree_sub_add_two (a b : R) : IsMonicOfDegree (X ^ 2 - C a * X + C b) 2 := by
rw [sub_add]
exact (isMonicOfDegree_X_pow R 2).add_right <| by
rw [natDegree_neg]
calc
_ ≤ max (C a * X).natDegree (C b).natDegree := natDegree_sub_le ..
_ = (C a * X).natDegree := by simp
_ < 2 := natDegree_C_mul_le .. |>.trans natDegree_X_le |>.trans_lt one_lt_two
/-- A version of `Polynomial.isMonicOfDegree_two_iff` with negated middle coefficient. -/
lemma isMonicOfDegree_two_iff' {f : R[X]} :
IsMonicOfDegree f 2 ↔ ∃ a b : R, f = X ^ 2 - C a * X + C b := by
refine ⟨fun H ↦ ?_, fun ⟨a, b, h⟩ ↦ h ▸ isMonicOfDegree_sub_add_two a b⟩
simp only [sub_eq_add_neg, ← neg_mul, ← map_neg]
obtain ⟨a, b, h⟩ := isMonicOfDegree_two_iff.mp H
exact ⟨-a, b, (neg_neg a).symm ▸ h⟩
end Ring
section CommRing
variable [CommRing R]
lemma IsMonicOfDegree.of_dvd_add {a b r : R[X]} {m n : ℕ} (hmn : n ≤ m) (ha : IsMonicOfDegree a m)
(hb : IsMonicOfDegree b n) (hr : r.natDegree < m) (h : b ∣ a + r) :
∃ q : R[X], IsMonicOfDegree q (m - n) ∧ a = q * b - r := by
obtain ⟨q, hq⟩ := exists_eq_mul_left_of_dvd h
refine ⟨q, hb.of_mul_right ?_, eq_sub_iff_add_eq.mpr hq⟩
rw [← hq, show m - n + n = m by cutsat]
exact ha.add_right hr
lemma IsMonicOfDegree.of_dvd_sub {a b r : R[X]} {m n : ℕ} (hmn : n ≤ m) (ha : IsMonicOfDegree a m)
(hb : IsMonicOfDegree b n) (hr : r.natDegree < m) (h : b ∣ a - r) :
∃ q : R[X], IsMonicOfDegree q (m - n) ∧ a = q * b + r := by
convert ha.of_dvd_add hmn hb ?_ h using 4 with q
· rw [sub_neg_eq_add]
· rwa [natDegree_neg]
lemma IsMonicOfDegree.aeval_add {p : R[X]} {n : ℕ} (hp : IsMonicOfDegree p n) (r : R) :
IsMonicOfDegree (aeval (X + C r) p) n := by
rcases subsingleton_or_nontrivial R with H | H
· simpa using hp
rw [← mul_one n]
exact hp.comp one_ne_zero (isMonicOfDegree_X_add_one r)
lemma IsMonicOfDegree.aeval_sub {p : R[X]} {n : ℕ} (hp : IsMonicOfDegree p n) (r : R) :
IsMonicOfDegree (aeval (X - C r) p) n := by
rw [sub_eq_add_neg, ← map_neg]
exact aeval_add hp (-r)
end CommRing
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/Domain.lean | import Mathlib.Algebra.Polynomial.Degree.Operations
/-!
# Univariate polynomials form a domain
## Main results
* `Polynomial.instNoZeroDivisors`: `R[X]` has no zero divisors if `R` does not
* `Polynomial.instDomain`: `R[X]` is a domain if `R` is
-/
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] [NoZeroDivisors R] {p q : R[X]}
lemma natDegree_mul (hp : p ≠ 0) (hq : q ≠ 0) : (p*q).natDegree = p.natDegree + q.natDegree := by
rw [← Nat.cast_inj (R := WithBot ℕ), ← degree_eq_natDegree (mul_ne_zero hp hq),
Nat.cast_add, ← degree_eq_natDegree hp, ← degree_eq_natDegree hq, degree_mul]
omit [NoZeroDivisors R] in
variable (p) in
lemma natDegree_smul {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] {a : S}
(ha : a ≠ 0) : (a • p).natDegree = p.natDegree := by
by_cases hp : p = 0
· simp only [hp, smul_zero]
· apply natDegree_eq_of_le_of_coeff_ne_zero
· exact (natDegree_smul_le _ _).trans (le_refl _)
· simp only [coeff_smul]
apply smul_ne_zero ha
simp [hp]
@[simp]
lemma natDegree_pow (p : R[X]) (n : ℕ) : natDegree (p ^ n) = n * natDegree p := by
classical
obtain rfl | hp := eq_or_ne p 0
· obtain rfl | hn := eq_or_ne n 0 <;> simp [*]
exact natDegree_pow' <| by
rw [← leadingCoeff_pow, Ne, leadingCoeff_eq_zero]; exact pow_ne_zero _ hp
lemma natDegree_le_of_dvd (h1 : p ∣ q) (h2 : q ≠ 0) : p.natDegree ≤ q.natDegree := by
obtain ⟨q, rfl⟩ := h1
rw [mul_ne_zero_iff] at h2
rw [natDegree_mul h2.1 h2.2]; exact Nat.le_add_right _ _
lemma degree_le_of_dvd (h1 : p ∣ q) (h2 : q ≠ 0) : degree p ≤ degree q := by
rcases h1 with ⟨q, rfl⟩; rw [mul_ne_zero_iff] at h2
exact degree_le_mul_left p h2.2
lemma eq_zero_of_dvd_of_degree_lt (h₁ : p ∣ q) (h₂ : degree q < degree p) : q = 0 := by
by_contra hc
exact lt_iff_not_ge.mp h₂ (degree_le_of_dvd h₁ hc)
lemma eq_zero_of_dvd_of_natDegree_lt (h₁ : p ∣ q) (h₂ : natDegree q < natDegree p) :
q = 0 := by
by_contra hc
exact lt_iff_not_ge.mp h₂ (natDegree_le_of_dvd h₁ hc)
lemma not_dvd_of_degree_lt (h0 : q ≠ 0) (hl : q.degree < p.degree) : ¬p ∣ q := by
by_contra hcontra
exact h0 (eq_zero_of_dvd_of_degree_lt hcontra hl)
lemma not_dvd_of_natDegree_lt (h0 : q ≠ 0) (hl : q.natDegree < p.natDegree) :
¬p ∣ q := by
by_contra hcontra
exact h0 (eq_zero_of_dvd_of_natDegree_lt hcontra hl)
/-- This lemma is useful for working with the `intDegree` of a rational function. -/
lemma natDegree_sub_eq_of_prod_eq {p₁ p₂ q₁ q₂ : R[X]} (hp₁ : p₁ ≠ 0) (hq₁ : q₁ ≠ 0)
(hp₂ : p₂ ≠ 0) (hq₂ : q₂ ≠ 0) (h_eq : p₁ * q₂ = p₂ * q₁) :
(p₁.natDegree : ℤ) - q₁.natDegree = (p₂.natDegree : ℤ) - q₂.natDegree := by
rw [sub_eq_sub_iff_add_eq_add]
norm_cast
rw [← natDegree_mul hp₁ hq₂, ← natDegree_mul hp₂ hq₁, h_eq]
end Semiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/SmallDegree.lean | import Mathlib.Algebra.Polynomial.Degree.Operations
import Mathlib.Data.Nat.WithBot
/-!
# Results on polynomials of specific small degrees
-/
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
theorem eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) : p = C (p.coeff 1) * X + C (p.coeff 0) :=
ext fun n =>
Nat.casesOn n (by simp) fun n =>
Nat.casesOn n (by simp [coeff_C]) fun m => by
have : degree p < m.succ.succ := lt_of_le_of_lt h Nat.one_lt_ofNat
simp [coeff_eq_zero_of_degree_lt this]
theorem eq_X_add_C_of_degree_eq_one (h : degree p = 1) :
p = C p.leadingCoeff * X + C (p.coeff 0) :=
(eq_X_add_C_of_degree_le_one h.le).trans
(by rw [← Nat.cast_one] at h; rw [leadingCoeff, natDegree_eq_of_degree_eq_some h])
theorem eq_X_add_C_of_natDegree_le_one (h : natDegree p ≤ 1) :
p = C (p.coeff 1) * X + C (p.coeff 0) :=
eq_X_add_C_of_degree_le_one <| degree_le_of_natDegree_le h
theorem Monic.eq_X_add_C (hm : p.Monic) (hnd : p.natDegree = 1) : p = X + C (p.coeff 0) := by
rw [← one_mul X, ← C_1, ← hm.coeff_natDegree, hnd, ← eq_X_add_C_of_natDegree_le_one hnd.le]
theorem exists_eq_X_add_C_of_natDegree_le_one (h : natDegree p ≤ 1) : ∃ a b, p = C a * X + C b :=
⟨p.coeff 1, p.coeff 0, eq_X_add_C_of_natDegree_le_one h⟩
end Semiring
section Semiring
variable [Semiring R] {p q : R[X]} {ι : Type*}
theorem zero_le_degree_iff : 0 ≤ degree p ↔ p ≠ 0 := by
rw [← not_lt, Nat.WithBot.lt_zero_iff, degree_eq_bot]
theorem ne_zero_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : p ≠ 0 :=
zero_le_degree_iff.mp <| (WithBot.coe_le_coe.mpr n.zero_le).trans hdeg
theorem le_natDegree_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : n ≤ p.natDegree :=
WithBot.coe_le_coe.mp <| by
rwa [degree_eq_natDegree <| ne_zero_of_coe_le_degree hdeg] at hdeg
theorem degree_linear_le : degree (C a * X + C b) ≤ 1 :=
degree_add_le_of_degree_le (degree_C_mul_X_le _) <| le_trans degree_C_le Nat.WithBot.coe_nonneg
theorem degree_linear_lt : degree (C a * X + C b) < 2 :=
degree_linear_le.trans_lt <| WithBot.coe_lt_coe.mpr one_lt_two
@[simp]
theorem degree_linear (ha : a ≠ 0) : degree (C a * X + C b) = 1 := by
rw [degree_add_eq_left_of_degree_lt <| degree_C_lt_degree_C_mul_X ha, degree_C_mul_X ha]
theorem natDegree_linear_le : natDegree (C a * X + C b) ≤ 1 :=
natDegree_le_of_degree_le degree_linear_le
theorem natDegree_linear (ha : a ≠ 0) : natDegree (C a * X + C b) = 1 := by
rw [natDegree_add_C, natDegree_C_mul_X a ha]
@[simp]
theorem leadingCoeff_linear (ha : a ≠ 0) : leadingCoeff (C a * X + C b) = a := by
rw [add_comm, leadingCoeff_add_of_degree_lt (degree_C_lt_degree_C_mul_X ha),
leadingCoeff_C_mul_X]
theorem degree_quadratic_le : degree (C a * X ^ 2 + C b * X + C c) ≤ 2 := by
simpa only [add_assoc] using
degree_add_le_of_degree_le (degree_C_mul_X_pow_le 2 a)
(le_trans degree_linear_le <| WithBot.coe_le_coe.mpr one_le_two)
theorem degree_quadratic_lt : degree (C a * X ^ 2 + C b * X + C c) < 3 :=
degree_quadratic_le.trans_lt <| WithBot.coe_lt_coe.mpr <| lt_add_one 2
theorem degree_linear_lt_degree_C_mul_X_sq (ha : a ≠ 0) :
degree (C b * X + C c) < degree (C a * X ^ 2) := by
simpa only [degree_C_mul_X_pow 2 ha] using degree_linear_lt
@[simp]
theorem degree_quadratic (ha : a ≠ 0) : degree (C a * X ^ 2 + C b * X + C c) = 2 := by
rw [add_assoc, degree_add_eq_left_of_degree_lt <| degree_linear_lt_degree_C_mul_X_sq ha,
degree_C_mul_X_pow 2 ha]
rfl
theorem natDegree_quadratic_le : natDegree (C a * X ^ 2 + C b * X + C c) ≤ 2 :=
natDegree_le_of_degree_le degree_quadratic_le
theorem natDegree_quadratic (ha : a ≠ 0) : natDegree (C a * X ^ 2 + C b * X + C c) = 2 :=
natDegree_eq_of_degree_eq_some <| degree_quadratic ha
@[simp]
theorem leadingCoeff_quadratic (ha : a ≠ 0) : leadingCoeff (C a * X ^ 2 + C b * X + C c) = a := by
rw [add_assoc, add_comm, leadingCoeff_add_of_degree_lt <| degree_linear_lt_degree_C_mul_X_sq ha,
leadingCoeff_C_mul_X_pow]
theorem degree_cubic_le : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 := by
simpa only [add_assoc] using
degree_add_le_of_degree_le (degree_C_mul_X_pow_le 3 a)
(le_trans degree_quadratic_le <| WithBot.coe_le_coe.mpr <| Nat.le_succ 2)
theorem degree_cubic_lt : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) < 4 :=
degree_cubic_le.trans_lt <| WithBot.coe_lt_coe.mpr <| lt_add_one 3
theorem degree_quadratic_lt_degree_C_mul_X_cb (ha : a ≠ 0) :
degree (C b * X ^ 2 + C c * X + C d) < degree (C a * X ^ 3) := by
simpa only [degree_C_mul_X_pow 3 ha] using degree_quadratic_lt
@[simp]
theorem degree_cubic (ha : a ≠ 0) : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 := by
rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2),
degree_add_eq_left_of_degree_lt <| degree_quadratic_lt_degree_C_mul_X_cb ha,
degree_C_mul_X_pow 3 ha]
rfl
theorem natDegree_cubic_le : natDegree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 :=
natDegree_le_of_degree_le degree_cubic_le
theorem natDegree_cubic (ha : a ≠ 0) : natDegree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 :=
natDegree_eq_of_degree_eq_some <| degree_cubic ha
@[simp]
theorem leadingCoeff_cubic (ha : a ≠ 0) :
leadingCoeff (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = a := by
rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), add_comm,
leadingCoeff_add_of_degree_lt <| degree_quadratic_lt_degree_C_mul_X_cb ha,
leadingCoeff_C_mul_X_pow]
end Semiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Degree/Units.lean | import Mathlib.Algebra.Polynomial.Degree.Domain
import Mathlib.Algebra.Polynomial.Degree.SmallDegree
/-!
# Degree of polynomials that are units
-/
noncomputable section
open Finsupp Finset Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] [NoZeroDivisors R] {p q : R[X]}
lemma natDegree_eq_zero_of_isUnit (h : IsUnit p) : natDegree p = 0 := by
nontriviality R
obtain ⟨q, hq⟩ := h.exists_right_inv
have := natDegree_mul (left_ne_zero_of_mul_eq_one hq) (right_ne_zero_of_mul_eq_one hq)
rw [hq, natDegree_one, eq_comm, add_eq_zero] at this
exact this.1
lemma degree_eq_zero_of_isUnit [Nontrivial R] (h : IsUnit p) : degree p = 0 :=
(natDegree_eq_zero_iff_degree_le_zero.mp <| natDegree_eq_zero_of_isUnit h).antisymm
(zero_le_degree_iff.mpr h.ne_zero)
@[simp]
lemma degree_coe_units [Nontrivial R] (u : R[X]ˣ) : degree (u : R[X]) = 0 :=
degree_eq_zero_of_isUnit ⟨u, rfl⟩
/-- Characterization of a unit of a polynomial ring over an integral domain `R`.
See `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent` when `R` is a commutative ring. -/
lemma isUnit_iff : IsUnit p ↔ ∃ r : R, IsUnit r ∧ C r = p :=
⟨fun hp =>
⟨p.coeff 0,
let h := eq_C_of_natDegree_eq_zero (natDegree_eq_zero_of_isUnit hp)
⟨isUnit_C.1 (h ▸ hp), h.symm⟩⟩,
fun ⟨_, hr, hrp⟩ => hrp ▸ isUnit_C.2 hr⟩
lemma not_isUnit_of_degree_pos (p : R[X]) (hpl : 0 < p.degree) : ¬ IsUnit p := by
cases subsingleton_or_nontrivial R
· simp [Subsingleton.elim p 0] at hpl
intro h
simp [degree_eq_zero_of_isUnit h] at hpl
lemma not_isUnit_of_natDegree_pos (p : R[X]) (hpl : 0 < p.natDegree) : ¬ IsUnit p :=
not_isUnit_of_degree_pos _ (natDegree_pos_iff_degree_pos.mp hpl)
@[simp] lemma natDegree_coe_units (u : R[X]ˣ) : natDegree (u : R[X]) = 0 := by
nontriviality R
exact natDegree_eq_of_degree_eq_some (degree_coe_units u)
theorem coeff_coe_units_zero_ne_zero [Nontrivial R] (u : R[X]ˣ) : coeff (u : R[X]) 0 ≠ 0 := by
conv in 0 => rw [← natDegree_coe_units u]
rw [← leadingCoeff, Ne, leadingCoeff_eq_zero]
exact Units.ne_zero _
end Semiring
section CommSemiring
variable [CommSemiring R] {a p : R[X]} (hp : p.Monic)
include hp
lemma Monic.C_dvd_iff_isUnit {a : R} : C a ∣ p ↔ IsUnit a where
mp h := isUnit_iff_dvd_one.mpr <| hp.coeff_natDegree ▸ (C_dvd_iff_dvd_coeff _ _).mp h p.natDegree
mpr ha := (ha.map C).dvd
lemma Monic.degree_pos_of_not_isUnit (hu : ¬IsUnit p) : 0 < degree p :=
hp.degree_pos.mpr fun hp' ↦ (hp' ▸ hu) isUnit_one
lemma Monic.natDegree_pos_of_not_isUnit (hu : ¬IsUnit p) : 0 < natDegree p :=
hp.natDegree_pos.mpr fun hp' ↦ (hp' ▸ hu) isUnit_one
lemma degree_pos_of_not_isUnit_of_dvd_monic (ha : ¬IsUnit a) (hap : a ∣ p) : 0 < degree a := by
contrapose! ha with h
rw [Polynomial.eq_C_of_degree_le_zero h] at hap ⊢
simpa [hp.C_dvd_iff_isUnit, isUnit_C] using hap
lemma natDegree_pos_of_not_isUnit_of_dvd_monic (ha : ¬IsUnit a) (hap : a ∣ p) : 0 < natDegree a :=
natDegree_pos_iff_degree_pos.mpr <| degree_pos_of_not_isUnit_of_dvd_monic hp ha hap
end CommSemiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Eval/SMul.lean | import Mathlib.Algebra.Polynomial.Degree.Support
import Mathlib.Algebra.Polynomial.Eval.Defs
/-!
# Evaluating polynomials and scalar multiplication
## Main results
* `eval₂_smul`, `eval_smul`, `map_smul`, `comp_smul`: the functions preserve scalar multiplication
* `Polynomial.leval`: `Polynomial.eval` as linear map
-/
noncomputable section
open Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section
variable [Semiring S]
variable (f : R →+* S) (x : S)
@[simp]
theorem eval₂_smul (g : R →+* S) (p : R[X]) (x : S) {s : R} :
eval₂ g x (s • p) = g s * eval₂ g x p := by
have A : p.natDegree < p.natDegree.succ := Nat.lt_succ_self _
have B : (s • p).natDegree < p.natDegree.succ := (natDegree_smul_le _ _).trans_lt A
rw [eval₂_eq_sum, eval₂_eq_sum, sum_over_range' _ _ _ A, sum_over_range' _ _ _ B] <;>
simp [mul_sum, mul_assoc]
end
section Eval
variable {x : R}
@[simp]
theorem eval_smul [SMulZeroClass S R] [IsScalarTower S R R] (s : S) (p : R[X])
(x : R) : (s • p).eval x = s • p.eval x := by
rw [← smul_one_smul R s p, eval, eval₂_smul, RingHom.id_apply, smul_one_mul, eval₂_id]
/-- `Polynomial.eval` as linear map -/
@[simps]
def leval {R : Type*} [Semiring R] (r : R) : R[X] →ₗ[R] R where
toFun f := f.eval r
map_add' _f _g := eval_add
map_smul' c f := eval_smul c f r
end Eval
section Comp
@[simp]
theorem smul_comp [SMulZeroClass S R] [IsScalarTower S R R] (s : S) (p q : R[X]) :
(s • p).comp q = s • p.comp q := by
rw [← smul_one_smul R s p, comp, comp, eval₂_smul, ← smul_eq_C_mul, smul_assoc, one_smul]
end Comp
section Map
variable [Semiring S]
variable (f : R →+* S)
@[simp]
protected theorem map_smul (r : R) : (r • p).map f = f r • p.map f := by
rw [map, eval₂_smul, RingHom.comp_apply, C_mul']
end Map
end Semiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Eval/Subring.lean | import Mathlib.Algebra.Polynomial.Degree.Support
import Mathlib.Algebra.Polynomial.Eval.Coeff
import Mathlib.Algebra.Ring.Subring.Basic
/-!
# Evaluation of polynomials in subrings
## Main results
* `mem_map_rangeS`, `mem_map_range`: the range of `mapRingHom f` consists of
polynomials with coefficients in the range of `f`
-/
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
variable [Semiring R] {p q r : R[X]} [Semiring S]
variable (f : R →+* S)
theorem mem_map_rangeS {p : S[X]} : p ∈ (mapRingHom f).rangeS ↔ ∀ n, p.coeff n ∈ f.rangeS := by
constructor
· rintro ⟨p, rfl⟩ n
rw [coe_mapRingHom, coeff_map]
exact Set.mem_range_self _
· intro h
rw [p.as_sum_range_C_mul_X_pow]
refine (mapRingHom f).rangeS.sum_mem ?_
intro i _hi
rcases h i with ⟨c, hc⟩
use C c * X ^ i
rw [coe_mapRingHom, Polynomial.map_mul, map_C, hc, Polynomial.map_pow, map_X]
theorem mem_map_range {R S : Type*} [Ring R] [Ring S] (f : R →+* S) {p : S[X]} :
p ∈ (mapRingHom f).range ↔ ∀ n, p.coeff n ∈ f.range :=
mem_map_rangeS f
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Eval/Defs.lean | import Mathlib.Algebra.Group.Nat.Hom
import Mathlib.Algebra.Polynomial.Basic
/-!
# Evaluating a polynomial
## Main definitions
* `Polynomial.eval₂`: evaluate `p : R[X]` in `S` given a ring hom `f : R →+* S` and `x : S`.
* `Polynomial.eval`: evaluate `p : R[X]` given `x : R`.
* `Polynomial.IsRoot`: `x : R` is a root of `p : R[X]`.
* `Polynomial.comp`: compose two polynomials `p q : R[X]` by evaluating `p` at `q`.
* `Polynomial.map`: apply `f : R →+* S` to the coefficients of `p : R[X]`.
We also provide the following bundled versions:
* `Polynomial.eval₂AddMonoidHom`, `Polynomial.eval₂RingHom`
* `Polynomial.evalRingHom`
* `Polynomial.compRingHom`
* `Polynomial.mapRingHom`
We include results on applying the definitions to `C`, `X` and ring operations.
-/
noncomputable section
open Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section
variable [Semiring S]
variable (f : R →+* S) (x : S)
/-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring
to the target and a value `x` for the variable in the target -/
irreducible_def eval₂ (p : R[X]) : S :=
p.sum fun e a => f a * x ^ e
theorem eval₂_eq_sum {f : R →+* S} {x : S} : p.eval₂ f x = p.sum fun e a => f a * x ^ e := by
rw [eval₂_def]
theorem eval₂_congr {R S : Type*} [Semiring R] [Semiring S] {f g : R →+* S} {s t : S}
{φ ψ : R[X]} : f = g → s = t → φ = ψ → eval₂ f s φ = eval₂ g t ψ := by
rintro rfl rfl rfl; rfl
@[simp]
theorem eval₂_zero : (0 : R[X]).eval₂ f x = 0 := by simp [eval₂_eq_sum]
@[simp]
theorem eval₂_C : (C a).eval₂ f x = f a := by simp [eval₂_eq_sum]
@[simp]
theorem eval₂_X : X.eval₂ f x = x := by simp [eval₂_eq_sum]
@[simp]
theorem eval₂_monomial {n : ℕ} {r : R} : (monomial n r).eval₂ f x = f r * x ^ n := by
simp [eval₂_eq_sum]
@[simp]
theorem eval₂_X_pow {n : ℕ} : (X ^ n).eval₂ f x = x ^ n := by
rw [X_pow_eq_monomial]
convert eval₂_monomial f x (n := n) (r := 1)
simp
@[simp]
theorem eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x := by
simp only [eval₂_eq_sum]
apply sum_add_index <;> simp [add_mul]
@[simp]
theorem eval₂_one : (1 : R[X]).eval₂ f x = 1 := by rw [← C_1, eval₂_C, f.map_one]
/-- `eval₂AddMonoidHom (f : R →+* S) (x : S)` is the `AddMonoidHom` from
`R[X]` to `S` obtained by evaluating the pushforward of `p` along `f` at `x`. -/
@[simps]
def eval₂AddMonoidHom : R[X] →+ S where
toFun := eval₂ f x
map_zero' := eval₂_zero _ _
map_add' _ _ := eval₂_add _ _
@[simp]
theorem eval₂_natCast (n : ℕ) : (n : R[X]).eval₂ f x = n := by
induction n with
| zero => simp only [eval₂_zero, Nat.cast_zero]
| succ n ih => rw [n.cast_succ, eval₂_add, ih, eval₂_one, n.cast_succ]
@[simp]
lemma eval₂_ofNat {S : Type*} [Semiring S] (n : ℕ) [n.AtLeastTwo] (f : R →+* S) (a : S) :
(ofNat(n) : R[X]).eval₂ f a = ofNat(n) := by
simp [OfNat.ofNat]
variable [Semiring T]
theorem eval₂_sum (p : T[X]) (g : ℕ → T → R[X]) (x : S) :
(p.sum g).eval₂ f x = p.sum fun n a => (g n a).eval₂ f x := by
let T : R[X] →+ S :=
{ toFun := eval₂ f x
map_zero' := eval₂_zero _ _
map_add' := fun p q => eval₂_add _ _ }
have A : ∀ y, eval₂ f x y = T y := fun y => rfl
simp only [A]
rw [sum, map_sum, sum]
theorem eval₂_list_sum (l : List R[X]) (x : S) : eval₂ f x l.sum = (l.map (eval₂ f x)).sum :=
map_list_sum (eval₂AddMonoidHom f x) l
theorem eval₂_multiset_sum (s : Multiset R[X]) (x : S) :
eval₂ f x s.sum = (s.map (eval₂ f x)).sum :=
map_multiset_sum (eval₂AddMonoidHom f x) s
theorem eval₂_finset_sum (s : Finset ι) (g : ι → R[X]) (x : S) :
(∑ i ∈ s, g i).eval₂ f x = ∑ i ∈ s, (g i).eval₂ f x :=
map_sum (eval₂AddMonoidHom f x) _ _
theorem eval₂_ofFinsupp {f : R →+* S} {x : S} {p : R[ℕ]} :
eval₂ f x (⟨p⟩ : R[X]) = liftNC (↑f) (powersHom S x) p := by
simp only [eval₂_eq_sum, sum, support, coeff]
rfl
theorem eval₂_mul_noncomm (hf : ∀ k, Commute (f <| q.coeff k) x) :
eval₂ f x (p * q) = eval₂ f x p * eval₂ f x q := by
rcases p with ⟨p⟩; rcases q with ⟨q⟩
simp only [coeff] at hf
simp only [← ofFinsupp_mul, eval₂_ofFinsupp]
exact liftNC_mul _ _ p q fun {k n} _hn => (hf k).pow_right n
@[simp]
theorem eval₂_mul_X : eval₂ f x (p * X) = eval₂ f x p * x := by
refine _root_.trans (eval₂_mul_noncomm _ _ fun k => ?_) (by rw [eval₂_X])
rcases em (k = 1) with (rfl | hk)
· simp
· simp [coeff_X_of_ne_one hk]
@[simp]
theorem eval₂_X_mul : eval₂ f x (X * p) = eval₂ f x p * x := by rw [X_mul, eval₂_mul_X]
theorem eval₂_mul_C' (h : Commute (f a) x) : eval₂ f x (p * C a) = eval₂ f x p * f a := by
rw [eval₂_mul_noncomm, eval₂_C]
intro k
by_cases hk : k = 0
· simp only [hk, h, coeff_C_zero]
· simp only [coeff_C_ne_zero hk, RingHom.map_zero, Commute.zero_left]
theorem eval₂_list_prod_noncomm (ps : List R[X])
(hf : ∀ p ∈ ps, ∀ (k), Commute (f <| coeff p k) x) :
eval₂ f x ps.prod = (ps.map (Polynomial.eval₂ f x)).prod := by
induction ps using List.reverseRecOn with
| nil => simp
| append_singleton ps p ihp =>
simp only [List.forall_mem_append, List.forall_mem_singleton] at hf
simp [eval₂_mul_noncomm _ _ hf.2, ihp hf.1]
/-- `eval₂` as a `RingHom` for noncommutative rings -/
@[simps]
def eval₂RingHom' (f : R →+* S) (x : S) (hf : ∀ a, Commute (f a) x) : R[X] →+* S where
toFun := eval₂ f x
map_add' _ _ := eval₂_add _ _
map_zero' := eval₂_zero _ _
map_mul' _p q := eval₂_mul_noncomm f x fun k => hf <| coeff q k
map_one' := eval₂_one _ _
end
/-!
We next prove that eval₂ is multiplicative
as long as target ring is commutative
(even if the source ring is not).
-/
section Eval₂
section
variable [CommSemiring S] (f : R →+* S) (x : S)
@[simp]
theorem eval₂_mul : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x :=
eval₂_mul_noncomm _ _ fun _k => Commute.all _ _
theorem eval₂_mul_eq_zero_of_left (q : R[X]) (hp : p.eval₂ f x = 0) : (p * q).eval₂ f x = 0 := by
rw [eval₂_mul f x]
exact mul_eq_zero_of_left hp (q.eval₂ f x)
theorem eval₂_mul_eq_zero_of_right (p : R[X]) (hq : q.eval₂ f x = 0) : (p * q).eval₂ f x = 0 := by
rw [eval₂_mul f x]
exact mul_eq_zero_of_right (p.eval₂ f x) hq
/-- `eval₂` as a `RingHom` -/
def eval₂RingHom (f : R →+* S) (x : S) : R[X] →+* S :=
{ eval₂AddMonoidHom f x with
map_one' := eval₂_one _ _
map_mul' := fun _ _ => eval₂_mul _ _ }
@[simp]
theorem coe_eval₂RingHom (f : R →+* S) (x) : ⇑(eval₂RingHom f x) = eval₂ f x :=
rfl
theorem eval₂_pow (n : ℕ) : (p ^ n).eval₂ f x = p.eval₂ f x ^ n :=
(eval₂RingHom _ _).map_pow _ _
@[gcongr]
theorem eval₂_dvd : p ∣ q → eval₂ f x p ∣ eval₂ f x q :=
map_dvd (eval₂RingHom f x)
theorem eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (h : p ∣ q) (h0 : eval₂ f x p = 0) :
eval₂ f x q = 0 :=
zero_dvd_iff.mp (h0 ▸ eval₂_dvd f x h)
theorem eval₂_list_prod (l : List R[X]) (x : S) : eval₂ f x l.prod = (l.map (eval₂ f x)).prod :=
map_list_prod (eval₂RingHom f x) l
end
end Eval₂
section Eval
variable {x : R}
/-- `eval x p` is the evaluation of the polynomial `p` at `x` -/
def eval (x : R) (p : R[X]) : R :=
eval₂ (RingHom.id _) x p
@[simp]
theorem eval₂_id : eval₂ (RingHom.id _) x p = p.eval x := rfl
theorem eval_eq_sum : p.eval x = p.sum fun e a => a * x ^ e := by
rw [eval, eval₂_eq_sum]
rfl
@[simp]
theorem eval₂_at_apply {S : Type*} [Semiring S] (f : R →+* S) (r : R) :
p.eval₂ f (f r) = f (p.eval r) := by
rw [eval₂_eq_sum, eval_eq_sum, sum, sum, map_sum f]
simp only [f.map_mul, f.map_pow]
@[simp]
theorem eval₂_at_one {S : Type*} [Semiring S] (f : R →+* S) : p.eval₂ f 1 = f (p.eval 1) := by
convert eval₂_at_apply (p := p) f 1
simp
@[simp]
theorem eval₂_at_natCast {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) :
p.eval₂ f n = f (p.eval n) := by
convert eval₂_at_apply (p := p) f n
simp
@[simp]
theorem eval₂_at_ofNat {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) [n.AtLeastTwo] :
p.eval₂ f ofNat(n) = f (p.eval (ofNat(n))) := by
simp [OfNat.ofNat]
@[simp]
theorem eval_C : (C a).eval x = a :=
eval₂_C _ _
@[simp]
theorem eval_natCast {n : ℕ} : (n : R[X]).eval x = n := by simp only [← C_eq_natCast, eval_C]
@[simp]
lemma eval_ofNat (n : ℕ) [n.AtLeastTwo] (a : R) :
(ofNat(n) : R[X]).eval a = ofNat(n) := by
simp only [OfNat.ofNat, eval_natCast]
@[simp]
theorem eval_X : X.eval x = x :=
eval₂_X _ _
@[simp]
theorem eval_monomial {n a} : (monomial n a).eval x = a * x ^ n :=
eval₂_monomial _ _
@[simp]
theorem eval_zero : (0 : R[X]).eval x = 0 :=
eval₂_zero _ _
@[simp]
theorem eval_add : (p + q).eval x = p.eval x + q.eval x :=
eval₂_add _ _
@[simp]
theorem eval_one : (1 : R[X]).eval x = 1 :=
eval₂_one _ _
@[simp]
theorem eval_C_mul : (C a * p).eval x = a * p.eval x := by
induction p using Polynomial.induction_on' with
| add p q ph qh => simp only [mul_add, eval_add, ph, qh]
| monomial n b => simp only [mul_assoc, C_mul_monomial, eval_monomial]
@[simp]
theorem eval_natCast_mul {n : ℕ} : ((n : R[X]) * p).eval x = n * p.eval x := by
rw [← C_eq_natCast, eval_C_mul]
@[simp]
theorem eval_mul_X : (p * X).eval x = p.eval x * x := eval₂_mul_X ..
@[simp]
theorem eval_mul_X_pow {k : ℕ} : (p * X ^ k).eval x = p.eval x * x ^ k := by
induction k with
| zero => simp
| succ k ih => simp [pow_succ, ← mul_assoc, ih]
/-- Polynomial evaluation commutes with `List.sum`. -/
theorem eval_listSum (l : List R[X]) (x : R) : eval x l.sum = (l.map (eval x)).sum :=
eval₂_list_sum ..
/-- Polynomial evaluation commutes with `Multiset.sum`. -/
theorem eval_multisetSum (s : Multiset R[X]) (x : R) : eval x s.sum = (s.map (eval x)).sum :=
eval₂_multiset_sum ..
theorem eval_sum (p : R[X]) (f : ℕ → R → R[X]) (x : R) :
(p.sum f).eval x = p.sum fun n a => (f n a).eval x :=
eval₂_sum _ _ _ _
theorem eval_finset_sum (s : Finset ι) (g : ι → R[X]) (x : R) :
(∑ i ∈ s, g i).eval x = ∑ i ∈ s, (g i).eval x :=
eval₂_finset_sum _ _ _ _
/-- `IsRoot p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/
def IsRoot (p : R[X]) (a : R) : Prop :=
p.eval a = 0
instance IsRoot.decidable [DecidableEq R] : Decidable (IsRoot p a) := by
unfold IsRoot; infer_instance
@[simp]
theorem IsRoot.def : IsRoot p a ↔ p.eval a = 0 :=
Iff.rfl
theorem IsRoot.eq_zero (h : IsRoot p x) : eval x p = 0 :=
h
theorem IsRoot.dvd {R : Type*} [CommSemiring R] {p q : R[X]} {x : R} (h : p.IsRoot x)
(hpq : p ∣ q) : q.IsRoot x := by
rwa [IsRoot, eval, eval₂_eq_zero_of_dvd_of_eval₂_eq_zero _ _ hpq]
theorem not_isRoot_C (r a : R) (hr : r ≠ 0) : ¬IsRoot (C r) a := by simpa using hr
theorem eval_surjective (x : R) : Function.Surjective <| eval x := fun y => ⟨C y, eval_C⟩
end Eval
section Comp
/-- The composition of polynomials as a polynomial. -/
def comp (p q : R[X]) : R[X] :=
p.eval₂ C q
theorem comp_eq_sum_left : p.comp q = p.sum fun e a => C a * q ^ e := by rw [comp, eval₂_eq_sum]
@[simp]
theorem comp_X : p.comp X = p := by
simp only [comp, eval₂_def, C_mul_X_pow_eq_monomial]
exact sum_monomial_eq _
@[simp]
theorem X_comp : X.comp p = p :=
eval₂_X _ _
@[simp]
theorem comp_C : p.comp (C a) = C (p.eval a) := by simp [comp]
@[simp]
theorem C_comp : (C a).comp p = C a :=
eval₂_C _ _
@[simp]
theorem natCast_comp {n : ℕ} : (n : R[X]).comp p = n := by rw [← C_eq_natCast, C_comp]
@[simp]
theorem ofNat_comp (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R[X]).comp p = n :=
natCast_comp
@[simp]
theorem comp_zero : p.comp (0 : R[X]) = C (p.eval 0) := by rw [← C_0, comp_C]
@[simp]
theorem zero_comp : comp (0 : R[X]) p = 0 := by rw [← C_0, C_comp]
@[simp]
theorem comp_one : p.comp 1 = C (p.eval 1) := by rw [← C_1, comp_C]
@[simp]
theorem one_comp : comp (1 : R[X]) p = 1 := by rw [← C_1, C_comp]
@[simp]
theorem add_comp : (p + q).comp r = p.comp r + q.comp r :=
eval₂_add _ _
@[simp]
theorem monomial_comp (n : ℕ) : (monomial n a).comp p = C a * p ^ n :=
eval₂_monomial _ _
@[simp]
theorem mul_X_comp : (p * X).comp r = p.comp r * r := by
induction p using Polynomial.induction_on' with
| add p q hp hq => simp only [hp, hq, add_mul, add_comp]
| monomial n b => simp only [pow_succ, mul_assoc, monomial_mul_X, monomial_comp]
@[simp]
theorem X_pow_comp {k : ℕ} : (X ^ k).comp p = p ^ k := by
induction k with
| zero => simp
| succ k ih => simp [pow_succ, mul_X_comp, ih]
@[simp]
theorem mul_X_pow_comp {k : ℕ} : (p * X ^ k).comp r = p.comp r * r ^ k := by
induction k with
| zero => simp
| succ k ih => simp [ih, pow_succ, ← mul_assoc, mul_X_comp]
@[simp]
theorem C_mul_comp : (C a * p).comp r = C a * p.comp r := by
induction p using Polynomial.induction_on' with
| add p q hp hq => simp [hp, hq, mul_add]
| monomial n b => simp [mul_assoc]
@[simp]
theorem natCast_mul_comp {n : ℕ} : ((n : R[X]) * p).comp r = n * p.comp r := by
rw [← C_eq_natCast, C_mul_comp]
theorem mul_X_add_natCast_comp {n : ℕ} :
(p * (X + (n : R[X]))).comp q = p.comp q * (q + n) := by
rw [mul_add, add_comp, mul_X_comp, ← Nat.cast_comm, natCast_mul_comp, Nat.cast_comm, mul_add]
@[simp]
theorem mul_comp {R : Type*} [CommSemiring R] (p q r : R[X]) :
(p * q).comp r = p.comp r * q.comp r :=
eval₂_mul _ _
@[simp]
theorem pow_comp {R : Type*} [CommSemiring R] (p q : R[X]) (n : ℕ) :
(p ^ n).comp q = p.comp q ^ n :=
(MonoidHom.mk (OneHom.mk (fun r : R[X] => r.comp q) one_comp) fun r s => mul_comp r s q).map_pow
p n
theorem comp_assoc {R : Type*} [CommSemiring R] (φ ψ χ : R[X]) :
(φ.comp ψ).comp χ = φ.comp (ψ.comp χ) := by
refine Polynomial.induction_on φ ?_ ?_ ?_ <;>
· intros
simp_all only [add_comp, mul_comp, C_comp, X_comp, pow_succ, ← mul_assoc]
@[simp] lemma sum_comp (s : Finset ι) (p : ι → R[X]) (q : R[X]) :
(∑ i ∈ s, p i).comp q = ∑ i ∈ s, (p i).comp q := Polynomial.eval₂_finset_sum _ _ _ _
end Comp
section Map
variable [Semiring S]
variable (f : R →+* S)
/-- `map f p` maps a polynomial `p` across a ring hom `f` -/
def map : R[X] → S[X] :=
eval₂ (C.comp f) X
@[simp]
theorem map_C : (C a).map f = C (f a) :=
eval₂_C _ _
@[simp]
theorem map_X : X.map f = X :=
eval₂_X _ _
@[simp]
theorem map_monomial {n a} : (monomial n a).map f = monomial n (f a) := by
dsimp only [map]
rw [eval₂_monomial, ← C_mul_X_pow_eq_monomial]; rfl
@[simp]
protected theorem map_zero : (0 : R[X]).map f = 0 :=
eval₂_zero _ _
@[simp]
protected theorem map_add : (p + q).map f = p.map f + q.map f :=
eval₂_add _ _
@[simp]
protected theorem map_one : (1 : R[X]).map f = 1 :=
eval₂_one _ _
@[simp]
protected theorem map_mul : (p * q).map f = p.map f * q.map f := by
rw [map, eval₂_mul_noncomm]
exact fun k => (commute_X _).symm
-- `map` is a ring-hom unconditionally, and theoretically the definition could be replaced,
-- but this turns out not to be easy because `p.map f` does not resolve to `Polynomial.map`
-- if `map` is a `RingHom` instead of a plain function; the elaborator does not try to coerce
-- to a function before trying field (dot) notation (this may be technically infeasible);
-- the relevant code is (both lines): https://github.com/leanprover-community/
-- lean/blob/487ac5d7e9b34800502e1ddf3c7c806c01cf9d51/src/frontends/lean/elaborator.cpp#L1876-L1913
/-- `Polynomial.map` as a `RingHom`. -/
def mapRingHom (f : R →+* S) : R[X] →+* S[X] where
toFun := Polynomial.map f
map_add' _ _ := Polynomial.map_add f
map_zero' := Polynomial.map_zero f
map_mul' _ _ := Polynomial.map_mul f
map_one' := Polynomial.map_one f
@[simp]
theorem coe_mapRingHom (f : R →+* S) : ⇑(mapRingHom f) = map f :=
rfl
-- This is protected to not clash with the global `map_natCast`.
@[simp]
protected theorem map_natCast (n : ℕ) : (n : R[X]).map f = n :=
map_natCast (mapRingHom f) n
@[simp]
protected theorem map_ofNat (n : ℕ) [n.AtLeastTwo] :
(ofNat(n) : R[X]).map f = ofNat(n) :=
show (n : R[X]).map f = n by rw [Polynomial.map_natCast]
--TODO rename to `map_dvd_map`
theorem map_dvd (f : R →+* S) {x y : R[X]} : x ∣ y → x.map f ∣ y.map f :=
_root_.map_dvd (mapRingHom f)
lemma mapRingHom_comp_C {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) :
(mapRingHom f).comp C = C.comp f := by ext; simp
theorem eval₂_eq_eval_map {x : S} : p.eval₂ f x = (p.map f).eval x := by
induction p using Polynomial.induction_on' with
| add p q hp hq => simp [hp, hq]
| monomial n r => simp
protected theorem map_list_prod (L : List R[X]) : L.prod.map f = (L.map <| map f).prod :=
Eq.symm <| List.prod_hom _ (mapRingHom f).toMonoidHom
@[simp]
protected theorem map_pow (n : ℕ) : (p ^ n).map f = p.map f ^ n :=
(mapRingHom f).map_pow _ _
theorem eval_map (x : S) : (p.map f).eval x = p.eval₂ f x :=
(eval₂_eq_eval_map f).symm
@[simp] lemma eval_map_apply (x : R) : (p.map f).eval (f x) = f (p.eval x) :=
eval_map f _ ▸ eval₂_at_apply ..
protected theorem map_sum {ι : Type*} (g : ι → R[X]) (s : Finset ι) :
(∑ i ∈ s, g i).map f = ∑ i ∈ s, (g i).map f :=
map_sum (mapRingHom f) _ _
theorem map_comp (p q : R[X]) : map f (p.comp q) = (map f p).comp (map f q) :=
Polynomial.induction_on p (by simp only [map_C, forall_const, C_comp])
(by
simp +contextual only [Polynomial.map_add, add_comp, forall_const,
imp_true_iff])
(by
simp +contextual only [pow_succ, ← mul_assoc, comp, forall_const,
eval₂_mul_X, imp_true_iff, map_X, Polynomial.map_mul])
end Map
end Semiring
section CommSemiring
section Eval
section
variable [CommSemiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R →+* S)
@[simp]
theorem eval_mul : (p * q).eval x = p.eval x * q.eval x :=
eval₂_mul _ _
/-- `eval r`, regarded as a ring homomorphism from `R[X]` to `R`. -/
def evalRingHom : R → R[X] →+* R :=
eval₂RingHom (RingHom.id _)
@[simp]
theorem coe_evalRingHom (r : R) : (evalRingHom r : R[X] → R) = eval r :=
rfl
@[simp]
theorem eval_pow (n : ℕ) : (p ^ n).eval x = p.eval x ^ n :=
eval₂_pow _ _ _
theorem eval_X_pow (n : ℕ) : (X ^ n : R[X]).eval x = x ^ n := by
simp
@[simp]
theorem eval_comp : (p.comp q).eval x = p.eval (q.eval x) := by
induction p using Polynomial.induction_on' with
| add r s hr hs => simp [add_comp, hr, hs]
| monomial n a => simp
lemma isRoot_comp {R} [CommSemiring R] {p q : R[X]} {r : R} :
(p.comp q).IsRoot r ↔ p.IsRoot (q.eval r) := by simp_rw [IsRoot, eval_comp]
/-- `comp p`, regarded as a ring homomorphism from `R[X]` to itself. -/
def compRingHom : R[X] → R[X] →+* R[X] :=
eval₂RingHom C
@[simp]
theorem coe_compRingHom (q : R[X]) : (compRingHom q : R[X] → R[X]) = fun p => comp p q :=
rfl
theorem coe_compRingHom_apply (p q : R[X]) : (compRingHom q : R[X] → R[X]) p = comp p q :=
rfl
theorem root_mul_left_of_isRoot (p : R[X]) {q : R[X]} : IsRoot q a → IsRoot (p * q) a := fun H => by
rw [IsRoot, eval_mul, IsRoot.def.1 H, mul_zero]
theorem root_mul_right_of_isRoot {p : R[X]} (q : R[X]) : IsRoot p a → IsRoot (p * q) a := fun H =>
by rw [IsRoot, eval_mul, IsRoot.def.1 H, zero_mul]
theorem eval₂_multiset_prod (s : Multiset R[X]) (x : S) :
eval₂ f x s.prod = (s.map (eval₂ f x)).prod :=
map_multiset_prod (eval₂RingHom f x) s
theorem eval₂_finset_prod (s : Finset ι) (g : ι → R[X]) (x : S) :
(∏ i ∈ s, g i).eval₂ f x = ∏ i ∈ s, (g i).eval₂ f x :=
map_prod (eval₂RingHom f x) _ _
/-- Polynomial evaluation commutes with `List.prod`
-/
theorem eval_list_prod (l : List R[X]) (x : R) : eval x l.prod = (l.map (eval x)).prod :=
map_list_prod (evalRingHom x) l
/-- Polynomial evaluation commutes with `Multiset.prod`
-/
theorem eval_multiset_prod (s : Multiset R[X]) (x : R) : eval x s.prod = (s.map (eval x)).prod :=
(evalRingHom x).map_multiset_prod s
/-- Polynomial evaluation commutes with `Finset.prod`
-/
theorem eval_prod {ι : Type*} (s : Finset ι) (p : ι → R[X]) (x : R) :
eval x (∏ j ∈ s, p j) = ∏ j ∈ s, eval x (p j) :=
map_prod (evalRingHom x) _ _
theorem list_prod_comp (l : List R[X]) (q : R[X]) :
l.prod.comp q = (l.map fun p : R[X] => p.comp q).prod :=
map_list_prod (compRingHom q) _
theorem multiset_prod_comp (s : Multiset R[X]) (q : R[X]) :
s.prod.comp q = (s.map fun p : R[X] => p.comp q).prod :=
map_multiset_prod (compRingHom q) _
theorem prod_comp {ι : Type*} (s : Finset ι) (p : ι → R[X]) (q : R[X]) :
(∏ j ∈ s, p j).comp q = ∏ j ∈ s, (p j).comp q :=
map_prod (compRingHom q) _ _
theorem isRoot_prod {R} [CommSemiring R] [IsDomain R] {ι : Type*} (s : Finset ι) (p : ι → R[X])
(x : R) : IsRoot (∏ j ∈ s, p j) x ↔ ∃ i ∈ s, IsRoot (p i) x := by
simp only [IsRoot, eval_prod, Finset.prod_eq_zero_iff]
@[gcongr]
theorem eval_dvd : p ∣ q → eval x p ∣ eval x q :=
eval₂_dvd _ _
theorem eval_eq_zero_of_dvd_of_eval_eq_zero : p ∣ q → eval x p = 0 → eval x q = 0 :=
eval₂_eq_zero_of_dvd_of_eval₂_eq_zero _ _
@[simp]
theorem eval_geom_sum {R} [CommSemiring R] {n : ℕ} {x : R} :
eval x (∑ i ∈ range n, X ^ i) = ∑ i ∈ range n, x ^ i := by simp [eval_finset_sum]
variable [NoZeroDivisors R]
lemma root_mul : IsRoot (p * q) a ↔ IsRoot p a ∨ IsRoot q a := by
simp_rw [IsRoot, eval_mul, mul_eq_zero]
lemma root_or_root_of_root_mul (h : IsRoot (p * q) a) : IsRoot p a ∨ IsRoot q a :=
root_mul.1 h
end
end Eval
section Map
variable [CommSemiring R] [CommSemiring S] (f : R →+* S)
protected theorem map_multiset_prod (m : Multiset R[X]) : m.prod.map f = (m.map <| map f).prod :=
Eq.symm <| Multiset.prod_hom _ (mapRingHom f).toMonoidHom
protected theorem map_prod {ι : Type*} (g : ι → R[X]) (s : Finset ι) :
(∏ i ∈ s, g i).map f = ∏ i ∈ s, (g i).map f :=
map_prod (mapRingHom f) _ _
end Map
end CommSemiring
section Ring
variable [Ring R] {p q r : R[X]}
@[simp]
protected theorem map_sub {S} [Ring S] (f : R →+* S) : (p - q).map f = p.map f - q.map f :=
(mapRingHom f).map_sub p q
@[simp]
protected theorem map_neg {S} [Ring S] (f : R →+* S) : (-p).map f = -p.map f :=
(mapRingHom f).map_neg p
@[simp] protected lemma map_intCast {S} [Ring S] (f : R →+* S) (n : ℤ) : map f ↑n = ↑n :=
map_intCast (mapRingHom f) n
@[simp]
theorem eval_intCast {n : ℤ} {x : R} : (n : R[X]).eval x = n := by
simp only [← C_eq_intCast, eval_C]
@[simp]
theorem eval₂_neg {S} [Ring S] (f : R →+* S) {x : S} : (-p).eval₂ f x = -p.eval₂ f x := by
rw [eq_neg_iff_add_eq_zero, ← eval₂_add, neg_add_cancel, eval₂_zero]
@[simp]
theorem eval₂_sub {S} [Ring S] (f : R →+* S) {x : S} :
(p - q).eval₂ f x = p.eval₂ f x - q.eval₂ f x := by
rw [sub_eq_add_neg, eval₂_add, eval₂_neg, sub_eq_add_neg]
@[simp]
theorem eval_neg (p : R[X]) (x : R) : (-p).eval x = -p.eval x :=
eval₂_neg _
@[simp]
theorem eval_sub (p q : R[X]) (x : R) : (p - q).eval x = p.eval x - q.eval x :=
eval₂_sub _
theorem root_X_sub_C : IsRoot (X - C a) b ↔ a = b := by
rw [IsRoot.def, eval_sub, eval_X, eval_C, sub_eq_zero, eq_comm]
@[simp]
theorem neg_comp : (-p).comp q = -p.comp q :=
eval₂_neg _
@[simp]
theorem sub_comp : (p - q).comp r = p.comp r - q.comp r :=
eval₂_sub _
@[simp]
theorem intCast_comp (i : ℤ) : comp (i : R[X]) p = i := by cases i <;> simp
@[simp]
theorem eval₂_at_intCast {S : Type*} [Ring S] (f : R →+* S) (n : ℤ) :
p.eval₂ f n = f (p.eval n) := by
convert eval₂_at_apply (p := p) f n
simp
theorem mul_X_sub_intCast_comp {n : ℕ} :
(p * (X - (n : R[X]))).comp q = p.comp q * (q - n) := by
rw [mul_sub, sub_comp, mul_X_comp, ← Nat.cast_comm, natCast_mul_comp, Nat.cast_comm, mul_sub]
end Ring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Eval/Degree.lean | import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Algebra.Polynomial.Degree.Support
import Mathlib.Algebra.Polynomial.Degree.Units
import Mathlib.Algebra.Polynomial.Eval.Coeff
/-!
# Evaluation of polynomials and degrees
This file contains results on the interaction of `Polynomial.eval` and `Polynomial.degree`.
-/
noncomputable section
open Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section Eval₂
section
variable [Semiring S] (f : R →+* S) (x : S)
theorem eval₂_eq_sum_range :
p.eval₂ f x = ∑ i ∈ Finset.range (p.natDegree + 1), f (p.coeff i) * x ^ i :=
_root_.trans (congr_arg _ p.as_sum_range)
(_root_.trans (eval₂_finset_sum f _ _ x) (congr_arg _ (by simp)))
theorem eval₂_eq_sum_range' (f : R →+* S) {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : S) :
eval₂ f x p = ∑ i ∈ Finset.range n, f (p.coeff i) * x ^ i := by
rw [eval₂_eq_sum, p.sum_over_range' _ _ hn]
intro i
rw [f.map_zero, zero_mul]
end
end Eval₂
section Eval
variable {x : R}
theorem eval_eq_sum_range {p : R[X]} (x : R) :
p.eval x = ∑ i ∈ Finset.range (p.natDegree + 1), p.coeff i * x ^ i := by
rw [eval_eq_sum, sum_over_range]; simp
theorem eval_eq_sum_range' {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : R) :
p.eval x = ∑ i ∈ Finset.range n, p.coeff i * x ^ i := by
rw [eval_eq_sum, p.sum_over_range' _ _ hn]; simp
/-- A reformulation of the expansion of (1 + y)^d:
$$(d + 1) (1 + y)^d - (d + 1)y^d = \sum_{i = 0}^d {d + 1 \choose i} \cdot i \cdot y^{i - 1}.$$
-/
theorem eval_monomial_one_add_sub [CommRing S] (d : ℕ) (y : S) :
eval (1 + y) (monomial d (d + 1 : S)) - eval y (monomial d (d + 1 : S)) =
∑ x_1 ∈ range (d + 1), ↑((d + 1).choose x_1) * (↑x_1 * y ^ (x_1 - 1)) := by
have cast_succ : (d + 1 : S) = ((d.succ : ℕ) : S) := by simp only [Nat.cast_succ]
rw [cast_succ, eval_monomial, eval_monomial, add_comm, add_pow]
simp only [one_pow, mul_one, mul_comm (y ^ _) (d.choose _)]
rw [sum_range_succ, mul_add, Nat.choose_self, Nat.cast_one, one_mul, add_sub_cancel_right,
mul_sum, sum_range_succ', Nat.cast_zero, zero_mul, mul_zero, add_zero]
refine sum_congr rfl fun y _hy => ?_
rw [← mul_assoc, ← mul_assoc, ← Nat.cast_mul, Nat.succ_mul_choose_eq, Nat.cast_mul,
Nat.add_sub_cancel]
end Eval
section Comp
theorem coeff_comp_degree_mul_degree (hqd0 : natDegree q ≠ 0) :
coeff (p.comp q) (natDegree p * natDegree q) =
leadingCoeff p * leadingCoeff q ^ natDegree p := by
rw [comp, eval₂_def, coeff_sum]
refine Eq.trans (Finset.sum_eq_single p.natDegree ?h₀ ?h₁) ?h₂
case h₂ =>
simp only [coeff_natDegree, coeff_C_mul, coeff_pow_mul_natDegree]
case h₀ =>
intro b hbs hbp
refine coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt ?_)
rw [natDegree_C, zero_add]
refine natDegree_pow_le.trans_lt ?_
gcongr
exact lt_of_le_of_ne (le_natDegree_of_mem_supp _ hbs) hbp
case h₁ =>
simp +contextual
@[simp] lemma comp_C_mul_X_coeff {r : R} {n : ℕ} :
(p.comp <| C r * X).coeff n = p.coeff n * r ^ n := by
simp_rw [comp, eval₂_eq_sum_range, (commute_X _).symm.mul_pow,
← C_pow, finset_sum_coeff, coeff_C_mul, coeff_X_pow]
rw [Finset.sum_eq_single n _ fun h ↦ ?_, if_pos rfl, mul_one]
· intro b _ h; simp_rw [if_neg h.symm, mul_zero]
· rw [coeff_eq_zero_of_natDegree_lt, zero_mul]
rwa [Finset.mem_range_succ_iff, not_le] at h
lemma comp_C_mul_X_eq_zero_iff {r : R} (hr : r ∈ nonZeroDivisors R) :
p.comp (C r * X) = 0 ↔ p = 0 := by
simp_rw [ext_iff]
refine forall_congr' fun n ↦ ?_
rw [comp_C_mul_X_coeff, coeff_zero, mul_right_mem_nonZeroDivisors_eq_zero_iff (pow_mem hr _)]
end Comp
section Map
variable [Semiring S] {f : R →+* S} {p : R[X]}
variable (f) in
/-- If `R` and `S` are isomorphic, then so are their polynomial rings. -/
@[simps!]
def mapEquiv (e : R ≃+* S) : R[X] ≃+* S[X] :=
RingEquiv.ofHomInv (mapRingHom (e : R →+* S)) (mapRingHom (e.symm : S →+* R)) (by ext; simp)
(by ext; simp)
theorem map_monic_eq_zero_iff (hp : p.Monic) : p.map f = 0 ↔ ∀ x, f x = 0 :=
⟨fun hfp x =>
calc
f x = f x * f p.leadingCoeff := by simp only [mul_one, hp.leadingCoeff, f.map_one]
_ = f x * (p.map f).coeff p.natDegree := congr_arg _ (coeff_map _ _).symm
_ = 0 := by simp only [hfp, mul_zero, coeff_zero],
fun h => ext fun n => by simp only [h, coeff_map, coeff_zero]⟩
theorem map_monic_ne_zero (hp : p.Monic) [Nontrivial S] : p.map f ≠ 0 := fun h =>
f.map_one_ne_zero ((map_monic_eq_zero_iff hp).mp h _)
lemma degree_map_le : degree (p.map f) ≤ degree p := by
refine (degree_le_iff_coeff_zero _ _).2 fun m hm => ?_
rw [degree_lt_iff_coeff_zero] at hm
simp [hm m le_rfl]
lemma natDegree_map_le : natDegree (p.map f) ≤ natDegree p := natDegree_le_natDegree degree_map_le
lemma degree_map_lt (hp : f p.leadingCoeff = 0) (hp₀ : p ≠ 0) : (p.map f).degree < p.degree := by
refine degree_map_le.lt_of_ne fun hpq ↦ hp₀ ?_
rw [leadingCoeff, ← coeff_map, ← natDegree_eq_natDegree hpq, ← leadingCoeff, leadingCoeff_eq_zero]
at hp
rw [← degree_eq_bot, ← hpq, hp, degree_zero]
lemma natDegree_map_lt (hp : f p.leadingCoeff = 0) (hp₀ : map f p ≠ 0) :
(p.map f).natDegree < p.natDegree :=
natDegree_lt_natDegree hp₀ <| degree_map_lt hp <| by rintro rfl; simp at hp₀
/-- Variant of `natDegree_map_lt` that assumes `0 < natDegree p` instead of `map f p ≠ 0`. -/
lemma natDegree_map_lt' (hp : f p.leadingCoeff = 0) (hp₀ : 0 < natDegree p) :
(p.map f).natDegree < p.natDegree := by
by_cases H : map f p = 0
· rwa [H, natDegree_zero]
· exact natDegree_map_lt hp H
theorem degree_map_eq_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) :
degree (p.map f) = degree p := by
refine degree_map_le.antisymm ?_
have hp0 : p ≠ 0 :=
leadingCoeff_ne_zero.mp fun hp0 => hf (_root_.trans (congr_arg _ hp0) f.map_zero)
rw [degree_eq_natDegree hp0]
refine le_degree_of_ne_zero ?_
rw [coeff_map]
exact hf
theorem natDegree_map_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) :
natDegree (p.map f) = natDegree p :=
natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f hf)
theorem leadingCoeff_map_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f (leadingCoeff p) ≠ 0) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
unfold leadingCoeff
rw [coeff_map, natDegree_map_of_leadingCoeff_ne_zero f hf]
theorem nextCoeff_map_of_leadingCoeff_ne_zero (f : R →+* S) (hf : f p.leadingCoeff ≠ 0) :
(p.map f).nextCoeff = f p.nextCoeff := by
grind [nextCoeff, natDegree_map_of_leadingCoeff_ne_zero, coeff_map]
end Map
end Semiring
section CommSemiring
section Eval
section
variable [Semiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R →+* S)
theorem eval₂_comp {x : S} : eval₂ f x (p.comp q) = eval₂ f (eval₂ f x q) p := by
rw [comp, p.as_sum_range]; simp [eval₂_finset_sum, eval₂_pow]
@[simp]
theorem iterate_comp_eval₂ (k : ℕ) (t : S) :
eval₂ f t (p.comp^[k] q) = (fun x => eval₂ f x p)^[k] (eval₂ f t q) := by
induction k with
| zero => simp
| succ k IH => rw [Function.iterate_succ_apply', Function.iterate_succ_apply', eval₂_comp, IH]
end
section
variable [CommSemiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R →+* S)
@[simp]
theorem iterate_comp_eval :
∀ (k : ℕ) (t : R), (p.comp^[k] q).eval t = (fun x => p.eval x)^[k] (q.eval t) :=
iterate_comp_eval₂ _
end
end Eval
end CommSemiring
section
variable [Semiring R] [CommRing S] [IsDomain S] (φ : R →+* S) {f : R[X]}
lemma isUnit_of_isUnit_leadingCoeff_of_isUnit_map (hf : IsUnit f.leadingCoeff)
(H : IsUnit (map φ f)) : IsUnit f := by
have dz := degree_eq_zero_of_isUnit H
rw [degree_map_eq_of_leadingCoeff_ne_zero] at dz
· rw [eq_C_of_degree_eq_zero dz]
refine IsUnit.map C ?_
convert hf
change coeff f 0 = coeff f (natDegree f)
rw [(degree_eq_iff_natDegree_eq _).1 dz]
· rfl
rintro rfl
simp at H
· intro h
have u : IsUnit (φ f.leadingCoeff) := IsUnit.map φ hf
rw [h] at u
simp at u
end
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Eval/Irreducible.lean | import Mathlib.Algebra.Polynomial.Eval.Coeff
import Mathlib.Algebra.Polynomial.Eval.Degree
import Mathlib.Algebra.Prime.Defs
/-!
# Mapping irreducible polynomials
## Main results
* `Monic.irreducible_of_irreducible_map`: we can prove a monic polynomial is irreducible
by mapping it to another integral domain and checking for irreducibility there.
-/
noncomputable section
open Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
section
variable [CommRing R] [IsDomain R] [CommRing S] [IsDomain S] (φ : R →+* S)
/-- A polynomial over an integral domain `R` is irreducible if it is monic and
irreducible after mapping into an integral domain `S`.
A special case of this lemma is that a polynomial over `ℤ` is irreducible if
it is monic and irreducible over `ℤ/pℤ` for some prime `p`.
-/
lemma Monic.irreducible_of_irreducible_map (f : R[X]) (h_mon : Monic f)
(h_irr : Irreducible (f.map φ)) : Irreducible f := by
refine ⟨h_irr.not_isUnit ∘ IsUnit.map (mapRingHom φ), fun a b h => ?_⟩
dsimp [Monic] at h_mon
have q := (leadingCoeff_mul a b).symm
rw [← h, h_mon] at q
refine (h_irr.isUnit_or_isUnit <|
(congr_arg (Polynomial.map φ) h).trans (Polynomial.map_mul φ)).imp ?_ ?_ <;>
apply isUnit_of_isUnit_leadingCoeff_of_isUnit_map <;>
apply IsUnit.of_mul_eq_one
· exact q
· rw [mul_comm]
exact q
end
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Eval/Coeff.lean | import Mathlib.Algebra.Polynomial.Coeff
import Mathlib.Algebra.Polynomial.Eval.Defs
/-!
# Evaluation of polynomials
This file contains results on the interaction of `Polynomial.eval` and `Polynomial.coeff`
-/
noncomputable section
open Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section
variable [Semiring S]
variable (f : R →+* S) (x : S)
@[simp]
theorem eval₂_at_zero : p.eval₂ f 0 = f (coeff p 0) := by
simp +contextual only [eval₂_eq_sum, zero_pow_eq, mul_ite, mul_zero,
mul_one, sum, Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff,
RingHom.map_zero, imp_true_iff]
@[simp]
theorem eval₂_C_X : eval₂ C X p = p :=
Polynomial.induction_on' p (fun p q hp hq => by simp [hp, hq]) fun n x => by
rw [eval₂_monomial, ← smul_X_eq_monomial, C_mul']
end
section Eval
variable {x : R}
theorem coeff_zero_eq_eval_zero (p : R[X]) : coeff p 0 = p.eval 0 :=
calc
coeff p 0 = coeff p 0 * 0 ^ 0 := by simp
_ = p.eval 0 := by
symm
rw [eval_eq_sum]
exact Finset.sum_eq_single _ (fun b _ hb => by simp [zero_pow hb]) (by simp)
theorem zero_isRoot_iff_coeff_zero_eq_zero {p : R[X]} : IsRoot p 0 ↔ p.coeff 0 = 0 := by
rw [coeff_zero_eq_eval_zero, IsRoot]
alias ⟨coeff_zero_eq_zero_of_zero_isRoot, zero_isRoot_of_coeff_zero_eq_zero⟩ :=
zero_isRoot_iff_coeff_zero_eq_zero
end Eval
section Map
variable [Semiring S]
variable (f : R →+* S)
@[simp]
theorem coeff_map (n : ℕ) : coeff (p.map f) n = f (coeff p n) := by
rw [map, eval₂_def, coeff_sum, sum]
simp_all
lemma coeff_map_eq_comp (p : R[X]) (f : R →+* S) : (p.map f).coeff = f ∘ p.coeff := by
ext n; exact coeff_map ..
theorem map_map [Semiring T] (g : S →+* T) (p : R[X]) : (p.map f).map g = p.map (g.comp f) :=
ext (by simp [coeff_map])
@[simp]
theorem map_id : p.map (RingHom.id _) = p := by simp [Polynomial.ext_iff, coeff_map]
/-- The polynomial ring over a finite product of rings is isomorphic to
the product of polynomial rings over individual rings. -/
def piEquiv {ι} [Finite ι] (R : ι → Type*) [∀ i, Semiring (R i)] :
(∀ i, R i)[X] ≃+* ∀ i, (R i)[X] :=
.ofBijective (Pi.ringHom fun i ↦ mapRingHom (Pi.evalRingHom R i))
⟨fun p q h ↦ by ext n i; simpa using congr_arg (fun p ↦ coeff (p i) n) h,
fun p ↦ ⟨.ofFinsupp (.ofSupportFinite (fun n i ↦ coeff (p i) n) <|
(Set.finite_iUnion fun i ↦ (p i).support.finite_toSet).subset fun n hn ↦ by
simp only [Set.mem_iUnion, Finset.mem_coe, mem_support_iff, Function.mem_support] at hn ⊢
contrapose! hn; exact funext hn), by ext i n; exact coeff_map _ _⟩⟩
theorem map_injective (hf : Function.Injective f) : Function.Injective (map f) := fun p q h =>
ext fun m => hf <| by rw [← coeff_map f, ← coeff_map f, h]
theorem map_injective_iff : Function.Injective (map f) ↔ Function.Injective f :=
⟨fun h r r' eq ↦ by simpa using h (a₁ := C r) (a₂ := C r') (by simpa), map_injective f⟩
theorem map_surjective (hf : Function.Surjective f) : Function.Surjective (map f) := fun p =>
p.induction_on'
(by rintro _ _ ⟨p, rfl⟩ ⟨q, rfl⟩; exact ⟨p + q, Polynomial.map_add f⟩)
fun n s ↦
let ⟨r, hr⟩ := hf s
⟨monomial n r, by rw [map_monomial f, hr]⟩
theorem map_surjective_iff : Function.Surjective (map f) ↔ Function.Surjective f :=
⟨fun h s ↦ let ⟨p, h⟩ := h (C s); ⟨p.coeff 0, by simpa using congr(coeff $h 0)⟩, map_surjective f⟩
variable {f}
protected theorem map_eq_zero_iff (hf : Function.Injective f) : p.map f = 0 ↔ p = 0 :=
map_eq_zero_iff (mapRingHom f) (map_injective f hf)
protected theorem map_ne_zero_iff (hf : Function.Injective f) : p.map f ≠ 0 ↔ p ≠ 0 :=
(Polynomial.map_eq_zero_iff hf).not
variable (f)
@[simp]
theorem mapRingHom_id : mapRingHom (RingHom.id R) = RingHom.id R[X] :=
RingHom.ext fun _x => map_id
@[simp]
theorem mapRingHom_comp [Semiring T] (f : S →+* T) (g : R →+* S) :
(mapRingHom f).comp (mapRingHom g) = mapRingHom (f.comp g) :=
RingHom.ext <| Polynomial.map_map g f
theorem eval₂_map [Semiring T] (g : S →+* T) (x : T) :
(p.map f).eval₂ g x = p.eval₂ (g.comp f) x := by
rw [eval₂_eq_eval_map, eval₂_eq_eval_map, map_map]
@[simp]
theorem eval_zero_map (f : R →+* S) (p : R[X]) : (p.map f).eval 0 = f (p.eval 0) := by
simp [← coeff_zero_eq_eval_zero]
@[simp]
theorem eval_one_map (f : R →+* S) (p : R[X]) : (p.map f).eval 1 = f (p.eval 1) := by
induction p using Polynomial.induction_on' with
| add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| monomial n r => simp only [one_pow, mul_one, eval_monomial, map_monomial]
@[simp]
theorem eval_natCast_map (f : R →+* S) (p : R[X]) (n : ℕ) :
(p.map f).eval (n : S) = f (p.eval n) := by
induction p using Polynomial.induction_on' with
| add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| monomial n r => simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul]
@[simp]
theorem eval_intCast_map {R S : Type*} [Ring R] [Ring S] (f : R →+* S) (p : R[X]) (i : ℤ) :
(p.map f).eval (i : S) = f (p.eval i) := by
induction p using Polynomial.induction_on' with
| add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add]
| monomial n r => simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul]
end Map
section HomEval₂
variable [Semiring S] [Semiring T] (f : R →+* S) (g : S →+* T) (p)
theorem hom_eval₂ (x : S) : g (p.eval₂ f x) = p.eval₂ (g.comp f) (g x) := by
rw [← eval₂_map, eval₂_at_apply, eval_map]
end HomEval₂
end Semiring
section CommSemiring
section Eval
section
variable [Semiring R] {p q : R[X]} {x : R} [Semiring S] (f : R →+* S)
theorem eval₂_hom (x : R) : p.eval₂ f (f x) = f (p.eval x) :=
RingHom.comp_id f ▸ (hom_eval₂ p (RingHom.id R) f x).symm
end
section
variable [CommSemiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R →+* S)
theorem evalRingHom_zero : evalRingHom 0 = constantCoeff :=
DFunLike.ext _ _ fun p => p.coeff_zero_eq_eval_zero.symm
end
end Eval
section Map
theorem support_map_subset [Semiring R] [Semiring S] (f : R →+* S) (p : R[X]) :
(map f p).support ⊆ p.support := by
intro x
contrapose!
simp +contextual
theorem support_map_of_injective [Semiring R] [Semiring S] (p : R[X]) {f : R →+* S}
(hf : Function.Injective f) : (map f p).support = p.support := by
simp_rw [Finset.ext_iff, mem_support_iff, coeff_map, ← map_zero f, hf.ne_iff,
forall_const]
variable [CommSemiring R] [CommSemiring S] (f : R →+* S)
theorem IsRoot.map {f : R →+* S} {x : R} {p : R[X]} (h : IsRoot p x) : IsRoot (p.map f) (f x) := by
rw [IsRoot, eval_map, eval₂_hom, h.eq_zero, f.map_zero]
theorem IsRoot.of_map {R} [Ring R] {f : R →+* S} {x : R} {p : R[X]} (h : IsRoot (p.map f) (f x))
(hf : Function.Injective f) : IsRoot p x := by
rwa [IsRoot, ← (injective_iff_map_eq_zero' f).mp hf, ← eval₂_hom, ← eval_map]
theorem isRoot_map_iff {R : Type*} [CommRing R] {f : R →+* S} {x : R} {p : R[X]}
(hf : Function.Injective f) : IsRoot (p.map f) (f x) ↔ IsRoot p x :=
⟨fun h => h.of_map hf, fun h => h.map⟩
end Map
end CommSemiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Polynomial/Eval/Algebra.lean | import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.Polynomial.Eval.Defs
/-!
# Evaluation of polynomials in an algebra
This file concerns evaluating polynomials where the map is `algebraMap`
TODO: merge with parts of `Algebra/Polynomial/AlgebraMap.lean`?
-/
noncomputable section
open Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
section CommSemiring
section Eval
section Algebra
variable [CommSemiring R] [Semiring S] [Algebra R S] (x : S) (p q : R[X])
@[simp]
theorem eval₂_mul' :
(p * q).eval₂ (algebraMap R S) x = p.eval₂ (algebraMap R S) x * q.eval₂ (algebraMap R S) x := by
exact eval₂_mul_noncomm _ _ fun k => Algebra.commute_algebraMap_left (coeff q k) x
@[simp]
theorem eval₂_pow' (n : ℕ) :
(p ^ n).eval₂ (algebraMap R S) x = (p.eval₂ (algebraMap R S) x) ^ n := by
induction n with
| zero => simp only [pow_zero, eval₂_one]
| succ n ih => rw [pow_succ, pow_succ, eval₂_mul', ih]
@[simp]
theorem eval₂_comp' : eval₂ (algebraMap R S) x (p.comp q) =
eval₂ (algebraMap R S) (eval₂ (algebraMap R S) x q) p := by
induction p using Polynomial.induction_on' with
| add r s hr hs => simp only [add_comp, eval₂_add, hr, hs]
| monomial n a => simp only [monomial_comp, eval₂_mul', eval₂_C, eval₂_monomial, eval₂_pow']
end Algebra
end Eval
end CommSemiring
end Polynomial |
.lake/packages/mathlib/Mathlib/Algebra/Prime/Lemmas.lean | import Mathlib.Algebra.Divisibility.Hom
import Mathlib.Algebra.Group.Irreducible.Lemmas
import Mathlib.Algebra.GroupWithZero.Equiv
import Mathlib.Algebra.Prime.Defs
import Mathlib.Order.Monotone.Defs
/-!
# Associated, prime, and irreducible elements.
In this file we define the predicate `Prime p`
saying that an element of a commutative monoid with zero is prime.
Namely, `Prime p` means that `p` isn't zero, it isn't a unit,
and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`;
In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Irreducible`,
however this is not true in general.
We also define an equivalence relation `Associated`
saying that two elements of a monoid differ by a multiplication by a unit.
Then we show that the quotient type `Associates` is a monoid
and prove basic properties of this quotient.
-/
assert_not_exists IsOrderedMonoid Multiset
variable {M N : Type*}
section Prime
variable [CommMonoidWithZero M]
section Map
variable [CommMonoidWithZero N] {F : Type*} {G : Type*} [FunLike F M N]
variable [MonoidWithZeroHomClass F M N] [FunLike G N M] [MulHomClass G N M]
variable (f : F) (g : G) {p : M}
theorem comap_prime (hinv : ∀ a, g (f a : N) = a) (hp : Prime (f p)) : Prime p :=
⟨fun h => hp.1 <| by simp [h], fun h => hp.2.1 <| h.map f, fun a b h => by
refine
(hp.2.2 (f a) (f b) <| by
convert map_dvd f h
simp).imp
?_ ?_ <;>
· intro h
convert ← map_dvd g h <;> apply hinv⟩
theorem MulEquiv.prime_iff {E : Type*} [EquivLike E M N] [MulEquivClass E M N] (e : E) :
Prime (e p) ↔ Prime p := by
let e := MulEquivClass.toMulEquiv e
exact ⟨comap_prime e e.symm fun a => by simp,
fun h => (comap_prime e.symm e fun a => by simp) <| (e.symm_apply_apply p).substr h⟩
end Map
end Prime
theorem Prime.left_dvd_or_dvd_right_of_dvd_mul [CancelCommMonoidWithZero M] {p : M} (hp : Prime p)
{a b : M} : a ∣ p * b → p ∣ a ∨ a ∣ b := by
rintro ⟨c, hc⟩
rcases hp.2.2 a c (hc ▸ dvd_mul_right _ _) with (h | ⟨x, rfl⟩)
· exact Or.inl h
· rw [mul_left_comm, mul_right_inj' hp.ne_zero] at hc
exact Or.inr (hc.symm ▸ dvd_mul_right _ _)
theorem Prime.pow_dvd_of_dvd_mul_left [CancelCommMonoidWithZero M] {p a b : M} (hp : Prime p)
(n : ℕ) (h : ¬p ∣ a) (h' : p ^ n ∣ a * b) : p ^ n ∣ b := by
induction n with
| zero =>
rw [pow_zero]
exact one_dvd b
| succ n ih =>
obtain ⟨c, rfl⟩ := ih (dvd_trans (pow_dvd_pow p n.le_succ) h')
rw [pow_succ]
apply mul_dvd_mul_left _ ((hp.dvd_or_dvd _).resolve_left h)
rwa [← mul_dvd_mul_iff_left (pow_ne_zero n hp.ne_zero), ← pow_succ, mul_left_comm]
theorem Prime.pow_dvd_of_dvd_mul_right [CancelCommMonoidWithZero M] {p a b : M} (hp : Prime p)
(n : ℕ) (h : ¬p ∣ b) (h' : p ^ n ∣ a * b) : p ^ n ∣ a := by
rw [mul_comm] at h'
exact hp.pow_dvd_of_dvd_mul_left n h h'
theorem Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd [CancelCommMonoidWithZero M] {p a b : M}
{n : ℕ} (hp : Prime p) (hpow : p ^ n.succ ∣ a ^ n.succ * b ^ n) (hb : ¬p ^ 2 ∣ b) : p ∣ a := by
-- Suppose `p ∣ b`, write `b = p * x` and `hy : a ^ n.succ * b ^ n = p ^ n.succ * y`.
rcases hp.dvd_or_dvd ((dvd_pow_self p (Nat.succ_ne_zero n)).trans hpow) with H | hbdiv
· exact hp.dvd_of_dvd_pow H
obtain ⟨x, rfl⟩ := hp.dvd_of_dvd_pow hbdiv
obtain ⟨y, hy⟩ := hpow
-- Then we can divide out a common factor of `p ^ n` from the equation `hy`.
have : a ^ n.succ * x ^ n = p * y := by
refine mul_left_cancel₀ (pow_ne_zero n hp.ne_zero) ?_
rw [← mul_assoc _ p, ← pow_succ, ← hy, mul_pow, ← mul_assoc (a ^ n.succ), mul_comm _ (p ^ n),
mul_assoc]
-- So `p ∣ a` (and we're done) or `p ∣ x`, which can't be the case since it implies `p^2 ∣ b`.
refine hp.dvd_of_dvd_pow ((hp.dvd_or_dvd ⟨_, this⟩).resolve_right fun hdvdx => hb ?_)
obtain ⟨z, rfl⟩ := hp.dvd_of_dvd_pow hdvdx
rw [pow_two, ← mul_assoc]
exact dvd_mul_right _ _
theorem prime_pow_succ_dvd_mul {M : Type*} [CancelCommMonoidWithZero M] {p x y : M} (h : Prime p)
{i : ℕ} (hxy : p ^ (i + 1) ∣ x * y) : p ^ (i + 1) ∣ x ∨ p ∣ y := by
rw [or_iff_not_imp_right]
exact fun a ↦ Prime.pow_dvd_of_dvd_mul_right h (i + 1) a hxy
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero M] {a p : M}
theorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul (hp : Prime p) {a b : M} {k l : ℕ} :
p ^ k ∣ a → p ^ l ∣ b → p ^ (k + l + 1) ∣ a * b → p ^ (k + 1) ∣ a ∨ p ^ (l + 1) ∣ b :=
fun ⟨x, hx⟩ ⟨y, hy⟩ ⟨z, hz⟩ =>
have h : p ^ (k + l) * (x * y) = p ^ (k + l) * (p * z) := by
simpa [mul_comm, pow_add, hx, hy, mul_assoc, mul_left_comm] using hz
have hp0 : p ^ (k + l) ≠ 0 := pow_ne_zero _ hp.ne_zero
have hpd : p ∣ x * y := ⟨z, by rwa [mul_right_inj' hp0] at h⟩
(hp.dvd_or_dvd hpd).elim
(fun ⟨d, hd⟩ => Or.inl ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩)
fun ⟨d, hd⟩ => Or.inr ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩
theorem Prime.not_isSquare (hp : Prime p) : ¬IsSquare p :=
hp.irreducible.not_isSquare
theorem IsSquare.not_prime (ha : IsSquare a) : ¬Prime a := fun h => h.not_isSquare ha
theorem not_prime_pow {n : ℕ} (hn : n ≠ 1) : ¬Prime (a ^ n) := fun hp =>
not_irreducible_pow hn hp.irreducible
end CancelCommMonoidWithZero
section CommMonoidWithZero
theorem DvdNotUnit.isUnit_of_irreducible_right [CommMonoidWithZero M] {p q : M}
(h : DvdNotUnit p q) (hq : Irreducible q) : IsUnit p := by
obtain ⟨_, x, hx, hx'⟩ := h
exact ((irreducible_iff.1 hq).right hx').resolve_right hx
theorem not_irreducible_of_not_unit_dvdNotUnit [CommMonoidWithZero M] {p q : M} (hp : ¬IsUnit p)
(h : DvdNotUnit p q) : ¬Irreducible q :=
mt h.isUnit_of_irreducible_right hp
theorem DvdNotUnit.not_unit [CommMonoidWithZero M] {p q : M} (hp : DvdNotUnit p q) : ¬IsUnit q := by
obtain ⟨-, x, hx, rfl⟩ := hp
exact fun hc => hx (isUnit_iff_dvd_one.mpr (dvd_of_mul_left_dvd (isUnit_iff_dvd_one.mp hc)))
end CommMonoidWithZero
section CancelCommMonoidWithZero
theorem DvdNotUnit.ne [CancelCommMonoidWithZero M] {p q : M} (h : DvdNotUnit p q) : p ≠ q := by
by_contra hcontra
obtain ⟨hp, x, hx', hx''⟩ := h
simp_all
theorem pow_injective_of_not_isUnit [CancelCommMonoidWithZero M] {q : M} (hq : ¬IsUnit q)
(hq' : q ≠ 0) : Function.Injective fun n : ℕ => q ^ n := by
refine injective_of_lt_imp_ne fun n m h => DvdNotUnit.ne ⟨pow_ne_zero n hq', q ^ (m - n), ?_, ?_⟩
· exact not_isUnit_of_not_isUnit_dvd hq (dvd_pow (dvd_refl _) (Nat.sub_pos_of_lt h).ne')
· exact (pow_mul_pow_sub q h.le).symm
theorem pow_inj_of_not_isUnit [CancelCommMonoidWithZero M] {q : M} (hq : ¬IsUnit q)
(hq' : q ≠ 0) {m n : ℕ} : q ^ m = q ^ n ↔ m = n :=
(pow_injective_of_not_isUnit hq hq').eq_iff
end CancelCommMonoidWithZero |
.lake/packages/mathlib/Mathlib/Algebra/Prime/Defs.lean | import Mathlib.Algebra.Group.Irreducible.Defs
import Mathlib.Algebra.GroupWithZero.Divisibility
/-!
# Prime elements
In this file we define the predicate `Prime p`
saying that an element of a commutative monoid with zero is prime.
Namely, `Prime p` means that `p` isn't zero, it isn't a unit,
and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`;
In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Irreducible`
(see `irreducible_iff_prime`), however this is not true in general.
## Main definitions
* `Prime`: a prime element of a commutative monoid with zero
## Main results
* `irreducible_iff_prime`: the two definitions are equivalent in a decomposition monoid.
-/
assert_not_exists IsOrderedMonoid Multiset
variable {M : Type*}
section Prime
variable [CommMonoidWithZero M]
/-- An element `p` of a commutative monoid with zero (e.g., a ring) is called *prime*,
if it's not zero, not a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`. -/
def Prime (p : M) : Prop :=
p ≠ 0 ∧ ¬IsUnit p ∧ ∀ a b, p ∣ a * b → p ∣ a ∨ p ∣ b
namespace Prime
variable {p : M} (hp : Prime p)
include hp
theorem ne_zero : p ≠ 0 :=
hp.1
theorem not_unit : ¬IsUnit p :=
hp.2.1
theorem not_dvd_one : ¬p ∣ 1 :=
mt (isUnit_of_dvd_one ·) hp.not_unit
theorem ne_one : p ≠ 1 := fun h => hp.2.1 (h.symm ▸ isUnit_one)
theorem dvd_or_dvd {a b : M} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b :=
hp.2.2 a b h
theorem dvd_mul {a b : M} : p ∣ a * b ↔ p ∣ a ∨ p ∣ b :=
⟨hp.dvd_or_dvd, (Or.elim · (dvd_mul_of_dvd_left · _) (dvd_mul_of_dvd_right · _))⟩
theorem isPrimal : IsPrimal p := fun _a _b dvd ↦ (hp.dvd_or_dvd dvd).elim
(fun h ↦ ⟨p, 1, h, one_dvd _, (mul_one p).symm⟩) fun h ↦ ⟨1, p, one_dvd _, h, (one_mul p).symm⟩
theorem not_dvd_mul {a b : M} (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) : ¬ p ∣ a * b :=
hp.dvd_mul.not.mpr <| not_or.mpr ⟨ha, hb⟩
theorem dvd_of_dvd_pow {a : M} {n : ℕ} (h : p ∣ a ^ n) : p ∣ a := by
induction n with
| zero =>
rw [pow_zero] at h
have := isUnit_of_dvd_one h
have := not_unit hp
contradiction
| succ n ih =>
rw [pow_succ'] at h
rcases dvd_or_dvd hp h with dvd_a | dvd_pow
· assumption
· exact ih dvd_pow
theorem dvd_pow_iff_dvd {a : M} {n : ℕ} (hn : n ≠ 0) : p ∣ a ^ n ↔ p ∣ a :=
⟨hp.dvd_of_dvd_pow, (dvd_pow · hn)⟩
end Prime
@[simp]
theorem not_prime_zero : ¬Prime (0 : M) := fun h => h.ne_zero rfl
@[simp]
theorem not_prime_one : ¬Prime (1 : M) := fun h => h.not_unit isUnit_one
end Prime
theorem Irreducible.not_dvd_isUnit [CommMonoid M] {p u : M} (hp : Irreducible p) (hu : IsUnit u) :
¬p ∣ u :=
mt (isUnit_of_dvd_unit · hu) hp.not_isUnit
theorem Irreducible.not_dvd_one [CommMonoid M] {p : M} (hp : Irreducible p) : ¬p ∣ 1 :=
hp.not_dvd_isUnit isUnit_one
theorem Irreducible.not_dvd_unit [CommMonoid M] {p : M} (u : Mˣ) (hp : Irreducible p) :
¬ p ∣ u :=
hp.not_dvd_isUnit u.isUnit
@[simp]
theorem not_irreducible_zero [MonoidWithZero M] : ¬Irreducible (0 : M)
| ⟨hn0, h⟩ =>
have : IsUnit (0 : M) ∨ IsUnit (0 : M) := h (mul_zero 0).symm
this.elim hn0 hn0
theorem Irreducible.ne_zero [MonoidWithZero M] : ∀ {p : M}, Irreducible p → p ≠ 0
| _, hp, rfl => not_irreducible_zero hp
/-- If `p` and `q` are irreducible, then `p ∣ q` implies `q ∣ p`. -/
theorem Irreducible.dvd_symm [Monoid M] {p q : M} (hp : Irreducible p) (hq : Irreducible q) :
p ∣ q → q ∣ p := by
rintro ⟨q', rfl⟩
rw [IsUnit.mul_right_dvd (Or.resolve_left (of_irreducible_mul hq) hp.not_isUnit)]
theorem Irreducible.dvd_comm [Monoid M] {p q : M} (hp : Irreducible p) (hq : Irreducible q) :
p ∣ q ↔ q ∣ p :=
⟨hp.dvd_symm hq, hq.dvd_symm hp⟩
section CommMonoidWithZero
variable [CommMonoidWithZero M]
theorem Irreducible.prime_of_isPrimal {a : M}
(irr : Irreducible a) (primal : IsPrimal a) : Prime a :=
⟨irr.ne_zero, irr.not_isUnit, fun a b dvd ↦ by
obtain ⟨d₁, d₂, h₁, h₂, rfl⟩ := primal dvd
exact (of_irreducible_mul irr).symm.imp (·.mul_right_dvd.mpr h₁) (·.mul_left_dvd.mpr h₂)⟩
theorem Irreducible.prime [DecompositionMonoid M] {a : M} (irr : Irreducible a) : Prime a :=
irr.prime_of_isPrimal (DecompositionMonoid.primal a)
end CommMonoidWithZero
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero M] {p : M}
protected theorem Prime.irreducible (hp : Prime p) : Irreducible p :=
⟨hp.not_unit, fun a b ↦ by
rintro rfl
exact (hp.dvd_or_dvd dvd_rfl).symm.imp
(isUnit_of_dvd_one <| (mul_dvd_mul_iff_right <| right_ne_zero_of_mul hp.ne_zero).mp <|
dvd_mul_of_dvd_right · _)
(isUnit_of_dvd_one <| (mul_dvd_mul_iff_left <| left_ne_zero_of_mul hp.ne_zero).mp <|
dvd_mul_of_dvd_left · _)⟩
theorem irreducible_iff_prime [DecompositionMonoid M] {a : M} : Irreducible a ↔ Prime a :=
⟨Irreducible.prime, Prime.irreducible⟩
end CancelCommMonoidWithZero |
.lake/packages/mathlib/Mathlib/Algebra/Squarefree/Basic.lean | import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Nilpotent.Basic
import Mathlib.RingTheory.UniqueFactorizationDomain.GCDMonoid
import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicity
/-!
# Squarefree elements of monoids
An element of a monoid is squarefree when it is not divisible by any squares
except the squares of units.
Results about squarefree natural numbers are proved in `Data.Nat.Squarefree`.
## Main Definitions
- `Squarefree r` indicates that `r` is only divisible by `x * x` if `x` is a unit.
## Main Results
- `multiplicity.squarefree_iff_emultiplicity_le_one`: `x` is `Squarefree` iff for every `y`, either
`emultiplicity y x ≤ 1` or `IsUnit y`.
- `UniqueFactorizationMonoid.squarefree_iff_nodup_factors`: A nonzero element `x` of a unique
factorization monoid is squarefree iff `factors x` has no duplicate factors.
## Tags
squarefree, multiplicity
-/
variable {R : Type*}
/-- An element of a monoid is squarefree if the only squares that
divide it are the squares of units. -/
def Squarefree [Monoid R] (r : R) : Prop :=
∀ x : R, x * x ∣ r → IsUnit x
theorem IsRelPrime.of_squarefree_mul [CommMonoid R] {m n : R} (h : Squarefree (m * n)) :
IsRelPrime m n := fun c hca hcb ↦ h c (mul_dvd_mul hca hcb)
@[simp]
theorem IsUnit.squarefree [CommMonoid R] {x : R} (h : IsUnit x) : Squarefree x := fun _ hdvd =>
isUnit_of_mul_isUnit_left (isUnit_of_dvd_unit hdvd h)
theorem squarefree_one [CommMonoid R] : Squarefree (1 : R) :=
isUnit_one.squarefree
@[simp]
theorem not_squarefree_zero [MonoidWithZero R] [Nontrivial R] : ¬Squarefree (0 : R) := by
rw [Squarefree, not_forall]
exact ⟨0, by simp⟩
theorem Squarefree.ne_zero [MonoidWithZero R] [Nontrivial R] {m : R} (hm : Squarefree (m : R)) :
m ≠ 0 := by
rintro rfl
exact not_squarefree_zero hm
@[simp]
theorem Irreducible.squarefree [CommMonoid R] {x : R} (h : Irreducible x) : Squarefree x := by
rintro y ⟨z, hz⟩
rw [mul_assoc] at hz
rcases h.isUnit_or_isUnit hz with (hu | hu)
· exact hu
· apply isUnit_of_mul_isUnit_left hu
@[simp]
theorem Prime.squarefree [CancelCommMonoidWithZero R] {x : R} (h : Prime x) : Squarefree x :=
h.irreducible.squarefree
theorem Squarefree.of_mul_left [Monoid R] {m n : R} (hmn : Squarefree (m * n)) : Squarefree m :=
fun p hp => hmn p (dvd_mul_of_dvd_left hp n)
theorem Squarefree.of_mul_right [CommMonoid R] {m n : R} (hmn : Squarefree (m * n)) :
Squarefree n := fun p hp => hmn p (dvd_mul_of_dvd_right hp m)
theorem Squarefree.squarefree_of_dvd [Monoid R] {x y : R} (hdvd : x ∣ y) (hsq : Squarefree y) :
Squarefree x := fun _ h => hsq _ (h.trans hdvd)
theorem Squarefree.eq_zero_or_one_of_pow_of_not_isUnit [Monoid R] {x : R} {n : ℕ}
(h : Squarefree (x ^ n)) (h' : ¬ IsUnit x) :
n = 0 ∨ n = 1 := by
contrapose! h'
replace h' : 2 ≤ n := by omega
have : x * x ∣ x ^ n := by rw [← sq]; exact pow_dvd_pow x h'
exact h.squarefree_of_dvd this x (refl _)
theorem Squarefree.pow_dvd_of_pow_dvd [Monoid R] {x y : R} {n : ℕ}
(hx : Squarefree y) (h : x ^ n ∣ y) : x ^ n ∣ x := by
by_cases hu : IsUnit x
· exact (hu.pow n).dvd
· rcases (hx.squarefree_of_dvd h).eq_zero_or_one_of_pow_of_not_isUnit hu with rfl | rfl <;> simp
section SquarefreeGcdOfSquarefree
variable {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α]
theorem Squarefree.gcd_right (a : α) {b : α} (hb : Squarefree b) : Squarefree (gcd a b) :=
hb.squarefree_of_dvd (gcd_dvd_right _ _)
theorem Squarefree.gcd_left {a : α} (b : α) (ha : Squarefree a) : Squarefree (gcd a b) :=
ha.squarefree_of_dvd (gcd_dvd_left _ _)
end SquarefreeGcdOfSquarefree
theorem squarefree_iff_emultiplicity_le_one [CommMonoid R] (r : R) :
Squarefree r ↔ ∀ x : R, emultiplicity x r ≤ 1 ∨ IsUnit x := by
refine forall_congr' fun a => ?_
rw [← sq, pow_dvd_iff_le_emultiplicity, or_iff_not_imp_left, not_le, imp_congr _ Iff.rfl]
norm_cast
rw [← one_add_one_eq_two]
exact Order.add_one_le_iff_of_not_isMax (by simp)
section Irreducible
variable [CommMonoidWithZero R] [WfDvdMonoid R]
theorem squarefree_iff_no_irreducibles {x : R} (hx₀ : x ≠ 0) :
Squarefree x ↔ ∀ p, Irreducible p → ¬ (p * p ∣ x) := by
refine ⟨fun h p hp hp' ↦ hp.not_isUnit (h p hp'), fun h d hd ↦ by_contra fun hdu ↦ ?_⟩
have hd₀ : d ≠ 0 := ne_zero_of_dvd_ne_zero (ne_zero_of_dvd_ne_zero hx₀ hd) (dvd_mul_left d d)
obtain ⟨p, irr, dvd⟩ := WfDvdMonoid.exists_irreducible_factor hdu hd₀
exact h p irr ((mul_dvd_mul dvd dvd).trans hd)
theorem irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree (r : R) :
(∀ x : R, Irreducible x → ¬x * x ∣ r) ↔ (r = 0 ∧ ∀ x : R, ¬Irreducible x) ∨ Squarefree r := by
refine ⟨fun h ↦ ?_, ?_⟩
· rcases eq_or_ne r 0 with (rfl | hr)
· exact .inl (by simpa using h)
· exact .inr ((squarefree_iff_no_irreducibles hr).mpr h)
· rintro (⟨rfl, h⟩ | h)
· simpa using h
intro x hx t
exact hx.not_isUnit (h x t)
theorem squarefree_iff_irreducible_sq_not_dvd_of_ne_zero {r : R} (hr : r ≠ 0) :
Squarefree r ↔ ∀ x : R, Irreducible x → ¬x * x ∣ r := by
simpa [hr] using (irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree r).symm
theorem squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible {r : R}
(hr : ∃ x : R, Irreducible x) : Squarefree r ↔ ∀ x : R, Irreducible x → ¬x * x ∣ r := by
rw [irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree, ← not_exists]
simp only [hr, not_true, false_or, and_false]
end Irreducible
section IsRadical
section
variable [CommMonoidWithZero R] [DecompositionMonoid R]
theorem Squarefree.isRadical {x : R} (hx : Squarefree x) : IsRadical x :=
(isRadical_iff_pow_one_lt 2 one_lt_two).2 fun y hy ↦ by
obtain ⟨a, b, ha, hb, rfl⟩ := exists_dvd_and_dvd_of_dvd_mul (sq y ▸ hy)
exact (IsRelPrime.of_squarefree_mul hx).mul_dvd ha hb
theorem Squarefree.dvd_pow_iff_dvd {x y : R} {n : ℕ} (hsq : Squarefree x) (h0 : n ≠ 0) :
x ∣ y ^ n ↔ x ∣ y := ⟨hsq.isRadical n y, (·.pow h0)⟩
end
variable [CancelCommMonoidWithZero R] {x y p d : R}
theorem IsRadical.squarefree (h0 : x ≠ 0) (h : IsRadical x) : Squarefree x := by
rintro z ⟨w, rfl⟩
specialize h 2 (z * w) ⟨w, by simp_rw [pow_two, mul_left_comm, ← mul_assoc]⟩
rwa [← one_mul (z * w), mul_assoc, mul_dvd_mul_iff_right, ← isUnit_iff_dvd_one] at h
rw [mul_assoc, mul_ne_zero_iff] at h0; exact h0.2
namespace Squarefree
theorem pow_dvd_of_squarefree_of_pow_succ_dvd_mul_right {k : ℕ}
(hx : Squarefree x) (hp : Prime p) (h : p ^ (k + 1) ∣ x * y) :
p ^ k ∣ y := by
by_cases hxp : p ∣ x
· obtain ⟨x', rfl⟩ := hxp
have hx' : ¬ p ∣ x' := fun contra ↦ hp.not_unit <| hx p (mul_dvd_mul_left p contra)
replace h : p ^ k ∣ x' * y := by
rw [pow_succ', mul_assoc] at h
exact (mul_dvd_mul_iff_left hp.ne_zero).mp h
exact hp.pow_dvd_of_dvd_mul_left _ hx' h
· exact (pow_dvd_pow _ k.le_succ).trans (hp.pow_dvd_of_dvd_mul_left _ hxp h)
theorem pow_dvd_of_squarefree_of_pow_succ_dvd_mul_left {k : ℕ}
(hy : Squarefree y) (hp : Prime p) (h : p ^ (k + 1) ∣ x * y) :
p ^ k ∣ x := by
rw [mul_comm] at h
exact pow_dvd_of_squarefree_of_pow_succ_dvd_mul_right hy hp h
variable [DecompositionMonoid R]
theorem dvd_of_squarefree_of_mul_dvd_mul_right (hx : Squarefree x) (h : d * d ∣ x * y) : d ∣ y := by
nontriviality R
obtain ⟨a, b, ha, hb, eq⟩ := exists_dvd_and_dvd_of_dvd_mul h
replace ha : Squarefree a := hx.squarefree_of_dvd ha
obtain ⟨c, hc⟩ : a ∣ d := ha.isRadical 2 d ⟨b, by rw [sq, eq]⟩
rw [hc, mul_assoc, (mul_right_injective₀ ha.ne_zero).eq_iff] at eq
exact dvd_trans ⟨c, by rw [hc, ← eq, mul_comm]⟩ hb
theorem dvd_of_squarefree_of_mul_dvd_mul_left (hy : Squarefree y) (h : d * d ∣ x * y) : d ∣ x :=
dvd_of_squarefree_of_mul_dvd_mul_right hy (mul_comm x y ▸ h)
end Squarefree
variable [DecompositionMonoid R]
/-- `x * y` is square-free iff `x` and `y` have no common factors and are themselves square-free. -/
theorem squarefree_mul_iff : Squarefree (x * y) ↔ IsRelPrime x y ∧ Squarefree x ∧ Squarefree y :=
⟨fun h ↦ ⟨IsRelPrime.of_squarefree_mul h, h.of_mul_left, h.of_mul_right⟩,
fun ⟨hp, sqx, sqy⟩ _ dvd ↦ hp (sqy.dvd_of_squarefree_of_mul_dvd_mul_left dvd)
(sqx.dvd_of_squarefree_of_mul_dvd_mul_right dvd)⟩
open scoped Function in
theorem Finset.squarefree_prod_of_pairwise_isCoprime {ι : Type*} {s : Finset ι}
{f : ι → R} (hs : Set.Pairwise s (IsRelPrime on f)) (hs' : ∀ i ∈ s, Squarefree (f i)) :
Squarefree (∏ i ∈ s, f i) := by
induction s using Finset.cons_induction with
| empty => simp
| cons a s ha ih =>
rw [Finset.prod_cons, squarefree_mul_iff]
rw [Finset.coe_cons, Set.pairwise_insert] at hs
refine ⟨.prod_right fun i hi ↦ ?_, hs' a (by simp), ?_⟩
· exact (hs.right i (by simp [hi]) fun h ↦ ha (h ▸ hi)).left
· exact ih hs.left fun i hi ↦ hs' i <| Finset.mem_cons_of_mem hi
theorem isRadical_iff_squarefree_or_zero : IsRadical x ↔ Squarefree x ∨ x = 0 :=
⟨fun hx ↦ (em <| x = 0).elim .inr fun h ↦ .inl <| hx.squarefree h,
Or.rec Squarefree.isRadical <| by
rintro rfl
rw [zero_isRadical_iff]
infer_instance⟩
theorem isRadical_iff_squarefree_of_ne_zero (h : x ≠ 0) : IsRadical x ↔ Squarefree x :=
⟨IsRadical.squarefree h, Squarefree.isRadical⟩
end IsRadical
namespace UniqueFactorizationMonoid
variable [CancelCommMonoidWithZero R] [UniqueFactorizationMonoid R]
lemma _root_.exists_squarefree_dvd_pow_of_ne_zero {x : R} (hx : x ≠ 0) :
∃ (y : R) (n : ℕ), Squarefree y ∧ y ∣ x ∧ x ∣ y ^ n := by
induction x using WfDvdMonoid.induction_on_irreducible with
| zero => contradiction
| unit u hu => exact ⟨1, 0, squarefree_one, one_dvd u, hu.dvd⟩
| mul z p hz hp ih =>
obtain ⟨y, n, hy, hyx, hy'⟩ := ih hz
rcases n.eq_zero_or_pos with rfl | hn
· exact ⟨p, 1, hp.squarefree, dvd_mul_right p z, by simp [isUnit_of_dvd_one (pow_zero y ▸ hy')]⟩
by_cases hp' : p ∣ y
· exact ⟨y, n + 1, hy, dvd_mul_of_dvd_right hyx _,
mul_comm p z ▸ pow_succ y n ▸ mul_dvd_mul hy' hp'⟩
· suffices Squarefree (p * y) from ⟨p * y, n, this,
mul_dvd_mul_left p hyx, mul_pow p y n ▸ mul_dvd_mul (dvd_pow_self p hn.ne') hy'⟩
exact squarefree_mul_iff.mpr ⟨hp.isRelPrime_iff_not_dvd.mpr hp', hp.squarefree, hy⟩
theorem squarefree_iff_nodup_normalizedFactors [NormalizationMonoid R] {x : R}
(x0 : x ≠ 0) : Squarefree x ↔ Multiset.Nodup (normalizedFactors x) := by
classical
rw [squarefree_iff_emultiplicity_le_one, Multiset.nodup_iff_count_le_one]
haveI := nontrivial_of_ne x 0 x0
constructor <;> intro h a
· by_cases hmem : a ∈ normalizedFactors x
· have ha := irreducible_of_normalized_factor _ hmem
rcases h a with (h | h)
· rw [← normalize_normalized_factor _ hmem]
rw [emultiplicity_eq_count_normalizedFactors ha x0] at h
assumption_mod_cast
· have := ha.1
contradiction
· simp [Multiset.count_eq_zero_of_notMem hmem]
· rw [or_iff_not_imp_right]
intro hu
rcases eq_or_ne a 0 with rfl | h0
· simp [x0]
rcases WfDvdMonoid.exists_irreducible_factor hu h0 with ⟨b, hib, hdvd⟩
apply le_trans (emultiplicity_le_emultiplicity_of_dvd_left hdvd)
rw [emultiplicity_eq_count_normalizedFactors hib x0]
exact_mod_cast h (normalize b)
end UniqueFactorizationMonoid
namespace Int
@[simp]
theorem squarefree_natAbs {n : ℤ} : Squarefree n.natAbs ↔ Squarefree n := by
simp_rw [Squarefree, natAbs_surjective.forall, ← natAbs_mul, natAbs_dvd_natAbs,
isUnit_iff_natAbs_eq, Nat.isUnit_iff]
@[simp]
theorem squarefree_natCast {n : ℕ} : Squarefree (n : ℤ) ↔ Squarefree n := by
rw [← squarefree_natAbs, natAbs_natCast]
end Int |
.lake/packages/mathlib/Mathlib/Algebra/Homology/ExactSequence.lean | import Mathlib.Algebra.Homology.ShortComplex.Exact
import Mathlib.CategoryTheory.ComposableArrows.Basic
/-!
# 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
/-- A map of short complexes induces a map of composable arrows with the same data. -/
def ShortComplex.mapToComposableArrows {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) :
S₁.toComposableArrows ⟶ S₂.toComposableArrows :=
ComposableArrows.homMk₂ φ.τ₁ φ.τ₂ φ.τ₃ φ.comm₁₂.symm φ.comm₂₃.symm
@[simp]
theorem ShortComplex.mapToComposableArrows_app_0 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) :
(ShortComplex.mapToComposableArrows φ).app 0 = φ.τ₁ := rfl
@[simp]
theorem ShortComplex.mapToComposableArrows_app_1 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) :
(ShortComplex.mapToComposableArrows φ).app 1 = φ.τ₂ := rfl
@[simp]
theorem ShortComplex.mapToComposableArrows_app_2 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) :
(ShortComplex.mapToComposableArrows φ).app 2 = φ.τ₃ := rfl
@[simp]
theorem ShortComplex.mapToComposableArrows_id {S₁ : ShortComplex C} :
(ShortComplex.mapToComposableArrows (𝟙 S₁)) = 𝟙 S₁.toComposableArrows := by
cat_disch
@[simp]
theorem ShortComplex.mapToComposableArrows_comp {S₁ S₂ S₃ : ShortComplex C} (φ : S₁ ⟶ S₂)
(ψ : S₂ ⟶ S₃) : ShortComplex.mapToComposableArrows (φ ≫ ψ) =
ShortComplex.mapToComposableArrows φ ≫ ShortComplex.mapToComposableArrows ψ := by
cat_disch
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
zero i hi := by simp at hi
lemma isComplex₁ (S : ComposableArrows C 1) : S.IsComplex where
zero i hi := by 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 : Prop extends S.IsComplex 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 <;> simp
inv_hom_id := by ext <;> 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 <;> simp
inv_hom_id := by ext <;> 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₀
exact i hi := by simp 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 cutsat)
· intro h
refine IsComplex.mk (fun i hi => ?_)
obtain rfl : i = 0 := by cutsat
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
lemma _root_.CategoryTheory.ShortComplex.isComplex_toComposableArrows (S : ShortComplex C) :
S.toComposableArrows.IsComplex :=
-- Disable `Fin.reduceFinMk` because otherwise `Precompose.map_one_succ` does not apply. (https://github.com/leanprover-community/mathlib4/issues/27382)
isComplex₂_mk _ (by simp [-Fin.reduceFinMk])
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 cutsat)
· intro h
refine Exact.mk hS (fun i hi => ?_)
obtain rfl : i = 0 := by cutsat
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 cutsat)
· 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 cutsat)
· 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
lemma Exact.isIso_map' {C : Type*} [Category C] [Preadditive C]
[Balanced C] {n : ℕ} {S : ComposableArrows C n} (hS : S.Exact) (k : ℕ) (hk : k + 3 ≤ n)
(h₀ : S.map' k (k + 1) = 0) (h₁ : S.map' (k + 2) (k + 3) = 0) :
IsIso (S.map' (k + 1) (k + 2)) := by
have := (hS.exact k).mono_g h₀
have := (hS.exact (k + 1)).epi_f h₁
apply isIso_of_mono_of_epi
end ComposableArrows
end CategoryTheory |
.lake/packages/mathlib/Mathlib/Algebra/Homology/AlternatingConst.lean | import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex
import Mathlib.Algebra.Module.BigOperators
import Mathlib.AlgebraicTopology.ExtraDegeneracy
/-!
# The alternating constant complex
Given an object `X : C` and endomorphisms `φ, ψ : X ⟶ X` such that `φ ∘ ψ = ψ ∘ φ = 0`, this file
defines the periodic chain and cochain complexes
`... ⟶ X --φ--> X --ψ--> X --φ--> X --ψ--> 0` and `0 ⟶ X --ψ--> X --φ--> X --ψ--> X --φ--> ...`
(or more generally for any complex shape `c` on `ℕ` where `c.Rel i j` implies `i` and `j` have
different parity). We calculate the homology of these periodic complexes.
In particular, we show `... ⟶ X --𝟙--> X --0--> X --𝟙--> X --0--> X ⟶ 0` is homotopy equivalent
to the single complex where `X` is in degree `0`.
-/
universe v u
open CategoryTheory Limits
namespace ComplexShape
lemma up_nat_odd_add {i j : ℕ} (h : (ComplexShape.up ℕ).Rel i j) : Odd (i + j) := by
subst h
norm_num
lemma down_nat_odd_add {i j : ℕ} (h : (ComplexShape.down ℕ).Rel i j) : Odd (i + j) := by
subst h
norm_num
end ComplexShape
namespace HomologicalComplex
open ShortComplex
variable {C : Type*} [Category C] [Limits.HasZeroMorphisms C]
(A : C) {φ : A ⟶ A} {ψ : A ⟶ A} (hOdd : φ ≫ ψ = 0) (hEven : ψ ≫ φ = 0)
/-- Let `c : ComplexShape ℕ` be such that `i j : ℕ` have opposite parity if they are related by
`c`. Let `φ, ψ : A ⟶ A` be such that `φ ∘ ψ = ψ ∘ φ = 0`. This is a complex of shape `c` whose
objects are all `A`. For all `i, j` related by `c`, `dᵢⱼ = φ` when `i` is even, and `dᵢⱼ = ψ` when
`i` is odd. -/
@[simps!]
noncomputable def alternatingConst {c : ComplexShape ℕ} [DecidableRel c.Rel]
(hc : ∀ i j, c.Rel i j → Odd (i + j)) :
HomologicalComplex C c where
X n := A
d i j :=
if hij : c.Rel i j then
if hi : Even i then φ
else ψ
else 0
shape i j := by aesop
d_comp_d' i j k hij hjk := by
have := hc i j hij
split_ifs with hi hj hj
· exact False.elim <| Nat.not_odd_iff_even.2 hi <| by simp_all [Nat.odd_add]
· assumption
· assumption
· exact False.elim <| hj <| by simp_all [Nat.odd_add]
variable {c : ComplexShape ℕ} [DecidableRel c.Rel] (hc : ∀ i j, c.Rel i j → Odd (i + j))
open HomologicalComplex hiding mk
/-- The `i, j, k`th short complex associated to the alternating constant complex on `φ, ψ : A ⟶ A`
is `A --ψ--> A --φ--> A` when `i ~ j, j ~ k` and `j` is even. -/
noncomputable def alternatingConstScIsoEven
{i j k : ℕ} (hij : c.Rel i j) (hjk : c.Rel j k) (h : Even j) :
(alternatingConst A hOdd hEven hc).sc' i j k ≅ ShortComplex.mk ψ φ hEven :=
isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _)
(by
simp_all only [alternatingConst, dite_eq_ite, Iso.refl_hom, Category.id_comp,
shortComplexFunctor'_obj_f, ↓reduceIte, Category.comp_id, right_eq_ite_iff]
intro hi
have := hc i j hij
exact False.elim <| Nat.not_odd_iff_even.2 hi <| by simp_all [Nat.odd_add])
(by simp_all [alternatingConst])
/-- The `i, j, k`th short complex associated to the alternating constant complex on `φ, ψ : A ⟶ A`
is `A --φ--> A --ψ--> A` when `i ~ j, j ~ k` and `j` is even. -/
noncomputable def alternatingConstScIsoOdd
{i j k : ℕ} (hij : c.Rel i j) (hjk : c.Rel j k) (h : Odd j) :
(alternatingConst A hOdd hEven hc).sc' i j k ≅ ShortComplex.mk φ ψ hOdd :=
isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _)
(by
simp_all only [alternatingConst, dite_eq_ite, Iso.refl_hom, Category.id_comp,
shortComplexFunctor'_obj_f, ↓reduceIte, Category.comp_id, left_eq_ite_iff]
intro hi
have := hc i j hij
exact False.elim <| Nat.not_even_iff_odd.2 h <| by simp_all [Nat.odd_add])
(by simp_all [alternatingConst])
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma alternatingConst_iCycles_even_comp [CategoryWithHomology C]
{j : ℕ} (hpj : c.Rel (c.prev j) j) (hnj : c.Rel j (c.next j)) (h : Even j) :
(alternatingConst A hOdd hEven hc).iCycles j ≫ φ = 0 := by
rw [← cancel_epi (ShortComplex.cyclesMapIso
(alternatingConstScIsoEven A hOdd hEven hc hpj hnj h)).inv]
simpa [HomologicalComplex.iCycles, -Preadditive.IsIso.comp_left_eq_zero, HomologicalComplex.sc,
HomologicalComplex.shortComplexFunctor, alternatingConstScIsoEven,
Category.id_comp (X := (alternatingConst A hOdd hEven hc).X _)]
using (ShortComplex.mk ψ φ hEven).iCycles_g
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma alternatingConst_iCycles_odd_comp [CategoryWithHomology C]
{j : ℕ} (hpj : c.Rel (c.prev j) j) (hnj : c.Rel j (c.next j)) (h : Odd j) :
(alternatingConst A hOdd hEven hc).iCycles j ≫ ψ = 0 := by
rw [← cancel_epi (ShortComplex.cyclesMapIso
(alternatingConstScIsoOdd A hOdd hEven hc hpj hnj h)).inv]
simpa [HomologicalComplex.iCycles, -Preadditive.IsIso.comp_left_eq_zero, HomologicalComplex.sc,
HomologicalComplex.shortComplexFunctor, alternatingConstScIsoOdd,
Category.id_comp (X := (alternatingConst A hOdd hEven hc).X _)]
using (ShortComplex.mk φ ψ hOdd).iCycles_g
/-- The `j`th homology of the alternating constant complex on `φ, ψ : A ⟶ A` is the homology of
`A --ψ--> A --φ--> A` when `prev(j) ~ j, j ~ next(j)` and `j` is even. -/
noncomputable def alternatingConstHomologyIsoEven [CategoryWithHomology C]
{j : ℕ} (hpj : c.Rel (c.prev j) j) (hnj : c.Rel j (c.next j)) (h : Even j) :
(alternatingConst A hOdd hEven hc).homology j ≅ (ShortComplex.mk ψ φ hEven).homology :=
ShortComplex.homologyMapIso (alternatingConstScIsoEven A hOdd hEven hc hpj hnj h)
/-- The `j`th homology of the alternating constant complex on `φ, ψ : A ⟶ A` is the homology of
`A --φ--> A --ψ--> A` when `prev(j) ~ j, j ~ next(j)` and `j` is odd. -/
noncomputable def alternatingConstHomologyIsoOdd [CategoryWithHomology C]
{j : ℕ} (hpj : c.Rel (c.prev j) j) (hnj : c.Rel j (c.next j)) (h : Odd j) :
(alternatingConst A hOdd hEven hc).homology j ≅ (ShortComplex.mk φ ψ hOdd).homology :=
ShortComplex.homologyMapIso (alternatingConstScIsoOdd A hOdd hEven hc hpj hnj h)
end HomologicalComplex
open CategoryTheory Limits AlgebraicTopology
variable {C : Type*} [Category C]
namespace ChainComplex
/-- The chain complex `X ←0- X ←𝟙- X ←0- X ←𝟙- X ⋯`.
It is exact away from `0` and has homology `X` at `0`. -/
@[simps]
noncomputable def alternatingConst [HasZeroMorphisms C] : C ⥤ ChainComplex C ℕ where
obj X := HomologicalComplex.alternatingConst X (Category.id_comp 0) (Category.comp_id 0)
(fun _ _ => ComplexShape.down_nat_odd_add)
map {X Y} f := {
f _ := f
comm' i j hij := by by_cases Even i <;> simp_all [-Nat.not_even_iff_odd] }
variable [HasZeroMorphisms C] [HasZeroObject C]
open ZeroObject
/-- The `n`-th homology of the alternating constant complex is zero for non-zero even `n`. -/
noncomputable
def alternatingConstHomologyDataEvenNEZero (X : C) (n : ℕ) (hn : Even n) (h₀ : n ≠ 0) :
((alternatingConst.obj X).sc n).HomologyData :=
.ofIsLimitKernelFork _ (by simp [Nat.even_add_one, hn]) _
(Limits.zeroKernelOfCancelZero _ (by cases n <;> simp_all))
/-- The `n`-th homology of the alternating constant complex is zero for odd `n`. -/
noncomputable
def alternatingConstHomologyDataOdd (X : C) (n : ℕ) (hn : Odd n) :
((alternatingConst.obj X).sc n).HomologyData :=
.ofIsColimitCokernelCofork _ (by simp [hn]) _ (Limits.zeroCokernelOfZeroCancel _ (by simp [hn]))
/-- The `n`-th homology of the alternating constant complex is `X` for `n = 0`. -/
noncomputable
def alternatingConstHomologyDataZero (X : C) (n : ℕ) (hn : n = 0) :
((alternatingConst.obj X).sc n).HomologyData :=
.ofZeros _ (by simp [hn]) (by simp [hn])
instance (X : C) (n : ℕ) : (alternatingConst.obj X).HasHomology n := by
rcases n.even_or_odd with h | h
· rcases n with - | n
· exact ⟨⟨alternatingConstHomologyDataZero X _ rfl⟩⟩
· exact ⟨⟨alternatingConstHomologyDataEvenNEZero X _ h (by simp)⟩⟩
· exact ⟨⟨alternatingConstHomologyDataOdd X _ h⟩⟩
/-- The `n`-th homology of the alternating constant complex is `X` for `n ≠ 0`. -/
lemma alternatingConst_exactAt (X : C) (n : ℕ) (hn : n ≠ 0) :
(alternatingConst.obj X).ExactAt n := by
rcases n.even_or_odd with h | h
· exact ⟨(alternatingConstHomologyDataEvenNEZero X _ h hn), isZero_zero C⟩
· exact ⟨(alternatingConstHomologyDataOdd X _ h), isZero_zero C⟩
/-- The `n`-th homology of the alternating constant complex is `X` for `n = 0`. -/
noncomputable
def alternatingConstHomologyZero (X : C) : (alternatingConst.obj X).homology 0 ≅ X :=
(alternatingConstHomologyDataZero X _ rfl).left.homologyIso
end ChainComplex
variable [Preadditive C] [HasZeroObject C]
/-- The alternating face complex of the constant complex is the alternating constant complex. -/
noncomputable def AlgebraicTopology.alternatingFaceMapComplexConst :
Functor.const _ ⋙ alternatingFaceMapComplex C ≅ ChainComplex.alternatingConst :=
NatIso.ofComponents (fun X ↦ HomologicalComplex.Hom.isoOfComponents (fun _ ↦ Iso.refl _) <| by
rintro _ i rfl
simp [SimplicialObject.δ, ← Finset.sum_smul, Fin.sum_neg_one_pow, Nat.even_add_one,
-Nat.not_even_iff_odd]) (by intros; ext; simp)
namespace ChainComplex
/-- `alternatingConst.obj X` is homotopy equivalent to the chain
complex `(single₀ C).obj X`. -/
noncomputable def alternatingConstHomotopyEquiv (X : C) :
HomotopyEquiv (alternatingConst.obj X) ((single₀ C).obj X) :=
(HomotopyEquiv.ofIso (alternatingFaceMapComplexConst.app X).symm).trans
((SimplicialObject.Augmented.ExtraDegeneracy.const X).homotopyEquiv)
end ChainComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Opposite.lean | import Mathlib.CategoryTheory.Abelian.Opposite
import Mathlib.Algebra.Homology.Additive
import Mathlib.Algebra.Homology.ImageToKernel
import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex
import Mathlib.Algebra.Homology.QuasiIso
/-!
# 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 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 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 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 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 _ => 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)
/-- Auxiliary definition for `opEquivalence`. -/
def opCounitIso : opInverse V c ⋙ opFunctor V c ≅ 𝟭 (HomologicalComplex Vᵒᵖ c.symm) :=
NatIso.ofComponents
fun X => HomologicalComplex.Hom.isoOfComponents fun _ => 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 _ => 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)
/-- Auxiliary definition for `unopEquivalence`. -/
def unopCounitIso : unopInverse V c ⋙ unopFunctor V c ≅ 𝟭 (HomologicalComplex V c.symm) :=
NatIso.ofComponents
fun X => HomologicalComplex.Hom.isoOfComponents fun _ => 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 [comp_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)
instance (K : HomologicalComplex V c) (i : ι) [K.HasHomology i] :
((opFunctor _ _).obj (op K)).HasHomology i := by
dsimp
infer_instance
instance (K : HomologicalComplex Vᵒᵖ c) (i : ι) [K.HasHomology i] :
((unopFunctor _ _).obj (op K)).HasHomology i := by
dsimp
infer_instance
variable {V c}
@[simp]
lemma quasiIsoAt_opFunctor_map_iff
{K L : HomologicalComplex V c} (φ : K ⟶ L) (i : ι)
[K.HasHomology i] [L.HasHomology i] :
QuasiIsoAt ((opFunctor _ _).map φ.op) i ↔ QuasiIsoAt φ i := by
simp only [quasiIsoAt_iff]
exact ShortComplex.quasiIso_opMap_iff ((shortComplexFunctor V c i).map φ)
@[simp]
lemma quasiIsoAt_unopFunctor_map_iff
{K L : HomologicalComplex Vᵒᵖ c} (φ : K ⟶ L) (i : ι)
[K.HasHomology i] [L.HasHomology i] :
QuasiIsoAt ((unopFunctor _ _).map φ.op) i ↔ QuasiIsoAt φ i := by
rw [← quasiIsoAt_opFunctor_map_iff]
rfl
instance {K L : HomologicalComplex V c} (φ : K ⟶ L) (i : ι)
[K.HasHomology i] [L.HasHomology i] [QuasiIsoAt φ i] :
QuasiIsoAt ((opFunctor _ _).map φ.op) i := by
rw [quasiIsoAt_opFunctor_map_iff]
infer_instance
instance {K L : HomologicalComplex Vᵒᵖ c} (φ : K ⟶ L) (i : ι)
[K.HasHomology i] [L.HasHomology i] [QuasiIsoAt φ i] :
QuasiIsoAt ((unopFunctor _ _).map φ.op) i := by
rw [quasiIsoAt_unopFunctor_map_iff]
infer_instance
@[simp]
lemma quasiIso_opFunctor_map_iff
{K L : HomologicalComplex V c} (φ : K ⟶ L)
[∀ i, K.HasHomology i] [∀ i, L.HasHomology i] :
QuasiIso ((opFunctor _ _).map φ.op) ↔ QuasiIso φ := by
simp only [quasiIso_iff, quasiIsoAt_opFunctor_map_iff]
@[simp]
lemma quasiIso_unopFunctor_map_iff
{K L : HomologicalComplex Vᵒᵖ c} (φ : K ⟶ L)
[∀ i, K.HasHomology i] [∀ i, L.HasHomology i] :
QuasiIso ((unopFunctor _ _).map φ.op) ↔ QuasiIso φ := by
simp only [quasiIso_iff, quasiIsoAt_unopFunctor_map_iff]
instance {K L : HomologicalComplex V c} (φ : K ⟶ L)
[∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [QuasiIso φ] :
QuasiIso ((opFunctor _ _).map φ.op) := by
rw [quasiIso_opFunctor_map_iff]
infer_instance
instance {K L : HomologicalComplex Vᵒᵖ c} (φ : K ⟶ L)
[∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [QuasiIso φ] :
QuasiIso ((unopFunctor _ _).map φ.op) := by
rw [quasiIso_unopFunctor_map_iff]
infer_instance
lemma ExactAt.op {K : HomologicalComplex V c} {i : ι} (h : K.ExactAt i) :
K.op.ExactAt i :=
ShortComplex.Exact.op h
lemma ExactAt.unop {K : HomologicalComplex Vᵒᵖ c} {i : ι} (h : K.ExactAt i) :
K.unop.ExactAt i :=
ShortComplex.Exact.unop h
@[simp]
lemma exactAt_op_iff (K : HomologicalComplex V c) {i : ι} :
K.op.ExactAt i ↔ K.ExactAt i :=
⟨fun h ↦ h.unop, fun h ↦ h.op⟩
lemma Acyclic.op {K : HomologicalComplex V c} (h : K.Acyclic) :
K.op.Acyclic :=
fun i ↦ (h i).op
lemma Acyclic.unop {K : HomologicalComplex Vᵒᵖ c} (h : K.Acyclic) :
K.unop.Acyclic :=
fun i ↦ (h i).unop
@[simp]
lemma acyclic_op_iff (K : HomologicalComplex V c) :
K.op.Acyclic ↔ K.Acyclic :=
⟨fun h ↦ h.unop, fun h ↦ h.op⟩
/-- 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
section
variable (K : HomologicalComplex V c) (i : ι) [K.HasHomology i]
/-- The canonical isomorphism `K.op.cycles i ≅ op (K.opcycles i)`. -/
def cyclesOpIso : K.op.cycles i ≅ op (K.opcycles i) :=
(K.sc i).cyclesOpIso
/-- The canonical isomorphism `K.op.opcycles i ≅ op (K.cycles i)`. -/
def opcyclesOpIso : K.op.opcycles i ≅ op (K.cycles i) :=
(K.sc i).opcyclesOpIso
variable (j : ι)
@[reassoc (attr := simp)]
lemma opcyclesOpIso_hom_toCycles_op :
(K.opcyclesOpIso i).hom ≫ (K.toCycles j i).op = K.op.fromOpcycles i j := by
by_cases hij : c.Rel j i
· obtain rfl := c.prev_eq' hij
exact (K.sc i).opcyclesOpIso_hom_toCycles_op
· rw [K.toCycles_eq_zero hij, K.op.fromOpcycles_eq_zero hij, op_zero, comp_zero]
@[reassoc (attr := simp)]
lemma fromOpcycles_op_cyclesOpIso_inv :
(K.fromOpcycles i j).op ≫ (K.cyclesOpIso i).inv = K.op.toCycles j i := by
by_cases hij : c.Rel i j
· obtain rfl := c.next_eq' hij
exact (K.sc i).fromOpcycles_op_cyclesOpIso_inv
· rw [K.op.toCycles_eq_zero hij, K.fromOpcycles_eq_zero hij, op_zero, zero_comp]
end
section
variable {K L : HomologicalComplex V c} (φ : K ⟶ L) (i : ι)
[K.HasHomology i] [L.HasHomology i]
@[reassoc]
lemma homologyOp_hom_naturality :
homologyMap ((opFunctor _ _).map φ.op) _ ≫ (K.homologyOp i).hom =
(L.homologyOp i).hom ≫ (homologyMap φ i).op :=
ShortComplex.homologyOpIso_hom_naturality ((shortComplexFunctor V c i).map φ)
@[reassoc]
lemma opcyclesOpIso_hom_naturality :
opcyclesMap ((opFunctor _ _).map φ.op) _ ≫ (K.opcyclesOpIso i).hom =
(L.opcyclesOpIso i).hom ≫ (cyclesMap φ i).op :=
ShortComplex.opcyclesOpIso_hom_naturality ((shortComplexFunctor V c i).map φ)
@[reassoc]
lemma opcyclesOpIso_inv_naturality :
(cyclesMap φ i).op ≫ (K.opcyclesOpIso i).inv =
(L.opcyclesOpIso i).inv ≫ opcyclesMap ((opFunctor _ _).map φ.op) _ :=
ShortComplex.opcyclesOpIso_inv_naturality ((shortComplexFunctor V c i).map φ)
@[reassoc]
lemma cyclesOpIso_hom_naturality :
cyclesMap ((opFunctor _ _).map φ.op) _ ≫ (K.cyclesOpIso i).hom =
(L.cyclesOpIso i).hom ≫ (opcyclesMap φ i).op :=
ShortComplex.cyclesOpIso_hom_naturality ((shortComplexFunctor V c i).map φ)
@[reassoc]
lemma cyclesOpIso_inv_naturality :
(opcyclesMap φ i).op ≫ (K.cyclesOpIso i).inv =
(L.cyclesOpIso i).inv ≫ cyclesMap ((opFunctor _ _).map φ.op) _ :=
ShortComplex.cyclesOpIso_inv_naturality ((shortComplexFunctor V c i).map φ)
end
section
variable (V c) [CategoryWithHomology V] (i : ι)
/-- The natural isomorphism `K.op.cycles i ≅ op (K.opcycles i)`. -/
@[simps!]
def cyclesOpNatIso :
opFunctor V c ⋙ cyclesFunctor Vᵒᵖ c.symm i ≅ (opcyclesFunctor V c i).op :=
NatIso.ofComponents (fun K ↦ (unop K).cyclesOpIso i)
(fun _ ↦ cyclesOpIso_hom_naturality _ _)
/-- The natural isomorphism `K.op.opcycles i ≅ op (K.cycles i)`. -/
def opcyclesOpNatIso :
opFunctor V c ⋙ opcyclesFunctor Vᵒᵖ c.symm i ≅ (cyclesFunctor V c i).op :=
NatIso.ofComponents (fun K ↦ (unop K).opcyclesOpIso i)
(fun _ ↦ opcyclesOpIso_hom_naturality _ _)
/-- The natural isomorphism `K.op.homology i ≅ op (K.homology i)`. -/
def homologyOpNatIso :
opFunctor V c ⋙ homologyFunctor Vᵒᵖ c.symm i ≅ (homologyFunctor V c i).op :=
NatIso.ofComponents (fun K ↦ (unop K).homologyOp i)
(fun _ ↦ homologyOp_hom_naturality _ _)
end
end
section
variable [Preadditive V]
instance opFunctor_additive : (@opFunctor ι V _ c _).Additive where
instance unopFunctor_additive : (@unopFunctor ι V _ c _).Additive where
end
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/BifunctorShift.lean | 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`.
-/
assert_not_exists TwoSidedIdeal
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 _ => Iso.refl _) (by
intros
ext
dsimp
simp only [Linear.comp_units_smul, id_comp, Functor.map_units_smul,
NatTrans.app_units_zsmul, comp_id])
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 _ => Iso.refl _)) (by
intros
ext
dsimp
simp only [id_comp, comp_id])
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Augment.lean | 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 simp⟩
-- 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
| _ + 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 _ => 𝟙 _ }
inv :=
{ f := fun _ => 𝟙 _
comm' := fun i j => by
cases j <;> simp }
hom_inv_id := by
ext (_ | i) <;> simp
inv_hom_id := by
ext (_ | i) <;> 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 => 𝟙 _ | _+1 => 𝟙 _
comm' := fun i j => by
match i with
| 0 | 1 | n+2 =>
rcases j with - | j <;> dsimp [augment, truncate] <;> simp
}
inv :=
{ f := fun | 0 => 𝟙 _ | _+1 => 𝟙 _
comm' := fun i j => by
match i with
| 0 | 1 | n+2 =>
rcases j with - | j <;> dsimp [augment, truncate] <;> simp
}
hom_inv_id := by
ext i
cases i <;> simp
inv_hom_id := by
ext i
cases i <;> 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 simp⟩
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
rcases j with (_ | _ | j) <;> cases i <;> try simp
· contradiction
· rw [C.shape]
simp only [ComplexShape.up_Rel] at ⊢ s
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 [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 _ => 𝟙 _ }
inv :=
{ f := fun _ => 𝟙 _
comm' := fun i j => by
cases j <;> simp }
hom_inv_id := by
ext i
cases i <;> simp
inv_hom_id := by
ext i
cases i <;> 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 => 𝟙 _ | _+1 => 𝟙 _
comm' := fun i j => by
rcases j with (_ | _ | j) <;> cases i <;> aesop }
inv :=
{ f := fun | 0 => 𝟙 _ | _+1 => 𝟙 _
comm' := fun i j => by
rcases j with (_ | _ | j) <;> rcases i with - | i <;> aesop }
@[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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/ComplexShape.lean | import Mathlib.Algebra.Group.Defs
import Mathlib.Logic.Relation
import Mathlib.Logic.Function.Basic
/-!
# 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 := rfl
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*} [Add α] [IsRightCancelAdd α] (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*} [Add α] [IsRightCancelAdd α] (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*} [Add α] [IsRightCancelAdd α] (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*) [Add α] [IsRightCancelAdd α] [One α] : ComplexShape α :=
up' 1
/-- The `ComplexShape` appropriate for homology, so `d : X i ⟶ X j` only when `i = j + 1`.
-/
@[simps!]
def down (α : Type*) [Add α] [IsRightCancelAdd α] [One α] : ComplexShape α :=
down' 1
theorem down_mk {α : Type*} [Add α] [IsRightCancelAdd α] [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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Additive.lean | import Mathlib.Algebra.Group.Pi.Basic
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 : HomologicalComplex V c}
variable (f : C ⟶ D) (i : ι)
namespace HomologicalComplex
instance : Zero (C ⟶ D) :=
⟨{ f := fun _ => 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 cat_disch) (by cat_disch) (by cat_disch) (by cat_disch) (by cat_disch) (by cat_disch)
instance : Preadditive (HomologicalComplex V c) where
/-- 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
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 _ => 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 _ => α.app _ }
@[simp]
theorem NatTrans.mapHomologicalComplex_id
(c : ComplexShape ι) (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] :
NatTrans.mapHomologicalComplex (𝟙 F) c = 𝟙 (F.mapHomologicalComplex c) := by cat_disch
@[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
cat_disch
@[reassoc]
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
simp
/-- 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
· 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
· 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/QuasiIso.lean | import Mathlib.Algebra.Homology.Homotopy
import Mathlib.Algebra.Homology.ShortComplex.Retract
import Mathlib.CategoryTheory.MorphismProperty.Composition
/-!
# 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_of_retract {f : K ⟶ L} {f' : K' ⟶ L'}
(h : RetractArrow f f') (i : ι) [K.HasHomology i] [L.HasHomology i]
[K'.HasHomology i] [L'.HasHomology i] [hf' : QuasiIsoAt f' i] :
QuasiIsoAt f i := by
rw [quasiIsoAt_iff] at hf' ⊢
have : RetractArrow ((shortComplexFunctor C c i).map f)
((shortComplexFunctor C c i).map f') := h.map (shortComplexFunctor C c i).mapArrow
exact ShortComplex.quasiIso_of_retract this
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 _ _⟩⟩
lemma exactAt_iff_of_quasiIsoAt (f : K ⟶ L) (i : ι)
[K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] :
K.ExactAt i ↔ L.ExactAt i :=
⟨fun hK => (quasiIsoAt_iff_exactAt f i hK).1 inferInstance,
fun hL => (quasiIsoAt_iff_exactAt' f i hL).1 inferInstance⟩
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
simp [← quasiIso_iff_comp_left (show K' ⟶ K from e.inv.left) φ,
← quasiIso_iff_comp_right φ' (show L' ⟶ L from e.inv.right)]
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]
lemma quasiIso_of_retractArrow {f : K ⟶ L} {f' : K' ⟶ L'}
(h : RetractArrow f f') [∀ i, K.HasHomology i] [∀ i, L.HasHomology i]
[∀ i, K'.HasHomology i] [∀ i, L'.HasHomology i] [QuasiIso f'] :
QuasiIso f where
quasiIsoAt i := quasiIsoAt_of_retract h i
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} [CategoryWithHomology C]
@[simp]
lemma mem_quasiIso_iff (f : K ⟶ L) : quasiIso C c f ↔ QuasiIso f := by rfl
instance : (quasiIso C c).IsMultiplicative where
id_mem _ := by
rw [mem_quasiIso_iff]
infer_instance
comp_mem _ _ hf hg := by
rw [mem_quasiIso_iff] at hf hg ⊢
infer_instance
instance : (quasiIso C c).HasTwoOutOfThreeProperty where
of_postcomp f g hg hfg := by
rw [mem_quasiIso_iff] at hg hfg ⊢
rwa [← quasiIso_iff_comp_right f g]
of_precomp f g hf hfg := by
rw [mem_quasiIso_iff] at hf hfg ⊢
rwa [← quasiIso_iff_comp_left f g]
instance : (quasiIso C c).IsStableUnderRetracts where
of_retract h hg := by
rw [mem_quasiIso_iff] at hg ⊢
exact quasiIso_of_retractArrow h
instance : (quasiIso C c).RespectsIso :=
MorphismProperty.respectsIso_of_isStableUnderComposition
(fun _ _ _ (_ : IsIso _) ↦ by rw [mem_quasiIso_iff]; infer_instance)
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Monoidal.lean | import Mathlib.Algebra.Homology.BifunctorAssociator
import Mathlib.Algebra.Homology.Single
import Mathlib.CategoryTheory.GradedObject.Monoidal
import Mathlib.CategoryTheory.Monoidal.Transport
/-!
# The monoidal category structure on homological complexes
Let `c : ComplexShape I` with `I` an additive monoid. If `c` is equipped
with the data and axioms `c.TensorSigns`, then the category
`HomologicalComplex C c` can be equipped with a monoidal category
structure if `C` is a monoidal category such that `C` has certain
coproducts and both left/right tensoring commute with these.
In particular, we obtain a monoidal category structure on
`ChainComplex C ℕ` when `C` is an additive monoidal category.
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Limits MonoidalCategory Category
namespace HomologicalComplex
variable {C : Type*} [Category C] [MonoidalCategory C] [Preadditive C] [HasZeroObject C]
[(curriedTensor C).Additive] [∀ (X₁ : C), ((curriedTensor C).obj X₁).Additive]
{I : Type*} [AddMonoid I] {c : ComplexShape I} [c.TensorSigns]
/-- If `K₁` and `K₂` are two homological complexes, this is the property that
for all `j`, the coproduct of `K₁ i₁ ⊗ K₂ i₂` for `i₁ + i₂ = j` exists. -/
abbrev HasTensor (K₁ K₂ : HomologicalComplex C c) := HasMapBifunctor K₁ K₂ (curriedTensor C) c
section
variable [DecidableEq I]
/-- The tensor product of two homological complexes. -/
noncomputable abbrev tensorObj (K₁ K₂ : HomologicalComplex C c) [HasTensor K₁ K₂] :
HomologicalComplex C c :=
mapBifunctor K₁ K₂ (curriedTensor C) c
/-- The inclusion `K₁.X i₁ ⊗ K₂.X i₂ ⟶ (tensorObj K₁ K₂).X j` of a summand in
the tensor product of the homological complexes. -/
noncomputable abbrev ιTensorObj (K₁ K₂ : HomologicalComplex C c) [HasTensor K₁ K₂]
(i₁ i₂ j : I) (h : i₁ + i₂ = j) :
K₁.X i₁ ⊗ K₂.X i₂ ⟶ (tensorObj K₁ K₂).X j :=
ιMapBifunctor K₁ K₂ (curriedTensor C) c i₁ i₂ j h
/-- The tensor product of two morphisms of homological complexes. -/
noncomputable abbrev tensorHom {K₁ K₂ L₁ L₂ : HomologicalComplex C c}
(f : K₁ ⟶ L₁) (g : K₂ ⟶ L₂) [HasTensor K₁ K₂] [HasTensor L₁ L₂] :
tensorObj K₁ K₂ ⟶ tensorObj L₁ L₂ :=
mapBifunctorMap f g _ _
/-- Given three homological complexes `K₁`, `K₂`, and `K₃`, this asserts that for
all `j`, the functor `- ⊗ K₃.X i₃` commutes with the coproduct of
the `K₁.X i₁ ⊗ K₂.X i₂` such that `i₁ + i₂ = j`. -/
abbrev HasGoodTensor₁₂ (K₁ K₂ K₃ : HomologicalComplex C c) :=
HasGoodTrifunctor₁₂Obj (curriedTensor C) (curriedTensor C) K₁ K₂ K₃ c c
/-- Given three homological complexes `K₁`, `K₂`, and `K₃`, this asserts that for
all `j`, the functor `K₁.X i₁` commutes with the coproduct of
the `K₂.X i₂ ⊗ K₃.X i₃` such that `i₂ + i₃ = j`. -/
abbrev HasGoodTensor₂₃ (K₁ K₂ K₃ : HomologicalComplex C c) :=
HasGoodTrifunctor₂₃Obj (curriedTensor C) (curriedTensor C) K₁ K₂ K₃ c c c
/-- The associator isomorphism for the tensor product of homological complexes. -/
noncomputable abbrev associator (K₁ K₂ K₃ : HomologicalComplex C c)
[HasTensor K₁ K₂] [HasTensor K₂ K₃]
[HasTensor (tensorObj K₁ K₂) K₃] [HasTensor K₁ (tensorObj K₂ K₃)]
[HasGoodTensor₁₂ K₁ K₂ K₃] [HasGoodTensor₂₃ K₁ K₂ K₃] :
tensorObj (tensorObj K₁ K₂) K₃ ≅ tensorObj K₁ (tensorObj K₂ K₃) :=
mapBifunctorAssociator (curriedAssociatorNatIso C) K₁ K₂ K₃ c c c
variable (C c) in
/-- The unit of the tensor product of homological complexes. -/
noncomputable abbrev tensorUnit : HomologicalComplex C c := (single C c 0).obj (𝟙_ C)
variable (C c) in
/-- As a graded object, the single complex `(single C c 0).obj (𝟙_ C)` identifies
to the unit `(GradedObject.single₀ I).obj (𝟙_ C)` of the tensor product of graded objects. -/
noncomputable def tensorUnitIso :
(GradedObject.single₀ I).obj (𝟙_ C) ≅ (tensorUnit C c).X :=
GradedObject.isoMk _ _ (fun i ↦
if hi : i = 0 then
(GradedObject.singleObjApplyIsoOfEq (0 : I) (𝟙_ C) i hi).trans
(singleObjXIsoOfEq c 0 (𝟙_ C) i hi).symm
else
{ hom := 0
inv := 0
hom_inv_id := (GradedObject.isInitialSingleObjApply 0 (𝟙_ C) i hi).hom_ext _ _
inv_hom_id := (isZero_single_obj_X c 0 (𝟙_ C) i hi).eq_of_src _ _ })
end
instance (K₁ K₂ : HomologicalComplex C c) [GradedObject.HasTensor K₁.X K₂.X] :
HasTensor K₁ K₂ := by
assumption
instance (K₁ K₂ K₃ : HomologicalComplex C c)
[GradedObject.HasGoodTensor₁₂Tensor K₁.X K₂.X K₃.X] :
HasGoodTensor₁₂ K₁ K₂ K₃ :=
inferInstanceAs (GradedObject.HasGoodTensor₁₂Tensor K₁.X K₂.X K₃.X)
instance (K₁ K₂ K₃ : HomologicalComplex C c)
[GradedObject.HasGoodTensorTensor₂₃ K₁.X K₂.X K₃.X] :
HasGoodTensor₂₃ K₁ K₂ K₃ :=
inferInstanceAs (GradedObject.HasGoodTensorTensor₂₃ K₁.X K₂.X K₃.X)
section
variable (K : HomologicalComplex C c) [DecidableEq I]
section
variable [∀ X₂, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).flip.obj X₂)]
instance : GradedObject.HasTensor (tensorUnit C c).X K.X :=
GradedObject.hasTensor_of_iso (tensorUnitIso C c) (Iso.refl _)
instance : HasTensor (tensorUnit C c) K :=
inferInstanceAs (GradedObject.HasTensor (tensorUnit C c).X K.X)
@[simp]
lemma unit_tensor_d₁ (i₁ i₂ j : I) :
mapBifunctor.d₁ (tensorUnit C c) K (curriedTensor C) c i₁ i₂ j = 0 := by
by_cases h₁ : c.Rel i₁ (c.next i₁)
· by_cases h₂ : ComplexShape.π c c c (c.next i₁, i₂) = j
· rw [mapBifunctor.d₁_eq _ _ _ _ h₁ _ _ h₂, single_obj_d, Functor.map_zero,
zero_app, zero_comp, smul_zero]
· rw [mapBifunctor.d₁_eq_zero' _ _ _ _ h₁ _ _ h₂]
· rw [mapBifunctor.d₁_eq_zero _ _ _ _ _ _ _ h₁]
end
section
variable [∀ X₁, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).obj X₁)]
instance : GradedObject.HasTensor K.X (tensorUnit C c).X :=
GradedObject.hasTensor_of_iso (Iso.refl _) (tensorUnitIso C c)
instance : HasTensor K (tensorUnit C c) :=
inferInstanceAs (GradedObject.HasTensor K.X (tensorUnit C c).X)
@[simp]
lemma tensor_unit_d₂ (i₁ i₂ j : I) :
mapBifunctor.d₂ K (tensorUnit C c) (curriedTensor C) c i₁ i₂ j = 0 := by
by_cases h₁ : c.Rel i₂ (c.next i₂)
· by_cases h₂ : ComplexShape.π c c c (i₁, c.next i₂) = j
· rw [mapBifunctor.d₂_eq _ _ _ _ _ h₁ _ h₂, single_obj_d, Functor.map_zero,
zero_comp, smul_zero]
· rw [mapBifunctor.d₂_eq_zero' _ _ _ _ _ h₁ _ h₂]
· rw [mapBifunctor.d₂_eq_zero _ _ _ _ _ _ _ h₁]
end
end
section Unitor
variable (K : HomologicalComplex C c) [DecidableEq I]
section LeftUnitor
variable [∀ X₂, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).flip.obj X₂)]
/-- Auxiliary definition for `leftUnitor`. -/
noncomputable def leftUnitor' :
(tensorObj (tensorUnit C c) K).X ≅ K.X :=
GradedObject.Monoidal.tensorIso ((tensorUnitIso C c).symm) (Iso.refl _) ≪≫
GradedObject.Monoidal.leftUnitor K.X
lemma leftUnitor'_inv (i : I) :
(leftUnitor' K).inv i = (λ_ (K.X i)).inv ≫ ((singleObjXSelf c 0 (𝟙_ C)).inv ▷ (K.X i)) ≫
ιTensorObj (tensorUnit C c) K 0 i i (zero_add i) := by
dsimp [leftUnitor']
rw [GradedObject.Monoidal.leftUnitor_inv_apply, assoc, assoc, Iso.cancel_iso_inv_left,
GradedObject.Monoidal.ι_tensorHom]
dsimp
rw [tensorHom_id, ← comp_whiskerRight_assoc]
congr 2
rw [← cancel_epi (GradedObject.Monoidal.tensorUnit₀ (I := I)).hom, Iso.hom_inv_id_assoc]
dsimp [tensorUnitIso]
rw [dif_pos rfl]
rfl
@[reassoc]
lemma leftUnitor'_inv_comm (i j : I) :
(leftUnitor' K).inv i ≫ (tensorObj (tensorUnit C c) K).d i j =
K.d i j ≫ (leftUnitor' K).inv j := by
by_cases hij : c.Rel i j
· simp only [leftUnitor'_inv, assoc, mapBifunctor.d_eq,
Preadditive.comp_add, mapBifunctor.ι_D₁, mapBifunctor.ι_D₂,
unit_tensor_d₁, comp_zero, zero_add]
rw [mapBifunctor.d₂_eq _ _ _ _ _ hij _ (by simp)]
dsimp
simp only [ComplexShape.ε_zero, one_smul, ← whisker_exchange_assoc,
id_whiskerLeft, assoc, Iso.inv_hom_id_assoc]
· simp only [shape _ _ _ hij, comp_zero, zero_comp]
/-- The left unitor for the tensor product of homological complexes. -/
noncomputable def leftUnitor :
tensorObj (tensorUnit C c) K ≅ K :=
Iso.symm (Hom.isoOfComponents (fun i ↦ (GradedObject.eval i).mapIso (leftUnitor' K).symm)
(fun _ _ _ ↦ leftUnitor'_inv_comm _ _ _))
end LeftUnitor
section RightUnitor
variable [∀ X₁, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).obj X₁)]
/-- Auxiliary definition for `rightUnitor`. -/
noncomputable def rightUnitor' :
(tensorObj K (tensorUnit C c)).X ≅ K.X :=
GradedObject.Monoidal.tensorIso (Iso.refl _) ((tensorUnitIso C c).symm) ≪≫
GradedObject.Monoidal.rightUnitor K.X
lemma rightUnitor'_inv (i : I) :
(rightUnitor' K).inv i = (ρ_ (K.X i)).inv ≫ ((K.X i) ◁ (singleObjXSelf c 0 (𝟙_ C)).inv) ≫
ιTensorObj K (tensorUnit C c) i 0 i (add_zero i) := by
dsimp [rightUnitor']
rw [GradedObject.Monoidal.rightUnitor_inv_apply, assoc, assoc, Iso.cancel_iso_inv_left,
GradedObject.Monoidal.ι_tensorHom]
dsimp
rw [id_tensorHom, ← whiskerLeft_comp_assoc]
congr 2
rw [← cancel_epi (GradedObject.Monoidal.tensorUnit₀ (I := I)).hom, Iso.hom_inv_id_assoc]
dsimp [tensorUnitIso]
rw [dif_pos rfl]
rfl
lemma rightUnitor'_inv_comm (i j : I) :
(rightUnitor' K).inv i ≫ (tensorObj K (tensorUnit C c)).d i j =
K.d i j ≫ (rightUnitor' K).inv j := by
by_cases hij : c.Rel i j
· simp only [rightUnitor'_inv, assoc, mapBifunctor.d_eq,
Preadditive.comp_add, mapBifunctor.ι_D₁, mapBifunctor.ι_D₂,
tensor_unit_d₂, comp_zero, add_zero]
rw [mapBifunctor.d₁_eq _ _ _ _ hij _ _ (by simp)]
dsimp
simp only [one_smul, whisker_exchange_assoc, whiskerRight_id, assoc, Iso.inv_hom_id_assoc]
· simp only [shape _ _ _ hij, comp_zero, zero_comp]
/-- The right unitor for the tensor product of homological complexes. -/
noncomputable def rightUnitor :
tensorObj K (tensorUnit C c) ≅ K :=
Iso.symm (Hom.isoOfComponents (fun i ↦ (GradedObject.eval i).mapIso (rightUnitor' K).symm)
(fun _ _ _ ↦ rightUnitor'_inv_comm _ _ _))
end RightUnitor
end Unitor
variable (C c) [∀ (X₁ X₂ : GradedObject I C), GradedObject.HasTensor X₁ X₂]
[∀ X₁, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).obj X₁)]
[∀ X₂, PreservesColimit (Functor.empty.{0} C) ((curriedTensor C).flip.obj X₂)]
[∀ (X₁ X₂ X₃ X₄ : GradedObject I C), GradedObject.HasTensor₄ObjExt X₁ X₂ X₃ X₄]
[∀ (X₁ X₂ X₃ : GradedObject I C), GradedObject.HasGoodTensor₁₂Tensor X₁ X₂ X₃]
[∀ (X₁ X₂ X₃ : GradedObject I C), GradedObject.HasGoodTensorTensor₂₃ X₁ X₂ X₃]
[DecidableEq I]
noncomputable instance monoidalCategoryStruct :
MonoidalCategoryStruct (HomologicalComplex C c) where
tensorObj K₁ K₂ := tensorObj K₁ K₂
whiskerLeft _ _ _ g := tensorHom (𝟙 _) g
whiskerRight f _ := tensorHom f (𝟙 _)
tensorHom f g := tensorHom f g
tensorUnit := tensorUnit C c
associator K₁ K₂ K₃ := associator K₁ K₂ K₃
leftUnitor K := leftUnitor K
rightUnitor K := rightUnitor K
/-- The structure which allows to construct the monoidal category structure
on `HomologicalComplex C c` from the monoidal category structure on
graded objects. -/
noncomputable def Monoidal.inducingFunctorData :
Monoidal.InducingFunctorData (forget C c) where
μIso _ _ := Iso.refl _
εIso := tensorUnitIso C c
whiskerLeft_eq K₁ K₂ L₂ g := by
dsimp [forget]
rw [comp_id]
erw [id_comp]
rfl
whiskerRight_eq {K₁ L₁} f K₂ := by
dsimp [forget]
rw [comp_id]
erw [id_comp]
rfl
tensorHom_eq {K₁ L₁ K₂ L₂} f g := by
dsimp [forget]
rw [comp_id]
erw [id_comp]
rfl
associator_eq K₁ K₂ K₃ := by
dsimp [forget]
simp only [tensorHom_id, whiskerRight_tensor, id_whiskerRight,
id_comp, Iso.inv_hom_id, comp_id, assoc]
erw [id_whiskerRight]
rw [id_comp]
erw [id_comp]
rfl
leftUnitor_eq K := by
dsimp
erw [id_comp]
rfl
rightUnitor_eq K := by
dsimp
rw [assoc]
erw [id_comp]
rfl
noncomputable instance monoidalCategory : MonoidalCategory (HomologicalComplex C c) :=
Monoidal.induced _ (Monoidal.inducingFunctorData C c)
noncomputable example {D : Type*} [Category D] [Preadditive D] [MonoidalCategory D]
[HasZeroObject D] [HasFiniteCoproducts D] [((curriedTensor D).Additive)]
[∀ (X : D), (((curriedTensor D).obj X).Additive)]
[∀ (X : D), PreservesFiniteCoproducts ((curriedTensor D).obj X)]
[∀ (X : D), PreservesFiniteCoproducts ((curriedTensor D).flip.obj X)] :
MonoidalCategory (ChainComplex D ℕ) := inferInstance
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomologicalComplex.lean | 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 cat_disch
d_comp_d' : ∀ i j k, c.Rel i j → c.Rel j k → d i j ≫ d j k = 0 := by cat_disch
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 cat_disch
@[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 _ => 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
@[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 cat_disch
instance (X Y : HomologicalComplex V c) : Zero (X ⟶ Y) :=
⟨{ f := fun _ => 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 _ => 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
/-- 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`.
-/
@[simp]
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]
/-- 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`.
-/
@[simp]
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
theorem dTo_eq_zero {j : ι} (h : ¬c.Rel (c.prev j) j) : C.dTo j = 0 := by
simp [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
theorem dFrom_eq_zero {i : ι} (h : ¬c.Rel i (c.next i)) : C.dFrom i = 0 := by
simp [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]
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]
theorem dFrom_comp_xNextIsoSelf {i : ι} (h : ¬c.Rel i (c.next i)) :
C.dFrom i ≫ (C.xNextIsoSelf h).hom = 0 := by simp [h]
-- This is not a simp lemma; the LHS already simplifies.
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 cat_disch) :
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]
theorem comm_from (f : Hom C₁ C₂) (i : ι) : f.f i ≫ C₂.dFrom i = C₁.dFrom i ≫ f.next i :=
f.comm _ _
attribute [simp] comm_from_apply
@[reassoc, elementwise]
theorem comm_to (f : Hom C₁ C₂) (j : ι) : f.prev j ≫ C₂.dTo j = C₁.dTo j ≫ f.f j :=
f.comm _ _
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
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]
lemma mk_congr_succ_X₃ {S S' : ShortComplex V} (h : S = S') :
(succ S).1 = (succ S').1 := by rw [h]
lemma mk_congr_succ_d₂ {S S' : ShortComplex V} (h : S = S') :
(succ S).2.1 = eqToHom (by subst h; rfl) ≫ (succ S').2.1 ≫ eqToHom (by subst h; rfl) := by
subst h
simp
lemma mkAux_eq_shortComplex_mk_d_comp_d (n : ℕ) :
mkAux X₀ X₁ X₂ d₀ d₁ s succ n =
ShortComplex.mk _ _ ((mk X₀ X₁ X₂ d₀ d₁ s succ).d_comp_d (n + 2) (n + 1) n) := by
change ShortComplex.mk _ _ (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).zero = _
dsimp [mk, of, mkAux]
congr
· rw [if_pos (by rfl), id_comp]
· simp
/-- The isomorphism from `(mk X₀ X₁ X₂ d₀ d₁ s succ).X (n + 3)` that is given by
the inductive construction. -/
def mkXIso (n : ℕ) :
(mk X₀ X₁ X₂ d₀ d₁ s succ).X (n + 3) ≅
(succ (ShortComplex.mk _ _ ((mk X₀ X₁ X₂ d₀ d₁ s succ).d_comp_d (n + 2) (n + 1) n))).1 :=
eqToIso (by
rw [← mk_congr_succ_X₃ succ
(mkAux_eq_shortComplex_mk_d_comp_d X₀ X₁ X₂ d₀ d₁ s succ n)]
rfl)
lemma mk_d (n : ℕ) :
(mk X₀ X₁ X₂ d₀ d₁ s succ).d (n + 3) (n + 2) =
(mkXIso X₀ X₁ X₂ d₀ d₁ s succ n).hom ≫ (succ
(ShortComplex.mk _ _ ((mk X₀ X₁ X₂ d₀ d₁ s succ).d_comp_d (n + 2) (n + 1) n))).2.1 := by
have eq := mk_congr_succ_d₂ succ
(mkAux_eq_shortComplex_mk_d_comp_d X₀ X₁ X₂ d₀ d₁ s succ n)
rw [eqToHom_refl, comp_id] at eq
refine Eq.trans ?_ eq
dsimp only [mk, of]
rw [dif_pos (by rfl), eqToHom_refl, id_comp]
rfl
/-- 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]
/-- The isomorphism from `(mk' X₀ X₁ d₀ succ').X (n + 2)` that is given by
the inductive construction. -/
def mk'XIso (n : ℕ) :
(mk' X₀ X₁ d₀ succ').X (n + 2) ≅ (succ' ((mk' X₀ X₁ d₀ succ').d (n + 1) n)).1 := by
obtain _|n := n
· apply eqToIso
dsimp [mk', mk, of, mkAux]
rw [id_comp]
· exact mkXIso _ _ _ _ _ (succ' d₀).2.2 (fun S => succ' S.f) n
lemma mk'_congr_succ'_d {X Y : V} (f g : X ⟶ Y) (h : f = g) :
(succ' f).2.1 = eqToHom (by rw [h]) ≫ (succ' g).2.1 := by
subst h
simp
lemma mk'_d (n : ℕ) :
(mk' X₀ X₁ d₀ succ').d (n + 2) (n + 1) = (mk'XIso X₀ X₁ d₀ succ' n).hom ≫
(succ' ((mk' X₀ X₁ d₀ succ').d (n + 1) n)).2.1 := by
obtain _|n := n
· dsimp [mk'XIso, mk']
rw [mk_d_2_1]
apply mk'_congr_succ'_d
rw [mk_d_1_0]
· apply mk_d
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
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/LocalCohomology.lean | import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Category.ModuleCat.Projective
import Mathlib.CategoryTheory.Abelian.Ext
import Mathlib.CategoryTheory.Limits.Final
import Mathlib.RingTheory.Finiteness.Ideal
import Mathlib.RingTheory.Ideal.Basic
import Mathlib.RingTheory.Ideal.Quotient.Defs
import Mathlib.RingTheory.Noetherian.Defs
/-!
# 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 := ModuleCat.ofHom <| Submodule.mapQ _ _ LinearMap.id (I.map w).down.down
/-- 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) := inferInstance
/-
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 : ℕ) : ModuleCat.{max u v} R ⥤ ModuleCat.{max 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 :=
ObjectProperty.FullSubcategory fun J' : Ideal R => J ≤ J'.radical
deriving 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 :=
ObjectProperty.ι _
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 :=
ObjectProperty.lift _ (idealPowersDiagram J) fun k => by
change _ ≤ (J ^ unop k).radical
rcases unop k with - | n
· simp [Ideal.radical_top, pow_zero, Ideal.one_eq_top, le_top]
· simp only [J.radical_pow n.succ_ne_zero, Ideal.le_radical]
variable {I J K : Ideal R}
/-- 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 rfl⟩
· left; exact ⟨CostructuredArrow.homMk (homOfLE h).op rfl⟩
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 :=
ObjectProperty.ιOfLE 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomologicalComplexAbelian.lean | 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 : IsNormalEpiCategory (HomologicalComplex C c) := ⟨fun p _ =>
⟨NormalEpi.mk _ (kernel.ι p) (kernel.condition _)
(isColimitOfEval _ _ (fun _ =>
Abelian.isColimitMapCoconeOfCokernelCoforkOfπ _ _))⟩⟩
noncomputable instance : IsNormalMonoCategory (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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/BifunctorFlip.lean | import Mathlib.Algebra.Homology.Bifunctor
import Mathlib.Algebra.Homology.TotalComplexSymmetry
/-!
# Action of the flip of a bifunctor on homological complexes
Given `K₁ : HomologicalComplex C₁ c₁`, `K₂ : HomologicalComplex C₂ c₂`,
a bifunctor `F : C₁ ⥤ C₂ ⥤ D`, and a complex shape `c` with
`[TotalComplexShape c₁ c₂ c]` and `[TotalComplexShape c₂ c₁ c]`, we define
an isomorphism `mapBifunctor K₂ K₁ F.flip c ≅ mapBifunctor K₁ K₂ F c`
under the additional assumption `[TotalComplexShapeSymmetry c₁ c₂ c]`.
-/
open CategoryTheory Limits
variable {C₁ C₂ D : Type*} [Category C₁] [Category C₂] [Category D]
namespace HomologicalComplex
variable {I₁ I₂ J : Type*} {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂}
[HasZeroMorphisms C₁] [HasZeroMorphisms C₂] [Preadditive D]
(K₁ : HomologicalComplex C₁ c₁) (K₂ : HomologicalComplex C₂ c₂)
(F : C₁ ⥤ C₂ ⥤ D) [F.PreservesZeroMorphisms] [∀ X₁, (F.obj X₁).PreservesZeroMorphisms]
(c : ComplexShape J) [TotalComplexShape c₁ c₂ c] [TotalComplexShape c₂ c₁ c]
[TotalComplexShapeSymmetry c₁ c₂ c]
lemma hasMapBifunctor_flip_iff :
HasMapBifunctor K₂ K₁ F.flip c ↔ HasMapBifunctor K₁ K₂ F c :=
(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).flip_hasTotal_iff c
variable [DecidableEq J] [HasMapBifunctor K₁ K₂ F c]
instance : HasMapBifunctor K₂ K₁ F.flip c := by
rw [hasMapBifunctor_flip_iff]
infer_instance
/-- The canonical isomorphism `mapBifunctor K₂ K₁ F.flip c ≅ mapBifunctor K₁ K₂ F c`. -/
noncomputable def mapBifunctorFlipIso :
mapBifunctor K₂ K₁ F.flip c ≅ mapBifunctor K₁ K₂ F c :=
(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).totalFlipIso c
lemma mapBifunctorFlipIso_flip
[TotalComplexShapeSymmetry c₂ c₁ c] [TotalComplexShapeSymmetrySymmetry c₁ c₂ c] :
mapBifunctorFlipIso K₂ K₁ F.flip c = (mapBifunctorFlipIso K₁ K₂ F c).symm :=
(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).flip_totalFlipIso c
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/ImageToKernel.lean | 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] HasForget.instFunLike
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem imageToKernel_arrow (w : f ≫ g = 0) :
imageToKernel f g w ≫ (kernelSubobject g).arrow = (imageSubobject f).arrow := by
simp [imageToKernel]
-- 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
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]
infer_instance
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomologicalBicomplex.lean | 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 _ _ 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 _ => Iso.refl _)
(by simp)) (by cat_disch)) (by cat_disch)
/-- 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 _ => Iso.refl _)
(by simp)) (by cat_disch)) (by cat_disch)
/-- 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₂ |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Linear.lean | 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.lean`)
-/
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 cat_disch
smul_zero := by cat_disch
smul_add := by cat_disch
zero_smul := by cat_disch
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/BifunctorHomotopy.lean | 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).
-/
assert_not_exists TwoSidedIdeal
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? [HomologicalComplex₂.total_d, h₁.comm i₁, dFrom, fromNext, toPrev, dTo] says
simp only [ι_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, Functor.mapBifunctorHomologicalComplex_obj_obj_X_X,
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Bifunctor.lean | 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₂)`.
-/
assert_not_exists TwoSidedIdeal
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₂ F c}
variable {A : D} {j : J}
(f : ∀ (i₁ : I₁) (i₂ : I₂) (_ : ComplexShape.π c₁ c₂ c ⟨i₁, i₂⟩ = j),
(F.obj (K₁.X i₁)).obj (K₂.X i₂) ⟶ A)
/-- Constructor for morphisms from `(mapBifunctor K₁ K₂ F c).X j`. -/
noncomputable def mapBifunctorDesc : (mapBifunctor K₁ K₂ F c).X j ⟶ A :=
HomologicalComplex₂.totalDesc _ f
@[reassoc (attr := simp)]
lemma ι_mapBifunctorDesc (i₁ : I₁) (i₂ : I₂) (h : ComplexShape.π c₁ c₂ c ⟨i₁, i₂⟩ = j) :
ιMapBifunctor K₁ K₂ F c i₁ i₂ j h ≫ mapBifunctorDesc f = f i₁ i₂ h := by
apply HomologicalComplex₂.ι_totalDesc
end
namespace mapBifunctor
variable {K₁ K₂ F c} in
@[ext]
lemma hom_ext {Y : D} {j : J} {f g : (mapBifunctor K₁ K₂ F c).X j ⟶ Y}
(h : ∀ (i₁ : I₁) (i₂ : I₂) (h : ComplexShape.π c₁ c₂ c ⟨i₁, i₂⟩ = j),
ιMapBifunctor K₁ K₂ F c i₁ i₂ j h ≫ f = ιMapBifunctor K₁ K₂ F c i₁ i₂ j h ≫ g) :
f = g :=
HomologicalComplex₂.total.hom_ext _ h
section
variable (j j' : J)
/-- The first differential on `mapBifunctor K₁ K₂ F c` -/
noncomputable def D₁ :
(mapBifunctor K₁ K₂ F c).X j ⟶ (mapBifunctor K₁ K₂ F c).X j' :=
(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).D₁ c j j'
/-- The second differential on `mapBifunctor K₁ K₂ F c` -/
noncomputable def D₂ :
(mapBifunctor K₁ K₂ F c).X j ⟶ (mapBifunctor K₁ K₂ F c).X j' :=
(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).D₂ c j j'
lemma d_eq :
(mapBifunctor K₁ K₂ F c).d j j' = D₁ K₁ K₂ F c j j' + D₂ K₁ K₂ F c j j' := rfl
end
section
variable (i₁ : I₁) (i₂ : I₂) (j : J)
/-- The first differential on a summand of `mapBifunctor K₁ K₂ F c` -/
noncomputable def d₁ :
(F.obj (K₁.X i₁)).obj (K₂.X i₂) ⟶ (mapBifunctor K₁ K₂ F c).X j :=
(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).d₁ c i₁ i₂ j
/-- The second differential on a summand of `mapBifunctor K₁ K₂ F c` -/
noncomputable def d₂ :
(F.obj (K₁.X i₁)).obj (K₂.X i₂) ⟶ (mapBifunctor K₁ K₂ F c).X j :=
(((F.mapBifunctorHomologicalComplex c₁ c₂).obj K₁).obj K₂).d₂ c i₁ i₂ j
lemma d₁_eq_zero (h : ¬ c₁.Rel i₁ (c₁.next i₁)) :
d₁ K₁ K₂ F c i₁ i₂ j = 0 :=
HomologicalComplex₂.d₁_eq_zero _ _ _ _ _ h
lemma d₂_eq_zero (h : ¬ c₂.Rel i₂ (c₂.next i₂)) :
d₂ K₁ K₂ F c i₁ i₂ j = 0 :=
HomologicalComplex₂.d₂_eq_zero _ _ _ _ _ h
lemma d₁_eq_zero' {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (j : J)
(h' : ComplexShape.π c₁ c₂ c ⟨i₁', i₂⟩ ≠ j) :
d₁ K₁ K₂ F c i₁ i₂ j = 0 :=
HomologicalComplex₂.d₁_eq_zero' _ _ h _ _ h'
lemma d₂_eq_zero' (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (j : J)
(h' : ComplexShape.π c₁ c₂ c ⟨i₁, i₂'⟩ ≠ j) :
d₂ K₁ K₂ F c i₁ i₂ j = 0 :=
HomologicalComplex₂.d₂_eq_zero' _ _ _ h _ h'
lemma d₁_eq' {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (j : J) :
d₁ K₁ K₂ F c i₁ i₂ j = ComplexShape.ε₁ c₁ c₂ c ⟨i₁, i₂⟩ •
((F.map (K₁.d i₁ i₁')).app (K₂.X i₂) ≫ ιMapBifunctorOrZero K₁ K₂ F c i₁' i₂ j) :=
HomologicalComplex₂.d₁_eq' _ _ h _ _
lemma d₂_eq' (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (j : J) :
d₂ K₁ K₂ F c i₁ i₂ j = ComplexShape.ε₂ c₁ c₂ c ⟨i₁, i₂⟩ •
((F.obj (K₁.X i₁)).map (K₂.d i₂ i₂') ≫ ιMapBifunctorOrZero K₁ K₂ F c i₁ i₂' j) :=
HomologicalComplex₂.d₂_eq' _ _ _ h _
lemma d₁_eq {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (j : J)
(h' : ComplexShape.π c₁ c₂ c ⟨i₁', i₂⟩ = j) :
d₁ K₁ K₂ F c i₁ i₂ j = ComplexShape.ε₁ c₁ c₂ c ⟨i₁, i₂⟩ •
((F.map (K₁.d i₁ i₁')).app (K₂.X i₂) ≫ ιMapBifunctor K₁ K₂ F c i₁' i₂ j h') :=
HomologicalComplex₂.d₁_eq _ _ h _ _ h'
lemma d₂_eq (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (j : J)
(h' : ComplexShape.π c₁ c₂ c ⟨i₁, i₂'⟩ = j) :
d₂ K₁ K₂ F c i₁ i₂ j = ComplexShape.ε₂ c₁ c₂ c ⟨i₁, i₂⟩ •
((F.obj (K₁.X i₁)).map (K₂.d i₂ i₂') ≫ ιMapBifunctor K₁ K₂ F c i₁ i₂' j h') :=
HomologicalComplex₂.d₂_eq _ _ _ h _ h'
end
section
variable (j j' : J) (i₁ : I₁) (i₂ : I₂) (h : ComplexShape.π c₁ c₂ c (i₁, i₂) = j)
@[reassoc (attr := simp)]
lemma ι_D₁ :
ιMapBifunctor K₁ K₂ F c i₁ i₂ j h ≫ D₁ K₁ K₂ F c j j' = d₁ K₁ K₂ F c i₁ i₂ j' := by
apply HomologicalComplex₂.ι_D₁
@[reassoc (attr := simp)]
lemma ι_D₂ :
ιMapBifunctor K₁ K₂ F c i₁ i₂ j h ≫ D₂ K₁ K₂ F c j j' = d₂ K₁ K₂ F c i₁ i₂ j' := by
apply HomologicalComplex₂.ι_D₂
end
end mapBifunctor
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Single.lean | 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 _ _ => 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 /-- nightly-2024-03-07
previously was `rw [if_neg h]; simp`, but that fails with "motive not type correct"
This is because dsimp does not simplify numerals;
this note should be removable once https://github.com/leanprover/lean4/pull/8433 lands. -/
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]
rw [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 cat_disch
right_inv f := by simp
@[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 cat_disch
right_inv := by cat_disch
@[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]
rw [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 cat_disch
right_inv := by cat_disch
@[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 cat_disch
right_inv := by cat_disch
@[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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomologicalComplexBiprod.lean | 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 hasLimit_of_iso 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 hasColimit_of_iso e
instance : HasBinaryBiproduct K L := HasBinaryBiproduct.of_hasBinaryProduct _ _
instance (i : ι) : PreservesBinaryBiproduct K L (eval C c i) :=
preservesBinaryBiproduct_of_preservesBinaryProduct _
/-- 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HasNoLoop.lean | import Mathlib.Algebra.Homology.ComplexShape
import Mathlib.Algebra.Group.Int.Defs
import Mathlib.Algebra.Group.Nat.Defs
/-!
# Complex shapes with no loop
Let `c : ComplexShape ι`. We define a type class `c.HasNoLoop`
which expresses that `¬ c.Rel i i` for all `i : ι`.
-/
namespace ComplexShape
variable {ι : Type*}
/-- The condition that `c.Rel i i` does not hold for any `i`. -/
class HasNoLoop (c : ComplexShape ι) : Prop where
not_rel_self (i : ι) : ¬ c.Rel i i
section
variable (c : ComplexShape ι) [c.HasNoLoop] (j : ι)
lemma not_rel_self : ¬ c.Rel j j :=
HasNoLoop.not_rel_self j
variable {j} in
lemma not_rel_of_eq {j' : ι} (h : j = j') : ¬ c.Rel j j' := by
subst h
exact c.not_rel_self j
instance : c.symm.HasNoLoop where
not_rel_self j := c.not_rel_self j
lemma exists_distinct_prev_or :
(∃ (k : ι), c.Rel j k ∧ j ≠ k) ∨ ∀ (k : ι), ¬ c.Rel j k := by
by_cases h : ∃ (k : ι), c.Rel j k
· obtain ⟨k, hk⟩ := h
exact Or.inl ⟨k, hk, fun hjk ↦ c.not_rel_of_eq hjk hk⟩
· exact Or.inr (by simpa using h)
lemma exists_distinct_next_or :
(∃ (i : ι), c.Rel i j ∧ i ≠ j) ∨ ∀ (i : ι), ¬ c.Rel i j := by
by_cases h : ∃ (i : ι), c.Rel i j
· obtain ⟨i, hi⟩ := h
exact Or.inl ⟨i, hi, fun hij ↦ c.not_rel_of_eq hij hi⟩
· exact Or.inr (by simpa using h)
lemma hasNoLoop_up' {α : Type*} [AddZeroClass α] [IsRightCancelAdd α] [IsLeftCancelAdd α]
(a : α) (ha : a ≠ 0) :
(up' a).HasNoLoop where
not_rel_self i (hi : _ = _) :=
ha (add_left_cancel (by rw [add_zero, hi]))
lemma hasNoLoop_down' {α : Type*} [AddZeroClass α] [IsRightCancelAdd α] [IsLeftCancelAdd α]
(a : α) (ha : a ≠ 0) :
(down' a).HasNoLoop := by
have := hasNoLoop_up' a ha
exact inferInstanceAs (up' a).symm.HasNoLoop
lemma hasNoLoop_up {α : Type*} [AddZeroClass α] [IsRightCancelAdd α] [IsLeftCancelAdd α]
[One α] (ha : (1 : α) ≠ 0) :
(up α).HasNoLoop :=
hasNoLoop_up' _ ha
lemma hasNoLoop_down {α : Type*} [AddZeroClass α] [IsRightCancelAdd α] [IsLeftCancelAdd α]
[One α] (ha : (1 : α) ≠ 0) :
(down α).HasNoLoop :=
hasNoLoop_down' _ ha
end
instance : (up ℤ).HasNoLoop := hasNoLoop_up (by simp)
instance : (up ℕ).HasNoLoop := hasNoLoop_up (by simp)
instance : (down ℤ).HasNoLoop := hasNoLoop_down (by simp)
instance : (down ℕ).HasNoLoop := hasNoLoop_down (by simp)
end ComplexShape |
.lake/packages/mathlib/Mathlib/Algebra/Homology/TotalComplex.lean | import Mathlib.CategoryTheory.Linear.Basic
import Mathlib.Algebra.Homology.ComplexShapeSigns
import Mathlib.Algebra.Homology.HomologicalBicomplex
import Mathlib.Algebra.Module.Basic
/-!
# 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)`.
-/
assert_not_exists TwoSidedIdeal
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₁₂) [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₁₂)
include e in
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 [DecidableEq I₁₂] [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 -isSimp 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
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
cat_disch
@[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
cat_disch
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₂ |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Square.lean | import Mathlib.Algebra.Homology.CommSq
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Square
/-!
# Relation between pullback/pushout squares and kernel/cokernel sequences
This file is the bundled counterpart of `Algebra.Homology.CommSq`.
The same results are obtained here for squares `sq : Square C` where
`C` is an additive category.
-/
namespace CategoryTheory
open Category Limits
namespace Square
variable {C : Type*} [Category C] [Preadditive C]
(sq : Square C) [HasBinaryBiproduct sq.X₂ sq.X₃]
/-- The cokernel cofork attached to a commutative square in a preadditive category. -/
noncomputable abbrev cokernelCofork :
CokernelCofork (biprod.lift sq.f₁₂ (-sq.f₁₃)) :=
CokernelCofork.ofπ (biprod.desc sq.f₂₄ sq.f₃₄) (by simp [sq.fac])
/-- 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 isPushoutEquivIsColimitCokernelCofork :
sq.IsPushout ≃ IsColimit sq.cokernelCofork :=
Equiv.trans
{ toFun := fun h ↦ h.isColimit
invFun := fun h ↦ IsPushout.mk _ h
right_inv := fun _ ↦ Subsingleton.elim _ _ }
sq.commSq.isColimitEquivIsColimitCokernelCofork
variable {sq} in
/-- The colimit cokernel cofork attached to a pushout square. -/
noncomputable def IsPushout.isColimitCokernelCofork (h : sq.IsPushout) :
IsColimit sq.cokernelCofork :=
h.isColimitEquivIsColimitCokernelCofork h.isColimit
/-- The kernel fork attached to a commutative square in a preadditive category. -/
noncomputable abbrev kernelFork :
KernelFork (biprod.desc sq.f₂₄ (-sq.f₃₄)) :=
KernelFork.ofι (biprod.lift sq.f₁₂ sq.f₁₃) (by simp [sq.fac])
/-- 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 isPullbackEquivIsLimitKernelFork :
sq.IsPullback ≃ IsLimit sq.kernelFork :=
Equiv.trans
{ toFun := fun h ↦ h.isLimit
invFun := fun h ↦ IsPullback.mk _ h
right_inv := fun _ ↦ Subsingleton.elim _ _ }
sq.commSq.isLimitEquivIsLimitKernelFork
variable {sq} in
/-- The limit kernel fork attached to a pullback square. -/
noncomputable def IsPullback.isLimitKernelFork (h : sq.IsPullback) :
IsLimit sq.kernelFork :=
h.isLimitEquivIsLimitKernelFork h.isLimit
end Square
end CategoryTheory |
.lake/packages/mathlib/Mathlib/Algebra/Homology/BifunctorAssociator.lean | import Mathlib.CategoryTheory.GradedObject.Associator
import Mathlib.CategoryTheory.Linear.LinearFunctor
import Mathlib.Algebra.Homology.Bifunctor
/-!
# The associator for actions of bifunctors on homological complexes
In this file, we shall adapt the results of the file
`CategoryTheory.GradedObject.Associator` to the case of homological complexes.
Given functors `F₁₂ : C₁ ⥤ C₂ ⥤ C₁₂`, `G : C₁₂ ⥤ C₃ ⥤ C₄`,
`F : C₁ ⥤ C₂₃ ⥤ C₄`, `G₂₃ : C₂ ⥤ C₃ ⥤ C₂₃` equipped with an isomorphism
`associator : bifunctorComp₁₂ F₁₂ G ≅ bifunctorComp₂₃ F G₂₃` (which informally means
that we have natural isomorphisms `G(F₁₂(X₁, X₂), X₃) ≅ F(X₁, G₂₃(X₂, X₃))`),
we define an isomorphism `mapBifunctorAssociator` from
`mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄` to
`mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄` when
we have three homological complexes `K₁ : HomologicalComplex C₁ c₁`,
`K₂ : HomologicalComplex C₂ c₂` and `K₃ : HomologicalComplex C₃ c₃`,
assumptions `TotalComplexShape c₁ c₂ c₁₂`, `TotalComplexShape c₁₂ c₃ c₄`,
`TotalComplexShape c₂ c₃ c₂₃`, `TotalComplexShape c₁ c₂₃ c₄`,
and `ComplexShape.Associative c₁ c₂ c₃ c₁₂ c₂₃ c₄` about the complex
shapes, and technical assumptions
`[HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄]` and
`[HasGoodTrifunctor₂₃Obj F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄]` about the
commutation of certain functors to certain coproducts.
The main application of these results shall be the construction of
the associator for the monoidal category structure on homological complexes.
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Category Limits
namespace HomologicalComplex
variable {C₁ C₂ C₁₂ C₂₃ C₃ C₄ : Type*}
[Category C₁] [Category C₂] [Category C₃] [Category C₄] [Category C₁₂] [Category C₂₃]
[HasZeroMorphisms C₁] [HasZeroMorphisms C₂] [HasZeroMorphisms C₃]
[Preadditive C₁₂] [Preadditive C₂₃] [Preadditive C₄]
{F₁₂ : C₁ ⥤ C₂ ⥤ C₁₂} {G : C₁₂ ⥤ C₃ ⥤ C₄}
{F : C₁ ⥤ C₂₃ ⥤ C₄} {G₂₃ : C₂ ⥤ C₃ ⥤ C₂₃}
[F₁₂.PreservesZeroMorphisms] [∀ (X₁ : C₁), (F₁₂.obj X₁).PreservesZeroMorphisms]
[G.Additive] [∀ (X₁₂ : C₁₂), (G.obj X₁₂).PreservesZeroMorphisms]
[G₂₃.PreservesZeroMorphisms] [∀ (X₂ : C₂), (G₂₃.obj X₂).PreservesZeroMorphisms]
[F.PreservesZeroMorphisms] [∀ (X₁ : C₁), (F.obj X₁).Additive]
(associator : bifunctorComp₁₂ F₁₂ G ≅ bifunctorComp₂₃ F G₂₃)
{ι₁ ι₂ ι₃ ι₁₂ ι₂₃ ι₄ : Type*} [DecidableEq ι₄]
{c₁ : ComplexShape ι₁} {c₂ : ComplexShape ι₂} {c₃ : ComplexShape ι₃}
(K₁ : HomologicalComplex C₁ c₁) (K₂ : HomologicalComplex C₂ c₂)
(K₃ : HomologicalComplex C₃ c₃)
(c₁₂ : ComplexShape ι₁₂) (c₂₃ : ComplexShape ι₂₃) (c₄ : ComplexShape ι₄)
[TotalComplexShape c₁ c₂ c₁₂] [TotalComplexShape c₁₂ c₃ c₄]
[TotalComplexShape c₂ c₃ c₂₃] [TotalComplexShape c₁ c₂₃ c₄]
[HasMapBifunctor K₁ K₂ F₁₂ c₁₂] [HasMapBifunctor K₂ K₃ G₂₃ c₂₃]
[ComplexShape.Associative c₁ c₂ c₃ c₁₂ c₂₃ c₄]
variable (F₁₂ G) in
/-- Given bifunctors `F₁₂ : C₁ ⥤ C₂ ⥤ C₁₂`, `G : C₁₂ ⥤ C₃ ⥤ C₄`, homological complexes
`K₁ : HomologicalComplex C₁ c₁`, `K₂ : HomologicalComplex C₂ c₂` and
`K₃ : HomologicalComplex C₃ c₃`, and complexes shapes `c₁₂`, `c₄`, this asserts
that for all `i₁₂ : ι₁₂` and `i₃ : ι₃`, the functor `G(-, K₃.X i₃)` commutes with
the coproducts of the `F₁₂(X₁ i₁, X₂ i₂)` such that `π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = i₁₂`. -/
abbrev HasGoodTrifunctor₁₂Obj :=
GradedObject.HasGoodTrifunctor₁₂Obj F₁₂ G
(ComplexShape.ρ₁₂ c₁ c₂ c₃ c₁₂ c₄) K₁.X K₂.X K₃.X
variable (F G₂₃) in
/-- Given bifunctors `F : C₁ ⥤ C₂₃ ⥤ C₄`, `G₂₃ : C₂ ⥤ C₃ ⥤ C₂₃`, homological complexes
`K₁ : HomologicalComplex C₁ c₁`, `K₂ : HomologicalComplex C₂ c₂` and
`K₃ : HomologicalComplex C₃ c₃`, and complexes shapes `c₁₂`, `c₂₃`, `c₄`
with `ComplexShape.Associative c₁ c₂ c₃ c₁₂ c₂₃ c₄`, this asserts that for
all `i₁ : ι₁` and `i₂₃ : ι₂₃`, the functor `F(K₁.X i₁, _)` commutes with
the coproducts of the `G₂₃(K₂.X i₂, K₃.X i₃)`
such that `π c₂ c₃ c₂₃ ⟨i₂, i₃⟩ = i₂₃`. -/
abbrev HasGoodTrifunctor₂₃Obj :=
GradedObject.HasGoodTrifunctor₂₃Obj F G₂₃
(ComplexShape.ρ₂₃ c₁ c₂ c₃ c₁₂ c₂₃ c₄) K₁.X K₂.X K₃.X
instance :
(((GradedObject.mapBifunctor F₁₂ ι₁ ι₂).obj K₁.X).obj K₂.X).HasMap
(ComplexShape.π c₁ c₂ c₁₂) :=
inferInstanceAs (HasMapBifunctor K₁ K₂ F₁₂ c₁₂)
section
variable [DecidableEq ι₁₂] [DecidableEq ι₂₃]
[HasMapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄]
[HasMapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄]
instance :
(((GradedObject.mapBifunctor G ι₁₂ ι₃).obj (GradedObject.mapBifunctorMapObj F₁₂
(ComplexShape.π c₁ c₂ c₁₂) K₁.X K₂.X)).obj K₃.X).HasMap
(ComplexShape.π c₁₂ c₃ c₄) :=
inferInstanceAs (HasMapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄)
instance :
(((GradedObject.mapBifunctor F ι₁ ι₂₃).obj K₁.X).obj
(GradedObject.mapBifunctorMapObj G₂₃
(ComplexShape.π c₂ c₃ c₂₃) K₂.X K₃.X)).HasMap (ComplexShape.π c₁ c₂₃ c₄) :=
inferInstanceAs (HasMapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄)
/-- The associator isomorphism for the action of bifunctors
on homological complexes, in each degree. -/
noncomputable def mapBifunctorAssociatorX
[H₁₂ : HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄]
[H₂₃ : HasGoodTrifunctor₂₃Obj F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄] (j : ι₄) :
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j ≅
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j :=
(GradedObject.eval j).mapIso
(GradedObject.mapBifunctorAssociator (associator := associator)
(H₁₂ := H₁₂) (H₂₃ := H₂₃))
end
namespace mapBifunctor₁₂
variable [DecidableEq ι₁₂] [HasMapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄]
section
variable (F₁₂ G)
/-- The inclusion of a summand in `mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄`. -/
noncomputable def ι (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j) :
(G.obj ((F₁₂.obj (K₁.X i₁)).obj (K₂.X i₂))).obj (K₃.X i₃) ⟶
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j :=
GradedObject.ιMapBifunctor₁₂BifunctorMapObj _ _ (ComplexShape.ρ₁₂ c₁ c₂ c₃ c₁₂ c₄) _ _ _ _ _ _ _ h
lemma ι_eq (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (i₁₂ : ι₁₂) (j : ι₄)
(h₁₂ : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = i₁₂)
(h : ComplexShape.π c₁₂ c₃ c₄ (i₁₂, i₃) = j) :
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j (by rw [← h, ← h₁₂]; rfl) =
(G.map (ιMapBifunctor K₁ K₂ F₁₂ c₁₂ i₁ i₂ i₁₂ h₁₂)).app (K₃.X i₃) ≫
ιMapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄ i₁₂ i₃ j h := by
subst h₁₂
rfl
/-- The inclusion of a summand in `mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄`,
or zero. -/
noncomputable def ιOrZero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
(G.obj ((F₁₂.obj (K₁.X i₁)).obj (K₂.X i₂))).obj (K₃.X i₃) ⟶
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j :=
if h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j then
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h
else 0
lemma ιOrZero_eq (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j) :
ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j =
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h := dif_pos h
lemma ιOrZero_eq_zero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) ≠ j) :
ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j = 0 := dif_neg h
variable {F₁₂ G K₁ K₂ K₃ c₁₂ c₄} in
@[ext]
lemma hom_ext
[HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄] {j : ι₄} {A : C₄}
{f g : (mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j ⟶ A}
(hfg : ∀ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j),
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h ≫ f =
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h ≫ g) :
f = g :=
GradedObject.mapBifunctor₁₂BifunctorMapObj_ext hfg
end
section
variable {K₁ K₂ K₃ c₁₂ c₄}
variable [HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄] {j : ι₄} {A : C₄}
(f : ∀ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (_ : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j),
(G.obj ((F₁₂.obj (K₁.X i₁)).obj (K₂.X i₂))).obj (K₃.X i₃) ⟶ A)
/-- Constructor for morphisms from
`(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j`. -/
noncomputable def mapBifunctor₁₂Desc :
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j ⟶ A :=
GradedObject.mapBifunctor₁₂BifunctorDesc (ρ₁₂ := ComplexShape.ρ₁₂ c₁ c₂ c₃ c₁₂ c₄) f
@[reassoc (attr := simp)]
lemma ι_mapBifunctor₁₂Desc (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j) :
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h ≫ mapBifunctor₁₂Desc f =
f i₁ i₂ i₃ h := by
apply GradedObject.ι_mapBifunctor₁₂BifunctorDesc
end
variable (F₁₂ G)
/-- The first differential on a summand
of `mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄`. -/
noncomputable def d₁ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
(G.obj ((F₁₂.obj (K₁.X i₁)).obj (K₂.X i₂))).obj (K₃.X i₃) ⟶
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j :=
(ComplexShape.ε₁ c₁₂ c₃ c₄ (ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩, i₃) *
ComplexShape.ε₁ c₁ c₂ c₁₂ (i₁, i₂)) •
(G.map ((F₁₂.map (K₁.d i₁ (c₁.next i₁))).app (K₂.X i₂))).app (K₃.X i₃) ≫
ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ _ i₂ i₃ j
lemma d₁_eq_zero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) (h : ¬ c₁.Rel i₁ (c₁.next i₁)) :
d₁ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j = 0 := by
dsimp [d₁]
rw [shape _ _ _ h, Functor.map_zero, zero_app, Functor.map_zero, zero_app, zero_comp, smul_zero]
lemma d₁_eq {i₁ i₁' : ι₁} (h₁ : c₁.Rel i₁ i₁') (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
d₁ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j =
(ComplexShape.ε₁ c₁₂ c₃ c₄ (ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩, i₃) *
ComplexShape.ε₁ c₁ c₂ c₁₂ (i₁, i₂) ) •
(G.map ((F₁₂.map (K₁.d i₁ i₁')).app (K₂.X i₂))).app (K₃.X i₃) ≫
ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁' i₂ i₃ j := by
obtain rfl := c₁.next_eq' h₁
rfl
/-- The second differential on a summand
of `mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄`. -/
noncomputable def d₂ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
(G.obj ((F₁₂.obj (K₁.X i₁)).obj (K₂.X i₂))).obj (K₃.X i₃) ⟶
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j :=
(c₁₂.ε₁ c₃ c₄ (ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩, i₃) * c₁.ε₂ c₂ c₁₂ (i₁, i₂)) •
(G.map ((F₁₂.obj (K₁.X i₁)).map (K₂.d i₂ (c₂.next i₂)))).app (K₃.X i₃) ≫
ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ _ i₃ j
lemma d₂_eq_zero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) (h : ¬ c₂.Rel i₂ (c₂.next i₂)) :
d₂ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j = 0 := by
dsimp [d₂]
rw [shape _ _ _ h, Functor.map_zero, Functor.map_zero, zero_app, zero_comp, smul_zero]
lemma d₂_eq (i₁ : ι₁) {i₂ i₂' : ι₂} (h₂ : c₂.Rel i₂ i₂') (i₃ : ι₃) (j : ι₄) :
d₂ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j =
(c₁₂.ε₁ c₃ c₄ (ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩, i₃) * c₁.ε₂ c₂ c₁₂ (i₁, i₂)) •
(G.map ((F₁₂.obj (K₁.X i₁)).map (K₂.d i₂ i₂'))).app (K₃.X i₃) ≫
ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ _ i₃ j := by
obtain rfl := c₂.next_eq' h₂
rfl
/-- The third differential on a summand
of `mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄`. -/
noncomputable def d₃ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
(G.obj ((F₁₂.obj (K₁.X i₁)).obj (K₂.X i₂))).obj (K₃.X i₃) ⟶
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j :=
(ComplexShape.ε₂ c₁₂ c₃ c₄ (c₁.π c₂ c₁₂ (i₁, i₂), i₃)) •
(G.obj ((F₁₂.obj (K₁.X i₁)).obj (K₂.X i₂))).map (K₃.d i₃ (c₃.next i₃)) ≫
ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ _ j
lemma d₃_eq_zero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) (h : ¬ c₃.Rel i₃ (c₃.next i₃)) :
d₃ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j = 0 := by
dsimp [d₃]
rw [shape _ _ _ h, Functor.map_zero, zero_comp, smul_zero]
lemma d₃_eq (i₁ : ι₁) (i₂ : ι₂) {i₃ i₃' : ι₃} (h₃ : c₃.Rel i₃ i₃') (j : ι₄) :
d₃ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j =
(ComplexShape.ε₂ c₁₂ c₃ c₄ (c₁.π c₂ c₁₂ (i₁, i₂), i₃)) •
(G.obj ((F₁₂.obj (K₁.X i₁)).obj (K₂.X i₂))).map (K₃.d i₃ i₃') ≫
ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ _ j := by
obtain rfl := c₃.next_eq' h₃
rfl
section
variable [HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄]
variable (j j' : ι₄)
/-- The first differential on `mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄`. -/
noncomputable def D₁ :
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j ⟶
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j' :=
mapBifunctor₁₂Desc (fun i₁ i₂ i₃ _ ↦ d₁ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j')
/-- The second differential on `mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄`. -/
noncomputable def D₂ :
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j ⟶
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j' :=
mapBifunctor₁₂Desc (fun i₁ i₂ i₃ _ ↦ d₂ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j')
/-- The third differential on `mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄`. -/
noncomputable def D₃ :
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j ⟶
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).X j' :=
mapBifunctor.D₂ _ _ _ _ _ _
end
section
variable (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j j' : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j)
@[reassoc (attr := simp)]
lemma ι_D₁ [HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄] :
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h ≫ D₁ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' =
d₁ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j' := by
simp [D₁]
@[reassoc (attr := simp)]
lemma ι_D₂ [HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄] :
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h ≫ D₂ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' =
d₂ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j' := by
simp [D₂]
@[reassoc (attr := simp)]
lemma ι_D₃ :
ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h ≫ D₃ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' =
d₃ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j' := by
simp only [ι_eq _ _ _ _ _ _ _ _ _ _ _ _ rfl h, D₃, assoc, mapBifunctor.ι_D₂]
by_cases h₁ : c₃.Rel i₃ (c₃.next i₃)
· rw [d₃_eq _ _ _ _ _ _ _ _ _ h₁]
by_cases h₂ : ComplexShape.π c₁₂ c₃ c₄ (c₁.π c₂ c₁₂ (i₁, i₂), c₃.next i₃) = j'
· rw [mapBifunctor.d₂_eq _ _ _ _ _ h₁ _ h₂,
ιOrZero_eq _ _ _ _ _ _ _ _ _ _ _ h₂,
Linear.comp_units_smul, smul_left_cancel_iff,
ι_eq _ _ _ _ _ _ _ _ _ _ _ _ rfl h₂,
NatTrans.naturality_assoc]
· rw [mapBifunctor.d₂_eq_zero' _ _ _ _ _ h₁ _ h₂, comp_zero,
ιOrZero_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₂, comp_zero, smul_zero]
· rw [mapBifunctor.d₂_eq_zero _ _ _ _ _ _ _ h₁, comp_zero,
d₃_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₁]
end
lemma d_eq (j j' : ι₄) [HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄] :
(mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄).d j j' =
D₁ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' + D₂ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' +
D₃ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' := by
rw [mapBifunctor.d_eq]
congr 1
ext i₁ i₂ i₃ h
simp only [Preadditive.comp_add, ι_D₁, ι_D₂]
rw [ι_eq _ _ _ _ _ _ _ _ _ _ _ _ rfl h, assoc, mapBifunctor.ι_D₁]
set i₁₂ := ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩
by_cases h₁ : c₁₂.Rel i₁₂ (c₁₂.next i₁₂)
· by_cases h₂ : ComplexShape.π c₁₂ c₃ c₄ (c₁₂.next i₁₂, i₃) = j'
· rw [mapBifunctor.d₁_eq _ _ _ _ h₁ _ _ h₂]
simp only [i₁₂, mapBifunctor.d_eq, Functor.map_add, NatTrans.app_add,
Preadditive.add_comp, smul_add, Preadditive.comp_add, Linear.comp_units_smul]
congr 1
· rw [← NatTrans.comp_app_assoc, ← Functor.map_comp,
mapBifunctor.ι_D₁]
by_cases h₃ : c₁.Rel i₁ (c₁.next i₁)
· have h₄ := (ComplexShape.next_π₁ c₂ c₁₂ h₃ i₂).symm
rw [mapBifunctor.d₁_eq _ _ _ _ h₃ _ _ h₄,
d₁_eq _ _ _ _ _ _ _ h₃,
ιOrZero_eq _ _ _ _ _ _ _ _ _ _ _ (by rw [← h₂, ← h₄]; rfl),
ι_eq _ _ _ _ _ _ _ _ _ _ (c₁₂.next i₁₂) _ h₄ h₂,
Functor.map_units_smul, Functor.map_comp, NatTrans.app_units_zsmul,
NatTrans.comp_app, Linear.units_smul_comp, assoc, smul_smul]
· rw [d₁_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₃,
mapBifunctor.d₁_eq_zero _ _ _ _ _ _ _ h₃,
Functor.map_zero, zero_app, zero_comp, smul_zero]
· rw [← NatTrans.comp_app_assoc, ← Functor.map_comp,
mapBifunctor.ι_D₂]
by_cases h₃ : c₂.Rel i₂ (c₂.next i₂)
· have h₄ := (ComplexShape.next_π₂ c₁ c₁₂ i₁ h₃).symm
rw [mapBifunctor.d₂_eq _ _ _ _ _ h₃ _ h₄,
d₂_eq _ _ _ _ _ _ _ _ h₃,
ιOrZero_eq _ _ _ _ _ _ _ _ _ _ _ (by rw [← h₂, ← h₄]; rfl),
ι_eq _ _ _ _ _ _ _ _ _ _ (c₁₂.next i₁₂) _ h₄ h₂,
Functor.map_units_smul, Functor.map_comp, NatTrans.app_units_zsmul,
NatTrans.comp_app, Linear.units_smul_comp, assoc, smul_smul]
· rw [d₂_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₃,
mapBifunctor.d₂_eq_zero _ _ _ _ _ _ _ h₃,
Functor.map_zero, zero_app, zero_comp, smul_zero]
· rw [mapBifunctor.d₁_eq_zero' _ _ _ _ h₁ _ _ h₂, comp_zero]
trans 0 + 0
· simp
· congr 1
· by_cases h₃ : c₁.Rel i₁ (c₁.next i₁)
· rw [d₁_eq _ _ _ _ _ _ _ h₃, ιOrZero_eq_zero, comp_zero, smul_zero]
dsimp [ComplexShape.r]
intro h₄
apply h₂
rw [← h₄, ComplexShape.next_π₁ c₂ c₁₂ h₃ i₂]
· rw [d₁_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₃]
· by_cases h₃ : c₂.Rel i₂ (c₂.next i₂)
· rw [d₂_eq _ _ _ _ _ _ _ _ h₃, ιOrZero_eq_zero, comp_zero, smul_zero]
dsimp [ComplexShape.r]
intro h₄
apply h₂
rw [← h₄, ComplexShape.next_π₂ c₁ c₁₂ i₁ h₃]
· rw [d₂_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₃]
· rw [mapBifunctor.d₁_eq_zero _ _ _ _ _ _ _ h₁, comp_zero,
d₁_eq_zero, d₂_eq_zero, zero_add]
· intro h₂
apply h₁
have := ComplexShape.rel_π₂ c₁ c₁₂ i₁ h₂
rw [c₁₂.next_eq' this]
exact this
· intro h₂
apply h₁
have := ComplexShape.rel_π₁ c₂ c₁₂ h₂ i₂
rw [c₁₂.next_eq' this]
exact this
end mapBifunctor₁₂
namespace mapBifunctor₂₃
variable [DecidableEq ι₂₃] [HasMapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄]
section
variable (F G₂₃)
/-- The inclusion of a summand in `mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄`. -/
noncomputable def ι (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j) :
(F.obj (K₁.X i₁)).obj ((G₂₃.obj (K₂.X i₂)).obj (K₃.X i₃)) ⟶
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j :=
GradedObject.ιMapBifunctorBifunctor₂₃MapObj _ _ (ComplexShape.ρ₂₃ c₁ c₂ c₃ c₁₂ c₂₃ c₄)
_ _ _ _ _ _ _ h
lemma ι_eq (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (i₂₃ : ι₂₃) (j : ι₄)
(h₂₃ : ComplexShape.π c₂ c₃ c₂₃ ⟨i₂, i₃⟩ = i₂₃)
(h : ComplexShape.π c₁ c₂₃ c₄ (i₁, i₂₃) = j) :
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j
(by rw [← h, ← h₂₃, ← ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄]; rfl) =
(F.obj (K₁.X i₁)).map (ιMapBifunctor K₂ K₃ G₂₃ c₂₃ i₂ i₃ i₂₃ h₂₃) ≫
ιMapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄ i₁ i₂₃ j h := by
subst h₂₃
rfl
/-- The inclusion of a summand in `mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄`,
or zero. -/
noncomputable def ιOrZero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
(F.obj (K₁.X i₁)).obj ((G₂₃.obj (K₂.X i₂)).obj (K₃.X i₃)) ⟶
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j :=
if h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j then
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h
else 0
lemma ιOrZero_eq (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j) :
ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j =
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h := dif_pos h
lemma ιOrZero_eq_zero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) ≠ j) :
ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j = 0 := dif_neg h
variable [HasGoodTrifunctor₂₃Obj F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄]
-- this is not an ext lemma because Lean cannot guess `c₁₂`
variable {F G₂₃ K₁ K₂ K₃ c₂₃ c₄} in
lemma hom_ext {j : ι₄} {A : C₄}
{f g : (mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j ⟶ A}
(hfg : ∀ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j),
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h ≫ f =
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h ≫ g) :
f = g :=
GradedObject.mapBifunctorBifunctor₂₃MapObj_ext
(ρ₂₃ := ComplexShape.ρ₂₃ c₁ c₂ c₃ c₁₂ c₂₃ c₄) hfg
variable {F G₂₃ K₁ K₂ K₃ c₂₃ c₄}
variable {j : ι₄} {A : C₄}
(f : ∀ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (_ : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j),
(F.obj (K₁.X i₁)).obj ((G₂₃.obj (K₂.X i₂)).obj (K₃.X i₃)) ⟶ A)
/-- Constructor for morphisms from
`(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j`. -/
noncomputable def mapBifunctor₂₃Desc :
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j ⟶ A :=
GradedObject.mapBifunctorBifunctor₂₃Desc (ρ₂₃ := ComplexShape.ρ₂₃ c₁ c₂ c₃ c₁₂ c₂₃ c₄) f
@[reassoc (attr := simp)]
lemma ι_mapBifunctor₂₃Desc (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j) :
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h ≫ mapBifunctor₂₃Desc c₁₂ f =
f i₁ i₂ i₃ h := by
apply GradedObject.ι_mapBifunctorBifunctor₂₃Desc
end
variable (F G₂₃)
/-- The first differential on a summand
of `mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄`. -/
noncomputable def d₁ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
(F.obj (K₁.X i₁)).obj ((G₂₃.obj (K₂.X i₂)).obj (K₃.X i₃)) ⟶
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j :=
(ComplexShape.ε₁ c₁ c₂₃ c₄ (i₁, ComplexShape.π c₂ c₃ c₂₃ (i₂, i₃))) •
((F.map (K₁.d i₁ (c₁.next i₁)))).app ((G₂₃.obj (K₂.X i₂)).obj (K₃.X i₃)) ≫
ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ _ i₂ i₃ j
lemma d₁_eq_zero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) (h : ¬ c₁.Rel i₁ (c₁.next i₁)) :
d₁ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j = 0 := by
dsimp [d₁]
rw [shape _ _ _ h, Functor.map_zero, zero_app, zero_comp, smul_zero]
lemma d₁_eq {i₁ i₁' : ι₁} (h₁ : c₁.Rel i₁ i₁') (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
d₁ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j =
(ComplexShape.ε₁ c₁ c₂₃ c₄ (i₁, ComplexShape.π c₂ c₃ c₂₃ (i₂, i₃))) •
((F.map (K₁.d i₁ i₁'))).app ((G₂₃.obj (K₂.X i₂)).obj (K₃.X i₃)) ≫
ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ _ i₂ i₃ j := by
obtain rfl := c₁.next_eq' h₁
rfl
/-- The second differential on a summand
of `mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄`. -/
noncomputable def d₂ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
(F.obj (K₁.X i₁)).obj ((G₂₃.obj (K₂.X i₂)).obj (K₃.X i₃)) ⟶
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j :=
(ComplexShape.ε₂ c₁ c₂₃ c₄ (i₁, c₂.π c₃ c₂₃ (i₂, i₃)) * ComplexShape.ε₁ c₂ c₃ c₂₃ (i₂, i₃)) •
(F.obj (K₁.X i₁)).map ((G₂₃.map (K₂.d i₂ (c₂.next i₂))).app (K₃.X i₃)) ≫
ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ _ i₃ j
lemma d₂_eq_zero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) (h : ¬ c₂.Rel i₂ (c₂.next i₂)) :
d₂ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j = 0 := by
dsimp [d₂]
rw [shape _ _ _ h, Functor.map_zero, zero_app, Functor.map_zero, zero_comp, smul_zero]
lemma d₂_eq (i₁ : ι₁) {i₂ i₂' : ι₂} (h₂ : c₂.Rel i₂ i₂') (i₃ : ι₃) (j : ι₄) :
d₂ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j =
(ComplexShape.ε₂ c₁ c₂₃ c₄ (i₁, c₂.π c₃ c₂₃ (i₂, i₃)) * ComplexShape.ε₁ c₂ c₃ c₂₃ (i₂, i₃)) •
(F.obj (K₁.X i₁)).map ((G₂₃.map (K₂.d i₂ i₂')).app (K₃.X i₃)) ≫
ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ _ i₃ j := by
obtain rfl := c₂.next_eq' h₂
rfl
/-- The third differential on a summand
of `mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄`. -/
noncomputable def d₃ (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
(F.obj (K₁.X i₁)).obj ((G₂₃.obj (K₂.X i₂)).obj (K₃.X i₃)) ⟶
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j :=
((ComplexShape.ε₂ c₁ c₂₃ c₄ (i₁, ComplexShape.π c₂ c₃ c₂₃ (i₂, i₃)) *
ComplexShape.ε₂ c₂ c₃ c₂₃ (i₂, i₃))) •
(F.obj (K₁.X i₁)).map ((G₂₃.obj (K₂.X i₂)).map (K₃.d i₃ (c₃.next i₃))) ≫
ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ _ j
lemma d₃_eq_zero (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) (h : ¬ c₃.Rel i₃ (c₃.next i₃)) :
d₃ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j = 0 := by
dsimp [d₃]
rw [shape _ _ _ h, Functor.map_zero, Functor.map_zero, zero_comp, smul_zero]
lemma d₃_eq (i₁ : ι₁) (i₂ : ι₂) {i₃ i₃' : ι₃} (h₃ : c₃.Rel i₃ i₃') (j : ι₄) :
d₃ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j =
((ComplexShape.ε₂ c₁ c₂₃ c₄ (i₁, ComplexShape.π c₂ c₃ c₂₃ (i₂, i₃)) *
ComplexShape.ε₂ c₂ c₃ c₂₃ (i₂, i₃))) •
(F.obj (K₁.X i₁)).map ((G₂₃.obj (K₂.X i₂)).map (K₃.d i₃ i₃')) ≫
ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ _ j := by
obtain rfl := c₃.next_eq' h₃
rfl
section
variable (j j' : ι₄)
/-- The first differential on `mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄`. -/
noncomputable def D₁ :
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j ⟶
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j' :=
mapBifunctor.D₁ _ _ _ _ _ _
variable [HasGoodTrifunctor₂₃Obj F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄]
/-- The second differential on `mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄`. -/
noncomputable def D₂ :
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j ⟶
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j' :=
mapBifunctor₂₃Desc c₁₂ (fun i₁ i₂ i₃ _ ↦ d₂ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j')
/-- The third differential on `mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄`. -/
noncomputable def D₃ :
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j ⟶
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).X j' :=
mapBifunctor₂₃Desc c₁₂ (fun i₁ i₂ i₃ _ ↦ d₃ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j')
end
section
variable (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j j' : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j)
@[reassoc (attr := simp)]
lemma ι_D₁ :
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h ≫ D₁ F G₂₃ K₁ K₂ K₃ c₂₃ c₄ j j' =
d₁ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j' := by
dsimp only [D₁]
rw [ι_eq _ _ _ _ _ _ _ _ _ _ _ _ _ rfl
(by rw [← h, ← ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄]; rfl),
assoc, mapBifunctor.ι_D₁]
by_cases h₁ : c₁.Rel i₁ (c₁.next i₁)
· rw [d₁_eq _ _ _ _ _ _ _ _ h₁]
by_cases h₂ : ComplexShape.π c₁ c₂₃ c₄ (c₁.next i₁, ComplexShape.π c₂ c₃ c₂₃ (i₂, i₃)) = j'
· rw [mapBifunctor.d₁_eq _ _ _ _ h₁ _ _ h₂, ιOrZero_eq,
Linear.comp_units_smul, NatTrans.naturality_assoc]
· rfl
· rw [← h₂, ← ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄]
rfl
· rw [mapBifunctor.d₁_eq_zero' _ _ _ _ h₁ _ _ h₂, comp_zero,
ιOrZero_eq_zero _ _ _ _ _ _ _ _ _ _ _ _
(by simpa only [← ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄] using h₂),
comp_zero, smul_zero]
· rw [mapBifunctor.d₁_eq_zero _ _ _ _ _ _ _ h₁,
d₁_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h₁, comp_zero]
variable [HasGoodTrifunctor₂₃Obj F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄]
@[reassoc (attr := simp)]
lemma ι_D₂ :
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h ≫ D₂ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ j j' =
d₂ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j' := by
simp [D₂]
@[reassoc (attr := simp)]
lemma ι_D₃ :
ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h ≫ D₃ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ j j' =
d₃ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j' := by
simp [D₃]
end
variable [HasGoodTrifunctor₂₃Obj F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄] (j j' : ι₄)
lemma d_eq :
(mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄).d j j' =
D₁ F G₂₃ K₁ K₂ K₃ c₂₃ c₄ j j' + D₂ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ j j' +
D₃ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ j j' := by
rw [mapBifunctor.d_eq]
rw [add_assoc]
congr 1
apply mapBifunctor₂₃.hom_ext (c₁₂ := c₁₂)
intro i₁ i₂ i₃ h
simp only [Preadditive.comp_add, ι_D₂, ι_D₃]
rw [ι_eq _ _ _ _ _ _ _ _ _ _ _ _ _ rfl
(by rw [← h, ← ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄]; rfl),
assoc, mapBifunctor.ι_D₂]
set i₂₃ := ComplexShape.π c₂ c₃ c₂₃ ⟨i₂, i₃⟩
by_cases h₁ : c₂₃.Rel i₂₃ (c₂₃.next i₂₃)
· by_cases h₂ : ComplexShape.π c₁ c₂₃ c₄ (i₁, c₂₃.next i₂₃) = j'
· rw [mapBifunctor.d₂_eq _ _ _ _ _ h₁ _ h₂, mapBifunctor.d_eq,
Linear.comp_units_smul, Functor.map_add, Preadditive.add_comp,
Preadditive.comp_add, smul_add]
congr 1
· rw [← Functor.map_comp_assoc, mapBifunctor.ι_D₁]
by_cases h₃ : c₂.Rel i₂ (c₂.next i₂)
· rw [d₂_eq _ _ _ _ _ _ _ _ _ h₃,
mapBifunctor.d₁_eq _ _ _ _ h₃ _ _ (ComplexShape.next_π₁ c₃ c₂₃ h₃ i₃).symm,
Functor.map_units_smul, Functor.map_comp, Linear.units_smul_comp,
assoc, smul_smul, smul_left_cancel_iff,
ιOrZero_eq _ _ _ _ _ _ _ _ _ _ _ _ (by
dsimp [ComplexShape.r]
rw [← h₂, ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄,
ComplexShape.next_π₁ c₃ c₂₃ h₃ i₃]), ι_eq]
· rw [d₂_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h₃,
mapBifunctor.d₁_eq_zero _ _ _ _ _ _ _ h₃,
Functor.map_zero, zero_comp, smul_zero]
· rw [← Functor.map_comp_assoc, mapBifunctor.ι_D₂]
by_cases h₃ : c₃.Rel i₃ (c₃.next i₃)
· rw [d₃_eq _ _ _ _ _ _ _ _ _ _ h₃,
mapBifunctor.d₂_eq _ _ _ _ _ h₃ _ (ComplexShape.next_π₂ c₂ c₂₃ i₂ h₃).symm,
Functor.map_units_smul, Functor.map_comp, Linear.units_smul_comp, assoc,
smul_smul, smul_left_cancel_iff]
rw [ιOrZero_eq _ _ _ _ _ _ _ _ _ _ _ _ (by
dsimp [ComplexShape.r]
rw [← h₂, ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄, ComplexShape.next_π₂ c₂ c₂₃ i₂ h₃]),
ι_eq]
· rw [d₃_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h₃,
mapBifunctor.d₂_eq_zero _ _ _ _ _ _ _ h₃,
Functor.map_zero, zero_comp, smul_zero]
· rw [mapBifunctor.d₂_eq_zero' _ _ _ _ _ h₁ _ h₂, comp_zero]
trans 0 + 0
· simp
· congr 1
· by_cases h₃ : c₂.Rel i₂ (c₂.next i₂)
· rw [d₂_eq _ _ _ _ _ _ _ _ _ h₃, ιOrZero_eq_zero, comp_zero, smul_zero]
intro h₄
apply h₂
rw [← h₄]
dsimp [ComplexShape.r]
rw [ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄, ComplexShape.next_π₁ c₃ c₂₃ h₃ i₃]
· rw [d₂_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h₃]
· by_cases h₃ : c₃.Rel i₃ (c₃.next i₃)
· rw [d₃_eq _ _ _ _ _ _ _ _ _ _ h₃, ιOrZero_eq_zero, comp_zero, smul_zero]
intro h₄
apply h₂
rw [← h₄]
dsimp [ComplexShape.r]
rw [ComplexShape.assoc c₁ c₂ c₃ c₁₂ c₂₃ c₄, ComplexShape.next_π₂ c₂ c₂₃ i₂ h₃]
· rw [d₃_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h₃]
· rw [mapBifunctor.d₂_eq_zero _ _ _ _ _ _ _ h₁, comp_zero]
trans 0 + 0
· simp only [add_zero]
· congr 1
· rw [d₂_eq_zero]
intro h₂
apply h₁
simpa only [← ComplexShape.next_π₁ c₃ c₂₃ h₂ i₃]
using ComplexShape.rel_π₁ c₃ c₂₃ h₂ i₃
· rw [d₃_eq_zero]
intro h₂
apply h₁
simpa only [i₂₃, ComplexShape.next_π₂ c₂ c₂₃ i₂ h₂]
using ComplexShape.rel_π₂ c₂ c₂₃ i₂ h₂
end mapBifunctor₂₃
variable [DecidableEq ι₁₂] [DecidableEq ι₂₃]
[HasMapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄]
[HasMapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄]
[HasGoodTrifunctor₁₂Obj F₁₂ G K₁ K₂ K₃ c₁₂ c₄]
[HasGoodTrifunctor₂₃Obj F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄]
@[reassoc (attr := simp)]
lemma ι_mapBifunctorAssociatorX_hom (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄)
(h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j) :
mapBifunctor₁₂.ι F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j h ≫
(mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄ j).hom =
((associator.hom.app (K₁.X i₁)).app (K₂.X i₂)).app (K₃.X i₃) ≫
mapBifunctor₂₃.ι F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j h := by
apply GradedObject.ι_mapBifunctorAssociator_hom
@[reassoc (attr := simp)]
lemma ιOrZero_mapBifunctorAssociatorX_hom (i₁ : ι₁) (i₂ : ι₂) (i₃ : ι₃) (j : ι₄) :
mapBifunctor₁₂.ιOrZero F₁₂ G K₁ K₂ K₃ c₁₂ c₄ i₁ i₂ i₃ j ≫
(mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄ j).hom =
((associator.hom.app (K₁.X i₁)).app (K₂.X i₂)).app (K₃.X i₃) ≫
mapBifunctor₂₃.ιOrZero F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ i₁ i₂ i₃ j := by
by_cases h : ComplexShape.r c₁ c₂ c₃ c₁₂ c₄ (i₁, i₂, i₃) = j
· rw [mapBifunctor₁₂.ιOrZero_eq _ _ _ _ _ _ _ _ _ _ _ h,
mapBifunctor₂₃.ιOrZero_eq _ _ _ _ _ _ _ _ _ _ _ _ h,
ι_mapBifunctorAssociatorX_hom]
· rw [mapBifunctor₁₂.ιOrZero_eq_zero _ _ _ _ _ _ _ _ _ _ _ h,
mapBifunctor₂₃.ιOrZero_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h,
zero_comp, comp_zero]
@[reassoc]
lemma mapBifunctorAssociatorX_hom_D₁ (j j' : ι₄) :
(mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄ j).hom ≫
mapBifunctor₂₃.D₁ F G₂₃ K₁ K₂ K₃ c₂₃ c₄ j j' =
mapBifunctor₁₂.D₁ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' ≫
(mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄ j').hom := by
ext i₁ i₂ i₃ h
rw [mapBifunctor₁₂.ι_D₁_assoc, ι_mapBifunctorAssociatorX_hom_assoc, mapBifunctor₂₃.ι_D₁]
by_cases h₁ : c₁.Rel i₁ (c₁.next i₁)
· have := NatTrans.naturality_app_app associator.hom
(K₁.d i₁ (c₁.next i₁)) (K₂.X i₂) (K₃.X i₃)
dsimp at this
rw [mapBifunctor₁₂.d₁_eq _ _ _ _ _ _ _ h₁, mapBifunctor₂₃.d₁_eq _ _ _ _ _ _ _ _ h₁,
Linear.comp_units_smul, Linear.units_smul_comp, assoc,
ComplexShape.associative_ε₁_eq_mul c₁ c₂ c₃ c₁₂ c₂₃ c₄,
ιOrZero_mapBifunctorAssociatorX_hom, smul_left_cancel_iff,
reassoc_of% this]
· rw [mapBifunctor₁₂.d₁_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₁,
mapBifunctor₂₃.d₁_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h₁, comp_zero, zero_comp]
@[reassoc]
lemma mapBifunctorAssociatorX_hom_D₂ (j j' : ι₄) :
(mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄ j).hom ≫
mapBifunctor₂₃.D₂ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ j j' =
mapBifunctor₁₂.D₂ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' ≫
(mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄ j').hom := by
ext i₁ i₂ i₃ h
rw [mapBifunctor₁₂.ι_D₂_assoc, ι_mapBifunctorAssociatorX_hom_assoc, mapBifunctor₂₃.ι_D₂]
by_cases h₁ : c₂.Rel i₂ (c₂.next i₂)
· have := NatTrans.naturality_app (associator.hom.app (K₁.X i₁)) (K₃.X i₃) (K₂.d i₂ (c₂.next i₂))
dsimp at this
rw [mapBifunctor₁₂.d₂_eq _ _ _ _ _ _ _ _ h₁, mapBifunctor₂₃.d₂_eq _ _ _ _ _ _ _ _ _ h₁,
Linear.units_smul_comp, assoc, ιOrZero_mapBifunctorAssociatorX_hom,
reassoc_of% this, Linear.comp_units_smul,
ComplexShape.associative_ε₂_ε₁ c₁ c₂ c₃ c₁₂ c₂₃ c₄]
· rw [mapBifunctor₁₂.d₂_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₁,
mapBifunctor₂₃.d₂_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h₁, comp_zero, zero_comp]
@[reassoc]
lemma mapBifunctorAssociatorX_hom_D₃ (j j' : ι₄) :
(mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄ j).hom ≫
mapBifunctor₂₃.D₃ F G₂₃ K₁ K₂ K₃ c₁₂ c₂₃ c₄ j j' =
mapBifunctor₁₂.D₃ F₁₂ G K₁ K₂ K₃ c₁₂ c₄ j j' ≫
(mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄ j').hom := by
ext i₁ i₂ i₃ h
rw [mapBifunctor₁₂.ι_D₃_assoc, ι_mapBifunctorAssociatorX_hom_assoc, mapBifunctor₂₃.ι_D₃]
by_cases h₁ : c₃.Rel i₃ (c₃.next i₃)
· rw [mapBifunctor₁₂.d₃_eq _ _ _ _ _ _ _ _ _ h₁,
mapBifunctor₂₃.d₃_eq _ _ _ _ _ _ _ _ _ _ h₁,
Linear.comp_units_smul, Linear.units_smul_comp, assoc,
ιOrZero_mapBifunctorAssociatorX_hom, NatTrans.naturality_assoc,
ComplexShape.associative_ε₂_eq_mul c₁ c₂ c₃ c₁₂ c₂₃ c₄]
dsimp
· rw [mapBifunctor₁₂.d₃_eq_zero _ _ _ _ _ _ _ _ _ _ _ h₁,
mapBifunctor₂₃.d₃_eq_zero _ _ _ _ _ _ _ _ _ _ _ _ h₁, comp_zero, zero_comp]
/-- The associator isomorphism for the action of bifunctors
on homological complexes. -/
noncomputable def mapBifunctorAssociator :
mapBifunctor (mapBifunctor K₁ K₂ F₁₂ c₁₂) K₃ G c₄ ≅
mapBifunctor K₁ (mapBifunctor K₂ K₃ G₂₃ c₂₃) F c₄ :=
Hom.isoOfComponents (mapBifunctorAssociatorX associator K₁ K₂ K₃ c₁₂ c₂₃ c₄) (by
intro j j' _
simp only [mapBifunctor₁₂.d_eq, mapBifunctor₂₃.d_eq _ _ _ _ _ c₁₂,
Preadditive.add_comp, Preadditive.comp_add,
mapBifunctorAssociatorX_hom_D₁, mapBifunctorAssociatorX_hom_D₂,
mapBifunctorAssociatorX_hom_D₃])
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Refinements.lean | 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomologySequence.lean | 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
instance [K.HasHomology i] [K.HasHomology j] :
Epi ((composableArrows₃ K i j).map' 2 3) := by
-- Disable `Fin.reduceFinMk`, otherwise `Precomp.obj_succ` does not fire. (https://github.com/leanprover-community/mathlib4/issues/27382)
dsimp [-Fin.reduceFinMk]
infer_instance
include hij in
/-- 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
/-- 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)
-- Disable `Fin.reduceFinMk`, otherwise `Precomp.obj_succ` does not fire. (https://github.com/leanprover-community/mathlib4/issues/27382)
(homologyMap φ j) (by simp) (by simp [-Fin.reduceFinMk]) (by simp [-Fin.reduceFinMk])
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 (hS : S.ShortExact) (i j : ι) (hij : c.Rel i j) :
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 homomorphism `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
include hS in
/-- 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 simp) (by simp)
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₁])
theorem mono_δ (hi : IsZero (S.X₂.homology i)) : Mono (hS.δ i j hij) :=
(HomologicalComplex.HomologySequence.snakeInput _ _ _ _).mono_δ hi
theorem epi_δ (hj : IsZero (S.X₂.homology j)) : Epi (hS.δ i j hij) :=
(HomologicalComplex.HomologySequence.snakeInput _ _ _ _).epi_δ hj
theorem isIso_δ (hi : IsZero (S.X₂.homology i)) (hj : IsZero (S.X₂.homology j)) :
IsIso (hS.δ i j hij) :=
(HomologicalComplex.HomologySequence.snakeInput _ _ _ _).isIso_δ hi hj
/-- If `c.Rel i j` and `Hᵢ(X₂), Hⱼ(X₂)` are trivial, `δ` defines an isomorphism
`Hᵢ(X₃) ≅ Hⱼ(X₁)`. -/
noncomputable def δIso (hi : IsZero (S.X₂.homology i)) (hj : IsZero (S.X₂.homology j)) :
S.X₃.homology i ≅ S.X₁.homology j :=
@asIso _ _ _ _ (hS.δ i j hij) (hS.isIso_δ i j hij hi hj)
end ShortExact
end ShortComplex
end CategoryTheory |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Localization.lean | 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]
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
variable [(HomologicalComplex.quasiIso C c).HasLocalization]
/-- The category of homological complexes up to quasi-isomorphisms. -/
abbrev HomologicalComplexUpToQuasiIso := (HomologicalComplex.quasiIso C c).Localization'
variable {C c} in
/-- The localization functor `HomologicalComplex C c ⥤ HomologicalComplexUpToQuasiIso C c`. -/
abbrev HomologicalComplexUpToQuasiIso.Q :
HomologicalComplex C c ⥤ HomologicalComplexUpToQuasiIso C c :=
(HomologicalComplex.quasiIso C c).Q'
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]
lemma HomologicalComplexUpToQuasiIso.Q_inverts_homotopyEquivalences
[(HomologicalComplex.quasiIso C c).HasLocalization] :
(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 [(HomologicalComplex.quasiIso C c).HasLocalization] [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 ≪≫
Functor.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 to 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]
include hc
/-- 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 _ _ := rfl
uniq _ _ 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 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
variable [(HomologicalComplex.quasiIso C c).HasLocalization]
/-- 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Functor.lean | 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, funext_iff] at this
exact this t
shape := fun i j h => by
have := C.shape _ _ h
rw [NatTrans.ext_iff, funext_iff] at this
exact this t }
map h :=
{ f := fun i => (C.X i).map h
comm' := fun _ _ _ => 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/TotalComplexSymmetry.lean | import Mathlib.Algebra.Homology.TotalComplex
/-! The symmetry of the total complex of a bicomplex
Let `K : HomologicalComplex₂ C c₁ c₂` be a bicomplex. If we assume both
`[TotalComplexShape c₁ c₂ c]` and `[TotalComplexShape c₂ c₁ c]`, we may form
the total complex `K.total c` and `K.flip.total c`.
In this file, we show that if we assume `[TotalComplexShapeSymmetry c₁ c₂ c]`,
then there is an isomorphism `K.totalFlipIso c : K.flip.total c ≅ K.total c`.
Moreover, if we also have `[TotalComplexShapeSymmetry c₂ c₁ c]` and that the signs
are compatible `[TotalComplexShapeSymmetrySymmetry c₁ c₂ c]`, then the isomorphisms
`K.totalFlipIso c` and `K.flip.totalFlipIso c` are inverse to each other.
-/
assert_not_exists Ideal TwoSidedIdeal
open CategoryTheory Category Limits
namespace HomologicalComplex₂
variable {C I₁ I₂ J : Type*} [Category C] [Preadditive C]
{c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} (K : HomologicalComplex₂ C c₁ c₂)
(c : ComplexShape J) [TotalComplexShape c₁ c₂ c] [TotalComplexShape c₂ c₁ c]
[TotalComplexShapeSymmetry c₁ c₂ c]
instance [K.HasTotal c] : K.flip.HasTotal c := fun j =>
hasCoproduct_of_equiv_of_iso (K.toGradedObject.mapObjFun (ComplexShape.π c₁ c₂ c) j) _
(ComplexShape.symmetryEquiv c₁ c₂ c j) (fun _ => Iso.refl _)
lemma flip_hasTotal_iff : K.flip.HasTotal c ↔ K.HasTotal c := by
constructor
· intro
change K.flip.flip.HasTotal c
have := TotalComplexShapeSymmetry.symmetry c₁ c₂ c
infer_instance
· intro
infer_instance
variable [K.HasTotal c] [DecidableEq J]
attribute [local simp] smul_smul
/-- Auxiliary definition for `totalFlipIso`. -/
noncomputable def totalFlipIsoX (j : J) : (K.flip.total c).X j ≅ (K.total c).X j where
hom := K.flip.totalDesc (fun i₂ i₁ h => ComplexShape.σ c₁ c₂ c i₁ i₂ • K.ιTotal c i₁ i₂ j (by
rw [← ComplexShape.π_symm c₁ c₂ c i₁ i₂, h]))
inv := K.totalDesc (fun i₁ i₂ h => ComplexShape.σ c₁ c₂ c i₁ i₂ • K.flip.ιTotal c i₂ i₁ j (by
rw [ComplexShape.π_symm c₁ c₂ c i₁ i₂, h]))
hom_inv_id := by ext; simp
inv_hom_id := by ext; simp
@[reassoc]
lemma totalFlipIsoX_hom_D₁ (j j' : J) :
(K.totalFlipIsoX c j).hom ≫ K.D₁ c j j' =
K.flip.D₂ c j j' ≫ (K.totalFlipIsoX c j').hom := by
by_cases h₀ : c.Rel j j'
· ext i₂ i₁ h₁
dsimp [totalFlipIsoX]
rw [ι_totalDesc_assoc, Linear.units_smul_comp, ι_D₁, ι_D₂_assoc]
dsimp
by_cases h₂ : c₁.Rel i₁ (c₁.next i₁)
· have h₃ : ComplexShape.π c₂ c₁ c ⟨i₂, c₁.next i₁⟩ = j' := by
rw [← ComplexShape.next_π₂ c₂ c i₂ h₂, h₁, c.next_eq' h₀]
have h₄ : ComplexShape.π c₁ c₂ c ⟨c₁.next i₁, i₂⟩ = j' := by
rw [← h₃, ComplexShape.π_symm c₁ c₂ c]
rw [K.d₁_eq _ h₂ _ _ h₄, K.flip.d₂_eq _ _ h₂ _ h₃, Linear.units_smul_comp,
assoc, ι_totalDesc, Linear.comp_units_smul, smul_smul, smul_smul,
ComplexShape.σ_ε₁ c₂ c h₂ i₂]
dsimp only [flip_X_X, flip_X_d]
· rw [K.d₁_eq_zero _ _ _ _ h₂, K.flip.d₂_eq_zero _ _ _ _ h₂, smul_zero, zero_comp]
· rw [K.D₁_shape _ _ _ h₀, K.flip.D₂_shape c _ _ h₀, zero_comp, comp_zero]
@[reassoc]
lemma totalFlipIsoX_hom_D₂ (j j' : J) :
(K.totalFlipIsoX c j).hom ≫ K.D₂ c j j' =
K.flip.D₁ c j j' ≫ (K.totalFlipIsoX c j').hom := by
by_cases h₀ : c.Rel j j'
· ext i₂ i₁ h₁
dsimp [totalFlipIsoX]
rw [ι_totalDesc_assoc, Linear.units_smul_comp, ι_D₂, ι_D₁_assoc]
dsimp
by_cases h₂ : c₂.Rel i₂ (c₂.next i₂)
· have h₃ : ComplexShape.π c₂ c₁ c (ComplexShape.next c₂ i₂, i₁) = j' := by
rw [← ComplexShape.next_π₁ c₁ c h₂ i₁, h₁, c.next_eq' h₀]
have h₄ : ComplexShape.π c₁ c₂ c (i₁, ComplexShape.next c₂ i₂) = j' := by
rw [← h₃, ComplexShape.π_symm c₁ c₂ c]
rw [K.d₂_eq _ _ h₂ _ h₄, K.flip.d₁_eq _ h₂ _ _ h₃, Linear.units_smul_comp,
assoc, ι_totalDesc, Linear.comp_units_smul, smul_smul, smul_smul,
ComplexShape.σ_ε₂ c₁ c i₁ h₂]
rfl
· rw [K.d₂_eq_zero _ _ _ _ h₂, K.flip.d₁_eq_zero _ _ _ _ h₂, smul_zero, zero_comp]
· rw [K.D₂_shape _ _ _ h₀, K.flip.D₁_shape c _ _ h₀, zero_comp, comp_zero]
/-- The symmetry isomorphism `K.flip.total c ≅ K.total c` of the total complex of a
bicomplex when we have `[TotalComplexShapeSymmetry c₁ c₂ c]`. -/
noncomputable def totalFlipIso : K.flip.total c ≅ K.total c :=
HomologicalComplex.Hom.isoOfComponents (K.totalFlipIsoX c) (fun j j' _ => by
simp only [total_d, Preadditive.comp_add, totalFlipIsoX_hom_D₁,
totalFlipIsoX_hom_D₂, Preadditive.add_comp]
rw [add_comm])
@[reassoc]
lemma totalFlipIso_hom_f_D₁ (j j' : J) :
(K.totalFlipIso c).hom.f j ≫ K.D₁ c j j' =
K.flip.D₂ c j j' ≫ (K.totalFlipIso c).hom.f j' := by
apply totalFlipIsoX_hom_D₁
@[reassoc]
lemma totalFlipIso_hom_f_D₂ (j j' : J) :
(K.totalFlipIso c).hom.f j ≫ K.D₂ c j j' =
K.flip.D₁ c j j' ≫ (K.totalFlipIso c).hom.f j' := by
apply totalFlipIsoX_hom_D₂
@[reassoc (attr := simp)]
lemma ιTotal_totalFlipIso_f_hom
(i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₂ c₁ c (i₂, i₁) = j) :
K.flip.ιTotal c i₂ i₁ j h ≫ (K.totalFlipIso c).hom.f j =
ComplexShape.σ c₁ c₂ c i₁ i₂ • K.ιTotal c i₁ i₂ j
(by rw [← ComplexShape.π_symm c₁ c₂ c i₁ i₂, h]) := by
simp [totalFlipIso, totalFlipIsoX]
@[reassoc (attr := simp)]
lemma ιTotal_totalFlipIso_f_inv
(i₁ : I₁) (i₂ : I₂) (j : J) (h : ComplexShape.π c₁ c₂ c (i₁, i₂) = j) :
K.ιTotal c i₁ i₂ j h ≫ (K.totalFlipIso c).inv.f j =
ComplexShape.σ c₁ c₂ c i₁ i₂ • K.flip.ιTotal c i₂ i₁ j
(by rw [ComplexShape.π_symm c₁ c₂ c i₁ i₂, h]) := by
simp [totalFlipIso, totalFlipIsoX]
instance : K.flip.flip.HasTotal c := (inferInstance : K.HasTotal c)
section
variable [TotalComplexShapeSymmetry c₂ c₁ c] [TotalComplexShapeSymmetrySymmetry c₁ c₂ c]
lemma flip_totalFlipIso : K.flip.totalFlipIso c = (K.totalFlipIso c).symm := by
ext j i₁ i₂ h
rw [Iso.symm_hom, ιTotal_totalFlipIso_f_hom]
dsimp only [flip_flip]
rw [ιTotal_totalFlipIso_f_inv, ComplexShape.σ_symm]
end
end HomologicalComplex₂ |
.lake/packages/mathlib/Mathlib/Algebra/Homology/ComplexShapeSigns.lean | import Mathlib.Algebra.Homology.ComplexShape
import Mathlib.Algebra.Ring.NegOnePow
import Mathlib.CategoryTheory.GradedObject.Trifunctor
/-! 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`).
-/
assert_not_exists Field TwoSidedIdeal
variable {I₁ I₂ I₃ I₁₂ I₂₃ J : Type*}
(c₁ : ComplexShape I₁) (c₂ : ComplexShape I₂) (c₃ : ComplexShape I₃)
(c₁₂ : ComplexShape I₁₂) (c₂₃ : ComplexShape I₂₃) (c : ComplexShape J)
/-- A total complex shape for three complex 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
section
variable (c₁ c₂)
variable [TotalComplexShape c₁₂ c₃ c] [TotalComplexShape c₂ c₃ c₂₃] [TotalComplexShape c₁ c₂₃ c]
/-- When we have six complex shapes `c₁`, `c₂`, `c₃`, `c₁₂`, `c₂₃`, `c`, and total functors
`HomologicalComplex₂ C c₁ c₂ ⥤ HomologicalComplex C c₁₂`,
`HomologicalComplex₂ C c₁₂ c₃ ⥤ HomologicalComplex C c`,
`HomologicalComplex₂ C c₂ c₃ ⥤ HomologicalComplex C c₂₃`,
`HomologicalComplex₂ C c₁ c₂₂₃ ⥤ HomologicalComplex C c`, we get two ways to
compute the total complex of a triple complex in `HomologicalComplex₃ C c₁ c₂ c₃`, then
under this assumption `[Associative c₁ c₂ c₃ c₁₂ c₂₃ c]`, these two complexes
canonically identify (without introducing signs). -/
class Associative : Prop where
assoc (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) :
π c₁₂ c₃ c ⟨π c₁ c₂ c₁₂ ⟨i₁, i₂⟩, i₃⟩ = π c₁ c₂₃ c ⟨i₁, π c₂ c₃ c₂₃ ⟨i₂, i₃⟩⟩
ε₁_eq_mul (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) :
ε₁ c₁ c₂₃ c (i₁, π c₂ c₃ c₂₃ (i₂, i₃)) =
ε₁ c₁₂ c₃ c (π c₁ c₂ c₁₂ (i₁, i₂), i₃) * ε₁ c₁ c₂ c₁₂ (i₁, i₂)
ε₂_ε₁ (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) :
ε₂ c₁ c₂₃ c (i₁, π c₂ c₃ c₂₃ (i₂, i₃)) * ε₁ c₂ c₃ c₂₃ (i₂, i₃) =
ε₁ c₁₂ c₃ c (π c₁ c₂ c₁₂ (i₁, i₂), i₃) * ε₂ c₁ c₂ c₁₂ (i₁, i₂)
ε₂_eq_mul (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) :
ε₂ c₁₂ c₃ c (π c₁ c₂ c₁₂ (i₁, i₂), i₃) =
(ε₂ c₁ c₂₃ c (i₁, π c₂ c₃ c₂₃ (i₂, i₃)) * ε₂ c₂ c₃ c₂₃ (i₂, i₃))
variable [Associative c₁ c₂ c₃ c₁₂ c₂₃ c]
lemma assoc (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) :
π c₁₂ c₃ c ⟨π c₁ c₂ c₁₂ ⟨i₁, i₂⟩, i₃⟩ = π c₁ c₂₃ c ⟨i₁, π c₂ c₃ c₂₃ ⟨i₂, i₃⟩⟩ := by
apply Associative.assoc
lemma associative_ε₁_eq_mul (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) :
ε₁ c₁ c₂₃ c (i₁, π c₂ c₃ c₂₃ (i₂, i₃)) =
ε₁ c₁₂ c₃ c (π c₁ c₂ c₁₂ (i₁, i₂), i₃) * ε₁ c₁ c₂ c₁₂ (i₁, i₂) := by
apply Associative.ε₁_eq_mul
lemma associative_ε₂_ε₁ (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) :
ε₂ c₁ c₂₃ c (i₁, π c₂ c₃ c₂₃ (i₂, i₃)) * ε₁ c₂ c₃ c₂₃ (i₂, i₃) =
ε₁ c₁₂ c₃ c (π c₁ c₂ c₁₂ (i₁, i₂), i₃) * ε₂ c₁ c₂ c₁₂ (i₁, i₂) := by
apply Associative.ε₂_ε₁
lemma associative_ε₂_eq_mul (i₁ : I₁) (i₂ : I₂) (i₃ : I₃) :
ε₂ c₁₂ c₃ c (π c₁ c₂ c₁₂ (i₁, i₂), i₃) =
(ε₂ c₁ c₂₃ c (i₁, π c₂ c₃ c₂₃ (i₂, i₃)) * ε₂ c₂ c₃ c₂₃ (i₂, i₃)) := by
apply Associative.ε₂_eq_mul
/-- The map `I₁ × I₂ × I₃ → j` that is obtained using `TotalComplexShape c₁ c₂ c₁₂`
and `TotalComplexShape c₁₂ c₃ c` when `c₁ : ComplexShape I₁`, `c₂ : ComplexShape I₂`,
`c₃ : ComplexShape I₃`, `c₁₂ : ComplexShape I₁₂` and `c : ComplexShape J`. -/
def r : I₁ × I₂ × I₃ → J := fun ⟨i₁, i₂, i₃⟩ ↦ π c₁₂ c₃ c ⟨π c₁ c₂ c₁₂ ⟨i₁, i₂⟩, i₃⟩
open CategoryTheory
/-- The `GradedObject.BifunctorComp₁₂IndexData` which arises from complex shapes. -/
@[reducible]
def ρ₁₂ : GradedObject.BifunctorComp₁₂IndexData (r c₁ c₂ c₃ c₁₂ c) where
I₁₂ := I₁₂
p := π c₁ c₂ c₁₂
q := π c₁₂ c₃ c
hpq _ := rfl
/-- The `GradedObject.BifunctorComp₂₃IndexData` which arises from complex shapes. -/
@[reducible]
def ρ₂₃ : GradedObject.BifunctorComp₂₃IndexData (r c₁ c₂ c₃ c₁₂ c) where
I₂₃ := I₂₃
p := π c₂ c₃ c₂₃
q := π c₁ c₂₃ c
hpq := fun ⟨i₁, i₂, i₃⟩ ↦ (assoc c₁ c₂ c₃ c₁₂ c₂₃ c i₁ i₂ i₃).symm
end
instance {I : Type*} [AddMonoid I] (c : ComplexShape I) [c.TensorSigns] :
Associative c c c c c c where
assoc := add_assoc
ε₁_eq_mul _ _ _ := by dsimp; rw [one_mul]
ε₂_ε₁ _ _ _ := by dsimp; rw [one_mul, mul_one]
ε₂_eq_mul _ _ _ := by dsimp; rw [ε_add]
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
/-- The symmetry bijection `(π c₂ c₁ c₁₂ ⁻¹' {j}) ≃ (π c₁ c₂ c₁₂ ⁻¹' {j})`. -/
@[simps]
def symmetryEquiv (j : I₁₂) :
(π c₂ c₁ c₁₂ ⁻¹' {j}) ≃ (π c₁ c₂ c₁₂ ⁻¹' {j}) where
toFun := fun ⟨⟨i₂, i₁⟩, h⟩ => ⟨⟨i₁, i₂⟩, by simpa [π_symm] using h⟩
invFun := fun ⟨⟨i₁, i₂⟩, h⟩ => ⟨⟨i₂, i₁⟩, by simpa [π_symm] using h⟩
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
/-- The obvious `TotalComplexShapeSymmetry c₂ c₁ c₁₂` deduced from a
`TotalComplexShapeSymmetry c₁ c₂ c₁₂`. -/
def TotalComplexShapeSymmetry.symmetry [TotalComplexShape c₁ c₂ c₁₂]
[TotalComplexShape c₂ c₁ c₁₂] [TotalComplexShapeSymmetry c₁ c₂ c₁₂] :
TotalComplexShapeSymmetry c₂ c₁ c₁₂ where
symm i₂ i₁ := (ComplexShape.π_symm c₁ c₂ c₁₂ i₁ i₂).symm
σ i₂ i₁ := ComplexShape.σ c₁ c₂ c₁₂ i₁ i₂
σ_ε₁ {i₂ i₂'} h₂ i₁ := by
apply mul_right_cancel (b := ComplexShape.ε₂ c₁ c₂ c₁₂ (i₁, i₂))
rw [mul_assoc]
nth_rw 2 [mul_comm]
rw [← mul_assoc, ComplexShape.σ_ε₂ c₁ c₁₂ i₁ h₂, mul_comm, ← mul_assoc,
Int.units_mul_self, one_mul, mul_comm, ← mul_assoc, Int.units_mul_self, one_mul]
σ_ε₂ i₂ i₁ i₁' h₁ := by
apply mul_right_cancel (b := ComplexShape.ε₁ c₁ c₂ c₁₂ (i₁, i₂))
rw [mul_assoc]
nth_rw 2 [mul_comm]
rw [← mul_assoc, ComplexShape.σ_ε₁ c₂ c₁₂ h₁ i₂, mul_comm, ← mul_assoc,
Int.units_mul_self, one_mul, mul_comm, ← mul_assoc, Int.units_mul_self, one_mul]
/-- 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCategory.lean | 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] : ((Functor.whiskeringLeft _ _ D).obj (quotient V c)).Full :=
Quotient.full_whiskeringLeft_functor _ _
instance {D : Type*} [Category D] : ((Functor.whiskeringLeft _ _ D).obj (quotient V c)).Faithful :=
Quotient.faithful_whiskeringLeft_functor _ _
variable {V c}
lemma quotient_obj_surjective (X : HomotopyCategory V c) :
∃ (K : HomologicalComplex V c), (quotient _ _).obj K = X :=
⟨_, rfl⟩
-- Not `@[simp]` 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 _
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
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]
/-- 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 cat_disch
@[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 cat_disch
end CategoryTheory |
.lake/packages/mathlib/Mathlib/Algebra/Homology/GrothendieckAbelian.lean | import Mathlib.CategoryTheory.Abelian.GrothendieckCategory.Basic
import Mathlib.CategoryTheory.Generator.HomologicalComplex
import Mathlib.Algebra.Homology.HomologicalComplexAbelian
/-!
# Homological complexes in a Grothendieck abelian category
Let `c : ComplexShape ι` be a complex shape with no loop, and
such that `Small.{w} ι`. Then, if `C` is a Grothendieck abelian
category (with `IsGrothendieckAbelian.{w} C`), the category
`HomologicalComplex C c` is Grothendieck abelian.
-/
universe w w' t v u
open CategoryTheory Limits
namespace HomologicalComplex
variable (C : Type u) [Category.{v} C] {ι : Type t} (c : ComplexShape ι)
section HasZeroMorphisms
variable [HasZeroMorphisms C]
instance locallySmall [LocallySmall.{w} C] [Small.{w} ι] :
LocallySmall.{w} (HomologicalComplex C c) where
hom_small K L := by
let emb (f : K ⟶ L) (i : Shrink.{w} ι) := (equivShrink.{w} _) (f.f ((equivShrink _).symm i))
have hemb : Function.Injective emb := fun f g h ↦ by
ext i
obtain ⟨i, rfl⟩ := (equivShrink.{w} _).symm.surjective i
simpa [emb] using congr_fun h i
apply small_of_injective hemb
instance [HasFilteredColimitsOfSize.{w, w'} C] :
HasFilteredColimitsOfSize.{w, w'} (HomologicalComplex C c) where
HasColimitsOfShape J _ _ := by infer_instance
instance hasExactColimitsOfShape (J : Type w) [Category.{w'} J] [HasFiniteLimits C]
[HasColimitsOfShape J C] [HasExactColimitsOfShape J C] :
HasExactColimitsOfShape J (HomologicalComplex C c) where
preservesFiniteLimits :=
⟨fun K _ _ ↦ ⟨fun {F} ↦ ⟨fun hc ↦ ⟨isLimitOfEval _ _ (fun i ↦ by
let e := preservesColimitNatIso (J := J) (eval C c i)
exact (IsLimit.postcomposeHomEquiv (Functor.isoWhiskerLeft F e) _).1
(IsLimit.ofIsoLimit
(isLimitOfPreserves ((Functor.whiskeringRight J _ _).obj (eval C c i) ⋙ colim) hc)
(Cones.ext (e.symm.app _) (fun k ↦ (NatIso.naturality_2 e.symm _).symm))))⟩⟩⟩⟩
instance ab5OfSize [HasFilteredColimitsOfSize.{w', w} C] [HasFiniteLimits C]
[AB5OfSize.{w', w} C] :
AB5OfSize.{w', w} (HomologicalComplex C c) where
ofShape J _ _ := by infer_instance
end HasZeroMorphisms
instance isGrothendieckAbelian [Abelian C] [IsGrothendieckAbelian.{w} C]
[c.HasNoLoop] [Small.{w} ι] :
IsGrothendieckAbelian.{w} (HomologicalComplex C c) where
hasSeparator := by
have : HasCoproductsOfShape ι C :=
hasColimitsOfShape_of_equivalence (Discrete.equivalence (equivShrink.{w} ι)).symm
infer_instance
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/TotalComplexShift.lean | 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`.
-/
assert_not_exists TwoSidedIdeal
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, π_def, Set.mem_singleton_iff] at h ⊢
cutsat⟩
invFun := fun ⟨⟨a, b⟩, h⟩ => ⟨(a - x, b), by
simp only [Set.mem_preimage, π_def, Set.mem_singleton_iff] at h ⊢
cutsat⟩
left_inv := by
rintro ⟨⟨a, b⟩, h⟩
ext
· dsimp
cutsat
· rfl
right_inv := by
intro ⟨⟨a, b⟩, h⟩
ext
· dsimp
cutsat
· 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, π_def, Set.mem_singleton_iff] at h ⊢
cutsat⟩
invFun := fun ⟨⟨a, b⟩, h⟩ => ⟨(a, b - y), by
simp only [Set.mem_preimage, π_def, Set.mem_singleton_iff] at h ⊢
cutsat⟩
left_inv _ := by simp
right_inv _ := by simp }
(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 _ _
inv_hom_id := by
ext
dsimp
simp only [ι_totalDesc_assoc, Category.assoc, ι_totalDesc, XXIsoOfEq_inv_ιTotal, comp_id]
@[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; cutsat),
K.d₁_eq _ (show p + x + 1 = p + 1 + x by cutsat) _ _ (by dsimp; cutsat)]
dsimp
rw [one_smul, Category.assoc, ι_totalDesc, one_smul, Linear.units_smul_comp]
· rw [D₁_shape _ _ _ _ h, zero_comp, D₁_shape, comp_zero, smul_zero]
grind [up_Rel]
@[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; cutsat),
K.d₂_eq _ _ rfl _ (by dsimp; cutsat), smul_smul,
Linear.units_smul_comp, Category.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]
grind [up_Rel]
/-- 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 [total_d, 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; cutsat) ≫
(CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) x n n' hn').inv := by
subst ha' hn'
dsimp [totalShift₁Iso, totalShift₁XIso]
simp only [ι_totalDesc, comp_id, id_comp]
@[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 cutsat) b).inv ≫
((shiftFunctor₁ C x).obj K).ιTotal (up ℤ) a b n h := by
subst hn'
obtain rfl : a = a' - x := by cutsat
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 ⊢
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]
/-- 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) _ _
inv_hom_id := by
ext
dsimp
simp only [ι_totalDesc_assoc, Linear.units_smul_comp, Category.assoc, ι_totalDesc,
Linear.comp_units_smul, XXIsoOfEq_inv_ιTotal, smul_smul, Int.units_mul_self, one_smul,
comp_id]
@[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; cutsat),
K.d₁_eq _ rfl _ _ (by dsimp; cutsat)]
dsimp
rw [one_smul, one_smul, Category.assoc, ι_totalDesc, Linear.comp_units_smul,
← Int.negOnePow_add]
congr 2
linarith
· rw [D₁_shape _ _ _ _ h, zero_comp, D₁_shape, comp_zero, smul_zero]
grind [up_Rel]
@[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; cutsat),
K.d₂_eq _ _ (show q + y + 1 = q + 1 + y by cutsat) _ (by dsimp; cutsat),
Linear.units_smul_comp, Category.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
cutsat
· rw [D₂_shape _ _ _ _ h, zero_comp, D₂_shape, comp_zero, smul_zero]
simp_all only [up_Rel]
grind
/-- 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 [total_d, 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; cutsat) ≫
(CochainComplex.shiftFunctorObjXIso (K.total (up ℤ)) y n n' hn').inv := by
subst hb' hn'
dsimp [totalShift₂Iso, totalShift₂XIso]
simp only [ι_totalDesc, comp_id, id_comp]
@[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 cutsat)).inv ≫
((shiftFunctor₂ C y).obj K).ιTotal (up ℤ) a b n h := by
subst hn'
obtain rfl : b = b' - y := by cutsat
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 ⊢
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 cutsat) _ 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 cutsat) _ rfl (n + x + y) (by cutsat),
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₂ |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomologicalComplexLimits.lean | 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 _ => limit.π _ j }
naturality := fun i j φ => by
ext n
dsimp
erw [limit.w]
rw [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) :=
preservesLimit_of_preserves_limit_cone (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]
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) φ]
rw [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) :=
preservesColimit_of_preserves_colimit_cocone (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. -/
lemma preservesLimitsOfShape_of_eval {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. -/
lemma preservesColimitsOfShape_of_eval {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) :=
preservesLimitsOfShape_of_eval _ (fun j => by
by_cases h : j = i
· subst h
exact preservesLimitsOfShape_of_natIso (singleCompEvalIsoSelf C c j).symm
· exact Functor.preservesLimitsOfShape_of_isZero _ (isZero_single_comp_eval C c _ _ h) _)
noncomputable instance : PreservesColimitsOfShape J (single C c i) :=
preservesColimitsOfShape_of_eval _ (fun j => by
by_cases h : j = i
· subst h
exact preservesColimitsOfShape_of_natIso (singleCompEvalIsoSelf C c j).symm
· exact Functor.preservesColimitsOfShape_of_isZero _ (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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/DifferentialObject.lean | 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.
TODO: We should 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
-- Removing `@[simp]`, because it is in the opposite direction of `eqToHom_naturality`.
-- Having both causes an infinite loop in the simpNF linter.
@[reassoc]
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; simp
@[reassoc (attr := simp)]
theorem d_squared_apply {x : β} : X.d x ≫ X.d _ = 0 := congr_fun X.d_squared _
-- Removing `@[simp]`, because it is in the opposite direction of `eqToHom_naturality`.
-- Having both causes an infinite loop in the simpNF linter.
@[reassoc]
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]
@[reassoc]
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
/-- 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 [objEqToHom_d_assoc] }
map {X Y} f :=
{ f := f.f
comm' := fun i j h => by
dsimp at h ⊢
subst h
have : f.f i ≫ Y.d i = X.d i ≫ f.f _ := (congr_fun f.comm i).symm
simp only [dite_true, Category.assoc, eqToHom_f', 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomotopyCofiber.lean | 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
· 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
/-- The composition `φ ≫ mappingCone.inr φ` is homotopic to `0`. -/
noncomputable def inrCompHomotopy (hc : ∀ j, ∃ i, c.Rel i j) :
Homotopy (φ ≫ inr φ) 0 where
hom i j :=
if hij : c.Rel j i then inlX φ i j hij else 0
zero _ _ 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]
variable (hc : ∀ j, ∃ i, c.Rel i j)
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
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, 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 cat_disch
@[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]
cat_disch
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 [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]
include hc
lemma inrX_nullHomotopy_f (j : ι) :
inrX K j ≫ (nullHomotopicMap K).f j = inrX K j ≫ (π K ≫ ι₀ K - 𝟙 _).f j := by
have : biprod.lift (𝟙 K) (-𝟙 K) = biprod.inl - biprod.inr :=
biprod.hom_ext _ _ (by simp) (by simp)
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, this,
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 [this]
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)))
include hc in
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Double.lean | import Mathlib.Algebra.Homology.HasNoLoop
import Mathlib.Algebra.Homology.Single
import Mathlib.CategoryTheory.Yoneda
/-!
# A homological complex lying in two degrees
Given `c : ComplexShape ι`, distinct indices `i₀` and `i₁` such that `hi₀₁ : c.Rel i₀ i₁`,
we construct a homological complex `double f hi₀₁` for any morphism `f : X₀ ⟶ X₁`.
It consists of the objects `X₀` and `X₁` in degrees `i₀` and `i₁`, respectively,
with the differential `X₀ ⟶ X₁` given by `f`, and zero everywhere else.
-/
open CategoryTheory Category Limits ZeroObject Opposite
namespace HomologicalComplex
variable {C : Type*} [Category C] [HasZeroMorphisms C] [HasZeroObject C]
section
variable {X₀ X₁ : C} (f : X₀ ⟶ X₁) {ι : Type*} {c : ComplexShape ι}
{i₀ i₁ : ι} (hi₀₁ : c.Rel i₀ i₁)
open Classical in
/-- Given a complex shape `c`, two indices `i₀` and `i₁` such that `c.Rel i₀ i₁`,
and `f : X₀ ⟶ X₁`, this is the homological complex which, if `i₀ ≠ i₁`, only
consists of the map `f` in degrees `i₀` and `i₁`, and zero everywhere else. -/
noncomputable def double : HomologicalComplex C c where
X k := if k = i₀ then X₀ else if k = i₁ then X₁ else 0
d k k' :=
if hk : k = i₀ ∧ k' = i₁ ∧ i₀ ≠ i₁ then
eqToHom (if_pos hk.1) ≫ f ≫ eqToHom (by
rw [if_neg, if_pos hk.2.1]
aesop)
else 0
d_comp_d' := by
rintro i j k hij hjk
dsimp
by_cases hi : i = i₀
· subst hi
by_cases hj : j = i₁
· subst hj
nth_rw 2 [dif_neg (by tauto)]
rw [comp_zero]
· rw [dif_neg (by tauto), zero_comp]
· rw [dif_neg (by tauto), zero_comp]
shape i j hij := dif_neg (by aesop)
lemma isZero_double_X (k : ι) (h₀ : k ≠ i₀) (h₁ : k ≠ i₁) :
IsZero ((double f hi₀₁).X k) := by
dsimp [double]
rw [if_neg h₀, if_neg h₁]
exact Limits.isZero_zero C
/-- The isomorphism `(double f hi₀₁).X i₀ ≅ X₀`. -/
noncomputable def doubleXIso₀ : (double f hi₀₁).X i₀ ≅ X₀ :=
eqToIso (dif_pos rfl)
/-- The isomorphism `(double f hi₀₁).X i₁ ≅ X₁`. -/
noncomputable def doubleXIso₁ (h : i₀ ≠ i₁) : (double f hi₀₁).X i₁ ≅ X₁ :=
eqToIso (by
dsimp [double]
rw [if_neg h.symm, if_pos rfl])
lemma double_d (h : i₀ ≠ i₁) :
(double f hi₀₁).d i₀ i₁ =
(doubleXIso₀ f hi₀₁).hom ≫ f ≫ (doubleXIso₁ f hi₀₁ h).inv :=
dif_pos ⟨rfl, rfl, h⟩
lemma double_d_eq_zero₀ (a b : ι) (ha : a ≠ i₀) :
(double f hi₀₁).d a b = 0 :=
dif_neg (by tauto)
lemma double_d_eq_zero₁ (a b : ι) (hb : b ≠ i₁) :
(double f hi₀₁).d a b = 0 :=
dif_neg (by tauto)
variable {f hi₀₁} in
@[ext]
lemma from_double_hom_ext {K : HomologicalComplex C c} {φ φ' : double f hi₀₁ ⟶ K}
(h₀ : φ.f i₀ = φ'.f i₀) (h₁ : φ.f i₁ = φ'.f i₁) : φ = φ' := by
ext k
by_cases h : k = i₀ ∨ k = i₁
· obtain rfl | rfl := h <;> assumption
· simp only [not_or] at h
apply (isZero_double_X f hi₀₁ k h.1 h.2).eq_of_src
variable {f hi₀₁} in
@[ext]
lemma to_double_hom_ext {K : HomologicalComplex C c} {φ φ' : K ⟶ double f hi₀₁}
(h₀ : φ.f i₀ = φ'.f i₀) (h₁ : φ.f i₁ = φ'.f i₁) : φ = φ' := by
ext k
by_cases h : k = i₀ ∨ k = i₁
· obtain rfl | rfl := h <;> assumption
· simp only [not_or] at h
apply (isZero_double_X f hi₀₁ k h.1 h.2).eq_of_tgt
section
variable {f} (h : i₀ ≠ i₁) {K : HomologicalComplex C c} (φ₀ : X₀ ⟶ K.X i₀) (φ₁ : X₁ ⟶ K.X i₁)
(comm : φ₀ ≫ K.d i₀ i₁ = f ≫ φ₁)
(hφ : ∀ (k : ι), c.Rel i₁ k → φ₁ ≫ K.d i₁ k = 0)
open Classical in
/-- Constructor for morphisms from a homological complex `double f hi₀₁`. -/
noncomputable def mkHomFromDouble : double f hi₀₁ ⟶ K where
f k :=
if hk₀ : k = i₀ then
eqToHom (by rw [hk₀]) ≫ (doubleXIso₀ f hi₀₁).hom ≫ φ₀ ≫ eqToHom (by rw [hk₀])
else if hk₁ : k = i₁ then
eqToHom (by rw [hk₁]) ≫ (doubleXIso₁ f hi₀₁ h).hom ≫ φ₁ ≫ eqToHom (by rw [hk₁])
else 0
comm' k₀ k₁ hk := by
by_cases h₀ : k₀ = i₀
· subst h₀
rw [dif_pos rfl]
obtain rfl := c.next_eq hk hi₀₁
simp [dif_neg h.symm, double_d f hi₀₁ h, comm]
· rw [dif_neg h₀]
by_cases h₁ : k₀ = i₁
· subst h₁
dsimp
rw [if_pos rfl, comp_id, id_comp, assoc, hφ k₁ hk, comp_zero,
double_d_eq_zero₀ _ _ _ _ h.symm, zero_comp]
· apply (isZero_double_X f hi₀₁ k₀ h₀ h₁).eq_of_src
@[simp, reassoc]
lemma mkHomFromDouble_f₀ :
(mkHomFromDouble hi₀₁ h φ₀ φ₁ comm hφ).f i₀ =
(doubleXIso₀ f hi₀₁).hom ≫ φ₀ := by
dsimp [mkHomFromDouble]
rw [if_pos rfl, id_comp, comp_id]
@[simp, reassoc]
lemma mkHomFromDouble_f₁ :
(mkHomFromDouble hi₀₁ h φ₀ φ₁ comm hφ).f i₁ =
(doubleXIso₁ f hi₀₁ h).hom ≫ φ₁ := by
dsimp [mkHomFromDouble]
rw [dif_neg h.symm, if_pos rfl, id_comp, comp_id]
end
/-- Let `c : ComplexShape ι`, and `i₀` and `i₁` be distinct indices such
that `hi₀₁ : c.Rel i₀ i₁`, then for any `X : C`, the functor which sends
`K : HomologicalComplex C c` to `X ⟶ K.X i` is corepresentable by `double (𝟙 X) hi₀₁`. -/
@[simps -isSimp]
noncomputable def evalCompCoyonedaCorepresentableByDoubleId (h : i₀ ≠ i₁) (X : C) :
(eval C c i₀ ⋙ coyoneda.obj (op X)).CorepresentableBy (double (𝟙 X) hi₀₁) where
homEquiv {K} :=
{ toFun g := (doubleXIso₀ _ hi₀₁).inv ≫ g.f i₀
invFun φ₀ := mkHomFromDouble _ h φ₀ (φ₀ ≫ K.d i₀ i₁) (by simp) (by simp)
left_inv g := by
ext
· simp
· simp [double_d _ _ h]
right_inv _ := by simp }
homEquiv_comp _ _ := by simp
end
variable {ι : Type*} (c : ComplexShape ι)
/-- If `i` has no successor for the complex shape `c`,
then for any `X : C`, the functor which sends `K : HomologicalComplex C c`
to `X ⟶ K.X i` is corepresentable by `(single C c i).obj X`. -/
@[simps -isSimp]
noncomputable def evalCompCoyonedaCorepresentableBySingle (i : ι) [DecidableEq ι]
(hi : ∀ (j : ι), ¬ c.Rel i j) (X : C) :
(eval C c i ⋙ coyoneda.obj (op X)).CorepresentableBy ((single C c i).obj X) where
homEquiv {K} :=
{ toFun g := (singleObjXSelf c i X).inv ≫ g.f i
invFun f := mkHomFromSingle f (fun j hj ↦ (hi j hj).elim)
left_inv g := by cat_disch
right_inv f := by simp }
homEquiv_comp := by simp
variable [c.HasNoLoop]
open Classical in
/-- Given a complex shape `c : ComplexShape ι` (with no loop), `X : C` and `j : ι`,
this is a quite explicit choice of corepresentative of the functor which sends
`K : HomologicalComplex C c` to `X ⟶ K.X j`. -/
noncomputable def evalCompCoyonedaCorepresentative (X : C) (j : ι) :
HomologicalComplex C c :=
if hj : ∃ (k : ι), c.Rel j k then
double (𝟙 X) hj.choose_spec
else (single C c j).obj X
/-- If a complex shape `c : ComplexShape ι` has no loop,
then for any `X : C` and `j : ι`, the functor which sends `K : HomologicalComplex C c`
to `X ⟶ K.X j` is corepresentable. -/
noncomputable def evalCompCoyonedaCorepresentable (X : C) (j : ι) :
(eval C c j ⋙ coyoneda.obj (op X)).CorepresentableBy
(evalCompCoyonedaCorepresentative c X j) := by
dsimp [evalCompCoyonedaCorepresentative]
classical
split_ifs with h
· exact evalCompCoyonedaCorepresentableByDoubleId _
(fun hj ↦ c.not_rel_of_eq hj h.choose_spec) _
· apply evalCompCoyonedaCorepresentableBySingle
obtain _ | _ := c.exists_distinct_prev_or j <;> tauto
instance (X : C) (j : ι) : (eval C c j ⋙ coyoneda.obj (op X)).IsCorepresentable where
has_corepresentation := ⟨_, ⟨evalCompCoyonedaCorepresentable c X j⟩⟩
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/ConcreteCategory.lean | 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.lean`. 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] {FC : C → C → Type*} {CC : C → Type v}
[∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{v} C FC] [HasForget₂ C Ab.{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₁
set_option linter.style.commandStart false in
include hS in
/--
In the short exact sequence of complexes
```
0 0 0
| | |
v v v
...-> X_1,i -----> X_1,j --d--> X_1,k ->...
| | |
| f | |
v v v
...-> X_2,i --d--> X_2,j -----> X_2,k ->...
| | |
v v v
...-> X_3,i -----> X_3,j -----> X_3,k ->...
| | |
v v v
0 0 0
```
if `x₁ ∈ X_1,j` and `x₂ ∈ X_2,i` and if `f(x₁) = d(x₂)` then `d(x₁) = 0`. -/
theorem d_eq_zero_of_f_eq_d_apply
(x₂ : ((forget₂ C Ab).obj (S.X₂.X i))) (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 : ι) :
((forget₂ C Ab).map (S.X₁.d j k)) x₁ = 0 := by
have := hS.mono_f
apply (Preadditive.mono_iff_injective (S.f.f k)).1 inferInstance
rw [← ConcreteCategory.forget₂_comp_apply, ← HomologicalComplex.Hom.comm,
ConcreteCategory.forget₂_comp_apply, hx₁, ← ConcreteCategory.forget₂_comp_apply,
HomologicalComplex.d_comp_d, Functor.map_zero, map_zero]
rfl
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
(d_eq_zero_of_f_eq_d_apply hS _ _ x₂ x₁ hx₁ _)) := by
refine hS.δ_apply' i j hij _ ((forget₂ C Ab).map (S.X₂.pOpcycles i) x₂) _ ?_ ?_
· rw [← ConcreteCategory.forget₂_comp_apply, ← ConcreteCategory.forget₂_comp_apply,
HomologicalComplex.p_opcyclesMap, Functor.map_comp, ConcreteCategory.comp_apply,
HomologicalComplex.homology_π_ι, ConcreteCategory.forget₂_comp_apply, hx₂,
HomologicalComplex.i_cyclesMk]
· apply (Preadditive.mono_iff_injective (S.X₂.iCycles j)).1 inferInstance
conv_lhs =>
rw [← ConcreteCategory.forget₂_comp_apply, HomologicalComplex.cyclesMap_i,
ConcreteCategory.forget₂_comp_apply, HomologicalComplex.i_cyclesMk, hx₁]
conv_rhs =>
rw [← ConcreteCategory.forget₂_comp_apply, ← ConcreteCategory.forget₂_comp_apply,
HomologicalComplex.pOpcycles_opcyclesToCycles_assoc, HomologicalComplex.toCycles_i]
end ShortExact
end ShortComplex
end CategoryTheory |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Homotopy.lean | 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]
-- This is not a simp lemma; the LHS already simplifies.
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
-- This is not a simp lemma; the LHS already simplifies.
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
-- This is not a simp lemma; the LHS already simplifies.
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 _ _ _
-- This is not a simp lemma; the LHS already simplifies.
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, not_false_iff, zero_comp,
reduceCtorEq]
· 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, not_false_iff, comp_zero,
reduceCtorEq]
· congr <;> simp
/-- 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 cat_disch
comm : ∀ i, f.f i = dNext i hom + prevD i hom + g.f i := by cat_disch
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 _ _ w => h.zero _ _ w
comm := fun i => by simp [h.comm] }
invFun h :=
{ hom := fun i j => h.hom i j
zero := fun _ _ w => h.zero _ _ w
comm := fun i => by simpa [sub_eq_iff_eq_add] using h.comm i }
left_inv := by cat_disch
right_inv := by cat_disch
/-- 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_cancel,
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 grind [Homotopy.comm]
/-- 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 grind [HomologicalComplex.add_f_apply, Homotopy.comm]
/-- 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
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 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 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]
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
rw [nullHomotopicMap', 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
rw [nullHomotopicMap', 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
rw [nullHomotopicMap', 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
grind
/-! 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'` -/
-- Cannot be @[simp] because `k₀` and `k₂` cannot be inferred by `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₂₁]
-- Cannot be @[simp] because `k₀` and `k₂` cannot be inferred by `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
-- Cannot be @[simp] because `k₁` cannot be inferred by `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₀ _
-- Cannot be @[simp] because `k₁` cannot be inferred by `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
-- Cannot be @[simp] because `k₀` cannot be inferred by `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₁ _
-- Cannot be @[simp] because `k₀` cannot be inferred by `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 ℕ}
-- This is not a simp lemma; the LHS already simplifies.
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
-- This is not a simp lemma; the LHS already simplifies.
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
-- This is not a simp lemma; the LHS already simplifies.
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⟩
@[simp] theorem mkInductiveAux₂_zero :
mkInductiveAux₂ e zero comm_zero one comm_one succ 0 =
⟨0, zero ≫ (Q.xPrevIso rfl).inv, by simpa using comm_zero⟩ :=
rfl
@[simp] theorem mkInductiveAux₂_add_one (n) :
mkInductiveAux₂ e zero comm_zero one comm_one succ (n + 1) =
letI I := mkInductiveAux₁ e 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⟩ :=
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 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]
rw [dif_pos (by simp only [ChainComplex.prev])]
simp [xPrevIso, comp_id]
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 ℕ}
-- This is not a simp lemma; the LHS already simplifies.
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
-- This is not a simp lemma; the LHS already simplifies.
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
-- This is not a simp lemma; the LHS already simplifies.
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⟩
@[simp] theorem mkCoinductiveAux₂_zero :
mkCoinductiveAux₂ e zero comm_zero one comm_one succ 0 =
⟨0, (P.xNextIso rfl).hom ≫ zero, by simpa using comm_zero⟩ :=
rfl
@[simp] theorem mkCoinductiveAux₂_add_one (n) :
mkCoinductiveAux₂ e zero comm_zero one comm_one succ (n + 1) =
letI 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⟩ :=
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 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]
rw [dif_pos (by simp only [CochainComplex.next])]
simp [xNextIso, id_comp]
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
/-- The forward chain map -/
hom : C ⟶ D
/-- The backward chain map -/
inv : D ⟶ C
/-- A homotopy showing that composing the forward and backward maps is homotopic to the identity
on C -/
homotopyHomInvId : Homotopy (hom ≫ inv) (𝟙 C)
/-- A homotopy showing that composing the backward and forward maps is homotopic to the identity
on D -/
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
· 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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/HomologySequenceLemmas.lean | 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 give sufficient conditions 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 (hS₁ : S₁.ShortExact) (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)
include hS₁ hS₂
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/CommSq.lean | import Mathlib.Algebra.Homology.ShortComplex.Basic
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])
/-- The short complex attached to the cokernel cofork of a commutative square. -/
@[simps]
noncomputable def CommSq.shortComplex (sq : CommSq f g inl inr) : ShortComplex C where
f := biprod.lift f (-g)
g := biprod.desc inl inr
zero := 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 <;> cat_disch))
(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
cat_disch)
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
lemma IsPushout.epi_shortComplex_g (h : IsPushout f g inl inr) :
Epi h.shortComplex.g := by
rw [Preadditive.epi_iff_cancel_zero]
intro _ b hb
exact Cofork.IsColimit.hom_ext h.isColimitCokernelCofork (by simpa using hb)
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])
/-- The short complex attached to the kernel fork of a commutative square.
(This is similar to `CommSq.shortComplex`, but with different signs.) -/
@[simps]
noncomputable def CommSq.shortComplex' (sq : CommSq fst snd f g) : ShortComplex C where
f := biprod.lift fst snd
g := biprod.desc f (-g)
zero := 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 <;> cat_disch))
(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
cat_disch)
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
lemma IsPullback.mono_shortComplex'_f (h : IsPullback fst snd f g) :
Mono h.shortComplex'.f := by
rw [Preadditive.mono_iff_cancel_zero]
intro _ b hb
exact Fork.IsLimit.hom_ext h.isLimitKernelFork (by simpa using hb)
end Pullback
end CategoryTheory |
.lake/packages/mathlib/Mathlib/Algebra/Homology/SingleHomology.lean | 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ι]
@[reassoc (attr := simp)]
lemma pOpcycles_singleObjOpcyclesSelfIso_inv :
((single C c j).obj A).pOpcycles j ≫ (singleObjOpcyclesSelfIso _ _ _).inv =
(singleObjXSelf c j A).hom := by
have := ((single C c j).obj A).isIso_iCycles j _ rfl (by simp)
rw [← cancel_epi (((single C c j).obj A).iCycles j),
← HomologicalComplex.homology_π_ι_assoc, homologyι_singleObjOpcyclesSelfIso_inv,
homologyπ_singleObjHomologySelfIso_hom, singleObjCyclesSelfIso_hom]
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) |
.lake/packages/mathlib/Mathlib/Algebra/Homology/LeftResolution/Transport.lean | import Mathlib.Algebra.Homology.LeftResolution.Basic
/-!
# Transport left resolutions along equivalences
If `ι : C ⥤ A` is equipped with `Λ : LeftResolution ι` and
`ι' : C' ⥤ A'` is a functor which corresponds to `ι` via
equivalences of categories `A' ≌ A` and `C' ≌ C`, we
define `Λ.transport .. : LeftResolution ι'`.
-/
namespace CategoryTheory.Abelian
open Category
variable {A C : Type*} [Category C] [Category A]
{A' C' : Type*} [Category C'] [Category A']
namespace LeftResolution
open Functor
/-- Transport `LeftResolution` via equivalences of categories. -/
def transport {ι : C ⥤ A} (Λ : LeftResolution ι) {ι' : C' ⥤ A'}
(eA : A' ≌ A) (eC : C' ≌ C) (e : ι' ⋙ eA.functor ≅ eC.functor ⋙ ι) :
LeftResolution ι' where
F := eA.functor ⋙ Λ.F ⋙ eC.inverse
π := (rightUnitor _).inv ≫ whiskerLeft _ eA.unitIso.hom ≫
(associator _ _ _).hom ≫ whiskerLeft _ (associator _ _ _).inv ≫
whiskerLeft _ (whiskerRight e.hom _) ≫ (associator _ _ _).inv ≫
whiskerRight (associator _ _ _).inv _ ≫
whiskerRight (whiskerRight (associator _ _ _).hom _) _ ≫
whiskerRight (whiskerRight (whiskerLeft _ ((associator _ _ _).hom ≫
whiskerLeft Λ.F eC.counitIso.hom ≫ Λ.F.rightUnitor.hom)) _) _ ≫
(whiskerRight ((associator _ _ _).hom ≫ whiskerLeft _ Λ.π ≫
(rightUnitor _).hom) _) ≫ eA.unitIso.inv
epi_π_app _ := by dsimp; infer_instance
/-- If we have an isomorphism `e : G ⋙ ι' ≅ ι`, then any `Λ : LeftResolution ι`
induces `Λ.ofCompIso e : LeftResolution ι'`. -/
def ofCompIso {ι : C ⥤ A} (Λ : LeftResolution ι) {ι' : C' ⥤ A} {G : C ⥤ C'}
(e : G ⋙ ι' ≅ ι) :
LeftResolution ι' where
F := Λ.F ⋙ G
π := (associator _ _ _).hom ≫ whiskerLeft _ e.hom ≫ Λ.π
epi_π_app _ := by dsimp; infer_instance
end LeftResolution
end CategoryTheory.Abelian |
.lake/packages/mathlib/Mathlib/Algebra/Homology/LeftResolution/Basic.lean | import Mathlib.Algebra.Homology.Additive
import Mathlib.Algebra.Homology.ShortComplex.Abelian
import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex
/-!
# Left resolutions
Given a fully faithful functor `ι : C ⥤ A` to an abelian category,
we introduce a structure `Abelian.LeftResolution ι` which gives
a functor `F : A ⥤ C` and a natural epimorphism
`π.app X : ι.obj (F.obj X) ⟶ X` for all `X : A`.
This is used in order to construct a resolution functor
`LeftResolution.chainComplexFunctor : A ⥤ ChainComplex C ℕ`.
This shall be used in order to construct functorial flat resolutions.
-/
namespace CategoryTheory.Abelian
open Category Limits Preadditive ZeroObject
variable {A C : Type*} [Category C] [Category A] (ι : C ⥤ A)
/-- Given a fully faithful functor `ι : C ⥤ A`, this structure contains the data
of a functor `F : A ⥤ C` and a functorial epimorphism
`π.app X : ι.obj (F.obj X) ⟶ X` for all `X : A`. -/
structure LeftResolution where
/-- a functor which sends `X : A` to an object `F.obj X` with an epimorphism
`π.app X : ι.obj (F.obj X) ⟶ X` -/
F : A ⥤ C
/-- the natural epimorphism -/
π : F ⋙ ι ⟶ 𝟭 A
epi_π_app (X : A) : Epi (π.app X) := by infer_instance
namespace LeftResolution
attribute [instance] epi_π_app
variable {ι} (Λ : LeftResolution ι) (X Y Z : A) (f : X ⟶ Y) (g : Y ⟶ Z)
@[reassoc (attr := simp)]
lemma π_naturality : ι.map (Λ.F.map f) ≫ Λ.π.app Y = Λ.π.app X ≫ f :=
Λ.π.naturality f
variable [ι.Full] [ι.Faithful] [HasZeroMorphisms C] [Abelian A]
/-- Given `ι : C ⥤ A`, `Λ : LeftResolution ι`, `X : A`, this is a chain complex
which is a (functorial) resolution of `A` that is obtained inductively by using
the epimorphisms given by `Λ`. -/
noncomputable def chainComplex : ChainComplex C ℕ :=
ChainComplex.mk' _ _ (ι.preimage (Λ.π.app (kernel (Λ.π.app X)) ≫ kernel.ι _))
(fun f => ⟨_, ι.preimage (Λ.π.app (kernel (ι.map f)) ≫ kernel.ι _),
ι.map_injective (by simp)⟩)
/-- Given `Λ : LeftResolution ι`, the chain complex `Λ.chainComplex X`
identifies in degree `0` to `Λ.F.obj X`. -/
noncomputable def chainComplexXZeroIso :
(Λ.chainComplex X).X 0 ≅ Λ.F.obj X := Iso.refl _
/-- Given `Λ : LeftResolution ι`, the chain complex `Λ.chainComplex X`
identifies in degree `1` to `Λ.F.obj (kernel (Λ.π.app X))`. -/
noncomputable def chainComplexXOneIso :
(Λ.chainComplex X).X 1 ≅ Λ.F.obj (kernel (Λ.π.app X)) := Iso.refl _
@[reassoc]
lemma map_chainComplex_d_1_0 :
ι.map ((Λ.chainComplex X).d 1 0) =
ι.map (Λ.chainComplexXOneIso X).hom ≫ Λ.π.app (kernel (Λ.π.app X)) ≫ kernel.ι _ ≫
ι.map (Λ.chainComplexXZeroIso X).inv := by
simp [chainComplexXOneIso, chainComplexXZeroIso, chainComplex]
/-- The isomorphism which gives the inductive step of the construction of `Λ.chainComplex X`. -/
noncomputable def chainComplexXIso (n : ℕ) :
(Λ.chainComplex X).X (n + 2) ≅ Λ.F.obj (kernel (ι.map ((Λ.chainComplex X).d (n + 1) n))) := by
apply ChainComplex.mk'XIso
lemma map_chainComplex_d (n : ℕ) :
ι.map ((Λ.chainComplex X).d (n + 2) (n + 1)) =
ι.map (Λ.chainComplexXIso X n).hom ≫ Λ.π.app (kernel (ι.map ((Λ.chainComplex X).d (n + 1) n))) ≫
kernel.ι (ι.map ((Λ.chainComplex X).d (n + 1) n)) := by
have := ι.map_preimage (Λ.π.app _ ≫ kernel.ι (ι.map ((Λ.chainComplex X).d (n + 1) n)))
dsimp at this
rw [← this, ← Functor.map_comp]
congr 1
apply ChainComplex.mk'_d
attribute [irreducible] chainComplex
lemma exactAt_map_chainComplex_succ (n : ℕ) :
((ι.mapHomologicalComplex _).obj (Λ.chainComplex X)).ExactAt (n + 1) := by
rw [HomologicalComplex.exactAt_iff' _ (n + 2) (n + 1) n
(ComplexShape.prev_eq' _ (by dsimp; omega)) (by simp),
ShortComplex.exact_iff_epi_kernel_lift]
convert epi_comp (ι.map (Λ.chainComplexXIso X n).hom) (Λ.π.app _)
rw [← cancel_mono (kernel.ι _), kernel.lift_ι]
simp [map_chainComplex_d]
variable {X Y Z}
/-- The morphism `Λ.chainComplex X ⟶ Λ.chainComplex Y` of chain complexes
induced by `f : X ⟶ Y`. -/
noncomputable def chainComplexMap : Λ.chainComplex X ⟶ Λ.chainComplex Y :=
ChainComplex.mkHom _ _
((Λ.chainComplexXZeroIso X).hom ≫ Λ.F.map f ≫ (Λ.chainComplexXZeroIso Y).inv)
((Λ.chainComplexXOneIso X).hom ≫
Λ.F.map (kernel.map _ _ (ι.map (Λ.F.map f)) f (Λ.π.naturality f).symm) ≫
(Λ.chainComplexXOneIso Y).inv)
(ι.map_injective (by
dsimp
simp only [Category.assoc, Functor.map_comp, map_chainComplex_d_1_0]
simp only [← ι.map_comp, ← ι.map_comp_assoc, Iso.inv_hom_id_assoc,
Iso.inv_hom_id, comp_id]
simp))
(fun n p ↦
⟨(Λ.chainComplexXIso X n).hom ≫ (Λ.F.map
(kernel.map _ _ (ι.map p.2.1) (ι.map p.1) (by
rw [← ι.map_comp, ← ι.map_comp, p.2.2]))) ≫ (Λ.chainComplexXIso Y n).inv,
ι.map_injective (by simp [map_chainComplex_d])⟩)
@[simp]
lemma chainComplexMap_f_0 :
(Λ.chainComplexMap f).f 0 =
((Λ.chainComplexXZeroIso X).hom ≫ Λ.F.map f ≫ (Λ.chainComplexXZeroIso Y).inv) := rfl
@[simp]
lemma chainComplexMap_f_1 :
(Λ.chainComplexMap f).f 1 =
(Λ.chainComplexXOneIso X).hom ≫
Λ.F.map (kernel.map _ _ (ι.map (Λ.F.map f)) f (Λ.π.naturality f).symm) ≫
(Λ.chainComplexXOneIso Y).inv := rfl
@[simp]
lemma chainComplexMap_f_succ_succ (n : ℕ) :
(Λ.chainComplexMap f).f (n + 2) =
(Λ.chainComplexXIso X n).hom ≫
Λ.F.map (kernel.map _ _ (ι.map ((Λ.chainComplexMap f).f (n + 1)))
(ι.map ((Λ.chainComplexMap f).f n))
(by rw [← ι.map_comp, ← ι.map_comp, HomologicalComplex.Hom.comm])) ≫
(Λ.chainComplexXIso Y n).inv := by
apply ChainComplex.mkHom_f_succ_succ
variable (X) in
@[simp]
lemma chainComplexMap_id : Λ.chainComplexMap (𝟙 X) = 𝟙 _ := by
ext n
induction n with
| zero => simp
| succ n hn => obtain _ | n := n <;> simp [hn]
variable (X Y) in
@[simp]
lemma chainComplexMap_zero [Λ.F.PreservesZeroMorphisms] :
Λ.chainComplexMap (0 : X ⟶ Y) = 0 := by
ext n
induction n with
| zero => simp
| succ n hn => obtain _|n := n <;> simp [hn]
@[reassoc, simp]
lemma chainComplexMap_comp :
Λ.chainComplexMap (f ≫ g) = Λ.chainComplexMap f ≫ Λ.chainComplexMap g := by
ext n
induction n with
| zero => simp
| succ n hn =>
obtain _ | n := n
all_goals
dsimp
simp only [chainComplexMap_f_succ_succ, assoc, Iso.cancel_iso_hom_left,
Iso.inv_hom_id_assoc, ← Λ.F.map_comp_assoc, Iso.cancel_iso_inv_right_assoc]
congr 1
cat_disch
/-- Given `ι : C ⥤ A`, `Λ : LeftResolution ι`, this is a
functor `A ⥤ ChainComplex C ℕ` which sends `X : A` to a resolution consisting
of objects in `C`. -/
noncomputable def chainComplexFunctor : A ⥤ ChainComplex C ℕ where
obj X := Λ.chainComplex X
map f := Λ.chainComplexMap f
end LeftResolution
end CategoryTheory.Abelian |
.lake/packages/mathlib/Mathlib/Algebra/Homology/LeftResolution/Reduced.lean | import Mathlib.Algebra.Homology.LeftResolution.Transport
import Mathlib.CategoryTheory.Idempotents.FunctorExtension
import Mathlib.CategoryTheory.MorphismProperty.Retract
/-!
# Left resolutions which preserve the zero object
The structure `LeftResolution` allows to define a functorial
resolution of an object (see `LeftResolution.chainComplexFunctor`
in the file `Algebra.Homology.LeftResolution.Basic`). In
order to extend this resolution to complexes, we not only
need the functoriality but also that zero morphisms
are sent to zero. In this file, given `ι : C ⥤ A`,
we extend `Λ : LeftResolution ι` to idempotent completions as
`Λ.karoubi : LeftResolution ((functorExtension₂ C A).obj ι)`, and
when both `C` and `A` are idempotent complete, we define
`Λ.reduced : LeftResolution ι` in such a way that the
functor `Λ.reduced.F : A ⥤ C` preserves zero morphisms.
For example, if `A := ModuleCat R` and `C` is the full subcategory
of flat `R`-modules, we may first define `Λ` by using the
functor which sends an `R`-module `M` to the free `R`-module
on the elements of `M`. Then, `Λ.reduced.F.obj M` will be obtained
from the free `R`-module on `M` by factoring out the direct factor
corresponding to the submodule spanned by the generator corresponding
to `0 : M` (TODO).
-/
namespace CategoryTheory.Abelian
variable {A C : Type*} [Category C] [Category A] {ι : C ⥤ A}
(Λ : LeftResolution ι)
open Idempotents Limits MorphismProperty
namespace LeftResolution
variable [Preadditive C] [Preadditive A] [ι.Additive]
/-- Auxiliary definition for `LeftResolution.karoubi`. -/
@[simps]
def karoubi.F' : A ⥤ Karoubi C where
obj X := ⟨Λ.F.obj X, 𝟙 _ - Λ.F.map 0, by simp [← Functor.map_comp]⟩
map {X Y} f := ⟨Λ.F.map f - Λ.F.map 0, by simp [← Functor.map_comp]⟩
map_comp _ _ := by simp [← Functor.map_comp]
/-- Auxiliary definition for `LeftResolution.karoubi`. -/
@[simps!]
def karoubi.F : Karoubi A ⥤ Karoubi C := (functorExtension₁ A C).obj (karoubi.F' Λ)
instance : (karoubi.F Λ).PreservesZeroMorphisms where
/-- Auxiliary definition for `LeftResolution.karoubi`. -/
@[simps]
def karoubi.π' : toKaroubi A ⋙ F Λ ⋙ (functorExtension₂ C A).obj ι ⟶ toKaroubi A where
app X := ⟨Λ.π.app X, by simp⟩
/-- The morphism `(karoubi.π' Λ).app X` is a retract of `(toKaroubi _).map (Λ.π.app X)`. -/
def karoubi.retractArrow (X : A) :
RetractArrow ((karoubi.π' Λ).app X) ((toKaroubi _).map (Λ.π.app X)) where
i := Arrow.homMk ⟨ι.map ((karoubi.F' Λ).obj X).p, by simp [← Functor.map_comp]⟩ (𝟙 _)
r := Arrow.homMk ⟨ι.map ((karoubi.F' Λ).obj X).p, by simp [← Functor.map_comp]⟩ (𝟙 _)
retract := by
ext
· simp [← Functor.map_comp]
· simp
instance (X : A) : Epi ((karoubi.π' Λ).app X) :=
of_retract (P := epimorphisms _) (karoubi.retractArrow Λ X)
(epimorphisms.infer_property _)
/-- Auxiliary definition for `LeftResolution.karoubi`. -/
def karoubi.π : karoubi.F Λ ⋙ (functorExtension₂ C A).obj ι ⟶ 𝟭 (Karoubi A) :=
whiskeringLeftObjToKaroubiFullyFaithful.preimage (karoubi.π' Λ)
@[simp]
lemma karoubi.π_app_toKaroubi_obj (X : A) :
(karoubi.π Λ).app ((toKaroubi _).obj X) = (karoubi.π' Λ).app X := by
simp [π, whiskeringLeftObjToKaroubiFullyFaithful]
instance (X : A) : Epi ((karoubi.π Λ).app ((toKaroubi _).obj X)) := by
rw [karoubi.π_app_toKaroubi_obj]
infer_instance
instance (X : Karoubi A) : Epi ((karoubi.π Λ).app X) :=
of_retract (P := epimorphisms _) (NatTrans.retractArrowApp (karoubi.π Λ) X.retract)
(epimorphisms.infer_property _)
/-- Given `ι : C ⥤ A`, this is the extension of `Λ : LeftResolution ι` to
`LeftResolution ((functorExtension₂ C A).obj ι)`, where
`(functorExtension₂ C A).obj ι : Karoubi C ⥤ Karoubi A` is the extension of `ι`. -/
@[simps]
noncomputable def karoubi : LeftResolution ((functorExtension₂ C A).obj ι) where
F := karoubi.F Λ
π := karoubi.π Λ
instance : Λ.karoubi.F.PreservesZeroMorphisms where
section
variable [IsIdempotentComplete A] [IsIdempotentComplete C]
/-- Given an additive functor `ι : C ⥤ A` between idempotent complete categories,
any `Λ : LeftResolution ι` induces a term `Λ.reduced : LeftResolution ι`
such that `Λ.reduced.F` preserves zero morphisms. -/
noncomputable def reduced : LeftResolution ι :=
Λ.karoubi.transport (toKaroubiEquivalence A) (toKaroubiEquivalence C)
((karoubiUniversal₁ C A).unitIso.app _)
instance : Λ.reduced.F.PreservesZeroMorphisms := by
dsimp [reduced, transport]
infer_instance
end
end LeftResolution
end CategoryTheory.Abelian |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/Boundary.lean | 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.lean`, 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.lean`) 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.notMem {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')
@[deprecated (since := "2025-05-23")] alias BoundaryGE.not_mem := BoundaryGE.notMem
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.notMem {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')
@[deprecated (since := "2025-05-23")] alias BoundaryLE.not_mem := BoundaryLE.notMem
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)
lemma next_f [e.IsTruncGE] {j k : ι} (hjk : c.next j = k) : c'.next (e.f j) = e.f k := by
by_cases hj : c'.Rel (e.f j) (c'.next (e.f j))
· obtain ⟨k', hk'⟩ := e.mem_next hj
rw [← hk', e.rel_iff] at hj
rw [← hk', ← c.next_eq' hj, hjk]
· rw [c'.next_eq_self _ hj, ← hjk, c.next_eq_self j]
intro hj'
apply hj
rw [← e.rel_iff] at hj'
simpa only [c'.next_eq' hj'] using hj'
lemma prev_f [e.IsTruncLE] {i j : ι} (hij : c.prev j = i) : c'.prev (e.f j) = e.f i :=
e.op.next_f hij
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)
@[simp] lemma op_boundaryLE_iff {j : ι} : e.op.BoundaryLE j ↔ e.BoundaryGE j := by rfl
@[simp] lemma op_boundaryGE_iff {j : ι} : e.op.BoundaryGE j ↔ e.BoundaryLE j := by rfl
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
cutsat
· rintro rfl
constructor
· simp
· intro i hi
dsimp at hi
cutsat
lemma boundaryLE_embeddingUpIntLE_iff (p : ℤ) (n : ℕ) :
(embeddingUpIntLE p).BoundaryLE n ↔ n = 0 := by
constructor
· intro h
obtain _ | n := n
· rfl
· have := h.2 n
dsimp at this
cutsat
· rintro rfl
constructor
· simp
· intro i hi
dsimp at hi
cutsat
end ComplexShape |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/Restriction.lean | 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]
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/TruncGEHomology.lean | import Mathlib.Algebra.Homology.Embedding.ExtendHomology
import Mathlib.Algebra.Homology.Embedding.TruncGE
import Mathlib.Algebra.Homology.Embedding.RestrictionHomology
import Mathlib.Algebra.Homology.QuasiIso
/-! # The homology of a canonical truncation
Given an embedding of complex shapes `e : Embedding c c'`,
we relate the homology of `K : HomologicalComplex C c'` and of
`K.truncGE e : HomologicalComplex C c'`.
The main result is that `K.πTruncGE e : K ⟶ K.truncGE e` induces a
quasi-isomorphism in degree `e.f i` for all `i`. (Note that the complex
`K.truncGE e` is exact in degrees that are not in the image of `e.f`.)
-/
open CategoryTheory Category Limits
namespace HomologicalComplex
variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'}
{C : Type*} [Category C] [HasZeroMorphisms C]
(K L : HomologicalComplex C c') (φ : K ⟶ L) (e : c.Embedding c') [e.IsTruncGE]
[∀ i', K.HasHomology i'] [∀ i', L.HasHomology i']
namespace truncGE'
variable (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k)
include hi hk in
lemma hasHomology_sc'_of_not_mem_boundary (hj : ¬ e.BoundaryGE j) :
((K.truncGE' e).sc' i j k).HasHomology := by
have : (K.restriction e).HasHomology j :=
restriction.hasHomology K e i j k hi hk rfl rfl rfl
(e.prev_f_of_not_boundaryGE hi hj) (e.next_f hk)
have := ShortComplex.hasHomology_of_iso ((K.restriction e).isoSc' i j k hi hk)
let φ := (shortComplexFunctor' C c i j k).map (K.restrictionToTruncGE' e)
have : Epi φ.τ₁ := by dsimp [φ]; infer_instance
have : IsIso φ.τ₂ := K.isIso_restrictionToTruncGE' e j hj
have : IsIso φ.τ₃ := K.isIso_restrictionToTruncGE' e k (e.not_boundaryGE_next' hj hk)
exact ShortComplex.hasHomology_of_epi_of_isIso_of_mono φ
lemma hasHomology_of_not_mem_boundary (hj : ¬ e.BoundaryGE j) :
(K.truncGE' e).HasHomology j :=
hasHomology_sc'_of_not_mem_boundary K e _ j _ rfl rfl hj
/-- `K.restrictionToTruncGE' e` is a quasi-isomorphism in degrees that are not at the boundary. -/
lemma quasiIsoAt_restrictionToTruncGE' (hj : ¬ e.BoundaryGE j)
[(K.restriction e).HasHomology j] [(K.truncGE' e).HasHomology j] :
QuasiIsoAt (K.restrictionToTruncGE' e) j := by
rw [quasiIsoAt_iff]
let φ := (shortComplexFunctor C c j).map (K.restrictionToTruncGE' e)
have : Epi φ.τ₁ := by dsimp [φ]; infer_instance
have : IsIso φ.τ₂ := K.isIso_restrictionToTruncGE' e j hj
have : IsIso φ.τ₃ := K.isIso_restrictionToTruncGE' e _ (e.not_boundaryGE_next' hj rfl)
exact ShortComplex.quasiIso_of_epi_of_isIso_of_mono φ
section
variable {j' : ι'} (hj' : e.f j = j') (hj : e.BoundaryGE j)
lemma homologyι_truncGE'XIsoOpcycles_inv_d :
(K.homologyι j' ≫ (K.truncGE'XIsoOpcycles e hj' hj).inv) ≫ (K.truncGE' e).d j k = 0 := by
by_cases hjk : c.Rel j k
· rw [K.truncGE'_d_eq_fromOpcycles e hjk hj' rfl hj, assoc, Iso.inv_hom_id_assoc,
homologyι_comp_fromOpcycles_assoc, zero_comp]
· rw [shape _ _ _ hjk, comp_zero]
/-- Auxiliary definition for `truncGE'.homologyData`. -/
noncomputable def isLimitKernelFork :
IsLimit (KernelFork.ofι _ (homologyι_truncGE'XIsoOpcycles_inv_d K e j k hj' hj)) := by
have hk' : c'.next j' = e.f k := by simpa only [hj'] using e.next_f hk
by_cases hjk : c.Rel j k
· let e : parallelPair ((K.truncGE' e).d j k) 0 ≅
parallelPair (K.fromOpcycles j' (e.f k)) 0 :=
parallelPair.ext (K.truncGE'XIsoOpcycles e hj' hj)
(K.truncGE'XIso e rfl (e.not_boundaryGE_next hjk))
(by simp [K.truncGE'_d_eq_fromOpcycles e hjk hj' rfl hj]) (by simp)
exact (IsLimit.postcomposeHomEquiv e _).1
(IsLimit.ofIsoLimit (K.homologyIsKernel _ _ hk')
(Fork.ext (Iso.refl _) (by simp [e, Fork.ι])))
· have := K.isIso_homologyι _ _ hk'
(shape _ _ _ (by simpa only [← hj', e.rel_iff] using hjk))
exact IsLimit.ofIsoLimit (KernelFork.IsLimit.ofId _ (shape _ _ _ hjk))
(Fork.ext ((truncGE'XIsoOpcycles K e hj' hj) ≪≫ (asIso (K.homologyι j')).symm))
/-- When `j` is at the boundary of the embedding `e` of complex shapes,
this is a homology data for `K.truncGE' e` in degree `j`: the homology is
given by `K.homology j'` where `e.f j = j'`. -/
noncomputable def homologyData :
((K.truncGE' e).sc' i j k).HomologyData :=
ShortComplex.HomologyData.ofIsLimitKernelFork _
((K.truncGE' e).shape _ _ (fun hij => e.not_boundaryGE_next hij hj)) _
(isLimitKernelFork K e j k hk hj' hj)
/-- Computation of the `right.g'` field of `truncGE'.homologyData K e i j k hk hj' hj`. -/
@[simp]
lemma homologyData_right_g' :
(homologyData K e i j k hk hj' hj).right.g' = (K.truncGE' e).d j k := rfl
end
instance truncGE'_hasHomology (i : ι) : (K.truncGE' e).HasHomology i := by
by_cases hi : e.BoundaryGE i
· exact ShortComplex.HasHomology.mk' (homologyData K e _ _ _ rfl rfl hi)
· exact hasHomology_of_not_mem_boundary K e i hi
end truncGE'
variable [HasZeroObject C]
namespace truncGE
instance (i' : ι') : (K.truncGE e).HasHomology i' := by
dsimp [truncGE]
infer_instance
/-- The right homology data which allows to show that `K.πTruncGE e`
induces an isomorphism in homology in degrees `j'` such that `e.f j = j'` for some `j`. -/
@[simps]
noncomputable def rightHomologyMapData {i j k : ι} {j' : ι'} (hj' : e.f j = j')
(hi : c.prev j = i) (hk : c.next j = k) (hj : e.BoundaryGE j) :
ShortComplex.RightHomologyMapData ((shortComplexFunctor C c' j').map (K.πTruncGE e))
(ShortComplex.RightHomologyData.canonical (K.sc j'))
(extend.rightHomologyData (K.truncGE' e) e hj' hi rfl hk rfl
(truncGE'.homologyData K e i j k hk hj' hj).right) where
φQ := (K.truncGE'XIsoOpcycles e hj' hj).inv
φH := 𝟙 _
commp := by
change K.pOpcycles j' ≫ _ = _
simp [truncGE'.homologyData, πTruncGE, e.liftExtend_f _ _ hj',
K.restrictionToTruncGE'_f_eq_iso_hom_pOpcycles_iso_inv e hj' hj]
commg' := by
have hk' : e.f k = c'.next j' := by rw [← hj', e.next_f hk]
dsimp
rw [extend.rightHomologyData_g' _ _ _ _ _ _ _ _ hk', πTruncGE,
e.liftExtend_f _ _ hk', truncGE'.homologyData_right_g']
by_cases hjk : c.Rel j k
· simp [K.truncGE'_d_eq_fromOpcycles e hjk hj' hk' hj,
K.restrictionToTruncGE'_f_eq_iso_hom_iso_inv e hk' (e.not_boundaryGE_next hjk)]
rfl
· obtain rfl : k = j := by rw [← c.next_eq_self j (by simpa only [hk] using hjk), hk]
rw [shape _ _ _ hjk, zero_comp, comp_zero,
K.restrictionToTruncGE'_f_eq_iso_hom_pOpcycles_iso_inv e hk' hj]
simp only [restriction_X, restrictionXIso, eqToIso.inv, eqToIso.hom, assoc,
eqToHom_trans_assoc, eqToHom_refl, id_comp]
change 0 = K.fromOpcycles _ _ ≫ _
rw [← cancel_epi (K.pOpcycles _), comp_zero, p_fromOpcycles_assoc,
d_pOpcycles_assoc, zero_comp]
end truncGE
lemma quasiIsoAt_πTruncGE {j : ι} {j' : ι'} (hj' : e.f j = j') :
QuasiIsoAt (K.πTruncGE e) j' := by
rw [quasiIsoAt_iff]
by_cases hj : e.BoundaryGE j
· rw [(truncGE.rightHomologyMapData K e hj' rfl rfl hj).quasiIso_iff]
dsimp
infer_instance
· let φ := (shortComplexFunctor C c' j').map (K.πTruncGE e)
have : Epi φ.τ₁ := by
by_cases hi : ∃ i, e.f i = c'.prev j'
· obtain ⟨i, hi⟩ := hi
dsimp [φ, πTruncGE]
rw [e.epi_liftExtend_f_iff _ _ hi]
infer_instance
· apply IsZero.epi (isZero_extend_X _ _ _ (by simpa using hi))
have : IsIso φ.τ₂ := by
dsimp [φ, πTruncGE]
rw [e.isIso_liftExtend_f_iff _ _ hj']
exact K.isIso_restrictionToTruncGE' e j hj
have : IsIso φ.τ₃ := by
dsimp [φ, πTruncGE]
have : c'.next j' = e.f (c.next j) := by simpa only [← hj'] using e.next_f rfl
rw [e.isIso_liftExtend_f_iff _ _ this.symm]
exact K.isIso_restrictionToTruncGE' e _ (e.not_boundaryGE_next' hj rfl)
exact ShortComplex.quasiIso_of_epi_of_isIso_of_mono φ
instance (i : ι) : QuasiIsoAt (K.πTruncGE e) (e.f i) := K.quasiIsoAt_πTruncGE e rfl
lemma quasiIso_πTruncGE_iff_isSupported :
QuasiIso (K.πTruncGE e) ↔ K.IsSupported e := by
constructor
· intro
refine ⟨fun i' hi' => ?_⟩
rw [exactAt_iff_of_quasiIsoAt (K.πTruncGE e) i']
exact (K.truncGE e).exactAt_of_isSupported e i' hi'
· intro
rw [quasiIso_iff]
intro i'
by_cases hi' : ∃ i, e.f i = i'
· obtain ⟨i, rfl⟩ := hi'
infer_instance
· rw [quasiIsoAt_iff_exactAt (K.πTruncGE e) i']
all_goals exact exactAt_of_isSupported _ e i' (by simpa using hi')
lemma acyclic_truncGE_iff_isSupportedOutside :
(K.truncGE e).Acyclic ↔ K.IsSupportedOutside e := by
constructor
· intro hK
exact ⟨fun i =>
by simpa only [exactAt_iff_of_quasiIsoAt (K.πTruncGE e)] using hK (e.f i)⟩
· intro hK i'
by_cases hi' : ∃ i, e.f i = i'
· obtain ⟨i, rfl⟩ := hi'
simpa only [← exactAt_iff_of_quasiIsoAt (K.πTruncGE e)] using hK.exactAt i
· exact exactAt_of_isSupported _ e i' (by simpa using hi')
variable {K L}
lemma quasiIso_truncGEMap_iff :
QuasiIso (truncGEMap φ e) ↔ ∀ (i : ι) (i' : ι') (_ : e.f i = i'), QuasiIsoAt φ i' := by
have : ∀ (i : ι) (i' : ι') (_ : e.f i = i'),
QuasiIsoAt (truncGEMap φ e) i' ↔ QuasiIsoAt φ i' := by
rintro i _ rfl
rw [← quasiIsoAt_iff_comp_left (K.πTruncGE e), πTruncGE_naturality φ e,
quasiIsoAt_iff_comp_right]
rw [quasiIso_iff]
constructor
· intro h i i' hi
simpa only [← this i i' hi] using h i'
· intro h i'
by_cases hi' : ∃ i, e.f i = i'
· obtain ⟨i, hi⟩ := hi'
simpa only [this i i' hi] using h i i' hi
· rw [quasiIsoAt_iff_exactAt]
all_goals exact exactAt_of_isSupported _ e i' (by simpa using hi')
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/CochainComplex.lean | import Mathlib.Algebra.Homology.Embedding.AreComplementary
import Mathlib.Algebra.Homology.HomotopyCategory.SingleFunctors
import Mathlib.Algebra.Homology.HomotopyCategory.ShiftSequence
/-!
# Truncations on cochain complexes indexed by the integers.
In this file, we introduce abbreviations for the canonical truncations
`CochainComplex.truncLE`, `CochainComplex.truncGE` of cochain
complexes indexed by `ℤ`, as well as the conditions
`CochainComplex.IsStrictlyLE`, `CochainComplex.IsStrictlyGE`,
`CochainComplex.IsLE`, and `CochainComplex.IsGE`.
-/
open CategoryTheory Category Limits ComplexShape ZeroObject
namespace CochainComplex
variable {C : Type*} [Category C]
open HomologicalComplex
section HasZeroMorphisms
variable [HasZeroMorphisms C] (K L : CochainComplex C ℤ) (φ : K ⟶ L) (e : K ≅ L)
section
variable [HasZeroObject C] [∀ i, K.HasHomology i] [∀ i, L.HasHomology i]
/-- If `K : CochainComplex C ℤ`, this is the canonical truncation `≤ n` of `K`. -/
noncomputable abbrev truncLE (n : ℤ) : CochainComplex C ℤ :=
HomologicalComplex.truncLE K (embeddingUpIntLE n)
/-- If `K : CochainComplex C ℤ`, this is the canonical truncation `≥ n` of `K`. -/
noncomputable abbrev truncGE (n : ℤ) : CochainComplex C ℤ :=
HomologicalComplex.truncGE K (embeddingUpIntGE n)
/-- The canonical map `K.truncLE n ⟶ K` for `K : CochainComplex C ℤ`. -/
noncomputable def ιTruncLE (n : ℤ) : K.truncLE n ⟶ K :=
HomologicalComplex.ιTruncLE K (embeddingUpIntLE n)
/-- The canonical map `K ⟶ K.truncGE n` for `K : CochainComplex C ℤ`. -/
noncomputable def πTruncGE (n : ℤ) : K ⟶ K.truncGE n :=
HomologicalComplex.πTruncGE K (embeddingUpIntGE n)
section
variable {K L}
/-- The morphism `K.truncLE n ⟶ L.truncLE n` induced by a morphism `K ⟶ L`. -/
noncomputable abbrev truncLEMap (n : ℤ) : K.truncLE n ⟶ L.truncLE n :=
HomologicalComplex.truncLEMap φ (embeddingUpIntLE n)
/-- The morphism `K.truncGE n ⟶ L.truncGE n` induced by a morphism `K ⟶ L`. -/
noncomputable abbrev truncGEMap (n : ℤ) : K.truncGE n ⟶ L.truncGE n :=
HomologicalComplex.truncGEMap φ (embeddingUpIntGE n)
@[reassoc (attr := simp)]
lemma ιTruncLE_naturality (n : ℤ) :
truncLEMap φ n ≫ L.ιTruncLE n = K.ιTruncLE n ≫ φ := by
apply HomologicalComplex.ιTruncLE_naturality
@[reassoc (attr := simp)]
lemma πTruncGE_naturality (n : ℤ) :
K.πTruncGE n ≫ truncGEMap φ n = φ ≫ L.πTruncGE n := by
apply HomologicalComplex.πTruncGE_naturality
end
end
/-- The condition that a cochain complex `K` is strictly `≥ n`. -/
abbrev IsStrictlyGE (n : ℤ) := K.IsStrictlySupported (embeddingUpIntGE n)
/-- The condition that a cochain complex `K` is strictly `≤ n`. -/
abbrev IsStrictlyLE (n : ℤ) := K.IsStrictlySupported (embeddingUpIntLE n)
/-- The condition that a cochain complex `K` is (cohomologically) `≥ n`. -/
abbrev IsGE (n : ℤ) := K.IsSupported (embeddingUpIntGE n)
/-- The condition that a cochain complex `K` is (cohomologically) `≤ n`. -/
abbrev IsLE (n : ℤ) := K.IsSupported (embeddingUpIntLE n)
lemma isZero_of_isStrictlyGE (n i : ℤ) (hi : i < n) [K.IsStrictlyGE n] :
IsZero (K.X i) :=
isZero_X_of_isStrictlySupported K (embeddingUpIntGE n) i
(by simpa only [notMem_range_embeddingUpIntGE_iff] using hi)
lemma isZero_of_isStrictlyLE (n i : ℤ) (hi : n < i) [K.IsStrictlyLE n] :
IsZero (K.X i) :=
isZero_X_of_isStrictlySupported K (embeddingUpIntLE n) i
(by simpa only [notMem_range_embeddingUpIntLE_iff] using hi)
lemma exactAt_of_isGE (n i : ℤ) (hi : i < n) [K.IsGE n] :
K.ExactAt i :=
exactAt_of_isSupported K (embeddingUpIntGE n) i
(by simpa only [notMem_range_embeddingUpIntGE_iff] using hi)
lemma exactAt_of_isLE (n i : ℤ) (hi : n < i) [K.IsLE n] :
K.ExactAt i :=
exactAt_of_isSupported K (embeddingUpIntLE n) i
(by simpa only [notMem_range_embeddingUpIntLE_iff] using hi)
lemma isZero_of_isGE (n i : ℤ) (hi : i < n) [K.IsGE n] [K.HasHomology i] :
IsZero (K.homology i) :=
(K.exactAt_of_isGE n i hi).isZero_homology
lemma isZero_of_isLE (n i : ℤ) (hi : n < i) [K.IsLE n] [K.HasHomology i] :
IsZero (K.homology i) :=
(K.exactAt_of_isLE n i hi).isZero_homology
lemma isStrictlyGE_iff (n : ℤ) :
K.IsStrictlyGE n ↔ ∀ (i : ℤ) (_ : i < n), IsZero (K.X i) := by
constructor
· intro _ i hi
exact K.isZero_of_isStrictlyGE n i hi
· intro h
refine IsStrictlySupported.mk (fun i hi ↦ ?_)
rw [notMem_range_embeddingUpIntGE_iff] at hi
exact h i hi
lemma isStrictlyLE_iff (n : ℤ) :
K.IsStrictlyLE n ↔ ∀ (i : ℤ) (_ : n < i), IsZero (K.X i) := by
constructor
· intro _ i hi
exact K.isZero_of_isStrictlyLE n i hi
· intro h
refine IsStrictlySupported.mk (fun i hi ↦ ?_)
rw [notMem_range_embeddingUpIntLE_iff] at hi
exact h i hi
lemma isGE_iff (n : ℤ) :
K.IsGE n ↔ ∀ (i : ℤ) (_ : i < n), K.ExactAt i := by
constructor
· intro _ i hi
exact K.exactAt_of_isGE n i hi
· intro h
refine IsSupported.mk (fun i hi ↦ ?_)
rw [notMem_range_embeddingUpIntGE_iff] at hi
exact h i hi
lemma isLE_iff (n : ℤ) :
K.IsLE n ↔ ∀ (i : ℤ) (_ : n < i), K.ExactAt i := by
constructor
· intro _ i hi
exact K.exactAt_of_isLE n i hi
· intro h
refine IsSupported.mk (fun i hi ↦ ?_)
rw [notMem_range_embeddingUpIntLE_iff] at hi
exact h i hi
lemma isStrictlyLE_of_le (p q : ℤ) (hpq : p ≤ q) [K.IsStrictlyLE p] :
K.IsStrictlyLE q := by
rw [isStrictlyLE_iff]
intro i hi
apply K.isZero_of_isStrictlyLE p
cutsat
lemma isStrictlyGE_of_ge (p q : ℤ) (hpq : p ≤ q) [K.IsStrictlyGE q] :
K.IsStrictlyGE p := by
rw [isStrictlyGE_iff]
intro i hi
apply K.isZero_of_isStrictlyGE q
cutsat
lemma isLE_of_le (p q : ℤ) (hpq : p ≤ q) [K.IsLE p] :
K.IsLE q := by
rw [isLE_iff]
intro i hi
apply K.exactAt_of_isLE p
cutsat
lemma isGE_of_ge (p q : ℤ) (hpq : p ≤ q) [K.IsGE q] :
K.IsGE p := by
rw [isGE_iff]
intro i hi
apply K.exactAt_of_isGE q
cutsat
section
variable {K L}
include e
lemma isStrictlyLE_of_iso (n : ℤ) [K.IsStrictlyLE n] : L.IsStrictlyLE n := by
apply isStrictlySupported_of_iso e
lemma isStrictlyGE_of_iso (n : ℤ) [K.IsStrictlyGE n] : L.IsStrictlyGE n := by
apply isStrictlySupported_of_iso e
lemma isLE_of_iso (n : ℤ) [K.IsLE n] : L.IsLE n := by
apply isSupported_of_iso e
lemma isGE_of_iso (n : ℤ) [K.IsGE n] : L.IsGE n := by
apply isSupported_of_iso e
end
section
variable [HasZeroObject C]
/-- A cochain complex that is both strictly `≤ n` and `≥ n` is isomorphic to
a complex `(single _ _ n).obj M` for some object `M`. -/
lemma exists_iso_single (n : ℤ) [K.IsStrictlyGE n] [K.IsStrictlyLE n] :
∃ (M : C), Nonempty (K ≅ (single _ _ n).obj M) :=
⟨K.X n, ⟨{
hom := mkHomToSingle (𝟙 _) (fun i (hi : i + 1 = n) ↦
(K.isZero_of_isStrictlyGE n i (by cutsat)).eq_of_src _ _)
inv := mkHomFromSingle (𝟙 _) (fun i (hi : n + 1 = i) ↦
(K.isZero_of_isStrictlyLE n i (by cutsat)).eq_of_tgt _ _)
hom_inv_id := by
ext i
obtain hi | rfl | hi := lt_trichotomy i n
· apply (K.isZero_of_isStrictlyGE n i (by cutsat)).eq_of_src
· simp
· apply (K.isZero_of_isStrictlyLE n i (by cutsat)).eq_of_tgt
inv_hom_id := by aesop }⟩⟩
instance (A : C) (n : ℤ) :
IsStrictlyGE ((single C (ComplexShape.up ℤ) n).obj A) n := by
rw [isStrictlyGE_iff]
intro i hi
exact isZero_single_obj_X _ _ _ _ (by cutsat)
instance (A : C) (n : ℤ) :
IsStrictlyLE ((single C (ComplexShape.up ℤ) n).obj A) n := by
rw [isStrictlyLE_iff]
intro i hi
exact isZero_single_obj_X _ _ _ _ (by cutsat)
variable [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] (n : ℤ)
instance [K.IsStrictlyGE n] : IsIso (K.πTruncGE n) := by dsimp [πTruncGE]; infer_instance
instance [K.IsStrictlyLE n] : IsIso (K.ιTruncLE n) := by dsimp [ιTruncLE]; infer_instance
lemma isIso_πTruncGE_iff : IsIso (K.πTruncGE n) ↔ K.IsStrictlyGE n := by
apply HomologicalComplex.isIso_πTruncGE_iff
lemma isIso_ιTruncLE_iff : IsIso (K.ιTruncLE n) ↔ K.IsStrictlyLE n := by
apply HomologicalComplex.isIso_ιTruncLE_iff
lemma quasiIso_πTruncGE_iff : QuasiIso (K.πTruncGE n) ↔ K.IsGE n :=
quasiIso_πTruncGE_iff_isSupported K (embeddingUpIntGE n)
lemma quasiIso_ιTruncLE_iff : QuasiIso (K.ιTruncLE n) ↔ K.IsLE n :=
quasiIso_ιTruncLE_iff_isSupported K (embeddingUpIntLE n)
instance [K.IsGE n] : QuasiIso (K.πTruncGE n) := by
rw [quasiIso_πTruncGE_iff]
infer_instance
instance [K.IsLE n] : QuasiIso (K.ιTruncLE n) := by
rw [quasiIso_ιTruncLE_iff]
infer_instance
variable {K L}
lemma quasiIso_truncGEMap_iff :
QuasiIso (truncGEMap φ n) ↔ ∀ (i : ℤ) (_ : n ≤ i), QuasiIsoAt φ i := by
rw [HomologicalComplex.quasiIso_truncGEMap_iff]
constructor
· intro h i hi
obtain ⟨k, rfl⟩ := Int.le.dest hi
exact h k _ rfl
· rintro h i i' rfl
exact h _ (by dsimp; cutsat)
lemma quasiIso_truncLEMap_iff :
QuasiIso (truncLEMap φ n) ↔ ∀ (i : ℤ) (_ : i ≤ n), QuasiIsoAt φ i := by
rw [HomologicalComplex.quasiIso_truncLEMap_iff]
constructor
· intro h i hi
obtain ⟨k, rfl⟩ := Int.le.dest hi
exact h k _ (by dsimp; cutsat)
· rintro h i i' rfl
exact h _ (by dsimp; cutsat)
end
end HasZeroMorphisms
section Preadditive
variable [Preadditive C]
instance [HasZeroObject C] (A : C) (n : ℤ) : ((singleFunctor C n).obj A).IsStrictlyGE n :=
inferInstanceAs (IsStrictlyGE ((single C (ComplexShape.up ℤ) n).obj A) n)
instance [HasZeroObject C] (A : C) (n : ℤ) : ((singleFunctor C n).obj A).IsStrictlyLE n :=
inferInstanceAs (IsStrictlyLE ((single C (ComplexShape.up ℤ) n).obj A) n)
variable (K : CochainComplex C ℤ)
lemma isStrictlyLE_shift (n : ℤ) [K.IsStrictlyLE n] (a n' : ℤ) (h : a + n' = n) :
(K⟦a⟧).IsStrictlyLE n' := by
rw [isStrictlyLE_iff]
intro i hi
exact IsZero.of_iso (K.isZero_of_isStrictlyLE n _ (by cutsat)) (K.shiftFunctorObjXIso a i _ rfl)
lemma isStrictlyGE_shift (n : ℤ) [K.IsStrictlyGE n] (a n' : ℤ) (h : a + n' = n) :
(K⟦a⟧).IsStrictlyGE n' := by
rw [isStrictlyGE_iff]
intro i hi
exact IsZero.of_iso (K.isZero_of_isStrictlyGE n _ (by cutsat)) (K.shiftFunctorObjXIso a i _ rfl)
section
variable [CategoryWithHomology C]
lemma isLE_shift (n : ℤ) [K.IsLE n] (a n' : ℤ) (h : a + n' = n) : (K⟦a⟧).IsLE n' := by
rw [isLE_iff]
intro i hi
rw [exactAt_iff_isZero_homology]
exact IsZero.of_iso (K.isZero_of_isLE n (a + i) (by cutsat))
(((homologyFunctor C _ (0 : ℤ)).shiftIso a i _ rfl).app K)
lemma isGE_shift (n : ℤ) [K.IsGE n] (a n' : ℤ) (h : a + n' = n) : (K⟦a⟧).IsGE n' := by
rw [isGE_iff]
intro i hi
rw [exactAt_iff_isZero_homology]
exact IsZero.of_iso (K.isZero_of_isGE n (a + i) (by cutsat))
(((homologyFunctor C _ (0 : ℤ)).shiftIso a i _ rfl).app K)
end
end Preadditive
section Abelian
variable [Abelian C] (K L : CochainComplex C ℤ)
/-- The cokernel sequence of the monomorphism `K.ιTruncLE n`. -/
noncomputable abbrev shortComplexTruncLE (n : ℤ) : ShortComplex (CochainComplex C ℤ) :=
HomologicalComplex.shortComplexTruncLE K (embeddingUpIntLE n)
lemma shortComplexTruncLE_shortExact (n : ℤ) :
(K.shortComplexTruncLE n).ShortExact := by
apply HomologicalComplex.shortComplexTruncLE_shortExact
variable (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁)
/-- The canonical morphism `(K.shortComplexTruncLE n₀).X₃ ⟶ K.truncGE n₁`. -/
noncomputable abbrev shortComplexTruncLEX₃ToTruncGE :
(K.shortComplexTruncLE n₀).X₃ ⟶ K.truncGE n₁ :=
HomologicalComplex.shortComplexTruncLEX₃ToTruncGE K
(Embedding.embeddingUpInt_areComplementary n₀ n₁ h)
@[reassoc]
lemma g_shortComplexTruncLEX₃ToTruncGE :
(K.shortComplexTruncLE n₀).g ≫ K.shortComplexTruncLEX₃ToTruncGE n₀ n₁ h = K.πTruncGE n₁ := by
apply HomologicalComplex.g_shortComplexTruncLEX₃ToTruncGE
end Abelian
end CochainComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/Basic.lean | import Mathlib.Algebra.Homology.ComplexShape
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Tactic.ByContra
/-! # 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).
## Description of the API
- The extension functor `e.extendFunctor C : HomologicalComplex C c ⥤ HomologicalComplex C c'`
(extending by the zero object outside of the image of `e.f`) is defined in
the file `Embedding.Extend`;
- assuming `e.IsRelIff`, the restriction functor
`e.restrictionFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c`
is defined in the file `Embedding.Restriction`;
- the stupid truncation functor
`e.stupidTruncFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c'`
which is the composition of the two previous functors is defined in the file
`Embedding.StupidTrunc`.
- assuming `e.IsTruncGE`, we have truncation functors
`e.truncGE'Functor C : HomologicalComplex C c' ⥤ HomologicalComplex C c` and
`e.truncGEFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c'`
(see the file `Embedding.TruncGE`), and a natural
transformation `e.πTruncGENatTrans : 𝟭 _ ⟶ e.truncGEFunctor C` which is a quasi-isomorphism
in degrees in the image of `e.f` (TODO);
- assuming `e.IsTruncLE`, we have 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` (TODO);
-/
assert_not_exists Nat.instAddMonoidWithOne Nat.instMulZeroClass
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 compatibility 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
instance [e.IsRelIff] : e.op.IsRelIff where
rel' i₁ i₂ h := (e.rel_iff i₂ i₁).1 h
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 : Prop extends e.IsRelIff 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 : Prop extends e.IsRelIff 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
instance [e.IsTruncGE] : e.op.IsTruncLE where
mem_prev h := e.mem_next h
instance [e.IsTruncLE] : e.op.IsTruncGE where
mem_next h := e.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
section
variable {A : Type*} [AddCommSemigroup A] [IsRightCancelAdd A] [One A]
/-- The embedding from `up' a` to itself via (· + b). -/
@[simps!]
def embeddingUp'Add (a b : A) : Embedding (up' a) (up' a) :=
Embedding.mk' _ _ (· + b)
(fun _ _ h => by simpa using h)
(by dsimp; simp_rw [add_right_comm _ b a, add_right_cancel_iff, implies_true])
instance (a b : A) : (embeddingUp'Add a b).IsRelIff := by dsimp [embeddingUp'Add]; infer_instance
instance (a b : A) : (embeddingUp'Add a b).IsTruncGE where
mem_next {j _} h := ⟨j + a, (add_right_comm _ _ _).trans h⟩
/-- The embedding from `down' a` to itself via (· + b). -/
@[simps!]
def embeddingDown'Add (a b : A) : Embedding (down' a) (down' a) :=
Embedding.mk' _ _ (· + b)
(fun _ _ h => by simpa using h)
(by dsimp; simp_rw [add_right_comm _ b a, add_right_cancel_iff, implies_true])
instance (a b : A) : (embeddingDown'Add a b).IsRelIff := by
dsimp [embeddingDown'Add]; infer_instance
instance (a b : A) : (embeddingDown'Add a b).IsTruncLE where
mem_prev {_ x} h := ⟨x + a, (add_right_comm _ _ _).trans h⟩
end
/-- 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; cutsat)
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; cutsat)
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; cutsat)
(by dsimp; cutsat)
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; cutsat)
(by dsimp; cutsat)
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⟩
lemma notMem_range_embeddingUpIntLE_iff (n : ℤ) :
(∀ (i : ℕ), (embeddingUpIntLE p).f i ≠ n) ↔ p < n := by
constructor
· intro h
by_contra!
exact h (p - n).natAbs (by simp; cutsat)
· intros
dsimp
cutsat
@[deprecated (since := "2025-05-23")]
alias not_mem_range_embeddingUpIntLE_iff := notMem_range_embeddingUpIntLE_iff
lemma notMem_range_embeddingUpIntGE_iff (n : ℤ) :
(∀ (i : ℕ), (embeddingUpIntGE p).f i ≠ n) ↔ n < p := by
constructor
· intro h
by_contra!
exact h (n - p).natAbs (by simp; cutsat)
· intros
dsimp
cutsat
@[deprecated (since := "2025-05-23")]
alias not_mem_range_embeddingUpIntGE_iff := notMem_range_embeddingUpIntGE_iff
end ComplexShape |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/TruncLE.lean | import Mathlib.Algebra.Homology.Embedding.TruncGE
/-!
# The canonical truncation
Given an embedding `e : Embedding c c'` of complex shapes which
satisfies `e.IsTruncLE` and `K : HomologicalComplex C c'`,
we define `K.truncGE' e : HomologicalComplex C c`
and `K.truncLE e : HomologicalComplex C c'` which are the canonical
truncations of `K` relative to `e`.
In order to achieve this, we dualize the constructions from the file
`Embedding.TruncGE`.
-/
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.IsTruncLE]
[∀ i', K.HasHomology i'] [∀ i', L.HasHomology i'] [∀ i', M.HasHomology i']
/-- The canonical truncation of a homological complex relative to an embedding
of complex shapes `e` which satisfies `e.IsTruncLE`. -/
noncomputable def truncLE' : HomologicalComplex C c := (K.op.truncGE' e.op).unop
/-- The isomorphism `(K.truncLE' e).X i ≅ K.X i'` when `e.f i = i'`
and `e.BoundaryLE i` does not hold. -/
noncomputable def truncLE'XIso {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : ¬ e.BoundaryLE i) :
(K.truncLE' e).X i ≅ K.X i' :=
(K.op.truncGE'XIso e.op hi' (by simpa)).symm.unop
/-- The isomorphism `(K.truncLE' e).X i ≅ K.cycles i'` when `e.f i = i'`
and `e.BoundaryLE i` holds. -/
noncomputable def truncLE'XIsoCycles {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : e.BoundaryLE i) :
(K.truncLE' e).X i ≅ K.cycles i' :=
(K.op.truncGE'XIsoOpcycles e.op hi' (by simpa)).unop.symm ≪≫
(K.opcyclesOpIso i').unop.symm
lemma truncLE'_d_eq {i j : ι} (hij : c.Rel i j) {i' j' : ι'}
(hi' : e.f i = i') (hj' : e.f j = j') (hj : ¬ e.BoundaryLE j) :
(K.truncLE' e).d i j = (K.truncLE'XIso e hi' (e.not_boundaryLE_prev hij)).hom ≫ K.d i' j' ≫
(K.truncLE'XIso e hj' hj).inv :=
Quiver.Hom.op_inj (by simpa using K.op.truncGE'_d_eq e.op hij hj' hi' (by simpa))
lemma truncLE'_d_eq_toCycles {i j : ι} (hij : c.Rel i j) {i' j' : ι'}
(hi' : e.f i = i') (hj' : e.f j = j') (hj : e.BoundaryLE j) :
(K.truncLE' e).d i j = (K.truncLE'XIso e hi' (e.not_boundaryLE_prev hij)).hom ≫
K.toCycles i' j' ≫ (K.truncLE'XIsoCycles e hj' hj).inv :=
Quiver.Hom.op_inj (by
simpa [truncLE', truncLE'XIso, truncLE'XIsoCycles]
using K.op.truncGE'_d_eq_fromOpcycles e.op hij hj' hi' (by simpa))
section
variable [HasZeroObject C]
/-- The canonical truncation of a homological complex relative to an embedding
of complex shapes `e` which satisfies `e.IsTruncLE`. -/
noncomputable def truncLE : HomologicalComplex C c' := (K.op.truncGE e.op).unop
/-- The canonical isomorphism `K.truncLE e ≅ (K.truncLE' e).extend e`. -/
noncomputable def truncLEIso : K.truncLE e ≅ (K.truncLE' e).extend e :=
(unopFunctor C c'.symm).mapIso ((K.truncLE' e).extendOpIso e).symm.op
/-- The isomorphism `(K.truncLE e).X i' ≅ K.X i'` when `e.f i = i'`
and `e.BoundaryLE i` does not hold. -/
noncomputable def truncLEXIso {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : ¬ e.BoundaryLE i) :
(K.truncLE e).X i' ≅ K.X i' :=
(K.op.truncGEXIso e.op hi' (by simpa)).unop.symm
/-- The isomorphism `(K.truncLE e).X i' ≅ K.cycles i'` when `e.f i = i'`
and `e.BoundaryLE i` holds. -/
noncomputable def truncLEXIsoCycles {i : ι} {i' : ι'} (hi' : e.f i = i') (hi : e.BoundaryLE i) :
(K.truncLE e).X i' ≅ K.cycles i' :=
(K.op.truncGEXIsoOpcycles e.op hi' (by simpa)).unop.symm ≪≫
(K.opcyclesOpIso i').unop.symm
end
section
variable {K L M}
/-- The morphism `K.truncLE' e ⟶ L.truncLE' e` induced by a morphism `K ⟶ L`. -/
noncomputable def truncLE'Map : K.truncLE' e ⟶ L.truncLE' e :=
(unopFunctor C c.symm).map (truncGE'Map ((opFunctor C c').map φ.op) e.op).op
lemma truncLE'Map_f_eq_cyclesMap {i : ι} (hi : e.BoundaryLE i) {i' : ι'} (h : e.f i = i') :
(truncLE'Map φ e).f i =
(K.truncLE'XIsoCycles e h hi).hom ≫ cyclesMap φ i' ≫
(L.truncLE'XIsoCycles e h hi).inv := by
apply Quiver.Hom.op_inj
dsimp [truncLE'Map, truncLE'XIsoCycles]
rw [assoc, assoc, truncGE'Map_f_eq_opcyclesMap _ e.op (by simpa) h,
opcyclesOpIso_inv_naturality_assoc, Iso.hom_inv_id_assoc]
lemma truncLE'Map_f_eq {i : ι} (hi : ¬ e.BoundaryLE i) {i' : ι'} (h : e.f i = i') :
(truncLE'Map φ e).f i =
(K.truncLE'XIso e h hi).hom ≫ φ.f i' ≫ (L.truncLE'XIso e h hi).inv :=
Quiver.Hom.op_inj
(by simpa using truncGE'Map_f_eq ((opFunctor C c').map φ.op) e.op (by simpa) h)
variable (K) in
@[simp]
lemma truncLE'Map_id : truncLE'Map (𝟙 K) e = 𝟙 _ :=
(unopFunctor C c.symm).congr_map (congr_arg Quiver.Hom.op (K.op.truncGE'Map_id e.op))
@[reassoc, simp]
lemma truncLE'Map_comp : truncLE'Map (φ ≫ φ') e = truncLE'Map φ e ≫ truncLE'Map φ' e :=
(unopFunctor C c.symm).congr_map (congr_arg Quiver.Hom.op
(truncGE'Map_comp ((opFunctor C c').map φ'.op) ((opFunctor C c').map φ.op) e.op))
variable [HasZeroObject C]
/-- The morphism `K.truncLE e ⟶ L.truncLE e` induced by a morphism `K ⟶ L`. -/
noncomputable def truncLEMap : K.truncLE e ⟶ L.truncLE e :=
(unopFunctor C c'.symm).map (truncGEMap ((opFunctor C c').map φ.op) e.op).op
variable (K) in
@[simp]
lemma truncLEMap_id : truncLEMap (𝟙 K) e = 𝟙 _ :=
(unopFunctor C c'.symm).congr_map (congr_arg Quiver.Hom.op (K.op.truncGEMap_id e.op))
@[reassoc, simp]
lemma truncLEMap_comp : truncLEMap (φ ≫ φ') e = truncLEMap φ e ≫ truncLEMap φ' e :=
(unopFunctor C c'.symm).congr_map (congr_arg Quiver.Hom.op
(truncGEMap_comp ((opFunctor C c').map φ'.op) ((opFunctor C c').map φ.op) e.op))
end
/-- The canonical morphism `K.truncLE' e ⟶ K.restriction e`. -/
noncomputable def truncLE'ToRestriction : K.truncLE' e ⟶ K.restriction e :=
(unopFunctor C c.symm).map (K.op.restrictionToTruncGE' e.op).op
/-- `(K.truncLE'ToRestriction e).f i` is an isomorphism when `¬ e.BoundaryLE i`. -/
lemma isIso_truncLE'ToRestriction (i : ι) (hi : ¬ e.BoundaryLE i) :
IsIso ((K.truncLE'ToRestriction e).f i) := by
change IsIso ((K.op.restrictionToTruncGE' e.op).f i).unop
have := K.op.isIso_restrictionToTruncGE' e.op i (by simpa)
infer_instance
variable {K L} in
@[reassoc (attr := simp)]
lemma truncLE'ToRestriction_naturality :
truncLE'Map φ e ≫ L.truncLE'ToRestriction e =
K.truncLE'ToRestriction e ≫ restrictionMap φ e :=
(unopFunctor C c.symm).congr_map (congr_arg Quiver.Hom.op
(restrictionToTruncGE'_naturality ((opFunctor C c').map φ.op) e.op))
instance (i : ι) : Mono ((K.truncLE'ToRestriction e).f i) :=
inferInstanceAs (Mono ((K.op.restrictionToTruncGE' e.op).f i).unop)
instance [K.IsStrictlySupported e] (i : ι) :
IsIso ((K.truncLE'ToRestriction e).f i) :=
inferInstanceAs (IsIso ((K.op.restrictionToTruncGE' e.op).f i).unop)
section
variable [HasZeroObject C]
/-- The canonical morphism `K.truncLE e ⟶ K` when `e` is an embedding of complex
shapes which satisfy `e.IsTruncLE`. -/
noncomputable def ιTruncLE : K.truncLE e ⟶ K :=
(unopFunctor C c'.symm).map (K.op.πTruncGE e.op).op
instance (i' : ι') : Mono ((K.ιTruncLE e).f i') :=
inferInstanceAs (Mono ((K.op.πTruncGE e.op).f i').unop)
instance : Mono (K.ιTruncLE e) := mono_of_mono_f _ (fun _ => inferInstance)
instance : (K.truncLE e).IsStrictlySupported e := by
rw [← isStrictlySupported_op_iff]
exact inferInstanceAs ((K.op.truncGE e.op).IsStrictlySupported e.op)
variable {K L} in
@[reassoc (attr := simp)]
lemma ιTruncLE_naturality :
truncLEMap φ e ≫ L.ιTruncLE e = K.ιTruncLE e ≫ φ :=
(unopFunctor C c'.symm).congr_map (congr_arg Quiver.Hom.op
(πTruncGE_naturality ((opFunctor C c').map φ.op) e.op))
instance {ι'' : Type*} {c'' : ComplexShape ι''} (e' : c''.Embedding c')
[K.IsStrictlySupported e'] : (K.truncLE e).IsStrictlySupported e' := by
rw [← isStrictlySupported_op_iff]
exact inferInstanceAs ((K.op.truncGE e.op).IsStrictlySupported e'.op)
instance [K.IsStrictlySupported e] : IsIso (K.ιTruncLE e) :=
inferInstanceAs (IsIso ((unopFunctor C c'.symm).map (K.op.πTruncGE e.op).op))
lemma isIso_ιTruncLE_iff : IsIso (K.ιTruncLE e) ↔ K.IsStrictlySupported e :=
⟨fun _ ↦ isStrictlySupported_of_iso (asIso (K.ιTruncLE e)) e,
fun _ ↦ inferInstance⟩
end
end HomologicalComplex
namespace ComplexShape.Embedding
variable (e : Embedding c c') [e.IsTruncLE]
(C : Type*) [Category C] [HasZeroMorphisms C] [HasZeroObject C] [CategoryWithHomology C]
/-- Given an embedding `e : Embedding c c'` of complex shapes which satisfy `e.IsTruncLE`,
this is the (canonical) truncation functor
`HomologicalComplex C c' ⥤ HomologicalComplex C c`. -/
@[simps]
noncomputable def truncLE'Functor :
HomologicalComplex C c' ⥤ HomologicalComplex C c where
obj K := K.truncLE' e
map φ := HomologicalComplex.truncLE'Map φ e
/-- The natural transformation `K.truncGE' e ⟶ K.restriction e` for all `K`. -/
@[simps]
noncomputable def truncLE'ToRestrictionNatTrans :
e.truncLE'Functor C ⟶ e.restrictionFunctor C where
app K := K.truncLE'ToRestriction e
/-- Given an embedding `e : Embedding c c'` of complex shapes which satisfy `e.IsTruncLE`,
this is the (canonical) truncation functor
`HomologicalComplex C c' ⥤ HomologicalComplex C c'`. -/
@[simps]
noncomputable def truncLEFunctor :
HomologicalComplex C c' ⥤ HomologicalComplex C c' where
obj K := K.truncLE e
map φ := HomologicalComplex.truncLEMap φ e
/-- The natural transformation `K.ιTruncLE e : K.truncLE e ⟶ K` for all `K`. -/
@[simps]
noncomputable def ιTruncLENatTrans : e.truncLEFunctor C ⟶ 𝟭 _ where
app K := K.ιTruncLE e
end ComplexShape.Embedding |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/AreComplementary.lean | import Mathlib.Algebra.Homology.Embedding.TruncLEHomology
/-!
# Complementary embeddings
Given two embeddings `e₁ : c₁.Embedding c` and `e₂ : c₂.Embedding c`
of complex shapes, we introduce a property `e₁.AreComplementary e₂`
saying that the image subsets of the indices of `c₁` and `c₂` form
a partition of the indices of `c`.
If `e₁.IsTruncLE` and `e₂.IsTruncGE`, and `K : HomologicalComplex C c`,
we construct a quasi-isomorphism `shortComplexTruncLEX₃ToTruncGE` between
the cokernel of `K.ιTruncLE e₁ : K.truncLE e₁ ⟶ K` and `K.truncGE e₂`.
-/
open CategoryTheory Limits
variable {ι ι₁ ι₂ : Type*} {c : ComplexShape ι} {c₁ : ComplexShape ι₁} {c₂ : ComplexShape ι₂}
namespace ComplexShape
namespace Embedding
variable {C : Type*} [Category C] [HasZeroMorphisms C]
(e₁ : Embedding c₁ c) (e₂ : Embedding c₂ c)
/-- Two embedding `e₁` and `e₂` into a complex shape `c : ComplexShape ι`
are complementary when the range of `e₁.f` and `e₂.f` form a partition of `ι`. -/
structure AreComplementary : Prop where
disjoint (i₁ : ι₁) (i₂ : ι₂) : e₁.f i₁ ≠ e₂.f i₂
union (i : ι) : (∃ i₁, e₁.f i₁ = i) ∨ ∃ i₂, e₂.f i₂ = i
variable {e₁ e₂}
namespace AreComplementary
variable (ac : AreComplementary e₁ e₂)
include ac
lemma symm : AreComplementary e₂ e₁ where
disjoint i₂ i₁ := (ac.disjoint i₁ i₂).symm
union i := (ac.union i).symm
lemma exists_i₁ (i : ι) (hi : ∀ i₂, e₂.f i₂ ≠ i) :
∃ i₁, i = e₁.f i₁ := by
obtain ⟨i₁, rfl⟩ | ⟨i₂, rfl⟩ := ac.union i
· exact ⟨_, rfl⟩
· exfalso
exact hi i₂ rfl
lemma exists_i₂ (i : ι) (hi : ∀ i₁, e₁.f i₁ ≠ i) :
∃ i₂, i = e₂.f i₂ :=
ac.symm.exists_i₁ i hi
variable (e₁ e₂) in
/-- Given complementary embeddings of complex shapes
`e₁ : Embedding c₁ c` and `e₂ : Embedding c₂ c`, this is
the obvious map `ι₁ ⊕ ι₂ → ι` from the sum of the index
types of `c₁` and `c₂` to the index type of `c`. -/
@[simp]
def fromSum : ι₁ ⊕ ι₂ → ι
| Sum.inl i₁ => e₁.f i₁
| Sum.inr i₂ => e₂.f i₂
lemma fromSum_bijective : Function.Bijective (fromSum e₁ e₂) := by
constructor
· rintro (i₁ | i₂) (j₁ | j₂) h
· obtain rfl := e₁.injective_f h
rfl
· exact (ac.disjoint _ _ h).elim
· exact (ac.disjoint _ _ h.symm).elim
· obtain rfl := e₂.injective_f h
rfl
· intro n
obtain ⟨i₁, rfl⟩ | ⟨i₂, rfl⟩ := ac.union n
· exact ⟨Sum.inl i₁, rfl⟩
· exact ⟨Sum.inr i₂, rfl⟩
/-- Given complementary embeddings of complex shapes
`e₁ : Embedding c₁ c` and `e₂ : Embedding c₂ c`, this is
the obvious bijection `ι₁ ⊕ ι₂ ≃ ι` from the sum of the index
types of `c₁` and `c₂` to the index type of `c`. -/
noncomputable def equiv : ι₁ ⊕ ι₂ ≃ ι := Equiv.ofBijective _ (ac.fromSum_bijective)
@[simp] lemma equiv_inl (i₁ : ι₁) : ac.equiv (Sum.inl i₁) = e₁.f i₁ := rfl
@[simp] lemma equiv_inr (i₂ : ι₂) : ac.equiv (Sum.inr i₂) = e₂.f i₂ := rfl
section
variable {X : ι → Type*} (x₁ : ∀ i₁, X (e₁.f i₁)) (x₂ : ∀ i₂, X (e₂.f i₂))
variable (X) in
/-- Auxiliary definition for `desc`. -/
def desc.aux (i j : ι) (hij : i = j) : X i ≃ X j := by
subst hij
rfl
omit ac in
@[simp]
lemma desc.aux_trans {i j k : ι} (hij : i = j) (hjk : j = k) (x : X i) :
desc.aux X j k hjk (aux X i j hij x) = desc.aux X i k (hij.trans hjk) x := by
subst hij hjk
rfl
/-- Auxiliary definition for `desc`. -/
def desc' : ∀ (i : ι₁ ⊕ ι₂), X (ac.equiv i)
| Sum.inl i₁ => x₁ i₁
| Sum.inr i₂ => x₂ i₂
lemma desc'_inl (i : ι₁ ⊕ ι₂) (i₁ : ι₁) (h : Sum.inl i₁ = i) :
ac.desc' x₁ x₂ i = desc.aux _ _ _ (by subst h; simp) (x₁ i₁) := by subst h; rfl
lemma desc'_inr (i : ι₁ ⊕ ι₂) (i₂ : ι₂) (h : Sum.inr i₂ = i) :
ac.desc' x₁ x₂ i = desc.aux _ _ _ (by subst h; simp) (x₂ i₂) := by subst h; rfl
/-- If `ι₁` and `ι₂` are the index types of complementary embeddings into a
complex shape of index type `ι`, this is a constructor for (dependent) maps from `ι`,
which takes as inputs the "restrictions" to `ι₁` and `ι₂`. -/
noncomputable def desc (i : ι) : X i :=
desc.aux _ _ _ (by simp) (ac.desc' x₁ x₂ (ac.equiv.symm i))
lemma desc_inl (i₁ : ι₁) : ac.desc x₁ x₂ (e₁.f i₁) = x₁ i₁ := by
dsimp [desc]
rw [ac.desc'_inl _ _ _ i₁ (ac.equiv.injective (by simp)), desc.aux_trans]
rfl
lemma desc_inr (i₂ : ι₂) : ac.desc x₁ x₂ (e₂.f i₂) = x₂ i₂ := by
dsimp [desc]
rw [ac.desc'_inr _ _ _ i₂ (ac.equiv.injective (by simp)), desc.aux_trans]
rfl
end
variable (K L : HomologicalComplex C c)
lemma isStrictlySupportedOutside₁_iff :
K.IsStrictlySupportedOutside e₁ ↔ K.IsStrictlySupported e₂ := by
constructor
· intro h
exact ⟨fun i hi => by
obtain ⟨i₁, rfl⟩ := ac.exists_i₁ i hi
exact h.isZero i₁⟩
· intro _
exact ⟨fun i₁ => K.isZero_X_of_isStrictlySupported e₂ _
(fun i₂ => (ac.disjoint i₁ i₂).symm)⟩
lemma isStrictlySupportedOutside₂_iff :
K.IsStrictlySupportedOutside e₂ ↔ K.IsStrictlySupported e₁ :=
ac.symm.isStrictlySupportedOutside₁_iff K
lemma isSupportedOutside₁_iff :
K.IsSupportedOutside e₁ ↔ K.IsSupported e₂ := by
constructor
· intro h
exact ⟨fun i hi => by
obtain ⟨i₁, rfl⟩ := ac.exists_i₁ i hi
exact h.exactAt i₁⟩
· intro _
exact ⟨fun i₁ => K.exactAt_of_isSupported e₂ _
(fun i₂ => (ac.disjoint i₁ i₂).symm)⟩
lemma isSupportedOutside₂_iff :
K.IsSupportedOutside e₂ ↔ K.IsSupported e₁ :=
ac.symm.isSupportedOutside₁_iff K
variable {K L}
/-- Variant of `hom_ext`. -/
lemma hom_ext' (φ : K ⟶ L) (hK : K.IsStrictlySupportedOutside e₂)
(hL : L.IsStrictlySupportedOutside e₁) :
φ = 0 := by
ext i
obtain ⟨i₁, rfl⟩ | ⟨i₂, rfl⟩ := ac.union i
· apply (hL.isZero i₁).eq_of_tgt
· apply (hK.isZero i₂).eq_of_src
lemma hom_ext [K.IsStrictlySupported e₁] [L.IsStrictlySupported e₂] (φ : K ⟶ L) :
φ = 0 := by
apply ac.hom_ext'
· rw [ac.isStrictlySupportedOutside₂_iff]
infer_instance
· rw [ac.isStrictlySupportedOutside₁_iff]
infer_instance
/-- If `e₁` and `e₂` are complementary embeddings into a complex shape `c`,
indices `i₁` and `i₂` are at the boundary if `c.Rel (e₁.f i₁) (e₂.f i₂)`. -/
@[nolint unusedArguments]
def Boundary (_ : AreComplementary e₁ e₂) (i₁ : ι₁) (i₂ : ι₂) : Prop :=
c.Rel (e₁.f i₁) (e₂.f i₂)
namespace Boundary
variable {ac}
section
variable {i₁ : ι₁} {i₂ : ι₂} (h : ac.Boundary i₁ i₂)
include h
lemma fst : e₁.BoundaryLE i₁ :=
e₁.boundaryLE h (fun _ => ac.disjoint _ _)
lemma snd : e₂.BoundaryGE i₂ :=
e₂.boundaryGE h (fun _ => ac.symm.disjoint _ _)
end
lemma fst_inj {i₁ i₁' : ι₁} {i₂ : ι₂} (h : ac.Boundary i₁ i₂) (h' : ac.Boundary i₁' i₂) :
i₁ = i₁' :=
e₁.injective_f (c.prev_eq h h')
lemma snd_inj {i₁ : ι₁} {i₂ i₂' : ι₂} (h : ac.Boundary i₁ i₂) (h' : ac.Boundary i₁ i₂') :
i₂ = i₂' :=
e₂.injective_f (c.next_eq h h')
variable (ac)
lemma exists₁ {i₁ : ι₁} (h : e₁.BoundaryLE i₁) :
∃ i₂, ac.Boundary i₁ i₂ := by
obtain ⟨h₁, h₂⟩ := h
obtain ⟨i₂, hi₂⟩ := ac.exists_i₂ (c.next (e₁.f i₁))
(fun i₁' hi₁' => h₂ i₁' (by simpa only [← hi₁'] using h₁))
exact ⟨i₂, by simpa only [hi₂] using h₁⟩
lemma exists₂ {i₂ : ι₂} (h : e₂.BoundaryGE i₂) :
∃ i₁, ac.Boundary i₁ i₂ := by
obtain ⟨h₁, h₂⟩ := h
obtain ⟨i₁, hi₁⟩ := ac.exists_i₁ (c.prev (e₂.f i₂))
(fun i₂' hi₂' => h₂ i₂' (by simpa only [← hi₂'] using h₁))
exact ⟨i₁, by simpa only [hi₁] using h₁⟩
/-- If `ac : AreComplementary e₁ e₂` (with `e₁ : ComplexShape.Embedding c₁ c` and
`e₂ : ComplexShape.Embedding c₂ c`), and `i₁` belongs to `e₁.BoundaryLE`,
then this is the (unique) index `i₂` of `c₂` such that `ac.Boundary i₁ i₂`. -/
noncomputable def indexOfBoundaryLE {i₁ : ι₁} (h : e₁.BoundaryLE i₁) : ι₂ :=
(exists₁ ac h).choose
lemma of_boundaryLE {i₁ : ι₁} (h : e₁.BoundaryLE i₁) :
ac.Boundary i₁ (indexOfBoundaryLE ac h) := (exists₁ ac h).choose_spec
/-- If `ac : AreComplementary e₁ e₂` (with `e₁ : ComplexShape.Embedding c₁ c` and
`e₂ : ComplexShape.Embedding c₂ c`), and `i₂` belongs to `e₂.BoundaryGE`,
then this is the (unique) index `i₁` of `c₁` such that `ac.Boundary i₁ i₂`. -/
noncomputable def indexOfBoundaryGE {i₂ : ι₂} (h : e₂.BoundaryGE i₂) : ι₁ :=
(exists₂ ac h).choose
lemma of_boundaryGE {i₂ : ι₂} (h : e₂.BoundaryGE i₂) :
ac.Boundary (indexOfBoundaryGE ac h) i₂ := (exists₂ ac h).choose_spec
/-- The bijection `Subtype e₁.BoundaryLE ≃ Subtype e₂.BoundaryGE` when
`e₁` and `e₂` are complementary embeddings of complex shapes. -/
noncomputable def equiv : Subtype e₁.BoundaryLE ≃ Subtype e₂.BoundaryGE where
toFun := fun ⟨i₁, h⟩ => ⟨_, (of_boundaryLE ac h).snd⟩
invFun := fun ⟨i₂, h⟩ => ⟨_, (of_boundaryGE ac h).fst⟩
left_inv := fun ⟨i₁, h⟩ => by
ext
have h' := of_boundaryLE ac h
have h'' := of_boundaryGE ac h'.snd
exact fst_inj h'' h'
right_inv := fun ⟨i₂, h⟩ => by
ext
have h' := of_boundaryGE ac h
have h'' := of_boundaryLE ac h'.fst
exact snd_inj h'' h'
end Boundary
end AreComplementary
lemma embeddingUpInt_areComplementary (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) :
AreComplementary (embeddingUpIntLE n₀) (embeddingUpIntGE n₁) where
disjoint i₁ i₂ := by dsimp; omega
union i := by
by_cases hi : i ≤ n₀
· obtain ⟨k, rfl⟩ := Int.exists_add_of_le hi
exact Or.inl ⟨k, by dsimp; omega⟩
· obtain ⟨k, rfl⟩ := Int.exists_add_of_le (show n₁ ≤ i by omega)
exact Or.inr ⟨k, rfl⟩
end Embedding
end ComplexShape
namespace HomologicalComplex
section
variable {C : Type*} [Category C] [Abelian C]
(K : HomologicalComplex C c) {e₁ : c₁.Embedding c} {e₂ : c₂.Embedding c}
[e₁.IsTruncLE] [e₂.IsTruncGE] (ac : e₁.AreComplementary e₂)
/-- When `e₁` and `e₂` are complementary embeddings of complex shapes, with
`e₁.IsTruncLE` and `e₂.IsTruncGE`, then this is the canonical quasi-isomorphism
`(K.shortComplexTruncLE e₁).X₃ ⟶ K.truncGE e₂` where
`(K.shortComplexTruncLE e₁).X₃` is the cokernel of `K.ιTruncLE e₁ : K.truncLE e₁ ⟶ K`. -/
noncomputable def shortComplexTruncLEX₃ToTruncGE :
(K.shortComplexTruncLE e₁).X₃ ⟶ K.truncGE e₂ :=
cokernel.desc _ (K.πTruncGE e₂) (ac.hom_ext _)
@[reassoc (attr := simp)]
lemma g_shortComplexTruncLEX₃ToTruncGE :
(K.shortComplexTruncLE e₁).g ≫ K.shortComplexTruncLEX₃ToTruncGE ac = K.πTruncGE e₂ :=
cokernel.π_desc _ _ _
instance : QuasiIso (K.shortComplexTruncLEX₃ToTruncGE ac) where
quasiIsoAt i := by
obtain ⟨i₁, rfl⟩ | ⟨i₂, rfl⟩ := ac.union i
· have h₁ := ((ac.isSupportedOutside₁_iff (K.truncGE e₂)).2 inferInstance).exactAt i₁
have h₂ := (K.shortComplexTruncLE_X₃_isSupportedOutside e₁).exactAt i₁
simpa only [quasiIsoAt_iff_exactAt _ _ h₂] using h₁
· have := quasiIsoAt_shortComplexTruncLE_g K e₁ (e₂.f i₂) (fun _ => ac.disjoint _ _)
rw [← quasiIsoAt_iff_comp_left (K.shortComplexTruncLE e₁).g
(K.shortComplexTruncLEX₃ToTruncGE ac), g_shortComplexTruncLEX₃ToTruncGE]
dsimp
infer_instance
end
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/Connect.lean | import Mathlib.Algebra.Homology.Embedding.RestrictionHomology
/-!
# Connecting a chain complex and a cochain complex
Given a chain complex `K`: `... ⟶ K.X 2 ⟶ K.X 1 ⟶ K.X 0`,
a cochain complex `L`: `L.X 0 ⟶ L.X 1 ⟶ L.X 2 ⟶ ...`,
a morphism `d₀ : K.X 0 ⟶ L.X 0` satisfying the identifies `K.d 1 0 ≫ d₀ = 0`
and `d₀ ≫ L.d 0 1 = 0`, we construct a cochain complex indexed by `ℤ` of the form
`... ⟶ K.X 2 ⟶ K.X 1 ⟶ K.X 0 ⟶ L.X 0 ⟶ L.X 1 ⟶ L.X 2 ⟶ ...`,
where `K.X 0` lies in degree `-1` and `L.X 0` in degree `0`.
## Main definitions
Say `K : ChainComplex C ℕ` and `L : CochainComplex C ℕ`, so `... ⟶ K₂ ⟶ K₁ ⟶ K₀`
and `L⁰ ⟶ L¹ ⟶ L² ⟶ ...`.
* `ConnectData K L`: an auxiliary structure consisting of `d₀ : K₀ ⟶ L⁰` "connecting" the
complexes and proofs that the induced maps `K₁ ⟶ K₀ ⟶ L⁰` and `K₀ ⟶ L⁰ ⟶ L¹` are both zero.
Now say `h : ConnectData K L`.
* `CochainComplex.ConnectData.cochainComplex h` : the induced ℤ-indexed complex
`... ⟶ K₁ ⟶ K₀ ⟶ L⁰ ⟶ L¹ ⟶ ...`
* `CochainComplex.ConnectData.homologyIsoPos h (n : ℕ) (m : ℤ)` : if `m = n + 1`,
the isomorphism `h.cochainComplex.homology m ≅ L.homology (n + 1)`
* `CochainComplex.ConnectData.homologyIsoNeg h (n : ℕ) (m : ℤ)` : if `m = -(n + 2)`,
the isomorphism `h.cochainComplex.homology m ≅ K.homology (n + 1)`
## TODO
* Computation of `h.cochainComplex.homology k` when `k = 0` or `k = -1`.
-/
universe v u
open CategoryTheory Limits
variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C]
namespace CochainComplex
variable (K : ChainComplex C ℕ) (L : CochainComplex C ℕ)
/-- Given `K : ChainComplex C ℕ` and `L : CochainComplex C ℕ`, this data
allows to connect `K` and `L` in order to get a cochain complex indexed by `ℤ`,
see `ConnectData.cochainComplex`. -/
structure ConnectData where
/-- the differential which connect `K` and `L` -/
d₀ : K.X 0 ⟶ L.X 0
comp_d₀ : K.d 1 0 ≫ d₀ = 0
d₀_comp : d₀ ≫ L.d 0 1 = 0
namespace ConnectData
attribute [reassoc (attr := simp)] comp_d₀ d₀_comp
variable {K L} (h : ConnectData K L)
variable (K L) in
/-- Auxiliary definition for `ConnectData.cochainComplex`. -/
def X : ℤ → C
| .ofNat n => L.X n
| .negSucc n => K.X n
@[simp] lemma X_ofNat (n : ℕ) : X K L n = L.X n := rfl
@[simp] lemma X_negSucc (n : ℕ) : X K L (.negSucc n) = K.X n := rfl
@[simp] lemma X_zero : X K L 0 = L.X 0 := rfl
@[simp] lemma X_negOne : X K L (-1) = K.X 0 := rfl
/-- Auxiliary definition for `ConnectData.cochainComplex`. -/
def d : ∀ (n m : ℤ), X K L n ⟶ X K L m
| .ofNat n, .ofNat m => L.d n m
| .negSucc n, .negSucc m => K.d n m
| .negSucc 0, .ofNat 0 => h.d₀
| .ofNat _, .negSucc _ => 0
| .negSucc _, .ofNat _ => 0
@[simp] lemma d_ofNat (n m : ℕ) : h.d n m = L.d n m := rfl
@[simp] lemma d_negSucc (n m : ℕ) : h.d (.negSucc n) (.negSucc m) = K.d n m := by simp [d]
@[simp] lemma d_sub_one_zero : h.d (-1) 0 = h.d₀ := rfl
@[simp] lemma d_zero_one : h.d 0 1 = L.d 0 1 := rfl
@[simp] lemma d_sub_two_sub_one : h.d (-2) (-1) = K.d 1 0 := rfl
lemma shape (n m : ℤ) (hnm : n + 1 ≠ m) : h.d n m = 0 :=
match n, m with
| .ofNat n, .ofNat m => L.shape _ _ (by simp at hnm ⊢; cutsat)
| .negSucc n, .negSucc m => by
simpa only [d_negSucc] using K.shape n m (by simp at hnm ⊢; cutsat)
| .negSucc 0, .ofNat 0 => by simp at hnm
| .ofNat _, .negSucc m => rfl
| .negSucc n, .ofNat m => by
obtain _ | n := n
· obtain _ | m := m
· simp at hnm
· rfl
· rfl
@[reassoc (attr := simp)]
lemma d_comp_d (n m p : ℤ) : h.d n m ≫ h.d m p = 0 := by
by_cases hnm : n + 1 = m; swap
· rw [h.shape n m hnm, zero_comp]
by_cases hmp : m + 1 = p; swap
· rw [h.shape m p hmp, comp_zero]
obtain n | (_ | _ | n) := n
· obtain rfl : m = .ofNat (n + 1) := by simp [← hnm]
obtain rfl : p = .ofNat (n + 2) := by simp [← hmp]; cutsat
simp only [Int.ofNat_eq_coe, X_ofNat, d_ofNat, HomologicalComplex.d_comp_d]
· obtain rfl : m = 0 := by cutsat
obtain rfl : p = 1 := by cutsat
simp
· obtain rfl : m = -1 := by cutsat
obtain rfl : p = 0 := by cutsat
simp
· obtain rfl : m = .negSucc (n + 1) := by cutsat
obtain rfl : p = .negSucc n := by cutsat
simp
/-- Given `h : ConnectData K L` where `K : ChainComplex C ℕ` and `L : CochainComplex C ℕ`,
this is the cochain complex indexed by `ℤ` obtained by connecting `K` and `L`:
`... ⟶ K.X 2 ⟶ K.X 1 ⟶ K.X 0 ⟶ L.X 0 ⟶ L.X 1 ⟶ L.X 2 ⟶ ...`. -/
@[simps]
def cochainComplex : CochainComplex C ℤ where
X := X K L
d := h.d
shape := h.shape
open HomologicalComplex
/-- If `h : ConnectData K L`, then `h.cochainComplex` identifies to `L` in degrees `≥ 0`. -/
@[simps!]
def restrictionGEIso :
h.cochainComplex.restriction (ComplexShape.embeddingUpIntGE 0) ≅ L :=
Hom.isoOfComponents
(fun n ↦ h.cochainComplex.restrictionXIso (ComplexShape.embeddingUpIntGE 0)
(i := n) (i' := n) (by simp)) (by
rintro n _ rfl
dsimp only
rw [restriction_d_eq (e := (ComplexShape.embeddingUpIntGE 0)) _ (i' := n)
(j' := (n + 1 : ℕ)) (by simp) (by simp), cochainComplex_d, h.d_ofNat]
simp)
/-- If `h : ConnectData K L`, then `h.cochainComplex` identifies to `K` in degrees `≤ -1`. -/
@[simps!]
def restrictionLEIso :
h.cochainComplex.restriction (ComplexShape.embeddingUpIntLE (-1)) ≅ K :=
Hom.isoOfComponents
(fun n ↦ h.cochainComplex.restrictionXIso (ComplexShape.embeddingUpIntLE (-1))
(i := n) (i' := .negSucc n) (by dsimp; cutsat)) (by
rintro _ n rfl
dsimp only
rw [restriction_d_eq (e := (ComplexShape.embeddingUpIntLE (-1))) _
(i' := Int.negSucc (n + 1)) (j' := Int.negSucc n) (by dsimp; cutsat) (by dsimp; cutsat),
cochainComplex_d, d_negSucc]
simp)
/-- Given `h : ConnectData K L` and `n : ℕ`, the homology
of `h.cochainComplex` in degree `n + 1` identifies to the homology of `L` in degree `n + 1`. -/
noncomputable def homologyIsoPos (n : ℕ) (m : ℤ)
[h.cochainComplex.HasHomology m] [L.HasHomology (n + 1)]
(hm : m = (n + 1 : ℕ)) :
h.cochainComplex.homology m ≅ L.homology (n + 1) :=
have := hasHomology_of_iso h.restrictionGEIso.symm (n + 1)
(h.cochainComplex.restrictionHomologyIso
(ComplexShape.embeddingUpIntGE 0) n (n + 1) (n + 2) (by simp) (by simp)
(i' := m - 1) (j' := m) (k' := m + 1) (by simp; cutsat) (by simp; cutsat)
(by simp; cutsat) (by simp) (by simp)).symm ≪≫
HomologicalComplex.homologyMapIso h.restrictionGEIso (n + 1)
/-- Given `h : ConnectData K L` and `n : ℕ`, the homology
of `h.cochainComplex` in degree `-(n + 2)` identifies to the homology of `K` in degree `n + 1`. -/
noncomputable def homologyIsoNeg (n : ℕ) (m : ℤ)
[h.cochainComplex.HasHomology m] [K.HasHomology (n + 1)]
(hm : m = -(n + 2 : ℕ)) :
h.cochainComplex.homology m ≅ K.homology (n + 1) :=
have := hasHomology_of_iso h.restrictionLEIso.symm (n + 1)
(h.cochainComplex.restrictionHomologyIso
(ComplexShape.embeddingUpIntLE (-1)) (n + 2) (n + 1) n (by simp) (by simp)
(i' := m - 1) (j' := m) (k' := m + 1)
(by simp; cutsat) (by simp; cutsat) (by simp; cutsat) (by simp) (by simp)).symm ≪≫
HomologicalComplex.homologyMapIso h.restrictionLEIso (n + 1)
end ConnectData
end CochainComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/IsSupported.lean | 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
whenever `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'
include e' in
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)
@[simp]
lemma isStrictlySupported_op_iff :
K.op.IsStrictlySupported e.op ↔ K.IsStrictlySupported e :=
⟨(fun _ ↦ ⟨fun i' hi' ↦ (K.op.isZero_X_of_isStrictlySupported e.op i' hi').unop⟩),
(fun _ ↦ ⟨fun i' hi' ↦ (K.isZero_X_of_isStrictlySupported e i' hi').op⟩)⟩
instance [K.IsStrictlySupported e] : K.op.IsStrictlySupported e.op := by
rw [isStrictlySupported_op_iff]
infer_instance
/-- 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'
include e' in
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')
@[simp]
lemma isSupported_op_iff :
K.op.IsSupported e.op ↔ K.IsSupported e :=
⟨fun _ ↦ ⟨fun i' hi' ↦ (K.op.exactAt_of_isSupported e.op i' hi').unop⟩,
fun _ ↦ ⟨fun i' hi' ↦ (K.exactAt_of_isSupported e i' hi').op⟩⟩
/-- 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))
@[simp]
lemma isStrictlySupportedOutside_op_iff :
K.op.IsStrictlySupportedOutside e.op ↔ K.IsStrictlySupportedOutside e :=
⟨fun h ↦ ⟨fun i ↦ (h.isZero i).unop⟩, fun h ↦ ⟨fun i ↦ (h.isZero i).op⟩⟩
/-- 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)
@[simp]
lemma isSupportedOutside_op_iff :
K.op.IsSupportedOutside e.op ↔ K.IsSupportedOutside e :=
⟨fun h ↦ ⟨fun i ↦ (h.exactAt i).unop⟩, fun h ↦ ⟨fun i ↦ (h.exactAt i).op⟩⟩
variable {K e} in
lemma IsStrictlySupportedOutside.isSupportedOutside (h : K.IsStrictlySupportedOutside e) :
K.IsSupportedOutside e where
exactAt i := 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)
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 |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/ExtendHomology.lean | import Mathlib.Algebra.Homology.Embedding.Extend
import Mathlib.Algebra.Homology.Embedding.IsSupported
import Mathlib.Algebra.Homology.QuasiIso
/-!
# Homology of the extension of an homological complex
Given an embedding `e : c.Embedding c'` and `K : HomologicalComplex C c`, we shall
compute the homology of `K.extend e`. In degrees that are not in the image of `e.f`,
the homology is obviously zero. When `e.f j = j`, we construct an isomorphism
`(K.extend e).homology j' ≅ K.homology j`.
-/
open CategoryTheory Limits Category
namespace HomologicalComplex
variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'}
{C : Type*} [Category C] [HasZeroMorphisms C]
[HasZeroObject C]
variable (K L M : HomologicalComplex C c) (φ : K ⟶ L) (φ' : L ⟶ M) (e : c.Embedding c')
namespace extend
section HomologyData
variable {i j k : ι} {i' j' k' : ι'} (hj' : e.f j = j')
(hi : c.prev j = i) (hi' : c'.prev j' = i') (hk : c.next j = k) (hk' : c'.next j' = k')
include hk hk' in
lemma comp_d_eq_zero_iff ⦃W : C⦄ (φ : W ⟶ K.X j) :
φ ≫ K.d j k = 0 ↔ φ ≫ (K.extendXIso e hj').inv ≫ (K.extend e).d j' k' = 0 := by
by_cases hjk : c.Rel j k
· have hk' : e.f k = k' := by rw [← hk', ← hj', c'.next_eq' (e.rel hjk)]
rw [K.extend_d_eq e hj' hk', Iso.inv_hom_id_assoc,
← cancel_mono (K.extendXIso e hk').inv, zero_comp, assoc]
· simp only [K.shape _ _ hjk, comp_zero, true_iff]
rw [K.extend_d_from_eq_zero e j' k' j hj', comp_zero, comp_zero]
rw [hk]
exact hjk
include hi hi' in
lemma d_comp_eq_zero_iff ⦃W : C⦄ (φ : K.X j ⟶ W) :
K.d i j ≫ φ = 0 ↔ (K.extend e).d i' j' ≫ (K.extendXIso e hj').hom ≫ φ = 0 := by
by_cases hij : c.Rel i j
· have hi' : e.f i = i' := by rw [← hi', ← hj', c'.prev_eq' (e.rel hij)]
rw [K.extend_d_eq e hi' hj', assoc, assoc, Iso.inv_hom_id_assoc,
← cancel_epi (K.extendXIso e hi').hom, comp_zero]
· simp only [K.shape _ _ hij, zero_comp, true_iff]
rw [K.extend_d_to_eq_zero e i' j' j hj', zero_comp]
rw [hi]
exact hij
namespace leftHomologyData
variable (cone : KernelFork (K.d j k)) (hcone : IsLimit cone)
/-- The kernel fork of `(K.extend e).d j' k'` that is deduced from a kernel
fork of `K.d j k `. -/
@[simp]
noncomputable def kernelFork : KernelFork ((K.extend e).d j' k') :=
KernelFork.ofι (cone.ι ≫ (extendXIso K e hj').inv)
(by rw [assoc, ← comp_d_eq_zero_iff K e hj' hk hk' cone.ι, cone.condition])
/-- The limit kernel fork of `(K.extend e).d j' k'` that is deduced from a limit
kernel fork of `K.d j k `. -/
noncomputable def isLimitKernelFork : IsLimit (kernelFork K e hj' hk hk' cone) :=
KernelFork.isLimitOfIsLimitOfIff hcone ((K.extend e).d j' k')
(extendXIso K e hj').symm (comp_d_eq_zero_iff K e hj' hk hk')
variable (cocone : CokernelCofork (hcone.lift (KernelFork.ofι (K.d i j) (K.d_comp_d i j k))))
(hcocone : IsColimit cocone)
include hi hi' hcone in
/-- Auxiliary lemma for `lift_d_comp_eq_zero_iff`. -/
lemma lift_d_comp_eq_zero_iff' ⦃W : C⦄ (f' : K.X i ⟶ cone.pt)
(hf' : f' ≫ cone.ι = K.d i j)
(f'' : (K.extend e).X i' ⟶ cone.pt)
(hf'' : f'' ≫ cone.ι ≫ (extendXIso K e hj').inv = (K.extend e).d i' j')
(φ : cone.pt ⟶ W) :
f' ≫ φ = 0 ↔ f'' ≫ φ = 0 := by
by_cases hij : c.Rel i j
· have hi'' : e.f i = i' := by rw [← hi', ← hj', c'.prev_eq' (e.rel hij)]
have : (K.extendXIso e hi'').hom ≫ f' = f'' := by
apply Fork.IsLimit.hom_ext hcone
rw [assoc, hf', ← cancel_mono (extendXIso K e hj').inv, assoc, assoc, hf'',
K.extend_d_eq e hi'' hj']
rw [← cancel_epi (K.extendXIso e hi'').hom, comp_zero, ← this, assoc]
· have h₁ : f' = 0 := by
apply Fork.IsLimit.hom_ext hcone
simp only [zero_comp, hf', K.shape _ _ hij]
have h₂ : f'' = 0 := by
apply Fork.IsLimit.hom_ext hcone
dsimp
rw [← cancel_mono (extendXIso K e hj').inv, assoc, hf'', zero_comp, zero_comp,
K.extend_d_to_eq_zero e i' j' j hj']
rw [hi]
exact hij
simp [h₁, h₂]
include hi hi' in
lemma lift_d_comp_eq_zero_iff ⦃W : C⦄ (φ : cone.pt ⟶ W) :
hcone.lift (KernelFork.ofι (K.d i j) (K.d_comp_d i j k)) ≫ φ = 0 ↔
((isLimitKernelFork K e hj' hk hk' cone hcone).lift
(KernelFork.ofι ((K.extend e).d i' j') (d_comp_d _ _ _ _))) ≫ φ = 0 :=
lift_d_comp_eq_zero_iff' K e hj' hi hi' cone hcone _ (hcone.fac _ _) _
(IsLimit.fac _ _ WalkingParallelPair.zero) _
/-- Auxiliary definition for `extend.leftHomologyData`. -/
noncomputable def cokernelCofork :
CokernelCofork ((isLimitKernelFork K e hj' hk hk' cone hcone).lift
(KernelFork.ofι ((K.extend e).d i' j') (d_comp_d _ _ _ _))) :=
CokernelCofork.ofπ cocone.π (by
rw [← lift_d_comp_eq_zero_iff K e hj' hi hi' hk hk' cone hcone]
exact cocone.condition)
/-- Auxiliary definition for `extend.leftHomologyData`. -/
noncomputable def isColimitCokernelCofork :
IsColimit (cokernelCofork K e hj' hi hi' hk hk' cone hcone cocone) :=
CokernelCofork.isColimitOfIsColimitOfIff' hcocone _
(lift_d_comp_eq_zero_iff K e hj' hi hi' hk hk' cone hcone)
end leftHomologyData
open leftHomologyData in
/-- The left homology data of `(K.extend e).sc' i' j' k'` that is deduced
from a left homology data of `K.sc' i j k`. -/
@[simps]
noncomputable def leftHomologyData (h : (K.sc' i j k).LeftHomologyData) :
((K.extend e).sc' i' j' k').LeftHomologyData where
K := h.K
H := h.H
i := h.i ≫ (extendXIso K e hj').inv
π := h.π
wi := by
dsimp
rw [assoc, ← comp_d_eq_zero_iff K e hj' hk hk']
exact h.wi
hi := isLimitKernelFork K e hj' hk hk' _ h.hi
wπ := by
dsimp
rw [← lift_d_comp_eq_zero_iff K e hj' hi hi' hk hk' _ h.hi]
exact h.wπ
hπ := isColimitCokernelCofork K e hj' hi hi' hk hk' _ h.hi _ h.hπ
namespace rightHomologyData
variable (cocone : CokernelCofork (K.d i j)) (hcocone : IsColimit cocone)
/-- The cokernel cofork of `(K.extend e).d i' j'` that is deduced from a cokernel
cofork of `K.d i j`. -/
@[simp]
noncomputable def cokernelCofork : CokernelCofork ((K.extend e).d i' j') :=
CokernelCofork.ofπ ((extendXIso K e hj').hom ≫ cocone.π) (by
rw [← d_comp_eq_zero_iff K e hj' hi hi' cocone.π, cocone.condition])
/-- The colimit cokernel cofork of `(K.extend e).d i' j'` that is deduced from a
colimit cokernel cofork of `K.d i j`. -/
noncomputable def isColimitCokernelCofork : IsColimit (cokernelCofork K e hj' hi hi' cocone) :=
CokernelCofork.isColimitOfIsColimitOfIff hcocone ((K.extend e).d i' j')
(extendXIso K e hj') (d_comp_eq_zero_iff K e hj' hi hi')
variable (cone : KernelFork (hcocone.desc (CokernelCofork.ofπ (K.d j k) (K.d_comp_d i j k))))
(hcone : IsLimit cone)
include hk hk' hcocone in
lemma d_comp_desc_eq_zero_iff' ⦃W : C⦄ (f' : cocone.pt ⟶ K.X k)
(hf' : cocone.π ≫ f' = K.d j k)
(f'' : cocone.pt ⟶ (K.extend e).X k')
(hf'' : (extendXIso K e hj').hom ≫ cocone.π ≫ f'' = (K.extend e).d j' k')
(φ : W ⟶ cocone.pt) :
φ ≫ f' = 0 ↔ φ ≫ f'' = 0 := by
by_cases hjk : c.Rel j k
· have hk'' : e.f k = k' := by rw [← hk', ← hj', c'.next_eq' (e.rel hjk)]
have : f' ≫ (K.extendXIso e hk'').inv = f'' := by
apply Cofork.IsColimit.hom_ext hcocone
rw [reassoc_of% hf', ← cancel_epi (extendXIso K e hj').hom, hf'',
K.extend_d_eq e hj' hk'']
rw [← cancel_mono (K.extendXIso e hk'').inv, zero_comp, assoc, this]
· have h₁ : f' = 0 := by
apply Cofork.IsColimit.hom_ext hcocone
simp only [hf', comp_zero, K.shape _ _ hjk]
have h₂ : f'' = 0 := by
apply Cofork.IsColimit.hom_ext hcocone
rw [← cancel_epi (extendXIso K e hj').hom, hf'', comp_zero, comp_zero,
K.extend_d_from_eq_zero e j' k' j hj']
rw [hk]
exact hjk
simp [h₁, h₂]
include hk hk' in
lemma d_comp_desc_eq_zero_iff ⦃W : C⦄ (φ : W ⟶ cocone.pt) :
φ ≫ hcocone.desc (CokernelCofork.ofπ (K.d j k) (K.d_comp_d i j k)) = 0 ↔
φ ≫ ((isColimitCokernelCofork K e hj' hi hi' cocone hcocone).desc
(CokernelCofork.ofπ ((K.extend e).d j' k') (d_comp_d _ _ _ _))) = 0 :=
d_comp_desc_eq_zero_iff' K e hj' hk hk' cocone hcocone _ (hcocone.fac _ _) _ (by
simpa using (isColimitCokernelCofork K e hj' hi hi' cocone hcocone).fac _
WalkingParallelPair.one) _
/-- Auxiliary definition for `extend.rightHomologyData`. -/
noncomputable def kernelFork :
KernelFork ((isColimitCokernelCofork K e hj' hi hi' cocone hcocone).desc
(CokernelCofork.ofπ ((K.extend e).d j' k') (d_comp_d _ _ _ _))) :=
KernelFork.ofι cone.ι (by
rw [← d_comp_desc_eq_zero_iff K e hj' hi hi' hk hk' cocone hcocone]
exact cone.condition)
/-- Auxiliary definition for `extend.rightHomologyData`. -/
noncomputable def isLimitKernelFork :
IsLimit (kernelFork K e hj' hi hi' hk hk' cocone hcocone cone) :=
KernelFork.isLimitOfIsLimitOfIff' hcone _
(d_comp_desc_eq_zero_iff K e hj' hi hi' hk hk' cocone hcocone)
end rightHomologyData
open rightHomologyData in
/-- The right homology data of `(K.extend e).sc' i' j' k'` that is deduced
from a right homology data of `K.sc' i j k`. -/
@[simps]
noncomputable def rightHomologyData (h : (K.sc' i j k).RightHomologyData) :
((K.extend e).sc' i' j' k').RightHomologyData where
Q := h.Q
H := h.H
p := (extendXIso K e hj').hom ≫ h.p
ι := h.ι
wp := by
dsimp
rw [← d_comp_eq_zero_iff K e hj' hi hi']
exact h.wp
hp := isColimitCokernelCofork K e hj' hi hi' _ h.hp
wι := by
dsimp
rw [← d_comp_desc_eq_zero_iff K e hj' hi hi' hk hk' _ h.hp]
exact h.wι
hι := isLimitKernelFork K e hj' hi hi' hk hk' _ h.hp _ h.hι
/-- Computation of the `g'` field of `extend.rightHomologyData`. -/
lemma rightHomologyData_g' (h : (K.sc' i j k).RightHomologyData) (hk'' : e.f k = k') :
(rightHomologyData K e hj' hi hi' hk hk' h).g' = h.g' ≫ (K.extendXIso e hk'').inv := by
rw [← cancel_epi h.p, ← cancel_epi (extendXIso K e hj').hom]
have := (rightHomologyData K e hj' hi hi' hk hk' h).p_g'
dsimp at this
rw [assoc] at this
rw [this, K.extend_d_eq e hj' hk'', h.p_g'_assoc, shortComplexFunctor'_obj_g]
/-- The homology data of `(K.extend e).sc' i' j' k'` that is deduced
from a homology data of `K.sc' i j k`. -/
@[simps]
noncomputable def homologyData (h : (K.sc' i j k).HomologyData) :
((K.extend e).sc' i' j' k').HomologyData where
left := leftHomologyData K e hj' hi hi' hk hk' h.left
right := rightHomologyData K e hj' hi hi' hk hk' h.right
iso := h.iso
/-- The homology data of `(K.extend e).sc j'` that is deduced
from a homology data of `K.sc' i j k`. -/
@[simps!]
noncomputable def homologyData' (h : (K.sc' i j k).HomologyData) :
((K.extend e).sc j').HomologyData :=
homologyData K e hj' hi rfl hk rfl h
end HomologyData
lemma hasHomology {j : ι} {j' : ι'} (hj' : e.f j = j') [K.HasHomology j] :
(K.extend e).HasHomology j' :=
ShortComplex.HasHomology.mk'
(homologyData' K e hj' rfl rfl ((K.sc j).homologyData))
instance (j : ι) [K.HasHomology j] : (K.extend e).HasHomology (e.f j) :=
hasHomology K e rfl
instance [∀ j, K.HasHomology j] (j' : ι') : (K.extend e).HasHomology j' := by
by_cases h : ∃ j, e.f j = j'
· obtain ⟨j, rfl⟩ := h
infer_instance
· have hj := isZero_extend_X K e j' (by tauto)
exact ShortComplex.HasHomology.mk'
(ShortComplex.HomologyData.ofZeros _ (hj.eq_of_tgt _ _) (hj.eq_of_src _ _))
end extend
lemma extend_exactAt (j' : ι') (hj' : ∀ j, e.f j ≠ j') :
(K.extend e).ExactAt j' :=
exactAt_of_isSupported _ e j' hj'
section
variable {j : ι} {j' : ι'} (hj' : e.f j = j') [K.HasHomology j] [L.HasHomology j]
[(K.extend e).HasHomology j'] [(L.extend e).HasHomology j']
/-- The isomorphism `(K.extend e).cycles j' ≅ K.cycles j` when `e.f j = j'`. -/
noncomputable def extendCyclesIso :
(K.extend e).cycles j' ≅ K.cycles j :=
(extend.homologyData' K e hj' rfl rfl (K.sc j).homologyData).left.cyclesIso ≪≫
(K.sc j).homologyData.left.cyclesIso.symm
/-- The isomorphism `(K.extend e).opcycles j' ≅ K.opcycles j` when `e.f j = j'`. -/
noncomputable def extendOpcyclesIso :
(K.extend e).opcycles j' ≅ K.opcycles j :=
(extend.homologyData' K e hj' rfl rfl (K.sc j).homologyData).right.opcyclesIso ≪≫
(K.sc j).homologyData.right.opcyclesIso.symm
/-- The isomorphism `(K.extend e).homology j' ≅ K.homology j` when `e.f j = j'`. -/
noncomputable def extendHomologyIso :
(K.extend e).homology j' ≅ K.homology j :=
(extend.homologyData' K e hj' rfl rfl (K.sc j).homologyData).left.homologyIso ≪≫
(K.sc j).homologyData.left.homologyIso.symm
include hj' in
lemma extend_exactAt_iff :
(K.extend e).ExactAt j' ↔ K.ExactAt j := by
simp only [HomologicalComplex.exactAt_iff_isZero_homology]
exact (K.extendHomologyIso e hj').isZero_iff
@[reassoc (attr := simp)]
lemma extendCyclesIso_hom_iCycles :
(K.extendCyclesIso e hj').hom ≫ K.iCycles j =
(K.extend e).iCycles j' ≫ (K.extendXIso e hj').hom := by
rw [← cancel_epi (K.extendCyclesIso e hj').inv, Iso.inv_hom_id_assoc]
dsimp [extendCyclesIso, iCycles]
rw [assoc, ShortComplex.LeftHomologyData.cyclesIso_inv_comp_iCycles_assoc]
dsimp
rw [assoc, Iso.inv_hom_id, comp_id,
ShortComplex.LeftHomologyData.cyclesIso_hom_comp_i]
@[reassoc (attr := simp)]
lemma extendCyclesIso_inv_iCycles :
(K.extendCyclesIso e hj').inv ≫ (K.extend e).iCycles j' =
K.iCycles j ≫ (K.extendXIso e hj').inv := by
simp only [← cancel_epi (K.extendCyclesIso e hj').hom, Iso.hom_inv_id_assoc,
extendCyclesIso_hom_iCycles_assoc, Iso.hom_inv_id, comp_id]
@[reassoc (attr := simp)]
lemma homologyπ_extendHomologyIso_hom :
(K.extend e).homologyπ j' ≫ (K.extendHomologyIso e hj').hom =
(K.extendCyclesIso e hj').hom ≫ K.homologyπ j := by
dsimp [extendHomologyIso, homologyπ]
rw [ShortComplex.LeftHomologyData.homologyπ_comp_homologyIso_hom_assoc,
← cancel_mono (K.sc j).homologyData.left.homologyIso.hom,
assoc, assoc, assoc, Iso.inv_hom_id, comp_id,
ShortComplex.LeftHomologyData.homologyπ_comp_homologyIso_hom]
dsimp [extendCyclesIso]
simp only [assoc, Iso.inv_hom_id_assoc]
@[reassoc (attr := simp)]
lemma homologyπ_extendHomologyIso_inv :
K.homologyπ j ≫ (K.extendHomologyIso e hj').inv =
(K.extendCyclesIso e hj').inv ≫ (K.extend e).homologyπ j' := by
simp only [← cancel_mono (K.extendHomologyIso e hj').hom,
assoc, Iso.inv_hom_id, comp_id, homologyπ_extendHomologyIso_hom, Iso.inv_hom_id_assoc]
@[reassoc (attr := simp)]
lemma pOpcycles_extendOpcyclesIso_inv :
K.pOpcycles j ≫ (K.extendOpcyclesIso e hj').inv =
(K.extendXIso e hj').inv ≫ (K.extend e).pOpcycles j' := by
rw [← cancel_mono (K.extendOpcyclesIso e hj').hom, assoc, assoc, Iso.inv_hom_id, comp_id]
dsimp [extendOpcyclesIso, pOpcycles]
rw [ShortComplex.RightHomologyData.pOpcycles_comp_opcyclesIso_hom_assoc]
dsimp
rw [assoc, Iso.inv_hom_id_assoc, ShortComplex.RightHomologyData.p_comp_opcyclesIso_inv]
rfl
@[reassoc (attr := simp)]
lemma pOpcycles_extendOpcyclesIso_hom :
(K.extend e).pOpcycles j' ≫ (K.extendOpcyclesIso e hj').hom =
(K.extendXIso e hj').hom ≫ K.pOpcycles j := by
simp only [← cancel_mono (K.extendOpcyclesIso e hj').inv,
assoc, Iso.hom_inv_id, comp_id, pOpcycles_extendOpcyclesIso_inv, Iso.hom_inv_id_assoc]
@[reassoc (attr := simp)]
lemma extendHomologyIso_hom_homologyι :
(K.extendHomologyIso e hj').hom ≫ K.homologyι j =
(K.extend e).homologyι j' ≫ (K.extendOpcyclesIso e hj').hom := by
simp only [← cancel_epi ((K.extend e).homologyπ j'),
homologyπ_extendHomologyIso_hom_assoc, homology_π_ι, extendCyclesIso_hom_iCycles_assoc,
homology_π_ι_assoc, pOpcycles_extendOpcyclesIso_hom]
@[reassoc (attr := simp)]
lemma extendHomologyIso_inv_homologyι :
(K.extendHomologyIso e hj').inv ≫ (K.extend e).homologyι j' =
K.homologyι j ≫ (K.extendOpcyclesIso e hj').inv := by
simp only [← cancel_epi (K.extendHomologyIso e hj').hom,
Iso.hom_inv_id_assoc, extendHomologyIso_hom_homologyι_assoc, Iso.hom_inv_id, comp_id]
variable {K L}
@[reassoc (attr := simp)]
lemma extendCyclesIso_hom_naturality :
cyclesMap (extendMap φ e) j' ≫ (L.extendCyclesIso e hj').hom =
(K.extendCyclesIso e hj').hom ≫ cyclesMap φ j := by
simp [← cancel_mono (L.iCycles j), extendMap_f φ e hj']
@[reassoc (attr := simp)]
lemma extendHomologyIso_hom_naturality :
homologyMap (extendMap φ e) j' ≫ (L.extendHomologyIso e hj').hom =
(K.extendHomologyIso e hj').hom ≫ homologyMap φ j := by
simp [← cancel_epi ((K.extend e).homologyπ _)]
include hj' in
lemma quasiIsoAt_extendMap_iff :
QuasiIsoAt (extendMap φ e) j' ↔ QuasiIsoAt φ j := by
simp only [quasiIsoAt_iff_isIso_homologyMap]
exact (MorphismProperty.isomorphisms C).arrow_mk_iso_iff
(Arrow.isoMk (K.extendHomologyIso e hj') (L.extendHomologyIso e hj'))
end
lemma quasiIso_extendMap_iff [∀ j, K.HasHomology j] [∀ j, L.HasHomology j] :
QuasiIso (extendMap φ e) ↔ QuasiIso φ := by
simp only [quasiIso_iff, ← fun j ↦ quasiIsoAt_extendMap_iff φ e (j := j) (hj' := rfl)]
constructor
· tauto
· intro h j'
by_cases hj' : ∃ j, e.f j = j'
· obtain ⟨j, rfl⟩ := hj'
exact h j
· rw [quasiIsoAt_iff_exactAt]
all_goals
exact extend_exactAt _ _ _ (by simpa using hj')
end HomologicalComplex |
.lake/packages/mathlib/Mathlib/Algebra/Homology/Embedding/HomEquiv.lean | import Mathlib.Algebra.Homology.Embedding.Restriction
import Mathlib.Algebra.Homology.Embedding.Extend
import Mathlib.Algebra.Homology.Embedding.Boundary
import Mathlib.CategoryTheory.MorphismProperty.Basic
/-!
# Relations between `extend` and `restriction`
Given an embedding `e : Embedding c c'` of complex shapes satisfying `e.IsRelIff`,
we obtain a bijection `e.homEquiv` between the type of morphisms
`K ⟶ L.extend e` (with `K : HomologicalComplex C c'` and `L : HomologicalComplex C c`)
and the subtype of morphisms `φ : K.restriction e ⟶ L` which satisfy a certain
condition `e.HasLift φ`.
## TODO
* obtain dual results for morphisms `L.extend e ⟶ K`.
-/
open CategoryTheory Category Limits
namespace ComplexShape
variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} (e : Embedding c c')
{C : Type*} [Category C] [HasZeroMorphisms C] [HasZeroObject C]
namespace Embedding
open HomologicalComplex
variable {K K' : HomologicalComplex C c'} {L L' : HomologicalComplex C c}
[e.IsRelIff]
section
/-- The condition on a morphism `K.restriction e ⟶ L` which allows to
extend it as a morphism `K ⟶ L.extend e`, see `Embedding.homEquiv`. -/
def HasLift (φ : K.restriction e ⟶ L) : Prop :=
∀ (j : ι) (_ : e.BoundaryGE j) (i' : ι')
(_ : c'.Rel i' (e.f j)), K.d i' _ ≫ φ.f j = 0
namespace liftExtend
variable (φ : K.restriction e ⟶ L)
variable {e}
open Classical in
/-- Auxiliary definition for `liftExtend`. -/
noncomputable def f (i' : ι') : K.X i' ⟶ (L.extend e).X i' :=
if hi' : ∃ i, e.f i = i' then
(K.restrictionXIso e hi'.choose_spec).inv ≫ φ.f hi'.choose ≫
(L.extendXIso e hi'.choose_spec).inv
else 0
lemma f_eq {i' : ι'} {i : ι} (hi : e.f i = i') :
f φ i' = (K.restrictionXIso e hi).inv ≫ φ.f i ≫ (L.extendXIso e hi).inv := by
have hi' : ∃ k, e.f k = i' := ⟨i, hi⟩
have : hi'.choose = i := e.injective_f (by rw [hi'.choose_spec, hi])
grind [f]
@[reassoc (attr := simp)]
lemma comm (hφ : e.HasLift φ) (i' j' : ι') :
f φ i' ≫ (L.extend e).d i' j' = K.d i' j' ≫ f φ j' := by
by_cases hij' : c'.Rel i' j'
· by_cases hi' : ∃ i, e.f i = i'
· obtain ⟨i, hi⟩ := hi'
rw [f_eq φ hi]
by_cases hj' : ∃ j, e.f j = j'
· obtain ⟨j, hj⟩ := hj'
rw [f_eq φ hj, L.extend_d_eq e hi hj]
subst hi hj
simp [HomologicalComplex.restrictionXIso]
· apply (L.isZero_extend_X e j' (by simpa using hj')).eq_of_tgt
· have : (L.extend e).d i' j' = 0 := by
apply (L.isZero_extend_X e i' (by simpa using hi')).eq_of_src
rw [this, comp_zero]
by_cases hj' : ∃ j, e.f j = j'
· obtain ⟨j, rfl⟩ := hj'
rw [f_eq φ rfl]
dsimp [restrictionXIso]
rw [id_comp, reassoc_of% (hφ j (e.boundaryGE hij'
(by simpa using hi')) i' hij'), zero_comp]
· have : f φ j' = 0 := by
apply (L.isZero_extend_X e j' (by simpa using hj')).eq_of_tgt
rw [this, comp_zero]
· simp [HomologicalComplex.shape _ _ _ hij']
end liftExtend
variable (φ : K.restriction e ⟶ L) (hφ : e.HasLift φ)
/-- The morphism `K ⟶ L.extend e` given by a morphism `K.restriction e ⟶ L`
which satisfy `e.HasLift φ`. -/
noncomputable def liftExtend :
K ⟶ L.extend e where
f i' := liftExtend.f φ i'
comm' _ _ _ := liftExtend.comm φ hφ _ _
variable {i' : ι'} {i : ι} (hi : e.f i = i')
lemma liftExtend_f :
(e.liftExtend φ hφ).f i' = (K.restrictionXIso e hi).inv ≫ φ.f i ≫
(L.extendXIso e hi).inv := by
apply liftExtend.f_eq
/-- Given `φ : K.restriction e ⟶ L` such that `hφ : e.HasLift φ`, this is
the isomorphisms in the category of arrows between the maps
`(e.liftExtend φ hφ).f i'` and `φ.f i` when `e.f i = i'`. -/
noncomputable def liftExtendfArrowIso :
Arrow.mk ((e.liftExtend φ hφ).f i') ≅ Arrow.mk (φ.f i) :=
Arrow.isoMk (K.restrictionXIso e hi).symm (L.extendXIso e hi)
(by simp [e.liftExtend_f φ hφ hi])
lemma isIso_liftExtend_f_iff (hi : e.f i = i') :
IsIso ((e.liftExtend φ hφ).f i') ↔ IsIso (φ.f i) :=
(MorphismProperty.isomorphisms C).arrow_mk_iso_iff (e.liftExtendfArrowIso φ hφ hi)
lemma mono_liftExtend_f_iff (hi : e.f i = i') :
Mono ((e.liftExtend φ hφ).f i') ↔ Mono (φ.f i) :=
(MorphismProperty.monomorphisms C).arrow_mk_iso_iff (e.liftExtendfArrowIso φ hφ hi)
lemma epi_liftExtend_f_iff (hi : e.f i = i') :
Epi ((e.liftExtend φ hφ).f i') ↔ Epi (φ.f i) :=
(MorphismProperty.epimorphisms C).arrow_mk_iso_iff (e.liftExtendfArrowIso φ hφ hi)
end
namespace homRestrict
variable {e}
variable (ψ : K ⟶ L.extend e)
/-- Auxiliary definition for `Embedding.homRestrict`. -/
noncomputable def f (i : ι) : (K.restriction e).X i ⟶ L.X i :=
ψ.f (e.f i) ≫ (L.extendXIso e rfl).hom
lemma f_eq {i : ι} {i' : ι'} (h : e.f i = i') :
f ψ i = (K.restrictionXIso e h).hom ≫ ψ.f i' ≫ (L.extendXIso e h).hom := by
subst h
simp [f, restrictionXIso]
@[reassoc (attr := simp)]
lemma comm (i j : ι) :
f ψ i ≫ L.d i j = K.d (e.f i) (e.f j) ≫ f ψ j := by
dsimp [f]
simp only [assoc, ← ψ.comm_assoc, L.extend_d_eq e rfl rfl, Iso.inv_hom_id, comp_id]
end homRestrict
/-- The morphism `K.restriction e ⟶ L` induced by a morphism `K ⟶ L.extend e`. -/
noncomputable def homRestrict (ψ : K ⟶ L.extend e) : K.restriction e ⟶ L where
f i := homRestrict.f ψ i
lemma homRestrict_f (ψ : K ⟶ L.extend e) {i : ι} {i' : ι'} (h : e.f i = i') :
(e.homRestrict ψ).f i = (K.restrictionXIso e h).hom ≫ ψ.f i' ≫ (L.extendXIso e h).hom :=
homRestrict.f_eq ψ h
lemma homRestrict_hasLift (ψ : K ⟶ L.extend e) :
e.HasLift (e.homRestrict ψ) := by
intro j hj i' hij'
have : (L.extend e).d i' (e.f j) = 0 := by
apply (L.isZero_extend_X e i' (hj.notMem hij')).eq_of_src
dsimp [homRestrict]
rw [homRestrict.f_eq ψ rfl, restrictionXIso, eqToIso_refl, Iso.refl_hom, id_comp,
← ψ.comm_assoc, this, zero_comp, comp_zero]
@[simp]
lemma liftExtend_homRestrict (ψ : K ⟶ L.extend e) :
e.liftExtend (e.homRestrict ψ) (e.homRestrict_hasLift ψ) = ψ := by
ext i'
by_cases hi' : ∃ i, e.f i = i'
· obtain ⟨i, rfl⟩ := hi'
simp [e.homRestrict_f _ rfl, e.liftExtend_f _ _ rfl]
· apply (L.isZero_extend_X e i' (by simpa using hi')).eq_of_tgt
@[simp]
lemma homRestrict_liftExtend (φ : K.restriction e ⟶ L) (hφ : e.HasLift φ) :
e.homRestrict (e.liftExtend φ hφ) = φ := by
ext i
simp [e.homRestrict_f _ rfl, e.liftExtend_f _ _ rfl]
@[reassoc]
lemma homRestrict_precomp (α : K' ⟶ K) (ψ : K ⟶ L.extend e) :
e.homRestrict (α ≫ ψ) = restrictionMap α e ≫ e.homRestrict ψ := by
ext i
simp [homRestrict_f _ _ rfl, restrictionXIso]
@[reassoc]
lemma homRestrict_comp_extendMap (ψ : K ⟶ L.extend e) (β : L ⟶ L') :
e.homRestrict (ψ ≫ extendMap β e) =
e.homRestrict ψ ≫ β := by
ext i
simp [homRestrict_f _ _ rfl, extendMap_f β e rfl]
variable (K L)
/-- The bijection between `K ⟶ L.extend e` and the subtype of `K.restriction e ⟶ L`
consisting of morphisms `φ` such that `e.HasLift φ`. -/
@[simps]
noncomputable def homEquiv :
(K ⟶ L.extend e) ≃ { φ : K.restriction e ⟶ L // e.HasLift φ } where
toFun ψ := ⟨e.homRestrict ψ, e.homRestrict_hasLift ψ⟩
invFun φ := e.liftExtend φ.1 φ.2
left_inv ψ := by simp
right_inv φ := by simp
end Embedding
end ComplexShape |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.