Skip to content

s-celles/MathJSON.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MathJSON.jl

DOI Build Status Documentation Documentation Coverage

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.

Features

  • 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

Installation

using Pkg
Pkg.add("MathJSON")

Quick Start

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)

Symbolics.jl Integration

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)

Operator Registry

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, ...

Documentation

For full documentation, see the documentation site.

License

MIT License - see LICENSE for details.