use std::fmt;
use std::sync::Arc;
use crate::algebra::{Algebra, AlgebraBuildError};
use crate::decompose::{Certificate, matrix_inverse};
use crate::dynkin::{DynkinError, dynkin_indecomposables};
use crate::endo::EndoAlgebra;
use crate::enumerate::{EnumerateError, nakayama_indecomposables};
use crate::field::{Fp, PrimeField};
use crate::hom::{HomError, Morphism};
use crate::homspace::{HomQuotient, HomSpace, HomSpaceError, HomSubspace};
use crate::indec::IndecomposableModule;
use crate::iso::indecomposable_iso;
use crate::linalg::DenseMat;
use crate::module::Module;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ArQuiverError {
Hom(HomError),
Space(HomSpaceError),
Injective(AlgebraBuildError),
UnsupportedDomain {
dynkin: DynkinError,
nakayama: EnumerateError,
},
RadicalSquareNotContained {
source: Vec<usize>,
target: Vec<usize>,
},
ResidueDegreeDoesNotDivide {
dim_vector: Vec<usize>,
base_dim: usize,
residue_degree: usize,
},
}
impl fmt::Display for ArQuiverError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Hom(error) => write!(f, "morphism rejected: {error}"),
Self::Space(error) => write!(f, "hom space rejected the input: {error}"),
Self::Injective(error) => {
write!(f, "the opposite algebra could not be built: {error}")
}
Self::UnsupportedDomain { dynkin, nakayama } => write!(
f,
"no complete enumeration applies: the Dynkin route reports {dynkin}, \
the Nakayama route reports {nakayama}"
),
Self::RadicalSquareNotContained { source, target } => write!(
f,
"the radical square of ({source:?}, {target:?}) left the radical; crate defect"
),
Self::ResidueDegreeDoesNotDivide {
dim_vector,
base_dim,
residue_degree,
} => write!(
f,
"residue degree {residue_degree} of {dim_vector:?} does not divide \
the base dimension {base_dim}; crate defect"
),
}
}
}
impl std::error::Error for ArQuiverError {}
impl From<HomError> for ArQuiverError {
fn from(error: HomError) -> ArQuiverError {
ArQuiverError::Hom(error)
}
}
impl From<HomSpaceError> for ArQuiverError {
fn from(error: HomSpaceError) -> ArQuiverError {
ArQuiverError::Space(error)
}
}
fn inverse_of(f: &Morphism) -> Option<Morphism> {
let field = f.source().field();
let mut maps = Vec::new();
for v in 0..f.source().algebra().quiver().num_vertices() {
maps.push(matrix_inverse(f.map_at(v), &field)?);
}
Morphism::new(f.target(), f.source(), maps).ok()
}
fn radical_against_iso(
space: &HomSpace,
endo: &EndoAlgebra,
u: &Morphism,
) -> Result<HomSubspace, ArQuiverError> {
let field = space.source().field();
let radical = endo.radical_basis();
let mut rows: Vec<Vec<Fp>> = Vec::with_capacity(space.dim() + radical.rows());
for f in space.basis() {
rows.push(endo.coords(&f.then(u)?));
}
for r in 0..radical.rows() {
rows.push(radical.row(r).to_vec());
}
let stacked = if rows.is_empty() {
DenseMat::zero(0, endo.dim())
} else {
DenseMat::from_rows(&rows)
};
let kernel = stacked.transpose().kernel_basis(&field);
let spanning: Vec<Morphism> = (0..kernel.rows())
.map(|k| space.morphism(&kernel.row(k)[..space.dim()]))
.collect();
Ok(space.subspace(&spanning)?)
}
pub fn category_radical(
x: &IndecomposableModule,
y: &IndecomposableModule,
) -> Result<HomSubspace, ArQuiverError> {
let space = HomSpace::new(x.module(), y.module())?;
let Some(h) = indecomposable_iso(x.module(), y.module(), x.endo()) else {
return Ok(space.full_subspace());
};
let u = inverse_of(&h).expect("the radical criterion returns an isomorphism");
radical_against_iso(&space, x.endo(), &u)
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum CatalogProvenance {
Nakayama,
DynkinZeroIdeal,
}
impl fmt::Display for CatalogProvenance {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Nakayama => f.write_str("Nakayama classification"),
Self::DynkinZeroIdeal => f.write_str("Gabriel's theorem"),
}
}
}
pub struct IndecomposableCatalog {
algebra: Arc<Algebra>,
provenance: CatalogProvenance,
entries: Vec<IndecomposableModule>,
}
impl fmt::Debug for IndecomposableCatalog {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("IndecomposableCatalog")
.field("provenance", &self.provenance)
.field("entries", &self.entries.len())
.finish()
}
}
fn certified_entries(listed: Vec<(Module, Certificate)>) -> Vec<IndecomposableModule> {
listed
.into_iter()
.map(|(m, certificate)| {
IndecomposableModule::new(&m).unwrap_or_else(|error| {
panic!(
"the enumerator listed the module {:?} with certificate {certificate:?}, \
and the locality gate rejected it: {error}; crate defect",
m.dim_vector()
)
})
})
.collect()
}
impl IndecomposableCatalog {
pub fn nakayama(algebra: &Arc<Algebra>) -> Result<IndecomposableCatalog, EnumerateError> {
let listed = nakayama_indecomposables(algebra)?;
Ok(IndecomposableCatalog {
algebra: algebra.clone(),
provenance: CatalogProvenance::Nakayama,
entries: certified_entries(listed),
})
}
pub fn dynkin(algebra: &Arc<Algebra>) -> Result<IndecomposableCatalog, DynkinError> {
let listed = dynkin_indecomposables(algebra)?;
Ok(IndecomposableCatalog {
algebra: algebra.clone(),
provenance: CatalogProvenance::DynkinZeroIdeal,
entries: certified_entries(listed),
})
}
#[inline]
pub fn algebra(&self) -> &Arc<Algebra> {
&self.algebra
}
#[inline]
pub fn provenance(&self) -> CatalogProvenance {
self.provenance
}
#[inline]
pub fn entries(&self) -> &[IndecomposableModule] {
&self.entries
}
#[inline]
pub fn len(&self) -> usize {
self.entries.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
}
}
fn span_of_composites<'a>(
space: &HomSpace,
factorizations: impl Iterator<Item = (&'a HomSubspace, &'a HomSubspace)>,
) -> Result<HomSubspace, ArQuiverError> {
let mut composites = Vec::new();
for (left, right) in factorizations {
for i in 0..left.dim() {
let f = left.basis_morphism(i);
for j in 0..right.dim() {
composites.push(f.then(&right.basis_morphism(j))?);
}
}
}
Ok(space.subspace(&composites)?)
}
pub fn radical_square_through_catalog(
catalog: &IndecomposableCatalog,
x: &IndecomposableModule,
y: &IndecomposableModule,
) -> Result<HomSubspace, ArQuiverError> {
let space = HomSpace::new(x.module(), y.module())?;
let mut legs = Vec::with_capacity(catalog.len());
for z in catalog.entries() {
legs.push((category_radical(x, z)?, category_radical(z, y)?));
}
span_of_composites(&space, legs.iter().map(|(left, right)| (left, right)))
}
pub fn irreducible_quotient(
catalog: &IndecomposableCatalog,
x: &IndecomposableModule,
y: &IndecomposableModule,
) -> Result<HomQuotient, ArQuiverError> {
let radical = category_radical(x, y)?;
let square = radical_square_through_catalog(catalog, x, y)?;
quotient_or_defect(&radical, &square)
}
fn quotient_or_defect(
radical: &HomSubspace,
square: &HomSubspace,
) -> Result<HomQuotient, ArQuiverError> {
radical.quotient_by(square).map_err(|error| match error {
HomSpaceError::NotContained => ArQuiverError::RadicalSquareNotContained {
source: radical.source().dim_vector().to_vec(),
target: radical.target().dim_vector().to_vec(),
},
other => ArQuiverError::Space(other),
})
}
#[derive(Debug)]
pub struct ArVertex {
id: usize,
module: IndecomposableModule,
residue_degree: usize,
projective: bool,
injective: bool,
}
impl ArVertex {
#[inline]
pub fn id(&self) -> usize {
self.id
}
#[inline]
pub fn module(&self) -> &IndecomposableModule {
&self.module
}
#[inline]
pub fn residue_degree(&self) -> usize {
self.residue_degree
}
#[inline]
pub fn projective(&self) -> bool {
self.projective
}
#[inline]
pub fn injective(&self) -> bool {
self.injective
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ArrowValuation {
Plain(usize),
Valued {
base_dim: usize,
over_source: usize,
over_target: usize,
},
}
#[derive(Debug)]
pub struct ArArrow {
source: usize,
target: usize,
base_dim: usize,
over_source_residue: usize,
over_target_residue: usize,
representatives: Vec<Morphism>,
}
impl ArArrow {
#[inline]
pub fn source(&self) -> usize {
self.source
}
#[inline]
pub fn target(&self) -> usize {
self.target
}
#[inline]
pub fn base_dim(&self) -> usize {
self.base_dim
}
#[inline]
pub fn over_source_residue(&self) -> usize {
self.over_source_residue
}
#[inline]
pub fn over_target_residue(&self) -> usize {
self.over_target_residue
}
#[inline]
pub fn representatives(&self) -> &[Morphism] {
&self.representatives
}
pub fn valuation(&self) -> ArrowValuation {
if self.base_dim == self.over_source_residue && self.base_dim == self.over_target_residue {
ArrowValuation::Plain(self.base_dim)
} else {
ArrowValuation::Valued {
base_dim: self.base_dim,
over_source: self.over_source_residue,
over_target: self.over_target_residue,
}
}
}
}
#[derive(Debug)]
pub struct ArQuiver {
catalog: IndecomposableCatalog,
vertices: Vec<ArVertex>,
arrows: Vec<ArArrow>,
}
impl ArQuiver {
#[inline]
pub fn catalog(&self) -> &IndecomposableCatalog {
&self.catalog
}
#[inline]
pub fn vertices(&self) -> &[ArVertex] {
&self.vertices
}
#[inline]
pub fn arrows(&self) -> &[ArArrow] {
&self.arrows
}
}
fn over_residue(
base_dim: usize,
residue_degree: usize,
module: &Module,
) -> Result<usize, ArQuiverError> {
if residue_degree == 0 || !base_dim.is_multiple_of(residue_degree) {
return Err(ArQuiverError::ResidueDegreeDoesNotDivide {
dim_vector: module.dim_vector().to_vec(),
base_dim,
residue_degree,
});
}
Ok(base_dim / residue_degree)
}
fn unit(dim: usize, k: usize, field: &PrimeField) -> Vec<Fp> {
let mut coords = vec![field.zero(); dim];
coords[k] = field.one();
coords
}
fn vertices_of(catalog: &IndecomposableCatalog) -> Result<Vec<ArVertex>, ArQuiverError> {
let mut vertices = Vec::with_capacity(catalog.len());
for (id, entry) in catalog.entries().iter().enumerate() {
let module = IndecomposableModule::new(entry.module())
.expect("a catalog entry passed the same gate already");
let injective = module.is_injective().map_err(ArQuiverError::Injective)?;
vertices.push(ArVertex {
id,
residue_degree: module.residue_degree(),
projective: module.is_projective(),
injective,
module,
});
}
Ok(vertices)
}
fn quiver_of(catalog: IndecomposableCatalog) -> Result<ArQuiver, ArQuiverError> {
let vertices = vertices_of(&catalog)?;
let n = catalog.len();
let mut radicals = Vec::with_capacity(n * n);
for x in catalog.entries() {
for y in catalog.entries() {
radicals.push(category_radical(x, y)?);
}
}
let mut arrows = Vec::new();
for i in 0..n {
for j in 0..n {
let space =
HomSpace::new(catalog.entries()[i].module(), catalog.entries()[j].module())?;
let square = span_of_composites(
&space,
(0..n).map(|k| (&radicals[i * n + k], &radicals[k * n + j])),
)?;
let quotient = quotient_or_defect(&radicals[i * n + j], &square)?;
let base_dim = quotient.dim();
if base_dim == 0 {
continue;
}
let field = space.source().field();
arrows.push(ArArrow {
source: i,
target: j,
base_dim,
over_source_residue: over_residue(
base_dim,
vertices[i].residue_degree,
space.source(),
)?,
over_target_residue: over_residue(
base_dim,
vertices[j].residue_degree,
space.target(),
)?,
representatives: (0..base_dim)
.map(|k| quotient.representative(&unit(base_dim, k, &field)))
.collect(),
});
}
}
Ok(ArQuiver {
catalog,
vertices,
arrows,
})
}
pub fn ar_quiver(algebra: &Arc<Algebra>) -> Result<ArQuiver, ArQuiverError> {
let catalog = match IndecomposableCatalog::dynkin(algebra) {
Ok(catalog) => catalog,
Err(dynkin) => match IndecomposableCatalog::nakayama(algebra) {
Ok(catalog) => catalog,
Err(nakayama) => return Err(ArQuiverError::UnsupportedDomain { dynkin, nakayama }),
},
};
quiver_of(catalog)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::algebra::{
MonomialPresentation, commutative_square, cyclic_nakayama, kronecker, linear_an,
monomial_completion_limits, radical_square_zero_cycle, truncated_poly,
};
use crate::dynkin::{DynkinType, dynkin_quiver};
use crate::hom::hom;
use crate::module::Module;
use crate::quiver::Quiver;
fn f2() -> PrimeField {
PrimeField::new(2).unwrap()
}
fn f5() -> PrimeField {
PrimeField::new(5).unwrap()
}
fn path_algebra(quiver: Quiver, field: PrimeField) -> Arc<Algebra> {
let presentation = MonomialPresentation::new(quiver, Vec::new())
.expect("an acyclic quiver has a finite path algebra");
Algebra::from_monomial(
field,
&presentation,
&monomial_completion_limits(&presentation),
)
.expect("the zero ideal over an acyclic quiver completes")
}
fn d4(field: PrimeField) -> Arc<Algebra> {
path_algebra(
dynkin_quiver(DynkinType::D(4)).expect("D_4 has a quiver"),
field,
)
}
fn indec(m: &Module) -> IndecomposableModule {
IndecomposableModule::new(m).expect("the fixture module is indecomposable")
}
fn dim_vectors(quiver: &ArQuiver) -> Vec<Vec<usize>> {
quiver
.vertices()
.iter()
.map(|v| v.module().module().dim_vector().to_vec())
.collect()
}
fn arrow_triples(quiver: &ArQuiver) -> Vec<(usize, usize, usize)> {
quiver
.arrows()
.iter()
.map(|a| (a.source(), a.target(), a.base_dim()))
.collect()
}
fn flags(quiver: &ArQuiver) -> Vec<(bool, bool)> {
quiver
.vertices()
.iter()
.map(|v| (v.projective(), v.injective()))
.collect()
}
fn f8_module() -> Module {
let field = f2();
let algebra = kronecker(2, field);
let mut companion = DenseMat::zero(3, 3);
companion.set(0, 1, field.one());
companion.set(1, 2, field.one());
companion.set(2, 0, field.one());
companion.set(2, 1, field.one());
Module::new(algebra, vec![3, 3], vec![DenseMat::identity(3), companion])
.expect("the Kronecker representation is a module")
}
#[test]
fn the_radical_between_distinct_simples_is_the_whole_hom_space() {
for field in [f2(), f5()] {
let algebra = linear_an(3, field);
let simples: Vec<IndecomposableModule> = (0..3)
.map(|v| indec(&Module::simple(&algebra, v)))
.collect();
for x in &simples {
for y in &simples {
let space = HomSpace::new(x.module(), y.module()).unwrap();
let radical = category_radical(x, y).unwrap();
if x.module().ptr_eq(y.module()) {
assert_eq!(space.dim(), 1);
assert_eq!(radical.dim(), 0);
} else {
assert_eq!(space.dim(), 0);
assert_eq!(radical, space.full_subspace());
}
}
}
}
}
#[test]
fn the_radical_from_a_projective_onto_its_top_is_the_whole_hom_line() {
for field in [f2(), f5()] {
let algebra = linear_an(3, field);
let p0 = indec(&Module::projective(&algebra, 0));
let s0 = indec(&Module::simple(&algebra, 0));
let space = HomSpace::new(p0.module(), s0.module()).unwrap();
assert_eq!(space.dim(), 1);
let radical = category_radical(&p0, &s0).unwrap();
assert_eq!(radical.dim(), 1);
assert_eq!(radical, space.full_subspace());
assert!(radical.contains(&space.basis()[0]).unwrap());
}
}
#[test]
fn the_radical_does_not_depend_on_the_chosen_isomorphism() {
for field in [f2(), f5()] {
let algebra = truncated_poly(3, field).unwrap();
let catalog = IndecomposableCatalog::nakayama(&algebra).unwrap();
let x = indec(&Module::projective(&algebra, 0));
let y = &catalog.entries()[2];
assert_eq!(y.module().total_dim(), 3);
assert!(!x.module().ptr_eq(y.module()));
let space = HomSpace::new(x.module(), y.module()).unwrap();
assert_eq!(space.dim(), 3);
let first = inverse_of(
&indecomposable_iso(x.module(), y.module(), x.endo())
.expect("the two copies are isomorphic"),
)
.unwrap();
let endo = x.endo();
assert_eq!(endo.radical_dim(), 2);
let mut automorphism = endo.one().to_vec();
for (c, entry) in automorphism.iter_mut().enumerate() {
*entry = field.add(*entry, endo.radical_basis().get(0, c));
}
let second = first.then(&endo.morphism(&automorphism)).unwrap();
assert!(second.is_isomorphism());
assert_ne!(first, second);
let by_first = radical_against_iso(&space, endo, &first).unwrap();
let by_second = radical_against_iso(&space, endo, &second).unwrap();
assert_eq!(by_first.dim(), 2);
assert_eq!(by_first, by_second);
assert_eq!(by_first, category_radical(&x, y).unwrap());
}
}
#[test]
fn the_radical_of_the_f8_module_is_zero_with_residue_degree_3_bookkeeping() {
let w = indec(&f8_module());
assert_eq!(w.residue_degree(), 3);
assert_eq!(w.endo().radical_dim(), 0);
let space = HomSpace::new(w.module(), w.module()).unwrap();
assert_eq!(space.dim(), 3);
let radical = category_radical(&w, &w).unwrap();
assert_eq!(radical.dim(), 0);
assert_eq!(over_residue(space.dim(), 3, w.module()).unwrap(), 1);
assert_eq!(over_residue(radical.dim(), 3, w.module()).unwrap(), 0);
}
#[test]
fn a_residue_degree_that_does_not_divide_is_a_typed_defect() {
let w = f8_module();
assert_eq!(
over_residue(2, 3, &w).unwrap_err(),
ArQuiverError::ResidueDegreeDoesNotDivide {
dim_vector: vec![3, 3],
base_dim: 2,
residue_degree: 3,
}
);
assert_eq!(
over_residue(1, 0, &w).unwrap_err(),
ArQuiverError::ResidueDegreeDoesNotDivide {
dim_vector: vec![3, 3],
base_dim: 1,
residue_degree: 0,
}
);
}
#[test]
fn valued_arrow_arithmetic_and_the_division_gate_are_pinned() {
let w = f8_module();
let valued = ArArrow {
source: 0,
target: 1,
base_dim: 6,
over_source_residue: over_residue(6, 2, &w).unwrap(),
over_target_residue: over_residue(6, 3, &w).unwrap(),
representatives: Vec::new(),
};
assert_eq!(
valued.valuation(),
ArrowValuation::Valued {
base_dim: 6,
over_source: 3,
over_target: 2,
}
);
let one_sided = ArArrow {
source: 0,
target: 1,
base_dim: 6,
over_source_residue: over_residue(6, 1, &w).unwrap(),
over_target_residue: over_residue(6, 3, &w).unwrap(),
representatives: Vec::new(),
};
assert_eq!(
one_sided.valuation(),
ArrowValuation::Valued {
base_dim: 6,
over_source: 6,
over_target: 2,
}
);
let plain = ArArrow {
source: 0,
target: 1,
base_dim: 6,
over_source_residue: over_residue(6, 1, &w).unwrap(),
over_target_residue: over_residue(6, 1, &w).unwrap(),
representatives: Vec::new(),
};
assert_eq!(plain.valuation(), ArrowValuation::Plain(6));
assert_eq!(
over_residue(5, 3, &w).unwrap_err(),
ArQuiverError::ResidueDegreeDoesNotDivide {
dim_vector: vec![3, 3],
base_dim: 5,
residue_degree: 3,
}
);
}
#[test]
fn the_radical_square_on_linear_a3_matches_the_hand_checked_factorizations() {
for field in [f2(), f5()] {
let algebra = linear_an(3, field);
let catalog = IndecomposableCatalog::dynkin(&algebra).unwrap();
let p0 = indec(&Module::projective(&algebra, 0));
let s0 = indec(&Module::simple(&algebra, 0));
let m01 = indec(&Module::injective(&algebra, 1));
assert_eq!(m01.module().dim_vector(), [1, 1, 0]);
assert_eq!(category_radical(&p0, &s0).unwrap().dim(), 1);
assert_eq!(
radical_square_through_catalog(&catalog, &p0, &s0)
.unwrap()
.dim(),
1
);
assert_eq!(irreducible_quotient(&catalog, &p0, &s0).unwrap().dim(), 0);
assert_eq!(category_radical(&p0, &m01).unwrap().dim(), 1);
assert_eq!(
radical_square_through_catalog(&catalog, &p0, &m01)
.unwrap()
.dim(),
0
);
assert_eq!(irreducible_quotient(&catalog, &p0, &m01).unwrap().dim(), 1);
}
}
#[test]
fn linear_a3_has_the_hand_derived_zigzag_ar_quiver() {
for field in [f2(), f5()] {
let algebra = linear_an(3, field);
let quiver = ar_quiver(&algebra).unwrap();
assert_eq!(
quiver.catalog().provenance(),
CatalogProvenance::DynkinZeroIdeal
);
assert_eq!(
dim_vectors(&quiver),
vec![
vec![0, 0, 1],
vec![0, 1, 0],
vec![1, 0, 0],
vec![0, 1, 1],
vec![1, 1, 0],
vec![1, 1, 1],
]
);
assert_eq!(
flags(&quiver),
vec![
(true, false),
(false, false),
(false, true),
(true, false),
(false, true),
(true, true),
]
);
assert_eq!(
arrow_triples(&quiver),
vec![
(0, 3, 1),
(1, 4, 1),
(3, 1, 1),
(3, 5, 1),
(4, 2, 1),
(5, 4, 1),
]
);
}
}
#[test]
fn truncated_poly_3_has_the_ar_quiver_of_k_x_mod_x_cubed() {
for field in [f2(), f5()] {
let algebra = truncated_poly(3, field).unwrap();
let quiver = ar_quiver(&algebra).unwrap();
assert_eq!(quiver.catalog().provenance(), CatalogProvenance::Nakayama);
assert_eq!(dim_vectors(&quiver), vec![vec![1], vec![2], vec![3]]);
assert_eq!(
flags(&quiver),
vec![(false, false), (false, false), (true, true)]
);
assert_eq!(
arrow_triples(&quiver),
vec![(0, 1, 1), (1, 0, 1), (1, 2, 1), (2, 1, 1)]
);
}
}
#[test]
fn the_radical_square_zero_3_cycle_has_a_hexagonal_ar_quiver() {
for field in [f2(), f5()] {
let algebra = radical_square_zero_cycle(3, field);
let quiver = ar_quiver(&algebra).unwrap();
assert_eq!(quiver.catalog().provenance(), CatalogProvenance::Nakayama);
assert_eq!(
dim_vectors(&quiver),
vec![
vec![1, 0, 0],
vec![1, 1, 0],
vec![0, 1, 0],
vec![0, 1, 1],
vec![0, 0, 1],
vec![1, 0, 1],
]
);
assert_eq!(
flags(&quiver),
vec![
(false, false),
(true, true),
(false, false),
(true, true),
(false, false),
(true, true),
]
);
assert_eq!(
arrow_triples(&quiver),
vec![
(0, 5, 1),
(1, 0, 1),
(2, 1, 1),
(3, 2, 1),
(4, 3, 1),
(5, 4, 1),
]
);
}
}
#[test]
fn d4_oriented_away_from_the_branch_vertex_has_15_arrows_and_two_stars() {
let algebra = d4(f2());
let quiver = ar_quiver(&algebra).unwrap();
assert_eq!(quiver.vertices().len(), 12);
assert_eq!(quiver.arrows().len(), 15);
assert_eq!(
dim_vectors(&quiver),
vec![
vec![0, 0, 0, 1],
vec![0, 0, 1, 0],
vec![0, 1, 0, 0],
vec![1, 0, 0, 0],
vec![1, 0, 0, 1],
vec![1, 0, 1, 0],
vec![1, 1, 0, 0],
vec![1, 0, 1, 1],
vec![1, 1, 0, 1],
vec![1, 1, 1, 0],
vec![1, 1, 1, 1],
vec![2, 1, 1, 1],
]
);
assert_eq!(
arrow_triples(&quiver),
vec![
(0, 10, 1),
(1, 10, 1),
(2, 10, 1),
(4, 3, 1),
(5, 3, 1),
(6, 3, 1),
(7, 11, 1),
(8, 11, 1),
(9, 11, 1),
(10, 7, 1),
(10, 8, 1),
(10, 9, 1),
(11, 4, 1),
(11, 5, 1),
(11, 6, 1),
]
);
let star_in = |id: usize| -> Vec<usize> {
quiver
.arrows()
.iter()
.filter(|a| a.target() == id)
.map(|a| a.source())
.collect()
};
let star_out = |id: usize| -> Vec<usize> {
quiver
.arrows()
.iter()
.filter(|a| a.source() == id)
.map(|a| a.target())
.collect()
};
assert_eq!(star_in(10), vec![0, 1, 2]);
assert_eq!(star_out(10), vec![7, 8, 9]);
assert_eq!(star_in(11), vec![7, 8, 9]);
assert_eq!(star_out(11), vec![4, 5, 6]);
assert!(quiver.vertices()[10].projective());
assert!(!quiver.vertices()[11].projective());
assert!(!quiver.vertices()[11].injective());
}
fn catalog_fixtures() -> Vec<Arc<Algebra>> {
vec![
linear_an(3, f5()),
linear_an(4, f2()),
truncated_poly(3, f2()).unwrap(),
truncated_poly(4, f5()).unwrap(),
radical_square_zero_cycle(3, f5()),
cyclic_nakayama(&[3, 3, 3], f2()).unwrap(),
d4(f2()),
]
}
#[test]
fn every_arrow_on_the_catalog_domains_is_plain() {
for algebra in catalog_fixtures() {
let quiver = ar_quiver(&algebra).unwrap();
for vertex in quiver.vertices() {
assert_eq!(
vertex.residue_degree(),
1,
"vertex {} of a catalog domain",
vertex.id()
);
}
for arrow in quiver.arrows() {
assert!(arrow.base_dim() > 0);
assert_eq!(arrow.over_source_residue(), arrow.base_dim());
assert_eq!(arrow.over_target_residue(), arrow.base_dim());
assert_eq!(arrow.valuation(), ArrowValuation::Plain(arrow.base_dim()));
assert_eq!(arrow.representatives().len(), arrow.base_dim());
}
}
}
#[test]
fn arrow_representatives_are_radical_maps_outside_the_radical_square() {
for algebra in [linear_an(3, f5()), truncated_poly(3, f2()).unwrap()] {
let quiver = ar_quiver(&algebra).unwrap();
let catalog = quiver.catalog();
for arrow in quiver.arrows() {
let x = &catalog.entries()[arrow.source()];
let y = &catalog.entries()[arrow.target()];
let radical = category_radical(x, y).unwrap();
let square = radical_square_through_catalog(catalog, x, y).unwrap();
for f in arrow.representatives() {
assert!(radical.contains(f).unwrap());
assert!(!square.contains(f).unwrap());
}
}
}
}
#[test]
fn every_catalog_has_at_least_one_entry_per_vertex() {
for algebra in catalog_fixtures() {
let quiver = ar_quiver(&algebra).unwrap();
let vertices = algebra.quiver().num_vertices() as usize;
assert!(quiver.catalog().len() >= vertices);
assert!(!quiver.catalog().is_empty());
assert_eq!(quiver.vertices().len(), quiver.catalog().len());
assert!(Arc::ptr_eq(quiver.catalog().algebra(), &algebra));
for (id, vertex) in quiver.vertices().iter().enumerate() {
assert_eq!(vertex.id(), id);
assert!(
vertex
.module()
.module()
.ptr_eq(quiver.catalog().entries()[id].module())
);
}
}
}
#[test]
fn the_catalog_constructors_reject_the_other_route() {
let nakayama = truncated_poly(3, f5()).unwrap();
assert_eq!(
IndecomposableCatalog::dynkin(&nakayama).unwrap_err(),
DynkinError::NonzeroIdeal { relations: 1 }
);
let dynkin = d4(f5());
assert_eq!(
IndecomposableCatalog::nakayama(&dynkin).unwrap_err(),
EnumerateError::NotNakayama {
vertex: 0,
incoming: 0,
outgoing: 3,
}
);
}
#[test]
fn an_unsupported_domain_carries_both_rejections() {
let algebra = commutative_square(f5());
assert_eq!(
ar_quiver(&algebra).unwrap_err(),
ArQuiverError::UnsupportedDomain {
dynkin: DynkinError::NonzeroIdeal { relations: 1 },
nakayama: EnumerateError::NotNakayama {
vertex: 0,
incoming: 0,
outgoing: 2,
},
}
);
}
#[test]
fn the_radical_needs_one_algebra() {
let first = linear_an(3, f5());
let second = linear_an(3, f5());
let x = indec(&Module::simple(&first, 0));
let y = indec(&Module::simple(&second, 0));
assert_eq!(
category_radical(&x, &y).unwrap_err(),
ArQuiverError::Hom(HomError::DifferentAlgebras)
);
}
#[test]
fn maps_outside_the_radical_are_isomorphisms() {
for algebra in [linear_an(3, f5()), truncated_poly(3, f2()).unwrap()] {
let catalog = ar_quiver(&algebra).unwrap();
let catalog = catalog.catalog();
for x in catalog.entries() {
for y in catalog.entries() {
let radical = category_radical(x, y).unwrap();
for f in hom(x.module(), y.module()).unwrap() {
if !radical.contains(&f).unwrap() {
assert!(f.is_isomorphism());
}
}
}
}
}
}
#[test]
fn the_ar_quiver_is_the_same_on_a_second_run() {
for algebra in [linear_an(3, f2()), radical_square_zero_cycle(3, f5())] {
let first = ar_quiver(&algebra).unwrap();
let second = ar_quiver(&algebra).unwrap();
assert_eq!(dim_vectors(&first), dim_vectors(&second));
assert_eq!(arrow_triples(&first), arrow_triples(&second));
for (a, b) in first.arrows().iter().zip(second.arrows()) {
for (f, g) in a.representatives().iter().zip(b.representatives()) {
assert_eq!(f.map_at(0).entries_u64(), g.map_at(0).entries_u64());
}
}
}
}
}