TorchLean API

NN.Verification.PINN.PdeParse

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 : StringOption 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:

@[reducible, inline]

Parser state for the hand-written PDE expression parser.

Instances For
    @[inline]

    Whether the PDE parser cursor has reached the end of its source text.

    Instances For
      @[inline]

      Inspect the current PDE source character without advancing.

      Instances For
        @[inline]

        Advance the PDE parser cursor by one character.

        Instances For
          @[inline]

          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

                  Consume characters satisfying p, accumulating into acc, with explicit fuel.

                  Instances For

                    Consume characters satisfying p, accumulating into acc.

                    Instances For

                      Parse a signed decimal number without exponent, e.g. -12.34.

                      Instances For

                        Parse a natural number at the current parser state.

                        Instances For

                          Parse an identifier used for environment lookup.

                          Instances For

                            Parse the built-in PDE primitive names before falling back to external constants.

                            Instances For

                              Parse an additive/subtractive expression with an explicit recursion budget.

                              Instances For

                                Parse a multiplicative term with an explicit recursion budget.

                                Instances For

                                  Parse a primary expression plus an optional natural-number power, with $x^0=1$.

                                  Instances For

                                    Parse leading negations. Exponentiation binds more tightly than unary minus.

                                    Instances For

                                      Parse atoms: parenthesized expressions, u/derivative names, numerals, or environment identifiers.

                                      Instances For

                                        Parse a full expression from the current parser state.

                                        Instances For

                                          Entry point: parse a string to Expr using env for identifiers.

                                          Instances For