use crate::base::budget::BudgetKind;
#[derive(Clone, Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SymplexError {
#[error("contradictory assumptions for '{symbol}': cannot be both {a} and {b}")]
ContradictoryAssumptions {
symbol: String,
a: String,
b: String,
},
#[error("precision exhausted: requested {requested} digits, achieved {achieved}")]
PrecisionExhausted {
requested: u32,
achieved: u32,
},
#[error("expression contains free symbol '{name}'")]
FreeSymbol {
name: String,
},
#[error("cannot evaluate: {reason}")]
Unevaluable {
reason: String,
},
#[error("{operation} could not be computed: {reason}")]
ComputationFailed {
operation: &'static str,
reason: String,
},
#[error("not implemented: {0}")]
NotImplemented(String),
#[error("{operation} diverges: {reason}")]
Divergent {
operation: &'static str,
reason: String,
},
#[error("{operation}: no solution ({reason})")]
NoSolution {
operation: &'static str,
reason: String,
},
#[error("{operation}: infinitely many solutions ({reason})")]
InfiniteSolutions {
operation: &'static str,
reason: String,
},
#[error("{operation}: invalid argument: {reason}")]
InvalidArgument {
operation: &'static str,
reason: String,
},
#[error("{operation} could not be computed: {}", kind.reason())]
BudgetExhausted {
operation: &'static str,
kind: BudgetKind,
},
#[error(
"{operation} could not be computed: expression swell: intermediate result exceeds the \
budget of {nodes} expression nodes; simplify the input or substitute numeric values \
first"
)]
ExpressionSwell {
operation: &'static str,
nodes: usize,
},
#[error("{operation} could not be computed: matrix is not diagonalizable: {reason}")]
NotDiagonalizable {
operation: &'static str,
reason: String,
},
}
impl SymplexError {
pub fn invalid_argument(operation: &'static str, reason: impl Into<String>) -> Self {
SymplexError::InvalidArgument {
operation,
reason: reason.into(),
}
}
pub fn computation_failed(operation: &'static str, reason: impl Into<String>) -> Self {
SymplexError::ComputationFailed {
operation,
reason: reason.into(),
}
}
}