Welcome to the Grim documentation
Grim is a symbolic language for representing mathematical formulas.
Source code: https://github.com/fredrik-johansson/fungrim
Grim is human-readable, computer-readable, and can be converted to LaTeX for rendering. It can be used both as a mathematical markup language and as a simple functional programming language for expressing mathematical objects. Grim is being developed as a means to represent mathematics in semantic form in Fungrim: the Mathematical Functions Grimoire. A second goal is to have a symbolic interface to Arb.
This project has the following components:
- A simple core language for symbolic expressions (similar to Lisp S-expressions and Wolfram language M-expressions).
- A vocabulary of hundreds of builtin symbols for mathematical objects and operations.
- A reference implementation in Python (Pygrim), which currently handles LaTeX conversion and symbolic or numerical evaluation of a subset of the functions.
- The 2600+ formulas added Fungrim so far which both serve as documentation and as a test suite.
Warning: Grim is currently alpha-level, and anything in this documentation may change. There are many known inconsistencies. Feedback is welcome on anything from mathematical foundations to syntax and naming.
Quick formula examples
Grim | Generated LaTeX | Rendered formula |
---|---|---|
Implies(Element(n, ZZ), Equal(Sin(Mul(Pi, n)), 0)) | \left(n \in \mathbb{Z}\right) \implies \left(\sin\!\left(\pi n\right) = 0\right) | $$\left(n \in \mathbb{Z}\right) \implies \left(\sin\!\left(\pi n\right) = 0\right)$$ |
Equal(Exp(z), Sum(Div(Pow(z, n), Factorial(n)), For(n, 0, Infinity))) | {e}^{z} = \sum_{n=0}^{\infty} \frac{{z}^{n}}{n !} | $${e}^{z} = \sum_{n=0}^{\infty} \frac{{z}^{n}}{n !}$$ |
Equal(Det(Matrix(BellNumber(Add(i, j)), For(i, 0, n), For(j, 0, n))), Product(Factorial(k), For(k, 1, n)), BarnesG(Add(n, 2))) | \operatorname{det}\displaystyle{\begin{pmatrix} B_{0 + 0} & B_{0 + 1} & \cdots & B_{0 + n} \\ B_{1 + 0} & B_{1 + 1} & \cdots & B_{1 + n} \\ \vdots & \vdots & \ddots & \vdots \\ B_{n + 0} & B_{n + 1} & \ldots & B_{n + n} \end{pmatrix}} = \prod_{k=1}^{n} k ! = G\!\left(n + 2\right) | $$\operatorname{det}\displaystyle{\begin{pmatrix} B_{0 + 0} & B_{0 + 1} & \cdots & B_{0 + n} \\ B_{1 + 0} & B_{1 + 1} & \cdots & B_{1 + n} \\ \vdots & \vdots & \ddots & \vdots \\ B_{n + 0} & B_{n + 1} & \ldots & B_{n + n} \end{pmatrix}} = \prod_{k=1}^{n} k ! = G\!\left(n + 2\right)$$ |
In the table above, the Grim expressions are written in a rather verbose way using explicit function calls for arithmetic operators. Pygrim also supports infix Python syntax: x**2 + 3*y for Add(Pow(x, 2), Mul(3, y)).
Symbolic evaluation examples
By default, Grim expressions are inert (remain unevaluated). Calling the .eval() method in Pygrim evaluates an expression symbolically; that is, Pygrim produces an equivalent symbolic expression consisting of more explicit (and hopefully simpler) objects. For example, an implicit description of a finite set might be replaced by an explicit listing of the elements. This example demonstrates computing the set of roots of a polynomial which satisfy a given condition.
Pygrim can find symbolic closed form evaluations of various transcendental functions.
Numerical evaluation examples
Calling the .n() method on an expression in Pygrim produces an enclosure of the numerical value. This shows an example output.