use crate::algebra::AlgebraBuildError;
use crate::hom::{Morphism, cokernel};
use crate::module::{Module, same_morphism_data, same_representation, same_slice};
use crate::opposite::{dual, dual_morphism, opposite};
use crate::resolution::{Bounded, ResolutionEnd, bounded_dimension, projective_cover, resolve};
pub fn injective_envelope(m: &Module) -> Result<(Module, Morphism), AlgebraBuildError> {
let op = opposite(m.algebra())?;
let dm = dual(m, &op).expect("m lives over the algebra side of its own opposite pair");
let (cover_term, cover) = projective_cover(&dm);
let envelope =
dual(&cover_term, &op).expect("the cover of D(m) lives over the opposite side of the pair");
let embedding = dual_morphism(&cover, m, &envelope, &op)
.expect("D(D(m)) is m entry for entry, and the envelope is D of the cover term");
Ok((envelope, embedding))
}
#[derive(Clone)]
pub struct InjectiveCoresolution {
pub terms: Vec<Module>,
pub maps: Vec<Morphism>,
pub coaugmentation: Morphism,
pub end: ResolutionEnd,
}
impl InjectiveCoresolution {
pub(crate) fn agrees_with(&self, other: &InjectiveCoresolution) -> bool {
self.end == other.end
&& same_slice(&self.terms, &other.terms, same_representation)
&& same_slice(&self.maps, &other.maps, same_morphism_data)
&& same_morphism_data(&self.coaugmentation, &other.coaugmentation)
}
}
#[derive(Clone)]
pub enum CosyzygyWitness {
Identity,
Coresolution(InjectiveCoresolution),
}
#[derive(Clone)]
pub struct Cosyzygy {
source: Module,
degree: usize,
module: Module,
witness: CosyzygyWitness,
}
impl Cosyzygy {
accessor_methods! {
pub source() -> &Module = |this| &this.source;
pub degree() -> usize = |this| this.degree;
pub module() -> &Module = |this| &this.module;
pub witness() -> &CosyzygyWitness = |this| &this.witness;
}
pub fn verify(&self) -> bool {
let Ok(rebuilt) = cosyzygy(&self.source, self.degree) else {
return false;
};
same_representation(&self.module, &rebuilt.module)
&& match (&self.witness, &rebuilt.witness) {
(CosyzygyWitness::Identity, CosyzygyWitness::Identity) => true,
(CosyzygyWitness::Coresolution(left), CosyzygyWitness::Coresolution(right)) => {
left.agrees_with(right)
}
_ => false,
}
}
}
debug_fields! { Cosyzygy |this| {
"degree" => this.degree;
"source" => this.source.dim_vector();
"module" => this.module.dim_vector();
} }
pub fn coresolve(m: &Module, steps: usize) -> Result<InjectiveCoresolution, AlgebraBuildError> {
let op = opposite(m.algebra())?;
let dm = dual(m, &op).expect("m lives over the algebra side of its own opposite pair");
let resolution = resolve(&dm, steps);
let terms: Vec<Module> = resolution
.terms
.iter()
.map(|p| dual(p, &op).expect("resolution terms live over the opposite side of the pair"))
.collect();
let coaugmentation = dual_morphism(&resolution.augmentation, m, &terms[0], &op)
.expect("D(D(m)) is m entry for entry, and terms[0] is D(P_0)");
let maps = resolution
.maps
.iter()
.enumerate()
.map(|(k, d)| {
dual_morphism(d, &terms[k], &terms[k + 1], &op)
.expect("terms[k] is D(P_k) and terms[k + 1] is D(P_{k+1})")
})
.collect();
Ok(InjectiveCoresolution {
terms,
maps,
coaugmentation,
end: resolution.end,
})
}
pub fn cosyzygy(m: &Module, degree: usize) -> Result<Cosyzygy, AlgebraBuildError> {
if degree == 0 {
return Ok(Cosyzygy {
source: m.clone(),
degree,
module: m.clone(),
witness: CosyzygyWitness::Identity,
});
}
let coresolution = coresolve(m, degree - 1)?;
let module = if coresolution.terms.len() < degree {
Module::zero(m.algebra())
} else {
let boundary = if degree == 1 {
&coresolution.coaugmentation
} else {
&coresolution.maps[degree - 2]
};
cokernel(boundary).0
};
Ok(Cosyzygy {
source: m.clone(),
degree,
module,
witness: CosyzygyWitness::Coresolution(coresolution),
})
}
pub fn injective_dimension(m: &Module, bound: usize) -> Result<Bounded<usize>, AlgebraBuildError> {
let coresolution = coresolve(m, bound)?;
Ok(bounded_dimension(
coresolution.end,
coresolution.terms.len(),
))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::algebra::{
Algebra, an_with_relations, commutative_square, cyclic_nakayama, dual_numbers, linear_an,
linear_nakayama, radical_square_zero_cycle, truncated_poly,
};
use crate::field::PrimeField;
use crate::hom::{image, kernel};
use crate::iso::{IsoOutcome, is_isomorphic};
use crate::module::direct_sum;
use crate::radical::socle;
use std::sync::Arc;
fn fields() -> [PrimeField; 3] {
[
PrimeField::new(2).unwrap(),
PrimeField::new(5).unwrap(),
PrimeField::new(32003).unwrap(),
]
}
fn socle_injective_sum(m: &Module) -> Module {
let algebra = m.algebra();
let (soc, _) = socle(m);
let mut parts = Vec::new();
for v in 0..algebra.quiver().num_vertices() {
for _ in 0..soc.dim_at(v) {
parts.push(Module::injective(algebra, v));
}
}
if parts.is_empty() {
return Module::zero(algebra);
}
let refs: Vec<&Module> = parts.iter().collect();
direct_sum(&refs).0
}
fn is_mono(f: &Morphism) -> bool {
let field = f.source().field();
(0..f.source().algebra().quiver().num_vertices())
.all(|v| f.map_at(v).rank(&field) == f.source().dim_at(v))
}
fn fixtures(field: PrimeField) -> Vec<Arc<Algebra>> {
vec![
linear_an(3, field),
an_with_relations(3, &[(0, 2)], field).unwrap(),
dual_numbers(field),
truncated_poly(3, field).unwrap(),
radical_square_zero_cycle(3, field),
cyclic_nakayama(&[3, 3, 3], field).unwrap(),
commutative_square(field),
]
}
fn assorted_modules(algebra: &Arc<Algebra>) -> Vec<Module> {
let n = algebra.quiver().num_vertices();
let mut modules = vec![Module::zero(algebra)];
for v in 0..n {
modules.push(Module::simple(algebra, v));
modules.push(Module::projective(algebra, v));
modules.push(Module::injective(algebra, v));
}
let s0 = Module::simple(algebra, 0);
let p_last = Module::projective(algebra, n - 1);
modules.push(direct_sum(&[&s0, &p_last]).0);
modules
}
#[test]
fn envelope_of_a_simple_is_the_indecomposable_injective() {
for field in fields() {
for algebra in fixtures(field) {
for v in 0..algebra.quiver().num_vertices() {
let s = Module::simple(&algebra, v);
let (envelope, embedding) = injective_envelope(&s).unwrap();
let i_v = Module::injective(&algebra, v);
assert_eq!(envelope.dim_vector(), i_v.dim_vector(), "I(S_{v})");
assert!(is_mono(&embedding));
assert!(embedding.source().ptr_eq(&s));
}
}
}
}
#[test]
fn envelope_of_the_zero_module_is_zero() {
let algebra = linear_an(3, PrimeField::new(5).unwrap());
let z = Module::zero(&algebra);
let (envelope, embedding) = injective_envelope(&z).unwrap();
assert!(envelope.is_zero());
assert!(embedding.is_zero());
assert_eq!(injective_dimension(&z, 4).unwrap(), Bounded::Exact(0));
}
#[test]
fn envelope_agrees_with_the_socle_direct_sum_and_is_essential() {
for field in fields() {
for algebra in fixtures(field) {
for m in assorted_modules(&algebra) {
let (envelope, embedding) = injective_envelope(&m).unwrap();
let by_socle = socle_injective_sum(&m);
assert_eq!(
envelope.dim_vector(),
by_socle.dim_vector(),
"envelope of {:?} over F_{}",
m.dim_vector(),
field.modulus()
);
assert!(is_mono(&embedding));
assert_eq!(
socle(&envelope).0.dim_vector(),
socle(&m).0.dim_vector(),
"essential image for {:?}",
m.dim_vector()
);
}
}
}
}
#[test]
fn envelope_is_isomorphic_to_the_socle_direct_sum() {
for field in fields() {
for algebra in [
linear_an(3, field),
an_with_relations(3, &[(0, 2)], field).unwrap(),
] {
for m in assorted_modules(&algebra) {
let (envelope, _) = injective_envelope(&m).unwrap();
let by_socle = socle_injective_sum(&m);
assert!(
matches!(
is_isomorphic(&envelope, &by_socle).unwrap(),
IsoOutcome::Isomorphic(_)
),
"envelope of {:?} over F_{}",
m.dim_vector(),
field.modulus()
);
}
}
}
}
#[test]
fn a3_simples_have_injective_dimensions_0_1_1() {
for field in fields() {
let algebra = linear_an(3, field);
let expected = [0usize, 1, 1];
for v in 0..3u32 {
let s = Module::simple(&algebra, v);
assert_eq!(
injective_dimension(&s, 5).unwrap(),
Bounded::Exact(expected[v as usize]),
"id S_{v}"
);
}
}
}
#[test]
fn a3_mod_ab_simple_2_coresolves_through_i2_i1_i0() {
for field in fields() {
let algebra = an_with_relations(3, &[(0, 2)], field).unwrap();
let s2 = Module::simple(&algebra, 2);
let coresolution = coresolve(&s2, 5).unwrap();
assert_eq!(coresolution.end, ResolutionEnd::Finite);
let dims: Vec<&[usize]> = coresolution.terms.iter().map(Module::dim_vector).collect();
assert_eq!(dims, vec![&[0, 1, 1][..], &[1, 1, 0], &[1, 0, 0]]);
assert_eq!(injective_dimension(&s2, 5).unwrap(), Bounded::Exact(2));
let s1 = Module::simple(&algebra, 1);
let s0 = Module::simple(&algebra, 0);
assert_eq!(injective_dimension(&s1, 5).unwrap(), Bounded::Exact(1));
assert_eq!(injective_dimension(&s0, 5).unwrap(), Bounded::Exact(0));
}
}
#[test]
fn truncated_poly_projectives_are_injective() {
for field in fields() {
for n in 2..5 {
let algebra = truncated_poly(n, field).unwrap();
let p = Module::projective(&algebra, 0);
assert_eq!(
injective_dimension(&p, 6).unwrap(),
Bounded::Exact(0),
"id A for x^{n}"
);
let i = Module::injective(&algebra, 0);
assert_eq!(p.dim_vector(), i.dim_vector());
}
}
}
#[test]
fn dual_numbers_simple_coresolves_periodically() {
for field in fields() {
let algebra = dual_numbers(field);
let s = Module::simple(&algebra, 0);
let coresolution = coresolve(&s, 6).unwrap();
assert_eq!(coresolution.end, ResolutionEnd::Cut { at: 6 });
assert_eq!(coresolution.terms.len(), 7);
for term in &coresolution.terms {
assert_eq!(term.dim_vector(), &[2]);
}
assert_eq!(injective_dimension(&s, 10).unwrap(), Bounded::AtLeast(11));
}
}
#[test]
fn iterated_cosyzygies_keep_their_minimal_coresolution_witness() {
for field in fields() {
let algebra = dual_numbers(field);
let simple = Module::simple(&algebra, 0);
for degree in 0..5 {
let value = cosyzygy(&simple, degree).unwrap();
assert_eq!(value.source().dim_vector(), &[1]);
assert_eq!(value.degree(), degree);
assert_eq!(value.module().dim_vector(), &[1]);
assert!(value.verify());
assert_eq!(
matches!(value.witness(), CosyzygyWitness::Identity),
degree == 0
);
}
}
}
#[test]
fn cosyzygy_is_zero_past_a_finite_coresolution() {
let algebra = linear_an(3, PrimeField::new(5).unwrap());
let simple = Module::simple(&algebra, 2);
assert_eq!(
cosyzygy(&simple, 0).unwrap().module().dim_vector(),
&[0, 0, 1]
);
assert_eq!(
cosyzygy(&simple, 1).unwrap().module().dim_vector(),
&[1, 1, 0]
);
assert!(cosyzygy(&simple, 2).unwrap().module().is_zero());
let injective = Module::injective(&algebra, 1);
assert!(cosyzygy(&injective, 1).unwrap().module().is_zero());
}
#[test]
fn a_cosyzygy_with_a_changed_degree_fails_verification() {
let algebra = dual_numbers(PrimeField::new(5).unwrap());
let mut value = cosyzygy(&Module::simple(&algebra, 0), 2).unwrap();
value.degree = 1;
assert!(!value.verify());
}
#[test]
fn cyclic_nakayama_is_self_injective_and_linear_nakayama_is_not() {
for field in fields() {
let cyclic = cyclic_nakayama(&[3, 3, 3], field).unwrap();
for v in 0..3u32 {
let p = Module::projective(&cyclic, v);
assert_eq!(
injective_dimension(&p, 6).unwrap(),
Bounded::Exact(0),
"id P_{v}"
);
}
let linear = linear_nakayama(&[3, 2, 1], field).unwrap();
let p1 = Module::projective(&linear, 1);
assert_eq!(p1.dim_vector(), &[0, 1, 1]);
assert_eq!(injective_dimension(&p1, 6).unwrap(), Bounded::Exact(1));
}
}
#[test]
fn coresolve_with_zero_steps_reports_cut_for_a_noninjective_module() {
let field = PrimeField::new(32003).unwrap();
let algebra = linear_an(3, field);
let s2 = Module::simple(&algebra, 2);
let coresolution = coresolve(&s2, 0).unwrap();
assert_eq!(coresolution.end, ResolutionEnd::Cut { at: 0 });
assert_eq!(coresolution.terms.len(), 1);
let i0 = Module::injective(&algebra, 0);
assert_eq!(coresolve(&i0, 0).unwrap().end, ResolutionEnd::Finite);
}
#[test]
fn coresolution_prefixes_are_complexes_and_exact() {
for field in fields() {
for algebra in fixtures(field) {
for m in assorted_modules(&algebra) {
let coresolution = coresolve(&m, 4).unwrap();
assert!(is_mono(&coresolution.coaugmentation));
if let Some(d0) = coresolution.maps.first() {
assert!(
coresolution.coaugmentation.then(d0).unwrap().is_zero(),
"d^0 ∘ ι = 0"
);
}
for pair in coresolution.maps.windows(2) {
assert!(pair[0].then(&pair[1]).unwrap().is_zero(), "d² = 0");
}
for k in 0..coresolution.terms.len() {
let (incoming, _) = if k == 0 {
image(&coresolution.coaugmentation)
} else {
image(&coresolution.maps[k - 1])
};
if k + 1 < coresolution.terms.len() {
let (ker, _) = kernel(&coresolution.maps[k]);
assert_eq!(
ker.dim_vector(),
incoming.dim_vector(),
"exactness at I^{k}"
);
} else if coresolution.end == ResolutionEnd::Finite {
assert_eq!(
incoming.dim_vector(),
coresolution.terms[k].dim_vector(),
"a finite coresolution ends onto its last term"
);
}
}
}
}
}
}
#[test]
fn differentials_vanish_on_socles() {
for field in fields() {
for algebra in fixtures(field) {
for m in assorted_modules(&algebra) {
let coresolution = coresolve(&m, 4).unwrap();
for (k, d) in coresolution.maps.iter().enumerate() {
let (_, inclusion) = socle(&coresolution.terms[k]);
assert!(
inclusion.then(d).unwrap().is_zero(),
"soc I^{k} survives d^{k}"
);
}
}
}
}
}
#[test]
fn every_first_term_is_the_injective_envelope() {
for field in fields() {
for algebra in fixtures(field) {
for m in assorted_modules(&algebra) {
let coresolution = coresolve(&m, 3).unwrap();
let (envelope, _) = injective_envelope(&m).unwrap();
assert_eq!(coresolution.terms[0].dim_vector(), envelope.dim_vector());
assert_eq!(
injective_dimension(&coresolution.terms[0], 3).unwrap(),
Bounded::Exact(0),
"I^0 of {:?} is injective",
m.dim_vector()
);
}
}
}
}
}