use std::sync::Arc;
use crate::algebra::Algebra;
use crate::decompose::Certificate;
use crate::dynkin::{DynkinError, dynkin_indecomposables};
use crate::enumerate::{EnumerateError, nakayama_indecomposables};
use crate::indec::IndecomposableModule;
use crate::module::Module;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum CatalogProvenance {
Nakayama,
DynkinZeroIdeal,
}
display_error! { CatalogProvenance {
Self::Nakayama => "Nakayama classification";
Self::DynkinZeroIdeal => "Gabriel's theorem";
} }
pub struct IndecomposableCatalog {
algebra: Arc<Algebra>,
provenance: CatalogProvenance,
entries: Vec<Arc<IndecomposableModule>>,
}
debug_fields!(IndecomposableCatalog |this| {
"provenance" => this.provenance;
"entries" => this.entries.len();
});
fn certified_entries(listed: Vec<(Module, Certificate)>) -> Vec<Arc<IndecomposableModule>> {
listed
.into_iter()
.map(|(m, certificate)| {
Arc::new(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),
})
}
accessor_methods! {
pub algebra() -> &Arc<Algebra> = |this| &this.algebra;
pub provenance() -> CatalogProvenance = |this| this.provenance;
pub entries() -> &[Arc<IndecomposableModule>] = |this| &this.entries;
pub len() -> usize = |this| this.entries.len();
pub is_empty() -> bool = |this| this.entries.is_empty();
}
}