Numerica
Numerica is an open-source mathematics library for Rust, that provides high-performance number types, such as error-tracking floats and finite field elements.
It provides
- Abstractions over rings, Euclidean domains, fields and floats
- High-performance Integer with automatic up-and-downgrading to arbitrary precision types
- Rational numbers with reconstruction algorithms
- Fast finite field arithmetic
- Error-tracking floating point types
- Generic dual numbers for automatic (higher-order) differentiation
- Matrix operations and linear system solving
- Numerical integration using Vegas algorithm with discrete layer support
For operations on symbols, check out the parent project Symbolica.
Examples
Solving a linear system
Solve a linear system over the rationals:
let a = from_linear
.unwrap;
let b = new_vec;
let r = a.solve.unwrap;
assert_eq!;
Solution: $(-1/3, 2/3, 0)$.
Solve over the finite field $\mathbb{Z}_7$:
let z_7 = new;
let a = from_linear
.unwrap;
let r = a.inv;
assert_eq!;
Error-tracking floating points
Wrap f64 and Float in an ErrorPropagatingFloat to propagate errors through
your computation. For example, a number with 60 accurate digits only has 10 remaining after the following operations:
let a = new;
let r = / a; // large cancellation
assert_eq!;
assert_eq!;
Automatic differentiation with dual numbers
Create a dual number that fits your needs (supports multiple variables and higher-order differentiation). Here, we create a simple dual number in three variables:
create_hyperdual_single_derivative!;
It yields (1/6)+(-1/6)*ε0+(-1/12)*ε1+(-1/18)*ε2.
The multiplication table is computed and unrolled at compile time for maximal performance.
Solve integer relations
Solve
$$ -32.0177 c_1 + 3.1416 c_2 + 2.7183 c_3 = 0 $$
over the integers using PSLQ:
let result = solve_integer_relation
.unwrap;
assert_eq!;
Or via LLL basis reduction:
let v1 = new;
let v2 = new;
let v3 = new;
let basis = basis_reduction;
assert_eq!;
Numerical integration
Integrate $sin(x \pi) + y$ using the Vegas algorithm and using random numbers suitable for Monte Carlo integration:
let f = ;
let mut grid = Continuous;
let mut rng = new;
let mut sample = new;
for iteration in 1..20
Development
Follow the development and discussions on Zulip!