use std::ops::Deref;
use super::cache::HomotopyBlockCache;
use super::classification::classify_with_goal;
use super::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum OrthogonalityGoal {
Tilting,
Silting,
}
#[derive(Clone)]
pub struct CertifiedSiltingComplex {
pub(super) candidate: TiltingComplexCandidate,
pub(super) generation: ThickGenerationWitness,
pub(super) degree_zero_endomorphisms: Vec<HomotopyHomQuotient>,
pub(super) degree_zero_residues: Vec<Vec<Fp>>,
pub(super) zero_shifted_homs: Vec<TiltingHomCheck>,
pub(super) negative_class: Option<Box<TiltingSelfOrthogonalityRejection>>,
pub(super) limits: TiltingComplexLimits,
pub(super) block_cache: HomotopyBlockCache,
pub(super) work: TiltingComplexWork,
}
impl std::fmt::Debug for CertifiedSiltingComplex {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("CertifiedSiltingComplex")
.field("summands", &self.candidate.len())
.field("zero_shifted_homs", &self.zero_shifted_homs.len())
.field("tilting", &self.negative_class.is_none())
.field("hom_spaces_built", &self.work.hom_spaces_built())
.field("hom_spaces_reused", &self.work.hom_spaces_reused())
.finish()
}
}
impl CertifiedSiltingComplex {
accessor_methods! {
pub candidate() -> &TiltingComplexCandidate = |this| &this.candidate;
pub generation() -> &ThickGenerationWitness = |this| &this.generation;
pub degree_zero_endomorphisms() -> &[HomotopyHomQuotient] = |this| &this.degree_zero_endomorphisms;
pub degree_zero_residues() -> &[Vec<Fp>] = |this| &this.degree_zero_residues;
pub zero_shifted_homs() -> &[TiltingHomCheck] = |this| &this.zero_shifted_homs;
pub negative_class() -> Option<&TiltingSelfOrthogonalityRejection> = |this| this.negative_class.as_deref();
pub limits() -> TiltingComplexLimits = |this| this.limits;
pub work() -> TiltingComplexWork = |this| this.work;
}
pub(super) fn block_cache(&self) -> &HomotopyBlockCache {
&self.block_cache
}
pub fn to_tilting(&self) -> Option<CertifiedTiltingComplex> {
self.negative_class
.is_none()
.then(|| CertifiedTiltingComplex {
silting: self.clone(),
})
}
pub fn verify(&self) -> bool {
self.rebuilds(OrthogonalityGoal::Silting)
}
fn rebuilds(&self, goal: OrthogonalityGoal) -> bool {
let rebuilt = classify_with_goal(
self.candidate.clone(),
Some(self.generation.clone()),
self.limits,
goal,
);
rebuilt.is_ok_and(|rebuilt| {
rebuilt.zero_shifted_homs.len() == self.zero_shifted_homs.len()
&& rebuilt.negative_class.is_none() == self.negative_class.is_none()
&& rebuilt.degree_zero_residues == self.degree_zero_residues
})
}
}
#[derive(Clone, Debug)]
pub struct CertifiedTiltingComplex {
pub(super) silting: CertifiedSiltingComplex,
}
impl Deref for CertifiedTiltingComplex {
type Target = CertifiedSiltingComplex;
fn deref(&self) -> &CertifiedSiltingComplex {
&self.silting
}
}
impl CertifiedTiltingComplex {
pub fn into_silting(self) -> CertifiedSiltingComplex {
self.silting
}
pub fn verify(&self) -> bool {
self.silting.negative_class.is_none() && self.silting.rebuilds(OrthogonalityGoal::Tilting)
}
}