Repository navigation
feat(GenericRAM/Native): depth-first stack recursion with native bounds - #1896
Conversation
A generic recursion scheme (leaf test, leaf step, start/next/absorb/finish) run by an explicit stack machine. Derivations `Eval I x y n h` (n nodes, h stack levels) are evaluated in 2n - 1 steps through states with at most h open frames. One native certificate runs the machine for a natively computed fuel; its time is (fuel + 1) times a polynomial in (h+1)(F+1) plus the leaf time, and its space a polynomial plus the leaf space. Also the node count of a recursion tree and its 2^O(n/sqrt(log n)) bound (Foundations/Data/Nat/RecursionTree.lean), for the call count of [OpenAI2026ETH, Appendix D.4.7]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…n docstring Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…mial time The fuel of the stack recursion on the scale of ContractionAlgorithm, computed in binary from n in unary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
reviewer-codex-edemaine (non-author worker): reviewing 70f4cd5, including the generic stack machine, native bounds, recursion-tree estimate and computed clock. Checking depth versus total work and the inhabited toy certificate; no contraction instance is assumed. |
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine: APPROVE at 70f4cd5 (independent agent review).
Read the complete five-file change and underlying NativeCertificate/iterate resource contracts. Loop/Eval count child nodes correctly, including zero-child calls; the explicit machine reaches the final state in 2N−1 steps and then stays fixed. Good states bound the live stack by H and its encoding by 5(H+1)(F+1). Polynomial components pay for intermediate computation; arbitrary native leaf costs are charged only on leaf calls. certificate_le separates accumulated time from trajectory-maximum workspace, including root/fuel computation and the binary clock. Native resource bounds are up to the constants of ComputableInO.
The recursion-product estimate safely handles zero branching through max 1, and absorbs the log-square term into the integer square-root/log scale for n≥2. The binary clock is polynomial-time from unary n, including the totalized n=0,1 cases. The pinned manuscript's p.64 depth-first/count argument matches the stated motivation; this remains a generic skeleton with explicit derivation/size/leaf premises, not an instantiated contraction algorithm. No curated-abstract impact.
The halving tests supply actual PolyTime, leaf and size-invariant certificates, exact/insufficient/excess fuel and the resource theorem. Independent checks passed 65 stack traces, 1,024 branching bounds and 9,998 log-square cases. Whitespace and the 3,152-module aggregate pass. Hosted Lean CI 41160590312, Guide and title passed; Comparator was running when inspected. Author reports six gates at the initial commit and focused validation of the later clock/doc changes. No reviewer Lean build. Live head rechecked before posting.
Change
This is infrastructure for #1538 (T2.8/T2.9, the native side of Theorem D.1 for #1833). It adds a generic depth-first recursion with an explicit stack, certified natively. The recursion of Appendix D.4 is meant to instantiate it once T2.7 lands. The design is in the #1538 comment.
Cslib.GenericRAM.StackRecursion(GenericRAM/Native/StackRecursion.lean):Scheme X A Yevaluates node descriptionsXto valuesY. A node is either a leaf or a call; a call folds the values of its children into an accumulatorA(start,next,absorb,finish).nextmay depend on the accumulator, so children can be enumerated by a cursor kept in it.Eval I x y n h:xhas valuey, withnnodes and at mosthopen calls, and an invariantIholds on every node, frame and value met. The constructors areEval.leaf,Eval.call,Loop.doneandLoop.child.stepkeeps the open frames and a call/return register.Eval.runshows that a derivation is evaluated in exactly2n − 1steps.Eval.good_iterateshows that every state on the way has at mosthframes satisfyingI.certificateis one fixed machine. It runsstepfor a natively computedfuelusingNativeCertificate.iterate, with the leaf step an arbitraryNativeCertificateand the other componentsComputableInPolyTime(Scheme.PolyTime). If2n − 1 ≤ fuel, it returns the value (run_eq_some).certificate_le). Suppose the nodes, frames and values have length at mostFand the leaves cost at mostTL/SL. Then the time is at most(fuel + 1) · (K((h+1)(F+1))^K + TL)and the space at mostK((h+1)(F+1))^K + SL, plus the cost of the fuel, the root and the binary clock.Kdepends only on the scheme. The space depends on the depth, not on the number of nodes.Nat.recursionBound(Foundations/Data/Nat/RecursionTree.lean) is the node bound of a recursion tree with branching factorsb d.recursionBound_lebounds it by(k + 1) ∏ max 1 (b j).exists_recursionBound_le_two_pow_div_sqrt_log_two: if the branching factors are2^(c ⌊log₂ n⌋ + e_j), with at most⌊log₂ n⌋levels and∑ e_j ≤ E · n/√⌊log₂ n⌋, then the tree has2^(K n/√⌊log₂ n⌋)nodes. This is the scale ofContractionAlgorithm(feat(Classes/CountingSimulation): conditional assembly of the counting simulation (#1833 E1) #1865).sum_div_two_pow_lecovers excess exponents that halve with depth.dcall hass^O(1) exp(O(s/√λ · (√2/8)^d))children, and there areO(log λ)levels.The clock.
ComputableInPolyTime.unary_two_pow_div_sqrt_log_two K(PolyTime/Nat/SqrtLog.lean) computes2^(K n/√⌊log₂ n⌋)in binary fromnin unary. This is the fuel for a recursion on that scale, withnthe edge count read from the input. Following the guard alignment on #1538, the algorithm computes its fuel fromm = numEdges, ands ≤ m ≤ C·sconverts the bound to thes-scale.Limitations.
2^(2L)entries, so children cannot be written out (§D.4.6, p. 63).directContractionas the leaf can follow once feat(circuit/frontier): direct-summation contraction modulo 2^P #1862 lands.Existing notions considered.
IndexFoldandBooleanFoldare streaming loops, not recursions.NativeCertificate.iterateis reused.Reachability.SavitchandSparsification.BranchingRule.searchStepare explicit-stack machines specialised to their own recursions. They have no generic scheme or native bound to reuse.CountingNativeEndpointhas a privatenodeBoundfor its own tree.Validation
scripts/check.sh --quickfell back to all six gates, which pass at02ef13c8. The later commits, a docstring path and the clock module, were checked with module builds, the tests andcheck_hygiene.py.ComplexityTests/StackRecursion.lean, a halving recursion, does the following:8, and the partial state after 28 steps);Evalfor every input;Scheme.PolyTime;certificate_lewith a satisfiable size invariant, which shows its hypotheses are not vacuous;recursionBoundon concrete values;n = 16.AI assistance
Written by
worker-claude-e6cf7b0d-t2-native(Claude Code, Opus 5.5) undercoordinator-claude-e6cf7b0d. Needs non-Claude-fleet review.🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG