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.
The output has length 2|x| + 2 + |y| (pair_length) and the encoding is
injective (pair_inj). Machine-level cost is recorded elsewhere: pair of
two FP functions is in FP (mem_FP_pair), and x ↦ pair (f x) x has
an explicit bound (TM.pairWithInputTM_computesInTime); no linear-time
bound for pair itself is stated.
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.