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.RankedTreeThe 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 uThe 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 entryWordThe empty stack's layout.
@[simp] theorem stackWordV_nil : stackWordV [] = [] := rflThe 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 := rflThe total length of the pending values.
def stackSize (st : List (List Bool)) : ℕ := st.flatten.lengthThe empty stack's values are empty.
@[simp] theorem stackSize_nil : stackSize [] = 0 := rflThe 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 ↦ by 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
rw [stackWordV_cons, a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length⊢ (entryWord a ++ stackWordV t).length = 2 * stackSize (a :: t) + (a :: t).length List.length_append, a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length⊢ (entryWord a).length + (stackWordV t).length = 2 * stackSize (a :: t) + (a :: t).length length_entryWord, a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length⊢ 2 * a.length + 1 + (stackWordV t).length = 2 * stackSize (a :: t) + (a :: t).length ih, a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length⊢ 2 * a.length + 1 + (2 * stackSize t + t.length) = 2 * stackSize (a :: t) + (a :: t).length stackSize_cons, a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length⊢ 2 * a.length + 1 + (2 * stackSize t + t.length) = 2 * (a.length + stackSize t) + (a :: t).length
List.length_cons a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length⊢ 2 * a.length + 1 + (2 * stackSize t + t.length) = 2 * (a.length + stackSize t) + (t.length + 1)] a:List Boolt:List (List Bool)ih:(stackWordV t).length = 2 * stackSize t + t.length⊢ 2 * a.length + 1 + (2 * stackSize t + t.length) = 2 * (a.length + stackSize t) + (t.length + 1)
omega 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.stackThe 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) := by 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)
have hd : (toScan s).depth = s.stack.length := rfl 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)
rw [stateWordV, R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length⊢ (stateWord R (toScan s) ++ false :: stackWordV s.stack).length =
1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length) List.length_append, R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length⊢ (stateWord R (toScan s)).length + (false :: stackWordV s.stack).length =
1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length) length_stateWord_of_lt R (toScan s) h, R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length⊢ 1 + R.width + (toScan s).depth + (false :: stackWordV s.stack).length =
1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length)
List.length_cons, R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length⊢ 1 + R.width + (toScan s).depth + ((stackWordV s.stack).length + 1) =
1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length) length_stackWordV, R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length⊢ 1 + R.width + (toScan s).depth + (2 * stackSize s.stack + s.stack.length + 1) =
1 + R.width + s.stack.length + 1 + (2 * stackSize s.stack + s.stack.length) hd R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length⊢ 1 + 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)] R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthhd:(toScan s).depth = s.stack.length⊢ 1 + 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)
omega 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 ↦ by st:List (List Bool)⊢ stepWord (dropEntriesOf Nat.zero) (stackWordV st) = stackWordV (List.drop Nat.zero st) rw [dropEntriesOf_zero, st:List (List Bool)⊢ stepWord idOf (stackWordV st) = stackWordV (List.drop Nat.zero st) stepWord_idOf, st:List (List Bool)⊢ stackWordV st = stackWordV (List.drop Nat.zero st) List.drop_zero st:List (List Bool)⊢ stackWordV st = stackWordV st] All goals completed! 🐙)
fun k ih st ↦ by 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)
rw [stepWord_dropEntriesOf_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 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 [])
rw [List.drop_nil 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 []] 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 []
exact (ih []).trans (congrArg stackWordV List.drop_nil) All goals completed! 🐙
| a :: t => 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))
rw [stackWordV_cons, 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 ![entryWord a ++ stackWordV t]) = stackWordV (List.drop k.succ (a :: t)) dropEntrySem_entryWord, 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) (stackWordV t) = stackWordV (List.drop k.succ (a :: t)) ih t, 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)⊢ stackWordV (List.drop k t) = stackWordV (List.drop k.succ (a :: t)) List.drop_succ_cons 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)⊢ stackWordV (List.drop k t) = stackWordV (List.drop k 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 [] := by j:ℕst:List (List Bool)⊢ stepWord (entryOf j) (stackWordV st) = (List.drop j st).headD []
rw [stepWord_entryOf, j:ℕst:List (List Bool)⊢ takeEntrySem ![stepWord (dropEntriesOf j) (stackWordV st)] = (List.drop j st).headD [] stepWord_dropEntriesOf_stackWordV j:ℕst:List (List Bool)⊢ takeEntrySem ![stackWordV (List.drop j 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 [] rw [stackWordV_nil j:ℕst:List (List Bool)hd:List.drop j st = []⊢ takeEntrySem ![[]] = [].headD []] j:ℕst:List (List Bool)hd:List.drop j st = []⊢ takeEntrySem ![[]] = [].headD []; rfl All goals completed! 🐙
| a :: t => j:ℕst:List (List Bool)a:List Boolt:List (List Bool)hd:List.drop j st = a :: t⊢ takeEntrySem ![stackWordV (a :: t)] = (a :: t).headD [] rw [stackWordV_cons, j:ℕst:List (List Bool)a:List Boolt:List (List Bool)hd:List.drop j st = a :: t⊢ takeEntrySem ![entryWord a ++ stackWordV t] = (a :: t).headD [] takeEntrySem_entryWord j:ℕst:List (List Bool)a:List Boolt:List (List Bool)hd:List.drop j st = a :: t⊢ a = (a :: t).headD []] j:ℕst:List (List Bool)a:List Boolt:List (List Bool)hd:List.drop j st = a :: t⊢ a = (a :: t).headD []; rfl 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 _ ↦ by st:List (List Bool)rest:List Boolx✝:Nat.zero ≤ st.length⊢ stepWord (dropEntriesOf Nat.zero) (stackWordV st ++ rest) = stackWordV (List.drop Nat.zero st) ++ rest rw [dropEntriesOf_zero, st:List (List Bool)rest:List Boolx✝:Nat.zero ≤ st.length⊢ stepWord idOf (stackWordV st ++ rest) = stackWordV (List.drop Nat.zero st) ++ rest stepWord_idOf, st:List (List Bool)rest:List Boolx✝:Nat.zero ≤ st.length⊢ stackWordV st ++ rest = stackWordV (List.drop Nat.zero st) ++ rest
List.drop_zero st:List (List Bool)rest:List Boolx✝:Nat.zero ≤ st.length⊢ stackWordV st ++ rest = stackWordV st ++ rest] All goals completed! 🐙)
fun k ih st rest h ↦ match st with
| [] => absurd h (Nat.not_succ_le_zero k)
| a :: t => 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).length⊢ stepWord (dropEntriesOf k.succ) (stackWordV (a :: t) ++ rest) = stackWordV (List.drop k.succ (a :: t)) ++ rest by 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).length⊢ stepWord (dropEntriesOf k.succ) (stackWordV (a :: t) ++ rest) = stackWordV (List.drop k.succ (a :: t)) ++ rest
rw [stackWordV_cons, 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).length⊢ stepWord (dropEntriesOf k.succ) (entryWord a ++ stackWordV t ++ rest) = stackWordV (List.drop k.succ (a :: t)) ++ rest List.append_assoc, 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).length⊢ stepWord (dropEntriesOf k.succ) (entryWord a ++ (stackWordV t ++ rest)) = stackWordV (List.drop k.succ (a :: t)) ++ rest stepWord_dropEntriesOf_succ, 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).length⊢ stepWord (dropEntriesOf k) (dropEntrySem ![entryWord a ++ (stackWordV t ++ rest)]) =
stackWordV (List.drop k.succ (a :: t)) ++ rest
dropEntrySem_entryWord, 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).length⊢ stepWord (dropEntriesOf k) (stackWordV t ++ rest) = stackWordV (List.drop k.succ (a :: t)) ++ rest ih t rest (Nat.le_of_succ_le_succ h), 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).length⊢ stackWordV (List.drop k t) ++ rest = stackWordV (List.drop k.succ (a :: t)) ++ rest
List.drop_succ_cons 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).length⊢ stackWordV (List.drop k t) ++ rest = stackWordV (List.drop k 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] := by j:ℕst:List (List Bool)rest:List Boolh:j < st.length⊢ stepWord (entryOf j) (stackWordV st ++ rest) = st[j]
rw [stepWord_entryOf, j:ℕst:List (List Bool)rest:List Boolh:j < st.length⊢ takeEntrySem ![stepWord (dropEntriesOf j) (stackWordV st ++ rest)] = st[j]
stepWord_dropEntriesOf_stackWordV_append j st rest (Nat.le_of_lt h), j:ℕst:List (List Bool)rest:List Boolh:j < st.length⊢ takeEntrySem ![stackWordV (List.drop j st) ++ rest] = st[j]
List.drop_eq_getElem_cons h, j:ℕst:List (List Bool)rest:List Boolh:j < st.length⊢ takeEntrySem ![stackWordV (st[j] :: List.drop (j + 1) st) ++ rest] = st[j] stackWordV_cons, j:ℕst:List (List Bool)rest:List Boolh:j < st.length⊢ takeEntrySem ![entryWord st[j] ++ stackWordV (List.drop (j + 1) st) ++ rest] = st[j] List.append_assoc, j:ℕst:List (List Bool)rest:List Boolh:j < st.length⊢ takeEntrySem ![entryWord st[j] ++ (stackWordV (List.drop (j + 1) st) ++ rest)] = st[j]
takeEntrySem_entryWord j:ℕst:List (List Bool)rest:List Boolh:j < st.length⊢ st[j] = 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 ↦ by 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
rw [List.take_zero, Z:List Boolk:ℕp:ℕ⊢ List.takeWhile id ([] ++ List.replicate p false) = List.replicate (min Nat.zero k) true List.nil_append, Z:List Boolk:ℕp:ℕ⊢ List.takeWhile id (List.replicate p false) = List.replicate (min Nat.zero k) true Nat.zero_min, Z:List Boolk:ℕp:ℕ⊢ List.takeWhile id (List.replicate p false) = List.replicate 0 true List.replicate_zero Z:List Boolk:ℕp:ℕ⊢ List.takeWhile id (List.replicate p false) = []] Z:List Boolk:ℕp:ℕ⊢ List.takeWhile id (List.replicate p false) = []
match p with
| 0 => Z:List Boolk:ℕp:ℕ⊢ List.takeWhile id (List.replicate 0 false) = [] rfl All goals completed! 🐙
| _ + 1 => Z:List Boolk:ℕp:ℕn✝:ℕ⊢ List.takeWhile id (List.replicate (n✝ + 1) false) = [] rfl All goals completed! 🐙)
fun m ih k p ↦ match k with
| 0 => 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 by 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
rw [List.replicate_zero, 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 ([] ++ false :: Z) ++ List.replicate p false) = List.replicate (min m.succ 0) true List.nil_append, 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 (false :: Z) ++ List.replicate p false) = List.replicate (min m.succ 0) true List.take_succ_cons, 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) = List.replicate (min m.succ 0) true
List.cons_append, 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)) = List.replicate (min m.succ 0) true Nat.min_zero, 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)) = List.replicate 0 true List.replicate_zero 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)) = []] 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)) = []
rfl All goals completed! 🐙
| k + 1 => 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 by 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
rw [List.replicate_succ, 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 (true :: List.replicate k true ++ false :: Z) ++ List.replicate p false) =
List.replicate (min m.succ (k + 1)) true List.cons_append, 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 (true :: (List.replicate k true ++ false :: Z)) ++ List.replicate p false) =
List.replicate (min m.succ (k + 1)) true List.take_succ_cons, 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) =
List.replicate (min m.succ (k + 1)) true
List.cons_append, 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)) =
List.replicate (min m.succ (k + 1)) true Nat.succ_min_succ, 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)) =
List.replicate (min m k).succ true List.replicate_succ 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] 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
exact congrArg (fun t ↦ true :: t) (ih k p) 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)) := by R:RankedAlphabets:FoldScan (List Bool)n:ℕm:ℕhn:n = 1 + R.width + mh:s.buf.length < R.width⊢ 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))
have hbuf : (bufBits R s.buf).length = R.width := length_bufBits_of_lt R s.buf h R:RankedAlphabets:FoldScan (List Bool)n:ℕm:ℕhn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.width⊢ 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))
have hdw : n = (bufBits R s.buf).length + m + 1 := by
rw [hbuf, R:RankedAlphabets:FoldScan (List Bool)n:ℕm:ℕhn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.width⊢ n = R.width + m + 1 hn R:RankedAlphabets:FoldScan (List Bool)n:ℕm:ℕhn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.width⊢ 1 + R.width + m = R.width + m + 1] R:RankedAlphabets:FoldScan (List Bool)n:ℕm:ℕhn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.width⊢ 1 + R.width + m = R.width + m + 1
omega 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 + 1⊢ 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))
have hcons : stateWordV R s =
s.live :: (bufBits R s.buf ++
(List.replicate s.stack.length true ++ false :: stackWordV s.stack)) := by
rw [stateWordV, 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 + 1⊢ stateWord R (toScan s) ++ false :: stackWordV s.stack =
s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack)) stateWord, 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 + 1⊢ (toScan s).live :: bufBits R (toScan s).buf ++ List.replicate (toScan s).depth true ++ false :: stackWordV s.stack =
s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack)) toScan 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 + 1⊢ { buf := s.buf, depth := s.stack.length, live := s.live }.live ::
bufBits R { buf := s.buf, depth := s.stack.length, live := s.live }.buf ++
List.replicate { buf := s.buf, depth := s.stack.length, live := s.live }.depth true ++
false :: stackWordV s.stack =
s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))] 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 + 1⊢ { buf := s.buf, depth := s.stack.length, live := s.live }.live ::
bufBits R { buf := s.buf, depth := s.stack.length, live := s.live }.buf ++
List.replicate { buf := s.buf, depth := s.stack.length, live := s.live }.depth true ++
false :: stackWordV s.stack =
s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))
dsimp only 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 + 1⊢ s.live :: bufBits R s.buf ++ List.replicate s.stack.length true ++ false :: stackWordV s.stack =
s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))
simp only [List.cons_append, List.append_assoc] 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))
rw [ofFn_bits, 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.take n (stateWordV R s) ++ List.replicate (n - (stateWordV R s).length) false =
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)) hcons, 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.take n (s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))) ++
List.replicate
(n - (s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false =
s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate
(n -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false)) hdw, 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.take ((bufBits R s.buf).length + m + 1)
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false =
s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false)) List.take_succ_cons, 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))⊢ s.live ::
List.take ((bufBits R s.buf).length + m)
(bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack)) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false =
s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false)) List.take_length_add_append, 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))⊢ s.live :: (bufBits R s.buf ++ List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack)) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false =
s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false))
List.cons_append, 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))⊢ s.live ::
(bufBits R s.buf ++ List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false) =
s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false)) List.append_assoc, 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))⊢ s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false)) =
s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate
((bufBits R s.buf).length + m + 1 -
(s.live :: (bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))).length)
false)) ← hcons 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))⊢ s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate ((bufBits R s.buf).length + m + 1 - (stateWordV R s).length) false)) =
s.live ::
(bufBits R s.buf ++
(List.take m (List.replicate s.stack.length true ++ false :: stackWordV s.stack) ++
List.replicate ((bufBits R s.buf).length + m + 1 - (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⟩ := by R:RankedAlphabets:FoldScan (List Bool)n:ℕm:ℕhn:n = 1 + R.width + mh:s.buf.length < R.width⊢ decodeVAt R n (bits n (stateWordV R s)) = { buf := s.buf, depth := min s.stack.length m, live := s.live }
have hbuf : (bufBits R s.buf).length = R.width := length_bufBits_of_lt R s.buf h R:RankedAlphabets:FoldScan (List Bool)n:ℕm:ℕhn:n = 1 + R.width + mh:s.buf.length < R.widthhbuf:(bufBits R s.buf).length = R.width⊢ decodeVAt R n (bits n (stateWordV R s)) = { buf := s.buf, depth := min s.stack.length m, live := s.live }
have hword := ofFn_bits_stateWordV R s n m hn h 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 }
refine Scan.ext ?_ ?_ ?_ refine_1 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 }.bufrefine_2 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 }.depthrefine_3 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
· refine_1 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 rw [decodeVAt, refine_1 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 (List.ofFn (bits n (stateWordV R s))).tail)).tail,
depth := (List.takeWhile id (List.drop R.width (List.ofFn (bits n (stateWordV R s))).tail)).length,
live := (List.ofFn (bits n (stateWordV R s))).headD false }.buf =
{ buf := s.buf, depth := min s.stack.length m, live := s.live }.buf hword, refine_1 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
(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))).tail)).tail,
depth :=
(List.takeWhile id
(List.drop R.width
(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))).tail)).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 List.tail_cons, refine_1 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 :=
(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 List.take_left' hbuf, refine_1 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) (bufBits R 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 dropWhile_bufBits refine_1 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] refine_1 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
rfl All goals completed! 🐙
· refine_2 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 rw [decodeVAt, refine_2 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 (List.ofFn (bits n (stateWordV R s))).tail)).tail,
depth := (List.takeWhile id (List.drop R.width (List.ofFn (bits n (stateWordV R s))).tail)).length,
live := (List.ofFn (bits n (stateWordV R s))).headD false }.depth =
{ buf := s.buf, depth := min s.stack.length m, live := s.live }.depth hword, refine_2 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
(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))).tail)).tail,
depth :=
(List.takeWhile id
(List.drop R.width
(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))).tail)).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 List.tail_cons, refine_2 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 :=
(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 }.depth =
{ buf := s.buf, depth := min s.stack.length m, live := s.live }.depth List.drop_left' hbuf, refine_2 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 :=
(List.takeWhile id
(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 }.depth =
{ buf := s.buf, depth := min s.stack.length m, live := s.live }.depth
takeWhile_id_take_replicate, refine_2 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 := (List.replicate (min m s.stack.length) true).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 List.length_replicate refine_2 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] refine_2 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
exact Nat.min_comm _ _ All goals completed! 🐙
· refine_3 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 rw [decodeVAt, refine_3 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 (List.ofFn (bits n (stateWordV R s))).tail)).tail,
depth := (List.takeWhile id (List.drop R.width (List.ofFn (bits n (stateWordV R s))).tail)).length,
live := (List.ofFn (bits n (stateWordV R s))).headD false }.live =
{ buf := s.buf, depth := min s.stack.length m, live := s.live }.live hword, refine_3 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
(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))).tail)).tail,
depth :=
(List.takeWhile id
(List.drop R.width
(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))).tail)).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 }.live =
{ buf := s.buf, depth := min s.stack.length m, live := s.live }.live List.headD_cons refine_3 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
(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))).tail)).tail,
depth :=
(List.takeWhile id
(List.drop R.width
(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))).tail)).length,
live := s.live }.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)
(by R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ dispatchWidth R = 1 + R.width + (R.maxArity + 1) rw [dispatchWidth R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ R.width + R.maxArity + 2 = 1 + R.width + (R.maxArity + 1)] R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ R.width + R.maxArity + 2 = 1 + R.width + (R.maxArity + 1); omega All goals completed! 🐙) hThe self-delimiting spelling, as an expression of arity one.
def entryWordOf : COf 1 := concatCompOf 1 (prependOf [false] idOf) unaryOfThe spelling expression's value at a step.
theorem stepWord_entryWordOf (u : List Bool) :
stepWord entryWordOf u = entryWord u := by u:List Bool⊢ stepWord entryWordOf u = entryWord u
rw [entryWordOf, u:List Bool⊢ stepWord (concatCompOf 1 (prependOf [false] idOf) unaryOf) u = entryWord u stepWord_concatCompOf, u:List Bool⊢ stepWord unaryOf u ++ stepWord (prependOf [false] idOf) u = entryWord u stepWord_unaryOf, u:List Bool⊢ unarySem ![u] ++ stepWord (prependOf [false] idOf) u = entryWord u unarySem_eq, u:List Bool⊢ List.replicate u.length true ++ stepWord (prependOf [false] idOf) u = entryWord u
stepWord_prependOf, u:List Bool⊢ List.replicate u.length true ++ ([false] ++ stepWord idOf u) = entryWord u stepWord_idOf, u:List Bool⊢ List.replicate u.length true ++ ([false] ++ u) = entryWord u entryWord u:List Bool⊢ List.replicate u.length true ++ ([false] ++ u) = List.replicate u.length true ++ false :: u] u:List Bool⊢ List.replicate u.length true ++ ([false] ++ u) = List.replicate u.length true ++ false :: u
rfl All goals completed! 🐙The algebra's operation applied to the entries the stack holds.
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 _ uThe 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 := by r:ℕalgI:COf ru:List Bool⊢ stepWord (newStackOf algI) u = entryWord (stepWord (applyAlgOf algI) u) ++ stepWord (dropEntriesOf r) u
rw [newStackOf, r:ℕalgI:COf ru:List Bool⊢ stepWord (concatCompOf 1 (dropEntriesOf r) (comp1Of entryWordOf (applyAlgOf algI))) u =
entryWord (stepWord (applyAlgOf algI) u) ++ stepWord (dropEntriesOf r) u stepWord_concatCompOf, r:ℕalgI:COf ru:List Bool⊢ stepWord (comp1Of entryWordOf (applyAlgOf algI)) u ++ stepWord (dropEntriesOf r) u =
entryWord (stepWord (applyAlgOf algI) u) ++ stepWord (dropEntriesOf r) u stepWord_comp1Of, r:ℕalgI:COf ru:List Bool⊢ stepWord entryWordOf (stepWord (applyAlgOf algI) u) ++ stepWord (dropEntriesOf r) u =
entryWord (stepWord (applyAlgOf algI) u) ++ stepWord (dropEntriesOf r) u stepWord_entryWordOf r:ℕalgI:COf ru:List Bool⊢ entryWord (stepWord (applyAlgOf algI) u) ++ stepWord (dropEntriesOf r) 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))
takeUnaryOfThe 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]) := by r:ℕalgI:COf rz:List Bool⊢ stepWord (rebuildOf algI) z = takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z])
rw [rebuildOf, r:ℕalgI:COf rz:List Bool⊢ stepWord (concatCompOf 1 (prependOf [false] (comp1Of (newStackOf algI) dropUnaryOf)) takeUnaryOf) z =
takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z]) stepWord_concatCompOf, r:ℕalgI:COf rz:List Bool⊢ stepWord takeUnaryOf z ++ stepWord (prependOf [false] (comp1Of (newStackOf algI) dropUnaryOf)) z =
takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z]) stepWord_takeUnaryOf, r:ℕalgI:COf rz:List Bool⊢ takeUnarySem ![z] ++ stepWord (prependOf [false] (comp1Of (newStackOf algI) dropUnaryOf)) z =
takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z]) stepWord_prependOf, r:ℕalgI:COf rz:List Bool⊢ takeUnarySem ![z] ++ ([false] ++ stepWord (comp1Of (newStackOf algI) dropUnaryOf) z) =
takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z])
stepWord_comp1Of, r:ℕalgI:COf rz:List Bool⊢ takeUnarySem ![z] ++ ([false] ++ stepWord (newStackOf algI) (stepWord dropUnaryOf z)) =
takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z]) stepWord_dropUnaryOf r:ℕalgI:COf rz:List Bool⊢ takeUnarySem ![z] ++ ([false] ++ stepWord (newStackOf algI) (dropUnarySem ![z])) =
takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z])] r:ℕalgI:COf rz:List Bool⊢ takeUnarySem ![z] ++ ([false] ++ stepWord (newStackOf algI) (dropUnarySem ![z])) =
takeUnarySem ![z] ++ false :: stepWord (newStackOf algI) (dropUnarySem ![z])
rfl 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 := by R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthk:ℕhk:k ≤ s.stack.length⊢ List.drop (1 + R.width + k) (stateWordV R s) = List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack
have hpre : (s.live :: bufBits R s.buf).length = 1 + R.width := by
rw [List.length_cons, R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthk:ℕhk:k ≤ s.stack.length⊢ (bufBits R s.buf).length + 1 = 1 + R.width length_bufBits_of_lt R s.buf h R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthk:ℕhk:k ≤ s.stack.length⊢ R.width + 1 = 1 + R.width] R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthk:ℕhk:k ≤ s.stack.length⊢ R.width + 1 = 1 + R.width
omega 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.width⊢ List.drop (1 + R.width + k) (stateWordV R s) = List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack
have hsplit : List.replicate s.stack.length true =
List.replicate k true ++ List.replicate (s.stack.length - k) true := by
rw [← List.replicate_add 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.width⊢ List.replicate s.stack.length true = List.replicate (k + (s.stack.length - k)) true] 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.width⊢ List.replicate s.stack.length true = List.replicate (k + (s.stack.length - k)) true
exact congrArg (fun j ↦ List.replicate j true) (by 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.width⊢ s.stack.length = k + (s.stack.length - k) omega All goals completed! 🐙) 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) true⊢ List.drop (1 + R.width + k) (stateWordV R s) = List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack
have hcons : stateWordV R s =
(s.live :: bufBits R s.buf) ++
(List.replicate s.stack.length true ++ false :: stackWordV s.stack) := by
rw [stateWordV, 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) true⊢ stateWord R (toScan s) ++ false :: stackWordV s.stack =
s.live :: bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack) stateWord, 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) true⊢ (toScan s).live :: bufBits R (toScan s).buf ++ List.replicate (toScan s).depth true ++ false :: stackWordV s.stack =
s.live :: bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack) toScan 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) true⊢ { buf := s.buf, depth := s.stack.length, live := s.live }.live ::
bufBits R { buf := s.buf, depth := s.stack.length, live := s.live }.buf ++
List.replicate { buf := s.buf, depth := s.stack.length, live := s.live }.depth true ++
false :: stackWordV s.stack =
s.live :: bufBits R s.buf ++ (List.replicate s.stack.length 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) true⊢ { buf := s.buf, depth := s.stack.length, live := s.live }.live ::
bufBits R { buf := s.buf, depth := s.stack.length, live := s.live }.buf ++
List.replicate { buf := s.buf, depth := s.stack.length, live := s.live }.depth true ++
false :: stackWordV s.stack =
s.live :: bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack)
dsimp only 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) true⊢ s.live :: bufBits R s.buf ++ List.replicate s.stack.length true ++ false :: stackWordV s.stack =
s.live :: bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack)
simp only [List.append_assoc] 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
rw [← List.drop_drop, 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 k (List.drop (1 + R.width) (stateWordV R s)) =
List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack hcons, 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 k
(List.drop (1 + R.width)
(s.live :: bufBits R s.buf ++ (List.replicate s.stack.length true ++ false :: stackWordV s.stack))) =
List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack List.drop_left' hpre, 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 k (List.replicate s.stack.length true ++ false :: stackWordV s.stack) =
List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack hsplit, 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 k (List.replicate k true ++ List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack) =
List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack List.append_assoc, 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 k (List.replicate k true ++ (List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack)) =
List.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack
List.drop_left' (List.length_replicate (n := k) (a := true)) 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.replicate (s.stack.length - k) true ++ false :: stackWordV s.stack =
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) := by R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.width⊢ stepWord (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)
rw [foldStepV, R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.width⊢ stepWord (diagOf (casesOf (dispatchWidth R) fun v ↦ branchV R algOf b (decodeState R v))) (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) stepWord_diagOf R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.width⊢ semAt 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.width⊢ semAt 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)
change casesSem (dispatchWidth R) _ ![stateWordV R s, stateWordV R s] = _ R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.width⊢ casesSem (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)
rw [casesSem_eq, R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.width⊢ stepWord (branchV R algOf b (decodeState R (bits (dispatchWidth R) (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) decodeState_stateWordV R s h R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Bools:FoldScan (List Bool)h:s.buf.length < R.width⊢ stepWord (branchV R algOf b { buf := s.buf, depth := min s.stack.length (R.maxArity + 1), live := s.live })
(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 := by R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Boolt:Scan⊢ branchV R algOf b { buf := t.buf, depth := min t.depth (R.maxArity + 1), live := t.live } = branchV R algOf b t
obtain ⟨buf, depth, live⟩ := t R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Boolbuf:List Booldepth:ℕlive:Bool⊢ branchV 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 }
rw [branchV, 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))) =
branchV R algOf b { buf := buf, depth := depth, live := live } branchV 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
{ 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))
dsimp only 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))
cases live false 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))true 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))
· false 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)) rfl All goals completed! 🐙
· true 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)) dsimp only true 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))
by_cases hlen : (b :: buf).length = R.width pos 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))neg 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))
· pos 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)) rw [ite_eq_left hlen, pos 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))) =
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)) ite_eq_left hlen pos 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))] pos 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
| none => 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)) rfl All goals completed! 🐙
| some i => 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))
dsimp only 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))
have hle : R.arity i ≤ R.maxArity := arity_le_maxArity R i 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))
by_cases hst : R.arity i ≤ depth pos 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))neg 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))
· pos 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)) rw [ite_eq_left hst, pos 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))) =
prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))) ite_eq_left (by 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⊢ R.arity i ≤ min depth (R.maxArity + 1) omega All goals completed! 🐙)] All goals completed! 🐙
· neg 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)) rw [ite_eq_right hst, neg 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))) =
prependOf (false :: bufBits R []) (predIterOf (1 + R.width)) ite_eq_right (by 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⊢ ¬R.arity i ≤ min depth (R.maxArity + 1) omega All goals completed! 🐙)] All goals completed! 🐙
· neg 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)) rw [ite_eq_right hlen, neg R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Boolbuf:List Booldepth:ℕhlen:¬(b :: buf).length = R.width⊢ 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)) ite_eq_right hlen neg R:RankedAlphabetalgOf:(i : Fin R.card) → COf (R.arity i)b:Boolbuf:List Booldepth:ℕhlen:¬(b :: buf).length = R.width⊢ prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)) =
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 := rflThe 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] := by j:ℕst:List (List Bool)hj:j < st.length⊢ (List.drop j st).headD [] = st[j]
rw [List.drop_eq_getElem_cons hj j:ℕst:List (List Bool)hj:j < st.length⊢ (st[j] :: List.drop (j + 1) st).headD [] = st[j]] j:ℕst:List (List Bool)hj:j < st.length⊢ (st[j] :: List.drop (j + 1) st).headD [] = st[j]
rfl 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) := by 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.width⊢ stepWord (foldStepV R algOf b) (stateWordV R s) = stateWordV R (foldScanStep R alg b s)
rw [stepWord_foldStepV_apply R algOf b s h 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.width⊢ 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.width⊢ 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)
have hcap : branchV R algOf b ⟨s.buf, min s.stack.length (R.maxArity + 1), s.live⟩ =
branchV R algOf b ⟨s.buf, s.stack.length, s.live⟩ :=
branchV_min R algOf b ⟨s.buf, s.stack.length, s.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: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)
rw [hcap 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 }⊢ 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)
have hdrop0 : (stateWordV R s).drop (1 + R.width) =
List.replicate s.stack.length true ++ false :: stackWordV s.stack := by 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.width⊢ stepWord (foldStepV R algOf b) (stateWordV R s) = stateWordV R (foldScanStep R alg b s)
have := drop_stateWordV R s h 0 (Nat.zero_le _) 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 }this:List.drop (1 + R.width + 0) (stateWordV R s) = List.replicate (s.stack.length - 0) true ++ false :: stackWordV s.stack⊢ List.drop (1 + R.width) (stateWordV R s) = List.replicate s.stack.length true ++ false :: stackWordV s.stack
rwa [Nat.add_zero, 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 }this:List.drop (1 + R.width) (stateWordV R s) = List.replicate (s.stack.length - 0) true ++ false :: stackWordV s.stack⊢ List.drop (1 + R.width) (stateWordV R s) = List.replicate s.stack.length true ++ false :: stackWordV s.stack Nat.sub_zero 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 }this:List.drop (1 + R.width) (stateWordV R s) = List.replicate s.stack.length true ++ false :: stackWordV s.stack⊢ List.drop (1 + R.width) (stateWordV R s) = List.replicate s.stack.length true ++ false :: stackWordV s.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: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 }this:List.drop (1 + R.width) (stateWordV R s) = List.replicate s.stack.length true ++ false :: stackWordV s.stack⊢ List.drop (1 + R.width) (stateWordV R s) = List.replicate s.stack.length true ++ false :: stackWordV s.stack at this 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.stack⊢ 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)
obtain ⟨buf, stack, live⟩ := 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 }.stack⊢ stepWord
(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 })
dsimp only at h hdrop0 ⊢ 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 stack⊢ stepWord (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 })
rw [branchV, 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 stack⊢ stepWord
(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 (foldScanStep R alg b { buf := buf, stack := stack, live := live }) foldScanStep 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 stack⊢ stepWord
(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 stack⊢ stepWord
(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 })
dsimp only 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 stack⊢ stepWord
(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 })
cases 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 := 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 stack⊢ stepWord
(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 })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 stack⊢ stepWord
(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 })
· 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 := 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 stack⊢ stepWord
(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 }) rw [stepWord_idOf 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 := 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 stack⊢ 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! 🐙
· 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 stack⊢ stepWord
(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 }) dsimp only 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 stack⊢ stepWord
(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 })
by_cases hlen : (b :: buf).length = R.width pos 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.width⊢ stepWord
(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 })neg 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.width⊢ stepWord
(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 })
· pos 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.width⊢ stepWord
(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 }) rw [ite_eq_left hlen, pos 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.width⊢ stepWord
(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
(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 }) ite_eq_left hlen pos 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.width⊢ stepWord
(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 })] pos 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.width⊢ stepWord
(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
| none => 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)) = none⊢ stepWord
(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 })
rw [stepWord_prependOf, 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)) = none⊢ false :: bufBits R [] ++
stepWord (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 }) stepWord_predIterOf, 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)) = none⊢ false :: bufBits R [] ++ List.drop (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 }) hdrop0, 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)) = none⊢ false :: bufBits R [] ++ (List.replicate stack.length true ++ false :: stackWordV stack) =
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 }) stateWordV_mk 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)) = none⊢ false :: bufBits R [] ++ (List.replicate stack.length true ++ false :: stackWordV stack) =
false :: bufBits R [] ++ List.replicate stack.length true ++ false :: stackWordV 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.widthhsym:symOf R (decodeBits (b :: buf)) = none⊢ false :: bufBits R [] ++ (List.replicate stack.length true ++ false :: stackWordV stack) =
false :: bufBits R [] ++ List.replicate stack.length true ++ false :: stackWordV stack
simp only [List.cons_append, List.append_assoc] All goals completed! 🐙
| some i => 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 i⊢ stepWord
(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 })
dsimp only 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 i⊢ stepWord
(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 })
by_cases hst : R.arity i ≤ stack.length pos 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.length⊢ stepWord
(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 })neg 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.length⊢ stepWord
(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 })
· pos 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.length⊢ stepWord
(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 }) rw [ite_eq_left hst, pos 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.length⊢ stepWord
(prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))))
(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 }) dite_eq_left hst, pos 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.length⊢ stepWord
(prependOf (true :: bufBits R [] ++ [true]) (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i))))
(stateWordV R { buf := buf, stack := stack, live := true }) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true } stepWord_prependOf, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
stepWord (comp1Of (rebuildOf (algOf i)) (predIterOf (1 + R.width + R.arity i)))
(stateWordV R { buf := buf, stack := stack, live := true }) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true }
stepWord_comp1Of, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
stepWord (rebuildOf (algOf i))
(stepWord (predIterOf (1 + R.width + R.arity i)) (stateWordV R { buf := buf, stack := stack, live := true })) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true } stepWord_predIterOf, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
stepWord (rebuildOf (algOf i))
(List.drop (1 + R.width + R.arity i) (stateWordV R { buf := buf, stack := stack, live := true })) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true } drop_stateWordV R _ h _ hst, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
stepWord (rebuildOf (algOf i))
(List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false :: stackWordV { buf := buf, stack := stack, live := true }.stack) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true }
stepWord_rebuildOf, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
(takeUnarySem
![List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false :: stackWordV { buf := buf, stack := stack, live := true }.stack] ++
false ::
stepWord (newStackOf (algOf i))
(dropUnarySem
![List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false :: stackWordV { buf := buf, stack := stack, live := true }.stack])) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true } takeUnarySem_replicate, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
(List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false ::
stepWord (newStackOf (algOf i))
(dropUnarySem
![List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false :: stackWordV { buf := buf, stack := stack, live := true }.stack])) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true } dropUnarySem_replicate, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
(List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false :: stepWord (newStackOf (algOf i)) (stackWordV { buf := buf, stack := stack, live := true }.stack)) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true }
stepWord_newStackOf, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
(List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false ::
(entryWord (stepWord (applyAlgOf (algOf i)) (stackWordV { buf := buf, stack := stack, live := true }.stack)) ++
stepWord (dropEntriesOf (R.arity i)) (stackWordV { buf := buf, stack := stack, live := true }.stack))) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true } stepWord_dropEntriesOf_stackWordV, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
(List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false ::
(entryWord (stepWord (applyAlgOf (algOf i)) (stackWordV { buf := buf, stack := stack, live := true }.stack)) ++
stackWordV (List.drop (R.arity i) { buf := buf, stack := stack, live := true }.stack))) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true }
stepWord_applyAlgOf, pos 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.length⊢ true :: bufBits R [] ++ [true] ++
(List.replicate ({ buf := buf, stack := stack, live := true }.stack.length - R.arity i) true ++
false ::
(entryWord
(semAt (R.arity i) ↑↑(algOf 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))) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true } halg, pos 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.length⊢ 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))) =
stateWordV R { buf := [], stack := (alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack, live := true } stateWordV_mk pos 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.length⊢ 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)] pos 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.length⊢ 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)
have hargs : (fun j : Fin (R.arity i) ↦
stepWord (entryOf j.val) (stackWordV stack)) =
fun j : Fin (R.arity i) ↦ stack[j.val]'(Nat.lt_of_lt_of_le j.isLt hst) := by 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.width⊢ stepWord (foldStepV R algOf b) (stateWordV R s) = stateWordV R (foldScanStep R alg b s)
funext j 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.lengthj:Fin (R.arity i)⊢ stepWord (entryOf ↑j) (stackWordV stack) = stack[↑j]
rw [stepWord_entryOf_stackWordV 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.lengthj:Fin (R.arity i)⊢ (List.drop (↑j) stack).headD [] = stack[↑j]] 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.lengthj:Fin (R.arity i)⊢ (List.drop (↑j) stack).headD [] = stack[↑j]
exact headD_drop j.val stack (Nat.lt_of_lt_of_le j.isLt hst) pos 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)
rw [hargs, pos 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 ((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) List.length_cons, pos 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 ((List.drop (R.arity i) stack).length + 1) true ++
false :: stackWordV ((alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack) List.length_drop, pos 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 :: stackWordV ((alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack) stackWordV_cons pos 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))] pos 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))
have hrep : List.replicate (stack.length - R.arity i + 1) true =
[true] ++ List.replicate (stack.length - R.arity i) true := by 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.width⊢ stepWord (foldStepV R algOf b) (stateWordV R s) = stateWordV R (foldScanStep R alg b s)
rw [Nat.add_comm, 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]⊢ List.replicate (1 + (stack.length - R.arity i)) true = [true] ++ List.replicate (stack.length - R.arity i) true List.replicate_add 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]⊢ List.replicate 1 true ++ List.replicate (stack.length - R.arity i) true =
[true] ++ List.replicate (stack.length - R.arity i) 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.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]⊢ List.replicate 1 true ++ List.replicate (stack.length - R.arity i) true =
[true] ++ List.replicate (stack.length - R.arity i) true
rfl pos 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) true⊢ 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))
rw [hrep pos 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) true⊢ 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 [] ++ ([true] ++ List.replicate (stack.length - R.arity i) true) ++
false :: (entryWord (alg i fun d ↦ stack[↑d]) ++ stackWordV (List.drop (R.arity i) stack))] pos 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) true⊢ 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 [] ++ ([true] ++ List.replicate (stack.length - R.arity i) true) ++
false :: (entryWord (alg i fun d ↦ stack[↑d]) ++ stackWordV (List.drop (R.arity i) stack))
simp only [List.cons_append, List.append_assoc] All goals completed! 🐙
· neg 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.length⊢ stepWord
(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 }) rw [ite_eq_right hst, neg 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.length⊢ stepWord (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 }) dite_eq_right hst, neg 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.length⊢ stepWord (prependOf (false :: bufBits R []) (predIterOf (1 + R.width)))
(stateWordV R { buf := buf, stack := stack, live := true }) =
stateWordV R { buf := [], stack := stack, live := false } stepWord_prependOf, neg 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.length⊢ false :: bufBits R [] ++
stepWord (predIterOf (1 + R.width)) (stateWordV R { buf := buf, stack := stack, live := true }) =
stateWordV R { buf := [], stack := stack, live := false }
stepWord_predIterOf, neg 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.length⊢ false :: bufBits R [] ++ List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) =
stateWordV R { buf := [], stack := stack, live := false } hdrop0, neg 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.length⊢ false :: bufBits R [] ++ (List.replicate stack.length true ++ false :: stackWordV stack) =
stateWordV R { buf := [], stack := stack, live := false } stateWordV_mk neg 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.length⊢ false :: bufBits R [] ++ (List.replicate stack.length true ++ false :: stackWordV stack) =
false :: bufBits R [] ++ List.replicate stack.length true ++ false :: stackWordV stack] neg 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.length⊢ false :: bufBits R [] ++ (List.replicate stack.length true ++ false :: stackWordV stack) =
false :: bufBits R [] ++ List.replicate stack.length true ++ false :: stackWordV stack
simp only [List.cons_append, List.append_assoc] All goals completed! 🐙
· neg 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.width⊢ stepWord
(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 }) rw [ite_eq_right hlen, neg 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.width⊢ stepWord (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 }) ite_eq_right hlen, neg 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.width⊢ stepWord (prependOf (true :: bufBits R (b :: buf)) (predIterOf (1 + R.width)))
(stateWordV R { buf := buf, stack := stack, live := true }) =
stateWordV R { buf := b :: buf, stack := stack, live := true } stepWord_prependOf, neg 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.width⊢ true :: bufBits R (b :: buf) ++
stepWord (predIterOf (1 + R.width)) (stateWordV R { buf := buf, stack := stack, live := true }) =
stateWordV R { buf := b :: buf, stack := stack, live := true }
stepWord_predIterOf, neg 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.width⊢ true :: bufBits R (b :: buf) ++ List.drop (1 + R.width) (stateWordV R { buf := buf, stack := stack, live := true }) =
stateWordV R { buf := b :: buf, stack := stack, live := true } hdrop0, neg 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.width⊢ true :: bufBits R (b :: buf) ++ (List.replicate stack.length true ++ false :: stackWordV stack) =
stateWordV R { buf := b :: buf, stack := stack, live := true } stateWordV_mk neg 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.width⊢ true :: 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] neg 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.width⊢ true :: 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
simp only [List.cons_append, List.append_assoc] 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.widthThe 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) := by 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⊢ foldSemV R algOf mult ![w] = stateWordV R (foldScanFinal R alg w)
rw [foldSemV, 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⊢ scanBSem (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) (foldStepV R algOf false)
(foldStepV R algOf true) (boundMulRaw mult (foldGrowthV R)) ⋯ ⋯ ![w] =
stateWordV R (foldScanFinal R alg w) scanBSem_eq 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⊢ List.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 Bool⊢ List.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)
refine List.rec ?_ ?_ w refine_1 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⊢ List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true))
(baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) [] =
stateWordV R (foldScanFinal R alg [])refine_2 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))
· refine_1 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⊢ List.foldr (scanStepWord (foldStepV R algOf false) (foldStepV R algOf true))
(baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true }))) [] =
stateWordV R (foldScanFinal R alg []) rw [List.foldr_nil, refine_1 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⊢ baseWord (constAtOf 0 (stateWordV R { buf := [], stack := [], live := true })) = stateWordV R (foldScanFinal R alg []) baseWord_constAtOf refine_1 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⊢ stateWordV R { buf := [], stack := [], live := true } = stateWordV R (foldScanFinal R alg [])] refine_1 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⊢ stateWordV R { buf := [], stack := [], live := true } = stateWordV R (foldScanFinal R alg [])
rfl All goals completed! 🐙
· refine_2 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)) intro b v ih refine_2 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))
rw [List.foldr_cons, refine_2 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
(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 (b :: v)) ih refine_2 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))] refine_2 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))
cases b refine_2.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 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))refine_2.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 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))
· refine_2.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 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)) exact stepWord_foldStepV R algOf alg halg false _
(length_buf_foldScanFinal_lt R alg v) All goals completed! 🐙
· refine_2.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 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)) exact stepWord_foldStepV R algOf alg halg true _
(length_buf_foldScanFinal_lt R alg 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 := by 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
have hstate : (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 =
1 + R.width + (R.scanFinal w).depth + 1 +
(2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth) := by
rw [← foldSemV, 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⊢ (foldSemV R algOf mult ![w]).length =
1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth) foldSemV_eq R algOf alg halg mult 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 Bool⊢ (stateWordV R (foldScanFinal R alg w)).length =
1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)
length_stateWordV_of_lt R _ (length_buf_foldScanFinal_lt 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 Bool⊢ 1 + R.width + (foldScanFinal R alg w).stack.length + 1 +
(2 * stackSize (foldScanFinal R alg w).stack + (foldScanFinal R alg w).stack.length) =
1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)
length_stack_foldScanFinal 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⊢ 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth) =
1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth)] 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
have hd : (R.scanFinal w).depth ≤ w.length := depth_scanFinal_le_length R 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 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
have hs := hsize 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 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
have h1 : (2 * c + 2) * w.length ≤ mult * w.length :=
Nat.mul_le_mul_right w.length hmult 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
have h2 : (2 * c + 2) * w.length = 2 * (c * w.length) + 2 * w.length := by
rw [Nat.add_mul, 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⊢ 2 * c * w.length + 2 * w.length = 2 * (c * w.length) + 2 * w.length Nat.mul_assoc 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⊢ 2 * (c * w.length) + 2 * w.length = 2 * (c * w.length) + 2 * w.length] 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
rw [hstate, 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⊢ 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth) ≤
mult * w.length + foldGrowthV R foldGrowthV 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⊢ 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth) ≤
mult * w.length + (2 + R.width)] 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⊢ 1 + R.width + (R.scanFinal w).depth + 1 + (2 * stackSize (foldScanFinal R alg w).stack + (R.scanFinal w).depth) ≤
mult * w.length + (2 + R.width)
omega 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 := rflA 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 ↦ by α: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 rw [bits_ofFn, α: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 (enc (g d)) = g d hdec α: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)⊢ g 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 := by R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthh1:s.stack.length = 1⊢ List.drop (R.width + 3) (stateWordV R s) = stackWordV s.stack
have hd := drop_stateWordV R s h 1 (by R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthh1:s.stack.length = 1⊢ 1 ≤ s.stack.length omega All goals completed! 🐙) 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.stack⊢ List.drop (R.width + 3) (stateWordV R s) = stackWordV s.stack
rw [h1 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.stack⊢ List.drop (R.width + 3) (stateWordV R s) = stackWordV s.stack] at hd 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.stack⊢ List.drop (R.width + 3) (stateWordV R s) = stackWordV s.stack
have hdd : (stateWordV R s).drop (R.width + 3) =
((stateWordV R s).drop (1 + R.width + 1)).drop 1 := by
rw [List.drop_drop 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.stack⊢ List.drop (R.width + 3) (stateWordV R s) = List.drop (1 + R.width + 1 + 1) (stateWordV R s)] 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.stack⊢ List.drop (R.width + 3) (stateWordV R s) = List.drop (1 + R.width + 1 + 1) (stateWordV R s)
exact congrArg (fun k ↦ (stateWordV R s).drop k) (by 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.stack⊢ R.width + 3 = 1 + R.width + 1 + 1 omega All goals completed! 🐙) 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
rw [hdd, 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.drop (1 + R.width + 1) (stateWordV R s)) = stackWordV s.stack hd 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] 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
rfl 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) := by R:RankedAlphabets: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) = true then s.stack.head? else none)
rw [readOfV, R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ stepWord
(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) =
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) stepWord_diagOf R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ semAt 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.width⊢ semAt 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)
change casesSem (readoutWidthV R) _ ![stateWordV R s, stateWordV R s] = _ R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ casesSem (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)
rw [casesSem_eq, R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ stepWord
(if
((decodeVAt R (readoutWidthV R) (bits (readoutWidthV R) (stateWordV R s))).live &&
(decodeVAt R (readoutWidthV R) (bits (readoutWidthV R) (stateWordV R s))).buf.isEmpty &&
(decodeVAt R (readoutWidthV R) (bits (readoutWidthV R) (stateWordV R s))).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) decodeVAt_stateWordV R s (readoutWidthV R) (R.maxArity + 2)
(by R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ readoutWidthV R = 1 + R.width + (R.maxArity + 2) rw [readoutWidthV R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ 1 + R.width + (R.maxArity + 2) = 1 + R.width + (R.maxArity + 2)] All goals completed! 🐙) h] R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ stepWord
(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)
dsimp only R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.width⊢ 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)
have hmin : ∀ n : ℕ, (min n (R.maxArity + 2) == 1) = (n == 1) := by R:RankedAlphabets: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) = true then s.stack.head? else none)
intro n R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕ⊢ (min n (R.maxArity + 2) == 1) = (n == 1)
by_cases hn : n = 1 pos R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:n = 1⊢ (min n (R.maxArity + 2) == 1) = (n == 1)neg R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:¬n = 1⊢ (min n (R.maxArity + 2) == 1) = (n == 1)
· pos R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:n = 1⊢ (min n (R.maxArity + 2) == 1) = (n == 1) have h2 : min n (R.maxArity + 2) = 1 := by R:RankedAlphabets: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) = true then s.stack.head? else none) omega pos R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:n = 1h2:min n (R.maxArity + 2) = 1⊢ (min n (R.maxArity + 2) == 1) = (n == 1)
rw [h2, pos R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:n = 1h2:min n (R.maxArity + 2) = 1⊢ (1 == 1) = (n == 1) hn pos R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:n = 1h2:min n (R.maxArity + 2) = 1⊢ (1 == 1) = (1 == 1)] All goals completed! 🐙
· neg R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:¬n = 1⊢ (min n (R.maxArity + 2) == 1) = (n == 1) rw [beq_eq_false_iff_ne.mpr (by R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:¬n = 1⊢ ¬min n (R.maxArity + 2) = 1 omega All goals completed! 🐙 : ¬ min n (R.maxArity + 2) = 1),
beq_eq_false_iff_ne.mpr hn neg R:RankedAlphabets:FoldScan (List Bool)h:s.buf.length < R.widthn:ℕhn:¬n = 1⊢ false = false] 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)
rw [hmin 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)⊢ 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)
by_cases hacc : (s.live && s.buf.isEmpty && (s.stack.length == 1)) = true pos 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⊢ 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)neg 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⊢ 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)
· pos 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⊢ 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) rw [ite_eq_left hacc, pos 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⊢ stepWord (prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3)))) (stateWordV R s) =
outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) ite_eq_left hacc, pos 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⊢ stepWord (prependOf [true] (comp1Of takeEntryOf (predIterOf (R.width + 3)))) (stateWordV R s) = outWordV s.stack.head? stepWord_prependOf, pos 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 (comp1Of takeEntryOf (predIterOf (R.width + 3))) (stateWordV R s) = outWordV s.stack.head? stepWord_comp1Of, pos 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 (stepWord (predIterOf (R.width + 3)) (stateWordV R s)) = outWordV s.stack.head?
stepWord_predIterOf pos 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?] pos 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?
obtain ⟨_, hone⟩ := (Bool.and_eq_true _ _).mp hacc pos 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?
have h1 : s.stack.length = 1 := eq_of_beq hone pos 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?
have hsing : ∃ a, s.stack = [a] := by R:RankedAlphabets: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) = true then s.stack.head? else none)
match hs2 : s.stack with
| [] => 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 = 1hs2:s.stack = []⊢ ∃ a, [] = [a]
rw [hs2, 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:[].length = 1hs2:s.stack = []⊢ ∃ a, [] = [a] List.length_nil 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:0 = 1hs2:s.stack = []⊢ ∃ a, [] = [a]] at h1 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:0 = 1hs2:s.stack = []⊢ ∃ a, [] = [a]
exact absurd h1 Nat.zero_ne_one All goals completed! 🐙
| a :: [] => 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 Boolhs2:s.stack = [a]⊢ ∃ a_1, [a] = [a_1] exact ⟨a, rfl⟩ All goals completed! 🐙
| _ :: _ :: t => 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 = 1head✝¹:List Boolhead✝:List Boolt:List (List Bool)hs2:s.stack = head✝¹ :: head✝ :: t⊢ ∃ a, head✝¹ :: head✝ :: t = [a]
rw [hs2, 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) = truehead✝¹:List Boolhead✝:List Boolt:List (List Bool)h1:(head✝¹ :: head✝ :: t).length = 1hs2:s.stack = head✝¹ :: head✝ :: t⊢ ∃ a, head✝¹ :: head✝ :: t = [a] List.length_cons, 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) = truehead✝¹:List Boolhead✝:List Boolt:List (List Bool)h1:(head✝ :: t).length + 1 = 1hs2:s.stack = head✝¹ :: head✝ :: t⊢ ∃ a, head✝¹ :: head✝ :: t = [a] List.length_cons 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) = truehead✝¹:List Boolhead✝:List Boolt:List (List Bool)h1:t.length + 1 + 1 = 1hs2:s.stack = head✝¹ :: head✝ :: t⊢ ∃ a, head✝¹ :: head✝ :: t = [a]] at h1 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) = truehead✝¹:List Boolhead✝:List Boolt:List (List Bool)h1:t.length + 1 + 1 = 1hs2:s.stack = head✝¹ :: head✝ :: t⊢ ∃ a, head✝¹ :: head✝ :: t = [a]
exact absurd h1 (by 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) = truehead✝¹:List Boolhead✝:List Boolt:List (List Bool)h1:t.length + 1 + 1 = 1hs2:s.stack = head✝¹ :: head✝ :: t⊢ ¬t.length + 1 + 1 = 1 omega All goals completed! 🐙) pos 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?
obtain ⟨a, ha⟩ := hsing pos 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?
rw [drop_stateWordV_succ R s h h1, pos 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 (stackWordV s.stack) = outWordV s.stack.head? stepWord_takeEntryOf, pos 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] ++ takeEntrySem ![stackWordV s.stack] = outWordV s.stack.head? ha, pos 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] ++ takeEntrySem ![stackWordV [a]] = outWordV [a].head?
stackWordV_cons, pos 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] ++ takeEntrySem ![entryWord a ++ stackWordV []] = outWordV [a].head? stackWordV_nil, pos 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] ++ takeEntrySem ![entryWord a ++ []] = outWordV [a].head? takeEntrySem_entryWord pos 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?] pos 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?
rfl All goals completed! 🐙
· neg 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⊢ 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) rw [ite_eq_right hacc, neg 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⊢ stepWord (constAtOf 1 [false]) (stateWordV R s) =
outWordV (if (s.live && s.buf.isEmpty && s.stack.length == 1) = true then s.stack.head? else none) ite_eq_right hacc, neg 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⊢ stepWord (constAtOf 1 [false]) (stateWordV R s) = outWordV none stepWord_constAtOf neg 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] neg 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
rfl 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).1The 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).2The 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) := by 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⊢ foldOutSemV R algOf alg halg mult c hsize hmult ![w] = outWordV (foldOut R alg w)
have happly : foldOutSemV R algOf alg halg mult c hsize hmult ![w] =
stepWord (readOfV R) (foldSemV R algOf mult ![w]) :=
congrArg (semAt 1 (readOfV R).1.1 (readOfV R).2)
(funext fun i ↦ match i with | ⟨0, _⟩ => rfl) 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)
rw [happly, 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])⊢ stepWord (readOfV R) (foldSemV R algOf mult ![w]) = outWordV (foldOut R alg w) foldSemV_eq R algOf alg halg mult 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])⊢ stepWord (readOfV R) (stateWordV R (foldScanFinal R alg w)) = outWordV (foldOut R alg w)
stepWord_readOfV R _ (length_buf_foldScanFinal_lt 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])⊢ outWordV
(if
((foldScanFinal R alg w).live && (foldScanFinal R alg w).buf.isEmpty &&
(foldScanFinal R alg w).stack.length == 1) =
true then
(foldScanFinal R alg w).stack.head?
else none) =
outWordV (foldOut R alg w) foldOut 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])⊢ outWordV
(if
((foldScanFinal R alg w).live && (foldScanFinal R alg w).buf.isEmpty &&
(foldScanFinal R alg w).stack.length == 1) =
true then
(foldScanFinal R alg w).stack.head?
else none) =
outWordV
(if
((foldScanFinal R alg w).live && (foldScanFinal R alg w).buf.isEmpty &&
(foldScanFinal R alg w).stack.length == 1) =
true then
(foldScanFinal R alg w).stack.head?
else none)] 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 := by c:ℕn:ℕg:Fin n → ℕ⊢ (List.ofFn fun d ↦ c * g d).sum = c * (List.ofFn g).sum
rw [List.ofFn_eq_map, c:ℕn:ℕg:Fin n → ℕ⊢ (List.map (fun d ↦ c * g d) (List.finRange n)).sum = c * (List.ofFn g).sum List.ofFn_eq_map, c:ℕn:ℕg:Fin n → ℕ⊢ (List.map (fun d ↦ c * g d) (List.finRange n)).sum = c * (List.map g (List.finRange n)).sum List.sum_map_mul_left c:ℕn:ℕg:Fin n → ℕ⊢ c * (List.map g (List.finRange n)).sum = c * (List.map g (List.finRange n)).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 _ _ _ ↦ by 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 rw [List.ofFn_zero, x✝²:Fin Nat.zero → ℕx✝¹:Fin Nat.zero → ℕx✝:∀ (d : Fin Nat.zero), x✝² d ≤ x✝¹ d⊢ [].sum ≤ (List.ofFn x✝¹).sum List.ofFn_zero x✝²:Fin Nat.zero → ℕx✝¹:Fin Nat.zero → ℕx✝:∀ (d : Fin Nat.zero), x✝² d ≤ x✝¹ d⊢ [].sum ≤ [].sum] All goals completed! 🐙)
fun n ih g h hgh ↦ by 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
rw [List.ofFn_succ, 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⊢ (g 0 :: List.ofFn fun i ↦ g i.succ).sum ≤ (List.ofFn h).sum List.ofFn_succ, 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⊢ (g 0 :: List.ofFn fun i ↦ g i.succ).sum ≤ (h 0 :: List.ofFn fun i ↦ h i.succ).sum List.sum_cons, 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⊢ g 0 + (List.ofFn fun i ↦ g i.succ).sum ≤ (h 0 :: List.ofFn fun i ↦ h i.succ).sum List.sum_cons 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⊢ g 0 + (List.ofFn fun i ↦ g i.succ).sum ≤ h 0 + (List.ofFn fun i ↦ h i.succ).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 d⊢ g 0 + (List.ofFn fun i ↦ g i.succ).sum ≤ h 0 + (List.ofFn fun i ↦ h i.succ).sum
exact Nat.add_le_add (hgh 0)
(ih (fun i ↦ g i.succ) (fun i ↦ h i.succ) fun i ↦ hgh i.succ) 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 ↦ by 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
rw [Term.fold_mk, 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 * (Term.mk R i ch).size size_mk, 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 + 1) Nat.mul_add, 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 * 1 Nat.mul_one 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⊢ (alg i fun d ↦ Term.fold R alg (ch d)).length ≤ c * (List.ofFn fun d ↦ (ch d).size).sum + c
refine Nat.le_trans (hgrow i fun d ↦ Term.fold R alg (ch d)) ?_ 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
refine Nat.add_le_add_right ?_ 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
refine Nat.le_trans
(sum_ofFn_le (R.arity i) _ (fun d ↦ c * (ch d).size) 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⊢ (List.ofFn fun d ↦ c * (ch d).size).sum ≤ c * (List.ofFn fun d ↦ (ch d).size).sum
exact Nat.le_of_eq (sum_ofFn_mul c (R.arity i) fun d ↦ (ch d).size) 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 := by a:List (List Bool)b:List (List Bool)⊢ stackSize (a ++ b) = stackSize a + stackSize b
rw [stackSize, a:List (List Bool)b:List (List Bool)⊢ (a ++ b).flatten.length = stackSize a + stackSize b stackSize, a:List (List Bool)b:List (List Bool)⊢ (a ++ b).flatten.length = a.flatten.length + stackSize b stackSize, a:List (List Bool)b:List (List Bool)⊢ (a ++ b).flatten.length = a.flatten.length + b.flatten.length List.flatten_append, a:List (List Bool)b:List (List Bool)⊢ (a.flatten ++ b.flatten).length = a.flatten.length + b.flatten.length List.length_append a:List (List Bool)b:List (List Bool)⊢ a.flatten.length + b.flatten.length = a.flatten.length + b.flatten.length] 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 := by st:List (List Bool)r:ℕ⊢ stackSize (List.take r st) + stackSize (List.drop r st) = stackSize st
rw [← stackSize_append, st:List (List Bool)r:ℕ⊢ stackSize (List.take r st ++ List.drop r st) = stackSize st List.take_append_drop st:List (List Bool)r:ℕ⊢ stackSize 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 _ ↦ by st:List (List Bool)x✝:Nat.zero ≤ st.length⊢ (List.ofFn fun d ↦ st[↑d].length).sum = stackSize (List.take Nat.zero st) rw [List.ofFn_zero, st:List (List Bool)x✝:Nat.zero ≤ st.length⊢ [].sum = stackSize (List.take Nat.zero st) List.sum_nil, st:List (List Bool)x✝:Nat.zero ≤ st.length⊢ 0 = stackSize (List.take Nat.zero st) List.take_zero, st:List (List Bool)x✝:Nat.zero ≤ st.length⊢ 0 = stackSize [] stackSize_nil st:List (List Bool)x✝:Nat.zero ≤ st.length⊢ 0 = 0] All goals completed! 🐙)
fun r ih st h ↦ match st with
| [] => absurd h (Nat.not_succ_le_zero r)
| 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)) by 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))
rw [List.ofFn_succ, 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 = stackSize (List.take r.succ (a :: t)) List.sum_cons, 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 = stackSize (List.take r.succ (a :: t)) List.take_succ_cons, 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 = stackSize (a :: List.take r t) stackSize_cons 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)] 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)
exact congrArg (a.length + ·) (ih t (Nat.le_of_succ_le_succ h)) 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 := by 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 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
obtain ⟨buf, stack, live⟩ := s 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 v⊢ R.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
dsimp only at hs 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 v⊢ R.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
rw [foldScanStep 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 v⊢ R.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 v⊢ R.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
dsimp only 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 v⊢ R.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
cases live false 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 v⊢ R.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 + ctrue 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 v⊢ R.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
· false 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 v⊢ R.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 dsimp only false 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 v⊢ R.width * stackSize stack + c * buf.length ≤ R.width * stackSize stack + c * buf.length + c
omega All goals completed! 🐙
· true 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 v⊢ R.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 dsimp only true 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 v⊢ R.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
by_cases hlen : (b :: buf).length = R.width pos 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.width⊢ R.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 + cneg 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.width⊢ R.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
· pos 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.width⊢ R.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 rw [ite_eq_left hlen pos 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.width⊢ R.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] pos 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.width⊢ R.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
have hbw : buf.length + 1 = R.width := by 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 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
rw [List.length_cons 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:buf.length + 1 = R.width⊢ buf.length + 1 = R.width] at hlen 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:buf.length + 1 = R.width⊢ buf.length + 1 = R.width
omega pos 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.width⊢ R.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
| none => 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)) = none⊢ R.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
dsimp only 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)) = none⊢ R.width * stackSize stack + c * [].length ≤ R.width * stackSize stack + c * buf.length + c
simp only [List.length_nil, Nat.mul_zero] 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)) = none⊢ R.width * stackSize stack + 0 ≤ R.width * stackSize stack + c * buf.length + c
omega All goals completed! 🐙
| some i => 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 i⊢ R.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
dsimp only 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 i⊢ R.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
by_cases hst : R.arity i ≤ stack.length pos 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.length⊢ R.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 + cneg 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.length⊢ R.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
· pos 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.length⊢ R.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 rw [dite_eq_left hst pos 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.length⊢ R.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] pos 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.length⊢ R.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
dsimp only pos 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.length⊢ 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
have hsum := sum_ofFn_getElem (R.arity i) stack hst pos 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
have halg := hgrow i
(fun d ↦ stack[d.val]'(Nat.lt_of_lt_of_le d.isLt hst))
fun d ↦ hs _ (List.getElem_mem _) pos 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 + 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
rw [hsum pos 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) + 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] at halg pos 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) + 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
have hsplit := stackSize_take_add_drop stack (R.arity i) pos 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 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
have hnew : stackSize ((alg i fun d ↦
stack[d.val]'(Nat.lt_of_lt_of_le d.isLt hst)) ::
stack.drop (R.arity i)) ≤ stackSize stack + c := by 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 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
rw [stackSize_cons 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 stack⊢ (alg i fun d ↦ stack[↑d]).length + stackSize (List.drop (R.arity i) stack) ≤ stackSize stack + 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 stack⊢ (alg i fun d ↦ stack[↑d]).length + stackSize (List.drop (R.arity i) stack) ≤ stackSize stack + c
omega pos 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 + 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
have hmul : R.width * stackSize ((alg i fun d ↦
stack[d.val]'(Nat.lt_of_lt_of_le d.isLt hst)) ::
stack.drop (R.arity i)) ≤ R.width * (stackSize stack + c) :=
Nat.mul_le_mul_left _ hnew pos 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
rw [Nat.mul_add pos 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 * 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] at hmul pos 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 * 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
have hcw : R.width * c = c * R.width := Nat.mul_comm _ _ pos 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.width⊢ 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
have hcb : c * buf.length + c = c * R.width := by 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 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
rw [← hbw, 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.width⊢ c * buf.length + c = c * (buf.length + 1) Nat.mul_add, 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.width⊢ c * buf.length + c = c * buf.length + c * 1 Nat.mul_one 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.width⊢ c * buf.length + c = c * buf.length + c] pos 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.width⊢ 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
simp only [List.length_nil, Nat.mul_zero, Nat.add_zero] pos 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.width⊢ R.width * stackSize ((alg i fun d ↦ stack[↑d]) :: List.drop (R.arity i) stack) ≤
R.width * stackSize stack + c * buf.length + c
omega All goals completed! 🐙
· neg 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.length⊢ R.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 rw [dite_eq_right hst neg 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.length⊢ R.width * stackSize { buf := [], stack := stack, live := false }.stack +
c * { buf := [], stack := stack, live := false }.buf.length ≤
R.width * stackSize stack + c * buf.length + c] neg 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.length⊢ R.width * stackSize { buf := [], stack := stack, live := false }.stack +
c * { buf := [], stack := stack, live := false }.buf.length ≤
R.width * stackSize stack + c * buf.length + c
dsimp only neg 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.length⊢ R.width * stackSize stack + c * [].length ≤ R.width * stackSize stack + c * buf.length + c
simp only [List.length_nil, Nat.mul_zero] neg 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.length⊢ R.width * stackSize stack + 0 ≤ R.width * stackSize stack + c * buf.length + c
omega All goals completed! 🐙
· neg 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.width⊢ R.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 rw [ite_eq_right hlen neg 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.width⊢ R.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] neg 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.width⊢ R.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
dsimp only neg 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.width⊢ R.width * stackSize stack + c * (b :: buf).length ≤ R.width * stackSize stack + c * buf.length + c
have hcb : c * (buf.length + 1) = c * buf.length + c := by 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 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
rw [Nat.mul_add, 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.width⊢ c * buf.length + c * 1 = c * buf.length + c Nat.mul_one 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.width⊢ c * buf.length + c = c * buf.length + c] neg 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 + c⊢ R.width * stackSize stack + c * (b :: buf).length ≤ R.width * stackSize stack + c * buf.length + c
simp only [List.length_cons] neg 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 + c⊢ R.width * stackSize stack + c * (buf.length + 1) ≤ R.width * stackSize stack + c * buf.length + c
omega 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 (by 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 + c⊢ R.width * stackSize (foldScanFinal R alg []).stack + c * (foldScanFinal R alg []).buf.length ≤ c * [].length
rw [List.length_nil, 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 + c⊢ R.width * stackSize (foldScanFinal R alg []).stack + c * (foldScanFinal R alg []).buf.length ≤ c * 0 Nat.mul_zero 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 + c⊢ R.width * stackSize (foldScanFinal R alg []).stack + c * (foldScanFinal R alg []).buf.length ≤ 0] 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 + c⊢ R.width * stackSize (foldScanFinal R alg []).stack + c * (foldScanFinal R alg []).buf.length ≤ 0
exact Nat.le_of_eq rfl All goals completed! 🐙)
fun b v ih ↦ by 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.length⊢ R.width * stackSize (foldScanFinal R alg (b :: v)).stack + c * (foldScanFinal R alg (b :: v)).buf.length ≤
c * (b :: v).length
have hstep := potential_foldScanStep_le_of_invariant R alg P c hgrow b
(foldScanFinal R alg v) (mem_stack_foldScanFinal R alg P hpush v) 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 + c⊢ R.width * stackSize (foldScanFinal R alg (b :: v)).stack + c * (foldScanFinal R alg (b :: v)).buf.length ≤
c * (b :: v).length
have hcons : foldScanFinal R alg (b :: v) =
foldScanStep R alg b (foldScanFinal R alg v) := rfl 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
have hc : c * (v.length + 1) = c * v.length + c := by
rw [Nat.mul_add, 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)⊢ c * v.length + c * 1 = c * v.length + c Nat.mul_one 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)⊢ c * v.length + c = c * v.length + c] 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 + c⊢ R.width * stackSize (foldScanFinal R alg (b :: v)).stack + c * (foldScanFinal R alg (b :: v)).buf.length ≤
c * (b :: v).length
rw [hcons, 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 + c⊢ R.width * stackSize (foldScanStep R alg b (foldScanFinal R alg v)).stack +
c * (foldScanStep R alg b (foldScanFinal R alg v)).buf.length ≤
c * (b :: v).length List.length_cons 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 + c⊢ R.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)] 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 + c⊢ R.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)
omega 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 := by 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 Bool⊢ stackSize (foldScanFinal R alg w).stack ≤ c * w.length
have h := potential_foldScanFinal_le_of_invariant R alg P c hpush hgrow w 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.length⊢ stackSize (foldScanFinal R alg w).stack ≤ c * w.length
have hm : stackSize (foldScanFinal R alg w).stack ≤
R.width * stackSize (foldScanFinal R alg w).stack :=
Nat.le_mul_of_pos_left _ R.width_pos 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).stack⊢ stackSize (foldScanFinal R alg w).stack ≤ c * w.length
omega 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) wend Geb.CobhamFoldend