Symbolic Simplification
Comprehensive symbolic simplification for mathematical expressions, with full support for noncommutative algebra (matrices, operators, quaternions). Implements canonical forms and mathematical identities to reduce expressions to simplest form.
Code Examples
Basic Simplification
Identity elements and constant folding
use mathhook::prelude::*;
let x = symbol!(x);
// Identity elements
let expr = expr!((x + 0) * 1);
let simplified = expr.simplify();
// Result: x
// Constant folding
let expr = expr!(2 + 3);
let simplified = expr.simplify();
// Result: 5
Power Rule Simplification
Combine like powers with same base
use mathhook::prelude::*;
let x = symbol!(x);
// Combine like powers
let expr = expr!((x^2) * (x^3));
let simplified = expr.simplify();
// Result: x^5
// Multiple powers
let expr = expr!((x^2) * (x^3) * (x^4));
let simplified = expr.simplify();
// Result: x^9
Noncommutative Algebra
Preserve order for noncommutative symbols
use mathhook::prelude::*;
// Scalar symbols (commutative) - factors can be sorted
let x = symbol!(x);
let y = symbol!(y);
let expr = expr!(y * x);
let simplified = expr.simplify();
// Result: x * y (sorted alphabetically)
// Matrix symbols (noncommutative) - order preserved
let A = symbol!(A; matrix);
let B = symbol!(B; matrix);
let expr = expr!(B * A);
let simplified = expr.simplify();
// Result: B * A (original order preserved)
Power Distribution (Commutative Only)
Distribute powers for scalars, not for matrices
use mathhook::prelude::*;
// Scalars (commutative): distributes power
let x = symbol!(x);
let y = symbol!(y);
let expr = expr!((x * y) ^ 2);
let simplified = expr.simplify();
// Result: x^2 * y^2 (distributed)
// Matrices (noncommutative): does NOT distribute
let A = symbol!(A; matrix);
let B = symbol!(B; matrix);
let expr = expr!((A * B) ^ 2);
let simplified = expr.simplify();
// Result: (A*B)^2 (NOT distributed to A^2 * B^2)
Rational Arithmetic
Exact rational computation with arbitrary precision
use mathhook::prelude::*;
let expr = expr!(1/3 + 1/6); // Rational arithmetic
let simplified = expr.simplify();
// Result: 1/2 (exact rational, not 0.5)
// Arbitrary precision
let expr = expr!(1/999999999 + 1/999999999);
let simplified = expr.simplify();
// Result: 2/999999999 (exact, no overflow)