Pairing binary strings #
This file defines the low-level self-delimiting pairing codec used by machine inputs throughout Complexitylib. It deliberately has no dependency on the machine or complexity-class layers, so parsers and encoders can reuse it without introducing an import cycle.
Encode a pair of binary strings as a single binary string.
Each bit of x is doubled (false ↦ [false, false], true ↦ [true, true]),
followed by the separator [false, true], followed by y verbatim.
This encoding is injective and computable in linear time.
Equations
- Complexity.pair x y = Complexity.delimit x ++ y
Instances For
The projections #
Total decoders for the two components. pairFst is defined by scanning rather
than through unpair? so that a single-pass machine can compute it; only the
behaviour of either projection on canonical pairs is ever used.
The first component of a canonical pair: read doubled bits until the
[false, true] separator. On pair x y this returns x (see pairFst_pair);
on malformed input it returns the bits decoded so far.