pub struct LinearSolver {
pub show_steps: bool,
}Expand description
Handles linear equations with step-by-step explanations
Fields§
§show_steps: boolEnable step-by-step explanations
Implementations§
Trait Implementations§
Source§impl Clone for LinearSolver
impl Clone for LinearSolver
Source§fn clone(&self) -> LinearSolver
fn clone(&self) -> LinearSolver
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LinearSolver
impl Debug for LinearSolver
Source§impl Default for LinearSolver
impl Default for LinearSolver
Source§impl EquationSolver for LinearSolver
impl EquationSolver for LinearSolver
Source§fn solve(&self, equation: &Expression, variable: &Symbol) -> SolverResult
fn solve(&self, equation: &Expression, variable: &Symbol) -> SolverResult
Solve linear equation ax + b = 0
Fractional solutions are automatically simplified to lowest terms via
BigRational::new(), which reduces fractions using GCD. Integer solutions
(where numerator is divisible by denominator) are returned as integers.
§Examples
use mathhook_core::algebra::solvers::{linear::LinearSolver, EquationSolver, SolverResult};
use mathhook_core::core::{Expression, Number};
use mathhook_core::symbol;
use num_bigint::BigInt;
let solver = LinearSolver::new_fast();
let x = symbol!(x);
// Example: 4x = 6 gives x = 3/2 (simplified from 6/4)
let equation = Expression::add(vec![
Expression::mul(vec![Expression::integer(4), Expression::symbol(x.clone())]),
Expression::integer(-6),
]);
match solver.solve(&equation, &x) {
SolverResult::Single(solution) => {
if let Expression::Number(Number::Rational(r)) = solution {
assert_eq!(r.numer(), &BigInt::from(3));
assert_eq!(r.denom(), &BigInt::from(2));
}
}
_ => panic!("Expected single solution"),
}Source§fn solve_with_explanation(
&self,
equation: &Expression,
variable: &Symbol,
) -> (SolverResult, StepByStepExplanation)
fn solve_with_explanation( &self, equation: &Expression, variable: &Symbol, ) -> (SolverResult, StepByStepExplanation)
Solve with step-by-step explanation
Source§fn can_solve(&self, equation: &Expression) -> bool
fn can_solve(&self, equation: &Expression) -> bool
Check if this solver can handle the equation
Auto Trait Implementations§
impl Freeze for LinearSolver
impl RefUnwindSafe for LinearSolver
impl Send for LinearSolver
impl Sync for LinearSolver
impl Unpin for LinearSolver
impl UnwindSafe for LinearSolver
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
Mutably borrows from an owned value. Read more
§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)
🔬This is a nightly-only experimental API. (
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>
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