Main internal data type for the rose tree machine (RTM) #
This file contains the main internal data structure for the RTM, Data, a rose tree.
Main definitions and notations #
Data- the main data structureData.size- the size of aDataobject when encoded using parentheses, complexity results use this size as the main measure.Data.toBits- a parenthesized (balanced-bracket) serialization intoList Bool, with length equal toData.size, and injective (Data.toBits_injective).Data.recL- the main recursion principle forDataData.inductionL- the main induction principle forData
Equations
- Complexity.instReprData = { reprPrec := Complexity.instReprData.repr }
Decidable equality for Data, defined jointly with Data.listDecEq.
Equations
- (Complexity.Data.l xs).decEq (Complexity.Data.l ys) = match Complexity.Data.listDecEq xs ys with | isTrue h => isTrue ⋯ | isFalse h => isFalse ⋯
Instances For
Decidable equality for List Data, defined jointly with Data.decEq.
Equations
- One or more equations did not get rendered due to their size.
- Complexity.Data.listDecEq [] [] = isTrue Complexity.Data.listDecEq._proof_1✝
- Complexity.Data.listDecEq [] (head :: tail) = isFalse ⋯
- Complexity.Data.listDecEq (head :: tail) [] = isFalse ⋯
Instances For
Equations
The encoding length of d, relevant for complexity.
This is the encoded size assuming an encoding into parenthesized expressions.
Equations
- (Complexity.Data.l a).size = 2 + (List.map Complexity.Data.size a).sum
Instances For
Recursion principle for Data.
Equations
- Complexity.Data.recL nil cons (Complexity.Data.l []) = nil
- Complexity.Data.recL nil cons (Complexity.Data.l (x_1 :: xs)) = cons x_1 xs (Complexity.Data.recL nil cons x_1) (Complexity.Data.recL nil cons (Complexity.Data.l xs))
Instances For
Bitstring serialization #
Data.toBits serializes a Data value into a List Bool using a parenthesized
(balanced-bracket) encoding: false opens a node, its children are serialized in order, and
true closes the node. This matches Data.size exactly (Data.length_toBits) and is injective
(Data.toBits_injective), so any DataEncode instance yields an injective bitstring encoding
(see Complexitylib.Encoding.DataEncode).
Serialize Data into a bitstring with a parenthesized (balanced-bracket) encoding: false
opens a node, the children are serialized in order, and true closes the node.
Equations
Instances For
One step of the stack-based Data.fromBits parser. The state is a stack of frames, each a
list of the sibling nodes completed so far at that nesting depth (outermost frame at the bottom).
Reading false opens a new (empty) frame; reading true closes the top frame into a Data.l
node and appends it to its parent. none is a permanent failure state (an unmatched true).
Equations
Instances For
Decode a bitstring produced by Data.toBits back into a Data value, or none if it is not
a valid single serialization. This is a left inverse of Data.toBits (Data.fromBits_toBits).
Equations
Instances For
Running Data.fromBitsStep over d.toBits appends the decoded d to the top frame of the
stack, leaving the rest of the stack untouched. This is the key lemma behind
Data.fromBits_toBits.
Data.fromBits recovers any value serialized by Data.toBits.
Data.toBits is injective: the parenthesized serialization determines the value. This follows
from Data.fromBits being a left inverse.