Imports
/- Copyright (c) 2026 Terence Rokop. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Terence Rokop -/ module public import Geb.Prototypes.Computability.CobhamFoldProto.Bound public import Geb.Prototypes.Computability.CobhamFoldProto.Fold public import Geb.Prototypes.Computability.CobhamFoldProto.SelfDelim public import Geb.Mathlib.Computability.Cobham.RankedTree

The fold at a bitstring carrier

Geb/Prototypes/Computability/CobhamFoldProto/Expr.lean folds at a carrier with a fixed-width bit encoding, dispatching each step on a constant window that holds the whole stack the step reads. This module folds at the carrier List Bool with the algebra's operations supplied as expressions of Cobham's class, so the carrier is unrestricted and the algebra is whatever the class can define.

Main definitions

    Geb.CobhamFold.stackWordV, Geb.CobhamFold.stateWordV — the stack and the state as bitstrings.

    Geb.CobhamFold.stackSize — the total length of the pending values.

    Geb.CobhamFold.entryWordOf, Geb.CobhamFold.applyAlgOf, Geb.CobhamFold.newStackOf, Geb.CobhamFold.rebuildOf — the step's stack rewrite, as expressions.

    Geb.CobhamFold.branchV, Geb.CobhamFold.foldStepV — one step of the fold.

    Geb.CobhamFold.decodeVAt — the inverse of the layout at a window.

    Geb.CobhamFold.foldGrowthV — the growth the state layout's fixed part contributes.

    Geb.CobhamFold.foldSemV, Geb.CobhamFold.foldExprV, Geb.CobhamFold.foldExprOfV — the scan, and the scan as a member of Cobham.C.

    Geb.CobhamFold.readoutWidthV, Geb.CobhamFold.outWordV, Geb.CobhamFold.readOfV — the readout's window, its output word, and the readout as an expression.

    Geb.CobhamFold.foldOutOfV, Geb.CobhamFold.foldOutExprV, Geb.CobhamFold.foldOutSemV — the readout composed onto the scan by Geb.CobhamFold.comp1Of.

    Geb.CobhamFold.algOfFixed — a fixed-width carrier's algebra transported here.

Main statements

    Geb.CobhamFold.stackWordV_cons, Geb.CobhamFold.length_stackWordV — the stack's layout and its length.

    Geb.CobhamFold.stepWord_dropEntriesOf_stackWordV, Geb.CobhamFold.stepWord_entryOf_stackWordV — the primitives read the stack.

    Geb.CobhamFold.stepWord_dropEntriesOf_stackWordV_append, Geb.CobhamFold.stepWord_entryOf_stackWordV_append — the same two reads at a stack layout followed by an arbitrary remainder, which each need the count to be within the stack.

    Geb.CobhamFold.decodeState_stateWordV — the dispatch window decodes the flag, the block and the count capped at the window.

    Geb.CobhamFold.stepWord_foldStepV — a step of the expression computes a step of the fold scan.

    Geb.CobhamFold.foldSemV_eq, Geb.CobhamFold.length_foldSemV_le — the expression computes the fold scan's state word, and the recursion bound it satisfies under the linear-growth hypothesis.

    Geb.CobhamFold.stepWord_readOfV — the readout's value at a state word.

    Geb.CobhamFold.length_fold_le_of_growth — an algebra lengthening by at most a constant per symbol folds a term to a value linear in its node count.

    Geb.CobhamFold.potential_foldScanStep_le, Geb.CobhamFold.potential_foldScanFinal_le, Geb.CobhamFold.stackSize_le_of_growth — the same condition bounds the scan's potential R.width * stackSize + c * |buf|, and so discharges the linear-growth hypothesis length_foldSemV_le takes.

    Geb.CobhamFold.potential_foldScanStep_le_of_invariant, Geb.CobhamFold.potential_foldScanFinal_le_of_invariant, Geb.CobhamFold.stackSize_le_of_growth_of_invariant — the same three with the growth condition assumed only of values satisfying a predicate the scan's stack carries, which an algebra duplicating its children's payloads needs; the unrestricted forms are these at the trivial predicate.

    Geb.CobhamFold.foldOutSemV_eq — the expression computes Geb.CobhamFold.foldOut, spelled by outWordV; with foldOut_eq this is RankedAlphabet.parse followed by the algebra morphism.

    Geb.CobhamFold.foldOut_algOfFixed — at an algebra whose carrier stays within a fixed width, the fold this construction computes and the one the fixed-width construction computes agree, up to the encoding. It is a statement about the two algebras at the shared semantic layer, which each construction is separately proved to compute (foldOutSemV_eq here, foldOutSem_eq there).

    Geb.CobhamFold.foldSemV_eq_eval, Geb.CobhamFold.foldOutSemV_eq_eval — the meanings read at the raw trees are the meanings the expressions carry.

Implementation notes

Names here carry a V suffix where their fixed-width counterparts in Geb/Prototypes/Computability/CobhamFoldProto/Layout.lean and Geb/Prototypes/Computability/CobhamFoldProto/Expr.lean carry an F or, where the fixed-width name came first, no suffix at all: the two constructions define the same notions at a variable-width and at a fixed-width carrier, and the suffix is what keeps them apart in one namespace.

The state layout

stateWordV R s = stateWord R (toScan s) ++ false :: stackWordV s.stack

The state word is the recognizer's — the liveness flag, the block slot, and the pending count in unary — followed by a false sentinel and the stack, whose entries are Geb.CobhamFold.entryWord's self-delimiting spellings.

Two consequences. The pending count stays inside a constant dispatch window, so the test R.arity i ≤ depth is still a bounded one and the branch family is Cobham.dispatchWidth R wide — the recognizer's own width, independent of the carrier. And the sentinel is required: an entry begins with its length in unary, so without a false between the count and the stack the decoder's takeWhile would run out of the count and into the first entry's prefix.

Cost

Each primitive the step reads the stack with is itself a recursion whose step is not constant. Geb.CobhamFold.dropEntryOf's step applies Cobham.pred, itself a boundedRec; Geb.CobhamFold.takeEntryOf's step runs a fresh dropEntryOf over the remaining word. Counting a boundedRec's cost as the sum over its levels of its step's cost, dropEntryOf is quadratic in its argument and takeEntryOf cubic, so a fold's state-reading here is polynomial of a degree above two rather than quadratic.

Nothing here measures a number of reduction steps, as Geb/Mathlib/Computability/Cobham/Tree.lean records of its own subject; the paragraph above is an analysis of the expression under one cost model, and a machine evaluating it is not obliged to follow that model.

The accompanying lower bound rests only on the class's shape rather than on a cost model: reading an unbounded field of the state requires a recursion over the state, boundedRec being the class's only recursion, so no step reading such a field is constant. It bears on this layout, whose steps do read one; it does not exclude some other expression computing the same fold without reading an unbounded field. It is an argument about the expression, not a theorem stated here.

The algebra is an arbitrary member of the class and so carries whatever cost the class admits, putting a fold above its algebra by whatever the state-reading costs. The state-reading is therefore not what limits a fold: any cost the class admits at all is reached by spending it inside the algebra. How far that goes is a question about the class, not about this construction, and it is not settled here — only the left-to-right inclusion of [Strahm2003] Theorem 1(2) is relied on anywhere in this repository, and docs/references.bib records that the equality fails read literally.

Space is what binds. The state holds every pending value, so a linear-space reading forces a constant c bounding the pending values' total length by c * n, which is the hypothesis Geb.CobhamFold.length_foldSemV_le takes. That hypothesis is not an artifact of this construction: [Clote1999]'s arithmetic analogue reads its class as one of functions of linear growth.

The dispatch is no wider here than at a fixed-width carrier, and narrower at every positive carrier width; at p = 0 the two coincide, which Geb.CobhamFold.dispatchWidthF_zero states. The fixed-width dispatch reads the stack, so its branch family is 2 ^ (1 + R.width + (p + 1) * (R.maxArity + 1)); here it reads only the flag, the slot and the count, so the family is 2 ^ Cobham.dispatchWidth R whatever the carrier. This is a statement about the branch family alone: the completing branch here carries a rebuildOf subtree no fixed-width branch does, and the two expressions' sizes are not compared.

References

    [Clote1999]

    [Cobham1965]

    [Strahm2003]

Tags

Cobham, bounded recursion on notation, fold, self-delimiting, bitstring carrier

@[expose] public sectionnamespace Geb.CobhamFoldopen Cobham RankedAlphabetuniverse u

The stack as a bitstring: the self-delimiting spelling of each entry, the top entry first.

def stackWordV (st : List (List Bool)) : List Bool := st.flatMap entryWord

The empty stack's layout.

@[simp] theorem stackWordV_nil : stackWordV [] = [] := rfl

The stack's layout, one entry at a time.

@[simp] theorem stackWordV_cons (a : List Bool) (st : List (List Bool)) : stackWordV (a :: st) = entryWord a ++ stackWordV st := rfl

The total length of the pending values.

def stackSize (st : List (List Bool)) : := st.flatten.length

The empty stack's values are empty.

@[simp] theorem stackSize_nil : stackSize [] = 0 := rfl

The pending values' total length, one entry at a time.

@[simp] theorem stackSize_cons (a : List Bool) (st : List (List Bool)) : stackSize (a :: st) = a.length + stackSize st := a:List Boolst:List (List Bool)stackSize (a :: st) = a.length + stackSize st All goals completed! 🐙

The stack's layout is twice the pending values' total length plus one bit per entry.

theorem length_stackWordV : st : List (List Bool), (stackWordV st).length = 2 * stackSize st + st.length := List.rec rfl fun a t ih a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length(stackWordV (a :: t)).length = 2 * stackSize (a :: t) + (a :: t).length a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length2 * a.length + 1 + (2 * stackSize t + t.length) = 2 * (a.length + stackSize t) + (t.length + 1) All goals completed! 🐙

The state as a bitstring: the recognizer's state word, a false sentinel, then the stack.

def stateWordV (R : RankedAlphabet) (s : FoldScan (List Bool)) : List Bool := stateWord R (toScan s) ++ false :: stackWordV s.stack

The state word's length.

theorem length_stateWordV_of_lt (R : RankedAlphabet) (s : FoldScan (List Bool)) (h : s.buf.length < R.width) : (stateWordV R s).length = 1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length) := R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width(stateWordV R s).length = 1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length(stateWordV R s).length = 1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length1 + R.width + s.stack.length + (2 * stackSize s.stack + s.stack.length + 1) = 1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length) All goals completed! 🐙

