Exact nested-pair stack encoding #
A stack is encoded top first: the empty stack is [], and pushing a frame
pairs its encoding with the encoded tail. Empty frame encodings are permitted;
the pair separator still distinguishes a nonempty stack from an empty one.
The frame encoder need not be injective for the projection and length laws.
The raw stack operations are the existing pair, pairFst, and pairSnd,
including their total behavior on malformed strings. Their polynomial-time
closure rules live in Classes.P.Pairing, outside this machine-independent
module. Return values and algorithm-specific frame semantics are not encoded here.
Encode a stack with its top frame first, using the supplied frame encoding.
Equations
- Complexity.StackEncoding.encode frame [] = []
- Complexity.StackEncoding.encode frame (f :: fs) = Complexity.pair (frame f) (Complexity.StackEncoding.encode frame fs)