$ show symengine/SymEngine.jl
SymEngine.jl is a Julia wrapper for the SymEngine C++ symbolic mathematics library. It provides symbolic types (`Basic`), algebraic operations, calculus (differentiation, series expansion), substitution, numeric evaluation, and matrix operations (LU decomposition, determinants). The package uses C library calls via Julia's `ccall` and `SymEngine_jll` binaries, managing memory with finalizers. It extends Julia's generic interfaces (`+`, `*`, `diff`, etc.) for symbolic expressions and offers macros (`@vars`, `@funs`) for convenient variable and function declarations. The extension module for `TermInterface` allows integration with generic symbolic manipulation frameworks. The codebase is well-structured, with separate files for types, math operations, simplification, display, and dense matrix handling. It is production-ready, with CI testing across Julia versions and platforms, and is actively maintained with regular dependency updates via Dependabot. The primary use case is as a library for symbolic mathematics in Julia, suitable for research, education, and applications requiring algebraic manipulation.
The LLM identified 3 files worth highlighting for reuse:
Converts symbolic expressions to Julia functions via `lambdify`. It walks the expression tree using `convert(::Type{Expr}, ex)` to produce a Julia expression, then evaluates it with `eval` wrapped in `invokelatest` for safe closure creation. This is a reusable pattern for turning symbolic expressions into callable functions, applicable to other symbolic backends. The module also implements multiple dispatch for `subs` supporting pairs, dicts, and positional arguments.
Implements the `@vars` macro with a recursive parser for variable declarations including symbolic functions, named variables, and indexed arrays (e.g., `@vars x[1:3]`). The `VarDecl` type hierarchy and `parsedecl` function demonstrate sophisticated pattern matching on Julia ASTs to generate symbol definitions. This pattern is self-contained and could be adapted for other packages needing similar declarative syntax.
Defines a reusable metaprogramming pattern (`IMPLEMENT_ONE_ARG_FUNC` and `IMPLEMENT_TWO_ARG_FUNC`) for wrapping C library functions as Julia methods with mutating and non-mutating variants. It generates `!` versions (e.g., `sin!`) that reuse pre-allocated output `Basic` objects, reducing allocations. The pattern uses `@eval` and `ccall` with error handling, and can be extracted for wrapping any C library with a similar interface.