1 unstable release
Uses new Rust 2024
| 0.0.1 | Jun 2, 2025 |
|---|
#28 in #symbolic-math
620KB
13K
SLoC
DSLCompile: Mathematical Expression Compilation
DSLCompile provides a three-layer optimization strategy for mathematical expressions:
- Final Tagless Approach: Type-safe expression building with multiple interpreters
- Symbolic Optimization: Algebraic simplification using egglog
- Compilation Backends: Rust hot-loading (primary) and optional Cranelift JIT
Typed Variable System
The library includes a type-safe variable system that provides compile-time type checking with operator overloading syntax and full backward compatibility.
Quick Start with Typed Variables
use dslcompile::prelude::*;
// Create a typed math builder
let math = MathBuilder::new();
// Create typed variables
let x: TypedVar<f64> = math.typed_var();
let y: TypedVar<f32> = math.typed_var();
// Build expressions with syntax and type safety
let x_expr = math.expr_from(x);
let y_expr = math.expr_from(y);
let expr = &x_expr * &x_expr + y_expr; // f32 auto-promotes to f64
// Backward compatible API still works
let old_style = math.var(); // Defaults to f64
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Final Tagless Layer │
│ (Expression Building & Type Safety) │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Symbolic Optimization │
│ (Algebraic Simplification & Rewrite Rules) │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Compilation Backends │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Rust │ │ Cranelift │ │ Future Backends │ │
│ │ Hot-Loading │ │ JIT │ │ (LLVM, etc.) │ │
│ │ (Primary) │ │ (Optional) │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Dependencies
~0.5–17MB
~166K SLoC