Dropping whole entries from the stack's layout drops whole entries from the stack.

theorem stepWord_dropEntriesOf_stackWordV : (k : ) (st : List (List Bool)), stepWord (dropEntriesOf k) (stackWordV st) = stackWordV (st.drop k) := Nat.rec (fun st st:List (List Bool)stepWord (dropEntriesOf Nat.zero) (stackWordV st) = stackWordV (List.drop Nat.zero st) All goals completed! 🐙) fun k ih st k:ih: (st : List (List Bool)), stepWord (dropEntriesOf k) (stackWordV st) = stackWordV (List.drop k st)st:List (List Bool)stepWord (dropEntriesOf k.succ) (stackWordV st) = stackWordV (List.drop k.succ st) k:ih: (st : List (List Bool)), stepWord (dropEntriesOf k) (stackWordV st) = stackWordV (List.drop k st)st:List (List Bool)stepWord (dropEntriesOf k) (dropEntrySem ![stackWordV st]) = stackWordV (List.drop k.succ st) match st with k:ih: (st : List (List Bool)), stepWord (dropEntriesOf k) (stackWordV st) = stackWordV (List.drop k st)st:List (List Bool)stepWord (dropEntriesOf k) (dropEntrySem ![stackWordV []]) = stackWordV (List.drop k.succ []) k:ih: (st : List (List Bool)), stepWord (dropEntriesOf k) (stackWordV st) = stackWordV (List.drop k st)st:List (List Bool)stepWord (dropEntriesOf k) (dropEntrySem ![stackWordV []]) = stackWordV [] All goals completed! 🐙 k:ih: (st : List (List Bool)), stepWord (dropEntriesOf k) (stackWordV st) = stackWordV (List.drop k st)st:List (List Bool)a:List Boolt:List (List Bool)stepWord (dropEntriesOf k) (dropEntrySem ![stackWordV (a :: t)]) = stackWordV (List.drop k.succ (a :: t)) All goals completed! 🐙

The j-th entry primitive reads the j-th pending value.

theorem stepWord_entryOf_stackWordV (j : ) (st : List (List Bool)) : stepWord (entryOf j) (stackWordV st) = (st.drop j).headD [] := j:st:List (List Bool)stepWord (entryOf j) (stackWordV st) = (List.drop j st).headD [] j:st:List (List Bool)takeEntrySem ![stackWordV (List.drop j st)] = (List.drop j st).headD [] match hd : st.drop j with j:st:List (List Bool)hd:List.drop j st = []takeEntrySem ![stackWordV []] = [].headD [] j:st:List (List Bool)hd:List.drop j st = []takeEntrySem ![[]] = [].headD []; All goals completed! 🐙 j:st:List (List Bool)a:List Boolt:List (List Bool)hd:List.drop j st = a :: ttakeEntrySem ![stackWordV (a :: t)] = (a :: t).headD [] j:st:List (List Bool)a:List Boolt:List (List Bool)hd:List.drop j st = a :: ta = (a :: t).headD []; All goals completed! 🐙

Dropping as many entries as a stack layout holds leaves what follows it. Geb.CobhamFold.stepWord_dropEntriesOf_stackWordV is this at the empty remainder, where the hypothesis is unnecessary.

theorem stepWord_dropEntriesOf_stackWordV_append : (k : ) (st : List (List Bool)) (rest : List Bool), k st.length stepWord (dropEntriesOf k) (stackWordV st ++ rest) = stackWordV (st.drop k) ++ rest := Nat.rec (fun st rest _ st:List (List Bool)rest:List Boolx✝:Nat.zero st.lengthstepWord (dropEntriesOf Nat.zero) (stackWordV st ++ rest) = stackWordV (List.drop Nat.zero st) ++ rest All goals completed! 🐙) fun k ih st rest h match st with | [] => absurd h (Nat.not_succ_le_zero k) k:ih: (st : List (List Bool)) (rest : List Bool), k st.length stepWord (dropEntriesOf k) (stackWordV st ++ rest) = stackWordV (List.drop k st) ++ restst:List (List Bool)rest:List Boola:List Boolt:List (List Bool)h:k.succ (a :: t).lengthstepWord (dropEntriesOf k.succ) (stackWordV (a :: t) ++ rest) = stackWordV (List.drop k.succ (a :: t)) ++ rest k:ih: (st : List (List Bool)) (rest : List Bool), k st.length stepWord (dropEntriesOf k) (stackWordV st ++ rest) = stackWordV (List.drop k st) ++ restst:List (List Bool)rest:List Boola:List Boolt:List (List Bool)h:k.succ (a :: t).lengthstepWord (dropEntriesOf k.succ) (stackWordV (a :: t) ++ rest) = stackWordV (List.drop k.succ (a :: t)) ++ rest All goals completed! 🐙

The j-th entry of a stack layout is its j-th value, whatever follows the layout. Geb.CobhamFold.stepWord_entryOf_stackWordV agrees with it where j < st.length; neither is an instance of the other, that one being unconditional in j and read through List.headD.

theorem stepWord_entryOf_stackWordV_append (j : ) (st : List (List Bool)) (rest : List Bool) (h : j < st.length) : stepWord (entryOf j) (stackWordV st ++ rest) = st[j] := j:st:List (List Bool)rest:List Boolh:j < st.lengthstepWord (entryOf j) (stackWordV st ++ rest) = st[j] All goals completed! 🐙

The run of true a window over a unary count reads, when the count is followed by a false sentinel and the window may overrun the word. Whether the window ends inside the count or past the sentinel, the run is the count capped at the window.

private theorem takeWhile_id_take_replicate (Z : List Bool) : (m k p : ), (((List.replicate k true ++ false :: Z).take m) ++ List.replicate p false).takeWhile id = List.replicate (min m k) true := Nat.rec (fun k p Z:List Boolk:p:List.takeWhile id (List.take Nat.zero (List.replicate k true ++ false :: Z) ++ List.replicate p false) = List.replicate (min Nat.zero k) true Z:List Boolk:p:List.takeWhile id (List.replicate p false) = [] match p with Z:List Boolk:p:List.takeWhile id (List.replicate 0 false) = [] All goals completed! 🐙 Z:List Boolk:p:n✝:List.takeWhile id (List.replicate (n✝ + 1) false) = [] All goals completed! 🐙) fun m ih k p match k with Z:List Boolm:ih: (k p : ), List.takeWhile id (List.take m (List.replicate k true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m k) truek:p:List.takeWhile id (List.take m.succ (List.replicate 0 true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m.succ 0) true Z:List Boolm:ih: (k p : ), List.takeWhile id (List.take m (List.replicate k true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m k) truek:p:List.takeWhile id (List.take m.succ (List.replicate 0 true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m.succ 0) true Z:List Boolm:ih: (k p : ), List.takeWhile id (List.take m (List.replicate k true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m k) truek:p:List.takeWhile id (false :: (List.take m Z ++ List.replicate p false)) = [] All goals completed! 🐙 Z:List Boolm:ih: (k p : ), List.takeWhile id (List.take m (List.replicate k true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m k) truek✝:p:k:List.takeWhile id (List.take m.succ (List.replicate (k + 1) true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m.succ (k + 1)) true Z:List Boolm:ih: (k p : ), List.takeWhile id (List.take m (List.replicate k true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m k) truek✝:p:k:List.takeWhile id (List.take m.succ (List.replicate (k + 1) true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m.succ (k + 1)) true Z:List Boolm:ih: (k p : ), List.takeWhile id (List.take m (List.replicate k true ++ false :: Z) ++ List.replicate p false) = List.replicate (min m k) truek✝:p:k:List.takeWhile id (true :: (List.take m (List.replicate k true ++ false :: Z) ++ List.replicate p false)) = true :: List.replicate (min m k) true All goals completed! 🐙

The state word truncated to a window and zero-padded: the flag, the slot, then the count and whatever of the stack the window reaches.

theorem ofFn_bits_stateWordV (R : RankedAlphabet) (s : FoldScan (List Bool)) (n m : ) (hn : n = 1 + R.width + m) (h : s.buf.length < R.width) : List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (((List.replicate s.stack.length true ++ false :: stackWordV s.stack).take m) ++ List.replicate (n - (stateWordV R s).length) false)) := R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthList.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false)) R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthList.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false)) R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhdw:n = (bufBits R s.buf).length + m + 1List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false)) R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhdw:n = (bufBits R s.buf).length + m + 1hcons:stateWordV R s = s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false)) All goals completed! 🐙

The inverse of the layout at a window of n bits: the flag, the block past the slot's padding, and the run of the pending count. Cobham.decodeState is this at the dispatch window.

def decodeVAt (R : RankedAlphabet) (n : ) (v : Fin n Bool) : Scan := (((List.ofFn v).tail.take R.width).dropWhile (fun b !b)).tail, (((List.ofFn v).tail.drop R.width).takeWhile id).length, (List.ofFn v).headD false

A window decodes the flag, the incomplete block, and the pending count capped at the window. The false sentinel is what stops the count's run from continuing into the first entry's own unary prefix.

theorem decodeVAt_stateWordV (R : RankedAlphabet) (s : FoldScan (List Bool)) (n m : ) (hn : n = 1 + R.width + m) (h : s.buf.length < R.width) : decodeVAt R n (bits n (stateWordV R s)) = s.buf, min s.stack.length m, s.live := R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthdecodeVAt R n (bits n (stateWordV R s)) = { buf := s.buf, depth := min s.stack.length m, live := s.live } R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthdecodeVAt R n (bits n (stateWordV R s)) = { buf := s.buf, depth := min s.stack.length m, live := s.live } R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))decodeVAt R n (bits n (stateWordV R s)) = { buf := s.buf, depth := min s.stack.length m, live := s.live } R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))(decodeVAt R n (bits n (stateWordV R s))).buf = { buf := s.buf, depth := min s.stack.length m, live := s.live }.bufR:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))(decodeVAt R n (bits n (stateWordV R s))).depth = { buf := s.buf, depth := min s.stack.length m, live := s.live }.depthR:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))(decodeVAt R n (bits n (stateWordV R s))).live = { buf := s.buf, depth := min s.stack.length m, live := s.live }.live R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))(decodeVAt R n (bits n (stateWordV R s))).buf = { buf := s.buf, depth := min s.stack.length m, live := s.live }.buf R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false)){ buf := (true :: s.buf).tail, depth := (List.takeWhile id (List.drop R.width (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false)))).length, live := (s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))).headD false }.buf = { buf := s.buf, depth := min s.stack.length m, live := s.live }.buf All goals completed! 🐙 R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))(decodeVAt R n (bits n (stateWordV R s))).depth = { buf := s.buf, depth := min s.stack.length m, live := s.live }.depth R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false)){ buf := (List.dropWhile (fun b !b) (List.take R.width (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false)))).tail, depth := min m s.stack.length, live := (s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))).headD false }.depth = { buf := s.buf, depth := min s.stack.length m, live := s.live }.depth All goals completed! 🐙 R:RankedAlphabets:FoldScan (List Bool)n:m:hn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.widthhword:List.ofFn (bits n (stateWordV R s)) = s.live :: (bufBits R s.buf ++ (List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++ List.replicate (n - (stateWordV R s).length) false))(decodeVAt R n (bits n (stateWordV R s))).live = { buf := s.buf, depth := min s.stack.length m, live := s.live }.live All goals completed! 🐙

