PdeParse #
A compact hand-rolled parser from strings to PDE AST (Expr).
Grammar (informal): expr := term (('+' | '-') term)* term := unary ('' unary) unary := '-' unary | factor factor := primary ('^' nat)? primary:= derivative | number | ident | '(' expr ')'
Derivative names accept both compact and subscript-style spellings:
u, ux, uy, ut, uxx, uyy, utt, u_x, u_y, u_t, u_xx, u_yy, and u_tt.
For 1D-in-time PINN examples, the parser treats t as the second axis, so u_t is the same
primitive as u_y.
Numbers are parsed as Floats. Idents look up a value from env : String → Option Float.
Unsupported tokens produce an error.
Natural powers use the usual identities ($x^0=1$), and powers bind more tightly than unary
minus, so -u^2 means -(u^2).
Implementation note:
The parser is total by threading a simple fuel : Nat through the recursive descent; fuel is
initialized from the remaining bytes in the input and decreases on every recursive descent step.
References:
- PINNs (motivation for residual expressions):
https://arxiv.org/abs/1711.10561
Parser state for the hand-written PDE expression parser.
Instances For
Whether the PDE parser cursor has reached the end of its source text.
Instances For
Inspect the current PDE source character without advancing.
Instances For
Advance the PDE parser cursor by one character.
Instances For
Recursion budget with additional headroom for the mutually recursive PDE grammar.
Instances For
Whitespace predicate used by the PDE expression parser.
Instances For
Skip whitespace with an explicit recursion budget.
Instances For
Skip whitespace from the current parser state.
Instances For
Parse the built-in PDE primitive names before falling back to external constants.
Instances For
Instances For
Instances For
Instances For
Entry point: parse a string to Expr using env for identifiers.