1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Error types for the OxiEML crate.
use std::fmt;
/// Errors that can occur during EML tree operations.
#[derive(Clone, Debug, PartialEq)]
pub enum EmlError {
/// Evaluation produced a complex result when real was expected.
/// Contains the imaginary part magnitude.
ComplexResult(f64),
/// Numerical overflow during exp computation.
/// Contains the argument that caused overflow.
ExpOverflow(f64),
/// Logarithm of zero or negative number in real mode.
LnDomain(f64),
/// Variable index out of bounds.
/// (requested_index, num_vars)
VarOutOfBounds(usize, usize),
/// Input data dimension mismatch.
/// (expected, got)
DimensionMismatch(usize, usize),
/// Symbolic regression failed to converge.
ConvergenceFailed {
/// Best MSE achieved
best_mse: f64,
/// Number of iterations completed
iterations: usize,
},
/// NaN encountered during computation.
NanEncountered,
/// Empty input data.
EmptyData,
/// A [`tensorlogic_ir::TLExpr`] variant has no `LoweredOp` equivalent.
///
/// Produced by `crate::tensorlogic::from_tlexpr` when the input falls
/// outside the arithmetic/transcendental subset supported by the bridge
/// (for example, logical connectives, quantifiers, or set-theoretic ops).
#[cfg(feature = "tensorlogic")]
UnsupportedTlExpr(String),
}
impl fmt::Display for EmlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ComplexResult(im) => {
write!(f, "complex result with |Im| = {im:.2e}")
}
Self::ExpOverflow(x) => {
write!(f, "exp overflow: argument {x:.2e} exceeds limit")
}
Self::LnDomain(x) => {
write!(f, "ln domain error: argument {x}")
}
Self::VarOutOfBounds(idx, n) => {
write!(f, "variable index {idx} out of bounds (num_vars = {n})")
}
Self::DimensionMismatch(expected, got) => {
write!(f, "dimension mismatch: expected {expected}, got {got}")
}
Self::ConvergenceFailed {
best_mse,
iterations,
} => {
write!(
f,
"convergence failed after {iterations} iterations (best MSE = {best_mse:.2e})"
)
}
Self::NanEncountered => write!(f, "NaN encountered during computation"),
Self::EmptyData => write!(f, "empty input data"),
#[cfg(feature = "tensorlogic")]
Self::UnsupportedTlExpr(desc) => {
write!(f, "unsupported TLExpr variant: {desc}")
}
}
}
}
impl std::error::Error for EmlError {}