/-
Copyright (c) 2026 Terence Rokop. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Terence Rokop
-/modulepublicimportGeb.Prototypes.Computability.CobhamFoldProto.SmashFree
The term algebra's constructor in the fold's language
The initial algebra's structure map at the carrier List Bool, whose
elements are read as spellings.
Term.fold at algMk is RankedAlphabet.spell itself, so algMk is the
step spell's own WType.elim runs, named apart from it, and the preorder
encoding is the unique morphism from the term algebra into it by the
initiality Term.fold_unique carries [GambinoHyland2004]. The carrier
List Bool is not itself initial — the spellings are a proper subalgebra of
it — so what the equation says is that algMk is the initial algebra's
structure map transported along the encoding.
mkOf computes that map inside the class: the symbol's block prepended to
flattenOf, a Nat.rec on the arity whose step composes the arity-n tail
against the shifted projections, so no def calls itself.
Main definitions
Geb.CobhamFold.algMk — the initial algebra's structure map.
Geb.CobhamFold.flattenOf — the concatenation of an arity's slots.
Geb.CobhamFold.mkOf — the structure map as an expression of the class.
Main statements
Geb.CobhamFold.fold_algMk — the fold at that map is the spelling.
Geb.CobhamFold.length_algMk — it lengthens by the alphabet's width.
Geb.CobhamFold.foldOut_algMk — the fold at that map is the identity on
the recognized language.
Geb.CobhamFold.flattenOf_succ — the slot concatenation at a successor,
which Nat.rec generates no equation lemma for.
Geb.CobhamFold.semAt_flattenOf, Geb.CobhamFold.semAt_mkOf — what those
two expressions compute.
Geb.CobhamFold.growth_algMk, Geb.CobhamFold.stackSize_algMk_le — the
per-symbol growth condition at the constant R.width, and the linearity
hypothesis it discharges.
Geb.CobhamFold.smashFreeBool_flattenOf,
Geb.CobhamFold.smashFreeBool_mkOf — those expressions carry no smash.
Geb.CobhamFold.foldOutSemV_algMk — the expression at that algebra returns
its own input on the recognized language, characterised for every input
word; ## Implementation notes records why it is characterised rather than
computed.
Geb.CobhamFold.smashFree_foldOutExprV_mkOf — that expression lies in the
subalgebra Cobham.SmashFree names.
Implementation notes
Nothing here is evaluated. readoutWidthV R is six at
RankedAlphabet.Binary.binRanked, so the readout dispatches on 2 ^ 6
branches. foldOutSemV_algMk characterises the output word for every input
word instead, which needs no branch of that tree.
algMk and the step RankedAlphabet.spell's own WType.elim runs agree by
rfl rather than sharing one definition: factoring that step out of spell
would touch Geb/Mathlib/Data/Tree/Ranked/Preorder.lean.
The fold at that map is the preorder encoding, so RankedAlphabet.spell
is the unique morphism from the term algebra into it, by the initiality
Geb.CobhamFold.Term.fold_unique carries [GambinoHyland2004].
The concatenation of an arity's slots, in index order. Built by Nat.rec
on the arity, the arity-n tail composed against the shifted projections, so
no def calls itself.
The pending values stay linear in the input, at the same constant. This
is the hypothesis Geb.CobhamFold.foldOutExprV takes, discharged by
Geb.CobhamFold.stackSize_le_of_growth from the per-symbol condition
alone.
The expression at the structure map returns its own input, spelled by
Geb.CobhamFold.outWordV, on the recognized language and the absence marker
off it. The output word is characterised for every input word rather than
computed from one, the readout's dispatch having 2 ^ readoutWidthV R
branches.
That expression lies in the subalgebra Cobham.SmashFree names, so with
[Strahm2003] Theorem 1(2)'s left-to-right inclusion it is computable
simultaneously in polynomial time and linear space.