MathSolver

Struct MathSolver 

Source
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.

§Examples

use mathhook_core::{MathSolver, Expression, symbol, expr};
use mathhook_core::simplify::Simplify;

let mut 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 = 2

Implementations§

Source§

impl MathSolver

Source

pub fn new() -> Self

Create a new solver with default configuration

§Examples
use mathhook_core::MathSolver;

let solver = MathSolver::new();
Source

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);
Source

pub fn solve( &mut 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 mut solver = MathSolver::new();
let equation = Expression::equation(
    expr!(x),
    expr!(5),
);
let result = solver.solve(&equation, &symbol!(x));
Source

pub fn solve_system( &mut self, equations: &[Expression], variables: &[Symbol], ) -> Vec<SolverResult>

Solve a system of equations

§Examples
use mathhook_core::{MathSolver, Expression};
use mathhook_core::{symbol, expr};

let mut 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);
Source

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§

Source§

impl Default for MathSolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.