# mathlex Plain Text Syntax Reference
This document is the authoritative specification for mathlex's plain text input format. Every supported construct is shown with its plain text syntax, the literal LaTeX equivalent, and a description of the rendered form.
Conventions adopted here follow a cross-CAS survey of Mathematica, SymPy, Maple, MATLAB, Maxima, SageMath, GeoGebra, and AsciiMath. The guiding principles are:
- **Lowercase function names** (matching Maple, MATLAB, Maxima, SageMath)
- **Positional arguments** with consistent `(expr, var, ...)` ordering
- **Explicit functional notation** over ambiguous shorthand
---
## 1. Literals
| `42` | `42` | 42 | `Integer(42)` |
| `-17` | `-17` | -17 | `Unary(Neg, Integer(17))` |
| `3.14` | `3.14` | 3.14 | `Float(3.14)` |
| `2.5e-3` | `2.5e-3` | 0.0025 | `Float(0.0025)` |
## 2. Variables and Constants
| `x` | `x` | *x* | `Variable("x")` |
| `theta` | `theta` | theta | `Variable("theta")` |
| `x_1` | `x_1` | x₁ | `Variable("x_1")` |
| `pi` | `\pi` | π | `Constant(Pi)` |
| `e` | `e` | *e* | `Constant(E)` |
| `i` | `i` | *i* | `Constant(I)` |
| `inf` | `\infty` | ∞ | `Constant(Infinity)` |
| `-inf` | `-\infty` | -∞ | `Constant(NegInfinity)` |
| `nan` | `\text{NaN}` | NaN | `Constant(NaN)` |
## 3. Arithmetic Operators
| `a + b` | `a + b` | *a* + *b* | Addition |
| `a - b` | `a - b` | *a* - *b* | Subtraction |
| `a * b` | `a \cdot b` | *a* · *b* | Multiplication |
| `a / b` | `\frac{a}{b}` | *a*/*b* | Division |
| `a ^ b` | `a^{b}` | *a*ᵇ | Exponentiation (right-associative) |
| `a ** b` | `a^{b}` | *a*ᵇ | Exponentiation (alternative) |
| `a % b` | `a \bmod b` | *a* mod *b* | Modulo |
| `-x` | `-x` | -*x* | Unary negation |
| `+x` | `+x` | +*x* | Unary positive |
| `n!` | `n!` | *n*! | Factorial |
### Operator Precedence (lowest to highest)
1. Logical: `iff`, `implies`, `or`, `and`, `not`
2. Quantifiers: `forall`, `exists`
3. Set operations: `union`, `intersect`, `in`, `notin`
4. Relations: `=`, `<`, `>`, `<=`, `>=`, `!=`
5. Addition/Subtraction: `+`, `-`
6. Multiplication/Division/Modulo: `*`, `/`, `%`
7. Unary prefix: `-x`, `+x`
8. Power: `^`, `**` (right-associative)
9. Postfix: `!`
10. Function calls and atoms
## 4. Relations
| `x = y` | `x = y` | *x* = *y* |
| `x < y` | `x < y` | *x* < *y* |
| `x > y` | `x > y` | *x* > *y* |
| `x <= y` | `x \leq y` | *x* ≤ *y* |
| `x >= y` | `x \geq y` | *x* ≥ *y* |
| `x != y` | `x \neq y` | *x* ≠ *y* |
Unicode alternatives: `x ≤ y`, `x ≥ y`, `x ≠ y`
## 5. Reserved Function Names
### 5.1 Trigonometric
| `sin(x)` | `\sin\left(x\right)` | sin(*x*) |
| `cos(x)` | `\cos\left(x\right)` | cos(*x*) |
| `tan(x)` | `\tan\left(x\right)` | tan(*x*) |
| `cot(x)` | `\cot\left(x\right)` | cot(*x*) |
| `sec(x)` | `\sec\left(x\right)` | sec(*x*) |
| `csc(x)` | `\csc\left(x\right)` | csc(*x*) |
### 5.2 Inverse Trigonometric
| `arcsin(x)` | `asin(x)` | `\arcsin\left(x\right)` |
| `arccos(x)` | `acos(x)` | `\arccos\left(x\right)` |
| `arctan(x)` | `atan(x)` | `\arctan\left(x\right)` |
### 5.3 Hyperbolic
| `sinh(x)` | `\sinh\left(x\right)` |
| `cosh(x)` | `\cosh\left(x\right)` |
| `tanh(x)` | `\tanh\left(x\right)` |
### 5.4 Exponential and Logarithmic
| `exp(x)` | `\exp\left(x\right)` | Exponential |
| `ln(x)` | `\ln\left(x\right)` | Natural logarithm |
| `log(x)` | `\log\left(x\right)` | Natural logarithm (CAS convention) |
| `log(b, x)` | `\log_{b}\left(x\right)` | Logarithm base *b* |
| `lg(x)` | `\log_2\left(x\right)` | Binary logarithm (alias: `log2`) |
### 5.5 Other Standard Functions
| `sqrt(x)` | `\sqrt{x}` | Square root |
| `abs(x)` | `\lvert x \rvert` | Absolute value |
| `sgn(x)` | `\operatorname{sgn}\left(x\right)` | Sign function (alias: `sign`) |
| `floor(x)` | `\lfloor x \rfloor` | Floor |
| `ceil(x)` | `\lceil x \rceil` | Ceiling |
| `max(a, b)` | `\max\left(a, b\right)` | Maximum |
| `min(a, b)` | `\min\left(a, b\right)` | Minimum |
| `atan2(y, x)` | `\operatorname{atan2}\left(y, x\right)` | Two-argument arctangent |
| `cbrt(x)` | `\sqrt[3]{x}` | Cube root |
| `round(x)` | `\operatorname{round}\left(x\right)` | Rounding |
| `pow(x, n)` | `x^{n}` | Power (functional form) |
| `trunc(x)` | `\operatorname{trunc}\left(x\right)` | Truncation |
| `clamp(x, a, b)` | `\operatorname{clamp}\left(x, a, b\right)` | Clamp to range |
| `det(A)` | `\det\left(A\right)` | Determinant |
| `tr(A)` | `\operatorname{tr}\left(A\right)` | Trace |
| `rank(A)` | `\operatorname{rank}\left(A\right)` | Matrix rank |
### 5.6 Special Functions (planned)
| `gamma(z)` | `\Gamma\left(z\right)` | Gamma function |
| `beta(a, b)` | `B\left(a, b\right)` | Beta function |
| `erf(x)` | `\operatorname{erf}\left(x\right)` | Error function |
| `zeta(s)` | `\zeta\left(s\right)` | Riemann zeta |
| `bessel_j(n, x)` | `J_n\left(x\right)` | Bessel function first kind |
## 6. Calculus
### 6.1 Derivatives
| `diff(y, x)` | `\frac{d}{dx}y` | dy/dx | First derivative (CAS standard) |
| `diff(y, x, 2)` | `\frac{d^2}{dx^2}y` | d²y/dx² | Second derivative |
| `diff(y, x, n)` | `\frac{d^n}{dx^n}y` | dⁿy/dxⁿ | nth derivative |
| `dy/dx` | `\frac{dy}{dx}` | dy/dx | Leibniz shorthand |
| `d2y/dx2` | `\frac{d^2y}{dx^2}` | d²y/dx² | Higher-order Leibniz |
| `y'` | — | y′ | Prime notation (var implicit) |
| `y''` | — | y″ | Second derivative |
| `y'''` | — | y′′′ | Third derivative |
The **recommended form** is `diff(expr, var[, order])` — it is unambiguous and matches SymPy, Maple, MATLAB, Maxima, and SageMath.
### 6.2 Partial Derivatives
| `partial(f, x)` | `\frac{\partial f}{\partial x}` | ∂f/∂x |
| `partial(f, x, 2)` | `\frac{\partial^2 f}{\partial x^2}` | ∂²f/∂x² |
| `partial(f, x, y)` | `\frac{\partial^2 f}{\partial x \partial y}` | ∂²f/∂x∂y |
Note: `diff(expr, var)` also works for partial derivatives when the expression contains multiple free variables — the interpretation is context-dependent, matching CAS conventions.
### 6.3 Integrals (planned)
Based on CAS consensus, the following forms will be supported:
| `integrate(f, x)` | `\int f \, dx` | ∫f dx | Indefinite integral |
| `integrate(f, x, a, b)` | `\int_a^b f \, dx` | ∫ₐᵇ f dx | Definite integral |
Aliases: `integral`, `int`
### 6.4 Summation (planned)
| `sum(f, i, 1, n)` | `\sum_{i=1}^{n} f` | Σⁱ=₁ⁿ f |
Aliases: `summation`, `Sum`
### 6.5 Products (planned)
| `product(f, k, 1, n)` | `\prod_{k=1}^{n} f` | Πₖ=₁ⁿ f |
Aliases: `prod`, `Product`
### 6.6 Limits (planned)
| `limit(f, x, a)` | `\lim_{x \to a} f` | limₓ→ₐ f |
| `limit(f, x, a, "+")` | `\lim_{x \to a^+} f` | Right-hand limit |
| `limit(f, x, a, "-")` | `\lim_{x \to a^-} f` | Left-hand limit |
Aliases: `lim`, `Limit`
## 7. Vector Calculus
| `grad(f)` | `\nabla f` | ∇f |
| `nabla(f)` | `\nabla f` | ∇f |
| `div(F)` | `\nabla \cdot F` | ∇·F |
| `curl(F)` | `\nabla \times F` | ∇×F |
| `laplacian(f)` | `\nabla^2 f` | ∇²f |
| `dot(a, b)` | `a \cdot b` | a·b |
| `cross(a, b)` | `a \times b` | a×b |
Unicode alternative: `∇f` is equivalent to `grad(f)`. All vector calculus operators work with or without parentheses: `grad f` = `grad(f)`.
## 8. Logic
| `x and y` | `x ∧ y` | `x \land y` | x ∧ y |
| `x or y` | `x ∨ y` | `x \lor y` | x ∨ y |
| `not x` | `¬x` | `\lnot x` | ¬x |
| `x implies y` | `x → y` | `x \implies y` | x ⇒ y |
| `x iff y` | `x ↔ y` | `x \iff y` | x ⇔ y |
## 9. Quantifiers
| `forall x, P(x)` | `\forall x, P(x)` | ∀x, P(x) |
| `forall x in S, P(x)` | `\forall x \in S, P(x)` | ∀x ∈ S, P(x) |
| `exists x, P(x)` | `\exists x, P(x)` | ∃x, P(x) |
| `exists x in S, P(x)` | `\exists x \in S, P(x)` | ∃x ∈ S, P(x) |
## 10. Set Operations
| `x union y` | `x ∪ y` | `x \cup y` | x ∪ y |
| `x intersect y` | `x ∩ y` | `x \cap y` | x ∩ y |
| `x in S` | `x ∈ S` | `x \in S` | x ∈ S |
| `x notin S` | `x ∉ S` | `x \notin S` | x ∉ S |
## 11. Transforms (planned)
| `laplace(f, t, s)` | `\mathcal{L}\{f\}` | Laplace transform |
| `fourier(f, t, omega)` | `\mathcal{F}\{f\}` | Fourier transform |
| `ilaplace(F, s, t)` | `\mathcal{L}^{-1}\{F\}` | Inverse Laplace |
| `ifourier(F, omega, t)` | `\mathcal{F}^{-1}\{F\}` | Inverse Fourier |
---
## Appendix: Alias Table
| `arcsin` | `asin` |
| `arccos` | `acos` |
| `arctan` | `atan` |
| `sgn` | `sign` |
| `lg` | `log2` |
| `grad` | `nabla` |
| `integrate` | `integral`, `int` |
| `sum` | `summation`, `Sum` |
| `product` | `prod`, `Product` |
| `limit` | `lim`, `Limit` |
| `laplace` | `laplace_transform` |
| `fourier` | `fourier_transform` |