Introduction
Symjit is a lightweight just-in-time (JIT) optimizer compiler for mathematical expressions written in Rust. It was originally designed to compile SymPy (Python’s symbolic algebra package) expressions into machine code and to serve as a bridge between SymPy and numerical routines provided by NumPy and SciPy libraries.
Symjit emits AMD64 (x86-64), ARM64 (aarch64), and 64-bit RISC-V (riscv64) machine codes on Linux, Windows, and macOS platforms. SIMD is supported on x86-64 CPUs with AVX instruction sets.
Symbolica (https://symbolica.io/) is a fast Rust-based Computer Algebra System. Symbolica usually generate fast code using external compilers (e.g., using gcc to compile synthetic c++ code). Symjit accepts Symbolica expressions and can act as an optional code-generator for Symbolica.
Symjit-bridge crate acts as a bridge between Symbolica and Symjit to ease generating JIT code for Symbolica expressions.
Workflow
The main workflow is using different Runners. A runner corresponds to a Symbolica
CompiledEvaluator object. The main runners are:
CompiledRealRunner, corresponding toCompiledRealEvaluator.CompiledComplexRunner, corresponding toCompiledComplexEvaluator.CompiledSimdRealRunner, corresponding toCompiledSimdRealEvaluator.CompiledSimdComplexRunner, corresponding toCompiledSimdComplexEvaluator.CompiledTransposedSimdRealRunner, similar toCompiledSimdRealRunnerbut the data layout is similar toCompiledRealRunner.CompiledTransposedSimdComplexRunner, similar toCompiledSimdComplexRunnerbut the data layout is similar toCompiledComplexRunner.InterpretedRealRunner, bytecode interpreter, generally similar toExpressionEvaluator.InterpretedComplexRunner, bytecode interpreter, generally similar toExpressionEvaluator.
Each runner has four main methods:
compile(ev: &ExpressionEvaluator<T>, config: Config): the main constructor.Tis eitherf64orComplex<f64>, andconfigis an object of typeConfig. For most applications, the default config suffices. However,Config.use_threads(bool)is useful to enable multi-threading.evaluate(args, outs): similar to the corresponding method of theEvaluators.save(filename).load(filename).
use Result;
use ;
use ;
External Functions
Symjit has a rich set of transcendental, conditional, and logical functions (refer to
Symjit for details). It is possible to expose
these functions to Symbolica by using add_external_function: