Module xxcalc::linear_solver [] [src]

Defines a LinearSolver which extends a PolynomialCalculator with ability of solving single linear equation.

It supports the very same operations and functions as the PolynomialCalculator, however a new operator = is defined which solves a linear equation.

One can use LinearSolverParser, LinearSolverEvaluator or functions module in their own implementations, so there is no need of reimplementing this functionality.

Examples

A LinearSolver provides an easy way to integrate a solver and calculator into your project. It simply takes a string expression and returns evaluated value, however if you need high-efficiency solution you should consider using LinearSolverParser and LinearSolverEvaluator directly.

use xxcalc::linear_solver::LinearSolver;
use xxcalc::calculator::Calculator;
use xxcalc::polynomial::Polynomial;

assert_eq!(LinearSolver.process("2 * x + 0.5 = 1"), Ok(Polynomial::constant(0.25)));
assert_eq!(LinearSolver.process("2x + 1 = 2(1-x)"), Ok(Polynomial::constant(0.25)));
assert_eq!(LinearSolver.process("x^2-x^2+x=2"), Ok(Polynomial::constant(2.0)));
assert_eq!(LinearSolver.process("1-x=x"), Ok(Polynomial::constant(0.5)));

Modules

functions

Implementation of solving operator handler.

Structs

LinearSolver

LinearSolver is a calculator using a LinearSolverParser and a LinearSolverEvaluator, to provide multiple arithmetic operations and basic linear solver capability.

LinearSolverEvaluator

Extends PolynomialEvaluator with handler for linear solver operator.

LinearSolverParser

Extends PolynomialParser with a solving operator = with minimal precedence.

Enums

SolvingError

An error that occurs during linear solving.