use crate::arquiver::IndecomposableCatalog;
use crate::ext::ExtClass;
use crate::field::Fp;
use crate::homspace::row_times;
use crate::indec::IndecomposableModule;
use crate::iso::{IsoOutcome, is_isomorphic};
use crate::linalg::DenseMat;
use crate::sequence::{NonSplitWitness, ShortExactSequence};
use super::stable::{action_matrices, ext_sequence_holds, socle_kernel};
use super::{catalog, stable_end};
use crate::ar::tau;
#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum AlmostSplitOutcome {
Projective,
Sequence(AlmostSplitSequence),
}
#[derive(Clone, Debug)]
pub struct AlmostSplitSequence {
pub(in crate::almost_split) sequence: ShortExactSequence,
pub(in crate::almost_split) class: ExtClass,
pub(in crate::almost_split) witness: AlmostSplitWitness,
}
impl AlmostSplitSequence {
accessor_methods! {
pub sequence() -> &ShortExactSequence = |this| &this.sequence;
pub chosen_ar_class() -> &ExtClass = |this| &this.class;
pub witness() -> &AlmostSplitWitness = |this| &this.witness;
}
pub fn verify(&self, m: &IndecomposableModule) -> bool {
match &self.witness {
AlmostSplitWitness::ArDuality(witness) => {
witness.verify(m, &self.sequence, &self.class)
}
AlmostSplitWitness::ExhaustiveCatalog(_) => false,
}
}
pub fn verify_with_catalog(
&self,
m: &IndecomposableModule,
catalog: &IndecomposableCatalog,
) -> bool {
match &self.witness {
AlmostSplitWitness::ExhaustiveCatalog(witness) => {
witness.verify(m, catalog, &self.sequence, &self.class)
}
AlmostSplitWitness::ArDuality(_) => false,
}
}
}
#[derive(Clone, Debug)]
pub enum AlmostSplitWitness {
ArDuality(ArDualityWitness),
ExhaustiveCatalog(catalog::CatalogWitness),
}
#[derive(Clone, Debug)]
pub struct ArDualityWitness {
pub(in crate::almost_split) radical_coords: DenseMat,
pub(in crate::almost_split) action_traces: Vec<Vec<Fp>>,
pub(in crate::almost_split) socle_rref: DenseMat,
pub(in crate::almost_split) chosen_row: usize,
pub(in crate::almost_split) ext_dim: usize,
pub(in crate::almost_split) stable_end_dim: usize,
pub(in crate::almost_split) socle_dim: usize,
pub(in crate::almost_split) residue_degree: usize,
pub(in crate::almost_split) non_split: NonSplitWitness,
}
impl ArDualityWitness {
accessor_methods! {
pub radical_basis_coords() -> &DenseMat = |this| &this.radical_coords;
pub action_traces() -> &[Vec<Fp>] = |this| &this.action_traces;
pub socle_rref() -> &DenseMat = |this| &this.socle_rref;
pub chosen_row() -> usize = |this| this.chosen_row;
pub ext_dim() -> usize = |this| this.ext_dim;
pub stable_end_dim() -> usize = |this| this.stable_end_dim;
pub socle_dim() -> usize = |this| this.socle_dim;
pub residue_degree() -> usize = |this| this.residue_degree;
pub non_split() -> &NonSplitWitness = |this| &this.non_split;
}
pub fn verify(
&self,
m: &IndecomposableModule,
sequence: &ShortExactSequence,
class: &ExtClass,
) -> bool {
let space = class.space();
verify_guard!(ext_sequence_holds(m, sequence, class));
let_or_false!(Ok(translate) = tau(m.module()));
verify_guard!(IndecomposableModule::new(&translate).is_ok());
verify_guard!(matches!(
is_isomorphic(&translate, space.target()),
Ok(IsoOutcome::Isomorphic(_))
));
let field = m.module().field();
verify_guard!(self.radical_coords == *m.endo().radical_basis());
let d = space.dim();
verify_guard!(self.ext_dim == d && self.ext_dim == self.stable_end_dim);
let_or_false!(Ok(stable) = stable_end(m.module()));
verify_guard!(stable.dim() == self.stable_end_dim);
verify_guard!(
self.socle_dim == self.socle_rref.rows()
&& self.residue_degree == m.residue_degree()
&& self.socle_dim == self.residue_degree
);
let_or_false!(Ok(action) = action_matrices(m, space));
verify_guard!(socle_kernel(&action, d, &field) == self.socle_rref);
verify_guard!(!(0..self.socle_rref.rows()).any(|r| {
action.iter().any(|a| {
row_times(self.socle_rref.row(r), a, &field)
.iter()
.any(|v| !v.is_zero())
})
}));
verify_guard!(
self.chosen_row == 0
&& self.socle_rref.rows() > 0
&& class.coordinates() == self.socle_rref.row(0)
&& !class.is_zero()
);
verify_guard!(
self.action_traces.len() == action.len()
&& !self.action_traces.iter().zip(&action).any(|(trace, a)| {
*trace != row_times(class.coordinates(), a, &field)
|| trace.iter().any(|v| !v.is_zero())
})
);
self.non_split.verify(sequence)
}
}