pub enum Expression {
Show 15 variants
Number(Number),
Symbol(Symbol),
Add(Box<Vec<Expression>>),
Mul(Box<Vec<Expression>>),
Pow(Box<Expression>, Box<Expression>),
Function {
name: String,
args: Box<Vec<Expression>>,
},
Constant(MathConstant),
Set(Box<Vec<Expression>>),
Complex(Box<ComplexData>),
Matrix(Box<Matrix>),
Relation(Box<RelationData>),
Piecewise(Box<PiecewiseData>),
Interval(Box<IntervalData>),
Calculus(Box<CalculusData>),
MethodCall(Box<MethodCallData>),
}Expand description
Memory-optimized Expression enum (target: 32 bytes)
Hot-path variants (frequently used) are kept inline for performance. Cold-path variants (less common) are boxed to maintain small enum size.
Variants§
Number(Number)
Symbol(Symbol)
Add(Box<Vec<Expression>>)
Mul(Box<Vec<Expression>>)
Pow(Box<Expression>, Box<Expression>)
Function
Constant(MathConstant)
Set(Box<Vec<Expression>>)
Complex(Box<ComplexData>)
Matrix(Box<Matrix>)
Relation(Box<RelationData>)
Piecewise(Box<PiecewiseData>)
Interval(Box<IntervalData>)
Calculus(Box<CalculusData>)
MethodCall(Box<MethodCallData>)
Implementations§
Source§impl Expression
impl Expression
Sourcepub fn factorial(arg: Expression) -> Expression
pub fn factorial(arg: Expression) -> Expression
Create factorial expression
Sourcepub fn ln(arg: Expression) -> Expression
pub fn ln(arg: Expression) -> Expression
Create natural logarithm expression
Source§impl Expression
impl Expression
Sourcepub fn is_constant(&self) -> bool
pub fn is_constant(&self) -> bool
Check if an expression is constant (contains no variables)
Source§impl Expression
impl Expression
Sourcepub fn separate_constants(&self) -> (Expression, Expression)
pub fn separate_constants(&self) -> (Expression, Expression)
Separate variables and constants
Source§impl Expression
impl Expression
Sourcepub fn real(&self) -> Expression
pub fn real(&self) -> Expression
Extract the real part of a complex number
Returns the real component of a complex expression. For non-complex expressions, returns the expression itself.
§Examples
use mathhook_core::{Expression, expr};
let z = Expression::complex(expr!(3), expr!(4));
let real_part = z.real();
assert_eq!(real_part, expr!(3));Sourcepub fn imag(&self) -> Expression
pub fn imag(&self) -> Expression
Extract the imaginary part of a complex number
Returns the imaginary component of a complex expression. For non-complex expressions, returns zero.
§Examples
use mathhook_core::{Expression, expr};
let z = Expression::complex(expr!(3), expr!(4));
let imag_part = z.imag();
assert_eq!(imag_part, expr!(4));Sourcepub fn conjugate(&self) -> Expression
pub fn conjugate(&self) -> Expression
Compute the complex conjugate
Returns the complex conjugate (a + bi → a - bi). For non-complex expressions, returns the expression itself.
§Examples
use mathhook_core::{Expression, expr};
let z = Expression::complex(expr!(3), expr!(4));
let conjugate = z.conjugate();
if let Expression::Complex(data) = conjugate {
assert_eq!(data.real, expr!(3));
assert_eq!(data.imag, expr!(-4));
}Sourcepub fn abs(&self) -> Expression
pub fn abs(&self) -> Expression
Compute the absolute value (modulus) of a complex number
Returns |z| = √(re² + im²). For complex numbers, this is the magnitude. For real numbers, this is the absolute value.
§Examples
use mathhook_core::{Expression, expr};
let z = Expression::complex(expr!(3), expr!(4));
let magnitude = z.abs();Sourcepub fn arg(&self) -> Expression
pub fn arg(&self) -> Expression
Compute the argument (phase angle) of a complex number
Returns the angle θ = atan2(im, re) in radians, in the range (-π, π]. This is the principal value of the argument.
§Examples
use mathhook_core::{Expression, expr};
let z = Expression::complex(expr!(1), expr!(1));
let angle = z.arg();Sourcepub fn to_polar(&self) -> (Expression, Expression)
pub fn to_polar(&self) -> (Expression, Expression)
Convert to polar form (magnitude, angle)
Returns (r, θ) where z = r·e^(iθ). The angle is in radians, in the range (-π, π].
§Examples
use mathhook_core::{Expression, expr};
let z = Expression::complex(expr!(3), expr!(4));
let (magnitude, angle) = z.to_polar();Sourcepub fn from_polar(magnitude: Expression, angle: Expression) -> Expression
pub fn from_polar(magnitude: Expression, angle: Expression) -> Expression
Create a complex number from polar form
Converts polar coordinates (magnitude, angle) to rectangular form (a + bi). The angle should be in radians.
§Arguments
magnitude- The magnitude (r) of the complex numberangle- The angle (θ) in radians
§Examples
use mathhook_core::{Expression, expr};
let magnitude = expr!(5);
let angle = Expression::pi();
let z = Expression::from_polar(magnitude, angle);Sourcepub fn from_polar_form(magnitude: Expression, angle: Expression) -> Expression
pub fn from_polar_form(magnitude: Expression, angle: Expression) -> Expression
Create a complex number from polar form
Converts polar coordinates (magnitude, angle) to rectangular form (a + bi).
§Examples
use mathhook_core::{Expression, expr};
let magnitude = expr!(5);
let angle = Expression::pi();
let z = Expression::from_polar_form(magnitude, angle);Sourcepub fn simplify_complex(expr: &Expression) -> Expression
pub fn simplify_complex(expr: &Expression) -> Expression
Simplify complex expressions by removing zero parts
Converts complex numbers to their simplest form by removing zero real or imaginary components.
§Examples
use mathhook_core::{Expression, expr};
use mathhook_core::simplify::Simplify;
let z = Expression::complex(expr!(3), expr!(0));
let simplified = z.simplify();Source§impl Expression
impl Expression
Sourcepub fn expand_binomial(
&self,
a: &Expression,
b: &Expression,
n: u32,
) -> Expression
pub fn expand_binomial( &self, a: &Expression, b: &Expression, n: u32, ) -> Expression
Expand binomial expressions: (a + b)^n using binomial theorem
For commutative terms, uses binomial theorem: C(n,k) * a^k * b^(n-k) For noncommutative terms, uses direct multiplication to preserve order
Source§impl Expression
impl Expression
Sourcepub fn factor_numeric_coefficient(&self) -> (BigInt, Expression)
pub fn factor_numeric_coefficient(&self) -> (BigInt, Expression)
Factor out numeric coefficients
Source§impl Expression
impl Expression
Sourcepub fn factor_perfect_square(&self, terms: &[Expression]) -> Option<Expression>
pub fn factor_perfect_square(&self, terms: &[Expression]) -> Option<Expression>
Factor perfect square trinomials: a^2 + 2ab + b^2 = (a + b)^2
Sourcepub fn factor_difference_of_squares(
&self,
a: &Expression,
b: &Expression,
) -> Expression
pub fn factor_difference_of_squares( &self, a: &Expression, b: &Expression, ) -> Expression
Factor difference of squares: a^2 - b^2 = (a + b)(a - b)
Source§impl Expression
impl Expression
Sourcepub fn add_rationals(&self, other: &Expression) -> Expression
pub fn add_rationals(&self, other: &Expression) -> Expression
Add rational expressions: a/b + c/d = (ad + bc)/(bd)
Sourcepub fn multiply_rationals(&self, other: &Expression) -> Expression
pub fn multiply_rationals(&self, other: &Expression) -> Expression
Multiply rational expressions: (a/b) * (c/d) = (ac)/(bd)
Sourcepub fn simplify_complex_rational(&self) -> Expression
pub fn simplify_complex_rational(&self) -> Expression
Simplify complex rational expressions
Sourcepub fn extract_rational_coefficient(&self) -> (Ratio<BigInt>, Expression)
pub fn extract_rational_coefficient(&self) -> (Ratio<BigInt>, Expression)
Extract rational coefficient from expression
Source§impl Expression
impl Expression
Sourcepub fn is_valid_expression(&self) -> bool
pub fn is_valid_expression(&self) -> bool
Check if expression is a valid mathematical expression
Sourcepub fn solver_to_latex(&self) -> String
pub fn solver_to_latex(&self) -> String
Convert to LaTeX representation for solvers (avoid conflict)
pub fn flatten_add_terms(&self) -> Vec<Expression>
Sourcepub fn negate(&self) -> Expression
pub fn negate(&self) -> Expression
Negate an expression
Source§impl Expression
impl Expression
Sourcepub fn detect_advanced_zero_patterns(&self) -> bool
pub fn detect_advanced_zero_patterns(&self) -> bool
Advanced zero detection for specific algebraic patterns
Source§impl Expression
impl Expression
Sourcepub fn number<T>(value: T) -> Expression
pub fn number<T>(value: T) -> Expression
Create a number expression
§Examples
use mathhook_core::{Expression, Number};
let expr = Expression::number(42);
let expr = Expression::number(3.14);Sourcepub fn integer(value: i64) -> Expression
pub fn integer(value: i64) -> Expression
Create an integer expression
§Examples
use mathhook_core::Expression;
let expr = Expression::integer(42);Sourcepub fn big_integer(value: BigInt) -> Expression
pub fn big_integer(value: BigInt) -> Expression
Create an integer expression from BigInt
§Examples
use mathhook_core::Expression;
use num_bigint::BigInt;
let big_val = BigInt::from(42);
let expr = Expression::big_integer(big_val);Sourcepub fn rational(numerator: i64, denominator: i64) -> Expression
pub fn rational(numerator: i64, denominator: i64) -> Expression
Create a rational number expression
§Examples
use mathhook_core::Expression;
let expr = Expression::rational(3, 4); // 3/4
let expr = Expression::rational(-1, 2); // -1/2Sourcepub fn float(value: f64) -> Expression
pub fn float(value: f64) -> Expression
Create a float expression
§Examples
use mathhook_core::Expression;
let expr = Expression::float(3.14159);Sourcepub fn symbol<T>(symbol: T) -> Expression
pub fn symbol<T>(symbol: T) -> Expression
Create a symbol expression
§Examples
use mathhook_core::{symbol, Expression};
let expr = Expression::symbol(symbol!(x));Sourcepub fn add(terms: Vec<Expression>) -> Expression
pub fn add(terms: Vec<Expression>) -> Expression
Create an addition expression in canonical form
This constructor automatically produces a canonical form expression by:
- Flattening nested additions:
(a + b) + c→a + b + c - Removing identity elements:
x + 0→x - Combining like terms:
2x + 3x→5x - Sorting terms in canonical order:
y + x→x + y - Evaluating constant subexpressions:
2 + 3→5
§Examples
use mathhook_core::{Expression, expr};
// Constant folding
let expression = Expression::add(vec![
Expression::integer(1),
Expression::integer(2),
]);
assert_eq!(expression, Expression::integer(3));
// Identity element removal
let x = expr!(x);
let expression = Expression::add(vec![x.clone(), Expression::integer(0)]);
assert_eq!(expression, x);
// Commutativity (canonical ordering)
let y = expr!(y);
let expr1 = Expression::add(vec![x.clone(), y.clone()]);
let expr2 = Expression::add(vec![y.clone(), x.clone()]);
assert_eq!(expr1, expr2); // Both produce x + y in canonical orderSourcepub fn mul(factors: Vec<Expression>) -> Expression
pub fn mul(factors: Vec<Expression>) -> Expression
Create a multiplication expression in canonical form
This constructor automatically produces a canonical form expression by:
- Flattening nested multiplications:
(a * b) * c→a * b * c - Removing identity elements:
x * 1→x - Handling zero:
x * 0→0 - Sorting factors in canonical order:
y * x→x * y - Evaluating constant subexpressions:
2 * 3→6 - Converting division to multiplication:
a / b→a * b^(-1)
§Examples
use mathhook_core::{Expression, expr};
// Constant folding
let expression = Expression::mul(vec![
Expression::integer(2),
Expression::integer(3),
]);
assert_eq!(expression, Expression::integer(6));
// Identity element removal
let x = expr!(x);
let expr = Expression::mul(vec![x.clone(), Expression::integer(1)]);
assert_eq!(expr, x);
// Zero handling
let expression = Expression::mul(vec![x.clone(), Expression::integer(0)]);
assert_eq!(expression, Expression::integer(0));
// Commutativity (canonical ordering)
let y = expr!(y);
let expr1 = Expression::mul(vec![x.clone(), y.clone()]);
let expr2 = Expression::mul(vec![y.clone(), x.clone()]);
assert_eq!(expr1, expr2); // Both produce x * y in canonical orderSourcepub fn pow(base: Expression, exponent: Expression) -> Expression
pub fn pow(base: Expression, exponent: Expression) -> Expression
Create a power expression in canonical form
This constructor automatically produces a canonical form expression by:
- Applying power identities:
x^0→1,x^1→x,1^x→1 - Evaluating constant powers:
2^3→8 - Converting negative exponents to rationals:
x^(-1)→1/x - Flattening nested powers:
(x^a)^b→x^(a*b) - Handling special cases:
0^n→0for positive n
§Examples
use mathhook_core::{Expression, expr};
// Power identities
let x = expr!(x);
let expression = Expression::pow(x.clone(), Expression::integer(1));
assert_eq!(expression, x);
let expression = Expression::pow(x.clone(), Expression::integer(0));
assert_eq!(expression, Expression::integer(1));
// Constant evaluation
let expression = expr!(2 ^ 3);
assert_eq!(expression, Expression::integer(8));
// Nested power flattening
let expression = Expression::pow(
Expression::pow(x.clone(), Expression::integer(2)),
Expression::integer(3),
);
// Produces x^6 in canonical formSourcepub fn constant(constant: MathConstant) -> Expression
pub fn constant(constant: MathConstant) -> Expression
Create a constant expression
§Examples
use mathhook_core::{Expression, core::MathConstant};
let expr = Expression::constant(MathConstant::Pi);Sourcepub fn pi() -> Expression
pub fn pi() -> Expression
Sourcepub fn e() -> Expression
pub fn e() -> Expression
Sourcepub fn i() -> Expression
pub fn i() -> Expression
Create an imaginary unit expression
§Examples
use mathhook_core::Expression;
let i = Expression::i();Sourcepub fn infinity() -> Expression
pub fn infinity() -> Expression
Create an infinity expression
§Examples
use mathhook_core::Expression;
let inf = Expression::infinity();Sourcepub fn negative_infinity() -> Expression
pub fn negative_infinity() -> Expression
Create a negative infinity expression
§Examples
use mathhook_core::Expression;
let neg_inf = Expression::negative_infinity();Sourcepub fn undefined() -> Expression
pub fn undefined() -> Expression
Create an undefined expression
§Examples
use mathhook_core::Expression;
let undef = Expression::undefined();Sourcepub fn golden_ratio() -> Expression
pub fn golden_ratio() -> Expression
Create a golden ratio (phi) expression
§Examples
use mathhook_core::Expression;
let phi = Expression::golden_ratio();Sourcepub fn euler_gamma() -> Expression
pub fn euler_gamma() -> Expression
Create an Euler-Mascheroni constant (gamma) expression
§Examples
use mathhook_core::Expression;
let gamma = Expression::euler_gamma();Sourcepub fn equation(left: Expression, right: Expression) -> Expression
pub fn equation(left: Expression, right: Expression) -> Expression
Create an equation (equality relation)
§Examples
use mathhook_core::{Expression, expr};
let expr = Expression::equation(
expr!(x),
expr!(5),
);Sourcepub fn relation(
left: Expression,
right: Expression,
relation_type: RelationType,
) -> Expression
pub fn relation( left: Expression, right: Expression, relation_type: RelationType, ) -> Expression
Create a relation expression
§Examples
use mathhook_core::{Expression, expr};
use mathhook_core::core::expression::RelationType;
let relation = Expression::relation(
expr!(x),
expr!(5),
RelationType::Greater,
);Sourcepub fn div(numerator: Expression, denominator: Expression) -> Expression
pub fn div(numerator: Expression, denominator: Expression) -> Expression
Create a division expression (symbolic, always succeeds)
This constructor is for symbolic division where the denominator may be unknown
or symbolic. It converts division to multiplication by the reciprocal: a / b → a * b^(-1)
For numerical evaluation contexts where you need to detect division by zero,
use div_checked() instead.
§Examples
use mathhook_core::{Expression, symbol};
// Symbolic division (denominator is unknown)
let x = symbol!(x);
let expr = Expression::div(Expression::integer(1), Expression::symbol(x));
// Produces: 1 * x^(-1)
// Constant division (still symbolic context)
let expr = Expression::div(Expression::integer(3), Expression::integer(4));
// Produces: 3 * 4^(-1), which simplifies to 3/4Sourcepub fn div_checked(
numerator: Expression,
denominator: Expression,
) -> Result<Expression, MathError>
pub fn div_checked( numerator: Expression, denominator: Expression, ) -> Result<Expression, MathError>
Create a division expression with division-by-zero checking
This constructor checks if the denominator is zero and returns an error if so. Use this in evaluation contexts where division by zero should be detected.
For symbolic contexts where the denominator is unknown or symbolic, use div() instead.
§Errors
Returns MathError::DivisionByZero if the denominator is exactly zero.
§Examples
use mathhook_core::{Expression, MathError};
// Valid division
let result = Expression::div_checked(
Expression::integer(10),
Expression::integer(2),
);
assert!(result.is_ok());
// Division by zero
let result = Expression::div_checked(
Expression::integer(1),
Expression::integer(0),
);
assert!(matches!(result, Err(MathError::DivisionByZero)));Source§impl Expression
impl Expression
Sourcepub fn function<S>(name: S, args: Vec<Expression>) -> Expression
pub fn function<S>(name: S, args: Vec<Expression>) -> Expression
Create a function expression
§Examples
use mathhook_core::{Expression, expr};
let expression = Expression::function("sin", vec![expr!(x)]);Sourcepub fn sqrt(arg: Expression) -> Expression
pub fn sqrt(arg: Expression) -> Expression
Create a square root expression
§Examples
use mathhook_core::Expression;
let sqrt_2 = Expression::sqrt(Expression::integer(2));Sourcepub fn derivative(
expression: Expression,
variable: Symbol,
order: u32,
) -> Expression
pub fn derivative( expression: Expression, variable: Symbol, order: u32, ) -> Expression
Create a derivative expression
§Examples
use mathhook_core::{Expression, symbol, expr};
let expr = Expression::derivative(
Expression::pow(expr!(x), Expression::integer(2)),
symbol!(x),
1,
);Sourcepub fn integral(integrand: Expression, variable: Symbol) -> Expression
pub fn integral(integrand: Expression, variable: Symbol) -> Expression
Create an integral expression
§Examples
use mathhook_core::{Expression, symbol, expr};
let expr = Expression::integral(
expr!(x),
symbol!(x),
);Sourcepub fn definite_integral(
integrand: Expression,
variable: Symbol,
start: Expression,
end: Expression,
) -> Expression
pub fn definite_integral( integrand: Expression, variable: Symbol, start: Expression, end: Expression, ) -> Expression
Create a definite integral expression
§Examples
use mathhook_core::{Expression, symbol, expr};
let expr = Expression::definite_integral(
expr!(x),
symbol!(x),
Expression::integer(0),
Expression::integer(1),
);Sourcepub fn limit(
expression: Expression,
variable: Symbol,
point: Expression,
) -> Expression
pub fn limit( expression: Expression, variable: Symbol, point: Expression, ) -> Expression
Create a limit expression
§Examples
use mathhook_core::{Expression, symbol, expr};
let expr = Expression::limit(
expr!(x),
symbol!(x),
Expression::integer(0),
);Sourcepub fn sum(
expression: Expression,
variable: Symbol,
start: Expression,
end: Expression,
) -> Expression
pub fn sum( expression: Expression, variable: Symbol, start: Expression, end: Expression, ) -> Expression
Create a sum expression
§Examples
use mathhook_core::{Expression, symbol, expr};
let expr = Expression::sum(
expr!(i),
symbol!(i),
Expression::integer(1),
Expression::integer(10),
);Sourcepub fn product(
expression: Expression,
variable: Symbol,
start: Expression,
end: Expression,
) -> Expression
pub fn product( expression: Expression, variable: Symbol, start: Expression, end: Expression, ) -> Expression
Create a product expression
§Examples
use mathhook_core::{Expression, symbol, expr};
let expr = Expression::product(
expr!(i),
symbol!(i),
Expression::integer(1),
Expression::integer(10),
);Source§impl Expression
impl Expression
Sourcepub fn complex(real: Expression, imag: Expression) -> Expression
pub fn complex(real: Expression, imag: Expression) -> Expression
Create a complex number expression
§Examples
use mathhook_core::Expression;
let expr = Expression::complex(
Expression::integer(3),
Expression::integer(4),
);Sourcepub fn set(elements: Vec<Expression>) -> Expression
pub fn set(elements: Vec<Expression>) -> Expression
Create a set expression
§Examples
use mathhook_core::Expression;
let set = Expression::set(vec![
Expression::integer(1),
Expression::integer(2),
Expression::integer(3),
]);Sourcepub fn interval(
start: Expression,
end: Expression,
start_inclusive: bool,
end_inclusive: bool,
) -> Expression
pub fn interval( start: Expression, end: Expression, start_inclusive: bool, end_inclusive: bool, ) -> Expression
Create an interval expression
§Examples
use mathhook_core::Expression;
let interval = Expression::interval(
Expression::integer(0),
Expression::integer(10),
true,
false,
);Sourcepub fn piecewise(
pieces: Vec<(Expression, Expression)>,
default: Option<Expression>,
) -> Expression
pub fn piecewise( pieces: Vec<(Expression, Expression)>, default: Option<Expression>, ) -> Expression
Create a piecewise function expression
§Examples
use mathhook_core::{Expression, symbol};
let piecewise = Expression::piecewise(
vec![(Expression::symbol(symbol!(x)), Expression::integer(1))],
Some(Expression::integer(0)),
);Sourcepub fn matrix(rows: Vec<Vec<Expression>>) -> Expression
pub fn matrix(rows: Vec<Vec<Expression>>) -> Expression
Create a matrix expression from rows
§Examples
use mathhook_core::Expression;
let matrix = Expression::matrix(vec![
vec![Expression::integer(1), Expression::integer(2)],
vec![Expression::integer(3), Expression::integer(4)]
]);Sourcepub fn identity_matrix(size: usize) -> Expression
pub fn identity_matrix(size: usize) -> Expression
Create an identity matrix expression
§Examples
use mathhook_core::Expression;
use mathhook_core::matrices::operations::MatrixOperations;
let identity = Expression::identity_matrix(3);
assert!(identity.is_identity_matrix());Sourcepub fn method_call(
object: Expression,
method_name: impl Into<String>,
args: Vec<Expression>,
) -> Expression
pub fn method_call( object: Expression, method_name: impl Into<String>, args: Vec<Expression>, ) -> Expression
Create a method call expression
§Examples
use mathhook_core::{Expression, symbol};
let matrix = Expression::symbol(symbol!(A));
let det_call = Expression::method_call(matrix, "det", vec![]);
let trace_call = Expression::method_call(
Expression::symbol(symbol!(B)),
"trace",
vec![]
);Sourcepub fn zero_matrix(rows: usize, cols: usize) -> Expression
pub fn zero_matrix(rows: usize, cols: usize) -> Expression
Create a zero matrix expression
§Examples
use mathhook_core::matrices::operations::MatrixOperations;
use mathhook_core::Expression;
let zero = Expression::zero_matrix(2, 3);
assert!(zero.is_zero_matrix());Sourcepub fn diagonal_matrix(diagonal_elements: Vec<Expression>) -> Expression
pub fn diagonal_matrix(diagonal_elements: Vec<Expression>) -> Expression
Create a diagonal matrix expression
§Examples
use mathhook_core::Expression;
let diag = Expression::diagonal_matrix(vec![
Expression::integer(1),
Expression::integer(2),
Expression::integer(3)
]);Sourcepub fn scalar_matrix(size: usize, scalar_value: Expression) -> Expression
pub fn scalar_matrix(size: usize, scalar_value: Expression) -> Expression
Create a scalar matrix expression (c*I)
§Examples
use mathhook_core::Expression;
let scalar = Expression::scalar_matrix(3, Expression::integer(5));
// Creates 5*I (5 times the 3x3 identity matrix)Sourcepub fn matrix_from_arrays<const R: usize, const C: usize>(
arrays: [[i64; C]; R],
) -> Expression
pub fn matrix_from_arrays<const R: usize, const C: usize>( arrays: [[i64; C]; R], ) -> Expression
Create matrix from nested arrays (convenience method)
§Examples
use mathhook_core::Expression;
let matrix = Expression::matrix_from_arrays([
[1, 2, 3],
[4, 5, 6]
]);Sourcepub fn commutator(a: Expression, b: Expression) -> Expression
pub fn commutator(a: Expression, b: Expression) -> Expression
Create a commutator: [A, B] = AB - BA
The commutator measures the failure of two operators to commute. It is zero for commutative operators and nonzero for noncommutative.
§Examples
use mathhook_core::{Expression, symbol};
let A = Expression::symbol(symbol!(A; matrix));
let B = Expression::symbol(symbol!(B; matrix));
let comm = Expression::commutator(A.clone(), B.clone());
// Represents: AB - BA§Mathematical Properties
- [A, B] = -[B, A] (antisymmetry)
- [A, A] = 0 (self-commutator is zero)
- Jacobi identity: [A, [B, C]] + [B, [C, A]] + [C, [A, B]] = 0
§Quantum Mechanics Example
use mathhook_core::{Expression, symbol};
let x = Expression::symbol(symbol!(x; operator));
let p = Expression::symbol(symbol!(p; operator));
let comm = Expression::commutator(x, p);
// In quantum mechanics: [x, p] = ih (canonical commutation relation)Sourcepub fn anticommutator(a: Expression, b: Expression) -> Expression
pub fn anticommutator(a: Expression, b: Expression) -> Expression
Create an anticommutator: {A, B} = AB + BA
The anticommutator is the symmetric combination of two operators.
§Examples
use mathhook_core::{Expression, symbol};
let A = Expression::symbol(symbol!(A; matrix));
let B = Expression::symbol(symbol!(B; matrix));
let anticomm = Expression::anticommutator(A.clone(), B.clone());
// Represents: AB + BA§Mathematical Properties
- {A, B} = {B, A} (symmetry)
- {A, A} = 2A^2 (self-anticommutator)
§Physics Example
use mathhook_core::{Expression, symbol};
let sigma_x = Expression::symbol(symbol!(sigma_x; operator));
let sigma_y = Expression::symbol(symbol!(sigma_y; operator));
let anticomm = Expression::anticommutator(sigma_x, sigma_y);
// For Pauli matrices: {sigma_x, sigma_y} = 0Source§impl Expression
impl Expression
Sourcepub fn evaluate(&self) -> Result<Expression, MathError>
pub fn evaluate(&self) -> Result<Expression, MathError>
Evaluate expression with domain checking
Computes numerical values from expressions while validating mathematical
domain constraints. Returns Result<Expression, MathError> to handle
domain violations gracefully.
§Evaluation vs Simplification
Use evaluate() when: You need numerical results with domain validation
Use simplify() when: You need algebraic reduction without domain checking
Use evaluate_with_context() when: You need variable substitution + computation
§Domain Constraints Checked
sqrt(x): Requires x >= 0 in real domainlog(x): Requires x > 0 (pole at 0)tan(x): Has poles at π/2 + nπarcsin(x),arccos(x): Require |x| <= 1 in real domaincsc(x),sec(x),cot(x): Have poles where sin/cos/tan = 0- Division by zero: Checked in
x/yandx^(-n)for n > 0
§Returns
Ok(Expression): Evaluated result (numerical or symbolic if can’t evaluate)Err(MathError::DomainError): Domain constraint violatedErr(MathError::DivisionByZero): Division by zero detected
§Examples
§Successful Evaluation
use mathhook_core::{Expression, MathError};
// Constants evaluate to numbers
let sum = Expression::add(vec![Expression::integer(2), Expression::integer(3)]);
assert_eq!(sum.evaluate().unwrap(), Expression::integer(5));
let product = Expression::mul(vec![Expression::integer(2), Expression::integer(3), Expression::integer(4)]);
assert_eq!(product.evaluate().unwrap(), Expression::integer(24));
// Special values
let sin_zero = Expression::function("sin".to_string(), vec![Expression::integer(0)]);
assert_eq!(sin_zero.evaluate().unwrap(), Expression::integer(0));§Domain Errors
use mathhook_core::{expr, Expression, MathError};
// sqrt requires non-negative input
let sqrt_neg = Expression::function("sqrt".to_string(), vec![Expression::integer(-1)]);
assert!(matches!(
sqrt_neg.evaluate(),
Err(MathError::Pole { .. })
));
// log has pole at 0
assert!(matches!(
expr!(log(0)).evaluate(),
Err(MathError::Pole { .. })
));
// Division by zero
assert!(matches!(
expr!(1 / 0).evaluate(),
Err(MathError::DivisionByZero)
));§Symbolic Results (No Variables to Substitute)
use mathhook_core::{expr, symbol};
use mathhook_core::simplify::Simplify;
let x = symbol!(x);
// Can't evaluate without variable value - returns simplified symbolic
let result = expr!(x + 1).evaluate().unwrap();
assert_eq!(result, expr!(x + 1).simplify());
// For variable substitution, use evaluate_with_context() instead§Handling Errors
use mathhook_core::{Expression, MathError};
let sqrt_neg = Expression::function("sqrt".to_string(), vec![Expression::integer(-1)]);
match sqrt_neg.evaluate() {
Ok(result) => println!("Result: {}", result),
Err(MathError::DomainError { operation, value, reason }) => {
eprintln!("Domain error in {}: {} ({})", operation, value, reason);
}
Err(e) => eprintln!("Other error: {:?}", e),
}Sourcepub fn evaluate_with_context(
&self,
context: &EvalContext,
) -> Result<Expression, MathError>
pub fn evaluate_with_context( &self, context: &EvalContext, ) -> Result<Expression, MathError>
High-level evaluation with context
This is the PRIMARY user-facing evaluation method following SymPy’s two-level architecture. It handles:
- Variable substitution
- Optional symbolic simplification
- Optional numerical evaluation
This mirrors SymPy’s evalf(subs={...}, ...) high-level API.
§Arguments
context- Evaluation context (variables, numeric mode, precision, etc.)
§Returns
Evaluated expression
§Errors
Returns MathError for domain violations, undefined operations, etc.
§Examples
use mathhook_core::{expr, symbol};
use mathhook_core::core::expression::eval_numeric::EvalContext;
use std::collections::HashMap;
// Symbolic evaluation (no substitution)
let x = symbol!(x);
let f = expr!(x ^ 2);
let result = f.evaluate_with_context(&EvalContext::symbolic()).unwrap();
assert_eq!(result, expr!(x ^ 2)); // Unchanged
// Numerical evaluation with substitution
let mut vars = HashMap::new();
vars.insert("x".to_string(), expr!(3));
let ctx = EvalContext::numeric(vars);
let result = f.evaluate_with_context(&ctx).unwrap();
assert_eq!(result, expr!(9));Sourcepub fn evaluate_to_f64(&self) -> Result<f64, MathError>
pub fn evaluate_to_f64(&self) -> Result<f64, MathError>
Convert evaluated expression to f64
First evaluates the expression, then attempts to convert the result to f64. Returns error if the result is non-numerical (symbolic).
§Returns
f64 value if expression evaluates to a number
§Errors
Returns MathError::NonNumericalResult if evaluation produces symbolic expression
§Examples
use mathhook_core::{expr, symbol};
// Numerical expression
let e = expr!(2 + 3);
assert_eq!(e.evaluate_to_f64().unwrap(), 5.0);
// Symbolic expression fails
let x = symbol!(x);
assert!(x.evaluate_to_f64().is_err());Source§impl Expression
impl Expression
Sourcepub fn substitute(
&self,
substitutions: &HashMap<String, Expression>,
) -> Expression
pub fn substitute( &self, substitutions: &HashMap<String, Expression>, ) -> Expression
Substitute variables with expressions
Recursively replaces all occurrences of symbols with provided expressions.
§Arguments
substitutions- Map from symbol name to replacement expression
§Returns
New expression with substitutions applied
§Examples
use mathhook_core::{expr, symbol};
use std::collections::HashMap;
let x = symbol!(x);
let y = symbol!(y);
let e = expr!(x + y);
let mut subs = HashMap::new();
subs.insert("x".to_string(), expr!(3));
subs.insert("y".to_string(), expr!(4));
let result = e.substitute(&subs);
assert_eq!(result, expr!(3 + 4));Sourcepub fn substitute_and_simplify(
&self,
substitutions: &HashMap<String, Expression>,
) -> Expression
pub fn substitute_and_simplify( &self, substitutions: &HashMap<String, Expression>, ) -> Expression
Source§impl Expression
impl Expression
Sourcepub fn transpose(&self) -> Expression
pub fn transpose(&self) -> Expression
Compute transpose of matrix expression
For symbolic matrix expressions, this implements proper order reversal according to the mathematical rule: (AB)^T = B^T A^T
§Mathematical Rules
- For products: (AB)^T = B^T A^T (order reverses)
- For sums: (A+B)^T = A^T + B^T (distributes)
- For scalars: scalar^T = scalar (no change)
- For matrix symbols: A^T creates transpose function
§Examples
use mathhook_core::{Expression, symbol};
let a = symbol!(A; matrix);
let b = symbol!(B; matrix);
let product = Expression::mul(vec![
Expression::symbol(a.clone()),
Expression::symbol(b.clone()),
]);
let transposed = product.transpose();Sourcepub fn inverse(&self) -> Expression
pub fn inverse(&self) -> Expression
Compute inverse of matrix expression
For symbolic matrix expressions, this implements proper order reversal according to the mathematical rule: (AB)^(-1) = B^(-1) A^(-1)
§Mathematical Rules
- For products: (AB)^(-1) = B^(-1) A^(-1) (order reverses)
- For matrix symbols: A^(-1) creates inverse function
- For identity: I^(-1) = I
- For scalars: a^(-1) = 1/a (reciprocal)
§Examples
use mathhook_core::{Expression, symbol};
let a = symbol!(A; matrix);
let b = symbol!(B; matrix);
let product = Expression::mul(vec![
Expression::symbol(a.clone()),
Expression::symbol(b.clone()),
]);
let inverse = product.inverse();Source§impl Expression
impl Expression
Sourcepub fn commutativity(&self) -> Commutativity
pub fn commutativity(&self) -> Commutativity
Compute commutativity of this expression
Commutativity is inferred from the symbols and operations:
- Numbers, constants: Commutative
- Symbols: Depends on symbol type (Scalar → Commutative, Matrix/Operator/Quaternion → Noncommutative)
- Mul: Noncommutative if ANY factor is noncommutative
- Add, Pow, Function: Depends on subexpressions
§Examples
Basic scalar symbols (commutative):
use mathhook_core::core::symbol::Symbol;
use mathhook_core::core::expression::Expression;
use mathhook_core::core::commutativity::Commutativity;
let x = Symbol::scalar("x");
let y = Symbol::scalar("y");
let expr = Expression::mul(vec![
Expression::symbol(x.clone()),
Expression::symbol(y.clone()),
]);
assert_eq!(expr.commutativity(), Commutativity::Commutative);Matrix symbols (noncommutative):
use mathhook_core::core::symbol::Symbol;
use mathhook_core::core::expression::Expression;
use mathhook_core::core::commutativity::Commutativity;
let a = Symbol::matrix("A");
let b = Symbol::matrix("B");
let expr = Expression::mul(vec![
Expression::symbol(a.clone()),
Expression::symbol(b.clone()),
]);
assert_eq!(expr.commutativity(), Commutativity::Noncommutative);Sourcepub fn count_variable_occurrences(&self, variable: &Symbol) -> usize
pub fn count_variable_occurrences(&self, variable: &Symbol) -> usize
Count occurrences of a variable in the expression
Recursively counts how many times a specific variable symbol appears in the expression tree. This is useful for:
- Determining if an expression is polynomial in a variable
- Analyzing variable dependencies
- Checking if a variable appears in an equation
§Arguments
variable- The symbol to count occurrences of
§Returns
The number of times the variable appears in the expression
§Examples
Basic counting in simple expressions:
use mathhook_core::{Expression, symbol};
let x = symbol!(x);
let expr = Expression::mul(vec![
Expression::integer(2),
Expression::symbol(x.clone()),
]);
assert_eq!(expr.count_variable_occurrences(&x), 1);Counting multiple occurrences:
use mathhook_core::{Expression, symbol};
let x = symbol!(x);
// x^2 + 2*x + 1 has 2 occurrences of x (in x^2 and in 2*x)
let expr = Expression::Add(Box::new(vec![
Expression::pow(Expression::symbol(x.clone()), Expression::integer(2)),
Expression::mul(vec![Expression::integer(2), Expression::symbol(x.clone())]),
Expression::integer(1),
]));
assert_eq!(expr.count_variable_occurrences(&x), 2);Counting in power expressions:
use mathhook_core::{Expression, symbol};
let x = symbol!(x);
// x^x has 2 occurrences (base and exponent)
let expr = Expression::pow(
Expression::symbol(x.clone()),
Expression::symbol(x.clone())
);
assert_eq!(expr.count_variable_occurrences(&x), 2);Counting in functions:
use mathhook_core::{Expression, symbol};
let x = symbol!(x);
// sin(x)
let expr = Expression::function("sin", vec![Expression::symbol(x.clone())]);
assert_eq!(expr.count_variable_occurrences(&x), 1);
// f(x, x, 2) has 2 occurrences
let expr2 = Expression::function("f", vec![
Expression::symbol(x.clone()),
Expression::symbol(x.clone()),
Expression::integer(2),
]);
assert_eq!(expr2.count_variable_occurrences(&x), 2);Zero occurrences when variable is not present:
use mathhook_core::{Expression, symbol};
let x = symbol!(x);
let y = symbol!(y);
let expr = Expression::symbol(y.clone());
assert_eq!(expr.count_variable_occurrences(&x), 0);pub fn contains_variable(&self, symbol: &Symbol) -> bool
Sourcepub fn is_simple_variable(&self, var: &Symbol) -> bool
pub fn is_simple_variable(&self, var: &Symbol) -> bool
Check if expression is just the variable itself
Sourcepub fn is_symbol_matching(&self, symbol: &Symbol) -> bool
pub fn is_symbol_matching(&self, symbol: &Symbol) -> bool
Check if this expression is a specific symbol
Convenience method for pattern matching against a specific symbol. More readable than inline matches! pattern in complex conditions.
§Arguments
symbol- The symbol to check against
§Returns
True if this expression is exactly the given symbol
§Examples
use mathhook_core::{Expression, symbol};
let x = symbol!(x);
let y = symbol!(y);
let expr = Expression::symbol(x.clone());
assert!(expr.is_symbol_matching(&x));
assert!(!expr.is_symbol_matching(&y));Source§impl Expression
impl Expression
Sourcepub fn gcd(&self, other: &Expression) -> Expression
pub fn gcd(&self, other: &Expression) -> Expression
Compute the greatest common divisor of two expressions
For integer expressions, computes the mathematical GCD. For polynomial expressions with integer coefficients, uses fast IntPoly algorithm. For other expressions, returns 1.
§Arguments
other- The expression to compute GCD with
§Examples
use mathhook_core::expr;
let a = expr!(12);
let b = expr!(8);
let gcd = a.gcd(&b);
assert_eq!(gcd, expr!(4));use mathhook_core::expr;
// GCD of zero with any number is that number
let a = expr!(0);
let b = expr!(15);
let gcd = a.gcd(&b);
assert_eq!(gcd, expr!(15));Sourcepub fn lcm(&self, other: &Expression) -> Expression
pub fn lcm(&self, other: &Expression) -> Expression
Compute the least common multiple of two expressions
For integer expressions, computes the mathematical LCM. For other expressions, returns the first expression.
§Arguments
other- The expression to compute LCM with
§Examples
use mathhook_core::expr;
let a = expr!(12);
let b = expr!(8);
let lcm = a.lcm(&b);
assert_eq!(lcm, expr!(24));use mathhook_core::expr;
// LCM with zero is zero
let a = expr!(0);
let b = expr!(15);
let lcm = a.lcm(&b);
assert_eq!(lcm, expr!(0));Sourcepub fn factor_gcd(&self) -> Expression
pub fn factor_gcd(&self) -> Expression
Factor out the GCD from an expression
Currently a stub that returns the original expression. Will be implemented to extract common factors.
§Examples
use mathhook_core::{expr, Expression};
let expr = Expression::add(vec![
expr!(6*x),
expr!(9),
]);
let factored = expr.factor_gcd();Sourcepub fn cofactors(
&self,
other: &Expression,
) -> (Expression, Expression, Expression)
pub fn cofactors( &self, other: &Expression, ) -> (Expression, Expression, Expression)
Compute GCD and cofactors
Returns a tuple of (gcd, cofactor_a, cofactor_b) where:
- gcd is the greatest common divisor
- cofactor_a = a / gcd
- cofactor_b = b / gcd
§Arguments
other- The expression to compute cofactors with
§Examples
use mathhook_core::expr;
let a = expr!(12);
let b = expr!(8);
let (gcd, cofactor_a, cofactor_b) = a.cofactors(&b);
assert_eq!(gcd, expr!(4));
assert_eq!(cofactor_a, expr!(3));
assert_eq!(cofactor_b, expr!(2));Sourcepub fn find_variables(&self) -> Vec<Symbol>
pub fn find_variables(&self) -> Vec<Symbol>
Find all variables in expression
Returns a vector of all unique Symbol nodes found in the expression tree. This is used by GCD algorithms to detect univariate polynomials.
Source§impl Expression
impl Expression
Sourcepub fn solve(&self, variable: &Symbol) -> SolverResult
pub fn solve(&self, variable: &Symbol) -> SolverResult
Solve equation for a variable
Solves the equation self = 0 for the given variable.
By default, returns only the solutions without educational explanation for best performance.
Use solve_with_steps() if you need the step-by-step explanation.
§Arguments
variable- The variable to solve for
§Returns
The solver result containing solutions or error information
§Examples
Basic usage (default: no explanation):
use mathhook_core::{Expression, symbol};
use mathhook_core::algebra::solvers::SolverResult;
let x = symbol!(x);
let equation = Expression::add(vec![
Expression::mul(vec![Expression::integer(2), Expression::symbol(x.clone())]),
Expression::integer(-6),
]);
let result = equation.solve(&x);
match result {
SolverResult::Single(solution) => {
assert_eq!(solution, Expression::integer(3));
}
_ => panic!("Expected single solution"),
}Sourcepub fn solve_with_steps(
&self,
variable: &Symbol,
) -> (SolverResult, StepByStepExplanation)
pub fn solve_with_steps( &self, variable: &Symbol, ) -> (SolverResult, StepByStepExplanation)
Solve equation with step-by-step educational explanation
Solves the equation self = 0 for the given variable and generates
an educational explanation showing each solving step. Use this when you need
to teach or explain the solving process. For performance-critical code where
you only need the answer, use solve() instead.
§Arguments
variable- The variable to solve for
§Returns
A tuple of (solver result, step-by-step explanation)
§Examples
use mathhook_core::{Expression, symbol};
let x = symbol!(x);
let equation = Expression::add(vec![
Expression::mul(vec![Expression::integer(2), Expression::symbol(x.clone())]),
Expression::integer(-6),
]);
let (result, explanation) = equation.solve_with_steps(&x);
// The explanation contains educational content showing how to solve the equationSource§impl Expression
impl Expression
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Check if the expression is zero (robust version with simplification)
This method simplifies the expression first before checking if it equals zero. It correctly detects zero for expressions like:
- Literal zeros:
0,0.0,0/1 - Symbolic zeros:
x - x,0 * y,sin(0) - Simplified zeros:
(x + 1) - (x + 1)
§Performance Note
This method calls simplify(), which may be expensive for complex expressions.
For performance-critical code where you only need to check literal zeros,
use is_zero_fast() instead.
§Examples
use mathhook_core::simplify::Simplify;
use mathhook_core::Expression;
// Literal zero
assert!(Expression::integer(0).is_zero());
// Symbolic zero after simplification
let expr = Expression::mul(vec![Expression::integer(0), Expression::integer(5)]);
assert!(expr.is_zero());Sourcepub fn is_zero_fast(&self) -> bool
pub fn is_zero_fast(&self) -> bool
Fast literal zero check without simplification
This is a performance-optimized version that only checks if the expression
is literally Number(0). It does NOT simplify the expression first.
Use this in performance-critical loops where you know the expression is already in simplified form, or where you specifically want to check for literal zeros only.
§Examples
use mathhook_core::Expression;
// Detects literal zero
assert!(Expression::integer(0).is_zero_fast());
// Mul constructor auto-simplifies, so this IS detected
let expr = Expression::mul(vec![Expression::integer(0), Expression::integer(5)]);
assert!(expr.is_zero_fast()); // Simplified to 0 by constructor
// Example of what is_zero_fast() does NOT detect (without simplification):
// If we had a raw unsimplified Mul expression, is_zero_fast() wouldn't detect itSourcepub fn is_one(&self) -> bool
pub fn is_one(&self) -> bool
Check if the expression is one (robust version with simplification)
This method simplifies the expression first before checking if it equals one. It correctly detects one for expressions like:
- Literal ones:
1,1.0,2/2 - Symbolic ones:
x / x,x^0,cos(0) - Simplified ones:
(x + 1) / (x + 1)
§Performance Note
This method calls simplify(), which may be expensive for complex expressions.
For performance-critical code where you only need to check literal ones,
use is_one_fast() instead.
§Examples
use mathhook_core::simplify::Simplify;
use mathhook_core::Expression;
// Literal one
assert!(Expression::integer(1).is_one());
// Symbolic one after simplification
let expr = Expression::pow(Expression::integer(5), Expression::integer(0));
assert!(expr.is_one());Sourcepub fn is_one_fast(&self) -> bool
pub fn is_one_fast(&self) -> bool
Fast literal one check without simplification
This is a performance-optimized version that only checks if the expression
is literally Number(1). It does NOT simplify the expression first.
Use this in performance-critical loops where you know the expression is already in simplified form, or where you specifically want to check for literal ones only.
§Examples
use mathhook_core::Expression;
// Detects literal one
assert!(Expression::integer(1).is_one_fast());
// Pow constructor auto-simplifies, so x^0 = 1 IS detected
let expr = Expression::pow(Expression::integer(5), Expression::integer(0));
assert!(expr.is_one_fast()); // Simplified to 1 by constructor
// is_one_fast() checks ONLY for literal Number(1)
// It does not simplify complex expressions firstSourcepub fn as_number(&self) -> Option<&Number>
pub fn as_number(&self) -> Option<&Number>
Get the numeric coefficient if this is a simple numeric expression
Sourcepub fn as_symbol(&self) -> Option<&Symbol>
pub fn as_symbol(&self) -> Option<&Symbol>
Get the symbol if this is a simple symbol expression
Sourcepub fn is_negative_number(&self) -> bool
pub fn is_negative_number(&self) -> bool
Check if this expression is a negative number
Returns true if the expression is a negative integer, rational, or float. Returns false for symbolic expressions (even if they might evaluate to negative).
§Examples
use mathhook_core::Expression;
assert!(Expression::integer(-5).is_negative_number());
assert!(Expression::rational(-1, 2).is_negative_number());
assert!(!Expression::integer(5).is_negative_number());
assert!(!Expression::symbol("x").is_negative_number()); // Symbolic, not a numberSourcepub fn is_positive_number(&self) -> bool
pub fn is_positive_number(&self) -> bool
Check if this expression is a positive number
Returns true if the expression is a positive integer, rational, or float. Returns false for symbolic expressions (even if they might evaluate to positive).
§Examples
use mathhook_core::Expression;
assert!(Expression::integer(5).is_positive_number());
assert!(Expression::rational(1, 2).is_positive_number());
assert!(!Expression::integer(-5).is_positive_number());
assert!(!Expression::symbol("x").is_positive_number()); // Symbolic, not a numberSourcepub fn evaluate_method_call(&self) -> Expression
pub fn evaluate_method_call(&self) -> Expression
Evaluate method calls on expressions
This handles method calls like matrix.det(), matrix.trace(), etc. by calling the appropriate methods on the underlying objects.
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Check if this expression represents a mathematical function
Returns true for expressions like sin(x), cos(x), etc. Now integrated with Universal Function Intelligence System
Sourcepub fn get_function_intelligence(&self) -> Option<&FunctionProperties>
pub fn get_function_intelligence(&self) -> Option<&FunctionProperties>
Get function intelligence properties if available
Seamless integration between core expressions and function intelligence
Sourcepub fn explain_function(&self) -> Vec<Step>
pub fn explain_function(&self) -> Vec<Step>
Generate educational explanation for function expressions
Perfect integration with the educational system
Source§impl Expression
Convenient formatting methods for Expression without requiring context
impl Expression
Convenient formatting methods for Expression without requiring context
Sourcepub fn format(&self) -> Result<String, FormattingError>
pub fn format(&self) -> Result<String, FormattingError>
Format expression using default LaTeX formatting
This is the most convenient way to format expressions when you don’t need specific formatting options. Always uses LaTeX format.
§Examples
use mathhook_core::core::Expression;
use mathhook_core::{expr};
let x_expr = expr!(x);
let formatted = x_expr.format().unwrap();
// Returns LaTeX formatted stringSourcepub fn format_as(
&self,
language: MathLanguage,
) -> Result<String, FormattingError>
pub fn format_as( &self, language: MathLanguage, ) -> Result<String, FormattingError>
Format expression with specific language/format
§Examples
use mathhook_core::core::Expression;
use mathhook_core::formatter::MathLanguage;
use mathhook_core::expr;
let x_expr = expr!(x);
let latex = x_expr.format_as(MathLanguage::LaTeX).unwrap();
let simple = x_expr.format_as(MathLanguage::Simple).unwrap();
let wolfram = x_expr.format_as(MathLanguage::Wolfram).unwrap();Source§impl Expression
impl Expression
Sourcepub fn matrix_dimensions(&self) -> Option<(usize, usize)>
pub fn matrix_dimensions(&self) -> Option<(usize, usize)>
Get matrix dimensions for any matrix type
Returns (rows, columns) for all matrix types.
§Examples
use mathhook_core::Expression;
let matrix = Expression::matrix(vec![
vec![Expression::integer(1), Expression::integer(2)],
vec![Expression::integer(3), Expression::integer(4)]
]);
assert_eq!(matrix.matrix_dimensions(), Some((2, 2)));
let identity = Expression::identity_matrix(3);
assert_eq!(identity.matrix_dimensions(), Some((3, 3)));Trait Implementations§
Source§impl Add<&Expression> for Expression
impl Add<&Expression> for Expression
Source§type Output = Expression
type Output = Expression
+ operator.Source§fn add(self, rhs: &Expression) -> Expression
fn add(self, rhs: &Expression) -> Expression
+ operation. Read moreSource§impl Add<Expression> for &Expression
impl Add<Expression> for &Expression
Source§type Output = Expression
type Output = Expression
+ operator.Source§fn add(self, rhs: Expression) -> Expression
fn add(self, rhs: Expression) -> Expression
+ operation. Read moreSource§impl Add<i32> for &Expression
impl Add<i32> for &Expression
Source§type Output = Expression
type Output = Expression
+ operator.Source§impl Add<i32> for Expression
impl Add<i32> for Expression
Source§type Output = Expression
type Output = Expression
+ operator.Source§impl Add for &Expression
impl Add for &Expression
Source§type Output = Expression
type Output = Expression
+ operator.Source§fn add(self, rhs: &Expression) -> Expression
fn add(self, rhs: &Expression) -> Expression
+ operation. Read moreSource§impl Add for Expression
impl Add for Expression
Source§type Output = Expression
type Output = Expression
+ operator.Source§fn add(self, rhs: Expression) -> Expression
fn add(self, rhs: Expression) -> Expression
+ operation. Read moreSource§impl AdvancedPolynomial for Expression
impl AdvancedPolynomial for Expression
Source§fn polynomial_divide(&self, divisor: &Expression) -> (Expression, Expression)
fn polynomial_divide(&self, divisor: &Expression) -> (Expression, Expression)
Polynomial division using optimized algorithms
Source§fn polynomial_remainder(&self, divisor: &Expression) -> Expression
fn polynomial_remainder(&self, divisor: &Expression) -> Expression
Polynomial remainder
Source§fn polynomial_leading_coefficient(&self, var: &Symbol) -> Expression
fn polynomial_leading_coefficient(&self, var: &Symbol) -> Expression
Source§fn polynomial_content(&self) -> Expression
fn polynomial_content(&self) -> Expression
Source§fn polynomial_primitive_part(&self) -> Expression
fn polynomial_primitive_part(&self) -> Expression
Source§fn polynomial_resultant(&self, other: &Expression, var: &Symbol) -> Expression
fn polynomial_resultant(&self, other: &Expression, var: &Symbol) -> Expression
Source§fn polynomial_discriminant(&self, var: &Symbol) -> Expression
fn polynomial_discriminant(&self, var: &Symbol) -> Expression
Source§impl AdvancedSimplify for Expression
impl AdvancedSimplify for Expression
Source§fn advanced_simplify(&self) -> Expression
fn advanced_simplify(&self) -> Expression
Perform advanced simplification including special functions
Source§fn simplify_factorial(&self) -> Expression
fn simplify_factorial(&self) -> Expression
Simplify factorial expressions
Source§fn simplify_logarithms(&self) -> Expression
fn simplify_logarithms(&self) -> Expression
Simplify logarithmic expressions
Source§fn simplify_trigonometric(&self) -> Expression
fn simplify_trigonometric(&self) -> Expression
Simplify trigonometric expressions
Source§fn simplify_special_functions(&self) -> Expression
fn simplify_special_functions(&self) -> Expression
Simplify other special functions
Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Collect for Expression
impl Collect for Expression
Source§fn collect(&self, var: &Symbol) -> Expression
fn collect(&self, var: &Symbol) -> Expression
Collect terms with respect to a specific variable
Source§fn collect_terms(&self) -> Expression
fn collect_terms(&self) -> Expression
Collect and combine all like terms
Source§fn combine_like_terms(&self) -> Expression
fn combine_like_terms(&self) -> Expression
Combine like terms in the expression
Source§impl ComplexAnalysis for Expression
impl ComplexAnalysis for Expression
Source§fn is_analytic_at(&self, variable: &Symbol, point: &Expression) -> bool
fn is_analytic_at(&self, variable: &Symbol, point: &Expression) -> bool
Source§fn pole_order(&self, variable: &Symbol, pole: &Expression) -> u32
fn pole_order(&self, variable: &Symbol, pole: &Expression) -> u32
Source§fn is_removable_singularity(
&self,
variable: &Symbol,
point: &Expression,
) -> bool
fn is_removable_singularity( &self, variable: &Symbol, point: &Expression, ) -> bool
Source§fn is_essential_singularity(
&self,
variable: &Symbol,
point: &Expression,
) -> bool
fn is_essential_singularity( &self, variable: &Symbol, point: &Expression, ) -> bool
Source§impl ComplexOperations for Expression
impl ComplexOperations for Expression
Source§fn complex_add(&self, other: &Expression) -> Expression
fn complex_add(&self, other: &Expression) -> Expression
Source§fn complex_subtract(&self, other: &Expression) -> Expression
fn complex_subtract(&self, other: &Expression) -> Expression
Source§fn complex_multiply(&self, other: &Expression) -> Expression
fn complex_multiply(&self, other: &Expression) -> Expression
Source§fn complex_divide(&self, other: &Expression) -> Expression
fn complex_divide(&self, other: &Expression) -> Expression
Source§fn complex_conjugate(&self) -> Expression
fn complex_conjugate(&self) -> Expression
Source§fn complex_modulus(&self) -> Expression
fn complex_modulus(&self) -> Expression
Source§fn complex_argument(&self) -> Expression
fn complex_argument(&self) -> Expression
Source§fn to_polar_form(&self) -> (Expression, Expression)
fn to_polar_form(&self) -> (Expression, Expression)
Source§fn is_imaginary(&self) -> bool
fn is_imaginary(&self) -> bool
Source§fn is_pure_imaginary(&self) -> bool
fn is_pure_imaginary(&self) -> bool
Source§impl Debug for Expression
impl Debug for Expression
Source§impl Derivative for Expression
impl Derivative for Expression
Source§fn derivative(&self, variable: Symbol) -> Expression
fn derivative(&self, variable: Symbol) -> Expression
Source§fn nth_derivative(&self, variable: Symbol, order: u32) -> Expression
fn nth_derivative(&self, variable: Symbol, order: u32) -> Expression
Source§impl DerivativeWithSteps for Expression
impl DerivativeWithSteps for Expression
Source§fn derivative_with_steps(
&self,
variable: &Symbol,
order: u32,
) -> StepByStepExplanation
fn derivative_with_steps( &self, variable: &Symbol, order: u32, ) -> StepByStepExplanation
Source§impl<'de> Deserialize<'de> for Expression
impl<'de> Deserialize<'de> for Expression
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Expression, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Expression, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for Expression
impl Display for Expression
Source§impl EvalNumeric for Expression
impl EvalNumeric for Expression
Source§fn eval_numeric(&self, _precision: u32) -> Result<Expression, MathError>
fn eval_numeric(&self, _precision: u32) -> Result<Expression, MathError>
Source§impl Expand for Expression
impl Expand for Expression
Source§fn expand(&self) -> Expression
fn expand(&self) -> Expression
Expand the expression by distributing multiplication over addition
Source§impl<C> ExpressionFormatter<C> for Expressionwhere
C: FormattingContext,
impl<C> ExpressionFormatter<C> for Expressionwhere
C: FormattingContext,
Source§impl Factor for Expression
impl Factor for Expression
Source§fn factor(&self) -> Expression
fn factor(&self) -> Expression
Factor the expression by extracting common factors
Source§fn factor_out_gcd(&self) -> Expression
fn factor_out_gcd(&self) -> Expression
Factor out the GCD from an expression
Source§fn factor_common(&self) -> Expression
fn factor_common(&self) -> Expression
Factor common elements
Source§impl From<&str> for Expression
impl From<&str> for Expression
Source§fn from(name: &str) -> Expression
fn from(name: &str) -> Expression
Source§impl From<Symbol> for Expression
impl From<Symbol> for Expression
Source§fn from(symbol: Symbol) -> Expression
fn from(symbol: Symbol) -> Expression
Source§impl From<f64> for Expression
impl From<f64> for Expression
Source§fn from(value: f64) -> Expression
fn from(value: f64) -> Expression
Source§impl From<i32> for Expression
impl From<i32> for Expression
Source§fn from(value: i32) -> Expression
fn from(value: i32) -> Expression
Source§impl From<i64> for Expression
impl From<i64> for Expression
Source§fn from(value: i64) -> Expression
fn from(value: i64) -> Expression
Source§impl Integration for Expression
impl Integration for Expression
Source§fn integrate(&self, variable: Symbol, depth: usize) -> Expression
fn integrate(&self, variable: Symbol, depth: usize) -> Expression
Source§fn definite_integrate(
&self,
variable: Symbol,
lower: Expression,
upper: Expression,
) -> Expression
fn definite_integrate( &self, variable: Symbol, lower: Expression, upper: Expression, ) -> Expression
Source§impl LaTeXFormatter for Expression
impl LaTeXFormatter for Expression
Source§fn to_latex_with_depth(
&self,
context: &LaTeXContext,
depth: usize,
) -> Result<String, FormattingError>
fn to_latex_with_depth( &self, context: &LaTeXContext, depth: usize, ) -> Result<String, FormattingError>
Source§fn function_to_latex_with_depth(
&self,
name: &str,
args: &[Expression],
context: &LaTeXContext,
depth: usize,
) -> Result<String, FormattingError>
fn function_to_latex_with_depth( &self, name: &str, args: &[Expression], context: &LaTeXContext, depth: usize, ) -> Result<String, FormattingError>
Source§fn to_latex<C>(&self, context: C) -> Result<String, FormattingError>
fn to_latex<C>(&self, context: C) -> Result<String, FormattingError>
Source§fn function_to_latex(
&self,
name: &str,
args: &[Expression],
context: &LaTeXContext,
) -> Result<String, FormattingError>
fn function_to_latex( &self, name: &str, args: &[Expression], context: &LaTeXContext, ) -> Result<String, FormattingError>
Source§impl Limits for Expression
impl Limits for Expression
Source§fn limit(&self, variable: &Symbol, point: &Expression) -> Expression
fn limit(&self, variable: &Symbol, point: &Expression) -> Expression
Source§fn limit_directed(
&self,
variable: &Symbol,
point: &Expression,
direction: LimitDirection,
) -> Expression
fn limit_directed( &self, variable: &Symbol, point: &Expression, direction: LimitDirection, ) -> Expression
Source§fn limit_at_infinity(&self, variable: &Symbol) -> Expression
fn limit_at_infinity(&self, variable: &Symbol) -> Expression
Source§fn limit_at_negative_infinity(&self, variable: &Symbol) -> Expression
fn limit_at_negative_infinity(&self, variable: &Symbol) -> Expression
Source§impl Matchable for Expression
impl Matchable for Expression
Source§impl MatrixOperations for Expression
impl MatrixOperations for Expression
Source§fn matrix_add(&self, other: &Expression) -> Expression
fn matrix_add(&self, other: &Expression) -> Expression
Source§fn matrix_subtract(&self, other: &Expression) -> Expression
fn matrix_subtract(&self, other: &Expression) -> Expression
Source§fn matrix_multiply(&self, other: &Expression) -> Expression
fn matrix_multiply(&self, other: &Expression) -> Expression
Source§fn matrix_scalar_multiply(&self, scalar: &Expression) -> Expression
fn matrix_scalar_multiply(&self, scalar: &Expression) -> Expression
Source§fn matrix_determinant(&self) -> Expression
fn matrix_determinant(&self) -> Expression
Source§fn matrix_transpose(&self) -> Expression
fn matrix_transpose(&self) -> Expression
Source§fn matrix_inverse(&self) -> Expression
fn matrix_inverse(&self) -> Expression
Source§fn matrix_trace(&self) -> Expression
fn matrix_trace(&self) -> Expression
Source§fn matrix_power(&self, exponent: &Expression) -> Expression
fn matrix_power(&self, exponent: &Expression) -> Expression
Source§fn is_identity_matrix(&self) -> bool
fn is_identity_matrix(&self) -> bool
Source§fn is_zero_matrix(&self) -> bool
fn is_zero_matrix(&self) -> bool
Source§fn is_diagonal(&self) -> bool
fn is_diagonal(&self) -> bool
Source§fn simplify_matrix(&self) -> Expression
fn simplify_matrix(&self) -> Expression
Source§impl Mul<&Expression> for Expression
impl Mul<&Expression> for Expression
Source§type Output = Expression
type Output = Expression
* operator.Source§fn mul(self, rhs: &Expression) -> Expression
fn mul(self, rhs: &Expression) -> Expression
* operation. Read moreSource§impl Mul<Expression> for &Expression
impl Mul<Expression> for &Expression
Source§type Output = Expression
type Output = Expression
* operator.Source§fn mul(self, rhs: Expression) -> Expression
fn mul(self, rhs: Expression) -> Expression
* operation. Read moreSource§impl Mul<i32> for &Expression
impl Mul<i32> for &Expression
Source§type Output = Expression
type Output = Expression
* operator.Source§impl Mul<i32> for Expression
impl Mul<i32> for Expression
Source§type Output = Expression
type Output = Expression
* operator.Source§impl Mul for &Expression
impl Mul for &Expression
Source§type Output = Expression
type Output = Expression
* operator.Source§fn mul(self, rhs: &Expression) -> Expression
fn mul(self, rhs: &Expression) -> Expression
* operation. Read moreSource§impl Mul for Expression
impl Mul for Expression
Source§type Output = Expression
type Output = Expression
* operator.Source§fn mul(self, rhs: Expression) -> Expression
fn mul(self, rhs: Expression) -> Expression
* operation. Read moreSource§impl Neg for &Expression
impl Neg for &Expression
Source§type Output = Expression
type Output = Expression
- operator.Source§fn neg(self) -> Expression
fn neg(self) -> Expression
- operation. Read moreSource§impl Neg for Expression
impl Neg for Expression
Source§type Output = Expression
type Output = Expression
- operator.Source§fn neg(self) -> Expression
fn neg(self) -> Expression
- operation. Read moreSource§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl PolynomialArithmetic for Expression
impl PolynomialArithmetic for Expression
Source§fn poly_div(
&self,
divisor: &Expression,
var: &Symbol,
) -> Result<(Expression, Expression), PolynomialError>
fn poly_div( &self, divisor: &Expression, var: &Symbol, ) -> Result<(Expression, Expression), PolynomialError>
Source§fn poly_quo(
&self,
divisor: &Expression,
var: &Symbol,
) -> Result<Expression, PolynomialError>
fn poly_quo( &self, divisor: &Expression, var: &Symbol, ) -> Result<Expression, PolynomialError>
Source§fn poly_rem(
&self,
divisor: &Expression,
var: &Symbol,
) -> Result<Expression, PolynomialError>
fn poly_rem( &self, divisor: &Expression, var: &Symbol, ) -> Result<Expression, PolynomialError>
Source§fn is_divisible_by(&self, divisor: &Expression, var: &Symbol) -> bool
fn is_divisible_by(&self, divisor: &Expression, var: &Symbol) -> bool
Source§impl PolynomialClassification for Expression
impl PolynomialClassification for Expression
Source§fn is_polynomial(&self) -> bool
fn is_polynomial(&self) -> bool
Source§fn is_polynomial_in(&self, vars: &[Symbol]) -> bool
fn is_polynomial_in(&self, vars: &[Symbol]) -> bool
Source§fn polynomial_variables(&self) -> Vec<Symbol>
fn polynomial_variables(&self) -> Vec<Symbol>
Source§fn classify(&self) -> ExpressionClass
fn classify(&self) -> ExpressionClass
Source§fn is_intpoly_compatible(&self) -> bool
fn is_intpoly_compatible(&self) -> bool
Source§impl PolynomialEducational for Expression
impl PolynomialEducational for Expression
Source§fn explain_poly_division(
&self,
divisor: &Expression,
var: &Symbol,
) -> StepByStepExplanation
fn explain_poly_division( &self, divisor: &Expression, var: &Symbol, ) -> StepByStepExplanation
Source§fn explain_poly_gcd(&self, other: &Expression) -> StepByStepExplanation
fn explain_poly_gcd(&self, other: &Expression) -> StepByStepExplanation
Source§fn explain_poly_factorization(&self, var: &Symbol) -> StepByStepExplanation
fn explain_poly_factorization(&self, var: &Symbol) -> StepByStepExplanation
Source§impl PolynomialGcd for Expression
impl PolynomialGcd for Expression
Source§fn gcd(&self, other: &Expression) -> Expression
fn gcd(&self, other: &Expression) -> Expression
GCD using IntPoly fast-path (primary path)
Converts to IntPoly at API boundary, performs pure numeric GCD, converts result back. NO Expression tree walking in fast path.
Source§fn lcm(&self, other: &Expression) -> Expression
fn lcm(&self, other: &Expression) -> Expression
Least Common Multiple
Source§fn factor_gcd(&self) -> Expression
fn factor_gcd(&self) -> Expression
Factor out GCD from expression
Source§fn cofactors(&self, other: &Expression) -> (Expression, Expression, Expression)
fn cofactors(&self, other: &Expression) -> (Expression, Expression, Expression)
Compute GCD and cofactors: returns (gcd, a/gcd, b/gcd)
Source§fn div_polynomial(
&self,
divisor: &Expression,
var: &Symbol,
) -> (Expression, Expression)
fn div_polynomial( &self, divisor: &Expression, var: &Symbol, ) -> (Expression, Expression)
Source§fn quo_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression
fn quo_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression
Source§fn rem_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression
fn rem_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression
Source§impl PolynomialGcdOps for Expression
impl PolynomialGcdOps for Expression
Source§fn polynomial_gcd(
&self,
other: &Expression,
) -> Result<Expression, PolynomialError>
fn polynomial_gcd( &self, other: &Expression, ) -> Result<Expression, PolynomialError>
Source§fn polynomial_lcm(
&self,
other: &Expression,
) -> Result<Expression, PolynomialError>
fn polynomial_lcm( &self, other: &Expression, ) -> Result<Expression, PolynomialError>
Source§fn polynomial_cofactors(
&self,
other: &Expression,
) -> Result<(Expression, Expression, Expression), PolynomialError>
fn polynomial_cofactors( &self, other: &Expression, ) -> Result<(Expression, Expression, Expression), PolynomialError>
Source§impl PolynomialProperties for Expression
impl PolynomialProperties for Expression
Source§fn degree(&self, var: &Symbol) -> Option<i64>
fn degree(&self, var: &Symbol) -> Option<i64>
Source§fn total_degree(&self) -> Option<i64>
fn total_degree(&self) -> Option<i64>
Source§fn leading_coefficient(&self, var: &Symbol) -> Expression
fn leading_coefficient(&self, var: &Symbol) -> Expression
Source§fn content(&self) -> Expression
fn content(&self) -> Expression
Source§fn primitive_part(&self) -> Expression
fn primitive_part(&self) -> Expression
Source§impl RationalSimplify for Expression
impl RationalSimplify for Expression
Source§fn simplify_rational(&self) -> Expression
fn simplify_rational(&self) -> Expression
Simplify rational expressions by canceling common factors
Source§fn to_rational_form(&self) -> (Expression, Expression)
fn to_rational_form(&self) -> (Expression, Expression)
Convert to rational form (numerator/denominator)
Source§fn rationalize(&self) -> Expression
fn rationalize(&self) -> Expression
Rationalize denominators (remove radicals from denominators)
Source§impl ResidueCalculus for Expression
impl ResidueCalculus for Expression
Source§fn residue(&self, variable: &Symbol, pole: &Expression) -> Expression
fn residue(&self, variable: &Symbol, pole: &Expression) -> Expression
Source§fn find_poles(&self, variable: &Symbol) -> Vec<Expression>
fn find_poles(&self, variable: &Symbol) -> Vec<Expression>
Source§fn contour_integral(&self, variable: &Symbol) -> Expression
fn contour_integral(&self, variable: &Symbol) -> Expression
Source§impl Serialize for Expression
impl Serialize for Expression
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl SeriesExpansion for Expression
impl SeriesExpansion for Expression
Source§fn taylor_series(
&self,
variable: &Symbol,
point: &Expression,
order: u32,
) -> Expression
fn taylor_series( &self, variable: &Symbol, point: &Expression, order: u32, ) -> Expression
Source§fn laurent_series(
&self,
variable: &Symbol,
point: &Expression,
order: u32,
) -> Expression
fn laurent_series( &self, variable: &Symbol, point: &Expression, order: u32, ) -> Expression
Source§fn maclaurin_series(&self, variable: &Symbol, order: u32) -> Expression
fn maclaurin_series(&self, variable: &Symbol, order: u32) -> Expression
Source§fn power_series_coefficients(
&self,
variable: &Symbol,
point: &Expression,
order: u32,
) -> Vec<Expression>
fn power_series_coefficients( &self, variable: &Symbol, point: &Expression, order: u32, ) -> Vec<Expression>
Source§impl SimpleFormatter for Expression
impl SimpleFormatter for Expression
Source§fn to_simple_with_depth(
&self,
context: &SimpleContext,
depth: usize,
) -> Result<String, FormattingError>
fn to_simple_with_depth( &self, context: &SimpleContext, depth: usize, ) -> Result<String, FormattingError>
Source§fn to_simple(&self, context: &SimpleContext) -> Result<String, FormattingError>
fn to_simple(&self, context: &SimpleContext) -> Result<String, FormattingError>
Source§impl Simplify for Expression
impl Simplify for Expression
Source§fn simplify(&self) -> Expression
fn simplify(&self) -> Expression
Source§impl SolverStepByStep for Expression
impl SolverStepByStep for Expression
Source§fn solve_with_steps(
&self,
_variable: &Symbol,
) -> (SolverResult, StepByStepExplanation)
fn solve_with_steps( &self, _variable: &Symbol, ) -> (SolverResult, StepByStepExplanation)
Source§fn explain_solving_steps(&self, variable: &Symbol) -> StepByStepExplanation
fn explain_solving_steps(&self, variable: &Symbol) -> StepByStepExplanation
Source§impl StepByStep for Expression
impl StepByStep for Expression
Source§fn explain_simplification(&self) -> StepByStepExplanation
fn explain_simplification(&self) -> StepByStepExplanation
Generate step-by-step explanation for simplification
Source§fn explain_expansion(&self) -> StepByStepExplanation
fn explain_expansion(&self) -> StepByStepExplanation
Generate step-by-step explanation for expansion
Source§fn explain_factorization(&self) -> StepByStepExplanation
fn explain_factorization(&self) -> StepByStepExplanation
Generate step-by-step explanation for factorization
Source§impl Sub<&Expression> for Expression
impl Sub<&Expression> for Expression
Source§type Output = Expression
type Output = Expression
- operator.Source§fn sub(self, rhs: &Expression) -> Expression
fn sub(self, rhs: &Expression) -> Expression
- operation. Read moreSource§impl Sub<Expression> for &Expression
impl Sub<Expression> for &Expression
Source§type Output = Expression
type Output = Expression
- operator.Source§fn sub(self, rhs: Expression) -> Expression
fn sub(self, rhs: Expression) -> Expression
- operation. Read moreSource§impl Sub<i32> for Expression
impl Sub<i32> for Expression
Source§type Output = Expression
type Output = Expression
- operator.Source§impl Sub for &Expression
impl Sub for &Expression
Source§type Output = Expression
type Output = Expression
- operator.Source§fn sub(self, rhs: &Expression) -> Expression
fn sub(self, rhs: &Expression) -> Expression
- operation. Read moreSource§impl Sub for Expression
impl Sub for Expression
Source§type Output = Expression
type Output = Expression
- operator.Source§fn sub(self, rhs: Expression) -> Expression
fn sub(self, rhs: Expression) -> Expression
- operation. Read moreSource§impl Substitutable for Expression
impl Substitutable for Expression
Source§fn subs(&self, old: &Expression, new: &Expression) -> Expression
fn subs(&self, old: &Expression, new: &Expression) -> Expression
Source§fn subs_multiple(
&self,
substitutions: &[(Expression, Expression)],
) -> Expression
fn subs_multiple( &self, substitutions: &[(Expression, Expression)], ) -> Expression
Source§impl Summation for Expression
impl Summation for Expression
Source§fn finite_sum(
&self,
variable: &Symbol,
start: &Expression,
end: &Expression,
) -> Expression
fn finite_sum( &self, variable: &Symbol, start: &Expression, end: &Expression, ) -> Expression
Source§fn infinite_sum(&self, variable: &Symbol, start: &Expression) -> Expression
fn infinite_sum(&self, variable: &Symbol, start: &Expression) -> Expression
Source§fn finite_product(
&self,
variable: &Symbol,
start: &Expression,
end: &Expression,
) -> Expression
fn finite_product( &self, variable: &Symbol, start: &Expression, end: &Expression, ) -> Expression
Source§fn infinite_product(&self, variable: &Symbol, start: &Expression) -> Expression
fn infinite_product(&self, variable: &Symbol, start: &Expression) -> Expression
Source§impl SummationEducational for Expression
impl SummationEducational for Expression
Source§fn explain_finite_sum(
&self,
variable: &Symbol,
start: &Expression,
end: &Expression,
) -> StepByStepExplanation
fn explain_finite_sum( &self, variable: &Symbol, start: &Expression, end: &Expression, ) -> StepByStepExplanation
Source§fn explain_infinite_sum(
&self,
variable: &Symbol,
start: &Expression,
) -> StepByStepExplanation
fn explain_infinite_sum( &self, variable: &Symbol, start: &Expression, ) -> StepByStepExplanation
Source§impl WolframFormatter for Expression
impl WolframFormatter for Expression
Source§fn format_function_with_depth(
&self,
name: &str,
args: &[Expression],
context: &WolframContext,
depth: usize,
) -> Result<String, FormattingError>
fn format_function_with_depth( &self, name: &str, args: &[Expression], context: &WolframContext, depth: usize, ) -> Result<String, FormattingError>
Convert function to Wolfram Language with depth tracking
Source§fn to_wolfram_with_depth(
&self,
context: &WolframContext,
depth: usize,
) -> Result<String, FormattingError>
fn to_wolfram_with_depth( &self, context: &WolframContext, depth: usize, ) -> Result<String, FormattingError>
Source§fn to_wolfram(
&self,
context: &WolframContext,
) -> Result<String, FormattingError>
fn to_wolfram( &self, context: &WolframContext, ) -> Result<String, FormattingError>
Source§impl ZeroDetection for Expression
impl ZeroDetection for Expression
Source§fn is_algebraic_zero(&self) -> bool
fn is_algebraic_zero(&self) -> bool
Detect if an expression is algebraically equivalent to zero
Source§fn detect_zero_patterns(&self) -> bool
fn detect_zero_patterns(&self) -> bool
Detect common patterns that equal zero
Source§fn simplify_to_zero(&self) -> Option<Expression>
fn simplify_to_zero(&self) -> Option<Expression>
Try to simplify expression to zero if it’s algebraically zero
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more