The dispatch window's decode, which is Cobham.decodeState.

theorem decodeState_stateWordV (R : RankedAlphabet) (s : FoldScan (List Bool)) (h : s.buf.length < R.width) : decodeState R (bits (dispatchWidth R) (stateWordV R s)) = s.buf, min s.stack.length (R.maxArity + 1), s.live := decodeVAt_stateWordV R s (dispatchWidth R) (R.maxArity + 1) (R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthdispatchWidth R = 1 + R.width + (R.maxArity + 1) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthR.width + R.maxArity + 2 = 1 + R.width + (R.maxArity + 1); All goals completed! 🐙) h

The self-delimiting spelling, as an expression of arity one.

def entryWordOf : COf 1 := concatCompOf 1 (prependOf [false] idOf) unaryOf

The spelling expression's value at a step.

theorem stepWord_entryWordOf (u : List Bool) : stepWord entryWordOf u = entryWord u := u:List BoolstepWord entryWordOf u = entryWord u u:List BoolList.replicate u.length true ++ ([false] ++ u) = List.replicate u.length true ++ false :: u All goals completed! 🐙

The algebra's operation applied to the entries the stack holds.

def applyAlgOf {r : } (algI : COf r) : COf 1 := compOf algI fun j entryOf j.val

The algebra application's value at a step.

theorem stepWord_applyAlgOf {r : } (algI : COf r) (u : List Bool) : stepWord (applyAlgOf algI) u = semAt r algI.1.1 algI.2 fun j stepWord (entryOf j.val) u := stepWord_compOf algI _ u

The stack after the pop: the algebra's value spelled as an entry, then the stack past the entries it consumed.

def newStackOf {r : } (algI : COf r) : COf 1 := concatCompOf 1 (dropEntriesOf r) (comp1Of entryWordOf (applyAlgOf algI))

The new stack's value at a step.

theorem stepWord_newStackOf {r : } (algI : COf r) (u : List Bool) : stepWord (newStackOf algI) u = entryWord (stepWord (applyAlgOf algI) u) ++ stepWord (dropEntriesOf r) u := r:algI:COf ru:List BoolstepWord (newStackOf algI) u = entryWord (stepWord (applyAlgOf algI) u) ++ stepWord (dropEntriesOf r) u All goals completed! 🐙

The state past the flag and the slot, rebuilt: the pending count is kept and the stack is rewritten.

def rebuildOf {r : } (algI : COf r) : COf 1 := concatCompOf 1 (prependOf [false] (comp1Of (newStackOf algI) dropUnaryOf)) takeUnaryOf

The rebuild's value at a step.

theorem stepWord_rebuildOf {r : } (algI : COf r) (z : List Bool) : stepWord (rebuildOf algI) z = takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z]) := r:algI:COf rz:List BoolstepWord (rebuildOf algI) z = takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z]) r:algI:COf rz:List BooltakeUnarySem ![z] ++ ([false] ++ stepWord (newStackOf algI) (dropUnarySem ![z])) = takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z]) All goals completed! 🐙

The state word past the flag, the slot and k of the pending count: the count short by k, then the sentinel and the stack.

theorem drop_stateWordV (R : RankedAlphabet) (s : FoldScan (List Bool)) (h : s.buf.length < R.width) (k : ) (hk : k s.stack.length) : (stateWordV R s).drop (1 + R.width + k) = List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack := R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthk:hk:k s.stack.lengthList.drop (1 + R.width + k) (stateWordV R s) = List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthk:hk:k s.stack.lengthhpre:(s.live :: bufBits R s.buf).length = 1 + R.widthList.drop (1 + R.width + k) (stateWordV R s) = List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthk:hk:k s.stack.lengthhpre:(s.live :: bufBits R s.buf).length = 1 + R.widthhsplit:List.replicate s.stack.length true = List.replicate k true ++ List.replicate (s.stack.length - k) trueList.drop (1 + R.width + k) (stateWordV R s) = List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthk:hk:k s.stack.lengthhpre:(s.live :: bufBits R s.buf).length = 1 + R.widthhsplit:List.replicate s.stack.length true = List.replicate k true ++ List.replicate (s.stack.length - k) truehcons:stateWordV R s = s.live :: bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack)List.drop (1 + R.width + k) (stateWordV R s) = List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack All goals completed! 🐙

One step of the fold at a bitstring carrier, as a function of the state the dispatch window decodes. A failed state absorbs; an incomplete block takes the bit; a completed block's symbol pops its arity from the count and rewrites the stack.

def branchV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (b : Bool) (t : Scan) : COf 1 := match t.live with | false => idOf | true => if (b :: t.buf).length = R.width then match symOf R (decodeBits (b :: t.buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i t.depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: t.buf)) (predIterOf (1 + R.width))

One step of the fold expression: dispatch on the flag, the slot and the pending count, and rewrite.

def foldStepV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (b : Bool) : COf 1 := diagOf (casesOf (dispatchWidth R) fun v branchV R algOf b (decodeState R v))

The step's value at a state word, before the branch is resolved.

theorem stepWord_foldStepV_apply (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (b : Bool) (s : FoldScan (List Bool)) (h : s.buf.length < R.width) : stepWord (foldStepV R algOf b) (stateWordV R s) = stepWord (branchV R algOf b s.buf, min s.stack.length (R.maxArity + 1), s.live) (stateWordV R s) := R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.widthstepWord (foldStepV R algOf b) (stateWordV R s) = stepWord (branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live }) (stateWordV R s) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.widthsemAt 2 (casesOf (dispatchWidth R) fun v branchV R algOf b (decodeState R v)) ![stateWordV R s, stateWordV R s] = stepWord (branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live }) (stateWordV R s) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.widthcasesSem (dispatchWidth R) (fun v branchV R algOf b (decodeState R v)) ![stateWordV R s, stateWordV R s] = stepWord (branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live }) (stateWordV R s) All goals completed! 🐙

Capping the pending count at the dispatch window leaves the branch unchanged: the only test reading the count compares it with an arity, which RankedAlphabet.arity_le_maxArity bounds by R.maxArity.

