pub trait Integration {
// Required methods
fn integrate(&self, variable: Symbol, depth: usize) -> Expression;
fn definite_integrate(
&self,
variable: Symbol,
lower: Expression,
upper: Expression,
) -> Result<Expression, MathError>;
}Expand description
Trait for integration operations
Added depth parameter to prevent infinite recursion in integration by parts.
The depth parameter tracks recursion depth and enables maximum depth limiting.
Default depth is 0 (top-level call). Internal implementations increment this to prevent stack overflow in cases where simplification fails.
Required Methods§
Sourcefn integrate(&self, variable: Symbol, depth: usize) -> Expression
fn integrate(&self, variable: Symbol, depth: usize) -> Expression
Compute indefinite integral with recursion depth tracking
Returns an unevaluated integral if no closed form exists.
§Arguments
variable- The variable to integrate with respect todepth- Current recursion depth (default: 0)
§Examples
use mathhook_core::calculus::integrals::IntegrationMethods;
use mathhook_core::Expression;
use mathhook_core::calculus::integrals::Integration;
use mathhook_core::symbol;
let x = symbol!(x);
let expr = Expression::pow(Expression::symbol(x.clone()), Expression::integer(2));
let result = expr.integrate(x, 0);Sourcefn definite_integrate(
&self,
variable: Symbol,
lower: Expression,
upper: Expression,
) -> Result<Expression, MathError>
fn definite_integrate( &self, variable: Symbol, lower: Expression, upper: Expression, ) -> Result<Expression, MathError>
Compute definite integral
§Errors
Returns MathError::DomainError when evaluation at bounds fails.
§Examples
use mathhook_core::Expression;
use mathhook_core::symbol;
use mathhook_core::calculus::integrals::Integration;
let x = symbol!(x);
let expr = Expression::symbol(x.clone());
let lower = Expression::integer(0);
let upper = Expression::integer(1);
let result = expr.definite_integrate(x, lower, upper);