Derivations of stack recursions from their recursion trees #
A derivation Cslib.Algorithms.StackRecursion.Scheme.Eval of a recursion scheme records the
value of a node with its number of nodes and its stack depth. This file builds derivations from
a description of the recursion tree, and reads off what a clocked run returns, without reference
to any machine model.
Counted children (Scheme.Loop.counted). A call whose accumulators acc c ask for the
children child c for c < bound, and then stop, runs its loop through the children's
derivations.
The recursion tree (Scheme.exists_eval_of_counted). Let value assign values to the nodes
satisfying I.node, such that a leaf has its leaf value, and a call at depth d < D has at most
b d counted children, all at depth d + 1 and smaller in a measure, with its value the
finish of the accumulated children's values. Then every node at depth d ≤ D has a derivation
of its value, with at most Nat.recursionBound b (D - d) d nodes and at most D - d stack
levels. This is the induction "from the leaves" of a recursive algorithm, with its node count;
without the count, Scheme.exists_eval_of_measure is the induction alone.
What a run returns (Scheme.value_of_run_eq_some). Every value the clocked run returns, for
any fuel, satisfies the invariant of a derivation of the root. If the values carry a tag that
only the root's value has, a returned tagged value is the root's value, even when the fuel is too
small to vouch for the run.
Main results #
Cslib.Algorithms.StackRecursion.Scheme.Loop.counted: the loop over counted children.Cslib.Algorithms.StackRecursion.Scheme.exists_eval_of_measure: derivations by well-founded recursion.Cslib.Algorithms.StackRecursion.Scheme.exists_eval_of_counted: derivations with the node count of the recursion tree.Cslib.Algorithms.StackRecursion.Scheme.exists_eval_of_height: derivations with their height alone.Cslib.Algorithms.StackRecursion.Scheme.value_of_run_eq_some: a returned value satisfies the invariant.
References #
- OpenAI, The Exponential Time Hypothesis is False, Appendix D.4.7 (p. 64).
A call with counted children. If, from the accumulators acc c, the call x asks for the
children child c for c < bound and then stops, and the children evaluate to val c, then its
loop from acc 0 ends at acc bound, with the children's nodes and at most H levels.
Derivations by well-founded recursion. Let value assign values to the nodes satisfying
I.node, all satisfying I.value, such that a leaf has its leaf value, and a call has counted
children: from the accumulators acc c, starting at start, it asks for child c for c < cnt
and then stops, absorbing the children's values; the frames satisfy I.frame, the children
satisfies I.node and are smaller in the measure μ; and its value is the finish of the last
accumulator. Then every node has a derivation of its value. exists_eval_of_counted adds the node
count.
Derivations from the recursion tree. Let value assign values to the nodes satisfying
I.node, all satisfying I.value, such that
- a leaf has its leaf value;
- a call at depth
dhasd < Dand at mostb dchildren, counted: from the accumulatorsacc c, starting atstart, it asks forchild cforc < cntand then stops, absorbing the children's values; the frames satisfyI.frame, and the children satisfyI.node, are smaller in the measureμand lie at depthd + 1; and its value is thefinishof the last accumulator.
Then every node at depth d ≤ D has a derivation of its value with at most
Nat.recursionBound b (D - d) d nodes and at most D - d stack levels.
Derivations with their height. Let value assign values to the nodes satisfying I.node,
all satisfying I.value, such that a leaf has its leaf value, and a call at depth d has
d < D and counted children, as in exists_eval_of_counted, at depth d + 1. Then every node at
depth d ≤ D has a derivation of its value with at most D - d stack levels. This is
exists_eval_of_counted without a bound on the number of children.
What a clocked run returns. For any fuel, a value returned by the run satisfies the invariant of a derivation of the root.