pub struct MathSolver { /* private fields */ }Expand description
Stateful mathematical solver for the hybrid API
This is a separate object from Expression that maintains configuration and state for complex solving operations.
@no-binding - use Expression::solve() or Expression::solve_with_steps() instead
§Examples
use mathhook_core::{MathSolver, Expression, symbol, expr};
use mathhook_core::simplify::Simplify;
let solver = MathSolver::new();
let x = symbol!(x);
let equation = Expression::equation(
expr!((2*x) + 3),
expr!(7),
);
let result = solver.solve(&equation, &x);
// Result: SolverResult::Single for x = 2Implementations§
Source§impl MathSolver
impl MathSolver
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new solver with default configuration
§Examples
use mathhook_core::MathSolver;
let solver = MathSolver::new();Sourcepub fn with_config(config: SolverConfig) -> Self
pub fn with_config(config: SolverConfig) -> Self
Create a new solver with custom configuration
§Examples
use mathhook_core::{MathSolver, SolverConfig};
let config = SolverConfig {
max_iterations: 500,
tolerance: 1e-8,
use_numeric: true,
simplify_results: false,
};
let solver = MathSolver::with_config(config);Sourcepub fn solve(&self, equation: &Expression, variable: &Symbol) -> SolverResult
pub fn solve(&self, equation: &Expression, variable: &Symbol) -> SolverResult
Solve an equation for a given variable
§Examples
use mathhook_core::{MathSolver, Expression};
use mathhook_core::{symbol, expr};
let solver = MathSolver::new();
let equation = Expression::equation(
expr!(x),
expr!(5),
);
let result = solver.solve(&equation, &symbol!(x));Sourcepub fn solve_system(
&self,
equations: &[Expression],
variables: &[Symbol],
) -> Vec<SolverResult>
pub fn solve_system( &self, equations: &[Expression], variables: &[Symbol], ) -> Vec<SolverResult>
Solve a system of equations
§Examples
use mathhook_core::{MathSolver, Expression};
use mathhook_core::{symbol, expr};
let solver = MathSolver::new();
let equations = vec![
Expression::equation(expr!(x), expr!(1)),
Expression::equation(expr!(y), expr!(2)),
];
let variables = vec![symbol!(x), symbol!(y)];
let result = solver.solve_system(&equations, &variables);Sourcepub fn configure(&mut self, config: SolverConfig)
pub fn configure(&mut self, config: SolverConfig)
Update solver configuration
§Examples
use mathhook_core::{MathSolver, SolverConfig};
let mut solver = MathSolver::new();
let new_config = SolverConfig {
max_iterations: 2000,
..Default::default()
};
solver.configure(new_config);Trait Implementations§
Auto Trait Implementations§
impl Freeze for MathSolver
impl !RefUnwindSafe for MathSolver
impl Send for MathSolver
impl Sync for MathSolver
impl Unpin for MathSolver
impl !UnwindSafe for MathSolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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