PdeParse #
A compact hand-rolled parser from strings to PDE AST (Expr).
Grammar (informal): expr := term (('+' | '-') term)* term := factor ('' factor) factor := primary ('^' int)? primary:= 'u' | 'ux' | 'uy' | 'uxx' | 'uyy' | number | ident | '(' expr ')'
Numbers are parsed as Floats. Idents look up a value from env : String → Option Float.
Unsupported tokens produce an error.
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
- s : String
s.
- i : String.Pos.Raw
i.
Instances For
def
NN.Verification.PINN.PdeParse.parseExprCoreFuel.loop
(env : String → Option Float)
(fuel : ℕ)
(acc : PdeAst.Expr)
(st : State)
:
Instances For
def
NN.Verification.PINN.PdeParse.parseTermFuel.loop
(env : String → Option Float)
(fuel : ℕ)
(acc : PdeAst.Expr)
(st : State)
:
Instances For
def
NN.Verification.PINN.PdeParse.parseFactorFuel.powMul
(base : PdeAst.Expr)
(k : ℕ)
(acc : PdeAst.Expr)
:
Instances For
Entry point: parse a string to Expr using env for identifiers.