Skip to main content

Module eq

Module eq 

Source
Expand description

Symbolic equation type (lhs = rhs). Symbolic equation type.

Equation represents lhs = rhs and provides convenience methods for solving, substitution, rearrangement, and display. Internally, solving converts to lhs - rhs = 0 and delegates to the existing solver.

The type is named Equation (not Eq) to avoid conflict with std::cmp::Eq.

§Arithmetic

Applying an operation to both sides is written with the ordinary operators: &eq + 1, &eq * &x, -&eq, &eq / 2.0. The right-hand operand may be any ToEx value (integers, f64 — converted exactly — BigInt, Ratio, Ex, &Ex). Two equations can also be combined side-by-side: &eq1 + &eq2 is lhs1 + lhs2 = rhs1 + rhs2.

use symplex::prelude::*;

let ctx = Context::new();
let x = ctx.symbol("x");
let eq = Equation::new(&x * 2 + 3, ctx.int(11));   // 2x + 3 = 11
let eq = (&eq - 3) / 2;                             // x = 4
assert_eq!(format!("{eq}"), "x = 4");
assert_eq!(eq.solve(&x).unwrap(), vec![ctx.int(4)]);

Structs§

Equation
A symbolic equation lhs = rhs.

Traits§

Scalar
Rust numeric types accepted as the right-hand operand of + - * / (and += -= *= /=) on Ex: i32, i64, i128, u32, u64, f64, BigInt, Ratio<BigInt>.
ToEx
A Rust value that can be turned into an exact expression in a Context.