Binary-counted folds in polynomial space #
Nat.fold visits the indices below a binary count in increasing order. The step receives the
original input, current index and accumulator. Its native computation may use arbitrary time in
polynomial space. A polynomial bound on all encoded accumulator prefixes suffices for the fold;
the count itself need not be polynomially bounded.
Main results #
Turing.MultiTapeTM.ComputableTidilyInPolySpace.natFold: a fold with bounded accumulators.Turing.MultiTapeTM.ComputableTidilyInPolySpace.natFold_spec: a prefix invariant gives both the space certificate and the final postcondition.
References #
Adapted from the lean-canny contributors' Computation/TidyBoundedFold.lean at
2a50a2ee.
The port uses the standard Nat.fold and the existing tidy space calculus, with no separate
machine or computability predicate.
A fold over a binary count is polynomial-space when its step and seed are polynomial-space and every accumulator prefix has polynomially bounded encoded length.
A prefix invariant proves the fold's polynomial-space certificate and its final postcondition. The invariant and bound are proof data; only the count, seed and step run.