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::gentle::{GentleError, gentle_tree_indecomposables};
use crate::indec::IndecomposableModule;
use crate::module::Module;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum CatalogProvenance {
Nakayama,
DynkinZeroIdeal,
GentleTree,
}
display_error! { CatalogProvenance {
Self::Nakayama => "Nakayama classification";
Self::DynkinZeroIdeal => "Gabriel's theorem";
Self::GentleTree => "the string classification for a gentle tree";
} }
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CatalogError {
UnsupportedDomain {
dynkin: DynkinError,
nakayama: EnumerateError,
gentle: GentleError,
},
}
display_error! { error CatalogError {
Self::UnsupportedDomain { dynkin, nakayama, gentle } => "no complete enumeration applies: the Dynkin route reports {dynkin}, the Nakayama route reports {nakayama}, and the gentle-tree route reports {gentle}";
} }
#[derive(Clone)]
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),
})
}
pub fn gentle_tree(algebra: &Arc<Algebra>) -> Result<IndecomposableCatalog, GentleError> {
let listed = gentle_tree_indecomposables(algebra)?;
Ok(IndecomposableCatalog {
algebra: algebra.clone(),
provenance: CatalogProvenance::GentleTree,
entries: certified_entries(listed),
})
}
pub fn complete(algebra: &Arc<Algebra>) -> Result<IndecomposableCatalog, CatalogError> {
let dynkin = match Self::dynkin(algebra) {
Ok(catalog) => return Ok(catalog),
Err(error) => error,
};
let nakayama = match Self::nakayama(algebra) {
Ok(catalog) => return Ok(catalog),
Err(error) => error,
};
Self::gentle_tree(algebra).map_err(|gentle| CatalogError::UnsupportedDomain {
dynkin,
nakayama,
gentle,
})
}
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();
}
}