theorem branchV_min (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (b : Bool) (t : Scan) : branchV R algOf b { t with depth := min t.depth (R.maxArity + 1) } = branchV R algOf b t := R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolt:ScanbranchV R algOf b { buf := t.buf, depth := min t.depth (R.maxArity + 1), live := t.live } = branchV R algOf b t R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:live:BoolbranchV R algOf b { buf := { buf := buf, depth := depth, live := live }.buf, depth := min { buf := buf, depth := depth, live := live }.depth (R.maxArity + 1), live := { buf := buf, depth := depth, live := live }.live } = branchV R algOf b { buf := buf, depth := depth, live := live } R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:live:Bool(match { buf := { buf := buf, depth := depth, live := live }.buf, depth := min { buf := buf, depth := depth, live := live }.depth (R.maxArity + 1), live := { buf := buf, depth := depth, live := live }.live }.live with | false => idOf | true => if (b :: { buf := { buf := buf, depth := depth, live := live }.buf, depth := min { buf := buf, depth := depth, live := live }.depth (R.maxArity + 1), live := { buf := buf, depth := depth, live := live }.live }.buf).length = R.width then match symOf R (decodeBits (b :: { buf := { buf := buf, depth := depth, live := live }.buf, depth := min { buf := buf, depth := depth, live := live }.depth (R.maxArity + 1), live := { buf := buf, depth := depth, live := live }.live }.buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i { buf := { buf := buf, depth := depth, live := live }.buf, depth := min { buf := buf, depth := depth, live := live }.depth (R.maxArity + 1), live := { buf := buf, depth := depth, live := live }.live }.depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: { buf := { buf := buf, depth := depth, live := live }.buf, depth := min { buf := buf, depth := depth, live := live }.depth (R.maxArity + 1), live := { buf := buf, depth := depth, live := live }.live }.buf)) (predIterOf (1 + R.width))) = match { buf := buf, depth := depth, live := live }.live with | false => idOf | true => if (b :: { buf := buf, depth := depth, live := live }.buf).length = R.width then match symOf R (decodeBits (b :: { buf := buf, depth := depth, live := live }.buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i { buf := buf, depth := depth, live := live }.depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: { buf := buf, depth := depth, live := live }.buf)) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:live:Bool(match live with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = match live with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:(match false with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = match false with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:(match true with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = match true with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:(match false with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = match false with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:(match true with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = match true with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:(if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.width(if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:¬(b :: buf).length = R.width(if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.width(if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.width(match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) match hsym : symOf R (decodeBits (b :: buf)) with R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.widthhsym:symOf R (decodeBits (b :: buf)) = none(match none with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = match none with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some i(match some i with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = match some i with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some i(if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihle:R.arity i R.maxArity(if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihle:R.arity i R.maxArityhst:R.arity i depth(if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihle:R.arity i R.maxArityhst:¬R.arity i depth(if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihle:R.arity i R.maxArityhst:R.arity i depth(if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihle:R.arity i R.maxArityhst:¬R.arity i depth(if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) = if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)b:Boolbuf:List Booldepth:hlen:¬(b :: buf).length = R.width(if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i min depth (R.maxArity + 1) then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) = if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) All goals completed! 🐙

The state layout at an explicit state.

theorem stateWordV_mk (R : RankedAlphabet) (buf : List Bool) (st : List (List Bool)) (live : Bool) : stateWordV R buf, st, live = (live :: bufBits R buf ++ List.replicate st.length true) ++ false :: stackWordV st := rfl

The head of a suffix is the element it starts at.

private theorem headD_drop (j : ) (st : List (List Bool)) (hj : j < st.length) : (st.drop j).headD [] = st[j] := j:st:List (List Bool)hj:j < st.length(List.drop j st).headD [] = st[j] j:st:List (List Bool)hj:j < st.length(st[j] :: List.drop (j + 1) st).headD [] = st[j] All goals completed! 🐙

A step of the expression computes a step of the fold scan. The algebra's operations enter only through halg, which reads each expression's meaning as the corresponding carrier-level operation.

theorem stepWord_foldStepV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (b : Bool) (s : FoldScan (List Bool)) (h : s.buf.length < R.width) : stepWord (foldStepV R algOf b) (stateWordV R s) = stateWordV R (foldScanStep R alg b s) := R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Bools:FoldScan (List Bool)h:s.buf.length < R.widthstepWord (foldStepV R algOf b) (stateWordV R s) = stateWordV R (foldScanStep R alg b s) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Bools:FoldScan (List Bool)h:s.buf.length < R.widthstepWord (branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live }) (stateWordV R s) = stateWordV R (foldScanStep R alg b s) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Bools:FoldScan (List Bool)h:s.buf.length < R.widthhcap:branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live } = branchV R algOf b { buf := s.buf, depth := s.stack.length, live := s.live }stepWord (branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live }) (stateWordV R s) = stateWordV R (foldScanStep R alg b s) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Bools:FoldScan (List Bool)h:s.buf.length < R.widthhcap:branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live } = branchV R algOf b { buf := s.buf, depth := s.stack.length, live := s.live }stepWord (branchV R algOf b { buf := s.buf, depth := s.stack.length, live := s.live }) (stateWordV R s) = stateWordV R (foldScanStep R alg b s) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Bools:FoldScan (List Bool)h:s.buf.length < R.widthhcap:branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live } = branchV R algOf b { buf := s.buf, depth := s.stack.length, live := s.live }hdrop0:List.drop (1 + R.width) (stateWordV R s) = List.replicate s.stack.length true ++ false :: stackWordV s.stackstepWord (branchV R algOf b { buf := s.buf, depth := s.stack.length, live := s.live }) (stateWordV R s) = stateWordV R (foldScanStep R alg b s) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)live:Boolh:{ buf := buf, stack := stack, live := live }.buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := min { buf := buf, stack := stack, live := live }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := live }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := { buf := buf, stack := stack, live := live }.stack.length, live := { buf := buf, stack := stack, live := live }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := live }) = List.replicate { buf := buf, stack := stack, live := live }.stack.length true ++ false :: stackWordV { buf := buf, stack := stack, live := live }.stackstepWord (branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := { buf := buf, stack := stack, live := live }.stack.length, live := { buf := buf, stack := stack, live := live }.live }) (stateWordV R { buf := buf, stack := stack, live := live }) = stateWordV R (foldScanStep R alg b { buf := buf, stack := stack, live := live }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)live:Boolh:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := min { buf := buf, stack := stack, live := live }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := live }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := { buf := buf, stack := stack, live := live }.stack.length, live := { buf := buf, stack := stack, live := live }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := live }) = List.replicate stack.length true ++ false :: stackWordV stackstepWord (branchV R algOf b { buf := buf, depth := stack.length, live := live }) (stateWordV R { buf := buf, stack := stack, live := live }) = stateWordV R (foldScanStep R alg b { buf := buf, stack := stack, live := live }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)live:Boolh:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := min { buf := buf, stack := stack, live := live }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := live }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := { buf := buf, stack := stack, live := live }.stack.length, live := { buf := buf, stack := stack, live := live }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := live }) = List.replicate stack.length true ++ false :: stackWordV stackstepWord (match { buf := buf, depth := stack.length, live := live }.live with | false => idOf | true => if (b :: { buf := buf, depth := stack.length, live := live }.buf).length = R.width then match symOf R (decodeBits (b :: { buf := buf, depth := stack.length, live := live }.buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i { buf := buf, depth := stack.length, live := live }.depth then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: { buf := buf, depth := stack.length, live := live }.buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := live }) = stateWordV R (match { buf := buf, stack := stack, live := live }.live with | false => { buf := buf, stack := stack, live := live } | true => if (b :: { buf := buf, stack := stack, live := live }.buf).length = R.width then match symOf R (decodeBits (b :: { buf := buf, stack := stack, live := live }.buf)) with | none => { buf := [], stack := { buf := buf, stack := stack, live := live }.stack, live := false } | some i => if h : R.arity i { buf := buf, stack := stack, live := live }.stack.length then { buf := [], stack := (alg i fun d { buf := buf, stack := stack, live := live }.stack[d]) :: List.drop (R.arity i) { buf := buf, stack := stack, live := live }.stack, live := true } else { buf := [], stack := { buf := buf, stack := stack, live := live }.stack, live := false } else { buf := b :: { buf := buf, stack := stack, live := live }.buf, stack := { buf := buf, stack := stack, live := live }.stack, live := true }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)live:Boolh:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := min { buf := buf, stack := stack, live := live }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := live }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := live }.buf, depth := { buf := buf, stack := stack, live := live }.stack.length, live := { buf := buf, stack := stack, live := live }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := live }) = List.replicate stack.length true ++ false :: stackWordV stackstepWord (match live with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := live }) = stateWordV R (match live with | false => { buf := buf, stack := stack, live := live } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := false }.buf, depth := min { buf := buf, stack := stack, live := false }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := false }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := false }.buf, depth := { buf := buf, stack := stack, live := false }.stack.length, live := { buf := buf, stack := stack, live := false }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := false }) = List.replicate stack.length true ++ false :: stackWordV stackstepWord (match false with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := false }) = stateWordV R (match false with | false => { buf := buf, stack := stack, live := false } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true })R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackstepWord (match true with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (match true with | false => { buf := buf, stack := stack, live := true } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := false }.buf, depth := min { buf := buf, stack := stack, live := false }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := false }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := false }.buf, depth := { buf := buf, stack := stack, live := false }.stack.length, live := { buf := buf, stack := stack, live := false }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := false }) = List.replicate stack.length true ++ false :: stackWordV stackstepWord (match false with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := false }) = stateWordV R (match false with | false => { buf := buf, stack := stack, live := false } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }) All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackstepWord (match true with | false => idOf | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (match true with | false => { buf := buf, stack := stack, live := true } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackstepWord (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthstepWord (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true })R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:¬(b :: buf).length = R.widthstepWord (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthstepWord (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthstepWord (match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }) match hsym : symOf R (decodeBits (b :: buf)) with R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthhsym:symOf R (decodeBits (b :: buf)) = nonestepWord (match none with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (match none with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthhsym:symOf R (decodeBits (b :: buf)) = nonefalse :: bufBits R [] ++ (List.replicate stack.length true ++ false :: stackWordV stack) = false :: bufBits R [] ++ List.replicate stack.length true ++ false :: stackWordV stack All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some istepWord (match some i with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (match some i with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some istepWord (if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthstepWord (if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false })R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:¬R.arity i stack.lengthstepWord (if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthstepWord (if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthtrue :: bufBits R [] ++ [true] ++ (List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++ false :: (entryWord (alg i fun j stepWord (entryOf j) (stackWordV { buf := buf, stack := stack, live := true }.stack)) ++ stackWordV (List.drop (R.arity i) { buf := buf, stack := stack, live := true }.stack))) = true :: bufBits R [] ++ List.replicate ((alg i fun d stack[d]) :: List.drop (R.arity i) stack).length true ++ false :: stackWordV ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhargs:(fun j stepWord (entryOf j) (stackWordV stack)) = fun j stack[j]true :: bufBits R [] ++ [true] ++ (List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++ false :: (entryWord (alg i fun j stepWord (entryOf j) (stackWordV { buf := buf, stack := stack, live := true }.stack)) ++ stackWordV (List.drop (R.arity i) { buf := buf, stack := stack, live := true }.stack))) = true :: bufBits R [] ++ List.replicate ((alg i fun d stack[d]) :: List.drop (R.arity i) stack).length true ++ false :: stackWordV ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhargs:(fun j stepWord (entryOf j) (stackWordV stack)) = fun j stack[j]true :: bufBits R [] ++ [true] ++ (List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++ false :: (entryWord (alg i fun j stack[j]) ++ stackWordV (List.drop (R.arity i) { buf := buf, stack := stack, live := true }.stack))) = true :: bufBits R [] ++ List.replicate (stack.length - R.arity i + 1) true ++ false :: (entryWord (alg i fun d stack[d]) ++ stackWordV (List.drop (R.arity i) stack)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhargs:(fun j stepWord (entryOf j) (stackWordV stack)) = fun j stack[j]hrep:List.replicate (stack.length - R.arity i + 1) true = [true] ++ List.replicate (stack.length - R.arity i) truetrue :: bufBits R [] ++ [true] ++ (List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++ false :: (entryWord (alg i fun j stack[j]) ++ stackWordV (List.drop (R.arity i) { buf := buf, stack := stack, live := true }.stack))) = true :: bufBits R [] ++ List.replicate (stack.length - R.arity i + 1) true ++ false :: (entryWord (alg i fun d stack[d]) ++ stackWordV (List.drop (R.arity i) stack)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhargs:(fun j stepWord (entryOf j) (stackWordV stack)) = fun j stack[j]hrep:List.replicate (stack.length - R.arity i + 1) true = [true] ++ List.replicate (stack.length - R.arity i) truetrue :: bufBits R [] ++ [true] ++ (List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++ false :: (entryWord (alg i fun j stack[j]) ++ stackWordV (List.drop (R.arity i) { buf := buf, stack := stack, live := true }.stack))) = true :: bufBits R [] ++ ([true] ++ List.replicate (stack.length - R.arity i) true) ++ false :: (entryWord (alg i fun d stack[d]) ++ stackWordV (List.drop (R.arity i) stack)) All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:¬R.arity i stack.lengthstepWord (if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:(b :: buf).length = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:¬R.arity i stack.lengthfalse :: bufBits R [] ++ (List.replicate stack.length true ++ false :: stackWordV stack) = false :: bufBits R [] ++ List.replicate stack.length true ++ false :: stackWordV stack All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:¬(b :: buf).length = R.widthstepWord (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) | some i => if R.arity i stack.length then prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) else prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) else prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width))) (stateWordV R { buf := buf, stack := stack, live := true }) = stateWordV R (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fb:Boolbuf:List Boolstack:List (List Bool)h:buf.length < R.widthhcap:branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := min { buf := buf, stack := stack, live := true }.stack.length (R.maxArity + 1), live := { buf := buf, stack := stack, live := true }.live } = branchV R algOf b { buf := { buf := buf, stack := stack, live := true }.buf, depth := { buf := buf, stack := stack, live := true }.stack.length, live := { buf := buf, stack := stack, live := true }.live }hdrop0:List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) = List.replicate stack.length true ++ false :: stackWordV stackhlen:¬(b :: buf).length = R.widthtrue :: bufBits R (b :: buf) ++ (List.replicate stack.length true ++ false :: stackWordV stack) = true :: bufBits R (b :: buf) ++ List.replicate stack.length true ++ false :: stackWordV stack All goals completed! 🐙

The growth the state layout's fixed part contributes: the flag, the slot and the sentinel.

def foldGrowthV (R : RankedAlphabet) : := 2 + R.width

The fold's scan at a bitstring carrier.

def foldSemV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (mult : ) : Sem 1 := scanBSem (constAtOf 0 (stateWordV R [], [], true)) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) (wValid_boundMulRaw mult (foldGrowthV R)) (wIndexRoot_boundMulRaw mult (foldGrowthV R))

The expression computes the fold scan's state word on every input.

theorem foldSemV_eq (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult : ) (w : List Bool) : foldSemV R algOf mult ![w] = stateWordV R (foldScanFinal R alg w) := R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List BoolfoldSemV R algOf mult ![w] = stateWordV R (foldScanFinal R alg w) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List BoolList.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) w = stateWordV R (foldScanFinal R alg w) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List BoolList.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) [] = stateWordV R (foldScanFinal R alg [])R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List Bool (head : Bool) (tail : List Bool), List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) tail = stateWordV R (foldScanFinal R alg tail) List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) (head :: tail) = stateWordV R (foldScanFinal R alg (head :: tail)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List BoolList.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) [] = stateWordV R (foldScanFinal R alg []) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List BoolstateWordV R { buf := [], stack := [], live := true } = stateWordV R (foldScanFinal R alg []) All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List Bool (head : Bool) (tail : List Bool), List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) tail = stateWordV R (foldScanFinal R alg tail) List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) (head :: tail) = stateWordV R (foldScanFinal R alg (head :: tail)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List Boolb:Boolv:List Boolih:List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) v = stateWordV R (foldScanFinal R alg v)List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) (b :: v) = stateWordV R (foldScanFinal R alg (b :: v)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List Boolb:Boolv:List Boolih:List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) v = stateWordV R (foldScanFinal R alg v)scanStepWord (foldStepV R algOf false) (foldStepV R algOf true) b (stateWordV R (foldScanFinal R alg v)) = stateWordV R (foldScanFinal R alg (b :: v)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List Boolv:List Boolih:List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) v = stateWordV R (foldScanFinal R alg v)scanStepWord (foldStepV R algOf false) (foldStepV R algOf true) false (stateWordV R (foldScanFinal R alg v)) = stateWordV R (foldScanFinal R alg (false :: v))R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List Boolv:List Boolih:List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) v = stateWordV R (foldScanFinal R alg v)scanStepWord (foldStepV R algOf false) (foldStepV R algOf true) true (stateWordV R (foldScanFinal R alg v)) = stateWordV R (foldScanFinal R alg (true :: v)) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List Boolv:List Boolih:List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) v = stateWordV R (foldScanFinal R alg v)scanStepWord (foldStepV R algOf false) (foldStepV R algOf true) false (stateWordV R (foldScanFinal R alg v)) = stateWordV R (foldScanFinal R alg (false :: v)) All goals completed! 🐙 R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:w:List Boolv:List Boolih:List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true)) (baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) v = stateWordV R (foldScanFinal R alg v)scanStepWord (foldStepV R algOf false) (foldStepV R algOf true) true (stateWordV R (foldScanFinal R alg v)) = stateWordV R (foldScanFinal R alg (true :: v)) All goals completed! 🐙

