MPP-TeX is a TeX-inspired symbolic math language designed for writing ฯ- and P-based expressions with a focus on fundamental physical constants and mathematical structures.
\let r := \P
\let A := \pi r^2
\derive{A}{r}
\ket{\psi} := \frac{1}{\sqrt{2}}(\ket{0} + \ket{1})
\interval{\tau}{0}{0}{0}
| Token | Meaning |
|---|---|
\pi |
Symbol for pi (geometry constant) |
\P |
Symbol for Planck length |
\tau |
Planck time constant |
\c |
Speed of light constant (defined as P/ฯ) |
\Delta, \ptu |
Planck Time Unit (defined as P/c) |
\hbar |
Reduced Planck constant |
\G |
Gravitational constant |
\k |
Boltzmann constant |
\second |
Second (legacy unit) |
| Operation | Syntax | Description |
|---|---|---|
| Assignment | \let x := expr |
Assign value to variable |
| Addition | a + b |
Add expressions |
| Subtraction | a - b |
Subtract expressions |
| Multiplication | a \cdot b, a * b, a b |
Multiply expressions (implicit) |
| Division | a / b, \frac{a}{b} |
Divide expressions |
| Exponentiation | a^b |
Raise to power |
| Derivative | \derive{expr}{var} |
Derivative of expr with respect to var |
| Integration | \integral{expr}{var} |
Indefinite integral of expr with respect to var |
| Operation | Syntax | Description |
|---|---|---|
| Ket vector | \ket{ฯ} |
Quantum state vector |
| Bra vector | \bra{ฯ} |
Dual vector |
| Inner product | \braket{ฯ}{ฯ} |
Inner product between two states |
| Commutator | \commutator{A}{B} |
Commutator [A,B] = AB - BA |
| Anti-commutator | \anticommutator{A}{B} |
Anti-commutator {A,B} = AB + BA |
| Operation | Syntax | Description |
|---|---|---|
| Lagrangian | \lagrangian{L} |
Lagrangian function |
| Hamiltonian | \hamiltonian{H} |
Hamiltonian function |
| Vector notation | \vec{v} |
Vector notation |
| Spacetime interval | \interval{t}{x}{y}{z} |
4D spacetime interval |
| Operation | Syntax | Description |
|---|---|---|
| Text | \text{comment} |
Text for documentation |
| Assert | \assert{expr} |
Assertion for validation |
| Solve | \solve{expr}{var} |
Solve equation for variable |
The MPP-TeX parser is implemented using the nom parsing library, which provides:
The parser processes input in multiple stages:
The parser provides detailed error messages including:
Example error:
Parse error at line 3, column 7: Expected ')' but found '+'
The grammar is designed around a standard operator hierarchy, from lowest to highest precedence. This ensures that expressions like a + b * c are parsed unambiguously as a + (b * c).
| Precedence | Operator(s) | Associativity | Description |
|---|---|---|---|
| 1 (Lowest) | := |
- | Assignment |
| 2 | +, - |
Left | Addition / Subtraction |
| 3 | *, /, (implicit) |
Left | Multiplication / Division |
| 4 | +, - (unary) |
Right | Unary Plus / Minus |
| 5 (Highest) | ^ |
Right | Exponentiation |
Parentheses () and braces {} are used to override the natural precedence.
This Extended Backus-Naur Form (EBNF) grammar formally defines the syntactic structure of MPP-TeX.
(* --- Top Level --- *)
program ::= statement*
statement ::= assignment | expression
(* --- Core Expressions --- *)
assignment ::= '\let' identifier ':=' expression
expression ::= additive_expr
(* --- Binary Operations (by precedence) --- *)
additive_expr ::= multiplicative_expr ( ( '+' | '-' ) multiplicative_expr )*
multiplicative_expr ::= unary_expr ( ( '*' | '\cdot' | '/' | implicit_mul ) unary_expr )*
unary_expr ::= ( '+' | '-' ) unary_expr
| power_expr
power_expr ::= primary_expr ( '^' power_expr )? (* Right-associative *)
(* --- Primitives and Grouping --- *)
primary_expr ::= literal
| identifier
| command
| function_call
| '(' expression ')'
(* --- Specific Forms --- *)
literal ::= rational | integer
rational ::= integer '/' integer
integer ::= [0-9]+
function_call ::= command ( group )+
group ::= '{' expression '}'
identifier ::= [a-zA-Z][a-zA-Z0-9_]*
(* --- Implicit Multiplication Rule --- *)
(* This is a contextual rule: whitespace or juxtaposition between two `unary_expr` *)
(* that are not separated by another operator implies multiplication. *)
(* e.g., "2\pi", "x y", "(a+b)(c+d)" *)
implicit_mul ::= (* e.g., whitespace between valid multiplicative terms *)
\let r := 5 \cdot \P
\let area := \pi r^2
\derive{area}{r} // Should yield 2\pi r
\let \psi := \frac{1}{\sqrt{2}}(\ket{0} + \ket{1})
\let \phi := \frac{1}{\sqrt{2}}(\ket{0} - \ket{1})
\braket{\psi}{\phi} // Should yield 0
\let dt := \c \cdot \tau
\let dx := 0
\let dy := 0
\let dz := 0
\interval{dt}{dx}{dy}{dz} // Timelike interval
\let L := \frac{1}{2}m\vec{v}^2 - V(x)
\lagrangian{L}
\hamiltonian{p^2/(2m) + V(x)}