A Julia package for parsing, manipulating, and generating mathematical expressions in the MathJSON format.
MathJSON is a JSON-based format for representing mathematical expressions, providing interoperability with web-based mathematical tools like MathLive and the Cortex Compute Engine.
- Parse MathJSON: Convert MathJSON strings to Julia expression trees
- Generate MathJSON: Serialize Julia expressions to MathJSON format
- Validation: Verify expressions conform to the MathJSON specification
- Symbolics.jl Integration: Bidirectional conversion with Symbolics.jl expressions
- Cortex Compute Engine Compatible: Full support for all 382 operators from the official MathJSON standard library
using Pkg
Pkg.add("MathJSON")using MathJSON
# Parse a MathJSON expression
expr = parse(MathJSONFormat, """["Add", 1, 2]""")
# Generate MathJSON from an expression
json = generate(MathJSONFormat, FunctionExpr(:Multiply, [NumberExpr(3), SymbolExpr("x")]))
# Output: "[\"Multiply\",3,\"x\"]"
# Validate an expression
result = validate(expr)MathJSON.jl provides seamless integration with Symbolics.jl:
using MathJSON
using Symbolics
# Convert MathJSON to Symbolics
expr = parse(MathJSONFormat, """["Add", "x", 1]""")
symbolic = to_symbolics(expr)
# Convert Symbolics to MathJSON
@variables x
mathjson = from_symbolics(x + 1)MathJSON.jl includes an extensive operator registry based on the Cortex Compute Engine standard library:
- 382 operators across 15 categories
- Arithmetic: Add, Subtract, Multiply, Divide, Power, Sqrt, Abs, Exp, Log, ...
- Trigonometry: Sin, Cos, Tan, Arcsin, Arccos, Arctan, Sinh, Cosh, ...
- Calculus: D (derivative), Integrate, Limit, Sum, Product, ...
- Linear Algebra: Determinant, Transpose, Inverse, Eigenvalues, ...
- Logic: And, Or, Not, Xor, Implies, Equivalent, ...
- Statistics: Mean, Median, Variance, StandardDeviation, ...
- And more: Collections, Combinatorics, Number Theory, Polynomials, ...
For full documentation, see the documentation site.
MIT License - see LICENSE for details.