The recursion bound, under the hypothesis that the pending values stay linear in the input. That hypothesis is what linear space forces of this layout: the state holds every pending value at once. Whether a fold whose values grow faster is excluded from the subalgebra Cobham.SmashFree names outright, rather than from this layout, is not stated here.

theorem length_foldSemV_le (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) (w : List Bool) : (scanBSem (constAtOf 0 (stateWordV R [], [], true)) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) (wValid_boundMulRaw mult (foldGrowthV R)) (wIndexRoot_boundMulRaw mult (foldGrowthV R)) ![w]).length mult * w.length + foldGrowthV R := R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List Bool(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length mult * w.length + foldGrowthV R R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List Boolhstate:(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length = 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length mult * w.length + foldGrowthV R R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List Boolhstate:(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length = 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)hd:(R.scanFinal w).depth w.length(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length mult * w.length + foldGrowthV R R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List Boolhstate:(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length = 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)hd:(R.scanFinal w).depth w.lengthhs:stackSize (foldScanFinal R alg w).stack c * w.length(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length mult * w.length + foldGrowthV R R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List Boolhstate:(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length = 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)hd:(R.scanFinal w).depth w.lengthhs:stackSize (foldScanFinal R alg w).stack c * w.lengthh1:(2 * c + 2) * w.length mult * w.length(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length mult * w.length + foldGrowthV R R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List Boolhstate:(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length = 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)hd:(R.scanFinal w).depth w.lengthhs:stackSize (foldScanFinal R alg w).stack c * w.lengthh1:(2 * c + 2) * w.length mult * w.lengthh2:(2 * c + 2) * w.length = 2 * (c * w.length) + 2 * w.length(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length mult * w.length + foldGrowthV R R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List Boolhstate:(scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false) (foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ![w]).length = 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)hd:(R.scanFinal w).depth w.lengthhs:stackSize (foldScanFinal R alg w).stack c * w.lengthh1:(2 * c + 2) * w.length mult * w.lengthh2:(2 * c + 2) * w.length = 2 * (c * w.length) + 2 * w.length1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth) mult * w.length + (2 + R.width) All goals completed! 🐙

The scan as a member of Cobham.C, at its arity: the form consumers take, foldExprV being its underlying expression.

def foldExprOfV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) : COf 1 := scanMulOf (constAtOf 0 (stateWordV R [], [], true)) (foldStepV R algOf false) (foldStepV R algOf true) mult (foldGrowthV R) (length_foldSemV_le R algOf alg halg mult c hsize hmult)

The fold at a bitstring carrier, as an expression of Cobham's class.

def foldExprV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) : C := (foldExprOfV R algOf alg halg mult c hsize hmult).1

The meaning foldSemV reads at the raw tree is the meaning foldExprV carries.

theorem foldSemV_eq_eval (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) : transport (foldExprOfV R algOf alg halg mult c hsize hmult).2 (foldExprOfV R algOf alg halg mult c hsize hmult).1.eval = foldSemV R algOf mult := rfl

A fixed-width carrier's algebra transported to the bitstring carrier: decode each argument, apply the algebra, and spell the result.

def algOfFixed {α : Type u} {p : } (R : RankedAlphabet) (enc : α Fin p Bool) (dec : (Fin p Bool) α) (alg : (i : Fin R.card) (Fin (R.arity i) α) α) : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool := fun i f List.ofFn (enc (alg i fun d dec (bits p (f d))))

The two fold constructions agree on results. Called at an algebra whose carrier does stay within a fixed width, the bitstring fold computes the encoding of what the fixed-width fold computes, on every input — including the inputs that spell no term, where both are absent.

This is an equality of results only, and it relates the two algebras at the shared semantic layer rather than the two expressions directly; each expression is tied to that layer separately, by foldOutSemV_eq here and by Geb.CobhamFold.foldOutSem_eq for the fixed-width construction. The two differ in cost, though not as a constant-time step against a linear-time one: under the model of § Cost neither construction has constant-time steps, Cobham.casesOf dispatching through Cobham.cond and Cobham.predIterOf iterating Cobham.pred, both boundedRec nodes over the state. What differs is the degree, a fixed-width step being linear in the state where takeEntryOf is cubic.

theorem foldOut_algOfFixed {α : Type u} {p : } (R : RankedAlphabet) (enc : α Fin p Bool) (dec : (Fin p Bool) α) (hdec : a, dec (enc a) = a) (alg : (i : Fin R.card) (Fin (R.arity i) α) α) (w : List Bool) : foldOut R (algOfFixed R enc dec alg) w = (foldOut R alg w).map fun a List.ofFn (enc a) := foldOut_map R alg (algOfFixed R enc dec alg) (fun a List.ofFn (enc a)) (fun i g congrArg (fun h List.ofFn (enc (alg i h))) (funext fun d α:Type up:R:RankedAlphabetenc:α Fin p Booldec:(Fin p Bool) αhdec: (a : α), dec (enc a) = aalg:(i : Fin R.card) (Fin (R.arity i) α) αw:List Booli:Fin R.cardg:Fin (R.arity i) αd:Fin (R.arity i)dec (bits p ((fun d List.ofFn (enc (g d))) d)) = g d All goals completed! 🐙)) w

The readout's output word: a true marker followed by the value, and [false] at no value. The marker separates the two branches, a value being free to be empty.

def outWordV : Option (List Bool) List Bool | none => [false] | some a => true :: a

The number of state bits the readout dispatches on: the flag, the slot, and R.maxArity + 2 count bits. Any count region of two or more bits separates a count of one from a longer one; this width is chosen to exceed the dispatch window's, which is one bit at an alphabet whose symbols are all nullary.

def readoutWidthV (R : RankedAlphabet) : := 1 + R.width + (R.maxArity + 2)

The readout at a bitstring carrier, dispatching on Geb.CobhamFold.readoutWidthV's window: on acceptance the sole stack entry's payload, prefixed with a presence marker, and [false] otherwise.

def readOfV (R : RankedAlphabet) : COf 1 := diagOf (casesOf (readoutWidthV R) fun v if (decodeVAt R (readoutWidthV R) v).live && (decodeVAt R (readoutWidthV R) v).buf.isEmpty && (decodeVAt R (readoutWidthV R) v).depth == 1 then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false])

The state word past the flag, the slot, one pending count and the sentinel is the stack.

theorem drop_stateWordV_succ (R : RankedAlphabet) (s : FoldScan (List Bool)) (h : s.buf.length < R.width) (h1 : s.stack.length = 1) : (stateWordV R s).drop (R.width + 3) = stackWordV s.stack := R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthh1:s.stack.length = 1List.drop (R.width + 3) (stateWordV R s) = stackWordV s.stack R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthh1:s.stack.length = 1hd:List.drop (1 + R.width + 1) (stateWordV R s) = List.replicate (s.stack.length - 1) true ++ false :: stackWordV s.stackList.drop (R.width + 3) (stateWordV R s) = stackWordV s.stack R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthh1:s.stack.length = 1hd:List.drop (1 + R.width + 1) (stateWordV R s) = List.replicate (1 - 1) true ++ false :: stackWordV s.stackList.drop (R.width + 3) (stateWordV R s) = stackWordV s.stack R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthh1:s.stack.length = 1hd:List.drop (1 + R.width + 1) (stateWordV R s) = List.replicate (1 - 1) true ++ false :: stackWordV s.stackhdd:List.drop (R.width + 3) (stateWordV R s) = List.drop 1 (List.drop (1 + R.width + 1) (stateWordV R s))List.drop (R.width + 3) (stateWordV R s) = stackWordV s.stack R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthh1:s.stack.length = 1hd:List.drop (1 + R.width + 1) (stateWordV R s) = List.replicate (1 - 1) true ++ false :: stackWordV s.stackhdd:List.drop (R.width + 3) (stateWordV R s) = List.drop 1 (List.drop (1 + R.width + 1) (stateWordV R s))List.drop 1 (List.replicate (1 - 1) true ++ false :: stackWordV s.stack) = stackWordV s.stack All goals completed! 🐙

The readout's value at a state word.

theorem stepWord_readOfV (R : RankedAlphabet) (s : FoldScan (List Bool)) (h : s.buf.length < R.width) : stepWord (readOfV R) (stateWordV R s) = outWordV (if s.live && s.buf.isEmpty && s.stack.length == 1 then s.stack.head? else none) := R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthstepWord (readOfV R) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthsemAt 2 (casesOf (readoutWidthV R) fun v if ((decodeVAt R (readoutWidthV R) v).live && (decodeVAt R (readoutWidthV R) v).buf.isEmpty && (decodeVAt R (readoutWidthV R) v).depth == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) ![stateWordV R s, stateWordV R s] = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthcasesSem (readoutWidthV R) (fun v if ((decodeVAt R (readoutWidthV R) v).live && (decodeVAt R (readoutWidthV R) v).buf.isEmpty && (decodeVAt R (readoutWidthV R) v).depth == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) ![stateWordV R s, stateWordV R s] = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthstepWord (if ({ buf := s.buf, depth := min s.stack.length (R.maxArity + 2), live := s.live }.live && { buf := s.buf, depth := min s.stack.length (R.maxArity + 2), live := s.live }.buf.isEmpty && { buf := s.buf, depth := min s.stack.length (R.maxArity + 2), live := s.live }.depth == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthstepWord (if (s.live && s.buf.isEmpty && min s.stack.length (R.maxArity + 2) == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)stepWord (if (s.live && s.buf.isEmpty && min s.stack.length (R.maxArity + 2) == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)stepWord (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:(s.live && s.buf.isEmpty && s.stack.length == 1) = truestepWord (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none)R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:¬(s.live && s.buf.isEmpty && s.stack.length == 1) = truestepWord (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:(s.live && s.buf.isEmpty && s.stack.length == 1) = truestepWord (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:(s.live && s.buf.isEmpty && s.stack.length == 1) = true[true] ++ stepWord takeEntryOf (List.drop (R.width + 3) (stateWordV R s)) = outWordV s.stack.head? R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:(s.live && s.buf.isEmpty && s.stack.length == 1) = trueleft✝:(s.live && s.buf.isEmpty) = truehone:(s.stack.length == 1) = true[true] ++ stepWord takeEntryOf (List.drop (R.width + 3) (stateWordV R s)) = outWordV s.stack.head? R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:(s.live && s.buf.isEmpty && s.stack.length == 1) = trueleft✝:(s.live && s.buf.isEmpty) = truehone:(s.stack.length == 1) = trueh1:s.stack.length = 1[true] ++ stepWord takeEntryOf (List.drop (R.width + 3) (stateWordV R s)) = outWordV s.stack.head? R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:(s.live && s.buf.isEmpty && s.stack.length == 1) = trueleft✝:(s.live && s.buf.isEmpty) = truehone:(s.stack.length == 1) = trueh1:s.stack.length = 1hsing: a, s.stack = [a][true] ++ stepWord takeEntryOf (List.drop (R.width + 3) (stateWordV R s)) = outWordV s.stack.head? R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:(s.live && s.buf.isEmpty && s.stack.length == 1) = trueleft✝:(s.live && s.buf.isEmpty) = truehone:(s.stack.length == 1) = trueh1:s.stack.length = 1a:List Boolha:s.stack = [a][true] ++ stepWord takeEntryOf (List.drop (R.width + 3) (stateWordV R s)) = outWordV s.stack.head? R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:(s.live && s.buf.isEmpty && s.stack.length == 1) = trueleft✝:(s.live && s.buf.isEmpty) = truehone:(s.stack.length == 1) = trueh1:s.stack.length = 1a:List Boolha:s.stack = [a][true] ++ a = outWordV [a].head? All goals completed! 🐙 R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:¬(s.live && s.buf.isEmpty && s.stack.length == 1) = truestepWord (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3))) else constAtOf 1 [false]) (stateWordV R s) = outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhmin: (n : ), (min n (R.maxArity + 2) == 1) = (n == 1)hacc:¬(s.live && s.buf.isEmpty && s.stack.length == 1) = true[false] = outWordV none All goals completed! 🐙

The readout composed onto the scan, at its declared arity.

def foldOutOfV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) : COf 1 := comp1Of (readOfV R) (foldExprOfV R algOf alg halg mult c hsize hmult)

The fold at a bitstring carrier, as an expression of Cobham's class.

def foldOutExprV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) : C := (foldOutOfV R algOf alg halg mult c hsize hmult).1

The fold's meaning at its arity, read at the raw tree.

def foldOutSemV (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) : Sem 1 := semAt 1 (foldOutOfV R algOf alg halg mult c hsize hmult).1.1 (foldOutOfV R algOf alg halg mult c hsize hmult).2

The meaning read at the raw tree is the meaning the expression carries.

theorem foldOutSemV_eq_eval (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) : transport (foldOutOfV R algOf alg halg mult c hsize hmult).2 (foldOutOfV R algOf alg halg mult c hsize hmult).1.eval = foldOutSemV R algOf alg halg mult c hsize hmult := rfl

The expression at a bitstring carrier computes the fold: the readout on the scan is Geb.CobhamFold.foldOut, spelled by outWordV. With Geb.CobhamFold.foldOut_eq this is RankedAlphabet.parse followed by the algebra morphism out of the term algebra.

theorem foldOutSemV_eq (R : RankedAlphabet) (algOf : (i : Fin R.card) COf (R.arity i)) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (halg : (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i).1.1 (algOf i).2 f = alg i f) (mult c : ) (hsize : w : List Bool, stackSize (foldScanFinal R alg w).stack c * w.length) (hmult : 2 * c + 2 mult) (w : List Bool) : foldOutSemV R algOf alg halg mult c hsize hmult ![w] = outWordV (foldOut R alg w) := R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List BoolfoldOutSemV R algOf alg halg mult c hsize hmult ![w] = outWordV (foldOut R alg w) R:RankedAlphabetalgOf:(i : Fin R.card) COf (R.arity i)alg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolhalg: (i : Fin R.card) (f : Fin (R.arity i) List Bool), semAt (R.arity i) (algOf i) f = alg i fmult:c:hsize: (w : List Bool), stackSize (foldScanFinal R alg w).stack c * w.lengthhmult:2 * c + 2 multw:List Boolhapply:foldOutSemV R algOf alg halg mult c hsize hmult ![w] = stepWord (readOfV R) (foldSemV R algOf mult ![w])foldOutSemV R algOf alg halg mult c hsize hmult ![w] = outWordV (foldOut R alg w) All goals completed! 🐙

A scaled family's sum is the scaled sum.

private theorem sum_ofFn_mul (c n : ) (g : Fin n ) : (List.ofFn fun d c * g d).sum = c * (List.ofFn g).sum := c:n:g:Fin n (List.ofFn fun d c * g d).sum = c * (List.ofFn g).sum All goals completed! 🐙

Sums of families order pointwise. List.sum_le_sum states this over List.map, but in Mathlib.Algebra.Order.BigOperators.Group.List, outside this module's import closure.

private theorem sum_ofFn_le : (n : ) (g h : Fin n ), ( d, g d h d) (List.ofFn g).sum (List.ofFn h).sum := Nat.rec (fun _ _ _ x✝²:Fin Nat.zero x✝¹:Fin Nat.zero x✝: (d : Fin Nat.zero), x✝² d x✝¹ d(List.ofFn x✝²).sum (List.ofFn x✝¹).sum All goals completed! 🐙) fun n ih g h hgh n:ih: (g h : Fin n ), (∀ (d : Fin n), g d h d) (List.ofFn g).sum (List.ofFn h).sumg:Fin n.succ h:Fin n.succ hgh: (d : Fin n.succ), g d h d(List.ofFn g).sum (List.ofFn h).sum n:ih: (g h : Fin n ), (∀ (d : Fin n), g d h d) (List.ofFn g).sum (List.ofFn h).sumg:Fin n.succ h:Fin n.succ hgh: (d : Fin n.succ), g d h dg 0 + (List.ofFn fun i g i.succ).sum h 0 + (List.ofFn fun i h i.succ).sum All goals completed! 🐙

An algebra that lengthens by at most a constant per symbol folds a term to a value linear in the term's node count. The term-level companion of stackSize_le_of_growth, which derives length_foldSemV_le's hypothesis from the same condition: this states what the condition says about the fold's value, that a fold meeting it is one whose output the class can hold.

theorem length_fold_le_of_growth (R : RankedAlphabet) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (c : ) (hgrow : (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + c) : t : R.Term, (Term.fold R alg t).length c * t.size := Term.induction (motive := fun t (Term.fold R alg t).length c * t.size) fun i ch ih R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + ci:Fin R.cardch:Fin (R.arity i) R.Termih: (d : Fin (R.arity i)), (Term.fold R alg (ch d)).length c * (ch d).size(Term.fold R alg (Term.mk R i ch)).length c * (Term.mk R i ch).size R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + ci:Fin R.cardch:Fin (R.arity i) R.Termih: (d : Fin (R.arity i)), (Term.fold R alg (ch d)).length c * (ch d).size(alg i fun d Term.fold R alg (ch d)).length c * (List.ofFn fun d (ch d).size).sum + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + ci:Fin R.cardch:Fin (R.arity i) R.Termih: (d : Fin (R.arity i)), (Term.fold R alg (ch d)).length c * (ch d).size(List.ofFn fun d (Term.fold R alg (ch d)).length).sum + c c * (List.ofFn fun d (ch d).size).sum + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + ci:Fin R.cardch:Fin (R.arity i) R.Termih: (d : Fin (R.arity i)), (Term.fold R alg (ch d)).length c * (ch d).size(List.ofFn fun d (Term.fold R alg (ch d)).length).sum c * (List.ofFn fun d (ch d).size).sum R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List Boolc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + ci:Fin R.cardch:Fin (R.arity i) R.Termih: (d : Fin (R.arity i)), (Term.fold R alg (ch d)).length c * (ch d).size(List.ofFn fun d c * (ch d).size).sum c * (List.ofFn fun d (ch d).size).sum All goals completed! 🐙

The pending values' total length is additive over a concatenation.

theorem stackSize_append (a b : List (List Bool)) : stackSize (a ++ b) = stackSize a + stackSize b := a:List (List Bool)b:List (List Bool)stackSize (a ++ b) = stackSize a + stackSize b All goals completed! 🐙

The pending values' total length splits at any point.

theorem stackSize_take_add_drop (st : List (List Bool)) (r : ) : stackSize (st.take r) + stackSize (st.drop r) = stackSize st := st:List (List Bool)r:stackSize (List.take r st) + stackSize (List.drop r st) = stackSize st All goals completed! 🐙

The lengths of the first r entries sum to their total length.

private theorem sum_ofFn_getElem : (r : ) (st : List (List Bool)) (h : r st.length), (List.ofFn fun d : Fin r (st[d.val]'(Nat.lt_of_lt_of_le d.isLt h)).length).sum = stackSize (st.take r) := Nat.rec (fun st _ st:List (List Bool)x✝:Nat.zero st.length(List.ofFn fun d st[d].length).sum = stackSize (List.take Nat.zero st) All goals completed! 🐙) fun r ih st h match st with | [] => absurd h (Nat.not_succ_le_zero r) r:ih: (st : List (List Bool)) (h : r st.length), (List.ofFn fun d st[d].length).sum = stackSize (List.take r st)st:List (List Bool)a:List Boolt:List (List Bool)h:r.succ (a :: t).length(List.ofFn fun d (a :: t)[d].length).sum = stackSize (List.take r.succ (a :: t)) r:ih: (st : List (List Bool)) (h : r st.length), (List.ofFn fun d st[d].length).sum = stackSize (List.take r st)st:List (List Bool)a:List Boolt:List (List Bool)h:r.succ (a :: t).length(List.ofFn fun d (a :: t)[d].length).sum = stackSize (List.take r.succ (a :: t)) r:ih: (st : List (List Bool)) (h : r st.length), (List.ofFn fun d st[d].length).sum = stackSize (List.take r st)st:List (List Bool)a:List Boolt:List (List Bool)h:r.succ (a :: t).length(a :: t)[0].length + (List.ofFn fun i (a :: t)[i.succ].length).sum = a.length + stackSize (List.take r t) All goals completed! 🐙

One step raises the potential R.width * stackSize + c * |buf| by at most c, the growth condition assumed only of arguments the stack holds. Geb.CobhamFold.potential_foldScanStep_le is this where the condition holds at arbitrary arguments.

theorem potential_foldScanStep_le_of_invariant (R : RankedAlphabet) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (P : List Bool Prop) (c : ) (hgrow : (i : Fin R.card) (f : Fin (R.arity i) List Bool), ( d, P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + c) (b : Bool) (s : FoldScan (List Bool)) (hs : v s.stack, P v) : R.width * stackSize (foldScanStep R alg b s).stack + c * (foldScanStep R alg b s).buf.length R.width * stackSize s.stack + c * s.buf.length + c := R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Bools:FoldScan (List Bool)hs: v s.stack, P vR.width * stackSize (foldScanStep R alg b s).stack + c * (foldScanStep R alg b s).buf.length R.width * stackSize s.stack + c * s.buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)live:Boolhs: v { buf := buf, stack := stack, live := live }.stack, P vR.width * stackSize (foldScanStep R alg b { buf := buf, stack := stack, live := live }).stack + c * (foldScanStep R alg b { buf := buf, stack := stack, live := live }).buf.length R.width * stackSize { buf := buf, stack := stack, live := live }.stack + c * { buf := buf, stack := stack, live := live }.buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)live:Boolhs: v stack, P vR.width * stackSize (foldScanStep R alg b { buf := buf, stack := stack, live := live }).stack + c * (foldScanStep R alg b { buf := buf, stack := stack, live := live }).buf.length R.width * stackSize { buf := buf, stack := stack, live := live }.stack + c * { buf := buf, stack := stack, live := live }.buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)live:Boolhs: v stack, P vR.width * stackSize (match { buf := buf, stack := stack, live := live }.live with | false => { buf := buf, stack := stack, live := live } | true => if (b :: { buf := buf, stack := stack, live := live }.buf).length = R.width then match symOf R (decodeBits (b :: { buf := buf, stack := stack, live := live }.buf)) with | none => { buf := [], stack := { buf := buf, stack := stack, live := live }.stack, live := false } | some i => if h : R.arity i { buf := buf, stack := stack, live := live }.stack.length then { buf := [], stack := (alg i fun d { buf := buf, stack := stack, live := live }.stack[d]) :: List.drop (R.arity i) { buf := buf, stack := stack, live := live }.stack, live := true } else { buf := [], stack := { buf := buf, stack := stack, live := live }.stack, live := false } else { buf := b :: { buf := buf, stack := stack, live := live }.buf, stack := { buf := buf, stack := stack, live := live }.stack, live := true }).stack + c * (match { buf := buf, stack := stack, live := live }.live with | false => { buf := buf, stack := stack, live := live } | true => if (b :: { buf := buf, stack := stack, live := live }.buf).length = R.width then match symOf R (decodeBits (b :: { buf := buf, stack := stack, live := live }.buf)) with | none => { buf := [], stack := { buf := buf, stack := stack, live := live }.stack, live := false } | some i => if h : R.arity i { buf := buf, stack := stack, live := live }.stack.length then { buf := [], stack := (alg i fun d { buf := buf, stack := stack, live := live }.stack[d]) :: List.drop (R.arity i) { buf := buf, stack := stack, live := live }.stack, live := true } else { buf := [], stack := { buf := buf, stack := stack, live := live }.stack, live := false } else { buf := b :: { buf := buf, stack := stack, live := live }.buf, stack := { buf := buf, stack := stack, live := live }.stack, live := true }).buf.length R.width * stackSize { buf := buf, stack := stack, live := live }.stack + c * { buf := buf, stack := stack, live := live }.buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)live:Boolhs: v stack, P vR.width * stackSize (match live with | false => { buf := buf, stack := stack, live := live } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (match live with | false => { buf := buf, stack := stack, live := live } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vR.width * stackSize (match false with | false => { buf := buf, stack := stack, live := false } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (match false with | false => { buf := buf, stack := stack, live := false } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + cR:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vR.width * stackSize (match true with | false => { buf := buf, stack := stack, live := true } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (match true with | false => { buf := buf, stack := stack, live := true } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vR.width * stackSize (match false with | false => { buf := buf, stack := stack, live := false } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (match false with | false => { buf := buf, stack := stack, live := false } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vR.width * stackSize stack + c * buf.length R.width * stackSize stack + c * buf.length + c All goals completed! 🐙 R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vR.width * stackSize (match true with | false => { buf := buf, stack := stack, live := true } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (match true with | false => { buf := buf, stack := stack, live := true } | true => if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vR.width * stackSize (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthR.width * stackSize (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + cR:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:¬(b :: buf).length = R.widthR.width * stackSize (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthR.width * stackSize (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthR.width * stackSize (match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthR.width * stackSize (match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + c match hsym : symOf R (decodeBits (b :: buf)) with R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthhsym:symOf R (decodeBits (b :: buf)) = noneR.width * stackSize (match none with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (match none with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthhsym:symOf R (decodeBits (b :: buf)) = noneR.width * stackSize stack + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthhsym:symOf R (decodeBits (b :: buf)) = noneR.width * stackSize stack + 0 R.width * stackSize stack + c * buf.length + c All goals completed! 🐙 R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some iR.width * stackSize (match some i with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (match some i with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some iR.width * stackSize (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthR.width * stackSize (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + cR:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:¬R.arity i stack.lengthR.width * stackSize (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthR.width * stackSize (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthR.width * stackSize { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true }.stack + c * { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true }.buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)R.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c -- the popped arguments are members of the stack, so `hs` supplies -- `P` at each R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length (List.ofFn fun d stack[d].length).sum + cR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length stackSize (List.take (R.arity i) stack) + cR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length stackSize (List.take (R.arity i) stack) + chsplit:stackSize (List.take (R.arity i) stack) + stackSize (List.drop (R.arity i) stack) = stackSize stackR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length stackSize (List.take (R.arity i) stack) + chsplit:stackSize (List.take (R.arity i) stack) + stackSize (List.drop (R.arity i) stack) = stackSize stackhnew:stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) stackSize stack + cR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length stackSize (List.take (R.arity i) stack) + chsplit:stackSize (List.take (R.arity i) stack) + stackSize (List.drop (R.arity i) stack) = stackSize stackhnew:stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) stackSize stack + chmul:R.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) R.width * (stackSize stack + c)R.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length stackSize (List.take (R.arity i) stack) + chsplit:stackSize (List.take (R.arity i) stack) + stackSize (List.drop (R.arity i) stack) = stackSize stackhnew:stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) stackSize stack + chmul:R.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) R.width * stackSize stack + R.width * cR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length stackSize (List.take (R.arity i) stack) + chsplit:stackSize (List.take (R.arity i) stack) + stackSize (List.drop (R.arity i) stack) = stackSize stackhnew:stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) stackSize stack + chmul:R.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) R.width * stackSize stack + R.width * chcw:R.width * c = c * R.widthR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length stackSize (List.take (R.arity i) stack) + chsplit:stackSize (List.take (R.arity i) stack) + stackSize (List.drop (R.arity i) stack) = stackSize stackhnew:stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) stackSize stack + chmul:R.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) R.width * stackSize stack + R.width * chcw:R.width * c = c * R.widthhcb:c * buf.length + c = c * R.widthR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:R.arity i stack.lengthhsum:(List.ofFn fun d stack[d].length).sum = stackSize (List.take (R.arity i) stack)halg:(alg i fun d stack[d]).length stackSize (List.take (R.arity i) stack) + chsplit:stackSize (List.take (R.arity i) stack) + stackSize (List.drop (R.arity i) stack) = stackSize stackhnew:stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) stackSize stack + chmul:R.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) R.width * stackSize stack + R.width * chcw:R.width * c = c * R.widthhcb:c * buf.length + c = c * R.widthR.width * stackSize ((alg i fun d stack[d]) :: List.drop (R.arity i) stack) R.width * stackSize stack + c * buf.length + c All goals completed! 🐙 R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:¬R.arity i stack.lengthR.width * stackSize (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).stack + c * (if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:¬R.arity i stack.lengthR.width * stackSize { buf := [], stack := stack, live := false }.stack + c * { buf := [], stack := stack, live := false }.buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:¬R.arity i stack.lengthR.width * stackSize stack + c * [].length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:(b :: buf).length = R.widthhbw:buf.length + 1 = R.widthi:Fin R.cardhsym:symOf R (decodeBits (b :: buf)) = some ihst:¬R.arity i stack.lengthR.width * stackSize stack + 0 R.width * stackSize stack + c * buf.length + c All goals completed! 🐙 R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:¬(b :: buf).length = R.widthR.width * stackSize (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).stack + c * (if (b :: buf).length = R.width then match symOf R (decodeBits (b :: buf)) with | none => { buf := [], stack := stack, live := false } | some i => if h : R.arity i stack.length then { buf := [], stack := (alg i fun d stack[d]) :: List.drop (R.arity i) stack, live := true } else { buf := [], stack := stack, live := false } else { buf := b :: buf, stack := stack, live := true }).buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:¬(b :: buf).length = R.widthR.width * stackSize { buf := b :: buf, stack := stack, live := true }.stack + c * { buf := b :: buf, stack := stack, live := true }.buf.length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:¬(b :: buf).length = R.widthR.width * stackSize stack + c * (b :: buf).length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:¬(b :: buf).length = R.widthhcb:c * (buf.length + 1) = c * buf.length + cR.width * stackSize stack + c * (b :: buf).length R.width * stackSize stack + c * buf.length + c R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolbuf:List Boolstack:List (List Bool)hs: v stack, P vhlen:¬(b :: buf).length = R.widthhcb:c * (buf.length + 1) = c * buf.length + cR.width * stackSize stack + c * (buf.length + 1) R.width * stackSize stack + c * buf.length + c All goals completed! 🐙

One step raises the potential R.width * stackSize + c * |buf| by at most c. Every clause but the completing pop leaves the stack alone, and the pop adds at most c to it while clearing a block worth R.width bits.

theorem potential_foldScanStep_le (R : RankedAlphabet) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (c : ) (hgrow : (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + c) (b : Bool) (s : FoldScan (List Bool)) : R.width * stackSize (foldScanStep R alg b s).stack + c * (foldScanStep R alg b s).buf.length R.width * stackSize s.stack + c * s.buf.length + c := potential_foldScanStep_le_of_invariant R alg (fun _ True) c (fun i f _ hgrow i f) b s fun _ _ trivial

The potential never exceeds c per input bit, the growth condition assumed only of values satisfying P, which Geb.CobhamFold.mem_stack_foldScanFinal carries along the scan. Geb.CobhamFold.potential_foldScanFinal_le is this at the trivial predicate.

theorem potential_foldScanFinal_le_of_invariant (R : RankedAlphabet) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (P : List Bool Prop) (c : ) (hpush : (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)) (hgrow : (i : Fin R.card) (f : Fin (R.arity i) List Bool), ( d, P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + c) : w : List Bool, R.width * stackSize (foldScanFinal R alg w).stack + c * (foldScanFinal R alg w).buf.length c * w.length := List.rec (R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cR.width * stackSize (foldScanFinal R alg []).stack + c * (foldScanFinal R alg []).buf.length c * [].length R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cR.width * stackSize (foldScanFinal R alg []).stack + c * (foldScanFinal R alg []).buf.length 0 All goals completed! 🐙) fun b v ih R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolv:List Boolih:R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length c * v.lengthR.width * stackSize (foldScanFinal R alg (b :: v)).stack + c * (foldScanFinal R alg (b :: v)).buf.length c * (b :: v).length R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolv:List Boolih:R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length c * v.lengthhstep:R.width * stackSize (foldScanStep R alg b (foldScanFinal R alg v)).stack + c * (foldScanStep R alg b (foldScanFinal R alg v)).buf.length R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length + cR.width * stackSize (foldScanFinal R alg (b :: v)).stack + c * (foldScanFinal R alg (b :: v)).buf.length c * (b :: v).length R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolv:List Boolih:R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length c * v.lengthhstep:R.width * stackSize (foldScanStep R alg b (foldScanFinal R alg v)).stack + c * (foldScanStep R alg b (foldScanFinal R alg v)).buf.length R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length + chcons:foldScanFinal R alg (b :: v) = foldScanStep R alg b (foldScanFinal R alg v)R.width * stackSize (foldScanFinal R alg (b :: v)).stack + c * (foldScanFinal R alg (b :: v)).buf.length c * (b :: v).length R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolv:List Boolih:R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length c * v.lengthhstep:R.width * stackSize (foldScanStep R alg b (foldScanFinal R alg v)).stack + c * (foldScanStep R alg b (foldScanFinal R alg v)).buf.length R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length + chcons:foldScanFinal R alg (b :: v) = foldScanStep R alg b (foldScanFinal R alg v)hc:c * (v.length + 1) = c * v.length + cR.width * stackSize (foldScanFinal R alg (b :: v)).stack + c * (foldScanFinal R alg (b :: v)).buf.length c * (b :: v).length R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cb:Boolv:List Boolih:R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length c * v.lengthhstep:R.width * stackSize (foldScanStep R alg b (foldScanFinal R alg v)).stack + c * (foldScanStep R alg b (foldScanFinal R alg v)).buf.length R.width * stackSize (foldScanFinal R alg v).stack + c * (foldScanFinal R alg v).buf.length + chcons:foldScanFinal R alg (b :: v) = foldScanStep R alg b (foldScanFinal R alg v)hc:c * (v.length + 1) = c * v.length + cR.width * stackSize (foldScanStep R alg b (foldScanFinal R alg v)).stack + c * (foldScanStep R alg b (foldScanFinal R alg v)).buf.length c * (v.length + 1) All goals completed! 🐙

An algebra whose values satisfy an invariant under which it lengthens by at most a constant per symbol keeps the pending values linear in the input. Geb.CobhamFold.stackSize_le_of_growth is this at the trivial invariant.

theorem stackSize_le_of_growth_of_invariant (R : RankedAlphabet) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (P : List Bool Prop) (c : ) (hpush : (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)) (hgrow : (i : Fin R.card) (f : Fin (R.arity i) List Bool), ( d, P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + c) (w : List Bool) : stackSize (foldScanFinal R alg w).stack c * w.length := R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cw:List BoolstackSize (foldScanFinal R alg w).stack c * w.length R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cw:List Boolh:R.width * stackSize (foldScanFinal R alg w).stack + c * (foldScanFinal R alg w).buf.length c * w.lengthstackSize (foldScanFinal R alg w).stack c * w.length R:RankedAlphabetalg:(i : Fin R.card) (Fin (R.arity i) List Bool) List BoolP:List Bool Propc:hpush: (i : Fin R.card) (f : Fin (R.arity i) List Bool), P (alg i f)hgrow: (i : Fin R.card) (f : Fin (R.arity i) List Bool), (∀ (d : Fin (R.arity i)), P (f d)) (alg i f).length (List.ofFn fun d (f d).length).sum + cw:List Boolh:R.width * stackSize (foldScanFinal R alg w).stack + c * (foldScanFinal R alg w).buf.length c * w.lengthhm:stackSize (foldScanFinal R alg w).stack R.width * stackSize (foldScanFinal R alg w).stackstackSize (foldScanFinal R alg w).stack c * w.length All goals completed! 🐙

The potential never exceeds c per input bit.

theorem potential_foldScanFinal_le (R : RankedAlphabet) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (c : ) (hgrow : (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + c) : w : List Bool, R.width * stackSize (foldScanFinal R alg w).stack + c * (foldScanFinal R alg w).buf.length c * w.length := potential_foldScanFinal_le_of_invariant R alg (fun _ True) c (fun _ _ trivial) fun i f _ hgrow i f

An algebra that lengthens by at most a constant per symbol keeps the pending values linear in the input, which is the hypothesis Geb.CobhamFold.length_foldSemV_le takes. This is the bridge from a condition on the algebra alone to the condition the recursion bound consumes.

theorem stackSize_le_of_growth (R : RankedAlphabet) (alg : (i : Fin R.card) (Fin (R.arity i) List Bool) List Bool) (c : ) (hgrow : (i : Fin R.card) (f : Fin (R.arity i) List Bool), (alg i f).length (List.ofFn fun d (f d).length).sum + c) (w : List Bool) : stackSize (foldScanFinal R alg w).stack c * w.length := stackSize_le_of_growth_of_invariant R alg (fun _ True) c (fun _ _ trivial) (fun i f _ hgrow i f) w
end Geb.CobhamFoldend