Documentation

MeTTaILProofs.Order

Strings as a single natural number #

A string becomes one Nat by encoding the list of its code points through Encodable (List Nat). Every name leaf in the term family then occupies exactly one slot in the List Nat stream, so the decoders never have to split a string out of the middle of a list. The decode is made total by defaulting to the empty string; the round-trip only ever feeds it a valid encoding.

Encode a string as a single natural number.

Equations
Instances For

    Decode a string from a single natural number, defaulting to "" on a malformed code.

    Equations
    Instances For
      @[simp]

      DottedPath #

      Tags: 0 for base, 1 for qualified. DottedPath does not nest through a list of itself, so the decoder is a plain prefix-style parser whose recursion is on the structurally smaller tail.

      Parse one dotted path off the front of a List Nat, returning the remainder.

      Equations
      Instances For
        theorem MeTTaIL.dpDec_enc (p : DottedPath) (rest : List ) :
        dpDec (dpEnc p ++ rest) = some (p, rest)

        Decode a dotted path from a List Nat that encodes exactly one.

        Equations
        Instances For

          Cat #

          Tags: 0 idCat, 1 listOf, 2 arrow, 3 prod. The only non-recursive leaf is the idCat string, encoded as one Nat. Following Mathlib's Term.listDecode, catDecAll decodes the whole stream into a List Cat and recurses only on the tail; each constructor reclaims its sub-categories from the front of the decoded suffix. arrow consumes two, listOf one, and prod consumes a count-prefixed run.

          Serialise a single category by natural structural recursion. A constructor's tag is followed by its sub-categories' encodings; prod adds a count prefix so its run can be reclaimed on decode.

          Equations
          Instances For

            Serialise a list of categories by concatenating their encodings.

            Equations
            Instances For

              Decode a whole List Nat into the list of categories it encodes, recursing on the tail. A constructor reclaims its children from the front of the decoded suffix.

              Equations
              Instances For
                theorem MeTTaIL.catDecAll_enc (c : Cat) (rest : List ) :
                catDecAll (catEnc c ++ rest) = c :: catDecAll rest

                Decoding the whole stream after one category's encoding yields that category in front of whatever the suffix decodes to.

                theorem MeTTaIL.catDecAll_encL (cs : List Cat) (rest : List ) :
                catDecAll (catEncL cs ++ rest) = cs ++ catDecAll rest

                Decoding the whole stream after a list of categories' encodings yields that list in front of whatever the suffix decodes to.

                Decode a category from a List Nat that encodes exactly one.

                Equations
                Instances For

                  Label #

                  Tags: 0 id, 1 wild, 2 listE, 3 listCons, 4 listOne. The three list labels carry a Cat, which is already Encodable, so it goes in as a single Nat. Label does not nest through a list of itself, so the decode is a plain non-recursive parser.

                  Parse one label off the front of a List Nat, returning the remainder. The Cat payload is decoded from its single Nat; a malformed code defaults to idCat "".

                  Equations
                  Instances For
                    theorem MeTTaIL.lblDec_enc (l : Label) (rest : List ) :
                    lblDec (lblEnc l ++ rest) = some (l, rest)

                    Decode a label from a List Nat that encodes exactly one.

                    Equations
                    Instances For

                      AST #

                      Tags: 0 var, 1 sexp, 2 subst. The non-recursive payloads (DottedPath for var and subst, Label for sexp) are already Encodable, so each goes in as a single Nat. The recursive sub-terms flow through the stream: sexp carries a count-prefixed run of arguments and subst carries two sub-terms. As with Cat, astDecAll decodes the whole stream into a List AST, recursing on the tail, and each constructor reclaims its children from the front of the decoded suffix.

                      Serialise a single term by natural structural recursion. The single-Nat payloads (label, dotted paths) sit next to the tag; sexp adds a count prefix for its argument run.

                      Equations
                      Instances For

                        Serialise a list of terms by concatenating their encodings.

                        Equations
                        Instances For

                          Decode a whole List Nat into the list of terms it encodes, recursing on the tail.

                          Equations
                          Instances For
                            theorem MeTTaIL.astDecAll_enc (a : AST) (rest : List ) :
                            astDecAll (astEnc a ++ rest) = a :: astDecAll rest

                            Decoding the whole stream after one term's encoding yields that term in front of whatever the suffix decodes to.

                            theorem MeTTaIL.astDecAll_encL (as : List AST) (rest : List ) :
                            astDecAll (astEncL as ++ rest) = as ++ astDecAll rest

                            Decoding the whole stream after a list of terms' encodings yields that list in front of whatever the suffix decodes to.

                            Decode a term from a List Nat that encodes exactly one.

                            Equations
                            Instances For