Reading a table of unary numbers #
An algorithm that materializes a graph writes a list of records and reads them
back. PosScan reads an entry of an encoded list, and DataEncode writes the
entries; what is missing is getting a number back out, in the unary form the
loops of the toolkit consume.
Storing the number in unary makes that a length computation: the encoding of a
unary string of w marks is 4 * w + 2 bits long — two brackets, and four bits
a mark — so dividing the length by four recovers the marks. No parsing of the
encoding is needed, and no binary arithmetic.
The same scan reads the two halves of an encoded pair, since a pair is encoded as the two-element list of its halves.
Main definitions #
Complexity.unaryOf— the marks an encoded unary string stands forComplexity.fstEnc,Complexity.sndEnc— the halves of an encoded pair
Main results #
Complexity.unaryOf_encode,Complexity.unaryOf_mem_FPComplexity.fstEnc_eq,Complexity.sndEnc_eq, and theirFPversionsComplexity.tableFst_eq,Complexity.tableSnd_eq— an entry of a table of pairs of unary numbers, read back in unaryComplexity.recFst_eq,Complexity.recSnd_eq,Complexity.recThd_eq— the same for records of three numbersComplexity.encPair_eq— and written out
Numbers #
The size of an encoded unary string: two brackets and four bits a mark.
The unary number an encoded unary string stands for.
Equations
Instances For
Pairs #
The first half of an encoded pair.
Equations
Instances For
The second half of an encoded pair.
Equations
Instances For
Unary arithmetic with constants #
Any string, as that many marks.
Equations
Instances For
Division by a constant.
Equations
- Complexity.divC c s = Complexity.divFn (List.replicate c false) s
Instances For
Remainder by a constant.
Equations
- Complexity.modC c s = Complexity.modFn (List.replicate c false) s
Instances For
The product of two lengths.
Equations
- Complexity.mulLen a b = List.replicate (a.length * b.length) false
Instances For
Multiplication by a constant, as a length.
Equations
- Complexity.mulC c s = List.replicate (s.length * c) false
Instances For
Writing records #
The encoding of a unary string.
Equations
Instances For
The encoding of a pair of unary strings.
Equations
Instances For
The encoding of a list is two brackets and its entries' encodings.
Tables of pairs of numbers #
The first number of the j-th record of a table, in unary.
Equations
Instances For
The second number of the j-th record of a table, in unary.
Equations
Instances For
Records of three numbers #
The encoding of three unary strings.
Equations
- Complexity.encTriple a b c = false :: (Complexity.encUnary a ++ Complexity.encPair b c) ++ [true]
Instances For
The first number of the j-th record of a table of triples.
Equations
Instances For
The second.
Equations
Instances For
The third.
Equations
Instances For
Digit sums #
A number from its digits: ∑ j < n, digit j · radix ^ j, written in marks.
The digits are read from the input, so this is how an algorithm assembles a
mixed-radix number out of constantly many pieces.
Equations
- Complexity.digitSum radix digit 0 x✝ = []
- Complexity.digitSum radix digit n.succ x✝ = Complexity.digitSum radix digit n x✝ ++ Complexity.mulC (radix ^ n) (digit n x✝)