Documentation

CodeLayer.SerializationParse

A computable, self-delimiting parser for E #

This is the parser for AdditiveComplexity.E, the prefix (Polish-form) AST serialization of CodeLayer/AdditiveComplexity.lean. E is a prefix code by construction (E_append_inj); this module exhibits the computable decoder that recovers a serialized program and its trailing bits from any description, discharging EParserSpec.

What this establishes #

What this does NOT establish (flagged) #

The parser specification. A computable parser recovering a serialized machine e and its trailing argument r from any description E e ++ r — and ONLY from a description of that shape.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    The parser: a nested fold over an explicit stack of open frames #

    @[reducible, inline]

    The 3-bit opcode of an E-node, in the same order E itself matches on.

    Equations
    Instances For
      @[reducible, inline]

      An open frame on the parse stack: a node's opcode together with the children parsed for it so far, in the order they were parsed.

      Equations
      Instances For

        The number of children a tag's node takes: 0 for the four leaves, 2 for pair/comp/ prec, 1 for rfind' — read off E's own case split.

        Equations
        Instances For

          Builds the Code a completed tag denotes from its (already-parsed) children, taken in the order collected. Only ever applied where cs.length = opArity t (opArity_buildOp_eq_E records what this produces there); off that domain cs.headI/cs.tail.headI pad with a junk default and the result carries no meaning.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            One step of absorbing a newly-completed child c into the innermost open frame: if it completes that frame, the built code becomes the next child to absorb into the frame below (cascading); otherwise absorption stops there, and every frame from that point on (the state's first component turns false) passes through unchanged.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Absorbs a newly-completed code c0 into a parse stack, cascading as far as it goes: true with the completed top-level code if the whole stack collapses, false with the resulting (shorter or equal-length) stack otherwise.

              Equations
              Instances For
                @[reducible, inline]

                The parser's running state: the partial (0/1/2-bit) tag being read, the stack of open frames (innermost first), and, once a top-level code has been read off, its slot together with every bit seen since.

                Equations
                Instances For

                  One bit's transition: if the slot is already filled, the bit is just appended to the trailing remainder; otherwise it extends the partial tag, and a completed 3-bit tag either opens a new frame (arity > 0) or is immediately absorbed (arity 0, a leaf).

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Folds bitStep over a bit-list from the fresh state.

                    Equations
                    Instances For

                      The parser. Total; primrec_parseE below is its computability, parseE_E_append and parseE_eq_some its correctness.

                      Equations
                      Instances For

                        Bit-level identities #

                        absorbFold: reconstruction #

                        The main forward invariant, and parseE_eq_some #

                        theorem AdditiveComplexity.parseE_eq_some (w : List Bool) (e : Nat.Partrec.Code) (r : List Bool) (h : parseE w = some (e, r)) :
                        w = E e ++ r

                        Domain characterization: a successful parse consumed exactly a serialization. The third clause of EParserSpec.

                        parseE recovers a serialization: parseE_E_append #

                        parseE recovers exactly what E serialized, together with any trailing bits. The second clause of EParserSpec.

                        parseE is Primrec #

                        The packaged witness #

                        The parser specification, discharged. parseE is Primrec, recovers (e, r) from E e ++ r, and only from a description of that shape.

                        Axiom guards #