ARAEL
Algorithms for Robust Autonomy, Estimation, and Localization
A Rust framework for nonlinear optimization with compile-time symbolic differentiation. Define your model and constraints declaratively -- the macro system symbolically differentiates, applies common subexpression elimination, and generates compiled cost/gradient/hessian code.
Features
- Symbolic math -- expression trees with automatic differentiation, simplification, expansion, LaTeX/Rust code generation
- Compile-time constraint code generation -- write constraints symbolically, get compiled derivative code with CSE
- Levenberg-Marquardt solver -- with robust error suppression via the Starship method (US12346118)
gamma * atan(r / gamma) - Multiple solver backends via
LmSolvertrait:- Dense Cholesky (nalgebra) -- fixed-size dispatch up to 9x9, dynamic for larger
- Band Cholesky -- pure Rust O(n*kd^2) for block-tridiagonal systems (9.4x faster than dense at 500 poses)
- Sparse Cholesky (faer, pure Rust) -- for general sparse hessians (66x faster than dense at 200 poses with 6% fill)
- Eigen SimplicialLLT and CHOLMOD -- optional C++ backends via FFI (
--features eigen,--features cholmod) - LAPACK band -- optional dpbsv/spbsv backend (
--features lapack)
- Indexed sparse assembly -- precomputed position lists for zero-overhead hessian assembly after first iteration
- f32 and f64 precision --
#[arael(root)]for f64,#[arael(root, f32)]for f32 throughout - Model trait -- hierarchical serialize/deserialize/update protocol for parameter optimization
- Type-safe references --
Ref<T>,Vec<T>,Deque<T>,Arena<T>for indexed collections with stable references - Hessian blocks --
SelfBlock<A>andCrossBlock<A, B>generic over float type for sparse hessian structure - WASM/browser support -- the sketch editor compiles to WebAssembly and runs in the browser via eframe/egui
Quick Example: Symbolic Math
use *;
sym!
The arael::sym! macro auto-inserts .clone() on variable reuse, so you write natural math without Rust's ownership boilerplate.
See docs/SYM.md for the full symbolic math reference.
Quick Example: Robust Linear Regression
Define a model with optimizable parameters and a residual expression. The gamma * atan(plain_r / gamma) formulation is the Starship robust error suppression method -- residuals up to ~gamma pass linearly, beyond that they saturate, suppressing outlier influence while preserving smooth differentiability:
The macro auto-generates calc_cost(), calc_grad_hessian(), and fit() methods with symbolically differentiated, CSE-optimized compiled code:
The robust fit ignores outliers while tracking the inlier data:

See docs/LINEAR.md for the full walkthrough. Full source: examples/linear_demo.rs.
SLAM Path Optimization
For multi-body optimization (SLAM, bundle adjustment), define your model hierarchy with constraints. The macro system handles symbolic differentiation, reference resolution, and code generation automatically.
The demo (examples/slam_demo.rs) generates a synthetic S-curve trajectory with 60 poses and 240 landmarks observed by 5 cameras. It handles 50% outlier associations with 30x pixel noise via robust suppression and graduated optimization. The solver uses faer sparse Cholesky (pure Rust) to exploit the hessian's sparsity structure:

The sparsity pattern shows pose-pose blocks (upper-left), pose-landmark coupling (off-diagonal), and landmark self-blocks (lower-right diagonal). The faer sparse Cholesky solver exploits this, achieving 66x speedup over dense at 200 poses.
// Robot pose -- multiple constraints on the same hessian block
}))]
// Observation linking a landmark to a pose
}))]
// Odometry constraint between consecutive poses
// Root model -- triggers code generation for all constraints
The #[arael(root)] attribute generates calc_cost() and calc_grad_hessian() methods that traverse the entire hierarchy, resolve references, and evaluate all constraints with compiled, CSE-optimized derivative code.
See docs/SLAM.md for the full walkthrough.
Localization Demo
Same model as SLAM but landmarks are fixed (known map). Since landmark positions are not optimized, there is no gauge freedom and absolute pose errors are meaningful. No GPS needed -- the known landmarks anchor the solution.
The frine constraint uses a remote block (pose.hb_pose) -- the hessian block lives on Pose, not on PointFrine, since only Pose has parameters. With only pose parameters, the hessian is block-tridiagonal (kd=11 for 6-param poses), so the band solver can be used for O(n) scaling instead of O(n^3) dense -- 9.4x faster at 500 poses.
See examples/loc_demo.rs.
2D Sketch Editor
An interactive constraint-based 2D sketch editor built on the arael optimization framework. Draw geometry, apply constraints, and the solver keeps everything consistent in real time.

