A mathematics library for embedded scientific computation
Note: This library is in no way ready for even limited use. Use num-traits, num-complex, and nalgebra if you need a proper math library.
This repository contains Talrost, an experimental library with the goal of providing an ergonomic, expedient, and embedded-ready numerical tower existing at the edges of Rust’s limitations on specialization and type coercion. Will likely require libm, currently requires std.
Examples of use
Warning: Most features are not remotely close to being properly implemented. Do not expect to be able to use this library at this time.
Algebraic traits
Loosely selected algebraic structures:
trait Element: Sized + Copy + Clone + core::fmt::Display + Debug {}trait Monoid: Element + Add<Output = Self> + AddAssign { const ZERO: Self; }trait Group: Monoid + Sub<Output = Self> + SubAssign + Neg<Output = Self> { fn Neg(self) -> Self; }trait Semiring: Monoid + Mul<Output = Self> + MulAssign { const ONE: Self; }trait Ring: Group + Semiring {}trait Field: Ring + Div<Output = Self> + DivAssign { fn recip(self) -> Self; }
and then composes them to build a numerical tower accordingly:
trait Natural: Semiring + PartialOrd + PartialEq { ... } // unsigned intstrait Integer: Ring + Natural { ... } // signed intstrait Float: Field + Natural { ... } // standard floats & (currently) complex numbers
Complex arithmetic
Implements Float, exposed as c32 and c64 with like-basis interoperability with f32 and f64 accordingly.
use *;
let a: f64 = 0.25;
let mut b: c64 = .into;
b += a;
b /= new;
assert_eq!;
Polynomials
Supports polynomials in $\mathbb{R}$ (working) and $\mathbb{C}$ (broken).
use *;
let tol = f64EPSILON;
// p(x) = 1x^3 + 5x^2 + -14x + 0, has roots -7, 0, 2
let p = new;
let y = p.eval;
assert_eq!; // p(4) = 88
let r = roots_cubic;
assert_eq!; // count roots
assert_eq!; // verify ordered roots
Vectors and Matrices
Vectors are supported over $\mathbb{Rn}$ and $\mathbb{Cn}$, with explicit coercion to row and column matrix types.
use ;
let v1 = new;
let v2 = new;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let vec_real = new;
let vec_complex = new;
assert_eq!;
assert_eq!;
$M \times N$ matrices are supported over $\mathbb{Rn}$ and $\mathbb{Cn}$.
use *;
let x = new;
assert_eq!;
let y = new;
assert_eq!;
let a = new;
let b = new;
let c = new;
assert_eq!;