oCAS is a modern, high-performance computer algebra system written in Rust. Its performance target is to match or exceed the core performance of Symbolica and SageMath while remaining free and open under the LGPL-3.0-or-later license. This is a target, not a measured current result: the gap against the reference systems is tracked in GAP_ANALYSIS_EN.md and BENCHMARK_RESULTS_CN.md (Chinese).
Status: Beta (0.30.0). The full symbolic engine, polynomial algebra, equation solvers, ODE solvers (first/second-order + systems + series + Laplace IVP), JIT/SIMD evaluation, and tri-language bindings (Rust, Python, C/C++) are feature-complete.
pip install ocasis available on PyPI. See the documentation (中文), Rust API docs, and roadmap.Note on docs.rs: The hosted Rust API docs are built with portable features only (no system GMP/MPFR/FLINT backends). To browse the full API including backend features, build the documentation locally with
cargo doc -p ocas --features gmp,mpfr,flint --no-deps.
| Capability | oCAS | Symbolica | SageMath |
|---|---|---|---|
| Core language | Rust | Rust | Python/Cython |
| License | LGPL-3.0+ | Proprietary / source-available | GPL-3.0 |
| Python API | ✅ PyO3 | ✅ | ✅ Native |
| C/C++ API | ✅ cbindgen | ✅ | |
| Rust API | ✅ Native | ✅ | ❌ |
| High-performance backend | GMP / FLINT 3 / Arb / LinBox | Self-hosted + optional | FLINT / Singular / PARI |
| JIT code generation | Cranelift | Custom | Limited |
| E-graph simplification | ✅ egg (optional) |
❌ | Partial |
oCAS targets researchers, engineers, and developers who need a fast, embeddable, and license-clean symbolic computation engine.
- Symbolic expressions: variables, functions, rational numbers, arbitrary-precision integers, floats, and complex numbers.
- Fast parsing & printing: Mathematica-like and Python-like syntax, LaTeX output.
-
Simplification & rewriting: normalization, hash consing, and equality
saturation via
egg. - Polynomial arithmetic: dense and sparse multivariate polynomials, GCD, univariate and bivariate factorization (Hensel lifting), algebraic number fields (Trager), Gröbner bases (Buchberger/F4/F5, WeightOrder, BlockOrder, MatrixOrder), resultants.
- Ideal operations: membership testing, sum, product, quotient, saturation, intersection, elimination, zero-dimensional solving, primary decomposition, radical computation, and Hilbert series.
- Algebraic geometry: zero-dimensional system solving with Sturm root isolation, primary decomposition via Lex GB factoring, Jacobian-based radical computation.
- Calculus: symbolic differentiation, partial integration, Taylor/Laurent series.
- ODE solving: first-order (separable/linear/Bernoulli/exact/homogeneous + integrating factors), second-order (constant-coefficient/Cauchy-Euler + variation of parameters + reduction of order), power series + Frobenius, Laplace IVP, and 2×2 constant-coefficient systems.
- Equation solving: linear systems, polynomial systems, algebraic numbers.
- Numerical evaluation: arbitrary-precision floating point, interval arithmetic, adaptive Monte Carlo integration (Vegas).
- Automatic differentiation: forward-mode via hyper-dual numbers.
- JIT compilation: compile repeated expressions to native code with Cranelift (an LLVM backend is planned for 0.34).
- Multi-language bindings: Rust, Python, and C/C++ from a single codebase.
-
Optimized integer arithmetic: SOO (small-object optimization) stores
values fitting in
i64on the stack with GMP fallback for large values. -
Modular multivariate GCD: compute GCD over
$\mathbb{Z}[x,y]$ via reduction mod prime and reconstruction.
┌─────────────────────────────────────────────────────────────┐
│ Layer 5: Language Bindings │
│ Python (PyO3) │ C/C++ (cbindgen) │ Rust API │
├─────────────────────────────────────────────────────────────┤
│ Layer 4: Applications │
│ Parser │ Printer │ Solver │ Calculus │ Series │
├─────────────────────────────────────────────────────────────┤
│ Layer 3: Symbolic Engine │
│ Expression (Atom) │ Transformer │ Pattern Matcher │ Rewriting │ E-Graph │
├─────────────────────────────────────────────────────────────┤
│ Layer 2: Algebraic Kernel │
│ Polynomial │ Matrix │ Domain │ Number Theory │ Factorize │
├─────────────────────────────────────────────────────────────┤
│ Layer 1: Numeric Backend │
│ GMP/MPFR/MPC │ FLINT 3 / Arb │ NTL │ LinBox │ faer │
├─────────────────────────────────────────────────────────────┤
│ Layer 0: Runtime │
│ Arena Allocator │ Error Handling │ Thread Pool │ FFI Glue │
└─────────────────────────────────────────────────────────────┘
See ARCHITECTURE_EN.md for the full design.
[dependencies]
ocas = "0.30"use ocas::prelude::*;
use ocas_core::arena::Arena;
fn main() -> Result<(), ParseError> {
let arena = Arena::new();
let ctx = AtomArena::new(&arena);
let expr = parse(&ctx, "x^2 + 2*x + 1")?;
println!("{}", expr); // 1 + 2*x + x^2
Ok(())
}Rule-based simplification, pattern matching, and optional egg equality
saturation are available through ocas::prelude (see ocas-rewrite examples).
- Rust 1.97 or later
- C compiler (MSVC, GCC, or Clang)
- GMP, MPFR, and FLINT 3 development libraries
On Ubuntu/Debian:
sudo apt-get install libgmp-dev libmpfr-dev libflint-devOn macOS:
brew install gmp mpfr flintOn Windows, see docs/build-windows.md.
git clone https://github.com/charleshzh/ocas.git
cd ocas
cargo build --releasecargo test --workspace --exclude ocas-pyMatching Symbolica and SageMath on core workloads is a target, not a measured current result. oCAS builds on competitive components:
- Integer and rational arithmetic via GMP.
- Polynomial multiplication, GCD, and factorization via FLINT 3.
- Exact linear algebra via faer (default) and LinBox (optional).
- JIT evaluation via Cranelift.
Benchmarks are under active development; benchmark code lives in ocas-tests/benches. The measured gap against Symbolica, SageMath, and SymPy and its attribution are documented in GAP_ANALYSIS_EN.md (English) and BENCHMARK_RESULTS_CN.md (Chinese). Do not quote a speed-up without a fresh benchmark run.
See ROADMAP_EN.md for the versioned plan, and EVOLUTION_PLAN_EN.md for the fine-grained per-version evolution plan (Beta → 1.0).
This project is licensed under the GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later). See LICENSE for the full text.
Some optional backends (e.g., NTL, Singular, PARI/GP, SageMath interfaces) are
licensed under GPL-compatible licenses. These are isolated in the ocas-gpl
crate and disabled by default. Enabling them will produce a combined work
under GPL terms.
We welcome contributions. Please read CONTRIBUTING.md before opening a pull request.
oCAS builds on the shoulders of many excellent open-source projects: