pub mod hyperterm;
pub mod qfield;
pub mod zeilberger;
pub use hyperterm::{GammaFactor, ProperTerm};
pub use qfield::{PolyK, RatK, Rn};
pub use zeilberger::{
boundary_side_condition, boundary_term, zeilberger, ZeilbergerOpts, ZeilbergerResult,
};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HolonomicError {
NotProperHypergeometric(String),
SearchExhausted(String),
CertificateVerificationFailed(String),
InvalidInput(String),
}
impl fmt::Display for HolonomicError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
HolonomicError::NotProperHypergeometric(s) => {
write!(f, "holonomic: not a proper hypergeometric term: {s}")
}
HolonomicError::SearchExhausted(s) => {
write!(f, "holonomic: search exhausted: {s}")
}
HolonomicError::CertificateVerificationFailed(s) => {
write!(f, "holonomic: certificate failed exact verification: {s}")
}
HolonomicError::InvalidInput(s) => {
write!(f, "holonomic: invalid input: {s}")
}
}
}
}
impl std::error::Error for HolonomicError {}
impl crate::errors::AlkahestError for HolonomicError {
fn code(&self) -> &'static str {
match self {
HolonomicError::NotProperHypergeometric(_) => "E-HOLO-001",
HolonomicError::SearchExhausted(_) => "E-HOLO-002",
HolonomicError::CertificateVerificationFailed(_) => "E-HOLO-003",
HolonomicError::InvalidInput(_) => "E-HOLO-004",
}
}
fn remediation(&self) -> Option<&'static str> {
Some(match self {
HolonomicError::NotProperHypergeometric(_) => {
"rewrite the term as R(n,k)*z**k*w**n*prod(gamma(a*n + b*k + c)**e) with \
integer a, b and rational c; supported function heads are gamma, factorial, \
binomial, pochhammer"
}
HolonomicError::SearchExhausted(_) => {
"raise max_order and/or max_degree in ZeilbergerOpts; if the term genuinely \
has no such recurrence within reach, Zeilberger's algorithm does not apply"
}
HolonomicError::CertificateVerificationFailed(_) => {
"internal: report the term as a minimal failing example"
}
HolonomicError::InvalidInput(_) => {
"n and k must be distinct symbols; max_order and max_degree must be positive"
}
})
}
}