Running (native)
Running (browser)
The sketch editor compiles to WebAssembly and runs in the browser.
Requires trunk (cargo install trunk) and the
wasm32-unknown-unknown target (rustup target add wasm32-unknown-unknown):
# Open http://localhost:8080
Tools
- Line (L), Circle (O), Arc (A), Point (P) -- draw geometry with auto-snap to nearby points, endpoints, and curves
- Dimension (D) -- add length, distance, and radius dimensions with draggable annotations
- Select (S) -- click to select, drag to move entities, Backspace/Delete to remove
- Dark/Light mode toggle, Save/Load (JSON), Undo/Redo (Ctrl+Z/Ctrl+Shift+Z)
Constraints
Horizontal (H), Vertical (V), Coincident (C), Parallel, Perpendicular, Equal length/radius, Tangent (T), Lock (K), Line style (X). Constraints are visualized as symbols on the geometry and can be selected and deleted.
Example: Sketch Solver API
use CrossBlock;
use vect2d;
use *;
let mut sketch = new;
// Create a rectangle from 4 lines
let bottom = sketch.add_line;
let right = sketch.add_line;
let top = sketch.add_line;
let left = sketch.add_line;
// Horizontal/vertical constraints
sketch.lines.constraints.horizontal = true;
sketch.lines.constraints.horizontal = true;
sketch.lines.constraints.vertical = true;
sketch.lines.constraints.vertical = true;
// Connect corners (a.p2 == b.p1)
sketch.coincident_ll21.push;
sketch.coincident_ll21.push;
sketch.coincident_ll21.push;
sketch.coincident_ll21.push;
// Fix bottom-left corner and set dimensions
sketch.lines.p1 = fixed;
sketch.lines.constraints.has_length = true;
sketch.lines.constraints.length = 4.0;
sketch.lines.constraints.has_length = true;
sketch.lines.constraints.length = 2.0;
// Solve -- all constraints satisfied simultaneously
sketch.solve;
// bottom: (0,0)->(4,0), right: (4,0)->(4,2), top: (4,2)->(0,2), left: (0,2)->(0,0)
The sketch solver uses Levenberg-Marquardt optimization with drift regularization and robust drag constraints. All constraints are symbolically differentiated at compile time.
See arael-sketch/ for the full implementation.
Project Structure
arael/ Main library
src/
model.rs Param<T>, Model trait, SelfBlock, CrossBlock (generic over float type)
simple_lm.rs LM solver, LmSolver trait, Dense/Band/Sparse backends, CooMatrix, CscMatrix
refs.rs Type-safe Vec<T>, Deque<T>, Arena<T>, Ref<T>
vect.rs vect2<T>, vect3<T>
matrix.rs matrix2<T>, matrix3<T>
quatern.rs quatern<T>
cpp/
eigen_sparse.cpp Eigen SimplicialLLT + CHOLMOD FFI bridge (optional)
arael-sym/ Symbolic math library
src/
lib.rs E type, constructors, operators
diff.rs Symbolic differentiation
simplify.rs Algebraic simplification
cse.rs Common subexpression elimination
eval.rs Evaluation, substitution, free variables
fmt.rs Display, LaTeX, Rust code generation
geo.rs Symbolic vectors/matrices (vect3sym, matrix3sym)
linalg.rs SymVec, SymMat, Jacobian
parse.rs Expression parser
arael-macros/ Procedural macros
src/
lib.rs #[arael::model], sym!, field rewriting
constraint.rs Constraint code generation, CSE integration
arael-sketch/ 2D sketch constraint solver + editor
src/
lib.rs Entities, constraints, solver, Arena storage
examples/
editor.rs Interactive egui-based sketch editor
License
See LICENSE.md.