Writing out a table #
Every stage of an algorithmic reduction writes a list: the edges of a graph, the
entries of a rotation table, the records of a gadget. ListEncode runs the loop
that does it, but asks for a bound on the loop's own state; this module
discharges that bound from the rule alone, since a polynomial-time rule has
polynomially bounded output and the loop runs no more often than its argument is
long.
Main results #
Complexity.materialize_mem_FP— a record rule makes the list encoder polynomial timeComplexity.materialize_eq— and it writes the list it is meant toComplexity.countOver,Complexity.length_countOver— the same loop used to add up a rule's outputs, which is how a bounded count is takenComplexity.findFirst,Complexity.length_findFirst— and, run twice, how a bounded search is madeComplexity.ifEqLen,Complexity.ifLtLen— comparing two unary numbers, and branching on the answerComplexity.length_findFirst_eq— the search returns the least index the rule answers at
A record rule materializes a list in polynomial time. No bound need be supplied: a polynomial-time rule already has polynomially bounded output, and the loop runs only as many times as its own argument is long.
The list encoder writes the list.
Adding up #
The total length of a rule's outputs over a range, in unary. Running the
rule for its length alone is how a loop counts: a rule that answers [true] or
[] counts the indices where it says yes.
Equations
Instances For
Comparing #
x when the two strings have the same length, y otherwise.
Equations
- Complexity.ifEqLen a b x y = Complexity.Cobham.selectHead (Complexity.Cobham.emptyFlag (List.drop a.length b ++ List.drop b.length a)) x y
Instances For
x when the first string is shorter than the second, y otherwise.
Equations
- Complexity.ifLtLen a b x y = Complexity.Cobham.selectHead (Complexity.Cobham.emptyFlag (List.drop a.length b)) y x
Instances For
Searching #
One mark when the string is empty, none otherwise.
Equations
Instances For
The least index below the bound at which the rule answers something, or the bound itself when it never does: count the indices no answer has been seen up to.
Equations
- One or more equations did not get rendered due to their size.